@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,145 @@
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 { isKnown, leoRegistry, resolve } from './registry.js';
24
+ import { scan } from './scanner.js';
25
+ import { isIslandSpan } from './types.js';
26
+ /** The `<leo.` opener prefix (kept in sync with the scanner). */
27
+ const LEO_PREFIX = '<leo.';
28
+ /**
29
+ * A name-token after `<leo.` regardless of case: a leading letter, then
30
+ * letters/digits/hyphens. Used by the casing lint to FIND a tag the
31
+ * lowercase-only scanner would skip. The leading `[A-Za-z]` keeps it from
32
+ * matching `<leo. text` (a space) — that is the scanner's "treat as prose" case,
33
+ * not a casing error.
34
+ */
35
+ const ANY_CASE_NAME_RE = /^[A-Za-z][A-Za-z0-9-]*/;
36
+ /** True iff the name is entirely lowercase (the only valid authored form). */
37
+ function isLowercaseName(name) {
38
+ return name === name.toLowerCase();
39
+ }
40
+ /**
41
+ * casing: only lowercase `<leo.*>` is valid. Flags any opener whose
42
+ * name has an uppercase letter — `<Leo.Callout>` (the prefix itself is matched
43
+ * lowercase, but a `<leo.Callout>` / `<leo.statusBadge>` body is the target).
44
+ *
45
+ * Scans the RAW source rather than the scanned spans because the scanner is
46
+ * lowercase-only and never yields an island for a mixed-case name — so the only
47
+ * place a casing error is visible is the source text. Each `<leo.` whose name
48
+ * token contains an uppercase char is reported once.
49
+ */
50
+ export function lintCasing(source) {
51
+ const diagnostics = [];
52
+ let from = 0;
53
+ while (from < source.length) {
54
+ const at = source.indexOf(LEO_PREFIX, from);
55
+ if (at === -1) {
56
+ break;
57
+ }
58
+ const rest = source.slice(at + LEO_PREFIX.length);
59
+ const match = ANY_CASE_NAME_RE.exec(rest);
60
+ if (match) {
61
+ const name = match[0];
62
+ if (!isLowercaseName(name)) {
63
+ diagnostics.push({
64
+ rule: 'casing',
65
+ message: `<leo.${name}> uses non-lowercase casing; only lowercase <leo.*> tags are valid (e.g. <leo.${name.toLowerCase()}>)`,
66
+ name,
67
+ position: at,
68
+ });
69
+ }
70
+ }
71
+ // Advance past this prefix so a later opener is still found. (A mixed-case
72
+ // opener never advances the scanner, so we cannot lean on island offsets.)
73
+ from = at + LEO_PREFIX.length;
74
+ }
75
+ return diagnostics;
76
+ }
77
+ /**
78
+ * unknown-tag: a `<leo.X>` whose lowercase name `X` is NOT in the registry is an
79
+ * authoring error. Runs over the scanner's islands (which are already
80
+ * lowercase-only), so a PascalCase tag is the casing lint's concern, not this
81
+ * one — they compose without double-reporting.
82
+ */
83
+ export function lintUnknownTag(source, registry = leoRegistry) {
84
+ const diagnostics = [];
85
+ for (const span of scan(source)) {
86
+ if (!isIslandSpan(span)) {
87
+ continue;
88
+ }
89
+ if (!isKnown(span.name, registry)) {
90
+ diagnostics.push({
91
+ rule: 'unknown-tag',
92
+ message: `<leo.${span.name}> is not a known leo component`,
93
+ name: span.name,
94
+ position: span.start,
95
+ });
96
+ }
97
+ }
98
+ return diagnostics;
99
+ }
100
+ /**
101
+ * help-scope: in a help doc, a `<leo.*>` may ONLY be a `targets: 'both'`
102
+ * component — terminal help and web help render the SAME source, so a web-only or
103
+ * terminal-only component would render on one surface and degrade on the other,
104
+ * which a help doc must never do. Flags any KNOWN island whose component does not
105
+ * target `both`.
106
+ *
107
+ * Unknown tags are left to {@link lintUnknownTag}; this lint only judges the
108
+ * target of a tag that actually resolves, so the two rules don't double-report
109
+ * the same offender.
110
+ */
111
+ export function lintHelpScope(source, registry = leoRegistry) {
112
+ const diagnostics = [];
113
+ for (const span of scan(source)) {
114
+ if (!isIslandSpan(span)) {
115
+ continue;
116
+ }
117
+ const component = resolve(span.name, registry);
118
+ if (component === undefined) {
119
+ // Unknown tag — lintUnknownTag owns this; not a help-scope error.
120
+ continue;
121
+ }
122
+ if (component.targets !== 'both') {
123
+ diagnostics.push({
124
+ rule: 'help-scope',
125
+ message: `<leo.${span.name}> targets ${component.targets}; help docs may only use targets:'both' components (terminal + web)`,
126
+ name: span.name,
127
+ position: span.start,
128
+ });
129
+ }
130
+ }
131
+ return diagnostics;
132
+ }
133
+ export function lintAuthoring(source, options = {}) {
134
+ const registry = options.registry ?? leoRegistry;
135
+ const diagnostics = [
136
+ ...lintCasing(source),
137
+ ...lintUnknownTag(source, registry),
138
+ ];
139
+ if (options.helpScope) {
140
+ diagnostics.push(...lintHelpScope(source, registry));
141
+ }
142
+ // Stable source order so a caller reports diagnostics top-to-bottom.
143
+ return diagnostics.sort((a, b) => a.position - b.position);
144
+ }
145
+ //# sourceMappingURL=authoring-lints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authoring-lints.js","sourceRoot":"","sources":["../src/authoring-lints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAkB1C,iEAAiE;AACjE,MAAM,UAAU,GAAG,OAAO,CAAC;AAE3B;;;;;;GAMG;AACH,MAAM,gBAAgB,GAAG,wBAAwB,CAAC;AAElD,8EAA8E;AAC9E,SAAS,eAAe,CAAC,IAAY;IACjC,OAAO,IAAI,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC;AACvC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc;IACrC,MAAM,WAAW,GAA0B,EAAE,CAAC;IAC9C,IAAI,IAAI,GAAG,CAAC,CAAC;IAEb,OAAO,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QAC1B,MAAM,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAC5C,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;YACZ,MAAM;QACV,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;QAClD,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,KAAK,EAAE,CAAC;YACR,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACtB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzB,WAAW,CAAC,IAAI,CAAC;oBACb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AAC,CAAC;QAC/C,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC1B,kEAAkE;YAClE,SAAS;QACb,CAAC;QACD,IAAI,SAAS,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC;YAC/B,WAAW,CAAC,IAAI,CAAC;gBACb,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,QAAQ,IAAI,CAAC,IAAI,aAAa,SAAS,CAAC,OAAO,qEAAqE;gBAC7H,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,QAAQ,EAAE,IAAI,CAAC,KAAK;aACvB,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAED,OAAO,WAAW,CAAC;AACvB,CAAC;AAaD,MAAM,UAAU,aAAa,CACzB,MAAc,EACd,OAAO,GAAyB,EAAE;IAElC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,WAAW,CAAC;IACjD,MAAM,WAAW,GAA0B;QACvC,GAAG,UAAU,CAAC,MAAM,CAAC;QACrB,GAAG,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC;KACtC,CAAC;IACF,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACpB,WAAW,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IACzD,CAAC;IACD,qEAAqE;IACrE,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["/**\n * Authoring lints over `<leo.*>` source text.\n *\n * Three pure functions, each `(source) → Diagnostic[]`, that catch authoring\n * errors the scanner deliberately does NOT throw on — it degrades or passes\n * through so rendering never stalls, and a lint surfaces the mistake instead:\n *\n * - {@link lintCasing} — only lowercase `<leo.*>` is valid; a `<Leo.*>` or\n * `<leo.SomethingCamel>` is an authoring error.\n * - {@link lintUnknownTag} — a `<leo.X>` whose `X` is not in the registry is an\n * authoring error (the scanner resolves only the allow-list).\n * - {@link lintHelpScope} — in help-scope content a `<leo.*>` may ONLY be a\n * `targets: 'both'` component; a web-only or terminal-only component cannot\n * render in a help doc.\n *\n * These build on the SAME scanner + registry as the renderer, so a lint can\n * never disagree with what actually resolves. The casing lint is the exception:\n * it scans the raw source for the `<leo.` prefix because the scanner is\n * lowercase-only (NAME_RE) and SKIPS a PascalCase opener entirely — so a\n * casing error never reaches the scanner's island output and must be found in\n * the raw text.\n */\n\nimport { isKnown, leoRegistry, resolve } from './registry.js';\nimport { scan } from './scanner.js';\nimport type { LeoRegistry } from './types.js';\nimport { isIslandSpan } from './types.js';\n\n/** The lint rules these functions emit. */\nexport type AuthoringLintRule = 'casing' | 'unknown-tag' | 'help-scope';\n\n/**\n * One authoring diagnostic. `position` is the source offset of the offending\n * `<leo.` opener (the `<`), so a caller can map it to a line/column.\n */\nexport interface AuthoringDiagnostic {\n readonly rule: AuthoringLintRule;\n readonly message: string;\n /** The authored tag name as it appeared (e.g. `Callout`, `tabs`). */\n readonly name: string;\n /** Source offset of the offending `<leo.` opener. */\n readonly position: number;\n}\n\n/** The `<leo.` opener prefix (kept in sync with the scanner). */\nconst LEO_PREFIX = '<leo.';\n\n/**\n * A name-token after `<leo.` regardless of case: a leading letter, then\n * letters/digits/hyphens. Used by the casing lint to FIND a tag the\n * lowercase-only scanner would skip. The leading `[A-Za-z]` keeps it from\n * matching `<leo. text` (a space) — that is the scanner's \"treat as prose\" case,\n * not a casing error.\n */\nconst ANY_CASE_NAME_RE = /^[A-Za-z][A-Za-z0-9-]*/;\n\n/** True iff the name is entirely lowercase (the only valid authored form). */\nfunction isLowercaseName(name: string): boolean {\n return name === name.toLowerCase();\n}\n\n/**\n * casing: only lowercase `<leo.*>` is valid. Flags any opener whose\n * name has an uppercase letter — `<Leo.Callout>` (the prefix itself is matched\n * lowercase, but a `<leo.Callout>` / `<leo.statusBadge>` body is the target).\n *\n * Scans the RAW source rather than the scanned spans because the scanner is\n * lowercase-only and never yields an island for a mixed-case name — so the only\n * place a casing error is visible is the source text. Each `<leo.` whose name\n * token contains an uppercase char is reported once.\n */\nexport function lintCasing(source: string): AuthoringDiagnostic[] {\n const diagnostics: AuthoringDiagnostic[] = [];\n let from = 0;\n\n while (from < source.length) {\n const at = source.indexOf(LEO_PREFIX, from);\n if (at === -1) {\n break;\n }\n const rest = source.slice(at + LEO_PREFIX.length);\n const match = ANY_CASE_NAME_RE.exec(rest);\n if (match) {\n const name = match[0];\n if (!isLowercaseName(name)) {\n diagnostics.push({\n rule: 'casing',\n message: `<leo.${name}> uses non-lowercase casing; only lowercase <leo.*> tags are valid (e.g. <leo.${name.toLowerCase()}>)`,\n name,\n position: at,\n });\n }\n }\n // Advance past this prefix so a later opener is still found. (A mixed-case\n // opener never advances the scanner, so we cannot lean on island offsets.)\n from = at + LEO_PREFIX.length;\n }\n\n return diagnostics;\n}\n\n/**\n * unknown-tag: a `<leo.X>` whose lowercase name `X` is NOT in the registry is an\n * authoring error. Runs over the scanner's islands (which are already\n * lowercase-only), so a PascalCase tag is the casing lint's concern, not this\n * one — they compose without double-reporting.\n */\nexport function lintUnknownTag(\n source: string,\n registry: LeoRegistry = leoRegistry\n): AuthoringDiagnostic[] {\n const diagnostics: AuthoringDiagnostic[] = [];\n\n for (const span of scan(source)) {\n if (!isIslandSpan(span)) {\n continue;\n }\n if (!isKnown(span.name, registry)) {\n diagnostics.push({\n rule: 'unknown-tag',\n message: `<leo.${span.name}> is not a known leo component`,\n name: span.name,\n position: span.start,\n });\n }\n }\n\n return diagnostics;\n}\n\n/**\n * help-scope: in a help doc, a `<leo.*>` may ONLY be a `targets: 'both'`\n * component — terminal help and web help render the SAME source, so a web-only or\n * terminal-only component would render on one surface and degrade on the other,\n * which a help doc must never do. Flags any KNOWN island whose component does not\n * target `both`.\n *\n * Unknown tags are left to {@link lintUnknownTag}; this lint only judges the\n * target of a tag that actually resolves, so the two rules don't double-report\n * the same offender.\n */\nexport function lintHelpScope(\n source: string,\n registry: LeoRegistry = leoRegistry\n): AuthoringDiagnostic[] {\n const diagnostics: AuthoringDiagnostic[] = [];\n\n for (const span of scan(source)) {\n if (!isIslandSpan(span)) {\n continue;\n }\n const component = resolve(span.name, registry);\n if (component === undefined) {\n // Unknown tag — lintUnknownTag owns this; not a help-scope error.\n continue;\n }\n if (component.targets !== 'both') {\n diagnostics.push({\n rule: 'help-scope',\n message: `<leo.${span.name}> targets ${component.targets}; help docs may only use targets:'both' components (terminal + web)`,\n name: span.name,\n position: span.start,\n });\n }\n }\n\n return diagnostics;\n}\n\n/**\n * Run the authoring lints over `source`. `helpScope` enables the help-scope rule\n * — off by default, since the casing + unknown-tag rules apply to ALL\n * docs but help-scope only to help content. The actual wiring of which files are\n * help-scope is the documentation site's concern; this flag is the seam.\n */\nexport interface AuthoringLintOptions {\n readonly helpScope?: boolean;\n readonly registry?: LeoRegistry;\n}\n\nexport function lintAuthoring(\n source: string,\n options: AuthoringLintOptions = {}\n): AuthoringDiagnostic[] {\n const registry = options.registry ?? leoRegistry;\n const diagnostics: AuthoringDiagnostic[] = [\n ...lintCasing(source),\n ...lintUnknownTag(source, registry),\n ];\n if (options.helpScope) {\n diagnostics.push(...lintHelpScope(source, registry));\n }\n // Stable source order so a caller reports diagnostics top-to-bottom.\n return diagnostics.sort((a, b) => a.position - b.position);\n}\n"]}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Component-body block-vs-inline classification.
3
+ *
4
+ * A `<leo.*>` island's body may contain prose, block elements, and nested
5
+ * islands. Whether the body renders INLINE (a single run of inline content) or
6
+ * as BLOCKS is decided by the body's OWN content — NOT by the component:
7
+ *
8
+ * - trimmed body is a single line with no block constructs → inline
9
+ * - blank-line-separated blocks, lists, headings, fenced code, blockquotes,
10
+ * or nested `<leo.*>` islands → blocks
11
+ *
12
+ * CRITICAL PARITY INVARIANT: both surfaces apply THIS SAME function. The terminal
13
+ * ANSI markdown renderer and the web react-markdown pipeline each receive the
14
+ * same extracted body and the same classification, so a callout body that is a
15
+ * bulleted list is a list on both. A divergent re-implementation on one surface
16
+ * would silently break body parity — so the rule lives here, once, in core.
17
+ *
18
+ * This module performs CLASSIFICATION only (a pure, surface-agnostic predicate).
19
+ * Extraction of the balanced body is the scanner's job; recursing prose →
20
+ * markdown and nested islands → scanner is the renderer's job. Keeping this a
21
+ * pure classifier is what lets both surfaces share it verbatim.
22
+ */
23
+ import type { DocSpan, IslandSpan, LeoComponent, LeoRegistry } from './types.js';
24
+ export type BodyMode = 'inline' | 'block';
25
+ /**
26
+ * Classify an island body as `inline` or `block`. Surface-agnostic: the same
27
+ * result is used by the ANSI and the web renderer.
28
+ */
29
+ export declare function classifyBody(body: string): BodyMode;
30
+ /** Convenience predicate. */
31
+ export declare function isInlineBody(body: string): boolean;
32
+ /** An inline island already scanned and assigned an opaque Markdown token. */
33
+ export interface InlineIslandRecord {
34
+ readonly id: string;
35
+ readonly placeholder: string;
36
+ readonly island: IslandSpan;
37
+ /** Canonical entry resolved during composition; rehydration never resolves again. */
38
+ readonly component: LeoComponent;
39
+ }
40
+ /** A block island paired with its canonical entry from the same scanner pass. */
41
+ export interface BlockIslandRecord {
42
+ readonly kind: 'block-island';
43
+ readonly island: IslandSpan;
44
+ readonly component: LeoComponent;
45
+ }
46
+ /** A contiguous Markdown run between block islands. */
47
+ export interface MarkdownCompositionSpan {
48
+ readonly kind: 'markdown';
49
+ readonly content: string;
50
+ readonly start: number;
51
+ readonly end: number;
52
+ readonly inlineIslands: readonly InlineIslandRecord[];
53
+ }
54
+ export type ComposedSpan = MarkdownCompositionSpan | BlockIslandRecord;
55
+ export interface IslandDiagnostic {
56
+ readonly code: 'malformed-island' | 'unknown-island';
57
+ readonly message: string;
58
+ readonly start: number;
59
+ readonly end: number;
60
+ readonly name?: string;
61
+ }
62
+ export interface MarkdownComposition {
63
+ readonly spans: readonly ComposedSpan[];
64
+ readonly diagnostics: readonly IslandDiagnostic[];
65
+ }
66
+ /**
67
+ * Compose one scanner pass into Markdown segments and block islands.
68
+ *
69
+ * Known inline islands stay inside their surrounding Markdown segment as opaque
70
+ * tokens. Known block islands remain top-level spans. Malformed and unknown
71
+ * source is preserved as escaped Markdown text with a structured diagnostic.
72
+ */
73
+ export declare function composeMarkdownIslands(source: string, registry: LeoRegistry, spans?: readonly DocSpan[]): MarkdownComposition;
74
+ //# sourceMappingURL=block-inline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block-inline.d.ts","sourceRoot":"","sources":["../src/block-inline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGjF,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;AAiB1C;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAmCnD;AAED,6BAA6B;AAC7B,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAID,8EAA8E;AAC9E,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,qFAAqF;IACrF,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;CACpC;AAED,iFAAiF;AACjF,MAAM,WAAW,iBAAiB;IAC9B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;CACpC;AAED,uDAAuD;AACvD,MAAM,WAAW,uBAAuB;IACpC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,aAAa,EAAE,SAAS,kBAAkB,EAAE,CAAC;CACzD;AAED,MAAM,MAAM,YAAY,GAAG,uBAAuB,GAAG,iBAAiB,CAAC;AAEvE,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,IAAI,EAAE,kBAAkB,GAAG,gBAAgB,CAAC;IACrD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,mBAAmB;IAChC,QAAQ,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;IACxC,QAAQ,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,CAAC;CACrD;AAWD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAClC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,WAAW,EACrB,KAAK,GAAE,SAAS,OAAO,EAAiB,GACzC,mBAAmB,CA6FrB"}
@@ -0,0 +1,171 @@
1
+ /**
2
+ * Component-body block-vs-inline classification.
3
+ *
4
+ * A `<leo.*>` island's body may contain prose, block elements, and nested
5
+ * islands. Whether the body renders INLINE (a single run of inline content) or
6
+ * as BLOCKS is decided by the body's OWN content — NOT by the component:
7
+ *
8
+ * - trimmed body is a single line with no block constructs → inline
9
+ * - blank-line-separated blocks, lists, headings, fenced code, blockquotes,
10
+ * or nested `<leo.*>` islands → blocks
11
+ *
12
+ * CRITICAL PARITY INVARIANT: both surfaces apply THIS SAME function. The terminal
13
+ * ANSI markdown renderer and the web react-markdown pipeline each receive the
14
+ * same extracted body and the same classification, so a callout body that is a
15
+ * bulleted list is a list on both. A divergent re-implementation on one surface
16
+ * would silently break body parity — so the rule lives here, once, in core.
17
+ *
18
+ * This module performs CLASSIFICATION only (a pure, surface-agnostic predicate).
19
+ * Extraction of the balanced body is the scanner's job; recursing prose →
20
+ * markdown and nested islands → scanner is the renderer's job. Keeping this a
21
+ * pure classifier is what lets both surfaces share it verbatim.
22
+ */
23
+ import { scan } from './scanner.js';
24
+ import { isIslandSpan, isMalformedSpan, isProseSpan } from './types.js';
25
+ /** A fenced-code opener: ``` or ~~~ (optionally indented up to 3 spaces). */
26
+ const FENCE_RE = /^ {0,3}(```|~~~)/;
27
+ /** An ATX heading: up to 3 leading spaces then 1-6 `#` then a space/end. */
28
+ const HEADING_RE = /^ {0,3}#{1,6}(\s|$)/;
29
+ /** A bullet list item: `-`, `*`, or `+` followed by a space. */
30
+ const BULLET_RE = /^ {0,3}[-*+]\s/;
31
+ /** An ordered list item: digits then `.` or `)` then a space. */
32
+ const ORDERED_RE = /^ {0,3}\d+[.)]\s/;
33
+ /** A blockquote line. */
34
+ const BLOCKQUOTE_RE = /^ {0,3}>/;
35
+ /** A GFM table delimiter row, with optional leading/trailing pipes. */
36
+ const TABLE_DELIMITER_RE = /^ {0,3}\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)+\|?\s*$/;
37
+ /** A nested leo island opener (lowercase-only, matching the scanner). */
38
+ const ISLAND_RE = /<leo\.[a-z]/;
39
+ /**
40
+ * Classify an island body as `inline` or `block`. Surface-agnostic: the same
41
+ * result is used by the ANSI and the web renderer.
42
+ */
43
+ export function classifyBody(body) {
44
+ const trimmed = body.trim();
45
+ if (trimmed === '') {
46
+ // An empty body has no block constructs — inline (renders nothing).
47
+ return 'inline';
48
+ }
49
+ // A nested island anywhere → the body is a block (it composes sub-trees).
50
+ if (ISLAND_RE.test(trimmed)) {
51
+ return 'block';
52
+ }
53
+ const lines = trimmed.split('\n');
54
+ // Multiple blocks separated by a blank line → block.
55
+ if (/\n[ \t]*\n/.test(trimmed)) {
56
+ return 'block';
57
+ }
58
+ // Any line that is itself a block construct → block.
59
+ for (const line of lines) {
60
+ if (FENCE_RE.test(line) ||
61
+ HEADING_RE.test(line) ||
62
+ BULLET_RE.test(line) ||
63
+ ORDERED_RE.test(line) ||
64
+ BLOCKQUOTE_RE.test(line) ||
65
+ TABLE_DELIMITER_RE.test(line)) {
66
+ return 'block';
67
+ }
68
+ }
69
+ // A single line (or soft-wrapped lines with no block constructs) → inline.
70
+ return 'inline';
71
+ }
72
+ /** Convenience predicate. */
73
+ export function isInlineBody(body) {
74
+ return classifyBody(body) === 'inline';
75
+ }
76
+ /** Private-use delimiters survive Markdown parsing without creating syntax. */
77
+ const PLACEHOLDER_OPEN = '\u{e000}';
78
+ const PLACEHOLDER_CLOSE = '\u{e001}';
79
+ /** Escape a Leo source slice so rehype-raw can only render it as visible text. */
80
+ function escapeLeoSource(source) {
81
+ return source.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;');
82
+ }
83
+ /**
84
+ * Compose one scanner pass into Markdown segments and block islands.
85
+ *
86
+ * Known inline islands stay inside their surrounding Markdown segment as opaque
87
+ * tokens. Known block islands remain top-level spans. Malformed and unknown
88
+ * source is preserved as escaped Markdown text with a structured diagnostic.
89
+ */
90
+ export function composeMarkdownIslands(source, registry, spans = scan(source)) {
91
+ const composed = [];
92
+ const diagnostics = [];
93
+ let markdown = '';
94
+ let markdownStart;
95
+ let markdownEnd = 0;
96
+ let inlineIslands = [];
97
+ let placeholderNonce = 0;
98
+ const appendMarkdown = (text, start, end) => {
99
+ if (markdownStart === undefined) {
100
+ markdownStart = start;
101
+ }
102
+ markdown += text;
103
+ markdownEnd = end;
104
+ };
105
+ const flushMarkdown = () => {
106
+ if (markdownStart === undefined) {
107
+ return;
108
+ }
109
+ composed.push({
110
+ kind: 'markdown',
111
+ content: markdown,
112
+ start: markdownStart,
113
+ end: markdownEnd,
114
+ inlineIslands,
115
+ });
116
+ markdown = '';
117
+ markdownStart = undefined;
118
+ markdownEnd = 0;
119
+ inlineIslands = [];
120
+ };
121
+ const nextPlaceholder = () => {
122
+ let id;
123
+ let placeholder;
124
+ do {
125
+ id = `leo-inline-${placeholderNonce++}`;
126
+ placeholder = `${PLACEHOLDER_OPEN}${id}${PLACEHOLDER_CLOSE}`;
127
+ } while (source.includes(placeholder));
128
+ return { id, placeholder };
129
+ };
130
+ for (const span of spans) {
131
+ if (isProseSpan(span)) {
132
+ appendMarkdown(span.text, span.start, span.end);
133
+ continue;
134
+ }
135
+ if (isMalformedSpan(span)) {
136
+ appendMarkdown(escapeLeoSource(span.text), span.start, span.end);
137
+ diagnostics.push({
138
+ code: 'malformed-island',
139
+ message: `Malformed Leo island at source offset ${span.start}`,
140
+ start: span.start,
141
+ end: span.end,
142
+ });
143
+ continue;
144
+ }
145
+ if (isIslandSpan(span)) {
146
+ const component = Object.hasOwn(registry, span.name) ? registry[span.name] : undefined;
147
+ if (!component) {
148
+ appendMarkdown(escapeLeoSource(source.slice(span.start, span.end)), span.start, span.end);
149
+ diagnostics.push({
150
+ code: 'unknown-island',
151
+ message: `Unknown Leo island <leo.${span.name}> at source offset ${span.start}`,
152
+ name: span.name,
153
+ start: span.start,
154
+ end: span.end,
155
+ });
156
+ continue;
157
+ }
158
+ if (component.flow === 'inline') {
159
+ const token = nextPlaceholder();
160
+ appendMarkdown(token.placeholder, span.start, span.end);
161
+ inlineIslands.push({ ...token, island: span, component });
162
+ continue;
163
+ }
164
+ flushMarkdown();
165
+ composed.push({ kind: 'block-island', island: span, component });
166
+ }
167
+ }
168
+ flushMarkdown();
169
+ return { spans: composed, diagnostics };
170
+ }
171
+ //# sourceMappingURL=block-inline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block-inline.js","sourceRoot":"","sources":["../src/block-inline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,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E,WAAW,EAAE,CAAC;AAC5C,CAAC","sourcesContent":["/**\n * Component-body block-vs-inline classification.\n *\n * A `<leo.*>` island's body may contain prose, block elements, and nested\n * islands. Whether the body renders INLINE (a single run of inline content) or\n * as BLOCKS is decided by the body's OWN content — NOT by the component:\n *\n * - trimmed body is a single line with no block constructs → inline\n * - blank-line-separated blocks, lists, headings, fenced code, blockquotes,\n * or nested `<leo.*>` islands → blocks\n *\n * CRITICAL PARITY INVARIANT: both surfaces apply THIS SAME function. The terminal\n * ANSI markdown renderer and the web react-markdown pipeline each receive the\n * same extracted body and the same classification, so a callout body that is a\n * bulleted list is a list on both. A divergent re-implementation on one surface\n * would silently break body parity — so the rule lives here, once, in core.\n *\n * This module performs CLASSIFICATION only (a pure, surface-agnostic predicate).\n * Extraction of the balanced body is the scanner's job; recursing prose →\n * markdown and nested islands → scanner is the renderer's job. Keeping this a\n * pure classifier is what lets both surfaces share it verbatim.\n */\n\nimport { scan } from './scanner.js';\nimport type { DocSpan, IslandSpan, LeoComponent, LeoRegistry } from './types.js';\nimport { isIslandSpan, isMalformedSpan, isProseSpan } from './types.js';\n\nexport type BodyMode = 'inline' | 'block';\n\n/** A fenced-code opener: ``` or ~~~ (optionally indented up to 3 spaces). */\nconst FENCE_RE = /^ {0,3}(```|~~~)/;\n/** An ATX heading: up to 3 leading spaces then 1-6 `#` then a space/end. */\nconst HEADING_RE = /^ {0,3}#{1,6}(\\s|$)/;\n/** A bullet list item: `-`, `*`, or `+` followed by a space. */\nconst BULLET_RE = /^ {0,3}[-*+]\\s/;\n/** An ordered list item: digits then `.` or `)` then a space. */\nconst ORDERED_RE = /^ {0,3}\\d+[.)]\\s/;\n/** A blockquote line. */\nconst BLOCKQUOTE_RE = /^ {0,3}>/;\n/** A GFM table delimiter row, with optional leading/trailing pipes. */\nconst TABLE_DELIMITER_RE = /^ {0,3}\\|?\\s*:?-{3,}:?\\s*(?:\\|\\s*:?-{3,}:?\\s*)+\\|?\\s*$/;\n/** A nested leo island opener (lowercase-only, matching the scanner). */\nconst ISLAND_RE = /<leo\\.[a-z]/;\n\n/**\n * Classify an island body as `inline` or `block`. Surface-agnostic: the same\n * result is used by the ANSI and the web renderer.\n */\nexport function classifyBody(body: string): BodyMode {\n const trimmed = body.trim();\n if (trimmed === '') {\n // An empty body has no block constructs — inline (renders nothing).\n return 'inline';\n }\n\n // A nested island anywhere → the body is a block (it composes sub-trees).\n if (ISLAND_RE.test(trimmed)) {\n return 'block';\n }\n\n const lines = trimmed.split('\\n');\n\n // Multiple blocks separated by a blank line → block.\n if (/\\n[ \\t]*\\n/.test(trimmed)) {\n return 'block';\n }\n\n // Any line that is itself a block construct → block.\n for (const line of lines) {\n if (\n FENCE_RE.test(line) ||\n HEADING_RE.test(line) ||\n BULLET_RE.test(line) ||\n ORDERED_RE.test(line) ||\n BLOCKQUOTE_RE.test(line) ||\n TABLE_DELIMITER_RE.test(line)\n ) {\n return 'block';\n }\n }\n\n // A single line (or soft-wrapped lines with no block constructs) → inline.\n return 'inline';\n}\n\n/** Convenience predicate. */\nexport function isInlineBody(body: string): boolean {\n return classifyBody(body) === 'inline';\n}\n\n// ── Markdown-aware island composition ───────────────────────────────────────\n\n/** An inline island already scanned and assigned an opaque Markdown token. */\nexport interface InlineIslandRecord {\n readonly id: string;\n readonly placeholder: string;\n readonly island: IslandSpan;\n /** Canonical entry resolved during composition; rehydration never resolves again. */\n readonly component: LeoComponent;\n}\n\n/** A block island paired with its canonical entry from the same scanner pass. */\nexport interface BlockIslandRecord {\n readonly kind: 'block-island';\n readonly island: IslandSpan;\n readonly component: LeoComponent;\n}\n\n/** A contiguous Markdown run between block islands. */\nexport interface MarkdownCompositionSpan {\n readonly kind: 'markdown';\n readonly content: string;\n readonly start: number;\n readonly end: number;\n readonly inlineIslands: readonly InlineIslandRecord[];\n}\n\nexport type ComposedSpan = MarkdownCompositionSpan | BlockIslandRecord;\n\nexport interface IslandDiagnostic {\n readonly code: 'malformed-island' | 'unknown-island';\n readonly message: string;\n readonly start: number;\n readonly end: number;\n readonly name?: string;\n}\n\nexport interface MarkdownComposition {\n readonly spans: readonly ComposedSpan[];\n readonly diagnostics: readonly IslandDiagnostic[];\n}\n\n/** Private-use delimiters survive Markdown parsing without creating syntax. */\nconst PLACEHOLDER_OPEN = '\\u{e000}';\nconst PLACEHOLDER_CLOSE = '\\u{e001}';\n\n/** Escape a Leo source slice so rehype-raw can only render it as visible text. */\nfunction escapeLeoSource(source: string): string {\n return source.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;');\n}\n\n/**\n * Compose one scanner pass into Markdown segments and block islands.\n *\n * Known inline islands stay inside their surrounding Markdown segment as opaque\n * tokens. Known block islands remain top-level spans. Malformed and unknown\n * source is preserved as escaped Markdown text with a structured diagnostic.\n */\nexport function composeMarkdownIslands(\n source: string,\n registry: LeoRegistry,\n spans: readonly DocSpan[] = scan(source)\n): MarkdownComposition {\n const composed: ComposedSpan[] = [];\n const diagnostics: IslandDiagnostic[] = [];\n let markdown = '';\n let markdownStart: number | undefined;\n let markdownEnd = 0;\n let inlineIslands: InlineIslandRecord[] = [];\n let placeholderNonce = 0;\n\n const appendMarkdown = (text: string, start: number, end: number): void => {\n if (markdownStart === undefined) {\n markdownStart = start;\n }\n markdown += text;\n markdownEnd = end;\n };\n\n const flushMarkdown = (): void => {\n if (markdownStart === undefined) {\n return;\n }\n composed.push({\n kind: 'markdown',\n content: markdown,\n start: markdownStart,\n end: markdownEnd,\n inlineIslands,\n });\n markdown = '';\n markdownStart = undefined;\n markdownEnd = 0;\n inlineIslands = [];\n };\n\n const nextPlaceholder = (): { id: string; placeholder: string } => {\n let id: string;\n let placeholder: string;\n do {\n id = `leo-inline-${placeholderNonce++}`;\n placeholder = `${PLACEHOLDER_OPEN}${id}${PLACEHOLDER_CLOSE}`;\n } while (source.includes(placeholder));\n return { id, placeholder };\n };\n\n for (const span of spans) {\n if (isProseSpan(span)) {\n appendMarkdown(span.text, span.start, span.end);\n continue;\n }\n\n if (isMalformedSpan(span)) {\n appendMarkdown(escapeLeoSource(span.text), span.start, span.end);\n diagnostics.push({\n code: 'malformed-island',\n message: `Malformed Leo island at source offset ${span.start}`,\n start: span.start,\n end: span.end,\n });\n continue;\n }\n\n if (isIslandSpan(span)) {\n const component = Object.hasOwn(registry, span.name) ? registry[span.name] : undefined;\n if (!component) {\n appendMarkdown(\n escapeLeoSource(source.slice(span.start, span.end)),\n span.start,\n span.end\n );\n diagnostics.push({\n code: 'unknown-island',\n message: `Unknown Leo island <leo.${span.name}> at source offset ${span.start}`,\n name: span.name,\n start: span.start,\n end: span.end,\n });\n continue;\n }\n\n if (component.flow === 'inline') {\n const token = nextPlaceholder();\n appendMarkdown(token.placeholder, span.start, span.end);\n inlineIslands.push({ ...token, island: span, component });\n continue;\n }\n\n flushMarkdown();\n composed.push({ kind: 'block-island', island: span, component });\n }\n }\n\n flushMarkdown();\n return { spans: composed, diagnostics };\n}\n"]}
@@ -0,0 +1,14 @@
1
+ /** CommonMark fenced-code delimiters, shared by the scanner and the fence-form projection. */
2
+ export interface FenceOpen {
3
+ readonly marker: '`' | '~';
4
+ readonly length: number;
5
+ readonly contentStart: number;
6
+ /** The trimmed info string after the opening run. */
7
+ readonly info: string;
8
+ }
9
+ /** Read a fenced-code opener at a physical line start (up to 3 spaces indented). */
10
+ export declare function readFence(source: string, lineStart: number): FenceOpen | null;
11
+ /** Find the byte immediately after a matching fenced-code closer. */
12
+ export declare function findFenceEnd(source: string, from: number, marker: '`' | '~', length: number): number;
13
+ export declare function countRun(source: string, from: number, char: '`' | '~'): number;
14
+ //# sourceMappingURL=fence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fence.d.ts","sourceRoot":"","sources":["../src/fence.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAE9F,MAAM,WAAW,SAAS;IACtB,QAAQ,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,qDAAqD;IACrD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACzB;AAED,oFAAoF;AACpF,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAoB7E;AAED,qEAAqE;AACrE,wBAAgB,YAAY,CACxB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,GAAG,GAAG,GAAG,EACjB,MAAM,EAAE,MAAM,GACf,MAAM,CAsBR;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,GAAG,GAAG,MAAM,CAM9E"}
package/dist/fence.js ADDED
@@ -0,0 +1,55 @@
1
+ /** CommonMark fenced-code delimiters, shared by the scanner and the fence-form projection. */
2
+ /** Read a fenced-code opener at a physical line start (up to 3 spaces indented). */
3
+ export function readFence(source, lineStart) {
4
+ let markerStart = lineStart;
5
+ while (markerStart < lineStart + 3 && source[markerStart] === ' ') {
6
+ markerStart++;
7
+ }
8
+ const marker = source[markerStart];
9
+ if (marker !== '`' && marker !== '~') {
10
+ return null;
11
+ }
12
+ const length = countRun(source, markerStart, marker);
13
+ if (length < 3) {
14
+ return null;
15
+ }
16
+ const lineEnd = source.indexOf('\n', markerStart + length);
17
+ return {
18
+ marker,
19
+ length,
20
+ contentStart: lineEnd === -1 ? source.length : lineEnd + 1,
21
+ info: source.slice(markerStart + length, lineEnd === -1 ? source.length : lineEnd).trim(),
22
+ };
23
+ }
24
+ /** Find the byte immediately after a matching fenced-code closer. */
25
+ export function findFenceEnd(source, from, marker, length) {
26
+ let lineStart = from;
27
+ while (lineStart < source.length) {
28
+ let markerStart = lineStart;
29
+ while (markerStart < lineStart + 3 && source[markerStart] === ' ') {
30
+ markerStart++;
31
+ }
32
+ const runLength = countRun(source, markerStart, marker);
33
+ if (runLength >= length) {
34
+ const lineEnd = source.indexOf('\n', markerStart + runLength);
35
+ const remainderEnd = lineEnd === -1 ? source.length : lineEnd;
36
+ if (source.slice(markerStart + runLength, remainderEnd).trim() === '') {
37
+ return lineEnd === -1 ? source.length : lineEnd + 1;
38
+ }
39
+ }
40
+ const nextLine = source.indexOf('\n', lineStart);
41
+ if (nextLine === -1) {
42
+ return -1;
43
+ }
44
+ lineStart = nextLine + 1;
45
+ }
46
+ return -1;
47
+ }
48
+ export function countRun(source, from, char) {
49
+ let end = from;
50
+ while (source[end] === char) {
51
+ end++;
52
+ }
53
+ return end - from;
54
+ }
55
+ //# sourceMappingURL=fence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fence.js","sourceRoot":"","sources":["../src/fence.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAU9F,oFAAoF;AACpF,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,SAAiB;IACvD,IAAI,WAAW,GAAG,SAAS,CAAC;IAC5B,OAAO,WAAW,GAAG,SAAS,GAAG,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC,KAAK,GAAG,EAAE,CAAC;QAChE,WAAW,EAAE,CAAC;IAClB,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IACnC,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACnC,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;IACrD,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAAC,CAAC;IAC3D,OAAO;QACH,MAAM;QACN,MAAM;QACN,YAAY,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,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O,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACjD,IAAI,QAAQ,KAAK,CAAC,CAAC,EAAE,CAAC;YAClB,OAAO,CAAC,CAAC,CAAC;QACd,CAAC;QACD,SAAS,GAAG,QAAQ,GAAG,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,CAAC,CAAC,CAAC;AACd,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,MAAc,EAAE,IAAY,EAAE,IAAe;IAClE,IAAI,GAAG,GAAG,IAAI,CAAC;IACf,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;QAC1B,GAAG,EAAE,CAAC;IACV,CAAC;IACD,OAAO,GAAG,GAAG,IAAI,CAAC;AACtB,CAAC","sourcesContent":["/** CommonMark fenced-code delimiters, shared by the scanner and the fence-form projection. */\n\nexport interface FenceOpen {\n readonly marker: '`' | '~';\n readonly length: number;\n readonly contentStart: number;\n /** The trimmed info string after the opening run. */\n readonly info: string;\n}\n\n/** Read a fenced-code opener at a physical line start (up to 3 spaces indented). */\nexport function readFence(source: string, lineStart: number): FenceOpen | null {\n let markerStart = lineStart;\n while (markerStart < lineStart + 3 && source[markerStart] === ' ') {\n markerStart++;\n }\n const marker = source[markerStart];\n if (marker !== '`' && marker !== '~') {\n return null;\n }\n const length = countRun(source, markerStart, marker);\n if (length < 3) {\n return null;\n }\n const lineEnd = source.indexOf('\\n', markerStart + length);\n return {\n marker,\n length,\n contentStart: lineEnd === -1 ? source.length : lineEnd + 1,\n info: source.slice(markerStart + length, lineEnd === -1 ? source.length : lineEnd).trim(),\n };\n}\n\n/** Find the byte immediately after a matching fenced-code closer. */\nexport function findFenceEnd(\n source: string,\n from: number,\n marker: '`' | '~',\n length: number\n): number {\n let lineStart = from;\n while (lineStart < source.length) {\n let markerStart = lineStart;\n while (markerStart < lineStart + 3 && source[markerStart] === ' ') {\n markerStart++;\n }\n const runLength = countRun(source, markerStart, marker);\n if (runLength >= length) {\n const lineEnd = source.indexOf('\\n', markerStart + runLength);\n const remainderEnd = lineEnd === -1 ? source.length : lineEnd;\n if (source.slice(markerStart + runLength, remainderEnd).trim() === '') {\n return lineEnd === -1 ? source.length : lineEnd + 1;\n }\n }\n const nextLine = source.indexOf('\\n', lineStart);\n if (nextLine === -1) {\n return -1;\n }\n lineStart = nextLine + 1;\n }\n return -1;\n}\n\nexport function countRun(source: string, from: number, char: '`' | '~'): number {\n let end = from;\n while (source[end] === char) {\n end++;\n }\n return end - from;\n}\n"]}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @leo-studio/leo-markup
3
+ *
4
+ * Pure-contract doc engine: the shared `<leo.*>` vocabulary, the island scanner,
5
+ * the leo registry + canonical prop schemas, the block/inline body rule, the
6
+ * PageContext type, and the parity test harness. No React, no ANSI — the web and
7
+ * terminal emitters are injected by leo-doc-web and leo-pty-renderer.
8
+ */
9
+ export * from './agent-support.js';
10
+ export * from './ast-json.js';
11
+ export * from './authoring-lints.js';
12
+ export * from './block-inline.js';
13
+ export * from './parity.js';
14
+ export * from './product-spec.js';
15
+ export * from './registry.js';
16
+ export * from './scanner.js';
17
+ export * from './tree-text.js';
18
+ export * from './types.js';
19
+ export * from './vocabulary.js';
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @leo-studio/leo-markup
3
+ *
4
+ * Pure-contract doc engine: the shared `<leo.*>` vocabulary, the island scanner,
5
+ * the leo registry + canonical prop schemas, the block/inline body rule, the
6
+ * PageContext type, and the parity test harness. No React, no ANSI — the web and
7
+ * terminal emitters are injected by leo-doc-web and leo-pty-renderer.
8
+ */
9
+ export * from './agent-support.js';
10
+ export * from './ast-json.js';
11
+ export * from './authoring-lints.js';
12
+ export * from './block-inline.js';
13
+ export * from './parity.js';
14
+ export * from './product-spec.js';
15
+ export * from './registry.js';
16
+ export * from './scanner.js';
17
+ export * from './tree-text.js';
18
+ export * from './types.js';
19
+ export * from './vocabulary.js';
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC","sourcesContent":["/**\n * @leo-studio/leo-markup\n *\n * Pure-contract doc engine: the shared `<leo.*>` vocabulary, the island scanner,\n * the leo registry + canonical prop schemas, the block/inline body rule, the\n * PageContext type, and the parity test harness. No React, no ANSI — the web and\n * terminal emitters are injected by leo-doc-web and leo-pty-renderer.\n */\n\nexport * from './agent-support.js';\nexport * from './ast-json.js';\nexport * from './authoring-lints.js';\nexport * from './block-inline.js';\nexport * from './parity.js';\nexport * from './product-spec.js';\nexport * from './registry.js';\nexport * from './scanner.js';\nexport * from './tree-text.js';\nexport * from './types.js';\nexport * from './vocabulary.js';\n"]}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The parity harness.
3
+ *
4
+ * The anti-drift spine: a shared component cannot ship half-rendered. This
5
+ * module checks a registry against the parity contract and returns the
6
+ * violations; a build/test wraps it to FAIL when any exist.
7
+ *
8
+ * Contract:
9
+ * - `targets: 'both'` → MUST register an ansi emitter AND a web emitter.
10
+ * - `targets: 'web-only'` → MUST register a web emitter AND declare a degrade.
11
+ * - `targets: 'terminal-only'` → MUST register an ansi emitter AND declare a degrade.
12
+ *
13
+ * The harness takes the registry as a PARAMETER (no hidden import of the real
14
+ * one) so it can be exercised against synthetic registries — including the
15
+ * RED-CHECK: a deliberately emitter-less `both` entry must produce a violation,
16
+ * proving the coverage check is not vacuous.
17
+ *
18
+ * Until both emitters are attached — the web emitters by leo-doc-web and the
19
+ * terminal emitters by leo-pty-renderer — the real registry's `both` entries
20
+ * have no emitters yet, so `checkParity(leoRegistry)` is EXPECTED to report
21
+ * violations. Once they are wired, the verify step re-runs it against the wired
22
+ * registry, where it must be clean. (This module never imports the real registry
23
+ * — it only defines the check.)
24
+ */
25
+ import type { LeoRegistry } from './types.js';
26
+ export interface ParityViolation {
27
+ /** The offending entry's registry key. */
28
+ readonly name: string;
29
+ readonly kind: 'missing-ansi' | 'missing-web' | 'missing-degrade';
30
+ readonly message: string;
31
+ }
32
+ export interface ParityReport {
33
+ readonly ok: boolean;
34
+ readonly violations: readonly ParityViolation[];
35
+ }
36
+ /** Check a whole registry; returns every violation (stable order by key). */
37
+ export declare function checkParity(registry: LeoRegistry): ParityReport;
38
+ /**
39
+ * Assert parity over a registry: throws with a readable message listing every
40
+ * violation when the contract is not met. This is the form a build/test step
41
+ * calls to FAIL on a missing emitter.
42
+ */
43
+ export declare function assertParity(registry: LeoRegistry): void;
44
+ //# sourceMappingURL=parity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parity.d.ts","sourceRoot":"","sources":["../src/parity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAgB,WAAW,EAAE,MAAM,YAAY,CAAC;AAG5D,MAAM,WAAW,eAAe;IAC5B,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,aAAa,GAAG,iBAAiB,CAAC;IAClE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,UAAU,EAAE,SAAS,eAAe,EAAE,CAAC;CACnD;AAwCD,6EAA6E;AAC7E,wBAAgB,WAAW,CAAC,QAAQ,EAAE,WAAW,GAAG,YAAY,CAO/D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,WAAW,GAAG,IAAI,CAMxD"}