@antv/g-canvas 1.9.4 → 1.9.6

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
@@ -424,17 +424,34 @@
424
424
 
425
425
  function __param(paramIndex, decorator) {
426
426
  return function (target, key) { decorator(target, key, paramIndex); }
427
- }
428
-
429
- /** @deprecated */
430
- function __spreadArrays() {
431
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
432
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
433
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
434
- r[k] = a[j];
435
- return r;
436
427
  }
437
428
 
429
+ var toString = {}.toString;
430
+ var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
431
+
432
+ // isFinite,
433
+ var isNil = function (value) {
434
+ /**
435
+ * isNil(null) => true
436
+ * isNil() => true
437
+ */
438
+ return value === null || value === undefined;
439
+ };
440
+
441
+ var isString = (function (str) {
442
+ return isType(str, 'String');
443
+ });
444
+
445
+ var clamp = function (a, min, max) {
446
+ if (a < min) {
447
+ return min;
448
+ }
449
+ else if (a > max) {
450
+ return max;
451
+ }
452
+ return a;
453
+ };
454
+
438
455
  function _inheritsLoose$1(subClass, superClass) {
439
456
  subClass.prototype = Object.create(superClass.prototype);
440
457
  subClass.prototype.constructor = subClass;
@@ -691,158 +708,6 @@
691
708
  context.lineTo(x2 + endOffsetX, y2 + endOffsetY);
692
709
  }
693
710
 
694
- var toString = {}.toString;
695
-
696
- var isType = function isType(value, type) {
697
- return toString.call(value) === '[object ' + type + ']';
698
- };
699
- /**
700
- * 是否为函数
701
- * @param {*} fn 对象
702
- * @return {Boolean} 是否函数
703
- */
704
-
705
-
706
- var isFunction = function isFunction(value) {
707
- return isType(value, 'Function');
708
- };
709
-
710
- var isArray = function isArray(value) {
711
- return Array.isArray ? Array.isArray(value) : isType(value, 'Array');
712
- };
713
-
714
- var isObject = function isObject(value) {
715
- /**
716
- * isObject({}) => true
717
- * isObject([1, 2, 3]) => true
718
- * isObject(Function) => true
719
- * isObject(null) => false
720
- */
721
- var type = typeof value;
722
- return value !== null && type === 'object' || type === 'function';
723
- };
724
-
725
- function each(elements, func) {
726
- if (!elements) {
727
- return;
728
- }
729
-
730
- var rst;
731
-
732
- if (isArray(elements)) {
733
- for (var i = 0, len = elements.length; i < len; i++) {
734
- rst = func(elements[i], i);
735
-
736
- if (rst === false) {
737
- break;
738
- }
739
- }
740
- } else if (isObject(elements)) {
741
- for (var k in elements) {
742
- if (elements.hasOwnProperty(k)) {
743
- rst = func(elements[k], k);
744
-
745
- if (rst === false) {
746
- break;
747
- }
748
- }
749
- }
750
- }
751
- }
752
-
753
- var isString = function isString(str) {
754
- return isType(str, 'String');
755
- };
756
-
757
- var clamp = function clamp(a, min, max) {
758
- if (a < min) {
759
- return min;
760
- } else if (a > max) {
761
- return max;
762
- }
763
-
764
- return a;
765
- }; // @ts-ignore
766
-
767
-
768
- var values = Object.values ? function (obj) {
769
- return Object.values(obj);
770
- } : function (obj) {
771
- var result = [];
772
- each(obj, function (value, key) {
773
- if (!(isFunction(obj) && key === 'prototype')) {
774
- result.push(value);
775
- }
776
- });
777
- return result;
778
- };
779
- /**
780
- * _.memoize(calColor);
781
- * _.memoize(calColor, (...args) => args[0]);
782
- * @param f
783
- * @param resolver
784
- */
785
-
786
- var memoize = function memoize(f, resolver) {
787
- if (!isFunction(f)) {
788
- throw new TypeError('Expected a function');
789
- }
790
-
791
- var memoized = function memoized() {
792
- var args = [];
793
-
794
- for (var _i = 0; _i < arguments.length; _i++) {
795
- args[_i] = arguments[_i];
796
- } // 使用方法构造 key,如果不存在 resolver,则直接取第一个参数作为 key
797
-
798
-
799
- var key = resolver ? resolver.apply(this, args) : args[0];
800
- var cache = memoized.cache;
801
-
802
- if (cache.has(key)) {
803
- return cache.get(key);
804
- }
805
-
806
- var result = f.apply(this, args); // 缓存起来
807
-
808
- cache.set(key, result);
809
- return result;
810
- };
811
-
812
- memoized.cache = new Map();
813
- return memoized;
814
- };
815
-
816
- var ctx;
817
- /**
818
- * 计算文本的宽度
819
- */
820
-
821
- memoize(function (text, font) {
822
- if (font === void 0) {
823
- font = {};
824
- }
825
-
826
- var fontSize = font.fontSize,
827
- fontFamily = font.fontFamily,
828
- fontWeight = font.fontWeight,
829
- fontStyle = font.fontStyle,
830
- fontVariant = font.fontVariant;
831
-
832
- if (!ctx) {
833
- ctx = document.createElement('canvas').getContext('2d');
834
- }
835
-
836
- ctx.font = [fontStyle, fontVariant, fontWeight, fontSize + "px", fontFamily].join(' ');
837
- return ctx.measureText(isString(text) ? text : '').width;
838
- }, function (text, font) {
839
- if (font === void 0) {
840
- font = {};
841
- }
842
-
843
- return __spreadArrays([text], values(font)).join('');
844
- });
845
-
846
711
  function generatePath$6(context, parsedStyle) {
847
712
  var radius = parsedStyle.radius,
848
713
  width = parsedStyle.width,
@@ -998,16 +863,6 @@
998
863
  Plugin: Plugin
999
864
  });
1000
865
 
1001
- var clamp$1 = function (a, min, max) {
1002
- if (a < min) {
1003
- return min;
1004
- }
1005
- else if (a > max) {
1006
- return max;
1007
- }
1008
- return a;
1009
- };
1010
-
1011
866
  function _regeneratorRuntime$1() {
1012
867
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1013
868
  _regeneratorRuntime$1 = function _regeneratorRuntime() {
@@ -2856,7 +2711,7 @@
2856
2711
 
2857
2712
  if (hasStroke || isClipPath) {
2858
2713
  isHit = inRectWithRadius(0, 0, width, height, radius.map(function (r) {
2859
- return clamp$1(r, 0, Math.min(Math.abs(width) / 2, Math.abs(height) / 2));
2714
+ return clamp(r, 0, Math.min(Math.abs(width) / 2, Math.abs(height) / 2));
2860
2715
  }), lineWidthForHitTesting, position.x, position.y);
2861
2716
  } // 仅填充时带有圆角的矩形直接通过图形拾取
2862
2717
  // 以后可以改成纯数学的近似拾取,将圆弧切割成多边形
@@ -3347,148 +3202,6 @@
3347
3202
  return _setPrototypeOf$3(o, p);
3348
3203
  }
3349
3204
 
3350
- var toString$1 = {}.toString;
3351
-
3352
- var isType$1 = function isType(value, type) {
3353
- return toString$1.call(value) === '[object ' + type + ']';
3354
- };
3355
- /**
3356
- * 是否为函数
3357
- * @param {*} fn 对象
3358
- * @return {Boolean} 是否函数
3359
- */
3360
-
3361
-
3362
- var isFunction$1 = function isFunction(value) {
3363
- return isType$1(value, 'Function');
3364
- };
3365
-
3366
- var isArray$1 = function isArray(value) {
3367
- return Array.isArray ? Array.isArray(value) : isType$1(value, 'Array');
3368
- };
3369
-
3370
- var isObject$1 = function isObject(value) {
3371
- /**
3372
- * isObject({}) => true
3373
- * isObject([1, 2, 3]) => true
3374
- * isObject(Function) => true
3375
- * isObject(null) => false
3376
- */
3377
- var type = typeof value;
3378
- return value !== null && type === 'object' || type === 'function';
3379
- };
3380
-
3381
- function each$1(elements, func) {
3382
- if (!elements) {
3383
- return;
3384
- }
3385
-
3386
- var rst;
3387
-
3388
- if (isArray$1(elements)) {
3389
- for (var i = 0, len = elements.length; i < len; i++) {
3390
- rst = func(elements[i], i);
3391
-
3392
- if (rst === false) {
3393
- break;
3394
- }
3395
- }
3396
- } else if (isObject$1(elements)) {
3397
- for (var k in elements) {
3398
- if (elements.hasOwnProperty(k)) {
3399
- rst = func(elements[k], k);
3400
-
3401
- if (rst === false) {
3402
- break;
3403
- }
3404
- }
3405
- }
3406
- }
3407
- }
3408
-
3409
- var isString$1 = function isString(str) {
3410
- return isType$1(str, 'String');
3411
- }; // @ts-ignore
3412
-
3413
-
3414
- var values$1 = Object.values ? function (obj) {
3415
- return Object.values(obj);
3416
- } : function (obj) {
3417
- var result = [];
3418
- each$1(obj, function (value, key) {
3419
- if (!(isFunction$1(obj) && key === 'prototype')) {
3420
- result.push(value);
3421
- }
3422
- });
3423
- return result;
3424
- };
3425
- /**
3426
- * _.memoize(calColor);
3427
- * _.memoize(calColor, (...args) => args[0]);
3428
- * @param f
3429
- * @param resolver
3430
- */
3431
-
3432
- var memoize$1 = function memoize(f, resolver) {
3433
- if (!isFunction$1(f)) {
3434
- throw new TypeError('Expected a function');
3435
- }
3436
-
3437
- var memoized = function memoized() {
3438
- var args = [];
3439
-
3440
- for (var _i = 0; _i < arguments.length; _i++) {
3441
- args[_i] = arguments[_i];
3442
- } // 使用方法构造 key,如果不存在 resolver,则直接取第一个参数作为 key
3443
-
3444
-
3445
- var key = resolver ? resolver.apply(this, args) : args[0];
3446
- var cache = memoized.cache;
3447
-
3448
- if (cache.has(key)) {
3449
- return cache.get(key);
3450
- }
3451
-
3452
- var result = f.apply(this, args); // 缓存起来
3453
-
3454
- cache.set(key, result);
3455
- return result;
3456
- };
3457
-
3458
- memoized.cache = new Map();
3459
- return memoized;
3460
- };
3461
-
3462
- var ctx$1;
3463
- /**
3464
- * 计算文本的宽度
3465
- */
3466
-
3467
- memoize$1(function (text, font) {
3468
- if (font === void 0) {
3469
- font = {};
3470
- }
3471
-
3472
- var fontSize = font.fontSize,
3473
- fontFamily = font.fontFamily,
3474
- fontWeight = font.fontWeight,
3475
- fontStyle = font.fontStyle,
3476
- fontVariant = font.fontVariant;
3477
-
3478
- if (!ctx$1) {
3479
- ctx$1 = document.createElement('canvas').getContext('2d');
3480
- }
3481
-
3482
- ctx$1.font = [fontStyle, fontVariant, fontWeight, fontSize + "px", fontFamily].join(' ');
3483
- return ctx$1.measureText(isString$1(text) ? text : '').width;
3484
- }, function (text, font) {
3485
- if (font === void 0) {
3486
- font = {};
3487
- }
3488
-
3489
- return __spreadArrays([text], values$1(font)).join('');
3490
- });
3491
-
3492
3205
  var ImagePool = /*#__PURE__*/function () {
3493
3206
  function ImagePool(canvasConfig) {
3494
3207
  this.canvasConfig = void 0;
@@ -3561,7 +3274,7 @@
3561
3274
  repetition = pattern.repetition;
3562
3275
  var src; // Image URL
3563
3276
 
3564
- if (isString$1(image)) {
3277
+ if (isString(image)) {
3565
3278
  src = this.getImageSync(image, callback);
3566
3279
  } else {
3567
3280
  src = image;
@@ -3578,15 +3291,15 @@
3578
3291
  };
3579
3292
 
3580
3293
  _proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
3581
- var key = this.generateGradientKey(params); // @ts-ignore
3582
-
3294
+ var key = this.generateGradientKey(params);
3583
3295
  var type = params.type,
3584
3296
  steps = params.steps,
3585
3297
  width = params.width,
3586
3298
  height = params.height,
3587
3299
  angle = params.angle,
3588
3300
  cx = params.cx,
3589
- cy = params.cy;
3301
+ cy = params.cy,
3302
+ size = params.size;
3590
3303
 
3591
3304
  if (this.gradientCache[key]) {
3592
3305
  return this.gradientCache[key];
@@ -3604,7 +3317,7 @@
3604
3317
 
3605
3318
  gradient = context.createLinearGradient(x1, y1, x2, y2);
3606
3319
  } else if (type === gLite.GradientType.RadialGradient) {
3607
- var _computeRadialGradien = gLite.computeRadialGradient(width, height, cx, cy),
3320
+ var _computeRadialGradien = gLite.computeRadialGradient(width, height, cx, cy, size),
3608
3321
  x = _computeRadialGradien.x,
3609
3322
  y = _computeRadialGradien.y,
3610
3323
  r = _computeRadialGradien.r; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
@@ -3615,11 +3328,14 @@
3615
3328
 
3616
3329
  if (gradient) {
3617
3330
  steps.forEach(function (_ref) {
3618
- var _gradient;
3331
+ var offset = _ref.offset,
3332
+ color = _ref.color;
3333
+
3334
+ if (offset.unit === gLite.UnitType.kPercentage) {
3335
+ var _gradient;
3619
3336
 
3620
- var offset = _ref[0],
3621
- color = _ref[1];
3622
- (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset, color);
3337
+ (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset.value / 100, color.toString());
3338
+ }
3623
3339
  });
3624
3340
  this.gradientCache[key] = gradient;
3625
3341
  }
@@ -3628,16 +3344,18 @@
3628
3344
  };
3629
3345
 
3630
3346
  _proto.generateGradientKey = function generateGradientKey(params) {
3631
- // @ts-ignore
3632
3347
  var type = params.type,
3633
3348
  width = params.width,
3634
3349
  height = params.height,
3635
3350
  steps = params.steps,
3636
3351
  angle = params.angle,
3637
3352
  cx = params.cx,
3638
- cy = params.cy;
3639
- return "gradient-" + type + "-" + (angle || 0) + "-" + (cx || 0) + "-" + (cy || 0) + "-" + width + "-" + height + "-" + steps.map(function (step) {
3640
- return step.join('');
3353
+ cy = params.cy,
3354
+ size = params.size;
3355
+ return "gradient-" + type + "-" + ((angle === null || angle === void 0 ? void 0 : angle.toString()) || 0) + "-" + ((cx === null || cx === void 0 ? void 0 : cx.toString()) || 0) + "-" + ((cy === null || cy === void 0 ? void 0 : cy.toString()) || 0) + "-" + ((size === null || size === void 0 ? void 0 : size.toString()) || 0) + "-" + width + "-" + height + "-" + steps.map(function (_ref2) {
3356
+ var offset = _ref2.offset,
3357
+ color = _ref2.color;
3358
+ return "" + offset + color;
3641
3359
  }).join('-');
3642
3360
  };
3643
3361
 
@@ -3645,7 +3363,7 @@
3645
3363
  var image = pattern.image,
3646
3364
  repetition = pattern.repetition; // only generate cache for Image
3647
3365
 
3648
- if (isString$1(image)) {
3366
+ if (isString(image)) {
3649
3367
  return "pattern-" + image + "-" + repetition;
3650
3368
  }
3651
3369
  };
@@ -3679,7 +3397,7 @@
3679
3397
  if (nodeName === gLite.Shape.IMAGE) {
3680
3398
  var img = attributes.img;
3681
3399
 
3682
- if (isString$1(img)) {
3400
+ if (isString(img)) {
3683
3401
  _this.imagePool.getImageSync(img, function () {
3684
3402
  // set dirty rectangle flag
3685
3403
  object.renderable.dirty = true;
@@ -3696,7 +3414,7 @@
3696
3414
 
3697
3415
  if (object.nodeName === gLite.Shape.IMAGE) {
3698
3416
  if (attrName === 'img') {
3699
- if (isString$1(newValue)) {
3417
+ if (isString(newValue)) {
3700
3418
  _this.imagePool.getOrCreateImage(newValue).then(function () {
3701
3419
  // set dirty rectangle flag
3702
3420
  object.renderable.dirty = true;
@@ -4191,162 +3909,12 @@
4191
3909
  };
4192
3910
  return _setPrototypeOf$4(o, p);
4193
3911
  }
4194
-
4195
- var toString$2 = {}.toString;
4196
-
4197
- var isType$2 = function isType(value, type) {
4198
- return toString$2.call(value) === '[object ' + type + ']';
4199
- };
4200
- /**
4201
- * 是否为函数
4202
- * @param {*} fn 对象
4203
- * @return {Boolean} 是否函数
4204
- */
4205
-
4206
-
4207
- var isFunction$2 = function isFunction(value) {
4208
- return isType$2(value, 'Function');
4209
- }; // isFinite,
4210
-
4211
-
4212
- var isNil = function isNil(value) {
4213
- /**
4214
- * isNil(null) => true
4215
- * isNil() => true
4216
- */
4217
- return value === null || value === undefined;
4218
- };
4219
-
4220
- var isArray$2 = function isArray(value) {
4221
- return Array.isArray ? Array.isArray(value) : isType$2(value, 'Array');
4222
- };
4223
-
4224
- var isObject$2 = function isObject(value) {
4225
- /**
4226
- * isObject({}) => true
4227
- * isObject([1, 2, 3]) => true
4228
- * isObject(Function) => true
4229
- * isObject(null) => false
4230
- */
4231
- var type = typeof value;
4232
- return value !== null && type === 'object' || type === 'function';
4233
- };
4234
-
4235
- function each$2(elements, func) {
4236
- if (!elements) {
4237
- return;
4238
- }
4239
-
4240
- var rst;
4241
-
4242
- if (isArray$2(elements)) {
4243
- for (var i = 0, len = elements.length; i < len; i++) {
4244
- rst = func(elements[i], i);
4245
-
4246
- if (rst === false) {
4247
- break;
4248
- }
4249
- }
4250
- } else if (isObject$2(elements)) {
4251
- for (var k in elements) {
4252
- if (elements.hasOwnProperty(k)) {
4253
- rst = func(elements[k], k);
4254
-
4255
- if (rst === false) {
4256
- break;
4257
- }
4258
- }
4259
- }
4260
- }
4261
- }
4262
-
4263
- var isString$2 = function isString(str) {
4264
- return isType$2(str, 'String');
4265
- }; // @ts-ignore
4266
-
4267
-
4268
- var values$2 = Object.values ? function (obj) {
4269
- return Object.values(obj);
4270
- } : function (obj) {
4271
- var result = [];
4272
- each$2(obj, function (value, key) {
4273
- if (!(isFunction$2(obj) && key === 'prototype')) {
4274
- result.push(value);
4275
- }
4276
- });
4277
- return result;
4278
- };
4279
- /**
4280
- * _.memoize(calColor);
4281
- * _.memoize(calColor, (...args) => args[0]);
4282
- * @param f
4283
- * @param resolver
4284
- */
4285
-
4286
- var memoize$2 = function memoize(f, resolver) {
4287
- if (!isFunction$2(f)) {
4288
- throw new TypeError('Expected a function');
4289
- }
4290
-
4291
- var memoized = function memoized() {
4292
- var args = [];
4293
-
4294
- for (var _i = 0; _i < arguments.length; _i++) {
4295
- args[_i] = arguments[_i];
4296
- } // 使用方法构造 key,如果不存在 resolver,则直接取第一个参数作为 key
4297
-
4298
-
4299
- var key = resolver ? resolver.apply(this, args) : args[0];
4300
- var cache = memoized.cache;
4301
-
4302
- if (cache.has(key)) {
4303
- return cache.get(key);
4304
- }
4305
-
4306
- var result = f.apply(this, args); // 缓存起来
4307
-
4308
- cache.set(key, result);
4309
- return result;
4310
- };
4311
-
4312
- memoized.cache = new Map();
4313
- return memoized;
4314
- };
4315
-
4316
- var ctx$2;
4317
- /**
4318
- * 计算文本的宽度
4319
- */
4320
-
4321
- memoize$2(function (text, font) {
4322
- if (font === void 0) {
4323
- font = {};
4324
- }
4325
-
4326
- var fontSize = font.fontSize,
4327
- fontFamily = font.fontFamily,
4328
- fontWeight = font.fontWeight,
4329
- fontStyle = font.fontStyle,
4330
- fontVariant = font.fontVariant;
4331
-
4332
- if (!ctx$2) {
4333
- ctx$2 = document.createElement('canvas').getContext('2d');
4334
- }
4335
-
4336
- ctx$2.font = [fontStyle, fontVariant, fontWeight, fontSize + "px", fontFamily].join(' ');
4337
- return ctx$2.measureText(isString$2(text) ? text : '').width;
4338
- }, function (text, font) {
4339
- if (font === void 0) {
4340
- font = {};
4341
- }
4342
-
4343
- return __spreadArrays([text], values$2(font)).join('');
4344
- });
4345
3912
  /**
4346
3913
  * Common utilities
4347
3914
  * @module glMatrix
4348
3915
  */
4349
3916
 
3917
+
4350
3918
  var ARRAY_TYPE$1 = typeof Float32Array !== 'undefined' ? Float32Array : Array;
4351
3919
  if (!Math.hypot) Math.hypot = function () {
4352
3920
  var y = 0,
@@ -4912,7 +4480,7 @@
4912
4480
  var iw = width;
4913
4481
  var ih = height;
4914
4482
 
4915
- if (isString$2(img)) {
4483
+ if (isString(img)) {
4916
4484
  // image has been loaded in `mounted` hook
4917
4485
  image = this.imagePool.getImageSync(img);
4918
4486
  } else {
@@ -5289,9 +4857,7 @@
5289
4857
 
5290
4858
  _this.clearRect(context, 0, 0, width * dpr, height * dpr);
5291
4859
 
5292
- fromScaling(_this.dprMatrix, fromValues(dpr, dpr, 1));
5293
-
5294
- case 7:
4860
+ case 6:
5295
4861
  case "end":
5296
4862
  return _context.stop();
5297
4863
  }
@@ -5351,6 +4917,9 @@
5351
4917
  var context = _this.contextService.getContext(); // clear & clip dirty rectangle
5352
4918
 
5353
4919
 
4920
+ var dpr = _this.contextService.getDPR();
4921
+
4922
+ fromScaling(_this.dprMatrix, fromValues(dpr, dpr, 1));
5354
4923
  multiply$1(_this.vpMatrix, _this.dprMatrix, _this.camera.getOrthoMatrix());
5355
4924
 
5356
4925
  if (_this.clearFullScreen) {
@@ -6818,148 +6387,6 @@
6818
6387
  return _setPrototypeOf$6(o, p);
6819
6388
  }
6820
6389
 
6821
- var toString$3 = {}.toString;
6822
-
6823
- var isType$3 = function isType(value, type) {
6824
- return toString$3.call(value) === '[object ' + type + ']';
6825
- };
6826
- /**
6827
- * 是否为函数
6828
- * @param {*} fn 对象
6829
- * @return {Boolean} 是否函数
6830
- */
6831
-
6832
-
6833
- var isFunction$3 = function isFunction(value) {
6834
- return isType$3(value, 'Function');
6835
- };
6836
-
6837
- var isArray$3 = function isArray(value) {
6838
- return Array.isArray ? Array.isArray(value) : isType$3(value, 'Array');
6839
- };
6840
-
6841
- var isObject$3 = function isObject(value) {
6842
- /**
6843
- * isObject({}) => true
6844
- * isObject([1, 2, 3]) => true
6845
- * isObject(Function) => true
6846
- * isObject(null) => false
6847
- */
6848
- var type = typeof value;
6849
- return value !== null && type === 'object' || type === 'function';
6850
- };
6851
-
6852
- function each$3(elements, func) {
6853
- if (!elements) {
6854
- return;
6855
- }
6856
-
6857
- var rst;
6858
-
6859
- if (isArray$3(elements)) {
6860
- for (var i = 0, len = elements.length; i < len; i++) {
6861
- rst = func(elements[i], i);
6862
-
6863
- if (rst === false) {
6864
- break;
6865
- }
6866
- }
6867
- } else if (isObject$3(elements)) {
6868
- for (var k in elements) {
6869
- if (elements.hasOwnProperty(k)) {
6870
- rst = func(elements[k], k);
6871
-
6872
- if (rst === false) {
6873
- break;
6874
- }
6875
- }
6876
- }
6877
- }
6878
- }
6879
-
6880
- var isString$3 = function isString(str) {
6881
- return isType$3(str, 'String');
6882
- }; // @ts-ignore
6883
-
6884
-
6885
- var values$3 = Object.values ? function (obj) {
6886
- return Object.values(obj);
6887
- } : function (obj) {
6888
- var result = [];
6889
- each$3(obj, function (value, key) {
6890
- if (!(isFunction$3(obj) && key === 'prototype')) {
6891
- result.push(value);
6892
- }
6893
- });
6894
- return result;
6895
- };
6896
- /**
6897
- * _.memoize(calColor);
6898
- * _.memoize(calColor, (...args) => args[0]);
6899
- * @param f
6900
- * @param resolver
6901
- */
6902
-
6903
- var memoize$3 = function memoize(f, resolver) {
6904
- if (!isFunction$3(f)) {
6905
- throw new TypeError('Expected a function');
6906
- }
6907
-
6908
- var memoized = function memoized() {
6909
- var args = [];
6910
-
6911
- for (var _i = 0; _i < arguments.length; _i++) {
6912
- args[_i] = arguments[_i];
6913
- } // 使用方法构造 key,如果不存在 resolver,则直接取第一个参数作为 key
6914
-
6915
-
6916
- var key = resolver ? resolver.apply(this, args) : args[0];
6917
- var cache = memoized.cache;
6918
-
6919
- if (cache.has(key)) {
6920
- return cache.get(key);
6921
- }
6922
-
6923
- var result = f.apply(this, args); // 缓存起来
6924
-
6925
- cache.set(key, result);
6926
- return result;
6927
- };
6928
-
6929
- memoized.cache = new Map();
6930
- return memoized;
6931
- };
6932
-
6933
- var ctx$3;
6934
- /**
6935
- * 计算文本的宽度
6936
- */
6937
-
6938
- memoize$3(function (text, font) {
6939
- if (font === void 0) {
6940
- font = {};
6941
- }
6942
-
6943
- var fontSize = font.fontSize,
6944
- fontFamily = font.fontFamily,
6945
- fontWeight = font.fontWeight,
6946
- fontStyle = font.fontStyle,
6947
- fontVariant = font.fontVariant;
6948
-
6949
- if (!ctx$3) {
6950
- ctx$3 = document.createElement('canvas').getContext('2d');
6951
- }
6952
-
6953
- ctx$3.font = [fontStyle, fontVariant, fontWeight, fontSize + "px", fontFamily].join(' ');
6954
- return ctx$3.measureText(isString$3(text) ? text : '').width;
6955
- }, function (text, font) {
6956
- if (font === void 0) {
6957
- font = {};
6958
- }
6959
-
6960
- return __spreadArrays([text], values$3(font)).join('');
6961
- });
6962
-
6963
6390
  var _class$4;
6964
6391
 
6965
6392
  var HTMLRenderingPlugin_1;
@@ -7122,7 +6549,7 @@
7122
6549
  case 'innerHTML':
7123
6550
  var innerHTML = object.parsedStyle.innerHTML;
7124
6551
 
7125
- if (isString$3(innerHTML)) {
6552
+ if (isString(innerHTML)) {
7126
6553
  $el.innerHTML = innerHTML;
7127
6554
  } else {
7128
6555
  $el.innerHTML = '';
@@ -7259,143 +6686,29 @@
7259
6686
  Plugin: Plugin$5
7260
6687
  });
7261
6688
 
7262
- var toString$4 = {}.toString;
7263
- var isType$4 = function (value, type) { return toString$4.call(value) === '[object ' + type + ']'; };
7264
-
7265
- /**
7266
- * 是否为函数
7267
- * @param {*} fn 对象
7268
- * @return {Boolean} 是否函数
7269
- */
7270
- var isFunction$4 = (function (value) {
7271
- return isType$4(value, 'Function');
7272
- });
7273
-
7274
- var isArray$4 = (function (value) {
7275
- return Array.isArray ?
7276
- Array.isArray(value) :
7277
- isType$4(value, 'Array');
7278
- });
7279
-
7280
- var isObject$4 = (function (value) {
7281
- /**
7282
- * isObject({}) => true
7283
- * isObject([1, 2, 3]) => true
7284
- * isObject(Function) => true
7285
- * isObject(null) => false
7286
- */
7287
- var type = typeof value;
7288
- return value !== null && type === 'object' || type === 'function';
7289
- });
7290
-
7291
- function each$4(elements, func) {
7292
- if (!elements) {
7293
- return;
7294
- }
7295
- var rst;
7296
- if (isArray$4(elements)) {
7297
- for (var i = 0, len = elements.length; i < len; i++) {
7298
- rst = func(elements[i], i);
7299
- if (rst === false) {
7300
- break;
7301
- }
7302
- }
7303
- }
7304
- else if (isObject$4(elements)) {
7305
- for (var k in elements) {
7306
- if (elements.hasOwnProperty(k)) {
7307
- rst = func(elements[k], k);
7308
- if (rst === false) {
7309
- break;
7310
- }
7311
- }
7312
- }
7313
- }
7314
- }
7315
-
7316
- var isString$4 = (function (str) {
7317
- return isType$4(str, 'String');
7318
- });
7319
-
7320
- // @ts-ignore
7321
- var values$4 = Object.values ? function (obj) { return Object.values(obj); } : function (obj) {
7322
- var result = [];
7323
- each$4(obj, function (value, key) {
7324
- if (!(isFunction$4(obj) && key === 'prototype')) {
7325
- result.push(value);
7326
- }
7327
- });
7328
- return result;
7329
- };
7330
-
7331
- /**
7332
- * _.memoize(calColor);
7333
- * _.memoize(calColor, (...args) => args[0]);
7334
- * @param f
7335
- * @param resolver
7336
- */
7337
- var memoize$4 = (function (f, resolver) {
7338
- if (!isFunction$4(f)) {
7339
- throw new TypeError('Expected a function');
7340
- }
7341
- var memoized = function () {
7342
- var args = [];
7343
- for (var _i = 0; _i < arguments.length; _i++) {
7344
- args[_i] = arguments[_i];
7345
- }
7346
- // 使用方法构造 key,如果不存在 resolver,则直接取第一个参数作为 key
7347
- var key = resolver ? resolver.apply(this, args) : args[0];
7348
- var cache = memoized.cache;
7349
- if (cache.has(key)) {
7350
- return cache.get(key);
7351
- }
7352
- var result = f.apply(this, args);
7353
- // 缓存起来
7354
- cache.set(key, result);
7355
- return result;
7356
- };
7357
- memoized.cache = new Map();
7358
- return memoized;
7359
- });
7360
-
7361
- var ctx$4;
7362
- /**
7363
- * 计算文本的宽度
7364
- */
7365
- memoize$4(function (text, font) {
7366
- if (font === void 0) { font = {}; }
7367
- var fontSize = font.fontSize, fontFamily = font.fontFamily, fontWeight = font.fontWeight, fontStyle = font.fontStyle, fontVariant = font.fontVariant;
7368
- if (!ctx$4) {
7369
- ctx$4 = document.createElement('canvas').getContext('2d');
7370
- }
7371
- ctx$4.font = [fontStyle, fontVariant, fontWeight, fontSize + "px", fontFamily].join(' ');
7372
- return ctx$4.measureText(isString$4(text) ? text : '').width;
7373
- }, function (text, font) {
7374
- if (font === void 0) { font = {}; }
7375
- return __spreadArrays([text], values$4(font)).join('');
7376
- });
7377
-
7378
6689
  var Canvas2DContextService = /*#__PURE__*/function () {
7379
- function Canvas2DContextService(canvasConfig) {
6690
+ function Canvas2DContextService(canvasConfig, renderingContext) {
7380
6691
  this.canvasConfig = void 0;
6692
+ this.renderingContext = void 0;
7381
6693
  this.$container = void 0;
7382
6694
  this.$canvas = void 0;
7383
6695
  this.dpr = void 0;
7384
6696
  this.context = void 0;
7385
6697
  this.canvasConfig = canvasConfig;
6698
+ this.renderingContext = renderingContext;
7386
6699
  }
7387
6700
 
7388
6701
  var _proto = Canvas2DContextService.prototype;
7389
6702
 
7390
6703
  _proto.init = /*#__PURE__*/function () {
7391
6704
  var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
7392
- var _this$canvasConfig, container, canvas, devicePixelRatio, $canvas, dpr;
6705
+ var _this$canvasConfig, container, canvas, $canvas;
7393
6706
 
7394
6707
  return _regeneratorRuntime().wrap(function _callee$(_context) {
7395
6708
  while (1) {
7396
6709
  switch (_context.prev = _context.next) {
7397
6710
  case 0:
7398
- _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas, devicePixelRatio = _this$canvasConfig.devicePixelRatio;
6711
+ _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas;
7399
6712
 
7400
6713
  if (canvas) {
7401
6714
  this.$canvas = canvas;
@@ -7408,7 +6721,7 @@
7408
6721
  this.canvasConfig.container = this.$container;
7409
6722
  } else if (container) {
7410
6723
  // create container
7411
- this.$container = isString$4(container) ? document.getElementById(container) : container;
6724
+ this.$container = isString(container) ? document.getElementById(container) : container;
7412
6725
 
7413
6726
  if (this.$container) {
7414
6727
  // create canvas
@@ -7423,14 +6736,10 @@
7423
6736
  }
7424
6737
  }
7425
6738
 
7426
- this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
7427
-
7428
- dpr = devicePixelRatio || gLite.isBrowser && window.devicePixelRatio || 1;
7429
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
7430
- this.dpr = dpr;
6739
+ this.context = this.$canvas.getContext('2d');
7431
6740
  this.resize(this.canvasConfig.width, this.canvasConfig.height);
7432
6741
 
7433
- case 7:
6742
+ case 4:
7434
6743
  case "end":
7435
6744
  return _context.stop();
7436
6745
  }
@@ -7473,6 +6782,12 @@
7473
6782
  };
7474
6783
 
7475
6784
  _proto.resize = function resize(width, height) {
6785
+ var devicePixelRatio = this.canvasConfig.devicePixelRatio; // use user-defined dpr first
6786
+
6787
+ var dpr = devicePixelRatio || gLite.isBrowser && window.devicePixelRatio || 1;
6788
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
6789
+ this.dpr = dpr;
6790
+
7476
6791
  if (this.$canvas) {
7477
6792
  // set canvas width & height
7478
6793
  this.$canvas.width = this.dpr * width;
@@ -7483,6 +6798,8 @@
7483
6798
  // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
7484
6799
  // this.context.scale(dpr, dpr);
7485
6800
  }
6801
+
6802
+ this.renderingContext.renderReasons.add(gLite.RenderReason.CAMERA_CHANGED);
7486
6803
  };
7487
6804
 
7488
6805
  _proto.applyCursorStyle = function applyCursorStyle(cursor) {
@@ -7526,7 +6843,7 @@
7526
6843
 
7527
6844
  Canvas2DContextService = __decorate([gLite.singleton({
7528
6845
  token: gLite.ContextService
7529
- }), __param(0, gLite.inject(gLite.CanvasConfig))], Canvas2DContextService);
6846
+ }), __param(0, gLite.inject(gLite.CanvasConfig)), __param(1, gLite.inject(gLite.RenderingContext))], Canvas2DContextService);
7530
6847
 
7531
6848
  var containerModule$6 = gLite.Module(function (register) {
7532
6849
  /**