All files / player-browser/src/view/shared dom-style.ts

100% Statements 4/4
100% Branches 4/4
100% Functions 2/2
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21                          3x         3x    
/** Inline style properties {@link setStyle} writes. */
export type StyleProperty = Exclude<
  {
    [Key in keyof CSSStyleDeclaration]: CSSStyleDeclaration[Key] extends string ? Key : never;
  }[keyof CSSStyleDeclaration],
  'cssText' | 'cssFloat'
>;
 
/**
 * Sets an inline style property only when it differs, so an overlay redrawn every frame leaves the style (and the
 * layout behind it) alone while nothing moves.
 */
export function setStyle(element: HTMLElement, property: StyleProperty, value: string): void {
  if (element.style[property] !== value) element.style[property] = value;
}
 
/** Sets `element.hidden` only when it differs. */
export function setHidden(element: HTMLElement, hidden: boolean): void {
  if (element.hidden !== hidden) element.hidden = hidden;
}