stillflow.engine 0.1.9 → 0.2.1

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 (68) hide show
  1. package/README.md +14 -4
  2. package/dist/index.d.ts +2 -4
  3. package/dist/index.js +2 -3
  4. package/dist/stillflow-adapters/dom/aot/appliers/apply.d.ts +6 -0
  5. package/dist/stillflow-adapters/dom/{compiler/apply.generator.js → aot/appliers/apply.js} +52 -57
  6. package/dist/stillflow-adapters/dom/aot/compiler/compile.d.ts +11 -0
  7. package/dist/stillflow-adapters/dom/aot/compiler/compile.js +71 -0
  8. package/dist/stillflow-adapters/dom/aot/dom.delegator.d.ts +6 -0
  9. package/dist/stillflow-adapters/dom/aot/dom.delegator.js +39 -0
  10. package/dist/stillflow-adapters/dom/aot/dom.directives.d.ts +16 -0
  11. package/dist/stillflow-adapters/dom/aot/dom.operations.d.ts +3 -0
  12. package/dist/stillflow-adapters/dom/aot/dom.operations.js +1 -0
  13. package/dist/stillflow-adapters/dom/aot/dom.pool.d.ts +11 -0
  14. package/dist/stillflow-adapters/dom/aot/dom.pool.js +47 -0
  15. package/dist/stillflow-adapters/dom/aot/dom.resources.d.ts +3 -0
  16. package/dist/stillflow-adapters/dom/aot/dom.resources.js +3 -0
  17. package/dist/stillflow-adapters/dom/aot/dom.symbols.d.ts +5 -0
  18. package/dist/stillflow-adapters/dom/aot/dom.symbols.js +5 -0
  19. package/dist/stillflow-adapters/dom/{dom.d.ts → aot/dom.types.d.ts} +2 -2
  20. package/dist/stillflow-adapters/dom/aot/transformers/transform.d.ts +3 -0
  21. package/dist/stillflow-adapters/dom/aot/transformers/transform.js +42 -0
  22. package/dist/stillflow-adapters/dom/base.dom.d.ts +5 -3
  23. package/dist/stillflow-adapters/dom/base.dom.js +20 -12
  24. package/dist/stillflow-adapters/dom/description/describe.d.ts +1 -1
  25. package/dist/stillflow-adapters/dom/jsx.dom.d.ts +3 -3
  26. package/dist/stillflow-adapters/dom/jsx.dom.js +1 -1
  27. package/dist/stillflow-adapters/dom/properties/modifiers.d.ts +3 -4
  28. package/dist/stillflow-collection/index.d.ts +3 -0
  29. package/dist/stillflow-collection/index.js +2 -0
  30. package/dist/stillflow-examples/app.js +7 -5
  31. package/dist/stillflow-examples/test.js +4 -4
  32. package/package.json +1 -1
  33. package/dist/stillflow-adapters/dom/compiler/apply.d.ts +0 -37
  34. package/dist/stillflow-adapters/dom/compiler/apply.generator.d.ts +0 -5
  35. package/dist/stillflow-adapters/dom/compiler/apply.js +0 -289
  36. package/dist/stillflow-adapters/dom/compiler/compile.d.ts +0 -18
  37. package/dist/stillflow-adapters/dom/compiler/compile.js +0 -47
  38. package/dist/stillflow-adapters/dom/compiler/pool.d.ts +0 -21
  39. package/dist/stillflow-adapters/dom/compiler/pool.js +0 -91
  40. package/dist/stillflow-adapters/dom/compiler/test.d.ts +0 -1
  41. package/dist/stillflow-adapters/dom/compiler/test.js +0 -59
  42. package/dist/stillflow-adapters/dom/compiler/transform.d.ts +0 -2
  43. package/dist/stillflow-adapters/dom/compiler/transform.js +0 -41
  44. package/dist/stillflow-adapters/dom/dom.js +0 -1
  45. package/dist/stillflow-adapters/dom/index.d.ts +0 -15
  46. package/dist/stillflow-adapters/dom/index.js +0 -22
  47. package/dist/stillflow-adapters/dom/types.d.ts +0 -4
  48. package/dist/stillflow-adapters/dom/types.js +0 -1
  49. package/dist/stillflow-adapters/dom/vm/compile.d.ts +0 -8
  50. package/dist/stillflow-adapters/dom/vm/compile.js +0 -8
  51. package/dist/stillflow-adapters/dom/vm/instructions/instructions.d.ts +0 -1
  52. package/dist/stillflow-adapters/dom/vm/instructions/instructions.js +0 -1
  53. package/dist/stillflow-adapters/dom/vm/resources.d.ts +0 -1
  54. package/dist/stillflow-adapters/dom/vm/resources.js +0 -1
  55. package/dist/stillflow-examples/files.d.ts +0 -1
  56. package/dist/stillflow-examples/files.js +0 -29
  57. package/dist/stillflow-vm/analyze.d.ts +0 -7
  58. package/dist/stillflow-vm/analyze.js +0 -22
  59. package/dist/stillflow-vm/buffer.d.ts +0 -1
  60. package/dist/stillflow-vm/buffer.js +0 -1
  61. package/dist/stillflow-vm/instruction.d.ts +0 -1
  62. package/dist/stillflow-vm/instruction.js +0 -1
  63. package/dist/stillflow-vm/pool.d.ts +0 -1
  64. package/dist/stillflow-vm/pool.js +0 -1
  65. package/dist/stillflow-vm/resources.d.ts +0 -14
  66. package/dist/stillflow-vm/resources.js +0 -16
  67. /package/dist/stillflow-adapters/dom/{compiler/apply-generator.d.ts → aot/dom.directives.js} +0 -0
  68. /package/dist/stillflow-adapters/dom/{compiler/apply-generator.js → aot/dom.types.js} +0 -0
@@ -1,5 +1,5 @@
1
- import { AnyDOM } from "./types.js";
2
- import { FlushableCollection } from "../../index.js";
1
+ import { AnyDOM } from "./aot/dom.types.js";
2
+ import { collection } from "../../index.js";
3
3
  declare const DYNAMIC_PROPERTY_PREFIX = "sf:";
4
4
  declare const DELEGATE_EVENT_PROPERTY_PREFIX = "sf:on-";
5
5
  declare const COMMON_EVENT_PROPERTY_PREFIX = "on:";
@@ -9,7 +9,7 @@ type ElementStyles<K extends keyof HTMLElementTagNameMap> = {
9
9
  type ElementPropertiesWithoutStyles<K extends keyof HTMLElementTagNameMap> = Omit<HTMLElementTagNameMap[K], 'style'>;
10
10
  type ElementServicePropertiesWithoutPrefix<V> = {
11
11
  'if': (context: V) => boolean;
12
- 'for': (context: V) => FlushableCollection<unknown>;
12
+ 'for': (context: V) => collection.Flushable<unknown>;
13
13
  'each': () => AnyDOM<V>;
14
14
  };
15
15
  type ElementServicePropertiesWithPrefix<V> = {
@@ -80,7 +80,7 @@ for (const tag of HTML_TAGS) {
80
80
  properties.modifiers.text = (context) => {
81
81
  let contents = String();
82
82
  for (const site of dynamic_content) {
83
- contents += site(context);
83
+ contents += site(context).toString();
84
84
  }
85
85
  return contents;
86
86
  };
@@ -1,8 +1,7 @@
1
- import { FlushableCollection } from "../../../index.js";
2
- import { AnyDOM } from "../types.js";
1
+ import { collection } from "../../../index.js";
2
+ import { AnyDOM } from "../aot/dom.types.js";
3
3
  export type Modifiers<Context, K extends keyof HTMLElementTagNameMap = any> = Partial<{
4
4
  text: (context: Context) => string;
5
- lens: <Another>(context: Context) => Another;
6
5
  conditional: (context: Context) => boolean;
7
6
  events: Partial<{
8
7
  [L in keyof HTMLElementEventMap]: (event: HTMLElementEventMap[L], context: Context) => void;
@@ -11,7 +10,7 @@ export type Modifiers<Context, K extends keyof HTMLElementTagNameMap = any> = Pa
11
10
  [L in keyof HTMLElementTagNameMap[K]]: (context: Context) => string;
12
11
  }>;
13
12
  iterate: {
14
- select: <V>(context: Context) => FlushableCollection<V>;
13
+ select: <V>(context: Context) => collection.Flushable<V>;
15
14
  each: () => AnyDOM<any>;
16
15
  };
17
16
  }>;
@@ -0,0 +1,3 @@
1
+ export { FlushableCollection as Flushable } from "./flushable.js";
2
+ export { FenwickCollection as Fenwick } from "./fenwick.js";
3
+ export { AbstractCollection as Abstract } from './abstract/collection.js';
@@ -0,0 +1,2 @@
1
+ export { FlushableCollection as Flushable } from "./flushable.js";
2
+ export { FenwickCollection as Fenwick } from "./fenwick.js";
@@ -1,4 +1,4 @@
1
- import { Stillflow, State, Batcher, operators, adapters, FlushableCollection, FenwickCollection } from "../index.js";
1
+ import { Stillflow, State, Batcher, operators, adapters, collection } from "../index.js";
2
2
  import { buildData } from "./data.js";
3
3
  const { jsxdom, dom } = adapters;
4
4
  class BenchmarkApplicationController {
@@ -29,13 +29,13 @@ class BenchmarkApplicationController {
29
29
  current_id: current_id.backref()
30
30
  }),
31
31
  data: data.backref(),
32
- items: operators.is(FlushableCollection.name)
32
+ items: operators.is(collection.Flushable.name)
33
33
  };
34
34
  }
35
35
  constructor() {
36
- const collection = new FlushableCollection(new FenwickCollection(10000));
36
+ const col = new collection.Flushable(new collection.Fenwick(10000));
37
37
  const view = this._stillflow.compile(this.source);
38
- this._factory.add(FlushableCollection.name, view => collection);
38
+ this._factory.add(collection.Flushable.name, view => col);
39
39
  this._view = this._stillflow.instantiate(view, this._factory);
40
40
  }
41
41
  is_selected(id) {
@@ -52,7 +52,9 @@ class BenchmarkApplicationController {
52
52
  this.create(10000);
53
53
  }
54
54
  remove(id) {
55
- this._view.items.mark_removed(id);
55
+ for (let index = 0, size = this._view.items.size; index < size; index += 2) {
56
+ this._view.items.mark_removed(index);
57
+ }
56
58
  this._stillflow.commit();
57
59
  }
58
60
  select(id) {
@@ -1,12 +1,12 @@
1
- import { Stillflow, State, FenwickCollection, FlushableCollection, operators, adapters } from '../index.js';
1
+ import { Stillflow, State, collection, operators, adapters } from '../index.js';
2
2
  const { jsxdom, dom } = adapters;
3
3
  const state = new State();
4
4
  const stillflow = new Stillflow(state);
5
5
  const factory = stillflow.factory();
6
- factory.add(FlushableCollection.name, () => new FlushableCollection(new FenwickCollection(100)));
6
+ factory.add(collection.Flushable.name, () => new collection.Flushable(new collection.Fenwick(100)));
7
7
  const source = {
8
8
  input: stillflow.variable('input').backref(),
9
- items: operators.is(FlushableCollection.name)
9
+ items: operators.is(collection.Flushable.name)
10
10
  };
11
11
  const view = stillflow.compile(source);
12
12
  const instance = stillflow.instantiate(view, factory);
@@ -31,5 +31,5 @@ function App() {
31
31
  const { element: app, update } = dom.$(adapters.jsx(App, null));
32
32
  stillflow.on(() => update(instance));
33
33
  instance.input = String();
34
+ stillflow.commit();
34
35
  document.body.appendChild(app);
35
- update(instance);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stillflow.engine",
3
- "version": "0.1.9",
3
+ "version": "0.2.1",
4
4
  "description": "A headless, transaction-based UI engine with AOT compilation.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,37 +0,0 @@
1
- import { Template } from "./compile.js";
2
- export declare class Listeners {
3
- private _listeners;
4
- private _actives;
5
- private ensure;
6
- remove(root: HTMLElement): void;
7
- add(root: HTMLElement, type: string, listener: (event: Event, context: any) => void): void;
8
- }
9
- export declare class Pool {
10
- private _listeners;
11
- private static TIME_TO_EVICT;
12
- private _hots;
13
- private _colds;
14
- private _frame;
15
- constructor(_listeners: Listeners);
16
- private evict;
17
- private retrieve;
18
- get(): HTMLElement | undefined;
19
- add(root: HTMLElement): void;
20
- tick(): void;
21
- get listeners(): Listeners;
22
- }
23
- type Applier<V> = (root: HTMLElement, context: V) => void;
24
- export declare class Appliers<V> {
25
- private _pool;
26
- private _listeners;
27
- constructor(_pool: Pool);
28
- private find_element_by;
29
- private apply_conditional;
30
- private apply_text;
31
- private apply_properties;
32
- private apply_events;
33
- private apply_iterate;
34
- private markup;
35
- apply(template: Template<V>): Applier<V>;
36
- }
37
- export {};
@@ -1,5 +0,0 @@
1
- import { Pool } from "./pool.js";
2
- import { Template } from "./compile.js";
3
- type Applier<T> = (root: HTMLElement, context: T) => void;
4
- export declare function generate_applier<V>(template: Template<V>, pool: Pool): Applier<V>;
5
- export {};
@@ -1,289 +0,0 @@
1
- import { Compiler } from "./compile.js";
2
- import { transform } from "./transform.js";
3
- const SF_LISTENED = '__stillflow_listened__';
4
- const SF_CONTEXT = '__stillflow_context__';
5
- const SF_CACHE_TEXT = '__stillflow_cache_text__';
6
- const SF_CACHE = '__stillflow_cache__';
7
- export class Listeners {
8
- _listeners = new WeakMap();
9
- _actives = new Set();
10
- ensure(type) {
11
- if (this._actives.has(type)) {
12
- return;
13
- }
14
- this._actives.add(type);
15
- document.body.addEventListener(type, event => {
16
- let target = event.target;
17
- while (target && target !== document.body) {
18
- const listeners = this._listeners.get(target);
19
- if (listeners !== undefined) {
20
- const callback = listeners.get(type);
21
- callback?.(event, target[SF_CONTEXT]);
22
- if (event.cancelBubble) {
23
- break;
24
- }
25
- }
26
- target = target.parentElement;
27
- }
28
- });
29
- }
30
- remove(root) {
31
- this._listeners.delete(root);
32
- }
33
- add(root, type, listener) {
34
- const listeners = this._listeners.get(root) || new Map();
35
- listeners.set(type, listener);
36
- this._listeners.set(root, listeners);
37
- this.ensure(type);
38
- }
39
- }
40
- export class Pool {
41
- _listeners;
42
- static TIME_TO_EVICT = 2;
43
- _hots = [];
44
- _colds = [];
45
- _frame = 0;
46
- constructor(_listeners) {
47
- this._listeners = _listeners;
48
- }
49
- evict() {
50
- for (let id = this._hots.length - 1; id >= 0; id--) {
51
- const hot = this._hots[id];
52
- if (this._frame - hot.frame >= Pool.TIME_TO_EVICT) {
53
- this._listeners.remove(hot.root);
54
- const element = hot.root;
55
- element[SF_CONTEXT] = null;
56
- element[SF_LISTENED] = false;
57
- this._colds.push(new WeakRef(hot.root));
58
- this._hots.splice(id, 1);
59
- }
60
- }
61
- }
62
- retrieve() {
63
- if (this._hots.length <= 0) {
64
- while (this._colds.length > 0) {
65
- const cold = this._colds.pop();
66
- const element = cold.deref();
67
- if (element !== undefined) {
68
- this._hots.push({ root: element, frame: this._frame });
69
- return;
70
- }
71
- }
72
- }
73
- }
74
- get() {
75
- this.retrieve();
76
- const element = this._hots.pop();
77
- if (element === undefined) {
78
- return undefined;
79
- }
80
- element.frame = this._frame;
81
- return element.root;
82
- }
83
- add(root) {
84
- this._hots.push({ root, frame: this._frame });
85
- }
86
- tick() {
87
- this.evict();
88
- this._frame++;
89
- }
90
- get listeners() {
91
- return this._listeners;
92
- }
93
- }
94
- class CollectionApplier {
95
- _pool;
96
- _id;
97
- _payload;
98
- _compilation;
99
- _template;
100
- _elements = [];
101
- _appliers;
102
- _applier;
103
- constructor(_pool, _id, _payload) {
104
- this._pool = _pool;
105
- this._id = _id;
106
- this._payload = _payload;
107
- const node = this._payload.each();
108
- const compiler = new Compiler();
109
- const appliers = new Appliers(this._pool);
110
- const template = transform(node);
111
- const compilation = compiler.compile(node);
112
- this._appliers = appliers;
113
- this._compilation = compilation;
114
- this._template = template;
115
- }
116
- apply(root, context) {
117
- if (this._applier === undefined) {
118
- this._applier = this._appliers.apply(this._compilation);
119
- }
120
- const items = this._payload.select(context);
121
- const nodes = root[SF_CACHE];
122
- const target = nodes[this._id];
123
- const { replaces, clears, addes, swaps, removes, updates } = items.flush();
124
- if (replaces) {
125
- const items_count = items.size;
126
- const child_count = this._elements.length;
127
- const common_count = Math.min(items_count, child_count);
128
- for (let index = 0; index < common_count; index++) {
129
- this._applier(this._elements[index], items.at(index));
130
- }
131
- if (items_count < child_count) {
132
- for (let index = items_count; index < child_count; index++) {
133
- const element = this._elements[index];
134
- this._pool.add(element);
135
- element.remove();
136
- }
137
- this._elements.length = items_count;
138
- }
139
- else if (child_count < items_count) {
140
- const fragment = document.createDocumentFragment();
141
- const elements = new Array(items_count - child_count);
142
- for (let index = child_count; index < items_count; index++) {
143
- const element = this._pool.get() || this._template.cloneNode(true);
144
- this._applier(element, items.at(index));
145
- elements[index - child_count] = element;
146
- fragment.appendChild(element);
147
- }
148
- this._elements = this._elements.concat(elements);
149
- target.appendChild(fragment);
150
- }
151
- return;
152
- }
153
- if (clears) {
154
- const free = this._elements.splice(0);
155
- for (const element of free) {
156
- this._pool.add(element);
157
- }
158
- target.innerHTML = String();
159
- }
160
- if (addes > 0) {
161
- const fragment = document.createDocumentFragment();
162
- const elements = new Array(addes);
163
- for (let index = 0; index < addes; index++) {
164
- const element = this._template.cloneNode(true);
165
- this._applier(element, items.at(index));
166
- elements[index] = element;
167
- fragment.appendChild(element);
168
- }
169
- this._elements = this._elements.concat(elements);
170
- target.appendChild(fragment);
171
- }
172
- for (const [i, j] of swaps.entries()) {
173
- this._applier(this._elements[i], items.at(i));
174
- this._applier(this._elements[j], items.at(j));
175
- }
176
- for (const id of removes) {
177
- const element = this._elements[id];
178
- this._pool.add(element);
179
- element.remove();
180
- }
181
- for (const id of updates) {
182
- this._applier(this._elements[id], items.at(id));
183
- }
184
- }
185
- }
186
- export class Appliers {
187
- _pool;
188
- _listeners;
189
- constructor(_pool) {
190
- this._pool = _pool;
191
- this._listeners = this._pool.listeners;
192
- }
193
- find_element_by(root, path) {
194
- let current = root;
195
- for (let id = 0; id < path.length; id++) {
196
- current = current.children[path[id]];
197
- }
198
- return current;
199
- }
200
- apply_conditional(id, payload) {
201
- return (root, context) => {
202
- const nodes = root[SF_CACHE];
203
- const target = nodes[id];
204
- const condition = payload(context);
205
- target.style.display = condition ? String() : 'none';
206
- };
207
- }
208
- apply_text(id, payload) {
209
- return (root, context) => {
210
- const text = payload(context);
211
- const nodes = root[SF_CACHE_TEXT];
212
- const textnode = nodes[id];
213
- textnode.nodeValue = text;
214
- };
215
- }
216
- apply_properties(id, payload) {
217
- return (root, context) => {
218
- const nodes = root[SF_CACHE];
219
- const element = nodes[id];
220
- for (const key in payload) {
221
- element[key] = payload[key](context);
222
- }
223
- };
224
- }
225
- apply_events(id, payload) {
226
- return (root, context) => {
227
- const nodes = root[SF_CACHE];
228
- const element = nodes[id];
229
- if (element[SF_LISTENED]) {
230
- element[SF_CONTEXT] = context;
231
- return;
232
- }
233
- element[SF_LISTENED] = true;
234
- element[SF_CONTEXT] = context;
235
- for (let key in payload) {
236
- this._listeners.add(element, key, payload[key]);
237
- }
238
- };
239
- }
240
- apply_iterate(id, payload) {
241
- const appliers = new CollectionApplier(this._pool, id, payload);
242
- return (root, context) => appliers.apply(root, context);
243
- }
244
- markup(root, paths) {
245
- const node = root;
246
- if (node[SF_CACHE]) {
247
- return node[SF_CACHE];
248
- }
249
- const cache = new Array(paths.length);
250
- const text_cache = new Array(paths.length);
251
- for (let id = 0; id < paths.length; id++) {
252
- cache[id] = this.find_element_by(root, paths[id]);
253
- text_cache[id] = cache[id].firstChild;
254
- }
255
- node[SF_CACHE] = cache;
256
- node[SF_CACHE_TEXT] = text_cache;
257
- return cache;
258
- }
259
- apply(template) {
260
- const { instructions, paths } = template;
261
- const appliers = new Array(instructions.length);
262
- let fill_index = 0;
263
- for (let index = 0; index < instructions.length; index++) {
264
- const instruction = instructions[index];
265
- const id = instruction.id;
266
- if (instruction.text !== undefined) {
267
- appliers[fill_index++] = this.apply_text(id, instruction.text);
268
- }
269
- if (instruction.iterate !== undefined) {
270
- appliers[fill_index++] = this.apply_iterate(id, instruction.iterate);
271
- }
272
- if (instruction.events !== undefined) {
273
- appliers[fill_index++] = this.apply_events(id, instruction.events);
274
- }
275
- if (instruction.properties !== undefined) {
276
- appliers[fill_index++] = this.apply_properties(id, instruction.properties);
277
- }
278
- if (instruction.conditional !== undefined) {
279
- appliers[fill_index++] = this.apply_conditional(id, instruction.conditional);
280
- }
281
- }
282
- return (root, context) => {
283
- this.markup(root, paths);
284
- for (const applier of appliers) {
285
- applier(root, context);
286
- }
287
- };
288
- }
289
- }
@@ -1,18 +0,0 @@
1
- import { AnyDOM } from "../types.js";
2
- import { Modifiers } from "../properties/modifiers.js";
3
- export type Instructions<V> = Partial<{
4
- [L in keyof Modifiers<V>]: Modifiers<V>[L];
5
- }> & {
6
- id: number;
7
- };
8
- export type Template<V> = {
9
- paths: number[][];
10
- instructions: Instructions<V>[];
11
- };
12
- export declare class Compiler<V> {
13
- private ID_COUNTER;
14
- private _paths;
15
- private _instructions;
16
- private recursive_compile;
17
- compile(root: AnyDOM<V>): Template<V>;
18
- }
@@ -1,47 +0,0 @@
1
- export class Compiler {
2
- ID_COUNTER = 0;
3
- _paths = [];
4
- _instructions = [];
5
- recursive_compile(node, path) {
6
- const modifiers = node.properties.modifiers || {};
7
- const has_modifiers = modifiers.text !== undefined ||
8
- modifiers.properties !== undefined ||
9
- modifiers.events !== undefined ||
10
- modifiers.iterate !== undefined ||
11
- modifiers.conditional !== undefined;
12
- if (has_modifiers) {
13
- const current_id = this.ID_COUNTER++;
14
- this._paths.push(path);
15
- const instruction = { id: current_id };
16
- if (modifiers.text !== undefined) {
17
- instruction.text = modifiers.text;
18
- }
19
- if (modifiers.properties !== undefined) {
20
- instruction.properties = modifiers.properties;
21
- }
22
- if (modifiers.events !== undefined) {
23
- instruction.events = modifiers.events;
24
- }
25
- if (modifiers.iterate !== undefined) {
26
- instruction.iterate = modifiers.iterate;
27
- }
28
- if (modifiers.conditional !== undefined) {
29
- instruction.conditional = modifiers.conditional;
30
- }
31
- this._instructions.push(instruction);
32
- }
33
- for (let index = 0; index < node.children.length; index++) {
34
- this.recursive_compile(node.children[index], [...path, index]);
35
- }
36
- }
37
- compile(root) {
38
- this.ID_COUNTER = 0;
39
- this._instructions = [];
40
- this._paths = [];
41
- this.recursive_compile(root, []);
42
- return {
43
- paths: this._paths,
44
- instructions: this._instructions
45
- };
46
- }
47
- }
@@ -1,21 +0,0 @@
1
- export declare class Listeners {
2
- private _listeners;
3
- private _actives;
4
- private ensure;
5
- remove(root: HTMLElement): void;
6
- add(root: HTMLElement, type: string, listener: (event: Event, context: any) => void): void;
7
- }
8
- export declare class Pool {
9
- private _listeners;
10
- private static TIME_TO_EVICT;
11
- private _hots;
12
- private _colds;
13
- private _frame;
14
- constructor(_listeners: Listeners);
15
- private evict;
16
- private retrieve;
17
- get(): HTMLElement | undefined;
18
- add(root: HTMLElement): void;
19
- tick(): void;
20
- get listeners(): Listeners;
21
- }
@@ -1,91 +0,0 @@
1
- const SF_LISTENED = '__stillflow_listened__';
2
- const SF_CONTEXT = '__stillflow_context__';
3
- const SF_CACHE_TEXT = '__stillflow_cache_text__';
4
- const SF_CACHE = '__stillflow_cache__';
5
- export class Listeners {
6
- _listeners = new WeakMap();
7
- _actives = new Set();
8
- ensure(type) {
9
- if (this._actives.has(type)) {
10
- return;
11
- }
12
- this._actives.add(type);
13
- document.body.addEventListener(type, event => {
14
- let target = event.target;
15
- while (target && target !== document.body) {
16
- const listeners = this._listeners.get(target);
17
- if (listeners !== undefined) {
18
- const callback = listeners.get(type);
19
- callback?.(event, target[SF_CONTEXT]);
20
- if (event.cancelBubble) {
21
- break;
22
- }
23
- }
24
- target = target.parentElement;
25
- }
26
- });
27
- }
28
- remove(root) {
29
- this._listeners.delete(root);
30
- }
31
- add(root, type, listener) {
32
- const listeners = this._listeners.get(root) || new Map();
33
- listeners.set(type, listener);
34
- this._listeners.set(root, listeners);
35
- this.ensure(type);
36
- }
37
- }
38
- export class Pool {
39
- _listeners;
40
- static TIME_TO_EVICT = 2;
41
- _hots = [];
42
- _colds = [];
43
- _frame = 0;
44
- constructor(_listeners) {
45
- this._listeners = _listeners;
46
- }
47
- evict() {
48
- for (let id = this._hots.length - 1; id >= 0; id--) {
49
- const hot = this._hots[id];
50
- if (this._frame - hot.frame >= Pool.TIME_TO_EVICT) {
51
- this._listeners.remove(hot.root);
52
- const element = hot.root;
53
- element[SF_CONTEXT] = null;
54
- element[SF_LISTENED] = false;
55
- this._colds.push(new WeakRef(hot.root));
56
- this._hots.splice(id, 1);
57
- }
58
- }
59
- }
60
- retrieve() {
61
- if (this._hots.length <= 0) {
62
- while (this._colds.length > 0) {
63
- const cold = this._colds.pop();
64
- const element = cold.deref();
65
- if (element !== undefined) {
66
- this._hots.push({ root: element, frame: this._frame });
67
- return;
68
- }
69
- }
70
- }
71
- }
72
- get() {
73
- this.retrieve();
74
- const element = this._hots.pop();
75
- if (element === undefined) {
76
- return undefined;
77
- }
78
- element.frame = this._frame;
79
- return element.root;
80
- }
81
- add(root) {
82
- this._hots.push({ root, frame: this._frame });
83
- }
84
- tick() {
85
- this.evict();
86
- this._frame++;
87
- }
88
- get listeners() {
89
- return this._listeners;
90
- }
91
- }
@@ -1 +0,0 @@
1
- export {};