@lingxia/bridge 0.5.0 → 0.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/dist/bridge-runtime.es2020.js +1 -0
- package/dist/bridge-runtime.es5.js +1 -0
- package/dist/bridge.d.ts +5 -2
- package/dist/es2020/boot.js +34 -0
- package/dist/es2020/bridge.js +1597 -0
- package/dist/es2020/error.js +89 -0
- package/dist/es2020/image-proxy.js +82 -0
- package/dist/es2020/index.js +19 -0
- package/dist/es2020/invocation.js +77 -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 +1930 -0
- package/dist/es5/error.js +35 -0
- package/dist/es5/image-proxy.js +83 -0
- package/dist/es5/index.js +19 -0
- package/dist/es5/invocation.js +103 -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/index.d.ts +3 -2
- package/dist/invocation.d.ts +14 -0
- package/dist/types.d.ts +42 -15
- package/package.json +21 -9
- package/dist/runtime.es2020.js +0 -1663
- package/dist/runtime.es5.js +0 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var ANIMATION_MS = 200;
|
|
2
|
+
var STYLE_ID = 'lx-modal-style';
|
|
3
|
+
var activeModal = null;
|
|
4
|
+
function ensureModalStyle() {
|
|
5
|
+
if (document.getElementById(STYLE_ID))
|
|
6
|
+
return;
|
|
7
|
+
var style = document.createElement('style');
|
|
8
|
+
style.id = STYLE_ID;
|
|
9
|
+
style.textContent = "\n.lx-modal-backdrop {\n position: fixed; inset: 0; z-index: 99999;\n background: rgba(0,0,0,0.4);\n opacity: 0; transition: opacity ".concat(ANIMATION_MS, "ms ease;\n display: flex; align-items: center; justify-content: center;\n}\n.lx-modal-backdrop.lx-modal-visible { opacity: 1; }\n\n.lx-modal-dialog {\n width: min(92vw, 320px);\n background: #fff;\n border-radius: 14px;\n overflow: hidden;\n font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;\n -webkit-font-smoothing: antialiased;\n transform: scale(0.95); opacity: 0;\n transition: transform ").concat(ANIMATION_MS, "ms ease, opacity ").concat(ANIMATION_MS, "ms ease;\n}\n.lx-modal-backdrop.lx-modal-visible .lx-modal-dialog {\n transform: scale(1); opacity: 1;\n}\n\n.lx-modal-body {\n padding: 24px 20px 16px;\n text-align: center;\n}\n.lx-modal-title {\n margin: 0 0 8px;\n font-size: 17px;\n font-weight: 600;\n color: #000;\n line-height: 1.35;\n}\n.lx-modal-content {\n margin: 0;\n font-size: 14px;\n color: #666;\n line-height: 1.5;\n word-break: break-word;\n}\n.lx-modal-body:has(.lx-modal-title:empty) .lx-modal-content {\n font-size: 17px;\n font-weight: 600;\n color: #000;\n}\n\n.lx-modal-footer {\n display: flex;\n border-top: 1px solid #E0E0E0;\n}\n.lx-modal-btn {\n flex: 1;\n height: 44px;\n line-height: 44px;\n padding: 0;\n border: none;\n background: none;\n font-size: 17px;\n text-align: center;\n cursor: pointer;\n -webkit-tap-highlight-color: transparent;\n}\n.lx-modal-btn:active { background: rgba(0,0,0,0.06); }\n.lx-modal-btn + .lx-modal-btn {\n border-left: 1px solid #E0E0E0;\n}\n.lx-modal-btn-cancel {\n color: #666;\n font-weight: 400;\n}\n.lx-modal-btn-confirm {\n font-weight: 600;\n}\n\n@media (prefers-color-scheme: dark) {\n .lx-modal-dialog { background: #2c2c2e; }\n .lx-modal-title { color: #f5f5f7; }\n .lx-modal-content { color: #ababab; }\n .lx-modal-body:has(.lx-modal-title:empty) .lx-modal-content {\n color: #f5f5f7;\n }\n .lx-modal-footer { border-top-color: #3a3a3c; }\n .lx-modal-btn:active { background: rgba(255,255,255,0.08); }\n .lx-modal-btn + .lx-modal-btn { border-left-color: #3a3a3c; }\n .lx-modal-btn-cancel { color: #ababab; }\n}\n");
|
|
10
|
+
document.head.appendChild(style);
|
|
11
|
+
}
|
|
12
|
+
export function showModal(params) {
|
|
13
|
+
var _a, _b, _c, _d, _e, _f;
|
|
14
|
+
var p = params;
|
|
15
|
+
var title = (_a = p === null || p === void 0 ? void 0 : p.title) !== null && _a !== void 0 ? _a : '';
|
|
16
|
+
var content = (_b = p === null || p === void 0 ? void 0 : p.content) !== null && _b !== void 0 ? _b : '';
|
|
17
|
+
var showCancel = (_c = p === null || p === void 0 ? void 0 : p.showCancel) !== null && _c !== void 0 ? _c : true;
|
|
18
|
+
var cancelText = (_d = p === null || p === void 0 ? void 0 : p.cancelText) !== null && _d !== void 0 ? _d : 'Cancel';
|
|
19
|
+
var cancelColor = p === null || p === void 0 ? void 0 : p.cancelColor;
|
|
20
|
+
var confirmText = (_e = p === null || p === void 0 ? void 0 : p.confirmText) !== null && _e !== void 0 ? _e : 'OK';
|
|
21
|
+
var confirmColor = (_f = p === null || p === void 0 ? void 0 : p.confirmColor) !== null && _f !== void 0 ? _f : '#007AFF';
|
|
22
|
+
var task = (activeModal !== null && activeModal !== void 0 ? activeModal : Promise.resolve()).then(function () { return renderModal(title, content, showCancel, cancelText, cancelColor, confirmText, confirmColor); }, function () { return renderModal(title, content, showCancel, cancelText, cancelColor, confirmText, confirmColor); });
|
|
23
|
+
activeModal = task;
|
|
24
|
+
return task;
|
|
25
|
+
}
|
|
26
|
+
function renderModal(title, content, showCancel, cancelText, cancelColor, confirmText, confirmColor) {
|
|
27
|
+
return new Promise(function (resolve) {
|
|
28
|
+
var dismissed = false;
|
|
29
|
+
ensureModalStyle();
|
|
30
|
+
var backdrop = document.createElement('div');
|
|
31
|
+
backdrop.className = 'lx-modal-backdrop';
|
|
32
|
+
var dialog = document.createElement('div');
|
|
33
|
+
dialog.className = 'lx-modal-dialog';
|
|
34
|
+
// Body
|
|
35
|
+
var body = document.createElement('div');
|
|
36
|
+
body.className = 'lx-modal-body';
|
|
37
|
+
var titleEl = document.createElement('div');
|
|
38
|
+
titleEl.className = 'lx-modal-title';
|
|
39
|
+
titleEl.textContent = title;
|
|
40
|
+
body.appendChild(titleEl);
|
|
41
|
+
if (content) {
|
|
42
|
+
var contentEl = document.createElement('p');
|
|
43
|
+
contentEl.className = 'lx-modal-content';
|
|
44
|
+
contentEl.textContent = content;
|
|
45
|
+
body.appendChild(contentEl);
|
|
46
|
+
}
|
|
47
|
+
dialog.appendChild(body);
|
|
48
|
+
// Footer
|
|
49
|
+
var footer = document.createElement('div');
|
|
50
|
+
footer.className = 'lx-modal-footer';
|
|
51
|
+
if (showCancel) {
|
|
52
|
+
var cancelBtn = document.createElement('button');
|
|
53
|
+
cancelBtn.className = 'lx-modal-btn lx-modal-btn-cancel';
|
|
54
|
+
cancelBtn.textContent = cancelText;
|
|
55
|
+
if (cancelColor)
|
|
56
|
+
cancelBtn.style.color = cancelColor;
|
|
57
|
+
cancelBtn.addEventListener('click', function () { return dismiss(false); });
|
|
58
|
+
footer.appendChild(cancelBtn);
|
|
59
|
+
}
|
|
60
|
+
var confirmBtn = document.createElement('button');
|
|
61
|
+
confirmBtn.className = 'lx-modal-btn lx-modal-btn-confirm';
|
|
62
|
+
confirmBtn.textContent = confirmText;
|
|
63
|
+
confirmBtn.style.color = confirmColor;
|
|
64
|
+
confirmBtn.addEventListener('click', function () { return dismiss(true); });
|
|
65
|
+
footer.appendChild(confirmBtn);
|
|
66
|
+
dialog.appendChild(footer);
|
|
67
|
+
backdrop.appendChild(dialog);
|
|
68
|
+
document.body.appendChild(backdrop);
|
|
69
|
+
// Trigger enter animation
|
|
70
|
+
requestAnimationFrame(function () {
|
|
71
|
+
backdrop.classList.add('lx-modal-visible');
|
|
72
|
+
});
|
|
73
|
+
function dismiss(confirmed) {
|
|
74
|
+
if (dismissed)
|
|
75
|
+
return;
|
|
76
|
+
dismissed = true;
|
|
77
|
+
backdrop.classList.remove('lx-modal-visible');
|
|
78
|
+
setTimeout(function () {
|
|
79
|
+
backdrop.remove();
|
|
80
|
+
resolve({ confirm: confirmed, cancel: !confirmed });
|
|
81
|
+
}, ANIMATION_MS);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
@@ -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
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* - Bridge initialization for native communication
|
|
6
6
|
* - Error UI rendering when page cannot be loaded
|
|
7
7
|
*/
|
|
8
|
-
export type { BridgeConfig, CallOptions, ChannelOpenOptions, BridgeErrorCode, ChannelEventName, DataSubscriber, ErrorInfo,
|
|
9
|
-
export { LingXiaBridge,
|
|
8
|
+
export type { BridgeConfig, CallOptions, ChannelCloseEvent, ChannelOptions, ChannelOpenOptions, BridgeErrorCode, ChannelEventName, DataSubscriber, ErrorInfo, LingXiaBridgeInterface, LxChannel, LxBridgeError, LxMethod, LxMethodParams, LxMethodResult, LxMethodStreamData, LxStream, NativeComponentMessage, NativeChannel, NativeError, NativeStream, NotifyOptions, InvokeOptions, StateInfo, StreamCallOptions, StreamOptions, StreamEventName, } from './types';
|
|
9
|
+
export { LingXiaBridge, channel, initBridge, invoke, notify, stream, } from './bridge';
|
|
10
|
+
export { isNativeError } from './invocation';
|
|
10
11
|
export { renderErrorUI, hasError, getErrorInfo } from './error';
|
|
11
12
|
export { boot, bootWhenReady } from './boot';
|
|
@@ -0,0 +1,14 @@
|
|
|
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 toNativeError(err: unknown): import("./types").NativeError;
|
|
10
|
+
export declare function isNativeError(error: unknown, code?: string): error is import("./types").NativeError;
|
|
11
|
+
export declare function resolveParams<T>(source?: ParamsSource<T>): T | undefined;
|
|
12
|
+
export declare function stableParamKey(value: unknown): string;
|
|
13
|
+
export declare function invokeMethod<TMethod extends (...args: any[]) => any>(method: TMethod, params: unknown): ReturnType<TMethod>;
|
|
14
|
+
export declare function getMethodKey(method: unknown): string | undefined;
|
package/dist/types.d.ts
CHANGED
|
@@ -31,6 +31,11 @@ export interface LxBridgeError {
|
|
|
31
31
|
message?: string;
|
|
32
32
|
data?: unknown;
|
|
33
33
|
}
|
|
34
|
+
export interface NativeError {
|
|
35
|
+
code: string;
|
|
36
|
+
message: string;
|
|
37
|
+
data?: unknown;
|
|
38
|
+
}
|
|
34
39
|
export interface StateInfo {
|
|
35
40
|
rev: number;
|
|
36
41
|
initial: boolean;
|
|
@@ -79,12 +84,11 @@ export interface LxStream<TData = unknown, TResult = unknown> extends AsyncItera
|
|
|
79
84
|
readonly id: string;
|
|
80
85
|
readonly result: Promise<TResult>;
|
|
81
86
|
}
|
|
82
|
-
export interface
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
[namespace: string]: unknown;
|
|
87
|
+
export interface NativeStream<TEvent = unknown, TResult = void> {
|
|
88
|
+
onEvent(listener: (event: TEvent) => void): () => void;
|
|
89
|
+
onError(listener: (error: NativeError) => void): () => void;
|
|
90
|
+
result: Promise<TResult>;
|
|
91
|
+
cancel(): void;
|
|
88
92
|
}
|
|
89
93
|
export interface LxChannel<TIn = unknown, TOut = TIn> extends AsyncIterable<TIn> {
|
|
90
94
|
send(payload: TOut): void;
|
|
@@ -95,9 +99,20 @@ export interface LxChannel<TIn = unknown, TOut = TIn> extends AsyncIterable<TIn>
|
|
|
95
99
|
[Symbol.asyncIterator](): AsyncIterator<TIn, void, void>;
|
|
96
100
|
readonly id: string;
|
|
97
101
|
}
|
|
102
|
+
export interface ChannelCloseEvent {
|
|
103
|
+
code?: string;
|
|
104
|
+
reason?: string;
|
|
105
|
+
}
|
|
106
|
+
export interface NativeChannel<TIn = unknown, TOut = unknown> {
|
|
107
|
+
send(message: TIn): void;
|
|
108
|
+
onMessage(listener: (message: TOut) => void): () => void;
|
|
109
|
+
onClose(listener: (event: ChannelCloseEvent) => void): () => void;
|
|
110
|
+
close(code?: string, reason?: string): void;
|
|
111
|
+
}
|
|
98
112
|
declare global {
|
|
99
113
|
interface Window {
|
|
100
114
|
__LX_BRIDGE_CFG?: BridgeConfig;
|
|
115
|
+
__LX_BRIDGE_INIT_STATE?: 'initializing' | 'initialized';
|
|
101
116
|
__LX_RUNTIME_CONFIG?: RuntimeConfig;
|
|
102
117
|
__pageBridge?: {
|
|
103
118
|
__names: string[];
|
|
@@ -113,7 +128,6 @@ declare global {
|
|
|
113
128
|
NativeComponentBridge?: {
|
|
114
129
|
postMessage: (message: string) => void;
|
|
115
130
|
};
|
|
116
|
-
host?: HostApi;
|
|
117
131
|
webkit?: {
|
|
118
132
|
messageHandlers: {
|
|
119
133
|
[key: string]: {
|
|
@@ -124,17 +138,14 @@ declare global {
|
|
|
124
138
|
}
|
|
125
139
|
}
|
|
126
140
|
export interface LingXiaBridgeInterface {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
141
|
+
invoke<TResult = unknown, TInput = void>(route: string, input?: TInput, options?: InvokeOptions): Promise<TResult>;
|
|
142
|
+
stream<TEvent = unknown, TResult = void, TInput = void>(route: string, input?: TInput, options?: StreamOptions): NativeStream<TEvent, TResult>;
|
|
143
|
+
notify<TInput = void>(route: string, input?: TInput, options?: NotifyOptions): void;
|
|
144
|
+
channel<TIn = unknown, TOut = unknown>(route: string, input?: unknown, options?: ChannelOptions): Promise<NativeChannel<TIn, TOut>>;
|
|
145
|
+
raw: LingXiaBridgeRawInterface;
|
|
132
146
|
state: {
|
|
133
147
|
subscribe(callback: DataSubscriber): () => void;
|
|
134
148
|
};
|
|
135
|
-
channel: {
|
|
136
|
-
open<TIn = unknown, TOut = TIn>(topic: string, params?: unknown, options?: ChannelOpenOptions): Promise<LxChannel<TIn, TOut>>;
|
|
137
|
-
};
|
|
138
149
|
_connectWebMessagePort(port: MessagePort): void;
|
|
139
150
|
_receiveEvaluateMessage(messageString: string): void;
|
|
140
151
|
debug: {
|
|
@@ -162,3 +173,19 @@ export interface LingXiaBridgeInterface {
|
|
|
162
173
|
};
|
|
163
174
|
isReady(): boolean;
|
|
164
175
|
}
|
|
176
|
+
export interface LingXiaBridgeRawInterface {
|
|
177
|
+
call(method: string, params?: unknown, options?: CallOptions): Promise<unknown>;
|
|
178
|
+
call<M extends LxMethod>(method: M, params?: LxMethodParams<M>, options?: CallOptions): Promise<LxMethodResult<M>>;
|
|
179
|
+
stream(method: string, params?: unknown, options?: StreamCallOptions): LxStream<unknown, unknown>;
|
|
180
|
+
stream<M extends LxMethod>(method: M, params?: LxMethodParams<M>, options?: StreamCallOptions): LxStream<LxMethodStreamData<M>, LxMethodResult<M>>;
|
|
181
|
+
notify(method: string, params?: unknown, options?: NotifyOptions): void;
|
|
182
|
+
channel: {
|
|
183
|
+
open<TIn = unknown, TOut = TIn>(topic: string, params?: unknown, options?: ChannelOpenOptions): Promise<LxChannel<TIn, TOut>>;
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
export interface InvokeOptions extends CallOptions {
|
|
187
|
+
}
|
|
188
|
+
export interface StreamOptions extends StreamCallOptions {
|
|
189
|
+
}
|
|
190
|
+
export interface ChannelOptions extends ChannelOpenOptions {
|
|
191
|
+
}
|
package/package.json
CHANGED
|
@@ -1,33 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingxia/bridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
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"
|