@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,53 @@
|
|
|
1
|
+
export type SkeletonPrimitiveKind = 'block' | 'text' | 'avatar' | 'row' | 'stack' | 'grid';
|
|
2
|
+
export interface SkeletonNode {
|
|
3
|
+
kind: SkeletonPrimitiveKind;
|
|
4
|
+
width?: string;
|
|
5
|
+
height?: string;
|
|
6
|
+
lines?: number;
|
|
7
|
+
columns?: number;
|
|
8
|
+
gap?: string;
|
|
9
|
+
radius?: string;
|
|
10
|
+
aspectRatio?: string;
|
|
11
|
+
children?: readonly SkeletonNode[];
|
|
12
|
+
}
|
|
13
|
+
export interface GeometryReservationOptions {
|
|
14
|
+
aspectRatio?: string;
|
|
15
|
+
minBlockSize?: string;
|
|
16
|
+
lines?: number;
|
|
17
|
+
lineHeight?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Validates and renders a serializable skeleton composition tree (F11 + F13).
|
|
21
|
+
* Bounds nesting/node counts, rejects arbitrary HTML/callbacks, and uses deterministic
|
|
22
|
+
* seeded line widths so SSR and client hydration always match.
|
|
23
|
+
*/
|
|
24
|
+
export declare function renderSkeletonTree(root: SkeletonNode, options?: {
|
|
25
|
+
seed?: number;
|
|
26
|
+
idPrefix?: string;
|
|
27
|
+
label?: string;
|
|
28
|
+
}): {
|
|
29
|
+
html: string;
|
|
30
|
+
nodeCount: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Content geometry reservation helper (F12).
|
|
34
|
+
* Computes deterministic CSS reservation declarations without hidden DOM cloning.
|
|
35
|
+
*/
|
|
36
|
+
export declare function reserveGeometry(options?: GeometryReservationOptions): Record<string, string>;
|
|
37
|
+
export interface SchemaDescriptor {
|
|
38
|
+
kind: 'table' | 'form' | 'card';
|
|
39
|
+
columns?: number;
|
|
40
|
+
rows?: number;
|
|
41
|
+
fields?: readonly {
|
|
42
|
+
type: string;
|
|
43
|
+
}[];
|
|
44
|
+
hasMedia?: boolean;
|
|
45
|
+
lines?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Deterministic schema-to-skeleton generator (F28).
|
|
49
|
+
*/
|
|
50
|
+
export declare function skeletonFromSchema(descriptor: SchemaDescriptor): {
|
|
51
|
+
tree: SkeletonNode;
|
|
52
|
+
diagnostics: readonly string[];
|
|
53
|
+
};
|
package/dist/skeleton.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
const MAX_DEPTH = 6;
|
|
2
|
+
const MAX_NODES = 100;
|
|
3
|
+
const SAFE_LEN_RE = /^[0-9]+(?:\.[0-9]+)?(?:px|rem|em|%|cqi|vw|vh)?$/i;
|
|
4
|
+
function escAttr(s) {
|
|
5
|
+
return s.replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
6
|
+
}
|
|
7
|
+
function safeLen(val) {
|
|
8
|
+
if (!val)
|
|
9
|
+
return undefined;
|
|
10
|
+
return SAFE_LEN_RE.test(val.trim()) ? val.trim() : undefined;
|
|
11
|
+
}
|
|
12
|
+
function mulberry32(seed) {
|
|
13
|
+
let a = seed >>> 0;
|
|
14
|
+
return () => {
|
|
15
|
+
a |= 0;
|
|
16
|
+
a = (a + 0x6d2b79f5) | 0;
|
|
17
|
+
let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
|
18
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
19
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Validates and renders a serializable skeleton composition tree (F11 + F13).
|
|
24
|
+
* Bounds nesting/node counts, rejects arbitrary HTML/callbacks, and uses deterministic
|
|
25
|
+
* seeded line widths so SSR and client hydration always match.
|
|
26
|
+
*/
|
|
27
|
+
export function renderSkeletonTree(root, options = {}) {
|
|
28
|
+
const rand = mulberry32(options.seed ?? 1337);
|
|
29
|
+
const idPrefix = options.idPrefix ?? 'wavelo-sk';
|
|
30
|
+
let nodeCount = 0;
|
|
31
|
+
const renderNode = (node, depth) => {
|
|
32
|
+
if (depth > MAX_DEPTH)
|
|
33
|
+
throw new RangeError(`Skeleton tree exceeds max depth of ${MAX_DEPTH}.`);
|
|
34
|
+
nodeCount += 1;
|
|
35
|
+
if (nodeCount > MAX_NODES)
|
|
36
|
+
throw new RangeError(`Skeleton tree exceeds max node count of ${MAX_NODES}.`);
|
|
37
|
+
const id = `${idPrefix}-${nodeCount}`;
|
|
38
|
+
const styleParts = [];
|
|
39
|
+
const w = safeLen(node.width);
|
|
40
|
+
const h = safeLen(node.height);
|
|
41
|
+
const gap = safeLen(node.gap);
|
|
42
|
+
const radius = safeLen(node.radius);
|
|
43
|
+
if (w)
|
|
44
|
+
styleParts.push(`width:${w}`);
|
|
45
|
+
if (h)
|
|
46
|
+
styleParts.push(`height:${h}`);
|
|
47
|
+
if (gap)
|
|
48
|
+
styleParts.push(`gap:${gap}`);
|
|
49
|
+
if (radius)
|
|
50
|
+
styleParts.push(`border-radius:${radius}`);
|
|
51
|
+
if (node.aspectRatio && /^\d+\s*\/\s*\d+$/.test(node.aspectRatio.trim())) {
|
|
52
|
+
styleParts.push(`aspect-ratio:${node.aspectRatio.trim()}`);
|
|
53
|
+
}
|
|
54
|
+
if (node.kind === 'text') {
|
|
55
|
+
const lines = Math.max(1, Math.min(20, node.lines ?? 3));
|
|
56
|
+
const items = Array.from({ length: lines }, (_, i) => {
|
|
57
|
+
const pct = i === lines - 1 ? Math.round(45 + rand() * 35) : Math.round(78 + rand() * 22);
|
|
58
|
+
return `<span class="wavelo__part wavelo-sk__line" style="width:${pct}%" aria-hidden="true"></span>`;
|
|
59
|
+
}).join('');
|
|
60
|
+
return `<div id="${escAttr(id)}" class="wavelo-sk wavelo-sk--text" style="${escAttr(styleParts.join(';'))}">${items}</div>`;
|
|
61
|
+
}
|
|
62
|
+
if (node.kind === 'avatar' || node.kind === 'block') {
|
|
63
|
+
const cls = node.kind === 'avatar' ? 'wavelo-sk wavelo-sk--avatar' : 'wavelo-sk wavelo-sk--block';
|
|
64
|
+
return `<div id="${escAttr(id)}" class="${cls}" style="${escAttr(styleParts.join(';'))}" aria-hidden="true"></div>`;
|
|
65
|
+
}
|
|
66
|
+
if (node.kind === 'grid') {
|
|
67
|
+
const cols = Math.max(1, Math.min(12, node.columns ?? 2));
|
|
68
|
+
styleParts.push(`display:grid`, `grid-template-columns:repeat(${cols},minmax(0,1fr))`);
|
|
69
|
+
}
|
|
70
|
+
else if (node.kind === 'row') {
|
|
71
|
+
styleParts.push(`display:flex`, `flex-direction:row`, `align-items:center`);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
styleParts.push(`display:flex`, `flex-direction:column`);
|
|
75
|
+
}
|
|
76
|
+
const inner = (node.children ?? []).map((child) => renderNode(child, depth + 1)).join('');
|
|
77
|
+
return `<div id="${escAttr(id)}" class="wavelo-sk wavelo-sk--${node.kind}" style="${escAttr(styleParts.join(';'))}">${inner}</div>`;
|
|
78
|
+
};
|
|
79
|
+
const body = renderNode(root, 1);
|
|
80
|
+
const aria = options.label ? ` role="status" aria-label="${escAttr(options.label)}"` : ` aria-hidden="true"`;
|
|
81
|
+
return {
|
|
82
|
+
html: `<div class="wavelo wavelo--skeleton wavelo-sk-root"${aria}>${body}</div>`,
|
|
83
|
+
nodeCount
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Content geometry reservation helper (F12).
|
|
88
|
+
* Computes deterministic CSS reservation declarations without hidden DOM cloning.
|
|
89
|
+
*/
|
|
90
|
+
export function reserveGeometry(options = {}) {
|
|
91
|
+
const styles = {};
|
|
92
|
+
if (options.aspectRatio && /^\d+(?:\.\d+)?\s*\/\s*\d+(?:\.\d+)?$/.test(options.aspectRatio.trim())) {
|
|
93
|
+
styles.aspectRatio = options.aspectRatio.trim();
|
|
94
|
+
}
|
|
95
|
+
const minBlock = safeLen(options.minBlockSize);
|
|
96
|
+
if (minBlock) {
|
|
97
|
+
styles.minBlockSize = minBlock;
|
|
98
|
+
}
|
|
99
|
+
else if (options.lines && options.lines > 0) {
|
|
100
|
+
const lh = options.lineHeight && options.lineHeight > 0 ? options.lineHeight : 1.5;
|
|
101
|
+
styles.minBlockSize = `${Math.round(options.lines * lh * 100) / 100}em`;
|
|
102
|
+
}
|
|
103
|
+
return styles;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Deterministic schema-to-skeleton generator (F28).
|
|
107
|
+
*/
|
|
108
|
+
export function skeletonFromSchema(descriptor) {
|
|
109
|
+
const diagnostics = [];
|
|
110
|
+
if (descriptor.kind === 'table') {
|
|
111
|
+
const cols = Math.max(1, Math.min(8, descriptor.columns ?? 4));
|
|
112
|
+
const rows = Math.max(1, Math.min(10, descriptor.rows ?? 4));
|
|
113
|
+
return {
|
|
114
|
+
tree: {
|
|
115
|
+
kind: 'stack',
|
|
116
|
+
gap: '0.5rem',
|
|
117
|
+
children: Array.from({ length: rows }, () => ({
|
|
118
|
+
kind: 'grid',
|
|
119
|
+
columns: cols,
|
|
120
|
+
gap: '0.5rem',
|
|
121
|
+
children: Array.from({ length: cols }, () => ({ kind: 'block', height: '1rem' }))
|
|
122
|
+
}))
|
|
123
|
+
},
|
|
124
|
+
diagnostics
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (descriptor.kind === 'form') {
|
|
128
|
+
const fields = descriptor.fields ?? [{ type: 'text' }, { type: 'text' }];
|
|
129
|
+
const children = fields.map((f) => {
|
|
130
|
+
if (f.type === 'textarea')
|
|
131
|
+
return { kind: 'block', height: '4.5rem' };
|
|
132
|
+
if (f.type === 'checkbox' || f.type === 'toggle')
|
|
133
|
+
return { kind: 'block', width: '1.5rem', height: '1.5rem' };
|
|
134
|
+
if (f.type !== 'text' && f.type !== 'select' && f.type !== 'number') {
|
|
135
|
+
diagnostics.push(`Unsupported form field type "${f.type}"; defaulted to text input placeholder.`);
|
|
136
|
+
}
|
|
137
|
+
return { kind: 'block', height: '2.25rem' };
|
|
138
|
+
});
|
|
139
|
+
return { tree: { kind: 'stack', gap: '0.75rem', children }, diagnostics };
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
tree: {
|
|
143
|
+
kind: 'stack',
|
|
144
|
+
gap: '0.75rem',
|
|
145
|
+
children: [
|
|
146
|
+
...(descriptor.hasMedia ? [{ kind: 'block', height: '8rem', aspectRatio: '16 / 9' }] : []),
|
|
147
|
+
{ kind: 'text', lines: descriptor.lines ?? 3 }
|
|
148
|
+
]
|
|
149
|
+
},
|
|
150
|
+
diagnostics
|
|
151
|
+
};
|
|
152
|
+
}
|
package/dist/stages.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export type StageStatus = 'pending' | 'active' | 'completed' | 'skipped' | 'failed';
|
|
2
|
+
export interface StageDefinition {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
weight?: number;
|
|
6
|
+
total?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface StageState {
|
|
9
|
+
id: string;
|
|
10
|
+
label: string;
|
|
11
|
+
weight: number;
|
|
12
|
+
status: StageStatus;
|
|
13
|
+
completed: number;
|
|
14
|
+
total: number | undefined;
|
|
15
|
+
error: unknown;
|
|
16
|
+
}
|
|
17
|
+
export interface StageProgressSnapshot {
|
|
18
|
+
stages: readonly StageState[];
|
|
19
|
+
currentStage: StageState | undefined;
|
|
20
|
+
assistiveLabel: string;
|
|
21
|
+
busy: boolean;
|
|
22
|
+
indeterminate: boolean;
|
|
23
|
+
percent: number | undefined;
|
|
24
|
+
hasFailure: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface StageProgressModel {
|
|
27
|
+
getSnapshot: () => StageProgressSnapshot;
|
|
28
|
+
subscribe: (listener: (snapshot: StageProgressSnapshot) => void) => () => void;
|
|
29
|
+
start: (id: string) => void;
|
|
30
|
+
update: (id: string, completed: number, total?: number) => void;
|
|
31
|
+
complete: (id: string) => void;
|
|
32
|
+
skip: (id: string) => void;
|
|
33
|
+
fail: (id: string, error?: unknown) => void;
|
|
34
|
+
reset: () => void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Stage-aware progress model (F14).
|
|
38
|
+
* Tracks named sequential stages with explicit weights and honest indeterminate states.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createStageProgress(definitions: readonly StageDefinition[]): StageProgressModel;
|
|
41
|
+
export interface WorkflowBranchNode {
|
|
42
|
+
id: string;
|
|
43
|
+
label: string;
|
|
44
|
+
dependencies?: readonly string[];
|
|
45
|
+
weight?: number;
|
|
46
|
+
total?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface WorkflowGraphSnapshot {
|
|
49
|
+
orderedIds: readonly string[];
|
|
50
|
+
branches: Readonly<Record<string, StageState>>;
|
|
51
|
+
busy: boolean;
|
|
52
|
+
indeterminate: boolean;
|
|
53
|
+
percent: number | undefined;
|
|
54
|
+
failedIds: readonly string[];
|
|
55
|
+
}
|
|
56
|
+
export interface WorkflowGraph {
|
|
57
|
+
getSnapshot: () => WorkflowGraphSnapshot;
|
|
58
|
+
subscribe: (listener: (snapshot: WorkflowGraphSnapshot) => void) => () => void;
|
|
59
|
+
startBranch: (id: string) => void;
|
|
60
|
+
updateBranch: (id: string, completed: number, total?: number) => void;
|
|
61
|
+
completeBranch: (id: string) => void;
|
|
62
|
+
failBranch: (id: string, error?: unknown) => void;
|
|
63
|
+
toAccessibleList: () => readonly string[];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Parallel workflow dependency graph view (F25).
|
|
67
|
+
* Validates bounded DAG size and rejects cycles; presentation only, not a job scheduler.
|
|
68
|
+
*/
|
|
69
|
+
export declare function createWorkflowGraph(nodes: readonly WorkflowBranchNode[]): WorkflowGraph;
|
package/dist/stages.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
function computeStageSnapshot(stages) {
|
|
2
|
+
let busy = false;
|
|
3
|
+
let hasFailure = false;
|
|
4
|
+
let hasUnknown = false;
|
|
5
|
+
let weightSum = 0;
|
|
6
|
+
let weightedFraction = 0;
|
|
7
|
+
for (const s of stages) {
|
|
8
|
+
if (s.status === 'active')
|
|
9
|
+
busy = true;
|
|
10
|
+
if (s.status === 'failed')
|
|
11
|
+
hasFailure = true;
|
|
12
|
+
if (s.status === 'skipped')
|
|
13
|
+
continue;
|
|
14
|
+
weightSum += s.weight;
|
|
15
|
+
if (s.status === 'completed') {
|
|
16
|
+
weightedFraction += s.weight;
|
|
17
|
+
}
|
|
18
|
+
else if (s.total !== undefined && s.total > 0) {
|
|
19
|
+
weightedFraction += s.weight * Math.max(0, Math.min(1, s.completed / s.total));
|
|
20
|
+
}
|
|
21
|
+
else if (s.status === 'active' || s.status === 'pending') {
|
|
22
|
+
hasUnknown = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const currentStage = stages.find((s) => s.status === 'active') ??
|
|
26
|
+
stages.find((s) => s.status === 'failed') ??
|
|
27
|
+
stages.find((s) => s.status === 'pending');
|
|
28
|
+
const indeterminate = weightSum === 0 || hasUnknown;
|
|
29
|
+
const percent = indeterminate ? undefined : Math.round((weightedFraction / weightSum) * 100);
|
|
30
|
+
const assistiveLabel = currentStage
|
|
31
|
+
? `${currentStage.label}: ${currentStage.status}${percent !== undefined ? ` (${percent}%)` : ''}`
|
|
32
|
+
: 'All stages completed';
|
|
33
|
+
return {
|
|
34
|
+
stages: stages.map((s) => ({ ...s })),
|
|
35
|
+
currentStage: currentStage ? { ...currentStage } : undefined,
|
|
36
|
+
assistiveLabel,
|
|
37
|
+
busy,
|
|
38
|
+
indeterminate,
|
|
39
|
+
percent,
|
|
40
|
+
hasFailure
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Stage-aware progress model (F14).
|
|
45
|
+
* Tracks named sequential stages with explicit weights and honest indeterminate states.
|
|
46
|
+
*/
|
|
47
|
+
export function createStageProgress(definitions) {
|
|
48
|
+
if (!Array.isArray(definitions) || definitions.length === 0) {
|
|
49
|
+
throw new RangeError('StageProgress requires at least one stage definition.');
|
|
50
|
+
}
|
|
51
|
+
const seen = new Set();
|
|
52
|
+
const initial = definitions.map((d) => {
|
|
53
|
+
if (seen.has(d.id)) {
|
|
54
|
+
throw new RangeError(`StageProgress requires unique stage ids; "${d.id}" is repeated.`);
|
|
55
|
+
}
|
|
56
|
+
seen.add(d.id);
|
|
57
|
+
const weight = d.weight ?? 1;
|
|
58
|
+
if (!Number.isFinite(weight) || weight <= 0) {
|
|
59
|
+
throw new RangeError(`Stage "${d.id}" weight must be a positive finite number.`);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
id: d.id,
|
|
63
|
+
label: d.label,
|
|
64
|
+
weight,
|
|
65
|
+
status: 'pending',
|
|
66
|
+
completed: 0,
|
|
67
|
+
total: d.total !== undefined && Number.isFinite(d.total) && d.total > 0 ? d.total : undefined,
|
|
68
|
+
error: undefined
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
let stages = initial.map((s) => ({ ...s }));
|
|
72
|
+
const listeners = new Set();
|
|
73
|
+
let snapshot = computeStageSnapshot(stages);
|
|
74
|
+
const emit = () => {
|
|
75
|
+
snapshot = computeStageSnapshot(stages);
|
|
76
|
+
for (const listener of [...listeners])
|
|
77
|
+
listener(snapshot);
|
|
78
|
+
};
|
|
79
|
+
const find = (id) => stages.find((s) => s.id === id);
|
|
80
|
+
return {
|
|
81
|
+
getSnapshot: () => snapshot,
|
|
82
|
+
subscribe(listener) {
|
|
83
|
+
listeners.add(listener);
|
|
84
|
+
return () => listeners.delete(listener);
|
|
85
|
+
},
|
|
86
|
+
start(id) {
|
|
87
|
+
const stage = find(id);
|
|
88
|
+
if (!stage || stage.status === 'completed')
|
|
89
|
+
return;
|
|
90
|
+
stage.status = 'active';
|
|
91
|
+
emit();
|
|
92
|
+
},
|
|
93
|
+
update(id, completed, total) {
|
|
94
|
+
const stage = find(id);
|
|
95
|
+
if (!stage || stage.status === 'completed' || stage.status === 'skipped')
|
|
96
|
+
return;
|
|
97
|
+
if (total !== undefined && Number.isFinite(total) && total > 0)
|
|
98
|
+
stage.total = total;
|
|
99
|
+
if (Number.isFinite(completed) && completed >= 0)
|
|
100
|
+
stage.completed = completed;
|
|
101
|
+
if (stage.status === 'pending')
|
|
102
|
+
stage.status = 'active';
|
|
103
|
+
emit();
|
|
104
|
+
},
|
|
105
|
+
complete(id) {
|
|
106
|
+
const stage = find(id);
|
|
107
|
+
if (!stage || stage.status === 'completed')
|
|
108
|
+
return;
|
|
109
|
+
stage.status = 'completed';
|
|
110
|
+
if (stage.total !== undefined)
|
|
111
|
+
stage.completed = stage.total;
|
|
112
|
+
emit();
|
|
113
|
+
},
|
|
114
|
+
skip(id) {
|
|
115
|
+
const stage = find(id);
|
|
116
|
+
if (!stage || stage.status === 'completed')
|
|
117
|
+
return;
|
|
118
|
+
stage.status = 'skipped';
|
|
119
|
+
emit();
|
|
120
|
+
},
|
|
121
|
+
fail(id, error) {
|
|
122
|
+
const stage = find(id);
|
|
123
|
+
if (!stage || stage.status === 'completed')
|
|
124
|
+
return;
|
|
125
|
+
stage.status = 'failed';
|
|
126
|
+
stage.error = error;
|
|
127
|
+
emit();
|
|
128
|
+
},
|
|
129
|
+
reset() {
|
|
130
|
+
stages = initial.map((s) => ({ ...s }));
|
|
131
|
+
emit();
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const MAX_WORKFLOW_NODES = 64;
|
|
136
|
+
/**
|
|
137
|
+
* Parallel workflow dependency graph view (F25).
|
|
138
|
+
* Validates bounded DAG size and rejects cycles; presentation only, not a job scheduler.
|
|
139
|
+
*/
|
|
140
|
+
export function createWorkflowGraph(nodes) {
|
|
141
|
+
if (nodes.length === 0 || nodes.length > MAX_WORKFLOW_NODES) {
|
|
142
|
+
throw new RangeError(`Workflow graph must contain 1..${MAX_WORKFLOW_NODES} nodes.`);
|
|
143
|
+
}
|
|
144
|
+
const byId = new Map();
|
|
145
|
+
for (const n of nodes) {
|
|
146
|
+
if (byId.has(n.id))
|
|
147
|
+
throw new Error(`Duplicate workflow node "${n.id}".`);
|
|
148
|
+
byId.set(n.id, n);
|
|
149
|
+
}
|
|
150
|
+
for (const n of nodes) {
|
|
151
|
+
for (const dep of n.dependencies ?? []) {
|
|
152
|
+
if (!byId.has(dep))
|
|
153
|
+
throw new Error(`Workflow node "${n.id}" depends on unknown node "${dep}".`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Topological sort + cycle detection (Kahn / DFS)
|
|
157
|
+
const visiting = new Set();
|
|
158
|
+
const visited = new Set();
|
|
159
|
+
const orderedIds = [];
|
|
160
|
+
const visit = (id) => {
|
|
161
|
+
if (visited.has(id))
|
|
162
|
+
return;
|
|
163
|
+
if (visiting.has(id))
|
|
164
|
+
throw new Error(`Cycle detected in workflow graph at "${id}".`);
|
|
165
|
+
visiting.add(id);
|
|
166
|
+
for (const dep of byId.get(id).dependencies ?? [])
|
|
167
|
+
visit(dep);
|
|
168
|
+
visiting.delete(id);
|
|
169
|
+
visited.add(id);
|
|
170
|
+
orderedIds.push(id);
|
|
171
|
+
};
|
|
172
|
+
for (const n of nodes)
|
|
173
|
+
visit(n.id);
|
|
174
|
+
const stageModel = createStageProgress(orderedIds.map((id) => {
|
|
175
|
+
const n = byId.get(id);
|
|
176
|
+
return { id: n.id, label: n.label, weight: n.weight, total: n.total };
|
|
177
|
+
}));
|
|
178
|
+
const mapSnapshot = (snap) => {
|
|
179
|
+
// `Object.fromEntries` creates an own property for every id, including `__proto__`,
|
|
180
|
+
// rather than letting a caller-selected key re-parent the snapshot object.
|
|
181
|
+
const branches = Object.fromEntries(snap.stages.map((s) => [s.id, s]));
|
|
182
|
+
const failedIds = snap.stages.filter((s) => s.status === 'failed').map((s) => s.id);
|
|
183
|
+
return {
|
|
184
|
+
orderedIds,
|
|
185
|
+
branches,
|
|
186
|
+
busy: snap.busy,
|
|
187
|
+
indeterminate: snap.indeterminate,
|
|
188
|
+
percent: snap.percent,
|
|
189
|
+
failedIds
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
return {
|
|
193
|
+
getSnapshot: () => mapSnapshot(stageModel.getSnapshot()),
|
|
194
|
+
subscribe(listener) {
|
|
195
|
+
return stageModel.subscribe((snap) => listener(mapSnapshot(snap)));
|
|
196
|
+
},
|
|
197
|
+
startBranch: stageModel.start,
|
|
198
|
+
updateBranch: stageModel.update,
|
|
199
|
+
completeBranch: stageModel.complete,
|
|
200
|
+
failBranch: stageModel.fail,
|
|
201
|
+
toAccessibleList() {
|
|
202
|
+
const snap = stageModel.getSnapshot();
|
|
203
|
+
return snap.stages.map((s) => `${s.label}: ${s.status}`);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}
|
package/dist/svelte.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TaskGroup, TaskGroupOptions, TaskGroupSnapshot } from './group.js';
|
|
2
|
+
import type { LoadingController, LoadingControllerOptions, LoadingSnapshot } from './types.js';
|
|
3
|
+
export type Subscriber<V> = (value: V, invalidate?: () => void) => void;
|
|
4
|
+
export interface LoadingStore<T = unknown> {
|
|
5
|
+
subscribe: (run: Subscriber<LoadingSnapshot<T>>, invalidate?: () => void) => () => void;
|
|
6
|
+
getSnapshot: LoadingController<T>['getSnapshot'];
|
|
7
|
+
getCurrentOperation: LoadingController<T>['getCurrentOperation'];
|
|
8
|
+
start: LoadingController<T>['start'];
|
|
9
|
+
run: LoadingController<T>['run'];
|
|
10
|
+
reset: LoadingController<T>['reset'];
|
|
11
|
+
dispose: LoadingController<T>['dispose'];
|
|
12
|
+
}
|
|
13
|
+
export declare function createLoadingStore<T = unknown>(options?: LoadingControllerOptions): LoadingStore<T>;
|
|
14
|
+
export interface TaskGroupStore {
|
|
15
|
+
subscribe: (run: Subscriber<TaskGroupSnapshot>, invalidate?: () => void) => () => void;
|
|
16
|
+
getSnapshot: TaskGroup['getSnapshot'];
|
|
17
|
+
register: TaskGroup['register'];
|
|
18
|
+
start: TaskGroup['start'];
|
|
19
|
+
update: TaskGroup['update'];
|
|
20
|
+
complete: TaskGroup['complete'];
|
|
21
|
+
fail: TaskGroup['fail'];
|
|
22
|
+
cancel: TaskGroup['cancel'];
|
|
23
|
+
remove: TaskGroup['remove'];
|
|
24
|
+
reset: TaskGroup['reset'];
|
|
25
|
+
dispose: TaskGroup['dispose'];
|
|
26
|
+
}
|
|
27
|
+
export declare function createTaskGroupStore(options?: TaskGroupOptions): TaskGroupStore;
|
package/dist/svelte.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createLoadingController } from './controller.js';
|
|
2
|
+
import { createTaskGroup } from './group.js';
|
|
3
|
+
export function createLoadingStore(options = {}) {
|
|
4
|
+
const controller = createLoadingController(options);
|
|
5
|
+
return {
|
|
6
|
+
subscribe(run, invalidate) {
|
|
7
|
+
run(controller.getSnapshot(), invalidate);
|
|
8
|
+
const unsubscribe = controller.subscribe((snapshot) => {
|
|
9
|
+
run(snapshot, invalidate);
|
|
10
|
+
invalidate?.();
|
|
11
|
+
});
|
|
12
|
+
return unsubscribe;
|
|
13
|
+
},
|
|
14
|
+
getSnapshot: controller.getSnapshot,
|
|
15
|
+
getCurrentOperation: controller.getCurrentOperation,
|
|
16
|
+
start: controller.start,
|
|
17
|
+
run: controller.run,
|
|
18
|
+
reset: controller.reset,
|
|
19
|
+
dispose: controller.dispose
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function createTaskGroupStore(options = {}) {
|
|
23
|
+
const group = createTaskGroup(options);
|
|
24
|
+
return {
|
|
25
|
+
subscribe(run, invalidate) {
|
|
26
|
+
run(group.getSnapshot(), invalidate);
|
|
27
|
+
const unsubscribe = group.subscribe((snapshot) => {
|
|
28
|
+
run(snapshot, invalidate);
|
|
29
|
+
invalidate?.();
|
|
30
|
+
});
|
|
31
|
+
return unsubscribe;
|
|
32
|
+
},
|
|
33
|
+
getSnapshot: group.getSnapshot,
|
|
34
|
+
register: group.register,
|
|
35
|
+
start: group.start,
|
|
36
|
+
update: group.update,
|
|
37
|
+
complete: group.complete,
|
|
38
|
+
fail: group.fail,
|
|
39
|
+
cancel: group.cancel,
|
|
40
|
+
remove: group.remove,
|
|
41
|
+
reset: group.reset,
|
|
42
|
+
dispose: group.dispose
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TimerScheduler } from './types.js';
|
|
2
|
+
export interface FakeClock extends TimerScheduler {
|
|
3
|
+
advance: (ms: number) => void;
|
|
4
|
+
pendingCount: () => number;
|
|
5
|
+
assertClean: () => void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Deterministic fake-clock driver for testing loading states without real sleeps (F31).
|
|
9
|
+
*/
|
|
10
|
+
export declare function createFakeClock(): FakeClock;
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic fake-clock driver for testing loading states without real sleeps (F31).
|
|
3
|
+
*/
|
|
4
|
+
export function createFakeClock() {
|
|
5
|
+
let nowMs = 0;
|
|
6
|
+
let nextId = 1;
|
|
7
|
+
const timers = new Map();
|
|
8
|
+
return {
|
|
9
|
+
setTimeout(fn, ms) {
|
|
10
|
+
const id = nextId++;
|
|
11
|
+
timers.set(id, { fn, at: nowMs + Math.max(0, ms) });
|
|
12
|
+
return id;
|
|
13
|
+
},
|
|
14
|
+
clearTimeout(id) {
|
|
15
|
+
timers.delete(id);
|
|
16
|
+
},
|
|
17
|
+
now: () => nowMs,
|
|
18
|
+
advance(ms) {
|
|
19
|
+
const target = nowMs + Math.max(0, ms);
|
|
20
|
+
while (true) {
|
|
21
|
+
let earliestId = null;
|
|
22
|
+
let earliestAt = Infinity;
|
|
23
|
+
for (const [id, entry] of timers.entries()) {
|
|
24
|
+
if (entry.at <= target && entry.at < earliestAt) {
|
|
25
|
+
earliestAt = entry.at;
|
|
26
|
+
earliestId = id;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (earliestId === null)
|
|
30
|
+
break;
|
|
31
|
+
const entry = timers.get(earliestId);
|
|
32
|
+
timers.delete(earliestId);
|
|
33
|
+
nowMs = entry.at;
|
|
34
|
+
entry.fn();
|
|
35
|
+
}
|
|
36
|
+
nowMs = target;
|
|
37
|
+
},
|
|
38
|
+
pendingCount: () => timers.size,
|
|
39
|
+
assertClean() {
|
|
40
|
+
if (timers.size > 0) {
|
|
41
|
+
throw new Error(`Expected 0 pending timers, found ${timers.size}.`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
package/dist/themes.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { LoaderConfig } from '@wavelo/core';
|
|
2
|
+
export interface ThemePack {
|
|
3
|
+
version: 1;
|
|
4
|
+
name: string;
|
|
5
|
+
tokens: Readonly<Record<string, string>>;
|
|
6
|
+
defaults?: Readonly<Partial<LoaderConfig>>;
|
|
7
|
+
overrides?: Readonly<Record<string, Readonly<Partial<LoaderConfig>>>>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Validated, serializable design-system theme pack (F20).
|
|
11
|
+
* Cannot rewrite frozen built-in presets; applies scoped tokens and defaults cleanly.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createThemePack(pack: ThemePack): {
|
|
14
|
+
pack: ThemePack;
|
|
15
|
+
toCss(selector?: string): string;
|
|
16
|
+
applyTo(element: HTMLElement): () => void;
|
|
17
|
+
resolveConfig(type: string, instanceConfig?: LoaderConfig): LoaderConfig;
|
|
18
|
+
};
|
|
19
|
+
export interface LowMotionPose {
|
|
20
|
+
designId: string;
|
|
21
|
+
pose: 'isometric-rest' | 'static-arc' | 'paused-frame' | 'subtle-opacity';
|
|
22
|
+
transform?: string;
|
|
23
|
+
opacity?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Authored low-motion treatment metadata (F29).
|
|
27
|
+
* Preserves visual identity without adding motion under `reducedMotion: 'always'`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getLowMotionPose(designId: string): LowMotionPose;
|