@stillflow/engine 0.0.0-stage → 1.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.
Files changed (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +156 -3
  3. package/dist/index.cjs.js +1051 -0
  4. package/dist/index.d.ts +9 -0
  5. package/dist/index.es.js +1023 -0
  6. package/dist/jsx-runtime.d.ts +43 -0
  7. package/dist/lib-DUuDpiwh.js +11975 -0
  8. package/dist/lib-lWz8P7iq.cjs +11979 -0
  9. package/dist/stillflow/abstracts/IR.d.ts +7 -0
  10. package/dist/stillflow/abstracts/meta.d.ts +8 -0
  11. package/dist/stillflow/abstracts/operators.d.ts +22 -0
  12. package/dist/stillflow/abstracts/state.d.ts +13 -0
  13. package/dist/stillflow/abstracts/view.d.ts +8 -0
  14. package/dist/stillflow/compiler/compile.d.ts +11 -0
  15. package/dist/stillflow/compiler/instantiate.d.ts +3 -0
  16. package/dist/stillflow/factories/factories.d.ts +10 -0
  17. package/dist/stillflow/index.d.ts +5 -0
  18. package/dist/stillflow/kernel/buffer.d.ts +10 -0
  19. package/dist/stillflow/kernel/kernel.d.ts +26 -0
  20. package/dist/stillflow/kernel/signal.d.ts +5 -0
  21. package/dist/stillflow/operators.d.ts +15 -0
  22. package/dist/stillflow/state.d.ts +15 -0
  23. package/dist/stillflow/stillflow.d.ts +28 -0
  24. package/dist/stillflow/tools/batcher.d.ts +9 -0
  25. package/dist/stillflow/variable.d.ts +12 -0
  26. package/dist/stillflow-collection/abstract/collection.delta.d.ts +10 -0
  27. package/dist/stillflow-collection/abstract/collection.flusher.d.ts +17 -0
  28. package/dist/stillflow-collection/abstract/collection.glee.d.ts +28 -0
  29. package/dist/stillflow-collection/abstract/collection.index.d.ts +9 -0
  30. package/dist/stillflow-collection/abstract/collection.logical.d.ts +13 -0
  31. package/dist/stillflow-collection/abstract/collection.physical.d.ts +13 -0
  32. package/dist/stillflow-collection/abstract/collection.serializable.d.ts +4 -0
  33. package/dist/stillflow-collection/array.d.ts +21 -0
  34. package/dist/stillflow-collection/fenwick.d.ts +28 -0
  35. package/dist/stillflow-collection/flushable.d.ts +38 -0
  36. package/dist/stillflow-collection/index.d.ts +6 -0
  37. package/dist/stillflow-collection/utilities/disjointed-set.d.ts +10 -0
  38. package/dist/stillflow-collection/utilities/fenwick-tree.d.ts +9 -0
  39. package/dist/stillflow-collection/utilities/index.d.ts +1 -0
  40. package/dist/stillflow-collection/utilities/interval-merger.d.ts +7 -0
  41. package/dist/stillflow-collection/utilities/range-fenwick-tree.d.ts +11 -0
  42. package/dist/stillflow-runtime/dom.d.ts +5 -0
  43. package/dist/stillflow-runtime/utilities/delegate-event.d.ts +1 -0
  44. package/dist/stillflow-runtime/utilities/index.d.ts +3 -0
  45. package/dist/stillflow-runtime/utilities/reconcile-if.d.ts +10 -0
  46. package/dist/stillflow-runtime/utilities/reconcile-list.d.ts +8 -0
  47. package/dist/stillflow-serialize/deserialize.d.ts +2 -0
  48. package/dist/stillflow-serialize/index.d.ts +2 -0
  49. package/dist/stillflow-serialize/serialize.d.ts +2 -0
  50. package/dist/stillflow-serialize/serialized.d.ts +4 -0
  51. package/dist/stillflow-vite/dom.pass.codegen.d.ts +8 -0
  52. package/dist/stillflow-vite/dom.pass.transform.d.ts +16 -0
  53. package/dist/stillflow-vite/dom.target.d.ts +2 -0
  54. package/dist/stillflow-vite/targets.plugin.d.ts +9 -0
  55. package/dist/stillflow-vite/vm-abstract/index.d.ts +3 -0
  56. package/dist/stillflow-vite/vm-abstract/vm.instruction.d.ts +7 -0
  57. package/dist/stillflow-vite/vm-abstract/vm.options.d.ts +4 -0
  58. package/dist/stillflow-vite/vm-abstract/vm.target.d.ts +23 -0
  59. package/dist/stillflow-vite/vm-compiler/bytecode-builder.d.ts +33 -0
  60. package/dist/stillflow-vite/vm-compiler/codes.d.ts +20 -0
  61. package/dist/stillflow-vite/vm-compiler/dirty.d.ts +7 -0
  62. package/dist/stillflow-vite/vm-compiler/fabric.d.ts +9 -0
  63. package/dist/stillflow-vite/vm-compiler/index.d.ts +8 -0
  64. package/dist/stillflow-vite/vm-compiler/nodes.d.ts +72 -0
  65. package/dist/stillflow-vite/vm-compiler/pass.analyze-dirty.d.ts +3 -0
  66. package/dist/stillflow-vite/vm-compiler/pass.analyze-dynamic.d.ts +2 -0
  67. package/dist/stillflow-vite/vm-compiler/pass.lowering.d.ts +4 -0
  68. package/dist/stillflow-vite/vm-compiler/pass.scopes.d.ts +14 -0
  69. package/dist/stillflow-vite/vm-targets/collect-components.d.ts +8 -0
  70. package/dist/stillflow-vite/vm-targets/collect-imports.d.ts +3 -0
  71. package/dist/stillflow-vite/vm-targets/find-component.d.ts +3 -0
  72. package/dist/targets.index.d.ts +1 -0
  73. package/dist/vite.cjs.js +261 -0
  74. package/dist/vite.es.js +260 -0
  75. package/dist/vite.plugin.d.ts +3 -0
  76. package/dist/vm.instruction-DPuxu4sV.cjs +9 -0
  77. package/dist/vm.instruction-oyM-GI-p.js +4 -0
  78. package/dist/vms.cjs.js +1096 -0
  79. package/dist/vms.es.js +1095 -0
  80. package/package.json +99 -5
@@ -0,0 +1,260 @@
1
+ import { generate, transformAsync, types } from "@babel/core";
2
+ // src/stillflow-vite/vm-targets/collect-components.ts
3
+ function get_function_body(node) {
4
+ const body = node.body;
5
+ if (types.isBlockStatement(body)) return body.body;
6
+ return [types.toBlock(body)];
7
+ }
8
+ function filter_parameters(nodes) {
9
+ const params = [];
10
+ const defaults = {};
11
+ for (const param of nodes) if (types.isIdentifier(param)) params.push(param.name);
12
+ else if (types.isAssignmentPattern(param)) {
13
+ if (types.isIdentifier(param.left)) defaults[param.left.name] = generate(param.right).code;
14
+ else throw new Error(`Identifier expected at ${param.loc.filename} ${param.loc.start.line}:${param.loc.start.column}`);
15
+ } else throw new Error(`Identifier or assignment pattern expected at ${param.loc.filename} ${param.loc.start.line}:${param.loc.start.column}`);
16
+ return {
17
+ ids: params,
18
+ defaults
19
+ };
20
+ }
21
+ function get_return_argument(node) {
22
+ const statement = get_function_body(node).find((statement) => types.isReturnStatement(statement));
23
+ if (!statement || !statement.argument) {
24
+ if (types.isArrowFunctionExpression(node)) return node.body;
25
+ return null;
26
+ }
27
+ return statement.argument;
28
+ }
29
+ function collect_components(program_path, state) {
30
+ const components = /* @__PURE__ */ new Map();
31
+ const filename = state.filename || "unknown";
32
+ program_path.traverse({
33
+ FunctionDeclaration(path) {
34
+ if (!path.node.id) return;
35
+ const argument = get_return_argument(path.node);
36
+ if (!types.isJSXElement(argument)) return;
37
+ components.set(path.node.id.name, {
38
+ node: path.node,
39
+ parameters: filter_parameters(path.node.params),
40
+ body: argument,
41
+ filename,
42
+ scope: path.scope
43
+ });
44
+ },
45
+ VariableDeclarator(path) {
46
+ if (!types.isIdentifier(path.node.id)) return;
47
+ if (!(types.isFunctionExpression(path.node.init) || types.isArrowFunctionExpression(path.node.init))) return;
48
+ const initializer = path.node.init;
49
+ const argument = get_return_argument(initializer);
50
+ if (!types.isJSXElement(argument)) return;
51
+ components.set(path.node.id.name, {
52
+ node: initializer,
53
+ parameters: filter_parameters(initializer.params),
54
+ body: argument,
55
+ filename,
56
+ scope: path.scope
57
+ });
58
+ }
59
+ });
60
+ return components;
61
+ }
62
+ // src/stillflow-vite/vm-targets/collect-imports.ts
63
+ function collect_imports(program_path) {
64
+ const imports = /* @__PURE__ */ new Map();
65
+ program_path.traverse({ ImportDeclaration(path) {
66
+ const source = path.node.source.value;
67
+ for (const specifier of path.node.specifiers) if (types.isImportDefaultSpecifier(specifier)) imports.set(specifier.local.name, {
68
+ source,
69
+ imported_name: "default",
70
+ is_default: true
71
+ });
72
+ else if (types.isImportSpecifier(specifier)) imports.set(specifier.local.name, {
73
+ source,
74
+ imported_name: types.isIdentifier(specifier.imported) ? specifier.imported.name : specifier.imported.value,
75
+ is_default: false
76
+ });
77
+ else if (types.isImportNamespaceSpecifier(specifier)) throw new Error(`Does not support import namespaces`);
78
+ } });
79
+ return imports;
80
+ }
81
+ // src/stillflow-vite/vm-targets/find-component.ts
82
+ function find_component(ast, name, filename) {
83
+ let result = null;
84
+ types.traverseFast(ast, (node) => {
85
+ if (result) return;
86
+ if (types.isExportDefaultDeclaration(node)) {
87
+ const declaration = node.declaration;
88
+ if (types.isFunctionDeclaration(declaration)) {
89
+ if (declaration.id) {
90
+ const argument = get_return_argument(declaration);
91
+ if (types.isJSXElement(argument)) result = {
92
+ node: declaration,
93
+ parameters: filter_parameters(declaration.params),
94
+ body: argument,
95
+ filename,
96
+ scope: null
97
+ };
98
+ }
99
+ } else if (types.isArrowFunctionExpression(declaration)) {
100
+ const argument = get_return_argument(declaration);
101
+ if (types.isJSXElement(argument)) result = {
102
+ node: declaration,
103
+ parameters: filter_parameters(declaration.params),
104
+ body: argument,
105
+ filename,
106
+ scope: null
107
+ };
108
+ }
109
+ }
110
+ if (types.isExportNamedDeclaration(node)) {
111
+ const declaration = node.declaration;
112
+ if (types.isFunctionDeclaration(declaration)) {
113
+ if (declaration.id?.name === name) {
114
+ const argument = get_return_argument(declaration);
115
+ if (types.isJSXElement(argument)) result = {
116
+ node: declaration,
117
+ parameters: filter_parameters(declaration.params),
118
+ body: argument,
119
+ filename,
120
+ scope: null
121
+ };
122
+ }
123
+ }
124
+ if (types.isVariableDeclaration(declaration)) declaration.declarations.forEach((declaration) => {
125
+ if (result) return;
126
+ const id = declaration.id;
127
+ if (types.isIdentifier(id)) {
128
+ if (name === id.name) {
129
+ const init = declaration.init;
130
+ if (types.isArrowFunctionExpression(init) || types.isFunctionExpression(init)) {
131
+ const argument = get_return_argument(init);
132
+ if (types.isJSXElement(argument)) result = {
133
+ node: init,
134
+ parameters: filter_parameters(init.params),
135
+ body: argument,
136
+ filename,
137
+ scope: null
138
+ };
139
+ }
140
+ }
141
+ }
142
+ });
143
+ }
144
+ });
145
+ return result;
146
+ }
147
+ // src/stillflow-vite/targets.plugin.ts
148
+ function StillflowTargets({ node_module, path, babel, fs, parser }, options) {
149
+ const { existsSync, readFileSync, statSync } = fs;
150
+ const { types } = babel;
151
+ const { parse } = parser;
152
+ const { createRequire } = node_module;
153
+ const require = createRequire(import.meta.url);
154
+ function resolve_import(source, filename) {
155
+ try {
156
+ return require.resolve(source, { paths: [path.dirname(filename)] });
157
+ } catch (error) {
158
+ const base = path.resolve(path.dirname(filename), source);
159
+ const extensions = [
160
+ ".ts",
161
+ ".tsx",
162
+ ".jsx",
163
+ ".js"
164
+ ];
165
+ for (const extension of extensions) {
166
+ const fullname = base + extension;
167
+ if (existsSync(fullname)) return fullname;
168
+ }
169
+ if (existsSync(base) && statSync(base).isDirectory()) for (const extension of extensions) {
170
+ const fullname = path.join(base, `index${extension}`);
171
+ if (existsSync(fullname)) return fullname;
172
+ }
173
+ return error;
174
+ }
175
+ }
176
+ return function StillflowTarget() {
177
+ return {
178
+ name: "stillflow-aot",
179
+ visitor: { Program: { enter(program_path, state) {
180
+ const components = collect_components(program_path, state);
181
+ const imports = collect_imports(program_path);
182
+ const filename = state.filename || "unknown";
183
+ for (const [local_name, import_info] of imports) {
184
+ if (components.has(local_name)) continue;
185
+ const resolved_import = resolve_import(import_info.source, filename);
186
+ if (resolved_import instanceof Error) {
187
+ console.error(`[stillflow] Could not import file "${import_info.source}: "`, resolved_import);
188
+ continue;
189
+ }
190
+ const source = readFileSync(resolved_import, "utf-8");
191
+ const ast = parse(source, {
192
+ sourceType: "module",
193
+ plugins: ["jsx", "typescript"]
194
+ });
195
+ if (ast == null) {
196
+ console.warn(`[stillflow] File is not found: ${resolved_import}`);
197
+ return;
198
+ }
199
+ const component = find_component(ast, import_info.imported_name, resolved_import);
200
+ if (component) components.set(local_name, component);
201
+ }
202
+ const jsx_elements = [];
203
+ program_path.traverse({ CallExpression(path) {
204
+ if (!types.isIdentifier(path.node.callee, { name: "$" })) return;
205
+ const argument = path.node.arguments;
206
+ if (argument.length !== 1) return;
207
+ if (!types.isJSXElement(argument[0])) return;
208
+ const jsx_path = path.get("arguments.0");
209
+ jsx_elements.push(jsx_path);
210
+ } });
211
+ for (const jsx_path of jsx_elements.reverse()) try {
212
+ const call_path = jsx_path.parentPath;
213
+ const program = options.targets[0].main(jsx_path.node, components);
214
+ if (!types.isCallExpression(call_path.node)) continue;
215
+ const functional_module = types.functionExpression(null, [types.identifier("$parent")], types.blockStatement(program.body));
216
+ if (program.module.length > 0) program_path.unshiftContainer("body", program.module);
217
+ call_path.replaceWith(functional_module);
218
+ } catch (error) {
219
+ console.error(`[stillflow] Failed to compile JSX in ${state.filename}: `, error);
220
+ }
221
+ program_path.traverse({ JSXElement(path) {
222
+ path.replaceWith(types.nullLiteral());
223
+ } });
224
+ } } }
225
+ };
226
+ };
227
+ }
228
+ // src/vite.plugin.ts
229
+ function stillflow_plugin(options) {
230
+ return {
231
+ name: "vite-plugin-stillflow",
232
+ enforce: "pre",
233
+ async transform(code, id) {
234
+ if (!(id.endsWith(".tsx") || id.endsWith(".jsx"))) return;
235
+ const node_module = await new Function("return import('node:module')")();
236
+ const parser = await import("./lib-DUuDpiwh.js");
237
+ const babel = await import("@babel/core");
238
+ const path = await new Function("return import('node:path')")();
239
+ const fs = await new Function("return import('node:fs')")();
240
+ const result = await transformAsync(code, {
241
+ filename: id,
242
+ plugins: [StillflowTargets({
243
+ node_module,
244
+ babel,
245
+ parser,
246
+ path,
247
+ fs
248
+ }, options)],
249
+ parserOpts: { plugins: ["jsx", "typescript"] },
250
+ babelrc: false,
251
+ configFile: false
252
+ });
253
+ return {
254
+ code: result?.code ?? code,
255
+ map: result?.map
256
+ };
257
+ }
258
+ };
259
+ }
260
+ export { stillflow_plugin };
@@ -0,0 +1,3 @@
1
+ import { Plugin } from 'vite';
2
+ import { Options } from './stillflow-vite/vm-abstract';
3
+ export declare function stillflow_plugin(options: Options): Plugin;
@@ -0,0 +1,9 @@
1
+ // src/stillflow-vite/vm-abstract/vm.instruction.ts
2
+ var OPCODE_MASK = 0xffffff;
3
+ var unpack_local = (pack) => pack & OPCODE_MASK;
4
+ Object.defineProperty(exports, "unpack_local", {
5
+ enumerable: true,
6
+ get: function() {
7
+ return unpack_local;
8
+ }
9
+ });
@@ -0,0 +1,4 @@
1
+ // src/stillflow-vite/vm-abstract/vm.instruction.ts
2
+ var OPCODE_MASK = 0xffffff;
3
+ var unpack_local = (pack) => pack & OPCODE_MASK;
4
+ export { unpack_local as t };