@antv/g-svg 1.2.1 → 1.3.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.js CHANGED
@@ -413,54 +413,11 @@ function _asyncToGenerator(fn) {
413
413
  };
414
414
  }
415
415
 
416
- function _classCallCheck(instance, Constructor) {
417
- if (!(instance instanceof Constructor)) {
418
- throw new TypeError("Cannot call a class as a function");
419
- }
420
- }
421
-
422
- function _defineProperties(target, props) {
423
- for (var i = 0; i < props.length; i++) {
424
- var descriptor = props[i];
425
- descriptor.enumerable = descriptor.enumerable || false;
426
- descriptor.configurable = true;
427
- if ("value" in descriptor) descriptor.writable = true;
428
- Object.defineProperty(target, descriptor.key, descriptor);
429
- }
430
- }
416
+ function _inheritsLoose(subClass, superClass) {
417
+ subClass.prototype = Object.create(superClass.prototype);
418
+ subClass.prototype.constructor = subClass;
431
419
 
432
- function _createClass(Constructor, protoProps, staticProps) {
433
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
434
- if (staticProps) _defineProperties(Constructor, staticProps);
435
- Object.defineProperty(Constructor, "prototype", {
436
- writable: false
437
- });
438
- return Constructor;
439
- }
440
-
441
- function _inherits(subClass, superClass) {
442
- if (typeof superClass !== "function" && superClass !== null) {
443
- throw new TypeError("Super expression must either be null or a function");
444
- }
445
-
446
- subClass.prototype = Object.create(superClass && superClass.prototype, {
447
- constructor: {
448
- value: subClass,
449
- writable: true,
450
- configurable: true
451
- }
452
- });
453
- Object.defineProperty(subClass, "prototype", {
454
- writable: false
455
- });
456
- if (superClass) _setPrototypeOf(subClass, superClass);
457
- }
458
-
459
- function _getPrototypeOf(o) {
460
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
461
- return o.__proto__ || Object.getPrototypeOf(o);
462
- };
463
- return _getPrototypeOf(o);
420
+ _setPrototypeOf(subClass, superClass);
464
421
  }
465
422
 
466
423
  function _setPrototypeOf(o, p) {
@@ -471,157 +428,126 @@ function _setPrototypeOf(o, p) {
471
428
  return _setPrototypeOf(o, p);
472
429
  }
473
430
 
474
- function _isNativeReflectConstruct() {
475
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
476
- if (Reflect.construct.sham) return false;
477
- if (typeof Proxy === "function") return true;
478
-
479
- try {
480
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
481
- return true;
482
- } catch (e) {
483
- return false;
484
- }
485
- }
486
-
487
- function _assertThisInitialized(self) {
488
- if (self === void 0) {
489
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
431
+ var SVGContextService = /*#__PURE__*/function () {
432
+ function SVGContextService() {
433
+ this.$container = void 0;
434
+ this.$namespace = void 0;
435
+ this.dpr = void 0;
436
+ this.canvasConfig = void 0;
490
437
  }
491
438
 
492
- return self;
493
- }
439
+ var _proto = SVGContextService.prototype;
494
440
 
495
- function _possibleConstructorReturn(self, call) {
496
- if (call && (typeof call === "object" || typeof call === "function")) {
497
- return call;
498
- } else if (call !== void 0) {
499
- throw new TypeError("Derived constructors may only return object or undefined");
500
- }
441
+ _proto.init = /*#__PURE__*/function () {
442
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
443
+ var _this$canvasConfig, container, doc, $namespace, dpr;
501
444
 
502
- return _assertThisInitialized(self);
503
- }
445
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
446
+ while (1) {
447
+ switch (_context.prev = _context.next) {
448
+ case 0:
449
+ _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, doc = _this$canvasConfig.document; // create container
504
450
 
505
- function _createSuper(Derived) {
506
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
451
+ this.$container = g.isString(container) ? (doc || document).getElementById(container) : container;
507
452
 
508
- return function _createSuperInternal() {
509
- var Super = _getPrototypeOf(Derived),
510
- result;
453
+ if (this.$container) {
454
+ if (!this.$container.style.position) {
455
+ this.$container.style.position = 'relative';
456
+ }
511
457
 
512
- if (hasNativeReflectConstruct) {
513
- var NewTarget = _getPrototypeOf(this).constructor;
458
+ $namespace = SVGRenderer.createSVGElement('svg', doc);
459
+ $namespace.setAttribute('width', "" + this.canvasConfig.width);
460
+ $namespace.setAttribute('height', "" + this.canvasConfig.height);
461
+ this.$container.appendChild($namespace);
462
+ this.$namespace = $namespace;
463
+ }
514
464
 
515
- result = Reflect.construct(Super, arguments, NewTarget);
516
- } else {
517
- result = Super.apply(this, arguments);
518
- }
465
+ dpr = window.devicePixelRatio || 1;
466
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
467
+ this.dpr = dpr;
519
468
 
520
- return _possibleConstructorReturn(this, result);
521
- };
522
- }
469
+ case 6:
470
+ case "end":
471
+ return _context.stop();
472
+ }
473
+ }
474
+ }, _callee, this);
475
+ }));
523
476
 
524
- var SVGContextService = /*#__PURE__*/function () {
525
- function SVGContextService() {
526
- _classCallCheck(this, SVGContextService);
477
+ function init() {
478
+ return _init.apply(this, arguments);
479
+ }
527
480
 
528
- this.$container = void 0;
529
- this.$namespace = void 0;
530
- this.dpr = void 0;
531
- this.canvasConfig = void 0;
532
- }
481
+ return init;
482
+ }() // @ts-ignore
483
+ ;
533
484
 
534
- _createClass(SVGContextService, [{
535
- key: "init",
536
- value: function () {
537
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
538
- var _this$canvasConfig, container, doc, $namespace, dpr;
539
-
540
- return _regeneratorRuntime().wrap(function _callee$(_context) {
541
- while (1) {
542
- switch (_context.prev = _context.next) {
543
- case 0:
544
- _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, doc = _this$canvasConfig.document; // create container
545
-
546
- this.$container = g.isString(container) ? (doc || document).getElementById(container) : container;
547
-
548
- if (this.$container) {
549
- if (!this.$container.style.position) {
550
- this.$container.style.position = 'relative';
551
- }
552
-
553
- $namespace = SVGRenderer.createSVGElement('svg', doc);
554
- $namespace.setAttribute('width', "".concat(this.canvasConfig.width));
555
- $namespace.setAttribute('height', "".concat(this.canvasConfig.height));
556
- this.$container.appendChild($namespace);
557
- this.$namespace = $namespace;
558
- }
485
+ _proto.getDomElement = function getDomElement() {
486
+ return this.$namespace;
487
+ };
559
488
 
560
- dpr = window.devicePixelRatio || 1;
561
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
562
- this.dpr = dpr;
489
+ _proto.getContext = function getContext() {
490
+ return this.$namespace;
491
+ };
563
492
 
564
- case 6:
565
- case "end":
566
- return _context.stop();
567
- }
568
- }
569
- }, _callee, this);
570
- }));
493
+ _proto.getDPR = function getDPR() {
494
+ return this.dpr;
495
+ };
571
496
 
572
- function init() {
573
- return _init.apply(this, arguments);
574
- }
497
+ _proto.getBoundingClientRect = function getBoundingClientRect() {
498
+ var _this$$namespace;
575
499
 
576
- return init;
577
- }() // @ts-ignore
500
+ return (_this$$namespace = this.$namespace) === null || _this$$namespace === void 0 ? void 0 : _this$$namespace.getBoundingClientRect();
501
+ };
578
502
 
579
- }, {
580
- key: "getDomElement",
581
- value: function getDomElement() {
582
- return this.$namespace;
583
- }
584
- }, {
585
- key: "getContext",
586
- value: function getContext() {
587
- return this.$namespace;
503
+ _proto.destroy = function destroy() {
504
+ // destroy context
505
+ if (this.$container && this.$namespace && this.$namespace.parentNode) {
506
+ this.$container.removeChild(this.$namespace);
588
507
  }
589
- }, {
590
- key: "getDPR",
591
- value: function getDPR() {
592
- return this.dpr;
593
- }
594
- }, {
595
- key: "getBoundingClientRect",
596
- value: function getBoundingClientRect() {
597
- var _this$$namespace;
508
+ };
598
509
 
599
- return (_this$$namespace = this.$namespace) === null || _this$$namespace === void 0 ? void 0 : _this$$namespace.getBoundingClientRect();
600
- }
601
- }, {
602
- key: "destroy",
603
- value: function destroy() {
604
- // destroy context
605
- if (this.$container && this.$namespace && this.$namespace.parentNode) {
606
- this.$container.removeChild(this.$namespace);
607
- }
510
+ _proto.resize = function resize(width, height) {
511
+ if (this.$namespace) {
512
+ this.$namespace.setAttribute('width', "" + width);
513
+ this.$namespace.setAttribute('height', "" + height);
608
514
  }
609
- }, {
610
- key: "resize",
611
- value: function resize(width, height) {
612
- if (this.$namespace) {
613
- this.$namespace.setAttribute('width', "".concat(width));
614
- this.$namespace.setAttribute('height', "".concat(height));
615
- }
515
+ };
516
+
517
+ _proto.applyCursorStyle = function applyCursorStyle(cursor) {
518
+ if (this.$container) {
519
+ this.$container.style.cursor = cursor;
616
520
  }
617
- }, {
618
- key: "applyCursorStyle",
619
- value: function applyCursorStyle(cursor) {
620
- if (this.$container) {
621
- this.$container.style.cursor = cursor;
622
- }
521
+ };
522
+
523
+ _proto.toDataURL = /*#__PURE__*/function () {
524
+ var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
525
+ var cloneNode, svgDocType, svgDoc;
526
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
527
+ while (1) {
528
+ switch (_context2.prev = _context2.next) {
529
+ case 0:
530
+
531
+ cloneNode = this.$namespace.cloneNode(true);
532
+ svgDocType = document.implementation.createDocumentType('svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
533
+ svgDoc = document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg', svgDocType);
534
+ svgDoc.replaceChild(cloneNode, svgDoc.documentElement);
535
+ return _context2.abrupt("return", "data:image/svg+xml;charset=utf8," + encodeURIComponent(new XMLSerializer().serializeToString(svgDoc)));
536
+
537
+ case 6:
538
+ case "end":
539
+ return _context2.stop();
540
+ }
541
+ }
542
+ }, _callee2, this);
543
+ }));
544
+
545
+ function toDataURL(_x) {
546
+ return _toDataURL.apply(this, arguments);
623
547
  }
624
- }]);
548
+
549
+ return toDataURL;
550
+ }();
625
551
 
626
552
  return SVGContextService;
627
553
  }();
@@ -640,37 +566,29 @@ var containerModule = g.Module(function (register) {
640
566
  });
641
567
  var ContextRegisterPlugin = /*#__PURE__*/function () {
642
568
  function ContextRegisterPlugin() {
643
- _classCallCheck(this, ContextRegisterPlugin);
644
-
645
569
  this.name = 'svg-context-register';
646
570
  }
647
571
 
648
- _createClass(ContextRegisterPlugin, [{
649
- key: "init",
650
- value: function init(container) {
651
- container.load(containerModule, true);
652
- }
653
- }, {
654
- key: "destroy",
655
- value: function destroy(container) {
656
- container.unload(containerModule);
657
- }
658
- }]);
572
+ var _proto = ContextRegisterPlugin.prototype;
573
+
574
+ _proto.init = function init(container) {
575
+ container.load(containerModule, true);
576
+ };
577
+
578
+ _proto.destroy = function destroy(container) {
579
+ container.unload(containerModule);
580
+ };
659
581
 
660
582
  return ContextRegisterPlugin;
661
583
  }();
662
584
 
663
585
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
664
- _inherits(Renderer, _AbstractRenderer);
665
-
666
- var _super = _createSuper(Renderer);
586
+ _inheritsLoose(Renderer, _AbstractRenderer);
667
587
 
668
588
  function Renderer(config) {
669
589
  var _this;
670
590
 
671
- _classCallCheck(this, Renderer);
672
-
673
- _this = _super.call(this, config);
591
+ _this = _AbstractRenderer.call(this, config) || this;
674
592
 
675
593
  _this.registerPlugin(new ContextRegisterPlugin());
676
594
 
@@ -683,7 +601,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
683
601
  return _this;
684
602
  }
685
603
 
686
- return _createClass(Renderer);
604
+ return Renderer;
687
605
  }(g.AbstractRenderer);
688
606
 
689
607
  exports.DomInteraction = DomInteraction__namespace;