@antv/g-svg 1.8.27 → 1.8.29

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
@@ -167,14 +167,9 @@ function _regeneratorRuntime() {
167
167
  };
168
168
  }
169
169
  function maybeInvokeDelegate(delegate, context) {
170
- var method = delegate.iterator[context.method];
171
- if (undefined === method) {
172
- if (context.delegate = null, "throw" === context.method) {
173
- if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
174
- context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
175
- }
176
- return ContinueSentinel;
177
- }
170
+ var methodName = context.method,
171
+ method = delegate.iterator[methodName];
172
+ if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
178
173
  var record = tryCatch(method, delegate.iterator, context.arg);
179
174
  if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
180
175
  var info = record.arg;
@@ -368,10 +363,49 @@ function _asyncToGenerator(fn) {
368
363
  });
369
364
  };
370
365
  }
371
- function _inheritsLoose(subClass, superClass) {
372
- subClass.prototype = Object.create(superClass.prototype);
373
- subClass.prototype.constructor = subClass;
374
- _setPrototypeOf(subClass, superClass);
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);
375
409
  }
376
410
  function _setPrototypeOf(o, p) {
377
411
  _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
@@ -380,140 +414,219 @@ function _setPrototypeOf(o, p) {
380
414
  };
381
415
  return _setPrototypeOf(o, p);
382
416
  }
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
+ }
383
470
 
384
471
  var SVGContextService = /*#__PURE__*/function () {
385
472
  function SVGContextService(context) {
473
+ _classCallCheck(this, SVGContextService);
386
474
  this.$container = void 0;
387
475
  this.$namespace = void 0;
388
476
  this.dpr = void 0;
389
477
  this.canvasConfig = void 0;
390
478
  this.canvasConfig = context.config;
391
479
  }
392
- var _proto = SVGContextService.prototype;
393
- _proto.init = /*#__PURE__*/function () {
394
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
395
- var _this$canvasConfig, container, doc, devicePixelRatio, $namespace, dpr;
396
- return _regeneratorRuntime().wrap(function _callee$(_context) {
397
- while (1) {
398
- switch (_context.prev = _context.next) {
399
- case 0:
400
- _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, doc = _this$canvasConfig.document, devicePixelRatio = _this$canvasConfig.devicePixelRatio; // create container
401
- this.$container = util.isString(container) ? (doc || document).getElementById(container) : container;
402
- if (this.$container) {
403
- if (!this.$container.style.position) {
404
- this.$container.style.position = 'relative';
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;
405
500
  }
406
- $namespace = SVGRenderer.createSVGElement('svg', doc);
407
- $namespace.setAttribute('width', "" + this.canvasConfig.width);
408
- $namespace.setAttribute('height', "" + this.canvasConfig.height);
409
- this.$container.appendChild($namespace);
410
- this.$namespace = $namespace;
411
- }
412
- // use user-defined dpr first
413
- dpr = devicePixelRatio || gLite.isBrowser && window.devicePixelRatio || 1;
414
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
415
- this.dpr = dpr;
416
- case 6:
417
- case "end":
418
- return _context.stop();
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
+ }
419
509
  }
420
- }
421
- }, _callee, this);
422
- }));
423
- function init() {
424
- return _init.apply(this, arguments);
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;
425
521
  }
426
- return init;
427
- }() // @ts-ignore
428
- ;
429
- _proto.getDomElement = function getDomElement() {
430
- return this.$namespace;
431
- };
432
- _proto.getContext = function getContext() {
433
- return this.$namespace;
434
- };
435
- _proto.getDPR = function getDPR() {
436
- return this.dpr;
437
- };
438
- _proto.getBoundingClientRect = function getBoundingClientRect() {
439
- var _this$$namespace;
440
- return (_this$$namespace = this.$namespace) === null || _this$$namespace === void 0 ? void 0 : _this$$namespace.getBoundingClientRect();
441
- };
442
- _proto.destroy = function destroy() {
443
- // destroy context
444
- if (this.$container && this.$namespace && this.$namespace.parentNode) {
445
- this.$container.removeChild(this.$namespace);
522
+ }, {
523
+ key: "getContext",
524
+ value: function getContext() {
525
+ return this.$namespace;
446
526
  }
447
- };
448
- _proto.resize = function resize(width, height) {
449
- // SVG should ignore DPR
450
- if (this.$namespace) {
451
- this.$namespace.setAttribute('width', "" + width);
452
- this.$namespace.setAttribute('height', "" + height);
527
+ }, {
528
+ key: "getDPR",
529
+ value: function getDPR() {
530
+ return this.dpr;
453
531
  }
454
- };
455
- _proto.applyCursorStyle = function applyCursorStyle(cursor) {
456
- if (this.$container) {
457
- this.$container.style.cursor = cursor;
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();
458
537
  }
459
- };
460
- _proto.toDataURL = /*#__PURE__*/function () {
461
- var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
462
- var cloneNode, svgDocType, svgDoc;
463
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
464
- while (1) {
465
- switch (_context2.prev = _context2.next) {
466
- case 0:
467
- cloneNode = this.$namespace.cloneNode(true);
468
- svgDocType = document.implementation.createDocumentType('svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
469
- svgDoc = document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg', svgDocType);
470
- svgDoc.replaceChild(cloneNode, svgDoc.documentElement);
471
- return _context2.abrupt("return", "data:image/svg+xml;charset=utf8," + encodeURIComponent(new XMLSerializer().serializeToString(svgDoc)));
472
- case 6:
473
- case "end":
474
- return _context2.stop();
475
- }
476
- }
477
- }, _callee2, this);
478
- }));
479
- function toDataURL(_x) {
480
- return _toDataURL.apply(this, arguments);
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
+ }
545
+ }
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
+ }
481
554
  }
482
- return toDataURL;
483
- }();
555
+ }, {
556
+ key: "applyCursorStyle",
557
+ value: function applyCursorStyle(cursor) {
558
+ if (this.$container) {
559
+ this.$container.style.cursor = cursor;
560
+ }
561
+ }
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
+ }
582
+ }
583
+ }, _callee2, this);
584
+ }));
585
+ function toDataURL() {
586
+ return _toDataURL.apply(this, arguments);
587
+ }
588
+ return toDataURL;
589
+ }()
590
+ }]);
484
591
  return SVGContextService;
485
592
  }();
486
593
 
487
594
  var ContextRegisterPlugin = /*#__PURE__*/function (_AbstractRendererPlug) {
488
- _inheritsLoose(ContextRegisterPlugin, _AbstractRendererPlug);
595
+ _inherits(ContextRegisterPlugin, _AbstractRendererPlug);
596
+ var _super = _createSuper(ContextRegisterPlugin);
489
597
  function ContextRegisterPlugin() {
490
598
  var _this;
599
+ _classCallCheck(this, ContextRegisterPlugin);
491
600
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
492
601
  args[_key] = arguments[_key];
493
602
  }
494
- _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
603
+ _this = _super.call.apply(_super, [this].concat(args));
495
604
  _this.name = 'svg-context-register';
496
605
  return _this;
497
606
  }
498
- var _proto = ContextRegisterPlugin.prototype;
499
- _proto.init = function init() {
500
- // @ts-ignore
501
- this.context.ContextService = SVGContextService;
502
- };
503
- _proto.destroy = function destroy() {
504
- delete this.context.ContextService;
505
- };
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
+ }]);
506
619
  return ContextRegisterPlugin;
507
620
  }(gLite.AbstractRendererPlugin);
508
621
 
509
622
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
510
- _inheritsLoose(Renderer, _AbstractRenderer);
511
- function Renderer(config) {
623
+ _inherits(Renderer, _AbstractRenderer);
624
+ var _super = _createSuper(Renderer);
625
+ function Renderer() {
512
626
  var _this;
513
- if (config === void 0) {
514
- config = {};
515
- }
516
- _this = _AbstractRenderer.call(this, config) || this;
627
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
628
+ _classCallCheck(this, Renderer);
629
+ _this = _super.call(this, config);
517
630
  _this.registerPlugin(new ContextRegisterPlugin());
518
631
  _this.registerPlugin(new SVGRenderer.Plugin({
519
632
  outputSVGElementId: config.outputSVGElementId
@@ -522,7 +635,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
522
635
  _this.registerPlugin(new SVGPicker.Plugin());
523
636
  return _this;
524
637
  }
525
- return Renderer;
638
+ return _createClass(Renderer);
526
639
  }(gLite.AbstractRenderer);
527
640
 
528
641
  exports.DomInteraction = DomInteraction__namespace;