@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.
Files changed (110) hide show
  1. package/README.md +431 -0
  2. package/build/attributes.d.ts +7 -1
  3. package/build/attributes.js +86 -33
  4. package/build/constants.d.ts +3 -11
  5. package/build/constants.js +4 -32
  6. package/build/event/constants.d.ts +3 -0
  7. package/build/event/constants.js +13 -0
  8. package/build/event/index.d.ts +9 -1
  9. package/build/event/index.js +29 -35
  10. package/build/event/ontick.js +6 -9
  11. package/build/html.d.ts +9 -0
  12. package/build/html.js +7 -0
  13. package/build/index.d.ts +8 -2
  14. package/build/index.js +8 -1
  15. package/build/render.d.ts +2 -2
  16. package/build/render.js +2 -3
  17. package/build/runtime.d.ts +1 -0
  18. package/build/runtime.js +5 -0
  19. package/build/slot/array.d.ts +3 -3
  20. package/build/slot/array.js +11 -14
  21. package/build/slot/cleanup.d.ts +1 -1
  22. package/build/slot/cleanup.js +1 -2
  23. package/build/slot/effect.js +5 -7
  24. package/build/slot/index.js +1 -7
  25. package/build/slot/render.js +6 -8
  26. package/build/svg.d.ts +1 -1
  27. package/build/svg.js +1 -1
  28. package/build/transformer/codegen.d.ts +18 -0
  29. package/build/transformer/codegen.js +316 -0
  30. package/build/transformer/index.d.ts +12 -0
  31. package/build/transformer/index.js +62 -0
  32. package/build/transformer/parser.d.ts +18 -0
  33. package/build/transformer/parser.js +166 -0
  34. package/build/transformer/plugins/esbuild.d.ts +5 -0
  35. package/build/transformer/plugins/esbuild.js +35 -0
  36. package/build/transformer/plugins/tsc.d.ts +3 -0
  37. package/build/transformer/plugins/tsc.js +4 -0
  38. package/build/transformer/plugins/vite.d.ts +5 -0
  39. package/build/transformer/plugins/vite.js +37 -0
  40. package/build/transformer/ts-parser.d.ts +21 -0
  41. package/build/transformer/ts-parser.js +72 -0
  42. package/build/transformer/type-analyzer.d.ts +7 -0
  43. package/build/transformer/type-analyzer.js +230 -0
  44. package/build/types.d.ts +2 -3
  45. package/build/utilities.d.ts +7 -0
  46. package/build/utilities.js +31 -0
  47. package/package.json +33 -4
  48. package/src/attributes.ts +115 -51
  49. package/src/constants.ts +6 -53
  50. package/src/event/constants.ts +16 -0
  51. package/src/event/index.ts +36 -42
  52. package/src/event/onconnect.ts +1 -1
  53. package/src/event/onresize.ts +1 -1
  54. package/src/event/ontick.ts +7 -11
  55. package/src/html.ts +18 -0
  56. package/src/index.ts +8 -2
  57. package/src/render.ts +6 -7
  58. package/src/runtime.ts +8 -0
  59. package/src/slot/array.ts +18 -24
  60. package/src/slot/cleanup.ts +3 -4
  61. package/src/slot/effect.ts +6 -8
  62. package/src/slot/index.ts +2 -8
  63. package/src/slot/render.ts +7 -9
  64. package/src/svg.ts +1 -1
  65. package/src/transformer/codegen.ts +518 -0
  66. package/src/transformer/index.ts +98 -0
  67. package/src/transformer/parser.ts +239 -0
  68. package/src/transformer/plugins/esbuild.ts +46 -0
  69. package/src/transformer/plugins/tsc.ts +7 -0
  70. package/src/transformer/plugins/vite.ts +49 -0
  71. package/src/transformer/ts-parser.ts +123 -0
  72. package/src/transformer/type-analyzer.ts +334 -0
  73. package/src/types.ts +3 -4
  74. package/src/utilities.ts +52 -0
  75. package/storage/rewrite-analysis-2026-01-04.md +439 -0
  76. package/test/constants.ts +69 -0
  77. package/test/effects.ts +237 -0
  78. package/test/events.ts +318 -0
  79. package/test/imported-values.ts +253 -0
  80. package/test/nested.ts +298 -0
  81. package/test/slots.ts +259 -0
  82. package/test/spread.ts +290 -0
  83. package/test/static.ts +118 -0
  84. package/test/templates.ts +473 -0
  85. package/test/tsconfig.json +17 -0
  86. package/test/vite.config.ts +50 -0
  87. package/build/html/index.d.ts +0 -9
  88. package/build/html/index.js +0 -29
  89. package/build/html/parser.d.ts +0 -5
  90. package/build/html/parser.js +0 -165
  91. package/build/utilities/element.d.ts +0 -11
  92. package/build/utilities/element.js +0 -9
  93. package/build/utilities/fragment.d.ts +0 -3
  94. package/build/utilities/fragment.js +0 -10
  95. package/build/utilities/marker.d.ts +0 -2
  96. package/build/utilities/marker.js +0 -4
  97. package/build/utilities/node.d.ts +0 -9
  98. package/build/utilities/node.js +0 -10
  99. package/build/utilities/raf.d.ts +0 -2
  100. package/build/utilities/raf.js +0 -1
  101. package/build/utilities/text.d.ts +0 -2
  102. package/build/utilities/text.js +0 -9
  103. package/src/html/index.ts +0 -48
  104. package/src/html/parser.ts +0 -235
  105. package/src/utilities/element.ts +0 -28
  106. package/src/utilities/fragment.ts +0 -19
  107. package/src/utilities/marker.ts +0 -6
  108. package/src/utilities/node.ts +0 -29
  109. package/src/utilities/raf.ts +0 -1
  110. 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 { append } from '~/utilities/fragment';
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 scheduled: boolean = false;
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: Node;
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 = cloneNode.call(EMPTY_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.call(frag),
48
- tail: lastChild.call(frag)
44
+ head: frag.firstChild as unknown as Element,
45
+ tail: frag.lastChild as unknown as Element
49
46
  };
50
47
 
51
- append.call(fragment, frag);
48
+ fragment.append(frag);
52
49
  ondisconnect(group.head, dispose!);
53
50
 
54
51
  return group;
55
52
  };
56
53
 
57
- append.call(fragment, this.marker);
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( ...items.map(this.template) );
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.length = 0;
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( ...this.nodes.splice(start, stop, ...items.map(this.template)) );
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.call(node);
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 };
@@ -1,6 +1,5 @@
1
1
  import { CLEANUP } from '~/constants';
2
- import { previousSibling } from '~/utilities/node';
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.call(tail);
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 };
@@ -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/raf'
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.call(textnode, value);
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.call(fragment);
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.call(fragment)
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
- if (typeof value === 'function') {
8
- new EffectSlot(anchor, value as ConstructorParameters<typeof EffectSlot>[1]);
9
- }
10
- else {
11
- anchor.after( render(anchor, value) );
12
- }
13
- };
6
+ anchor.after( render(anchor, value) );
7
+ };
@@ -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 { cloneNode, lastChild } from '~/utilities/node';
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 = cloneNode.call(EMPTY_FRAGMENT);
37
+ let fragment = clone(EMPTY_FRAGMENT) as DocumentFragment;
40
38
 
41
39
  for (let i = 0; i < n; i++) {
42
- append.call(fragment, render(anchor, value[i]));
43
- anchor = lastChild.call(fragment);
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 = cloneNode.call(EMPTY_FRAGMENT);
48
+ let fragment = clone(EMPTY_FRAGMENT) as DocumentFragment;
51
49
 
52
50
  for (let i = 0; i < n; i++) {
53
- append.call(fragment, value[i]);
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
@@ -14,4 +14,4 @@ svg.sprite = (href: string) => {
14
14
  };
15
15
 
16
16
 
17
- export default svg;
17
+ export default svg;