-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
export creation helper functions for all html elements and svg elemen…
…ts using get proxy
- Loading branch information
Showing
1 changed file
with
218 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,219 @@ | ||
import { genCreateHTMLElement } from './core' | ||
import { | ||
genCreateHTMLElement, | ||
genCreateSVGElement, | ||
PartialCreateElement, | ||
} from './core' | ||
|
||
export const br = genCreateHTMLElement('br') | ||
export const p = genCreateHTMLElement('p') | ||
export const a = genCreateHTMLElement('a') | ||
export const div = genCreateHTMLElement('div') | ||
export const form = genCreateHTMLElement('form') | ||
export const input = genCreateHTMLElement('input') | ||
export const label = genCreateHTMLElement('label') | ||
export const span = genCreateHTMLElement('span') | ||
export const button = genCreateHTMLElement('button') | ||
export const h1 = genCreateHTMLElement('h1') | ||
export const h2 = genCreateHTMLElement('h2') | ||
export const h3 = genCreateHTMLElement('h3') | ||
export const h4 = genCreateHTMLElement('h4') | ||
export const h5 = genCreateHTMLElement('h5') | ||
export const h6 = genCreateHTMLElement('h6') | ||
export const b = genCreateHTMLElement('b') | ||
export const i = genCreateHTMLElement('i') | ||
export const img = genCreateHTMLElement('img') | ||
export const audio = genCreateHTMLElement('audio') | ||
export const video = genCreateHTMLElement('video') | ||
export const ol = genCreateHTMLElement('ol') | ||
export const ul = genCreateHTMLElement('ul') | ||
export const li = genCreateHTMLElement('li') | ||
export const code = genCreateHTMLElement('code') | ||
type CreateHTMLElementFunctions = { | ||
[K in keyof HTMLElementTagNameMap]: PartialCreateElement< | ||
HTMLElementTagNameMap[K] | ||
> | ||
} | ||
|
||
export const createHTMLElementFunctions = new Proxy( | ||
{} as CreateHTMLElementFunctions, | ||
{ | ||
get(target, p: keyof HTMLElementTagNameMap, receiver) { | ||
return genCreateHTMLElement(p) | ||
}, | ||
}, | ||
) | ||
|
||
type CreateSVGElementFunctions = { | ||
[K in keyof SVGElementTagNameMap]: PartialCreateElement< | ||
SVGElementTagNameMap[K] | ||
> | ||
} | ||
|
||
export const createSVGElementFunctions = new Proxy( | ||
{} as CreateSVGElementFunctions, | ||
{ | ||
get(target, p: keyof SVGElementTagNameMap, receiver) { | ||
return genCreateSVGElement(p) | ||
}, | ||
}, | ||
) | ||
|
||
export const createElementFunctions = { | ||
html: createHTMLElementFunctions, | ||
svg: createSVGElementFunctions, | ||
} | ||
|
||
export const { | ||
a, | ||
abbr, | ||
address, | ||
area, | ||
article, | ||
aside, | ||
audio, | ||
b, | ||
base, | ||
bdi, | ||
bdo, | ||
blockquote, | ||
body, | ||
br, | ||
button, | ||
canvas, | ||
caption, | ||
cite, | ||
code, | ||
col, | ||
colgroup, | ||
data, | ||
datalist, | ||
dd, | ||
del, | ||
details, | ||
dfn, | ||
dialog, | ||
div, | ||
dl, | ||
dt, | ||
em, | ||
embed, | ||
figcaption, | ||
figure, | ||
footer, | ||
form, | ||
h1, | ||
h2, | ||
h3, | ||
h4, | ||
h5, | ||
h6, | ||
head, | ||
header, | ||
hgroup, | ||
hr, | ||
html: htmlElement, | ||
i, | ||
iframe, | ||
img, | ||
input, | ||
ins, | ||
kbd, | ||
label, | ||
legend, | ||
li, | ||
link, | ||
main, | ||
map, | ||
mark, | ||
menu, | ||
meta, | ||
meter, | ||
nav, | ||
noscript, | ||
object, | ||
ol, | ||
optgroup, | ||
option, | ||
output, | ||
p, | ||
picture, | ||
pre, | ||
progress, | ||
q, | ||
rp, | ||
rt, | ||
ruby, | ||
s: sElement, | ||
samp, | ||
script: scriptElement, | ||
section, | ||
select, | ||
slot, | ||
small, | ||
source, | ||
span, | ||
strong, | ||
style: styleElement, | ||
sub, | ||
summary, | ||
sup, | ||
table, | ||
tbody, | ||
td, | ||
template, | ||
textarea, | ||
tfoot, | ||
th, | ||
thead, | ||
time, | ||
title: titleElement, | ||
tr, | ||
track, | ||
u, | ||
ul, | ||
var: varElement, | ||
video, | ||
wbr, | ||
} = createHTMLElementFunctions | ||
|
||
export const { | ||
a: aSVG, | ||
animate, | ||
animateMotion, | ||
animateTransform, | ||
circle, | ||
clipPath, | ||
defs, | ||
desc, | ||
ellipse, | ||
feBlend, | ||
feColorMatrix, | ||
feComponentTransfer, | ||
feComposite, | ||
feConvolveMatrix, | ||
feDiffuseLighting, | ||
feDisplacementMap, | ||
feDistantLight, | ||
feDropShadow, | ||
feFlood, | ||
feFuncA, | ||
feFuncB, | ||
feFuncG, | ||
feFuncR, | ||
feGaussianBlur, | ||
feImage, | ||
feMerge, | ||
feMergeNode, | ||
feMorphology, | ||
feOffset, | ||
fePointLight, | ||
feSpecularLighting, | ||
feSpotLight, | ||
feTile, | ||
feTurbulence, | ||
filter, | ||
foreignObject, | ||
g, | ||
image, | ||
line, | ||
linearGradient, | ||
marker, | ||
mask, | ||
metadata, | ||
mpath, | ||
path, | ||
pattern, | ||
polygon, | ||
polyline, | ||
radialGradient, | ||
rect, | ||
script: scriptSVG, | ||
set, | ||
stop, | ||
style: styleSVG, | ||
svg: svgSVG, | ||
switch: switchSVG, | ||
symbol, | ||
text: textSVG, | ||
textPath, | ||
title: titleSVG, | ||
tspan, | ||
use, | ||
view, | ||
} = createSVGElementFunctions |