@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.global.min.js
CHANGED
|
@@ -1,288 +1 @@
|
|
|
1
|
-
var iDrawUtil = (function () {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
function compose(middleware) {
|
|
5
|
-
return function (context, next) {
|
|
6
|
-
return dispatch(0);
|
|
7
|
-
function dispatch(i) {
|
|
8
|
-
var fn = middleware[i];
|
|
9
|
-
if (i === middleware.length && next) {
|
|
10
|
-
fn = next;
|
|
11
|
-
}
|
|
12
|
-
if (!fn)
|
|
13
|
-
return Promise.resolve();
|
|
14
|
-
try {
|
|
15
|
-
return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
|
|
16
|
-
}
|
|
17
|
-
catch (err) {
|
|
18
|
-
return Promise.reject(err);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
function delay(time) {
|
|
24
|
-
return new Promise(function (resolve) {
|
|
25
|
-
setTimeout(function () {
|
|
26
|
-
resolve();
|
|
27
|
-
}, time);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
function throttle(fn, timeout) {
|
|
31
|
-
var timer = -1;
|
|
32
|
-
return function () {
|
|
33
|
-
var args = [];
|
|
34
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
35
|
-
args[_i] = arguments[_i];
|
|
36
|
-
}
|
|
37
|
-
if (timer > 0) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
timer = setTimeout(function () {
|
|
41
|
-
fn.apply(void 0, args);
|
|
42
|
-
timer = -1;
|
|
43
|
-
}, timeout);
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function downloadImageFromCanvas(canvas, opts) {
|
|
48
|
-
var filename = opts.filename, _a = opts.type, type = _a === void 0 ? 'image/jpeg' : _a;
|
|
49
|
-
var stream = canvas.toDataURL(type);
|
|
50
|
-
var downloadLink = document.createElement('a');
|
|
51
|
-
downloadLink.href = stream;
|
|
52
|
-
downloadLink.download = filename;
|
|
53
|
-
var downloadClickEvent = document.createEvent('MouseEvents');
|
|
54
|
-
downloadClickEvent.initEvent('click', true, false);
|
|
55
|
-
downloadLink.dispatchEvent(downloadClickEvent);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function toColorHexNum(color) {
|
|
59
|
-
return parseInt(color.replace(/^\#/, '0x'));
|
|
60
|
-
}
|
|
61
|
-
function toColorHexStr(color) {
|
|
62
|
-
return '#' + color.toString(16);
|
|
63
|
-
}
|
|
64
|
-
function isColorStr(color) {
|
|
65
|
-
return typeof color === 'string' && /^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function createUUID() {
|
|
69
|
-
function str4() {
|
|
70
|
-
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
71
|
-
}
|
|
72
|
-
return "" + str4() + str4() + "-" + str4() + "-" + str4() + "-" + str4() + "-" + str4() + str4() + str4();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function deepClone(target) {
|
|
76
|
-
function _clone(t) {
|
|
77
|
-
var type = is(t);
|
|
78
|
-
if (['Null', 'Number', 'String', 'Boolean', 'Undefined'].indexOf(type) >= 0) {
|
|
79
|
-
return t;
|
|
80
|
-
}
|
|
81
|
-
else if (type === 'Array') {
|
|
82
|
-
var arr_1 = [];
|
|
83
|
-
t.forEach(function (item) {
|
|
84
|
-
arr_1.push(_clone(item));
|
|
85
|
-
});
|
|
86
|
-
return arr_1;
|
|
87
|
-
}
|
|
88
|
-
else if (type === 'Object') {
|
|
89
|
-
var obj_1 = {};
|
|
90
|
-
var keys = Object.keys(t);
|
|
91
|
-
keys.forEach(function (key) {
|
|
92
|
-
obj_1[key] = _clone(t[key]);
|
|
93
|
-
});
|
|
94
|
-
return obj_1;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return _clone(target);
|
|
98
|
-
}
|
|
99
|
-
function is(data) {
|
|
100
|
-
return Object.prototype.toString.call(data).replace(/[\]|\[]{1,1}/ig, '').split(' ')[1];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function parsePrototype(data) {
|
|
104
|
-
var typeStr = Object.prototype.toString.call(data) || '';
|
|
105
|
-
var result = typeStr.replace(/(\[object|\])/ig, '').trim();
|
|
106
|
-
return result;
|
|
107
|
-
}
|
|
108
|
-
var istype = {
|
|
109
|
-
type: function (data, lowerCase) {
|
|
110
|
-
var result = parsePrototype(data);
|
|
111
|
-
return lowerCase === true ? result.toLocaleLowerCase() : result;
|
|
112
|
-
},
|
|
113
|
-
array: function (data) {
|
|
114
|
-
return parsePrototype(data) === 'Array';
|
|
115
|
-
},
|
|
116
|
-
json: function (data) {
|
|
117
|
-
return parsePrototype(data) === 'Object';
|
|
118
|
-
},
|
|
119
|
-
function: function (data) {
|
|
120
|
-
return parsePrototype(data) === 'Function';
|
|
121
|
-
},
|
|
122
|
-
asyncFunction: function (data) {
|
|
123
|
-
return parsePrototype(data) === 'AsyncFunction';
|
|
124
|
-
},
|
|
125
|
-
string: function (data) {
|
|
126
|
-
return parsePrototype(data) === 'String';
|
|
127
|
-
},
|
|
128
|
-
number: function (data) {
|
|
129
|
-
return parsePrototype(data) === 'Number';
|
|
130
|
-
},
|
|
131
|
-
undefined: function (data) {
|
|
132
|
-
return parsePrototype(data) === 'Undefined';
|
|
133
|
-
},
|
|
134
|
-
null: function (data) {
|
|
135
|
-
return parsePrototype(data) === 'Null';
|
|
136
|
-
},
|
|
137
|
-
promise: function (data) {
|
|
138
|
-
return parsePrototype(data) === 'Promise';
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
143
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
144
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
145
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
146
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
147
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
148
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
function __generator(thisArg, body) {
|
|
152
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
153
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
154
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
155
|
-
function step(op) {
|
|
156
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
157
|
-
while (_) try {
|
|
158
|
-
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;
|
|
159
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
160
|
-
switch (op[0]) {
|
|
161
|
-
case 0: case 1: t = op; break;
|
|
162
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
163
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
164
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
165
|
-
default:
|
|
166
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
167
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
168
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
169
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
170
|
-
if (t[2]) _.ops.pop();
|
|
171
|
-
_.trys.pop(); continue;
|
|
172
|
-
}
|
|
173
|
-
op = body.call(thisArg, _);
|
|
174
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
175
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function parseHTMLToDataURL(html, opts) {
|
|
180
|
-
var width = opts.width, height = opts.height;
|
|
181
|
-
return new Promise(function (resolve, reject) {
|
|
182
|
-
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 ";
|
|
183
|
-
var blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
|
|
184
|
-
var reader = new FileReader();
|
|
185
|
-
reader.readAsDataURL(blob);
|
|
186
|
-
reader.onload = function (event) {
|
|
187
|
-
var _a;
|
|
188
|
-
var base64 = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
189
|
-
resolve(base64);
|
|
190
|
-
};
|
|
191
|
-
reader.onerror = function (err) {
|
|
192
|
-
reject(err);
|
|
193
|
-
};
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
function parseSVGToDataURL(svg) {
|
|
197
|
-
return new Promise(function (resolve, reject) {
|
|
198
|
-
var _svg = svg;
|
|
199
|
-
var blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
|
|
200
|
-
var reader = new FileReader();
|
|
201
|
-
reader.readAsDataURL(blob);
|
|
202
|
-
reader.onload = function (event) {
|
|
203
|
-
var _a;
|
|
204
|
-
var base64 = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
205
|
-
resolve(base64);
|
|
206
|
-
};
|
|
207
|
-
reader.onerror = function (err) {
|
|
208
|
-
reject(err);
|
|
209
|
-
};
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
var Image = window.Image;
|
|
214
|
-
function loadImage(src) {
|
|
215
|
-
return new Promise(function (resolve, reject) {
|
|
216
|
-
var img = new Image;
|
|
217
|
-
img.onload = function () {
|
|
218
|
-
resolve(img);
|
|
219
|
-
};
|
|
220
|
-
img.onabort = reject;
|
|
221
|
-
img.onerror = reject;
|
|
222
|
-
img.src = src;
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
function loadSVG(svg) {
|
|
226
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
227
|
-
var dataURL, image;
|
|
228
|
-
return __generator(this, function (_a) {
|
|
229
|
-
switch (_a.label) {
|
|
230
|
-
case 0: return [4, parseSVGToDataURL(svg)];
|
|
231
|
-
case 1:
|
|
232
|
-
dataURL = _a.sent();
|
|
233
|
-
return [4, loadImage(dataURL)];
|
|
234
|
-
case 2:
|
|
235
|
-
image = _a.sent();
|
|
236
|
-
return [2, image];
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
function loadHTML(html, opts) {
|
|
242
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
243
|
-
var dataURL, image;
|
|
244
|
-
return __generator(this, function (_a) {
|
|
245
|
-
switch (_a.label) {
|
|
246
|
-
case 0: return [4, parseHTMLToDataURL(html, opts)];
|
|
247
|
-
case 1:
|
|
248
|
-
dataURL = _a.sent();
|
|
249
|
-
return [4, loadImage(dataURL)];
|
|
250
|
-
case 2:
|
|
251
|
-
image = _a.sent();
|
|
252
|
-
return [2, image];
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
var index = {
|
|
259
|
-
time: {
|
|
260
|
-
delay: delay,
|
|
261
|
-
compose: compose,
|
|
262
|
-
throttle: throttle,
|
|
263
|
-
},
|
|
264
|
-
loader: {
|
|
265
|
-
loadImage: loadImage,
|
|
266
|
-
loadSVG: loadSVG,
|
|
267
|
-
loadHTML: loadHTML,
|
|
268
|
-
},
|
|
269
|
-
file: {
|
|
270
|
-
downloadImageFromCanvas: downloadImageFromCanvas,
|
|
271
|
-
},
|
|
272
|
-
color: {
|
|
273
|
-
toColorHexStr: toColorHexStr,
|
|
274
|
-
toColorHexNum: toColorHexNum,
|
|
275
|
-
isColorStr: isColorStr,
|
|
276
|
-
},
|
|
277
|
-
uuid: {
|
|
278
|
-
createUUID: createUUID
|
|
279
|
-
},
|
|
280
|
-
istype: istype,
|
|
281
|
-
data: {
|
|
282
|
-
deepClone: deepClone,
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
return index;
|
|
287
|
-
|
|
288
|
-
})();
|
|
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}();
|
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.22",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.es.js",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
|
-
"dist"
|
|
13
|
+
"dist/*.ts",
|
|
14
|
+
"dist/*.js"
|
|
14
15
|
],
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|
|
@@ -22,8 +23,11 @@
|
|
|
22
23
|
"homepage": "https://github.com/idrawjs/idraw#readme",
|
|
23
24
|
"author": "chenshenhai",
|
|
24
25
|
"license": "MIT",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@idraw/types": "^0.2.0-alpha.22"
|
|
28
|
+
},
|
|
25
29
|
"publishConfig": {
|
|
26
30
|
"access": "public"
|
|
27
31
|
},
|
|
28
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "884153bfe050aee75f4d132316db3bb750371375"
|
|
29
33
|
}
|