@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.
- package/dist/index.cjs.js +536 -62
- package/dist/index.d.ts +196 -51
- package/dist/index.esm.js +701 -0
- package/dist/index.global.js +537 -63
- 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 -227
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
|
|
|
@@ -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
|
|
148
|
-
function
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
function
|
|
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
|
-
|
|
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
|
|
180
|
-
var width = opts.width, height = opts.height;
|
|
205
|
+
function parseSVGToDataURL(svg) {
|
|
181
206
|
return new Promise(function (resolve, reject) {
|
|
182
|
-
var _svg =
|
|
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
|
-
|
|
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,485 @@ function loadHTML(html, opts) {
|
|
|
198
219
|
});
|
|
199
220
|
}
|
|
200
221
|
|
|
201
|
-
var
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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 filterAmpersand(str) {
|
|
251
|
+
return str.replace(/\&/ig, '&');
|
|
252
|
+
}
|
|
253
|
+
function loadHTML(html, opts) {
|
|
254
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
255
|
+
var dataURL, image;
|
|
256
|
+
return __generator(this, function (_a) {
|
|
257
|
+
switch (_a.label) {
|
|
258
|
+
case 0:
|
|
259
|
+
html = filterAmpersand(html);
|
|
260
|
+
return [4, parseHTMLToDataURL(html, opts)];
|
|
261
|
+
case 1:
|
|
262
|
+
dataURL = _a.sent();
|
|
263
|
+
return [4, loadImage(dataURL)];
|
|
264
|
+
case 2:
|
|
265
|
+
image = _a.sent();
|
|
266
|
+
return [2, image];
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
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
|
+
};
|
|
226
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,
|
|
566
|
+
};
|
|
567
|
+
|
|
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,
|
|
227
681
|
};
|
|
228
682
|
|
|
229
|
-
|
|
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;
|