@glyphjs/compiler 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4,10 +4,14 @@ var parser = require('@glyphjs/parser');
4
4
  var ir = require('@glyphjs/ir');
5
5
  var yaml = require('yaml');
6
6
  var schemas = require('@glyphjs/schemas');
7
+ var unified = require('unified');
8
+ var remarkParse = require('remark-parse');
7
9
 
8
- // src/compile.ts
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var remarkParse__default = /*#__PURE__*/_interopDefault(remarkParse);
9
13
 
10
- // src/inline.ts
14
+ // src/compile.ts
11
15
  function convertPhrasingContent(nodes) {
12
16
  const result = [];
13
17
  for (const node of nodes) {
@@ -74,6 +78,43 @@ function convertSingleNode(node) {
74
78
  }
75
79
  }
76
80
  }
81
+ function parseInlineMarkdown(text, diagnostics) {
82
+ if (text.trim() === "") {
83
+ return [];
84
+ }
85
+ const processor = unified.unified().use(remarkParse__default.default);
86
+ const tree = processor.parse(text);
87
+ const root = tree;
88
+ if (!root.children || root.children.length === 0) {
89
+ return [{ type: "text", value: text }];
90
+ }
91
+ const hasBlockElements = root.children.some(
92
+ (child) => child.type !== "paragraph" && child.type !== "text" && !["strong", "emphasis", "delete", "inlineCode", "link", "image", "break"].includes(
93
+ child.type
94
+ )
95
+ );
96
+ if (hasBlockElements && diagnostics) {
97
+ diagnostics.push({
98
+ severity: "warning",
99
+ code: "INLINE_BLOCK_ELEMENTS",
100
+ message: "Block-level markdown elements (headings, lists, etc.) are not supported in inline text fields. Only inline formatting (bold, italic, links, code) will be preserved.",
101
+ source: "compiler"
102
+ });
103
+ }
104
+ const firstParagraph = root.children.find((child) => child.type === "paragraph");
105
+ if (firstParagraph && firstParagraph.children) {
106
+ return convertPhrasingContent(firstParagraph.children);
107
+ }
108
+ const inlineChildren = root.children.filter(
109
+ (child) => ["text", "strong", "emphasis", "delete", "inlineCode", "link", "image", "break"].includes(
110
+ child.type
111
+ )
112
+ );
113
+ if (inlineChildren.length > 0) {
114
+ return convertPhrasingContent(inlineChildren);
115
+ }
116
+ return [{ type: "text", value: text }];
117
+ }
77
118
 
78
119
  // src/diagnostics.ts
79
120
  function createDiagnostic(source, severity, code, message, position, details) {
@@ -123,6 +164,80 @@ var DEFAULT_POSITION = {
123
164
  function isGlyphUIBlock(node) {
124
165
  return node.type === "glyphUIBlock";
125
166
  }
167
+ var MARKDOWN_FIELD_MAP = {
168
+ callout: ["content", "title"],
169
+ card: ["cards[].body", "cards[].subtitle"],
170
+ accordion: ["sections[].content"],
171
+ steps: ["steps[].content"],
172
+ kpi: ["metrics[].label"],
173
+ comparison: ["options[].description", "features[].values[]"],
174
+ quiz: ["questions[].question", "questions[].explanation", "questions[].options[]"],
175
+ infographic: ["sections[].items[].text", "sections[].items[].description"],
176
+ timeline: ["events[].title", "events[].description"],
177
+ poll: ["question", "options[].label"],
178
+ rating: ["label", "description"],
179
+ ranker: ["items[].label"],
180
+ slider: ["label"],
181
+ matrix: ["rowLabels[]", "columnLabels[]"],
182
+ annotate: ["annotations[].text"],
183
+ form: ["description"]
184
+ };
185
+ function processMarkdownFields(componentType, data, ctx) {
186
+ const markdownEnabled = data.markdown === true || ctx.compileOptions.parseComponentMarkdown === true;
187
+ if (!markdownEnabled) {
188
+ return data;
189
+ }
190
+ const fieldPaths = MARKDOWN_FIELD_MAP[componentType];
191
+ if (!fieldPaths || fieldPaths.length === 0) {
192
+ return data;
193
+ }
194
+ const result = { ...data };
195
+ for (const path of fieldPaths) {
196
+ processFieldPath(result, path, ctx.diagnostics);
197
+ }
198
+ return result;
199
+ function processFieldPath(obj, path, diagnostics) {
200
+ const segments = path.split(".");
201
+ processSegments(obj, segments, diagnostics);
202
+ }
203
+ function processSegments(obj, segments, diagnostics) {
204
+ if (segments.length === 0) return;
205
+ const [first, ...rest] = segments;
206
+ if (!first) return;
207
+ if (first.endsWith("[]")) {
208
+ const fieldName = first.slice(0, -2);
209
+ const value = obj[fieldName];
210
+ if (Array.isArray(value)) {
211
+ if (rest.length === 0) {
212
+ obj[fieldName] = value.map((item) => {
213
+ if (typeof item === "string") {
214
+ return parseInlineMarkdown(item, diagnostics);
215
+ }
216
+ return item;
217
+ });
218
+ } else {
219
+ for (const item of value) {
220
+ if (typeof item === "object" && item !== null) {
221
+ processSegments(item, rest, diagnostics);
222
+ }
223
+ }
224
+ }
225
+ }
226
+ } else {
227
+ if (rest.length === 0) {
228
+ const value = obj[first];
229
+ if (typeof value === "string") {
230
+ obj[first] = parseInlineMarkdown(value, diagnostics);
231
+ }
232
+ } else {
233
+ const value = obj[first];
234
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
235
+ processSegments(value, rest, diagnostics);
236
+ }
237
+ }
238
+ }
239
+ }
240
+ }
126
241
  function translateNode(node, ctx) {
127
242
  if (isGlyphUIBlock(node)) {
128
243
  return translateGlyphUIBlock(node, ctx);
@@ -163,6 +278,7 @@ function translateGlyphUIBlock(node, ctx) {
163
278
  ctx.diagnostics.push(diag);
164
279
  }
165
280
  }
281
+ data = processMarkdownFields(componentType, data, ctx);
166
282
  if (node.refs && node.refs.length > 0) {
167
283
  processRefs(node.refs, blockId, ctx);
168
284
  }
@@ -656,7 +772,8 @@ function compile(markdown, options) {
656
772
  documentId,
657
773
  diagnostics,
658
774
  references,
659
- blockIdMap: /* @__PURE__ */ new Map()
775
+ blockIdMap: /* @__PURE__ */ new Map(),
776
+ compileOptions: options ?? {}
660
777
  };
661
778
  const blocks = [];
662
779
  for (const child of ast.children) {
@@ -712,17 +829,13 @@ function extractFrontmatter(children, diagnostics) {
712
829
  metadata.description = fm["description"];
713
830
  }
714
831
  if (Array.isArray(fm["authors"])) {
715
- metadata.authors = fm["authors"].filter(
716
- (a) => typeof a === "string"
717
- );
832
+ metadata.authors = fm["authors"].filter((a) => typeof a === "string");
718
833
  }
719
834
  if (typeof fm["createdAt"] === "string") {
720
835
  metadata.createdAt = fm["createdAt"];
721
836
  }
722
837
  if (Array.isArray(fm["tags"])) {
723
- metadata.tags = fm["tags"].filter(
724
- (t) => typeof t === "string"
725
- );
838
+ metadata.tags = fm["tags"].filter((t) => typeof t === "string");
726
839
  }
727
840
  if (fm["layout"] && typeof fm["layout"] === "object" && !Array.isArray(fm["layout"])) {
728
841
  const rawLayout = fm["layout"];
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/inline.ts","../src/diagnostics.ts","../src/ast-to-ir.ts","../src/references.ts","../src/containers.ts","../src/compile.ts"],"names":["generateBlockId","componentSchemas","parseGlyphMarkdown","generateDocumentId","resolveBlockIdCollisions","ir","parseYaml"],"mappings":";;;;;;;;;;AAsEO,SAAS,uBAAuB,KAAA,EAAgC;AACrE,EAAA,MAAM,SAAuB,EAAC;AAE9B,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,MAAM,SAAA,GAAY,kBAAkB,IAA4B,CAAA;AAChE,IAAA,IAAI,SAAA,EAAW;AACb,MAAA,MAAA,CAAO,KAAK,SAAS,CAAA;AAAA,IACvB;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,kBAAkB,IAAA,EAA+C;AACxE,EAAA,QAAQ,KAAK,IAAA;AAAM,IACjB,KAAK,MAAA;AACH,MAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,KAAA,EAAO,KAAK,KAAA,EAAM;AAAA,IAE3C,KAAK,QAAA;AACH,MAAA,OAAO;AAAA,QACL,IAAA,EAAM,QAAA;AAAA,QACN,QAAA,EAAU,sBAAA,CAAuB,IAAA,CAAK,QAAQ;AAAA,OAChD;AAAA,IAEF,KAAK,UAAA;AACH,MAAA,OAAO;AAAA,QACL,IAAA,EAAM,UAAA;AAAA,QACN,QAAA,EAAU,sBAAA,CAAuB,IAAA,CAAK,QAAQ;AAAA,OAChD;AAAA,IAEF,KAAK,QAAA;AACH,MAAA,OAAO;AAAA,QACL,IAAA,EAAM,QAAA;AAAA,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AAC,SAAS,WAAA,EAAa;AACzB,IAAA,MAAM,iBAAiB,MAAA,CAAO,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,SAAS,WAAW,CAAA;AAChE,IAAA,IAAI,cAAA,EAAgB;AAClB,MAAA,MAAM,OAAO,cAAA,CAAe,IAAA;AAC5B,MAAA,IAAI,KAAK,QAAA,EAAU;AACjB,QAAA,QAAA,CAAS,WAAA,GAAc,IAAA,CAAK,QAAA,CACzB,GAAA,CAAI,CAAC,IAAA,KAAS;AACb,UAAA,IAAI,OAAA,IAAW,IAAA,IAAQ,OAAO,IAAA,CAAK,UAAU,QAAA,EAAU;AACrD,YAAA,OAAO,IAAA,CAAK,KAAA;AAAA,UACd;AACA,UAAA,OAAO,EAAA;AAAA,QACT,CAAC,CAAA,CACA,IAAA,CAAK,EAAE,CAAA;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["import type { InlineNode } from '@glyphjs/types';\n\n// ─── MDAST Phrasing Content Types ───────────────────────────\n// These are structural types matching the shapes from mdast,\n// avoiding a hard dependency on @types/mdast.\n\ninterface MdastText {\n type: 'text';\n value: string;\n}\n\ninterface MdastStrong {\n type: 'strong';\n children: MdastPhrasingContent[];\n}\n\ninterface MdastEmphasis {\n type: 'emphasis';\n children: MdastPhrasingContent[];\n}\n\ninterface MdastDelete {\n type: 'delete';\n children: MdastPhrasingContent[];\n}\n\ninterface MdastInlineCode {\n type: 'inlineCode';\n value: string;\n}\n\ninterface MdastLink {\n type: 'link';\n url: string;\n title?: string | null;\n children: MdastPhrasingContent[];\n}\n\ninterface MdastImage {\n type: 'image';\n url: string;\n alt?: string | null;\n title?: string | null;\n}\n\ninterface MdastBreak {\n type: 'break';\n}\n\ntype MdastPhrasingContent =\n | MdastText\n | MdastStrong\n | MdastEmphasis\n | MdastDelete\n | MdastInlineCode\n | MdastLink\n | MdastImage\n | MdastBreak;\n\n// ─── Conversion ─────────────────────────────────────────────\n\n/**\n * Convert an array of MDAST phrasing content nodes to InlineNode[].\n *\n * Unknown node types are converted to text nodes with their string value\n * (if present) or skipped entirely.\n *\n * @param nodes - Raw MDAST phrasing content nodes (typed as unknown[] to avoid a hard @types/mdast dependency).\n * @returns Normalized InlineNode array suitable for inclusion in IR blocks.\n */\nexport function convertPhrasingContent(nodes: unknown[]): InlineNode[] {\n const result: InlineNode[] = [];\n\n for (const node of nodes) {\n const converted = convertSingleNode(node as MdastPhrasingContent);\n if (converted) {\n result.push(converted);\n }\n }\n\n return result;\n}\n\nfunction convertSingleNode(node: MdastPhrasingContent): InlineNode | null {\n switch (node.type) {\n case 'text':\n return { type: 'text', value: node.value };\n\n case 'strong':\n return {\n type: 'strong',\n children: convertPhrasingContent(node.children),\n };\n\n case 'emphasis':\n return {\n type: 'emphasis',\n children: convertPhrasingContent(node.children),\n };\n\n case 'delete':\n return {\n type: 'delete',\n children: convertPhrasingContent(node.children),\n };\n\n case 'inlineCode':\n return { type: 'inlineCode', value: node.value };\n\n case 'link': {\n const linkNode: InlineNode = {\n type: 'link',\n url: node.url,\n children: convertPhrasingContent(node.children),\n };\n if (node.title != null) {\n (linkNode as { type: 'link'; url: string; title?: string; children: InlineNode[] }).title =\n node.title;\n }\n return linkNode;\n }\n\n case 'image': {\n const imgNode: InlineNode = {\n type: 'image',\n src: node.url,\n };\n if (node.alt != null) {\n (imgNode as { type: 'image'; src: string; alt?: string; title?: string }).alt = node.alt;\n }\n if (node.title != null) {\n (imgNode as { type: 'image'; src: string; alt?: string; title?: string }).title =\n node.title;\n }\n return imgNode;\n }\n\n case 'break':\n return { type: 'break' };\n\n default: {\n // For unknown phrasing content types, attempt to extract a text value\n const unknown = node as Record<string, unknown>;\n if (typeof unknown['value'] === 'string') {\n return { type: 'text', value: unknown['value'] };\n }\n return null;\n }\n }\n}\n","import type { Diagnostic, DiagnosticSource, SourcePosition } from '@glyphjs/types';\n\n// ─── Diagnostic Creation Helpers ─────────────────────────────\n\n/**\n * Create a diagnostic with the given source, severity, message, and optional position.\n *\n * @param source - The subsystem that produced the diagnostic (e.g., 'compiler', 'parser', 'schema').\n * @param severity - Severity level: 'error', 'warning', or 'info'.\n * @param code - Machine-readable diagnostic code (e.g., 'YAML_PARSE_ERROR').\n * @param message - Human-readable description of the issue.\n * @param position - Optional source position where the issue was detected.\n * @param details - Optional structured details (e.g., Zod issue objects).\n * @returns A fully constructed Diagnostic object.\n */\nexport function createDiagnostic(\n source: DiagnosticSource,\n severity: Diagnostic['severity'],\n code: string,\n message: string,\n position?: SourcePosition,\n details?: unknown,\n): Diagnostic {\n const diag: Diagnostic = { severity, code, message, source };\n if (position) {\n diag.position = position;\n }\n if (details !== undefined) {\n diag.details = details;\n }\n return diag;\n}\n\n/**\n * Create a schema validation error diagnostic.\n *\n * @param componentType - The ui: component type that failed validation (without the `ui:` prefix).\n * @param message - Concatenated validation error messages from Zod.\n * @param position - Optional source position of the component block.\n * @param details - Optional raw Zod issue objects.\n * @returns A Diagnostic with severity 'error' and code 'SCHEMA_VALIDATION_FAILED'.\n */\nexport function createSchemaError(\n componentType: string,\n message: string,\n position?: SourcePosition,\n details?: unknown,\n): Diagnostic {\n return createDiagnostic(\n 'schema',\n 'error',\n 'SCHEMA_VALIDATION_FAILED',\n `Schema validation failed for ui:${componentType}: ${message}`,\n position,\n details,\n );\n}\n\n/**\n * Create an info diagnostic for unknown component types.\n *\n * @param componentType - The unrecognized component type (without the `ui:` prefix).\n * @param position - Optional source position of the component block.\n * @returns A Diagnostic with severity 'info' and code 'UNKNOWN_COMPONENT_TYPE'.\n */\nexport function createUnknownComponentInfo(\n componentType: string,\n position?: SourcePosition,\n): Diagnostic {\n return createDiagnostic(\n 'compiler',\n 'info',\n 'UNKNOWN_COMPONENT_TYPE',\n `Unknown component type \"ui:${componentType}\". Block preserved as-is.`,\n position,\n );\n}\n\n/**\n * Create a diagnostic for YAML parse errors on ui: blocks.\n *\n * @param componentType - The ui: component type whose YAML failed to parse (without the `ui:` prefix).\n * @param yamlError - The YAML parser error message.\n * @param position - Optional source position of the fenced code block.\n * @returns A Diagnostic with severity 'error' and code 'YAML_PARSE_ERROR'.\n */\nexport function createYamlError(\n componentType: string,\n yamlError: string,\n position?: SourcePosition,\n): Diagnostic {\n return createDiagnostic(\n 'parser',\n 'error',\n 'YAML_PARSE_ERROR',\n `YAML parse error in ui:${componentType}: ${yamlError}`,\n position,\n );\n}\n","import type {\n Block,\n BlockType,\n Diagnostic,\n GlyphUIBlock,\n MdastContentNode,\n SourcePosition,\n Reference,\n RawRef,\n ListData,\n ListItemData,\n InlineNode,\n} from '@glyphjs/types';\nimport { generateBlockId } from '@glyphjs/ir';\nimport { componentSchemas } from '@glyphjs/schemas';\nimport { convertPhrasingContent } from './inline.js';\nimport { createSchemaError, createUnknownComponentInfo, createYamlError } from './diagnostics.js';\n\n// ─── Default Source Position ─────────────────────────────────\n\nconst DEFAULT_POSITION: SourcePosition = {\n start: { line: 0, column: 0 },\n end: { line: 0, column: 0 },\n};\n\n// ─── Translation Context ────────────────────────────────────\n\nexport interface TranslationContext {\n documentId: string;\n diagnostics: Diagnostic[];\n references: Reference[];\n blockIdMap: Map<string, string>;\n}\n\n// ─── AST Node Type Guards ────────────────────────────────────\n\nfunction isGlyphUIBlock(node: GlyphUIBlock | MdastContentNode): node is GlyphUIBlock {\n return node.type === 'glyphUIBlock';\n}\n\n// ─── Main Translation Entry Point ────────────────────────────\n\n/**\n * Translate a single AST child node (either a GlyphUIBlock or a standard\n * MDAST content node) into an IR Block.\n *\n * Returns null for nodes that should be skipped (e.g., yaml frontmatter).\n *\n * @param node - The AST node to translate (GlyphUIBlock or standard MDAST content node).\n * @param ctx - Translation context carrying document ID, accumulated diagnostics, and references.\n * @returns The translated IR Block, or null if the node should be skipped.\n */\nexport function translateNode(\n node: GlyphUIBlock | MdastContentNode,\n ctx: TranslationContext,\n): Block | null {\n if (isGlyphUIBlock(node)) {\n return translateGlyphUIBlock(node, ctx);\n }\n return translateMdastNode(node, ctx);\n}\n\n// ─── Glyph UI Block Translation ─────────────────────────────\n\nfunction translateGlyphUIBlock(node: GlyphUIBlock, ctx: TranslationContext): Block {\n const componentType = node.componentType;\n const blockType: BlockType = `ui:${componentType}`;\n const position: SourcePosition = node.position ?? DEFAULT_POSITION;\n const blockDiagnostics: Diagnostic[] = [];\n\n // Determine block ID: user-assigned glyph-id or content-addressed\n const blockId = node.glyphId\n ? node.glyphId\n : generateBlockId(ctx.documentId, blockType, node.rawYaml);\n\n // Track the block ID mapping for reference resolution\n if (node.glyphId) {\n ctx.blockIdMap.set(node.glyphId, blockId);\n }\n\n // Handle YAML parse errors\n if (node.yamlError) {\n const diag = createYamlError(componentType, node.yamlError, position);\n blockDiagnostics.push(diag);\n ctx.diagnostics.push(diag);\n }\n\n // Determine block data\n let data: Record<string, unknown> = node.parsedData ?? {};\n\n // Validate against Zod schema if we have parsed data\n if (node.parsedData) {\n const schema = componentSchemas.get(componentType);\n if (schema) {\n const result = schema.safeParse(node.parsedData);\n if (!result.success) {\n const zodErrors = result.error.issues\n .map((issue) => `${issue.path.join('.')}: ${issue.message}`)\n .join('; ');\n const diag = createSchemaError(componentType, zodErrors, position, result.error.issues);\n blockDiagnostics.push(diag);\n ctx.diagnostics.push(diag);\n // Preserve the raw parsedData even on validation failure\n data = node.parsedData;\n } else {\n data = result.data as Record<string, unknown>;\n }\n } else {\n // Unknown component type — info diagnostic, preserve block as-is\n const diag = createUnknownComponentInfo(componentType, position);\n blockDiagnostics.push(diag);\n ctx.diagnostics.push(diag);\n }\n }\n\n // Process refs into references\n if (node.refs && node.refs.length > 0) {\n processRefs(node.refs, blockId, ctx);\n }\n\n const block: Block = {\n id: blockId,\n type: blockType,\n data,\n position,\n };\n\n if (node.interactive) {\n block.metadata = { interactive: true };\n }\n\n if (blockDiagnostics.length > 0) {\n block.diagnostics = blockDiagnostics;\n }\n\n return block;\n}\n\n// ─── Reference Processing ────────────────────────────────────\n\nfunction processRefs(refs: RawRef[], sourceBlockId: string, ctx: TranslationContext): void {\n for (const ref of refs) {\n const reference: Reference = {\n id: generateBlockId(ctx.documentId, 'ref', `${sourceBlockId}->${ref.target}`),\n type: (ref.type as Reference['type']) ?? 'navigates-to',\n sourceBlockId,\n targetBlockId: ref.target,\n };\n\n if (ref.label) {\n reference.label = ref.label;\n }\n if (ref.sourceAnchor) {\n reference.sourceAnchor = ref.sourceAnchor;\n }\n if (ref.targetAnchor) {\n reference.targetAnchor = ref.targetAnchor;\n }\n if (ref.bidirectional) {\n reference.bidirectional = ref.bidirectional;\n }\n\n // Mark as unresolved — we resolve later in the compile step\n reference.unresolved = true;\n\n ctx.references.push(reference);\n }\n}\n\n// ─── Standard MDAST Node Translation ─────────────────────────\n\nfunction translateMdastNode(node: MdastContentNode, ctx: TranslationContext): Block | null {\n const position: SourcePosition = node.position ?? DEFAULT_POSITION;\n\n switch (node.type) {\n case 'heading':\n return translateHeading(node, position, ctx);\n case 'paragraph':\n return translateParagraph(node, position, ctx);\n case 'list':\n return translateList(node, position, ctx);\n case 'code':\n return translateCode(node, position, ctx);\n case 'blockquote':\n return translateBlockquote(node, position, ctx);\n case 'image':\n return translateImage(node, position, ctx);\n case 'thematicBreak':\n return translateThematicBreak(position, ctx);\n case 'html':\n return translateHtml(node, position, ctx);\n case 'yaml':\n // Frontmatter is handled separately in compile.ts; skip here\n return null;\n default:\n // Unknown MDAST node type — skip silently\n return null;\n }\n}\n\n// ─── Individual Node Translators ─────────────────────────────\n\nfunction translateHeading(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const depth = (node['depth'] as number) ?? 1;\n const children = convertPhrasingContent((node.children ?? []) as unknown[]);\n const content = inlineNodesToText(children);\n\n return {\n id: generateBlockId(ctx.documentId, 'heading', content),\n type: 'heading',\n data: { depth, children },\n position,\n };\n}\n\nfunction translateParagraph(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const children = convertPhrasingContent((node.children ?? []) as unknown[]);\n const content = inlineNodesToText(children);\n\n return {\n id: generateBlockId(ctx.documentId, 'paragraph', content),\n type: 'paragraph',\n data: { children },\n position,\n };\n}\n\nfunction translateList(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const ordered = (node['ordered'] as boolean) ?? false;\n const start = ordered ? ((node['start'] as number) ?? 1) : undefined;\n const items = translateListItems((node.children ?? []) as MdastContentNode[]);\n const content = listDataToText({ ordered, start, items });\n\n const data: ListData = { ordered, items };\n if (start !== undefined) {\n data.start = start;\n }\n\n return {\n id: generateBlockId(ctx.documentId, 'list', content),\n type: 'list',\n data,\n position,\n };\n}\n\nfunction translateListItems(listItemNodes: MdastContentNode[]): ListItemData[] {\n const items: ListItemData[] = [];\n\n for (const itemNode of listItemNodes) {\n if (itemNode.type !== 'listItem') continue;\n\n const itemChildren = (itemNode.children ?? []) as MdastContentNode[];\n let inlineChildren: InlineNode[] = [];\n let subList: ListData | undefined;\n\n for (const child of itemChildren) {\n if (child.type === 'paragraph') {\n inlineChildren = convertPhrasingContent((child.children ?? []) as unknown[]);\n } else if (child.type === 'list') {\n const subOrdered = (child['ordered'] as boolean) ?? false;\n const subStart = subOrdered ? ((child['start'] as number) ?? 1) : undefined;\n const subItems = translateListItems((child.children ?? []) as MdastContentNode[]);\n subList = { ordered: subOrdered, items: subItems };\n if (subStart !== undefined) {\n subList.start = subStart;\n }\n }\n }\n\n const item: ListItemData = { children: inlineChildren };\n if (subList) {\n item.subList = subList;\n }\n items.push(item);\n }\n\n return items;\n}\n\nfunction translateCode(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const value = (node.value as string) ?? '';\n const language = (node['lang'] as string) ?? undefined;\n const meta = (node['meta'] as string) ?? undefined;\n\n const data: Record<string, unknown> = { value };\n if (language) {\n data['language'] = language;\n }\n if (meta) {\n data['meta'] = meta;\n }\n\n return {\n id: generateBlockId(ctx.documentId, 'code', value),\n type: 'code',\n data,\n position,\n };\n}\n\nfunction translateBlockquote(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n // Blockquote children are typically paragraphs — flatten their inline content\n const allInlineNodes: InlineNode[] = [];\n for (const child of (node.children ?? []) as MdastContentNode[]) {\n if (child.type === 'paragraph') {\n const inlines = convertPhrasingContent((child.children ?? []) as unknown[]);\n allInlineNodes.push(...inlines);\n }\n }\n const content = inlineNodesToText(allInlineNodes);\n\n return {\n id: generateBlockId(ctx.documentId, 'blockquote', content),\n type: 'blockquote',\n data: { children: allInlineNodes },\n position,\n };\n}\n\nfunction translateImage(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const src = (node['url'] as string) ?? '';\n const alt = (node['alt'] as string) ?? undefined;\n const title = (node['title'] as string) ?? undefined;\n\n const data: Record<string, unknown> = { src };\n if (alt) {\n data['alt'] = alt;\n }\n if (title) {\n data['title'] = title;\n }\n\n return {\n id: generateBlockId(ctx.documentId, 'image', src),\n type: 'image',\n data,\n position,\n };\n}\n\nfunction translateThematicBreak(position: SourcePosition, ctx: TranslationContext): Block {\n return {\n id: generateBlockId(ctx.documentId, 'thematic-break', '---'),\n type: 'thematic-break',\n data: {},\n position,\n };\n}\n\nfunction translateHtml(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const value = (node.value as string) ?? '';\n\n return {\n id: generateBlockId(ctx.documentId, 'html', value),\n type: 'html',\n data: { value },\n position,\n };\n}\n\n// ─── Text Extraction Helpers ─────────────────────────────────\n\n/**\n * Extract plain text from InlineNode[] for content-addressing purposes.\n */\nfunction inlineNodesToText(nodes: InlineNode[]): string {\n return nodes\n .map((node) => {\n switch (node.type) {\n case 'text':\n return node.value;\n case 'inlineCode':\n return node.value;\n case 'strong':\n case 'emphasis':\n case 'delete':\n return inlineNodesToText(node.children);\n case 'link':\n return inlineNodesToText(node.children);\n case 'image':\n return node.alt ?? '';\n case 'break':\n return '\\n';\n default:\n return '';\n }\n })\n .join('');\n}\n\n/**\n * Extract plain text from ListData for content-addressing purposes.\n */\nfunction listDataToText(data: ListData): string {\n return data.items\n .map((item) => {\n let text = inlineNodesToText(item.children);\n if (item.subList) {\n text += '\\n' + listDataToText(item.subList);\n }\n return text;\n })\n .join('\\n');\n}\n","import type {\n Block,\n Diagnostic,\n InlineNode,\n Reference,\n} from '@glyphjs/types';\nimport { generateBlockId } from '@glyphjs/ir';\nimport { createDiagnostic } from './diagnostics.js';\n\n// ─── Glyph Link Pattern ─────────────────────────────────────\n\n/**\n * Matches inline links of the form `[text](#glyph:block-id)`.\n * The captured group is the block ID after the `#glyph:` prefix.\n */\nconst GLYPH_LINK_PREFIX = '#glyph:';\n\n// ─── Inline Reference Scanning ──────────────────────────────\n\n/**\n * Scan a block's inline content for `[text](#glyph:block-id)` links\n * and create Reference objects for each match.\n *\n * @param block - The block whose inline data fields are scanned for glyph links.\n * @param documentId - Document ID used to generate deterministic reference IDs.\n * @returns Newly created (unresolved) Reference objects.\n */\nexport function extractInlineReferences(\n block: Block,\n documentId: string,\n): Reference[] {\n const references: Reference[] = [];\n const inlineNodes = extractInlineNodes(block);\n\n for (const node of inlineNodes) {\n if (node.type === 'link' && node.url.startsWith(GLYPH_LINK_PREFIX)) {\n const targetBlockId = node.url.slice(GLYPH_LINK_PREFIX.length);\n if (!targetBlockId) continue;\n\n const label = inlineNodesToPlainText(node.children);\n\n const reference: Reference = {\n id: generateBlockId(documentId, 'ref', `${block.id}->${targetBlockId}`),\n type: 'navigates-to',\n sourceBlockId: block.id,\n targetBlockId,\n unresolved: true,\n };\n\n if (label) {\n reference.label = label;\n }\n\n references.push(reference);\n }\n }\n\n return references;\n}\n\n/**\n * Scan all blocks (including nested children) for inline `#glyph:` link references\n * and collect them.\n *\n * @param blocks - Top-level block array to scan recursively.\n * @param documentId - Document ID used to generate deterministic reference IDs.\n * @returns Aggregated array of unresolved Reference objects from all blocks.\n */\nexport function extractAllInlineReferences(\n blocks: Block[],\n documentId: string,\n): Reference[] {\n const references: Reference[] = [];\n\n for (const block of blocks) {\n const blockRefs = extractInlineReferences(block, documentId);\n references.push(...blockRefs);\n\n // Also scan children (e.g. container blocks)\n if (block.children) {\n const childRefs = extractAllInlineReferences(block.children, documentId);\n references.push(...childRefs);\n }\n }\n\n return references;\n}\n\n// ─── Reference Resolution ────────────────────────────────────\n\n/**\n * Resolve references by checking if target block IDs exist in the document.\n * Marks unresolved references and adds warning diagnostics.\n *\n * Collects all block IDs including children (for container blocks).\n *\n * @param references - The reference array to resolve in-place (mutates `unresolved` flag).\n * @param blocks - All blocks in the document (used to build the known-ID set).\n * @param diagnostics - Accumulator for 'UNRESOLVED_REFERENCE' warnings.\n */\nexport function resolveReferences(\n references: Reference[],\n blocks: Block[],\n diagnostics: Diagnostic[],\n): void {\n const blockIdSet = collectAllBlockIds(blocks);\n\n for (const ref of references) {\n if (blockIdSet.has(ref.targetBlockId)) {\n ref.unresolved = false;\n } else {\n ref.unresolved = true;\n diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'warning',\n 'UNRESOLVED_REFERENCE',\n `Reference target \"${ref.targetBlockId}\" was not found in the document.`,\n ),\n );\n }\n }\n}\n\n/**\n * Collect all block IDs from blocks and their children recursively.\n */\nfunction collectAllBlockIds(blocks: Block[]): Set<string> {\n const ids = new Set<string>();\n for (const block of blocks) {\n ids.add(block.id);\n if (block.children) {\n for (const id of collectAllBlockIds(block.children)) {\n ids.add(id);\n }\n }\n }\n return ids;\n}\n\n// ─── Glyph-ID Uniqueness Validation ─────────────────────────\n\n/**\n * Validate that all user-assigned glyph-ids are unique within the document.\n * Emits error diagnostics for duplicates.\n *\n * @param blockIdMap - Map of user-assigned glyph-id to resolved block ID (from translation).\n * @param blocks - All blocks in the document (scanned to count occurrences).\n * @param diagnostics - Accumulator for 'DUPLICATE_GLYPH_ID' error diagnostics.\n */\nexport function validateGlyphIdUniqueness(\n blockIdMap: Map<string, string>,\n blocks: Block[],\n diagnostics: Diagnostic[],\n): void {\n // blockIdMap tracks glyphId -> blockId, but we need to detect duplicates\n // by scanning blocks for those whose id matches a glyph-id key\n const glyphIdOccurrences = new Map<string, number>();\n\n for (const glyphId of blockIdMap.keys()) {\n const count = countBlocksWithGlyphId(blocks, glyphId);\n glyphIdOccurrences.set(glyphId, count);\n }\n\n for (const [glyphId, count] of glyphIdOccurrences) {\n if (count > 1) {\n diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'error',\n 'DUPLICATE_GLYPH_ID',\n `Duplicate glyph-id \"${glyphId}\" found on ${String(count)} blocks. Block IDs must be unique within a document.`,\n ),\n );\n }\n }\n}\n\n/**\n * Count how many blocks in the array have a given ID (which came from a glyph-id).\n */\nfunction countBlocksWithGlyphId(blocks: Block[], glyphId: string): number {\n let count = 0;\n for (const block of blocks) {\n if (block.id === glyphId) {\n count++;\n }\n }\n return count;\n}\n\n// ─── Inline Node Extraction Helpers ──────────────────────────\n\n/**\n * Extract all InlineNode arrays from a block's data field.\n * Handles heading, paragraph, blockquote, and list blocks.\n */\nfunction extractInlineNodes(block: Block): InlineNode[] {\n const data = block.data as Record<string, unknown>;\n const nodes: InlineNode[] = [];\n\n // Blocks with a direct `children` inline array\n if (Array.isArray(data['children'])) {\n nodes.push(...(data['children'] as InlineNode[]));\n }\n\n // List blocks: extract inline nodes from items\n if (Array.isArray(data['items'])) {\n for (const item of data['items'] as { children?: InlineNode[]; subList?: { items?: unknown[] } }[]) {\n if (Array.isArray(item.children)) {\n nodes.push(...item.children);\n }\n }\n }\n\n return nodes;\n}\n\n/**\n * Extract plain text from InlineNode[] for label purposes.\n */\nfunction inlineNodesToPlainText(nodes: InlineNode[]): string {\n return nodes\n .map((node) => {\n switch (node.type) {\n case 'text':\n return node.value;\n case 'inlineCode':\n return node.value;\n case 'strong':\n case 'emphasis':\n case 'delete':\n return inlineNodesToPlainText(node.children);\n case 'link':\n return inlineNodesToPlainText(node.children);\n case 'image':\n return node.alt ?? '';\n case 'break':\n return '\\n';\n default:\n return '';\n }\n })\n .join('');\n}\n","import type { Block, Diagnostic } from '@glyphjs/types';\nimport { parseGlyphMarkdown } from '@glyphjs/parser';\nimport { translateNode } from './ast-to-ir.js';\nimport type { TranslationContext } from './ast-to-ir.js';\nimport { createDiagnostic } from './diagnostics.js';\n\n// ─── Container Block Compilation ─────────────────────────────\n\n/**\n * Process container blocks (ui:tabs and ui:steps) by recursively parsing\n * their content fields as Markdown into child Block[] arrays.\n *\n * This function mutates blocks in-place, populating their `children` field\n * and updating data entries with parsed child blocks.\n *\n * @param blocks - The top-level block array to scan for container blocks.\n * @param ctx - Translation context used for recursive compilation.\n */\nexport function compileContainerBlocks(\n blocks: Block[],\n ctx: TranslationContext,\n): void {\n for (const block of blocks) {\n if (block.type === 'ui:tabs') {\n compileTabsBlock(block, ctx);\n } else if (block.type === 'ui:steps') {\n compileStepsBlock(block, ctx);\n }\n }\n}\n\n// ─── Tabs Compilation ────────────────────────────────────────\n\nfunction compileTabsBlock(block: Block, ctx: TranslationContext): void {\n const data = block.data as Record<string, unknown>;\n const tabs = data['tabs'];\n\n if (!Array.isArray(tabs)) return;\n\n const allChildren: Block[] = [];\n\n for (const tab of tabs as { label?: string; content?: string }[]) {\n if (typeof tab.content !== 'string') continue;\n\n const childBlocks = parseContentToBlocks(tab.content, block, ctx);\n allChildren.push(...childBlocks);\n }\n\n if (allChildren.length > 0) {\n block.children = allChildren;\n }\n}\n\n// ─── Steps Compilation ───────────────────────────────────────\n\nfunction compileStepsBlock(block: Block, ctx: TranslationContext): void {\n const data = block.data as Record<string, unknown>;\n const steps = data['steps'];\n\n if (!Array.isArray(steps)) return;\n\n const allChildren: Block[] = [];\n\n for (const step of steps as { title?: string; status?: string; content?: string }[]) {\n if (typeof step.content !== 'string') continue;\n\n const childBlocks = parseContentToBlocks(step.content, block, ctx);\n allChildren.push(...childBlocks);\n }\n\n if (allChildren.length > 0) {\n block.children = allChildren;\n }\n}\n\n// ─── Content Parsing Helper ──────────────────────────────────\n\n/**\n * Parse a Markdown content string into Block[] using the compiler pipeline.\n * Emits a warning diagnostic if nested ui: components are found (deferred to v2).\n */\nfunction parseContentToBlocks(\n content: string,\n parentBlock: Block,\n ctx: TranslationContext,\n): Block[] {\n const ast = parseGlyphMarkdown(content);\n const blocks: Block[] = [];\n\n for (const child of ast.children) {\n // Check for nested ui: components — warn and skip\n if (child.type === 'glyphUIBlock') {\n ctx.diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'warning',\n 'NESTED_UI_COMPONENT',\n `Nested ui: component found inside container block \"${parentBlock.id}\". ` +\n `Nested ui: components inside tabs/steps are not supported in v1 and will be ignored.`,\n child.position,\n ),\n );\n continue;\n }\n\n const block = translateNode(child, ctx);\n if (block) {\n blocks.push(block);\n }\n }\n\n return blocks;\n}\n\n// ─── Nested UI Detection ─────────────────────────────────────\n\n/**\n * Check if content contains nested ui: blocks by looking for the pattern.\n * This is a quick heuristic check. The actual detection happens during parsing.\n *\n * @param content - Raw Markdown string to test for nested ui: fenced blocks.\n * @returns True if the content matches the `` ```ui: `` pattern.\n */\nexport function hasNestedUiBlocks(content: string): boolean {\n return /```ui:/m.test(content);\n}\n\n// ─── Validate Container Diagnostics ──────────────────────────\n\n/**\n * Post-process container blocks to ensure data consistency.\n * Called after container compilation is complete.\n *\n * @param blocks - The compiled block array to validate.\n * @param diagnostics - Accumulator for warning diagnostics (e.g., missing labels/titles).\n */\nexport function validateContainerBlocks(\n blocks: Block[],\n diagnostics: Diagnostic[],\n): void {\n for (const block of blocks) {\n if (block.type === 'ui:tabs') {\n validateTabsData(block, diagnostics);\n } else if (block.type === 'ui:steps') {\n validateStepsData(block, diagnostics);\n }\n }\n}\n\nfunction validateTabsData(block: Block, _diagnostics: Diagnostic[]): void {\n const data = block.data as Record<string, unknown>;\n const tabs = data['tabs'];\n\n if (!Array.isArray(tabs) || tabs.length === 0) {\n return;\n }\n\n // Ensure each tab has a label\n for (const tab of tabs as { label?: string }[]) {\n if (!tab.label) {\n _diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'warning',\n 'MISSING_TAB_LABEL',\n `A tab in block \"${block.id}\" is missing a label.`,\n block.position,\n ),\n );\n }\n }\n}\n\nfunction validateStepsData(block: Block, _diagnostics: Diagnostic[]): void {\n const data = block.data as Record<string, unknown>;\n const steps = data['steps'];\n\n if (!Array.isArray(steps) || steps.length === 0) {\n return;\n }\n\n // Ensure each step has a title\n for (const step of steps as { title?: string }[]) {\n if (!step.title) {\n _diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'warning',\n 'MISSING_STEP_TITLE',\n `A step in block \"${block.id}\" is missing a title.`,\n block.position,\n ),\n );\n }\n }\n}\n","import type {\n GlyphIR,\n CompilationResult,\n Diagnostic,\n DocumentMetadata,\n LayoutHints,\n Block,\n Reference,\n MdastContentNode,\n} from '@glyphjs/types';\nimport { parseGlyphMarkdown } from '@glyphjs/parser';\nimport { generateDocumentId, resolveBlockIdCollisions } from '@glyphjs/ir';\nimport { parse as parseYaml } from 'yaml';\nimport { translateNode } from './ast-to-ir.js';\nimport type { TranslationContext } from './ast-to-ir.js';\nimport { createDiagnostic } from './diagnostics.js';\nimport {\n extractAllInlineReferences,\n resolveReferences,\n validateGlyphIdUniqueness,\n} from './references.js';\nimport { compileContainerBlocks, validateContainerBlocks } from './containers.js';\n\n// ─── Public Interface ────────────────────────────────────────\n\nexport interface CompileOptions {\n /** Source file path, used for document ID generation. */\n filePath?: string;\n /** Explicit document ID override. */\n documentId?: string;\n}\n\n// ─── Main Compile Function ───────────────────────────────────\n\n/**\n * Compile a Markdown string into Glyph IR.\n *\n * Steps:\n * 1. Parse the markdown via `parseGlyphMarkdown`\n * 2. Extract frontmatter metadata and layout hints\n * 3. Walk the AST and translate each node to IR blocks\n * 4. Validate ui: blocks against Zod schemas\n * 5. Compile container blocks (ui:tabs, ui:steps) — recursively parse content\n * 6. Validate container block data\n * 7. Generate content-addressed block IDs\n * 8. Generate the document ID\n * 9. Resolve block ID collisions\n * 10. Validate glyph-id uniqueness\n * 11. Extract inline references from `[text](#glyph:block-id)` links\n * 12. Resolve all references (from refs arrays and inline links)\n * 13. Infer metadata from content if not in frontmatter\n * 14. Return CompilationResult with IR, diagnostics, and hasErrors flag\n *\n * Uses a collect-all-errors strategy: IR is always produced, even when errors exist.\n */\nexport function compile(markdown: string, options?: CompileOptions): CompilationResult {\n const diagnostics: Diagnostic[] = [];\n\n // 1. Parse the markdown into a Glyph AST\n const ast = parseGlyphMarkdown(markdown);\n\n // 2. Extract frontmatter\n const { metadata, layout, frontmatterGlyphId } = extractFrontmatter(ast.children, diagnostics);\n\n // 3. Generate document ID\n const documentId =\n options?.documentId ??\n generateDocumentId({\n glyphId: frontmatterGlyphId,\n filePath: options?.filePath,\n content: markdown,\n });\n\n // Set sourceFile from options if available\n if (options?.filePath && !metadata.sourceFile) {\n metadata.sourceFile = options.filePath;\n }\n\n // 4. Create translation context\n const references: Reference[] = [];\n const ctx: TranslationContext = {\n documentId,\n diagnostics,\n references,\n blockIdMap: new Map(),\n };\n\n // 5. Walk the AST and translate nodes\n const blocks: Block[] = [];\n for (const child of ast.children) {\n const block = translateNode(child, ctx);\n if (block) {\n blocks.push(block);\n }\n }\n\n // 6. Compile container blocks (ui:tabs, ui:steps) — recursively parse content fields\n compileContainerBlocks(blocks, ctx);\n\n // 7. Validate container block data\n validateContainerBlocks(blocks, diagnostics);\n\n // 8. Infer metadata from content if not in frontmatter\n inferMetadata(metadata, blocks);\n\n // 9. Resolve block ID collisions\n const blockIds = blocks.map((b) => b.id);\n const resolvedIds = resolveBlockIdCollisions(blockIds);\n for (let i = 0; i < blocks.length; i++) {\n const block = blocks[i];\n const resolvedId = resolvedIds[i];\n if (block && resolvedId) {\n block.id = resolvedId;\n }\n }\n\n // 10. Validate glyph-id uniqueness\n validateGlyphIdUniqueness(ctx.blockIdMap, blocks, diagnostics);\n\n // 11. Extract inline references from [text](#glyph:block-id) links\n const inlineRefs = extractAllInlineReferences(blocks, documentId);\n references.push(...inlineRefs);\n\n // 12. Resolve all references (from refs arrays and inline links)\n resolveReferences(references, blocks, diagnostics);\n\n // 13. Build the IR\n const ir: GlyphIR = {\n version: '1.0.0',\n id: documentId,\n metadata,\n blocks,\n references,\n layout,\n };\n\n const hasErrors = diagnostics.some((d) => d.severity === 'error');\n\n return { ir, diagnostics, hasErrors };\n}\n\n// ─── Frontmatter Extraction ─────────────────────────────────\n\ninterface FrontmatterResult {\n metadata: DocumentMetadata;\n layout: LayoutHints;\n frontmatterGlyphId?: string;\n}\n\nfunction extractFrontmatter(\n children: readonly unknown[],\n diagnostics: Diagnostic[],\n): FrontmatterResult {\n const metadata: DocumentMetadata = {};\n let layout: LayoutHints = { mode: 'document', spacing: 'normal' };\n let frontmatterGlyphId: string | undefined;\n\n // Look for yaml frontmatter node (always first child if present)\n const firstChild = children[0] as MdastContentNode | undefined;\n if (firstChild && firstChild.type === 'yaml' && typeof firstChild.value === 'string') {\n try {\n const parsed: unknown = parseYaml(firstChild.value);\n if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {\n const fm = parsed as Record<string, unknown>;\n\n // Extract glyph-id\n if (typeof fm['glyph-id'] === 'string') {\n frontmatterGlyphId = fm['glyph-id'];\n }\n\n // Extract metadata fields\n if (typeof fm['title'] === 'string') {\n metadata.title = fm['title'];\n }\n if (typeof fm['description'] === 'string') {\n metadata.description = fm['description'];\n }\n if (Array.isArray(fm['authors'])) {\n metadata.authors = fm['authors'].filter(\n (a): a is string => typeof a === 'string',\n );\n }\n if (typeof fm['createdAt'] === 'string') {\n metadata.createdAt = fm['createdAt'];\n }\n if (Array.isArray(fm['tags'])) {\n metadata.tags = fm['tags'].filter(\n (t): t is string => typeof t === 'string',\n );\n }\n\n // Extract layout hints\n if (fm['layout'] && typeof fm['layout'] === 'object' && !Array.isArray(fm['layout'])) {\n const rawLayout = fm['layout'] as Record<string, unknown>;\n layout = {\n mode: isLayoutMode(rawLayout['mode']) ? rawLayout['mode'] : 'document',\n spacing: isLayoutSpacing(rawLayout['spacing']) ? rawLayout['spacing'] : 'normal',\n };\n if (typeof rawLayout['columns'] === 'number') {\n layout.columns = rawLayout['columns'];\n }\n if (typeof rawLayout['maxWidth'] === 'string') {\n layout.maxWidth = rawLayout['maxWidth'];\n }\n }\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : String(err);\n diagnostics.push(\n createDiagnostic(\n 'parser',\n 'error',\n 'FRONTMATTER_PARSE_ERROR',\n `Failed to parse frontmatter YAML: ${message}`,\n firstChild.position,\n ),\n );\n }\n }\n\n return { metadata, layout, frontmatterGlyphId };\n}\n\nfunction isLayoutMode(value: unknown): value is LayoutHints['mode'] {\n return value === 'document' || value === 'dashboard' || value === 'presentation';\n}\n\nfunction isLayoutSpacing(value: unknown): value is 'compact' | 'normal' | 'relaxed' {\n return value === 'compact' || value === 'normal' || value === 'relaxed';\n}\n\n// ─── Metadata Inference ──────────────────────────────────────\n\n/**\n * Infer metadata from content when not provided via frontmatter.\n * - title: from the first h1 heading\n * - description: from the first paragraph\n */\nfunction inferMetadata(metadata: DocumentMetadata, blocks: Block[]): void {\n if (!metadata.title) {\n const firstHeading = blocks.find(\n (b) => b.type === 'heading' && (b.data as Record<string, unknown>)['depth'] === 1,\n );\n if (firstHeading) {\n const data = firstHeading.data as { children?: { type: string; value?: string }[] };\n if (data.children) {\n metadata.title = data.children\n .map((node) => {\n if ('value' in node && typeof node.value === 'string') {\n return node.value;\n }\n return '';\n })\n .join('');\n }\n }\n }\n\n if (!metadata.description) {\n const firstParagraph = blocks.find((b) => b.type === 'paragraph');\n if (firstParagraph) {\n const data = firstParagraph.data as { children?: { type: string; value?: string }[] };\n if (data.children) {\n metadata.description = data.children\n .map((node) => {\n if ('value' in node && typeof node.value === 'string') {\n return node.value;\n }\n return '';\n })\n .join('');\n }\n }\n }\n}\n\n"]}
1
+ {"version":3,"sources":["../src/inline.ts","../src/diagnostics.ts","../src/ast-to-ir.ts","../src/references.ts","../src/containers.ts","../src/compile.ts"],"names":["unified","remarkParse","generateBlockId","componentSchemas","parseGlyphMarkdown","generateDocumentId","resolveBlockIdCollisions","ir","parseYaml"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AAO,IAAA,CAAK,UAAU,QAAA,EAAU;AACrD,YAAA,OAAO,IAAA,CAAK,KAAA;AAAA,UACd;AACA,UAAA,OAAO,EAAA;AAAA,QACT,CAAC,CAAA,CACA,IAAA,CAAK,EAAE,CAAA;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["import type { InlineNode } from '@glyphjs/types';\nimport type { Diagnostic } from '@glyphjs/types';\nimport { unified } from 'unified';\nimport remarkParse from 'remark-parse';\n\n// ─── MDAST Phrasing Content Types ───────────────────────────\n// These are structural types matching the shapes from mdast,\n// avoiding a hard dependency on @types/mdast.\n\ninterface MdastText {\n type: 'text';\n value: string;\n}\n\ninterface MdastStrong {\n type: 'strong';\n children: MdastPhrasingContent[];\n}\n\ninterface MdastEmphasis {\n type: 'emphasis';\n children: MdastPhrasingContent[];\n}\n\ninterface MdastDelete {\n type: 'delete';\n children: MdastPhrasingContent[];\n}\n\ninterface MdastInlineCode {\n type: 'inlineCode';\n value: string;\n}\n\ninterface MdastLink {\n type: 'link';\n url: string;\n title?: string | null;\n children: MdastPhrasingContent[];\n}\n\ninterface MdastImage {\n type: 'image';\n url: string;\n alt?: string | null;\n title?: string | null;\n}\n\ninterface MdastBreak {\n type: 'break';\n}\n\ntype MdastPhrasingContent =\n | MdastText\n | MdastStrong\n | MdastEmphasis\n | MdastDelete\n | MdastInlineCode\n | MdastLink\n | MdastImage\n | MdastBreak;\n\n// ─── Conversion ─────────────────────────────────────────────\n\n/**\n * Convert an array of MDAST phrasing content nodes to InlineNode[].\n *\n * Unknown node types are converted to text nodes with their string value\n * (if present) or skipped entirely.\n *\n * @param nodes - Raw MDAST phrasing content nodes (typed as unknown[] to avoid a hard @types/mdast dependency).\n * @returns Normalized InlineNode array suitable for inclusion in IR blocks.\n */\nexport function convertPhrasingContent(nodes: unknown[]): InlineNode[] {\n const result: InlineNode[] = [];\n\n for (const node of nodes) {\n const converted = convertSingleNode(node as MdastPhrasingContent);\n if (converted) {\n result.push(converted);\n }\n }\n\n return result;\n}\n\nfunction convertSingleNode(node: MdastPhrasingContent): InlineNode | null {\n switch (node.type) {\n case 'text':\n return { type: 'text', value: node.value };\n\n case 'strong':\n return {\n type: 'strong',\n children: convertPhrasingContent(node.children),\n };\n\n case 'emphasis':\n return {\n type: 'emphasis',\n children: convertPhrasingContent(node.children),\n };\n\n case 'delete':\n return {\n type: 'delete',\n children: convertPhrasingContent(node.children),\n };\n\n case 'inlineCode':\n return { type: 'inlineCode', value: node.value };\n\n case 'link': {\n const linkNode: InlineNode = {\n type: 'link',\n url: node.url,\n children: convertPhrasingContent(node.children),\n };\n if (node.title != null) {\n (linkNode as { type: 'link'; url: string; title?: string; children: InlineNode[] }).title =\n node.title;\n }\n return linkNode;\n }\n\n case 'image': {\n const imgNode: InlineNode = {\n type: 'image',\n src: node.url,\n };\n if (node.alt != null) {\n (imgNode as { type: 'image'; src: string; alt?: string; title?: string }).alt = node.alt;\n }\n if (node.title != null) {\n (imgNode as { type: 'image'; src: string; alt?: string; title?: string }).title =\n node.title;\n }\n return imgNode;\n }\n\n case 'break':\n return { type: 'break' };\n\n default: {\n // For unknown phrasing content types, attempt to extract a text value\n const unknown = node as Record<string, unknown>;\n if (typeof unknown['value'] === 'string') {\n return { type: 'text', value: unknown['value'] };\n }\n return null;\n }\n }\n}\n\n// ─── Markdown String Parser ─────────────────────────────────────\n\n/**\n * Parse a string containing inline markdown into InlineNode[].\n *\n * Uses remark-parse to parse the text, extracts phrasing content from\n * the first paragraph. Only supports inline elements (bold, italic, links, code).\n * Block elements trigger diagnostic warnings.\n *\n * Edge cases:\n * - Empty string → `[]`\n * - Plain text → `[{ type: 'text', value: text }]`\n * - Block elements (headings, lists) → diagnostic warning, extract text only\n *\n * @param text - Markdown string to parse\n * @param diagnostics - Optional array to collect warnings (e.g., for block elements)\n * @returns Array of InlineNode elements\n */\nexport function parseInlineMarkdown(text: string, diagnostics?: Diagnostic[]): InlineNode[] {\n // Handle empty string\n if (text.trim() === '') {\n return [];\n }\n\n // Parse markdown using unified + remark-parse\n const processor = unified().use(remarkParse);\n const tree = processor.parse(text);\n\n // Type guard for MDAST root node\n interface MdastRoot {\n type: 'root';\n children: { type: string; children?: unknown[] }[];\n }\n\n const root = tree as unknown as MdastRoot;\n\n if (!root.children || root.children.length === 0) {\n // No content parsed\n return [{ type: 'text', value: text }];\n }\n\n // Check for block-level elements (not just paragraph)\n const hasBlockElements = root.children.some(\n (child) =>\n child.type !== 'paragraph' &&\n child.type !== 'text' &&\n !['strong', 'emphasis', 'delete', 'inlineCode', 'link', 'image', 'break'].includes(\n child.type,\n ),\n );\n\n if (hasBlockElements && diagnostics) {\n diagnostics.push({\n severity: 'warning',\n code: 'INLINE_BLOCK_ELEMENTS',\n message:\n 'Block-level markdown elements (headings, lists, etc.) are not supported in inline text fields. Only inline formatting (bold, italic, links, code) will be preserved.',\n source: 'compiler',\n });\n }\n\n // Extract first paragraph's children, or fall back to all inline children\n const firstParagraph = root.children.find((child) => child.type === 'paragraph');\n\n if (firstParagraph && firstParagraph.children) {\n return convertPhrasingContent(firstParagraph.children);\n }\n\n // If no paragraph found but we have inline-only children, convert them\n const inlineChildren = root.children.filter((child) =>\n ['text', 'strong', 'emphasis', 'delete', 'inlineCode', 'link', 'image', 'break'].includes(\n child.type,\n ),\n );\n\n if (inlineChildren.length > 0) {\n return convertPhrasingContent(inlineChildren);\n }\n\n // Fallback: return plain text\n return [{ type: 'text', value: text }];\n}\n","import type { Diagnostic, DiagnosticSource, SourcePosition } from '@glyphjs/types';\n\n// ─── Diagnostic Creation Helpers ─────────────────────────────\n\n/**\n * Create a diagnostic with the given source, severity, message, and optional position.\n *\n * @param source - The subsystem that produced the diagnostic (e.g., 'compiler', 'parser', 'schema').\n * @param severity - Severity level: 'error', 'warning', or 'info'.\n * @param code - Machine-readable diagnostic code (e.g., 'YAML_PARSE_ERROR').\n * @param message - Human-readable description of the issue.\n * @param position - Optional source position where the issue was detected.\n * @param details - Optional structured details (e.g., Zod issue objects).\n * @returns A fully constructed Diagnostic object.\n */\nexport function createDiagnostic(\n source: DiagnosticSource,\n severity: Diagnostic['severity'],\n code: string,\n message: string,\n position?: SourcePosition,\n details?: unknown,\n): Diagnostic {\n const diag: Diagnostic = { severity, code, message, source };\n if (position) {\n diag.position = position;\n }\n if (details !== undefined) {\n diag.details = details;\n }\n return diag;\n}\n\n/**\n * Create a schema validation error diagnostic.\n *\n * @param componentType - The ui: component type that failed validation (without the `ui:` prefix).\n * @param message - Concatenated validation error messages from Zod.\n * @param position - Optional source position of the component block.\n * @param details - Optional raw Zod issue objects.\n * @returns A Diagnostic with severity 'error' and code 'SCHEMA_VALIDATION_FAILED'.\n */\nexport function createSchemaError(\n componentType: string,\n message: string,\n position?: SourcePosition,\n details?: unknown,\n): Diagnostic {\n return createDiagnostic(\n 'schema',\n 'error',\n 'SCHEMA_VALIDATION_FAILED',\n `Schema validation failed for ui:${componentType}: ${message}`,\n position,\n details,\n );\n}\n\n/**\n * Create an info diagnostic for unknown component types.\n *\n * @param componentType - The unrecognized component type (without the `ui:` prefix).\n * @param position - Optional source position of the component block.\n * @returns A Diagnostic with severity 'info' and code 'UNKNOWN_COMPONENT_TYPE'.\n */\nexport function createUnknownComponentInfo(\n componentType: string,\n position?: SourcePosition,\n): Diagnostic {\n return createDiagnostic(\n 'compiler',\n 'info',\n 'UNKNOWN_COMPONENT_TYPE',\n `Unknown component type \"ui:${componentType}\". Block preserved as-is.`,\n position,\n );\n}\n\n/**\n * Create a diagnostic for YAML parse errors on ui: blocks.\n *\n * @param componentType - The ui: component type whose YAML failed to parse (without the `ui:` prefix).\n * @param yamlError - The YAML parser error message.\n * @param position - Optional source position of the fenced code block.\n * @returns A Diagnostic with severity 'error' and code 'YAML_PARSE_ERROR'.\n */\nexport function createYamlError(\n componentType: string,\n yamlError: string,\n position?: SourcePosition,\n): Diagnostic {\n return createDiagnostic(\n 'parser',\n 'error',\n 'YAML_PARSE_ERROR',\n `YAML parse error in ui:${componentType}: ${yamlError}`,\n position,\n );\n}\n","import type {\n Block,\n BlockType,\n Diagnostic,\n GlyphUIBlock,\n MdastContentNode,\n SourcePosition,\n Reference,\n RawRef,\n ListData,\n ListItemData,\n InlineNode,\n} from '@glyphjs/types';\nimport { generateBlockId } from '@glyphjs/ir';\nimport { componentSchemas } from '@glyphjs/schemas';\nimport { convertPhrasingContent, parseInlineMarkdown } from './inline.js';\nimport { createSchemaError, createUnknownComponentInfo, createYamlError } from './diagnostics.js';\nimport type { CompileOptions } from './compile.js';\n\n// ─── Default Source Position ─────────────────────────────────\n\nconst DEFAULT_POSITION: SourcePosition = {\n start: { line: 0, column: 0 },\n end: { line: 0, column: 0 },\n};\n\n// ─── Translation Context ────────────────────────────────────\n\nexport interface TranslationContext {\n documentId: string;\n diagnostics: Diagnostic[];\n references: Reference[];\n blockIdMap: Map<string, string>;\n compileOptions: CompileOptions;\n}\n\n// ─── AST Node Type Guards ────────────────────────────────────\n\nfunction isGlyphUIBlock(node: GlyphUIBlock | MdastContentNode): node is GlyphUIBlock {\n return node.type === 'glyphUIBlock';\n}\n\n// ─── Markdown Field Processing ──────────────────────────────\n\n/**\n * Field mapping table: defines which component text fields support markdown.\n * Format: componentType -> array of field paths (supports nested paths like \"items[].text\")\n */\nconst MARKDOWN_FIELD_MAP: Record<string, string[]> = {\n callout: ['content', 'title'],\n card: ['cards[].body', 'cards[].subtitle'],\n accordion: ['sections[].content'],\n steps: ['steps[].content'],\n kpi: ['metrics[].label'],\n comparison: ['options[].description', 'features[].values[]'],\n quiz: ['questions[].question', 'questions[].explanation', 'questions[].options[]'],\n infographic: ['sections[].items[].text', 'sections[].items[].description'],\n timeline: ['events[].title', 'events[].description'],\n poll: ['question', 'options[].label'],\n rating: ['label', 'description'],\n ranker: ['items[].label'],\n slider: ['label'],\n matrix: ['rowLabels[]', 'columnLabels[]'],\n annotate: ['annotations[].text'],\n form: ['description'],\n};\n\n/**\n * Process component data to parse markdown text fields into InlineNode[].\n * Checks if markdown is enabled (component-level flag OR global option).\n * Recursively processes nested objects and arrays based on field mapping.\n *\n * @param componentType - Component type (without \"ui:\" prefix)\n * @param data - Component data object\n * @param ctx - Translation context with compiler options and diagnostics\n * @returns Processed data with markdown fields converted to InlineNode[]\n */\nfunction processMarkdownFields(\n componentType: string,\n data: Record<string, unknown>,\n ctx: TranslationContext,\n): Record<string, unknown> {\n // Check if markdown is enabled (component-level flag OR global option)\n const markdownEnabled =\n (data.markdown as boolean) === true || ctx.compileOptions.parseComponentMarkdown === true;\n\n if (!markdownEnabled) {\n return data;\n }\n\n // Get field paths for this component type\n const fieldPaths = MARKDOWN_FIELD_MAP[componentType];\n if (!fieldPaths || fieldPaths.length === 0) {\n return data;\n }\n\n // Clone data to avoid mutations\n const result = { ...data };\n\n // Process each field path\n for (const path of fieldPaths) {\n processFieldPath(result, path, ctx.diagnostics);\n }\n\n return result;\n\n /**\n * Recursively process a field path (e.g., \"items[].text\" or \"question\")\n */\n function processFieldPath(\n obj: Record<string, unknown>,\n path: string,\n diagnostics: Diagnostic[],\n ): void {\n // Split path into segments (e.g., \"items[].text\" -> [\"items[]\", \"text\"])\n const segments = path.split('.');\n processSegments(obj, segments, diagnostics);\n }\n\n /**\n * Process path segments recursively\n */\n function processSegments(\n obj: Record<string, unknown>,\n segments: string[],\n diagnostics: Diagnostic[],\n ): void {\n if (segments.length === 0) return;\n\n const [first, ...rest] = segments;\n\n // Type guard: first must be defined\n if (!first) return;\n\n // Check if segment is array notation (e.g., \"items[]\")\n if (first.endsWith('[]')) {\n const fieldName = first.slice(0, -2);\n const value = obj[fieldName];\n\n if (Array.isArray(value)) {\n if (rest.length === 0) {\n // This array contains strings to process directly\n // This case handles paths like \"options[]\" where the array elements are strings\n obj[fieldName] = value.map((item) => {\n if (typeof item === 'string') {\n return parseInlineMarkdown(item, diagnostics);\n }\n return item;\n });\n } else {\n // Array contains objects, process nested fields\n for (const item of value) {\n if (typeof item === 'object' && item !== null) {\n processSegments(item as Record<string, unknown>, rest, diagnostics);\n }\n }\n }\n }\n } else {\n // Regular field\n if (rest.length === 0) {\n // Leaf node - process the string field\n const value = obj[first];\n if (typeof value === 'string') {\n obj[first] = parseInlineMarkdown(value, diagnostics);\n }\n } else {\n // Continue traversing\n const value = obj[first];\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n processSegments(value as Record<string, unknown>, rest, diagnostics);\n }\n }\n }\n }\n}\n\n// ─── Main Translation Entry Point ────────────────────────────\n\n/**\n * Translate a single AST child node (either a GlyphUIBlock or a standard\n * MDAST content node) into an IR Block.\n *\n * Returns null for nodes that should be skipped (e.g., yaml frontmatter).\n *\n * @param node - The AST node to translate (GlyphUIBlock or standard MDAST content node).\n * @param ctx - Translation context carrying document ID, accumulated diagnostics, and references.\n * @returns The translated IR Block, or null if the node should be skipped.\n */\nexport function translateNode(\n node: GlyphUIBlock | MdastContentNode,\n ctx: TranslationContext,\n): Block | null {\n if (isGlyphUIBlock(node)) {\n return translateGlyphUIBlock(node, ctx);\n }\n return translateMdastNode(node, ctx);\n}\n\n// ─── Glyph UI Block Translation ─────────────────────────────\n\nfunction translateGlyphUIBlock(node: GlyphUIBlock, ctx: TranslationContext): Block {\n const componentType = node.componentType;\n const blockType: BlockType = `ui:${componentType}`;\n const position: SourcePosition = node.position ?? DEFAULT_POSITION;\n const blockDiagnostics: Diagnostic[] = [];\n\n // Determine block ID: user-assigned glyph-id or content-addressed\n const blockId = node.glyphId\n ? node.glyphId\n : generateBlockId(ctx.documentId, blockType, node.rawYaml);\n\n // Track the block ID mapping for reference resolution\n if (node.glyphId) {\n ctx.blockIdMap.set(node.glyphId, blockId);\n }\n\n // Handle YAML parse errors\n if (node.yamlError) {\n const diag = createYamlError(componentType, node.yamlError, position);\n blockDiagnostics.push(diag);\n ctx.diagnostics.push(diag);\n }\n\n // Determine block data\n let data: Record<string, unknown> = node.parsedData ?? {};\n\n // Validate against Zod schema if we have parsed data\n if (node.parsedData) {\n const schema = componentSchemas.get(componentType);\n if (schema) {\n const result = schema.safeParse(node.parsedData);\n if (!result.success) {\n const zodErrors = result.error.issues\n .map((issue) => `${issue.path.join('.')}: ${issue.message}`)\n .join('; ');\n const diag = createSchemaError(componentType, zodErrors, position, result.error.issues);\n blockDiagnostics.push(diag);\n ctx.diagnostics.push(diag);\n // Preserve the raw parsedData even on validation failure\n data = node.parsedData;\n } else {\n data = result.data as Record<string, unknown>;\n }\n } else {\n // Unknown component type — info diagnostic, preserve block as-is\n const diag = createUnknownComponentInfo(componentType, position);\n blockDiagnostics.push(diag);\n ctx.diagnostics.push(diag);\n }\n }\n\n // Process markdown fields after validation\n data = processMarkdownFields(componentType, data, ctx);\n\n // Process refs into references\n if (node.refs && node.refs.length > 0) {\n processRefs(node.refs, blockId, ctx);\n }\n\n const block: Block = {\n id: blockId,\n type: blockType,\n data,\n position,\n };\n\n if (node.interactive) {\n block.metadata = { interactive: true };\n }\n\n if (blockDiagnostics.length > 0) {\n block.diagnostics = blockDiagnostics;\n }\n\n return block;\n}\n\n// ─── Reference Processing ────────────────────────────────────\n\nfunction processRefs(refs: RawRef[], sourceBlockId: string, ctx: TranslationContext): void {\n for (const ref of refs) {\n const reference: Reference = {\n id: generateBlockId(ctx.documentId, 'ref', `${sourceBlockId}->${ref.target}`),\n type: (ref.type as Reference['type']) ?? 'navigates-to',\n sourceBlockId,\n targetBlockId: ref.target,\n };\n\n if (ref.label) {\n reference.label = ref.label;\n }\n if (ref.sourceAnchor) {\n reference.sourceAnchor = ref.sourceAnchor;\n }\n if (ref.targetAnchor) {\n reference.targetAnchor = ref.targetAnchor;\n }\n if (ref.bidirectional) {\n reference.bidirectional = ref.bidirectional;\n }\n\n // Mark as unresolved — we resolve later in the compile step\n reference.unresolved = true;\n\n ctx.references.push(reference);\n }\n}\n\n// ─── Standard MDAST Node Translation ─────────────────────────\n\nfunction translateMdastNode(node: MdastContentNode, ctx: TranslationContext): Block | null {\n const position: SourcePosition = node.position ?? DEFAULT_POSITION;\n\n switch (node.type) {\n case 'heading':\n return translateHeading(node, position, ctx);\n case 'paragraph':\n return translateParagraph(node, position, ctx);\n case 'list':\n return translateList(node, position, ctx);\n case 'code':\n return translateCode(node, position, ctx);\n case 'blockquote':\n return translateBlockquote(node, position, ctx);\n case 'image':\n return translateImage(node, position, ctx);\n case 'thematicBreak':\n return translateThematicBreak(position, ctx);\n case 'html':\n return translateHtml(node, position, ctx);\n case 'yaml':\n // Frontmatter is handled separately in compile.ts; skip here\n return null;\n default:\n // Unknown MDAST node type — skip silently\n return null;\n }\n}\n\n// ─── Individual Node Translators ─────────────────────────────\n\nfunction translateHeading(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const depth = (node['depth'] as number) ?? 1;\n const children = convertPhrasingContent((node.children ?? []) as unknown[]);\n const content = inlineNodesToText(children);\n\n return {\n id: generateBlockId(ctx.documentId, 'heading', content),\n type: 'heading',\n data: { depth, children },\n position,\n };\n}\n\nfunction translateParagraph(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const children = convertPhrasingContent((node.children ?? []) as unknown[]);\n const content = inlineNodesToText(children);\n\n return {\n id: generateBlockId(ctx.documentId, 'paragraph', content),\n type: 'paragraph',\n data: { children },\n position,\n };\n}\n\nfunction translateList(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const ordered = (node['ordered'] as boolean) ?? false;\n const start = ordered ? ((node['start'] as number) ?? 1) : undefined;\n const items = translateListItems((node.children ?? []) as MdastContentNode[]);\n const content = listDataToText({ ordered, start, items });\n\n const data: ListData = { ordered, items };\n if (start !== undefined) {\n data.start = start;\n }\n\n return {\n id: generateBlockId(ctx.documentId, 'list', content),\n type: 'list',\n data,\n position,\n };\n}\n\nfunction translateListItems(listItemNodes: MdastContentNode[]): ListItemData[] {\n const items: ListItemData[] = [];\n\n for (const itemNode of listItemNodes) {\n if (itemNode.type !== 'listItem') continue;\n\n const itemChildren = (itemNode.children ?? []) as MdastContentNode[];\n let inlineChildren: InlineNode[] = [];\n let subList: ListData | undefined;\n\n for (const child of itemChildren) {\n if (child.type === 'paragraph') {\n inlineChildren = convertPhrasingContent((child.children ?? []) as unknown[]);\n } else if (child.type === 'list') {\n const subOrdered = (child['ordered'] as boolean) ?? false;\n const subStart = subOrdered ? ((child['start'] as number) ?? 1) : undefined;\n const subItems = translateListItems((child.children ?? []) as MdastContentNode[]);\n subList = { ordered: subOrdered, items: subItems };\n if (subStart !== undefined) {\n subList.start = subStart;\n }\n }\n }\n\n const item: ListItemData = { children: inlineChildren };\n if (subList) {\n item.subList = subList;\n }\n items.push(item);\n }\n\n return items;\n}\n\nfunction translateCode(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const value = (node.value as string) ?? '';\n const language = (node['lang'] as string) ?? undefined;\n const meta = (node['meta'] as string) ?? undefined;\n\n const data: Record<string, unknown> = { value };\n if (language) {\n data['language'] = language;\n }\n if (meta) {\n data['meta'] = meta;\n }\n\n return {\n id: generateBlockId(ctx.documentId, 'code', value),\n type: 'code',\n data,\n position,\n };\n}\n\nfunction translateBlockquote(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n // Blockquote children are typically paragraphs — flatten their inline content\n const allInlineNodes: InlineNode[] = [];\n for (const child of (node.children ?? []) as MdastContentNode[]) {\n if (child.type === 'paragraph') {\n const inlines = convertPhrasingContent((child.children ?? []) as unknown[]);\n allInlineNodes.push(...inlines);\n }\n }\n const content = inlineNodesToText(allInlineNodes);\n\n return {\n id: generateBlockId(ctx.documentId, 'blockquote', content),\n type: 'blockquote',\n data: { children: allInlineNodes },\n position,\n };\n}\n\nfunction translateImage(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const src = (node['url'] as string) ?? '';\n const alt = (node['alt'] as string) ?? undefined;\n const title = (node['title'] as string) ?? undefined;\n\n const data: Record<string, unknown> = { src };\n if (alt) {\n data['alt'] = alt;\n }\n if (title) {\n data['title'] = title;\n }\n\n return {\n id: generateBlockId(ctx.documentId, 'image', src),\n type: 'image',\n data,\n position,\n };\n}\n\nfunction translateThematicBreak(position: SourcePosition, ctx: TranslationContext): Block {\n return {\n id: generateBlockId(ctx.documentId, 'thematic-break', '---'),\n type: 'thematic-break',\n data: {},\n position,\n };\n}\n\nfunction translateHtml(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const value = (node.value as string) ?? '';\n\n return {\n id: generateBlockId(ctx.documentId, 'html', value),\n type: 'html',\n data: { value },\n position,\n };\n}\n\n// ─── Text Extraction Helpers ─────────────────────────────────\n\n/**\n * Extract plain text from InlineNode[] for content-addressing purposes.\n */\nfunction inlineNodesToText(nodes: InlineNode[]): string {\n return nodes\n .map((node) => {\n switch (node.type) {\n case 'text':\n return node.value;\n case 'inlineCode':\n return node.value;\n case 'strong':\n case 'emphasis':\n case 'delete':\n return inlineNodesToText(node.children);\n case 'link':\n return inlineNodesToText(node.children);\n case 'image':\n return node.alt ?? '';\n case 'break':\n return '\\n';\n default:\n return '';\n }\n })\n .join('');\n}\n\n/**\n * Extract plain text from ListData for content-addressing purposes.\n */\nfunction listDataToText(data: ListData): string {\n return data.items\n .map((item) => {\n let text = inlineNodesToText(item.children);\n if (item.subList) {\n text += '\\n' + listDataToText(item.subList);\n }\n return text;\n })\n .join('\\n');\n}\n","import type {\n Block,\n Diagnostic,\n InlineNode,\n Reference,\n} from '@glyphjs/types';\nimport { generateBlockId } from '@glyphjs/ir';\nimport { createDiagnostic } from './diagnostics.js';\n\n// ─── Glyph Link Pattern ─────────────────────────────────────\n\n/**\n * Matches inline links of the form `[text](#glyph:block-id)`.\n * The captured group is the block ID after the `#glyph:` prefix.\n */\nconst GLYPH_LINK_PREFIX = '#glyph:';\n\n// ─── Inline Reference Scanning ──────────────────────────────\n\n/**\n * Scan a block's inline content for `[text](#glyph:block-id)` links\n * and create Reference objects for each match.\n *\n * @param block - The block whose inline data fields are scanned for glyph links.\n * @param documentId - Document ID used to generate deterministic reference IDs.\n * @returns Newly created (unresolved) Reference objects.\n */\nexport function extractInlineReferences(\n block: Block,\n documentId: string,\n): Reference[] {\n const references: Reference[] = [];\n const inlineNodes = extractInlineNodes(block);\n\n for (const node of inlineNodes) {\n if (node.type === 'link' && node.url.startsWith(GLYPH_LINK_PREFIX)) {\n const targetBlockId = node.url.slice(GLYPH_LINK_PREFIX.length);\n if (!targetBlockId) continue;\n\n const label = inlineNodesToPlainText(node.children);\n\n const reference: Reference = {\n id: generateBlockId(documentId, 'ref', `${block.id}->${targetBlockId}`),\n type: 'navigates-to',\n sourceBlockId: block.id,\n targetBlockId,\n unresolved: true,\n };\n\n if (label) {\n reference.label = label;\n }\n\n references.push(reference);\n }\n }\n\n return references;\n}\n\n/**\n * Scan all blocks (including nested children) for inline `#glyph:` link references\n * and collect them.\n *\n * @param blocks - Top-level block array to scan recursively.\n * @param documentId - Document ID used to generate deterministic reference IDs.\n * @returns Aggregated array of unresolved Reference objects from all blocks.\n */\nexport function extractAllInlineReferences(\n blocks: Block[],\n documentId: string,\n): Reference[] {\n const references: Reference[] = [];\n\n for (const block of blocks) {\n const blockRefs = extractInlineReferences(block, documentId);\n references.push(...blockRefs);\n\n // Also scan children (e.g. container blocks)\n if (block.children) {\n const childRefs = extractAllInlineReferences(block.children, documentId);\n references.push(...childRefs);\n }\n }\n\n return references;\n}\n\n// ─── Reference Resolution ────────────────────────────────────\n\n/**\n * Resolve references by checking if target block IDs exist in the document.\n * Marks unresolved references and adds warning diagnostics.\n *\n * Collects all block IDs including children (for container blocks).\n *\n * @param references - The reference array to resolve in-place (mutates `unresolved` flag).\n * @param blocks - All blocks in the document (used to build the known-ID set).\n * @param diagnostics - Accumulator for 'UNRESOLVED_REFERENCE' warnings.\n */\nexport function resolveReferences(\n references: Reference[],\n blocks: Block[],\n diagnostics: Diagnostic[],\n): void {\n const blockIdSet = collectAllBlockIds(blocks);\n\n for (const ref of references) {\n if (blockIdSet.has(ref.targetBlockId)) {\n ref.unresolved = false;\n } else {\n ref.unresolved = true;\n diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'warning',\n 'UNRESOLVED_REFERENCE',\n `Reference target \"${ref.targetBlockId}\" was not found in the document.`,\n ),\n );\n }\n }\n}\n\n/**\n * Collect all block IDs from blocks and their children recursively.\n */\nfunction collectAllBlockIds(blocks: Block[]): Set<string> {\n const ids = new Set<string>();\n for (const block of blocks) {\n ids.add(block.id);\n if (block.children) {\n for (const id of collectAllBlockIds(block.children)) {\n ids.add(id);\n }\n }\n }\n return ids;\n}\n\n// ─── Glyph-ID Uniqueness Validation ─────────────────────────\n\n/**\n * Validate that all user-assigned glyph-ids are unique within the document.\n * Emits error diagnostics for duplicates.\n *\n * @param blockIdMap - Map of user-assigned glyph-id to resolved block ID (from translation).\n * @param blocks - All blocks in the document (scanned to count occurrences).\n * @param diagnostics - Accumulator for 'DUPLICATE_GLYPH_ID' error diagnostics.\n */\nexport function validateGlyphIdUniqueness(\n blockIdMap: Map<string, string>,\n blocks: Block[],\n diagnostics: Diagnostic[],\n): void {\n // blockIdMap tracks glyphId -> blockId, but we need to detect duplicates\n // by scanning blocks for those whose id matches a glyph-id key\n const glyphIdOccurrences = new Map<string, number>();\n\n for (const glyphId of blockIdMap.keys()) {\n const count = countBlocksWithGlyphId(blocks, glyphId);\n glyphIdOccurrences.set(glyphId, count);\n }\n\n for (const [glyphId, count] of glyphIdOccurrences) {\n if (count > 1) {\n diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'error',\n 'DUPLICATE_GLYPH_ID',\n `Duplicate glyph-id \"${glyphId}\" found on ${String(count)} blocks. Block IDs must be unique within a document.`,\n ),\n );\n }\n }\n}\n\n/**\n * Count how many blocks in the array have a given ID (which came from a glyph-id).\n */\nfunction countBlocksWithGlyphId(blocks: Block[], glyphId: string): number {\n let count = 0;\n for (const block of blocks) {\n if (block.id === glyphId) {\n count++;\n }\n }\n return count;\n}\n\n// ─── Inline Node Extraction Helpers ──────────────────────────\n\n/**\n * Extract all InlineNode arrays from a block's data field.\n * Handles heading, paragraph, blockquote, and list blocks.\n */\nfunction extractInlineNodes(block: Block): InlineNode[] {\n const data = block.data as Record<string, unknown>;\n const nodes: InlineNode[] = [];\n\n // Blocks with a direct `children` inline array\n if (Array.isArray(data['children'])) {\n nodes.push(...(data['children'] as InlineNode[]));\n }\n\n // List blocks: extract inline nodes from items\n if (Array.isArray(data['items'])) {\n for (const item of data['items'] as { children?: InlineNode[]; subList?: { items?: unknown[] } }[]) {\n if (Array.isArray(item.children)) {\n nodes.push(...item.children);\n }\n }\n }\n\n return nodes;\n}\n\n/**\n * Extract plain text from InlineNode[] for label purposes.\n */\nfunction inlineNodesToPlainText(nodes: InlineNode[]): string {\n return nodes\n .map((node) => {\n switch (node.type) {\n case 'text':\n return node.value;\n case 'inlineCode':\n return node.value;\n case 'strong':\n case 'emphasis':\n case 'delete':\n return inlineNodesToPlainText(node.children);\n case 'link':\n return inlineNodesToPlainText(node.children);\n case 'image':\n return node.alt ?? '';\n case 'break':\n return '\\n';\n default:\n return '';\n }\n })\n .join('');\n}\n","import type { Block, Diagnostic } from '@glyphjs/types';\nimport { parseGlyphMarkdown } from '@glyphjs/parser';\nimport { translateNode } from './ast-to-ir.js';\nimport type { TranslationContext } from './ast-to-ir.js';\nimport { createDiagnostic } from './diagnostics.js';\n\n// ─── Container Block Compilation ─────────────────────────────\n\n/**\n * Process container blocks (ui:tabs and ui:steps) by recursively parsing\n * their content fields as Markdown into child Block[] arrays.\n *\n * This function mutates blocks in-place, populating their `children` field\n * and updating data entries with parsed child blocks.\n *\n * @param blocks - The top-level block array to scan for container blocks.\n * @param ctx - Translation context used for recursive compilation.\n */\nexport function compileContainerBlocks(\n blocks: Block[],\n ctx: TranslationContext,\n): void {\n for (const block of blocks) {\n if (block.type === 'ui:tabs') {\n compileTabsBlock(block, ctx);\n } else if (block.type === 'ui:steps') {\n compileStepsBlock(block, ctx);\n }\n }\n}\n\n// ─── Tabs Compilation ────────────────────────────────────────\n\nfunction compileTabsBlock(block: Block, ctx: TranslationContext): void {\n const data = block.data as Record<string, unknown>;\n const tabs = data['tabs'];\n\n if (!Array.isArray(tabs)) return;\n\n const allChildren: Block[] = [];\n\n for (const tab of tabs as { label?: string; content?: string }[]) {\n if (typeof tab.content !== 'string') continue;\n\n const childBlocks = parseContentToBlocks(tab.content, block, ctx);\n allChildren.push(...childBlocks);\n }\n\n if (allChildren.length > 0) {\n block.children = allChildren;\n }\n}\n\n// ─── Steps Compilation ───────────────────────────────────────\n\nfunction compileStepsBlock(block: Block, ctx: TranslationContext): void {\n const data = block.data as Record<string, unknown>;\n const steps = data['steps'];\n\n if (!Array.isArray(steps)) return;\n\n const allChildren: Block[] = [];\n\n for (const step of steps as { title?: string; status?: string; content?: string }[]) {\n if (typeof step.content !== 'string') continue;\n\n const childBlocks = parseContentToBlocks(step.content, block, ctx);\n allChildren.push(...childBlocks);\n }\n\n if (allChildren.length > 0) {\n block.children = allChildren;\n }\n}\n\n// ─── Content Parsing Helper ──────────────────────────────────\n\n/**\n * Parse a Markdown content string into Block[] using the compiler pipeline.\n * Emits a warning diagnostic if nested ui: components are found (deferred to v2).\n */\nfunction parseContentToBlocks(\n content: string,\n parentBlock: Block,\n ctx: TranslationContext,\n): Block[] {\n const ast = parseGlyphMarkdown(content);\n const blocks: Block[] = [];\n\n for (const child of ast.children) {\n // Check for nested ui: components — warn and skip\n if (child.type === 'glyphUIBlock') {\n ctx.diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'warning',\n 'NESTED_UI_COMPONENT',\n `Nested ui: component found inside container block \"${parentBlock.id}\". ` +\n `Nested ui: components inside tabs/steps are not supported in v1 and will be ignored.`,\n child.position,\n ),\n );\n continue;\n }\n\n const block = translateNode(child, ctx);\n if (block) {\n blocks.push(block);\n }\n }\n\n return blocks;\n}\n\n// ─── Nested UI Detection ─────────────────────────────────────\n\n/**\n * Check if content contains nested ui: blocks by looking for the pattern.\n * This is a quick heuristic check. The actual detection happens during parsing.\n *\n * @param content - Raw Markdown string to test for nested ui: fenced blocks.\n * @returns True if the content matches the `` ```ui: `` pattern.\n */\nexport function hasNestedUiBlocks(content: string): boolean {\n return /```ui:/m.test(content);\n}\n\n// ─── Validate Container Diagnostics ──────────────────────────\n\n/**\n * Post-process container blocks to ensure data consistency.\n * Called after container compilation is complete.\n *\n * @param blocks - The compiled block array to validate.\n * @param diagnostics - Accumulator for warning diagnostics (e.g., missing labels/titles).\n */\nexport function validateContainerBlocks(\n blocks: Block[],\n diagnostics: Diagnostic[],\n): void {\n for (const block of blocks) {\n if (block.type === 'ui:tabs') {\n validateTabsData(block, diagnostics);\n } else if (block.type === 'ui:steps') {\n validateStepsData(block, diagnostics);\n }\n }\n}\n\nfunction validateTabsData(block: Block, _diagnostics: Diagnostic[]): void {\n const data = block.data as Record<string, unknown>;\n const tabs = data['tabs'];\n\n if (!Array.isArray(tabs) || tabs.length === 0) {\n return;\n }\n\n // Ensure each tab has a label\n for (const tab of tabs as { label?: string }[]) {\n if (!tab.label) {\n _diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'warning',\n 'MISSING_TAB_LABEL',\n `A tab in block \"${block.id}\" is missing a label.`,\n block.position,\n ),\n );\n }\n }\n}\n\nfunction validateStepsData(block: Block, _diagnostics: Diagnostic[]): void {\n const data = block.data as Record<string, unknown>;\n const steps = data['steps'];\n\n if (!Array.isArray(steps) || steps.length === 0) {\n return;\n }\n\n // Ensure each step has a title\n for (const step of steps as { title?: string }[]) {\n if (!step.title) {\n _diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'warning',\n 'MISSING_STEP_TITLE',\n `A step in block \"${block.id}\" is missing a title.`,\n block.position,\n ),\n );\n }\n }\n}\n","import type {\n GlyphIR,\n CompilationResult,\n Diagnostic,\n DocumentMetadata,\n LayoutHints,\n Block,\n Reference,\n MdastContentNode,\n} from '@glyphjs/types';\nimport { parseGlyphMarkdown } from '@glyphjs/parser';\nimport { generateDocumentId, resolveBlockIdCollisions } from '@glyphjs/ir';\nimport { parse as parseYaml } from 'yaml';\nimport { translateNode } from './ast-to-ir.js';\nimport type { TranslationContext } from './ast-to-ir.js';\nimport { createDiagnostic } from './diagnostics.js';\nimport {\n extractAllInlineReferences,\n resolveReferences,\n validateGlyphIdUniqueness,\n} from './references.js';\nimport { compileContainerBlocks, validateContainerBlocks } from './containers.js';\n\n// ─── Public Interface ────────────────────────────────────────\n\nexport interface CompileOptions {\n /** Source file path, used for document ID generation. */\n filePath?: string;\n /** Explicit document ID override. */\n documentId?: string;\n /** Enable markdown parsing in component text fields by default. */\n parseComponentMarkdown?: boolean;\n}\n\n// ─── Main Compile Function ───────────────────────────────────\n\n/**\n * Compile a Markdown string into Glyph IR.\n *\n * Steps:\n * 1. Parse the markdown via `parseGlyphMarkdown`\n * 2. Extract frontmatter metadata and layout hints\n * 3. Walk the AST and translate each node to IR blocks\n * 4. Validate ui: blocks against Zod schemas\n * 5. Compile container blocks (ui:tabs, ui:steps) — recursively parse content\n * 6. Validate container block data\n * 7. Generate content-addressed block IDs\n * 8. Generate the document ID\n * 9. Resolve block ID collisions\n * 10. Validate glyph-id uniqueness\n * 11. Extract inline references from `[text](#glyph:block-id)` links\n * 12. Resolve all references (from refs arrays and inline links)\n * 13. Infer metadata from content if not in frontmatter\n * 14. Return CompilationResult with IR, diagnostics, and hasErrors flag\n *\n * Uses a collect-all-errors strategy: IR is always produced, even when errors exist.\n */\nexport function compile(markdown: string, options?: CompileOptions): CompilationResult {\n const diagnostics: Diagnostic[] = [];\n\n // 1. Parse the markdown into a Glyph AST\n const ast = parseGlyphMarkdown(markdown);\n\n // 2. Extract frontmatter\n const { metadata, layout, frontmatterGlyphId } = extractFrontmatter(ast.children, diagnostics);\n\n // 3. Generate document ID\n const documentId =\n options?.documentId ??\n generateDocumentId({\n glyphId: frontmatterGlyphId,\n filePath: options?.filePath,\n content: markdown,\n });\n\n // Set sourceFile from options if available\n if (options?.filePath && !metadata.sourceFile) {\n metadata.sourceFile = options.filePath;\n }\n\n // 4. Create translation context\n const references: Reference[] = [];\n const ctx: TranslationContext = {\n documentId,\n diagnostics,\n references,\n blockIdMap: new Map(),\n compileOptions: options ?? {},\n };\n\n // 5. Walk the AST and translate nodes\n const blocks: Block[] = [];\n for (const child of ast.children) {\n const block = translateNode(child, ctx);\n if (block) {\n blocks.push(block);\n }\n }\n\n // 6. Compile container blocks (ui:tabs, ui:steps) — recursively parse content fields\n compileContainerBlocks(blocks, ctx);\n\n // 7. Validate container block data\n validateContainerBlocks(blocks, diagnostics);\n\n // 8. Infer metadata from content if not in frontmatter\n inferMetadata(metadata, blocks);\n\n // 9. Resolve block ID collisions\n const blockIds = blocks.map((b) => b.id);\n const resolvedIds = resolveBlockIdCollisions(blockIds);\n for (let i = 0; i < blocks.length; i++) {\n const block = blocks[i];\n const resolvedId = resolvedIds[i];\n if (block && resolvedId) {\n block.id = resolvedId;\n }\n }\n\n // 10. Validate glyph-id uniqueness\n validateGlyphIdUniqueness(ctx.blockIdMap, blocks, diagnostics);\n\n // 11. Extract inline references from [text](#glyph:block-id) links\n const inlineRefs = extractAllInlineReferences(blocks, documentId);\n references.push(...inlineRefs);\n\n // 12. Resolve all references (from refs arrays and inline links)\n resolveReferences(references, blocks, diagnostics);\n\n // 13. Build the IR\n const ir: GlyphIR = {\n version: '1.0.0',\n id: documentId,\n metadata,\n blocks,\n references,\n layout,\n };\n\n const hasErrors = diagnostics.some((d) => d.severity === 'error');\n\n return { ir, diagnostics, hasErrors };\n}\n\n// ─── Frontmatter Extraction ─────────────────────────────────\n\ninterface FrontmatterResult {\n metadata: DocumentMetadata;\n layout: LayoutHints;\n frontmatterGlyphId?: string;\n}\n\nfunction extractFrontmatter(\n children: readonly unknown[],\n diagnostics: Diagnostic[],\n): FrontmatterResult {\n const metadata: DocumentMetadata = {};\n let layout: LayoutHints = { mode: 'document', spacing: 'normal' };\n let frontmatterGlyphId: string | undefined;\n\n // Look for yaml frontmatter node (always first child if present)\n const firstChild = children[0] as MdastContentNode | undefined;\n if (firstChild && firstChild.type === 'yaml' && typeof firstChild.value === 'string') {\n try {\n const parsed: unknown = parseYaml(firstChild.value);\n if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {\n const fm = parsed as Record<string, unknown>;\n\n // Extract glyph-id\n if (typeof fm['glyph-id'] === 'string') {\n frontmatterGlyphId = fm['glyph-id'];\n }\n\n // Extract metadata fields\n if (typeof fm['title'] === 'string') {\n metadata.title = fm['title'];\n }\n if (typeof fm['description'] === 'string') {\n metadata.description = fm['description'];\n }\n if (Array.isArray(fm['authors'])) {\n metadata.authors = fm['authors'].filter((a): a is string => typeof a === 'string');\n }\n if (typeof fm['createdAt'] === 'string') {\n metadata.createdAt = fm['createdAt'];\n }\n if (Array.isArray(fm['tags'])) {\n metadata.tags = fm['tags'].filter((t): t is string => typeof t === 'string');\n }\n\n // Extract layout hints\n if (fm['layout'] && typeof fm['layout'] === 'object' && !Array.isArray(fm['layout'])) {\n const rawLayout = fm['layout'] as Record<string, unknown>;\n layout = {\n mode: isLayoutMode(rawLayout['mode']) ? rawLayout['mode'] : 'document',\n spacing: isLayoutSpacing(rawLayout['spacing']) ? rawLayout['spacing'] : 'normal',\n };\n if (typeof rawLayout['columns'] === 'number') {\n layout.columns = rawLayout['columns'];\n }\n if (typeof rawLayout['maxWidth'] === 'string') {\n layout.maxWidth = rawLayout['maxWidth'];\n }\n }\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : String(err);\n diagnostics.push(\n createDiagnostic(\n 'parser',\n 'error',\n 'FRONTMATTER_PARSE_ERROR',\n `Failed to parse frontmatter YAML: ${message}`,\n firstChild.position,\n ),\n );\n }\n }\n\n return { metadata, layout, frontmatterGlyphId };\n}\n\nfunction isLayoutMode(value: unknown): value is LayoutHints['mode'] {\n return value === 'document' || value === 'dashboard' || value === 'presentation';\n}\n\nfunction isLayoutSpacing(value: unknown): value is 'compact' | 'normal' | 'relaxed' {\n return value === 'compact' || value === 'normal' || value === 'relaxed';\n}\n\n// ─── Metadata Inference ──────────────────────────────────────\n\n/**\n * Infer metadata from content when not provided via frontmatter.\n * - title: from the first h1 heading\n * - description: from the first paragraph\n */\nfunction inferMetadata(metadata: DocumentMetadata, blocks: Block[]): void {\n if (!metadata.title) {\n const firstHeading = blocks.find(\n (b) => b.type === 'heading' && (b.data as Record<string, unknown>)['depth'] === 1,\n );\n if (firstHeading) {\n const data = firstHeading.data as { children?: { type: string; value?: string }[] };\n if (data.children) {\n metadata.title = data.children\n .map((node) => {\n if ('value' in node && typeof node.value === 'string') {\n return node.value;\n }\n return '';\n })\n .join('');\n }\n }\n }\n\n if (!metadata.description) {\n const firstParagraph = blocks.find((b) => b.type === 'paragraph');\n if (firstParagraph) {\n const data = firstParagraph.data as { children?: { type: string; value?: string }[] };\n if (data.children) {\n metadata.description = data.children\n .map((node) => {\n if ('value' in node && typeof node.value === 'string') {\n return node.value;\n }\n return '';\n })\n .join('');\n }\n }\n }\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -5,6 +5,8 @@ interface CompileOptions {
5
5
  filePath?: string;
6
6
  /** Explicit document ID override. */
7
7
  documentId?: string;
8
+ /** Enable markdown parsing in component text fields by default. */
9
+ parseComponentMarkdown?: boolean;
8
10
  }
9
11
  /**
10
12
  * Compile a Markdown string into Glyph IR.
@@ -85,6 +87,7 @@ interface TranslationContext {
85
87
  diagnostics: Diagnostic[];
86
88
  references: Reference[];
87
89
  blockIdMap: Map<string, string>;
90
+ compileOptions: CompileOptions;
88
91
  }
89
92
  /**
90
93
  * Translate a single AST child node (either a GlyphUIBlock or a standard
package/dist/index.d.ts CHANGED
@@ -5,6 +5,8 @@ interface CompileOptions {
5
5
  filePath?: string;
6
6
  /** Explicit document ID override. */
7
7
  documentId?: string;
8
+ /** Enable markdown parsing in component text fields by default. */
9
+ parseComponentMarkdown?: boolean;
8
10
  }
9
11
  /**
10
12
  * Compile a Markdown string into Glyph IR.
@@ -85,6 +87,7 @@ interface TranslationContext {
85
87
  diagnostics: Diagnostic[];
86
88
  references: Reference[];
87
89
  blockIdMap: Map<string, string>;
90
+ compileOptions: CompileOptions;
88
91
  }
89
92
  /**
90
93
  * Translate a single AST child node (either a GlyphUIBlock or a standard
package/dist/index.js CHANGED
@@ -2,10 +2,10 @@ import { parseGlyphMarkdown } from '@glyphjs/parser';
2
2
  import { generateBlockId, generateDocumentId, resolveBlockIdCollisions } from '@glyphjs/ir';
3
3
  import { parse } from 'yaml';
4
4
  import { componentSchemas } from '@glyphjs/schemas';
5
+ import { unified } from 'unified';
6
+ import remarkParse from 'remark-parse';
5
7
 
6
8
  // src/compile.ts
7
-
8
- // src/inline.ts
9
9
  function convertPhrasingContent(nodes) {
10
10
  const result = [];
11
11
  for (const node of nodes) {
@@ -72,6 +72,43 @@ function convertSingleNode(node) {
72
72
  }
73
73
  }
74
74
  }
75
+ function parseInlineMarkdown(text, diagnostics) {
76
+ if (text.trim() === "") {
77
+ return [];
78
+ }
79
+ const processor = unified().use(remarkParse);
80
+ const tree = processor.parse(text);
81
+ const root = tree;
82
+ if (!root.children || root.children.length === 0) {
83
+ return [{ type: "text", value: text }];
84
+ }
85
+ const hasBlockElements = root.children.some(
86
+ (child) => child.type !== "paragraph" && child.type !== "text" && !["strong", "emphasis", "delete", "inlineCode", "link", "image", "break"].includes(
87
+ child.type
88
+ )
89
+ );
90
+ if (hasBlockElements && diagnostics) {
91
+ diagnostics.push({
92
+ severity: "warning",
93
+ code: "INLINE_BLOCK_ELEMENTS",
94
+ message: "Block-level markdown elements (headings, lists, etc.) are not supported in inline text fields. Only inline formatting (bold, italic, links, code) will be preserved.",
95
+ source: "compiler"
96
+ });
97
+ }
98
+ const firstParagraph = root.children.find((child) => child.type === "paragraph");
99
+ if (firstParagraph && firstParagraph.children) {
100
+ return convertPhrasingContent(firstParagraph.children);
101
+ }
102
+ const inlineChildren = root.children.filter(
103
+ (child) => ["text", "strong", "emphasis", "delete", "inlineCode", "link", "image", "break"].includes(
104
+ child.type
105
+ )
106
+ );
107
+ if (inlineChildren.length > 0) {
108
+ return convertPhrasingContent(inlineChildren);
109
+ }
110
+ return [{ type: "text", value: text }];
111
+ }
75
112
 
76
113
  // src/diagnostics.ts
77
114
  function createDiagnostic(source, severity, code, message, position, details) {
@@ -121,6 +158,80 @@ var DEFAULT_POSITION = {
121
158
  function isGlyphUIBlock(node) {
122
159
  return node.type === "glyphUIBlock";
123
160
  }
161
+ var MARKDOWN_FIELD_MAP = {
162
+ callout: ["content", "title"],
163
+ card: ["cards[].body", "cards[].subtitle"],
164
+ accordion: ["sections[].content"],
165
+ steps: ["steps[].content"],
166
+ kpi: ["metrics[].label"],
167
+ comparison: ["options[].description", "features[].values[]"],
168
+ quiz: ["questions[].question", "questions[].explanation", "questions[].options[]"],
169
+ infographic: ["sections[].items[].text", "sections[].items[].description"],
170
+ timeline: ["events[].title", "events[].description"],
171
+ poll: ["question", "options[].label"],
172
+ rating: ["label", "description"],
173
+ ranker: ["items[].label"],
174
+ slider: ["label"],
175
+ matrix: ["rowLabels[]", "columnLabels[]"],
176
+ annotate: ["annotations[].text"],
177
+ form: ["description"]
178
+ };
179
+ function processMarkdownFields(componentType, data, ctx) {
180
+ const markdownEnabled = data.markdown === true || ctx.compileOptions.parseComponentMarkdown === true;
181
+ if (!markdownEnabled) {
182
+ return data;
183
+ }
184
+ const fieldPaths = MARKDOWN_FIELD_MAP[componentType];
185
+ if (!fieldPaths || fieldPaths.length === 0) {
186
+ return data;
187
+ }
188
+ const result = { ...data };
189
+ for (const path of fieldPaths) {
190
+ processFieldPath(result, path, ctx.diagnostics);
191
+ }
192
+ return result;
193
+ function processFieldPath(obj, path, diagnostics) {
194
+ const segments = path.split(".");
195
+ processSegments(obj, segments, diagnostics);
196
+ }
197
+ function processSegments(obj, segments, diagnostics) {
198
+ if (segments.length === 0) return;
199
+ const [first, ...rest] = segments;
200
+ if (!first) return;
201
+ if (first.endsWith("[]")) {
202
+ const fieldName = first.slice(0, -2);
203
+ const value = obj[fieldName];
204
+ if (Array.isArray(value)) {
205
+ if (rest.length === 0) {
206
+ obj[fieldName] = value.map((item) => {
207
+ if (typeof item === "string") {
208
+ return parseInlineMarkdown(item, diagnostics);
209
+ }
210
+ return item;
211
+ });
212
+ } else {
213
+ for (const item of value) {
214
+ if (typeof item === "object" && item !== null) {
215
+ processSegments(item, rest, diagnostics);
216
+ }
217
+ }
218
+ }
219
+ }
220
+ } else {
221
+ if (rest.length === 0) {
222
+ const value = obj[first];
223
+ if (typeof value === "string") {
224
+ obj[first] = parseInlineMarkdown(value, diagnostics);
225
+ }
226
+ } else {
227
+ const value = obj[first];
228
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
229
+ processSegments(value, rest, diagnostics);
230
+ }
231
+ }
232
+ }
233
+ }
234
+ }
124
235
  function translateNode(node, ctx) {
125
236
  if (isGlyphUIBlock(node)) {
126
237
  return translateGlyphUIBlock(node, ctx);
@@ -161,6 +272,7 @@ function translateGlyphUIBlock(node, ctx) {
161
272
  ctx.diagnostics.push(diag);
162
273
  }
163
274
  }
275
+ data = processMarkdownFields(componentType, data, ctx);
164
276
  if (node.refs && node.refs.length > 0) {
165
277
  processRefs(node.refs, blockId, ctx);
166
278
  }
@@ -654,7 +766,8 @@ function compile(markdown, options) {
654
766
  documentId,
655
767
  diagnostics,
656
768
  references,
657
- blockIdMap: /* @__PURE__ */ new Map()
769
+ blockIdMap: /* @__PURE__ */ new Map(),
770
+ compileOptions: options ?? {}
658
771
  };
659
772
  const blocks = [];
660
773
  for (const child of ast.children) {
@@ -710,17 +823,13 @@ function extractFrontmatter(children, diagnostics) {
710
823
  metadata.description = fm["description"];
711
824
  }
712
825
  if (Array.isArray(fm["authors"])) {
713
- metadata.authors = fm["authors"].filter(
714
- (a) => typeof a === "string"
715
- );
826
+ metadata.authors = fm["authors"].filter((a) => typeof a === "string");
716
827
  }
717
828
  if (typeof fm["createdAt"] === "string") {
718
829
  metadata.createdAt = fm["createdAt"];
719
830
  }
720
831
  if (Array.isArray(fm["tags"])) {
721
- metadata.tags = fm["tags"].filter(
722
- (t) => typeof t === "string"
723
- );
832
+ metadata.tags = fm["tags"].filter((t) => typeof t === "string");
724
833
  }
725
834
  if (fm["layout"] && typeof fm["layout"] === "object" && !Array.isArray(fm["layout"])) {
726
835
  const rawLayout = fm["layout"];
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/inline.ts","../src/diagnostics.ts","../src/ast-to-ir.ts","../src/references.ts","../src/containers.ts","../src/compile.ts"],"names":["generateBlockId","parseGlyphMarkdown","parseYaml"],"mappings":";;;;;;;;AAsEO,SAAS,uBAAuB,KAAA,EAAgC;AACrE,EAAA,MAAM,SAAuB,EAAC;AAE9B,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,MAAM,SAAA,GAAY,kBAAkB,IAA4B,CAAA;AAChE,IAAA,IAAI,SAAA,EAAW;AACb,MAAA,MAAA,CAAO,KAAK,SAAS,CAAA;AAAA,IACvB;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,kBAAkB,IAAA,EAA+C;AACxE,EAAA,QAAQ,KAAK,IAAA;AAAM,IACjB,KAAK,MAAA;AACH,MAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,KAAA,EAAO,KAAK,KAAA,EAAM;AAAA,IAE3C,KAAK,QAAA;AACH,MAAA,OAAO;AAAA,QACL,IAAA,EAAM,QAAA;AAAA,QACN,QAAA,EAAU,sBAAA,CAAuB,IAAA,CAAK,QAAQ;AAAA,OAChD;AAAA,IAEF,KAAK,UAAA;AACH,MAAA,OAAO;AAAA,QACL,IAAA,EAAM,UAAA;AAAA,QACN,QAAA,EAAU,sBAAA,CAAuB,IAAA,CAAK,QAAQ;AAAA,OAChD;AAAA,IAEF,KAAK,QAAA;AACH,MAAA,OAAO;AAAA,QACL,IAAA,EAAM,QAAA;AAAA,QACN,QAAA,EAAU,sBAAA,CAAuB,IAAA,CAAK,QAAQ;AAAA,OAChD;AAAA,IAEF,KAAK,YAAA;AACH,MAAA,OAAO,EAA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IAAI,cAAA,EAAgB;AAClB,MAAA,MAAM,OAAO,cAAA,CAAe,IAAA;AAC5B,MAAA,IAAI,KAAK,QAAA,EAAU;AACjB,QAAA,QAAA,CAAS,WAAA,GAAc,IAAA,CAAK,QAAA,CACzB,GAAA,CAAI,CAAC,IAAA,KAAS;AACb,UAAA,IAAI,OAAA,IAAW,IAAA,IAAQ,OAAO,IAAA,CAAK,UAAU,QAAA,EAAU;AACrD,YAAA,OAAO,IAAA,CAAK,KAAA;AAAA,UACd;AACA,UAAA,OAAO,EAAA;AAAA,QACT,CAAC,CAAA,CACA,IAAA,CAAK,EAAE,CAAA;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AACF","file":"index.js","sourcesContent":["import type { InlineNode } from '@glyphjs/types';\n\n// ─── MDAST Phrasing Content Types ───────────────────────────\n// These are structural types matching the shapes from mdast,\n// avoiding a hard dependency on @types/mdast.\n\ninterface MdastText {\n type: 'text';\n value: string;\n}\n\ninterface MdastStrong {\n type: 'strong';\n children: MdastPhrasingContent[];\n}\n\ninterface MdastEmphasis {\n type: 'emphasis';\n children: MdastPhrasingContent[];\n}\n\ninterface MdastDelete {\n type: 'delete';\n children: MdastPhrasingContent[];\n}\n\ninterface MdastInlineCode {\n type: 'inlineCode';\n value: string;\n}\n\ninterface MdastLink {\n type: 'link';\n url: string;\n title?: string | null;\n children: MdastPhrasingContent[];\n}\n\ninterface MdastImage {\n type: 'image';\n url: string;\n alt?: string | null;\n title?: string | null;\n}\n\ninterface MdastBreak {\n type: 'break';\n}\n\ntype MdastPhrasingContent =\n | MdastText\n | MdastStrong\n | MdastEmphasis\n | MdastDelete\n | MdastInlineCode\n | MdastLink\n | MdastImage\n | MdastBreak;\n\n// ─── Conversion ─────────────────────────────────────────────\n\n/**\n * Convert an array of MDAST phrasing content nodes to InlineNode[].\n *\n * Unknown node types are converted to text nodes with their string value\n * (if present) or skipped entirely.\n *\n * @param nodes - Raw MDAST phrasing content nodes (typed as unknown[] to avoid a hard @types/mdast dependency).\n * @returns Normalized InlineNode array suitable for inclusion in IR blocks.\n */\nexport function convertPhrasingContent(nodes: unknown[]): InlineNode[] {\n const result: InlineNode[] = [];\n\n for (const node of nodes) {\n const converted = convertSingleNode(node as MdastPhrasingContent);\n if (converted) {\n result.push(converted);\n }\n }\n\n return result;\n}\n\nfunction convertSingleNode(node: MdastPhrasingContent): InlineNode | null {\n switch (node.type) {\n case 'text':\n return { type: 'text', value: node.value };\n\n case 'strong':\n return {\n type: 'strong',\n children: convertPhrasingContent(node.children),\n };\n\n case 'emphasis':\n return {\n type: 'emphasis',\n children: convertPhrasingContent(node.children),\n };\n\n case 'delete':\n return {\n type: 'delete',\n children: convertPhrasingContent(node.children),\n };\n\n case 'inlineCode':\n return { type: 'inlineCode', value: node.value };\n\n case 'link': {\n const linkNode: InlineNode = {\n type: 'link',\n url: node.url,\n children: convertPhrasingContent(node.children),\n };\n if (node.title != null) {\n (linkNode as { type: 'link'; url: string; title?: string; children: InlineNode[] }).title =\n node.title;\n }\n return linkNode;\n }\n\n case 'image': {\n const imgNode: InlineNode = {\n type: 'image',\n src: node.url,\n };\n if (node.alt != null) {\n (imgNode as { type: 'image'; src: string; alt?: string; title?: string }).alt = node.alt;\n }\n if (node.title != null) {\n (imgNode as { type: 'image'; src: string; alt?: string; title?: string }).title =\n node.title;\n }\n return imgNode;\n }\n\n case 'break':\n return { type: 'break' };\n\n default: {\n // For unknown phrasing content types, attempt to extract a text value\n const unknown = node as Record<string, unknown>;\n if (typeof unknown['value'] === 'string') {\n return { type: 'text', value: unknown['value'] };\n }\n return null;\n }\n }\n}\n","import type { Diagnostic, DiagnosticSource, SourcePosition } from '@glyphjs/types';\n\n// ─── Diagnostic Creation Helpers ─────────────────────────────\n\n/**\n * Create a diagnostic with the given source, severity, message, and optional position.\n *\n * @param source - The subsystem that produced the diagnostic (e.g., 'compiler', 'parser', 'schema').\n * @param severity - Severity level: 'error', 'warning', or 'info'.\n * @param code - Machine-readable diagnostic code (e.g., 'YAML_PARSE_ERROR').\n * @param message - Human-readable description of the issue.\n * @param position - Optional source position where the issue was detected.\n * @param details - Optional structured details (e.g., Zod issue objects).\n * @returns A fully constructed Diagnostic object.\n */\nexport function createDiagnostic(\n source: DiagnosticSource,\n severity: Diagnostic['severity'],\n code: string,\n message: string,\n position?: SourcePosition,\n details?: unknown,\n): Diagnostic {\n const diag: Diagnostic = { severity, code, message, source };\n if (position) {\n diag.position = position;\n }\n if (details !== undefined) {\n diag.details = details;\n }\n return diag;\n}\n\n/**\n * Create a schema validation error diagnostic.\n *\n * @param componentType - The ui: component type that failed validation (without the `ui:` prefix).\n * @param message - Concatenated validation error messages from Zod.\n * @param position - Optional source position of the component block.\n * @param details - Optional raw Zod issue objects.\n * @returns A Diagnostic with severity 'error' and code 'SCHEMA_VALIDATION_FAILED'.\n */\nexport function createSchemaError(\n componentType: string,\n message: string,\n position?: SourcePosition,\n details?: unknown,\n): Diagnostic {\n return createDiagnostic(\n 'schema',\n 'error',\n 'SCHEMA_VALIDATION_FAILED',\n `Schema validation failed for ui:${componentType}: ${message}`,\n position,\n details,\n );\n}\n\n/**\n * Create an info diagnostic for unknown component types.\n *\n * @param componentType - The unrecognized component type (without the `ui:` prefix).\n * @param position - Optional source position of the component block.\n * @returns A Diagnostic with severity 'info' and code 'UNKNOWN_COMPONENT_TYPE'.\n */\nexport function createUnknownComponentInfo(\n componentType: string,\n position?: SourcePosition,\n): Diagnostic {\n return createDiagnostic(\n 'compiler',\n 'info',\n 'UNKNOWN_COMPONENT_TYPE',\n `Unknown component type \"ui:${componentType}\". Block preserved as-is.`,\n position,\n );\n}\n\n/**\n * Create a diagnostic for YAML parse errors on ui: blocks.\n *\n * @param componentType - The ui: component type whose YAML failed to parse (without the `ui:` prefix).\n * @param yamlError - The YAML parser error message.\n * @param position - Optional source position of the fenced code block.\n * @returns A Diagnostic with severity 'error' and code 'YAML_PARSE_ERROR'.\n */\nexport function createYamlError(\n componentType: string,\n yamlError: string,\n position?: SourcePosition,\n): Diagnostic {\n return createDiagnostic(\n 'parser',\n 'error',\n 'YAML_PARSE_ERROR',\n `YAML parse error in ui:${componentType}: ${yamlError}`,\n position,\n );\n}\n","import type {\n Block,\n BlockType,\n Diagnostic,\n GlyphUIBlock,\n MdastContentNode,\n SourcePosition,\n Reference,\n RawRef,\n ListData,\n ListItemData,\n InlineNode,\n} from '@glyphjs/types';\nimport { generateBlockId } from '@glyphjs/ir';\nimport { componentSchemas } from '@glyphjs/schemas';\nimport { convertPhrasingContent } from './inline.js';\nimport { createSchemaError, createUnknownComponentInfo, createYamlError } from './diagnostics.js';\n\n// ─── Default Source Position ─────────────────────────────────\n\nconst DEFAULT_POSITION: SourcePosition = {\n start: { line: 0, column: 0 },\n end: { line: 0, column: 0 },\n};\n\n// ─── Translation Context ────────────────────────────────────\n\nexport interface TranslationContext {\n documentId: string;\n diagnostics: Diagnostic[];\n references: Reference[];\n blockIdMap: Map<string, string>;\n}\n\n// ─── AST Node Type Guards ────────────────────────────────────\n\nfunction isGlyphUIBlock(node: GlyphUIBlock | MdastContentNode): node is GlyphUIBlock {\n return node.type === 'glyphUIBlock';\n}\n\n// ─── Main Translation Entry Point ────────────────────────────\n\n/**\n * Translate a single AST child node (either a GlyphUIBlock or a standard\n * MDAST content node) into an IR Block.\n *\n * Returns null for nodes that should be skipped (e.g., yaml frontmatter).\n *\n * @param node - The AST node to translate (GlyphUIBlock or standard MDAST content node).\n * @param ctx - Translation context carrying document ID, accumulated diagnostics, and references.\n * @returns The translated IR Block, or null if the node should be skipped.\n */\nexport function translateNode(\n node: GlyphUIBlock | MdastContentNode,\n ctx: TranslationContext,\n): Block | null {\n if (isGlyphUIBlock(node)) {\n return translateGlyphUIBlock(node, ctx);\n }\n return translateMdastNode(node, ctx);\n}\n\n// ─── Glyph UI Block Translation ─────────────────────────────\n\nfunction translateGlyphUIBlock(node: GlyphUIBlock, ctx: TranslationContext): Block {\n const componentType = node.componentType;\n const blockType: BlockType = `ui:${componentType}`;\n const position: SourcePosition = node.position ?? DEFAULT_POSITION;\n const blockDiagnostics: Diagnostic[] = [];\n\n // Determine block ID: user-assigned glyph-id or content-addressed\n const blockId = node.glyphId\n ? node.glyphId\n : generateBlockId(ctx.documentId, blockType, node.rawYaml);\n\n // Track the block ID mapping for reference resolution\n if (node.glyphId) {\n ctx.blockIdMap.set(node.glyphId, blockId);\n }\n\n // Handle YAML parse errors\n if (node.yamlError) {\n const diag = createYamlError(componentType, node.yamlError, position);\n blockDiagnostics.push(diag);\n ctx.diagnostics.push(diag);\n }\n\n // Determine block data\n let data: Record<string, unknown> = node.parsedData ?? {};\n\n // Validate against Zod schema if we have parsed data\n if (node.parsedData) {\n const schema = componentSchemas.get(componentType);\n if (schema) {\n const result = schema.safeParse(node.parsedData);\n if (!result.success) {\n const zodErrors = result.error.issues\n .map((issue) => `${issue.path.join('.')}: ${issue.message}`)\n .join('; ');\n const diag = createSchemaError(componentType, zodErrors, position, result.error.issues);\n blockDiagnostics.push(diag);\n ctx.diagnostics.push(diag);\n // Preserve the raw parsedData even on validation failure\n data = node.parsedData;\n } else {\n data = result.data as Record<string, unknown>;\n }\n } else {\n // Unknown component type — info diagnostic, preserve block as-is\n const diag = createUnknownComponentInfo(componentType, position);\n blockDiagnostics.push(diag);\n ctx.diagnostics.push(diag);\n }\n }\n\n // Process refs into references\n if (node.refs && node.refs.length > 0) {\n processRefs(node.refs, blockId, ctx);\n }\n\n const block: Block = {\n id: blockId,\n type: blockType,\n data,\n position,\n };\n\n if (node.interactive) {\n block.metadata = { interactive: true };\n }\n\n if (blockDiagnostics.length > 0) {\n block.diagnostics = blockDiagnostics;\n }\n\n return block;\n}\n\n// ─── Reference Processing ────────────────────────────────────\n\nfunction processRefs(refs: RawRef[], sourceBlockId: string, ctx: TranslationContext): void {\n for (const ref of refs) {\n const reference: Reference = {\n id: generateBlockId(ctx.documentId, 'ref', `${sourceBlockId}->${ref.target}`),\n type: (ref.type as Reference['type']) ?? 'navigates-to',\n sourceBlockId,\n targetBlockId: ref.target,\n };\n\n if (ref.label) {\n reference.label = ref.label;\n }\n if (ref.sourceAnchor) {\n reference.sourceAnchor = ref.sourceAnchor;\n }\n if (ref.targetAnchor) {\n reference.targetAnchor = ref.targetAnchor;\n }\n if (ref.bidirectional) {\n reference.bidirectional = ref.bidirectional;\n }\n\n // Mark as unresolved — we resolve later in the compile step\n reference.unresolved = true;\n\n ctx.references.push(reference);\n }\n}\n\n// ─── Standard MDAST Node Translation ─────────────────────────\n\nfunction translateMdastNode(node: MdastContentNode, ctx: TranslationContext): Block | null {\n const position: SourcePosition = node.position ?? DEFAULT_POSITION;\n\n switch (node.type) {\n case 'heading':\n return translateHeading(node, position, ctx);\n case 'paragraph':\n return translateParagraph(node, position, ctx);\n case 'list':\n return translateList(node, position, ctx);\n case 'code':\n return translateCode(node, position, ctx);\n case 'blockquote':\n return translateBlockquote(node, position, ctx);\n case 'image':\n return translateImage(node, position, ctx);\n case 'thematicBreak':\n return translateThematicBreak(position, ctx);\n case 'html':\n return translateHtml(node, position, ctx);\n case 'yaml':\n // Frontmatter is handled separately in compile.ts; skip here\n return null;\n default:\n // Unknown MDAST node type — skip silently\n return null;\n }\n}\n\n// ─── Individual Node Translators ─────────────────────────────\n\nfunction translateHeading(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const depth = (node['depth'] as number) ?? 1;\n const children = convertPhrasingContent((node.children ?? []) as unknown[]);\n const content = inlineNodesToText(children);\n\n return {\n id: generateBlockId(ctx.documentId, 'heading', content),\n type: 'heading',\n data: { depth, children },\n position,\n };\n}\n\nfunction translateParagraph(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const children = convertPhrasingContent((node.children ?? []) as unknown[]);\n const content = inlineNodesToText(children);\n\n return {\n id: generateBlockId(ctx.documentId, 'paragraph', content),\n type: 'paragraph',\n data: { children },\n position,\n };\n}\n\nfunction translateList(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const ordered = (node['ordered'] as boolean) ?? false;\n const start = ordered ? ((node['start'] as number) ?? 1) : undefined;\n const items = translateListItems((node.children ?? []) as MdastContentNode[]);\n const content = listDataToText({ ordered, start, items });\n\n const data: ListData = { ordered, items };\n if (start !== undefined) {\n data.start = start;\n }\n\n return {\n id: generateBlockId(ctx.documentId, 'list', content),\n type: 'list',\n data,\n position,\n };\n}\n\nfunction translateListItems(listItemNodes: MdastContentNode[]): ListItemData[] {\n const items: ListItemData[] = [];\n\n for (const itemNode of listItemNodes) {\n if (itemNode.type !== 'listItem') continue;\n\n const itemChildren = (itemNode.children ?? []) as MdastContentNode[];\n let inlineChildren: InlineNode[] = [];\n let subList: ListData | undefined;\n\n for (const child of itemChildren) {\n if (child.type === 'paragraph') {\n inlineChildren = convertPhrasingContent((child.children ?? []) as unknown[]);\n } else if (child.type === 'list') {\n const subOrdered = (child['ordered'] as boolean) ?? false;\n const subStart = subOrdered ? ((child['start'] as number) ?? 1) : undefined;\n const subItems = translateListItems((child.children ?? []) as MdastContentNode[]);\n subList = { ordered: subOrdered, items: subItems };\n if (subStart !== undefined) {\n subList.start = subStart;\n }\n }\n }\n\n const item: ListItemData = { children: inlineChildren };\n if (subList) {\n item.subList = subList;\n }\n items.push(item);\n }\n\n return items;\n}\n\nfunction translateCode(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const value = (node.value as string) ?? '';\n const language = (node['lang'] as string) ?? undefined;\n const meta = (node['meta'] as string) ?? undefined;\n\n const data: Record<string, unknown> = { value };\n if (language) {\n data['language'] = language;\n }\n if (meta) {\n data['meta'] = meta;\n }\n\n return {\n id: generateBlockId(ctx.documentId, 'code', value),\n type: 'code',\n data,\n position,\n };\n}\n\nfunction translateBlockquote(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n // Blockquote children are typically paragraphs — flatten their inline content\n const allInlineNodes: InlineNode[] = [];\n for (const child of (node.children ?? []) as MdastContentNode[]) {\n if (child.type === 'paragraph') {\n const inlines = convertPhrasingContent((child.children ?? []) as unknown[]);\n allInlineNodes.push(...inlines);\n }\n }\n const content = inlineNodesToText(allInlineNodes);\n\n return {\n id: generateBlockId(ctx.documentId, 'blockquote', content),\n type: 'blockquote',\n data: { children: allInlineNodes },\n position,\n };\n}\n\nfunction translateImage(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const src = (node['url'] as string) ?? '';\n const alt = (node['alt'] as string) ?? undefined;\n const title = (node['title'] as string) ?? undefined;\n\n const data: Record<string, unknown> = { src };\n if (alt) {\n data['alt'] = alt;\n }\n if (title) {\n data['title'] = title;\n }\n\n return {\n id: generateBlockId(ctx.documentId, 'image', src),\n type: 'image',\n data,\n position,\n };\n}\n\nfunction translateThematicBreak(position: SourcePosition, ctx: TranslationContext): Block {\n return {\n id: generateBlockId(ctx.documentId, 'thematic-break', '---'),\n type: 'thematic-break',\n data: {},\n position,\n };\n}\n\nfunction translateHtml(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const value = (node.value as string) ?? '';\n\n return {\n id: generateBlockId(ctx.documentId, 'html', value),\n type: 'html',\n data: { value },\n position,\n };\n}\n\n// ─── Text Extraction Helpers ─────────────────────────────────\n\n/**\n * Extract plain text from InlineNode[] for content-addressing purposes.\n */\nfunction inlineNodesToText(nodes: InlineNode[]): string {\n return nodes\n .map((node) => {\n switch (node.type) {\n case 'text':\n return node.value;\n case 'inlineCode':\n return node.value;\n case 'strong':\n case 'emphasis':\n case 'delete':\n return inlineNodesToText(node.children);\n case 'link':\n return inlineNodesToText(node.children);\n case 'image':\n return node.alt ?? '';\n case 'break':\n return '\\n';\n default:\n return '';\n }\n })\n .join('');\n}\n\n/**\n * Extract plain text from ListData for content-addressing purposes.\n */\nfunction listDataToText(data: ListData): string {\n return data.items\n .map((item) => {\n let text = inlineNodesToText(item.children);\n if (item.subList) {\n text += '\\n' + listDataToText(item.subList);\n }\n return text;\n })\n .join('\\n');\n}\n","import type {\n Block,\n Diagnostic,\n InlineNode,\n Reference,\n} from '@glyphjs/types';\nimport { generateBlockId } from '@glyphjs/ir';\nimport { createDiagnostic } from './diagnostics.js';\n\n// ─── Glyph Link Pattern ─────────────────────────────────────\n\n/**\n * Matches inline links of the form `[text](#glyph:block-id)`.\n * The captured group is the block ID after the `#glyph:` prefix.\n */\nconst GLYPH_LINK_PREFIX = '#glyph:';\n\n// ─── Inline Reference Scanning ──────────────────────────────\n\n/**\n * Scan a block's inline content for `[text](#glyph:block-id)` links\n * and create Reference objects for each match.\n *\n * @param block - The block whose inline data fields are scanned for glyph links.\n * @param documentId - Document ID used to generate deterministic reference IDs.\n * @returns Newly created (unresolved) Reference objects.\n */\nexport function extractInlineReferences(\n block: Block,\n documentId: string,\n): Reference[] {\n const references: Reference[] = [];\n const inlineNodes = extractInlineNodes(block);\n\n for (const node of inlineNodes) {\n if (node.type === 'link' && node.url.startsWith(GLYPH_LINK_PREFIX)) {\n const targetBlockId = node.url.slice(GLYPH_LINK_PREFIX.length);\n if (!targetBlockId) continue;\n\n const label = inlineNodesToPlainText(node.children);\n\n const reference: Reference = {\n id: generateBlockId(documentId, 'ref', `${block.id}->${targetBlockId}`),\n type: 'navigates-to',\n sourceBlockId: block.id,\n targetBlockId,\n unresolved: true,\n };\n\n if (label) {\n reference.label = label;\n }\n\n references.push(reference);\n }\n }\n\n return references;\n}\n\n/**\n * Scan all blocks (including nested children) for inline `#glyph:` link references\n * and collect them.\n *\n * @param blocks - Top-level block array to scan recursively.\n * @param documentId - Document ID used to generate deterministic reference IDs.\n * @returns Aggregated array of unresolved Reference objects from all blocks.\n */\nexport function extractAllInlineReferences(\n blocks: Block[],\n documentId: string,\n): Reference[] {\n const references: Reference[] = [];\n\n for (const block of blocks) {\n const blockRefs = extractInlineReferences(block, documentId);\n references.push(...blockRefs);\n\n // Also scan children (e.g. container blocks)\n if (block.children) {\n const childRefs = extractAllInlineReferences(block.children, documentId);\n references.push(...childRefs);\n }\n }\n\n return references;\n}\n\n// ─── Reference Resolution ────────────────────────────────────\n\n/**\n * Resolve references by checking if target block IDs exist in the document.\n * Marks unresolved references and adds warning diagnostics.\n *\n * Collects all block IDs including children (for container blocks).\n *\n * @param references - The reference array to resolve in-place (mutates `unresolved` flag).\n * @param blocks - All blocks in the document (used to build the known-ID set).\n * @param diagnostics - Accumulator for 'UNRESOLVED_REFERENCE' warnings.\n */\nexport function resolveReferences(\n references: Reference[],\n blocks: Block[],\n diagnostics: Diagnostic[],\n): void {\n const blockIdSet = collectAllBlockIds(blocks);\n\n for (const ref of references) {\n if (blockIdSet.has(ref.targetBlockId)) {\n ref.unresolved = false;\n } else {\n ref.unresolved = true;\n diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'warning',\n 'UNRESOLVED_REFERENCE',\n `Reference target \"${ref.targetBlockId}\" was not found in the document.`,\n ),\n );\n }\n }\n}\n\n/**\n * Collect all block IDs from blocks and their children recursively.\n */\nfunction collectAllBlockIds(blocks: Block[]): Set<string> {\n const ids = new Set<string>();\n for (const block of blocks) {\n ids.add(block.id);\n if (block.children) {\n for (const id of collectAllBlockIds(block.children)) {\n ids.add(id);\n }\n }\n }\n return ids;\n}\n\n// ─── Glyph-ID Uniqueness Validation ─────────────────────────\n\n/**\n * Validate that all user-assigned glyph-ids are unique within the document.\n * Emits error diagnostics for duplicates.\n *\n * @param blockIdMap - Map of user-assigned glyph-id to resolved block ID (from translation).\n * @param blocks - All blocks in the document (scanned to count occurrences).\n * @param diagnostics - Accumulator for 'DUPLICATE_GLYPH_ID' error diagnostics.\n */\nexport function validateGlyphIdUniqueness(\n blockIdMap: Map<string, string>,\n blocks: Block[],\n diagnostics: Diagnostic[],\n): void {\n // blockIdMap tracks glyphId -> blockId, but we need to detect duplicates\n // by scanning blocks for those whose id matches a glyph-id key\n const glyphIdOccurrences = new Map<string, number>();\n\n for (const glyphId of blockIdMap.keys()) {\n const count = countBlocksWithGlyphId(blocks, glyphId);\n glyphIdOccurrences.set(glyphId, count);\n }\n\n for (const [glyphId, count] of glyphIdOccurrences) {\n if (count > 1) {\n diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'error',\n 'DUPLICATE_GLYPH_ID',\n `Duplicate glyph-id \"${glyphId}\" found on ${String(count)} blocks. Block IDs must be unique within a document.`,\n ),\n );\n }\n }\n}\n\n/**\n * Count how many blocks in the array have a given ID (which came from a glyph-id).\n */\nfunction countBlocksWithGlyphId(blocks: Block[], glyphId: string): number {\n let count = 0;\n for (const block of blocks) {\n if (block.id === glyphId) {\n count++;\n }\n }\n return count;\n}\n\n// ─── Inline Node Extraction Helpers ──────────────────────────\n\n/**\n * Extract all InlineNode arrays from a block's data field.\n * Handles heading, paragraph, blockquote, and list blocks.\n */\nfunction extractInlineNodes(block: Block): InlineNode[] {\n const data = block.data as Record<string, unknown>;\n const nodes: InlineNode[] = [];\n\n // Blocks with a direct `children` inline array\n if (Array.isArray(data['children'])) {\n nodes.push(...(data['children'] as InlineNode[]));\n }\n\n // List blocks: extract inline nodes from items\n if (Array.isArray(data['items'])) {\n for (const item of data['items'] as { children?: InlineNode[]; subList?: { items?: unknown[] } }[]) {\n if (Array.isArray(item.children)) {\n nodes.push(...item.children);\n }\n }\n }\n\n return nodes;\n}\n\n/**\n * Extract plain text from InlineNode[] for label purposes.\n */\nfunction inlineNodesToPlainText(nodes: InlineNode[]): string {\n return nodes\n .map((node) => {\n switch (node.type) {\n case 'text':\n return node.value;\n case 'inlineCode':\n return node.value;\n case 'strong':\n case 'emphasis':\n case 'delete':\n return inlineNodesToPlainText(node.children);\n case 'link':\n return inlineNodesToPlainText(node.children);\n case 'image':\n return node.alt ?? '';\n case 'break':\n return '\\n';\n default:\n return '';\n }\n })\n .join('');\n}\n","import type { Block, Diagnostic } from '@glyphjs/types';\nimport { parseGlyphMarkdown } from '@glyphjs/parser';\nimport { translateNode } from './ast-to-ir.js';\nimport type { TranslationContext } from './ast-to-ir.js';\nimport { createDiagnostic } from './diagnostics.js';\n\n// ─── Container Block Compilation ─────────────────────────────\n\n/**\n * Process container blocks (ui:tabs and ui:steps) by recursively parsing\n * their content fields as Markdown into child Block[] arrays.\n *\n * This function mutates blocks in-place, populating their `children` field\n * and updating data entries with parsed child blocks.\n *\n * @param blocks - The top-level block array to scan for container blocks.\n * @param ctx - Translation context used for recursive compilation.\n */\nexport function compileContainerBlocks(\n blocks: Block[],\n ctx: TranslationContext,\n): void {\n for (const block of blocks) {\n if (block.type === 'ui:tabs') {\n compileTabsBlock(block, ctx);\n } else if (block.type === 'ui:steps') {\n compileStepsBlock(block, ctx);\n }\n }\n}\n\n// ─── Tabs Compilation ────────────────────────────────────────\n\nfunction compileTabsBlock(block: Block, ctx: TranslationContext): void {\n const data = block.data as Record<string, unknown>;\n const tabs = data['tabs'];\n\n if (!Array.isArray(tabs)) return;\n\n const allChildren: Block[] = [];\n\n for (const tab of tabs as { label?: string; content?: string }[]) {\n if (typeof tab.content !== 'string') continue;\n\n const childBlocks = parseContentToBlocks(tab.content, block, ctx);\n allChildren.push(...childBlocks);\n }\n\n if (allChildren.length > 0) {\n block.children = allChildren;\n }\n}\n\n// ─── Steps Compilation ───────────────────────────────────────\n\nfunction compileStepsBlock(block: Block, ctx: TranslationContext): void {\n const data = block.data as Record<string, unknown>;\n const steps = data['steps'];\n\n if (!Array.isArray(steps)) return;\n\n const allChildren: Block[] = [];\n\n for (const step of steps as { title?: string; status?: string; content?: string }[]) {\n if (typeof step.content !== 'string') continue;\n\n const childBlocks = parseContentToBlocks(step.content, block, ctx);\n allChildren.push(...childBlocks);\n }\n\n if (allChildren.length > 0) {\n block.children = allChildren;\n }\n}\n\n// ─── Content Parsing Helper ──────────────────────────────────\n\n/**\n * Parse a Markdown content string into Block[] using the compiler pipeline.\n * Emits a warning diagnostic if nested ui: components are found (deferred to v2).\n */\nfunction parseContentToBlocks(\n content: string,\n parentBlock: Block,\n ctx: TranslationContext,\n): Block[] {\n const ast = parseGlyphMarkdown(content);\n const blocks: Block[] = [];\n\n for (const child of ast.children) {\n // Check for nested ui: components — warn and skip\n if (child.type === 'glyphUIBlock') {\n ctx.diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'warning',\n 'NESTED_UI_COMPONENT',\n `Nested ui: component found inside container block \"${parentBlock.id}\". ` +\n `Nested ui: components inside tabs/steps are not supported in v1 and will be ignored.`,\n child.position,\n ),\n );\n continue;\n }\n\n const block = translateNode(child, ctx);\n if (block) {\n blocks.push(block);\n }\n }\n\n return blocks;\n}\n\n// ─── Nested UI Detection ─────────────────────────────────────\n\n/**\n * Check if content contains nested ui: blocks by looking for the pattern.\n * This is a quick heuristic check. The actual detection happens during parsing.\n *\n * @param content - Raw Markdown string to test for nested ui: fenced blocks.\n * @returns True if the content matches the `` ```ui: `` pattern.\n */\nexport function hasNestedUiBlocks(content: string): boolean {\n return /```ui:/m.test(content);\n}\n\n// ─── Validate Container Diagnostics ──────────────────────────\n\n/**\n * Post-process container blocks to ensure data consistency.\n * Called after container compilation is complete.\n *\n * @param blocks - The compiled block array to validate.\n * @param diagnostics - Accumulator for warning diagnostics (e.g., missing labels/titles).\n */\nexport function validateContainerBlocks(\n blocks: Block[],\n diagnostics: Diagnostic[],\n): void {\n for (const block of blocks) {\n if (block.type === 'ui:tabs') {\n validateTabsData(block, diagnostics);\n } else if (block.type === 'ui:steps') {\n validateStepsData(block, diagnostics);\n }\n }\n}\n\nfunction validateTabsData(block: Block, _diagnostics: Diagnostic[]): void {\n const data = block.data as Record<string, unknown>;\n const tabs = data['tabs'];\n\n if (!Array.isArray(tabs) || tabs.length === 0) {\n return;\n }\n\n // Ensure each tab has a label\n for (const tab of tabs as { label?: string }[]) {\n if (!tab.label) {\n _diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'warning',\n 'MISSING_TAB_LABEL',\n `A tab in block \"${block.id}\" is missing a label.`,\n block.position,\n ),\n );\n }\n }\n}\n\nfunction validateStepsData(block: Block, _diagnostics: Diagnostic[]): void {\n const data = block.data as Record<string, unknown>;\n const steps = data['steps'];\n\n if (!Array.isArray(steps) || steps.length === 0) {\n return;\n }\n\n // Ensure each step has a title\n for (const step of steps as { title?: string }[]) {\n if (!step.title) {\n _diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'warning',\n 'MISSING_STEP_TITLE',\n `A step in block \"${block.id}\" is missing a title.`,\n block.position,\n ),\n );\n }\n }\n}\n","import type {\n GlyphIR,\n CompilationResult,\n Diagnostic,\n DocumentMetadata,\n LayoutHints,\n Block,\n Reference,\n MdastContentNode,\n} from '@glyphjs/types';\nimport { parseGlyphMarkdown } from '@glyphjs/parser';\nimport { generateDocumentId, resolveBlockIdCollisions } from '@glyphjs/ir';\nimport { parse as parseYaml } from 'yaml';\nimport { translateNode } from './ast-to-ir.js';\nimport type { TranslationContext } from './ast-to-ir.js';\nimport { createDiagnostic } from './diagnostics.js';\nimport {\n extractAllInlineReferences,\n resolveReferences,\n validateGlyphIdUniqueness,\n} from './references.js';\nimport { compileContainerBlocks, validateContainerBlocks } from './containers.js';\n\n// ─── Public Interface ────────────────────────────────────────\n\nexport interface CompileOptions {\n /** Source file path, used for document ID generation. */\n filePath?: string;\n /** Explicit document ID override. */\n documentId?: string;\n}\n\n// ─── Main Compile Function ───────────────────────────────────\n\n/**\n * Compile a Markdown string into Glyph IR.\n *\n * Steps:\n * 1. Parse the markdown via `parseGlyphMarkdown`\n * 2. Extract frontmatter metadata and layout hints\n * 3. Walk the AST and translate each node to IR blocks\n * 4. Validate ui: blocks against Zod schemas\n * 5. Compile container blocks (ui:tabs, ui:steps) — recursively parse content\n * 6. Validate container block data\n * 7. Generate content-addressed block IDs\n * 8. Generate the document ID\n * 9. Resolve block ID collisions\n * 10. Validate glyph-id uniqueness\n * 11. Extract inline references from `[text](#glyph:block-id)` links\n * 12. Resolve all references (from refs arrays and inline links)\n * 13. Infer metadata from content if not in frontmatter\n * 14. Return CompilationResult with IR, diagnostics, and hasErrors flag\n *\n * Uses a collect-all-errors strategy: IR is always produced, even when errors exist.\n */\nexport function compile(markdown: string, options?: CompileOptions): CompilationResult {\n const diagnostics: Diagnostic[] = [];\n\n // 1. Parse the markdown into a Glyph AST\n const ast = parseGlyphMarkdown(markdown);\n\n // 2. Extract frontmatter\n const { metadata, layout, frontmatterGlyphId } = extractFrontmatter(ast.children, diagnostics);\n\n // 3. Generate document ID\n const documentId =\n options?.documentId ??\n generateDocumentId({\n glyphId: frontmatterGlyphId,\n filePath: options?.filePath,\n content: markdown,\n });\n\n // Set sourceFile from options if available\n if (options?.filePath && !metadata.sourceFile) {\n metadata.sourceFile = options.filePath;\n }\n\n // 4. Create translation context\n const references: Reference[] = [];\n const ctx: TranslationContext = {\n documentId,\n diagnostics,\n references,\n blockIdMap: new Map(),\n };\n\n // 5. Walk the AST and translate nodes\n const blocks: Block[] = [];\n for (const child of ast.children) {\n const block = translateNode(child, ctx);\n if (block) {\n blocks.push(block);\n }\n }\n\n // 6. Compile container blocks (ui:tabs, ui:steps) — recursively parse content fields\n compileContainerBlocks(blocks, ctx);\n\n // 7. Validate container block data\n validateContainerBlocks(blocks, diagnostics);\n\n // 8. Infer metadata from content if not in frontmatter\n inferMetadata(metadata, blocks);\n\n // 9. Resolve block ID collisions\n const blockIds = blocks.map((b) => b.id);\n const resolvedIds = resolveBlockIdCollisions(blockIds);\n for (let i = 0; i < blocks.length; i++) {\n const block = blocks[i];\n const resolvedId = resolvedIds[i];\n if (block && resolvedId) {\n block.id = resolvedId;\n }\n }\n\n // 10. Validate glyph-id uniqueness\n validateGlyphIdUniqueness(ctx.blockIdMap, blocks, diagnostics);\n\n // 11. Extract inline references from [text](#glyph:block-id) links\n const inlineRefs = extractAllInlineReferences(blocks, documentId);\n references.push(...inlineRefs);\n\n // 12. Resolve all references (from refs arrays and inline links)\n resolveReferences(references, blocks, diagnostics);\n\n // 13. Build the IR\n const ir: GlyphIR = {\n version: '1.0.0',\n id: documentId,\n metadata,\n blocks,\n references,\n layout,\n };\n\n const hasErrors = diagnostics.some((d) => d.severity === 'error');\n\n return { ir, diagnostics, hasErrors };\n}\n\n// ─── Frontmatter Extraction ─────────────────────────────────\n\ninterface FrontmatterResult {\n metadata: DocumentMetadata;\n layout: LayoutHints;\n frontmatterGlyphId?: string;\n}\n\nfunction extractFrontmatter(\n children: readonly unknown[],\n diagnostics: Diagnostic[],\n): FrontmatterResult {\n const metadata: DocumentMetadata = {};\n let layout: LayoutHints = { mode: 'document', spacing: 'normal' };\n let frontmatterGlyphId: string | undefined;\n\n // Look for yaml frontmatter node (always first child if present)\n const firstChild = children[0] as MdastContentNode | undefined;\n if (firstChild && firstChild.type === 'yaml' && typeof firstChild.value === 'string') {\n try {\n const parsed: unknown = parseYaml(firstChild.value);\n if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {\n const fm = parsed as Record<string, unknown>;\n\n // Extract glyph-id\n if (typeof fm['glyph-id'] === 'string') {\n frontmatterGlyphId = fm['glyph-id'];\n }\n\n // Extract metadata fields\n if (typeof fm['title'] === 'string') {\n metadata.title = fm['title'];\n }\n if (typeof fm['description'] === 'string') {\n metadata.description = fm['description'];\n }\n if (Array.isArray(fm['authors'])) {\n metadata.authors = fm['authors'].filter(\n (a): a is string => typeof a === 'string',\n );\n }\n if (typeof fm['createdAt'] === 'string') {\n metadata.createdAt = fm['createdAt'];\n }\n if (Array.isArray(fm['tags'])) {\n metadata.tags = fm['tags'].filter(\n (t): t is string => typeof t === 'string',\n );\n }\n\n // Extract layout hints\n if (fm['layout'] && typeof fm['layout'] === 'object' && !Array.isArray(fm['layout'])) {\n const rawLayout = fm['layout'] as Record<string, unknown>;\n layout = {\n mode: isLayoutMode(rawLayout['mode']) ? rawLayout['mode'] : 'document',\n spacing: isLayoutSpacing(rawLayout['spacing']) ? rawLayout['spacing'] : 'normal',\n };\n if (typeof rawLayout['columns'] === 'number') {\n layout.columns = rawLayout['columns'];\n }\n if (typeof rawLayout['maxWidth'] === 'string') {\n layout.maxWidth = rawLayout['maxWidth'];\n }\n }\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : String(err);\n diagnostics.push(\n createDiagnostic(\n 'parser',\n 'error',\n 'FRONTMATTER_PARSE_ERROR',\n `Failed to parse frontmatter YAML: ${message}`,\n firstChild.position,\n ),\n );\n }\n }\n\n return { metadata, layout, frontmatterGlyphId };\n}\n\nfunction isLayoutMode(value: unknown): value is LayoutHints['mode'] {\n return value === 'document' || value === 'dashboard' || value === 'presentation';\n}\n\nfunction isLayoutSpacing(value: unknown): value is 'compact' | 'normal' | 'relaxed' {\n return value === 'compact' || value === 'normal' || value === 'relaxed';\n}\n\n// ─── Metadata Inference ──────────────────────────────────────\n\n/**\n * Infer metadata from content when not provided via frontmatter.\n * - title: from the first h1 heading\n * - description: from the first paragraph\n */\nfunction inferMetadata(metadata: DocumentMetadata, blocks: Block[]): void {\n if (!metadata.title) {\n const firstHeading = blocks.find(\n (b) => b.type === 'heading' && (b.data as Record<string, unknown>)['depth'] === 1,\n );\n if (firstHeading) {\n const data = firstHeading.data as { children?: { type: string; value?: string }[] };\n if (data.children) {\n metadata.title = data.children\n .map((node) => {\n if ('value' in node && typeof node.value === 'string') {\n return node.value;\n }\n return '';\n })\n .join('');\n }\n }\n }\n\n if (!metadata.description) {\n const firstParagraph = blocks.find((b) => b.type === 'paragraph');\n if (firstParagraph) {\n const data = firstParagraph.data as { children?: { type: string; value?: string }[] };\n if (data.children) {\n metadata.description = data.children\n .map((node) => {\n if ('value' in node && typeof node.value === 'string') {\n return node.value;\n }\n return '';\n })\n .join('');\n }\n }\n }\n}\n\n"]}
1
+ {"version":3,"sources":["../src/inline.ts","../src/diagnostics.ts","../src/ast-to-ir.ts","../src/references.ts","../src/containers.ts","../src/compile.ts"],"names":["generateBlockId","parseGlyphMarkdown","parseYaml"],"mappings":";;;;;;;;AAyEO,SAAS,uBAAuB,KAAA,EAAgC;AACrE,EAAA,MAAM,SAAuB,EAAC;AAE9B,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,MAAM,SAAA,GAAY,kBAAkB,IAA4B,CAAA;AAChE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ode } from '@glyphjs/types';\nimport type { Diagnostic } from '@glyphjs/types';\nimport { unified } from 'unified';\nimport remarkParse from 'remark-parse';\n\n// ─── MDAST Phrasing Content Types ───────────────────────────\n// These are structural types matching the shapes from mdast,\n// avoiding a hard dependency on @types/mdast.\n\ninterface MdastText {\n type: 'text';\n value: string;\n}\n\ninterface MdastStrong {\n type: 'strong';\n children: MdastPhrasingContent[];\n}\n\ninterface MdastEmphasis {\n type: 'emphasis';\n children: MdastPhrasingContent[];\n}\n\ninterface MdastDelete {\n type: 'delete';\n children: MdastPhrasingContent[];\n}\n\ninterface MdastInlineCode {\n type: 'inlineCode';\n value: string;\n}\n\ninterface MdastLink {\n type: 'link';\n url: string;\n title?: string | null;\n children: MdastPhrasingContent[];\n}\n\ninterface MdastImage {\n type: 'image';\n url: string;\n alt?: string | null;\n title?: string | null;\n}\n\ninterface MdastBreak {\n type: 'break';\n}\n\ntype MdastPhrasingContent =\n | MdastText\n | MdastStrong\n | MdastEmphasis\n | MdastDelete\n | MdastInlineCode\n | MdastLink\n | MdastImage\n | MdastBreak;\n\n// ─── Conversion ─────────────────────────────────────────────\n\n/**\n * Convert an array of MDAST phrasing content nodes to InlineNode[].\n *\n * Unknown node types are converted to text nodes with their string value\n * (if present) or skipped entirely.\n *\n * @param nodes - Raw MDAST phrasing content nodes (typed as unknown[] to avoid a hard @types/mdast dependency).\n * @returns Normalized InlineNode array suitable for inclusion in IR blocks.\n */\nexport function convertPhrasingContent(nodes: unknown[]): InlineNode[] {\n const result: InlineNode[] = [];\n\n for (const node of nodes) {\n const converted = convertSingleNode(node as MdastPhrasingContent);\n if (converted) {\n result.push(converted);\n }\n }\n\n return result;\n}\n\nfunction convertSingleNode(node: MdastPhrasingContent): InlineNode | null {\n switch (node.type) {\n case 'text':\n return { type: 'text', value: node.value };\n\n case 'strong':\n return {\n type: 'strong',\n children: convertPhrasingContent(node.children),\n };\n\n case 'emphasis':\n return {\n type: 'emphasis',\n children: convertPhrasingContent(node.children),\n };\n\n case 'delete':\n return {\n type: 'delete',\n children: convertPhrasingContent(node.children),\n };\n\n case 'inlineCode':\n return { type: 'inlineCode', value: node.value };\n\n case 'link': {\n const linkNode: InlineNode = {\n type: 'link',\n url: node.url,\n children: convertPhrasingContent(node.children),\n };\n if (node.title != null) {\n (linkNode as { type: 'link'; url: string; title?: string; children: InlineNode[] }).title =\n node.title;\n }\n return linkNode;\n }\n\n case 'image': {\n const imgNode: InlineNode = {\n type: 'image',\n src: node.url,\n };\n if (node.alt != null) {\n (imgNode as { type: 'image'; src: string; alt?: string; title?: string }).alt = node.alt;\n }\n if (node.title != null) {\n (imgNode as { type: 'image'; src: string; alt?: string; title?: string }).title =\n node.title;\n }\n return imgNode;\n }\n\n case 'break':\n return { type: 'break' };\n\n default: {\n // For unknown phrasing content types, attempt to extract a text value\n const unknown = node as Record<string, unknown>;\n if (typeof unknown['value'] === 'string') {\n return { type: 'text', value: unknown['value'] };\n }\n return null;\n }\n }\n}\n\n// ─── Markdown String Parser ─────────────────────────────────────\n\n/**\n * Parse a string containing inline markdown into InlineNode[].\n *\n * Uses remark-parse to parse the text, extracts phrasing content from\n * the first paragraph. Only supports inline elements (bold, italic, links, code).\n * Block elements trigger diagnostic warnings.\n *\n * Edge cases:\n * - Empty string → `[]`\n * - Plain text → `[{ type: 'text', value: text }]`\n * - Block elements (headings, lists) → diagnostic warning, extract text only\n *\n * @param text - Markdown string to parse\n * @param diagnostics - Optional array to collect warnings (e.g., for block elements)\n * @returns Array of InlineNode elements\n */\nexport function parseInlineMarkdown(text: string, diagnostics?: Diagnostic[]): InlineNode[] {\n // Handle empty string\n if (text.trim() === '') {\n return [];\n }\n\n // Parse markdown using unified + remark-parse\n const processor = unified().use(remarkParse);\n const tree = processor.parse(text);\n\n // Type guard for MDAST root node\n interface MdastRoot {\n type: 'root';\n children: { type: string; children?: unknown[] }[];\n }\n\n const root = tree as unknown as MdastRoot;\n\n if (!root.children || root.children.length === 0) {\n // No content parsed\n return [{ type: 'text', value: text }];\n }\n\n // Check for block-level elements (not just paragraph)\n const hasBlockElements = root.children.some(\n (child) =>\n child.type !== 'paragraph' &&\n child.type !== 'text' &&\n !['strong', 'emphasis', 'delete', 'inlineCode', 'link', 'image', 'break'].includes(\n child.type,\n ),\n );\n\n if (hasBlockElements && diagnostics) {\n diagnostics.push({\n severity: 'warning',\n code: 'INLINE_BLOCK_ELEMENTS',\n message:\n 'Block-level markdown elements (headings, lists, etc.) are not supported in inline text fields. Only inline formatting (bold, italic, links, code) will be preserved.',\n source: 'compiler',\n });\n }\n\n // Extract first paragraph's children, or fall back to all inline children\n const firstParagraph = root.children.find((child) => child.type === 'paragraph');\n\n if (firstParagraph && firstParagraph.children) {\n return convertPhrasingContent(firstParagraph.children);\n }\n\n // If no paragraph found but we have inline-only children, convert them\n const inlineChildren = root.children.filter((child) =>\n ['text', 'strong', 'emphasis', 'delete', 'inlineCode', 'link', 'image', 'break'].includes(\n child.type,\n ),\n );\n\n if (inlineChildren.length > 0) {\n return convertPhrasingContent(inlineChildren);\n }\n\n // Fallback: return plain text\n return [{ type: 'text', value: text }];\n}\n","import type { Diagnostic, DiagnosticSource, SourcePosition } from '@glyphjs/types';\n\n// ─── Diagnostic Creation Helpers ─────────────────────────────\n\n/**\n * Create a diagnostic with the given source, severity, message, and optional position.\n *\n * @param source - The subsystem that produced the diagnostic (e.g., 'compiler', 'parser', 'schema').\n * @param severity - Severity level: 'error', 'warning', or 'info'.\n * @param code - Machine-readable diagnostic code (e.g., 'YAML_PARSE_ERROR').\n * @param message - Human-readable description of the issue.\n * @param position - Optional source position where the issue was detected.\n * @param details - Optional structured details (e.g., Zod issue objects).\n * @returns A fully constructed Diagnostic object.\n */\nexport function createDiagnostic(\n source: DiagnosticSource,\n severity: Diagnostic['severity'],\n code: string,\n message: string,\n position?: SourcePosition,\n details?: unknown,\n): Diagnostic {\n const diag: Diagnostic = { severity, code, message, source };\n if (position) {\n diag.position = position;\n }\n if (details !== undefined) {\n diag.details = details;\n }\n return diag;\n}\n\n/**\n * Create a schema validation error diagnostic.\n *\n * @param componentType - The ui: component type that failed validation (without the `ui:` prefix).\n * @param message - Concatenated validation error messages from Zod.\n * @param position - Optional source position of the component block.\n * @param details - Optional raw Zod issue objects.\n * @returns A Diagnostic with severity 'error' and code 'SCHEMA_VALIDATION_FAILED'.\n */\nexport function createSchemaError(\n componentType: string,\n message: string,\n position?: SourcePosition,\n details?: unknown,\n): Diagnostic {\n return createDiagnostic(\n 'schema',\n 'error',\n 'SCHEMA_VALIDATION_FAILED',\n `Schema validation failed for ui:${componentType}: ${message}`,\n position,\n details,\n );\n}\n\n/**\n * Create an info diagnostic for unknown component types.\n *\n * @param componentType - The unrecognized component type (without the `ui:` prefix).\n * @param position - Optional source position of the component block.\n * @returns A Diagnostic with severity 'info' and code 'UNKNOWN_COMPONENT_TYPE'.\n */\nexport function createUnknownComponentInfo(\n componentType: string,\n position?: SourcePosition,\n): Diagnostic {\n return createDiagnostic(\n 'compiler',\n 'info',\n 'UNKNOWN_COMPONENT_TYPE',\n `Unknown component type \"ui:${componentType}\". Block preserved as-is.`,\n position,\n );\n}\n\n/**\n * Create a diagnostic for YAML parse errors on ui: blocks.\n *\n * @param componentType - The ui: component type whose YAML failed to parse (without the `ui:` prefix).\n * @param yamlError - The YAML parser error message.\n * @param position - Optional source position of the fenced code block.\n * @returns A Diagnostic with severity 'error' and code 'YAML_PARSE_ERROR'.\n */\nexport function createYamlError(\n componentType: string,\n yamlError: string,\n position?: SourcePosition,\n): Diagnostic {\n return createDiagnostic(\n 'parser',\n 'error',\n 'YAML_PARSE_ERROR',\n `YAML parse error in ui:${componentType}: ${yamlError}`,\n position,\n );\n}\n","import type {\n Block,\n BlockType,\n Diagnostic,\n GlyphUIBlock,\n MdastContentNode,\n SourcePosition,\n Reference,\n RawRef,\n ListData,\n ListItemData,\n InlineNode,\n} from '@glyphjs/types';\nimport { generateBlockId } from '@glyphjs/ir';\nimport { componentSchemas } from '@glyphjs/schemas';\nimport { convertPhrasingContent, parseInlineMarkdown } from './inline.js';\nimport { createSchemaError, createUnknownComponentInfo, createYamlError } from './diagnostics.js';\nimport type { CompileOptions } from './compile.js';\n\n// ─── Default Source Position ─────────────────────────────────\n\nconst DEFAULT_POSITION: SourcePosition = {\n start: { line: 0, column: 0 },\n end: { line: 0, column: 0 },\n};\n\n// ─── Translation Context ────────────────────────────────────\n\nexport interface TranslationContext {\n documentId: string;\n diagnostics: Diagnostic[];\n references: Reference[];\n blockIdMap: Map<string, string>;\n compileOptions: CompileOptions;\n}\n\n// ─── AST Node Type Guards ────────────────────────────────────\n\nfunction isGlyphUIBlock(node: GlyphUIBlock | MdastContentNode): node is GlyphUIBlock {\n return node.type === 'glyphUIBlock';\n}\n\n// ─── Markdown Field Processing ──────────────────────────────\n\n/**\n * Field mapping table: defines which component text fields support markdown.\n * Format: componentType -> array of field paths (supports nested paths like \"items[].text\")\n */\nconst MARKDOWN_FIELD_MAP: Record<string, string[]> = {\n callout: ['content', 'title'],\n card: ['cards[].body', 'cards[].subtitle'],\n accordion: ['sections[].content'],\n steps: ['steps[].content'],\n kpi: ['metrics[].label'],\n comparison: ['options[].description', 'features[].values[]'],\n quiz: ['questions[].question', 'questions[].explanation', 'questions[].options[]'],\n infographic: ['sections[].items[].text', 'sections[].items[].description'],\n timeline: ['events[].title', 'events[].description'],\n poll: ['question', 'options[].label'],\n rating: ['label', 'description'],\n ranker: ['items[].label'],\n slider: ['label'],\n matrix: ['rowLabels[]', 'columnLabels[]'],\n annotate: ['annotations[].text'],\n form: ['description'],\n};\n\n/**\n * Process component data to parse markdown text fields into InlineNode[].\n * Checks if markdown is enabled (component-level flag OR global option).\n * Recursively processes nested objects and arrays based on field mapping.\n *\n * @param componentType - Component type (without \"ui:\" prefix)\n * @param data - Component data object\n * @param ctx - Translation context with compiler options and diagnostics\n * @returns Processed data with markdown fields converted to InlineNode[]\n */\nfunction processMarkdownFields(\n componentType: string,\n data: Record<string, unknown>,\n ctx: TranslationContext,\n): Record<string, unknown> {\n // Check if markdown is enabled (component-level flag OR global option)\n const markdownEnabled =\n (data.markdown as boolean) === true || ctx.compileOptions.parseComponentMarkdown === true;\n\n if (!markdownEnabled) {\n return data;\n }\n\n // Get field paths for this component type\n const fieldPaths = MARKDOWN_FIELD_MAP[componentType];\n if (!fieldPaths || fieldPaths.length === 0) {\n return data;\n }\n\n // Clone data to avoid mutations\n const result = { ...data };\n\n // Process each field path\n for (const path of fieldPaths) {\n processFieldPath(result, path, ctx.diagnostics);\n }\n\n return result;\n\n /**\n * Recursively process a field path (e.g., \"items[].text\" or \"question\")\n */\n function processFieldPath(\n obj: Record<string, unknown>,\n path: string,\n diagnostics: Diagnostic[],\n ): void {\n // Split path into segments (e.g., \"items[].text\" -> [\"items[]\", \"text\"])\n const segments = path.split('.');\n processSegments(obj, segments, diagnostics);\n }\n\n /**\n * Process path segments recursively\n */\n function processSegments(\n obj: Record<string, unknown>,\n segments: string[],\n diagnostics: Diagnostic[],\n ): void {\n if (segments.length === 0) return;\n\n const [first, ...rest] = segments;\n\n // Type guard: first must be defined\n if (!first) return;\n\n // Check if segment is array notation (e.g., \"items[]\")\n if (first.endsWith('[]')) {\n const fieldName = first.slice(0, -2);\n const value = obj[fieldName];\n\n if (Array.isArray(value)) {\n if (rest.length === 0) {\n // This array contains strings to process directly\n // This case handles paths like \"options[]\" where the array elements are strings\n obj[fieldName] = value.map((item) => {\n if (typeof item === 'string') {\n return parseInlineMarkdown(item, diagnostics);\n }\n return item;\n });\n } else {\n // Array contains objects, process nested fields\n for (const item of value) {\n if (typeof item === 'object' && item !== null) {\n processSegments(item as Record<string, unknown>, rest, diagnostics);\n }\n }\n }\n }\n } else {\n // Regular field\n if (rest.length === 0) {\n // Leaf node - process the string field\n const value = obj[first];\n if (typeof value === 'string') {\n obj[first] = parseInlineMarkdown(value, diagnostics);\n }\n } else {\n // Continue traversing\n const value = obj[first];\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n processSegments(value as Record<string, unknown>, rest, diagnostics);\n }\n }\n }\n }\n}\n\n// ─── Main Translation Entry Point ────────────────────────────\n\n/**\n * Translate a single AST child node (either a GlyphUIBlock or a standard\n * MDAST content node) into an IR Block.\n *\n * Returns null for nodes that should be skipped (e.g., yaml frontmatter).\n *\n * @param node - The AST node to translate (GlyphUIBlock or standard MDAST content node).\n * @param ctx - Translation context carrying document ID, accumulated diagnostics, and references.\n * @returns The translated IR Block, or null if the node should be skipped.\n */\nexport function translateNode(\n node: GlyphUIBlock | MdastContentNode,\n ctx: TranslationContext,\n): Block | null {\n if (isGlyphUIBlock(node)) {\n return translateGlyphUIBlock(node, ctx);\n }\n return translateMdastNode(node, ctx);\n}\n\n// ─── Glyph UI Block Translation ─────────────────────────────\n\nfunction translateGlyphUIBlock(node: GlyphUIBlock, ctx: TranslationContext): Block {\n const componentType = node.componentType;\n const blockType: BlockType = `ui:${componentType}`;\n const position: SourcePosition = node.position ?? DEFAULT_POSITION;\n const blockDiagnostics: Diagnostic[] = [];\n\n // Determine block ID: user-assigned glyph-id or content-addressed\n const blockId = node.glyphId\n ? node.glyphId\n : generateBlockId(ctx.documentId, blockType, node.rawYaml);\n\n // Track the block ID mapping for reference resolution\n if (node.glyphId) {\n ctx.blockIdMap.set(node.glyphId, blockId);\n }\n\n // Handle YAML parse errors\n if (node.yamlError) {\n const diag = createYamlError(componentType, node.yamlError, position);\n blockDiagnostics.push(diag);\n ctx.diagnostics.push(diag);\n }\n\n // Determine block data\n let data: Record<string, unknown> = node.parsedData ?? {};\n\n // Validate against Zod schema if we have parsed data\n if (node.parsedData) {\n const schema = componentSchemas.get(componentType);\n if (schema) {\n const result = schema.safeParse(node.parsedData);\n if (!result.success) {\n const zodErrors = result.error.issues\n .map((issue) => `${issue.path.join('.')}: ${issue.message}`)\n .join('; ');\n const diag = createSchemaError(componentType, zodErrors, position, result.error.issues);\n blockDiagnostics.push(diag);\n ctx.diagnostics.push(diag);\n // Preserve the raw parsedData even on validation failure\n data = node.parsedData;\n } else {\n data = result.data as Record<string, unknown>;\n }\n } else {\n // Unknown component type — info diagnostic, preserve block as-is\n const diag = createUnknownComponentInfo(componentType, position);\n blockDiagnostics.push(diag);\n ctx.diagnostics.push(diag);\n }\n }\n\n // Process markdown fields after validation\n data = processMarkdownFields(componentType, data, ctx);\n\n // Process refs into references\n if (node.refs && node.refs.length > 0) {\n processRefs(node.refs, blockId, ctx);\n }\n\n const block: Block = {\n id: blockId,\n type: blockType,\n data,\n position,\n };\n\n if (node.interactive) {\n block.metadata = { interactive: true };\n }\n\n if (blockDiagnostics.length > 0) {\n block.diagnostics = blockDiagnostics;\n }\n\n return block;\n}\n\n// ─── Reference Processing ────────────────────────────────────\n\nfunction processRefs(refs: RawRef[], sourceBlockId: string, ctx: TranslationContext): void {\n for (const ref of refs) {\n const reference: Reference = {\n id: generateBlockId(ctx.documentId, 'ref', `${sourceBlockId}->${ref.target}`),\n type: (ref.type as Reference['type']) ?? 'navigates-to',\n sourceBlockId,\n targetBlockId: ref.target,\n };\n\n if (ref.label) {\n reference.label = ref.label;\n }\n if (ref.sourceAnchor) {\n reference.sourceAnchor = ref.sourceAnchor;\n }\n if (ref.targetAnchor) {\n reference.targetAnchor = ref.targetAnchor;\n }\n if (ref.bidirectional) {\n reference.bidirectional = ref.bidirectional;\n }\n\n // Mark as unresolved — we resolve later in the compile step\n reference.unresolved = true;\n\n ctx.references.push(reference);\n }\n}\n\n// ─── Standard MDAST Node Translation ─────────────────────────\n\nfunction translateMdastNode(node: MdastContentNode, ctx: TranslationContext): Block | null {\n const position: SourcePosition = node.position ?? DEFAULT_POSITION;\n\n switch (node.type) {\n case 'heading':\n return translateHeading(node, position, ctx);\n case 'paragraph':\n return translateParagraph(node, position, ctx);\n case 'list':\n return translateList(node, position, ctx);\n case 'code':\n return translateCode(node, position, ctx);\n case 'blockquote':\n return translateBlockquote(node, position, ctx);\n case 'image':\n return translateImage(node, position, ctx);\n case 'thematicBreak':\n return translateThematicBreak(position, ctx);\n case 'html':\n return translateHtml(node, position, ctx);\n case 'yaml':\n // Frontmatter is handled separately in compile.ts; skip here\n return null;\n default:\n // Unknown MDAST node type — skip silently\n return null;\n }\n}\n\n// ─── Individual Node Translators ─────────────────────────────\n\nfunction translateHeading(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const depth = (node['depth'] as number) ?? 1;\n const children = convertPhrasingContent((node.children ?? []) as unknown[]);\n const content = inlineNodesToText(children);\n\n return {\n id: generateBlockId(ctx.documentId, 'heading', content),\n type: 'heading',\n data: { depth, children },\n position,\n };\n}\n\nfunction translateParagraph(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const children = convertPhrasingContent((node.children ?? []) as unknown[]);\n const content = inlineNodesToText(children);\n\n return {\n id: generateBlockId(ctx.documentId, 'paragraph', content),\n type: 'paragraph',\n data: { children },\n position,\n };\n}\n\nfunction translateList(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const ordered = (node['ordered'] as boolean) ?? false;\n const start = ordered ? ((node['start'] as number) ?? 1) : undefined;\n const items = translateListItems((node.children ?? []) as MdastContentNode[]);\n const content = listDataToText({ ordered, start, items });\n\n const data: ListData = { ordered, items };\n if (start !== undefined) {\n data.start = start;\n }\n\n return {\n id: generateBlockId(ctx.documentId, 'list', content),\n type: 'list',\n data,\n position,\n };\n}\n\nfunction translateListItems(listItemNodes: MdastContentNode[]): ListItemData[] {\n const items: ListItemData[] = [];\n\n for (const itemNode of listItemNodes) {\n if (itemNode.type !== 'listItem') continue;\n\n const itemChildren = (itemNode.children ?? []) as MdastContentNode[];\n let inlineChildren: InlineNode[] = [];\n let subList: ListData | undefined;\n\n for (const child of itemChildren) {\n if (child.type === 'paragraph') {\n inlineChildren = convertPhrasingContent((child.children ?? []) as unknown[]);\n } else if (child.type === 'list') {\n const subOrdered = (child['ordered'] as boolean) ?? false;\n const subStart = subOrdered ? ((child['start'] as number) ?? 1) : undefined;\n const subItems = translateListItems((child.children ?? []) as MdastContentNode[]);\n subList = { ordered: subOrdered, items: subItems };\n if (subStart !== undefined) {\n subList.start = subStart;\n }\n }\n }\n\n const item: ListItemData = { children: inlineChildren };\n if (subList) {\n item.subList = subList;\n }\n items.push(item);\n }\n\n return items;\n}\n\nfunction translateCode(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const value = (node.value as string) ?? '';\n const language = (node['lang'] as string) ?? undefined;\n const meta = (node['meta'] as string) ?? undefined;\n\n const data: Record<string, unknown> = { value };\n if (language) {\n data['language'] = language;\n }\n if (meta) {\n data['meta'] = meta;\n }\n\n return {\n id: generateBlockId(ctx.documentId, 'code', value),\n type: 'code',\n data,\n position,\n };\n}\n\nfunction translateBlockquote(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n // Blockquote children are typically paragraphs — flatten their inline content\n const allInlineNodes: InlineNode[] = [];\n for (const child of (node.children ?? []) as MdastContentNode[]) {\n if (child.type === 'paragraph') {\n const inlines = convertPhrasingContent((child.children ?? []) as unknown[]);\n allInlineNodes.push(...inlines);\n }\n }\n const content = inlineNodesToText(allInlineNodes);\n\n return {\n id: generateBlockId(ctx.documentId, 'blockquote', content),\n type: 'blockquote',\n data: { children: allInlineNodes },\n position,\n };\n}\n\nfunction translateImage(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const src = (node['url'] as string) ?? '';\n const alt = (node['alt'] as string) ?? undefined;\n const title = (node['title'] as string) ?? undefined;\n\n const data: Record<string, unknown> = { src };\n if (alt) {\n data['alt'] = alt;\n }\n if (title) {\n data['title'] = title;\n }\n\n return {\n id: generateBlockId(ctx.documentId, 'image', src),\n type: 'image',\n data,\n position,\n };\n}\n\nfunction translateThematicBreak(position: SourcePosition, ctx: TranslationContext): Block {\n return {\n id: generateBlockId(ctx.documentId, 'thematic-break', '---'),\n type: 'thematic-break',\n data: {},\n position,\n };\n}\n\nfunction translateHtml(\n node: MdastContentNode,\n position: SourcePosition,\n ctx: TranslationContext,\n): Block {\n const value = (node.value as string) ?? '';\n\n return {\n id: generateBlockId(ctx.documentId, 'html', value),\n type: 'html',\n data: { value },\n position,\n };\n}\n\n// ─── Text Extraction Helpers ─────────────────────────────────\n\n/**\n * Extract plain text from InlineNode[] for content-addressing purposes.\n */\nfunction inlineNodesToText(nodes: InlineNode[]): string {\n return nodes\n .map((node) => {\n switch (node.type) {\n case 'text':\n return node.value;\n case 'inlineCode':\n return node.value;\n case 'strong':\n case 'emphasis':\n case 'delete':\n return inlineNodesToText(node.children);\n case 'link':\n return inlineNodesToText(node.children);\n case 'image':\n return node.alt ?? '';\n case 'break':\n return '\\n';\n default:\n return '';\n }\n })\n .join('');\n}\n\n/**\n * Extract plain text from ListData for content-addressing purposes.\n */\nfunction listDataToText(data: ListData): string {\n return data.items\n .map((item) => {\n let text = inlineNodesToText(item.children);\n if (item.subList) {\n text += '\\n' + listDataToText(item.subList);\n }\n return text;\n })\n .join('\\n');\n}\n","import type {\n Block,\n Diagnostic,\n InlineNode,\n Reference,\n} from '@glyphjs/types';\nimport { generateBlockId } from '@glyphjs/ir';\nimport { createDiagnostic } from './diagnostics.js';\n\n// ─── Glyph Link Pattern ─────────────────────────────────────\n\n/**\n * Matches inline links of the form `[text](#glyph:block-id)`.\n * The captured group is the block ID after the `#glyph:` prefix.\n */\nconst GLYPH_LINK_PREFIX = '#glyph:';\n\n// ─── Inline Reference Scanning ──────────────────────────────\n\n/**\n * Scan a block's inline content for `[text](#glyph:block-id)` links\n * and create Reference objects for each match.\n *\n * @param block - The block whose inline data fields are scanned for glyph links.\n * @param documentId - Document ID used to generate deterministic reference IDs.\n * @returns Newly created (unresolved) Reference objects.\n */\nexport function extractInlineReferences(\n block: Block,\n documentId: string,\n): Reference[] {\n const references: Reference[] = [];\n const inlineNodes = extractInlineNodes(block);\n\n for (const node of inlineNodes) {\n if (node.type === 'link' && node.url.startsWith(GLYPH_LINK_PREFIX)) {\n const targetBlockId = node.url.slice(GLYPH_LINK_PREFIX.length);\n if (!targetBlockId) continue;\n\n const label = inlineNodesToPlainText(node.children);\n\n const reference: Reference = {\n id: generateBlockId(documentId, 'ref', `${block.id}->${targetBlockId}`),\n type: 'navigates-to',\n sourceBlockId: block.id,\n targetBlockId,\n unresolved: true,\n };\n\n if (label) {\n reference.label = label;\n }\n\n references.push(reference);\n }\n }\n\n return references;\n}\n\n/**\n * Scan all blocks (including nested children) for inline `#glyph:` link references\n * and collect them.\n *\n * @param blocks - Top-level block array to scan recursively.\n * @param documentId - Document ID used to generate deterministic reference IDs.\n * @returns Aggregated array of unresolved Reference objects from all blocks.\n */\nexport function extractAllInlineReferences(\n blocks: Block[],\n documentId: string,\n): Reference[] {\n const references: Reference[] = [];\n\n for (const block of blocks) {\n const blockRefs = extractInlineReferences(block, documentId);\n references.push(...blockRefs);\n\n // Also scan children (e.g. container blocks)\n if (block.children) {\n const childRefs = extractAllInlineReferences(block.children, documentId);\n references.push(...childRefs);\n }\n }\n\n return references;\n}\n\n// ─── Reference Resolution ────────────────────────────────────\n\n/**\n * Resolve references by checking if target block IDs exist in the document.\n * Marks unresolved references and adds warning diagnostics.\n *\n * Collects all block IDs including children (for container blocks).\n *\n * @param references - The reference array to resolve in-place (mutates `unresolved` flag).\n * @param blocks - All blocks in the document (used to build the known-ID set).\n * @param diagnostics - Accumulator for 'UNRESOLVED_REFERENCE' warnings.\n */\nexport function resolveReferences(\n references: Reference[],\n blocks: Block[],\n diagnostics: Diagnostic[],\n): void {\n const blockIdSet = collectAllBlockIds(blocks);\n\n for (const ref of references) {\n if (blockIdSet.has(ref.targetBlockId)) {\n ref.unresolved = false;\n } else {\n ref.unresolved = true;\n diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'warning',\n 'UNRESOLVED_REFERENCE',\n `Reference target \"${ref.targetBlockId}\" was not found in the document.`,\n ),\n );\n }\n }\n}\n\n/**\n * Collect all block IDs from blocks and their children recursively.\n */\nfunction collectAllBlockIds(blocks: Block[]): Set<string> {\n const ids = new Set<string>();\n for (const block of blocks) {\n ids.add(block.id);\n if (block.children) {\n for (const id of collectAllBlockIds(block.children)) {\n ids.add(id);\n }\n }\n }\n return ids;\n}\n\n// ─── Glyph-ID Uniqueness Validation ─────────────────────────\n\n/**\n * Validate that all user-assigned glyph-ids are unique within the document.\n * Emits error diagnostics for duplicates.\n *\n * @param blockIdMap - Map of user-assigned glyph-id to resolved block ID (from translation).\n * @param blocks - All blocks in the document (scanned to count occurrences).\n * @param diagnostics - Accumulator for 'DUPLICATE_GLYPH_ID' error diagnostics.\n */\nexport function validateGlyphIdUniqueness(\n blockIdMap: Map<string, string>,\n blocks: Block[],\n diagnostics: Diagnostic[],\n): void {\n // blockIdMap tracks glyphId -> blockId, but we need to detect duplicates\n // by scanning blocks for those whose id matches a glyph-id key\n const glyphIdOccurrences = new Map<string, number>();\n\n for (const glyphId of blockIdMap.keys()) {\n const count = countBlocksWithGlyphId(blocks, glyphId);\n glyphIdOccurrences.set(glyphId, count);\n }\n\n for (const [glyphId, count] of glyphIdOccurrences) {\n if (count > 1) {\n diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'error',\n 'DUPLICATE_GLYPH_ID',\n `Duplicate glyph-id \"${glyphId}\" found on ${String(count)} blocks. Block IDs must be unique within a document.`,\n ),\n );\n }\n }\n}\n\n/**\n * Count how many blocks in the array have a given ID (which came from a glyph-id).\n */\nfunction countBlocksWithGlyphId(blocks: Block[], glyphId: string): number {\n let count = 0;\n for (const block of blocks) {\n if (block.id === glyphId) {\n count++;\n }\n }\n return count;\n}\n\n// ─── Inline Node Extraction Helpers ──────────────────────────\n\n/**\n * Extract all InlineNode arrays from a block's data field.\n * Handles heading, paragraph, blockquote, and list blocks.\n */\nfunction extractInlineNodes(block: Block): InlineNode[] {\n const data = block.data as Record<string, unknown>;\n const nodes: InlineNode[] = [];\n\n // Blocks with a direct `children` inline array\n if (Array.isArray(data['children'])) {\n nodes.push(...(data['children'] as InlineNode[]));\n }\n\n // List blocks: extract inline nodes from items\n if (Array.isArray(data['items'])) {\n for (const item of data['items'] as { children?: InlineNode[]; subList?: { items?: unknown[] } }[]) {\n if (Array.isArray(item.children)) {\n nodes.push(...item.children);\n }\n }\n }\n\n return nodes;\n}\n\n/**\n * Extract plain text from InlineNode[] for label purposes.\n */\nfunction inlineNodesToPlainText(nodes: InlineNode[]): string {\n return nodes\n .map((node) => {\n switch (node.type) {\n case 'text':\n return node.value;\n case 'inlineCode':\n return node.value;\n case 'strong':\n case 'emphasis':\n case 'delete':\n return inlineNodesToPlainText(node.children);\n case 'link':\n return inlineNodesToPlainText(node.children);\n case 'image':\n return node.alt ?? '';\n case 'break':\n return '\\n';\n default:\n return '';\n }\n })\n .join('');\n}\n","import type { Block, Diagnostic } from '@glyphjs/types';\nimport { parseGlyphMarkdown } from '@glyphjs/parser';\nimport { translateNode } from './ast-to-ir.js';\nimport type { TranslationContext } from './ast-to-ir.js';\nimport { createDiagnostic } from './diagnostics.js';\n\n// ─── Container Block Compilation ─────────────────────────────\n\n/**\n * Process container blocks (ui:tabs and ui:steps) by recursively parsing\n * their content fields as Markdown into child Block[] arrays.\n *\n * This function mutates blocks in-place, populating their `children` field\n * and updating data entries with parsed child blocks.\n *\n * @param blocks - The top-level block array to scan for container blocks.\n * @param ctx - Translation context used for recursive compilation.\n */\nexport function compileContainerBlocks(\n blocks: Block[],\n ctx: TranslationContext,\n): void {\n for (const block of blocks) {\n if (block.type === 'ui:tabs') {\n compileTabsBlock(block, ctx);\n } else if (block.type === 'ui:steps') {\n compileStepsBlock(block, ctx);\n }\n }\n}\n\n// ─── Tabs Compilation ────────────────────────────────────────\n\nfunction compileTabsBlock(block: Block, ctx: TranslationContext): void {\n const data = block.data as Record<string, unknown>;\n const tabs = data['tabs'];\n\n if (!Array.isArray(tabs)) return;\n\n const allChildren: Block[] = [];\n\n for (const tab of tabs as { label?: string; content?: string }[]) {\n if (typeof tab.content !== 'string') continue;\n\n const childBlocks = parseContentToBlocks(tab.content, block, ctx);\n allChildren.push(...childBlocks);\n }\n\n if (allChildren.length > 0) {\n block.children = allChildren;\n }\n}\n\n// ─── Steps Compilation ───────────────────────────────────────\n\nfunction compileStepsBlock(block: Block, ctx: TranslationContext): void {\n const data = block.data as Record<string, unknown>;\n const steps = data['steps'];\n\n if (!Array.isArray(steps)) return;\n\n const allChildren: Block[] = [];\n\n for (const step of steps as { title?: string; status?: string; content?: string }[]) {\n if (typeof step.content !== 'string') continue;\n\n const childBlocks = parseContentToBlocks(step.content, block, ctx);\n allChildren.push(...childBlocks);\n }\n\n if (allChildren.length > 0) {\n block.children = allChildren;\n }\n}\n\n// ─── Content Parsing Helper ──────────────────────────────────\n\n/**\n * Parse a Markdown content string into Block[] using the compiler pipeline.\n * Emits a warning diagnostic if nested ui: components are found (deferred to v2).\n */\nfunction parseContentToBlocks(\n content: string,\n parentBlock: Block,\n ctx: TranslationContext,\n): Block[] {\n const ast = parseGlyphMarkdown(content);\n const blocks: Block[] = [];\n\n for (const child of ast.children) {\n // Check for nested ui: components — warn and skip\n if (child.type === 'glyphUIBlock') {\n ctx.diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'warning',\n 'NESTED_UI_COMPONENT',\n `Nested ui: component found inside container block \"${parentBlock.id}\". ` +\n `Nested ui: components inside tabs/steps are not supported in v1 and will be ignored.`,\n child.position,\n ),\n );\n continue;\n }\n\n const block = translateNode(child, ctx);\n if (block) {\n blocks.push(block);\n }\n }\n\n return blocks;\n}\n\n// ─── Nested UI Detection ─────────────────────────────────────\n\n/**\n * Check if content contains nested ui: blocks by looking for the pattern.\n * This is a quick heuristic check. The actual detection happens during parsing.\n *\n * @param content - Raw Markdown string to test for nested ui: fenced blocks.\n * @returns True if the content matches the `` ```ui: `` pattern.\n */\nexport function hasNestedUiBlocks(content: string): boolean {\n return /```ui:/m.test(content);\n}\n\n// ─── Validate Container Diagnostics ──────────────────────────\n\n/**\n * Post-process container blocks to ensure data consistency.\n * Called after container compilation is complete.\n *\n * @param blocks - The compiled block array to validate.\n * @param diagnostics - Accumulator for warning diagnostics (e.g., missing labels/titles).\n */\nexport function validateContainerBlocks(\n blocks: Block[],\n diagnostics: Diagnostic[],\n): void {\n for (const block of blocks) {\n if (block.type === 'ui:tabs') {\n validateTabsData(block, diagnostics);\n } else if (block.type === 'ui:steps') {\n validateStepsData(block, diagnostics);\n }\n }\n}\n\nfunction validateTabsData(block: Block, _diagnostics: Diagnostic[]): void {\n const data = block.data as Record<string, unknown>;\n const tabs = data['tabs'];\n\n if (!Array.isArray(tabs) || tabs.length === 0) {\n return;\n }\n\n // Ensure each tab has a label\n for (const tab of tabs as { label?: string }[]) {\n if (!tab.label) {\n _diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'warning',\n 'MISSING_TAB_LABEL',\n `A tab in block \"${block.id}\" is missing a label.`,\n block.position,\n ),\n );\n }\n }\n}\n\nfunction validateStepsData(block: Block, _diagnostics: Diagnostic[]): void {\n const data = block.data as Record<string, unknown>;\n const steps = data['steps'];\n\n if (!Array.isArray(steps) || steps.length === 0) {\n return;\n }\n\n // Ensure each step has a title\n for (const step of steps as { title?: string }[]) {\n if (!step.title) {\n _diagnostics.push(\n createDiagnostic(\n 'compiler',\n 'warning',\n 'MISSING_STEP_TITLE',\n `A step in block \"${block.id}\" is missing a title.`,\n block.position,\n ),\n );\n }\n }\n}\n","import type {\n GlyphIR,\n CompilationResult,\n Diagnostic,\n DocumentMetadata,\n LayoutHints,\n Block,\n Reference,\n MdastContentNode,\n} from '@glyphjs/types';\nimport { parseGlyphMarkdown } from '@glyphjs/parser';\nimport { generateDocumentId, resolveBlockIdCollisions } from '@glyphjs/ir';\nimport { parse as parseYaml } from 'yaml';\nimport { translateNode } from './ast-to-ir.js';\nimport type { TranslationContext } from './ast-to-ir.js';\nimport { createDiagnostic } from './diagnostics.js';\nimport {\n extractAllInlineReferences,\n resolveReferences,\n validateGlyphIdUniqueness,\n} from './references.js';\nimport { compileContainerBlocks, validateContainerBlocks } from './containers.js';\n\n// ─── Public Interface ────────────────────────────────────────\n\nexport interface CompileOptions {\n /** Source file path, used for document ID generation. */\n filePath?: string;\n /** Explicit document ID override. */\n documentId?: string;\n /** Enable markdown parsing in component text fields by default. */\n parseComponentMarkdown?: boolean;\n}\n\n// ─── Main Compile Function ───────────────────────────────────\n\n/**\n * Compile a Markdown string into Glyph IR.\n *\n * Steps:\n * 1. Parse the markdown via `parseGlyphMarkdown`\n * 2. Extract frontmatter metadata and layout hints\n * 3. Walk the AST and translate each node to IR blocks\n * 4. Validate ui: blocks against Zod schemas\n * 5. Compile container blocks (ui:tabs, ui:steps) — recursively parse content\n * 6. Validate container block data\n * 7. Generate content-addressed block IDs\n * 8. Generate the document ID\n * 9. Resolve block ID collisions\n * 10. Validate glyph-id uniqueness\n * 11. Extract inline references from `[text](#glyph:block-id)` links\n * 12. Resolve all references (from refs arrays and inline links)\n * 13. Infer metadata from content if not in frontmatter\n * 14. Return CompilationResult with IR, diagnostics, and hasErrors flag\n *\n * Uses a collect-all-errors strategy: IR is always produced, even when errors exist.\n */\nexport function compile(markdown: string, options?: CompileOptions): CompilationResult {\n const diagnostics: Diagnostic[] = [];\n\n // 1. Parse the markdown into a Glyph AST\n const ast = parseGlyphMarkdown(markdown);\n\n // 2. Extract frontmatter\n const { metadata, layout, frontmatterGlyphId } = extractFrontmatter(ast.children, diagnostics);\n\n // 3. Generate document ID\n const documentId =\n options?.documentId ??\n generateDocumentId({\n glyphId: frontmatterGlyphId,\n filePath: options?.filePath,\n content: markdown,\n });\n\n // Set sourceFile from options if available\n if (options?.filePath && !metadata.sourceFile) {\n metadata.sourceFile = options.filePath;\n }\n\n // 4. Create translation context\n const references: Reference[] = [];\n const ctx: TranslationContext = {\n documentId,\n diagnostics,\n references,\n blockIdMap: new Map(),\n compileOptions: options ?? {},\n };\n\n // 5. Walk the AST and translate nodes\n const blocks: Block[] = [];\n for (const child of ast.children) {\n const block = translateNode(child, ctx);\n if (block) {\n blocks.push(block);\n }\n }\n\n // 6. Compile container blocks (ui:tabs, ui:steps) — recursively parse content fields\n compileContainerBlocks(blocks, ctx);\n\n // 7. Validate container block data\n validateContainerBlocks(blocks, diagnostics);\n\n // 8. Infer metadata from content if not in frontmatter\n inferMetadata(metadata, blocks);\n\n // 9. Resolve block ID collisions\n const blockIds = blocks.map((b) => b.id);\n const resolvedIds = resolveBlockIdCollisions(blockIds);\n for (let i = 0; i < blocks.length; i++) {\n const block = blocks[i];\n const resolvedId = resolvedIds[i];\n if (block && resolvedId) {\n block.id = resolvedId;\n }\n }\n\n // 10. Validate glyph-id uniqueness\n validateGlyphIdUniqueness(ctx.blockIdMap, blocks, diagnostics);\n\n // 11. Extract inline references from [text](#glyph:block-id) links\n const inlineRefs = extractAllInlineReferences(blocks, documentId);\n references.push(...inlineRefs);\n\n // 12. Resolve all references (from refs arrays and inline links)\n resolveReferences(references, blocks, diagnostics);\n\n // 13. Build the IR\n const ir: GlyphIR = {\n version: '1.0.0',\n id: documentId,\n metadata,\n blocks,\n references,\n layout,\n };\n\n const hasErrors = diagnostics.some((d) => d.severity === 'error');\n\n return { ir, diagnostics, hasErrors };\n}\n\n// ─── Frontmatter Extraction ─────────────────────────────────\n\ninterface FrontmatterResult {\n metadata: DocumentMetadata;\n layout: LayoutHints;\n frontmatterGlyphId?: string;\n}\n\nfunction extractFrontmatter(\n children: readonly unknown[],\n diagnostics: Diagnostic[],\n): FrontmatterResult {\n const metadata: DocumentMetadata = {};\n let layout: LayoutHints = { mode: 'document', spacing: 'normal' };\n let frontmatterGlyphId: string | undefined;\n\n // Look for yaml frontmatter node (always first child if present)\n const firstChild = children[0] as MdastContentNode | undefined;\n if (firstChild && firstChild.type === 'yaml' && typeof firstChild.value === 'string') {\n try {\n const parsed: unknown = parseYaml(firstChild.value);\n if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {\n const fm = parsed as Record<string, unknown>;\n\n // Extract glyph-id\n if (typeof fm['glyph-id'] === 'string') {\n frontmatterGlyphId = fm['glyph-id'];\n }\n\n // Extract metadata fields\n if (typeof fm['title'] === 'string') {\n metadata.title = fm['title'];\n }\n if (typeof fm['description'] === 'string') {\n metadata.description = fm['description'];\n }\n if (Array.isArray(fm['authors'])) {\n metadata.authors = fm['authors'].filter((a): a is string => typeof a === 'string');\n }\n if (typeof fm['createdAt'] === 'string') {\n metadata.createdAt = fm['createdAt'];\n }\n if (Array.isArray(fm['tags'])) {\n metadata.tags = fm['tags'].filter((t): t is string => typeof t === 'string');\n }\n\n // Extract layout hints\n if (fm['layout'] && typeof fm['layout'] === 'object' && !Array.isArray(fm['layout'])) {\n const rawLayout = fm['layout'] as Record<string, unknown>;\n layout = {\n mode: isLayoutMode(rawLayout['mode']) ? rawLayout['mode'] : 'document',\n spacing: isLayoutSpacing(rawLayout['spacing']) ? rawLayout['spacing'] : 'normal',\n };\n if (typeof rawLayout['columns'] === 'number') {\n layout.columns = rawLayout['columns'];\n }\n if (typeof rawLayout['maxWidth'] === 'string') {\n layout.maxWidth = rawLayout['maxWidth'];\n }\n }\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : String(err);\n diagnostics.push(\n createDiagnostic(\n 'parser',\n 'error',\n 'FRONTMATTER_PARSE_ERROR',\n `Failed to parse frontmatter YAML: ${message}`,\n firstChild.position,\n ),\n );\n }\n }\n\n return { metadata, layout, frontmatterGlyphId };\n}\n\nfunction isLayoutMode(value: unknown): value is LayoutHints['mode'] {\n return value === 'document' || value === 'dashboard' || value === 'presentation';\n}\n\nfunction isLayoutSpacing(value: unknown): value is 'compact' | 'normal' | 'relaxed' {\n return value === 'compact' || value === 'normal' || value === 'relaxed';\n}\n\n// ─── Metadata Inference ──────────────────────────────────────\n\n/**\n * Infer metadata from content when not provided via frontmatter.\n * - title: from the first h1 heading\n * - description: from the first paragraph\n */\nfunction inferMetadata(metadata: DocumentMetadata, blocks: Block[]): void {\n if (!metadata.title) {\n const firstHeading = blocks.find(\n (b) => b.type === 'heading' && (b.data as Record<string, unknown>)['depth'] === 1,\n );\n if (firstHeading) {\n const data = firstHeading.data as { children?: { type: string; value?: string }[] };\n if (data.children) {\n metadata.title = data.children\n .map((node) => {\n if ('value' in node && typeof node.value === 'string') {\n return node.value;\n }\n return '';\n })\n .join('');\n }\n }\n }\n\n if (!metadata.description) {\n const firstParagraph = blocks.find((b) => b.type === 'paragraph');\n if (firstParagraph) {\n const data = firstParagraph.data as { children?: { type: string; value?: string }[] };\n if (data.children) {\n metadata.description = data.children\n .map((node) => {\n if ('value' in node && typeof node.value === 'string') {\n return node.value;\n }\n return '';\n })\n .join('');\n }\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glyphjs/compiler",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Compiles Glyph AST into IR with schema validation and diagnostics",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -24,11 +24,13 @@
24
24
  "README.md"
25
25
  ],
26
26
  "dependencies": {
27
+ "unified": "^11.0.5",
28
+ "remark-parse": "^11.0.0",
27
29
  "yaml": "^2.7.0",
28
- "@glyphjs/types": "0.2.0",
29
- "@glyphjs/schemas": "0.2.0",
30
- "@glyphjs/ir": "0.2.0",
31
- "@glyphjs/parser": "0.2.0"
30
+ "@glyphjs/types": "0.3.0",
31
+ "@glyphjs/schemas": "0.3.0",
32
+ "@glyphjs/parser": "0.3.0",
33
+ "@glyphjs/ir": "0.3.0"
32
34
  },
33
35
  "sideEffects": false,
34
36
  "license": "MIT",