@antv/g-canvas 1.5.2 → 1.6.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.
package/dist/index.umd.js CHANGED
@@ -1,7 +1,7 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@antv/g')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', '@antv/g'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.G = global.G || {}, global.G.ImageExporter = {}), global.window.G));
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.G = global.G || {}, global.G.Canvas2D = {}), global.window.G));
5
5
  }(this, (function (exports, g) { 'use strict';
6
6
 
7
7
  function _regeneratorRuntime() {
@@ -400,6 +400,21 @@
400
400
  return _setPrototypeOf(o, p);
401
401
  }
402
402
 
403
+ function _inheritsLoose$1(subClass, superClass) {
404
+ subClass.prototype = Object.create(superClass.prototype);
405
+ subClass.prototype.constructor = subClass;
406
+
407
+ _setPrototypeOf$1(subClass, superClass);
408
+ }
409
+
410
+ function _setPrototypeOf$1(o, p) {
411
+ _setPrototypeOf$1 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
412
+ o.__proto__ = p;
413
+ return o;
414
+ };
415
+ return _setPrototypeOf$1(o, p);
416
+ }
417
+
403
418
  var PathGeneratorFactory = g.Syringe.defineToken('PathGeneratorFactory');
404
419
  var PathGenerator = g.Syringe.defineToken('PathGenerator');
405
420
 
@@ -637,23 +652,33 @@
637
652
  });
638
653
  });
639
654
 
640
- var Plugin = /*#__PURE__*/function () {
655
+ var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
656
+ _inheritsLoose$1(Plugin, _AbstractRendererPlug);
657
+
641
658
  function Plugin() {
642
- this.name = 'canvas-path-generator';
659
+ var _this;
660
+
661
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
662
+ args[_key] = arguments[_key];
663
+ }
664
+
665
+ _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
666
+ _this.name = 'canvas-path-generator';
667
+ return _this;
643
668
  }
644
669
 
645
670
  var _proto = Plugin.prototype;
646
671
 
647
- _proto.init = function init(container) {
648
- container.load(containerModule, true);
672
+ _proto.init = function init() {
673
+ this.container.load(containerModule, true);
649
674
  };
650
675
 
651
- _proto.destroy = function destroy(container) {
652
- container.unload(containerModule);
676
+ _proto.destroy = function destroy() {
677
+ this.container.unload(containerModule);
653
678
  };
654
679
 
655
680
  return Plugin;
656
- }();
681
+ }(g.AbstractRendererPlugin);
657
682
 
658
683
  var index_esm = /*#__PURE__*/Object.freeze({
659
684
  __proto__: null,
@@ -1073,6 +1098,21 @@
1073
1098
  });
1074
1099
  };
1075
1100
  }
1101
+
1102
+ function _inheritsLoose$2(subClass, superClass) {
1103
+ subClass.prototype = Object.create(superClass.prototype);
1104
+ subClass.prototype.constructor = subClass;
1105
+
1106
+ _setPrototypeOf$2(subClass, superClass);
1107
+ }
1108
+
1109
+ function _setPrototypeOf$2(o, p) {
1110
+ _setPrototypeOf$2 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
1111
+ o.__proto__ = p;
1112
+ return o;
1113
+ };
1114
+ return _setPrototypeOf$2(o, p);
1115
+ }
1076
1116
  /**
1077
1117
  * Common utilities
1078
1118
  * @module glMatrix
@@ -2524,192 +2564,39 @@
2524
2564
  register(CanvasPickerPlugin);
2525
2565
  });
2526
2566
 
2527
- var Plugin$1 = /*#__PURE__*/function () {
2567
+ var Plugin$1 = /*#__PURE__*/function (_AbstractRendererPlug) {
2568
+ _inheritsLoose$2(Plugin, _AbstractRendererPlug);
2569
+
2528
2570
  function Plugin() {
2529
- this.name = 'canvas-picker';
2571
+ var _this;
2572
+
2573
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2574
+ args[_key] = arguments[_key];
2575
+ }
2576
+
2577
+ _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
2578
+ _this.name = 'canvas-picker';
2579
+ return _this;
2530
2580
  }
2531
2581
 
2532
2582
  var _proto = Plugin.prototype;
2533
2583
 
2534
- _proto.init = function init(container) {
2535
- container.load(containerModule$1, true);
2584
+ _proto.init = function init() {
2585
+ this.container.load(containerModule$1, true);
2536
2586
  };
2537
2587
 
2538
- _proto.destroy = function destroy(container) {
2539
- container.unload(containerModule$1);
2588
+ _proto.destroy = function destroy() {
2589
+ this.container.unload(containerModule$1);
2540
2590
  };
2541
2591
 
2542
2592
  return Plugin;
2543
- }();
2593
+ }(g.AbstractRendererPlugin);
2544
2594
 
2545
2595
  var index_esm$1 = /*#__PURE__*/Object.freeze({
2546
2596
  __proto__: null,
2547
2597
  Plugin: Plugin$1
2548
2598
  });
2549
2599
 
2550
- var ImagePool = /*#__PURE__*/function () {
2551
- function ImagePool() {
2552
- this.imageCache = {};
2553
- this.gradientCache = {};
2554
- this.patternCache = {};
2555
- this.canvasConfig = void 0;
2556
- }
2557
-
2558
- var _proto = ImagePool.prototype;
2559
-
2560
- _proto.getImageSync = function getImageSync(src, callback) {
2561
- if (!this.imageCache[src]) {
2562
- this.getOrCreateImage(src).then(function () {
2563
- if (callback) {
2564
- callback();
2565
- }
2566
- });
2567
- }
2568
-
2569
- return this.imageCache[src];
2570
- };
2571
-
2572
- _proto.getOrCreateImage = function getOrCreateImage(src) {
2573
- var _this = this;
2574
-
2575
- if (this.imageCache[src]) {
2576
- return Promise.resolve(this.imageCache[src]);
2577
- } // @see https://github.com/antvis/g/issues/938
2578
-
2579
-
2580
- var createImage = this.canvasConfig.createImage;
2581
- return new Promise(function (resolve, reject) {
2582
- var image;
2583
-
2584
- if (createImage) {
2585
- image = createImage(src);
2586
- } else if (g.isBrowser) {
2587
- image = new window.Image();
2588
- }
2589
-
2590
- if (image) {
2591
- image.onload = function () {
2592
- resolve(image);
2593
- };
2594
-
2595
- image.onerror = function (ev) {
2596
- reject(ev);
2597
- };
2598
-
2599
- image.crossOrigin = 'Anonymous';
2600
- image.src = src;
2601
- _this.imageCache[src] = image;
2602
- }
2603
- });
2604
- };
2605
-
2606
- _proto.getOrCreatePatternSync = function getOrCreatePatternSync(pattern, context, callback) {
2607
- var patternKey = this.generatePatternKey(pattern);
2608
-
2609
- if (patternKey && this.patternCache[patternKey]) {
2610
- return this.patternCache[patternKey];
2611
- }
2612
-
2613
- var image = pattern.image,
2614
- repetition = pattern.repetition;
2615
- var src; // Image URL
2616
-
2617
- if (g.isString(image)) {
2618
- src = this.getImageSync(image, callback);
2619
- } else {
2620
- src = image;
2621
- } // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
2622
-
2623
-
2624
- var canvasPattern = src && context.createPattern(src, repetition);
2625
-
2626
- if (patternKey && canvasPattern) {
2627
- this.patternCache[patternKey] = canvasPattern;
2628
- }
2629
-
2630
- return canvasPattern;
2631
- };
2632
-
2633
- _proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
2634
- var key = this.generateGradientKey(params); // @ts-ignore
2635
-
2636
- var type = params.type,
2637
- steps = params.steps,
2638
- width = params.width,
2639
- height = params.height,
2640
- angle = params.angle,
2641
- cx = params.cx,
2642
- cy = params.cy;
2643
-
2644
- if (this.gradientCache[key]) {
2645
- return this.gradientCache[key];
2646
- }
2647
-
2648
- var gradient = null;
2649
-
2650
- if (type === g.GradientType.LinearGradient) {
2651
- var _computeLinearGradien = g.computeLinearGradient(width, height, angle),
2652
- x1 = _computeLinearGradien.x1,
2653
- y1 = _computeLinearGradien.y1,
2654
- x2 = _computeLinearGradien.x2,
2655
- y2 = _computeLinearGradien.y2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
2656
-
2657
-
2658
- gradient = context.createLinearGradient(x1, y1, x2, y2);
2659
- } else if (type === g.GradientType.RadialGradient) {
2660
- var _computeRadialGradien = g.computeRadialGradient(width, height, cx, cy),
2661
- x = _computeRadialGradien.x,
2662
- y = _computeRadialGradien.y,
2663
- r = _computeRadialGradien.r; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
2664
-
2665
-
2666
- gradient = context.createRadialGradient(x, y, 0, x, y, r);
2667
- }
2668
-
2669
- if (gradient) {
2670
- steps.forEach(function (_ref) {
2671
- var _gradient;
2672
-
2673
- var offset = _ref[0],
2674
- color = _ref[1];
2675
- (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset, color);
2676
- });
2677
- this.gradientCache[key] = gradient;
2678
- }
2679
-
2680
- return this.gradientCache[key];
2681
- };
2682
-
2683
- _proto.generateGradientKey = function generateGradientKey(params) {
2684
- // @ts-ignore
2685
- var type = params.type,
2686
- width = params.width,
2687
- height = params.height,
2688
- steps = params.steps,
2689
- angle = params.angle,
2690
- cx = params.cx,
2691
- cy = params.cy;
2692
- return "gradient-" + type + "-" + (angle || 0) + "-" + (cx || 0) + "-" + (cy || 0) + "-" + width + "-" + height + "-" + steps.map(function (step) {
2693
- return step.join('');
2694
- }).join('-');
2695
- };
2696
-
2697
- _proto.generatePatternKey = function generatePatternKey(pattern) {
2698
- var image = pattern.image,
2699
- repetition = pattern.repetition; // only generate cache for Image
2700
-
2701
- if (g.isString(image)) {
2702
- return "pattern-" + image + "-" + repetition;
2703
- }
2704
- };
2705
-
2706
- return ImagePool;
2707
- }();
2708
-
2709
- __decorate([g.inject(g.CanvasConfig), __metadata("design:type", Object)], ImagePool.prototype, "canvasConfig", void 0);
2710
-
2711
- ImagePool = __decorate([g.singleton()], ImagePool);
2712
-
2713
2600
  function _regeneratorRuntime$2() {
2714
2601
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
2715
2602
  _regeneratorRuntime$2 = function _regeneratorRuntime() {
@@ -3096,6 +2983,184 @@
3096
2983
  };
3097
2984
  }
3098
2985
 
2986
+ function _inheritsLoose$3(subClass, superClass) {
2987
+ subClass.prototype = Object.create(superClass.prototype);
2988
+ subClass.prototype.constructor = subClass;
2989
+
2990
+ _setPrototypeOf$3(subClass, superClass);
2991
+ }
2992
+
2993
+ function _setPrototypeOf$3(o, p) {
2994
+ _setPrototypeOf$3 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
2995
+ o.__proto__ = p;
2996
+ return o;
2997
+ };
2998
+ return _setPrototypeOf$3(o, p);
2999
+ }
3000
+
3001
+ var ImagePool = /*#__PURE__*/function () {
3002
+ function ImagePool() {
3003
+ this.imageCache = {};
3004
+ this.gradientCache = {};
3005
+ this.patternCache = {};
3006
+ this.canvasConfig = void 0;
3007
+ }
3008
+
3009
+ var _proto = ImagePool.prototype;
3010
+
3011
+ _proto.getImageSync = function getImageSync(src, callback) {
3012
+ if (!this.imageCache[src]) {
3013
+ this.getOrCreateImage(src).then(function () {
3014
+ if (callback) {
3015
+ callback();
3016
+ }
3017
+ });
3018
+ }
3019
+
3020
+ return this.imageCache[src];
3021
+ };
3022
+
3023
+ _proto.getOrCreateImage = function getOrCreateImage(src) {
3024
+ var _this = this;
3025
+
3026
+ if (this.imageCache[src]) {
3027
+ return Promise.resolve(this.imageCache[src]);
3028
+ } // @see https://github.com/antvis/g/issues/938
3029
+
3030
+
3031
+ var createImage = this.canvasConfig.createImage;
3032
+ return new Promise(function (resolve, reject) {
3033
+ var image;
3034
+
3035
+ if (createImage) {
3036
+ image = createImage(src);
3037
+ } else if (g.isBrowser) {
3038
+ image = new window.Image();
3039
+ }
3040
+
3041
+ if (image) {
3042
+ image.onload = function () {
3043
+ resolve(image);
3044
+ };
3045
+
3046
+ image.onerror = function (ev) {
3047
+ reject(ev);
3048
+ };
3049
+
3050
+ image.crossOrigin = 'Anonymous';
3051
+ image.src = src;
3052
+ _this.imageCache[src] = image;
3053
+ }
3054
+ });
3055
+ };
3056
+
3057
+ _proto.getOrCreatePatternSync = function getOrCreatePatternSync(pattern, context, callback) {
3058
+ var patternKey = this.generatePatternKey(pattern);
3059
+
3060
+ if (patternKey && this.patternCache[patternKey]) {
3061
+ return this.patternCache[patternKey];
3062
+ }
3063
+
3064
+ var image = pattern.image,
3065
+ repetition = pattern.repetition;
3066
+ var src; // Image URL
3067
+
3068
+ if (g.isString(image)) {
3069
+ src = this.getImageSync(image, callback);
3070
+ } else {
3071
+ src = image;
3072
+ } // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
3073
+
3074
+
3075
+ var canvasPattern = src && context.createPattern(src, repetition);
3076
+
3077
+ if (patternKey && canvasPattern) {
3078
+ this.patternCache[patternKey] = canvasPattern;
3079
+ }
3080
+
3081
+ return canvasPattern;
3082
+ };
3083
+
3084
+ _proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
3085
+ var key = this.generateGradientKey(params); // @ts-ignore
3086
+
3087
+ var type = params.type,
3088
+ steps = params.steps,
3089
+ width = params.width,
3090
+ height = params.height,
3091
+ angle = params.angle,
3092
+ cx = params.cx,
3093
+ cy = params.cy;
3094
+
3095
+ if (this.gradientCache[key]) {
3096
+ return this.gradientCache[key];
3097
+ }
3098
+
3099
+ var gradient = null;
3100
+
3101
+ if (type === g.GradientType.LinearGradient) {
3102
+ var _computeLinearGradien = g.computeLinearGradient(width, height, angle),
3103
+ x1 = _computeLinearGradien.x1,
3104
+ y1 = _computeLinearGradien.y1,
3105
+ x2 = _computeLinearGradien.x2,
3106
+ y2 = _computeLinearGradien.y2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
3107
+
3108
+
3109
+ gradient = context.createLinearGradient(x1, y1, x2, y2);
3110
+ } else if (type === g.GradientType.RadialGradient) {
3111
+ var _computeRadialGradien = g.computeRadialGradient(width, height, cx, cy),
3112
+ x = _computeRadialGradien.x,
3113
+ y = _computeRadialGradien.y,
3114
+ r = _computeRadialGradien.r; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
3115
+
3116
+
3117
+ gradient = context.createRadialGradient(x, y, 0, x, y, r);
3118
+ }
3119
+
3120
+ if (gradient) {
3121
+ steps.forEach(function (_ref) {
3122
+ var _gradient;
3123
+
3124
+ var offset = _ref[0],
3125
+ color = _ref[1];
3126
+ (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset, color);
3127
+ });
3128
+ this.gradientCache[key] = gradient;
3129
+ }
3130
+
3131
+ return this.gradientCache[key];
3132
+ };
3133
+
3134
+ _proto.generateGradientKey = function generateGradientKey(params) {
3135
+ // @ts-ignore
3136
+ var type = params.type,
3137
+ width = params.width,
3138
+ height = params.height,
3139
+ steps = params.steps,
3140
+ angle = params.angle,
3141
+ cx = params.cx,
3142
+ cy = params.cy;
3143
+ return "gradient-" + type + "-" + (angle || 0) + "-" + (cx || 0) + "-" + (cy || 0) + "-" + width + "-" + height + "-" + steps.map(function (step) {
3144
+ return step.join('');
3145
+ }).join('-');
3146
+ };
3147
+
3148
+ _proto.generatePatternKey = function generatePatternKey(pattern) {
3149
+ var image = pattern.image,
3150
+ repetition = pattern.repetition; // only generate cache for Image
3151
+
3152
+ if (g.isString(image)) {
3153
+ return "pattern-" + image + "-" + repetition;
3154
+ }
3155
+ };
3156
+
3157
+ return ImagePool;
3158
+ }();
3159
+
3160
+ __decorate([g.inject(g.CanvasConfig), __metadata("design:type", Object)], ImagePool.prototype, "canvasConfig", void 0);
3161
+
3162
+ ImagePool = __decorate([g.singleton()], ImagePool);
3163
+
3099
3164
  var _class$1;
3100
3165
 
3101
3166
  var LoadImagePlugin_1;
@@ -3184,23 +3249,33 @@
3184
3249
  register(LoadImagePlugin);
3185
3250
  });
3186
3251
 
3187
- var Plugin$2 = /*#__PURE__*/function () {
3252
+ var Plugin$2 = /*#__PURE__*/function (_AbstractRendererPlug) {
3253
+ _inheritsLoose$3(Plugin, _AbstractRendererPlug);
3254
+
3188
3255
  function Plugin() {
3189
- this.name = 'image-loader';
3256
+ var _this;
3257
+
3258
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3259
+ args[_key] = arguments[_key];
3260
+ }
3261
+
3262
+ _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
3263
+ _this.name = 'image-loader';
3264
+ return _this;
3190
3265
  }
3191
3266
 
3192
3267
  var _proto = Plugin.prototype;
3193
3268
 
3194
- _proto.init = function init(container) {
3195
- container.load(containerModule$2, true);
3269
+ _proto.init = function init() {
3270
+ this.container.load(containerModule$2, true);
3196
3271
  };
3197
3272
 
3198
- _proto.destroy = function destroy(container) {
3199
- container.unload(containerModule$2);
3273
+ _proto.destroy = function destroy() {
3274
+ this.container.unload(containerModule$2);
3200
3275
  };
3201
3276
 
3202
3277
  return Plugin;
3203
- }();
3278
+ }(g.AbstractRendererPlugin);
3204
3279
 
3205
3280
  var index_esm$2 = /*#__PURE__*/Object.freeze({
3206
3281
  __proto__: null,
@@ -3611,19 +3686,19 @@
3611
3686
  return _extends.apply(this, arguments);
3612
3687
  }
3613
3688
 
3614
- function _inheritsLoose$1(subClass, superClass) {
3689
+ function _inheritsLoose$4(subClass, superClass) {
3615
3690
  subClass.prototype = Object.create(superClass.prototype);
3616
3691
  subClass.prototype.constructor = subClass;
3617
3692
 
3618
- _setPrototypeOf$1(subClass, superClass);
3693
+ _setPrototypeOf$4(subClass, superClass);
3619
3694
  }
3620
3695
 
3621
- function _setPrototypeOf$1(o, p) {
3622
- _setPrototypeOf$1 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
3696
+ function _setPrototypeOf$4(o, p) {
3697
+ _setPrototypeOf$4 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
3623
3698
  o.__proto__ = p;
3624
3699
  return o;
3625
3700
  };
3626
- return _setPrototypeOf$1(o, p);
3701
+ return _setPrototypeOf$4(o, p);
3627
3702
  }
3628
3703
  /**
3629
3704
  * Common utilities
@@ -3895,6 +3970,28 @@
3895
3970
  out[2] = z;
3896
3971
  return out;
3897
3972
  }
3973
+ /**
3974
+ * Transforms the vec3 with a mat4.
3975
+ * 4th vector component is implicitly '1'
3976
+ *
3977
+ * @param {vec3} out the receiving vector
3978
+ * @param {ReadonlyVec3} a the vector to transform
3979
+ * @param {ReadonlyMat4} m matrix to transform with
3980
+ * @returns {vec3} out
3981
+ */
3982
+
3983
+
3984
+ function transformMat4$1(out, a, m) {
3985
+ var x = a[0],
3986
+ y = a[1],
3987
+ z = a[2];
3988
+ var w = m[3] * x + m[7] * y + m[11] * z + m[15];
3989
+ w = w || 1.0;
3990
+ out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
3991
+ out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
3992
+ out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
3993
+ return out;
3994
+ }
3898
3995
  /**
3899
3996
  * Perform some operation over an array of vec3s.
3900
3997
  *
@@ -4345,7 +4442,7 @@
4345
4442
  DefaultRenderer = __decorate([g.singleton()], DefaultRenderer);
4346
4443
 
4347
4444
  var RectRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4348
- _inheritsLoose$1(RectRenderer, _DefaultRenderer);
4445
+ _inheritsLoose$4(RectRenderer, _DefaultRenderer);
4349
4446
 
4350
4447
  function RectRenderer() {
4351
4448
  return _DefaultRenderer.apply(this, arguments) || this;
@@ -4359,7 +4456,7 @@
4359
4456
  })], RectRenderer);
4360
4457
 
4361
4458
  var CircleRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4362
- _inheritsLoose$1(CircleRenderer, _DefaultRenderer);
4459
+ _inheritsLoose$4(CircleRenderer, _DefaultRenderer);
4363
4460
 
4364
4461
  function CircleRenderer() {
4365
4462
  return _DefaultRenderer.apply(this, arguments) || this;
@@ -4373,7 +4470,7 @@
4373
4470
  })], CircleRenderer);
4374
4471
 
4375
4472
  var EllipseRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4376
- _inheritsLoose$1(EllipseRenderer, _DefaultRenderer);
4473
+ _inheritsLoose$4(EllipseRenderer, _DefaultRenderer);
4377
4474
 
4378
4475
  function EllipseRenderer() {
4379
4476
  return _DefaultRenderer.apply(this, arguments) || this;
@@ -4387,7 +4484,7 @@
4387
4484
  })], EllipseRenderer);
4388
4485
 
4389
4486
  var LineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4390
- _inheritsLoose$1(LineRenderer, _DefaultRenderer);
4487
+ _inheritsLoose$4(LineRenderer, _DefaultRenderer);
4391
4488
 
4392
4489
  function LineRenderer() {
4393
4490
  return _DefaultRenderer.apply(this, arguments) || this;
@@ -4401,7 +4498,7 @@
4401
4498
  })], LineRenderer);
4402
4499
 
4403
4500
  var PolylineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4404
- _inheritsLoose$1(PolylineRenderer, _DefaultRenderer);
4501
+ _inheritsLoose$4(PolylineRenderer, _DefaultRenderer);
4405
4502
 
4406
4503
  function PolylineRenderer() {
4407
4504
  return _DefaultRenderer.apply(this, arguments) || this;
@@ -4415,7 +4512,7 @@
4415
4512
  })], PolylineRenderer);
4416
4513
 
4417
4514
  var PolygonRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4418
- _inheritsLoose$1(PolygonRenderer, _DefaultRenderer);
4515
+ _inheritsLoose$4(PolygonRenderer, _DefaultRenderer);
4419
4516
 
4420
4517
  function PolygonRenderer() {
4421
4518
  return _DefaultRenderer.apply(this, arguments) || this;
@@ -4429,7 +4526,7 @@
4429
4526
  })], PolygonRenderer);
4430
4527
 
4431
4528
  var PathRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4432
- _inheritsLoose$1(PathRenderer, _DefaultRenderer);
4529
+ _inheritsLoose$4(PathRenderer, _DefaultRenderer);
4433
4530
 
4434
4531
  function PathRenderer() {
4435
4532
  return _DefaultRenderer.apply(this, arguments) || this;
@@ -4441,6 +4538,7 @@
4441
4538
  PathRenderer = __decorate([g.singleton({
4442
4539
  token: PathRendererContribution
4443
4540
  })], PathRenderer);
4541
+ var CanvasRendererPluginOptions = g.Syringe.defineToken('CanvasRendererPluginOptions');
4444
4542
 
4445
4543
  var _class$2;
4446
4544
 
@@ -4462,6 +4560,7 @@
4462
4560
  this.styleRendererFactory = void 0;
4463
4561
  this.styleRendererFactoryCache = {};
4464
4562
  this.displayObjectPool = void 0;
4563
+ this.canvasRendererPluginOptions = void 0;
4465
4564
  this.rBush = void 0;
4466
4565
  this.removedRBushNodeAABBs = [];
4467
4566
  this.renderQueue = [];
@@ -4478,6 +4577,8 @@
4478
4577
  _proto.apply = function apply(renderingService) {
4479
4578
  var _this = this;
4480
4579
 
4580
+ var canvas = this.renderingContext.root.ownerDocument.defaultView;
4581
+
4481
4582
  var handleUnmounted = function handleUnmounted(e) {
4482
4583
  var object = e.target; // remove r-bush node
4483
4584
  // @ts-ignore
@@ -4540,19 +4641,22 @@
4540
4641
 
4541
4642
  var _this$canvasConfig2 = _this.canvasConfig,
4542
4643
  width = _this$canvasConfig2.width,
4543
- height = _this$canvasConfig2.height; // some heuristic conditions such as 80% object changed
4644
+ height = _this$canvasConfig2.height;
4645
+ var _this$canvasRendererP = _this.canvasRendererPluginOptions,
4646
+ dirtyObjectNumThreshold = _this$canvasRendererP.dirtyObjectNumThreshold,
4647
+ dirtyObjectRatioThreshold = _this$canvasRendererP.dirtyObjectRatioThreshold; // some heuristic conditions such as 80% object changed
4544
4648
 
4545
4649
  var _renderingService$get = renderingService.getStats(),
4546
4650
  total = _renderingService$get.total,
4547
4651
  rendered = _renderingService$get.rendered;
4548
4652
 
4549
4653
  var ratio = rendered / total;
4550
- _this.clearFullScreen = renderingService.disableDirtyRectangleRendering() || rendered > 100 && ratio > 0.8;
4654
+ _this.clearFullScreen = renderingService.disableDirtyRectangleRendering() || rendered > dirtyObjectNumThreshold && ratio > dirtyObjectRatioThreshold;
4551
4655
 
4552
4656
  if (context) {
4553
- if (_this.clearFullScreen) {
4554
- context.resetTransform();
4657
+ context.resetTransform();
4555
4658
 
4659
+ if (_this.clearFullScreen) {
4556
4660
  _this.clearRect(context, 0, 0, width * dpr, height * dpr);
4557
4661
  }
4558
4662
  }
@@ -4567,7 +4671,10 @@
4567
4671
  if (_this.clearFullScreen) {
4568
4672
  _this.renderingContext.root.forEach(function (object) {
4569
4673
  if (object.isVisible() && !object.isCulled()) {
4570
- _this.renderDisplayObject(object, renderingService);
4674
+ _this.renderDisplayObject(object, renderingService); // if we did a full screen rendering last frame
4675
+
4676
+
4677
+ _this.saveDirtyAABB(object);
4571
4678
  }
4572
4679
  });
4573
4680
  } else {
@@ -4589,29 +4696,37 @@
4589
4696
  return;
4590
4697
  }
4591
4698
 
4592
- var _this$convertAABB2Rec = _this.convertAABB2Rect(dirtyRenderBounds),
4593
- x = _this$convertAABB2Rec.x,
4594
- y = _this$convertAABB2Rec.y,
4595
- width = _this$convertAABB2Rec.width,
4596
- height = _this$convertAABB2Rec.height; // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
4597
-
4598
-
4599
- context.setTransform(_this.vpMatrix[0], _this.vpMatrix[1], _this.vpMatrix[4], _this.vpMatrix[5], _this.vpMatrix[12], _this.vpMatrix[13]);
4699
+ var dirtyRect = _this.convertAABB2Rect(dirtyRenderBounds);
4700
+
4701
+ var x = dirtyRect.x,
4702
+ y = dirtyRect.y,
4703
+ width = dirtyRect.width,
4704
+ height = dirtyRect.height;
4705
+ var tl = transformMat4$1(_this.tmpVec3, fromValues$1(x, y, 0), _this.vpMatrix);
4706
+ var br = transformMat4$1(create$1$1(), fromValues$1(x + width, y + height, 0), _this.vpMatrix);
4707
+ var ix = Math.floor(tl[0]);
4708
+ var iy = Math.floor(tl[1]);
4709
+ var iwidth = Math.ceil(br[0] - tl[0]);
4710
+ var iheight = Math.ceil(br[1] - tl[1]);
4600
4711
  context.save();
4601
4712
 
4602
- _this.clearRect(context, x, y, width, height);
4713
+ _this.clearRect(context, ix, iy, iwidth, iheight);
4603
4714
 
4604
4715
  context.beginPath();
4605
- context.rect(x, y, width, height);
4606
- context.clip(); // draw dirty rectangle
4607
- // if (enableDirtyRectangleRenderingDebug) {
4608
- // context.lineWidth = 4;
4609
- // context.strokeStyle = `rgba(${Math.random() * 255}, ${Math.random() * 255}, ${
4610
- // Math.random() * 255
4611
- // }, 1)`;
4612
- // context.strokeRect(x, y, width, height);
4613
- // }
4614
- // search objects intersect with dirty rectangle
4716
+ context.rect(ix, iy, iwidth, iheight);
4717
+ context.clip(); // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
4718
+
4719
+ context.setTransform(_this.vpMatrix[0], _this.vpMatrix[1], _this.vpMatrix[4], _this.vpMatrix[5], _this.vpMatrix[12], _this.vpMatrix[13]); // draw dirty rectangle
4720
+
4721
+ var _this$canvasConfig$re = _this.canvasConfig.renderer.getConfig(),
4722
+ enableDirtyRectangleRenderingDebug = _this$canvasConfig$re.enableDirtyRectangleRenderingDebug;
4723
+
4724
+ if (enableDirtyRectangleRenderingDebug) {
4725
+ canvas.dispatchEvent(new g.CustomEvent(g.CanvasEvent.DIRTY_RECTANGLE, {
4726
+ dirtyRect: dirtyRect
4727
+ }));
4728
+ } // search objects intersect with dirty rectangle
4729
+
4615
4730
 
4616
4731
  var dirtyObjects = _this.searchDirtyObjects(dirtyRenderBounds); // do rendering
4617
4732
 
@@ -4642,12 +4757,9 @@
4642
4757
 
4643
4758
 
4644
4759
  _this.restoreStack = [];
4645
- _this.clearFullScreen = false;
4646
4760
  });
4647
4761
  renderingService.hooks.render.tap(CanvasRendererPlugin_1.tag, function (object) {
4648
- if (!_this.clearFullScreen && ( // basic shapes
4649
- object.nodeName !== g.Shape.GROUP && !object.isCustomElement || // should not ignore group since clipPath may affect its children
4650
- object.parsedStyle.clipPath)) {
4762
+ if (!_this.clearFullScreen) {
4651
4763
  // render at the end of frame
4652
4764
  _this.renderQueue.push(object);
4653
4765
  }
@@ -4655,6 +4767,7 @@
4655
4767
  };
4656
4768
 
4657
4769
  _proto.clearRect = function clearRect(context, x, y, width, height) {
4770
+ // clearRect is faster than fillRect @see https://stackoverflow.com/a/30830253
4658
4771
  context.clearRect(x, y, width, height);
4659
4772
  var background = this.canvasConfig.background;
4660
4773
 
@@ -4702,10 +4815,8 @@
4702
4815
 
4703
4816
  if (_generatePath) {
4704
4817
  context.save(); // save clip
4705
- // if (object.nodeName === Shape.GROUP || object.isCustomElement) {
4706
-
4707
- this.restoreStack.push(object); // }
4708
4818
 
4819
+ this.restoreStack.push(object);
4709
4820
  context.beginPath();
4710
4821
 
4711
4822
  _generatePath(context, clipPathShape.parsedStyle);
@@ -4770,6 +4881,7 @@
4770
4881
 
4771
4882
  _proto.mergeDirtyAABBs = function mergeDirtyAABBs(dirtyObjects) {
4772
4883
  // merge into a big AABB
4884
+ // TODO: skip descendant if ancestor is caculated, but compareNodePosition is really slow
4773
4885
  var aabb = new g.AABB();
4774
4886
  dirtyObjects.forEach(function (object) {
4775
4887
  var renderBounds = object.getRenderBounds();
@@ -4867,7 +4979,7 @@
4867
4979
  context.filter = object.style.filter;
4868
4980
  }
4869
4981
 
4870
- var hasShadow = !g.isNil(shadowColor) && shadowBlur.value > 0;
4982
+ var hasShadow = !g.isNil(shadowColor) && (shadowBlur === null || shadowBlur === void 0 ? void 0 : shadowBlur.value) > 0;
4871
4983
 
4872
4984
  if (hasShadow) {
4873
4985
  context.shadowColor = shadowColor.toString();
@@ -4948,6 +5060,8 @@
4948
5060
 
4949
5061
  __decorate([g.inject(g.DisplayObjectPool), __metadata("design:type", g.DisplayObjectPool)], CanvasRendererPlugin.prototype, "displayObjectPool", void 0);
4950
5062
 
5063
+ __decorate([g.inject(CanvasRendererPluginOptions), __metadata("design:type", Object)], CanvasRendererPlugin.prototype, "canvasRendererPluginOptions", void 0);
5064
+
4951
5065
  __decorate([g.inject(g.RBushRoot), __metadata("design:type", g.RBush)], CanvasRendererPlugin.prototype, "rBush", void 0);
4952
5066
 
4953
5067
  CanvasRendererPlugin = CanvasRendererPlugin_1 = __decorate([g.singleton({
@@ -4983,23 +5097,42 @@
4983
5097
  register(CanvasRendererPlugin);
4984
5098
  });
4985
5099
 
4986
- var Plugin$3 = /*#__PURE__*/function () {
4987
- function Plugin() {
4988
- this.name = 'canvas-renderer';
5100
+ var Plugin$3 = /*#__PURE__*/function (_AbstractRendererPlug) {
5101
+ _inheritsLoose$4(Plugin, _AbstractRendererPlug);
5102
+
5103
+ function Plugin(options) {
5104
+ var _this;
5105
+
5106
+ if (options === void 0) {
5107
+ options = {};
5108
+ }
5109
+
5110
+ _this = _AbstractRendererPlug.call(this) || this;
5111
+ _this.options = void 0;
5112
+ _this.name = 'canvas-renderer';
5113
+ _this.options = options;
5114
+ return _this;
4989
5115
  }
4990
5116
 
4991
5117
  var _proto = Plugin.prototype;
4992
5118
 
4993
- _proto.init = function init(container) {
4994
- container.load(containerModule$3, true);
5119
+ _proto.init = function init() {
5120
+ this.container.register(CanvasRendererPluginOptions, {
5121
+ useValue: _extends({
5122
+ dirtyObjectNumThreshold: 500,
5123
+ dirtyObjectRatioThreshold: 0.8
5124
+ }, this.options)
5125
+ });
5126
+ this.container.load(containerModule$3, true);
4995
5127
  };
4996
5128
 
4997
- _proto.destroy = function destroy(container) {
4998
- container.unload(containerModule$3);
5129
+ _proto.destroy = function destroy() {
5130
+ this.container.unload(containerModule$3);
5131
+ this.container.remove(CanvasRendererPluginOptions);
4999
5132
  };
5000
5133
 
5001
5134
  return Plugin;
5002
- }();
5135
+ }(g.AbstractRendererPlugin);
5003
5136
 
5004
5137
  var index_esm$3 = /*#__PURE__*/Object.freeze({
5005
5138
  __proto__: null,
@@ -5411,6 +5544,21 @@
5411
5544
  };
5412
5545
  }
5413
5546
 
5547
+ function _inheritsLoose$5(subClass, superClass) {
5548
+ subClass.prototype = Object.create(superClass.prototype);
5549
+ subClass.prototype.constructor = subClass;
5550
+
5551
+ _setPrototypeOf$5(subClass, superClass);
5552
+ }
5553
+
5554
+ function _setPrototypeOf$5(o, p) {
5555
+ _setPrototypeOf$5 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
5556
+ o.__proto__ = p;
5557
+ return o;
5558
+ };
5559
+ return _setPrototypeOf$5(o, p);
5560
+ }
5561
+
5414
5562
  var _class$3;
5415
5563
 
5416
5564
  var DOMInteractionPlugin_1;
@@ -5577,23 +5725,33 @@
5577
5725
  register(DOMInteractionPlugin);
5578
5726
  });
5579
5727
 
5580
- var Plugin$4 = /*#__PURE__*/function () {
5728
+ var Plugin$4 = /*#__PURE__*/function (_AbstractRendererPlug) {
5729
+ _inheritsLoose$5(Plugin, _AbstractRendererPlug);
5730
+
5581
5731
  function Plugin() {
5582
- this.name = 'dom-interaction';
5732
+ var _this;
5733
+
5734
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5735
+ args[_key] = arguments[_key];
5736
+ }
5737
+
5738
+ _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
5739
+ _this.name = 'dom-interaction';
5740
+ return _this;
5583
5741
  }
5584
5742
 
5585
5743
  var _proto = Plugin.prototype;
5586
5744
 
5587
- _proto.init = function init(container) {
5588
- container.load(containerModule$4, true);
5745
+ _proto.init = function init() {
5746
+ this.container.load(containerModule$4, true);
5589
5747
  };
5590
5748
 
5591
- _proto.destroy = function destroy(container) {
5592
- container.unload(containerModule$4);
5749
+ _proto.destroy = function destroy() {
5750
+ this.container.unload(containerModule$4);
5593
5751
  };
5594
5752
 
5595
5753
  return Plugin;
5596
- }();
5754
+ }(g.AbstractRendererPlugin);
5597
5755
 
5598
5756
  var index_esm$4 = /*#__PURE__*/Object.freeze({
5599
5757
  __proto__: null,
@@ -5986,6 +6144,21 @@
5986
6144
  };
5987
6145
  }
5988
6146
 
6147
+ function _inheritsLoose$6(subClass, superClass) {
6148
+ subClass.prototype = Object.create(superClass.prototype);
6149
+ subClass.prototype.constructor = subClass;
6150
+
6151
+ _setPrototypeOf$6(subClass, superClass);
6152
+ }
6153
+
6154
+ function _setPrototypeOf$6(o, p) {
6155
+ _setPrototypeOf$6 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
6156
+ o.__proto__ = p;
6157
+ return o;
6158
+ };
6159
+ return _setPrototypeOf$6(o, p);
6160
+ }
6161
+
5989
6162
  var _class$4;
5990
6163
 
5991
6164
  var HTMLRenderingPlugin_1;
@@ -6254,23 +6427,33 @@
6254
6427
  register(HTMLRenderingPlugin);
6255
6428
  });
6256
6429
 
6257
- var Plugin$5 = /*#__PURE__*/function () {
6430
+ var Plugin$5 = /*#__PURE__*/function (_AbstractRendererPlug) {
6431
+ _inheritsLoose$6(Plugin, _AbstractRendererPlug);
6432
+
6258
6433
  function Plugin() {
6259
- this.name = 'html-renderer';
6434
+ var _this;
6435
+
6436
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
6437
+ args[_key] = arguments[_key];
6438
+ }
6439
+
6440
+ _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
6441
+ _this.name = 'html-renderer';
6442
+ return _this;
6260
6443
  }
6261
6444
 
6262
6445
  var _proto = Plugin.prototype;
6263
6446
 
6264
- _proto.init = function init(container) {
6265
- container.load(containerModule$5, true);
6447
+ _proto.init = function init() {
6448
+ this.container.load(containerModule$5, true);
6266
6449
  };
6267
6450
 
6268
- _proto.destroy = function destroy(container) {
6269
- container.unload(containerModule$5);
6451
+ _proto.destroy = function destroy() {
6452
+ this.container.unload(containerModule$5);
6270
6453
  };
6271
6454
 
6272
6455
  return Plugin;
6273
- }();
6456
+ }(g.AbstractRendererPlugin);
6274
6457
 
6275
6458
  var index_esm$5 = /*#__PURE__*/Object.freeze({
6276
6459
  __proto__: null,
@@ -6437,23 +6620,33 @@
6437
6620
  */
6438
6621
  register(Canvas2DContextService);
6439
6622
  });
6440
- var ContextRegisterPlugin = /*#__PURE__*/function () {
6623
+ var ContextRegisterPlugin = /*#__PURE__*/function (_AbstractRendererPlug) {
6624
+ _inheritsLoose(ContextRegisterPlugin, _AbstractRendererPlug);
6625
+
6441
6626
  function ContextRegisterPlugin() {
6442
- this.name = 'canvas-context-register';
6627
+ var _this;
6628
+
6629
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
6630
+ args[_key] = arguments[_key];
6631
+ }
6632
+
6633
+ _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
6634
+ _this.name = 'canvas-context-register';
6635
+ return _this;
6443
6636
  }
6444
6637
 
6445
6638
  var _proto = ContextRegisterPlugin.prototype;
6446
6639
 
6447
- _proto.init = function init(container) {
6448
- container.load(containerModule$6, true);
6640
+ _proto.init = function init() {
6641
+ this.container.load(containerModule$6, true);
6449
6642
  };
6450
6643
 
6451
- _proto.destroy = function destroy(container) {
6452
- container.unload(containerModule$6);
6644
+ _proto.destroy = function destroy() {
6645
+ this.container.unload(containerModule$6);
6453
6646
  };
6454
6647
 
6455
6648
  return ContextRegisterPlugin;
6456
- }();
6649
+ }(g.AbstractRendererPlugin);
6457
6650
 
6458
6651
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
6459
6652
  _inheritsLoose(Renderer, _AbstractRenderer);