@antv/g-svg 1.0.0-alpha.28 → 1.0.0-alpha.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.
@@ -0,0 +1,6 @@
1
+ import { Syringe } from 'mana-syringe';
2
+ import { RendererPlugin } from '@antv/g';
3
+ export declare class ContextRegisterPlugin implements RendererPlugin {
4
+ init(container: Syringe.Container): void;
5
+ destroy(container: Syringe.Container): void;
6
+ }
@@ -0,0 +1,28 @@
1
+ import { Module } from 'mana-syringe';
2
+ import { SVGContextService } from './SVGContextService';
3
+ var containerModule = Module(function (register) {
4
+ /**
5
+ * implements ContextService
6
+ */
7
+ register(SVGContextService);
8
+ });
9
+
10
+ var ContextRegisterPlugin =
11
+ /** @class */
12
+ function () {
13
+ function ContextRegisterPlugin() {}
14
+
15
+ ContextRegisterPlugin.prototype.init = function (container) {
16
+ container.load(containerModule, true);
17
+ };
18
+
19
+ ContextRegisterPlugin.prototype.destroy = function (container) {
20
+ container.remove(SVGContextService); // @ts-ignore
21
+ // container.container.unload(containerModule);
22
+ // container.unload(containerModule);
23
+ };
24
+
25
+ return ContextRegisterPlugin;
26
+ }();
27
+
28
+ export { ContextRegisterPlugin };
@@ -0,0 +1,15 @@
1
+ import { ContextService } from '@antv/g';
2
+ export declare class SVGContextService implements ContextService<SVGElement> {
3
+ private $container;
4
+ private $namespace;
5
+ private dpr;
6
+ private canvasConfig;
7
+ init(): void;
8
+ getDomElement(): SVGElement;
9
+ getContext(): SVGElement;
10
+ getDPR(): number;
11
+ getBoundingClientRect(): DOMRect;
12
+ destroy(): void;
13
+ resize(width: number, height: number): void;
14
+ applyCursorStyle(cursor: string): void;
15
+ }
@@ -0,0 +1,81 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { CanvasConfig, ContextService } from '@antv/g';
3
+ import { inject, singleton } from 'mana-syringe';
4
+ import { isString } from '@antv/util';
5
+ import { createSVGElement } from '@antv/g-plugin-svg-renderer';
6
+
7
+ var SVGContextService =
8
+ /** @class */
9
+ function () {
10
+ function SVGContextService() {}
11
+
12
+ SVGContextService.prototype.init = function () {
13
+ var container = this.canvasConfig.container; // create container
14
+
15
+ this.$container = isString(container) ? document.getElementById(container) : container;
16
+
17
+ if (this.$container) {
18
+ if (!this.$container.style.position) {
19
+ this.$container.style.position = 'relative';
20
+ }
21
+
22
+ var $namespace = createSVGElement('svg');
23
+ $namespace.setAttribute('width', "" + this.canvasConfig.width);
24
+ $namespace.setAttribute('height', "" + this.canvasConfig.height);
25
+ this.$container.appendChild($namespace);
26
+ this.$namespace = $namespace;
27
+ }
28
+
29
+ var dpr = window.devicePixelRatio || 1;
30
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
31
+ this.dpr = dpr;
32
+ }; // @ts-ignore
33
+
34
+
35
+ SVGContextService.prototype.getDomElement = function () {
36
+ return this.$namespace;
37
+ };
38
+
39
+ SVGContextService.prototype.getContext = function () {
40
+ return this.$namespace;
41
+ };
42
+
43
+ SVGContextService.prototype.getDPR = function () {
44
+ return this.dpr;
45
+ };
46
+
47
+ SVGContextService.prototype.getBoundingClientRect = function () {
48
+ var _a;
49
+
50
+ return (_a = this.$namespace) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
51
+ };
52
+
53
+ SVGContextService.prototype.destroy = function () {
54
+ // destroy context
55
+ if (this.$container && this.$namespace && this.$namespace.parentNode) {
56
+ this.$container.removeChild(this.$namespace);
57
+ }
58
+ };
59
+
60
+ SVGContextService.prototype.resize = function (width, height) {
61
+ if (this.$namespace) {
62
+ this.$namespace.setAttribute('width', "" + width);
63
+ this.$namespace.setAttribute('height', "" + height);
64
+ }
65
+ };
66
+
67
+ SVGContextService.prototype.applyCursorStyle = function (cursor) {
68
+ if (this.$container) {
69
+ this.$container.style.cursor = cursor;
70
+ }
71
+ };
72
+
73
+ __decorate([inject(CanvasConfig), __metadata("design:type", Object)], SVGContextService.prototype, "canvasConfig", void 0);
74
+
75
+ SVGContextService = __decorate([singleton({
76
+ token: ContextService
77
+ })], SVGContextService);
78
+ return SVGContextService;
79
+ }();
80
+
81
+ export { SVGContextService };
package/es/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { AbstractRenderer, RendererConfig } from '@antv/g';
2
+ import * as DomInteraction from '@antv/g-plugin-dom-interaction';
3
+ import * as SVGRenderer from '@antv/g-plugin-svg-renderer';
4
+ import * as SVGPicker from '@antv/g-plugin-svg-picker';
5
+ export { DomInteraction, SVGRenderer, SVGPicker };
6
+ export declare class Renderer extends AbstractRenderer {
7
+ constructor(config?: Partial<RendererConfig>);
8
+ }
package/es/index.js ADDED
@@ -0,0 +1,31 @@
1
+ import { __extends } from "tslib";
2
+ import { AbstractRenderer } from '@antv/g';
3
+ import * as DomInteraction from '@antv/g-plugin-dom-interaction';
4
+ import * as SVGRenderer from '@antv/g-plugin-svg-renderer';
5
+ import * as SVGPicker from '@antv/g-plugin-svg-picker';
6
+ import { ContextRegisterPlugin } from './ContextRegisterPlugin';
7
+ export { DomInteraction, SVGRenderer, SVGPicker };
8
+
9
+ var Renderer =
10
+ /** @class */
11
+ function (_super) {
12
+ __extends(Renderer, _super);
13
+
14
+ function Renderer(config) {
15
+ var _this = _super.call(this, config) || this;
16
+
17
+ _this.registerPlugin(new ContextRegisterPlugin());
18
+
19
+ _this.registerPlugin(new SVGRenderer.Plugin());
20
+
21
+ _this.registerPlugin(new DomInteraction.Plugin());
22
+
23
+ _this.registerPlugin(new SVGPicker.Plugin());
24
+
25
+ return _this;
26
+ }
27
+
28
+ return Renderer;
29
+ }(AbstractRenderer);
30
+
31
+ export { Renderer };
@@ -0,0 +1,6 @@
1
+ export declare function parseRadius(radius: number[]): {
2
+ r1: number;
3
+ r2: number;
4
+ r3: number;
5
+ r4: number;
6
+ };
@@ -0,0 +1,34 @@
1
+ import { isArray } from '@antv/util';
2
+ export function parseRadius(radius) {
3
+ var r1 = 0;
4
+ var r2 = 0;
5
+ var r3 = 0;
6
+ var r4 = 0;
7
+
8
+ if (isArray(radius)) {
9
+ if (radius.length === 1) {
10
+ r1 = r2 = r3 = r4 = radius[0];
11
+ } else if (radius.length === 2) {
12
+ r1 = r3 = radius[0];
13
+ r2 = r4 = radius[1];
14
+ } else if (radius.length === 3) {
15
+ r1 = radius[0];
16
+ r2 = r4 = radius[1];
17
+ r3 = radius[2];
18
+ } else {
19
+ r1 = radius[0];
20
+ r2 = radius[1];
21
+ r3 = radius[2];
22
+ r4 = radius[3];
23
+ }
24
+ } else {
25
+ r1 = r2 = r3 = r4 = radius;
26
+ }
27
+
28
+ return {
29
+ r1: r1,
30
+ r2: r2,
31
+ r3: r3,
32
+ r4: r4
33
+ };
34
+ }
@@ -0,0 +1,6 @@
1
+ import { Syringe } from 'mana-syringe';
2
+ import { RendererPlugin } from '@antv/g';
3
+ export declare class ContextRegisterPlugin implements RendererPlugin {
4
+ init(container: Syringe.Container): void;
5
+ destroy(container: Syringe.Container): void;
6
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ContextRegisterPlugin = void 0;
7
+
8
+ var _manaSyringe = require("mana-syringe");
9
+
10
+ var _SVGContextService = require("./SVGContextService");
11
+
12
+ var containerModule = (0, _manaSyringe.Module)(function (register) {
13
+ /**
14
+ * implements ContextService
15
+ */
16
+ register(_SVGContextService.SVGContextService);
17
+ });
18
+
19
+ var ContextRegisterPlugin =
20
+ /** @class */
21
+ function () {
22
+ function ContextRegisterPlugin() {}
23
+
24
+ ContextRegisterPlugin.prototype.init = function (container) {
25
+ container.load(containerModule, true);
26
+ };
27
+
28
+ ContextRegisterPlugin.prototype.destroy = function (container) {
29
+ container.remove(_SVGContextService.SVGContextService); // @ts-ignore
30
+ // container.container.unload(containerModule);
31
+ // container.unload(containerModule);
32
+ };
33
+
34
+ return ContextRegisterPlugin;
35
+ }();
36
+
37
+ exports.ContextRegisterPlugin = ContextRegisterPlugin;
@@ -0,0 +1,15 @@
1
+ import { ContextService } from '@antv/g';
2
+ export declare class SVGContextService implements ContextService<SVGElement> {
3
+ private $container;
4
+ private $namespace;
5
+ private dpr;
6
+ private canvasConfig;
7
+ init(): void;
8
+ getDomElement(): SVGElement;
9
+ getContext(): SVGElement;
10
+ getDPR(): number;
11
+ getBoundingClientRect(): DOMRect;
12
+ destroy(): void;
13
+ resize(width: number, height: number): void;
14
+ applyCursorStyle(cursor: string): void;
15
+ }
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SVGContextService = void 0;
7
+
8
+ var _tslib = require("tslib");
9
+
10
+ var _g = require("@antv/g");
11
+
12
+ var _manaSyringe = require("mana-syringe");
13
+
14
+ var _util = require("@antv/util");
15
+
16
+ var _gPluginSvgRenderer = require("@antv/g-plugin-svg-renderer");
17
+
18
+ var SVGContextService =
19
+ /** @class */
20
+ function () {
21
+ function SVGContextService() {}
22
+
23
+ SVGContextService.prototype.init = function () {
24
+ var container = this.canvasConfig.container; // create container
25
+
26
+ this.$container = (0, _util.isString)(container) ? document.getElementById(container) : container;
27
+
28
+ if (this.$container) {
29
+ if (!this.$container.style.position) {
30
+ this.$container.style.position = 'relative';
31
+ }
32
+
33
+ var $namespace = (0, _gPluginSvgRenderer.createSVGElement)('svg');
34
+ $namespace.setAttribute('width', "" + this.canvasConfig.width);
35
+ $namespace.setAttribute('height', "" + this.canvasConfig.height);
36
+ this.$container.appendChild($namespace);
37
+ this.$namespace = $namespace;
38
+ }
39
+
40
+ var dpr = window.devicePixelRatio || 1;
41
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
42
+ this.dpr = dpr;
43
+ }; // @ts-ignore
44
+
45
+
46
+ SVGContextService.prototype.getDomElement = function () {
47
+ return this.$namespace;
48
+ };
49
+
50
+ SVGContextService.prototype.getContext = function () {
51
+ return this.$namespace;
52
+ };
53
+
54
+ SVGContextService.prototype.getDPR = function () {
55
+ return this.dpr;
56
+ };
57
+
58
+ SVGContextService.prototype.getBoundingClientRect = function () {
59
+ var _a;
60
+
61
+ return (_a = this.$namespace) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
62
+ };
63
+
64
+ SVGContextService.prototype.destroy = function () {
65
+ // destroy context
66
+ if (this.$container && this.$namespace && this.$namespace.parentNode) {
67
+ this.$container.removeChild(this.$namespace);
68
+ }
69
+ };
70
+
71
+ SVGContextService.prototype.resize = function (width, height) {
72
+ if (this.$namespace) {
73
+ this.$namespace.setAttribute('width', "" + width);
74
+ this.$namespace.setAttribute('height', "" + height);
75
+ }
76
+ };
77
+
78
+ SVGContextService.prototype.applyCursorStyle = function (cursor) {
79
+ if (this.$container) {
80
+ this.$container.style.cursor = cursor;
81
+ }
82
+ };
83
+
84
+ (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_g.CanvasConfig), (0, _tslib.__metadata)("design:type", Object)], SVGContextService.prototype, "canvasConfig", void 0);
85
+ SVGContextService = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
86
+ token: _g.ContextService
87
+ })], SVGContextService);
88
+ return SVGContextService;
89
+ }();
90
+
91
+ exports.SVGContextService = SVGContextService;
package/lib/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { AbstractRenderer, RendererConfig } from '@antv/g';
2
+ import * as DomInteraction from '@antv/g-plugin-dom-interaction';
3
+ import * as SVGRenderer from '@antv/g-plugin-svg-renderer';
4
+ import * as SVGPicker from '@antv/g-plugin-svg-picker';
5
+ export { DomInteraction, SVGRenderer, SVGPicker };
6
+ export declare class Renderer extends AbstractRenderer {
7
+ constructor(config?: Partial<RendererConfig>);
8
+ }
package/lib/index.js CHANGED
@@ -5,7 +5,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.SVGPicker = exports.SVGRenderer = exports.DomInteraction = exports.Renderer = void 0;
8
+ exports.SVGRenderer = exports.SVGPicker = exports.Renderer = exports.DomInteraction = void 0;
9
9
 
10
10
  var _tslib = require("tslib");
11
11
 
@@ -29,7 +29,9 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
29
29
 
30
30
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
31
31
 
32
- var Renderer = function (_super) {
32
+ var Renderer =
33
+ /** @class */
34
+ function (_super) {
33
35
  (0, _tslib.__extends)(Renderer, _super);
34
36
 
35
37
  function Renderer(config) {
@@ -0,0 +1,6 @@
1
+ export declare function parseRadius(radius: number[]): {
2
+ r1: number;
3
+ r2: number;
4
+ r3: number;
5
+ r4: number;
6
+ };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseRadius = parseRadius;
7
+
8
+ var _util = require("@antv/util");
9
+
10
+ function parseRadius(radius) {
11
+ var r1 = 0;
12
+ var r2 = 0;
13
+ var r3 = 0;
14
+ var r4 = 0;
15
+
16
+ if ((0, _util.isArray)(radius)) {
17
+ if (radius.length === 1) {
18
+ r1 = r2 = r3 = r4 = radius[0];
19
+ } else if (radius.length === 2) {
20
+ r1 = r3 = radius[0];
21
+ r2 = r4 = radius[1];
22
+ } else if (radius.length === 3) {
23
+ r1 = radius[0];
24
+ r2 = r4 = radius[1];
25
+ r3 = radius[2];
26
+ } else {
27
+ r1 = radius[0];
28
+ r2 = radius[1];
29
+ r3 = radius[2];
30
+ r4 = radius[3];
31
+ }
32
+ } else {
33
+ r1 = r2 = r3 = r4 = radius;
34
+ }
35
+
36
+ return {
37
+ r1: r1,
38
+ r2: r2,
39
+ r3: r3,
40
+ r4: r4
41
+ };
42
+ }
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@antv/g-svg",
3
- "version": "1.0.0-alpha.28",
3
+ "version": "1.0.0-alpha.29",
4
4
  "description": "A renderer implemented by SVG",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.esm.js",
7
7
  "types": "es/index.d.ts",
8
+ "unpkg": "dist/index.umd.js",
8
9
  "files": [
9
10
  "package.json",
10
11
  "dist",
12
+ "es",
13
+ "lib",
11
14
  "LICENSE",
12
15
  "README.md"
13
16
  ],
@@ -37,10 +40,10 @@
37
40
  },
38
41
  "homepage": "https://github.com/antvis/g#readme",
39
42
  "dependencies": {
40
- "@antv/g": "^1.0.0-alpha.28",
41
- "@antv/g-plugin-dom-interaction": "^1.0.0-alpha.27",
42
- "@antv/g-plugin-svg-picker": "^1.0.0-alpha.27",
43
- "@antv/g-plugin-svg-renderer": "^1.0.0-alpha.28",
43
+ "@antv/g": "^1.0.0-alpha.29",
44
+ "@antv/g-plugin-dom-interaction": "^1.0.0-alpha.28",
45
+ "@antv/g-plugin-svg-picker": "^1.0.0-alpha.28",
46
+ "@antv/g-plugin-svg-renderer": "^1.0.0-alpha.29",
44
47
  "@antv/util": "^2.0.13",
45
48
  "mana-syringe": "^0.2.1"
46
49
  },
@@ -51,5 +54,5 @@
51
54
  "scripts": {
52
55
  "umd": "webpack"
53
56
  },
54
- "gitHead": "b8af919853fa578b4aa6c5e84715948085ac0170"
57
+ "gitHead": "97b0cd921c395a28d0432b33db157723b7967db1"
55
58
  }