@idraw/util 0.3.0-alpha.6 → 0.3.0-alpha.8
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/esm/index.d.ts +71 -0
- package/{esm → dist/esm}/index.js +19 -1
- 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 +655 -701
- package/dist/index.global.min.js +1 -1
- package/package.json +8 -13
- package/dist/index.cjs.js +0 -704
- package/dist/index.d.ts +0 -222
- package/dist/index.esm.js +0 -702
- package/esm/default.d.ts +0 -1
- package/esm/default.js +0 -2
- package/esm/esm.d.ts +0 -2
- package/esm/esm.js +0 -3
- package/esm/index.d.ts +0 -11
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const istype: {
|
|
2
|
+
type(data: any, lowerCase?: boolean): string;
|
|
3
|
+
array(data: any): boolean;
|
|
4
|
+
json(data: any): boolean;
|
|
5
|
+
function(data: any): boolean;
|
|
6
|
+
asyncFunction(data: any): boolean;
|
|
7
|
+
string(data: any): boolean;
|
|
8
|
+
number(data: any): boolean;
|
|
9
|
+
undefined(data: any): boolean;
|
|
10
|
+
null(data: any): boolean;
|
|
11
|
+
promise(data: any): boolean;
|
|
12
|
+
};
|
|
13
|
+
export default istype;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function parsePrototype(data) {
|
|
2
|
+
const typeStr = Object.prototype.toString.call(data) || '';
|
|
3
|
+
const result = typeStr.replace(/(\[object|\])/ig, '').trim();
|
|
4
|
+
return result;
|
|
5
|
+
}
|
|
6
|
+
const istype = {
|
|
7
|
+
type(data, lowerCase) {
|
|
8
|
+
const result = parsePrototype(data);
|
|
9
|
+
return lowerCase === true ? result.toLocaleLowerCase() : result;
|
|
10
|
+
},
|
|
11
|
+
array(data) {
|
|
12
|
+
return parsePrototype(data) === 'Array';
|
|
13
|
+
},
|
|
14
|
+
json(data) {
|
|
15
|
+
return parsePrototype(data) === 'Object';
|
|
16
|
+
},
|
|
17
|
+
function(data) {
|
|
18
|
+
return parsePrototype(data) === 'Function';
|
|
19
|
+
},
|
|
20
|
+
asyncFunction(data) {
|
|
21
|
+
return parsePrototype(data) === 'AsyncFunction';
|
|
22
|
+
},
|
|
23
|
+
string(data) {
|
|
24
|
+
return parsePrototype(data) === 'String';
|
|
25
|
+
},
|
|
26
|
+
number(data) {
|
|
27
|
+
return parsePrototype(data) === 'Number';
|
|
28
|
+
},
|
|
29
|
+
undefined(data) {
|
|
30
|
+
return parsePrototype(data) === 'Undefined';
|
|
31
|
+
},
|
|
32
|
+
null(data) {
|
|
33
|
+
return parsePrototype(data) === 'Null';
|
|
34
|
+
},
|
|
35
|
+
promise(data) {
|
|
36
|
+
return parsePrototype(data) === 'Promise';
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
export default istype;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function loadImage(src: string): Promise<HTMLImageElement>;
|
|
2
|
+
export declare function loadSVG(svg: string): Promise<HTMLImageElement>;
|
|
3
|
+
export declare function loadHTML(html: string, opts: {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}): Promise<HTMLImageElement>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { parseHTMLToDataURL, parseSVGToDataURL } from './parser';
|
|
11
|
+
const { Image } = window;
|
|
12
|
+
export function loadImage(src) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const img = new Image;
|
|
15
|
+
img.crossOrigin = 'anonymous';
|
|
16
|
+
img.onload = function () {
|
|
17
|
+
resolve(img);
|
|
18
|
+
};
|
|
19
|
+
img.onabort = reject;
|
|
20
|
+
img.onerror = reject;
|
|
21
|
+
img.src = src;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export function loadSVG(svg) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const dataURL = yield parseSVGToDataURL(svg);
|
|
27
|
+
const image = yield loadImage(dataURL);
|
|
28
|
+
return image;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function filterAmpersand(str) {
|
|
32
|
+
return str.replace(/\&/ig, '&');
|
|
33
|
+
}
|
|
34
|
+
export function loadHTML(html, opts) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
html = filterAmpersand(html);
|
|
37
|
+
const dataURL = yield parseHTMLToDataURL(html, opts);
|
|
38
|
+
const image = yield loadImage(dataURL);
|
|
39
|
+
return image;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export function parseHTMLToDataURL(html, opts) {
|
|
2
|
+
const { width, height } = opts;
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
const _svg = `
|
|
5
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="${width || ''}" height = "${height || ''}">
|
|
6
|
+
<foreignObject width="100%" height="100%">
|
|
7
|
+
<div xmlns = "http://www.w3.org/1999/xhtml">
|
|
8
|
+
${html}
|
|
9
|
+
</div>
|
|
10
|
+
</foreignObject>
|
|
11
|
+
</svg>
|
|
12
|
+
`;
|
|
13
|
+
const blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
|
|
14
|
+
const reader = new FileReader();
|
|
15
|
+
reader.readAsDataURL(blob);
|
|
16
|
+
reader.onload = function (event) {
|
|
17
|
+
var _a;
|
|
18
|
+
const base64 = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
19
|
+
resolve(base64);
|
|
20
|
+
};
|
|
21
|
+
reader.onerror = function (err) {
|
|
22
|
+
reject(err);
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export function parseSVGToDataURL(svg) {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
const _svg = svg;
|
|
29
|
+
const blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
|
|
30
|
+
const reader = new FileReader();
|
|
31
|
+
reader.readAsDataURL(blob);
|
|
32
|
+
reader.onload = function (event) {
|
|
33
|
+
var _a;
|
|
34
|
+
const base64 = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
35
|
+
resolve(base64);
|
|
36
|
+
};
|
|
37
|
+
reader.onerror = function (err) {
|
|
38
|
+
reject(err);
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type Middleware = (ctx: any, next: Middleware) => any;
|
|
2
|
+
export declare function compose(middleware: Middleware[]): (context: any, next?: Middleware) => any;
|
|
3
|
+
export declare function delay(time: number): Promise<void>;
|
|
4
|
+
export declare function throttle(fn: (...args: any[]) => any, timeout: number): (...args: any[]) => any;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export function compose(middleware) {
|
|
2
|
+
return function (context, next) {
|
|
3
|
+
return dispatch(0);
|
|
4
|
+
function dispatch(i) {
|
|
5
|
+
let fn = middleware[i];
|
|
6
|
+
if (i === middleware.length && next) {
|
|
7
|
+
fn = next;
|
|
8
|
+
}
|
|
9
|
+
if (!fn)
|
|
10
|
+
return Promise.resolve();
|
|
11
|
+
try {
|
|
12
|
+
return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
return Promise.reject(err);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function delay(time) {
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
setTimeout(() => {
|
|
23
|
+
resolve();
|
|
24
|
+
}, time);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export function throttle(fn, timeout) {
|
|
28
|
+
let timer = -1;
|
|
29
|
+
return function (...args) {
|
|
30
|
+
if (timer > 0) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
timer = setTimeout(() => {
|
|
34
|
+
fn(...args);
|
|
35
|
+
timer = -1;
|
|
36
|
+
}, timeout);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createUUID(): string;
|