@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.
@@ -1,3 +1,4 @@
1
+ import type { DataURLOptions } from '@antv/g';
1
2
  import { ContextService } from '@antv/g';
2
3
  export declare class SVGContextService implements ContextService<SVGElement> {
3
4
  private $container;
@@ -12,5 +13,6 @@ export declare class SVGContextService implements ContextService<SVGElement> {
12
13
  destroy(): void;
13
14
  resize(width: number, height: number): void;
14
15
  applyCursorStyle(cursor: string): void;
16
+ toDataURL(options?: Partial<DataURLOptions>): Promise<string>;
15
17
  }
16
18
  //# sourceMappingURL=SVGContextService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SVGContextService.d.ts","sourceRoot":"","sources":["../src/SVGContextService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,cAAc,EAA+B,MAAM,SAAS,CAAC;AAGpF,qBACa,iBAAkB,YAAW,cAAc,CAAC,UAAU,CAAC;IAClE,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,UAAU,CAAoB;IACtC,OAAO,CAAC,GAAG,CAAS;IAGpB,OAAO,CAAC,YAAY,CAAe;IAE7B,IAAI;IAwBV,aAAa;IAIb,UAAU;IAIV,MAAM;IAIN,qBAAqB;IAIrB,OAAO;IAOP,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAOpC,gBAAgB,CAAC,MAAM,EAAE,MAAM;CAKhC"}
1
+ {"version":3,"file":"SVGContextService.d.ts","sourceRoot":"","sources":["../src/SVGContextService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAgB,cAAc,EAA+B,MAAM,SAAS,CAAC;AAGpF,qBACa,iBAAkB,YAAW,cAAc,CAAC,UAAU,CAAC;IAClE,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,UAAU,CAAoB;IACtC,OAAO,CAAC,GAAG,CAAS;IAGpB,OAAO,CAAC,YAAY,CAAe;IAE7B,IAAI;IAwBV,aAAa;IAIb,UAAU;IAIV,MAAM;IAIN,qBAAqB;IAIrB,OAAO;IAOP,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAOpC,gBAAgB,CAAC,MAAM,EAAE,MAAM;IAMzB,SAAS,CAAC,OAAO,GAAE,OAAO,CAAC,cAAc,CAAM;CAiBtD"}
package/dist/index.esm.js CHANGED
@@ -391,54 +391,11 @@ function _asyncToGenerator(fn) {
391
391
  };
392
392
  }
393
393
 
394
- function _classCallCheck(instance, Constructor) {
395
- if (!(instance instanceof Constructor)) {
396
- throw new TypeError("Cannot call a class as a function");
397
- }
398
- }
399
-
400
- function _defineProperties(target, props) {
401
- for (var i = 0; i < props.length; i++) {
402
- var descriptor = props[i];
403
- descriptor.enumerable = descriptor.enumerable || false;
404
- descriptor.configurable = true;
405
- if ("value" in descriptor) descriptor.writable = true;
406
- Object.defineProperty(target, descriptor.key, descriptor);
407
- }
408
- }
394
+ function _inheritsLoose(subClass, superClass) {
395
+ subClass.prototype = Object.create(superClass.prototype);
396
+ subClass.prototype.constructor = subClass;
409
397
 
410
- function _createClass(Constructor, protoProps, staticProps) {
411
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
412
- if (staticProps) _defineProperties(Constructor, staticProps);
413
- Object.defineProperty(Constructor, "prototype", {
414
- writable: false
415
- });
416
- return Constructor;
417
- }
418
-
419
- function _inherits(subClass, superClass) {
420
- if (typeof superClass !== "function" && superClass !== null) {
421
- throw new TypeError("Super expression must either be null or a function");
422
- }
423
-
424
- subClass.prototype = Object.create(superClass && superClass.prototype, {
425
- constructor: {
426
- value: subClass,
427
- writable: true,
428
- configurable: true
429
- }
430
- });
431
- Object.defineProperty(subClass, "prototype", {
432
- writable: false
433
- });
434
- if (superClass) _setPrototypeOf(subClass, superClass);
435
- }
436
-
437
- function _getPrototypeOf(o) {
438
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
439
- return o.__proto__ || Object.getPrototypeOf(o);
440
- };
441
- return _getPrototypeOf(o);
398
+ _setPrototypeOf(subClass, superClass);
442
399
  }
443
400
 
444
401
  function _setPrototypeOf(o, p) {
@@ -449,157 +406,126 @@ function _setPrototypeOf(o, p) {
449
406
  return _setPrototypeOf(o, p);
450
407
  }
451
408
 
452
- function _isNativeReflectConstruct() {
453
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
454
- if (Reflect.construct.sham) return false;
455
- if (typeof Proxy === "function") return true;
456
-
457
- try {
458
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
459
- return true;
460
- } catch (e) {
461
- return false;
462
- }
463
- }
464
-
465
- function _assertThisInitialized(self) {
466
- if (self === void 0) {
467
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
409
+ var SVGContextService = /*#__PURE__*/function () {
410
+ function SVGContextService() {
411
+ this.$container = void 0;
412
+ this.$namespace = void 0;
413
+ this.dpr = void 0;
414
+ this.canvasConfig = void 0;
468
415
  }
469
416
 
470
- return self;
471
- }
417
+ var _proto = SVGContextService.prototype;
472
418
 
473
- function _possibleConstructorReturn(self, call) {
474
- if (call && (typeof call === "object" || typeof call === "function")) {
475
- return call;
476
- } else if (call !== void 0) {
477
- throw new TypeError("Derived constructors may only return object or undefined");
478
- }
419
+ _proto.init = /*#__PURE__*/function () {
420
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
421
+ var _this$canvasConfig, container, doc, $namespace, dpr;
479
422
 
480
- return _assertThisInitialized(self);
481
- }
423
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
424
+ while (1) {
425
+ switch (_context.prev = _context.next) {
426
+ case 0:
427
+ _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, doc = _this$canvasConfig.document; // create container
482
428
 
483
- function _createSuper(Derived) {
484
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
429
+ this.$container = isString(container) ? (doc || document).getElementById(container) : container;
485
430
 
486
- return function _createSuperInternal() {
487
- var Super = _getPrototypeOf(Derived),
488
- result;
431
+ if (this.$container) {
432
+ if (!this.$container.style.position) {
433
+ this.$container.style.position = 'relative';
434
+ }
489
435
 
490
- if (hasNativeReflectConstruct) {
491
- var NewTarget = _getPrototypeOf(this).constructor;
436
+ $namespace = createSVGElement('svg', doc);
437
+ $namespace.setAttribute('width', "" + this.canvasConfig.width);
438
+ $namespace.setAttribute('height', "" + this.canvasConfig.height);
439
+ this.$container.appendChild($namespace);
440
+ this.$namespace = $namespace;
441
+ }
492
442
 
493
- result = Reflect.construct(Super, arguments, NewTarget);
494
- } else {
495
- result = Super.apply(this, arguments);
496
- }
443
+ dpr = window.devicePixelRatio || 1;
444
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
445
+ this.dpr = dpr;
497
446
 
498
- return _possibleConstructorReturn(this, result);
499
- };
500
- }
447
+ case 6:
448
+ case "end":
449
+ return _context.stop();
450
+ }
451
+ }
452
+ }, _callee, this);
453
+ }));
501
454
 
502
- var SVGContextService = /*#__PURE__*/function () {
503
- function SVGContextService() {
504
- _classCallCheck(this, SVGContextService);
455
+ function init() {
456
+ return _init.apply(this, arguments);
457
+ }
505
458
 
506
- this.$container = void 0;
507
- this.$namespace = void 0;
508
- this.dpr = void 0;
509
- this.canvasConfig = void 0;
510
- }
459
+ return init;
460
+ }() // @ts-ignore
461
+ ;
511
462
 
512
- _createClass(SVGContextService, [{
513
- key: "init",
514
- value: function () {
515
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
516
- var _this$canvasConfig, container, doc, $namespace, dpr;
517
-
518
- return _regeneratorRuntime().wrap(function _callee$(_context) {
519
- while (1) {
520
- switch (_context.prev = _context.next) {
521
- case 0:
522
- _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, doc = _this$canvasConfig.document; // create container
523
-
524
- this.$container = isString(container) ? (doc || document).getElementById(container) : container;
525
-
526
- if (this.$container) {
527
- if (!this.$container.style.position) {
528
- this.$container.style.position = 'relative';
529
- }
530
-
531
- $namespace = createSVGElement('svg', doc);
532
- $namespace.setAttribute('width', "".concat(this.canvasConfig.width));
533
- $namespace.setAttribute('height', "".concat(this.canvasConfig.height));
534
- this.$container.appendChild($namespace);
535
- this.$namespace = $namespace;
536
- }
463
+ _proto.getDomElement = function getDomElement() {
464
+ return this.$namespace;
465
+ };
537
466
 
538
- dpr = window.devicePixelRatio || 1;
539
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
540
- this.dpr = dpr;
467
+ _proto.getContext = function getContext() {
468
+ return this.$namespace;
469
+ };
541
470
 
542
- case 6:
543
- case "end":
544
- return _context.stop();
545
- }
546
- }
547
- }, _callee, this);
548
- }));
471
+ _proto.getDPR = function getDPR() {
472
+ return this.dpr;
473
+ };
549
474
 
550
- function init() {
551
- return _init.apply(this, arguments);
552
- }
475
+ _proto.getBoundingClientRect = function getBoundingClientRect() {
476
+ var _this$$namespace;
553
477
 
554
- return init;
555
- }() // @ts-ignore
478
+ return (_this$$namespace = this.$namespace) === null || _this$$namespace === void 0 ? void 0 : _this$$namespace.getBoundingClientRect();
479
+ };
556
480
 
557
- }, {
558
- key: "getDomElement",
559
- value: function getDomElement() {
560
- return this.$namespace;
561
- }
562
- }, {
563
- key: "getContext",
564
- value: function getContext() {
565
- return this.$namespace;
481
+ _proto.destroy = function destroy() {
482
+ // destroy context
483
+ if (this.$container && this.$namespace && this.$namespace.parentNode) {
484
+ this.$container.removeChild(this.$namespace);
566
485
  }
567
- }, {
568
- key: "getDPR",
569
- value: function getDPR() {
570
- return this.dpr;
571
- }
572
- }, {
573
- key: "getBoundingClientRect",
574
- value: function getBoundingClientRect() {
575
- var _this$$namespace;
486
+ };
576
487
 
577
- return (_this$$namespace = this.$namespace) === null || _this$$namespace === void 0 ? void 0 : _this$$namespace.getBoundingClientRect();
578
- }
579
- }, {
580
- key: "destroy",
581
- value: function destroy() {
582
- // destroy context
583
- if (this.$container && this.$namespace && this.$namespace.parentNode) {
584
- this.$container.removeChild(this.$namespace);
585
- }
488
+ _proto.resize = function resize(width, height) {
489
+ if (this.$namespace) {
490
+ this.$namespace.setAttribute('width', "" + width);
491
+ this.$namespace.setAttribute('height', "" + height);
586
492
  }
587
- }, {
588
- key: "resize",
589
- value: function resize(width, height) {
590
- if (this.$namespace) {
591
- this.$namespace.setAttribute('width', "".concat(width));
592
- this.$namespace.setAttribute('height', "".concat(height));
593
- }
493
+ };
494
+
495
+ _proto.applyCursorStyle = function applyCursorStyle(cursor) {
496
+ if (this.$container) {
497
+ this.$container.style.cursor = cursor;
594
498
  }
595
- }, {
596
- key: "applyCursorStyle",
597
- value: function applyCursorStyle(cursor) {
598
- if (this.$container) {
599
- this.$container.style.cursor = cursor;
600
- }
499
+ };
500
+
501
+ _proto.toDataURL = /*#__PURE__*/function () {
502
+ var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
503
+ var cloneNode, svgDocType, svgDoc;
504
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
505
+ while (1) {
506
+ switch (_context2.prev = _context2.next) {
507
+ case 0:
508
+
509
+ cloneNode = this.$namespace.cloneNode(true);
510
+ svgDocType = document.implementation.createDocumentType('svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
511
+ svgDoc = document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg', svgDocType);
512
+ svgDoc.replaceChild(cloneNode, svgDoc.documentElement);
513
+ return _context2.abrupt("return", "data:image/svg+xml;charset=utf8," + encodeURIComponent(new XMLSerializer().serializeToString(svgDoc)));
514
+
515
+ case 6:
516
+ case "end":
517
+ return _context2.stop();
518
+ }
519
+ }
520
+ }, _callee2, this);
521
+ }));
522
+
523
+ function toDataURL(_x) {
524
+ return _toDataURL.apply(this, arguments);
601
525
  }
602
- }]);
526
+
527
+ return toDataURL;
528
+ }();
603
529
 
604
530
  return SVGContextService;
605
531
  }();
@@ -618,37 +544,29 @@ var containerModule = Module(function (register) {
618
544
  });
619
545
  var ContextRegisterPlugin = /*#__PURE__*/function () {
620
546
  function ContextRegisterPlugin() {
621
- _classCallCheck(this, ContextRegisterPlugin);
622
-
623
547
  this.name = 'svg-context-register';
624
548
  }
625
549
 
626
- _createClass(ContextRegisterPlugin, [{
627
- key: "init",
628
- value: function init(container) {
629
- container.load(containerModule, true);
630
- }
631
- }, {
632
- key: "destroy",
633
- value: function destroy(container) {
634
- container.unload(containerModule);
635
- }
636
- }]);
550
+ var _proto = ContextRegisterPlugin.prototype;
551
+
552
+ _proto.init = function init(container) {
553
+ container.load(containerModule, true);
554
+ };
555
+
556
+ _proto.destroy = function destroy(container) {
557
+ container.unload(containerModule);
558
+ };
637
559
 
638
560
  return ContextRegisterPlugin;
639
561
  }();
640
562
 
641
563
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
642
- _inherits(Renderer, _AbstractRenderer);
643
-
644
- var _super = _createSuper(Renderer);
564
+ _inheritsLoose(Renderer, _AbstractRenderer);
645
565
 
646
566
  function Renderer(config) {
647
567
  var _this;
648
568
 
649
- _classCallCheck(this, Renderer);
650
-
651
- _this = _super.call(this, config);
569
+ _this = _AbstractRenderer.call(this, config) || this;
652
570
 
653
571
  _this.registerPlugin(new ContextRegisterPlugin());
654
572
 
@@ -661,7 +579,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
661
579
  return _this;
662
580
  }
663
581
 
664
- return _createClass(Renderer);
582
+ return Renderer;
665
583
  }(AbstractRenderer);
666
584
 
667
585
  export { Renderer };