@antv/g-canvas 1.9.44 → 1.9.45
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 +117 -237
- package/dist/index.js +117 -237
- package/dist/index.umd.js +1635 -2721
- package/dist/index.umd.min.js +1 -1
- package/package.json +8 -8
package/dist/index.esm.js
CHANGED
|
@@ -350,49 +350,10 @@ function _asyncToGenerator(fn) {
|
|
|
350
350
|
});
|
|
351
351
|
};
|
|
352
352
|
}
|
|
353
|
-
function
|
|
354
|
-
|
|
355
|
-
|
|
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);
|
|
353
|
+
function _inheritsLoose(subClass, superClass) {
|
|
354
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
355
|
+
subClass.prototype.constructor = subClass;
|
|
356
|
+
_setPrototypeOf(subClass, superClass);
|
|
396
357
|
}
|
|
397
358
|
function _setPrototypeOf(o, p) {
|
|
398
359
|
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
@@ -401,63 +362,9 @@ function _setPrototypeOf(o, p) {
|
|
|
401
362
|
};
|
|
402
363
|
return _setPrototypeOf(o, p);
|
|
403
364
|
}
|
|
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
|
-
}
|
|
457
365
|
|
|
458
366
|
var Canvas2DContextService = /*#__PURE__*/function () {
|
|
459
367
|
function Canvas2DContextService(context) {
|
|
460
|
-
_classCallCheck(this, Canvas2DContextService);
|
|
461
368
|
this.$container = void 0;
|
|
462
369
|
this.$canvas = void 0;
|
|
463
370
|
this.dpr = void 0;
|
|
@@ -467,172 +374,145 @@ var Canvas2DContextService = /*#__PURE__*/function () {
|
|
|
467
374
|
this.renderingContext = context.renderingContext;
|
|
468
375
|
this.canvasConfig = context.config;
|
|
469
376
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
var
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
this.$container.style.position = 'relative';
|
|
495
|
-
}
|
|
496
|
-
this.$canvas = $canvas;
|
|
377
|
+
var _proto = Canvas2DContextService.prototype;
|
|
378
|
+
_proto.init = /*#__PURE__*/function () {
|
|
379
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
380
|
+
var _this$canvasConfig, container, canvas, $canvas;
|
|
381
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
382
|
+
while (1) switch (_context.prev = _context.next) {
|
|
383
|
+
case 0:
|
|
384
|
+
_this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas;
|
|
385
|
+
if (canvas) {
|
|
386
|
+
this.$canvas = canvas;
|
|
387
|
+
if (container && canvas.parentElement !== container) {
|
|
388
|
+
container.appendChild(canvas);
|
|
389
|
+
}
|
|
390
|
+
this.$container = canvas.parentElement;
|
|
391
|
+
this.canvasConfig.container = this.$container;
|
|
392
|
+
} else if (container) {
|
|
393
|
+
// create container
|
|
394
|
+
this.$container = isString(container) ? document.getElementById(container) : container;
|
|
395
|
+
if (this.$container) {
|
|
396
|
+
// create canvas
|
|
397
|
+
$canvas = document.createElement('canvas');
|
|
398
|
+
this.$container.appendChild($canvas);
|
|
399
|
+
if (!this.$container.style.position) {
|
|
400
|
+
this.$container.style.position = 'relative';
|
|
497
401
|
}
|
|
402
|
+
this.$canvas = $canvas;
|
|
498
403
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
})
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
return init;
|
|
511
|
-
}()
|
|
512
|
-
}, {
|
|
513
|
-
key: "getContext",
|
|
514
|
-
value: function getContext() {
|
|
515
|
-
return this.context;
|
|
516
|
-
}
|
|
517
|
-
}, {
|
|
518
|
-
key: "getDomElement",
|
|
519
|
-
value: function getDomElement() {
|
|
520
|
-
return this.$canvas;
|
|
521
|
-
}
|
|
522
|
-
}, {
|
|
523
|
-
key: "getDPR",
|
|
524
|
-
value: function getDPR() {
|
|
525
|
-
return this.dpr;
|
|
404
|
+
}
|
|
405
|
+
this.context = this.$canvas.getContext('2d');
|
|
406
|
+
this.resize(this.canvasConfig.width, this.canvasConfig.height);
|
|
407
|
+
case 4:
|
|
408
|
+
case "end":
|
|
409
|
+
return _context.stop();
|
|
410
|
+
}
|
|
411
|
+
}, _callee, this);
|
|
412
|
+
}));
|
|
413
|
+
function init() {
|
|
414
|
+
return _init.apply(this, arguments);
|
|
526
415
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
416
|
+
return init;
|
|
417
|
+
}();
|
|
418
|
+
_proto.getContext = function getContext() {
|
|
419
|
+
return this.context;
|
|
420
|
+
};
|
|
421
|
+
_proto.getDomElement = function getDomElement() {
|
|
422
|
+
return this.$canvas;
|
|
423
|
+
};
|
|
424
|
+
_proto.getDPR = function getDPR() {
|
|
425
|
+
return this.dpr;
|
|
426
|
+
};
|
|
427
|
+
_proto.getBoundingClientRect = function getBoundingClientRect() {
|
|
428
|
+
if (this.$canvas.getBoundingClientRect) {
|
|
429
|
+
return this.$canvas.getBoundingClientRect();
|
|
533
430
|
}
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
|
|
431
|
+
};
|
|
432
|
+
_proto.destroy = function destroy() {
|
|
433
|
+
// @ts-ignore
|
|
434
|
+
if (this.$container && this.$canvas && this.$canvas.parentNode) {
|
|
435
|
+
// destroy context
|
|
537
436
|
// @ts-ignore
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
437
|
+
this.$container.removeChild(this.$canvas);
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
_proto.resize = function resize(width, height) {
|
|
441
|
+
var devicePixelRatio = this.canvasConfig.devicePixelRatio;
|
|
442
|
+
// use user-defined dpr first
|
|
443
|
+
var dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
|
|
444
|
+
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
445
|
+
this.dpr = dpr;
|
|
446
|
+
if (this.$canvas) {
|
|
447
|
+
// set canvas width & height
|
|
448
|
+
this.$canvas.width = this.dpr * width;
|
|
449
|
+
this.$canvas.height = this.dpr * height;
|
|
450
|
+
// set CSS style width & height
|
|
451
|
+
setDOMSize(this.$canvas, width, height);
|
|
452
|
+
// const dpr = this.getDPR();
|
|
453
|
+
// scale all drawing operations by the dpr
|
|
454
|
+
// @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
|
|
455
|
+
// this.context.scale(dpr, dpr);
|
|
543
456
|
}
|
|
544
|
-
}, {
|
|
545
|
-
key: "resize",
|
|
546
|
-
value: function resize(width, height) {
|
|
547
|
-
var devicePixelRatio = this.canvasConfig.devicePixelRatio;
|
|
548
|
-
// use user-defined dpr first
|
|
549
|
-
var dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
|
|
550
|
-
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
551
|
-
this.dpr = dpr;
|
|
552
|
-
if (this.$canvas) {
|
|
553
|
-
// set canvas width & height
|
|
554
|
-
this.$canvas.width = this.dpr * width;
|
|
555
|
-
this.$canvas.height = this.dpr * height;
|
|
556
|
-
// set CSS style width & height
|
|
557
|
-
setDOMSize(this.$canvas, width, height);
|
|
558
|
-
// const dpr = this.getDPR();
|
|
559
|
-
// scale all drawing operations by the dpr
|
|
560
|
-
// @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
|
|
561
|
-
// this.context.scale(dpr, dpr);
|
|
562
|
-
}
|
|
563
457
|
|
|
564
|
-
|
|
458
|
+
this.renderingContext.renderReasons.add(RenderReason.CAMERA_CHANGED);
|
|
459
|
+
};
|
|
460
|
+
_proto.applyCursorStyle = function applyCursorStyle(cursor) {
|
|
461
|
+
if (this.$container && this.$container.style) {
|
|
462
|
+
this.$container.style.cursor = cursor;
|
|
565
463
|
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
464
|
+
};
|
|
465
|
+
_proto.toDataURL = /*#__PURE__*/function () {
|
|
466
|
+
var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
|
|
467
|
+
var _options, type, encoderOptions;
|
|
468
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
469
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
470
|
+
case 0:
|
|
471
|
+
if (options === void 0) {
|
|
472
|
+
options = {};
|
|
473
|
+
}
|
|
474
|
+
_options = options, type = _options.type, encoderOptions = _options.encoderOptions;
|
|
475
|
+
return _context2.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
|
|
476
|
+
case 3:
|
|
477
|
+
case "end":
|
|
478
|
+
return _context2.stop();
|
|
479
|
+
}
|
|
480
|
+
}, _callee2, this);
|
|
481
|
+
}));
|
|
482
|
+
function toDataURL(_x) {
|
|
483
|
+
return _toDataURL.apply(this, arguments);
|
|
572
484
|
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
value: function () {
|
|
576
|
-
var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
577
|
-
var options,
|
|
578
|
-
type,
|
|
579
|
-
encoderOptions,
|
|
580
|
-
_args2 = arguments;
|
|
581
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
582
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
583
|
-
case 0:
|
|
584
|
-
options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
|
|
585
|
-
type = options.type, encoderOptions = options.encoderOptions;
|
|
586
|
-
return _context2.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
|
|
587
|
-
case 3:
|
|
588
|
-
case "end":
|
|
589
|
-
return _context2.stop();
|
|
590
|
-
}
|
|
591
|
-
}, _callee2, this);
|
|
592
|
-
}));
|
|
593
|
-
function toDataURL() {
|
|
594
|
-
return _toDataURL.apply(this, arguments);
|
|
595
|
-
}
|
|
596
|
-
return toDataURL;
|
|
597
|
-
}()
|
|
598
|
-
}]);
|
|
485
|
+
return toDataURL;
|
|
486
|
+
}();
|
|
599
487
|
return Canvas2DContextService;
|
|
600
488
|
}();
|
|
601
489
|
|
|
602
490
|
var ContextRegisterPlugin = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
603
|
-
|
|
604
|
-
var _super = _createSuper(ContextRegisterPlugin);
|
|
491
|
+
_inheritsLoose(ContextRegisterPlugin, _AbstractRendererPlug);
|
|
605
492
|
function ContextRegisterPlugin() {
|
|
606
493
|
var _this;
|
|
607
|
-
_classCallCheck(this, ContextRegisterPlugin);
|
|
608
494
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
609
495
|
args[_key] = arguments[_key];
|
|
610
496
|
}
|
|
611
|
-
_this =
|
|
497
|
+
_this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
|
|
612
498
|
_this.name = 'canvas-context-register';
|
|
613
499
|
return _this;
|
|
614
500
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
value: function destroy() {
|
|
623
|
-
delete this.context.ContextService;
|
|
624
|
-
}
|
|
625
|
-
}]);
|
|
501
|
+
var _proto = ContextRegisterPlugin.prototype;
|
|
502
|
+
_proto.init = function init() {
|
|
503
|
+
this.context.ContextService = Canvas2DContextService;
|
|
504
|
+
};
|
|
505
|
+
_proto.destroy = function destroy() {
|
|
506
|
+
delete this.context.ContextService;
|
|
507
|
+
};
|
|
626
508
|
return ContextRegisterPlugin;
|
|
627
509
|
}(AbstractRendererPlugin);
|
|
628
510
|
|
|
629
511
|
var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
630
|
-
|
|
631
|
-
var _super = _createSuper(Renderer);
|
|
512
|
+
_inheritsLoose(Renderer, _AbstractRenderer);
|
|
632
513
|
function Renderer(config) {
|
|
633
514
|
var _this;
|
|
634
|
-
|
|
635
|
-
_this = _super.call(this, config);
|
|
515
|
+
_this = _AbstractRenderer.call(this, config) || this;
|
|
636
516
|
// register Canvas2DContext
|
|
637
517
|
_this.registerPlugin(new ContextRegisterPlugin());
|
|
638
518
|
_this.registerPlugin(new Plugin());
|
|
@@ -646,7 +526,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
|
646
526
|
_this.registerPlugin(new Plugin$5());
|
|
647
527
|
return _this;
|
|
648
528
|
}
|
|
649
|
-
return
|
|
529
|
+
return Renderer;
|
|
650
530
|
}(AbstractRenderer);
|
|
651
531
|
|
|
652
532
|
export { Renderer };
|