@antv/g-svg 1.8.29 → 1.8.30

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
@@ -363,49 +363,10 @@ function _asyncToGenerator(fn) {
363
363
  });
364
364
  };
365
365
  }
366
- function _classCallCheck(instance, Constructor) {
367
- if (!(instance instanceof Constructor)) {
368
- throw new TypeError("Cannot call a class as a function");
369
- }
370
- }
371
- function _defineProperties(target, props) {
372
- for (var i = 0; i < props.length; i++) {
373
- var descriptor = props[i];
374
- descriptor.enumerable = descriptor.enumerable || false;
375
- descriptor.configurable = true;
376
- if ("value" in descriptor) descriptor.writable = true;
377
- Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
378
- }
379
- }
380
- function _createClass(Constructor, protoProps, staticProps) {
381
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
382
- if (staticProps) _defineProperties(Constructor, staticProps);
383
- Object.defineProperty(Constructor, "prototype", {
384
- writable: false
385
- });
386
- return Constructor;
387
- }
388
- function _inherits(subClass, superClass) {
389
- if (typeof superClass !== "function" && superClass !== null) {
390
- throw new TypeError("Super expression must either be null or a function");
391
- }
392
- subClass.prototype = Object.create(superClass && superClass.prototype, {
393
- constructor: {
394
- value: subClass,
395
- writable: true,
396
- configurable: true
397
- }
398
- });
399
- Object.defineProperty(subClass, "prototype", {
400
- writable: false
401
- });
402
- if (superClass) _setPrototypeOf(subClass, superClass);
403
- }
404
- function _getPrototypeOf(o) {
405
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
406
- return o.__proto__ || Object.getPrototypeOf(o);
407
- };
408
- return _getPrototypeOf(o);
366
+ function _inheritsLoose(subClass, superClass) {
367
+ subClass.prototype = Object.create(superClass.prototype);
368
+ subClass.prototype.constructor = subClass;
369
+ _setPrototypeOf(subClass, superClass);
409
370
  }
410
371
  function _setPrototypeOf(o, p) {
411
372
  _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
@@ -414,219 +375,140 @@ function _setPrototypeOf(o, p) {
414
375
  };
415
376
  return _setPrototypeOf(o, p);
416
377
  }
417
- function _isNativeReflectConstruct() {
418
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
419
- if (Reflect.construct.sham) return false;
420
- if (typeof Proxy === "function") return true;
421
- try {
422
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
423
- return true;
424
- } catch (e) {
425
- return false;
426
- }
427
- }
428
- function _assertThisInitialized(self) {
429
- if (self === void 0) {
430
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
431
- }
432
- return self;
433
- }
434
- function _possibleConstructorReturn(self, call) {
435
- if (call && (typeof call === "object" || typeof call === "function")) {
436
- return call;
437
- } else if (call !== void 0) {
438
- throw new TypeError("Derived constructors may only return object or undefined");
439
- }
440
- return _assertThisInitialized(self);
441
- }
442
- function _createSuper(Derived) {
443
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
444
- return function _createSuperInternal() {
445
- var Super = _getPrototypeOf(Derived),
446
- result;
447
- if (hasNativeReflectConstruct) {
448
- var NewTarget = _getPrototypeOf(this).constructor;
449
- result = Reflect.construct(Super, arguments, NewTarget);
450
- } else {
451
- result = Super.apply(this, arguments);
452
- }
453
- return _possibleConstructorReturn(this, result);
454
- };
455
- }
456
- function _toPrimitive(input, hint) {
457
- if (typeof input !== "object" || input === null) return input;
458
- var prim = input[Symbol.toPrimitive];
459
- if (prim !== undefined) {
460
- var res = prim.call(input, hint || "default");
461
- if (typeof res !== "object") return res;
462
- throw new TypeError("@@toPrimitive must return a primitive value.");
463
- }
464
- return (hint === "string" ? String : Number)(input);
465
- }
466
- function _toPropertyKey(arg) {
467
- var key = _toPrimitive(arg, "string");
468
- return typeof key === "symbol" ? key : String(key);
469
- }
470
378
 
471
379
  var SVGContextService = /*#__PURE__*/function () {
472
380
  function SVGContextService(context) {
473
- _classCallCheck(this, SVGContextService);
474
381
  this.$container = void 0;
475
382
  this.$namespace = void 0;
476
383
  this.dpr = void 0;
477
384
  this.canvasConfig = void 0;
478
385
  this.canvasConfig = context.config;
479
386
  }
480
- _createClass(SVGContextService, [{
481
- key: "init",
482
- value: function () {
483
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
484
- var _this$canvasConfig, container, doc, devicePixelRatio, $namespace, dpr;
485
- return _regeneratorRuntime().wrap(function _callee$(_context) {
486
- while (1) {
487
- switch (_context.prev = _context.next) {
488
- case 0:
489
- _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, doc = _this$canvasConfig.document, devicePixelRatio = _this$canvasConfig.devicePixelRatio; // create container
490
- this.$container = util.isString(container) ? (doc || document).getElementById(container) : container;
491
- if (this.$container) {
492
- if (!this.$container.style.position) {
493
- this.$container.style.position = 'relative';
494
- }
495
- $namespace = SVGRenderer.createSVGElement('svg', doc);
496
- $namespace.setAttribute('width', "".concat(this.canvasConfig.width));
497
- $namespace.setAttribute('height', "".concat(this.canvasConfig.height));
498
- this.$container.appendChild($namespace);
499
- this.$namespace = $namespace;
387
+ var _proto = SVGContextService.prototype;
388
+ _proto.init = /*#__PURE__*/function () {
389
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
390
+ var _this$canvasConfig, container, doc, devicePixelRatio, $namespace, dpr;
391
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
392
+ while (1) {
393
+ switch (_context.prev = _context.next) {
394
+ case 0:
395
+ _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, doc = _this$canvasConfig.document, devicePixelRatio = _this$canvasConfig.devicePixelRatio; // create container
396
+ this.$container = util.isString(container) ? (doc || document).getElementById(container) : container;
397
+ if (this.$container) {
398
+ if (!this.$container.style.position) {
399
+ this.$container.style.position = 'relative';
500
400
  }
501
- // use user-defined dpr first
502
- dpr = devicePixelRatio || gLite.isBrowser && window.devicePixelRatio || 1;
503
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
504
- this.dpr = dpr;
505
- case 6:
506
- case "end":
507
- return _context.stop();
508
- }
401
+ $namespace = SVGRenderer.createSVGElement('svg', doc);
402
+ $namespace.setAttribute('width', "" + this.canvasConfig.width);
403
+ $namespace.setAttribute('height', "" + this.canvasConfig.height);
404
+ this.$container.appendChild($namespace);
405
+ this.$namespace = $namespace;
406
+ }
407
+ // use user-defined dpr first
408
+ dpr = devicePixelRatio || gLite.isBrowser && window.devicePixelRatio || 1;
409
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
410
+ this.dpr = dpr;
411
+ case 6:
412
+ case "end":
413
+ return _context.stop();
509
414
  }
510
- }, _callee, this);
511
- }));
512
- function init() {
513
- return _init.apply(this, arguments);
514
- }
515
- return init;
516
- }() // @ts-ignore
517
- }, {
518
- key: "getDomElement",
519
- value: function getDomElement() {
520
- return this.$namespace;
521
- }
522
- }, {
523
- key: "getContext",
524
- value: function getContext() {
525
- return this.$namespace;
526
- }
527
- }, {
528
- key: "getDPR",
529
- value: function getDPR() {
530
- return this.dpr;
531
- }
532
- }, {
533
- key: "getBoundingClientRect",
534
- value: function getBoundingClientRect() {
535
- var _this$$namespace;
536
- return (_this$$namespace = this.$namespace) === null || _this$$namespace === void 0 ? void 0 : _this$$namespace.getBoundingClientRect();
415
+ }
416
+ }, _callee, this);
417
+ }));
418
+ function init() {
419
+ return _init.apply(this, arguments);
537
420
  }
538
- }, {
539
- key: "destroy",
540
- value: function destroy() {
541
- // destroy context
542
- if (this.$container && this.$namespace && this.$namespace.parentNode) {
543
- this.$container.removeChild(this.$namespace);
544
- }
421
+ return init;
422
+ }() // @ts-ignore
423
+ ;
424
+ _proto.getDomElement = function getDomElement() {
425
+ return this.$namespace;
426
+ };
427
+ _proto.getContext = function getContext() {
428
+ return this.$namespace;
429
+ };
430
+ _proto.getDPR = function getDPR() {
431
+ return this.dpr;
432
+ };
433
+ _proto.getBoundingClientRect = function getBoundingClientRect() {
434
+ var _this$$namespace;
435
+ return (_this$$namespace = this.$namespace) === null || _this$$namespace === void 0 ? void 0 : _this$$namespace.getBoundingClientRect();
436
+ };
437
+ _proto.destroy = function destroy() {
438
+ // destroy context
439
+ if (this.$container && this.$namespace && this.$namespace.parentNode) {
440
+ this.$container.removeChild(this.$namespace);
545
441
  }
546
- }, {
547
- key: "resize",
548
- value: function resize(width, height) {
549
- // SVG should ignore DPR
550
- if (this.$namespace) {
551
- this.$namespace.setAttribute('width', "".concat(width));
552
- this.$namespace.setAttribute('height', "".concat(height));
553
- }
442
+ };
443
+ _proto.resize = function resize(width, height) {
444
+ // SVG should ignore DPR
445
+ if (this.$namespace) {
446
+ this.$namespace.setAttribute('width', "" + width);
447
+ this.$namespace.setAttribute('height', "" + height);
554
448
  }
555
- }, {
556
- key: "applyCursorStyle",
557
- value: function applyCursorStyle(cursor) {
558
- if (this.$container) {
559
- this.$container.style.cursor = cursor;
560
- }
449
+ };
450
+ _proto.applyCursorStyle = function applyCursorStyle(cursor) {
451
+ if (this.$container) {
452
+ this.$container.style.cursor = cursor;
561
453
  }
562
- }, {
563
- key: "toDataURL",
564
- value: function () {
565
- var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
566
- var cloneNode,
567
- svgDocType,
568
- svgDoc;
569
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
570
- while (1) {
571
- switch (_context2.prev = _context2.next) {
572
- case 0:
573
- cloneNode = this.$namespace.cloneNode(true);
574
- svgDocType = document.implementation.createDocumentType('svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
575
- svgDoc = document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg', svgDocType);
576
- svgDoc.replaceChild(cloneNode, svgDoc.documentElement);
577
- return _context2.abrupt("return", "data:image/svg+xml;charset=utf8,".concat(encodeURIComponent(new XMLSerializer().serializeToString(svgDoc))));
578
- case 6:
579
- case "end":
580
- return _context2.stop();
581
- }
454
+ };
455
+ _proto.toDataURL = /*#__PURE__*/function () {
456
+ var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
457
+ var cloneNode, svgDocType, svgDoc;
458
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
459
+ while (1) {
460
+ switch (_context2.prev = _context2.next) {
461
+ case 0:
462
+ cloneNode = this.$namespace.cloneNode(true);
463
+ svgDocType = document.implementation.createDocumentType('svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
464
+ svgDoc = document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg', svgDocType);
465
+ svgDoc.replaceChild(cloneNode, svgDoc.documentElement);
466
+ return _context2.abrupt("return", "data:image/svg+xml;charset=utf8," + encodeURIComponent(new XMLSerializer().serializeToString(svgDoc)));
467
+ case 6:
468
+ case "end":
469
+ return _context2.stop();
582
470
  }
583
- }, _callee2, this);
584
- }));
585
- function toDataURL() {
586
- return _toDataURL.apply(this, arguments);
587
- }
588
- return toDataURL;
589
- }()
590
- }]);
471
+ }
472
+ }, _callee2, this);
473
+ }));
474
+ function toDataURL(_x) {
475
+ return _toDataURL.apply(this, arguments);
476
+ }
477
+ return toDataURL;
478
+ }();
591
479
  return SVGContextService;
592
480
  }();
593
481
 
594
482
  var ContextRegisterPlugin = /*#__PURE__*/function (_AbstractRendererPlug) {
595
- _inherits(ContextRegisterPlugin, _AbstractRendererPlug);
596
- var _super = _createSuper(ContextRegisterPlugin);
483
+ _inheritsLoose(ContextRegisterPlugin, _AbstractRendererPlug);
597
484
  function ContextRegisterPlugin() {
598
485
  var _this;
599
- _classCallCheck(this, ContextRegisterPlugin);
600
486
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
601
487
  args[_key] = arguments[_key];
602
488
  }
603
- _this = _super.call.apply(_super, [this].concat(args));
489
+ _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
604
490
  _this.name = 'svg-context-register';
605
491
  return _this;
606
492
  }
607
- _createClass(ContextRegisterPlugin, [{
608
- key: "init",
609
- value: function init() {
610
- // @ts-ignore
611
- this.context.ContextService = SVGContextService;
612
- }
613
- }, {
614
- key: "destroy",
615
- value: function destroy() {
616
- delete this.context.ContextService;
617
- }
618
- }]);
493
+ var _proto = ContextRegisterPlugin.prototype;
494
+ _proto.init = function init() {
495
+ // @ts-ignore
496
+ this.context.ContextService = SVGContextService;
497
+ };
498
+ _proto.destroy = function destroy() {
499
+ delete this.context.ContextService;
500
+ };
619
501
  return ContextRegisterPlugin;
620
502
  }(gLite.AbstractRendererPlugin);
621
503
 
622
504
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
623
- _inherits(Renderer, _AbstractRenderer);
624
- var _super = _createSuper(Renderer);
625
- function Renderer() {
505
+ _inheritsLoose(Renderer, _AbstractRenderer);
506
+ function Renderer(config) {
626
507
  var _this;
627
- var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
628
- _classCallCheck(this, Renderer);
629
- _this = _super.call(this, config);
508
+ if (config === void 0) {
509
+ config = {};
510
+ }
511
+ _this = _AbstractRenderer.call(this, config) || this;
630
512
  _this.registerPlugin(new ContextRegisterPlugin());
631
513
  _this.registerPlugin(new SVGRenderer.Plugin({
632
514
  outputSVGElementId: config.outputSVGElementId
@@ -635,7 +517,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
635
517
  _this.registerPlugin(new SVGPicker.Plugin());
636
518
  return _this;
637
519
  }
638
- return _createClass(Renderer);
520
+ return Renderer;
639
521
  }(gLite.AbstractRenderer);
640
522
 
641
523
  exports.DomInteraction = DomInteraction__namespace;