obix-template 0.2.1

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 ADDED
@@ -0,0 +1,34 @@
1
+ # obix-template
2
+
3
+ **Pure semantic template analysis for OBIX.**
4
+
5
+ ```bash
6
+ npm install obix-template
7
+ ```
8
+
9
+ ## Purpose
10
+
11
+ | Export | Role |
12
+ |---|---|
13
+ | `analyzeBindings(root)` | `BindingDescriptor[]` — text / attr / bool / aria / conditional, each with a child-index `path` |
14
+ | `analyzeEvents(root)` | `EventDescriptor[]` — every `on:event="Action"` |
15
+ | `analyzeTemplate(root)` | `TemplateDescriptor` = root + bindings + events |
16
+ | `extractDependencies(expr)` | root identifier(s) an expression reads |
17
+ | `resolveBinding(expr, scope)` | evaluate an identifier / dotted path against a flat scope |
18
+ | `bindingScope(state, props, derived)` | build that flat scope (derived > state > props) |
19
+
20
+ ## Constraints
21
+
22
+ - **No JavaScript parsing.** Level 0 binding expressions are identifiers or
23
+ dotted paths.
24
+ - **No DOM.** Returns plain descriptors; `obix-adapter-native` and
25
+ `obix-adapter-ssr` decide what to do with them.
26
+
27
+ ## Dependency role
28
+
29
+ Depends only on `obix-spec`. Consumed by `obix-compiler`,
30
+ `obix-accessibility` and `obix-language-server`.
31
+
32
+ ## Level 0 status
33
+
34
+ ✅ Complete for the Level 0 binding set.
@@ -0,0 +1,8 @@
1
+ import type { TemplateElement, TemplateDescriptor, BindingDescriptor, EventDescriptor } from "obix-spec";
2
+ export declare function extractDependencies(expr: string): string[];
3
+ export declare function analyzeBindings(root: TemplateElement): BindingDescriptor[];
4
+ export declare function analyzeEvents(root: TemplateElement): EventDescriptor[];
5
+ export declare function analyzeTemplate(root: TemplateElement): TemplateDescriptor;
6
+ export declare function resolveBinding(expr: string, scope: Record<string, unknown>): unknown;
7
+ export declare function bindingScope(state: Record<string, unknown>, props: Record<string, unknown>, derived: Record<string, unknown>): Record<string, unknown>;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EAChB,MAAM,WAAW,CAAC;AAKnB,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAI1D;AAGD,wBAAgB,eAAe,CAAC,IAAI,EAAE,eAAe,GAAG,iBAAiB,EAAE,CAwB1E;AAGD,wBAAgB,aAAa,CAAC,IAAI,EAAE,eAAe,GAAG,eAAe,EAAE,CAWtE;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,eAAe,GAAG,kBAAkB,CAEzE;AAOD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAQpF;AAGD,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzB"}
package/dist/index.js ADDED
@@ -0,0 +1,78 @@
1
+ const PATH = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/;
2
+ export function extractDependencies(expr) {
3
+ const e = expr.trim();
4
+ if (!PATH.test(e))
5
+ return [];
6
+ return [e.split(".")[0]];
7
+ }
8
+ export function analyzeBindings(root) {
9
+ const out = [];
10
+ walk(root, [], (node, path) => {
11
+ if (node.kind === "interpolation") {
12
+ out.push({ kind: "text", target: "", expr: node.expr, deps: extractDependencies(node.expr), path });
13
+ return;
14
+ }
15
+ if (node.kind !== "element")
16
+ return;
17
+ for (const attr of node.attrs) {
18
+ if (attr.directive === "event")
19
+ continue;
20
+ if (attr.directive === "conditional") {
21
+ const expr = (attr.value ?? "").trim();
22
+ out.push({ kind: "conditional", target: "", expr, deps: extractDependencies(expr), path });
23
+ continue;
24
+ }
25
+ if (!attr.interpolation)
26
+ continue;
27
+ const expr = attr.interpolation;
28
+ const deps = extractDependencies(expr);
29
+ if (attr.directive === "aria")
30
+ out.push({ kind: "aria", target: attr.name, expr, deps, path });
31
+ else if (attr.directive === "bool")
32
+ out.push({ kind: "bool", target: attr.name, expr, deps, path });
33
+ else
34
+ out.push({ kind: "attr", target: attr.name, expr, deps, path });
35
+ }
36
+ });
37
+ return out;
38
+ }
39
+ export function analyzeEvents(root) {
40
+ const out = [];
41
+ walk(root, [], (node, path) => {
42
+ if (node.kind !== "element")
43
+ return;
44
+ for (const attr of node.attrs) {
45
+ if (attr.directive === "event" && attr.value) {
46
+ out.push({ event: attr.name.slice(3), action: attr.value, path });
47
+ }
48
+ }
49
+ });
50
+ return out;
51
+ }
52
+ export function analyzeTemplate(root) {
53
+ return { root, bindings: analyzeBindings(root), events: analyzeEvents(root) };
54
+ }
55
+ export function resolveBinding(expr, scope) {
56
+ const parts = expr.trim().split(".");
57
+ let cur = scope[parts[0]];
58
+ for (let i = 1; i < parts.length; i++) {
59
+ if (cur == null)
60
+ return undefined;
61
+ cur = cur[parts[i]];
62
+ }
63
+ return cur;
64
+ }
65
+ export function bindingScope(state, props, derived) {
66
+ return { ...props, ...state, ...derived };
67
+ }
68
+ function walk(node, path, visit) {
69
+ visit(node, path);
70
+ node.children.forEach((child, i) => {
71
+ const childPath = [...path, i];
72
+ if (child.kind === "element")
73
+ walk(child, childPath, visit);
74
+ else
75
+ visit(child, childPath);
76
+ });
77
+ }
78
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,MAAM,IAAI,GAAG,2CAA2C,CAAC;AAGzD,MAAM,UAAU,mBAAmB,CAAC,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,EAAE,SAAS,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "obix-template",
3
+ "version": "0.2.1",
4
+ "description": "Pure semantic template analysis for OBIX: binding + event descriptor construction and dependency extraction. No JS parsing, no DOM. Depends only on obix-spec.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "private": false,
8
+ "sideEffects": false,
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ },
16
+ "./package.json": "./package.json"
17
+ },
18
+ "files": ["dist", "README.md", "LICENSE"],
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json"
21
+ },
22
+ "dependencies": {
23
+ "obix-spec": "0.2.1"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "engines": {
29
+ "node": ">=20.11.0"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/obinexusmk2/obix-monorepo-2026.git",
34
+ "directory": "packages/obix-template"
35
+ }
36
+ }