@atom.io/spa 0.0.1 → 0.0.2
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 +201 -6
- package/README.mdx +62 -1
- package/dist/astro-application.d.ts +1 -1
- package/dist/astro-client.d.ts +1 -1
- package/dist/astro-client.js +6 -3
- package/dist/astro-client.js.map +1 -1
- package/dist/astro-server.js +2 -1
- package/dist/astro-server.js.map +1 -1
- package/dist/astro-shared-BT45auwR.js.map +1 -1
- package/dist/{astro-shared-DkZaqX7L.d.ts → astro-shared-DyzbUi6c.d.ts} +4 -2
- package/dist/astro-shared-DyzbUi6c.d.ts.map +1 -0
- package/dist/astro.d.ts +1 -1
- package/dist/astro.js +1 -1
- package/dist/{core-Dvqm7w2y.js → capabilities-BuZUQpiD.js} +64 -2
- package/dist/capabilities-BuZUQpiD.js.map +1 -0
- package/dist/{core-BhiA9fFi.d.ts → capabilities-yC9TsHDI.d.ts} +20 -2
- package/dist/capabilities-yC9TsHDI.d.ts.map +1 -0
- package/dist/client.min.js +1 -1
- package/dist/development/astro-client.js +6 -3
- package/dist/development/astro-client.js.map +1 -1
- package/dist/development/astro-server.js +2 -1
- package/dist/development/astro-server.js.map +1 -1
- package/dist/development/astro-shared-BT45auwR.js.map +1 -1
- package/dist/development/astro.js +1 -1
- package/dist/development/{core-DB3sQz4h.js → capabilities-DhOJmeoJ.js} +64 -2
- package/dist/development/capabilities-DhOJmeoJ.js.map +1 -0
- package/dist/development/{dom-D9cY6l1R.js → dom-BKc6V_Kz.js} +8 -3
- package/dist/development/dom-BKc6V_Kz.js.map +1 -0
- package/dist/development/index.js +3 -38
- package/dist/development/jsx-runtime.js.map +1 -1
- package/dist/development/konva.js +121 -0
- package/dist/development/konva.js.map +1 -0
- package/dist/development/motion.js +217 -0
- package/dist/development/motion.js.map +1 -0
- package/dist/development/renderer.js +177 -0
- package/dist/development/renderer.js.map +1 -0
- package/dist/development/server.js +3 -2
- package/dist/development/server.js.map +1 -1
- package/dist/development/src-Dh-d6w4y.js +38 -0
- package/dist/development/src-Dh-d6w4y.js.map +1 -0
- package/dist/development/three.js +438 -0
- package/dist/development/three.js.map +1 -0
- package/dist/development/vite-CSHoxzXU.js +240 -0
- package/dist/development/vite-CSHoxzXU.js.map +1 -0
- package/dist/development/vite.js +1 -1
- package/dist/{dom-BR9o9wZW.js → dom-B2rm8o2L.js} +8 -3
- package/dist/dom-B2rm8o2L.js.map +1 -0
- package/dist/index-BdwxmSKg.d.ts +24 -0
- package/dist/index-BdwxmSKg.d.ts.map +1 -0
- package/dist/index.d.ts +4 -24
- package/dist/index.js +3 -38
- package/dist/{jsx-runtime-BzGV18VO.d.ts → jsx-runtime-CZU7F8Qz.d.ts} +6 -4
- package/dist/jsx-runtime-CZU7F8Qz.d.ts.map +1 -0
- package/dist/jsx-runtime.d.ts +2 -2
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/konva.d.ts +32 -0
- package/dist/konva.d.ts.map +1 -0
- package/dist/konva.js +121 -0
- package/dist/konva.js.map +1 -0
- package/dist/motion.d.ts +44 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +217 -0
- package/dist/motion.js.map +1 -0
- package/dist/renderer.d.ts +24 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +177 -0
- package/dist/renderer.js.map +1 -0
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +3 -2
- package/dist/server.js.map +1 -1
- package/dist/size.json +16 -16
- package/dist/src-BZxX4xbU.js +38 -0
- package/dist/src-BZxX4xbU.js.map +1 -0
- package/dist/three.d.ts +110 -0
- package/dist/three.d.ts.map +1 -0
- package/dist/three.js +438 -0
- package/dist/three.js.map +1 -0
- package/dist/vite-CSHoxzXU.js +240 -0
- package/dist/vite-CSHoxzXU.js.map +1 -0
- package/dist/vite.js +1 -1
- package/package.json +56 -11
- package/src/astro-client.ts +1 -0
- package/src/astro-server.ts +1 -0
- package/src/astro-shared.ts +3 -0
- package/src/capabilities.ts +88 -0
- package/src/compiler.ts +251 -178
- package/src/core.ts +11 -0
- package/src/dom.ts +4 -1
- package/src/index.ts +5 -0
- package/src/jsx-runtime.ts +4 -0
- package/src/jsx-types.d.ts +3 -1
- package/src/konva.ts +159 -0
- package/src/motion.ts +406 -0
- package/src/renderer.ts +241 -0
- package/src/server.ts +3 -0
- package/src/three-events.ts +330 -0
- package/src/three.ts +350 -0
- package/dist/astro-shared-DkZaqX7L.d.ts.map +0 -1
- package/dist/core-BhiA9fFi.d.ts.map +0 -1
- package/dist/core-Dvqm7w2y.js.map +0 -1
- package/dist/development/core-DB3sQz4h.js.map +0 -1
- package/dist/development/dom-D9cY6l1R.js.map +0 -1
- package/dist/development/index.js.map +0 -1
- package/dist/development/vite-CQchIQ_-.js +0 -126
- package/dist/development/vite-CQchIQ_-.js.map +0 -1
- package/dist/dom-BR9o9wZW.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/jsx-runtime-BzGV18VO.d.ts.map +0 -1
- package/dist/vite-CQchIQ_-.js +0 -126
- package/dist/vite-CQchIQ_-.js.map +0 -1
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { decode } from "html-entities";
|
|
2
|
+
import MagicString from "magic-string";
|
|
3
|
+
import { parseSync, visitorKeys } from "oxc-parser";
|
|
4
|
+
// src/compiler.ts
|
|
5
|
+
const decodeJsx = (value) => decode(value, {
|
|
6
|
+
level: `html4`,
|
|
7
|
+
scope: `strict`
|
|
8
|
+
});
|
|
9
|
+
/** Match JSX's multiline whitespace rules without reprinting JavaScript. */
|
|
10
|
+
function text(value) {
|
|
11
|
+
const lines = value.split(/\r\n|\n|\r/);
|
|
12
|
+
let last = 0;
|
|
13
|
+
for (let i = 0; i < lines.length; i++) if (/[^ \t]/.test(lines[i])) last = i;
|
|
14
|
+
return lines.map((line, i) => {
|
|
15
|
+
line = line.replace(/\t/g, ` `);
|
|
16
|
+
if (i > 0) line = line.replace(/^ +/, ``);
|
|
17
|
+
if (i < lines.length - 1) line = line.replace(/ +$/, ``);
|
|
18
|
+
return line && i < last ? `${line} ` : line;
|
|
19
|
+
}).join(``);
|
|
20
|
+
}
|
|
21
|
+
function eager(node, allowJsx = false) {
|
|
22
|
+
if (node.type === `ParenthesizedExpression`) return eager(node.expression, allowJsx);
|
|
23
|
+
return node.type === `Literal` || node.type === `FunctionExpression` || node.type === `ArrowFunctionExpression` || allowJsx && (node.type === `JSXElement` || node.type === `JSXFragment`) || node.type === `TemplateLiteral` && node.expressions.length === 0;
|
|
24
|
+
}
|
|
25
|
+
function compile(code, filename) {
|
|
26
|
+
const parsed = parseSync(filename, code, {
|
|
27
|
+
lang: `tsx`,
|
|
28
|
+
preserveParens: true
|
|
29
|
+
});
|
|
30
|
+
if (parsed.errors.length) {
|
|
31
|
+
const error = parsed.errors[0];
|
|
32
|
+
throw new SyntaxError([`${filename}: ${error.message}`, error.codeframe].filter(Boolean).join(`\n`));
|
|
33
|
+
}
|
|
34
|
+
const output = new MagicString(code);
|
|
35
|
+
const parents = /* @__PURE__ */ new WeakMap();
|
|
36
|
+
const identifiers = /* @__PURE__ */ new Set();
|
|
37
|
+
const elements = [];
|
|
38
|
+
const functions = /* @__PURE__ */ new Set();
|
|
39
|
+
function walk(node, parent, outerFunction) {
|
|
40
|
+
if (parent) parents.set(node, parent);
|
|
41
|
+
output.addSourcemapLocation(node.start);
|
|
42
|
+
output.addSourcemapLocation(node.end);
|
|
43
|
+
if (node.type === `Identifier` || node.type === `JSXIdentifier`) identifiers.add(node.name);
|
|
44
|
+
if (!outerFunction && (node.type === `FunctionDeclaration` || node.type === `FunctionExpression` || node.type === `ArrowFunctionExpression`)) outerFunction = node;
|
|
45
|
+
if (node.type === `JSXElement` || node.type === `JSXFragment`) {
|
|
46
|
+
elements.push(node);
|
|
47
|
+
if (outerFunction) functions.add(outerFunction);
|
|
48
|
+
}
|
|
49
|
+
for (const key of visitorKeys[node.type]) {
|
|
50
|
+
const value = node[key];
|
|
51
|
+
if (Array.isArray(value)) {
|
|
52
|
+
for (const child of value) if (child) walk(child, node, outerFunction);
|
|
53
|
+
} else if (value) walk(value, node, outerFunction);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
walk(parsed.program);
|
|
57
|
+
function uid(base) {
|
|
58
|
+
let name = `_${base}`;
|
|
59
|
+
let suffix = 1;
|
|
60
|
+
while (identifiers.has(name)) name = `_${base}${++suffix}`;
|
|
61
|
+
identifiers.add(name);
|
|
62
|
+
return name;
|
|
63
|
+
}
|
|
64
|
+
const create = uid(`spa`);
|
|
65
|
+
const merge = uid(`props`);
|
|
66
|
+
const join = (parts, separator) => parts.flatMap((part, i) => i ? [separator, ...part] : part);
|
|
67
|
+
const expression = (node) => eager(node, true) ? [
|
|
68
|
+
`(`,
|
|
69
|
+
node,
|
|
70
|
+
`)`
|
|
71
|
+
] : [
|
|
72
|
+
`() => (`,
|
|
73
|
+
node,
|
|
74
|
+
`)`
|
|
75
|
+
];
|
|
76
|
+
function tag(node) {
|
|
77
|
+
if (node.type === `JSXNamespacedName`) return JSON.stringify(`${node.namespace.name}:${node.name.name}`);
|
|
78
|
+
if (node.type === `JSXMemberExpression`) return code.slice(node.start, node.end);
|
|
79
|
+
return /^[a-z]/.test(node.name) || node.name.includes(`-`) ? JSON.stringify(node.name) : node.name;
|
|
80
|
+
}
|
|
81
|
+
/** Rewrite syntax around untouched expression spans, including nested JSX. */
|
|
82
|
+
function rewrite(node, parts) {
|
|
83
|
+
let cursor = node.start;
|
|
84
|
+
let replacement = ``;
|
|
85
|
+
for (const part of parts) {
|
|
86
|
+
if (typeof part === `string`) {
|
|
87
|
+
replacement += part;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (cursor < part.start) output.update(cursor, part.start, replacement);
|
|
91
|
+
else output.appendLeft(cursor, replacement);
|
|
92
|
+
cursor = part.end;
|
|
93
|
+
replacement = ``;
|
|
94
|
+
}
|
|
95
|
+
output.update(cursor, node.end, replacement);
|
|
96
|
+
}
|
|
97
|
+
for (const node of elements) {
|
|
98
|
+
const chunks = [];
|
|
99
|
+
let properties = [];
|
|
100
|
+
const flush = () => {
|
|
101
|
+
if (properties.length) chunks.push([
|
|
102
|
+
`{`,
|
|
103
|
+
...join(properties, `, `),
|
|
104
|
+
`}`
|
|
105
|
+
]);
|
|
106
|
+
properties = [];
|
|
107
|
+
};
|
|
108
|
+
if (node.type === `JSXElement`) for (const attribute of node.openingElement.attributes) {
|
|
109
|
+
if (attribute.type === `JSXSpreadAttribute`) {
|
|
110
|
+
flush();
|
|
111
|
+
chunks.push([
|
|
112
|
+
`() => (`,
|
|
113
|
+
attribute.argument,
|
|
114
|
+
`)`
|
|
115
|
+
]);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const key = JSON.stringify(attribute.name.type === `JSXNamespacedName` ? `${attribute.name.namespace.name}:${attribute.name.name.name}` : attribute.name.name);
|
|
119
|
+
const value = attribute.value;
|
|
120
|
+
if (!value) properties.push([`${key}: true`]);
|
|
121
|
+
else if (value.type === `Literal`) properties.push([`${key}: ${JSON.stringify(decodeJsx(value.value))}`]);
|
|
122
|
+
else {
|
|
123
|
+
const expr = value.type === `JSXExpressionContainer` ? value.expression : value;
|
|
124
|
+
properties.push(key === `"key"` || eager(expr) ? [
|
|
125
|
+
`${key}: (`,
|
|
126
|
+
expr,
|
|
127
|
+
`)`
|
|
128
|
+
] : [
|
|
129
|
+
`get ${key}(){ return (`,
|
|
130
|
+
expr,
|
|
131
|
+
`); }`
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const children = [];
|
|
136
|
+
for (const child of node.children) if (child.type === `JSXText`) {
|
|
137
|
+
const value = text(decodeJsx(child.value));
|
|
138
|
+
if (value) children.push([JSON.stringify(value)]);
|
|
139
|
+
} else if (child.type === `JSXElement` || child.type === `JSXFragment`) children.push([child]);
|
|
140
|
+
else if (child.type === `JSXExpressionContainer`) {
|
|
141
|
+
if (child.expression.type !== `JSXEmptyExpression`) children.push(expression(child.expression));
|
|
142
|
+
} else throw new SyntaxError(`${filename}: JSX spread children are unsupported`);
|
|
143
|
+
if (children.length) properties.push([`children: `, ...children.length === 1 ? children[0] : [
|
|
144
|
+
`[`,
|
|
145
|
+
...join(children, `, `),
|
|
146
|
+
`]`
|
|
147
|
+
]]);
|
|
148
|
+
flush();
|
|
149
|
+
const props = node.type === `JSXElement` && node.openingElement.attributes.some((attr) => attr.type === `JSXSpreadAttribute`) ? [
|
|
150
|
+
`${merge}(`,
|
|
151
|
+
...join(chunks, `, `),
|
|
152
|
+
`)`
|
|
153
|
+
] : chunks[0] ?? [`{}`];
|
|
154
|
+
rewrite(node, [
|
|
155
|
+
`${create}(${node.type === `JSXElement` ? tag(node.openingElement.name) : `null`}, `,
|
|
156
|
+
...props,
|
|
157
|
+
`)`
|
|
158
|
+
]);
|
|
159
|
+
}
|
|
160
|
+
const components = /* @__PURE__ */ new Set();
|
|
161
|
+
for (const fn of functions) {
|
|
162
|
+
let node = fn;
|
|
163
|
+
let parent = parents.get(node);
|
|
164
|
+
while (parent?.type === `ParenthesizedExpression`) {
|
|
165
|
+
node = parent;
|
|
166
|
+
parent = parents.get(node);
|
|
167
|
+
}
|
|
168
|
+
if (fn.type === `FunctionDeclaration` && fn.id) components.add(fn.id.name);
|
|
169
|
+
else if (parent?.type === `VariableDeclarator` && parent.id.type === `Identifier`) components.add(parent.id.name);
|
|
170
|
+
else if (parent?.type === `ExportDefaultDeclaration`) {
|
|
171
|
+
const name = uid(`Component`);
|
|
172
|
+
if (fn.type === `FunctionDeclaration`) {
|
|
173
|
+
const token = [...code.slice(fn.start, fn.body.start).matchAll(/\/\*[\s\S]*?\*\/|\/\/[^\r\n]*|\bfunction\b|\*/g)].find((match) => match[0] === (fn.generator ? `*` : `function`));
|
|
174
|
+
output.appendLeft(fn.start + token.index + token[0].length, ` ${name}`);
|
|
175
|
+
} else {
|
|
176
|
+
const prefix = code.slice(parent.start, node.start);
|
|
177
|
+
for (const token of prefix.matchAll(/\/\*[\s\S]*?\*\/|\/\/[^\r\n]*|\b(?:export|default)\b/g)) {
|
|
178
|
+
if (token[0] !== `export` && token[0] !== `default`) continue;
|
|
179
|
+
output.update(parent.start + token.index, parent.start + token.index + token[0].length, token[0] === `export` ? `const ${name} =` : ``);
|
|
180
|
+
}
|
|
181
|
+
output.appendLeft(parent.end, `;\nexport default ${name};`);
|
|
182
|
+
}
|
|
183
|
+
components.add(name);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (elements.length) {
|
|
187
|
+
let position = parsed.program.hashbang?.end ?? 0;
|
|
188
|
+
for (const statement of parsed.program.body) {
|
|
189
|
+
if (statement.type !== `ExpressionStatement` || !statement.directive) break;
|
|
190
|
+
position = statement.end;
|
|
191
|
+
}
|
|
192
|
+
output.appendLeft(position, `\nimport { jsx as ${create}, merge as ${merge} } from "@atom.io/spa/jsx-runtime";\n`);
|
|
193
|
+
for (const component of components) output.append(`\n;${component}.spa = true;`);
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
code: output.toString(),
|
|
197
|
+
map: output.generateMap({
|
|
198
|
+
source: filename,
|
|
199
|
+
includeContent: true,
|
|
200
|
+
hires: true
|
|
201
|
+
})
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
// src/vite.ts
|
|
205
|
+
function spa(options = {}) {
|
|
206
|
+
const include = options.include ?? /\.[jt]sx$/;
|
|
207
|
+
const matches = (id) => {
|
|
208
|
+
include.lastIndex = 0;
|
|
209
|
+
return !id.includes(`/node_modules/`) && include.test(id.split(`?`)[0]);
|
|
210
|
+
};
|
|
211
|
+
return {
|
|
212
|
+
name: `spa`,
|
|
213
|
+
enforce: `pre`,
|
|
214
|
+
config() {
|
|
215
|
+
return {
|
|
216
|
+
resolve: { dedupe: [`@atom.io/spa`, `atom.io`] },
|
|
217
|
+
optimizeDeps: { exclude: [`@atom.io/spa`, `atom.io`] }
|
|
218
|
+
};
|
|
219
|
+
},
|
|
220
|
+
configEnvironment: {
|
|
221
|
+
order: `post`,
|
|
222
|
+
handler(_name, config) {
|
|
223
|
+
if (config.optimizeDeps?.include) config.optimizeDeps.include = config.optimizeDeps.include.filter((id) => !/^(@atom\.io\/spa|atom\.io)(\/|$)/.test(id));
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
transform(code, id) {
|
|
227
|
+
if (!matches(id)) return;
|
|
228
|
+
return compile(code, id);
|
|
229
|
+
},
|
|
230
|
+
handleHotUpdate({ server, file }) {
|
|
231
|
+
if (matches(file)) {
|
|
232
|
+
server.ws.send({ type: `full-reload` });
|
|
233
|
+
return [];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
export { spa as t };
|
|
239
|
+
|
|
240
|
+
//# sourceMappingURL=vite-CSHoxzXU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-CSHoxzXU.js","names":[],"sources":["../src/compiler.ts","../src/vite.ts"],"sourcesContent":["import { decode } from \"html-entities\"\nimport type { SourceMap } from \"magic-string\"\nimport MagicString from \"magic-string\"\nimport type {\n\tExpression,\n\tJSXElement,\n\tJSXElementName,\n\tJSXFragment,\n\tNode,\n} from \"oxc-parser\"\nimport { parseSync, visitorKeys } from \"oxc-parser\"\n\ntype Part = string | Node\n\nconst decodeJsx = (value: string): string =>\n\tdecode(value, { level: `html4`, scope: `strict` })\n\n/** Match JSX's multiline whitespace rules without reprinting JavaScript. */\nfunction text(value: string): string {\n\tconst lines = value.split(/\\r\\n|\\n|\\r/)\n\tlet last = 0\n\tfor (let i = 0; i < lines.length; i++) if (/[^ \\t]/.test(lines[i])) last = i\n\treturn lines\n\t\t.map((line, i) => {\n\t\t\tline = line.replace(/\\t/g, ` `)\n\t\t\tif (i > 0) line = line.replace(/^ +/, ``)\n\t\t\tif (i < lines.length - 1) line = line.replace(/ +$/, ``)\n\t\t\treturn line && i < last ? `${line} ` : line\n\t\t})\n\t\t.join(``)\n}\n\nfunction eager(node: Node, allowJsx = false): boolean {\n\tif (node.type === `ParenthesizedExpression`)\n\t\treturn eager(node.expression, allowJsx)\n\treturn (\n\t\tnode.type === `Literal` ||\n\t\tnode.type === `FunctionExpression` ||\n\t\tnode.type === `ArrowFunctionExpression` ||\n\t\t(allowJsx && (node.type === `JSXElement` || node.type === `JSXFragment`)) ||\n\t\t(node.type === `TemplateLiteral` && node.expressions.length === 0)\n\t)\n}\n\nexport function compile(\n\tcode: string,\n\tfilename: string,\n): { code: string; map: SourceMap } {\n\tconst parsed = parseSync(filename, code, {\n\t\tlang: `tsx`,\n\t\tpreserveParens: true,\n\t})\n\tif (parsed.errors.length) {\n\t\tconst error = parsed.errors[0]\n\t\tthrow new SyntaxError(\n\t\t\t[`${filename}: ${error.message}`, error.codeframe]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(`\\n`),\n\t\t)\n\t}\n\tconst output = new MagicString(code)\n\tconst parents = new WeakMap<Node, Node>()\n\tconst identifiers = new Set<string>()\n\tconst elements: (JSXElement | JSXFragment)[] = []\n\tconst functions = new Set<Node>()\n\tfunction walk(node: Node, parent?: Node, outerFunction?: Node): void {\n\t\tif (parent) parents.set(node, parent)\n\t\toutput.addSourcemapLocation(node.start)\n\t\toutput.addSourcemapLocation(node.end)\n\t\tif (node.type === `Identifier` || node.type === `JSXIdentifier`)\n\t\t\tidentifiers.add(node.name)\n\t\tif (\n\t\t\t!outerFunction &&\n\t\t\t(node.type === `FunctionDeclaration` ||\n\t\t\t\tnode.type === `FunctionExpression` ||\n\t\t\t\tnode.type === `ArrowFunctionExpression`)\n\t\t)\n\t\t\touterFunction = node\n\t\tif (node.type === `JSXElement` || node.type === `JSXFragment`) {\n\t\t\telements.push(node)\n\t\t\tif (outerFunction) functions.add(outerFunction)\n\t\t}\n\t\tfor (const key of visitorKeys[node.type]) {\n\t\t\tconst value = (node as unknown as Record<string, unknown>)[key]\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tfor (const child of value) if (child) walk(child, node, outerFunction)\n\t\t\t} else if (value) walk(value as Node, node, outerFunction)\n\t\t}\n\t}\n\twalk(parsed.program)\n\tfunction uid(base: string): string {\n\t\tlet name = `_${base}`\n\t\tlet suffix = 1\n\t\twhile (identifiers.has(name)) name = `_${base}${++suffix}`\n\t\tidentifiers.add(name)\n\t\treturn name\n\t}\n\tconst create = uid(`spa`)\n\tconst merge = uid(`props`)\n\tconst join = (parts: Part[][], separator: string): Part[] =>\n\t\tparts.flatMap((part, i) => (i ? [separator, ...part] : part))\n\tconst expression = (node: Expression): Part[] =>\n\t\teager(node, true) ? [`(`, node, `)`] : [`() => (`, node, `)`]\n\tfunction tag(node: JSXElementName): string {\n\t\tif (node.type === `JSXNamespacedName`)\n\t\t\treturn JSON.stringify(`${node.namespace.name}:${node.name.name}`)\n\t\tif (node.type === `JSXMemberExpression`)\n\t\t\treturn code.slice(node.start, node.end)\n\t\treturn /^[a-z]/.test(node.name) || node.name.includes(`-`)\n\t\t\t? JSON.stringify(node.name)\n\t\t\t: node.name\n\t}\n\t/** Rewrite syntax around untouched expression spans, including nested JSX. */\n\tfunction rewrite(node: JSXElement | JSXFragment, parts: Part[]): void {\n\t\tlet cursor = node.start\n\t\tlet replacement = ``\n\t\tfor (const part of parts) {\n\t\t\tif (typeof part === `string`) {\n\t\t\t\treplacement += part\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (cursor < part.start) output.update(cursor, part.start, replacement)\n\t\t\telse output.appendLeft(cursor, replacement)\n\t\t\tcursor = part.end\n\t\t\treplacement = ``\n\t\t}\n\t\t// Every JSX node ends with closing syntax after its last expression span.\n\t\toutput.update(cursor, node.end, replacement)\n\t}\n\tfor (const node of elements) {\n\t\tconst chunks: Part[][] = []\n\t\tlet properties: Part[][] = []\n\t\tconst flush = () => {\n\t\t\tif (properties.length) chunks.push([`{`, ...join(properties, `, `), `}`])\n\t\t\tproperties = []\n\t\t}\n\t\tif (node.type === `JSXElement`) {\n\t\t\tfor (const attribute of node.openingElement.attributes) {\n\t\t\t\tif (attribute.type === `JSXSpreadAttribute`) {\n\t\t\t\t\tflush()\n\t\t\t\t\tchunks.push([`() => (`, attribute.argument, `)`])\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst key = JSON.stringify(\n\t\t\t\t\tattribute.name.type === `JSXNamespacedName`\n\t\t\t\t\t\t? `${attribute.name.namespace.name}:${attribute.name.name.name}`\n\t\t\t\t\t\t: attribute.name.name,\n\t\t\t\t)\n\t\t\t\tconst value = attribute.value\n\t\t\t\tif (!value) properties.push([`${key}: true`])\n\t\t\t\telse if (value.type === `Literal`)\n\t\t\t\t\tproperties.push([`${key}: ${JSON.stringify(decodeJsx(value.value))}`])\n\t\t\t\telse {\n\t\t\t\t\tconst expr =\n\t\t\t\t\t\tvalue.type === `JSXExpressionContainer` ? value.expression : value\n\t\t\t\t\tproperties.push(\n\t\t\t\t\t\tkey === `\"key\"` || eager(expr)\n\t\t\t\t\t\t\t? [`${key}: (`, expr, `)`]\n\t\t\t\t\t\t\t: [`get ${key}(){ return (`, expr, `); }`],\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tconst children: Part[][] = []\n\t\tfor (const child of node.children) {\n\t\t\tif (child.type === `JSXText`) {\n\t\t\t\tconst value = text(decodeJsx(child.value))\n\t\t\t\tif (value) children.push([JSON.stringify(value)])\n\t\t\t} else if (child.type === `JSXElement` || child.type === `JSXFragment`)\n\t\t\t\tchildren.push([child])\n\t\t\telse if (child.type === `JSXExpressionContainer`) {\n\t\t\t\tif (child.expression.type !== `JSXEmptyExpression`)\n\t\t\t\t\tchildren.push(expression(child.expression))\n\t\t\t} else\n\t\t\t\tthrow new SyntaxError(`${filename}: JSX spread children are unsupported`)\n\t\t}\n\t\tif (children.length)\n\t\t\tproperties.push([\n\t\t\t\t`children: `,\n\t\t\t\t...(children.length === 1\n\t\t\t\t\t? children[0]\n\t\t\t\t\t: [`[`, ...join(children, `, `), `]`]),\n\t\t\t])\n\t\tflush()\n\t\tconst spreads =\n\t\t\tnode.type === `JSXElement` &&\n\t\t\tnode.openingElement.attributes.some(\n\t\t\t\t(attr) => attr.type === `JSXSpreadAttribute`,\n\t\t\t)\n\t\tconst props = spreads\n\t\t\t? [`${merge}(`, ...join(chunks, `, `), `)`]\n\t\t\t: (chunks[0] ?? [`{}`])\n\t\trewrite(node, [\n\t\t\t`${create}(${node.type === `JSXElement` ? tag(node.openingElement.name) : `null`}, `,\n\t\t\t...props,\n\t\t\t`)`,\n\t\t])\n\t}\n\tconst components = new Set<string>()\n\tfor (const fn of functions) {\n\t\tlet node = fn\n\t\tlet parent = parents.get(node)\n\t\twhile (parent?.type === `ParenthesizedExpression`) {\n\t\t\tnode = parent\n\t\t\tparent = parents.get(node)\n\t\t}\n\t\tif (fn.type === `FunctionDeclaration` && fn.id) components.add(fn.id.name)\n\t\telse if (\n\t\t\tparent?.type === `VariableDeclarator` &&\n\t\t\tparent.id.type === `Identifier`\n\t\t)\n\t\t\tcomponents.add(parent.id.name)\n\t\telse if (parent?.type === `ExportDefaultDeclaration`) {\n\t\t\tconst name = uid(`Component`)\n\t\t\tif (fn.type === `FunctionDeclaration`) {\n\t\t\t\t// Keep anonymous default function declarations hoisted.\n\t\t\t\tconst token = [\n\t\t\t\t\t...code\n\t\t\t\t\t\t.slice(fn.start, fn.body!.start)\n\t\t\t\t\t\t.matchAll(/\\/\\*[\\s\\S]*?\\*\\/|\\/\\/[^\\r\\n]*|\\bfunction\\b|\\*/g),\n\t\t\t\t].find((match) => match[0] === (fn.generator ? `*` : `function`))!\n\t\t\t\toutput.appendLeft(fn.start + token.index + token[0].length, ` ${name}`)\n\t\t\t} else {\n\t\t\t\t// Replace only keywords so intervening comments and annotations survive.\n\t\t\t\tconst prefix = code.slice(parent.start, node.start)\n\t\t\t\tfor (const token of prefix.matchAll(\n\t\t\t\t\t/\\/\\*[\\s\\S]*?\\*\\/|\\/\\/[^\\r\\n]*|\\b(?:export|default)\\b/g,\n\t\t\t\t)) {\n\t\t\t\t\tif (token[0] !== `export` && token[0] !== `default`) continue\n\t\t\t\t\toutput.update(\n\t\t\t\t\t\tparent.start + token.index,\n\t\t\t\t\t\tparent.start + token.index + token[0].length,\n\t\t\t\t\t\ttoken[0] === `export` ? `const ${name} =` : ``,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\toutput.appendLeft(parent.end, `;\\nexport default ${name};`)\n\t\t\t}\n\t\t\tcomponents.add(name)\n\t\t}\n\t}\n\tif (elements.length) {\n\t\t// Keep hashbangs and directive prologues ahead of generated imports.\n\t\tlet position = parsed.program.hashbang?.end ?? 0\n\t\tfor (const statement of parsed.program.body) {\n\t\t\tif (statement.type !== `ExpressionStatement` || !statement.directive) break\n\t\t\tposition = statement.end\n\t\t}\n\t\toutput.appendLeft(\n\t\t\tposition,\n\t\t\t`\\nimport { jsx as ${create}, merge as ${merge} } from \"@atom.io/spa/jsx-runtime\";\\n`,\n\t\t)\n\t\tfor (const component of components)\n\t\t\toutput.append(`\\n;${component}.spa = true;`)\n\t}\n\treturn {\n\t\tcode: output.toString(),\n\t\tmap: output.generateMap({\n\t\t\tsource: filename,\n\t\t\tincludeContent: true,\n\t\t\thires: true,\n\t\t}),\n\t}\n}\n","import type { Plugin } from \"vite\"\n\nimport { compile } from \"./compiler.ts\"\n\nexport interface SpaPluginOptions {\n\tinclude?: RegExp\n}\nexport default function spa(options: SpaPluginOptions = {}): Plugin {\n\tconst include = options.include ?? /\\.[jt]sx$/\n\tconst matches = (id: string): boolean => {\n\t\tinclude.lastIndex = 0\n\t\treturn !id.includes(`/node_modules/`) && include.test(id.split(`?`)[0])\n\t}\n\treturn {\n\t\tname: `spa`,\n\t\tenforce: `pre`,\n\t\tconfig() {\n\t\t\treturn {\n\t\t\t\tresolve: { dedupe: [`@atom.io/spa`, `atom.io`] },\n\t\t\t\toptimizeDeps: { exclude: [`@atom.io/spa`, `atom.io`] },\n\t\t\t}\n\t\t},\n\t\tconfigEnvironment: {\n\t\t\torder: `post`,\n\t\t\thandler(_name, config) {\n\t\t\t\t// Astro and its adapters force renderer entries into the optimizer.\n\t\t\t\t// Vite processes explicit includes even when their package is excluded.\n\t\t\t\t// Keep the renderer, hooks, and store in one unbundled module graph.\n\t\t\t\tif (config.optimizeDeps?.include) {\n\t\t\t\t\tconfig.optimizeDeps.include = config.optimizeDeps.include.filter(\n\t\t\t\t\t\t(id) => !/^(@atom\\.io\\/spa|atom\\.io)(\\/|$)/.test(id),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\ttransform(code, id) {\n\t\t\tif (!matches(id)) return\n\t\t\treturn compile(code, id)\n\t\t},\n\t\t// A reload disposes the whole document. No state-preserving HMR is promised.\n\t\thandleHotUpdate({ server, file }) {\n\t\t\tif (matches(file)) {\n\t\t\t\tserver.ws.send({ type: `full-reload` })\n\t\t\t\treturn []\n\t\t\t}\n\t\t},\n\t}\n}\n"],"mappings":";;;;AAcA,MAAM,aAAa,UAClB,OAAO,OAAO;CAAE,OAAO;CAAS,OAAO;AAAS,CAAC;;AAGlD,SAAS,KAAK,OAAuB;CACpC,MAAM,QAAQ,MAAM,MAAM,YAAY;CACtC,IAAI,OAAO;CACX,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,IAAI,SAAS,KAAK,MAAM,EAAE,GAAG,OAAO;CAC3E,OAAO,MACL,KAAK,MAAM,MAAM;EACjB,OAAO,KAAK,QAAQ,OAAO,GAAG;EAC9B,IAAI,IAAI,GAAG,OAAO,KAAK,QAAQ,OAAO,EAAE;EACxC,IAAI,IAAI,MAAM,SAAS,GAAG,OAAO,KAAK,QAAQ,OAAO,EAAE;EACvD,OAAO,QAAQ,IAAI,OAAO,GAAG,KAAK,KAAK;CACxC,CAAC,CAAC,CACD,KAAK,EAAE;AACV;AAEA,SAAS,MAAM,MAAY,WAAW,OAAgB;CACrD,IAAI,KAAK,SAAS,2BACjB,OA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B,OAAO;GACP,QAAQ,OAAO,QAAQ;IAItB,IAAI,OAAO,cAAc,SACxB,OAAO,aAAa,UAAU,OAAO,aAAa,QAAQ,QACxD,OAAO,CAAC,mCAAmC,KAAK,EAAE,CACpD;GAEF;EACD;EACA,UAAU,MAAM,IAAI;GACnB,IAAI,CAAC,QAAQ,EAAE,GAAG;GAClB,OAAO,QAAQ,MAAM,EAAE;EACxB;EAEA,gBAAgB,EAAE,QAAQ,QAAQ;GACjC,IAAI,QAAQ,IAAI,GAAG;IAClB,OAAO,GAAG,KAAK,EAAE,MAAM,cAAc,CAAC;IACtC,OAAO,CAAC;GACT;EACD;CACD;AACD"}
|
package/dist/vite.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as default } from "./vite-
|
|
1
|
+
export { t as default } from "./vite-CSHoxzXU.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atom.io/spa",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "An atom.io-driven JSX renderer.",
|
|
5
5
|
"homepage": "https://atom.io.fyi/docs/spa",
|
|
6
6
|
"repository": {
|
|
@@ -63,6 +63,26 @@
|
|
|
63
63
|
"types": "./dist/astro-application.d.ts",
|
|
64
64
|
"development": "./dist/development/astro-application.js",
|
|
65
65
|
"import": "./dist/astro-application.js"
|
|
66
|
+
},
|
|
67
|
+
"./renderer": {
|
|
68
|
+
"types": "./dist/renderer.d.ts",
|
|
69
|
+
"development": "./dist/development/renderer.js",
|
|
70
|
+
"import": "./dist/renderer.js"
|
|
71
|
+
},
|
|
72
|
+
"./konva": {
|
|
73
|
+
"types": "./dist/konva.d.ts",
|
|
74
|
+
"development": "./dist/development/konva.js",
|
|
75
|
+
"import": "./dist/konva.js"
|
|
76
|
+
},
|
|
77
|
+
"./three": {
|
|
78
|
+
"types": "./dist/three.d.ts",
|
|
79
|
+
"development": "./dist/development/three.js",
|
|
80
|
+
"import": "./dist/three.js"
|
|
81
|
+
},
|
|
82
|
+
"./motion": {
|
|
83
|
+
"types": "./dist/motion.d.ts",
|
|
84
|
+
"development": "./dist/development/motion.js",
|
|
85
|
+
"import": "./dist/motion.js"
|
|
66
86
|
}
|
|
67
87
|
},
|
|
68
88
|
"main": "./dist/index.js",
|
|
@@ -72,36 +92,58 @@
|
|
|
72
92
|
"src"
|
|
73
93
|
],
|
|
74
94
|
"dependencies": {
|
|
75
|
-
"
|
|
95
|
+
"html-entities": "2.6.0",
|
|
96
|
+
"magic-string": "1.4.5",
|
|
97
|
+
"oxc-parser": "0.157.0"
|
|
76
98
|
},
|
|
77
99
|
"devDependencies": {
|
|
78
100
|
"@breakage/changesets": "0.1.0",
|
|
79
|
-
"@
|
|
101
|
+
"@jridgewell/trace-mapping": "0.3.31",
|
|
80
102
|
"@types/node": "26.6.6",
|
|
81
|
-
"@
|
|
82
|
-
"
|
|
103
|
+
"@types/three": "0.187.0",
|
|
104
|
+
"@vitest/coverage-v8": "5.1.0",
|
|
105
|
+
"astro": "7.4.5",
|
|
83
106
|
"atom.io": "0.54.3",
|
|
84
107
|
"breakage": "0.10.1",
|
|
85
108
|
"esbuild": "0.28.2",
|
|
86
|
-
"eslint": "10.
|
|
109
|
+
"eslint": "10.14.0",
|
|
87
110
|
"happy-dom": "21.0.4",
|
|
111
|
+
"konva": "10.9.1",
|
|
112
|
+
"motion": "14.9.0",
|
|
88
113
|
"playwright": "1.64.1",
|
|
89
|
-
"preact": "11.1.
|
|
114
|
+
"preact": "11.1.1",
|
|
90
115
|
"rolldown": "1.2.16",
|
|
116
|
+
"three": "0.187.0",
|
|
91
117
|
"tsdown": "0.23.4",
|
|
92
118
|
"typescript": "7.0.2",
|
|
93
119
|
"vite": "8.3.5",
|
|
94
|
-
"vitest": "5.0
|
|
120
|
+
"vitest": "5.1.0"
|
|
95
121
|
},
|
|
96
122
|
"peerDependencies": {
|
|
123
|
+
"@types/three": "^0.187.0",
|
|
97
124
|
"astro": "^7.4.2",
|
|
98
125
|
"atom.io": "^0.54.1",
|
|
126
|
+
"konva": "^10.9.1",
|
|
127
|
+
"motion": "^14.9.0",
|
|
128
|
+
"three": "^0.187.0",
|
|
99
129
|
"vite": "^8.3.5"
|
|
100
130
|
},
|
|
101
131
|
"peerDependenciesMeta": {
|
|
132
|
+
"@types/three": {
|
|
133
|
+
"optional": true
|
|
134
|
+
},
|
|
102
135
|
"astro": {
|
|
103
136
|
"optional": true
|
|
104
137
|
},
|
|
138
|
+
"konva": {
|
|
139
|
+
"optional": true
|
|
140
|
+
},
|
|
141
|
+
"motion": {
|
|
142
|
+
"optional": true
|
|
143
|
+
},
|
|
144
|
+
"three": {
|
|
145
|
+
"optional": true
|
|
146
|
+
},
|
|
105
147
|
"vite": {
|
|
106
148
|
"optional": true
|
|
107
149
|
}
|
|
@@ -118,15 +160,18 @@
|
|
|
118
160
|
"pack:breakage": "pnpm --reporter=silent pack --out .breakage/package.tgz",
|
|
119
161
|
"test:breakage:peers": "breakage npm check",
|
|
120
162
|
"test": "vitest",
|
|
121
|
-
"test:once": "vitest run --config vitest.config.ts && pnpm test:consumer",
|
|
163
|
+
"test:once": "vitest run --config vitest.config.ts && pnpm test:consumer && pnpm test:optional-peers",
|
|
122
164
|
"test:consumer": "node __tests__/fixtures/consumer/check.ts",
|
|
123
165
|
"test:production": "node scripts/production-test.ts",
|
|
124
|
-
"test:browser": "astro build --root __tests__/astro && node scripts/browser-test.mjs && node scripts/dev-browser-test.mjs",
|
|
166
|
+
"test:browser": "astro build --root __tests__/astro && node scripts/browser-test.mjs && node scripts/dev-browser-test.mjs && node scripts/graphics-browser-test.mjs",
|
|
125
167
|
"test:browser:dev": "node scripts/dev-browser-test.mjs",
|
|
126
168
|
"cov": "vitest run --config vitest.config.ts --coverage",
|
|
127
169
|
"readme:write": "galley write README.mdx",
|
|
128
170
|
"readme:check": "galley check README.mdx",
|
|
129
171
|
"tonnage": "pnpm readme:write",
|
|
130
|
-
"tonnage:check": "pnpm readme:check"
|
|
172
|
+
"tonnage:check": "pnpm readme:check",
|
|
173
|
+
"test:browser:graphics": "node scripts/graphics-browser-test.mjs",
|
|
174
|
+
"test:optional-peers": "node scripts/optional-peers-check.mjs && node __tests__/fixtures/graphics-consumer/check.ts",
|
|
175
|
+
"bench:compiler": "node scripts/compiler-benchmark.ts"
|
|
131
176
|
}
|
|
132
177
|
}
|
package/src/astro-client.ts
CHANGED
|
@@ -107,6 +107,7 @@ export default (element: HTMLElement): Hydrator =>
|
|
|
107
107
|
if (replace) element.replaceChildren()
|
|
108
108
|
const root = (replace ? render : hydrate)(mount, element, {
|
|
109
109
|
store: store!,
|
|
110
|
+
capabilities: component.capabilities ?? [],
|
|
110
111
|
})
|
|
111
112
|
lifetime.context.onCleanup(root.dispose)
|
|
112
113
|
update = (next) => {
|
package/src/astro-server.ts
CHANGED
package/src/astro-shared.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RootStore } from "atom.io/internal"
|
|
2
2
|
import { IMPLICIT, Store } from "atom.io/internal"
|
|
3
3
|
|
|
4
|
+
import type { Capability } from "./capabilities.ts"
|
|
4
5
|
import type { Component, VNode } from "./core.ts"
|
|
5
6
|
import { jsx } from "./jsx-runtime.ts"
|
|
6
7
|
|
|
@@ -33,6 +34,8 @@ export type AstroStorePreparation<P = Record<string, any>> = (
|
|
|
33
34
|
) => void | Promise<void>
|
|
34
35
|
export type Island<P = any> = Component<P> & {
|
|
35
36
|
spa?: boolean
|
|
37
|
+
/** Capabilities are scoped to this island root on the server and client. */
|
|
38
|
+
capabilities?: readonly Capability[]
|
|
36
39
|
/** Opt into a private island store instead of the shared application store. */
|
|
37
40
|
isolate?: boolean
|
|
38
41
|
createStore?: AstroStoreFactory<P>
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Cleanup, Scope } from "./core.ts"
|
|
2
|
+
|
|
3
|
+
/** Native renderers expose property access without importing capability engines. */
|
|
4
|
+
export interface CapabilityTarget {
|
|
5
|
+
kind: string
|
|
6
|
+
node: unknown
|
|
7
|
+
read?(key: string): unknown
|
|
8
|
+
write?(key: string, value: unknown): void
|
|
9
|
+
listen?(event: string, listener: () => void): Cleanup
|
|
10
|
+
}
|
|
11
|
+
export interface CapabilityBinding {
|
|
12
|
+
update(props: Record<string, unknown>): void
|
|
13
|
+
dispose(): void
|
|
14
|
+
}
|
|
15
|
+
export interface Capability {
|
|
16
|
+
namespace: string
|
|
17
|
+
scheduleFrame?(callback: (time: number) => void): Cleanup
|
|
18
|
+
attach(target: CapabilityTarget): CapabilityBinding
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function capabilityNamespace(key: string): string | undefined {
|
|
22
|
+
const colon = key.indexOf(`:`)
|
|
23
|
+
if (colon < 0) return undefined
|
|
24
|
+
const namespace = key.slice(0, colon)
|
|
25
|
+
return /^(xml|xmlns|xlink)$/.test(namespace) ? undefined : namespace
|
|
26
|
+
}
|
|
27
|
+
export function validateCapabilities(
|
|
28
|
+
scope: Scope,
|
|
29
|
+
props: Record<string, unknown>,
|
|
30
|
+
): void {
|
|
31
|
+
for (const key of Object.keys(props)) {
|
|
32
|
+
const namespace = capabilityNamespace(key)
|
|
33
|
+
if (namespace && !scope._root._capabilities.has(namespace))
|
|
34
|
+
throw new Error(
|
|
35
|
+
`spa: capability "${namespace}" is not registered for this root`,
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Separate framework properties from native attributes and own their bindings. */
|
|
41
|
+
export function capabilityProps(
|
|
42
|
+
scope: Scope,
|
|
43
|
+
target: CapabilityTarget,
|
|
44
|
+
): (props: Record<string, any>) => Record<string, any> {
|
|
45
|
+
const bindings = new Map<string, CapabilityBinding>()
|
|
46
|
+
const cleanup: Cleanup = () => {
|
|
47
|
+
const errors: unknown[] = []
|
|
48
|
+
for (const binding of [...bindings.values()].reverse()) {
|
|
49
|
+
try {
|
|
50
|
+
binding.dispose()
|
|
51
|
+
} catch (error) {
|
|
52
|
+
errors.push(error)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
bindings.clear()
|
|
56
|
+
if (errors.length) throw new AggregateError(errors)
|
|
57
|
+
}
|
|
58
|
+
scope._cleanups.add(cleanup)
|
|
59
|
+
return (props) => {
|
|
60
|
+
validateCapabilities(scope, props)
|
|
61
|
+
const native: Record<string, any> = {}
|
|
62
|
+
const groups = new Map<string, Record<string, unknown>>()
|
|
63
|
+
for (const key of Object.keys(props)) {
|
|
64
|
+
const namespace = capabilityNamespace(key)
|
|
65
|
+
if (!namespace) {
|
|
66
|
+
native[key] = props[key]
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
const group = groups.get(namespace) ?? {}
|
|
70
|
+
group[key.slice(namespace.length + 1)] = props[key]
|
|
71
|
+
groups.set(namespace, group)
|
|
72
|
+
}
|
|
73
|
+
for (const [namespace, values] of groups) {
|
|
74
|
+
let binding = bindings.get(namespace)
|
|
75
|
+
if (!binding) {
|
|
76
|
+
binding = scope._root._capabilities.get(namespace)!.attach(target)
|
|
77
|
+
bindings.set(namespace, binding)
|
|
78
|
+
}
|
|
79
|
+
binding.update(values)
|
|
80
|
+
}
|
|
81
|
+
for (const [namespace, binding] of bindings)
|
|
82
|
+
if (!groups.has(namespace)) {
|
|
83
|
+
bindings.delete(namespace)
|
|
84
|
+
binding.dispose()
|
|
85
|
+
}
|
|
86
|
+
return native
|
|
87
|
+
}
|
|
88
|
+
}
|