@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,363 @@
|
|
|
1
|
+
const defaultScheduler = {
|
|
2
|
+
setTimeout: (fn, ms) => globalThis.setTimeout(fn, ms),
|
|
3
|
+
clearTimeout: (id) => globalThis.clearTimeout(id),
|
|
4
|
+
now: () => Date.now()
|
|
5
|
+
};
|
|
6
|
+
function sanitizeNonNegative(value, fallback = 0) {
|
|
7
|
+
if (value === undefined)
|
|
8
|
+
return fallback;
|
|
9
|
+
if (!Number.isFinite(value) || value < 0)
|
|
10
|
+
return fallback;
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
function buildProgress(value, max) {
|
|
14
|
+
if (value === undefined || !Number.isFinite(value) || !Number.isFinite(max) || max <= 0) {
|
|
15
|
+
return { value: undefined, max: max > 0 && Number.isFinite(max) ? max : 100, percent: undefined, indeterminate: true };
|
|
16
|
+
}
|
|
17
|
+
const clamped = Math.max(0, Math.min(max, value));
|
|
18
|
+
return {
|
|
19
|
+
value: clamped,
|
|
20
|
+
max,
|
|
21
|
+
percent: Math.round((clamped / max) * 100),
|
|
22
|
+
indeterminate: false
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function isAbortError(error) {
|
|
26
|
+
return (typeof error === 'object' &&
|
|
27
|
+
error !== null &&
|
|
28
|
+
'name' in error &&
|
|
29
|
+
error.name === 'AbortError');
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Headless async operation controller (F01 + F02).
|
|
33
|
+
* Owns latest-operation identity, cancellation vs failure, and anti-flicker visibility timing.
|
|
34
|
+
* Framework-independent and DOM-free; schedules no timers until an operation starts.
|
|
35
|
+
*/
|
|
36
|
+
export function createLoadingController(options = {}) {
|
|
37
|
+
const showDelay = sanitizeNonNegative(options.showDelay, 0);
|
|
38
|
+
const minVisible = sanitizeNonNegative(options.minVisible, 0);
|
|
39
|
+
const slowThreshold = options.slowThreshold !== undefined ? sanitizeNonNegative(options.slowThreshold, 0) : undefined;
|
|
40
|
+
const scheduler = options.scheduler ?? defaultScheduler;
|
|
41
|
+
const listeners = new Set();
|
|
42
|
+
let nextId = 0;
|
|
43
|
+
let activeAbort = null;
|
|
44
|
+
let activeContext = null;
|
|
45
|
+
let externalCleanup = null;
|
|
46
|
+
let showTimer = null;
|
|
47
|
+
let hideTimer = null;
|
|
48
|
+
let slowTimer = null;
|
|
49
|
+
let visibleSince = null;
|
|
50
|
+
let snapshot = {
|
|
51
|
+
operationId: 0,
|
|
52
|
+
status: 'idle',
|
|
53
|
+
pending: false,
|
|
54
|
+
visible: false,
|
|
55
|
+
isSlow: false,
|
|
56
|
+
progress: buildProgress(undefined, 100),
|
|
57
|
+
data: undefined,
|
|
58
|
+
error: undefined,
|
|
59
|
+
disposed: false
|
|
60
|
+
};
|
|
61
|
+
// Every state change bumps this, so a multi-step transition can tell whether one of its
|
|
62
|
+
// own notifications re-entered the controller (a listener that calls start/reset/dispose).
|
|
63
|
+
let stateVersion = 0;
|
|
64
|
+
const clearTimers = () => {
|
|
65
|
+
if (showTimer !== null) {
|
|
66
|
+
scheduler.clearTimeout(showTimer);
|
|
67
|
+
showTimer = null;
|
|
68
|
+
}
|
|
69
|
+
if (hideTimer !== null) {
|
|
70
|
+
scheduler.clearTimeout(hideTimer);
|
|
71
|
+
hideTimer = null;
|
|
72
|
+
}
|
|
73
|
+
if (slowTimer !== null) {
|
|
74
|
+
scheduler.clearTimeout(slowTimer);
|
|
75
|
+
slowTimer = null;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const cleanupExternal = () => {
|
|
79
|
+
if (externalCleanup) {
|
|
80
|
+
externalCleanup();
|
|
81
|
+
externalCleanup = null;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Publishes `next` and reports whether the notification came back untouched. A false
|
|
86
|
+
* return means a listener called start/reset/dispose on this controller while it was
|
|
87
|
+
* being notified, so whatever the listener did owns the state now.
|
|
88
|
+
*/
|
|
89
|
+
const emit = (next) => {
|
|
90
|
+
snapshot = next;
|
|
91
|
+
const version = ++stateVersion;
|
|
92
|
+
if (!snapshot.disposed) {
|
|
93
|
+
for (const listener of [...listeners]) {
|
|
94
|
+
listener(snapshot);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return stateVersion === version;
|
|
98
|
+
};
|
|
99
|
+
const hidePresentation = () => {
|
|
100
|
+
if (hideTimer !== null) {
|
|
101
|
+
scheduler.clearTimeout(hideTimer);
|
|
102
|
+
hideTimer = null;
|
|
103
|
+
}
|
|
104
|
+
if (snapshot.visible) {
|
|
105
|
+
visibleSince = null;
|
|
106
|
+
emit({ ...snapshot, visible: false });
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const settle = (id, status, payload) => {
|
|
110
|
+
if (snapshot.disposed || id !== snapshot.operationId || !snapshot.pending)
|
|
111
|
+
return;
|
|
112
|
+
cleanupExternal();
|
|
113
|
+
activeAbort = null;
|
|
114
|
+
activeContext = null;
|
|
115
|
+
if (showTimer !== null) {
|
|
116
|
+
scheduler.clearTimeout(showTimer);
|
|
117
|
+
showTimer = null;
|
|
118
|
+
}
|
|
119
|
+
if (slowTimer !== null) {
|
|
120
|
+
scheduler.clearTimeout(slowTimer);
|
|
121
|
+
slowTimer = null;
|
|
122
|
+
}
|
|
123
|
+
let nextVisible = snapshot.visible;
|
|
124
|
+
if (nextVisible) {
|
|
125
|
+
if (minVisible <= 0 || visibleSince === null) {
|
|
126
|
+
nextVisible = false;
|
|
127
|
+
visibleSince = null;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const elapsed = Math.max(0, scheduler.now() - visibleSince);
|
|
131
|
+
const remaining = minVisible - elapsed;
|
|
132
|
+
if (remaining <= 0) {
|
|
133
|
+
nextVisible = false;
|
|
134
|
+
visibleSince = null;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
hideTimer = scheduler.setTimeout(() => {
|
|
138
|
+
hideTimer = null;
|
|
139
|
+
if (!snapshot.pending && !snapshot.disposed) {
|
|
140
|
+
hidePresentation();
|
|
141
|
+
}
|
|
142
|
+
}, remaining);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
emit({
|
|
147
|
+
...snapshot,
|
|
148
|
+
status,
|
|
149
|
+
pending: false,
|
|
150
|
+
visible: nextVisible,
|
|
151
|
+
isSlow: false,
|
|
152
|
+
data: status === 'success' ? payload.data : snapshot.data,
|
|
153
|
+
error: status === 'error' ? payload.error : undefined
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
const start = (startOptions = {}) => {
|
|
157
|
+
if (snapshot.disposed) {
|
|
158
|
+
const noopController = new AbortController();
|
|
159
|
+
return {
|
|
160
|
+
id: snapshot.operationId,
|
|
161
|
+
signal: noopController.signal,
|
|
162
|
+
isCurrent: () => false,
|
|
163
|
+
setProgress: () => { },
|
|
164
|
+
succeed: () => { },
|
|
165
|
+
fail: () => { },
|
|
166
|
+
cancel: () => { }
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
clearTimers();
|
|
170
|
+
cleanupExternal();
|
|
171
|
+
// Visual timing state is per-operation: a new current operation must derive
|
|
172
|
+
// `visible`/`isSlow` and the minVisible window from its own timeline, never
|
|
173
|
+
// inherit a partially consumed window from the superseded operation.
|
|
174
|
+
visibleSince = null;
|
|
175
|
+
activeContext = null;
|
|
176
|
+
if (activeAbort) {
|
|
177
|
+
activeAbort.abort();
|
|
178
|
+
}
|
|
179
|
+
const id = ++nextId;
|
|
180
|
+
const abortController = new AbortController();
|
|
181
|
+
activeAbort = abortController;
|
|
182
|
+
const externalSignal = startOptions.signal;
|
|
183
|
+
if (externalSignal?.aborted) {
|
|
184
|
+
abortController.abort(externalSignal.reason);
|
|
185
|
+
snapshot = {
|
|
186
|
+
...snapshot,
|
|
187
|
+
operationId: id,
|
|
188
|
+
status: 'cancelled',
|
|
189
|
+
pending: false,
|
|
190
|
+
visible: false,
|
|
191
|
+
isSlow: false,
|
|
192
|
+
progress: buildProgress(startOptions.value, startOptions.max ?? 100),
|
|
193
|
+
error: undefined
|
|
194
|
+
};
|
|
195
|
+
emit(snapshot);
|
|
196
|
+
return {
|
|
197
|
+
id,
|
|
198
|
+
signal: abortController.signal,
|
|
199
|
+
isCurrent: () => !snapshot.disposed && snapshot.operationId === id,
|
|
200
|
+
setProgress: () => { },
|
|
201
|
+
succeed: () => { },
|
|
202
|
+
fail: () => { },
|
|
203
|
+
cancel: () => { }
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
if (externalSignal) {
|
|
207
|
+
const onAbort = () => {
|
|
208
|
+
abortController.abort(externalSignal.reason);
|
|
209
|
+
settle(id, 'cancelled', {});
|
|
210
|
+
};
|
|
211
|
+
externalSignal.addEventListener('abort', onAbort, { once: true });
|
|
212
|
+
externalCleanup = () => externalSignal.removeEventListener('abort', onAbort);
|
|
213
|
+
}
|
|
214
|
+
const initialVisible = showDelay === 0 || snapshot.visible;
|
|
215
|
+
if (initialVisible) {
|
|
216
|
+
visibleSince = scheduler.now();
|
|
217
|
+
}
|
|
218
|
+
const isCurrent = () => !snapshot.disposed && snapshot.operationId === id;
|
|
219
|
+
const context = {
|
|
220
|
+
id,
|
|
221
|
+
signal: abortController.signal,
|
|
222
|
+
isCurrent,
|
|
223
|
+
setProgress: (value, max) => {
|
|
224
|
+
if (!isCurrent() || !snapshot.pending)
|
|
225
|
+
return;
|
|
226
|
+
emit({ ...snapshot, progress: buildProgress(value, max ?? snapshot.progress.max) });
|
|
227
|
+
},
|
|
228
|
+
succeed: (data) => settle(id, 'success', { data }),
|
|
229
|
+
fail: (error) => settle(id, 'error', { error }),
|
|
230
|
+
cancel: () => {
|
|
231
|
+
if (!isCurrent() || !snapshot.pending)
|
|
232
|
+
return;
|
|
233
|
+
abortController.abort();
|
|
234
|
+
settle(id, 'cancelled', {});
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
activeContext = context;
|
|
238
|
+
const owned = emit({
|
|
239
|
+
...snapshot,
|
|
240
|
+
operationId: id,
|
|
241
|
+
status: 'pending',
|
|
242
|
+
pending: true,
|
|
243
|
+
visible: initialVisible,
|
|
244
|
+
isSlow: slowThreshold === 0,
|
|
245
|
+
progress: buildProgress(startOptions.value, startOptions.max ?? 100),
|
|
246
|
+
error: undefined
|
|
247
|
+
});
|
|
248
|
+
// A listener that started, reset or disposed the controller during the notification
|
|
249
|
+
// above owns the state now. Arming this operation's timers would resurrect it.
|
|
250
|
+
if (!owned)
|
|
251
|
+
return context;
|
|
252
|
+
if (!initialVisible && showDelay > 0) {
|
|
253
|
+
showTimer = scheduler.setTimeout(() => {
|
|
254
|
+
showTimer = null;
|
|
255
|
+
if (!snapshot.disposed && snapshot.operationId === id && snapshot.pending && !snapshot.visible) {
|
|
256
|
+
visibleSince = scheduler.now();
|
|
257
|
+
emit({ ...snapshot, visible: true });
|
|
258
|
+
}
|
|
259
|
+
}, showDelay);
|
|
260
|
+
}
|
|
261
|
+
if (slowThreshold !== undefined && slowThreshold > 0) {
|
|
262
|
+
slowTimer = scheduler.setTimeout(() => {
|
|
263
|
+
slowTimer = null;
|
|
264
|
+
if (!snapshot.disposed && snapshot.operationId === id && snapshot.pending && !snapshot.isSlow) {
|
|
265
|
+
emit({ ...snapshot, isSlow: true });
|
|
266
|
+
}
|
|
267
|
+
}, slowThreshold);
|
|
268
|
+
}
|
|
269
|
+
return context;
|
|
270
|
+
};
|
|
271
|
+
const run = async (task, runOptions) => {
|
|
272
|
+
const ctx = start(runOptions);
|
|
273
|
+
if (ctx.signal.aborted)
|
|
274
|
+
return undefined;
|
|
275
|
+
try {
|
|
276
|
+
const result = await task(ctx);
|
|
277
|
+
if (ctx.signal.aborted) {
|
|
278
|
+
ctx.cancel();
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
ctx.succeed(result);
|
|
282
|
+
return ctx.isCurrent() ? result : undefined;
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
if (ctx.signal.aborted || isAbortError(error)) {
|
|
286
|
+
ctx.cancel();
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
289
|
+
ctx.fail(error);
|
|
290
|
+
if (ctx.isCurrent())
|
|
291
|
+
throw error;
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
const reset = () => {
|
|
296
|
+
if (snapshot.disposed)
|
|
297
|
+
return;
|
|
298
|
+
clearTimers();
|
|
299
|
+
cleanupExternal();
|
|
300
|
+
if (activeAbort) {
|
|
301
|
+
activeAbort.abort();
|
|
302
|
+
activeAbort = null;
|
|
303
|
+
}
|
|
304
|
+
activeContext = null;
|
|
305
|
+
visibleSince = null;
|
|
306
|
+
emit({
|
|
307
|
+
operationId: snapshot.operationId,
|
|
308
|
+
status: 'idle',
|
|
309
|
+
pending: false,
|
|
310
|
+
visible: false,
|
|
311
|
+
isSlow: false,
|
|
312
|
+
progress: buildProgress(undefined, 100),
|
|
313
|
+
data: undefined,
|
|
314
|
+
error: undefined,
|
|
315
|
+
disposed: false
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
const dispose = () => {
|
|
319
|
+
if (snapshot.disposed)
|
|
320
|
+
return;
|
|
321
|
+
clearTimers();
|
|
322
|
+
cleanupExternal();
|
|
323
|
+
if (activeAbort) {
|
|
324
|
+
activeAbort.abort();
|
|
325
|
+
activeAbort = null;
|
|
326
|
+
}
|
|
327
|
+
activeContext = null;
|
|
328
|
+
visibleSince = null;
|
|
329
|
+
// One terminal notification, then the listener set is gone: a subscriber that is still
|
|
330
|
+
// attached when the controller is disposed has to learn the presentation ended, or it
|
|
331
|
+
// keeps a visible spinner (and the DOM nodes behind it) that nothing will ever clear.
|
|
332
|
+
const final = {
|
|
333
|
+
...snapshot,
|
|
334
|
+
pending: false,
|
|
335
|
+
visible: false,
|
|
336
|
+
isSlow: false,
|
|
337
|
+
disposed: true
|
|
338
|
+
};
|
|
339
|
+
const notify = [...listeners];
|
|
340
|
+
listeners.clear();
|
|
341
|
+
snapshot = final;
|
|
342
|
+
stateVersion += 1;
|
|
343
|
+
for (const listener of notify) {
|
|
344
|
+
listener(final);
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
return {
|
|
348
|
+
getSnapshot: () => snapshot,
|
|
349
|
+
subscribe: (listener) => {
|
|
350
|
+
if (snapshot.disposed)
|
|
351
|
+
return () => { };
|
|
352
|
+
listeners.add(listener);
|
|
353
|
+
return () => {
|
|
354
|
+
listeners.delete(listener);
|
|
355
|
+
};
|
|
356
|
+
},
|
|
357
|
+
getCurrentOperation: () => (snapshot.pending && !snapshot.disposed ? activeContext : null),
|
|
358
|
+
start,
|
|
359
|
+
run,
|
|
360
|
+
reset,
|
|
361
|
+
dispose
|
|
362
|
+
};
|
|
363
|
+
}
|
package/dist/dom.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { LoaderConfig, StyleOptions } from '@wavelo/core';
|
|
2
|
+
import type { AnnouncementPolicyOptions } from './announcer.js';
|
|
3
|
+
import type { LoadingController } from './types.js';
|
|
4
|
+
export interface LoaderHandle {
|
|
5
|
+
update: (nextConfig: LoaderConfig) => void;
|
|
6
|
+
getElement: () => HTMLElement | null;
|
|
7
|
+
destroy: () => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Updatable DOM loader handle (F04).
|
|
11
|
+
* Patches compatible visual/ARIA attributes in place so CSS transitions interpolate
|
|
12
|
+
* smoothly without replacing DOM nodes; re-renders only for structural changes.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createLoaderHandle(container: HTMLElement, initialConfig?: LoaderConfig, styleOptions?: StyleOptions): LoaderHandle;
|
|
15
|
+
export interface BusyRegionBinding {
|
|
16
|
+
acquire: () => () => void;
|
|
17
|
+
bindController: (controller: LoadingController) => () => void;
|
|
18
|
+
isBusy: () => boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Accessible busy-region ownership (F05).
|
|
22
|
+
* Reference-counts `aria-busy` across nested owners and restores any pre-existing
|
|
23
|
+
* `aria-busy` attribute on final release. Never traps focus or locks scroll.
|
|
24
|
+
*/
|
|
25
|
+
export declare function bindBusyRegion(region: HTMLElement): BusyRegionBinding;
|
|
26
|
+
export interface StatusRegionHandle {
|
|
27
|
+
announce: (message: string) => void;
|
|
28
|
+
bindController: (controller: LoadingController) => () => void;
|
|
29
|
+
destroy: () => void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Scoped live-region announcer (F06).
|
|
33
|
+
* Mounts a single visually-hidden `role="status"` node and drives it with `createAnnouncementPolicy`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function mountStatusRegion(container: HTMLElement, options?: AnnouncementPolicyOptions): StatusRegionHandle;
|
package/dist/dom.js
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { ensureStyles, renderLoader } from '@wavelo/core';
|
|
2
|
+
import { createAnnouncementPolicy } from './announcer.js';
|
|
3
|
+
function structuralSignature(config) {
|
|
4
|
+
return JSON.stringify([
|
|
5
|
+
config.type ?? null,
|
|
6
|
+
config.count ?? null,
|
|
7
|
+
Boolean(config.inline),
|
|
8
|
+
Boolean(config.decorative),
|
|
9
|
+
config.loading !== false,
|
|
10
|
+
config.label ?? null,
|
|
11
|
+
config.labelledBy ?? null,
|
|
12
|
+
config.describedBy ?? null,
|
|
13
|
+
config.brand ?? null
|
|
14
|
+
]);
|
|
15
|
+
}
|
|
16
|
+
function patchInPlace(node, config, supportsProgress) {
|
|
17
|
+
if (config.size !== undefined)
|
|
18
|
+
node.style.setProperty('--wavelo-size', String(config.size));
|
|
19
|
+
else
|
|
20
|
+
node.style.removeProperty('--wavelo-size');
|
|
21
|
+
if (config.width !== undefined)
|
|
22
|
+
node.style.setProperty('--wavelo-width', String(config.width));
|
|
23
|
+
else
|
|
24
|
+
node.style.removeProperty('--wavelo-width');
|
|
25
|
+
if (config.height !== undefined)
|
|
26
|
+
node.style.setProperty('--wavelo-height', String(config.height));
|
|
27
|
+
else
|
|
28
|
+
node.style.removeProperty('--wavelo-height');
|
|
29
|
+
if (config.color !== undefined)
|
|
30
|
+
node.style.setProperty('--wavelo-color', config.color);
|
|
31
|
+
else
|
|
32
|
+
node.style.removeProperty('--wavelo-color');
|
|
33
|
+
if (config.secondaryColor !== undefined)
|
|
34
|
+
node.style.setProperty('--wavelo-secondary-color', config.secondaryColor);
|
|
35
|
+
else
|
|
36
|
+
node.style.removeProperty('--wavelo-secondary-color');
|
|
37
|
+
if (config.backgroundColor !== undefined)
|
|
38
|
+
node.style.setProperty('--wavelo-background', config.backgroundColor);
|
|
39
|
+
else
|
|
40
|
+
node.style.removeProperty('--wavelo-background');
|
|
41
|
+
if (config.duration !== undefined)
|
|
42
|
+
node.style.setProperty('--wavelo-duration', String(config.duration));
|
|
43
|
+
else
|
|
44
|
+
node.style.removeProperty('--wavelo-duration');
|
|
45
|
+
if (config.strokeWidth !== undefined)
|
|
46
|
+
node.style.setProperty('--wavelo-stroke', `${config.strokeWidth}px`);
|
|
47
|
+
else
|
|
48
|
+
node.style.removeProperty('--wavelo-stroke');
|
|
49
|
+
if (config.direction !== undefined)
|
|
50
|
+
node.style.setProperty('--wavelo-direction', config.direction);
|
|
51
|
+
else
|
|
52
|
+
node.style.removeProperty('--wavelo-direction');
|
|
53
|
+
if (config.paused !== undefined)
|
|
54
|
+
node.style.setProperty('--wavelo-play-state', config.paused ? 'paused' : 'running');
|
|
55
|
+
else
|
|
56
|
+
node.style.removeProperty('--wavelo-play-state');
|
|
57
|
+
const max = config.max ?? 100;
|
|
58
|
+
if (config.value !== undefined) {
|
|
59
|
+
const pct = (config.value / max) * 100;
|
|
60
|
+
node.style.setProperty('--wavelo-progress', `${pct}%`);
|
|
61
|
+
if (supportsProgress) {
|
|
62
|
+
node.style.setProperty('--wavelo-count', String(Math.round(pct)));
|
|
63
|
+
if (node.getAttribute('role') === 'progressbar') {
|
|
64
|
+
node.setAttribute('aria-valuenow', String(config.value));
|
|
65
|
+
node.setAttribute('aria-valuemax', String(max));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
node.style.removeProperty('--wavelo-progress');
|
|
71
|
+
node.style.removeProperty('--wavelo-count');
|
|
72
|
+
}
|
|
73
|
+
if (config.valueText !== undefined) {
|
|
74
|
+
node.setAttribute('data-wavelo-value-text', config.valueText);
|
|
75
|
+
if (node.getAttribute('role') === 'progressbar') {
|
|
76
|
+
node.setAttribute('aria-valuetext', config.valueText);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (config.type === 'progress-label-inline') {
|
|
80
|
+
const pct = config.value !== undefined ? Math.round((config.value / max) * 100) : 35;
|
|
81
|
+
node.setAttribute('data-wavelo-value-text', `${pct}%`);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
node.removeAttribute('data-wavelo-value-text');
|
|
85
|
+
node.removeAttribute('aria-valuetext');
|
|
86
|
+
}
|
|
87
|
+
const stateAttr = config['data-wavelo-state'];
|
|
88
|
+
if (stateAttr !== undefined)
|
|
89
|
+
node.setAttribute('data-wavelo-state', String(stateAttr));
|
|
90
|
+
else
|
|
91
|
+
node.removeAttribute('data-wavelo-state');
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Updatable DOM loader handle (F04).
|
|
95
|
+
* Patches compatible visual/ARIA attributes in place so CSS transitions interpolate
|
|
96
|
+
* smoothly without replacing DOM nodes; re-renders only for structural changes.
|
|
97
|
+
*/
|
|
98
|
+
export function createLoaderHandle(container, initialConfig = {}, styleOptions = {}) {
|
|
99
|
+
let destroyed = false;
|
|
100
|
+
let currentConfig = { ...initialConfig };
|
|
101
|
+
let lastResult = renderLoader(currentConfig);
|
|
102
|
+
let lastSig = structuralSignature(currentConfig);
|
|
103
|
+
const renderFull = () => {
|
|
104
|
+
if (destroyed)
|
|
105
|
+
return;
|
|
106
|
+
lastResult = renderLoader(currentConfig);
|
|
107
|
+
if (lastResult.css)
|
|
108
|
+
ensureStyles(lastResult.css, styleOptions);
|
|
109
|
+
container.innerHTML = lastResult.html;
|
|
110
|
+
};
|
|
111
|
+
renderFull();
|
|
112
|
+
return {
|
|
113
|
+
update(nextConfig) {
|
|
114
|
+
if (destroyed)
|
|
115
|
+
return;
|
|
116
|
+
currentConfig = { ...nextConfig };
|
|
117
|
+
const nextSig = structuralSignature(currentConfig);
|
|
118
|
+
const existingNode = container.querySelector('.wavelo');
|
|
119
|
+
const canPatchInPlace = nextSig === lastSig &&
|
|
120
|
+
existingNode !== null &&
|
|
121
|
+
currentConfig.loading !== false &&
|
|
122
|
+
lastResult.definition.id !== 'progress-steps' &&
|
|
123
|
+
lastResult.definition.id !== 'progress-dots-fill' &&
|
|
124
|
+
lastResult.definition.id !== 'progress-multi-step' &&
|
|
125
|
+
lastResult.definition.id !== 'progress-orbit-fill' &&
|
|
126
|
+
lastResult.definition.id !== 'progress-upload-multi' &&
|
|
127
|
+
lastResult.definition.id !== 'progress-signal' &&
|
|
128
|
+
lastResult.definition.id !== 'progress-path';
|
|
129
|
+
if (canPatchInPlace) {
|
|
130
|
+
patchInPlace(existingNode, currentConfig, Boolean(lastResult.definition.supportsProgress));
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
lastSig = nextSig;
|
|
134
|
+
renderFull();
|
|
135
|
+
},
|
|
136
|
+
getElement: () => (destroyed ? null : container.querySelector('.wavelo')),
|
|
137
|
+
destroy() {
|
|
138
|
+
if (destroyed)
|
|
139
|
+
return;
|
|
140
|
+
destroyed = true;
|
|
141
|
+
if (typeof container.replaceChildren === 'function')
|
|
142
|
+
container.replaceChildren();
|
|
143
|
+
else
|
|
144
|
+
container.textContent = '';
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const busyOwners = new WeakMap();
|
|
149
|
+
/**
|
|
150
|
+
* Accessible busy-region ownership (F05).
|
|
151
|
+
* Reference-counts `aria-busy` across nested owners and restores any pre-existing
|
|
152
|
+
* `aria-busy` attribute on final release. Never traps focus or locks scroll.
|
|
153
|
+
*/
|
|
154
|
+
export function bindBusyRegion(region) {
|
|
155
|
+
const acquire = () => {
|
|
156
|
+
let released = false;
|
|
157
|
+
let state = busyOwners.get(region);
|
|
158
|
+
if (!state) {
|
|
159
|
+
state = { count: 0, previousBusy: region.getAttribute('aria-busy') };
|
|
160
|
+
busyOwners.set(region, state);
|
|
161
|
+
}
|
|
162
|
+
state.count += 1;
|
|
163
|
+
region.setAttribute('aria-busy', 'true');
|
|
164
|
+
return () => {
|
|
165
|
+
if (released)
|
|
166
|
+
return;
|
|
167
|
+
released = true;
|
|
168
|
+
const current = busyOwners.get(region);
|
|
169
|
+
if (!current)
|
|
170
|
+
return;
|
|
171
|
+
current.count = Math.max(0, current.count - 1);
|
|
172
|
+
if (current.count === 0) {
|
|
173
|
+
if (current.previousBusy === null)
|
|
174
|
+
region.removeAttribute('aria-busy');
|
|
175
|
+
else
|
|
176
|
+
region.setAttribute('aria-busy', current.previousBusy);
|
|
177
|
+
busyOwners.delete(region);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
return {
|
|
182
|
+
acquire,
|
|
183
|
+
bindController(controller) {
|
|
184
|
+
let release = null;
|
|
185
|
+
const sync = (pending) => {
|
|
186
|
+
if (pending && !release) {
|
|
187
|
+
release = acquire();
|
|
188
|
+
}
|
|
189
|
+
else if (!pending && release) {
|
|
190
|
+
release();
|
|
191
|
+
release = null;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
sync(controller.getSnapshot().pending);
|
|
195
|
+
const unsubscribe = controller.subscribe((snap) => sync(snap.pending));
|
|
196
|
+
return () => {
|
|
197
|
+
unsubscribe();
|
|
198
|
+
if (release) {
|
|
199
|
+
release();
|
|
200
|
+
release = null;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
isBusy: () => (busyOwners.get(region)?.count ?? 0) > 0
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Scoped live-region announcer (F06).
|
|
209
|
+
* Mounts a single visually-hidden `role="status"` node and drives it with `createAnnouncementPolicy`.
|
|
210
|
+
*/
|
|
211
|
+
export function mountStatusRegion(container, options = {}) {
|
|
212
|
+
const policy = createAnnouncementPolicy(options);
|
|
213
|
+
const el = container.ownerDocument.createElement('span');
|
|
214
|
+
el.setAttribute('role', 'status');
|
|
215
|
+
el.setAttribute('aria-live', 'polite');
|
|
216
|
+
el.setAttribute('aria-atomic', 'true');
|
|
217
|
+
el.style.cssText =
|
|
218
|
+
'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0';
|
|
219
|
+
container.appendChild(el);
|
|
220
|
+
let destroyed = false;
|
|
221
|
+
const announce = (message) => {
|
|
222
|
+
if (!destroyed)
|
|
223
|
+
el.textContent = message;
|
|
224
|
+
};
|
|
225
|
+
return {
|
|
226
|
+
announce,
|
|
227
|
+
bindController(controller) {
|
|
228
|
+
const unsubscribe = controller.subscribe((snapshot) => {
|
|
229
|
+
const event = policy.evaluate(snapshot);
|
|
230
|
+
if (event)
|
|
231
|
+
announce(event.message);
|
|
232
|
+
});
|
|
233
|
+
return unsubscribe;
|
|
234
|
+
},
|
|
235
|
+
destroy() {
|
|
236
|
+
if (destroyed)
|
|
237
|
+
return;
|
|
238
|
+
destroyed = true;
|
|
239
|
+
policy.reset();
|
|
240
|
+
el.remove();
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface ExportBundleOptions {
|
|
2
|
+
layer?: boolean;
|
|
3
|
+
layerName?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ExportBundleResult {
|
|
6
|
+
designs: readonly string[];
|
|
7
|
+
slicesUsed: readonly string[];
|
|
8
|
+
css: string;
|
|
9
|
+
snippets: Readonly<Record<string, string>>;
|
|
10
|
+
bytes: {
|
|
11
|
+
selectedCssBytes: number;
|
|
12
|
+
fullCatalogCssBytes: number;
|
|
13
|
+
savedBytes: number;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Build-time loader export tool (F30).
|
|
18
|
+
* Validates selected IDs, deduplicates stylesheet slices, emits optional `@layer` CSS,
|
|
19
|
+
* and reports actual byte savings against the full catalog stylesheet.
|
|
20
|
+
*/
|
|
21
|
+
export declare function exportLoaderBundle(allowlist: readonly string[], options?: ExportBundleOptions): ExportBundleResult;
|
|
22
|
+
export interface StaticCspConfigEntry {
|
|
23
|
+
className: string;
|
|
24
|
+
type: string;
|
|
25
|
+
size?: string;
|
|
26
|
+
color?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Strict-CSP static export mode (F41).
|
|
30
|
+
* Emits external CSS classes for a bounded config allowlist so consumers running
|
|
31
|
+
* `style-src-attr 'none'` need zero inline `style="..."` attributes.
|
|
32
|
+
*/
|
|
33
|
+
export declare function exportStaticStrictCsp(entries: readonly StaticCspConfigEntry[]): {
|
|
34
|
+
css: string;
|
|
35
|
+
classCount: number;
|
|
36
|
+
cssBytes: number;
|
|
37
|
+
diagnostics: string[];
|
|
38
|
+
};
|