elit 1.0.0 → 2.0.0

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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +552 -19
  3. package/dist/build.d.mts +11 -0
  4. package/dist/build.d.ts +11 -0
  5. package/dist/build.js +1 -0
  6. package/dist/build.mjs +1 -0
  7. package/dist/cli.js +2307 -0
  8. package/dist/client.d.mts +9 -0
  9. package/dist/client.d.ts +9 -0
  10. package/dist/client.js +1 -0
  11. package/dist/client.mjs +1 -0
  12. package/dist/dom.d.mts +80 -0
  13. package/dist/dom.d.ts +80 -0
  14. package/dist/dom.js +1 -0
  15. package/dist/dom.mjs +1 -0
  16. package/dist/el.d.mts +227 -0
  17. package/dist/el.d.ts +227 -0
  18. package/dist/el.js +1 -0
  19. package/dist/el.mjs +1 -0
  20. package/dist/hmr.d.mts +38 -0
  21. package/dist/hmr.d.ts +38 -0
  22. package/dist/hmr.js +1 -0
  23. package/dist/hmr.mjs +1 -0
  24. package/dist/index.d.mts +38 -490
  25. package/dist/index.d.ts +38 -490
  26. package/dist/index.js +1 -2266
  27. package/dist/index.mjs +1 -2039
  28. package/dist/router.d.mts +45 -0
  29. package/dist/router.d.ts +45 -0
  30. package/dist/router.js +1 -0
  31. package/dist/router.mjs +1 -0
  32. package/dist/server.d.mts +3 -0
  33. package/dist/server.d.ts +3 -0
  34. package/dist/server.js +1 -0
  35. package/dist/server.mjs +1 -0
  36. package/dist/state.d.mts +109 -0
  37. package/dist/state.d.ts +109 -0
  38. package/dist/state.js +1 -0
  39. package/dist/state.mjs +1 -0
  40. package/dist/style.d.mts +113 -0
  41. package/dist/style.d.ts +113 -0
  42. package/dist/style.js +1 -0
  43. package/dist/style.mjs +1 -0
  44. package/dist/types-DOAdFFJB.d.mts +330 -0
  45. package/dist/types-DOAdFFJB.d.ts +330 -0
  46. package/dist/types.d.mts +3 -0
  47. package/dist/types.d.ts +3 -0
  48. package/dist/types.js +1 -0
  49. package/dist/types.mjs +0 -0
  50. package/package.json +77 -7
  51. package/dist/index.global.js +0 -2064
@@ -1,2064 +0,0 @@
1
- "use strict";
2
- var DomLib = (() => {
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
-
21
- // src/index.ts
22
- var index_exports = {};
23
- __export(index_exports, {
24
- CreateStyle: () => CreateStyle,
25
- DomNode: () => DomNode,
26
- a: () => a,
27
- abbr: () => abbr,
28
- addLink: () => addLink,
29
- addMeta: () => addMeta,
30
- addStyle: () => addStyle,
31
- address: () => address,
32
- area: () => area,
33
- article: () => article,
34
- aside: () => aside,
35
- audio: () => audio,
36
- b: () => b,
37
- base: () => base,
38
- batchRender: () => batchRender,
39
- bdi: () => bdi,
40
- bdo: () => bdo,
41
- bindChecked: () => bindChecked,
42
- bindValue: () => bindValue,
43
- blockquote: () => blockquote,
44
- body: () => body,
45
- br: () => br,
46
- button: () => button,
47
- canvas: () => canvas,
48
- caption: () => caption,
49
- cite: () => cite,
50
- cleanupUnused: () => cleanupUnused,
51
- code: () => code,
52
- col: () => col,
53
- colgroup: () => colgroup,
54
- computed: () => computed,
55
- createElementFactory: () => createElementFactory,
56
- createRouter: () => createRouter,
57
- createRouterView: () => createRouterView,
58
- createState: () => createState,
59
- createVirtualList: () => createVirtualList,
60
- data: () => data,
61
- datalist: () => datalist,
62
- dd: () => dd,
63
- debounce: () => debounce,
64
- del: () => del,
65
- details: () => details,
66
- dfn: () => dfn,
67
- dialog: () => dialog,
68
- div: () => div,
69
- dl: () => dl,
70
- domNode: () => domNode,
71
- dt: () => dt,
72
- effect: () => effect,
73
- elements: () => elements,
74
- em: () => em,
75
- embed: () => embed,
76
- fieldset: () => fieldset,
77
- figcaption: () => figcaption,
78
- figure: () => figure,
79
- footer: () => footer,
80
- form: () => form,
81
- h1: () => h1,
82
- h2: () => h2,
83
- h3: () => h3,
84
- h4: () => h4,
85
- h5: () => h5,
86
- h6: () => h6,
87
- head: () => head,
88
- header: () => header,
89
- hr: () => hr,
90
- html: () => html,
91
- i: () => i,
92
- iframe: () => iframe,
93
- img: () => img,
94
- input: () => input,
95
- ins: () => ins,
96
- jsonToVNode: () => jsonToVNode,
97
- kbd: () => kbd,
98
- label: () => label,
99
- lazy: () => lazy,
100
- legend: () => legend,
101
- li: () => li,
102
- link: () => link,
103
- main: () => main,
104
- map: () => map,
105
- mark: () => mark,
106
- mathMath: () => mathMath,
107
- mathMfrac: () => mathMfrac,
108
- mathMi: () => mathMi,
109
- mathMn: () => mathMn,
110
- mathMo: () => mathMo,
111
- mathMroot: () => mathMroot,
112
- mathMrow: () => mathMrow,
113
- mathMs: () => mathMs,
114
- mathMsqrt: () => mathMsqrt,
115
- mathMsub: () => mathMsub,
116
- mathMsup: () => mathMsup,
117
- mathMtext: () => mathMtext,
118
- menu: () => menu,
119
- meta: () => meta,
120
- meter: () => meter,
121
- nav: () => nav,
122
- noscript: () => noscript,
123
- object: () => object,
124
- ol: () => ol,
125
- optgroup: () => optgroup,
126
- option: () => option,
127
- output: () => output,
128
- p: () => p,
129
- param: () => param,
130
- picture: () => picture,
131
- portal: () => portal,
132
- pre: () => pre,
133
- progress: () => progress,
134
- q: () => q,
135
- reactive: () => reactive,
136
- reactiveAs: () => reactiveAs,
137
- renderChunked: () => renderChunked,
138
- renderJson: () => renderJson,
139
- renderJsonToString: () => renderJsonToString,
140
- renderToHead: () => renderToHead,
141
- renderToString: () => renderToString,
142
- renderVNode: () => renderVNode,
143
- renderVNodeToString: () => renderVNodeToString,
144
- routerLink: () => routerLink,
145
- rp: () => rp,
146
- rt: () => rt,
147
- ruby: () => ruby,
148
- s: () => s,
149
- samp: () => samp,
150
- script: () => script,
151
- section: () => section,
152
- select: () => select,
153
- setTitle: () => setTitle,
154
- slot: () => slot,
155
- small: () => small,
156
- source: () => source,
157
- span: () => span,
158
- strong: () => strong,
159
- style: () => style,
160
- sub: () => sub,
161
- summary: () => summary,
162
- sup: () => sup,
163
- svgAnimate: () => svgAnimate,
164
- svgAnimateMotion: () => svgAnimateMotion,
165
- svgAnimateTransform: () => svgAnimateTransform,
166
- svgCircle: () => svgCircle,
167
- svgClipPath: () => svgClipPath,
168
- svgDefs: () => svgDefs,
169
- svgEllipse: () => svgEllipse,
170
- svgFeBlend: () => svgFeBlend,
171
- svgFeColorMatrix: () => svgFeColorMatrix,
172
- svgFeComponentTransfer: () => svgFeComponentTransfer,
173
- svgFeComposite: () => svgFeComposite,
174
- svgFeConvolveMatrix: () => svgFeConvolveMatrix,
175
- svgFeDiffuseLighting: () => svgFeDiffuseLighting,
176
- svgFeDisplacementMap: () => svgFeDisplacementMap,
177
- svgFeFlood: () => svgFeFlood,
178
- svgFeGaussianBlur: () => svgFeGaussianBlur,
179
- svgFeMorphology: () => svgFeMorphology,
180
- svgFeOffset: () => svgFeOffset,
181
- svgFeSpecularLighting: () => svgFeSpecularLighting,
182
- svgFeTile: () => svgFeTile,
183
- svgFeTurbulence: () => svgFeTurbulence,
184
- svgFilter: () => svgFilter,
185
- svgForeignObject: () => svgForeignObject,
186
- svgG: () => svgG,
187
- svgImage: () => svgImage,
188
- svgLine: () => svgLine,
189
- svgLinearGradient: () => svgLinearGradient,
190
- svgMarker: () => svgMarker,
191
- svgMask: () => svgMask,
192
- svgPath: () => svgPath,
193
- svgPattern: () => svgPattern,
194
- svgPolygon: () => svgPolygon,
195
- svgPolyline: () => svgPolyline,
196
- svgRadialGradient: () => svgRadialGradient,
197
- svgRect: () => svgRect,
198
- svgSet: () => svgSet,
199
- svgStop: () => svgStop,
200
- svgSvg: () => svgSvg,
201
- svgSymbol: () => svgSymbol,
202
- svgText: () => svgText,
203
- svgTspan: () => svgTspan,
204
- svgUse: () => svgUse,
205
- table: () => table,
206
- tbody: () => tbody,
207
- td: () => td,
208
- template: () => template,
209
- text: () => text,
210
- textarea: () => textarea,
211
- tfoot: () => tfoot,
212
- th: () => th,
213
- thead: () => thead,
214
- throttle: () => throttle,
215
- time: () => time,
216
- title: () => title,
217
- tr: () => tr,
218
- track: () => track,
219
- u: () => u,
220
- ul: () => ul,
221
- vNodeJsonToVNode: () => vNodeJsonToVNode,
222
- varElement: () => varElement,
223
- video: () => video,
224
- wbr: () => wbr
225
- });
226
-
227
- // src/DomNode.ts
228
- var DomNode = class {
229
- constructor() {
230
- this.elementCache = /* @__PURE__ */ new WeakMap();
231
- this.reactiveNodes = /* @__PURE__ */ new Map();
232
- }
233
- createElement(tagName, props = {}, children = []) {
234
- return { tagName, props, children };
235
- }
236
- renderToDOM(vNode, parent) {
237
- if (vNode == null || vNode === false) {
238
- return;
239
- }
240
- if (typeof vNode !== "object") {
241
- parent.appendChild(document.createTextNode(String(vNode)));
242
- return;
243
- }
244
- const tagName = vNode.tagName;
245
- const isSVG = tagName === "svg" || tagName[0] === "s" && tagName[1] === "v" && tagName[2] === "g" || parent.namespaceURI === "http://www.w3.org/2000/svg";
246
- const el = isSVG ? document.createElementNS("http://www.w3.org/2000/svg", tagName.replace("svg", "").toLowerCase() || tagName) : document.createElement(tagName);
247
- const props = vNode.props;
248
- for (const key in props) {
249
- const value = props[key];
250
- if (value == null || value === false) continue;
251
- const c = key.charCodeAt(0);
252
- if (c === 99) {
253
- if (key.length < 6 || key[5] === "N") {
254
- const classValue = Array.isArray(value) ? value.join(" ") : value;
255
- if (isSVG) {
256
- el.setAttribute("class", classValue);
257
- } else {
258
- el.className = classValue;
259
- }
260
- continue;
261
- }
262
- } else if (c === 115 && key.length === 5) {
263
- if (typeof value === "string") {
264
- el.style.cssText = value;
265
- } else {
266
- const s2 = el.style;
267
- for (const k in value) s2[k] = value[k];
268
- }
269
- continue;
270
- } else if (c === 111 && key.charCodeAt(1) === 110) {
271
- el[key.toLowerCase()] = value;
272
- continue;
273
- } else if (c === 100 && key.length > 20) {
274
- el.innerHTML = value.__html;
275
- continue;
276
- } else if (c === 114 && key.length === 3) {
277
- setTimeout(() => {
278
- if (typeof value === "function") {
279
- value(el);
280
- } else if (value && "current" in value) {
281
- value.current = el;
282
- }
283
- }, 0);
284
- continue;
285
- }
286
- isSVG ? el.setAttributeNS(null, key, value === true ? "" : String(value)) : el.setAttribute(key, value === true ? "" : String(value));
287
- }
288
- const children = vNode.children;
289
- const len = children.length;
290
- if (len === 0) {
291
- parent.appendChild(el);
292
- return;
293
- }
294
- if (len > 30) {
295
- const fragment = document.createDocumentFragment();
296
- for (let i2 = 0; i2 < len; i2++) {
297
- const child = children[i2];
298
- if (child == null || child === false) continue;
299
- if (Array.isArray(child)) {
300
- const childLen = child.length;
301
- for (let j = 0; j < childLen; j++) {
302
- const c = child[j];
303
- if (c != null && c !== false) {
304
- this.renderToDOM(c, fragment);
305
- }
306
- }
307
- } else {
308
- this.renderToDOM(child, fragment);
309
- }
310
- }
311
- el.appendChild(fragment);
312
- } else {
313
- for (let i2 = 0; i2 < len; i2++) {
314
- const child = children[i2];
315
- if (child == null || child === false) continue;
316
- if (Array.isArray(child)) {
317
- const childLen = child.length;
318
- for (let j = 0; j < childLen; j++) {
319
- const c = child[j];
320
- if (c != null && c !== false) {
321
- this.renderToDOM(c, el);
322
- }
323
- }
324
- } else {
325
- this.renderToDOM(child, el);
326
- }
327
- }
328
- }
329
- parent.appendChild(el);
330
- }
331
- render(rootElement, vNode) {
332
- const el = typeof rootElement === "string" ? document.getElementById(rootElement.replace("#", "")) : rootElement;
333
- if (!el) {
334
- throw new Error(`Element not found: ${rootElement}`);
335
- }
336
- if (vNode.children && vNode.children.length > 500) {
337
- const fragment = document.createDocumentFragment();
338
- this.renderToDOM(vNode, fragment);
339
- el.appendChild(fragment);
340
- } else {
341
- this.renderToDOM(vNode, el);
342
- }
343
- return el;
344
- }
345
- batchRender(rootElement, vNodes) {
346
- const el = typeof rootElement === "string" ? document.getElementById(rootElement.replace("#", "")) : rootElement;
347
- if (!el) {
348
- throw new Error(`Element not found: ${rootElement}`);
349
- }
350
- const len = vNodes.length;
351
- if (len > 3e3) {
352
- const fragment = document.createDocumentFragment();
353
- let processed = 0;
354
- const chunkSize = 1500;
355
- const processChunk = () => {
356
- const end = Math.min(processed + chunkSize, len);
357
- for (let i2 = processed; i2 < end; i2++) {
358
- this.renderToDOM(vNodes[i2], fragment);
359
- }
360
- processed = end;
361
- if (processed >= len) {
362
- el.appendChild(fragment);
363
- } else {
364
- requestAnimationFrame(processChunk);
365
- }
366
- };
367
- processChunk();
368
- } else {
369
- const fragment = document.createDocumentFragment();
370
- for (let i2 = 0; i2 < len; i2++) {
371
- this.renderToDOM(vNodes[i2], fragment);
372
- }
373
- el.appendChild(fragment);
374
- }
375
- return el;
376
- }
377
- renderChunked(rootElement, vNodes, chunkSize = 5e3, onProgress) {
378
- const el = typeof rootElement === "string" ? document.getElementById(rootElement.replace("#", "")) : rootElement;
379
- if (!el) {
380
- throw new Error(`Element not found: ${rootElement}`);
381
- }
382
- const len = vNodes.length;
383
- let index = 0;
384
- const renderChunk = () => {
385
- const end = Math.min(index + chunkSize, len);
386
- const fragment = document.createDocumentFragment();
387
- for (let i2 = index; i2 < end; i2++) {
388
- this.renderToDOM(vNodes[i2], fragment);
389
- }
390
- el.appendChild(fragment);
391
- index = end;
392
- if (onProgress) onProgress(index, len);
393
- if (index < len) {
394
- requestAnimationFrame(renderChunk);
395
- }
396
- };
397
- requestAnimationFrame(renderChunk);
398
- return el;
399
- }
400
- renderToHead(...vNodes) {
401
- const head2 = document.head;
402
- if (head2) {
403
- for (const vNode of vNodes.flat()) {
404
- vNode && this.renderToDOM(vNode, head2);
405
- }
406
- }
407
- return head2;
408
- }
409
- addStyle(cssText) {
410
- const el = document.createElement("style");
411
- el.textContent = cssText;
412
- return document.head.appendChild(el);
413
- }
414
- addMeta(attrs) {
415
- const el = document.createElement("meta");
416
- for (const k in attrs) el.setAttribute(k, attrs[k]);
417
- return document.head.appendChild(el);
418
- }
419
- addLink(attrs) {
420
- const el = document.createElement("link");
421
- for (const k in attrs) el.setAttribute(k, attrs[k]);
422
- return document.head.appendChild(el);
423
- }
424
- setTitle(text2) {
425
- return document.title = text2;
426
- }
427
- // Reactive State Management
428
- createState(initialValue, options = {}) {
429
- let value = initialValue;
430
- const listeners = /* @__PURE__ */ new Set();
431
- let updateTimer = null;
432
- const { throttle: throttle2 = 0, deep = false } = options;
433
- const notify = () => {
434
- listeners.forEach((fn) => fn(value));
435
- };
436
- const scheduleUpdate = () => {
437
- if (throttle2 > 0) {
438
- if (!updateTimer) {
439
- updateTimer = setTimeout(() => {
440
- updateTimer = null;
441
- notify();
442
- }, throttle2);
443
- }
444
- } else {
445
- notify();
446
- }
447
- };
448
- return {
449
- get value() {
450
- return value;
451
- },
452
- set value(newValue) {
453
- const changed = deep ? JSON.stringify(value) !== JSON.stringify(newValue) : value !== newValue;
454
- if (changed) {
455
- value = newValue;
456
- scheduleUpdate();
457
- }
458
- },
459
- subscribe(fn) {
460
- listeners.add(fn);
461
- return () => {
462
- listeners.delete(fn);
463
- };
464
- },
465
- destroy() {
466
- listeners.clear();
467
- if (updateTimer) clearTimeout(updateTimer);
468
- }
469
- };
470
- }
471
- computed(states, computeFn) {
472
- const values = states.map((s2) => s2.value);
473
- const result = this.createState(computeFn(...values));
474
- states.forEach((state, index) => {
475
- state.subscribe((newValue) => {
476
- values[index] = newValue;
477
- result.value = computeFn(...values);
478
- });
479
- });
480
- return result;
481
- }
482
- effect(stateFn) {
483
- stateFn();
484
- }
485
- // Virtual scrolling helper for large lists
486
- createVirtualList(container, items, renderItem, itemHeight = 50, bufferSize = 5) {
487
- const viewportHeight = container.clientHeight;
488
- const totalHeight = items.length * itemHeight;
489
- let scrollTop = 0;
490
- const getVisibleRange = () => {
491
- const start = Math.max(0, Math.floor(scrollTop / itemHeight) - bufferSize);
492
- const end = Math.min(items.length, Math.ceil((scrollTop + viewportHeight) / itemHeight) + bufferSize);
493
- return { start, end };
494
- };
495
- const render = () => {
496
- const { start, end } = getVisibleRange();
497
- const wrapper = document.createElement("div");
498
- wrapper.style.cssText = `height:${totalHeight}px;position:relative`;
499
- for (let i2 = start; i2 < end; i2++) {
500
- const itemEl = document.createElement("div");
501
- itemEl.style.cssText = `position:absolute;top:${i2 * itemHeight}px;height:${itemHeight}px;width:100%`;
502
- this.renderToDOM(renderItem(items[i2], i2), itemEl);
503
- wrapper.appendChild(itemEl);
504
- }
505
- container.innerHTML = "";
506
- container.appendChild(wrapper);
507
- };
508
- const scrollHandler = () => {
509
- scrollTop = container.scrollTop;
510
- requestAnimationFrame(render);
511
- };
512
- container.addEventListener("scroll", scrollHandler);
513
- render();
514
- return {
515
- render,
516
- destroy: () => {
517
- container.removeEventListener("scroll", scrollHandler);
518
- container.innerHTML = "";
519
- }
520
- };
521
- }
522
- // Lazy load components
523
- lazy(loadFn) {
524
- let component = null;
525
- let loading = false;
526
- return async (...args) => {
527
- if (!component && !loading) {
528
- loading = true;
529
- component = await loadFn();
530
- loading = false;
531
- }
532
- return component ? component(...args) : { tagName: "div", props: { class: "loading" }, children: ["Loading..."] };
533
- };
534
- }
535
- // Memory management - cleanup unused elements
536
- cleanupUnusedElements(root) {
537
- const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
538
- const toRemove = [];
539
- while (walker.nextNode()) {
540
- const node = walker.currentNode;
541
- if (node.id && node.id.startsWith("r") && !this.elementCache.has(node)) {
542
- toRemove.push(node);
543
- }
544
- }
545
- toRemove.forEach((el) => el.remove());
546
- return toRemove.length;
547
- }
548
- // Server-Side Rendering - convert VNode to HTML string
549
- renderToString(vNode, options = {}) {
550
- const { pretty = false, indent = 0 } = options;
551
- const indentStr = pretty ? " ".repeat(indent) : "";
552
- const newLine = pretty ? "\n" : "";
553
- let resolvedVNode = this.resolveStateValue(vNode);
554
- resolvedVNode = this.unwrapReactive(resolvedVNode);
555
- if (Array.isArray(resolvedVNode)) {
556
- return resolvedVNode.map((child) => this.renderToString(child, options)).join("");
557
- }
558
- if (typeof resolvedVNode !== "object" || resolvedVNode === null) {
559
- if (resolvedVNode === null || resolvedVNode === void 0 || resolvedVNode === false) {
560
- return "";
561
- }
562
- return this.escapeHtml(String(resolvedVNode));
563
- }
564
- const { tagName, props, children } = resolvedVNode;
565
- const isSelfClosing = this.isSelfClosingTag(tagName);
566
- let html2 = `${indentStr}<${tagName}`;
567
- const attrs = this.propsToAttributes(props);
568
- if (attrs) {
569
- html2 += ` ${attrs}`;
570
- }
571
- if (isSelfClosing) {
572
- html2 += ` />${newLine}`;
573
- return html2;
574
- }
575
- html2 += ">";
576
- if (props.dangerouslySetInnerHTML) {
577
- html2 += props.dangerouslySetInnerHTML.__html;
578
- html2 += `</${tagName}>${newLine}`;
579
- return html2;
580
- }
581
- if (children && children.length > 0) {
582
- const resolvedChildren = children.map((c) => {
583
- const resolved = this.resolveStateValue(c);
584
- return this.unwrapReactive(resolved);
585
- });
586
- const hasComplexChildren = resolvedChildren.some(
587
- (c) => typeof c === "object" && c !== null && !Array.isArray(c) && "tagName" in c
588
- );
589
- if (pretty && hasComplexChildren) {
590
- html2 += newLine;
591
- for (const child of resolvedChildren) {
592
- if (child == null || child === false) continue;
593
- if (Array.isArray(child)) {
594
- for (const c of child) {
595
- if (c != null && c !== false) {
596
- html2 += this.renderToString(c, { pretty, indent: indent + 1 });
597
- }
598
- }
599
- } else {
600
- html2 += this.renderToString(child, { pretty, indent: indent + 1 });
601
- }
602
- }
603
- html2 += indentStr;
604
- } else {
605
- for (const child of resolvedChildren) {
606
- if (child == null || child === false) continue;
607
- if (Array.isArray(child)) {
608
- for (const c of child) {
609
- if (c != null && c !== false) {
610
- html2 += this.renderToString(c, { pretty: false, indent: 0 });
611
- }
612
- }
613
- } else {
614
- html2 += this.renderToString(child, { pretty: false, indent: 0 });
615
- }
616
- }
617
- }
618
- }
619
- html2 += `</${tagName}>${newLine}`;
620
- return html2;
621
- }
622
- resolveStateValue(value) {
623
- if (value && typeof value === "object" && "value" in value && "subscribe" in value) {
624
- return value.value;
625
- }
626
- return value;
627
- }
628
- isReactiveWrapper(vNode) {
629
- if (!vNode || typeof vNode !== "object" || !vNode.tagName) {
630
- return false;
631
- }
632
- return vNode.tagName === "span" && vNode.props?.id && typeof vNode.props.id === "string" && vNode.props.id.match(/^r[a-z0-9]{9}$/);
633
- }
634
- unwrapReactive(vNode) {
635
- if (!this.isReactiveWrapper(vNode)) {
636
- return vNode;
637
- }
638
- const children = vNode.children;
639
- if (!children || children.length === 0) {
640
- return "";
641
- }
642
- if (children.length === 1) {
643
- const child = children[0];
644
- if (child && typeof child === "object" && child.tagName === "span") {
645
- const props = child.props;
646
- const hasNoProps = !props || Object.keys(props).length === 0;
647
- const hasSingleStringChild = child.children && child.children.length === 1 && typeof child.children[0] === "string";
648
- if (hasNoProps && hasSingleStringChild) {
649
- return child.children[0];
650
- }
651
- }
652
- return this.unwrapReactive(child);
653
- }
654
- return children.map((c) => this.unwrapReactive(c));
655
- }
656
- escapeHtml(text2) {
657
- const htmlEscapes = {
658
- "&": "&amp;",
659
- "<": "&lt;",
660
- ">": "&gt;",
661
- '"': "&quot;",
662
- "'": "&#x27;"
663
- };
664
- return text2.replace(/[&<>"']/g, (char) => htmlEscapes[char]);
665
- }
666
- isSelfClosingTag(tagName) {
667
- const selfClosingTags = /* @__PURE__ */ new Set([
668
- "area",
669
- "base",
670
- "br",
671
- "col",
672
- "embed",
673
- "hr",
674
- "img",
675
- "input",
676
- "link",
677
- "meta",
678
- "param",
679
- "source",
680
- "track",
681
- "wbr"
682
- ]);
683
- return selfClosingTags.has(tagName.toLowerCase());
684
- }
685
- propsToAttributes(props) {
686
- const attrs = [];
687
- for (const key in props) {
688
- if (key === "children" || key === "dangerouslySetInnerHTML" || key === "ref") {
689
- continue;
690
- }
691
- let value = props[key];
692
- value = this.resolveStateValue(value);
693
- if (value == null || value === false) continue;
694
- if (key.startsWith("on") && typeof value === "function") {
695
- continue;
696
- }
697
- if (key === "className" || key === "class") {
698
- const className = Array.isArray(value) ? value.join(" ") : value;
699
- if (className) {
700
- attrs.push(`class="${this.escapeHtml(String(className))}"`);
701
- }
702
- continue;
703
- }
704
- if (key === "style") {
705
- const styleStr = this.styleToString(value);
706
- if (styleStr) {
707
- attrs.push(`style="${this.escapeHtml(styleStr)}"`);
708
- }
709
- continue;
710
- }
711
- if (value === true) {
712
- attrs.push(key);
713
- continue;
714
- }
715
- attrs.push(`${key}="${this.escapeHtml(String(value))}"`);
716
- }
717
- return attrs.join(" ");
718
- }
719
- styleToString(style2) {
720
- if (typeof style2 === "string") {
721
- return style2;
722
- }
723
- if (typeof style2 === "object" && style2 !== null) {
724
- const styles = [];
725
- for (const key in style2) {
726
- const cssKey = key.replace(/([A-Z])/g, "-$1").toLowerCase();
727
- styles.push(`${cssKey}:${style2[key]}`);
728
- }
729
- return styles.join(";");
730
- }
731
- return "";
732
- }
733
- isState(value) {
734
- return value && typeof value === "object" && "value" in value && "subscribe" in value && typeof value.subscribe === "function";
735
- }
736
- createReactiveChild(state, renderFn) {
737
- const currentValue = renderFn(state.value);
738
- if (typeof window !== "undefined" && typeof document !== "undefined") {
739
- const entry = { node: null, renderFn };
740
- this.reactiveNodes.set(state, entry);
741
- state.subscribe(() => {
742
- if (entry.node && entry.node.parentNode) {
743
- const newValue = renderFn(state.value);
744
- entry.node.textContent = String(newValue ?? "");
745
- }
746
- });
747
- }
748
- return currentValue;
749
- }
750
- jsonToVNode(json) {
751
- if (this.isState(json)) {
752
- return this.createReactiveChild(json, (v) => v);
753
- }
754
- if (json == null || typeof json === "boolean") {
755
- return json;
756
- }
757
- if (typeof json === "string" || typeof json === "number") {
758
- return json;
759
- }
760
- const { tag, attributes = {}, children } = json;
761
- const props = {};
762
- for (const key in attributes) {
763
- const value = attributes[key];
764
- if (key === "class") {
765
- props.className = this.isState(value) ? value.value : value;
766
- } else {
767
- props[key] = this.isState(value) ? value.value : value;
768
- }
769
- }
770
- const childrenArray = [];
771
- if (children != null) {
772
- if (Array.isArray(children)) {
773
- for (const child of children) {
774
- if (this.isState(child)) {
775
- childrenArray.push(this.createReactiveChild(child, (v) => v));
776
- } else {
777
- const converted = this.jsonToVNode(child);
778
- if (converted != null && converted !== false) {
779
- childrenArray.push(converted);
780
- }
781
- }
782
- }
783
- } else if (this.isState(children)) {
784
- childrenArray.push(this.createReactiveChild(children, (v) => v));
785
- } else if (typeof children === "object" && "tag" in children) {
786
- const converted = this.jsonToVNode(children);
787
- if (converted != null && converted !== false) {
788
- childrenArray.push(converted);
789
- }
790
- } else {
791
- childrenArray.push(children);
792
- }
793
- }
794
- return { tagName: tag, props, children: childrenArray };
795
- }
796
- vNodeJsonToVNode(json) {
797
- if (this.isState(json)) {
798
- return this.createReactiveChild(json, (v) => v);
799
- }
800
- if (json == null || typeof json === "boolean") {
801
- return json;
802
- }
803
- if (typeof json === "string" || typeof json === "number") {
804
- return json;
805
- }
806
- const { tagName, props = {}, children = [] } = json;
807
- const resolvedProps = {};
808
- for (const key in props) {
809
- const value = props[key];
810
- resolvedProps[key] = this.isState(value) ? value.value : value;
811
- }
812
- const childrenArray = [];
813
- for (const child of children) {
814
- if (this.isState(child)) {
815
- childrenArray.push(this.createReactiveChild(child, (v) => v));
816
- } else {
817
- const converted = this.vNodeJsonToVNode(child);
818
- if (converted != null && converted !== false) {
819
- childrenArray.push(converted);
820
- }
821
- }
822
- }
823
- return { tagName, props: resolvedProps, children: childrenArray };
824
- }
825
- renderJson(rootElement, json) {
826
- const vNode = this.jsonToVNode(json);
827
- if (!vNode || typeof vNode !== "object" || !("tagName" in vNode)) {
828
- throw new Error("Invalid JSON structure");
829
- }
830
- return this.render(rootElement, vNode);
831
- }
832
- renderVNode(rootElement, json) {
833
- const vNode = this.vNodeJsonToVNode(json);
834
- if (!vNode || typeof vNode !== "object" || !("tagName" in vNode)) {
835
- throw new Error("Invalid VNode JSON structure");
836
- }
837
- return this.render(rootElement, vNode);
838
- }
839
- renderJsonToString(json, options = {}) {
840
- const vNode = this.jsonToVNode(json);
841
- return this.renderToString(vNode, options);
842
- }
843
- renderVNodeToString(json, options = {}) {
844
- const vNode = this.vNodeJsonToVNode(json);
845
- return this.renderToString(vNode, options);
846
- }
847
- // Expose elementCache for reactive updates
848
- getElementCache() {
849
- return this.elementCache;
850
- }
851
- };
852
- var domNode = new DomNode();
853
-
854
- // src/state.ts
855
- var createState = (initial, options) => domNode.createState(initial, options);
856
- var computed = (states, fn) => domNode.computed(states, fn);
857
- var effect = (fn) => domNode.effect(fn);
858
- var batchRender = (container, vNodes) => domNode.batchRender(container, vNodes);
859
- var renderChunked = (container, vNodes, chunkSize, onProgress) => domNode.renderChunked(container, vNodes, chunkSize, onProgress);
860
- var createVirtualList = (container, items, renderItem, itemHeight, bufferSize) => domNode.createVirtualList(container, items, renderItem, itemHeight, bufferSize);
861
- var lazy = (loadFn) => domNode.lazy(loadFn);
862
- var cleanupUnused = (root) => domNode.cleanupUnusedElements(root);
863
- var throttle = (fn, delay) => {
864
- let timer = null;
865
- return (...args) => {
866
- if (!timer) {
867
- timer = setTimeout(() => {
868
- timer = null;
869
- fn(...args);
870
- }, delay);
871
- }
872
- };
873
- };
874
- var debounce = (fn, delay) => {
875
- let timer = null;
876
- return (...args) => {
877
- if (timer) clearTimeout(timer);
878
- timer = setTimeout(() => fn(...args), delay);
879
- };
880
- };
881
-
882
- // src/reactive.ts
883
- var reactive = (state, renderFn) => {
884
- let rafId = null;
885
- let elementRef = null;
886
- let placeholder = null;
887
- let isInDOM = true;
888
- const initialResult = renderFn(state.value);
889
- const isVNodeResult = initialResult && typeof initialResult === "object" && "tagName" in initialResult;
890
- const initialIsNull = initialResult == null || initialResult === false;
891
- state.subscribe(() => {
892
- if (rafId) cancelAnimationFrame(rafId);
893
- rafId = requestAnimationFrame(() => {
894
- if (!elementRef && !placeholder) return;
895
- const newResult = renderFn(state.value);
896
- const resultIsNull = newResult == null || newResult === false;
897
- if (resultIsNull) {
898
- if (isInDOM && elementRef) {
899
- placeholder = document.createComment("reactive");
900
- elementRef.parentNode?.replaceChild(placeholder, elementRef);
901
- isInDOM = false;
902
- }
903
- } else {
904
- if (!isInDOM && placeholder && elementRef) {
905
- placeholder.parentNode?.replaceChild(elementRef, placeholder);
906
- placeholder = null;
907
- isInDOM = true;
908
- }
909
- if (elementRef) {
910
- const fragment = document.createDocumentFragment();
911
- if (isVNodeResult && newResult && typeof newResult === "object" && "tagName" in newResult) {
912
- const vnode = newResult;
913
- const props = vnode.props;
914
- for (const key in props) {
915
- const value = props[key];
916
- if (key === "ref") continue;
917
- if (key === "class" || key === "className") {
918
- elementRef.className = Array.isArray(value) ? value.join(" ") : value || "";
919
- } else if (key === "style" && typeof value === "object") {
920
- const s2 = elementRef.style;
921
- for (const k in value) s2[k] = value[k];
922
- } else if (key.startsWith("on")) {
923
- elementRef[key.toLowerCase()] = value;
924
- } else if (value != null && value !== false) {
925
- elementRef.setAttribute(key, String(value === true ? "" : value));
926
- } else {
927
- elementRef.removeAttribute(key);
928
- }
929
- }
930
- for (const child of vnode.children) {
931
- domNode.renderToDOM(child, fragment);
932
- }
933
- } else {
934
- domNode.renderToDOM(newResult, fragment);
935
- }
936
- elementRef.textContent = "";
937
- elementRef.appendChild(fragment);
938
- domNode.getElementCache().set(elementRef, true);
939
- }
940
- }
941
- rafId = null;
942
- });
943
- });
944
- const refCallback = (el) => {
945
- elementRef = el;
946
- if (initialIsNull && el.parentNode) {
947
- placeholder = document.createComment("reactive");
948
- el.parentNode.replaceChild(placeholder, el);
949
- isInDOM = false;
950
- }
951
- };
952
- if (isVNodeResult) {
953
- const vnode = initialResult;
954
- return {
955
- tagName: vnode.tagName,
956
- props: { ...vnode.props, ref: refCallback },
957
- children: vnode.children
958
- };
959
- }
960
- return { tagName: "span", props: { ref: refCallback }, children: [initialResult] };
961
- };
962
- var reactiveAs = (tagName, state, renderFn, props = {}) => {
963
- let rafId = null;
964
- let elementRef = null;
965
- state.subscribe(() => {
966
- if (rafId) cancelAnimationFrame(rafId);
967
- rafId = requestAnimationFrame(() => {
968
- if (elementRef) {
969
- const fragment = document.createDocumentFragment();
970
- const newResult = renderFn(state.value);
971
- if (newResult == null || newResult === false) {
972
- elementRef.style.display = "none";
973
- elementRef.textContent = "";
974
- } else {
975
- elementRef.style.display = "";
976
- domNode.renderToDOM(newResult, fragment);
977
- elementRef.textContent = "";
978
- elementRef.appendChild(fragment);
979
- }
980
- domNode.getElementCache().set(elementRef, true);
981
- }
982
- rafId = null;
983
- });
984
- });
985
- const refCallback = (el) => {
986
- elementRef = el;
987
- };
988
- return { tagName, props: { ...props, ref: refCallback }, children: [renderFn(state.value)] };
989
- };
990
- var text = (state) => state && state.value !== void 0 ? reactive(state, (v) => ({ tagName: "span", props: {}, children: [String(v)] })) : String(state);
991
- var bindValue = (state) => ({
992
- value: state.value,
993
- oninput: (e) => {
994
- state.value = e.target.value;
995
- }
996
- });
997
- var bindChecked = (state) => ({
998
- checked: state.value,
999
- onchange: (e) => {
1000
- state.value = e.target.checked;
1001
- }
1002
- });
1003
-
1004
- // src/CreateStyle.ts
1005
- var CreateStyle = class {
1006
- constructor() {
1007
- this.variables = [];
1008
- this.rules = [];
1009
- this.mediaRules = [];
1010
- this.keyframes = [];
1011
- this.fontFaces = [];
1012
- this.imports = [];
1013
- this.containerRules = [];
1014
- this.supportsRules = [];
1015
- this.layerRules = [];
1016
- this._layerOrder = [];
1017
- }
1018
- // CSS Variables
1019
- addVar(name, value) {
1020
- const cssVar = {
1021
- name: name.startsWith("--") ? name : `--${name}`,
1022
- value,
1023
- toString() {
1024
- return `var(${this.name})`;
1025
- }
1026
- };
1027
- this.variables.push(cssVar);
1028
- return cssVar;
1029
- }
1030
- var(variable, fallback) {
1031
- const varName = typeof variable === "string" ? variable.startsWith("--") ? variable : `--${variable}` : variable.name;
1032
- return fallback ? `var(${varName}, ${fallback})` : `var(${varName})`;
1033
- }
1034
- // Basic Selectors
1035
- addTag(tag, styles) {
1036
- const rule = { selector: tag, styles, type: "tag" };
1037
- this.rules.push(rule);
1038
- return rule;
1039
- }
1040
- addClass(name, styles) {
1041
- const selector = name.startsWith(".") ? name : `.${name}`;
1042
- const rule = { selector, styles, type: "class" };
1043
- this.rules.push(rule);
1044
- return rule;
1045
- }
1046
- addId(name, styles) {
1047
- const selector = name.startsWith("#") ? name : `#${name}`;
1048
- const rule = { selector, styles, type: "id" };
1049
- this.rules.push(rule);
1050
- return rule;
1051
- }
1052
- // Pseudo Selectors
1053
- addPseudoClass(pseudo, styles, baseSelector) {
1054
- const pseudoClass = pseudo.startsWith(":") ? pseudo : `:${pseudo}`;
1055
- const selector = baseSelector ? `${baseSelector}${pseudoClass}` : pseudoClass;
1056
- const rule = { selector, styles, type: "pseudo-class" };
1057
- this.rules.push(rule);
1058
- return rule;
1059
- }
1060
- addPseudoElement(pseudo, styles, baseSelector) {
1061
- const pseudoElement = pseudo.startsWith("::") ? pseudo : `::${pseudo}`;
1062
- const selector = baseSelector ? `${baseSelector}${pseudoElement}` : pseudoElement;
1063
- const rule = { selector, styles, type: "pseudo-element" };
1064
- this.rules.push(rule);
1065
- return rule;
1066
- }
1067
- // Attribute Selectors
1068
- addAttribute(attr, styles, baseSelector) {
1069
- const attrSelector = attr.startsWith("[") ? attr : `[${attr}]`;
1070
- const selector = baseSelector ? `${baseSelector}${attrSelector}` : attrSelector;
1071
- const rule = { selector, styles, type: "attribute" };
1072
- this.rules.push(rule);
1073
- return rule;
1074
- }
1075
- attrEquals(attr, value, styles, baseSelector) {
1076
- return this.addAttribute(`${attr}="${value}"`, styles, baseSelector);
1077
- }
1078
- attrContainsWord(attr, value, styles, baseSelector) {
1079
- return this.addAttribute(`${attr}~="${value}"`, styles, baseSelector);
1080
- }
1081
- attrStartsWith(attr, value, styles, baseSelector) {
1082
- return this.addAttribute(`${attr}^="${value}"`, styles, baseSelector);
1083
- }
1084
- attrEndsWith(attr, value, styles, baseSelector) {
1085
- return this.addAttribute(`${attr}$="${value}"`, styles, baseSelector);
1086
- }
1087
- attrContains(attr, value, styles, baseSelector) {
1088
- return this.addAttribute(`${attr}*="${value}"`, styles, baseSelector);
1089
- }
1090
- // Combinator Selectors
1091
- descendant(ancestor, descendant, styles) {
1092
- const selector = `${ancestor} ${descendant}`;
1093
- const rule = { selector, styles, type: "custom" };
1094
- this.rules.push(rule);
1095
- return rule;
1096
- }
1097
- child(parent, childSel, styles) {
1098
- const selector = `${parent} > ${childSel}`;
1099
- const rule = { selector, styles, type: "custom" };
1100
- this.rules.push(rule);
1101
- return rule;
1102
- }
1103
- adjacentSibling(element, sibling, styles) {
1104
- const selector = `${element} + ${sibling}`;
1105
- const rule = { selector, styles, type: "custom" };
1106
- this.rules.push(rule);
1107
- return rule;
1108
- }
1109
- generalSibling(element, sibling, styles) {
1110
- const selector = `${element} ~ ${sibling}`;
1111
- const rule = { selector, styles, type: "custom" };
1112
- this.rules.push(rule);
1113
- return rule;
1114
- }
1115
- multiple(selectors, styles) {
1116
- const selector = selectors.join(", ");
1117
- const rule = { selector, styles, type: "custom" };
1118
- this.rules.push(rule);
1119
- return rule;
1120
- }
1121
- // Nesting (BEM-style)
1122
- addName(name, styles) {
1123
- const selector = name.startsWith("--") ? `&${name}` : `&--${name}`;
1124
- const rule = { selector, styles, type: "name" };
1125
- return rule;
1126
- }
1127
- nesting(parentRule, ...childRules) {
1128
- parentRule.nested = childRules;
1129
- return parentRule;
1130
- }
1131
- // @keyframes - Animations
1132
- keyframe(name, steps) {
1133
- const keyframeSteps = Object.entries(steps).map(([step, styles]) => ({
1134
- step: step === "from" ? "from" : step === "to" ? "to" : `${step}%`,
1135
- styles
1136
- }));
1137
- const kf = { name, steps: keyframeSteps };
1138
- this.keyframes.push(kf);
1139
- return kf;
1140
- }
1141
- keyframeFromTo(name, from, to) {
1142
- return this.keyframe(name, { from, to });
1143
- }
1144
- // @font-face - Custom Fonts
1145
- fontFace(options) {
1146
- this.fontFaces.push(options);
1147
- return options;
1148
- }
1149
- // @import - Import Stylesheets
1150
- import(url, mediaQuery) {
1151
- const importRule = mediaQuery ? `@import url("${url}") ${mediaQuery};` : `@import url("${url}");`;
1152
- this.imports.push(importRule);
1153
- return importRule;
1154
- }
1155
- // @media - Media Queries
1156
- media(type, condition, rules) {
1157
- const cssRules = Object.entries(rules).map(([selector, styles]) => ({
1158
- selector,
1159
- styles,
1160
- type: "custom"
1161
- }));
1162
- const mediaRule = { type, condition, rules: cssRules };
1163
- this.mediaRules.push(mediaRule);
1164
- return mediaRule;
1165
- }
1166
- mediaScreen(condition, rules) {
1167
- return this.media("screen", condition, rules);
1168
- }
1169
- mediaPrint(rules) {
1170
- return this.media("print", "", rules);
1171
- }
1172
- mediaMinWidth(minWidth, rules) {
1173
- return this.media("screen", `min-width: ${minWidth}`, rules);
1174
- }
1175
- mediaMaxWidth(maxWidth, rules) {
1176
- return this.media("screen", `max-width: ${maxWidth}`, rules);
1177
- }
1178
- mediaDark(rules) {
1179
- const cssRules = Object.entries(rules).map(([selector, styles]) => ({
1180
- selector,
1181
- styles,
1182
- type: "custom"
1183
- }));
1184
- const mediaRule = { type: "", condition: "prefers-color-scheme: dark", rules: cssRules };
1185
- this.mediaRules.push(mediaRule);
1186
- return mediaRule;
1187
- }
1188
- mediaLight(rules) {
1189
- const cssRules = Object.entries(rules).map(([selector, styles]) => ({
1190
- selector,
1191
- styles,
1192
- type: "custom"
1193
- }));
1194
- const mediaRule = { type: "", condition: "prefers-color-scheme: light", rules: cssRules };
1195
- this.mediaRules.push(mediaRule);
1196
- return mediaRule;
1197
- }
1198
- mediaReducedMotion(rules) {
1199
- const cssRules = Object.entries(rules).map(([selector, styles]) => ({
1200
- selector,
1201
- styles,
1202
- type: "custom"
1203
- }));
1204
- const mediaRule = { type: "", condition: "prefers-reduced-motion: reduce", rules: cssRules };
1205
- this.mediaRules.push(mediaRule);
1206
- return mediaRule;
1207
- }
1208
- // @container - Container Queries
1209
- container(condition, rules, name) {
1210
- const cssRules = Object.entries(rules).map(([selector, styles]) => ({
1211
- selector,
1212
- styles,
1213
- type: "custom"
1214
- }));
1215
- const containerRule = { name, condition, rules: cssRules };
1216
- this.containerRules.push(containerRule);
1217
- return containerRule;
1218
- }
1219
- addContainer(name, styles) {
1220
- const containerStyles = { ...styles, containerName: name };
1221
- return this.addClass(name, containerStyles);
1222
- }
1223
- // @supports - Feature Queries
1224
- supports(condition, rules) {
1225
- const cssRules = Object.entries(rules).map(([selector, styles]) => ({
1226
- selector,
1227
- styles,
1228
- type: "custom"
1229
- }));
1230
- const supportsRule = { condition, rules: cssRules };
1231
- this.supportsRules.push(supportsRule);
1232
- return supportsRule;
1233
- }
1234
- // @layer - Cascade Layers
1235
- layerOrder(...layers) {
1236
- this._layerOrder = layers;
1237
- }
1238
- layer(name, rules) {
1239
- const cssRules = Object.entries(rules).map(([selector, styles]) => ({
1240
- selector,
1241
- styles,
1242
- type: "custom"
1243
- }));
1244
- const layerRule = { name, rules: cssRules };
1245
- this.layerRules.push(layerRule);
1246
- return layerRule;
1247
- }
1248
- // Custom Rules
1249
- add(rules) {
1250
- const cssRules = Object.entries(rules).map(([selector, styles]) => {
1251
- const rule = { selector, styles, type: "custom" };
1252
- this.rules.push(rule);
1253
- return rule;
1254
- });
1255
- return cssRules;
1256
- }
1257
- important(value) {
1258
- return `${value} !important`;
1259
- }
1260
- // Utility Methods
1261
- toKebabCase(str) {
1262
- return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
1263
- }
1264
- stylesToString(styles, indent = " ") {
1265
- return Object.entries(styles).map(([prop, value]) => {
1266
- const cssValue = typeof value === "object" && value !== null && "name" in value ? `var(${value.name})` : value;
1267
- return `${indent}${this.toKebabCase(prop)}: ${cssValue};`;
1268
- }).join("\n");
1269
- }
1270
- renderRule(rule, indent = "") {
1271
- let css = `${indent}${rule.selector} {
1272
- ${this.stylesToString(rule.styles, indent + " ")}
1273
- `;
1274
- if (rule.nested && rule.nested.length > 0) {
1275
- for (const nestedRule of rule.nested) {
1276
- const nestedSelector = nestedRule.selector.startsWith("&") ? nestedRule.selector.replace(/&/g, rule.selector) : `${rule.selector} ${nestedRule.selector}`;
1277
- css += `
1278
- ${indent}${nestedSelector} {
1279
- ${this.stylesToString(nestedRule.styles, indent + " ")}
1280
- ${indent}}
1281
- `;
1282
- }
1283
- }
1284
- css += `${indent}}`;
1285
- return css;
1286
- }
1287
- renderMediaRule(media) {
1288
- const condition = media.type && media.condition ? `${media.type} and (${media.condition})` : media.type ? media.type : `(${media.condition})`;
1289
- let css = `@media ${condition} {
1290
- `;
1291
- for (const rule of media.rules) {
1292
- css += this.renderRule(rule, " ") + "\n";
1293
- }
1294
- css += "}";
1295
- return css;
1296
- }
1297
- renderKeyframes(kf) {
1298
- let css = `@keyframes ${kf.name} {
1299
- `;
1300
- for (const step of kf.steps) {
1301
- css += ` ${step.step} {
1302
- ${this.stylesToString(step.styles, " ")}
1303
- }
1304
- `;
1305
- }
1306
- css += "}";
1307
- return css;
1308
- }
1309
- renderFontFace(ff) {
1310
- let css = "@font-face {\n";
1311
- css += ` font-family: "${ff.fontFamily}";
1312
- `;
1313
- css += ` src: ${ff.src};
1314
- `;
1315
- if (ff.fontWeight) css += ` font-weight: ${ff.fontWeight};
1316
- `;
1317
- if (ff.fontStyle) css += ` font-style: ${ff.fontStyle};
1318
- `;
1319
- if (ff.fontDisplay) css += ` font-display: ${ff.fontDisplay};
1320
- `;
1321
- if (ff.unicodeRange) css += ` unicode-range: ${ff.unicodeRange};
1322
- `;
1323
- css += "}";
1324
- return css;
1325
- }
1326
- renderContainerRule(container) {
1327
- const nameStr = container.name ? `${container.name} ` : "";
1328
- let css = `@container ${nameStr}(${container.condition}) {
1329
- `;
1330
- for (const rule of container.rules) {
1331
- css += this.renderRule(rule, " ") + "\n";
1332
- }
1333
- css += "}";
1334
- return css;
1335
- }
1336
- renderSupportsRule(supports) {
1337
- let css = `@supports (${supports.condition}) {
1338
- `;
1339
- for (const rule of supports.rules) {
1340
- css += this.renderRule(rule, " ") + "\n";
1341
- }
1342
- css += "}";
1343
- return css;
1344
- }
1345
- renderLayerRule(layer) {
1346
- let css = `@layer ${layer.name} {
1347
- `;
1348
- for (const rule of layer.rules) {
1349
- css += this.renderRule(rule, " ") + "\n";
1350
- }
1351
- css += "}";
1352
- return css;
1353
- }
1354
- // Render Output
1355
- render(...additionalRules) {
1356
- const parts = [];
1357
- if (this.imports.length > 0) {
1358
- parts.push(this.imports.join("\n"));
1359
- }
1360
- if (this._layerOrder.length > 0) {
1361
- parts.push(`@layer ${this._layerOrder.join(", ")};`);
1362
- }
1363
- if (this.variables.length > 0) {
1364
- const varDeclarations = this.variables.map((v) => ` ${v.name}: ${v.value};`).join("\n");
1365
- parts.push(`:root {
1366
- ${varDeclarations}
1367
- }`);
1368
- }
1369
- for (const ff of this.fontFaces) {
1370
- parts.push(this.renderFontFace(ff));
1371
- }
1372
- for (const kf of this.keyframes) {
1373
- parts.push(this.renderKeyframes(kf));
1374
- }
1375
- const allRules = [...this.rules];
1376
- const allMediaRules = [...this.mediaRules];
1377
- const allKeyframes = [];
1378
- const allContainerRules = [...this.containerRules];
1379
- const allSupportsRules = [...this.supportsRules];
1380
- const allLayerRules = [...this.layerRules];
1381
- for (const item of additionalRules) {
1382
- if (!item) continue;
1383
- if (Array.isArray(item)) {
1384
- allRules.push(...item);
1385
- } else if ("condition" in item && "rules" in item && !("name" in item && "steps" in item)) {
1386
- if ("type" in item) {
1387
- allMediaRules.push(item);
1388
- } else if ("name" in item && typeof item.name === "string") {
1389
- allContainerRules.push(item);
1390
- } else {
1391
- allSupportsRules.push(item);
1392
- }
1393
- } else if ("name" in item && "steps" in item) {
1394
- allKeyframes.push(item);
1395
- } else if ("name" in item && "rules" in item) {
1396
- allLayerRules.push(item);
1397
- } else {
1398
- allRules.push(item);
1399
- }
1400
- }
1401
- for (const kf of allKeyframes) {
1402
- parts.push(this.renderKeyframes(kf));
1403
- }
1404
- for (const layer of allLayerRules) {
1405
- parts.push(this.renderLayerRule(layer));
1406
- }
1407
- for (const rule of allRules) {
1408
- parts.push(this.renderRule(rule));
1409
- }
1410
- for (const supports of allSupportsRules) {
1411
- parts.push(this.renderSupportsRule(supports));
1412
- }
1413
- for (const container of allContainerRules) {
1414
- parts.push(this.renderContainerRule(container));
1415
- }
1416
- for (const media of allMediaRules) {
1417
- parts.push(this.renderMediaRule(media));
1418
- }
1419
- return parts.join("\n\n");
1420
- }
1421
- inject(styleId) {
1422
- const css = this.render();
1423
- const style2 = document.createElement("style");
1424
- if (styleId) style2.id = styleId;
1425
- style2.textContent = css;
1426
- document.head.appendChild(style2);
1427
- return style2;
1428
- }
1429
- clear() {
1430
- this.variables = [];
1431
- this.rules = [];
1432
- this.mediaRules = [];
1433
- this.keyframes = [];
1434
- this.fontFaces = [];
1435
- this.imports = [];
1436
- this.containerRules = [];
1437
- this.supportsRules = [];
1438
- this.layerRules = [];
1439
- this._layerOrder = [];
1440
- }
1441
- };
1442
-
1443
- // src/router.ts
1444
- function matchRoute(pattern, path) {
1445
- const patternParts = pattern.split("/").filter(Boolean);
1446
- const pathParts = path.split("/").filter(Boolean);
1447
- if (pattern.endsWith("*")) {
1448
- const basePattern = pattern.slice(0, -1);
1449
- if (path.startsWith(basePattern) || basePattern === "/" || pattern === "*") {
1450
- return { "*": path.slice(basePattern.length) };
1451
- }
1452
- }
1453
- if (patternParts.length !== pathParts.length) return null;
1454
- const params = {};
1455
- for (let i2 = 0; i2 < patternParts.length; i2++) {
1456
- const patternPart = patternParts[i2];
1457
- const pathPart = pathParts[i2];
1458
- if (patternPart.startsWith(":")) {
1459
- params[patternPart.slice(1)] = decodeURIComponent(pathPart);
1460
- } else if (patternPart !== pathPart) {
1461
- return null;
1462
- }
1463
- }
1464
- return params;
1465
- }
1466
- function createRouter(options) {
1467
- const { mode = "history", base: base2 = "", routes } = options;
1468
- const globalGuards = [];
1469
- const parseQuery = (search) => {
1470
- const query = {};
1471
- const params = new URLSearchParams(search);
1472
- params.forEach((value, key) => {
1473
- query[key] = value;
1474
- });
1475
- return query;
1476
- };
1477
- const getCurrentPath = () => {
1478
- if (mode === "hash") {
1479
- return window.location.hash.slice(1) || "/";
1480
- }
1481
- return window.location.pathname.replace(base2, "") || "/";
1482
- };
1483
- const parseLocation = (path) => {
1484
- const [pathPart, queryPart = ""] = path.split("?");
1485
- const [cleanPath, hash = ""] = pathPart.split("#");
1486
- return {
1487
- path: cleanPath || "/",
1488
- params: {},
1489
- query: parseQuery(queryPart),
1490
- hash: hash ? "#" + hash : ""
1491
- };
1492
- };
1493
- const findRoute = (path) => {
1494
- for (const route of routes) {
1495
- const params = matchRoute(route.path, path);
1496
- if (params !== null) {
1497
- return { route, params };
1498
- }
1499
- }
1500
- return null;
1501
- };
1502
- const currentRoute = domNode.createState(parseLocation(getCurrentPath()));
1503
- const navigate = (path, replace = false) => {
1504
- const location = parseLocation(path);
1505
- const match = findRoute(location.path);
1506
- if (match) {
1507
- location.params = match.params;
1508
- }
1509
- for (const guard of globalGuards) {
1510
- const result = guard(location, currentRoute.value);
1511
- if (result === false) return;
1512
- if (typeof result === "string") {
1513
- navigate(result, replace);
1514
- return;
1515
- }
1516
- }
1517
- if (match?.route.beforeEnter) {
1518
- const result = match.route.beforeEnter(location, currentRoute.value);
1519
- if (result === false) return;
1520
- if (typeof result === "string") {
1521
- navigate(result, replace);
1522
- return;
1523
- }
1524
- }
1525
- const url = mode === "hash" ? "#" + path : base2 + path;
1526
- if (replace) {
1527
- window.history.replaceState({ path }, "", url);
1528
- } else {
1529
- window.history.pushState({ path }, "", url);
1530
- }
1531
- currentRoute.value = location;
1532
- };
1533
- const handlePopState = () => {
1534
- const path = getCurrentPath();
1535
- const location = parseLocation(path);
1536
- const match = findRoute(location.path);
1537
- if (match) {
1538
- location.params = match.params;
1539
- }
1540
- currentRoute.value = location;
1541
- };
1542
- if (typeof window !== "undefined") {
1543
- window.addEventListener("popstate", handlePopState);
1544
- }
1545
- return {
1546
- currentRoute,
1547
- push: (path) => navigate(path, false),
1548
- replace: (path) => navigate(path, true),
1549
- back: () => window.history.back(),
1550
- forward: () => window.history.forward(),
1551
- go: (delta) => window.history.go(delta),
1552
- beforeEach: (guard) => {
1553
- globalGuards.push(guard);
1554
- },
1555
- destroy: () => {
1556
- if (typeof window !== "undefined") {
1557
- window.removeEventListener("popstate", handlePopState);
1558
- }
1559
- currentRoute.destroy();
1560
- }
1561
- };
1562
- }
1563
- function createRouterView(router, options) {
1564
- const { routes, notFound } = options;
1565
- return () => {
1566
- const location = router.currentRoute.value;
1567
- const match = routes.find((r) => matchRoute(r.path, location.path) !== null);
1568
- if (match) {
1569
- const params = matchRoute(match.path, location.path) || {};
1570
- const component = match.component({ ...params, ...location.query });
1571
- if (typeof component === "object" && component !== null && "tagName" in component) {
1572
- return component;
1573
- }
1574
- return { tagName: "span", props: {}, children: [component] };
1575
- }
1576
- if (notFound) {
1577
- const component = notFound(location.params);
1578
- if (typeof component === "object" && component !== null && "tagName" in component) {
1579
- return component;
1580
- }
1581
- return { tagName: "span", props: {}, children: [component] };
1582
- }
1583
- return { tagName: "div", props: {}, children: ["404 - Not Found"] };
1584
- };
1585
- }
1586
- var routerLink = (router, props, ...children) => {
1587
- return {
1588
- tagName: "a",
1589
- props: {
1590
- ...props,
1591
- href: props.to,
1592
- onclick: (e) => {
1593
- e.preventDefault();
1594
- router.push(props.to);
1595
- }
1596
- },
1597
- children
1598
- };
1599
- };
1600
-
1601
- // src/elements.ts
1602
- var createElementFactory = (tag) => {
1603
- return function(props, ...rest) {
1604
- if (arguments.length === 0) {
1605
- return { tagName: tag, props: {}, children: [] };
1606
- }
1607
- let actualProps = {};
1608
- let startIndex = 1;
1609
- const isState = props && typeof props === "object" && "value" in props && "subscribe" in props;
1610
- const isVNode = props && typeof props === "object" && "tagName" in props;
1611
- const isChild = typeof props !== "object" || Array.isArray(props) || props === null || isState || isVNode;
1612
- if (isChild) {
1613
- actualProps = {};
1614
- startIndex = 0;
1615
- } else {
1616
- actualProps = props;
1617
- }
1618
- const args = startIndex === 0 ? [props, ...rest] : rest;
1619
- if (args.length === 0) {
1620
- return { tagName: tag, props: actualProps, children: [] };
1621
- }
1622
- if (args.length === 1) {
1623
- const child = args[0];
1624
- if (child == null || child === false) {
1625
- return { tagName: tag, props: actualProps, children: [] };
1626
- }
1627
- if (Array.isArray(child)) {
1628
- const flatChildren2 = [];
1629
- const len = child.length;
1630
- for (let j = 0; j < len; j++) {
1631
- const c = child[j];
1632
- if (c != null && c !== false) {
1633
- flatChildren2.push(c);
1634
- }
1635
- }
1636
- return { tagName: tag, props: actualProps, children: flatChildren2 };
1637
- }
1638
- return { tagName: tag, props: actualProps, children: [child] };
1639
- }
1640
- const flatChildren = [];
1641
- for (let i2 = 0; i2 < args.length; i2++) {
1642
- const child = args[i2];
1643
- if (child == null || child === false) continue;
1644
- if (Array.isArray(child)) {
1645
- const len = child.length;
1646
- for (let j = 0; j < len; j++) {
1647
- const c = child[j];
1648
- if (c != null && c !== false) {
1649
- flatChildren.push(c);
1650
- }
1651
- }
1652
- } else {
1653
- flatChildren.push(child);
1654
- }
1655
- }
1656
- return { tagName: tag, props: actualProps, children: flatChildren };
1657
- };
1658
- };
1659
- var tags = [
1660
- "html",
1661
- "head",
1662
- "body",
1663
- "title",
1664
- "base",
1665
- "link",
1666
- "meta",
1667
- "style",
1668
- "address",
1669
- "article",
1670
- "aside",
1671
- "footer",
1672
- "header",
1673
- "h1",
1674
- "h2",
1675
- "h3",
1676
- "h4",
1677
- "h5",
1678
- "h6",
1679
- "main",
1680
- "nav",
1681
- "section",
1682
- "blockquote",
1683
- "dd",
1684
- "div",
1685
- "dl",
1686
- "dt",
1687
- "figcaption",
1688
- "figure",
1689
- "hr",
1690
- "li",
1691
- "ol",
1692
- "p",
1693
- "pre",
1694
- "ul",
1695
- "a",
1696
- "abbr",
1697
- "b",
1698
- "bdi",
1699
- "bdo",
1700
- "br",
1701
- "cite",
1702
- "code",
1703
- "data",
1704
- "dfn",
1705
- "em",
1706
- "i",
1707
- "kbd",
1708
- "mark",
1709
- "q",
1710
- "rp",
1711
- "rt",
1712
- "ruby",
1713
- "s",
1714
- "samp",
1715
- "small",
1716
- "span",
1717
- "strong",
1718
- "sub",
1719
- "sup",
1720
- "time",
1721
- "u",
1722
- "wbr",
1723
- "area",
1724
- "audio",
1725
- "img",
1726
- "map",
1727
- "track",
1728
- "video",
1729
- "embed",
1730
- "iframe",
1731
- "object",
1732
- "param",
1733
- "picture",
1734
- "portal",
1735
- "source",
1736
- "canvas",
1737
- "noscript",
1738
- "script",
1739
- "del",
1740
- "ins",
1741
- "caption",
1742
- "col",
1743
- "colgroup",
1744
- "table",
1745
- "tbody",
1746
- "td",
1747
- "tfoot",
1748
- "th",
1749
- "thead",
1750
- "tr",
1751
- "button",
1752
- "datalist",
1753
- "fieldset",
1754
- "form",
1755
- "input",
1756
- "label",
1757
- "legend",
1758
- "meter",
1759
- "optgroup",
1760
- "option",
1761
- "output",
1762
- "progress",
1763
- "select",
1764
- "textarea",
1765
- "details",
1766
- "dialog",
1767
- "menu",
1768
- "summary",
1769
- "slot",
1770
- "template"
1771
- ];
1772
- var svgTags = [
1773
- "svg",
1774
- "circle",
1775
- "rect",
1776
- "path",
1777
- "line",
1778
- "polyline",
1779
- "polygon",
1780
- "ellipse",
1781
- "g",
1782
- "text",
1783
- "tspan",
1784
- "defs",
1785
- "linearGradient",
1786
- "radialGradient",
1787
- "stop",
1788
- "pattern",
1789
- "mask",
1790
- "clipPath",
1791
- "use",
1792
- "symbol",
1793
- "marker",
1794
- "image",
1795
- "foreignObject",
1796
- "animate",
1797
- "animateTransform",
1798
- "animateMotion",
1799
- "set",
1800
- "filter",
1801
- "feBlend",
1802
- "feColorMatrix",
1803
- "feComponentTransfer",
1804
- "feComposite",
1805
- "feConvolveMatrix",
1806
- "feDiffuseLighting",
1807
- "feDisplacementMap",
1808
- "feFlood",
1809
- "feGaussianBlur",
1810
- "feMorphology",
1811
- "feOffset",
1812
- "feSpecularLighting",
1813
- "feTile",
1814
- "feTurbulence"
1815
- ];
1816
- var mathTags = [
1817
- "math",
1818
- "mi",
1819
- "mn",
1820
- "mo",
1821
- "ms",
1822
- "mtext",
1823
- "mrow",
1824
- "mfrac",
1825
- "msqrt",
1826
- "mroot",
1827
- "msub",
1828
- "msup"
1829
- ];
1830
- var elements = {};
1831
- tags.forEach((tag) => {
1832
- elements[tag] = createElementFactory(tag);
1833
- });
1834
- svgTags.forEach((tag) => {
1835
- const name = "svg" + tag.charAt(0).toUpperCase() + tag.slice(1);
1836
- elements[name] = createElementFactory(tag);
1837
- });
1838
- mathTags.forEach((tag) => {
1839
- const name = "math" + tag.charAt(0).toUpperCase() + tag.slice(1);
1840
- elements[name] = createElementFactory(tag);
1841
- });
1842
- elements.varElement = createElementFactory("var");
1843
- var {
1844
- html,
1845
- head,
1846
- body,
1847
- title,
1848
- base,
1849
- link,
1850
- meta,
1851
- style,
1852
- address,
1853
- article,
1854
- aside,
1855
- footer,
1856
- header,
1857
- h1,
1858
- h2,
1859
- h3,
1860
- h4,
1861
- h5,
1862
- h6,
1863
- main,
1864
- nav,
1865
- section,
1866
- blockquote,
1867
- dd,
1868
- div,
1869
- dl,
1870
- dt,
1871
- figcaption,
1872
- figure,
1873
- hr,
1874
- li,
1875
- ol,
1876
- p,
1877
- pre,
1878
- ul,
1879
- a,
1880
- abbr,
1881
- b,
1882
- bdi,
1883
- bdo,
1884
- br,
1885
- cite,
1886
- code,
1887
- data,
1888
- dfn,
1889
- em,
1890
- i,
1891
- kbd,
1892
- mark,
1893
- q,
1894
- rp,
1895
- rt,
1896
- ruby,
1897
- s,
1898
- samp,
1899
- small,
1900
- span,
1901
- strong,
1902
- sub,
1903
- sup,
1904
- time,
1905
- u,
1906
- wbr,
1907
- area,
1908
- audio,
1909
- img,
1910
- map,
1911
- track,
1912
- video,
1913
- embed,
1914
- iframe,
1915
- object,
1916
- param,
1917
- picture,
1918
- portal,
1919
- source,
1920
- canvas,
1921
- noscript,
1922
- script,
1923
- del,
1924
- ins,
1925
- caption,
1926
- col,
1927
- colgroup,
1928
- table,
1929
- tbody,
1930
- td,
1931
- tfoot,
1932
- th,
1933
- thead,
1934
- tr,
1935
- button,
1936
- datalist,
1937
- fieldset,
1938
- form,
1939
- input,
1940
- label,
1941
- legend,
1942
- meter,
1943
- optgroup,
1944
- option,
1945
- output,
1946
- progress,
1947
- select,
1948
- textarea,
1949
- details,
1950
- dialog,
1951
- menu,
1952
- summary,
1953
- slot,
1954
- template,
1955
- svgSvg,
1956
- svgCircle,
1957
- svgRect,
1958
- svgPath,
1959
- svgLine,
1960
- svgPolyline,
1961
- svgPolygon,
1962
- svgEllipse,
1963
- svgG,
1964
- svgText,
1965
- svgTspan,
1966
- svgDefs,
1967
- svgLinearGradient,
1968
- svgRadialGradient,
1969
- svgStop,
1970
- svgPattern,
1971
- svgMask,
1972
- svgClipPath,
1973
- svgUse,
1974
- svgSymbol,
1975
- svgMarker,
1976
- svgImage,
1977
- svgForeignObject,
1978
- svgAnimate,
1979
- svgAnimateTransform,
1980
- svgAnimateMotion,
1981
- svgSet,
1982
- svgFilter,
1983
- svgFeBlend,
1984
- svgFeColorMatrix,
1985
- svgFeComponentTransfer,
1986
- svgFeComposite,
1987
- svgFeConvolveMatrix,
1988
- svgFeDiffuseLighting,
1989
- svgFeDisplacementMap,
1990
- svgFeFlood,
1991
- svgFeGaussianBlur,
1992
- svgFeMorphology,
1993
- svgFeOffset,
1994
- svgFeSpecularLighting,
1995
- svgFeTile,
1996
- svgFeTurbulence,
1997
- mathMath,
1998
- mathMi,
1999
- mathMn,
2000
- mathMo,
2001
- mathMs,
2002
- mathMtext,
2003
- mathMrow,
2004
- mathMfrac,
2005
- mathMsqrt,
2006
- mathMroot,
2007
- mathMsub,
2008
- mathMsup,
2009
- varElement
2010
- } = elements;
2011
-
2012
- // src/index.ts
2013
- var renderToHead = (...vNodes) => domNode.renderToHead(...vNodes);
2014
- var addStyle = (css) => domNode.addStyle(css);
2015
- var addMeta = (attrs) => domNode.addMeta(attrs);
2016
- var addLink = (attrs) => domNode.addLink(attrs);
2017
- var setTitle = (text2) => domNode.setTitle(text2);
2018
- var renderToString = (vNode, options) => domNode.renderToString(vNode, options);
2019
- var jsonToVNode = (json) => domNode.jsonToVNode(json);
2020
- var renderJson = (container, json) => domNode.renderJson(container, json);
2021
- var renderJsonToString = (json, options) => domNode.renderJsonToString(json, options);
2022
- var vNodeJsonToVNode = (json) => domNode.vNodeJsonToVNode(json);
2023
- var renderVNode = (container, json) => domNode.renderVNode(container, json);
2024
- var renderVNodeToString = (json, options) => domNode.renderVNodeToString(json, options);
2025
- if (typeof window !== "undefined") {
2026
- Object.assign(window, {
2027
- domNode,
2028
- createElementFactory,
2029
- renderToHead,
2030
- addStyle,
2031
- addMeta,
2032
- addLink,
2033
- setTitle,
2034
- createState,
2035
- computed,
2036
- effect,
2037
- reactive,
2038
- reactiveAs,
2039
- text,
2040
- bindValue,
2041
- bindChecked,
2042
- batchRender,
2043
- renderChunked,
2044
- createVirtualList,
2045
- lazy,
2046
- cleanupUnused,
2047
- renderToString,
2048
- jsonToVNode,
2049
- renderJson,
2050
- renderJsonToString,
2051
- vNodeJsonToVNode,
2052
- renderVNode,
2053
- renderVNodeToString,
2054
- throttle,
2055
- debounce,
2056
- CreateStyle,
2057
- createRouter,
2058
- createRouterView,
2059
- routerLink,
2060
- ...elements
2061
- });
2062
- }
2063
- return __toCommonJS(index_exports);
2064
- })();