@esportsplus/template 0.28.3 → 0.29.2
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 +431 -0
- package/build/attributes.d.ts +7 -1
- package/build/attributes.js +86 -33
- package/build/constants.d.ts +3 -11
- package/build/constants.js +4 -32
- package/build/event/constants.d.ts +3 -0
- package/build/event/constants.js +13 -0
- package/build/event/index.d.ts +9 -1
- package/build/event/index.js +29 -35
- package/build/event/ontick.js +6 -9
- package/build/html.d.ts +9 -0
- package/build/html.js +7 -0
- package/build/index.d.ts +8 -2
- package/build/index.js +8 -1
- package/build/render.d.ts +2 -2
- package/build/render.js +2 -3
- package/build/runtime.d.ts +1 -0
- package/build/runtime.js +5 -0
- package/build/slot/array.d.ts +3 -3
- package/build/slot/array.js +11 -14
- package/build/slot/cleanup.d.ts +1 -1
- package/build/slot/cleanup.js +1 -2
- package/build/slot/effect.js +5 -7
- package/build/slot/index.js +1 -7
- package/build/slot/render.js +6 -8
- package/build/svg.d.ts +1 -1
- package/build/svg.js +1 -1
- package/build/transformer/codegen.d.ts +18 -0
- package/build/transformer/codegen.js +316 -0
- package/build/transformer/index.d.ts +12 -0
- package/build/transformer/index.js +62 -0
- package/build/transformer/parser.d.ts +18 -0
- package/build/transformer/parser.js +166 -0
- package/build/transformer/plugins/esbuild.d.ts +5 -0
- package/build/transformer/plugins/esbuild.js +35 -0
- package/build/transformer/plugins/tsc.d.ts +3 -0
- package/build/transformer/plugins/tsc.js +4 -0
- package/build/transformer/plugins/vite.d.ts +5 -0
- package/build/transformer/plugins/vite.js +37 -0
- package/build/transformer/ts-parser.d.ts +21 -0
- package/build/transformer/ts-parser.js +72 -0
- package/build/transformer/type-analyzer.d.ts +7 -0
- package/build/transformer/type-analyzer.js +230 -0
- package/build/types.d.ts +2 -3
- package/build/utilities.d.ts +7 -0
- package/build/utilities.js +31 -0
- package/package.json +33 -4
- package/src/attributes.ts +115 -51
- package/src/constants.ts +6 -53
- package/src/event/constants.ts +16 -0
- package/src/event/index.ts +36 -42
- package/src/event/onconnect.ts +1 -1
- package/src/event/onresize.ts +1 -1
- package/src/event/ontick.ts +7 -11
- package/src/html.ts +18 -0
- package/src/index.ts +8 -2
- package/src/render.ts +6 -7
- package/src/runtime.ts +8 -0
- package/src/slot/array.ts +18 -24
- package/src/slot/cleanup.ts +3 -4
- package/src/slot/effect.ts +6 -8
- package/src/slot/index.ts +2 -8
- package/src/slot/render.ts +7 -9
- package/src/svg.ts +1 -1
- package/src/transformer/codegen.ts +518 -0
- package/src/transformer/index.ts +98 -0
- package/src/transformer/parser.ts +239 -0
- package/src/transformer/plugins/esbuild.ts +46 -0
- package/src/transformer/plugins/tsc.ts +7 -0
- package/src/transformer/plugins/vite.ts +49 -0
- package/src/transformer/ts-parser.ts +123 -0
- package/src/transformer/type-analyzer.ts +334 -0
- package/src/types.ts +3 -4
- package/src/utilities.ts +52 -0
- package/storage/rewrite-analysis-2026-01-04.md +439 -0
- package/test/constants.ts +69 -0
- package/test/effects.ts +237 -0
- package/test/events.ts +318 -0
- package/test/imported-values.ts +253 -0
- package/test/nested.ts +298 -0
- package/test/slots.ts +259 -0
- package/test/spread.ts +290 -0
- package/test/static.ts +118 -0
- package/test/templates.ts +473 -0
- package/test/tsconfig.json +17 -0
- package/test/vite.config.ts +50 -0
- package/build/html/index.d.ts +0 -9
- package/build/html/index.js +0 -29
- package/build/html/parser.d.ts +0 -5
- package/build/html/parser.js +0 -165
- package/build/utilities/element.d.ts +0 -11
- package/build/utilities/element.js +0 -9
- package/build/utilities/fragment.d.ts +0 -3
- package/build/utilities/fragment.js +0 -10
- package/build/utilities/marker.d.ts +0 -2
- package/build/utilities/marker.js +0 -4
- package/build/utilities/node.d.ts +0 -9
- package/build/utilities/node.js +0 -10
- package/build/utilities/raf.d.ts +0 -2
- package/build/utilities/raf.js +0 -1
- package/build/utilities/text.d.ts +0 -2
- package/build/utilities/text.js +0 -9
- package/src/html/index.ts +0 -48
- package/src/html/parser.ts +0 -235
- package/src/utilities/element.ts +0 -28
- package/src/utilities/fragment.ts +0 -19
- package/src/utilities/marker.ts +0 -6
- package/src/utilities/node.ts +0 -29
- package/src/utilities/raf.ts +0 -1
- package/src/utilities/text.ts +0 -15
package/src/slot/array.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { read, root, set, signal, ReactiveArray } from '@esportsplus/reactivity';
|
|
2
2
|
import { ARRAY_SLOT, EMPTY_FRAGMENT } from '~/constants';
|
|
3
|
-
import { SlotGroup } from '~/types';
|
|
4
|
-
import {
|
|
5
|
-
import { cloneNode, firstChild, lastChild, nextSibling } from '~/utilities/node';
|
|
3
|
+
import { Element, SlotGroup } from '~/types';
|
|
4
|
+
import { clone, marker, raf } from '~/utilities';
|
|
6
5
|
import { ondisconnect, remove } from './cleanup';
|
|
7
|
-
import marker from '~/utilities/marker';
|
|
8
|
-
import raf from '~/utilities/raf';
|
|
9
6
|
import html from '~/html';
|
|
10
7
|
|
|
11
8
|
|
|
@@ -22,20 +19,20 @@ type ArraySlotOp<T> =
|
|
|
22
19
|
|
|
23
20
|
|
|
24
21
|
class ArraySlot<T> {
|
|
25
|
-
private queue: ArraySlotOp<T>[] = [];
|
|
26
22
|
private marker: Element;
|
|
27
23
|
private nodes: SlotGroup[] = [];
|
|
28
|
-
private
|
|
24
|
+
private queue: ArraySlotOp<T>[] = [];
|
|
25
|
+
private scheduled = false;
|
|
29
26
|
private signal;
|
|
30
27
|
private template: (...args: Parameters<(value: T) => ReturnType<typeof html>>) => SlotGroup;
|
|
31
28
|
|
|
32
|
-
readonly fragment:
|
|
29
|
+
readonly fragment: DocumentFragment;
|
|
33
30
|
|
|
34
31
|
|
|
35
32
|
constructor(private array: ReactiveArray<T>, template: ((value: T) => ReturnType<typeof html>)) {
|
|
36
|
-
let fragment = this.fragment =
|
|
33
|
+
let fragment = this.fragment = clone(EMPTY_FRAGMENT);
|
|
37
34
|
|
|
38
|
-
this.marker = marker.cloneNode();
|
|
35
|
+
this.marker = marker.cloneNode() as unknown as Element;
|
|
39
36
|
this.signal = signal(array.length);
|
|
40
37
|
this.template = function (data) {
|
|
41
38
|
let dispose: VoidFunction,
|
|
@@ -44,17 +41,17 @@ class ArraySlot<T> {
|
|
|
44
41
|
return template(data);
|
|
45
42
|
}),
|
|
46
43
|
group = {
|
|
47
|
-
head: firstChild
|
|
48
|
-
tail: lastChild
|
|
44
|
+
head: frag.firstChild as unknown as Element,
|
|
45
|
+
tail: frag.lastChild as unknown as Element
|
|
49
46
|
};
|
|
50
47
|
|
|
51
|
-
append
|
|
48
|
+
fragment.append(frag);
|
|
52
49
|
ondisconnect(group.head, dispose!);
|
|
53
50
|
|
|
54
51
|
return group;
|
|
55
52
|
};
|
|
56
53
|
|
|
57
|
-
append
|
|
54
|
+
fragment.append(this.marker);
|
|
58
55
|
|
|
59
56
|
if (array.length) {
|
|
60
57
|
root(() => {
|
|
@@ -118,8 +115,7 @@ class ArraySlot<T> {
|
|
|
118
115
|
private push(items: T[]) {
|
|
119
116
|
let anchor = this.anchor();
|
|
120
117
|
|
|
121
|
-
this.nodes.push(
|
|
122
|
-
|
|
118
|
+
this.nodes.push(...items.map(this.template));
|
|
123
119
|
anchor.after(this.fragment);
|
|
124
120
|
}
|
|
125
121
|
|
|
@@ -135,7 +131,8 @@ class ArraySlot<T> {
|
|
|
135
131
|
raf(() => {
|
|
136
132
|
let queue = this.queue;
|
|
137
133
|
|
|
138
|
-
this.queue
|
|
134
|
+
this.queue = [];
|
|
135
|
+
this.scheduled = false;
|
|
139
136
|
|
|
140
137
|
root(() => {
|
|
141
138
|
for (let i = 0, n = queue.length; i < n; i++) {
|
|
@@ -175,7 +172,6 @@ class ArraySlot<T> {
|
|
|
175
172
|
});
|
|
176
173
|
|
|
177
174
|
set(this.signal, this.nodes.length);
|
|
178
|
-
this.scheduled = false;
|
|
179
175
|
});
|
|
180
176
|
}
|
|
181
177
|
|
|
@@ -193,7 +189,6 @@ class ArraySlot<T> {
|
|
|
193
189
|
|
|
194
190
|
if (n !== order.length) {
|
|
195
191
|
remove(...nodes.splice(0));
|
|
196
|
-
|
|
197
192
|
this.nodes = this.array.map(this.template);
|
|
198
193
|
this.marker.after(this.fragment);
|
|
199
194
|
return;
|
|
@@ -215,7 +210,7 @@ class ArraySlot<T> {
|
|
|
215
210
|
return;
|
|
216
211
|
}
|
|
217
212
|
|
|
218
|
-
remove(
|
|
213
|
+
remove(...this.nodes.splice(start, stop, ...items.map(this.template)));
|
|
219
214
|
this.anchor(start - 1).after(this.fragment);
|
|
220
215
|
}
|
|
221
216
|
|
|
@@ -233,9 +228,8 @@ class ArraySlot<T> {
|
|
|
233
228
|
node: Node | null = group.head;
|
|
234
229
|
|
|
235
230
|
while (node) {
|
|
236
|
-
next = node === group.tail ? null : nextSibling
|
|
237
|
-
|
|
238
|
-
append.call(this.fragment, node);
|
|
231
|
+
next = node === group.tail ? null : node.nextSibling;
|
|
232
|
+
this.fragment.append(node);
|
|
239
233
|
node = next;
|
|
240
234
|
}
|
|
241
235
|
}
|
|
@@ -257,4 +251,4 @@ class ArraySlot<T> {
|
|
|
257
251
|
Object.defineProperty(ArraySlot.prototype, ARRAY_SLOT, { value: true });
|
|
258
252
|
|
|
259
253
|
|
|
260
|
-
export { ArraySlot };
|
|
254
|
+
export { ArraySlot };
|
package/src/slot/cleanup.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CLEANUP } from '~/constants';
|
|
2
|
-
import {
|
|
3
|
-
import { SlotGroup } from '~/types';
|
|
2
|
+
import { Element, SlotGroup } from '~/types';
|
|
4
3
|
|
|
5
4
|
|
|
6
5
|
const ondisconnect = (element: Element, fn: VoidFunction) => {
|
|
@@ -24,7 +23,7 @@ const remove = (...groups: SlotGroup[]) => {
|
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
next = previousSibling
|
|
26
|
+
next = tail.previousSibling as unknown as Element;
|
|
28
27
|
tail.remove();
|
|
29
28
|
|
|
30
29
|
if (head === tail) {
|
|
@@ -37,4 +36,4 @@ const remove = (...groups: SlotGroup[]) => {
|
|
|
37
36
|
};
|
|
38
37
|
|
|
39
38
|
|
|
40
|
-
export { ondisconnect, remove };
|
|
39
|
+
export { ondisconnect, remove };
|
package/src/slot/effect.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { effect } from '@esportsplus/reactivity';
|
|
2
2
|
import { Element, Renderable, SlotGroup } from '~/types';
|
|
3
|
-
import { firstChild, lastChild, nodeValue } from '~/utilities/node'
|
|
4
3
|
import { remove } from './cleanup';
|
|
5
|
-
import raf from '~/utilities
|
|
6
|
-
import text from '~/utilities/text';
|
|
4
|
+
import { raf, text } from '~/utilities'
|
|
7
5
|
import render from './render';
|
|
8
6
|
|
|
9
7
|
|
|
@@ -82,7 +80,7 @@ class EffectSlot {
|
|
|
82
80
|
}
|
|
83
81
|
|
|
84
82
|
if (textnode) {
|
|
85
|
-
nodeValue
|
|
83
|
+
textnode.nodeValue = value as string;
|
|
86
84
|
|
|
87
85
|
if (!textnode.isConnected) {
|
|
88
86
|
anchor.after(textnode);
|
|
@@ -94,7 +92,7 @@ class EffectSlot {
|
|
|
94
92
|
}
|
|
95
93
|
else {
|
|
96
94
|
let fragment = render(anchor, value),
|
|
97
|
-
head = firstChild
|
|
95
|
+
head = fragment.firstChild;
|
|
98
96
|
|
|
99
97
|
if (textnode?.isConnected) {
|
|
100
98
|
remove({ head: textnode as Element, tail: textnode as Element });
|
|
@@ -102,8 +100,8 @@ class EffectSlot {
|
|
|
102
100
|
|
|
103
101
|
if (head) {
|
|
104
102
|
this.group = {
|
|
105
|
-
head,
|
|
106
|
-
tail: lastChild
|
|
103
|
+
head: head as Element,
|
|
104
|
+
tail: fragment.lastChild as Element
|
|
107
105
|
};
|
|
108
106
|
|
|
109
107
|
anchor.after(fragment);
|
|
@@ -113,4 +111,4 @@ class EffectSlot {
|
|
|
113
111
|
}
|
|
114
112
|
|
|
115
113
|
|
|
116
|
-
export { EffectSlot };
|
|
114
|
+
export { EffectSlot };
|
package/src/slot/index.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { Element } from '~/types';
|
|
2
|
-
import { EffectSlot } from './effect';
|
|
3
2
|
import render from './render';
|
|
4
3
|
|
|
5
4
|
|
|
6
5
|
export default (anchor: Element, value: unknown): void => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
anchor.after( render(anchor, value) );
|
|
12
|
-
}
|
|
13
|
-
};
|
|
6
|
+
anchor.after( render(anchor, value) );
|
|
7
|
+
};
|
package/src/slot/render.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { isArray } from '@esportsplus/utilities';
|
|
2
2
|
import { ARRAY_SLOT, EMPTY_FRAGMENT } from '~/constants';
|
|
3
3
|
import { Element } from '~/types';
|
|
4
|
-
import {
|
|
5
|
-
import { append } from '~/utilities/fragment';
|
|
4
|
+
import { clone, text } from '~/utilities';
|
|
6
5
|
import { ArraySlot } from './array';
|
|
7
|
-
import text from '~/utilities/text';
|
|
8
6
|
|
|
9
7
|
|
|
10
8
|
export default function render(anchor: Element, value: unknown): Node {
|
|
@@ -36,25 +34,25 @@ export default function render(anchor: Element, value: unknown): Node {
|
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
if (isArray(value)) {
|
|
39
|
-
let fragment =
|
|
37
|
+
let fragment = clone(EMPTY_FRAGMENT) as DocumentFragment;
|
|
40
38
|
|
|
41
39
|
for (let i = 0; i < n; i++) {
|
|
42
|
-
append
|
|
43
|
-
anchor = lastChild
|
|
40
|
+
fragment.append(render(anchor, value[i]));
|
|
41
|
+
anchor = fragment.lastChild as Element;
|
|
44
42
|
}
|
|
45
43
|
|
|
46
44
|
return fragment;
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
if (value instanceof NodeList) {
|
|
50
|
-
let fragment =
|
|
48
|
+
let fragment = clone(EMPTY_FRAGMENT) as DocumentFragment;
|
|
51
49
|
|
|
52
50
|
for (let i = 0; i < n; i++) {
|
|
53
|
-
append
|
|
51
|
+
fragment.append(value[i]);
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
return fragment;
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
return text(value as any);
|
|
60
|
-
};
|
|
58
|
+
};
|
package/src/svg.ts
CHANGED