@wireweave/core 3.1.0-beta.5 → 3.1.0-beta.6

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
@@ -60,6 +60,7 @@ __export(src_exports, {
60
60
  calculateViewportScale: () => calculateViewportScale,
61
61
  cloneNode: () => cloneNode,
62
62
  collectInteractions: () => collectInteractions,
63
+ collectParameterReferences: () => collectParameterReferences,
63
64
  compileApp: () => compileApp,
64
65
  contains: () => contains,
65
66
  countNodes: () => countNodes,
@@ -172,6 +173,7 @@ __export(src_exports, {
172
173
  mapNodes: () => mapNodes,
173
174
  normalizeInteractionHandlers: () => normalizeInteractionHandlers,
174
175
  normalizeStateGuard: () => normalizeStateGuard,
176
+ parameterReferenceName: () => parameterReferenceName,
175
177
  parse: () => parse,
176
178
  parseViewportString: () => parseViewportString,
177
179
  printWireframe: () => printWireframe,
@@ -515,6 +517,43 @@ function getNodeTypes(node) {
515
517
  return types;
516
518
  }
517
519
 
520
+ // src/ast/component-parameters.ts
521
+ var PARAMETER_REFERENCE = /^\$([a-zA-Z_][a-zA-Z0-9_-]*)$/;
522
+ function parameterReferenceName(value) {
523
+ return typeof value === "string" ? PARAMETER_REFERENCE.exec(value)?.[1] : void 0;
524
+ }
525
+ function collectParameterReferences(children) {
526
+ const found = [];
527
+ const visitValue = (value, key, node) => {
528
+ const name = parameterReferenceName(value);
529
+ if (name !== void 0) {
530
+ found.push({ name, key, node });
531
+ return;
532
+ }
533
+ if (Array.isArray(value)) {
534
+ for (const item of value) visitValue(item, key, node);
535
+ return;
536
+ }
537
+ if (value === null || typeof value !== "object") return;
538
+ for (const [childKey, item] of Object.entries(value)) {
539
+ if (childKey === "loc") continue;
540
+ visitValue(item, childKey, node);
541
+ }
542
+ };
543
+ const visitNode = (node) => {
544
+ if (node.type === "ComponentUse") return;
545
+ for (const [key, value] of Object.entries(node)) {
546
+ if (key === "loc" || key === "children") continue;
547
+ visitValue(value, key, node);
548
+ }
549
+ if ("children" in node && Array.isArray(node.children)) {
550
+ for (const child of node.children) visitNode(child);
551
+ }
552
+ };
553
+ for (const child of children) visitNode(child);
554
+ return found;
555
+ }
556
+
518
557
  // src/parser/generated-parser.js
519
558
  var peg$SyntaxError = class extends SyntaxError {
520
559
  constructor(message, expected, found, location) {
@@ -63504,18 +63543,6 @@ function checkComponentContracts(ast, addError) {
63504
63543
  }
63505
63544
  slots.add(name);
63506
63545
  }
63507
- for (const [key, value] of Object.entries(node)) {
63508
- if (key === "loc" || key === "children" || typeof value !== "string") continue;
63509
- const name = /^\$([a-zA-Z_][a-zA-Z0-9_-]*)$/.exec(value)?.[1];
63510
- if (name !== void 0 && !parameters.has(name) && !report(
63511
- node,
63512
- path,
63513
- `Unknown component parameter reference "$${name}" in component "${definition.name}"`,
63514
- key
63515
- )) {
63516
- return false;
63517
- }
63518
- }
63519
63546
  for (let childIndex = 0; childIndex < childrenOf2(node).length; childIndex++) {
63520
63547
  const child = childrenOf2(node)[childIndex];
63521
63548
  if (child && !inspect(child, `${path}.children[${childIndex}]`)) return false;
@@ -63526,6 +63553,17 @@ function checkComponentContracts(ast, addError) {
63526
63553
  const child = definition.children[childIndex];
63527
63554
  if (child && !inspect(child, `pages[${index}].children[${childIndex}]`)) return false;
63528
63555
  }
63556
+ for (const reference of collectParameterReferences(definition.children)) {
63557
+ if (parameters.has(reference.name)) continue;
63558
+ if (!report(
63559
+ reference.node,
63560
+ `pages[${index}]`,
63561
+ `Unknown component parameter reference "$${reference.name}" in component "${definition.name}"`,
63562
+ reference.key
63563
+ )) {
63564
+ return false;
63565
+ }
63566
+ }
63529
63567
  }
63530
63568
  const validateUse = (use, path) => {
63531
63569
  const definition = use.namespace === void 0 ? definitions.get(use.name) : void 0;
@@ -65306,27 +65344,24 @@ function validateComponentDefinitions(definitions, diagnostics) {
65306
65344
  slotNames.add(name);
65307
65345
  }
65308
65346
  }
65309
- for (const [key, value] of Object.entries(node)) {
65310
- if (key === "loc" || key === "children" || typeof value !== "string") continue;
65311
- const name = /^\$([a-zA-Z_][a-zA-Z0-9_-]*)$/.exec(value)?.[1];
65312
- if (name !== void 0 && !parameterNames.has(name)) {
65313
- diagnostics.push({
65314
- code: "invalid-component-definition",
65315
- message: `Unknown parameter reference "$${name}" in component "${pending.namespace}:${pending.input.id}"`,
65316
- source: pending.input.source
65317
- });
65318
- invalid.add(pending.nodeId);
65319
- }
65320
- }
65321
65347
  for (const child of childNodes(node)) inspect(child);
65322
65348
  };
65323
65349
  for (const child of definition.children) inspect(child);
65350
+ for (const reference of collectParameterReferences(definition.children)) {
65351
+ if (parameterNames.has(reference.name)) continue;
65352
+ diagnostics.push({
65353
+ code: "invalid-component-definition",
65354
+ message: `Unknown parameter reference "$${reference.name}" in component "${pending.namespace}:${pending.input.id}"`,
65355
+ source: pending.input.source
65356
+ });
65357
+ invalid.add(pending.nodeId);
65358
+ }
65324
65359
  }
65325
65360
  return invalid;
65326
65361
  }
65327
65362
  function substituteTemplate(value, inputs) {
65328
65363
  if (typeof value === "string") {
65329
- const name = /^\$([a-zA-Z_][a-zA-Z0-9_-]*)$/.exec(value)?.[1];
65364
+ const name = parameterReferenceName(value);
65330
65365
  return name !== void 0 && name in inputs ? inputs[name] : value;
65331
65366
  }
65332
65367
  if (Array.isArray(value)) return value.map((item) => substituteTemplate(item, inputs));
@@ -65692,6 +65727,7 @@ function linkAndCompileApp(manifest, modules, options = {}) {
65692
65727
  calculateViewportScale,
65693
65728
  cloneNode,
65694
65729
  collectInteractions,
65730
+ collectParameterReferences,
65695
65731
  compileApp,
65696
65732
  contains,
65697
65733
  countNodes,
@@ -65804,6 +65840,7 @@ function linkAndCompileApp(manifest, modules, options = {}) {
65804
65840
  mapNodes,
65805
65841
  normalizeInteractionHandlers,
65806
65842
  normalizeStateGuard,
65843
+ parameterReferenceName,
65807
65844
  parse,
65808
65845
  parseViewportString,
65809
65846
  printWireframe,
package/dist/index.d.cts CHANGED
@@ -208,6 +208,62 @@ declare function contains(node: AnyNode, target: AnyNode): boolean;
208
208
  */
209
209
  declare function getNodeTypes(node: AnyNode): Set<NodeType>;
210
210
 
211
+ /**
212
+ * Component parameter references (`"$name"`) — one traversal, one pattern.
213
+ *
214
+ * A component body may reference a declared parameter anywhere a string value
215
+ * sits: a top-level prop (`title "$name"`), a nested object (an interaction
216
+ * effect's `target`), or an element of an array (`effects[]`). Substitution at
217
+ * link time walks all three. Validation must walk exactly the same shape, or a
218
+ * reference that gets substituted is never checked — an undeclared name then
219
+ * survives as the literal string `"$too"` with no diagnostic.
220
+ *
221
+ * Both the linker and the document validator therefore share the traversal and
222
+ * the pattern defined here rather than re-deriving either.
223
+ */
224
+
225
+ /**
226
+ * The parameter name a string value references, or `undefined` when the value
227
+ * is ordinary text.
228
+ *
229
+ * @param value - Any value; only whole-string references match.
230
+ * @returns The referenced name without its `$`, or `undefined`.
231
+ * @public
232
+ */
233
+ declare function parameterReferenceName(value: unknown): string | undefined;
234
+ /**
235
+ * One `"$name"` reference found inside a component body.
236
+ *
237
+ * @public
238
+ */
239
+ interface ComponentParameterReference {
240
+ /** Referenced parameter name, without its `$`. */
241
+ name: string;
242
+ /**
243
+ * Property key the reference was found under. Nested keys report the leaf
244
+ * key (`target`), which is what an author sees in the source text.
245
+ */
246
+ key: string;
247
+ /** Nearest enclosing AST node, for diagnostic location and node type. */
248
+ node: AnyNode;
249
+ }
250
+ /**
251
+ * Every parameter reference reachable from a component's children.
252
+ *
253
+ * Mirrors link-time substitution exactly: it descends into arrays and plain
254
+ * objects as well as child nodes, and skips `loc` so a source location can
255
+ * never be mistaken for authored content. `ComponentUse` subtrees are skipped —
256
+ * a nested invocation's inputs belong to that component's own scope, and its
257
+ * body is validated where it is defined.
258
+ *
259
+ * @param children - The component definition's children.
260
+ * @returns References in traversal order.
261
+ * @public
262
+ * @example
263
+ * `collectParameterReferences(definition.children).map((item) => item.name)`
264
+ */
265
+ declare function collectParameterReferences(children: readonly AnyNode[]): ComponentParameterReference[];
266
+
211
267
  /**
212
268
  * Node/document-level canonical `.wf` printing.
213
269
  *
@@ -1622,4 +1678,4 @@ declare function compileApp(document: AppDocument, options?: CompileAppOptions):
1622
1678
  */
1623
1679
  declare function linkAndCompileApp(manifest: AppManifest, modules: readonly AppModuleInput[], options?: CompileAppOptions): AppCompileResult;
1624
1680
 
1625
- 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 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, RadioNode, 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, compileApp, contains, countNodes, createAppComponentInstanceId, createAppNodeId, diff, documentDefinitions, documentPages, 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, parseViewportString, printWireframe, resetFigmaIdCounter, resolveAnchor, resolveViewport, validate, walk, walkDocument, wrapInPreviewContainer };
1681
+ 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, RadioNode, 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, 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 };
package/dist/index.d.ts CHANGED
@@ -208,6 +208,62 @@ declare function contains(node: AnyNode, target: AnyNode): boolean;
208
208
  */
209
209
  declare function getNodeTypes(node: AnyNode): Set<NodeType>;
210
210
 
211
+ /**
212
+ * Component parameter references (`"$name"`) — one traversal, one pattern.
213
+ *
214
+ * A component body may reference a declared parameter anywhere a string value
215
+ * sits: a top-level prop (`title "$name"`), a nested object (an interaction
216
+ * effect's `target`), or an element of an array (`effects[]`). Substitution at
217
+ * link time walks all three. Validation must walk exactly the same shape, or a
218
+ * reference that gets substituted is never checked — an undeclared name then
219
+ * survives as the literal string `"$too"` with no diagnostic.
220
+ *
221
+ * Both the linker and the document validator therefore share the traversal and
222
+ * the pattern defined here rather than re-deriving either.
223
+ */
224
+
225
+ /**
226
+ * The parameter name a string value references, or `undefined` when the value
227
+ * is ordinary text.
228
+ *
229
+ * @param value - Any value; only whole-string references match.
230
+ * @returns The referenced name without its `$`, or `undefined`.
231
+ * @public
232
+ */
233
+ declare function parameterReferenceName(value: unknown): string | undefined;
234
+ /**
235
+ * One `"$name"` reference found inside a component body.
236
+ *
237
+ * @public
238
+ */
239
+ interface ComponentParameterReference {
240
+ /** Referenced parameter name, without its `$`. */
241
+ name: string;
242
+ /**
243
+ * Property key the reference was found under. Nested keys report the leaf
244
+ * key (`target`), which is what an author sees in the source text.
245
+ */
246
+ key: string;
247
+ /** Nearest enclosing AST node, for diagnostic location and node type. */
248
+ node: AnyNode;
249
+ }
250
+ /**
251
+ * Every parameter reference reachable from a component's children.
252
+ *
253
+ * Mirrors link-time substitution exactly: it descends into arrays and plain
254
+ * objects as well as child nodes, and skips `loc` so a source location can
255
+ * never be mistaken for authored content. `ComponentUse` subtrees are skipped —
256
+ * a nested invocation's inputs belong to that component's own scope, and its
257
+ * body is validated where it is defined.
258
+ *
259
+ * @param children - The component definition's children.
260
+ * @returns References in traversal order.
261
+ * @public
262
+ * @example
263
+ * `collectParameterReferences(definition.children).map((item) => item.name)`
264
+ */
265
+ declare function collectParameterReferences(children: readonly AnyNode[]): ComponentParameterReference[];
266
+
211
267
  /**
212
268
  * Node/document-level canonical `.wf` printing.
213
269
  *
@@ -1622,4 +1678,4 @@ declare function compileApp(document: AppDocument, options?: CompileAppOptions):
1622
1678
  */
1623
1679
  declare function linkAndCompileApp(manifest: AppManifest, modules: readonly AppModuleInput[], options?: CompileAppOptions): AppCompileResult;
1624
1680
 
1625
- 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 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, RadioNode, 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, compileApp, contains, countNodes, createAppComponentInstanceId, createAppNodeId, diff, documentDefinitions, documentPages, 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, parseViewportString, printWireframe, resetFigmaIdCounter, resolveAnchor, resolveViewport, validate, walk, walkDocument, wrapInPreviewContainer };
1681
+ 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, RadioNode, 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, 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 };
package/dist/index.js CHANGED
@@ -318,6 +318,43 @@ function getNodeTypes(node) {
318
318
  return types;
319
319
  }
320
320
 
321
+ // src/ast/component-parameters.ts
322
+ var PARAMETER_REFERENCE = /^\$([a-zA-Z_][a-zA-Z0-9_-]*)$/;
323
+ function parameterReferenceName(value) {
324
+ return typeof value === "string" ? PARAMETER_REFERENCE.exec(value)?.[1] : void 0;
325
+ }
326
+ function collectParameterReferences(children) {
327
+ const found = [];
328
+ const visitValue = (value, key, node) => {
329
+ const name = parameterReferenceName(value);
330
+ if (name !== void 0) {
331
+ found.push({ name, key, node });
332
+ return;
333
+ }
334
+ if (Array.isArray(value)) {
335
+ for (const item of value) visitValue(item, key, node);
336
+ return;
337
+ }
338
+ if (value === null || typeof value !== "object") return;
339
+ for (const [childKey, item] of Object.entries(value)) {
340
+ if (childKey === "loc") continue;
341
+ visitValue(item, childKey, node);
342
+ }
343
+ };
344
+ const visitNode = (node) => {
345
+ if (node.type === "ComponentUse") return;
346
+ for (const [key, value] of Object.entries(node)) {
347
+ if (key === "loc" || key === "children") continue;
348
+ visitValue(value, key, node);
349
+ }
350
+ if ("children" in node && Array.isArray(node.children)) {
351
+ for (const child of node.children) visitNode(child);
352
+ }
353
+ };
354
+ for (const child of children) visitNode(child);
355
+ return found;
356
+ }
357
+
321
358
  // src/parser/generated-parser.js
322
359
  var peg$SyntaxError = class extends SyntaxError {
323
360
  constructor(message, expected, found, location) {
@@ -63307,18 +63344,6 @@ function checkComponentContracts(ast, addError) {
63307
63344
  }
63308
63345
  slots.add(name);
63309
63346
  }
63310
- for (const [key, value] of Object.entries(node)) {
63311
- if (key === "loc" || key === "children" || typeof value !== "string") continue;
63312
- const name = /^\$([a-zA-Z_][a-zA-Z0-9_-]*)$/.exec(value)?.[1];
63313
- if (name !== void 0 && !parameters.has(name) && !report(
63314
- node,
63315
- path,
63316
- `Unknown component parameter reference "$${name}" in component "${definition.name}"`,
63317
- key
63318
- )) {
63319
- return false;
63320
- }
63321
- }
63322
63347
  for (let childIndex = 0; childIndex < childrenOf2(node).length; childIndex++) {
63323
63348
  const child = childrenOf2(node)[childIndex];
63324
63349
  if (child && !inspect(child, `${path}.children[${childIndex}]`)) return false;
@@ -63329,6 +63354,17 @@ function checkComponentContracts(ast, addError) {
63329
63354
  const child = definition.children[childIndex];
63330
63355
  if (child && !inspect(child, `pages[${index}].children[${childIndex}]`)) return false;
63331
63356
  }
63357
+ for (const reference of collectParameterReferences(definition.children)) {
63358
+ if (parameters.has(reference.name)) continue;
63359
+ if (!report(
63360
+ reference.node,
63361
+ `pages[${index}]`,
63362
+ `Unknown component parameter reference "$${reference.name}" in component "${definition.name}"`,
63363
+ reference.key
63364
+ )) {
63365
+ return false;
63366
+ }
63367
+ }
63332
63368
  }
63333
63369
  const validateUse = (use, path) => {
63334
63370
  const definition = use.namespace === void 0 ? definitions.get(use.name) : void 0;
@@ -65109,27 +65145,24 @@ function validateComponentDefinitions(definitions, diagnostics) {
65109
65145
  slotNames.add(name);
65110
65146
  }
65111
65147
  }
65112
- for (const [key, value] of Object.entries(node)) {
65113
- if (key === "loc" || key === "children" || typeof value !== "string") continue;
65114
- const name = /^\$([a-zA-Z_][a-zA-Z0-9_-]*)$/.exec(value)?.[1];
65115
- if (name !== void 0 && !parameterNames.has(name)) {
65116
- diagnostics.push({
65117
- code: "invalid-component-definition",
65118
- message: `Unknown parameter reference "$${name}" in component "${pending.namespace}:${pending.input.id}"`,
65119
- source: pending.input.source
65120
- });
65121
- invalid.add(pending.nodeId);
65122
- }
65123
- }
65124
65148
  for (const child of childNodes(node)) inspect(child);
65125
65149
  };
65126
65150
  for (const child of definition.children) inspect(child);
65151
+ for (const reference of collectParameterReferences(definition.children)) {
65152
+ if (parameterNames.has(reference.name)) continue;
65153
+ diagnostics.push({
65154
+ code: "invalid-component-definition",
65155
+ message: `Unknown parameter reference "$${reference.name}" in component "${pending.namespace}:${pending.input.id}"`,
65156
+ source: pending.input.source
65157
+ });
65158
+ invalid.add(pending.nodeId);
65159
+ }
65127
65160
  }
65128
65161
  return invalid;
65129
65162
  }
65130
65163
  function substituteTemplate(value, inputs) {
65131
65164
  if (typeof value === "string") {
65132
- const name = /^\$([a-zA-Z_][a-zA-Z0-9_-]*)$/.exec(value)?.[1];
65165
+ const name = parameterReferenceName(value);
65133
65166
  return name !== void 0 && name in inputs ? inputs[name] : value;
65134
65167
  }
65135
65168
  if (Array.isArray(value)) return value.map((item) => substituteTemplate(item, inputs));
@@ -65494,6 +65527,7 @@ export {
65494
65527
  calculateViewportScale,
65495
65528
  cloneNode,
65496
65529
  collectInteractions,
65530
+ collectParameterReferences,
65497
65531
  compileApp,
65498
65532
  contains,
65499
65533
  countNodes,
@@ -65606,6 +65640,7 @@ export {
65606
65640
  mapNodes,
65607
65641
  normalizeInteractionHandlers,
65608
65642
  normalizeStateGuard,
65643
+ parameterReferenceName,
65609
65644
  parse,
65610
65645
  parseViewportString,
65611
65646
  printWireframe,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wireweave/core",
3
- "version": "3.1.0-beta.5",
3
+ "version": "3.1.0-beta.6",
4
4
  "description": "Core parser and renderer for wireweave",
5
5
  "type": "module",
6
6
  "sideEffects": false,