mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { StateAttrMap } from "../../core/ui/types.js";
|
|
//#region src/dom/utils/state-data-attrs.d.ts
|
|
/**
|
|
* Convert state object to data attributes.
|
|
*
|
|
* - `true` → `data-keyname=""`
|
|
* - truthy string/number → `data-keyname="value"`
|
|
* - falsy → no attribute
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* const state = { paused: true, ended: false, volume: 0.5 };
|
|
* getStateDataAttrs(state);
|
|
* // { 'data-paused': '', 'data-volume': '0.5' }
|
|
* ```
|
|
*
|
|
* When a mapping is provided, only mapped keys are converted.
|
|
*/
|
|
declare function getStateDataAttrs<State extends object>(state: State, map?: StateAttrMap<State>): Record<string, string>;
|
|
/**
|
|
* Apply state as data attributes to an element.
|
|
*
|
|
* - `true` → sets `data-keyname=""`
|
|
* - truthy string/number → sets `data-keyname="value"`
|
|
* - falsy → removes the attribute
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* const state = { paused: true, ended: false };
|
|
* applyStateDataAttrs(element, state);
|
|
* // element has data-paused="", data-ended is removed
|
|
* ```
|
|
*/
|
|
declare function applyStateDataAttrs<State extends object>(element: HTMLElement, state: State, map?: StateAttrMap<State>): void;
|
|
//#endregion
|
|
export { applyStateDataAttrs, getStateDataAttrs };
|
|
//# sourceMappingURL=state-data-attrs.d.ts.map
|