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