@arcmantle/lit-jsx 1.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 (119) hide show
  1. package/README.md +768 -0
  2. package/dist/compiler/attribute-processor.d.ts +128 -0
  3. package/dist/compiler/attribute-processor.d.ts.map +1 -0
  4. package/dist/compiler/attribute-processor.js +380 -0
  5. package/dist/compiler/attribute-processor.js.map +1 -0
  6. package/dist/compiler/babel-preset.d.ts +6 -0
  7. package/dist/compiler/babel-preset.d.ts.map +1 -0
  8. package/dist/compiler/babel-preset.js +27 -0
  9. package/dist/compiler/babel-preset.js.map +1 -0
  10. package/dist/compiler/builder.d.ts +22 -0
  11. package/dist/compiler/builder.d.ts.map +1 -0
  12. package/dist/compiler/builder.js +62 -0
  13. package/dist/compiler/builder.js.map +1 -0
  14. package/dist/compiler/compiler-utils.d.ts +81 -0
  15. package/dist/compiler/compiler-utils.d.ts.map +1 -0
  16. package/dist/compiler/compiler-utils.js +410 -0
  17. package/dist/compiler/compiler-utils.js.map +1 -0
  18. package/dist/compiler/config.d.ts +77 -0
  19. package/dist/compiler/config.d.ts.map +1 -0
  20. package/dist/compiler/config.js +78 -0
  21. package/dist/compiler/config.js.map +1 -0
  22. package/dist/compiler/postprocess.d.ts +5 -0
  23. package/dist/compiler/postprocess.d.ts.map +1 -0
  24. package/dist/compiler/postprocess.js +3 -0
  25. package/dist/compiler/postprocess.js.map +1 -0
  26. package/dist/compiler/preprocess.d.ts +5 -0
  27. package/dist/compiler/preprocess.d.ts.map +1 -0
  28. package/dist/compiler/preprocess.js +28 -0
  29. package/dist/compiler/preprocess.js.map +1 -0
  30. package/dist/compiler/transform-jsx.d.ts +5 -0
  31. package/dist/compiler/transform-jsx.d.ts.map +1 -0
  32. package/dist/compiler/transform-jsx.js +25 -0
  33. package/dist/compiler/transform-jsx.js.map +1 -0
  34. package/dist/compiler/transpiler.d.ts +48 -0
  35. package/dist/compiler/transpiler.d.ts.map +1 -0
  36. package/dist/compiler/transpiler.js +463 -0
  37. package/dist/compiler/transpiler.js.map +1 -0
  38. package/dist/compiler/vite-plugin.d.ts +38 -0
  39. package/dist/compiler/vite-plugin.d.ts.map +1 -0
  40. package/dist/compiler/vite-plugin.js +96 -0
  41. package/dist/compiler/vite-plugin.js.map +1 -0
  42. package/dist/runtime/choose-component.d.ts +39 -0
  43. package/dist/runtime/choose-component.d.ts.map +1 -0
  44. package/dist/runtime/choose-component.js +40 -0
  45. package/dist/runtime/choose-component.js.map +1 -0
  46. package/dist/runtime/compiler-ctors.d.ts +21 -0
  47. package/dist/runtime/compiler-ctors.d.ts.map +1 -0
  48. package/dist/runtime/compiler-ctors.js +21 -0
  49. package/dist/runtime/compiler-ctors.js.map +1 -0
  50. package/dist/runtime/for-component.d.ts +25 -0
  51. package/dist/runtime/for-component.d.ts.map +1 -0
  52. package/dist/runtime/for-component.js +35 -0
  53. package/dist/runtime/for-component.js.map +1 -0
  54. package/dist/runtime/literal-map.d.ts +22 -0
  55. package/dist/runtime/literal-map.d.ts.map +1 -0
  56. package/dist/runtime/literal-map.js +29 -0
  57. package/dist/runtime/literal-map.js.map +1 -0
  58. package/dist/runtime/rest-directive.d.ts +28 -0
  59. package/dist/runtime/rest-directive.d.ts.map +1 -0
  60. package/dist/runtime/rest-directive.js +49 -0
  61. package/dist/runtime/rest-directive.js.map +1 -0
  62. package/dist/runtime/show-component.d.ts +33 -0
  63. package/dist/runtime/show-component.d.ts.map +1 -0
  64. package/dist/runtime/show-component.js +30 -0
  65. package/dist/runtime/show-component.js.map +1 -0
  66. package/dist/runtime/tagged-template.d.ts +12 -0
  67. package/dist/runtime/tagged-template.d.ts.map +1 -0
  68. package/dist/runtime/tagged-template.js +12 -0
  69. package/dist/runtime/tagged-template.js.map +1 -0
  70. package/dist/runtime/type-helpers.d.ts +80 -0
  71. package/dist/runtime/type-helpers.d.ts.map +1 -0
  72. package/dist/runtime/type-helpers.js +85 -0
  73. package/dist/runtime/type-helpers.js.map +1 -0
  74. package/dist/shared/jsx-types.d.ts +2139 -0
  75. package/dist/shared/jsx-types.d.ts.map +1 -0
  76. package/dist/shared/jsx-types.js +2 -0
  77. package/dist/shared/jsx-types.js.map +1 -0
  78. package/dist/shared/jsx-utils.d.ts +30 -0
  79. package/dist/shared/jsx-utils.d.ts.map +1 -0
  80. package/dist/shared/jsx-utils.js +58 -0
  81. package/dist/shared/jsx-utils.js.map +1 -0
  82. package/dist/shared/mathml-tags.d.ts +12 -0
  83. package/dist/shared/mathml-tags.d.ts.map +1 -0
  84. package/dist/shared/mathml-tags.js +215 -0
  85. package/dist/shared/mathml-tags.js.map +1 -0
  86. package/dist/shared/svg-tags.d.ts +13 -0
  87. package/dist/shared/svg-tags.d.ts.map +1 -0
  88. package/dist/shared/svg-tags.js +95 -0
  89. package/dist/shared/svg-tags.js.map +1 -0
  90. package/dist/utils.d.ts +30 -0
  91. package/dist/utils.d.ts.map +1 -0
  92. package/dist/utils.js +30 -0
  93. package/dist/utils.js.map +1 -0
  94. package/package.json +52 -0
  95. package/src/compiler/attribute-processor.ts +579 -0
  96. package/src/compiler/babel-preset.ts +34 -0
  97. package/src/compiler/builder.ts +86 -0
  98. package/src/compiler/compiler-utils.ts +789 -0
  99. package/src/compiler/config.ts +77 -0
  100. package/src/compiler/postprocess.ts +7 -0
  101. package/src/compiler/preprocess.ts +40 -0
  102. package/src/compiler/transform-jsx.ts +36 -0
  103. package/src/compiler/transpiler.ts +644 -0
  104. package/src/compiler/vite-plugin.ts +114 -0
  105. package/src/external.d.ts +9 -0
  106. package/src/runtime/choose-component.ts +53 -0
  107. package/src/runtime/compiler-ctors.ts +28 -0
  108. package/src/runtime/for-component.ts +54 -0
  109. package/src/runtime/literal-map.ts +37 -0
  110. package/src/runtime/rest-directive.ts +66 -0
  111. package/src/runtime/show-component.ts +48 -0
  112. package/src/runtime/tagged-template.ts +11 -0
  113. package/src/runtime/type-helpers.ts +91 -0
  114. package/src/shared/jsx-types.ts +2556 -0
  115. package/src/shared/jsx-utils.ts +85 -0
  116. package/src/shared/mathml-tags.ts +235 -0
  117. package/src/shared/svg-tags.ts +103 -0
  118. package/src/tsconfig.json +4 -0
  119. package/src/utils.ts +30 -0
@@ -0,0 +1,85 @@
1
+ import type { AttributePart, BooleanAttributePart, ChildPart, ElementPart, EventPart, PropertyPart } from 'lit-html';
2
+ import { html, render } from 'lit-html';
3
+ import type { PartInfo } from 'lit-html/directive.js';
4
+ import { Directive, directive, PartType } from 'lit-html/directive.js';
5
+
6
+
7
+ export interface LitPartConstructors {
8
+ AttributePart: typeof AttributePart;
9
+ PropertyPart: typeof PropertyPart;
10
+ BooleanPart: typeof BooleanAttributePart;
11
+ EventPart: typeof EventPart;
12
+ ChildPart: typeof ChildPart;
13
+ ElementPart: typeof ElementPart;
14
+ }
15
+
16
+
17
+ /**
18
+ * Template tag function marker for jsx-lit React compatibility mode.
19
+ *
20
+ * This function serves the same purpose as __$t but for React JSX transform mode.
21
+ * It's an identity function that marks template literals for jsx-lit processing.
22
+ *
23
+ * @param strings - Template strings array from template literal
24
+ * @returns The same template strings array unchanged
25
+ */
26
+ export const __ttl: (strings: TemplateStringsArray) => TemplateStringsArray = s => s;
27
+
28
+
29
+ /**
30
+ * Lazy-initialized function that extracts lit-html part constructors.
31
+ *
32
+ * This function uses a clever technique to extract the internal part constructors
33
+ * from lit-html by creating temporary directives and examining their part types.
34
+ * This is necessary for jsx-lit's compile-time optimizations.
35
+ *
36
+ * @returns Object containing all lit-html part constructors
37
+ */
38
+ export const getLitParts: () => LitPartConstructors = (() => {
39
+ let hasRun = false;
40
+
41
+ const constructors = {
42
+ AttributePart: undefined,
43
+ PropertyPart: undefined,
44
+ BooleanPart: undefined,
45
+ EventPart: undefined,
46
+ ChildPart: undefined,
47
+ ElementPart: undefined,
48
+ } satisfies Record<keyof LitPartConstructors, undefined> as
49
+ any as LitPartConstructors;
50
+
51
+ const partCtorGrabber: any = directive(class PartCtorGrabber extends Directive {
52
+
53
+ constructor(part: PartInfo) {
54
+ super(part);
55
+
56
+ if (part.type === PartType.BOOLEAN_ATTRIBUTE)
57
+ constructors.BooleanPart = part.constructor as typeof BooleanAttributePart;
58
+ else if (part.type === PartType.ATTRIBUTE)
59
+ constructors.AttributePart = part.constructor as typeof AttributePart;
60
+ else if (part.type === PartType.PROPERTY)
61
+ constructors.PropertyPart = part.constructor as typeof PropertyPart;
62
+ else if (part.type === PartType.ELEMENT)
63
+ constructors.ElementPart = part.constructor as typeof ElementPart;
64
+ else if (part.type === PartType.EVENT)
65
+ constructors.EventPart = part.constructor as typeof EventPart;
66
+ else if (part.type === PartType.CHILD)
67
+ constructors.ChildPart = part.constructor as typeof ChildPart;
68
+ }
69
+
70
+ override render(): void {}
71
+
72
+ });
73
+
74
+ return () => {
75
+ if (!hasRun) {
76
+ const g = partCtorGrabber;
77
+ hasRun = !!render(
78
+ html`<div ${ g() } prop=${ g() } .prop=${ g() } ?prop=${ g() } @prop=${ g() }>${ g() }</div>`,
79
+ document.createElement('div'),
80
+ );
81
+ }
82
+
83
+ return constructors;
84
+ };
85
+ })();
@@ -0,0 +1,235 @@
1
+ /* cspell:disable */
2
+
3
+ /**
4
+ * A comprehensive set of all MathML tag names.
5
+ * This includes current and deprecated MathML elements from the MathML specification.
6
+ */
7
+ export const mathmlTags: Set<string> = new Set([
8
+ // Token Elements
9
+ 'mi', // identifier
10
+ 'mn', // number
11
+ 'mo', // operator
12
+ 'mtext', // text
13
+ 'mspace', // space
14
+ 'ms', // string literal
15
+
16
+ // General Layout Elements
17
+ 'mrow', // horizontal group of sub-expressions
18
+ 'mfrac', // fraction
19
+ 'msqrt', // square root
20
+ 'mroot', // nth root
21
+ 'mstyle', // style change
22
+ 'merror', // error message
23
+ 'mpadded', // adjust spacing
24
+ 'mphantom', // make content invisible but preserve spacing
25
+ 'mfenced', // surround content with fences
26
+ 'menclose', // enclose content with stretching symbols
27
+
28
+ // Script and Limit Elements
29
+ 'msub', // subscript
30
+ 'msup', // superscript
31
+ 'msubsup', // subscript-superscript pair
32
+ 'munder', // underscript
33
+ 'mover', // overscript
34
+ 'munderover', // underscript-overscript pair
35
+ 'mmultiscripts', // prescripts and tensor indices
36
+
37
+ // Tabular Math Elements
38
+ 'mtable', // table
39
+ 'mtr', // table row
40
+ 'mtd', // table cell
41
+ 'maligngroup', // alignment group
42
+ 'malignmark', // alignment point
43
+
44
+ // Elementary Math Elements (MathML 3)
45
+ 'mstack', // stacked notation
46
+ 'mlongdiv', // long division notation
47
+ 'msgroup', // group of rows in mstack
48
+ 'msrow', // row of digits
49
+ 'mscarries', // carries row
50
+ 'mscarry', // carry digit
51
+ 'msline', // horizontal line
52
+
53
+ // Action Elements
54
+ 'maction', // bind actions to sub-expressions
55
+
56
+ // Annotation Elements
57
+ 'semantics', // semantic annotation
58
+ 'annotation', // annotation
59
+ 'annotation-xml', // XML annotation
60
+
61
+ // Content Elements (Content MathML)
62
+ 'apply', // function application
63
+ 'bind', // binding constructor
64
+ 'bvar', // bound variable
65
+ 'condition', // condition
66
+ 'declare', // declaration
67
+ 'lambda', // lambda expression
68
+ 'piecewise', // piecewise function
69
+ 'piece', // piece of piecewise function
70
+ 'otherwise', // default case
71
+
72
+ // Arithmetic, Algebra, and Logic Operators
73
+ 'plus',
74
+ 'minus',
75
+ 'times',
76
+ 'divide',
77
+ 'power',
78
+ 'rem',
79
+ 'quotient',
80
+ 'factorial',
81
+ 'abs',
82
+ 'conjugate',
83
+ 'arg',
84
+ 'real',
85
+ 'imaginary',
86
+ 'floor',
87
+ 'ceiling',
88
+ 'exp',
89
+ 'ln',
90
+ 'log',
91
+ 'sin',
92
+ 'cos',
93
+ 'tan',
94
+ 'sec',
95
+ 'csc',
96
+ 'cot',
97
+ 'sinh',
98
+ 'cosh',
99
+ 'tanh',
100
+ 'sech',
101
+ 'csch',
102
+ 'coth',
103
+ 'arcsin',
104
+ 'arccos',
105
+ 'arctan',
106
+ 'arcsec',
107
+ 'arccsc',
108
+ 'arccot',
109
+ 'arcsinh',
110
+ 'arccosh',
111
+ 'arctanh',
112
+ 'arcsech',
113
+ 'arccsch',
114
+ 'arccoth',
115
+ 'root',
116
+ 'gcd',
117
+ 'lcm',
118
+ 'max',
119
+ 'min',
120
+ 'sum',
121
+ 'product',
122
+ 'limit',
123
+ 'mean',
124
+ 'sdev',
125
+ 'variance',
126
+ 'median',
127
+ 'mode',
128
+ 'moment',
129
+ 'momentabout',
130
+ 'and',
131
+ 'or',
132
+ 'xor',
133
+ 'not',
134
+ 'implies',
135
+ 'forall',
136
+ 'exists',
137
+
138
+ // Relations
139
+ 'eq',
140
+ 'neq',
141
+ 'gt',
142
+ 'lt',
143
+ 'geq',
144
+ 'leq',
145
+ 'equivalent',
146
+ 'approx',
147
+ 'factorof',
148
+ 'tendsto',
149
+
150
+ // Calculus and Vector Calculus
151
+ 'int',
152
+ 'diff',
153
+ 'partialdiff',
154
+ 'grad',
155
+ 'curl',
156
+ 'divergence',
157
+ 'laplacian',
158
+
159
+ // Theory of Sets
160
+ 'set',
161
+ 'list',
162
+ 'union',
163
+ 'intersect',
164
+ 'in',
165
+ 'notin',
166
+ 'subset',
167
+ 'prsubset',
168
+ 'notsubset',
169
+ 'notprsubset',
170
+ 'setdiff',
171
+ 'card',
172
+ 'cartesianproduct',
173
+
174
+ // Sequences and Series
175
+ 'lowlimit',
176
+ 'uplimit',
177
+ 'interval',
178
+
179
+ // Trigonometry
180
+ 'inverse',
181
+
182
+ // Statistics
183
+ 'vector',
184
+ 'matrix',
185
+ 'matrixrow',
186
+ 'determinant',
187
+ 'transpose',
188
+ 'selector',
189
+ 'vectorproduct',
190
+ 'scalarproduct',
191
+ 'outerproduct',
192
+
193
+ // Constants
194
+ 'integers',
195
+ 'reals',
196
+ 'rationals',
197
+ 'naturalnumbers',
198
+ 'complexes',
199
+ 'primes',
200
+ 'exponentiale',
201
+ 'imaginaryi',
202
+ 'notanumber',
203
+ 'true',
204
+ 'false',
205
+ 'emptyset',
206
+ 'pi',
207
+ 'eulergamma',
208
+ 'infinity',
209
+
210
+ // Linear Algebra
211
+ 'ident',
212
+
213
+ // Semantic Mapping Elements
214
+ 'csymbol',
215
+ 'cn', // content number
216
+ 'ci', // content identifier
217
+ 'cs', // content string
218
+
219
+ // Deprecated Elements
220
+ 'reln', // deprecated
221
+ 'fn', // deprecated
222
+ 'domainofapplication', // deprecated
223
+ 'sep', // deprecated
224
+
225
+ // Experimental/Less Common Elements
226
+ 'mlabeledtr', // labeled table row
227
+ 'mglyph', // glyph
228
+ ]);
229
+
230
+ /**
231
+ * Check if a given tag name is a MathML tag.
232
+ * @param tagName - The tag name to check
233
+ * @returns true if the tag is a MathML tag, false otherwise
234
+ */
235
+ export const isMathmlTag = (tagName: string): boolean => mathmlTags.has(tagName);
@@ -0,0 +1,103 @@
1
+ /** cspell: disable */
2
+
3
+ /**
4
+ * A comprehensive set of all SVG tag names.
5
+ * This includes current and deprecated SVG elements from the SVG specification.
6
+ */
7
+ export const svgTags: Set<string> = new Set([
8
+ // Structure and Container Elements
9
+ 'g',
10
+ 'defs',
11
+ 'use',
12
+ 'symbol',
13
+ 'marker',
14
+ 'clipPath',
15
+ 'mask',
16
+ 'pattern',
17
+ 'image',
18
+ 'switch',
19
+ 'foreignObject',
20
+
21
+ // Shape Elements
22
+ 'rect',
23
+ 'circle',
24
+ 'ellipse',
25
+ 'line',
26
+ 'polyline',
27
+ 'polygon',
28
+ 'path',
29
+
30
+ // Text Elements
31
+ 'text',
32
+ 'tspan',
33
+ 'tref', // deprecated
34
+ 'textPath',
35
+ 'altGlyph', // deprecated
36
+ 'altGlyphDef', // deprecated
37
+ 'altGlyphItem', // deprecated
38
+ 'glyph', // deprecated
39
+ 'glyphRef', // deprecated
40
+
41
+ // Gradient Elements
42
+ 'linearGradient',
43
+ 'radialGradient',
44
+ 'meshGradient',
45
+ 'meshPatch',
46
+ 'meshRow',
47
+ 'stop',
48
+
49
+ // Animation Elements
50
+ 'animate',
51
+ 'animateMotion',
52
+ 'animateTransform',
53
+ 'animateColor', // deprecated
54
+ 'set',
55
+ 'mpath',
56
+
57
+ // Filter Elements
58
+ 'filter',
59
+ 'feBlend',
60
+ 'feColorMatrix',
61
+ 'feComponentTransfer',
62
+ 'feComposite',
63
+ 'feConvolveMatrix',
64
+ 'feDiffuseLighting',
65
+ 'feDisplacementMap',
66
+ 'feDistantLight',
67
+ 'feDropShadow',
68
+ 'feFlood',
69
+ 'feFuncA',
70
+ 'feFuncB',
71
+ 'feFuncG',
72
+ 'feFuncR',
73
+ 'feGaussianBlur',
74
+ 'feImage',
75
+ 'feMerge',
76
+ 'feMergeNode',
77
+ 'feMorphology',
78
+ 'feOffset',
79
+ 'fePointLight',
80
+ 'feSpecularLighting',
81
+ 'feSpotLight',
82
+ 'feTile',
83
+ 'feTurbulence',
84
+
85
+ // Font Elements (mostly deprecated)
86
+ 'font', // deprecated
87
+ 'font-face', // deprecated
88
+ 'font-face-format', // deprecated
89
+ 'font-face-name', // deprecated
90
+ 'font-face-src', // deprecated
91
+ 'font-face-uri', // deprecated
92
+ 'hkern', // deprecated
93
+ 'vkern', // deprecated
94
+ 'missing-glyph', // deprecated
95
+ ]);
96
+
97
+
98
+ /**
99
+ * Check if a given tag name is an SVG tag.
100
+ * @param tagName - The tag name to check
101
+ * @returns true if the tag is an SVG tag, false otherwise
102
+ */
103
+ export const isSvgTag = (tagName: string): boolean => svgTags.has(tagName);
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "@arcmantle/tsconfig/build",
3
+ "compilerOptions": {}
4
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @fileoverview Main entrypoint for jsx-lit runtime utilities and components.
3
+ *
4
+ * This module provides all the runtime utilities needed for jsx-lit compiled templates,
5
+ * including helper components for conditional rendering, iteration, and template composition.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { Choose, For, Show } from "@arcmantle/lit-jsx";
10
+ *
11
+ * function MyComponent() {
12
+ * return (
13
+ * <div>
14
+ * <Show when={condition}>
15
+ * <p>Conditionally rendered content</p>
16
+ * </Show>
17
+ * </div>
18
+ * );
19
+ * }
20
+ * ```
21
+ */
22
+
23
+ export * from './runtime/choose-component.js';
24
+ export * from './runtime/compiler-ctors.js';
25
+ export * from './runtime/for-component.js';
26
+ export * from './runtime/literal-map.js';
27
+ export * from './runtime/rest-directive.js';
28
+ export * from './runtime/show-component.js';
29
+ export * from './runtime/tagged-template.js';
30
+ export * from './runtime/type-helpers.js';