@leo-studio/leo-markup 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +18 -2
  3. package/dist/agent-support.d.ts +10 -0
  4. package/dist/agent-support.d.ts.map +1 -0
  5. package/dist/agent-support.js +27 -0
  6. package/dist/agent-support.js.map +1 -0
  7. package/dist/ast-json.d.ts +104 -0
  8. package/dist/ast-json.d.ts.map +1 -0
  9. package/dist/ast-json.js +203 -0
  10. package/dist/ast-json.js.map +1 -0
  11. package/dist/authoring-lints.d.ts +79 -0
  12. package/dist/authoring-lints.d.ts.map +1 -0
  13. package/dist/authoring-lints.js +145 -0
  14. package/dist/authoring-lints.js.map +1 -0
  15. package/dist/block-inline.d.ts +74 -0
  16. package/dist/block-inline.d.ts.map +1 -0
  17. package/dist/block-inline.js +171 -0
  18. package/dist/block-inline.js.map +1 -0
  19. package/dist/fence.d.ts +14 -0
  20. package/dist/fence.d.ts.map +1 -0
  21. package/dist/fence.js +55 -0
  22. package/dist/fence.js.map +1 -0
  23. package/dist/index.d.ts +20 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +20 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/parity.d.ts +44 -0
  28. package/dist/parity.d.ts.map +1 -0
  29. package/dist/parity.js +80 -0
  30. package/dist/parity.js.map +1 -0
  31. package/dist/product-spec.d.ts +164 -0
  32. package/dist/product-spec.d.ts.map +1 -0
  33. package/dist/product-spec.js +240 -0
  34. package/dist/product-spec.js.map +1 -0
  35. package/dist/registry.d.ts +53 -0
  36. package/dist/registry.d.ts.map +1 -0
  37. package/dist/registry.js +483 -0
  38. package/dist/registry.js.map +1 -0
  39. package/dist/scanner.d.ts +40 -0
  40. package/dist/scanner.d.ts.map +1 -0
  41. package/dist/scanner.js +291 -0
  42. package/dist/scanner.js.map +1 -0
  43. package/dist/schema/leo-markup-ast.schema.json +217 -0
  44. package/dist/schema/vocabulary.json +382 -0
  45. package/dist/tree-text.d.ts +16 -0
  46. package/dist/tree-text.d.ts.map +1 -0
  47. package/dist/tree-text.js +320 -0
  48. package/dist/tree-text.js.map +1 -0
  49. package/dist/types.d.ts +211 -0
  50. package/dist/types.d.ts.map +1 -0
  51. package/dist/types.js +34 -0
  52. package/dist/types.js.map +1 -0
  53. package/dist/vocabulary.d.ts +293 -0
  54. package/dist/vocabulary.d.ts.map +1 -0
  55. package/dist/vocabulary.js +226 -0
  56. package/dist/vocabulary.js.map +1 -0
  57. package/package.json +43 -3
@@ -0,0 +1,320 @@
1
+ import { ANNOTATION_RELATIONS } from './vocabulary.js';
2
+ const DRAWING = /[\u2502\u251C\u2514\u2500]/u;
3
+ const RELATIONS = new Set(ANNOTATION_RELATIONS);
4
+ function textNode(source, scope) {
5
+ return {
6
+ kind: 'prose',
7
+ source,
8
+ start: 0,
9
+ end: source.length,
10
+ ...(scope ? { scope } : {}),
11
+ };
12
+ }
13
+ function component(name, props, children, source = '', scope) {
14
+ return {
15
+ kind: 'component',
16
+ name,
17
+ props,
18
+ children,
19
+ body: children.map((child) => child.source).join(''),
20
+ bodyStart: 0,
21
+ source,
22
+ start: 0,
23
+ end: source.length,
24
+ ...(scope ? { scope } : {}),
25
+ };
26
+ }
27
+ function keyValue(text) {
28
+ const separator = text.indexOf(':');
29
+ if (separator < 1) {
30
+ return undefined;
31
+ }
32
+ const key = text.slice(0, separator).trim();
33
+ const value = text.slice(separator + 1).trim();
34
+ return !key || key.includes(' ') || !value ? undefined : { key, value };
35
+ }
36
+ function isIncrement(text) {
37
+ return /^I[0-9]+$/u.test(text);
38
+ }
39
+ function parseNodeLine(content) {
40
+ const refs = [];
41
+ const attributes = {};
42
+ let scope;
43
+ let remainder = '';
44
+ let bracket = '';
45
+ let depth = 0;
46
+ const applyBracket = (raw) => {
47
+ const text = raw.trim();
48
+ if (!text) {
49
+ return;
50
+ }
51
+ const pair = keyValue(text);
52
+ if (pair) {
53
+ if (RELATIONS.has(pair.key)) {
54
+ refs.push({ relation: pair.key, target: pair.value });
55
+ }
56
+ else {
57
+ attributes[pair.key] = pair.value;
58
+ }
59
+ return;
60
+ }
61
+ if (isIncrement(text) || text === 'deferred' || text === 'unassigned') {
62
+ scope = text;
63
+ }
64
+ else if (RELATIONS.has(text)) {
65
+ refs.push({ relation: text, target: '' });
66
+ }
67
+ else {
68
+ attributes[text] = '';
69
+ }
70
+ };
71
+ for (const character of content) {
72
+ if (character === '[') {
73
+ depth += 1;
74
+ if (depth === 1) {
75
+ bracket = '';
76
+ continue;
77
+ }
78
+ }
79
+ if (character === ']' && depth > 0) {
80
+ depth -= 1;
81
+ if (depth === 0) {
82
+ applyBracket(bracket);
83
+ remainder += ' ';
84
+ continue;
85
+ }
86
+ }
87
+ if (depth > 0) {
88
+ bracket += character;
89
+ }
90
+ else {
91
+ remainder += character;
92
+ }
93
+ }
94
+ if (depth > 0) {
95
+ remainder += `[${bracket}`;
96
+ }
97
+ const segments = remainder
98
+ .split(/ {2,}/u)
99
+ .map((segment) => segment.trim())
100
+ .filter(Boolean);
101
+ let label = segments.shift() ?? '';
102
+ for (const segment of segments) {
103
+ const pair = keyValue(segment);
104
+ if (pair) {
105
+ attributes[pair.key] = pair.value;
106
+ }
107
+ else {
108
+ label += ` ${segment}`;
109
+ }
110
+ }
111
+ return { label: label.trim(), attributes, refs, ...(scope ? { scope } : {}) };
112
+ }
113
+ function readRows(body) {
114
+ const drawn = DRAWING.test(body);
115
+ const rows = [];
116
+ for (const rawLine of body.split(/\r?\n/u)) {
117
+ const line = rawLine.replaceAll('\t', ' ');
118
+ const scaffoldEnd = drawn
119
+ ? (/^[\u2502| ]*(?:(?:[\u251C\u2514]\u2500+|[+`]-+) ?)?/u.exec(line)?.[0].length ?? 0)
120
+ : (/^ */u.exec(line)?.[0].length ?? 0);
121
+ const scaffold = line.slice(0, scaffoldEnd);
122
+ const content = line.slice(scaffoldEnd).trim();
123
+ if (!content) {
124
+ continue;
125
+ }
126
+ const hasConnector = scaffold.includes('├') || scaffold.includes('└');
127
+ const isRoot = scaffold.length === 0;
128
+ if (drawn && !hasConnector && !isRoot && rows.length > 0) {
129
+ rows.at(-1)?.description.push(content);
130
+ continue;
131
+ }
132
+ rows.push({
133
+ column: scaffold.length,
134
+ ...parseNodeLine(content),
135
+ description: [],
136
+ });
137
+ }
138
+ return rows;
139
+ }
140
+ function assignDepths(rows) {
141
+ const columns = [];
142
+ return rows.map((row) => {
143
+ while (columns.length > 0 && (columns.at(-1) ?? 0) >= row.column) {
144
+ columns.pop();
145
+ }
146
+ const depth = columns.length;
147
+ columns.push(row.column);
148
+ return depth;
149
+ });
150
+ }
151
+ function deliveryScope(value) {
152
+ if (!value) {
153
+ return undefined;
154
+ }
155
+ return isIncrement(value)
156
+ ? { kind: 'increment', increment: value }
157
+ : value === 'deferred' || value === 'unassigned'
158
+ ? { kind: value }
159
+ : undefined;
160
+ }
161
+ function buildNode(row, children) {
162
+ const scope = deliveryScope(row.scope);
163
+ const description = row.description.join(' ').trim();
164
+ const ownChildren = [
165
+ ...(description ? [textNode(description, scope)] : []),
166
+ ...row.refs.map((ref) => component('ref', { relation: ref.relation, target: ref.target }, [], '', scope)),
167
+ ...children,
168
+ ];
169
+ const node = component('node', { ...row.attributes, label: row.label }, ownChildren, row.label, scope);
170
+ if (!scope || !row.scope) {
171
+ return node;
172
+ }
173
+ const props = scope.kind === 'increment' ? { increment: scope.increment } : { [scope.kind]: true };
174
+ return component('scope', props, [node], node.source, scope);
175
+ }
176
+ function assemble(rows) {
177
+ const depths = assignDepths(rows);
178
+ const roots = [];
179
+ const stack = [];
180
+ const close = (depth) => {
181
+ while (stack.length > depth) {
182
+ const frame = stack.pop();
183
+ if (!frame) {
184
+ continue;
185
+ }
186
+ const built = buildNode(frame.row, frame.children);
187
+ const parent = stack.at(-1);
188
+ if (parent) {
189
+ parent.children.push(built);
190
+ }
191
+ else {
192
+ roots.push(built);
193
+ }
194
+ }
195
+ };
196
+ rows.forEach((row, index) => {
197
+ close(Math.min(depths[index] ?? 0, stack.length));
198
+ stack.push({ row, children: [] });
199
+ });
200
+ close(0);
201
+ return roots;
202
+ }
203
+ /** Parse a drawn `leo.tree` fence into the shared product-spec component model. */
204
+ export function parseLeoTreeText(body, options = {}) {
205
+ const rows = readRows(body);
206
+ if (rows.length === 0) {
207
+ return undefined;
208
+ }
209
+ const children = assemble(rows);
210
+ if (children.length === 0) {
211
+ return undefined;
212
+ }
213
+ const source = options.source ?? body;
214
+ return component('tree', { ...(options.title ? { title: options.title } : {}) }, children, source);
215
+ }
216
+ /** `1. text` or `1) text`; returns the text after the marker. */
217
+ function stepMarker(line) {
218
+ return /^\s*[0-9]+[.)] (.*)$/u.exec(line)?.[1];
219
+ }
220
+ /** `→ 2 when the linter reports an error`; the arrow may be written `->`. */
221
+ function transitionLine(line) {
222
+ const match = /^(?:→|->)(.*)$/u.exec(line.trim());
223
+ if (!match) {
224
+ return undefined;
225
+ }
226
+ const rest = (match[1] ?? '').trim();
227
+ const when = rest.indexOf(' when ');
228
+ return when === -1
229
+ ? { to: rest, when: '' }
230
+ : { to: rest.slice(0, when).trim(), when: rest.slice(when + 6).trim() };
231
+ }
232
+ function readSteps(body) {
233
+ const steps = [];
234
+ for (const rawLine of body.split(/\r?\n/u)) {
235
+ const line = rawLine.replaceAll('\t', ' ');
236
+ if (!line.trim()) {
237
+ continue;
238
+ }
239
+ const marker = stepMarker(line);
240
+ if (marker !== undefined) {
241
+ let text = marker;
242
+ let id;
243
+ const space = text.indexOf(' ');
244
+ if (text.startsWith('#') && space !== -1) {
245
+ id = text.slice(1, space);
246
+ text = text.slice(space + 1);
247
+ }
248
+ const parsed = parseNodeLine(text);
249
+ steps.push({
250
+ ...(id ? { id } : {}),
251
+ text: parsed.label,
252
+ body: [],
253
+ refs: [...parsed.refs],
254
+ attributes: parsed.attributes,
255
+ ...(parsed.scope ? { scope: parsed.scope } : {}),
256
+ transitions: [],
257
+ });
258
+ continue;
259
+ }
260
+ const step = steps.at(-1);
261
+ if (!step) {
262
+ continue;
263
+ }
264
+ const edge = transitionLine(line);
265
+ if (edge) {
266
+ step.transitions.push(edge);
267
+ continue;
268
+ }
269
+ const parsed = parseNodeLine(line.trim());
270
+ step.refs.push(...parsed.refs);
271
+ if (!parsed.label && parsed.refs.length > 0) {
272
+ // A line holding only annotations qualifies the step above it.
273
+ step.scope ??= parsed.scope;
274
+ continue;
275
+ }
276
+ step.body.push(parsed.label);
277
+ }
278
+ return steps;
279
+ }
280
+ /** Lowercase, non-alphanumerics collapsed to `-`, at most six words. */
281
+ function journeySlug(text) {
282
+ return text
283
+ .toLowerCase()
284
+ .replace(/[^\p{L}\p{N}]/gu, '-')
285
+ .split('-')
286
+ .filter(Boolean)
287
+ .slice(0, 6)
288
+ .join('-');
289
+ }
290
+ function buildStep(step, number) {
291
+ const scope = deliveryScope(step.scope);
292
+ const prose = [step.text, ...step.body].join(' ').trim();
293
+ const children = [
294
+ ...(prose ? [textNode(prose, scope)] : []),
295
+ ...step.refs.map((ref) => component('ref', { relation: ref.relation, target: ref.target }, [], '', scope)),
296
+ ...step.transitions.map((edge) => component('transition',
297
+ // A transition to a bare number addresses the step of that ordinal.
298
+ { to: /^[0-9]+$/u.test(edge.to) ? `step-${edge.to}` : edge.to, when: edge.when }, [], '', scope)),
299
+ ];
300
+ const node = component('step', { ...step.attributes, id: step.id ?? `step-${number}` }, children, prose, scope);
301
+ if (!scope) {
302
+ return node;
303
+ }
304
+ const props = scope.kind === 'increment' ? { increment: scope.increment } : { [scope.kind]: true };
305
+ return component('scope', props, [node], node.source, scope);
306
+ }
307
+ /**
308
+ * Parse a numbered-list `leo.journey` fence into the shared product-spec component model.
309
+ * A `N.` line is a step (`#id` after the marker overrides the derived `step-N`), an arrow
310
+ * line is a transition, and other lines continue the step above.
311
+ */
312
+ export function parseLeoJourneyText(body, options = {}) {
313
+ const steps = readSteps(body);
314
+ if (steps.length === 0) {
315
+ return undefined;
316
+ }
317
+ const title = options.title?.trim();
318
+ return component('journey', title ? { id: journeySlug(title), title } : { id: 'journey' }, steps.map((step, index) => buildStep(step, index + 1)), options.source ?? body);
319
+ }
320
+ //# sourceMappingURL=tree-text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree-text.js","sourceRoot":"","sources":["../src/tree-text.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,OAAO,GAAG,6BAA6B,CAAC;AAC9C,MAAM,SAAS,GAAwB,IAAI,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAgBrE,SAAS,QAAQ,CAAC,MAAc,EAAE,KAAqB;IACnD,OAAO;QACH,IAAI,EAAE,OAAO;QACb,MAAM;QACN,KAAK,EAAE,CAAC;QACR,GAAG,EAAE,MAAM,CAAC,MAAM;QAClB,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9B,CAAC;AACN,CAAC;AAED,SAAS,SAAS,CACd,IAAkC,EAClC,KAAiD,EACjD,QAAoC,EACpC,MAAM,GAAG,EAAE,EACX,KAAqB;IAErB,OAAO;QACH,IAAI,EAAE,WAAW;QACjB,IAAI;QACJ,KAAK;QACL,QAAQ;QACR,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;QACpD,SAAS,EAAE,CAAC;QACZ,MAAM;QACN,KAAK,EAAE,CAAC;QACR,GAAG,EAAE,MAAM,CAAC,MAAM;QAClB,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9B,CAAC;AACN,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC1B,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,C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E,EAAE,SAAS,EAAE,EAC7D,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,EACtD,OAAO,CAAC,MAAM,IAAI,IAAI,CACzB,CAAC;AACN,CAAC","sourcesContent":["import type {\n DeliveryScope,\n ProductSpecComponent,\n ProductSpecNode,\n ProductSpecText,\n} from './product-spec.js';\nimport { ANNOTATION_RELATIONS } from './vocabulary.js';\n\nconst DRAWING = /[\\u2502\\u251C\\u2514\\u2500]/u;\nconst RELATIONS: ReadonlySet<string> = new Set(ANNOTATION_RELATIONS);\n\ninterface TreeTextRow {\n readonly column: number;\n readonly label: string;\n readonly attributes: Readonly<Record<string, string>>;\n readonly refs: ReadonlyArray<{ readonly relation: string; readonly target: string }>;\n readonly scope?: string;\n readonly description: string[];\n}\n\ninterface MutableFrame {\n readonly row: TreeTextRow;\n readonly children: ProductSpecComponent[];\n}\n\nfunction textNode(source: string, scope?: DeliveryScope): ProductSpecText {\n return {\n kind: 'prose',\n source,\n start: 0,\n end: source.length,\n ...(scope ? { scope } : {}),\n };\n}\n\nfunction component(\n name: ProductSpecComponent['name'],\n props: Readonly<Record<string, string | boolean>>,\n children: readonly ProductSpecNode[],\n source = '',\n scope?: DeliveryScope\n): ProductSpecComponent {\n return {\n kind: 'component',\n name,\n props,\n children,\n body: children.map((child) => child.source).join(''),\n bodyStart: 0,\n source,\n start: 0,\n end: source.length,\n ...(scope ? { scope } : {}),\n };\n}\n\nfunction keyValue(text: string): { key: string; value: string } | undefined {\n const separator = text.indexOf(':');\n if (separator < 1) {\n return undefined;\n }\n const key = text.slice(0, separator).trim();\n const value = text.slice(separator + 1).trim();\n return !key || key.includes(' ') || !value ? undefined : { key, value };\n}\n\nfunction isIncrement(text: string): boolean {\n return /^I[0-9]+$/u.test(text);\n}\n\nfunction parseNodeLine(content: string): Omit<TreeTextRow, 'column' | 'description'> {\n const refs: Array<{ relation: string; target: string }> = [];\n const attributes: Record<string, string> = {};\n let scope: string | undefined;\n let remainder = '';\n let bracket = '';\n let depth = 0;\n\n const applyBracket = (raw: string): void => {\n const text = raw.trim();\n if (!text) {\n return;\n }\n const pair = keyValue(text);\n if (pair) {\n if (RELATIONS.has(pair.key)) {\n refs.push({ relation: pair.key, target: pair.value });\n } else {\n attributes[pair.key] = pair.value;\n }\n return;\n }\n if (isIncrement(text) || text === 'deferred' || text === 'unassigned') {\n scope = text;\n } else if (RELATIONS.has(text)) {\n refs.push({ relation: text, target: '' });\n } else {\n attributes[text] = '';\n }\n };\n\n for (const character of content) {\n if (character === '[') {\n depth += 1;\n if (depth === 1) {\n bracket = '';\n continue;\n }\n }\n if (character === ']' && depth > 0) {\n depth -= 1;\n if (depth === 0) {\n applyBracket(bracket);\n remainder += ' ';\n continue;\n }\n }\n if (depth > 0) {\n bracket += character;\n } else {\n remainder += character;\n }\n }\n if (depth > 0) {\n remainder += `[${bracket}`;\n }\n\n const segments = remainder\n .split(/ {2,}/u)\n .map((segment) => segment.trim())\n .filter(Boolean);\n let label = segments.shift() ?? '';\n for (const segment of segments) {\n const pair = keyValue(segment);\n if (pair) {\n attributes[pair.key] = pair.value;\n } else {\n label += ` ${segment}`;\n }\n }\n return { label: label.trim(), attributes, refs, ...(scope ? { scope } : {}) };\n}\n\nfunction readRows(body: string): TreeTextRow[] {\n const drawn = DRAWING.test(body);\n const rows: TreeTextRow[] = [];\n for (const rawLine of body.split(/\\r?\\n/u)) {\n const line = rawLine.replaceAll('\\t', ' ');\n const scaffoldEnd = drawn\n ? (/^[\\u2502| ]*(?:(?:[\\u251C\\u2514]\\u2500+|[+`]-+) ?)?/u.exec(line)?.[0].length ?? 0)\n : (/^ */u.exec(line)?.[0].length ?? 0);\n const scaffold = line.slice(0, scaffoldEnd);\n const content = line.slice(scaffoldEnd).trim();\n if (!content) {\n continue;\n }\n const hasConnector = scaffold.includes('├') || scaffold.includes('└');\n const isRoot = scaffold.length === 0;\n if (drawn && !hasConnector && !isRoot && rows.length > 0) {\n rows.at(-1)?.description.push(content);\n continue;\n }\n rows.push({\n column: scaffold.length,\n ...parseNodeLine(content),\n description: [],\n });\n }\n return rows;\n}\n\nfunction assignDepths(rows: readonly TreeTextRow[]): number[] {\n const columns: number[] = [];\n return rows.map((row) => {\n while (columns.length > 0 && (columns.at(-1) ?? 0) >= row.column) {\n columns.pop();\n }\n const depth = columns.length;\n columns.push(row.column);\n return depth;\n });\n}\n\nfunction deliveryScope(value: string | undefined): DeliveryScope | undefined {\n if (!value) {\n return undefined;\n }\n return isIncrement(value)\n ? { kind: 'increment', increment: value }\n : value === 'deferred' || value === 'unassigned'\n ? { kind: value }\n : undefined;\n}\n\nfunction buildNode(row: TreeTextRow, children: ProductSpecComponent[]): ProductSpecComponent {\n const scope = deliveryScope(row.scope);\n const description = row.description.join(' ').trim();\n const ownChildren: ProductSpecNode[] = [\n ...(description ? [textNode(description, scope)] : []),\n ...row.refs.map((ref) =>\n component('ref', { relation: ref.relation, target: ref.target }, [], '', scope)\n ),\n ...children,\n ];\n const node = component(\n 'node',\n { ...row.attributes, label: row.label },\n ownChildren,\n row.label,\n scope\n );\n if (!scope || !row.scope) {\n return node;\n }\n const props =\n scope.kind === 'increment' ? { increment: scope.increment } : { [scope.kind]: true };\n return component('scope', props, [node], node.source, scope);\n}\n\nfunction assemble(rows: TreeTextRow[]): ProductSpecComponent[] {\n const depths = assignDepths(rows);\n const roots: ProductSpecComponent[] = [];\n const stack: MutableFrame[] = [];\n const close = (depth: number): void => {\n while (stack.length > depth) {\n const frame = stack.pop();\n if (!frame) {\n continue;\n }\n const built = buildNode(frame.row, frame.children);\n const parent = stack.at(-1);\n if (parent) {\n parent.children.push(built);\n } else {\n roots.push(built);\n }\n }\n };\n\n rows.forEach((row, index) => {\n close(Math.min(depths[index] ?? 0, stack.length));\n stack.push({ row, children: [] });\n });\n close(0);\n return roots;\n}\n\n/** Parse a drawn `leo.tree` fence into the shared product-spec component model. */\nexport function parseLeoTreeText(\n body: string,\n options: { readonly title?: string; readonly source?: string } = {}\n): ProductSpecComponent | undefined {\n const rows = readRows(body);\n if (rows.length === 0) {\n return undefined;\n }\n const children = assemble(rows);\n if (children.length === 0) {\n return undefined;\n }\n const source = options.source ?? body;\n return component(\n 'tree',\n { ...(options.title ? { title: options.title } : {}) },\n children,\n source\n );\n}\n\ninterface JourneyStep {\n readonly id?: string;\n readonly text: string;\n readonly body: string[];\n readonly refs: Array<{ readonly relation: string; readonly target: string }>;\n readonly attributes: Readonly<Record<string, string>>;\n scope?: string;\n readonly transitions: Array<{ readonly to: string; readonly when: string }>;\n}\n\n/** `1. text` or `1) text`; returns the text after the marker. */\nfunction stepMarker(line: string): string | undefined {\n return /^\\s*[0-9]+[.)] (.*)$/u.exec(line)?.[1];\n}\n\n/** `→ 2 when the linter reports an error`; the arrow may be written `->`. */\nfunction transitionLine(line: string): { to: string; when: string } | undefined {\n const match = /^(?:→|->)(.*)$/u.exec(line.trim());\n if (!match) {\n return undefined;\n }\n const rest = (match[1] ?? '').trim();\n const when = rest.indexOf(' when ');\n return when === -1\n ? { to: rest, when: '' }\n : { to: rest.slice(0, when).trim(), when: rest.slice(when + 6).trim() };\n}\n\nfunction readSteps(body: string): JourneyStep[] {\n const steps: JourneyStep[] = [];\n for (const rawLine of body.split(/\\r?\\n/u)) {\n const line = rawLine.replaceAll('\\t', ' ');\n if (!line.trim()) {\n continue;\n }\n const marker = stepMarker(line);\n if (marker !== undefined) {\n let text = marker;\n let id: string | undefined;\n const space = text.indexOf(' ');\n if (text.startsWith('#') && space !== -1) {\n id = text.slice(1, space);\n text = text.slice(space + 1);\n }\n const parsed = parseNodeLine(text);\n steps.push({\n ...(id ? { id } : {}),\n text: parsed.label,\n body: [],\n refs: [...parsed.refs],\n attributes: parsed.attributes,\n ...(parsed.scope ? { scope: parsed.scope } : {}),\n transitions: [],\n });\n continue;\n }\n const step = steps.at(-1);\n if (!step) {\n continue;\n }\n const edge = transitionLine(line);\n if (edge) {\n step.transitions.push(edge);\n continue;\n }\n const parsed = parseNodeLine(line.trim());\n step.refs.push(...parsed.refs);\n if (!parsed.label && parsed.refs.length > 0) {\n // A line holding only annotations qualifies the step above it.\n step.scope ??= parsed.scope;\n continue;\n }\n step.body.push(parsed.label);\n }\n return steps;\n}\n\n/** Lowercase, non-alphanumerics collapsed to `-`, at most six words. */\nfunction journeySlug(text: string): string {\n return text\n .toLowerCase()\n .replace(/[^\\p{L}\\p{N}]/gu, '-')\n .split('-')\n .filter(Boolean)\n .slice(0, 6)\n .join('-');\n}\n\nfunction buildStep(step: JourneyStep, number: number): ProductSpecComponent {\n const scope = deliveryScope(step.scope);\n const prose = [step.text, ...step.body].join(' ').trim();\n const children: ProductSpecNode[] = [\n ...(prose ? [textNode(prose, scope)] : []),\n ...step.refs.map((ref) =>\n component('ref', { relation: ref.relation, target: ref.target }, [], '', scope)\n ),\n ...step.transitions.map((edge) =>\n component(\n 'transition',\n // A transition to a bare number addresses the step of that ordinal.\n { to: /^[0-9]+$/u.test(edge.to) ? `step-${edge.to}` : edge.to, when: edge.when },\n [],\n '',\n scope\n )\n ),\n ];\n const node = component(\n 'step',\n { ...step.attributes, id: step.id ?? `step-${number}` },\n children,\n prose,\n scope\n );\n if (!scope) {\n return node;\n }\n const props =\n scope.kind === 'increment' ? { increment: scope.increment } : { [scope.kind]: true };\n return component('scope', props, [node], node.source, scope);\n}\n\n/**\n * Parse a numbered-list `leo.journey` fence into the shared product-spec component model.\n * A `N.` line is a step (`#id` after the marker overrides the derived `step-N`), an arrow\n * line is a transition, and other lines continue the step above.\n */\nexport function parseLeoJourneyText(\n body: string,\n options: { readonly title?: string; readonly source?: string } = {}\n): ProductSpecComponent | undefined {\n const steps = readSteps(body);\n if (steps.length === 0) {\n return undefined;\n }\n const title = options.title?.trim();\n return component(\n 'journey',\n title ? { id: journeySlug(title), title } : { id: 'journey' },\n steps.map((step, index) => buildStep(step, index + 1)),\n options.source ?? body\n );\n}\n"]}
@@ -0,0 +1,211 @@
1
+ /**
2
+ * @leo-studio/leo-markup — shared contract types.
3
+ *
4
+ * This module is the SINGLE source of truth for the vocabulary's shape: the
5
+ * `LeoComponent` registry entry, the canonical `PropSchema`, the parsed-document
6
+ * model the scanner produces, the frontmatter shape, and `PageContext`.
7
+ *
8
+ * leo-doc-core is the PURE CONTRACT package — it has NO React and NO ANSI
9
+ * dependency. The web emitter (a React component) and the ANSI emitter (a
10
+ * terminal string renderer) are typed here as OPAQUE markers; their concrete
11
+ * implementations are injected from leo-doc-web and leo-pty-renderer
12
+ * respectively. Core never imports either runtime, so it can be the
13
+ * shared dependency of both surfaces without dragging React onto the terminal
14
+ * hot path.
15
+ */
16
+ /**
17
+ * Which surfaces a vocabulary entry renders to.
18
+ * - `both`: parity-enforced — MUST register an ansi AND a web emitter.
19
+ * - `web-only`: registers a web emitter; declares a `degrade` for the terminal.
20
+ * - `terminal-only`: registers an ansi emitter; declares a `degrade` for the web.
21
+ */
22
+ export type RenderTarget = 'both' | 'web-only' | 'terminal-only';
23
+ /** Whether an authored island participates in surrounding Markdown flow. */
24
+ export type IslandFlow = 'inline' | 'block';
25
+ /**
26
+ * The terminal emitter: maps a resolved island (coerced props + parsed body) to
27
+ * an ANSI string. Defined as an opaque function marker here — leo-pty-renderer
28
+ * supplies the concrete fn. `unknown` props/return keep core free of
29
+ * the renderer's concrete types.
30
+ */
31
+ export type AnsiEmitter = (input: AnsiEmitterInput) => string;
32
+ export interface AnsiEmitterInput {
33
+ /** Coerced, validated props (per the component's PropSchema). */
34
+ readonly props: Record<string, unknown>;
35
+ /** The raw, balanced inner body of the island (empty for self-closing). */
36
+ readonly body: string;
37
+ /** Whether to emit color escapes. */
38
+ readonly color: boolean;
39
+ }
40
+ /**
41
+ * The web emitter: a React component. Typed as an OPAQUE marker (`WebEmitter`)
42
+ * so core stays React-free — leo-doc-web registers the concrete component and
43
+ * narrows the type at its own boundary. The parity harness only checks PRESENCE,
44
+ * never invokes it, so an opaque marker is sufficient for the contract.
45
+ */
46
+ export type WebEmitter = WebEmitterMarker;
47
+ /**
48
+ * Opaque brand for a registered web component. leo-doc-web casts its React
49
+ * component to this when registering; consumers cast back. The brand prevents an
50
+ * arbitrary value from silently satisfying `web?` in a registry entry.
51
+ */
52
+ export interface WebEmitterMarker {
53
+ readonly __leoWebEmitter: true;
54
+ }
55
+ /**
56
+ * How a component renders on the surface it does NOT target. Never an error and
57
+ * never leaked raw tag text.
58
+ * - `omit`: render nothing.
59
+ * - `inline`: render the body's children inline (e.g. web-only layout on terminal).
60
+ * - `summary`: a one-line marker/summary.
61
+ * - `note`: a static "see other surface" note.
62
+ */
63
+ export type DegradeKind = 'omit' | 'inline' | 'summary' | 'note';
64
+ export interface DegradeStrategy {
65
+ readonly kind: DegradeKind;
66
+ /** Optional static text for `summary`/`note`. */
67
+ readonly text?: string;
68
+ }
69
+ /**
70
+ * The canonical prop kind. Attributes arrive from the scanner as STRINGS; the
71
+ * schema coerces/validates per prop. A richer `json`
72
+ * kind covers props like `heatmap data` that are JSON-encoded in an attribute.
73
+ */
74
+ export type PropKind = 'string' | 'number' | 'boolean' | 'enum' | 'json';
75
+ export interface PropDecl {
76
+ readonly kind: PropKind;
77
+ readonly required?: boolean;
78
+ /** Allowed values when `kind: 'enum'` (lowercase canonical forms). */
79
+ readonly values?: readonly string[];
80
+ /** Default applied when the attribute is absent. */
81
+ readonly default?: unknown;
82
+ /**
83
+ * Human-readable note recording a canonical-naming decision — e.g. a
84
+ * leo-ANSI-attr-wins conflict. Auditable, not load-bearing at runtime.
85
+ */
86
+ readonly note?: string;
87
+ }
88
+ /** A component's canonical prop contract: prop name → declaration. */
89
+ export type PropSchema = Readonly<Record<string, PropDecl>>;
90
+ /**
91
+ * One vocabulary entry. Keyed in the registry by its lowercase authored `name`
92
+ * (`leo.callout` resolves `registry['callout']`). The React impl may be
93
+ * PascalCase internally; the registry key is always the lowercase authored form.
94
+ *
95
+ * Invariants (enforced by the parity harness, src/parity.ts):
96
+ * - `targets: 'both'` → both `ansi` AND `web` MUST be present.
97
+ * - `targets: 'web-only'` → `web` present; `degrade` declared (terminal).
98
+ * - `targets: 'terminal-only'`→ `ansi` present; `degrade` declared (web).
99
+ */
100
+ export interface LeoComponent {
101
+ /** Lowercase authored name — the registry key and the allow-list entry. */
102
+ readonly name: string;
103
+ /** Placement in authored Markdown; independent of body block classification. */
104
+ readonly flow: IslandFlow;
105
+ readonly targets: RenderTarget;
106
+ /** Canonical prop schema — both emitters adapt to this. */
107
+ readonly props: PropSchema;
108
+ /** Required iff targets ∈ {both, terminal-only}. Wired by leo-pty-renderer. */
109
+ readonly ansi?: AnsiEmitter;
110
+ /** Required iff targets ∈ {both, web-only}. Wired by leo-doc-web. */
111
+ readonly web?: WebEmitter;
112
+ /** Required iff the component does NOT target a surface. */
113
+ readonly degrade?: DegradeStrategy;
114
+ }
115
+ /** The registry root: lowercase authored name → entry. */
116
+ export type LeoRegistry = Readonly<Record<string, LeoComponent>>;
117
+ /**
118
+ * The scanner splits a source into ordered spans: prose passes through verbatim;
119
+ * each `<leo.*>` island is resolved against the registry. Spans are emitted in
120
+ * SOURCE ORDER so a renderer can interleave prose and islands into one tree.
121
+ */
122
+ export type DocSpan = ProseSpan | IslandSpan | MalformedSpan;
123
+ export interface ProseSpan {
124
+ readonly kind: 'prose';
125
+ /** Verbatim source text (never reformatted by the scanner). */
126
+ readonly text: string;
127
+ /** Source offsets [start, end) of this prose run. */
128
+ readonly start: number;
129
+ readonly end: number;
130
+ }
131
+ export interface IslandSpan {
132
+ readonly kind: 'island';
133
+ /** Lowercase authored tag name (e.g. `callout`); maps to a registry key. */
134
+ readonly name: string;
135
+ /** Raw attribute string → value map, as scanned (pre-coercion). */
136
+ readonly attrs: Readonly<Record<string, string>>;
137
+ /** The balanced inner body (empty for a self-closing island). */
138
+ readonly body: string;
139
+ /** True for `<leo.x ... />`. */
140
+ readonly selfClosing: boolean;
141
+ /** Absolute offset of the balanced body when emitted by the scanner. */
142
+ readonly bodyStart?: number;
143
+ /** Source offsets [start, end) of the whole island. */
144
+ readonly start: number;
145
+ readonly end: number;
146
+ }
147
+ /**
148
+ * A `<leo.` opener the scanner could not parse as a balanced island (e.g. an
149
+ * unterminated opener). It DEGRADES: the offending opener is preserved as text
150
+ * so surrounding content is never stalled or dropped (the malformed PoC case).
151
+ */
152
+ export interface MalformedSpan {
153
+ readonly kind: 'malformed';
154
+ /** The verbatim source slice that failed to parse (passed through as-is). */
155
+ readonly text: string;
156
+ /** Why it failed — for diagnostics/lints, not rendering. */
157
+ readonly reason: 'unterminated' | 'unclosed-body';
158
+ readonly start: number;
159
+ readonly end: number;
160
+ }
161
+ /** A scanned document: the frontmatter (if any) plus the ordered span list. */
162
+ export interface ParsedDocument {
163
+ readonly frontmatter: Frontmatter;
164
+ readonly spans: readonly DocSpan[];
165
+ }
166
+ /**
167
+ * The doc frontmatter shape. Discovery (leo-doc-web) parses YAML into
168
+ * this; core owns the type so both surfaces agree on the fields. Open-ended
169
+ * `[key: string]` keeps it tolerant of doc-specific extras.
170
+ */
171
+ export interface Frontmatter {
172
+ readonly title?: string;
173
+ readonly description?: string;
174
+ /** Ordering hint within a nav section. */
175
+ readonly order?: number;
176
+ /** Stability taxonomy (leo-documentation's IA concern; tolerated here). */
177
+ readonly status?: string;
178
+ readonly [key: string]: unknown;
179
+ }
180
+ /**
181
+ * Per-page render context. leo-doc-core OWNS this type; leo-doc-web
182
+ * POPULATES it during discovery and the app threads it through render. Core
183
+ * never constructs it — it only defines the contract both sides share.
184
+ */
185
+ export interface PageContext {
186
+ /** Route-relative path of the current page (e.g. `product/overview`). */
187
+ readonly path: string;
188
+ /** The page's parsed frontmatter. */
189
+ readonly frontmatter: Frontmatter;
190
+ /** Breadcrumb trail from root to this page (each: label + path). */
191
+ readonly breadcrumbs: readonly Breadcrumb[];
192
+ /** Trust level governing raw-HTML sanitization. */
193
+ readonly trust: TrustLevel;
194
+ }
195
+ export interface Breadcrumb {
196
+ readonly label: string;
197
+ readonly path: string;
198
+ }
199
+ /**
200
+ * Render trust level. `first-party` content (leo's own docs) may skip
201
+ * HTML sanitization; `untrusted` content is sanitized with an allow-list.
202
+ */
203
+ export type TrustLevel = 'first-party' | 'untrusted';
204
+ export declare function isProseSpan(span: DocSpan): span is ProseSpan;
205
+ export declare function isIslandSpan(span: DocSpan): span is IslandSpan;
206
+ export declare function isMalformedSpan(span: DocSpan): span is MalformedSpan;
207
+ /** True when the entry must register an ANSI emitter (both | terminal-only). */
208
+ export declare function requiresAnsi(component: LeoComponent): boolean;
209
+ /** True when the entry must register a web emitter (both | web-only). */
210
+ export declare function requiresWeb(component: LeoComponent): boolean;
211
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,UAAU,GAAG,eAAe,CAAC;AAEjE,4EAA4E;AAC5E,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,gBAAgB,KAAK,MAAM,CAAC;AAE9D,MAAM,WAAW,gBAAgB;IAC7B,iEAAiE;IACjE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qCAAqC;IACrC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,gBAAgB,CAAC;AAE1C;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,eAAe,EAAE,IAAI,CAAC;CAClC;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG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,yEAAyE;AACzE,wBAAgB,WAAW,CAAC,SAAS,EAAE,YAAY,GAAG,OAAO,CAE5D"}
package/dist/types.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @leo-studio/leo-markup — shared contract types.
3
+ *
4
+ * This module is the SINGLE source of truth for the vocabulary's shape: the
5
+ * `LeoComponent` registry entry, the canonical `PropSchema`, the parsed-document
6
+ * model the scanner produces, the frontmatter shape, and `PageContext`.
7
+ *
8
+ * leo-doc-core is the PURE CONTRACT package — it has NO React and NO ANSI
9
+ * dependency. The web emitter (a React component) and the ANSI emitter (a
10
+ * terminal string renderer) are typed here as OPAQUE markers; their concrete
11
+ * implementations are injected from leo-doc-web and leo-pty-renderer
12
+ * respectively. Core never imports either runtime, so it can be the
13
+ * shared dependency of both surfaces without dragging React onto the terminal
14
+ * hot path.
15
+ */
16
+ // ── Type guards ─────────────────────────────────────────────────────────────
17
+ export function isProseSpan(span) {
18
+ return span.kind === 'prose';
19
+ }
20
+ export function isIslandSpan(span) {
21
+ return span.kind === 'island';
22
+ }
23
+ export function isMalformedSpan(span) {
24
+ return span.kind === 'malformed';
25
+ }
26
+ /** True when the entry must register an ANSI emitter (both | terminal-only). */
27
+ export function requiresAnsi(component) {
28
+ return component.targets === 'both' || component.targets === 'terminal-only';
29
+ }
30
+ /** True when the entry must register a web emitter (both | web-only). */
31
+ export function requiresWeb(component) {
32
+ return component.targets === 'both' || component.targets === 'web-only';
33
+ }
34
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAgOH,+EAA+E;AAE/E,MAAM,UAAU,WAAW,CAAC,IAAa;IACrC,OAAO,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAa;IACtC,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAa;IACzC,OAAO,IAAI,CAAC,IAAI,KAAK,WAAW,CAAC;AACrC,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,YAAY,CAAC,SAAuB;IAChD,OAAO,SAAS,CAAC,OAAO,KAAK,MAAM,IAAI,SAAS,CAAC,OAAO,KAAK,eAAe,CAAC;AACjF,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,WAAW,CAAC,SAAuB;IAC/C,OAAO,SAAS,CAAC,OAAO,KAAK,MAAM,IAAI,SAAS,CAAC,OAAO,KAAK,UAAU,CAAC;AAC5E,CAAC","sourcesContent":["/**\n * @leo-studio/leo-markup — shared contract types.\n *\n * This module is the SINGLE source of truth for the vocabulary's shape: the\n * `LeoComponent` registry entry, the canonical `PropSchema`, the parsed-document\n * model the scanner produces, the frontmatter shape, and `PageContext`.\n *\n * leo-doc-core is the PURE CONTRACT package — it has NO React and NO ANSI\n * dependency. The web emitter (a React component) and the ANSI emitter (a\n * terminal string renderer) are typed here as OPAQUE markers; their concrete\n * implementations are injected from leo-doc-web and leo-pty-renderer\n * respectively. Core never imports either runtime, so it can be the\n * shared dependency of both surfaces without dragging React onto the terminal\n * hot path.\n */\n\n// ── Targets & emitters ──────────────────────────────────────────────────────\n\n/**\n * Which surfaces a vocabulary entry renders to.\n * - `both`: parity-enforced — MUST register an ansi AND a web emitter.\n * - `web-only`: registers a web emitter; declares a `degrade` for the terminal.\n * - `terminal-only`: registers an ansi emitter; declares a `degrade` for the web.\n */\nexport type RenderTarget = 'both' | 'web-only' | 'terminal-only';\n\n/** Whether an authored island participates in surrounding Markdown flow. */\nexport type IslandFlow = 'inline' | 'block';\n\n/**\n * The terminal emitter: maps a resolved island (coerced props + parsed body) to\n * an ANSI string. Defined as an opaque function marker here — leo-pty-renderer\n * supplies the concrete fn. `unknown` props/return keep core free of\n * the renderer's concrete types.\n */\nexport type AnsiEmitter = (input: AnsiEmitterInput) => string;\n\nexport interface AnsiEmitterInput {\n /** Coerced, validated props (per the component's PropSchema). */\n readonly props: Record<string, unknown>;\n /** The raw, balanced inner body of the island (empty for self-closing). */\n readonly body: string;\n /** Whether to emit color escapes. */\n readonly color: boolean;\n}\n\n/**\n * The web emitter: a React component. Typed as an OPAQUE marker (`WebEmitter`)\n * so core stays React-free — leo-doc-web registers the concrete component and\n * narrows the type at its own boundary. The parity harness only checks PRESENCE,\n * never invokes it, so an opaque marker is sufficient for the contract.\n */\nexport type WebEmitter = WebEmitterMarker;\n\n/**\n * Opaque brand for a registered web component. leo-doc-web casts its React\n * component to this when registering; consumers cast back. The brand prevents an\n * arbitrary value from silently satisfying `web?` in a registry entry.\n */\nexport interface WebEmitterMarker {\n readonly __leoWebEmitter: true;\n}\n\n/**\n * How a component renders on the surface it does NOT target. Never an error and\n * never leaked raw tag text.\n * - `omit`: render nothing.\n * - `inline`: render the body's children inline (e.g. web-only layout on terminal).\n * - `summary`: a one-line marker/summary.\n * - `note`: a static \"see other surface\" note.\n */\nexport type DegradeKind = 'omit' | 'inline' | 'summary' | 'note';\n\nexport interface DegradeStrategy {\n readonly kind: DegradeKind;\n /** Optional static text for `summary`/`note`. */\n readonly text?: string;\n}\n\n// ── Prop schema (hand-rolled, dependency-free) ──────────────────────────────\n\n/**\n * The canonical prop kind. Attributes arrive from the scanner as STRINGS; the\n * schema coerces/validates per prop. A richer `json`\n * kind covers props like `heatmap data` that are JSON-encoded in an attribute.\n */\nexport type PropKind = 'string' | 'number' | 'boolean' | 'enum' | 'json';\n\nexport interface PropDecl {\n readonly kind: PropKind;\n readonly required?: boolean;\n /** Allowed values when `kind: 'enum'` (lowercase canonical forms). */\n readonly values?: readonly string[];\n /** Default applied when the attribute is absent. */\n readonly default?: unknown;\n /**\n * Human-readable note recording a canonical-naming decision — e.g. a\n * leo-ANSI-attr-wins conflict. Auditable, not load-bearing at runtime.\n */\n readonly note?: string;\n}\n\n/** A component's canonical prop contract: prop name → declaration. */\nexport type PropSchema = Readonly<Record<string, PropDecl>>;\n\n// ── The registry entry ──────────────────────────────────────────────────────\n\n/**\n * One vocabulary entry. Keyed in the registry by its lowercase authored `name`\n * (`leo.callout` resolves `registry['callout']`). The React impl may be\n * PascalCase internally; the registry key is always the lowercase authored form.\n *\n * Invariants (enforced by the parity harness, src/parity.ts):\n * - `targets: 'both'` → both `ansi` AND `web` MUST be present.\n * - `targets: 'web-only'` → `web` present; `degrade` declared (terminal).\n * - `targets: 'terminal-only'`→ `ansi` present; `degrade` declared (web).\n */\nexport interface LeoComponent {\n /** Lowercase authored name — the registry key and the allow-list entry. */\n readonly name: string;\n /** Placement in authored Markdown; independent of body block classification. */\n readonly flow: IslandFlow;\n readonly targets: RenderTarget;\n /** Canonical prop schema — both emitters adapt to this. */\n readonly props: PropSchema;\n /** Required iff targets ∈ {both, terminal-only}. Wired by leo-pty-renderer. */\n readonly ansi?: AnsiEmitter;\n /** Required iff targets ∈ {both, web-only}. Wired by leo-doc-web. */\n readonly web?: WebEmitter;\n /** Required iff the component does NOT target a surface. */\n readonly degrade?: DegradeStrategy;\n}\n\n/** The registry root: lowercase authored name → entry. */\nexport type LeoRegistry = Readonly<Record<string, LeoComponent>>;\n\n// ── Parsed-document model (scanner output) ──────────────────────────────────\n\n/**\n * The scanner splits a source into ordered spans: prose passes through verbatim;\n * each `<leo.*>` island is resolved against the registry. Spans are emitted in\n * SOURCE ORDER so a renderer can interleave prose and islands into one tree.\n */\nexport type DocSpan = ProseSpan | IslandSpan | MalformedSpan;\n\nexport interface ProseSpan {\n readonly kind: 'prose';\n /** Verbatim source text (never reformatted by the scanner). */\n readonly text: string;\n /** Source offsets [start, end) of this prose run. */\n readonly start: number;\n readonly end: number;\n}\n\nexport interface IslandSpan {\n readonly kind: 'island';\n /** Lowercase authored tag name (e.g. `callout`); maps to a registry key. */\n readonly name: string;\n /** Raw attribute string → value map, as scanned (pre-coercion). */\n readonly attrs: Readonly<Record<string, string>>;\n /** The balanced inner body (empty for a self-closing island). */\n readonly body: string;\n /** True for `<leo.x ... />`. */\n readonly selfClosing: boolean;\n /** Absolute offset of the balanced body when emitted by the scanner. */\n readonly bodyStart?: number;\n /** Source offsets [start, end) of the whole island. */\n readonly start: number;\n readonly end: number;\n}\n\n/**\n * A `<leo.` opener the scanner could not parse as a balanced island (e.g. an\n * unterminated opener). It DEGRADES: the offending opener is preserved as text\n * so surrounding content is never stalled or dropped (the malformed PoC case).\n */\nexport interface MalformedSpan {\n readonly kind: 'malformed';\n /** The verbatim source slice that failed to parse (passed through as-is). */\n readonly text: string;\n /** Why it failed — for diagnostics/lints, not rendering. */\n readonly reason: 'unterminated' | 'unclosed-body';\n readonly start: number;\n readonly end: number;\n}\n\n/** A scanned document: the frontmatter (if any) plus the ordered span list. */\nexport interface ParsedDocument {\n readonly frontmatter: Frontmatter;\n readonly spans: readonly DocSpan[];\n}\n\n// ── Frontmatter ─────────────────────────────────────────────────────────────\n\n/**\n * The doc frontmatter shape. Discovery (leo-doc-web) parses YAML into\n * this; core owns the type so both surfaces agree on the fields. Open-ended\n * `[key: string]` keeps it tolerant of doc-specific extras.\n */\nexport interface Frontmatter {\n readonly title?: string;\n readonly description?: string;\n /** Ordering hint within a nav section. */\n readonly order?: number;\n /** Stability taxonomy (leo-documentation's IA concern; tolerated here). */\n readonly status?: string;\n readonly [key: string]: unknown;\n}\n\n// ── PageContext (core OWNS this type) ───────────────────────────────────────\n\n/**\n * Per-page render context. leo-doc-core OWNS this type; leo-doc-web\n * POPULATES it during discovery and the app threads it through render. Core\n * never constructs it — it only defines the contract both sides share.\n */\nexport interface PageContext {\n /** Route-relative path of the current page (e.g. `product/overview`). */\n readonly path: string;\n /** The page's parsed frontmatter. */\n readonly frontmatter: Frontmatter;\n /** Breadcrumb trail from root to this page (each: label + path). */\n readonly breadcrumbs: readonly Breadcrumb[];\n /** Trust level governing raw-HTML sanitization. */\n readonly trust: TrustLevel;\n}\n\nexport interface Breadcrumb {\n readonly label: string;\n readonly path: string;\n}\n\n/**\n * Render trust level. `first-party` content (leo's own docs) may skip\n * HTML sanitization; `untrusted` content is sanitized with an allow-list.\n */\nexport type TrustLevel = 'first-party' | 'untrusted';\n\n// ── Type guards ─────────────────────────────────────────────────────────────\n\nexport function isProseSpan(span: DocSpan): span is ProseSpan {\n return span.kind === 'prose';\n}\n\nexport function isIslandSpan(span: DocSpan): span is IslandSpan {\n return span.kind === 'island';\n}\n\nexport function isMalformedSpan(span: DocSpan): span is MalformedSpan {\n return span.kind === 'malformed';\n}\n\n/** True when the entry must register an ANSI emitter (both | terminal-only). */\nexport function requiresAnsi(component: LeoComponent): boolean {\n return component.targets === 'both' || component.targets === 'terminal-only';\n}\n\n/** True when the entry must register a web emitter (both | web-only). */\nexport function requiresWeb(component: LeoComponent): boolean {\n return component.targets === 'both' || component.targets === 'web-only';\n}\n"]}