@wireweave/core 3.1.0-beta.7 → 3.1.0-beta.9

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/dist/index.cjs CHANGED
@@ -75,6 +75,7 @@ __export(src_exports, {
75
75
  documentDefinitions: () => documentDefinitions,
76
76
  documentPages: () => documentPages,
77
77
  expandRepeats: () => expandRepeats,
78
+ expandVariants: () => expandVariants,
78
79
  exportToFigma: () => exportToFigma,
79
80
  exportToFigmaString: () => exportToFigmaString,
80
81
  exportToJson: () => exportToJson,
@@ -82,6 +83,8 @@ __export(src_exports, {
82
83
  extractAllScreenFields: () => extractAllScreenFields,
83
84
  extractScreenFields: () => extractScreenFields,
84
85
  extractScreenTransitions: () => extractScreenTransitions,
86
+ filterUnscopedPages: () => filterUnscopedPages,
87
+ filterVariantScope: () => filterVariantScope,
85
88
  find: () => find,
86
89
  findAll: () => findAll,
87
90
  findByType: () => findByType,
@@ -194,6 +197,7 @@ __export(src_exports, {
194
197
  resolveViewport: () => resolveViewport,
195
198
  tryParse: () => tryParse,
196
199
  validate: () => validate,
200
+ variantScope: () => variantScope,
197
201
  walk: () => walk,
198
202
  walkDocument: () => walkDocument,
199
203
  wrapInPreviewContainer: () => wrapInPreviewContainer
@@ -634,6 +638,153 @@ function expandRepeats(document) {
634
638
  };
635
639
  }
636
640
 
641
+ // src/ast/filter-variant-scope.ts
642
+ function variantScope(node) {
643
+ const declared = node.when;
644
+ if (declared === void 0) return void 0;
645
+ const raw = Array.isArray(declared) ? declared : [declared];
646
+ const seen = /* @__PURE__ */ new Set();
647
+ const names = [];
648
+ for (const item of raw) {
649
+ if (typeof item !== "string") continue;
650
+ const name = item.trim();
651
+ if (name.length === 0 || seen.has(name)) continue;
652
+ seen.add(name);
653
+ names.push(name);
654
+ }
655
+ return names;
656
+ }
657
+ function childList(value) {
658
+ const children = value?.children;
659
+ return Array.isArray(children) ? children : void 0;
660
+ }
661
+ function asNode(value) {
662
+ return value !== null && typeof value === "object" && "type" in value ? value : void 0;
663
+ }
664
+ function filterChildList(children, variant) {
665
+ return children.flatMap((child) => {
666
+ const node = asNode(child);
667
+ if (node === void 0) return [child];
668
+ const kept = filterNode(node, variant);
669
+ return kept === void 0 ? [] : [kept];
670
+ });
671
+ }
672
+ function containsScope(node) {
673
+ if (node.when !== void 0) return true;
674
+ for (const child of childList(node) ?? []) {
675
+ const nested = asNode(child);
676
+ if (nested !== void 0 && containsScope(nested)) return true;
677
+ }
678
+ const fills = node.fills;
679
+ if (Array.isArray(fills)) {
680
+ for (const fill of fills) {
681
+ for (const child of childList(fill) ?? []) {
682
+ const nested = asNode(child);
683
+ if (nested !== void 0 && containsScope(nested)) return true;
684
+ }
685
+ }
686
+ }
687
+ return false;
688
+ }
689
+ function filterNode(node, variant) {
690
+ const scope = variantScope(node);
691
+ if (scope !== void 0) {
692
+ if (variant === void 0 || !scope.includes(variant)) return void 0;
693
+ }
694
+ const nested = containsScope(node);
695
+ if (scope === void 0 && !nested) return node;
696
+ const result = {};
697
+ for (const [key, value] of Object.entries(node)) {
698
+ if (key === "when") continue;
699
+ result[key] = value;
700
+ }
701
+ const children = childList(node);
702
+ if (children !== void 0) {
703
+ result.children = filterChildList(children, variant);
704
+ }
705
+ const fills = node.fills;
706
+ if (Array.isArray(fills)) {
707
+ result.fills = fills.map((fill) => {
708
+ const fillChildren = childList(fill);
709
+ if (fillChildren === void 0) return fill;
710
+ return {
711
+ ...fill,
712
+ children: filterChildList(fillChildren, variant)
713
+ };
714
+ });
715
+ }
716
+ return result;
717
+ }
718
+ function filterVariantScope(children, variant) {
719
+ if (!children.some((child) => containsScope(child))) return children;
720
+ return children.flatMap((child) => {
721
+ const kept = filterNode(child, variant);
722
+ return kept === void 0 ? [] : [kept];
723
+ });
724
+ }
725
+ function filterUnscopedPages(document) {
726
+ let changed = false;
727
+ const children = document.children.map((child) => {
728
+ if (child.type !== "Page" || child.variant !== void 0) return child;
729
+ const filtered = filterVariantScope(child.children, void 0);
730
+ if (filtered === child.children) return child;
731
+ changed = true;
732
+ return { ...child, children: filtered };
733
+ });
734
+ return changed ? { ...document, children } : document;
735
+ }
736
+
737
+ // src/ast/expand-variants.ts
738
+ function cloneNode3(value) {
739
+ if (Array.isArray(value)) return value.map(cloneNode3);
740
+ if (value === null || typeof value !== "object") return value;
741
+ const source = value;
742
+ const result = {};
743
+ for (const [key, item] of Object.entries(source)) {
744
+ result[key] = key === "loc" ? item : cloneNode3(item);
745
+ }
746
+ return result;
747
+ }
748
+ function variantNames(page) {
749
+ const declared = page.variants;
750
+ if (!Array.isArray(declared)) return [];
751
+ const seen = /* @__PURE__ */ new Set();
752
+ const names = [];
753
+ for (const raw of declared) {
754
+ if (typeof raw !== "string") continue;
755
+ const name = raw.trim();
756
+ if (name.length === 0 || seen.has(name)) continue;
757
+ seen.add(name);
758
+ names.push(name);
759
+ }
760
+ return names;
761
+ }
762
+ function hasVariants(document) {
763
+ return document.children.some((child) => child.type === "Page" && variantNames(child).length > 0);
764
+ }
765
+ function expandVariants(document) {
766
+ if (!hasVariants(document)) return filterUnscopedPages(document);
767
+ return {
768
+ ...document,
769
+ children: document.children.flatMap((child) => {
770
+ if (child.type !== "Page") return [child];
771
+ const names = variantNames(child);
772
+ if (names.length === 0) {
773
+ const filtered = filterVariantScope(child.children, void 0);
774
+ return [filtered === child.children ? child : { ...child, children: filtered }];
775
+ }
776
+ return names.map((variant, position) => {
777
+ const clone = cloneNode3(child);
778
+ delete clone.variants;
779
+ clone.variant = variant;
780
+ if (position > 0) delete clone.states;
781
+ clone.children = filterVariantScope(clone.children, variant);
782
+ return clone;
783
+ });
784
+ })
785
+ };
786
+ }
787
+
637
788
  // src/parser/generated-parser.js
638
789
  var peg$SyntaxError = class extends SyntaxError {
639
790
  constructor(message, expected, found, location) {
@@ -13320,6 +13471,16 @@ var ATTRIBUTE_SPECS = [
13320
13471
  type: "object[]",
13321
13472
  description: "Typed application state declarations owned by a page or shared layout"
13322
13473
  },
13474
+ {
13475
+ name: "variants",
13476
+ type: "string[]",
13477
+ description: "Named state variants of this page \u2014 each one renders the page again as a screen of its own"
13478
+ },
13479
+ {
13480
+ name: "when",
13481
+ type: "string[]",
13482
+ description: "Variant boards this element is drawn on \u2014 when=loading, or when=[loading, empty] for both"
13483
+ },
13323
13484
  {
13324
13485
  name: "id",
13325
13486
  type: "string",
@@ -13365,6 +13526,13 @@ var BOX_ATTRIBUTES = [
13365
13526
  // Guarded runtime outcomes
13366
13527
  "visibleWhen",
13367
13528
  "enabledWhen",
13529
+ // Build-time variant scope. Listed beside the guards because it reads like
13530
+ // them and is deliberately not one of them: a guard leaves the element in the
13531
+ // markup for the runtime to toggle, `when` decides whether the element is in
13532
+ // that board's markup at all. Every element takes it for the same reason
13533
+ // every element takes a guard — which boards a piece of a screen belongs to
13534
+ // is a property of the piece, not of what kind of piece it is.
13535
+ "when",
13368
13536
  // Spacing
13369
13537
  "p",
13370
13538
  "px",
@@ -13427,7 +13595,15 @@ var COMPONENT_METADATA = {
13427
13595
  // board that path renders *into* — nothing emits the attribute for it and
13428
13596
  // nothing would toggle it, so declaring it would let an author write a
13429
13597
  // guard on a page, pass `validate()`, and have the value silently dropped.
13430
- ...BOX_ATTRIBUTES.filter((name) => name !== "visibleWhen" && name !== "enabledWhen"),
13598
+ // `when` is filtered out alongside the guards, for a reason of its own: a
13599
+ // page *is* a board, so scoping one to a variant would be a board saying
13600
+ // which board it is drawn on. The axis a page declares is `variants`, and
13601
+ // `when` names positions along it — the two sit at different levels and a
13602
+ // page carrying both would be asking `expandVariants` to filter a page
13603
+ // against a name it is itself the source of.
13604
+ ...BOX_ATTRIBUTES.filter(
13605
+ (name) => name !== "visibleWhen" && name !== "enabledWhen" && name !== "when"
13606
+ ),
13431
13607
  ...CONTAINER_ATTRIBUTES,
13432
13608
  "id",
13433
13609
  "title",
@@ -13437,7 +13613,8 @@ var COMPONENT_METADATA = {
13437
13613
  "device",
13438
13614
  "centered",
13439
13615
  "uses",
13440
- "states"
13616
+ "states",
13617
+ "variants"
13441
13618
  ],
13442
13619
  hasChildren: true,
13443
13620
  description: "Root container for a wireframe page. Multiple pages in one .wf file lay out side-by-side on a canvas; use at(x, y) for explicit placement, or omit for auto-flow. Give it uses=<layout> to draw it inside a shared layout instead of restating the shell."
@@ -14112,6 +14289,8 @@ function pageTitle(page) {
14112
14289
  const title = page.title?.trim();
14113
14290
  return title !== void 0 && title.length > 0 ? title : void 0;
14114
14291
  }
14292
+ var VARIANT_SEPARATOR = "#";
14293
+ var variantName = (name, variant) => `${name}${VARIANT_SEPARATOR}${variant}`;
14115
14294
  function hasSlot(layout) {
14116
14295
  let found = false;
14117
14296
  for (const child of layout.children) {
@@ -14143,7 +14322,10 @@ function resolveShell(page, layouts) {
14143
14322
  function buildSiteModel(doc) {
14144
14323
  const pages = documentPages(doc);
14145
14324
  const layouts = layoutsByName(doc);
14146
- const screens = pages.map((page, index) => ({ index, page }));
14325
+ const screens = pages.map((page, index) => {
14326
+ const variant = page.variant?.trim();
14327
+ return variant !== void 0 && variant.length > 0 ? { index, page, variant } : { index, page };
14328
+ });
14147
14329
  const shells = [];
14148
14330
  const shellByName = /* @__PURE__ */ new Map();
14149
14331
  screens.forEach((screen) => {
@@ -14177,7 +14359,26 @@ function buildSiteModel(doc) {
14177
14359
  }
14178
14360
  }
14179
14361
  for (const screen of screens) {
14180
- const declared = [pageId(screen.page), pageTitle(screen.page)];
14362
+ if (screen.variant === void 0) continue;
14363
+ for (const declared of [pageId(screen.page), pageTitle(screen.page)]) {
14364
+ if (declared === void 0) continue;
14365
+ const owner = names.get(declared);
14366
+ if (owner === void 0) continue;
14367
+ const winner = screens[owner].page;
14368
+ if (pageId(winner) !== pageId(screen.page) || pageTitle(winner) !== pageTitle(screen.page)) {
14369
+ continue;
14370
+ }
14371
+ const qualified = variantName(declared, screen.variant);
14372
+ if (!names.has(qualified)) names.set(qualified, screen.index);
14373
+ }
14374
+ }
14375
+ for (const screen of screens) {
14376
+ const bare = [pageId(screen.page), pageTitle(screen.page)];
14377
+ const variant = screen.variant;
14378
+ const declared = variant === void 0 ? bare : [
14379
+ ...bare.map((name) => name === void 0 ? void 0 : variantName(name, variant)),
14380
+ ...bare
14381
+ ];
14181
14382
  screen.name = declared.find(
14182
14383
  (name) => name !== void 0 && names.get(name) === screen.index
14183
14384
  );
@@ -62729,7 +62930,8 @@ function wrapBoard(pageHtml, placed, prefix) {
62729
62930
  const { x, y, w, h, page } = placed;
62730
62931
  const positionStyle = `position: absolute; left: ${x}px; top: ${y}px; width: ${w}px; height: ${h}px;`;
62731
62932
  const titleAttr = page.title ? ` data-page-title="${escapeAttr(page.title)}"` : "";
62732
- const dataAttrs = ` data-page-x="${x}" data-page-y="${y}" data-page-w="${w}" data-page-h="${h}"${titleAttr}`;
62933
+ const variantAttr = page.variant ? ` data-wf-variant="${escapeAttr(page.variant)}"` : "";
62934
+ const dataAttrs = ` data-page-x="${x}" data-page-y="${y}" data-page-w="${w}" data-page-h="${h}"${titleAttr}${variantAttr}`;
62733
62935
  return `<div class="${prefix}-canvas-board" style="${positionStyle}"${dataAttrs}>
62734
62936
  ${pageHtml}
62735
62937
  </div>`;
@@ -63316,6 +63518,7 @@ function renderHostedScreen(screen, shell, make, prefix) {
63316
63518
  const marks = attrs([
63317
63519
  ["data-screen", String(screen.index)],
63318
63520
  ["data-screen-name", screen.name],
63521
+ ["data-wf-variant", screen.variant],
63319
63522
  [ID_SCOPE_ATTR, scope],
63320
63523
  ["data-wf-viewport-conflict", conflict]
63321
63524
  ]);
@@ -63329,6 +63532,7 @@ function renderStandaloneScreen(screen, make, prefix) {
63329
63532
  const marks = attrs([
63330
63533
  ["data-screen", String(screen.index)],
63331
63534
  ["data-screen-name", screen.name],
63535
+ ["data-wf-variant", screen.variant],
63332
63536
  [ID_SCOPE_ATTR, scope],
63333
63537
  ["data-wf-uses-unresolved", screen.miss?.uses],
63334
63538
  ["data-wf-uses-reason", screen.miss?.reason]
@@ -63397,7 +63601,7 @@ function compactRuntimeInteractions(model, interactions) {
63397
63601
  }
63398
63602
  function renderSite(document, options = {}) {
63399
63603
  const prefix = options.classPrefix ?? DEFAULT_PREFIX2;
63400
- document = expandRepeats(document);
63604
+ document = expandRepeats(expandVariants(document));
63401
63605
  const model = buildSiteModel(document);
63402
63606
  const interactionModel = collectInteractions(document);
63403
63607
  const make = (idScope) => new HtmlRenderer({
@@ -63466,6 +63670,7 @@ ${runtime}
63466
63670
 
63467
63671
  // src/renderer/index.ts
63468
63672
  function render(document, options = {}) {
63673
+ document = expandVariants(document);
63469
63674
  const isMultiPage = documentPages(document).length > 1;
63470
63675
  if (isMultiPage) {
63471
63676
  const result = renderCanvas(document, options);
@@ -63475,6 +63680,7 @@ function render(document, options = {}) {
63475
63680
  return renderer.render(document);
63476
63681
  }
63477
63682
  function renderToHtml(document, options = {}) {
63683
+ document = expandVariants(document);
63478
63684
  const { html, css } = render(document, options);
63479
63685
  const prefix = options.classPrefix ?? "wf";
63480
63686
  const isMultiPage = documentPages(document).length > 1;
@@ -63516,6 +63722,7 @@ ${html}
63516
63722
  </html>`;
63517
63723
  }
63518
63724
  function renderToSvg(document, options = {}) {
63725
+ document = expandVariants(document);
63519
63726
  const isMultiPage = documentPages(document).length > 1;
63520
63727
  let width = options.width ?? 800;
63521
63728
  let height = options.height ?? 600;
@@ -63628,6 +63835,63 @@ function checkDuplicateDeclarations(ast, addError) {
63628
63835
  }
63629
63836
  return true;
63630
63837
  }
63838
+ function checkVariantScopes(ast, addError) {
63839
+ const children = ast.children ?? [];
63840
+ for (let index = 0; index < children.length; index++) {
63841
+ const page = children[index];
63842
+ if (page?.type !== "Page") continue;
63843
+ const declared = new Set(
63844
+ (Array.isArray(page.variants) ? page.variants : []).filter((name) => typeof name === "string").map((name) => name.trim()).filter((name) => name.length > 0)
63845
+ );
63846
+ const visit = (node, path, inherited) => {
63847
+ const scope = variantScope(node);
63848
+ let reachable = inherited;
63849
+ if (scope !== void 0) {
63850
+ const unknown = scope.filter((name) => !declared.has(name));
63851
+ if (unknown.length > 0) {
63852
+ const message = declared.size === 0 ? `Unknown variant ${unknown.map((n) => `"${n}"`).join(", ")} in when= \u2014 this page declares no variants=, so the element is drawn on no board` : `Unknown variant ${unknown.map((n) => `"${n}"`).join(", ")} in when= \u2014 this page declares [${[...declared].join(", ")}]`;
63853
+ if (!addError({
63854
+ message,
63855
+ path,
63856
+ nodeType: node.type,
63857
+ attribute: "when",
63858
+ location: node.loc ? { line: node.loc.start.line, column: node.loc.start.column } : void 0
63859
+ })) {
63860
+ return false;
63861
+ }
63862
+ }
63863
+ const named = new Set(scope.filter((name) => declared.has(name)));
63864
+ reachable = inherited === void 0 ? named : new Set([...named].filter((n) => inherited.has(n)));
63865
+ if (unknown.length === 0 && inherited !== void 0 && reachable.size === 0) {
63866
+ if (!addError({
63867
+ message: `Contradictory when= [${scope.join(", ")}] \u2014 an enclosing element is scoped to [${[...inherited].join(", ")}], so no board draws both and this element is never rendered`,
63868
+ path,
63869
+ nodeType: node.type,
63870
+ attribute: "when",
63871
+ location: node.loc ? { line: node.loc.start.line, column: node.loc.start.column } : void 0
63872
+ })) {
63873
+ return false;
63874
+ }
63875
+ }
63876
+ }
63877
+ const kids = "children" in node && Array.isArray(node.children) ? node.children : [];
63878
+ for (let i = 0; i < kids.length; i++) {
63879
+ const child = kids[i];
63880
+ if (child && typeof child === "object" && "type" in child) {
63881
+ if (!visit(child, `${path}.children[${i}]`, reachable)) return false;
63882
+ }
63883
+ }
63884
+ return true;
63885
+ };
63886
+ for (let i = 0; i < page.children.length; i++) {
63887
+ const child = page.children[i];
63888
+ if (child && typeof child === "object" && "type" in child) {
63889
+ if (!visit(child, `pages[${index}].children[${i}]`, void 0)) return false;
63890
+ }
63891
+ }
63892
+ }
63893
+ return true;
63894
+ }
63631
63895
  function checkDuplicateElementIds(ast, addError) {
63632
63896
  const CONTEXT_OF = {
63633
63897
  Page: "page",
@@ -63908,6 +64172,7 @@ function validate(ast, options = {}) {
63908
64172
  }
63909
64173
  if (shouldContinue) shouldContinue = checkComponentContracts(ast, addError);
63910
64174
  if (shouldContinue) shouldContinue = checkDuplicateDeclarations(ast, addError);
64175
+ if (shouldContinue) shouldContinue = checkVariantScopes(ast, addError);
63911
64176
  if (shouldContinue) checkDuplicateElementIds(ast, addError);
63912
64177
  const valid = errors.length === 0;
63913
64178
  return {
@@ -65930,6 +66195,7 @@ function linkAndCompileApp(manifest, modules, options = {}) {
65930
66195
  documentDefinitions,
65931
66196
  documentPages,
65932
66197
  expandRepeats,
66198
+ expandVariants,
65933
66199
  exportToFigma,
65934
66200
  exportToFigmaString,
65935
66201
  exportToJson,
@@ -65937,6 +66203,8 @@ function linkAndCompileApp(manifest, modules, options = {}) {
65937
66203
  extractAllScreenFields,
65938
66204
  extractScreenFields,
65939
66205
  extractScreenTransitions,
66206
+ filterUnscopedPages,
66207
+ filterVariantScope,
65940
66208
  find,
65941
66209
  findAll,
65942
66210
  findByType,
@@ -66049,6 +66317,7 @@ function linkAndCompileApp(manifest, modules, options = {}) {
66049
66317
  resolveViewport,
66050
66318
  tryParse,
66051
66319
  validate,
66320
+ variantScope,
66052
66321
  walk,
66053
66322
  walkDocument,
66054
66323
  wrapInPreviewContainer
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { h as AnyNode, A as AccordionNode, a as AlertNode, j as AvatarNode, B as BadgeNode, r as BreadcrumbNode, s as ButtonNode, C as CardNode, w as CheckboxNode, x as ColNode, z as ComponentDefinitionNode, H as ComponentUseNode, I as ContainerComponentNode, J as ContainerNode, K as DataNode, L as DefinitionNode, N as DisplayNode, O as DividerComponentNode, P as DrawerNode, S as DropdownNode, T as FeedbackNode, V as FooterNode, W as GridNode, Z as HeaderNode, $ as IconNode, a2 as ImageNode, a3 as InputComponentNode, a4 as InputNode, aa as LayoutDefinitionNode, ab as LayoutNode, ac as LeafNode, ad as LinkNode, af as ListNode, ag as MainNode, aj as ModalNode, ao as NavNode, ap as NavigationNode, aq as NodeType, ar as OverlayNode, as as PageNode, at as PlaceholderNode, au as PopoverNode, ax as ProgressNode, ay as RadioNode, aB as RowNode, aC as SectionNode, aD as SelectNode, aG as SidebarNode, aI as SliderNode, aJ as SlotNode, aN as SpinnerNode, aV as SwitchNode, aX as TableNode, aY as TabsNode, a_ as TextContentNode, a$ as TextNode, b3 as TextareaNode, b5 as TitleNode, b6 as ToastNode, b8 as TooltipNode, bd as WireframeDocument, aK as SourceLocation, aR as StateDeclaration, aS as StateGuard, a6 as InteractionEffect, a5 as InputType } from './types-BphXi5Tn.cjs';
2
- export { b as AlertVariant, c as AlignValue, d as AnchorPosition, e as AnnotationItemNode, f as AnnotationNode, g as AnnotationsNode, i as AppearanceProps, k as AvatarSize, l as AvatarSizeToken, m as BadgeSize, n as BadgeSizeToken, o as BadgeVariant, p as BaseNode, q as BreadcrumbItem, t as ButtonSize, u as ButtonSizeToken, v as ButtonVariant, y as CommonProps, D as ComponentInputValue, E as ComponentParameter, F as ComponentParameterType, G as ComponentSlotFill, M as DirectionValue, Q as DrawerPosition, R as DropdownItemNode, U as FlexProps, X as GridProps, Y as GuardedOutcomeProps, _ as HeightValue, a0 as IconSize, a1 as IconSizeToken, a7 as InteractionHandler, a8 as InteractiveProps, a9 as JustifyValue, ae as ListItemNode, ah as MarkerColor, ai as MarkerNode, ak as NavBlockItem, al as NavChild, am as NavGroupNode, an as NavItem, av as Position, aw as PositionProps, az as RelativeNode, aA as RepeatNode, aE as SelectOption, aF as ShadowValue, aH as SizeProps, aL as SpacingProps, aM as SpacingValue, aO as SpinnerSize, aP as SpinnerSizeToken, aQ as StackNode, aT as StateValue, aU as StateValueType, aW as TabNode, aZ as TextAlign, b0 as TextSize, b1 as TextSizeToken, b2 as TextWeight, b4 as TitleLevel, b7 as ToastPosition, b9 as TooltipPosition, ba as TopLevelNode, bb as ValueWithUnit, bc as WidthValue } from './types-BphXi5Tn.cjs';
1
+ import { h as AnyNode, A as AccordionNode, a as AlertNode, j as AvatarNode, B as BadgeNode, r as BreadcrumbNode, s as ButtonNode, C as CardNode, w as CheckboxNode, x as ColNode, z as ComponentDefinitionNode, H as ComponentUseNode, I as ContainerComponentNode, J as ContainerNode, K as DataNode, L as DefinitionNode, N as DisplayNode, O as DividerComponentNode, P as DrawerNode, S as DropdownNode, T as FeedbackNode, V as FooterNode, W as GridNode, Z as HeaderNode, $ as IconNode, a2 as ImageNode, a3 as InputComponentNode, a4 as InputNode, aa as LayoutDefinitionNode, ab as LayoutNode, ac as LeafNode, ad as LinkNode, af as ListNode, ag as MainNode, aj as ModalNode, ao as NavNode, ap as NavigationNode, aq as NodeType, ar as OverlayNode, as as PageNode, at as PlaceholderNode, au as PopoverNode, ax as ProgressNode, ay as RadioNode, aB as RowNode, aC as SectionNode, aD as SelectNode, aG as SidebarNode, aI as SliderNode, aJ as SlotNode, aN as SpinnerNode, aV as SwitchNode, aX as TableNode, aY as TabsNode, a_ as TextContentNode, a$ as TextNode, b3 as TextareaNode, b5 as TitleNode, b6 as ToastNode, b8 as TooltipNode, be as WireframeDocument, aK as SourceLocation, aR as StateDeclaration, aS as StateGuard, a6 as InteractionEffect, a5 as InputType } from './types-vhPCZpAW.cjs';
2
+ export { b as AlertVariant, c as AlignValue, d as AnchorPosition, e as AnnotationItemNode, f as AnnotationNode, g as AnnotationsNode, i as AppearanceProps, k as AvatarSize, l as AvatarSizeToken, m as BadgeSize, n as BadgeSizeToken, o as BadgeVariant, p as BaseNode, q as BreadcrumbItem, t as ButtonSize, u as ButtonSizeToken, v as ButtonVariant, y as CommonProps, D as ComponentInputValue, E as ComponentParameter, F as ComponentParameterType, G as ComponentSlotFill, M as DirectionValue, Q as DrawerPosition, R as DropdownItemNode, U as FlexProps, X as GridProps, Y as GuardedOutcomeProps, _ as HeightValue, a0 as IconSize, a1 as IconSizeToken, a7 as InteractionHandler, a8 as InteractiveProps, a9 as JustifyValue, ae as ListItemNode, ah as MarkerColor, ai as MarkerNode, ak as NavBlockItem, al as NavChild, am as NavGroupNode, an as NavItem, av as Position, aw as PositionProps, az as RelativeNode, aA as RepeatNode, aE as SelectOption, aF as ShadowValue, aH as SizeProps, aL as SpacingProps, aM as SpacingValue, aO as SpinnerSize, aP as SpinnerSizeToken, aQ as StackNode, aT as StateValue, aU as StateValueType, aW as TabNode, aZ as TextAlign, b0 as TextSize, b1 as TextSizeToken, b2 as TextWeight, b4 as TitleLevel, b7 as ToastPosition, b9 as TooltipPosition, ba as TopLevelNode, bb as ValueWithUnit, bc as VariantScopedProps, bd as WidthValue } from './types-vhPCZpAW.cjs';
3
3
  export { ExpectedToken, ParseError, ParseErrorInfo, ParseOptions, ParseResult, getErrors, isValid, parse, tryParse } from './parser.cjs';
4
4
  import { SiteOptions } from './renderer.cjs';
5
5
  export { AnnotationStyle, CanvasOptions, CanvasRenderResult, ENABLED_GUARD_ATTR, EXTERNAL_NAVIGATE_ATTR, HtmlRenderer, INERT_HREF, INTERACTIVE_ATTR_NAMES, IconData, IconElement, InteractiveAttrs, PageRenderResult, PlacedPage, RenderContext, RenderOptions, RenderResult, ShellMiss, SiteModel, SiteScreen, SiteShell, SvgRenderOptions, SvgRenderResult, TYPED_INTERACTION_ATTR, ThemeColors, ThemeConfig, VISIBLE_GUARD_ATTR, anchorIntent, buildSiteModel, createHtmlRenderer, darkTheme, defaultTheme, generateComponentStyles, generateStyles, getIconData, getTheme, guardedOutcomeAttrs, interactiveAttrs, layoutCanvas, lucideIcons, render, renderCanvas, renderIconSvg, renderPage, renderSite, renderToHtml, renderToSvg, renderUnknownIconSvg, resolvePageDimensions } from './renderer.cjs';
@@ -333,6 +333,167 @@ declare class RepeatBudgetError extends Error {
333
333
  */
334
334
  declare function expandRepeats(document: WireframeDocument): WireframeDocument;
335
335
 
336
+ /**
337
+ * `page … variants=[a, b, c]` expansion — one page turned into the screens it denotes.
338
+ *
339
+ * ## What a variant is, and why it is not a state
340
+ *
341
+ * A wireframe usually has to show a screen in several conditions: loading,
342
+ * empty, populated, failed. The language already has `states` for that, and it
343
+ * is the wrong tool: a `state` is a runtime value the site runtime flips and
344
+ * `visibleWhen` guards read, so *something in the wireframe has to flip it*.
345
+ * That something is a control the product does not have — a reviewer opening
346
+ * the artifact sees state-switching buttons among the real UI and cannot tell
347
+ * which is which. It also produces one board, so the conditions are only
348
+ * visible one at a time, and any block common to two conditions is written
349
+ * twice because a guard has no disjunction.
350
+ *
351
+ * A variant moves the same information from a toggle inside the screen to an
352
+ * axis of the document: `variants=[loading, empty, ready]` draws the page three
353
+ * times, side by side, with no switching UI in any of them. The artifact
354
+ * becomes the sheet of state-by-state boards a reviewer reads top to bottom,
355
+ * and the common blocks are shared because they are one authored body.
356
+ *
357
+ * ## Why this is a document pass, like `repeat`
358
+ *
359
+ * For the reason spelled out at length in `expand-repeats.ts`: the renderer
360
+ * builds `buildAnchorPathMap(document)` up front and keys it by **node object
361
+ * identity**. Two variant boards sharing one child tree would be two boards the
362
+ * map has seen once, so the second would render without `data-wf-path` and the
363
+ * anchor count would stop matching the index. Every variant is therefore a
364
+ * fresh deep clone, and `loc` is deliberately shared: all three boards really do
365
+ * originate at one span of source.
366
+ *
367
+ * Doing it here rather than in each renderer is also what keeps the surfaces
368
+ * agreeing. `render`'s canvas counts pages and `renderSite` builds a screen
369
+ * model; if each expanded on its own, a variant would be a canvas board and a
370
+ * site screen by two separate rules that could drift. They both run this pass
371
+ * and then count what it produced.
372
+ *
373
+ * And, as with `repeat`, this is deliberately **not** in the parser: the AST
374
+ * keeps `variants` so the printer writes it back out, and expanding at parse
375
+ * time would break the `parse(print(parse(src)))` round-trip law the corpus
376
+ * harness pins.
377
+ */
378
+
379
+ /**
380
+ * Replace every page declaring `variants=` with one page per variant.
381
+ *
382
+ * Each produced page carries `variant` naming which one it is and no longer
383
+ * carries `variants`, so the result declares none and a second application is a
384
+ * no-op. A document with no variants is returned as-is, identity included, so
385
+ * the common case costs one scan and no allocation — the property every
386
+ * existing document relies on to render exactly as it did before.
387
+ *
388
+ * @param document - Parsed wireframe document
389
+ * @returns The document with all variant-bearing pages expanded
390
+ * @public
391
+ * @example
392
+ * `const drawable = expandVariants(parse(source))`
393
+ */
394
+ declare function expandVariants(document: WireframeDocument): WireframeDocument;
395
+
396
+ /**
397
+ * `when=` filtering — dropping the elements a board does not draw.
398
+ *
399
+ * ## What `when` says, and why it is not a guard
400
+ *
401
+ * `visibleWhen` already answers "should this be on screen right now": the
402
+ * element is rendered onto every board, carries `data-wf-visible-when`, and the
403
+ * site runtime shows and hides it as state changes. `when` answers a different
404
+ * question — *which boards is this element part of at all* — and it answers it
405
+ * before anything renders. An element scoped to `loading` is not hidden on the
406
+ * `ready` board; it is absent from it, so no state change can bring it back and
407
+ * nothing in that board's markup refers to it.
408
+ *
409
+ * The two are therefore orthogonal, not alternatives, and this pass is careful
410
+ * to leave guards alone: it deletes `when` from the nodes it keeps and touches
411
+ * no other property, so `when=ready visibleWhen={…}` survives as a guard on the
412
+ * ready board. Collapsing them would lose the case the feature exists for.
413
+ *
414
+ * ## Why disjunction is the point
415
+ *
416
+ * A guard compares one state to one value, so a block belonging to two
417
+ * conditions could only be written twice. That is not a stylistic cost: the two
418
+ * copies are edited separately and drift, and a reviewer reading the sheet
419
+ * cannot tell whether a difference between them is intentional. `when=[loading,
420
+ * empty]` is the same block, authored once, drawn on both boards — the header
421
+ * shared by three states is one header, and it stays one.
422
+ *
423
+ * ## Why it runs inside variant expansion
424
+ *
425
+ * Filtering needs to know which board it is filtering *for*, and that fact
426
+ * exists only after `expandVariants` has turned one authored page into one page
427
+ * per name and stamped each with `page.variant`. Running as a separate pass
428
+ * afterwards would have to rediscover the same association by walking the
429
+ * document again; running before expansion would have no board to ask about.
430
+ * So the board is filtered at the moment it is cloned, while the name is in
431
+ * hand — see `expand-variants.ts`.
432
+ *
433
+ * ## The rule, stated once
434
+ *
435
+ * An element is drawn on a board **iff its `when` set contains that board's
436
+ * variant**. Everything else follows from that one sentence rather than from a
437
+ * list of cases:
438
+ *
439
+ * - No `when` at all → drawn on every board. This is what keeps every document
440
+ * written before the attribute existed rendering byte-for-byte as it did.
441
+ * - A board with no variant (a page that declared no `variants=`) matches no
442
+ * name, so *any* `when` filters the element out. That is the honest reading
443
+ * rather than a convenient one: the element declares membership in a board
444
+ * this page never declared, and drawing it anyway would make `when` mean
445
+ * "sometimes nothing", which is the silently-dropped-value failure the spec
446
+ * gates exist to prevent. `validate()` reports the same document, so the
447
+ * author is told rather than left to discover an empty board.
448
+ * - A parent that is filtered out takes its children with it, whatever they
449
+ * say. A child scoped to `ready` inside a parent scoped to `loading` cannot
450
+ * be drawn on either board — there is no board where both are present — and
451
+ * the contradiction is reported by `validate()` rather than resolved here.
452
+ */
453
+
454
+ /**
455
+ * The variant names an element declares, trimmed, blanks and duplicates dropped.
456
+ *
457
+ * Both spellings collapse to the same set, because `when=loading` and
458
+ * `when=[loading]` denote the same membership and nothing downstream should
459
+ * have to know which the author typed.
460
+ *
461
+ * A `when` that is present but names nothing — `when=[]`, or a blank string —
462
+ * yields an empty set, which matches no board. It is deliberately not treated
463
+ * as "no `when`": the author wrote the attribute, and answering an empty list
464
+ * with "every board" would make the emptiest possible scope the widest one.
465
+ */
466
+ declare function variantScope(node: AnyNode): string[] | undefined;
467
+ /**
468
+ * Drop from `children` everything not drawn on `variant`'s board.
469
+ *
470
+ * Identity-preserving: a subtree carrying no `when` anywhere is returned as the
471
+ * same array, so a board of a document that uses no scoping costs one scan.
472
+ *
473
+ * @param children - The board's children, already cloned by variant expansion
474
+ * @param variant - The board's variant name, or `undefined` for an unnamed board
475
+ * @returns The children this board draws
476
+ * @internal
477
+ */
478
+ declare function filterVariantScope(children: AnyNode[], variant: string | undefined): AnyNode[];
479
+ /**
480
+ * Apply `when` filtering to every page of a document that expansion did not.
481
+ *
482
+ * Variant-bearing pages are filtered as they are cloned, inside
483
+ * `expandVariants`, because that is where the board's name exists. This covers
484
+ * the rest: a page that declared no `variants=` is still a board, an unnamed
485
+ * one, and an element scoped to a name it never declared is not drawn on it.
486
+ *
487
+ * Layout and component definitions are filtered through the pages that use
488
+ * them, not here — a definition has no board of its own, and scoping inside one
489
+ * resolves against whichever page pulled it in.
490
+ *
491
+ * @param document - A document whose variant-bearing pages are already expanded
492
+ * @returns The document with unnamed boards filtered
493
+ * @internal
494
+ */
495
+ declare function filterUnscopedPages(document: WireframeDocument): WireframeDocument;
496
+
336
497
  /**
337
498
  * Node/document-level canonical `.wf` printing.
338
499
  *
@@ -1747,4 +1908,4 @@ declare function compileApp(document: AppDocument, options?: CompileAppOptions):
1747
1908
  */
1748
1909
  declare function linkAndCompileApp(manifest: AppManifest, modules: readonly AppModuleInput[], options?: CompileAppOptions): AppCompileResult;
1749
1910
 
1750
- export { ANCHOR_LOC_ATTR, ANCHOR_PATH_ATTR, type AccessibilityMetrics, AccordionNode, AlertNode, type AnalysisOptions, type AnalysisResult, type AnchorEntry, AnyNode, type AppCompileResult, type AppComponentInput, type AppComponentInstanceId, type AppDefinitionKind, type AppDocument, type AppLayoutInput, type AppLinkDiagnostic, type AppLinkDiagnosticCode, type AppLinkResult, type AppManifest, type AppManifestModule, type AppModuleInput, type AppNodeId, type AppNodeKind, type AppReferenceInput, type AppScreenInput, type AppSourceMapEntry, type AppSourceSpan, type AttributeChange, AvatarNode, BadgeNode, BreadcrumbNode, ButtonNode, CardNode, CheckboxNode, ColNode, type CompileAppOptions, type ComplexityMetrics, ComponentCategory, ComponentDefinitionNode, type ComponentParameterReference, type ComponentStats, ComponentUseNode, ContainerComponentNode, ContainerNode, type ContentAnalysis, DEFAULT_VIEWPORT, DEVICE_PRESETS, DataNode, DefinitionNode, type DiffChangeType, type DiffOptions, type DiffResult, type DiffSummary, DisplayNode, DividerComponentNode, type DomTreeNode, DrawerNode, DropdownNode, type ExportOptions, FeedbackNode, type FigmaAutoLayout, type FigmaColor, type FigmaCounterAxisAlign, type FigmaExportResult, type FigmaLayoutMode, type FigmaNode, type FigmaNodeType, type FigmaPrimaryAxisAlign, type FigmaSize, type FigmaSizingMode, type FigmaSolidFill, type FigmaStroke, type FigmaTextAlign, type FigmaTextStyle, FooterNode, GridNode, HeaderNode, IconNode, ImageNode, InputComponentNode, InputNode, InputType, type InteractionDiagnostic, type InteractionDiagnosticCode, InteractionEffect, type InteractionKind, type InteractionModel, type JsonExportResult, type JsonNode, type LayoutAnalysis, LayoutDefinitionNode, LayoutNode, LeafNode, LinkNode, ListNode, MainNode, ModalNode, NavNode, NavigationNode, type NodeChange, type NodePredicate, NodeType, type NormalizedInteraction, type NormalizedInteractionEffect, type NormalizedInteractionHandler, OverlayNode, PageNode, PlaceholderNode, PopoverNode, type PreviewWrapperOptions, ProgressNode, REPEAT_EXPANSION_BUDGET, RadioNode, RepeatBudgetError, type ResolvedAppComponent, type ResolvedAppLayout, type ResolvedAppModule, type ResolvedAppReference, type ResolvedAppScreen, RowNode, type ScreenAction, type ScreenDisplay, type ScreenElement, type ScreenFields, type ScreenFieldsSummary, type ScreenInput, type ScreenTransitionGraph, SectionNode, SelectNode, SidebarNode, SiteOptions, SliderNode, SlotNode, SourceLocation, type SourceSlice, SpinnerNode, StateDeclaration, StateGuard, SwitchNode, TableNode, TabsNode, TextContentNode, TextNode, TextareaNode, TitleNode, ToastNode, TooltipNode, type TransitionEdge, type TransitionScreen, type TreeMetrics, type ValidationError, type ValidationOptions, type ValidationResult, type ViewportSize, type WalkCallback, WireframeDocument, analyze, areIdentical, buildAnchorIndex, buildDomTree, calculateViewportScale, cloneNode, collectInteractions, collectParameterReferences, compileApp, contains, countNodes, createAppComponentInstanceId, createAppNodeId, diff, documentDefinitions, documentPages, expandRepeats, exportToFigma, exportToFigmaString, exportToJson, exportToJsonString, extractAllScreenFields, extractScreenFields, extractScreenTransitions, find, findAll, findByType, formatWireframeCode, getAncestors, getChangeSummary, getDevicePresets, getMaxDepth, getNodeSource, getNodeTypes, getPageSource, getValidationErrors, hasChildren, importFromJson, interactionSignature, isAccordionNode, isAlertNode, isAvatarNode, isBadgeNode, isBreadcrumbNode, isButtonNode, isCardNode, isCheckboxNode, isColNode, isComponentDefinitionNode, isComponentUseNode, isContainerComponentNode, isContainerNode, isDataNode, isDefinitionNode, isDisplayNode, isDividerNode, isDrawerNode, isDropdownNode, isFeedbackNode, isFooterNode, isGridNode, isHeaderNode, isIconNode, isImageNode, isInputComponentNode, isInputNode, isLayoutDefinitionNode, isLayoutNode, isLeafNode, isLinkNode, isListNode, isMainNode, isModalNode, isNavNode, isNavigationNode, isNodeType, isOverlayNode, isPageNode, isPlaceholderNode, isPopoverNode, isProgressNode, isRadioNode, isRowNode, isSectionNode, isSelectNode, isSidebarNode, isSliderNode, isSlotNode, isSpinnerNode, isSwitchNode, isTableNode, isTabsNode, isTextContentNode, isTextNode, isTextareaNode, isTitleNode, isToastNode, isTooltipNode, isUrlTarget, isValidAst, isValidDevicePreset, linkAndCompileApp, linkApp, mapNodes, normalizeInteractionHandlers, normalizeStateGuard, parameterReferenceName, parseViewportString, printWireframe, resetFigmaIdCounter, resolveAnchor, resolveViewport, validate, walk, walkDocument, wrapInPreviewContainer };
1911
+ export { ANCHOR_LOC_ATTR, ANCHOR_PATH_ATTR, type AccessibilityMetrics, AccordionNode, AlertNode, type AnalysisOptions, type AnalysisResult, type AnchorEntry, AnyNode, type AppCompileResult, type AppComponentInput, type AppComponentInstanceId, type AppDefinitionKind, type AppDocument, type AppLayoutInput, type AppLinkDiagnostic, type AppLinkDiagnosticCode, type AppLinkResult, type AppManifest, type AppManifestModule, type AppModuleInput, type AppNodeId, type AppNodeKind, type AppReferenceInput, type AppScreenInput, type AppSourceMapEntry, type AppSourceSpan, type AttributeChange, AvatarNode, BadgeNode, BreadcrumbNode, ButtonNode, CardNode, CheckboxNode, ColNode, type CompileAppOptions, type ComplexityMetrics, ComponentCategory, ComponentDefinitionNode, type ComponentParameterReference, type ComponentStats, ComponentUseNode, ContainerComponentNode, ContainerNode, type ContentAnalysis, DEFAULT_VIEWPORT, DEVICE_PRESETS, DataNode, DefinitionNode, type DiffChangeType, type DiffOptions, type DiffResult, type DiffSummary, DisplayNode, DividerComponentNode, type DomTreeNode, DrawerNode, DropdownNode, type ExportOptions, FeedbackNode, type FigmaAutoLayout, type FigmaColor, type FigmaCounterAxisAlign, type FigmaExportResult, type FigmaLayoutMode, type FigmaNode, type FigmaNodeType, type FigmaPrimaryAxisAlign, type FigmaSize, type FigmaSizingMode, type FigmaSolidFill, type FigmaStroke, type FigmaTextAlign, type FigmaTextStyle, FooterNode, GridNode, HeaderNode, IconNode, ImageNode, InputComponentNode, InputNode, InputType, type InteractionDiagnostic, type InteractionDiagnosticCode, InteractionEffect, type InteractionKind, type InteractionModel, type JsonExportResult, type JsonNode, type LayoutAnalysis, LayoutDefinitionNode, LayoutNode, LeafNode, LinkNode, ListNode, MainNode, ModalNode, NavNode, NavigationNode, type NodeChange, type NodePredicate, NodeType, type NormalizedInteraction, type NormalizedInteractionEffect, type NormalizedInteractionHandler, OverlayNode, PageNode, PlaceholderNode, PopoverNode, type PreviewWrapperOptions, ProgressNode, REPEAT_EXPANSION_BUDGET, RadioNode, RepeatBudgetError, type ResolvedAppComponent, type ResolvedAppLayout, type ResolvedAppModule, type ResolvedAppReference, type ResolvedAppScreen, RowNode, type ScreenAction, type ScreenDisplay, type ScreenElement, type ScreenFields, type ScreenFieldsSummary, type ScreenInput, type ScreenTransitionGraph, SectionNode, SelectNode, SidebarNode, SiteOptions, SliderNode, SlotNode, SourceLocation, type SourceSlice, SpinnerNode, StateDeclaration, StateGuard, SwitchNode, TableNode, TabsNode, TextContentNode, TextNode, TextareaNode, TitleNode, ToastNode, TooltipNode, type TransitionEdge, type TransitionScreen, type TreeMetrics, type ValidationError, type ValidationOptions, type ValidationResult, type ViewportSize, type WalkCallback, WireframeDocument, analyze, areIdentical, buildAnchorIndex, buildDomTree, calculateViewportScale, cloneNode, collectInteractions, collectParameterReferences, compileApp, contains, countNodes, createAppComponentInstanceId, createAppNodeId, diff, documentDefinitions, documentPages, expandRepeats, expandVariants, exportToFigma, exportToFigmaString, exportToJson, exportToJsonString, extractAllScreenFields, extractScreenFields, extractScreenTransitions, filterUnscopedPages, filterVariantScope, find, findAll, findByType, formatWireframeCode, getAncestors, getChangeSummary, getDevicePresets, getMaxDepth, getNodeSource, getNodeTypes, getPageSource, getValidationErrors, hasChildren, importFromJson, interactionSignature, isAccordionNode, isAlertNode, isAvatarNode, isBadgeNode, isBreadcrumbNode, isButtonNode, isCardNode, isCheckboxNode, isColNode, isComponentDefinitionNode, isComponentUseNode, isContainerComponentNode, isContainerNode, isDataNode, isDefinitionNode, isDisplayNode, isDividerNode, isDrawerNode, isDropdownNode, isFeedbackNode, isFooterNode, isGridNode, isHeaderNode, isIconNode, isImageNode, isInputComponentNode, isInputNode, isLayoutDefinitionNode, isLayoutNode, isLeafNode, isLinkNode, isListNode, isMainNode, isModalNode, isNavNode, isNavigationNode, isNodeType, isOverlayNode, isPageNode, isPlaceholderNode, isPopoverNode, isProgressNode, isRadioNode, isRowNode, isSectionNode, isSelectNode, isSidebarNode, isSliderNode, isSlotNode, isSpinnerNode, isSwitchNode, isTableNode, isTabsNode, isTextContentNode, isTextNode, isTextareaNode, isTitleNode, isToastNode, isTooltipNode, isUrlTarget, isValidAst, isValidDevicePreset, linkAndCompileApp, linkApp, mapNodes, normalizeInteractionHandlers, normalizeStateGuard, parameterReferenceName, parseViewportString, printWireframe, resetFigmaIdCounter, resolveAnchor, resolveViewport, validate, variantScope, walk, walkDocument, wrapInPreviewContainer };