@idraw/util 0.2.0-alpha.22 → 0.2.0-alpha.26
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 +9 -9
- package/dist/index.es.js +9 -9
- package/dist/index.global.js +9 -9
- package/dist/index.global.min.js +1 -1
- package/package.json +3 -3
package/dist/index.cjs.js
CHANGED
|
@@ -68,7 +68,7 @@ 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) {
|
|
@@ -188,7 +188,7 @@ function __generator(thisArg, body) {
|
|
|
188
188
|
function parseHTMLToDataURL(html, opts) {
|
|
189
189
|
var width = opts.width, height = opts.height;
|
|
190
190
|
return new Promise(function (resolve, reject) {
|
|
191
|
-
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 ");
|
|
192
192
|
var blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
|
|
193
193
|
var reader = new FileReader();
|
|
194
194
|
reader.readAsDataURL(blob);
|
|
@@ -412,11 +412,11 @@ var Context = (function () {
|
|
|
412
412
|
Context.prototype.setFont = function (opts) {
|
|
413
413
|
var strList = [];
|
|
414
414
|
if (opts.fontWeight === 'bold') {
|
|
415
|
-
strList.push(""
|
|
415
|
+
strList.push("".concat(opts.fontWeight));
|
|
416
416
|
}
|
|
417
|
-
strList.push(this._doSize(opts.fontSize || 12)
|
|
418
|
-
strList.push(""
|
|
419
|
-
this._ctx.font = ""
|
|
417
|
+
strList.push("".concat(this._doSize(opts.fontSize || 12), "px"));
|
|
418
|
+
strList.push("".concat(opts.fontFamily || 'sans-serif'));
|
|
419
|
+
this._ctx.font = "".concat(strList.join(' '));
|
|
420
420
|
};
|
|
421
421
|
Context.prototype.setTextBaseline = function (baseline) {
|
|
422
422
|
this._ctx.textBaseline = baseline;
|
|
@@ -492,16 +492,16 @@ function color(value) {
|
|
|
492
492
|
return isColorStr(value);
|
|
493
493
|
}
|
|
494
494
|
function imageURL(value) {
|
|
495
|
-
return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test(""
|
|
495
|
+
return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("".concat(value)));
|
|
496
496
|
}
|
|
497
497
|
function imageBase64(value) {
|
|
498
|
-
return (typeof value === 'string' && /^(data:image\/)/.test(""
|
|
498
|
+
return (typeof value === 'string' && /^(data:image\/)/.test("".concat(value)));
|
|
499
499
|
}
|
|
500
500
|
function imageSrc(value) {
|
|
501
501
|
return (imageBase64(value) || imageURL(value));
|
|
502
502
|
}
|
|
503
503
|
function svg(value) {
|
|
504
|
-
return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test(
|
|
504
|
+
return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test("".concat(value).trim()) && /<\/[\s]{0,}svg>$/i.test("".concat(value).trim()));
|
|
505
505
|
}
|
|
506
506
|
function html(value) {
|
|
507
507
|
var result = false;
|
package/dist/index.es.js
CHANGED
|
@@ -66,7 +66,7 @@ function createUUID() {
|
|
|
66
66
|
function str4() {
|
|
67
67
|
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
68
68
|
}
|
|
69
|
-
return ""
|
|
69
|
+
return "".concat(str4()).concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4()).concat(str4()).concat(str4());
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
function deepClone(target) {
|
|
@@ -186,7 +186,7 @@ function __generator(thisArg, body) {
|
|
|
186
186
|
function parseHTMLToDataURL(html, opts) {
|
|
187
187
|
var width = opts.width, height = opts.height;
|
|
188
188
|
return new Promise(function (resolve, reject) {
|
|
189
|
-
var _svg = "\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\""
|
|
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
190
|
var blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
|
|
191
191
|
var reader = new FileReader();
|
|
192
192
|
reader.readAsDataURL(blob);
|
|
@@ -410,11 +410,11 @@ var Context = (function () {
|
|
|
410
410
|
Context.prototype.setFont = function (opts) {
|
|
411
411
|
var strList = [];
|
|
412
412
|
if (opts.fontWeight === 'bold') {
|
|
413
|
-
strList.push(""
|
|
413
|
+
strList.push("".concat(opts.fontWeight));
|
|
414
414
|
}
|
|
415
|
-
strList.push(this._doSize(opts.fontSize || 12)
|
|
416
|
-
strList.push(""
|
|
417
|
-
this._ctx.font = ""
|
|
415
|
+
strList.push("".concat(this._doSize(opts.fontSize || 12), "px"));
|
|
416
|
+
strList.push("".concat(opts.fontFamily || 'sans-serif'));
|
|
417
|
+
this._ctx.font = "".concat(strList.join(' '));
|
|
418
418
|
};
|
|
419
419
|
Context.prototype.setTextBaseline = function (baseline) {
|
|
420
420
|
this._ctx.textBaseline = baseline;
|
|
@@ -490,16 +490,16 @@ function color(value) {
|
|
|
490
490
|
return isColorStr(value);
|
|
491
491
|
}
|
|
492
492
|
function imageURL(value) {
|
|
493
|
-
return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test(""
|
|
493
|
+
return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("".concat(value)));
|
|
494
494
|
}
|
|
495
495
|
function imageBase64(value) {
|
|
496
|
-
return (typeof value === 'string' && /^(data:image\/)/.test(""
|
|
496
|
+
return (typeof value === 'string' && /^(data:image\/)/.test("".concat(value)));
|
|
497
497
|
}
|
|
498
498
|
function imageSrc(value) {
|
|
499
499
|
return (imageBase64(value) || imageURL(value));
|
|
500
500
|
}
|
|
501
501
|
function svg(value) {
|
|
502
|
-
return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test(
|
|
502
|
+
return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test("".concat(value).trim()) && /<\/[\s]{0,}svg>$/i.test("".concat(value).trim()));
|
|
503
503
|
}
|
|
504
504
|
function html(value) {
|
|
505
505
|
var result = false;
|
package/dist/index.global.js
CHANGED
|
@@ -69,7 +69,7 @@ var iDrawUtil = (function () {
|
|
|
69
69
|
function str4() {
|
|
70
70
|
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
71
71
|
}
|
|
72
|
-
return ""
|
|
72
|
+
return "".concat(str4()).concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4()).concat(str4()).concat(str4());
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function deepClone(target) {
|
|
@@ -189,7 +189,7 @@ var iDrawUtil = (function () {
|
|
|
189
189
|
function parseHTMLToDataURL(html, opts) {
|
|
190
190
|
var width = opts.width, height = opts.height;
|
|
191
191
|
return new Promise(function (resolve, reject) {
|
|
192
|
-
var _svg = "\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\""
|
|
192
|
+
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 ");
|
|
193
193
|
var blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
|
|
194
194
|
var reader = new FileReader();
|
|
195
195
|
reader.readAsDataURL(blob);
|
|
@@ -413,11 +413,11 @@ var iDrawUtil = (function () {
|
|
|
413
413
|
Context.prototype.setFont = function (opts) {
|
|
414
414
|
var strList = [];
|
|
415
415
|
if (opts.fontWeight === 'bold') {
|
|
416
|
-
strList.push(""
|
|
416
|
+
strList.push("".concat(opts.fontWeight));
|
|
417
417
|
}
|
|
418
|
-
strList.push(this._doSize(opts.fontSize || 12)
|
|
419
|
-
strList.push(""
|
|
420
|
-
this._ctx.font = ""
|
|
418
|
+
strList.push("".concat(this._doSize(opts.fontSize || 12), "px"));
|
|
419
|
+
strList.push("".concat(opts.fontFamily || 'sans-serif'));
|
|
420
|
+
this._ctx.font = "".concat(strList.join(' '));
|
|
421
421
|
};
|
|
422
422
|
Context.prototype.setTextBaseline = function (baseline) {
|
|
423
423
|
this._ctx.textBaseline = baseline;
|
|
@@ -493,16 +493,16 @@ var iDrawUtil = (function () {
|
|
|
493
493
|
return isColorStr(value);
|
|
494
494
|
}
|
|
495
495
|
function imageURL(value) {
|
|
496
|
-
return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test(""
|
|
496
|
+
return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("".concat(value)));
|
|
497
497
|
}
|
|
498
498
|
function imageBase64(value) {
|
|
499
|
-
return (typeof value === 'string' && /^(data:image\/)/.test(""
|
|
499
|
+
return (typeof value === 'string' && /^(data:image\/)/.test("".concat(value)));
|
|
500
500
|
}
|
|
501
501
|
function imageSrc(value) {
|
|
502
502
|
return (imageBase64(value) || imageURL(value));
|
|
503
503
|
}
|
|
504
504
|
function svg(value) {
|
|
505
|
-
return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test(
|
|
505
|
+
return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test("".concat(value).trim()) && /<\/[\s]{0,}svg>$/i.test("".concat(value).trim()));
|
|
506
506
|
}
|
|
507
507
|
function html(value) {
|
|
508
508
|
var result = false;
|
package/dist/index.global.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var iDrawUtil=function(){'use strict';function t(t){return'string'==typeof t&&/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)}function e(t){return(Object.prototype.toString.call(t)||'').replace(/(\[object|\])/gi,'').trim()}var n={type:function(t,n){var o=e(t);return!0===n?o.toLocaleLowerCase():o},array:function(t){return'Array'===e(t)},json:function(t){return'Object'===e(t)},function:function(t){return'Function'===e(t)},asyncFunction:function(t){return'AsyncFunction'===e(t)},string:function(t){return'String'===e(t)},number:function(t){return'Number'===e(t)},undefined:function(t){return'Undefined'===e(t)},null:function(t){return'Null'===e(t)},promise:function(t){return'Promise'===e(t)}},o=function(){return o=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},o.apply(this,arguments)};function r(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function c(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,c)}u((o=o.apply(t,e||[])).next())}))}function i(t,e){var n,o,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,o=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){s.label=i[1];break}if(6===i[0]&&s.label<r[1]){s.label=r[1],r=i;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(i);break}r[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function s(t,e){var n=e.width,o=e.height;return new Promise((function(e,r){var i=new Blob(["\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\""+(n||'')+"\" height = \""+(o||'')+"\">\n <foreignObject width=\"100%\" height=\"100%\">\n <div xmlns = \"http://www.w3.org/1999/xhtml\">\n "+t+"\n </div>\n </foreignObject>\n </svg>\n "],{type:'image/svg+xml;charset=utf-8'}),s=new FileReader;s.readAsDataURL(i),s.onload=function(t){var n,o=null===(n=null==t?void 0:t.target)||void 0===n?void 0:n.result;e(o)},s.onerror=function(t){r(t)}}))}function c(t){return new Promise((function(e,n){var o=new Blob([t],{type:'image/svg+xml;charset=utf-8'}),r=new FileReader;r.readAsDataURL(o),r.onload=function(t){var n,o=null===(n=null==t?void 0:t.target)||void 0===n?void 0:n.result;e(o)},r.onerror=function(t){n(t)}}))}var u=window.Image;function a(t){return new Promise((function(e,n){var o=new u;o.onload=function(){e(o)},o.onabort=n,o.onerror=n,o.src=t}))}var h=function(){function t(t,e){this._opts=e,this._ctx=t,this._transform={scale:1,scrollX:0,scrollY:0}}return t.prototype.getContext=function(){return this._ctx},t.prototype.resetSize=function(t){this._opts=o(o({},this._opts),t)},t.prototype.calcDeviceNum=function(t){return t*this._opts.devicePixelRatio},t.prototype.calcScreenNum=function(t){return t/this._opts.devicePixelRatio},t.prototype.getSize=function(){return{width:this._opts.width,height:this._opts.height,contextWidth:this._opts.contextWidth,contextHeight:this._opts.contextHeight,devicePixelRatio:this._opts.devicePixelRatio}},t.prototype.setTransform=function(t){this._transform=o(o({},this._transform),t)},t.prototype.getTransform=function(){return{scale:this._transform.scale,scrollX:this._transform.scrollX,scrollY:this._transform.scrollY}},t.prototype.setFillStyle=function(t){this._ctx.fillStyle=t},t.prototype.fill=function(t){return this._ctx.fill(t||'nonzero')},t.prototype.arc=function(t,e,n,o,r,i){return this._ctx.arc(this._doSize(t),this._doSize(e),this._doSize(n),o,r,i)},t.prototype.rect=function(t,e,n,o){return this._ctx.rect(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o))},t.prototype.fillRect=function(t,e,n,o){return this._ctx.fillRect(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o))},t.prototype.clearRect=function(t,e,n,o){return this._ctx.clearRect(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o))},t.prototype.beginPath=function(){return this._ctx.beginPath()},t.prototype.closePath=function(){return this._ctx.closePath()},t.prototype.lineTo=function(t,e){return this._ctx.lineTo(this._doSize(t),this._doSize(e))},t.prototype.moveTo=function(t,e){return this._ctx.moveTo(this._doSize(t),this._doSize(e))},t.prototype.arcTo=function(t,e,n,o,r){return this._ctx.arcTo(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o),this._doSize(r))},t.prototype.setLineWidth=function(t){return this._ctx.lineWidth=this._doSize(t)},t.prototype.setLineDash=function(t){var e=this;return this._ctx.setLineDash(t.map((function(t){return e._doSize(t)})))},t.prototype.isPointInPath=function(t,e){return this._ctx.isPointInPath(this._doX(t),this._doY(e))},t.prototype.isPointInPathWithoutScroll=function(t,e){return this._ctx.isPointInPath(this._doSize(t),this._doSize(e))},t.prototype.setStrokeStyle=function(t){this._ctx.strokeStyle=t},t.prototype.stroke=function(){return this._ctx.stroke()},t.prototype.translate=function(t,e){return this._ctx.translate(this._doSize(t),this._doSize(e))},t.prototype.rotate=function(t){return this._ctx.rotate(t)},t.prototype.drawImage=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=t[0],o=t[1],r=t[2],i=t[3],s=t[4],c=t[t.length-4],u=t[t.length-3],a=t[t.length-2],h=t[t.length-1];return 9===t.length?this._ctx.drawImage(n,this._doSize(o),this._doSize(r),this._doSize(i),this._doSize(s),this._doSize(c),this._doSize(u),this._doSize(a),this._doSize(h)):this._ctx.drawImage(n,this._doSize(c),this._doSize(u),this._doSize(a),this._doSize(h))},t.prototype.createPattern=function(t,e){return this._ctx.createPattern(t,e)},t.prototype.measureText=function(t){return this._ctx.measureText(t)},t.prototype.setTextAlign=function(t){this._ctx.textAlign=t},t.prototype.fillText=function(t,e,n,o){return void 0!==o?this._ctx.fillText(t,this._doSize(e),this._doSize(n),this._doSize(o)):this._ctx.fillText(t,this._doSize(e),this._doSize(n))},t.prototype.strokeText=function(t,e,n,o){return void 0!==o?this._ctx.strokeText(t,this._doSize(e),this._doSize(n),this._doSize(o)):this._ctx.strokeText(t,this._doSize(e),this._doSize(n))},t.prototype.setFont=function(t){var e=[];'bold'===t.fontWeight&&e.push(""+t.fontWeight),e.push(this._doSize(t.fontSize||12)+"px"),e.push(""+(t.fontFamily||'sans-serif')),this._ctx.font=""+e.join(' ')},t.prototype.setTextBaseline=function(t){this._ctx.textBaseline=t},t.prototype.setGlobalAlpha=function(t){this._ctx.globalAlpha=t},t.prototype.save=function(){this._ctx.save()},t.prototype.restore=function(){this._ctx.restore()},t.prototype.scale=function(t,e){this._ctx.scale(t,e)},t.prototype.setShadowColor=function(t){this._ctx.shadowColor=t},t.prototype.setShadowOffsetX=function(t){this._ctx.shadowOffsetX=this._doSize(t)},t.prototype.setShadowOffsetY=function(t){this._ctx.shadowOffsetY=this._doSize(t)},t.prototype.setShadowBlur=function(t){this._ctx.shadowBlur=this._doSize(t)},t.prototype.ellipse=function(t,e,n,o,r,i,s,c){this._ctx.ellipse(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o),r,i,s,c)},t.prototype._doSize=function(t){return this._opts.devicePixelRatio*t},t.prototype._doX=function(t){var e=this._transform,n=e.scale,o=(t-e.scrollX)/n;return this._doSize(o)},t.prototype._doY=function(t){var e=this._transform,n=e.scale,o=(t-e.scrollY)/n;return this._doSize(o)},t}();function l(t){return'number'==typeof t&&(t>0||t<=0)}function f(t){return'number'==typeof t&&t>=0}function p(t){return'string'==typeof t&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(""+t)}function d(t){return'string'==typeof t&&/^(data:image\/)/.test(""+t)}var _={x:function(t){return l(t)},y:function(t){return l(t)},w:f,h:function(t){return'number'==typeof t&&t>=0},angle:function(t){return'number'==typeof t&&t>=-360&&t<=360},number:l,borderWidth:function(t){return f(t)},borderRadius:function(t){return l(t)&&t>=0},color:function(e){return t(e)},imageSrc:function(t){return d(t)||p(t)},imageURL:p,imageBase64:d,svg:function(t){return'string'==typeof t&&/^(<svg[\s]{1,}|<svg>)/i.test((""+t).trim())&&/<\/[\s]{0,}svg>$/i.test((""+t).trim())},html:function(t){var e=!1;if('string'==typeof t){var n=document.createElement('div');n.innerHTML=t,n.children.length>0&&(e=!0),n=null}return e},text:function(t){return'string'==typeof t},fontSize:function(t){return l(t)&&t>0},lineHeight:function(t){return l(t)&&t>0},textAlign:function(t){return['center','left','right'].includes(t)},fontFamily:function(t){return'string'==typeof t&&t.length>0},fontWeight:function(t){return['bold'].includes(t)},strokeWidth:function(t){return l(t)&&t>0}};function y(t){void 0===t&&(t={});var e=t.borderColor,n=t.borderRadius,o=t.borderWidth;return!(t.hasOwnProperty('borderColor')&&!_.color(e))&&(!(t.hasOwnProperty('borderRadius')&&!_.number(n))&&!(t.hasOwnProperty('borderWidth')&&!_.number(o)))}var g={attrs:function(t){var e=t.x,n=t.y,o=t.w,r=t.h,i=t.angle;return!!(_.x(e)&&_.y(n)&&_.w(o)&&_.h(r)&&_.angle(i))&&(i>=-360&&i<=360)},textDesc:function(t){var e=t.text,n=t.color,o=t.fontSize,r=t.lineHeight,i=t.fontFamily,s=t.textAlign,c=t.fontWeight,u=t.bgColor,a=t.strokeWidth,h=t.strokeColor;return!!_.text(e)&&(!!_.color(n)&&(!!_.fontSize(o)&&(!(t.hasOwnProperty('bgColor')&&!_.color(u))&&(!(t.hasOwnProperty('fontWeight')&&!_.fontWeight(c))&&(!(t.hasOwnProperty('lineHeight')&&!_.lineHeight(r))&&(!(t.hasOwnProperty('fontFamily')&&!_.fontFamily(i))&&(!(t.hasOwnProperty('textAlign')&&!_.textAlign(s))&&(!(t.hasOwnProperty('strokeWidth')&&!_.strokeWidth(a))&&(!(t.hasOwnProperty('strokeColor')&&!_.color(h))&&!!y(t))))))))))},rectDesc:function(t){var e=t.bgColor;return!(t.hasOwnProperty('bgColor')&&!_.color(e))&&!!y(t)},circleDesc:function(t){var e=t.bgColor,n=t.borderColor,o=t.borderWidth;return!(t.hasOwnProperty('bgColor')&&!_.color(e))&&(!(t.hasOwnProperty('borderColor')&&!_.color(n))&&!(t.hasOwnProperty('borderWidth')&&!_.number(o)))},imageDesc:function(t){var e=t.src;return!!_.imageSrc(e)},svgDesc:function(t){var e=t.svg;return!!_.svg(e)},htmlDesc:function(t){var e=t.html;return!!_.html(e)}},v={is:_,check:g,time:{delay:function(t){return new Promise((function(e){setTimeout((function(){e()}),t)}))},compose:function(t){return function(e,n){return function o(r){var i=t[r];r===t.length&&n&&(i=n);if(!i)return Promise.resolve();try{return Promise.resolve(i(e,o.bind(null,r+1)))}catch(t){return Promise.reject(t)}}(0)}},throttle:function(t,e){var n=-1;return function(){for(var o=[],r=0;r<arguments.length;r++)o[r]=arguments[r];n>0||(n=setTimeout((function(){t.apply(void 0,o),n=-1}),e))}}},loader:{loadImage:a,loadSVG:function(t){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,c(t)];case 1:return[4,a(e.sent())];case 2:return[2,e.sent()]}}))}))},loadHTML:function(t,e){return r(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return[4,s(t,e)];case 1:return[4,a(n.sent())];case 2:return[2,n.sent()]}}))}))}},file:{downloadImageFromCanvas:function(t,e){var n=e.filename,o=e.type,r=void 0===o?'image/jpeg':o,i=t.toDataURL(r),s=document.createElement('a');s.href=i,s.download=n;var c=document.createEvent('MouseEvents');c.initEvent('click',!0,!1),s.dispatchEvent(c)}},color:{toColorHexStr:function(t){return'#'+t.toString(16)},toColorHexNum:function(t){return parseInt(t.replace(/^\#/,'0x'))},isColorStr:t},uuid:{createUUID:function(){function t(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return""+t()+t()+"-"+t()+"-"+t()+"-"+t()+"-"+t()+t()+t()}},istype:n,data:{deepClone:function(t){return function t(e){var n,o=(n=e,Object.prototype.toString.call(n).replace(/[\]|\[]{1,1}/gi,'').split(' ')[1]);if(['Null','Number','String','Boolean','Undefined'].indexOf(o)>=0)return e;if('Array'===o){var r=[];return e.forEach((function(e){r.push(t(e))})),r}if('Object'===o){var i={};return Object.keys(e).forEach((function(n){i[n]=t(e[n])})),i}}(t)}},Context:h};return v}();
|
|
1
|
+
var iDrawUtil=function(){'use strict';function t(t){return'string'==typeof t&&/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)}function e(t){return(Object.prototype.toString.call(t)||'').replace(/(\[object|\])/gi,'').trim()}var n={type:function(t,n){var o=e(t);return!0===n?o.toLocaleLowerCase():o},array:function(t){return'Array'===e(t)},json:function(t){return'Object'===e(t)},function:function(t){return'Function'===e(t)},asyncFunction:function(t){return'AsyncFunction'===e(t)},string:function(t){return'String'===e(t)},number:function(t){return'Number'===e(t)},undefined:function(t){return'Undefined'===e(t)},null:function(t){return'Null'===e(t)},promise:function(t){return'Promise'===e(t)}},o=function(){return o=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},o.apply(this,arguments)};function r(t,e,n,o){return new(n||(n=Promise))((function(r,i){function c(t){try{u(o.next(t))}catch(t){i(t)}}function s(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(c,s)}u((o=o.apply(t,e||[])).next())}))}function i(t,e){var n,o,r,i,c={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;c;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,o=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(r=c.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){c.label=i[1];break}if(6===i[0]&&c.label<r[1]){c.label=r[1],r=i;break}if(r&&c.label<r[2]){c.label=r[2],c.ops.push(i);break}r[2]&&c.ops.pop(),c.trys.pop();continue}i=e.call(t,c)}catch(t){i=[6,t],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function c(t,e){var n=e.width,o=e.height;return new Promise((function(e,r){var i="\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"".concat(n||'',"\" height = \"").concat(o||'',"\">\n <foreignObject width=\"100%\" height=\"100%\">\n <div xmlns = \"http://www.w3.org/1999/xhtml\">\n ").concat(t,"\n </div>\n </foreignObject>\n </svg>\n "),c=new Blob([i],{type:'image/svg+xml;charset=utf-8'}),s=new FileReader;s.readAsDataURL(c),s.onload=function(t){var n,o=null===(n=null==t?void 0:t.target)||void 0===n?void 0:n.result;e(o)},s.onerror=function(t){r(t)}}))}function s(t){return new Promise((function(e,n){var o=new Blob([t],{type:'image/svg+xml;charset=utf-8'}),r=new FileReader;r.readAsDataURL(o),r.onload=function(t){var n,o=null===(n=null==t?void 0:t.target)||void 0===n?void 0:n.result;e(o)},r.onerror=function(t){n(t)}}))}var u=window.Image;function a(t){return new Promise((function(e,n){var o=new u;o.onload=function(){e(o)},o.onabort=n,o.onerror=n,o.src=t}))}var h=function(){function t(t,e){this._opts=e,this._ctx=t,this._transform={scale:1,scrollX:0,scrollY:0}}return t.prototype.getContext=function(){return this._ctx},t.prototype.resetSize=function(t){this._opts=o(o({},this._opts),t)},t.prototype.calcDeviceNum=function(t){return t*this._opts.devicePixelRatio},t.prototype.calcScreenNum=function(t){return t/this._opts.devicePixelRatio},t.prototype.getSize=function(){return{width:this._opts.width,height:this._opts.height,contextWidth:this._opts.contextWidth,contextHeight:this._opts.contextHeight,devicePixelRatio:this._opts.devicePixelRatio}},t.prototype.setTransform=function(t){this._transform=o(o({},this._transform),t)},t.prototype.getTransform=function(){return{scale:this._transform.scale,scrollX:this._transform.scrollX,scrollY:this._transform.scrollY}},t.prototype.setFillStyle=function(t){this._ctx.fillStyle=t},t.prototype.fill=function(t){return this._ctx.fill(t||'nonzero')},t.prototype.arc=function(t,e,n,o,r,i){return this._ctx.arc(this._doSize(t),this._doSize(e),this._doSize(n),o,r,i)},t.prototype.rect=function(t,e,n,o){return this._ctx.rect(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o))},t.prototype.fillRect=function(t,e,n,o){return this._ctx.fillRect(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o))},t.prototype.clearRect=function(t,e,n,o){return this._ctx.clearRect(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o))},t.prototype.beginPath=function(){return this._ctx.beginPath()},t.prototype.closePath=function(){return this._ctx.closePath()},t.prototype.lineTo=function(t,e){return this._ctx.lineTo(this._doSize(t),this._doSize(e))},t.prototype.moveTo=function(t,e){return this._ctx.moveTo(this._doSize(t),this._doSize(e))},t.prototype.arcTo=function(t,e,n,o,r){return this._ctx.arcTo(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o),this._doSize(r))},t.prototype.setLineWidth=function(t){return this._ctx.lineWidth=this._doSize(t)},t.prototype.setLineDash=function(t){var e=this;return this._ctx.setLineDash(t.map((function(t){return e._doSize(t)})))},t.prototype.isPointInPath=function(t,e){return this._ctx.isPointInPath(this._doX(t),this._doY(e))},t.prototype.isPointInPathWithoutScroll=function(t,e){return this._ctx.isPointInPath(this._doSize(t),this._doSize(e))},t.prototype.setStrokeStyle=function(t){this._ctx.strokeStyle=t},t.prototype.stroke=function(){return this._ctx.stroke()},t.prototype.translate=function(t,e){return this._ctx.translate(this._doSize(t),this._doSize(e))},t.prototype.rotate=function(t){return this._ctx.rotate(t)},t.prototype.drawImage=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=t[0],o=t[1],r=t[2],i=t[3],c=t[4],s=t[t.length-4],u=t[t.length-3],a=t[t.length-2],h=t[t.length-1];return 9===t.length?this._ctx.drawImage(n,this._doSize(o),this._doSize(r),this._doSize(i),this._doSize(c),this._doSize(s),this._doSize(u),this._doSize(a),this._doSize(h)):this._ctx.drawImage(n,this._doSize(s),this._doSize(u),this._doSize(a),this._doSize(h))},t.prototype.createPattern=function(t,e){return this._ctx.createPattern(t,e)},t.prototype.measureText=function(t){return this._ctx.measureText(t)},t.prototype.setTextAlign=function(t){this._ctx.textAlign=t},t.prototype.fillText=function(t,e,n,o){return void 0!==o?this._ctx.fillText(t,this._doSize(e),this._doSize(n),this._doSize(o)):this._ctx.fillText(t,this._doSize(e),this._doSize(n))},t.prototype.strokeText=function(t,e,n,o){return void 0!==o?this._ctx.strokeText(t,this._doSize(e),this._doSize(n),this._doSize(o)):this._ctx.strokeText(t,this._doSize(e),this._doSize(n))},t.prototype.setFont=function(t){var e=[];'bold'===t.fontWeight&&e.push("".concat(t.fontWeight)),e.push("".concat(this._doSize(t.fontSize||12),"px")),e.push("".concat(t.fontFamily||'sans-serif')),this._ctx.font="".concat(e.join(' '))},t.prototype.setTextBaseline=function(t){this._ctx.textBaseline=t},t.prototype.setGlobalAlpha=function(t){this._ctx.globalAlpha=t},t.prototype.save=function(){this._ctx.save()},t.prototype.restore=function(){this._ctx.restore()},t.prototype.scale=function(t,e){this._ctx.scale(t,e)},t.prototype.setShadowColor=function(t){this._ctx.shadowColor=t},t.prototype.setShadowOffsetX=function(t){this._ctx.shadowOffsetX=this._doSize(t)},t.prototype.setShadowOffsetY=function(t){this._ctx.shadowOffsetY=this._doSize(t)},t.prototype.setShadowBlur=function(t){this._ctx.shadowBlur=this._doSize(t)},t.prototype.ellipse=function(t,e,n,o,r,i,c,s){this._ctx.ellipse(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o),r,i,c,s)},t.prototype._doSize=function(t){return this._opts.devicePixelRatio*t},t.prototype._doX=function(t){var e=this._transform,n=e.scale,o=(t-e.scrollX)/n;return this._doSize(o)},t.prototype._doY=function(t){var e=this._transform,n=e.scale,o=(t-e.scrollY)/n;return this._doSize(o)},t}();function l(t){return'number'==typeof t&&(t>0||t<=0)}function f(t){return'number'==typeof t&&t>=0}function p(t){return'string'==typeof t&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test("".concat(t))}function d(t){return'string'==typeof t&&/^(data:image\/)/.test("".concat(t))}var _={x:function(t){return l(t)},y:function(t){return l(t)},w:f,h:function(t){return'number'==typeof t&&t>=0},angle:function(t){return'number'==typeof t&&t>=-360&&t<=360},number:l,borderWidth:function(t){return f(t)},borderRadius:function(t){return l(t)&&t>=0},color:function(e){return t(e)},imageSrc:function(t){return d(t)||p(t)},imageURL:p,imageBase64:d,svg:function(t){return'string'==typeof t&&/^(<svg[\s]{1,}|<svg>)/i.test("".concat(t).trim())&&/<\/[\s]{0,}svg>$/i.test("".concat(t).trim())},html:function(t){var e=!1;if('string'==typeof t){var n=document.createElement('div');n.innerHTML=t,n.children.length>0&&(e=!0),n=null}return e},text:function(t){return'string'==typeof t},fontSize:function(t){return l(t)&&t>0},lineHeight:function(t){return l(t)&&t>0},textAlign:function(t){return['center','left','right'].includes(t)},fontFamily:function(t){return'string'==typeof t&&t.length>0},fontWeight:function(t){return['bold'].includes(t)},strokeWidth:function(t){return l(t)&&t>0}};function y(t){void 0===t&&(t={});var e=t.borderColor,n=t.borderRadius,o=t.borderWidth;return!(t.hasOwnProperty('borderColor')&&!_.color(e))&&(!(t.hasOwnProperty('borderRadius')&&!_.number(n))&&!(t.hasOwnProperty('borderWidth')&&!_.number(o)))}var g={attrs:function(t){var e=t.x,n=t.y,o=t.w,r=t.h,i=t.angle;return!!(_.x(e)&&_.y(n)&&_.w(o)&&_.h(r)&&_.angle(i))&&(i>=-360&&i<=360)},textDesc:function(t){var e=t.text,n=t.color,o=t.fontSize,r=t.lineHeight,i=t.fontFamily,c=t.textAlign,s=t.fontWeight,u=t.bgColor,a=t.strokeWidth,h=t.strokeColor;return!!_.text(e)&&(!!_.color(n)&&(!!_.fontSize(o)&&(!(t.hasOwnProperty('bgColor')&&!_.color(u))&&(!(t.hasOwnProperty('fontWeight')&&!_.fontWeight(s))&&(!(t.hasOwnProperty('lineHeight')&&!_.lineHeight(r))&&(!(t.hasOwnProperty('fontFamily')&&!_.fontFamily(i))&&(!(t.hasOwnProperty('textAlign')&&!_.textAlign(c))&&(!(t.hasOwnProperty('strokeWidth')&&!_.strokeWidth(a))&&(!(t.hasOwnProperty('strokeColor')&&!_.color(h))&&!!y(t))))))))))},rectDesc:function(t){var e=t.bgColor;return!(t.hasOwnProperty('bgColor')&&!_.color(e))&&!!y(t)},circleDesc:function(t){var e=t.bgColor,n=t.borderColor,o=t.borderWidth;return!(t.hasOwnProperty('bgColor')&&!_.color(e))&&(!(t.hasOwnProperty('borderColor')&&!_.color(n))&&!(t.hasOwnProperty('borderWidth')&&!_.number(o)))},imageDesc:function(t){var e=t.src;return!!_.imageSrc(e)},svgDesc:function(t){var e=t.svg;return!!_.svg(e)},htmlDesc:function(t){var e=t.html;return!!_.html(e)}},v={is:_,check:g,time:{delay:function(t){return new Promise((function(e){setTimeout((function(){e()}),t)}))},compose:function(t){return function(e,n){return function o(r){var i=t[r];r===t.length&&n&&(i=n);if(!i)return Promise.resolve();try{return Promise.resolve(i(e,o.bind(null,r+1)))}catch(t){return Promise.reject(t)}}(0)}},throttle:function(t,e){var n=-1;return function(){for(var o=[],r=0;r<arguments.length;r++)o[r]=arguments[r];n>0||(n=setTimeout((function(){t.apply(void 0,o),n=-1}),e))}}},loader:{loadImage:a,loadSVG:function(t){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,s(t)];case 1:return[4,a(e.sent())];case 2:return[2,e.sent()]}}))}))},loadHTML:function(t,e){return r(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return[4,c(t,e)];case 1:return[4,a(n.sent())];case 2:return[2,n.sent()]}}))}))}},file:{downloadImageFromCanvas:function(t,e){var n=e.filename,o=e.type,r=void 0===o?'image/jpeg':o,i=t.toDataURL(r),c=document.createElement('a');c.href=i,c.download=n;var s=document.createEvent('MouseEvents');s.initEvent('click',!0,!1),c.dispatchEvent(s)}},color:{toColorHexStr:function(t){return'#'+t.toString(16)},toColorHexNum:function(t){return parseInt(t.replace(/^\#/,'0x'))},isColorStr:t},uuid:{createUUID:function(){function t(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return"".concat(t()).concat(t(),"-").concat(t(),"-").concat(t(),"-").concat(t(),"-").concat(t()).concat(t()).concat(t())}},istype:n,data:{deepClone:function(t){return function t(e){var n,o=(n=e,Object.prototype.toString.call(n).replace(/[\]|\[]{1,1}/gi,'').split(' ')[1]);if(['Null','Number','String','Boolean','Undefined'].indexOf(o)>=0)return e;if('Array'===o){var r=[];return e.forEach((function(e){r.push(t(e))})),r}if('Object'===o){var i={};return Object.keys(e).forEach((function(n){i[n]=t(e[n])})),i}}(t)}},Context:h};return v}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idraw/util",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.26",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.es.js",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"author": "chenshenhai",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@idraw/types": "^0.2.0-alpha.
|
|
27
|
+
"@idraw/types": "^0.2.0-alpha.26"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "464b223dbd3d5899a63bc6a0aff46e79d7ba3269"
|
|
33
33
|
}
|