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