@idraw/util 0.3.0-alpha.6 → 0.3.0-alpha.8

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