stillflow.engine 0.4.9 → 0.5.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 (138) hide show
  1. package/README.md +12 -30
  2. package/dist/index.cjs.js +566 -0
  3. package/dist/index.d.ts +4 -5
  4. package/dist/index.es.js +557 -0
  5. package/dist/rolldown-runtime-BW-eSwOZ.cjs +42 -0
  6. package/dist/stillflow/abstracts/meta.d.ts +1 -1
  7. package/dist/stillflow/abstracts/view.d.ts +2 -2
  8. package/dist/stillflow/compiler/compile.d.ts +5 -5
  9. package/dist/stillflow/compiler/instantiate.d.ts +2 -2
  10. package/dist/stillflow/index.d.ts +2 -2
  11. package/dist/stillflow/kernel/buffer.d.ts +1 -1
  12. package/dist/stillflow/kernel/kernel.d.ts +2 -2
  13. package/dist/stillflow/operators.d.ts +1 -1
  14. package/dist/stillflow/state.d.ts +1 -1
  15. package/dist/stillflow/stillflow.d.ts +6 -6
  16. package/dist/stillflow/variable.d.ts +2 -2
  17. package/dist/stillflow-collection/fenwick.d.ts +1 -1
  18. package/dist/stillflow-collection/flushable.d.ts +2 -2
  19. package/dist/stillflow-collection/index.d.ts +3 -3
  20. package/dist/stillflow-collection/utilities/range-fenwick-tree.d.ts +1 -1
  21. package/dist/stillflow-vite/babel-vm/abstract/binding.d.ts +4 -0
  22. package/dist/stillflow-vite/babel-vm/abstract/configurator.d.ts +7 -0
  23. package/dist/stillflow-vite/babel-vm/abstract/generator.d.ts +2 -0
  24. package/dist/stillflow-vite/babel-vm/classes/payload.d.ts +23 -0
  25. package/dist/stillflow-vite/babel-vm/index.d.ts +7 -0
  26. package/dist/stillflow-vite/babel-vm/utilities/build.d.ts +6 -0
  27. package/dist/stillflow-vite/babel-vm/utilities/create.d.ts +11 -0
  28. package/dist/stillflow-vite/dom/build-vm/build.d.ts +4 -0
  29. package/dist/stillflow-vite/dom/build-vm/build.dom.d.ts +6 -0
  30. package/dist/stillflow-vite/dom/build-vm/compile.d.ts +8 -0
  31. package/dist/stillflow-vite/dom/build-vm/markup.d.ts +7 -0
  32. package/dist/stillflow-vite/dom/build-vm/run.d.ts +12 -0
  33. package/dist/stillflow-vite/dom/build-vm/template.d.ts +14 -0
  34. package/dist/stillflow-vite/dom/build-vm/transform.d.ts +10 -0
  35. package/dist/{stillflow-adapters/dom/vm/dom.codes.d.ts → stillflow-vite/dom/directives/codes.d.ts} +1 -2
  36. package/dist/stillflow-vite/dom/directives/generators.d.ts +3 -0
  37. package/dist/stillflow-vite/dom/environment.d.ts +21 -0
  38. package/dist/stillflow-vite/dom/helpers/collectors.d.ts +9 -0
  39. package/dist/stillflow-vite/dom/helpers/extractors.d.ts +11 -0
  40. package/dist/stillflow-vite/dom/helpers/getters.d.ts +7 -0
  41. package/dist/stillflow-vite/dom/helpers/replacers.d.ts +2 -0
  42. package/dist/stillflow-vite/dom/properties/directives.d.ts +16 -0
  43. package/dist/{stillflow-adapters → stillflow-vite}/dom/properties/properties.d.ts +4 -3
  44. package/dist/{stillflow-adapters/dom/vm/dom.types.d.ts → stillflow-vite/dom/properties/types.d.ts} +2 -2
  45. package/dist/{stillflow-adapters/dom/vm/utilities/dom.delegator.d.ts → stillflow-vite/dom/utilities/delegator.d.ts} +1 -0
  46. package/dist/stillflow-vite/dom.plugin.d.ts +2 -0
  47. package/dist/{stillflow-adapters/dom → stillflow-vite/runtime}/jsx.dom.d.ts +20 -14
  48. package/dist/vite.cjs.js +18348 -0
  49. package/dist/vite.es.js +18345 -0
  50. package/dist/vite.plugin.d.ts +2 -0
  51. package/package.json +41 -29
  52. package/dist/index.js +0 -6
  53. package/dist/jsx-runtime.d.ts +0 -3
  54. package/dist/jsx-runtime.js +0 -7
  55. package/dist/stillflow/abstracts/IR.js +0 -1
  56. package/dist/stillflow/abstracts/meta.js +0 -1
  57. package/dist/stillflow/abstracts/operators.js +0 -1
  58. package/dist/stillflow/abstracts/state.js +0 -1
  59. package/dist/stillflow/abstracts/view.js +0 -1
  60. package/dist/stillflow/compiler/compile.js +0 -84
  61. package/dist/stillflow/compiler/instantiate.js +0 -40
  62. package/dist/stillflow/factories/factories.js +0 -20
  63. package/dist/stillflow/index.js +0 -3
  64. package/dist/stillflow/kernel/buffer.js +0 -16
  65. package/dist/stillflow/kernel/kernel.js +0 -44
  66. package/dist/stillflow/kernel/signal.js +0 -12
  67. package/dist/stillflow/operators.js +0 -31
  68. package/dist/stillflow/state.js +0 -12
  69. package/dist/stillflow/stillflow.js +0 -59
  70. package/dist/stillflow/tools/batcher.js +0 -21
  71. package/dist/stillflow/variable.js +0 -24
  72. package/dist/stillflow-adapters/dom/base.dom.d.ts +0 -17
  73. package/dist/stillflow-adapters/dom/base.dom.js +0 -31
  74. package/dist/stillflow-adapters/dom/description/describe.d.ts +0 -3
  75. package/dist/stillflow-adapters/dom/description/describe.js +0 -6
  76. package/dist/stillflow-adapters/dom/jsx.dom.js +0 -98
  77. package/dist/stillflow-adapters/dom/properties/properties.js +0 -1
  78. package/dist/stillflow-adapters/dom/tags.d.ts +0 -7
  79. package/dist/stillflow-adapters/dom/tags.js +0 -5
  80. package/dist/stillflow-adapters/dom/vm/compile/dom.apply.d.ts +0 -3
  81. package/dist/stillflow-adapters/dom/vm/compile/dom.apply.js +0 -10
  82. package/dist/stillflow-adapters/dom/vm/compile/dom.apply.keyed.d.ts +0 -3
  83. package/dist/stillflow-adapters/dom/vm/compile/dom.apply.keyed.js +0 -10
  84. package/dist/stillflow-adapters/dom/vm/compile/dom.compile-vm.d.ts +0 -2
  85. package/dist/stillflow-adapters/dom/vm/compile/dom.compile-vm.js +0 -204
  86. package/dist/stillflow-adapters/dom/vm/compile/dom.compile-vm.keyed.d.ts +0 -2
  87. package/dist/stillflow-adapters/dom/vm/compile/dom.compile-vm.keyed.js +0 -168
  88. package/dist/stillflow-adapters/dom/vm/compile/dom.compile.d.ts +0 -3
  89. package/dist/stillflow-adapters/dom/vm/compile/dom.compile.js +0 -77
  90. package/dist/stillflow-adapters/dom/vm/compile/dom.context.d.ts +0 -13
  91. package/dist/stillflow-adapters/dom/vm/compile/dom.context.js +0 -1
  92. package/dist/stillflow-adapters/dom/vm/compile/dom.markup.d.ts +0 -3
  93. package/dist/stillflow-adapters/dom/vm/compile/dom.markup.js +0 -32
  94. package/dist/stillflow-adapters/dom/vm/dom.codes.js +0 -1
  95. package/dist/stillflow-adapters/dom/vm/dom.directives.d.ts +0 -18
  96. package/dist/stillflow-adapters/dom/vm/dom.directives.js +0 -1
  97. package/dist/stillflow-adapters/dom/vm/dom.symbols.js +0 -18
  98. package/dist/stillflow-adapters/dom/vm/dom.template.d.ts +0 -10
  99. package/dist/stillflow-adapters/dom/vm/dom.template.js +0 -1
  100. package/dist/stillflow-adapters/dom/vm/dom.types.js +0 -1
  101. package/dist/stillflow-adapters/dom/vm/transform/dom.transform.d.ts +0 -3
  102. package/dist/stillflow-adapters/dom/vm/transform/dom.transform.js +0 -54
  103. package/dist/stillflow-adapters/dom/vm/utilities/dom.delegator.js +0 -39
  104. package/dist/stillflow-adapters/dom/vm/utilities/dom.pool.js +0 -46
  105. package/dist/stillflow-adapters/index.d.ts +0 -2
  106. package/dist/stillflow-adapters/index.js +0 -2
  107. package/dist/stillflow-collection/abstract/collection.js +0 -1
  108. package/dist/stillflow-collection/delta.js +0 -18
  109. package/dist/stillflow-collection/fenwick.js +0 -102
  110. package/dist/stillflow-collection/flushable.js +0 -70
  111. package/dist/stillflow-collection/index.js +0 -2
  112. package/dist/stillflow-collection/utilities/disjointed-set.js +0 -45
  113. package/dist/stillflow-collection/utilities/fenwick-tree.js +0 -27
  114. package/dist/stillflow-collection/utilities/interval-merger.js +0 -70
  115. package/dist/stillflow-collection/utilities/range-fenwick-tree.js +0 -28
  116. package/dist/stillflow-examples/app.js +0 -120
  117. package/dist/stillflow-examples/data.js +0 -73
  118. package/dist/stillflow-examples/test.js +0 -32
  119. package/dist/stillflow-scripts/gen-tags.d.ts +0 -1
  120. package/dist/stillflow-scripts/gen-tags.js +0 -50
  121. package/dist/stillflow-vm/abstract/config.d.ts +0 -6
  122. package/dist/stillflow-vm/abstract/config.js +0 -1
  123. package/dist/stillflow-vm/abstract/generator.d.ts +0 -1
  124. package/dist/stillflow-vm/abstract/generator.js +0 -1
  125. package/dist/stillflow-vm/abstract/target.d.ts +0 -7
  126. package/dist/stillflow-vm/abstract/target.js +0 -1
  127. package/dist/stillflow-vm/binding.d.ts +0 -4
  128. package/dist/stillflow-vm/binding.js +0 -1
  129. package/dist/stillflow-vm/create.d.ts +0 -5
  130. package/dist/stillflow-vm/create.js +0 -17
  131. package/dist/stillflow-vm/emitter.js +0 -9
  132. package/dist/stillflow-vm/index.d.ts +0 -6
  133. package/dist/stillflow-vm/index.js +0 -3
  134. package/dist/stillflow-vm/payload.d.ts +0 -9
  135. package/dist/stillflow-vm/payload.js +0 -24
  136. /package/dist/{stillflow-vm → stillflow-vite/babel-vm/classes}/emitter.d.ts +0 -0
  137. /package/dist/{stillflow-adapters/dom/vm/utilities/dom.pool.d.ts → stillflow-vite/dom/utilities/pool.d.ts} +0 -0
  138. /package/dist/{stillflow-adapters/dom/vm/dom.symbols.d.ts → stillflow-vite/dom/utilities/symbols.d.ts} +0 -0
package/README.md CHANGED
@@ -21,20 +21,6 @@ Also I think that **explicit reactivity is better than implicit reactivity**. So
21
21
  3. **Pluggable Collections** --- Built-in Fenwick-based collections for fast clear/remove and Flushable with `flush()` collection for fast `delta` calculations.
22
22
  4. **Headless core** --- The core is completely independent of `DOM`
23
23
  5. **Type-safe JSX** --- Full autocomplete for `DOM` properties and directives (`sf:`)
24
-
25
- ## Benchmarks
26
-
27
- **Stillflow** performs within *3-4% of VanillaJS* in the Krause benchmark on my notepad, while providing a full transactional state model. I run benchmark on JSX and DOM versions of my framework. You can see results below. I explicitly removed benchmark-specific optimizations from the data generation to ensure a completely fair comparison.
28
-
29
- *Note 1*: In specific operations like `remove row`, **Stillflow** is up to 1.8-2x than *VanillaJS* due to its delta-based collection and lazy deletion.
30
-
31
- *Note 2*: The results of jsx version of **Stillflow** is done without micro- or macro- tasks.
32
-
33
- ![Benchmark scores of Stillflow](images/4.png)
34
-
35
- **Stillflow** memory usage score is below
36
-
37
- ![Memory usage of Stillflow](images/m2.png)
38
24
 
39
25
  ## Quick Start
40
26
 
@@ -42,18 +28,10 @@ Also I think that **explicit reactivity is better than implicit reactivity**. So
42
28
 
43
29
  For a starter you can play with [it in **CodeSandBox**](https://codesandbox.io/p/sandbox/stillflow-engine-starter-3qv9mh). Simple demonstration of the features of **Stillflow**.
44
30
 
45
- You can test some benchmarks on [**CodeSandBox**](https://codesandbox.io/p/sandbox/43vn9g). It shows following results:
46
-
47
- | Operation | Dataset Size | Execution Time (State + DOM) |
48
- | :--- | :--- | :--- |
49
- | **Append rows** | 10,000 rows | **~57ms** |
50
- | **Full list swap (sort)** | 10,000 rows | **~40ms max** |
51
- | **Partial random swaps** | 1,000 pairs | **~6-8ms max** |
52
- | **Lazy remove every 2nd row** | 10,000 rows (5k removed) | **~24ms max** |
53
- | **Lazy remove every 2nd row** | 10,000 rows (60k removed) | **~242ms max** ($O(k \log n)$ scaling) |
31
+ You can test some benchmarks on [**CodeSandBox**](https://codesandbox.io/p/sandbox/43vn9g).
54
32
 
55
33
  ```ts
56
- import { core, vm, collection, operators, adapters } from 'stillflow.engine'
34
+ import { core, collections, operators, runtime } from 'stillflow.engine'
57
35
 
58
36
  type AppState = {
59
37
  input: string
@@ -65,20 +43,20 @@ type TodoItem = {
65
43
 
66
44
  type TodoState = {
67
45
  input: string,
68
- items: collection.Flushable<TodoItem>
46
+ items: collections.Flushable<TodoItem>
69
47
  }
70
48
 
71
- const { jsxdom, dom } = adapters
49
+ const { jsxdom, $ } = runtime
72
50
 
73
51
  const state = new core.State()
74
52
  const stillflow = new core.Stillflow<AppState>(state)
75
53
  const factory = stillflow.factory()
76
54
 
77
- factory.add(collection.Flushable.name, () => new collection.Flushable(new collection.Fenwick(100)))
55
+ factory.add(collections.Flushable.name, () => new collections.Flushable(new collections.Fenwick(100)))
78
56
 
79
57
  const source = {
80
58
  input: stillflow.variable('input').backref(),
81
- items: operators.is(collection.Flushable.name)
59
+ items: operators.is(collections.Flushable.name)
82
60
  }
83
61
 
84
62
  const view = stillflow.compile(source)
@@ -115,9 +93,13 @@ function App() {
115
93
  )
116
94
  }
117
95
 
118
- const update = dom.$(<App />, { container: document.body })
96
+ const Fabric = $(<App />)
97
+
98
+ const { app: update, root } = Fabric()
99
+
100
+ stillflow.on(() => update(root, instance))
119
101
 
120
- stillflow.on(() => update(instance))
102
+ document.body.appendChild(root)
121
103
 
122
104
  instance.input = String()
123
105
  stillflow.commit()
@@ -0,0 +1,566 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_rolldown_runtime = require("./rolldown-runtime-BW-eSwOZ.cjs");
3
+ // src/stillflow-collection/delta.js
4
+ function clear_delta(delta) {
5
+ delta.addes = 0;
6
+ delta.swaps.clear();
7
+ delta.updates.clear();
8
+ delta.removes.clear();
9
+ delta.replaces = false;
10
+ delta.clears = false;
11
+ }
12
+ function copy_delta(delta) {
13
+ return {
14
+ addes: delta.addes,
15
+ swaps: new Map(delta.swaps),
16
+ updates: new Set(delta.updates),
17
+ removes: new Set(delta.removes),
18
+ replaces: delta.replaces,
19
+ clears: delta.clears
20
+ };
21
+ }
22
+ // src/stillflow-collection/flushable.ts
23
+ var FlushableCollection = class {
24
+ _base;
25
+ _delta = {
26
+ addes: 0,
27
+ swaps: /* @__PURE__ */ new Map(),
28
+ updates: /* @__PURE__ */ new Set(),
29
+ removes: /* @__PURE__ */ new Set(),
30
+ replaces: false,
31
+ clears: false
32
+ };
33
+ constructor(_base) {
34
+ this._base = _base;
35
+ }
36
+ at(index) {
37
+ return this._base.at(index);
38
+ }
39
+ map(id) {
40
+ return this._base.map(id);
41
+ }
42
+ add(value) {
43
+ this._delta.addes++;
44
+ this._base.add(value);
45
+ }
46
+ set(index, value) {
47
+ this._delta.updates.add(index);
48
+ this._base.set(index, value);
49
+ }
50
+ swap(i, j) {
51
+ this._delta.swaps.set(i, j);
52
+ this._base.swap(i, j);
53
+ }
54
+ attach(value) {
55
+ this._delta.addes += value.length;
56
+ this._base.attach(value);
57
+ }
58
+ mutate(index, mutator) {
59
+ this._delta.updates.add(index);
60
+ this._base.mutate(index, mutator);
61
+ }
62
+ shrink() {
63
+ this._base.shrink();
64
+ }
65
+ mark_cleared() {
66
+ this._delta.clears = true;
67
+ this._base.mark_cleared();
68
+ }
69
+ mark_removed(index) {
70
+ this._delta.removes.add(index);
71
+ this._base.mark_removed(index);
72
+ }
73
+ mark_removed_range(left, right) {
74
+ for (let index = left; index <= right; index++) this._delta.removes.add(index);
75
+ this._base.mark_removed_range(left, right);
76
+ }
77
+ flush() {
78
+ this._delta.replaces = this._delta.addes > 0 && this._delta.clears;
79
+ const delta = copy_delta(this._delta);
80
+ clear_delta(this._delta);
81
+ return delta;
82
+ }
83
+ get size() {
84
+ return this._base.size;
85
+ }
86
+ get capacity() {
87
+ return this._base.capacity;
88
+ }
89
+ };
90
+ // src/stillflow-collection/utilities/fenwick-tree.ts
91
+ var Fenwick = class Fenwick {
92
+ _size;
93
+ _tree;
94
+ constructor(_size, old = /* @__PURE__ */ new Int32Array(0)) {
95
+ this._size = _size;
96
+ this._tree = new Int32Array(this._size + 1);
97
+ this._tree.set(old);
98
+ }
99
+ add(start, delta) {
100
+ for (let index = start + 1; index <= this._size; index += index & -index) this._tree[index] += delta;
101
+ }
102
+ count(end) {
103
+ let amount = 0;
104
+ for (let index = end + 1; index > 0; index -= index & -index) amount += this._tree[index];
105
+ return amount;
106
+ }
107
+ grow(length) {
108
+ return new Fenwick(this._size + length, this._tree);
109
+ }
110
+ get size() {
111
+ return this._size;
112
+ }
113
+ };
114
+ // src/stillflow-collection/fenwick.ts
115
+ var FenwickCollection = class FenwickCollection {
116
+ _size;
117
+ static GROW = 2;
118
+ static REMOVE_COUNT = 1;
119
+ _removes = /* @__PURE__ */ new Set();
120
+ _tree;
121
+ _shift = 0;
122
+ _data;
123
+ constructor(_size = 1) {
124
+ this._size = _size;
125
+ this._data = new Array();
126
+ this._tree = new Fenwick(this._size);
127
+ }
128
+ at(index) {
129
+ return this._data[index + this._shift];
130
+ }
131
+ map(id) {
132
+ let physical_index = 0;
133
+ let step = 1;
134
+ while (step * 2 <= this._size) step *= 2;
135
+ for (let index = step; index > 0; index >>= 1) {
136
+ const next = physical_index + index;
137
+ if (next <= this._data.length) {
138
+ if (next - this._tree.count(next) <= id) physical_index = next;
139
+ }
140
+ }
141
+ return physical_index + this._shift;
142
+ }
143
+ set(index, value) {
144
+ this._data[index + this._shift] = value;
145
+ }
146
+ add(value) {
147
+ if (this._data.push(value) >= this._size) {
148
+ this._tree = this._tree.grow(this._size);
149
+ this._size *= FenwickCollection.GROW;
150
+ }
151
+ }
152
+ swap(i, j) {
153
+ const temporary = this.at(i);
154
+ this.set(i, this.at(j));
155
+ this.set(j, temporary);
156
+ }
157
+ attach(value) {
158
+ this._data = this._data.concat(value);
159
+ const index = this._data.length;
160
+ while (index >= this._size) {
161
+ this._tree = this._tree.grow(this._size);
162
+ this._size *= FenwickCollection.GROW;
163
+ }
164
+ }
165
+ mutate(index, mutator) {
166
+ mutator(this.at(index));
167
+ }
168
+ shrink() {
169
+ this._data.splice(0, this._shift);
170
+ this._shift = 0;
171
+ const removes = Array.from(this._removes).sort((i, j) => j - i);
172
+ for (const id of removes) this._data.splice(id, 1);
173
+ this._removes.clear();
174
+ this._size = this._data.length + 1;
175
+ this._tree = new Fenwick(this._size);
176
+ }
177
+ mark_cleared() {
178
+ this._shift = this._data.length;
179
+ this._size = this._data.length + 1;
180
+ this._removes.clear();
181
+ this._tree = new Fenwick(this._size);
182
+ }
183
+ mark_removed(index) {
184
+ this.mark_removed_range(index, index);
185
+ }
186
+ mark_removed_range(left, right) {
187
+ if (left > right) return;
188
+ for (let index = left; index <= right; index++) if (this._removes.has(index) === false) {
189
+ this._tree.add(index, FenwickCollection.REMOVE_COUNT);
190
+ this._removes.add(index);
191
+ }
192
+ }
193
+ get size() {
194
+ return this._data.length - this._shift - this._tree.count(this._data.length - this._shift);
195
+ }
196
+ get capacity() {
197
+ return this._size;
198
+ }
199
+ };
200
+ // src/stillflow-collection/index.ts
201
+ var stillflow_collection_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
202
+ Fenwick: () => FenwickCollection,
203
+ Flushable: () => FlushableCollection
204
+ });
205
+ // src/stillflow/state.ts
206
+ var State = class {
207
+ _state = /* @__PURE__ */ new Map();
208
+ write(path, value) {
209
+ this._state.set(path, value);
210
+ }
211
+ read(path) {
212
+ return this._state.get(path);
213
+ }
214
+ remove(path) {
215
+ this._state.delete(path);
216
+ }
217
+ };
218
+ // src/stillflow/compiler/compile.ts
219
+ function $CompileIR(source) {
220
+ const ir = {
221
+ refs: Object.create(null),
222
+ links: Object.create(null),
223
+ locals: Object.create(null),
224
+ backrefs: Object.create(null),
225
+ behaviors: Object.create(null)
226
+ };
227
+ for (const key in source) {
228
+ const operator = source[key];
229
+ switch (operator.type) {
230
+ case "is":
231
+ ir.behaviors[key] = operator.factory;
232
+ break;
233
+ case "ref":
234
+ ir.refs[key] = operator.path;
235
+ break;
236
+ case "link":
237
+ ir.links[key] = operator.source;
238
+ break;
239
+ case "local":
240
+ ir.locals[key] = operator.value;
241
+ break;
242
+ case "backref":
243
+ ir.backrefs[key] = operator.path;
244
+ break;
245
+ default: throw new Error(`Undefined operator '${operator}'`);
246
+ }
247
+ }
248
+ return ir;
249
+ }
250
+ function $ProcessBackrefs(kernel, source, view) {
251
+ for (const key in source.backrefs) kernel.write(source.backrefs[key], view[key]);
252
+ }
253
+ function $ProcessLocals(source, view) {
254
+ for (const key in source.locals) view[key] = source.locals[key];
255
+ }
256
+ function $ProcessLinks(kernel, source, view) {
257
+ for (const key in source.links) {
258
+ view[key] = view[key] || {};
259
+ $Process(kernel, source.links[key], view[key]);
260
+ }
261
+ }
262
+ function $ProcessRef(kernel, source, view) {
263
+ for (const key in source.refs) view[key] = kernel.read(source.refs[key]);
264
+ }
265
+ function $ProcessIs(source, view) {
266
+ for (const key in source.behaviors) view.meta.behaviors[key] = source.behaviors[key];
267
+ }
268
+ function $Process(kernel, source, view) {
269
+ view.meta = {
270
+ instantiated: false,
271
+ behaviors: Object.create(null),
272
+ source
273
+ };
274
+ $ProcessBackrefs(kernel, source, view);
275
+ $ProcessLocals(source, view);
276
+ $ProcessLinks(kernel, source, view);
277
+ $ProcessRef(kernel, source, view);
278
+ $ProcessIs(source, view);
279
+ }
280
+ function $ProcessWrite(kernel, source, view) {
281
+ $ProcessBackrefs(kernel, source, view);
282
+ $ProcessLinks(kernel, source, view);
283
+ }
284
+ function $ProcessRead(kernel, source, view) {
285
+ $ProcessRef(kernel, source, view);
286
+ $ProcessLinks(kernel, source, view);
287
+ }
288
+ function $Compile(kernel, source) {
289
+ const view = Object.create(null);
290
+ $Process(kernel, $CompileIR(source), view);
291
+ return view;
292
+ }
293
+ // src/stillflow/compiler/instantiate.ts
294
+ function $Instantiate(view, factories) {
295
+ function copy(view) {
296
+ return {
297
+ ...view,
298
+ meta: {
299
+ ...view.meta,
300
+ behaviors: { ...view.meta.behaviors }
301
+ }
302
+ };
303
+ }
304
+ function deepcopy(view, cache) {
305
+ if (cache.has(view)) return cache.get(view);
306
+ const instance = copy(view);
307
+ cache.set(view, instance);
308
+ for (const key in view.meta.source.links) instance[key] = deepcopy(view[key], cache);
309
+ return instance;
310
+ }
311
+ function instantiate(view, seen) {
312
+ if (seen.has(view) || view.meta.instantiated) return;
313
+ seen.add(view);
314
+ for (const key in view.meta.behaviors) view[key] = factories.get(view.meta.behaviors[key], view);
315
+ for (const key in view.meta.source.links) instantiate(view[key], seen);
316
+ view.meta.instantiated = true;
317
+ }
318
+ const instance = deepcopy(view, /* @__PURE__ */ new WeakMap());
319
+ instantiate(instance, /* @__PURE__ */ new Set());
320
+ return instance;
321
+ }
322
+ // src/stillflow/factories/factories.ts
323
+ var Factories = class Factories {
324
+ _parent;
325
+ _factories = /* @__PURE__ */ new Map();
326
+ constructor(_parent = null) {
327
+ this._parent = _parent;
328
+ }
329
+ add(type, factory) {
330
+ this._factories.set(type, factory);
331
+ }
332
+ get(type, view) {
333
+ const factory = this._factories.get(type);
334
+ if (factory === void 0) return this._parent?.get(type, view);
335
+ return factory(view, this);
336
+ }
337
+ make() {
338
+ return new Factories(this);
339
+ }
340
+ };
341
+ // src/stillflow/kernel/buffer.ts
342
+ var Buffer = class {
343
+ _messages = /* @__PURE__ */ new Map();
344
+ constructor() {}
345
+ write(path, value) {
346
+ this._messages.set(path, value);
347
+ }
348
+ discard() {
349
+ this._messages.clear();
350
+ }
351
+ commit(state) {
352
+ for (const [path, value] of this._messages.entries()) state.write(path, value);
353
+ this._messages.clear();
354
+ }
355
+ };
356
+ // src/stillflow/kernel/signal.ts
357
+ var Signal = class {
358
+ _subscribers = /* @__PURE__ */ new Set();
359
+ subscribe(site) {
360
+ this._subscribers.add(site);
361
+ return () => this._subscribers.delete(site);
362
+ }
363
+ dispatch(payload) {
364
+ for (const subscriber of this._subscribers) subscriber(payload);
365
+ }
366
+ };
367
+ // src/stillflow/kernel/kernel.ts
368
+ var Kernel = class {
369
+ _state;
370
+ _before = new Signal();
371
+ _after = new Signal();
372
+ _commiting = false;
373
+ _additional = new Buffer();
374
+ _buffers = /* @__PURE__ */ new Set([this._additional]);
375
+ constructor(_state) {
376
+ this._state = _state;
377
+ }
378
+ bind(buffer) {
379
+ this._buffers.add(buffer);
380
+ return () => this._buffers.delete(buffer);
381
+ }
382
+ before(site) {
383
+ return this._before.subscribe(site);
384
+ }
385
+ after(site) {
386
+ return this._after.subscribe(site);
387
+ }
388
+ write(path, value) {
389
+ this._additional.write(path, value);
390
+ }
391
+ read(path) {
392
+ return this._state.read(path);
393
+ }
394
+ remove(path) {
395
+ this._state.remove(path);
396
+ }
397
+ commit() {
398
+ if (this._commiting) throw new Error(`Can not "kernel.commit()" within commit`);
399
+ this._commiting = true;
400
+ this._before.dispatch();
401
+ for (const buffer of this._buffers) buffer.commit(this._state);
402
+ this._after.dispatch();
403
+ this._commiting = false;
404
+ }
405
+ };
406
+ // src/stillflow/operators.ts
407
+ function ref(path) {
408
+ return {
409
+ type: "ref",
410
+ path
411
+ };
412
+ }
413
+ function backref(path) {
414
+ return {
415
+ type: "backref",
416
+ path
417
+ };
418
+ }
419
+ function local(value) {
420
+ return {
421
+ type: "local",
422
+ value
423
+ };
424
+ }
425
+ function link(source) {
426
+ return {
427
+ type: "link",
428
+ source
429
+ };
430
+ }
431
+ function is(factory) {
432
+ return {
433
+ type: "is",
434
+ factory
435
+ };
436
+ }
437
+ var operators_default = {
438
+ ref,
439
+ backref,
440
+ link,
441
+ local,
442
+ is
443
+ };
444
+ // src/stillflow/variable.ts
445
+ var Variable = class {
446
+ _kernel;
447
+ _key;
448
+ constructor(_kernel, _key) {
449
+ this._kernel = _kernel;
450
+ this._key = _key;
451
+ }
452
+ write(value) {
453
+ this._kernel.write(this._key, value);
454
+ }
455
+ read() {
456
+ return this._kernel.read(this._key);
457
+ }
458
+ remove() {
459
+ this._kernel.remove(this._key);
460
+ }
461
+ ref() {
462
+ return operators_default.ref(this._key);
463
+ }
464
+ backref() {
465
+ return operators_default.backref(this._key);
466
+ }
467
+ };
468
+ // src/stillflow/tools/batcher.ts
469
+ var Batcher = class {
470
+ _strategy;
471
+ _commiting = false;
472
+ _tasks = /* @__PURE__ */ new Set();
473
+ constructor(_strategy) {
474
+ this._strategy = _strategy;
475
+ }
476
+ task(task) {
477
+ this._tasks.add(task);
478
+ if (this._commiting) return;
479
+ this._commiting = true;
480
+ this._strategy(() => {
481
+ for (const task of this._tasks) task();
482
+ this._commiting = false;
483
+ });
484
+ }
485
+ };
486
+ // src/stillflow/stillflow.ts
487
+ var Stillflow = class {
488
+ _state;
489
+ _options;
490
+ _views = /* @__PURE__ */ new Set();
491
+ _kernel;
492
+ _batcher;
493
+ constructor(_state, _options = { strategy: (site) => site() }) {
494
+ this._state = _state;
495
+ this._options = _options;
496
+ this._kernel = new Kernel(this._state);
497
+ this._batcher = new Batcher(this._options.strategy);
498
+ this._kernel.before(() => {
499
+ for (const view of [...this._views]) $ProcessWrite(this._kernel, view.meta.source, view);
500
+ });
501
+ this._kernel.after(() => {
502
+ for (const view of [...this._views]) $ProcessRead(this._kernel, view.meta.source, view);
503
+ });
504
+ }
505
+ on(site) {
506
+ return this._kernel.after(site);
507
+ }
508
+ factory() {
509
+ return new Factories();
510
+ }
511
+ buffer() {
512
+ return new Buffer();
513
+ }
514
+ bind(buffer) {
515
+ this._kernel.bind(buffer);
516
+ }
517
+ compile(source) {
518
+ const view = $Compile(this._kernel, source);
519
+ this._views.add(view);
520
+ return view;
521
+ }
522
+ instantiate(source, factory) {
523
+ const view = $Instantiate(source, factory);
524
+ this._views.delete(source);
525
+ this._views.add(view);
526
+ return view;
527
+ }
528
+ commit() {
529
+ this._batcher.task(() => this._kernel.commit());
530
+ }
531
+ variable(path) {
532
+ return new Variable(this._kernel, path);
533
+ }
534
+ };
535
+ // src/stillflow/index.ts
536
+ var stillflow_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
537
+ Batcher: () => Batcher,
538
+ State: () => State,
539
+ Stillflow: () => Stillflow
540
+ });
541
+ // src/stillflow-vite/runtime/jsx.dom.ts
542
+ var jsx_dom_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
543
+ $: () => $,
544
+ jsxdom: () => jsxdom
545
+ });
546
+ var jsxdom = Object.create(null);
547
+ var $ = (() => {});
548
+ Object.defineProperty(exports, "collections", {
549
+ enumerable: true,
550
+ get: function() {
551
+ return stillflow_collection_exports;
552
+ }
553
+ });
554
+ Object.defineProperty(exports, "core", {
555
+ enumerable: true,
556
+ get: function() {
557
+ return stillflow_exports;
558
+ }
559
+ });
560
+ exports.operators = operators_default;
561
+ Object.defineProperty(exports, "runtime", {
562
+ enumerable: true,
563
+ get: function() {
564
+ return jsx_dom_exports;
565
+ }
566
+ });
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import * as adapters from './stillflow-adapters/index.js';
2
- import * as collection from './stillflow-collection/index.js';
1
+ import { default as operators } from './stillflow/operators.js';
2
+ import * as collections from './stillflow-collection/index.js';
3
3
  import * as core from './stillflow/index.js';
4
- import * as vm from './stillflow-vm/index.js';
5
- import operators from './stillflow/operators.js';
6
- export { operators, adapters, collection, core, vm };
4
+ import * as runtime from './stillflow-vite/runtime/jsx.dom.js';
5
+ export { operators, collections, runtime, core };