@antv/g-canvas 1.7.2 → 1.7.5
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 +363 -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
|
// 以后可以改成纯数学的近似拾取,将圆弧切割成多边形
|
|
@@ -4107,7 +4101,7 @@
|
|
|
4107
4101
|
*/
|
|
4108
4102
|
|
|
4109
4103
|
|
|
4110
|
-
function fromValues
|
|
4104
|
+
function fromValues(x, y, z) {
|
|
4111
4105
|
var out = new ARRAY_TYPE$1(3);
|
|
4112
4106
|
out[0] = x;
|
|
4113
4107
|
out[1] = y;
|
|
@@ -4183,35 +4177,221 @@
|
|
|
4183
4177
|
};
|
|
4184
4178
|
}();
|
|
4185
4179
|
|
|
4186
|
-
var StyleRendererFactory = g.Syringe.defineToken('
|
|
4187
|
-
var CircleRendererContribution = g.Syringe.defineToken('
|
|
4180
|
+
var StyleRendererFactory = g.Syringe.defineToken('');
|
|
4181
|
+
var CircleRendererContribution = g.Syringe.defineToken('', {
|
|
4188
4182
|
multiple: false
|
|
4189
4183
|
});
|
|
4190
|
-
var EllipseRendererContribution = g.Syringe.defineToken('
|
|
4184
|
+
var EllipseRendererContribution = g.Syringe.defineToken('', {
|
|
4191
4185
|
multiple: false
|
|
4192
4186
|
});
|
|
4193
|
-
var RectRendererContribution = g.Syringe.defineToken('
|
|
4187
|
+
var RectRendererContribution = g.Syringe.defineToken('', {
|
|
4194
4188
|
multiple: false
|
|
4195
4189
|
});
|
|
4196
|
-
var LineRendererContribution = g.Syringe.defineToken('
|
|
4190
|
+
var LineRendererContribution = g.Syringe.defineToken('', {
|
|
4197
4191
|
multiple: false
|
|
4198
4192
|
});
|
|
4199
|
-
var PolylineRendererContribution = g.Syringe.defineToken('
|
|
4193
|
+
var PolylineRendererContribution = g.Syringe.defineToken('', {
|
|
4200
4194
|
multiple: false
|
|
4201
4195
|
});
|
|
4202
|
-
var PolygonRendererContribution = g.Syringe.defineToken('
|
|
4196
|
+
var PolygonRendererContribution = g.Syringe.defineToken('', {
|
|
4203
4197
|
multiple: false
|
|
4204
4198
|
});
|
|
4205
|
-
var PathRendererContribution = g.Syringe.defineToken('
|
|
4199
|
+
var PathRendererContribution = g.Syringe.defineToken('', {
|
|
4206
4200
|
multiple: false
|
|
4207
4201
|
});
|
|
4208
|
-
var TextRendererContribution = g.Syringe.defineToken('
|
|
4202
|
+
var TextRendererContribution = g.Syringe.defineToken('', {
|
|
4209
4203
|
multiple: false
|
|
4210
4204
|
});
|
|
4211
|
-
var ImageRendererContribution = g.Syringe.defineToken('
|
|
4205
|
+
var ImageRendererContribution = g.Syringe.defineToken('', {
|
|
4212
4206
|
multiple: false
|
|
4213
4207
|
});
|
|
4214
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
|
+
|
|
4215
4395
|
var ImageRenderer = /*#__PURE__*/function () {
|
|
4216
4396
|
function ImageRenderer() {
|
|
4217
4397
|
this.imagePool = void 0;
|
|
@@ -4219,13 +4399,15 @@
|
|
|
4219
4399
|
|
|
4220
4400
|
var _proto = ImageRenderer.prototype;
|
|
4221
4401
|
|
|
4222
|
-
_proto.render = function render(context, parsedStyle) {
|
|
4402
|
+
_proto.render = function render(context, parsedStyle, object) {
|
|
4223
4403
|
var width = parsedStyle.width,
|
|
4224
4404
|
height = parsedStyle.height,
|
|
4225
|
-
img = parsedStyle.img
|
|
4405
|
+
img = parsedStyle.img,
|
|
4406
|
+
shadowColor = parsedStyle.shadowColor,
|
|
4407
|
+
shadowBlur = parsedStyle.shadowBlur;
|
|
4226
4408
|
var image;
|
|
4227
|
-
var iw = width
|
|
4228
|
-
var ih = height
|
|
4409
|
+
var iw = width;
|
|
4410
|
+
var ih = height;
|
|
4229
4411
|
|
|
4230
4412
|
if (g.isString(img)) {
|
|
4231
4413
|
// image has been loaded in `mounted` hook
|
|
@@ -4237,8 +4419,10 @@
|
|
|
4237
4419
|
}
|
|
4238
4420
|
|
|
4239
4421
|
if (image) {
|
|
4240
|
-
|
|
4422
|
+
var hasShadow = !g.isNil(shadowColor) && shadowBlur > 0;
|
|
4423
|
+
setShadowAndFilter(object, context, hasShadow); // node-canvas will throw the following err:
|
|
4241
4424
|
// Error: Image given has not completed loading
|
|
4425
|
+
|
|
4242
4426
|
try {
|
|
4243
4427
|
context.drawImage(image, 0, 0, iw, ih);
|
|
4244
4428
|
} catch (e) {}
|
|
@@ -4273,55 +4457,51 @@
|
|
|
4273
4457
|
opacity = parsedStyle.opacity,
|
|
4274
4458
|
metrics = parsedStyle.metrics,
|
|
4275
4459
|
dx = parsedStyle.dx,
|
|
4276
|
-
dy = parsedStyle.dy
|
|
4460
|
+
dy = parsedStyle.dy,
|
|
4461
|
+
shadowColor = parsedStyle.shadowColor,
|
|
4462
|
+
shadowBlur = parsedStyle.shadowBlur;
|
|
4277
4463
|
var font = metrics.font,
|
|
4278
4464
|
lines = metrics.lines,
|
|
4279
4465
|
height = metrics.height,
|
|
4280
4466
|
lineHeight = metrics.lineHeight,
|
|
4281
4467
|
lineMetrics = metrics.lineMetrics;
|
|
4282
4468
|
context.font = font;
|
|
4283
|
-
context.lineWidth = lineWidth
|
|
4284
|
-
context.textAlign = textAlign
|
|
4285
|
-
context.textBaseline = textBaseline
|
|
4286
|
-
context.lineJoin = lineJoin
|
|
4469
|
+
context.lineWidth = lineWidth;
|
|
4470
|
+
context.textAlign = textAlign;
|
|
4471
|
+
context.textBaseline = textBaseline;
|
|
4472
|
+
context.lineJoin = lineJoin;
|
|
4287
4473
|
|
|
4288
4474
|
if (!g.isNil(miterLimit)) {
|
|
4289
|
-
context.miterLimit = miterLimit
|
|
4475
|
+
context.miterLimit = miterLimit;
|
|
4290
4476
|
}
|
|
4291
4477
|
|
|
4292
4478
|
var linePositionY = 0; // handle vertical text baseline
|
|
4293
4479
|
|
|
4294
|
-
if (textBaseline
|
|
4480
|
+
if (textBaseline === 'middle') {
|
|
4295
4481
|
linePositionY = -height / 2 - lineHeight / 2;
|
|
4296
|
-
} else if (textBaseline
|
|
4482
|
+
} else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
|
|
4297
4483
|
linePositionY = -height;
|
|
4298
|
-
} else if (textBaseline
|
|
4484
|
+
} else if (textBaseline === 'top' || textBaseline === 'hanging') {
|
|
4299
4485
|
linePositionY = -lineHeight;
|
|
4300
4486
|
} // account for dx & dy
|
|
4301
4487
|
|
|
4302
4488
|
|
|
4303
|
-
var offsetX = 0;
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
}
|
|
4308
|
-
|
|
4309
|
-
if (dy && dy.unit === g.UnitType.kPixels) {
|
|
4310
|
-
linePositionY += dy.value;
|
|
4311
|
-
} // draw lines line by line
|
|
4312
|
-
|
|
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
|
|
4313
4493
|
|
|
4314
4494
|
for (var i = 0; i < lines.length; i++) {
|
|
4315
|
-
var linePositionX = lineWidth
|
|
4495
|
+
var linePositionX = lineWidth / 2 + offsetX;
|
|
4316
4496
|
linePositionY += lineHeight; // no need to re-position X, cause we already set text align
|
|
4317
4497
|
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
|
|
4318
4498
|
|
|
4319
|
-
if (!g.isNil(stroke) && !stroke.isNone && lineWidth
|
|
4320
|
-
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);
|
|
4321
4501
|
}
|
|
4322
4502
|
|
|
4323
4503
|
if (!g.isNil(fill)) {
|
|
4324
|
-
this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign
|
|
4504
|
+
this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity);
|
|
4325
4505
|
}
|
|
4326
4506
|
}
|
|
4327
4507
|
};
|
|
@@ -4413,193 +4593,6 @@
|
|
|
4413
4593
|
token: TextRendererContribution
|
|
4414
4594
|
})], TextRenderer);
|
|
4415
4595
|
|
|
4416
|
-
var DefaultRenderer = /*#__PURE__*/function () {
|
|
4417
|
-
function DefaultRenderer() {
|
|
4418
|
-
this.imagePool = void 0;
|
|
4419
|
-
}
|
|
4420
|
-
|
|
4421
|
-
var _proto = DefaultRenderer.prototype;
|
|
4422
|
-
|
|
4423
|
-
_proto.render = function render(context, parsedStyle, object, renderingService) {
|
|
4424
|
-
var fill = parsedStyle.fill,
|
|
4425
|
-
opacity = parsedStyle.opacity,
|
|
4426
|
-
fillOpacity = parsedStyle.fillOpacity,
|
|
4427
|
-
stroke = parsedStyle.stroke,
|
|
4428
|
-
strokeOpacity = parsedStyle.strokeOpacity,
|
|
4429
|
-
lineWidth = parsedStyle.lineWidth,
|
|
4430
|
-
lineCap = parsedStyle.lineCap,
|
|
4431
|
-
lineJoin = parsedStyle.lineJoin,
|
|
4432
|
-
shadowType = parsedStyle.shadowType,
|
|
4433
|
-
shadowColor = parsedStyle.shadowColor,
|
|
4434
|
-
shadowBlur = parsedStyle.shadowBlur,
|
|
4435
|
-
filter = parsedStyle.filter,
|
|
4436
|
-
miterLimit = parsedStyle.miterLimit;
|
|
4437
|
-
var hasFill = !g.isNil(fill) && !fill.isNone;
|
|
4438
|
-
var hasStroke = !g.isNil(stroke) && !stroke.isNone && lineWidth && lineWidth.value > 0;
|
|
4439
|
-
var isFillTransparent = fill.alpha === 0;
|
|
4440
|
-
var hasFilter = !g.isNil(filter);
|
|
4441
|
-
var hasShadow = !g.isNil(shadowColor) && (shadowBlur === null || shadowBlur === void 0 ? void 0 : shadowBlur.value) > 0;
|
|
4442
|
-
var nodeName = object.nodeName;
|
|
4443
|
-
var isInnerShadow = (shadowType === null || shadowType === void 0 ? void 0 : shadowType.value) === 'inner';
|
|
4444
|
-
var shouldDrawShadowWithStroke = hasStroke && hasShadow && (nodeName === g.Shape.PATH || nodeName === g.Shape.LINE || nodeName === g.Shape.POLYLINE || isFillTransparent || isInnerShadow);
|
|
4445
|
-
|
|
4446
|
-
if (hasFill) {
|
|
4447
|
-
context.globalAlpha = opacity.value * fillOpacity.value;
|
|
4448
|
-
|
|
4449
|
-
if (!shouldDrawShadowWithStroke) {
|
|
4450
|
-
this.setShadowAndFilter(object, context, hasShadow);
|
|
4451
|
-
}
|
|
4452
|
-
|
|
4453
|
-
this.fill(context, object, fill, renderingService);
|
|
4454
|
-
|
|
4455
|
-
if (!shouldDrawShadowWithStroke) {
|
|
4456
|
-
this.clearShadowAndFilter(context, hasFilter, hasShadow);
|
|
4457
|
-
}
|
|
4458
|
-
}
|
|
4459
|
-
|
|
4460
|
-
if (hasStroke) {
|
|
4461
|
-
context.globalAlpha = opacity.value * strokeOpacity.value;
|
|
4462
|
-
context.lineWidth = lineWidth.value;
|
|
4463
|
-
|
|
4464
|
-
if (!g.isNil(miterLimit)) {
|
|
4465
|
-
context.miterLimit = miterLimit.value;
|
|
4466
|
-
}
|
|
4467
|
-
|
|
4468
|
-
if (!g.isNil(lineCap)) {
|
|
4469
|
-
context.lineCap = lineCap.value;
|
|
4470
|
-
}
|
|
4471
|
-
|
|
4472
|
-
if (!g.isNil(lineJoin)) {
|
|
4473
|
-
context.lineJoin = lineJoin.value;
|
|
4474
|
-
}
|
|
4475
|
-
|
|
4476
|
-
if (shouldDrawShadowWithStroke) {
|
|
4477
|
-
if (isInnerShadow) {
|
|
4478
|
-
context.globalCompositeOperation = 'source-atop';
|
|
4479
|
-
}
|
|
4480
|
-
|
|
4481
|
-
this.setShadowAndFilter(object, context, true);
|
|
4482
|
-
|
|
4483
|
-
if (isInnerShadow) {
|
|
4484
|
-
this.stroke(context, object, stroke, renderingService);
|
|
4485
|
-
context.globalCompositeOperation = 'source-over';
|
|
4486
|
-
this.clearShadowAndFilter(context, hasFilter, true);
|
|
4487
|
-
}
|
|
4488
|
-
}
|
|
4489
|
-
|
|
4490
|
-
this.stroke(context, object, stroke, renderingService);
|
|
4491
|
-
}
|
|
4492
|
-
};
|
|
4493
|
-
|
|
4494
|
-
_proto.clearShadowAndFilter = function clearShadowAndFilter(context, hasFilter, hasShadow) {
|
|
4495
|
-
if (hasShadow) {
|
|
4496
|
-
context.shadowColor = 'transparent';
|
|
4497
|
-
context.shadowBlur = 0;
|
|
4498
|
-
}
|
|
4499
|
-
|
|
4500
|
-
if (hasFilter) {
|
|
4501
|
-
// save drop-shadow filter
|
|
4502
|
-
var oldFilter = context.filter;
|
|
4503
|
-
|
|
4504
|
-
if (!g.isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
|
|
4505
|
-
context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
|
|
4506
|
-
}
|
|
4507
|
-
}
|
|
4508
|
-
}
|
|
4509
|
-
/**
|
|
4510
|
-
* apply before fill and stroke but only once
|
|
4511
|
-
*/
|
|
4512
|
-
;
|
|
4513
|
-
|
|
4514
|
-
_proto.setShadowAndFilter = function setShadowAndFilter(object, context, hasShadow) {
|
|
4515
|
-
var _object$parsedStyle = object.parsedStyle,
|
|
4516
|
-
filter = _object$parsedStyle.filter,
|
|
4517
|
-
shadowColor = _object$parsedStyle.shadowColor,
|
|
4518
|
-
shadowBlur = _object$parsedStyle.shadowBlur,
|
|
4519
|
-
shadowOffsetX = _object$parsedStyle.shadowOffsetX,
|
|
4520
|
-
shadowOffsetY = _object$parsedStyle.shadowOffsetY;
|
|
4521
|
-
|
|
4522
|
-
if (!g.isNil(filter)) {
|
|
4523
|
-
// use raw filter string
|
|
4524
|
-
context.filter = object.style.filter;
|
|
4525
|
-
}
|
|
4526
|
-
|
|
4527
|
-
if (hasShadow) {
|
|
4528
|
-
context.shadowColor = shadowColor.toString();
|
|
4529
|
-
context.shadowBlur = shadowBlur && shadowBlur.value || 0;
|
|
4530
|
-
context.shadowOffsetX = shadowOffsetX && shadowOffsetX.value || 0;
|
|
4531
|
-
context.shadowOffsetY = shadowOffsetY && shadowOffsetY.value || 0;
|
|
4532
|
-
}
|
|
4533
|
-
};
|
|
4534
|
-
|
|
4535
|
-
_proto.fill = function fill(context, object, _fill, renderingService) {
|
|
4536
|
-
var _this = this;
|
|
4537
|
-
|
|
4538
|
-
if (Array.isArray(_fill)) {
|
|
4539
|
-
_fill.forEach(function (gradient) {
|
|
4540
|
-
context.fillStyle = _this.getColor(gradient, object, context);
|
|
4541
|
-
context.fill();
|
|
4542
|
-
});
|
|
4543
|
-
} else {
|
|
4544
|
-
if (g.isPattern(_fill)) {
|
|
4545
|
-
context.fillStyle = this.getPattern(_fill, object, context, renderingService);
|
|
4546
|
-
}
|
|
4547
|
-
|
|
4548
|
-
context.fill();
|
|
4549
|
-
}
|
|
4550
|
-
};
|
|
4551
|
-
|
|
4552
|
-
_proto.stroke = function stroke(context, object, _stroke, renderingService) {
|
|
4553
|
-
var _this2 = this;
|
|
4554
|
-
|
|
4555
|
-
if (Array.isArray(_stroke)) {
|
|
4556
|
-
_stroke.forEach(function (gradient) {
|
|
4557
|
-
context.strokeStyle = _this2.getColor(gradient, object, context);
|
|
4558
|
-
context.stroke();
|
|
4559
|
-
});
|
|
4560
|
-
} else {
|
|
4561
|
-
if (g.isPattern(_stroke)) {
|
|
4562
|
-
context.strokeStyle = this.getPattern(_stroke, object, context, renderingService);
|
|
4563
|
-
}
|
|
4564
|
-
|
|
4565
|
-
context.stroke();
|
|
4566
|
-
}
|
|
4567
|
-
};
|
|
4568
|
-
|
|
4569
|
-
_proto.getPattern = function getPattern(pattern, object, context, renderingService) {
|
|
4570
|
-
var canvasPattern = this.imagePool.getOrCreatePatternSync(pattern, context, function () {
|
|
4571
|
-
// set dirty rectangle flag
|
|
4572
|
-
object.renderable.dirty = true;
|
|
4573
|
-
renderingService.dirtify();
|
|
4574
|
-
});
|
|
4575
|
-
return canvasPattern;
|
|
4576
|
-
};
|
|
4577
|
-
|
|
4578
|
-
_proto.getColor = function getColor(parsedColor, object, context) {
|
|
4579
|
-
var color;
|
|
4580
|
-
|
|
4581
|
-
if (parsedColor.type === g.GradientType.LinearGradient || parsedColor.type === g.GradientType.RadialGradient) {
|
|
4582
|
-
var bounds = object.getGeometryBounds();
|
|
4583
|
-
var width = bounds && bounds.halfExtents[0] * 2 || 1;
|
|
4584
|
-
var height = bounds && bounds.halfExtents[1] * 2 || 1;
|
|
4585
|
-
color = this.imagePool.getOrCreateGradient(_extends({
|
|
4586
|
-
type: parsedColor.type
|
|
4587
|
-
}, parsedColor.value, {
|
|
4588
|
-
width: width,
|
|
4589
|
-
height: height
|
|
4590
|
-
}), context);
|
|
4591
|
-
}
|
|
4592
|
-
|
|
4593
|
-
return color;
|
|
4594
|
-
};
|
|
4595
|
-
|
|
4596
|
-
return DefaultRenderer;
|
|
4597
|
-
}();
|
|
4598
|
-
|
|
4599
|
-
__decorate([g.inject(ImagePool), __metadata("design:type", ImagePool)], DefaultRenderer.prototype, "imagePool", void 0);
|
|
4600
|
-
|
|
4601
|
-
DefaultRenderer = __decorate([g.singleton()], DefaultRenderer);
|
|
4602
|
-
|
|
4603
4596
|
var RectRenderer = /*#__PURE__*/function (_DefaultRenderer) {
|
|
4604
4597
|
_inheritsLoose$4(RectRenderer, _DefaultRenderer);
|
|
4605
4598
|
|
|
@@ -4697,7 +4690,7 @@
|
|
|
4697
4690
|
PathRenderer = __decorate([g.singleton({
|
|
4698
4691
|
token: PathRendererContribution
|
|
4699
4692
|
})], PathRenderer);
|
|
4700
|
-
var CanvasRendererPluginOptions = g.Syringe.defineToken('
|
|
4693
|
+
var CanvasRendererPluginOptions = g.Syringe.defineToken('');
|
|
4701
4694
|
|
|
4702
4695
|
var _class$2;
|
|
4703
4696
|
|
|
@@ -4728,7 +4721,10 @@
|
|
|
4728
4721
|
this.vpMatrix = create$3();
|
|
4729
4722
|
this.dprMatrix = create$3();
|
|
4730
4723
|
this.tmpMat4 = create$3();
|
|
4731
|
-
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();
|
|
4732
4728
|
}
|
|
4733
4729
|
|
|
4734
4730
|
var _proto = CanvasRendererPlugin.prototype;
|
|
@@ -4779,7 +4775,7 @@
|
|
|
4779
4775
|
|
|
4780
4776
|
_this.clearRect(context, 0, 0, width * dpr, height * dpr);
|
|
4781
4777
|
|
|
4782
|
-
fromScaling(_this.dprMatrix, fromValues
|
|
4778
|
+
fromScaling(_this.dprMatrix, fromValues(dpr, dpr, 1));
|
|
4783
4779
|
|
|
4784
4780
|
case 7:
|
|
4785
4781
|
case "end":
|
|
@@ -4827,14 +4823,13 @@
|
|
|
4827
4823
|
|
|
4828
4824
|
|
|
4829
4825
|
_this.saveDirtyAABB(object);
|
|
4830
|
-
}
|
|
4826
|
+
}
|
|
4831
4827
|
|
|
4828
|
+
var sorted = object.sortable.sorted || object.childNodes; // should account for z-index
|
|
4832
4829
|
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
});
|
|
4837
|
-
}
|
|
4830
|
+
sorted.forEach(function (child) {
|
|
4831
|
+
renderByZIndex(child);
|
|
4832
|
+
});
|
|
4838
4833
|
}; // render at the end of frame
|
|
4839
4834
|
|
|
4840
4835
|
|
|
@@ -4854,7 +4849,7 @@
|
|
|
4854
4849
|
maxX = _ref2.maxX,
|
|
4855
4850
|
maxY = _ref2.maxY;
|
|
4856
4851
|
var aabb = new g.AABB();
|
|
4857
|
-
aabb.setMinMax(fromValues
|
|
4852
|
+
aabb.setMinMax(fromValues(minX, minY, 0), fromValues(maxX, maxY, 0));
|
|
4858
4853
|
return aabb;
|
|
4859
4854
|
})));
|
|
4860
4855
|
|
|
@@ -4871,12 +4866,18 @@
|
|
|
4871
4866
|
y = dirtyRect.y,
|
|
4872
4867
|
width = dirtyRect.width,
|
|
4873
4868
|
height = dirtyRect.height;
|
|
4874
|
-
var tl = transformMat4$1(_this.
|
|
4875
|
-
var
|
|
4876
|
-
var
|
|
4877
|
-
var
|
|
4878
|
-
var
|
|
4879
|
-
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);
|
|
4880
4881
|
context.save();
|
|
4881
4882
|
|
|
4882
4883
|
_this.clearRect(context, ix, iy, iwidth, iheight);
|
|
@@ -4892,7 +4893,12 @@
|
|
|
4892
4893
|
|
|
4893
4894
|
if (enableDirtyRectangleRenderingDebug) {
|
|
4894
4895
|
canvas.dispatchEvent(new g.CustomEvent(g.CanvasEvent.DIRTY_RECTANGLE, {
|
|
4895
|
-
dirtyRect:
|
|
4896
|
+
dirtyRect: {
|
|
4897
|
+
x: ix,
|
|
4898
|
+
y: iy,
|
|
4899
|
+
width: iwidth,
|
|
4900
|
+
height: iheight
|
|
4901
|
+
}
|
|
4896
4902
|
}));
|
|
4897
4903
|
} // search objects intersect with dirty rectangle
|
|
4898
4904
|
|
|
@@ -5118,19 +5124,17 @@
|
|
|
5118
5124
|
lineDash = _object$parsedStyle.lineDash,
|
|
5119
5125
|
lineDashOffset = _object$parsedStyle.lineDashOffset; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
|
|
5120
5126
|
|
|
5121
|
-
if (lineDash
|
|
5122
|
-
context.setLineDash(lineDash
|
|
5123
|
-
return segment.value;
|
|
5124
|
-
}));
|
|
5127
|
+
if (lineDash) {
|
|
5128
|
+
context.setLineDash(lineDash);
|
|
5125
5129
|
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
|
|
5126
5130
|
|
|
5127
5131
|
|
|
5128
5132
|
if (!g.isNil(lineDashOffset)) {
|
|
5129
|
-
context.lineDashOffset = lineDashOffset
|
|
5133
|
+
context.lineDashOffset = lineDashOffset;
|
|
5130
5134
|
}
|
|
5131
5135
|
|
|
5132
5136
|
if (!g.isNil(opacity)) {
|
|
5133
|
-
context.globalAlpha *= opacity
|
|
5137
|
+
context.globalAlpha *= opacity;
|
|
5134
5138
|
}
|
|
5135
5139
|
|
|
5136
5140
|
if (!g.isNil(stroke) && !Array.isArray(stroke) && !stroke.isNone) {
|
|
@@ -5149,8 +5153,8 @@
|
|
|
5149
5153
|
var _ref4 = object.parsedStyle || {},
|
|
5150
5154
|
anchor = _ref4.anchor;
|
|
5151
5155
|
|
|
5152
|
-
var anchorX = anchor && anchor[0]
|
|
5153
|
-
var anchorY = anchor && anchor[1]
|
|
5156
|
+
var anchorX = anchor && anchor[0] || 0;
|
|
5157
|
+
var anchorY = anchor && anchor[1] || 0;
|
|
5154
5158
|
|
|
5155
5159
|
if (anchorX !== 0 || anchorY !== 0) {
|
|
5156
5160
|
var bounds = object.getGeometryBounds();
|
|
@@ -5163,19 +5167,19 @@
|
|
|
5163
5167
|
|
|
5164
5168
|
if (matrix) {
|
|
5165
5169
|
copy(this.tmpMat4, object.getLocalTransform());
|
|
5166
|
-
this.
|
|
5167
|
-
this.
|
|
5168
|
-
this.
|
|
5169
|
-
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);
|
|
5170
5174
|
multiply$1(this.tmpMat4, matrix, this.tmpMat4);
|
|
5171
5175
|
multiply$1(this.tmpMat4, this.vpMatrix, this.tmpMat4);
|
|
5172
5176
|
} else {
|
|
5173
5177
|
// apply RTS transformation in world space
|
|
5174
5178
|
copy(this.tmpMat4, object.getWorldTransform());
|
|
5175
|
-
this.
|
|
5176
|
-
this.
|
|
5177
|
-
this.
|
|
5178
|
-
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);
|
|
5179
5183
|
multiply$1(this.tmpMat4, this.vpMatrix, this.tmpMat4);
|
|
5180
5184
|
} // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
|
|
5181
5185
|
|
|
@@ -6505,22 +6509,22 @@
|
|
|
6505
6509
|
|
|
6506
6510
|
case 'zIndex':
|
|
6507
6511
|
var zIndex = object.parsedStyle.zIndex;
|
|
6508
|
-
$el.style['z-index'] = "" + zIndex
|
|
6512
|
+
$el.style['z-index'] = "" + zIndex;
|
|
6509
6513
|
break;
|
|
6510
6514
|
|
|
6511
6515
|
case 'visibility':
|
|
6512
6516
|
var visibility = object.parsedStyle.visibility;
|
|
6513
|
-
$el.style.visibility = visibility
|
|
6517
|
+
$el.style.visibility = visibility;
|
|
6514
6518
|
break;
|
|
6515
6519
|
|
|
6516
6520
|
case 'pointerEvents':
|
|
6517
6521
|
var pointerEvents = object.parsedStyle.pointerEvents;
|
|
6518
|
-
$el.style.pointerEvents = pointerEvents
|
|
6522
|
+
$el.style.pointerEvents = pointerEvents;
|
|
6519
6523
|
break;
|
|
6520
6524
|
|
|
6521
6525
|
case 'opacity':
|
|
6522
6526
|
var opacity = object.parsedStyle.opacity;
|
|
6523
|
-
$el.style.opacity = "" + opacity
|
|
6527
|
+
$el.style.opacity = "" + opacity;
|
|
6524
6528
|
break;
|
|
6525
6529
|
|
|
6526
6530
|
case 'fill':
|
|
@@ -6560,7 +6564,7 @@
|
|
|
6560
6564
|
|
|
6561
6565
|
case 'lineWidth':
|
|
6562
6566
|
var lineWidth = object.parsedStyle.lineWidth;
|
|
6563
|
-
$el.style['border-width'] = (lineWidth
|
|
6567
|
+
$el.style['border-width'] = (lineWidth || 0) + "px";
|
|
6564
6568
|
break;
|
|
6565
6569
|
|
|
6566
6570
|
case 'lineDash':
|
|
@@ -6568,7 +6572,7 @@
|
|
|
6568
6572
|
break;
|
|
6569
6573
|
|
|
6570
6574
|
case 'filter':
|
|
6571
|
-
var filter = object.
|
|
6575
|
+
var filter = object.style.filter;
|
|
6572
6576
|
$el.style.filter = filter;
|
|
6573
6577
|
break;
|
|
6574
6578
|
}
|