@antv/g-canvas 1.7.1 → 1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.umd.js +367 -359
- package/dist/index.umd.min.js +6 -6
- package/package.json +8 -8
package/dist/index.umd.js
CHANGED
|
@@ -415,19 +415,19 @@
|
|
|
415
415
|
return _setPrototypeOf$1(o, p);
|
|
416
416
|
}
|
|
417
417
|
|
|
418
|
-
var PathGeneratorFactory = g.Syringe.defineToken('
|
|
419
|
-
var PathGenerator = g.Syringe.defineToken('
|
|
418
|
+
var PathGeneratorFactory = g.Syringe.defineToken('');
|
|
419
|
+
var PathGenerator = g.Syringe.defineToken('');
|
|
420
420
|
|
|
421
421
|
function generatePath(context, parsedStyle) {
|
|
422
422
|
var r = parsedStyle.r;
|
|
423
|
-
context.arc(r
|
|
423
|
+
context.arc(r, r, r, 0, Math.PI * 2, false);
|
|
424
424
|
}
|
|
425
425
|
|
|
426
426
|
function generatePath$1(context, parsedStyle) {
|
|
427
427
|
var rxInPixels = parsedStyle.rx,
|
|
428
428
|
ryInPixels = parsedStyle.ry;
|
|
429
|
-
var rx = rxInPixels
|
|
430
|
-
var ry = ryInPixels
|
|
429
|
+
var rx = rxInPixels;
|
|
430
|
+
var ry = ryInPixels; // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse
|
|
431
431
|
|
|
432
432
|
if (context.ellipse) {
|
|
433
433
|
context.ellipse(rx, ry, rx, ry, 0, 0, Math.PI * 2, false);
|
|
@@ -464,23 +464,23 @@
|
|
|
464
464
|
var y;
|
|
465
465
|
|
|
466
466
|
if (markerStart && markerStart instanceof g.DisplayObject && markerStartOffset) {
|
|
467
|
-
x = x2
|
|
468
|
-
y = y2
|
|
467
|
+
x = x2 - x1;
|
|
468
|
+
y = y2 - y1;
|
|
469
469
|
rad = Math.atan2(y, x);
|
|
470
|
-
startOffsetX = Math.cos(rad) * (
|
|
471
|
-
startOffsetY = Math.sin(rad) * (
|
|
470
|
+
startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
|
|
471
|
+
startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
|
|
472
472
|
}
|
|
473
473
|
|
|
474
474
|
if (markerEnd && markerEnd instanceof g.DisplayObject && markerEndOffset) {
|
|
475
|
-
x = x1
|
|
476
|
-
y = y1
|
|
475
|
+
x = x1 - x2;
|
|
476
|
+
y = y1 - y2;
|
|
477
477
|
rad = Math.atan2(y, x);
|
|
478
|
-
endOffsetX = Math.cos(rad) * (
|
|
479
|
-
endOffsetY = Math.sin(rad) * (
|
|
478
|
+
endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
|
|
479
|
+
endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
|
|
480
480
|
}
|
|
481
481
|
|
|
482
|
-
context.moveTo(x1
|
|
483
|
-
context.lineTo(x2
|
|
482
|
+
context.moveTo(x1 - defX + startOffsetX, y1 - defY + startOffsetY);
|
|
483
|
+
context.lineTo(x2 - defX + endOffsetX, y2 - defY + endOffsetY);
|
|
484
484
|
}
|
|
485
485
|
|
|
486
486
|
function generatePath$3(context, parsedStyle) {
|
|
@@ -501,7 +501,7 @@
|
|
|
501
501
|
path.splice(zIndex + index, 1, ['Z']);
|
|
502
502
|
}); // @ts-ignore
|
|
503
503
|
|
|
504
|
-
var isClosed = path[path.length - 1][0] === 'Z';
|
|
504
|
+
var isClosed = path.length && path[path.length - 1][0] === 'Z';
|
|
505
505
|
var startOffsetX = 0;
|
|
506
506
|
var startOffsetY = 0;
|
|
507
507
|
var endOffsetX = 0;
|
|
@@ -518,8 +518,8 @@
|
|
|
518
518
|
x = p1[0] - p2[0];
|
|
519
519
|
y = p1[1] - p2[1];
|
|
520
520
|
rad = Math.atan2(y, x);
|
|
521
|
-
startOffsetX = Math.cos(rad) * (
|
|
522
|
-
startOffsetY = Math.sin(rad) * (
|
|
521
|
+
startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
|
|
522
|
+
startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
|
|
523
523
|
}
|
|
524
524
|
|
|
525
525
|
if (markerEnd && markerEnd instanceof g.DisplayObject && markerEndOffset) {
|
|
@@ -530,8 +530,8 @@
|
|
|
530
530
|
x = _p[0] - _p2[0];
|
|
531
531
|
y = _p[1] - _p2[1];
|
|
532
532
|
rad = Math.atan2(y, x);
|
|
533
|
-
endOffsetX = Math.cos(rad) * (
|
|
534
|
-
endOffsetY = Math.sin(rad) * (
|
|
533
|
+
endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
|
|
534
|
+
endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
|
|
535
535
|
}
|
|
536
536
|
|
|
537
537
|
for (var i = 0; i < path.length; i++) {
|
|
@@ -585,16 +585,16 @@
|
|
|
585
585
|
x = points[1][0] - points[0][0];
|
|
586
586
|
y = points[1][1] - points[0][1];
|
|
587
587
|
rad = Math.atan2(y, x);
|
|
588
|
-
startOffsetX = Math.cos(rad) * (
|
|
589
|
-
startOffsetY = Math.sin(rad) * (
|
|
588
|
+
startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
|
|
589
|
+
startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
|
|
590
590
|
}
|
|
591
591
|
|
|
592
592
|
if (markerEnd && markerEnd instanceof g.DisplayObject && markerEndOffset) {
|
|
593
593
|
x = points[length - 1][0] - points[0][0];
|
|
594
594
|
y = points[length - 1][1] - points[0][1];
|
|
595
595
|
rad = Math.atan2(y, x);
|
|
596
|
-
endOffsetX = Math.cos(rad) * (
|
|
597
|
-
endOffsetY = Math.sin(rad) * (
|
|
596
|
+
endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
|
|
597
|
+
endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
|
|
598
598
|
}
|
|
599
599
|
|
|
600
600
|
context.moveTo(x1 + (startOffsetX || endOffsetX), y1 + (startOffsetY || endOffsetY));
|
|
@@ -634,16 +634,16 @@
|
|
|
634
634
|
x = points[1][0] - points[0][0];
|
|
635
635
|
y = points[1][1] - points[0][1];
|
|
636
636
|
rad = Math.atan2(y, x);
|
|
637
|
-
startOffsetX = Math.cos(rad) * (
|
|
638
|
-
startOffsetY = Math.sin(rad) * (
|
|
637
|
+
startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
|
|
638
|
+
startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
|
|
639
639
|
}
|
|
640
640
|
|
|
641
641
|
if (markerEnd && markerEnd instanceof g.DisplayObject && markerEndOffset) {
|
|
642
642
|
x = points[length - 2][0] - points[length - 1][0];
|
|
643
643
|
y = points[length - 2][1] - points[length - 1][1];
|
|
644
644
|
rad = Math.atan2(y, x);
|
|
645
|
-
endOffsetX = Math.cos(rad) * (
|
|
646
|
-
endOffsetY = Math.sin(rad) * (
|
|
645
|
+
endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
|
|
646
|
+
endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
|
|
647
647
|
}
|
|
648
648
|
|
|
649
649
|
context.moveTo(x1 + startOffsetX, y1 + startOffsetY);
|
|
@@ -660,22 +660,22 @@
|
|
|
660
660
|
var radius = parsedStyle.radius,
|
|
661
661
|
width = parsedStyle.width,
|
|
662
662
|
height = parsedStyle.height;
|
|
663
|
-
var w = width
|
|
664
|
-
var h = height
|
|
663
|
+
var w = width;
|
|
664
|
+
var h = height;
|
|
665
665
|
var hasRadius = radius && radius.some(function (r) {
|
|
666
|
-
return r
|
|
666
|
+
return r !== 0;
|
|
667
667
|
});
|
|
668
668
|
|
|
669
669
|
if (!hasRadius) {
|
|
670
670
|
// Canvas support negative width/height of rect
|
|
671
671
|
context.rect(0, 0, w, h);
|
|
672
672
|
} else {
|
|
673
|
-
var signX = width
|
|
674
|
-
var signY = height
|
|
673
|
+
var signX = width > 0 ? 1 : -1;
|
|
674
|
+
var signY = height > 0 ? 1 : -1;
|
|
675
675
|
var sweepFlag = signX + signY === 0;
|
|
676
676
|
|
|
677
677
|
var _radius$map = radius.map(function (r) {
|
|
678
|
-
return g.clamp(r
|
|
678
|
+
return g.clamp(r, 0, Math.min(Math.abs(w) / 2, Math.abs(h) / 2));
|
|
679
679
|
}),
|
|
680
680
|
tlr = _radius$map[0],
|
|
681
681
|
trr = _radius$map[1],
|
|
@@ -1439,17 +1439,17 @@
|
|
|
1439
1439
|
return out;
|
|
1440
1440
|
}
|
|
1441
1441
|
/**
|
|
1442
|
-
*
|
|
1442
|
+
* Set the components of a vec3 to the given values
|
|
1443
1443
|
*
|
|
1444
|
+
* @param {vec3} out the receiving vector
|
|
1444
1445
|
* @param {Number} x X component
|
|
1445
1446
|
* @param {Number} y Y component
|
|
1446
1447
|
* @param {Number} z Z component
|
|
1447
|
-
* @returns {vec3}
|
|
1448
|
+
* @returns {vec3} out
|
|
1448
1449
|
*/
|
|
1449
1450
|
|
|
1450
1451
|
|
|
1451
|
-
function
|
|
1452
|
-
var out = new ARRAY_TYPE(3);
|
|
1452
|
+
function set(out, x, y, z) {
|
|
1453
1453
|
out[0] = x;
|
|
1454
1454
|
out[1] = y;
|
|
1455
1455
|
out[2] = z;
|
|
@@ -1640,7 +1640,7 @@
|
|
|
1640
1640
|
var _class;
|
|
1641
1641
|
|
|
1642
1642
|
var CanvasPickerPlugin_1;
|
|
1643
|
-
var PointInPathPickerFactory = g.Syringe.defineToken('
|
|
1643
|
+
var PointInPathPickerFactory = g.Syringe.defineToken('');
|
|
1644
1644
|
/**
|
|
1645
1645
|
* pick shape(s) with Mouse/Touch event
|
|
1646
1646
|
*
|
|
@@ -1659,6 +1659,9 @@
|
|
|
1659
1659
|
this.pathGeneratorFactory = void 0;
|
|
1660
1660
|
this.pathGeneratorFactoryCache = {};
|
|
1661
1661
|
this.pointInPathPickerFactory = void 0;
|
|
1662
|
+
this.tmpVec3a = create$1();
|
|
1663
|
+
this.tmpVec3b = create$1();
|
|
1664
|
+
this.tmpVec3c = create$1();
|
|
1662
1665
|
|
|
1663
1666
|
this.isHit = function (displayObject, position, worldTransform) {
|
|
1664
1667
|
// use picker for current shape's type
|
|
@@ -1668,14 +1671,14 @@
|
|
|
1668
1671
|
// invert with world matrix
|
|
1669
1672
|
var invertWorldMat = invert(create(), worldTransform); // transform client position to local space, do picking in local space
|
|
1670
1673
|
|
|
1671
|
-
var localPosition = transformMat4(
|
|
1674
|
+
var localPosition = transformMat4(_this.tmpVec3b, set(_this.tmpVec3c, position[0], position[1], 0), invertWorldMat); // account for anchor
|
|
1672
1675
|
|
|
1673
1676
|
var _displayObject$getGeo = displayObject.getGeometryBounds(),
|
|
1674
1677
|
halfExtents = _displayObject$getGeo.halfExtents;
|
|
1675
1678
|
|
|
1676
1679
|
var anchor = displayObject.parsedStyle.anchor;
|
|
1677
|
-
localPosition[0] += (anchor && anchor[0]
|
|
1678
|
-
localPosition[1] += (anchor && anchor[1]
|
|
1680
|
+
localPosition[0] += (anchor && anchor[0] || 0) * halfExtents[0] * 2;
|
|
1681
|
+
localPosition[1] += (anchor && anchor[1] || 0) * halfExtents[1] * 2;
|
|
1679
1682
|
|
|
1680
1683
|
if (pick(displayObject, new g.Point(localPosition[0], localPosition[1]), _this.isPointInPath)) {
|
|
1681
1684
|
return true;
|
|
@@ -1719,7 +1722,7 @@
|
|
|
1719
1722
|
case 0:
|
|
1720
1723
|
topmost = result.topmost, _result$position = result.position, x = _result$position.x, y = _result$position.y; // position in world space
|
|
1721
1724
|
|
|
1722
|
-
position =
|
|
1725
|
+
position = set(_this2.tmpVec3a, x, y, 0); // query by AABB first with spatial index(r-tree)
|
|
1723
1726
|
|
|
1724
1727
|
rBushNodes = _this2.rBush.search({
|
|
1725
1728
|
minX: position[0],
|
|
@@ -2379,14 +2382,13 @@
|
|
|
2379
2382
|
|
|
2380
2383
|
function isPointInPath(displayObject, position) {
|
|
2381
2384
|
var _displayObject$parsed = displayObject.parsedStyle,
|
|
2382
|
-
|
|
2385
|
+
r = _displayObject$parsed.r,
|
|
2383
2386
|
fill = _displayObject$parsed.fill,
|
|
2384
2387
|
stroke = _displayObject$parsed.stroke,
|
|
2385
2388
|
lineWidth = _displayObject$parsed.lineWidth,
|
|
2386
2389
|
increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
|
|
2387
2390
|
clipPathTargets = _displayObject$parsed.clipPathTargets;
|
|
2388
|
-
var
|
|
2389
|
-
var halfLineWidth = (((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0)) / 2;
|
|
2391
|
+
var halfLineWidth = ((lineWidth || 0) + (increasedLineWidthForHitTesting || 0)) / 2;
|
|
2390
2392
|
var absDistance = distance$1(r, r, position.x, position.y);
|
|
2391
2393
|
var isClipPath = !!(clipPathTargets === null || clipPathTargets === void 0 ? void 0 : clipPathTargets.length);
|
|
2392
2394
|
var hasFill = fill && !fill.isNone;
|
|
@@ -2415,8 +2417,8 @@
|
|
|
2415
2417
|
var x = _ref.x,
|
|
2416
2418
|
y = _ref.y;
|
|
2417
2419
|
var _displayObject$parsed = displayObject.parsedStyle,
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
+
rx = _displayObject$parsed.rx,
|
|
2421
|
+
ry = _displayObject$parsed.ry,
|
|
2420
2422
|
fill = _displayObject$parsed.fill,
|
|
2421
2423
|
stroke = _displayObject$parsed.stroke,
|
|
2422
2424
|
lineWidth = _displayObject$parsed.lineWidth,
|
|
@@ -2425,9 +2427,7 @@
|
|
|
2425
2427
|
var isClipPath = !!(clipPathTargets === null || clipPathTargets === void 0 ? void 0 : clipPathTargets.length);
|
|
2426
2428
|
var hasFill = fill && !fill.isNone;
|
|
2427
2429
|
var hasStroke = stroke && !stroke.isNone;
|
|
2428
|
-
var
|
|
2429
|
-
var ry = ryInPixels.value;
|
|
2430
|
-
var halfLineWith = (((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0)) / 2;
|
|
2430
|
+
var halfLineWith = ((lineWidth || 0) + (increasedLineWidthForHitTesting || 0)) / 2;
|
|
2431
2431
|
var squareX = (x - rx) * (x - rx);
|
|
2432
2432
|
var squareY = (y - ry) * (y - ry); // 使用椭圆的公式: x*x/rx*rx + y*y/ry*ry = 1;
|
|
2433
2433
|
|
|
@@ -2458,10 +2458,10 @@
|
|
|
2458
2458
|
x = _displayObject$parsed2 === void 0 ? 0 : _displayObject$parsed2,
|
|
2459
2459
|
_displayObject$parsed3 = _displayObject$parsed.defY,
|
|
2460
2460
|
y = _displayObject$parsed3 === void 0 ? 0 : _displayObject$parsed3;
|
|
2461
|
-
return inLine(x1
|
|
2461
|
+
return inLine(x1, y1, x2, y2, (lineWidth || 0) + (increasedLineWidthForHitTesting || 0), position.x + x, position.y + y);
|
|
2462
2462
|
}
|
|
2463
2463
|
|
|
2464
|
-
function isPointInStroke(segments, lineWidth, px, py, length
|
|
2464
|
+
function isPointInStroke(segments, lineWidth, px, py, length) {
|
|
2465
2465
|
var isHit = false;
|
|
2466
2466
|
|
|
2467
2467
|
for (var i = 0; i < segments.length; i++) {
|
|
@@ -2476,19 +2476,6 @@
|
|
|
2476
2476
|
case 'Z':
|
|
2477
2477
|
isHit = inLine(prePoint[0], prePoint[1], currentPoint[0], currentPoint[1], lineWidth, px, py);
|
|
2478
2478
|
break;
|
|
2479
|
-
// case 'Q':
|
|
2480
|
-
// const qDistance = QuadUtil.pointDistance(
|
|
2481
|
-
// prePoint[0],
|
|
2482
|
-
// prePoint[1],
|
|
2483
|
-
// params[1],
|
|
2484
|
-
// params[2],
|
|
2485
|
-
// params[3],
|
|
2486
|
-
// params[4],
|
|
2487
|
-
// px,
|
|
2488
|
-
// py,
|
|
2489
|
-
// );
|
|
2490
|
-
// isHit = qDistance <= lineWidth / 2;
|
|
2491
|
-
// break;
|
|
2492
2479
|
|
|
2493
2480
|
case 'C':
|
|
2494
2481
|
var cDistance = cubic.pointDistance(prePoint[0], // 上一段结束位置, 即 C 的起始点
|
|
@@ -2528,11 +2515,7 @@
|
|
|
2528
2515
|
var isClipPath = !!(clipPathTargets === null || clipPathTargets === void 0 ? void 0 : clipPathTargets.length);
|
|
2529
2516
|
var isHit = false;
|
|
2530
2517
|
|
|
2531
|
-
if (
|
|
2532
|
-
isHit = isPointInStroke(segments, ((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0), position.x + x, position.y + y, totalLength);
|
|
2533
|
-
}
|
|
2534
|
-
|
|
2535
|
-
if (!isHit && (hasFill || isClipPath)) {
|
|
2518
|
+
if (hasFill || isClipPath) {
|
|
2536
2519
|
if (hasArc) {
|
|
2537
2520
|
// 存在曲线时,暂时使用 canvas 的 api 计算,后续可以进行多边形切割
|
|
2538
2521
|
isHit = isPointInPath(displayObject, position);
|
|
@@ -2540,7 +2523,33 @@
|
|
|
2540
2523
|
// 提取出来的多边形包含闭合的和非闭合的,在这里统一按照多边形处理
|
|
2541
2524
|
isHit = inPolygons(polygons, position.x + x, position.y + y) || inPolygons(polylines, position.x + x, position.y + y);
|
|
2542
2525
|
}
|
|
2543
|
-
|
|
2526
|
+
|
|
2527
|
+
return isHit;
|
|
2528
|
+
} else if (hasStroke || isClipPath) {
|
|
2529
|
+
isHit = isPointInStroke(segments, (lineWidth || 0) + (increasedLineWidthForHitTesting || 0), position.x + x, position.y + y, totalLength);
|
|
2530
|
+
} // if (hasStroke || isClipPath) {
|
|
2531
|
+
// isHit = isPointInStroke(
|
|
2532
|
+
// segments,
|
|
2533
|
+
// (lineWidth?.value || 0) + (increasedLineWidthForHitTesting?.value || 0),
|
|
2534
|
+
// position.x + x,
|
|
2535
|
+
// position.y + y,
|
|
2536
|
+
// totalLength,
|
|
2537
|
+
// x,
|
|
2538
|
+
// y,
|
|
2539
|
+
// );
|
|
2540
|
+
// }
|
|
2541
|
+
// if (!isHit && (hasFill || isClipPath)) {
|
|
2542
|
+
// if (hasArc) {
|
|
2543
|
+
// // 存在曲线时,暂时使用 canvas 的 api 计算,后续可以进行多边形切割
|
|
2544
|
+
// isHit = isPointInPath(displayObject, position);
|
|
2545
|
+
// } else {
|
|
2546
|
+
// // 提取出来的多边形包含闭合的和非闭合的,在这里统一按照多边形处理
|
|
2547
|
+
// isHit =
|
|
2548
|
+
// inPolygons(polygons, position.x + x, position.y + y) ||
|
|
2549
|
+
// inPolygons(polylines, position.x + x, position.y + y);
|
|
2550
|
+
// }
|
|
2551
|
+
// }
|
|
2552
|
+
|
|
2544
2553
|
|
|
2545
2554
|
return isHit;
|
|
2546
2555
|
}
|
|
@@ -2563,7 +2572,7 @@
|
|
|
2563
2572
|
var isHit = false;
|
|
2564
2573
|
|
|
2565
2574
|
if (hasStroke || isClipPath) {
|
|
2566
|
-
isHit = inPolyline(points.points, (
|
|
2575
|
+
isHit = inPolyline(points.points, (lineWidth || 0) + (increasedLineWidthForHitTesting || 0), position.x + x, position.y + y, true);
|
|
2567
2576
|
}
|
|
2568
2577
|
|
|
2569
2578
|
if (!isHit && (hasFill || isClipPath)) {
|
|
@@ -2591,7 +2600,7 @@
|
|
|
2591
2600
|
return false;
|
|
2592
2601
|
}
|
|
2593
2602
|
|
|
2594
|
-
return inPolyline(points.points, (
|
|
2603
|
+
return inPolyline(points.points, (lineWidth || 0) + (increasedLineWidthForHitTesting || 0), position.x + x, position.y + y, false);
|
|
2595
2604
|
}
|
|
2596
2605
|
|
|
2597
2606
|
function isPointInPath$6(displayObject, position, isPointInPath) {
|
|
@@ -2601,31 +2610,16 @@
|
|
|
2601
2610
|
stroke = _displayObject$parsed.stroke,
|
|
2602
2611
|
lineWidth = _displayObject$parsed.lineWidth,
|
|
2603
2612
|
increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
|
|
2604
|
-
|
|
2605
|
-
|
|
2613
|
+
width = _displayObject$parsed.width,
|
|
2614
|
+
height = _displayObject$parsed.height,
|
|
2606
2615
|
clipPathTargets = _displayObject$parsed.clipPathTargets;
|
|
2607
2616
|
var isClipPath = !!(clipPathTargets === null || clipPathTargets === void 0 ? void 0 : clipPathTargets.length);
|
|
2608
2617
|
var hasFill = fill && !fill.isNone;
|
|
2609
2618
|
var hasStroke = stroke && !stroke.isNone;
|
|
2610
2619
|
var hasRadius = radius && radius.some(function (r) {
|
|
2611
|
-
return r
|
|
2620
|
+
return r !== 0;
|
|
2612
2621
|
});
|
|
2613
|
-
var
|
|
2614
|
-
widthValue = parsedWidth.value;
|
|
2615
|
-
var heightUnit = parsedHeight.unit,
|
|
2616
|
-
heightValue = parsedHeight.value;
|
|
2617
|
-
var width = 0;
|
|
2618
|
-
var height = 0;
|
|
2619
|
-
|
|
2620
|
-
if (widthUnit === g.UnitType.kNumber || widthUnit === g.UnitType.kPixels) {
|
|
2621
|
-
width = widthValue;
|
|
2622
|
-
}
|
|
2623
|
-
|
|
2624
|
-
if (heightUnit === g.UnitType.kNumber || heightUnit === g.UnitType.kPixels) {
|
|
2625
|
-
height = heightValue;
|
|
2626
|
-
}
|
|
2627
|
-
|
|
2628
|
-
var lineWidthForHitTesting = ((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0); // 无圆角时的策略
|
|
2622
|
+
var lineWidthForHitTesting = (lineWidth || 0) + (increasedLineWidthForHitTesting || 0); // 无圆角时的策略
|
|
2629
2623
|
|
|
2630
2624
|
if (!hasRadius) {
|
|
2631
2625
|
var halfWidth = lineWidthForHitTesting / 2; // 同时填充和带有边框
|
|
@@ -2647,7 +2641,7 @@
|
|
|
2647
2641
|
|
|
2648
2642
|
if (hasStroke || isClipPath) {
|
|
2649
2643
|
isHit = inRectWithRadius(0, 0, width, height, radius.map(function (r) {
|
|
2650
|
-
return g.clamp(r
|
|
2644
|
+
return g.clamp(r, 0, Math.min(Math.abs(width) / 2, Math.abs(height) / 2));
|
|
2651
2645
|
}), lineWidthForHitTesting, position.x, position.y);
|
|
2652
2646
|
} // 仅填充时带有圆角的矩形直接通过图形拾取
|
|
2653
2647
|
// 以后可以改成纯数学的近似拾取,将圆弧切割成多边形
|
|
@@ -3155,6 +3149,10 @@
|
|
|
3155
3149
|
callback();
|
|
3156
3150
|
}
|
|
3157
3151
|
});
|
|
3152
|
+
} else {
|
|
3153
|
+
if (callback) {
|
|
3154
|
+
callback();
|
|
3155
|
+
}
|
|
3158
3156
|
}
|
|
3159
3157
|
|
|
3160
3158
|
return this.imageCache[src];
|
|
@@ -4103,7 +4101,7 @@
|
|
|
4103
4101
|
*/
|
|
4104
4102
|
|
|
4105
4103
|
|
|
4106
|
-
function fromValues
|
|
4104
|
+
function fromValues(x, y, z) {
|
|
4107
4105
|
var out = new ARRAY_TYPE$1(3);
|
|
4108
4106
|
out[0] = x;
|
|
4109
4107
|
out[1] = y;
|
|
@@ -4179,35 +4177,221 @@
|
|
|
4179
4177
|
};
|
|
4180
4178
|
}();
|
|
4181
4179
|
|
|
4182
|
-
var StyleRendererFactory = g.Syringe.defineToken('
|
|
4183
|
-
var CircleRendererContribution = g.Syringe.defineToken('
|
|
4180
|
+
var StyleRendererFactory = g.Syringe.defineToken('');
|
|
4181
|
+
var CircleRendererContribution = g.Syringe.defineToken('', {
|
|
4184
4182
|
multiple: false
|
|
4185
4183
|
});
|
|
4186
|
-
var EllipseRendererContribution = g.Syringe.defineToken('
|
|
4184
|
+
var EllipseRendererContribution = g.Syringe.defineToken('', {
|
|
4187
4185
|
multiple: false
|
|
4188
4186
|
});
|
|
4189
|
-
var RectRendererContribution = g.Syringe.defineToken('
|
|
4187
|
+
var RectRendererContribution = g.Syringe.defineToken('', {
|
|
4190
4188
|
multiple: false
|
|
4191
4189
|
});
|
|
4192
|
-
var LineRendererContribution = g.Syringe.defineToken('
|
|
4190
|
+
var LineRendererContribution = g.Syringe.defineToken('', {
|
|
4193
4191
|
multiple: false
|
|
4194
4192
|
});
|
|
4195
|
-
var PolylineRendererContribution = g.Syringe.defineToken('
|
|
4193
|
+
var PolylineRendererContribution = g.Syringe.defineToken('', {
|
|
4196
4194
|
multiple: false
|
|
4197
4195
|
});
|
|
4198
|
-
var PolygonRendererContribution = g.Syringe.defineToken('
|
|
4196
|
+
var PolygonRendererContribution = g.Syringe.defineToken('', {
|
|
4199
4197
|
multiple: false
|
|
4200
4198
|
});
|
|
4201
|
-
var PathRendererContribution = g.Syringe.defineToken('
|
|
4199
|
+
var PathRendererContribution = g.Syringe.defineToken('', {
|
|
4202
4200
|
multiple: false
|
|
4203
4201
|
});
|
|
4204
|
-
var TextRendererContribution = g.Syringe.defineToken('
|
|
4202
|
+
var TextRendererContribution = g.Syringe.defineToken('', {
|
|
4205
4203
|
multiple: false
|
|
4206
4204
|
});
|
|
4207
|
-
var ImageRendererContribution = g.Syringe.defineToken('
|
|
4205
|
+
var ImageRendererContribution = g.Syringe.defineToken('', {
|
|
4208
4206
|
multiple: false
|
|
4209
4207
|
});
|
|
4210
4208
|
|
|
4209
|
+
var DefaultRenderer = /*#__PURE__*/function () {
|
|
4210
|
+
function DefaultRenderer() {
|
|
4211
|
+
this.imagePool = void 0;
|
|
4212
|
+
}
|
|
4213
|
+
|
|
4214
|
+
var _proto = DefaultRenderer.prototype;
|
|
4215
|
+
|
|
4216
|
+
_proto.render = function render(context, parsedStyle, object, renderingService) {
|
|
4217
|
+
var fill = parsedStyle.fill,
|
|
4218
|
+
opacity = parsedStyle.opacity,
|
|
4219
|
+
fillOpacity = parsedStyle.fillOpacity,
|
|
4220
|
+
stroke = parsedStyle.stroke,
|
|
4221
|
+
strokeOpacity = parsedStyle.strokeOpacity,
|
|
4222
|
+
lineWidth = parsedStyle.lineWidth,
|
|
4223
|
+
lineCap = parsedStyle.lineCap,
|
|
4224
|
+
lineJoin = parsedStyle.lineJoin,
|
|
4225
|
+
shadowType = parsedStyle.shadowType,
|
|
4226
|
+
shadowColor = parsedStyle.shadowColor,
|
|
4227
|
+
shadowBlur = parsedStyle.shadowBlur,
|
|
4228
|
+
filter = parsedStyle.filter,
|
|
4229
|
+
miterLimit = parsedStyle.miterLimit;
|
|
4230
|
+
var hasFill = !g.isNil(fill) && !fill.isNone;
|
|
4231
|
+
var hasStroke = !g.isNil(stroke) && !stroke.isNone && lineWidth > 0;
|
|
4232
|
+
var isFillTransparent = fill.alpha === 0;
|
|
4233
|
+
var hasFilter = !!(filter && filter.length);
|
|
4234
|
+
var hasShadow = !g.isNil(shadowColor) && shadowBlur > 0;
|
|
4235
|
+
var nodeName = object.nodeName;
|
|
4236
|
+
var isInnerShadow = shadowType === 'inner';
|
|
4237
|
+
var shouldDrawShadowWithStroke = hasStroke && hasShadow && (nodeName === g.Shape.PATH || nodeName === g.Shape.LINE || nodeName === g.Shape.POLYLINE || isFillTransparent || isInnerShadow);
|
|
4238
|
+
|
|
4239
|
+
if (hasFill) {
|
|
4240
|
+
context.globalAlpha = opacity * fillOpacity;
|
|
4241
|
+
|
|
4242
|
+
if (!shouldDrawShadowWithStroke) {
|
|
4243
|
+
setShadowAndFilter(object, context, hasShadow);
|
|
4244
|
+
}
|
|
4245
|
+
|
|
4246
|
+
this.fill(context, object, fill, renderingService);
|
|
4247
|
+
|
|
4248
|
+
if (!shouldDrawShadowWithStroke) {
|
|
4249
|
+
this.clearShadowAndFilter(context, hasFilter, hasShadow);
|
|
4250
|
+
}
|
|
4251
|
+
}
|
|
4252
|
+
|
|
4253
|
+
if (hasStroke) {
|
|
4254
|
+
context.globalAlpha = opacity * strokeOpacity;
|
|
4255
|
+
context.lineWidth = lineWidth;
|
|
4256
|
+
|
|
4257
|
+
if (!g.isNil(miterLimit)) {
|
|
4258
|
+
context.miterLimit = miterLimit;
|
|
4259
|
+
}
|
|
4260
|
+
|
|
4261
|
+
if (!g.isNil(lineCap)) {
|
|
4262
|
+
context.lineCap = lineCap;
|
|
4263
|
+
}
|
|
4264
|
+
|
|
4265
|
+
if (!g.isNil(lineJoin)) {
|
|
4266
|
+
context.lineJoin = lineJoin;
|
|
4267
|
+
}
|
|
4268
|
+
|
|
4269
|
+
if (shouldDrawShadowWithStroke) {
|
|
4270
|
+
if (isInnerShadow) {
|
|
4271
|
+
context.globalCompositeOperation = 'source-atop';
|
|
4272
|
+
}
|
|
4273
|
+
|
|
4274
|
+
setShadowAndFilter(object, context, true);
|
|
4275
|
+
|
|
4276
|
+
if (isInnerShadow) {
|
|
4277
|
+
this.stroke(context, object, stroke, renderingService);
|
|
4278
|
+
context.globalCompositeOperation = 'source-over';
|
|
4279
|
+
this.clearShadowAndFilter(context, hasFilter, true);
|
|
4280
|
+
}
|
|
4281
|
+
}
|
|
4282
|
+
|
|
4283
|
+
this.stroke(context, object, stroke, renderingService);
|
|
4284
|
+
}
|
|
4285
|
+
};
|
|
4286
|
+
|
|
4287
|
+
_proto.clearShadowAndFilter = function clearShadowAndFilter(context, hasFilter, hasShadow) {
|
|
4288
|
+
if (hasShadow) {
|
|
4289
|
+
context.shadowColor = 'transparent';
|
|
4290
|
+
context.shadowBlur = 0;
|
|
4291
|
+
}
|
|
4292
|
+
|
|
4293
|
+
if (hasFilter) {
|
|
4294
|
+
// save drop-shadow filter
|
|
4295
|
+
var oldFilter = context.filter;
|
|
4296
|
+
|
|
4297
|
+
if (!g.isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
|
|
4298
|
+
context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
|
|
4299
|
+
}
|
|
4300
|
+
}
|
|
4301
|
+
};
|
|
4302
|
+
|
|
4303
|
+
_proto.fill = function fill(context, object, _fill, renderingService) {
|
|
4304
|
+
var _this = this;
|
|
4305
|
+
|
|
4306
|
+
if (Array.isArray(_fill)) {
|
|
4307
|
+
_fill.forEach(function (gradient) {
|
|
4308
|
+
context.fillStyle = _this.getColor(gradient, object, context);
|
|
4309
|
+
context.fill();
|
|
4310
|
+
});
|
|
4311
|
+
} else {
|
|
4312
|
+
if (g.isPattern(_fill)) {
|
|
4313
|
+
context.fillStyle = this.getPattern(_fill, object, context, renderingService);
|
|
4314
|
+
}
|
|
4315
|
+
|
|
4316
|
+
context.fill();
|
|
4317
|
+
}
|
|
4318
|
+
};
|
|
4319
|
+
|
|
4320
|
+
_proto.stroke = function stroke(context, object, _stroke, renderingService) {
|
|
4321
|
+
var _this2 = this;
|
|
4322
|
+
|
|
4323
|
+
if (Array.isArray(_stroke)) {
|
|
4324
|
+
_stroke.forEach(function (gradient) {
|
|
4325
|
+
context.strokeStyle = _this2.getColor(gradient, object, context);
|
|
4326
|
+
context.stroke();
|
|
4327
|
+
});
|
|
4328
|
+
} else {
|
|
4329
|
+
if (g.isPattern(_stroke)) {
|
|
4330
|
+
context.strokeStyle = this.getPattern(_stroke, object, context, renderingService);
|
|
4331
|
+
}
|
|
4332
|
+
|
|
4333
|
+
context.stroke();
|
|
4334
|
+
}
|
|
4335
|
+
};
|
|
4336
|
+
|
|
4337
|
+
_proto.getPattern = function getPattern(pattern, object, context, renderingService) {
|
|
4338
|
+
var canvasPattern = this.imagePool.getOrCreatePatternSync(pattern, context, function () {
|
|
4339
|
+
// set dirty rectangle flag
|
|
4340
|
+
object.renderable.dirty = true;
|
|
4341
|
+
renderingService.dirtify();
|
|
4342
|
+
});
|
|
4343
|
+
return canvasPattern;
|
|
4344
|
+
};
|
|
4345
|
+
|
|
4346
|
+
_proto.getColor = function getColor(parsedColor, object, context) {
|
|
4347
|
+
var color;
|
|
4348
|
+
|
|
4349
|
+
if (parsedColor.type === g.GradientType.LinearGradient || parsedColor.type === g.GradientType.RadialGradient) {
|
|
4350
|
+
var bounds = object.getGeometryBounds();
|
|
4351
|
+
var width = bounds && bounds.halfExtents[0] * 2 || 1;
|
|
4352
|
+
var height = bounds && bounds.halfExtents[1] * 2 || 1;
|
|
4353
|
+
color = this.imagePool.getOrCreateGradient(_extends({
|
|
4354
|
+
type: parsedColor.type
|
|
4355
|
+
}, parsedColor.value, {
|
|
4356
|
+
width: width,
|
|
4357
|
+
height: height
|
|
4358
|
+
}), context);
|
|
4359
|
+
}
|
|
4360
|
+
|
|
4361
|
+
return color;
|
|
4362
|
+
};
|
|
4363
|
+
|
|
4364
|
+
return DefaultRenderer;
|
|
4365
|
+
}();
|
|
4366
|
+
|
|
4367
|
+
__decorate([g.inject(ImagePool), __metadata("design:type", ImagePool)], DefaultRenderer.prototype, "imagePool", void 0);
|
|
4368
|
+
|
|
4369
|
+
DefaultRenderer = __decorate([g.singleton()], DefaultRenderer);
|
|
4370
|
+
/**
|
|
4371
|
+
* apply before fill and stroke but only once
|
|
4372
|
+
*/
|
|
4373
|
+
|
|
4374
|
+
function setShadowAndFilter(object, context, hasShadow) {
|
|
4375
|
+
var _object$parsedStyle = object.parsedStyle,
|
|
4376
|
+
filter = _object$parsedStyle.filter,
|
|
4377
|
+
shadowColor = _object$parsedStyle.shadowColor,
|
|
4378
|
+
shadowBlur = _object$parsedStyle.shadowBlur,
|
|
4379
|
+
shadowOffsetX = _object$parsedStyle.shadowOffsetX,
|
|
4380
|
+
shadowOffsetY = _object$parsedStyle.shadowOffsetY;
|
|
4381
|
+
|
|
4382
|
+
if (filter && filter.length) {
|
|
4383
|
+
// use raw filter string
|
|
4384
|
+
context.filter = object.style.filter;
|
|
4385
|
+
}
|
|
4386
|
+
|
|
4387
|
+
if (hasShadow) {
|
|
4388
|
+
context.shadowColor = shadowColor.toString();
|
|
4389
|
+
context.shadowBlur = shadowBlur || 0;
|
|
4390
|
+
context.shadowOffsetX = shadowOffsetX || 0;
|
|
4391
|
+
context.shadowOffsetY = shadowOffsetY || 0;
|
|
4392
|
+
}
|
|
4393
|
+
}
|
|
4394
|
+
|
|
4211
4395
|
var ImageRenderer = /*#__PURE__*/function () {
|
|
4212
4396
|
function ImageRenderer() {
|
|
4213
4397
|
this.imagePool = void 0;
|
|
@@ -4215,13 +4399,15 @@
|
|
|
4215
4399
|
|
|
4216
4400
|
var _proto = ImageRenderer.prototype;
|
|
4217
4401
|
|
|
4218
|
-
_proto.render = function render(context, parsedStyle) {
|
|
4402
|
+
_proto.render = function render(context, parsedStyle, object) {
|
|
4219
4403
|
var width = parsedStyle.width,
|
|
4220
4404
|
height = parsedStyle.height,
|
|
4221
|
-
img = parsedStyle.img
|
|
4405
|
+
img = parsedStyle.img,
|
|
4406
|
+
shadowColor = parsedStyle.shadowColor,
|
|
4407
|
+
shadowBlur = parsedStyle.shadowBlur;
|
|
4222
4408
|
var image;
|
|
4223
|
-
var iw = width
|
|
4224
|
-
var ih = height
|
|
4409
|
+
var iw = width;
|
|
4410
|
+
var ih = height;
|
|
4225
4411
|
|
|
4226
4412
|
if (g.isString(img)) {
|
|
4227
4413
|
// image has been loaded in `mounted` hook
|
|
@@ -4233,8 +4419,10 @@
|
|
|
4233
4419
|
}
|
|
4234
4420
|
|
|
4235
4421
|
if (image) {
|
|
4236
|
-
|
|
4422
|
+
var hasShadow = !g.isNil(shadowColor) && shadowBlur > 0;
|
|
4423
|
+
setShadowAndFilter(object, context, hasShadow); // node-canvas will throw the following err:
|
|
4237
4424
|
// Error: Image given has not completed loading
|
|
4425
|
+
|
|
4238
4426
|
try {
|
|
4239
4427
|
context.drawImage(image, 0, 0, iw, ih);
|
|
4240
4428
|
} catch (e) {}
|
|
@@ -4269,55 +4457,51 @@
|
|
|
4269
4457
|
opacity = parsedStyle.opacity,
|
|
4270
4458
|
metrics = parsedStyle.metrics,
|
|
4271
4459
|
dx = parsedStyle.dx,
|
|
4272
|
-
dy = parsedStyle.dy
|
|
4460
|
+
dy = parsedStyle.dy,
|
|
4461
|
+
shadowColor = parsedStyle.shadowColor,
|
|
4462
|
+
shadowBlur = parsedStyle.shadowBlur;
|
|
4273
4463
|
var font = metrics.font,
|
|
4274
4464
|
lines = metrics.lines,
|
|
4275
4465
|
height = metrics.height,
|
|
4276
4466
|
lineHeight = metrics.lineHeight,
|
|
4277
4467
|
lineMetrics = metrics.lineMetrics;
|
|
4278
4468
|
context.font = font;
|
|
4279
|
-
context.lineWidth = lineWidth
|
|
4280
|
-
context.textAlign = textAlign
|
|
4281
|
-
context.textBaseline = textBaseline
|
|
4282
|
-
context.lineJoin = lineJoin
|
|
4469
|
+
context.lineWidth = lineWidth;
|
|
4470
|
+
context.textAlign = textAlign;
|
|
4471
|
+
context.textBaseline = textBaseline;
|
|
4472
|
+
context.lineJoin = lineJoin;
|
|
4283
4473
|
|
|
4284
4474
|
if (!g.isNil(miterLimit)) {
|
|
4285
|
-
context.miterLimit = miterLimit
|
|
4475
|
+
context.miterLimit = miterLimit;
|
|
4286
4476
|
}
|
|
4287
4477
|
|
|
4288
4478
|
var linePositionY = 0; // handle vertical text baseline
|
|
4289
4479
|
|
|
4290
|
-
if (textBaseline
|
|
4480
|
+
if (textBaseline === 'middle') {
|
|
4291
4481
|
linePositionY = -height / 2 - lineHeight / 2;
|
|
4292
|
-
} else if (textBaseline
|
|
4482
|
+
} else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
|
|
4293
4483
|
linePositionY = -height;
|
|
4294
|
-
} else if (textBaseline
|
|
4484
|
+
} else if (textBaseline === 'top' || textBaseline === 'hanging') {
|
|
4295
4485
|
linePositionY = -lineHeight;
|
|
4296
4486
|
} // account for dx & dy
|
|
4297
4487
|
|
|
4298
4488
|
|
|
4299
|
-
var offsetX = 0;
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
}
|
|
4304
|
-
|
|
4305
|
-
if (dy && dy.unit === g.UnitType.kPixels) {
|
|
4306
|
-
linePositionY += dy.value;
|
|
4307
|
-
} // draw lines line by line
|
|
4308
|
-
|
|
4489
|
+
var offsetX = dx || 0;
|
|
4490
|
+
linePositionY += dy || 0;
|
|
4491
|
+
var hasShadow = !g.isNil(shadowColor) && shadowBlur > 0;
|
|
4492
|
+
setShadowAndFilter(object, context, hasShadow); // draw lines line by line
|
|
4309
4493
|
|
|
4310
4494
|
for (var i = 0; i < lines.length; i++) {
|
|
4311
|
-
var linePositionX = lineWidth
|
|
4495
|
+
var linePositionX = lineWidth / 2 + offsetX;
|
|
4312
4496
|
linePositionY += lineHeight; // no need to re-position X, cause we already set text align
|
|
4313
4497
|
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
|
|
4314
4498
|
|
|
4315
|
-
if (!g.isNil(stroke) && !stroke.isNone && lineWidth
|
|
4316
|
-
this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign
|
|
4499
|
+
if (!g.isNil(stroke) && !stroke.isNone && lineWidth) {
|
|
4500
|
+
this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity, true);
|
|
4317
4501
|
}
|
|
4318
4502
|
|
|
4319
4503
|
if (!g.isNil(fill)) {
|
|
4320
|
-
this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign
|
|
4504
|
+
this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity);
|
|
4321
4505
|
}
|
|
4322
4506
|
}
|
|
4323
4507
|
};
|
|
@@ -4409,193 +4593,6 @@
|
|
|
4409
4593
|
token: TextRendererContribution
|
|
4410
4594
|
})], TextRenderer);
|
|
4411
4595
|
|
|
4412
|
-
var DefaultRenderer = /*#__PURE__*/function () {
|
|
4413
|
-
function DefaultRenderer() {
|
|
4414
|
-
this.imagePool = void 0;
|
|
4415
|
-
}
|
|
4416
|
-
|
|
4417
|
-
var _proto = DefaultRenderer.prototype;
|
|
4418
|
-
|
|
4419
|
-
_proto.render = function render(context, parsedStyle, object, renderingService) {
|
|
4420
|
-
var fill = parsedStyle.fill,
|
|
4421
|
-
opacity = parsedStyle.opacity,
|
|
4422
|
-
fillOpacity = parsedStyle.fillOpacity,
|
|
4423
|
-
stroke = parsedStyle.stroke,
|
|
4424
|
-
strokeOpacity = parsedStyle.strokeOpacity,
|
|
4425
|
-
lineWidth = parsedStyle.lineWidth,
|
|
4426
|
-
lineCap = parsedStyle.lineCap,
|
|
4427
|
-
lineJoin = parsedStyle.lineJoin,
|
|
4428
|
-
shadowType = parsedStyle.shadowType,
|
|
4429
|
-
shadowColor = parsedStyle.shadowColor,
|
|
4430
|
-
shadowBlur = parsedStyle.shadowBlur,
|
|
4431
|
-
filter = parsedStyle.filter,
|
|
4432
|
-
miterLimit = parsedStyle.miterLimit;
|
|
4433
|
-
var hasFill = !g.isNil(fill) && !fill.isNone;
|
|
4434
|
-
var hasStroke = !g.isNil(stroke) && !stroke.isNone && lineWidth && lineWidth.value > 0;
|
|
4435
|
-
var isFillTransparent = fill.alpha === 0;
|
|
4436
|
-
var hasFilter = !g.isNil(filter);
|
|
4437
|
-
var hasShadow = !g.isNil(shadowColor) && (shadowBlur === null || shadowBlur === void 0 ? void 0 : shadowBlur.value) > 0;
|
|
4438
|
-
var nodeName = object.nodeName;
|
|
4439
|
-
var isInnerShadow = (shadowType === null || shadowType === void 0 ? void 0 : shadowType.value) === 'inner';
|
|
4440
|
-
var shouldDrawShadowWithStroke = hasStroke && hasShadow && (nodeName === g.Shape.PATH || nodeName === g.Shape.LINE || nodeName === g.Shape.POLYLINE || isFillTransparent || isInnerShadow);
|
|
4441
|
-
|
|
4442
|
-
if (hasFill) {
|
|
4443
|
-
context.globalAlpha = opacity.value * fillOpacity.value;
|
|
4444
|
-
|
|
4445
|
-
if (!shouldDrawShadowWithStroke) {
|
|
4446
|
-
this.setShadowAndFilter(object, context, hasShadow);
|
|
4447
|
-
}
|
|
4448
|
-
|
|
4449
|
-
this.fill(context, object, fill, renderingService);
|
|
4450
|
-
|
|
4451
|
-
if (!shouldDrawShadowWithStroke) {
|
|
4452
|
-
this.clearShadowAndFilter(context, hasFilter, hasShadow);
|
|
4453
|
-
}
|
|
4454
|
-
}
|
|
4455
|
-
|
|
4456
|
-
if (hasStroke) {
|
|
4457
|
-
context.globalAlpha = opacity.value * strokeOpacity.value;
|
|
4458
|
-
context.lineWidth = lineWidth.value;
|
|
4459
|
-
|
|
4460
|
-
if (!g.isNil(miterLimit)) {
|
|
4461
|
-
context.miterLimit = miterLimit.value;
|
|
4462
|
-
}
|
|
4463
|
-
|
|
4464
|
-
if (!g.isNil(lineCap)) {
|
|
4465
|
-
context.lineCap = lineCap.value;
|
|
4466
|
-
}
|
|
4467
|
-
|
|
4468
|
-
if (!g.isNil(lineJoin)) {
|
|
4469
|
-
context.lineJoin = lineJoin.value;
|
|
4470
|
-
}
|
|
4471
|
-
|
|
4472
|
-
if (shouldDrawShadowWithStroke) {
|
|
4473
|
-
if (isInnerShadow) {
|
|
4474
|
-
context.globalCompositeOperation = 'source-atop';
|
|
4475
|
-
}
|
|
4476
|
-
|
|
4477
|
-
this.setShadowAndFilter(object, context, true);
|
|
4478
|
-
|
|
4479
|
-
if (isInnerShadow) {
|
|
4480
|
-
this.stroke(context, object, stroke, renderingService);
|
|
4481
|
-
context.globalCompositeOperation = 'source-over';
|
|
4482
|
-
this.clearShadowAndFilter(context, hasFilter, true);
|
|
4483
|
-
}
|
|
4484
|
-
}
|
|
4485
|
-
|
|
4486
|
-
this.stroke(context, object, stroke, renderingService);
|
|
4487
|
-
}
|
|
4488
|
-
};
|
|
4489
|
-
|
|
4490
|
-
_proto.clearShadowAndFilter = function clearShadowAndFilter(context, hasFilter, hasShadow) {
|
|
4491
|
-
if (hasShadow) {
|
|
4492
|
-
context.shadowColor = 'transparent';
|
|
4493
|
-
context.shadowBlur = 0;
|
|
4494
|
-
}
|
|
4495
|
-
|
|
4496
|
-
if (hasFilter) {
|
|
4497
|
-
// save drop-shadow filter
|
|
4498
|
-
var oldFilter = context.filter;
|
|
4499
|
-
|
|
4500
|
-
if (!g.isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
|
|
4501
|
-
context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
|
|
4502
|
-
}
|
|
4503
|
-
}
|
|
4504
|
-
}
|
|
4505
|
-
/**
|
|
4506
|
-
* apply before fill and stroke but only once
|
|
4507
|
-
*/
|
|
4508
|
-
;
|
|
4509
|
-
|
|
4510
|
-
_proto.setShadowAndFilter = function setShadowAndFilter(object, context, hasShadow) {
|
|
4511
|
-
var _object$parsedStyle = object.parsedStyle,
|
|
4512
|
-
filter = _object$parsedStyle.filter,
|
|
4513
|
-
shadowColor = _object$parsedStyle.shadowColor,
|
|
4514
|
-
shadowBlur = _object$parsedStyle.shadowBlur,
|
|
4515
|
-
shadowOffsetX = _object$parsedStyle.shadowOffsetX,
|
|
4516
|
-
shadowOffsetY = _object$parsedStyle.shadowOffsetY;
|
|
4517
|
-
|
|
4518
|
-
if (!g.isNil(filter)) {
|
|
4519
|
-
// use raw filter string
|
|
4520
|
-
context.filter = object.style.filter;
|
|
4521
|
-
}
|
|
4522
|
-
|
|
4523
|
-
if (hasShadow) {
|
|
4524
|
-
context.shadowColor = shadowColor.toString();
|
|
4525
|
-
context.shadowBlur = shadowBlur && shadowBlur.value || 0;
|
|
4526
|
-
context.shadowOffsetX = shadowOffsetX && shadowOffsetX.value || 0;
|
|
4527
|
-
context.shadowOffsetY = shadowOffsetY && shadowOffsetY.value || 0;
|
|
4528
|
-
}
|
|
4529
|
-
};
|
|
4530
|
-
|
|
4531
|
-
_proto.fill = function fill(context, object, _fill, renderingService) {
|
|
4532
|
-
var _this = this;
|
|
4533
|
-
|
|
4534
|
-
if (Array.isArray(_fill)) {
|
|
4535
|
-
_fill.forEach(function (gradient) {
|
|
4536
|
-
context.fillStyle = _this.getColor(gradient, object, context);
|
|
4537
|
-
context.fill();
|
|
4538
|
-
});
|
|
4539
|
-
} else {
|
|
4540
|
-
if (g.isPattern(_fill)) {
|
|
4541
|
-
context.fillStyle = this.getPattern(_fill, object, context, renderingService);
|
|
4542
|
-
}
|
|
4543
|
-
|
|
4544
|
-
context.fill();
|
|
4545
|
-
}
|
|
4546
|
-
};
|
|
4547
|
-
|
|
4548
|
-
_proto.stroke = function stroke(context, object, _stroke, renderingService) {
|
|
4549
|
-
var _this2 = this;
|
|
4550
|
-
|
|
4551
|
-
if (Array.isArray(_stroke)) {
|
|
4552
|
-
_stroke.forEach(function (gradient) {
|
|
4553
|
-
context.strokeStyle = _this2.getColor(gradient, object, context);
|
|
4554
|
-
context.stroke();
|
|
4555
|
-
});
|
|
4556
|
-
} else {
|
|
4557
|
-
if (g.isPattern(_stroke)) {
|
|
4558
|
-
context.strokeStyle = this.getPattern(_stroke, object, context, renderingService);
|
|
4559
|
-
}
|
|
4560
|
-
|
|
4561
|
-
context.stroke();
|
|
4562
|
-
}
|
|
4563
|
-
};
|
|
4564
|
-
|
|
4565
|
-
_proto.getPattern = function getPattern(pattern, object, context, renderingService) {
|
|
4566
|
-
var canvasPattern = this.imagePool.getOrCreatePatternSync(pattern, context, function () {
|
|
4567
|
-
// set dirty rectangle flag
|
|
4568
|
-
object.renderable.dirty = true;
|
|
4569
|
-
renderingService.dirtify();
|
|
4570
|
-
});
|
|
4571
|
-
return canvasPattern;
|
|
4572
|
-
};
|
|
4573
|
-
|
|
4574
|
-
_proto.getColor = function getColor(parsedColor, object, context) {
|
|
4575
|
-
var color;
|
|
4576
|
-
|
|
4577
|
-
if (parsedColor.type === g.GradientType.LinearGradient || parsedColor.type === g.GradientType.RadialGradient) {
|
|
4578
|
-
var bounds = object.getGeometryBounds();
|
|
4579
|
-
var width = bounds && bounds.halfExtents[0] * 2 || 1;
|
|
4580
|
-
var height = bounds && bounds.halfExtents[1] * 2 || 1;
|
|
4581
|
-
color = this.imagePool.getOrCreateGradient(_extends({
|
|
4582
|
-
type: parsedColor.type
|
|
4583
|
-
}, parsedColor.value, {
|
|
4584
|
-
width: width,
|
|
4585
|
-
height: height
|
|
4586
|
-
}), context);
|
|
4587
|
-
}
|
|
4588
|
-
|
|
4589
|
-
return color;
|
|
4590
|
-
};
|
|
4591
|
-
|
|
4592
|
-
return DefaultRenderer;
|
|
4593
|
-
}();
|
|
4594
|
-
|
|
4595
|
-
__decorate([g.inject(ImagePool), __metadata("design:type", ImagePool)], DefaultRenderer.prototype, "imagePool", void 0);
|
|
4596
|
-
|
|
4597
|
-
DefaultRenderer = __decorate([g.singleton()], DefaultRenderer);
|
|
4598
|
-
|
|
4599
4596
|
var RectRenderer = /*#__PURE__*/function (_DefaultRenderer) {
|
|
4600
4597
|
_inheritsLoose$4(RectRenderer, _DefaultRenderer);
|
|
4601
4598
|
|
|
@@ -4693,7 +4690,7 @@
|
|
|
4693
4690
|
PathRenderer = __decorate([g.singleton({
|
|
4694
4691
|
token: PathRendererContribution
|
|
4695
4692
|
})], PathRenderer);
|
|
4696
|
-
var CanvasRendererPluginOptions = g.Syringe.defineToken('
|
|
4693
|
+
var CanvasRendererPluginOptions = g.Syringe.defineToken('');
|
|
4697
4694
|
|
|
4698
4695
|
var _class$2;
|
|
4699
4696
|
|
|
@@ -4724,7 +4721,10 @@
|
|
|
4724
4721
|
this.vpMatrix = create$3();
|
|
4725
4722
|
this.dprMatrix = create$3();
|
|
4726
4723
|
this.tmpMat4 = create$3();
|
|
4727
|
-
this.
|
|
4724
|
+
this.vec3a = create$1$1();
|
|
4725
|
+
this.vec3b = create$1$1();
|
|
4726
|
+
this.vec3c = create$1$1();
|
|
4727
|
+
this.vec3d = create$1$1();
|
|
4728
4728
|
}
|
|
4729
4729
|
|
|
4730
4730
|
var _proto = CanvasRendererPlugin.prototype;
|
|
@@ -4775,7 +4775,7 @@
|
|
|
4775
4775
|
|
|
4776
4776
|
_this.clearRect(context, 0, 0, width * dpr, height * dpr);
|
|
4777
4777
|
|
|
4778
|
-
fromScaling(_this.dprMatrix, fromValues
|
|
4778
|
+
fromScaling(_this.dprMatrix, fromValues(dpr, dpr, 1));
|
|
4779
4779
|
|
|
4780
4780
|
case 7:
|
|
4781
4781
|
case "end":
|
|
@@ -4823,14 +4823,13 @@
|
|
|
4823
4823
|
|
|
4824
4824
|
|
|
4825
4825
|
_this.saveDirtyAABB(object);
|
|
4826
|
-
}
|
|
4826
|
+
}
|
|
4827
4827
|
|
|
4828
|
+
var sorted = object.sortable.sorted || object.childNodes; // should account for z-index
|
|
4828
4829
|
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
});
|
|
4833
|
-
}
|
|
4830
|
+
sorted.forEach(function (child) {
|
|
4831
|
+
renderByZIndex(child);
|
|
4832
|
+
});
|
|
4834
4833
|
}; // render at the end of frame
|
|
4835
4834
|
|
|
4836
4835
|
|
|
@@ -4850,7 +4849,7 @@
|
|
|
4850
4849
|
maxX = _ref2.maxX,
|
|
4851
4850
|
maxY = _ref2.maxY;
|
|
4852
4851
|
var aabb = new g.AABB();
|
|
4853
|
-
aabb.setMinMax(fromValues
|
|
4852
|
+
aabb.setMinMax(fromValues(minX, minY, 0), fromValues(maxX, maxY, 0));
|
|
4854
4853
|
return aabb;
|
|
4855
4854
|
})));
|
|
4856
4855
|
|
|
@@ -4867,12 +4866,18 @@
|
|
|
4867
4866
|
y = dirtyRect.y,
|
|
4868
4867
|
width = dirtyRect.width,
|
|
4869
4868
|
height = dirtyRect.height;
|
|
4870
|
-
var tl = transformMat4$1(_this.
|
|
4871
|
-
var
|
|
4872
|
-
var
|
|
4873
|
-
var
|
|
4874
|
-
var
|
|
4875
|
-
var
|
|
4869
|
+
var tl = transformMat4$1(_this.vec3a, fromValues(x, y, 0), _this.vpMatrix);
|
|
4870
|
+
var tr = transformMat4$1(_this.vec3b, fromValues(x + width, y, 0), _this.vpMatrix);
|
|
4871
|
+
var bl = transformMat4$1(_this.vec3c, fromValues(x, y + height, 0), _this.vpMatrix);
|
|
4872
|
+
var br = transformMat4$1(_this.vec3d, fromValues(x + width, y + height, 0), _this.vpMatrix);
|
|
4873
|
+
var minx = Math.min(tl[0], tr[0], br[0], bl[0]);
|
|
4874
|
+
var miny = Math.min(tl[1], tr[1], br[1], bl[1]);
|
|
4875
|
+
var maxx = Math.max(tl[0], tr[0], br[0], bl[0]);
|
|
4876
|
+
var maxy = Math.max(tl[1], tr[1], br[1], bl[1]);
|
|
4877
|
+
var ix = Math.floor(minx);
|
|
4878
|
+
var iy = Math.floor(miny);
|
|
4879
|
+
var iwidth = Math.ceil(maxx - minx);
|
|
4880
|
+
var iheight = Math.ceil(maxy - miny);
|
|
4876
4881
|
context.save();
|
|
4877
4882
|
|
|
4878
4883
|
_this.clearRect(context, ix, iy, iwidth, iheight);
|
|
@@ -4888,7 +4893,12 @@
|
|
|
4888
4893
|
|
|
4889
4894
|
if (enableDirtyRectangleRenderingDebug) {
|
|
4890
4895
|
canvas.dispatchEvent(new g.CustomEvent(g.CanvasEvent.DIRTY_RECTANGLE, {
|
|
4891
|
-
dirtyRect:
|
|
4896
|
+
dirtyRect: {
|
|
4897
|
+
x: ix,
|
|
4898
|
+
y: iy,
|
|
4899
|
+
width: iwidth,
|
|
4900
|
+
height: iheight
|
|
4901
|
+
}
|
|
4892
4902
|
}));
|
|
4893
4903
|
} // search objects intersect with dirty rectangle
|
|
4894
4904
|
|
|
@@ -5114,19 +5124,17 @@
|
|
|
5114
5124
|
lineDash = _object$parsedStyle.lineDash,
|
|
5115
5125
|
lineDashOffset = _object$parsedStyle.lineDashOffset; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
|
|
5116
5126
|
|
|
5117
|
-
if (lineDash
|
|
5118
|
-
context.setLineDash(lineDash
|
|
5119
|
-
return segment.value;
|
|
5120
|
-
}));
|
|
5127
|
+
if (lineDash) {
|
|
5128
|
+
context.setLineDash(lineDash);
|
|
5121
5129
|
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
|
|
5122
5130
|
|
|
5123
5131
|
|
|
5124
5132
|
if (!g.isNil(lineDashOffset)) {
|
|
5125
|
-
context.lineDashOffset = lineDashOffset
|
|
5133
|
+
context.lineDashOffset = lineDashOffset;
|
|
5126
5134
|
}
|
|
5127
5135
|
|
|
5128
5136
|
if (!g.isNil(opacity)) {
|
|
5129
|
-
context.globalAlpha *= opacity
|
|
5137
|
+
context.globalAlpha *= opacity;
|
|
5130
5138
|
}
|
|
5131
5139
|
|
|
5132
5140
|
if (!g.isNil(stroke) && !Array.isArray(stroke) && !stroke.isNone) {
|
|
@@ -5145,8 +5153,8 @@
|
|
|
5145
5153
|
var _ref4 = object.parsedStyle || {},
|
|
5146
5154
|
anchor = _ref4.anchor;
|
|
5147
5155
|
|
|
5148
|
-
var anchorX = anchor && anchor[0]
|
|
5149
|
-
var anchorY = anchor && anchor[1]
|
|
5156
|
+
var anchorX = anchor && anchor[0] || 0;
|
|
5157
|
+
var anchorY = anchor && anchor[1] || 0;
|
|
5150
5158
|
|
|
5151
5159
|
if (anchorX !== 0 || anchorY !== 0) {
|
|
5152
5160
|
var bounds = object.getGeometryBounds();
|
|
@@ -5159,19 +5167,19 @@
|
|
|
5159
5167
|
|
|
5160
5168
|
if (matrix) {
|
|
5161
5169
|
copy(this.tmpMat4, object.getLocalTransform());
|
|
5162
|
-
this.
|
|
5163
|
-
this.
|
|
5164
|
-
this.
|
|
5165
|
-
translate(this.tmpMat4, this.tmpMat4, this.
|
|
5170
|
+
this.vec3a[0] = tx;
|
|
5171
|
+
this.vec3a[1] = ty;
|
|
5172
|
+
this.vec3a[2] = 0;
|
|
5173
|
+
translate(this.tmpMat4, this.tmpMat4, this.vec3a);
|
|
5166
5174
|
multiply$1(this.tmpMat4, matrix, this.tmpMat4);
|
|
5167
5175
|
multiply$1(this.tmpMat4, this.vpMatrix, this.tmpMat4);
|
|
5168
5176
|
} else {
|
|
5169
5177
|
// apply RTS transformation in world space
|
|
5170
5178
|
copy(this.tmpMat4, object.getWorldTransform());
|
|
5171
|
-
this.
|
|
5172
|
-
this.
|
|
5173
|
-
this.
|
|
5174
|
-
translate(this.tmpMat4, this.tmpMat4, this.
|
|
5179
|
+
this.vec3a[0] = tx;
|
|
5180
|
+
this.vec3a[1] = ty;
|
|
5181
|
+
this.vec3a[2] = 0;
|
|
5182
|
+
translate(this.tmpMat4, this.tmpMat4, this.vec3a);
|
|
5175
5183
|
multiply$1(this.tmpMat4, this.vpMatrix, this.tmpMat4);
|
|
5176
5184
|
} // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
|
|
5177
5185
|
|
|
@@ -6501,22 +6509,22 @@
|
|
|
6501
6509
|
|
|
6502
6510
|
case 'zIndex':
|
|
6503
6511
|
var zIndex = object.parsedStyle.zIndex;
|
|
6504
|
-
$el.style['z-index'] = "" + zIndex
|
|
6512
|
+
$el.style['z-index'] = "" + zIndex;
|
|
6505
6513
|
break;
|
|
6506
6514
|
|
|
6507
6515
|
case 'visibility':
|
|
6508
6516
|
var visibility = object.parsedStyle.visibility;
|
|
6509
|
-
$el.style.visibility = visibility
|
|
6517
|
+
$el.style.visibility = visibility;
|
|
6510
6518
|
break;
|
|
6511
6519
|
|
|
6512
6520
|
case 'pointerEvents':
|
|
6513
6521
|
var pointerEvents = object.parsedStyle.pointerEvents;
|
|
6514
|
-
$el.style.pointerEvents = pointerEvents
|
|
6522
|
+
$el.style.pointerEvents = pointerEvents;
|
|
6515
6523
|
break;
|
|
6516
6524
|
|
|
6517
6525
|
case 'opacity':
|
|
6518
6526
|
var opacity = object.parsedStyle.opacity;
|
|
6519
|
-
$el.style.opacity = "" + opacity
|
|
6527
|
+
$el.style.opacity = "" + opacity;
|
|
6520
6528
|
break;
|
|
6521
6529
|
|
|
6522
6530
|
case 'fill':
|
|
@@ -6556,7 +6564,7 @@
|
|
|
6556
6564
|
|
|
6557
6565
|
case 'lineWidth':
|
|
6558
6566
|
var lineWidth = object.parsedStyle.lineWidth;
|
|
6559
|
-
$el.style['border-width'] = (lineWidth
|
|
6567
|
+
$el.style['border-width'] = (lineWidth || 0) + "px";
|
|
6560
6568
|
break;
|
|
6561
6569
|
|
|
6562
6570
|
case 'lineDash':
|
|
@@ -6564,7 +6572,7 @@
|
|
|
6564
6572
|
break;
|
|
6565
6573
|
|
|
6566
6574
|
case 'filter':
|
|
6567
|
-
var filter = object.
|
|
6575
|
+
var filter = object.style.filter;
|
|
6568
6576
|
$el.style.filter = filter;
|
|
6569
6577
|
break;
|
|
6570
6578
|
}
|