@idraw/util 0.2.0-alpha.9 → 0.3.0-0.3.0-beta.6.0
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/LICENSE +1 -1
- package/dist/esm/index.d.ts +71 -0
- package/dist/esm/index.js +29 -0
- package/dist/esm/lib/check.d.ts +17 -0
- package/dist/esm/lib/check.js +115 -0
- package/dist/esm/lib/color.d.ts +3 -0
- package/dist/esm/lib/color.js +9 -0
- package/dist/esm/lib/context.d.ts +80 -0
- package/dist/esm/lib/context.js +194 -0
- package/dist/esm/lib/data.d.ts +1 -0
- package/dist/esm/lib/data.js +27 -0
- package/dist/esm/lib/file.d.ts +6 -0
- package/dist/esm/lib/file.js +10 -0
- package/dist/esm/lib/is.d.ts +45 -0
- package/dist/esm/lib/is.js +81 -0
- package/dist/esm/lib/istype.d.ts +13 -0
- package/dist/esm/lib/istype.js +39 -0
- package/dist/esm/lib/loader.d.ts +6 -0
- package/dist/esm/lib/loader.js +41 -0
- package/dist/esm/lib/parser.d.ts +5 -0
- package/dist/esm/lib/parser.js +41 -0
- package/dist/esm/lib/time.d.ts +5 -0
- package/dist/esm/lib/time.js +38 -0
- package/dist/esm/lib/uuid.d.ts +1 -0
- package/dist/esm/lib/uuid.js +6 -0
- package/dist/index.global.js +710 -284
- package/dist/index.global.min.js +1 -0
- package/package.json +10 -9
- package/dist/index.cjs.js +0 -285
- package/dist/index.d.ts +0 -75
- package/dist/index.es.js +0 -283
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var iDrawUtil=function(t){"use strict";function e(t){return function(e,o){return function i(r){let n=t[r];r===t.length&&o&&(n=o);if(!n)return Promise.resolve();try{return Promise.resolve(n(e,i.bind(null,r+1)))}catch(t){return Promise.reject(t)}}(0)}}function o(t){return new Promise((e=>{setTimeout((()=>{e()}),t)}))}function i(t,e){let o=-1;return function(...i){o>0||(o=setTimeout((()=>{t(...i),o=-1}),e))}}function r(t,e){const{filename:o,type:i="image/jpeg"}=e,r=t.toDataURL(i),n=document.createElement("a");n.href=r,n.download=o;const s=document.createEvent("MouseEvents");s.initEvent("click",!0,!1),n.dispatchEvent(s)}function n(t){return parseInt(t.replace(/^\#/,"0x"))}function s(t){return"#"+t.toString(16)}function c(t){return"string"==typeof t&&/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)}function h(){function t(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return`${t()}${t()}-${t()}-${t()}-${t()}-${t()}${t()}${t()}`}function l(t){return function t(e){const o=(i=e,Object.prototype.toString.call(i).replace(/[\]|\[]{1,1}/gi,"").split(" ")[1]);var i;if(["Null","Number","String","Boolean","Undefined"].indexOf(o)>=0)return e;if("Array"===o){const o=[];return e.forEach((e=>{o.push(t(e))})),o}if("Object"===o){const o={};return Object.keys(e).forEach((i=>{o[i]=t(e[i])})),o}}(t)}function a(t){return(Object.prototype.toString.call(t)||"").replace(/(\[object|\])/gi,"").trim()}const u={type(t,e){const o=a(t);return!0===e?o.toLocaleLowerCase():o},array:t=>"Array"===a(t),json:t=>"Object"===a(t),function:t=>"Function"===a(t),asyncFunction:t=>"AsyncFunction"===a(t),string:t=>"String"===a(t),number:t=>"Number"===a(t),undefined:t=>"Undefined"===a(t),null:t=>"Null"===a(t),promise:t=>"Promise"===a(t)};const{Image:d}=window;function f(t){return new Promise(((e,o)=>{const i=new d;i.crossOrigin="anonymous",i.onload=function(){e(i)},i.onabort=o,i.onerror=o,i.src=t}))}async function _(t){const e=await function(t){return new Promise(((e,o)=>{const i=new Blob([t],{type:"image/svg+xml;charset=utf-8"}),r=new FileReader;r.readAsDataURL(i),r.onload=function(t){var o;const i=null==(o=null==t?void 0:t.target)?void 0:o.result;e(i)},r.onerror=function(t){o(t)}}))}(t);return await f(e)}async function g(t,e){t=t.replace(/\&/gi,"&");const o=await function(t,e){const{width:o,height:i}=e;return new Promise(((e,r)=>{const n=new Blob([`\n <svg xmlns="http://www.w3.org/2000/svg" width="${o||""}" height = "${i||""}">\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(n),s.onload=function(t){var o;const i=null==(o=null==t?void 0:t.target)?void 0:o.result;e(i)},s.onerror=function(t){r(t)}}))}(t,e);return await f(o)}class S{constructor(t,e){this._opts=e,this._ctx=t,this._transform={scale:1,scrollX:0,scrollY:0}}getContext(){return this._ctx}resetSize(t){this._opts={...this._opts,...t}}calcDeviceNum(t){return t*this._opts.devicePixelRatio}calcScreenNum(t){return t/this._opts.devicePixelRatio}getSize(){return{width:this._opts.width,height:this._opts.height,contextWidth:this._opts.contextWidth,contextHeight:this._opts.contextHeight,devicePixelRatio:this._opts.devicePixelRatio}}setTransform(t){this._transform={...this._transform,...t}}getTransform(){return{scale:this._transform.scale,scrollX:this._transform.scrollX,scrollY:this._transform.scrollY}}setFillStyle(t){this._ctx.fillStyle=t}fill(t){return this._ctx.fill(t||"nonzero")}arc(t,e,o,i,r,n){return this._ctx.arc(this._doSize(t),this._doSize(e),this._doSize(o),i,r,n)}rect(t,e,o,i){return this._ctx.rect(this._doSize(t),this._doSize(e),this._doSize(o),this._doSize(i))}fillRect(t,e,o,i){return this._ctx.fillRect(this._doSize(t),this._doSize(e),this._doSize(o),this._doSize(i))}clearRect(t,e,o,i){return this._ctx.clearRect(this._doSize(t),this._doSize(e),this._doSize(o),this._doSize(i))}beginPath(){return this._ctx.beginPath()}closePath(){return this._ctx.closePath()}lineTo(t,e){return this._ctx.lineTo(this._doSize(t),this._doSize(e))}moveTo(t,e){return this._ctx.moveTo(this._doSize(t),this._doSize(e))}arcTo(t,e,o,i,r){return this._ctx.arcTo(this._doSize(t),this._doSize(e),this._doSize(o),this._doSize(i),this._doSize(r))}setLineWidth(t){return this._ctx.lineWidth=this._doSize(t)}setLineDash(t){return this._ctx.setLineDash(t.map((t=>this._doSize(t))))}isPointInPath(t,e){return this._ctx.isPointInPath(this._doX(t),this._doY(e))}isPointInPathWithoutScroll(t,e){return this._ctx.isPointInPath(this._doSize(t),this._doSize(e))}setStrokeStyle(t){this._ctx.strokeStyle=t}stroke(){return this._ctx.stroke()}translate(t,e){return this._ctx.translate(this._doSize(t),this._doSize(e))}rotate(t){return this._ctx.rotate(t)}drawImage(...t){const e=t[0],o=t[1],i=t[2],r=t[3],n=t[4],s=t[t.length-4],c=t[t.length-3],h=t[t.length-2],l=t[t.length-1];return 9===t.length?this._ctx.drawImage(e,this._doSize(o),this._doSize(i),this._doSize(r),this._doSize(n),this._doSize(s),this._doSize(c),this._doSize(h),this._doSize(l)):this._ctx.drawImage(e,this._doSize(s),this._doSize(c),this._doSize(h),this._doSize(l))}createPattern(t,e){return this._ctx.createPattern(t,e)}measureText(t){return this._ctx.measureText(t)}setTextAlign(t){this._ctx.textAlign=t}fillText(t,e,o,i){return void 0!==i?this._ctx.fillText(t,this._doSize(e),this._doSize(o),this._doSize(i)):this._ctx.fillText(t,this._doSize(e),this._doSize(o))}strokeText(t,e,o,i){return void 0!==i?this._ctx.strokeText(t,this._doSize(e),this._doSize(o),this._doSize(i)):this._ctx.strokeText(t,this._doSize(e),this._doSize(o))}setFont(t){const 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(" ")}`}setTextBaseline(t){this._ctx.textBaseline=t}setGlobalAlpha(t){this._ctx.globalAlpha=t}save(){this._ctx.save()}restore(){this._ctx.restore()}scale(t,e){this._ctx.scale(t,e)}setShadowColor(t){this._ctx.shadowColor=t}setShadowOffsetX(t){this._ctx.shadowOffsetX=this._doSize(t)}setShadowOffsetY(t){this._ctx.shadowOffsetY=this._doSize(t)}setShadowBlur(t){this._ctx.shadowBlur=this._doSize(t)}ellipse(t,e,o,i,r,n,s,c){this._ctx.ellipse(this._doSize(t),this._doSize(e),this._doSize(o),this._doSize(i),r,n,s,c)}_doSize(t){return this._opts.devicePixelRatio*t}_doX(t){const{scale:e,scrollX:o}=this._transform,i=(t-o)/e;return this._doSize(i)}_doY(t){const{scale:e,scrollY:o}=this._transform,i=(t-o)/e;return this._doSize(i)}}function m(t){return"number"==typeof t&&(t>0||t<=0)}function x(t){return"number"==typeof t&&t>=0}function p(t){return"string"==typeof t&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${t}`)}function z(t){return"string"==typeof t&&/^(data:image\/)/.test(`${t}`)}const w={x:function(t){return m(t)},y:function(t){return m(t)},w:x,h:function(t){return"number"==typeof t&&t>=0},angle:function(t){return"number"==typeof t&&t>=-360&&t<=360},number:m,borderWidth:function(t){return x(t)},borderRadius:function(t){return m(t)&&t>=0},color:function(t){return c(t)},imageSrc:function(t){return z(t)||p(t)},imageURL:p,imageBase64:z,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){let e=!1;if("string"==typeof t){let o=document.createElement("div");o.innerHTML=t,o.children.length>0&&(e=!0),o=null}return e},text:function(t){return"string"==typeof t},fontSize:function(t){return m(t)&&t>0},lineHeight:function(t){return m(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 m(t)&&t>0}};function y(t={}){const{borderColor:e,borderRadius:o,borderWidth:i}=t;return!(t.hasOwnProperty("borderColor")&&!w.color(e))&&(!(t.hasOwnProperty("borderRadius")&&!w.number(o))&&!(t.hasOwnProperty("borderWidth")&&!w.number(i)))}const b={attrs:function(t){const{x:e,y:o,w:i,h:r,angle:n}=t;return!!(w.x(e)&&w.y(o)&&w.w(i)&&w.h(r)&&w.angle(n))&&(n>=-360&&n<=360)},textDesc:function(t){const{text:e,color:o,fontSize:i,lineHeight:r,fontFamily:n,textAlign:s,fontWeight:c,bgColor:h,strokeWidth:l,strokeColor:a}=t;return!!w.text(e)&&(!!w.color(o)&&(!!w.fontSize(i)&&(!(t.hasOwnProperty("bgColor")&&!w.color(h))&&(!(t.hasOwnProperty("fontWeight")&&!w.fontWeight(c))&&(!(t.hasOwnProperty("lineHeight")&&!w.lineHeight(r))&&(!(t.hasOwnProperty("fontFamily")&&!w.fontFamily(n))&&(!(t.hasOwnProperty("textAlign")&&!w.textAlign(s))&&(!(t.hasOwnProperty("strokeWidth")&&!w.strokeWidth(l))&&(!(t.hasOwnProperty("strokeColor")&&!w.color(a))&&!!y(t))))))))))},rectDesc:function(t){const{bgColor:e}=t;return!(t.hasOwnProperty("bgColor")&&!w.color(e))&&!!y(t)},circleDesc:function(t){const{bgColor:e,borderColor:o,borderWidth:i}=t;return!(t.hasOwnProperty("bgColor")&&!w.color(e))&&(!(t.hasOwnProperty("borderColor")&&!w.color(o))&&!(t.hasOwnProperty("borderWidth")&&!w.number(i)))},imageDesc:function(t){const{src:e}=t;return!!w.imageSrc(e)},svgDesc:function(t){const{svg:e}=t;return!!w.svg(e)},htmlDesc:function(t){const{html:e}=t;return!!w.html(e)}},v={is:w,check:b,delay:o,compose:e,throttle:i,loadImage:f,loadSVG:_,loadHTML:g,downloadImageFromCanvas:r,toColorHexStr:s,toColorHexNum:n,isColorStr:c,createUUID:h,istype:u,deepClone:l,Context:S};return t.Context=S,t.check=b,t.compose=e,t.createUUID=h,t.deepClone=l,t.default=v,t.delay=o,t.downloadImageFromCanvas=r,t.is=w,t.isColorStr=c,t.istype=u,t.loadHTML=g,t.loadImage=f,t.loadSVG=_,t.throttle=i,t.toColorHexNum=n,t.toColorHexStr=s,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),t}({});
|
package/package.json
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idraw/util",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-0.3.0-beta.6.0",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "dist/index.
|
|
6
|
-
"module": "dist/index.
|
|
5
|
+
"main": "dist/esm/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
7
|
"unpkg": "dist/index.global.js",
|
|
8
|
-
"types": "dist/index.d.ts",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
-
},
|
|
8
|
+
"types": "dist/esm/index.d.ts",
|
|
12
9
|
"files": [
|
|
13
|
-
"dist"
|
|
10
|
+
"dist/**/*.ts",
|
|
11
|
+
"dist/**/*.js"
|
|
14
12
|
],
|
|
15
13
|
"repository": {
|
|
16
14
|
"type": "git",
|
|
@@ -22,8 +20,11 @@
|
|
|
22
20
|
"homepage": "https://github.com/idrawjs/idraw#readme",
|
|
23
21
|
"author": "chenshenhai",
|
|
24
22
|
"license": "MIT",
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@idraw/types": "^0.3.0-0.3.0-beta.6.0"
|
|
25
|
+
},
|
|
25
26
|
"publishConfig": {
|
|
26
27
|
"access": "public"
|
|
27
28
|
},
|
|
28
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "3e332c451c8931aecfd7bd8c840a1986388d2257"
|
|
29
30
|
}
|
package/dist/index.cjs.js
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function compose(middleware) {
|
|
4
|
-
return function (context, next) {
|
|
5
|
-
return dispatch(0);
|
|
6
|
-
function dispatch(i) {
|
|
7
|
-
var fn = middleware[i];
|
|
8
|
-
if (i === middleware.length && next) {
|
|
9
|
-
fn = next;
|
|
10
|
-
}
|
|
11
|
-
if (!fn)
|
|
12
|
-
return Promise.resolve();
|
|
13
|
-
try {
|
|
14
|
-
return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
|
|
15
|
-
}
|
|
16
|
-
catch (err) {
|
|
17
|
-
return Promise.reject(err);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function delay(time) {
|
|
23
|
-
return new Promise(function (resolve) {
|
|
24
|
-
setTimeout(function () {
|
|
25
|
-
resolve();
|
|
26
|
-
}, time);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
function throttle(fn, timeout) {
|
|
30
|
-
var timer = -1;
|
|
31
|
-
return function () {
|
|
32
|
-
var args = [];
|
|
33
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
34
|
-
args[_i] = arguments[_i];
|
|
35
|
-
}
|
|
36
|
-
if (timer > 0) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
timer = setTimeout(function () {
|
|
40
|
-
fn.apply(void 0, args);
|
|
41
|
-
timer = -1;
|
|
42
|
-
}, timeout);
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function downloadImageFromCanvas(canvas, opts) {
|
|
47
|
-
var filename = opts.filename, _a = opts.type, type = _a === void 0 ? 'image/jpeg' : _a;
|
|
48
|
-
var stream = canvas.toDataURL(type);
|
|
49
|
-
var downloadLink = document.createElement('a');
|
|
50
|
-
downloadLink.href = stream;
|
|
51
|
-
downloadLink.download = filename;
|
|
52
|
-
var downloadClickEvent = document.createEvent('MouseEvents');
|
|
53
|
-
downloadClickEvent.initEvent('click', true, false);
|
|
54
|
-
downloadLink.dispatchEvent(downloadClickEvent);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function toColorHexNum(color) {
|
|
58
|
-
return parseInt(color.replace(/^\#/, '0x'));
|
|
59
|
-
}
|
|
60
|
-
function toColorHexStr(color) {
|
|
61
|
-
return '#' + color.toString(16);
|
|
62
|
-
}
|
|
63
|
-
function isColorStr(color) {
|
|
64
|
-
return typeof color === 'string' && /^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function createUUID() {
|
|
68
|
-
function str4() {
|
|
69
|
-
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
70
|
-
}
|
|
71
|
-
return "" + str4() + str4() + "-" + str4() + "-" + str4() + "-" + str4() + "-" + str4() + str4() + str4();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function deepClone(target) {
|
|
75
|
-
function _clone(t) {
|
|
76
|
-
var type = is(t);
|
|
77
|
-
if (['Null', 'Number', 'String', 'Boolean', 'Undefined'].indexOf(type) >= 0) {
|
|
78
|
-
return t;
|
|
79
|
-
}
|
|
80
|
-
else if (type === 'Array') {
|
|
81
|
-
var arr_1 = [];
|
|
82
|
-
t.forEach(function (item) {
|
|
83
|
-
arr_1.push(_clone(item));
|
|
84
|
-
});
|
|
85
|
-
return arr_1;
|
|
86
|
-
}
|
|
87
|
-
else if (type === 'Object') {
|
|
88
|
-
var obj_1 = {};
|
|
89
|
-
var keys = Object.keys(t);
|
|
90
|
-
keys.forEach(function (key) {
|
|
91
|
-
obj_1[key] = _clone(t[key]);
|
|
92
|
-
});
|
|
93
|
-
return obj_1;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return _clone(target);
|
|
97
|
-
}
|
|
98
|
-
function is(data) {
|
|
99
|
-
return Object.prototype.toString.call(data).replace(/[\]|\[]{1,1}/ig, '').split(' ')[1];
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function parsePrototype(data) {
|
|
103
|
-
var typeStr = Object.prototype.toString.call(data) || '';
|
|
104
|
-
var result = typeStr.replace(/(\[object|\])/ig, '').trim();
|
|
105
|
-
return result;
|
|
106
|
-
}
|
|
107
|
-
var istype = {
|
|
108
|
-
type: function (data, lowerCase) {
|
|
109
|
-
var result = parsePrototype(data);
|
|
110
|
-
return lowerCase === true ? result.toLocaleLowerCase() : result;
|
|
111
|
-
},
|
|
112
|
-
array: function (data) {
|
|
113
|
-
return parsePrototype(data) === 'Array';
|
|
114
|
-
},
|
|
115
|
-
json: function (data) {
|
|
116
|
-
return parsePrototype(data) === 'Object';
|
|
117
|
-
},
|
|
118
|
-
function: function (data) {
|
|
119
|
-
return parsePrototype(data) === 'Function';
|
|
120
|
-
},
|
|
121
|
-
asyncFunction: function (data) {
|
|
122
|
-
return parsePrototype(data) === 'AsyncFunction';
|
|
123
|
-
},
|
|
124
|
-
string: function (data) {
|
|
125
|
-
return parsePrototype(data) === 'String';
|
|
126
|
-
},
|
|
127
|
-
number: function (data) {
|
|
128
|
-
return parsePrototype(data) === 'Number';
|
|
129
|
-
},
|
|
130
|
-
undefined: function (data) {
|
|
131
|
-
return parsePrototype(data) === 'Undefined';
|
|
132
|
-
},
|
|
133
|
-
null: function (data) {
|
|
134
|
-
return parsePrototype(data) === 'Null';
|
|
135
|
-
},
|
|
136
|
-
promise: function (data) {
|
|
137
|
-
return parsePrototype(data) === 'Promise';
|
|
138
|
-
},
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
142
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
143
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
144
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
145
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
146
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
147
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
function __generator(thisArg, body) {
|
|
151
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
152
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
153
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
154
|
-
function step(op) {
|
|
155
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
156
|
-
while (_) try {
|
|
157
|
-
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;
|
|
158
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
159
|
-
switch (op[0]) {
|
|
160
|
-
case 0: case 1: t = op; break;
|
|
161
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
162
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
163
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
164
|
-
default:
|
|
165
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
166
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
167
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
168
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
169
|
-
if (t[2]) _.ops.pop();
|
|
170
|
-
_.trys.pop(); continue;
|
|
171
|
-
}
|
|
172
|
-
op = body.call(thisArg, _);
|
|
173
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
174
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function parseHTMLToDataURL(html, opts) {
|
|
179
|
-
var width = opts.width, height = opts.height;
|
|
180
|
-
return new Promise(function (resolve, reject) {
|
|
181
|
-
var _svg = "\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"" + (width || '') + "\" height = \"" + (height || '') + "\">\n <foreignObject width=\"100%\" height=\"100%\">\n <div xmlns = \"http://www.w3.org/1999/xhtml\">\n " + html + "\n </div>\n </foreignObject>\n </svg>\n ";
|
|
182
|
-
var blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
|
|
183
|
-
var reader = new FileReader();
|
|
184
|
-
reader.readAsDataURL(blob);
|
|
185
|
-
reader.onload = function (event) {
|
|
186
|
-
var _a;
|
|
187
|
-
var base64 = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
188
|
-
resolve(base64);
|
|
189
|
-
};
|
|
190
|
-
reader.onerror = function (err) {
|
|
191
|
-
reject(err);
|
|
192
|
-
};
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
function parseSVGToDataURL(svg) {
|
|
196
|
-
return new Promise(function (resolve, reject) {
|
|
197
|
-
var _svg = svg;
|
|
198
|
-
var blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
|
|
199
|
-
var reader = new FileReader();
|
|
200
|
-
reader.readAsDataURL(blob);
|
|
201
|
-
reader.onload = function (event) {
|
|
202
|
-
var _a;
|
|
203
|
-
var base64 = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
204
|
-
resolve(base64);
|
|
205
|
-
};
|
|
206
|
-
reader.onerror = function (err) {
|
|
207
|
-
reject(err);
|
|
208
|
-
};
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
var Image = window.Image;
|
|
213
|
-
function loadImage(src) {
|
|
214
|
-
return new Promise(function (resolve, reject) {
|
|
215
|
-
var img = new Image;
|
|
216
|
-
img.onload = function () {
|
|
217
|
-
resolve(img);
|
|
218
|
-
};
|
|
219
|
-
img.onabort = reject;
|
|
220
|
-
img.onerror = reject;
|
|
221
|
-
img.src = src;
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
function loadSVG(svg) {
|
|
225
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
226
|
-
var dataURL, image;
|
|
227
|
-
return __generator(this, function (_a) {
|
|
228
|
-
switch (_a.label) {
|
|
229
|
-
case 0: return [4, parseSVGToDataURL(svg)];
|
|
230
|
-
case 1:
|
|
231
|
-
dataURL = _a.sent();
|
|
232
|
-
return [4, loadImage(dataURL)];
|
|
233
|
-
case 2:
|
|
234
|
-
image = _a.sent();
|
|
235
|
-
return [2, image];
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
function loadHTML(html, opts) {
|
|
241
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
242
|
-
var dataURL, image;
|
|
243
|
-
return __generator(this, function (_a) {
|
|
244
|
-
switch (_a.label) {
|
|
245
|
-
case 0: return [4, parseHTMLToDataURL(html, opts)];
|
|
246
|
-
case 1:
|
|
247
|
-
dataURL = _a.sent();
|
|
248
|
-
return [4, loadImage(dataURL)];
|
|
249
|
-
case 2:
|
|
250
|
-
image = _a.sent();
|
|
251
|
-
return [2, image];
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
var index = {
|
|
258
|
-
time: {
|
|
259
|
-
delay: delay,
|
|
260
|
-
compose: compose,
|
|
261
|
-
throttle: throttle,
|
|
262
|
-
},
|
|
263
|
-
loader: {
|
|
264
|
-
loadImage: loadImage,
|
|
265
|
-
loadSVG: loadSVG,
|
|
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,
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
module.exports = index;
|
package/dist/index.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
declare function compose(middleware: Middleware[]): (context: any, next?: Middleware) => any;
|
|
2
|
-
|
|
3
|
-
declare function createUUID(): string;
|
|
4
|
-
|
|
5
|
-
declare function deepClone(target: any): any;
|
|
6
|
-
|
|
7
|
-
declare const _default: {
|
|
8
|
-
time: {
|
|
9
|
-
delay: typeof delay;
|
|
10
|
-
compose: typeof compose;
|
|
11
|
-
throttle: typeof throttle;
|
|
12
|
-
};
|
|
13
|
-
loader: {
|
|
14
|
-
loadImage: typeof loadImage;
|
|
15
|
-
loadSVG: typeof loadSVG;
|
|
16
|
-
loadHTML: typeof loadHTML;
|
|
17
|
-
};
|
|
18
|
-
file: {
|
|
19
|
-
downloadImageFromCanvas: typeof downloadImageFromCanvas;
|
|
20
|
-
};
|
|
21
|
-
color: {
|
|
22
|
-
toColorHexStr: typeof toColorHexStr;
|
|
23
|
-
toColorHexNum: typeof toColorHexNum;
|
|
24
|
-
isColorStr: typeof isColorStr;
|
|
25
|
-
};
|
|
26
|
-
uuid: {
|
|
27
|
-
createUUID: typeof createUUID;
|
|
28
|
-
};
|
|
29
|
-
istype: {
|
|
30
|
-
type(data: any, lowerCase?: boolean | undefined): string;
|
|
31
|
-
array(data: any): boolean;
|
|
32
|
-
json(data: any): boolean;
|
|
33
|
-
function(data: any): boolean;
|
|
34
|
-
asyncFunction(data: any): boolean;
|
|
35
|
-
string(data: any): boolean;
|
|
36
|
-
number(data: any): boolean;
|
|
37
|
-
undefined(data: any): boolean;
|
|
38
|
-
null(data: any): boolean;
|
|
39
|
-
promise(data: any): boolean;
|
|
40
|
-
};
|
|
41
|
-
data: {
|
|
42
|
-
deepClone: typeof deepClone;
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
export default _default;
|
|
46
|
-
|
|
47
|
-
declare function delay(time: number): Promise<void>;
|
|
48
|
-
|
|
49
|
-
declare function downloadImageFromCanvas(canvas: HTMLCanvasElement, opts: {
|
|
50
|
-
filename: string;
|
|
51
|
-
type: ImageType;
|
|
52
|
-
}): void;
|
|
53
|
-
|
|
54
|
-
declare type ImageType = 'image/jpeg' | 'image/png';
|
|
55
|
-
|
|
56
|
-
declare function isColorStr(color?: string): boolean;
|
|
57
|
-
|
|
58
|
-
declare function loadHTML(html: string, opts: {
|
|
59
|
-
width: number;
|
|
60
|
-
height: number;
|
|
61
|
-
}): Promise<HTMLImageElement>;
|
|
62
|
-
|
|
63
|
-
declare function loadImage(src: string): Promise<HTMLImageElement>;
|
|
64
|
-
|
|
65
|
-
declare function loadSVG(svg: string): Promise<HTMLImageElement>;
|
|
66
|
-
|
|
67
|
-
declare type Middleware = (ctx: any, next: Middleware) => any;
|
|
68
|
-
|
|
69
|
-
declare function throttle(fn: (...args: any[]) => any, timeout: number): (...args: any[]) => any;
|
|
70
|
-
|
|
71
|
-
declare function toColorHexNum(color: string): number;
|
|
72
|
-
|
|
73
|
-
declare function toColorHexStr(color: number): string;
|
|
74
|
-
|
|
75
|
-
export { }
|