@esportsplus/template 0.28.3 → 0.29.1
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.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 +11 -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
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
// Test Templates for Compilation Benchmark
|
|
2
|
+
// Wide variety of template patterns for performance testing
|
|
3
|
+
|
|
4
|
+
import { html } from '../src';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
// =============================================================================
|
|
8
|
+
// STATIC TEMPLATES (no slots)
|
|
9
|
+
// =============================================================================
|
|
10
|
+
|
|
11
|
+
// 1. Simple static element
|
|
12
|
+
export const staticSimple = () => html`<div>Hello World</div>`;
|
|
13
|
+
|
|
14
|
+
// 2. Static with classes
|
|
15
|
+
export const staticClasses = () => html`<div class="container mx-auto p-4">Static content</div>`;
|
|
16
|
+
|
|
17
|
+
// 3. Static nested
|
|
18
|
+
export const staticNested = () => html`
|
|
19
|
+
<div class="wrapper">
|
|
20
|
+
<header class="header">Title</header>
|
|
21
|
+
<main class="content">Body</main>
|
|
22
|
+
<footer class="footer">Footer</footer>
|
|
23
|
+
</div>
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
// 4. Static list
|
|
27
|
+
export const staticList = () => html`
|
|
28
|
+
<ul class="list">
|
|
29
|
+
<li>Item 1</li>
|
|
30
|
+
<li>Item 2</li>
|
|
31
|
+
<li>Item 3</li>
|
|
32
|
+
</ul>
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
// 5. Static table
|
|
36
|
+
export const staticTable = () => html`
|
|
37
|
+
<table class="table">
|
|
38
|
+
<thead><tr><th>ID</th><th>Name</th></tr></thead>
|
|
39
|
+
<tbody>
|
|
40
|
+
<tr><td>1</td><td>Alice</td></tr>
|
|
41
|
+
<tr><td>2</td><td>Bob</td></tr>
|
|
42
|
+
</tbody>
|
|
43
|
+
</table>
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// =============================================================================
|
|
48
|
+
// SINGLE SLOT TEMPLATES
|
|
49
|
+
// =============================================================================
|
|
50
|
+
|
|
51
|
+
// 6. Single text slot
|
|
52
|
+
export const singleText = (text: string) => html`<div>${text}</div>`;
|
|
53
|
+
|
|
54
|
+
// 7. Single attribute
|
|
55
|
+
export const singleAttr = (cls: string) => html`<div class="${cls}"></div>`;
|
|
56
|
+
|
|
57
|
+
// 8. Single id attribute
|
|
58
|
+
export const singleId = (id: string) => html`<div id="${id}"></div>`;
|
|
59
|
+
|
|
60
|
+
// 9. Single style
|
|
61
|
+
export const singleStyle = (style: string) => html`<div style="${style}"></div>`;
|
|
62
|
+
|
|
63
|
+
// 10. Single data attribute
|
|
64
|
+
export const singleData = (value: string) => html`<div data-value="${value}"></div>`;
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
// =============================================================================
|
|
68
|
+
// MULTIPLE SLOT TEMPLATES
|
|
69
|
+
// =============================================================================
|
|
70
|
+
|
|
71
|
+
// 11. Multiple attributes same element
|
|
72
|
+
export const multiAttrSame = (id: string, cls: string, style: string) =>
|
|
73
|
+
html`<div id="${id}" class="${cls}" style="${style}"></div>`;
|
|
74
|
+
|
|
75
|
+
// 12. Multiple text slots
|
|
76
|
+
export const multiText = (a: string, b: string, c: string) =>
|
|
77
|
+
html`<div><span>${a}</span><span>${b}</span><span>${c}</span></div>`;
|
|
78
|
+
|
|
79
|
+
// 13. Mixed attributes and text
|
|
80
|
+
export const mixedSlots = (cls: string, text: string) =>
|
|
81
|
+
html`<div class="${cls}">${text}</div>`;
|
|
82
|
+
|
|
83
|
+
// 14. Multiple elements with slots
|
|
84
|
+
export const multiElement = (title: string, body: string) =>
|
|
85
|
+
html`<article><h1>${title}</h1><p>${body}</p></article>`;
|
|
86
|
+
|
|
87
|
+
// 15. Form inputs
|
|
88
|
+
export const formInputs = (name: string, email: string, placeholder: string) =>
|
|
89
|
+
html`<form>
|
|
90
|
+
<input type="text" value="${name}" placeholder="${placeholder}">
|
|
91
|
+
<input type="email" value="${email}">
|
|
92
|
+
</form>`;
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
// =============================================================================
|
|
96
|
+
// NESTED TEMPLATES
|
|
97
|
+
// =============================================================================
|
|
98
|
+
|
|
99
|
+
// 16. Simple nested template
|
|
100
|
+
export const nestedSimple = (items: string[]) =>
|
|
101
|
+
html`<ul>${items.map(item => html`<li>${item}</li>`)}</ul>`;
|
|
102
|
+
|
|
103
|
+
// 17. Nested with attributes
|
|
104
|
+
export const nestedWithAttrs = (items: { cls: string; text: string }[]) =>
|
|
105
|
+
html`<ul>${items.map(item => html`<li class="${item.cls}">${item.text}</li>`)}</ul>`;
|
|
106
|
+
|
|
107
|
+
// 18. Deeply nested templates
|
|
108
|
+
export const nestedDeep = (sections: { title: string; items: string[] }[]) =>
|
|
109
|
+
html`<div class="container">
|
|
110
|
+
${sections.map(section => html`
|
|
111
|
+
<section>
|
|
112
|
+
<h2>${section.title}</h2>
|
|
113
|
+
<ul>${section.items.map(item => html`<li>${item}</li>`)}</ul>
|
|
114
|
+
</section>
|
|
115
|
+
`)}
|
|
116
|
+
</div>`;
|
|
117
|
+
|
|
118
|
+
// 19. Table with nested rows
|
|
119
|
+
export const nestedTable = (rows: { id: number; name: string; email: string }[]) =>
|
|
120
|
+
html`<table>
|
|
121
|
+
<thead><tr><th>ID</th><th>Name</th><th>Email</th></tr></thead>
|
|
122
|
+
<tbody>
|
|
123
|
+
${rows.map(row => html`<tr>
|
|
124
|
+
<td>${row.id}</td>
|
|
125
|
+
<td>${row.name}</td>
|
|
126
|
+
<td>${row.email}</td>
|
|
127
|
+
</tr>`)}
|
|
128
|
+
</tbody>
|
|
129
|
+
</table>`;
|
|
130
|
+
|
|
131
|
+
// 20. Card grid
|
|
132
|
+
export const nestedCards = (cards: { title: string; body: string; footer: string }[]) =>
|
|
133
|
+
html`<div class="grid">
|
|
134
|
+
${cards.map(card => html`
|
|
135
|
+
<div class="card">
|
|
136
|
+
<div class="card-header">${card.title}</div>
|
|
137
|
+
<div class="card-body">${card.body}</div>
|
|
138
|
+
<div class="card-footer">${card.footer}</div>
|
|
139
|
+
</div>
|
|
140
|
+
`)}
|
|
141
|
+
</div>`;
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
// =============================================================================
|
|
145
|
+
// SPREAD ATTRIBUTE TEMPLATES
|
|
146
|
+
// =============================================================================
|
|
147
|
+
|
|
148
|
+
// 21. Simple spread
|
|
149
|
+
export const spreadSimple = (attrs: Record<string, unknown>) =>
|
|
150
|
+
html`<div ${attrs}></div>`;
|
|
151
|
+
|
|
152
|
+
// 22. Spread with static
|
|
153
|
+
export const spreadWithStatic = (attrs: Record<string, unknown>) =>
|
|
154
|
+
html`<div class="base" ${attrs}></div>`;
|
|
155
|
+
|
|
156
|
+
// 23. Spread in nested
|
|
157
|
+
export const spreadNested = (items: Record<string, unknown>[]) =>
|
|
158
|
+
html`<ul>${items.map(attrs => html`<li ${attrs}>Item</li>`)}</ul>`;
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
// =============================================================================
|
|
162
|
+
// EVENT HANDLER TEMPLATES
|
|
163
|
+
// =============================================================================
|
|
164
|
+
|
|
165
|
+
// 24. Single event
|
|
166
|
+
export const eventSingle = (handler: () => void) =>
|
|
167
|
+
html`<button onclick="${handler}">Click</button>`;
|
|
168
|
+
|
|
169
|
+
// 25. Multiple events
|
|
170
|
+
export const eventMultiple = (click: () => void, hover: () => void) =>
|
|
171
|
+
html`<button onclick="${click}" onmouseover="${hover}">Interact</button>`;
|
|
172
|
+
|
|
173
|
+
// 26. Event with attributes
|
|
174
|
+
export const eventWithAttrs = (cls: string, handler: () => void) =>
|
|
175
|
+
html`<button class="${cls}" onclick="${handler}">Action</button>`;
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
// =============================================================================
|
|
179
|
+
// DEEPLY NESTED DOM TEMPLATES
|
|
180
|
+
// =============================================================================
|
|
181
|
+
|
|
182
|
+
// 27. 4-level nesting with slot at leaf
|
|
183
|
+
export const deepNest4 = (text: string) =>
|
|
184
|
+
html`<div><div><div><div>${text}</div></div></div></div>`;
|
|
185
|
+
|
|
186
|
+
// 28. 6-level nesting
|
|
187
|
+
export const deepNest6 = (text: string) =>
|
|
188
|
+
html`<div><div><div><div><div><div>${text}</div></div></div></div></div></div>`;
|
|
189
|
+
|
|
190
|
+
// 29. Wide and deep
|
|
191
|
+
export const wideAndDeep = (a: string, b: string, c: string, d: string) =>
|
|
192
|
+
html`<div class="level-1">
|
|
193
|
+
<div class="level-2">
|
|
194
|
+
<div class="level-3">
|
|
195
|
+
<span>${a}</span>
|
|
196
|
+
<span>${b}</span>
|
|
197
|
+
</div>
|
|
198
|
+
</div>
|
|
199
|
+
<div class="level-2">
|
|
200
|
+
<div class="level-3">
|
|
201
|
+
<span>${c}</span>
|
|
202
|
+
<span>${d}</span>
|
|
203
|
+
</div>
|
|
204
|
+
</div>
|
|
205
|
+
</div>`;
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
// =============================================================================
|
|
209
|
+
// SIBLING SLOT TEMPLATES (path optimization test)
|
|
210
|
+
// =============================================================================
|
|
211
|
+
|
|
212
|
+
// 30. Adjacent siblings
|
|
213
|
+
export const siblingAdjacent = (a: string, b: string, c: string) =>
|
|
214
|
+
html`<div>${a}${b}${c}</div>`;
|
|
215
|
+
|
|
216
|
+
// 31. Sibling elements
|
|
217
|
+
export const siblingElements = (a: string, b: string, c: string, d: string, e: string) =>
|
|
218
|
+
html`<div>
|
|
219
|
+
<span>${a}</span>
|
|
220
|
+
<span>${b}</span>
|
|
221
|
+
<span>${c}</span>
|
|
222
|
+
<span>${d}</span>
|
|
223
|
+
<span>${e}</span>
|
|
224
|
+
</div>`;
|
|
225
|
+
|
|
226
|
+
// 32. Many siblings (10)
|
|
227
|
+
export const sibling10 = (values: string[]) =>
|
|
228
|
+
html`<div>
|
|
229
|
+
<span>${values[0]}</span>
|
|
230
|
+
<span>${values[1]}</span>
|
|
231
|
+
<span>${values[2]}</span>
|
|
232
|
+
<span>${values[3]}</span>
|
|
233
|
+
<span>${values[4]}</span>
|
|
234
|
+
<span>${values[5]}</span>
|
|
235
|
+
<span>${values[6]}</span>
|
|
236
|
+
<span>${values[7]}</span>
|
|
237
|
+
<span>${values[8]}</span>
|
|
238
|
+
<span>${values[9]}</span>
|
|
239
|
+
</div>`;
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
// =============================================================================
|
|
243
|
+
// COMPLEX REAL-WORLD TEMPLATES
|
|
244
|
+
// =============================================================================
|
|
245
|
+
|
|
246
|
+
// 33. Navigation menu
|
|
247
|
+
export const navMenu = (items: { href: string; text: string; active: boolean }[]) =>
|
|
248
|
+
html`<nav class="nav">
|
|
249
|
+
<ul class="nav-list">
|
|
250
|
+
${items.map(item => html`
|
|
251
|
+
<li class="${item.active ? 'active' : ''}">
|
|
252
|
+
<a href="${item.href}">${item.text}</a>
|
|
253
|
+
</li>
|
|
254
|
+
`)}
|
|
255
|
+
</ul>
|
|
256
|
+
</nav>`;
|
|
257
|
+
|
|
258
|
+
// 34. Blog post card
|
|
259
|
+
export const blogCard = (post: {
|
|
260
|
+
title: string;
|
|
261
|
+
author: string;
|
|
262
|
+
date: string;
|
|
263
|
+
excerpt: string;
|
|
264
|
+
imageUrl: string;
|
|
265
|
+
tags: string[];
|
|
266
|
+
}) => html`
|
|
267
|
+
<article class="blog-card">
|
|
268
|
+
<img src="${post.imageUrl}" alt="${post.title}">
|
|
269
|
+
<div class="blog-card-content">
|
|
270
|
+
<h2>${post.title}</h2>
|
|
271
|
+
<p class="meta">By ${post.author} on ${post.date}</p>
|
|
272
|
+
<p>${post.excerpt}</p>
|
|
273
|
+
<div class="tags">
|
|
274
|
+
${post.tags.map(tag => html`<span class="tag">${tag}</span>`)}
|
|
275
|
+
</div>
|
|
276
|
+
</div>
|
|
277
|
+
</article>
|
|
278
|
+
`;
|
|
279
|
+
|
|
280
|
+
// 35. Product listing
|
|
281
|
+
export const productListing = (products: {
|
|
282
|
+
id: number;
|
|
283
|
+
name: string;
|
|
284
|
+
price: number;
|
|
285
|
+
inStock: boolean;
|
|
286
|
+
rating: number;
|
|
287
|
+
}[]) => html`
|
|
288
|
+
<div class="product-grid">
|
|
289
|
+
${products.map(product => html`
|
|
290
|
+
<div class="product-card" data-id="${product.id}">
|
|
291
|
+
<h3>${product.name}</h3>
|
|
292
|
+
<p class="price">$${product.price}</p>
|
|
293
|
+
<span class="${product.inStock ? 'in-stock' : 'out-of-stock'}">
|
|
294
|
+
${product.inStock ? 'In Stock' : 'Out of Stock'}
|
|
295
|
+
</span>
|
|
296
|
+
<div class="rating">${'★'.repeat(product.rating)}${'☆'.repeat(5 - product.rating)}</div>
|
|
297
|
+
</div>
|
|
298
|
+
`)}
|
|
299
|
+
</div>
|
|
300
|
+
`;
|
|
301
|
+
|
|
302
|
+
// 36. Comment thread
|
|
303
|
+
export const commentThread = (comments: {
|
|
304
|
+
author: string;
|
|
305
|
+
avatar: string;
|
|
306
|
+
text: string;
|
|
307
|
+
date: string;
|
|
308
|
+
replies: { author: string; text: string; date: string }[];
|
|
309
|
+
}[]) => html`
|
|
310
|
+
<div class="comments">
|
|
311
|
+
${comments.map(comment => html`
|
|
312
|
+
<div class="comment">
|
|
313
|
+
<img src="${comment.avatar}" class="avatar">
|
|
314
|
+
<div class="comment-content">
|
|
315
|
+
<p class="author">${comment.author}</p>
|
|
316
|
+
<p class="date">${comment.date}</p>
|
|
317
|
+
<p class="text">${comment.text}</p>
|
|
318
|
+
${comment.replies.length > 0 ? html`
|
|
319
|
+
<div class="replies">
|
|
320
|
+
${comment.replies.map(reply => html`
|
|
321
|
+
<div class="reply">
|
|
322
|
+
<p class="author">${reply.author}</p>
|
|
323
|
+
<p class="text">${reply.text}</p>
|
|
324
|
+
</div>
|
|
325
|
+
`)}
|
|
326
|
+
</div>
|
|
327
|
+
` : ''}
|
|
328
|
+
</div>
|
|
329
|
+
</div>
|
|
330
|
+
`)}
|
|
331
|
+
</div>
|
|
332
|
+
`;
|
|
333
|
+
|
|
334
|
+
// 37. Dashboard widget
|
|
335
|
+
export const dashboardWidget = (widget: {
|
|
336
|
+
title: string;
|
|
337
|
+
value: number;
|
|
338
|
+
change: number;
|
|
339
|
+
chartData: number[];
|
|
340
|
+
}) => html`
|
|
341
|
+
<div class="widget">
|
|
342
|
+
<h3>${widget.title}</h3>
|
|
343
|
+
<p class="value">${widget.value}</p>
|
|
344
|
+
<p class="${widget.change >= 0 ? 'positive' : 'negative'}">
|
|
345
|
+
${widget.change >= 0 ? '+' : ''}${widget.change}%
|
|
346
|
+
</p>
|
|
347
|
+
<div class="chart">
|
|
348
|
+
${widget.chartData.map(point => html`
|
|
349
|
+
<div class="bar" style="height: ${point}%"></div>
|
|
350
|
+
`)}
|
|
351
|
+
</div>
|
|
352
|
+
</div>
|
|
353
|
+
`;
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
// =============================================================================
|
|
357
|
+
// CONDITIONAL RENDERING
|
|
358
|
+
// =============================================================================
|
|
359
|
+
|
|
360
|
+
// 38. Conditional class
|
|
361
|
+
export const conditionalClass = (isActive: boolean) =>
|
|
362
|
+
html`<div class="${isActive ? 'active' : 'inactive'}">Status</div>`;
|
|
363
|
+
|
|
364
|
+
// 39. Conditional content
|
|
365
|
+
export const conditionalContent = (show: boolean, content: string) =>
|
|
366
|
+
html`<div>${show ? content : ''}</div>`;
|
|
367
|
+
|
|
368
|
+
// 40. Conditional nested template
|
|
369
|
+
export const conditionalNested = (items: string[] | null) =>
|
|
370
|
+
html`<div>
|
|
371
|
+
${items ? html`<ul>${items.map(i => html`<li>${i}</li>`)}</ul>` : html`<p>No items</p>`}
|
|
372
|
+
</div>`;
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
// =============================================================================
|
|
376
|
+
// STRESS TEST TEMPLATES
|
|
377
|
+
// =============================================================================
|
|
378
|
+
|
|
379
|
+
// 41. 20 slots
|
|
380
|
+
export const stressSlots20 = (values: string[]) =>
|
|
381
|
+
html`<div>
|
|
382
|
+
<p>${values[0]}</p><p>${values[1]}</p><p>${values[2]}</p><p>${values[3]}</p>
|
|
383
|
+
<p>${values[4]}</p><p>${values[5]}</p><p>${values[6]}</p><p>${values[7]}</p>
|
|
384
|
+
<p>${values[8]}</p><p>${values[9]}</p><p>${values[10]}</p><p>${values[11]}</p>
|
|
385
|
+
<p>${values[12]}</p><p>${values[13]}</p><p>${values[14]}</p><p>${values[15]}</p>
|
|
386
|
+
<p>${values[16]}</p><p>${values[17]}</p><p>${values[18]}</p><p>${values[19]}</p>
|
|
387
|
+
</div>`;
|
|
388
|
+
|
|
389
|
+
// 42. 50 item list
|
|
390
|
+
export const stressList50 = (items: string[]) =>
|
|
391
|
+
html`<ul>${items.slice(0, 50).map(item => html`<li>${item}</li>`)}</ul>`;
|
|
392
|
+
|
|
393
|
+
// 43. 100 item list
|
|
394
|
+
export const stressList100 = (items: string[]) =>
|
|
395
|
+
html`<ul>${items.slice(0, 100).map(item => html`<li>${item}</li>`)}</ul>`;
|
|
396
|
+
|
|
397
|
+
// 44. Complex nested structure
|
|
398
|
+
export const stressComplex = (data: {
|
|
399
|
+
header: { title: string; subtitle: string };
|
|
400
|
+
sections: {
|
|
401
|
+
title: string;
|
|
402
|
+
items: { name: string; value: string }[];
|
|
403
|
+
}[];
|
|
404
|
+
footer: string;
|
|
405
|
+
}) => html`
|
|
406
|
+
<div class="complex">
|
|
407
|
+
<header>
|
|
408
|
+
<h1>${data.header.title}</h1>
|
|
409
|
+
<p>${data.header.subtitle}</p>
|
|
410
|
+
</header>
|
|
411
|
+
<main>
|
|
412
|
+
${data.sections.map(section => html`
|
|
413
|
+
<section>
|
|
414
|
+
<h2>${section.title}</h2>
|
|
415
|
+
<dl>
|
|
416
|
+
${section.items.map(item => html`
|
|
417
|
+
<dt>${item.name}</dt>
|
|
418
|
+
<dd>${item.value}</dd>
|
|
419
|
+
`)}
|
|
420
|
+
</dl>
|
|
421
|
+
</section>
|
|
422
|
+
`)}
|
|
423
|
+
</main>
|
|
424
|
+
<footer>${data.footer}</footer>
|
|
425
|
+
</div>
|
|
426
|
+
`;
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
// =============================================================================
|
|
430
|
+
// SVG TEMPLATES
|
|
431
|
+
// =============================================================================
|
|
432
|
+
|
|
433
|
+
// 45. Simple SVG
|
|
434
|
+
export const svgSimple = (fill: string) =>
|
|
435
|
+
html`<svg width="100" height="100"><circle cx="50" cy="50" r="40" fill="${fill}"/></svg>`;
|
|
436
|
+
|
|
437
|
+
// 46. SVG with multiple elements
|
|
438
|
+
export const svgMultiple = (colors: { circle: string; rect: string }) =>
|
|
439
|
+
html`<svg width="200" height="100">
|
|
440
|
+
<circle cx="50" cy="50" r="40" fill="${colors.circle}"/>
|
|
441
|
+
<rect x="100" y="10" width="80" height="80" fill="${colors.rect}"/>
|
|
442
|
+
</svg>`;
|
|
443
|
+
|
|
444
|
+
// 47. SVG path
|
|
445
|
+
export const svgPath = (d: string, stroke: string) =>
|
|
446
|
+
html`<svg viewBox="0 0 100 100"><path d="${d}" stroke="${stroke}" fill="none"/></svg>`;
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
// =============================================================================
|
|
450
|
+
// VOID ELEMENT TEMPLATES
|
|
451
|
+
// =============================================================================
|
|
452
|
+
|
|
453
|
+
// 48. Input with all attributes
|
|
454
|
+
export const inputComplete = (attrs: {
|
|
455
|
+
type: string;
|
|
456
|
+
name: string;
|
|
457
|
+
value: string;
|
|
458
|
+
placeholder: string;
|
|
459
|
+
cls: string;
|
|
460
|
+
}) => html`<input
|
|
461
|
+
type="${attrs.type}"
|
|
462
|
+
name="${attrs.name}"
|
|
463
|
+
value="${attrs.value}"
|
|
464
|
+
placeholder="${attrs.placeholder}"
|
|
465
|
+
class="${attrs.cls}">`;
|
|
466
|
+
|
|
467
|
+
// 49. Image
|
|
468
|
+
export const imageSrc = (src: string, alt: string) =>
|
|
469
|
+
html`<img src="${src}" alt="${alt}" loading="lazy">`;
|
|
470
|
+
|
|
471
|
+
// 50. Meta tags
|
|
472
|
+
export const metaTags = (tags: { name: string; content: string }[]) =>
|
|
473
|
+
html`<head>${tags.map(t => html`<meta name="${t.name}" content="${t.content}">`)}</head>`;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
4
|
+
import templatePlugin from '../src/transformer/plugins/vite';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
build: {
|
|
9
|
+
lib: {
|
|
10
|
+
entry: {
|
|
11
|
+
'constants': resolve(__dirname, 'constants.ts'),
|
|
12
|
+
'effects': resolve(__dirname, 'effects.ts'),
|
|
13
|
+
'events': resolve(__dirname, 'events.ts'),
|
|
14
|
+
'imported-values': resolve(__dirname, 'imported-values.ts'),
|
|
15
|
+
'nested': resolve(__dirname, 'nested.ts'),
|
|
16
|
+
'slots': resolve(__dirname, 'slots.ts'),
|
|
17
|
+
'spread': resolve(__dirname, 'spread.ts'),
|
|
18
|
+
'static': resolve(__dirname, 'static.ts'),
|
|
19
|
+
'templates': resolve(__dirname, 'templates.ts')
|
|
20
|
+
},
|
|
21
|
+
formats: ['es'],
|
|
22
|
+
fileName: (_, entryName) => `${entryName}.js`
|
|
23
|
+
},
|
|
24
|
+
outDir: resolve(__dirname, 'build'),
|
|
25
|
+
emptyOutDir: true,
|
|
26
|
+
minify: false,
|
|
27
|
+
rollupOptions: {
|
|
28
|
+
external: [
|
|
29
|
+
/^~\//,
|
|
30
|
+
/^\.\.\/src/,
|
|
31
|
+
'@esportsplus/reactivity',
|
|
32
|
+
'@esportsplus/template',
|
|
33
|
+
'@esportsplus/utilities'
|
|
34
|
+
],
|
|
35
|
+
output: {
|
|
36
|
+
preserveModules: false,
|
|
37
|
+
entryFileNames: '[name].js'
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
plugins: [
|
|
42
|
+
tsconfigPaths(),
|
|
43
|
+
templatePlugin()
|
|
44
|
+
],
|
|
45
|
+
resolve: {
|
|
46
|
+
alias: {
|
|
47
|
+
'~': resolve(__dirname, '../src')
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
package/build/html/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ReactiveArray } from '@esportsplus/reactivity';
|
|
2
|
-
import { Attribute, Attributes, Renderable } from '../types.js';
|
|
3
|
-
import { ArraySlot } from '../slot/array.js';
|
|
4
|
-
type Values<T> = Attribute | Attributes<any> | ArraySlot<T> | Renderable<T>;
|
|
5
|
-
declare const html: {
|
|
6
|
-
<T>(literals: TemplateStringsArray, ...values: (Values<T> | Values<T>[])[]): Node;
|
|
7
|
-
reactive<T>(arr: ReactiveArray<T>, template: (value: T) => ReturnType<typeof html>): ArraySlot<T>;
|
|
8
|
-
};
|
|
9
|
-
export default html;
|
package/build/html/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { cloneNode } from '../utilities/node.js';
|
|
2
|
-
import { ArraySlot } from '../slot/array.js';
|
|
3
|
-
import parser from './parser.js';
|
|
4
|
-
const html = (literals, ...values) => {
|
|
5
|
-
let { fragment, slots } = parser.parse(literals), clone = cloneNode.call(fragment, true);
|
|
6
|
-
if (slots !== null) {
|
|
7
|
-
let e, p;
|
|
8
|
-
for (let i = slots.length - 1; i >= 0; i--) {
|
|
9
|
-
let { fn, name, path } = slots[i];
|
|
10
|
-
if (p !== path) {
|
|
11
|
-
e = clone;
|
|
12
|
-
for (let i = 0, n = path.length; i < n; i++) {
|
|
13
|
-
e = path[i].call(e);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
if (name === null) {
|
|
17
|
-
fn(e, values[i]);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
fn(e, name, values[i]);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return clone;
|
|
25
|
-
};
|
|
26
|
-
html.reactive = (arr, template) => {
|
|
27
|
-
return new ArraySlot(arr, template);
|
|
28
|
-
};
|
|
29
|
-
export default html;
|