@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
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ Copyright (c) 2026 Marius Rackwitz
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,19 @@
1
- # Temporary Holding Version
1
+ # @leo-studio/leo-markup
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Pure-contract doc engine: shared leo.* vocabulary, island scanner, leo registry, prop schemas, PageContext type, and the parity test harness
4
+
5
+ ## Usage
6
+
7
+ ```typescript
8
+ import { isIslandSpan, scan } from '@leo-studio/leo-markup';
9
+
10
+ const islands = scan('Stability: <leo.badge value="Stable" />').filter(isIslandSpan);
11
+ ```
12
+
13
+ ## Development
14
+
15
+ ```sh
16
+ pnpm build # tsc → dist/ (.js, .d.ts, source maps)
17
+ pnpm test # Vitest
18
+ pnpm smoke:pack # build, pnpm pack, import the tarball with plain node
19
+ ```
@@ -0,0 +1,10 @@
1
+ /** Canonical agent support vocabulary shared by web and terminal emitters. */
2
+ export declare const AGENT_SUPPORT_AGENTS: readonly ['claude-code', 'codex', 'cursor'];
3
+ export type AgentSupportAgent = (typeof AGENT_SUPPORT_AGENTS)[number];
4
+ export declare const AGENT_SUPPORT_STATES: readonly ['yes', 'no', 'not-applicable'];
5
+ export type AgentSupportState = (typeof AGENT_SUPPORT_STATES)[number];
6
+ export declare const AGENT_SUPPORT_QUALIFIERS: readonly ['native', 'emulated', 'defense-in-depth', 'wired'];
7
+ export type AgentSupportQualifier = (typeof AGENT_SUPPORT_QUALIFIERS)[number];
8
+ export declare function agentSupportLabel(agent: AgentSupportAgent, support: AgentSupportState, qualifier?: AgentSupportQualifier): string;
9
+ export declare function agentSupportAgentLabel(agent: AgentSupportAgent): string;
10
+ //# sourceMappingURL=agent-support.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-support.d.ts","sourceRoot":"","sources":["../src/agent-support.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB,YAAI,aAAa,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAC;AAChF,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtE,eAAO,MAAM,oBAAoB,YAAI,KAAK,EAAE,IAAI,EAAE,gBAAgB,CAAU,CAAC;AAC7E,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtE,eAAO,MAAM,wBAAwB,YACjC,QAAQ,EACR,UAAU,EACV,kBAAkB,EAClB,OAAO,CACD,CAAC;AACX,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC;AAc9E,wBAAgB,iBAAiB,CAC7B,KAAK,EAAE,iBAAiB,EACxB,OAAO,EAAE,iBAAiB,EAC1B,SAAS,CAAC,EAAE,qBAAqB,GAClC,MAAM,CAGR;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,CAEvE"}
@@ -0,0 +1,27 @@
1
+ /** Canonical agent support vocabulary shared by web and terminal emitters. */
2
+ export const AGENT_SUPPORT_AGENTS = ['claude-code', 'codex', 'cursor'];
3
+ export const AGENT_SUPPORT_STATES = ['yes', 'no', 'not-applicable'];
4
+ export const AGENT_SUPPORT_QUALIFIERS = [
5
+ 'native',
6
+ 'emulated',
7
+ 'defense-in-depth',
8
+ 'wired',
9
+ ];
10
+ const AGENT_LABELS = {
11
+ 'claude-code': 'Claude Code',
12
+ codex: 'Codex',
13
+ cursor: 'Cursor',
14
+ };
15
+ const SUPPORT_LABELS = {
16
+ yes: 'supported',
17
+ no: 'unsupported',
18
+ 'not-applicable': 'not applicable',
19
+ };
20
+ export function agentSupportLabel(agent, support, qualifier) {
21
+ const qualification = qualifier ? ` (${qualifier})` : '';
22
+ return `${AGENT_LABELS[agent]}: ${SUPPORT_LABELS[support]}${qualification}`;
23
+ }
24
+ export function agentSupportAgentLabel(agent) {
25
+ return AGENT_LABELS[agent];
26
+ }
27
+ //# sourceMappingURL=agent-support.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-support.js","sourceRoot":"","sources":["../src/agent-support.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,aAAa,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAC;AAGhF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,gBAAgB,CAAU,CAAC;AAG7E,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACpC,QAAQ;IACR,UAAU;IACV,kBAAkB;IAClB,OAAO;CACD,CAAC;AAGX,MAAM,YAAY,GAAsC;IACpD,aAAa,EAAE,aAAa;IAC5B,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;CACnB,CAAC;AAEF,MAAM,cAAc,GAAsC;IACtD,GAAG,EAAE,WAAW;IAChB,EAAE,EAAE,aAAa;IACjB,gBAAgB,EAAE,gBAAgB;CACrC,CAAC;AAEF,MAAM,UAAU,iBAAiB,CAC7B,KAAwB,EACxB,OAA0B,EAC1B,SAAiC;IAEjC,MAAM,aAAa,GAAG,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACzD,OAAO,GAAG,YAAY,CAAC,KAAK,CAAC,KAAK,cAAc,CAAC,OAAO,CAAC,GAAG,aAAa,EAAE,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,KAAwB;IAC3D,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["/** Canonical agent support vocabulary shared by web and terminal emitters. */\nexport const AGENT_SUPPORT_AGENTS = ['claude-code', 'codex', 'cursor'] as const;\nexport type AgentSupportAgent = (typeof AGENT_SUPPORT_AGENTS)[number];\n\nexport const AGENT_SUPPORT_STATES = ['yes', 'no', 'not-applicable'] as const;\nexport type AgentSupportState = (typeof AGENT_SUPPORT_STATES)[number];\n\nexport const AGENT_SUPPORT_QUALIFIERS = [\n 'native',\n 'emulated',\n 'defense-in-depth',\n 'wired',\n] as const;\nexport type AgentSupportQualifier = (typeof AGENT_SUPPORT_QUALIFIERS)[number];\n\nconst AGENT_LABELS: Record<AgentSupportAgent, string> = {\n 'claude-code': 'Claude Code',\n codex: 'Codex',\n cursor: 'Cursor',\n};\n\nconst SUPPORT_LABELS: Record<AgentSupportState, string> = {\n yes: 'supported',\n no: 'unsupported',\n 'not-applicable': 'not applicable',\n};\n\nexport function agentSupportLabel(\n agent: AgentSupportAgent,\n support: AgentSupportState,\n qualifier?: AgentSupportQualifier\n): string {\n const qualification = qualifier ? ` (${qualifier})` : '';\n return `${AGENT_LABELS[agent]}: ${SUPPORT_LABELS[support]}${qualification}`;\n}\n\nexport function agentSupportAgentLabel(agent: AgentSupportAgent): string {\n return AGENT_LABELS[agent];\n}\n"]}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * The JSON projection of a parsed leo markup document, as described by
3
+ * schema/leo-markup-ast.schema.json at the repository root. Both implementations
4
+ * are checked against fixtures in this shape, so it is deterministic: object keys
5
+ * are emitted in a fixed order (attribute and prop maps sorted by key) and no
6
+ * value is `undefined`.
7
+ */
8
+ export type AstJsonValue = string | number | boolean | null | readonly AstJsonValue[] | {
9
+ readonly [key: string]: AstJsonValue;
10
+ };
11
+ export type AstScope = {
12
+ readonly kind: 'increment';
13
+ readonly increment: string;
14
+ } | {
15
+ readonly kind: 'deferred' | 'unassigned';
16
+ };
17
+ export type AstSpan = {
18
+ readonly kind: 'prose';
19
+ readonly start: number;
20
+ readonly end: number;
21
+ } | {
22
+ readonly kind: 'island';
23
+ readonly name: string;
24
+ readonly start: number;
25
+ readonly end: number;
26
+ readonly bodyStart: number;
27
+ readonly bodyEnd: number;
28
+ readonly selfClosing: boolean;
29
+ readonly attrs: Readonly<Record<string, string>>;
30
+ readonly known: boolean;
31
+ readonly props: Readonly<Record<string, AstJsonValue>>;
32
+ readonly errors: readonly string[];
33
+ } | {
34
+ readonly kind: 'malformed';
35
+ readonly reason: 'unterminated' | 'unclosed-body';
36
+ readonly start: number;
37
+ readonly end: number;
38
+ };
39
+ export interface AstFenceComponent {
40
+ readonly kind: 'component';
41
+ readonly name: string;
42
+ readonly props: Readonly<Record<string, string | boolean>>;
43
+ readonly scope?: AstScope;
44
+ readonly children: readonly (AstFenceComponent | AstFenceText)[];
45
+ }
46
+ export interface AstFenceText {
47
+ readonly kind: 'text';
48
+ readonly text: string;
49
+ }
50
+ export type AstNode = {
51
+ readonly kind: 'component';
52
+ readonly name: string;
53
+ readonly start: number;
54
+ readonly end: number;
55
+ readonly bodyStart: number;
56
+ readonly bodyEnd: number;
57
+ readonly props: Readonly<Record<string, string | boolean>>;
58
+ readonly scope?: AstScope;
59
+ readonly children: readonly AstNode[];
60
+ } | {
61
+ readonly kind: 'prose' | 'fallback';
62
+ readonly start: number;
63
+ readonly end: number;
64
+ readonly scope?: AstScope;
65
+ } | {
66
+ readonly kind: 'display';
67
+ readonly name: string;
68
+ readonly start: number;
69
+ readonly end: number;
70
+ readonly scope?: AstScope;
71
+ } | {
72
+ readonly kind: 'fence';
73
+ readonly form: 'tree' | 'journey';
74
+ readonly start: number;
75
+ readonly end: number;
76
+ readonly title?: string;
77
+ readonly scope?: AstScope;
78
+ /** `null` when the block claims a form but yields no content. */
79
+ readonly component: AstFenceComponent | null;
80
+ };
81
+ export interface AstDiagnostic {
82
+ readonly code: string;
83
+ readonly message: string;
84
+ readonly start: number;
85
+ readonly end: number;
86
+ }
87
+ export interface AstDocument {
88
+ readonly version: 1;
89
+ /** Offset of the first character after the frontmatter block (0 without one). */
90
+ readonly bodyStart: number;
91
+ readonly spans: readonly AstSpan[];
92
+ readonly productSpec: {
93
+ readonly nodes: readonly AstNode[];
94
+ readonly diagnostics: readonly AstDiagnostic[];
95
+ };
96
+ }
97
+ /**
98
+ * Project a leo markup document (frontmatter, if any, is skipped) into the AST
99
+ * JSON shape: the scanner's top-level spans and the product-spec node tree, with
100
+ * `leo.tree` / `leo.journey` fences parsed into their component form. Offsets
101
+ * are UTF-16 code-unit offsets into `source`.
102
+ */
103
+ export declare function toAstJson(source: string): AstDocument;
104
+ //# sourceMappingURL=ast-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast-json.d.ts","source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,aAAa,EAAE,CAAC;KAClD,CAAC;CACL;AAqLD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAkBrD"}
@@ -0,0 +1,203 @@
1
+ /**
2
+ * The JSON projection of a parsed leo markup document, as described by
3
+ * schema/leo-markup-ast.schema.json at the repository root. Both implementations
4
+ * are checked against fixtures in this shape, so it is deterministic: object keys
5
+ * are emitted in a fixed order (attribute and prop maps sorted by key) and no
6
+ * value is `undefined`.
7
+ */
8
+ import { findFenceEnd, readFence } from './fence.js';
9
+ import { parseProductSpec, productSpecSchemas, } from './product-spec.js';
10
+ import { coerceProps, leoRegistry } from './registry.js';
11
+ import { scan } from './scanner.js';
12
+ import { parseLeoJourneyText, parseLeoTreeText } from './tree-text.js';
13
+ function sorted(record) {
14
+ return Object.fromEntries(Object.keys(record)
15
+ .sort()
16
+ .map((key) => [key, record[key]]));
17
+ }
18
+ function scopeJson(scope) {
19
+ if (!scope) {
20
+ return {};
21
+ }
22
+ return {
23
+ scope: scope.kind === 'increment'
24
+ ? { kind: 'increment', increment: scope.increment }
25
+ : { kind: scope.kind },
26
+ };
27
+ }
28
+ /** Offset just past a leading `---` frontmatter block, or 0. */
29
+ function frontmatterEnd(source) {
30
+ const firstEnd = source.indexOf('\n');
31
+ if (firstEnd === -1 || source.slice(0, firstEnd).trim() !== '---') {
32
+ return 0;
33
+ }
34
+ let lineStart = firstEnd + 1;
35
+ while (lineStart < source.length) {
36
+ const lineEnd = source.indexOf('\n', lineStart);
37
+ const end = lineEnd === -1 ? source.length : lineEnd;
38
+ if (source.slice(lineStart, end).trim() === '---') {
39
+ return lineEnd === -1 ? source.length : lineEnd + 1;
40
+ }
41
+ lineStart = end + 1;
42
+ }
43
+ return 0;
44
+ }
45
+ function spanJson(span, offset) {
46
+ const start = offset + span.start;
47
+ const end = offset + span.end;
48
+ if (span.kind === 'prose') {
49
+ return { kind: 'prose', start, end };
50
+ }
51
+ if (span.kind === 'malformed') {
52
+ return { kind: 'malformed', reason: span.reason, start, end };
53
+ }
54
+ // Display vocabulary first: the scanner level is what terminal and web renderers resolve.
55
+ const schema = Object.hasOwn(leoRegistry, span.name)
56
+ ? leoRegistry[span.name]?.props
57
+ : Object.hasOwn(productSpecSchemas, span.name)
58
+ ? productSpecSchemas[span.name]
59
+ : undefined;
60
+ const coerced = schema ? coerceProps(schema, span.attrs) : { props: {}, errors: [] };
61
+ const bodyStart = offset + (span.bodyStart ?? span.end);
62
+ return {
63
+ kind: 'island',
64
+ name: span.name,
65
+ start,
66
+ end,
67
+ bodyStart,
68
+ bodyEnd: bodyStart + span.body.length,
69
+ selfClosing: span.selfClosing,
70
+ attrs: sorted(span.attrs),
71
+ known: schema !== undefined,
72
+ props: sorted(coerced.props),
73
+ errors: [...coerced.errors],
74
+ };
75
+ }
76
+ function fenceComponentJson(node) {
77
+ return {
78
+ kind: 'component',
79
+ name: node.name,
80
+ props: sorted(node.props),
81
+ ...scopeJson(node.scope),
82
+ children: node.children.map((child) => child.kind === 'component'
83
+ ? fenceComponentJson(child)
84
+ : { kind: 'text', text: child.source }),
85
+ };
86
+ }
87
+ /** Split a prose node around the closed `leo.tree` / `leo.journey` fences it contains. */
88
+ function splitFences(source, start, end, scope) {
89
+ const nodes = [];
90
+ let proseStart = start;
91
+ const firstBreak = source.indexOf('\n', start);
92
+ let lineStart = start === 0 || source[start - 1] === '\n'
93
+ ? start
94
+ : firstBreak === -1
95
+ ? end
96
+ : firstBreak + 1;
97
+ while (lineStart < end) {
98
+ const fence = readFence(source, lineStart);
99
+ if (fence) {
100
+ const closeEnd = findFenceEnd(source, fence.contentStart, fence.marker, fence.length);
101
+ if (closeEnd === -1 || closeEnd > end + 1) {
102
+ break;
103
+ }
104
+ const closerEnd = source[closeEnd - 1] === '\n' ? closeEnd - 1 : closeEnd;
105
+ const token = fence.info.split(/\s+/u)[0] ?? '';
106
+ if (token === 'leo.tree' || token === 'leo.journey') {
107
+ const closerStart = source.lastIndexOf('\n', closerEnd - 1) + 1;
108
+ const body = source.slice(fence.contentStart, closerStart).replace(/\n$/u, '');
109
+ const title = fence.info.slice(token.length).trim();
110
+ const parsed = token === 'leo.tree'
111
+ ? parseLeoTreeText(body, title ? { title } : {})
112
+ : parseLeoJourneyText(body, title ? { title } : {});
113
+ if (lineStart > proseStart) {
114
+ nodes.push({
115
+ kind: 'prose',
116
+ start: proseStart,
117
+ end: lineStart,
118
+ ...scopeJson(scope),
119
+ });
120
+ }
121
+ nodes.push({
122
+ kind: 'fence',
123
+ form: token === 'leo.tree' ? 'tree' : 'journey',
124
+ start: lineStart,
125
+ end: closerEnd,
126
+ ...(title ? { title } : {}),
127
+ ...scopeJson(scope),
128
+ component: parsed ? fenceComponentJson(parsed) : null,
129
+ });
130
+ proseStart = closerEnd;
131
+ }
132
+ lineStart = closeEnd;
133
+ continue;
134
+ }
135
+ const next = source.indexOf('\n', lineStart);
136
+ if (next === -1) {
137
+ break;
138
+ }
139
+ lineStart = next + 1;
140
+ }
141
+ if (proseStart < end) {
142
+ nodes.push({ kind: 'prose', start: proseStart, end, ...scopeJson(scope) });
143
+ }
144
+ return nodes;
145
+ }
146
+ function nodeJson(node, source) {
147
+ if (node.kind === 'component') {
148
+ return [
149
+ {
150
+ kind: 'component',
151
+ name: node.name,
152
+ start: node.start,
153
+ end: node.end,
154
+ bodyStart: node.bodyStart,
155
+ bodyEnd: node.bodyStart + node.body.length,
156
+ props: sorted(node.props),
157
+ ...scopeJson(node.scope),
158
+ children: node.children.flatMap((child) => nodeJson(child, source)),
159
+ },
160
+ ];
161
+ }
162
+ if (node.kind === 'display') {
163
+ return [
164
+ {
165
+ kind: 'display',
166
+ name: node.island.name,
167
+ start: node.start,
168
+ end: node.end,
169
+ ...scopeJson(node.scope),
170
+ },
171
+ ];
172
+ }
173
+ if (node.kind === 'prose') {
174
+ return splitFences(source, node.start, node.end, node.scope);
175
+ }
176
+ return [{ kind: 'fallback', start: node.start, end: node.end, ...scopeJson(node.scope) }];
177
+ }
178
+ /**
179
+ * Project a leo markup document (frontmatter, if any, is skipped) into the AST
180
+ * JSON shape: the scanner's top-level spans and the product-spec node tree, with
181
+ * `leo.tree` / `leo.journey` fences parsed into their component form. Offsets
182
+ * are UTF-16 code-unit offsets into `source`.
183
+ */
184
+ export function toAstJson(source) {
185
+ const bodyStart = frontmatterEnd(source);
186
+ const body = source.slice(bodyStart);
187
+ const parsed = parseProductSpec(body, { offset: bodyStart });
188
+ return {
189
+ version: 1,
190
+ bodyStart,
191
+ spans: scan(body).map((span) => spanJson(span, bodyStart)),
192
+ productSpec: {
193
+ nodes: parsed.nodes.flatMap((node) => nodeJson(node, source)),
194
+ diagnostics: parsed.diagnostics.map((diagnostic) => ({
195
+ code: diagnostic.code,
196
+ message: diagnostic.message,
197
+ start: diagnostic.start,
198
+ end: diagnostic.end,
199
+ })),
200
+ },
201
+ };
202
+ }
203
+ //# sourceMappingURL=ast-json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast-json.js","sourceRoot":"","sources":["../src/ast-json.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAIH,gBAAgB,EAChB,kBAAkB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAwGvE,SAAS,MAAM,CAAI,MAAmC;IAClD,OAAO,MAAM,CAAC,WAAW,CACrB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SACd,IAAI,EAAE;SACN,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAM,CAAC,CAAC,CAC7C,CAAC;AACN,CAAC;AAED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AAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAC9F,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,MAAc;IACpC,MAAM,SAAS,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IAC7D,OAAO;QACH,OAAO,EAAE,CAAC;QACV,SAAS;QACT,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC1D,WAAW,EAAE;YACT,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC7D,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;gBACjD,IAAI,EAAE,UAAU,CAAC,IAAI;gBACrB,OAAO,EAAE,UAAU,CAAC,OAAO;gBAC3B,KAAK,EAAE,UAAU,CAAC,KAAK;gBACvB,GAAG,EAAE,UAAU,CAAC,GAAG;aACtB,CAAC,CAAC;SACN;KACJ,CAAC;AACN,CAAC","sourcesContent":["/**\n * The JSON projection of a parsed leo markup document, as described by\n * schema/leo-markup-ast.schema.json at the repository root. Both implementations\n * are checked against fixtures in this shape, so it is deterministic: object keys\n * are emitted in a fixed order (attribute and prop maps sorted by key) and no\n * value is `undefined`.\n */\n\nimport { findFenceEnd, readFence } from './fence.js';\nimport {\n type DeliveryScope,\n type ProductSpecComponent,\n type ProductSpecNode,\n parseProductSpec,\n productSpecSchemas,\n} from './product-spec.js';\nimport { coerceProps, leoRegistry } from './registry.js';\nimport { scan } from './scanner.js';\nimport { parseLeoJourneyText, parseLeoTreeText } from './tree-text.js';\nimport type { DocSpan, PropSchema } from './types.js';\n\nexport type AstJsonValue =\n | string\n | number\n | boolean\n | null\n | readonly AstJsonValue[]\n | { readonly [key: string]: AstJsonValue };\n\nexport type AstScope =\n | { readonly kind: 'increment'; readonly increment: string }\n | { readonly kind: 'deferred' | 'unassigned' };\n\nexport type AstSpan =\n | { readonly kind: 'prose'; readonly start: number; readonly end: number }\n | {\n readonly kind: 'island';\n readonly name: string;\n readonly start: number;\n readonly end: number;\n readonly bodyStart: number;\n readonly bodyEnd: number;\n readonly selfClosing: boolean;\n readonly attrs: Readonly<Record<string, string>>;\n readonly known: boolean;\n readonly props: Readonly<Record<string, AstJsonValue>>;\n readonly errors: readonly string[];\n }\n | {\n readonly kind: 'malformed';\n readonly reason: 'unterminated' | 'unclosed-body';\n readonly start: number;\n readonly end: number;\n };\n\nexport interface AstFenceComponent {\n readonly kind: 'component';\n readonly name: string;\n readonly props: Readonly<Record<string, string | boolean>>;\n readonly scope?: AstScope;\n readonly children: readonly (AstFenceComponent | AstFenceText)[];\n}\n\nexport interface AstFenceText {\n readonly kind: 'text';\n readonly text: string;\n}\n\nexport type AstNode =\n | {\n readonly kind: 'component';\n readonly name: string;\n readonly start: number;\n readonly end: number;\n readonly bodyStart: number;\n readonly bodyEnd: number;\n readonly props: Readonly<Record<string, string | boolean>>;\n readonly scope?: AstScope;\n readonly children: readonly AstNode[];\n }\n | {\n readonly kind: 'prose' | 'fallback';\n readonly start: number;\n readonly end: number;\n readonly scope?: AstScope;\n }\n | {\n readonly kind: 'display';\n readonly name: string;\n readonly start: number;\n readonly end: number;\n readonly scope?: AstScope;\n }\n | {\n readonly kind: 'fence';\n readonly form: 'tree' | 'journey';\n readonly start: number;\n readonly end: number;\n readonly title?: string;\n readonly scope?: AstScope;\n /** `null` when the block claims a form but yields no content. */\n readonly component: AstFenceComponent | null;\n };\n\nexport interface AstDiagnostic {\n readonly code: string;\n readonly message: string;\n readonly start: number;\n readonly end: number;\n}\n\nexport interface AstDocument {\n readonly version: 1;\n /** Offset of the first character after the frontmatter block (0 without one). */\n readonly bodyStart: number;\n readonly spans: readonly AstSpan[];\n readonly productSpec: {\n readonly nodes: readonly AstNode[];\n readonly diagnostics: readonly AstDiagnostic[];\n };\n}\n\nfunction sorted<T>(record: Readonly<Record<string, T>>): Record<string, T> {\n return Object.fromEntries(\n Object.keys(record)\n .sort()\n .map((key) => [key, record[key] as T])\n );\n}\n\nfunction scopeJson(scope: DeliveryScope | undefined): { scope?: AstScope } {\n if (!scope) {\n return {};\n }\n return {\n scope:\n scope.kind === 'increment'\n ? { kind: 'increment', increment: scope.increment }\n : { kind: scope.kind },\n };\n}\n\n/** Offset just past a leading `---` frontmatter block, or 0. */\nfunction frontmatterEnd(source: string): number {\n const firstEnd = source.indexOf('\\n');\n if (firstEnd === -1 || source.slice(0, firstEnd).trim() !== '---') {\n return 0;\n }\n let lineStart = firstEnd + 1;\n while (lineStart < source.length) {\n const lineEnd = source.indexOf('\\n', lineStart);\n const end = lineEnd === -1 ? source.length : lineEnd;\n if (source.slice(lineStart, end).trim() === '---') {\n return lineEnd === -1 ? source.length : lineEnd + 1;\n }\n lineStart = end + 1;\n }\n return 0;\n}\n\nfunction spanJson(span: DocSpan, offset: number): AstSpan {\n const start = offset + span.start;\n const end = offset + span.end;\n if (span.kind === 'prose') {\n return { kind: 'prose', start, end };\n }\n if (span.kind === 'malformed') {\n return { kind: 'malformed', reason: span.reason, start, end };\n }\n // Display vocabulary first: the scanner level is what terminal and web renderers resolve.\n const schema: PropSchema | undefined = Object.hasOwn(leoRegistry, span.name)\n ? leoRegistry[span.name]?.props\n : Object.hasOwn(productSpecSchemas, span.name)\n ? productSpecSchemas[span.name as keyof typeof productSpecSchemas]\n : undefined;\n const coerced = schema ? coerceProps(schema, span.attrs) : { props: {}, errors: [] };\n const bodyStart = offset + (span.bodyStart ?? span.end);\n return {\n kind: 'island',\n name: span.name,\n start,\n end,\n bodyStart,\n bodyEnd: bodyStart + span.body.length,\n selfClosing: span.selfClosing,\n attrs: sorted(span.attrs),\n known: schema !== undefined,\n props: sorted(coerced.props as Record<string, AstJsonValue>),\n errors: [...coerced.errors],\n };\n}\n\nfunction fenceComponentJson(node: ProductSpecComponent): AstFenceComponent {\n return {\n kind: 'component',\n name: node.name,\n props: sorted(node.props),\n ...scopeJson(node.scope),\n children: node.children.map((child) =>\n child.kind === 'component'\n ? fenceComponentJson(child)\n : { kind: 'text', text: child.source }\n ),\n };\n}\n\n/** Split a prose node around the closed `leo.tree` / `leo.journey` fences it contains. */\nfunction splitFences(source: string, start: number, end: number, scope?: DeliveryScope): AstNode[] {\n const nodes: AstNode[] = [];\n let proseStart = start;\n const firstBreak = source.indexOf('\\n', start);\n let lineStart =\n start === 0 || source[start - 1] === '\\n'\n ? start\n : firstBreak === -1\n ? end\n : firstBreak + 1;\n while (lineStart < end) {\n const fence = readFence(source, lineStart);\n if (fence) {\n const closeEnd = findFenceEnd(source, fence.contentStart, fence.marker, fence.length);\n if (closeEnd === -1 || closeEnd > end + 1) {\n break;\n }\n const closerEnd = source[closeEnd - 1] === '\\n' ? closeEnd - 1 : closeEnd;\n const token = fence.info.split(/\\s+/u)[0] ?? '';\n if (token === 'leo.tree' || token === 'leo.journey') {\n const closerStart = source.lastIndexOf('\\n', closerEnd - 1) + 1;\n const body = source.slice(fence.contentStart, closerStart).replace(/\\n$/u, '');\n const title = fence.info.slice(token.length).trim();\n const parsed =\n token === 'leo.tree'\n ? parseLeoTreeText(body, title ? { title } : {})\n : parseLeoJourneyText(body, title ? { title } : {});\n if (lineStart > proseStart) {\n nodes.push({\n kind: 'prose',\n start: proseStart,\n end: lineStart,\n ...scopeJson(scope),\n });\n }\n nodes.push({\n kind: 'fence',\n form: token === 'leo.tree' ? 'tree' : 'journey',\n start: lineStart,\n end: closerEnd,\n ...(title ? { title } : {}),\n ...scopeJson(scope),\n component: parsed ? fenceComponentJson(parsed) : null,\n });\n proseStart = closerEnd;\n }\n lineStart = closeEnd;\n continue;\n }\n const next = source.indexOf('\\n', lineStart);\n if (next === -1) {\n break;\n }\n lineStart = next + 1;\n }\n if (proseStart < end) {\n nodes.push({ kind: 'prose', start: proseStart, end, ...scopeJson(scope) });\n }\n return nodes;\n}\n\nfunction nodeJson(node: ProductSpecNode, source: string): AstNode[] {\n if (node.kind === 'component') {\n return [\n {\n kind: 'component',\n name: node.name,\n start: node.start,\n end: node.end,\n bodyStart: node.bodyStart,\n bodyEnd: node.bodyStart + node.body.length,\n props: sorted(node.props),\n ...scopeJson(node.scope),\n children: node.children.flatMap((child) => nodeJson(child, source)),\n },\n ];\n }\n if (node.kind === 'display') {\n return [\n {\n kind: 'display',\n name: node.island.name,\n start: node.start,\n end: node.end,\n ...scopeJson(node.scope),\n },\n ];\n }\n if (node.kind === 'prose') {\n return splitFences(source, node.start, node.end, node.scope);\n }\n return [{ kind: 'fallback', start: node.start, end: node.end, ...scopeJson(node.scope) }];\n}\n\n/**\n * Project a leo markup document (frontmatter, if any, is skipped) into the AST\n * JSON shape: the scanner's top-level spans and the product-spec node tree, with\n * `leo.tree` / `leo.journey` fences parsed into their component form. Offsets\n * are UTF-16 code-unit offsets into `source`.\n */\nexport function toAstJson(source: string): AstDocument {\n const bodyStart = frontmatterEnd(source);\n const body = source.slice(bodyStart);\n const parsed = parseProductSpec(body, { offset: bodyStart });\n return {\n version: 1,\n bodyStart,\n spans: scan(body).map((span) => spanJson(span, bodyStart)),\n productSpec: {\n nodes: parsed.nodes.flatMap((node) => nodeJson(node, source)),\n diagnostics: parsed.diagnostics.map((diagnostic) => ({\n code: diagnostic.code,\n message: diagnostic.message,\n start: diagnostic.start,\n end: diagnostic.end,\n })),\n },\n };\n}\n"]}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Authoring lints over `<leo.*>` source text.
3
+ *
4
+ * Three pure functions, each `(source) → Diagnostic[]`, that catch authoring
5
+ * errors the scanner deliberately does NOT throw on — it degrades or passes
6
+ * through so rendering never stalls, and a lint surfaces the mistake instead:
7
+ *
8
+ * - {@link lintCasing} — only lowercase `<leo.*>` is valid; a `<Leo.*>` or
9
+ * `<leo.SomethingCamel>` is an authoring error.
10
+ * - {@link lintUnknownTag} — a `<leo.X>` whose `X` is not in the registry is an
11
+ * authoring error (the scanner resolves only the allow-list).
12
+ * - {@link lintHelpScope} — in help-scope content a `<leo.*>` may ONLY be a
13
+ * `targets: 'both'` component; a web-only or terminal-only component cannot
14
+ * render in a help doc.
15
+ *
16
+ * These build on the SAME scanner + registry as the renderer, so a lint can
17
+ * never disagree with what actually resolves. The casing lint is the exception:
18
+ * it scans the raw source for the `<leo.` prefix because the scanner is
19
+ * lowercase-only (NAME_RE) and SKIPS a PascalCase opener entirely — so a
20
+ * casing error never reaches the scanner's island output and must be found in
21
+ * the raw text.
22
+ */
23
+ import type { LeoRegistry } from './types.js';
24
+ /** The lint rules these functions emit. */
25
+ export type AuthoringLintRule = 'casing' | 'unknown-tag' | 'help-scope';
26
+ /**
27
+ * One authoring diagnostic. `position` is the source offset of the offending
28
+ * `<leo.` opener (the `<`), so a caller can map it to a line/column.
29
+ */
30
+ export interface AuthoringDiagnostic {
31
+ readonly rule: AuthoringLintRule;
32
+ readonly message: string;
33
+ /** The authored tag name as it appeared (e.g. `Callout`, `tabs`). */
34
+ readonly name: string;
35
+ /** Source offset of the offending `<leo.` opener. */
36
+ readonly position: number;
37
+ }
38
+ /**
39
+ * casing: only lowercase `<leo.*>` is valid. Flags any opener whose
40
+ * name has an uppercase letter — `<Leo.Callout>` (the prefix itself is matched
41
+ * lowercase, but a `<leo.Callout>` / `<leo.statusBadge>` body is the target).
42
+ *
43
+ * Scans the RAW source rather than the scanned spans because the scanner is
44
+ * lowercase-only and never yields an island for a mixed-case name — so the only
45
+ * place a casing error is visible is the source text. Each `<leo.` whose name
46
+ * token contains an uppercase char is reported once.
47
+ */
48
+ export declare function lintCasing(source: string): AuthoringDiagnostic[];
49
+ /**
50
+ * unknown-tag: a `<leo.X>` whose lowercase name `X` is NOT in the registry is an
51
+ * authoring error. Runs over the scanner's islands (which are already
52
+ * lowercase-only), so a PascalCase tag is the casing lint's concern, not this
53
+ * one — they compose without double-reporting.
54
+ */
55
+ export declare function lintUnknownTag(source: string, registry?: LeoRegistry): AuthoringDiagnostic[];
56
+ /**
57
+ * help-scope: in a help doc, a `<leo.*>` may ONLY be a `targets: 'both'`
58
+ * component — terminal help and web help render the SAME source, so a web-only or
59
+ * terminal-only component would render on one surface and degrade on the other,
60
+ * which a help doc must never do. Flags any KNOWN island whose component does not
61
+ * target `both`.
62
+ *
63
+ * Unknown tags are left to {@link lintUnknownTag}; this lint only judges the
64
+ * target of a tag that actually resolves, so the two rules don't double-report
65
+ * the same offender.
66
+ */
67
+ export declare function lintHelpScope(source: string, registry?: LeoRegistry): AuthoringDiagnostic[];
68
+ /**
69
+ * Run the authoring lints over `source`. `helpScope` enables the help-scope rule
70
+ * — off by default, since the casing + unknown-tag rules apply to ALL
71
+ * docs but help-scope only to help content. The actual wiring of which files are
72
+ * help-scope is the documentation site's concern; this flag is the seam.
73
+ */
74
+ export interface AuthoringLintOptions {
75
+ readonly helpScope?: boolean;
76
+ readonly registry?: LeoRegistry;
77
+ }
78
+ export declare function lintAuthoring(source: string, options?: AuthoringLintOptions): AuthoringDiagnostic[];
79
+ //# sourceMappingURL=authoring-lints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authoring-lints.d.ts","sourceRoot":"","sources":["../src/authoring-lints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C,2CAA2C;AAC3C,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,aAAa,GAAG,YAAY,CAAC;AAExE;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAChC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,qEAAqE;IACrE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC7B;AAmBD;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,mBAAmB,EAAE,CA4BhE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC1B,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,WAAyB,GACpC,mBAAmB,EAAE,CAkBvB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CACzB,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,WAAyB,GACpC,mBAAmB,EAAE,CAuBvB;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACjC,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC;CACnC;AAED,wBAAgB,aAAa,CACzB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,oBAAyB,GACnC,mBAAmB,EAAE,CAWvB"}