fn

assignStyle

v0.0.5tested

Merges 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
export function assignStyle(element: HTMLElement | null | undefined, style: Partial<CSSStyleDeclaration>): () => void{ ... }

Parameters

ParameterTypeDescription
elementHTMLElement | null | undefinedThe element to style
stylePartial<CSSStyleDeclaration>The element to style

Returns

() => voidA cleanup function that restores the previous cssText