@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.
- package/dist/SVGContextService.d.ts +2 -0
- package/dist/SVGContextService.d.ts.map +1 -1
- package/dist/index.esm.js +114 -196
- package/dist/index.js +114 -196
- package/dist/index.umd.js +1780 -2157
- package/dist/index.umd.min.js +5 -5
- package/package.json +5 -5
|
@@ -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;
|
|
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
|
|
395
|
-
|
|
396
|
-
|
|
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
|
-
|
|
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
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
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
|
-
|
|
471
|
-
}
|
|
417
|
+
var _proto = SVGContextService.prototype;
|
|
472
418
|
|
|
473
|
-
function
|
|
474
|
-
|
|
475
|
-
|
|
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
|
-
|
|
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
|
-
|
|
484
|
-
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
429
|
+
this.$container = isString(container) ? (doc || document).getElementById(container) : container;
|
|
485
430
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
431
|
+
if (this.$container) {
|
|
432
|
+
if (!this.$container.style.position) {
|
|
433
|
+
this.$container.style.position = 'relative';
|
|
434
|
+
}
|
|
489
435
|
|
|
490
|
-
|
|
491
|
-
|
|
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
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
}
|
|
443
|
+
dpr = window.devicePixelRatio || 1;
|
|
444
|
+
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
445
|
+
this.dpr = dpr;
|
|
497
446
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
447
|
+
case 6:
|
|
448
|
+
case "end":
|
|
449
|
+
return _context.stop();
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}, _callee, this);
|
|
453
|
+
}));
|
|
501
454
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
455
|
+
function init() {
|
|
456
|
+
return _init.apply(this, arguments);
|
|
457
|
+
}
|
|
505
458
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
this.canvasConfig = void 0;
|
|
510
|
-
}
|
|
459
|
+
return init;
|
|
460
|
+
}() // @ts-ignore
|
|
461
|
+
;
|
|
511
462
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
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
|
-
|
|
539
|
-
|
|
540
|
-
|
|
467
|
+
_proto.getContext = function getContext() {
|
|
468
|
+
return this.$namespace;
|
|
469
|
+
};
|
|
541
470
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
}, _callee, this);
|
|
548
|
-
}));
|
|
471
|
+
_proto.getDPR = function getDPR() {
|
|
472
|
+
return this.dpr;
|
|
473
|
+
};
|
|
549
474
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
}
|
|
475
|
+
_proto.getBoundingClientRect = function getBoundingClientRect() {
|
|
476
|
+
var _this$$namespace;
|
|
553
477
|
|
|
554
|
-
|
|
555
|
-
|
|
478
|
+
return (_this$$namespace = this.$namespace) === null || _this$$namespace === void 0 ? void 0 : _this$$namespace.getBoundingClientRect();
|
|
479
|
+
};
|
|
556
480
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
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
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
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
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
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
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
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
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
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
|
-
|
|
643
|
-
|
|
644
|
-
var _super = _createSuper(Renderer);
|
|
564
|
+
_inheritsLoose(Renderer, _AbstractRenderer);
|
|
645
565
|
|
|
646
566
|
function Renderer(config) {
|
|
647
567
|
var _this;
|
|
648
568
|
|
|
649
|
-
|
|
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
|
|
582
|
+
return Renderer;
|
|
665
583
|
}(AbstractRenderer);
|
|
666
584
|
|
|
667
585
|
export { Renderer };
|