@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.
- package/README.md +1 -0
- package/clean.d.ts +2 -0
- package/clean.js +1 -0
- package/components/Attribute.d.ts +15 -0
- package/components/Attribute.js +16 -0
- package/components/BooleanAttribute.d.ts +15 -0
- package/components/BooleanAttribute.js +16 -0
- package/components/ClassName.d.ts +13 -0
- package/components/ClassName.js +14 -0
- package/components/El.d.ts +15 -0
- package/components/El.js +21 -0
- package/components/FadeIn.d.ts +18 -0
- package/components/FadeIn.js +52 -0
- package/components/FadeOut.d.ts +16 -0
- package/components/FadeOut.js +39 -0
- package/components/For.d.ts +7 -0
- package/components/For.js +15 -0
- package/components/Fragment.d.ts +12 -0
- package/components/Fragment.js +16 -0
- package/components/HiddenWhenEmpty.d.ts +7 -0
- package/components/HiddenWhenEmpty.js +12 -0
- package/components/If.d.ts +14 -0
- package/components/If.js +19 -0
- package/components/InnerHTML.d.ts +13 -0
- package/components/InnerHTML.js +23 -0
- package/components/Lifecycle.d.ts +14 -0
- package/components/Lifecycle.js +18 -0
- package/components/Match.d.ts +33 -0
- package/components/Match.js +44 -0
- package/components/NotEmpty.d.ts +10 -0
- package/components/NotEmpty.js +11 -0
- package/components/On.d.ts +15 -0
- package/components/On.js +14 -0
- package/components/OnRemove.d.ts +11 -0
- package/components/OnRemove.js +14 -0
- package/components/OneOf.d.ts +20 -0
- package/components/OneOf.js +45 -0
- package/components/Portal.d.ts +15 -0
- package/components/Portal.js +20 -0
- package/components/Property.d.ts +15 -0
- package/components/Property.js +16 -0
- package/components/Provider.d.ts +28 -0
- package/components/Provider.js +44 -0
- package/components/Repeat.d.ts +15 -0
- package/components/Repeat.js +33 -0
- package/components/Shadow.d.ts +0 -0
- package/components/Shadow.js +1 -0
- package/components/Show.d.ts +20 -0
- package/components/Show.js +22 -0
- package/components/Text.d.ts +15 -0
- package/components/Text.js +33 -0
- package/components/TextContent.d.ts +13 -0
- package/components/TextContent.js +23 -0
- package/components/Tween.d.ts +75 -0
- package/components/Tween.js +242 -0
- package/components/animatable.d.ts +53 -0
- package/components/animatable.js +156 -0
- package/dom-context.d.ts +38 -0
- package/dom-context.js +260 -0
- package/helpers/handle-anchor-click.d.ts +4 -0
- package/helpers/handle-anchor-click.js +43 -0
- package/helpers/handle-text-input.d.ts +1 -0
- package/helpers/handle-text-input.js +4 -0
- package/helpers/is-empty-element.d.ts +2 -0
- package/helpers/is-empty-element.js +8 -0
- package/index.d.ts +36 -0
- package/jsx-dev-runtime.d.ts +1 -0
- package/jsx-dev-runtime.js +1 -0
- package/jsx-runtime.d.ts +9 -0
- package/jsx-runtime.js +157 -0
- package/jsx.d.ts +806 -0
- package/jsx.js +1 -0
- package/package.json +5 -3
- package/prop.d.ts +43 -0
- package/prop.js +174 -0
- package/render.d.ts +3 -0
- package/render.js +7 -0
- package/renderable.d.ts +5 -0
- package/renderable.js +1 -0
- package/types/clean.d.ts +2 -0
- package/types/clean.js +1 -0
- package/types/idom-context.d.ts +27 -0
- package/types/idom-context.js +3 -0
- package/types/renderable.d.ts +5 -0
- package/types/renderable.js +1 -0
- package/.eslintignore +0 -10
- package/.eslintrc.cjs +0 -28
- package/coverage/clover.xml +0 -39
- package/coverage/coverage-final.json +0 -2
- package/coverage/lcov-report/OneOf.ts.html +0 -256
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/dom-context.ts.html +0 -928
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -116
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/prop.ts.html +0 -691
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/src/components/Attribute.ts.html +0 -154
- package/coverage/lcov-report/src/components/BooleanAttribute.ts.html +0 -154
- package/coverage/lcov-report/src/components/ClassName.ts.html +0 -151
- package/coverage/lcov-report/src/components/El.ts.html +0 -166
- package/coverage/lcov-report/src/components/FadeIn.ts.html +0 -262
- package/coverage/lcov-report/src/components/FadeOut.ts.html +0 -226
- package/coverage/lcov-report/src/components/For.ts.html +0 -151
- package/coverage/lcov-report/src/components/Fragment.ts.html +0 -142
- package/coverage/lcov-report/src/components/HiddenWhenEmpty.ts.html +0 -133
- package/coverage/lcov-report/src/components/If.ts.html +0 -217
- package/coverage/lcov-report/src/components/InnerHTML.ts.html +0 -178
- package/coverage/lcov-report/src/components/Lifecycle.ts.html +0 -157
- package/coverage/lcov-report/src/components/Match.ts.html +0 -286
- package/coverage/lcov-report/src/components/NotEmpty.tsx.html +0 -184
- package/coverage/lcov-report/src/components/On.ts.html +0 -151
- package/coverage/lcov-report/src/components/OnRemove.ts.html +0 -145
- package/coverage/lcov-report/src/components/OneOf.ts.html +0 -256
- package/coverage/lcov-report/src/components/Portal.ts.html +0 -175
- package/coverage/lcov-report/src/components/Property.ts.html +0 -154
- package/coverage/lcov-report/src/components/Provider.ts.html +0 -244
- package/coverage/lcov-report/src/components/Repeat.ts.html +0 -223
- package/coverage/lcov-report/src/components/Show.tsx.html +0 -190
- package/coverage/lcov-report/src/components/Text.ts.html +0 -229
- package/coverage/lcov-report/src/components/TextContent.ts.html +0 -178
- package/coverage/lcov-report/src/components/Tween.tsx.html +0 -943
- package/coverage/lcov-report/src/components/animatable.ts.html +0 -619
- package/coverage/lcov-report/src/components/index.html +0 -476
- package/coverage/lcov-report/src/dom-context.ts.html +0 -928
- package/coverage/lcov-report/src/helpers/handle-anchor-click.ts.html +0 -277
- package/coverage/lcov-report/src/helpers/handle-text-input.ts.html +0 -100
- package/coverage/lcov-report/src/helpers/index.html +0 -146
- package/coverage/lcov-report/src/helpers/is-empty-element.ts.html +0 -112
- package/coverage/lcov-report/src/index.html +0 -176
- package/coverage/lcov-report/src/index.ts.html +0 -412
- package/coverage/lcov-report/src/jsx-runtime.ts.html +0 -601
- package/coverage/lcov-report/src/prop.ts.html +0 -691
- package/coverage/lcov-report/src/render.ts.html +0 -112
- package/coverage/lcov-report/src/types/idom-context.ts.html +0 -184
- package/coverage/lcov-report/src/types/index.html +0 -116
- package/coverage/lcov-report/test/common.ts.html +0 -112
- package/coverage/lcov-report/test/index.html +0 -116
- package/coverage/lcov.info +0 -57
- package/jest.config.js +0 -5
- package/src/clean.ts +0 -2
- package/src/components/Attribute.ts +0 -23
- package/src/components/BooleanAttribute.ts +0 -23
- package/src/components/ClassName.ts +0 -22
- package/src/components/El.ts +0 -27
- package/src/components/FadeIn.ts +0 -59
- package/src/components/FadeOut.ts +0 -47
- package/src/components/For.ts +0 -22
- package/src/components/Fragment.ts +0 -19
- package/src/components/HiddenWhenEmpty.ts +0 -16
- package/src/components/If.ts +0 -44
- package/src/components/InnerHTML.ts +0 -31
- package/src/components/Lifecycle.ts +0 -24
- package/src/components/Match.ts +0 -67
- package/src/components/NotEmpty.tsx +0 -33
- package/src/components/On.ts +0 -22
- package/src/components/OnRemove.ts +0 -20
- package/src/components/OneOf.ts +0 -57
- package/src/components/Portal.ts +0 -30
- package/src/components/Property.ts +0 -23
- package/src/components/Provider.ts +0 -53
- package/src/components/Repeat.ts +0 -46
- package/src/components/Show.tsx +0 -35
- package/src/components/Text.ts +0 -48
- package/src/components/TextContent.ts +0 -31
- package/src/components/animatable.ts +0 -178
- package/src/dom-context.ts +0 -281
- package/src/helpers/handle-anchor-click.ts +0 -64
- package/src/helpers/handle-text-input.ts +0 -5
- package/src/helpers/is-empty-element.ts +0 -9
- package/src/index.ts +0 -109
- package/src/jsx-dev-runtime.ts +0 -8
- package/src/jsx-runtime.ts +0 -172
- package/src/jsx.ts +0 -1046
- package/src/prop.ts +0 -202
- package/src/render.ts +0 -9
- package/src/renderable.ts +0 -6
- package/test/common.ts +0 -9
- package/test/component.spec.tsx +0 -27
- package/test/domcontext.spec.ts +0 -36
- package/test/fadein.spec.tsx +0 -36
- package/test/fadeout.spec.tsx +0 -41
- package/test/if.spec.tsx +0 -30
- package/test/innerhtml.spec.tsx +0 -45
- package/test/prop.spec.ts +0 -10
- package/test/render.spec.tsx +0 -19
- package/test/textcontent.spec.tsx +0 -45
- package/test/when.spec.tsx +0 -30
- package/tsconfig.json +0 -21
- /package/{dist/index.js → index.js} +0 -0
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
function shouldNotApplyCallback(
|
|
2
|
-
e: MouseEvent,
|
|
3
|
-
checkExtension: boolean,
|
|
4
|
-
checkExternalUrl: boolean
|
|
5
|
-
): boolean {
|
|
6
|
-
let target = e.target as HTMLElement | null
|
|
7
|
-
while ((target != null) && !(target instanceof HTMLAnchorElement)) {
|
|
8
|
-
target = target.parentElement
|
|
9
|
-
}
|
|
10
|
-
if (target == null) return true
|
|
11
|
-
|
|
12
|
-
const anchor = target
|
|
13
|
-
|
|
14
|
-
// Check for modifier keys and non-left-button, which indicate the user wants to control
|
|
15
|
-
// navigation
|
|
16
|
-
if (e.button !== 0 || e.ctrlKey || e.metaKey) {
|
|
17
|
-
return true
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// If there is a target and it is not `_self` then we take this
|
|
21
|
-
// as a signal that it doesn't want to be intercepted.
|
|
22
|
-
if (anchor.target !== '_self') {
|
|
23
|
-
return true
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (anchor.getAttribute('download') != null) {
|
|
27
|
-
return true // let the download happen
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (checkExternalUrl) {
|
|
31
|
-
const { pathname, search, hash } = anchor
|
|
32
|
-
const relativeUrl = pathname + search + hash
|
|
33
|
-
|
|
34
|
-
// don't navigate if external link or has extension
|
|
35
|
-
if (
|
|
36
|
-
anchor.getAttribute('href') !== relativeUrl ||
|
|
37
|
-
(checkExtension && !/\/[^/.]*$/.test(pathname))
|
|
38
|
-
) {
|
|
39
|
-
return true
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return false
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const handleAnchorClick =
|
|
47
|
-
(
|
|
48
|
-
callback: () => boolean,
|
|
49
|
-
options: { checkExtension?: boolean, checkExternalUrl?: boolean } = {
|
|
50
|
-
checkExtension: true,
|
|
51
|
-
checkExternalUrl: true
|
|
52
|
-
}
|
|
53
|
-
) =>
|
|
54
|
-
(e: MouseEvent) => {
|
|
55
|
-
const { checkExtension, checkExternalUrl } = options
|
|
56
|
-
if (
|
|
57
|
-
shouldNotApplyCallback(
|
|
58
|
-
e,
|
|
59
|
-
checkExtension === true,
|
|
60
|
-
checkExternalUrl === true
|
|
61
|
-
)
|
|
62
|
-
) { return }
|
|
63
|
-
if (callback()) e.preventDefault()
|
|
64
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type JSX } from '../jsx-runtime'
|
|
2
|
-
|
|
3
|
-
export function isEmptyElement(element: JSX.DOMNode): boolean {
|
|
4
|
-
if (Array.isArray(element)) {
|
|
5
|
-
if (element.length === 0) return true
|
|
6
|
-
return element.every(isEmptyElement)
|
|
7
|
-
}
|
|
8
|
-
return element == null || element === ''
|
|
9
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
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
|
-
|
|
11
|
-
import { AttributeImpl, Attribute, type AttributeProps } from './components/Attribute'
|
|
12
|
-
import { BooleanAttributeImpl, BooleanAttribute, type BooleanAttributeProps } from './components/BooleanAttribute'
|
|
13
|
-
import { ClassNameImpl, ClassName, type ClassNameProps } from './components/ClassName'
|
|
14
|
-
import { ConsumerImpl, Consumer, type ConsumerProps, ProviderImpl, Provider, type ProviderProps } from './components/Provider'
|
|
15
|
-
import { ElImpl, El, type ElProps } from './components/El'
|
|
16
|
-
import { FadeIn, FadeInImpl, FadeInProps } from './components/FadeIn'
|
|
17
|
-
import { FadeOut, FadeOutImpl, FadeOutProps } from './components/FadeOut'
|
|
18
|
-
import { For, type ForProps } from './components/For'
|
|
19
|
-
import { FragmentImpl, Fragment } from './components/Fragment'
|
|
20
|
-
import { HiddenWhenEmptyImpl, HiddenWhenEmpty } from './components/HiddenWhenEmpty'
|
|
21
|
-
import { If, type IfProps, Unless, When, type WhenProps } from './components/If'
|
|
22
|
-
import { InnerHTMLImpl, InnerHTML, type InnerHTMLProps } from './components/InnerHTML'
|
|
23
|
-
import { Lifecycle, LifecycleImpl, type LifecycleProps } from './components/Lifecycle'
|
|
24
|
-
import { MatchImpl, Match, type MatchProps } from './components/Match'
|
|
25
|
-
import { NotEmpty, type NotEmptyProps } from './components/NotEmpty'
|
|
26
|
-
import { OnImpl, On, type OnProps } from './components/On'
|
|
27
|
-
import { OnRemoveImpl, OnRemove, type OnRemoveProps } from './components/OnRemove'
|
|
28
|
-
import { OneOfImpl, OneOf, type OneOfProps } from './components/OneOf'
|
|
29
|
-
import { PortalImpl, Portal, type PortalProps } from './components/Portal'
|
|
30
|
-
import { PropertyImpl, Property, type PropertyProps } from './components/Property'
|
|
31
|
-
import { RepeatImpl, Repeat, type RepeatProps } from './components/Repeat'
|
|
32
|
-
import { ShowImpl, Show, type ShowProps } from './components/Show'
|
|
33
|
-
import { TextImpl, Text, type TextProps } from './components/Text'
|
|
34
|
-
import { TextContentImpl, TextContent, type TextContentProps } from './components/TextContent'
|
|
35
|
-
|
|
36
|
-
import type { JSX } from './jsx-runtime'
|
|
37
|
-
|
|
38
|
-
export {
|
|
39
|
-
applyInterpolatedAnimatableProp, applyInterpolatedAnimatable, applyAnimatableProp, applyAnimatable, getComputedAnimatableProp, getComputedAnimatable,
|
|
40
|
-
|
|
41
|
-
AttributeImpl, Attribute,
|
|
42
|
-
BooleanAttributeImpl, BooleanAttribute,
|
|
43
|
-
ClassNameImpl, ClassName,
|
|
44
|
-
ConsumerImpl, Consumer,
|
|
45
|
-
DOMContext,
|
|
46
|
-
ElImpl, El,
|
|
47
|
-
FadeIn, FadeInImpl,
|
|
48
|
-
FadeOut, FadeOutImpl,
|
|
49
|
-
For,
|
|
50
|
-
FragmentImpl, Fragment,
|
|
51
|
-
handleTextInput,
|
|
52
|
-
handleAnchorClick,
|
|
53
|
-
HiddenWhenEmptyImpl, HiddenWhenEmpty,
|
|
54
|
-
If,
|
|
55
|
-
InnerHTMLImpl, InnerHTML,
|
|
56
|
-
isEmptyElement,
|
|
57
|
-
Lifecycle, LifecycleImpl,
|
|
58
|
-
makeProviderMark,
|
|
59
|
-
MatchImpl, Match,
|
|
60
|
-
NotEmpty,
|
|
61
|
-
OnImpl, On,
|
|
62
|
-
OnRemoveImpl, OnRemove,
|
|
63
|
-
OneOfImpl, OneOf,
|
|
64
|
-
PortalImpl, Portal,
|
|
65
|
-
Prop,
|
|
66
|
-
PropertyImpl, Property,
|
|
67
|
-
ProviderImpl, Provider,
|
|
68
|
-
render,
|
|
69
|
-
RepeatImpl, Repeat,
|
|
70
|
-
ShowImpl, Show,
|
|
71
|
-
Signal,
|
|
72
|
-
TextImpl, Text,
|
|
73
|
-
TextContentImpl, TextContent,
|
|
74
|
-
Unless,
|
|
75
|
-
When
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export type {
|
|
79
|
-
AttributeProps,
|
|
80
|
-
BooleanAttributeProps,
|
|
81
|
-
ClassNameProps,
|
|
82
|
-
Clean,
|
|
83
|
-
Clear,
|
|
84
|
-
ConsumerProps,
|
|
85
|
-
ElProps,
|
|
86
|
-
FadeInProps,
|
|
87
|
-
FadeOutProps,
|
|
88
|
-
ForProps,
|
|
89
|
-
InnerHTMLProps,
|
|
90
|
-
IfProps,
|
|
91
|
-
JSX,
|
|
92
|
-
LifecycleProps,
|
|
93
|
-
MatchProps,
|
|
94
|
-
NotEmptyProps,
|
|
95
|
-
OnProps,
|
|
96
|
-
OnRemoveProps,
|
|
97
|
-
OneOfProps,
|
|
98
|
-
PortalProps,
|
|
99
|
-
PropertyProps,
|
|
100
|
-
ProviderMark,
|
|
101
|
-
ProviderProps,
|
|
102
|
-
Renderable,
|
|
103
|
-
RepeatProps,
|
|
104
|
-
ShowProps,
|
|
105
|
-
TextProps,
|
|
106
|
-
TextContentProps,
|
|
107
|
-
Animatable,
|
|
108
|
-
WhenProps
|
|
109
|
-
}
|
package/src/jsx-dev-runtime.ts
DELETED
package/src/jsx-runtime.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { type JSX } from './jsx'
|
|
2
|
-
import { type Renderable } from './renderable'
|
|
3
|
-
import { ElImpl } from './components/El'
|
|
4
|
-
import { AttributeImpl } from './components/Attribute'
|
|
5
|
-
import { BooleanAttributeImpl } from './components/BooleanAttribute'
|
|
6
|
-
import { PropertyImpl } from './components/Property'
|
|
7
|
-
import { ClassNameImpl } from './components/ClassName'
|
|
8
|
-
import { Prop, Signal } from './prop'
|
|
9
|
-
import { TextImpl } from './components/Text'
|
|
10
|
-
import { OnImpl } from './components/On'
|
|
11
|
-
import { FragmentImpl } from './components/Fragment'
|
|
12
|
-
|
|
13
|
-
const domBooleanAttributes = new Set([
|
|
14
|
-
'allowfullscreen',
|
|
15
|
-
'allowpaymentrequest',
|
|
16
|
-
'async',
|
|
17
|
-
'autofocus',
|
|
18
|
-
'autoplay',
|
|
19
|
-
'capture',
|
|
20
|
-
'controls',
|
|
21
|
-
'default',
|
|
22
|
-
'defer',
|
|
23
|
-
'disabled',
|
|
24
|
-
'disablepictureinpicture',
|
|
25
|
-
'disableremoteplayback',
|
|
26
|
-
'download',
|
|
27
|
-
'draggable',
|
|
28
|
-
'formnovalidate',
|
|
29
|
-
'hidden',
|
|
30
|
-
'ismap',
|
|
31
|
-
'itemscope',
|
|
32
|
-
'loop',
|
|
33
|
-
'nomodule',
|
|
34
|
-
'novalidate',
|
|
35
|
-
'open',
|
|
36
|
-
'playsinline',
|
|
37
|
-
'readonly',
|
|
38
|
-
'required',
|
|
39
|
-
'reversed',
|
|
40
|
-
'scoped',
|
|
41
|
-
'seamless',
|
|
42
|
-
'spellcheck',
|
|
43
|
-
'truespeed'
|
|
44
|
-
])
|
|
45
|
-
|
|
46
|
-
const domProperties = new Set([
|
|
47
|
-
'checked',
|
|
48
|
-
'checked',
|
|
49
|
-
'classList',
|
|
50
|
-
'className',
|
|
51
|
-
'contentEditable',
|
|
52
|
-
'dataset',
|
|
53
|
-
'innerHTML',
|
|
54
|
-
'multiple',
|
|
55
|
-
'muted',
|
|
56
|
-
'scrollLeft',
|
|
57
|
-
'scrollTop',
|
|
58
|
-
'selected',
|
|
59
|
-
'style',
|
|
60
|
-
'tabIndex',
|
|
61
|
-
'textContent',
|
|
62
|
-
'value'
|
|
63
|
-
])
|
|
64
|
-
|
|
65
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
|
-
function isPrimitive(value: any): value is string | number | boolean | Date | bigint {
|
|
67
|
-
return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint' || value instanceof Date
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
-
export function makeRenderables(value: any): Renderable[] {
|
|
72
|
-
if (value == null) {
|
|
73
|
-
return []
|
|
74
|
-
}
|
|
75
|
-
if (Array.isArray(value)) {
|
|
76
|
-
return value.flatMap(makeRenderables)
|
|
77
|
-
}
|
|
78
|
-
if (typeof value === 'string') {
|
|
79
|
-
return [new TextImpl(new Prop(value))]
|
|
80
|
-
}
|
|
81
|
-
if (Signal.isSignal(value)) {
|
|
82
|
-
return [new TextImpl(value as Prop<string>)]
|
|
83
|
-
}
|
|
84
|
-
if (typeof value === 'object' && 'appendTo' in value) {
|
|
85
|
-
return [value]
|
|
86
|
-
}
|
|
87
|
-
if (isPrimitive(value)) {
|
|
88
|
-
return [new TextImpl(new Prop(value).map(String))]
|
|
89
|
-
}
|
|
90
|
-
throw new Error(`Unkwown renderable: ${String(value)}`)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
|
-
export function makeRenderable(value: any): Renderable {
|
|
95
|
-
const renderables = makeRenderables(value)
|
|
96
|
-
if (renderables.length === 0) {
|
|
97
|
-
return new FragmentImpl([])
|
|
98
|
-
}
|
|
99
|
-
if (renderables.length === 1) {
|
|
100
|
-
return renderables[0]
|
|
101
|
-
}
|
|
102
|
-
return new FragmentImpl(renderables)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
106
|
-
function isNamedConstructor(obj: any): boolean {
|
|
107
|
-
return obj.prototype?.constructor?.name != null
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
111
|
-
function makeFragment({ children }: { children: any[] }): Renderable {
|
|
112
|
-
if (Array.isArray(children)) {
|
|
113
|
-
return new FragmentImpl(children.flatMap(makeRenderables))
|
|
114
|
-
} else {
|
|
115
|
-
return makeRenderable(children)
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
120
|
-
function makeElement(Name: any, ...args: any[]): Renderable {
|
|
121
|
-
if (typeof Name === 'function') {
|
|
122
|
-
if (isNamedConstructor(Name)) {
|
|
123
|
-
const el = new Name(...args)
|
|
124
|
-
return el
|
|
125
|
-
} else {
|
|
126
|
-
const el = Name(...args)
|
|
127
|
-
return el
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
const { children: untypedChildren, ...rest } = args[0] ?? {}
|
|
131
|
-
const children: Renderable[] = []
|
|
132
|
-
if (Array.isArray(untypedChildren)) {
|
|
133
|
-
children.push(...(untypedChildren.flatMap(makeRenderables)))
|
|
134
|
-
} else if (untypedChildren !== undefined) {
|
|
135
|
-
children.push(...makeRenderables(untypedChildren))
|
|
136
|
-
}
|
|
137
|
-
for (const [key, value] of Object.entries(rest)) {
|
|
138
|
-
if (key.startsWith('on')) {
|
|
139
|
-
const eventName = key.slice(2).toLowerCase()
|
|
140
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
141
|
-
children.push(new OnImpl(eventName, value as any))
|
|
142
|
-
continue
|
|
143
|
-
}
|
|
144
|
-
if (value == null) {
|
|
145
|
-
continue
|
|
146
|
-
}
|
|
147
|
-
const prop: Prop<unknown> = isPrimitive(value) ? new Prop(value) as Prop<unknown> : value as Prop<unknown>
|
|
148
|
-
if (key === 'class' || key === 'className') {
|
|
149
|
-
children.push(new ClassNameImpl(prop as Prop<string>))
|
|
150
|
-
continue
|
|
151
|
-
}
|
|
152
|
-
if (domProperties.has(key)) {
|
|
153
|
-
children.push(new PropertyImpl(key, prop))
|
|
154
|
-
continue
|
|
155
|
-
}
|
|
156
|
-
if (domBooleanAttributes.has(key)) {
|
|
157
|
-
children.push(new BooleanAttributeImpl(key, prop as Prop<boolean>))
|
|
158
|
-
continue
|
|
159
|
-
}
|
|
160
|
-
children.push(new AttributeImpl(key, prop as Prop<string>))
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return new ElImpl(Name, children)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export {
|
|
167
|
-
makeElement as jsx,
|
|
168
|
-
makeElement as jsxs,
|
|
169
|
-
makeElement as jsxDEV,
|
|
170
|
-
makeFragment as Fragment,
|
|
171
|
-
type JSX
|
|
172
|
-
}
|