aktion-runtime 0.5.3 → 0.5.4
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.
- package/README.md +119 -0
- package/dist/aktion.iife.js +34 -34
- package/dist/aktion.iife.js.map +1 -1
- package/dist/aktion.js +1823 -1644
- package/dist/aktion.js.map +1 -1
- package/dist/aktion.umd.cjs +34 -34
- package/dist/aktion.umd.cjs.map +1 -1
- package/dist/node/compile-BUw0GAvN.cjs +491 -0
- package/dist/node/compile-BUw0GAvN.cjs.map +1 -0
- package/dist/node/compile-DxttTzo8.js +492 -0
- package/dist/node/compile-DxttTzo8.js.map +1 -0
- package/dist/node/compiler.cjs +11 -0
- package/dist/node/compiler.cjs.map +1 -0
- package/dist/node/compiler.js +11 -0
- package/dist/node/compiler.js.map +1 -0
- package/dist/node/index-8OvnOYPI.js +14070 -0
- package/dist/node/index-8OvnOYPI.js.map +1 -0
- package/dist/node/index-DBgA3bHQ.cjs +14069 -0
- package/dist/node/index-DBgA3bHQ.cjs.map +1 -0
- package/dist/node/language.cjs +1244 -0
- package/dist/node/language.cjs.map +1 -0
- package/dist/node/language.js +1244 -0
- package/dist/node/language.js.map +1 -0
- package/dist/node/vite.cjs +65 -0
- package/dist/node/vite.cjs.map +1 -0
- package/dist/node/vite.js +65 -0
- package/dist/node/vite.js.map +1 -0
- package/dist/types/aktion-modules.d.ts +22 -0
- package/dist/types/compiler/compile.d.ts +54 -0
- package/dist/types/compiler/emit.d.ts +15 -0
- package/dist/types/compiler/index.d.ts +14 -0
- package/dist/types/compiler/linker.d.ts +27 -0
- package/dist/types/compiler/runtime.d.ts +63 -0
- package/dist/types/compiler/sourcemap.d.ts +40 -0
- package/dist/types/element.d.ts +36 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/language-api.d.ts +15 -0
- package/dist/types/parser/types.d.ts +38 -1
- package/dist/types/plugin/index.d.ts +10 -0
- package/dist/types/plugin/vite.d.ts +21 -0
- package/package.json +36 -5
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source-map generation for the build-time compiler (Node-oriented).
|
|
3
|
+
*
|
|
4
|
+
* Fidelity note — read before "improving" this. The Aktion DSL is compiled to
|
|
5
|
+
* an inert data blob (`JSON.parse(...)`), NOT transpiled line-for-line to JS,
|
|
6
|
+
* and the parser records start-only `loc` (line + column, 1-indexed) with no
|
|
7
|
+
* end position or byte offset (see `src/parser/types.ts`). So a high-precision
|
|
8
|
+
* range map is neither possible nor meaningful here. What IS valuable, and
|
|
9
|
+
* what we produce, is a valid v3 map that:
|
|
10
|
+
*
|
|
11
|
+
* - registers the original `.aktion` file as a source with its full content
|
|
12
|
+
* (`sourcesContent`), so it shows up in browser devtools, and
|
|
13
|
+
* - anchors the generated module back to the original source,
|
|
14
|
+
*
|
|
15
|
+
* which is exactly what lets Vite chain the map and surface the original file.
|
|
16
|
+
* Per-statement range mappings are a future enhancement gated on the parser
|
|
17
|
+
* recording end positions.
|
|
18
|
+
*
|
|
19
|
+
* We use `magic-string` (already a transitive dep, promoted to a direct one)
|
|
20
|
+
* because it is the de-facto standard every Vite/Rollup plugin uses, so the
|
|
21
|
+
* VLQ-encoded output is guaranteed compatible with Vite's source-map pipeline.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Plain v3 source map object (decoupled from magic-string's class instance).
|
|
25
|
+
* Shaped to match Vite/Rollup's `ExistingRawSourceMap` so it flows straight
|
|
26
|
+
* into the bundler's source-map pipeline when returned from `transform`.
|
|
27
|
+
*/
|
|
28
|
+
export interface RawSourceMap {
|
|
29
|
+
version: number;
|
|
30
|
+
sources: string[];
|
|
31
|
+
sourcesContent: string[];
|
|
32
|
+
names: string[];
|
|
33
|
+
mappings: string;
|
|
34
|
+
file?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Produce a v3 source map tying `generatedCode` back to `source`. `path` names
|
|
38
|
+
* the original file in `sources`; the map's `file` is `path + ".js"`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function generateSourceMap(source: string, generatedCode: string, path: string): RawSourceMap;
|
package/dist/types/element.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CompiledProgram } from './compiler/runtime.js';
|
|
1
2
|
import { DeltaOp } from './tooling/index.js';
|
|
2
3
|
import { ComponentSpec } from './library/types.js';
|
|
3
4
|
import { PromptOptions } from './prompt/generator.js';
|
|
@@ -19,6 +20,21 @@ export declare class AktionElement extends HTMLElement {
|
|
|
19
20
|
private rootEl;
|
|
20
21
|
private errorEl;
|
|
21
22
|
private currentResponse;
|
|
23
|
+
/**
|
|
24
|
+
* Pre-parsed AST injected by `mountCompiled(...)` (the build-time compiler /
|
|
25
|
+
* Vite plugin path). When set, `replan()` consumes it instead of calling
|
|
26
|
+
* `parse(currentResponse)`, then clears it so a later string update
|
|
27
|
+
* (`setResponse` / `appendChunk`) re-parses normally. `null` for the
|
|
28
|
+
* ordinary streamed-string path.
|
|
29
|
+
*/
|
|
30
|
+
private pendingCompiled;
|
|
31
|
+
/**
|
|
32
|
+
* Module id of the compiled program currently mounted (from
|
|
33
|
+
* `CompiledProgram.path`), or `null` for the string path. The Vite plugin's
|
|
34
|
+
* HMR runtime reads it (via the `sourceId` getter) to target the right
|
|
35
|
+
* `<aktion-app>` instances when a `.aktion` file changes.
|
|
36
|
+
*/
|
|
37
|
+
private compiledSourceId;
|
|
22
38
|
private renderScheduled;
|
|
23
39
|
/** True when the program text changed and the runtime needs a re-plan. */
|
|
24
40
|
private programDirty;
|
|
@@ -115,6 +131,26 @@ export declare class AktionElement extends HTMLElement {
|
|
|
115
131
|
programText: string;
|
|
116
132
|
state: Record<string, unknown>;
|
|
117
133
|
}): void;
|
|
134
|
+
/**
|
|
135
|
+
* Mount a build-time-compiled program — the artefact produced by the
|
|
136
|
+
* Aktion Vite/Rollup plugin or `compile()` from `aktion-runtime/compiler`.
|
|
137
|
+
* The pre-parsed AST is rendered directly, skipping the runtime parser; the
|
|
138
|
+
* runtime still re-validates against the active library on `replan()`, so a
|
|
139
|
+
* host that has called `registerComponents(...)` stays correct even if the
|
|
140
|
+
* program was compiled against the default library.
|
|
141
|
+
*
|
|
142
|
+
* The string path (`setResponse`, `appendChunk`, `response`) is unaffected.
|
|
143
|
+
* Pass `state` to seed reactive values before the first render (used for SSR
|
|
144
|
+
* hydration and for HMR `$state` preservation — see the plugin's HMR
|
|
145
|
+
* runtime, which snapshots via `serializeState()` and replays it here).
|
|
146
|
+
*/
|
|
147
|
+
mountCompiled(compiled: CompiledProgram, state?: Record<string, unknown>): void;
|
|
148
|
+
/**
|
|
149
|
+
* Module id of the compiled program currently mounted, or `null` when the
|
|
150
|
+
* element is driven by the streamed-string path. Used by the Vite plugin's
|
|
151
|
+
* HMR runtime to find the instances that host a changed `.aktion` file.
|
|
152
|
+
*/
|
|
153
|
+
get sourceId(): string | null;
|
|
118
154
|
/** Append a streaming chunk and re-render. */
|
|
119
155
|
appendChunk(chunk: string): void;
|
|
120
156
|
setTheme(theme: ThemeInput): void;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './renderer/index.js';
|
|
|
7
7
|
export * from './prompt/index.js';
|
|
8
8
|
export * from './theme/index.js';
|
|
9
9
|
export * from './language/index.js';
|
|
10
|
+
export * from './compiler/runtime.js';
|
|
10
11
|
declare global {
|
|
11
12
|
interface HTMLElementTagNameMap {
|
|
12
13
|
"aktion-app": AktionElement;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aktion-runtime/language` — the DOM-free language + tooling surface.
|
|
3
|
+
*
|
|
4
|
+
* Editors (VS Code, a future LSP), CLIs, and any host that needs
|
|
5
|
+
* diagnostics / completions / hover / snippets / grammar metadata can import
|
|
6
|
+
* this WITHOUT loading the `<aktion-app>` custom element (the main
|
|
7
|
+
* `aktion-runtime` entry calls `defineElement()` on import, which requires a
|
|
8
|
+
* DOM and would crash in a Node extension host). Everything re-exported here
|
|
9
|
+
* is pure and Node-safe — no DOM access at import time.
|
|
10
|
+
*/
|
|
11
|
+
export { getDiagnostics, getCompletions, getHoverInfo, type Position, type Diagnostic, type CompletionItem, type HoverInfo, } from './tooling/language-service.js';
|
|
12
|
+
export { getSnippets, type SnippetEntry } from './language/snippets.js';
|
|
13
|
+
export { getLanguageSpec, grammarSpec, keywordDocs, getComponentCatalog, type LanguageSpec, type ComponentEntry, type ComponentParam, type GrammarSpec, } from './language/index.js';
|
|
14
|
+
export { defaultLibrary } from './library/index.js';
|
|
15
|
+
export type { ComponentLibrary } from './library/types.js';
|
|
@@ -201,6 +201,37 @@ export interface AssignmentStatement {
|
|
|
201
201
|
identifier: string;
|
|
202
202
|
isState: boolean;
|
|
203
203
|
expression: Expression;
|
|
204
|
+
/**
|
|
205
|
+
* True when prefixed with `export` (multi-file modules). Build-time only —
|
|
206
|
+
* the linker uses it to decide importability; the runtime ignores it.
|
|
207
|
+
*/
|
|
208
|
+
exported?: boolean;
|
|
209
|
+
loc?: SourceLocation;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Single specifier in an `import { … } from "./mod.aktion"`. Names are stored
|
|
213
|
+
* WITHOUT the leading `$`; `isState` records that the surface syntax used `$`
|
|
214
|
+
* (so `import { $shared }` and `export $shared = …` line up by bare name).
|
|
215
|
+
*/
|
|
216
|
+
export interface ImportSpecifier {
|
|
217
|
+
/** Name as exported by the source module (bare, no `$`). */
|
|
218
|
+
imported: string;
|
|
219
|
+
/** Local alias bound in this module (bare, no `$`). */
|
|
220
|
+
local: string;
|
|
221
|
+
/** True when the binding is a `$state` atom. */
|
|
222
|
+
isState?: boolean;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* `import { A, B as C, $shared } from "./other.aktion"` — named imports for
|
|
226
|
+
* multi-file `.aktion` programs. Resolved + linked at BUILD TIME by the
|
|
227
|
+
* compiler/linker into a single merged program; the streaming runtime treats
|
|
228
|
+
* `Import` as a no-op (it has no filesystem to resolve against).
|
|
229
|
+
*/
|
|
230
|
+
export interface ImportStatement {
|
|
231
|
+
kind: "Import";
|
|
232
|
+
specifiers: ReadonlyArray<ImportSpecifier>;
|
|
233
|
+
/** Raw module specifier, e.g. "./components/counter.aktion". */
|
|
234
|
+
source: string;
|
|
204
235
|
loc?: SourceLocation;
|
|
205
236
|
}
|
|
206
237
|
/**
|
|
@@ -215,6 +246,8 @@ export interface ComponentDeclaration {
|
|
|
215
246
|
/** Names of the declared slots (from props object convention). */
|
|
216
247
|
slots: ReadonlyArray<string>;
|
|
217
248
|
body: BlockExpr;
|
|
249
|
+
/** True when prefixed with `export` (multi-file modules; build-time only). */
|
|
250
|
+
exported?: boolean;
|
|
218
251
|
loc?: SourceLocation;
|
|
219
252
|
}
|
|
220
253
|
/**
|
|
@@ -294,6 +327,8 @@ export interface ActionDeclaration {
|
|
|
294
327
|
params: ReadonlyArray<DeclParam>;
|
|
295
328
|
optimistic: boolean;
|
|
296
329
|
body: BlockExpr;
|
|
330
|
+
/** True when prefixed with `export` (multi-file modules; build-time only). */
|
|
331
|
+
exported?: boolean;
|
|
297
332
|
loc?: SourceLocation;
|
|
298
333
|
}
|
|
299
334
|
/**
|
|
@@ -319,6 +354,8 @@ export interface HookDeclaration {
|
|
|
319
354
|
name: string;
|
|
320
355
|
params: ReadonlyArray<DeclParam>;
|
|
321
356
|
body: BlockExpr;
|
|
357
|
+
/** True when prefixed with `export` (multi-file modules; build-time only). */
|
|
358
|
+
exported?: boolean;
|
|
322
359
|
loc?: SourceLocation;
|
|
323
360
|
}
|
|
324
361
|
/** `await expr` statement / expression — only valid inside `function`/`effect`. */
|
|
@@ -458,7 +495,7 @@ export interface TryStatement {
|
|
|
458
495
|
finallyBlock?: BlockExpr;
|
|
459
496
|
loc?: SourceLocation;
|
|
460
497
|
}
|
|
461
|
-
export type Statement = AssignmentStatement | ComponentDeclaration | EffectDeclaration | ActionDeclaration | HookDeclaration | AwaitStatement | ReturnStatement | ExpressionStatement | IfStatement | SwitchStatement | ForOfStatement | ForClassicStatement | ForInStatement | WhileStatement | DoWhileStatement | DestructureStatement | BreakStatement | ContinueStatement | ThrowStatement | TryStatement;
|
|
498
|
+
export type Statement = AssignmentStatement | ImportStatement | ComponentDeclaration | EffectDeclaration | ActionDeclaration | HookDeclaration | AwaitStatement | ReturnStatement | ExpressionStatement | IfStatement | SwitchStatement | ForOfStatement | ForClassicStatement | ForInStatement | WhileStatement | DoWhileStatement | DestructureStatement | BreakStatement | ContinueStatement | ThrowStatement | TryStatement;
|
|
462
499
|
export interface Program {
|
|
463
500
|
statements: Statement[];
|
|
464
501
|
errors: ParseError[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aktion-runtime/vite` — the Vite/Rollup plugin entry.
|
|
3
|
+
*
|
|
4
|
+
* Default export is the plugin factory, so consumers can write either:
|
|
5
|
+
*
|
|
6
|
+
* import aktion from "aktion-runtime/vite";
|
|
7
|
+
* import { aktionPlugin } from "aktion-runtime/vite";
|
|
8
|
+
*/
|
|
9
|
+
export { aktionPlugin, aktionPlugin as default } from './vite.js';
|
|
10
|
+
export type { AktionPluginOptions } from './vite.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
import { ComponentLibrary } from '../library/types.js';
|
|
3
|
+
export interface AktionPluginOptions {
|
|
4
|
+
/** Library to validate against at build time. Default: the default library. */
|
|
5
|
+
library?: ComponentLibrary;
|
|
6
|
+
/** Treat schema violations as fatal build errors vs. warnings. Default: true. */
|
|
7
|
+
schemaErrorsFatal?: boolean;
|
|
8
|
+
/** Warn when a program has no `aktion = …` entry binding. Default: true. */
|
|
9
|
+
requireEntry?: boolean;
|
|
10
|
+
/** Specifier the emitted module imports the runtime helper from. Default: `"aktion-runtime"`. */
|
|
11
|
+
runtimeModuleId?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The Aktion Vite/Rollup plugin. Add it to `plugins` in `vite.config.ts`:
|
|
15
|
+
*
|
|
16
|
+
* import aktion from "aktion-runtime/vite";
|
|
17
|
+
* export default { plugins: [aktion()] };
|
|
18
|
+
*/
|
|
19
|
+
export declare function aktionPlugin(options?: AktionPluginOptions): Plugin;
|
|
20
|
+
/** True for `*.aktion` ids (query/hash stripped). */
|
|
21
|
+
export declare function isAktionId(id: string): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aktion-runtime",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Aktion is a single web component that turns a compact, streaming-first DSL into a rich, interactive UI inside its shadow DOM. Works in React, Vue, Angular, Svelte, plain HTML — or no framework at all.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -12,6 +12,24 @@
|
|
|
12
12
|
"import": "./dist/index.js",
|
|
13
13
|
"require": "./dist/index.cjs"
|
|
14
14
|
},
|
|
15
|
+
"./vite": {
|
|
16
|
+
"types": "./dist/types/plugin/index.d.ts",
|
|
17
|
+
"import": "./dist/node/vite.js",
|
|
18
|
+
"require": "./dist/node/vite.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./compiler": {
|
|
21
|
+
"types": "./dist/types/compiler/index.d.ts",
|
|
22
|
+
"import": "./dist/node/compiler.js",
|
|
23
|
+
"require": "./dist/node/compiler.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./language": {
|
|
26
|
+
"types": "./dist/types/language-api.d.ts",
|
|
27
|
+
"import": "./dist/node/language.js",
|
|
28
|
+
"require": "./dist/node/language.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./aktion-modules": {
|
|
31
|
+
"types": "./dist/types/aktion-modules.d.ts"
|
|
32
|
+
},
|
|
15
33
|
"./style.css": "./dist/aktion.css",
|
|
16
34
|
"./system_prompt.txt": "./dist/system_prompt.txt",
|
|
17
35
|
"./system_prompt_chat.txt": "./dist/system_prompt_chat.txt"
|
|
@@ -24,8 +42,9 @@
|
|
|
24
42
|
},
|
|
25
43
|
"scripts": {
|
|
26
44
|
"dev": "npm run build && vite",
|
|
27
|
-
"build": "tsc -p tsconfig.build.json && vite build && node scripts/emit-prompt.mjs && node scripts/emit-entry.mjs",
|
|
45
|
+
"build": "tsc -p tsconfig.build.json && vite build && vite build -c vite.node.config.ts && node scripts/emit-prompt.mjs && node scripts/emit-entry.mjs",
|
|
28
46
|
"build:lib": "vite build",
|
|
47
|
+
"build:node": "vite build -c vite.node.config.ts",
|
|
29
48
|
"build:prompt": "node scripts/emit-prompt.mjs",
|
|
30
49
|
"build:entry": "node scripts/emit-entry.mjs",
|
|
31
50
|
"build:docs": "node scripts/build-docs.mjs",
|
|
@@ -34,13 +53,25 @@
|
|
|
34
53
|
"test:watch": "vitest",
|
|
35
54
|
"prepublishOnly": "npm run build"
|
|
36
55
|
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"magic-string": "^0.30.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"vite": "^5.0.0 || ^6.0.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependenciesMeta": {
|
|
63
|
+
"vite": {
|
|
64
|
+
"optional": true
|
|
65
|
+
}
|
|
66
|
+
},
|
|
37
67
|
"devDependencies": {
|
|
68
|
+
"@types/node": "^20.19.41",
|
|
69
|
+
"@vitest/web-worker": "^2.1.4",
|
|
70
|
+
"happy-dom": "^15.7.4",
|
|
38
71
|
"typescript": "^5.6.3",
|
|
39
72
|
"vite": "^5.4.10",
|
|
40
73
|
"vite-plugin-dts": "^4.3.0",
|
|
41
|
-
"vitest": "^2.1.4"
|
|
42
|
-
"@vitest/web-worker": "^2.1.4",
|
|
43
|
-
"happy-dom": "^15.7.4"
|
|
74
|
+
"vitest": "^2.1.4"
|
|
44
75
|
},
|
|
45
76
|
"keywords": [
|
|
46
77
|
"llm",
|