@idraw/util 0.2.0-alpha.16 → 0.2.0-alpha.22
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 +427 -3
- package/dist/index.d.ts +117 -0
- package/dist/index.es.js +427 -3
- package/dist/index.global.js +427 -3
- package/dist/index.global.min.js +1 -288
- package/package.json +7 -3
package/dist/index.cjs.js
CHANGED
|
@@ -73,7 +73,7 @@ function createUUID() {
|
|
|
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) {
|
|
@@ -254,7 +264,420 @@ function loadHTML(html, opts) {
|
|
|
254
264
|
});
|
|
255
265
|
}
|
|
256
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("" + opts.fontWeight);
|
|
416
|
+
}
|
|
417
|
+
strList.push(this._doSize(opts.fontSize || 12) + "px");
|
|
418
|
+
strList.push("" + (opts.fontFamily || 'sans-serif'));
|
|
419
|
+
this._ctx.font = "" + 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("" + value));
|
|
496
|
+
}
|
|
497
|
+
function imageBase64(value) {
|
|
498
|
+
return (typeof value === 'string' && /^(data:image\/)/.test("" + 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(("" + value).trim()) && /<\/[\s]{0,}svg>$/i.test(("" + 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;
|
|
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,
|
|
676
|
+
};
|
|
677
|
+
|
|
257
678
|
var index = {
|
|
679
|
+
is: is,
|
|
680
|
+
check: check,
|
|
258
681
|
time: {
|
|
259
682
|
delay: delay,
|
|
260
683
|
compose: compose,
|
|
@@ -279,7 +702,8 @@ var index = {
|
|
|
279
702
|
istype: istype,
|
|
280
703
|
data: {
|
|
281
704
|
deepClone: deepClone,
|
|
282
|
-
}
|
|
705
|
+
},
|
|
706
|
+
Context: Context,
|
|
283
707
|
};
|
|
284
708
|
|
|
285
709
|
module.exports = index;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,112 @@
|
|
|
1
|
+
import { TypeBoardSizeOptions } from '@idraw/types';
|
|
2
|
+
import { TypeContext } from '@idraw/types';
|
|
3
|
+
|
|
1
4
|
declare function compose(middleware: Middleware[]): (context: any, next?: Middleware) => any;
|
|
2
5
|
|
|
6
|
+
declare class Context implements TypeContext {
|
|
7
|
+
private _opts;
|
|
8
|
+
private _ctx;
|
|
9
|
+
private _transform;
|
|
10
|
+
constructor(ctx: CanvasRenderingContext2D, opts: Options);
|
|
11
|
+
getContext(): CanvasRenderingContext2D;
|
|
12
|
+
resetSize(opts: TypeBoardSizeOptions): void;
|
|
13
|
+
calcDeviceNum(num: number): number;
|
|
14
|
+
calcScreenNum(num: number): number;
|
|
15
|
+
getSize(): {
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
contextWidth: number;
|
|
19
|
+
contextHeight: number;
|
|
20
|
+
devicePixelRatio: number;
|
|
21
|
+
};
|
|
22
|
+
setTransform(config: Transform): void;
|
|
23
|
+
getTransform(): {
|
|
24
|
+
scale: number;
|
|
25
|
+
scrollX: number;
|
|
26
|
+
scrollY: number;
|
|
27
|
+
};
|
|
28
|
+
setFillStyle(color: string | CanvasPattern | CanvasGradient): void;
|
|
29
|
+
fill(fillRule?: CanvasFillRule | undefined): void;
|
|
30
|
+
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean | undefined): void;
|
|
31
|
+
rect(x: number, y: number, w: number, h: number): void;
|
|
32
|
+
fillRect(x: number, y: number, w: number, h: number): void;
|
|
33
|
+
clearRect(x: number, y: number, w: number, h: number): void;
|
|
34
|
+
beginPath(): void;
|
|
35
|
+
closePath(): void;
|
|
36
|
+
lineTo(x: number, y: number): void;
|
|
37
|
+
moveTo(x: number, y: number): void;
|
|
38
|
+
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
|
|
39
|
+
setLineWidth(w: number): number;
|
|
40
|
+
setLineDash(nums: number[]): void;
|
|
41
|
+
isPointInPath(x: number, y: number): boolean;
|
|
42
|
+
isPointInPathWithoutScroll(x: number, y: number): boolean;
|
|
43
|
+
setStrokeStyle(color: string): void;
|
|
44
|
+
stroke(): void;
|
|
45
|
+
translate(x: number, y: number): void;
|
|
46
|
+
rotate(angle: number): void;
|
|
47
|
+
drawImage(...args: any[]): void;
|
|
48
|
+
createPattern(image: CanvasImageSource, repetition: string | null): CanvasPattern | null;
|
|
49
|
+
measureText(text: string): TextMetrics;
|
|
50
|
+
setTextAlign(align: CanvasTextAlign): void;
|
|
51
|
+
fillText(text: string, x: number, y: number, maxWidth?: number | undefined): void;
|
|
52
|
+
strokeText(text: string, x: number, y: number, maxWidth?: number | undefined): void;
|
|
53
|
+
setFont(opts: {
|
|
54
|
+
fontSize: number;
|
|
55
|
+
fontFamily?: string;
|
|
56
|
+
fontWeight?: 'bold';
|
|
57
|
+
}): void;
|
|
58
|
+
setTextBaseline(baseline: CanvasTextBaseline): void;
|
|
59
|
+
setGlobalAlpha(alpha: number): void;
|
|
60
|
+
save(): void;
|
|
61
|
+
restore(): void;
|
|
62
|
+
scale(ratioX: number, ratioY: number): void;
|
|
63
|
+
setShadowColor(color: string): void;
|
|
64
|
+
setShadowOffsetX(offsetX: number): void;
|
|
65
|
+
setShadowOffsetY(offsetY: number): void;
|
|
66
|
+
setShadowBlur(blur: number): void;
|
|
67
|
+
ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean | undefined): void;
|
|
68
|
+
private _doSize;
|
|
69
|
+
private _doX;
|
|
70
|
+
private _doY;
|
|
71
|
+
}
|
|
72
|
+
|
|
3
73
|
declare function createUUID(): string;
|
|
4
74
|
|
|
5
75
|
declare function deepClone(target: any): any;
|
|
6
76
|
|
|
7
77
|
declare const _default: {
|
|
78
|
+
is: {
|
|
79
|
+
x: (value: any) => boolean;
|
|
80
|
+
y: (value: any) => boolean;
|
|
81
|
+
w: (value: any) => boolean;
|
|
82
|
+
h: (value: any) => boolean;
|
|
83
|
+
angle: (value: any) => boolean;
|
|
84
|
+
number: (value: any) => boolean;
|
|
85
|
+
borderWidth: (value: any) => boolean;
|
|
86
|
+
borderRadius: (value: any) => boolean;
|
|
87
|
+
color: (value: any) => boolean;
|
|
88
|
+
imageSrc: (value: any) => boolean;
|
|
89
|
+
imageURL: (value: any) => boolean;
|
|
90
|
+
imageBase64: (value: any) => boolean;
|
|
91
|
+
svg: (value: any) => boolean;
|
|
92
|
+
html: (value: any) => boolean;
|
|
93
|
+
text: (value: any) => boolean;
|
|
94
|
+
fontSize: (value: any) => boolean;
|
|
95
|
+
lineHeight: (value: any) => boolean;
|
|
96
|
+
textAlign: (value: any) => boolean;
|
|
97
|
+
fontFamily: (value: any) => boolean;
|
|
98
|
+
fontWeight: (value: any) => boolean;
|
|
99
|
+
strokeWidth: (value: any) => boolean;
|
|
100
|
+
};
|
|
101
|
+
check: {
|
|
102
|
+
attrs: (attrs: any) => boolean;
|
|
103
|
+
textDesc: (desc: any) => boolean;
|
|
104
|
+
rectDesc: (desc: any) => boolean;
|
|
105
|
+
circleDesc: (desc: any) => boolean;
|
|
106
|
+
imageDesc: (desc: any) => boolean;
|
|
107
|
+
svgDesc: (desc: any) => boolean;
|
|
108
|
+
htmlDesc: (desc: any) => boolean;
|
|
109
|
+
};
|
|
8
110
|
time: {
|
|
9
111
|
delay: typeof delay;
|
|
10
112
|
compose: typeof compose;
|
|
@@ -41,6 +143,7 @@ declare const _default: {
|
|
|
41
143
|
data: {
|
|
42
144
|
deepClone: typeof deepClone;
|
|
43
145
|
};
|
|
146
|
+
Context: typeof Context;
|
|
44
147
|
};
|
|
45
148
|
export default _default;
|
|
46
149
|
|
|
@@ -66,10 +169,24 @@ declare function loadSVG(svg: string): Promise<HTMLImageElement>;
|
|
|
66
169
|
|
|
67
170
|
declare type Middleware = (ctx: any, next: Middleware) => any;
|
|
68
171
|
|
|
172
|
+
declare type Options = {
|
|
173
|
+
width: number;
|
|
174
|
+
height: number;
|
|
175
|
+
contextWidth: number;
|
|
176
|
+
contextHeight: number;
|
|
177
|
+
devicePixelRatio: number;
|
|
178
|
+
};
|
|
179
|
+
|
|
69
180
|
declare function throttle(fn: (...args: any[]) => any, timeout: number): (...args: any[]) => any;
|
|
70
181
|
|
|
71
182
|
declare function toColorHexNum(color: string): number;
|
|
72
183
|
|
|
73
184
|
declare function toColorHexStr(color: number): string;
|
|
74
185
|
|
|
186
|
+
declare type Transform = {
|
|
187
|
+
scale?: number;
|
|
188
|
+
scrollX?: number;
|
|
189
|
+
scrollY?: number;
|
|
190
|
+
};
|
|
191
|
+
|
|
75
192
|
export { }
|