@antv/g-plugin-canvas-path-generator
Advanced tools
Comparing version 1.1.27 to 1.1.28
@@ -7,6 +7,4 @@ import { DisplayObject, Shape, AbstractRendererPlugin } from '@antv/g-lite'; | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
@@ -27,6 +25,6 @@ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
var rxInPixels = parsedStyle.rx, | ||
ryInPixels = parsedStyle.ry; | ||
ryInPixels = parsedStyle.ry; | ||
var rx = rxInPixels; | ||
var ry = ryInPixels; // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
var ry = ryInPixels; | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
if (context.ellipse) { | ||
@@ -47,13 +45,13 @@ context.ellipse(rx, ry, rx, ry, 0, 0, Math.PI * 2, false); | ||
var x1 = parsedStyle.x1, | ||
y1 = parsedStyle.y1, | ||
x2 = parsedStyle.x2, | ||
y2 = parsedStyle.y2, | ||
_parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
y1 = parsedStyle.y1, | ||
x2 = parsedStyle.x2, | ||
y2 = parsedStyle.y2, | ||
_parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var startOffsetX = 0; | ||
@@ -66,3 +64,2 @@ var startOffsetY = 0; | ||
var y; | ||
if (markerStart && markerStart instanceof DisplayObject && markerStartOffset) { | ||
@@ -75,3 +72,2 @@ x = x2 - x1; | ||
} | ||
if (markerEnd && markerEnd instanceof DisplayObject && markerEndOffset) { | ||
@@ -84,3 +80,2 @@ x = x1 - x2; | ||
} | ||
context.moveTo(x1 - defX + startOffsetX, y1 - defY + startOffsetY); | ||
@@ -92,12 +87,12 @@ context.lineTo(x2 - defX + endOffsetX, y2 - defY + endOffsetY); | ||
var _parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var _parsedStyle$path = parsedStyle.path, | ||
absolutePath = _parsedStyle$path.absolutePath, | ||
segments = _parsedStyle$path.segments; | ||
absolutePath = _parsedStyle$path.absolutePath, | ||
segments = _parsedStyle$path.segments; | ||
var startOffsetX = 0; | ||
@@ -110,8 +105,6 @@ var startOffsetY = 0; | ||
var y; | ||
if (markerStart && markerStart instanceof DisplayObject && markerStartOffset) { | ||
var _markerStart$parentNo = markerStart.parentNode.getStartTangent(), | ||
p1 = _markerStart$parentNo[0], | ||
p2 = _markerStart$parentNo[1]; | ||
p1 = _markerStart$parentNo[0], | ||
p2 = _markerStart$parentNo[1]; | ||
x = p1[0] - p2[0]; | ||
@@ -123,8 +116,6 @@ y = p1[1] - p2[1]; | ||
} | ||
if (markerEnd && markerEnd instanceof DisplayObject && markerEndOffset) { | ||
var _markerEnd$parentNode = markerEnd.parentNode.getEndTangent(), | ||
_p = _markerEnd$parentNode[0], | ||
_p2 = _markerEnd$parentNode[1]; | ||
_p = _markerEnd$parentNode[0], | ||
_p2 = _markerEnd$parentNode[1]; | ||
x = _p[0] - _p2[0]; | ||
@@ -136,3 +127,2 @@ y = _p[1] - _p2[1]; | ||
} | ||
for (var i = 0; i < absolutePath.length; i++) { | ||
@@ -142,5 +132,4 @@ var params = absolutePath[i]; | ||
var nextSegment = absolutePath[i + 1]; | ||
var useStartOffset = i === 0 && startOffsetX !== 0 && startOffsetY !== 0; | ||
var useStartOffset = i === 0 && (startOffsetX !== 0 || startOffsetY !== 0); | ||
var useEndOffset = (i === absolutePath.length - 1 || nextSegment && (nextSegment[0] === 'M' || nextSegment[0] === 'Z')) && endOffsetX !== 0 && endOffsetY !== 0; | ||
switch (command) { | ||
@@ -155,5 +144,3 @@ case 'M': | ||
} | ||
break; | ||
case 'L': | ||
@@ -165,23 +152,15 @@ if (useEndOffset) { | ||
} | ||
break; | ||
case 'Q': | ||
context.quadraticCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY); | ||
if (useEndOffset) { | ||
context.lineTo(params[3] - defX + endOffsetX, params[4] - defY + endOffsetY); | ||
} | ||
break; | ||
case 'C': | ||
context.bezierCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY, params[5] - defX, params[6] - defY); | ||
if (useEndOffset) { | ||
context.lineTo(params[5] - defX + endOffsetX, params[6] - defY + endOffsetY); | ||
} | ||
break; | ||
case 'A': | ||
@@ -191,10 +170,10 @@ { | ||
var cx = arcParams.cx, | ||
cy = arcParams.cy, | ||
rx = arcParams.rx, | ||
ry = arcParams.ry, | ||
startAngle = arcParams.startAngle, | ||
endAngle = arcParams.endAngle, | ||
xRotation = arcParams.xRotation, | ||
sweepFlag = arcParams.sweepFlag; // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
cy = arcParams.cy, | ||
rx = arcParams.rx, | ||
ry = arcParams.ry, | ||
startAngle = arcParams.startAngle, | ||
endAngle = arcParams.endAngle, | ||
xRotation = arcParams.xRotation, | ||
sweepFlag = arcParams.sweepFlag; | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
if (context.ellipse) { | ||
@@ -215,10 +194,7 @@ context.ellipse(cx - defX, cy - defY, rx, ry, xRotation, startAngle, endAngle, !!(1 - sweepFlag)); | ||
} | ||
if (useEndOffset) { | ||
context.lineTo(params[6] - defX + endOffsetX, params[7] - defY + endOffsetY); | ||
} | ||
break; | ||
} | ||
case 'Z': | ||
@@ -233,9 +209,9 @@ context.closePath(); | ||
var _parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var points = parsedStyle.points.points; | ||
@@ -254,3 +230,2 @@ var length = points.length; | ||
var y; | ||
if (markerStart && markerStart instanceof DisplayObject && markerStartOffset) { | ||
@@ -263,3 +238,2 @@ x = points[1][0] - points[0][0]; | ||
} | ||
if (markerEnd && markerEnd instanceof DisplayObject && markerEndOffset) { | ||
@@ -272,5 +246,3 @@ x = points[length - 1][0] - points[0][0]; | ||
} | ||
context.moveTo(x1 + (startOffsetX || endOffsetX), y1 + (startOffsetY || endOffsetY)); | ||
for (var i = 1; i < length - 1; i++) { | ||
@@ -280,3 +252,2 @@ var point = points[i]; | ||
} | ||
context.lineTo(x2, y2); | ||
@@ -287,9 +258,9 @@ } | ||
var _parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var points = parsedStyle.points.points; | ||
@@ -308,3 +279,2 @@ var length = points.length; | ||
var y; | ||
if (markerStart && markerStart instanceof DisplayObject && markerStartOffset) { | ||
@@ -317,3 +287,2 @@ x = points[1][0] - points[0][0]; | ||
} | ||
if (markerEnd && markerEnd instanceof DisplayObject && markerEndOffset) { | ||
@@ -326,5 +295,3 @@ x = points[length - 2][0] - points[length - 1][0]; | ||
} | ||
context.moveTo(x1 + startOffsetX, y1 + startOffsetY); | ||
for (var i = 1; i < length - 1; i++) { | ||
@@ -334,3 +301,2 @@ var point = points[i]; | ||
} | ||
context.lineTo(x2 + endOffsetX, y2 + endOffsetY); | ||
@@ -341,4 +307,4 @@ } | ||
var radius = parsedStyle.radius, | ||
width = parsedStyle.width, | ||
height = parsedStyle.height; | ||
width = parsedStyle.width, | ||
height = parsedStyle.height; | ||
var w = width; | ||
@@ -349,3 +315,2 @@ var h = height; | ||
}); | ||
if (!hasRadius) { | ||
@@ -358,32 +323,23 @@ // Canvas support negative width/height of rect | ||
var sweepFlag = signX + signY === 0; | ||
var _radius$map = radius.map(function (r) { | ||
return clamp(r, 0, Math.min(Math.abs(w) / 2, Math.abs(h) / 2)); | ||
}), | ||
tlr = _radius$map[0], | ||
trr = _radius$map[1], | ||
brr = _radius$map[2], | ||
blr = _radius$map[3]; | ||
return clamp(r, 0, Math.min(Math.abs(w) / 2, Math.abs(h) / 2)); | ||
}), | ||
tlr = _radius$map[0], | ||
trr = _radius$map[1], | ||
brr = _radius$map[2], | ||
blr = _radius$map[3]; | ||
context.moveTo(signX * tlr, 0); | ||
context.lineTo(w - signX * trr, 0); | ||
if (trr !== 0) { | ||
context.arc(w - signX * trr, signY * trr, trr, -signY * Math.PI / 2, signX > 0 ? 0 : Math.PI, sweepFlag); | ||
} | ||
context.lineTo(w, h - signY * brr); | ||
if (brr !== 0) { | ||
context.arc(w - signX * brr, h - signY * brr, brr, signX > 0 ? 0 : Math.PI, signY > 0 ? Math.PI / 2 : 1.5 * Math.PI, sweepFlag); | ||
} | ||
context.lineTo(signX * blr, h); | ||
if (blr !== 0) { | ||
context.arc(signX * blr, h - signY * blr, blr, signY > 0 ? Math.PI / 2 : -Math.PI / 2, signX > 0 ? Math.PI : 0, sweepFlag); | ||
} | ||
context.lineTo(0, signY * tlr); | ||
if (tlr !== 0) { | ||
@@ -397,10 +353,7 @@ context.arc(signX * tlr, signY * tlr, tlr, signX > 0 ? Math.PI : 0, signY > 0 ? Math.PI * 1.5 : Math.PI / 2, sweepFlag); | ||
_inheritsLoose(Plugin, _AbstractRendererPlug); | ||
function Plugin() { | ||
var _this; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this; | ||
@@ -410,13 +363,9 @@ _this.name = 'canvas-path-generator'; | ||
} | ||
var _proto = Plugin.prototype; | ||
_proto.init = function init() { | ||
var _pathGeneratorFactory; | ||
var pathGeneratorFactory = (_pathGeneratorFactory = {}, _pathGeneratorFactory[Shape.CIRCLE] = generatePath, _pathGeneratorFactory[Shape.ELLIPSE] = generatePath$1, _pathGeneratorFactory[Shape.RECT] = generatePath$6, _pathGeneratorFactory[Shape.LINE] = generatePath$2, _pathGeneratorFactory[Shape.POLYLINE] = generatePath$5, _pathGeneratorFactory[Shape.POLYGON] = generatePath$4, _pathGeneratorFactory[Shape.PATH] = generatePath$3, _pathGeneratorFactory[Shape.TEXT] = undefined, _pathGeneratorFactory[Shape.GROUP] = undefined, _pathGeneratorFactory[Shape.IMAGE] = undefined, _pathGeneratorFactory[Shape.HTML] = undefined, _pathGeneratorFactory[Shape.MESH] = undefined, _pathGeneratorFactory); // @ts-ignore | ||
var pathGeneratorFactory = (_pathGeneratorFactory = {}, _pathGeneratorFactory[Shape.CIRCLE] = generatePath, _pathGeneratorFactory[Shape.ELLIPSE] = generatePath$1, _pathGeneratorFactory[Shape.RECT] = generatePath$6, _pathGeneratorFactory[Shape.LINE] = generatePath$2, _pathGeneratorFactory[Shape.POLYLINE] = generatePath$5, _pathGeneratorFactory[Shape.POLYGON] = generatePath$4, _pathGeneratorFactory[Shape.PATH] = generatePath$3, _pathGeneratorFactory[Shape.TEXT] = undefined, _pathGeneratorFactory[Shape.GROUP] = undefined, _pathGeneratorFactory[Shape.IMAGE] = undefined, _pathGeneratorFactory[Shape.HTML] = undefined, _pathGeneratorFactory[Shape.MESH] = undefined, _pathGeneratorFactory); | ||
// @ts-ignore | ||
this.context.pathGeneratorFactory = pathGeneratorFactory; | ||
}; | ||
_proto.destroy = function destroy() { | ||
@@ -426,3 +375,2 @@ // @ts-ignore | ||
}; | ||
return Plugin; | ||
@@ -429,0 +377,0 @@ }(AbstractRendererPlugin); |
@@ -11,6 +11,4 @@ 'use strict'; | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
@@ -31,6 +29,6 @@ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
var rxInPixels = parsedStyle.rx, | ||
ryInPixels = parsedStyle.ry; | ||
ryInPixels = parsedStyle.ry; | ||
var rx = rxInPixels; | ||
var ry = ryInPixels; // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
var ry = ryInPixels; | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
if (context.ellipse) { | ||
@@ -51,13 +49,13 @@ context.ellipse(rx, ry, rx, ry, 0, 0, Math.PI * 2, false); | ||
var x1 = parsedStyle.x1, | ||
y1 = parsedStyle.y1, | ||
x2 = parsedStyle.x2, | ||
y2 = parsedStyle.y2, | ||
_parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
y1 = parsedStyle.y1, | ||
x2 = parsedStyle.x2, | ||
y2 = parsedStyle.y2, | ||
_parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var startOffsetX = 0; | ||
@@ -70,3 +68,2 @@ var startOffsetY = 0; | ||
var y; | ||
if (markerStart && markerStart instanceof gLite.DisplayObject && markerStartOffset) { | ||
@@ -79,3 +76,2 @@ x = x2 - x1; | ||
} | ||
if (markerEnd && markerEnd instanceof gLite.DisplayObject && markerEndOffset) { | ||
@@ -88,3 +84,2 @@ x = x1 - x2; | ||
} | ||
context.moveTo(x1 - defX + startOffsetX, y1 - defY + startOffsetY); | ||
@@ -96,12 +91,12 @@ context.lineTo(x2 - defX + endOffsetX, y2 - defY + endOffsetY); | ||
var _parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var _parsedStyle$path = parsedStyle.path, | ||
absolutePath = _parsedStyle$path.absolutePath, | ||
segments = _parsedStyle$path.segments; | ||
absolutePath = _parsedStyle$path.absolutePath, | ||
segments = _parsedStyle$path.segments; | ||
var startOffsetX = 0; | ||
@@ -114,8 +109,6 @@ var startOffsetY = 0; | ||
var y; | ||
if (markerStart && markerStart instanceof gLite.DisplayObject && markerStartOffset) { | ||
var _markerStart$parentNo = markerStart.parentNode.getStartTangent(), | ||
p1 = _markerStart$parentNo[0], | ||
p2 = _markerStart$parentNo[1]; | ||
p1 = _markerStart$parentNo[0], | ||
p2 = _markerStart$parentNo[1]; | ||
x = p1[0] - p2[0]; | ||
@@ -127,8 +120,6 @@ y = p1[1] - p2[1]; | ||
} | ||
if (markerEnd && markerEnd instanceof gLite.DisplayObject && markerEndOffset) { | ||
var _markerEnd$parentNode = markerEnd.parentNode.getEndTangent(), | ||
_p = _markerEnd$parentNode[0], | ||
_p2 = _markerEnd$parentNode[1]; | ||
_p = _markerEnd$parentNode[0], | ||
_p2 = _markerEnd$parentNode[1]; | ||
x = _p[0] - _p2[0]; | ||
@@ -140,3 +131,2 @@ y = _p[1] - _p2[1]; | ||
} | ||
for (var i = 0; i < absolutePath.length; i++) { | ||
@@ -146,5 +136,4 @@ var params = absolutePath[i]; | ||
var nextSegment = absolutePath[i + 1]; | ||
var useStartOffset = i === 0 && startOffsetX !== 0 && startOffsetY !== 0; | ||
var useStartOffset = i === 0 && (startOffsetX !== 0 || startOffsetY !== 0); | ||
var useEndOffset = (i === absolutePath.length - 1 || nextSegment && (nextSegment[0] === 'M' || nextSegment[0] === 'Z')) && endOffsetX !== 0 && endOffsetY !== 0; | ||
switch (command) { | ||
@@ -159,5 +148,3 @@ case 'M': | ||
} | ||
break; | ||
case 'L': | ||
@@ -169,23 +156,15 @@ if (useEndOffset) { | ||
} | ||
break; | ||
case 'Q': | ||
context.quadraticCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY); | ||
if (useEndOffset) { | ||
context.lineTo(params[3] - defX + endOffsetX, params[4] - defY + endOffsetY); | ||
} | ||
break; | ||
case 'C': | ||
context.bezierCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY, params[5] - defX, params[6] - defY); | ||
if (useEndOffset) { | ||
context.lineTo(params[5] - defX + endOffsetX, params[6] - defY + endOffsetY); | ||
} | ||
break; | ||
case 'A': | ||
@@ -195,10 +174,10 @@ { | ||
var cx = arcParams.cx, | ||
cy = arcParams.cy, | ||
rx = arcParams.rx, | ||
ry = arcParams.ry, | ||
startAngle = arcParams.startAngle, | ||
endAngle = arcParams.endAngle, | ||
xRotation = arcParams.xRotation, | ||
sweepFlag = arcParams.sweepFlag; // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
cy = arcParams.cy, | ||
rx = arcParams.rx, | ||
ry = arcParams.ry, | ||
startAngle = arcParams.startAngle, | ||
endAngle = arcParams.endAngle, | ||
xRotation = arcParams.xRotation, | ||
sweepFlag = arcParams.sweepFlag; | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
if (context.ellipse) { | ||
@@ -219,10 +198,7 @@ context.ellipse(cx - defX, cy - defY, rx, ry, xRotation, startAngle, endAngle, !!(1 - sweepFlag)); | ||
} | ||
if (useEndOffset) { | ||
context.lineTo(params[6] - defX + endOffsetX, params[7] - defY + endOffsetY); | ||
} | ||
break; | ||
} | ||
case 'Z': | ||
@@ -237,9 +213,9 @@ context.closePath(); | ||
var _parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var points = parsedStyle.points.points; | ||
@@ -258,3 +234,2 @@ var length = points.length; | ||
var y; | ||
if (markerStart && markerStart instanceof gLite.DisplayObject && markerStartOffset) { | ||
@@ -267,3 +242,2 @@ x = points[1][0] - points[0][0]; | ||
} | ||
if (markerEnd && markerEnd instanceof gLite.DisplayObject && markerEndOffset) { | ||
@@ -276,5 +250,3 @@ x = points[length - 1][0] - points[0][0]; | ||
} | ||
context.moveTo(x1 + (startOffsetX || endOffsetX), y1 + (startOffsetY || endOffsetY)); | ||
for (var i = 1; i < length - 1; i++) { | ||
@@ -284,3 +256,2 @@ var point = points[i]; | ||
} | ||
context.lineTo(x2, y2); | ||
@@ -291,9 +262,9 @@ } | ||
var _parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var points = parsedStyle.points.points; | ||
@@ -312,3 +283,2 @@ var length = points.length; | ||
var y; | ||
if (markerStart && markerStart instanceof gLite.DisplayObject && markerStartOffset) { | ||
@@ -321,3 +291,2 @@ x = points[1][0] - points[0][0]; | ||
} | ||
if (markerEnd && markerEnd instanceof gLite.DisplayObject && markerEndOffset) { | ||
@@ -330,5 +299,3 @@ x = points[length - 2][0] - points[length - 1][0]; | ||
} | ||
context.moveTo(x1 + startOffsetX, y1 + startOffsetY); | ||
for (var i = 1; i < length - 1; i++) { | ||
@@ -338,3 +305,2 @@ var point = points[i]; | ||
} | ||
context.lineTo(x2 + endOffsetX, y2 + endOffsetY); | ||
@@ -345,4 +311,4 @@ } | ||
var radius = parsedStyle.radius, | ||
width = parsedStyle.width, | ||
height = parsedStyle.height; | ||
width = parsedStyle.width, | ||
height = parsedStyle.height; | ||
var w = width; | ||
@@ -353,3 +319,2 @@ var h = height; | ||
}); | ||
if (!hasRadius) { | ||
@@ -362,32 +327,23 @@ // Canvas support negative width/height of rect | ||
var sweepFlag = signX + signY === 0; | ||
var _radius$map = radius.map(function (r) { | ||
return util.clamp(r, 0, Math.min(Math.abs(w) / 2, Math.abs(h) / 2)); | ||
}), | ||
tlr = _radius$map[0], | ||
trr = _radius$map[1], | ||
brr = _radius$map[2], | ||
blr = _radius$map[3]; | ||
return util.clamp(r, 0, Math.min(Math.abs(w) / 2, Math.abs(h) / 2)); | ||
}), | ||
tlr = _radius$map[0], | ||
trr = _radius$map[1], | ||
brr = _radius$map[2], | ||
blr = _radius$map[3]; | ||
context.moveTo(signX * tlr, 0); | ||
context.lineTo(w - signX * trr, 0); | ||
if (trr !== 0) { | ||
context.arc(w - signX * trr, signY * trr, trr, -signY * Math.PI / 2, signX > 0 ? 0 : Math.PI, sweepFlag); | ||
} | ||
context.lineTo(w, h - signY * brr); | ||
if (brr !== 0) { | ||
context.arc(w - signX * brr, h - signY * brr, brr, signX > 0 ? 0 : Math.PI, signY > 0 ? Math.PI / 2 : 1.5 * Math.PI, sweepFlag); | ||
} | ||
context.lineTo(signX * blr, h); | ||
if (blr !== 0) { | ||
context.arc(signX * blr, h - signY * blr, blr, signY > 0 ? Math.PI / 2 : -Math.PI / 2, signX > 0 ? Math.PI : 0, sweepFlag); | ||
} | ||
context.lineTo(0, signY * tlr); | ||
if (tlr !== 0) { | ||
@@ -401,10 +357,7 @@ context.arc(signX * tlr, signY * tlr, tlr, signX > 0 ? Math.PI : 0, signY > 0 ? Math.PI * 1.5 : Math.PI / 2, sweepFlag); | ||
_inheritsLoose(Plugin, _AbstractRendererPlug); | ||
function Plugin() { | ||
var _this; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this; | ||
@@ -414,13 +367,9 @@ _this.name = 'canvas-path-generator'; | ||
} | ||
var _proto = Plugin.prototype; | ||
_proto.init = function init() { | ||
var _pathGeneratorFactory; | ||
var pathGeneratorFactory = (_pathGeneratorFactory = {}, _pathGeneratorFactory[gLite.Shape.CIRCLE] = generatePath, _pathGeneratorFactory[gLite.Shape.ELLIPSE] = generatePath$1, _pathGeneratorFactory[gLite.Shape.RECT] = generatePath$6, _pathGeneratorFactory[gLite.Shape.LINE] = generatePath$2, _pathGeneratorFactory[gLite.Shape.POLYLINE] = generatePath$5, _pathGeneratorFactory[gLite.Shape.POLYGON] = generatePath$4, _pathGeneratorFactory[gLite.Shape.PATH] = generatePath$3, _pathGeneratorFactory[gLite.Shape.TEXT] = undefined, _pathGeneratorFactory[gLite.Shape.GROUP] = undefined, _pathGeneratorFactory[gLite.Shape.IMAGE] = undefined, _pathGeneratorFactory[gLite.Shape.HTML] = undefined, _pathGeneratorFactory[gLite.Shape.MESH] = undefined, _pathGeneratorFactory); // @ts-ignore | ||
var pathGeneratorFactory = (_pathGeneratorFactory = {}, _pathGeneratorFactory[gLite.Shape.CIRCLE] = generatePath, _pathGeneratorFactory[gLite.Shape.ELLIPSE] = generatePath$1, _pathGeneratorFactory[gLite.Shape.RECT] = generatePath$6, _pathGeneratorFactory[gLite.Shape.LINE] = generatePath$2, _pathGeneratorFactory[gLite.Shape.POLYLINE] = generatePath$5, _pathGeneratorFactory[gLite.Shape.POLYGON] = generatePath$4, _pathGeneratorFactory[gLite.Shape.PATH] = generatePath$3, _pathGeneratorFactory[gLite.Shape.TEXT] = undefined, _pathGeneratorFactory[gLite.Shape.GROUP] = undefined, _pathGeneratorFactory[gLite.Shape.IMAGE] = undefined, _pathGeneratorFactory[gLite.Shape.HTML] = undefined, _pathGeneratorFactory[gLite.Shape.MESH] = undefined, _pathGeneratorFactory); | ||
// @ts-ignore | ||
this.context.pathGeneratorFactory = pathGeneratorFactory; | ||
}; | ||
_proto.destroy = function destroy() { | ||
@@ -430,3 +379,2 @@ // @ts-ignore | ||
}; | ||
return Plugin; | ||
@@ -433,0 +381,0 @@ }(gLite.AbstractRendererPlugin); |
@@ -10,6 +10,4 @@ (function (global, factory) { | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
@@ -30,6 +28,6 @@ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
var rxInPixels = parsedStyle.rx, | ||
ryInPixels = parsedStyle.ry; | ||
ryInPixels = parsedStyle.ry; | ||
var rx = rxInPixels; | ||
var ry = ryInPixels; // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
var ry = ryInPixels; | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
if (context.ellipse) { | ||
@@ -50,13 +48,13 @@ context.ellipse(rx, ry, rx, ry, 0, 0, Math.PI * 2, false); | ||
var x1 = parsedStyle.x1, | ||
y1 = parsedStyle.y1, | ||
x2 = parsedStyle.x2, | ||
y2 = parsedStyle.y2, | ||
_parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
y1 = parsedStyle.y1, | ||
x2 = parsedStyle.x2, | ||
y2 = parsedStyle.y2, | ||
_parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var startOffsetX = 0; | ||
@@ -69,3 +67,2 @@ var startOffsetY = 0; | ||
var y; | ||
if (markerStart && markerStart instanceof gLite.DisplayObject && markerStartOffset) { | ||
@@ -78,3 +75,2 @@ x = x2 - x1; | ||
} | ||
if (markerEnd && markerEnd instanceof gLite.DisplayObject && markerEndOffset) { | ||
@@ -87,3 +83,2 @@ x = x1 - x2; | ||
} | ||
context.moveTo(x1 - defX + startOffsetX, y1 - defY + startOffsetY); | ||
@@ -95,12 +90,12 @@ context.lineTo(x2 - defX + endOffsetX, y2 - defY + endOffsetY); | ||
var _parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var _parsedStyle$path = parsedStyle.path, | ||
absolutePath = _parsedStyle$path.absolutePath, | ||
segments = _parsedStyle$path.segments; | ||
absolutePath = _parsedStyle$path.absolutePath, | ||
segments = _parsedStyle$path.segments; | ||
var startOffsetX = 0; | ||
@@ -113,8 +108,6 @@ var startOffsetY = 0; | ||
var y; | ||
if (markerStart && markerStart instanceof gLite.DisplayObject && markerStartOffset) { | ||
var _markerStart$parentNo = markerStart.parentNode.getStartTangent(), | ||
p1 = _markerStart$parentNo[0], | ||
p2 = _markerStart$parentNo[1]; | ||
p1 = _markerStart$parentNo[0], | ||
p2 = _markerStart$parentNo[1]; | ||
x = p1[0] - p2[0]; | ||
@@ -126,8 +119,6 @@ y = p1[1] - p2[1]; | ||
} | ||
if (markerEnd && markerEnd instanceof gLite.DisplayObject && markerEndOffset) { | ||
var _markerEnd$parentNode = markerEnd.parentNode.getEndTangent(), | ||
_p = _markerEnd$parentNode[0], | ||
_p2 = _markerEnd$parentNode[1]; | ||
_p = _markerEnd$parentNode[0], | ||
_p2 = _markerEnd$parentNode[1]; | ||
x = _p[0] - _p2[0]; | ||
@@ -139,3 +130,2 @@ y = _p[1] - _p2[1]; | ||
} | ||
for (var i = 0; i < absolutePath.length; i++) { | ||
@@ -145,5 +135,4 @@ var params = absolutePath[i]; | ||
var nextSegment = absolutePath[i + 1]; | ||
var useStartOffset = i === 0 && startOffsetX !== 0 && startOffsetY !== 0; | ||
var useStartOffset = i === 0 && (startOffsetX !== 0 || startOffsetY !== 0); | ||
var useEndOffset = (i === absolutePath.length - 1 || nextSegment && (nextSegment[0] === 'M' || nextSegment[0] === 'Z')) && endOffsetX !== 0 && endOffsetY !== 0; | ||
switch (command) { | ||
@@ -158,5 +147,3 @@ case 'M': | ||
} | ||
break; | ||
case 'L': | ||
@@ -168,23 +155,15 @@ if (useEndOffset) { | ||
} | ||
break; | ||
case 'Q': | ||
context.quadraticCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY); | ||
if (useEndOffset) { | ||
context.lineTo(params[3] - defX + endOffsetX, params[4] - defY + endOffsetY); | ||
} | ||
break; | ||
case 'C': | ||
context.bezierCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY, params[5] - defX, params[6] - defY); | ||
if (useEndOffset) { | ||
context.lineTo(params[5] - defX + endOffsetX, params[6] - defY + endOffsetY); | ||
} | ||
break; | ||
case 'A': | ||
@@ -194,10 +173,10 @@ { | ||
var cx = arcParams.cx, | ||
cy = arcParams.cy, | ||
rx = arcParams.rx, | ||
ry = arcParams.ry, | ||
startAngle = arcParams.startAngle, | ||
endAngle = arcParams.endAngle, | ||
xRotation = arcParams.xRotation, | ||
sweepFlag = arcParams.sweepFlag; // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
cy = arcParams.cy, | ||
rx = arcParams.rx, | ||
ry = arcParams.ry, | ||
startAngle = arcParams.startAngle, | ||
endAngle = arcParams.endAngle, | ||
xRotation = arcParams.xRotation, | ||
sweepFlag = arcParams.sweepFlag; | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse | ||
if (context.ellipse) { | ||
@@ -218,10 +197,7 @@ context.ellipse(cx - defX, cy - defY, rx, ry, xRotation, startAngle, endAngle, !!(1 - sweepFlag)); | ||
} | ||
if (useEndOffset) { | ||
context.lineTo(params[6] - defX + endOffsetX, params[7] - defY + endOffsetY); | ||
} | ||
break; | ||
} | ||
case 'Z': | ||
@@ -236,9 +212,9 @@ context.closePath(); | ||
var _parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var points = parsedStyle.points.points; | ||
@@ -257,3 +233,2 @@ var length = points.length; | ||
var y; | ||
if (markerStart && markerStart instanceof gLite.DisplayObject && markerStartOffset) { | ||
@@ -266,3 +241,2 @@ x = points[1][0] - points[0][0]; | ||
} | ||
if (markerEnd && markerEnd instanceof gLite.DisplayObject && markerEndOffset) { | ||
@@ -275,5 +249,3 @@ x = points[length - 1][0] - points[0][0]; | ||
} | ||
context.moveTo(x1 + (startOffsetX || endOffsetX), y1 + (startOffsetY || endOffsetY)); | ||
for (var i = 1; i < length - 1; i++) { | ||
@@ -283,3 +255,2 @@ var point = points[i]; | ||
} | ||
context.lineTo(x2, y2); | ||
@@ -290,9 +261,9 @@ } | ||
var _parsedStyle$defX = parsedStyle.defX, | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX, | ||
_parsedStyle$defY = parsedStyle.defY, | ||
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY, | ||
markerStart = parsedStyle.markerStart, | ||
markerEnd = parsedStyle.markerEnd, | ||
markerStartOffset = parsedStyle.markerStartOffset, | ||
markerEndOffset = parsedStyle.markerEndOffset; | ||
var points = parsedStyle.points.points; | ||
@@ -311,3 +282,2 @@ var length = points.length; | ||
var y; | ||
if (markerStart && markerStart instanceof gLite.DisplayObject && markerStartOffset) { | ||
@@ -320,3 +290,2 @@ x = points[1][0] - points[0][0]; | ||
} | ||
if (markerEnd && markerEnd instanceof gLite.DisplayObject && markerEndOffset) { | ||
@@ -329,5 +298,3 @@ x = points[length - 2][0] - points[length - 1][0]; | ||
} | ||
context.moveTo(x1 + startOffsetX, y1 + startOffsetY); | ||
for (var i = 1; i < length - 1; i++) { | ||
@@ -337,3 +304,2 @@ var point = points[i]; | ||
} | ||
context.lineTo(x2 + endOffsetX, y2 + endOffsetY); | ||
@@ -354,4 +320,4 @@ } | ||
var radius = parsedStyle.radius, | ||
width = parsedStyle.width, | ||
height = parsedStyle.height; | ||
width = parsedStyle.width, | ||
height = parsedStyle.height; | ||
var w = width; | ||
@@ -362,3 +328,2 @@ var h = height; | ||
}); | ||
if (!hasRadius) { | ||
@@ -371,32 +336,23 @@ // Canvas support negative width/height of rect | ||
var sweepFlag = signX + signY === 0; | ||
var _radius$map = radius.map(function (r) { | ||
return clamp(r, 0, Math.min(Math.abs(w) / 2, Math.abs(h) / 2)); | ||
}), | ||
tlr = _radius$map[0], | ||
trr = _radius$map[1], | ||
brr = _radius$map[2], | ||
blr = _radius$map[3]; | ||
return clamp(r, 0, Math.min(Math.abs(w) / 2, Math.abs(h) / 2)); | ||
}), | ||
tlr = _radius$map[0], | ||
trr = _radius$map[1], | ||
brr = _radius$map[2], | ||
blr = _radius$map[3]; | ||
context.moveTo(signX * tlr, 0); | ||
context.lineTo(w - signX * trr, 0); | ||
if (trr !== 0) { | ||
context.arc(w - signX * trr, signY * trr, trr, -signY * Math.PI / 2, signX > 0 ? 0 : Math.PI, sweepFlag); | ||
} | ||
context.lineTo(w, h - signY * brr); | ||
if (brr !== 0) { | ||
context.arc(w - signX * brr, h - signY * brr, brr, signX > 0 ? 0 : Math.PI, signY > 0 ? Math.PI / 2 : 1.5 * Math.PI, sweepFlag); | ||
} | ||
context.lineTo(signX * blr, h); | ||
if (blr !== 0) { | ||
context.arc(signX * blr, h - signY * blr, blr, signY > 0 ? Math.PI / 2 : -Math.PI / 2, signX > 0 ? Math.PI : 0, sweepFlag); | ||
} | ||
context.lineTo(0, signY * tlr); | ||
if (tlr !== 0) { | ||
@@ -410,10 +366,7 @@ context.arc(signX * tlr, signY * tlr, tlr, signX > 0 ? Math.PI : 0, signY > 0 ? Math.PI * 1.5 : Math.PI / 2, sweepFlag); | ||
_inheritsLoose(Plugin, _AbstractRendererPlug); | ||
function Plugin() { | ||
var _this; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this; | ||
@@ -423,13 +376,9 @@ _this.name = 'canvas-path-generator'; | ||
} | ||
var _proto = Plugin.prototype; | ||
_proto.init = function init() { | ||
var _pathGeneratorFactory; | ||
var pathGeneratorFactory = (_pathGeneratorFactory = {}, _pathGeneratorFactory[gLite.Shape.CIRCLE] = generatePath, _pathGeneratorFactory[gLite.Shape.ELLIPSE] = generatePath$1, _pathGeneratorFactory[gLite.Shape.RECT] = generatePath$6, _pathGeneratorFactory[gLite.Shape.LINE] = generatePath$2, _pathGeneratorFactory[gLite.Shape.POLYLINE] = generatePath$5, _pathGeneratorFactory[gLite.Shape.POLYGON] = generatePath$4, _pathGeneratorFactory[gLite.Shape.PATH] = generatePath$3, _pathGeneratorFactory[gLite.Shape.TEXT] = undefined, _pathGeneratorFactory[gLite.Shape.GROUP] = undefined, _pathGeneratorFactory[gLite.Shape.IMAGE] = undefined, _pathGeneratorFactory[gLite.Shape.HTML] = undefined, _pathGeneratorFactory[gLite.Shape.MESH] = undefined, _pathGeneratorFactory); // @ts-ignore | ||
var pathGeneratorFactory = (_pathGeneratorFactory = {}, _pathGeneratorFactory[gLite.Shape.CIRCLE] = generatePath, _pathGeneratorFactory[gLite.Shape.ELLIPSE] = generatePath$1, _pathGeneratorFactory[gLite.Shape.RECT] = generatePath$6, _pathGeneratorFactory[gLite.Shape.LINE] = generatePath$2, _pathGeneratorFactory[gLite.Shape.POLYLINE] = generatePath$5, _pathGeneratorFactory[gLite.Shape.POLYGON] = generatePath$4, _pathGeneratorFactory[gLite.Shape.PATH] = generatePath$3, _pathGeneratorFactory[gLite.Shape.TEXT] = undefined, _pathGeneratorFactory[gLite.Shape.GROUP] = undefined, _pathGeneratorFactory[gLite.Shape.IMAGE] = undefined, _pathGeneratorFactory[gLite.Shape.HTML] = undefined, _pathGeneratorFactory[gLite.Shape.MESH] = undefined, _pathGeneratorFactory); | ||
// @ts-ignore | ||
this.context.pathGeneratorFactory = pathGeneratorFactory; | ||
}; | ||
_proto.destroy = function destroy() { | ||
@@ -439,3 +388,2 @@ // @ts-ignore | ||
}; | ||
return Plugin; | ||
@@ -442,0 +390,0 @@ }(gLite.AbstractRendererPlugin); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g-lite")):"function"==typeof define&&define.amd?define(["exports","@antv/g-lite"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).G=t.G||{},t.G.CanvasPathGenerator={}),t.window.G)}(this,(function(t,e){"use strict";function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}function n(t,e){var a=e.r;t.arc(a,a,a,0,2*Math.PI,!1)}function r(t,e){var a=e.rx,n=e.ry;if(t.ellipse)t.ellipse(a,n,a,n,0,0,2*Math.PI,!1);else{var r=a>n?a:n,o=a>n?1:a/n,i=a>n?n/a:1;t.save(),t.scale(o,i),t.arc(0,0,r,0,2*Math.PI)}}function o(t,a){var n,r,o=a.x1,i=a.y1,s=a.x2,c=a.y2,h=a.defX,f=void 0===h?0:h,l=a.defY,p=void 0===l?0:l,d=a.markerStart,v=a.markerEnd,M=a.markerStartOffset,u=a.markerEndOffset,T=0,m=0,y=0,P=0,b=0;d&&d instanceof e.DisplayObject&&M&&(n=s-o,r=c-i,b=Math.atan2(r,n),T=Math.cos(b)*(M||0),m=Math.sin(b)*(M||0)),v&&v instanceof e.DisplayObject&&u&&(n=o-s,r=i-c,b=Math.atan2(r,n),y=Math.cos(b)*(u||0),P=Math.sin(b)*(u||0)),t.moveTo(o-f+T,i-p+m),t.lineTo(s-f+y,c-p+P)}function i(t,a){var n,r,o=a.defX,i=void 0===o?0:o,s=a.defY,c=void 0===s?0:s,h=a.markerStart,f=a.markerEnd,l=a.markerStartOffset,p=a.markerEndOffset,d=a.path,v=d.absolutePath,M=d.segments,u=0,T=0,m=0,y=0,P=0;if(h&&h instanceof e.DisplayObject&&l){var b=h.parentNode.getStartTangent(),O=b[0],S=b[1];n=O[0]-S[0],r=O[1]-S[1],P=Math.atan2(r,n),u=Math.cos(P)*(l||0),T=Math.sin(P)*(l||0)}if(f&&f instanceof e.DisplayObject&&p){var g=f.parentNode.getEndTangent(),k=g[0],I=g[1];n=k[0]-I[0],r=k[1]-I[1],P=Math.atan2(r,n),m=Math.cos(P)*(p||0),y=Math.sin(P)*(p||0)}for(var E=0;v.length>E;E++){var j=v[E],x=v[E+1],G=0===E&&0!==u&&0!==T,L=(E===v.length-1||x&&("M"===x[0]||"Z"===x[0]))&&0!==m&&0!==y;switch(j[0]){case"M":G?(t.moveTo(j[1]-i+u,j[2]-c+T),t.lineTo(j[1]-i,j[2]-c)):t.moveTo(j[1]-i,j[2]-c);break;case"L":L?t.lineTo(j[1]-i+m,j[2]-c+y):t.lineTo(j[1]-i,j[2]-c);break;case"Q":t.quadraticCurveTo(j[1]-i,j[2]-c,j[3]-i,j[4]-c),L&&t.lineTo(j[3]-i+m,j[4]-c+y);break;case"C":t.bezierCurveTo(j[1]-i,j[2]-c,j[3]-i,j[4]-c,j[5]-i,j[6]-c),L&&t.lineTo(j[5]-i+m,j[6]-c+y);break;case"A":var D=M[E].arcParams,A=D.cx,C=D.cy,w=D.rx,Y=D.ry,_=D.startAngle,N=D.endAngle,R=D.xRotation,X=D.sweepFlag;if(t.ellipse)t.ellipse(A-i,C-c,w,Y,R,_,N,!!(1-X));else{var F=w>Y?w:Y,H=w>Y?1:w/Y,q=w>Y?Y/w:1;t.translate(A-i,C-c),t.rotate(R),t.scale(H,q),t.arc(0,0,F,_,N,!!(1-X)),t.scale(1/H,1/q),t.rotate(-R),t.translate(-(A-i),-(C-c))}L&&t.lineTo(j[6]-i+m,j[7]-c+y);break;case"Z":t.closePath()}}}function s(t,a){var n,r,o=a.defX,i=void 0===o?0:o,s=a.defY,c=void 0===s?0:s,h=a.markerStart,f=a.markerEnd,l=a.markerStartOffset,p=a.markerEndOffset,d=a.points.points,v=d.length,M=d[0][0]-i,u=d[0][1]-c,T=d[v-1][0]-i,m=d[v-1][1]-c,y=0,P=0,b=0,O=0,S=0;h&&h instanceof e.DisplayObject&&l&&(n=d[1][0]-d[0][0],r=d[1][1]-d[0][1],S=Math.atan2(r,n),y=Math.cos(S)*(l||0),P=Math.sin(S)*(l||0)),f&&f instanceof e.DisplayObject&&p&&(n=d[v-1][0]-d[0][0],r=d[v-1][1]-d[0][1],S=Math.atan2(r,n),b=Math.cos(S)*(p||0),O=Math.sin(S)*(p||0)),t.moveTo(M+(y||b),u+(P||O));for(var g=1;v-1>g;g++){var k=d[g];t.lineTo(k[0]-i,k[1]-c)}t.lineTo(T,m)}function c(t,a){var n,r,o=a.defX,i=void 0===o?0:o,s=a.defY,c=void 0===s?0:s,h=a.markerStart,f=a.markerEnd,l=a.markerStartOffset,p=a.markerEndOffset,d=a.points.points,v=d.length,M=d[0][0]-i,u=d[0][1]-c,T=d[v-1][0]-i,m=d[v-1][1]-c,y=0,P=0,b=0,O=0,S=0;h&&h instanceof e.DisplayObject&&l&&(n=d[1][0]-d[0][0],r=d[1][1]-d[0][1],S=Math.atan2(r,n),y=Math.cos(S)*(l||0),P=Math.sin(S)*(l||0)),f&&f instanceof e.DisplayObject&&p&&(n=d[v-2][0]-d[v-1][0],r=d[v-2][1]-d[v-1][1],S=Math.atan2(r,n),b=Math.cos(S)*(p||0),O=Math.sin(S)*(p||0)),t.moveTo(M+y,u+P);for(var g=1;v-1>g;g++){var k=d[g];t.lineTo(k[0]-i,k[1]-c)}t.lineTo(T+b,m+O)}function h(t,e){var a=e.radius,n=e.width,r=e.height,o=n,i=r;if(a&&a.some((function(t){return 0!==t}))){var s=n>0?1:-1,c=r>0?1:-1,h=s+c===0,f=a.map((function(t){return e=t,a=0,n=Math.min(Math.abs(o)/2,Math.abs(i)/2),a>e?a:e>n?n:e;var e,a,n})),l=f[0],p=f[1],d=f[2],v=f[3];t.moveTo(s*l,0),t.lineTo(o-s*p,0),0!==p&&t.arc(o-s*p,c*p,p,-c*Math.PI/2,s>0?0:Math.PI,h),t.lineTo(o,i-c*d),0!==d&&t.arc(o-s*d,i-c*d,d,s>0?0:Math.PI,c>0?Math.PI/2:1.5*Math.PI,h),t.lineTo(s*v,i),0!==v&&t.arc(s*v,i-c*v,v,c>0?Math.PI/2:-Math.PI/2,s>0?Math.PI:0,h),t.lineTo(0,c*l),0!==l&&t.arc(s*l,c*l,l,s>0?Math.PI:0,c>0?1.5*Math.PI:Math.PI/2,h)}else t.rect(0,0,o,i)}var f=function(t){var f,l;function p(){for(var e,a=arguments.length,n=new Array(a),r=0;a>r;r++)n[r]=arguments[r];return(e=t.call.apply(t,[this].concat(n))||this).name="canvas-path-generator",e}l=t,(f=p).prototype=Object.create(l.prototype),f.prototype.constructor=f,a(f,l);var d=p.prototype;return d.init=function(){var t,a=((t={})[e.Shape.CIRCLE]=n,t[e.Shape.ELLIPSE]=r,t[e.Shape.RECT]=h,t[e.Shape.LINE]=o,t[e.Shape.POLYLINE]=c,t[e.Shape.POLYGON]=s,t[e.Shape.PATH]=i,t[e.Shape.TEXT]=void 0,t[e.Shape.GROUP]=void 0,t[e.Shape.IMAGE]=void 0,t[e.Shape.HTML]=void 0,t[e.Shape.MESH]=void 0,t);this.context.pathGeneratorFactory=a},d.destroy=function(){delete this.context.pathGeneratorFactory},p}(e.AbstractRendererPlugin);t.Plugin=f,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g-lite")):"function"==typeof define&&define.amd?define(["exports","@antv/g-lite"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).G=t.G||{},t.G.CanvasPathGenerator={}),t.window.G)}(this,(function(t,e){"use strict";function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}function n(t,e){var a=e.r;t.arc(a,a,a,0,2*Math.PI,!1)}function r(t,e){var a=e.rx,n=e.ry;if(t.ellipse)t.ellipse(a,n,a,n,0,0,2*Math.PI,!1);else{var r=a>n?a:n,o=a>n?1:a/n,i=a>n?n/a:1;t.save(),t.scale(o,i),t.arc(0,0,r,0,2*Math.PI)}}function o(t,a){var n,r,o=a.x1,i=a.y1,s=a.x2,c=a.y2,h=a.defX,f=void 0===h?0:h,l=a.defY,p=void 0===l?0:l,d=a.markerStart,v=a.markerEnd,M=a.markerStartOffset,u=a.markerEndOffset,T=0,m=0,y=0,P=0,b=0;d&&d instanceof e.DisplayObject&&M&&(n=s-o,r=c-i,b=Math.atan2(r,n),T=Math.cos(b)*(M||0),m=Math.sin(b)*(M||0)),v&&v instanceof e.DisplayObject&&u&&(n=o-s,r=i-c,b=Math.atan2(r,n),y=Math.cos(b)*(u||0),P=Math.sin(b)*(u||0)),t.moveTo(o-f+T,i-p+m),t.lineTo(s-f+y,c-p+P)}function i(t,a){var n,r,o=a.defX,i=void 0===o?0:o,s=a.defY,c=void 0===s?0:s,h=a.markerStart,f=a.markerEnd,l=a.markerStartOffset,p=a.markerEndOffset,d=a.path,v=d.absolutePath,M=d.segments,u=0,T=0,m=0,y=0,P=0;if(h&&h instanceof e.DisplayObject&&l){var b=h.parentNode.getStartTangent(),O=b[0],S=b[1];n=O[0]-S[0],r=O[1]-S[1],P=Math.atan2(r,n),u=Math.cos(P)*(l||0),T=Math.sin(P)*(l||0)}if(f&&f instanceof e.DisplayObject&&p){var g=f.parentNode.getEndTangent(),k=g[0],I=g[1];n=k[0]-I[0],r=k[1]-I[1],P=Math.atan2(r,n),m=Math.cos(P)*(p||0),y=Math.sin(P)*(p||0)}for(var E=0;v.length>E;E++){var j=v[E],x=v[E+1],G=0===E&&(0!==u||0!==T),L=(E===v.length-1||x&&("M"===x[0]||"Z"===x[0]))&&0!==m&&0!==y;switch(j[0]){case"M":G?(t.moveTo(j[1]-i+u,j[2]-c+T),t.lineTo(j[1]-i,j[2]-c)):t.moveTo(j[1]-i,j[2]-c);break;case"L":L?t.lineTo(j[1]-i+m,j[2]-c+y):t.lineTo(j[1]-i,j[2]-c);break;case"Q":t.quadraticCurveTo(j[1]-i,j[2]-c,j[3]-i,j[4]-c),L&&t.lineTo(j[3]-i+m,j[4]-c+y);break;case"C":t.bezierCurveTo(j[1]-i,j[2]-c,j[3]-i,j[4]-c,j[5]-i,j[6]-c),L&&t.lineTo(j[5]-i+m,j[6]-c+y);break;case"A":var D=M[E].arcParams,A=D.cx,C=D.cy,w=D.rx,Y=D.ry,_=D.startAngle,N=D.endAngle,R=D.xRotation,X=D.sweepFlag;if(t.ellipse)t.ellipse(A-i,C-c,w,Y,R,_,N,!!(1-X));else{var F=w>Y?w:Y,H=w>Y?1:w/Y,q=w>Y?Y/w:1;t.translate(A-i,C-c),t.rotate(R),t.scale(H,q),t.arc(0,0,F,_,N,!!(1-X)),t.scale(1/H,1/q),t.rotate(-R),t.translate(-(A-i),-(C-c))}L&&t.lineTo(j[6]-i+m,j[7]-c+y);break;case"Z":t.closePath()}}}function s(t,a){var n,r,o=a.defX,i=void 0===o?0:o,s=a.defY,c=void 0===s?0:s,h=a.markerStart,f=a.markerEnd,l=a.markerStartOffset,p=a.markerEndOffset,d=a.points.points,v=d.length,M=d[0][0]-i,u=d[0][1]-c,T=d[v-1][0]-i,m=d[v-1][1]-c,y=0,P=0,b=0,O=0,S=0;h&&h instanceof e.DisplayObject&&l&&(n=d[1][0]-d[0][0],r=d[1][1]-d[0][1],S=Math.atan2(r,n),y=Math.cos(S)*(l||0),P=Math.sin(S)*(l||0)),f&&f instanceof e.DisplayObject&&p&&(n=d[v-1][0]-d[0][0],r=d[v-1][1]-d[0][1],S=Math.atan2(r,n),b=Math.cos(S)*(p||0),O=Math.sin(S)*(p||0)),t.moveTo(M+(y||b),u+(P||O));for(var g=1;v-1>g;g++){var k=d[g];t.lineTo(k[0]-i,k[1]-c)}t.lineTo(T,m)}function c(t,a){var n,r,o=a.defX,i=void 0===o?0:o,s=a.defY,c=void 0===s?0:s,h=a.markerStart,f=a.markerEnd,l=a.markerStartOffset,p=a.markerEndOffset,d=a.points.points,v=d.length,M=d[0][0]-i,u=d[0][1]-c,T=d[v-1][0]-i,m=d[v-1][1]-c,y=0,P=0,b=0,O=0,S=0;h&&h instanceof e.DisplayObject&&l&&(n=d[1][0]-d[0][0],r=d[1][1]-d[0][1],S=Math.atan2(r,n),y=Math.cos(S)*(l||0),P=Math.sin(S)*(l||0)),f&&f instanceof e.DisplayObject&&p&&(n=d[v-2][0]-d[v-1][0],r=d[v-2][1]-d[v-1][1],S=Math.atan2(r,n),b=Math.cos(S)*(p||0),O=Math.sin(S)*(p||0)),t.moveTo(M+y,u+P);for(var g=1;v-1>g;g++){var k=d[g];t.lineTo(k[0]-i,k[1]-c)}t.lineTo(T+b,m+O)}function h(t,e){var a=e.radius,n=e.width,r=e.height,o=n,i=r;if(a&&a.some((function(t){return 0!==t}))){var s=n>0?1:-1,c=r>0?1:-1,h=s+c===0,f=a.map((function(t){return e=t,a=0,n=Math.min(Math.abs(o)/2,Math.abs(i)/2),a>e?a:e>n?n:e;var e,a,n})),l=f[0],p=f[1],d=f[2],v=f[3];t.moveTo(s*l,0),t.lineTo(o-s*p,0),0!==p&&t.arc(o-s*p,c*p,p,-c*Math.PI/2,s>0?0:Math.PI,h),t.lineTo(o,i-c*d),0!==d&&t.arc(o-s*d,i-c*d,d,s>0?0:Math.PI,c>0?Math.PI/2:1.5*Math.PI,h),t.lineTo(s*v,i),0!==v&&t.arc(s*v,i-c*v,v,c>0?Math.PI/2:-Math.PI/2,s>0?Math.PI:0,h),t.lineTo(0,c*l),0!==l&&t.arc(s*l,c*l,l,s>0?Math.PI:0,c>0?1.5*Math.PI:Math.PI/2,h)}else t.rect(0,0,o,i)}var f=function(t){var f,l;function p(){for(var e,a=arguments.length,n=new Array(a),r=0;a>r;r++)n[r]=arguments[r];return(e=t.call.apply(t,[this].concat(n))||this).name="canvas-path-generator",e}l=t,(f=p).prototype=Object.create(l.prototype),f.prototype.constructor=f,a(f,l);var d=p.prototype;return d.init=function(){var t,a=((t={})[e.Shape.CIRCLE]=n,t[e.Shape.ELLIPSE]=r,t[e.Shape.RECT]=h,t[e.Shape.LINE]=o,t[e.Shape.POLYLINE]=c,t[e.Shape.POLYGON]=s,t[e.Shape.PATH]=i,t[e.Shape.TEXT]=void 0,t[e.Shape.GROUP]=void 0,t[e.Shape.IMAGE]=void 0,t[e.Shape.HTML]=void 0,t[e.Shape.MESH]=void 0,t);this.context.pathGeneratorFactory=a},d.destroy=function(){delete this.context.pathGeneratorFactory},p}(e.AbstractRendererPlugin);t.Plugin=f,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "@antv/g-plugin-canvas-path-generator", | ||
"version": "1.1.27", | ||
"version": "1.1.28", | ||
"description": "A G plugin of path generator with Canvas2D API", | ||
@@ -33,4 +33,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@antv/g-math": "^1.7.27", | ||
"@antv/util": "^3.2.4", | ||
"@antv/g-math": "^1.7.28", | ||
"@antv/util": "^3.3.1", | ||
"tslib": "^2.3.1" | ||
@@ -47,3 +47,3 @@ }, | ||
}, | ||
"gitHead": "e7c23dd07f888b9e46a27a4f79ec80ed2db62fc7" | ||
"gitHead": "c92278756907344ff54ebc6f6a83630559ef36ff" | ||
} |
1090
54649
Updated@antv/g-math@^1.7.28
Updated@antv/util@^3.3.1