@esportsplus/template 0.16.0 → 0.16.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 (53) hide show
  1. package/.editorconfig +9 -9
  2. package/.gitattributes +2 -2
  3. package/.github/dependabot.yml +24 -24
  4. package/.github/workflows/bump.yml +8 -8
  5. package/.github/workflows/dependabot.yml +11 -11
  6. package/.github/workflows/publish.yml +16 -16
  7. package/README.md +385 -385
  8. package/build/compiler/codegen.js +9 -9
  9. package/build/compiler/index.js +3 -3
  10. package/{src/llm.txt → llm.txt} +403 -403
  11. package/package.json +10 -3
  12. package/src/attributes.ts +312 -312
  13. package/src/compiler/codegen.ts +492 -492
  14. package/src/compiler/constants.ts +24 -24
  15. package/src/compiler/index.ts +87 -87
  16. package/src/compiler/parser.ts +242 -242
  17. package/src/compiler/plugins/tsc.ts +6 -6
  18. package/src/compiler/plugins/vite.ts +10 -10
  19. package/src/compiler/ts-analyzer.ts +89 -89
  20. package/src/compiler/ts-parser.ts +112 -112
  21. package/src/constants.ts +44 -44
  22. package/src/event/index.ts +130 -130
  23. package/src/event/onconnect.ts +22 -22
  24. package/src/event/onresize.ts +37 -37
  25. package/src/event/ontick.ts +59 -59
  26. package/src/html.ts +18 -18
  27. package/src/index.ts +18 -18
  28. package/src/render.ts +13 -13
  29. package/src/slot/array.ts +257 -257
  30. package/src/slot/cleanup.ts +37 -37
  31. package/src/slot/effect.ts +114 -114
  32. package/src/slot/index.ts +16 -16
  33. package/src/slot/render.ts +61 -61
  34. package/src/svg.ts +27 -27
  35. package/src/types.ts +40 -40
  36. package/src/utilities.ts +53 -53
  37. package/test/attributes.test.ts +311 -0
  38. package/test/compiler/parser.test.ts +402 -0
  39. package/test/compiler/ts-analyzer.test.ts +296 -0
  40. package/test/constants.test.ts +153 -0
  41. package/test/event/index.test.ts +359 -0
  42. package/test/html.test.ts +33 -0
  43. package/test/index.ts +648 -648
  44. package/test/render.test.ts +154 -0
  45. package/test/slot/array.test.ts +475 -0
  46. package/test/slot/cleanup.test.ts +243 -0
  47. package/test/slot/effect.test.ts +263 -0
  48. package/test/slot/index.test.ts +176 -0
  49. package/test/slot/render.test.ts +216 -0
  50. package/test/svg.test.ts +92 -0
  51. package/test/utilities.test.ts +242 -0
  52. package/tsconfig.json +8 -8
  53. package/vitest.config.ts +21 -0
@@ -1,25 +1,25 @@
1
- import { uid } from '@esportsplus/typescript/compiler';
2
-
3
-
4
- const ENTRYPOINT = 'html';
5
-
6
- const ENTRYPOINT_REACTIVITY = 'reactive';
7
-
8
- const NAMESPACE = uid('template');
9
-
10
-
11
- const enum TYPES {
12
- ArraySlot = 'array-slot',
13
- Attributes = 'attributes',
14
- Attribute = 'attribute',
15
- DocumentFragment = 'document-fragment',
16
- Effect = 'effect',
17
- Node = 'node',
18
- Primitive = 'primitive',
19
- Static = 'static',
20
- Unknown = 'unknown'
21
- };
22
-
23
-
24
- export { ENTRYPOINT, ENTRYPOINT_REACTIVITY, NAMESPACE, TYPES };
1
+ import { uid } from '@esportsplus/typescript/compiler';
2
+
3
+
4
+ const ENTRYPOINT = 'html';
5
+
6
+ const ENTRYPOINT_REACTIVITY = 'reactive';
7
+
8
+ const NAMESPACE = uid('template');
9
+
10
+
11
+ const enum TYPES {
12
+ ArraySlot = 'array-slot',
13
+ Attributes = 'attributes',
14
+ Attribute = 'attribute',
15
+ DocumentFragment = 'document-fragment',
16
+ Effect = 'effect',
17
+ Node = 'node',
18
+ Primitive = 'primitive',
19
+ Static = 'static',
20
+ Unknown = 'unknown'
21
+ };
22
+
23
+
24
+ export { ENTRYPOINT, ENTRYPOINT_REACTIVITY, NAMESPACE, TYPES };
25
25
  export { PACKAGE_NAME } from '~/constants';
@@ -1,87 +1,87 @@
1
- import { ts } from '@esportsplus/typescript';
2
- import { ast } from '@esportsplus/typescript/compiler';
3
- import type { ImportIntent, ReplacementIntent, TransformContext } from '@esportsplus/typescript/compiler';
4
- import { ENTRYPOINT, ENTRYPOINT_REACTIVITY, NAMESPACE, PACKAGE_NAME } from './constants';
5
- import { generateCode, printer, rewriteExpression } from './codegen';
6
- import { findHtmlTemplates, findReactiveCalls } from './ts-parser';
7
-
8
-
9
- export default {
10
- patterns: [
11
- `${ENTRYPOINT}\``,
12
- `${ENTRYPOINT}.${ENTRYPOINT_REACTIVITY}`
13
- ],
14
- transform: (ctx: TransformContext) => {
15
- let callRanges: { end: number; start: number }[] = [],
16
- callTemplates = new Map<string, string>(),
17
- imports: ImportIntent[] = [],
18
- prepend: string[] = [],
19
- ranges: { end: number; start: number }[] = [],
20
- remove: string[] = [],
21
- replacements: ReplacementIntent[] = [],
22
- templates = findHtmlTemplates(ctx.sourceFile, ctx.checker);
23
-
24
- for (let i = 0, n = templates.length; i < n; i++) {
25
- ranges.push({
26
- end: templates[i].end,
27
- start: templates[i].start
28
- });
29
- }
30
-
31
- let calls = findReactiveCalls(ctx.sourceFile, ctx.checker);
32
-
33
- for (let i = 0, n = calls.length; i < n; i++) {
34
- let call = calls[i];
35
-
36
- if (ast.inRange(ranges, call.start, call.end)) {
37
- continue;
38
- }
39
-
40
- // Add callback range so nested templates inside it are excluded from separate processing
41
- callRanges.push({
42
- end: call.callbackArg.end,
43
- start: call.callbackArg.getStart(ctx.sourceFile)
44
- });
45
-
46
- // Pre-compute the rewritten callback to capture templates
47
- let rewrittenCallback = rewriteExpression({
48
- checker: ctx.checker,
49
- sourceFile: ctx.sourceFile,
50
- templates: callTemplates
51
- }, call.callbackArg);
52
-
53
- replacements.push({
54
- generate: (sourceFile) => `new ${NAMESPACE}.ArraySlot(
55
- ${printer.printNode(ts.EmitHint.Expression, call.arrayArg, sourceFile)},
56
- ${rewrittenCallback}
57
- )`,
58
- node: call.node
59
- });
60
- }
61
-
62
- // Add template definitions from reactive call callbacks
63
- for (let [html, id] of callTemplates) {
64
- prepend.push(`const ${id} = ${NAMESPACE}.template(\`${html}\`);`);
65
- }
66
-
67
- if (templates.length > 0) {
68
- let result = generateCode(templates, ctx.sourceFile, ctx.checker, callRanges);
69
-
70
- prepend.push(...result.prepend);
71
- replacements.push(...result.replacements);
72
- remove.push(ENTRYPOINT);
73
- }
74
-
75
- if (replacements.length === 0 && prepend.length === 0) {
76
- return {};
77
- }
78
-
79
- imports.push({
80
- namespace: NAMESPACE,
81
- package: PACKAGE_NAME,
82
- remove: remove
83
- });
84
-
85
- return { imports, prepend, replacements };
86
- }
87
- };
1
+ import { ts } from '@esportsplus/typescript';
2
+ import { ast } from '@esportsplus/typescript/compiler';
3
+ import type { ImportIntent, ReplacementIntent, TransformContext } from '@esportsplus/typescript/compiler';
4
+ import { ENTRYPOINT, ENTRYPOINT_REACTIVITY, NAMESPACE, PACKAGE_NAME } from './constants';
5
+ import { generateCode, printer, rewriteExpression } from './codegen';
6
+ import { findHtmlTemplates, findReactiveCalls } from './ts-parser';
7
+
8
+
9
+ export default {
10
+ patterns: [
11
+ `${ENTRYPOINT}\``,
12
+ `${ENTRYPOINT}.${ENTRYPOINT_REACTIVITY}`
13
+ ],
14
+ transform: (ctx: TransformContext) => {
15
+ let callRanges: { end: number; start: number }[] = [],
16
+ callTemplates = new Map<string, string>(),
17
+ imports: ImportIntent[] = [],
18
+ prepend: string[] = [],
19
+ ranges: { end: number; start: number }[] = [],
20
+ remove: string[] = [],
21
+ replacements: ReplacementIntent[] = [],
22
+ templates = findHtmlTemplates(ctx.sourceFile, ctx.checker);
23
+
24
+ for (let i = 0, n = templates.length; i < n; i++) {
25
+ ranges.push({
26
+ end: templates[i].end,
27
+ start: templates[i].start
28
+ });
29
+ }
30
+
31
+ let calls = findReactiveCalls(ctx.sourceFile, ctx.checker);
32
+
33
+ for (let i = 0, n = calls.length; i < n; i++) {
34
+ let call = calls[i];
35
+
36
+ if (ast.inRange(ranges, call.start, call.end)) {
37
+ continue;
38
+ }
39
+
40
+ // Add callback range so nested templates inside it are excluded from separate processing
41
+ callRanges.push({
42
+ end: call.callbackArg.end,
43
+ start: call.callbackArg.getStart(ctx.sourceFile)
44
+ });
45
+
46
+ // Pre-compute the rewritten callback to capture templates
47
+ let rewrittenCallback = rewriteExpression({
48
+ checker: ctx.checker,
49
+ sourceFile: ctx.sourceFile,
50
+ templates: callTemplates
51
+ }, call.callbackArg);
52
+
53
+ replacements.push({
54
+ generate: (sourceFile) => `new ${NAMESPACE}.ArraySlot(
55
+ ${printer.printNode(ts.EmitHint.Expression, call.arrayArg, sourceFile)},
56
+ ${rewrittenCallback}
57
+ )`,
58
+ node: call.node
59
+ });
60
+ }
61
+
62
+ // Add template definitions from reactive call callbacks
63
+ for (let [html, id] of callTemplates) {
64
+ prepend.push(`const ${id} = ${NAMESPACE}.template(\`${html}\`);`);
65
+ }
66
+
67
+ if (templates.length > 0) {
68
+ let result = generateCode(templates, ctx.sourceFile, ctx.checker, callRanges);
69
+
70
+ prepend.push(...result.prepend);
71
+ replacements.push(...result.replacements);
72
+ remove.push(ENTRYPOINT);
73
+ }
74
+
75
+ if (replacements.length === 0 && prepend.length === 0) {
76
+ return {};
77
+ }
78
+
79
+ imports.push({
80
+ namespace: NAMESPACE,
81
+ package: PACKAGE_NAME,
82
+ remove: remove
83
+ });
84
+
85
+ return { imports, prepend, replacements };
86
+ }
87
+ };