@qilin-agent/client-web 0.0.0-stage → 3.1.4
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/LICENSE +21 -0
- package/README.i18n.yaml +61 -0
- package/README.md +128 -2
- package/README.zh.md +129 -0
- package/lib/apply-injections.js +40 -0
- package/lib/base.css +106 -0
- package/lib/boot-page.module.css +103 -0
- package/lib/index.js +641 -0
- package/lib/types/apply-injections.d.ts +14 -0
- package/lib/types/boot-client.d.ts +38 -0
- package/lib/types/boot-page.d.ts +46 -0
- package/lib/types/boot.d.ts +32 -0
- package/lib/types/index.d.ts +12 -0
- package/lib/types/loader-status.d.ts +26 -0
- package/lib/types/mount.d.ts +18 -0
- package/lib/types/platform.d.ts +12 -0
- package/lib/types/seed.d.ts +6 -0
- package/lib/types/window-drag/recall.d.ts +25 -0
- package/lib/types/window-drag/regions.d.ts +71 -0
- package/package.json +55 -3
package/lib/index.js
ADDED
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
import * as Cordis from "@qilin-agent/kylin";
|
|
2
|
+
import { Context } from "@qilin-agent/kylin";
|
|
3
|
+
import Loader from "@qilin-agent/kylin-plugin-loader";
|
|
4
|
+
import css from "./boot-page.module.css";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import * as ReactJsxRuntime from "react/jsx-runtime";
|
|
7
|
+
import * as ReactDom from "react-dom";
|
|
8
|
+
import * as ReactDomClient from "react-dom/client";
|
|
9
|
+
import * as ClientStore from "@qilin-agent/client-store";
|
|
10
|
+
import * as UiSlots from "@qilin-agent/client-ui-slots";
|
|
11
|
+
import * as UiPrimitives from "@qilin-agent/client-ui-primitives";
|
|
12
|
+
import * as UiDockkit from "@qilin-agent/client-ui-dockkit";
|
|
13
|
+
import { DSH_PLATFORM_MODULE_ALIASES } from "@qilin-agent/dsh-compat";
|
|
14
|
+
import "./base.css";
|
|
15
|
+
//#region lib/types/loader-status.js
|
|
16
|
+
/**
|
|
17
|
+
* Value mirror of cordis's `FiberState` const enum: a const enum has no
|
|
18
|
+
* runtime object to import (and esbuild-based pipelines cannot inline it
|
|
19
|
+
* across modules), so these values mirror the pinned vendored definition
|
|
20
|
+
* while retaining its type (same rationale as qilin-tool-kylin's mirror).
|
|
21
|
+
*/
|
|
22
|
+
const FIBER_STATE = {
|
|
23
|
+
PENDING: 0,
|
|
24
|
+
LOADING: 1,
|
|
25
|
+
ACTIVE: 2,
|
|
26
|
+
FAILED: 3,
|
|
27
|
+
DISPOSED: 4,
|
|
28
|
+
UNLOADING: 5
|
|
29
|
+
};
|
|
30
|
+
/** Label for each fiber state, keyed by member (inlining-safe — no reverse mapping). */
|
|
31
|
+
const STATE_LABELS = {
|
|
32
|
+
[FIBER_STATE.PENDING]: "pending",
|
|
33
|
+
[FIBER_STATE.LOADING]: "loading",
|
|
34
|
+
[FIBER_STATE.ACTIVE]: "active",
|
|
35
|
+
[FIBER_STATE.FAILED]: "failed",
|
|
36
|
+
[FIBER_STATE.DISPOSED]: "disposed",
|
|
37
|
+
[FIBER_STATE.UNLOADING]: "unloading"
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region lib/types/boot-client.js
|
|
41
|
+
/**
|
|
42
|
+
* Compose the client: `ctx.plugin(Loader)`, `loader.internal = modules`, one
|
|
43
|
+
* `loader.create({ name })` per manifest row, `loader.await()`, then
|
|
44
|
+
* {@link assertEntriesActive}. A row whose module cannot be imported is marked
|
|
45
|
+
* failed; the Loader logs its import error and the audit rejects startup.
|
|
46
|
+
* @param options - context, module system, manifest, optional progress sink.
|
|
47
|
+
* @returns resolves after every entry is active; rejects with the audit report otherwise.
|
|
48
|
+
*/
|
|
49
|
+
async function bootClient(options) {
|
|
50
|
+
const { ctx, manifest, onEntryState } = options;
|
|
51
|
+
await ctx.plugin(Loader);
|
|
52
|
+
const loader = ctx.loader;
|
|
53
|
+
loader.internal = options.modules;
|
|
54
|
+
ctx.on("internal/status", (fiber) => {
|
|
55
|
+
const entry = fiber.entry;
|
|
56
|
+
if (entry === void 0 || entry.fiber === void 0) return;
|
|
57
|
+
onEntryState?.(entry.options.name, STATE_LABELS[entry.fiber.state]);
|
|
58
|
+
});
|
|
59
|
+
const rows = manifest.plugins.map((row) => row.id);
|
|
60
|
+
for (const name of rows) onEntryState?.(name, "loading");
|
|
61
|
+
await options.modules.entries.start(loader, manifest);
|
|
62
|
+
for (const entry of loader.entries()) if (entry.fiber === void 0) onEntryState?.(entry.options.name, "failed");
|
|
63
|
+
await loader.await();
|
|
64
|
+
assertEntriesActive(ctx);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* One retained Loader reason as text. An Error contributes its message, a
|
|
68
|
+
* string itself, and any other value its JSON form, so the audit never prints
|
|
69
|
+
* Object's default `[object Object]` spelling.
|
|
70
|
+
* @param reason - the value the failed fiber retained.
|
|
71
|
+
* @returns the message text.
|
|
72
|
+
*/
|
|
73
|
+
function reasonText(reason) {
|
|
74
|
+
if (reason instanceof Error) return reason.message;
|
|
75
|
+
if (reason === null) return "null";
|
|
76
|
+
if (typeof reason === "string") return reason;
|
|
77
|
+
if (typeof reason === "number" || typeof reason === "boolean" || typeof reason === "bigint" || typeof reason === "symbol") return String(reason);
|
|
78
|
+
if (typeof reason !== "object") return Object.prototype.toString.call(reason);
|
|
79
|
+
try {
|
|
80
|
+
return JSON.stringify(reason);
|
|
81
|
+
} catch {
|
|
82
|
+
return Object.prototype.toString.call(reason);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The reason a failed Loader fiber keeps for itself. The Loader holds it in a
|
|
87
|
+
* private field and logs it through a logger the browser composition does not
|
|
88
|
+
* mount, so the boot audit is the only place a report can read it.
|
|
89
|
+
* @param fiber - the entry's fiber.
|
|
90
|
+
* @returns a `: <message>` suffix, or an empty string when no reason is retained.
|
|
91
|
+
*/
|
|
92
|
+
function failureReason(fiber) {
|
|
93
|
+
const reason = fiber._error;
|
|
94
|
+
return reason === void 0 ? "" : `: ${reasonText(reason)}`;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Reject entries that failed import/apply or still wait on missing services.
|
|
98
|
+
* @param ctx - root Context carrying the Loader.
|
|
99
|
+
* @throws {Error} listing every non-active entry with its reason.
|
|
100
|
+
*/
|
|
101
|
+
function assertEntriesActive(ctx) {
|
|
102
|
+
const failures = [];
|
|
103
|
+
for (const entry of ctx.loader.entries()) {
|
|
104
|
+
const name = entry.options.name;
|
|
105
|
+
if (entry.fiber === void 0) {
|
|
106
|
+
failures.push(`${name}: import failed (see console for the import error)`);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const state = STATE_LABELS[entry.fiber.state];
|
|
110
|
+
if (state === "active") continue;
|
|
111
|
+
if (state === "pending") {
|
|
112
|
+
const missing = Object.keys(entry.fiber.inject).filter((service) => ctx.get(service) === void 0);
|
|
113
|
+
failures.push(`${name}: pending (waiting for service${missing.length === 1 ? "" : "s"}: ${missing.join(", ") || "unknown"})`);
|
|
114
|
+
} else failures.push(`${name}: ${state}${failureReason(entry.fiber)}`);
|
|
115
|
+
}
|
|
116
|
+
if (failures.length > 0) throw new Error(`web boot: ${String(failures.length)} entr${failures.length === 1 ? "y" : "ies"} did not activate\n${failures.join("\n")}`);
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region lib/types/boot-page.js
|
|
120
|
+
/** Create a div with one module class and optional text. */
|
|
121
|
+
function div(className, text) {
|
|
122
|
+
const el = document.createElement("div");
|
|
123
|
+
el.className = className ?? "";
|
|
124
|
+
if (text !== void 0) el.textContent = text;
|
|
125
|
+
return el;
|
|
126
|
+
}
|
|
127
|
+
/** Kernel-owned page mounted below the application's root element. */
|
|
128
|
+
var BootPage = class {
|
|
129
|
+
root;
|
|
130
|
+
card;
|
|
131
|
+
wordmark;
|
|
132
|
+
spinner;
|
|
133
|
+
hint;
|
|
134
|
+
states = /* @__PURE__ */ new Map();
|
|
135
|
+
active = /* @__PURE__ */ new Set();
|
|
136
|
+
total = 0;
|
|
137
|
+
failure;
|
|
138
|
+
/**
|
|
139
|
+
* Build and attach the boot page.
|
|
140
|
+
* @param container - Application mount point.
|
|
141
|
+
*/
|
|
142
|
+
constructor(container) {
|
|
143
|
+
this.root = div(css.boot);
|
|
144
|
+
this.root.dataset.qilinBoot = "";
|
|
145
|
+
this.card = div(css.card);
|
|
146
|
+
this.wordmark = div(css.wordmark, "QiLin");
|
|
147
|
+
this.spinner = div(css.spinner);
|
|
148
|
+
this.spinner.dataset.qilinBootSpinner = "";
|
|
149
|
+
this.hint = div(css.hint, "Loading plugins…");
|
|
150
|
+
this.card.append(this.wordmark, this.spinner, this.hint);
|
|
151
|
+
this.root.append(this.card);
|
|
152
|
+
container.append(this.root);
|
|
153
|
+
this.updateProgress();
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Set the number of loader entries represented by the progress arc.
|
|
157
|
+
* @param total - Complete boot roster size.
|
|
158
|
+
*/
|
|
159
|
+
setTotal(total) {
|
|
160
|
+
this.total = total;
|
|
161
|
+
this.updateProgress();
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Project one loader entry's fiber state.
|
|
165
|
+
* @param id - Loader entry name.
|
|
166
|
+
* @param state - Projected fiber state.
|
|
167
|
+
*/
|
|
168
|
+
setState(id, state) {
|
|
169
|
+
this.states.set(id, state);
|
|
170
|
+
if (state === "active") this.active.add(id);
|
|
171
|
+
this.updateProgress();
|
|
172
|
+
this.render();
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Display the boot failure report.
|
|
176
|
+
* @param message - Failure report text.
|
|
177
|
+
*/
|
|
178
|
+
fail(message) {
|
|
179
|
+
this.failure = message;
|
|
180
|
+
this.render();
|
|
181
|
+
}
|
|
182
|
+
/** Detach the page before or after the UI renderer takes the mount point. */
|
|
183
|
+
dispose() {
|
|
184
|
+
this.root.remove();
|
|
185
|
+
}
|
|
186
|
+
/** Redraw the state-dependent content below the wordmark. */
|
|
187
|
+
render() {
|
|
188
|
+
const failed = [...this.states].filter(([, state]) => state === "failed").map(([id]) => id);
|
|
189
|
+
if (this.failure === void 0 && failed.length === 0) {
|
|
190
|
+
if (this.spinner.parentElement !== this.card) this.card.replaceChildren(this.wordmark, this.spinner, this.hint);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const report = div(css.failed);
|
|
194
|
+
report.append(div(css.failedTitle, "Failed to load plugins"));
|
|
195
|
+
for (const id of failed) report.append(div(css.failedItem, id));
|
|
196
|
+
if (this.failure !== void 0) report.append(div(css.failedItem, this.failure));
|
|
197
|
+
this.card.replaceChildren(this.wordmark, report);
|
|
198
|
+
}
|
|
199
|
+
/** Grow the rotating arc monotonically as loader entries activate. */
|
|
200
|
+
updateProgress() {
|
|
201
|
+
const ratio = this.total === 0 ? 0 : Math.min(this.active.size / this.total, 1);
|
|
202
|
+
this.spinner.style.setProperty("--qilin-boot-arc", `${String(Math.round(72 + ratio * 216))}deg`);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region lib/types/mount.js
|
|
207
|
+
/**
|
|
208
|
+
* Mount the UI renderer into `container` through a dependency fiber on
|
|
209
|
+
* `uiRenderer`: the mount effect installs when the service is provided and
|
|
210
|
+
* reinstalls when it is replaced.
|
|
211
|
+
* @param ctx - booted root Context.
|
|
212
|
+
* @param container - application mount point.
|
|
213
|
+
* @returns resolves once the dependency fiber exists; with `uiRenderer`
|
|
214
|
+
* already provided (as after `bootClient`) the mount effect is installed by
|
|
215
|
+
* then, otherwise it installs when the service arrives.
|
|
216
|
+
*/
|
|
217
|
+
async function mountClient(ctx, container) {
|
|
218
|
+
await ctx.inject(["uiRenderer"], (scope) => {
|
|
219
|
+
scope.effect(() => scope.uiRenderer.mount(container), "web boot: application mount");
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region lib/types/seed.js
|
|
224
|
+
/**
|
|
225
|
+
* Platform-singleton module-table. These are the ONLY entities the shell
|
|
226
|
+
* shares into the frozen module table — fetch bundles resolve their externals
|
|
227
|
+
* against exactly this set through the loader's require. Keys come from the
|
|
228
|
+
* platform constant module ({@link ./platform.ts}, the single source
|
|
229
|
+
* of truth with the tsdown client externals); values stay shell-static
|
|
230
|
+
* imports so every bundle sees the same instance.
|
|
231
|
+
*/
|
|
232
|
+
/**
|
|
233
|
+
* Build the static table handed to the module loader at boot.
|
|
234
|
+
* @returns module specifier → exported entity (one entry per platform word).
|
|
235
|
+
*/
|
|
236
|
+
function getStaticModules() {
|
|
237
|
+
const modules = {
|
|
238
|
+
"react": React,
|
|
239
|
+
"react/jsx-runtime": ReactJsxRuntime,
|
|
240
|
+
"react-dom": ReactDom,
|
|
241
|
+
"react-dom/client": ReactDomClient,
|
|
242
|
+
"@qilin-agent/kylin": Cordis,
|
|
243
|
+
"@qilin-agent/client-store": ClientStore,
|
|
244
|
+
"@qilin-agent/client-ui-slots": UiSlots,
|
|
245
|
+
"@qilin-agent/client-ui-primitives": UiPrimitives,
|
|
246
|
+
"@qilin-agent/client-ui-dockkit": UiDockkit
|
|
247
|
+
};
|
|
248
|
+
for (const [alias, canonical] of Object.entries(DSH_PLATFORM_MODULE_ALIASES)) modules[alias] = modules[canonical];
|
|
249
|
+
return modules;
|
|
250
|
+
}
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region lib/types/window-drag/regions.js
|
|
253
|
+
/**
|
|
254
|
+
* The window drag-region contract for the macOS desktop shell: Electron hands
|
|
255
|
+
* the page's `-webkit-app-region` boxes to the native window, which hit-tests
|
|
256
|
+
* them by geometry in DOM order, ignoring stacking. The property does not inherit:
|
|
257
|
+
* Blink collects one box per element whose own computed value is not `none`,
|
|
258
|
+
* skipping subtrees that are not visible, and the window applies them in that
|
|
259
|
+
* order: `drag` adds geometry, `no-drag` removes it. The composition is therefore
|
|
260
|
+
* equivalent to "the last matching box decides" — a point is draggable when the
|
|
261
|
+
* last collected box containing it is `drag`.
|
|
262
|
+
*
|
|
263
|
+
* This module is the executable statement of that rule. Production CSS authors
|
|
264
|
+
* the boxes; tests and the browser coverage scenario both decide points through
|
|
265
|
+
* this module so a claim about coverage has one meaning.
|
|
266
|
+
*/
|
|
267
|
+
/**
|
|
268
|
+
* The attribute a chrome row puts on the element that owns its window drag.
|
|
269
|
+
* ui-web `base.css` turns the mark into the one darwin drag rule, so the row's
|
|
270
|
+
* own box is the window's draggable geometry.
|
|
271
|
+
*/
|
|
272
|
+
const DRAG_MARK = "data-window-drag";
|
|
273
|
+
/**
|
|
274
|
+
* The attribute the shell sets for one frame to make Electron recollect the
|
|
275
|
+
* window's drag rects (electron#32341). While it is set, ui-web `base.css`
|
|
276
|
+
* subtracts the marked box; the row marks inside it still declare drag and win in
|
|
277
|
+
* document order, so the mark's only effect is that app-region values changed.
|
|
278
|
+
*/
|
|
279
|
+
const RECALL_MARK = "data-window-drag-recall";
|
|
280
|
+
[
|
|
281
|
+
"button",
|
|
282
|
+
"a",
|
|
283
|
+
"input",
|
|
284
|
+
"select",
|
|
285
|
+
"textarea",
|
|
286
|
+
"summary",
|
|
287
|
+
"[contenteditable='true']",
|
|
288
|
+
"[tabindex]",
|
|
289
|
+
"[role='dialog']",
|
|
290
|
+
"[role='alertdialog']",
|
|
291
|
+
"[role='menu']",
|
|
292
|
+
"[role='listbox']",
|
|
293
|
+
"[role='tooltip']",
|
|
294
|
+
"[role='button']",
|
|
295
|
+
"[role='link']",
|
|
296
|
+
"[role='tab']",
|
|
297
|
+
"[role='menuitem']",
|
|
298
|
+
"[role='menuitemcheckbox']",
|
|
299
|
+
"[role='menuitemradio']",
|
|
300
|
+
"[role='option']",
|
|
301
|
+
"[role='checkbox']",
|
|
302
|
+
"[role='radio']",
|
|
303
|
+
"[role='switch']",
|
|
304
|
+
"[role='slider']",
|
|
305
|
+
"[role='combobox']",
|
|
306
|
+
"[role='textbox']"
|
|
307
|
+
].join(", ");
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region lib/types/window-drag/recall.js
|
|
310
|
+
/**
|
|
311
|
+
* Window drag recollection for the macOS desktop shell. Electron rebuilds the
|
|
312
|
+
* window's `-webkit-app-region` rects only when a style pass changes a computed
|
|
313
|
+
* app-region value (electron#32341), and Blink skips hidden boxes when it collects
|
|
314
|
+
* them, so a chrome row that appears, moves, or disappears without such a change
|
|
315
|
+
* leaves the native window holding the previous geometry: a press inside the row
|
|
316
|
+
* drags from where it used to be, and a row that slid under the pointer keeps its
|
|
317
|
+
* controls unreachable or its blank runs undraggable. This module owns the one
|
|
318
|
+
* watcher that closes that gap, so no chrome row has to know the trap.
|
|
319
|
+
*
|
|
320
|
+
* A row's viewport box is the measurement: every row in this composition shows and
|
|
321
|
+
* hides by mounting, unmounting, or moving, so a changed box is the signal. The
|
|
322
|
+
* watcher starts on a DOM change that touches a marked row — inside it, on it, on
|
|
323
|
+
* an ancestor that holds one, on a container it lives in, or adding or removing one
|
|
324
|
+
* — on a marked row's box resizing, or on a transition or animation starting on an
|
|
325
|
+
* element that holds one, and then measures every marked row once per frame for as
|
|
326
|
+
* long as any box keeps changing. Each frame that changed sets the recall mark, and
|
|
327
|
+
* the frame that finds the same geometry clears it and stops once the short grace
|
|
328
|
+
* window below has passed: that clear is the collection the steady state comes from.
|
|
329
|
+
* @module @qilin-agent/client-web/src/window-drag/recall
|
|
330
|
+
*/
|
|
331
|
+
/** The selector of an element that owns a window drag region. */
|
|
332
|
+
const ROW_SELECTOR = `[${DRAG_MARK}]`;
|
|
333
|
+
/**
|
|
334
|
+
* Quiet frames a report tolerates before the loop stops again. A CSS transition's
|
|
335
|
+
* first frame still reports the box's from-value, so a report that arrives before
|
|
336
|
+
* the surface starts moving must not end the loop on its first unchanged sample.
|
|
337
|
+
*/
|
|
338
|
+
const GRACE_FRAMES = 2;
|
|
339
|
+
/** The event types that mark a box starting or finishing a transition or animation. */
|
|
340
|
+
const MOTION_EVENTS = [
|
|
341
|
+
"transitionstart",
|
|
342
|
+
"transitionend",
|
|
343
|
+
"animationstart",
|
|
344
|
+
"animationend"
|
|
345
|
+
];
|
|
346
|
+
/**
|
|
347
|
+
* Watch the window's marked drag rows and pulse the recall mark whenever their
|
|
348
|
+
* geometry can have moved. Installs nothing outside the darwin platform, where no
|
|
349
|
+
* app-region rule exists.
|
|
350
|
+
* @param options - the document to watch and the two scheduling seams.
|
|
351
|
+
* @returns a disposer that stops watching, drops any pending frame, and clears the mark.
|
|
352
|
+
*/
|
|
353
|
+
function installWindowDragRecall(options) {
|
|
354
|
+
const doc = options.document;
|
|
355
|
+
if (doc.documentElement.dataset.platform !== "darwin") return () => {};
|
|
356
|
+
const scheduleFrame = options.scheduleFrame ?? defaultScheduleFrame;
|
|
357
|
+
const watchBox = options.watchBox ?? defaultWatchBox;
|
|
358
|
+
/** The last frame's measurement per row, the baseline a change is read against. */
|
|
359
|
+
let geometry = /* @__PURE__ */ new Map();
|
|
360
|
+
/** One box watcher per row currently rendered. */
|
|
361
|
+
const boxes = /* @__PURE__ */ new Map();
|
|
362
|
+
let scheduled = false;
|
|
363
|
+
let disposed = false;
|
|
364
|
+
let cancelPending;
|
|
365
|
+
/** Quiet frames left before the loop may stop; refreshed by every report. */
|
|
366
|
+
let grace = 0;
|
|
367
|
+
/**
|
|
368
|
+
* Measure every marked row and pulse when any box differs from the last frame's.
|
|
369
|
+
* Runs once per frame while the surface keeps moving.
|
|
370
|
+
*/
|
|
371
|
+
const measure = () => {
|
|
372
|
+
doc.body.removeAttribute(RECALL_MARK);
|
|
373
|
+
const rows = Array.from(doc.querySelectorAll(ROW_SELECTOR));
|
|
374
|
+
watchBoxes(rows);
|
|
375
|
+
const next = new Map(rows.map((row) => [row, readBox(row)]));
|
|
376
|
+
const moved = rows.length !== geometry.size || rows.some((row) => geometry.get(row) !== next.get(row));
|
|
377
|
+
geometry = next;
|
|
378
|
+
if (moved) {
|
|
379
|
+
doc.body.setAttribute(RECALL_MARK, "");
|
|
380
|
+
grace = 0;
|
|
381
|
+
schedule();
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (grace === 0) return;
|
|
385
|
+
grace -= 1;
|
|
386
|
+
schedule();
|
|
387
|
+
};
|
|
388
|
+
/** Report that the surface may be moving, opening the grace window again. */
|
|
389
|
+
const arm = () => {
|
|
390
|
+
grace = GRACE_FRAMES;
|
|
391
|
+
schedule();
|
|
392
|
+
};
|
|
393
|
+
/** Schedule one frame, keeping at most one pending. */
|
|
394
|
+
const schedule = () => {
|
|
395
|
+
if (scheduled) return;
|
|
396
|
+
scheduled = true;
|
|
397
|
+
cancelPending = scheduleFrame(() => {
|
|
398
|
+
scheduled = false;
|
|
399
|
+
cancelPending = void 0;
|
|
400
|
+
if (disposed) return;
|
|
401
|
+
measure();
|
|
402
|
+
});
|
|
403
|
+
};
|
|
404
|
+
/** Keep one box watcher per live row, re-watching when its frame moves or unmounts. */
|
|
405
|
+
const watchBoxes = (rows) => {
|
|
406
|
+
for (const [row, dispose] of boxes) {
|
|
407
|
+
if (rows.includes(row)) continue;
|
|
408
|
+
dispose();
|
|
409
|
+
boxes.delete(row);
|
|
410
|
+
}
|
|
411
|
+
for (const row of rows) {
|
|
412
|
+
if (boxes.has(row)) continue;
|
|
413
|
+
boxes.set(row, watchBox(row, arm));
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
/**
|
|
417
|
+
* Whether a motion event can be moving a marked row: the transitioning element is
|
|
418
|
+
* one, holds one, or lives inside one.
|
|
419
|
+
* @param target - the event target to classify.
|
|
420
|
+
* @returns true when the drag surface has to be re-measured.
|
|
421
|
+
*/
|
|
422
|
+
const movesRows = (target) => {
|
|
423
|
+
if (!(target instanceof Element)) return false;
|
|
424
|
+
return target.closest(ROW_SELECTOR) !== null || target.querySelector(ROW_SELECTOR) !== null;
|
|
425
|
+
};
|
|
426
|
+
/** Re-arm for a transition or animation that can be sliding a marked row. */
|
|
427
|
+
const onMotion = (event) => {
|
|
428
|
+
if (movesRows(event.target)) arm();
|
|
429
|
+
};
|
|
430
|
+
const observer = new MutationObserver((records) => {
|
|
431
|
+
if (records.some((record) => touchesRows(record, geometry.keys()))) arm();
|
|
432
|
+
});
|
|
433
|
+
observer.observe(doc.body, {
|
|
434
|
+
subtree: true,
|
|
435
|
+
childList: true,
|
|
436
|
+
attributes: true,
|
|
437
|
+
characterData: true
|
|
438
|
+
});
|
|
439
|
+
for (const type of MOTION_EVENTS) doc.addEventListener(type, onMotion, true);
|
|
440
|
+
arm();
|
|
441
|
+
return () => {
|
|
442
|
+
disposed = true;
|
|
443
|
+
observer.disconnect();
|
|
444
|
+
for (const type of MOTION_EVENTS) doc.removeEventListener(type, onMotion, true);
|
|
445
|
+
if (cancelPending !== void 0) cancelPending();
|
|
446
|
+
for (const dispose of boxes.values()) dispose();
|
|
447
|
+
boxes.clear();
|
|
448
|
+
geometry.clear();
|
|
449
|
+
doc.body.removeAttribute(RECALL_MARK);
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
/** The box a row owns this frame, in viewport pixels. */
|
|
453
|
+
function readBox(row) {
|
|
454
|
+
const rect = row.getBoundingClientRect();
|
|
455
|
+
return `${rect.x},${rect.y},${rect.width},${rect.height}`;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Whether one DOM change can have moved the drag surface: a child list change in a
|
|
459
|
+
* container that holds a marked row, or an attribute or text change that lands on a
|
|
460
|
+
* marked row, inside one, or on an element holding one (a panel's open flag, a
|
|
461
|
+
* column's width). A child list change in a container without a marked row is left
|
|
462
|
+
* alone — a row whose box grows because its content did is a resize, which the box
|
|
463
|
+
* watcher reports — and so is a mounted overlay, whose own app-region value is a
|
|
464
|
+
* change of its own.
|
|
465
|
+
* @param record - the mutation record to classify.
|
|
466
|
+
* @param rows - the rows the last frame measured.
|
|
467
|
+
* @returns true when the drag surface has to be re-measured.
|
|
468
|
+
*/
|
|
469
|
+
function touchesRows(record, rows) {
|
|
470
|
+
if (record.attributeName === "data-window-drag-recall") return false;
|
|
471
|
+
for (const node of [...record.addedNodes, ...record.removedNodes]) if (node instanceof Element && (node.matches(ROW_SELECTOR) || node.querySelector(ROW_SELECTOR) !== null)) return true;
|
|
472
|
+
const target = record.target instanceof Element ? record.target : record.target.parentElement;
|
|
473
|
+
/* v8 ignore next -- the observer watches body's subtree, so a text target always has a parent element. */
|
|
474
|
+
if (target === null) return false;
|
|
475
|
+
if (record.type === "childList") {
|
|
476
|
+
for (const row of rows) if (target.contains(row)) return true;
|
|
477
|
+
return false;
|
|
478
|
+
}
|
|
479
|
+
return target.closest(ROW_SELECTOR) !== null || target.querySelector(ROW_SELECTOR) !== null;
|
|
480
|
+
}
|
|
481
|
+
/** Schedule one frame through the browser's animation frame queue. */
|
|
482
|
+
function defaultScheduleFrame(frame) {
|
|
483
|
+
const handle = requestAnimationFrame(frame);
|
|
484
|
+
return () => {
|
|
485
|
+
cancelAnimationFrame(handle);
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
/** Watch one row's border box where the document has a `ResizeObserver`. */
|
|
489
|
+
function defaultWatchBox(row, changed) {
|
|
490
|
+
if (typeof ResizeObserver !== "function") return () => {};
|
|
491
|
+
const observer = new ResizeObserver(changed);
|
|
492
|
+
observer.observe(row);
|
|
493
|
+
return () => {
|
|
494
|
+
observer.disconnect();
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
//#endregion
|
|
498
|
+
//#region lib/types/boot.js
|
|
499
|
+
/**
|
|
500
|
+
* Web boot kernel. It owns only the module system, Cordis loader, and a
|
|
501
|
+
* framework-free boot page; plugin composition and the renderer handoff are
|
|
502
|
+
* `bootClient` and `mountClient`. The dynamic UI renderer receives the mount
|
|
503
|
+
* point after every client entry activates.
|
|
504
|
+
* @module @qilin-agent/client-web/src/boot
|
|
505
|
+
*/
|
|
506
|
+
/** Browser boot entry consumed by `apps/web`. */
|
|
507
|
+
var AppWebEntry = class {
|
|
508
|
+
container;
|
|
509
|
+
seams;
|
|
510
|
+
page;
|
|
511
|
+
ctx;
|
|
512
|
+
stopDragRecall;
|
|
513
|
+
modules;
|
|
514
|
+
manifest;
|
|
515
|
+
/**
|
|
516
|
+
* Draw the boot page; {@link run} starts the loader.
|
|
517
|
+
* @param container - Application mount point.
|
|
518
|
+
* @param seams - Optional module transport replacement.
|
|
519
|
+
*/
|
|
520
|
+
constructor(container, seams) {
|
|
521
|
+
this.container = container;
|
|
522
|
+
this.seams = seams;
|
|
523
|
+
this.page = new BootPage(container);
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Load and activate every client entry, then hand the mount point to the
|
|
527
|
+
* UI renderer. Plugin failures remain visible on the boot page.
|
|
528
|
+
* @param onFailure - Optional carrier-owned fatal presentation; keeps the boot page visible.
|
|
529
|
+
* @returns Resolves after application mount or failure reporting.
|
|
530
|
+
*/
|
|
531
|
+
async run(onFailure) {
|
|
532
|
+
try {
|
|
533
|
+
await globalThis.__QILIN_BOOT_READY__?.promise;
|
|
534
|
+
const win = globalThis;
|
|
535
|
+
const moduleLoader = win.__ModuleLoader__;
|
|
536
|
+
if (moduleLoader === void 0) throw new Error("web boot: window.__ModuleLoader__ bootstrap facade is missing");
|
|
537
|
+
const transport = globalThis.__QILIN_TRANSPORT__;
|
|
538
|
+
this.modules = moduleLoader.create({
|
|
539
|
+
boot: win.__QILIN_BOOT__,
|
|
540
|
+
staticModules: getStaticModules(),
|
|
541
|
+
...transport?.loadBundle === void 0 ? {} : { loadBundle: transport.loadBundle },
|
|
542
|
+
...this.seams
|
|
543
|
+
});
|
|
544
|
+
this.manifest = this.modules.manifest;
|
|
545
|
+
const prefetching = this.prefetchImmediateTier();
|
|
546
|
+
const ctx = new Context();
|
|
547
|
+
this.ctx = ctx;
|
|
548
|
+
this.page.setTotal(this.manifest.plugins.length);
|
|
549
|
+
await prefetching;
|
|
550
|
+
await bootClient({
|
|
551
|
+
ctx,
|
|
552
|
+
modules: this.modules,
|
|
553
|
+
manifest: this.manifest,
|
|
554
|
+
onEntryState: (name, state) => {
|
|
555
|
+
if (onFailure === void 0 || state !== "failed") this.page.setState(name, state);
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
this.stopDragRecall = installWindowDragRecall({ document: this.container.ownerDocument });
|
|
559
|
+
await mountClient(ctx, this.container);
|
|
560
|
+
} catch (reason) {
|
|
561
|
+
console.error(reason);
|
|
562
|
+
if (onFailure !== void 0) onFailure(reason);
|
|
563
|
+
else this.page.fail(reason instanceof Error ? reason.message : String(reason));
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
/** Dispose the client plugin tree and whichever page owns the mount point. */
|
|
567
|
+
async dispose() {
|
|
568
|
+
this.stopDragRecall?.();
|
|
569
|
+
this.stopDragRecall = void 0;
|
|
570
|
+
const ctx = this.ctx;
|
|
571
|
+
this.ctx = void 0;
|
|
572
|
+
if (ctx !== void 0) await ctx.fiber.dispose();
|
|
573
|
+
this.page.dispose();
|
|
574
|
+
}
|
|
575
|
+
/** Prefetch stage-one bundles and their dynamic requests before concurrent plugin imports. */
|
|
576
|
+
async prefetchImmediateTier() {
|
|
577
|
+
await Promise.all(this.manifest.plugins.filter((row) => row.immediately).map((row) => this.modules.prefetch(row.id).catch((_prefetchError) => {})));
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
//#endregion
|
|
581
|
+
//#region lib/types/platform.js
|
|
582
|
+
/**
|
|
583
|
+
* Shared browser platform modules. Seeding, bundling externals, and Vite
|
|
584
|
+
* aliases consume this list so their module identities cannot drift.
|
|
585
|
+
* @module @qilin-agent/client-web/src/platform
|
|
586
|
+
*/
|
|
587
|
+
/** The module specifiers the shell shares into the frozen module table. */
|
|
588
|
+
const PLATFORM_MODULES = [
|
|
589
|
+
"react",
|
|
590
|
+
"react/jsx-runtime",
|
|
591
|
+
"react-dom",
|
|
592
|
+
"react-dom/client",
|
|
593
|
+
"@qilin-agent/kylin",
|
|
594
|
+
"@qilin-agent/client-store",
|
|
595
|
+
"@qilin-agent/client-ui-slots",
|
|
596
|
+
"@qilin-agent/client-ui-primitives",
|
|
597
|
+
"@qilin-agent/client-ui-dockkit"
|
|
598
|
+
];
|
|
599
|
+
/** Client-bundle specifiers whose factories the parser preloads before the shell starts. */
|
|
600
|
+
const PRELOADED_CLIENT_EXTERNALS = [];
|
|
601
|
+
//#endregion
|
|
602
|
+
//#region lib/types/apply-injections.js
|
|
603
|
+
function assertNever(row) {
|
|
604
|
+
throw new Error(`web boot: unknown index injection row ${JSON.stringify(row)}`);
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Execute every row in table order.
|
|
608
|
+
* @param rows - Injection table from the boot payload.
|
|
609
|
+
* @param loadScript - Executes one script-src row through the page owner's asset transport.
|
|
610
|
+
*/
|
|
611
|
+
async function applyIndexInjections(rows, loadScript) {
|
|
612
|
+
for (const row of rows) switch (row.kind) {
|
|
613
|
+
case "global":
|
|
614
|
+
globalThis[row.name] = row.value;
|
|
615
|
+
break;
|
|
616
|
+
case "script": {
|
|
617
|
+
const el = document.createElement("script");
|
|
618
|
+
el.textContent = row.text;
|
|
619
|
+
(row.placement === "head" ? document.head : document.body).append(el);
|
|
620
|
+
break;
|
|
621
|
+
}
|
|
622
|
+
case "script-src":
|
|
623
|
+
await loadScript(row.src);
|
|
624
|
+
break;
|
|
625
|
+
case "script-preload": break;
|
|
626
|
+
case "style": {
|
|
627
|
+
const el = document.createElement("style");
|
|
628
|
+
el.textContent = row.text;
|
|
629
|
+
document.head.append(el);
|
|
630
|
+
break;
|
|
631
|
+
}
|
|
632
|
+
case "html":
|
|
633
|
+
(row.placement === "head" ? document.head : document.body).insertAdjacentHTML("beforeend", row.html);
|
|
634
|
+
break;
|
|
635
|
+
default: assertNever(row);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
//#endregion
|
|
639
|
+
export { AppWebEntry, PLATFORM_MODULES, PRELOADED_CLIENT_EXTERNALS, applyIndexInjections, getStaticModules };
|
|
640
|
+
|
|
641
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page-side interpreter for the structured index injection table. The served
|
|
3
|
+
* form renders the same rows into index.html text; a static worker page has
|
|
4
|
+
* no served HTML, so it executes the table directly. Rows execute strictly in
|
|
5
|
+
* table order, so a global row lands before the scripts that read it.
|
|
6
|
+
*/
|
|
7
|
+
import type { IndexInjection } from '@qilin-agent/host-webserver';
|
|
8
|
+
/**
|
|
9
|
+
* Execute every row in table order.
|
|
10
|
+
* @param rows - Injection table from the boot payload.
|
|
11
|
+
* @param loadScript - Executes one script-src row through the page owner's asset transport.
|
|
12
|
+
*/
|
|
13
|
+
export declare function applyIndexInjections(rows: readonly IndexInjection[], loadScript: (src: string) => Promise<void>): Promise<void>;
|
|
14
|
+
//# sourceMappingURL=apply-injections.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Production client composition without the page: mount the Loader over a
|
|
3
|
+
* module system, create every manifest row, wait for quiescence, and audit
|
|
4
|
+
* activation. `AppWebEntry` and the whole-client test carrier both call it.
|
|
5
|
+
* @module @qilin-agent/client-web/src/boot-client
|
|
6
|
+
*/
|
|
7
|
+
import type { Context } from '@qilin-agent/kylin';
|
|
8
|
+
import type { BootManifest, ClientModuleLoader } from '@qilin-agent/client-modules/client';
|
|
9
|
+
import { STATE_LABELS } from './loader-status.ts';
|
|
10
|
+
/** Entry state label as the boot page renders it. */
|
|
11
|
+
export type EntryStateLabel = (typeof STATE_LABELS)[keyof typeof STATE_LABELS] | 'loading' | 'failed';
|
|
12
|
+
/** Inputs of {@link bootClient}. */
|
|
13
|
+
export interface ClientBootOptions {
|
|
14
|
+
/** Fresh root Context that will own the plugin tree. */
|
|
15
|
+
readonly ctx: Context;
|
|
16
|
+
/** Module system installed as `loader.internal`. */
|
|
17
|
+
readonly modules: ClientModuleLoader;
|
|
18
|
+
/** Parsed manifest whose `plugins` rows become Loader entries (entry name = row id). */
|
|
19
|
+
readonly manifest: BootManifest;
|
|
20
|
+
/** Per-entry state reporting (the boot page); omitted when no one renders progress. */
|
|
21
|
+
readonly onEntryState?: (name: string, state: EntryStateLabel) => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Compose the client: `ctx.plugin(Loader)`, `loader.internal = modules`, one
|
|
25
|
+
* `loader.create({ name })` per manifest row, `loader.await()`, then
|
|
26
|
+
* {@link assertEntriesActive}. A row whose module cannot be imported is marked
|
|
27
|
+
* failed; the Loader logs its import error and the audit rejects startup.
|
|
28
|
+
* @param options - context, module system, manifest, optional progress sink.
|
|
29
|
+
* @returns resolves after every entry is active; rejects with the audit report otherwise.
|
|
30
|
+
*/
|
|
31
|
+
export declare function bootClient(options: ClientBootOptions): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Reject entries that failed import/apply or still wait on missing services.
|
|
34
|
+
* @param ctx - root Context carrying the Loader.
|
|
35
|
+
* @throws {Error} listing every non-active entry with its reason.
|
|
36
|
+
*/
|
|
37
|
+
export declare function assertEntriesActive(ctx: Context): void;
|
|
38
|
+
//# sourceMappingURL=boot-client.d.ts.map
|