@tempots/dom 5.0.0 → 5.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 (193) hide show
  1. package/README.md +1 -0
  2. package/clean.d.ts +2 -0
  3. package/clean.js +1 -0
  4. package/components/Attribute.d.ts +15 -0
  5. package/components/Attribute.js +16 -0
  6. package/components/BooleanAttribute.d.ts +15 -0
  7. package/components/BooleanAttribute.js +16 -0
  8. package/components/ClassName.d.ts +13 -0
  9. package/components/ClassName.js +14 -0
  10. package/components/El.d.ts +15 -0
  11. package/components/El.js +21 -0
  12. package/components/FadeIn.d.ts +18 -0
  13. package/components/FadeIn.js +52 -0
  14. package/components/FadeOut.d.ts +16 -0
  15. package/components/FadeOut.js +39 -0
  16. package/components/For.d.ts +7 -0
  17. package/components/For.js +15 -0
  18. package/components/Fragment.d.ts +12 -0
  19. package/components/Fragment.js +16 -0
  20. package/components/HiddenWhenEmpty.d.ts +7 -0
  21. package/components/HiddenWhenEmpty.js +12 -0
  22. package/components/If.d.ts +14 -0
  23. package/components/If.js +19 -0
  24. package/components/InnerHTML.d.ts +13 -0
  25. package/components/InnerHTML.js +23 -0
  26. package/components/Lifecycle.d.ts +14 -0
  27. package/components/Lifecycle.js +18 -0
  28. package/components/Match.d.ts +33 -0
  29. package/components/Match.js +44 -0
  30. package/components/NotEmpty.d.ts +10 -0
  31. package/components/NotEmpty.js +11 -0
  32. package/components/On.d.ts +15 -0
  33. package/components/On.js +14 -0
  34. package/components/OnRemove.d.ts +11 -0
  35. package/components/OnRemove.js +14 -0
  36. package/components/OneOf.d.ts +20 -0
  37. package/components/OneOf.js +45 -0
  38. package/components/Portal.d.ts +15 -0
  39. package/components/Portal.js +20 -0
  40. package/components/Property.d.ts +15 -0
  41. package/components/Property.js +16 -0
  42. package/components/Provider.d.ts +28 -0
  43. package/components/Provider.js +44 -0
  44. package/components/Repeat.d.ts +15 -0
  45. package/components/Repeat.js +33 -0
  46. package/components/Shadow.d.ts +0 -0
  47. package/components/Shadow.js +1 -0
  48. package/components/Show.d.ts +20 -0
  49. package/components/Show.js +22 -0
  50. package/components/Text.d.ts +15 -0
  51. package/components/Text.js +33 -0
  52. package/components/TextContent.d.ts +13 -0
  53. package/components/TextContent.js +23 -0
  54. package/components/Tween.d.ts +75 -0
  55. package/components/Tween.js +242 -0
  56. package/components/animatable.d.ts +53 -0
  57. package/components/animatable.js +156 -0
  58. package/dom-context.d.ts +38 -0
  59. package/dom-context.js +260 -0
  60. package/helpers/handle-anchor-click.d.ts +4 -0
  61. package/helpers/handle-anchor-click.js +43 -0
  62. package/helpers/handle-text-input.d.ts +1 -0
  63. package/helpers/handle-text-input.js +4 -0
  64. package/helpers/is-empty-element.d.ts +2 -0
  65. package/helpers/is-empty-element.js +8 -0
  66. package/index.d.ts +36 -0
  67. package/jsx-dev-runtime.d.ts +1 -0
  68. package/jsx-dev-runtime.js +1 -0
  69. package/jsx-runtime.d.ts +9 -0
  70. package/jsx-runtime.js +157 -0
  71. package/jsx.d.ts +806 -0
  72. package/jsx.js +1 -0
  73. package/package.json +5 -3
  74. package/prop.d.ts +43 -0
  75. package/prop.js +174 -0
  76. package/render.d.ts +3 -0
  77. package/render.js +7 -0
  78. package/renderable.d.ts +5 -0
  79. package/renderable.js +1 -0
  80. package/types/clean.d.ts +2 -0
  81. package/types/clean.js +1 -0
  82. package/types/idom-context.d.ts +27 -0
  83. package/types/idom-context.js +3 -0
  84. package/types/renderable.d.ts +5 -0
  85. package/types/renderable.js +1 -0
  86. package/.eslintignore +0 -10
  87. package/.eslintrc.cjs +0 -28
  88. package/coverage/clover.xml +0 -39
  89. package/coverage/coverage-final.json +0 -2
  90. package/coverage/lcov-report/OneOf.ts.html +0 -256
  91. package/coverage/lcov-report/base.css +0 -224
  92. package/coverage/lcov-report/block-navigation.js +0 -87
  93. package/coverage/lcov-report/dom-context.ts.html +0 -928
  94. package/coverage/lcov-report/favicon.png +0 -0
  95. package/coverage/lcov-report/index.html +0 -116
  96. package/coverage/lcov-report/prettify.css +0 -1
  97. package/coverage/lcov-report/prettify.js +0 -2
  98. package/coverage/lcov-report/prop.ts.html +0 -691
  99. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  100. package/coverage/lcov-report/sorter.js +0 -196
  101. package/coverage/lcov-report/src/components/Attribute.ts.html +0 -154
  102. package/coverage/lcov-report/src/components/BooleanAttribute.ts.html +0 -154
  103. package/coverage/lcov-report/src/components/ClassName.ts.html +0 -151
  104. package/coverage/lcov-report/src/components/El.ts.html +0 -166
  105. package/coverage/lcov-report/src/components/FadeIn.ts.html +0 -262
  106. package/coverage/lcov-report/src/components/FadeOut.ts.html +0 -226
  107. package/coverage/lcov-report/src/components/For.ts.html +0 -151
  108. package/coverage/lcov-report/src/components/Fragment.ts.html +0 -142
  109. package/coverage/lcov-report/src/components/HiddenWhenEmpty.ts.html +0 -133
  110. package/coverage/lcov-report/src/components/If.ts.html +0 -217
  111. package/coverage/lcov-report/src/components/InnerHTML.ts.html +0 -178
  112. package/coverage/lcov-report/src/components/Lifecycle.ts.html +0 -157
  113. package/coverage/lcov-report/src/components/Match.ts.html +0 -286
  114. package/coverage/lcov-report/src/components/NotEmpty.tsx.html +0 -184
  115. package/coverage/lcov-report/src/components/On.ts.html +0 -151
  116. package/coverage/lcov-report/src/components/OnRemove.ts.html +0 -145
  117. package/coverage/lcov-report/src/components/OneOf.ts.html +0 -256
  118. package/coverage/lcov-report/src/components/Portal.ts.html +0 -175
  119. package/coverage/lcov-report/src/components/Property.ts.html +0 -154
  120. package/coverage/lcov-report/src/components/Provider.ts.html +0 -244
  121. package/coverage/lcov-report/src/components/Repeat.ts.html +0 -223
  122. package/coverage/lcov-report/src/components/Show.tsx.html +0 -190
  123. package/coverage/lcov-report/src/components/Text.ts.html +0 -229
  124. package/coverage/lcov-report/src/components/TextContent.ts.html +0 -178
  125. package/coverage/lcov-report/src/components/Tween.tsx.html +0 -943
  126. package/coverage/lcov-report/src/components/animatable.ts.html +0 -619
  127. package/coverage/lcov-report/src/components/index.html +0 -476
  128. package/coverage/lcov-report/src/dom-context.ts.html +0 -928
  129. package/coverage/lcov-report/src/helpers/handle-anchor-click.ts.html +0 -277
  130. package/coverage/lcov-report/src/helpers/handle-text-input.ts.html +0 -100
  131. package/coverage/lcov-report/src/helpers/index.html +0 -146
  132. package/coverage/lcov-report/src/helpers/is-empty-element.ts.html +0 -112
  133. package/coverage/lcov-report/src/index.html +0 -176
  134. package/coverage/lcov-report/src/index.ts.html +0 -412
  135. package/coverage/lcov-report/src/jsx-runtime.ts.html +0 -601
  136. package/coverage/lcov-report/src/prop.ts.html +0 -691
  137. package/coverage/lcov-report/src/render.ts.html +0 -112
  138. package/coverage/lcov-report/src/types/idom-context.ts.html +0 -184
  139. package/coverage/lcov-report/src/types/index.html +0 -116
  140. package/coverage/lcov-report/test/common.ts.html +0 -112
  141. package/coverage/lcov-report/test/index.html +0 -116
  142. package/coverage/lcov.info +0 -57
  143. package/jest.config.js +0 -5
  144. package/src/clean.ts +0 -2
  145. package/src/components/Attribute.ts +0 -23
  146. package/src/components/BooleanAttribute.ts +0 -23
  147. package/src/components/ClassName.ts +0 -22
  148. package/src/components/El.ts +0 -27
  149. package/src/components/FadeIn.ts +0 -59
  150. package/src/components/FadeOut.ts +0 -47
  151. package/src/components/For.ts +0 -22
  152. package/src/components/Fragment.ts +0 -19
  153. package/src/components/HiddenWhenEmpty.ts +0 -16
  154. package/src/components/If.ts +0 -44
  155. package/src/components/InnerHTML.ts +0 -31
  156. package/src/components/Lifecycle.ts +0 -24
  157. package/src/components/Match.ts +0 -67
  158. package/src/components/NotEmpty.tsx +0 -33
  159. package/src/components/On.ts +0 -22
  160. package/src/components/OnRemove.ts +0 -20
  161. package/src/components/OneOf.ts +0 -57
  162. package/src/components/Portal.ts +0 -30
  163. package/src/components/Property.ts +0 -23
  164. package/src/components/Provider.ts +0 -53
  165. package/src/components/Repeat.ts +0 -46
  166. package/src/components/Show.tsx +0 -35
  167. package/src/components/Text.ts +0 -48
  168. package/src/components/TextContent.ts +0 -31
  169. package/src/components/animatable.ts +0 -178
  170. package/src/dom-context.ts +0 -281
  171. package/src/helpers/handle-anchor-click.ts +0 -64
  172. package/src/helpers/handle-text-input.ts +0 -5
  173. package/src/helpers/is-empty-element.ts +0 -9
  174. package/src/index.ts +0 -109
  175. package/src/jsx-dev-runtime.ts +0 -8
  176. package/src/jsx-runtime.ts +0 -172
  177. package/src/jsx.ts +0 -1046
  178. package/src/prop.ts +0 -202
  179. package/src/render.ts +0 -9
  180. package/src/renderable.ts +0 -6
  181. package/test/common.ts +0 -9
  182. package/test/component.spec.tsx +0 -27
  183. package/test/domcontext.spec.ts +0 -36
  184. package/test/fadein.spec.tsx +0 -36
  185. package/test/fadeout.spec.tsx +0 -41
  186. package/test/if.spec.tsx +0 -30
  187. package/test/innerhtml.spec.tsx +0 -45
  188. package/test/prop.spec.ts +0 -10
  189. package/test/render.spec.tsx +0 -19
  190. package/test/textcontent.spec.tsx +0 -45
  191. package/test/when.spec.tsx +0 -30
  192. package/tsconfig.json +0 -21
  193. /package/{dist/index.js → index.js} +0 -0
package/dom-context.js ADDED
@@ -0,0 +1,260 @@
1
+ function extractClassNames(cls) {
2
+ return (cls ?? '').split(/\s+/g).filter((className) => className.length > 0);
3
+ }
4
+ function createIntegerSet(x) {
5
+ const integerSet = new Set();
6
+ for (let i = 0; i < x; i++) {
7
+ integerSet.add(i);
8
+ }
9
+ return integerSet;
10
+ }
11
+ export function makeProviderMark() {
12
+ return Symbol('providerMark');
13
+ }
14
+ export class DOMContext {
15
+ document;
16
+ element;
17
+ reference;
18
+ ns;
19
+ providers;
20
+ static of(element) {
21
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
22
+ return new DOMContext(element.ownerDocument, element, undefined, undefined, {});
23
+ }
24
+ constructor(document, element, reference, ns, providers) {
25
+ this.document = document;
26
+ this.element = element;
27
+ this.reference = reference;
28
+ this.ns = ns;
29
+ this.providers = providers;
30
+ }
31
+ append(node) {
32
+ if (this.reference !== undefined) {
33
+ try {
34
+ // There are components (TextContent, InnerHTML) that can mess up with the internal state of an element
35
+ this.element.insertBefore(node, this.reference);
36
+ }
37
+ catch (_) {
38
+ this.element.appendChild(node);
39
+ }
40
+ }
41
+ else {
42
+ this.element.appendChild(node);
43
+ }
44
+ }
45
+ getElement() {
46
+ return this.element;
47
+ }
48
+ getDocument() {
49
+ return this.document;
50
+ }
51
+ makeReference() {
52
+ const textNode = this.document.createTextNode('');
53
+ this.append(textNode);
54
+ return new DOMContext(this.document, this.element, textNode, this.ns, this.providers);
55
+ }
56
+ makeElement(tagName) {
57
+ if (this.ns !== undefined || tagName === 'svg') {
58
+ const ns = this.ns ?? 'http://www.w3.org/2000/svg';
59
+ const element = this.document.createElementNS(ns, tagName);
60
+ this.append(element);
61
+ return new DOMContext(this.document, element, undefined, ns, this.providers);
62
+ }
63
+ else {
64
+ const element = this.document.createElement(tagName);
65
+ this.append(element);
66
+ return new DOMContext(this.document, element, undefined, this.ns, this.providers);
67
+ }
68
+ }
69
+ getBooleanAttribute(name) {
70
+ return this.element.hasAttribute(name);
71
+ }
72
+ setBooleanAttribute(name, value) {
73
+ if (value) {
74
+ this.element.setAttribute(name, '');
75
+ }
76
+ else {
77
+ this.element.removeAttribute(name);
78
+ }
79
+ }
80
+ createBooleanAttribute(name, value) {
81
+ const current = this.element.hasAttribute(name);
82
+ this.setBooleanAttribute(name, value);
83
+ return [
84
+ (newValue) => {
85
+ this.setBooleanAttribute(name, newValue);
86
+ },
87
+ (removeTree) => {
88
+ if (removeTree) {
89
+ this.setBooleanAttribute(name, current);
90
+ }
91
+ }
92
+ ];
93
+ }
94
+ getAttribute(name) {
95
+ return this.element.getAttribute(name);
96
+ }
97
+ setAttribute(name, value) {
98
+ if (value == null) {
99
+ this.element.removeAttribute(name);
100
+ }
101
+ else {
102
+ this.element.setAttribute(name, value);
103
+ }
104
+ }
105
+ createAttribute(name, value) {
106
+ const current = this.element.getAttribute(name);
107
+ this.setAttribute(name, value);
108
+ return [
109
+ (newValue) => {
110
+ this.setAttribute(name, newValue);
111
+ },
112
+ (removeTree) => {
113
+ if (removeTree) {
114
+ this.setAttribute(name, current);
115
+ }
116
+ }
117
+ ];
118
+ }
119
+ getProperty(name) {
120
+ return Reflect.get(this.element, name);
121
+ }
122
+ setProperty(name, value) {
123
+ if (value == null) {
124
+ Reflect.deleteProperty(this.element, name);
125
+ }
126
+ else {
127
+ Reflect.set(this.element, name, value);
128
+ }
129
+ }
130
+ createProperty(name, value) {
131
+ const current = this.getProperty(name);
132
+ this.setProperty(name, value);
133
+ return [
134
+ (newValue) => {
135
+ this.setProperty(name, newValue);
136
+ },
137
+ (removeTree) => {
138
+ if (removeTree) {
139
+ this.setProperty(name, current);
140
+ }
141
+ }
142
+ ];
143
+ }
144
+ createText(text) {
145
+ const textNode = this.document.createTextNode(text);
146
+ this.append(textNode);
147
+ return [
148
+ (newText) => {
149
+ textNode.nodeValue = newText;
150
+ },
151
+ (removeTree) => {
152
+ if (removeTree) {
153
+ textNode.remove();
154
+ }
155
+ }
156
+ ];
157
+ }
158
+ createClass(cls) {
159
+ let current = extractClassNames(cls);
160
+ current.forEach((className) => {
161
+ this.element.classList.add(className);
162
+ });
163
+ return [
164
+ (newClass) => {
165
+ current.forEach((className) => {
166
+ this.element.classList.remove(className);
167
+ });
168
+ current = extractClassNames(newClass);
169
+ current.forEach((className) => {
170
+ this.element.classList.add(className);
171
+ });
172
+ },
173
+ (removeTree) => {
174
+ if (removeTree) {
175
+ current.forEach((className) => {
176
+ this.element.classList.remove(className);
177
+ if (this.element.classList.length === 0) {
178
+ this.element.removeAttribute('class');
179
+ }
180
+ });
181
+ }
182
+ }
183
+ ];
184
+ }
185
+ createHandler(name, handler) {
186
+ this.element.addEventListener(name, handler);
187
+ return (removeTree) => {
188
+ if (removeTree) {
189
+ this.element.removeEventListener(name, handler);
190
+ }
191
+ };
192
+ }
193
+ suspendedClears = [];
194
+ delayClear(f) {
195
+ this.suspendedClears.push(f);
196
+ return (removeTree) => {
197
+ // TODO nothing happens?
198
+ };
199
+ }
200
+ requestClear(removeTree, willClear) {
201
+ if (this.suspendedClears.length === 0) {
202
+ willClear();
203
+ this.clear(removeTree);
204
+ }
205
+ else {
206
+ const set = createIntegerSet(this.suspendedClears.length);
207
+ const clearSuspended = (index) => {
208
+ set.delete(index);
209
+ if (set.size === 0) {
210
+ willClear();
211
+ this.clear(removeTree);
212
+ }
213
+ };
214
+ this.suspendedClears.forEach((f, i) => { f(removeTree, () => { clearSuspended(i); }); });
215
+ this.suspendedClears.length = 0;
216
+ }
217
+ }
218
+ clear(removeTree) {
219
+ if (removeTree) {
220
+ if (this.reference !== undefined) {
221
+ this.reference.parentElement?.removeChild(this.reference);
222
+ }
223
+ else {
224
+ this.element.onblur = null;
225
+ this.element.parentElement?.removeChild(this.element);
226
+ }
227
+ }
228
+ }
229
+ withProvider(mark, provider) {
230
+ return new DOMContext(this.document, this.element, this.reference, this.ns, {
231
+ ...this.providers,
232
+ [mark]: provider
233
+ });
234
+ }
235
+ getProvider(mark) {
236
+ return this.providers[mark];
237
+ }
238
+ setStyle(name, value) {
239
+ if (value == null) {
240
+ this.element.style.removeProperty(name);
241
+ }
242
+ else {
243
+ this.element.style.setProperty(name, value);
244
+ }
245
+ }
246
+ createStyle(name, value) {
247
+ const current = this.element.style.getPropertyValue(name);
248
+ this.setStyle(name, value);
249
+ return [
250
+ (newValue) => {
251
+ this.setStyle(name, newValue);
252
+ },
253
+ (removeTree) => {
254
+ if (removeTree) {
255
+ this.setStyle(name, current);
256
+ }
257
+ }
258
+ ];
259
+ }
260
+ }
@@ -0,0 +1,4 @@
1
+ export declare const handleAnchorClick: (callback: () => boolean, options?: {
2
+ checkExtension?: boolean;
3
+ checkExternalUrl?: boolean;
4
+ }) => (e: MouseEvent) => void;
@@ -0,0 +1,43 @@
1
+ function shouldNotApplyCallback(e, checkExtension, checkExternalUrl) {
2
+ let target = e.target;
3
+ while ((target != null) && !(target instanceof HTMLAnchorElement)) {
4
+ target = target.parentElement;
5
+ }
6
+ if (target == null)
7
+ return true;
8
+ const anchor = target;
9
+ // Check for modifier keys and non-left-button, which indicate the user wants to control
10
+ // navigation
11
+ if (e.button !== 0 || e.ctrlKey || e.metaKey) {
12
+ return true;
13
+ }
14
+ // If there is a target and it is not `_self` then we take this
15
+ // as a signal that it doesn't want to be intercepted.
16
+ if (anchor.target !== '_self') {
17
+ return true;
18
+ }
19
+ if (anchor.getAttribute('download') != null) {
20
+ return true; // let the download happen
21
+ }
22
+ if (checkExternalUrl) {
23
+ const { pathname, search, hash } = anchor;
24
+ const relativeUrl = pathname + search + hash;
25
+ // don't navigate if external link or has extension
26
+ if (anchor.getAttribute('href') !== relativeUrl ||
27
+ (checkExtension && !/\/[^/.]*$/.test(pathname))) {
28
+ return true;
29
+ }
30
+ }
31
+ return false;
32
+ }
33
+ export const handleAnchorClick = (callback, options = {
34
+ checkExtension: true,
35
+ checkExternalUrl: true
36
+ }) => (e) => {
37
+ const { checkExtension, checkExternalUrl } = options;
38
+ if (shouldNotApplyCallback(e, checkExtension === true, checkExternalUrl === true)) {
39
+ return;
40
+ }
41
+ if (callback())
42
+ e.preventDefault();
43
+ };
@@ -0,0 +1 @@
1
+ export declare const handleTextInput: (f: (input: string) => void) => (e: Event) => void;
@@ -0,0 +1,4 @@
1
+ export const handleTextInput = (f) => (e) => {
2
+ const input = e.target;
3
+ f(input?.value ?? '');
4
+ };
@@ -0,0 +1,2 @@
1
+ import { type JSX } from '../jsx-runtime';
2
+ export declare function isEmptyElement(element: JSX.DOMNode): boolean;
@@ -0,0 +1,8 @@
1
+ export function isEmptyElement(element) {
2
+ if (Array.isArray(element)) {
3
+ if (element.length === 0)
4
+ return true;
5
+ return element.every(isEmptyElement);
6
+ }
7
+ return element == null || element === '';
8
+ }
package/index.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { type Clear, type Clean } from './clean';
2
+ import { makeProviderMark, DOMContext, type ProviderMark } from './dom-context';
3
+ import { Prop, Signal } from './prop';
4
+ import { render } from './render';
5
+ import { type Renderable } from './renderable';
6
+ import { isEmptyElement } from './helpers/is-empty-element';
7
+ import { handleTextInput } from './helpers/handle-text-input';
8
+ import { handleAnchorClick } from './helpers/handle-anchor-click';
9
+ import { Animatable, applyInterpolatedAnimatableProp, applyInterpolatedAnimatable, applyAnimatableProp, applyAnimatable, getComputedAnimatableProp, getComputedAnimatable } from './components/animatable';
10
+ import { AttributeImpl, Attribute, type AttributeProps } from './components/Attribute';
11
+ import { BooleanAttributeImpl, BooleanAttribute, type BooleanAttributeProps } from './components/BooleanAttribute';
12
+ import { ClassNameImpl, ClassName, type ClassNameProps } from './components/ClassName';
13
+ import { ConsumerImpl, Consumer, type ConsumerProps, ProviderImpl, Provider, type ProviderProps } from './components/Provider';
14
+ import { ElImpl, El, type ElProps } from './components/El';
15
+ import { FadeIn, FadeInImpl, FadeInProps } from './components/FadeIn';
16
+ import { FadeOut, FadeOutImpl, FadeOutProps } from './components/FadeOut';
17
+ import { For, type ForProps } from './components/For';
18
+ import { FragmentImpl, Fragment } from './components/Fragment';
19
+ import { HiddenWhenEmptyImpl, HiddenWhenEmpty } from './components/HiddenWhenEmpty';
20
+ import { If, type IfProps, Unless, When, type WhenProps } from './components/If';
21
+ import { InnerHTMLImpl, InnerHTML, type InnerHTMLProps } from './components/InnerHTML';
22
+ import { Lifecycle, LifecycleImpl, type LifecycleProps } from './components/Lifecycle';
23
+ import { MatchImpl, Match, type MatchProps } from './components/Match';
24
+ import { NotEmpty, type NotEmptyProps } from './components/NotEmpty';
25
+ import { OnImpl, On, type OnProps } from './components/On';
26
+ import { OnRemoveImpl, OnRemove, type OnRemoveProps } from './components/OnRemove';
27
+ import { OneOfImpl, OneOf, type OneOfProps } from './components/OneOf';
28
+ import { PortalImpl, Portal, type PortalProps } from './components/Portal';
29
+ import { PropertyImpl, Property, type PropertyProps } from './components/Property';
30
+ import { RepeatImpl, Repeat, type RepeatProps } from './components/Repeat';
31
+ import { ShowImpl, Show, type ShowProps } from './components/Show';
32
+ import { TextImpl, Text, type TextProps } from './components/Text';
33
+ import { TextContentImpl, TextContent, type TextContentProps } from './components/TextContent';
34
+ import type { JSX } from './jsx-runtime';
35
+ export { applyInterpolatedAnimatableProp, applyInterpolatedAnimatable, applyAnimatableProp, applyAnimatable, getComputedAnimatableProp, getComputedAnimatable, AttributeImpl, Attribute, BooleanAttributeImpl, BooleanAttribute, ClassNameImpl, ClassName, ConsumerImpl, Consumer, DOMContext, ElImpl, El, FadeIn, FadeInImpl, FadeOut, FadeOutImpl, For, FragmentImpl, Fragment, handleTextInput, handleAnchorClick, HiddenWhenEmptyImpl, HiddenWhenEmpty, If, InnerHTMLImpl, InnerHTML, isEmptyElement, Lifecycle, LifecycleImpl, makeProviderMark, MatchImpl, Match, NotEmpty, OnImpl, On, OnRemoveImpl, OnRemove, OneOfImpl, OneOf, PortalImpl, Portal, Prop, PropertyImpl, Property, ProviderImpl, Provider, render, RepeatImpl, Repeat, ShowImpl, Show, Signal, TextImpl, Text, TextContentImpl, TextContent, Unless, When };
36
+ export type { AttributeProps, BooleanAttributeProps, ClassNameProps, Clean, Clear, ConsumerProps, ElProps, FadeInProps, FadeOutProps, ForProps, InnerHTMLProps, IfProps, JSX, LifecycleProps, MatchProps, NotEmptyProps, OnProps, OnRemoveProps, OneOfProps, PortalProps, PropertyProps, ProviderMark, ProviderProps, Renderable, RepeatProps, ShowProps, TextProps, TextContentProps, Animatable, WhenProps };
@@ -0,0 +1 @@
1
+ export { Fragment, jsx, jsxs, jsxDEV, makeRenderable, makeRenderables } from './jsx-runtime';
@@ -0,0 +1 @@
1
+ export { Fragment, jsx, jsxs, jsxDEV, makeRenderable, makeRenderables } from './jsx-runtime';
@@ -0,0 +1,9 @@
1
+ import { type JSX } from './jsx';
2
+ import { type Renderable } from './renderable';
3
+ export declare function makeRenderables(value: any): Renderable[];
4
+ export declare function makeRenderable(value: any): Renderable;
5
+ declare function makeFragment({ children }: {
6
+ children: any[];
7
+ }): Renderable;
8
+ declare function makeElement(Name: any, ...args: any[]): Renderable;
9
+ export { makeElement as jsx, makeElement as jsxs, makeElement as jsxDEV, makeFragment as Fragment, type JSX };
package/jsx-runtime.js ADDED
@@ -0,0 +1,157 @@
1
+ import { ElImpl } from './components/El';
2
+ import { AttributeImpl } from './components/Attribute';
3
+ import { BooleanAttributeImpl } from './components/BooleanAttribute';
4
+ import { PropertyImpl } from './components/Property';
5
+ import { ClassNameImpl } from './components/ClassName';
6
+ import { Prop, Signal } from './prop';
7
+ import { TextImpl } from './components/Text';
8
+ import { OnImpl } from './components/On';
9
+ import { FragmentImpl } from './components/Fragment';
10
+ const domBooleanAttributes = new Set([
11
+ 'allowfullscreen',
12
+ 'allowpaymentrequest',
13
+ 'async',
14
+ 'autofocus',
15
+ 'autoplay',
16
+ 'capture',
17
+ 'controls',
18
+ 'default',
19
+ 'defer',
20
+ 'disabled',
21
+ 'disablepictureinpicture',
22
+ 'disableremoteplayback',
23
+ 'download',
24
+ 'draggable',
25
+ 'formnovalidate',
26
+ 'hidden',
27
+ 'ismap',
28
+ 'itemscope',
29
+ 'loop',
30
+ 'nomodule',
31
+ 'novalidate',
32
+ 'open',
33
+ 'playsinline',
34
+ 'readonly',
35
+ 'required',
36
+ 'reversed',
37
+ 'scoped',
38
+ 'seamless',
39
+ 'spellcheck',
40
+ 'truespeed'
41
+ ]);
42
+ const domProperties = new Set([
43
+ 'checked',
44
+ 'checked',
45
+ 'classList',
46
+ 'className',
47
+ 'contentEditable',
48
+ 'dataset',
49
+ 'innerHTML',
50
+ 'multiple',
51
+ 'muted',
52
+ 'scrollLeft',
53
+ 'scrollTop',
54
+ 'selected',
55
+ 'style',
56
+ 'tabIndex',
57
+ 'textContent',
58
+ 'value'
59
+ ]);
60
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
+ function isPrimitive(value) {
62
+ return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint' || value instanceof Date;
63
+ }
64
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
+ export function makeRenderables(value) {
66
+ if (value == null) {
67
+ return [];
68
+ }
69
+ if (Array.isArray(value)) {
70
+ return value.flatMap(makeRenderables);
71
+ }
72
+ if (typeof value === 'string') {
73
+ return [new TextImpl(new Prop(value))];
74
+ }
75
+ if (Signal.isSignal(value)) {
76
+ return [new TextImpl(value)];
77
+ }
78
+ if (typeof value === 'object' && 'appendTo' in value) {
79
+ return [value];
80
+ }
81
+ if (isPrimitive(value)) {
82
+ return [new TextImpl(new Prop(value).map(String))];
83
+ }
84
+ throw new Error(`Unkwown renderable: ${String(value)}`);
85
+ }
86
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
+ export function makeRenderable(value) {
88
+ const renderables = makeRenderables(value);
89
+ if (renderables.length === 0) {
90
+ return new FragmentImpl([]);
91
+ }
92
+ if (renderables.length === 1) {
93
+ return renderables[0];
94
+ }
95
+ return new FragmentImpl(renderables);
96
+ }
97
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
+ function isNamedConstructor(obj) {
99
+ return obj.prototype?.constructor?.name != null;
100
+ }
101
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
102
+ function makeFragment({ children }) {
103
+ if (Array.isArray(children)) {
104
+ return new FragmentImpl(children.flatMap(makeRenderables));
105
+ }
106
+ else {
107
+ return makeRenderable(children);
108
+ }
109
+ }
110
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
+ function makeElement(Name, ...args) {
112
+ if (typeof Name === 'function') {
113
+ if (isNamedConstructor(Name)) {
114
+ const el = new Name(...args);
115
+ return el;
116
+ }
117
+ else {
118
+ const el = Name(...args);
119
+ return el;
120
+ }
121
+ }
122
+ const { children: untypedChildren, ...rest } = args[0] ?? {};
123
+ const children = [];
124
+ if (Array.isArray(untypedChildren)) {
125
+ children.push(...(untypedChildren.flatMap(makeRenderables)));
126
+ }
127
+ else if (untypedChildren !== undefined) {
128
+ children.push(...makeRenderables(untypedChildren));
129
+ }
130
+ for (const [key, value] of Object.entries(rest)) {
131
+ if (key.startsWith('on')) {
132
+ const eventName = key.slice(2).toLowerCase();
133
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
134
+ children.push(new OnImpl(eventName, value));
135
+ continue;
136
+ }
137
+ if (value == null) {
138
+ continue;
139
+ }
140
+ const prop = isPrimitive(value) ? new Prop(value) : value;
141
+ if (key === 'class' || key === 'className') {
142
+ children.push(new ClassNameImpl(prop));
143
+ continue;
144
+ }
145
+ if (domProperties.has(key)) {
146
+ children.push(new PropertyImpl(key, prop));
147
+ continue;
148
+ }
149
+ if (domBooleanAttributes.has(key)) {
150
+ children.push(new BooleanAttributeImpl(key, prop));
151
+ continue;
152
+ }
153
+ children.push(new AttributeImpl(key, prop));
154
+ }
155
+ return new ElImpl(Name, children);
156
+ }
157
+ export { makeElement as jsx, makeElement as jsxs, makeElement as jsxDEV, makeFragment as Fragment };