@lingxia/bridge 0.5.0 → 0.5.1
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/bridge-runtime.es2020.js +1 -0
- package/dist/bridge-runtime.es5.js +1 -0
- package/dist/es2020/boot.js +34 -0
- package/dist/es2020/bridge.js +1574 -0
- package/dist/es2020/error.js +89 -0
- package/dist/es2020/image-proxy.js +82 -0
- package/dist/es2020/index.js +18 -0
- package/dist/es2020/invocation.js +57 -0
- package/dist/es2020/nativecomponents/coverage-monitor.js +159 -0
- package/dist/es2020/runtime-env.js +31 -0
- package/dist/es2020/types.js +16 -0
- package/dist/es2020/ui/action-sheet.js +138 -0
- package/dist/es2020/ui/index.js +10 -0
- package/dist/es2020/ui/modal.js +170 -0
- package/dist/es2020/ui/toast.js +145 -0
- package/dist/es5/boot.js +34 -0
- package/dist/es5/bridge.js +1852 -0
- package/dist/es5/error.js +35 -0
- package/dist/es5/image-proxy.js +83 -0
- package/dist/es5/index.js +18 -0
- package/dist/es5/invocation.js +76 -0
- package/dist/es5/nativecomponents/coverage-monitor.js +219 -0
- package/dist/es5/runtime-env.js +32 -0
- package/dist/es5/types.js +16 -0
- package/dist/es5/ui/action-sheet.js +82 -0
- package/dist/es5/ui/index.js +10 -0
- package/dist/es5/ui/modal.js +84 -0
- package/dist/es5/ui/toast.js +102 -0
- package/dist/invocation.d.ts +12 -0
- package/dist/types.d.ts +1 -0
- package/package.json +21 -9
- package/dist/runtime.es2020.js +0 -1663
- package/dist/runtime.es5.js +0 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
var ANIMATION_MS = 200;
|
|
2
|
+
var STYLE_ID = 'lx-toast-style';
|
|
3
|
+
var currentToast = null;
|
|
4
|
+
var SVG_SUCCESS = "<svg width=\"36\" height=\"36\" viewBox=\"0 0 36 36\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><circle cx=\"18\" cy=\"18\" r=\"17\" stroke=\"currentColor\" stroke-width=\"2\"/><path d=\"M11 18l5 5 9-9\" stroke=\"currentColor\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>";
|
|
5
|
+
var SVG_ERROR = "<svg width=\"36\" height=\"36\" viewBox=\"0 0 36 36\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><circle cx=\"18\" cy=\"18\" r=\"17\" stroke=\"currentColor\" stroke-width=\"2\"/><path d=\"M13 13l10 10M23 13l-10 10\" stroke=\"currentColor\" stroke-width=\"2.5\" stroke-linecap=\"round\"/></svg>";
|
|
6
|
+
var SVG_LOADING = "<svg width=\"36\" height=\"36\" viewBox=\"0 0 36 36\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M18 4a14 14 0 0 1 14 14\" stroke=\"currentColor\" stroke-width=\"2.5\" stroke-linecap=\"round\"><animateTransform attributeName=\"transform\" type=\"rotate\" from=\"0 18 18\" to=\"360 18 18\" dur=\"0.8s\" repeatCount=\"indefinite\"/></path></svg>";
|
|
7
|
+
function ensureToastStyle() {
|
|
8
|
+
if (document.getElementById(STYLE_ID))
|
|
9
|
+
return;
|
|
10
|
+
var style = document.createElement('style');
|
|
11
|
+
style.id = STYLE_ID;
|
|
12
|
+
style.textContent = "\n.lx-toast-mask {\n position: fixed; inset: 0; z-index: 99998;\n}\n.lx-toast-container {\n position: fixed; left: 0; right: 0; z-index: 99999;\n display: flex; justify-content: center;\n pointer-events: none;\n}\n.lx-toast-container.lx-toast-top { top: 0; padding-top: 80px; }\n.lx-toast-container.lx-toast-center { top: 0; bottom: 0; align-items: center; }\n.lx-toast-container.lx-toast-bottom { bottom: 0; padding-bottom: 80px; }\n\n.lx-toast-box {\n display: flex; flex-direction: column; align-items: center; gap: 10px;\n min-width: 120px; max-width: 280px;\n padding: 20px;\n background: rgba(0,0,0,0.8);\n border-radius: 12px;\n color: #fff;\n pointer-events: auto;\n transform: scale(0.8); opacity: 0;\n transition: transform ".concat(ANIMATION_MS, "ms ease, opacity ").concat(ANIMATION_MS, "ms ease;\n}\n.lx-toast-box.lx-toast-no-icon {\n min-width: auto; min-height: auto;\n padding: 12px 20px;\n}\n.lx-toast-box.lx-toast-visible {\n transform: scale(1); opacity: 1;\n}\n.lx-toast-icon {\n width: 36px; height: 36px;\n color: #fff;\n line-height: 0;\n}\n.lx-toast-title {\n font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;\n font-size: 16px; font-weight: 500;\n text-align: center;\n line-height: 1.4;\n word-break: break-word;\n -webkit-font-smoothing: antialiased;\n}\n");
|
|
13
|
+
document.head.appendChild(style);
|
|
14
|
+
}
|
|
15
|
+
export function showToast(params) {
|
|
16
|
+
var _a, _b, _c, _d, _e;
|
|
17
|
+
var p = params;
|
|
18
|
+
var title = (_a = p === null || p === void 0 ? void 0 : p.title) !== null && _a !== void 0 ? _a : '';
|
|
19
|
+
var icon = (_b = p === null || p === void 0 ? void 0 : p.icon) !== null && _b !== void 0 ? _b : 'none';
|
|
20
|
+
var duration = (_c = p === null || p === void 0 ? void 0 : p.duration) !== null && _c !== void 0 ? _c : 1500;
|
|
21
|
+
var mask = (_d = p === null || p === void 0 ? void 0 : p.mask) !== null && _d !== void 0 ? _d : false;
|
|
22
|
+
var position = (_e = p === null || p === void 0 ? void 0 : p.position) !== null && _e !== void 0 ? _e : 'center';
|
|
23
|
+
// Hide existing toast first
|
|
24
|
+
if (currentToast) {
|
|
25
|
+
currentToast.dismiss();
|
|
26
|
+
currentToast = null;
|
|
27
|
+
}
|
|
28
|
+
ensureToastStyle();
|
|
29
|
+
// Mask (prevents interaction)
|
|
30
|
+
var maskEl = null;
|
|
31
|
+
if (mask) {
|
|
32
|
+
maskEl = document.createElement('div');
|
|
33
|
+
maskEl.className = 'lx-toast-mask';
|
|
34
|
+
document.body.appendChild(maskEl);
|
|
35
|
+
}
|
|
36
|
+
// Container
|
|
37
|
+
var container = document.createElement('div');
|
|
38
|
+
container.className = 'lx-toast-container';
|
|
39
|
+
if (position === 'top')
|
|
40
|
+
container.classList.add('lx-toast-top');
|
|
41
|
+
else if (position === 'bottom')
|
|
42
|
+
container.classList.add('lx-toast-bottom');
|
|
43
|
+
else
|
|
44
|
+
container.classList.add('lx-toast-center');
|
|
45
|
+
// Toast box
|
|
46
|
+
var box = document.createElement('div');
|
|
47
|
+
box.className = 'lx-toast-box';
|
|
48
|
+
var hasIcon = icon !== 'none';
|
|
49
|
+
if (!hasIcon)
|
|
50
|
+
box.classList.add('lx-toast-no-icon');
|
|
51
|
+
// Icon
|
|
52
|
+
if (hasIcon) {
|
|
53
|
+
var iconEl = document.createElement('div');
|
|
54
|
+
iconEl.className = 'lx-toast-icon';
|
|
55
|
+
if (icon === 'success')
|
|
56
|
+
iconEl.innerHTML = SVG_SUCCESS;
|
|
57
|
+
else if (icon === 'error')
|
|
58
|
+
iconEl.innerHTML = SVG_ERROR;
|
|
59
|
+
else if (icon === 'loading')
|
|
60
|
+
iconEl.innerHTML = SVG_LOADING;
|
|
61
|
+
box.appendChild(iconEl);
|
|
62
|
+
}
|
|
63
|
+
// Title
|
|
64
|
+
var titleEl = document.createElement('div');
|
|
65
|
+
titleEl.className = 'lx-toast-title';
|
|
66
|
+
titleEl.textContent = title;
|
|
67
|
+
box.appendChild(titleEl);
|
|
68
|
+
container.appendChild(box);
|
|
69
|
+
document.body.appendChild(container);
|
|
70
|
+
// Animate in
|
|
71
|
+
requestAnimationFrame(function () {
|
|
72
|
+
box.classList.add('lx-toast-visible');
|
|
73
|
+
});
|
|
74
|
+
var dismissed = false;
|
|
75
|
+
function dismiss() {
|
|
76
|
+
if (dismissed)
|
|
77
|
+
return;
|
|
78
|
+
dismissed = true;
|
|
79
|
+
if ((currentToast === null || currentToast === void 0 ? void 0 : currentToast.dismiss) === dismiss)
|
|
80
|
+
currentToast = null;
|
|
81
|
+
box.classList.remove('lx-toast-visible');
|
|
82
|
+
if (timer)
|
|
83
|
+
clearTimeout(timer);
|
|
84
|
+
setTimeout(function () {
|
|
85
|
+
container.remove();
|
|
86
|
+
maskEl === null || maskEl === void 0 ? void 0 : maskEl.remove();
|
|
87
|
+
}, ANIMATION_MS);
|
|
88
|
+
}
|
|
89
|
+
var timer = null;
|
|
90
|
+
if (duration > 0) {
|
|
91
|
+
timer = setTimeout(dismiss, duration);
|
|
92
|
+
}
|
|
93
|
+
currentToast = { dismiss: dismiss, timer: timer };
|
|
94
|
+
return Promise.resolve();
|
|
95
|
+
}
|
|
96
|
+
export function hideToast() {
|
|
97
|
+
if (currentToast) {
|
|
98
|
+
currentToast.dismiss();
|
|
99
|
+
currentToast = null;
|
|
100
|
+
}
|
|
101
|
+
return Promise.resolve();
|
|
102
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LxBridgeError, LxChannel, LxStream } from "./types";
|
|
2
|
+
export type ParamsSource<T> = T | (() => T);
|
|
3
|
+
export type MethodParams<TMethod> = TMethod extends () => any ? undefined : TMethod extends (params: infer P) => any ? P : never;
|
|
4
|
+
export type StreamData<TMethod> = TMethod extends (...args: any[]) => LxStream<infer TData, any> ? TData : never;
|
|
5
|
+
export type StreamResult<TMethod> = TMethod extends (...args: any[]) => LxStream<any, infer TResult> ? TResult : never;
|
|
6
|
+
export type ChannelIn<TMethod> = TMethod extends (...args: any[]) => Promise<LxChannel<infer TIn, any>> ? TIn : never;
|
|
7
|
+
export type ChannelOut<TMethod> = TMethod extends (...args: any[]) => Promise<LxChannel<any, infer TOut>> ? TOut : never;
|
|
8
|
+
export declare function toBridgeError(err: unknown): LxBridgeError;
|
|
9
|
+
export declare function resolveParams<T>(source?: ParamsSource<T>): T | undefined;
|
|
10
|
+
export declare function stableParamKey(value: unknown): string;
|
|
11
|
+
export declare function invokeMethod<TMethod extends (...args: any[]) => any>(method: TMethod, params: unknown): ReturnType<TMethod>;
|
|
12
|
+
export declare function getMethodKey(method: unknown): string | undefined;
|
package/dist/types.d.ts
CHANGED
|
@@ -98,6 +98,7 @@ export interface LxChannel<TIn = unknown, TOut = TIn> extends AsyncIterable<TIn>
|
|
|
98
98
|
declare global {
|
|
99
99
|
interface Window {
|
|
100
100
|
__LX_BRIDGE_CFG?: BridgeConfig;
|
|
101
|
+
__LX_BRIDGE_INIT_STATE?: 'initializing' | 'initialized';
|
|
101
102
|
__LX_RUNTIME_CONFIG?: RuntimeConfig;
|
|
102
103
|
__pageBridge?: {
|
|
103
104
|
__names: string[];
|
package/package.json
CHANGED
|
@@ -1,33 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingxia/bridge",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "LingXia Web Runtime - Bridge, boot, and error handling for WebView",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"main": "dist/
|
|
7
|
+
"main": "dist/es2020/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"default": "./dist/
|
|
12
|
+
"default": "./dist/es2020/index.js"
|
|
13
13
|
},
|
|
14
|
-
"./
|
|
15
|
-
|
|
14
|
+
"./es5": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/es5/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./invocation": {
|
|
19
|
+
"types": "./dist/invocation.d.ts",
|
|
20
|
+
"default": "./dist/es2020/invocation.js"
|
|
21
|
+
},
|
|
22
|
+
"./invocation/es5": {
|
|
23
|
+
"types": "./dist/invocation.d.ts",
|
|
24
|
+
"default": "./dist/es5/invocation.js"
|
|
25
|
+
},
|
|
26
|
+
"./dist/bridge-runtime.es2020.js": "./dist/bridge-runtime.es2020.js",
|
|
27
|
+
"./dist/bridge-runtime.es5.js": "./dist/bridge-runtime.es5.js",
|
|
16
28
|
"./package.json": "./package.json"
|
|
17
29
|
},
|
|
18
30
|
"scripts": {
|
|
19
|
-
"build": "npm run clean && npm run build:es2020 && npm run build:es5 && npm run build:types",
|
|
20
|
-
"build:es2020": "
|
|
31
|
+
"build": "npm run clean && npm run build:es2020 && npm run build:es5 && npm run build:modules:es2020 && npm run build:modules:es5 && npm run build:types",
|
|
32
|
+
"build:es2020": "node ./scripts/build-es2020.mjs",
|
|
21
33
|
"build:es5": "node ./scripts/build-es5.mjs",
|
|
34
|
+
"build:modules:es2020": "tsc -p tsconfig.modules.json",
|
|
35
|
+
"build:modules:es5": "tsc -p tsconfig.modules.legacy.json",
|
|
22
36
|
"build:types": "tsc -p tsconfig.json --emitDeclarationOnly",
|
|
23
37
|
"dev": "rolldown -c -w",
|
|
24
38
|
"clean": "rm -rf dist",
|
|
25
39
|
"prepublishOnly": "npm run build"
|
|
26
40
|
},
|
|
27
41
|
"devDependencies": {
|
|
28
|
-
"esbuild": "^0.25.3",
|
|
29
42
|
"rolldown": "^1.0.0-rc.13",
|
|
30
|
-
"rollup-plugin-esbuild": "^6.2.1",
|
|
31
43
|
"terser": "^5.39.0",
|
|
32
44
|
"tslib": "^2.6.2",
|
|
33
45
|
"typescript": "^5.3.0"
|