UNPKG

@oddbird/css-anchor-positioning

Version:

Polyfill for the proposed CSS anchor positioning spec

69 lines (68 loc) 2.65 kB
import { type VirtualElement } from '@floating-ui/dom'; import { type AnchorPositioningRoot } from './polyfill.js'; /** * Representation of a CSS selector that allows getting the element part and * pseudo-element part. */ export interface Selector { selector: string; elementPart: string; pseudoElementPart?: string; } /** * Used instead of an HTMLElement as a handle for pseudo-elements. */ export interface PseudoElement extends VirtualElement { fakePseudoElement: HTMLElement; computedStyle: CSSStyleDeclaration; removeFakePseudoElement(): void; } /** * Possible values for `anchor-scope` * (in addition to any valid dashed identifier) */ export declare const enum AnchorScopeValue { All = "all", None = "none" } /** * Gets the computed value of a CSS property for an element or pseudo-element. * * Note: values for properties that are not natively supported are *always* * subject to CSS inheritance. */ export declare function getCSSPropertyValue(el: HTMLElement | PseudoElement, prop: string): string; /** * Checks whether a given element or pseudo-element has the given property * value. * * Note: values for properties that are not natively supported are *always* * subject to CSS inheritance. */ export declare function hasStyle(element: HTMLElement | PseudoElement, cssProperty: string, value: string): boolean; /** * Like `document.querySelectorAll`, but if the selector has a pseudo-element it * will return a wrapper for the rest of the polyfill to use. */ export declare function getElementsBySelector(selector: Selector, options: { roots: AnchorPositioningRoot[]; }): (HTMLElement | PseudoElement)[]; /** * Checks whether the given element has the given anchor name, based on the * element's computed style. * * Note: because our `--anchor-name` custom property inherits, this function * should only be called for elements which are known to have an explicitly set * value for `anchor-name`. */ export declare function hasAnchorName(el: PseudoElement | HTMLElement, anchorName: string | null): boolean; /** * Checks whether the given element serves as a scope for the given anchor. * * Note: because our `--anchor-scope` custom property inherits, this function * should only be called for elements which are known to have an explicitly set * value for `anchor-scope`. */ export declare function hasAnchorScope(el: PseudoElement | HTMLElement, anchorName: string): boolean; export declare const getOffsetParent: (el: HTMLElement) => Promise<HTMLElement>; export declare const querySelectorAllRoots: (roots: AnchorPositioningRoot[], selector: string) => HTMLElement[];