@flatkit/compiler 0.19.10 → 0.19.12
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 +34 -0
- package/dist/{chunk-2NAWPQKH.js → chunk-DETQTCBJ.js} +2 -2
- package/dist/{chunk-TPDP5FDF.js → chunk-KXKX2RMX.js} +3 -2
- package/dist/chunk-KXKX2RMX.js.map +1 -0
- package/dist/cli/flatc.js +2 -2
- package/dist/compile.js +1 -1
- package/dist/index.js +2 -2
- package/package.json +6 -6
- package/dist/chunk-TPDP5FDF.js.map +0 -1
- /package/dist/{chunk-2NAWPQKH.js.map → chunk-DETQTCBJ.js.map} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @flatkit/compiler
|
|
2
|
+
|
|
3
|
+
The [FlatInk](http://flatink.zwyk-studio.com/) language (parser + AST) and compiler: turn readable
|
|
4
|
+
`.flatink` text into a single self-contained `.flatpack`. Ships the **`flatc`** CLI. Lives in build/CLI
|
|
5
|
+
tooling — the [player](https://www.npmjs.com/package/@flatkit/player) stays tiny and never pulls it in.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add -D @flatkit/compiler
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## CLI
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
flatc scene.flatink -o scene.flatpack # text sources -> one playable file
|
|
17
|
+
flatc scene.flatink --render -o frame.png # headless PNG preview
|
|
18
|
+
flatc scene.flatink --play --script gestures.json # headless replay + assertions (CI)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Programmatic
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { compileFlatpack } from '@flatkit/compiler/compile'
|
|
25
|
+
|
|
26
|
+
const doc = compileFlatpack(programSrc, assetSrcs, media) // -> Doc (the .flatpack)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Static analysis (lint, manifest, LLM context) lives under `@flatkit/compiler/analysis`.
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
|
+
|
|
33
|
+
[MIT](https://github.com/flatink/flatkit/blob/main/LICENSE) (c) Zwyk Studio — part of
|
|
34
|
+
[flatkit](https://github.com/flatink/flatkit).
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
compileFlatpack,
|
|
7
7
|
packToJSON
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-KXKX2RMX.js";
|
|
9
9
|
|
|
10
10
|
// src/cli/flatc.ts
|
|
11
11
|
import { readFileSync, writeFileSync, existsSync, readdirSync, watch, mkdirSync, copyFileSync } from "fs";
|
|
@@ -492,4 +492,4 @@ function run(argv) {
|
|
|
492
492
|
export {
|
|
493
493
|
run
|
|
494
494
|
};
|
|
495
|
-
//# sourceMappingURL=chunk-
|
|
495
|
+
//# sourceMappingURL=chunk-DETQTCBJ.js.map
|
|
@@ -20,7 +20,8 @@ function compileFlatpack(programSrc, assetSrcs = [], media = {}) {
|
|
|
20
20
|
resolveRefs(prog.layers, byName);
|
|
21
21
|
const assets = (prog.assets ?? []).map((a) => {
|
|
22
22
|
const m = media[a.data];
|
|
23
|
-
|
|
23
|
+
const r = m ? { ...a, mime: m.mime, data: m.data } : a;
|
|
24
|
+
return r.kind === "font" && !r.family ? { ...r, family: r.id } : r;
|
|
24
25
|
});
|
|
25
26
|
return {
|
|
26
27
|
width: prog.width,
|
|
@@ -44,4 +45,4 @@ export {
|
|
|
44
45
|
compileFlatpack,
|
|
45
46
|
packToJSON
|
|
46
47
|
};
|
|
47
|
-
//# sourceMappingURL=chunk-
|
|
48
|
+
//# sourceMappingURL=chunk-KXKX2RMX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/compile.ts"],"sourcesContent":["// ─────────────────────────────────────────────────────────────────────────────\n// compile.ts — the \"modern SWF\" compiler (RFC, step P2).\n//\n// Takes the PROGRAM (`.flatink`) + the ASSETS (`.flat`) and produces a resolved `Doc` —\n// the \".flatpack\" v1 (= the baked doc the player already plays). Steps:\n// 1. parse the assets → symbols;\n// 2. parse the program → composition + behavior (`@Name` refs);\n// 3. RESOLVE refs by name (instances → symbol id), across ALL libs;\n// 4. assemble the Doc.\n//\n// v1: no binary optimization nor media embedding (P2b). Pure, no DOM.\n// ─────────────────────────────────────────────────────────────────────────────\nimport type { Doc, Item, Layer } from '@flatkit/types'\nimport { parseFlatLib, parseProgramFull } from '@flatkit/engine/flatFormat'\nimport { isGroup, isInstance } from '@flatkit/engine/layers'\n\n/** Resolves `symbolId: '@Name'` instances into real ids (recursive, across groups). */\nfunction resolveRefs(layers: Layer[], byName: Map<string, string>): void {\n const walk = (items: Item[]) => {\n for (const it of items) {\n if (isInstance(it) && it.symbolId.startsWith('@')) it.symbolId = byName.get(it.symbolId.slice(1)) ?? it.symbolId\n if (isGroup(it)) it.layers.forEach((l) => walk(l.items))\n }\n }\n layers.forEach((l) => walk(l.items))\n}\n\n/** Source of a media (base64 data-URI) by declared path (`asset … \"path\" …`). */\nexport type MediaMap = Record<string, { mime: string; data: string }>\n\n/**\n * Compile a `.flatink` program + its `.flat` assets → playable `Doc` (the \".flatpack\").\n * `assetSrcs` = the text of each `.flat` lib. `media` = the content of the referenced media files\n * (by path). Symbol refs (by name) are resolved across the whole set of libs; declared media\n * are EMBEDDED (path → data-URI).\n */\nexport function compileFlatpack(programSrc: string, assetSrcs: string[] = [], media: MediaMap = {}): Doc {\n const libs = assetSrcs.map((src) => parseFlatLib(src))\n const symbols = libs.flatMap((l) => l.symbols)\n const folders = libs.flatMap((l) => l.folders) // library folders (organization)\n const prog = parseProgramFull(programSrc)\n const byName = new Map(symbols.map((s) => [s.name, s.id]))\n symbols.forEach((s) => resolveRefs(s.layers, byName)) // cross-lib refs\n resolveRefs(prog.layers, byName) // program refs\n\n // Embed declared media (data = path → provided data-URI). Missing = left as is.\n const assets = (prog.assets ?? []).map((a) => {\n const m = media[a.data]\n const r = m ? { ...a, mime: m.mime, data: m.data } : a\n // A font without an explicit family defaults to its declared id — which is exactly what text targets via\n // `font \"<id>\"`. Gives consumers an explicit `family` instead of relying on a `family || id` fallback.\n return r.kind === 'font' && !r.family ? { ...r, family: r.id } : r\n })\n\n return {\n width: prog.width,\n height: prog.height,\n ...(prog.background ? { background: prog.background } : {}),\n symbols,\n ...(folders.length ? { folders } : {}),\n layers: prog.layers,\n ...(prog.variables && Object.keys(prog.variables).length ? { variables: prog.variables } : {}),\n ...(prog.imports?.length ? { imports: prog.imports } : {}),\n ...(prog.functions?.length ? { functions: prog.functions } : {}),\n timeline: prog.timeline ?? { fps: 24, durationFrames: 60, tracks: [] },\n ...(prog.interactions?.length ? { interactions: prog.interactions } : {}),\n ...(prog.interactors?.length ? { interactors: prog.interactors } : {}),\n ...(assets.length ? { assets } : {}),\n }\n}\n\n/** Serialize the `.flatpack` v1 (JSON of the compiled Doc). */\nexport const packToJSON = (doc: Doc): string => JSON.stringify(doc)\n"],"mappings":";AAaA,SAAS,cAAc,wBAAwB;AAC/C,SAAS,SAAS,kBAAkB;AAGpC,SAAS,YAAY,QAAiB,QAAmC;AACvE,QAAM,OAAO,CAAC,UAAkB;AAC9B,eAAW,MAAM,OAAO;AACtB,UAAI,WAAW,EAAE,KAAK,GAAG,SAAS,WAAW,GAAG,EAAG,IAAG,WAAW,OAAO,IAAI,GAAG,SAAS,MAAM,CAAC,CAAC,KAAK,GAAG;AACxG,UAAI,QAAQ,EAAE,EAAG,IAAG,OAAO,QAAQ,CAAC,MAAM,KAAK,EAAE,KAAK,CAAC;AAAA,IACzD;AAAA,EACF;AACA,SAAO,QAAQ,CAAC,MAAM,KAAK,EAAE,KAAK,CAAC;AACrC;AAWO,SAAS,gBAAgB,YAAoB,YAAsB,CAAC,GAAG,QAAkB,CAAC,GAAQ;AACvG,QAAM,OAAO,UAAU,IAAI,CAAC,QAAQ,aAAa,GAAG,CAAC;AACrD,QAAM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I,CAAC;AAAA,IACvE,GAAI,KAAK,aAAa,SAAS,EAAE,aAAa,KAAK,YAAY,IAAI,CAAC;AAAA,IACpE,GAAI,OAAO,SAAS,EAAE,OAAO,IAAI,CAAC;AAAA,EACpC;AACF;AAGO,IAAM,aAAa,CAAC,QAAqB,KAAK,UAAU,GAAG;","names":[]}
|
package/dist/cli/flatc.js
CHANGED
package/dist/compile.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
run
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-DETQTCBJ.js";
|
|
4
4
|
import {
|
|
5
5
|
allScopeVariables,
|
|
6
6
|
docHasErrors,
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
import {
|
|
22
22
|
compileFlatpack,
|
|
23
23
|
packToJSON
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-KXKX2RMX.js";
|
|
25
25
|
|
|
26
26
|
// src/manifest.ts
|
|
27
27
|
import { EXPR_CHANNELS as EXPR_CHANNELS2 } from "@flatkit/engine/timeline";
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flatkit/compiler",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.12",
|
|
4
4
|
"description": "The FlatInk language (parser + AST) and compiler (.flatink → .flatpack). Ships the flatc CLI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Zwyk Studio",
|
|
7
7
|
"homepage": "http://flatink.zwyk-studio.com/",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/
|
|
10
|
+
"url": "git+https://github.com/flatink/flatkit.git",
|
|
11
11
|
"directory": "packages/compiler"
|
|
12
12
|
},
|
|
13
|
-
"bugs": "https://github.com/
|
|
13
|
+
"bugs": "https://github.com/flatink/flatkit/issues",
|
|
14
14
|
"keywords": [
|
|
15
15
|
"flatink",
|
|
16
16
|
"flatpack",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"bin"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@flatkit/player": "0.19.
|
|
49
|
-
"@flatkit/types": "0.19.
|
|
50
|
-
"@flatkit/engine": "0.19.
|
|
48
|
+
"@flatkit/player": "0.19.12",
|
|
49
|
+
"@flatkit/types": "0.19.12",
|
|
50
|
+
"@flatkit/engine": "0.19.12"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"skia-canvas": "^3.0.8"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/compile.ts"],"sourcesContent":["// ─────────────────────────────────────────────────────────────────────────────\n// compile.ts — the \"modern SWF\" compiler (RFC, step P2).\n//\n// Takes the PROGRAM (`.flatink`) + the ASSETS (`.flat`) and produces a resolved `Doc` —\n// the \".flatpack\" v1 (= the baked doc the player already plays). Steps:\n// 1. parse the assets → symbols;\n// 2. parse the program → composition + behavior (`@Name` refs);\n// 3. RESOLVE refs by name (instances → symbol id), across ALL libs;\n// 4. assemble the Doc.\n//\n// v1: no binary optimization nor media embedding (P2b). Pure, no DOM.\n// ─────────────────────────────────────────────────────────────────────────────\nimport type { Doc, Item, Layer } from '@flatkit/types'\nimport { parseFlatLib, parseProgramFull } from '@flatkit/engine/flatFormat'\nimport { isGroup, isInstance } from '@flatkit/engine/layers'\n\n/** Resolves `symbolId: '@Name'` instances into real ids (recursive, across groups). */\nfunction resolveRefs(layers: Layer[], byName: Map<string, string>): void {\n const walk = (items: Item[]) => {\n for (const it of items) {\n if (isInstance(it) && it.symbolId.startsWith('@')) it.symbolId = byName.get(it.symbolId.slice(1)) ?? it.symbolId\n if (isGroup(it)) it.layers.forEach((l) => walk(l.items))\n }\n }\n layers.forEach((l) => walk(l.items))\n}\n\n/** Source of a media (base64 data-URI) by declared path (`asset … \"path\" …`). */\nexport type MediaMap = Record<string, { mime: string; data: string }>\n\n/**\n * Compile a `.flatink` program + its `.flat` assets → playable `Doc` (the \".flatpack\").\n * `assetSrcs` = the text of each `.flat` lib. `media` = the content of the referenced media files\n * (by path). Symbol refs (by name) are resolved across the whole set of libs; declared media\n * are EMBEDDED (path → data-URI).\n */\nexport function compileFlatpack(programSrc: string, assetSrcs: string[] = [], media: MediaMap = {}): Doc {\n const libs = assetSrcs.map((src) => parseFlatLib(src))\n const symbols = libs.flatMap((l) => l.symbols)\n const folders = libs.flatMap((l) => l.folders) // library folders (organization)\n const prog = parseProgramFull(programSrc)\n const byName = new Map(symbols.map((s) => [s.name, s.id]))\n symbols.forEach((s) => resolveRefs(s.layers, byName)) // cross-lib refs\n resolveRefs(prog.layers, byName) // program refs\n\n // Embed declared media (data = path → provided data-URI). Missing = left as is.\n const assets = (prog.assets ?? []).map((a) => { const m = media[a.data]; return m ? { ...a, mime: m.mime, data: m.data } : a })\n\n return {\n width: prog.width,\n height: prog.height,\n ...(prog.background ? { background: prog.background } : {}),\n symbols,\n ...(folders.length ? { folders } : {}),\n layers: prog.layers,\n ...(prog.variables && Object.keys(prog.variables).length ? { variables: prog.variables } : {}),\n ...(prog.imports?.length ? { imports: prog.imports } : {}),\n ...(prog.functions?.length ? { functions: prog.functions } : {}),\n timeline: prog.timeline ?? { fps: 24, durationFrames: 60, tracks: [] },\n ...(prog.interactions?.length ? { interactions: prog.interactions } : {}),\n ...(prog.interactors?.length ? { interactors: prog.interactors } : {}),\n ...(assets.length ? { assets } : {}),\n }\n}\n\n/** Serialize the `.flatpack` v1 (JSON of the compiled Doc). */\nexport const packToJSON = (doc: Doc): string => JSON.stringify(doc)\n"],"mappings":";AAaA,SAAS,cAAc,wBAAwB;AAC/C,SAAS,SAAS,kBAAkB;AAGpC,SAAS,YAAY,QAAiB,QAAmC;AACvE,QAAM,OAAO,CAAC,UAAkB;AAC9B,eAAW,MAAM,OAAO;AACtB,UAAI,WAAW,EAAE,KAAK,GAAG,SAAS,WAAW,GAA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