@esportsplus/template 0.32.0 → 0.32.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/build/attributes.js +1 -2
- package/build/constants.d.ts +18 -3
- package/build/constants.js +31 -4
- package/build/html.d.ts +3 -3
- package/build/index.d.ts +3 -3
- package/build/index.js +3 -3
- package/build/slot/array.d.ts +2 -2
- package/build/slot/array.js +5 -4
- package/build/slot/render.js +3 -2
- package/build/transformer/codegen.d.ts +3 -9
- package/build/transformer/codegen.js +90 -147
- package/build/transformer/index.d.ts +1 -5
- package/build/transformer/index.js +30 -46
- package/build/transformer/parser.d.ts +3 -2
- package/build/transformer/parser.js +4 -4
- package/build/transformer/plugins/tsc.d.ts +2 -2
- package/build/transformer/plugins/tsc.js +3 -4
- package/build/transformer/plugins/vite.d.ts +11 -3
- package/build/transformer/plugins/vite.js +7 -37
- package/build/transformer/ts-parser.d.ts +1 -2
- package/build/transformer/ts-parser.js +28 -41
- package/build/transformer/type-analyzer.d.ts +4 -5
- package/build/transformer/type-analyzer.js +73 -118
- package/build/types.d.ts +1 -1
- package/package.json +7 -7
- package/src/attributes.ts +1 -4
- package/src/constants.ts +42 -6
- package/src/html.ts +3 -3
- package/src/index.ts +5 -3
- package/src/slot/array.ts +9 -6
- package/src/slot/render.ts +5 -2
- package/src/transformer/codegen.ts +119 -189
- package/src/transformer/index.ts +34 -54
- package/src/transformer/parser.ts +10 -7
- package/src/transformer/plugins/tsc.ts +3 -5
- package/src/transformer/plugins/vite.ts +7 -47
- package/src/transformer/ts-parser.ts +34 -54
- package/src/transformer/type-analyzer.ts +90 -158
- package/src/types.ts +1 -1
- package/test/vite.config.ts +1 -1
- package/build/event/constants.d.ts +0 -3
- package/build/event/constants.js +0 -13
- package/src/event/constants.ts +0 -16
- package/storage/rewrite-analysis-2026-01-04.md +0 -439
package/package.json
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
"author": "ICJR",
|
|
3
3
|
"dependencies": {
|
|
4
4
|
"@esportsplus/queue": "^0.2.0",
|
|
5
|
-
"@esportsplus/reactivity": "^0.25.
|
|
5
|
+
"@esportsplus/reactivity": "^0.25.12",
|
|
6
6
|
"@esportsplus/utilities": "^0.27.2",
|
|
7
7
|
"serve": "^14.2.5"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"@esportsplus/typescript": "^0.
|
|
10
|
+
"@esportsplus/typescript": "^0.18.0",
|
|
11
11
|
"@types/node": "^25.0.3",
|
|
12
12
|
"vite": "^7.3.0",
|
|
13
13
|
"vite-tsconfig-paths": "^6.0.3"
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"types": "./build/constants.d.ts"
|
|
23
23
|
},
|
|
24
24
|
"./plugins/tsc": {
|
|
25
|
+
"types": "./build/transformer/plugins/tsc.d.ts",
|
|
25
26
|
"import": "./build/transformer/plugins/tsc.js",
|
|
26
|
-
"require": "./build/transformer/plugins/tsc.js"
|
|
27
|
-
"types": "./build/transformer/plugins/tsc.d.ts"
|
|
27
|
+
"require": "./build/transformer/plugins/tsc.js"
|
|
28
28
|
},
|
|
29
29
|
"./plugins/vite": {
|
|
30
|
-
"
|
|
31
|
-
"
|
|
30
|
+
"types": "./build/transformer/plugins/vite.d.ts",
|
|
31
|
+
"import": "./build/transformer/plugins/vite.js"
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"main": "./build/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"type": "module",
|
|
42
42
|
"types": "./build/index.d.ts",
|
|
43
|
-
"version": "0.32.
|
|
43
|
+
"version": "0.32.2",
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsc",
|
|
46
46
|
"build:test": "vite build --config test/vite.config.ts",
|
package/src/attributes.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { effect } from '@esportsplus/reactivity';
|
|
2
2
|
import { isArray, isObject } from '@esportsplus/utilities';
|
|
3
|
-
import { DIRECT_ATTACH_EVENTS, LIFECYCLE_EVENTS, STATE_HYDRATING, STATE_NONE, STATE_WAITING } from './constants';
|
|
3
|
+
import { DIRECT_ATTACH_EVENTS, LIFECYCLE_EVENTS, STATE_HYDRATING, STATE_NONE, STATE_WAITING, STORE } from './constants';
|
|
4
4
|
import { Attributes, Element } from './types';
|
|
5
5
|
import { raf } from './utilities';
|
|
6
6
|
import q from '@esportsplus/queue';
|
|
7
7
|
import event from './event';
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
const STORE = Symbol();
|
|
11
|
-
|
|
12
|
-
|
|
13
10
|
type Context = {
|
|
14
11
|
effect?: 0,
|
|
15
12
|
element: Element;
|
package/src/constants.ts
CHANGED
|
@@ -1,11 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { uid } from '@esportsplus/typescript/transformer';
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
const ARRAY_SLOT = Symbol('template.array.slot');
|
|
5
5
|
|
|
6
6
|
const CLEANUP = Symbol('template.cleanup');
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
const COMPILER_ENTRYPOINT = 'html';
|
|
10
|
+
|
|
11
|
+
const COMPILER_ENTRYPOINT_REACTIVITY = 'reactive';
|
|
12
|
+
|
|
13
|
+
const COMPILER_NAMESPACE = uid('template');
|
|
14
|
+
|
|
15
|
+
const enum COMPILER_TYPES {
|
|
16
|
+
ArraySlot,
|
|
17
|
+
AttributeSlot,
|
|
18
|
+
AttributeSpreadSlot,
|
|
19
|
+
DocumentFragment,
|
|
20
|
+
Effect,
|
|
21
|
+
NodeSlot,
|
|
22
|
+
Primitive,
|
|
23
|
+
Static,
|
|
24
|
+
Unknown
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const DIRECT_ATTACH_EVENTS = new Set<string>([
|
|
28
|
+
'onblur',
|
|
29
|
+
'onerror',
|
|
30
|
+
'onfocus', 'onfocusin', 'onfocusout',
|
|
31
|
+
'onload',
|
|
32
|
+
'onplay', 'onpause', 'onended', 'ontimeupdate',
|
|
33
|
+
'onreset',
|
|
34
|
+
'onscroll', 'onsubmit'
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
const LIFECYCLE_EVENTS = new Set<string>([
|
|
38
|
+
'onconnect', 'ondisconnect', 'onrender', 'onresize', 'ontick'
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
const PACKAGE = '@esportsplus/template';
|
|
42
|
+
|
|
9
43
|
|
|
10
44
|
const SLOT_HTML = '<!--$-->';
|
|
11
45
|
|
|
@@ -21,7 +55,9 @@ const STORE = Symbol('template.store');
|
|
|
21
55
|
export {
|
|
22
56
|
ARRAY_SLOT,
|
|
23
57
|
CLEANUP,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
58
|
+
COMPILER_ENTRYPOINT, COMPILER_ENTRYPOINT_REACTIVITY, COMPILER_NAMESPACE, COMPILER_TYPES,
|
|
59
|
+
DIRECT_ATTACH_EVENTS,
|
|
60
|
+
LIFECYCLE_EVENTS,
|
|
61
|
+
PACKAGE,
|
|
62
|
+
SLOT_HTML, STATE_HYDRATING, STATE_NONE, STATE_WAITING, STORE,
|
|
63
|
+
};
|
package/src/html.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Reactive } from '@esportsplus/reactivity';
|
|
2
2
|
import { Attribute, Attributes, Renderable } from '~/types';
|
|
3
3
|
import { ArraySlot } from '~/slot/array';
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
type Values<T> = Attribute | Attributes<any> |
|
|
6
|
+
type Values<T> = ArraySlot<T extends unknown[] ? T : never> | Attribute | Attributes<any> | Renderable<T>;
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
const html = <T>(_literals: TemplateStringsArray, ..._values: (Values<T> | Values<T>[])[]): DocumentFragment => {
|
|
10
10
|
throw new Error('html`` templates must be compiled. Ensure vite-plugin is configured.');
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
html.reactive = <T>(_arr:
|
|
13
|
+
html.reactive = <T>(_arr: Reactive<T[]>, _template: (value: T) => DocumentFragment): ArraySlot<T[]> => {
|
|
14
14
|
throw new Error('html.reactive() must be compiled. Ensure vite-plugin is configured.');
|
|
15
15
|
};
|
|
16
16
|
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import './runtime';
|
|
2
|
-
export { default as attributes } from './attributes';
|
|
3
|
-
export { default as event } from './event';
|
|
4
2
|
export { default as html } from './html';
|
|
5
3
|
export { default as render } from './render';
|
|
6
|
-
export { default as slot } from './slot';
|
|
7
4
|
export { default as svg } from './svg';
|
|
5
|
+
|
|
6
|
+
// Must be exported for compilation even if not used directly
|
|
7
|
+
export { default as attributes } from './attributes';
|
|
8
|
+
export { default as event } from './event';
|
|
9
|
+
export { default as slot } from './slot';
|
|
8
10
|
export { ArraySlot } from './slot/array';
|
|
9
11
|
export { EffectSlot } from './slot/effect';
|
|
10
12
|
export type { Attributes, Element, Renderable } from './types';
|
package/src/slot/array.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { read, root,
|
|
2
|
-
import { ARRAY_SLOT
|
|
1
|
+
import { read, root, signal, write, Reactive } from '@esportsplus/reactivity';
|
|
2
|
+
import { ARRAY_SLOT } from '~/constants';
|
|
3
3
|
import { Element, SlotGroup } from '~/types';
|
|
4
|
-
import { clone, marker, raf } from '~/utilities';
|
|
4
|
+
import { clone, fragment, marker, raf } from '~/utilities';
|
|
5
5
|
import { ondisconnect, remove } from './cleanup';
|
|
6
6
|
import html from '~/html';
|
|
7
7
|
|
|
@@ -18,18 +18,21 @@ type ArraySlotOp<T> =
|
|
|
18
18
|
| { op: 'sort'; order: number[] };
|
|
19
19
|
|
|
20
20
|
|
|
21
|
+
const EMPTY_FRAGMENT = fragment('');
|
|
22
|
+
|
|
23
|
+
|
|
21
24
|
class ArraySlot<T> {
|
|
22
25
|
private marker: Element;
|
|
23
26
|
private nodes: SlotGroup[] = [];
|
|
24
27
|
private queue: ArraySlotOp<T>[] = [];
|
|
25
28
|
private scheduled = false;
|
|
26
29
|
private signal;
|
|
27
|
-
private template: (...args: Parameters<(value: T) => ReturnType<typeof html>>) => SlotGroup;
|
|
30
|
+
private template: (...args: Parameters<(value: Reactive<T[]>[number]) => ReturnType<typeof html>>) => SlotGroup;
|
|
28
31
|
|
|
29
32
|
readonly fragment: DocumentFragment;
|
|
30
33
|
|
|
31
34
|
|
|
32
|
-
constructor(private array:
|
|
35
|
+
constructor(private array: Reactive<T[]>, template: ((value: Reactive<T[]>[number]) => ReturnType<typeof html>)) {
|
|
33
36
|
let fragment = this.fragment = clone(EMPTY_FRAGMENT);
|
|
34
37
|
|
|
35
38
|
this.marker = marker.cloneNode() as unknown as Element;
|
|
@@ -171,7 +174,7 @@ class ArraySlot<T> {
|
|
|
171
174
|
}
|
|
172
175
|
});
|
|
173
176
|
|
|
174
|
-
|
|
177
|
+
write(this.signal, this.nodes.length);
|
|
175
178
|
});
|
|
176
179
|
}
|
|
177
180
|
|
package/src/slot/render.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { isArray } from '@esportsplus/utilities';
|
|
2
|
-
import { ARRAY_SLOT
|
|
2
|
+
import { ARRAY_SLOT } from '~/constants';
|
|
3
3
|
import { Element } from '~/types';
|
|
4
|
-
import { clone, text } from '~/utilities';
|
|
4
|
+
import { clone, fragment, text } from '~/utilities';
|
|
5
5
|
import { ArraySlot } from './array';
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
const EMPTY_FRAGMENT = fragment('');
|
|
9
|
+
|
|
10
|
+
|
|
8
11
|
export default function render(anchor: Element, value: unknown): Node {
|
|
9
12
|
if (value == null || value === false || value === '') {
|
|
10
13
|
return EMPTY_FRAGMENT;
|