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