@antv/g-canvas 1.1.6 → 1.1.7
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 +89 -200
- package/dist/index.js +89 -200
- package/dist/index.umd.js +1507 -2102
- package/dist/index.umd.min.js +5 -5
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -35,54 +35,11 @@ var CanvasRenderer__namespace = /*#__PURE__*/_interopNamespace(CanvasRenderer);
|
|
|
35
35
|
var CanvasPicker__namespace = /*#__PURE__*/_interopNamespace(CanvasPicker);
|
|
36
36
|
var HTMLRenderer__namespace = /*#__PURE__*/_interopNamespace(HTMLRenderer);
|
|
37
37
|
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function _defineProperties(target, props) {
|
|
45
|
-
for (var i = 0; i < props.length; i++) {
|
|
46
|
-
var descriptor = props[i];
|
|
47
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
48
|
-
descriptor.configurable = true;
|
|
49
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
50
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
38
|
+
function _inheritsLoose(subClass, superClass) {
|
|
39
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
40
|
+
subClass.prototype.constructor = subClass;
|
|
53
41
|
|
|
54
|
-
|
|
55
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
56
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
57
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
58
|
-
writable: false
|
|
59
|
-
});
|
|
60
|
-
return Constructor;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function _inherits(subClass, superClass) {
|
|
64
|
-
if (typeof superClass !== "function" && superClass !== null) {
|
|
65
|
-
throw new TypeError("Super expression must either be null or a function");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
69
|
-
constructor: {
|
|
70
|
-
value: subClass,
|
|
71
|
-
writable: true,
|
|
72
|
-
configurable: true
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
Object.defineProperty(subClass, "prototype", {
|
|
76
|
-
writable: false
|
|
77
|
-
});
|
|
78
|
-
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function _getPrototypeOf(o) {
|
|
82
|
-
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
83
|
-
return o.__proto__ || Object.getPrototypeOf(o);
|
|
84
|
-
};
|
|
85
|
-
return _getPrototypeOf(o);
|
|
42
|
+
_setPrototypeOf(subClass, superClass);
|
|
86
43
|
}
|
|
87
44
|
|
|
88
45
|
function _setPrototypeOf(o, p) {
|
|
@@ -94,60 +51,8 @@ function _setPrototypeOf(o, p) {
|
|
|
94
51
|
return _setPrototypeOf(o, p);
|
|
95
52
|
}
|
|
96
53
|
|
|
97
|
-
function _isNativeReflectConstruct() {
|
|
98
|
-
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
99
|
-
if (Reflect.construct.sham) return false;
|
|
100
|
-
if (typeof Proxy === "function") return true;
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
104
|
-
return true;
|
|
105
|
-
} catch (e) {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function _assertThisInitialized(self) {
|
|
111
|
-
if (self === void 0) {
|
|
112
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return self;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function _possibleConstructorReturn(self, call) {
|
|
119
|
-
if (call && (typeof call === "object" || typeof call === "function")) {
|
|
120
|
-
return call;
|
|
121
|
-
} else if (call !== void 0) {
|
|
122
|
-
throw new TypeError("Derived constructors may only return object or undefined");
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return _assertThisInitialized(self);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function _createSuper(Derived) {
|
|
129
|
-
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
130
|
-
|
|
131
|
-
return function _createSuperInternal() {
|
|
132
|
-
var Super = _getPrototypeOf(Derived),
|
|
133
|
-
result;
|
|
134
|
-
|
|
135
|
-
if (hasNativeReflectConstruct) {
|
|
136
|
-
var NewTarget = _getPrototypeOf(this).constructor;
|
|
137
|
-
|
|
138
|
-
result = Reflect.construct(Super, arguments, NewTarget);
|
|
139
|
-
} else {
|
|
140
|
-
result = Super.apply(this, arguments);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return _possibleConstructorReturn(this, result);
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
54
|
var Canvas2DContextService = /*#__PURE__*/function () {
|
|
148
55
|
function Canvas2DContextService() {
|
|
149
|
-
_classCallCheck(this, Canvas2DContextService);
|
|
150
|
-
|
|
151
56
|
this.$container = void 0;
|
|
152
57
|
this.$canvas = void 0;
|
|
153
58
|
this.dpr = void 0;
|
|
@@ -155,102 +60,94 @@ var Canvas2DContextService = /*#__PURE__*/function () {
|
|
|
155
60
|
this.canvasConfig = void 0;
|
|
156
61
|
}
|
|
157
62
|
|
|
158
|
-
|
|
159
|
-
key: "init",
|
|
160
|
-
value: function init() {
|
|
161
|
-
var _this$canvasConfig = this.canvasConfig,
|
|
162
|
-
container = _this$canvasConfig.container,
|
|
163
|
-
canvas = _this$canvasConfig.canvas,
|
|
164
|
-
devicePixelRatio = _this$canvasConfig.devicePixelRatio;
|
|
63
|
+
var _proto = Canvas2DContextService.prototype;
|
|
165
64
|
|
|
166
|
-
|
|
167
|
-
|
|
65
|
+
_proto.init = function init() {
|
|
66
|
+
var _this$canvasConfig = this.canvasConfig,
|
|
67
|
+
container = _this$canvasConfig.container,
|
|
68
|
+
canvas = _this$canvasConfig.canvas,
|
|
69
|
+
devicePixelRatio = _this$canvasConfig.devicePixelRatio;
|
|
168
70
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
71
|
+
if (canvas) {
|
|
72
|
+
this.$canvas = canvas;
|
|
172
73
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
// create container
|
|
177
|
-
this.$container = g.isString(container) ? document.getElementById(container) : container;
|
|
74
|
+
if (container && canvas.parentElement !== container) {
|
|
75
|
+
container.appendChild(canvas);
|
|
76
|
+
}
|
|
178
77
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
78
|
+
this.$container = canvas.parentElement;
|
|
79
|
+
this.canvasConfig.container = this.$container;
|
|
80
|
+
} else if (container) {
|
|
81
|
+
// create container
|
|
82
|
+
this.$container = g.isString(container) ? document.getElementById(container) : container;
|
|
183
83
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
84
|
+
if (this.$container) {
|
|
85
|
+
// create canvas
|
|
86
|
+
var $canvas = document.createElement('canvas');
|
|
87
|
+
this.$container.appendChild($canvas);
|
|
187
88
|
|
|
188
|
-
|
|
89
|
+
if (!this.$container.style.position) {
|
|
90
|
+
this.$container.style.position = 'relative';
|
|
189
91
|
}
|
|
92
|
+
|
|
93
|
+
this.$canvas = $canvas;
|
|
190
94
|
}
|
|
95
|
+
}
|
|
191
96
|
|
|
192
|
-
|
|
97
|
+
this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
|
|
193
98
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
key: "getBoundingClientRect",
|
|
216
|
-
value: function getBoundingClientRect() {
|
|
217
|
-
if (this.$canvas.getBoundingClientRect) {
|
|
218
|
-
return this.$canvas.getBoundingClientRect();
|
|
219
|
-
}
|
|
99
|
+
var dpr = devicePixelRatio || g.isBrowser && window.devicePixelRatio || 1;
|
|
100
|
+
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
101
|
+
this.dpr = dpr;
|
|
102
|
+
this.resize(this.canvasConfig.width, this.canvasConfig.height);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
_proto.getContext = function getContext() {
|
|
106
|
+
return this.context;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
_proto.getDomElement = function getDomElement() {
|
|
110
|
+
return this.$canvas;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
_proto.getDPR = function getDPR() {
|
|
114
|
+
return this.dpr;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
_proto.getBoundingClientRect = function getBoundingClientRect() {
|
|
118
|
+
if (this.$canvas.getBoundingClientRect) {
|
|
119
|
+
return this.$canvas.getBoundingClientRect();
|
|
220
120
|
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
_proto.destroy = function destroy() {
|
|
124
|
+
// @ts-ignore
|
|
125
|
+
if (this.$container && this.$canvas && this.$canvas.parentNode) {
|
|
126
|
+
// destroy context
|
|
224
127
|
// @ts-ignore
|
|
225
|
-
|
|
226
|
-
// destroy context
|
|
227
|
-
// @ts-ignore
|
|
228
|
-
this.$container.removeChild(this.$canvas);
|
|
229
|
-
}
|
|
128
|
+
this.$container.removeChild(this.$canvas);
|
|
230
129
|
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
_proto.resize = function resize(width, height) {
|
|
133
|
+
if (this.$canvas) {
|
|
134
|
+
// set canvas width & height
|
|
135
|
+
this.$canvas.width = this.dpr * width;
|
|
136
|
+
this.$canvas.height = this.dpr * height; // set CSS style width & height
|
|
137
|
+
|
|
138
|
+
g.setDOMSize(this.$canvas, width, height);
|
|
139
|
+
var dpr = this.getDPR(); // scale all drawing operations by the dpr
|
|
140
|
+
// @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
|
|
141
|
+
|
|
142
|
+
this.context.scale(dpr, dpr);
|
|
245
143
|
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
_proto.applyCursorStyle = function applyCursorStyle(cursor) {
|
|
147
|
+
if (this.$container && this.$container.style) {
|
|
148
|
+
this.$container.style.cursor = cursor;
|
|
252
149
|
}
|
|
253
|
-
}
|
|
150
|
+
};
|
|
254
151
|
|
|
255
152
|
return Canvas2DContextService;
|
|
256
153
|
}();
|
|
@@ -269,37 +166,29 @@ var containerModule = manaSyringe.Module(function (register) {
|
|
|
269
166
|
});
|
|
270
167
|
var ContextRegisterPlugin = /*#__PURE__*/function () {
|
|
271
168
|
function ContextRegisterPlugin() {
|
|
272
|
-
_classCallCheck(this, ContextRegisterPlugin);
|
|
273
|
-
|
|
274
169
|
this.name = 'canvas-context-register';
|
|
275
170
|
}
|
|
276
171
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
}]);
|
|
172
|
+
var _proto = ContextRegisterPlugin.prototype;
|
|
173
|
+
|
|
174
|
+
_proto.init = function init(container) {
|
|
175
|
+
container.load(containerModule, true);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
_proto.destroy = function destroy(container) {
|
|
179
|
+
container.unload(containerModule);
|
|
180
|
+
};
|
|
288
181
|
|
|
289
182
|
return ContextRegisterPlugin;
|
|
290
183
|
}();
|
|
291
184
|
|
|
292
185
|
var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
var _super = _createSuper(Renderer);
|
|
186
|
+
_inheritsLoose(Renderer, _AbstractRenderer);
|
|
296
187
|
|
|
297
188
|
function Renderer(config) {
|
|
298
189
|
var _this;
|
|
299
190
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
_this = _super.call(this, config); // register Canvas2DContext
|
|
191
|
+
_this = _AbstractRenderer.call(this, config) || this; // register Canvas2DContext
|
|
303
192
|
|
|
304
193
|
_this.registerPlugin(new ContextRegisterPlugin()); // enable rendering with Canvas2D API
|
|
305
194
|
|
|
@@ -317,7 +206,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
|
317
206
|
return _this;
|
|
318
207
|
}
|
|
319
208
|
|
|
320
|
-
return
|
|
209
|
+
return Renderer;
|
|
321
210
|
}(g.AbstractRenderer);
|
|
322
211
|
|
|
323
212
|
exports.DomInteraction = DomInteraction__namespace;
|