elit 3.0.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/build.d.ts +4 -12
  2. package/dist/build.d.ts.map +1 -0
  3. package/dist/chokidar.d.ts +7 -9
  4. package/dist/chokidar.d.ts.map +1 -0
  5. package/dist/cli.d.ts +6 -0
  6. package/dist/cli.d.ts.map +1 -0
  7. package/dist/cli.js +17 -4
  8. package/dist/config.d.ts +29 -0
  9. package/dist/config.d.ts.map +1 -0
  10. package/dist/dom.d.ts +7 -14
  11. package/dist/dom.d.ts.map +1 -0
  12. package/dist/el.d.ts +19 -191
  13. package/dist/el.d.ts.map +1 -0
  14. package/dist/fs.d.ts +35 -35
  15. package/dist/fs.d.ts.map +1 -0
  16. package/dist/hmr.d.ts +3 -3
  17. package/dist/hmr.d.ts.map +1 -0
  18. package/dist/http.d.ts +20 -22
  19. package/dist/http.d.ts.map +1 -0
  20. package/dist/https.d.ts +12 -15
  21. package/dist/https.d.ts.map +1 -0
  22. package/dist/index.d.ts +10 -629
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/mime-types.d.ts +9 -9
  25. package/dist/mime-types.d.ts.map +1 -0
  26. package/dist/path.d.ts +22 -19
  27. package/dist/path.d.ts.map +1 -0
  28. package/dist/router.d.ts +10 -17
  29. package/dist/router.d.ts.map +1 -0
  30. package/dist/runtime.d.ts +5 -6
  31. package/dist/runtime.d.ts.map +1 -0
  32. package/dist/server.d.ts +105 -7
  33. package/dist/server.d.ts.map +1 -0
  34. package/dist/server.js +14 -2
  35. package/dist/server.mjs +14 -2
  36. package/dist/state.d.ts +21 -27
  37. package/dist/state.d.ts.map +1 -0
  38. package/dist/style.d.ts +14 -55
  39. package/dist/style.d.ts.map +1 -0
  40. package/dist/types.d.ts +26 -240
  41. package/dist/types.d.ts.map +1 -0
  42. package/dist/ws.d.ts +14 -17
  43. package/dist/ws.d.ts.map +1 -0
  44. package/dist/wss.d.ts +16 -16
  45. package/dist/wss.d.ts.map +1 -0
  46. package/package.json +3 -2
  47. package/src/build.ts +337 -0
  48. package/src/chokidar.ts +401 -0
  49. package/src/cli.ts +638 -0
  50. package/src/config.ts +205 -0
  51. package/src/dom.ts +817 -0
  52. package/src/el.ts +164 -0
  53. package/src/fs.ts +727 -0
  54. package/src/hmr.ts +137 -0
  55. package/src/http.ts +775 -0
  56. package/src/https.ts +411 -0
  57. package/src/index.ts +14 -0
  58. package/src/mime-types.ts +222 -0
  59. package/src/path.ts +493 -0
  60. package/src/router.ts +237 -0
  61. package/src/runtime.ts +97 -0
  62. package/src/server.ts +1290 -0
  63. package/src/state.ts +468 -0
  64. package/src/style.ts +524 -0
  65. package/{dist/types-Du6kfwTm.d.ts → src/types.ts} +58 -141
  66. package/src/ws.ts +506 -0
  67. package/src/wss.ts +241 -0
  68. package/dist/build.d.mts +0 -20
  69. package/dist/chokidar.d.mts +0 -134
  70. package/dist/dom.d.mts +0 -87
  71. package/dist/el.d.mts +0 -207
  72. package/dist/fs.d.mts +0 -255
  73. package/dist/hmr.d.mts +0 -38
  74. package/dist/http.d.mts +0 -163
  75. package/dist/https.d.mts +0 -108
  76. package/dist/index.d.mts +0 -629
  77. package/dist/mime-types.d.mts +0 -48
  78. package/dist/path.d.mts +0 -163
  79. package/dist/router.d.mts +0 -47
  80. package/dist/runtime.d.mts +0 -97
  81. package/dist/server.d.mts +0 -7
  82. package/dist/state.d.mts +0 -111
  83. package/dist/style.d.mts +0 -159
  84. package/dist/types-C0nGi6MX.d.mts +0 -346
  85. package/dist/types.d.mts +0 -452
  86. package/dist/ws.d.mts +0 -195
  87. package/dist/wss.d.mts +0 -108
package/src/el.ts ADDED
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Elit - Element Factories
3
+ */
4
+
5
+ import type { VNode, Child, Props, ElementFactory } from './types';
6
+
7
+ /**
8
+ * Helper: Check if document is available (eliminates duplication in document checks)
9
+ */
10
+ const hasDocument = typeof document !== 'undefined';
11
+
12
+ /**
13
+ * Helper: Capitalize first letter (eliminates duplication in tag name processing)
14
+ */
15
+ function capitalize(str: string): string {
16
+ return str.charAt(0).toUpperCase() + str.slice(1);
17
+ }
18
+
19
+ /**
20
+ * Helper: Bind document method safely (eliminates duplication in document method binding)
21
+ */
22
+ function bindDocMethod<T extends Function>(method: T | undefined): T | undefined {
23
+ return hasDocument && method ? method.bind(doc) : undefined as any;
24
+ }
25
+
26
+ /**
27
+ * Helper: Create prefixed element factories (eliminates duplication in factory creation)
28
+ */
29
+ function createPrefixedFactories(tags: readonly string[], prefix: string, elements: any): void {
30
+ tags.forEach(tag => {
31
+ const name = prefix + capitalize(tag);
32
+ elements[name] = createElementFactory(tag);
33
+ });
34
+ }
35
+
36
+ export const createElementFactory = (tag: string): ElementFactory => {
37
+ return function(props?: Props | Child | null, ...rest: Child[]): VNode {
38
+ if (!arguments.length) return { tagName: tag, props: {}, children: [] };
39
+
40
+ const isState = props && typeof props === 'object' && 'value' in props && 'subscribe' in props;
41
+ const isVNode = props && typeof props === 'object' && 'tagName' in props;
42
+ const isChild = typeof props !== 'object' || Array.isArray(props) || props === null || isState || isVNode;
43
+
44
+ const actualProps: Props = isChild ? {} : props as Props;
45
+ const args: Child[] = isChild ? [props as Child, ...rest] : rest;
46
+
47
+ if (!args.length) return { tagName: tag, props: actualProps, children: [] };
48
+
49
+ const flatChildren: Child[] = [];
50
+ for (let i = 0, len = args.length; i < len; i++) {
51
+ const child = args[i];
52
+ if (child == null || child === false) continue;
53
+
54
+ if (Array.isArray(child)) {
55
+ for (let j = 0, cLen = child.length; j < cLen; j++) {
56
+ const c = child[j];
57
+ c != null && c !== false && flatChildren.push(c);
58
+ }
59
+ } else {
60
+ flatChildren.push(child);
61
+ }
62
+ }
63
+
64
+ return { tagName: tag, props: actualProps, children: flatChildren };
65
+ } as ElementFactory;
66
+ };
67
+
68
+ // HTML Tags
69
+ const tags = [
70
+ 'html', 'head', 'body', 'title', 'base', 'link', 'meta', 'style',
71
+ 'address', 'article', 'aside', 'footer', 'header', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'main', 'nav', 'section',
72
+ 'blockquote', 'dd', 'div', 'dl', 'dt', 'figcaption', 'figure', 'hr', 'li', 'ol', 'p', 'pre', 'ul',
73
+ 'a', 'abbr', 'b', 'bdi', 'bdo', 'br', 'cite', 'code', 'data', 'dfn', 'em', 'i', 'kbd', 'mark', 'q',
74
+ 'rp', 'rt', 'ruby', 's', 'samp', 'small', 'span', 'strong', 'sub', 'sup', 'time', 'u', 'wbr',
75
+ 'area', 'audio', 'img', 'map', 'track', 'video',
76
+ 'embed', 'iframe', 'object', 'param', 'picture', 'portal', 'source',
77
+ 'canvas', 'noscript', 'script',
78
+ 'del', 'ins',
79
+ 'caption', 'col', 'colgroup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr',
80
+ 'button', 'datalist', 'fieldset', 'form', 'input', 'label', 'legend', 'meter',
81
+ 'optgroup', 'option', 'output', 'progress', 'select', 'textarea',
82
+ 'details', 'dialog', 'menu', 'summary',
83
+ 'slot', 'template'
84
+ ] as const;
85
+
86
+ // SVG Tags
87
+ const svgTags = [
88
+ 'svg', 'circle', 'rect', 'path', 'line', 'polyline', 'polygon', 'ellipse', 'g', 'text', 'tspan',
89
+ 'defs', 'linearGradient', 'radialGradient', 'stop', 'pattern', 'mask', 'clipPath', 'use', 'symbol',
90
+ 'marker', 'image', 'foreignObject', 'animate', 'animateTransform', 'animateMotion', 'set', 'filter',
91
+ 'feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting',
92
+ 'feDisplacementMap', 'feFlood', 'feGaussianBlur', 'feMorphology', 'feOffset', 'feSpecularLighting',
93
+ 'feTile', 'feTurbulence'
94
+ ] as const;
95
+
96
+ // MathML Tags
97
+ const mathTags = [
98
+ 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'mrow', 'mfrac', 'msqrt', 'mroot', 'msub', 'msup'
99
+ ] as const;
100
+
101
+ type Elements = {
102
+ [K in typeof tags[number]]: ElementFactory;
103
+ } & {
104
+ [K in typeof svgTags[number] as `svg${Capitalize<K>}`]: ElementFactory;
105
+ } & {
106
+ [K in typeof mathTags[number] as `math${Capitalize<K>}`]: ElementFactory;
107
+ } & {
108
+ varElement: ElementFactory;
109
+ };
110
+
111
+ const elements: Partial<Elements> = {};
112
+
113
+ tags.forEach(tag => {
114
+ (elements as any)[tag] = createElementFactory(tag);
115
+ });
116
+
117
+ createPrefixedFactories(svgTags, 'svg', elements);
118
+ createPrefixedFactories(mathTags, 'math', elements);
119
+
120
+ (elements as any).varElement = createElementFactory('var');
121
+
122
+ // Export all element factories
123
+ export const {
124
+ html, head, body, title, base, link, meta, style,
125
+ address, article, aside, footer, header, h1, h2, h3, h4, h5, h6, main, nav, section,
126
+ blockquote, dd, div, dl, dt, figcaption, figure, hr, li, ol, p, pre, ul,
127
+ a, abbr, b, bdi, bdo, br, cite, code, data, dfn, em, i, kbd, mark, q,
128
+ rp, rt, ruby, s, samp, small, span, strong, sub, sup, time, u, wbr,
129
+ area, audio, img, map, track, video,
130
+ embed, iframe, object, param, picture, portal, source,
131
+ canvas, noscript, script,
132
+ del, ins,
133
+ caption, col, colgroup, table, tbody, td, tfoot, th, thead, tr,
134
+ button, datalist, fieldset, form, input, label, legend, meter,
135
+ optgroup, option, output, progress, select, textarea,
136
+ details, dialog, menu, summary,
137
+ slot, template,
138
+ svgSvg, svgCircle, svgRect, svgPath, svgLine, svgPolyline, svgPolygon, svgEllipse, svgG, svgText, svgTspan,
139
+ svgDefs, svgLinearGradient, svgRadialGradient, svgStop, svgPattern, svgMask, svgClipPath, svgUse, svgSymbol,
140
+ svgMarker, svgImage, svgForeignObject, svgAnimate, svgAnimateTransform, svgAnimateMotion, svgSet, svgFilter,
141
+ svgFeBlend, svgFeColorMatrix, svgFeComponentTransfer, svgFeComposite, svgFeConvolveMatrix, svgFeDiffuseLighting,
142
+ svgFeDisplacementMap, svgFeFlood, svgFeGaussianBlur, svgFeMorphology, svgFeOffset, svgFeSpecularLighting,
143
+ svgFeTile, svgFeTurbulence,
144
+ mathMath, mathMi, mathMn, mathMo, mathMs, mathMtext, mathMrow, mathMfrac, mathMsqrt, mathMroot, mathMsub, mathMsup,
145
+ varElement
146
+ } = elements as Elements;
147
+ export const el = elements;
148
+ // Export elements object for dynamic access
149
+ export { elements };
150
+
151
+ // DOM utility functions - Shorthand helpers for common document operations
152
+ export const doc = hasDocument ? document : undefined as any;
153
+ export const getEl = bindDocMethod(doc?.querySelector);
154
+ export const getEls = bindDocMethod(doc?.querySelectorAll);
155
+ export const createEl = bindDocMethod(doc?.createElement);
156
+ export const createSvgEl = hasDocument ? doc.createElementNS.bind(doc, 'http://www.w3.org/2000/svg') : undefined as any;
157
+ export const createMathEl = hasDocument ? doc.createElementNS.bind(doc, 'http://www.w3.org/1998/Math/MathML') : undefined as any;
158
+ export const fragment = bindDocMethod(doc?.createDocumentFragment);
159
+ export const textNode = bindDocMethod(doc?.createTextNode);
160
+ export const commentNode = bindDocMethod(doc?.createComment);
161
+ export const getElId = bindDocMethod(doc?.getElementById);
162
+ export const getElClass = bindDocMethod(doc?.getElementsByClassName);
163
+ export const getElTag = bindDocMethod(doc?.getElementsByTagName);
164
+ export const getElName = bindDocMethod(doc?.getElementsByName);