🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@seahax/elemental

Package Overview
Dependencies
Maintainers
2
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@seahax/elemental - npm Package Compare versions

Comparing version
0.8.6
to
0.8.7
+2
-2
dist/html.d.ts

@@ -17,4 +17,4 @@ type Alpha = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';

*/
export declare function html<TElement extends keyof TagMap | (string & {}) | CustomElementConstructor | Element | Document | ShadowRoot>(el: TElement, config?: HtmlConfig<TElement>, children?: HtmlChildren): ElementType<NoInfer<TElement>>;
export declare function html<TElement extends keyof TagMap | (string & {}) | CustomElementConstructor | Element | Document | ShadowRoot>(el: TElement, children?: HtmlChildren): ElementType<TElement>;
export declare function html<TElement extends keyof TagMap | (string & {}) | CustomElementConstructor | Element | Document | ShadowRoot>(el: TElement, config?: HtmlConfig<TElement>, children?: HtmlChildren | HtmlSingleChild): ElementType<NoInfer<TElement>>;
export declare function html<TElement extends keyof TagMap | (string & {}) | CustomElementConstructor | Element | Document | ShadowRoot>(el: TElement, children?: HtmlChildren | HtmlSingleChild): ElementType<TElement>;
export {};
//#region src/html.ts
function e(e, t = {}, n) {
function e(e, r = {}, i) {
if (typeof e == "function") {

@@ -8,5 +8,5 @@ let t = customElements.getName(e);

typeof e == "string" && (e = document.createElement(e));
let r;
if ([r, n] = Array.isArray(t) ? [{}, t] : [t, n], "setAttribute" in e) {
for (let [t, n] of Object.entries(r)) if (!(n === void 0 || t.startsWith(":"))) if (n === null || n === !1) e.hasAttribute(t) && e.removeAttribute(t);
let a;
if (t(r) || n(r) ? (a = {}, i = r) : a = r ?? {}, "setAttribute" in e) {
for (let [t, n] of Object.entries(a)) if (!(n === void 0 || t.startsWith(":"))) if (n === null || n === !1) e.hasAttribute(t) && e.removeAttribute(t);
else {

@@ -21,3 +21,3 @@ let r = n == 1 ? "" : String(n);

}
for (let [t, n] of Object.entries(r)) {
for (let [t, n] of Object.entries(a)) {
if (n === void 0 || !t.startsWith(":")) continue;

@@ -27,8 +27,14 @@ let r = t.slice(1);

}
if (n) {
let t = n.flat(1).filter((e) => e != null && e !== !1).map((e) => typeof e == "object" ? e : document.createTextNode(String(e)));
e.replaceChildren(...t);
if (i !== void 0) {
let n = (t(i) ? i.flat(1) : [i]).filter((e) => e != null && e !== !1).map((e) => typeof e == "object" ? e : document.createTextNode(String(e)));
e.replaceChildren(...n);
}
return e;
}
function t(e) {
return Array.isArray(e);
}
function n(e) {
return typeof e != "object" || !e || e instanceof Node;
}
//#endregion

@@ -35,0 +41,0 @@ export { e as html };

@@ -1,1 +0,1 @@

{"version":3,"file":"html.js","names":[],"sources":["../src/html.ts"],"sourcesContent":["// prettier-ignore\ntype Alpha = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';\ntype AttrValue = string | number | bigint | boolean | null | undefined;\ntype TagMap = HTMLElementTagNameMap & HTMLElementDeprecatedTagNameMap;\n\ntype IfEquals<T, U, Y = unknown, N = never> =\n (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? Y : N;\n\ntype Props<TElement> = {\n readonly [P in keyof TElement & string as TElement[P] extends ((...args: any[]) => any) | null | undefined\n ? never\n : IfEquals<Record<P, TElement[P]>, Pick<TElement, P>, `:${P}`, never>]?: TElement[P];\n};\n\ntype Attrs<TElement> = TElement extends string | CustomElementConstructor | Element\n ? Readonly<Record<`${Alpha}${string}`, AttrValue>>\n : {};\n\nexport type HtmlSingleChild = Node | string | number | bigint | false | null | undefined;\nexport type HtmlChild = HtmlSingleChild | readonly HtmlSingleChild[];\nexport type HtmlChildren = readonly HtmlChild[];\nexport type HtmlConfig<TElement> = Attrs<TElement> & Props<ElementType<TElement>>;\n\nexport type ElementType<TElement> = TElement extends string\n ? TElement extends keyof TagMap\n ? TagMap[TElement]\n : HTMLElement\n : TElement extends CustomElementConstructor\n ? InstanceType<TElement>\n : TElement extends Element | Document | ShadowRoot\n ? TElement\n : never;\n\n/**\n * Create or update an HTML element.\n */\nexport function html<\n TElement extends keyof TagMap | (string & {}) | CustomElementConstructor | Element | Document | ShadowRoot,\n>(el: TElement, config?: HtmlConfig<TElement>, children?: HtmlChildren): ElementType<NoInfer<TElement>>;\nexport function html<\n TElement extends keyof TagMap | (string & {}) | CustomElementConstructor | Element | Document | ShadowRoot,\n>(el: TElement, children?: HtmlChildren): ElementType<TElement>;\n\nexport function html(\n el: string | CustomElementConstructor | Element | Document | ShadowRoot,\n configOrChildren: HtmlChildren | Readonly<Record<string, any>> = {},\n children?: HtmlChildren,\n): Node {\n if (typeof el === 'function') {\n let name = customElements.getName(el);\n\n if (name == null) {\n name = `ce-${crypto.randomUUID()}`;\n customElements.define(name, el);\n }\n\n el = name;\n }\n\n if (typeof el === 'string') el = document.createElement(el);\n\n let config: Readonly<Record<string, any>>;\n [config, children] = Array.isArray(configOrChildren)\n ? [{}, configOrChildren as HtmlChildren]\n : [configOrChildren as Readonly<Record<string, any>>, children];\n\n if ('setAttribute' in el) {\n for (const [name, rawValue] of Object.entries(config)) {\n if (rawValue === undefined || name.startsWith(':')) continue;\n\n if (rawValue === null || rawValue === false) {\n if (el.hasAttribute(name)) el.removeAttribute(name);\n } else {\n const value = rawValue == true ? '' : String(rawValue);\n if (el.getAttribute(name) !== value) {\n try {\n el.setAttribute(name, value);\n } catch (error) {\n console.warn(error);\n }\n }\n }\n }\n }\n\n for (const [rawName, value] of Object.entries(config)) {\n if (value === undefined || !rawName.startsWith(':')) continue;\n const name = rawName.slice(1);\n if (Reflect.get(el, name) !== value) Reflect.set(el, name, value);\n }\n\n if (children) {\n const childNodes = children\n .flat(1)\n .filter((child) => child != null && child !== false)\n .map((child) => (typeof child !== 'object' ? document.createTextNode(String(child)) : child));\n\n el.replaceChildren(...childNodes);\n }\n\n return el;\n}\n"],"mappings":";AA2CA,SAAgB,EACd,GACA,IAAiE,EAAE,EACnE,GACM;AACN,KAAI,OAAO,KAAO,YAAY;EAC5B,IAAI,IAAO,eAAe,QAAQ,EAAG;AAOrC,EALI,MACF,IAAO,MAAM,OAAO,YAAY,IAChC,eAAe,OAAO,GAAM,EAAG,GAGjC,IAAK;;AAGP,CAAI,OAAO,KAAO,aAAU,IAAK,SAAS,cAAc,EAAG;CAE3D,IAAI;AAKJ,KAJA,CAAC,GAAQ,KAAY,MAAM,QAAQ,EAAiB,GAChD,CAAC,EAAE,EAAE,EAAiC,GACtC,CAAC,GAAmD,EAAS,EAE7D,kBAAkB,GACpB;OAAK,IAAM,CAAC,GAAM,MAAa,OAAO,QAAQ,EAAO,CAC/C,aAAa,KAAA,KAAa,EAAK,WAAW,IAAI,EAElD,KAAI,MAAa,QAAQ,MAAa,IAChC,EAAG,aAAa,EAAK,IAAE,EAAG,gBAAgB,EAAK;OAC9C;GACL,IAAM,IAAQ,KAAY,IAAO,KAAK,OAAO,EAAS;AACtD,OAAI,EAAG,aAAa,EAAK,KAAK,EAC5B,KAAI;AACF,MAAG,aAAa,GAAM,EAAM;YACrB,GAAO;AACd,YAAQ,KAAK,EAAM;;;;AAO7B,MAAK,IAAM,CAAC,GAAS,MAAU,OAAO,QAAQ,EAAO,EAAE;AACrD,MAAI,MAAU,KAAA,KAAa,CAAC,EAAQ,WAAW,IAAI,CAAE;EACrD,IAAM,IAAO,EAAQ,MAAM,EAAE;AAC7B,EAAI,QAAQ,IAAI,GAAI,EAAK,KAAK,KAAO,QAAQ,IAAI,GAAI,GAAM,EAAM;;AAGnE,KAAI,GAAU;EACZ,IAAM,IAAa,EAChB,KAAK,EAAE,CACP,QAAQ,MAAU,KAAS,QAAQ,MAAU,GAAM,CACnD,KAAK,MAAW,OAAO,KAAU,WAAoD,IAAzC,SAAS,eAAe,OAAO,EAAM,CAAC,CAAU;AAE/F,IAAG,gBAAgB,GAAG,EAAW;;AAGnC,QAAO"}
{"version":3,"file":"html.js","names":[],"sources":["../src/html.ts"],"sourcesContent":["// prettier-ignore\ntype Alpha = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';\ntype AttrValue = string | number | bigint | boolean | null | undefined;\ntype TagMap = HTMLElementTagNameMap & HTMLElementDeprecatedTagNameMap;\n\ntype IfEquals<T, U, Y = unknown, N = never> =\n (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? Y : N;\n\ntype Props<TElement> = {\n readonly [P in keyof TElement & string as TElement[P] extends ((...args: any[]) => any) | null | undefined\n ? never\n : IfEquals<Record<P, TElement[P]>, Pick<TElement, P>, `:${P}`, never>]?: TElement[P];\n};\n\ntype Attrs<TElement> = TElement extends string | CustomElementConstructor | Element\n ? Readonly<Record<`${Alpha}${string}`, AttrValue>>\n : {};\n\nexport type HtmlSingleChild = Node | string | number | bigint | false | null | undefined;\nexport type HtmlChild = HtmlSingleChild | readonly HtmlSingleChild[];\nexport type HtmlChildren = readonly HtmlChild[];\nexport type HtmlConfig<TElement> = Attrs<TElement> & Props<ElementType<TElement>>;\n\nexport type ElementType<TElement> = TElement extends string\n ? TElement extends keyof TagMap\n ? TagMap[TElement]\n : HTMLElement\n : TElement extends CustomElementConstructor\n ? InstanceType<TElement>\n : TElement extends Element | Document | ShadowRoot\n ? TElement\n : never;\n\n/**\n * Create or update an HTML element.\n */\nexport function html<\n TElement extends keyof TagMap | (string & {}) | CustomElementConstructor | Element | Document | ShadowRoot,\n>(\n el: TElement,\n config?: HtmlConfig<TElement>,\n children?: HtmlChildren | HtmlSingleChild,\n): ElementType<NoInfer<TElement>>;\nexport function html<\n TElement extends keyof TagMap | (string & {}) | CustomElementConstructor | Element | Document | ShadowRoot,\n>(el: TElement, children?: HtmlChildren | HtmlSingleChild): ElementType<TElement>;\n\nexport function html(\n el: string | CustomElementConstructor | Element | Document | ShadowRoot,\n configOrChildren: HtmlChildren | HtmlSingleChild | Readonly<Record<string, any>> = {},\n children?: HtmlChildren | HtmlSingleChild,\n): Node {\n if (typeof el === 'function') {\n let name = customElements.getName(el);\n\n if (name == null) {\n name = `ce-${crypto.randomUUID()}`;\n customElements.define(name, el);\n }\n\n el = name;\n }\n\n if (typeof el === 'string') el = document.createElement(el);\n\n let config: Readonly<Record<string, any>>;\n\n if (isChildren(configOrChildren) || isChild(configOrChildren)) {\n config = {};\n children = configOrChildren;\n } else {\n config = configOrChildren ?? {};\n }\n\n if ('setAttribute' in el) {\n for (const [name, rawValue] of Object.entries(config)) {\n if (rawValue === undefined || name.startsWith(':')) continue;\n\n if (rawValue === null || rawValue === false) {\n if (el.hasAttribute(name)) el.removeAttribute(name);\n } else {\n const value = rawValue == true ? '' : String(rawValue);\n if (el.getAttribute(name) !== value) {\n try {\n el.setAttribute(name, value);\n } catch (error) {\n console.warn(error);\n }\n }\n }\n }\n }\n\n for (const [rawName, value] of Object.entries(config)) {\n if (value === undefined || !rawName.startsWith(':')) continue;\n const name = rawName.slice(1);\n if (Reflect.get(el, name) !== value) Reflect.set(el, name, value);\n }\n\n if (children !== undefined) {\n const childNodes = (isChildren(children) ? children.flat(1) : [children])\n .filter((child) => child != null && child !== false)\n .map((child) => (typeof child !== 'object' ? document.createTextNode(String(child)) : child));\n\n el.replaceChildren(...childNodes);\n }\n\n return el;\n}\n\nfunction isChildren(value: any): value is HtmlChildren {\n return Array.isArray(value);\n}\n\nfunction isChild(value: any): value is HtmlSingleChild {\n return value === null || typeof value !== 'object' || value instanceof Node;\n}\n"],"mappings":";AA+CA,SAAgB,EACd,GACA,IAAmF,EAAE,EACrF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