@lingxia/html 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/global.es2020.js +151 -0
- package/dist/global.es5.js +176 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
var LingXiaPage = (function(exports) {
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
//#region dist/__page_runtime_runtime__.js
|
|
4
|
+
let snapshot = {};
|
|
5
|
+
let stateInfo = {
|
|
6
|
+
rev: -1,
|
|
7
|
+
initial: true
|
|
8
|
+
};
|
|
9
|
+
let subscribed = false;
|
|
10
|
+
let subscribeRetryTimer = null;
|
|
11
|
+
let initialSnapshotResolved = false;
|
|
12
|
+
let snapshotRequestInFlight = false;
|
|
13
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
14
|
+
function notifyListeners() {
|
|
15
|
+
listeners.forEach((listener) => {
|
|
16
|
+
try {
|
|
17
|
+
listener();
|
|
18
|
+
} catch {}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function updateSnapshot(next, info) {
|
|
22
|
+
snapshot = next && typeof next === "object" ? next : {};
|
|
23
|
+
stateInfo = info;
|
|
24
|
+
notifyListeners();
|
|
25
|
+
}
|
|
26
|
+
function scheduleSubscribeRetry() {
|
|
27
|
+
if (subscribeRetryTimer !== null || subscribed) return;
|
|
28
|
+
subscribeRetryTimer = setTimeout(() => {
|
|
29
|
+
subscribeRetryTimer = null;
|
|
30
|
+
ensurePageBridgeSubscription();
|
|
31
|
+
}, 10);
|
|
32
|
+
}
|
|
33
|
+
function requestInitialSnapshot(bridge) {
|
|
34
|
+
if (initialSnapshotResolved || snapshotRequestInFlight) return;
|
|
35
|
+
if (!bridge?.call) return;
|
|
36
|
+
snapshotRequestInFlight = true;
|
|
37
|
+
bridge.call("state.getSnapshot", { scope: "page" }).then(() => {
|
|
38
|
+
initialSnapshotResolved = true;
|
|
39
|
+
}).catch(() => {
|
|
40
|
+
scheduleSubscribeRetry();
|
|
41
|
+
}).finally(() => {
|
|
42
|
+
snapshotRequestInFlight = false;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function ensurePageBridgeSubscription() {
|
|
46
|
+
if (subscribed) return;
|
|
47
|
+
const bridge = window.LingXiaBridge;
|
|
48
|
+
const subscribeState = bridge?.state?.subscribe;
|
|
49
|
+
if (!subscribeState) {
|
|
50
|
+
scheduleSubscribeRetry();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
subscribeState((next, info) => {
|
|
54
|
+
updateSnapshot(next, info);
|
|
55
|
+
});
|
|
56
|
+
subscribed = true;
|
|
57
|
+
requestInitialSnapshot(bridge);
|
|
58
|
+
}
|
|
59
|
+
function subscribePageSnapshot(listener) {
|
|
60
|
+
ensurePageBridgeSubscription();
|
|
61
|
+
listeners.add(listener);
|
|
62
|
+
return () => {
|
|
63
|
+
listeners.delete(listener);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function subscribePageData(callback) {
|
|
67
|
+
if (typeof callback !== "function") return () => {};
|
|
68
|
+
ensurePageBridgeSubscription();
|
|
69
|
+
if (stateInfo.rev >= 0) callback(snapshot, {
|
|
70
|
+
rev: stateInfo.rev,
|
|
71
|
+
initial: true
|
|
72
|
+
});
|
|
73
|
+
return subscribePageSnapshot(() => {
|
|
74
|
+
callback(snapshot, stateInfo);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function getPageSnapshot() {
|
|
78
|
+
ensurePageBridgeSubscription();
|
|
79
|
+
return snapshot;
|
|
80
|
+
}
|
|
81
|
+
function getPageActions() {
|
|
82
|
+
const actions = {};
|
|
83
|
+
const bridge = window.__pageBridge;
|
|
84
|
+
if (!bridge?.__names) return actions;
|
|
85
|
+
for (const name of bridge.__names) {
|
|
86
|
+
if (typeof name !== "string") continue;
|
|
87
|
+
const fn = getOrCreatePageAction(bridge, name);
|
|
88
|
+
if (typeof fn === "function") actions[name] = fn;
|
|
89
|
+
}
|
|
90
|
+
return actions;
|
|
91
|
+
}
|
|
92
|
+
function getPageStateInfo() {
|
|
93
|
+
return stateInfo;
|
|
94
|
+
}
|
|
95
|
+
function getOrCreatePageAction(bridge, name) {
|
|
96
|
+
const existing = bridge[name];
|
|
97
|
+
if (typeof existing === "function") return existing;
|
|
98
|
+
const created = definePageBridgeAction(name, resolvePageActionMode(bridge, name));
|
|
99
|
+
bridge[name] = created;
|
|
100
|
+
return created;
|
|
101
|
+
}
|
|
102
|
+
function resolvePageActionMode(bridge, name) {
|
|
103
|
+
const mode = bridge.__modes?.[name];
|
|
104
|
+
return mode === "call" || mode === "stream" ? mode : "notify";
|
|
105
|
+
}
|
|
106
|
+
function definePageBridgeAction(name, mode) {
|
|
107
|
+
function action(...args) {
|
|
108
|
+
const payload = filterPayload(name, args);
|
|
109
|
+
const bridge = window.LingXiaBridge;
|
|
110
|
+
if (!bridge) throw new Error(`LingXiaBridge is not ready for page action '${name}'`);
|
|
111
|
+
if (mode === "stream") {
|
|
112
|
+
const handle = bridge.stream(name, payload);
|
|
113
|
+
if (handle && handle.result && typeof handle.result.catch === "function") handle.result.catch((err) => {
|
|
114
|
+
console.warn(`[PageFunc] ${name} failed:`, err instanceof Error ? err.message : err);
|
|
115
|
+
});
|
|
116
|
+
return handle;
|
|
117
|
+
}
|
|
118
|
+
if (mode === "call") {
|
|
119
|
+
const promise = bridge.call(name, payload);
|
|
120
|
+
if (promise && typeof promise.catch === "function") promise.catch((err) => {
|
|
121
|
+
console.warn(`[PageFunc] ${name} failed:`, err instanceof Error ? err.message : err);
|
|
122
|
+
});
|
|
123
|
+
return promise;
|
|
124
|
+
}
|
|
125
|
+
bridge.notify(name, payload);
|
|
126
|
+
}
|
|
127
|
+
Object.assign(action, {
|
|
128
|
+
__logicFunc: true,
|
|
129
|
+
__funcName: name,
|
|
130
|
+
__bridgeMode: mode
|
|
131
|
+
});
|
|
132
|
+
return action;
|
|
133
|
+
}
|
|
134
|
+
function filterPayload(name, args) {
|
|
135
|
+
const clean = [];
|
|
136
|
+
for (const value of args) {
|
|
137
|
+
if (value instanceof Event) continue;
|
|
138
|
+
if (value && typeof value === "object" && "stopPropagation" in value && typeof value.stopPropagation === "function") continue;
|
|
139
|
+
clean.push(value);
|
|
140
|
+
}
|
|
141
|
+
if (clean.length > 1) throw new Error(`Page action '${name}' accepts at most one payload argument`);
|
|
142
|
+
return clean[0];
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
exports.getActions = getPageActions;
|
|
146
|
+
exports.getSnapshot = getPageSnapshot;
|
|
147
|
+
exports.getStateInfo = getPageStateInfo;
|
|
148
|
+
exports.subscribe = subscribePageData;
|
|
149
|
+
exports.subscribeSnapshot = subscribePageSnapshot;
|
|
150
|
+
return exports;
|
|
151
|
+
})({});
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
var LingXiaPage = (function (exports) {
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
//#region dist/__page_runtime_runtime__.js
|
|
4
|
+
var snapshot = {};
|
|
5
|
+
var stateInfo = {
|
|
6
|
+
rev: -1,
|
|
7
|
+
initial: true
|
|
8
|
+
};
|
|
9
|
+
var subscribed = false;
|
|
10
|
+
var subscribeRetryTimer = null;
|
|
11
|
+
var initialSnapshotResolved = false;
|
|
12
|
+
var snapshotRequestInFlight = false;
|
|
13
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
14
|
+
function notifyListeners() {
|
|
15
|
+
listeners.forEach(function (listener) {
|
|
16
|
+
try {
|
|
17
|
+
listener();
|
|
18
|
+
}
|
|
19
|
+
catch (_a) { }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function updateSnapshot(next, info) {
|
|
23
|
+
snapshot = next && typeof next === "object" ? next : {};
|
|
24
|
+
stateInfo = info;
|
|
25
|
+
notifyListeners();
|
|
26
|
+
}
|
|
27
|
+
function scheduleSubscribeRetry() {
|
|
28
|
+
if (subscribeRetryTimer !== null || subscribed)
|
|
29
|
+
return;
|
|
30
|
+
subscribeRetryTimer = setTimeout(function () {
|
|
31
|
+
subscribeRetryTimer = null;
|
|
32
|
+
ensurePageBridgeSubscription();
|
|
33
|
+
}, 10);
|
|
34
|
+
}
|
|
35
|
+
function requestInitialSnapshot(bridge) {
|
|
36
|
+
if (initialSnapshotResolved || snapshotRequestInFlight)
|
|
37
|
+
return;
|
|
38
|
+
if (!(bridge === null || bridge === void 0 ? void 0 : bridge.call))
|
|
39
|
+
return;
|
|
40
|
+
snapshotRequestInFlight = true;
|
|
41
|
+
bridge.call("state.getSnapshot", { scope: "page" }).then(function () {
|
|
42
|
+
initialSnapshotResolved = true;
|
|
43
|
+
}).catch(function () {
|
|
44
|
+
scheduleSubscribeRetry();
|
|
45
|
+
}).finally(function () {
|
|
46
|
+
snapshotRequestInFlight = false;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function ensurePageBridgeSubscription() {
|
|
50
|
+
var _a;
|
|
51
|
+
if (subscribed)
|
|
52
|
+
return;
|
|
53
|
+
var bridge = window.LingXiaBridge;
|
|
54
|
+
var subscribeState = (_a = bridge === null || bridge === void 0 ? void 0 : bridge.state) === null || _a === void 0 ? void 0 : _a.subscribe;
|
|
55
|
+
if (!subscribeState) {
|
|
56
|
+
scheduleSubscribeRetry();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
subscribeState(function (next, info) {
|
|
60
|
+
updateSnapshot(next, info);
|
|
61
|
+
});
|
|
62
|
+
subscribed = true;
|
|
63
|
+
requestInitialSnapshot(bridge);
|
|
64
|
+
}
|
|
65
|
+
function subscribePageSnapshot(listener) {
|
|
66
|
+
ensurePageBridgeSubscription();
|
|
67
|
+
listeners.add(listener);
|
|
68
|
+
return function () {
|
|
69
|
+
listeners.delete(listener);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function subscribePageData(callback) {
|
|
73
|
+
if (typeof callback !== "function")
|
|
74
|
+
return function () { };
|
|
75
|
+
ensurePageBridgeSubscription();
|
|
76
|
+
if (stateInfo.rev >= 0)
|
|
77
|
+
callback(snapshot, {
|
|
78
|
+
rev: stateInfo.rev,
|
|
79
|
+
initial: true
|
|
80
|
+
});
|
|
81
|
+
return subscribePageSnapshot(function () {
|
|
82
|
+
callback(snapshot, stateInfo);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function getPageSnapshot() {
|
|
86
|
+
ensurePageBridgeSubscription();
|
|
87
|
+
return snapshot;
|
|
88
|
+
}
|
|
89
|
+
function getPageActions() {
|
|
90
|
+
var actions = {};
|
|
91
|
+
var bridge = window.__pageBridge;
|
|
92
|
+
if (!(bridge === null || bridge === void 0 ? void 0 : bridge.__names))
|
|
93
|
+
return actions;
|
|
94
|
+
for (var _i = 0, _a = bridge.__names; _i < _a.length; _i++) {
|
|
95
|
+
var name = _a[_i];
|
|
96
|
+
if (typeof name !== "string")
|
|
97
|
+
continue;
|
|
98
|
+
var fn = getOrCreatePageAction(bridge, name);
|
|
99
|
+
if (typeof fn === "function")
|
|
100
|
+
actions[name] = fn;
|
|
101
|
+
}
|
|
102
|
+
return actions;
|
|
103
|
+
}
|
|
104
|
+
function getPageStateInfo() {
|
|
105
|
+
return stateInfo;
|
|
106
|
+
}
|
|
107
|
+
function getOrCreatePageAction(bridge, name) {
|
|
108
|
+
var existing = bridge[name];
|
|
109
|
+
if (typeof existing === "function")
|
|
110
|
+
return existing;
|
|
111
|
+
var created = definePageBridgeAction(name, resolvePageActionMode(bridge, name));
|
|
112
|
+
bridge[name] = created;
|
|
113
|
+
return created;
|
|
114
|
+
}
|
|
115
|
+
function resolvePageActionMode(bridge, name) {
|
|
116
|
+
var _a;
|
|
117
|
+
var mode = (_a = bridge.__modes) === null || _a === void 0 ? void 0 : _a[name];
|
|
118
|
+
return mode === "call" || mode === "stream" ? mode : "notify";
|
|
119
|
+
}
|
|
120
|
+
function definePageBridgeAction(name, mode) {
|
|
121
|
+
function action() {
|
|
122
|
+
var args = [];
|
|
123
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
124
|
+
args[_i] = arguments[_i];
|
|
125
|
+
}
|
|
126
|
+
var payload = filterPayload(name, args);
|
|
127
|
+
var bridge = window.LingXiaBridge;
|
|
128
|
+
if (!bridge)
|
|
129
|
+
throw new Error("LingXiaBridge is not ready for page action '".concat(name, "'"));
|
|
130
|
+
if (mode === "stream") {
|
|
131
|
+
var handle = bridge.stream(name, payload);
|
|
132
|
+
if (handle && handle.result && typeof handle.result.catch === "function")
|
|
133
|
+
handle.result.catch(function (err) {
|
|
134
|
+
console.warn("[PageFunc] ".concat(name, " failed:"), err instanceof Error ? err.message : err);
|
|
135
|
+
});
|
|
136
|
+
return handle;
|
|
137
|
+
}
|
|
138
|
+
if (mode === "call") {
|
|
139
|
+
var promise = bridge.call(name, payload);
|
|
140
|
+
if (promise && typeof promise.catch === "function")
|
|
141
|
+
promise.catch(function (err) {
|
|
142
|
+
console.warn("[PageFunc] ".concat(name, " failed:"), err instanceof Error ? err.message : err);
|
|
143
|
+
});
|
|
144
|
+
return promise;
|
|
145
|
+
}
|
|
146
|
+
bridge.notify(name, payload);
|
|
147
|
+
}
|
|
148
|
+
Object.assign(action, {
|
|
149
|
+
__logicFunc: true,
|
|
150
|
+
__funcName: name,
|
|
151
|
+
__bridgeMode: mode
|
|
152
|
+
});
|
|
153
|
+
return action;
|
|
154
|
+
}
|
|
155
|
+
function filterPayload(name, args) {
|
|
156
|
+
var clean = [];
|
|
157
|
+
for (var _i = 0, args_1 = args; _i < args_1.length; _i++) {
|
|
158
|
+
var value = args_1[_i];
|
|
159
|
+
if (value instanceof Event)
|
|
160
|
+
continue;
|
|
161
|
+
if (value && typeof value === "object" && "stopPropagation" in value && typeof value.stopPropagation === "function")
|
|
162
|
+
continue;
|
|
163
|
+
clean.push(value);
|
|
164
|
+
}
|
|
165
|
+
if (clean.length > 1)
|
|
166
|
+
throw new Error("Page action '".concat(name, "' accepts at most one payload argument"));
|
|
167
|
+
return clean[0];
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
170
|
+
exports.getActions = getPageActions;
|
|
171
|
+
exports.getSnapshot = getPageSnapshot;
|
|
172
|
+
exports.getStateInfo = getPageStateInfo;
|
|
173
|
+
exports.subscribe = subscribePageData;
|
|
174
|
+
exports.subscribeSnapshot = subscribePageSnapshot;
|
|
175
|
+
return exports;
|
|
176
|
+
})({});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getPageActions as getActions, getPageSnapshot as getSnapshot, getPageStateInfo as getStateInfo, subscribePageData as subscribe, subscribePageSnapshot as subscribeSnapshot, type ActionMap, type Snapshot, } from "@lingxia/page-runtime";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getPageActions as getActions, getPageSnapshot as getSnapshot, getPageStateInfo as getStateInfo, subscribePageData as subscribe, subscribePageSnapshot as subscribeSnapshot, } from "@lingxia/page-runtime";
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lingxia/html",
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "LingXia HTML runtime for lxapp pages",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./global": "./dist/global.es2020.js",
|
|
15
|
+
"./global/es5": "./dist/global.es5.js",
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "npm run clean && npm --prefix ../lingxia-bridge run build && npm --prefix ../lingxia-page-runtime run build && tsc -p tsconfig.json && node ./scripts/build-html-global.mjs",
|
|
20
|
+
"clean": "rm -rf dist",
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@lingxia/page-runtime": "0.5.1"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@lingxia/page-runtime": "file:../lingxia-page-runtime",
|
|
28
|
+
"rolldown": "^1.0.0-rc.13",
|
|
29
|
+
"typescript": "^5.7.2"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"registry": "https://registry.npmjs.org",
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/LingXia-Dev/LingXia.git",
|
|
41
|
+
"directory": "packages/lingxia-html"
|
|
42
|
+
},
|
|
43
|
+
"license": "MIT"
|
|
44
|
+
}
|