@antv/g-canvas 1.0.0-alpha.27 → 1.0.0-alpha.30

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,16 @@
1
+ import { ContextService } from '@antv/g';
2
+ export declare class Canvas2DContextService implements ContextService<CanvasRenderingContext2D> {
3
+ private $container;
4
+ private $canvas;
5
+ private dpr;
6
+ private context;
7
+ private canvasConfig;
8
+ init(): void;
9
+ getContext(): CanvasRenderingContext2D;
10
+ getDomElement(): HTMLCanvasElement;
11
+ getDPR(): number;
12
+ getBoundingClientRect(): DOMRect;
13
+ destroy(): void;
14
+ resize(width: number, height: number): void;
15
+ applyCursorStyle(cursor: string): void;
16
+ }
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Canvas2DContextService = 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 _dom = require("./utils/dom");
17
+
18
+ var Canvas2DContextService =
19
+ /** @class */
20
+ function () {
21
+ function Canvas2DContextService() {}
22
+
23
+ Canvas2DContextService.prototype.init = function () {
24
+ var _a = this.canvasConfig,
25
+ container = _a.container,
26
+ width = _a.width,
27
+ height = _a.height; // create container
28
+
29
+ this.$container = (0, _util.isString)(container) ? document.getElementById(container) : container;
30
+
31
+ if (this.$container) {
32
+ // create canvas
33
+ var $canvas = document.createElement('canvas');
34
+ this.context = $canvas.getContext('2d');
35
+ this.$container.appendChild($canvas);
36
+
37
+ if (!this.$container.style.position) {
38
+ this.$container.style.position = 'relative';
39
+ }
40
+
41
+ this.$canvas = $canvas;
42
+ var dpr = window.devicePixelRatio || 1;
43
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
44
+ this.dpr = dpr;
45
+ this.resize(width, height);
46
+ }
47
+ };
48
+
49
+ Canvas2DContextService.prototype.getContext = function () {
50
+ return this.context;
51
+ };
52
+
53
+ Canvas2DContextService.prototype.getDomElement = function () {
54
+ return this.$canvas;
55
+ };
56
+
57
+ Canvas2DContextService.prototype.getDPR = function () {
58
+ return this.dpr;
59
+ };
60
+
61
+ Canvas2DContextService.prototype.getBoundingClientRect = function () {
62
+ var _a;
63
+
64
+ return (_a = this.$canvas) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
65
+ };
66
+
67
+ Canvas2DContextService.prototype.destroy = function () {
68
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
69
+ // destroy context
70
+ this.$container.removeChild(this.$canvas);
71
+ }
72
+ };
73
+
74
+ Canvas2DContextService.prototype.resize = function (width, height) {
75
+ if (this.$canvas) {
76
+ // set canvas width & height
77
+ this.$canvas.width = this.dpr * width;
78
+ this.$canvas.height = this.dpr * height; // set CSS style width & height
79
+
80
+ (0, _dom.setDOMSize)(this.$canvas, width, height);
81
+ }
82
+ };
83
+
84
+ Canvas2DContextService.prototype.applyCursorStyle = function (cursor) {
85
+ if (this.$container) {
86
+ this.$container.style.cursor = cursor;
87
+ }
88
+ };
89
+
90
+ (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_g.CanvasConfig), (0, _tslib.__metadata)("design:type", Object)], Canvas2DContextService.prototype, "canvasConfig", void 0);
91
+ Canvas2DContextService = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
92
+ token: _g.ContextService
93
+ })], Canvas2DContextService);
94
+ return Canvas2DContextService;
95
+ }();
96
+
97
+ exports.Canvas2DContextService = Canvas2DContextService;
@@ -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 _Canvas2DContextService = require("./Canvas2DContextService");
11
+
12
+ var containerModule = (0, _manaSyringe.Module)(function (register) {
13
+ /**
14
+ * implements ContextService
15
+ */
16
+ register(_Canvas2DContextService.Canvas2DContextService);
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(_Canvas2DContextService.Canvas2DContextService); // @ts-ignore
30
+ // container.container.unload(containerModule);
31
+ // container.remove(Canvas2DContextService);
32
+ };
33
+
34
+ return ContextRegisterPlugin;
35
+ }();
36
+
37
+ exports.ContextRegisterPlugin = ContextRegisterPlugin;
package/lib/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { AbstractRenderer, RendererConfig } from '@antv/g';
2
+ import * as DomInteraction from '@antv/g-plugin-dom-interaction';
3
+ import * as CanvasRenderer from '@antv/g-plugin-canvas-renderer';
4
+ import * as CanvasPicker from '@antv/g-plugin-canvas-picker';
5
+ import * as HTMLRenderer from '@antv/g-plugin-html-renderer';
6
+ export { DomInteraction, CanvasRenderer, CanvasPicker, HTMLRenderer };
7
+ export declare class Renderer extends AbstractRenderer {
8
+ constructor(config?: Partial<RendererConfig>);
9
+ }
package/lib/index.js ADDED
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.Renderer = exports.HTMLRenderer = exports.DomInteraction = exports.CanvasRenderer = exports.CanvasPicker = void 0;
9
+
10
+ var _tslib = require("tslib");
11
+
12
+ var _g = require("@antv/g");
13
+
14
+ var DomInteraction = _interopRequireWildcard(require("@antv/g-plugin-dom-interaction"));
15
+
16
+ exports.DomInteraction = DomInteraction;
17
+
18
+ var CanvasRenderer = _interopRequireWildcard(require("@antv/g-plugin-canvas-renderer"));
19
+
20
+ exports.CanvasRenderer = CanvasRenderer;
21
+
22
+ var CanvasPicker = _interopRequireWildcard(require("@antv/g-plugin-canvas-picker"));
23
+
24
+ exports.CanvasPicker = CanvasPicker;
25
+
26
+ var HTMLRenderer = _interopRequireWildcard(require("@antv/g-plugin-html-renderer"));
27
+
28
+ exports.HTMLRenderer = HTMLRenderer;
29
+
30
+ var _ContextRegisterPlugin = require("./ContextRegisterPlugin");
31
+
32
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
33
+
34
+ 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; }
35
+
36
+ var Renderer =
37
+ /** @class */
38
+ function (_super) {
39
+ (0, _tslib.__extends)(Renderer, _super);
40
+
41
+ function Renderer(config) {
42
+ var _this = _super.call(this, config) || this; // register Canvas2DContext
43
+
44
+
45
+ _this.registerPlugin(new _ContextRegisterPlugin.ContextRegisterPlugin()); // enable rendering with Canvas2D API
46
+
47
+
48
+ _this.registerPlugin(new CanvasRenderer.Plugin());
49
+
50
+ _this.registerPlugin(new DomInteraction.Plugin()); // enable picking with Canvas2D API
51
+
52
+
53
+ _this.registerPlugin(new CanvasPicker.Plugin()); // render HTML component
54
+
55
+
56
+ _this.registerPlugin(new HTMLRenderer.Plugin());
57
+
58
+ return _this;
59
+ }
60
+
61
+ return Renderer;
62
+ }(_g.AbstractRenderer);
63
+
64
+ exports.Renderer = Renderer;
@@ -0,0 +1 @@
1
+ export declare const isBrowser: boolean;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isBrowser = void 0;
7
+ var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
8
+ exports.isBrowser = isBrowser;
@@ -0,0 +1 @@
1
+ export declare function setDOMSize($el: HTMLElement, width: number, height: number): void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setDOMSize = setDOMSize;
7
+
8
+ var _browser = require("./browser");
9
+
10
+ var PX_SUFFIX = 'px';
11
+
12
+ function setDOMSize($el, width, height) {
13
+ if (_browser.isBrowser) {
14
+ $el.style.width = width + PX_SUFFIX;
15
+ $el.style.height = height + PX_SUFFIX;
16
+ }
17
+ }
package/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "@antv/g-canvas",
3
- "version": "1.0.0-alpha.27",
3
+ "version": "1.0.0-alpha.30",
4
4
  "description": "A renderer implemented by Canvas 2D API",
5
- "main": "dist/index.js",
6
- "module": "dist/index.esm.js",
7
- "types": "dist/index.d.ts",
8
- "sideEffects": false,
5
+ "main": "lib/index.js",
6
+ "module": "es/index.esm.js",
7
+ "types": "es/index.d.ts",
8
+ "unpkg": "dist/index.umd.js",
9
9
  "files": [
10
10
  "package.json",
11
11
  "dist",
12
+ "es",
13
+ "lib",
12
14
  "LICENSE",
13
15
  "README.md"
14
16
  ],
@@ -38,14 +40,20 @@
38
40
  },
39
41
  "homepage": "https://github.com/antvis/g#readme",
40
42
  "dependencies": {
41
- "@antv/g": "^1.0.0-alpha.27",
42
- "@antv/g-plugin-canvas-picker": "^1.0.0-alpha.21",
43
- "@antv/g-plugin-canvas-renderer": "^1.0.0-alpha.27",
44
- "@antv/g-plugin-dom-interaction": "^1.0.0-alpha.26",
45
- "@antv/g-plugin-html-renderer": "^1.0.0-alpha.10",
43
+ "@antv/g": "^1.0.0-alpha.30",
44
+ "@antv/g-plugin-canvas-picker": "^1.0.0-alpha.24",
45
+ "@antv/g-plugin-canvas-renderer": "^1.0.0-alpha.30",
46
+ "@antv/g-plugin-dom-interaction": "^1.0.0-alpha.29",
47
+ "@antv/g-plugin-html-renderer": "^1.0.0-alpha.13",
46
48
  "@antv/util": "^2.0.13",
47
- "@babel/runtime": "^7.16.0",
48
- "mana-syringe": "^0.1.0"
49
+ "@babel/runtime": "^7.16.3"
50
+ },
51
+ "peerDependencies": {
52
+ "@antv/g": "^1.0.0-alpha.27",
53
+ "mana-syringe": "^0.2.2"
54
+ },
55
+ "scripts": {
56
+ "umd": "webpack"
49
57
  },
50
- "gitHead": "c01101beb86f98aaa569f97c678c909d4f3faaa3"
58
+ "gitHead": "a5bedb7fc7482122f6d56b85d9c5654d16677203"
51
59
  }
package/dist/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { AbstractRenderer, RendererConfig } from '@antv/g';
2
- export declare class Renderer extends AbstractRenderer {
3
- constructor(config?: Partial<RendererConfig>);
4
- }
package/dist/index.esm.js DELETED
@@ -1,204 +0,0 @@
1
- import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck';
2
- import _inherits from '@babel/runtime/helpers/esm/inherits';
3
- import _createSuper from '@babel/runtime/helpers/esm/createSuper';
4
- import { CanvasConfig, ContextService, AbstractRenderer } from '@antv/g';
5
- import { Plugin as Plugin$1 } from '@antv/g-plugin-dom-interaction';
6
- import { Plugin } from '@antv/g-plugin-canvas-renderer';
7
- import { Plugin as Plugin$2 } from '@antv/g-plugin-canvas-picker';
8
- import { Plugin as Plugin$3 } from '@antv/g-plugin-html-renderer';
9
- import _createClass from '@babel/runtime/helpers/esm/createClass';
10
- import { inject, singleton, Module } from 'mana-syringe';
11
- import { isString } from '@antv/util';
12
-
13
- /*! *****************************************************************************
14
- Copyright (c) Microsoft Corporation.
15
-
16
- Permission to use, copy, modify, and/or distribute this software for any
17
- purpose with or without fee is hereby granted.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
20
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
21
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
22
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25
- PERFORMANCE OF THIS SOFTWARE.
26
- ***************************************************************************** */
27
-
28
- function __decorate(decorators, target, key, desc) {
29
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
30
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
31
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
32
- return c > 3 && r && Object.defineProperty(target, key, r), r;
33
- }
34
-
35
- function __metadata(metadataKey, metadataValue) {
36
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
37
- }
38
-
39
- var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
40
-
41
- var PX_SUFFIX = 'px';
42
- function setDOMSize($el, width, height) {
43
- if (isBrowser) {
44
- $el.style.width = width + PX_SUFFIX;
45
- $el.style.height = height + PX_SUFFIX;
46
- }
47
- }
48
-
49
- var Canvas2DContextService = /*#__PURE__*/function () {
50
- function Canvas2DContextService() {
51
- _classCallCheck(this, Canvas2DContextService);
52
-
53
- this.$container = void 0;
54
- this.$canvas = void 0;
55
- this.dpr = void 0;
56
- this.context = void 0;
57
- this.canvasConfig = void 0;
58
- }
59
-
60
- _createClass(Canvas2DContextService, [{
61
- key: "init",
62
- value: function init() {
63
- var _this$canvasConfig = this.canvasConfig,
64
- container = _this$canvasConfig.container,
65
- width = _this$canvasConfig.width,
66
- height = _this$canvasConfig.height; // create container
67
-
68
- this.$container = isString(container) ? document.getElementById(container) : container;
69
-
70
- if (this.$container) {
71
- // create canvas
72
- var $canvas = document.createElement('canvas');
73
- this.context = $canvas.getContext('2d');
74
- this.$container.appendChild($canvas);
75
-
76
- if (!this.$container.style.position) {
77
- this.$container.style.position = 'relative';
78
- }
79
-
80
- this.$canvas = $canvas;
81
- var dpr = window.devicePixelRatio || 1;
82
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
83
- this.dpr = dpr;
84
- this.resize(width, height);
85
- }
86
- }
87
- }, {
88
- key: "getContext",
89
- value: function getContext() {
90
- return this.context;
91
- }
92
- }, {
93
- key: "getDomElement",
94
- value: function getDomElement() {
95
- return this.$canvas;
96
- }
97
- }, {
98
- key: "getDPR",
99
- value: function getDPR() {
100
- return this.dpr;
101
- }
102
- }, {
103
- key: "getBoundingClientRect",
104
- value: function getBoundingClientRect() {
105
- var _this$$canvas;
106
-
107
- return (_this$$canvas = this.$canvas) === null || _this$$canvas === void 0 ? void 0 : _this$$canvas.getBoundingClientRect();
108
- }
109
- }, {
110
- key: "destroy",
111
- value: function destroy() {
112
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
113
- // destroy context
114
- this.$container.removeChild(this.$canvas);
115
- }
116
- }
117
- }, {
118
- key: "resize",
119
- value: function resize(width, height) {
120
- if (this.$canvas) {
121
- // set canvas width & height
122
- this.$canvas.width = this.dpr * width;
123
- this.$canvas.height = this.dpr * height; // set CSS style width & height
124
-
125
- setDOMSize(this.$canvas, width, height);
126
- }
127
- }
128
- }, {
129
- key: "applyCursorStyle",
130
- value: function applyCursorStyle(cursor) {
131
- if (this.$container) {
132
- this.$container.style.cursor = cursor;
133
- }
134
- }
135
- }]);
136
-
137
- return Canvas2DContextService;
138
- }();
139
-
140
- __decorate([inject(CanvasConfig), __metadata("design:type", Object)], Canvas2DContextService.prototype, "canvasConfig", void 0);
141
-
142
- Canvas2DContextService = __decorate([singleton({
143
- token: ContextService
144
- })], Canvas2DContextService);
145
-
146
- var containerModule = Module(function (register) {
147
- /**
148
- * implements ContextService
149
- */
150
- register(Canvas2DContextService);
151
- });
152
- var ContextRegisterPlugin = /*#__PURE__*/function () {
153
- function ContextRegisterPlugin() {
154
- _classCallCheck(this, ContextRegisterPlugin);
155
- }
156
-
157
- _createClass(ContextRegisterPlugin, [{
158
- key: "init",
159
- value: function init(container) {
160
- container.load(containerModule);
161
- }
162
- }, {
163
- key: "destroy",
164
- value: function destroy(container) {// @ts-ignore
165
- // container.container.unload(containerModule);
166
- // container.remove(Canvas2DContextService);
167
- }
168
- }]);
169
-
170
- return ContextRegisterPlugin;
171
- }();
172
-
173
- var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
174
- _inherits(Renderer, _AbstractRenderer);
175
-
176
- var _super = _createSuper(Renderer);
177
-
178
- function Renderer(config) {
179
- var _this;
180
-
181
- _classCallCheck(this, Renderer);
182
-
183
- _this = _super.call(this, config); // register Canvas2DContext
184
-
185
- _this.registerPlugin(new ContextRegisterPlugin()); // enable rendering with Canvas2D API
186
-
187
-
188
- _this.registerPlugin(new Plugin());
189
-
190
- _this.registerPlugin(new Plugin$1()); // enable picking with Canvas2D API
191
-
192
-
193
- _this.registerPlugin(new Plugin$2()); // render HTML component
194
-
195
-
196
- _this.registerPlugin(new Plugin$3());
197
-
198
- return _this;
199
- }
200
-
201
- return Renderer;
202
- }(AbstractRenderer);
203
-
204
- export { Renderer };