@wordpress/interactivity-router
Version:
Package that exposes state and actions from the `core/router` store, part of the Interactivity API.
71 lines • 2.98 kB
TypeScript
export type StyleElement = HTMLLinkElement | HTMLStyleElement;
/**
* Normalizes the passed style or link element, reverting the changes
* made by {@link prepareStylePromise|`prepareStylePromise`} to the
* `data-original-media` and `media`.
*
* @example
* The following elements should be normalized to the same element:
* ```html
* <link rel="stylesheet" src="./assets/styles.css">
* <link rel="stylesheet" src="./assets/styles.css" media="all">
* <link rel="stylesheet" src="./assets/styles.css" media="preload">
* <link rel="stylesheet" src="./assets/styles.css" media="preload" data-original-media="all">
* ```
*
* @param element `<style>` or `<link>` element.
* @return Normalized node.
*/
export declare const normalizeMedia: (element: StyleElement) => StyleElement;
/**
* Adds the minimum style elements from Y around those in X using a
* shortest common supersequence algorithm, returning a list of
* promises for all the elements in Y.
*
* If X is empty, it appends all elements in Y to the passed parent
* element or to `document.head` instead.
*
* The returned promises resolve once the corresponding style element
* is loaded and ready. Those elements that are also in X return a
* cached promise.
*
* The algorithm ensures that the final style elements present in the
* document (or the passed `parent` element) are in the correct order
* and they are included in either X or Y.
*
* @param X Base list of style elements.
* @param Y List of style elements.
* @param parent Optional parent element to append to the new style elements.
* @return List of promises that resolve once the elements in Y are ready.
*/
export declare function updateStylesWithSCS(X: StyleElement[], Y: StyleElement[], parent?: Element): any[];
/**
* Prepares all style elements contained in the passed document.
*
* This function calls {@link updateStylesWithSCS|`updateStylesWithSCS`}
* to insert only the minimum amount of style elements into the DOM, so
* those present in the passed document end up in the DOM while the order
* is respected.
*
* New appended style elements contain a `media=preload` attribute to
* make them effectively disabled until they are applied with the
* {@link applyStyles|`applyStyles`} function.
*
* Note that this function alters the passed document, as it can transfer
* nodes from it to the global document.
*
* @param doc Document instance.
* @return A list of promises for each style element in the passed document.
*/
export declare const preloadStyles: (doc: Document) => Promise<StyleElement>[];
/**
* Traverses all style elements in the DOM, enabling only those included
* in the passed list and disabling the others.
*
* If the style element has the `data-original-media` attribute, the
* original `media` value is restored.
*
* @param styles List of style elements to apply.
*/
export declare const applyStyles: (styles: StyleElement[]) => void;
//# sourceMappingURL=styles.d.ts.map