mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
23 lines
996 B
JavaScript
23 lines
996 B
JavaScript
import { listen } from "@videojs/utils/dom";
|
|
import { isFunction, isUndefined } from "@videojs/utils/predicate";
|
|
//#region src/dom/utils/element-props.ts
|
|
/**
|
|
* Apply props to a DOM element.
|
|
*
|
|
* Handles both attributes and event listeners:
|
|
* - Event props (onClick, onKeyDown, etc.) are attached as listeners
|
|
* - Boolean props: `true` sets empty attribute, `false` removes
|
|
* - `undefined` removes the attribute
|
|
* - Other props are set as string attributes
|
|
*/
|
|
function applyElementProps(element, props, options) {
|
|
const signal = options?.signal;
|
|
for (const [key, value] of Object.entries(props)) if (isFunction(value) && key.startsWith("on")) listen(element, key.slice(2).toLowerCase(), value, signal ? { signal } : void 0);
|
|
else if (isUndefined(value) || value === false) element.removeAttribute(key);
|
|
else if (value === true) element.setAttribute(key, "");
|
|
else element.setAttribute(key, String(value));
|
|
}
|
|
//#endregion
|
|
export { applyElementProps };
|
|
|
|
//# sourceMappingURL=element-props.js.map
|