@fluixi/template-runtime 0.1.0-alpha.3 → 0.1.0-alpha.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/dist/cdn/fluixi.global.js +4 -1
- package/dist/classify.cjs +99 -1
- package/dist/classify.mjs +78 -1
- package/dist/index.cjs +219 -1
- package/dist/index.mjs +189 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +7 -6
package/dist/classify.cjs
CHANGED
|
@@ -1 +1,99 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/classify.ts
|
|
21
|
+
var classify_exports = {};
|
|
22
|
+
__export(classify_exports, {
|
|
23
|
+
classify: () => classify
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(classify_exports);
|
|
26
|
+
function attrHoles(attr, out) {
|
|
27
|
+
switch (attr.kind) {
|
|
28
|
+
case "Attribute":
|
|
29
|
+
if (attr.value && attr.value.kind === "hole") out.set(attr.value.hole, "attr");
|
|
30
|
+
else if (attr.value && attr.value.kind === "mixed") {
|
|
31
|
+
for (const part of attr.value.parts) {
|
|
32
|
+
if ("hole" in part) out.set(part.hole, "attr");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return;
|
|
36
|
+
case "PropertyBinding":
|
|
37
|
+
out.set(attr.hole, "attr");
|
|
38
|
+
return;
|
|
39
|
+
// bindPair() wants the signal itself, so this one is never called.
|
|
40
|
+
case "BindDirective":
|
|
41
|
+
out.set(attr.hole, "bind");
|
|
42
|
+
return;
|
|
43
|
+
case "EventBinding":
|
|
44
|
+
out.set(attr.hole, "event");
|
|
45
|
+
return;
|
|
46
|
+
case "RefBinding":
|
|
47
|
+
out.set(attr.hole, "ref");
|
|
48
|
+
return;
|
|
49
|
+
case "Spread":
|
|
50
|
+
out.set(attr.hole, "spread");
|
|
51
|
+
return;
|
|
52
|
+
case "IfDirective":
|
|
53
|
+
out.set(attr.hole, "control");
|
|
54
|
+
return;
|
|
55
|
+
case "EachDirective":
|
|
56
|
+
out.set(attr.hole, "control");
|
|
57
|
+
if (attr.key && "hole" in attr.key) out.set(attr.key.hole, "attr");
|
|
58
|
+
return;
|
|
59
|
+
default:
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function walk(nodes, out, tags) {
|
|
64
|
+
for (const node of nodes) {
|
|
65
|
+
switch (node.kind) {
|
|
66
|
+
case "Expression":
|
|
67
|
+
if (!out.has(node.hole)) out.set(node.hole, "text");
|
|
68
|
+
break;
|
|
69
|
+
case "Element":
|
|
70
|
+
case "Component": {
|
|
71
|
+
if (node.kind === "Component") {
|
|
72
|
+
if (node.tagHole !== null) out.set(node.tagHole, "component");
|
|
73
|
+
else if (node.tag) tags.add(node.tag.split(".")[0]);
|
|
74
|
+
}
|
|
75
|
+
const repeats = node.attributes.some((a) => a.kind === "EachDirective");
|
|
76
|
+
for (const attr of node.attributes) attrHoles(attr, out);
|
|
77
|
+
if (repeats) {
|
|
78
|
+
for (const child of node.children) {
|
|
79
|
+
if (child.kind === "Expression") out.set(child.hole, "render");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
walk(node.children, out, tags);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
case "Root":
|
|
86
|
+
case "Fragment":
|
|
87
|
+
walk(node.children, out, tags);
|
|
88
|
+
break;
|
|
89
|
+
default:
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function classify(parsed) {
|
|
95
|
+
const holes = /* @__PURE__ */ new Map();
|
|
96
|
+
const components = /* @__PURE__ */ new Set();
|
|
97
|
+
walk(parsed.root.children, holes, components);
|
|
98
|
+
return { holes, components };
|
|
99
|
+
}
|
package/dist/classify.mjs
CHANGED
|
@@ -1 +1,78 @@
|
|
|
1
|
-
|
|
1
|
+
// src/classify.ts
|
|
2
|
+
function attrHoles(attr, out) {
|
|
3
|
+
switch (attr.kind) {
|
|
4
|
+
case "Attribute":
|
|
5
|
+
if (attr.value && attr.value.kind === "hole") out.set(attr.value.hole, "attr");
|
|
6
|
+
else if (attr.value && attr.value.kind === "mixed") {
|
|
7
|
+
for (const part of attr.value.parts) {
|
|
8
|
+
if ("hole" in part) out.set(part.hole, "attr");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return;
|
|
12
|
+
case "PropertyBinding":
|
|
13
|
+
out.set(attr.hole, "attr");
|
|
14
|
+
return;
|
|
15
|
+
// bindPair() wants the signal itself, so this one is never called.
|
|
16
|
+
case "BindDirective":
|
|
17
|
+
out.set(attr.hole, "bind");
|
|
18
|
+
return;
|
|
19
|
+
case "EventBinding":
|
|
20
|
+
out.set(attr.hole, "event");
|
|
21
|
+
return;
|
|
22
|
+
case "RefBinding":
|
|
23
|
+
out.set(attr.hole, "ref");
|
|
24
|
+
return;
|
|
25
|
+
case "Spread":
|
|
26
|
+
out.set(attr.hole, "spread");
|
|
27
|
+
return;
|
|
28
|
+
case "IfDirective":
|
|
29
|
+
out.set(attr.hole, "control");
|
|
30
|
+
return;
|
|
31
|
+
case "EachDirective":
|
|
32
|
+
out.set(attr.hole, "control");
|
|
33
|
+
if (attr.key && "hole" in attr.key) out.set(attr.key.hole, "attr");
|
|
34
|
+
return;
|
|
35
|
+
default:
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function walk(nodes, out, tags) {
|
|
40
|
+
for (const node of nodes) {
|
|
41
|
+
switch (node.kind) {
|
|
42
|
+
case "Expression":
|
|
43
|
+
if (!out.has(node.hole)) out.set(node.hole, "text");
|
|
44
|
+
break;
|
|
45
|
+
case "Element":
|
|
46
|
+
case "Component": {
|
|
47
|
+
if (node.kind === "Component") {
|
|
48
|
+
if (node.tagHole !== null) out.set(node.tagHole, "component");
|
|
49
|
+
else if (node.tag) tags.add(node.tag.split(".")[0]);
|
|
50
|
+
}
|
|
51
|
+
const repeats = node.attributes.some((a) => a.kind === "EachDirective");
|
|
52
|
+
for (const attr of node.attributes) attrHoles(attr, out);
|
|
53
|
+
if (repeats) {
|
|
54
|
+
for (const child of node.children) {
|
|
55
|
+
if (child.kind === "Expression") out.set(child.hole, "render");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
walk(node.children, out, tags);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case "Root":
|
|
62
|
+
case "Fragment":
|
|
63
|
+
walk(node.children, out, tags);
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function classify(parsed) {
|
|
71
|
+
const holes = /* @__PURE__ */ new Map();
|
|
72
|
+
const components = /* @__PURE__ */ new Set();
|
|
73
|
+
walk(parsed.root.children, holes, components);
|
|
74
|
+
return { holes, components };
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
classify
|
|
78
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1,219 @@
|
|
|
1
|
-
|
|
1
|
+
/*! @fluixi/template-runtime v0.1.0-alpha.4 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
|
+
define: () => define,
|
|
35
|
+
html: () => html,
|
|
36
|
+
svg: () => svg
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(index_exports);
|
|
39
|
+
var DOM = __toESM(require("@fluixi/dom"), 1);
|
|
40
|
+
var import_reactive = require("@fluixi/reactive");
|
|
41
|
+
var import_compile = require("@fluixi/compiler/compile");
|
|
42
|
+
var import_template_parser = require("@fluixi/template-parser");
|
|
43
|
+
|
|
44
|
+
// src/classify.ts
|
|
45
|
+
function attrHoles(attr, out) {
|
|
46
|
+
switch (attr.kind) {
|
|
47
|
+
case "Attribute":
|
|
48
|
+
if (attr.value && attr.value.kind === "hole") out.set(attr.value.hole, "attr");
|
|
49
|
+
else if (attr.value && attr.value.kind === "mixed") {
|
|
50
|
+
for (const part of attr.value.parts) {
|
|
51
|
+
if ("hole" in part) out.set(part.hole, "attr");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return;
|
|
55
|
+
case "PropertyBinding":
|
|
56
|
+
out.set(attr.hole, "attr");
|
|
57
|
+
return;
|
|
58
|
+
// bindPair() wants the signal itself, so this one is never called.
|
|
59
|
+
case "BindDirective":
|
|
60
|
+
out.set(attr.hole, "bind");
|
|
61
|
+
return;
|
|
62
|
+
case "EventBinding":
|
|
63
|
+
out.set(attr.hole, "event");
|
|
64
|
+
return;
|
|
65
|
+
case "RefBinding":
|
|
66
|
+
out.set(attr.hole, "ref");
|
|
67
|
+
return;
|
|
68
|
+
case "Spread":
|
|
69
|
+
out.set(attr.hole, "spread");
|
|
70
|
+
return;
|
|
71
|
+
case "IfDirective":
|
|
72
|
+
out.set(attr.hole, "control");
|
|
73
|
+
return;
|
|
74
|
+
case "EachDirective":
|
|
75
|
+
out.set(attr.hole, "control");
|
|
76
|
+
if (attr.key && "hole" in attr.key) out.set(attr.key.hole, "attr");
|
|
77
|
+
return;
|
|
78
|
+
default:
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function walk(nodes, out, tags) {
|
|
83
|
+
for (const node of nodes) {
|
|
84
|
+
switch (node.kind) {
|
|
85
|
+
case "Expression":
|
|
86
|
+
if (!out.has(node.hole)) out.set(node.hole, "text");
|
|
87
|
+
break;
|
|
88
|
+
case "Element":
|
|
89
|
+
case "Component": {
|
|
90
|
+
if (node.kind === "Component") {
|
|
91
|
+
if (node.tagHole !== null) out.set(node.tagHole, "component");
|
|
92
|
+
else if (node.tag) tags.add(node.tag.split(".")[0]);
|
|
93
|
+
}
|
|
94
|
+
const repeats = node.attributes.some((a) => a.kind === "EachDirective");
|
|
95
|
+
for (const attr of node.attributes) attrHoles(attr, out);
|
|
96
|
+
if (repeats) {
|
|
97
|
+
for (const child of node.children) {
|
|
98
|
+
if (child.kind === "Expression") out.set(child.hole, "render");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
walk(node.children, out, tags);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
case "Root":
|
|
105
|
+
case "Fragment":
|
|
106
|
+
walk(node.children, out, tags);
|
|
107
|
+
break;
|
|
108
|
+
default:
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function classify(parsed) {
|
|
114
|
+
const holes = /* @__PURE__ */ new Map();
|
|
115
|
+
const components = /* @__PURE__ */ new Set();
|
|
116
|
+
walk(parsed.root.children, holes, components);
|
|
117
|
+
return { holes, components };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/index.ts
|
|
121
|
+
var RUNTIME = {
|
|
122
|
+
...DOM,
|
|
123
|
+
createMemo: import_reactive.createMemo
|
|
124
|
+
};
|
|
125
|
+
var CONTROL_FLOW = [
|
|
126
|
+
"For",
|
|
127
|
+
"Index",
|
|
128
|
+
"Show",
|
|
129
|
+
"Switch",
|
|
130
|
+
"Match",
|
|
131
|
+
"Portal",
|
|
132
|
+
"Dynamic",
|
|
133
|
+
"ErrorBoundary",
|
|
134
|
+
"Suspense"
|
|
135
|
+
];
|
|
136
|
+
var registry = /* @__PURE__ */ new Map();
|
|
137
|
+
function define(components) {
|
|
138
|
+
for (const [name, value] of Object.entries(components)) registry.set(name, value);
|
|
139
|
+
}
|
|
140
|
+
function reads(context) {
|
|
141
|
+
return context === "text" || context === "attr" || context === "control";
|
|
142
|
+
}
|
|
143
|
+
function describe(values, holes) {
|
|
144
|
+
return values.map((value, i) => {
|
|
145
|
+
const context = holes.get(i) ?? "text";
|
|
146
|
+
if (context === "render") {
|
|
147
|
+
return {
|
|
148
|
+
code: `$$v[${i}]`,
|
|
149
|
+
reactive: false,
|
|
150
|
+
arrow: { params: ["$$item"], body: `$$v[${i}]($$item)`, bodyReactive: false }
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
if (typeof value === "function" && reads(context)) {
|
|
154
|
+
return { code: `$$v[${i}]()`, reactive: true };
|
|
155
|
+
}
|
|
156
|
+
return { code: `$$v[${i}]`, reactive: false };
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function resolveComponent(name) {
|
|
160
|
+
if (registry.has(name)) return registry.get(name);
|
|
161
|
+
const global = globalThis[name];
|
|
162
|
+
if (global !== void 0) return global;
|
|
163
|
+
throw new Error(
|
|
164
|
+
`[fluixi] <${name}> is not defined. Pass it as a hole — <\${${name}} /> — or register it with define({ ${name} }).`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
function build(strings, values, svg2) {
|
|
168
|
+
const statics = strings;
|
|
169
|
+
const parsed = (0, import_template_parser.parse)(statics, { svg: svg2 });
|
|
170
|
+
const fatal = parsed.diagnostics.filter((d) => d.severity === "error");
|
|
171
|
+
if (fatal.length > 0) {
|
|
172
|
+
throw new Error(
|
|
173
|
+
`[fluixi] ${svg2 ? "svg" : "html"}\`\`: ${fatal.map((d) => d.message).join("; ")}`
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
const { holes, components } = classify(parsed);
|
|
177
|
+
const { code, imports } = (0, import_compile.compileTemplate)({ statics, holes: describe(values, holes) }, { svg: svg2 });
|
|
178
|
+
const missing = imports.filter((n) => !(n in RUNTIME));
|
|
179
|
+
if (missing.length > 0) {
|
|
180
|
+
throw new Error(`[fluixi] no runtime binding for: ${missing.join(", ")}`);
|
|
181
|
+
}
|
|
182
|
+
const helpers = Array.from(/* @__PURE__ */ new Set([...imports, ...CONTROL_FLOW])).filter(
|
|
183
|
+
(n) => n in RUNTIME
|
|
184
|
+
);
|
|
185
|
+
const tags = Array.from(components).filter((n) => !helpers.includes(n));
|
|
186
|
+
const names = [...helpers, ...tags];
|
|
187
|
+
const factory = new Function(...names, "$$v", `return (${code});`);
|
|
188
|
+
return {
|
|
189
|
+
run: (vals) => factory(
|
|
190
|
+
...helpers.map((n) => RUNTIME[n]),
|
|
191
|
+
...tags.map(resolveComponent),
|
|
192
|
+
vals
|
|
193
|
+
)
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
197
|
+
function shapeOf(values) {
|
|
198
|
+
let shape = "";
|
|
199
|
+
for (const value of values) shape += typeof value === "function" ? "f" : "v";
|
|
200
|
+
return shape;
|
|
201
|
+
}
|
|
202
|
+
function tag(svg2) {
|
|
203
|
+
return (strings, ...values) => {
|
|
204
|
+
let shapes = cache.get(strings);
|
|
205
|
+
if (!shapes) {
|
|
206
|
+
shapes = /* @__PURE__ */ new Map();
|
|
207
|
+
cache.set(strings, shapes);
|
|
208
|
+
}
|
|
209
|
+
const shape = shapeOf(values);
|
|
210
|
+
let compiled = shapes.get(shape);
|
|
211
|
+
if (!compiled) {
|
|
212
|
+
compiled = build(strings, values, svg2);
|
|
213
|
+
shapes.set(shape, compiled);
|
|
214
|
+
}
|
|
215
|
+
return compiled.run(values);
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
var html = tag(false);
|
|
219
|
+
var svg = tag(true);
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,189 @@
|
|
|
1
|
-
|
|
1
|
+
/*! @fluixi/template-runtime v0.1.0-alpha.4 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import * as DOM from "@fluixi/dom";
|
|
5
|
+
import { createMemo } from "@fluixi/reactive";
|
|
6
|
+
import { compileTemplate } from "@fluixi/compiler/compile";
|
|
7
|
+
import { parse } from "@fluixi/template-parser";
|
|
8
|
+
|
|
9
|
+
// src/classify.ts
|
|
10
|
+
function attrHoles(attr, out) {
|
|
11
|
+
switch (attr.kind) {
|
|
12
|
+
case "Attribute":
|
|
13
|
+
if (attr.value && attr.value.kind === "hole") out.set(attr.value.hole, "attr");
|
|
14
|
+
else if (attr.value && attr.value.kind === "mixed") {
|
|
15
|
+
for (const part of attr.value.parts) {
|
|
16
|
+
if ("hole" in part) out.set(part.hole, "attr");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return;
|
|
20
|
+
case "PropertyBinding":
|
|
21
|
+
out.set(attr.hole, "attr");
|
|
22
|
+
return;
|
|
23
|
+
// bindPair() wants the signal itself, so this one is never called.
|
|
24
|
+
case "BindDirective":
|
|
25
|
+
out.set(attr.hole, "bind");
|
|
26
|
+
return;
|
|
27
|
+
case "EventBinding":
|
|
28
|
+
out.set(attr.hole, "event");
|
|
29
|
+
return;
|
|
30
|
+
case "RefBinding":
|
|
31
|
+
out.set(attr.hole, "ref");
|
|
32
|
+
return;
|
|
33
|
+
case "Spread":
|
|
34
|
+
out.set(attr.hole, "spread");
|
|
35
|
+
return;
|
|
36
|
+
case "IfDirective":
|
|
37
|
+
out.set(attr.hole, "control");
|
|
38
|
+
return;
|
|
39
|
+
case "EachDirective":
|
|
40
|
+
out.set(attr.hole, "control");
|
|
41
|
+
if (attr.key && "hole" in attr.key) out.set(attr.key.hole, "attr");
|
|
42
|
+
return;
|
|
43
|
+
default:
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function walk(nodes, out, tags) {
|
|
48
|
+
for (const node of nodes) {
|
|
49
|
+
switch (node.kind) {
|
|
50
|
+
case "Expression":
|
|
51
|
+
if (!out.has(node.hole)) out.set(node.hole, "text");
|
|
52
|
+
break;
|
|
53
|
+
case "Element":
|
|
54
|
+
case "Component": {
|
|
55
|
+
if (node.kind === "Component") {
|
|
56
|
+
if (node.tagHole !== null) out.set(node.tagHole, "component");
|
|
57
|
+
else if (node.tag) tags.add(node.tag.split(".")[0]);
|
|
58
|
+
}
|
|
59
|
+
const repeats = node.attributes.some((a) => a.kind === "EachDirective");
|
|
60
|
+
for (const attr of node.attributes) attrHoles(attr, out);
|
|
61
|
+
if (repeats) {
|
|
62
|
+
for (const child of node.children) {
|
|
63
|
+
if (child.kind === "Expression") out.set(child.hole, "render");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
walk(node.children, out, tags);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case "Root":
|
|
70
|
+
case "Fragment":
|
|
71
|
+
walk(node.children, out, tags);
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function classify(parsed) {
|
|
79
|
+
const holes = /* @__PURE__ */ new Map();
|
|
80
|
+
const components = /* @__PURE__ */ new Set();
|
|
81
|
+
walk(parsed.root.children, holes, components);
|
|
82
|
+
return { holes, components };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/index.ts
|
|
86
|
+
var RUNTIME = {
|
|
87
|
+
...DOM,
|
|
88
|
+
createMemo
|
|
89
|
+
};
|
|
90
|
+
var CONTROL_FLOW = [
|
|
91
|
+
"For",
|
|
92
|
+
"Index",
|
|
93
|
+
"Show",
|
|
94
|
+
"Switch",
|
|
95
|
+
"Match",
|
|
96
|
+
"Portal",
|
|
97
|
+
"Dynamic",
|
|
98
|
+
"ErrorBoundary",
|
|
99
|
+
"Suspense"
|
|
100
|
+
];
|
|
101
|
+
var registry = /* @__PURE__ */ new Map();
|
|
102
|
+
function define(components) {
|
|
103
|
+
for (const [name, value] of Object.entries(components)) registry.set(name, value);
|
|
104
|
+
}
|
|
105
|
+
function reads(context) {
|
|
106
|
+
return context === "text" || context === "attr" || context === "control";
|
|
107
|
+
}
|
|
108
|
+
function describe(values, holes) {
|
|
109
|
+
return values.map((value, i) => {
|
|
110
|
+
const context = holes.get(i) ?? "text";
|
|
111
|
+
if (context === "render") {
|
|
112
|
+
return {
|
|
113
|
+
code: `$$v[${i}]`,
|
|
114
|
+
reactive: false,
|
|
115
|
+
arrow: { params: ["$$item"], body: `$$v[${i}]($$item)`, bodyReactive: false }
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (typeof value === "function" && reads(context)) {
|
|
119
|
+
return { code: `$$v[${i}]()`, reactive: true };
|
|
120
|
+
}
|
|
121
|
+
return { code: `$$v[${i}]`, reactive: false };
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function resolveComponent(name) {
|
|
125
|
+
if (registry.has(name)) return registry.get(name);
|
|
126
|
+
const global = globalThis[name];
|
|
127
|
+
if (global !== void 0) return global;
|
|
128
|
+
throw new Error(
|
|
129
|
+
`[fluixi] <${name}> is not defined. Pass it as a hole — <\${${name}} /> — or register it with define({ ${name} }).`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
function build(strings, values, svg2) {
|
|
133
|
+
const statics = strings;
|
|
134
|
+
const parsed = parse(statics, { svg: svg2 });
|
|
135
|
+
const fatal = parsed.diagnostics.filter((d) => d.severity === "error");
|
|
136
|
+
if (fatal.length > 0) {
|
|
137
|
+
throw new Error(
|
|
138
|
+
`[fluixi] ${svg2 ? "svg" : "html"}\`\`: ${fatal.map((d) => d.message).join("; ")}`
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
const { holes, components } = classify(parsed);
|
|
142
|
+
const { code, imports } = compileTemplate({ statics, holes: describe(values, holes) }, { svg: svg2 });
|
|
143
|
+
const missing = imports.filter((n) => !(n in RUNTIME));
|
|
144
|
+
if (missing.length > 0) {
|
|
145
|
+
throw new Error(`[fluixi] no runtime binding for: ${missing.join(", ")}`);
|
|
146
|
+
}
|
|
147
|
+
const helpers = Array.from(/* @__PURE__ */ new Set([...imports, ...CONTROL_FLOW])).filter(
|
|
148
|
+
(n) => n in RUNTIME
|
|
149
|
+
);
|
|
150
|
+
const tags = Array.from(components).filter((n) => !helpers.includes(n));
|
|
151
|
+
const names = [...helpers, ...tags];
|
|
152
|
+
const factory = new Function(...names, "$$v", `return (${code});`);
|
|
153
|
+
return {
|
|
154
|
+
run: (vals) => factory(
|
|
155
|
+
...helpers.map((n) => RUNTIME[n]),
|
|
156
|
+
...tags.map(resolveComponent),
|
|
157
|
+
vals
|
|
158
|
+
)
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
162
|
+
function shapeOf(values) {
|
|
163
|
+
let shape = "";
|
|
164
|
+
for (const value of values) shape += typeof value === "function" ? "f" : "v";
|
|
165
|
+
return shape;
|
|
166
|
+
}
|
|
167
|
+
function tag(svg2) {
|
|
168
|
+
return (strings, ...values) => {
|
|
169
|
+
let shapes = cache.get(strings);
|
|
170
|
+
if (!shapes) {
|
|
171
|
+
shapes = /* @__PURE__ */ new Map();
|
|
172
|
+
cache.set(strings, shapes);
|
|
173
|
+
}
|
|
174
|
+
const shape = shapeOf(values);
|
|
175
|
+
let compiled = shapes.get(shape);
|
|
176
|
+
if (!compiled) {
|
|
177
|
+
compiled = build(strings, values, svg2);
|
|
178
|
+
shapes.set(shape, compiled);
|
|
179
|
+
}
|
|
180
|
+
return compiled.run(values);
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
var html = tag(false);
|
|
184
|
+
var svg = tag(true);
|
|
185
|
+
export {
|
|
186
|
+
define,
|
|
187
|
+
html,
|
|
188
|
+
svg
|
|
189
|
+
};
|