@genetik/renderer 0.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Eugene Michasiw
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 ADDED
@@ -0,0 +1,15 @@
1
+ # @genetik/renderer
2
+
3
+ Framework-agnostic core: resolves content + schema into a **resolved tree** (ResolvedNode). No UI framework; use @genetik/renderer-react (or another binding) to map the tree to components.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @genetik/renderer
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ - **resolve(content, schema)** — Returns the root ResolvedNode, or null if the entry node is missing. Each node has `block`, `config`, and `slots` (slot name → ordered array of ResolvedNode).
14
+
15
+ See the [docs](/docs/packages/renderer) for API and examples.
package/dist/index.cjs ADDED
@@ -0,0 +1,55 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _genetik_content = require("@genetik/content");
3
+ let _genetik_schema = require("@genetik/schema");
4
+
5
+ //#region src/resolve.ts
6
+ /**
7
+ * Resolves content against a schema into a tree of ResolvedNode. Walks from the
8
+ * entry node and resolves each slot to ordered child ResolvedNodes. Missing
9
+ * nodes (dangling refs) are skipped. Framework-agnostic; use a binding
10
+ * (e.g. @genetik/renderer-react) to map ResolvedNode to UI components.
11
+ *
12
+ * Accepts either a content object or a JSON string (parsed with parseContentJson).
13
+ * Returns null if content is invalid JSON, the entry node is missing, or resolution fails.
14
+ */
15
+ function resolve(content, schema) {
16
+ let parsed;
17
+ if (typeof content === "string") {
18
+ const result = (0, _genetik_content.parseContentJson)(content);
19
+ parsed = result.ok ? result.content : null;
20
+ } else parsed = content;
21
+ if (!parsed) return null;
22
+ const root = parsed.nodes[parsed.entryId];
23
+ if (!root) return null;
24
+ return resolveNode(parsed, schema, root);
25
+ }
26
+ function resolveNode(content, schema, node) {
27
+ const blockType = (0, _genetik_schema.getBlockType)(schema, node.block);
28
+ const slots = {};
29
+ if (blockType) for (const slotDef of blockType.slots) {
30
+ const value = node[slotDef.name];
31
+ const ids = slotValueToIds(value);
32
+ const children = [];
33
+ for (const id of ids) {
34
+ const child = content.nodes[id];
35
+ if (child) children.push(resolveNode(content, schema, child));
36
+ }
37
+ slots[slotDef.name] = children;
38
+ }
39
+ return {
40
+ id: node.id,
41
+ block: node.block,
42
+ config: node.config,
43
+ slots
44
+ };
45
+ }
46
+ function slotValueToIds(value) {
47
+ if (value === void 0 || value === null) return [];
48
+ if (typeof value === "string") return [value];
49
+ if (Array.isArray(value)) return value.filter((v) => typeof v === "string");
50
+ return [];
51
+ }
52
+
53
+ //#endregion
54
+ exports.resolve = resolve;
55
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/resolve.ts"],"sourcesContent":["import { parseContentJson } from \"@genetik/content\";\nimport type { ContentNode, GenetikContent } from \"@genetik/content\";\nimport type { GenetikSchema } from \"@genetik/schema\";\nimport { getBlockType } from \"@genetik/schema\";\nimport type { ResolvedNode } from \"./types.js\";\n\n/**\n * Resolves content against a schema into a tree of ResolvedNode. Walks from the\n * entry node and resolves each slot to ordered child ResolvedNodes. Missing\n * nodes (dangling refs) are skipped. Framework-agnostic; use a binding\n * (e.g. @genetik/renderer-react) to map ResolvedNode to UI components.\n *\n * Accepts either a content object or a JSON string (parsed with parseContentJson).\n * Returns null if content is invalid JSON, the entry node is missing, or resolution fails.\n */\nexport function resolve(\n content: GenetikContent | string,\n schema: GenetikSchema,\n): ResolvedNode | null {\n let parsed: GenetikContent | null;\n if (typeof content === \"string\") {\n const result = parseContentJson(content);\n parsed = result.ok ? result.content : null;\n } else {\n parsed = content;\n }\n if (!parsed) return null;\n const root = parsed.nodes[parsed.entryId];\n if (!root) return null;\n return resolveNode(parsed, schema, root);\n}\n\nfunction resolveNode(\n content: GenetikContent,\n schema: GenetikSchema,\n node: ContentNode\n): ResolvedNode {\n const blockType = getBlockType(schema, node.block);\n const slots: Record<string, ResolvedNode[]> = {};\n\n if (blockType) {\n for (const slotDef of blockType.slots) {\n const value = node[slotDef.name];\n const ids = slotValueToIds(value);\n const children: ResolvedNode[] = [];\n for (const id of ids) {\n const child = content.nodes[id];\n if (child) {\n children.push(resolveNode(content, schema, child));\n }\n }\n slots[slotDef.name] = children;\n }\n }\n\n return {\n id: node.id,\n block: node.block,\n config: node.config,\n slots,\n };\n}\n\nfunction slotValueToIds(value: unknown): string[] {\n if (value === undefined || value === null) return [];\n if (typeof value === \"string\") return [value];\n if (Array.isArray(value)) return value.filter((v): v is string => typeof v === \"string\");\n return [];\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,SAAgB,QACd,SACA,QACqB;CACrB,IAAI;AACJ,KAAI,OAAO,YAAY,UAAU;EAC/B,MAAM,gDAA0B,QAAQ;AACxC,WAAS,OAAO,KAAK,OAAO,UAAU;OAEtC,UAAS;AAEX,KAAI,CAAC,OAAQ,QAAO;CACpB,MAAM,OAAO,OAAO,MAAM,OAAO;AACjC,KAAI,CAAC,KAAM,QAAO;AAClB,QAAO,YAAY,QAAQ,QAAQ,KAAK;;AAG1C,SAAS,YACP,SACA,QACA,MACc;CACd,MAAM,8CAAyB,QAAQ,KAAK,MAAM;CAClD,MAAM,QAAwC,EAAE;AAEhD,KAAI,UACF,MAAK,MAAM,WAAW,UAAU,OAAO;EACrC,MAAM,QAAQ,KAAK,QAAQ;EAC3B,MAAM,MAAM,eAAe,MAAM;EACjC,MAAM,WAA2B,EAAE;AACnC,OAAK,MAAM,MAAM,KAAK;GACpB,MAAM,QAAQ,QAAQ,MAAM;AAC5B,OAAI,MACF,UAAS,KAAK,YAAY,SAAS,QAAQ,MAAM,CAAC;;AAGtD,QAAM,QAAQ,QAAQ;;AAI1B,QAAO;EACL,IAAI,KAAK;EACT,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb;EACD;;AAGH,SAAS,eAAe,OAA0B;AAChD,KAAI,UAAU,UAAa,UAAU,KAAM,QAAO,EAAE;AACpD,KAAI,OAAO,UAAU,SAAU,QAAO,CAAC,MAAM;AAC7C,KAAI,MAAM,QAAQ,MAAM,CAAE,QAAO,MAAM,QAAQ,MAAmB,OAAO,MAAM,SAAS;AACxF,QAAO,EAAE"}
@@ -0,0 +1,33 @@
1
+ import { GenetikContent } from "@genetik/content";
2
+ import { GenetikSchema } from "@genetik/schema";
3
+
4
+ //#region src/types.d.ts
5
+ /**
6
+ * A node in the resolved tree: block type, config, and resolved children per slot.
7
+ * Framework-agnostic; a React (or other) binding maps this to components.
8
+ */
9
+ interface ResolvedNode {
10
+ /** Content node id (for React keys when rendering slot children). */
11
+ id: string;
12
+ /** Block type name. */
13
+ block: string;
14
+ /** Block-specific config. */
15
+ config: Record<string, unknown>;
16
+ /** Resolved children by slot name. Each slot is an ordered array of ResolvedNode. */
17
+ slots: Record<string, ResolvedNode[]>;
18
+ }
19
+ //#endregion
20
+ //#region src/resolve.d.ts
21
+ /**
22
+ * Resolves content against a schema into a tree of ResolvedNode. Walks from the
23
+ * entry node and resolves each slot to ordered child ResolvedNodes. Missing
24
+ * nodes (dangling refs) are skipped. Framework-agnostic; use a binding
25
+ * (e.g. @genetik/renderer-react) to map ResolvedNode to UI components.
26
+ *
27
+ * Accepts either a content object or a JSON string (parsed with parseContentJson).
28
+ * Returns null if content is invalid JSON, the entry node is missing, or resolution fails.
29
+ */
30
+ declare function resolve(content: GenetikContent | string, schema: GenetikSchema): ResolvedNode | null;
31
+ //#endregion
32
+ export { type ResolvedNode, resolve };
33
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/resolve.ts"],"mappings":";;;;;;;;UAIiB,YAAA;EAAY;EAE3B,EAAA;EAIQ;EAFR,KAAA;EAIO;EAFP,MAAA,EAAQ,MAAA;EAEK;EAAb,KAAA,EAAO,MAAA,SAAe,YAAA;AAAA;;;;AARxB;;;;;;;;iBCWgB,OAAA,CACd,OAAA,EAAS,cAAA,WACT,MAAA,EAAQ,aAAA,GACP,YAAA"}
@@ -0,0 +1,33 @@
1
+ import { GenetikContent } from "@genetik/content";
2
+ import { GenetikSchema } from "@genetik/schema";
3
+
4
+ //#region src/types.d.ts
5
+ /**
6
+ * A node in the resolved tree: block type, config, and resolved children per slot.
7
+ * Framework-agnostic; a React (or other) binding maps this to components.
8
+ */
9
+ interface ResolvedNode {
10
+ /** Content node id (for React keys when rendering slot children). */
11
+ id: string;
12
+ /** Block type name. */
13
+ block: string;
14
+ /** Block-specific config. */
15
+ config: Record<string, unknown>;
16
+ /** Resolved children by slot name. Each slot is an ordered array of ResolvedNode. */
17
+ slots: Record<string, ResolvedNode[]>;
18
+ }
19
+ //#endregion
20
+ //#region src/resolve.d.ts
21
+ /**
22
+ * Resolves content against a schema into a tree of ResolvedNode. Walks from the
23
+ * entry node and resolves each slot to ordered child ResolvedNodes. Missing
24
+ * nodes (dangling refs) are skipped. Framework-agnostic; use a binding
25
+ * (e.g. @genetik/renderer-react) to map ResolvedNode to UI components.
26
+ *
27
+ * Accepts either a content object or a JSON string (parsed with parseContentJson).
28
+ * Returns null if content is invalid JSON, the entry node is missing, or resolution fails.
29
+ */
30
+ declare function resolve(content: GenetikContent | string, schema: GenetikSchema): ResolvedNode | null;
31
+ //#endregion
32
+ export { type ResolvedNode, resolve };
33
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/resolve.ts"],"mappings":";;;;;;;;UAIiB,YAAA;EAAY;EAE3B,EAAA;EAIQ;EAFR,KAAA;EAIO;EAFP,MAAA,EAAQ,MAAA;EAEK;EAAb,KAAA,EAAO,MAAA,SAAe,YAAA;AAAA;;;;AARxB;;;;;;;;iBCWgB,OAAA,CACd,OAAA,EAAS,cAAA,WACT,MAAA,EAAQ,aAAA,GACP,YAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,54 @@
1
+ import { parseContentJson } from "@genetik/content";
2
+ import { getBlockType } from "@genetik/schema";
3
+
4
+ //#region src/resolve.ts
5
+ /**
6
+ * Resolves content against a schema into a tree of ResolvedNode. Walks from the
7
+ * entry node and resolves each slot to ordered child ResolvedNodes. Missing
8
+ * nodes (dangling refs) are skipped. Framework-agnostic; use a binding
9
+ * (e.g. @genetik/renderer-react) to map ResolvedNode to UI components.
10
+ *
11
+ * Accepts either a content object or a JSON string (parsed with parseContentJson).
12
+ * Returns null if content is invalid JSON, the entry node is missing, or resolution fails.
13
+ */
14
+ function resolve(content, schema) {
15
+ let parsed;
16
+ if (typeof content === "string") {
17
+ const result = parseContentJson(content);
18
+ parsed = result.ok ? result.content : null;
19
+ } else parsed = content;
20
+ if (!parsed) return null;
21
+ const root = parsed.nodes[parsed.entryId];
22
+ if (!root) return null;
23
+ return resolveNode(parsed, schema, root);
24
+ }
25
+ function resolveNode(content, schema, node) {
26
+ const blockType = getBlockType(schema, node.block);
27
+ const slots = {};
28
+ if (blockType) for (const slotDef of blockType.slots) {
29
+ const value = node[slotDef.name];
30
+ const ids = slotValueToIds(value);
31
+ const children = [];
32
+ for (const id of ids) {
33
+ const child = content.nodes[id];
34
+ if (child) children.push(resolveNode(content, schema, child));
35
+ }
36
+ slots[slotDef.name] = children;
37
+ }
38
+ return {
39
+ id: node.id,
40
+ block: node.block,
41
+ config: node.config,
42
+ slots
43
+ };
44
+ }
45
+ function slotValueToIds(value) {
46
+ if (value === void 0 || value === null) return [];
47
+ if (typeof value === "string") return [value];
48
+ if (Array.isArray(value)) return value.filter((v) => typeof v === "string");
49
+ return [];
50
+ }
51
+
52
+ //#endregion
53
+ export { resolve };
54
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/resolve.ts"],"sourcesContent":["import { parseContentJson } from \"@genetik/content\";\nimport type { ContentNode, GenetikContent } from \"@genetik/content\";\nimport type { GenetikSchema } from \"@genetik/schema\";\nimport { getBlockType } from \"@genetik/schema\";\nimport type { ResolvedNode } from \"./types.js\";\n\n/**\n * Resolves content against a schema into a tree of ResolvedNode. Walks from the\n * entry node and resolves each slot to ordered child ResolvedNodes. Missing\n * nodes (dangling refs) are skipped. Framework-agnostic; use a binding\n * (e.g. @genetik/renderer-react) to map ResolvedNode to UI components.\n *\n * Accepts either a content object or a JSON string (parsed with parseContentJson).\n * Returns null if content is invalid JSON, the entry node is missing, or resolution fails.\n */\nexport function resolve(\n content: GenetikContent | string,\n schema: GenetikSchema,\n): ResolvedNode | null {\n let parsed: GenetikContent | null;\n if (typeof content === \"string\") {\n const result = parseContentJson(content);\n parsed = result.ok ? result.content : null;\n } else {\n parsed = content;\n }\n if (!parsed) return null;\n const root = parsed.nodes[parsed.entryId];\n if (!root) return null;\n return resolveNode(parsed, schema, root);\n}\n\nfunction resolveNode(\n content: GenetikContent,\n schema: GenetikSchema,\n node: ContentNode\n): ResolvedNode {\n const blockType = getBlockType(schema, node.block);\n const slots: Record<string, ResolvedNode[]> = {};\n\n if (blockType) {\n for (const slotDef of blockType.slots) {\n const value = node[slotDef.name];\n const ids = slotValueToIds(value);\n const children: ResolvedNode[] = [];\n for (const id of ids) {\n const child = content.nodes[id];\n if (child) {\n children.push(resolveNode(content, schema, child));\n }\n }\n slots[slotDef.name] = children;\n }\n }\n\n return {\n id: node.id,\n block: node.block,\n config: node.config,\n slots,\n };\n}\n\nfunction slotValueToIds(value: unknown): string[] {\n if (value === undefined || value === null) return [];\n if (typeof value === \"string\") return [value];\n if (Array.isArray(value)) return value.filter((v): v is string => typeof v === \"string\");\n return [];\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,SAAgB,QACd,SACA,QACqB;CACrB,IAAI;AACJ,KAAI,OAAO,YAAY,UAAU;EAC/B,MAAM,SAAS,iBAAiB,QAAQ;AACxC,WAAS,OAAO,KAAK,OAAO,UAAU;OAEtC,UAAS;AAEX,KAAI,CAAC,OAAQ,QAAO;CACpB,MAAM,OAAO,OAAO,MAAM,OAAO;AACjC,KAAI,CAAC,KAAM,QAAO;AAClB,QAAO,YAAY,QAAQ,QAAQ,KAAK;;AAG1C,SAAS,YACP,SACA,QACA,MACc;CACd,MAAM,YAAY,aAAa,QAAQ,KAAK,MAAM;CAClD,MAAM,QAAwC,EAAE;AAEhD,KAAI,UACF,MAAK,MAAM,WAAW,UAAU,OAAO;EACrC,MAAM,QAAQ,KAAK,QAAQ;EAC3B,MAAM,MAAM,eAAe,MAAM;EACjC,MAAM,WAA2B,EAAE;AACnC,OAAK,MAAM,MAAM,KAAK;GACpB,MAAM,QAAQ,QAAQ,MAAM;AAC5B,OAAI,MACF,UAAS,KAAK,YAAY,SAAS,QAAQ,MAAM,CAAC;;AAGtD,QAAM,QAAQ,QAAQ;;AAI1B,QAAO;EACL,IAAI,KAAK;EACT,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb;EACD;;AAGH,SAAS,eAAe,OAA0B;AAChD,KAAI,UAAU,UAAa,UAAU,KAAM,QAAO,EAAE;AACpD,KAAI,OAAO,UAAU,SAAU,QAAO,CAAC,MAAM;AAC7C,KAAI,MAAM,QAAQ,MAAM,CAAE,QAAO,MAAM,QAAQ,MAAmB,OAAO,MAAM,SAAS;AACxF,QAAO,EAAE"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@genetik/renderer",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.mjs",
10
+ "types": "./dist/index.d.mts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.mjs",
14
+ "require": "./dist/index.cjs",
15
+ "types": "./dist/index.d.mts"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "dependencies": {
22
+ "@genetik/content": "0.0.0",
23
+ "@genetik/schema": "0.0.0"
24
+ },
25
+ "devDependencies": {
26
+ "eslint": "^9.39.1",
27
+ "tsdown": "0.20.3",
28
+ "typescript": "5.9.2",
29
+ "vitest": "^2.1.8",
30
+ "@genetik/eslint-config": "0.0.0",
31
+ "@genetik/typescript-config": "0.0.0"
32
+ },
33
+ "engines": {
34
+ "node": ">=18"
35
+ },
36
+ "license": "MIT",
37
+ "scripts": {
38
+ "build": "tsdown",
39
+ "dev": "tsdown --watch",
40
+ "lint": "eslint . --max-warnings 0",
41
+ "check-types": "tsc --noEmit",
42
+ "test": "vitest run",
43
+ "test:watch": "vitest"
44
+ }
45
+ }