@antv/g-svg 1.8.28 → 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
@@ -341,10 +341,49 @@ function _asyncToGenerator(fn) {
341
341
  });
342
342
  };
343
343
  }
344
- function _inheritsLoose(subClass, superClass) {
345
- subClass.prototype = Object.create(superClass.prototype);
346
- subClass.prototype.constructor = subClass;
347
- _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);
348
387
  }
349
388
  function _setPrototypeOf(o, p) {
350
389
  _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
@@ -353,140 +392,219 @@ function _setPrototypeOf(o, p) {
353
392
  };
354
393
  return _setPrototypeOf(o, p);
355
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
+ }
356
448
 
357
449
  var SVGContextService = /*#__PURE__*/function () {
358
450
  function SVGContextService(context) {
451
+ _classCallCheck(this, SVGContextService);
359
452
  this.$container = void 0;
360
453
  this.$namespace = void 0;
361
454
  this.dpr = void 0;
362
455
  this.canvasConfig = void 0;
363
456
  this.canvasConfig = context.config;
364
457
  }
365
- var _proto = SVGContextService.prototype;
366
- _proto.init = /*#__PURE__*/function () {
367
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
368
- var _this$canvasConfig, container, doc, devicePixelRatio, $namespace, dpr;
369
- return _regeneratorRuntime().wrap(function _callee$(_context) {
370
- while (1) {
371
- switch (_context.prev = _context.next) {
372
- case 0:
373
- _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, doc = _this$canvasConfig.document, devicePixelRatio = _this$canvasConfig.devicePixelRatio; // create container
374
- this.$container = isString(container) ? (doc || document).getElementById(container) : container;
375
- if (this.$container) {
376
- if (!this.$container.style.position) {
377
- 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;
378
478
  }
379
- $namespace = createSVGElement('svg', doc);
380
- $namespace.setAttribute('width', "" + this.canvasConfig.width);
381
- $namespace.setAttribute('height', "" + this.canvasConfig.height);
382
- this.$container.appendChild($namespace);
383
- this.$namespace = $namespace;
384
- }
385
- // use user-defined dpr first
386
- dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
387
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
388
- this.dpr = dpr;
389
- case 6:
390
- case "end":
391
- 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
+ }
392
487
  }
393
- }
394
- }, _callee, this);
395
- }));
396
- function init() {
397
- 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;
398
499
  }
399
- return init;
400
- }() // @ts-ignore
401
- ;
402
- _proto.getDomElement = function getDomElement() {
403
- return this.$namespace;
404
- };
405
- _proto.getContext = function getContext() {
406
- return this.$namespace;
407
- };
408
- _proto.getDPR = function getDPR() {
409
- return this.dpr;
410
- };
411
- _proto.getBoundingClientRect = function getBoundingClientRect() {
412
- var _this$$namespace;
413
- return (_this$$namespace = this.$namespace) === null || _this$$namespace === void 0 ? void 0 : _this$$namespace.getBoundingClientRect();
414
- };
415
- _proto.destroy = function destroy() {
416
- // destroy context
417
- if (this.$container && this.$namespace && this.$namespace.parentNode) {
418
- this.$container.removeChild(this.$namespace);
500
+ }, {
501
+ key: "getContext",
502
+ value: function getContext() {
503
+ return this.$namespace;
419
504
  }
420
- };
421
- _proto.resize = function resize(width, height) {
422
- // SVG should ignore DPR
423
- if (this.$namespace) {
424
- this.$namespace.setAttribute('width', "" + width);
425
- this.$namespace.setAttribute('height', "" + height);
505
+ }, {
506
+ key: "getDPR",
507
+ value: function getDPR() {
508
+ return this.dpr;
426
509
  }
427
- };
428
- _proto.applyCursorStyle = function applyCursorStyle(cursor) {
429
- if (this.$container) {
430
- 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();
431
515
  }
432
- };
433
- _proto.toDataURL = /*#__PURE__*/function () {
434
- var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
435
- var cloneNode, svgDocType, svgDoc;
436
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
437
- while (1) {
438
- switch (_context2.prev = _context2.next) {
439
- case 0:
440
- cloneNode = this.$namespace.cloneNode(true);
441
- svgDocType = document.implementation.createDocumentType('svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
442
- svgDoc = document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg', svgDocType);
443
- svgDoc.replaceChild(cloneNode, svgDoc.documentElement);
444
- return _context2.abrupt("return", "data:image/svg+xml;charset=utf8," + encodeURIComponent(new XMLSerializer().serializeToString(svgDoc)));
445
- case 6:
446
- case "end":
447
- return _context2.stop();
448
- }
449
- }
450
- }, _callee2, this);
451
- }));
452
- function toDataURL(_x) {
453
- 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
+ }
454
532
  }
455
- return toDataURL;
456
- }();
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
+ }]);
457
569
  return SVGContextService;
458
570
  }();
459
571
 
460
572
  var ContextRegisterPlugin = /*#__PURE__*/function (_AbstractRendererPlug) {
461
- _inheritsLoose(ContextRegisterPlugin, _AbstractRendererPlug);
573
+ _inherits(ContextRegisterPlugin, _AbstractRendererPlug);
574
+ var _super = _createSuper(ContextRegisterPlugin);
462
575
  function ContextRegisterPlugin() {
463
576
  var _this;
577
+ _classCallCheck(this, ContextRegisterPlugin);
464
578
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
465
579
  args[_key] = arguments[_key];
466
580
  }
467
- _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
581
+ _this = _super.call.apply(_super, [this].concat(args));
468
582
  _this.name = 'svg-context-register';
469
583
  return _this;
470
584
  }
471
- var _proto = ContextRegisterPlugin.prototype;
472
- _proto.init = function init() {
473
- // @ts-ignore
474
- this.context.ContextService = SVGContextService;
475
- };
476
- _proto.destroy = function destroy() {
477
- delete this.context.ContextService;
478
- };
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
+ }]);
479
597
  return ContextRegisterPlugin;
480
598
  }(AbstractRendererPlugin);
481
599
 
482
600
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
483
- _inheritsLoose(Renderer, _AbstractRenderer);
484
- function Renderer(config) {
601
+ _inherits(Renderer, _AbstractRenderer);
602
+ var _super = _createSuper(Renderer);
603
+ function Renderer() {
485
604
  var _this;
486
- if (config === void 0) {
487
- config = {};
488
- }
489
- _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);
490
608
  _this.registerPlugin(new ContextRegisterPlugin());
491
609
  _this.registerPlugin(new Plugin({
492
610
  outputSVGElementId: config.outputSVGElementId
@@ -495,7 +613,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
495
613
  _this.registerPlugin(new Plugin$2());
496
614
  return _this;
497
615
  }
498
- return Renderer;
616
+ return _createClass(Renderer);
499
617
  }(AbstractRenderer);
500
618
 
501
619
  export { Renderer };