@wireweave/core 3.1.0-beta.9 → 4.0.0-beta.12

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