@wavelo/async 0.0.0 → 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 +49 -0
- 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 +147 -3
- package/index.js +0 -1
package/dist/themes.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const VALID_TOKEN_RE = /^--wavelo-[a-z-]+$/;
|
|
2
|
+
/**
|
|
3
|
+
* Validated, serializable design-system theme pack (F20).
|
|
4
|
+
* Cannot rewrite frozen built-in presets; applies scoped tokens and defaults cleanly.
|
|
5
|
+
*/
|
|
6
|
+
export function createThemePack(pack) {
|
|
7
|
+
if (pack.version !== 1)
|
|
8
|
+
throw new Error(`Unsupported theme pack version: ${pack.version}`);
|
|
9
|
+
if (!pack.name.trim())
|
|
10
|
+
throw new Error('Theme pack name is required.');
|
|
11
|
+
for (const [token, value] of Object.entries(pack.tokens)) {
|
|
12
|
+
if (!VALID_TOKEN_RE.test(token)) {
|
|
13
|
+
throw new Error(`Invalid theme pack token "${token}". Only --wavelo-* tokens are permitted.`);
|
|
14
|
+
}
|
|
15
|
+
if (/[;{}<>]/.test(value)) {
|
|
16
|
+
throw new Error(`Unsafe characters in theme pack token "${token}".`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
pack,
|
|
21
|
+
toCss(selector = ':root') {
|
|
22
|
+
const decls = Object.entries(pack.tokens)
|
|
23
|
+
.map(([k, v]) => `${k}:${v}`)
|
|
24
|
+
.join(';');
|
|
25
|
+
return `${selector}{${decls}}`;
|
|
26
|
+
},
|
|
27
|
+
applyTo(element) {
|
|
28
|
+
const previous = new Map();
|
|
29
|
+
for (const [k, v] of Object.entries(pack.tokens)) {
|
|
30
|
+
previous.set(k, element.style.getPropertyValue(k));
|
|
31
|
+
element.style.setProperty(k, v);
|
|
32
|
+
}
|
|
33
|
+
return () => {
|
|
34
|
+
for (const [k, prev] of previous.entries()) {
|
|
35
|
+
if (prev)
|
|
36
|
+
element.style.setProperty(k, prev);
|
|
37
|
+
else
|
|
38
|
+
element.style.removeProperty(k);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
resolveConfig(type, instanceConfig = {}) {
|
|
43
|
+
return {
|
|
44
|
+
...pack.defaults,
|
|
45
|
+
...pack.overrides?.[type],
|
|
46
|
+
...instanceConfig,
|
|
47
|
+
type: instanceConfig.type ?? type
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const LOW_MOTION_POSES = {
|
|
53
|
+
cube: { designId: 'cube', pose: 'isometric-rest', transform: 'rotateX(-24deg) rotateY(32deg)' },
|
|
54
|
+
tesseract: { designId: 'tesseract', pose: 'isometric-rest', transform: 'rotateX(-20deg) rotateY(35deg)' },
|
|
55
|
+
'solar-system': { designId: 'solar-system', pose: 'isometric-rest', transform: 'rotateX(65deg)' },
|
|
56
|
+
ring: { designId: 'ring', pose: 'static-arc', transform: 'rotate(45deg)' },
|
|
57
|
+
'dna-double-helix': { designId: 'dna-double-helix', pose: 'paused-frame', opacity: 0.9 },
|
|
58
|
+
'quantum-superposition': { designId: 'quantum-superposition', pose: 'isometric-rest', transform: 'rotateY(25deg)' }
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Authored low-motion treatment metadata (F29).
|
|
62
|
+
* Preserves visual identity without adding motion under `reducedMotion: 'always'`.
|
|
63
|
+
*/
|
|
64
|
+
export function getLowMotionPose(designId) {
|
|
65
|
+
return LOW_MOTION_POSES[designId] ?? { designId, pose: 'subtle-opacity', opacity: 0.85 };
|
|
66
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { OperationContext } from './types.js';
|
|
2
|
+
export interface TransferProgressEvent {
|
|
3
|
+
loaded: number;
|
|
4
|
+
total: number | undefined;
|
|
5
|
+
percent: number | undefined;
|
|
6
|
+
indeterminate: boolean;
|
|
7
|
+
bytesPerSecond?: number;
|
|
8
|
+
etaSeconds?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function formatTransferRate(bytesLoaded: number, elapsedMs: number, totalBytes?: number): {
|
|
11
|
+
bytesPerSecond: number;
|
|
12
|
+
etaSeconds: number | undefined;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Observes a caller-owned Response stream without unbounded buffering (F15).
|
|
16
|
+
* Leaves total indeterminate when Content-Length is missing or invalid.
|
|
17
|
+
*/
|
|
18
|
+
export declare function observeResponseStream(response: Response, onProgress: (event: TransferProgressEvent) => void, options?: {
|
|
19
|
+
now?: () => number;
|
|
20
|
+
controller?: OperationContext;
|
|
21
|
+
}): Response;
|
|
22
|
+
export interface XhrLike {
|
|
23
|
+
addEventListener: (type: string, listener: (event: unknown) => void) => void;
|
|
24
|
+
removeEventListener: (type: string, listener: (event: unknown) => void) => void;
|
|
25
|
+
}
|
|
26
|
+
export declare function observeXhrProgress(xhr: XhrLike, onProgress: (event: TransferProgressEvent) => void): () => void;
|
|
27
|
+
export type BatchItemStatus = 'pending' | 'active' | 'paused' | 'error' | 'completed';
|
|
28
|
+
export interface BatchTransferItem {
|
|
29
|
+
id: string;
|
|
30
|
+
name: string;
|
|
31
|
+
size?: number;
|
|
32
|
+
loaded: number;
|
|
33
|
+
status: BatchItemStatus;
|
|
34
|
+
error?: unknown;
|
|
35
|
+
}
|
|
36
|
+
export interface BatchTransferSnapshot {
|
|
37
|
+
items: readonly BatchTransferItem[];
|
|
38
|
+
totalBytes: number | undefined;
|
|
39
|
+
loadedBytes: number;
|
|
40
|
+
percent: number | undefined;
|
|
41
|
+
indeterminate: boolean;
|
|
42
|
+
activeCount: number;
|
|
43
|
+
completedCount: number;
|
|
44
|
+
errorCount: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Batch transfer state model (F26).
|
|
48
|
+
* Tracks per-item rows and overall summary; caller owns transport retry/cancel.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createBatchTransfer(initialItems?: readonly Omit<BatchTransferItem, 'loaded' | 'status'>[]): {
|
|
51
|
+
getSnapshot: () => BatchTransferSnapshot;
|
|
52
|
+
subscribe(listener: (snap: BatchTransferSnapshot) => void): () => boolean;
|
|
53
|
+
add(item: Omit<BatchTransferItem, "loaded" | "status">): void;
|
|
54
|
+
setStatus(id: string, status: BatchItemStatus, error?: unknown): void;
|
|
55
|
+
updateProgress(id: string, loaded: number, size?: number): void;
|
|
56
|
+
remove(id: string): void;
|
|
57
|
+
};
|
package/dist/transfer.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
export function formatTransferRate(bytesLoaded, elapsedMs, totalBytes) {
|
|
2
|
+
if (elapsedMs <= 0 || !Number.isFinite(bytesLoaded) || bytesLoaded < 0) {
|
|
3
|
+
return { bytesPerSecond: 0, etaSeconds: undefined };
|
|
4
|
+
}
|
|
5
|
+
const bytesPerSecond = (bytesLoaded / elapsedMs) * 1000;
|
|
6
|
+
if (totalBytes === undefined ||
|
|
7
|
+
!Number.isFinite(totalBytes) ||
|
|
8
|
+
totalBytes <= bytesLoaded ||
|
|
9
|
+
bytesPerSecond <= 0) {
|
|
10
|
+
return { bytesPerSecond, etaSeconds: undefined };
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
bytesPerSecond,
|
|
14
|
+
etaSeconds: Math.ceil((totalBytes - bytesLoaded) / bytesPerSecond)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Observes a caller-owned Response stream without unbounded buffering (F15).
|
|
19
|
+
* Leaves total indeterminate when Content-Length is missing or invalid.
|
|
20
|
+
*/
|
|
21
|
+
export function observeResponseStream(response, onProgress, options = {}) {
|
|
22
|
+
const rawLen = response.headers.get('content-length');
|
|
23
|
+
const parsedLen = rawLen !== null && /^\d+$/.test(rawLen.trim()) ? Number(rawLen.trim()) : NaN;
|
|
24
|
+
const total = Number.isFinite(parsedLen) && parsedLen > 0 ? parsedLen : undefined;
|
|
25
|
+
if (!response.body)
|
|
26
|
+
return response;
|
|
27
|
+
const now = options.now ?? (() => Date.now());
|
|
28
|
+
const startMs = now();
|
|
29
|
+
let loaded = 0;
|
|
30
|
+
const reader = response.body.getReader();
|
|
31
|
+
const stream = new ReadableStream({
|
|
32
|
+
async pull(controller) {
|
|
33
|
+
const { done, value } = await reader.read();
|
|
34
|
+
if (done) {
|
|
35
|
+
controller.close();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
loaded += value.byteLength;
|
|
39
|
+
const percent = total !== undefined ? Math.min(100, Math.round((loaded / total) * 100)) : undefined;
|
|
40
|
+
const { bytesPerSecond, etaSeconds } = formatTransferRate(loaded, now() - startMs, total);
|
|
41
|
+
options.controller?.setProgress(loaded, total);
|
|
42
|
+
onProgress({
|
|
43
|
+
loaded,
|
|
44
|
+
total,
|
|
45
|
+
percent,
|
|
46
|
+
indeterminate: total === undefined,
|
|
47
|
+
bytesPerSecond,
|
|
48
|
+
etaSeconds
|
|
49
|
+
});
|
|
50
|
+
controller.enqueue(value);
|
|
51
|
+
},
|
|
52
|
+
cancel(reason) {
|
|
53
|
+
return reader.cancel(reason);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return new Response(stream, {
|
|
57
|
+
status: response.status,
|
|
58
|
+
statusText: response.statusText,
|
|
59
|
+
headers: response.headers
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
export function observeXhrProgress(xhr, onProgress) {
|
|
63
|
+
const handleProgress = (raw) => {
|
|
64
|
+
const evt = raw;
|
|
65
|
+
const loaded = typeof evt.loaded === 'number' && Number.isFinite(evt.loaded) ? evt.loaded : 0;
|
|
66
|
+
const total = evt.lengthComputable && typeof evt.total === 'number' && Number.isFinite(evt.total) && evt.total > 0
|
|
67
|
+
? evt.total
|
|
68
|
+
: undefined;
|
|
69
|
+
onProgress({
|
|
70
|
+
loaded,
|
|
71
|
+
total,
|
|
72
|
+
percent: total !== undefined ? Math.min(100, Math.round((loaded / total) * 100)) : undefined,
|
|
73
|
+
indeterminate: total === undefined
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
xhr.addEventListener('progress', handleProgress);
|
|
77
|
+
return () => xhr.removeEventListener('progress', handleProgress);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Batch transfer state model (F26).
|
|
81
|
+
* Tracks per-item rows and overall summary; caller owns transport retry/cancel.
|
|
82
|
+
*/
|
|
83
|
+
export function createBatchTransfer(initialItems = []) {
|
|
84
|
+
const items = new Map();
|
|
85
|
+
for (const item of initialItems) {
|
|
86
|
+
items.set(item.id, { ...item, loaded: 0, status: 'pending' });
|
|
87
|
+
}
|
|
88
|
+
const listeners = new Set();
|
|
89
|
+
const compute = () => {
|
|
90
|
+
const list = [...items.values()].map((i) => ({ ...i }));
|
|
91
|
+
let totalBytes = 0;
|
|
92
|
+
let loadedBytes = 0;
|
|
93
|
+
let hasUnknown = list.length === 0;
|
|
94
|
+
let activeCount = 0;
|
|
95
|
+
let completedCount = 0;
|
|
96
|
+
let errorCount = 0;
|
|
97
|
+
for (const item of list) {
|
|
98
|
+
loadedBytes += item.loaded;
|
|
99
|
+
if (item.size !== undefined && item.size > 0)
|
|
100
|
+
totalBytes += item.size;
|
|
101
|
+
else
|
|
102
|
+
hasUnknown = true;
|
|
103
|
+
if (item.status === 'active')
|
|
104
|
+
activeCount++;
|
|
105
|
+
else if (item.status === 'completed')
|
|
106
|
+
completedCount++;
|
|
107
|
+
else if (item.status === 'error')
|
|
108
|
+
errorCount++;
|
|
109
|
+
}
|
|
110
|
+
const indeterminate = hasUnknown || totalBytes <= 0;
|
|
111
|
+
return {
|
|
112
|
+
items: list,
|
|
113
|
+
totalBytes: indeterminate ? undefined : totalBytes,
|
|
114
|
+
loadedBytes,
|
|
115
|
+
indeterminate,
|
|
116
|
+
percent: indeterminate ? undefined : Math.min(100, Math.round((loadedBytes / totalBytes) * 100)),
|
|
117
|
+
activeCount,
|
|
118
|
+
completedCount,
|
|
119
|
+
errorCount
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
let snapshot = compute();
|
|
123
|
+
const emit = () => {
|
|
124
|
+
snapshot = compute();
|
|
125
|
+
for (const l of [...listeners])
|
|
126
|
+
l(snapshot);
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
getSnapshot: () => snapshot,
|
|
130
|
+
subscribe(listener) {
|
|
131
|
+
listeners.add(listener);
|
|
132
|
+
return () => listeners.delete(listener);
|
|
133
|
+
},
|
|
134
|
+
add(item) {
|
|
135
|
+
items.set(item.id, { ...item, loaded: 0, status: 'pending' });
|
|
136
|
+
emit();
|
|
137
|
+
},
|
|
138
|
+
setStatus(id, status, error) {
|
|
139
|
+
const item = items.get(id);
|
|
140
|
+
if (!item)
|
|
141
|
+
return;
|
|
142
|
+
item.status = status;
|
|
143
|
+
item.error = status === 'error' ? error : undefined;
|
|
144
|
+
if (status === 'completed' && item.size !== undefined)
|
|
145
|
+
item.loaded = item.size;
|
|
146
|
+
emit();
|
|
147
|
+
},
|
|
148
|
+
updateProgress(id, loaded, size) {
|
|
149
|
+
const item = items.get(id);
|
|
150
|
+
if (!item)
|
|
151
|
+
return;
|
|
152
|
+
if (size !== undefined && size > 0)
|
|
153
|
+
item.size = size;
|
|
154
|
+
if (Number.isFinite(loaded) && loaded >= 0)
|
|
155
|
+
item.loaded = loaded;
|
|
156
|
+
if (item.status === 'pending')
|
|
157
|
+
item.status = 'active';
|
|
158
|
+
emit();
|
|
159
|
+
},
|
|
160
|
+
remove(id) {
|
|
161
|
+
if (items.delete(id))
|
|
162
|
+
emit();
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export type LoadingStatus = 'idle' | 'pending' | 'success' | 'error' | 'cancelled';
|
|
2
|
+
export interface ProgressSnapshot {
|
|
3
|
+
value: number | undefined;
|
|
4
|
+
max: number;
|
|
5
|
+
percent: number | undefined;
|
|
6
|
+
indeterminate: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface LoadingSnapshot<T = unknown> {
|
|
9
|
+
operationId: number;
|
|
10
|
+
status: LoadingStatus;
|
|
11
|
+
pending: boolean;
|
|
12
|
+
visible: boolean;
|
|
13
|
+
isSlow: boolean;
|
|
14
|
+
progress: ProgressSnapshot;
|
|
15
|
+
data: T | undefined;
|
|
16
|
+
error: unknown;
|
|
17
|
+
disposed: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface TimerScheduler {
|
|
20
|
+
setTimeout: (fn: () => void, ms: number) => ReturnType<typeof setTimeout>;
|
|
21
|
+
clearTimeout: (id: ReturnType<typeof setTimeout>) => void;
|
|
22
|
+
now: () => number;
|
|
23
|
+
}
|
|
24
|
+
export interface LoadingControllerOptions {
|
|
25
|
+
/** Milliseconds to wait before `visible` becomes true (anti-flicker). Default: 0. */
|
|
26
|
+
showDelay?: number;
|
|
27
|
+
/** Minimum milliseconds `visible` stays true once shown. Default: 0. */
|
|
28
|
+
minVisible?: number;
|
|
29
|
+
/** Milliseconds after start before `isSlow` becomes true. */
|
|
30
|
+
slowThreshold?: number;
|
|
31
|
+
/** Custom timer scheduler for deterministic testing. */
|
|
32
|
+
scheduler?: TimerScheduler;
|
|
33
|
+
}
|
|
34
|
+
export interface StartOperationOptions {
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
value?: number;
|
|
37
|
+
max?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface OperationContext<T = unknown> {
|
|
40
|
+
readonly id: number;
|
|
41
|
+
readonly signal: AbortSignal;
|
|
42
|
+
isCurrent: () => boolean;
|
|
43
|
+
setProgress: (value: number, max?: number) => void;
|
|
44
|
+
succeed: (data?: T) => void;
|
|
45
|
+
fail: (error: unknown) => void;
|
|
46
|
+
cancel: () => void;
|
|
47
|
+
}
|
|
48
|
+
export interface LoadingController<T = unknown> {
|
|
49
|
+
getSnapshot: () => LoadingSnapshot<T>;
|
|
50
|
+
subscribe: (listener: (snapshot: LoadingSnapshot<T>) => void) => () => void;
|
|
51
|
+
/**
|
|
52
|
+
* The context of the currently pending operation, or `null` when no
|
|
53
|
+
* operation is pending (idle, settled, or disposed). Lets integrations
|
|
54
|
+
* that did not call `start` themselves (e.g. the worker progress bridge)
|
|
55
|
+
* observe and settle the application's in-flight operation without
|
|
56
|
+
* superseding it.
|
|
57
|
+
*/
|
|
58
|
+
getCurrentOperation: () => OperationContext<T> | null;
|
|
59
|
+
start: (options?: StartOperationOptions) => OperationContext<T>;
|
|
60
|
+
run: <R = T>(task: (ctx: OperationContext<R>) => Promise<R>, options?: StartOperationOptions) => Promise<R | undefined>;
|
|
61
|
+
reset: () => void;
|
|
62
|
+
dispose: () => void;
|
|
63
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ShallowRef } from 'vue';
|
|
2
|
+
import type { TaskGroup, TaskGroupOptions, TaskGroupSnapshot } from './group.js';
|
|
3
|
+
import type { LoadingController, LoadingControllerOptions, LoadingSnapshot } from './types.js';
|
|
4
|
+
export interface UseVueLoadingControllerResult<T = unknown> {
|
|
5
|
+
snapshot: ShallowRef<LoadingSnapshot<T>>;
|
|
6
|
+
controller: LoadingController<T>;
|
|
7
|
+
start: LoadingController<T>['start'];
|
|
8
|
+
run: LoadingController<T>['run'];
|
|
9
|
+
reset: LoadingController<T>['reset'];
|
|
10
|
+
dispose: LoadingController<T>['dispose'];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Vue composable binding (F07).
|
|
14
|
+
*
|
|
15
|
+
* Disposal is bound to the effect scope or component instance that created the composable,
|
|
16
|
+
* so an explicit `dispose()` call ends this object: the shallow ref stops updating and the
|
|
17
|
+
* returned controller stays disposed. Unlike the React hook, there is no stable proxy to
|
|
18
|
+
* rebind — a component that disposes early calls `useLoadingController` again.
|
|
19
|
+
*/
|
|
20
|
+
export declare function useLoadingController<T = unknown>(options?: LoadingControllerOptions): UseVueLoadingControllerResult<T>;
|
|
21
|
+
export interface UseVueTaskGroupResult {
|
|
22
|
+
snapshot: ShallowRef<TaskGroupSnapshot>;
|
|
23
|
+
group: TaskGroup;
|
|
24
|
+
dispose: TaskGroup['dispose'];
|
|
25
|
+
}
|
|
26
|
+
export declare function useTaskGroup(options?: TaskGroupOptions): UseVueTaskGroupResult;
|
package/dist/vue.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { shallowRef } from 'vue';
|
|
3
|
+
import { createLoadingController } from './controller.js';
|
|
4
|
+
import { createTaskGroup } from './group.js';
|
|
5
|
+
function bindDisposal(cleanup) {
|
|
6
|
+
const api = vue;
|
|
7
|
+
if (typeof api.onScopeDispose === 'function' && typeof api.getCurrentScope === 'function' && api.getCurrentScope()) {
|
|
8
|
+
api.onScopeDispose(cleanup);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (typeof api.onUnmounted === 'function' && typeof api.getCurrentInstance === 'function' && api.getCurrentInstance()) {
|
|
12
|
+
api.onUnmounted(cleanup);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Vue composable binding (F07).
|
|
17
|
+
*
|
|
18
|
+
* Disposal is bound to the effect scope or component instance that created the composable,
|
|
19
|
+
* so an explicit `dispose()` call ends this object: the shallow ref stops updating and the
|
|
20
|
+
* returned controller stays disposed. Unlike the React hook, there is no stable proxy to
|
|
21
|
+
* rebind — a component that disposes early calls `useLoadingController` again.
|
|
22
|
+
*/
|
|
23
|
+
export function useLoadingController(options = {}) {
|
|
24
|
+
const controller = createLoadingController(options);
|
|
25
|
+
const snapshot = shallowRef(controller.getSnapshot());
|
|
26
|
+
const unsubscribe = controller.subscribe((next) => {
|
|
27
|
+
snapshot.value = next;
|
|
28
|
+
});
|
|
29
|
+
bindDisposal(() => {
|
|
30
|
+
unsubscribe();
|
|
31
|
+
controller.dispose();
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
snapshot,
|
|
35
|
+
controller,
|
|
36
|
+
start: controller.start,
|
|
37
|
+
run: controller.run,
|
|
38
|
+
reset: controller.reset,
|
|
39
|
+
dispose: controller.dispose
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function useTaskGroup(options = {}) {
|
|
43
|
+
const group = createTaskGroup(options);
|
|
44
|
+
const snapshot = shallowRef(group.getSnapshot());
|
|
45
|
+
const unsubscribe = group.subscribe((next) => {
|
|
46
|
+
snapshot.value = next;
|
|
47
|
+
});
|
|
48
|
+
bindDisposal(() => {
|
|
49
|
+
unsubscribe();
|
|
50
|
+
group.dispose();
|
|
51
|
+
});
|
|
52
|
+
return { snapshot, group, dispose: group.dispose };
|
|
53
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const STATE_MAP = {
|
|
2
|
+
idle: 'idle',
|
|
3
|
+
pending: 'loading',
|
|
4
|
+
success: 'success',
|
|
5
|
+
error: 'error',
|
|
6
|
+
cancelled: 'idle'
|
|
7
|
+
};
|
|
8
|
+
export function bindControllerToElement(controller, element) {
|
|
9
|
+
const sync = (snapshot) => {
|
|
10
|
+
element.setAttribute('loading', String(snapshot.visible));
|
|
11
|
+
element.setAttribute('data-wavelo-state', STATE_MAP[snapshot.status]);
|
|
12
|
+
if (!snapshot.progress.indeterminate && snapshot.progress.value !== undefined) {
|
|
13
|
+
element.setAttribute('value', String(snapshot.progress.value));
|
|
14
|
+
element.setAttribute('max', String(snapshot.progress.max));
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
element.removeAttribute('value');
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
sync(controller.getSnapshot());
|
|
21
|
+
return controller.subscribe(sync);
|
|
22
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,158 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wavelo/async",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Headless async loading controllers, anti-flicker timing, weighted task groups, and accessible DOM/framework bindings for Wavelo",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"license": "MIT",
|
|
6
|
-
"main": "index.js",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/princegoel0/wavelo.git",
|
|
10
10
|
"directory": "packages/async"
|
|
11
11
|
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/princegoel0/wavelo/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/princegoel0/wavelo#readme",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"loading",
|
|
18
|
+
"spinner",
|
|
19
|
+
"accessible",
|
|
20
|
+
"async",
|
|
21
|
+
"controller",
|
|
22
|
+
"anti-flicker",
|
|
23
|
+
"progress",
|
|
24
|
+
"react",
|
|
25
|
+
"vue",
|
|
26
|
+
"svelte",
|
|
27
|
+
"angular",
|
|
28
|
+
"wavelo",
|
|
29
|
+
"typescript"
|
|
30
|
+
],
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./dom": {
|
|
40
|
+
"types": "./dist/dom.d.ts",
|
|
41
|
+
"import": "./dist/dom.js"
|
|
42
|
+
},
|
|
43
|
+
"./react": {
|
|
44
|
+
"types": "./dist/react.d.ts",
|
|
45
|
+
"import": "./dist/react.js"
|
|
46
|
+
},
|
|
47
|
+
"./vue": {
|
|
48
|
+
"types": "./dist/vue.d.ts",
|
|
49
|
+
"import": "./dist/vue.js"
|
|
50
|
+
},
|
|
51
|
+
"./svelte": {
|
|
52
|
+
"types": "./dist/svelte.d.ts",
|
|
53
|
+
"import": "./dist/svelte.js"
|
|
54
|
+
},
|
|
55
|
+
"./angular": {
|
|
56
|
+
"types": "./dist/angular.d.ts",
|
|
57
|
+
"import": "./dist/angular.js"
|
|
58
|
+
},
|
|
59
|
+
"./web-components": {
|
|
60
|
+
"types": "./dist/web-components.d.ts",
|
|
61
|
+
"import": "./dist/web-components.js"
|
|
62
|
+
},
|
|
63
|
+
"./stages": {
|
|
64
|
+
"types": "./dist/stages.d.ts",
|
|
65
|
+
"import": "./dist/stages.js"
|
|
66
|
+
},
|
|
67
|
+
"./transfer": {
|
|
68
|
+
"types": "./dist/transfer.d.ts",
|
|
69
|
+
"import": "./dist/transfer.js"
|
|
70
|
+
},
|
|
71
|
+
"./ai": {
|
|
72
|
+
"types": "./dist/ai-stream.d.ts",
|
|
73
|
+
"import": "./dist/ai-stream.js"
|
|
74
|
+
},
|
|
75
|
+
"./skeleton": {
|
|
76
|
+
"types": "./dist/skeleton.d.ts",
|
|
77
|
+
"import": "./dist/skeleton.js"
|
|
78
|
+
},
|
|
79
|
+
"./boundary": {
|
|
80
|
+
"types": "./dist/boundary.d.ts",
|
|
81
|
+
"import": "./dist/boundary.js"
|
|
82
|
+
},
|
|
83
|
+
"./action-button": {
|
|
84
|
+
"types": "./dist/action-button.d.ts",
|
|
85
|
+
"import": "./dist/action-button.js"
|
|
86
|
+
},
|
|
87
|
+
"./runtime": {
|
|
88
|
+
"types": "./dist/runtime.d.ts",
|
|
89
|
+
"import": "./dist/runtime.js"
|
|
90
|
+
},
|
|
91
|
+
"./themes": {
|
|
92
|
+
"types": "./dist/themes.d.ts",
|
|
93
|
+
"import": "./dist/themes.js"
|
|
94
|
+
},
|
|
95
|
+
"./custom-registry": {
|
|
96
|
+
"types": "./dist/registry-ext.d.ts",
|
|
97
|
+
"import": "./dist/registry-ext.js"
|
|
98
|
+
},
|
|
99
|
+
"./schema": {
|
|
100
|
+
"types": "./dist/schema.d.ts",
|
|
101
|
+
"import": "./dist/schema.js"
|
|
102
|
+
},
|
|
103
|
+
"./export": {
|
|
104
|
+
"types": "./dist/export-tool.d.ts",
|
|
105
|
+
"import": "./dist/export-tool.js"
|
|
106
|
+
},
|
|
107
|
+
"./router": {
|
|
108
|
+
"types": "./dist/router.d.ts",
|
|
109
|
+
"import": "./dist/router.js"
|
|
110
|
+
},
|
|
111
|
+
"./testing": {
|
|
112
|
+
"types": "./dist/testing.d.ts",
|
|
113
|
+
"import": "./dist/testing.js"
|
|
114
|
+
},
|
|
115
|
+
"./innovation-ui": {
|
|
116
|
+
"types": "./dist/innovation-ui.d.ts",
|
|
117
|
+
"import": "./dist/innovation-ui.js"
|
|
118
|
+
},
|
|
119
|
+
"./innovation-progress": {
|
|
120
|
+
"types": "./dist/innovation-progress.d.ts",
|
|
121
|
+
"import": "./dist/innovation-progress.js"
|
|
122
|
+
},
|
|
123
|
+
"./innovation-session": {
|
|
124
|
+
"types": "./dist/innovation-session.d.ts",
|
|
125
|
+
"import": "./dist/innovation-session.js"
|
|
126
|
+
},
|
|
127
|
+
"./package.json": "./package.json"
|
|
128
|
+
},
|
|
129
|
+
"files": [
|
|
130
|
+
"dist",
|
|
131
|
+
"README.md",
|
|
132
|
+
"LICENSE"
|
|
133
|
+
],
|
|
134
|
+
"dependencies": {
|
|
135
|
+
"@wavelo/core": "0.9.0"
|
|
136
|
+
},
|
|
137
|
+
"peerDependencies": {
|
|
138
|
+
"react": ">=16.8.0 <20.0.0",
|
|
139
|
+
"vue": ">=3.0.0 <4.0.0",
|
|
140
|
+
"svelte": ">=5.0.0 <6.0.0",
|
|
141
|
+
"@angular/core": ">=14.0.0 <23.0.0"
|
|
142
|
+
},
|
|
143
|
+
"peerDependenciesMeta": {
|
|
144
|
+
"react": { "optional": true },
|
|
145
|
+
"vue": { "optional": true },
|
|
146
|
+
"svelte": { "optional": true },
|
|
147
|
+
"@angular/core": { "optional": true }
|
|
148
|
+
},
|
|
149
|
+
"scripts": {
|
|
150
|
+
"build": "node ../../scripts/clean.mjs dist && tsc -p tsconfig.json"
|
|
151
|
+
},
|
|
152
|
+
"author": "Prince Goel",
|
|
153
|
+
"engines": {
|
|
154
|
+
"node": ">=20.11.0"
|
|
155
|
+
},
|
|
12
156
|
"publishConfig": {
|
|
13
157
|
"access": "public"
|
|
14
158
|
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = {};
|