lupine.components 1.1.13 → 1.1.14
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/README.md +3 -3
- package/package.json +42 -42
- package/src/components/action-sheet.tsx +419 -419
- package/src/components/button-push-animation.tsx +147 -138
- package/src/components/button.tsx +55 -55
- package/src/components/desktop-footer.tsx +17 -17
- package/src/components/desktop-header.tsx +52 -52
- package/src/components/drag-refresh.tsx +129 -129
- package/src/components/editable-label.tsx +83 -83
- package/src/components/float-window.tsx +233 -233
- package/src/components/grid.tsx +18 -18
- package/src/components/html-load.tsx +41 -41
- package/src/components/html-var.tsx +81 -81
- package/src/components/index.ts +43 -44
- package/src/components/input-with-title.tsx +24 -24
- package/src/components/link-item.tsx +13 -13
- package/src/components/link-list.tsx +62 -62
- package/src/components/menu-bar.tsx +219 -219
- package/src/components/menu-item-props.tsx +13 -13
- package/src/components/menu-sidebar.tsx +325 -318
- package/src/components/message-box.tsx +44 -44
- package/src/components/meta-data.tsx +36 -36
- package/src/components/meta-description.tsx +12 -12
- package/src/components/mobile-components/icon-menu-item-props.ts +6 -6
- package/src/components/mobile-components/index.ts +8 -9
- package/src/components/mobile-components/mobile-footer-menu.tsx +95 -95
- package/src/components/mobile-components/mobile-header-component.tsx +101 -101
- package/src/components/mobile-components/mobile-header-title-icon.tsx +109 -101
- package/src/components/mobile-components/mobile-header-with-back.tsx +127 -117
- package/src/components/mobile-components/mobile-side-menu.tsx +154 -154
- package/src/components/mobile-components/mobile-top-sys-icon.tsx +18 -18
- package/src/components/mobile-components/mobile-top-sys-menu.tsx +62 -62
- package/src/components/modal.tsx +33 -33
- package/src/components/notice-message.tsx +118 -118
- package/src/components/page-title.tsx +6 -6
- package/src/components/paging-link.tsx +175 -175
- package/src/components/panel.tsx +21 -21
- package/src/components/popup-menu.tsx +289 -289
- package/src/components/progress.tsx +91 -91
- package/src/components/radio-label-component.tsx +36 -36
- package/src/components/redirect.tsx +19 -19
- package/src/components/resizable-splitter.tsx +128 -128
- package/src/components/select-angle-component.tsx +127 -127
- package/src/components/select-with-title.tsx +37 -37
- package/src/components/slide-tab-component.tsx +144 -149
- package/src/components/spinner.tsx +106 -100
- package/src/components/stars-component.tsx +66 -66
- package/src/components/svg.tsx +24 -24
- package/src/components/tabs.tsx +279 -279
- package/src/components/text-glow.tsx +37 -37
- package/src/components/text-scale.tsx +42 -42
- package/src/components/text-wave.tsx +55 -55
- package/src/components/theme-selector.tsx +28 -28
- package/src/components/toggle-base.tsx +269 -269
- package/src/components/toggle-switch.tsx +160 -160
- package/src/frames/index.ts +3 -3
- package/src/frames/responsive-frame.tsx +83 -83
- package/src/frames/slider-frame.tsx +111 -111
- package/src/frames/top-frame.tsx +30 -30
- package/src/index.ts +5 -5
- package/src/lib/back-action-helper.ts +54 -54
- package/src/lib/base62.ts +23 -23
- package/src/lib/blob-utils.ts +23 -23
- package/src/lib/calculate-text-width.ts +13 -13
- package/src/lib/date-utils.ts +317 -317
- package/src/lib/deep-merge.ts +37 -37
- package/src/lib/document-ready.ts +34 -34
- package/src/lib/dom-utils.ts +32 -32
- package/src/lib/download-file.ts +118 -118
- package/src/lib/download-link.ts +12 -12
- package/src/lib/download-stream.ts +19 -19
- package/src/lib/drag-util.ts +118 -118
- package/src/lib/dynamical-load.ts +134 -134
- package/src/lib/encode-html.ts +27 -27
- package/src/lib/find-parent-tag.ts +8 -8
- package/src/lib/format-bytes.ts +11 -11
- package/src/lib/index.ts +24 -24
- package/src/lib/lite-dom.ts +225 -225
- package/src/lib/message-hub.ts +103 -104
- package/src/lib/observable.ts +188 -188
- package/src/lib/path-utils.ts +42 -42
- package/src/lib/promise-timeout.ts +1 -1
- package/src/lib/simple-storage.ts +40 -40
- package/src/lib/stop-propagation.ts +7 -7
- package/src/lib/upload-file.ts +101 -101
- package/src/styles/base-themes.ts +17 -17
- package/src/styles/dark-themes.ts +99 -99
- package/src/styles/index.ts +5 -5
- package/src/styles/light-themes.ts +106 -106
- package/src/styles/media-query.ts +93 -93
- package/src/styles/shared-themes.ts +57 -57
- package/tsconfig.json +113 -113
package/src/lib/drag-util.ts
CHANGED
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
/*
|
|
2
|
-
const moveFn = createDragUtil();
|
|
3
|
-
moveFn.setOnMoveCallback((clientX: number, clientY: number, movedX: number, movedY: number) => {
|
|
4
|
-
const dragDom = moveFn.getDraggingDom();
|
|
5
|
-
if (dragDom?.classList.contains('xxx')) {
|
|
6
|
-
updateRangeMMove(clientX, true, dragDom, _saved.stopDoms);
|
|
7
|
-
} else if (dragDom?.classList.contains('yyy')) {
|
|
8
|
-
updatePicMMove(clientX);
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
<div
|
|
12
|
-
onMouseMove={moveFn.onMouseMove}
|
|
13
|
-
onMouseUp={moveFn.onMouseUp}
|
|
14
|
-
onTouchMove={moveFn.onTouchMove}
|
|
15
|
-
onTouchEnd={moveFn.onTouchEnd}
|
|
16
|
-
>
|
|
17
|
-
<div onMouseDown={moveFn.onMouseDown} onTouchStart={moveFn.onTouchStart}></div>
|
|
18
|
-
</div>
|
|
19
|
-
|
|
20
|
-
// when zooming an image, the way to scale slowly
|
|
21
|
-
const slowDelta = 1 + (scale - 1) * 0.2;
|
|
22
|
-
tempScale = lastScale * slowDelta;
|
|
23
|
-
*/
|
|
24
|
-
export const createDragUtil = () => {
|
|
25
|
-
let isDragging = false;
|
|
26
|
-
let initialX = 0;
|
|
27
|
-
let initialY = 0;
|
|
28
|
-
let draggingDom: HTMLDivElement | null = null;
|
|
29
|
-
let onMoveCallback: (clientX: number, clientY: number, movedX: number, movedY: number) => void = () => {};
|
|
30
|
-
let onScaleCallback: (scale: number) => void = () => {};
|
|
31
|
-
|
|
32
|
-
let isZooming = false;
|
|
33
|
-
let initialDistance = 0;
|
|
34
|
-
|
|
35
|
-
const getDistance = (t1: Touch, t2: Touch) => {
|
|
36
|
-
const dx = t2.clientX - t1.clientX;
|
|
37
|
-
const dy = t2.clientY - t1.clientY;
|
|
38
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
39
|
-
};
|
|
40
|
-
return {
|
|
41
|
-
setOnMoveCallback: (callback: (clientX: number, clientY: number, movedX: number, movedY: number) => void) => {
|
|
42
|
-
onMoveCallback = callback;
|
|
43
|
-
},
|
|
44
|
-
setOnScaleCallback: (callback: (scale: number) => void) => {
|
|
45
|
-
onScaleCallback = callback;
|
|
46
|
-
},
|
|
47
|
-
getDistance,
|
|
48
|
-
getDraggingDom: () => draggingDom,
|
|
49
|
-
onMouseDown: (event: MouseEvent) => {
|
|
50
|
-
event.preventDefault();
|
|
51
|
-
if (event.buttons !== 1) {
|
|
52
|
-
isDragging = false;
|
|
53
|
-
draggingDom = null;
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
isDragging = true;
|
|
57
|
-
draggingDom = event.currentTarget as HTMLDivElement;
|
|
58
|
-
initialX = event.clientX;
|
|
59
|
-
initialY = event.clientY;
|
|
60
|
-
},
|
|
61
|
-
onMouseMove: (event: MouseEvent) => {
|
|
62
|
-
if (event.buttons === 0 || !draggingDom) {
|
|
63
|
-
isDragging = false;
|
|
64
|
-
draggingDom = null;
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
onMoveCallback(event.clientX, event.clientY, event.clientX - initialX, event.clientY - initialY);
|
|
68
|
-
},
|
|
69
|
-
onMouseUp: () => {
|
|
70
|
-
isDragging = false;
|
|
71
|
-
isZooming = false;
|
|
72
|
-
draggingDom = null;
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
onTouchStart: (event: TouchEvent) => {
|
|
76
|
-
if (event.touches.length === 1) {
|
|
77
|
-
isDragging = true;
|
|
78
|
-
draggingDom = event.currentTarget as HTMLDivElement;
|
|
79
|
-
initialX = event.touches[0].clientX;
|
|
80
|
-
initialY = event.touches[0].clientY;
|
|
81
|
-
} else if (event.touches.length === 2) {
|
|
82
|
-
initialDistance = getDistance(event.touches[0], event.touches[1]);
|
|
83
|
-
isZooming = true;
|
|
84
|
-
} else {
|
|
85
|
-
isDragging = false;
|
|
86
|
-
draggingDom = null;
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
onTouchMove: (event: TouchEvent) => {
|
|
90
|
-
if (isZooming) {
|
|
91
|
-
if (event.touches.length === 2) {
|
|
92
|
-
event.preventDefault(); // 防止页面滚动
|
|
93
|
-
const newDistance = getDistance(event.touches[0], event.touches[1]);
|
|
94
|
-
const delta = newDistance / initialDistance;
|
|
95
|
-
// const newScale = Math.min(Math.max(1, scale * delta), 4); // 限制缩放范围
|
|
96
|
-
onScaleCallback(delta);
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (!isDragging || event.touches.length === 0 || !draggingDom) {
|
|
101
|
-
isDragging = false;
|
|
102
|
-
draggingDom = null;
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
onMoveCallback(
|
|
106
|
-
event.touches[0].clientX,
|
|
107
|
-
event.touches[0].clientY,
|
|
108
|
-
event.touches[0].clientX - initialX,
|
|
109
|
-
event.touches[0].clientY - initialY
|
|
110
|
-
);
|
|
111
|
-
},
|
|
112
|
-
onTouchEnd: () => {
|
|
113
|
-
isDragging = false;
|
|
114
|
-
isZooming = false;
|
|
115
|
-
draggingDom = null;
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
};
|
|
1
|
+
/*
|
|
2
|
+
const moveFn = createDragUtil();
|
|
3
|
+
moveFn.setOnMoveCallback((clientX: number, clientY: number, movedX: number, movedY: number) => {
|
|
4
|
+
const dragDom = moveFn.getDraggingDom();
|
|
5
|
+
if (dragDom?.classList.contains('xxx')) {
|
|
6
|
+
updateRangeMMove(clientX, true, dragDom, _saved.stopDoms);
|
|
7
|
+
} else if (dragDom?.classList.contains('yyy')) {
|
|
8
|
+
updatePicMMove(clientX);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
<div
|
|
12
|
+
onMouseMove={moveFn.onMouseMove}
|
|
13
|
+
onMouseUp={moveFn.onMouseUp}
|
|
14
|
+
onTouchMove={moveFn.onTouchMove}
|
|
15
|
+
onTouchEnd={moveFn.onTouchEnd}
|
|
16
|
+
>
|
|
17
|
+
<div onMouseDown={moveFn.onMouseDown} onTouchStart={moveFn.onTouchStart}></div>
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
// when zooming an image, the way to scale slowly
|
|
21
|
+
const slowDelta = 1 + (scale - 1) * 0.2;
|
|
22
|
+
tempScale = lastScale * slowDelta;
|
|
23
|
+
*/
|
|
24
|
+
export const createDragUtil = () => {
|
|
25
|
+
let isDragging = false;
|
|
26
|
+
let initialX = 0;
|
|
27
|
+
let initialY = 0;
|
|
28
|
+
let draggingDom: HTMLDivElement | null = null;
|
|
29
|
+
let onMoveCallback: (clientX: number, clientY: number, movedX: number, movedY: number) => void = () => {};
|
|
30
|
+
let onScaleCallback: (scale: number) => void = () => {};
|
|
31
|
+
|
|
32
|
+
let isZooming = false;
|
|
33
|
+
let initialDistance = 0;
|
|
34
|
+
|
|
35
|
+
const getDistance = (t1: Touch, t2: Touch) => {
|
|
36
|
+
const dx = t2.clientX - t1.clientX;
|
|
37
|
+
const dy = t2.clientY - t1.clientY;
|
|
38
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
setOnMoveCallback: (callback: (clientX: number, clientY: number, movedX: number, movedY: number) => void) => {
|
|
42
|
+
onMoveCallback = callback;
|
|
43
|
+
},
|
|
44
|
+
setOnScaleCallback: (callback: (scale: number) => void) => {
|
|
45
|
+
onScaleCallback = callback;
|
|
46
|
+
},
|
|
47
|
+
getDistance,
|
|
48
|
+
getDraggingDom: () => draggingDom,
|
|
49
|
+
onMouseDown: (event: MouseEvent) => {
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
if (event.buttons !== 1) {
|
|
52
|
+
isDragging = false;
|
|
53
|
+
draggingDom = null;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
isDragging = true;
|
|
57
|
+
draggingDom = event.currentTarget as HTMLDivElement;
|
|
58
|
+
initialX = event.clientX;
|
|
59
|
+
initialY = event.clientY;
|
|
60
|
+
},
|
|
61
|
+
onMouseMove: (event: MouseEvent) => {
|
|
62
|
+
if (event.buttons === 0 || !draggingDom) {
|
|
63
|
+
isDragging = false;
|
|
64
|
+
draggingDom = null;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
onMoveCallback(event.clientX, event.clientY, event.clientX - initialX, event.clientY - initialY);
|
|
68
|
+
},
|
|
69
|
+
onMouseUp: () => {
|
|
70
|
+
isDragging = false;
|
|
71
|
+
isZooming = false;
|
|
72
|
+
draggingDom = null;
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
onTouchStart: (event: TouchEvent) => {
|
|
76
|
+
if (event.touches.length === 1) {
|
|
77
|
+
isDragging = true;
|
|
78
|
+
draggingDom = event.currentTarget as HTMLDivElement;
|
|
79
|
+
initialX = event.touches[0].clientX;
|
|
80
|
+
initialY = event.touches[0].clientY;
|
|
81
|
+
} else if (event.touches.length === 2) {
|
|
82
|
+
initialDistance = getDistance(event.touches[0], event.touches[1]);
|
|
83
|
+
isZooming = true;
|
|
84
|
+
} else {
|
|
85
|
+
isDragging = false;
|
|
86
|
+
draggingDom = null;
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
onTouchMove: (event: TouchEvent) => {
|
|
90
|
+
if (isZooming) {
|
|
91
|
+
if (event.touches.length === 2) {
|
|
92
|
+
event.preventDefault(); // 防止页面滚动
|
|
93
|
+
const newDistance = getDistance(event.touches[0], event.touches[1]);
|
|
94
|
+
const delta = newDistance / initialDistance;
|
|
95
|
+
// const newScale = Math.min(Math.max(1, scale * delta), 4); // 限制缩放范围
|
|
96
|
+
onScaleCallback(delta);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (!isDragging || event.touches.length === 0 || !draggingDom) {
|
|
101
|
+
isDragging = false;
|
|
102
|
+
draggingDom = null;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
onMoveCallback(
|
|
106
|
+
event.touches[0].clientX,
|
|
107
|
+
event.touches[0].clientY,
|
|
108
|
+
event.touches[0].clientX - initialX,
|
|
109
|
+
event.touches[0].clientY - initialY
|
|
110
|
+
);
|
|
111
|
+
},
|
|
112
|
+
onTouchEnd: () => {
|
|
113
|
+
isDragging = false;
|
|
114
|
+
isZooming = false;
|
|
115
|
+
draggingDom = null;
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
};
|
|
@@ -1,134 +1,134 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* for my-apps
|
|
3
|
-
*/
|
|
4
|
-
export class DynamicalLoad {
|
|
5
|
-
static loadScript(url: string, idForReplace?: string, removeOnLoaded = false): Promise<string> {
|
|
6
|
-
return new Promise((resolve, reject) => {
|
|
7
|
-
if (this.existScript(url, idForReplace)) {
|
|
8
|
-
resolve(url);
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
const scriptDom = document.createElement('script');
|
|
12
|
-
scriptDom.src = url;
|
|
13
|
-
if (idForReplace) {
|
|
14
|
-
scriptDom.id = idForReplace;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
scriptDom.onload = () => {
|
|
18
|
-
resolve(url);
|
|
19
|
-
if (removeOnLoaded) {
|
|
20
|
-
scriptDom.remove();
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
scriptDom.onerror = () => {
|
|
25
|
-
reject(new Error('Failed to load module script with URL ' + url));
|
|
26
|
-
if (removeOnLoaded) {
|
|
27
|
-
scriptDom.remove();
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const head = document.getElementsByTagName('head')[0];
|
|
32
|
-
head ? head.appendChild(scriptDom) : document.documentElement.appendChild(scriptDom);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// TODO: more accuracy
|
|
37
|
-
static existScript(url: string, id?: string) {
|
|
38
|
-
if (id) {
|
|
39
|
-
const scriptDom = document.getElementById(id);
|
|
40
|
-
if (scriptDom && scriptDom.tagName === 'SCRIPT') {
|
|
41
|
-
const src = (scriptDom as HTMLScriptElement).src.split('?')[0];
|
|
42
|
-
if (src.substring(src.length - url.length) === url) {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const scripts = document.scripts;
|
|
49
|
-
for (let i = 0; i < scripts.length; i++) {
|
|
50
|
-
const src = scripts[i].src.split('?')[0];
|
|
51
|
-
if (src.substring(src.length - url.length) === url) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
static loadCss(url: string, idForReplace?: string): Promise<string> {
|
|
58
|
-
return new Promise((resolve, reject) => {
|
|
59
|
-
if (this.existCss(url, idForReplace)) {
|
|
60
|
-
resolve(url);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (idForReplace) {
|
|
64
|
-
const sheet = document.getElementById(idForReplace);
|
|
65
|
-
if (sheet && sheet.tagName === 'LINK') {
|
|
66
|
-
sheet.parentNode!.removeChild(sheet);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const linkDom = document.createElement('link');
|
|
71
|
-
linkDom.rel = 'stylesheet';
|
|
72
|
-
linkDom.type = 'text/css';
|
|
73
|
-
linkDom.href = url;
|
|
74
|
-
linkDom.media = 'all';
|
|
75
|
-
if (idForReplace) {
|
|
76
|
-
linkDom.id = idForReplace;
|
|
77
|
-
}
|
|
78
|
-
linkDom.onload = () => {
|
|
79
|
-
resolve(url);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
linkDom.onerror = () => {
|
|
83
|
-
reject(new Error('Failed to load css with URL ' + url));
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
document.getElementsByTagName('head')[0].appendChild(linkDom);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// TODO: more accuracy
|
|
91
|
-
static existCss(url: string, id?: string) {
|
|
92
|
-
if (id) {
|
|
93
|
-
const linkDom = document.getElementById(id);
|
|
94
|
-
if (linkDom && linkDom.tagName === 'LINK') {
|
|
95
|
-
const href = (<any>linkDom).href.split('?')[0];
|
|
96
|
-
if (href.substring(href.length - url.length) === url) {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const styles = document.styleSheets;
|
|
103
|
-
for (let i = 0; i < styles.length; i++) {
|
|
104
|
-
const linkDom = styles[i] as any;
|
|
105
|
-
const href = linkDom.href.split('?')[0];
|
|
106
|
-
if (href.substring(href.length - url.length) === url) {
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// removeCss(url: string, id?: string) {
|
|
113
|
-
// if (id) {
|
|
114
|
-
// const sheet = document.getElementById(id);
|
|
115
|
-
// if (sheet && sheet instanceof HTMLElement) {
|
|
116
|
-
// const href = (<any>sheet).href;
|
|
117
|
-
// if (href.substring(href.length - url.length) === url) {
|
|
118
|
-
// (<any>sheet).disabled = true;
|
|
119
|
-
// sheet.parentNode.removeChild(sheet);
|
|
120
|
-
// return;
|
|
121
|
-
// }
|
|
122
|
-
// }
|
|
123
|
-
// }
|
|
124
|
-
// const styles = document.styleSheets;
|
|
125
|
-
// for (const i = 0; i < styles.length; i++) {
|
|
126
|
-
// const sheet = styles[i] as any;
|
|
127
|
-
// if (sheet.href.substring(sheet.href.length - url.length) === url) {
|
|
128
|
-
// sheet.disabled = true;
|
|
129
|
-
// sheet.ownerNode.parentNode.removeChild(sheet.ownerNode);
|
|
130
|
-
// return;
|
|
131
|
-
// }
|
|
132
|
-
// }
|
|
133
|
-
// }
|
|
134
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* for my-apps
|
|
3
|
+
*/
|
|
4
|
+
export class DynamicalLoad {
|
|
5
|
+
static loadScript(url: string, idForReplace?: string, removeOnLoaded = false): Promise<string> {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
if (this.existScript(url, idForReplace)) {
|
|
8
|
+
resolve(url);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const scriptDom = document.createElement('script');
|
|
12
|
+
scriptDom.src = url;
|
|
13
|
+
if (idForReplace) {
|
|
14
|
+
scriptDom.id = idForReplace;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
scriptDom.onload = () => {
|
|
18
|
+
resolve(url);
|
|
19
|
+
if (removeOnLoaded) {
|
|
20
|
+
scriptDom.remove();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
scriptDom.onerror = () => {
|
|
25
|
+
reject(new Error('Failed to load module script with URL ' + url));
|
|
26
|
+
if (removeOnLoaded) {
|
|
27
|
+
scriptDom.remove();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const head = document.getElementsByTagName('head')[0];
|
|
32
|
+
head ? head.appendChild(scriptDom) : document.documentElement.appendChild(scriptDom);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// TODO: more accuracy
|
|
37
|
+
static existScript(url: string, id?: string) {
|
|
38
|
+
if (id) {
|
|
39
|
+
const scriptDom = document.getElementById(id);
|
|
40
|
+
if (scriptDom && scriptDom.tagName === 'SCRIPT') {
|
|
41
|
+
const src = (scriptDom as HTMLScriptElement).src.split('?')[0];
|
|
42
|
+
if (src.substring(src.length - url.length) === url) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const scripts = document.scripts;
|
|
49
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
50
|
+
const src = scripts[i].src.split('?')[0];
|
|
51
|
+
if (src.substring(src.length - url.length) === url) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static loadCss(url: string, idForReplace?: string): Promise<string> {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
if (this.existCss(url, idForReplace)) {
|
|
60
|
+
resolve(url);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (idForReplace) {
|
|
64
|
+
const sheet = document.getElementById(idForReplace);
|
|
65
|
+
if (sheet && sheet.tagName === 'LINK') {
|
|
66
|
+
sheet.parentNode!.removeChild(sheet);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const linkDom = document.createElement('link');
|
|
71
|
+
linkDom.rel = 'stylesheet';
|
|
72
|
+
linkDom.type = 'text/css';
|
|
73
|
+
linkDom.href = url;
|
|
74
|
+
linkDom.media = 'all';
|
|
75
|
+
if (idForReplace) {
|
|
76
|
+
linkDom.id = idForReplace;
|
|
77
|
+
}
|
|
78
|
+
linkDom.onload = () => {
|
|
79
|
+
resolve(url);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
linkDom.onerror = () => {
|
|
83
|
+
reject(new Error('Failed to load css with URL ' + url));
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
document.getElementsByTagName('head')[0].appendChild(linkDom);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// TODO: more accuracy
|
|
91
|
+
static existCss(url: string, id?: string) {
|
|
92
|
+
if (id) {
|
|
93
|
+
const linkDom = document.getElementById(id);
|
|
94
|
+
if (linkDom && linkDom.tagName === 'LINK') {
|
|
95
|
+
const href = (<any>linkDom).href.split('?')[0];
|
|
96
|
+
if (href.substring(href.length - url.length) === url) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const styles = document.styleSheets;
|
|
103
|
+
for (let i = 0; i < styles.length; i++) {
|
|
104
|
+
const linkDom = styles[i] as any;
|
|
105
|
+
const href = linkDom.href.split('?')[0];
|
|
106
|
+
if (href.substring(href.length - url.length) === url) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// removeCss(url: string, id?: string) {
|
|
113
|
+
// if (id) {
|
|
114
|
+
// const sheet = document.getElementById(id);
|
|
115
|
+
// if (sheet && sheet instanceof HTMLElement) {
|
|
116
|
+
// const href = (<any>sheet).href;
|
|
117
|
+
// if (href.substring(href.length - url.length) === url) {
|
|
118
|
+
// (<any>sheet).disabled = true;
|
|
119
|
+
// sheet.parentNode.removeChild(sheet);
|
|
120
|
+
// return;
|
|
121
|
+
// }
|
|
122
|
+
// }
|
|
123
|
+
// }
|
|
124
|
+
// const styles = document.styleSheets;
|
|
125
|
+
// for (const i = 0; i < styles.length; i++) {
|
|
126
|
+
// const sheet = styles[i] as any;
|
|
127
|
+
// if (sheet.href.substring(sheet.href.length - url.length) === url) {
|
|
128
|
+
// sheet.disabled = true;
|
|
129
|
+
// sheet.ownerNode.parentNode.removeChild(sheet.ownerNode);
|
|
130
|
+
// return;
|
|
131
|
+
// }
|
|
132
|
+
// }
|
|
133
|
+
// }
|
|
134
|
+
}
|
package/src/lib/encode-html.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
export const encodeHtml = (str: string): string => {
|
|
2
|
-
return str.replace(
|
|
3
|
-
/[&<>'"]/g,
|
|
4
|
-
(tag) =>
|
|
5
|
-
({
|
|
6
|
-
'&': '&',
|
|
7
|
-
'<': '<',
|
|
8
|
-
'>': '>',
|
|
9
|
-
"'": ''',
|
|
10
|
-
'"': '"',
|
|
11
|
-
}[tag] || '')
|
|
12
|
-
);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const decodeHtml = (str: string): string => {
|
|
16
|
-
return str.replace(
|
|
17
|
-
/&(\D+);/gi,
|
|
18
|
-
(tag) =>
|
|
19
|
-
({
|
|
20
|
-
'&': '&',
|
|
21
|
-
'<': '<',
|
|
22
|
-
'>': '>',
|
|
23
|
-
''': "'",
|
|
24
|
-
'"': '"',
|
|
25
|
-
}[tag] || '')
|
|
26
|
-
);
|
|
27
|
-
};
|
|
1
|
+
export const encodeHtml = (str: string): string => {
|
|
2
|
+
return str.replace(
|
|
3
|
+
/[&<>'"]/g,
|
|
4
|
+
(tag) =>
|
|
5
|
+
({
|
|
6
|
+
'&': '&',
|
|
7
|
+
'<': '<',
|
|
8
|
+
'>': '>',
|
|
9
|
+
"'": ''',
|
|
10
|
+
'"': '"',
|
|
11
|
+
}[tag] || '')
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const decodeHtml = (str: string): string => {
|
|
16
|
+
return str.replace(
|
|
17
|
+
/&(\D+);/gi,
|
|
18
|
+
(tag) =>
|
|
19
|
+
({
|
|
20
|
+
'&': '&',
|
|
21
|
+
'<': '<',
|
|
22
|
+
'>': '>',
|
|
23
|
+
''': "'",
|
|
24
|
+
'"': '"',
|
|
25
|
+
}[tag] || '')
|
|
26
|
+
);
|
|
27
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export const findParentTag = (dom: HTMLElement, tag: string) => {
|
|
2
|
-
const tagUpper = tag.toUpperCase();
|
|
3
|
-
let parent = dom.parentElement;
|
|
4
|
-
while (parent && parent.tagName !== tagUpper && parent.tagName !== 'BODY') {
|
|
5
|
-
parent = parent.parentElement;
|
|
6
|
-
}
|
|
7
|
-
return parent;
|
|
8
|
-
};
|
|
1
|
+
export const findParentTag = (dom: HTMLElement, tag: string) => {
|
|
2
|
+
const tagUpper = tag.toUpperCase();
|
|
3
|
+
let parent = dom.parentElement;
|
|
4
|
+
while (parent && parent.tagName !== tagUpper && parent.tagName !== 'BODY') {
|
|
5
|
+
parent = parent.parentElement;
|
|
6
|
+
}
|
|
7
|
+
return parent;
|
|
8
|
+
};
|
package/src/lib/format-bytes.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export const formatBytes = (bytes: number, decimals = 2) => {
|
|
2
|
-
if (!+bytes) return '0 Bytes';
|
|
3
|
-
|
|
4
|
-
const k = 1024;
|
|
5
|
-
const dm = decimals < 0 ? 0 : decimals;
|
|
6
|
-
const sizes = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
|
7
|
-
|
|
8
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
9
|
-
|
|
10
|
-
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
11
|
-
};
|
|
1
|
+
export const formatBytes = (bytes: number, decimals = 2) => {
|
|
2
|
+
if (!+bytes) return '0 Bytes';
|
|
3
|
+
|
|
4
|
+
const k = 1024;
|
|
5
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
6
|
+
const sizes = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
|
7
|
+
|
|
8
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
9
|
+
|
|
10
|
+
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
11
|
+
};
|
package/src/lib/index.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
export * from './back-action-helper';
|
|
2
|
-
export * from './base62';
|
|
3
|
-
export * from './blob-utils';
|
|
4
|
-
export * from './calculate-text-width';
|
|
5
|
-
export * from './date-utils';
|
|
6
|
-
export * from './deep-merge';
|
|
7
|
-
export * from './document-ready';
|
|
8
|
-
export * from './dom-utils';
|
|
9
|
-
export * from './download-file';
|
|
10
|
-
export * from './download-link';
|
|
11
|
-
export * from './download-stream';
|
|
12
|
-
export * from './drag-util';
|
|
13
|
-
export * from './dynamical-load';
|
|
14
|
-
export * from './encode-html';
|
|
15
|
-
export * from './find-parent-tag';
|
|
16
|
-
export * from './format-bytes';
|
|
17
|
-
export * from './lite-dom';
|
|
18
|
-
export * from './message-hub';
|
|
19
|
-
export * from './observable';
|
|
20
|
-
export * from './path-utils';
|
|
21
|
-
export * from './promise-timeout';
|
|
22
|
-
export * from './simple-storage';
|
|
23
|
-
export * from './stop-propagation';
|
|
24
|
-
export * from './upload-file';
|
|
1
|
+
export * from './back-action-helper';
|
|
2
|
+
export * from './base62';
|
|
3
|
+
export * from './blob-utils';
|
|
4
|
+
export * from './calculate-text-width';
|
|
5
|
+
export * from './date-utils';
|
|
6
|
+
export * from './deep-merge';
|
|
7
|
+
export * from './document-ready';
|
|
8
|
+
export * from './dom-utils';
|
|
9
|
+
export * from './download-file';
|
|
10
|
+
export * from './download-link';
|
|
11
|
+
export * from './download-stream';
|
|
12
|
+
export * from './drag-util';
|
|
13
|
+
export * from './dynamical-load';
|
|
14
|
+
export * from './encode-html';
|
|
15
|
+
export * from './find-parent-tag';
|
|
16
|
+
export * from './format-bytes';
|
|
17
|
+
export * from './lite-dom';
|
|
18
|
+
export * from './message-hub';
|
|
19
|
+
export * from './observable';
|
|
20
|
+
export * from './path-utils';
|
|
21
|
+
export * from './promise-timeout';
|
|
22
|
+
export * from './simple-storage';
|
|
23
|
+
export * from './stop-propagation';
|
|
24
|
+
export * from './upload-file';
|