@antv/g-canvas 1.9.18 → 1.9.20
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.esm.js +243 -128
- package/dist/index.js +243 -128
- package/dist/index.umd.js +2732 -1664
- package/dist/index.umd.min.js +1 -1
- package/package.json +8 -8
package/dist/index.esm.js
CHANGED
|
@@ -154,14 +154,9 @@ function _regeneratorRuntime() {
|
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
156
|
function maybeInvokeDelegate(delegate, context) {
|
|
157
|
-
var
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
|
|
161
|
-
context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
|
|
162
|
-
}
|
|
163
|
-
return ContinueSentinel;
|
|
164
|
-
}
|
|
157
|
+
var methodName = context.method,
|
|
158
|
+
method = delegate.iterator[methodName];
|
|
159
|
+
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
|
|
165
160
|
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
166
161
|
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
167
162
|
var info = record.arg;
|
|
@@ -355,10 +350,49 @@ function _asyncToGenerator(fn) {
|
|
|
355
350
|
});
|
|
356
351
|
};
|
|
357
352
|
}
|
|
358
|
-
function
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
353
|
+
function _classCallCheck(instance, Constructor) {
|
|
354
|
+
if (!(instance instanceof Constructor)) {
|
|
355
|
+
throw new TypeError("Cannot call a class as a function");
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
function _defineProperties(target, props) {
|
|
359
|
+
for (var i = 0; i < props.length; i++) {
|
|
360
|
+
var descriptor = props[i];
|
|
361
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
362
|
+
descriptor.configurable = true;
|
|
363
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
364
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
368
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
369
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
370
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
371
|
+
writable: false
|
|
372
|
+
});
|
|
373
|
+
return Constructor;
|
|
374
|
+
}
|
|
375
|
+
function _inherits(subClass, superClass) {
|
|
376
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
377
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
378
|
+
}
|
|
379
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
380
|
+
constructor: {
|
|
381
|
+
value: subClass,
|
|
382
|
+
writable: true,
|
|
383
|
+
configurable: true
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
Object.defineProperty(subClass, "prototype", {
|
|
387
|
+
writable: false
|
|
388
|
+
});
|
|
389
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
390
|
+
}
|
|
391
|
+
function _getPrototypeOf(o) {
|
|
392
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
|
393
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
394
|
+
};
|
|
395
|
+
return _getPrototypeOf(o);
|
|
362
396
|
}
|
|
363
397
|
function _setPrototypeOf(o, p) {
|
|
364
398
|
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
@@ -367,9 +401,63 @@ function _setPrototypeOf(o, p) {
|
|
|
367
401
|
};
|
|
368
402
|
return _setPrototypeOf(o, p);
|
|
369
403
|
}
|
|
404
|
+
function _isNativeReflectConstruct() {
|
|
405
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
406
|
+
if (Reflect.construct.sham) return false;
|
|
407
|
+
if (typeof Proxy === "function") return true;
|
|
408
|
+
try {
|
|
409
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
410
|
+
return true;
|
|
411
|
+
} catch (e) {
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
function _assertThisInitialized(self) {
|
|
416
|
+
if (self === void 0) {
|
|
417
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
418
|
+
}
|
|
419
|
+
return self;
|
|
420
|
+
}
|
|
421
|
+
function _possibleConstructorReturn(self, call) {
|
|
422
|
+
if (call && (typeof call === "object" || typeof call === "function")) {
|
|
423
|
+
return call;
|
|
424
|
+
} else if (call !== void 0) {
|
|
425
|
+
throw new TypeError("Derived constructors may only return object or undefined");
|
|
426
|
+
}
|
|
427
|
+
return _assertThisInitialized(self);
|
|
428
|
+
}
|
|
429
|
+
function _createSuper(Derived) {
|
|
430
|
+
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
431
|
+
return function _createSuperInternal() {
|
|
432
|
+
var Super = _getPrototypeOf(Derived),
|
|
433
|
+
result;
|
|
434
|
+
if (hasNativeReflectConstruct) {
|
|
435
|
+
var NewTarget = _getPrototypeOf(this).constructor;
|
|
436
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
|
437
|
+
} else {
|
|
438
|
+
result = Super.apply(this, arguments);
|
|
439
|
+
}
|
|
440
|
+
return _possibleConstructorReturn(this, result);
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
function _toPrimitive(input, hint) {
|
|
444
|
+
if (typeof input !== "object" || input === null) return input;
|
|
445
|
+
var prim = input[Symbol.toPrimitive];
|
|
446
|
+
if (prim !== undefined) {
|
|
447
|
+
var res = prim.call(input, hint || "default");
|
|
448
|
+
if (typeof res !== "object") return res;
|
|
449
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
450
|
+
}
|
|
451
|
+
return (hint === "string" ? String : Number)(input);
|
|
452
|
+
}
|
|
453
|
+
function _toPropertyKey(arg) {
|
|
454
|
+
var key = _toPrimitive(arg, "string");
|
|
455
|
+
return typeof key === "symbol" ? key : String(key);
|
|
456
|
+
}
|
|
370
457
|
|
|
371
458
|
var Canvas2DContextService = /*#__PURE__*/function () {
|
|
372
459
|
function Canvas2DContextService(context) {
|
|
460
|
+
_classCallCheck(this, Canvas2DContextService);
|
|
373
461
|
this.$container = void 0;
|
|
374
462
|
this.$canvas = void 0;
|
|
375
463
|
this.dpr = void 0;
|
|
@@ -379,149 +467,176 @@ var Canvas2DContextService = /*#__PURE__*/function () {
|
|
|
379
467
|
this.renderingContext = context.renderingContext;
|
|
380
468
|
this.canvasConfig = context.config;
|
|
381
469
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
var
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
container.
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
this.$container.style.position
|
|
470
|
+
_createClass(Canvas2DContextService, [{
|
|
471
|
+
key: "init",
|
|
472
|
+
value: function () {
|
|
473
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
474
|
+
var _this$canvasConfig, container, canvas, $canvas;
|
|
475
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
476
|
+
while (1) {
|
|
477
|
+
switch (_context.prev = _context.next) {
|
|
478
|
+
case 0:
|
|
479
|
+
_this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas;
|
|
480
|
+
if (canvas) {
|
|
481
|
+
this.$canvas = canvas;
|
|
482
|
+
if (container && canvas.parentElement !== container) {
|
|
483
|
+
container.appendChild(canvas);
|
|
484
|
+
}
|
|
485
|
+
this.$container = canvas.parentElement;
|
|
486
|
+
this.canvasConfig.container = this.$container;
|
|
487
|
+
} else if (container) {
|
|
488
|
+
// create container
|
|
489
|
+
this.$container = isString(container) ? document.getElementById(container) : container;
|
|
490
|
+
if (this.$container) {
|
|
491
|
+
// create canvas
|
|
492
|
+
$canvas = document.createElement('canvas');
|
|
493
|
+
this.$container.appendChild($canvas);
|
|
494
|
+
if (!this.$container.style.position) {
|
|
495
|
+
this.$container.style.position = 'relative';
|
|
496
|
+
}
|
|
497
|
+
this.$canvas = $canvas;
|
|
407
498
|
}
|
|
408
|
-
this.$canvas = $canvas;
|
|
409
499
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
500
|
+
this.context = this.$canvas.getContext('2d');
|
|
501
|
+
this.resize(this.canvasConfig.width, this.canvasConfig.height);
|
|
502
|
+
case 4:
|
|
503
|
+
case "end":
|
|
504
|
+
return _context.stop();
|
|
505
|
+
}
|
|
416
506
|
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
507
|
+
}, _callee, this);
|
|
508
|
+
}));
|
|
509
|
+
function init() {
|
|
510
|
+
return _init.apply(this, arguments);
|
|
511
|
+
}
|
|
512
|
+
return init;
|
|
513
|
+
}()
|
|
514
|
+
}, {
|
|
515
|
+
key: "getContext",
|
|
516
|
+
value: function getContext() {
|
|
517
|
+
return this.context;
|
|
422
518
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
};
|
|
428
|
-
_proto.getDomElement = function getDomElement() {
|
|
429
|
-
return this.$canvas;
|
|
430
|
-
};
|
|
431
|
-
_proto.getDPR = function getDPR() {
|
|
432
|
-
return this.dpr;
|
|
433
|
-
};
|
|
434
|
-
_proto.getBoundingClientRect = function getBoundingClientRect() {
|
|
435
|
-
if (this.$canvas.getBoundingClientRect) {
|
|
436
|
-
return this.$canvas.getBoundingClientRect();
|
|
519
|
+
}, {
|
|
520
|
+
key: "getDomElement",
|
|
521
|
+
value: function getDomElement() {
|
|
522
|
+
return this.$canvas;
|
|
437
523
|
}
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
// destroy context
|
|
443
|
-
// @ts-ignore
|
|
444
|
-
this.$container.removeChild(this.$canvas);
|
|
524
|
+
}, {
|
|
525
|
+
key: "getDPR",
|
|
526
|
+
value: function getDPR() {
|
|
527
|
+
return this.dpr;
|
|
445
528
|
}
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
// this.context.scale(dpr, dpr);
|
|
529
|
+
}, {
|
|
530
|
+
key: "getBoundingClientRect",
|
|
531
|
+
value: function getBoundingClientRect() {
|
|
532
|
+
if (this.$canvas.getBoundingClientRect) {
|
|
533
|
+
return this.$canvas.getBoundingClientRect();
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}, {
|
|
537
|
+
key: "destroy",
|
|
538
|
+
value: function destroy() {
|
|
539
|
+
// @ts-ignore
|
|
540
|
+
if (this.$container && this.$canvas && this.$canvas.parentNode) {
|
|
541
|
+
// destroy context
|
|
542
|
+
// @ts-ignore
|
|
543
|
+
this.$container.removeChild(this.$canvas);
|
|
544
|
+
}
|
|
463
545
|
}
|
|
546
|
+
}, {
|
|
547
|
+
key: "resize",
|
|
548
|
+
value: function resize(width, height) {
|
|
549
|
+
var devicePixelRatio = this.canvasConfig.devicePixelRatio;
|
|
550
|
+
// use user-defined dpr first
|
|
551
|
+
var dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
|
|
552
|
+
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
553
|
+
this.dpr = dpr;
|
|
554
|
+
if (this.$canvas) {
|
|
555
|
+
// set canvas width & height
|
|
556
|
+
this.$canvas.width = this.dpr * width;
|
|
557
|
+
this.$canvas.height = this.dpr * height;
|
|
558
|
+
// set CSS style width & height
|
|
559
|
+
setDOMSize(this.$canvas, width, height);
|
|
560
|
+
// const dpr = this.getDPR();
|
|
561
|
+
// scale all drawing operations by the dpr
|
|
562
|
+
// @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
|
|
563
|
+
// this.context.scale(dpr, dpr);
|
|
564
|
+
}
|
|
464
565
|
|
|
465
|
-
|
|
466
|
-
};
|
|
467
|
-
_proto.applyCursorStyle = function applyCursorStyle(cursor) {
|
|
468
|
-
if (this.$container && this.$container.style) {
|
|
469
|
-
this.$container.style.cursor = cursor;
|
|
566
|
+
this.renderingContext.renderReasons.add(RenderReason.CAMERA_CHANGED);
|
|
470
567
|
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
switch (_context2.prev = _context2.next) {
|
|
478
|
-
case 0:
|
|
479
|
-
if (options === void 0) {
|
|
480
|
-
options = {};
|
|
481
|
-
}
|
|
482
|
-
_options = options, type = _options.type, encoderOptions = _options.encoderOptions;
|
|
483
|
-
return _context2.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
|
|
484
|
-
case 3:
|
|
485
|
-
case "end":
|
|
486
|
-
return _context2.stop();
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}, _callee2, this);
|
|
490
|
-
}));
|
|
491
|
-
function toDataURL(_x) {
|
|
492
|
-
return _toDataURL.apply(this, arguments);
|
|
568
|
+
}, {
|
|
569
|
+
key: "applyCursorStyle",
|
|
570
|
+
value: function applyCursorStyle(cursor) {
|
|
571
|
+
if (this.$container && this.$container.style) {
|
|
572
|
+
this.$container.style.cursor = cursor;
|
|
573
|
+
}
|
|
493
574
|
}
|
|
494
|
-
|
|
495
|
-
|
|
575
|
+
}, {
|
|
576
|
+
key: "toDataURL",
|
|
577
|
+
value: function () {
|
|
578
|
+
var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
579
|
+
var options,
|
|
580
|
+
type,
|
|
581
|
+
encoderOptions,
|
|
582
|
+
_args2 = arguments;
|
|
583
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
584
|
+
while (1) {
|
|
585
|
+
switch (_context2.prev = _context2.next) {
|
|
586
|
+
case 0:
|
|
587
|
+
options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
|
|
588
|
+
type = options.type, encoderOptions = options.encoderOptions;
|
|
589
|
+
return _context2.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
|
|
590
|
+
case 3:
|
|
591
|
+
case "end":
|
|
592
|
+
return _context2.stop();
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}, _callee2, this);
|
|
596
|
+
}));
|
|
597
|
+
function toDataURL() {
|
|
598
|
+
return _toDataURL.apply(this, arguments);
|
|
599
|
+
}
|
|
600
|
+
return toDataURL;
|
|
601
|
+
}()
|
|
602
|
+
}]);
|
|
496
603
|
return Canvas2DContextService;
|
|
497
604
|
}();
|
|
498
605
|
|
|
499
606
|
var ContextRegisterPlugin = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
500
|
-
|
|
607
|
+
_inherits(ContextRegisterPlugin, _AbstractRendererPlug);
|
|
608
|
+
var _super = _createSuper(ContextRegisterPlugin);
|
|
501
609
|
function ContextRegisterPlugin() {
|
|
502
610
|
var _this;
|
|
611
|
+
_classCallCheck(this, ContextRegisterPlugin);
|
|
503
612
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
504
613
|
args[_key] = arguments[_key];
|
|
505
614
|
}
|
|
506
|
-
_this =
|
|
615
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
507
616
|
_this.name = 'canvas-context-register';
|
|
508
617
|
return _this;
|
|
509
618
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
619
|
+
_createClass(ContextRegisterPlugin, [{
|
|
620
|
+
key: "init",
|
|
621
|
+
value: function init() {
|
|
622
|
+
this.context.ContextService = Canvas2DContextService;
|
|
623
|
+
}
|
|
624
|
+
}, {
|
|
625
|
+
key: "destroy",
|
|
626
|
+
value: function destroy() {
|
|
627
|
+
delete this.context.ContextService;
|
|
628
|
+
}
|
|
629
|
+
}]);
|
|
517
630
|
return ContextRegisterPlugin;
|
|
518
631
|
}(AbstractRendererPlugin);
|
|
519
632
|
|
|
520
633
|
var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
521
|
-
|
|
634
|
+
_inherits(Renderer, _AbstractRenderer);
|
|
635
|
+
var _super = _createSuper(Renderer);
|
|
522
636
|
function Renderer(config) {
|
|
523
637
|
var _this;
|
|
524
|
-
|
|
638
|
+
_classCallCheck(this, Renderer);
|
|
639
|
+
_this = _super.call(this, config);
|
|
525
640
|
// register Canvas2DContext
|
|
526
641
|
_this.registerPlugin(new ContextRegisterPlugin());
|
|
527
642
|
_this.registerPlugin(new Plugin());
|
|
@@ -535,7 +650,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
|
535
650
|
_this.registerPlugin(new Plugin$5());
|
|
536
651
|
return _this;
|
|
537
652
|
}
|
|
538
|
-
return Renderer;
|
|
653
|
+
return _createClass(Renderer);
|
|
539
654
|
}(AbstractRenderer);
|
|
540
655
|
|
|
541
656
|
export { Renderer };
|