@wavelo/async 0.0.0-stage → 0.9.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/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/action-button.d.ts +12 -0
- package/dist/action-button.js +53 -0
- package/dist/ai-stream.d.ts +24 -0
- package/dist/ai-stream.js +54 -0
- package/dist/angular.d.ts +26 -0
- package/dist/angular.js +35 -0
- package/dist/announcer.d.ts +33 -0
- package/dist/announcer.js +102 -0
- package/dist/boundary.d.ts +37 -0
- package/dist/boundary.js +147 -0
- package/dist/controller.d.ts +7 -0
- package/dist/controller.js +363 -0
- package/dist/dom.d.ts +35 -0
- package/dist/dom.js +243 -0
- package/dist/export-tool.d.ts +38 -0
- package/dist/export-tool.js +89 -0
- package/dist/group.d.ts +65 -0
- package/dist/group.js +235 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +3 -0
- package/dist/innovation-progress.d.ts +101 -0
- package/dist/innovation-progress.js +276 -0
- package/dist/innovation-session.d.ts +70 -0
- package/dist/innovation-session.js +130 -0
- package/dist/innovation-ui.d.ts +55 -0
- package/dist/innovation-ui.js +122 -0
- package/dist/react.d.ts +17 -0
- package/dist/react.js +166 -0
- package/dist/registry-ext.d.ts +24 -0
- package/dist/registry-ext.js +41 -0
- package/dist/router.d.ts +25 -0
- package/dist/router.js +47 -0
- package/dist/runtime.d.ts +40 -0
- package/dist/runtime.js +140 -0
- package/dist/schema.d.ts +108 -0
- package/dist/schema.js +56 -0
- package/dist/skeleton.d.ts +53 -0
- package/dist/skeleton.js +152 -0
- package/dist/stages.d.ts +69 -0
- package/dist/stages.js +206 -0
- package/dist/svelte.d.ts +27 -0
- package/dist/svelte.js +44 -0
- package/dist/testing.d.ts +10 -0
- package/dist/testing.js +45 -0
- package/dist/themes.d.ts +29 -0
- package/dist/themes.js +66 -0
- package/dist/transfer.d.ts +57 -0
- package/dist/transfer.js +165 -0
- package/dist/types.d.ts +63 -0
- package/dist/types.js +1 -0
- package/dist/vue.d.ts +26 -0
- package/dist/vue.js +53 -0
- package/dist/web-components.d.ts +2 -0
- package/dist/web-components.js +22 -0
- package/package.json +157 -4
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stall explanation & recovery monitor (F35).
|
|
3
|
+
* Distinguishes elapsed slowness from lack of observed progress updates.
|
|
4
|
+
*/
|
|
5
|
+
export function createStallMonitor(controller, options = {}) {
|
|
6
|
+
const stallTimeoutMs = Math.max(100, options.stallTimeoutMs ?? 5000);
|
|
7
|
+
const scheduler = options.scheduler ?? {
|
|
8
|
+
setTimeout: (fn, ms) => globalThis.setTimeout(fn, ms),
|
|
9
|
+
clearTimeout: (id) => globalThis.clearTimeout(id),
|
|
10
|
+
now: () => Date.now()
|
|
11
|
+
};
|
|
12
|
+
let timer = null;
|
|
13
|
+
let lastOpId = -1;
|
|
14
|
+
let lastProgressVal;
|
|
15
|
+
let snapshot = { stalled: false, reason: undefined, deadlineMs: undefined };
|
|
16
|
+
const listeners = new Set();
|
|
17
|
+
const emit = (next) => {
|
|
18
|
+
snapshot = next;
|
|
19
|
+
for (const l of [...listeners])
|
|
20
|
+
l(snapshot);
|
|
21
|
+
};
|
|
22
|
+
const clearTimer = () => {
|
|
23
|
+
if (timer !== null) {
|
|
24
|
+
scheduler.clearTimeout(timer);
|
|
25
|
+
timer = null;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const arm = (opId) => {
|
|
29
|
+
clearTimer();
|
|
30
|
+
timer = scheduler.setTimeout(() => {
|
|
31
|
+
timer = null;
|
|
32
|
+
const snap = controller.getSnapshot();
|
|
33
|
+
if (snap.pending && snap.operationId === opId) {
|
|
34
|
+
emit({
|
|
35
|
+
stalled: true,
|
|
36
|
+
reason: snapshot.reason ?? 'Progress updates not received',
|
|
37
|
+
deadlineMs: snapshot.deadlineMs
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}, stallTimeoutMs);
|
|
41
|
+
};
|
|
42
|
+
// Initialize from the controller's current state: an operation that is already
|
|
43
|
+
// pending (frozen) when the monitor is constructed starts its observation
|
|
44
|
+
// window now instead of waiting for a future emission that may never arrive.
|
|
45
|
+
const initial = controller.getSnapshot();
|
|
46
|
+
lastOpId = initial.operationId;
|
|
47
|
+
lastProgressVal = initial.progress.value;
|
|
48
|
+
if (initial.pending && !initial.disposed) {
|
|
49
|
+
arm(initial.operationId);
|
|
50
|
+
}
|
|
51
|
+
const unsub = controller.subscribe((snap) => {
|
|
52
|
+
if (!snap.pending) {
|
|
53
|
+
clearTimer();
|
|
54
|
+
if (snapshot.stalled || snapshot.reason !== undefined) {
|
|
55
|
+
emit({ stalled: false, reason: undefined, deadlineMs: undefined });
|
|
56
|
+
}
|
|
57
|
+
lastOpId = snap.operationId;
|
|
58
|
+
lastProgressVal = snap.progress.value;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (snap.operationId !== lastOpId) {
|
|
62
|
+
lastOpId = snap.operationId;
|
|
63
|
+
lastProgressVal = snap.progress.value;
|
|
64
|
+
emit({ stalled: false, reason: undefined, deadlineMs: undefined });
|
|
65
|
+
arm(snap.operationId);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (snap.progress.value !== lastProgressVal) {
|
|
69
|
+
lastProgressVal = snap.progress.value;
|
|
70
|
+
if (snapshot.stalled)
|
|
71
|
+
emit({ stalled: false, reason: undefined, deadlineMs: undefined });
|
|
72
|
+
arm(snap.operationId);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return {
|
|
76
|
+
getSnapshot: () => snapshot,
|
|
77
|
+
subscribe(listener) {
|
|
78
|
+
listeners.add(listener);
|
|
79
|
+
return () => listeners.delete(listener);
|
|
80
|
+
},
|
|
81
|
+
setReason(reason, deadlineMs) {
|
|
82
|
+
emit({ stalled: true, reason, deadlineMs });
|
|
83
|
+
},
|
|
84
|
+
dispose() {
|
|
85
|
+
clearTimer();
|
|
86
|
+
unsub();
|
|
87
|
+
listeners.clear();
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Worker progress bridge (F36).
|
|
93
|
+
* Validates versioned envelopes, rejects stale operationIds and out-of-order seq
|
|
94
|
+
* numbers, coalesces progress updates to a bounded application rate, and never
|
|
95
|
+
* starts or disposes the application-owned controller as a side effect.
|
|
96
|
+
* Construction bridges the supplied operation or the controller's current pending
|
|
97
|
+
* operation; when neither exists, messages are rejected until `attach()` binds one.
|
|
98
|
+
* Transport cancellation is surfaced as an explicit request event rather than
|
|
99
|
+
* pretended to be acknowledged: only an inbound `cancel` envelope settles the
|
|
100
|
+
* operation as cancelled. Releasing the bridge removes port listeners and timers
|
|
101
|
+
* only — the application's worker, controller, and in-flight operation survive.
|
|
102
|
+
*/
|
|
103
|
+
export function createWorkerProgressBridge(port, controller, options = {}) {
|
|
104
|
+
const scheduler = options.scheduler ?? {
|
|
105
|
+
setTimeout: (fn, ms) => globalThis.setTimeout(fn, ms),
|
|
106
|
+
clearTimeout: (id) => globalThis.clearTimeout(id),
|
|
107
|
+
now: () => Date.now()
|
|
108
|
+
};
|
|
109
|
+
const coalesceMs = options.coalesceMs !== undefined && Number.isFinite(options.coalesceMs) && options.coalesceMs >= 0
|
|
110
|
+
? options.coalesceMs
|
|
111
|
+
: 50;
|
|
112
|
+
let op = options.operation ?? controller.getCurrentOperation();
|
|
113
|
+
let lastSeq = 0;
|
|
114
|
+
let cancelRequested = false;
|
|
115
|
+
let buffered = null;
|
|
116
|
+
let coalesceTimer = null;
|
|
117
|
+
const cancelListeners = new Set();
|
|
118
|
+
const clearCoalesce = () => {
|
|
119
|
+
if (coalesceTimer !== null) {
|
|
120
|
+
scheduler.clearTimeout(coalesceTimer);
|
|
121
|
+
coalesceTimer = null;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const flushBuffer = () => {
|
|
125
|
+
clearCoalesce();
|
|
126
|
+
if (buffered && op?.isCurrent()) {
|
|
127
|
+
op.setProgress(buffered.value, buffered.max);
|
|
128
|
+
}
|
|
129
|
+
buffered = null;
|
|
130
|
+
};
|
|
131
|
+
const discardBuffer = () => {
|
|
132
|
+
clearCoalesce();
|
|
133
|
+
buffered = null;
|
|
134
|
+
};
|
|
135
|
+
const classifyMessage = (raw) => {
|
|
136
|
+
if (raw.type === 'progress' && typeof raw.value === 'number' && Number.isFinite(raw.value)) {
|
|
137
|
+
const max = typeof raw.max === 'number' && Number.isFinite(raw.max) && raw.max > 0 ? raw.max : undefined;
|
|
138
|
+
return { kind: 'progress', value: raw.value, max };
|
|
139
|
+
}
|
|
140
|
+
if (raw.type === 'complete')
|
|
141
|
+
return { kind: 'complete' };
|
|
142
|
+
if (raw.type === 'error')
|
|
143
|
+
return { kind: 'error' };
|
|
144
|
+
if (raw.type === 'cancel')
|
|
145
|
+
return { kind: 'cancel' };
|
|
146
|
+
return null;
|
|
147
|
+
};
|
|
148
|
+
const onMessage = (event) => {
|
|
149
|
+
const raw = event.data;
|
|
150
|
+
if (!raw || typeof raw !== 'object' || raw.v !== 1)
|
|
151
|
+
return;
|
|
152
|
+
if (!op)
|
|
153
|
+
return;
|
|
154
|
+
if (typeof raw.operationId !== 'number' || raw.operationId !== op.id)
|
|
155
|
+
return;
|
|
156
|
+
if (typeof raw.seq !== 'number' || !Number.isInteger(raw.seq) || raw.seq <= lastSeq)
|
|
157
|
+
return;
|
|
158
|
+
const message = classifyMessage(raw);
|
|
159
|
+
if (!message)
|
|
160
|
+
return;
|
|
161
|
+
// Commit the sequence number only after the envelope is recognized as valid.
|
|
162
|
+
lastSeq = raw.seq;
|
|
163
|
+
if (message.kind === 'progress') {
|
|
164
|
+
buffered = { value: message.value, max: message.max };
|
|
165
|
+
if (coalesceMs === 0) {
|
|
166
|
+
flushBuffer();
|
|
167
|
+
}
|
|
168
|
+
else if (coalesceTimer === null) {
|
|
169
|
+
coalesceTimer = scheduler.setTimeout(() => {
|
|
170
|
+
coalesceTimer = null;
|
|
171
|
+
flushBuffer();
|
|
172
|
+
}, coalesceMs);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else if (message.kind === 'complete') {
|
|
176
|
+
flushBuffer();
|
|
177
|
+
op.succeed();
|
|
178
|
+
op = null;
|
|
179
|
+
cancelRequested = false;
|
|
180
|
+
}
|
|
181
|
+
else if (message.kind === 'error') {
|
|
182
|
+
discardBuffer();
|
|
183
|
+
op.fail(new Error('Worker reported operation error'));
|
|
184
|
+
op = null;
|
|
185
|
+
cancelRequested = false;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
// Inbound acknowledgement (or worker-initiated cancellation): the transport
|
|
189
|
+
// is now known-cancelled, so settle locally and clear the pending request.
|
|
190
|
+
discardBuffer();
|
|
191
|
+
op.cancel();
|
|
192
|
+
op = null;
|
|
193
|
+
cancelRequested = false;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
port.addEventListener('message', onMessage);
|
|
197
|
+
return {
|
|
198
|
+
get operationId() {
|
|
199
|
+
return op ? op.id : null;
|
|
200
|
+
},
|
|
201
|
+
get cancelRequested() {
|
|
202
|
+
return cancelRequested;
|
|
203
|
+
},
|
|
204
|
+
attach(operation) {
|
|
205
|
+
discardBuffer();
|
|
206
|
+
lastSeq = 0;
|
|
207
|
+
cancelRequested = false;
|
|
208
|
+
op = operation ?? controller.getCurrentOperation();
|
|
209
|
+
return op ? op.id : null;
|
|
210
|
+
},
|
|
211
|
+
flush: flushBuffer,
|
|
212
|
+
requestCancel() {
|
|
213
|
+
cancelRequested = true;
|
|
214
|
+
const request = { operationId: op ? op.id : null };
|
|
215
|
+
if (options.onCancelRequest)
|
|
216
|
+
options.onCancelRequest(request);
|
|
217
|
+
for (const listener of [...cancelListeners])
|
|
218
|
+
listener(request);
|
|
219
|
+
},
|
|
220
|
+
onCancelRequest(listener) {
|
|
221
|
+
cancelListeners.add(listener);
|
|
222
|
+
return () => cancelListeners.delete(listener);
|
|
223
|
+
},
|
|
224
|
+
dispose() {
|
|
225
|
+
port.removeEventListener('message', onMessage);
|
|
226
|
+
clearCoalesce();
|
|
227
|
+
buffered = null;
|
|
228
|
+
cancelListeners.clear();
|
|
229
|
+
// Ownership stays with the application: no controller.dispose(), no op.cancel().
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Truthful progress smoother (F42).
|
|
235
|
+
* Interpolates displayValue toward the latest confirmed value without ever exceeding it,
|
|
236
|
+
* snapping immediately on reset/lower values and disabling smoothing under reduced motion.
|
|
237
|
+
*/
|
|
238
|
+
export function createTruthfulSmoother(options = {}) {
|
|
239
|
+
const stepFactor = Math.min(1, Math.max(0.05, options.stepFactor ?? 0.35));
|
|
240
|
+
let confirmedValue;
|
|
241
|
+
let displayValue;
|
|
242
|
+
return {
|
|
243
|
+
getDisplayValue: () => displayValue,
|
|
244
|
+
getConfirmedValue: () => confirmedValue,
|
|
245
|
+
push(nextValue) {
|
|
246
|
+
if (nextValue === undefined || !Number.isFinite(nextValue)) {
|
|
247
|
+
confirmedValue = undefined;
|
|
248
|
+
displayValue = undefined;
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
confirmedValue = nextValue;
|
|
252
|
+
if (options.reducedMotion || displayValue === undefined || nextValue < displayValue) {
|
|
253
|
+
displayValue = nextValue;
|
|
254
|
+
return displayValue;
|
|
255
|
+
}
|
|
256
|
+
const nextDisplay = displayValue + (nextValue - displayValue) * stepFactor;
|
|
257
|
+
displayValue = Math.min(nextValue, Math.round(nextDisplay * 100) / 100);
|
|
258
|
+
return displayValue;
|
|
259
|
+
},
|
|
260
|
+
tick() {
|
|
261
|
+
if (confirmedValue === undefined || displayValue === undefined)
|
|
262
|
+
return displayValue;
|
|
263
|
+
if (options.reducedMotion || displayValue >= confirmedValue) {
|
|
264
|
+
displayValue = confirmedValue;
|
|
265
|
+
return displayValue;
|
|
266
|
+
}
|
|
267
|
+
const delta = confirmedValue - displayValue;
|
|
268
|
+
displayValue = delta < 0.1 ? confirmedValue : Math.min(confirmedValue, displayValue + delta * stepFactor);
|
|
269
|
+
return displayValue;
|
|
270
|
+
},
|
|
271
|
+
reset() {
|
|
272
|
+
confirmedValue = undefined;
|
|
273
|
+
displayValue = undefined;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { LoadingController, LoadingStatus } from './types.js';
|
|
2
|
+
import type { FakeClock } from './testing.js';
|
|
3
|
+
export interface HandoffSnapshot {
|
|
4
|
+
v: 1;
|
|
5
|
+
jobRef: string;
|
|
6
|
+
stageId?: string;
|
|
7
|
+
percent?: number;
|
|
8
|
+
userScope?: string;
|
|
9
|
+
expiresAt: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Long-running job presentation handoff (F37).
|
|
13
|
+
* Stores only opaque jobRef, known stage, and expiry — never Promises, timers, tokens, or payloads.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createHandoffSnapshot(input: {
|
|
16
|
+
jobRef: string;
|
|
17
|
+
stageId?: string;
|
|
18
|
+
percent?: number;
|
|
19
|
+
userScope?: string;
|
|
20
|
+
ttlMs?: number;
|
|
21
|
+
now?: () => number;
|
|
22
|
+
}): string;
|
|
23
|
+
export declare function restoreHandoffSnapshot(raw: string, options?: {
|
|
24
|
+
userScope?: string;
|
|
25
|
+
now?: () => number;
|
|
26
|
+
}): (HandoffSnapshot & {
|
|
27
|
+
state: 'reconnecting';
|
|
28
|
+
}) | null;
|
|
29
|
+
export interface TraceEvent {
|
|
30
|
+
deltaMs: number;
|
|
31
|
+
operationId: number;
|
|
32
|
+
status: LoadingStatus;
|
|
33
|
+
percent?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface SessionTrace {
|
|
36
|
+
v: 1;
|
|
37
|
+
truncated: boolean;
|
|
38
|
+
events: readonly TraceEvent[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Loading-session record and deterministic replay (F38).
|
|
42
|
+
* Captures bounded state/progress transitions without payloads or URLs.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createSessionRecorder(controller: LoadingController, options?: {
|
|
45
|
+
maxEvents?: number;
|
|
46
|
+
now?: () => number;
|
|
47
|
+
}): {
|
|
48
|
+
stop(): SessionTrace;
|
|
49
|
+
};
|
|
50
|
+
export declare function replaySession(trace: SessionTrace, clock: FakeClock): LoadingStatus[];
|
|
51
|
+
export interface CalibrationRecommendation {
|
|
52
|
+
operationClass: string;
|
|
53
|
+
sampleCount: number;
|
|
54
|
+
p50Ms: number;
|
|
55
|
+
p90Ms: number;
|
|
56
|
+
suggestedShowDelayMs: number;
|
|
57
|
+
suggestedSlowThresholdMs: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Local timing calibration report (F39).
|
|
61
|
+
* Separates completed vs cancelled/failed samples and omits recommendations below minSamples.
|
|
62
|
+
*/
|
|
63
|
+
export declare function createTimingCalibrator(options?: {
|
|
64
|
+
minSamples?: number;
|
|
65
|
+
maxSamples?: number;
|
|
66
|
+
}): {
|
|
67
|
+
record(operationClass: string, durationMs: number, outcome: "success" | "error" | "cancelled"): void;
|
|
68
|
+
recommend(operationClass: string): CalibrationRecommendation | null;
|
|
69
|
+
clear(): void;
|
|
70
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { createLoadingController } from './controller.js';
|
|
2
|
+
/**
|
|
3
|
+
* Long-running job presentation handoff (F37).
|
|
4
|
+
* Stores only opaque jobRef, known stage, and expiry — never Promises, timers, tokens, or payloads.
|
|
5
|
+
*/
|
|
6
|
+
export function createHandoffSnapshot(input) {
|
|
7
|
+
const now = input.now ?? (() => Date.now());
|
|
8
|
+
const snapshot = {
|
|
9
|
+
v: 1,
|
|
10
|
+
jobRef: String(input.jobRef),
|
|
11
|
+
...(input.stageId ? { stageId: String(input.stageId) } : {}),
|
|
12
|
+
...(typeof input.percent === 'number' && Number.isFinite(input.percent) ? { percent: input.percent } : {}),
|
|
13
|
+
...(input.userScope ? { userScope: String(input.userScope) } : {}),
|
|
14
|
+
expiresAt: now() + Math.max(1000, input.ttlMs ?? 300_000)
|
|
15
|
+
};
|
|
16
|
+
return JSON.stringify(snapshot);
|
|
17
|
+
}
|
|
18
|
+
export function restoreHandoffSnapshot(raw, options = {}) {
|
|
19
|
+
const now = options.now ?? (() => Date.now());
|
|
20
|
+
try {
|
|
21
|
+
const parsed = JSON.parse(raw);
|
|
22
|
+
if (!parsed || parsed.v !== 1 || typeof parsed.jobRef !== 'string' || typeof parsed.expiresAt !== 'number') {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (now() > parsed.expiresAt)
|
|
26
|
+
return null;
|
|
27
|
+
if (options.userScope && parsed.userScope !== options.userScope)
|
|
28
|
+
return null;
|
|
29
|
+
return { ...parsed, state: 'reconnecting' };
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Loading-session record and deterministic replay (F38).
|
|
37
|
+
* Captures bounded state/progress transitions without payloads or URLs.
|
|
38
|
+
*/
|
|
39
|
+
export function createSessionRecorder(controller, options = {}) {
|
|
40
|
+
const maxEvents = Math.max(1, options.maxEvents ?? 200);
|
|
41
|
+
const now = options.now ?? (() => Date.now());
|
|
42
|
+
const events = [];
|
|
43
|
+
let lastAt = now();
|
|
44
|
+
let truncated = false;
|
|
45
|
+
const unsub = controller.subscribe((snap) => {
|
|
46
|
+
if (events.length >= maxEvents) {
|
|
47
|
+
truncated = true;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const t = now();
|
|
51
|
+
events.push({
|
|
52
|
+
deltaMs: Math.max(0, t - lastAt),
|
|
53
|
+
operationId: snap.operationId,
|
|
54
|
+
status: snap.status,
|
|
55
|
+
...(snap.progress.percent !== undefined ? { percent: snap.progress.percent } : {})
|
|
56
|
+
});
|
|
57
|
+
lastAt = t;
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
stop() {
|
|
61
|
+
unsub();
|
|
62
|
+
return { v: 1, truncated, events: [...events] };
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export function replaySession(trace, clock) {
|
|
67
|
+
const ctrl = createLoadingController({ scheduler: clock });
|
|
68
|
+
const observed = [];
|
|
69
|
+
let activeOp = null;
|
|
70
|
+
for (const evt of trace.events) {
|
|
71
|
+
clock.advance(evt.deltaMs);
|
|
72
|
+
if (evt.status === 'pending' && (!activeOp || !activeOp.isCurrent())) {
|
|
73
|
+
activeOp = ctrl.start();
|
|
74
|
+
}
|
|
75
|
+
else if (evt.status === 'pending' && evt.percent !== undefined && activeOp) {
|
|
76
|
+
activeOp.setProgress(evt.percent, 100);
|
|
77
|
+
}
|
|
78
|
+
else if (evt.status === 'success' && activeOp) {
|
|
79
|
+
activeOp.succeed();
|
|
80
|
+
}
|
|
81
|
+
else if (evt.status === 'error' && activeOp) {
|
|
82
|
+
activeOp.fail(new Error('replayed error'));
|
|
83
|
+
}
|
|
84
|
+
else if (evt.status === 'cancelled' && activeOp) {
|
|
85
|
+
activeOp.cancel();
|
|
86
|
+
}
|
|
87
|
+
observed.push(ctrl.getSnapshot().status);
|
|
88
|
+
}
|
|
89
|
+
ctrl.dispose();
|
|
90
|
+
return observed;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Local timing calibration report (F39).
|
|
94
|
+
* Separates completed vs cancelled/failed samples and omits recommendations below minSamples.
|
|
95
|
+
*/
|
|
96
|
+
export function createTimingCalibrator(options = {}) {
|
|
97
|
+
const minSamples = Math.max(3, options.minSamples ?? 5);
|
|
98
|
+
const maxSamples = Math.max(minSamples, options.maxSamples ?? 200);
|
|
99
|
+
const samples = new Map();
|
|
100
|
+
return {
|
|
101
|
+
record(operationClass, durationMs, outcome) {
|
|
102
|
+
if (outcome !== 'success' || !Number.isFinite(durationMs) || durationMs < 0)
|
|
103
|
+
return;
|
|
104
|
+
const list = samples.get(operationClass) ?? [];
|
|
105
|
+
if (list.length >= maxSamples)
|
|
106
|
+
list.shift();
|
|
107
|
+
list.push(durationMs);
|
|
108
|
+
samples.set(operationClass, list);
|
|
109
|
+
},
|
|
110
|
+
recommend(operationClass) {
|
|
111
|
+
const list = samples.get(operationClass);
|
|
112
|
+
if (!list || list.length < minSamples)
|
|
113
|
+
return null;
|
|
114
|
+
const sorted = [...list].sort((a, b) => a - b);
|
|
115
|
+
const p50Ms = sorted[Math.floor(sorted.length * 0.5)];
|
|
116
|
+
const p90Ms = sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * 0.9))];
|
|
117
|
+
return {
|
|
118
|
+
operationClass,
|
|
119
|
+
sampleCount: sorted.length,
|
|
120
|
+
p50Ms,
|
|
121
|
+
p90Ms,
|
|
122
|
+
suggestedShowDelayMs: Math.min(250, Math.round(p50Ms * 0.5)),
|
|
123
|
+
suggestedSlowThresholdMs: Math.max(500, Math.round(p90Ms * 1.5))
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
clear() {
|
|
127
|
+
samples.clear();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export type RegionStatus = 'loading' | 'ready' | 'error';
|
|
2
|
+
export interface PartialRevealRegion {
|
|
3
|
+
key: string;
|
|
4
|
+
skeletonHtml: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Partial-data skeleton reveal (F33).
|
|
8
|
+
* Updates individual keyed regions in place without remounting the parent container,
|
|
9
|
+
* preserving existing input/focus state in ready sibling regions.
|
|
10
|
+
*
|
|
11
|
+
* Security: `skeletonHtml`, `readyHtml` and `errorHtml` are written to `innerHTML`
|
|
12
|
+
* without sanitization. Applications must pass only trusted, application-owned markup.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createPartialReveal(container: HTMLElement, regions: readonly PartialRevealRegion[], options?: {
|
|
15
|
+
reducedMotion?: boolean;
|
|
16
|
+
}): {
|
|
17
|
+
getState: (key: string) => RegionStatus | undefined;
|
|
18
|
+
reveal(key: string, readyHtml: string): void;
|
|
19
|
+
fail(key: string, errorHtml: string): void;
|
|
20
|
+
resetRegion(key: string): void;
|
|
21
|
+
};
|
|
22
|
+
export type AttentionPriority = 'foreground' | 'normal' | 'background';
|
|
23
|
+
export interface AttentionItem {
|
|
24
|
+
id: string;
|
|
25
|
+
priority?: AttentionPriority;
|
|
26
|
+
focusOwned?: boolean;
|
|
27
|
+
hasActionableError?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface AttentionSnapshot {
|
|
30
|
+
visibleIds: readonly string[];
|
|
31
|
+
hiddenIds: readonly string[];
|
|
32
|
+
hiddenCount: number;
|
|
33
|
+
summaryLabel: string | undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Loading attention coordinator (F34).
|
|
37
|
+
* Arbitrates presentation visibility across simultaneous operations without hiding
|
|
38
|
+
* failures, focus-owned items, or underlying task state.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createAttentionCoordinator(options?: {
|
|
41
|
+
maxVisible?: number;
|
|
42
|
+
}): {
|
|
43
|
+
register(item: AttentionItem): AttentionSnapshot;
|
|
44
|
+
unregister(id: string): AttentionSnapshot;
|
|
45
|
+
evaluate: () => AttentionSnapshot;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* RTL and mixed-script loading layout helper (F40).
|
|
49
|
+
* Sets logical HTML `dir` and `<bdi>` isolation without altering animation `direction`.
|
|
50
|
+
*/
|
|
51
|
+
export declare function applyRtlLayout(element: HTMLElement, options: {
|
|
52
|
+
dir: 'rtl' | 'ltr' | 'auto';
|
|
53
|
+
progressMirrored?: boolean;
|
|
54
|
+
captionText?: string;
|
|
55
|
+
}): void;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Partial-data skeleton reveal (F33).
|
|
3
|
+
* Updates individual keyed regions in place without remounting the parent container,
|
|
4
|
+
* preserving existing input/focus state in ready sibling regions.
|
|
5
|
+
*
|
|
6
|
+
* Security: `skeletonHtml`, `readyHtml` and `errorHtml` are written to `innerHTML`
|
|
7
|
+
* without sanitization. Applications must pass only trusted, application-owned markup.
|
|
8
|
+
*/
|
|
9
|
+
export function createPartialReveal(container, regions, options = {}) {
|
|
10
|
+
const states = new Map();
|
|
11
|
+
const skeletons = new Map();
|
|
12
|
+
for (const r of regions) {
|
|
13
|
+
if (states.has(r.key))
|
|
14
|
+
throw new Error(`Duplicate partial-reveal region: ${r.key}`);
|
|
15
|
+
states.set(r.key, 'loading');
|
|
16
|
+
skeletons.set(r.key, r.skeletonHtml);
|
|
17
|
+
}
|
|
18
|
+
if (options.reducedMotion) {
|
|
19
|
+
container.setAttribute('data-wavelo-motion', 'always');
|
|
20
|
+
}
|
|
21
|
+
const findRegion = (key) => {
|
|
22
|
+
if (!states.has(key))
|
|
23
|
+
throw new Error(`Unknown partial-reveal region: ${key}`);
|
|
24
|
+
return Array.from(container.querySelectorAll('[data-wavelo-region]')).find((element) => element.getAttribute('data-wavelo-region') === key) ?? null;
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
getState: (key) => states.get(key),
|
|
28
|
+
reveal(key, readyHtml) {
|
|
29
|
+
const el = findRegion(key);
|
|
30
|
+
if (!el)
|
|
31
|
+
return;
|
|
32
|
+
states.set(key, 'ready');
|
|
33
|
+
el.setAttribute('data-wavelo-region-state', 'ready');
|
|
34
|
+
el.removeAttribute('aria-busy');
|
|
35
|
+
el.innerHTML = readyHtml;
|
|
36
|
+
},
|
|
37
|
+
fail(key, errorHtml) {
|
|
38
|
+
const el = findRegion(key);
|
|
39
|
+
if (!el)
|
|
40
|
+
return;
|
|
41
|
+
states.set(key, 'error');
|
|
42
|
+
el.setAttribute('data-wavelo-region-state', 'error');
|
|
43
|
+
el.removeAttribute('aria-busy');
|
|
44
|
+
el.innerHTML = errorHtml;
|
|
45
|
+
},
|
|
46
|
+
resetRegion(key) {
|
|
47
|
+
const el = findRegion(key);
|
|
48
|
+
const sk = skeletons.get(key);
|
|
49
|
+
if (!el || sk === undefined)
|
|
50
|
+
return;
|
|
51
|
+
states.set(key, 'loading');
|
|
52
|
+
el.setAttribute('data-wavelo-region-state', 'loading');
|
|
53
|
+
el.setAttribute('aria-busy', 'true');
|
|
54
|
+
el.innerHTML = sk;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const PRIORITY_RANK = {
|
|
59
|
+
foreground: 3,
|
|
60
|
+
normal: 2,
|
|
61
|
+
background: 1
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Loading attention coordinator (F34).
|
|
65
|
+
* Arbitrates presentation visibility across simultaneous operations without hiding
|
|
66
|
+
* failures, focus-owned items, or underlying task state.
|
|
67
|
+
*/
|
|
68
|
+
export function createAttentionCoordinator(options = {}) {
|
|
69
|
+
const maxVisible = Math.max(1, options.maxVisible ?? 2);
|
|
70
|
+
const items = new Map();
|
|
71
|
+
let seqCounter = 0;
|
|
72
|
+
const evaluate = () => {
|
|
73
|
+
const all = [...items.values()];
|
|
74
|
+
const pinned = all.filter((i) => i.focusOwned || i.hasActionableError);
|
|
75
|
+
const rest = all
|
|
76
|
+
.filter((i) => !i.focusOwned && !i.hasActionableError)
|
|
77
|
+
.sort((a, b) => PRIORITY_RANK[b.priority] - PRIORITY_RANK[a.priority] || a.seq - b.seq);
|
|
78
|
+
const remainingSlots = Math.max(0, maxVisible - pinned.length);
|
|
79
|
+
const visibleIds = [...pinned.map((i) => i.id), ...rest.slice(0, remainingSlots).map((i) => i.id)];
|
|
80
|
+
const visibleSet = new Set(visibleIds);
|
|
81
|
+
const hiddenIds = all.filter((i) => !visibleSet.has(i.id)).map((i) => i.id);
|
|
82
|
+
return {
|
|
83
|
+
visibleIds,
|
|
84
|
+
hiddenIds,
|
|
85
|
+
hiddenCount: hiddenIds.length,
|
|
86
|
+
summaryLabel: hiddenIds.length > 0 ? `${hiddenIds.length} background loading operation(s) active` : undefined
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
register(item) {
|
|
91
|
+
items.set(item.id, {
|
|
92
|
+
id: item.id,
|
|
93
|
+
priority: item.priority ?? 'normal',
|
|
94
|
+
focusOwned: Boolean(item.focusOwned),
|
|
95
|
+
hasActionableError: Boolean(item.hasActionableError),
|
|
96
|
+
seq: ++seqCounter
|
|
97
|
+
});
|
|
98
|
+
return evaluate();
|
|
99
|
+
},
|
|
100
|
+
unregister(id) {
|
|
101
|
+
items.delete(id);
|
|
102
|
+
return evaluate();
|
|
103
|
+
},
|
|
104
|
+
evaluate
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* RTL and mixed-script loading layout helper (F40).
|
|
109
|
+
* Sets logical HTML `dir` and `<bdi>` isolation without altering animation `direction`.
|
|
110
|
+
*/
|
|
111
|
+
export function applyRtlLayout(element, options) {
|
|
112
|
+
element.setAttribute('dir', options.dir);
|
|
113
|
+
element.style.textAlign = 'start';
|
|
114
|
+
if (options.progressMirrored !== undefined) {
|
|
115
|
+
element.setAttribute('data-wavelo-progress-dir', options.progressMirrored ? 'rtl' : 'ltr');
|
|
116
|
+
}
|
|
117
|
+
if (options.captionText !== undefined) {
|
|
118
|
+
const bdi = element.ownerDocument.createElement('bdi');
|
|
119
|
+
bdi.textContent = options.captionText;
|
|
120
|
+
element.appendChild(bdi);
|
|
121
|
+
}
|
|
122
|
+
}
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TaskGroup, TaskGroupOptions, TaskGroupSnapshot } from './group.js';
|
|
2
|
+
import type { LoadingController, LoadingControllerOptions, LoadingSnapshot } from './types.js';
|
|
3
|
+
export interface UseLoadingControllerResult<T = unknown> {
|
|
4
|
+
snapshot: LoadingSnapshot<T>;
|
|
5
|
+
controller: LoadingController<T>;
|
|
6
|
+
start: LoadingController<T>['start'];
|
|
7
|
+
run: LoadingController<T>['run'];
|
|
8
|
+
reset: LoadingController<T>['reset'];
|
|
9
|
+
dispose: LoadingController<T>['dispose'];
|
|
10
|
+
}
|
|
11
|
+
export declare function useLoadingController<T = unknown>(options?: LoadingControllerOptions): UseLoadingControllerResult<T>;
|
|
12
|
+
export interface UseTaskGroupResult {
|
|
13
|
+
snapshot: TaskGroupSnapshot;
|
|
14
|
+
group: TaskGroup;
|
|
15
|
+
dispose: TaskGroup['dispose'];
|
|
16
|
+
}
|
|
17
|
+
export declare function useTaskGroup(options?: TaskGroupOptions): UseTaskGroupResult;
|