stillflow.engine 0.2.1 → 0.3.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/README.md +1 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/stillflow-adapters/dom/base.dom.d.ts +3 -6
- package/dist/stillflow-adapters/dom/base.dom.js +9 -21
- package/dist/stillflow-adapters/dom/description/describe.d.ts +1 -1
- package/dist/stillflow-adapters/dom/jsx.dom.d.ts +1 -1
- package/dist/stillflow-adapters/dom/jsx.dom.js +1 -1
- package/dist/stillflow-adapters/dom/properties/properties.d.ts +2 -2
- package/dist/stillflow-adapters/dom/vm/compile/dom.apply.d.ts +5 -0
- package/dist/stillflow-adapters/dom/vm/compile/dom.apply.js +10 -0
- package/dist/stillflow-adapters/dom/vm/compile/dom.compile-vm.d.ts +2 -0
- package/dist/stillflow-adapters/dom/vm/compile/dom.compile-vm.js +171 -0
- package/dist/stillflow-adapters/dom/vm/compile/dom.compile.d.ts +3 -0
- package/dist/stillflow-adapters/dom/vm/compile/dom.compile.js +65 -0
- package/dist/stillflow-adapters/dom/vm/compile/dom.context.d.ts +12 -0
- package/dist/stillflow-adapters/dom/vm/compile/dom.markup.d.ts +3 -0
- package/dist/stillflow-adapters/dom/vm/compile/dom.markup.js +32 -0
- package/dist/stillflow-adapters/dom/vm/dom.codes.d.ts +8 -0
- package/dist/stillflow-adapters/dom/vm/dom.symbols.d.ts +6 -0
- package/dist/stillflow-adapters/dom/vm/dom.symbols.js +18 -0
- package/dist/stillflow-adapters/dom/vm/dom.template.d.ts +9 -0
- package/dist/stillflow-adapters/dom/vm/dom.template.js +1 -0
- package/dist/stillflow-adapters/dom/vm/dom.types.js +1 -0
- package/dist/stillflow-adapters/dom/{aot/transformers/transform.js → vm/transform/dom.transform.js} +16 -4
- package/dist/stillflow-adapters/dom/{aot → vm/utilities}/dom.delegator.js +1 -1
- package/dist/stillflow-adapters/dom/{aot → vm/utilities}/dom.pool.js +1 -2
- package/dist/stillflow-examples/app.js +1 -2
- package/dist/stillflow-examples/test.js +3 -2
- package/dist/stillflow-vm/abstract/config.d.ts +6 -0
- package/dist/stillflow-vm/abstract/config.js +1 -0
- package/dist/stillflow-vm/abstract/generator.d.ts +1 -0
- package/dist/stillflow-vm/abstract/generator.js +1 -0
- package/dist/stillflow-vm/create.d.ts +5 -0
- package/dist/stillflow-vm/create.js +17 -0
- package/dist/stillflow-vm/emitter.d.ts +5 -0
- package/dist/stillflow-vm/emitter.js +9 -0
- package/dist/stillflow-vm/index.d.ts +5 -0
- package/dist/stillflow-vm/index.js +3 -0
- package/dist/stillflow-vm/payload.d.ts +9 -0
- package/dist/stillflow-vm/payload.js +24 -0
- package/package.json +1 -1
- package/dist/stillflow-adapters/dom/aot/appliers/apply.d.ts +0 -6
- package/dist/stillflow-adapters/dom/aot/appliers/apply.js +0 -167
- package/dist/stillflow-adapters/dom/aot/compiler/compile.d.ts +0 -11
- package/dist/stillflow-adapters/dom/aot/compiler/compile.js +0 -71
- package/dist/stillflow-adapters/dom/aot/dom.operations.d.ts +0 -3
- package/dist/stillflow-adapters/dom/aot/dom.operations.js +0 -1
- package/dist/stillflow-adapters/dom/aot/dom.resources.d.ts +0 -3
- package/dist/stillflow-adapters/dom/aot/dom.resources.js +0 -3
- package/dist/stillflow-adapters/dom/properties/modifiers.d.ts +0 -16
- /package/dist/stillflow-adapters/dom/{aot/dom.directives.js → vm/compile/dom.context.js} +0 -0
- /package/dist/stillflow-adapters/dom/{aot/dom.types.js → vm/dom.codes.js} +0 -0
- /package/dist/stillflow-adapters/dom/{aot → vm}/dom.directives.d.ts +0 -0
- /package/dist/stillflow-adapters/dom/{properties/modifiers.js → vm/dom.directives.js} +0 -0
- /package/dist/stillflow-adapters/dom/{aot → vm}/dom.types.d.ts +0 -0
- /package/dist/stillflow-adapters/dom/{aot/transformers/transform.d.ts → vm/transform/dom.transform.d.ts} +0 -0
- /package/dist/stillflow-adapters/dom/{aot → vm/utilities}/dom.delegator.d.ts +0 -0
- /package/dist/stillflow-adapters/dom/{aot → vm/utilities}/dom.pool.d.ts +0 -0
- /package/dist/stillflow-adapters/dom/{aot → vm/utilities}/dom.symbols.d.ts +0 -0
- /package/dist/stillflow-adapters/dom/{aot → vm/utilities}/dom.symbols.js +0 -0
package/README.md
CHANGED
|
@@ -115,14 +115,12 @@ function App() {
|
|
|
115
115
|
)
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
const
|
|
118
|
+
const update = dom.$(<App />, { container: document.body })
|
|
119
119
|
|
|
120
120
|
stillflow.on(() => update(instance))
|
|
121
121
|
|
|
122
122
|
instance.input = String()
|
|
123
123
|
stillflow.commit()
|
|
124
|
-
|
|
125
|
-
document.body.appendChild(app)
|
|
126
124
|
```
|
|
127
125
|
|
|
128
126
|
## How it works
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as adapters from './stillflow-adapters/index.js';
|
|
2
2
|
import * as collection from './stillflow-collection/index.js';
|
|
3
|
+
import * as vm from './stillflow-vm/index.js';
|
|
3
4
|
import operators from './stillflow/operators.js';
|
|
4
5
|
export { Stillflow } from './stillflow/stillflow.js';
|
|
5
6
|
export { State } from './stillflow/state.js';
|
|
6
7
|
export { Batcher } from './stillflow/tools/batcher.js';
|
|
7
|
-
export { operators, adapters, collection };
|
|
8
|
+
export { operators, adapters, collection, vm };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as adapters from './stillflow-adapters/index.js';
|
|
2
2
|
import * as collection from './stillflow-collection/index.js';
|
|
3
|
+
import * as vm from './stillflow-vm/index.js';
|
|
3
4
|
import operators from './stillflow/operators.js';
|
|
4
5
|
export { Stillflow } from './stillflow/stillflow.js';
|
|
5
6
|
export { State } from './stillflow/state.js';
|
|
6
7
|
export { Batcher } from './stillflow/tools/batcher.js';
|
|
7
|
-
export { operators, adapters, collection };
|
|
8
|
+
export { operators, adapters, collection, vm };
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { AnyDOM } from "./
|
|
1
|
+
import { AnyDOM } from "./vm/dom.types.js";
|
|
2
2
|
import { Properties } from "./properties/properties.js";
|
|
3
3
|
import { Binding } from "../binding.js";
|
|
4
4
|
type PropertiesWithoutServices<V, K extends keyof HTMLElementTagNameMap> = Omit<Properties<V, K>, 'name'>;
|
|
5
5
|
type Options = {
|
|
6
|
-
|
|
6
|
+
container: HTMLElement;
|
|
7
7
|
};
|
|
8
8
|
export type DOMRegistry = {
|
|
9
9
|
[K in keyof HTMLElementTagNameMap]: <V>(properties: Partial<PropertiesWithoutServices<V, K>>, children?: Binding<any>[]) => AnyDOM<V>;
|
|
10
10
|
} & {
|
|
11
|
-
$: <V>(root: AnyDOM<V>, options?: Options) =>
|
|
12
|
-
element: HTMLElement;
|
|
13
|
-
update: (context: V) => void;
|
|
14
|
-
};
|
|
11
|
+
$: <V>(root: AnyDOM<V>, options?: Options) => (context: V) => void;
|
|
15
12
|
};
|
|
16
13
|
export declare const DOM_REGISTRY: DOMRegistry;
|
|
17
14
|
export {};
|
|
@@ -1,27 +1,15 @@
|
|
|
1
1
|
import { HTML_TAGS } from "./tags.js";
|
|
2
|
-
import { transform } from "./aot/transformers/transform.js";
|
|
3
2
|
import { describe } from "./description/describe.js";
|
|
4
|
-
import { apply } from "./
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { apply } from "./vm/compile/dom.apply.js";
|
|
4
|
+
const DEFAULT_OPTIONS = {
|
|
5
|
+
container: document.body
|
|
6
|
+
};
|
|
8
7
|
export const DOM_REGISTRY = Object.create(null);
|
|
9
|
-
DOM_REGISTRY.$ = function $(root, options =
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const update = (context) => {
|
|
15
|
-
if (!cleaning) {
|
|
16
|
-
cleaning = true;
|
|
17
|
-
options.gc(() => {
|
|
18
|
-
pool.tick();
|
|
19
|
-
cleaning = false;
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
applier(element, context);
|
|
23
|
-
};
|
|
24
|
-
return { element, update };
|
|
8
|
+
DOM_REGISTRY.$ = function $(root, options = DEFAULT_OPTIONS) {
|
|
9
|
+
const runner = apply(root);
|
|
10
|
+
const update = (context) => runner.run(context);
|
|
11
|
+
options.container.appendChild(runner.root);
|
|
12
|
+
return update;
|
|
25
13
|
};
|
|
26
14
|
for (const tag of HTML_TAGS) {
|
|
27
15
|
DOM_REGISTRY[tag] = (properties, children = []) => {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { AnyDOM } from "../
|
|
1
|
+
import { AnyDOM } from "../vm/dom.types.js";
|
|
2
2
|
import { Properties } from "../properties/properties.js";
|
|
3
3
|
export declare function describe<V, K extends keyof HTMLElementTagNameMap>(properties: Properties<V, K>, children: AnyDOM<V>[]): AnyDOM<V>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Directives } from "../vm/dom.directives.js";
|
|
2
2
|
export type Properties<Context, Tag extends keyof HTMLElementTagNameMap> = Partial<{
|
|
3
3
|
name: Tag;
|
|
4
4
|
text: string;
|
|
@@ -8,7 +8,7 @@ export type Properties<Context, Tag extends keyof HTMLElementTagNameMap> = Parti
|
|
|
8
8
|
properties: Partial<{
|
|
9
9
|
[L in keyof Omit<HTMLElementTagNameMap[Tag], 'style'>]: HTMLElementTagNameMap[Tag][L];
|
|
10
10
|
}>;
|
|
11
|
-
modifiers: Partial<
|
|
11
|
+
modifiers: Partial<Directives<Context, Tag>>;
|
|
12
12
|
styles: Partial<{
|
|
13
13
|
[L in keyof HTMLElementTagNameMap[Tag]['style']]: HTMLElementTagNameMap[Tag]['style'][L];
|
|
14
14
|
}>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { run_dom_vm } from "./dom.compile-vm.js";
|
|
2
|
+
import { compile } from "./dom.compile.js";
|
|
3
|
+
export function apply(node) {
|
|
4
|
+
const compilation = compile(node);
|
|
5
|
+
const applier = run_dom_vm(compilation);
|
|
6
|
+
return {
|
|
7
|
+
root: compilation.root,
|
|
8
|
+
run: (context) => applier(compilation.root, context)
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { vm } from "../../../../index.js";
|
|
2
|
+
import { Pool } from "../utilities/dom.pool.js";
|
|
3
|
+
import { EventDelegator } from "../utilities/dom.delegator.js";
|
|
4
|
+
import { SF_ANY, SF_CACHE, SF_CACHE_TEXT, SF_CONTEXT, SF_HANDLERS, SF_LISTENED } from "../dom.symbols.js";
|
|
5
|
+
import { markup_template } from "./dom.markup.js";
|
|
6
|
+
const generators = {
|
|
7
|
+
[5 /* Codes.PROPERTY */](bytecode, offset, context) {
|
|
8
|
+
const container = bytecode[offset + 2];
|
|
9
|
+
const property = context.strings[bytecode[offset + 3]];
|
|
10
|
+
const handler = context.functions[bytecode[offset + 4]];
|
|
11
|
+
const propertyIndex = context.payload.add(property);
|
|
12
|
+
const handlerIndex = context.payload.add(handler);
|
|
13
|
+
const payload = context.payload.payload;
|
|
14
|
+
return `sf_node_cache[${container}][${payload(propertyIndex)}] = ${payload(handlerIndex)}(context);`;
|
|
15
|
+
},
|
|
16
|
+
[3 /* Codes.TEXT */](bytecode, offset, context) {
|
|
17
|
+
const container = bytecode[offset + 2];
|
|
18
|
+
const handler = context.functions[bytecode[offset + 3]];
|
|
19
|
+
const handlerIndex = context.payload.add(handler);
|
|
20
|
+
return `sf_text_cache[${container}].data = ${context.payload.payload(handlerIndex)}(context);`;
|
|
21
|
+
},
|
|
22
|
+
[4 /* Codes.EVENT */](bytecode, offset, context) {
|
|
23
|
+
const container = bytecode[offset + 2];
|
|
24
|
+
const event = context.strings[bytecode[offset + 3]];
|
|
25
|
+
const handler = context.functions[bytecode[offset + 4]];
|
|
26
|
+
const eventIndex = context.payload.add(event);
|
|
27
|
+
const handlerIndex = context.payload.add(handler);
|
|
28
|
+
const delegatorIndex = context.payload.add(context.delegator);
|
|
29
|
+
const payload = context.payload.payload;
|
|
30
|
+
let code = String();
|
|
31
|
+
code += `{`;
|
|
32
|
+
code += `const element = sf_node_cache[${container}];`;
|
|
33
|
+
code += `element.${SF_CONTEXT} = context;`;
|
|
34
|
+
code += `if (!element.${SF_LISTENED}) {`;
|
|
35
|
+
code += `element.${SF_LISTENED} = true;`;
|
|
36
|
+
code += `${payload(delegatorIndex)}.add(element, ${payload(eventIndex)}, ${payload(handlerIndex)});`;
|
|
37
|
+
code += `}`;
|
|
38
|
+
code += `}`;
|
|
39
|
+
return code;
|
|
40
|
+
},
|
|
41
|
+
[0 /* Codes.IF */](bytecode, offset, context) {
|
|
42
|
+
const container = bytecode[offset + 2];
|
|
43
|
+
const handler = context.functions[bytecode[offset + 3]];
|
|
44
|
+
const payload = context.payload.payload;
|
|
45
|
+
let code = String();
|
|
46
|
+
const handlerIndex = context.payload.add(handler);
|
|
47
|
+
code += `{`;
|
|
48
|
+
code += `const element = sf_node_cache[${container}];`;
|
|
49
|
+
code += `const condition = ${payload(handlerIndex)}(context);`;
|
|
50
|
+
code += `element.style.display = condition ? String() : 'none';`;
|
|
51
|
+
code += `}`;
|
|
52
|
+
return code;
|
|
53
|
+
},
|
|
54
|
+
[2 /* Codes.FOR */](bytecode, offset, context) {
|
|
55
|
+
const container = bytecode[offset + 2];
|
|
56
|
+
const select = context.functions[bytecode[offset + 3]];
|
|
57
|
+
const template = context.templates[bytecode[offset + 4]];
|
|
58
|
+
const item_applier = run_dom_vm(template);
|
|
59
|
+
item_applier(template.root, SF_ANY);
|
|
60
|
+
const selectIndex = context.payload.add_payload(select);
|
|
61
|
+
const applierIndex = context.payload.add_payload(item_applier);
|
|
62
|
+
const templateIndex = context.payload.add_payload(template.root);
|
|
63
|
+
const elementsIndex = context.payload.add_payload([]);
|
|
64
|
+
const poolIndex = context.payload.add_payload(new Pool());
|
|
65
|
+
let code = String();
|
|
66
|
+
code += `{`;
|
|
67
|
+
code += `const items = ${selectIndex}(context);`;
|
|
68
|
+
code += `const target = sf_node_cache[${container}];`;
|
|
69
|
+
code += `const { replaces, clears, addes, swaps, removes, updates } = items.flush();`;
|
|
70
|
+
code += `if (replaces) {`;
|
|
71
|
+
code += `const items_size = items.size;`;
|
|
72
|
+
code += `const children_size = ${elementsIndex}.length;`;
|
|
73
|
+
code += `const common_size = Math.min(items_size, children_size);`;
|
|
74
|
+
code += `for (let i = 0; i < common_size; i++) {`;
|
|
75
|
+
code += `${applierIndex}(${elementsIndex}[i], items.at(i));`;
|
|
76
|
+
code += `}`;
|
|
77
|
+
code += `if (items_size < children_size) {`;
|
|
78
|
+
code += `for (let i = items_size; i < children_size; i++) {`;
|
|
79
|
+
code += `const element = ${elementsIndex}[i];`;
|
|
80
|
+
code += `${poolIndex}.add(element);`;
|
|
81
|
+
code += `element.remove();`;
|
|
82
|
+
code += `}`;
|
|
83
|
+
code += `${elementsIndex}.length = items_size;`;
|
|
84
|
+
code += `}`;
|
|
85
|
+
code += `else if (children_size < items_size) {`;
|
|
86
|
+
code += `const fragment = document.createDocumentFragment();`;
|
|
87
|
+
code += `const elements = new Array(items_size - children_size);`;
|
|
88
|
+
code += `for (let i = children_size; i < items_size; i++) {`;
|
|
89
|
+
code += `const element = ${poolIndex}.get() || ${templateIndex}.cloneNode(true);`;
|
|
90
|
+
code += `element.${SF_HANDLERS} = ${templateIndex}.${SF_HANDLERS};`;
|
|
91
|
+
code += `element.${SF_CONTEXT} = items.at(i);`;
|
|
92
|
+
code += `${applierIndex}(element, items.at(i));`;
|
|
93
|
+
code += `elements[i - children_size] = element;`;
|
|
94
|
+
code += `fragment.appendChild(element);`;
|
|
95
|
+
code += `}`;
|
|
96
|
+
code += `${elementsIndex}.push(...elements);`;
|
|
97
|
+
code += `target.appendChild(fragment);`;
|
|
98
|
+
code += `}`;
|
|
99
|
+
code += `}`;
|
|
100
|
+
code += `else {`;
|
|
101
|
+
code += `if (clears) {`;
|
|
102
|
+
code += `const freelist = ${elementsIndex}.splice(0);`;
|
|
103
|
+
code += `for (const element of freelist) {`;
|
|
104
|
+
code += `element.${SF_HANDLERS} = undefined;`;
|
|
105
|
+
code += `${poolIndex}.add(element);`;
|
|
106
|
+
code += `}`;
|
|
107
|
+
code += `target.textContent = String();`;
|
|
108
|
+
code += `}`;
|
|
109
|
+
code += `if (addes > 0) {`;
|
|
110
|
+
code += `const fragment = document.createDocumentFragment();`;
|
|
111
|
+
code += `const elements = new Array(addes);`;
|
|
112
|
+
code += `const old_size = ${elementsIndex}.length;`;
|
|
113
|
+
code += `for (let i = 0; i < addes; i++) {`;
|
|
114
|
+
code += `const element = ${poolIndex}.get() || ${templateIndex}.cloneNode(true);`;
|
|
115
|
+
code += `element.${SF_HANDLERS} = ${templateIndex}.${SF_HANDLERS};`;
|
|
116
|
+
code += `element.${SF_CONTEXT} = items.at(i + old_size);`;
|
|
117
|
+
code += `${applierIndex}(element, items.at(i + old_size));`;
|
|
118
|
+
code += `elements[i] = element;`;
|
|
119
|
+
code += `fragment.appendChild(element);`;
|
|
120
|
+
code += `}`;
|
|
121
|
+
code += `${elementsIndex}.push(...elements);`;
|
|
122
|
+
code += `target.appendChild(fragment);`;
|
|
123
|
+
code += `}`;
|
|
124
|
+
code += `for (const [i, j] of swaps.entries()) {`;
|
|
125
|
+
code += `${applierIndex}(${elementsIndex}[i], items.at(i));`;
|
|
126
|
+
code += `${elementsIndex}[i].${SF_CONTEXT} = items.at(i);`;
|
|
127
|
+
code += `${applierIndex}(${elementsIndex}[j], items.at(j));`;
|
|
128
|
+
code += `${elementsIndex}[j].${SF_CONTEXT} = items.at(j);`;
|
|
129
|
+
code += `}`;
|
|
130
|
+
code += `for (const id of removes) {`;
|
|
131
|
+
code += `const element = ${elementsIndex}[id];`;
|
|
132
|
+
code += `element.${SF_HANDLERS} = undefined;`;
|
|
133
|
+
code += `${poolIndex}.add(element);`;
|
|
134
|
+
code += `element.remove();`;
|
|
135
|
+
code += `}`;
|
|
136
|
+
code += `for (const id of updates) {`;
|
|
137
|
+
code += `${applierIndex}(${elementsIndex}[id], items.at(id));`;
|
|
138
|
+
code += `}`;
|
|
139
|
+
code += `}`;
|
|
140
|
+
code += `${poolIndex}.tick();`;
|
|
141
|
+
code += `}`;
|
|
142
|
+
return code;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const DELEGATOR = new EventDelegator();
|
|
146
|
+
const create_context = (payload, input) => {
|
|
147
|
+
return {
|
|
148
|
+
node: input.node,
|
|
149
|
+
payload,
|
|
150
|
+
strings: input.strings,
|
|
151
|
+
functions: input.functions,
|
|
152
|
+
templates: input.templates,
|
|
153
|
+
delegator: DELEGATOR
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
const dom_vm = vm.create({
|
|
157
|
+
generators,
|
|
158
|
+
preamble(context) {
|
|
159
|
+
let code = String();
|
|
160
|
+
const markupIndex = context.payload.add_payload(markup_template(context.node));
|
|
161
|
+
code += `return function(root, context) {`;
|
|
162
|
+
code += `${markupIndex}(root);`;
|
|
163
|
+
code += `const sf_node_cache = root.${SF_CACHE};`;
|
|
164
|
+
code += `const sf_text_cache = root.${SF_CACHE_TEXT};`;
|
|
165
|
+
return code;
|
|
166
|
+
},
|
|
167
|
+
epilogue() {
|
|
168
|
+
return `}`;
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
export const run_dom_vm = (template) => dom_vm(template.bytecode, template, create_context);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { vm } from "../../../../index.js";
|
|
2
|
+
import { transform } from "../transform/dom.transform.js";
|
|
3
|
+
export function compile(node) {
|
|
4
|
+
const emitter = new vm.Emitter();
|
|
5
|
+
const strings = new vm.Payload();
|
|
6
|
+
const functions = new vm.Payload();
|
|
7
|
+
const templates = new vm.Payload();
|
|
8
|
+
let next_node_id = 0;
|
|
9
|
+
function walk(current) {
|
|
10
|
+
const modifiers = current.properties.modifiers;
|
|
11
|
+
const has_properties = modifiers?.properties !== undefined;
|
|
12
|
+
const has_events = modifiers?.events !== undefined;
|
|
13
|
+
const has_text = modifiers?.text !== undefined;
|
|
14
|
+
const has_for = modifiers?.iterate !== undefined;
|
|
15
|
+
const has_if = modifiers?.conditional !== undefined;
|
|
16
|
+
let current_id = -1;
|
|
17
|
+
if (has_properties || has_events || has_text || has_for || has_if) {
|
|
18
|
+
current_id = next_node_id++;
|
|
19
|
+
}
|
|
20
|
+
if (has_properties) {
|
|
21
|
+
const properties = modifiers.properties;
|
|
22
|
+
for (const key in properties) {
|
|
23
|
+
const propertyIndex = strings.add(key);
|
|
24
|
+
const functionIndex = functions.add(properties[key]);
|
|
25
|
+
emitter.emit(5 /* Codes.PROPERTY */, current_id, propertyIndex, functionIndex);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (has_events) {
|
|
29
|
+
const events = modifiers.events;
|
|
30
|
+
for (const name in events) {
|
|
31
|
+
const eventIndex = strings.add(name);
|
|
32
|
+
const functionIndex = functions.add(events[name]);
|
|
33
|
+
emitter.emit(4 /* Codes.EVENT */, current_id, eventIndex, functionIndex);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (has_text) {
|
|
37
|
+
const functionIndex = functions.add(modifiers.text);
|
|
38
|
+
emitter.emit(3 /* Codes.TEXT */, current_id, functionIndex);
|
|
39
|
+
}
|
|
40
|
+
if (has_if) {
|
|
41
|
+
const functionIndex = functions.add(modifiers.conditional);
|
|
42
|
+
emitter.emit(0 /* Codes.IF */, current_id, functionIndex);
|
|
43
|
+
}
|
|
44
|
+
if (has_for) {
|
|
45
|
+
const iterate = modifiers.iterate;
|
|
46
|
+
const selectIndex = functions.add(iterate.select);
|
|
47
|
+
const subTemplate = compile(iterate.each());
|
|
48
|
+
const templateIndex = templates.add(subTemplate);
|
|
49
|
+
emitter.emit(2 /* Codes.FOR */, current_id, selectIndex, templateIndex);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
for (const child of current.children) {
|
|
53
|
+
walk(child);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
walk(node);
|
|
57
|
+
return {
|
|
58
|
+
node,
|
|
59
|
+
root: transform(node),
|
|
60
|
+
strings: strings.values,
|
|
61
|
+
bytecode: emitter.finish(),
|
|
62
|
+
functions: functions.values,
|
|
63
|
+
templates: templates.values
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { vm } from "../../../../index.js";
|
|
2
|
+
import { Template } from "../dom.template.js";
|
|
3
|
+
import { AnyDOM } from "../dom.types.js";
|
|
4
|
+
import { EventDelegator } from "../utilities/dom.delegator.js";
|
|
5
|
+
export type Context = {
|
|
6
|
+
node: AnyDOM<any>;
|
|
7
|
+
payload: vm.Payload;
|
|
8
|
+
strings: string[];
|
|
9
|
+
functions: Function[];
|
|
10
|
+
templates: Template[];
|
|
11
|
+
delegator: EventDelegator;
|
|
12
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SF_CACHE, SF_CACHE_TEXT } from "../dom.symbols.js";
|
|
2
|
+
function markup_template_code(node, path) {
|
|
3
|
+
let { modifiers } = node.properties;
|
|
4
|
+
let code = String();
|
|
5
|
+
const has_modifiers = modifiers?.text !== undefined ||
|
|
6
|
+
modifiers?.properties !== undefined ||
|
|
7
|
+
modifiers?.events !== undefined ||
|
|
8
|
+
modifiers?.iterate !== undefined ||
|
|
9
|
+
modifiers?.conditional !== undefined;
|
|
10
|
+
if (has_modifiers) {
|
|
11
|
+
code += `sf_markup_path.push(root${path.map(x => `.children[${x}]`).join(String())});`;
|
|
12
|
+
}
|
|
13
|
+
for (let index = 0; index < node.children.length; index++) {
|
|
14
|
+
code += markup_template_code(node.children[index], [...path, index]);
|
|
15
|
+
}
|
|
16
|
+
return code;
|
|
17
|
+
}
|
|
18
|
+
function markup_template(node) {
|
|
19
|
+
let code = String();
|
|
20
|
+
code += `return function(root) {`;
|
|
21
|
+
code += `if (root.${SF_CACHE}) {`;
|
|
22
|
+
code += `return;`;
|
|
23
|
+
code += `}`;
|
|
24
|
+
code += `let sf_markup_path = [];`;
|
|
25
|
+
code += markup_template_code(node, []);
|
|
26
|
+
code += `root.${SF_CACHE} = sf_markup_path;`;
|
|
27
|
+
code += `root.${SF_CACHE_TEXT} = sf_markup_path.map(node => node.firstChild);`;
|
|
28
|
+
code += `}`;
|
|
29
|
+
const generator = new Function(code);
|
|
30
|
+
return generator();
|
|
31
|
+
}
|
|
32
|
+
export { markup_template };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const SF_LISTENED = "__stillflow_listened__";
|
|
2
|
+
export declare const SF_CONTEXT = "__stillflow_context__";
|
|
3
|
+
export declare const SF_CACHE_TEXT = "__stillflow_cache_text__";
|
|
4
|
+
export declare const SF_CACHE = "__stillflow_cache__";
|
|
5
|
+
export declare const SF_HANDLERS = "__stillflow_handlers__";
|
|
6
|
+
export declare const SF_ANY: any;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const EMPTY = () => String();
|
|
2
|
+
export const SF_LISTENED = '__stillflow_listened__';
|
|
3
|
+
export const SF_CONTEXT = '__stillflow_context__';
|
|
4
|
+
export const SF_CACHE_TEXT = '__stillflow_cache_text__';
|
|
5
|
+
export const SF_CACHE = '__stillflow_cache__';
|
|
6
|
+
export const SF_HANDLERS = `__stillflow_handlers__`;
|
|
7
|
+
export const SF_ANY = new Proxy({}, {
|
|
8
|
+
get: (_, property) => {
|
|
9
|
+
if (property === Symbol.toPrimitive || property === 'valueOf') {
|
|
10
|
+
return EMPTY;
|
|
11
|
+
}
|
|
12
|
+
if (property === Symbol.iterator) {
|
|
13
|
+
return [][Symbol.iterator];
|
|
14
|
+
}
|
|
15
|
+
return SF_ANY;
|
|
16
|
+
},
|
|
17
|
+
apply: () => SF_ANY
|
|
18
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/stillflow-adapters/dom/{aot/transformers/transform.js → vm/transform/dom.transform.js}
RENAMED
|
@@ -4,14 +4,22 @@ function transform_code(description, payloads, depth = 1) {
|
|
|
4
4
|
styles = styles || Object.create(null);
|
|
5
5
|
events = events || Object.create(null);
|
|
6
6
|
properties = properties || Object.create(null);
|
|
7
|
-
|
|
7
|
+
const nameIndex = payloads.length;
|
|
8
|
+
payloads.push(name);
|
|
9
|
+
code += `let sf_child_node_${depth} = document.createElement(p${nameIndex});`;
|
|
8
10
|
if (text !== undefined || modifiers?.text !== undefined) {
|
|
9
|
-
|
|
11
|
+
const textIndex = payloads.length;
|
|
12
|
+
payloads.push(text);
|
|
13
|
+
code += `let sf_text_node_${depth} = document.createTextNode(p${textIndex});`;
|
|
10
14
|
code += `sf_child_node_${depth}.appendChild(sf_text_node_${depth});`;
|
|
11
15
|
}
|
|
12
16
|
code += `sf_child_node_${depth - 1}.appendChild(sf_child_node_${depth});`;
|
|
13
17
|
for (const key in styles) {
|
|
14
|
-
|
|
18
|
+
const keyIndex = payloads.length;
|
|
19
|
+
payloads.push(key);
|
|
20
|
+
const styleIndex = payloads.length;
|
|
21
|
+
payloads.push(styles[key]);
|
|
22
|
+
code += `sf_child_node_${depth}.style[p${keyIndex}] = p${styleIndex};`;
|
|
15
23
|
}
|
|
16
24
|
for (const key in events) {
|
|
17
25
|
const pIndex = payloads.length;
|
|
@@ -20,8 +28,12 @@ function transform_code(description, payloads, depth = 1) {
|
|
|
20
28
|
code += `sf_child_node_${depth}.addEventListener("${key}", p${pIndex});`;
|
|
21
29
|
}
|
|
22
30
|
for (const key in properties) {
|
|
31
|
+
const keyIndex = payloads.length;
|
|
32
|
+
payloads.push(key);
|
|
33
|
+
const propertyIndex = payloads.length;
|
|
23
34
|
const property = properties[key];
|
|
24
|
-
|
|
35
|
+
payloads.push(property);
|
|
36
|
+
code += `sf_child_node_${depth}[p${keyIndex}] = p${propertyIndex};`;
|
|
25
37
|
}
|
|
26
38
|
for (const child of description.children) {
|
|
27
39
|
code += `{${transform_code(child, payloads, depth + 1)}}`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SF_CONTEXT, SF_LISTENED } from "
|
|
1
|
+
import { SF_CONTEXT, SF_LISTENED } from "../dom.symbols.js";
|
|
2
2
|
export class Pool {
|
|
3
3
|
static TIME_TO_EVICT = 2;
|
|
4
4
|
_hots = [];
|
|
@@ -23,7 +23,6 @@ export class Pool {
|
|
|
23
23
|
const element = cold.deref();
|
|
24
24
|
if (element !== undefined) {
|
|
25
25
|
this._hots.push({ root: element, frame: this._frame });
|
|
26
|
-
return;
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
28
|
}
|
|
@@ -135,7 +135,6 @@ function BenchmarkApplicationView(context) {
|
|
|
135
135
|
adapters.jsx(jsxdom.span, { ariaHidden: "true", className: "preloadicon glyphicon glyphicon-remove" })));
|
|
136
136
|
}
|
|
137
137
|
const controller = new BenchmarkApplicationController();
|
|
138
|
-
const
|
|
138
|
+
const update = dom.$(adapters.jsx(BenchmarkApplicationView, { controller: controller }));
|
|
139
139
|
controller.core.on(() => update({}));
|
|
140
|
-
document.body.appendChild(element);
|
|
141
140
|
update({});
|
|
@@ -28,8 +28,9 @@ function App() {
|
|
|
28
28
|
adapters.jsx(jsxdom.button, { "on:click": add }, "Add"),
|
|
29
29
|
adapters.jsx(jsxdom.div, { "sf:for": (context) => context.items, "sf:each": () => adapters.jsx(TodoItem, null) })));
|
|
30
30
|
}
|
|
31
|
-
const
|
|
31
|
+
const update = dom.$(adapters.jsx(App, null), {
|
|
32
|
+
container: document.body
|
|
33
|
+
});
|
|
32
34
|
stillflow.on(() => update(instance));
|
|
33
35
|
instance.input = String();
|
|
34
36
|
stillflow.commit();
|
|
35
|
-
document.body.appendChild(app);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type VMGenerator<Context> = (bytecode: ArrayLike<number>, offset: number, context: Context) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { VMConfig } from "./abstract/config.js";
|
|
2
|
+
import { Payload } from "./payload.js";
|
|
3
|
+
export declare function vm_create<Input, Context extends {
|
|
4
|
+
payload: Payload;
|
|
5
|
+
}>(config: VMConfig<Context>): (bytecode: ArrayLike<number>, input: Input, create_context: (payload: Payload, input: Input) => Context) => any;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Payload } from "./payload.js";
|
|
2
|
+
export function vm_create(config) {
|
|
3
|
+
return function compile(bytecode, input, create_context) {
|
|
4
|
+
const payload = new Payload();
|
|
5
|
+
const context = create_context(payload, input);
|
|
6
|
+
let code = config.preamble(context);
|
|
7
|
+
let offset = 0;
|
|
8
|
+
while (bytecode[offset] !== 0) {
|
|
9
|
+
const size = bytecode[offset];
|
|
10
|
+
const operation = bytecode[offset + 1];
|
|
11
|
+
code += config.generators[operation](bytecode, offset, context);
|
|
12
|
+
offset += size;
|
|
13
|
+
}
|
|
14
|
+
code += config.epilogue(context);
|
|
15
|
+
return new Function(...payload.parameters, code)(...payload.values);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class Payload {
|
|
2
|
+
_indices = new Map();
|
|
3
|
+
_index = 0;
|
|
4
|
+
payload(index) {
|
|
5
|
+
return `p${index}`;
|
|
6
|
+
}
|
|
7
|
+
add(value) {
|
|
8
|
+
let payload_name = this._indices.get(value);
|
|
9
|
+
if (payload_name === undefined) {
|
|
10
|
+
payload_name = this._index++;
|
|
11
|
+
this._indices.set(value, payload_name);
|
|
12
|
+
}
|
|
13
|
+
return payload_name;
|
|
14
|
+
}
|
|
15
|
+
add_payload(value) {
|
|
16
|
+
return this.payload(this.add(value));
|
|
17
|
+
}
|
|
18
|
+
get parameters() {
|
|
19
|
+
return Array.from(this._indices.values()).map(index => this.payload(index));
|
|
20
|
+
}
|
|
21
|
+
get values() {
|
|
22
|
+
return Array.from(this._indices.keys());
|
|
23
|
+
}
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Pool } from "../dom.pool.js";
|
|
2
|
-
import { EventDelegator } from "../dom.delegator.js";
|
|
3
|
-
import { AnyDOM } from "../dom.types.js";
|
|
4
|
-
type Applier<T> = (root: HTMLElement, context: T) => void;
|
|
5
|
-
export declare function apply<V>(node: AnyDOM<V>, delegator: EventDelegator, pool: Pool): Applier<V>;
|
|
6
|
-
export {};
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { transform } from "../transformers/transform.js";
|
|
2
|
-
import { compile, markup_template } from "../compiler/compile.js";
|
|
3
|
-
import { SF_CACHE, SF_CACHE_TEXT, SF_LISTENED, SF_CONTEXT, SF_HANDLERS } from "../dom.symbols.js";
|
|
4
|
-
const ANY = new Proxy({}, {
|
|
5
|
-
get(target, name) {
|
|
6
|
-
if (name === 'toString') {
|
|
7
|
-
return () => String();
|
|
8
|
-
}
|
|
9
|
-
return ANY;
|
|
10
|
-
},
|
|
11
|
-
apply(target, thisArg, argArray) {
|
|
12
|
-
return ANY;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
export function apply(node, delegator, pool) {
|
|
16
|
-
const instructions = compile(node);
|
|
17
|
-
const payload = (id) => `p${id}`;
|
|
18
|
-
const payloads = [markup_template(node)];
|
|
19
|
-
let code = `return function(root, context) {\n`;
|
|
20
|
-
let labels = 0;
|
|
21
|
-
code += `${payload(0)}(root);`;
|
|
22
|
-
code += `let sf_node_cache = root.${SF_CACHE};`;
|
|
23
|
-
code += `let sf_text_cache = root.${SF_CACHE_TEXT};`;
|
|
24
|
-
for (let id = 0; id < instructions.length; id++) {
|
|
25
|
-
const instruction = instructions[id];
|
|
26
|
-
const index = instruction.id;
|
|
27
|
-
if (instruction.text !== undefined) {
|
|
28
|
-
const pIndex = payloads.length;
|
|
29
|
-
payloads.push(instruction.text);
|
|
30
|
-
code += `iter_${labels++}: {`;
|
|
31
|
-
code += `const textnode = sf_text_cache[${index}];`;
|
|
32
|
-
code += `textnode.data = ${payload(pIndex)}(context);`;
|
|
33
|
-
code += `}`;
|
|
34
|
-
}
|
|
35
|
-
if (instruction.events !== undefined) {
|
|
36
|
-
code += `iter_${labels++}: {`;
|
|
37
|
-
code += `const element = sf_node_cache[${index}];`;
|
|
38
|
-
code += `if (!element.${SF_LISTENED}) {`;
|
|
39
|
-
code += `element.${SF_LISTENED} = true;`;
|
|
40
|
-
code += `element.${SF_CONTEXT} = context;`;
|
|
41
|
-
const pIndexRoot = payloads.length;
|
|
42
|
-
payloads.push(delegator);
|
|
43
|
-
for (const key in instruction.events) {
|
|
44
|
-
const pIndex = payloads.length;
|
|
45
|
-
payloads.push(instruction.events[key]);
|
|
46
|
-
code += `${payload(pIndexRoot)}.add(element, "${key}", ${payload(pIndex)});`;
|
|
47
|
-
}
|
|
48
|
-
code += `}`;
|
|
49
|
-
code += `else {`;
|
|
50
|
-
code += `element.${SF_CONTEXT} = context;`;
|
|
51
|
-
code += '}';
|
|
52
|
-
code += '}';
|
|
53
|
-
}
|
|
54
|
-
if (instruction.properties !== undefined) {
|
|
55
|
-
code += `iter_${labels++}: {`;
|
|
56
|
-
code += `const element = sf_node_cache[${index}];`;
|
|
57
|
-
for (const key in instruction.properties) {
|
|
58
|
-
const pIndex = payloads.length;
|
|
59
|
-
payloads.push(instruction.properties[key]);
|
|
60
|
-
code += `element.${key} = ${payload(pIndex)}(context);`;
|
|
61
|
-
}
|
|
62
|
-
code += '}';
|
|
63
|
-
}
|
|
64
|
-
if (instruction.conditional !== undefined) {
|
|
65
|
-
const pIndex = payloads.length;
|
|
66
|
-
payloads.push(instruction.conditional);
|
|
67
|
-
code += `iter_${labels++}: {`;
|
|
68
|
-
code += `const element = sf_node_cache[${index}];`;
|
|
69
|
-
code += `const condition = ${payload(pIndex)}(context);`;
|
|
70
|
-
code += `element.style.display = condition ? String() : 'none'`;
|
|
71
|
-
code += '}';
|
|
72
|
-
}
|
|
73
|
-
if (instruction.iterate !== undefined) {
|
|
74
|
-
const node = instruction.iterate.each();
|
|
75
|
-
const template = transform(node);
|
|
76
|
-
const pIndex = payloads.length;
|
|
77
|
-
payloads.push({
|
|
78
|
-
node,
|
|
79
|
-
any: ANY,
|
|
80
|
-
elements: [],
|
|
81
|
-
template,
|
|
82
|
-
applier: undefined,
|
|
83
|
-
select: instruction.iterate.select,
|
|
84
|
-
generator: apply,
|
|
85
|
-
delegator,
|
|
86
|
-
pool
|
|
87
|
-
});
|
|
88
|
-
code += `iter_${labels++}: {`;
|
|
89
|
-
code += `const items = ${payload(pIndex)}.select(context);`;
|
|
90
|
-
code += `if (${payload(pIndex)}.applier === undefined) {`;
|
|
91
|
-
code += `${payload(pIndex)}.applier = ${payload(pIndex)}.generator(${payload(pIndex)}.node, ${payload(pIndex)}.delegator, ${payload(pIndex)}.pool);`;
|
|
92
|
-
code += `${payload(pIndex)}.applier(${payload(pIndex)}.template, ${payload(pIndex)}.any);`;
|
|
93
|
-
code += '}';
|
|
94
|
-
code += `const target = root.${SF_CACHE}[${index}];`;
|
|
95
|
-
code += `const { replaces, clears, addes, swaps, removes, updates } = items.flush();`;
|
|
96
|
-
code += `if (replaces) {`;
|
|
97
|
-
code += `const items_count = items.size;`;
|
|
98
|
-
code += `const child_count = ${payload(pIndex)}.elements.length;`;
|
|
99
|
-
code += `const common_count = Math.min(items_count, child_count);`;
|
|
100
|
-
code += `for (let index = 0; index < common_count; index++) {`;
|
|
101
|
-
code += `${payload(pIndex)}.applier(${payload(pIndex)}.elements[index], items.at(index));`;
|
|
102
|
-
code += `}`;
|
|
103
|
-
code += `if (items_count < child_count) {`;
|
|
104
|
-
code += `for (let index = items_count; index < child_count; index++) {`;
|
|
105
|
-
code += `const element = ${payload(pIndex)}.elements[index];`;
|
|
106
|
-
code += `${payload(pIndex)}.pool.add(element);`;
|
|
107
|
-
code += `element.remove();`;
|
|
108
|
-
code += `}`;
|
|
109
|
-
code += `${payload(pIndex)}.elements.length = items_count;`;
|
|
110
|
-
code += `} else if (child_count < items_count) {`;
|
|
111
|
-
code += `const fragment = document.createDocumentFragment();`;
|
|
112
|
-
code += `const elements = new Array(items_count - child_count);`;
|
|
113
|
-
code += `for (let index = child_count; index < items_count; index++) {`;
|
|
114
|
-
code += `const element = ${payload(pIndex)}.pool.get() || ${payload(pIndex)}.template.cloneNode(true);`;
|
|
115
|
-
code += `element.${SF_HANDLERS} = ${payload(pIndex)}.template.${SF_HANDLERS};`;
|
|
116
|
-
code += `element.${SF_CONTEXT} = items.at(index);`;
|
|
117
|
-
code += `${payload(pIndex)}.applier(element, items.at(index));`;
|
|
118
|
-
code += `elements[index - child_count] = element;`;
|
|
119
|
-
code += `fragment.appendChild(element);`;
|
|
120
|
-
code += `}`;
|
|
121
|
-
code += `${payload(pIndex)}.elements = ${payload(pIndex)}.elements.concat(elements);`;
|
|
122
|
-
code += `target.appendChild(fragment);`;
|
|
123
|
-
code += `}`;
|
|
124
|
-
code += `break iter_${labels - 1};`;
|
|
125
|
-
code += `}`;
|
|
126
|
-
code += `if (clears) {`;
|
|
127
|
-
code += `const free = ${payload(pIndex)}.elements.splice(0);`;
|
|
128
|
-
code += `for (const element of free) {`;
|
|
129
|
-
code += `element.${SF_HANDLERS} = undefined;`;
|
|
130
|
-
code += `${payload(pIndex)}.pool.add(element);`;
|
|
131
|
-
code += `}`;
|
|
132
|
-
code += `target.innerHTML = String();`;
|
|
133
|
-
code += `}`;
|
|
134
|
-
code += `if (addes > 0) {`;
|
|
135
|
-
code += `const fragment = document.createDocumentFragment();`;
|
|
136
|
-
code += `const elements = new Array(addes);`;
|
|
137
|
-
code += `for (let index = 0; index < addes; index++) {`;
|
|
138
|
-
code += `const element = ${payload(pIndex)}.pool.get() || ${payload(pIndex)}.template.cloneNode(true);`;
|
|
139
|
-
code += `element.${SF_HANDLERS} = ${payload(pIndex)}.template.${SF_HANDLERS};`;
|
|
140
|
-
code += `element.${SF_CONTEXT} = items.at(index);`;
|
|
141
|
-
code += `${payload(pIndex)}.applier(element, items.at(index));`;
|
|
142
|
-
code += `elements[index] = element;`;
|
|
143
|
-
code += `fragment.appendChild(element);`;
|
|
144
|
-
code += `}`;
|
|
145
|
-
code += `${payload(pIndex)}.elements = ${payload(pIndex)}.elements.concat(elements);`;
|
|
146
|
-
code += `target.appendChild(fragment);`;
|
|
147
|
-
code += `}`;
|
|
148
|
-
code += `for (const [i, j] of swaps.entries()) {`;
|
|
149
|
-
code += `${payload(pIndex)}.applier(${payload(pIndex)}.elements[i], items.at(i));`;
|
|
150
|
-
code += `${payload(pIndex)}.applier(${payload(pIndex)}.elements[j], items.at(j));`;
|
|
151
|
-
code += `}`;
|
|
152
|
-
code += `for (const id of removes) {`;
|
|
153
|
-
code += `const element = ${payload(pIndex)}.elements[id];`;
|
|
154
|
-
code += `element.${SF_HANDLERS} = undefined;`;
|
|
155
|
-
code += `${payload(pIndex)}.pool.add(element);`;
|
|
156
|
-
code += `element.remove();`;
|
|
157
|
-
code += `}`;
|
|
158
|
-
code += `for (const id of updates) {`;
|
|
159
|
-
code += `${payload(pIndex)}.applier(${payload(pIndex)}.elements[id], items.at(id));`;
|
|
160
|
-
code += `}`;
|
|
161
|
-
code += `}`;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
code += '}';
|
|
165
|
-
const generator = new Function(...payloads.map((_, id) => payload(id)), code);
|
|
166
|
-
return generator(...payloads);
|
|
167
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AnyDOM } from "../dom.types.js";
|
|
2
|
-
import { Directives } from "../dom.directives.js";
|
|
3
|
-
type Instructions<V> = Partial<{
|
|
4
|
-
[L in keyof Directives<V>]: Directives<V>[L];
|
|
5
|
-
}> & {
|
|
6
|
-
id: number;
|
|
7
|
-
};
|
|
8
|
-
declare function markup_template<V>(node: AnyDOM<V>): (root: HTMLElement) => void;
|
|
9
|
-
declare function compile<V>(node: AnyDOM<V>): Instructions<V>[];
|
|
10
|
-
export { compile, markup_template };
|
|
11
|
-
export { Instructions };
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { SF_CACHE, SF_CACHE_TEXT } from "../dom.symbols.js";
|
|
2
|
-
function markup_template_code(node, path) {
|
|
3
|
-
let { modifiers } = node.properties;
|
|
4
|
-
let code = String();
|
|
5
|
-
const has_modifiers = modifiers?.text !== undefined ||
|
|
6
|
-
modifiers?.properties !== undefined ||
|
|
7
|
-
modifiers?.events !== undefined ||
|
|
8
|
-
modifiers?.iterate !== undefined ||
|
|
9
|
-
modifiers?.conditional !== undefined;
|
|
10
|
-
if (has_modifiers) {
|
|
11
|
-
code += `sf_markup_path.push(root${path.map(x => `.children[${x}]`).join(String())});`;
|
|
12
|
-
}
|
|
13
|
-
for (let index = 0; index < node.children.length; index++) {
|
|
14
|
-
code += markup_template_code(node.children[index], [...path, index]);
|
|
15
|
-
}
|
|
16
|
-
return code;
|
|
17
|
-
}
|
|
18
|
-
function markup_template(node) {
|
|
19
|
-
let code = String();
|
|
20
|
-
code += `return function(root) {`;
|
|
21
|
-
code += `if (root.${SF_CACHE}) {`;
|
|
22
|
-
code += `return;`;
|
|
23
|
-
code += `}`;
|
|
24
|
-
code += `let sf_markup_path = [];`;
|
|
25
|
-
code += markup_template_code(node, []);
|
|
26
|
-
code += `root.${SF_CACHE} = sf_markup_path;`;
|
|
27
|
-
code += `root.${SF_CACHE_TEXT} = sf_markup_path.map(node => node.firstChild);`;
|
|
28
|
-
code += `}`;
|
|
29
|
-
const generator = new Function(code);
|
|
30
|
-
return generator();
|
|
31
|
-
}
|
|
32
|
-
function compile_template(node, state) {
|
|
33
|
-
const modifiers = node.properties.modifiers || {};
|
|
34
|
-
const has_modifiers = modifiers.text !== undefined ||
|
|
35
|
-
modifiers.properties !== undefined ||
|
|
36
|
-
modifiers.events !== undefined ||
|
|
37
|
-
modifiers.iterate !== undefined ||
|
|
38
|
-
modifiers.conditional !== undefined;
|
|
39
|
-
if (has_modifiers) {
|
|
40
|
-
const current_id = state.id++;
|
|
41
|
-
const instruction = { id: current_id };
|
|
42
|
-
if (modifiers.text !== undefined) {
|
|
43
|
-
instruction.text = modifiers.text;
|
|
44
|
-
}
|
|
45
|
-
if (modifiers.properties !== undefined) {
|
|
46
|
-
instruction.properties = modifiers.properties;
|
|
47
|
-
}
|
|
48
|
-
if (modifiers.events !== undefined) {
|
|
49
|
-
instruction.events = modifiers.events;
|
|
50
|
-
}
|
|
51
|
-
if (modifiers.iterate !== undefined) {
|
|
52
|
-
instruction.iterate = modifiers.iterate;
|
|
53
|
-
}
|
|
54
|
-
if (modifiers.conditional !== undefined) {
|
|
55
|
-
instruction.conditional = modifiers.conditional;
|
|
56
|
-
}
|
|
57
|
-
state.instructions.push(instruction);
|
|
58
|
-
}
|
|
59
|
-
for (let index = 0; index < node.children.length; index++) {
|
|
60
|
-
compile_template(node.children[index], state);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function compile(node) {
|
|
64
|
-
const state = {
|
|
65
|
-
instructions: [],
|
|
66
|
-
id: 0
|
|
67
|
-
};
|
|
68
|
-
compile_template(node, state);
|
|
69
|
-
return state.instructions;
|
|
70
|
-
}
|
|
71
|
-
export { compile, markup_template };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const OPERATIONS = [];
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { collection } from "../../../index.js";
|
|
2
|
-
import { AnyDOM } from "../aot/dom.types.js";
|
|
3
|
-
export type Modifiers<Context, K extends keyof HTMLElementTagNameMap = any> = Partial<{
|
|
4
|
-
text: (context: Context) => string;
|
|
5
|
-
conditional: (context: Context) => boolean;
|
|
6
|
-
events: Partial<{
|
|
7
|
-
[L in keyof HTMLElementEventMap]: (event: HTMLElementEventMap[L], context: Context) => void;
|
|
8
|
-
}>;
|
|
9
|
-
properties: Partial<{
|
|
10
|
-
[L in keyof HTMLElementTagNameMap[K]]: (context: Context) => string;
|
|
11
|
-
}>;
|
|
12
|
-
iterate: {
|
|
13
|
-
select: <V>(context: Context) => collection.Flushable<V>;
|
|
14
|
-
each: () => AnyDOM<any>;
|
|
15
|
-
};
|
|
16
|
-
}>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|