@antv/g-canvas 2.0.51 → 2.1.0

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.
Files changed (76) hide show
  1. package/README.md +3 -3
  2. package/dist/index.esm.js +2643 -20
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.js +2651 -38
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.umd.min.js +8 -31
  7. package/dist/index.umd.min.js.map +1 -1
  8. package/package.json +7 -11
  9. package/types/index.d.ts +7 -8
  10. package/types/index.d.ts.map +1 -1
  11. package/types/plugins/canvas-renderer/CanvasRendererPlugin.d.ts +55 -0
  12. package/types/plugins/canvas-renderer/CanvasRendererPlugin.d.ts.map +1 -0
  13. package/types/plugins/canvas-renderer/index.d.ts +17 -0
  14. package/types/plugins/canvas-renderer/index.d.ts.map +1 -0
  15. package/types/plugins/canvas-renderer/interfaces.d.ts +5 -0
  16. package/types/plugins/canvas-renderer/interfaces.d.ts.map +1 -0
  17. package/types/plugins/canvas-renderer/shapes/styles/Default.d.ts +14 -0
  18. package/types/plugins/canvas-renderer/shapes/styles/Default.d.ts.map +1 -0
  19. package/types/plugins/canvas-renderer/shapes/styles/Image.d.ts +19 -0
  20. package/types/plugins/canvas-renderer/shapes/styles/Image.d.ts.map +1 -0
  21. package/types/plugins/canvas-renderer/shapes/styles/OptimizedDefault.d.ts +37 -0
  22. package/types/plugins/canvas-renderer/shapes/styles/OptimizedDefault.d.ts.map +1 -0
  23. package/types/plugins/canvas-renderer/shapes/styles/Text.d.ts +19 -0
  24. package/types/plugins/canvas-renderer/shapes/styles/Text.d.ts.map +1 -0
  25. package/types/plugins/canvas-renderer/shapes/styles/helper.d.ts +5 -0
  26. package/types/plugins/canvas-renderer/shapes/styles/helper.d.ts.map +1 -0
  27. package/types/plugins/canvas-renderer/shapes/styles/index.d.ts +13 -0
  28. package/types/plugins/canvas-renderer/shapes/styles/index.d.ts.map +1 -0
  29. package/types/plugins/canvas-renderer/shapes/styles/interfaces.d.ts +8 -0
  30. package/types/plugins/canvas-renderer/shapes/styles/interfaces.d.ts.map +1 -0
  31. package/types/plugins/canvas-renderer/utils/math.d.ts +8 -0
  32. package/types/plugins/canvas-renderer/utils/math.d.ts.map +1 -0
  33. package/types/plugins/path-generator/index.d.ts +11 -0
  34. package/types/plugins/path-generator/index.d.ts.map +1 -0
  35. package/types/plugins/path-generator/interfaces.d.ts +6 -0
  36. package/types/plugins/path-generator/interfaces.d.ts.map +1 -0
  37. package/types/plugins/path-generator/paths/Circle.d.ts +3 -0
  38. package/types/plugins/path-generator/paths/Circle.d.ts.map +1 -0
  39. package/types/plugins/path-generator/paths/Ellipse.d.ts +3 -0
  40. package/types/plugins/path-generator/paths/Ellipse.d.ts.map +1 -0
  41. package/types/plugins/path-generator/paths/Line.d.ts +3 -0
  42. package/types/plugins/path-generator/paths/Line.d.ts.map +1 -0
  43. package/types/plugins/path-generator/paths/Path.d.ts +3 -0
  44. package/types/plugins/path-generator/paths/Path.d.ts.map +1 -0
  45. package/types/plugins/path-generator/paths/Polygon.d.ts +3 -0
  46. package/types/plugins/path-generator/paths/Polygon.d.ts.map +1 -0
  47. package/types/plugins/path-generator/paths/Polyline.d.ts +3 -0
  48. package/types/plugins/path-generator/paths/Polyline.d.ts.map +1 -0
  49. package/types/plugins/path-generator/paths/Rect.d.ts +3 -0
  50. package/types/plugins/path-generator/paths/Rect.d.ts.map +1 -0
  51. package/types/plugins/path-generator/paths/index.d.ts +8 -0
  52. package/types/plugins/path-generator/paths/index.d.ts.map +1 -0
  53. package/types/plugins/picker/CanvasPickerPlugin.d.ts +23 -0
  54. package/types/plugins/picker/CanvasPickerPlugin.d.ts.map +1 -0
  55. package/types/plugins/picker/Circle.d.ts +3 -0
  56. package/types/plugins/picker/Circle.d.ts.map +1 -0
  57. package/types/plugins/picker/Ellipse.d.ts +3 -0
  58. package/types/plugins/picker/Ellipse.d.ts.map +1 -0
  59. package/types/plugins/picker/Image.d.ts +3 -0
  60. package/types/plugins/picker/Image.d.ts.map +1 -0
  61. package/types/plugins/picker/Line.d.ts +3 -0
  62. package/types/plugins/picker/Line.d.ts.map +1 -0
  63. package/types/plugins/picker/Path.d.ts +3 -0
  64. package/types/plugins/picker/Path.d.ts.map +1 -0
  65. package/types/plugins/picker/Polygon.d.ts +3 -0
  66. package/types/plugins/picker/Polygon.d.ts.map +1 -0
  67. package/types/plugins/picker/Polyline.d.ts +3 -0
  68. package/types/plugins/picker/Polyline.d.ts.map +1 -0
  69. package/types/plugins/picker/Rect.d.ts +4 -0
  70. package/types/plugins/picker/Rect.d.ts.map +1 -0
  71. package/types/plugins/picker/Text.d.ts +3 -0
  72. package/types/plugins/picker/Text.d.ts.map +1 -0
  73. package/types/plugins/picker/index.d.ts +7 -0
  74. package/types/plugins/picker/index.d.ts.map +1 -0
  75. package/types/plugins/picker/utils/math.d.ts +8 -0
  76. package/types/plugins/picker/utils/math.d.ts.map +1 -0
package/dist/index.esm.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /*!
2
2
  * @antv/g-canvas
3
3
  * @description A renderer implemented by Canvas 2D API
4
- * @version 2.0.51
5
- * @date 12/10/2025, 8:45:57 AM
4
+ * @version 2.1.0
5
+ * @date 12/22/2025, 3:03:16 AM
6
6
  * @author AntVis
7
7
  * @docs https://g.antv.antgroup.com/
8
8
  */
@@ -10,22 +10,2645 @@ import _createClass from '@babel/runtime/helpers/createClass';
10
10
  import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
11
11
  import _callSuper from '@babel/runtime/helpers/callSuper';
12
12
  import _inherits from '@babel/runtime/helpers/inherits';
13
- import { setDOMSize, RenderReason, AbstractRendererPlugin, AbstractRenderer } from '@antv/g-lite';
14
- import * as CanvasPathGenerator from '@antv/g-plugin-canvas-path-generator';
15
- export { CanvasPathGenerator };
16
- import * as CanvasPicker from '@antv/g-plugin-canvas-picker';
17
- export { CanvasPicker };
18
- import * as CanvasRenderer from '@antv/g-plugin-canvas-renderer';
19
- export { CanvasRenderer };
20
- import * as DomInteraction from '@antv/g-plugin-dom-interaction';
21
- export { DomInteraction };
22
- import * as HTMLRenderer from '@antv/g-plugin-html-renderer';
23
- export { HTMLRenderer };
24
- import * as ImageLoader from '@antv/g-plugin-image-loader';
25
- export { ImageLoader };
13
+ import { ElementEvent, AABB, CustomEvent, CanvasEvent, Shape, Node, GradientType, isPattern, AbstractRendererPlugin, findClosestClipPathTarget, Point, isFillOrStrokeAffected, getOrCalculatePathTotalLength, isDisplayObject, setDOMSize, RenderReason, AbstractRenderer, ImageLoader, DomInteraction, HTMLRenderer } from '@antv/g-lite';
14
+ export { DomInteraction, HTMLRenderer, ImageLoader } from '@antv/g-lite';
15
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
16
+ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
17
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
18
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
19
+ import _classPrivateFieldLooseBase from '@babel/runtime/helpers/classPrivateFieldLooseBase';
20
+ import _classPrivateFieldLooseKey from '@babel/runtime/helpers/classPrivateFieldLooseKey';
21
+ import { mat4, vec3 } from 'gl-matrix';
22
+ import { isNil, arcToCubic, clamp, isString } from '@antv/util';
23
+ import _createForOfIteratorHelper from '@babel/runtime/helpers/createForOfIteratorHelper';
26
24
  import _regeneratorRuntime from '@babel/runtime/helpers/regeneratorRuntime';
27
25
  import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
28
- import { isString } from '@antv/util';
26
+ import { distance, linePointToLine, cubicPointDistance, quadPointDistance } from '@antv/g-math';
27
+
28
+ var _renderState = /*#__PURE__*/_classPrivateFieldLooseKey("renderState");
29
+ /**
30
+ * support 2 modes in rendering:
31
+ * * immediate
32
+ * * delayed: render at the end of frame with dirty-rectangle
33
+ */
34
+ var CanvasRendererPlugin = /*#__PURE__*/function () {
35
+ /**
36
+ * RBush used in dirty rectangle rendering
37
+ */
38
+
39
+ function CanvasRendererPlugin(canvasRendererPluginOptions // private styleRendererFactory: Record<Shape, StyleRenderer>,
40
+ ) {
41
+ _classCallCheck(this, CanvasRendererPlugin);
42
+ this.removedRBushNodeAABBs = [];
43
+ this.renderQueue = [];
44
+ Object.defineProperty(this, _renderState, {
45
+ writable: true,
46
+ value: {
47
+ restoreStack: [],
48
+ prevObject: null,
49
+ currentContext: new Map()
50
+ }
51
+ });
52
+ this.clearFullScreenLastFrame = false;
53
+ this.clearFullScreen = false;
54
+ /**
55
+ * view projection matrix
56
+ */
57
+ this.vpMatrix = mat4.create();
58
+ this.dprMatrix = mat4.create();
59
+ this.tmpMat4 = mat4.create();
60
+ this.vec3a = vec3.create();
61
+ this.vec3b = vec3.create();
62
+ this.vec3c = vec3.create();
63
+ this.vec3d = vec3.create();
64
+ this.canvasRendererPluginOptions = canvasRendererPluginOptions;
65
+ }
66
+ return _createClass(CanvasRendererPlugin, [{
67
+ key: "apply",
68
+ value: function apply(context, runtime) {
69
+ var _this = this;
70
+ this.context = context;
71
+ var _this$context = this.context,
72
+ config = _this$context.config,
73
+ camera = _this$context.camera,
74
+ renderingService = _this$context.renderingService,
75
+ renderingContext = _this$context.renderingContext,
76
+ rBushRoot = _this$context.rBushRoot,
77
+ pathGeneratorFactory = _this$context.pathGeneratorFactory;
78
+ var enableRenderingOptimization = config.renderer.getConfig().enableRenderingOptimization;
79
+ config.renderer.getConfig().enableDirtyCheck = false;
80
+ config.renderer.getConfig().enableDirtyRectangleRendering = false;
81
+ this.rBush = rBushRoot;
82
+ this.pathGeneratorFactory = pathGeneratorFactory;
83
+ var contextService = context.contextService;
84
+ var canvas = renderingContext.root.ownerDocument.defaultView;
85
+ var handleUnmounted = function handleUnmounted(e) {
86
+ var object = e.target;
87
+
88
+ // remove r-bush node
89
+ // @ts-ignore
90
+ var rBushNode = object.rBushNode;
91
+ if (rBushNode !== null && rBushNode !== void 0 && rBushNode.aabb) {
92
+ // save removed aabbs for dirty-rectangle rendering later
93
+ _this.removedRBushNodeAABBs.push(rBushNode.aabb);
94
+ }
95
+ };
96
+ var handleCulled = function handleCulled(e) {
97
+ var object = e.target;
98
+ // @ts-ignore
99
+ var rBushNode = object.rBushNode;
100
+ if (rBushNode.aabb) {
101
+ // save removed aabbs for dirty-rectangle rendering later
102
+ _this.removedRBushNodeAABBs.push(rBushNode.aabb);
103
+ }
104
+ };
105
+ renderingService.hooks.init.tap(CanvasRendererPlugin.tag, function () {
106
+ canvas.addEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
107
+ canvas.addEventListener(ElementEvent.CULLED, handleCulled);
108
+
109
+ // clear fullscreen
110
+ var dpr = contextService.getDPR();
111
+ var width = config.width,
112
+ height = config.height;
113
+ var context = contextService.getContext();
114
+ _this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
115
+ });
116
+ renderingService.hooks.destroy.tap(CanvasRendererPlugin.tag, function () {
117
+ canvas.removeEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
118
+ canvas.removeEventListener(ElementEvent.CULLED, handleCulled);
119
+ _this.renderQueue = [];
120
+ _this.removedRBushNodeAABBs = [];
121
+ _classPrivateFieldLooseBase(_this, _renderState)[_renderState] = {
122
+ restoreStack: [],
123
+ prevObject: null,
124
+ currentContext: null
125
+ };
126
+ });
127
+ var beforeDraw = function beforeDraw() {
128
+ var _canvas$context$rende;
129
+ var context = contextService.getContext();
130
+ var dpr = contextService.getDPR();
131
+ var width = config.width,
132
+ height = config.height;
133
+ var _this$canvasRendererP = _this.canvasRendererPluginOptions,
134
+ dirtyObjectNumThreshold = _this$canvasRendererP.dirtyObjectNumThreshold,
135
+ dirtyObjectRatioThreshold = _this$canvasRendererP.dirtyObjectRatioThreshold;
136
+
137
+ // some heuristic conditions such as 80% object changed
138
+ var _renderingService$get = renderingService.getStats(),
139
+ total = _renderingService$get.total,
140
+ rendered = _renderingService$get.rendered;
141
+ var ratio = rendered / total;
142
+ _this.clearFullScreen = _this.clearFullScreenLastFrame ||
143
+ // @ts-ignore
144
+ !((_canvas$context$rende = canvas.context.renderingPlugins[1]) !== null && _canvas$context$rende !== void 0 && _canvas$context$rende.isFirstTimeRenderingFinished) || renderingService.disableDirtyRectangleRendering() || rendered > dirtyObjectNumThreshold && ratio > dirtyObjectRatioThreshold;
145
+ if (!context) {
146
+ return;
147
+ }
148
+ if (typeof context.resetTransform === 'function') {
149
+ context.resetTransform();
150
+ } else {
151
+ context.setTransform(1, 0, 0, 1, 0, 0);
152
+ }
153
+ if (_this.clearFullScreen) {
154
+ _this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
155
+ }
156
+ };
157
+
158
+ /**
159
+ * render objects by z-index
160
+ *
161
+ * - The level of the child node will be affected by the level of the parent node
162
+ */
163
+ var renderByZIndex = function renderByZIndex(object, context) {
164
+ var stack = [object];
165
+ while (stack.length > 0) {
166
+ var _currentObject$sortab;
167
+ var currentObject = stack.pop();
168
+ if (currentObject.isVisible() && !currentObject.isCulled()) {
169
+ if (enableRenderingOptimization) {
170
+ _this.renderDisplayObjectOptimized(currentObject, context, _this.context, _classPrivateFieldLooseBase(_this, _renderState)[_renderState], runtime);
171
+ } else {
172
+ _this.renderDisplayObject(currentObject, context, _this.context, _classPrivateFieldLooseBase(_this, _renderState)[_renderState], runtime);
173
+ }
174
+ }
175
+ var objects = ((_currentObject$sortab = currentObject.sortable) === null || _currentObject$sortab === void 0 || (_currentObject$sortab = _currentObject$sortab.sorted) === null || _currentObject$sortab === void 0 ? void 0 : _currentObject$sortab.length) > 0 ? currentObject.sortable.sorted : currentObject.childNodes;
176
+ // should account for z-index
177
+ for (var i = objects.length - 1; i >= 0; i--) {
178
+ stack.push(objects[i]);
179
+ }
180
+ }
181
+ };
182
+
183
+ // render at the end of frame
184
+ renderingService.hooks.endFrame.tap(CanvasRendererPlugin.tag, function () {
185
+ beforeDraw();
186
+
187
+ // Skip rendering.
188
+ if (renderingContext.root.childNodes.length === 0) {
189
+ _this.clearFullScreenLastFrame = true;
190
+ return;
191
+ }
192
+ enableRenderingOptimization = config.renderer.getConfig().enableRenderingOptimization;
193
+
194
+ // init
195
+ _classPrivateFieldLooseBase(_this, _renderState)[_renderState] = {
196
+ restoreStack: [],
197
+ prevObject: null,
198
+ currentContext: _classPrivateFieldLooseBase(_this, _renderState)[_renderState].currentContext
199
+ };
200
+ _classPrivateFieldLooseBase(_this, _renderState)[_renderState].currentContext.clear();
201
+ _this.clearFullScreenLastFrame = false;
202
+ var context = contextService.getContext();
203
+ // clear & clip dirty rectangle
204
+ var dpr = contextService.getDPR();
205
+ mat4.fromScaling(_this.dprMatrix, [dpr, dpr, 1]);
206
+ mat4.multiply(_this.vpMatrix, _this.dprMatrix, camera.getOrthoMatrix());
207
+ if (_this.clearFullScreen) {
208
+ // console.time('renderByZIndex');
209
+ if (enableRenderingOptimization) {
210
+ context.save();
211
+ renderByZIndex(renderingContext.root, context);
212
+ context.restore();
213
+ } else {
214
+ renderByZIndex(renderingContext.root, context);
215
+ }
216
+ // console.timeEnd('renderByZIndex');
217
+
218
+ _this.removedRBushNodeAABBs = [];
219
+ } else {
220
+ // console.log('canvas renderer next...', this.renderQueue);
221
+ // merge removed AABB
222
+ var dirtyRenderBounds = _this.safeMergeAABB.apply(_this, [_this.mergeDirtyAABBs(_this.renderQueue)].concat(_toConsumableArray(_this.removedRBushNodeAABBs.map(function (_ref) {
223
+ var minX = _ref.minX,
224
+ minY = _ref.minY,
225
+ maxX = _ref.maxX,
226
+ maxY = _ref.maxY;
227
+ var aabb = new AABB();
228
+ aabb.setMinMax(
229
+ // vec3.fromValues(minX, minY, 0),
230
+ // vec3.fromValues(maxX, maxY, 0),
231
+ [minX, minY, 0], [maxX, maxY, 0]);
232
+ return aabb;
233
+ }))));
234
+ _this.removedRBushNodeAABBs = [];
235
+ if (AABB.isEmpty(dirtyRenderBounds)) {
236
+ _this.renderQueue = [];
237
+ return;
238
+ }
239
+ var dirtyRect = _this.convertAABB2Rect(dirtyRenderBounds);
240
+ var x = dirtyRect.x,
241
+ y = dirtyRect.y,
242
+ width = dirtyRect.width,
243
+ height = dirtyRect.height;
244
+ var tl = vec3.transformMat4(_this.vec3a, [x, y, 0], _this.vpMatrix);
245
+ var tr = vec3.transformMat4(_this.vec3b, [x + width, y, 0], _this.vpMatrix);
246
+ var bl = vec3.transformMat4(_this.vec3c, [x, y + height, 0], _this.vpMatrix);
247
+ var br = vec3.transformMat4(_this.vec3d, [x + width, y + height, 0], _this.vpMatrix);
248
+ var minx = Math.min(tl[0], tr[0], br[0], bl[0]);
249
+ var miny = Math.min(tl[1], tr[1], br[1], bl[1]);
250
+ var maxx = Math.max(tl[0], tr[0], br[0], bl[0]);
251
+ var maxy = Math.max(tl[1], tr[1], br[1], bl[1]);
252
+ var ix = Math.floor(minx);
253
+ var iy = Math.floor(miny);
254
+ var iwidth = Math.ceil(maxx - minx);
255
+ var iheight = Math.ceil(maxy - miny);
256
+ context.save();
257
+ _this.clearRect(context, ix, iy, iwidth, iheight, config.background);
258
+ context.beginPath();
259
+ context.rect(ix, iy, iwidth, iheight);
260
+ context.clip();
261
+
262
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
263
+ context.setTransform(_this.vpMatrix[0], _this.vpMatrix[1], _this.vpMatrix[4], _this.vpMatrix[5], _this.vpMatrix[12], _this.vpMatrix[13]);
264
+
265
+ // draw dirty rectangle
266
+ var _config$renderer$getC = config.renderer.getConfig(),
267
+ enableDirtyRectangleRenderingDebug = _config$renderer$getC.enableDirtyRectangleRenderingDebug;
268
+ if (enableDirtyRectangleRenderingDebug) {
269
+ canvas.dispatchEvent(new CustomEvent(CanvasEvent.DIRTY_RECTANGLE, {
270
+ dirtyRect: {
271
+ x: ix,
272
+ y: iy,
273
+ width: iwidth,
274
+ height: iheight
275
+ }
276
+ }));
277
+ }
278
+
279
+ // search objects intersect with dirty rectangle
280
+ var dirtyObjects = _this.searchDirtyObjects(dirtyRenderBounds);
281
+
282
+ // do rendering
283
+ dirtyObjects
284
+ // sort by z-index
285
+ .sort(function (a, b) {
286
+ return a.sortable.renderOrder - b.sortable.renderOrder;
287
+ }).forEach(function (object) {
288
+ // culled object should not be rendered
289
+ if (object && object.isVisible() && !object.isCulled()) {
290
+ _this.renderDisplayObject(object, context, _this.context, _classPrivateFieldLooseBase(_this, _renderState)[_renderState], runtime);
291
+ }
292
+ });
293
+ context.restore();
294
+
295
+ // save dirty AABBs in last frame
296
+ _this.renderQueue.forEach(function (object) {
297
+ _this.saveDirtyAABB(object);
298
+ });
299
+
300
+ // clear queue
301
+ _this.renderQueue = [];
302
+ }
303
+
304
+ // pop restore stack, eg. root -> parent -> child
305
+ _classPrivateFieldLooseBase(_this, _renderState)[_renderState].restoreStack.forEach(function () {
306
+ context.restore();
307
+ });
308
+ // clear restore stack
309
+ _classPrivateFieldLooseBase(_this, _renderState)[_renderState].restoreStack = [];
310
+ });
311
+ renderingService.hooks.render.tap(CanvasRendererPlugin.tag, function (object) {
312
+ if (!_this.clearFullScreen) {
313
+ // render at the end of frame
314
+ _this.renderQueue.push(object);
315
+ }
316
+ });
317
+ }
318
+ }, {
319
+ key: "clearRect",
320
+ value: function clearRect(context, x, y, width, height, background) {
321
+ // clearRect is faster than fillRect @see https://stackoverflow.com/a/30830253
322
+ context.clearRect(x, y, width, height);
323
+ if (background) {
324
+ context.fillStyle = background;
325
+ context.fillRect(x, y, width, height);
326
+ }
327
+ }
328
+ }, {
329
+ key: "renderDisplayObjectOptimized",
330
+ value: function renderDisplayObjectOptimized(object, context, canvasContext, renderState, runtime) {
331
+ var nodeName = object.nodeName;
332
+ var updateTransform = false;
333
+ var clipDraw = false;
334
+
335
+ // @ts-ignore
336
+ var styleRenderer = this.context.styleRendererFactory[nodeName];
337
+ var generatePath = this.pathGeneratorFactory[nodeName];
338
+
339
+ // clip path
340
+ var clipPath = object.parsedStyle.clipPath;
341
+ if (clipPath) {
342
+ updateTransform = !renderState.prevObject || !mat4.exactEquals(clipPath.getWorldTransform(), renderState.prevObject.getWorldTransform());
343
+ if (updateTransform) {
344
+ this.applyWorldTransform(context, clipPath);
345
+ renderState.prevObject = null;
346
+ }
347
+
348
+ // generate path in local space
349
+ var _generatePath = this.pathGeneratorFactory[clipPath.nodeName];
350
+ if (_generatePath) {
351
+ context.save();
352
+ clipDraw = true;
353
+ context.beginPath();
354
+ _generatePath(context, clipPath.parsedStyle);
355
+ context.closePath();
356
+ context.clip();
357
+ }
358
+ }
359
+
360
+ // fill & stroke
361
+
362
+ if (styleRenderer) {
363
+ updateTransform = !renderState.prevObject || !mat4.exactEquals(object.getWorldTransform(), renderState.prevObject.getWorldTransform());
364
+ if (updateTransform) {
365
+ this.applyWorldTransform(context, object);
366
+ }
367
+ var forceUpdateStyle = !renderState.prevObject;
368
+ if (!forceUpdateStyle) {
369
+ var prevNodeName = renderState.prevObject.nodeName;
370
+ if (nodeName === Shape.TEXT) {
371
+ forceUpdateStyle = prevNodeName !== Shape.TEXT;
372
+ } else if (nodeName === Shape.IMAGE) {
373
+ forceUpdateStyle = prevNodeName !== Shape.IMAGE;
374
+ } else {
375
+ forceUpdateStyle = prevNodeName === Shape.TEXT || prevNodeName === Shape.IMAGE;
376
+ }
377
+ }
378
+ styleRenderer.applyStyleToContext(context, object, forceUpdateStyle, renderState);
379
+ renderState.prevObject = object;
380
+ }
381
+ if (generatePath) {
382
+ context.beginPath();
383
+ generatePath(context, object.parsedStyle);
384
+ if (nodeName !== Shape.LINE && nodeName !== Shape.PATH && nodeName !== Shape.POLYLINE) {
385
+ context.closePath();
386
+ }
387
+ }
388
+
389
+ // fill & stroke
390
+ if (styleRenderer) {
391
+ styleRenderer.drawToContext(context, object, _classPrivateFieldLooseBase(this, _renderState)[_renderState], this, runtime);
392
+ }
393
+ if (clipDraw) {
394
+ context.restore();
395
+ }
396
+
397
+ // finish rendering, clear dirty flag
398
+ object.dirty(false);
399
+ }
400
+ }, {
401
+ key: "renderDisplayObject",
402
+ value: function renderDisplayObject(object, context, canvasContext, renderState, runtime) {
403
+ var nodeName = object.nodeName;
404
+
405
+ // restore to its ancestor
406
+
407
+ var parent = renderState.restoreStack[renderState.restoreStack.length - 1];
408
+ if (parent && !(object.compareDocumentPosition(parent) & Node.DOCUMENT_POSITION_CONTAINS)) {
409
+ context.restore();
410
+ renderState.restoreStack.pop();
411
+ }
412
+
413
+ // @ts-ignore
414
+ var styleRenderer = this.context.styleRendererFactory[nodeName];
415
+ var generatePath = this.pathGeneratorFactory[nodeName];
416
+
417
+ // clip path
418
+ var clipPath = object.parsedStyle.clipPath;
419
+ if (clipPath) {
420
+ this.applyWorldTransform(context, clipPath);
421
+
422
+ // generate path in local space
423
+ var _generatePath2 = this.pathGeneratorFactory[clipPath.nodeName];
424
+ if (_generatePath2) {
425
+ context.save();
426
+
427
+ // save clip
428
+ renderState.restoreStack.push(object);
429
+ context.beginPath();
430
+ _generatePath2(context, clipPath.parsedStyle);
431
+ context.closePath();
432
+ context.clip();
433
+ }
434
+ }
435
+
436
+ // fill & stroke
437
+
438
+ if (styleRenderer) {
439
+ this.applyWorldTransform(context, object);
440
+ context.save();
441
+
442
+ // apply attributes to context
443
+ this.applyAttributesToContext(context, object);
444
+ }
445
+ if (generatePath) {
446
+ context.beginPath();
447
+ generatePath(context, object.parsedStyle);
448
+ if (nodeName !== Shape.LINE && nodeName !== Shape.PATH && nodeName !== Shape.POLYLINE) {
449
+ context.closePath();
450
+ }
451
+ }
452
+
453
+ // fill & stroke
454
+ if (styleRenderer) {
455
+ styleRenderer.render(context, object.parsedStyle, object, canvasContext, this, runtime);
456
+
457
+ // restore applied attributes, eg. shadowBlur shadowColor...
458
+ context.restore();
459
+ }
460
+
461
+ // finish rendering, clear dirty flag
462
+ object.dirty(false);
463
+ }
464
+ }, {
465
+ key: "applyAttributesToContext",
466
+ value: function applyAttributesToContext(context, object) {
467
+ var _ref2 = object.parsedStyle,
468
+ stroke = _ref2.stroke,
469
+ fill = _ref2.fill,
470
+ opacity = _ref2.opacity,
471
+ lineDash = _ref2.lineDash,
472
+ lineDashOffset = _ref2.lineDashOffset;
473
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
474
+ if (lineDash) {
475
+ context.setLineDash(lineDash);
476
+ }
477
+
478
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
479
+ if (!isNil(lineDashOffset)) {
480
+ context.lineDashOffset = lineDashOffset;
481
+ }
482
+ if (!isNil(opacity)) {
483
+ context.globalAlpha *= opacity;
484
+ }
485
+ if (!isNil(stroke) && !Array.isArray(stroke) && !stroke.isNone) {
486
+ context.strokeStyle = object.attributes.stroke;
487
+ }
488
+ if (!isNil(fill) && !Array.isArray(fill) && !fill.isNone) {
489
+ context.fillStyle = object.attributes.fill;
490
+ }
491
+ }
492
+ }, {
493
+ key: "convertAABB2Rect",
494
+ value: function convertAABB2Rect(aabb) {
495
+ var min = aabb.getMin();
496
+ var max = aabb.getMax();
497
+ // expand the rectangle a bit to avoid artifacts
498
+ // @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu
499
+ var minX = Math.floor(min[0]);
500
+ var minY = Math.floor(min[1]);
501
+ var maxX = Math.ceil(max[0]);
502
+ var maxY = Math.ceil(max[1]);
503
+ var width = maxX - minX;
504
+ var height = maxY - minY;
505
+ return {
506
+ x: minX,
507
+ y: minY,
508
+ width: width,
509
+ height: height
510
+ };
511
+ }
512
+
513
+ /**
514
+ * TODO: merge dirty rectangles with some strategies.
515
+ * For now, we just simply merge all the rectangles into one.
516
+ * @see https://idom.me/articles/841.html
517
+ */
518
+ }, {
519
+ key: "mergeDirtyAABBs",
520
+ value: function mergeDirtyAABBs(dirtyObjects) {
521
+ // merge into a big AABB
522
+ // TODO: skip descendant if ancestor is caculated, but compareNodePosition is really slow
523
+ var aabb = new AABB();
524
+ dirtyObjects.forEach(function (object) {
525
+ var renderBounds = object.getRenderBounds();
526
+ aabb.add(renderBounds);
527
+ var dirtyRenderBounds = object.renderable.dirtyRenderBounds;
528
+ if (dirtyRenderBounds) {
529
+ aabb.add(dirtyRenderBounds);
530
+ }
531
+ });
532
+ return aabb;
533
+ }
534
+ }, {
535
+ key: "searchDirtyObjects",
536
+ value: function searchDirtyObjects(dirtyRectangle) {
537
+ // search in r-tree, get all affected nodes
538
+ var _dirtyRectangle$getMi = dirtyRectangle.getMin(),
539
+ _dirtyRectangle$getMi2 = _slicedToArray(_dirtyRectangle$getMi, 2),
540
+ minX = _dirtyRectangle$getMi2[0],
541
+ minY = _dirtyRectangle$getMi2[1];
542
+ var _dirtyRectangle$getMa = dirtyRectangle.getMax(),
543
+ _dirtyRectangle$getMa2 = _slicedToArray(_dirtyRectangle$getMa, 2),
544
+ maxX = _dirtyRectangle$getMa2[0],
545
+ maxY = _dirtyRectangle$getMa2[1];
546
+ var rBushNodes = this.rBush.search({
547
+ minX: minX,
548
+ minY: minY,
549
+ maxX: maxX,
550
+ maxY: maxY
551
+ });
552
+ return rBushNodes.map(function (_ref3) {
553
+ var displayObject = _ref3.displayObject;
554
+ return displayObject;
555
+ });
556
+ }
557
+ }, {
558
+ key: "saveDirtyAABB",
559
+ value: function saveDirtyAABB(object) {
560
+ var renderable = object.renderable;
561
+ if (!renderable.dirtyRenderBounds) {
562
+ renderable.dirtyRenderBounds = new AABB();
563
+ }
564
+ var renderBounds = object.getRenderBounds();
565
+ if (renderBounds) {
566
+ // save last dirty aabb
567
+ renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
568
+ }
569
+ }
570
+ }, {
571
+ key: "applyWorldTransform",
572
+ value: function applyWorldTransform(context, object, matrix) {
573
+ // apply clip shape's RTS
574
+ if (matrix) {
575
+ mat4.copy(this.tmpMat4, object.getLocalTransform());
576
+ mat4.multiply(this.tmpMat4, matrix, this.tmpMat4);
577
+ mat4.multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
578
+ } else {
579
+ // apply RTS transformation in world space
580
+ mat4.copy(this.tmpMat4, object.getWorldTransform());
581
+ mat4.multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
582
+ }
583
+
584
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
585
+ context.setTransform(this.tmpMat4[0], this.tmpMat4[1], this.tmpMat4[4], this.tmpMat4[5], this.tmpMat4[12], this.tmpMat4[13]);
586
+ }
587
+ }, {
588
+ key: "safeMergeAABB",
589
+ value: function safeMergeAABB() {
590
+ var merged = new AABB();
591
+ for (var _len = arguments.length, aabbs = new Array(_len), _key = 0; _key < _len; _key++) {
592
+ aabbs[_key] = arguments[_key];
593
+ }
594
+ aabbs.forEach(function (aabb) {
595
+ merged.add(aabb);
596
+ });
597
+ return merged;
598
+ }
599
+ }]);
600
+ }();
601
+ CanvasRendererPlugin.tag = 'CanvasRenderer';
602
+
603
+ function getPattern(pattern, object, context, canvasContext, plugin, runtime, imagePool) {
604
+ var $offscreenCanvas;
605
+ var dpr;
606
+ if (pattern.image.nodeName === 'rect') {
607
+ var _parsedStyle = pattern.image.parsedStyle,
608
+ width = _parsedStyle.width,
609
+ height = _parsedStyle.height;
610
+ dpr = canvasContext.contextService.getDPR();
611
+ var offscreenCanvas = canvasContext.config.offscreenCanvas;
612
+ $offscreenCanvas = runtime.offscreenCanvasCreator.getOrCreateCanvas(offscreenCanvas);
613
+ $offscreenCanvas.width = width * dpr;
614
+ $offscreenCanvas.height = height * dpr;
615
+ var offscreenCanvasContext = runtime.offscreenCanvasCreator.getOrCreateContext(offscreenCanvas);
616
+ var renderState = {
617
+ restoreStack: [],
618
+ prevObject: null,
619
+ currentContext: new Map()
620
+ };
621
+
622
+ // offscreenCanvasContext.scale(1 / dpr, 1 / dpr);
623
+
624
+ pattern.image.forEach(function (object) {
625
+ plugin.renderDisplayObject(object, offscreenCanvasContext, canvasContext, renderState, runtime);
626
+ });
627
+ renderState.restoreStack.forEach(function () {
628
+ offscreenCanvasContext.restore();
629
+ });
630
+ }
631
+ var canvasPattern = imagePool.getOrCreatePatternSync(object, pattern, context, $offscreenCanvas, dpr, object.getGeometryBounds().min, function () {
632
+ // set dirty rectangle flag
633
+ object.dirty();
634
+ canvasContext.renderingService.dirty();
635
+ });
636
+ return canvasPattern;
637
+ }
638
+ function getColor(parsedColor, object, context, imagePool) {
639
+ var color;
640
+ if (parsedColor.type === GradientType.LinearGradient || parsedColor.type === GradientType.RadialGradient) {
641
+ var bounds = object.getGeometryBounds();
642
+ var width = bounds && bounds.halfExtents[0] * 2 || 1;
643
+ var height = bounds && bounds.halfExtents[1] * 2 || 1;
644
+ var min = bounds && bounds.min || [0, 0];
645
+ color = imagePool.getOrCreateGradient(_objectSpread(_objectSpread({
646
+ type: parsedColor.type
647
+ }, parsedColor.value), {}, {
648
+ min: min,
649
+ width: width,
650
+ height: height
651
+ }), context);
652
+ }
653
+ return color;
654
+ }
655
+
656
+ var SHADOW_NUMBER_STYLE = ['shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
657
+ var STROKE_STYLE = ['lineCap', 'lineJoin', 'miterLimit'];
658
+ var DEFAULT_STYLE = {
659
+ // common
660
+ globalAlpha: 1,
661
+ shadowBlur: 0,
662
+ shadowOffsetX: 0,
663
+ shadowOffsetY: 0,
664
+ shadowColor: '#000',
665
+ filter: 'none',
666
+ globalCompositeOperation: 'source-over',
667
+ // stroke/fill
668
+ strokeStyle: '#000',
669
+ strokeOpacity: 1,
670
+ lineWidth: 1,
671
+ lineDash: [],
672
+ lineDashOffset: 0,
673
+ lineCap: 'butt',
674
+ lineJoin: 'miter',
675
+ miterLimit: 10,
676
+ fillStyle: '#000',
677
+ fillOpacity: 1
678
+
679
+ // image
680
+ };
681
+ var defaultParsedStyle = {};
682
+
683
+ /**
684
+ * Updating the canvas context is an expensive operation. The state of the context is cached and the actual update operation is performed only when the cache is not hit.
685
+ *
686
+ * In any case, the previous value is returned, which is convenient for temporarily updating the context and restoring it later.
687
+ */
688
+ function updateContextIfNotHitCache(context, key, value, cache) {
689
+ var prevValue = cache.has(key) ? cache.get(key) : DEFAULT_STYLE[key];
690
+ if (prevValue !== value) {
691
+ // console.log('not hit cache', key, value, prevValue, cache);
692
+ if (key === 'lineDash') {
693
+ context.setLineDash(value);
694
+ } else {
695
+ // @ts-ignore
696
+ context[key] = value;
697
+ }
698
+ cache.set(key, value);
699
+ }
700
+ return prevValue;
701
+ }
702
+ var OptimizedDefaultRenderer = /*#__PURE__*/function () {
703
+ function OptimizedDefaultRenderer(imagePool) {
704
+ _classCallCheck(this, OptimizedDefaultRenderer);
705
+ this.imagePool = imagePool;
706
+ }
707
+ return _createClass(OptimizedDefaultRenderer, [{
708
+ key: "applyAttributesToContext",
709
+ value: function applyAttributesToContext(context, object) {}
710
+ }, {
711
+ key: "render",
712
+ value: function render(context, parsedStyle, object, canvasContext, plugin, runtime) {}
713
+
714
+ // #region common style
715
+ }, {
716
+ key: "applyCommonStyleToContext",
717
+ value: function applyCommonStyleToContext(context, object, forceUpdate, renderState) {
718
+ // const dpr = object.ownerDocument.defaultView.getContextService().getDPR();
719
+ var prevStyle = forceUpdate ? defaultParsedStyle : renderState.prevObject.parsedStyle;
720
+ var style = object.parsedStyle;
721
+ if (forceUpdate || style.opacity !== prevStyle.opacity) {
722
+ updateContextIfNotHitCache(context, 'globalAlpha', !isNil(style.opacity) ? style.opacity : DEFAULT_STYLE.globalAlpha, renderState.currentContext);
723
+ }
724
+
725
+ // TODO blend prop
726
+ // @ts-ignore
727
+ if (forceUpdate || style.blend !== prevStyle.blend) {
728
+ updateContextIfNotHitCache(context, 'globalCompositeOperation',
729
+ // @ts-ignore
730
+ !isNil(style.blend) ?
731
+ // @ts-ignore
732
+ style.blend : DEFAULT_STYLE.globalCompositeOperation, renderState.currentContext);
733
+ }
734
+ }
735
+ // #endregion common style
736
+
737
+ // #region stroke/fill style
738
+ }, {
739
+ key: "applyStrokeFillStyleToContext",
740
+ value: function applyStrokeFillStyleToContext(context, object, forceUpdate, renderState) {
741
+ var prevStyle = forceUpdate ? defaultParsedStyle : renderState.prevObject.parsedStyle;
742
+ var style = object.parsedStyle;
743
+ var _style$lineWidth = style.lineWidth,
744
+ lineWidth = _style$lineWidth === void 0 ? DEFAULT_STYLE.lineWidth : _style$lineWidth;
745
+ var hasFill = style.fill && !style.fill.isNone;
746
+ var hasStroke = style.stroke && !style.stroke.isNone && lineWidth > 0;
747
+ if (hasStroke) {
748
+ if (forceUpdate || object.attributes.stroke !== renderState.prevObject.attributes.stroke) {
749
+ var value = !isNil(style.stroke) && !Array.isArray(style.stroke) && !style.stroke.isNone ? object.attributes.stroke : DEFAULT_STYLE.strokeStyle;
750
+ updateContextIfNotHitCache(context, 'strokeStyle', value, renderState.currentContext);
751
+ }
752
+ if (forceUpdate || style.lineWidth !== prevStyle.lineWidth) {
753
+ updateContextIfNotHitCache(context, 'lineWidth', !isNil(style.lineWidth) ? style.lineWidth : DEFAULT_STYLE.lineWidth, renderState.currentContext);
754
+ }
755
+ if (forceUpdate || style.lineDash !== prevStyle.lineDash) {
756
+ updateContextIfNotHitCache(context, 'lineDash', style.lineDash || DEFAULT_STYLE.lineDash, renderState.currentContext);
757
+ }
758
+ if (forceUpdate || style.lineDashOffset !== prevStyle.lineDashOffset) {
759
+ updateContextIfNotHitCache(context, 'lineDashOffset', !isNil(style.lineDashOffset) ? style.lineDashOffset : DEFAULT_STYLE.lineDashOffset, renderState.currentContext);
760
+ }
761
+ for (var i = 0; i < STROKE_STYLE.length; i++) {
762
+ var styleName = STROKE_STYLE[i];
763
+ if (forceUpdate || style[styleName] !== prevStyle[styleName]) {
764
+ updateContextIfNotHitCache(context, styleName, !isNil(style[styleName]) ? style[styleName] : DEFAULT_STYLE[styleName], renderState.currentContext);
765
+ }
766
+ }
767
+ }
768
+ if (hasFill && (forceUpdate || object.attributes.fill !== renderState.prevObject.attributes.fill)) {
769
+ var _value = !isNil(style.fill) && !Array.isArray(style.fill) && !style.fill.isNone ? object.attributes.fill : DEFAULT_STYLE.fillStyle;
770
+ updateContextIfNotHitCache(context, 'fillStyle', _value, renderState.currentContext);
771
+ }
772
+ }
773
+ // #endregion stroke/fill style
774
+ }, {
775
+ key: "applyStyleToContext",
776
+ value: function applyStyleToContext(context, object, forceUpdate, renderState) {
777
+ var nodeName = object.nodeName;
778
+ this.applyCommonStyleToContext(context, object, forceUpdate, renderState);
779
+ if (nodeName === Shape.IMAGE) ; else {
780
+ this.applyStrokeFillStyleToContext(context, object, forceUpdate, renderState);
781
+ }
782
+ }
783
+ }, {
784
+ key: "applyShadowAndFilterStyleToContext",
785
+ value: function applyShadowAndFilterStyleToContext(context, object, hasShadow, renderState) {
786
+ var style = object.parsedStyle;
787
+ if (hasShadow) {
788
+ updateContextIfNotHitCache(context, 'shadowColor', style.shadowColor.toString(), renderState.currentContext);
789
+ for (var i = 0; i < SHADOW_NUMBER_STYLE.length; i++) {
790
+ var styleName = SHADOW_NUMBER_STYLE[i];
791
+ updateContextIfNotHitCache(context, styleName, style[styleName] || DEFAULT_STYLE[styleName], renderState.currentContext);
792
+ }
793
+ }
794
+ if (style.filter && style.filter.length) {
795
+ updateContextIfNotHitCache(context, 'filter',
796
+ // use raw filter string
797
+ object.attributes.filter, renderState.currentContext);
798
+ }
799
+ }
800
+ }, {
801
+ key: "clearShadowAndFilterStyleForContext",
802
+ value: function clearShadowAndFilterStyleForContext(context, hasShadow, hasFilter, renderState) {
803
+ var onlyClearShadowFilter = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
804
+ if (hasShadow) {
805
+ updateContextIfNotHitCache(context, 'shadowColor', DEFAULT_STYLE.shadowColor, renderState.currentContext);
806
+ for (var i = 0; i < SHADOW_NUMBER_STYLE.length; i++) {
807
+ var styleName = SHADOW_NUMBER_STYLE[i];
808
+ updateContextIfNotHitCache(context, styleName, DEFAULT_STYLE[styleName], renderState.currentContext);
809
+ }
810
+ }
811
+ if (hasFilter) {
812
+ if (hasShadow && onlyClearShadowFilter) {
813
+ // save drop-shadow filter
814
+ var oldFilter = context.filter;
815
+ if (!isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
816
+ updateContextIfNotHitCache(context, 'filter', oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || DEFAULT_STYLE.filter, renderState.currentContext);
817
+ }
818
+ } else {
819
+ updateContextIfNotHitCache(context, 'filter', DEFAULT_STYLE.filter, renderState.currentContext);
820
+ }
821
+ }
822
+ }
823
+ }, {
824
+ key: "fillToContext",
825
+ value: function fillToContext(context, object, renderState, plugin, runtime) {
826
+ var _this = this;
827
+ var _object$parsedStyle = object.parsedStyle,
828
+ fill = _object$parsedStyle.fill,
829
+ fillRule = _object$parsedStyle.fillRule;
830
+ var resetStyle = null;
831
+ if (Array.isArray(fill) && fill.length > 0) {
832
+ fill.forEach(function (gradient) {
833
+ var prevStyle = updateContextIfNotHitCache(context, 'fillStyle', getColor(gradient, object, context, _this.imagePool), renderState.currentContext);
834
+ resetStyle = resetStyle !== null && resetStyle !== void 0 ? resetStyle : prevStyle;
835
+ if (fillRule) {
836
+ context.fill(fillRule);
837
+ } else {
838
+ context.fill();
839
+ }
840
+ });
841
+ } else {
842
+ if (isPattern(fill)) {
843
+ var pattern = getPattern(fill, object, context, object.ownerDocument.defaultView.context, plugin, runtime, this.imagePool);
844
+ if (pattern) {
845
+ context.fillStyle = pattern;
846
+ resetStyle = true;
847
+ }
848
+ }
849
+ if (fillRule) {
850
+ context.fill(fillRule);
851
+ } else {
852
+ context.fill();
853
+ }
854
+ }
855
+ if (resetStyle !== null) {
856
+ updateContextIfNotHitCache(context, 'fillStyle', resetStyle, renderState.currentContext);
857
+ }
858
+ }
859
+ }, {
860
+ key: "strokeToContext",
861
+ value: function strokeToContext(context, object, renderState, plugin, runtime) {
862
+ var _this2 = this;
863
+ var stroke = object.parsedStyle.stroke;
864
+ var resetStyle = null;
865
+ if (Array.isArray(stroke) && stroke.length > 0) {
866
+ stroke.forEach(function (gradient) {
867
+ var prevStyle = updateContextIfNotHitCache(context, 'strokeStyle', getColor(gradient, object, context, _this2.imagePool), renderState.currentContext);
868
+ resetStyle = resetStyle !== null && resetStyle !== void 0 ? resetStyle : prevStyle;
869
+ context.stroke();
870
+ });
871
+ } else {
872
+ if (isPattern(stroke)) {
873
+ var pattern = getPattern(stroke, object, context, object.ownerDocument.defaultView.context, plugin, runtime, this.imagePool);
874
+ if (pattern) {
875
+ var prevStyle = updateContextIfNotHitCache(context, 'strokeStyle', pattern, renderState.currentContext);
876
+ resetStyle = resetStyle !== null && resetStyle !== void 0 ? resetStyle : prevStyle;
877
+ }
878
+ }
879
+ context.stroke();
880
+ }
881
+ if (resetStyle !== null) {
882
+ updateContextIfNotHitCache(context, 'strokeStyle', resetStyle, renderState.currentContext);
883
+ }
884
+ }
885
+ }, {
886
+ key: "drawToContext",
887
+ value: function drawToContext(context, object, renderState, plugin, runtime) {
888
+ var _style$fill;
889
+ var nodeName = object.nodeName;
890
+ var style = object.parsedStyle;
891
+ var _style$opacity = style.opacity,
892
+ opacity = _style$opacity === void 0 ? DEFAULT_STYLE.globalAlpha : _style$opacity,
893
+ _style$fillOpacity = style.fillOpacity,
894
+ fillOpacity = _style$fillOpacity === void 0 ? DEFAULT_STYLE.fillOpacity : _style$fillOpacity,
895
+ _style$strokeOpacity = style.strokeOpacity,
896
+ strokeOpacity = _style$strokeOpacity === void 0 ? DEFAULT_STYLE.strokeOpacity : _style$strokeOpacity,
897
+ _style$lineWidth2 = style.lineWidth,
898
+ lineWidth = _style$lineWidth2 === void 0 ? DEFAULT_STYLE.lineWidth : _style$lineWidth2;
899
+ var hasFill = style.fill && !style.fill.isNone;
900
+ var hasStroke = style.stroke && !style.stroke.isNone && lineWidth > 0;
901
+ if (!hasFill && !hasStroke) {
902
+ return;
903
+ }
904
+ var hasShadow = !isNil(style.shadowColor) && style.shadowBlur > 0;
905
+ var isInnerShadow = style.shadowType === 'inner';
906
+ var isFillTransparent = ((_style$fill = style.fill) === null || _style$fill === void 0 ? void 0 : _style$fill.alpha) === 0;
907
+ var hasFilter = !!(style.filter && style.filter.length);
908
+ // Shadows can only be applied to fill() or stroke(), the default is fill()
909
+ var shouldDrawShadowWithStroke = hasShadow && hasStroke && (nodeName === Shape.PATH || nodeName === Shape.LINE || nodeName === Shape.POLYLINE || isFillTransparent || isInnerShadow);
910
+
911
+ // TODO https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/paint-order
912
+
913
+ var originGlobalAlpha = null;
914
+ if (hasFill) {
915
+ if (!shouldDrawShadowWithStroke) {
916
+ this.applyShadowAndFilterStyleToContext(context, object, hasShadow, renderState);
917
+ }
918
+ var updateOpacity = opacity * fillOpacity;
919
+ originGlobalAlpha = updateContextIfNotHitCache(context, 'globalAlpha', updateOpacity, renderState.currentContext);
920
+ this.fillToContext(context, object, renderState, plugin, runtime);
921
+ if (!shouldDrawShadowWithStroke) {
922
+ this.clearShadowAndFilterStyleForContext(context, hasShadow, hasFilter, renderState);
923
+ }
924
+ }
925
+ if (hasStroke) {
926
+ var clearShadowAndFilter = false;
927
+ var _updateOpacity = opacity * strokeOpacity;
928
+ var prevOpacity = updateContextIfNotHitCache(context, 'globalAlpha', _updateOpacity, renderState.currentContext);
929
+ originGlobalAlpha = hasFill ? originGlobalAlpha : prevOpacity;
930
+ if (shouldDrawShadowWithStroke) {
931
+ this.applyShadowAndFilterStyleToContext(context, object, hasShadow, renderState);
932
+ clearShadowAndFilter = true;
933
+ if (isInnerShadow) {
934
+ var originBlend = context.globalCompositeOperation;
935
+ context.globalCompositeOperation = 'source-atop';
936
+ this.strokeToContext(context, object, renderState, plugin, runtime);
937
+ context.globalCompositeOperation = originBlend;
938
+ this.clearShadowAndFilterStyleForContext(context, hasShadow, hasFilter, renderState, true);
939
+ }
940
+ }
941
+ this.strokeToContext(context, object, renderState, plugin, runtime);
942
+ if (clearShadowAndFilter) {
943
+ this.clearShadowAndFilterStyleForContext(context, hasShadow, hasFilter, renderState);
944
+ }
945
+ }
946
+
947
+ // clear
948
+ if (originGlobalAlpha !== null) {
949
+ updateContextIfNotHitCache(context, 'globalAlpha', originGlobalAlpha, renderState.currentContext);
950
+ }
951
+ }
952
+ }]);
953
+ }();
954
+
955
+ var DefaultRenderer = /*#__PURE__*/function (_OptimizedDefaultRend) {
956
+ function DefaultRenderer() {
957
+ _classCallCheck(this, DefaultRenderer);
958
+ return _callSuper(this, DefaultRenderer, arguments);
959
+ }
960
+ _inherits(DefaultRenderer, _OptimizedDefaultRend);
961
+ return _createClass(DefaultRenderer, [{
962
+ key: "render",
963
+ value: function render(context, parsedStyle, object, canvasContext, plugin, runtime) {
964
+ var fill = parsedStyle.fill,
965
+ fillRule = parsedStyle.fillRule,
966
+ _parsedStyle$opacity = parsedStyle.opacity,
967
+ opacity = _parsedStyle$opacity === void 0 ? 1 : _parsedStyle$opacity,
968
+ _parsedStyle$fillOpac = parsedStyle.fillOpacity,
969
+ fillOpacity = _parsedStyle$fillOpac === void 0 ? 1 : _parsedStyle$fillOpac,
970
+ stroke = parsedStyle.stroke,
971
+ _parsedStyle$strokeOp = parsedStyle.strokeOpacity,
972
+ strokeOpacity = _parsedStyle$strokeOp === void 0 ? 1 : _parsedStyle$strokeOp,
973
+ _parsedStyle$lineWidt = parsedStyle.lineWidth,
974
+ lineWidth = _parsedStyle$lineWidt === void 0 ? 1 : _parsedStyle$lineWidt,
975
+ lineCap = parsedStyle.lineCap,
976
+ lineJoin = parsedStyle.lineJoin,
977
+ shadowType = parsedStyle.shadowType,
978
+ shadowColor = parsedStyle.shadowColor,
979
+ shadowBlur = parsedStyle.shadowBlur,
980
+ filter = parsedStyle.filter,
981
+ miterLimit = parsedStyle.miterLimit;
982
+ var hasFill = fill && !fill.isNone;
983
+ var hasStroke = stroke && !stroke.isNone && lineWidth > 0;
984
+ var isFillTransparent = (fill === null || fill === void 0 ? void 0 : fill.alpha) === 0;
985
+ var hasFilter = !!(filter && filter.length);
986
+ var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
987
+ var nodeName = object.nodeName;
988
+ var isInnerShadow = shadowType === 'inner';
989
+ var shouldDrawShadowWithStroke = hasStroke && hasShadow && (nodeName === Shape.PATH || nodeName === Shape.LINE || nodeName === Shape.POLYLINE || isFillTransparent || isInnerShadow);
990
+ if (hasFill) {
991
+ context.globalAlpha = opacity * fillOpacity;
992
+ if (!shouldDrawShadowWithStroke) {
993
+ setShadowAndFilter(object, context, hasShadow);
994
+ }
995
+ applyFill(context, object, fill, fillRule, canvasContext, plugin, runtime, this.imagePool);
996
+ if (!shouldDrawShadowWithStroke) {
997
+ this.clearShadowAndFilter(context, hasFilter, hasShadow);
998
+ }
999
+ }
1000
+ if (hasStroke) {
1001
+ context.globalAlpha = opacity * strokeOpacity;
1002
+ context.lineWidth = lineWidth;
1003
+ if (!isNil(miterLimit)) {
1004
+ context.miterLimit = miterLimit;
1005
+ }
1006
+ if (!isNil(lineCap)) {
1007
+ context.lineCap = lineCap;
1008
+ }
1009
+ if (!isNil(lineJoin)) {
1010
+ context.lineJoin = lineJoin;
1011
+ }
1012
+ if (shouldDrawShadowWithStroke) {
1013
+ if (isInnerShadow) {
1014
+ context.globalCompositeOperation = 'source-atop';
1015
+ }
1016
+ setShadowAndFilter(object, context, true);
1017
+ if (isInnerShadow) {
1018
+ applyStroke(context, object, stroke, canvasContext, plugin, runtime, this.imagePool);
1019
+ context.globalCompositeOperation = DEFAULT_STYLE.globalCompositeOperation;
1020
+ this.clearShadowAndFilter(context, hasFilter, true);
1021
+ }
1022
+ }
1023
+ applyStroke(context, object, stroke, canvasContext, plugin, runtime, this.imagePool);
1024
+ }
1025
+ }
1026
+ }, {
1027
+ key: "clearShadowAndFilter",
1028
+ value: function clearShadowAndFilter(context, hasFilter, hasShadow) {
1029
+ if (hasShadow) {
1030
+ context.shadowColor = 'transparent';
1031
+ context.shadowBlur = 0;
1032
+ }
1033
+ if (hasFilter) {
1034
+ // save drop-shadow filter
1035
+ var oldFilter = context.filter;
1036
+ if (!isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
1037
+ context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
1038
+ }
1039
+ }
1040
+ }
1041
+ }]);
1042
+ }(OptimizedDefaultRenderer);
1043
+
1044
+ /**
1045
+ * apply before fill and stroke but only once
1046
+ */
1047
+ function setShadowAndFilter(object, context, hasShadow) {
1048
+ var _object$parsedStyle = object.parsedStyle,
1049
+ filter = _object$parsedStyle.filter,
1050
+ shadowColor = _object$parsedStyle.shadowColor,
1051
+ shadowBlur = _object$parsedStyle.shadowBlur,
1052
+ shadowOffsetX = _object$parsedStyle.shadowOffsetX,
1053
+ shadowOffsetY = _object$parsedStyle.shadowOffsetY;
1054
+ if (filter && filter.length) {
1055
+ // use raw filter string
1056
+ context.filter = object.style.filter;
1057
+ }
1058
+ if (hasShadow) {
1059
+ context.shadowColor = shadowColor.toString();
1060
+ context.shadowBlur = shadowBlur || 0;
1061
+ context.shadowOffsetX = shadowOffsetX || 0;
1062
+ context.shadowOffsetY = shadowOffsetY || 0;
1063
+ }
1064
+ }
1065
+ function applyFill(context, object, fill, fillRule, canvasContext, plugin, runtime, imagePool) {
1066
+ var skipFill = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : false;
1067
+ if (Array.isArray(fill)) {
1068
+ fill.forEach(function (gradient) {
1069
+ context.fillStyle = getColor(gradient, object, context, imagePool);
1070
+ if (!skipFill) {
1071
+ fillRule ? context.fill(fillRule) : context.fill();
1072
+ }
1073
+ });
1074
+ } else {
1075
+ if (isPattern(fill)) {
1076
+ context.fillStyle = getPattern(fill, object, context, canvasContext, plugin, runtime, imagePool);
1077
+ }
1078
+ if (!skipFill) {
1079
+ fillRule ? context.fill(fillRule) : context.fill();
1080
+ }
1081
+ }
1082
+ }
1083
+ function applyStroke(context, object, stroke, canvasContext, plugin, runtime, imagePool) {
1084
+ var skipStroke = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
1085
+ if (Array.isArray(stroke)) {
1086
+ stroke.forEach(function (gradient) {
1087
+ context.strokeStyle = getColor(gradient, object, context, imagePool);
1088
+ if (!skipStroke) {
1089
+ context.stroke();
1090
+ }
1091
+ });
1092
+ } else {
1093
+ if (isPattern(stroke)) {
1094
+ context.strokeStyle = getPattern(stroke, object, context, canvasContext, plugin, runtime, imagePool);
1095
+ }
1096
+ if (!skipStroke) {
1097
+ context.stroke();
1098
+ }
1099
+ }
1100
+ }
1101
+
1102
+ function calculateOverlapRect(rect1, rect2) {
1103
+ var _rect = _slicedToArray(rect1, 4),
1104
+ x1 = _rect[0],
1105
+ y1 = _rect[1],
1106
+ w1 = _rect[2],
1107
+ h1 = _rect[3];
1108
+ var _rect2 = _slicedToArray(rect2, 4),
1109
+ x2 = _rect2[0],
1110
+ y2 = _rect2[1],
1111
+ w2 = _rect2[2],
1112
+ h2 = _rect2[3];
1113
+
1114
+ // 计算重叠区域的左上角和右下角
1115
+ var overlapLeft = Math.max(x1, x2);
1116
+ var overlapTop = Math.max(y1, y2);
1117
+ var overlapRight = Math.min(x1 + w1, x2 + w2);
1118
+ var overlapBottom = Math.min(y1 + h1, y2 + h2);
1119
+ if (overlapRight <= overlapLeft || overlapBottom <= overlapTop) {
1120
+ return null;
1121
+ }
1122
+ return [overlapLeft, overlapTop, overlapRight - overlapLeft, overlapBottom - overlapTop];
1123
+ }
1124
+ function transformRect(rect, matrix) {
1125
+ var tl = vec3.transformMat4(vec3.create(), [rect[0], rect[1], 0], matrix);
1126
+ var tr = vec3.transformMat4(vec3.create(), [rect[0] + rect[2], rect[1], 0], matrix);
1127
+ var bl = vec3.transformMat4(vec3.create(), [rect[0], rect[1] + rect[3], 0], matrix);
1128
+ var br = vec3.transformMat4(vec3.create(), [rect[0] + rect[2], rect[1] + rect[3], 0], matrix);
1129
+ return [Math.min(tl[0], tr[0], bl[0], br[0]), Math.min(tl[1], tr[1], bl[1], br[1]), Math.max(tl[0], tr[0], bl[0], br[0]) - Math.min(tl[0], tr[0], bl[0], br[0]), Math.max(tl[1], tr[1], bl[1], br[1]) - Math.min(tl[1], tr[1], bl[1], br[1])];
1130
+ }
1131
+
1132
+ var ImageRenderer = /*#__PURE__*/function (_DefaultRenderer) {
1133
+ function ImageRenderer() {
1134
+ _classCallCheck(this, ImageRenderer);
1135
+ return _callSuper(this, ImageRenderer, arguments);
1136
+ }
1137
+ _inherits(ImageRenderer, _DefaultRenderer);
1138
+ return _createClass(ImageRenderer, [{
1139
+ key: "renderDownSampled",
1140
+ value: function renderDownSampled(context, parsedStyle, object, data) {
1141
+ var src = data.src,
1142
+ imageCache = data.imageCache;
1143
+ if (!imageCache.downSampled) {
1144
+ this.imagePool.createDownSampledImage(src, object).then(function () {
1145
+ // be removed from dom tree
1146
+ if (!object.ownerDocument) {
1147
+ return;
1148
+ }
1149
+
1150
+ // rerender
1151
+ object.dirty();
1152
+ object.ownerDocument.defaultView.context.renderingService.dirty();
1153
+ })["catch"](function (reason) {
1154
+ console.error(reason);
1155
+ });
1156
+ return;
1157
+ }
1158
+ context.drawImage(imageCache.downSampled, Math.floor(data.drawRect[0]), Math.floor(data.drawRect[1]), Math.ceil(data.drawRect[2]), Math.ceil(data.drawRect[3]));
1159
+ }
1160
+ }, {
1161
+ key: "renderTile",
1162
+ value: function renderTile(context, parsedStyle, object, data) {
1163
+ var src = data.src,
1164
+ imageCache = data.imageCache,
1165
+ imageRect = data.imageRect,
1166
+ drawRect = data.drawRect;
1167
+ var originalSize = imageCache.size;
1168
+ var _context$getTransform = context.getTransform(),
1169
+ a = _context$getTransform.a,
1170
+ b = _context$getTransform.b,
1171
+ c = _context$getTransform.c,
1172
+ d = _context$getTransform.d,
1173
+ e = _context$getTransform.e,
1174
+ f = _context$getTransform.f;
1175
+ context.resetTransform();
1176
+ if (!(imageCache !== null && imageCache !== void 0 && imageCache.gridSize)) {
1177
+ this.imagePool.createImageTiles(src, [], function () {
1178
+ // be removed from dom tree
1179
+ if (!object.ownerDocument) {
1180
+ return;
1181
+ }
1182
+
1183
+ // rerender
1184
+ object.dirty();
1185
+ object.ownerDocument.defaultView.context.renderingService.dirty();
1186
+ }, object)["catch"](function (reason) {
1187
+ console.error(reason);
1188
+ });
1189
+ return;
1190
+ }
1191
+ var scaleToOrigin = [originalSize[0] / imageRect[2], originalSize[1] / imageRect[3]];
1192
+ var scaledTileSize = [imageCache.tileSize[0] / scaleToOrigin[0], imageCache.tileSize[1] / scaleToOrigin[1]];
1193
+ var _ref = [Math.floor((drawRect[0] - imageRect[0]) / scaledTileSize[0]), Math.ceil((drawRect[0] + drawRect[2] - imageRect[0]) / scaledTileSize[0])],
1194
+ startTileX = _ref[0],
1195
+ endTileX = _ref[1];
1196
+ var _ref2 = [Math.floor((drawRect[1] - imageRect[1]) / scaledTileSize[1]), Math.ceil((drawRect[1] + drawRect[3] - imageRect[1]) / scaledTileSize[1])],
1197
+ startTileY = _ref2[0],
1198
+ endTileY = _ref2[1];
1199
+ for (var tileY = startTileY; tileY <= endTileY; tileY++) {
1200
+ for (var tileX = startTileX; tileX <= endTileX; tileX++) {
1201
+ var item = imageCache.tiles[tileY][tileX];
1202
+ if (item) {
1203
+ var tileRect = [Math.floor(imageRect[0] + item.tileX * scaledTileSize[0]), Math.floor(imageRect[1] + item.tileY * scaledTileSize[1]), Math.ceil(scaledTileSize[0]), Math.ceil(scaledTileSize[1])];
1204
+ context.drawImage(item.data, tileRect[0], tileRect[1], tileRect[2], tileRect[3]);
1205
+ }
1206
+ }
1207
+ }
1208
+ context.setTransform(a, b, c, d, e, f);
1209
+ }
1210
+ }, {
1211
+ key: "render",
1212
+ value: function render(context, parsedStyle, object) {
1213
+ var _parsedStyle$x = parsedStyle.x,
1214
+ x = _parsedStyle$x === void 0 ? 0 : _parsedStyle$x,
1215
+ _parsedStyle$y = parsedStyle.y,
1216
+ y = _parsedStyle$y === void 0 ? 0 : _parsedStyle$y,
1217
+ width = parsedStyle.width,
1218
+ height = parsedStyle.height,
1219
+ src = parsedStyle.src,
1220
+ shadowColor = parsedStyle.shadowColor,
1221
+ shadowBlur = parsedStyle.shadowBlur;
1222
+ var imageCache = this.imagePool.getImageSync(src, object);
1223
+ var image = imageCache === null || imageCache === void 0 ? void 0 : imageCache.img;
1224
+ var iw = width;
1225
+ var ih = height;
1226
+ if (!image) {
1227
+ return;
1228
+ }
1229
+ iw || (iw = image.width);
1230
+ ih || (ih = image.height);
1231
+ var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
1232
+ setShadowAndFilter(object, context, hasShadow);
1233
+
1234
+ // node-canvas will throw the following err:
1235
+ // Error: Image given has not completed loading
1236
+ try {
1237
+ var _object$ownerDocument = object.ownerDocument.defaultView.getContextService().getDomElement(),
1238
+ viewWidth = _object$ownerDocument.width,
1239
+ viewHeight = _object$ownerDocument.height;
1240
+ var currentTransform = context.getTransform();
1241
+ var a = currentTransform.a,
1242
+ b = currentTransform.b,
1243
+ c = currentTransform.c,
1244
+ d = currentTransform.d,
1245
+ e = currentTransform.e,
1246
+ f = currentTransform.f;
1247
+ // 构建 mat4 矩阵
1248
+ // prettier-ignore
1249
+ var transformMatrix = mat4.fromValues(a, c, 0, 0, b, d, 0, 0, 0, 0, 1, 0, e, f, 0, 1);
1250
+ var imageRect = transformRect([x, y, iw, ih], transformMatrix);
1251
+ var drawRect = calculateOverlapRect([0, 0, viewWidth, viewHeight], imageRect);
1252
+ if (!drawRect) {
1253
+ return;
1254
+ }
1255
+ if (!object.ownerDocument.defaultView.getConfig().enableLargeImageOptimization) {
1256
+ ImageRenderer.renderFull(context, parsedStyle, object, {
1257
+ image: image,
1258
+ drawRect: [x, y, iw, ih]
1259
+ });
1260
+ return;
1261
+ }
1262
+ var sizeOfOrigin = imageRect[2] / imageCache.size[0];
1263
+ if (sizeOfOrigin < (imageCache.downSamplingRate || 0.5)) {
1264
+ this.renderDownSampled(context, parsedStyle, object, {
1265
+ src: src,
1266
+ imageCache: imageCache,
1267
+ drawRect: [x, y, iw, ih]
1268
+ });
1269
+ return;
1270
+ }
1271
+ if (!ImagePool.isSupportTile) {
1272
+ ImageRenderer.renderFull(context, parsedStyle, object, {
1273
+ image: image,
1274
+ drawRect: [x, y, iw, ih]
1275
+ });
1276
+ return;
1277
+ }
1278
+ this.renderTile(context, parsedStyle, object, {
1279
+ src: src,
1280
+ imageCache: imageCache,
1281
+ imageRect: imageRect,
1282
+ drawRect: drawRect
1283
+ });
1284
+ } catch (_unused) {
1285
+ // expected error
1286
+ }
1287
+ }
1288
+
1289
+ // ---
1290
+ }, {
1291
+ key: "drawToContext",
1292
+ value: function drawToContext(context, object, renderState, plugin, runtime) {
1293
+ this.render(context, object.parsedStyle, object);
1294
+ }
1295
+ }], [{
1296
+ key: "renderFull",
1297
+ value: function renderFull(context, parsedStyle, object, data) {
1298
+ context.drawImage(data.image, Math.floor(data.drawRect[0]), Math.floor(data.drawRect[1]), Math.ceil(data.drawRect[2]), Math.ceil(data.drawRect[3]));
1299
+ }
1300
+ }]);
1301
+ }(DefaultRenderer);
1302
+
1303
+ var TextRenderer = /*#__PURE__*/function (_DefaultRenderer) {
1304
+ function TextRenderer() {
1305
+ _classCallCheck(this, TextRenderer);
1306
+ return _callSuper(this, TextRenderer, arguments);
1307
+ }
1308
+ _inherits(TextRenderer, _DefaultRenderer);
1309
+ return _createClass(TextRenderer, [{
1310
+ key: "render",
1311
+ value: function render(context, parsedStyle, object, canvasContext, plugin, runtime) {
1312
+ // Trigger text geometry calculation.
1313
+ object.getBounds();
1314
+ var _parsedStyle$lineWidt = parsedStyle.lineWidth,
1315
+ lineWidth = _parsedStyle$lineWidt === void 0 ? 1 : _parsedStyle$lineWidt,
1316
+ _parsedStyle$textAlig = parsedStyle.textAlign,
1317
+ textAlign = _parsedStyle$textAlig === void 0 ? 'start' : _parsedStyle$textAlig,
1318
+ _parsedStyle$textBase = parsedStyle.textBaseline,
1319
+ textBaseline = _parsedStyle$textBase === void 0 ? 'alphabetic' : _parsedStyle$textBase,
1320
+ _parsedStyle$lineJoin = parsedStyle.lineJoin,
1321
+ lineJoin = _parsedStyle$lineJoin === void 0 ? 'miter' : _parsedStyle$lineJoin,
1322
+ _parsedStyle$miterLim = parsedStyle.miterLimit,
1323
+ miterLimit = _parsedStyle$miterLim === void 0 ? 10 : _parsedStyle$miterLim,
1324
+ _parsedStyle$letterSp = parsedStyle.letterSpacing,
1325
+ letterSpacing = _parsedStyle$letterSp === void 0 ? 0 : _parsedStyle$letterSp,
1326
+ stroke = parsedStyle.stroke,
1327
+ fill = parsedStyle.fill,
1328
+ fillRule = parsedStyle.fillRule,
1329
+ _parsedStyle$fillOpac = parsedStyle.fillOpacity,
1330
+ fillOpacity = _parsedStyle$fillOpac === void 0 ? 1 : _parsedStyle$fillOpac,
1331
+ _parsedStyle$strokeOp = parsedStyle.strokeOpacity,
1332
+ strokeOpacity = _parsedStyle$strokeOp === void 0 ? 1 : _parsedStyle$strokeOp,
1333
+ _parsedStyle$opacity = parsedStyle.opacity,
1334
+ opacity = _parsedStyle$opacity === void 0 ? 1 : _parsedStyle$opacity,
1335
+ metrics = parsedStyle.metrics,
1336
+ _parsedStyle$x = parsedStyle.x,
1337
+ x = _parsedStyle$x === void 0 ? 0 : _parsedStyle$x,
1338
+ _parsedStyle$y = parsedStyle.y,
1339
+ y = _parsedStyle$y === void 0 ? 0 : _parsedStyle$y,
1340
+ dx = parsedStyle.dx,
1341
+ dy = parsedStyle.dy,
1342
+ shadowColor = parsedStyle.shadowColor,
1343
+ shadowBlur = parsedStyle.shadowBlur,
1344
+ textDecorationLine = parsedStyle.textDecorationLine;
1345
+ var font = metrics.font,
1346
+ lines = metrics.lines,
1347
+ height = metrics.height,
1348
+ lineHeight = metrics.lineHeight,
1349
+ lineMetrics = metrics.lineMetrics;
1350
+ context.font = font;
1351
+ context.lineWidth = lineWidth;
1352
+ context.textAlign = textAlign === 'middle' ? 'center' : textAlign;
1353
+ var formattedTextBaseline = textBaseline;
1354
+ if (formattedTextBaseline === 'alphabetic') {
1355
+ formattedTextBaseline = 'bottom';
1356
+ }
1357
+ context.lineJoin = lineJoin;
1358
+ if (!isNil(miterLimit)) {
1359
+ context.miterLimit = miterLimit;
1360
+ }
1361
+ var linePositionY = y;
1362
+ // handle vertical text baseline
1363
+ if (textBaseline === 'middle') {
1364
+ linePositionY += -height / 2 - lineHeight / 2;
1365
+ } else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
1366
+ linePositionY += -height;
1367
+ } else if (textBaseline === 'top' || textBaseline === 'hanging') {
1368
+ linePositionY += -lineHeight;
1369
+ }
1370
+
1371
+ // account for dx & dy
1372
+ var offsetX = x + (dx || 0);
1373
+ linePositionY += dy || 0;
1374
+ if (lines.length === 1) {
1375
+ if (formattedTextBaseline === 'bottom') {
1376
+ formattedTextBaseline = 'middle';
1377
+ linePositionY -= 0.5 * height;
1378
+ } else if (formattedTextBaseline === 'top') {
1379
+ formattedTextBaseline = 'middle';
1380
+ linePositionY += 0.5 * height;
1381
+ }
1382
+ }
1383
+ context.textBaseline = formattedTextBaseline;
1384
+ var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
1385
+ setShadowAndFilter(object, context, hasShadow);
1386
+
1387
+ // draw lines line by line
1388
+ for (var i = 0; i < lines.length; i++) {
1389
+ var linePositionX = lineWidth / 2 + offsetX;
1390
+ linePositionY += lineHeight;
1391
+
1392
+ // no need to re-position X, cause we already set text align
1393
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
1394
+ if (!isNil(stroke) && !stroke.isNone && lineWidth) {
1395
+ this.drawLetterSpacing(context, object, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fill, fillRule, fillOpacity, stroke, strokeOpacity, opacity, true, canvasContext, plugin, runtime);
1396
+ }
1397
+ if (!isNil(fill)) {
1398
+ this.drawLetterSpacing(context, object, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fill, fillRule, fillOpacity, stroke, strokeOpacity, opacity, false, canvasContext, plugin, runtime);
1399
+ }
1400
+ }
1401
+
1402
+ // Draw text decoration lines
1403
+ if (textDecorationLine && textDecorationLine !== 'none') {
1404
+ this.drawTextDecorations(context, parsedStyle, object, lines, lineHeight, offsetX, y + (dy || 0), canvasContext, plugin, runtime);
1405
+ }
1406
+ }
1407
+ }, {
1408
+ key: "drawLetterSpacing",
1409
+ value: function drawLetterSpacing(context, object, text, lineMetrics, textAlign, x, y, letterSpacing, fill, fillRule, fillOpacity, stroke, strokeOpacity, opacity, isStroke, canvasContext, plugin, runtime) {
1410
+ // letterSpacing of 0 means normal, render all texts directly
1411
+ if (letterSpacing === 0) {
1412
+ if (isStroke) {
1413
+ this.strokeText(context, object, text, x, y, stroke, strokeOpacity, canvasContext, plugin, runtime);
1414
+ } else {
1415
+ this.fillText(context, object, text, x, y, fill, fillRule, fillOpacity, opacity, canvasContext, plugin, runtime);
1416
+ }
1417
+ return;
1418
+ }
1419
+
1420
+ // draw text using left align
1421
+ var currentTextAlign = context.textAlign;
1422
+ context.textAlign = 'left';
1423
+ var currentPosition = x;
1424
+ if (textAlign === 'center' || textAlign === 'middle') {
1425
+ currentPosition = x - lineMetrics.width / 2;
1426
+ } else if (textAlign === 'right' || textAlign === 'end') {
1427
+ currentPosition = x - lineMetrics.width;
1428
+ }
1429
+ var stringArray = Array.from(text);
1430
+ var previousWidth = context.measureText(text).width;
1431
+ var currentWidth = 0;
1432
+ for (var i = 0; i < stringArray.length; ++i) {
1433
+ var currentChar = stringArray[i];
1434
+ if (isStroke) {
1435
+ this.strokeText(context, object, currentChar, currentPosition, y, stroke, strokeOpacity, canvasContext, plugin, runtime);
1436
+ } else {
1437
+ this.fillText(context, object, currentChar, currentPosition, y, fill, fillRule, fillOpacity, opacity, canvasContext, plugin, runtime);
1438
+ }
1439
+ currentWidth = context.measureText(text.substring(i + 1)).width;
1440
+ currentPosition += previousWidth - currentWidth + letterSpacing;
1441
+ previousWidth = currentWidth;
1442
+ }
1443
+ context.textAlign = currentTextAlign;
1444
+ }
1445
+ }, {
1446
+ key: "fillText",
1447
+ value: function fillText(context, object, text, x, y, fill, fillRule, fillOpacity, opacity, canvasContext, plugin, runtime) {
1448
+ applyFill(context, object, fill, fillRule, canvasContext, plugin, runtime, this.imagePool, true);
1449
+ var currentGlobalAlpha;
1450
+ var applyOpacity = !isNil(fillOpacity) && fillOpacity !== 1;
1451
+ if (applyOpacity) {
1452
+ currentGlobalAlpha = context.globalAlpha;
1453
+ context.globalAlpha = fillOpacity * opacity;
1454
+ }
1455
+ context.fillText(text, x, y);
1456
+ if (applyOpacity) {
1457
+ context.globalAlpha = currentGlobalAlpha;
1458
+ }
1459
+ }
1460
+ }, {
1461
+ key: "strokeText",
1462
+ value: function strokeText(context, object, text, x, y, stroke, strokeOpacity, canvasContext, plugin, runtime) {
1463
+ applyStroke(context, object, stroke, canvasContext, plugin, runtime, this.imagePool, true);
1464
+ var currentGlobalAlpha;
1465
+ var applyOpacity = !isNil(strokeOpacity) && strokeOpacity !== 1;
1466
+ if (applyOpacity) {
1467
+ currentGlobalAlpha = context.globalAlpha;
1468
+ context.globalAlpha = strokeOpacity;
1469
+ }
1470
+ context.strokeText(text, x, y);
1471
+ if (applyOpacity) {
1472
+ context.globalAlpha = currentGlobalAlpha;
1473
+ }
1474
+ }
1475
+
1476
+ /**
1477
+ * Draw text decoration lines (underline, overline, line-through)
1478
+ */
1479
+ }, {
1480
+ key: "drawTextDecorations",
1481
+ value: function drawTextDecorations(context, parsedStyle, object, lines, lineHeight, offsetX, baseY, canvasContext, plugin, runtime) {
1482
+ var textDecorationLine = parsedStyle.textDecorationLine,
1483
+ textDecorationColor = parsedStyle.textDecorationColor,
1484
+ textDecorationStyle = parsedStyle.textDecorationStyle,
1485
+ _parsedStyle$textDeco = parsedStyle.textDecorationThickness,
1486
+ textDecorationThickness = _parsedStyle$textDeco === void 0 ? 1 : _parsedStyle$textDeco,
1487
+ _parsedStyle$textAlig2 = parsedStyle.textAlign,
1488
+ textAlign = _parsedStyle$textAlig2 === void 0 ? 'start' : _parsedStyle$textAlig2,
1489
+ _parsedStyle$lineWidt2 = parsedStyle.lineWidth,
1490
+ lineWidth = _parsedStyle$lineWidt2 === void 0 ? 1 : _parsedStyle$lineWidt2,
1491
+ metrics = parsedStyle.metrics;
1492
+ if (!textDecorationLine || textDecorationLine === 'none') {
1493
+ return;
1494
+ }
1495
+ var lineMetrics = metrics.lineMetrics;
1496
+ var decorations = textDecorationLine.split(' ');
1497
+
1498
+ // Set decoration style
1499
+ context.lineWidth = textDecorationThickness;
1500
+ if (textDecorationColor) {
1501
+ context.strokeStyle = "rgba(".concat(textDecorationColor.r, ", ").concat(textDecorationColor.g, ", ").concat(textDecorationColor.b, ", ").concat(textDecorationColor.alpha, ")");
1502
+ }
1503
+
1504
+ // Set line style based on textDecorationStyle
1505
+ switch (textDecorationStyle) {
1506
+ case 'dashed':
1507
+ context.setLineDash([5, 5]);
1508
+ break;
1509
+ case 'dotted':
1510
+ context.setLineDash([2, 2]);
1511
+ break;
1512
+ case 'wavy':
1513
+ // For wavy, we'll use a simple approximation with bezier curves
1514
+ // A full implementation would be more complex
1515
+ context.setLineDash([]);
1516
+ break;
1517
+ default:
1518
+ context.setLineDash([]);
1519
+ break;
1520
+ }
1521
+ var linePositionY = baseY;
1522
+
1523
+ // Adjust for text baseline
1524
+ var _parsedStyle$textBase2 = parsedStyle.textBaseline,
1525
+ textBaseline = _parsedStyle$textBase2 === void 0 ? 'alphabetic' : _parsedStyle$textBase2;
1526
+ if (textBaseline === 'middle') {
1527
+ linePositionY += -metrics.height / 2 - lineHeight / 2;
1528
+ } else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
1529
+ linePositionY += -metrics.height;
1530
+ } else if (textBaseline === 'top' || textBaseline === 'hanging') {
1531
+ linePositionY += -lineHeight;
1532
+ }
1533
+
1534
+ // Draw each decoration for each line
1535
+ for (var i = 0; i < lines.length; i++) {
1536
+ linePositionY += lineHeight;
1537
+ var lineMetric = lineMetrics[i];
1538
+ if (!lineMetric) continue;
1539
+ var lineWidthOffset = lineWidth / 2;
1540
+ var startX = offsetX;
1541
+ var endX = offsetX + lineMetric.width;
1542
+
1543
+ // Adjust for text alignment
1544
+ if (textAlign === 'center' || textAlign === 'middle') {
1545
+ startX = offsetX - lineMetric.width / 2;
1546
+ endX = offsetX + lineMetric.width / 2;
1547
+ } else if (textAlign === 'right' || textAlign === 'end') {
1548
+ startX = offsetX - lineMetric.width;
1549
+ endX = offsetX;
1550
+ }
1551
+
1552
+ // Add lineWidth offset
1553
+ startX += lineWidthOffset;
1554
+ endX += lineWidthOffset;
1555
+
1556
+ // Draw each type of decoration
1557
+ var _iterator = _createForOfIteratorHelper(decorations),
1558
+ _step;
1559
+ try {
1560
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1561
+ var decoration = _step.value;
1562
+ var decorationY = linePositionY;
1563
+ switch (decoration) {
1564
+ case 'underline':
1565
+ decorationY += 2; // Small offset below baseline
1566
+ break;
1567
+ case 'overline':
1568
+ decorationY -= lineHeight - 2; // Small offset above line
1569
+ break;
1570
+ case 'line-through':
1571
+ decorationY -= lineHeight / 2; // Middle of line
1572
+ break;
1573
+ default:
1574
+ continue;
1575
+ // Unknown decoration type
1576
+ }
1577
+ if (textDecorationStyle === 'wavy') {
1578
+ this.drawWavyLine(context, startX, endX, decorationY);
1579
+ } else {
1580
+ context.beginPath();
1581
+ context.moveTo(startX, decorationY);
1582
+ context.lineTo(endX, decorationY);
1583
+ context.stroke();
1584
+ }
1585
+ }
1586
+ } catch (err) {
1587
+ _iterator.e(err);
1588
+ } finally {
1589
+ _iterator.f();
1590
+ }
1591
+ }
1592
+
1593
+ // Reset line dash
1594
+ context.setLineDash([]);
1595
+ }
1596
+
1597
+ /**
1598
+ * Draw a wavy line as an approximation of the wavy text decoration style
1599
+ */
1600
+ }, {
1601
+ key: "drawWavyLine",
1602
+ value: function drawWavyLine(context, startX, endX, y) {
1603
+ var amplitude = 2; // Height of the wave
1604
+ var wavelength = 10; // Length of one wave cycle
1605
+ var numWaves = Math.floor((endX - startX) / wavelength);
1606
+ context.beginPath();
1607
+ context.moveTo(startX, y);
1608
+ for (var i = 0; i < numWaves; i++) {
1609
+ var x1 = startX + i * wavelength + wavelength / 4;
1610
+ var y1 = y + amplitude;
1611
+ var x2 = startX + i * wavelength + wavelength / 2;
1612
+ var y2 = y;
1613
+ context.quadraticCurveTo(x1, y1, x2, y2);
1614
+ var x3 = startX + i * wavelength + wavelength * 3 / 4;
1615
+ var y3 = y - amplitude;
1616
+ var x4 = startX + (i + 1) * wavelength;
1617
+ var y4 = y;
1618
+ context.quadraticCurveTo(x3, y3, x4, y4);
1619
+ }
1620
+ context.stroke();
1621
+ }
1622
+
1623
+ // ---
1624
+ }, {
1625
+ key: "drawToContext",
1626
+ value: function drawToContext(context, object, renderState, plugin, runtime) {
1627
+ this.render(context, object.parsedStyle, object, object.ownerDocument.defaultView.context, plugin, runtime);
1628
+ }
1629
+ }]);
1630
+ }(DefaultRenderer);
1631
+
1632
+ var Plugin$2 = /*#__PURE__*/function (_AbstractRendererPlug) {
1633
+ function Plugin() {
1634
+ var _this;
1635
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1636
+ _classCallCheck(this, Plugin);
1637
+ _this = _callSuper(this, Plugin);
1638
+ _this.name = 'canvas-renderer';
1639
+ _this.options = options;
1640
+ return _this;
1641
+ }
1642
+ _inherits(Plugin, _AbstractRendererPlug);
1643
+ return _createClass(Plugin, [{
1644
+ key: "init",
1645
+ value: function init() {
1646
+ var _defaultStyleRenderer;
1647
+ var canvasRendererPluginOptions = _objectSpread({
1648
+ dirtyObjectNumThreshold: 500,
1649
+ dirtyObjectRatioThreshold: 0.8
1650
+ }, this.options);
1651
+
1652
+ // @ts-ignore
1653
+ var imagePool = this.context.imagePool;
1654
+ var defaultRenderer = new DefaultRenderer(imagePool);
1655
+ var defaultStyleRendererFactory = (_defaultStyleRenderer = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defaultStyleRenderer, Shape.CIRCLE, defaultRenderer), Shape.ELLIPSE, defaultRenderer), Shape.RECT, defaultRenderer), Shape.IMAGE, new ImageRenderer(imagePool)), Shape.TEXT, new TextRenderer(imagePool)), Shape.LINE, defaultRenderer), Shape.POLYLINE, defaultRenderer), Shape.POLYGON, defaultRenderer), Shape.PATH, defaultRenderer), Shape.GROUP, undefined), _defineProperty(_defineProperty(_defineProperty(_defaultStyleRenderer, Shape.HTML, undefined), Shape.MESH, undefined), Shape.FRAGMENT, undefined));
1656
+ this.context.defaultStyleRendererFactory = defaultStyleRendererFactory;
1657
+ this.context.styleRendererFactory = defaultStyleRendererFactory;
1658
+ this.addRenderingPlugin(new CanvasRendererPlugin(canvasRendererPluginOptions));
1659
+ }
1660
+ }, {
1661
+ key: "destroy",
1662
+ value: function destroy() {
1663
+ this.removeAllRenderingPlugins();
1664
+ delete this.context.defaultStyleRendererFactory;
1665
+ delete this.context.styleRendererFactory;
1666
+ }
1667
+ }]);
1668
+ }(AbstractRendererPlugin);
1669
+
1670
+ var index$2 = /*#__PURE__*/Object.freeze({
1671
+ __proto__: null,
1672
+ CircleRenderer: DefaultRenderer,
1673
+ DefaultRenderer: DefaultRenderer,
1674
+ EllipseRenderer: DefaultRenderer,
1675
+ ImageRenderer: ImageRenderer,
1676
+ LineRenderer: DefaultRenderer,
1677
+ PathRenderer: DefaultRenderer,
1678
+ Plugin: Plugin$2,
1679
+ PolygonRenderer: DefaultRenderer,
1680
+ PolylineRenderer: DefaultRenderer,
1681
+ RectRenderer: DefaultRenderer,
1682
+ TextRenderer: TextRenderer
1683
+ });
1684
+
1685
+ var tmpVec3a = vec3.create();
1686
+ var tmpVec3b = vec3.create();
1687
+ var tmpVec3c = vec3.create();
1688
+ var tmpMat4 = mat4.create();
1689
+ /**
1690
+ * pick shape(s) with Mouse/Touch event
1691
+ *
1692
+ * 1. find AABB with r-tree
1693
+ * 2. do math calculation with geometry in an accurate way
1694
+ */
1695
+ var CanvasPickerPlugin = /*#__PURE__*/function () {
1696
+ function CanvasPickerPlugin() {
1697
+ var _this = this;
1698
+ _classCallCheck(this, CanvasPickerPlugin);
1699
+ this.isHit = function (displayObject, position, worldTransform, isClipPath) {
1700
+ // use picker for current shape's type
1701
+ var pick = _this.context.pointInPathPickerFactory[displayObject.nodeName];
1702
+ if (pick) {
1703
+ // invert with world matrix
1704
+ var invertWorldMat = mat4.invert(tmpMat4, worldTransform);
1705
+
1706
+ // transform client position to local space, do picking in local space
1707
+ var localPosition = vec3.transformMat4(tmpVec3b, vec3.set(tmpVec3c, position[0], position[1], 0), invertWorldMat);
1708
+ if (pick(displayObject, new Point(localPosition[0], localPosition[1]), isClipPath, _this.isPointInPath, _this.context, _this.runtime)) {
1709
+ return true;
1710
+ }
1711
+ }
1712
+ return false;
1713
+ };
1714
+ /**
1715
+ * use native picking method
1716
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/isPointInPath
1717
+ */
1718
+ this.isPointInPath = function (displayObject, position) {
1719
+ var context = _this.runtime.offscreenCanvasCreator.getOrCreateContext(_this.context.config.offscreenCanvas);
1720
+ var generatePath = _this.context.pathGeneratorFactory[displayObject.nodeName];
1721
+ if (generatePath) {
1722
+ context.beginPath();
1723
+ generatePath(context, displayObject.parsedStyle);
1724
+ context.closePath();
1725
+ }
1726
+ return context.isPointInPath(position.x, position.y);
1727
+ };
1728
+ }
1729
+ return _createClass(CanvasPickerPlugin, [{
1730
+ key: "apply",
1731
+ value: function apply(context, runtime) {
1732
+ var _renderingContext$roo,
1733
+ _this2 = this;
1734
+ var renderingService = context.renderingService,
1735
+ renderingContext = context.renderingContext;
1736
+ this.context = context;
1737
+ this.runtime = runtime;
1738
+ var document = (_renderingContext$roo = renderingContext.root) === null || _renderingContext$roo === void 0 ? void 0 : _renderingContext$roo.ownerDocument;
1739
+ renderingService.hooks.pick.tapPromise(CanvasPickerPlugin.tag, /*#__PURE__*/function () {
1740
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(result) {
1741
+ return _regeneratorRuntime().wrap(function (_context) {
1742
+ while (1) switch (_context.prev = _context.next) {
1743
+ case 0:
1744
+ return _context.abrupt("return", _this2.pick(document, result));
1745
+ case 1:
1746
+ case "end":
1747
+ return _context.stop();
1748
+ }
1749
+ }, _callee);
1750
+ }));
1751
+ return function (_x) {
1752
+ return _ref.apply(this, arguments);
1753
+ };
1754
+ }());
1755
+ renderingService.hooks.pickSync.tap(CanvasPickerPlugin.tag, function (result) {
1756
+ return _this2.pick(document, result);
1757
+ });
1758
+ }
1759
+ }, {
1760
+ key: "pick",
1761
+ value: function pick(document, result) {
1762
+ var topmost = result.topmost,
1763
+ _result$position = result.position,
1764
+ x = _result$position.x,
1765
+ y = _result$position.y;
1766
+
1767
+ // position in world space
1768
+ var position = vec3.set(tmpVec3a, x, y, 0);
1769
+
1770
+ // query by AABB
1771
+ var hitTestList = document.elementsFromBBox(position[0], position[1], position[0], position[1]);
1772
+
1773
+ // test with clip path & origin shape
1774
+ // @see https://github.com/antvis/g/issues/1064
1775
+ var pickedDisplayObjects = [];
1776
+ var _iterator = _createForOfIteratorHelper(hitTestList),
1777
+ _step;
1778
+ try {
1779
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1780
+ var _displayObject = _step.value;
1781
+ var worldTransform = _displayObject.getWorldTransform();
1782
+ var isHitOriginShape = this.isHit(_displayObject, position, worldTransform, false);
1783
+ if (isHitOriginShape) {
1784
+ // should look up in the ancestor node
1785
+ var clipped = findClosestClipPathTarget(_displayObject);
1786
+ if (clipped) {
1787
+ var clipPath = clipped.parsedStyle.clipPath;
1788
+ var isHitClipPath = this.isHit(clipPath, position, clipPath.getWorldTransform(), true);
1789
+ if (isHitClipPath) {
1790
+ if (topmost) {
1791
+ result.picked = [_displayObject];
1792
+ return result;
1793
+ }
1794
+ pickedDisplayObjects.push(_displayObject);
1795
+ }
1796
+ } else {
1797
+ if (topmost) {
1798
+ result.picked = [_displayObject];
1799
+ return result;
1800
+ }
1801
+ pickedDisplayObjects.push(_displayObject);
1802
+ }
1803
+ }
1804
+ }
1805
+ } catch (err) {
1806
+ _iterator.e(err);
1807
+ } finally {
1808
+ _iterator.f();
1809
+ }
1810
+ result.picked = pickedDisplayObjects;
1811
+ return result;
1812
+ }
1813
+ }]);
1814
+ }();
1815
+ CanvasPickerPlugin.tag = 'CanvasPicker';
1816
+
1817
+ function isPointInPath$8(displayObject, position, isClipPath) {
1818
+ var _ref = displayObject.parsedStyle,
1819
+ _ref$cx = _ref.cx,
1820
+ cx = _ref$cx === void 0 ? 0 : _ref$cx,
1821
+ _ref$cy = _ref.cy,
1822
+ cy = _ref$cy === void 0 ? 0 : _ref$cy,
1823
+ r = _ref.r,
1824
+ fill = _ref.fill,
1825
+ stroke = _ref.stroke,
1826
+ _ref$lineWidth = _ref.lineWidth,
1827
+ lineWidth = _ref$lineWidth === void 0 ? 1 : _ref$lineWidth,
1828
+ _ref$increasedLineWid = _ref.increasedLineWidthForHitTesting,
1829
+ increasedLineWidthForHitTesting = _ref$increasedLineWid === void 0 ? 0 : _ref$increasedLineWid,
1830
+ _ref$pointerEvents = _ref.pointerEvents,
1831
+ pointerEvents = _ref$pointerEvents === void 0 ? 'auto' : _ref$pointerEvents;
1832
+ var halfLineWidth = (lineWidth + increasedLineWidthForHitTesting) / 2;
1833
+ var absDistance = distance(cx, cy, position.x, position.y);
1834
+ var _isFillOrStrokeAffect = isFillOrStrokeAffected(pointerEvents, fill, stroke),
1835
+ _isFillOrStrokeAffect2 = _slicedToArray(_isFillOrStrokeAffect, 2),
1836
+ hasFill = _isFillOrStrokeAffect2[0],
1837
+ hasStroke = _isFillOrStrokeAffect2[1];
1838
+ if (hasFill && hasStroke || isClipPath) {
1839
+ return absDistance <= r + halfLineWidth;
1840
+ }
1841
+ if (hasFill) {
1842
+ return absDistance <= r;
1843
+ }
1844
+ if (hasStroke) {
1845
+ return absDistance >= r - halfLineWidth && absDistance <= r + halfLineWidth;
1846
+ }
1847
+ return false;
1848
+ }
1849
+
1850
+ function ellipseDistance(squareX, squareY, rx, ry) {
1851
+ return squareX / (rx * rx) + squareY / (ry * ry);
1852
+ }
1853
+ function isPointInPath$7(displayObject, position, isClipPath) {
1854
+ var _ref = displayObject.parsedStyle,
1855
+ _ref$cx = _ref.cx,
1856
+ cx = _ref$cx === void 0 ? 0 : _ref$cx,
1857
+ _ref$cy = _ref.cy,
1858
+ cy = _ref$cy === void 0 ? 0 : _ref$cy,
1859
+ rx = _ref.rx,
1860
+ ry = _ref.ry,
1861
+ fill = _ref.fill,
1862
+ stroke = _ref.stroke,
1863
+ _ref$lineWidth = _ref.lineWidth,
1864
+ lineWidth = _ref$lineWidth === void 0 ? 1 : _ref$lineWidth,
1865
+ _ref$increasedLineWid = _ref.increasedLineWidthForHitTesting,
1866
+ increasedLineWidthForHitTesting = _ref$increasedLineWid === void 0 ? 0 : _ref$increasedLineWid,
1867
+ _ref$pointerEvents = _ref.pointerEvents,
1868
+ pointerEvents = _ref$pointerEvents === void 0 ? 'auto' : _ref$pointerEvents;
1869
+ var x = position.x,
1870
+ y = position.y;
1871
+ var _isFillOrStrokeAffect = isFillOrStrokeAffected(pointerEvents, fill, stroke),
1872
+ _isFillOrStrokeAffect2 = _slicedToArray(_isFillOrStrokeAffect, 2),
1873
+ hasFill = _isFillOrStrokeAffect2[0],
1874
+ hasStroke = _isFillOrStrokeAffect2[1];
1875
+ var halfLineWith = (lineWidth + increasedLineWidthForHitTesting) / 2;
1876
+ var squareX = (x - cx) * (x - cx);
1877
+ var squareY = (y - cy) * (y - cy);
1878
+ // 使用椭圆的公式: x*x/rx*rx + y*y/ry*ry = 1;
1879
+ if (hasFill && hasStroke || isClipPath) {
1880
+ return ellipseDistance(squareX, squareY, rx + halfLineWith, ry + halfLineWith) <= 1;
1881
+ }
1882
+ if (hasFill) {
1883
+ return ellipseDistance(squareX, squareY, rx, ry) <= 1;
1884
+ }
1885
+ if (hasStroke) {
1886
+ return ellipseDistance(squareX, squareY, rx - halfLineWith, ry - halfLineWith) >= 1 && ellipseDistance(squareX, squareY, rx + halfLineWith, ry + halfLineWith) <= 1;
1887
+ }
1888
+ return false;
1889
+ }
1890
+
1891
+ function inBox(minX, minY, width, height, x, y) {
1892
+ return x >= minX && x <= minX + width && y >= minY && y <= minY + height;
1893
+ }
1894
+ function inRect(minX, minY, width, height, lineWidth, x, y) {
1895
+ var halfWidth = lineWidth / 2;
1896
+ // 将四个边看做矩形来检测,比边的检测算法要快
1897
+ return inBox(minX - halfWidth, minY - halfWidth, width, lineWidth, x, y) ||
1898
+ // 上边
1899
+ inBox(minX + width - halfWidth, minY - halfWidth, lineWidth, height, x, y) ||
1900
+ // 右边
1901
+ inBox(minX + halfWidth, minY + height - halfWidth, width, lineWidth, x, y) ||
1902
+ // 下边
1903
+ inBox(minX - halfWidth, minY + halfWidth, lineWidth, height, x, y); // 左边
1904
+ }
1905
+ function inArc(cx, cy, r, startAngle, endAngle, lineWidth, x, y) {
1906
+ var angle = (Math.atan2(y - cy, x - cx) + Math.PI * 2) % (Math.PI * 2); // 转换到 0 - 2 * Math.PI 之间
1907
+ // if (angle < startAngle || angle > endAngle) {
1908
+ // return false;
1909
+ // }
1910
+ var point = {
1911
+ x: cx + r * Math.cos(angle),
1912
+ y: cy + r * Math.sin(angle)
1913
+ };
1914
+ return distance(point.x, point.y, x, y) <= lineWidth / 2;
1915
+ }
1916
+ function inLine(x1, y1, x2, y2, lineWidth, x, y) {
1917
+ var minX = Math.min(x1, x2);
1918
+ var maxX = Math.max(x1, x2);
1919
+ var minY = Math.min(y1, y2);
1920
+ var maxY = Math.max(y1, y2);
1921
+ var halfWidth = lineWidth / 2;
1922
+ // 因为目前的方案是计算点到直线的距离,而有可能会在延长线上,所以要先判断是否在包围盒内
1923
+ // 这种方案会在水平或者竖直的情况下载线的延长线上有半 lineWidth 的误差
1924
+ if (!(x >= minX - halfWidth && x <= maxX + halfWidth && y >= minY - halfWidth && y <= maxY + halfWidth)) {
1925
+ return false;
1926
+ }
1927
+ // 因为已经计算了包围盒,所以仅需要计算到直线的距离即可,可以显著提升性能
1928
+ return linePointToLine(x1, y1, x2, y2, x, y) <= lineWidth / 2;
1929
+ }
1930
+ function inPolyline(points, lineWidth, x, y, isClose) {
1931
+ var count = points.length;
1932
+ if (count < 2) {
1933
+ return false;
1934
+ }
1935
+ for (var i = 0; i < count - 1; i++) {
1936
+ var x1 = points[i][0];
1937
+ var y1 = points[i][1];
1938
+ var x2 = points[i + 1][0];
1939
+ var y2 = points[i + 1][1];
1940
+ if (inLine(x1, y1, x2, y2, lineWidth, x, y)) {
1941
+ return true;
1942
+ }
1943
+ }
1944
+
1945
+ // 如果封闭,则计算起始点和结束点的边
1946
+ if (isClose) {
1947
+ var first = points[0];
1948
+ var last = points[count - 1];
1949
+ if (inLine(first[0], first[1], last[0], last[1], lineWidth, x, y)) {
1950
+ return true;
1951
+ }
1952
+ }
1953
+ return false;
1954
+ }
1955
+
1956
+ // 多边形的射线检测,参考:https://blog.csdn.net/WilliamSun0122/article/details/77994526
1957
+ var tolerance = 1e-6;
1958
+ // 三态函数,判断两个double在eps精度下的大小关系
1959
+ function dcmp(x) {
1960
+ if (Math.abs(x) < tolerance) {
1961
+ return 0;
1962
+ }
1963
+ return x < 0 ? -1 : 1;
1964
+ }
1965
+
1966
+ // 判断点Q是否在p1和p2的线段上
1967
+ function onSegment(p1, p2, q) {
1968
+ if ((q[0] - p1[0]) * (p2[1] - p1[1]) === (p2[0] - p1[0]) * (q[1] - p1[1]) && Math.min(p1[0], p2[0]) <= q[0] && q[0] <= Math.max(p1[0], p2[0]) && Math.min(p1[1], p2[1]) <= q[1] && q[1] <= Math.max(p1[1], p2[1])) {
1969
+ return true;
1970
+ }
1971
+ return false;
1972
+ }
1973
+
1974
+ // 判断点P在多边形内-射线法
1975
+ function inPolygon(points, x, y) {
1976
+ var isHit = false;
1977
+ var n = points.length;
1978
+ if (n <= 2) {
1979
+ // svg 中点小于 3 个时,不显示,也无法被拾取
1980
+ return false;
1981
+ }
1982
+ for (var i = 0; i < n; i++) {
1983
+ var p1 = points[i];
1984
+ var p2 = points[(i + 1) % n];
1985
+ if (onSegment(p1, p2, [x, y])) {
1986
+ // 点在多边形一条边上
1987
+ return true;
1988
+ }
1989
+ // 前一个判断min(p1[1],p2[1])<P.y<=max(p1[1],p2[1])
1990
+ // 后一个判断被测点 在 射线与边交点 的左边
1991
+ if (dcmp(p1[1] - y) > 0 !== dcmp(p2[1] - y) > 0 && dcmp(x - (y - p1[1]) * (p1[0] - p2[0]) / (p1[1] - p2[1]) - p1[0]) < 0) {
1992
+ isHit = !isHit;
1993
+ }
1994
+ }
1995
+ return isHit;
1996
+ }
1997
+ function inPolygons(polygons, x, y) {
1998
+ var isHit = false;
1999
+ for (var i = 0; i < polygons.length; i++) {
2000
+ var points = polygons[i];
2001
+ isHit = inPolygon(points, x, y);
2002
+ if (isHit) {
2003
+ break;
2004
+ }
2005
+ }
2006
+ return isHit;
2007
+ }
2008
+
2009
+ function isPointInPath$6(displayObject, position, isClipPath) {
2010
+ var _ref = displayObject.parsedStyle,
2011
+ x1 = _ref.x1,
2012
+ y1 = _ref.y1,
2013
+ x2 = _ref.x2,
2014
+ y2 = _ref.y2,
2015
+ _ref$lineWidth = _ref.lineWidth,
2016
+ lineWidth = _ref$lineWidth === void 0 ? 1 : _ref$lineWidth,
2017
+ _ref$increasedLineWid = _ref.increasedLineWidthForHitTesting,
2018
+ increasedLineWidthForHitTesting = _ref$increasedLineWid === void 0 ? 0 : _ref$increasedLineWid,
2019
+ _ref$pointerEvents = _ref.pointerEvents,
2020
+ pointerEvents = _ref$pointerEvents === void 0 ? 'auto' : _ref$pointerEvents,
2021
+ fill = _ref.fill,
2022
+ stroke = _ref.stroke;
2023
+ var _isFillOrStrokeAffect = isFillOrStrokeAffected(pointerEvents, fill, stroke),
2024
+ _isFillOrStrokeAffect2 = _slicedToArray(_isFillOrStrokeAffect, 2),
2025
+ hasStroke = _isFillOrStrokeAffect2[1];
2026
+ if (!hasStroke && !isClipPath || !lineWidth) {
2027
+ return false;
2028
+ }
2029
+ return inLine(x1, y1, x2, y2, lineWidth + increasedLineWidthForHitTesting, position.x, position.y);
2030
+ }
2031
+
2032
+ // TODO: replace it with method in @antv/util
2033
+ function isPointInStroke(segments, lineWidth, px, py, length) {
2034
+ var isHit = false;
2035
+ var halfWidth = lineWidth / 2;
2036
+ for (var i = 0; i < segments.length; i++) {
2037
+ var segment = segments[i];
2038
+ var currentPoint = segment.currentPoint,
2039
+ params = segment.params,
2040
+ prePoint = segment.prePoint,
2041
+ box = segment.box;
2042
+ // 如果在前面已经生成过包围盒,直接按照包围盒计算
2043
+ if (box && !inBox(box.x - halfWidth, box.y - halfWidth, box.width + lineWidth, box.height + lineWidth, px, py)) {
2044
+ continue;
2045
+ }
2046
+ switch (segment.command) {
2047
+ // L 和 Z 都是直线, M 不进行拾取
2048
+ case 'L':
2049
+ case 'Z':
2050
+ isHit = inLine(prePoint[0], prePoint[1], currentPoint[0], currentPoint[1], lineWidth, px, py);
2051
+ if (isHit) {
2052
+ return true;
2053
+ }
2054
+ break;
2055
+ case 'Q':
2056
+ var qDistance = quadPointDistance(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4], px, py);
2057
+ isHit = qDistance <= lineWidth / 2;
2058
+ if (isHit) {
2059
+ return true;
2060
+ }
2061
+ break;
2062
+ case 'C':
2063
+ var cDistance = cubicPointDistance(prePoint[0],
2064
+ // 上一段结束位置, 即 C 的起始点
2065
+ prePoint[1], params[1],
2066
+ // 'C' 的参数,1、2 为第一个控制点,3、4 为第二个控制点,5、6 为结束点
2067
+ params[2], params[3], params[4], params[5], params[6], px, py, length);
2068
+ isHit = cDistance <= lineWidth / 2;
2069
+ if (isHit) {
2070
+ return true;
2071
+ }
2072
+ break;
2073
+ case 'A':
2074
+ // cache conversion result
2075
+ if (!segment.cubicParams) {
2076
+ segment.cubicParams = arcToCubic(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4], params[5], params[6], params[7], undefined);
2077
+ }
2078
+ var args = segment.cubicParams;
2079
+
2080
+ // fixArc
2081
+ var prePointInCubic = prePoint;
2082
+ for (var _i = 0; _i < args.length; _i += 6) {
2083
+ var _cDistance = cubicPointDistance(prePointInCubic[0],
2084
+ // 上一段结束位置, 即 C 的起始点
2085
+ prePointInCubic[1], args[_i], args[_i + 1], args[_i + 2], args[_i + 3], args[_i + 4], args[_i + 5], px, py, length);
2086
+ prePointInCubic = [args[_i + 4], args[_i + 5]];
2087
+ isHit = _cDistance <= lineWidth / 2;
2088
+ if (isHit) {
2089
+ return true;
2090
+ }
2091
+ }
2092
+ break;
2093
+ }
2094
+ }
2095
+ return isHit;
2096
+ }
2097
+ function isPointInPath$5(displayObject, position, isClipPath, isPointInPath, renderingPluginContext, runtime) {
2098
+ var _ref = displayObject.parsedStyle,
2099
+ _ref$lineWidth = _ref.lineWidth,
2100
+ lineWidth = _ref$lineWidth === void 0 ? 1 : _ref$lineWidth,
2101
+ _ref$increasedLineWid = _ref.increasedLineWidthForHitTesting,
2102
+ increasedLineWidthForHitTesting = _ref$increasedLineWid === void 0 ? 0 : _ref$increasedLineWid,
2103
+ stroke = _ref.stroke,
2104
+ fill = _ref.fill,
2105
+ d = _ref.d,
2106
+ _ref$pointerEvents = _ref.pointerEvents,
2107
+ pointerEvents = _ref$pointerEvents === void 0 ? 'auto' : _ref$pointerEvents;
2108
+ var segments = d.segments,
2109
+ hasArc = d.hasArc,
2110
+ polylines = d.polylines,
2111
+ polygons = d.polygons;
2112
+ var _isFillOrStrokeAffect = isFillOrStrokeAffected(pointerEvents,
2113
+ // Only a closed path can be filled.
2114
+ (polygons === null || polygons === void 0 ? void 0 : polygons.length) && fill, stroke),
2115
+ _isFillOrStrokeAffect2 = _slicedToArray(_isFillOrStrokeAffect, 2),
2116
+ hasFill = _isFillOrStrokeAffect2[0],
2117
+ hasStroke = _isFillOrStrokeAffect2[1];
2118
+ var totalLength = getOrCalculatePathTotalLength(displayObject);
2119
+ var isHit = false;
2120
+ if (hasFill || isClipPath) {
2121
+ if (hasArc) {
2122
+ // 存在曲线时,暂时使用 canvas 的 api 计算,后续可以进行多边形切割
2123
+ isHit = isPointInPath(displayObject, position);
2124
+ } else {
2125
+ // 提取出来的多边形包含闭合的和非闭合的,在这里统一按照多边形处理
2126
+ isHit = inPolygons(polygons, position.x, position.y) || inPolygons(polylines, position.x, position.y);
2127
+ }
2128
+ return isHit;
2129
+ }
2130
+ if (hasStroke || isClipPath) {
2131
+ isHit = isPointInStroke(segments, lineWidth + increasedLineWidthForHitTesting, position.x, position.y, totalLength);
2132
+ }
2133
+ return isHit;
2134
+ }
2135
+
2136
+ function isPointInPath$4(displayObject, position, isClipPath) {
2137
+ var _ref = displayObject.parsedStyle,
2138
+ stroke = _ref.stroke,
2139
+ fill = _ref.fill,
2140
+ _ref$lineWidth = _ref.lineWidth,
2141
+ lineWidth = _ref$lineWidth === void 0 ? 1 : _ref$lineWidth,
2142
+ _ref$increasedLineWid = _ref.increasedLineWidthForHitTesting,
2143
+ increasedLineWidthForHitTesting = _ref$increasedLineWid === void 0 ? 0 : _ref$increasedLineWid,
2144
+ points = _ref.points,
2145
+ _ref$pointerEvents = _ref.pointerEvents,
2146
+ pointerEvents = _ref$pointerEvents === void 0 ? 'auto' : _ref$pointerEvents;
2147
+ var _isFillOrStrokeAffect = isFillOrStrokeAffected(pointerEvents, fill, stroke),
2148
+ _isFillOrStrokeAffect2 = _slicedToArray(_isFillOrStrokeAffect, 2),
2149
+ hasFill = _isFillOrStrokeAffect2[0],
2150
+ hasStroke = _isFillOrStrokeAffect2[1];
2151
+ var isHit = false;
2152
+ if (hasStroke || isClipPath) {
2153
+ isHit = inPolyline(points.points, lineWidth + increasedLineWidthForHitTesting, position.x, position.y, true);
2154
+ }
2155
+ if (!isHit && (hasFill || isClipPath)) {
2156
+ isHit = inPolygon(points.points, position.x, position.y);
2157
+ }
2158
+ return isHit;
2159
+ }
2160
+
2161
+ function isPointInPath$3(displayObject, position, isClipPath) {
2162
+ var _ref = displayObject.parsedStyle,
2163
+ _ref$lineWidth = _ref.lineWidth,
2164
+ lineWidth = _ref$lineWidth === void 0 ? 1 : _ref$lineWidth,
2165
+ _ref$increasedLineWid = _ref.increasedLineWidthForHitTesting,
2166
+ increasedLineWidthForHitTesting = _ref$increasedLineWid === void 0 ? 0 : _ref$increasedLineWid,
2167
+ points = _ref.points,
2168
+ _ref$pointerEvents = _ref.pointerEvents,
2169
+ pointerEvents = _ref$pointerEvents === void 0 ? 'auto' : _ref$pointerEvents,
2170
+ fill = _ref.fill,
2171
+ stroke = _ref.stroke;
2172
+ var _isFillOrStrokeAffect = isFillOrStrokeAffected(pointerEvents, fill, stroke),
2173
+ _isFillOrStrokeAffect2 = _slicedToArray(_isFillOrStrokeAffect, 2),
2174
+ hasStroke = _isFillOrStrokeAffect2[1];
2175
+ if (!hasStroke && !isClipPath || !lineWidth) {
2176
+ return false;
2177
+ }
2178
+ return inPolyline(points.points, lineWidth + increasedLineWidthForHitTesting, position.x, position.y, false);
2179
+ }
2180
+
2181
+ function isPointInPath$2(displayObject, position, isClipPath, isPointInPath, runtime) {
2182
+ var _ref = displayObject.parsedStyle,
2183
+ radius = _ref.radius,
2184
+ fill = _ref.fill,
2185
+ stroke = _ref.stroke,
2186
+ _ref$lineWidth = _ref.lineWidth,
2187
+ lineWidth = _ref$lineWidth === void 0 ? 1 : _ref$lineWidth,
2188
+ _ref$increasedLineWid = _ref.increasedLineWidthForHitTesting,
2189
+ increasedLineWidthForHitTesting = _ref$increasedLineWid === void 0 ? 0 : _ref$increasedLineWid,
2190
+ _ref$x = _ref.x,
2191
+ x = _ref$x === void 0 ? 0 : _ref$x,
2192
+ _ref$y = _ref.y,
2193
+ y = _ref$y === void 0 ? 0 : _ref$y,
2194
+ width = _ref.width,
2195
+ height = _ref.height,
2196
+ _ref$pointerEvents = _ref.pointerEvents,
2197
+ pointerEvents = _ref$pointerEvents === void 0 ? 'auto' : _ref$pointerEvents;
2198
+ var _isFillOrStrokeAffect = isFillOrStrokeAffected(pointerEvents, fill, stroke),
2199
+ _isFillOrStrokeAffect2 = _slicedToArray(_isFillOrStrokeAffect, 2),
2200
+ hasFill = _isFillOrStrokeAffect2[0],
2201
+ hasStroke = _isFillOrStrokeAffect2[1];
2202
+ var hasRadius = radius && radius.some(function (r) {
2203
+ return r !== 0;
2204
+ });
2205
+ var lineWidthForHitTesting = lineWidth + increasedLineWidthForHitTesting;
2206
+
2207
+ // 无圆角时的策略
2208
+ if (!hasRadius) {
2209
+ var halfWidth = lineWidthForHitTesting / 2;
2210
+ // 同时填充和带有边框
2211
+ if (hasFill && hasStroke || isClipPath) {
2212
+ return inBox(x - halfWidth, y - halfWidth, width + halfWidth, height + halfWidth, position.x, position.y);
2213
+ }
2214
+ // 仅填充
2215
+ if (hasFill) {
2216
+ return inBox(x, y, width, height, position.x, position.y);
2217
+ }
2218
+ if (hasStroke) {
2219
+ return inRect(x, y, width, height, lineWidthForHitTesting, position.x, position.y);
2220
+ }
2221
+ } else {
2222
+ var isHit = false;
2223
+ if (hasStroke || isClipPath) {
2224
+ isHit = inRectWithRadius(x, y, width, height, radius.map(function (r) {
2225
+ return clamp(r, 0, Math.min(Math.abs(width) / 2, Math.abs(height) / 2));
2226
+ }), lineWidthForHitTesting, position.x, position.y);
2227
+ }
2228
+ // 仅填充时带有圆角的矩形直接通过图形拾取
2229
+ // 以后可以改成纯数学的近似拾取,将圆弧切割成多边形
2230
+ if (!isHit && (hasFill || isClipPath)) {
2231
+ isHit = isPointInPath(displayObject, position);
2232
+ }
2233
+ return isHit;
2234
+ }
2235
+ return false;
2236
+ }
2237
+ function inRectWithRadius(minX, minY, width, height, radiusArray, lineWidth, x, y) {
2238
+ var _radiusArray = _slicedToArray(radiusArray, 4),
2239
+ tlr = _radiusArray[0],
2240
+ trr = _radiusArray[1],
2241
+ brr = _radiusArray[2],
2242
+ blr = _radiusArray[3];
2243
+ return inLine(minX + tlr, minY, minX + width - trr, minY, lineWidth, x, y) || inLine(minX + width, minY + trr, minX + width, minY + height - brr, lineWidth, x, y) || inLine(minX + width - brr, minY + height, minX + blr, minY + height, lineWidth, x, y) || inLine(minX, minY + height - blr, minX, minY + tlr, lineWidth, x, y) || inArc(minX + width - trr, minY + trr, trr, 1.5 * Math.PI, 2 * Math.PI, lineWidth, x, y) || inArc(minX + width - brr, minY + height - brr, brr, 0, 0.5 * Math.PI, lineWidth, x, y) || inArc(minX + blr, minY + height - blr, blr, 0.5 * Math.PI, Math.PI, lineWidth, x, y) || inArc(minX + tlr, minY + tlr, tlr, Math.PI, 1.5 * Math.PI, lineWidth, x, y);
2244
+ }
2245
+
2246
+ function isPointInPath$1(displayObject, position, isClipPath, isPointInPath, renderingPluginContext, runtime) {
2247
+ var _ref = displayObject.parsedStyle,
2248
+ _ref$pointerEvents = _ref.pointerEvents,
2249
+ pointerEvents = _ref$pointerEvents === void 0 ? 'auto' : _ref$pointerEvents,
2250
+ _ref$x = _ref.x,
2251
+ x = _ref$x === void 0 ? 0 : _ref$x,
2252
+ _ref$y = _ref.y,
2253
+ y = _ref$y === void 0 ? 0 : _ref$y,
2254
+ width = _ref.width,
2255
+ height = _ref.height;
2256
+ if (pointerEvents === 'non-transparent-pixel') {
2257
+ var offscreenCanvas = renderingPluginContext.config.offscreenCanvas;
2258
+ var canvas = runtime.offscreenCanvasCreator.getOrCreateCanvas(offscreenCanvas);
2259
+ var context = runtime.offscreenCanvasCreator.getOrCreateContext(offscreenCanvas, {
2260
+ willReadFrequently: true
2261
+ });
2262
+ canvas.width = width;
2263
+ canvas.height = height;
2264
+ renderingPluginContext.defaultStyleRendererFactory[Shape.IMAGE].render(context, _objectSpread(_objectSpread({}, displayObject.parsedStyle), {}, {
2265
+ x: 0,
2266
+ y: 0
2267
+ }), displayObject, undefined, undefined, undefined);
2268
+ var imagedata = context.getImageData(position.x - x, position.y - y, 1, 1).data;
2269
+ return imagedata.every(function (component) {
2270
+ return component !== 0;
2271
+ });
2272
+ }
2273
+ return true;
2274
+ }
2275
+
2276
+ function isPointInPath(displayObject, position, isClipPath, isPointInPath) {
2277
+ var bounds = displayObject.getGeometryBounds();
2278
+
2279
+ // @see https://stackoverflow.com/questions/28706989/how-do-i-check-if-a-mouse-click-is-inside-a-rotated-text-on-the-html5-canvas-in
2280
+ return position.x >= bounds.min[0] && position.y >= bounds.min[1] && position.x <= bounds.max[0] && position.y <= bounds.max[1];
2281
+ }
2282
+
2283
+ var Plugin$1 = /*#__PURE__*/function (_AbstractRendererPlug) {
2284
+ function Plugin() {
2285
+ var _this;
2286
+ _classCallCheck(this, Plugin);
2287
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2288
+ args[_key] = arguments[_key];
2289
+ }
2290
+ _this = _callSuper(this, Plugin, [].concat(args));
2291
+ _this.name = 'canvas-picker';
2292
+ return _this;
2293
+ }
2294
+ _inherits(Plugin, _AbstractRendererPlug);
2295
+ return _createClass(Plugin, [{
2296
+ key: "init",
2297
+ value: function init() {
2298
+ var _pointInPathPickerFac;
2299
+ var pointInPathPickerFactory = (_pointInPathPickerFac = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_pointInPathPickerFac, Shape.CIRCLE, isPointInPath$8), Shape.ELLIPSE, isPointInPath$7), Shape.RECT, isPointInPath$2), Shape.LINE, isPointInPath$6), Shape.POLYLINE, isPointInPath$3), Shape.POLYGON, isPointInPath$4), Shape.PATH, isPointInPath$5), Shape.TEXT, isPointInPath), Shape.GROUP, null), Shape.IMAGE, isPointInPath$1), _defineProperty(_defineProperty(_pointInPathPickerFac, Shape.HTML, null), Shape.MESH, null));
2300
+
2301
+ // @ts-ignore
2302
+ this.context.pointInPathPickerFactory = pointInPathPickerFactory;
2303
+ this.addRenderingPlugin(new CanvasPickerPlugin());
2304
+ }
2305
+ }, {
2306
+ key: "destroy",
2307
+ value: function destroy() {
2308
+ // @ts-ignore
2309
+ delete this.context.pointInPathPickerFactory;
2310
+ this.removeAllRenderingPlugins();
2311
+ }
2312
+ }]);
2313
+ }(AbstractRendererPlugin);
2314
+
2315
+ var index$1 = /*#__PURE__*/Object.freeze({
2316
+ __proto__: null,
2317
+ Plugin: Plugin$1
2318
+ });
2319
+
2320
+ function generatePath$6(context, parsedStyle) {
2321
+ var _parsedStyle$cx = parsedStyle.cx,
2322
+ cx = _parsedStyle$cx === void 0 ? 0 : _parsedStyle$cx,
2323
+ _parsedStyle$cy = parsedStyle.cy,
2324
+ cy = _parsedStyle$cy === void 0 ? 0 : _parsedStyle$cy,
2325
+ r = parsedStyle.r;
2326
+ context.arc(cx, cy, r, 0, Math.PI * 2, false);
2327
+ }
2328
+
2329
+ function generatePath$5(context, parsedStyle) {
2330
+ var _parsedStyle$cx = parsedStyle.cx,
2331
+ cx = _parsedStyle$cx === void 0 ? 0 : _parsedStyle$cx,
2332
+ _parsedStyle$cy = parsedStyle.cy,
2333
+ cy = _parsedStyle$cy === void 0 ? 0 : _parsedStyle$cy,
2334
+ rx = parsedStyle.rx,
2335
+ ry = parsedStyle.ry;
2336
+
2337
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse
2338
+ if (context.ellipse) {
2339
+ context.ellipse(cx, cy, rx, ry, 0, 0, Math.PI * 2, false);
2340
+ } else {
2341
+ // 如果不支持,则使用圆来绘制,进行变形
2342
+ var r = rx > ry ? rx : ry;
2343
+ var scaleX = rx > ry ? 1 : rx / ry;
2344
+ var scaleY = rx > ry ? ry / rx : 1;
2345
+ context.save();
2346
+ context.scale(scaleX, scaleY);
2347
+ context.arc(cx, cy, r, 0, Math.PI * 2);
2348
+ }
2349
+ }
2350
+
2351
+ function generatePath$4(context, parsedStyle) {
2352
+ var x1 = parsedStyle.x1,
2353
+ y1 = parsedStyle.y1,
2354
+ x2 = parsedStyle.x2,
2355
+ y2 = parsedStyle.y2,
2356
+ markerStart = parsedStyle.markerStart,
2357
+ markerEnd = parsedStyle.markerEnd,
2358
+ markerStartOffset = parsedStyle.markerStartOffset,
2359
+ markerEndOffset = parsedStyle.markerEndOffset;
2360
+ var startOffsetX = 0;
2361
+ var startOffsetY = 0;
2362
+ var endOffsetX = 0;
2363
+ var endOffsetY = 0;
2364
+ var rad = 0;
2365
+ var x;
2366
+ var y;
2367
+ if (markerStart && isDisplayObject(markerStart) && markerStartOffset) {
2368
+ x = x2 - x1;
2369
+ y = y2 - y1;
2370
+ rad = Math.atan2(y, x);
2371
+ startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
2372
+ startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
2373
+ }
2374
+ if (markerEnd && isDisplayObject(markerEnd) && markerEndOffset) {
2375
+ x = x1 - x2;
2376
+ y = y1 - y2;
2377
+ rad = Math.atan2(y, x);
2378
+ endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
2379
+ endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
2380
+ }
2381
+ context.moveTo(x1 + startOffsetX, y1 + startOffsetY);
2382
+ context.lineTo(x2 + endOffsetX, y2 + endOffsetY);
2383
+ }
2384
+
2385
+ function generatePath$3(context, parsedStyle) {
2386
+ var markerStart = parsedStyle.markerStart,
2387
+ markerEnd = parsedStyle.markerEnd,
2388
+ markerStartOffset = parsedStyle.markerStartOffset,
2389
+ markerEndOffset = parsedStyle.markerEndOffset;
2390
+ var _parsedStyle$d = parsedStyle.d,
2391
+ absolutePath = _parsedStyle$d.absolutePath,
2392
+ segments = _parsedStyle$d.segments;
2393
+ var startOffsetX = 0;
2394
+ var startOffsetY = 0;
2395
+ var endOffsetX = 0;
2396
+ var endOffsetY = 0;
2397
+ var rad = 0;
2398
+ var x;
2399
+ var y;
2400
+ if (markerStart && isDisplayObject(markerStart) && markerStartOffset) {
2401
+ var _getStartTangent = markerStart.parentNode.getStartTangent(),
2402
+ _getStartTangent2 = _slicedToArray(_getStartTangent, 2),
2403
+ p1 = _getStartTangent2[0],
2404
+ p2 = _getStartTangent2[1];
2405
+ x = p1[0] - p2[0];
2406
+ y = p1[1] - p2[1];
2407
+ rad = Math.atan2(y, x);
2408
+ startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
2409
+ startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
2410
+ }
2411
+ if (markerEnd && isDisplayObject(markerEnd) && markerEndOffset) {
2412
+ var _getEndTangent = markerEnd.parentNode.getEndTangent(),
2413
+ _getEndTangent2 = _slicedToArray(_getEndTangent, 2),
2414
+ _p = _getEndTangent2[0],
2415
+ _p2 = _getEndTangent2[1];
2416
+ x = _p[0] - _p2[0];
2417
+ y = _p[1] - _p2[1];
2418
+ rad = Math.atan2(y, x);
2419
+ endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
2420
+ endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
2421
+ }
2422
+ for (var i = 0; i < absolutePath.length; i++) {
2423
+ var params = absolutePath[i];
2424
+ var command = params[0];
2425
+ var nextSegment = absolutePath[i + 1];
2426
+ var useStartOffset = i === 0 && (startOffsetX !== 0 || startOffsetY !== 0);
2427
+ var useEndOffset = (i === absolutePath.length - 1 || nextSegment && (nextSegment[0] === 'M' || nextSegment[0] === 'Z')) && endOffsetX !== 0 && endOffsetY !== 0;
2428
+ var _ref = useStartOffset ? [startOffsetX, startOffsetY] : [0, 0],
2429
+ _ref2 = _slicedToArray(_ref, 2),
2430
+ startOffsetXTemp = _ref2[0],
2431
+ startOffsetYTemp = _ref2[1];
2432
+ var _ref3 = useEndOffset ? [endOffsetX, endOffsetY] : [0, 0],
2433
+ _ref4 = _slicedToArray(_ref3, 2),
2434
+ endOffsetXTemp = _ref4[0],
2435
+ endOffsetYTemp = _ref4[1];
2436
+ switch (command) {
2437
+ case 'M':
2438
+ // Use start marker offset
2439
+ context.moveTo(params[1] + startOffsetXTemp, params[2] + startOffsetYTemp);
2440
+ break;
2441
+ case 'L':
2442
+ context.lineTo(params[1] + endOffsetXTemp, params[2] + endOffsetYTemp);
2443
+ break;
2444
+ case 'Q':
2445
+ context.quadraticCurveTo(params[1], params[2], params[3] + endOffsetXTemp, params[4] + endOffsetYTemp);
2446
+ break;
2447
+ case 'C':
2448
+ context.bezierCurveTo(params[1], params[2], params[3], params[4], params[5] + endOffsetXTemp, params[6] + endOffsetYTemp);
2449
+ break;
2450
+ case 'A':
2451
+ {
2452
+ // FIXME startOffset / endOffset
2453
+ var arcParams = segments[i].arcParams;
2454
+ var cx = arcParams.cx,
2455
+ cy = arcParams.cy,
2456
+ rx = arcParams.rx,
2457
+ ry = arcParams.ry,
2458
+ startAngle = arcParams.startAngle,
2459
+ endAngle = arcParams.endAngle,
2460
+ xRotation = arcParams.xRotation,
2461
+ sweepFlag = arcParams.sweepFlag;
2462
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse
2463
+ if (context.ellipse) {
2464
+ context.ellipse(cx, cy, rx, ry, xRotation, startAngle, endAngle, !!(1 - sweepFlag));
2465
+ } else {
2466
+ // @see https://stackoverflow.com/a/47494351
2467
+ var r = rx > ry ? rx : ry;
2468
+ var scaleX = rx > ry ? 1 : rx / ry;
2469
+ var scaleY = rx > ry ? ry / rx : 1;
2470
+ context.translate(cx, cy);
2471
+ context.rotate(xRotation);
2472
+ context.scale(scaleX, scaleY);
2473
+ context.arc(0, 0, r, startAngle, endAngle, !!(1 - sweepFlag));
2474
+ context.scale(1 / scaleX, 1 / scaleY);
2475
+ context.rotate(-xRotation);
2476
+ context.translate(-cx, -cy);
2477
+ }
2478
+ if (useEndOffset) {
2479
+ context.lineTo(params[6] + endOffsetX, params[7] + endOffsetY);
2480
+ }
2481
+ break;
2482
+ }
2483
+ case 'Z':
2484
+ context.closePath();
2485
+ break;
2486
+ }
2487
+ }
2488
+ }
2489
+
2490
+ function generatePath$2(context, parsedStyle) {
2491
+ var markerStart = parsedStyle.markerStart,
2492
+ markerEnd = parsedStyle.markerEnd,
2493
+ markerStartOffset = parsedStyle.markerStartOffset,
2494
+ markerEndOffset = parsedStyle.markerEndOffset;
2495
+ var points = parsedStyle.points.points;
2496
+ var length = points.length;
2497
+ var x1 = points[0][0];
2498
+ var y1 = points[0][1];
2499
+ var x2 = points[length - 1][0];
2500
+ var y2 = points[length - 1][1];
2501
+ var startOffsetX = 0;
2502
+ var startOffsetY = 0;
2503
+ var endOffsetX = 0;
2504
+ var endOffsetY = 0;
2505
+ var rad = 0;
2506
+ var x;
2507
+ var y;
2508
+ if (markerStart && isDisplayObject(markerStart) && markerStartOffset) {
2509
+ x = points[1][0] - points[0][0];
2510
+ y = points[1][1] - points[0][1];
2511
+ rad = Math.atan2(y, x);
2512
+ startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
2513
+ startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
2514
+ }
2515
+ if (markerEnd && isDisplayObject(markerEnd) && markerEndOffset) {
2516
+ x = points[length - 1][0] - points[0][0];
2517
+ y = points[length - 1][1] - points[0][1];
2518
+ rad = Math.atan2(y, x);
2519
+ endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
2520
+ endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
2521
+ }
2522
+ context.moveTo(x1 + (startOffsetX || endOffsetX), y1 + (startOffsetY || endOffsetY));
2523
+ for (var i = 1; i < length - 1; i++) {
2524
+ var point = points[i];
2525
+ context.lineTo(point[0], point[1]);
2526
+ }
2527
+ context.lineTo(x2, y2);
2528
+ }
2529
+
2530
+ function generatePath$1(context, parsedStyle) {
2531
+ var markerStart = parsedStyle.markerStart,
2532
+ markerEnd = parsedStyle.markerEnd,
2533
+ markerStartOffset = parsedStyle.markerStartOffset,
2534
+ markerEndOffset = parsedStyle.markerEndOffset;
2535
+ var points = parsedStyle.points.points;
2536
+ var length = points.length;
2537
+ var x1 = points[0][0];
2538
+ var y1 = points[0][1];
2539
+ var x2 = points[length - 1][0];
2540
+ var y2 = points[length - 1][1];
2541
+ var startOffsetX = 0;
2542
+ var startOffsetY = 0;
2543
+ var endOffsetX = 0;
2544
+ var endOffsetY = 0;
2545
+ var rad = 0;
2546
+ var x;
2547
+ var y;
2548
+ if (markerStart && isDisplayObject(markerStart) && markerStartOffset) {
2549
+ x = points[1][0] - points[0][0];
2550
+ y = points[1][1] - points[0][1];
2551
+ rad = Math.atan2(y, x);
2552
+ startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
2553
+ startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
2554
+ }
2555
+ if (markerEnd && isDisplayObject(markerEnd) && markerEndOffset) {
2556
+ x = points[length - 2][0] - points[length - 1][0];
2557
+ y = points[length - 2][1] - points[length - 1][1];
2558
+ rad = Math.atan2(y, x);
2559
+ endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
2560
+ endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
2561
+ }
2562
+ context.moveTo(x1 + startOffsetX, y1 + startOffsetY);
2563
+ for (var i = 1; i < length - 1; i++) {
2564
+ var point = points[i];
2565
+ context.lineTo(point[0], point[1]);
2566
+ }
2567
+ context.lineTo(x2 + endOffsetX, y2 + endOffsetY);
2568
+ }
2569
+
2570
+ function generatePath(context, parsedStyle) {
2571
+ var _parsedStyle$x = parsedStyle.x,
2572
+ x = _parsedStyle$x === void 0 ? 0 : _parsedStyle$x,
2573
+ _parsedStyle$y = parsedStyle.y,
2574
+ y = _parsedStyle$y === void 0 ? 0 : _parsedStyle$y,
2575
+ radius = parsedStyle.radius,
2576
+ width = parsedStyle.width,
2577
+ height = parsedStyle.height;
2578
+ var w = width;
2579
+ var h = height;
2580
+ var hasRadius = radius && radius.some(function (r) {
2581
+ return r !== 0;
2582
+ });
2583
+ if (!hasRadius) {
2584
+ // Canvas support negative width/height of rect
2585
+ context.rect(x, y, w, h);
2586
+ } else {
2587
+ var signX = width > 0 ? 1 : -1;
2588
+ var signY = height > 0 ? 1 : -1;
2589
+ var sweepFlag = signX + signY === 0;
2590
+ var _radius$map = radius.map(function (r) {
2591
+ return clamp(r, 0, Math.min(Math.abs(w) / 2, Math.abs(h) / 2));
2592
+ }),
2593
+ _radius$map2 = _slicedToArray(_radius$map, 4),
2594
+ tlr = _radius$map2[0],
2595
+ trr = _radius$map2[1],
2596
+ brr = _radius$map2[2],
2597
+ blr = _radius$map2[3];
2598
+ context.moveTo(signX * tlr + x, y);
2599
+ context.lineTo(w - signX * trr + x, y);
2600
+ if (trr !== 0) {
2601
+ context.arc(w - signX * trr + x, signY * trr + y, trr, -signY * Math.PI / 2, signX > 0 ? 0 : Math.PI, sweepFlag);
2602
+ }
2603
+ context.lineTo(w + x, h - signY * brr + y);
2604
+ if (brr !== 0) {
2605
+ context.arc(w - signX * brr + x, h - signY * brr + y, brr, signX > 0 ? 0 : Math.PI, signY > 0 ? Math.PI / 2 : 1.5 * Math.PI, sweepFlag);
2606
+ }
2607
+ context.lineTo(signX * blr + x, h + y);
2608
+ if (blr !== 0) {
2609
+ context.arc(signX * blr + x, h - signY * blr + y, blr, signY > 0 ? Math.PI / 2 : -Math.PI / 2, signX > 0 ? Math.PI : 0, sweepFlag);
2610
+ }
2611
+ context.lineTo(x, signY * tlr + y);
2612
+ if (tlr !== 0) {
2613
+ context.arc(signX * tlr + x, signY * tlr + y, tlr, signX > 0 ? Math.PI : 0, signY > 0 ? Math.PI * 1.5 : Math.PI / 2, sweepFlag);
2614
+ }
2615
+ }
2616
+ }
2617
+
2618
+ var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
2619
+ function Plugin() {
2620
+ var _this;
2621
+ _classCallCheck(this, Plugin);
2622
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2623
+ args[_key] = arguments[_key];
2624
+ }
2625
+ _this = _callSuper(this, Plugin, [].concat(args));
2626
+ _this.name = 'canvas-path-generator';
2627
+ return _this;
2628
+ }
2629
+ _inherits(Plugin, _AbstractRendererPlug);
2630
+ return _createClass(Plugin, [{
2631
+ key: "init",
2632
+ value: function init() {
2633
+ var _pathGeneratorFactory;
2634
+ var pathGeneratorFactory = (_pathGeneratorFactory = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_pathGeneratorFactory, Shape.CIRCLE, generatePath$6), Shape.ELLIPSE, generatePath$5), Shape.RECT, generatePath), Shape.LINE, generatePath$4), Shape.POLYLINE, generatePath$1), Shape.POLYGON, generatePath$2), Shape.PATH, generatePath$3), Shape.TEXT, undefined), Shape.GROUP, undefined), Shape.IMAGE, undefined), _defineProperty(_defineProperty(_defineProperty(_pathGeneratorFactory, Shape.HTML, undefined), Shape.MESH, undefined), Shape.FRAGMENT, undefined));
2635
+
2636
+ // @ts-ignore
2637
+ this.context.pathGeneratorFactory = pathGeneratorFactory;
2638
+ }
2639
+ }, {
2640
+ key: "destroy",
2641
+ value: function destroy() {
2642
+ // @ts-ignore
2643
+ delete this.context.pathGeneratorFactory;
2644
+ }
2645
+ }]);
2646
+ }(AbstractRendererPlugin);
2647
+
2648
+ var index = /*#__PURE__*/Object.freeze({
2649
+ __proto__: null,
2650
+ Plugin: Plugin
2651
+ });
29
2652
 
30
2653
  var Canvas2DContextService = /*#__PURE__*/function () {
31
2654
  function Canvas2DContextService(context) {
@@ -183,12 +2806,12 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
183
2806
  // register Canvas2DContext
184
2807
  _this.registerPlugin(new ContextRegisterPlugin());
185
2808
  _this.registerPlugin(new ImageLoader.Plugin());
186
- _this.registerPlugin(new CanvasPathGenerator.Plugin());
2809
+ _this.registerPlugin(new Plugin());
187
2810
  // enable rendering with Canvas2D API
188
- _this.registerPlugin(new CanvasRenderer.Plugin());
2811
+ _this.registerPlugin(new Plugin$2());
189
2812
  _this.registerPlugin(new DomInteraction.Plugin());
190
2813
  // enable picking with Canvas2D API
191
- _this.registerPlugin(new CanvasPicker.Plugin());
2814
+ _this.registerPlugin(new Plugin$1());
192
2815
 
193
2816
  // render HTML component
194
2817
  _this.registerPlugin(new HTMLRenderer.Plugin());
@@ -198,5 +2821,5 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
198
2821
  return _createClass(Renderer);
199
2822
  }(AbstractRenderer);
200
2823
 
201
- export { Renderer };
2824
+ export { index as CanvasPathGenerator, index$1 as CanvasPicker, index$2 as CanvasRenderer, Renderer };
202
2825
  //# sourceMappingURL=index.esm.js.map