-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4add426
commit 511b4d7
Showing
5 changed files
with
173 additions
and
3,735 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
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
export function setAttributes(el: HTMLElement, attrs: any) { | ||
const { class: className, style, ...otherAttrs } = attrs; | ||
|
||
delete otherAttrs.key; | ||
|
||
if (className) { | ||
setClass(el, className); | ||
} | ||
|
||
if (style) { | ||
Object.entries(style).forEach(([prop, value]) => { | ||
setStyle(el, prop, value); | ||
}); | ||
} | ||
|
||
for (const [name, value] of Object.entries(otherAttrs)) { | ||
setAttribute(el, name, value); | ||
} | ||
} | ||
|
||
export function setAttribute(el: HTMLElement, name: string, value: any) { | ||
if (!value) { | ||
removeAttribute(el, name); | ||
} else { | ||
el.setAttribute(name, value); | ||
} | ||
} | ||
|
||
export function removeAttribute(el: HTMLElement, name: string) { | ||
try { | ||
//@ts-expect-error | ||
el[name] = null; | ||
} catch { | ||
console.warn(`Failed to set "${name}" to null on ${el.tagName}`); | ||
} | ||
|
||
el.removeAttribute(name); | ||
} | ||
|
||
export function setStyle(el: HTMLElement, name: any, value: any) { | ||
el.style[name] = value; | ||
} | ||
|
||
export function removeStyle(el: HTMLElement, name: string) { | ||
//@ts-expect-error | ||
el.style[name] = null; | ||
} | ||
|
||
function setClass(el: HTMLElement, className: string | string[]) { | ||
el.className = ""; | ||
|
||
if (typeof className === "string") { | ||
el.className = className; | ||
} | ||
|
||
if (Array.isArray(className)) { | ||
el.classList.add(...className); | ||
} | ||
} |
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,3 +1,2 @@ | ||
export * from "./h"; | ||
export * from "./mount-dom"; | ||
export * from "./app"; |
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
Oops, something went wrong.