@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.
- package/LICENSE +21 -0
- package/README.md +156 -3
- package/dist/index.cjs.js +1051 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.es.js +1023 -0
- package/dist/jsx-runtime.d.ts +43 -0
- package/dist/lib-DUuDpiwh.js +11975 -0
- package/dist/lib-lWz8P7iq.cjs +11979 -0
- package/dist/stillflow/abstracts/IR.d.ts +7 -0
- package/dist/stillflow/abstracts/meta.d.ts +8 -0
- package/dist/stillflow/abstracts/operators.d.ts +22 -0
- package/dist/stillflow/abstracts/state.d.ts +13 -0
- package/dist/stillflow/abstracts/view.d.ts +8 -0
- package/dist/stillflow/compiler/compile.d.ts +11 -0
- package/dist/stillflow/compiler/instantiate.d.ts +3 -0
- package/dist/stillflow/factories/factories.d.ts +10 -0
- package/dist/stillflow/index.d.ts +5 -0
- package/dist/stillflow/kernel/buffer.d.ts +10 -0
- package/dist/stillflow/kernel/kernel.d.ts +26 -0
- package/dist/stillflow/kernel/signal.d.ts +5 -0
- package/dist/stillflow/operators.d.ts +15 -0
- package/dist/stillflow/state.d.ts +15 -0
- package/dist/stillflow/stillflow.d.ts +28 -0
- package/dist/stillflow/tools/batcher.d.ts +9 -0
- package/dist/stillflow/variable.d.ts +12 -0
- package/dist/stillflow-collection/abstract/collection.delta.d.ts +10 -0
- package/dist/stillflow-collection/abstract/collection.flusher.d.ts +17 -0
- package/dist/stillflow-collection/abstract/collection.glee.d.ts +28 -0
- package/dist/stillflow-collection/abstract/collection.index.d.ts +9 -0
- package/dist/stillflow-collection/abstract/collection.logical.d.ts +13 -0
- package/dist/stillflow-collection/abstract/collection.physical.d.ts +13 -0
- package/dist/stillflow-collection/abstract/collection.serializable.d.ts +4 -0
- package/dist/stillflow-collection/array.d.ts +21 -0
- package/dist/stillflow-collection/fenwick.d.ts +28 -0
- package/dist/stillflow-collection/flushable.d.ts +38 -0
- package/dist/stillflow-collection/index.d.ts +6 -0
- package/dist/stillflow-collection/utilities/disjointed-set.d.ts +10 -0
- package/dist/stillflow-collection/utilities/fenwick-tree.d.ts +9 -0
- package/dist/stillflow-collection/utilities/index.d.ts +1 -0
- package/dist/stillflow-collection/utilities/interval-merger.d.ts +7 -0
- package/dist/stillflow-collection/utilities/range-fenwick-tree.d.ts +11 -0
- package/dist/stillflow-runtime/dom.d.ts +5 -0
- package/dist/stillflow-runtime/utilities/delegate-event.d.ts +1 -0
- package/dist/stillflow-runtime/utilities/index.d.ts +3 -0
- package/dist/stillflow-runtime/utilities/reconcile-if.d.ts +10 -0
- package/dist/stillflow-runtime/utilities/reconcile-list.d.ts +8 -0
- package/dist/stillflow-serialize/deserialize.d.ts +2 -0
- package/dist/stillflow-serialize/index.d.ts +2 -0
- package/dist/stillflow-serialize/serialize.d.ts +2 -0
- package/dist/stillflow-serialize/serialized.d.ts +4 -0
- package/dist/stillflow-vite/dom.pass.codegen.d.ts +8 -0
- package/dist/stillflow-vite/dom.pass.transform.d.ts +16 -0
- package/dist/stillflow-vite/dom.target.d.ts +2 -0
- package/dist/stillflow-vite/targets.plugin.d.ts +9 -0
- package/dist/stillflow-vite/vm-abstract/index.d.ts +3 -0
- package/dist/stillflow-vite/vm-abstract/vm.instruction.d.ts +7 -0
- package/dist/stillflow-vite/vm-abstract/vm.options.d.ts +4 -0
- package/dist/stillflow-vite/vm-abstract/vm.target.d.ts +23 -0
- package/dist/stillflow-vite/vm-compiler/bytecode-builder.d.ts +33 -0
- package/dist/stillflow-vite/vm-compiler/codes.d.ts +20 -0
- package/dist/stillflow-vite/vm-compiler/dirty.d.ts +7 -0
- package/dist/stillflow-vite/vm-compiler/fabric.d.ts +9 -0
- package/dist/stillflow-vite/vm-compiler/index.d.ts +8 -0
- package/dist/stillflow-vite/vm-compiler/nodes.d.ts +72 -0
- package/dist/stillflow-vite/vm-compiler/pass.analyze-dirty.d.ts +3 -0
- package/dist/stillflow-vite/vm-compiler/pass.analyze-dynamic.d.ts +2 -0
- package/dist/stillflow-vite/vm-compiler/pass.lowering.d.ts +4 -0
- package/dist/stillflow-vite/vm-compiler/pass.scopes.d.ts +14 -0
- package/dist/stillflow-vite/vm-targets/collect-components.d.ts +8 -0
- package/dist/stillflow-vite/vm-targets/collect-imports.d.ts +3 -0
- package/dist/stillflow-vite/vm-targets/find-component.d.ts +3 -0
- package/dist/targets.index.d.ts +1 -0
- package/dist/vite.cjs.js +261 -0
- package/dist/vite.es.js +260 -0
- package/dist/vite.plugin.d.ts +3 -0
- package/dist/vm.instruction-DPuxu4sV.cjs +9 -0
- package/dist/vm.instruction-oyM-GI-p.js +4 -0
- package/dist/vms.cjs.js +1096 -0
- package/dist/vms.es.js +1095 -0
- package/package.json +99 -5
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,1023 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, flags) => {
|
|
4
|
+
let target = Object.setPrototypeOf({}, null);
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return flags & 2 ? target : Object.preventExtensions(target);
|
|
11
|
+
};
|
|
12
|
+
// src/stillflow-collection/abstract/collection.delta.ts
|
|
13
|
+
function clear_delta(delta) {
|
|
14
|
+
delta.addes = 0;
|
|
15
|
+
delta.swaps.clear();
|
|
16
|
+
delta.updates.clear();
|
|
17
|
+
delta.removes.clear();
|
|
18
|
+
delta.replaces = false;
|
|
19
|
+
delta.clears = false;
|
|
20
|
+
}
|
|
21
|
+
// src/stillflow-collection/abstract/collection.index.ts
|
|
22
|
+
var as_logical$1 = (id) => id;
|
|
23
|
+
var as_physical$1 = (id) => id;
|
|
24
|
+
// src/stillflow-collection/abstract/collection.glee.ts
|
|
25
|
+
var GleeCollection = class {
|
|
26
|
+
at(id) {
|
|
27
|
+
return this.$at(this.$to_physical(id));
|
|
28
|
+
}
|
|
29
|
+
set(id, value) {
|
|
30
|
+
this.$set(this.$to_physical(id), value);
|
|
31
|
+
}
|
|
32
|
+
swap(i, j) {
|
|
33
|
+
this.$swap(this.$to_physical(i), this.$to_physical(j));
|
|
34
|
+
}
|
|
35
|
+
mutate(id, mutator) {
|
|
36
|
+
this.$mutate(this.$to_physical(id), mutator);
|
|
37
|
+
}
|
|
38
|
+
remove(id) {
|
|
39
|
+
this.$remove(this.$to_physical(id));
|
|
40
|
+
}
|
|
41
|
+
remove_range(left, right) {
|
|
42
|
+
this.$remove_range(this.$to_physical(left), this.$to_physical(right));
|
|
43
|
+
}
|
|
44
|
+
get size() {
|
|
45
|
+
return this.$size;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
// src/stillflow-collection/utilities/fenwick-tree.ts
|
|
49
|
+
var Fenwick = class Fenwick {
|
|
50
|
+
_size;
|
|
51
|
+
_tree;
|
|
52
|
+
constructor(_size, old = /* @__PURE__ */ new Int32Array(0)) {
|
|
53
|
+
this._size = _size;
|
|
54
|
+
this._tree = new Int32Array(this._size + 1);
|
|
55
|
+
this._tree.set(old);
|
|
56
|
+
}
|
|
57
|
+
add(start, delta) {
|
|
58
|
+
for (let index = start + 1; index <= this._size; index += index & -index) this._tree[index] += delta;
|
|
59
|
+
}
|
|
60
|
+
count(end) {
|
|
61
|
+
let amount = 0;
|
|
62
|
+
for (let index = end + 1; index > 0; index -= index & -index) amount += this._tree[index];
|
|
63
|
+
return amount;
|
|
64
|
+
}
|
|
65
|
+
grow(length) {
|
|
66
|
+
return new Fenwick(this._size + length, this._tree);
|
|
67
|
+
}
|
|
68
|
+
get size() {
|
|
69
|
+
return this._size;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
// src/stillflow-collection/fenwick.ts
|
|
73
|
+
var FenwickCollection$1 = class FenwickCollection$1 extends GleeCollection {
|
|
74
|
+
_size;
|
|
75
|
+
static GROW = 2;
|
|
76
|
+
static REMOVE_COUNT = 1;
|
|
77
|
+
_removes = /* @__PURE__ */ new Set();
|
|
78
|
+
_tree;
|
|
79
|
+
_shift = 0;
|
|
80
|
+
_data;
|
|
81
|
+
constructor(_size = 1) {
|
|
82
|
+
super();
|
|
83
|
+
this._size = _size;
|
|
84
|
+
this._data = new Array();
|
|
85
|
+
this._tree = new Fenwick(this._size);
|
|
86
|
+
}
|
|
87
|
+
$to_logical(index) {
|
|
88
|
+
return as_logical$1(index - (index > 0 ? this._tree.count(index - 1) : 0));
|
|
89
|
+
}
|
|
90
|
+
$to_physical(id) {
|
|
91
|
+
let physical_index = 0;
|
|
92
|
+
let step = 1;
|
|
93
|
+
const active_length = this._data.length - this._shift;
|
|
94
|
+
while (step * 2 < active_length) step *= 2;
|
|
95
|
+
for (let index = step; index > 0; index >>= 1) {
|
|
96
|
+
const next = physical_index + index;
|
|
97
|
+
if (next < active_length) {
|
|
98
|
+
if (next - this._tree.count(next - 1) <= id) physical_index = next;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return as_physical$1(physical_index);
|
|
102
|
+
}
|
|
103
|
+
$at(id) {
|
|
104
|
+
return this._data[id + this._shift];
|
|
105
|
+
}
|
|
106
|
+
$set(id, value) {
|
|
107
|
+
this._data[id + this._shift] = value;
|
|
108
|
+
}
|
|
109
|
+
$swap(i, j) {
|
|
110
|
+
const temporary = this.$at(i);
|
|
111
|
+
this.$set(i, this.$at(j));
|
|
112
|
+
this.$set(j, temporary);
|
|
113
|
+
}
|
|
114
|
+
$mutate(index, mutator) {
|
|
115
|
+
mutator(this.$at(index));
|
|
116
|
+
}
|
|
117
|
+
shrink() {
|
|
118
|
+
this._data.splice(0, this._shift);
|
|
119
|
+
this._shift = 0;
|
|
120
|
+
const removes = Array.from(this._removes).sort((i, j) => j - i);
|
|
121
|
+
for (const id of removes) {
|
|
122
|
+
this._tree.add(id, -FenwickCollection$1.REMOVE_COUNT);
|
|
123
|
+
this._data.splice(id, 1);
|
|
124
|
+
}
|
|
125
|
+
this._removes.clear();
|
|
126
|
+
}
|
|
127
|
+
clear() {
|
|
128
|
+
this._shift = this._data.length;
|
|
129
|
+
this._size = this._data.length + 1;
|
|
130
|
+
for (const id of this._removes) this._tree.add(id, -FenwickCollection$1.REMOVE_COUNT);
|
|
131
|
+
this._removes.clear();
|
|
132
|
+
}
|
|
133
|
+
add(value) {
|
|
134
|
+
if (this._data.push(value) >= this._size) {
|
|
135
|
+
this._tree = this._tree.grow(this._size);
|
|
136
|
+
this._size *= FenwickCollection$1.GROW;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
attach(value) {
|
|
140
|
+
this._data = this._data.concat(value);
|
|
141
|
+
const index = this._data.length;
|
|
142
|
+
while (index >= this._size) {
|
|
143
|
+
this._tree = this._tree.grow(this._size);
|
|
144
|
+
this._size *= FenwickCollection$1.GROW;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
serialize(map) {
|
|
148
|
+
this.shrink();
|
|
149
|
+
const result = new Array(this.$size);
|
|
150
|
+
for (let index = 0; index < result.length; index++) result[index] = map(this.at(as_logical$1(index)));
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
deserialize(items) {
|
|
154
|
+
this.clear();
|
|
155
|
+
this.attach(items);
|
|
156
|
+
}
|
|
157
|
+
$remove(id) {
|
|
158
|
+
if (this._removes.has(id) === false) {
|
|
159
|
+
this._tree.add(id, FenwickCollection$1.REMOVE_COUNT);
|
|
160
|
+
this._removes.add(id);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
$remove_range(left, right) {
|
|
164
|
+
if (left > right) return;
|
|
165
|
+
for (let index = left; index <= right; index++) this.$remove(index);
|
|
166
|
+
}
|
|
167
|
+
get $size() {
|
|
168
|
+
return this._data.length - this._shift - this._tree.count(this._data.length - this._shift);
|
|
169
|
+
}
|
|
170
|
+
get $capacity() {
|
|
171
|
+
return this._size;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
// src/stillflow-collection/array.ts
|
|
175
|
+
var ArrayCollection$1 = class extends GleeCollection {
|
|
176
|
+
_data;
|
|
177
|
+
constructor(initial = []) {
|
|
178
|
+
super();
|
|
179
|
+
this._data = initial;
|
|
180
|
+
}
|
|
181
|
+
$to_logical(index) {
|
|
182
|
+
return as_logical$1(index);
|
|
183
|
+
}
|
|
184
|
+
$to_physical(id) {
|
|
185
|
+
return as_physical$1(id);
|
|
186
|
+
}
|
|
187
|
+
$at(id) {
|
|
188
|
+
return this._data[id];
|
|
189
|
+
}
|
|
190
|
+
$set(id, value) {
|
|
191
|
+
this._data[id] = value;
|
|
192
|
+
}
|
|
193
|
+
$swap(i, j) {
|
|
194
|
+
const tmp = this._data[i];
|
|
195
|
+
this._data[i] = this._data[j];
|
|
196
|
+
this._data[j] = tmp;
|
|
197
|
+
}
|
|
198
|
+
$mutate(index, mutator) {
|
|
199
|
+
mutator(this._data[index]);
|
|
200
|
+
}
|
|
201
|
+
add(value) {
|
|
202
|
+
this._data.push(value);
|
|
203
|
+
}
|
|
204
|
+
attach(value) {
|
|
205
|
+
this._data = this._data.concat(value);
|
|
206
|
+
}
|
|
207
|
+
$remove(id) {
|
|
208
|
+
this._data.splice(id, 1);
|
|
209
|
+
}
|
|
210
|
+
$remove_range(left, right) {
|
|
211
|
+
if (left <= right) this._data.splice(left, right - left + 1);
|
|
212
|
+
}
|
|
213
|
+
serialize(map) {
|
|
214
|
+
return this._data.map((item) => map(item));
|
|
215
|
+
}
|
|
216
|
+
deserialize(items) {
|
|
217
|
+
this._data = items;
|
|
218
|
+
}
|
|
219
|
+
shrink() {}
|
|
220
|
+
clear() {
|
|
221
|
+
this._data.length = 0;
|
|
222
|
+
}
|
|
223
|
+
get $size() {
|
|
224
|
+
return this._data.length;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
// src/stillflow-collection/abstract/collection.index.ts
|
|
228
|
+
var as_logical = (id) => id;
|
|
229
|
+
var as_physical = (id) => id;
|
|
230
|
+
// src/stillflow-collection/fenwick.ts
|
|
231
|
+
var FenwickCollection = class FenwickCollection extends GleeCollection {
|
|
232
|
+
_size;
|
|
233
|
+
static GROW = 2;
|
|
234
|
+
static REMOVE_COUNT = 1;
|
|
235
|
+
_removes = /* @__PURE__ */ new Set();
|
|
236
|
+
_tree;
|
|
237
|
+
_shift = 0;
|
|
238
|
+
_data;
|
|
239
|
+
constructor(_size = 1) {
|
|
240
|
+
super();
|
|
241
|
+
this._size = _size;
|
|
242
|
+
this._data = new Array();
|
|
243
|
+
this._tree = new Fenwick(this._size);
|
|
244
|
+
}
|
|
245
|
+
$to_logical(index) {
|
|
246
|
+
return as_logical$1(index - (index > 0 ? this._tree.count(index - 1) : 0));
|
|
247
|
+
}
|
|
248
|
+
$to_physical(id) {
|
|
249
|
+
let physical_index = 0;
|
|
250
|
+
let step = 1;
|
|
251
|
+
const active_length = this._data.length - this._shift;
|
|
252
|
+
while (step * 2 < active_length) step *= 2;
|
|
253
|
+
for (let index = step; index > 0; index >>= 1) {
|
|
254
|
+
const next = physical_index + index;
|
|
255
|
+
if (next < active_length) {
|
|
256
|
+
if (next - this._tree.count(next - 1) <= id) physical_index = next;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return as_physical$1(physical_index);
|
|
260
|
+
}
|
|
261
|
+
$at(id) {
|
|
262
|
+
return this._data[id + this._shift];
|
|
263
|
+
}
|
|
264
|
+
$set(id, value) {
|
|
265
|
+
this._data[id + this._shift] = value;
|
|
266
|
+
}
|
|
267
|
+
$swap(i, j) {
|
|
268
|
+
const temporary = this.$at(i);
|
|
269
|
+
this.$set(i, this.$at(j));
|
|
270
|
+
this.$set(j, temporary);
|
|
271
|
+
}
|
|
272
|
+
$mutate(index, mutator) {
|
|
273
|
+
mutator(this.$at(index));
|
|
274
|
+
}
|
|
275
|
+
shrink() {
|
|
276
|
+
this._data.splice(0, this._shift);
|
|
277
|
+
this._shift = 0;
|
|
278
|
+
const removes = Array.from(this._removes).sort((i, j) => j - i);
|
|
279
|
+
for (const id of removes) {
|
|
280
|
+
this._tree.add(id, -FenwickCollection.REMOVE_COUNT);
|
|
281
|
+
this._data.splice(id, 1);
|
|
282
|
+
}
|
|
283
|
+
this._removes.clear();
|
|
284
|
+
}
|
|
285
|
+
clear() {
|
|
286
|
+
this._shift = this._data.length;
|
|
287
|
+
this._size = this._data.length + 1;
|
|
288
|
+
for (const id of this._removes) this._tree.add(id, -FenwickCollection.REMOVE_COUNT);
|
|
289
|
+
this._removes.clear();
|
|
290
|
+
}
|
|
291
|
+
add(value) {
|
|
292
|
+
if (this._data.push(value) >= this._size) {
|
|
293
|
+
this._tree = this._tree.grow(this._size);
|
|
294
|
+
this._size *= FenwickCollection.GROW;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
attach(value) {
|
|
298
|
+
this._data = this._data.concat(value);
|
|
299
|
+
const index = this._data.length;
|
|
300
|
+
while (index >= this._size) {
|
|
301
|
+
this._tree = this._tree.grow(this._size);
|
|
302
|
+
this._size *= FenwickCollection.GROW;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
serialize(map) {
|
|
306
|
+
this.shrink();
|
|
307
|
+
const result = new Array(this.$size);
|
|
308
|
+
for (let index = 0; index < result.length; index++) result[index] = map(this.at(as_logical$1(index)));
|
|
309
|
+
return result;
|
|
310
|
+
}
|
|
311
|
+
deserialize(items) {
|
|
312
|
+
this.clear();
|
|
313
|
+
this.attach(items);
|
|
314
|
+
}
|
|
315
|
+
$remove(id) {
|
|
316
|
+
if (this._removes.has(id) === false) {
|
|
317
|
+
this._tree.add(id, FenwickCollection.REMOVE_COUNT);
|
|
318
|
+
this._removes.add(id);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
$remove_range(left, right) {
|
|
322
|
+
if (left > right) return;
|
|
323
|
+
for (let index = left; index <= right; index++) this.$remove(index);
|
|
324
|
+
}
|
|
325
|
+
get $size() {
|
|
326
|
+
return this._data.length - this._shift - this._tree.count(this._data.length - this._shift);
|
|
327
|
+
}
|
|
328
|
+
get $capacity() {
|
|
329
|
+
return this._size;
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
// src/stillflow-collection/array.ts
|
|
333
|
+
var ArrayCollection = class extends GleeCollection {
|
|
334
|
+
_data;
|
|
335
|
+
constructor(initial = []) {
|
|
336
|
+
super();
|
|
337
|
+
this._data = initial;
|
|
338
|
+
}
|
|
339
|
+
$to_logical(index) {
|
|
340
|
+
return as_logical$1(index);
|
|
341
|
+
}
|
|
342
|
+
$to_physical(id) {
|
|
343
|
+
return as_physical$1(id);
|
|
344
|
+
}
|
|
345
|
+
$at(id) {
|
|
346
|
+
return this._data[id];
|
|
347
|
+
}
|
|
348
|
+
$set(id, value) {
|
|
349
|
+
this._data[id] = value;
|
|
350
|
+
}
|
|
351
|
+
$swap(i, j) {
|
|
352
|
+
const tmp = this._data[i];
|
|
353
|
+
this._data[i] = this._data[j];
|
|
354
|
+
this._data[j] = tmp;
|
|
355
|
+
}
|
|
356
|
+
$mutate(index, mutator) {
|
|
357
|
+
mutator(this._data[index]);
|
|
358
|
+
}
|
|
359
|
+
add(value) {
|
|
360
|
+
this._data.push(value);
|
|
361
|
+
}
|
|
362
|
+
attach(value) {
|
|
363
|
+
this._data = this._data.concat(value);
|
|
364
|
+
}
|
|
365
|
+
$remove(id) {
|
|
366
|
+
this._data.splice(id, 1);
|
|
367
|
+
}
|
|
368
|
+
$remove_range(left, right) {
|
|
369
|
+
if (left <= right) this._data.splice(left, right - left + 1);
|
|
370
|
+
}
|
|
371
|
+
serialize(map) {
|
|
372
|
+
return this._data.map((item) => map(item));
|
|
373
|
+
}
|
|
374
|
+
deserialize(items) {
|
|
375
|
+
this._data = items;
|
|
376
|
+
}
|
|
377
|
+
shrink() {}
|
|
378
|
+
clear() {
|
|
379
|
+
this._data.length = 0;
|
|
380
|
+
}
|
|
381
|
+
get $size() {
|
|
382
|
+
return this._data.length;
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
// src/stillflow-collection/flushable.ts
|
|
386
|
+
var FlushableCollection = class FlushableCollection {
|
|
387
|
+
_base;
|
|
388
|
+
_front = {
|
|
389
|
+
addes: 0,
|
|
390
|
+
swaps: /* @__PURE__ */ new Map(),
|
|
391
|
+
updates: /* @__PURE__ */ new Map(),
|
|
392
|
+
removes: /* @__PURE__ */ new Set(),
|
|
393
|
+
replaces: false,
|
|
394
|
+
clears: false
|
|
395
|
+
};
|
|
396
|
+
_back = {
|
|
397
|
+
addes: 0,
|
|
398
|
+
swaps: /* @__PURE__ */ new Map(),
|
|
399
|
+
updates: /* @__PURE__ */ new Map(),
|
|
400
|
+
removes: /* @__PURE__ */ new Set(),
|
|
401
|
+
replaces: false,
|
|
402
|
+
clears: false
|
|
403
|
+
};
|
|
404
|
+
constructor(_base) {
|
|
405
|
+
this._base = _base;
|
|
406
|
+
}
|
|
407
|
+
at(index) {
|
|
408
|
+
return this._base.at(as_logical(index));
|
|
409
|
+
}
|
|
410
|
+
add(value) {
|
|
411
|
+
this._front.addes++;
|
|
412
|
+
this._base.add(value);
|
|
413
|
+
}
|
|
414
|
+
set(index, value) {
|
|
415
|
+
this._base.set(as_logical(index), value);
|
|
416
|
+
this.touch(index);
|
|
417
|
+
}
|
|
418
|
+
swap(i, j) {
|
|
419
|
+
this._base.swap(as_logical(i), as_logical(j));
|
|
420
|
+
this._front.swaps.set(this._base.$to_logical(as_physical(i)), this._base.$to_logical(as_physical(j)));
|
|
421
|
+
}
|
|
422
|
+
attach(value) {
|
|
423
|
+
this._front.addes += value.length;
|
|
424
|
+
this._base.attach(value);
|
|
425
|
+
}
|
|
426
|
+
mutate(index, mutator) {
|
|
427
|
+
this._base.mutate(as_logical(index), mutator);
|
|
428
|
+
this.touch(index);
|
|
429
|
+
}
|
|
430
|
+
shrink() {
|
|
431
|
+
this._base.shrink();
|
|
432
|
+
}
|
|
433
|
+
clear() {
|
|
434
|
+
this._front.clears = true;
|
|
435
|
+
this._base.clear();
|
|
436
|
+
}
|
|
437
|
+
touch(id) {
|
|
438
|
+
const index = this._base.$to_logical(as_physical(id));
|
|
439
|
+
this._front.updates.set(index, this._base.at(index));
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Drops an item by its original creation index (`$index` inside `<for>`)
|
|
443
|
+
* resolving holes in $O(\log n)$ without re-indexing existing rows
|
|
444
|
+
*
|
|
445
|
+
* @param id Original physical index captured when the row was created
|
|
446
|
+
*/
|
|
447
|
+
drop(id) {
|
|
448
|
+
this._base.$remove(as_physical(id));
|
|
449
|
+
this._front.removes.add(this._base.$to_logical(as_physical(id)));
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Removes an item by its current logical index (`0 .. size - 1`)
|
|
453
|
+
*
|
|
454
|
+
* @param id Current logical position of the item in the list
|
|
455
|
+
*/
|
|
456
|
+
remove(id) {
|
|
457
|
+
this._base.remove(as_logical(id));
|
|
458
|
+
this._front.removes.add(as_logical(id));
|
|
459
|
+
}
|
|
460
|
+
remove_range(left, right) {
|
|
461
|
+
for (let id = left; id <= right; id++) this.remove(id);
|
|
462
|
+
}
|
|
463
|
+
serialize(map) {
|
|
464
|
+
return this._base.serialize(map);
|
|
465
|
+
}
|
|
466
|
+
deserialize(items) {
|
|
467
|
+
this._front.clears = true;
|
|
468
|
+
this._front.addes = items.length;
|
|
469
|
+
this._base.deserialize(items);
|
|
470
|
+
}
|
|
471
|
+
flush() {
|
|
472
|
+
this._front.replaces = this._front.addes > 0 && this._front.clears;
|
|
473
|
+
this._front.clears = this._front.addes <= 0 && this._front.clears;
|
|
474
|
+
this._front.addes = this._front.replaces ? 0 : this._front.addes;
|
|
475
|
+
const temporary = this._front;
|
|
476
|
+
this._front = this._back;
|
|
477
|
+
this._back = temporary;
|
|
478
|
+
clear_delta(this._front);
|
|
479
|
+
return this._back;
|
|
480
|
+
}
|
|
481
|
+
get size() {
|
|
482
|
+
return this._base.size;
|
|
483
|
+
}
|
|
484
|
+
static fenwick(initial_capacity = 16) {
|
|
485
|
+
return new FlushableCollection(new FenwickCollection(initial_capacity));
|
|
486
|
+
}
|
|
487
|
+
static array(initial = []) {
|
|
488
|
+
return new FlushableCollection(new ArrayCollection(initial));
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
// src/stillflow-collection/index.ts
|
|
492
|
+
var stillflow_collection_exports = /* @__PURE__ */ __exportAll({
|
|
493
|
+
Array: () => ArrayCollection$1,
|
|
494
|
+
Fenwick: () => FenwickCollection$1,
|
|
495
|
+
Flushable: () => FlushableCollection,
|
|
496
|
+
as_logical: () => as_logical,
|
|
497
|
+
as_physical: () => as_physical
|
|
498
|
+
});
|
|
499
|
+
// src/stillflow/state.ts
|
|
500
|
+
var State = class {
|
|
501
|
+
_state = /* @__PURE__ */ new Map();
|
|
502
|
+
write(path, value) {
|
|
503
|
+
this._state.set(path, value);
|
|
504
|
+
}
|
|
505
|
+
read(path) {
|
|
506
|
+
return this._state.get(path);
|
|
507
|
+
}
|
|
508
|
+
remove(path) {
|
|
509
|
+
this._state.delete(path);
|
|
510
|
+
}
|
|
511
|
+
entries() {
|
|
512
|
+
const out = {};
|
|
513
|
+
for (const [key, item] of this._state.entries()) out[key] = item;
|
|
514
|
+
return out;
|
|
515
|
+
}
|
|
516
|
+
from_entries(entries) {
|
|
517
|
+
for (const [key, value] of Object.entries(entries)) this._state.set(key, value);
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
// src/stillflow/compiler/compile.ts
|
|
521
|
+
function $CompileIR(source) {
|
|
522
|
+
const ir = {
|
|
523
|
+
refs: Object.create(null),
|
|
524
|
+
links: Object.create(null),
|
|
525
|
+
locals: Object.create(null),
|
|
526
|
+
backrefs: Object.create(null),
|
|
527
|
+
behaviors: Object.create(null)
|
|
528
|
+
};
|
|
529
|
+
for (const key in source) {
|
|
530
|
+
const operator = source[key];
|
|
531
|
+
switch (operator.type) {
|
|
532
|
+
case "is":
|
|
533
|
+
ir.behaviors[key] = operator.factory;
|
|
534
|
+
break;
|
|
535
|
+
case "ref":
|
|
536
|
+
ir.refs[key] = operator.path;
|
|
537
|
+
break;
|
|
538
|
+
case "link":
|
|
539
|
+
ir.links[key] = operator.source;
|
|
540
|
+
break;
|
|
541
|
+
case "local":
|
|
542
|
+
ir.locals[key] = operator.value;
|
|
543
|
+
break;
|
|
544
|
+
case "backref":
|
|
545
|
+
ir.backrefs[key] = operator.path;
|
|
546
|
+
break;
|
|
547
|
+
default: throw new Error(`Undefined operator '${operator}'`);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return ir;
|
|
551
|
+
}
|
|
552
|
+
function $ProcessBackrefs(kernel, source, view) {
|
|
553
|
+
for (const key in source.backrefs) kernel.write(source.backrefs[key], view[key]);
|
|
554
|
+
}
|
|
555
|
+
function $ProcessLocals(source, view) {
|
|
556
|
+
for (const key in source.locals) view[key] = source.locals[key];
|
|
557
|
+
}
|
|
558
|
+
function $ProcessLinks(kernel, source, view) {
|
|
559
|
+
for (const key in source.links) {
|
|
560
|
+
view[key] = view[key] || {};
|
|
561
|
+
$Process(kernel, source.links[key], view[key]);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
function $ProcessRef(kernel, source, view) {
|
|
565
|
+
for (const key in source.refs) view[key] = kernel.read(source.refs[key]);
|
|
566
|
+
}
|
|
567
|
+
function $ProcessIs(source, view) {
|
|
568
|
+
for (const key in source.behaviors) view.meta.behaviors[key] = source.behaviors[key];
|
|
569
|
+
}
|
|
570
|
+
function $Process(kernel, source, view) {
|
|
571
|
+
view.meta = {
|
|
572
|
+
instantiated: false,
|
|
573
|
+
behaviors: Object.create(null),
|
|
574
|
+
source
|
|
575
|
+
};
|
|
576
|
+
$ProcessBackrefs(kernel, source, view);
|
|
577
|
+
$ProcessLocals(source, view);
|
|
578
|
+
$ProcessLinks(kernel, source, view);
|
|
579
|
+
$ProcessRef(kernel, source, view);
|
|
580
|
+
$ProcessIs(source, view);
|
|
581
|
+
}
|
|
582
|
+
function $ProcessWrite(kernel, source, view) {
|
|
583
|
+
$ProcessBackrefs(kernel, source, view);
|
|
584
|
+
$ProcessLinks(kernel, source, view);
|
|
585
|
+
}
|
|
586
|
+
function $ProcessRead(kernel, source, view) {
|
|
587
|
+
$ProcessRef(kernel, source, view);
|
|
588
|
+
$ProcessLinks(kernel, source, view);
|
|
589
|
+
}
|
|
590
|
+
function $Compile(kernel, source) {
|
|
591
|
+
const view = Object.create(null);
|
|
592
|
+
$Process(kernel, $CompileIR(source), view);
|
|
593
|
+
return view;
|
|
594
|
+
}
|
|
595
|
+
// src/stillflow/compiler/instantiate.ts
|
|
596
|
+
function $Instantiate(view, factories) {
|
|
597
|
+
function copy(view) {
|
|
598
|
+
return {
|
|
599
|
+
...view,
|
|
600
|
+
meta: {
|
|
601
|
+
...view.meta,
|
|
602
|
+
behaviors: { ...view.meta.behaviors }
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
function deepcopy(view, cache) {
|
|
607
|
+
if (cache.has(view)) return cache.get(view);
|
|
608
|
+
const instance = copy(view);
|
|
609
|
+
cache.set(view, instance);
|
|
610
|
+
for (const key in view.meta.source.links) instance[key] = deepcopy(view[key], cache);
|
|
611
|
+
return instance;
|
|
612
|
+
}
|
|
613
|
+
function instantiate(view, seen) {
|
|
614
|
+
if (seen.has(view) || view.meta.instantiated) return;
|
|
615
|
+
seen.add(view);
|
|
616
|
+
for (const key in view.meta.behaviors) view[key] = factories.get(view.meta.behaviors[key], view);
|
|
617
|
+
for (const key in view.meta.source.links) instantiate(view[key], seen);
|
|
618
|
+
view.meta.instantiated = true;
|
|
619
|
+
}
|
|
620
|
+
const instance = deepcopy(view, /* @__PURE__ */ new WeakMap());
|
|
621
|
+
instantiate(instance, /* @__PURE__ */ new Set());
|
|
622
|
+
return instance;
|
|
623
|
+
}
|
|
624
|
+
// src/stillflow/factories/factories.ts
|
|
625
|
+
var Factories = class Factories {
|
|
626
|
+
_parent;
|
|
627
|
+
_factories = /* @__PURE__ */ new Map();
|
|
628
|
+
constructor(_parent = null) {
|
|
629
|
+
this._parent = _parent;
|
|
630
|
+
}
|
|
631
|
+
add(type, factory) {
|
|
632
|
+
this._factories.set(type, factory);
|
|
633
|
+
}
|
|
634
|
+
get(type, view) {
|
|
635
|
+
const factory = this._factories.get(type);
|
|
636
|
+
if (factory === void 0) return this._parent?.get(type, view);
|
|
637
|
+
return factory(view, this);
|
|
638
|
+
}
|
|
639
|
+
make() {
|
|
640
|
+
return new Factories(this);
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
// src/stillflow/kernel/buffer.ts
|
|
644
|
+
var Buffer$1 = class {
|
|
645
|
+
_messages = /* @__PURE__ */ new Map();
|
|
646
|
+
constructor() {}
|
|
647
|
+
write(path, value) {
|
|
648
|
+
this._messages.set(path, value);
|
|
649
|
+
}
|
|
650
|
+
discard() {
|
|
651
|
+
this._messages.clear();
|
|
652
|
+
}
|
|
653
|
+
commit(state) {
|
|
654
|
+
for (const [path, value] of this._messages.entries()) state.write(path, value);
|
|
655
|
+
this._messages.clear();
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
// src/stillflow/kernel/signal.ts
|
|
659
|
+
var Signal = class {
|
|
660
|
+
_subscribers = /* @__PURE__ */ new Set();
|
|
661
|
+
subscribe(site) {
|
|
662
|
+
this._subscribers.add(site);
|
|
663
|
+
return () => this._subscribers.delete(site);
|
|
664
|
+
}
|
|
665
|
+
dispatch(payload) {
|
|
666
|
+
for (const subscriber of this._subscribers) subscriber(payload);
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
// src/stillflow/kernel/kernel.ts
|
|
670
|
+
var Kernel = class {
|
|
671
|
+
_state;
|
|
672
|
+
_before = new Signal();
|
|
673
|
+
_after = new Signal();
|
|
674
|
+
_commiting = false;
|
|
675
|
+
_additional = new Buffer$1();
|
|
676
|
+
_buffers = /* @__PURE__ */ new Set([this._additional]);
|
|
677
|
+
constructor(_state) {
|
|
678
|
+
this._state = _state;
|
|
679
|
+
}
|
|
680
|
+
bind(buffer) {
|
|
681
|
+
this._buffers.add(buffer);
|
|
682
|
+
return () => this._buffers.delete(buffer);
|
|
683
|
+
}
|
|
684
|
+
before(site) {
|
|
685
|
+
return this._before.subscribe(site);
|
|
686
|
+
}
|
|
687
|
+
after(site) {
|
|
688
|
+
return this._after.subscribe(site);
|
|
689
|
+
}
|
|
690
|
+
write(path, value) {
|
|
691
|
+
this._additional.write(path, value);
|
|
692
|
+
}
|
|
693
|
+
read(path) {
|
|
694
|
+
return this._state.read(path);
|
|
695
|
+
}
|
|
696
|
+
remove(path) {
|
|
697
|
+
this._state.remove(path);
|
|
698
|
+
}
|
|
699
|
+
entries() {
|
|
700
|
+
return this._state.entries();
|
|
701
|
+
}
|
|
702
|
+
from_entries(entries) {
|
|
703
|
+
this._state.from_entries(entries);
|
|
704
|
+
}
|
|
705
|
+
commit() {
|
|
706
|
+
if (this._commiting) throw new Error(`Can not "kernel.commit()" within commit`);
|
|
707
|
+
this._commiting = true;
|
|
708
|
+
this._before.dispatch();
|
|
709
|
+
for (const buffer of this._buffers) buffer.commit(this._state);
|
|
710
|
+
this._after.dispatch();
|
|
711
|
+
this._commiting = false;
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
// src/stillflow/operators.ts
|
|
715
|
+
function ref(path) {
|
|
716
|
+
return {
|
|
717
|
+
type: "ref",
|
|
718
|
+
path
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
function backref(path) {
|
|
722
|
+
return {
|
|
723
|
+
type: "backref",
|
|
724
|
+
path
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
function local(value) {
|
|
728
|
+
return {
|
|
729
|
+
type: "local",
|
|
730
|
+
value
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
function link(source) {
|
|
734
|
+
return {
|
|
735
|
+
type: "link",
|
|
736
|
+
source
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
function is(factory) {
|
|
740
|
+
return {
|
|
741
|
+
type: "is",
|
|
742
|
+
factory
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
var operators_default = {
|
|
746
|
+
ref,
|
|
747
|
+
backref,
|
|
748
|
+
link,
|
|
749
|
+
local,
|
|
750
|
+
is
|
|
751
|
+
};
|
|
752
|
+
// src/stillflow/variable.ts
|
|
753
|
+
var Variable = class {
|
|
754
|
+
_kernel;
|
|
755
|
+
_key;
|
|
756
|
+
constructor(_kernel, _key) {
|
|
757
|
+
this._kernel = _kernel;
|
|
758
|
+
this._key = _key;
|
|
759
|
+
}
|
|
760
|
+
write(value) {
|
|
761
|
+
this._kernel.write(this._key, value);
|
|
762
|
+
}
|
|
763
|
+
read() {
|
|
764
|
+
return this._kernel.read(this._key);
|
|
765
|
+
}
|
|
766
|
+
remove() {
|
|
767
|
+
this._kernel.remove(this._key);
|
|
768
|
+
}
|
|
769
|
+
ref() {
|
|
770
|
+
return operators_default.ref(this._key);
|
|
771
|
+
}
|
|
772
|
+
backref() {
|
|
773
|
+
return operators_default.backref(this._key);
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
// src/stillflow/tools/batcher.ts
|
|
777
|
+
var Batcher = class {
|
|
778
|
+
_strategy;
|
|
779
|
+
_commiting = false;
|
|
780
|
+
_tasks = /* @__PURE__ */ new Set();
|
|
781
|
+
constructor(_strategy) {
|
|
782
|
+
this._strategy = _strategy;
|
|
783
|
+
}
|
|
784
|
+
task(task) {
|
|
785
|
+
this._tasks.add(task);
|
|
786
|
+
if (this._commiting) return;
|
|
787
|
+
this._commiting = true;
|
|
788
|
+
this._strategy(() => {
|
|
789
|
+
const tasks = [...this._tasks];
|
|
790
|
+
this._tasks.clear();
|
|
791
|
+
for (const task of tasks) task();
|
|
792
|
+
this._commiting = false;
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
// src/stillflow/stillflow.ts
|
|
797
|
+
var Stillflow = class {
|
|
798
|
+
_state;
|
|
799
|
+
_options;
|
|
800
|
+
_views = /* @__PURE__ */ new Set();
|
|
801
|
+
_kernel;
|
|
802
|
+
_batcher;
|
|
803
|
+
constructor(_state, _options = { strategy: (site) => site() }) {
|
|
804
|
+
this._state = _state;
|
|
805
|
+
this._options = _options;
|
|
806
|
+
this._kernel = new Kernel(this._state);
|
|
807
|
+
this._batcher = new Batcher(this._options.strategy);
|
|
808
|
+
this._kernel.before(() => {
|
|
809
|
+
for (const view of [...this._views]) $ProcessWrite(this._kernel, view.meta.source, view);
|
|
810
|
+
});
|
|
811
|
+
this._kernel.after(() => {
|
|
812
|
+
for (const view of [...this._views]) $ProcessRead(this._kernel, view.meta.source, view);
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
on(site) {
|
|
816
|
+
return this._kernel.after(site);
|
|
817
|
+
}
|
|
818
|
+
factory() {
|
|
819
|
+
return new Factories();
|
|
820
|
+
}
|
|
821
|
+
buffer() {
|
|
822
|
+
return new Buffer$1();
|
|
823
|
+
}
|
|
824
|
+
bind(buffer) {
|
|
825
|
+
this._kernel.bind(buffer);
|
|
826
|
+
}
|
|
827
|
+
compile(source) {
|
|
828
|
+
const view = $Compile(this._kernel, source);
|
|
829
|
+
this._views.add(view);
|
|
830
|
+
return view;
|
|
831
|
+
}
|
|
832
|
+
instantiate(source, factory) {
|
|
833
|
+
const view = $Instantiate(source, factory);
|
|
834
|
+
this._views.delete(source);
|
|
835
|
+
this._views.add(view);
|
|
836
|
+
return view;
|
|
837
|
+
}
|
|
838
|
+
entries() {
|
|
839
|
+
return this._state.entries();
|
|
840
|
+
}
|
|
841
|
+
commit() {
|
|
842
|
+
this._batcher.task(() => this._kernel.commit());
|
|
843
|
+
}
|
|
844
|
+
variable(path) {
|
|
845
|
+
return new Variable(this._kernel, path);
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
// src/stillflow/index.ts
|
|
849
|
+
var stillflow_exports = /* @__PURE__ */ __exportAll({
|
|
850
|
+
Batcher: () => Batcher,
|
|
851
|
+
State: () => State,
|
|
852
|
+
Stillflow: () => Stillflow
|
|
853
|
+
});
|
|
854
|
+
// src/stillflow-runtime/dom.ts
|
|
855
|
+
var dom_exports = /* @__PURE__ */ __exportAll({
|
|
856
|
+
$: () => $,
|
|
857
|
+
$index: () => 0,
|
|
858
|
+
$it: () => $it,
|
|
859
|
+
$parent: () => $parent
|
|
860
|
+
});
|
|
861
|
+
function $(_) {
|
|
862
|
+
return () => () => {};
|
|
863
|
+
}
|
|
864
|
+
var $parent = {};
|
|
865
|
+
var $it = {};
|
|
866
|
+
// src/stillflow-serialize/serialize.ts
|
|
867
|
+
function serialize(value) {
|
|
868
|
+
if (value === null || value === void 0 || typeof value !== "object") return value;
|
|
869
|
+
const any_value = value;
|
|
870
|
+
if (typeof any_value.serialize === "function") return any_value.serialize((item) => serialize(item));
|
|
871
|
+
if (value instanceof Map) {
|
|
872
|
+
const out = {};
|
|
873
|
+
for (const [key, item] of value.entries()) if (typeof item !== "function") out[String(key)] = serialize(item);
|
|
874
|
+
return out;
|
|
875
|
+
}
|
|
876
|
+
if (Array.isArray(value)) return value.map(serialize);
|
|
877
|
+
const dto = {};
|
|
878
|
+
for (const key of Object.keys(value)) {
|
|
879
|
+
const field = value[key];
|
|
880
|
+
if (typeof field !== "function") dto[key] = serialize(field);
|
|
881
|
+
}
|
|
882
|
+
return dto;
|
|
883
|
+
}
|
|
884
|
+
// src/stillflow-serialize/deserialize.ts
|
|
885
|
+
function deserialize(target, snapshot) {
|
|
886
|
+
if (snapshot === null || typeof snapshot !== "object" || target === null || typeof target !== "object") return snapshot;
|
|
887
|
+
const any_target = target;
|
|
888
|
+
if (typeof any_target.deserialize === "function") {
|
|
889
|
+
any_target.deserialize(snapshot);
|
|
890
|
+
return target;
|
|
891
|
+
}
|
|
892
|
+
if (target instanceof Map) {
|
|
893
|
+
if (!Array.isArray(snapshot)) {
|
|
894
|
+
for (const [key, incoming] of Object.entries(snapshot)) {
|
|
895
|
+
const current = target.get(key);
|
|
896
|
+
if (current !== null) {
|
|
897
|
+
if (typeof current === "object") deserialize(current, incoming);
|
|
898
|
+
else target.set(key, incoming);
|
|
899
|
+
} else target.set(key, incoming);
|
|
900
|
+
}
|
|
901
|
+
return target;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
if (Array.isArray(target)) {
|
|
905
|
+
if (Array.isArray(snapshot)) {
|
|
906
|
+
target.length = 0;
|
|
907
|
+
target.push(...snapshot);
|
|
908
|
+
return target;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
for (const key of Object.keys(snapshot)) {
|
|
912
|
+
const incoming = snapshot[key];
|
|
913
|
+
const current = target[key];
|
|
914
|
+
if (current !== null) {
|
|
915
|
+
if (typeof current === "object") deserialize(current, incoming);
|
|
916
|
+
else target[key] = incoming;
|
|
917
|
+
} else target[key] = incoming;
|
|
918
|
+
}
|
|
919
|
+
return target;
|
|
920
|
+
}
|
|
921
|
+
// src/stillflow-serialize/index.ts
|
|
922
|
+
var stillflow_serialize_exports = /* @__PURE__ */ __exportAll({
|
|
923
|
+
deserialize: () => deserialize,
|
|
924
|
+
serialize: () => serialize
|
|
925
|
+
});
|
|
926
|
+
// src/stillflow-runtime/utilities/delegate-event.ts
|
|
927
|
+
var registered_events = /* @__PURE__ */ new Set();
|
|
928
|
+
function delegate_event(event_name) {
|
|
929
|
+
if (registered_events.has(event_name)) return;
|
|
930
|
+
registered_events.add(event_name);
|
|
931
|
+
const handler_key = `$$${event_name}`;
|
|
932
|
+
const data_key = `$$${event_name}_data`;
|
|
933
|
+
document.addEventListener(event_name, (event) => {
|
|
934
|
+
let target = event.target;
|
|
935
|
+
while (target && target !== document) {
|
|
936
|
+
const handler = target[handler_key];
|
|
937
|
+
if (handler !== void 0) {
|
|
938
|
+
const data = target[data_key];
|
|
939
|
+
if (data !== void 0) handler(event, data);
|
|
940
|
+
else handler(event);
|
|
941
|
+
if (event.cancelBubble) return;
|
|
942
|
+
}
|
|
943
|
+
target = target.parentNode;
|
|
944
|
+
}
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
// src/stillflow-runtime/utilities/reconcile-list.ts
|
|
948
|
+
function reconcile_list(root, items, createItem) {
|
|
949
|
+
const { swaps, addes, updates, removes, replaces, clears } = items.flush();
|
|
950
|
+
let controllers = root.sf_elements;
|
|
951
|
+
if (!controllers) controllers = root.sf_elements = [];
|
|
952
|
+
if (replaces) {
|
|
953
|
+
const fragment = document.createDocumentFragment();
|
|
954
|
+
const size = items.size;
|
|
955
|
+
controllers.length = size;
|
|
956
|
+
for (let i = 0; i < size; i++) {
|
|
957
|
+
const ctrl = createItem(items.at(i), i);
|
|
958
|
+
controllers[i] = ctrl;
|
|
959
|
+
fragment.appendChild(ctrl.element);
|
|
960
|
+
}
|
|
961
|
+
root.replaceChildren(fragment);
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
if (clears) {
|
|
965
|
+
root.textContent = String();
|
|
966
|
+
controllers.length = 0;
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
if (addes > 0) {
|
|
970
|
+
const fragment = document.createDocumentFragment();
|
|
971
|
+
const oldSize = controllers.length;
|
|
972
|
+
for (let i = 0; i < addes; i++) {
|
|
973
|
+
const ctrl = createItem(items.at(oldSize + i), oldSize + i);
|
|
974
|
+
controllers.push(ctrl);
|
|
975
|
+
fragment.appendChild(ctrl.element);
|
|
976
|
+
}
|
|
977
|
+
root.appendChild(fragment);
|
|
978
|
+
}
|
|
979
|
+
for (const [i, j] of swaps.entries()) {
|
|
980
|
+
const ctrlI = controllers[i];
|
|
981
|
+
const ctrlJ = controllers[j];
|
|
982
|
+
const nextI = ctrlI.element.nextSibling;
|
|
983
|
+
const nextJ = ctrlJ.element.nextSibling;
|
|
984
|
+
root.insertBefore(ctrlI.element, nextJ);
|
|
985
|
+
root.insertBefore(ctrlJ.element, nextI);
|
|
986
|
+
controllers[i] = ctrlJ;
|
|
987
|
+
controllers[j] = ctrlI;
|
|
988
|
+
}
|
|
989
|
+
for (const [id, item] of updates.entries()) controllers[id].patch(item);
|
|
990
|
+
if (removes.size > 0) {
|
|
991
|
+
for (const id of removes) {
|
|
992
|
+
controllers[id].element.remove();
|
|
993
|
+
controllers[id] = null;
|
|
994
|
+
}
|
|
995
|
+
let write = 0;
|
|
996
|
+
for (let read = 0; read < controllers.length; read++) {
|
|
997
|
+
const ctrl = controllers[read];
|
|
998
|
+
if (ctrl !== null) controllers[write++] = ctrl;
|
|
999
|
+
}
|
|
1000
|
+
controllers.length = write;
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
// src/stillflow-runtime/utilities/reconcile-if.ts
|
|
1004
|
+
function reconcile_if(anchor, active_index, factories, dirty) {
|
|
1005
|
+
if (anchor._sf_branch === active_index) {
|
|
1006
|
+
anchor._sf_ctrl?.patch(dirty);
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
if (anchor._sf_ctrl) {
|
|
1010
|
+
const old_els = anchor._sf_ctrl.elements;
|
|
1011
|
+
for (let i = 0; i < old_els.length; i++) old_els[i].parentNode?.removeChild(old_els[i]);
|
|
1012
|
+
anchor._sf_ctrl = null;
|
|
1013
|
+
}
|
|
1014
|
+
anchor._sf_branch = active_index;
|
|
1015
|
+
if (active_index >= 0 && active_index < factories.length) {
|
|
1016
|
+
const ctrl = factories[active_index]();
|
|
1017
|
+
anchor._sf_ctrl = ctrl;
|
|
1018
|
+
const parent = anchor.parentNode;
|
|
1019
|
+
const new_els = ctrl.elements;
|
|
1020
|
+
for (let i = 0; i < new_els.length; i++) parent.insertBefore(new_els[i], anchor);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
export { stillflow_collection_exports as collections, stillflow_exports as core, delegate_event, operators_default as operators, reconcile_if, reconcile_list, dom_exports as runtime, stillflow_serialize_exports as serializator };
|