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

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