@idraw/util 0.2.0-y.0 → 0.3.0-alpha.2

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.
@@ -69,12 +69,12 @@ var iDrawUtil = (function () {
69
69
  function str4() {
70
70
  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
71
71
  }
72
- return "" + str4() + str4() + "-" + str4() + "-" + str4() + "-" + str4() + "-" + str4() + str4() + str4();
72
+ return "".concat(str4()).concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4()).concat(str4()).concat(str4());
73
73
  }
74
74
 
75
75
  function deepClone(target) {
76
76
  function _clone(t) {
77
- var type = is(t);
77
+ var type = is$1(t);
78
78
  if (['Null', 'Number', 'String', 'Boolean', 'Undefined'].indexOf(type) >= 0) {
79
79
  return t;
80
80
  }
@@ -96,7 +96,7 @@ var iDrawUtil = (function () {
96
96
  }
97
97
  return _clone(target);
98
98
  }
99
- function is(data) {
99
+ function is$1(data) {
100
100
  return Object.prototype.toString.call(data).replace(/[\]|\[]{1,1}/ig, '').split(' ')[1];
101
101
  }
102
102
 
@@ -137,61 +137,82 @@ var iDrawUtil = (function () {
137
137
  promise: function (data) {
138
138
  return parsePrototype(data) === 'Promise';
139
139
  },
140
- nodeList: function (data) {
141
- return parsePrototype(data) === 'NodeList';
142
- },
143
- imageData: function (data) {
144
- return parsePrototype(data) === 'ImageData';
145
- }
146
140
  };
147
141
 
148
- var Image = window.Image, Blob = window.Blob, FileReader = window.FileReader;
149
- function loadImage(src) {
150
- return new Promise(function (resolve, reject) {
151
- var img = new Image;
152
- img.onload = function () {
153
- resolve(img);
154
- };
155
- img.onabort = reject;
156
- img.onerror = reject;
157
- img.src = src;
158
- });
159
- }
160
- function loadSVG(svg) {
142
+ var __assign = function() {
143
+ __assign = Object.assign || function __assign(t) {
144
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
145
+ s = arguments[i];
146
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
147
+ }
148
+ return t;
149
+ };
150
+ return __assign.apply(this, arguments);
151
+ };
152
+ function __awaiter(thisArg, _arguments, P, generator) {
153
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
154
+ return new (P || (P = Promise))(function (resolve, reject) {
155
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
156
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
157
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
158
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
159
+ });
160
+ }
161
+ function __generator(thisArg, body) {
162
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
163
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
164
+ function verb(n) { return function (v) { return step([n, v]); }; }
165
+ function step(op) {
166
+ if (f) throw new TypeError("Generator is already executing.");
167
+ while (_) try {
168
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
169
+ if (y = 0, t) op = [op[0] & 2, t.value];
170
+ switch (op[0]) {
171
+ case 0: case 1: t = op; break;
172
+ case 4: _.label++; return { value: op[1], done: false };
173
+ case 5: _.label++; y = op[1]; op = [0]; continue;
174
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
175
+ default:
176
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
177
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
178
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
179
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
180
+ if (t[2]) _.ops.pop();
181
+ _.trys.pop(); continue;
182
+ }
183
+ op = body.call(thisArg, _);
184
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
185
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
186
+ }
187
+ }
188
+
189
+ function parseHTMLToDataURL(html, opts) {
190
+ var width = opts.width, height = opts.height;
161
191
  return new Promise(function (resolve, reject) {
162
- var _svg = svg;
163
- var image = new Image();
192
+ 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(html, "\n </div>\n </foreignObject>\n </svg>\n ");
164
193
  var blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
165
194
  var reader = new FileReader();
166
195
  reader.readAsDataURL(blob);
167
196
  reader.onload = function (event) {
168
197
  var _a;
169
198
  var base64 = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.result;
170
- image.onload = function () {
171
- resolve(image);
172
- };
173
- image.src = base64;
199
+ resolve(base64);
174
200
  };
175
201
  reader.onerror = function (err) {
176
202
  reject(err);
177
203
  };
178
204
  });
179
205
  }
180
- function loadHTML(html, opts) {
181
- var width = opts.width, height = opts.height;
206
+ function parseSVGToDataURL(svg) {
182
207
  return new Promise(function (resolve, reject) {
183
- var _svg = "\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"" + (width || '') + "\" height = \"" + (height || '') + "\">\n <foreignObject width=\"100%\" height=\"100%\">\n <div xmlns = \"http://www.w3.org/1999/xhtml\">\n " + html + "\n </div>\n </foreignObject>\n </svg>\n ";
184
- var image = new Image();
208
+ var _svg = svg;
185
209
  var blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
186
210
  var reader = new FileReader();
187
211
  reader.readAsDataURL(blob);
188
212
  reader.onload = function (event) {
189
213
  var _a;
190
214
  var base64 = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.result;
191
- image.onload = function () {
192
- resolve(image);
193
- };
194
- image.src = base64;
215
+ resolve(base64);
195
216
  };
196
217
  reader.onerror = function (err) {
197
218
  reject(err);
@@ -199,34 +220,487 @@ var iDrawUtil = (function () {
199
220
  });
200
221
  }
201
222
 
202
- var index = {
203
- time: {
204
- delay: delay,
205
- compose: compose,
206
- throttle: throttle,
207
- },
208
- loader: {
209
- loadImage: loadImage,
210
- loadSVG: loadSVG,
211
- loadHTML: loadHTML,
212
- },
213
- file: {
214
- downloadImageFromCanvas: downloadImageFromCanvas,
215
- },
216
- color: {
217
- toColorHexStr: toColorHexStr,
218
- toColorHexNum: toColorHexNum,
219
- isColorStr: isColorStr,
220
- },
221
- uuid: {
222
- createUUID: createUUID
223
- },
224
- istype: istype,
225
- data: {
226
- deepClone: deepClone,
223
+ var Image = window.Image;
224
+ function loadImage(src) {
225
+ return new Promise(function (resolve, reject) {
226
+ var img = new Image;
227
+ img.onload = function () {
228
+ resolve(img);
229
+ };
230
+ img.onabort = reject;
231
+ img.onerror = reject;
232
+ img.src = src;
233
+ });
234
+ }
235
+ function loadSVG(svg) {
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: return [4, parseSVGToDataURL(svg)];
241
+ case 1:
242
+ dataURL = _a.sent();
243
+ return [4, loadImage(dataURL)];
244
+ case 2:
245
+ image = _a.sent();
246
+ return [2, image];
247
+ }
248
+ });
249
+ });
250
+ }
251
+ function filterAmpersand(str) {
252
+ return str.replace(/\&/ig, '&amp;');
253
+ }
254
+ function loadHTML(html, opts) {
255
+ return __awaiter(this, void 0, void 0, function () {
256
+ var dataURL, image;
257
+ return __generator(this, function (_a) {
258
+ switch (_a.label) {
259
+ case 0:
260
+ html = filterAmpersand(html);
261
+ return [4, parseHTMLToDataURL(html, opts)];
262
+ case 1:
263
+ dataURL = _a.sent();
264
+ return [4, loadImage(dataURL)];
265
+ case 2:
266
+ image = _a.sent();
267
+ return [2, image];
268
+ }
269
+ });
270
+ });
271
+ }
272
+
273
+ var Context = (function () {
274
+ function Context(ctx, opts) {
275
+ this._opts = opts;
276
+ this._ctx = ctx;
277
+ this._transform = {
278
+ scale: 1,
279
+ scrollX: 0,
280
+ scrollY: 0,
281
+ };
227
282
  }
283
+ Context.prototype.getContext = function () {
284
+ return this._ctx;
285
+ };
286
+ Context.prototype.resetSize = function (opts) {
287
+ this._opts = __assign(__assign({}, this._opts), opts);
288
+ };
289
+ Context.prototype.calcDeviceNum = function (num) {
290
+ return num * this._opts.devicePixelRatio;
291
+ };
292
+ Context.prototype.calcScreenNum = function (num) {
293
+ return num / this._opts.devicePixelRatio;
294
+ };
295
+ Context.prototype.getSize = function () {
296
+ return {
297
+ width: this._opts.width,
298
+ height: this._opts.height,
299
+ contextWidth: this._opts.contextWidth,
300
+ contextHeight: this._opts.contextHeight,
301
+ devicePixelRatio: this._opts.devicePixelRatio,
302
+ };
303
+ };
304
+ Context.prototype.setTransform = function (config) {
305
+ this._transform = __assign(__assign({}, this._transform), config);
306
+ };
307
+ Context.prototype.getTransform = function () {
308
+ return {
309
+ scale: this._transform.scale,
310
+ scrollX: this._transform.scrollX,
311
+ scrollY: this._transform.scrollY,
312
+ };
313
+ };
314
+ Context.prototype.setFillStyle = function (color) {
315
+ this._ctx.fillStyle = color;
316
+ };
317
+ Context.prototype.fill = function (fillRule) {
318
+ return this._ctx.fill(fillRule || 'nonzero');
319
+ };
320
+ Context.prototype.arc = function (x, y, radius, startAngle, endAngle, anticlockwise) {
321
+ return this._ctx.arc(this._doSize(x), this._doSize(y), this._doSize(radius), startAngle, endAngle, anticlockwise);
322
+ };
323
+ Context.prototype.rect = function (x, y, w, h) {
324
+ return this._ctx.rect(this._doSize(x), this._doSize(y), this._doSize(w), this._doSize(h));
325
+ };
326
+ Context.prototype.fillRect = function (x, y, w, h) {
327
+ return this._ctx.fillRect(this._doSize(x), this._doSize(y), this._doSize(w), this._doSize(h));
328
+ };
329
+ Context.prototype.clearRect = function (x, y, w, h) {
330
+ return this._ctx.clearRect(this._doSize(x), this._doSize(y), this._doSize(w), this._doSize(h));
331
+ };
332
+ Context.prototype.beginPath = function () {
333
+ return this._ctx.beginPath();
334
+ };
335
+ Context.prototype.closePath = function () {
336
+ return this._ctx.closePath();
337
+ };
338
+ Context.prototype.lineTo = function (x, y) {
339
+ return this._ctx.lineTo(this._doSize(x), this._doSize(y));
340
+ };
341
+ Context.prototype.moveTo = function (x, y) {
342
+ return this._ctx.moveTo(this._doSize(x), this._doSize(y));
343
+ };
344
+ Context.prototype.arcTo = function (x1, y1, x2, y2, radius) {
345
+ return this._ctx.arcTo(this._doSize(x1), this._doSize(y1), this._doSize(x2), this._doSize(y2), this._doSize(radius));
346
+ };
347
+ Context.prototype.setLineWidth = function (w) {
348
+ return this._ctx.lineWidth = this._doSize(w);
349
+ };
350
+ Context.prototype.setLineDash = function (nums) {
351
+ var _this = this;
352
+ return this._ctx.setLineDash(nums.map(function (n) { return _this._doSize(n); }));
353
+ };
354
+ Context.prototype.isPointInPath = function (x, y) {
355
+ return this._ctx.isPointInPath(this._doX(x), this._doY(y));
356
+ };
357
+ Context.prototype.isPointInPathWithoutScroll = function (x, y) {
358
+ return this._ctx.isPointInPath(this._doSize(x), this._doSize(y));
359
+ };
360
+ Context.prototype.setStrokeStyle = function (color) {
361
+ this._ctx.strokeStyle = color;
362
+ };
363
+ Context.prototype.stroke = function () {
364
+ return this._ctx.stroke();
365
+ };
366
+ Context.prototype.translate = function (x, y) {
367
+ return this._ctx.translate(this._doSize(x), this._doSize(y));
368
+ };
369
+ Context.prototype.rotate = function (angle) {
370
+ return this._ctx.rotate(angle);
371
+ };
372
+ Context.prototype.drawImage = function () {
373
+ var args = [];
374
+ for (var _i = 0; _i < arguments.length; _i++) {
375
+ args[_i] = arguments[_i];
376
+ }
377
+ var image = args[0];
378
+ var sx = args[1];
379
+ var sy = args[2];
380
+ var sw = args[3];
381
+ var sh = args[4];
382
+ var dx = args[args.length - 4];
383
+ var dy = args[args.length - 3];
384
+ var dw = args[args.length - 2];
385
+ var dh = args[args.length - 1];
386
+ if (args.length === 9) {
387
+ 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));
388
+ }
389
+ else {
390
+ return this._ctx.drawImage(image, this._doSize(dx), this._doSize(dy), this._doSize(dw), this._doSize(dh));
391
+ }
392
+ };
393
+ Context.prototype.createPattern = function (image, repetition) {
394
+ return this._ctx.createPattern(image, repetition);
395
+ };
396
+ Context.prototype.measureText = function (text) {
397
+ return this._ctx.measureText(text);
398
+ };
399
+ Context.prototype.setTextAlign = function (align) {
400
+ this._ctx.textAlign = align;
401
+ };
402
+ Context.prototype.fillText = function (text, x, y, maxWidth) {
403
+ if (maxWidth !== undefined) {
404
+ return this._ctx.fillText(text, this._doSize(x), this._doSize(y), this._doSize(maxWidth));
405
+ }
406
+ else {
407
+ return this._ctx.fillText(text, this._doSize(x), this._doSize(y));
408
+ }
409
+ };
410
+ Context.prototype.strokeText = function (text, x, y, maxWidth) {
411
+ if (maxWidth !== undefined) {
412
+ return this._ctx.strokeText(text, this._doSize(x), this._doSize(y), this._doSize(maxWidth));
413
+ }
414
+ else {
415
+ return this._ctx.strokeText(text, this._doSize(x), this._doSize(y));
416
+ }
417
+ };
418
+ Context.prototype.setFont = function (opts) {
419
+ var strList = [];
420
+ if (opts.fontWeight === 'bold') {
421
+ strList.push("".concat(opts.fontWeight));
422
+ }
423
+ strList.push("".concat(this._doSize(opts.fontSize || 12), "px"));
424
+ strList.push("".concat(opts.fontFamily || 'sans-serif'));
425
+ this._ctx.font = "".concat(strList.join(' '));
426
+ };
427
+ Context.prototype.setTextBaseline = function (baseline) {
428
+ this._ctx.textBaseline = baseline;
429
+ };
430
+ Context.prototype.setGlobalAlpha = function (alpha) {
431
+ this._ctx.globalAlpha = alpha;
432
+ };
433
+ Context.prototype.save = function () {
434
+ this._ctx.save();
435
+ };
436
+ Context.prototype.restore = function () {
437
+ this._ctx.restore();
438
+ };
439
+ Context.prototype.scale = function (ratioX, ratioY) {
440
+ this._ctx.scale(ratioX, ratioY);
441
+ };
442
+ Context.prototype.setShadowColor = function (color) {
443
+ this._ctx.shadowColor = color;
444
+ };
445
+ Context.prototype.setShadowOffsetX = function (offsetX) {
446
+ this._ctx.shadowOffsetX = this._doSize(offsetX);
447
+ };
448
+ Context.prototype.setShadowOffsetY = function (offsetY) {
449
+ this._ctx.shadowOffsetY = this._doSize(offsetY);
450
+ };
451
+ Context.prototype.setShadowBlur = function (blur) {
452
+ this._ctx.shadowBlur = this._doSize(blur);
453
+ };
454
+ Context.prototype.ellipse = function (x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise) {
455
+ this._ctx.ellipse(this._doSize(x), this._doSize(y), this._doSize(radiusX), this._doSize(radiusY), rotation, startAngle, endAngle, counterclockwise);
456
+ };
457
+ Context.prototype._doSize = function (num) {
458
+ return this._opts.devicePixelRatio * num;
459
+ };
460
+ Context.prototype._doX = function (x) {
461
+ var _a = this._transform, scale = _a.scale, scrollX = _a.scrollX;
462
+ var _x = (x - scrollX) / scale;
463
+ return this._doSize(_x);
464
+ };
465
+ Context.prototype._doY = function (y) {
466
+ var _a = this._transform, scale = _a.scale, scrollY = _a.scrollY;
467
+ var _y = (y - scrollY) / scale;
468
+ return this._doSize(_y);
469
+ };
470
+ return Context;
471
+ }());
472
+
473
+ function number(value) {
474
+ return (typeof value === 'number' && (value > 0 || value <= 0));
475
+ }
476
+ function x(value) {
477
+ return number(value);
478
+ }
479
+ function y(value) {
480
+ return number(value);
481
+ }
482
+ function w(value) {
483
+ return (typeof value === 'number' && value >= 0);
484
+ }
485
+ function h(value) {
486
+ return (typeof value === 'number' && value >= 0);
487
+ }
488
+ function angle(value) {
489
+ return (typeof value === 'number' && value >= -360 && value <= 360);
490
+ }
491
+ function borderWidth(value) {
492
+ return w(value);
493
+ }
494
+ function borderRadius(value) {
495
+ return number(value) && value >= 0;
496
+ }
497
+ function color(value) {
498
+ return isColorStr(value);
499
+ }
500
+ function imageURL(value) {
501
+ return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("".concat(value)));
502
+ }
503
+ function imageBase64(value) {
504
+ return (typeof value === 'string' && /^(data:image\/)/.test("".concat(value)));
505
+ }
506
+ function imageSrc(value) {
507
+ return (imageBase64(value) || imageURL(value));
508
+ }
509
+ function svg(value) {
510
+ return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test("".concat(value).trim()) && /<\/[\s]{0,}svg>$/i.test("".concat(value).trim()));
511
+ }
512
+ function html(value) {
513
+ var result = false;
514
+ if (typeof value === 'string') {
515
+ var div = document.createElement('div');
516
+ div.innerHTML = value;
517
+ if (div.children.length > 0) {
518
+ result = true;
519
+ }
520
+ div = null;
521
+ }
522
+ return result;
523
+ }
524
+ function text(value) {
525
+ return typeof value === 'string';
526
+ }
527
+ function fontSize(value) {
528
+ return number(value) && value > 0;
529
+ }
530
+ function lineHeight(value) {
531
+ return number(value) && value > 0;
532
+ }
533
+ function strokeWidth(value) {
534
+ return number(value) && value > 0;
535
+ }
536
+ function textAlign(value) {
537
+ return ['center', 'left', 'right'].includes(value);
538
+ }
539
+ function fontFamily(value) {
540
+ return typeof value === 'string' && value.length > 0;
541
+ }
542
+ function fontWeight(value) {
543
+ return ['bold'].includes(value);
544
+ }
545
+ var is = {
546
+ x: x,
547
+ y: y,
548
+ w: w,
549
+ h: h,
550
+ angle: angle,
551
+ number: number,
552
+ borderWidth: borderWidth,
553
+ borderRadius: borderRadius,
554
+ color: color,
555
+ imageSrc: imageSrc,
556
+ imageURL: imageURL,
557
+ imageBase64: imageBase64,
558
+ svg: svg,
559
+ html: html,
560
+ text: text,
561
+ fontSize: fontSize,
562
+ lineHeight: lineHeight,
563
+ textAlign: textAlign,
564
+ fontFamily: fontFamily,
565
+ fontWeight: fontWeight,
566
+ strokeWidth: strokeWidth,
567
+ };
568
+
569
+ function attrs(attrs) {
570
+ var x = attrs.x, y = attrs.y, w = attrs.w, h = attrs.h, angle = attrs.angle;
571
+ if (!(is.x(x) && is.y(y) && is.w(w) && is.h(h) && is.angle(angle))) {
572
+ return false;
573
+ }
574
+ if (!(angle >= -360 && angle <= 360)) {
575
+ return false;
576
+ }
577
+ return true;
578
+ }
579
+ function box(desc) {
580
+ if (desc === void 0) { desc = {}; }
581
+ var borderColor = desc.borderColor, borderRadius = desc.borderRadius, borderWidth = desc.borderWidth;
582
+ if (desc.hasOwnProperty('borderColor') && !is.color(borderColor)) {
583
+ return false;
584
+ }
585
+ if (desc.hasOwnProperty('borderRadius') && !is.number(borderRadius)) {
586
+ return false;
587
+ }
588
+ if (desc.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
589
+ return false;
590
+ }
591
+ return true;
592
+ }
593
+ function rectDesc(desc) {
594
+ var bgColor = desc.bgColor;
595
+ if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
596
+ return false;
597
+ }
598
+ if (!box(desc)) {
599
+ return false;
600
+ }
601
+ return true;
602
+ }
603
+ function circleDesc(desc) {
604
+ var bgColor = desc.bgColor, borderColor = desc.borderColor, borderWidth = desc.borderWidth;
605
+ if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
606
+ return false;
607
+ }
608
+ if (desc.hasOwnProperty('borderColor') && !is.color(borderColor)) {
609
+ return false;
610
+ }
611
+ if (desc.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
612
+ return false;
613
+ }
614
+ return true;
615
+ }
616
+ function imageDesc(desc) {
617
+ var src = desc.src;
618
+ if (!is.imageSrc(src)) {
619
+ return false;
620
+ }
621
+ return true;
622
+ }
623
+ function svgDesc(desc) {
624
+ var svg = desc.svg;
625
+ if (!is.svg(svg)) {
626
+ return false;
627
+ }
628
+ return true;
629
+ }
630
+ function htmlDesc(desc) {
631
+ var html = desc.html;
632
+ if (!is.html(html)) {
633
+ return false;
634
+ }
635
+ return true;
636
+ }
637
+ function textDesc(desc) {
638
+ var text = desc.text, color = desc.color, fontSize = desc.fontSize, lineHeight = desc.lineHeight, fontFamily = desc.fontFamily, textAlign = desc.textAlign, fontWeight = desc.fontWeight, bgColor = desc.bgColor, strokeWidth = desc.strokeWidth, strokeColor = desc.strokeColor;
639
+ if (!is.text(text)) {
640
+ return false;
641
+ }
642
+ if (!is.color(color)) {
643
+ return false;
644
+ }
645
+ if (!is.fontSize(fontSize)) {
646
+ return false;
647
+ }
648
+ if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
649
+ return false;
650
+ }
651
+ if (desc.hasOwnProperty('fontWeight') && !is.fontWeight(fontWeight)) {
652
+ return false;
653
+ }
654
+ if (desc.hasOwnProperty('lineHeight') && !is.lineHeight(lineHeight)) {
655
+ return false;
656
+ }
657
+ if (desc.hasOwnProperty('fontFamily') && !is.fontFamily(fontFamily)) {
658
+ return false;
659
+ }
660
+ if (desc.hasOwnProperty('textAlign') && !is.textAlign(textAlign)) {
661
+ return false;
662
+ }
663
+ if (desc.hasOwnProperty('strokeWidth') && !is.strokeWidth(strokeWidth)) {
664
+ return false;
665
+ }
666
+ if (desc.hasOwnProperty('strokeColor') && !is.color(strokeColor)) {
667
+ return false;
668
+ }
669
+ if (!box(desc)) {
670
+ return false;
671
+ }
672
+ return true;
673
+ }
674
+ var check = {
675
+ attrs: attrs,
676
+ textDesc: textDesc,
677
+ rectDesc: rectDesc,
678
+ circleDesc: circleDesc,
679
+ imageDesc: imageDesc,
680
+ svgDesc: svgDesc,
681
+ htmlDesc: htmlDesc,
228
682
  };
229
683
 
230
- return index;
684
+ var default_1 = /*#__PURE__*/Object.freeze({
685
+ __proto__: null,
686
+ is: is,
687
+ check: check,
688
+ delay: delay,
689
+ compose: compose,
690
+ throttle: throttle,
691
+ loadImage: loadImage,
692
+ loadSVG: loadSVG,
693
+ loadHTML: loadHTML,
694
+ downloadImageFromCanvas: downloadImageFromCanvas,
695
+ toColorHexStr: toColorHexStr,
696
+ toColorHexNum: toColorHexNum,
697
+ isColorStr: isColorStr,
698
+ createUUID: createUUID,
699
+ istype: istype,
700
+ deepClone: deepClone,
701
+ Context: Context
702
+ });
703
+
704
+ return default_1;
231
705
 
232
- }());
706
+ })();
@@ -0,0 +1 @@
1
+ var iDrawUtil=function(){'use strict';function t(t){return'string'==typeof t&&/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)}function e(t){return(Object.prototype.toString.call(t)||'').replace(/(\[object|\])/gi,'').trim()}var n={type:function(t,n){var o=e(t);return!0===n?o.toLocaleLowerCase():o},array:function(t){return'Array'===e(t)},json:function(t){return'Object'===e(t)},function:function(t){return'Function'===e(t)},asyncFunction:function(t){return'AsyncFunction'===e(t)},string:function(t){return'String'===e(t)},number:function(t){return'Number'===e(t)},undefined:function(t){return'Undefined'===e(t)},null:function(t){return'Null'===e(t)},promise:function(t){return'Promise'===e(t)}},o=function(){return o=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},o.apply(this,arguments)};function r(t,e,n,o){return new(n||(n=Promise))((function(r,i){function c(t){try{u(o.next(t))}catch(t){i(t)}}function s(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(c,s)}u((o=o.apply(t,e||[])).next())}))}function i(t,e){var n,o,r,i,c={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;c;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,o=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(r=c.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){c.label=i[1];break}if(6===i[0]&&c.label<r[1]){c.label=r[1],r=i;break}if(r&&c.label<r[2]){c.label=r[2],c.ops.push(i);break}r[2]&&c.ops.pop(),c.trys.pop();continue}i=e.call(t,c)}catch(t){i=[6,t],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function c(t,e){var n=e.width,o=e.height;return new Promise((function(e,r){var i="\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"".concat(n||'',"\" height = \"").concat(o||'',"\">\n <foreignObject width=\"100%\" height=\"100%\">\n <div xmlns = \"http://www.w3.org/1999/xhtml\">\n ").concat(t,"\n </div>\n </foreignObject>\n </svg>\n "),c=new Blob([i],{type:'image/svg+xml;charset=utf-8'}),s=new FileReader;s.readAsDataURL(c),s.onload=function(t){var n,o=null===(n=null==t?void 0:t.target)||void 0===n?void 0:n.result;e(o)},s.onerror=function(t){r(t)}}))}function s(t){return new Promise((function(e,n){var o=new Blob([t],{type:'image/svg+xml;charset=utf-8'}),r=new FileReader;r.readAsDataURL(o),r.onload=function(t){var n,o=null===(n=null==t?void 0:t.target)||void 0===n?void 0:n.result;e(o)},r.onerror=function(t){n(t)}}))}var u=window.Image;function a(t){return new Promise((function(e,n){var o=new u;o.onload=function(){e(o)},o.onabort=n,o.onerror=n,o.src=t}))}var h=function(){function t(t,e){this._opts=e,this._ctx=t,this._transform={scale:1,scrollX:0,scrollY:0}}return t.prototype.getContext=function(){return this._ctx},t.prototype.resetSize=function(t){this._opts=o(o({},this._opts),t)},t.prototype.calcDeviceNum=function(t){return t*this._opts.devicePixelRatio},t.prototype.calcScreenNum=function(t){return t/this._opts.devicePixelRatio},t.prototype.getSize=function(){return{width:this._opts.width,height:this._opts.height,contextWidth:this._opts.contextWidth,contextHeight:this._opts.contextHeight,devicePixelRatio:this._opts.devicePixelRatio}},t.prototype.setTransform=function(t){this._transform=o(o({},this._transform),t)},t.prototype.getTransform=function(){return{scale:this._transform.scale,scrollX:this._transform.scrollX,scrollY:this._transform.scrollY}},t.prototype.setFillStyle=function(t){this._ctx.fillStyle=t},t.prototype.fill=function(t){return this._ctx.fill(t||'nonzero')},t.prototype.arc=function(t,e,n,o,r,i){return this._ctx.arc(this._doSize(t),this._doSize(e),this._doSize(n),o,r,i)},t.prototype.rect=function(t,e,n,o){return this._ctx.rect(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o))},t.prototype.fillRect=function(t,e,n,o){return this._ctx.fillRect(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o))},t.prototype.clearRect=function(t,e,n,o){return this._ctx.clearRect(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o))},t.prototype.beginPath=function(){return this._ctx.beginPath()},t.prototype.closePath=function(){return this._ctx.closePath()},t.prototype.lineTo=function(t,e){return this._ctx.lineTo(this._doSize(t),this._doSize(e))},t.prototype.moveTo=function(t,e){return this._ctx.moveTo(this._doSize(t),this._doSize(e))},t.prototype.arcTo=function(t,e,n,o,r){return this._ctx.arcTo(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o),this._doSize(r))},t.prototype.setLineWidth=function(t){return this._ctx.lineWidth=this._doSize(t)},t.prototype.setLineDash=function(t){var e=this;return this._ctx.setLineDash(t.map((function(t){return e._doSize(t)})))},t.prototype.isPointInPath=function(t,e){return this._ctx.isPointInPath(this._doX(t),this._doY(e))},t.prototype.isPointInPathWithoutScroll=function(t,e){return this._ctx.isPointInPath(this._doSize(t),this._doSize(e))},t.prototype.setStrokeStyle=function(t){this._ctx.strokeStyle=t},t.prototype.stroke=function(){return this._ctx.stroke()},t.prototype.translate=function(t,e){return this._ctx.translate(this._doSize(t),this._doSize(e))},t.prototype.rotate=function(t){return this._ctx.rotate(t)},t.prototype.drawImage=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=t[0],o=t[1],r=t[2],i=t[3],c=t[4],s=t[t.length-4],u=t[t.length-3],a=t[t.length-2],h=t[t.length-1];return 9===t.length?this._ctx.drawImage(n,this._doSize(o),this._doSize(r),this._doSize(i),this._doSize(c),this._doSize(s),this._doSize(u),this._doSize(a),this._doSize(h)):this._ctx.drawImage(n,this._doSize(s),this._doSize(u),this._doSize(a),this._doSize(h))},t.prototype.createPattern=function(t,e){return this._ctx.createPattern(t,e)},t.prototype.measureText=function(t){return this._ctx.measureText(t)},t.prototype.setTextAlign=function(t){this._ctx.textAlign=t},t.prototype.fillText=function(t,e,n,o){return void 0!==o?this._ctx.fillText(t,this._doSize(e),this._doSize(n),this._doSize(o)):this._ctx.fillText(t,this._doSize(e),this._doSize(n))},t.prototype.strokeText=function(t,e,n,o){return void 0!==o?this._ctx.strokeText(t,this._doSize(e),this._doSize(n),this._doSize(o)):this._ctx.strokeText(t,this._doSize(e),this._doSize(n))},t.prototype.setFont=function(t){var e=[];'bold'===t.fontWeight&&e.push("".concat(t.fontWeight)),e.push("".concat(this._doSize(t.fontSize||12),"px")),e.push("".concat(t.fontFamily||'sans-serif')),this._ctx.font="".concat(e.join(' '))},t.prototype.setTextBaseline=function(t){this._ctx.textBaseline=t},t.prototype.setGlobalAlpha=function(t){this._ctx.globalAlpha=t},t.prototype.save=function(){this._ctx.save()},t.prototype.restore=function(){this._ctx.restore()},t.prototype.scale=function(t,e){this._ctx.scale(t,e)},t.prototype.setShadowColor=function(t){this._ctx.shadowColor=t},t.prototype.setShadowOffsetX=function(t){this._ctx.shadowOffsetX=this._doSize(t)},t.prototype.setShadowOffsetY=function(t){this._ctx.shadowOffsetY=this._doSize(t)},t.prototype.setShadowBlur=function(t){this._ctx.shadowBlur=this._doSize(t)},t.prototype.ellipse=function(t,e,n,o,r,i,c,s){this._ctx.ellipse(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o),r,i,c,s)},t.prototype._doSize=function(t){return this._opts.devicePixelRatio*t},t.prototype._doX=function(t){var e=this._transform,n=e.scale,o=(t-e.scrollX)/n;return this._doSize(o)},t.prototype._doY=function(t){var e=this._transform,n=e.scale,o=(t-e.scrollY)/n;return this._doSize(o)},t}();function l(t){return'number'==typeof t&&(t>0||t<=0)}function f(t){return'number'==typeof t&&t>=0}function p(t){return'string'==typeof t&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test("".concat(t))}function d(t){return'string'==typeof t&&/^(data:image\/)/.test("".concat(t))}var _={x:function(t){return l(t)},y:function(t){return l(t)},w:f,h:function(t){return'number'==typeof t&&t>=0},angle:function(t){return'number'==typeof t&&t>=-360&&t<=360},number:l,borderWidth:function(t){return f(t)},borderRadius:function(t){return l(t)&&t>=0},color:function(e){return t(e)},imageSrc:function(t){return d(t)||p(t)},imageURL:p,imageBase64:d,svg:function(t){return'string'==typeof t&&/^(<svg[\s]{1,}|<svg>)/i.test("".concat(t).trim())&&/<\/[\s]{0,}svg>$/i.test("".concat(t).trim())},html:function(t){var e=!1;if('string'==typeof t){var n=document.createElement('div');n.innerHTML=t,n.children.length>0&&(e=!0),n=null}return e},text:function(t){return'string'==typeof t},fontSize:function(t){return l(t)&&t>0},lineHeight:function(t){return l(t)&&t>0},textAlign:function(t){return['center','left','right'].includes(t)},fontFamily:function(t){return'string'==typeof t&&t.length>0},fontWeight:function(t){return['bold'].includes(t)},strokeWidth:function(t){return l(t)&&t>0}};function y(t){void 0===t&&(t={});var e=t.borderColor,n=t.borderRadius,o=t.borderWidth;return!(t.hasOwnProperty('borderColor')&&!_.color(e))&&(!(t.hasOwnProperty('borderRadius')&&!_.number(n))&&!(t.hasOwnProperty('borderWidth')&&!_.number(o)))}var g={attrs:function(t){var e=t.x,n=t.y,o=t.w,r=t.h,i=t.angle;return!!(_.x(e)&&_.y(n)&&_.w(o)&&_.h(r)&&_.angle(i))&&(i>=-360&&i<=360)},textDesc:function(t){var e=t.text,n=t.color,o=t.fontSize,r=t.lineHeight,i=t.fontFamily,c=t.textAlign,s=t.fontWeight,u=t.bgColor,a=t.strokeWidth,h=t.strokeColor;return!!_.text(e)&&(!!_.color(n)&&(!!_.fontSize(o)&&(!(t.hasOwnProperty('bgColor')&&!_.color(u))&&(!(t.hasOwnProperty('fontWeight')&&!_.fontWeight(s))&&(!(t.hasOwnProperty('lineHeight')&&!_.lineHeight(r))&&(!(t.hasOwnProperty('fontFamily')&&!_.fontFamily(i))&&(!(t.hasOwnProperty('textAlign')&&!_.textAlign(c))&&(!(t.hasOwnProperty('strokeWidth')&&!_.strokeWidth(a))&&(!(t.hasOwnProperty('strokeColor')&&!_.color(h))&&!!y(t))))))))))},rectDesc:function(t){var e=t.bgColor;return!(t.hasOwnProperty('bgColor')&&!_.color(e))&&!!y(t)},circleDesc:function(t){var e=t.bgColor,n=t.borderColor,o=t.borderWidth;return!(t.hasOwnProperty('bgColor')&&!_.color(e))&&(!(t.hasOwnProperty('borderColor')&&!_.color(n))&&!(t.hasOwnProperty('borderWidth')&&!_.number(o)))},imageDesc:function(t){var e=t.src;return!!_.imageSrc(e)},svgDesc:function(t){var e=t.svg;return!!_.svg(e)},htmlDesc:function(t){var e=t.html;return!!_.html(e)}},v=Object.freeze({__proto__:null,is:_,check:g,delay:function(t){return new Promise((function(e){setTimeout((function(){e()}),t)}))},compose:function(t){return function(e,n){return function o(r){var i=t[r];r===t.length&&n&&(i=n);if(!i)return Promise.resolve();try{return Promise.resolve(i(e,o.bind(null,r+1)))}catch(t){return Promise.reject(t)}}(0)}},throttle:function(t,e){var n=-1;return function(){for(var o=[],r=0;r<arguments.length;r++)o[r]=arguments[r];n>0||(n=setTimeout((function(){t.apply(void 0,o),n=-1}),e))}},loadImage:a,loadSVG:function(t){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,s(t)];case 1:return[4,a(e.sent())];case 2:return[2,e.sent()]}}))}))},loadHTML:function(t,e){return r(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return[4,c(t=t.replace(/\&/gi,'&amp;'),e)];case 1:return[4,a(n.sent())];case 2:return[2,n.sent()]}}))}))},downloadImageFromCanvas:function(t,e){var n=e.filename,o=e.type,r=void 0===o?'image/jpeg':o,i=t.toDataURL(r),c=document.createElement('a');c.href=i,c.download=n;var s=document.createEvent('MouseEvents');s.initEvent('click',!0,!1),c.dispatchEvent(s)},toColorHexStr:function(t){return'#'+t.toString(16)},toColorHexNum:function(t){return parseInt(t.replace(/^\#/,'0x'))},isColorStr:t,createUUID:function(){function t(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return"".concat(t()).concat(t(),"-").concat(t(),"-").concat(t(),"-").concat(t(),"-").concat(t()).concat(t()).concat(t())},istype:n,deepClone:function(t){return function t(e){var n,o=(n=e,Object.prototype.toString.call(n).replace(/[\]|\[]{1,1}/gi,'').split(' ')[1]);if(['Null','Number','String','Boolean','Undefined'].indexOf(o)>=0)return e;if('Array'===o){var r=[];return e.forEach((function(e){r.push(t(e))})),r}if('Object'===o){var i={};return Object.keys(e).forEach((function(n){i[n]=t(e[n])})),i}}(t)},Context:h});return v}();