// Copyright (C) John Nesky, distributed under the MIT license. import {applyElementArgs, svgNS, parseHTML, parseSVG, replaceScriptWith, applyToElement} from "./elements-base.js"; export {replaceScriptWith, applyToElement}; interface HTMLElementFactory { (...args: Array): DocumentFragment; readonly [key: string]: (...args: Array) => HTMLElement; a(...args: Array): HTMLAnchorElement; abbr(...args: Array): HTMLElement; address(...args: Array): HTMLElement; area(...args: Array): HTMLAreaElement; article(...args: Array): HTMLElement; aside(...args: Array): HTMLElement; audio(...args: Array): HTMLAudioElement; b(...args: Array): HTMLElement; base(...args: Array): HTMLBaseElement; bdi(...args: Array): HTMLElement; bdo(...args: Array): HTMLElement; blockquote(...args: Array): HTMLQuoteElement; br(...args: Array): HTMLBRElement; button(...args: Array): HTMLButtonElement; canvas(...args: Array): HTMLCanvasElement; caption(...args: Array): HTMLTableCaptionElement; cite(...args: Array): HTMLElement; code(...args: Array): HTMLElement; col(...args: Array): HTMLTableColElement; colgroup(...args: Array): HTMLTableColElement; datalist(...args: Array): HTMLDataListElement; dd(...args: Array): HTMLElement; del(...args: Array): HTMLModElement; details(...args: Array): HTMLDetailsElement; dfn(...args: Array): HTMLElement; dialog(...args: Array): HTMLDialogElement; div(...args: Array): HTMLDivElement; dl(...args: Array): HTMLDListElement; dt(...args: Array): HTMLElement; em(...args: Array): HTMLElement; embed(...args: Array): HTMLEmbedElement; fieldset(...args: Array): HTMLFieldSetElement; figcaption(...args: Array): HTMLElement; figure(...args: Array): HTMLElement; footer(...args: Array): HTMLElement; form(...args: Array): HTMLFormElement; h1(...args: Array): HTMLHeadingElement; h2(...args: Array): HTMLHeadingElement; h3(...args: Array): HTMLHeadingElement; h4(...args: Array): HTMLHeadingElement; h5(...args: Array): HTMLHeadingElement; h6(...args: Array): HTMLHeadingElement; header(...args: Array): HTMLElement; hr(...args: Array): HTMLHRElement; i(...args: Array): HTMLElement; iframe(...args: Array): HTMLIFrameElement; img(...args: Array): HTMLImageElement; input(...args: Array): HTMLInputElement; ins(...args: Array): HTMLModElement; kbd(...args: Array): HTMLElement; label(...args: Array): HTMLLabelElement; legend(...args: Array): HTMLLegendElement; li(...args: Array): HTMLLIElement; link(...args: Array): HTMLLinkElement; main(...args: Array): HTMLElement; map(...args: Array): HTMLMapElement; mark(...args: Array): HTMLElement; menu(...args: Array): HTMLMenuElement; menuitem(...args: Array): HTMLUnknownElement; meta(...args: Array): HTMLMetaElement; meter(...args: Array): HTMLMeterElement; nav(...args: Array): HTMLElement; noscript(...args: Array): HTMLElement; object(...args: Array): HTMLObjectElement; ol(...args: Array): HTMLOListElement; optgroup(...args: Array): HTMLOptGroupElement; option(...args: Array): HTMLOptionElement; output(...args: Array): HTMLOutputElement; p(...args: Array): HTMLParagraphElement; param(...args: Array): HTMLParamElement; picture(...args: Array): HTMLPictureElement; pre(...args: Array): HTMLPreElement; progress(...args: Array): HTMLProgressElement; q(...args: Array): HTMLQuoteElement; rp(...args: Array): HTMLElement; rt(...args: Array): HTMLElement; ruby(...args: Array): HTMLElement; s(...args: Array): HTMLElement; samp(...args: Array): HTMLElement; script(...args: Array): HTMLScriptElement; section(...args: Array): HTMLElement; select(...args: Array): HTMLSelectElement; small(...args: Array): HTMLElement; source(...args: Array): HTMLSourceElement; span(...args: Array): HTMLSpanElement; strong(...args: Array): HTMLElement; style(...args: Array): HTMLStyleElement; sub(...args: Array): HTMLElement; summary(...args: Array): HTMLElement; sup(...args: Array): HTMLElement; table(...args: Array): HTMLTableElement; tbody(...args: Array): HTMLTableSectionElement; td(...args: Array): HTMLTableCellElement; template(...args: Array): HTMLTemplateElement; textarea(...args: Array): HTMLTextAreaElement; tfoot(...args: Array): HTMLTableSectionElement; th(...args: Array): HTMLTableCellElement; thead(...args: Array): HTMLTableSectionElement; time(...args: Array): HTMLTimeElement; title(...args: Array): HTMLTitleElement; tr(...args: Array): HTMLTableRowElement; track(...args: Array): HTMLTrackElement; u(...args: Array): HTMLElement; ul(...args: Array): HTMLUListElement; var(...args: Array): HTMLElement; video(...args: Array): HTMLVideoElement; wbr(...args: Array): HTMLElement; } interface SVGElementFactory { (...args: Array): DocumentFragment; readonly [key: string]: (...args: Array) => SVGElement; a(...args: Array): SVGAElement; altGlyph(...args: Array): SVGElement; altGlyphDef(...args: Array): SVGElement; altGlyphItem(...args: Array): SVGElement; animate(...args: Array): SVGAnimateElement; animateMotion(...args: Array): SVGAnimateMotionElement; animateTransform(...args: Array): SVGAnimateTransformElement; circle(...args: Array): SVGCircleElement; clipPath(...args: Array): SVGClipPathElement; "color-profile"(...args: Array): SVGElement; color_profile(...args: Array): SVGElement; cursor(...args: Array): SVGElement; defs(...args: Array): SVGDefsElement; desc(...args: Array): SVGDescElement; discard(...args: Array): SVGElement; ellipse(...args: Array): SVGEllipseElement; feBlend(...args: Array): SVGFEBlendElement; feColorMatrix(...args: Array): SVGFEColorMatrixElement; feComponentTransfer(...args: Array): SVGFEComponentTransferElement; feComposite(...args: Array): SVGFECompositeElement; feConvolveMatrix(...args: Array): SVGFEConvolveMatrixElement; feDiffuseLighting(...args: Array): SVGFEDiffuseLightingElement; feDisplacementMap(...args: Array): SVGFEDisplacementMapElement; feDistantLight(...args: Array): SVGFEDistantLightElement; feDropShadow(...args: Array): SVGElement; feFlood(...args: Array): SVGFEFloodElement; feFuncA(...args: Array): SVGFEFuncAElement; feFuncB(...args: Array): SVGFEFuncBElement; feFuncG(...args: Array): SVGFEFuncGElement; feFuncR(...args: Array): SVGFEFuncRElement; feGaussianBlur(...args: Array): SVGFEGaussianBlurElement; feImage(...args: Array): SVGFEImageElement; feMerge(...args: Array): SVGFEMergeElement; feMergeNode(...args: Array): SVGFEMergeNodeElement; feMorphology(...args: Array): SVGFEMorphologyElement; feOffset(...args: Array): SVGFEOffsetElement; fePointLight(...args: Array): SVGFEPointLightElement; feSpecularLighting(...args: Array): SVGFESpecularLightingElement; feSpotLight(...args: Array): SVGFESpotLightElement; feTile(...args: Array): SVGFETileElement; feTurbulence(...args: Array): SVGFETurbulenceElement; filter(...args: Array): SVGFilterElement; font(...args: Array): SVGElement; "font-face"(...args: Array): SVGElement; font_face(...args: Array): SVGElement; "font-face-format"(...args: Array): SVGElement; font_face_format(...args: Array): SVGElement; "font-face-name"(...args: Array): SVGElement; font_face_name(...args: Array): SVGElement; "font-face-src"(...args: Array): SVGElement; font_face_src(...args: Array): SVGElement; "font-face-uri"(...args: Array): SVGElement; font_face_uri(...args: Array): SVGElement; foreignObject(...args: Array): SVGForeignObjectElement; g(...args: Array): SVGGElement; glyph(...args: Array): SVGElement; glyphRef(...args: Array): SVGElement; hkern(...args: Array): SVGElement; image(...args: Array): SVGImageElement; line(...args: Array): SVGLineElement; linearGradient(...args: Array): SVGLinearGradientElement; marker(...args: Array): SVGMarkerElement; mask(...args: Array): SVGMaskElement; metadata(...args: Array): SVGMetadataElement; "missing-glyph"(...args: Array): SVGElement; missing_glyph(...args: Array): SVGElement; mpath(...args: Array): SVGElement; path(...args: Array): SVGPathElement; pattern(...args: Array): SVGPatternElement; polygon(...args: Array): SVGPolygonElement; polyline(...args: Array): SVGPolylineElement; radialGradient(...args: Array): SVGRadialGradientElement; rect(...args: Array): SVGRectElement; script(...args: Array): SVGScriptElement; set(...args: Array): SVGElement; stop(...args: Array): SVGStopElement; style(...args: Array): SVGStyleElement; svg(...args: Array): SVGSVGElement; switch(...args: Array): SVGSwitchElement; symbol(...args: Array): SVGSymbolElement; text(...args: Array): SVGTextElement; textPath(...args: Array): SVGTextPathElement; title(...args: Array): SVGTitleElement; tref(...args: Array): SVGElement; tspan(...args: Array): SVGTSpanElement; use(...args: Array): SVGUseElement; view(...args: Array): SVGViewElement; vkern(...args: Array): SVGElement; } export let HTML: HTMLElementFactory = parseHTML; export let SVG: SVGElementFactory = parseSVG; if (typeof Proxy !== "undefined") { //const uppercasePattern: RegExp = /\p{Uppercase}/ug; // ASCII-only fallback required for Internet Explorer. let uppercasePattern = /[A-Z]/g; try { uppercasePattern = new RegExp("\\p{Uppercase}", "ug"); } catch(e){}; HTML = new Proxy(parseHTML, { get: function(target: any, name: string) { const kebabCaseName = name.replace(uppercasePattern, (c: string) => "-" + c.toLowerCase()).replace(/^-/, "").replace(/_/g, "-"); return (...args: Array) => applyElementArgs(document.createElement(kebabCaseName), args); }, }); SVG = new Proxy(parseSVG, { get: function(target: any, name: string) { const kebabCaseName = name.replace(/_/g, "-"); return (...args: Array) => applyElementArgs( document.createElementNS(svgNS, kebabCaseName), args); }, }); } else { console.warn("imperative-html could not find a definition for Proxy, which means that custom elements won't be supported! Try a newer browser."); for (const name of "a abbr address area article aside audio b base bdi bdo blockquote br button canvas caption cite code col colgroup datalist dd del details dfn dialog div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 header hr i iframe img input ins kbd label legend li link main map mark menu menuitem meta meter nav noscript object ol optgroup option output p param picture pre progress q rp rt ruby s samp script section select small source span strong style sub summary sup table tbody td template textarea tfoot th thead time title tr track u ul var video wbr".split(" ")) { (HTML)[name] = (...args: Array) => applyElementArgs(document.createElement(name), args); } for (const name of "a altGlyph altGlyphDef altGlyphItem animate animateMotion animateTransform circle clipPath color-profile cursor defs desc discard 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 font font-face font-face-format font-face-name font-face-src font-face-uri foreignObject g glyph glyphRef hkern image line linearGradient marker mask metadata missing-glyph mpath path pattern polygon polyline radialGradient rect script set stop style svg switch symbol text textPath title tref tspan use view vkern".split(" ")) { (SVG)[name] = (...args: Array) => applyElementArgs( document.createElementNS(svgNS, name), args); if (/-/.test(name)) { const snakeCaseName = name.replace(/-/g, "_"); (SVG)[snakeCaseName] = (...args: Array) => applyElementArgs( document.createElementNS(svgNS, name), args); } } }