@idraw/renderer 0.3.0-beta.3 → 0.3.0-beta.6

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.
@@ -7,26 +7,26 @@ var iDrawRenderer = function() {
7
7
  function str4() {
8
8
  return ((1 + Math.random()) * 65536 | 0).toString(16).substring(1);
9
9
  }
10
- return `${str4()}${str4()}-${str4()}-${str4()}-${str4()}-${str4()}${str4()}${str4()}`;
10
+ return "".concat(str4()).concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4()).concat(str4()).concat(str4());
11
11
  }
12
12
  function deepClone(target) {
13
13
  function _clone(t) {
14
- const type = is$1(t);
14
+ var type = is$1(t);
15
15
  if (["Null", "Number", "String", "Boolean", "Undefined"].indexOf(type) >= 0) {
16
16
  return t;
17
17
  } else if (type === "Array") {
18
- const arr = [];
19
- t.forEach((item) => {
20
- arr.push(_clone(item));
18
+ var arr_1 = [];
19
+ t.forEach(function(item) {
20
+ arr_1.push(_clone(item));
21
21
  });
22
- return arr;
22
+ return arr_1;
23
23
  } else if (type === "Object") {
24
- const obj = {};
25
- const keys = Object.keys(t);
26
- keys.forEach((key) => {
27
- obj[key] = _clone(t[key]);
24
+ var obj_1 = {};
25
+ var keys = Object.keys(t);
26
+ keys.forEach(function(key) {
27
+ obj_1[key] = _clone(t[key]);
28
28
  });
29
- return obj;
29
+ return obj_1;
30
30
  }
31
31
  }
32
32
  return _clone(target);
@@ -35,85 +35,56 @@ var iDrawRenderer = function() {
35
35
  return Object.prototype.toString.call(data).replace(/[\]|\[]{1,1}/ig, "").split(" ")[1];
36
36
  }
37
37
  function parsePrototype(data) {
38
- const typeStr = Object.prototype.toString.call(data) || "";
39
- const result = typeStr.replace(/(\[object|\])/ig, "").trim();
38
+ var typeStr = Object.prototype.toString.call(data) || "";
39
+ var result = typeStr.replace(/(\[object|\])/ig, "").trim();
40
40
  return result;
41
41
  }
42
- const istype = {
43
- type(data, lowerCase) {
44
- const result = parsePrototype(data);
42
+ var istype = {
43
+ type: function(data, lowerCase) {
44
+ var result = parsePrototype(data);
45
45
  return lowerCase === true ? result.toLocaleLowerCase() : result;
46
46
  },
47
- array(data) {
47
+ array: function(data) {
48
48
  return parsePrototype(data) === "Array";
49
49
  },
50
- json(data) {
50
+ json: function(data) {
51
51
  return parsePrototype(data) === "Object";
52
52
  },
53
- function(data) {
53
+ function: function(data) {
54
54
  return parsePrototype(data) === "Function";
55
55
  },
56
- asyncFunction(data) {
56
+ asyncFunction: function(data) {
57
57
  return parsePrototype(data) === "AsyncFunction";
58
58
  },
59
- string(data) {
59
+ string: function(data) {
60
60
  return parsePrototype(data) === "String";
61
61
  },
62
- number(data) {
62
+ number: function(data) {
63
63
  return parsePrototype(data) === "Number";
64
64
  },
65
- undefined(data) {
65
+ undefined: function(data) {
66
66
  return parsePrototype(data) === "Undefined";
67
67
  },
68
- null(data) {
68
+ null: function(data) {
69
69
  return parsePrototype(data) === "Null";
70
70
  },
71
- promise(data) {
71
+ promise: function(data) {
72
72
  return parsePrototype(data) === "Promise";
73
73
  }
74
74
  };
75
- function parseHTMLToDataURL(html2, opts) {
76
- const { width, height } = opts;
77
- return new Promise((resolve, reject) => {
78
- const _svg = `
79
- <svg xmlns="http://www.w3.org/2000/svg" width="${width || ""}" height = "${height || ""}">
80
- <foreignObject width="100%" height="100%">
81
- <div xmlns = "http://www.w3.org/1999/xhtml">
82
- ${html2}
83
- </div>
84
- </foreignObject>
85
- </svg>
86
- `;
87
- const blob = new Blob([_svg], { type: "image/svg+xml;charset=utf-8" });
88
- const reader = new FileReader();
89
- reader.readAsDataURL(blob);
90
- reader.onload = function(event) {
91
- var _a2;
92
- const base64 = (_a2 = event === null || event === void 0 ? void 0 : event.target) === null || _a2 === void 0 ? void 0 : _a2.result;
93
- resolve(base64);
94
- };
95
- reader.onerror = function(err) {
96
- reject(err);
97
- };
98
- });
99
- }
100
- function parseSVGToDataURL(svg2) {
101
- return new Promise((resolve, reject) => {
102
- const _svg = svg2;
103
- const blob = new Blob([_svg], { type: "image/svg+xml;charset=utf-8" });
104
- const reader = new FileReader();
105
- reader.readAsDataURL(blob);
106
- reader.onload = function(event) {
107
- var _a2;
108
- const base64 = (_a2 = event === null || event === void 0 ? void 0 : event.target) === null || _a2 === void 0 ? void 0 : _a2.result;
109
- resolve(base64);
110
- };
111
- reader.onerror = function(err) {
112
- reject(err);
113
- };
114
- });
115
- }
116
- var __awaiter = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P, generator) {
75
+ var __assign = function() {
76
+ __assign = Object.assign || function __assign2(t) {
77
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
78
+ s = arguments[i];
79
+ for (var p in s)
80
+ if (Object.prototype.hasOwnProperty.call(s, p))
81
+ t[p] = s[p];
82
+ }
83
+ return t;
84
+ };
85
+ return __assign.apply(this, arguments);
86
+ };
87
+ function __awaiter(thisArg, _arguments, P, generator) {
117
88
  function adopt(value) {
118
89
  return value instanceof P ? value : new P(function(resolve) {
119
90
  resolve(value);
@@ -139,12 +110,120 @@ var iDrawRenderer = function() {
139
110
  }
140
111
  step((generator = generator.apply(thisArg, _arguments || [])).next());
141
112
  });
142
- };
143
- const { Image } = window;
113
+ }
114
+ function __generator(thisArg, body) {
115
+ var _ = { label: 0, sent: function() {
116
+ if (t[0] & 1)
117
+ throw t[1];
118
+ return t[1];
119
+ }, trys: [], ops: [] }, f, y2, t, g;
120
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
121
+ return this;
122
+ }), g;
123
+ function verb(n) {
124
+ return function(v) {
125
+ return step([n, v]);
126
+ };
127
+ }
128
+ function step(op) {
129
+ if (f)
130
+ throw new TypeError("Generator is already executing.");
131
+ while (_)
132
+ try {
133
+ if (f = 1, y2 && (t = op[0] & 2 ? y2["return"] : op[0] ? y2["throw"] || ((t = y2["return"]) && t.call(y2), 0) : y2.next) && !(t = t.call(y2, op[1])).done)
134
+ return t;
135
+ if (y2 = 0, t)
136
+ op = [op[0] & 2, t.value];
137
+ switch (op[0]) {
138
+ case 0:
139
+ case 1:
140
+ t = op;
141
+ break;
142
+ case 4:
143
+ _.label++;
144
+ return { value: op[1], done: false };
145
+ case 5:
146
+ _.label++;
147
+ y2 = op[1];
148
+ op = [0];
149
+ continue;
150
+ case 7:
151
+ op = _.ops.pop();
152
+ _.trys.pop();
153
+ continue;
154
+ default:
155
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
156
+ _ = 0;
157
+ continue;
158
+ }
159
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
160
+ _.label = op[1];
161
+ break;
162
+ }
163
+ if (op[0] === 6 && _.label < t[1]) {
164
+ _.label = t[1];
165
+ t = op;
166
+ break;
167
+ }
168
+ if (t && _.label < t[2]) {
169
+ _.label = t[2];
170
+ _.ops.push(op);
171
+ break;
172
+ }
173
+ if (t[2])
174
+ _.ops.pop();
175
+ _.trys.pop();
176
+ continue;
177
+ }
178
+ op = body.call(thisArg, _);
179
+ } catch (e) {
180
+ op = [6, e];
181
+ y2 = 0;
182
+ } finally {
183
+ f = t = 0;
184
+ }
185
+ if (op[0] & 5)
186
+ throw op[1];
187
+ return { value: op[0] ? op[1] : void 0, done: true };
188
+ }
189
+ }
190
+ function parseHTMLToDataURL(html2, opts) {
191
+ var width = opts.width, height = opts.height;
192
+ return new Promise(function(resolve, reject) {
193
+ var _svg = '\n <svg xmlns="http://www.w3.org/2000/svg" width="'.concat(width || "", '" height = "').concat(height || "", '">\n <foreignObject width="100%" height="100%">\n <div xmlns = "http://www.w3.org/1999/xhtml">\n ').concat(html2, "\n </div>\n </foreignObject>\n </svg>\n ");
194
+ var blob = new Blob([_svg], { type: "image/svg+xml;charset=utf-8" });
195
+ var reader = new FileReader();
196
+ reader.readAsDataURL(blob);
197
+ reader.onload = function(event) {
198
+ var _a;
199
+ var base64 = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.result;
200
+ resolve(base64);
201
+ };
202
+ reader.onerror = function(err) {
203
+ reject(err);
204
+ };
205
+ });
206
+ }
207
+ function parseSVGToDataURL(svg2) {
208
+ return new Promise(function(resolve, reject) {
209
+ var _svg = svg2;
210
+ var blob = new Blob([_svg], { type: "image/svg+xml;charset=utf-8" });
211
+ var reader = new FileReader();
212
+ reader.readAsDataURL(blob);
213
+ reader.onload = function(event) {
214
+ var _a;
215
+ var base64 = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.result;
216
+ resolve(base64);
217
+ };
218
+ reader.onerror = function(err) {
219
+ reject(err);
220
+ };
221
+ });
222
+ }
223
+ var Image = window.Image;
144
224
  function loadImage(src) {
145
- return new Promise((resolve, reject) => {
146
- const img = new Image();
147
- img.crossOrigin = "anonymous";
225
+ return new Promise(function(resolve, reject) {
226
+ var img = new Image();
148
227
  img.onload = function() {
149
228
  resolve(img);
150
229
  };
@@ -154,25 +233,41 @@ var iDrawRenderer = function() {
154
233
  });
155
234
  }
156
235
  function loadSVG(svg2) {
157
- return __awaiter(this, void 0, void 0, function* () {
158
- const dataURL = yield parseSVGToDataURL(svg2);
159
- const image = yield loadImage(dataURL);
160
- return image;
236
+ return __awaiter(this, void 0, void 0, function() {
237
+ var dataURL, image;
238
+ return __generator(this, function(_a) {
239
+ switch (_a.label) {
240
+ case 0:
241
+ return [4, parseSVGToDataURL(svg2)];
242
+ case 1:
243
+ dataURL = _a.sent();
244
+ return [4, loadImage(dataURL)];
245
+ case 2:
246
+ image = _a.sent();
247
+ return [2, image];
248
+ }
249
+ });
161
250
  });
162
251
  }
163
- function filterAmpersand(str) {
164
- return str.replace(/\&/ig, "&amp;");
165
- }
166
252
  function loadHTML(html2, opts) {
167
- return __awaiter(this, void 0, void 0, function* () {
168
- html2 = filterAmpersand(html2);
169
- const dataURL = yield parseHTMLToDataURL(html2, opts);
170
- const image = yield loadImage(dataURL);
171
- return image;
253
+ return __awaiter(this, void 0, void 0, function() {
254
+ var dataURL, image;
255
+ return __generator(this, function(_a) {
256
+ switch (_a.label) {
257
+ case 0:
258
+ return [4, parseHTMLToDataURL(html2, opts)];
259
+ case 1:
260
+ dataURL = _a.sent();
261
+ return [4, loadImage(dataURL)];
262
+ case 2:
263
+ image = _a.sent();
264
+ return [2, image];
265
+ }
266
+ });
172
267
  });
173
268
  }
174
- class Context {
175
- constructor(ctx, opts) {
269
+ var Context = function() {
270
+ function Context2(ctx, opts) {
176
271
  this._opts = opts;
177
272
  this._ctx = ctx;
178
273
  this._transform = {
@@ -181,19 +276,19 @@ var iDrawRenderer = function() {
181
276
  scrollY: 0
182
277
  };
183
278
  }
184
- getContext() {
279
+ Context2.prototype.getContext = function() {
185
280
  return this._ctx;
186
- }
187
- resetSize(opts) {
188
- this._opts = Object.assign(Object.assign({}, this._opts), opts);
189
- }
190
- calcDeviceNum(num) {
281
+ };
282
+ Context2.prototype.resetSize = function(opts) {
283
+ this._opts = __assign(__assign({}, this._opts), opts);
284
+ };
285
+ Context2.prototype.calcDeviceNum = function(num) {
191
286
  return num * this._opts.devicePixelRatio;
192
- }
193
- calcScreenNum(num) {
287
+ };
288
+ Context2.prototype.calcScreenNum = function(num) {
194
289
  return num / this._opts.devicePixelRatio;
195
- }
196
- getSize() {
290
+ };
291
+ Context2.prototype.getSize = function() {
197
292
  return {
198
293
  width: this._opts.width,
199
294
  height: this._opts.height,
@@ -201,166 +296,174 @@ var iDrawRenderer = function() {
201
296
  contextHeight: this._opts.contextHeight,
202
297
  devicePixelRatio: this._opts.devicePixelRatio
203
298
  };
204
- }
205
- setTransform(config) {
206
- this._transform = Object.assign(Object.assign({}, this._transform), config);
207
- }
208
- getTransform() {
299
+ };
300
+ Context2.prototype.setTransform = function(config) {
301
+ this._transform = __assign(__assign({}, this._transform), config);
302
+ };
303
+ Context2.prototype.getTransform = function() {
209
304
  return {
210
305
  scale: this._transform.scale,
211
306
  scrollX: this._transform.scrollX,
212
307
  scrollY: this._transform.scrollY
213
308
  };
214
- }
215
- setFillStyle(color2) {
309
+ };
310
+ Context2.prototype.setFillStyle = function(color2) {
216
311
  this._ctx.fillStyle = color2;
217
- }
218
- fill(fillRule) {
312
+ };
313
+ Context2.prototype.fill = function(fillRule) {
219
314
  return this._ctx.fill(fillRule || "nonzero");
220
- }
221
- arc(x2, y2, radius, startAngle, endAngle, anticlockwise) {
315
+ };
316
+ Context2.prototype.arc = function(x2, y2, radius, startAngle, endAngle, anticlockwise) {
222
317
  return this._ctx.arc(this._doSize(x2), this._doSize(y2), this._doSize(radius), startAngle, endAngle, anticlockwise);
223
- }
224
- rect(x2, y2, w2, h2) {
318
+ };
319
+ Context2.prototype.rect = function(x2, y2, w2, h2) {
225
320
  return this._ctx.rect(this._doSize(x2), this._doSize(y2), this._doSize(w2), this._doSize(h2));
226
- }
227
- fillRect(x2, y2, w2, h2) {
321
+ };
322
+ Context2.prototype.fillRect = function(x2, y2, w2, h2) {
228
323
  return this._ctx.fillRect(this._doSize(x2), this._doSize(y2), this._doSize(w2), this._doSize(h2));
229
- }
230
- clearRect(x2, y2, w2, h2) {
324
+ };
325
+ Context2.prototype.clearRect = function(x2, y2, w2, h2) {
231
326
  return this._ctx.clearRect(this._doSize(x2), this._doSize(y2), this._doSize(w2), this._doSize(h2));
232
- }
233
- beginPath() {
327
+ };
328
+ Context2.prototype.beginPath = function() {
234
329
  return this._ctx.beginPath();
235
- }
236
- closePath() {
330
+ };
331
+ Context2.prototype.closePath = function() {
237
332
  return this._ctx.closePath();
238
- }
239
- lineTo(x2, y2) {
333
+ };
334
+ Context2.prototype.lineTo = function(x2, y2) {
240
335
  return this._ctx.lineTo(this._doSize(x2), this._doSize(y2));
241
- }
242
- moveTo(x2, y2) {
336
+ };
337
+ Context2.prototype.moveTo = function(x2, y2) {
243
338
  return this._ctx.moveTo(this._doSize(x2), this._doSize(y2));
244
- }
245
- arcTo(x1, y1, x2, y2, radius) {
339
+ };
340
+ Context2.prototype.arcTo = function(x1, y1, x2, y2, radius) {
246
341
  return this._ctx.arcTo(this._doSize(x1), this._doSize(y1), this._doSize(x2), this._doSize(y2), this._doSize(radius));
247
- }
248
- setLineWidth(w2) {
342
+ };
343
+ Context2.prototype.setLineWidth = function(w2) {
249
344
  return this._ctx.lineWidth = this._doSize(w2);
250
- }
251
- setLineDash(nums) {
252
- return this._ctx.setLineDash(nums.map((n) => this._doSize(n)));
253
- }
254
- isPointInPath(x2, y2) {
345
+ };
346
+ Context2.prototype.setLineDash = function(nums) {
347
+ var _this = this;
348
+ return this._ctx.setLineDash(nums.map(function(n) {
349
+ return _this._doSize(n);
350
+ }));
351
+ };
352
+ Context2.prototype.isPointInPath = function(x2, y2) {
255
353
  return this._ctx.isPointInPath(this._doX(x2), this._doY(y2));
256
- }
257
- isPointInPathWithoutScroll(x2, y2) {
354
+ };
355
+ Context2.prototype.isPointInPathWithoutScroll = function(x2, y2) {
258
356
  return this._ctx.isPointInPath(this._doSize(x2), this._doSize(y2));
259
- }
260
- setStrokeStyle(color2) {
357
+ };
358
+ Context2.prototype.setStrokeStyle = function(color2) {
261
359
  this._ctx.strokeStyle = color2;
262
- }
263
- stroke() {
360
+ };
361
+ Context2.prototype.stroke = function() {
264
362
  return this._ctx.stroke();
265
- }
266
- translate(x2, y2) {
363
+ };
364
+ Context2.prototype.translate = function(x2, y2) {
267
365
  return this._ctx.translate(this._doSize(x2), this._doSize(y2));
268
- }
269
- rotate(angle2) {
366
+ };
367
+ Context2.prototype.rotate = function(angle2) {
270
368
  return this._ctx.rotate(angle2);
271
- }
272
- drawImage(...args) {
273
- const image = args[0];
274
- const sx = args[1];
275
- const sy = args[2];
276
- const sw = args[3];
277
- const sh = args[4];
278
- const dx = args[args.length - 4];
279
- const dy = args[args.length - 3];
280
- const dw = args[args.length - 2];
281
- const dh = args[args.length - 1];
369
+ };
370
+ Context2.prototype.drawImage = function() {
371
+ var args = [];
372
+ for (var _i = 0; _i < arguments.length; _i++) {
373
+ args[_i] = arguments[_i];
374
+ }
375
+ var image = args[0];
376
+ var sx = args[1];
377
+ var sy = args[2];
378
+ var sw = args[3];
379
+ var sh = args[4];
380
+ var dx = args[args.length - 4];
381
+ var dy = args[args.length - 3];
382
+ var dw = args[args.length - 2];
383
+ var dh = args[args.length - 1];
282
384
  if (args.length === 9) {
283
385
  return this._ctx.drawImage(image, this._doSize(sx), this._doSize(sy), this._doSize(sw), this._doSize(sh), this._doSize(dx), this._doSize(dy), this._doSize(dw), this._doSize(dh));
284
386
  } else {
285
387
  return this._ctx.drawImage(image, this._doSize(dx), this._doSize(dy), this._doSize(dw), this._doSize(dh));
286
388
  }
287
- }
288
- createPattern(image, repetition) {
389
+ };
390
+ Context2.prototype.createPattern = function(image, repetition) {
289
391
  return this._ctx.createPattern(image, repetition);
290
- }
291
- measureText(text2) {
392
+ };
393
+ Context2.prototype.measureText = function(text2) {
292
394
  return this._ctx.measureText(text2);
293
- }
294
- setTextAlign(align) {
395
+ };
396
+ Context2.prototype.setTextAlign = function(align) {
295
397
  this._ctx.textAlign = align;
296
- }
297
- fillText(text2, x2, y2, maxWidth) {
398
+ };
399
+ Context2.prototype.fillText = function(text2, x2, y2, maxWidth) {
298
400
  if (maxWidth !== void 0) {
299
401
  return this._ctx.fillText(text2, this._doSize(x2), this._doSize(y2), this._doSize(maxWidth));
300
402
  } else {
301
403
  return this._ctx.fillText(text2, this._doSize(x2), this._doSize(y2));
302
404
  }
303
- }
304
- strokeText(text2, x2, y2, maxWidth) {
405
+ };
406
+ Context2.prototype.strokeText = function(text2, x2, y2, maxWidth) {
305
407
  if (maxWidth !== void 0) {
306
408
  return this._ctx.strokeText(text2, this._doSize(x2), this._doSize(y2), this._doSize(maxWidth));
307
409
  } else {
308
410
  return this._ctx.strokeText(text2, this._doSize(x2), this._doSize(y2));
309
411
  }
310
- }
311
- setFont(opts) {
312
- const strList = [];
412
+ };
413
+ Context2.prototype.setFont = function(opts) {
414
+ var strList = [];
313
415
  if (opts.fontWeight === "bold") {
314
- strList.push(`${opts.fontWeight}`);
416
+ strList.push("".concat(opts.fontWeight));
315
417
  }
316
- strList.push(`${this._doSize(opts.fontSize || 12)}px`);
317
- strList.push(`${opts.fontFamily || "sans-serif"}`);
318
- this._ctx.font = `${strList.join(" ")}`;
319
- }
320
- setTextBaseline(baseline) {
418
+ strList.push("".concat(this._doSize(opts.fontSize || 12), "px"));
419
+ strList.push("".concat(opts.fontFamily || "sans-serif"));
420
+ this._ctx.font = "".concat(strList.join(" "));
421
+ };
422
+ Context2.prototype.setTextBaseline = function(baseline) {
321
423
  this._ctx.textBaseline = baseline;
322
- }
323
- setGlobalAlpha(alpha) {
424
+ };
425
+ Context2.prototype.setGlobalAlpha = function(alpha) {
324
426
  this._ctx.globalAlpha = alpha;
325
- }
326
- save() {
427
+ };
428
+ Context2.prototype.save = function() {
327
429
  this._ctx.save();
328
- }
329
- restore() {
430
+ };
431
+ Context2.prototype.restore = function() {
330
432
  this._ctx.restore();
331
- }
332
- scale(ratioX, ratioY) {
433
+ };
434
+ Context2.prototype.scale = function(ratioX, ratioY) {
333
435
  this._ctx.scale(ratioX, ratioY);
334
- }
335
- setShadowColor(color2) {
436
+ };
437
+ Context2.prototype.setShadowColor = function(color2) {
336
438
  this._ctx.shadowColor = color2;
337
- }
338
- setShadowOffsetX(offsetX) {
439
+ };
440
+ Context2.prototype.setShadowOffsetX = function(offsetX) {
339
441
  this._ctx.shadowOffsetX = this._doSize(offsetX);
340
- }
341
- setShadowOffsetY(offsetY) {
442
+ };
443
+ Context2.prototype.setShadowOffsetY = function(offsetY) {
342
444
  this._ctx.shadowOffsetY = this._doSize(offsetY);
343
- }
344
- setShadowBlur(blur) {
445
+ };
446
+ Context2.prototype.setShadowBlur = function(blur) {
345
447
  this._ctx.shadowBlur = this._doSize(blur);
346
- }
347
- ellipse(x2, y2, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise) {
448
+ };
449
+ Context2.prototype.ellipse = function(x2, y2, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise) {
348
450
  this._ctx.ellipse(this._doSize(x2), this._doSize(y2), this._doSize(radiusX), this._doSize(radiusY), rotation, startAngle, endAngle, counterclockwise);
349
- }
350
- _doSize(num) {
451
+ };
452
+ Context2.prototype._doSize = function(num) {
351
453
  return this._opts.devicePixelRatio * num;
352
- }
353
- _doX(x2) {
354
- const { scale, scrollX } = this._transform;
355
- const _x = (x2 - scrollX) / scale;
454
+ };
455
+ Context2.prototype._doX = function(x2) {
456
+ var _a = this._transform, scale = _a.scale, scrollX = _a.scrollX;
457
+ var _x = (x2 - scrollX) / scale;
356
458
  return this._doSize(_x);
357
- }
358
- _doY(y2) {
359
- const { scale, scrollY } = this._transform;
360
- const _y = (y2 - scrollY) / scale;
459
+ };
460
+ Context2.prototype._doY = function(y2) {
461
+ var _a = this._transform, scale = _a.scale, scrollY = _a.scrollY;
462
+ var _y = (y2 - scrollY) / scale;
361
463
  return this._doSize(_y);
362
- }
363
- }
464
+ };
465
+ return Context2;
466
+ }();
364
467
  function number(value) {
365
468
  return typeof value === "number" && (value > 0 || value <= 0);
366
469
  }
@@ -389,21 +492,21 @@ var iDrawRenderer = function() {
389
492
  return isColorStr(value);
390
493
  }
391
494
  function imageURL(value) {
392
- return typeof value === "string" && /^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${value}`);
495
+ return typeof value === "string" && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("".concat(value));
393
496
  }
394
497
  function imageBase64(value) {
395
- return typeof value === "string" && /^(data:image\/)/.test(`${value}`);
498
+ return typeof value === "string" && /^(data:image\/)/.test("".concat(value));
396
499
  }
397
500
  function imageSrc(value) {
398
501
  return imageBase64(value) || imageURL(value);
399
502
  }
400
503
  function svg(value) {
401
- return typeof value === "string" && /^(<svg[\s]{1,}|<svg>)/i.test(`${value}`.trim()) && /<\/[\s]{0,}svg>$/i.test(`${value}`.trim());
504
+ return typeof value === "string" && /^(<svg[\s]{1,}|<svg>)/i.test("".concat(value).trim()) && /<\/[\s]{0,}svg>$/i.test("".concat(value).trim());
402
505
  }
403
506
  function html(value) {
404
- let result = false;
507
+ var result = false;
405
508
  if (typeof value === "string") {
406
- let div = document.createElement("div");
509
+ var div = document.createElement("div");
407
510
  div.innerHTML = value;
408
511
  if (div.children.length > 0) {
409
512
  result = true;
@@ -433,7 +536,7 @@ var iDrawRenderer = function() {
433
536
  function fontWeight(value) {
434
537
  return ["bold"].includes(value);
435
538
  }
436
- const is = {
539
+ var is = {
437
540
  x,
438
541
  y,
439
542
  w,
@@ -744,7 +847,7 @@ var iDrawRenderer = function() {
744
847
  });
745
848
  }
746
849
  function drawContext(ctx, data, loader) {
747
- var _a2;
850
+ var _a;
748
851
  clearContext(ctx);
749
852
  const size = ctx.getSize();
750
853
  ctx.clearRect(0, 0, size.contextWidth, size.contextHeight);
@@ -756,7 +859,7 @@ var iDrawRenderer = function() {
756
859
  }
757
860
  for (let i = 0; i < data.elements.length; i++) {
758
861
  const elem = data.elements[i];
759
- if (((_a2 = elem == null ? void 0 : elem.operation) == null ? void 0 : _a2.invisible) === true) {
862
+ if (((_a = elem == null ? void 0 : elem.operation) == null ? void 0 : _a.invisible) === true) {
760
863
  continue;
761
864
  }
762
865
  switch (elem.type) {
@@ -850,7 +953,10 @@ var iDrawRenderer = function() {
850
953
  this._waitingLoadQueue = [];
851
954
  }
852
955
  load(data, changeResourceUUIDs) {
853
- const [uuidQueue, loadData] = this._resetLoadData(data, changeResourceUUIDs);
956
+ const [uuidQueue, loadData] = this._resetLoadData(
957
+ data,
958
+ changeResourceUUIDs
959
+ );
854
960
  if (this._status === "free" || this._status === "complete") {
855
961
  this._currentUUIDQueue = uuidQueue;
856
962
  this._currentLoadData = loadData;
@@ -872,14 +978,14 @@ var iDrawRenderer = function() {
872
978
  return this._status === "complete";
873
979
  }
874
980
  getContent(uuid) {
875
- var _a2;
876
- if (((_a2 = this._storageLoadData[uuid]) == null ? void 0 : _a2.status) === "loaded") {
981
+ var _a;
982
+ if (((_a = this._storageLoadData[uuid]) == null ? void 0 : _a.status) === "loaded") {
877
983
  return this._storageLoadData[uuid].content;
878
984
  }
879
985
  return null;
880
986
  }
881
987
  // getPattern(
882
- // elem: TypeElement<keyof TypeElemDesc>,
988
+ // elem: DataElement<keyof DataElemDesc>,
883
989
  // opts?: {
884
990
  // forceUpdate: boolean
885
991
  // }
@@ -990,7 +1096,7 @@ var iDrawRenderer = function() {
990
1096
  }
991
1097
  loadUUIDList.push(uuid);
992
1098
  this._loadElementSource(this._currentLoadData[uuid]).then((image) => {
993
- var _a2, _b2;
1099
+ var _a, _b;
994
1100
  loadUUIDList.splice(loadUUIDList.indexOf(uuid), 1);
995
1101
  const status = _loadAction();
996
1102
  this._storageLoadData[uuid] = {
@@ -1008,29 +1114,29 @@ var iDrawRenderer = function() {
1008
1114
  this._loadTask();
1009
1115
  }
1010
1116
  this._event.trigger("load", {
1011
- uuid: (_a2 = this._storageLoadData[uuid]) == null ? void 0 : _a2.uuid,
1117
+ uuid: (_a = this._storageLoadData[uuid]) == null ? void 0 : _a.uuid,
1012
1118
  type: this._storageLoadData[uuid].type,
1013
1119
  status: this._storageLoadData[uuid].status,
1014
1120
  content: this._storageLoadData[uuid].content,
1015
1121
  source: this._storageLoadData[uuid].source,
1016
1122
  elemW: this._storageLoadData[uuid].elemW,
1017
1123
  elemH: this._storageLoadData[uuid].elemH,
1018
- element: (_b2 = this._storageLoadData[uuid]) == null ? void 0 : _b2.element
1124
+ element: (_b = this._storageLoadData[uuid]) == null ? void 0 : _b.element
1019
1125
  });
1020
1126
  }).catch((err) => {
1021
- var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1127
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1022
1128
  console.warn(err);
1023
1129
  loadUUIDList.splice(loadUUIDList.indexOf(uuid), 1);
1024
1130
  const status = _loadAction();
1025
1131
  if (this._currentLoadData[uuid]) {
1026
1132
  this._storageLoadData[uuid] = {
1027
1133
  uuid,
1028
- type: (_a2 = this._currentLoadData[uuid]) == null ? void 0 : _a2.type,
1134
+ type: (_a = this._currentLoadData[uuid]) == null ? void 0 : _a.type,
1029
1135
  status: "fail",
1030
1136
  content: null,
1031
1137
  error: err,
1032
- source: (_b2 = this._currentLoadData[uuid]) == null ? void 0 : _b2.source,
1033
- elemW: (_c2 = this._currentLoadData[uuid]) == null ? void 0 : _c2.elemW,
1138
+ source: (_b = this._currentLoadData[uuid]) == null ? void 0 : _b.source,
1139
+ elemW: (_c = this._currentLoadData[uuid]) == null ? void 0 : _c.elemW,
1034
1140
  elemH: (_d = this._currentLoadData[uuid]) == null ? void 0 : _d.elemH,
1035
1141
  element: (_e = this._currentLoadData[uuid]) == null ? void 0 : _e.element
1036
1142
  };
@@ -1062,18 +1168,13 @@ var iDrawRenderer = function() {
1062
1168
  const image = await loadImage(params.source);
1063
1169
  return image;
1064
1170
  } else if (params && params.type === "svg") {
1065
- const image = await loadSVG(
1066
- params.source
1067
- );
1171
+ const image = await loadSVG(params.source);
1068
1172
  return image;
1069
1173
  } else if (params && params.type === "html") {
1070
- const image = await loadHTML(
1071
- params.source,
1072
- {
1073
- width: params.elemW,
1074
- height: params.elemH
1075
- }
1076
- );
1174
+ const image = await loadHTML(params.source, {
1175
+ width: params.elemW,
1176
+ height: params.elemH
1177
+ });
1077
1178
  return image;
1078
1179
  }
1079
1180
  throw Error("Element's source is not support!");
@@ -1127,40 +1228,31 @@ var iDrawRenderer = function() {
1127
1228
  return false;
1128
1229
  }
1129
1230
  }
1130
- const _queue = Symbol("_queue");
1131
- const _ctx = Symbol("_ctx");
1132
- const _status = Symbol("_status");
1133
- const _loader = Symbol("_loader");
1134
- const _opts = Symbol("_opts");
1135
- const _freeze = Symbol("_freeze");
1136
- const _drawFrame = Symbol("_drawFrame");
1137
- const _retainQueueOneItem = Symbol("_retainQueueOneItem");
1138
- var _a, _b, _c;
1139
1231
  const { requestAnimationFrame } = window;
1140
1232
  class Renderer extends RendererEvent {
1141
1233
  constructor(opts) {
1142
1234
  super();
1143
- this[_a] = [];
1144
- this[_b] = null;
1145
- this[_c] = "null";
1146
- this[_opts] = opts;
1147
- this[_loader] = new Loader({
1235
+ this._queue = [];
1236
+ this._ctx = null;
1237
+ this._status = "null";
1238
+ this._opts = opts;
1239
+ this._loader = new Loader({
1148
1240
  maxParallelNum: 6
1149
1241
  });
1150
- this[_loader].on("load", (res) => {
1151
- this[_drawFrame]();
1242
+ this._loader.on("load", (res) => {
1243
+ this._drawFrame();
1152
1244
  this.trigger("load", { element: res.element });
1153
1245
  });
1154
- this[_loader].on("error", (res) => {
1246
+ this._loader.on("error", (res) => {
1155
1247
  this.trigger("error", { element: res.element, error: res.error });
1156
1248
  });
1157
- this[_loader].on("complete", () => {
1249
+ this._loader.on("complete", () => {
1158
1250
  this.trigger("loadComplete", { t: Date.now() });
1159
1251
  });
1160
1252
  }
1161
1253
  render(target, originData, opts) {
1162
1254
  const { changeResourceUUIDs = [] } = opts || {};
1163
- this[_status] = "free";
1255
+ this._status = "free";
1164
1256
  const data = deepClone(originData);
1165
1257
  if (Array.isArray(data.elements)) {
1166
1258
  data.elements.forEach((elem) => {
@@ -1169,14 +1261,14 @@ var iDrawRenderer = function() {
1169
1261
  }
1170
1262
  });
1171
1263
  }
1172
- if (!this[_ctx]) {
1173
- if (this[_opts] && Object.prototype.toString.call(target) === "[object HTMLCanvasElement]") {
1174
- const { width, height, contextWidth, contextHeight, devicePixelRatio } = this[_opts];
1264
+ if (!this._ctx) {
1265
+ if (this._opts && Object.prototype.toString.call(target) === "[object HTMLCanvasElement]") {
1266
+ const { width, height, contextWidth, contextHeight, devicePixelRatio } = this._opts;
1175
1267
  const canvas = target;
1176
1268
  canvas.width = width * devicePixelRatio;
1177
1269
  canvas.height = height * devicePixelRatio;
1178
1270
  const ctx2d = canvas.getContext("2d");
1179
- this[_ctx] = new Context(ctx2d, {
1271
+ this._ctx = new Context(ctx2d, {
1180
1272
  width,
1181
1273
  height,
1182
1274
  contextWidth: contextWidth || width,
@@ -1184,77 +1276,77 @@ var iDrawRenderer = function() {
1184
1276
  devicePixelRatio
1185
1277
  });
1186
1278
  } else if (target) {
1187
- this[_ctx] = target;
1279
+ this._ctx = target;
1188
1280
  }
1189
1281
  }
1190
1282
  if ([
1191
1283
  "freeze"
1192
1284
  /* FREEZE */
1193
- ].includes(this[_status])) {
1285
+ ].includes(this._status)) {
1194
1286
  return;
1195
1287
  }
1196
1288
  const _data = deepClone({ data });
1197
- this[_queue].push(_data);
1198
- this[_drawFrame]();
1199
- this[_loader].load(data, changeResourceUUIDs || []);
1289
+ this._queue.push(_data);
1290
+ this._drawFrame();
1291
+ this._loader.load(data, changeResourceUUIDs || []);
1200
1292
  }
1201
1293
  getContext() {
1202
- return this[_ctx];
1294
+ return this._ctx;
1203
1295
  }
1204
1296
  thaw() {
1205
- this[_status] = "free";
1297
+ this._status = "free";
1206
1298
  }
1207
- [(_a = _queue, _b = _ctx, _c = _status, _freeze)]() {
1208
- this[_status] = "freeze";
1299
+ _freeze() {
1300
+ this._status = "freeze";
1209
1301
  }
1210
- [_drawFrame]() {
1211
- if (this[_status] === "freeze") {
1302
+ _drawFrame() {
1303
+ if (this._status === "freeze") {
1212
1304
  return;
1213
1305
  }
1214
1306
  requestAnimationFrame(() => {
1215
- if (this[_status] === "freeze") {
1307
+ if (this._status === "freeze") {
1216
1308
  return;
1217
1309
  }
1218
- const ctx = this[_ctx];
1219
- let item = this[_queue][0];
1310
+ const ctx = this._ctx;
1311
+ let item = this._queue[0];
1220
1312
  let isLastFrame = false;
1221
- if (this[_queue].length > 1) {
1222
- item = this[_queue].shift();
1313
+ if (this._queue.length > 1) {
1314
+ item = this._queue.shift();
1223
1315
  } else {
1224
1316
  isLastFrame = true;
1225
1317
  }
1226
- if (this[_loader].isComplete() !== true) {
1227
- this[_drawFrame]();
1318
+ if (this._loader.isComplete() !== true) {
1319
+ this._drawFrame();
1228
1320
  if (item && ctx) {
1229
- drawContext(ctx, item.data, this[_loader]);
1321
+ drawContext(ctx, item.data, this._loader);
1230
1322
  }
1231
1323
  } else if (item && ctx) {
1232
- drawContext(ctx, item.data, this[_loader]);
1233
- this[_retainQueueOneItem]();
1324
+ drawContext(ctx, item.data, this._loader);
1325
+ this._retainQueueOneItem();
1234
1326
  if (!isLastFrame) {
1235
- this[_drawFrame]();
1327
+ this._drawFrame();
1236
1328
  } else {
1237
- this[_status] = "free";
1329
+ this._status = "free";
1238
1330
  }
1239
1331
  } else {
1240
- this[_status] = "free";
1332
+ this._status = "free";
1241
1333
  }
1242
1334
  this.trigger("drawFrame", { t: Date.now() });
1243
- if (this[_loader].isComplete() === true && this[_queue].length === 1 && this[_status] === "free") {
1244
- if (ctx && this[_queue][0] && this[_queue][0].data) {
1245
- drawContext(ctx, this[_queue][0].data, this[_loader]);
1335
+ if (this._loader.isComplete() === true && this._queue.length === 1 && this._status === "free") {
1336
+ if (ctx && this._queue[0] && this._queue[0].data) {
1337
+ drawContext(ctx, this._queue[0].data, this._loader);
1246
1338
  }
1247
1339
  this.trigger("drawFrameComplete", { t: Date.now() });
1248
- this[_freeze]();
1340
+ this._freeze();
1249
1341
  }
1250
1342
  });
1251
1343
  }
1252
- [_retainQueueOneItem]() {
1253
- if (this[_queue].length <= 1) {
1344
+ _retainQueueOneItem() {
1345
+ if (this._queue.length <= 1) {
1254
1346
  return;
1255
1347
  }
1256
- const lastOne = deepClone(this[_queue][this[_queue].length - 1]);
1257
- this[_queue] = [lastOne];
1348
+ const lastOne = deepClone(this._queue[this._queue.length - 1]);
1349
+ this._queue = [lastOne];
1258
1350
  }
1259
1351
  }
1260
1352
  return Renderer;