@aftertext/compiler 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +38 -2
  3. package/dist/ast/expression.d.ts +55 -0
  4. package/dist/ast/expression.d.ts.map +1 -0
  5. package/dist/ast/expression.js +2 -0
  6. package/dist/ast/expression.js.map +1 -0
  7. package/dist/ast/index.d.ts +6 -0
  8. package/dist/ast/index.d.ts.map +1 -0
  9. package/dist/ast/index.js +2 -0
  10. package/dist/ast/index.js.map +1 -0
  11. package/dist/ast/inline.d.ts +39 -0
  12. package/dist/ast/inline.d.ts.map +1 -0
  13. package/dist/ast/inline.js +2 -0
  14. package/dist/ast/inline.js.map +1 -0
  15. package/dist/ast/presentation.d.ts +41 -0
  16. package/dist/ast/presentation.d.ts.map +1 -0
  17. package/dist/ast/presentation.js +8 -0
  18. package/dist/ast/presentation.js.map +1 -0
  19. package/dist/ast/span.d.ts +19 -0
  20. package/dist/ast/span.d.ts.map +1 -0
  21. package/dist/ast/span.js +2 -0
  22. package/dist/ast/span.js.map +1 -0
  23. package/dist/ast/story.d.ts +350 -0
  24. package/dist/ast/story.d.ts.map +1 -0
  25. package/dist/ast/story.js +2 -0
  26. package/dist/ast/story.js.map +1 -0
  27. package/dist/compile.d.ts +25 -0
  28. package/dist/compile.d.ts.map +1 -0
  29. package/dist/compile.js +19 -0
  30. package/dist/compile.js.map +1 -0
  31. package/dist/diagnostics/codes.d.ts +25 -0
  32. package/dist/diagnostics/codes.d.ts.map +1 -0
  33. package/dist/diagnostics/codes.js +66 -0
  34. package/dist/diagnostics/codes.js.map +1 -0
  35. package/dist/diagnostics/index.d.ts +3 -0
  36. package/dist/diagnostics/index.d.ts.map +1 -0
  37. package/dist/diagnostics/index.js +2 -0
  38. package/dist/diagnostics/index.js.map +1 -0
  39. package/dist/diagnostics/types.d.ts +19 -0
  40. package/dist/diagnostics/types.d.ts.map +1 -0
  41. package/dist/diagnostics/types.js +2 -0
  42. package/dist/diagnostics/types.js.map +1 -0
  43. package/dist/index.d.ts +5 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +11 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/parser/blocks.d.ts +40 -0
  48. package/dist/parser/blocks.d.ts.map +1 -0
  49. package/dist/parser/blocks.js +907 -0
  50. package/dist/parser/blocks.js.map +1 -0
  51. package/dist/parser/directive-line.d.ts +21 -0
  52. package/dist/parser/directive-line.d.ts.map +1 -0
  53. package/dist/parser/directive-line.js +50 -0
  54. package/dist/parser/directive-line.js.map +1 -0
  55. package/dist/parser/document.d.ts +13 -0
  56. package/dist/parser/document.d.ts.map +1 -0
  57. package/dist/parser/document.js +28 -0
  58. package/dist/parser/document.js.map +1 -0
  59. package/dist/parser/expression-lexer.d.ts +26 -0
  60. package/dist/parser/expression-lexer.d.ts.map +1 -0
  61. package/dist/parser/expression-lexer.js +137 -0
  62. package/dist/parser/expression-lexer.js.map +1 -0
  63. package/dist/parser/expression-parser.d.ts +13 -0
  64. package/dist/parser/expression-parser.d.ts.map +1 -0
  65. package/dist/parser/expression-parser.js +201 -0
  66. package/dist/parser/expression-parser.js.map +1 -0
  67. package/dist/parser/frontmatter.d.ts +23 -0
  68. package/dist/parser/frontmatter.d.ts.map +1 -0
  69. package/dist/parser/frontmatter.js +118 -0
  70. package/dist/parser/frontmatter.js.map +1 -0
  71. package/dist/parser/index.d.ts +2 -0
  72. package/dist/parser/index.d.ts.map +1 -0
  73. package/dist/parser/index.js +2 -0
  74. package/dist/parser/index.js.map +1 -0
  75. package/dist/parser/lexical-primitives.d.ts +38 -0
  76. package/dist/parser/lexical-primitives.d.ts.map +1 -0
  77. package/dist/parser/lexical-primitives.js +46 -0
  78. package/dist/parser/lexical-primitives.js.map +1 -0
  79. package/dist/parser/lines.d.ts +32 -0
  80. package/dist/parser/lines.d.ts.map +1 -0
  81. package/dist/parser/lines.js +60 -0
  82. package/dist/parser/lines.js.map +1 -0
  83. package/dist/parser/markdown.d.ts +19 -0
  84. package/dist/parser/markdown.d.ts.map +1 -0
  85. package/dist/parser/markdown.js +221 -0
  86. package/dist/parser/markdown.js.map +1 -0
  87. package/dist/parser/serializer-safety.d.ts +56 -0
  88. package/dist/parser/serializer-safety.d.ts.map +1 -0
  89. package/dist/parser/serializer-safety.js +65 -0
  90. package/dist/parser/serializer-safety.js.map +1 -0
  91. package/dist/validation/index.d.ts +2 -0
  92. package/dist/validation/index.d.ts.map +1 -0
  93. package/dist/validation/index.js +2 -0
  94. package/dist/validation/index.js.map +1 -0
  95. package/dist/validation/validate.d.ts +4 -0
  96. package/dist/validation/validate.d.ts.map +1 -0
  97. package/dist/validation/validate.js +221 -0
  98. package/dist/validation/validate.js.map +1 -0
  99. package/package.json +43 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 z0rimo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,39 @@
1
- # Temporary Holding Version
1
+ # `@aftertext/compiler`
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
+ Compiles prose-first AfterText source into a validated `StoryDocument`.
4
+
5
+ > v0.1 foundation: the language and public API are early and may change.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @aftertext/compiler
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { compile } from "@aftertext/compiler";
17
+
18
+ const result = compile(`---
19
+ title: Example
20
+ ---
21
+
22
+ @scene start
23
+
24
+ Hello.
25
+ `);
26
+
27
+ if (result.hasErrors) {
28
+ console.error(result.diagnostics);
29
+ }
30
+
31
+ console.log(result.document);
32
+ ```
33
+
34
+ The compiler returns best-effort output plus structured diagnostics. AfterText
35
+ source is declarative and cannot execute arbitrary JavaScript.
36
+
37
+ ## License
38
+
39
+ MIT
@@ -0,0 +1,55 @@
1
+ import type { SourceSpan } from "./span.js";
2
+ /** A literal value permitted inside AfterText expressions. */
3
+ export type LiteralValue = string | number | boolean | null;
4
+ export type UnaryOperator = "!" | "-";
5
+ export type BinaryOperator = "*" | "/" | "%" | "+" | "-" | "<" | "<=" | ">" | ">=" | "==" | "!=" | "&&" | "||";
6
+ export interface LiteralExpression {
7
+ readonly type: "Literal";
8
+ readonly value: LiteralValue;
9
+ readonly span: SourceSpan;
10
+ }
11
+ export interface IdentifierExpression {
12
+ readonly type: "Identifier";
13
+ readonly name: string;
14
+ readonly span: SourceSpan;
15
+ }
16
+ export interface UnaryExpression {
17
+ readonly type: "Unary";
18
+ readonly operator: UnaryOperator;
19
+ readonly argument: ExpressionNode;
20
+ readonly span: SourceSpan;
21
+ }
22
+ export interface BinaryExpression {
23
+ readonly type: "Binary";
24
+ readonly operator: BinaryOperator;
25
+ readonly left: ExpressionNode;
26
+ readonly right: ExpressionNode;
27
+ readonly span: SourceSpan;
28
+ }
29
+ /**
30
+ * A call, `callee(args...)`. This is a syntax/AST primitive only: it does
31
+ * not mean user-defined functions, callable values, or a general standard
32
+ * library exist. `callee` is a plain name, never itself an expression (no
33
+ * member calls, no calling a computed value) — only a small, fixed set of
34
+ * compiler/runtime-approved builtin names may execute (see
35
+ * docs/PROJECT_SPEC.md Section 17.14). `args` stays structurally general
36
+ * (ordinary comma-separated expressions) so a future builtin with a
37
+ * different argument contract does not require redesigning this node;
38
+ * individual builtins impose their own, narrower argument rules through
39
+ * semantic validation, not through this AST shape.
40
+ */
41
+ export interface CallExpression {
42
+ readonly type: "Call";
43
+ readonly callee: string;
44
+ readonly args: readonly ExpressionNode[];
45
+ readonly span: SourceSpan;
46
+ }
47
+ /**
48
+ * AfterText expression AST. A discriminated union on `type`, deliberately
49
+ * excluding member access, indexing, arrays, objects, and assignment:
50
+ * `@set` is the only state-mutation syntax in v0.1. `Call` (added for
51
+ * Reader Memory queries, Section 17.14) is a fixed-builtin-only primitive,
52
+ * not a general function-call feature — see `CallExpression` above.
53
+ */
54
+ export type ExpressionNode = LiteralExpression | IdentifierExpression | UnaryExpression | BinaryExpression | CallExpression;
55
+ //# sourceMappingURL=expression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expression.d.ts","sourceRoot":"","sources":["../../src/ast/expression.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,8DAA8D;AAC9D,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAE5D,MAAM,MAAM,aAAa,GAAG,GAAG,GAAG,GAAG,CAAC;AAEtC,MAAM,MAAM,cAAc,GACtB,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,IAAI,GACJ,GAAG,GACH,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,CAAC;AAET,MAAM,W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ot":"","sources":["../../src/ast/expression.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ export type { SourcePosition, SourceSpan } from "./span.js";
2
+ export type { LiteralValue, UnaryOperator, BinaryOperator, LiteralExpression, IdentifierExpression, UnaryExpression, BinaryExpression, CallExpression, ExpressionNode } from "./expression.js";
3
+ export type { TextInline, EmphasisInline, StrongInline, InlineCodeInline, LinkInline, LineBreakInline, InlineNode } from "./inline.js";
4
+ export type { BackgroundCommand, LayerCommand, CameraAction, CameraZoomCommand, CameraCommand, MusicCommand, SfxCommand, PauseCommand, PresentationCommand } from "./presentation.js";
5
+ export type { StateValue, StoryStateDefinition, StoryMetadata, ParagraphNode, HeadingNode, PresentationNode, SetNode, GotoNode, ChoiceItem, ChoiceNode, ConditionalBranchKind, ConditionalBranch, ConditionalNode, VariantBranchKind, VariantBranch, VariantNode, StoryBlock, SceneNode, StoryDocument } from "./story.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ast/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5D,YAAY,EACV,YAAY,EACZ,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,cAAc,EACf,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,UAAU,EACV,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,UAAU,EACX,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,UAAU,EACV,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACR,UAAU,EACV,UAAU,EACV,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,aAAa,EACd,MAAM,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ast/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,39 @@
1
+ import type { SourceSpan } from "./span.js";
2
+ /**
3
+ * Inline content types produced by converting prose regions out of the
4
+ * Markdown parser's AST. This is intentionally a small subset of Markdown's
5
+ * inline grammar (see architecture notes in parser/markdown.ts) — AfterText
6
+ * v0.1 does not attempt to reimplement the complete Markdown spec.
7
+ */
8
+ export interface TextInline {
9
+ readonly type: "Text";
10
+ readonly value: string;
11
+ readonly span: SourceSpan;
12
+ }
13
+ export interface EmphasisInline {
14
+ readonly type: "Emphasis";
15
+ readonly children: readonly InlineNode[];
16
+ readonly span: SourceSpan;
17
+ }
18
+ export interface StrongInline {
19
+ readonly type: "Strong";
20
+ readonly children: readonly InlineNode[];
21
+ readonly span: SourceSpan;
22
+ }
23
+ export interface InlineCodeInline {
24
+ readonly type: "InlineCode";
25
+ readonly value: string;
26
+ readonly span: SourceSpan;
27
+ }
28
+ export interface LinkInline {
29
+ readonly type: "Link";
30
+ readonly url: string;
31
+ readonly children: readonly InlineNode[];
32
+ readonly span: SourceSpan;
33
+ }
34
+ export interface LineBreakInline {
35
+ readonly type: "LineBreak";
36
+ readonly span: SourceSpan;
37
+ }
38
+ export type InlineNode = TextInline | EmphasisInline | StrongInline | InlineCodeInline | LinkInline | LineBreakInline;
39
+ //# sourceMappingURL=inline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline.d.ts","sourceRoot":"","sources":["../../src/ast/inline.ts"],"names":[],"mappings":"AAAA,OAA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@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline.js","sourceRoot":"","sources":["../../src/ast/inline.ts"],"names":[],"mappings":""}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Typed presentation commands for @background, @layer, @camera, @music,
3
+ * @sfx, and @pause. The compiler owns parsing, unit normalization (e.g.
4
+ * `6s` / `1200ms` -> milliseconds), and validation of these directives, so
5
+ * runtime code consumes typed values and never re-parses directive text.
6
+ */
7
+ export interface BackgroundCommand {
8
+ readonly type: "Background";
9
+ readonly image: string;
10
+ }
11
+ export interface LayerCommand {
12
+ readonly type: "Layer";
13
+ readonly image: string;
14
+ }
15
+ /** v0.1 defines a single camera action. New actions extend this union. */
16
+ export type CameraAction = "zoom";
17
+ export interface CameraZoomCommand {
18
+ readonly type: "Camera";
19
+ readonly action: "zoom";
20
+ readonly to: number;
21
+ /** Milliseconds; absent when the directive didn't specify `duration=`. */
22
+ readonly durationMs: number | undefined;
23
+ }
24
+ export type CameraCommand = CameraZoomCommand;
25
+ export interface MusicCommand {
26
+ readonly type: "Music";
27
+ readonly track: string;
28
+ /** Absent when the directive didn't specify `volume=`. */
29
+ readonly volume: number | undefined;
30
+ }
31
+ export interface SfxCommand {
32
+ readonly type: "Sfx";
33
+ readonly clip: string;
34
+ }
35
+ export interface PauseCommand {
36
+ readonly type: "Pause";
37
+ /** Milliseconds. */
38
+ readonly durationMs: number;
39
+ }
40
+ export type PresentationCommand = BackgroundCommand | LayerCommand | CameraCommand | MusicCommand | SfxCommand | PauseCommand;
41
+ //# sourceMappingURL=presentation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentation.d.ts","sourceRoot":"","sources":["../../src/ast/presentation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,0EAA0E;AAC1E,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,0EAA0E;IAC1E,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CACzC;AAED,MAAM,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAE9C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,oBAAoB;IACpB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,MAAM,mBAAmB,GAC3B,iBAAiB,GACjB,YAAY,GACZ,aAAa,GACb,YAAY,GACZ,UAAU,GACV,YAAY,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Typed presentation commands for @background, @layer, @camera, @music,
3
+ * @sfx, and @pause. The compiler owns parsing, unit normalization (e.g.
4
+ * `6s` / `1200ms` -> milliseconds), and validation of these directives, so
5
+ * runtime code consumes typed values and never re-parses directive text.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=presentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentation.js","sourceRoot":"","sources":["../../src/ast/presentation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A single position in AfterText source: 1-based line, 1-based column,
3
+ * and a 0-based absolute character offset into the source string.
4
+ */
5
+ export interface SourcePosition {
6
+ readonly line: number;
7
+ readonly column: number;
8
+ readonly offset: number;
9
+ }
10
+ /**
11
+ * A half-open range `[start, end)` in AfterText source. Every AST node that
12
+ * originates from source text carries one of these so downstream tools
13
+ * (editors, error reporters) can map back to the original text.
14
+ */
15
+ export interface SourceSpan {
16
+ readonly start: SourcePosition;
17
+ readonly end: SourcePosition;
18
+ }
19
+ //# sourceMappingURL=span.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"span.d.ts","sourceRoot":"","sources":["../../src/ast/span.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAC;CAC9B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=span.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"span.js","sourceRoot":"","sources":["../../src/ast/span.ts"],"names":[],"mappings":""}
@@ -0,0 +1,350 @@
1
+ import type { ExpressionNode } from "./expression.js";
2
+ import type { InlineNode } from "./inline.js";
3
+ import type { PresentationCommand } from "./presentation.js";
4
+ import type { SourcePosition, SourceSpan } from "./span.js";
5
+ /** A state value allowed in v0.1 frontmatter `state:` and in `@set`. */
6
+ export type StateValue = string | number | boolean | null;
7
+ /**
8
+ * The story's initial state, declared in frontmatter's `state:` block and
9
+ * normalized into a plain map. First-class on StoryDocument — not folded
10
+ * into generic metadata — since it is the seed for runtime story state,
11
+ * a distinct concern from title/entry.
12
+ */
13
+ export type StoryStateDefinition = Readonly<Record<string, StateValue>>;
14
+ export interface StoryMetadata {
15
+ readonly title: string | undefined;
16
+ readonly entry: string | undefined;
17
+ /** Absent when the source had no frontmatter block. */
18
+ readonly span: SourceSpan | undefined;
19
+ }
20
+ export interface ParagraphNode {
21
+ readonly type: "Paragraph";
22
+ readonly children: readonly InlineNode[];
23
+ readonly span: SourceSpan;
24
+ }
25
+ export interface HeadingNode {
26
+ readonly type: "Heading";
27
+ readonly depth: 1 | 2 | 3 | 4 | 5 | 6;
28
+ readonly children: readonly InlineNode[];
29
+ readonly span: SourceSpan;
30
+ /**
31
+ * The exact authored Heading content bytes, excluding the opening marker,
32
+ * opening separator whitespace, any recognized ATX closing-hash sequence,
33
+ * trailing Heading syntax/whitespace, the Setext underline (and its
34
+ * indentation), and the line ending. Non-optional: an empty ATX Heading
35
+ * (e.g. `#`) still has a valid zero-width `contentSourceSpan` rather than
36
+ * `undefined` — see docs/PROJECT_SPEC.md Section 25.49. This is the sole
37
+ * patch target for Heading Structured Editing; never reconstruct source
38
+ * from `children`, which is not lossless (delimiter choice, escaping,
39
+ * spacing, and closing-hash/underline syntax are not AST-preserved).
40
+ */
41
+ readonly contentSourceSpan: SourceSpan;
42
+ /**
43
+ * The exact authored Heading *level* marker bytes, excluding everything
44
+ * else: for ATX, exactly the opening `#` run (e.g. `###` in
45
+ * `### Heading ###`), excluding separator whitespace, content, closing
46
+ * hashes, trailing whitespace, and the line ending; for Setext, exactly
47
+ * the underline character run (e.g. `=======` in `Heading\n=======`),
48
+ * excluding content, the line ending before the underline, underline
49
+ * indentation, underline trailing whitespace, and the line ending after.
50
+ * Non-optional: every Heading has a valid, non-zero-width level span.
51
+ * This is the sole patch target for Heading Level Editing — changing only
52
+ * this span changes `depth` while preserving authored style and content
53
+ * exactly. docs/PROJECT_SPEC.md Section 25.50.
54
+ */
55
+ readonly levelSourceSpan: SourceSpan;
56
+ }
57
+ export interface PresentationNode {
58
+ readonly type: "Presentation";
59
+ readonly command: PresentationCommand;
60
+ readonly span: SourceSpan;
61
+ /**
62
+ * Compiler/source-tooling metadata (docs/PROJECT_SPEC.md Section 25.36):
63
+ * absolute source spans of each recognized `key=value` parameter's
64
+ * authored VALUE text (e.g. `to=1.20` maps `"to"` to the span slicing
65
+ * exactly `1.20`, never `to=` or surrounding whitespace). Optional on
66
+ * this public type only so existing hand-constructed `PresentationNode`
67
+ * object literals (tests, downstream tooling) remain source-compatible —
68
+ * every `PresentationNode` the compiler itself produces always populates
69
+ * it (an empty record when the directive has no named parameters). Not
70
+ * part of `PresentationCommand`, never read by Runtime/Player, and does
71
+ * not change DSL semantics — this is source-analysis data only, enabling
72
+ * targeted, formatting-preserving source edits without re-parsing.
73
+ */
74
+ readonly parameterValueSpans?: Readonly<Record<string, SourceSpan>>;
75
+ /**
76
+ * Compiler/source-tooling metadata (docs/PROJECT_SPEC.md Section 25.36):
77
+ * the absolute source span of the directive's single authored positional
78
+ * (non-`key=value`) argument token — e.g. `@pause 0.50s` maps this to the
79
+ * span slicing exactly `0.50s`. Populated if and only if the directive's
80
+ * argument text contains exactly one positional token; `undefined` when
81
+ * there are zero, or two-or-more, positional tokens. `undefined` does
82
+ * **not** mean "no positional value was authored" — with two or more
83
+ * positional tokens, the parser's own semantic value is a synthetic
84
+ * join of non-contiguous source text (e.g. a named parameter may sit
85
+ * between two positional tokens), so no single `SourceSpan` could
86
+ * represent it without also covering unrelated source; no such span is
87
+ * ever synthesized. Optional on this public type for the same
88
+ * source-compatibility reason as `parameterValueSpans`.
89
+ */
90
+ readonly positionalValueSpan?: SourceSpan;
91
+ /**
92
+ * Compiler/source-tooling metadata (docs/PROJECT_SPEC.md Section 14): the
93
+ * absolute source position immediately after the final non-whitespace
94
+ * character of the directive's authored argument text, before any
95
+ * trailing line whitespace and before the line terminator. Populated for
96
+ * every successfully-parsed compiler-produced `PresentationNode`,
97
+ * regardless of directive kind. Never derived from `span.end`, which
98
+ * includes trailing line whitespace and is therefore unsafe as a source-
99
+ * tooling append anchor. Optional on this public type for the same
100
+ * source-compatibility reason as `parameterValueSpans`/
101
+ * `positionalValueSpan`.
102
+ */
103
+ readonly argumentsEndPosition?: SourcePosition;
104
+ /**
105
+ * Compiler/source-tooling metadata (docs/PROJECT_SPEC.md Section 14): for
106
+ * a recognized named (`key=value`) parameter, the absolute source span
107
+ * that, deleted via a single text replacement with `""`, removes exactly
108
+ * that parameter's complete authored `key=value` token plus exactly one
109
+ * adjacent authored inter-token separator (chosen so the directive-name-
110
+ * to-first-argument boundary is never touched — see the compiler source
111
+ * for the exact position rule), while preserving every other authored
112
+ * byte of the directive exactly. Populated for key `k` **if and only if**
113
+ * `k` occurs exactly once in the directive's argument text; `undefined`
114
+ * both when `k` is not authored at all and when `k` occurs two-or-more
115
+ * times. **`undefined` does not mean "not authored"** — with duplicate
116
+ * occurrences, the existing last-occurrence-wins `parameterValueSpans`
117
+ * still resolves an effective value, but no single removal range could
118
+ * safely delete "the property" (deleting only the effective last
119
+ * occurrence would silently reveal an earlier duplicate as the new
120
+ * authored value) — the same availability-style principle already
121
+ * documented on `positionalValueSpan`. This is generic, directive-kind-
122
+ * agnostic metadata: it may be populated for any recognized named key,
123
+ * including one a particular Editor does not expose Remove support for.
124
+ * Optional on this public type for the same source-compatibility reason
125
+ * as the other metadata fields above.
126
+ */
127
+ readonly parameterRemovalSpans?: Readonly<Record<string, SourceSpan>>;
128
+ /**
129
+ * Compiler/source-tooling metadata (docs/PROJECT_SPEC.md Section 14): the
130
+ * absolute source span covering every positional (non-`key=value`) token
131
+ * in the directive's argument text, populated **if and only if** at
132
+ * least one positional token exists AND all positional tokens occupy one
133
+ * uninterrupted physical run — i.e. no named `key=value` token occurs
134
+ * between the first and last positional token. Includes all authored
135
+ * inter-token whitespace between positional tokens verbatim (never
136
+ * re-canonicalized, even though the parser's own semantic value joins
137
+ * them with a single space). For exactly one positional token this
138
+ * necessarily covers the identical raw range as `positionalValueSpan` —
139
+ * both are populated in that case, which is expected, not a
140
+ * contradiction; this field does not replace, broaden, or redefine
141
+ * `positionalValueSpan`'s own unchanged one-token-only contract.
142
+ * **`undefined` does not mean "no positional value exists"** — it may
143
+ * also mean positional tokens exist but are physically non-contiguous
144
+ * because a named-parameter token is interleaved among them (the same
145
+ * availability-style principle already documented on
146
+ * `positionalValueSpan`/`parameterRemovalSpans`). Generic and
147
+ * directive-kind-agnostic; optional on this public type for the same
148
+ * source-compatibility reason as the other metadata fields above.
149
+ */
150
+ readonly contiguousPositionalSpan?: SourceSpan;
151
+ /**
152
+ * Compiler/source-tooling metadata (docs/PROJECT_SPEC.md Section 14): the
153
+ * absolute source span that, deleted via a single text replacement with
154
+ * `""`, removes this entire authored Presentation directive cleanly —
155
+ * `start` is always exactly `span.start` (never adjusted backward into
156
+ * preceding source), and `end` extends `span.end` by this directive's
157
+ * own physical source line's terminator width (0 at true end-of-file, 1
158
+ * for an authored `\n`, 2 for an authored `\r\n`), so deletion never
159
+ * leaves an accidental blank line behind. A directive owns only its own
160
+ * immediately-following line terminator for this purpose — never a
161
+ * preceding terminator, never additional following blank-line trivia,
162
+ * never neighboring block or container syntax. Unlike
163
+ * `parameterRemovalSpans`, there is no ambiguity condition: every
164
+ * successfully-parsed `PresentationNode` has exactly one physical
165
+ * directive line, so this field is always populated for a
166
+ * compiler-produced node. Optional on this public type for the same
167
+ * source-compatibility reason as the other metadata fields above.
168
+ */
169
+ readonly commandRemovalSpan?: SourceSpan;
170
+ }
171
+ export interface SetNode {
172
+ readonly type: "Set";
173
+ readonly name: string;
174
+ readonly expression: ExpressionNode;
175
+ readonly span: SourceSpan;
176
+ }
177
+ export interface GotoNode {
178
+ readonly type: "Goto";
179
+ readonly target: string;
180
+ readonly span: SourceSpan;
181
+ readonly targetSourceSpan: SourceSpan;
182
+ }
183
+ export interface ChoiceItem {
184
+ readonly text: string;
185
+ readonly target: string;
186
+ readonly condition: ExpressionNode | undefined;
187
+ readonly span: SourceSpan;
188
+ /**
189
+ * The exact absolute source span of the authored condition text, after
190
+ * the syntactic `if` separator — e.g. for `- Go -> north if (a || b) && c`
191
+ * this slices exactly to `(a || b) && c`. Populated whenever the Choice
192
+ * tail syntactically contains `target if <condition text>`, independently
193
+ * of whether that condition text later parses successfully — it is a
194
+ * source-tooling fact about the Choice grammar's own tail shape, not a
195
+ * semantic-success signal. `undefined` for an unconditional item, exactly
196
+ * matching `condition === undefined`.
197
+ *
198
+ * `condition.span` (an `ExpressionNode`'s own span) must NOT be used as a
199
+ * substitute for this field: the expression parser returns the inner node
200
+ * directly for a parenthesized sub-expression without widening its span to
201
+ * include the surrounding parentheses, so `condition.span` silently omits
202
+ * an opening `(` whenever parentheses wrap only part of a larger
203
+ * expression (needed for operator precedence) rather than the whole
204
+ * condition — corrupting any source slice built from it.
205
+ */
206
+ readonly conditionSourceSpan?: SourceSpan;
207
+ }
208
+ export interface ChoiceNode {
209
+ readonly type: "Choice";
210
+ readonly items: readonly ChoiceItem[];
211
+ readonly span: SourceSpan;
212
+ }
213
+ export type ConditionalBranchKind = "if" | "elseif" | "else";
214
+ export interface ConditionalBranch {
215
+ readonly kind: ConditionalBranchKind;
216
+ /** Present for "if" and "elseif" branches; absent for "else". */
217
+ readonly condition: ExpressionNode | undefined;
218
+ readonly blocks: readonly StoryBlock[];
219
+ readonly span: SourceSpan;
220
+ /**
221
+ * Compiler/source-tooling metadata (docs/PROJECT_SPEC.md Section 25.36,
222
+ * "Expansion: Nested Presentation Command Insertion"): the exact line-
223
+ * terminator byte sequence immediately following `span.end`, if one
224
+ * exists — `"\n"`, `"\r\n"`, or `""` when `span.end` sits at true end-of-
225
+ * file with no authored terminator to reuse (only reachable for a branch
226
+ * whose enclosing Conditional is itself unclosed/malformed). A local
227
+ * source fact only, mirroring `SceneNode.followingLineEnding`. Optional
228
+ * on this public type for the same hand-construction-compatibility
229
+ * reason as every other metadata field in this line; every compiler-
230
+ * produced `ConditionalBranch` populates it.
231
+ */
232
+ readonly followingLineEnding?: "\n" | "\r\n" | "";
233
+ /**
234
+ * The exact absolute source span of the authored condition text on an
235
+ * `@if` or `@elseif` header line. Populated only for non-`else` branches
236
+ * whose directive has non-empty args; `undefined` for `@else`, which has no
237
+ * condition value at all (never a zero-width span). Mirrors
238
+ * `VariantBranch.conditionSourceSpan`: `condition.span` must not be used as
239
+ * a substitute, since it omits surrounding parentheses for partially
240
+ * parenthesized expressions.
241
+ */
242
+ readonly conditionSourceSpan?: SourceSpan;
243
+ }
244
+ export interface ConditionalNode {
245
+ readonly type: "Conditional";
246
+ readonly branches: readonly ConditionalBranch[];
247
+ readonly span: SourceSpan;
248
+ }
249
+ export type VariantBranchKind = "when" | "otherwise";
250
+ export interface VariantBranch {
251
+ readonly kind: VariantBranchKind;
252
+ /** Deterministic id, e.g. `alice-status:0` or `alice-status:otherwise`. */
253
+ readonly branchId: string;
254
+ /** Present for "when" branches; absent for "otherwise". */
255
+ readonly condition: ExpressionNode | undefined;
256
+ readonly blocks: readonly StoryBlock[];
257
+ readonly span: SourceSpan;
258
+ /**
259
+ * Compiler/source-tooling metadata (docs/PROJECT_SPEC.md Section 25.36,
260
+ * "Expansion: Nested Presentation Command Insertion"): identical contract
261
+ * to `ConditionalBranch.followingLineEnding` above — the exact line-
262
+ * terminator byte sequence immediately following `span.end`, `""` only
263
+ * when `span.end` sits at true end-of-file (only reachable for a branch
264
+ * whose enclosing Variant is itself unclosed/malformed). Optional on this
265
+ * public type for the same hand-construction-compatibility reason as
266
+ * every other metadata field in this line; every compiler-produced
267
+ * `VariantBranch` populates it.
268
+ */
269
+ readonly followingLineEnding?: "\n" | "\r\n" | "";
270
+ /**
271
+ * The exact absolute source span of the authored condition text on a
272
+ * `@when` header line — e.g. for `@when (a || b) && c` this slices exactly
273
+ * to `(a || b) && c`. Populated whenever the branch directive syntactically
274
+ * presents a condition payload (i.e. `kind === "when"` with non-empty
275
+ * directive args), independently of whether that payload later parses
276
+ * successfully — a source-tooling fact about the branch header's own
277
+ * shape, not a semantic-success signal. `undefined` for an `otherwise`
278
+ * branch, exactly matching `condition === undefined`.
279
+ *
280
+ * `condition.span` (an `ExpressionNode`'s own span) must NOT be used as a
281
+ * substitute for this field, for the identical reason documented on
282
+ * `ChoiceItem.conditionSourceSpan` above: the expression parser returns
283
+ * the inner node directly for a parenthesized sub-expression without
284
+ * widening its span to include the surrounding parentheses, so
285
+ * `condition.span` silently omits an opening `(` whenever parentheses wrap
286
+ * only part of a larger expression rather than the whole condition —
287
+ * corrupting any source slice built from it.
288
+ */
289
+ readonly conditionSourceSpan?: SourceSpan;
290
+ }
291
+ export interface VariantNode {
292
+ readonly type: "Variant";
293
+ readonly id: string;
294
+ /**
295
+ * The exact absolute source span of the authored Variant declaration ID
296
+ * on the `@variant` header line — e.g. for `@variant my variant` this
297
+ * slices exactly to `my variant`, excluding `@variant`, the separator
298
+ * whitespace before the ID, any trailing header whitespace, and the EOL.
299
+ * Unlike `VariantBranch.conditionSourceSpan`, this field is always
300
+ * present (never `undefined`): for an empty authored ID — both bare
301
+ * `@variant` and separator-only `@variant ` (the parser cannot
302
+ * distinguish these two forms at the `args` level) — this is a
303
+ * zero-width span (`start.offset === end.offset`) at the parser-computed
304
+ * `argsStartColumn` position, giving source-tooling a coordinate to patch
305
+ * even when no ID text was authored at all. docs/PROJECT_SPEC.md Section
306
+ * 25.46.
307
+ */
308
+ readonly idSourceSpan: SourceSpan;
309
+ readonly branches: readonly VariantBranch[];
310
+ readonly span: SourceSpan;
311
+ }
312
+ export type StoryBlock = ParagraphNode | HeadingNode | PresentationNode | SetNode | GotoNode | ChoiceNode | ConditionalNode | VariantNode;
313
+ export interface SceneNode {
314
+ readonly type: "Scene";
315
+ readonly id: string;
316
+ readonly blocks: readonly StoryBlock[];
317
+ readonly span: SourceSpan;
318
+ /**
319
+ * Compiler/source-tooling metadata (docs/PROJECT_SPEC.md Section 25.35):
320
+ * the exact line-terminator byte sequence immediately following
321
+ * `span.end`, if one exists — `"\n"`, `"\r\n"`, or `""` when `span.end`
322
+ * sits at true end-of-file with no authored terminator to reuse. Carries
323
+ * no indentation, blank-line trivia, or generated text — a neutral fact
324
+ * only, derived directly from the same per-line terminator tracking the
325
+ * parser already performs while splitting source into lines. Optional on
326
+ * this public type for the same source-compatibility reason as every
327
+ * other metadata field in this line (existing hand-constructed
328
+ * `SceneNode` object literals remain source-compatible); every
329
+ * compiler-produced `SceneNode` populates it.
330
+ */
331
+ readonly followingLineEnding?: "\n" | "\r\n" | "";
332
+ }
333
+ export interface StoryDocument {
334
+ readonly type: "StoryDocument";
335
+ readonly metadata: StoryMetadata;
336
+ readonly initialState: StoryStateDefinition;
337
+ /**
338
+ * The scene id runtime code should start execution from — compiler-
339
+ * normalized execution semantics, distinct from author-facing
340
+ * `metadata.entry`. Resolution order: the author's explicit `entry` if
341
+ * given (even if it turns out not to reference a real scene — that is
342
+ * reported separately as an AT1004 diagnostic, the same way a dangling
343
+ * `@goto` target is), otherwise the document's first scene, otherwise
344
+ * the synthetic leading scene id ("main"). Always set, so runtime code
345
+ * never needs to guess or re-derive which scene starts the story.
346
+ */
347
+ readonly entryScene: string;
348
+ readonly scenes: readonly SceneNode[];
349
+ }
350
+ //# sourceMappingURL=story.d.ts.map