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