stillflow.engine 0.0.0-stage → 0.1.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 (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +114 -2
  3. package/dist/index.d.ts +9 -0
  4. package/dist/index.js +8 -0
  5. package/dist/stillflow/abstracts/IR.d.ts +7 -0
  6. package/dist/stillflow/abstracts/IR.js +1 -0
  7. package/dist/stillflow/abstracts/meta.d.ts +8 -0
  8. package/dist/stillflow/abstracts/meta.js +1 -0
  9. package/dist/stillflow/abstracts/operators.d.ts +22 -0
  10. package/dist/stillflow/abstracts/operators.js +1 -0
  11. package/dist/stillflow/abstracts/state.d.ts +7 -0
  12. package/dist/stillflow/abstracts/state.js +1 -0
  13. package/dist/stillflow/abstracts/view.d.ts +8 -0
  14. package/dist/stillflow/abstracts/view.js +1 -0
  15. package/dist/stillflow/compiler/compile.d.ts +11 -0
  16. package/dist/stillflow/compiler/compile.js +84 -0
  17. package/dist/stillflow/compiler/instantiate.d.ts +3 -0
  18. package/dist/stillflow/compiler/instantiate.js +40 -0
  19. package/dist/stillflow/factories/factories.d.ts +10 -0
  20. package/dist/stillflow/factories/factories.js +20 -0
  21. package/dist/stillflow/kernel/buffer.d.ts +9 -0
  22. package/dist/stillflow/kernel/buffer.js +13 -0
  23. package/dist/stillflow/kernel/kernel.d.ts +20 -0
  24. package/dist/stillflow/kernel/kernel.js +44 -0
  25. package/dist/stillflow/kernel/signal.d.ts +5 -0
  26. package/dist/stillflow/kernel/signal.js +12 -0
  27. package/dist/stillflow/operators.d.ts +15 -0
  28. package/dist/stillflow/operators.js +31 -0
  29. package/dist/stillflow/state.d.ts +9 -0
  30. package/dist/stillflow/state.js +12 -0
  31. package/dist/stillflow/stillflow.d.ts +27 -0
  32. package/dist/stillflow/stillflow.js +59 -0
  33. package/dist/stillflow/tools/batcher.d.ts +8 -0
  34. package/dist/stillflow/tools/batcher.js +17 -0
  35. package/dist/stillflow/variable.d.ts +12 -0
  36. package/dist/stillflow/variable.js +24 -0
  37. package/dist/stillflow-adapters/binding.d.ts +4 -0
  38. package/dist/stillflow-adapters/binding.js +1 -0
  39. package/dist/stillflow-adapters/dom/compiler/apply.d.ts +16 -0
  40. package/dist/stillflow-adapters/dom/compiler/apply.js +212 -0
  41. package/dist/stillflow-adapters/dom/compiler/compile.d.ts +18 -0
  42. package/dist/stillflow-adapters/dom/compiler/compile.js +47 -0
  43. package/dist/stillflow-adapters/dom/compiler/transform.d.ts +2 -0
  44. package/dist/stillflow-adapters/dom/compiler/transform.js +41 -0
  45. package/dist/stillflow-adapters/dom/description/describe.d.ts +3 -0
  46. package/dist/stillflow-adapters/dom/description/describe.js +6 -0
  47. package/dist/stillflow-adapters/dom/dom.d.ts +4 -0
  48. package/dist/stillflow-adapters/dom/dom.js +1 -0
  49. package/dist/stillflow-adapters/dom/index.d.ts +15 -0
  50. package/dist/stillflow-adapters/dom/index.js +22 -0
  51. package/dist/stillflow-adapters/dom/jsx.dom.d.ts +32 -0
  52. package/dist/stillflow-adapters/dom/jsx.dom.js +77 -0
  53. package/dist/stillflow-adapters/dom/properties/modifiers.d.ts +17 -0
  54. package/dist/stillflow-adapters/dom/properties/modifiers.js +1 -0
  55. package/dist/stillflow-adapters/dom/properties/properties.d.ts +15 -0
  56. package/dist/stillflow-adapters/dom/properties/properties.js +1 -0
  57. package/dist/stillflow-adapters/dom/tags.d.ts +7 -0
  58. package/dist/stillflow-adapters/dom/tags.js +5 -0
  59. package/dist/stillflow-adapters/index.d.ts +3 -0
  60. package/dist/stillflow-adapters/index.js +3 -0
  61. package/dist/stillflow-adapters/runtime/jsx.runtime.d.ts +2 -0
  62. package/dist/stillflow-adapters/runtime/jsx.runtime.js +3 -0
  63. package/dist/stillflow-collection/abstract/collection.d.ts +15 -0
  64. package/dist/stillflow-collection/abstract/collection.js +1 -0
  65. package/dist/stillflow-collection/delta.d.ts +10 -0
  66. package/dist/stillflow-collection/delta.js +18 -0
  67. package/dist/stillflow-collection/fenwick.d.ts +24 -0
  68. package/dist/stillflow-collection/fenwick.js +102 -0
  69. package/dist/stillflow-collection/flushable.d.ts +21 -0
  70. package/dist/stillflow-collection/flushable.js +70 -0
  71. package/dist/stillflow-collection/utilities/disjointed-set.d.ts +10 -0
  72. package/dist/stillflow-collection/utilities/disjointed-set.js +45 -0
  73. package/dist/stillflow-collection/utilities/fenwick-tree.d.ts +9 -0
  74. package/dist/stillflow-collection/utilities/fenwick-tree.js +27 -0
  75. package/dist/stillflow-collection/utilities/interval-merger.d.ts +7 -0
  76. package/dist/stillflow-collection/utilities/interval-merger.js +70 -0
  77. package/dist/stillflow-collection/utilities/range-fenwick-tree.d.ts +11 -0
  78. package/dist/stillflow-collection/utilities/range-fenwick-tree.js +28 -0
  79. package/dist/stillflow-examples/app.d.ts +1 -0
  80. package/dist/stillflow-examples/app.js +140 -0
  81. package/dist/stillflow-examples/data.d.ts +5 -0
  82. package/dist/stillflow-examples/data.js +73 -0
  83. package/dist/stillflow-examples/test.d.ts +1 -0
  84. package/dist/stillflow-examples/test.js +35 -0
  85. package/dist/stillflow-scripts/gen-tags.d.ts +1 -0
  86. package/dist/stillflow-scripts/gen-tags.js +50 -0
  87. package/dist/stillflow-vm/analyze.d.ts +7 -0
  88. package/dist/stillflow-vm/analyze.js +22 -0
  89. package/dist/stillflow-vm/buffer.d.ts +1 -0
  90. package/dist/stillflow-vm/buffer.js +1 -0
  91. package/dist/stillflow-vm/instruction.d.ts +1 -0
  92. package/dist/stillflow-vm/instruction.js +1 -0
  93. package/dist/stillflow-vm/pool.d.ts +1 -0
  94. package/dist/stillflow-vm/pool.js +1 -0
  95. package/dist/stillflow-vm/resources.d.ts +14 -0
  96. package/dist/stillflow-vm/resources.js +16 -0
  97. package/package.json +37 -3
@@ -0,0 +1,59 @@
1
+ import { $Compile, $ProcessRead, $ProcessWrite } from "./compiler/compile.js";
2
+ import { $Instantiate } from "./compiler/instantiate.js";
3
+ import { Factories } from "./factories/factories.js";
4
+ import { Buffer } from "./kernel/buffer.js";
5
+ import { Kernel } from "./kernel/kernel.js";
6
+ import { Variable } from "./variable.js";
7
+ import { Batcher } from "./tools/batcher.js";
8
+ export class Stillflow {
9
+ _state;
10
+ _options;
11
+ _views = new Set();
12
+ _kernel;
13
+ _batcher;
14
+ constructor(_state, _options = { strategy: (site) => site() }) {
15
+ this._state = _state;
16
+ this._options = _options;
17
+ this._kernel = new Kernel(this._state);
18
+ this._batcher = new Batcher(this._options.strategy);
19
+ this._kernel.before(() => {
20
+ for (const view of [...this._views]) {
21
+ $ProcessWrite(this._kernel, view.meta.source, view);
22
+ }
23
+ });
24
+ this._kernel.after(() => {
25
+ for (const view of [...this._views]) {
26
+ $ProcessRead(this._kernel, view.meta.source, view);
27
+ }
28
+ });
29
+ }
30
+ on(site) {
31
+ return this._kernel.after(site);
32
+ }
33
+ factory() {
34
+ return new Factories();
35
+ }
36
+ buffer() {
37
+ return new Buffer();
38
+ }
39
+ bind(buffer) {
40
+ this._kernel.bind(buffer);
41
+ }
42
+ compile(source) {
43
+ const view = $Compile(this._kernel, source);
44
+ this._views.add(view);
45
+ return view;
46
+ }
47
+ instantiate(source, factory) {
48
+ const view = $Instantiate(source, factory);
49
+ this._views.delete(source);
50
+ this._views.add(view);
51
+ return view;
52
+ }
53
+ commit() {
54
+ this._batcher.task(() => this._kernel.commit());
55
+ }
56
+ variable(path) {
57
+ return new Variable(this._kernel, path);
58
+ }
59
+ }
@@ -0,0 +1,8 @@
1
+ type Strategy = (site: () => void) => void;
2
+ export declare class Batcher {
3
+ private _strategy;
4
+ private _commiting;
5
+ constructor(_strategy: Strategy);
6
+ task(task: () => void): void;
7
+ }
8
+ export {};
@@ -0,0 +1,17 @@
1
+ export class Batcher {
2
+ _strategy;
3
+ _commiting = false;
4
+ constructor(_strategy) {
5
+ this._strategy = _strategy;
6
+ }
7
+ task(task) {
8
+ if (this._commiting) {
9
+ return;
10
+ }
11
+ this._commiting = true;
12
+ this._strategy(() => {
13
+ task();
14
+ this._commiting = false;
15
+ });
16
+ }
17
+ }
@@ -0,0 +1,12 @@
1
+ import { Backref, Ref } from "./abstracts/operators.js";
2
+ import { Kernel } from "./kernel/kernel.js";
3
+ export declare class Variable<T extends Record<string, any>, P extends keyof T> {
4
+ private _kernel;
5
+ private _key;
6
+ constructor(_kernel: Kernel<T>, _key: P);
7
+ write(value: T[P]): void;
8
+ read(): T[P];
9
+ remove(): void;
10
+ ref(): Ref<T, P>;
11
+ backref(): Backref<T, P>;
12
+ }
@@ -0,0 +1,24 @@
1
+ import operators from "./operators.js";
2
+ export class Variable {
3
+ _kernel;
4
+ _key;
5
+ constructor(_kernel, _key) {
6
+ this._kernel = _kernel;
7
+ this._key = _key;
8
+ }
9
+ write(value) {
10
+ this._kernel.write(this._key, value);
11
+ }
12
+ read() {
13
+ return this._kernel.read(this._key);
14
+ }
15
+ remove() {
16
+ this._kernel.remove(this._key);
17
+ }
18
+ ref() {
19
+ return operators.ref(this._key);
20
+ }
21
+ backref() {
22
+ return operators.backref(this._key);
23
+ }
24
+ }
@@ -0,0 +1,4 @@
1
+ export type Binding<P> = {
2
+ children: Binding<P>[];
3
+ properties: P;
4
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { Template } from "./compile.js";
2
+ type Applier<V> = (root: HTMLElement, context: V) => void;
3
+ export declare class Appliers<V> {
4
+ private _listeners;
5
+ private _actives;
6
+ private ensure_listener;
7
+ private find_element_by;
8
+ private apply_conditional;
9
+ private apply_text;
10
+ private apply_properties;
11
+ private apply_events;
12
+ private apply_iterate;
13
+ private markup;
14
+ apply(template: Template<V>): Applier<V>;
15
+ }
16
+ export {};
@@ -0,0 +1,212 @@
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 = '__stillflow_cache__';
6
+ export class Appliers {
7
+ _listeners = new WeakMap();
8
+ _actives = new Set();
9
+ ensure_listener(name) {
10
+ if (this._actives.has(name)) {
11
+ return;
12
+ }
13
+ this._actives.add(name);
14
+ document.body.addEventListener(name, event => {
15
+ let target = event.target;
16
+ while (target && target !== document.body) {
17
+ const listeners = this._listeners.get(target);
18
+ if (listeners !== undefined) {
19
+ const callback = listeners.get(name);
20
+ callback?.(event, target[SF_CONTEXT]);
21
+ if (event.cancelBubble) {
22
+ break;
23
+ }
24
+ }
25
+ target = target.parentElement;
26
+ }
27
+ });
28
+ }
29
+ find_element_by(root, path) {
30
+ let current = root;
31
+ for (let id = 0; id < path.length; id++) {
32
+ current = current.children[path[id]];
33
+ }
34
+ return current;
35
+ }
36
+ apply_conditional(id, payload) {
37
+ return (root, context) => {
38
+ const nodes = root[SF_CACHE];
39
+ const target = nodes[id];
40
+ const condition = payload(context);
41
+ target.style.display = condition ? String() : 'none';
42
+ };
43
+ }
44
+ apply_text(id, payload) {
45
+ return (root, context) => {
46
+ const text = payload(context);
47
+ const nodes = root[SF_CACHE];
48
+ const element = nodes[id];
49
+ element.firstChild.nodeValue = text;
50
+ };
51
+ }
52
+ apply_properties(id, payload) {
53
+ return (root, context) => {
54
+ const nodes = root[SF_CACHE];
55
+ const element = nodes[id];
56
+ for (const key in payload) {
57
+ element[key] = payload[key](context);
58
+ }
59
+ };
60
+ }
61
+ apply_events(id, payload) {
62
+ return (root, context) => {
63
+ const nodes = root[SF_CACHE];
64
+ const element = nodes[id];
65
+ if (element[SF_LISTENED]) {
66
+ element[SF_CONTEXT] = context;
67
+ return;
68
+ }
69
+ element[SF_LISTENED] = true;
70
+ element[SF_CONTEXT] = context;
71
+ const listeners = this._listeners.get(element) || new Map();
72
+ for (let key in payload) {
73
+ listeners.set(key, payload[key]);
74
+ this.ensure_listener(key);
75
+ }
76
+ this._listeners.set(element, listeners);
77
+ };
78
+ }
79
+ apply_iterate(id, payload) {
80
+ const SPACE = " ";
81
+ const node = payload.each();
82
+ const compiler = new Compiler();
83
+ const appliers = new Appliers();
84
+ const template = transform(node);
85
+ const compilation = compiler.compile(node);
86
+ const applier = appliers.apply(compilation);
87
+ let bindings = new Array();
88
+ let pool = new Array();
89
+ return (root, context) => {
90
+ const items = payload.select(context);
91
+ const nodes = root[SF_CACHE];
92
+ const target = nodes[id];
93
+ const { replaces, clears, addes, swaps, removes, updates } = items.flush();
94
+ if (replaces) {
95
+ const items_count = items.size;
96
+ const child_count = bindings.length;
97
+ const common_count = Math.min(items_count, child_count);
98
+ for (let index = 0; index < common_count; index++) {
99
+ applier(bindings[index], items.at(index));
100
+ }
101
+ if (items_count < child_count) {
102
+ for (let index = items_count; index < child_count; index++) {
103
+ pool.push(bindings[index]);
104
+ bindings[index].remove();
105
+ }
106
+ bindings.length = items_count;
107
+ }
108
+ else if (child_count < items_count) {
109
+ const fragment = document.createDocumentFragment();
110
+ const elements = new Array(items_count - child_count);
111
+ for (let index = child_count; index < items_count; index++) {
112
+ const element = pool.pop() || template.cloneNode(true);
113
+ applier(element, items.at(index));
114
+ elements[index - child_count] = element;
115
+ fragment.appendChild(element);
116
+ }
117
+ bindings = bindings.concat(elements);
118
+ target.appendChild(fragment);
119
+ }
120
+ return;
121
+ }
122
+ if (clears) {
123
+ pool = pool.concat(bindings.splice(0));
124
+ target.innerHTML = SPACE;
125
+ }
126
+ if (addes > 0) {
127
+ const fragment = document.createDocumentFragment();
128
+ const old_size = bindings.length;
129
+ const elements = new Array(addes);
130
+ for (let index = 0; index < addes; index++) {
131
+ const element = template.cloneNode(true);
132
+ applier(element, items.at(index + old_size));
133
+ elements[index] = element;
134
+ fragment.appendChild(element);
135
+ }
136
+ bindings = bindings.concat(elements);
137
+ target.appendChild(fragment);
138
+ }
139
+ for (const [i, j] of swaps.entries()) {
140
+ applier(bindings[i], items.at(i));
141
+ applier(bindings[j], items.at(j));
142
+ }
143
+ for (const id of removes) {
144
+ const element = bindings[id];
145
+ pool.push(element);
146
+ element.remove();
147
+ }
148
+ for (const id of updates) {
149
+ applier(bindings[id], items.at(id));
150
+ }
151
+ };
152
+ }
153
+ markup(root, paths) {
154
+ const node = root;
155
+ if (node[SF_CACHE]) {
156
+ return node[SF_CACHE];
157
+ }
158
+ const cache = new Array(paths.length);
159
+ for (let id = 0; id < paths.length; id++) {
160
+ cache[id] = this.find_element_by(root, paths[id]);
161
+ }
162
+ node[SF_CACHE] = cache;
163
+ return cache;
164
+ }
165
+ apply(template) {
166
+ const { instructions, paths } = template;
167
+ const appliers = {
168
+ text: new Array(),
169
+ iterate: new Array(),
170
+ events: new Array(),
171
+ properties: new Array(),
172
+ conditional: new Array()
173
+ };
174
+ for (let index = 0; index < instructions.length; index++) {
175
+ const instruction = instructions[index];
176
+ const id = instruction.id;
177
+ if (instruction.text !== undefined) {
178
+ appliers.text.push(this.apply_text(id, instruction.text));
179
+ }
180
+ if (instruction.iterate !== undefined) {
181
+ appliers.iterate.push(this.apply_iterate(id, instruction.iterate));
182
+ }
183
+ if (instruction.events !== undefined) {
184
+ appliers.events.push(this.apply_events(id, instruction.events));
185
+ }
186
+ if (instruction.properties !== undefined) {
187
+ appliers.properties.push(this.apply_properties(id, instruction.properties));
188
+ }
189
+ if (instruction.conditional !== undefined) {
190
+ appliers.conditional.push(this.apply_conditional(id, instruction.conditional));
191
+ }
192
+ }
193
+ return (root, context) => {
194
+ this.markup(root, paths);
195
+ for (const applier of appliers.text) {
196
+ applier(root, context);
197
+ }
198
+ for (const applier of appliers.events) {
199
+ applier(root, context);
200
+ }
201
+ for (const applier of appliers.properties) {
202
+ applier(root, context);
203
+ }
204
+ for (const applier of appliers.iterate) {
205
+ applier(root, context);
206
+ }
207
+ for (const applier of appliers.conditional) {
208
+ applier(root, context);
209
+ }
210
+ };
211
+ }
212
+ }
@@ -0,0 +1,18 @@
1
+ import { AnyDOM } from "../dom.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
+ }
@@ -0,0 +1,47 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ import { DOM } from "../dom.js";
2
+ export declare function transform<V, K extends keyof HTMLElementTagNameMap>(description: DOM<V, K>): HTMLElementTagNameMap[K];
@@ -0,0 +1,41 @@
1
+ function apply_text(description, root) {
2
+ const text = description.properties.text || String();
3
+ if (root.firstChild === null || root.firstChild.nodeType !== Node.TEXT_NODE) {
4
+ root.insertBefore(document.createTextNode(text), null);
5
+ return;
6
+ }
7
+ root.firstChild.nodeValue = text;
8
+ }
9
+ function apply_properties(description, root) {
10
+ let { properties } = description.properties;
11
+ properties = properties || {};
12
+ for (const key in properties) {
13
+ root[key] = properties[key];
14
+ }
15
+ }
16
+ function apply_styles(description, root) {
17
+ let { styles } = description.properties;
18
+ styles = styles || {};
19
+ for (const key in styles) {
20
+ root.style[key] = styles[key];
21
+ }
22
+ }
23
+ function apply_events(description, root) {
24
+ let { events } = description.properties;
25
+ events = events || {};
26
+ for (const key in events) {
27
+ root.addEventListener(key, events[key]);
28
+ }
29
+ }
30
+ export function transform(description) {
31
+ let { name } = description.properties;
32
+ const root = document.createElement(name);
33
+ apply_properties(description, root);
34
+ apply_styles(description, root);
35
+ apply_events(description, root);
36
+ apply_text(description, root);
37
+ for (const child of description.children) {
38
+ root.appendChild(transform(child));
39
+ }
40
+ return root;
41
+ }
@@ -0,0 +1,3 @@
1
+ import { AnyDOM } from "../dom.js";
2
+ import { Properties } from "../properties/properties.js";
3
+ export declare function describe<V, K extends keyof HTMLElementTagNameMap>(properties: Properties<V, K>, children: AnyDOM<V>[]): AnyDOM<V>;
@@ -0,0 +1,6 @@
1
+ export function describe(properties, children) {
2
+ return {
3
+ children,
4
+ properties
5
+ };
6
+ }
@@ -0,0 +1,4 @@
1
+ import { Binding } from "../binding.js";
2
+ import { Properties } from "./properties/properties.js";
3
+ export type DOM<V, K extends keyof HTMLElementTagNameMap> = Binding<Properties<V, K>>;
4
+ export type AnyDOM<V> = Binding<Properties<V, keyof HTMLElementTagNameMap>>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import { AnyDOM } from "./dom.js";
2
+ import { Properties } from "./properties/properties.js";
3
+ import { Binding } from "../binding.js";
4
+ type PropertiesWithoutServices<V, K extends keyof HTMLElementTagNameMap> = Omit<Properties<V, K>, 'name'>;
5
+ export type DOMRegistry = {
6
+ [K in keyof HTMLElementTagNameMap]: <V>(properties: Partial<PropertiesWithoutServices<V, K>>, children?: Binding<any>[]) => AnyDOM<V>;
7
+ };
8
+ export declare const DOM_REGISTRY: DOMRegistry;
9
+ export declare class DOMAdapter<V> {
10
+ $(root: AnyDOM<V>): {
11
+ element: HTMLAnchorElement | HTMLAreaElement | HTMLAudioElement | HTMLBRElement | HTMLBaseElement | HTMLBodyElement | HTMLButtonElement | HTMLCanvasElement | HTMLDListElement | HTMLDataElement | HTMLDataListElement | HTMLDetailsElement | HTMLDialogElement | HTMLDivElement | HTMLElement | HTMLEmbedElement | HTMLFieldSetElement | HTMLFormElement | HTMLHRElement | HTMLHeadElement | HTMLHeadingElement | HTMLHtmlElement | HTMLIFrameElement | HTMLImageElement | HTMLInputElement | HTMLLIElement | HTMLLabelElement | HTMLLegendElement | HTMLLinkElement | HTMLMapElement | HTMLMenuElement | HTMLMetaElement | HTMLMeterElement | HTMLModElement | HTMLOListElement | HTMLObjectElement | HTMLOptGroupElement | HTMLOptionElement | HTMLOutputElement | HTMLParagraphElement | HTMLPictureElement | HTMLPreElement | HTMLProgressElement | HTMLQuoteElement | HTMLScriptElement | HTMLSelectElement | HTMLSlotElement | HTMLSourceElement | HTMLSpanElement | HTMLStyleElement | HTMLTableCaptionElement | HTMLTableCellElement | HTMLTableColElement | HTMLTableElement | HTMLTableRowElement | HTMLTableSectionElement | HTMLTemplateElement | HTMLTextAreaElement | HTMLTimeElement | HTMLTitleElement | HTMLTrackElement | HTMLUListElement | HTMLVideoElement;
12
+ update: (context: V) => void;
13
+ };
14
+ }
15
+ export {};
@@ -0,0 +1,22 @@
1
+ import { HTML_TAGS } from "./tags.js";
2
+ import { Compiler } from "./compiler/compile.js";
3
+ import { Appliers } from "./compiler/apply.js";
4
+ import { transform } from "./compiler/transform.js";
5
+ import { describe } from "./description/describe.js";
6
+ export const DOM_REGISTRY = Object.create(null);
7
+ export class DOMAdapter {
8
+ $(root) {
9
+ const element = transform(root);
10
+ const compiler = new Compiler();
11
+ const compilation = compiler.compile(root);
12
+ const appliers = new Appliers();
13
+ const applier = appliers.apply(compilation);
14
+ const update = (context) => applier(element, context);
15
+ return { element, update };
16
+ }
17
+ }
18
+ for (const tag of HTML_TAGS) {
19
+ DOM_REGISTRY[tag] = (properties, children = []) => {
20
+ return describe({ ...properties, name: tag }, children);
21
+ };
22
+ }
@@ -0,0 +1,32 @@
1
+ import { AnyDOM } from "./dom.js";
2
+ import { FlushableCollection } from "../../index.js";
3
+ declare const DYNAMIC_PROPERTY_PREFIX = "sf:";
4
+ declare const DELEGATE_EVENT_PROPERTY_PREFIX = "sf:on-";
5
+ declare const COMMON_EVENT_PROPERTY_PREFIX = "on:";
6
+ type ElementStyles<K extends keyof HTMLElementTagNameMap> = {
7
+ styles: HTMLElementTagNameMap[K]['style'];
8
+ };
9
+ type ElementPropertiesWithoutStyles<K extends keyof HTMLElementTagNameMap> = Omit<HTMLElementTagNameMap[K], 'style'>;
10
+ type ElementServicePropertiesWithoutPrefix<V> = {
11
+ 'if': (context: V) => boolean;
12
+ 'for': (context: V) => FlushableCollection<unknown>;
13
+ 'each': () => AnyDOM<V>;
14
+ };
15
+ type ElementServicePropertiesWithPrefix<V> = {
16
+ [K in keyof ElementServicePropertiesWithoutPrefix<V> as `${typeof DYNAMIC_PROPERTY_PREFIX}${K}`]: ElementServicePropertiesWithoutPrefix<V>[K];
17
+ };
18
+ type ElementDynamicPropertiesWithPrefix<V, K extends keyof HTMLElementTagNameMap> = {
19
+ [L in (keyof HTMLElementTagNameMap[K]) & string as `${typeof DYNAMIC_PROPERTY_PREFIX}${L}`]: (context: V) => HTMLElementTagNameMap[K][L];
20
+ };
21
+ type ElementDelegateEventsWithPrefix<V> = {
22
+ [L in keyof HTMLElementEventMap as `${typeof DELEGATE_EVENT_PROPERTY_PREFIX}${L}`]: (event: HTMLElementEventMap[L], context: V) => void;
23
+ };
24
+ type ElementEventMap<V> = {
25
+ [K in keyof HTMLElementEventMap as `${typeof COMMON_EVENT_PROPERTY_PREFIX}${K}`]: (event: HTMLElementEventMap[K], context: V) => void;
26
+ };
27
+ type JSXElementProperties<V, K extends keyof HTMLElementTagNameMap> = ElementEventMap<V> & ElementStyles<K> & ElementPropertiesWithoutStyles<K> & ElementDynamicPropertiesWithPrefix<V, K> & ElementServicePropertiesWithPrefix<V> & ElementDelegateEventsWithPrefix<V>;
28
+ export type JSXDOMRegistry = {
29
+ [K in keyof HTMLElementTagNameMap]: <V>(properties: Partial<JSXElementProperties<V, K>>, all: any[]) => AnyDOM<V>;
30
+ };
31
+ export declare const JSXDOM_REGISTRY: JSXDOMRegistry;
32
+ export {};
@@ -0,0 +1,77 @@
1
+ import { HTML_TAGS } from "./tags.js";
2
+ import { describe } from "./description/describe.js";
3
+ const DYNAMIC_PROPERTY_CONDITIONAL_MAP = 'conditional';
4
+ const DYNAMIC_PROPERTY_PREFIX = `sf:`;
5
+ const DYNAMIC_PROPERTY_CYCLES = [`${DYNAMIC_PROPERTY_PREFIX}for`, `${DYNAMIC_PROPERTY_PREFIX}each`];
6
+ const DYNAMIC_PROPERTY_CONDITIONAL = `${DYNAMIC_PROPERTY_PREFIX}if`;
7
+ const DELEGATE_EVENT_PROPERTY_PREFIX = `${DYNAMIC_PROPERTY_PREFIX}on-`;
8
+ const COMMON_EVENT_PROPERTY_PREFIX = `on:`;
9
+ class JSXDOMUtilities {
10
+ static patch(object, key, value) {
11
+ object[key] = value;
12
+ }
13
+ static outsort_children(all) {
14
+ const content = new Array();
15
+ const children = new Array();
16
+ for (const child of all) {
17
+ if (typeof child === 'string' || typeof child === 'number') {
18
+ content.push(() => child.toString());
19
+ }
20
+ else if (typeof child === 'function') {
21
+ content.push(child);
22
+ }
23
+ else if (typeof child === 'object') {
24
+ children.push(child);
25
+ }
26
+ else {
27
+ throw new Error(`JSX does not support typeof of ${typeof child} element`);
28
+ }
29
+ }
30
+ return { content, children };
31
+ }
32
+ static map_properties(jsx) {
33
+ const jsx_properties = jsx;
34
+ const dom_properties = {
35
+ styles: {},
36
+ modifiers: {},
37
+ properties: {},
38
+ events: {}
39
+ };
40
+ for (const property in jsx) {
41
+ if (property.startsWith(COMMON_EVENT_PROPERTY_PREFIX)) {
42
+ this.patch(dom_properties.events, property.slice(COMMON_EVENT_PROPERTY_PREFIX.length), jsx_properties[property]);
43
+ }
44
+ else if (property.startsWith(DELEGATE_EVENT_PROPERTY_PREFIX)) {
45
+ dom_properties.modifiers.events = dom_properties.modifiers.events || {};
46
+ this.patch(dom_properties.modifiers.events, property.slice(DELEGATE_EVENT_PROPERTY_PREFIX.length), jsx_properties[property]);
47
+ }
48
+ else if (property === DYNAMIC_PROPERTY_CONDITIONAL) {
49
+ this.patch(dom_properties.modifiers, DYNAMIC_PROPERTY_CONDITIONAL_MAP, jsx_properties[property]);
50
+ }
51
+ else if (DYNAMIC_PROPERTY_CYCLES.includes(property)) {
52
+ dom_properties.modifiers.iterate = {
53
+ select: jsx_properties[DYNAMIC_PROPERTY_CYCLES[0]],
54
+ each: jsx_properties[DYNAMIC_PROPERTY_CYCLES[1]]
55
+ };
56
+ }
57
+ else if (property.startsWith(DYNAMIC_PROPERTY_PREFIX)) {
58
+ dom_properties.modifiers.properties = dom_properties.modifiers.properties || {};
59
+ this.patch(dom_properties.modifiers.properties, property.slice(DYNAMIC_PROPERTY_PREFIX.length), jsx_properties[property]);
60
+ }
61
+ else {
62
+ this.patch(dom_properties.properties, property, jsx_properties[property]);
63
+ }
64
+ }
65
+ return dom_properties;
66
+ }
67
+ }
68
+ export const JSXDOM_REGISTRY = Object.create(null);
69
+ for (const tag of HTML_TAGS) {
70
+ JSXDOM_REGISTRY[tag] = (context, all) => {
71
+ const { content, children } = JSXDOMUtilities.outsort_children(all);
72
+ const properties = JSXDOMUtilities.map_properties(context);
73
+ properties.modifiers.text = (context) => content.map(site => site(context)).join(String());
74
+ properties.name = tag;
75
+ return describe(properties, children);
76
+ };
77
+ }
@@ -0,0 +1,17 @@
1
+ import { FlushableCollection } from "../../../index.js";
2
+ import { AnyDOM } from "../dom.js";
3
+ export type Modifiers<Context, K extends keyof HTMLElementTagNameMap = any> = Partial<{
4
+ text: (context: Context) => string;
5
+ lens: <Another>(context: Context) => Another;
6
+ conditional: (context: Context) => boolean;
7
+ events: Partial<{
8
+ [L in keyof HTMLElementEventMap]: (event: HTMLElementEventMap[L], context: Context) => void;
9
+ }>;
10
+ properties: Partial<{
11
+ [L in keyof HTMLElementTagNameMap[K]]: (context: Context) => string;
12
+ }>;
13
+ iterate: {
14
+ select: <V>(context: Context) => FlushableCollection<V>;
15
+ each: () => AnyDOM<any>;
16
+ };
17
+ }>;