@mildastudio/milda 0.1.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 +45 -0
- package/dist/index.d.mts +724 -0
- package/dist/index.d.ts +724 -0
- package/dist/index.js +3094 -0
- package/dist/index.mjs +3053 -0
- package/package.json +34 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,3053 @@
|
|
|
1
|
+
// types/tokens.ts
|
|
2
|
+
var TOKEN_VALUE_KIND = {
|
|
3
|
+
color: "color",
|
|
4
|
+
spacing: "dimension",
|
|
5
|
+
radius: "dimension",
|
|
6
|
+
size: "dimension",
|
|
7
|
+
shadow: "shadow",
|
|
8
|
+
typography: "typography",
|
|
9
|
+
fontFamily: "fontFamily",
|
|
10
|
+
duration: "duration",
|
|
11
|
+
opacity: "opacity",
|
|
12
|
+
blur: "blur",
|
|
13
|
+
tonal: "tonal",
|
|
14
|
+
border: "border",
|
|
15
|
+
elevation: "facet",
|
|
16
|
+
ring: "facet",
|
|
17
|
+
backdrop: "facet",
|
|
18
|
+
none: "facet"
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// prelude/preludeV0.ts
|
|
22
|
+
var atoms = [
|
|
23
|
+
{
|
|
24
|
+
kind: "atom",
|
|
25
|
+
name: "activation",
|
|
26
|
+
doc: "invoke an action + emit event/payload on a trigger",
|
|
27
|
+
params: [{ name: "payload" }],
|
|
28
|
+
states: [{ id: "ready", initial: true }],
|
|
29
|
+
events: [{ name: "trigger" }],
|
|
30
|
+
transitions: [
|
|
31
|
+
{
|
|
32
|
+
from: "ready",
|
|
33
|
+
on: "trigger",
|
|
34
|
+
when: "enabled",
|
|
35
|
+
to: "ready",
|
|
36
|
+
emit: { event: "invoke", arg: "payload" }
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
emits: [{ name: "invoke" }],
|
|
40
|
+
note: "transducer (single state); foundational atom under almost every interactive archetype"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
kind: "atom",
|
|
44
|
+
name: "scheduler",
|
|
45
|
+
doc: "timed transition: auto-dismiss, auto-advance, debounce, delay",
|
|
46
|
+
modes: ["timeout", "debounce", "interval"],
|
|
47
|
+
params: [{ name: "t" }, { name: "mode" }],
|
|
48
|
+
states: [{ id: "idle", initial: true }, { id: "pending" }],
|
|
49
|
+
events: [{ name: "arm" }, { name: "cancel" }],
|
|
50
|
+
transitions: [
|
|
51
|
+
{ from: "idle", on: "arm", to: "pending" },
|
|
52
|
+
{ from: "pending", after: "t", to: "idle", emit: { event: "fire" } },
|
|
53
|
+
{ from: "pending", on: "arm", to: "pending", note: "restart (debounce)" },
|
|
54
|
+
{ from: "pending", on: "cancel", to: "idle" }
|
|
55
|
+
],
|
|
56
|
+
emits: [{ name: "fire" }],
|
|
57
|
+
note: "load-bearing: all time-based interactions compose from it"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
kind: "atom",
|
|
61
|
+
name: "toggle",
|
|
62
|
+
doc: "flip a boolean (BooleanInput core; tristate \u2192 +mixed)",
|
|
63
|
+
params: [{ name: "v", bind: true }],
|
|
64
|
+
states: [{ id: "off", initial: true }, { id: "on" }],
|
|
65
|
+
events: [{ name: "toggle" }, { name: "set", args: ["b"] }],
|
|
66
|
+
transitions: [
|
|
67
|
+
{ from: "off", on: "toggle", to: "on", emit: { event: "change", arg: true } },
|
|
68
|
+
{ from: "on", on: "toggle", to: "off", emit: { event: "change", arg: false } },
|
|
69
|
+
{ from: "any", on: "set", to: { expr: "b?on:off" }, note: "controlled sync, no emit" }
|
|
70
|
+
],
|
|
71
|
+
exposes: [{ state: "checked", when: "state==on" }],
|
|
72
|
+
emits: [{ name: "change" }]
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
kind: "atom",
|
|
76
|
+
name: "selection",
|
|
77
|
+
doc: "choose member(s) of a collection",
|
|
78
|
+
modes: ["single", "multiple", "range", "none"],
|
|
79
|
+
params: [{ name: "C" }, { name: "selected", bind: true }],
|
|
80
|
+
context: [{ name: "sel", type: "C|none", init: "none" }],
|
|
81
|
+
states: [{ id: "empty", initial: true }, { id: "chosen" }],
|
|
82
|
+
events: [{ name: "select", args: ["x"] }, { name: "clear" }, { name: "set", args: ["x"] }],
|
|
83
|
+
transitions: [
|
|
84
|
+
{
|
|
85
|
+
from: "any",
|
|
86
|
+
on: "select",
|
|
87
|
+
when: "x\u2208C",
|
|
88
|
+
to: "chosen",
|
|
89
|
+
ctx: [{ target: "sel", expr: "x" }],
|
|
90
|
+
emit: { event: "change", arg: "x" }
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
from: "chosen",
|
|
94
|
+
on: "clear",
|
|
95
|
+
to: "empty",
|
|
96
|
+
ctx: [{ target: "sel", expr: "none" }],
|
|
97
|
+
emit: { event: "change", arg: "none" }
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
from: "any",
|
|
101
|
+
on: "set",
|
|
102
|
+
to: { expr: "x?chosen:empty" },
|
|
103
|
+
ctx: [{ target: "sel", expr: "x" }],
|
|
104
|
+
note: "controlled sync, no emit"
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
exposes: [{ state: "selected", arg: "x", when: "state==chosen \u2227 sel==x" }],
|
|
108
|
+
emits: [{ name: "change" }],
|
|
109
|
+
note: "multiple=set; range=anchor+extent (date range, shift-click, cell range)"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
kind: "atom",
|
|
113
|
+
name: "browse",
|
|
114
|
+
doc: "move a cursor over a collection",
|
|
115
|
+
modes: ["roving", "spatial", "tree", "scroll-detent"],
|
|
116
|
+
requires: [{ anyOf: ["input.keyboard", "input.remote"], when: "mode\u2208{roving,tree}" }],
|
|
117
|
+
params: [{ name: "C" }, { name: "mode" }],
|
|
118
|
+
context: [{ name: "active", type: "C|none", init: "none" }],
|
|
119
|
+
events: [
|
|
120
|
+
{ name: "move", args: ["dir"] },
|
|
121
|
+
{ name: "to", args: ["x"] }
|
|
122
|
+
],
|
|
123
|
+
transitions: [
|
|
124
|
+
{
|
|
125
|
+
from: "any",
|
|
126
|
+
on: "move",
|
|
127
|
+
to: "any",
|
|
128
|
+
ctx: [{ target: "active", expr: "neighbor(active,dir,mode,wrap)" }],
|
|
129
|
+
emit: { event: "activeChanged", arg: "active" }
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
from: "any",
|
|
133
|
+
on: "to",
|
|
134
|
+
to: "any",
|
|
135
|
+
ctx: [{ target: "active", expr: "x" }],
|
|
136
|
+
emit: { event: "activeChanged", arg: "x" }
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
exposes: [{ state: "active", arg: "x", when: "active==x" }],
|
|
140
|
+
emits: [{ name: "activeChanged" }],
|
|
141
|
+
note: "neighbor(): roving=linear \xB7 spatial=2D \xB7 tree=in/out/sib \xB7 scroll-detent=nearest"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
kind: "atom",
|
|
145
|
+
name: "presentation",
|
|
146
|
+
doc: "manage a surface",
|
|
147
|
+
modes: ["inline", "popover", "menu", "sheet", "dialog", "push", "wheel"],
|
|
148
|
+
params: [{ name: "surface" }],
|
|
149
|
+
states: [{ id: "closed", initial: true }, { id: "open" }],
|
|
150
|
+
events: [{ name: "open" }, { name: "close" }, { name: "toggle" }],
|
|
151
|
+
transitions: [
|
|
152
|
+
{ from: "closed", on: "toggle|open", to: "open", emit: { event: "opened" } },
|
|
153
|
+
{ from: "open", on: "toggle|close", to: "closed", emit: { event: "closed" } }
|
|
154
|
+
],
|
|
155
|
+
exposes: [{ state: "open", when: "state==open" }],
|
|
156
|
+
emits: [{ name: "opened" }, { name: "closed" }],
|
|
157
|
+
note: "surface is realization-only"
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
kind: "atom",
|
|
161
|
+
name: "dismiss",
|
|
162
|
+
doc: "close on a configured trigger",
|
|
163
|
+
params: [{ name: "when" }],
|
|
164
|
+
states: [{ id: "armed", initial: true }],
|
|
165
|
+
events: [{ name: "trigger" }],
|
|
166
|
+
transitions: [
|
|
167
|
+
{ from: "armed", on: "trigger", to: "armed", emit: { event: "dismissRequested" } }
|
|
168
|
+
],
|
|
169
|
+
emits: [{ name: "dismissRequested" }],
|
|
170
|
+
note: "trigger \u2208 configured [outside, escape, commit, swipe-down, timeout]"
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
kind: "atom",
|
|
174
|
+
name: "focus-scope",
|
|
175
|
+
doc: "trap / contain / restore focus within a region (modal a11y)",
|
|
176
|
+
requires: [{ anyOf: ["input.keyboard", "input.remote"] }],
|
|
177
|
+
states: [{ id: "inactive", initial: true }, { id: "active" }],
|
|
178
|
+
events: [{ name: "activate" }, { name: "deactivate" }],
|
|
179
|
+
transitions: [
|
|
180
|
+
{
|
|
181
|
+
from: "inactive",
|
|
182
|
+
on: "activate",
|
|
183
|
+
to: "active",
|
|
184
|
+
note: "save prior focus; move focus into region; trap Tab"
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
from: "active",
|
|
188
|
+
on: "deactivate",
|
|
189
|
+
to: "inactive",
|
|
190
|
+
note: "release trap; restore prior focus"
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
note: "no visual states (exposes none) \u2014 a behaviour guarantee, not a paint surface; realized as a focus trap on web, OS-owned on native sheets"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
kind: "atom",
|
|
197
|
+
name: "value-entry",
|
|
198
|
+
doc: "free text/value entry; commit on change|blur|enter",
|
|
199
|
+
params: [{ name: "value", bind: true }, { name: "commit" }],
|
|
200
|
+
context: [
|
|
201
|
+
{ name: "value", type: "V" },
|
|
202
|
+
{ name: "draft", type: "V", init: "value" }
|
|
203
|
+
],
|
|
204
|
+
states: [{ id: "idle", initial: true }, { id: "editing" }],
|
|
205
|
+
events: [
|
|
206
|
+
{ name: "focus" },
|
|
207
|
+
{ name: "input", args: ["t"] },
|
|
208
|
+
{ name: "enter" },
|
|
209
|
+
{ name: "blur" },
|
|
210
|
+
{ name: "set", args: ["v"] }
|
|
211
|
+
],
|
|
212
|
+
transitions: [
|
|
213
|
+
{ from: "idle", on: "focus", to: "editing" },
|
|
214
|
+
{
|
|
215
|
+
from: "editing",
|
|
216
|
+
on: "input",
|
|
217
|
+
to: "editing",
|
|
218
|
+
ctx: [{ target: "draft", expr: "t" }],
|
|
219
|
+
when: "change\u2208commit",
|
|
220
|
+
emit: { event: "change", arg: "t" },
|
|
221
|
+
note: "value:=t only when change\u2208commit"
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
from: "editing",
|
|
225
|
+
on: "enter",
|
|
226
|
+
when: "enter\u2208commit",
|
|
227
|
+
to: "editing",
|
|
228
|
+
ctx: [{ target: "value", expr: "draft" }],
|
|
229
|
+
emit: { event: "change", arg: "draft" }
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
from: "editing",
|
|
233
|
+
on: "blur",
|
|
234
|
+
to: "idle",
|
|
235
|
+
note: "when blur\u2208commit: value:=draft, emit change(draft); else draft:=value"
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
from: "any",
|
|
239
|
+
on: "set",
|
|
240
|
+
to: "any",
|
|
241
|
+
ctx: [
|
|
242
|
+
{ target: "value", expr: "v" },
|
|
243
|
+
{ target: "draft", expr: "v" }
|
|
244
|
+
],
|
|
245
|
+
note: "controlled, no emit"
|
|
246
|
+
}
|
|
247
|
+
],
|
|
248
|
+
exposes: [
|
|
249
|
+
{ state: "focused", when: "state==editing" },
|
|
250
|
+
{ state: "empty", when: "value empty" },
|
|
251
|
+
{ state: "dirty", when: "draft\u2260value" }
|
|
252
|
+
],
|
|
253
|
+
emits: [{ name: "change" }]
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
kind: "atom",
|
|
257
|
+
name: "range",
|
|
258
|
+
doc: "value(s) along a min/max track (single/dual thumb)",
|
|
259
|
+
params: [
|
|
260
|
+
{ name: "value", bind: true },
|
|
261
|
+
{ name: "min" },
|
|
262
|
+
{ name: "max" },
|
|
263
|
+
{ name: "step" },
|
|
264
|
+
{ name: "thumbs" }
|
|
265
|
+
],
|
|
266
|
+
context: [
|
|
267
|
+
{ name: "value", type: "V|{lo,hi}" },
|
|
268
|
+
{ name: "active", type: "thumb|none", init: "none" }
|
|
269
|
+
],
|
|
270
|
+
states: [{ id: "idle", initial: true }, { id: "dragging" }],
|
|
271
|
+
events: [
|
|
272
|
+
{ name: "grab", args: ["t"] },
|
|
273
|
+
{ name: "to", args: ["v"] },
|
|
274
|
+
{ name: "release" },
|
|
275
|
+
{ name: "by", args: ["t", "d"] },
|
|
276
|
+
{ name: "set", args: ["v"] }
|
|
277
|
+
],
|
|
278
|
+
transitions: [
|
|
279
|
+
{ from: "idle", on: "grab", to: "dragging", ctx: [{ target: "active", expr: "t" }] },
|
|
280
|
+
{
|
|
281
|
+
from: "dragging",
|
|
282
|
+
on: "to",
|
|
283
|
+
to: "dragging",
|
|
284
|
+
ctx: [{ target: "value[active]", expr: "clamp+snap(v); lo\u2264hi" }],
|
|
285
|
+
emit: { event: "change", arg: "value" }
|
|
286
|
+
},
|
|
287
|
+
{ from: "dragging", on: "release", to: "idle", emit: { event: "commit", arg: "value" } },
|
|
288
|
+
{
|
|
289
|
+
from: "idle",
|
|
290
|
+
on: "by",
|
|
291
|
+
to: "idle",
|
|
292
|
+
ctx: [{ target: "value[t]", expr: "clamp(value[t]+d)" }],
|
|
293
|
+
emit: { event: "change", arg: "value" },
|
|
294
|
+
note: "keyboard"
|
|
295
|
+
},
|
|
296
|
+
{ from: "any", on: "set", to: "any", ctx: [{ target: "value", expr: "v" }] }
|
|
297
|
+
],
|
|
298
|
+
exposes: [{ state: "active", arg: "t", when: "state==dragging \u2227 active==t" }],
|
|
299
|
+
emits: [{ name: "change" }, { name: "commit" }],
|
|
300
|
+
note: "live (change) vs committed (commit)"
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
kind: "atom",
|
|
304
|
+
name: "stepping",
|
|
305
|
+
doc: "increment/decrement a value",
|
|
306
|
+
params: [{ name: "value", bind: true }, { name: "min" }, { name: "max" }, { name: "step" }],
|
|
307
|
+
context: [{ name: "value", type: "number" }],
|
|
308
|
+
events: [{ name: "inc" }, { name: "dec" }, { name: "set", args: ["v"] }],
|
|
309
|
+
transitions: [
|
|
310
|
+
{
|
|
311
|
+
from: "any",
|
|
312
|
+
on: "inc",
|
|
313
|
+
when: "value+step\u2264max",
|
|
314
|
+
to: "any",
|
|
315
|
+
ctx: [{ target: "value", expr: "value+step" }],
|
|
316
|
+
emit: { event: "change", arg: "value" }
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
from: "any",
|
|
320
|
+
on: "dec",
|
|
321
|
+
when: "value-step\u2265min",
|
|
322
|
+
to: "any",
|
|
323
|
+
ctx: [{ target: "value", expr: "value-step" }],
|
|
324
|
+
emit: { event: "change", arg: "value" }
|
|
325
|
+
},
|
|
326
|
+
{ from: "any", on: "set", to: "any", ctx: [{ target: "value", expr: "clamp(v)" }] }
|
|
327
|
+
],
|
|
328
|
+
exposes: [
|
|
329
|
+
{ state: "atMin", when: "value\u2264min" },
|
|
330
|
+
{ state: "atMax", when: "value\u2265max" }
|
|
331
|
+
],
|
|
332
|
+
emits: [{ name: "change" }]
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
kind: "atom",
|
|
336
|
+
name: "validation",
|
|
337
|
+
doc: "valid/invalid against rules (PURE \u2014 does not listen to input)",
|
|
338
|
+
params: [{ name: "value" }, { name: "rules" }],
|
|
339
|
+
context: [{ name: "errors", type: "list", init: "[]" }],
|
|
340
|
+
states: [{ id: "pristine", initial: true }, { id: "valid" }, { id: "invalid" }],
|
|
341
|
+
events: [{ name: "check" }, { name: "reset" }],
|
|
342
|
+
transitions: [
|
|
343
|
+
{
|
|
344
|
+
from: "any",
|
|
345
|
+
on: "check",
|
|
346
|
+
to: { expr: "eval(rules)?valid:invalid" },
|
|
347
|
+
ctx: [{ target: "errors", expr: "eval(rules).errors" }]
|
|
348
|
+
},
|
|
349
|
+
{ from: "any", on: "reset", to: "pristine", ctx: [{ target: "errors", expr: "[]" }] }
|
|
350
|
+
],
|
|
351
|
+
exposes: [
|
|
352
|
+
{ state: "invalid", when: "state==invalid" },
|
|
353
|
+
{ state: "valid", when: "state==valid" },
|
|
354
|
+
{ state: "pristine", when: "state==pristine" }
|
|
355
|
+
],
|
|
356
|
+
emits: [{ name: "validity" }],
|
|
357
|
+
note: "the when:change|blur|submit policy = a wire from value-entry/submission into check"
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
kind: "atom",
|
|
361
|
+
name: "submission",
|
|
362
|
+
doc: "form-level orchestration: collective validation, submit, focus-first-error",
|
|
363
|
+
params: [{ name: "fields" }],
|
|
364
|
+
context: [{ name: "fields", type: "set<validation>" }],
|
|
365
|
+
states: [{ id: "editing", initial: true }, { id: "submitting" }, { id: "submitted" }],
|
|
366
|
+
events: [{ name: "submit" }, { name: "success" }, { name: "failure", args: ["e"] }],
|
|
367
|
+
transitions: [
|
|
368
|
+
{
|
|
369
|
+
from: "editing",
|
|
370
|
+
on: "submit",
|
|
371
|
+
to: "editing",
|
|
372
|
+
do: "broadcast fields.check",
|
|
373
|
+
note: "when allValid \u2192 submitting emit submitStart(values); else \u2192 editing do firstInvalid.focus"
|
|
374
|
+
},
|
|
375
|
+
{ from: "submitting", on: "success", to: "submitted", emit: { event: "submitSuccess" } },
|
|
376
|
+
{
|
|
377
|
+
from: "submitting",
|
|
378
|
+
on: "failure",
|
|
379
|
+
to: "editing",
|
|
380
|
+
emit: { event: "submitError", arg: "e" }
|
|
381
|
+
}
|
|
382
|
+
],
|
|
383
|
+
exposes: [
|
|
384
|
+
{ state: "loading", when: "state==submitting" },
|
|
385
|
+
{ state: "dirty", when: "any(fields,f\u2192f.dirty)" }
|
|
386
|
+
],
|
|
387
|
+
emits: [{ name: "submitStart" }, { name: "submitSuccess" }, { name: "submitError" }],
|
|
388
|
+
note: "fields: DYNAMIC set of validation machines; FAN-OUT broadcast + FAN-IN aggregate/select"
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
kind: "atom",
|
|
392
|
+
name: "gesture",
|
|
393
|
+
doc: "swipe | long-press | pinch | pan | drag | drop",
|
|
394
|
+
modes: ["swipe", "long-press", "pinch", "pan", "drag", "drop"],
|
|
395
|
+
requires: [{ anyOf: ["input.touch"], when: "per gesture" }],
|
|
396
|
+
params: [{ name: "kind" }, { name: "thresholds" }],
|
|
397
|
+
context: [{ name: "start" }, { name: "current" }, { name: "t0" }],
|
|
398
|
+
states: [{ id: "idle", initial: true }, { id: "tracking" }, { id: "recognized" }],
|
|
399
|
+
events: [{ name: "down", args: ["p"] }, { name: "move", args: ["p"] }, { name: "up" }],
|
|
400
|
+
transitions: [
|
|
401
|
+
{ from: "idle", on: "down", to: "tracking", ctx: [{ target: "start", expr: "p" }] },
|
|
402
|
+
{
|
|
403
|
+
from: "tracking",
|
|
404
|
+
on: "move",
|
|
405
|
+
to: "tracking",
|
|
406
|
+
ctx: [{ target: "current", expr: "p" }],
|
|
407
|
+
when: "exceeds(\u03B8)",
|
|
408
|
+
emit: { event: "begin" },
|
|
409
|
+
note: "recognized when threshold exceeded"
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
from: "tracking",
|
|
413
|
+
after: "t",
|
|
414
|
+
to: "recognized",
|
|
415
|
+
emit: { event: "begin" },
|
|
416
|
+
note: "long-press"
|
|
417
|
+
},
|
|
418
|
+
{ from: "tracking", on: "up", to: "idle", note: "canceled, threshold not met" },
|
|
419
|
+
{ from: "recognized", on: "move", to: "recognized", emit: { event: "update", arg: "delta" } },
|
|
420
|
+
{ from: "recognized", on: "up", to: "idle", emit: { event: "end" } }
|
|
421
|
+
],
|
|
422
|
+
exposes: [{ state: "dragging", when: "state==recognized" }],
|
|
423
|
+
emits: [{ name: "begin" }, { name: "update" }, { name: "end" }],
|
|
424
|
+
note: "load-bearing: all drag-based interactions compose from it"
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
kind: "atom",
|
|
428
|
+
name: "async-state",
|
|
429
|
+
doc: "idle | loading | success | error lifecycle",
|
|
430
|
+
states: [{ id: "idle", initial: true }, { id: "loading" }, { id: "success" }, { id: "error" }],
|
|
431
|
+
events: [{ name: "start" }, { name: "resolve", args: ["v"] }, { name: "reject", args: ["e"] }],
|
|
432
|
+
transitions: [
|
|
433
|
+
{ from: "any", on: "start", to: "loading", do: "run" },
|
|
434
|
+
{ from: "loading", on: "resolve", to: "success", emit: { event: "success", arg: "v" } },
|
|
435
|
+
{ from: "loading", on: "reject", to: "error", emit: { event: "error", arg: "e" } }
|
|
436
|
+
],
|
|
437
|
+
exposes: [
|
|
438
|
+
{ state: "loading", when: "state==loading" },
|
|
439
|
+
{ state: "success", when: "state==success" },
|
|
440
|
+
{ state: "error", when: "state==error" }
|
|
441
|
+
],
|
|
442
|
+
emits: [{ name: "success" }, { name: "error" }]
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
kind: "atom",
|
|
446
|
+
name: "navigation",
|
|
447
|
+
doc: "switch between destinations (carries a history stack)",
|
|
448
|
+
params: [{ name: "dests" }],
|
|
449
|
+
context: [{ name: "stack", type: "list", init: "[root]" }],
|
|
450
|
+
events: [{ name: "go", args: ["d"] }, { name: "back" }],
|
|
451
|
+
transitions: [
|
|
452
|
+
{
|
|
453
|
+
from: "any",
|
|
454
|
+
on: "go",
|
|
455
|
+
to: "any",
|
|
456
|
+
ctx: [{ target: "stack", expr: "stack.push(d)" }],
|
|
457
|
+
emit: { event: "navigate", arg: "current" }
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
from: "any",
|
|
461
|
+
on: "back",
|
|
462
|
+
when: "|stack|>1",
|
|
463
|
+
to: "any",
|
|
464
|
+
ctx: [{ target: "stack", expr: "stack.pop()" }],
|
|
465
|
+
emit: { event: "navigate", arg: "current" }
|
|
466
|
+
}
|
|
467
|
+
],
|
|
468
|
+
exposes: [{ state: "current", arg: "d", when: "current==d" }],
|
|
469
|
+
emits: [{ name: "navigate" }],
|
|
470
|
+
note: "history stack shared with undo/redo, wizard-back; richer than selection.single + activation"
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
kind: "atom",
|
|
474
|
+
name: "scroll",
|
|
475
|
+
doc: "observe scroll position: infinite-load, scroll-spy, reveal-on-scroll, parallax",
|
|
476
|
+
params: [{ name: "region" }],
|
|
477
|
+
context: [{ name: "pos", init: "0" }],
|
|
478
|
+
events: [{ name: "scrolled", args: ["p"] }],
|
|
479
|
+
transitions: [
|
|
480
|
+
{
|
|
481
|
+
from: "any",
|
|
482
|
+
on: "scrolled",
|
|
483
|
+
to: "any",
|
|
484
|
+
ctx: [{ target: "pos", expr: "p" }],
|
|
485
|
+
emit: { event: "atEnd", arg: "p" },
|
|
486
|
+
note: "emit atEnd when p\u2265max, nearEnd when p\u2265max-\u03B8"
|
|
487
|
+
}
|
|
488
|
+
],
|
|
489
|
+
exposes: [
|
|
490
|
+
{ state: "atStart", when: "pos\u22640" },
|
|
491
|
+
{ state: "atEnd", when: "pos\u2265max" },
|
|
492
|
+
{ state: "scrolled", when: "pos>0" }
|
|
493
|
+
],
|
|
494
|
+
emits: [{ name: "atEnd" }, { name: "nearEnd" }],
|
|
495
|
+
note: "atEnd \u2192 wire \u2192 async-state.start = infinite-load"
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
kind: "atom",
|
|
499
|
+
name: "progress",
|
|
500
|
+
doc: "determinate / indeterminate completion",
|
|
501
|
+
modes: ["determinate", "indeterminate"],
|
|
502
|
+
params: [{ name: "value" }, { name: "max" }],
|
|
503
|
+
events: [{ name: "set", args: ["v"] }],
|
|
504
|
+
transitions: [
|
|
505
|
+
{
|
|
506
|
+
from: "any",
|
|
507
|
+
on: "set",
|
|
508
|
+
to: "any",
|
|
509
|
+
ctx: [{ target: "value", expr: "v" }],
|
|
510
|
+
emit: { event: "change", arg: "value" }
|
|
511
|
+
}
|
|
512
|
+
],
|
|
513
|
+
exposes: [{ state: "complete", when: "value\u2265max" }],
|
|
514
|
+
emits: [{ name: "change" }]
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
kind: "atom",
|
|
518
|
+
name: "liveness",
|
|
519
|
+
doc: "announce dynamic changes (polite/assertive)",
|
|
520
|
+
modes: ["polite", "assertive"],
|
|
521
|
+
requires: [{ anyOf: ["a11y.screenreader"] }],
|
|
522
|
+
events: [{ name: "announce", args: ["msg"] }],
|
|
523
|
+
transitions: [
|
|
524
|
+
{ from: "any", on: "announce", to: "any", emit: { event: "announced", arg: "msg" } }
|
|
525
|
+
],
|
|
526
|
+
emits: [{ name: "announced" }]
|
|
527
|
+
}
|
|
528
|
+
];
|
|
529
|
+
var composites = [
|
|
530
|
+
{
|
|
531
|
+
kind: "composite",
|
|
532
|
+
name: "disclosure",
|
|
533
|
+
builtFrom: ["toggle", "presentation"],
|
|
534
|
+
uses: [
|
|
535
|
+
{ atom: "toggle", as: "T" },
|
|
536
|
+
{ atom: "presentation", as: "P", params: { surface: "inline" } }
|
|
537
|
+
],
|
|
538
|
+
composition: [{ kind: "wire", from: "T.change", to: "P.toggle" }],
|
|
539
|
+
note: "\u2248 toggle(expanded) + presentation(inline); exposes expanded"
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
kind: "composite",
|
|
543
|
+
name: "typeahead",
|
|
544
|
+
builtFrom: ["scheduler", "browse"],
|
|
545
|
+
uses: [
|
|
546
|
+
{ atom: "scheduler", as: "S", params: { mode: "debounce" } },
|
|
547
|
+
{ atom: "browse", as: "B" }
|
|
548
|
+
],
|
|
549
|
+
note: "jump to a member by typed prefix; requires input.keyboard"
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
kind: "composite",
|
|
553
|
+
name: "dnd",
|
|
554
|
+
builtFrom: ["gesture", "ordering"],
|
|
555
|
+
note: "drag-and-drop move/reorder across containers; ordering is a non-behavior (collection mutation)"
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
kind: "composite",
|
|
559
|
+
name: "resize",
|
|
560
|
+
builtFrom: ["gesture"],
|
|
561
|
+
uses: [{ atom: "gesture", as: "G", params: { kind: "drag" } }],
|
|
562
|
+
note: "drag-resize a region/panel; requires input.pointer"
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
kind: "composite",
|
|
566
|
+
name: "auto-dismiss",
|
|
567
|
+
builtFrom: ["scheduler"],
|
|
568
|
+
uses: [{ atom: "scheduler", as: "S", params: { mode: "timeout" } }],
|
|
569
|
+
composition: [{ kind: "wire", from: "S.fire", to: "dismissRequested" }],
|
|
570
|
+
note: "self-close after a timeout (toast)"
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
kind: "composite",
|
|
574
|
+
name: "stepping-nav",
|
|
575
|
+
builtFrom: ["navigation"],
|
|
576
|
+
note: "\u2248 navigation(ordered) + constraint; ordered progress through steps; exposes active, complete"
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
kind: "composite",
|
|
580
|
+
name: "pressability",
|
|
581
|
+
builtFrom: ["gesture"],
|
|
582
|
+
note: "press/hover/active feedback (ripple, highlight); contributes pressed/hovered feedback states ONLY \u2014 does not fire the action (that is activation)"
|
|
583
|
+
}
|
|
584
|
+
];
|
|
585
|
+
var archetypes = [
|
|
586
|
+
{
|
|
587
|
+
kind: "archetype",
|
|
588
|
+
name: "Button",
|
|
589
|
+
group: "Actions",
|
|
590
|
+
contract: "label/icon, fires action",
|
|
591
|
+
produces: { level: "phrase", interactive: true },
|
|
592
|
+
anatomy: [
|
|
593
|
+
{ name: "icon", role: "icon", optional: true },
|
|
594
|
+
{ name: "label", role: "text" }
|
|
595
|
+
],
|
|
596
|
+
composes: ["activation", "pressability", "async-state?"],
|
|
597
|
+
realizationNote: "Material FAB/elevated/tonal; iOS .borderedProminent"
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
kind: "archetype",
|
|
601
|
+
name: "ToggleButton",
|
|
602
|
+
group: "Actions",
|
|
603
|
+
contract: "on/off action",
|
|
604
|
+
produces: { level: "phrase", interactive: true },
|
|
605
|
+
anatomy: [
|
|
606
|
+
{ name: "indicator", role: "icon", optional: true },
|
|
607
|
+
{ name: "label", role: "text" }
|
|
608
|
+
],
|
|
609
|
+
composes: ["toggle", "pressability"]
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
kind: "archetype",
|
|
613
|
+
name: "MenuButton",
|
|
614
|
+
group: "Actions",
|
|
615
|
+
contract: "opens a menu of actions",
|
|
616
|
+
produces: { level: "region", interactive: false },
|
|
617
|
+
anatomy: [
|
|
618
|
+
{
|
|
619
|
+
name: "trigger",
|
|
620
|
+
role: "control",
|
|
621
|
+
children: [
|
|
622
|
+
{ name: "label", role: "text" },
|
|
623
|
+
{ name: "indicator", role: "icon", optional: true }
|
|
624
|
+
]
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
name: "surface",
|
|
628
|
+
role: "container",
|
|
629
|
+
children: [{ name: "item", role: "item", children: [{ name: "label", role: "text" }] }]
|
|
630
|
+
}
|
|
631
|
+
],
|
|
632
|
+
composes: ["presentation", "browse", "typeahead?", "dismiss"]
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
kind: "archetype",
|
|
636
|
+
name: "Link",
|
|
637
|
+
group: "Actions",
|
|
638
|
+
contract: "navigates",
|
|
639
|
+
produces: { level: "phrase", interactive: true },
|
|
640
|
+
anatomy: [
|
|
641
|
+
{ name: "label", role: "text" },
|
|
642
|
+
{ name: "icon", role: "icon", optional: true }
|
|
643
|
+
],
|
|
644
|
+
composes: ["activation", "pressability"]
|
|
645
|
+
},
|
|
646
|
+
{
|
|
647
|
+
kind: "archetype",
|
|
648
|
+
name: "Form",
|
|
649
|
+
group: "Inputs",
|
|
650
|
+
contract: "a set of fields, one submit",
|
|
651
|
+
produces: { level: "region", interactive: false },
|
|
652
|
+
anatomy: [
|
|
653
|
+
{ name: "content", role: "container" },
|
|
654
|
+
{ name: "submit", role: "control", children: [{ name: "label", role: "text" }] },
|
|
655
|
+
{ name: "error", role: "text", optional: true }
|
|
656
|
+
],
|
|
657
|
+
composes: ["submission"]
|
|
658
|
+
},
|
|
659
|
+
{
|
|
660
|
+
kind: "archetype",
|
|
661
|
+
name: "Field",
|
|
662
|
+
group: "Inputs",
|
|
663
|
+
contract: "label + control + error/help wrapper",
|
|
664
|
+
produces: { level: "region", interactive: false },
|
|
665
|
+
anatomy: [
|
|
666
|
+
{ name: "label", role: "text" },
|
|
667
|
+
{ name: "control", role: "container" },
|
|
668
|
+
{ name: "help", role: "text", optional: true },
|
|
669
|
+
{ name: "error", role: "text", optional: true }
|
|
670
|
+
],
|
|
671
|
+
composes: ["validation"]
|
|
672
|
+
},
|
|
673
|
+
{
|
|
674
|
+
kind: "archetype",
|
|
675
|
+
name: "TextField",
|
|
676
|
+
group: "Inputs",
|
|
677
|
+
contract: "string value",
|
|
678
|
+
produces: { level: "region", interactive: false },
|
|
679
|
+
anatomy: [
|
|
680
|
+
{ name: "icon", role: "icon", optional: true },
|
|
681
|
+
{ name: "control", role: "input" }
|
|
682
|
+
],
|
|
683
|
+
composes: ["value-entry", "validation?"]
|
|
684
|
+
},
|
|
685
|
+
{
|
|
686
|
+
kind: "archetype",
|
|
687
|
+
name: "TextArea",
|
|
688
|
+
group: "Inputs",
|
|
689
|
+
contract: "multiline string value",
|
|
690
|
+
produces: { level: "region", interactive: false },
|
|
691
|
+
anatomy: [{ name: "control", role: "input" }],
|
|
692
|
+
composes: ["value-entry", "validation?"]
|
|
693
|
+
},
|
|
694
|
+
{
|
|
695
|
+
kind: "archetype",
|
|
696
|
+
name: "SearchField",
|
|
697
|
+
group: "Inputs",
|
|
698
|
+
contract: "query string + clear",
|
|
699
|
+
produces: { level: "region", interactive: false },
|
|
700
|
+
anatomy: [
|
|
701
|
+
{ name: "icon", role: "icon", optional: true },
|
|
702
|
+
{ name: "control", role: "input" },
|
|
703
|
+
{ name: "clear", role: "control", optional: true }
|
|
704
|
+
],
|
|
705
|
+
composes: ["value-entry", "filter?"]
|
|
706
|
+
},
|
|
707
|
+
{
|
|
708
|
+
kind: "archetype",
|
|
709
|
+
name: "BooleanInput",
|
|
710
|
+
group: "Inputs",
|
|
711
|
+
contract: "one bool",
|
|
712
|
+
produces: { level: "region", interactive: false },
|
|
713
|
+
anatomy: [
|
|
714
|
+
{ name: "control", role: "input" },
|
|
715
|
+
{ name: "indicator", role: "icon" },
|
|
716
|
+
{ name: "label", role: "text", optional: true }
|
|
717
|
+
],
|
|
718
|
+
composes: ["toggle"],
|
|
719
|
+
realizationNote: "iOS: checkbox \u2192 switch (no indeterminate)"
|
|
720
|
+
},
|
|
721
|
+
{
|
|
722
|
+
kind: "archetype",
|
|
723
|
+
name: "ChoiceGroup",
|
|
724
|
+
group: "Inputs",
|
|
725
|
+
contract: "one-of-N",
|
|
726
|
+
produces: { level: "region", interactive: false },
|
|
727
|
+
anatomy: [
|
|
728
|
+
{
|
|
729
|
+
name: "option",
|
|
730
|
+
role: "item",
|
|
731
|
+
children: [
|
|
732
|
+
{ name: "indicator", role: "icon" },
|
|
733
|
+
{ name: "label", role: "text" }
|
|
734
|
+
]
|
|
735
|
+
}
|
|
736
|
+
],
|
|
737
|
+
composes: ["selection.single", "browse"],
|
|
738
|
+
realizationNote: "radio stack | segmented (node.group); iOS: radio \u2192 wheel/segmented"
|
|
739
|
+
},
|
|
740
|
+
{
|
|
741
|
+
kind: "archetype",
|
|
742
|
+
name: "SingleSelect",
|
|
743
|
+
group: "Inputs",
|
|
744
|
+
contract: "one of a known set",
|
|
745
|
+
produces: { level: "region", interactive: false },
|
|
746
|
+
anatomy: [
|
|
747
|
+
{
|
|
748
|
+
name: "trigger",
|
|
749
|
+
role: "control",
|
|
750
|
+
children: [
|
|
751
|
+
{ name: "value", role: "text" },
|
|
752
|
+
{ name: "indicator", role: "icon" }
|
|
753
|
+
]
|
|
754
|
+
},
|
|
755
|
+
{
|
|
756
|
+
name: "surface",
|
|
757
|
+
role: "container",
|
|
758
|
+
children: [
|
|
759
|
+
{
|
|
760
|
+
name: "option",
|
|
761
|
+
role: "item",
|
|
762
|
+
children: [
|
|
763
|
+
{ name: "check", role: "icon", optional: true },
|
|
764
|
+
{ name: "label", role: "text" }
|
|
765
|
+
]
|
|
766
|
+
}
|
|
767
|
+
]
|
|
768
|
+
}
|
|
769
|
+
],
|
|
770
|
+
composes: ["selection.single", "presentation", "browse", "dismiss", "typeahead?"],
|
|
771
|
+
uses: [
|
|
772
|
+
{ atom: "activation", as: "A" },
|
|
773
|
+
{ atom: "presentation", as: "P", params: { surface: "popover" } },
|
|
774
|
+
{ atom: "selection", as: "S", params: { mode: "single", over: "options" } },
|
|
775
|
+
{ atom: "browse", as: "B", params: { over: "options", mode: "roving" } },
|
|
776
|
+
{ atom: "dismiss", as: "D", params: { when: "[outside,escape]" } }
|
|
777
|
+
],
|
|
778
|
+
composition: [
|
|
779
|
+
{ kind: "wire", from: "A.invoke", to: "P.toggle" },
|
|
780
|
+
{ kind: "wire", from: "P.opened", to: "B.to", arg: "S.sel ?? first" },
|
|
781
|
+
{ kind: "gate", machine: "D", activeWhen: "P.open" },
|
|
782
|
+
{ kind: "wire", from: "D.dismissRequested", to: "P.close" },
|
|
783
|
+
{ kind: "wire", from: "option-activate", to: "S.select", arg: "B.active" },
|
|
784
|
+
{ kind: "wire", from: "S.change", to: "P.close", when: "closeOnSelect" }
|
|
785
|
+
],
|
|
786
|
+
exposes: [
|
|
787
|
+
{ state: "open", when: "P.open" },
|
|
788
|
+
{ state: "selected", when: "S.selected" },
|
|
789
|
+
{ state: "active", when: "B.active" }
|
|
790
|
+
],
|
|
791
|
+
emits: [{ name: "change", from: "S.change" }],
|
|
792
|
+
realize: [
|
|
793
|
+
{
|
|
794
|
+
target: "web",
|
|
795
|
+
surface: "popover",
|
|
796
|
+
browse: "roving",
|
|
797
|
+
commit: "explicit",
|
|
798
|
+
note: "place bottom-start; flip; matchWidth; commit on click/enter"
|
|
799
|
+
},
|
|
800
|
+
{
|
|
801
|
+
target: "ios",
|
|
802
|
+
when: "style=wheel",
|
|
803
|
+
surface: "inline-wheel",
|
|
804
|
+
browse: "scroll-detent",
|
|
805
|
+
commit: "continuous",
|
|
806
|
+
drop: ["activation", "dismiss"],
|
|
807
|
+
wire: [{ from: "B.active-changed", to: "S.select", arg: "B.active" }]
|
|
808
|
+
}
|
|
809
|
+
],
|
|
810
|
+
realizationNote: "web popover-listbox \xB7 Android dropdown/dialog \xB7 iOS menu/sheet/push/wheel"
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
kind: "archetype",
|
|
814
|
+
name: "MultiSelect",
|
|
815
|
+
group: "Inputs",
|
|
816
|
+
contract: "subset of a set",
|
|
817
|
+
produces: { level: "region", interactive: false },
|
|
818
|
+
anatomy: [
|
|
819
|
+
{
|
|
820
|
+
name: "trigger",
|
|
821
|
+
role: "control",
|
|
822
|
+
children: [
|
|
823
|
+
{ name: "value", role: "text" },
|
|
824
|
+
{ name: "indicator", role: "icon" }
|
|
825
|
+
]
|
|
826
|
+
},
|
|
827
|
+
{
|
|
828
|
+
name: "surface",
|
|
829
|
+
role: "container",
|
|
830
|
+
children: [
|
|
831
|
+
{
|
|
832
|
+
name: "option",
|
|
833
|
+
role: "item",
|
|
834
|
+
children: [
|
|
835
|
+
{ name: "check", role: "icon" },
|
|
836
|
+
{ name: "label", role: "text" }
|
|
837
|
+
]
|
|
838
|
+
}
|
|
839
|
+
]
|
|
840
|
+
}
|
|
841
|
+
],
|
|
842
|
+
composes: ["selection.multiple", "presentation", "browse", "dismiss"]
|
|
843
|
+
},
|
|
844
|
+
{
|
|
845
|
+
kind: "archetype",
|
|
846
|
+
name: "Combobox",
|
|
847
|
+
group: "Inputs",
|
|
848
|
+
contract: "filtered single-select w/ entry",
|
|
849
|
+
produces: { level: "region", interactive: false },
|
|
850
|
+
anatomy: [
|
|
851
|
+
{ name: "control", role: "input" },
|
|
852
|
+
{
|
|
853
|
+
name: "surface",
|
|
854
|
+
role: "container",
|
|
855
|
+
children: [{ name: "option", role: "item", children: [{ name: "label", role: "text" }] }]
|
|
856
|
+
}
|
|
857
|
+
],
|
|
858
|
+
composes: ["value-entry", "filter", "selection.single", "browse", "presentation", "dismiss"]
|
|
859
|
+
},
|
|
860
|
+
{
|
|
861
|
+
kind: "archetype",
|
|
862
|
+
name: "Slider",
|
|
863
|
+
group: "Inputs",
|
|
864
|
+
contract: "value(s) on a range",
|
|
865
|
+
produces: { level: "region", interactive: false },
|
|
866
|
+
anatomy: [
|
|
867
|
+
{
|
|
868
|
+
name: "track",
|
|
869
|
+
role: "container",
|
|
870
|
+
children: [
|
|
871
|
+
{ name: "range", role: "container", optional: true },
|
|
872
|
+
{ name: "thumb", role: "control" }
|
|
873
|
+
]
|
|
874
|
+
},
|
|
875
|
+
{ name: "value", role: "text", optional: true }
|
|
876
|
+
],
|
|
877
|
+
composes: ["range", "gesture(pan)"]
|
|
878
|
+
},
|
|
879
|
+
{
|
|
880
|
+
kind: "archetype",
|
|
881
|
+
name: "Stepper",
|
|
882
|
+
group: "Inputs",
|
|
883
|
+
contract: "number \xB1",
|
|
884
|
+
produces: { level: "region", interactive: false },
|
|
885
|
+
anatomy: [
|
|
886
|
+
{ name: "decrement", role: "control", children: [{ name: "icon", role: "icon" }] },
|
|
887
|
+
{ name: "control", role: "input" },
|
|
888
|
+
{ name: "increment", role: "control", children: [{ name: "icon", role: "icon" }] }
|
|
889
|
+
],
|
|
890
|
+
composes: ["stepping", "value-entry"]
|
|
891
|
+
},
|
|
892
|
+
{
|
|
893
|
+
kind: "archetype",
|
|
894
|
+
name: "DatePicker",
|
|
895
|
+
group: "Inputs",
|
|
896
|
+
contract: "date value",
|
|
897
|
+
produces: { level: "region", interactive: false },
|
|
898
|
+
anatomy: [
|
|
899
|
+
{
|
|
900
|
+
name: "trigger",
|
|
901
|
+
role: "control",
|
|
902
|
+
children: [
|
|
903
|
+
{ name: "value", role: "text" },
|
|
904
|
+
{ name: "icon", role: "icon" }
|
|
905
|
+
]
|
|
906
|
+
},
|
|
907
|
+
{
|
|
908
|
+
name: "surface",
|
|
909
|
+
role: "container",
|
|
910
|
+
children: [
|
|
911
|
+
{
|
|
912
|
+
name: "header",
|
|
913
|
+
role: "container",
|
|
914
|
+
children: [
|
|
915
|
+
{ name: "prev", role: "control" },
|
|
916
|
+
{ name: "title", role: "text" },
|
|
917
|
+
{ name: "next", role: "control" }
|
|
918
|
+
]
|
|
919
|
+
},
|
|
920
|
+
{
|
|
921
|
+
name: "grid",
|
|
922
|
+
role: "container",
|
|
923
|
+
children: [{ name: "day", role: "item", children: [{ name: "label", role: "text" }] }]
|
|
924
|
+
}
|
|
925
|
+
]
|
|
926
|
+
}
|
|
927
|
+
],
|
|
928
|
+
composes: ["selection.single", "presentation", "browse", "dismiss", "masking"],
|
|
929
|
+
realizationNote: "web calendar-grid \xB7 iOS wheel (momentum+detent+haptic) \xB7 Android dialog"
|
|
930
|
+
},
|
|
931
|
+
{
|
|
932
|
+
kind: "archetype",
|
|
933
|
+
name: "TimePicker",
|
|
934
|
+
group: "Inputs",
|
|
935
|
+
contract: "time value",
|
|
936
|
+
produces: { level: "region", interactive: false },
|
|
937
|
+
anatomy: [
|
|
938
|
+
{
|
|
939
|
+
name: "trigger",
|
|
940
|
+
role: "control",
|
|
941
|
+
children: [
|
|
942
|
+
{ name: "value", role: "text" },
|
|
943
|
+
{ name: "icon", role: "icon" }
|
|
944
|
+
]
|
|
945
|
+
},
|
|
946
|
+
{
|
|
947
|
+
name: "surface",
|
|
948
|
+
role: "container",
|
|
949
|
+
children: [
|
|
950
|
+
{
|
|
951
|
+
name: "column",
|
|
952
|
+
role: "item",
|
|
953
|
+
children: [
|
|
954
|
+
{ name: "option", role: "item", children: [{ name: "label", role: "text" }] }
|
|
955
|
+
]
|
|
956
|
+
}
|
|
957
|
+
]
|
|
958
|
+
}
|
|
959
|
+
],
|
|
960
|
+
composes: ["selection.single", "presentation", "browse", "dismiss", "masking"],
|
|
961
|
+
realizationNote: "iOS wheel \xB7 Android dialog"
|
|
962
|
+
},
|
|
963
|
+
{
|
|
964
|
+
kind: "archetype",
|
|
965
|
+
name: "ColorPicker",
|
|
966
|
+
group: "Inputs",
|
|
967
|
+
contract: "color value",
|
|
968
|
+
produces: { level: "region", interactive: false },
|
|
969
|
+
anatomy: [
|
|
970
|
+
{
|
|
971
|
+
name: "trigger",
|
|
972
|
+
role: "control",
|
|
973
|
+
children: [
|
|
974
|
+
{ name: "swatch", role: "icon" },
|
|
975
|
+
{ name: "value", role: "text" }
|
|
976
|
+
]
|
|
977
|
+
},
|
|
978
|
+
{
|
|
979
|
+
name: "surface",
|
|
980
|
+
role: "container",
|
|
981
|
+
children: [
|
|
982
|
+
{ name: "area", role: "container" },
|
|
983
|
+
{ name: "hue", role: "container" },
|
|
984
|
+
{ name: "input", role: "input" }
|
|
985
|
+
]
|
|
986
|
+
}
|
|
987
|
+
],
|
|
988
|
+
composes: ["range", "value-entry", "presentation", "dismiss"]
|
|
989
|
+
},
|
|
990
|
+
{
|
|
991
|
+
kind: "archetype",
|
|
992
|
+
name: "FileUpload",
|
|
993
|
+
group: "Inputs",
|
|
994
|
+
contract: "file(s)",
|
|
995
|
+
produces: { level: "region", interactive: false },
|
|
996
|
+
anatomy: [
|
|
997
|
+
{
|
|
998
|
+
name: "dropzone",
|
|
999
|
+
role: "container",
|
|
1000
|
+
children: [
|
|
1001
|
+
{ name: "icon", role: "icon" },
|
|
1002
|
+
{ name: "label", role: "text" }
|
|
1003
|
+
]
|
|
1004
|
+
},
|
|
1005
|
+
{ name: "input", role: "input" },
|
|
1006
|
+
{
|
|
1007
|
+
name: "list",
|
|
1008
|
+
role: "container",
|
|
1009
|
+
optional: true,
|
|
1010
|
+
children: [
|
|
1011
|
+
{
|
|
1012
|
+
name: "item",
|
|
1013
|
+
role: "item",
|
|
1014
|
+
children: [
|
|
1015
|
+
{ name: "name", role: "text" },
|
|
1016
|
+
{ name: "remove", role: "control" }
|
|
1017
|
+
]
|
|
1018
|
+
}
|
|
1019
|
+
]
|
|
1020
|
+
}
|
|
1021
|
+
],
|
|
1022
|
+
composes: ["activation", "gesture(drop)?", "async-state"]
|
|
1023
|
+
},
|
|
1024
|
+
{
|
|
1025
|
+
kind: "archetype",
|
|
1026
|
+
name: "TagsInput",
|
|
1027
|
+
group: "Inputs",
|
|
1028
|
+
contract: "list of tokens",
|
|
1029
|
+
produces: { level: "region", interactive: false },
|
|
1030
|
+
anatomy: [
|
|
1031
|
+
{
|
|
1032
|
+
name: "tag",
|
|
1033
|
+
role: "item",
|
|
1034
|
+
children: [
|
|
1035
|
+
{ name: "label", role: "text" },
|
|
1036
|
+
{ name: "remove", role: "control" }
|
|
1037
|
+
]
|
|
1038
|
+
},
|
|
1039
|
+
{ name: "control", role: "input" }
|
|
1040
|
+
],
|
|
1041
|
+
composes: ["value-entry", "selection.multiple"]
|
|
1042
|
+
},
|
|
1043
|
+
{
|
|
1044
|
+
kind: "archetype",
|
|
1045
|
+
name: "Rating",
|
|
1046
|
+
group: "Inputs",
|
|
1047
|
+
contract: "discrete score",
|
|
1048
|
+
produces: { level: "region", interactive: false },
|
|
1049
|
+
anatomy: [{ name: "item", role: "item", children: [{ name: "icon", role: "icon" }] }],
|
|
1050
|
+
composes: ["selection.single", "pressability"]
|
|
1051
|
+
},
|
|
1052
|
+
{
|
|
1053
|
+
kind: "archetype",
|
|
1054
|
+
name: "Disclosure",
|
|
1055
|
+
group: "Disclosure",
|
|
1056
|
+
contract: "expand region (a.k.a. Collapsible)",
|
|
1057
|
+
produces: { level: "region", interactive: false },
|
|
1058
|
+
anatomy: [
|
|
1059
|
+
{
|
|
1060
|
+
name: "trigger",
|
|
1061
|
+
role: "control",
|
|
1062
|
+
children: [
|
|
1063
|
+
{ name: "label", role: "text" },
|
|
1064
|
+
{ name: "indicator", role: "icon" }
|
|
1065
|
+
]
|
|
1066
|
+
},
|
|
1067
|
+
{ name: "panel", role: "container" }
|
|
1068
|
+
],
|
|
1069
|
+
composes: ["disclosure"]
|
|
1070
|
+
},
|
|
1071
|
+
{
|
|
1072
|
+
kind: "archetype",
|
|
1073
|
+
name: "Accordion",
|
|
1074
|
+
group: "Disclosure",
|
|
1075
|
+
contract: "group of disclosures (single/multi)",
|
|
1076
|
+
produces: { level: "region", interactive: false },
|
|
1077
|
+
anatomy: [
|
|
1078
|
+
{
|
|
1079
|
+
name: "item",
|
|
1080
|
+
role: "item",
|
|
1081
|
+
children: [
|
|
1082
|
+
{
|
|
1083
|
+
name: "header",
|
|
1084
|
+
role: "control",
|
|
1085
|
+
children: [
|
|
1086
|
+
{ name: "label", role: "text" },
|
|
1087
|
+
{ name: "indicator", role: "icon" }
|
|
1088
|
+
]
|
|
1089
|
+
},
|
|
1090
|
+
{ name: "panel", role: "container" }
|
|
1091
|
+
]
|
|
1092
|
+
}
|
|
1093
|
+
],
|
|
1094
|
+
composes: ["disclosure", "selection"]
|
|
1095
|
+
},
|
|
1096
|
+
{
|
|
1097
|
+
kind: "archetype",
|
|
1098
|
+
name: "Tabs",
|
|
1099
|
+
group: "Disclosure",
|
|
1100
|
+
contract: "switch panels",
|
|
1101
|
+
produces: { level: "region", interactive: false },
|
|
1102
|
+
anatomy: [
|
|
1103
|
+
{
|
|
1104
|
+
name: "list",
|
|
1105
|
+
role: "container",
|
|
1106
|
+
children: [{ name: "tab", role: "control", children: [{ name: "label", role: "text" }] }]
|
|
1107
|
+
},
|
|
1108
|
+
{ name: "panel", role: "container" }
|
|
1109
|
+
],
|
|
1110
|
+
composes: ["navigation", "browse"],
|
|
1111
|
+
realizationNote: "mobile: swipe-between; web: no swipe"
|
|
1112
|
+
},
|
|
1113
|
+
{
|
|
1114
|
+
kind: "archetype",
|
|
1115
|
+
name: "Dialog",
|
|
1116
|
+
group: "Disclosure",
|
|
1117
|
+
contract: "blocking layer (a.k.a. Modal)",
|
|
1118
|
+
produces: { level: "region", interactive: false },
|
|
1119
|
+
anatomy: [
|
|
1120
|
+
{ name: "trigger", role: "control", children: [{ name: "label", role: "text" }] },
|
|
1121
|
+
{ name: "backdrop", role: "container", optional: true },
|
|
1122
|
+
{
|
|
1123
|
+
name: "surface",
|
|
1124
|
+
role: "container",
|
|
1125
|
+
children: [
|
|
1126
|
+
{ name: "title", role: "text" },
|
|
1127
|
+
{ name: "content", role: "container" },
|
|
1128
|
+
{ name: "close", role: "control", optional: true }
|
|
1129
|
+
]
|
|
1130
|
+
}
|
|
1131
|
+
],
|
|
1132
|
+
composes: ["presentation(dialog)", "focus-scope", "dismiss", "backdrop"],
|
|
1133
|
+
realizationNote: "iOS sheet w/ detents"
|
|
1134
|
+
},
|
|
1135
|
+
{
|
|
1136
|
+
kind: "archetype",
|
|
1137
|
+
name: "Drawer",
|
|
1138
|
+
group: "Disclosure",
|
|
1139
|
+
contract: "edge-anchored panel (a.k.a. Sidebar)",
|
|
1140
|
+
produces: { level: "region", interactive: false },
|
|
1141
|
+
anatomy: [
|
|
1142
|
+
{ name: "trigger", role: "control" },
|
|
1143
|
+
{ name: "backdrop", role: "container", optional: true },
|
|
1144
|
+
{
|
|
1145
|
+
name: "surface",
|
|
1146
|
+
role: "container",
|
|
1147
|
+
children: [
|
|
1148
|
+
{ name: "content", role: "container" },
|
|
1149
|
+
{ name: "close", role: "control", optional: true }
|
|
1150
|
+
]
|
|
1151
|
+
}
|
|
1152
|
+
],
|
|
1153
|
+
composes: ["presentation(sheet)", "focus-scope", "dismiss", "gesture(swipe)?"]
|
|
1154
|
+
},
|
|
1155
|
+
{
|
|
1156
|
+
kind: "archetype",
|
|
1157
|
+
name: "Popover",
|
|
1158
|
+
group: "Disclosure",
|
|
1159
|
+
contract: "anchored transient layer",
|
|
1160
|
+
produces: { level: "region", interactive: false },
|
|
1161
|
+
anatomy: [
|
|
1162
|
+
{ name: "trigger", role: "control" },
|
|
1163
|
+
{ name: "surface", role: "container", children: [{ name: "content", role: "container" }] }
|
|
1164
|
+
],
|
|
1165
|
+
composes: ["presentation(popover)", "anchoring", "dismiss"]
|
|
1166
|
+
},
|
|
1167
|
+
{
|
|
1168
|
+
kind: "archetype",
|
|
1169
|
+
name: "Tooltip",
|
|
1170
|
+
group: "Disclosure",
|
|
1171
|
+
contract: "hover/focus hint",
|
|
1172
|
+
produces: { level: "region", interactive: false },
|
|
1173
|
+
anatomy: [
|
|
1174
|
+
{ name: "trigger", role: "control" },
|
|
1175
|
+
{ name: "surface", role: "container", children: [{ name: "content", role: "text" }] }
|
|
1176
|
+
],
|
|
1177
|
+
composes: ["presentation(popover)", "anchoring"],
|
|
1178
|
+
realizationNote: "requires input.pointer \u2192 tap/long-press fallback"
|
|
1179
|
+
},
|
|
1180
|
+
{
|
|
1181
|
+
kind: "archetype",
|
|
1182
|
+
name: "ContextMenu",
|
|
1183
|
+
group: "Disclosure",
|
|
1184
|
+
contract: "secondary-action menu",
|
|
1185
|
+
produces: { level: "region", interactive: false },
|
|
1186
|
+
anatomy: [
|
|
1187
|
+
{
|
|
1188
|
+
name: "surface",
|
|
1189
|
+
role: "container",
|
|
1190
|
+
children: [
|
|
1191
|
+
{
|
|
1192
|
+
name: "item",
|
|
1193
|
+
role: "item",
|
|
1194
|
+
children: [
|
|
1195
|
+
{ name: "icon", role: "icon", optional: true },
|
|
1196
|
+
{ name: "label", role: "text" }
|
|
1197
|
+
]
|
|
1198
|
+
}
|
|
1199
|
+
]
|
|
1200
|
+
}
|
|
1201
|
+
],
|
|
1202
|
+
composes: ["presentation(menu)", "browse", "dismiss"],
|
|
1203
|
+
realizationNote: "right-click / long-press"
|
|
1204
|
+
},
|
|
1205
|
+
{
|
|
1206
|
+
kind: "archetype",
|
|
1207
|
+
name: "Menu",
|
|
1208
|
+
group: "Navigation",
|
|
1209
|
+
contract: "hierarchical actions (a.k.a. MenuBar)",
|
|
1210
|
+
produces: { level: "region", interactive: false },
|
|
1211
|
+
anatomy: [
|
|
1212
|
+
{
|
|
1213
|
+
name: "surface",
|
|
1214
|
+
role: "container",
|
|
1215
|
+
children: [
|
|
1216
|
+
{
|
|
1217
|
+
name: "item",
|
|
1218
|
+
role: "item",
|
|
1219
|
+
children: [
|
|
1220
|
+
{ name: "icon", role: "icon", optional: true },
|
|
1221
|
+
{ name: "label", role: "text" }
|
|
1222
|
+
]
|
|
1223
|
+
}
|
|
1224
|
+
]
|
|
1225
|
+
}
|
|
1226
|
+
],
|
|
1227
|
+
composes: ["presentation", "browse", "typeahead?", "dismiss"]
|
|
1228
|
+
},
|
|
1229
|
+
{
|
|
1230
|
+
kind: "archetype",
|
|
1231
|
+
name: "NavigationBar",
|
|
1232
|
+
group: "Navigation",
|
|
1233
|
+
contract: "top-level destinations",
|
|
1234
|
+
produces: { level: "region", interactive: false },
|
|
1235
|
+
anatomy: [
|
|
1236
|
+
{
|
|
1237
|
+
name: "item",
|
|
1238
|
+
role: "item",
|
|
1239
|
+
children: [
|
|
1240
|
+
{ name: "icon", role: "icon", optional: true },
|
|
1241
|
+
{ name: "label", role: "text" }
|
|
1242
|
+
]
|
|
1243
|
+
}
|
|
1244
|
+
],
|
|
1245
|
+
composes: ["navigation"],
|
|
1246
|
+
realizationNote: "web top-nav \xB7 iOS tab-bar \xB7 Android bottom-nav/rail"
|
|
1247
|
+
},
|
|
1248
|
+
{
|
|
1249
|
+
kind: "archetype",
|
|
1250
|
+
name: "Breadcrumbs",
|
|
1251
|
+
group: "Navigation",
|
|
1252
|
+
contract: "path trail",
|
|
1253
|
+
produces: { level: "region", interactive: false },
|
|
1254
|
+
anatomy: [
|
|
1255
|
+
{ name: "item", role: "item", children: [{ name: "label", role: "text" }] },
|
|
1256
|
+
{ name: "separator", role: "icon", optional: true }
|
|
1257
|
+
],
|
|
1258
|
+
composes: ["navigation"],
|
|
1259
|
+
realizationNote: "iOS: \u2192 nav title + back"
|
|
1260
|
+
},
|
|
1261
|
+
{
|
|
1262
|
+
kind: "archetype",
|
|
1263
|
+
name: "Pagination",
|
|
1264
|
+
group: "Navigation",
|
|
1265
|
+
contract: "page index",
|
|
1266
|
+
produces: { level: "region", interactive: false },
|
|
1267
|
+
anatomy: [
|
|
1268
|
+
{ name: "previous", role: "control" },
|
|
1269
|
+
{ name: "item", role: "item", children: [{ name: "label", role: "text" }] },
|
|
1270
|
+
{ name: "next", role: "control" }
|
|
1271
|
+
],
|
|
1272
|
+
composes: ["navigation", "stepping"]
|
|
1273
|
+
},
|
|
1274
|
+
{
|
|
1275
|
+
kind: "archetype",
|
|
1276
|
+
name: "Tree",
|
|
1277
|
+
group: "Navigation",
|
|
1278
|
+
contract: "hierarchical collection",
|
|
1279
|
+
produces: { level: "region", interactive: false },
|
|
1280
|
+
anatomy: [
|
|
1281
|
+
{
|
|
1282
|
+
name: "item",
|
|
1283
|
+
role: "item",
|
|
1284
|
+
children: [
|
|
1285
|
+
{ name: "indicator", role: "icon" },
|
|
1286
|
+
{ name: "label", role: "text" }
|
|
1287
|
+
]
|
|
1288
|
+
}
|
|
1289
|
+
],
|
|
1290
|
+
composes: ["disclosure", "browse", "selection"]
|
|
1291
|
+
},
|
|
1292
|
+
{
|
|
1293
|
+
kind: "archetype",
|
|
1294
|
+
name: "Wizard",
|
|
1295
|
+
group: "Navigation",
|
|
1296
|
+
contract: "ordered flow (a.k.a. Stepper-nav)",
|
|
1297
|
+
produces: { level: "region", interactive: false },
|
|
1298
|
+
anatomy: [
|
|
1299
|
+
{
|
|
1300
|
+
name: "step",
|
|
1301
|
+
role: "item",
|
|
1302
|
+
children: [
|
|
1303
|
+
{ name: "indicator", role: "icon" },
|
|
1304
|
+
{ name: "label", role: "text" }
|
|
1305
|
+
]
|
|
1306
|
+
},
|
|
1307
|
+
{ name: "content", role: "container" },
|
|
1308
|
+
{ name: "back", role: "control" },
|
|
1309
|
+
{ name: "next", role: "control" }
|
|
1310
|
+
],
|
|
1311
|
+
composes: ["stepping-nav"]
|
|
1312
|
+
},
|
|
1313
|
+
{
|
|
1314
|
+
kind: "archetype",
|
|
1315
|
+
name: "List",
|
|
1316
|
+
group: "Collections",
|
|
1317
|
+
contract: "ordered items, optional select (a.k.a. ListBox)",
|
|
1318
|
+
produces: { level: "region", interactive: false },
|
|
1319
|
+
anatomy: [{ name: "item", role: "item", children: [{ name: "content", role: "container" }] }],
|
|
1320
|
+
composes: ["browse", "selection?", "virtualization?"],
|
|
1321
|
+
realizationNote: "iOS list: swipe-to-delete (gesture)"
|
|
1322
|
+
},
|
|
1323
|
+
{
|
|
1324
|
+
kind: "archetype",
|
|
1325
|
+
name: "Table",
|
|
1326
|
+
group: "Collections",
|
|
1327
|
+
contract: "rows\xD7cols, sort/select (a.k.a. DataGrid)",
|
|
1328
|
+
produces: { level: "region", interactive: false },
|
|
1329
|
+
anatomy: [
|
|
1330
|
+
{
|
|
1331
|
+
name: "header",
|
|
1332
|
+
role: "container",
|
|
1333
|
+
children: [{ name: "column", role: "item", children: [{ name: "label", role: "text" }] }]
|
|
1334
|
+
},
|
|
1335
|
+
{
|
|
1336
|
+
name: "body",
|
|
1337
|
+
role: "container",
|
|
1338
|
+
children: [{ name: "row", role: "item", children: [{ name: "cell", role: "item" }] }]
|
|
1339
|
+
}
|
|
1340
|
+
],
|
|
1341
|
+
composes: ["selection?", "ordering", "browse", "resize?", "virtualization?"],
|
|
1342
|
+
realizationNote: "aggregation/grouping is data, not a behavior"
|
|
1343
|
+
},
|
|
1344
|
+
{
|
|
1345
|
+
kind: "archetype",
|
|
1346
|
+
name: "Carousel",
|
|
1347
|
+
group: "Collections",
|
|
1348
|
+
contract: "paged horizontal items",
|
|
1349
|
+
produces: { level: "region", interactive: false },
|
|
1350
|
+
anatomy: [
|
|
1351
|
+
{ name: "viewport", role: "container", children: [{ name: "slide", role: "item" }] },
|
|
1352
|
+
{ name: "previous", role: "control", optional: true },
|
|
1353
|
+
{ name: "next", role: "control", optional: true }
|
|
1354
|
+
],
|
|
1355
|
+
composes: ["browse", "momentum-scroll", "gesture(swipe)"]
|
|
1356
|
+
},
|
|
1357
|
+
{
|
|
1358
|
+
kind: "archetype",
|
|
1359
|
+
name: "Grid",
|
|
1360
|
+
group: "Collections",
|
|
1361
|
+
contract: "2D arrangement of items",
|
|
1362
|
+
produces: { level: "region", interactive: false },
|
|
1363
|
+
anatomy: [{ name: "item", role: "item" }],
|
|
1364
|
+
composes: ["browse", "selection?"]
|
|
1365
|
+
},
|
|
1366
|
+
{
|
|
1367
|
+
kind: "archetype",
|
|
1368
|
+
name: "Toast",
|
|
1369
|
+
group: "Feedback",
|
|
1370
|
+
contract: "transient message (a.k.a. Snackbar)",
|
|
1371
|
+
produces: { level: "region", interactive: false },
|
|
1372
|
+
anatomy: [
|
|
1373
|
+
{ name: "icon", role: "icon", optional: true },
|
|
1374
|
+
{ name: "content", role: "text" },
|
|
1375
|
+
{ name: "action", role: "control", optional: true },
|
|
1376
|
+
{ name: "close", role: "control", optional: true }
|
|
1377
|
+
],
|
|
1378
|
+
composes: ["presentation", "auto-dismiss", "liveness"],
|
|
1379
|
+
realizationNote: "iOS: top banner; Android: snackbar bottom"
|
|
1380
|
+
},
|
|
1381
|
+
{
|
|
1382
|
+
kind: "archetype",
|
|
1383
|
+
name: "Alert",
|
|
1384
|
+
group: "Feedback",
|
|
1385
|
+
contract: "inline persistent message (a.k.a. Banner)",
|
|
1386
|
+
produces: { level: "region", interactive: false },
|
|
1387
|
+
anatomy: [
|
|
1388
|
+
{ name: "icon", role: "icon", optional: true },
|
|
1389
|
+
{ name: "title", role: "text", optional: true },
|
|
1390
|
+
{ name: "content", role: "text" },
|
|
1391
|
+
{ name: "close", role: "control", optional: true }
|
|
1392
|
+
],
|
|
1393
|
+
composes: ["liveness"]
|
|
1394
|
+
},
|
|
1395
|
+
{
|
|
1396
|
+
kind: "archetype",
|
|
1397
|
+
name: "ProgressBar",
|
|
1398
|
+
group: "Feedback",
|
|
1399
|
+
contract: "completion feedback (a.k.a. Spinner)",
|
|
1400
|
+
produces: { level: "region", interactive: false },
|
|
1401
|
+
anatomy: [
|
|
1402
|
+
{ name: "track", role: "container", children: [{ name: "indicator", role: "container" }] },
|
|
1403
|
+
{ name: "label", role: "text", optional: true }
|
|
1404
|
+
],
|
|
1405
|
+
composes: ["progress", "liveness"]
|
|
1406
|
+
},
|
|
1407
|
+
{
|
|
1408
|
+
kind: "archetype",
|
|
1409
|
+
name: "Skeleton",
|
|
1410
|
+
group: "Feedback",
|
|
1411
|
+
contract: "loading placeholder",
|
|
1412
|
+
produces: { level: "region", interactive: false },
|
|
1413
|
+
composes: ["async-state"]
|
|
1414
|
+
},
|
|
1415
|
+
{
|
|
1416
|
+
kind: "archetype",
|
|
1417
|
+
name: "Badge",
|
|
1418
|
+
group: "Feedback",
|
|
1419
|
+
contract: "numeric/status decoration",
|
|
1420
|
+
produces: { level: "phrase", interactive: false },
|
|
1421
|
+
anatomy: [{ name: "label", role: "text" }],
|
|
1422
|
+
composes: []
|
|
1423
|
+
},
|
|
1424
|
+
{
|
|
1425
|
+
kind: "archetype",
|
|
1426
|
+
name: "Meter",
|
|
1427
|
+
group: "Feedback",
|
|
1428
|
+
contract: "numeric gauge",
|
|
1429
|
+
produces: { level: "region", interactive: false },
|
|
1430
|
+
anatomy: [
|
|
1431
|
+
{ name: "track", role: "container", children: [{ name: "indicator", role: "container" }] },
|
|
1432
|
+
{ name: "label", role: "text", optional: true }
|
|
1433
|
+
],
|
|
1434
|
+
composes: []
|
|
1435
|
+
},
|
|
1436
|
+
{
|
|
1437
|
+
kind: "archetype",
|
|
1438
|
+
name: "EmptyState",
|
|
1439
|
+
group: "Feedback",
|
|
1440
|
+
contract: "no-content placeholder",
|
|
1441
|
+
produces: { level: "region", interactive: false },
|
|
1442
|
+
anatomy: [
|
|
1443
|
+
{ name: "icon", role: "icon", optional: true },
|
|
1444
|
+
{ name: "title", role: "text" },
|
|
1445
|
+
{ name: "description", role: "text", optional: true },
|
|
1446
|
+
{ name: "action", role: "control", optional: true }
|
|
1447
|
+
],
|
|
1448
|
+
composes: []
|
|
1449
|
+
},
|
|
1450
|
+
{
|
|
1451
|
+
kind: "archetype",
|
|
1452
|
+
name: "Avatar",
|
|
1453
|
+
group: "Media",
|
|
1454
|
+
contract: "identity image/initials",
|
|
1455
|
+
produces: { level: "phrase", interactive: false },
|
|
1456
|
+
anatomy: [
|
|
1457
|
+
{ name: "image", role: "content" },
|
|
1458
|
+
{ name: "fallback", role: "text", optional: true },
|
|
1459
|
+
{ name: "badge", role: "icon", optional: true }
|
|
1460
|
+
],
|
|
1461
|
+
composes: []
|
|
1462
|
+
},
|
|
1463
|
+
{
|
|
1464
|
+
kind: "archetype",
|
|
1465
|
+
name: "Image",
|
|
1466
|
+
group: "Media",
|
|
1467
|
+
contract: "bitmap w/ alt + fit",
|
|
1468
|
+
produces: { level: "phrase", interactive: false },
|
|
1469
|
+
composes: []
|
|
1470
|
+
},
|
|
1471
|
+
{
|
|
1472
|
+
kind: "archetype",
|
|
1473
|
+
name: "Icon",
|
|
1474
|
+
group: "Media",
|
|
1475
|
+
contract: "vector glyph from a set",
|
|
1476
|
+
produces: { level: "phrase", interactive: false },
|
|
1477
|
+
composes: []
|
|
1478
|
+
},
|
|
1479
|
+
{
|
|
1480
|
+
kind: "archetype",
|
|
1481
|
+
name: "AspectRatio",
|
|
1482
|
+
group: "Media",
|
|
1483
|
+
contract: "ratio-locked box",
|
|
1484
|
+
produces: { level: "region", interactive: false },
|
|
1485
|
+
anatomy: [{ name: "content", role: "container" }],
|
|
1486
|
+
composes: [],
|
|
1487
|
+
realizationNote: "layout facet, not a behavioral archetype"
|
|
1488
|
+
}
|
|
1489
|
+
];
|
|
1490
|
+
var facets = [
|
|
1491
|
+
{ name: "fill", covers: "surface/background" },
|
|
1492
|
+
{ name: "ink", covers: "text + icon foreground" },
|
|
1493
|
+
{
|
|
1494
|
+
name: "border",
|
|
1495
|
+
covers: "edge: color + width (hairline|thin|thick) + style",
|
|
1496
|
+
divergence: "iOS often overlay-stroke"
|
|
1497
|
+
},
|
|
1498
|
+
{ name: "corner", covers: "corner radius (token role)" },
|
|
1499
|
+
{ name: "inset", covers: "internal padding (block/inline)" },
|
|
1500
|
+
{ name: "gap", covers: "spacing between children" },
|
|
1501
|
+
{
|
|
1502
|
+
name: "text",
|
|
1503
|
+
covers: "typography role (body|caption|title\u2026) \u2014 bundles size/weight/line/tracking",
|
|
1504
|
+
divergence: "iOS Dynamic Type = OS-resolved role"
|
|
1505
|
+
},
|
|
1506
|
+
{
|
|
1507
|
+
name: "textClamp",
|
|
1508
|
+
covers: "truncate to N lines + ellipsis",
|
|
1509
|
+
divergence: "web -webkit-line-clamp \xB7 .lineLimit \xB7 maxLines+overflow"
|
|
1510
|
+
},
|
|
1511
|
+
{ name: "textWrap", covers: "wrap | nowrap | break" },
|
|
1512
|
+
{
|
|
1513
|
+
name: "elevation",
|
|
1514
|
+
covers: "depth",
|
|
1515
|
+
divergence: "web box-shadow \xB7 Android tonal-elevation \xB7 iOS none/sheet"
|
|
1516
|
+
},
|
|
1517
|
+
{
|
|
1518
|
+
name: "overlay",
|
|
1519
|
+
covers: "state layer (Material hover/press tint)",
|
|
1520
|
+
divergence: "Material-specific; web \u2248 bg shift"
|
|
1521
|
+
},
|
|
1522
|
+
{ name: "opacity", covers: "transparency" },
|
|
1523
|
+
{
|
|
1524
|
+
name: "ring",
|
|
1525
|
+
covers: "focus indicator",
|
|
1526
|
+
divergence: "desktop ring \xB7 mobile none \xB7 tv strong highlight"
|
|
1527
|
+
},
|
|
1528
|
+
{ name: "backdrop", covers: "scrim / blur behind layer", divergence: "iOS material/vibrancy" }
|
|
1529
|
+
];
|
|
1530
|
+
var states = [
|
|
1531
|
+
{ name: "pressed", from: "pressability" },
|
|
1532
|
+
{ name: "hovered", from: "pressability" },
|
|
1533
|
+
{ name: "focused", from: "value-entry" },
|
|
1534
|
+
{ name: "active", from: "browse" },
|
|
1535
|
+
{ name: "selected", from: "selection" },
|
|
1536
|
+
{ name: "checked", from: "toggle" },
|
|
1537
|
+
{ name: "expanded", from: "disclosure" },
|
|
1538
|
+
{ name: "open", from: "presentation" },
|
|
1539
|
+
{ name: "disabled", from: "ambient (global gate)" },
|
|
1540
|
+
{ name: "readonly", from: "ambient" },
|
|
1541
|
+
{ name: "loading", from: "async-state" },
|
|
1542
|
+
{ name: "error", from: "async-state" },
|
|
1543
|
+
{ name: "success", from: "async-state" },
|
|
1544
|
+
{ name: "invalid", from: "validation" },
|
|
1545
|
+
{ name: "valid", from: "validation" },
|
|
1546
|
+
{ name: "indeterminate", from: "toggle (tristate)" },
|
|
1547
|
+
{ name: "dragging", from: "gesture" },
|
|
1548
|
+
{ name: "empty", from: "value-entry" },
|
|
1549
|
+
{ name: "complete", from: "progress / stepping-nav" },
|
|
1550
|
+
{ name: "first", from: "collection-position" },
|
|
1551
|
+
{ name: "last", from: "collection-position" },
|
|
1552
|
+
{ name: "odd", from: "collection-position" },
|
|
1553
|
+
{ name: "even", from: "collection-position" }
|
|
1554
|
+
];
|
|
1555
|
+
var capabilities = [
|
|
1556
|
+
{ name: "input.keyboard" },
|
|
1557
|
+
{ name: "input.pointer", note: "hover" },
|
|
1558
|
+
{ name: "input.touch" },
|
|
1559
|
+
{ name: "input.remote", note: "tv focus engine" },
|
|
1560
|
+
{
|
|
1561
|
+
name: "input.voice",
|
|
1562
|
+
status: "aspirational",
|
|
1563
|
+
note: "aspirational \u2014 declared but consumed by no atom yet (no voice/turn-taking machine in v0); see NOTES-modality-coverage"
|
|
1564
|
+
},
|
|
1565
|
+
{ name: "motion.haptic" },
|
|
1566
|
+
{ name: "runtime.dynamic-color", note: "Material You" },
|
|
1567
|
+
{ name: "display.density" },
|
|
1568
|
+
{ name: "a11y.screenreader" },
|
|
1569
|
+
{ name: "platform.web" },
|
|
1570
|
+
{ name: "platform.ios" },
|
|
1571
|
+
{ name: "platform.android" },
|
|
1572
|
+
{ name: "platform.tvos" }
|
|
1573
|
+
];
|
|
1574
|
+
var decorations = [
|
|
1575
|
+
{
|
|
1576
|
+
name: "motion",
|
|
1577
|
+
note: "decorates existing transitions (spring/flip/fade+slide); adds no states"
|
|
1578
|
+
},
|
|
1579
|
+
{
|
|
1580
|
+
name: "masking",
|
|
1581
|
+
note: "format/constrain entry (date/phone/currency) \u2014 decorates value-entry draft"
|
|
1582
|
+
},
|
|
1583
|
+
{
|
|
1584
|
+
name: "anchoring",
|
|
1585
|
+
note: "position a surface relative to a reference (placement/flip/offset/match-size) \u2014 decorates presentation(popover|menu)"
|
|
1586
|
+
},
|
|
1587
|
+
{
|
|
1588
|
+
name: "backdrop",
|
|
1589
|
+
note: "scrim / blur behind a layer \u2014 decorates a modal presentation; painted via the `backdrop` facet on the backdrop anatomy part"
|
|
1590
|
+
},
|
|
1591
|
+
{
|
|
1592
|
+
name: "momentum-scroll",
|
|
1593
|
+
note: "inertial scroll with snap / detent \u2014 decorates scroll/browse on touch surfaces"
|
|
1594
|
+
}
|
|
1595
|
+
];
|
|
1596
|
+
var nonBehaviors = [
|
|
1597
|
+
{ name: "filter", note: "derived view over a collection (data, not interaction)" },
|
|
1598
|
+
{ name: "virtualization", note: "render windowing" },
|
|
1599
|
+
{ name: "ordering", note: "collection mutation (reorder/sort)" },
|
|
1600
|
+
{ name: "aggregation", note: "data transformation (grouping/totals) \u2014 DataGrid math" }
|
|
1601
|
+
];
|
|
1602
|
+
var preludeV0 = {
|
|
1603
|
+
milda: "0.0.1",
|
|
1604
|
+
kind: "prelude",
|
|
1605
|
+
prelude: "0.0.1",
|
|
1606
|
+
meta: {
|
|
1607
|
+
id: "prelude.milda",
|
|
1608
|
+
name: "Milda Prelude",
|
|
1609
|
+
version: "0.0.2",
|
|
1610
|
+
description: "Built-in standard library: atoms, archetypes, facets, states, capabilities."
|
|
1611
|
+
},
|
|
1612
|
+
atoms,
|
|
1613
|
+
composites,
|
|
1614
|
+
archetypes,
|
|
1615
|
+
facets,
|
|
1616
|
+
states,
|
|
1617
|
+
capabilities,
|
|
1618
|
+
decorations,
|
|
1619
|
+
nonBehaviors
|
|
1620
|
+
};
|
|
1621
|
+
var atomsByName = Object.fromEntries(atoms.map((a) => [a.name, a]));
|
|
1622
|
+
var archetypesByName = Object.fromEntries(
|
|
1623
|
+
archetypes.map((a) => [a.name, a])
|
|
1624
|
+
);
|
|
1625
|
+
|
|
1626
|
+
// engine/resolveToken.ts
|
|
1627
|
+
function resolveToken(tokenId, contextIds, layers, _depth = 0) {
|
|
1628
|
+
if (_depth > 20) return null;
|
|
1629
|
+
const ids = typeof contextIds === "string" ? [contextIds] : contextIds;
|
|
1630
|
+
const token = findToken(tokenId, layers)?.token;
|
|
1631
|
+
if (!token) return null;
|
|
1632
|
+
const v = token.value;
|
|
1633
|
+
if (v.kind === "raw") return { kind: "value", type: token.type, value: v.value };
|
|
1634
|
+
if (v.kind === "escape") return { kind: "escape", raw: v.raw, note: v.note };
|
|
1635
|
+
const ref = ids.reduce((found, id) => found ?? v.refs[id], void 0) ?? v.refs["default"] ?? null;
|
|
1636
|
+
if (!ref) return null;
|
|
1637
|
+
return resolveToken(ref, contextIds, layers, _depth + 1);
|
|
1638
|
+
}
|
|
1639
|
+
function findToken(tokenId, layers) {
|
|
1640
|
+
for (const layer of layers) {
|
|
1641
|
+
const token = layer.tokens.find((t) => t.id === tokenId);
|
|
1642
|
+
if (token) return { token, layerId: layer.id };
|
|
1643
|
+
}
|
|
1644
|
+
return null;
|
|
1645
|
+
}
|
|
1646
|
+
function allTokensOfType(type, layers) {
|
|
1647
|
+
const sorted = [...layers].sort((a, b) => a.order - b.order);
|
|
1648
|
+
const result = [];
|
|
1649
|
+
for (const layer of sorted) {
|
|
1650
|
+
for (const token of layer.tokens) {
|
|
1651
|
+
if (token.type === type) result.push({ token, layerId: layer.id, layerName: layer.name });
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
return result;
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
// engine/resolveFacets.ts
|
|
1658
|
+
function resolveFacets(input) {
|
|
1659
|
+
const { part, activeStates } = input;
|
|
1660
|
+
let result = { ...part.facets ?? {} };
|
|
1661
|
+
const states2 = part.states ?? {};
|
|
1662
|
+
const order = input.stateOrder ?? Object.keys(states2);
|
|
1663
|
+
for (const s of order) {
|
|
1664
|
+
const override = activeStates.has(s) ? states2[s]?.facets : void 0;
|
|
1665
|
+
if (override) result = { ...result, ...override };
|
|
1666
|
+
}
|
|
1667
|
+
return result;
|
|
1668
|
+
}
|
|
1669
|
+
function resolveLayout(input) {
|
|
1670
|
+
const { part, activeStates } = input;
|
|
1671
|
+
let result = part.layout ? { ...part.layout } : void 0;
|
|
1672
|
+
const states2 = part.states ?? {};
|
|
1673
|
+
const order = input.stateOrder ?? Object.keys(states2);
|
|
1674
|
+
for (const s of order) {
|
|
1675
|
+
const override = activeStates.has(s) ? states2[s]?.layout : void 0;
|
|
1676
|
+
if (override) result = { ...result ?? {}, ...override };
|
|
1677
|
+
}
|
|
1678
|
+
return result;
|
|
1679
|
+
}
|
|
1680
|
+
function collectActiveStates(flags) {
|
|
1681
|
+
const active = /* @__PURE__ */ new Set();
|
|
1682
|
+
for (const [state, enabled] of Object.entries(flags)) {
|
|
1683
|
+
if (enabled) active.add(state);
|
|
1684
|
+
}
|
|
1685
|
+
return active;
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
// engine/validate.ts
|
|
1689
|
+
function facetTokenRefs(facets2) {
|
|
1690
|
+
if (!facets2) return [];
|
|
1691
|
+
const ids = [];
|
|
1692
|
+
for (const v of Object.values(facets2)) {
|
|
1693
|
+
if (!v) continue;
|
|
1694
|
+
if ("token" in v) ids.push(v.token);
|
|
1695
|
+
else if ("inset" in v) {
|
|
1696
|
+
for (const edge of Object.values(v.inset)) if (typeof edge === "string") ids.push(edge);
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
return ids;
|
|
1700
|
+
}
|
|
1701
|
+
function layoutTokenRefs(layout) {
|
|
1702
|
+
if (!layout) return [];
|
|
1703
|
+
const ids = [];
|
|
1704
|
+
if (layout.gap) ids.push(layout.gap);
|
|
1705
|
+
if (layout.inset) {
|
|
1706
|
+
for (const edge of Object.values(layout.inset)) if (typeof edge === "string") ids.push(edge);
|
|
1707
|
+
}
|
|
1708
|
+
for (const axis of [layout.size?.width, layout.size?.height]) {
|
|
1709
|
+
if (axis && typeof axis === "object") {
|
|
1710
|
+
const intent = "intent" in axis ? axis.intent : axis;
|
|
1711
|
+
if (intent && typeof intent === "object" && "fixed" in intent) ids.push(intent.fixed);
|
|
1712
|
+
if ("min" in axis && axis.min) ids.push(axis.min);
|
|
1713
|
+
if ("max" in axis && axis.max) ids.push(axis.max);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
return ids;
|
|
1717
|
+
}
|
|
1718
|
+
function validate(doc, prelude) {
|
|
1719
|
+
const issues = [];
|
|
1720
|
+
const archetypeNames = new Set(prelude.archetypes.map((a) => a.name));
|
|
1721
|
+
const facetNames = new Set(prelude.facets.map((f) => f.name));
|
|
1722
|
+
const stateNames = new Set(prelude.states.map((s) => s.name));
|
|
1723
|
+
const groupIds = new Set(doc.foundations.contextGroups.map((g) => g.id));
|
|
1724
|
+
const layers = doc.foundations.layers;
|
|
1725
|
+
for (const layer of layers) {
|
|
1726
|
+
for (const tok of layer.tokens) {
|
|
1727
|
+
if (tok.value.kind === "alias") {
|
|
1728
|
+
const where = `token ${tok.name} (${tok.id})`;
|
|
1729
|
+
if (!groupIds.has(tok.value.by)) {
|
|
1730
|
+
issues.push({
|
|
1731
|
+
severity: "error",
|
|
1732
|
+
code: "alias.unknownGroup",
|
|
1733
|
+
message: `alias by unknown context group "${tok.value.by}"`,
|
|
1734
|
+
where
|
|
1735
|
+
});
|
|
1736
|
+
}
|
|
1737
|
+
for (const refId of Object.values(tok.value.refs)) {
|
|
1738
|
+
if (!findToken(refId, layers)) {
|
|
1739
|
+
issues.push({
|
|
1740
|
+
severity: "error",
|
|
1741
|
+
code: "alias.danglingRef",
|
|
1742
|
+
message: `alias ref points at missing token "${refId}"`,
|
|
1743
|
+
where
|
|
1744
|
+
});
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
for (const comp of doc.components) {
|
|
1751
|
+
const where = `component ${comp.name} (${comp.id})`;
|
|
1752
|
+
if (!archetypeNames.has(comp.archetype)) {
|
|
1753
|
+
issues.push({
|
|
1754
|
+
severity: "error",
|
|
1755
|
+
code: "component.unknownArchetype",
|
|
1756
|
+
message: `unknown archetype "${comp.archetype}"`,
|
|
1757
|
+
where
|
|
1758
|
+
});
|
|
1759
|
+
}
|
|
1760
|
+
const propIds = new Set(comp.contract.props.map((p) => p.id));
|
|
1761
|
+
for (const [param, binding] of Object.entries(comp.contract.params)) {
|
|
1762
|
+
if ("prop" in binding && !propIds.has(binding.prop)) {
|
|
1763
|
+
issues.push({
|
|
1764
|
+
severity: "error",
|
|
1765
|
+
code: "param.danglingProp",
|
|
1766
|
+
message: `param "${param}" binds missing prop "${binding.prop}"`,
|
|
1767
|
+
where
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
for (const [partName, part] of Object.entries(comp.anatomy)) {
|
|
1772
|
+
checkPart(comp, partName, part, { facetNames, stateNames, layers, issues });
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
return issues;
|
|
1776
|
+
}
|
|
1777
|
+
function checkPart(comp, partName, part, ctx) {
|
|
1778
|
+
const where = `${comp.name} \u203A part ${partName}`;
|
|
1779
|
+
const { facetNames, stateNames, layers, issues } = ctx;
|
|
1780
|
+
const checkFacets = (facets2, scope) => {
|
|
1781
|
+
if (!facets2) return;
|
|
1782
|
+
for (const name of Object.keys(facets2)) {
|
|
1783
|
+
if (!facetNames.has(name)) {
|
|
1784
|
+
issues.push({
|
|
1785
|
+
severity: "error",
|
|
1786
|
+
code: "facet.unknown",
|
|
1787
|
+
message: `unknown facet "${name}"`,
|
|
1788
|
+
where: scope
|
|
1789
|
+
});
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
for (const id of facetTokenRefs(facets2)) {
|
|
1793
|
+
if (!findToken(id, layers)) {
|
|
1794
|
+
issues.push({
|
|
1795
|
+
severity: "error",
|
|
1796
|
+
code: "facet.danglingToken",
|
|
1797
|
+
message: `facet references missing token "${id}"`,
|
|
1798
|
+
where: scope
|
|
1799
|
+
});
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
};
|
|
1803
|
+
const checkLayoutRefs = (layout, scope) => {
|
|
1804
|
+
for (const id of layoutTokenRefs(layout)) {
|
|
1805
|
+
if (!findToken(id, layers)) {
|
|
1806
|
+
issues.push({
|
|
1807
|
+
severity: "error",
|
|
1808
|
+
code: "layout.danglingToken",
|
|
1809
|
+
message: `layout references missing token "${id}"`,
|
|
1810
|
+
where: scope
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
};
|
|
1815
|
+
checkFacets(part.facets, where);
|
|
1816
|
+
checkLayoutRefs(part.layout, where);
|
|
1817
|
+
for (const [stateName, override] of Object.entries(part.states ?? {})) {
|
|
1818
|
+
const scope = `${where} [${stateName}]`;
|
|
1819
|
+
if (!stateNames.has(stateName)) {
|
|
1820
|
+
issues.push({
|
|
1821
|
+
severity: "error",
|
|
1822
|
+
code: "state.unknown",
|
|
1823
|
+
message: `unknown state "${stateName}"`,
|
|
1824
|
+
where: scope
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1827
|
+
checkFacets(override?.facets, scope);
|
|
1828
|
+
checkLayoutRefs(override?.layout, scope);
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
// engine/conformance.ts
|
|
1833
|
+
function walkFacets(facets2, where, opts, holes) {
|
|
1834
|
+
if (!facets2) return;
|
|
1835
|
+
for (const [name, value] of Object.entries(facets2)) {
|
|
1836
|
+
if (!value) continue;
|
|
1837
|
+
if ("raw" in value) {
|
|
1838
|
+
holes.push({
|
|
1839
|
+
kind: "facet",
|
|
1840
|
+
name,
|
|
1841
|
+
where,
|
|
1842
|
+
reason: "raw escape-hatch value is a platform-specific leaf"
|
|
1843
|
+
});
|
|
1844
|
+
} else if ("token" in value) {
|
|
1845
|
+
const resolved = resolveToken(value.token, opts.contextIds, opts.layers);
|
|
1846
|
+
if (resolved === null) {
|
|
1847
|
+
holes.push({
|
|
1848
|
+
kind: "facet",
|
|
1849
|
+
name,
|
|
1850
|
+
where,
|
|
1851
|
+
reason: `token "${value.token}" does not resolve for target`
|
|
1852
|
+
});
|
|
1853
|
+
} else if (resolved.kind === "escape") {
|
|
1854
|
+
holes.push({
|
|
1855
|
+
kind: "facet",
|
|
1856
|
+
name,
|
|
1857
|
+
where,
|
|
1858
|
+
reason: `token "${value.token}" resolves to an escape-hatch leaf for this target`
|
|
1859
|
+
});
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
function walkPart(comp, partName, part, opts, holes) {
|
|
1865
|
+
const where = `${comp.name} \u203A ${partName}`;
|
|
1866
|
+
walkFacets(part.facets, where, opts, holes);
|
|
1867
|
+
for (const [stateName, override] of Object.entries(part.states ?? {})) {
|
|
1868
|
+
walkFacets(override?.facets, `${where} [${stateName}]`, opts, holes);
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
function conformance(comp, opts) {
|
|
1872
|
+
const holes = [];
|
|
1873
|
+
for (const [partName, part] of Object.entries(comp.anatomy)) {
|
|
1874
|
+
walkPart(comp, partName, part, opts, holes);
|
|
1875
|
+
}
|
|
1876
|
+
const substitutions = [];
|
|
1877
|
+
const realize = comp.realize.find((r) => r.target === opts.target);
|
|
1878
|
+
if (realize) {
|
|
1879
|
+
for (const dropped of realize.drop ?? [])
|
|
1880
|
+
substitutions.push({ behavior: dropped, via: "dropped" });
|
|
1881
|
+
for (const wire of realize.wire ?? [])
|
|
1882
|
+
substitutions.push({ behavior: `${wire.from} \u2192 ${wire.to}`, via: "realize wire" });
|
|
1883
|
+
}
|
|
1884
|
+
return { target: opts.target, complete: holes.length === 0, holes, substitutions };
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
// dsl/lexer.ts
|
|
1888
|
+
var LexError = class extends Error {
|
|
1889
|
+
constructor(message, line, col) {
|
|
1890
|
+
super(`${message} (line ${line}:${col})`);
|
|
1891
|
+
this.line = line;
|
|
1892
|
+
this.col = col;
|
|
1893
|
+
this.name = "LexError";
|
|
1894
|
+
}
|
|
1895
|
+
};
|
|
1896
|
+
var isWordChar = (c) => /[A-Za-z0-9_./%-]/.test(c);
|
|
1897
|
+
var PUNCT = {
|
|
1898
|
+
"{": "lbrace",
|
|
1899
|
+
"}": "rbrace",
|
|
1900
|
+
"(": "lparen",
|
|
1901
|
+
")": "rparen",
|
|
1902
|
+
"<": "lt",
|
|
1903
|
+
">": "gt",
|
|
1904
|
+
":": "colon",
|
|
1905
|
+
"=": "equals",
|
|
1906
|
+
",": "comma",
|
|
1907
|
+
";": "semi",
|
|
1908
|
+
"?": "question"
|
|
1909
|
+
};
|
|
1910
|
+
function lex(src) {
|
|
1911
|
+
const tokens = [];
|
|
1912
|
+
let i = 0;
|
|
1913
|
+
let line = 1;
|
|
1914
|
+
let col = 1;
|
|
1915
|
+
const n = src.length;
|
|
1916
|
+
const advance = (count = 1) => {
|
|
1917
|
+
for (let k = 0; k < count; k++) {
|
|
1918
|
+
if (src[i] === "\n") {
|
|
1919
|
+
line++;
|
|
1920
|
+
col = 1;
|
|
1921
|
+
} else {
|
|
1922
|
+
col++;
|
|
1923
|
+
}
|
|
1924
|
+
i++;
|
|
1925
|
+
}
|
|
1926
|
+
};
|
|
1927
|
+
const push = (type, value, startPos, startLine, startCol) => {
|
|
1928
|
+
tokens.push({ type, value, pos: startPos, line: startLine, col: startCol });
|
|
1929
|
+
};
|
|
1930
|
+
while (i < n) {
|
|
1931
|
+
const c = src[i];
|
|
1932
|
+
const startPos = i;
|
|
1933
|
+
const startLine = line;
|
|
1934
|
+
const startCol = col;
|
|
1935
|
+
if (c === "\n") {
|
|
1936
|
+
advance();
|
|
1937
|
+
if (tokens.length && tokens[tokens.length - 1].type !== "newline") {
|
|
1938
|
+
push("newline", "\n", startPos, startLine, startCol);
|
|
1939
|
+
}
|
|
1940
|
+
continue;
|
|
1941
|
+
}
|
|
1942
|
+
if (c === " " || c === " " || c === "\r") {
|
|
1943
|
+
advance();
|
|
1944
|
+
continue;
|
|
1945
|
+
}
|
|
1946
|
+
if (c === "#") {
|
|
1947
|
+
while (i < n && src[i] !== "\n") advance();
|
|
1948
|
+
continue;
|
|
1949
|
+
}
|
|
1950
|
+
if (c === '"') {
|
|
1951
|
+
advance();
|
|
1952
|
+
let value = "";
|
|
1953
|
+
while (i < n && src[i] !== '"') {
|
|
1954
|
+
if (src[i] === "\\" && i + 1 < n) {
|
|
1955
|
+
const next = src[i + 1];
|
|
1956
|
+
value += next === "n" ? "\n" : next === "t" ? " " : next;
|
|
1957
|
+
advance(2);
|
|
1958
|
+
continue;
|
|
1959
|
+
}
|
|
1960
|
+
if (src[i] === "\n") throw new LexError("Unterminated string", startLine, startCol);
|
|
1961
|
+
value += src[i];
|
|
1962
|
+
advance();
|
|
1963
|
+
}
|
|
1964
|
+
if (i >= n) throw new LexError("Unterminated string", startLine, startCol);
|
|
1965
|
+
advance();
|
|
1966
|
+
push("string", value, startPos, startLine, startCol);
|
|
1967
|
+
continue;
|
|
1968
|
+
}
|
|
1969
|
+
if (c === "-" && src[i + 1] === ">") {
|
|
1970
|
+
advance(2);
|
|
1971
|
+
push("arrow", "->", startPos, startLine, startCol);
|
|
1972
|
+
continue;
|
|
1973
|
+
}
|
|
1974
|
+
if (c === "\u2192") {
|
|
1975
|
+
advance();
|
|
1976
|
+
push("arrow", "->", startPos, startLine, startCol);
|
|
1977
|
+
continue;
|
|
1978
|
+
}
|
|
1979
|
+
if (PUNCT[c]) {
|
|
1980
|
+
advance();
|
|
1981
|
+
push(PUNCT[c], c, startPos, startLine, startCol);
|
|
1982
|
+
continue;
|
|
1983
|
+
}
|
|
1984
|
+
if (isWordChar(c)) {
|
|
1985
|
+
let value = "";
|
|
1986
|
+
while (i < n && isWordChar(src[i]) && !(src[i] === "-" && src[i + 1] === ">")) {
|
|
1987
|
+
value += src[i];
|
|
1988
|
+
advance();
|
|
1989
|
+
}
|
|
1990
|
+
push("word", value, startPos, startLine, startCol);
|
|
1991
|
+
continue;
|
|
1992
|
+
}
|
|
1993
|
+
advance();
|
|
1994
|
+
}
|
|
1995
|
+
push("eof", "", i, line, col);
|
|
1996
|
+
return tokens;
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
// dsl/parse.ts
|
|
2000
|
+
var seg = (s) => s.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "x";
|
|
2001
|
+
var cgId = (name) => `cg.${seg(name)}`;
|
|
2002
|
+
var ctxId = (groupName, ctxName) => `ctx.${seg(groupName)}.${seg(ctxName)}`;
|
|
2003
|
+
var tokId = (path) => `tok.${path.replace(/\//g, ".")}`;
|
|
2004
|
+
var stId = (name) => `st.${seg(name)}`;
|
|
2005
|
+
var cmpId = (name) => `cmp.${seg(name)}`;
|
|
2006
|
+
var FACET_MAP = {
|
|
2007
|
+
fill: "fill",
|
|
2008
|
+
ink: "ink",
|
|
2009
|
+
border: "border",
|
|
2010
|
+
corner: "corner",
|
|
2011
|
+
inset: "inset",
|
|
2012
|
+
gap: "gap",
|
|
2013
|
+
text: "text",
|
|
2014
|
+
"text.clamp": "textClamp",
|
|
2015
|
+
"text.wrap": "textWrap",
|
|
2016
|
+
elevation: "elevation",
|
|
2017
|
+
overlay: "overlay",
|
|
2018
|
+
opacity: "opacity",
|
|
2019
|
+
ring: "ring",
|
|
2020
|
+
backdrop: "backdrop",
|
|
2021
|
+
weight: null,
|
|
2022
|
+
font: null,
|
|
2023
|
+
slant: null
|
|
2024
|
+
};
|
|
2025
|
+
var TYPE_MAP = {
|
|
2026
|
+
color: "color",
|
|
2027
|
+
spacing: "spacing",
|
|
2028
|
+
radius: "radius",
|
|
2029
|
+
size: "size",
|
|
2030
|
+
dimension: "size",
|
|
2031
|
+
shadow: "shadow",
|
|
2032
|
+
typography: "typography",
|
|
2033
|
+
"font-family": "fontFamily",
|
|
2034
|
+
fontFamily: "fontFamily",
|
|
2035
|
+
duration: "duration",
|
|
2036
|
+
opacity: "opacity",
|
|
2037
|
+
blur: "blur",
|
|
2038
|
+
tonal: "tonal",
|
|
2039
|
+
border: "border",
|
|
2040
|
+
elevation: "elevation",
|
|
2041
|
+
ring: "ring",
|
|
2042
|
+
backdrop: "backdrop",
|
|
2043
|
+
none: "none"
|
|
2044
|
+
};
|
|
2045
|
+
var NUMBER_RE = /^-?\d+(\.\d+)?$/;
|
|
2046
|
+
var isRawValue = (v) => /^#/.test(v) || /[(%]/.test(v) || /\d(px|rem|em|vh|vw|vmin|vmax|ch|ex|fr|deg|ms|s)$/.test(v);
|
|
2047
|
+
function hexToColor(hex) {
|
|
2048
|
+
const m = /^#([0-9a-fA-F]{3,8})$/.exec(hex.trim());
|
|
2049
|
+
if (!m) return null;
|
|
2050
|
+
let h = m[1];
|
|
2051
|
+
if (h.length === 3) h = h.split("").map((c) => c + c).join("");
|
|
2052
|
+
if (h.length !== 6 && h.length !== 8) return null;
|
|
2053
|
+
const byte = (k) => parseInt(h.slice(k * 2, k * 2 + 2), 16) / 255;
|
|
2054
|
+
const value = { space: "srgb", channels: [byte(0), byte(1), byte(2)] };
|
|
2055
|
+
if (h.length === 8) value.alpha = byte(3);
|
|
2056
|
+
return value;
|
|
2057
|
+
}
|
|
2058
|
+
var Parser = class {
|
|
2059
|
+
constructor(toks) {
|
|
2060
|
+
this.pos = 0;
|
|
2061
|
+
this.issues = [];
|
|
2062
|
+
// Tokens synthesized while parsing (inline literals hoisted out of alias slots —
|
|
2063
|
+
// the canonical AST's `refs` holds only token ids, so an inline value must become
|
|
2064
|
+
// its own token). Deduped by (type, serialized value). Flushed into the layer.
|
|
2065
|
+
this.synth = [];
|
|
2066
|
+
this.synthKeys = /* @__PURE__ */ new Map();
|
|
2067
|
+
this.toks = toks;
|
|
2068
|
+
}
|
|
2069
|
+
// Hoist an inline literal into a synthesized token and return its id.
|
|
2070
|
+
hoistLiteral(astType, raw, tok) {
|
|
2071
|
+
const value = this.typedRaw(astType, raw, tok);
|
|
2072
|
+
const key = `${astType}\0${JSON.stringify(value)}`;
|
|
2073
|
+
const existing = this.synthKeys.get(key);
|
|
2074
|
+
if (existing) return existing;
|
|
2075
|
+
const id = `tok.lit-${seg(String(astType))}-${this.synth.length + 1}`;
|
|
2076
|
+
this.synth.push({ id, name: `(inline ${astType})`, type: astType, value });
|
|
2077
|
+
this.synthKeys.set(key, id);
|
|
2078
|
+
this.issue("warning", "inline-literal", `inline ${astType} literal in an alias slot hoisted to token ${id}`, tok);
|
|
2079
|
+
return id;
|
|
2080
|
+
}
|
|
2081
|
+
peek() {
|
|
2082
|
+
return this.toks[this.pos];
|
|
2083
|
+
}
|
|
2084
|
+
next() {
|
|
2085
|
+
return this.toks[this.pos++];
|
|
2086
|
+
}
|
|
2087
|
+
at(type) {
|
|
2088
|
+
return this.peek().type === type;
|
|
2089
|
+
}
|
|
2090
|
+
// A `word` whose text equals `w` (case-sensitive keyword check).
|
|
2091
|
+
atWord(w) {
|
|
2092
|
+
const t = this.peek();
|
|
2093
|
+
return t.type === "word" && t.value === w;
|
|
2094
|
+
}
|
|
2095
|
+
skipNewlines() {
|
|
2096
|
+
while (this.at("newline") || this.at("semi")) this.pos++;
|
|
2097
|
+
}
|
|
2098
|
+
// Safety net: if a loop body made no progress (a malformed token that no rule
|
|
2099
|
+
// consumed), force one token forward so parsing can never spin. Returns true when
|
|
2100
|
+
// it had to intervene (the caller can also choose to break).
|
|
2101
|
+
ensureProgress(mark) {
|
|
2102
|
+
if (this.pos !== mark) return false;
|
|
2103
|
+
if (!this.at("eof")) this.next();
|
|
2104
|
+
return true;
|
|
2105
|
+
}
|
|
2106
|
+
issue(severity, code, message, tok = this.peek()) {
|
|
2107
|
+
this.issues.push({ severity, code, message, line: tok.line, col: tok.col });
|
|
2108
|
+
}
|
|
2109
|
+
// Consume a token of `type`, or record an error and synthesize one.
|
|
2110
|
+
expect(type, code) {
|
|
2111
|
+
if (this.at(type)) return this.next();
|
|
2112
|
+
const tok = this.peek();
|
|
2113
|
+
this.issue("error", code, `expected ${type}, got ${tok.type} ${JSON.stringify(tok.value)}`);
|
|
2114
|
+
return tok;
|
|
2115
|
+
}
|
|
2116
|
+
// A bare word (ident/path/number token).
|
|
2117
|
+
expectWord(code) {
|
|
2118
|
+
if (this.at("word")) return this.next().value;
|
|
2119
|
+
this.issue("error", code, `expected identifier, got ${this.peek().type}`);
|
|
2120
|
+
return "";
|
|
2121
|
+
}
|
|
2122
|
+
// Skip a balanced `{ … }` block (already positioned at or before the `{`).
|
|
2123
|
+
skipBlock() {
|
|
2124
|
+
while (!this.at("lbrace") && !this.at("eof") && !this.at("newline")) this.next();
|
|
2125
|
+
if (!this.at("lbrace")) return;
|
|
2126
|
+
let depth = 0;
|
|
2127
|
+
do {
|
|
2128
|
+
const t = this.next();
|
|
2129
|
+
if (t.type === "lbrace") depth++;
|
|
2130
|
+
else if (t.type === "rbrace") depth--;
|
|
2131
|
+
else if (t.type === "eof") break;
|
|
2132
|
+
} while (depth > 0);
|
|
2133
|
+
}
|
|
2134
|
+
// ── context-group NAME { ctx ctx … } ──
|
|
2135
|
+
parseContextGroup() {
|
|
2136
|
+
this.next();
|
|
2137
|
+
const name = this.expectWord("cg-name");
|
|
2138
|
+
this.expect("lbrace", "cg-lbrace");
|
|
2139
|
+
const contexts = [];
|
|
2140
|
+
while (!this.at("rbrace") && !this.at("eof")) {
|
|
2141
|
+
if (this.at("newline") || this.at("semi")) {
|
|
2142
|
+
this.pos++;
|
|
2143
|
+
continue;
|
|
2144
|
+
}
|
|
2145
|
+
const ctxName = this.expectWord("cg-ctx");
|
|
2146
|
+
if (!ctxName) break;
|
|
2147
|
+
contexts.push({ id: ctxId(name, ctxName), name: ctxName });
|
|
2148
|
+
}
|
|
2149
|
+
this.expect("rbrace", "cg-rbrace");
|
|
2150
|
+
return { id: cgId(name), name, contexts };
|
|
2151
|
+
}
|
|
2152
|
+
// ── raw value literal → a JS value (string | number | nested object) ──
|
|
2153
|
+
parseRawLiteral() {
|
|
2154
|
+
const t = this.peek();
|
|
2155
|
+
if (t.type === "string") return this.next().value;
|
|
2156
|
+
if (t.type === "lbrace") return this.parseStructured();
|
|
2157
|
+
if (t.type === "word") {
|
|
2158
|
+
const w = this.next().value;
|
|
2159
|
+
return NUMBER_RE.test(w) ? Number(w) : w;
|
|
2160
|
+
}
|
|
2161
|
+
this.issue("error", "raw-value", `expected a value, got ${t.type}`);
|
|
2162
|
+
return "";
|
|
2163
|
+
}
|
|
2164
|
+
parseStructured() {
|
|
2165
|
+
this.expect("lbrace", "struct-lbrace");
|
|
2166
|
+
const obj = {};
|
|
2167
|
+
while (!this.at("rbrace") && !this.at("eof")) {
|
|
2168
|
+
const mark = this.pos;
|
|
2169
|
+
if (this.at("newline") || this.at("semi")) {
|
|
2170
|
+
this.pos++;
|
|
2171
|
+
continue;
|
|
2172
|
+
}
|
|
2173
|
+
const key = this.expectWord("struct-key");
|
|
2174
|
+
this.expect("colon", "struct-colon");
|
|
2175
|
+
const val = this.parseRawLiteral();
|
|
2176
|
+
if (key) obj[key] = val;
|
|
2177
|
+
if (this.at("semi") || this.at("newline")) this.pos++;
|
|
2178
|
+
this.ensureProgress(mark);
|
|
2179
|
+
}
|
|
2180
|
+
this.expect("rbrace", "struct-rbrace");
|
|
2181
|
+
return obj;
|
|
2182
|
+
}
|
|
2183
|
+
// ── convert a raw JS value to the canonical typed value for `astType` ──
|
|
2184
|
+
typedRaw(astType, raw, tok) {
|
|
2185
|
+
if (astType === "color" && typeof raw === "string") {
|
|
2186
|
+
const color = hexToColor(raw);
|
|
2187
|
+
if (color) return { kind: "raw", value: color };
|
|
2188
|
+
this.issue("warning", "color-nonhex", `non-hex color "${raw}" kept as an escape value`, tok);
|
|
2189
|
+
return { kind: "escape", raw, note: "non-hex color literal" };
|
|
2190
|
+
}
|
|
2191
|
+
if (astType === "spacing" || astType === "radius" || astType === "size") {
|
|
2192
|
+
if (typeof raw === "number") return { kind: "raw", value: { value: raw, unit: "scaled" } };
|
|
2193
|
+
if (raw && typeof raw === "object" && "value" in raw) {
|
|
2194
|
+
const r = raw;
|
|
2195
|
+
return { kind: "raw", value: { value: Number(r.value), unit: r.unit ?? "scaled" } };
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
if (astType === "opacity" && typeof raw === "number") return { kind: "raw", value: { value: raw } };
|
|
2199
|
+
if (astType === "duration" && typeof raw === "number") return { kind: "raw", value: { ms: raw } };
|
|
2200
|
+
if (astType === "tonal" && typeof raw === "number") return { kind: "raw", value: { level: raw } };
|
|
2201
|
+
return { kind: "raw", value: raw };
|
|
2202
|
+
}
|
|
2203
|
+
// ── alias by GROUP { Ctx -> <path | inline literal> ; default -> … } ──
|
|
2204
|
+
// A slot value is normally a token path (ref). The authored surface also allows an
|
|
2205
|
+
// inline literal (a hex color, a structured value) in a slot; since the AST's `refs`
|
|
2206
|
+
// holds only ids, such literals are hoisted to synthesized tokens (hoistLiteral).
|
|
2207
|
+
parseAlias(astType) {
|
|
2208
|
+
this.next();
|
|
2209
|
+
if (this.atWord("by")) this.next();
|
|
2210
|
+
else this.issue("error", "alias-by", "expected 'by'");
|
|
2211
|
+
const groupName = this.expectWord("alias-group");
|
|
2212
|
+
this.expect("lbrace", "alias-lbrace");
|
|
2213
|
+
const refs = {};
|
|
2214
|
+
while (!this.at("rbrace") && !this.at("eof")) {
|
|
2215
|
+
const mark = this.pos;
|
|
2216
|
+
if (this.at("newline") || this.at("semi")) {
|
|
2217
|
+
this.pos++;
|
|
2218
|
+
continue;
|
|
2219
|
+
}
|
|
2220
|
+
const ctxName = this.expectWord("alias-ctx");
|
|
2221
|
+
this.expect("arrow", "alias-arrow");
|
|
2222
|
+
const slot = this.peek();
|
|
2223
|
+
let refId = "";
|
|
2224
|
+
if (slot.type === "string" || slot.type === "lbrace" || slot.type === "word" && NUMBER_RE.test(slot.value)) {
|
|
2225
|
+
refId = this.hoistLiteral(astType, this.parseRawLiteral(), slot);
|
|
2226
|
+
} else {
|
|
2227
|
+
const refPath = this.expectWord("alias-ref");
|
|
2228
|
+
if (refPath) refId = tokId(refPath);
|
|
2229
|
+
}
|
|
2230
|
+
if (ctxName && refId) {
|
|
2231
|
+
const key = ctxName === "default" ? "default" : ctxId(groupName, ctxName);
|
|
2232
|
+
refs[key] = refId;
|
|
2233
|
+
}
|
|
2234
|
+
if (this.at("semi") || this.at("newline")) this.pos++;
|
|
2235
|
+
this.ensureProgress(mark);
|
|
2236
|
+
}
|
|
2237
|
+
this.expect("rbrace", "alias-rbrace");
|
|
2238
|
+
return { kind: "alias", by: cgId(groupName), refs };
|
|
2239
|
+
}
|
|
2240
|
+
// ── the right-hand side of `token … =` ──
|
|
2241
|
+
parseTokenValue(astType) {
|
|
2242
|
+
const t = this.peek();
|
|
2243
|
+
if (t.type === "word" && t.value === "alias") return this.parseAlias(astType);
|
|
2244
|
+
if (t.type === "word" && t.value === "escape") {
|
|
2245
|
+
this.next();
|
|
2246
|
+
const raw = this.at("string") ? this.next().value : this.expectWord("escape-raw");
|
|
2247
|
+
let escNote;
|
|
2248
|
+
if (this.atWord("note")) {
|
|
2249
|
+
this.next();
|
|
2250
|
+
escNote = this.at("string") ? this.next().value : this.expectWord("escape-note");
|
|
2251
|
+
}
|
|
2252
|
+
const esc = { kind: "escape", raw };
|
|
2253
|
+
if (escNote) esc.note = escNote;
|
|
2254
|
+
return esc;
|
|
2255
|
+
}
|
|
2256
|
+
if (t.type === "word" && t.value === "raw") {
|
|
2257
|
+
this.next();
|
|
2258
|
+
const raw = this.parseRawLiteral();
|
|
2259
|
+
return this.typedRaw(astType, raw, t);
|
|
2260
|
+
}
|
|
2261
|
+
if (t.type === "lbrace") {
|
|
2262
|
+
const raw = this.parseStructured();
|
|
2263
|
+
return this.typedRaw(astType, raw, t);
|
|
2264
|
+
}
|
|
2265
|
+
if (t.type === "word") {
|
|
2266
|
+
const refPath = this.next().value;
|
|
2267
|
+
this.issue("warning", "ref-sugar", `unconditional ref "${refPath}" lowered to a default-only alias`, t);
|
|
2268
|
+
return { kind: "alias", by: "", refs: { default: tokId(refPath) } };
|
|
2269
|
+
}
|
|
2270
|
+
this.issue("error", "token-value", `expected a token value, got ${t.type}`);
|
|
2271
|
+
return { kind: "raw", value: "" };
|
|
2272
|
+
}
|
|
2273
|
+
// ── foundations { token PATH : TYPE = VALUE … } → one Layer ──
|
|
2274
|
+
parseFoundations(layer) {
|
|
2275
|
+
this.next();
|
|
2276
|
+
this.expect("lbrace", "foundations-lbrace");
|
|
2277
|
+
let order = 0;
|
|
2278
|
+
while (!this.at("rbrace") && !this.at("eof")) {
|
|
2279
|
+
const mark = this.pos;
|
|
2280
|
+
if (this.at("newline") || this.at("semi")) {
|
|
2281
|
+
this.pos++;
|
|
2282
|
+
continue;
|
|
2283
|
+
}
|
|
2284
|
+
if (this.atWord("token")) {
|
|
2285
|
+
const tok = this.parseTokenDecl(order);
|
|
2286
|
+
if (tok) {
|
|
2287
|
+
layer.tokens.push(tok);
|
|
2288
|
+
order++;
|
|
2289
|
+
}
|
|
2290
|
+
this.ensureProgress(mark);
|
|
2291
|
+
continue;
|
|
2292
|
+
}
|
|
2293
|
+
this.issue("error", "foundations-stmt", `unexpected ${JSON.stringify(this.peek().value)} in foundations`);
|
|
2294
|
+
while (!this.at("newline") && !this.at("semi") && !this.at("rbrace") && !this.at("eof")) this.next();
|
|
2295
|
+
this.ensureProgress(mark);
|
|
2296
|
+
}
|
|
2297
|
+
this.expect("rbrace", "foundations-rbrace");
|
|
2298
|
+
if (this.synth.length) {
|
|
2299
|
+
layer.tokens.push(...this.synth);
|
|
2300
|
+
this.synth = [];
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
parseTokenDecl(_order) {
|
|
2304
|
+
const startTok = this.next();
|
|
2305
|
+
const path = this.expectWord("token-path");
|
|
2306
|
+
if (!path) return null;
|
|
2307
|
+
this.expect("colon", "token-colon");
|
|
2308
|
+
const typeName = this.expectWord("token-type");
|
|
2309
|
+
const astType = TYPE_MAP[typeName];
|
|
2310
|
+
if (!astType) this.issue("warning", "token-type", `non-canonical token type "${typeName}" kept as-is`, startTok);
|
|
2311
|
+
this.expect("equals", "token-equals");
|
|
2312
|
+
const value = this.parseTokenValue(astType ?? typeName);
|
|
2313
|
+
return {
|
|
2314
|
+
id: tokId(path),
|
|
2315
|
+
name: path,
|
|
2316
|
+
type: astType ?? typeName,
|
|
2317
|
+
value
|
|
2318
|
+
};
|
|
2319
|
+
}
|
|
2320
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
2321
|
+
// Slice 2 — shared types
|
|
2322
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
2323
|
+
skipToTerminator() {
|
|
2324
|
+
while (!this.at("newline") && !this.at("semi") && !this.at("rbrace") && !this.at("eof")) this.next();
|
|
2325
|
+
}
|
|
2326
|
+
parseIdentList() {
|
|
2327
|
+
const out = [];
|
|
2328
|
+
if (this.at("word")) out.push(this.next().value);
|
|
2329
|
+
while (this.at("comma")) {
|
|
2330
|
+
this.next();
|
|
2331
|
+
if (this.at("word")) out.push(this.next().value);
|
|
2332
|
+
}
|
|
2333
|
+
return out;
|
|
2334
|
+
}
|
|
2335
|
+
parseObjectType() {
|
|
2336
|
+
this.expect("lbrace", "obj-lbrace");
|
|
2337
|
+
const fields = [];
|
|
2338
|
+
while (!this.at("rbrace") && !this.at("eof")) {
|
|
2339
|
+
const mark = this.pos;
|
|
2340
|
+
if (this.at("newline") || this.at("semi")) {
|
|
2341
|
+
this.pos++;
|
|
2342
|
+
continue;
|
|
2343
|
+
}
|
|
2344
|
+
const name = this.expectWord("field-name");
|
|
2345
|
+
let required = true;
|
|
2346
|
+
if (this.at("question")) {
|
|
2347
|
+
this.next();
|
|
2348
|
+
required = false;
|
|
2349
|
+
}
|
|
2350
|
+
this.expect("colon", "field-colon");
|
|
2351
|
+
const type = this.parseTypeExpr();
|
|
2352
|
+
if (name) fields.push({ id: `fld.${seg(name)}`, name, type, required });
|
|
2353
|
+
if (this.at("semi") || this.at("newline")) this.pos++;
|
|
2354
|
+
this.ensureProgress(mark);
|
|
2355
|
+
}
|
|
2356
|
+
this.expect("rbrace", "obj-rbrace");
|
|
2357
|
+
return { kind: "object", fields };
|
|
2358
|
+
}
|
|
2359
|
+
parseTypeExpr() {
|
|
2360
|
+
const t = this.peek();
|
|
2361
|
+
if (t.type !== "word") {
|
|
2362
|
+
this.issue("error", "type-expr", `expected a type, got ${t.type}`);
|
|
2363
|
+
return { kind: "string" };
|
|
2364
|
+
}
|
|
2365
|
+
const w = t.value;
|
|
2366
|
+
if (w === "string" || w === "number" || w === "boolean") {
|
|
2367
|
+
this.next();
|
|
2368
|
+
return { kind: w };
|
|
2369
|
+
}
|
|
2370
|
+
if (w === "enum") {
|
|
2371
|
+
this.next();
|
|
2372
|
+
this.expect("lparen", "enum-lparen");
|
|
2373
|
+
const values = this.parseIdentList();
|
|
2374
|
+
this.expect("rparen", "enum-rparen");
|
|
2375
|
+
return { kind: "enum", values };
|
|
2376
|
+
}
|
|
2377
|
+
if (w === "ref") {
|
|
2378
|
+
this.next();
|
|
2379
|
+
const name = this.expectWord("ref-name");
|
|
2380
|
+
return { kind: "ref", ref: stId(name) };
|
|
2381
|
+
}
|
|
2382
|
+
if (w === "array") {
|
|
2383
|
+
this.next();
|
|
2384
|
+
this.expect("lt", "array-lt");
|
|
2385
|
+
const item = this.parseTypeExpr();
|
|
2386
|
+
this.expect("gt", "array-gt");
|
|
2387
|
+
return { kind: "array", item };
|
|
2388
|
+
}
|
|
2389
|
+
if (w === "union") {
|
|
2390
|
+
this.next();
|
|
2391
|
+
this.expect("lparen", "union-lparen");
|
|
2392
|
+
const members = [this.parseTypeExpr()];
|
|
2393
|
+
while (this.at("comma")) {
|
|
2394
|
+
this.next();
|
|
2395
|
+
members.push(this.parseTypeExpr());
|
|
2396
|
+
}
|
|
2397
|
+
this.expect("rparen", "union-rparen");
|
|
2398
|
+
return { kind: "union", members };
|
|
2399
|
+
}
|
|
2400
|
+
if (w === "object") {
|
|
2401
|
+
this.next();
|
|
2402
|
+
return this.parseObjectType();
|
|
2403
|
+
}
|
|
2404
|
+
if (w === "component") {
|
|
2405
|
+
this.next();
|
|
2406
|
+
let componentIds;
|
|
2407
|
+
if (this.at("lparen")) {
|
|
2408
|
+
this.next();
|
|
2409
|
+
componentIds = this.parseIdentList().map(cmpId);
|
|
2410
|
+
this.expect("rparen", "component-rparen");
|
|
2411
|
+
}
|
|
2412
|
+
return { kind: "component", componentIds };
|
|
2413
|
+
}
|
|
2414
|
+
if (w === "context") {
|
|
2415
|
+
this.next();
|
|
2416
|
+
const group = this.expectWord("context-type");
|
|
2417
|
+
this.issue("warning", "context-type", `context-typed "${group}" lowered to ref (proposal 0001)`, t);
|
|
2418
|
+
return { kind: "ref", ref: cgId(group) };
|
|
2419
|
+
}
|
|
2420
|
+
this.next();
|
|
2421
|
+
return { kind: "ref", ref: stId(w) };
|
|
2422
|
+
}
|
|
2423
|
+
parseSharedType() {
|
|
2424
|
+
this.next();
|
|
2425
|
+
const name = this.expectWord("type-name");
|
|
2426
|
+
if (!name) return null;
|
|
2427
|
+
this.expect("equals", "type-equals");
|
|
2428
|
+
const definition = this.parseTypeExpr();
|
|
2429
|
+
return { id: stId(name), name, definition };
|
|
2430
|
+
}
|
|
2431
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
2432
|
+
// Slice 3 — components
|
|
2433
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
2434
|
+
// A condition's raw text: `prop` or `prop=value` (reused by wire/gate `when`).
|
|
2435
|
+
parseConditionText() {
|
|
2436
|
+
let text = this.expectWord("cond");
|
|
2437
|
+
if (this.at("equals")) {
|
|
2438
|
+
this.next();
|
|
2439
|
+
const v = this.at("string") ? this.next().value : this.expectWord("cond-val");
|
|
2440
|
+
text += `=${v}`;
|
|
2441
|
+
}
|
|
2442
|
+
return text;
|
|
2443
|
+
}
|
|
2444
|
+
// A prop condition → RealizeCond { prop, eq } (single `prop=value`).
|
|
2445
|
+
parseRealizeCond() {
|
|
2446
|
+
const prop = this.expectWord("rc-prop");
|
|
2447
|
+
let eq = true;
|
|
2448
|
+
if (this.at("equals")) {
|
|
2449
|
+
this.next();
|
|
2450
|
+
if (this.at("string")) eq = this.next().value;
|
|
2451
|
+
else {
|
|
2452
|
+
const v = this.expectWord("rc-val");
|
|
2453
|
+
eq = NUMBER_RE.test(v) ? Number(v) : v === "true" ? true : v === "false" ? false : v;
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
return { prop, eq };
|
|
2457
|
+
}
|
|
2458
|
+
parsePropDefault() {
|
|
2459
|
+
const t = this.peek();
|
|
2460
|
+
if (t.type === "string") return this.next().value;
|
|
2461
|
+
if (t.type === "word" && t.value === "alias") {
|
|
2462
|
+
this.next();
|
|
2463
|
+
if (this.atWord("by")) this.next();
|
|
2464
|
+
this.expectWord("alias-group");
|
|
2465
|
+
this.skipBlock();
|
|
2466
|
+
this.issue("warning", "alias-default", "context-aliased prop default skipped (proposal 0001)", t);
|
|
2467
|
+
return void 0;
|
|
2468
|
+
}
|
|
2469
|
+
if (t.type === "word") {
|
|
2470
|
+
this.next();
|
|
2471
|
+
if (NUMBER_RE.test(t.value)) return Number(t.value);
|
|
2472
|
+
if (t.value === "true") return true;
|
|
2473
|
+
if (t.value === "false") return false;
|
|
2474
|
+
return t.value;
|
|
2475
|
+
}
|
|
2476
|
+
this.issue("error", "prop-default", `expected a default value, got ${t.type}`);
|
|
2477
|
+
return void 0;
|
|
2478
|
+
}
|
|
2479
|
+
parsePropDecl() {
|
|
2480
|
+
const name = this.expectWord("prop-name");
|
|
2481
|
+
if (!name) return null;
|
|
2482
|
+
const type = this.parseTypeExpr();
|
|
2483
|
+
const prop = { id: `prop.${seg(name)}`, name, type };
|
|
2484
|
+
if (this.at("equals")) {
|
|
2485
|
+
this.next();
|
|
2486
|
+
const def = this.parsePropDefault();
|
|
2487
|
+
if (def !== void 0) prop.default = def;
|
|
2488
|
+
}
|
|
2489
|
+
if (this.atWord("bind")) {
|
|
2490
|
+
this.next();
|
|
2491
|
+
prop.binding = this.expectWord("bind-target");
|
|
2492
|
+
}
|
|
2493
|
+
return prop;
|
|
2494
|
+
}
|
|
2495
|
+
parseProps(props) {
|
|
2496
|
+
this.next();
|
|
2497
|
+
this.expect("lbrace", "props-lbrace");
|
|
2498
|
+
while (!this.at("rbrace") && !this.at("eof")) {
|
|
2499
|
+
const mark = this.pos;
|
|
2500
|
+
if (this.at("newline") || this.at("semi")) {
|
|
2501
|
+
this.pos++;
|
|
2502
|
+
continue;
|
|
2503
|
+
}
|
|
2504
|
+
const p = this.parsePropDecl();
|
|
2505
|
+
if (p) props.push(p);
|
|
2506
|
+
if (this.at("semi") || this.at("newline")) this.pos++;
|
|
2507
|
+
this.ensureProgress(mark);
|
|
2508
|
+
}
|
|
2509
|
+
this.expect("rbrace", "props-rbrace");
|
|
2510
|
+
}
|
|
2511
|
+
parseEvents(events) {
|
|
2512
|
+
this.next();
|
|
2513
|
+
this.expect("lbrace", "events-lbrace");
|
|
2514
|
+
while (!this.at("rbrace") && !this.at("eof")) {
|
|
2515
|
+
const mark = this.pos;
|
|
2516
|
+
if (this.at("newline") || this.at("semi")) {
|
|
2517
|
+
this.pos++;
|
|
2518
|
+
continue;
|
|
2519
|
+
}
|
|
2520
|
+
const name = this.expectWord("event-name");
|
|
2521
|
+
if (name) {
|
|
2522
|
+
const e = { name };
|
|
2523
|
+
if (this.atWord("from")) {
|
|
2524
|
+
this.next();
|
|
2525
|
+
e.from = this.expectWord("event-from");
|
|
2526
|
+
}
|
|
2527
|
+
events.push(e);
|
|
2528
|
+
}
|
|
2529
|
+
if (this.at("semi") || this.at("newline")) this.pos++;
|
|
2530
|
+
this.ensureProgress(mark);
|
|
2531
|
+
}
|
|
2532
|
+
this.expect("rbrace", "events-rbrace");
|
|
2533
|
+
}
|
|
2534
|
+
// `uses ATOM [ ( params ) ] as ALIAS`
|
|
2535
|
+
parseUses() {
|
|
2536
|
+
this.next();
|
|
2537
|
+
const atom = this.expectWord("uses-atom");
|
|
2538
|
+
if (!atom) return null;
|
|
2539
|
+
if (this.at("lparen")) {
|
|
2540
|
+
this.next();
|
|
2541
|
+
while (!this.at("rparen") && !this.at("eof") && !this.at("newline")) this.next();
|
|
2542
|
+
if (this.at("rparen")) this.next();
|
|
2543
|
+
}
|
|
2544
|
+
if (this.atWord("as")) this.next();
|
|
2545
|
+
else this.issue("warning", "uses-as", "expected 'as' in uses");
|
|
2546
|
+
const as = this.expectWord("uses-alias");
|
|
2547
|
+
return { atom, as };
|
|
2548
|
+
}
|
|
2549
|
+
// The `machineref` target of a wire, with an optional `(arg)`.
|
|
2550
|
+
parseWireEnd(code) {
|
|
2551
|
+
const end = this.expectWord(code);
|
|
2552
|
+
let arg;
|
|
2553
|
+
if (this.at("lparen")) {
|
|
2554
|
+
this.next();
|
|
2555
|
+
if (this.at("word")) arg = this.next().value;
|
|
2556
|
+
while (!this.at("rparen") && !this.at("eof") && !this.at("newline")) this.next();
|
|
2557
|
+
if (this.at("rparen")) this.next();
|
|
2558
|
+
}
|
|
2559
|
+
return { end, arg };
|
|
2560
|
+
}
|
|
2561
|
+
// `wire FROM [when COND] -> TO[(arg)]`
|
|
2562
|
+
parseWire() {
|
|
2563
|
+
this.next();
|
|
2564
|
+
const from = this.expectWord("wire-from");
|
|
2565
|
+
if (!from) return null;
|
|
2566
|
+
let when;
|
|
2567
|
+
if (this.atWord("when")) {
|
|
2568
|
+
this.next();
|
|
2569
|
+
when = this.parseConditionText();
|
|
2570
|
+
}
|
|
2571
|
+
this.expect("arrow", "wire-arrow");
|
|
2572
|
+
const { end: to, arg } = this.parseWireEnd("wire-to");
|
|
2573
|
+
const wire = { kind: "wire", from, to };
|
|
2574
|
+
if (arg) wire.arg = arg;
|
|
2575
|
+
if (when) wire.when = when;
|
|
2576
|
+
return wire;
|
|
2577
|
+
}
|
|
2578
|
+
// `gate MACHINE active when COND`
|
|
2579
|
+
parseGate() {
|
|
2580
|
+
this.next();
|
|
2581
|
+
const machine = this.expectWord("gate-machine");
|
|
2582
|
+
if (!machine) return null;
|
|
2583
|
+
if (this.atWord("active")) this.next();
|
|
2584
|
+
if (this.atWord("when")) this.next();
|
|
2585
|
+
else this.issue("warning", "gate-when", "expected 'when' in gate");
|
|
2586
|
+
const activeWhen = this.parseConditionText();
|
|
2587
|
+
return { kind: "gate", machine, activeWhen };
|
|
2588
|
+
}
|
|
2589
|
+
// ── layout / facet bodies ──
|
|
2590
|
+
parseAxisIntent() {
|
|
2591
|
+
const w = this.expectWord("axis");
|
|
2592
|
+
if (w === "fit" || w === "fill") return w;
|
|
2593
|
+
if (w === "weight") {
|
|
2594
|
+
if (this.at("lparen")) {
|
|
2595
|
+
this.next();
|
|
2596
|
+
const n = Number(this.expectWord("weight-n"));
|
|
2597
|
+
if (this.at("rparen")) this.next();
|
|
2598
|
+
return { weight: n };
|
|
2599
|
+
}
|
|
2600
|
+
return { weight: 1 };
|
|
2601
|
+
}
|
|
2602
|
+
if (w === "fixed") {
|
|
2603
|
+
if (this.at("lparen")) {
|
|
2604
|
+
this.next();
|
|
2605
|
+
const p = this.expectWord("fixed-token");
|
|
2606
|
+
if (this.at("rparen")) this.next();
|
|
2607
|
+
return { fixed: tokId(p) };
|
|
2608
|
+
}
|
|
2609
|
+
this.issue("warning", "axis-fixed", "bare 'fixed' axis has no dimension; treated as fit");
|
|
2610
|
+
return "fit";
|
|
2611
|
+
}
|
|
2612
|
+
this.issue("warning", "axis-unknown", `unknown size intent "${w}"; treated as fit`);
|
|
2613
|
+
return "fit";
|
|
2614
|
+
}
|
|
2615
|
+
parseInsetArgs() {
|
|
2616
|
+
const args = [];
|
|
2617
|
+
while (this.at("word") && args.length < 2) args.push(this.next().value);
|
|
2618
|
+
if (args.length >= 2) return { block: tokId(args[0]), inline: tokId(args[1]) };
|
|
2619
|
+
if (args.length === 1) return { all: tokId(args[0]) };
|
|
2620
|
+
return { all: "" };
|
|
2621
|
+
}
|
|
2622
|
+
parseLayoutBody() {
|
|
2623
|
+
this.expect("lbrace", "layout-lbrace");
|
|
2624
|
+
const spec = {};
|
|
2625
|
+
while (!this.at("rbrace") && !this.at("eof")) {
|
|
2626
|
+
const mark = this.pos;
|
|
2627
|
+
if (this.at("newline") || this.at("semi")) {
|
|
2628
|
+
this.pos++;
|
|
2629
|
+
continue;
|
|
2630
|
+
}
|
|
2631
|
+
const key = this.expectWord("layout-key");
|
|
2632
|
+
switch (key) {
|
|
2633
|
+
case "stack":
|
|
2634
|
+
spec.stack = this.expectWord("stack");
|
|
2635
|
+
break;
|
|
2636
|
+
case "flow":
|
|
2637
|
+
spec.flow = true;
|
|
2638
|
+
break;
|
|
2639
|
+
case "gap":
|
|
2640
|
+
spec.gap = tokId(this.expectWord("gap"));
|
|
2641
|
+
break;
|
|
2642
|
+
case "align":
|
|
2643
|
+
spec.align = this.expectWord("align");
|
|
2644
|
+
break;
|
|
2645
|
+
case "distribute":
|
|
2646
|
+
spec.distribute = this.expectWord("distribute");
|
|
2647
|
+
break;
|
|
2648
|
+
case "wrap": {
|
|
2649
|
+
const w = this.expectWord("wrap");
|
|
2650
|
+
if (w === "wrap" || w === "wrap-reverse") spec.flow = true;
|
|
2651
|
+
break;
|
|
2652
|
+
}
|
|
2653
|
+
case "position": {
|
|
2654
|
+
const p = this.expectWord("position");
|
|
2655
|
+
spec.position = p === "overlay" || p === "flow" ? p : { pinned: p };
|
|
2656
|
+
break;
|
|
2657
|
+
}
|
|
2658
|
+
case "size": {
|
|
2659
|
+
const width = this.parseAxisIntent();
|
|
2660
|
+
const height = this.parseAxisIntent();
|
|
2661
|
+
spec.size = { width, height };
|
|
2662
|
+
break;
|
|
2663
|
+
}
|
|
2664
|
+
case "ratio": {
|
|
2665
|
+
const wv = Number(this.expectWord("ratio-w"));
|
|
2666
|
+
const hv = Number(this.expectWord("ratio-h"));
|
|
2667
|
+
spec.size = { ...spec.size ?? {}, width: { ratio: { w: wv, h: hv } } };
|
|
2668
|
+
break;
|
|
2669
|
+
}
|
|
2670
|
+
case "inset":
|
|
2671
|
+
spec.inset = this.parseInsetArgs();
|
|
2672
|
+
break;
|
|
2673
|
+
default:
|
|
2674
|
+
this.issue("warning", "layout-key", `unknown layout key "${key}" skipped`);
|
|
2675
|
+
this.skipToTerminator();
|
|
2676
|
+
}
|
|
2677
|
+
if (this.at("semi") || this.at("newline")) this.pos++;
|
|
2678
|
+
this.ensureProgress(mark);
|
|
2679
|
+
}
|
|
2680
|
+
this.expect("rbrace", "layout-rbrace");
|
|
2681
|
+
return spec;
|
|
2682
|
+
}
|
|
2683
|
+
// A single facet statement `facetname value+` → [FacetName, FacetValue] | null.
|
|
2684
|
+
parseFacetStmt() {
|
|
2685
|
+
const raw = this.expectWord("facet-name");
|
|
2686
|
+
const mapped = FACET_MAP[raw];
|
|
2687
|
+
if (mapped === void 0) {
|
|
2688
|
+
this.issue("warning", "facet-unknown", `unknown facet "${raw}" skipped`);
|
|
2689
|
+
this.skipToTerminator();
|
|
2690
|
+
return null;
|
|
2691
|
+
}
|
|
2692
|
+
if (mapped === null) {
|
|
2693
|
+
this.issue("warning", "facet-nohome", `facet "${raw}" has no AST FacetMap home (\xA73) \u2014 skipped`);
|
|
2694
|
+
this.skipToTerminator();
|
|
2695
|
+
return null;
|
|
2696
|
+
}
|
|
2697
|
+
if (mapped === "inset") {
|
|
2698
|
+
return { name: "inset", value: { inset: this.parseInsetArgs() } };
|
|
2699
|
+
}
|
|
2700
|
+
const t = this.peek();
|
|
2701
|
+
let value;
|
|
2702
|
+
if (t.type === "string") {
|
|
2703
|
+
value = { raw: this.next().value };
|
|
2704
|
+
} else if (t.type === "word") {
|
|
2705
|
+
const v = this.next().value;
|
|
2706
|
+
if (NUMBER_RE.test(v)) value = { literal: Number(v) };
|
|
2707
|
+
else if (isRawValue(v)) value = { raw: v };
|
|
2708
|
+
else value = { token: tokId(v) };
|
|
2709
|
+
} else {
|
|
2710
|
+
this.issue("error", "facet-value", `expected a facet value, got ${t.type}`);
|
|
2711
|
+
this.skipToTerminator();
|
|
2712
|
+
return null;
|
|
2713
|
+
}
|
|
2714
|
+
if (!this.at("semi") && !this.at("newline") && !this.at("rbrace")) this.skipToTerminator();
|
|
2715
|
+
return { name: mapped, value };
|
|
2716
|
+
}
|
|
2717
|
+
// `state NAME [when COND] { … }` → a PartVariant with one interaction state.
|
|
2718
|
+
parseStateBlock() {
|
|
2719
|
+
this.next();
|
|
2720
|
+
const name = this.expectWord("state-name");
|
|
2721
|
+
const variant = { states: [name] };
|
|
2722
|
+
if (this.atWord("when")) {
|
|
2723
|
+
this.next();
|
|
2724
|
+
variant.when = this.parseRealizeCond();
|
|
2725
|
+
}
|
|
2726
|
+
this.applyStyleBody(variant);
|
|
2727
|
+
return variant;
|
|
2728
|
+
}
|
|
2729
|
+
// `when COND { … }` → a state-less prop-conditioned PartVariant (proposal 0025).
|
|
2730
|
+
parseWhenBlock() {
|
|
2731
|
+
this.next();
|
|
2732
|
+
const when = this.parseRealizeCond();
|
|
2733
|
+
const variant = { when };
|
|
2734
|
+
this.applyStyleBody(variant);
|
|
2735
|
+
return variant;
|
|
2736
|
+
}
|
|
2737
|
+
// Parse a `{ facet… / layout… }` style body into a variant's facets/layout.
|
|
2738
|
+
applyStyleBody(target) {
|
|
2739
|
+
this.expect("lbrace", "style-lbrace");
|
|
2740
|
+
const facets2 = {};
|
|
2741
|
+
while (!this.at("rbrace") && !this.at("eof")) {
|
|
2742
|
+
const mark = this.pos;
|
|
2743
|
+
if (this.at("newline") || this.at("semi")) {
|
|
2744
|
+
this.pos++;
|
|
2745
|
+
continue;
|
|
2746
|
+
}
|
|
2747
|
+
if (this.atWord("layout")) {
|
|
2748
|
+
this.next();
|
|
2749
|
+
target.layout = this.parseLayoutBody();
|
|
2750
|
+
} else {
|
|
2751
|
+
const f = this.parseFacetStmt();
|
|
2752
|
+
if (f) facets2[f.name] = f.value;
|
|
2753
|
+
}
|
|
2754
|
+
if (this.at("semi") || this.at("newline")) this.pos++;
|
|
2755
|
+
this.ensureProgress(mark);
|
|
2756
|
+
}
|
|
2757
|
+
this.expect("rbrace", "style-rbrace");
|
|
2758
|
+
if (Object.keys(facets2).length) target.facets = facets2;
|
|
2759
|
+
}
|
|
2760
|
+
// `part NAME { pstmt* }` → [name, Part]
|
|
2761
|
+
parsePart() {
|
|
2762
|
+
this.next();
|
|
2763
|
+
const name = this.expectWord("part-name");
|
|
2764
|
+
if (!name) return null;
|
|
2765
|
+
this.expect("lbrace", "part-lbrace");
|
|
2766
|
+
const part = {};
|
|
2767
|
+
const facets2 = {};
|
|
2768
|
+
const variants = [];
|
|
2769
|
+
while (!this.at("rbrace") && !this.at("eof")) {
|
|
2770
|
+
const mark = this.pos;
|
|
2771
|
+
if (this.at("newline") || this.at("semi")) {
|
|
2772
|
+
this.pos++;
|
|
2773
|
+
continue;
|
|
2774
|
+
}
|
|
2775
|
+
if (this.atWord("layout")) {
|
|
2776
|
+
this.next();
|
|
2777
|
+
if (this.atWord("when")) {
|
|
2778
|
+
this.next();
|
|
2779
|
+
const when = this.parseRealizeCond();
|
|
2780
|
+
variants.push({ when, layout: this.parseLayoutBody() });
|
|
2781
|
+
} else {
|
|
2782
|
+
part.layout = this.parseLayoutBody();
|
|
2783
|
+
}
|
|
2784
|
+
} else if (this.atWord("state")) {
|
|
2785
|
+
variants.push(this.parseStateBlock());
|
|
2786
|
+
} else if (this.atWord("when")) {
|
|
2787
|
+
variants.push(this.parseWhenBlock());
|
|
2788
|
+
} else if (this.atWord("slot")) {
|
|
2789
|
+
this.issue("warning", "slot", "part `slot` has no AST Part field yet \u2014 skipped");
|
|
2790
|
+
this.skipToTerminator();
|
|
2791
|
+
} else {
|
|
2792
|
+
const f = this.parseFacetStmt();
|
|
2793
|
+
if (f) facets2[f.name] = f.value;
|
|
2794
|
+
}
|
|
2795
|
+
if (this.at("semi") || this.at("newline")) this.pos++;
|
|
2796
|
+
this.ensureProgress(mark);
|
|
2797
|
+
}
|
|
2798
|
+
this.expect("rbrace", "part-rbrace");
|
|
2799
|
+
if (Object.keys(facets2).length) part.facets = facets2;
|
|
2800
|
+
if (variants.length) part.variants = variants;
|
|
2801
|
+
return [name, part];
|
|
2802
|
+
}
|
|
2803
|
+
// `realize TARGET [when COND] { rstmt* }`
|
|
2804
|
+
parseRealize() {
|
|
2805
|
+
this.next();
|
|
2806
|
+
const target = this.expectWord("realize-target");
|
|
2807
|
+
if (!target) return null;
|
|
2808
|
+
let when = null;
|
|
2809
|
+
if (this.atWord("when")) {
|
|
2810
|
+
this.next();
|
|
2811
|
+
when = this.parseRealizeCond();
|
|
2812
|
+
}
|
|
2813
|
+
const r = { target, when };
|
|
2814
|
+
this.expect("lbrace", "realize-lbrace");
|
|
2815
|
+
const wires = [];
|
|
2816
|
+
while (!this.at("rbrace") && !this.at("eof")) {
|
|
2817
|
+
const mark = this.pos;
|
|
2818
|
+
if (this.at("newline") || this.at("semi")) {
|
|
2819
|
+
this.pos++;
|
|
2820
|
+
continue;
|
|
2821
|
+
}
|
|
2822
|
+
const kw = this.peek().value;
|
|
2823
|
+
if (this.atWord("presentation")) {
|
|
2824
|
+
this.next();
|
|
2825
|
+
const surface = this.at("word") ? this.next().value : void 0;
|
|
2826
|
+
const pres = {};
|
|
2827
|
+
if (surface) pres.surface = surface;
|
|
2828
|
+
if (this.at("lbrace")) this.parsePresentationBody(pres);
|
|
2829
|
+
r.presentation = pres;
|
|
2830
|
+
} else if (this.atWord("browse")) {
|
|
2831
|
+
this.next();
|
|
2832
|
+
const mode = this.at("word") ? this.next().value : void 0;
|
|
2833
|
+
r.browse = { mode };
|
|
2834
|
+
if (this.at("lbrace")) this.skipBlock();
|
|
2835
|
+
} else if (this.atWord("commit")) {
|
|
2836
|
+
this.next();
|
|
2837
|
+
r.commit = this.parseCommit();
|
|
2838
|
+
} else if (this.atWord("drop")) {
|
|
2839
|
+
this.next();
|
|
2840
|
+
r.drop = this.parseIdentListWords();
|
|
2841
|
+
} else if (this.atWord("note")) {
|
|
2842
|
+
this.next();
|
|
2843
|
+
r.note = this.at("string") ? this.next().value : this.expectWord("note");
|
|
2844
|
+
} else if (this.atWord("wire")) {
|
|
2845
|
+
const w = this.parseWire();
|
|
2846
|
+
if (w && w.kind === "wire") wires.push({ from: w.from, to: w.to, ...w.arg ? { arg: w.arg } : {} });
|
|
2847
|
+
} else {
|
|
2848
|
+
this.issue("warning", "realize-stmt", `unknown realize statement "${kw}" skipped`);
|
|
2849
|
+
if (this.at("lbrace")) this.skipBlock();
|
|
2850
|
+
else this.skipToTerminator();
|
|
2851
|
+
}
|
|
2852
|
+
if (this.at("semi") || this.at("newline")) this.pos++;
|
|
2853
|
+
this.ensureProgress(mark);
|
|
2854
|
+
}
|
|
2855
|
+
this.expect("rbrace", "realize-rbrace");
|
|
2856
|
+
if (wires.length) r.wire = wires;
|
|
2857
|
+
return r;
|
|
2858
|
+
}
|
|
2859
|
+
parsePresentationBody(pres) {
|
|
2860
|
+
this.expect("lbrace", "pres-lbrace");
|
|
2861
|
+
while (!this.at("rbrace") && !this.at("eof")) {
|
|
2862
|
+
const mark = this.pos;
|
|
2863
|
+
if (this.at("newline") || this.at("semi")) {
|
|
2864
|
+
this.pos++;
|
|
2865
|
+
continue;
|
|
2866
|
+
}
|
|
2867
|
+
const key = this.expectWord("pres-key");
|
|
2868
|
+
if (key === "place") pres.place = this.expectWord("place");
|
|
2869
|
+
else if (key === "flip") pres.flip = true;
|
|
2870
|
+
else if (key === "matchWidth") pres.matchWidth = true;
|
|
2871
|
+
else this.skipToTerminator();
|
|
2872
|
+
if (this.at("semi") || this.at("newline")) this.pos++;
|
|
2873
|
+
this.ensureProgress(mark);
|
|
2874
|
+
}
|
|
2875
|
+
this.expect("rbrace", "pres-rbrace");
|
|
2876
|
+
}
|
|
2877
|
+
parseCommit() {
|
|
2878
|
+
const modeWord = this.expectWord("commit-mode");
|
|
2879
|
+
const mode = modeWord === "continuous" ? "continuous" : "explicit";
|
|
2880
|
+
const commit = { mode };
|
|
2881
|
+
if (this.atWord("on")) {
|
|
2882
|
+
this.next();
|
|
2883
|
+
commit.on = this.parseIdentListWords();
|
|
2884
|
+
}
|
|
2885
|
+
return commit;
|
|
2886
|
+
}
|
|
2887
|
+
// A run of bare words up to a terminator (for `drop a b c`, `commit … on click enter`).
|
|
2888
|
+
parseIdentListWords() {
|
|
2889
|
+
const out = [];
|
|
2890
|
+
while (this.at("word")) out.push(this.next().value);
|
|
2891
|
+
return out;
|
|
2892
|
+
}
|
|
2893
|
+
parseComponent() {
|
|
2894
|
+
this.next();
|
|
2895
|
+
const name = this.expectWord("component-name");
|
|
2896
|
+
if (!name) return null;
|
|
2897
|
+
let description;
|
|
2898
|
+
if (this.at("string")) description = this.next().value;
|
|
2899
|
+
this.expect("lbrace", "component-lbrace");
|
|
2900
|
+
let archetype = "";
|
|
2901
|
+
const props = [];
|
|
2902
|
+
const events = [];
|
|
2903
|
+
const uses = [];
|
|
2904
|
+
const coordination = [];
|
|
2905
|
+
const anatomy = {};
|
|
2906
|
+
const realize = [];
|
|
2907
|
+
while (!this.at("rbrace") && !this.at("eof")) {
|
|
2908
|
+
const mark = this.pos;
|
|
2909
|
+
if (this.at("newline") || this.at("semi")) {
|
|
2910
|
+
this.pos++;
|
|
2911
|
+
continue;
|
|
2912
|
+
}
|
|
2913
|
+
if (this.atWord("archetype")) {
|
|
2914
|
+
this.next();
|
|
2915
|
+
archetype = this.expectWord("archetype");
|
|
2916
|
+
} else if (this.atWord("props")) {
|
|
2917
|
+
this.parseProps(props);
|
|
2918
|
+
} else if (this.atWord("events")) {
|
|
2919
|
+
this.parseEvents(events);
|
|
2920
|
+
} else if (this.atWord("uses")) {
|
|
2921
|
+
const u = this.parseUses();
|
|
2922
|
+
if (u) uses.push(u);
|
|
2923
|
+
} else if (this.atWord("wire")) {
|
|
2924
|
+
const w = this.parseWire();
|
|
2925
|
+
if (w) coordination.push(w);
|
|
2926
|
+
} else if (this.atWord("gate")) {
|
|
2927
|
+
const g = this.parseGate();
|
|
2928
|
+
if (g) coordination.push(g);
|
|
2929
|
+
} else if (this.atWord("motion")) {
|
|
2930
|
+
this.issue("warning", "motion", "component-level motion parsed as a note \u2014 skipped");
|
|
2931
|
+
this.skipToTerminator();
|
|
2932
|
+
} else if (this.atWord("requires")) {
|
|
2933
|
+
this.next();
|
|
2934
|
+
this.parseIdentListWords();
|
|
2935
|
+
this.issue("warning", "requires", "component `requires` (capability gate) has no AST field \u2014 skipped");
|
|
2936
|
+
} else if (this.atWord("part")) {
|
|
2937
|
+
const p = this.parsePart();
|
|
2938
|
+
if (p) anatomy[p[0]] = p[1];
|
|
2939
|
+
} else if (this.atWord("realize")) {
|
|
2940
|
+
const r = this.parseRealize();
|
|
2941
|
+
if (r) realize.push(r);
|
|
2942
|
+
} else {
|
|
2943
|
+
this.issue("error", "component-stmt", `unexpected ${JSON.stringify(this.peek().value)} in component`);
|
|
2944
|
+
if (this.at("lbrace")) this.skipBlock();
|
|
2945
|
+
else this.skipToTerminator();
|
|
2946
|
+
}
|
|
2947
|
+
this.ensureProgress(mark);
|
|
2948
|
+
}
|
|
2949
|
+
this.expect("rbrace", "component-rbrace");
|
|
2950
|
+
const component = {
|
|
2951
|
+
id: cmpId(name),
|
|
2952
|
+
name,
|
|
2953
|
+
archetype,
|
|
2954
|
+
contract: { params: {}, props, events },
|
|
2955
|
+
anatomy,
|
|
2956
|
+
realize
|
|
2957
|
+
};
|
|
2958
|
+
if (description) component.description = description;
|
|
2959
|
+
if (uses.length || coordination.length) {
|
|
2960
|
+
const composition = { uses, coordination };
|
|
2961
|
+
component.composition = composition;
|
|
2962
|
+
}
|
|
2963
|
+
return component;
|
|
2964
|
+
}
|
|
2965
|
+
// ── top-level document driver ──
|
|
2966
|
+
parseDocument(opts) {
|
|
2967
|
+
const contextGroups = [];
|
|
2968
|
+
const layer = { id: "layer.foundations", name: "Foundations", order: 0, tokens: [] };
|
|
2969
|
+
const sharedTypes = [];
|
|
2970
|
+
const components = [];
|
|
2971
|
+
this.skipNewlines();
|
|
2972
|
+
while (!this.at("eof")) {
|
|
2973
|
+
const mark = this.pos;
|
|
2974
|
+
if (this.atWord("context-group")) {
|
|
2975
|
+
const cg = this.parseContextGroup();
|
|
2976
|
+
if (cg) contextGroups.push(cg);
|
|
2977
|
+
} else if (this.atWord("foundations")) {
|
|
2978
|
+
this.parseFoundations(layer);
|
|
2979
|
+
} else if (this.atWord("type")) {
|
|
2980
|
+
const st = this.parseSharedType();
|
|
2981
|
+
if (st) sharedTypes.push(st);
|
|
2982
|
+
} else if (this.atWord("component")) {
|
|
2983
|
+
const c = this.parseComponent();
|
|
2984
|
+
if (c) components.push(c);
|
|
2985
|
+
} else {
|
|
2986
|
+
const tok = this.peek();
|
|
2987
|
+
this.issue("error", "top-level", `unexpected top-level ${JSON.stringify(tok.value || tok.type)}`);
|
|
2988
|
+
this.next();
|
|
2989
|
+
}
|
|
2990
|
+
this.ensureProgress(mark);
|
|
2991
|
+
this.skipNewlines();
|
|
2992
|
+
}
|
|
2993
|
+
return {
|
|
2994
|
+
milda: opts.milda ?? "0.1",
|
|
2995
|
+
kind: "design-system",
|
|
2996
|
+
prelude: opts.prelude ?? "0.0.2",
|
|
2997
|
+
meta: {
|
|
2998
|
+
id: `ds.${seg(opts.name ?? "design-system")}`,
|
|
2999
|
+
name: opts.name ?? "Design system",
|
|
3000
|
+
version: "0.0.0"
|
|
3001
|
+
},
|
|
3002
|
+
foundations: {
|
|
3003
|
+
contextGroups,
|
|
3004
|
+
layers: layer.tokens.length ? [layer] : [],
|
|
3005
|
+
sharedTypes,
|
|
3006
|
+
metadata: []
|
|
3007
|
+
},
|
|
3008
|
+
components
|
|
3009
|
+
};
|
|
3010
|
+
}
|
|
3011
|
+
};
|
|
3012
|
+
function parseMildaDocument(src, opts = {}) {
|
|
3013
|
+
let toks;
|
|
3014
|
+
try {
|
|
3015
|
+
toks = lex(src);
|
|
3016
|
+
} catch (e) {
|
|
3017
|
+
const le = e;
|
|
3018
|
+
return {
|
|
3019
|
+
document: emptyDocument(opts),
|
|
3020
|
+
issues: [{ severity: "error", code: "lex", message: le.message, line: le.line ?? 1, col: le.col ?? 1 }]
|
|
3021
|
+
};
|
|
3022
|
+
}
|
|
3023
|
+
const p = new Parser(toks);
|
|
3024
|
+
const document = p.parseDocument(opts);
|
|
3025
|
+
return { document, issues: p.issues };
|
|
3026
|
+
}
|
|
3027
|
+
function emptyDocument(opts) {
|
|
3028
|
+
return {
|
|
3029
|
+
milda: opts.milda ?? "0.1",
|
|
3030
|
+
kind: "design-system",
|
|
3031
|
+
prelude: opts.prelude ?? "0.0.2",
|
|
3032
|
+
meta: { id: `ds.${seg(opts.name ?? "design-system")}`, name: opts.name ?? "Design system", version: "0.0.0" },
|
|
3033
|
+
foundations: { contextGroups: [], layers: [], sharedTypes: [], metadata: [] },
|
|
3034
|
+
components: []
|
|
3035
|
+
};
|
|
3036
|
+
}
|
|
3037
|
+
export {
|
|
3038
|
+
LexError,
|
|
3039
|
+
TOKEN_VALUE_KIND,
|
|
3040
|
+
allTokensOfType,
|
|
3041
|
+
archetypesByName,
|
|
3042
|
+
atomsByName,
|
|
3043
|
+
collectActiveStates,
|
|
3044
|
+
conformance,
|
|
3045
|
+
findToken,
|
|
3046
|
+
lex,
|
|
3047
|
+
parseMildaDocument,
|
|
3048
|
+
preludeV0,
|
|
3049
|
+
resolveFacets,
|
|
3050
|
+
resolveLayout,
|
|
3051
|
+
resolveToken,
|
|
3052
|
+
validate
|
|
3053
|
+
};
|