@antv/g-canvas 1.9.47 → 1.10.0-alpha.1
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/Canvas2DContextService.d.ts +19 -20
- package/dist/ContextRegisterPlugin.d.ts +6 -7
- package/dist/index.d.ts +12 -13
- package/dist/index.esm.js +115 -487
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +135 -506
- package/dist/index.js.map +1 -0
- package/dist/index.umd.min.js +2 -1
- package/dist/index.umd.min.js.map +1 -0
- package/package.json +22 -17
- package/dist/Canvas2DContextService.d.ts.map +0 -1
- package/dist/ContextRegisterPlugin.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.umd.js +0 -4760
package/dist/index.esm.js
CHANGED
|
@@ -1,519 +1,147 @@
|
|
|
1
|
+
import { __awaiter, __generator, __extends } from 'tslib';
|
|
1
2
|
import { setDOMSize, RenderReason, isBrowser, AbstractRendererPlugin, AbstractRenderer } from '@antv/g-lite';
|
|
2
|
-
import { Plugin as Plugin$1 } from '@antv/g-plugin-canvas-path-generator';
|
|
3
3
|
import * as CanvasPathGenerator from '@antv/g-plugin-canvas-path-generator';
|
|
4
4
|
export { CanvasPathGenerator };
|
|
5
|
-
import { Plugin as Plugin$4 } from '@antv/g-plugin-canvas-picker';
|
|
6
5
|
import * as CanvasPicker from '@antv/g-plugin-canvas-picker';
|
|
7
6
|
export { CanvasPicker };
|
|
8
|
-
import { Plugin as Plugin$2 } from '@antv/g-plugin-canvas-renderer';
|
|
9
7
|
import * as CanvasRenderer from '@antv/g-plugin-canvas-renderer';
|
|
10
8
|
export { CanvasRenderer };
|
|
11
|
-
import { Plugin as Plugin$3 } from '@antv/g-plugin-dom-interaction';
|
|
12
9
|
import * as DomInteraction from '@antv/g-plugin-dom-interaction';
|
|
13
10
|
export { DomInteraction };
|
|
14
|
-
import { Plugin as Plugin$5 } from '@antv/g-plugin-html-renderer';
|
|
15
11
|
import * as HTMLRenderer from '@antv/g-plugin-html-renderer';
|
|
16
12
|
export { HTMLRenderer };
|
|
17
|
-
import { Plugin } from '@antv/g-plugin-image-loader';
|
|
18
13
|
import * as ImageLoader from '@antv/g-plugin-image-loader';
|
|
19
14
|
export { ImageLoader };
|
|
20
15
|
import { isString } from '@antv/util';
|
|
21
16
|
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var exports = {},
|
|
27
|
-
Op = Object.prototype,
|
|
28
|
-
hasOwn = Op.hasOwnProperty,
|
|
29
|
-
defineProperty = Object.defineProperty || function (obj, key, desc) {
|
|
30
|
-
obj[key] = desc.value;
|
|
31
|
-
},
|
|
32
|
-
$Symbol = "function" == typeof Symbol ? Symbol : {},
|
|
33
|
-
iteratorSymbol = $Symbol.iterator || "@@iterator",
|
|
34
|
-
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
|
|
35
|
-
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
36
|
-
function define(obj, key, value) {
|
|
37
|
-
return Object.defineProperty(obj, key, {
|
|
38
|
-
value: value,
|
|
39
|
-
enumerable: !0,
|
|
40
|
-
configurable: !0,
|
|
41
|
-
writable: !0
|
|
42
|
-
}), obj[key];
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
define({}, "");
|
|
46
|
-
} catch (err) {
|
|
47
|
-
define = function (obj, key, value) {
|
|
48
|
-
return obj[key] = value;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
52
|
-
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
53
|
-
generator = Object.create(protoGenerator.prototype),
|
|
54
|
-
context = new Context(tryLocsList || []);
|
|
55
|
-
return defineProperty(generator, "_invoke", {
|
|
56
|
-
value: makeInvokeMethod(innerFn, self, context)
|
|
57
|
-
}), generator;
|
|
58
|
-
}
|
|
59
|
-
function tryCatch(fn, obj, arg) {
|
|
60
|
-
try {
|
|
61
|
-
return {
|
|
62
|
-
type: "normal",
|
|
63
|
-
arg: fn.call(obj, arg)
|
|
64
|
-
};
|
|
65
|
-
} catch (err) {
|
|
66
|
-
return {
|
|
67
|
-
type: "throw",
|
|
68
|
-
arg: err
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.wrap = wrap;
|
|
73
|
-
var ContinueSentinel = {};
|
|
74
|
-
function Generator() {}
|
|
75
|
-
function GeneratorFunction() {}
|
|
76
|
-
function GeneratorFunctionPrototype() {}
|
|
77
|
-
var IteratorPrototype = {};
|
|
78
|
-
define(IteratorPrototype, iteratorSymbol, function () {
|
|
79
|
-
return this;
|
|
80
|
-
});
|
|
81
|
-
var getProto = Object.getPrototypeOf,
|
|
82
|
-
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
83
|
-
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
84
|
-
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
85
|
-
function defineIteratorMethods(prototype) {
|
|
86
|
-
["next", "throw", "return"].forEach(function (method) {
|
|
87
|
-
define(prototype, method, function (arg) {
|
|
88
|
-
return this._invoke(method, arg);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
function AsyncIterator(generator, PromiseImpl) {
|
|
93
|
-
function invoke(method, arg, resolve, reject) {
|
|
94
|
-
var record = tryCatch(generator[method], generator, arg);
|
|
95
|
-
if ("throw" !== record.type) {
|
|
96
|
-
var result = record.arg,
|
|
97
|
-
value = result.value;
|
|
98
|
-
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
99
|
-
invoke("next", value, resolve, reject);
|
|
100
|
-
}, function (err) {
|
|
101
|
-
invoke("throw", err, resolve, reject);
|
|
102
|
-
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
103
|
-
result.value = unwrapped, resolve(result);
|
|
104
|
-
}, function (error) {
|
|
105
|
-
return invoke("throw", error, resolve, reject);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
reject(record.arg);
|
|
17
|
+
var Canvas2DContextService = /** @class */ (function () {
|
|
18
|
+
function Canvas2DContextService(context) {
|
|
19
|
+
this.renderingContext = context.renderingContext;
|
|
20
|
+
this.canvasConfig = context.config;
|
|
109
21
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
function makeInvokeMethod(innerFn, self, context) {
|
|
123
|
-
var state = "suspendedStart";
|
|
124
|
-
return function (method, arg) {
|
|
125
|
-
if ("executing" === state) throw new Error("Generator is already running");
|
|
126
|
-
if ("completed" === state) {
|
|
127
|
-
if ("throw" === method) throw arg;
|
|
128
|
-
return doneResult();
|
|
129
|
-
}
|
|
130
|
-
for (context.method = method, context.arg = arg;;) {
|
|
131
|
-
var delegate = context.delegate;
|
|
132
|
-
if (delegate) {
|
|
133
|
-
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
134
|
-
if (delegateResult) {
|
|
135
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
136
|
-
return delegateResult;
|
|
137
|
-
}
|
|
22
|
+
Canvas2DContextService.prototype.init = function () {
|
|
23
|
+
var _a = this.canvasConfig, container = _a.container, canvas = _a.canvas;
|
|
24
|
+
if (canvas) {
|
|
25
|
+
this.$canvas = canvas;
|
|
26
|
+
if (container &&
|
|
27
|
+
canvas.parentElement !== container) {
|
|
28
|
+
container.appendChild(canvas);
|
|
29
|
+
}
|
|
30
|
+
this.$container = canvas.parentElement;
|
|
31
|
+
this.canvasConfig.container = this.$container;
|
|
138
32
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
33
|
+
else if (container) {
|
|
34
|
+
// create container
|
|
35
|
+
this.$container = isString(container)
|
|
36
|
+
? document.getElementById(container)
|
|
37
|
+
: container;
|
|
38
|
+
if (this.$container) {
|
|
39
|
+
// create canvas
|
|
40
|
+
var $canvas = document.createElement('canvas');
|
|
41
|
+
this.$container.appendChild($canvas);
|
|
42
|
+
if (!this.$container.style.position) {
|
|
43
|
+
this.$container.style.position = 'relative';
|
|
44
|
+
}
|
|
45
|
+
this.$canvas = $canvas;
|
|
46
|
+
}
|
|
151
47
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
function maybeInvokeDelegate(delegate, context) {
|
|
157
|
-
var methodName = context.method,
|
|
158
|
-
method = delegate.iterator[methodName];
|
|
159
|
-
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
|
|
160
|
-
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
161
|
-
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
162
|
-
var info = record.arg;
|
|
163
|
-
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
|
|
164
|
-
}
|
|
165
|
-
function pushTryEntry(locs) {
|
|
166
|
-
var entry = {
|
|
167
|
-
tryLoc: locs[0]
|
|
48
|
+
this.context = this.$canvas.getContext('2d');
|
|
49
|
+
this.resize(this.canvasConfig.width, this.canvasConfig.height);
|
|
168
50
|
};
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
function resetTryEntry(entry) {
|
|
172
|
-
var record = entry.completion || {};
|
|
173
|
-
record.type = "normal", delete record.arg, entry.completion = record;
|
|
174
|
-
}
|
|
175
|
-
function Context(tryLocsList) {
|
|
176
|
-
this.tryEntries = [{
|
|
177
|
-
tryLoc: "root"
|
|
178
|
-
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
179
|
-
}
|
|
180
|
-
function values(iterable) {
|
|
181
|
-
if (iterable) {
|
|
182
|
-
var iteratorMethod = iterable[iteratorSymbol];
|
|
183
|
-
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
184
|
-
if ("function" == typeof iterable.next) return iterable;
|
|
185
|
-
if (!isNaN(iterable.length)) {
|
|
186
|
-
var i = -1,
|
|
187
|
-
next = function next() {
|
|
188
|
-
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
189
|
-
return next.value = undefined, next.done = !0, next;
|
|
190
|
-
};
|
|
191
|
-
return next.next = next;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return {
|
|
195
|
-
next: doneResult
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
function doneResult() {
|
|
199
|
-
return {
|
|
200
|
-
value: undefined,
|
|
201
|
-
done: !0
|
|
51
|
+
Canvas2DContextService.prototype.getContext = function () {
|
|
52
|
+
return this.context;
|
|
202
53
|
};
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
value: GeneratorFunctionPrototype,
|
|
206
|
-
configurable: !0
|
|
207
|
-
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
|
|
208
|
-
value: GeneratorFunction,
|
|
209
|
-
configurable: !0
|
|
210
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
|
|
211
|
-
var ctor = "function" == typeof genFun && genFun.constructor;
|
|
212
|
-
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
|
213
|
-
}, exports.mark = function (genFun) {
|
|
214
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
|
|
215
|
-
}, exports.awrap = function (arg) {
|
|
216
|
-
return {
|
|
217
|
-
__await: arg
|
|
54
|
+
Canvas2DContextService.prototype.getDomElement = function () {
|
|
55
|
+
return this.$canvas;
|
|
218
56
|
};
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
222
|
-
void 0 === PromiseImpl && (PromiseImpl = Promise);
|
|
223
|
-
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
224
|
-
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
|
|
225
|
-
return result.done ? result.value : iter.next();
|
|
226
|
-
});
|
|
227
|
-
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
|
|
228
|
-
return this;
|
|
229
|
-
}), define(Gp, "toString", function () {
|
|
230
|
-
return "[object Generator]";
|
|
231
|
-
}), exports.keys = function (val) {
|
|
232
|
-
var object = Object(val),
|
|
233
|
-
keys = [];
|
|
234
|
-
for (var key in object) keys.push(key);
|
|
235
|
-
return keys.reverse(), function next() {
|
|
236
|
-
for (; keys.length;) {
|
|
237
|
-
var key = keys.pop();
|
|
238
|
-
if (key in object) return next.value = key, next.done = !1, next;
|
|
239
|
-
}
|
|
240
|
-
return next.done = !0, next;
|
|
57
|
+
Canvas2DContextService.prototype.getDPR = function () {
|
|
58
|
+
return this.dpr;
|
|
241
59
|
};
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
|
|
246
|
-
},
|
|
247
|
-
stop: function () {
|
|
248
|
-
this.done = !0;
|
|
249
|
-
var rootRecord = this.tryEntries[0].completion;
|
|
250
|
-
if ("throw" === rootRecord.type) throw rootRecord.arg;
|
|
251
|
-
return this.rval;
|
|
252
|
-
},
|
|
253
|
-
dispatchException: function (exception) {
|
|
254
|
-
if (this.done) throw exception;
|
|
255
|
-
var context = this;
|
|
256
|
-
function handle(loc, caught) {
|
|
257
|
-
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
|
258
|
-
}
|
|
259
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
260
|
-
var entry = this.tryEntries[i],
|
|
261
|
-
record = entry.completion;
|
|
262
|
-
if ("root" === entry.tryLoc) return handle("end");
|
|
263
|
-
if (entry.tryLoc <= this.prev) {
|
|
264
|
-
var hasCatch = hasOwn.call(entry, "catchLoc"),
|
|
265
|
-
hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
266
|
-
if (hasCatch && hasFinally) {
|
|
267
|
-
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
268
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
269
|
-
} else if (hasCatch) {
|
|
270
|
-
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
271
|
-
} else {
|
|
272
|
-
if (!hasFinally) throw new Error("try statement without catch or finally");
|
|
273
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
274
|
-
}
|
|
60
|
+
Canvas2DContextService.prototype.getBoundingClientRect = function () {
|
|
61
|
+
if (this.$canvas.getBoundingClientRect) {
|
|
62
|
+
return this.$canvas.getBoundingClientRect();
|
|
275
63
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
break;
|
|
64
|
+
};
|
|
65
|
+
Canvas2DContextService.prototype.destroy = function () {
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
if (this.$container && this.$canvas && this.$canvas.parentNode) {
|
|
68
|
+
// destroy context
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
this.$container.removeChild(this.$canvas);
|
|
284
71
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
var entry = this.tryEntries[i];
|
|
303
|
-
if (entry.tryLoc === tryLoc) {
|
|
304
|
-
var record = entry.completion;
|
|
305
|
-
if ("throw" === record.type) {
|
|
306
|
-
var thrown = record.arg;
|
|
307
|
-
resetTryEntry(entry);
|
|
308
|
-
}
|
|
309
|
-
return thrown;
|
|
72
|
+
};
|
|
73
|
+
Canvas2DContextService.prototype.resize = function (width, height) {
|
|
74
|
+
var devicePixelRatio = this.canvasConfig.devicePixelRatio;
|
|
75
|
+
// use user-defined dpr first
|
|
76
|
+
var dpr = devicePixelRatio || (isBrowser && window.devicePixelRatio) || 1;
|
|
77
|
+
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
78
|
+
this.dpr = dpr;
|
|
79
|
+
if (this.$canvas) {
|
|
80
|
+
// set canvas width & height
|
|
81
|
+
this.$canvas.width = this.dpr * width;
|
|
82
|
+
this.$canvas.height = this.dpr * height;
|
|
83
|
+
// set CSS style width & height
|
|
84
|
+
setDOMSize(this.$canvas, width, height);
|
|
85
|
+
// const dpr = this.getDPR();
|
|
86
|
+
// scale all drawing operations by the dpr
|
|
87
|
+
// @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
|
|
88
|
+
// this.context.scale(dpr, dpr);
|
|
310
89
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
iterator: values(iterable),
|
|
317
|
-
resultName: resultName,
|
|
318
|
-
nextLoc: nextLoc
|
|
319
|
-
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
|
320
|
-
}
|
|
321
|
-
}, exports;
|
|
322
|
-
}
|
|
323
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
324
|
-
try {
|
|
325
|
-
var info = gen[key](arg);
|
|
326
|
-
var value = info.value;
|
|
327
|
-
} catch (error) {
|
|
328
|
-
reject(error);
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
if (info.done) {
|
|
332
|
-
resolve(value);
|
|
333
|
-
} else {
|
|
334
|
-
Promise.resolve(value).then(_next, _throw);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
function _asyncToGenerator(fn) {
|
|
338
|
-
return function () {
|
|
339
|
-
var self = this,
|
|
340
|
-
args = arguments;
|
|
341
|
-
return new Promise(function (resolve, reject) {
|
|
342
|
-
var gen = fn.apply(self, args);
|
|
343
|
-
function _next(value) {
|
|
344
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
345
|
-
}
|
|
346
|
-
function _throw(err) {
|
|
347
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
348
|
-
}
|
|
349
|
-
_next(undefined);
|
|
350
|
-
});
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
function _inheritsLoose(subClass, superClass) {
|
|
354
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
355
|
-
subClass.prototype.constructor = subClass;
|
|
356
|
-
_setPrototypeOf(subClass, superClass);
|
|
357
|
-
}
|
|
358
|
-
function _setPrototypeOf(o, p) {
|
|
359
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
360
|
-
o.__proto__ = p;
|
|
361
|
-
return o;
|
|
362
|
-
};
|
|
363
|
-
return _setPrototypeOf(o, p);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
var Canvas2DContextService = /*#__PURE__*/function () {
|
|
367
|
-
function Canvas2DContextService(context) {
|
|
368
|
-
this.$container = void 0;
|
|
369
|
-
this.$canvas = void 0;
|
|
370
|
-
this.dpr = void 0;
|
|
371
|
-
this.context = void 0;
|
|
372
|
-
this.canvasConfig = void 0;
|
|
373
|
-
this.renderingContext = void 0;
|
|
374
|
-
this.renderingContext = context.renderingContext;
|
|
375
|
-
this.canvasConfig = context.config;
|
|
376
|
-
}
|
|
377
|
-
var _proto = Canvas2DContextService.prototype;
|
|
378
|
-
_proto.init = function init() {
|
|
379
|
-
var _this$canvasConfig = this.canvasConfig,
|
|
380
|
-
container = _this$canvasConfig.container,
|
|
381
|
-
canvas = _this$canvasConfig.canvas;
|
|
382
|
-
if (canvas) {
|
|
383
|
-
this.$canvas = canvas;
|
|
384
|
-
if (container && canvas.parentElement !== container) {
|
|
385
|
-
container.appendChild(canvas);
|
|
386
|
-
}
|
|
387
|
-
this.$container = canvas.parentElement;
|
|
388
|
-
this.canvasConfig.container = this.$container;
|
|
389
|
-
} else if (container) {
|
|
390
|
-
// create container
|
|
391
|
-
this.$container = isString(container) ? document.getElementById(container) : container;
|
|
392
|
-
if (this.$container) {
|
|
393
|
-
// create canvas
|
|
394
|
-
var $canvas = document.createElement('canvas');
|
|
395
|
-
this.$container.appendChild($canvas);
|
|
396
|
-
if (!this.$container.style.position) {
|
|
397
|
-
this.$container.style.position = 'relative';
|
|
90
|
+
this.renderingContext.renderReasons.add(RenderReason.CAMERA_CHANGED);
|
|
91
|
+
};
|
|
92
|
+
Canvas2DContextService.prototype.applyCursorStyle = function (cursor) {
|
|
93
|
+
if (this.$container && this.$container.style) {
|
|
94
|
+
this.$container.style.cursor = cursor;
|
|
398
95
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
return this.dpr;
|
|
413
|
-
};
|
|
414
|
-
_proto.getBoundingClientRect = function getBoundingClientRect() {
|
|
415
|
-
if (this.$canvas.getBoundingClientRect) {
|
|
416
|
-
return this.$canvas.getBoundingClientRect();
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
_proto.destroy = function destroy() {
|
|
420
|
-
// @ts-ignore
|
|
421
|
-
if (this.$container && this.$canvas && this.$canvas.parentNode) {
|
|
422
|
-
// destroy context
|
|
423
|
-
// @ts-ignore
|
|
424
|
-
this.$container.removeChild(this.$canvas);
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
_proto.resize = function resize(width, height) {
|
|
428
|
-
var devicePixelRatio = this.canvasConfig.devicePixelRatio;
|
|
429
|
-
// use user-defined dpr first
|
|
430
|
-
var dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
|
|
431
|
-
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
432
|
-
this.dpr = dpr;
|
|
433
|
-
if (this.$canvas) {
|
|
434
|
-
// set canvas width & height
|
|
435
|
-
this.$canvas.width = this.dpr * width;
|
|
436
|
-
this.$canvas.height = this.dpr * height;
|
|
437
|
-
// set CSS style width & height
|
|
438
|
-
setDOMSize(this.$canvas, width, height);
|
|
439
|
-
// const dpr = this.getDPR();
|
|
440
|
-
// scale all drawing operations by the dpr
|
|
441
|
-
// @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
|
|
442
|
-
// this.context.scale(dpr, dpr);
|
|
443
|
-
}
|
|
96
|
+
};
|
|
97
|
+
Canvas2DContextService.prototype.toDataURL = function (options) {
|
|
98
|
+
if (options === void 0) { options = {}; }
|
|
99
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
+
var type, encoderOptions;
|
|
101
|
+
return __generator(this, function (_a) {
|
|
102
|
+
type = options.type, encoderOptions = options.encoderOptions;
|
|
103
|
+
return [2 /*return*/, this.context.canvas.toDataURL(type, encoderOptions)];
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
return Canvas2DContextService;
|
|
108
|
+
}());
|
|
444
109
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
110
|
+
var ContextRegisterPlugin = /** @class */ (function (_super) {
|
|
111
|
+
__extends(ContextRegisterPlugin, _super);
|
|
112
|
+
function ContextRegisterPlugin() {
|
|
113
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
114
|
+
_this.name = 'canvas-context-register';
|
|
115
|
+
return _this;
|
|
450
116
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
options = {};
|
|
460
|
-
}
|
|
461
|
-
_options = options, type = _options.type, encoderOptions = _options.encoderOptions;
|
|
462
|
-
return _context.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
|
|
463
|
-
case 3:
|
|
464
|
-
case "end":
|
|
465
|
-
return _context.stop();
|
|
466
|
-
}
|
|
467
|
-
}, _callee, this);
|
|
468
|
-
}));
|
|
469
|
-
function toDataURL(_x) {
|
|
470
|
-
return _toDataURL.apply(this, arguments);
|
|
471
|
-
}
|
|
472
|
-
return toDataURL;
|
|
473
|
-
}();
|
|
474
|
-
return Canvas2DContextService;
|
|
475
|
-
}();
|
|
117
|
+
ContextRegisterPlugin.prototype.init = function () {
|
|
118
|
+
this.context.ContextService = Canvas2DContextService;
|
|
119
|
+
};
|
|
120
|
+
ContextRegisterPlugin.prototype.destroy = function () {
|
|
121
|
+
delete this.context.ContextService;
|
|
122
|
+
};
|
|
123
|
+
return ContextRegisterPlugin;
|
|
124
|
+
}(AbstractRendererPlugin));
|
|
476
125
|
|
|
477
|
-
var
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
126
|
+
var Renderer = /** @class */ (function (_super) {
|
|
127
|
+
__extends(Renderer, _super);
|
|
128
|
+
function Renderer(config) {
|
|
129
|
+
var _this = _super.call(this, config) || this;
|
|
130
|
+
// register Canvas2DContext
|
|
131
|
+
_this.registerPlugin(new ContextRegisterPlugin());
|
|
132
|
+
_this.registerPlugin(new ImageLoader.Plugin());
|
|
133
|
+
_this.registerPlugin(new CanvasPathGenerator.Plugin());
|
|
134
|
+
// enable rendering with Canvas2D API
|
|
135
|
+
_this.registerPlugin(new CanvasRenderer.Plugin());
|
|
136
|
+
_this.registerPlugin(new DomInteraction.Plugin());
|
|
137
|
+
// enable picking with Canvas2D API
|
|
138
|
+
_this.registerPlugin(new CanvasPicker.Plugin());
|
|
139
|
+
// render HTML component
|
|
140
|
+
_this.registerPlugin(new HTMLRenderer.Plugin());
|
|
141
|
+
return _this;
|
|
483
142
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
return _this;
|
|
487
|
-
}
|
|
488
|
-
var _proto = ContextRegisterPlugin.prototype;
|
|
489
|
-
_proto.init = function init() {
|
|
490
|
-
this.context.ContextService = Canvas2DContextService;
|
|
491
|
-
};
|
|
492
|
-
_proto.destroy = function destroy() {
|
|
493
|
-
delete this.context.ContextService;
|
|
494
|
-
};
|
|
495
|
-
return ContextRegisterPlugin;
|
|
496
|
-
}(AbstractRendererPlugin);
|
|
497
|
-
|
|
498
|
-
var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
499
|
-
_inheritsLoose(Renderer, _AbstractRenderer);
|
|
500
|
-
function Renderer(config) {
|
|
501
|
-
var _this;
|
|
502
|
-
_this = _AbstractRenderer.call(this, config) || this;
|
|
503
|
-
// register Canvas2DContext
|
|
504
|
-
_this.registerPlugin(new ContextRegisterPlugin());
|
|
505
|
-
_this.registerPlugin(new Plugin());
|
|
506
|
-
_this.registerPlugin(new Plugin$1());
|
|
507
|
-
// enable rendering with Canvas2D API
|
|
508
|
-
_this.registerPlugin(new Plugin$2());
|
|
509
|
-
_this.registerPlugin(new Plugin$3());
|
|
510
|
-
// enable picking with Canvas2D API
|
|
511
|
-
_this.registerPlugin(new Plugin$4());
|
|
512
|
-
// render HTML component
|
|
513
|
-
_this.registerPlugin(new Plugin$5());
|
|
514
|
-
return _this;
|
|
515
|
-
}
|
|
516
|
-
return Renderer;
|
|
517
|
-
}(AbstractRenderer);
|
|
143
|
+
return Renderer;
|
|
144
|
+
}(AbstractRenderer));
|
|
518
145
|
|
|
519
146
|
export { Renderer };
|
|
147
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/packages/g-canvas/src/Canvas2DContextService.ts","../src/packages/g-canvas/src/ContextRegisterPlugin.ts","../src/packages/g-canvas/src/index.ts"],"sourcesContent":[null,null,null],"names":[],"mappings":";;;;;;;;;;;;;;;;AAYA,IAAA,sBAAA,kBAAA,YAAA;AAaE,IAAA,SAAA,sBAAA,CAAY,OAAsC,EAAA;AAChD,QAAA,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;AACjD,QAAA,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;KACpC;AAED,IAAA,sBAAA,CAAA,SAAA,CAAA,IAAI,GAAJ,YAAA;QACQ,IAAA,EAAA,GAAwB,IAAI,CAAC,YAAY,EAAvC,SAAS,GAAA,EAAA,CAAA,SAAA,EAAE,MAAM,GAAA,EAAA,CAAA,MAAsB,CAAC;AAEhD,QAAA,IAAI,MAAM,EAAE;AACV,YAAA,IAAI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