import { isCacheDisabled } from './cache.js'; import { getShorthandDepth } from './shorthand.js'; import type { Bucket, StyleSheetOpts } from './types.js'; /** * Ordered style buckets using their short pseudo name. * * This is very bare-bones, with no support for nesting, like styles in * `@media` queries, pseudo-selectors mixed with shorthand properties, etc. * * If changes are needed to the pseudo-selectors, make sure that it aligns with the * definition in `packages/css/src/utils/style-ordering.ts`. */ export const styleBucketOrdering: Bucket[] = [ // shorthand properties 's-0', 's-1', 's-2', 's-3', 's-4', 's-5', // catch-all '', // link 'l', // visited 'v', // focus-within 'w', // focus 'f', // focus-visible 'i', // hover 'h', // active 'a', // at-rules 'm', ]; /** * Holds all style buckets in memory that have been added to the head. */ const styleBucketsInHead: Partial> = {}; /** * Maps the long pseudo name to the short pseudo name. * Pseudos that match here will be ordered, * everything else will make their way to the catch all style bucket. * We reduce the pseudo name to save bundlesize. * Thankfully there aren't any overlaps, see: https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes. */ const pseudosMap: Record = { // link k: 'l', // visited ited: 'v', // focus-within 'us-within': 'w', // focus us: 'f', // focus-visible 'us-visible': 'i', // hover er: 'h', // active ive: 'a', }; /** * Holds style buckets per custom container (e.g. a ShadowRoot), keyed by the * container DOM node. Uses WeakMap so entries are garbage collected when the * container is removed from the page. */ const styleBucketsByContainer = new WeakMap< HTMLElement | ShadowRoot, Partial> >(); /** * Lazily adds a `