@wireweave/core 4.0.0-beta.0 → 4.0.0-beta.13

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.
Files changed (50) hide show
  1. package/README.md +17 -462
  2. package/dist/app.cjs +50 -0
  3. package/dist/app.d.cts +488 -0
  4. package/dist/app.d.ts +488 -0
  5. package/dist/app.js +1 -0
  6. package/dist/chunk-3RWGG5EC.js +18042 -0
  7. package/dist/chunk-4TMDPWPR.cjs +186 -0
  8. package/dist/chunk-4UZBGIGJ.cjs +4359 -0
  9. package/dist/chunk-5DGRIQDU.cjs +824 -0
  10. package/dist/chunk-ETV4XYOV.cjs +5 -0
  11. package/dist/chunk-FS6A6EJ4.js +4345 -0
  12. package/dist/chunk-IMUVIIJR.cjs +18051 -0
  13. package/dist/chunk-JJWAFHSV.js +821 -0
  14. package/dist/chunk-MD6MNOEQ.cjs +2884 -0
  15. package/dist/chunk-PKBMQBKP.js +5 -0
  16. package/dist/chunk-R5WBZWBC.js +180 -0
  17. package/dist/chunk-V3HVWC7C.js +2874 -0
  18. package/dist/chunk-XYACLXXF.js +51484 -0
  19. package/dist/chunk-ZPHNXJRY.cjs +51590 -0
  20. package/dist/index-BGU_4N4W.d.ts +240 -0
  21. package/dist/index-BlNYFaZd.d.cts +337 -0
  22. package/dist/index-Cx4-VXVS.d.ts +337 -0
  23. package/dist/index-DyXaMSgd.d.cts +240 -0
  24. package/dist/index.cjs +1844 -58238
  25. package/dist/index.d.cts +556 -102
  26. package/dist/index.d.ts +556 -102
  27. package/dist/index.js +1163 -58104
  28. package/dist/interaction.cjs +26 -0
  29. package/dist/interaction.d.cts +3 -0
  30. package/dist/interaction.d.ts +3 -0
  31. package/dist/interaction.js +1 -0
  32. package/dist/parser.cjs +34 -6611
  33. package/dist/parser.d.cts +11 -2
  34. package/dist/parser.d.ts +11 -2
  35. package/dist/parser.js +1 -6585
  36. package/dist/renderer.cjs +119 -50537
  37. package/dist/renderer.d.cts +348 -123
  38. package/dist/renderer.d.ts +348 -123
  39. package/dist/renderer.js +3 -50499
  40. package/dist/spec.cjs +94 -0
  41. package/dist/spec.d.cts +301 -0
  42. package/dist/spec.d.ts +301 -0
  43. package/dist/spec.js +1 -0
  44. package/dist/{types-hEr_afgw.d.cts → types-CGRi1k2N.d.cts} +307 -27
  45. package/dist/{types-hEr_afgw.d.ts → types-CGRi1k2N.d.ts} +307 -27
  46. package/dist/types-Dkgr0Wyc.d.cts +75 -0
  47. package/dist/types-Dkgr0Wyc.d.ts +75 -0
  48. package/dist/v4-types-2ORUg6To.d.cts +137 -0
  49. package/dist/v4-types-2ORUg6To.d.ts +137 -0
  50. package/package.json +112 -35
@@ -0,0 +1,824 @@
1
+ 'use strict';
2
+
3
+ var chunkZPHNXJRY_cjs = require('./chunk-ZPHNXJRY.cjs');
4
+
5
+ // src/ast/expand-variants.ts
6
+ function cloneNode(value) {
7
+ if (Array.isArray(value)) return value.map(cloneNode);
8
+ if (value === null || typeof value !== "object") return value;
9
+ const source = value;
10
+ const result = {};
11
+ for (const [key, item] of Object.entries(source)) {
12
+ result[key] = key === "loc" ? item : cloneNode(item);
13
+ }
14
+ return result;
15
+ }
16
+ function variantNames(page) {
17
+ const declared = page.variants;
18
+ if (!Array.isArray(declared)) return [];
19
+ const seen = /* @__PURE__ */ new Set();
20
+ const names = [];
21
+ for (const raw of declared) {
22
+ if (typeof raw !== "string") continue;
23
+ const name = raw.trim();
24
+ if (name.length === 0 || seen.has(name)) continue;
25
+ seen.add(name);
26
+ names.push(name);
27
+ }
28
+ return names;
29
+ }
30
+ function hasVariants(document) {
31
+ return document.children.some((child) => child.type === "Page" && variantNames(child).length > 0);
32
+ }
33
+ function expandVariants(document) {
34
+ if (!hasVariants(document)) return chunkZPHNXJRY_cjs.filterUnscopedPages(document);
35
+ return {
36
+ ...document,
37
+ children: document.children.flatMap((child) => {
38
+ if (child.type !== "Page") return [child];
39
+ const names = variantNames(child);
40
+ if (names.length === 0) {
41
+ const filtered = chunkZPHNXJRY_cjs.filterVariantScope(child.children, void 0);
42
+ return [filtered === child.children ? child : { ...child, children: filtered }];
43
+ }
44
+ return names.map((variant, position) => {
45
+ const clone = cloneNode(child);
46
+ delete clone.variants;
47
+ clone.variant = variant;
48
+ if (position > 0) delete clone.states;
49
+ clone.children = chunkZPHNXJRY_cjs.filterVariantScope(clone.children, variant);
50
+ return clone;
51
+ });
52
+ })
53
+ };
54
+ }
55
+
56
+ // src/renderer/site/styles.ts
57
+ function generateSiteStyles(prefix) {
58
+ return `
59
+ /* ===== Site composition (renderSite) ===== */
60
+
61
+ .${prefix}-site {
62
+ display: flex;
63
+ justify-content: center;
64
+ align-items: flex-start;
65
+ }
66
+
67
+ /* A shell and a standalone screen are both top-level frames: exactly one of
68
+ them is on at a time. Screens inside a shell switch within it. */
69
+ .${prefix}-site > .${prefix}-shell,
70
+ .${prefix}-site > .${prefix}-screen {
71
+ display: none;
72
+ }
73
+
74
+ .${prefix}-site > .${prefix}-shell.${prefix}-on {
75
+ display: flex;
76
+ flex-direction: column;
77
+ }
78
+
79
+ .${prefix}-site > .${prefix}-screen.${prefix}-on {
80
+ display: block;
81
+ }
82
+
83
+ /* A site document is a running prototype, not a canvas thumbnail. The page
84
+ renderer sizes a page to its authored viewport and clips what runs past it
85
+ with an inline \`overflow: hidden\` \u2014 right for a thumbnail, where a page is a
86
+ picture, and wrong here, where it is a screen someone is using: a settings
87
+ page authored 14x taller than its viewport would keep 93% of itself
88
+ unreachable. The frame stays exactly as authored and only the overflow
89
+ becomes reachable. \`!important\` is unavoidable and confined to this rule:
90
+ the declaration being overridden is inline. */
91
+ .${prefix}-site .${prefix}-page {
92
+ overflow: auto !important;
93
+ }
94
+
95
+ /* The slot is where a layout hands its frame over to page content, so it takes
96
+ the space a page's own root would have taken. */
97
+ .${prefix}-site .${prefix}-slot {
98
+ display: flex;
99
+ flex-direction: column;
100
+ flex: 1;
101
+ min-height: 0;
102
+ }
103
+
104
+ .${prefix}-site .${prefix}-slot > .${prefix}-screen {
105
+ display: none;
106
+ }
107
+
108
+ .${prefix}-site .${prefix}-slot > .${prefix}-screen.${prefix}-on {
109
+ display: flex;
110
+ flex-direction: column;
111
+ flex: 1;
112
+ min-height: 0;
113
+ }
114
+
115
+ /* Page-root layout rules key off \`.${prefix}-page > \u2026\`. A screen composed into
116
+ a shell is one level further in, so the same rules are restated for it \u2014
117
+ otherwise a sidebar row would stop filling its frame the moment a page
118
+ started using a layout. */
119
+ .${prefix}-site .${prefix}-screen > .${prefix}-col {
120
+ flex: 1;
121
+ min-height: 0;
122
+ }
123
+
124
+ .${prefix}-site .${prefix}-screen > .${prefix}-row:has(.${prefix}-sidebar),
125
+ .${prefix}-site .${prefix}-screen > .${prefix}-row:has(.${prefix}-main),
126
+ .${prefix}-site .${prefix}-screen > .${prefix}-col > .${prefix}-row:has(.${prefix}-sidebar),
127
+ .${prefix}-site .${prefix}-screen > .${prefix}-col > .${prefix}-row:has(.${prefix}-main) {
128
+ flex: 1;
129
+ min-height: 0;
130
+ align-items: stretch;
131
+ }
132
+
133
+ /* Overlays something opens start closed; overlays nothing opens are part of
134
+ the screen as drawn and never get this class. Two class selectors so the
135
+ rule outranks \`.${prefix}-modal-backdrop\` / \`.${prefix}-drawer\` on
136
+ specificity, not only on order. */
137
+ .${prefix}-site .${prefix}-closed {
138
+ display: none;
139
+ }
140
+
141
+ /* State guards use the native hidden/disabled semantics. Component display
142
+ rules can be more specific than the browser stylesheet, so hidden is held at
143
+ the site boundary explicitly. */
144
+ .${prefix}-site [hidden] {
145
+ display: none !important;
146
+ }
147
+ `;
148
+ }
149
+
150
+ // src/renderer/site/runtime.ts
151
+ var ID_SCOPE_ATTR = "data-id-scope";
152
+ var [NAVIGATE_ATTR, OPENS_ATTR, TOGGLES_ATTR, ACTION_ATTR] = chunkZPHNXJRY_cjs.INTERACTIVE_ATTR_NAMES;
153
+ function embedJson(value) {
154
+ return JSON.stringify(value).replace(/</g, "\\u003C");
155
+ }
156
+ function siteRuntime(registry, prefix) {
157
+ return `(function () {
158
+ 'use strict';
159
+ var P = ${embedJson(prefix)};
160
+ var R = ${embedJson(registry)};
161
+ var ON = P + '-on';
162
+ var CLOSED = P + '-closed';
163
+ var NAV_ACTIVE = P + '-nav-link-active';
164
+ var site = document.querySelector('.' + P + '-site');
165
+ if (!site) return;
166
+
167
+ var screens = {};
168
+ var order = [];
169
+ var shellOf = {};
170
+ var hosts = site.querySelectorAll('[data-screen]');
171
+ for (var i = 0; i < hosts.length; i++) {
172
+ var key = hosts[i].getAttribute('data-screen');
173
+ // First-wins: two pages can share a name, and the model already decided
174
+ // which one that name resolves to. The DOM must not disagree with it.
175
+ if (!Object.prototype.hasOwnProperty.call(screens, key)) {
176
+ screens[key] = hosts[i];
177
+ order.push(key);
178
+ shellOf[key] = shellFor(hosts[i]);
179
+ }
180
+ }
181
+ var shells = site.querySelectorAll('.' + P + '-shell');
182
+ var state = {};
183
+ var initial = {};
184
+ var stateTypes = {};
185
+ for (var st = 0; st < R.states.length; st++) {
186
+ var declaration = R.states[st];
187
+ state[declaration.name] = declaration.initial;
188
+ initial[declaration.name] = declaration.initial;
189
+ stateTypes[declaration.name] = declaration.valueType;
190
+ }
191
+
192
+ function diagnostic(code, detail) {
193
+ site.setAttribute('data-wf-runtime-diagnostic', code + ':' + detail);
194
+ }
195
+
196
+ function hasState(name) {
197
+ return Object.prototype.hasOwnProperty.call(state, name);
198
+ }
199
+
200
+ function guardPasses(guard) {
201
+ return !guard || (hasState(guard.state) && state[guard.state] === guard.equals);
202
+ }
203
+
204
+ function valueMatches(name, value) {
205
+ return hasState(name) && typeof value === stateTypes[name];
206
+ }
207
+
208
+ function parseJson(value, fallback) {
209
+ if (!value) return fallback;
210
+ try {
211
+ return JSON.parse(value);
212
+ } catch (e) {
213
+ return fallback;
214
+ }
215
+ }
216
+
217
+ function handlerId(signature) {
218
+ for (var i = 0; i < R.handlers.length; i++) {
219
+ if (JSON.stringify(R.handlers[i]) === signature) return i;
220
+ }
221
+ return -1;
222
+ }
223
+
224
+ function contains(ids, id) {
225
+ for (var i = 0; i < ids.length; i++) if (ids[i] === id) return true;
226
+ return false;
227
+ }
228
+
229
+ function shellHandlersFor(key) {
230
+ var shell = shellOf[key];
231
+ if (!shell) return [];
232
+ return R.shellHandlers[shell.getAttribute('data-layout')] || [];
233
+ }
234
+
235
+ function interactionFor(key, element, signature) {
236
+ var id = handlerId(signature);
237
+ if (id < 0) return null;
238
+ var ids = isChrome(element) ? shellHandlersFor(key) : R.screenHandlers[String(key)] || [];
239
+ return contains(ids, id) ? R.handlers[id] : null;
240
+ }
241
+
242
+ function routeAllowed(key, target) {
243
+ var groups = [R.screenHandlers[String(key)] || [], shellHandlersFor(key)];
244
+ for (var i = 0; i < groups.length; i++) {
245
+ for (var j = 0; j < groups[i].length; j++) {
246
+ var handler = R.handlers[groups[i][j]];
247
+ if (!handler || !guardPasses(handler.guard)) continue;
248
+ for (var e = 0; e < handler.effects.length; e++) {
249
+ var effect = handler.effects[e];
250
+ if (effect.kind === 'navigate' && effect.target === target) return true;
251
+ }
252
+ }
253
+ }
254
+ return false;
255
+ }
256
+
257
+ /** The shell a screen is hosted in, or null when it stands alone. */
258
+ function shellFor(node) {
259
+ var el = node.parentNode;
260
+ while (el && el !== site) {
261
+ if (el.classList && el.classList.contains(P + '-shell')) return el;
262
+ el = el.parentNode;
263
+ }
264
+ return null;
265
+ }
266
+
267
+ /** True for an element that belongs to a shell's own chrome, not to a screen. */
268
+ function isChrome(el) {
269
+ return !(el.closest && el.closest('[data-screen]'));
270
+ }
271
+
272
+ /**
273
+ * The id prefix a container namespaces its contents under.
274
+ *
275
+ * Read from the document rather than rebuilt from the scheme that produced
276
+ * it: the renderer decides how scopes are spelled, and a second spelling in
277
+ * here could disagree with the first without anything noticing.
278
+ */
279
+ function scopeOf(el) {
280
+ return (el && el.getAttribute(${embedJson(ID_SCOPE_ATTR)})) || '';
281
+ }
282
+
283
+ /** Match one id exactly, whatever characters an author put in it. */
284
+ function idSelector(id) {
285
+ return '[id="' + String(id).replace(/["\\\\]/g, '\\\\$&') + '"]';
286
+ }
287
+
288
+ /** Screen key for a navigate target or a fragment, or null. */
289
+ function resolve(target) {
290
+ if (target === null || target === undefined) return null;
291
+ var name = String(target).trim();
292
+ if (name === '') return null;
293
+ if (Object.prototype.hasOwnProperty.call(R.names, name)) return String(R.names[name]);
294
+ return Object.prototype.hasOwnProperty.call(screens, name) ? name : null;
295
+ }
296
+
297
+ /**
298
+ * The overlay an intent addresses, from the point of view of one screen.
299
+ *
300
+ * An overlay id is scoped to the thing that declares it, and composition gives
301
+ * a screen two declaring contexts: the page itself, and the shell it is hosted
302
+ * in. A \`drawer\` written into a layout belongs to every screen that uses that
303
+ * layout, so the screen is searched first and its shell second \u2014 nearest
304
+ * declaration wins, and a page can shadow a shell's overlay with its own.
305
+ *
306
+ * The shell is searched for chrome only. Its hosted screens are descendants of
307
+ * it, so an unfiltered query there would let one screen's trigger reach into
308
+ * another screen that happens to reuse the id.
309
+ *
310
+ * The two searches use two different selectors, because the two contexts
311
+ * namespace their ids separately: the authored name is composed with the
312
+ * scope each container publishes. The trigger's attribute is never rewritten
313
+ * \u2014 \`opens="confirm"\` means the \`confirm\` its author could see, and which
314
+ * element that is depends on where the search is standing.
315
+ */
316
+ function overlayFor(key, id) {
317
+ if (!id) return null;
318
+
319
+ var screen = screens[key];
320
+ if (screen) {
321
+ var own = screen.querySelector(idSelector(scopeOf(screen) + id));
322
+ if (own) return own;
323
+ }
324
+
325
+ var shell = shellOf[key];
326
+ if (shell) {
327
+ var candidates = shell.querySelectorAll(idSelector(scopeOf(shell) + id));
328
+ for (var i = 0; i < candidates.length; i++) {
329
+ if (isChrome(candidates[i])) return candidates[i];
330
+ }
331
+ }
332
+ return null;
333
+ }
334
+
335
+ /** Every element that opens or toggles something, from one screen's view. */
336
+ function triggersFor(key) {
337
+ var selector = '[' + ${embedJson(OPENS_ATTR)} + '],[' + ${embedJson(TOGGLES_ATTR)} + ']';
338
+ var found = [];
339
+ var i;
340
+
341
+ var screen = screens[key];
342
+ if (screen) {
343
+ var own = screen.querySelectorAll(selector);
344
+ for (i = 0; i < own.length; i++) found.push(own[i]);
345
+ }
346
+
347
+ var shell = shellOf[key];
348
+ if (shell) {
349
+ var chrome = shell.querySelectorAll(selector);
350
+ for (i = 0; i < chrome.length; i++) {
351
+ if (isChrome(chrome[i])) found.push(chrome[i]);
352
+ }
353
+ }
354
+ return found;
355
+ }
356
+
357
+ /**
358
+ * Close every overlay something points at, from one screen's point of view.
359
+ *
360
+ * An overlay nothing points at is left visible: a wireframe that draws a
361
+ * modal in order to describe it is not waiting for a click.
362
+ */
363
+ function closeOverlays(key) {
364
+ var triggers = triggersFor(key);
365
+ for (var i = 0; i < triggers.length; i++) {
366
+ var id =
367
+ triggers[i].getAttribute(${embedJson(OPENS_ATTR)}) ||
368
+ triggers[i].getAttribute(${embedJson(TOGGLES_ATTR)});
369
+ var overlay = overlayFor(key, id);
370
+ if (overlay) overlay.classList.add(CLOSED);
371
+ }
372
+ }
373
+
374
+ function initOverlays() {
375
+ for (var i = 0; i < order.length; i++) closeOverlays(order[i]);
376
+ }
377
+
378
+ function applyOutcomes() {
379
+ var visible = site.querySelectorAll('[' + ${embedJson(chunkZPHNXJRY_cjs.VISIBLE_GUARD_ATTR)} + ']');
380
+ for (var i = 0; i < visible.length; i++) {
381
+ var visibleGuard = parseJson(visible[i].getAttribute(${embedJson(chunkZPHNXJRY_cjs.VISIBLE_GUARD_ATTR)}), null);
382
+ if (guardPasses(visibleGuard)) visible[i].removeAttribute('hidden');
383
+ else visible[i].setAttribute('hidden', 'hidden');
384
+ }
385
+
386
+ var enabled = site.querySelectorAll('[' + ${embedJson(chunkZPHNXJRY_cjs.ENABLED_GUARD_ATTR)} + ']');
387
+ for (var j = 0; j < enabled.length; j++) {
388
+ var enabledGuard = parseJson(enabled[j].getAttribute(${embedJson(chunkZPHNXJRY_cjs.ENABLED_GUARD_ATTR)}), null);
389
+ if (guardPasses(enabledGuard)) {
390
+ enabled[j].removeAttribute('disabled');
391
+ enabled[j].removeAttribute('aria-disabled');
392
+ } else {
393
+ enabled[j].setAttribute('disabled', 'disabled');
394
+ enabled[j].setAttribute('aria-disabled', 'true');
395
+ }
396
+ }
397
+ }
398
+
399
+ function applyVariantScopes() {
400
+ var screen = current === null ? null : screens[current];
401
+ var variant = screen ? screen.getAttribute('data-wf-variant') : null;
402
+ var scoped = site.querySelectorAll('[' + ${embedJson(chunkZPHNXJRY_cjs.VARIANT_SCOPE_ATTR)} + ']');
403
+ for (var i = 0; i < scoped.length; i++) {
404
+ var names = parseJson(scoped[i].getAttribute(${embedJson(chunkZPHNXJRY_cjs.VARIANT_SCOPE_ATTR)}), []);
405
+ var visible = variant !== null && names.indexOf(variant) >= 0;
406
+ if (visible) scoped[i].removeAttribute('hidden');
407
+ else scoped[i].setAttribute('hidden', 'hidden');
408
+ }
409
+ }
410
+
411
+ function applyEffects(handler) {
412
+ for (var i = 0; i < handler.effects.length; i++) {
413
+ var effect = handler.effects[i];
414
+ if (effect.kind === 'navigate') {
415
+ var route = resolve(effect.target);
416
+ if (route !== null) show(route, true);
417
+ else diagnostic('unknown-route', effect.target);
418
+ } else if (effect.kind === 'set') {
419
+ if (valueMatches(effect.state, effect.value)) state[effect.state] = effect.value;
420
+ else diagnostic('invalid-set', effect.state);
421
+ } else if (effect.kind === 'reset') {
422
+ if (hasState(effect.state)) state[effect.state] = initial[effect.state];
423
+ else diagnostic('unknown-state', effect.state);
424
+ } else if (effect.kind === 'toggle') {
425
+ if (stateTypes[effect.state] === 'boolean') state[effect.state] = !state[effect.state];
426
+ else diagnostic('invalid-toggle', effect.state);
427
+ } else if (effect.kind === 'open') {
428
+ var opened = overlayFor(current, effect.target);
429
+ if (opened) opened.classList.remove(CLOSED);
430
+ else diagnostic('unknown-overlay', effect.target);
431
+ } else if (effect.kind === 'close') {
432
+ var closed = overlayFor(current, effect.target);
433
+ if (closed) closed.classList.add(CLOSED);
434
+ else diagnostic('unknown-overlay', effect.target);
435
+ }
436
+ }
437
+ applyOutcomes();
438
+ }
439
+
440
+ var current = null;
441
+
442
+ /**
443
+ * The one place \`active\` is decided.
444
+ *
445
+ * Every shell nav item carries its own \`navigate\` target, including the item
446
+ * for the screen being shown, and the class is applied to whichever of them
447
+ * resolves to the current screen. Authoring it by hand is what produced items
448
+ * marked active while pointing somewhere else; there is nothing to author
449
+ * here, so there is nothing to get wrong.
450
+ *
451
+ * Only the shell's own chrome is derived. Links inside a screen belong to
452
+ * that screen's content, where an authored \`active\` still means what its
453
+ * author meant.
454
+ */
455
+ function markActive(key) {
456
+ for (var i = 0; i < shells.length; i++) {
457
+ var links = shells[i].querySelectorAll('[' + ${embedJson(NAVIGATE_ATTR)} + ']');
458
+ for (var j = 0; j < links.length; j++) {
459
+ if (!isChrome(links[j])) continue;
460
+ // An external target names no screen, so it can never be the current
461
+ // one. Same marker, same skip: the registry is not consulted.
462
+ if (links[j].hasAttribute(${embedJson(chunkZPHNXJRY_cjs.EXTERNAL_NAVIGATE_ATTR)})) continue;
463
+ var target = resolve(links[j].getAttribute(${embedJson(NAVIGATE_ATTR)}));
464
+ if (target === key) links[j].classList.add(NAV_ACTIVE);
465
+ else links[j].classList.remove(NAV_ACTIVE);
466
+ }
467
+ }
468
+ }
469
+
470
+ function show(key, writeFragment) {
471
+ var screen = screens[key];
472
+ if (!screen) return false;
473
+ if (key === current) return true;
474
+
475
+ for (var i = 0; i < order.length; i++) {
476
+ var k = order[i];
477
+ if (k === key) screens[k].classList.add(ON);
478
+ else screens[k].classList.remove(ON);
479
+ }
480
+ var shell = shellOf[key];
481
+ for (var s = 0; s < shells.length; s++) {
482
+ if (shells[s] === shell) shells[s].classList.add(ON);
483
+ else shells[s].classList.remove(ON);
484
+ }
485
+
486
+ // Which screen is current is *state*; \`data-screen\` is the *identity* of a
487
+ // screen host. Writing the state under the identity attribute makes the site
488
+ // root answer \`[data-screen]\` and shadow every host below it, which is
489
+ // precisely the conflation this feature exists to remove.
490
+ site.setAttribute('data-current-screen', key);
491
+ current = key;
492
+ closeOverlays(key);
493
+ markActive(key);
494
+ applyVariantScopes();
495
+ applyOutcomes();
496
+
497
+ if (writeFragment) {
498
+ var fragment = R.fragments[Number(key)] || key;
499
+ // The resulting hashchange re-enters show() with the key already current,
500
+ // which returns early \u2014 the fragment and the screen cannot fight.
501
+ if (location.hash.slice(1) !== fragment) location.hash = fragment;
502
+ }
503
+ return true;
504
+ }
505
+
506
+ function fromFragment() {
507
+ var raw = location.hash.slice(1);
508
+ if (raw === '') return null;
509
+ var decoded = raw;
510
+ try {
511
+ decoded = decodeURIComponent(raw);
512
+ } catch (e) {
513
+ decoded = raw;
514
+ }
515
+ return resolve(decoded);
516
+ }
517
+
518
+ document.addEventListener('click', function (event) {
519
+ var typed = event.target.closest ? event.target.closest('[' + ${embedJson(chunkZPHNXJRY_cjs.TYPED_INTERACTION_ATTR)} + ']') : null;
520
+ if (typed) {
521
+ var signatures = parseJson(typed.getAttribute(${embedJson(chunkZPHNXJRY_cjs.TYPED_INTERACTION_ATTR)}), []);
522
+ var matched = false;
523
+ for (var typedIndex = 0; typedIndex < signatures.length; typedIndex++) {
524
+ var normalized = interactionFor(current, typed, signatures[typedIndex]);
525
+ if (!normalized) continue;
526
+ matched = true;
527
+ if (guardPasses(normalized.guard)) applyEffects(normalized);
528
+ }
529
+ if (matched) {
530
+ event.preventDefault();
531
+ return;
532
+ }
533
+ }
534
+
535
+ var mover = event.target.closest ? event.target.closest('[' + ${embedJson(NAVIGATE_ATTR)} + ']') : null;
536
+ // The marker is a decision the renderer already made, not a hint to check.
537
+ // Reading it here \u2014 rather than re-deriving "is this a URL" from the string \u2014
538
+ // is what keeps that rule in one place; a second copy in generated JS is a
539
+ // drift surface, and the two disagreeing is how a runtime ends up hunting
540
+ // for a screen named "https://\u2026". Marked elements skip the registry
541
+ // entirely: the lookup is not attempted, not merely discarded.
542
+ if (mover && !mover.hasAttribute(${embedJson(chunkZPHNXJRY_cjs.EXTERNAL_NAVIGATE_ATTR)})) {
543
+ var navigateTarget = mover.getAttribute(${embedJson(NAVIGATE_ATTR)});
544
+ var key = routeAllowed(current, navigateTarget) ? resolve(navigateTarget) : null;
545
+ if (key !== null) {
546
+ event.preventDefault();
547
+ show(key, true);
548
+ return;
549
+ }
550
+ }
551
+
552
+ var opener = event.target.closest ? event.target.closest('[' + ${embedJson(OPENS_ATTR)} + ']') : null;
553
+ if (opener) {
554
+ var opened = overlayFor(current, opener.getAttribute(${embedJson(OPENS_ATTR)}));
555
+ if (opened) {
556
+ event.preventDefault();
557
+ opened.classList.remove(CLOSED);
558
+ return;
559
+ }
560
+ }
561
+
562
+ var toggler = event.target.closest ? event.target.closest('[' + ${embedJson(TOGGLES_ATTR)} + ']') : null;
563
+ if (toggler) {
564
+ var toggled = overlayFor(current, toggler.getAttribute(${embedJson(TOGGLES_ATTR)}));
565
+ if (toggled) {
566
+ event.preventDefault();
567
+ toggled.classList.toggle(CLOSED);
568
+ return;
569
+ }
570
+ }
571
+
572
+ var actor = event.target.closest ? event.target.closest('[' + ${embedJson(ACTION_ATTR)} + ']') : null;
573
+ if (actor) {
574
+ // Only the two structural actions are the runtime's business. Every other
575
+ // value is an opaque handler id the wireframe never promised to run.
576
+ var action = (actor.getAttribute(${embedJson(ACTION_ATTR)}) || '').trim();
577
+ if (action === 'close' || action === 'back') {
578
+ event.preventDefault();
579
+ closeOverlays(current);
580
+ return;
581
+ }
582
+ if (action !== '') diagnostic('unknown-action', action);
583
+ }
584
+
585
+ // Clicking a modal's own backdrop dismisses it, the way a real one does.
586
+ var backdrop = event.target;
587
+ if (backdrop && backdrop.classList && backdrop.classList.contains(P + '-modal-backdrop')) {
588
+ backdrop.classList.add(CLOSED);
589
+ }
590
+
591
+ // Every branch above cancels the default only when it RESOLVES an intent,
592
+ // which is right for them \u2014 an unresolved intent must not silently look
593
+ // handled. But that leaves the anchors the renderer marked as having no
594
+ // destination at all, and a wireframe is mostly those: nav labels, tabs,
595
+ // breadcrumbs, placeholder links. Their default action is a navigation, and
596
+ // in the \`srcdoc\` frame every consumer mounts this output in, the inert
597
+ // \`href\` resolves against the EMBEDDER's URL \u2014 so the click walks the frame
598
+ // out of the wireframe and loads the host app inside itself, refetching its
599
+ // assets. Measured on a 20-screen demo: 44 such anchors, frame URL
600
+ // \`about:srcdoc\` -> \`<host page>#\`.
601
+ //
602
+ // The test is the renderer's own statement (\`INERT_HREF\`), read back, not a
603
+ // guess about what the string means: an authored \`href\`, and a URL-shaped
604
+ // \`navigate\` moved into one, are real destinations and are left alone. An
605
+ // authored fragment link is left alone too \u2014 the hashchange handler below is
606
+ // how that is supposed to work.
607
+ var link = event.target.closest ? event.target.closest('a[href]') : null;
608
+ if (link && link.getAttribute('href') === ${embedJson(chunkZPHNXJRY_cjs.INERT_HREF)}) event.preventDefault();
609
+ });
610
+
611
+ document.addEventListener('keydown', function (event) {
612
+ if (event.key === 'Escape' && current !== null) closeOverlays(current);
613
+ });
614
+
615
+ window.addEventListener('hashchange', function () {
616
+ var key = fromFragment();
617
+ if (key !== null) show(key, false);
618
+ });
619
+
620
+ initOverlays();
621
+ var start = fromFragment();
622
+ if (start === null) start = String(R.entry);
623
+ if (!show(start, false)) show(String(R.entry), false);
624
+ })();`;
625
+ }
626
+
627
+ // src/renderer/site/index.ts
628
+ var DEFAULT_PREFIX = "wf";
629
+ var screenScope = (index) => `s${index}-`;
630
+ var shellScope = (index) => `l${index}-`;
631
+ function escapeAttr(value) {
632
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
633
+ }
634
+ function escapeText(value) {
635
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
636
+ }
637
+ function attrs(pairs) {
638
+ return pairs.filter((pair) => pair[1] !== void 0).map(([name, value]) => ` ${name}="${escapeAttr(value)}"`).join("");
639
+ }
640
+ function renderHostedScreen(screen, shell, make, prefix) {
641
+ const { width, height } = chunkZPHNXJRY_cjs.resolvePageDimensions(screen.page);
642
+ const conflict = width !== shell.width || height !== shell.height ? `${width}x${height}` : void 0;
643
+ const scope = screenScope(screen.index);
644
+ const marks = attrs([
645
+ ["data-screen", String(screen.index)],
646
+ ["data-screen-name", screen.name],
647
+ ["data-wf-variant", screen.variant],
648
+ [ID_SCOPE_ATTR, scope],
649
+ ["data-wf-viewport-conflict", conflict]
650
+ ]);
651
+ const content = make(scope).renderFragment(screen.page.children);
652
+ return `<div class="${prefix}-screen"${marks}>
653
+ ${content}
654
+ </div>`;
655
+ }
656
+ function renderStandaloneScreen(screen, make, prefix) {
657
+ var _a, _b;
658
+ const scope = screenScope(screen.index);
659
+ const marks = attrs([
660
+ ["data-screen", String(screen.index)],
661
+ ["data-screen-name", screen.name],
662
+ ["data-wf-variant", screen.variant],
663
+ [ID_SCOPE_ATTR, scope],
664
+ ["data-wf-uses-unresolved", (_a = screen.miss) == null ? void 0 : _a.uses],
665
+ ["data-wf-uses-reason", (_b = screen.miss) == null ? void 0 : _b.reason]
666
+ ]);
667
+ const page = make(scope).render({ type: "Document", children: [screen.page] }).html;
668
+ return `<div class="${prefix}-screen"${marks}>
669
+ ${page}
670
+ </div>`;
671
+ }
672
+ function renderShell(shell, index, make, prefix) {
673
+ const hosted = shell.screens.map((screen) => renderHostedScreen(screen, shell, make, prefix)).join("\n");
674
+ const scope = shellScope(index);
675
+ const style = `position: relative; width: ${shell.width}px; height: ${shell.height}px; overflow: hidden`;
676
+ const marks = attrs([
677
+ ["data-layout", shell.name],
678
+ [ID_SCOPE_ATTR, scope],
679
+ ["data-viewport-width", String(shell.width)],
680
+ ["data-viewport-height", String(shell.height)]
681
+ ]);
682
+ const body = make(scope).renderFragment(shell.layout.children, hosted);
683
+ return `<div class="${prefix}-page ${prefix}-shell" style="${style}"${marks}>
684
+ ${body}
685
+ </div>`;
686
+ }
687
+ function resolveEntry(model, options) {
688
+ var _a;
689
+ const fallback = Math.max(model.entry, 0);
690
+ const requested = (_a = options.entry) == null ? void 0 : _a.trim();
691
+ if (requested === void 0 || requested.length === 0) return { index: fallback };
692
+ const index = model.names.get(requested);
693
+ if (index === void 0) return { index: fallback, unresolved: requested };
694
+ return { index };
695
+ }
696
+ function resolveTitle(model, options, entry) {
697
+ var _a, _b;
698
+ if (options.title !== void 0) return options.title;
699
+ const page = (_a = model.screens[entry]) == null ? void 0 : _a.page;
700
+ const title = (_b = page == null ? void 0 : page.title) == null ? void 0 : _b.trim();
701
+ return title !== void 0 && title.length > 0 ? title : "Wireframe";
702
+ }
703
+ function compactRuntimeInteractions(model, interactions) {
704
+ var _a;
705
+ const handlers = [];
706
+ const handlerIds = /* @__PURE__ */ new Map();
707
+ const screenHandlers = {};
708
+ const shellHandlers = {};
709
+ const intern = (signature, handler) => {
710
+ const existing = handlerIds.get(signature);
711
+ if (existing !== void 0) return existing;
712
+ const id = handlers.length;
713
+ handlerIds.set(signature, id);
714
+ handlers.push(handler);
715
+ return id;
716
+ };
717
+ const add = (owner, key, id) => {
718
+ var _a2;
719
+ const ids = (_a2 = owner[key]) != null ? _a2 : owner[key] = [];
720
+ if (!ids.includes(id)) ids.push(id);
721
+ };
722
+ for (const interaction of interactions) {
723
+ const id = intern(interaction.signature, interaction.handler);
724
+ if (interaction.source === "screen") {
725
+ add(screenHandlers, String(interaction.screenIndex), id);
726
+ continue;
727
+ }
728
+ const shell = (_a = model.screens[interaction.screenIndex]) == null ? void 0 : _a.shell;
729
+ if (shell !== void 0) add(shellHandlers, shell, id);
730
+ }
731
+ return { handlers, screenHandlers, shellHandlers };
732
+ }
733
+ function renderSite(document, options = {}) {
734
+ var _a;
735
+ const prefix = (_a = options.classPrefix) != null ? _a : DEFAULT_PREFIX;
736
+ document = chunkZPHNXJRY_cjs.expandRepeats(expandVariants(document));
737
+ const model = chunkZPHNXJRY_cjs.buildSiteModel(document);
738
+ const interactionModel = chunkZPHNXJRY_cjs.collectInteractions(document);
739
+ const make = (idScope) => new chunkZPHNXJRY_cjs.HtmlRenderer({
740
+ theme: options.theme,
741
+ classPrefix: prefix,
742
+ background: options.background,
743
+ annotationStyle: options.annotationStyle,
744
+ includeStyles: false,
745
+ idScope
746
+ });
747
+ const shells = model.shells.map((shell, index) => renderShell(shell, index, make, prefix)).join("\n");
748
+ const standalone = model.screens.filter((screen) => screen.shell === void 0).map((screen) => renderStandaloneScreen(screen, make, prefix)).join("\n");
749
+ const theme = options.theme === "dark" ? chunkZPHNXJRY_cjs.darkTheme : chunkZPHNXJRY_cjs.defaultTheme;
750
+ const css = chunkZPHNXJRY_cjs.generateStyles(theme, prefix, options.annotationStyle) + generateSiteStyles(prefix);
751
+ const entry = resolveEntry(model, options);
752
+ const fragments = model.screens.map((screen) => {
753
+ var _a2;
754
+ return (_a2 = screen.name) != null ? _a2 : String(screen.index);
755
+ });
756
+ const runtimeInteractions = compactRuntimeInteractions(model, interactionModel.interactions);
757
+ const runtime = siteRuntime(
758
+ {
759
+ names: Object.fromEntries(model.names),
760
+ fragments,
761
+ entry: entry.index,
762
+ states: interactionModel.states,
763
+ ...runtimeInteractions,
764
+ diagnostics: interactionModel.diagnostics
765
+ },
766
+ prefix
767
+ );
768
+ const body = [shells, standalone].filter((part) => part.length > 0).join("\n");
769
+ const siteAttrs = attrs([
770
+ ["data-screen-count", String(model.screens.length)],
771
+ ["data-shell-count", String(model.shells.length)],
772
+ ["data-wf-entry-unresolved", entry.unresolved],
773
+ ["data-wf-diagnostic-count", String(interactionModel.diagnostics.length)]
774
+ ]);
775
+ return `<!DOCTYPE html>
776
+ <html lang="en">
777
+ <head>
778
+ <meta charset="UTF-8">
779
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
780
+ <title>${escapeText(resolveTitle(model, options, entry.index))}</title>
781
+ <style>
782
+ html, body {
783
+ margin: 0;
784
+ padding: 0;
785
+ min-height: 100vh;
786
+ background: #f4f4f5;
787
+ }
788
+ /* The gutter is breathing room *around* a board, so it may never come out of
789
+ the width the board is laid out in.
790
+
791
+ \`body\` is a block box: its \`width: auto\` resolves to the space available in
792
+ the viewport minus its own horizontal padding, so \`padding: 24px\` made the
793
+ containing block 1440 - 24*2 = 1392px. \`box-sizing\` does not undo that \u2014
794
+ it only reinterprets an *explicit* width, and there is none here. A board
795
+ authored at the 1440px desktop viewport is 1440px of \`.wf-page\` that must
796
+ not shrink (\`flex-shrink: 0\`, the fixed-layout invariant), so it overhung
797
+ its 1392px parent by 24px on each side and the document scrolled sideways.
798
+
799
+ The gutter therefore moves off the horizontal axis, where it competes with
800
+ the board for the viewport, and stays only on the vertical one, where it
801
+ costs nothing: a document scrolls down by nature, so leading above and
802
+ below a board is free, while every horizontal pixel it takes is a pixel the
803
+ board must give back. A board authored at exactly the viewport width now
804
+ fills it edge to edge, as authored, and anything wider scrolls by its own
805
+ overflow rather than by the gutter's. */
806
+ body {
807
+ padding: 24px 0;
808
+ }
809
+ ${css}
810
+ </style>
811
+ </head>
812
+ <body>
813
+ <div class="${prefix}-site"${siteAttrs}>
814
+ ${body}
815
+ </div>
816
+ <script>
817
+ ${runtime}
818
+ </script>
819
+ </body>
820
+ </html>`;
821
+ }
822
+
823
+ exports.expandVariants = expandVariants;
824
+ exports.renderSite = renderSite;