fn
assignStyle
v0.0.5Merges a style patch onto an element's inline style and returns
a cleanup function that restores the element's entire previous cssText.
Unlike setStyle, the snapshot is the full cssText, so the cleanup is
an all-or-nothing revert — handy for scoped effects.
Example
ts
const restore = assignStyle(document.body, { overflow: 'hidden' });
// ...later
restore();Signature
ts
declare function assignStyle(element: HTMLElement | null | undefined, style: Partial<CSSStyleDeclaration>): () => void;Parameters
| Parameter | Type | Description |
|---|---|---|
element | HTMLElement | null | undefined | The element to style |
style | Partial<CSSStyleDeclaration> | The element to style |
Returns
() => voidA cleanup function that restores the previous cssText