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