@0xbuff/throughline 0.0.0-stage → 0.0.2

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.
@@ -0,0 +1,70 @@
1
+ // src/examples.ts
2
+ /** Copyable sources shared by the gallery, editor and compiler acceptance tests. */
3
+ const EXAMPLES = [
4
+ {
5
+ id: "reconciliation",
6
+ title: "Reconciliation",
7
+ description: "Compare keyed children, preserve identity, and prepare the changes to commit.",
8
+ source: [
9
+ "```thl flow",
10
+ "group \"Current tree\" as tree",
11
+ "group \"Work in progress\" as tree",
12
+ "group \"Changes\" as column",
13
+ "node current \"List\" in \"Current tree\" = \"ul\"",
14
+ "node a \"Key a\" in \"Current tree\" = \"li\"",
15
+ "node b \"Key b\" in \"Current tree\" = \"li\"",
16
+ "node next \"List\" in \"Work in progress\" = \"ul\"",
17
+ "node reuse \"Key a\" in \"Work in progress\" = \"li\"",
18
+ "node added \"Key c\" in \"Work in progress\" hidden = \"li\"",
19
+ "node changes \"Commit plan\" in \"Changes\" as array = []",
20
+ "link currentA current -> a",
21
+ "link currentB current -> b",
22
+ "link nextA next -> reuse",
23
+ "link nextC next -> added hidden",
24
+ "step \"Compare the roots\"",
25
+ " focus current, next",
26
+ " note \"Both roots are ul elements. Compare their keyed children.\"",
27
+ "step \"Reuse key a\"",
28
+ " focus a, reuse",
29
+ " set reuse = \"li · reused\"",
30
+ " note \"The type and key match. Preserve this child’s identity.\"",
31
+ "step \"Remove key b\"",
32
+ " focus b, changes",
33
+ " set changes = [\"remove b\"]",
34
+ " note \"Key b is absent from the next children. Schedule its removal; the current tree stays intact until commit.\"",
35
+ "step \"Insert key c\"",
36
+ " show node added",
37
+ " show link nextC",
38
+ " focus added, changes",
39
+ " set added = \"li · new\"",
40
+ " set changes = [\"remove b\", \"insert c\"]",
41
+ " note \"Key c has no match in the current children. Prepare a new child.\"",
42
+ "step \"Ready to commit\"",
43
+ " focus reuse, added, changes",
44
+ " note \"The comparison is complete. Commit applies the planned changes; key a keeps its identity.\"",
45
+ "```"
46
+ ].join("\n")
47
+ },
48
+ {
49
+ id: "references",
50
+ title: "Shared references",
51
+ description: "Copy a reference, mutate the shared object, then move one pointer.",
52
+ source: [
53
+ "```thl bindings",
54
+ "let list = [1, 2]",
55
+ "let alias = list",
56
+ "alias.push(3)",
57
+ "alias = [7]",
58
+ "```"
59
+ ].join("\n")
60
+ },
61
+ {
62
+ id: "matrix",
63
+ title: "Matrix multiplication",
64
+ description: "Follow one row and one column to each output cell.",
65
+ source: "```thl matrix\nA = [[1,2],[3,4]]\nB = [[5,6],[7,8]]\n```"
66
+ }
67
+ ];
68
+ export { EXAMPLES };
69
+
70
+ //# sourceMappingURL=examples.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"examples.js","names":[],"sources":["../src/examples.ts"],"sourcesContent":["/** Copyable sources shared by the gallery, editor and compiler acceptance tests. */\nexport const EXAMPLES = [\n\t{\n\t\tid: \"reconciliation\",\n\t\ttitle: \"Reconciliation\",\n\t\tdescription:\n\t\t\t\"Compare keyed children, preserve identity, and prepare the changes to commit.\",\n\t\tsource: [\n\t\t\t\"```thl flow\",\n\t\t\t'group \"Current tree\" as tree',\n\t\t\t'group \"Work in progress\" as tree',\n\t\t\t'group \"Changes\" as column',\n\t\t\t'node current \"List\" in \"Current tree\" = \"ul\"',\n\t\t\t'node a \"Key a\" in \"Current tree\" = \"li\"',\n\t\t\t'node b \"Key b\" in \"Current tree\" = \"li\"',\n\t\t\t'node next \"List\" in \"Work in progress\" = \"ul\"',\n\t\t\t'node reuse \"Key a\" in \"Work in progress\" = \"li\"',\n\t\t\t'node added \"Key c\" in \"Work in progress\" hidden = \"li\"',\n\t\t\t'node changes \"Commit plan\" in \"Changes\" as array = []',\n\t\t\t\"link currentA current -> a\",\n\t\t\t\"link currentB current -> b\",\n\t\t\t\"link nextA next -> reuse\",\n\t\t\t\"link nextC next -> added hidden\",\n\t\t\t'step \"Compare the roots\"',\n\t\t\t\" focus current, next\",\n\t\t\t' note \"Both roots are ul elements. Compare their keyed children.\"',\n\t\t\t'step \"Reuse key a\"',\n\t\t\t\" focus a, reuse\",\n\t\t\t' set reuse = \"li · reused\"',\n\t\t\t' note \"The type and key match. Preserve this child’s identity.\"',\n\t\t\t'step \"Remove key b\"',\n\t\t\t\" focus b, changes\",\n\t\t\t' set changes = [\"remove b\"]',\n\t\t\t' note \"Key b is absent from the next children. Schedule its removal; the current tree stays intact until commit.\"',\n\t\t\t'step \"Insert key c\"',\n\t\t\t\" show node added\",\n\t\t\t\" show link nextC\",\n\t\t\t\" focus added, changes\",\n\t\t\t' set added = \"li · new\"',\n\t\t\t' set changes = [\"remove b\", \"insert c\"]',\n\t\t\t' note \"Key c has no match in the current children. Prepare a new child.\"',\n\t\t\t'step \"Ready to commit\"',\n\t\t\t\" focus reuse, added, changes\",\n\t\t\t' note \"The comparison is complete. Commit applies the planned changes; key a keeps its identity.\"',\n\t\t\t\"```\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tid: \"references\",\n\t\ttitle: \"Shared references\",\n\t\tdescription:\n\t\t\t\"Copy a reference, mutate the shared object, then move one pointer.\",\n\t\tsource: [\n\t\t\t\"```thl bindings\",\n\t\t\t\"let list = [1, 2]\",\n\t\t\t\"let alias = list\",\n\t\t\t\"alias.push(3)\",\n\t\t\t\"alias = [7]\",\n\t\t\t\"```\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tid: \"matrix\",\n\t\ttitle: \"Matrix multiplication\",\n\t\tdescription: \"Follow one row and one column to each output cell.\",\n\t\tsource: \"```thl matrix\\nA = [[1,2],[3,4]]\\nB = [[5,6],[7,8]]\\n```\",\n\t},\n] as const;\n"],"mappings":";;AACA,MAAa,WAAW;CACvB;EACC,IAAI;EACJ,OAAO;EACP,aACC;EACD,QAAQ;GACP;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACD,CAAC,CAAC,KAAK,IAAI;CACZ;CACA;EACC,IAAI;EACJ,OAAO;EACP,aACC;EACD,QAAQ;GACP;GACA;GACA;GACA;GACA;GACA;EACD,CAAC,CAAC,KAAK,IAAI;CACZ;CACA;EACC,IAAI;EACJ,OAAO;EACP,aAAa;EACb,QAAQ;CACT;AACD"}
@@ -0,0 +1,68 @@
1
+ /** Pure authoring and compilation API. The optional renderer lives at ./react. */
2
+ import { a as Frame, c as ProgramError, d as Snapshot, f as SourceLocation, h as View, i as Event, l as Relation, m as Value, n as Diagnostic, o as GroupLayout, p as Trace, r as Entity, s as Program, t as Beat, u as SceneGroup } from "./model-Dwy20ibD.js";
3
+ /** A single parsed fence. Markdown adapters supply lines directly, without reparsing. */
4
+ type ThlBlock = {
5
+ kind: string;
6
+ lines: string[];
7
+ /** Location of the header, so the first body line is source.line + 1. */
8
+ source?: SourceLocation;
9
+ };
10
+ /**
11
+ * Parse one thl block, optionally fenced with backticks or tildes. Fence
12
+ * lengths/indentation follow CommonMark; document/container parsing belongs
13
+ * to the host's Markdown parser, not a second parser inside the engine.
14
+ */
15
+ export declare function parseThl(src: string): ThlBlock | null;
16
+ export declare function parseProgram(ast: ThlBlock): Program;
17
+ export declare function validateProgram(input: unknown): asserts input is Program;
18
+ export declare function compileProgram(input: unknown): Trace;
19
+ /**
20
+ * One paragraph naming the step position, label, changed values,
21
+ * focus targets, transfers, and author notes. Deterministic: the
22
+ * same frame always reads the same way.
23
+ */
24
+ export declare function describeFrame(frame: Frame, total?: number): string;
25
+ /** Domains routed by the ```thl <domain> info string. */
26
+ type DomainName = "flow" | "bindings" | "binary" | "matrix" | "callstack";
27
+ export declare const SUPPORTED_DOMAINS: readonly DomainName[];
28
+ /** Compile any fenced thl block, routing on the info-string domain. */
29
+ export declare function compile(src: string): Trace;
30
+ export declare function compileAst(ast: ThlBlock): Trace;
31
+ /** Fixed v1 safety ceilings, independent of machine speed or wall-clock timing. */
32
+ export declare const COMPILATION_LIMITS: Readonly<{
33
+ sourceCharacters: 262144;
34
+ programUnits: 1000000;
35
+ traceUnits: 8000000;
36
+ entities: 200;
37
+ relations: 1000;
38
+ steps: 2000;
39
+ events: 10000;
40
+ }>;
41
+ type StepApi = {
42
+ set(target: string, value: Value): void;
43
+ focus(...targets: string[]): void;
44
+ send(relation: string, value?: Value): void;
45
+ note(text: string): void;
46
+ show(kind: "node" | "link", id: string): void;
47
+ hide(kind: "node" | "link", id: string): void;
48
+ };
49
+ type Tracer = {
50
+ group(name: string, layout: GroupLayout): Tracer;
51
+ node(id: string, label: string, value: Value, options?: {
52
+ lane?: string;
53
+ view?: View;
54
+ hidden?: boolean;
55
+ }): Tracer;
56
+ link(id: string, from: string, to: string, label?: string, options?: {
57
+ hidden?: boolean;
58
+ }): Tracer;
59
+ get(target: string): Value | undefined;
60
+ step(label: string, body: (step: StepApi) => void): Tracer;
61
+ program(): Program;
62
+ };
63
+ /**
64
+ * Computation adapter: run any ordinary algorithm and narrate it.
65
+ * Values written in a step become visible together, exactly like authored steps.
66
+ */
67
+ export declare function tracer(): Tracer;
68
+ export { type Beat, type Diagnostic, type DomainName, type Entity, type Event, type Frame, type GroupLayout, type Program, ProgramError, type Relation, type SceneGroup, type Snapshot, type SourceLocation, type StepApi, type ThlBlock, type Trace, type Tracer, type Value, type View };