- From: Daniil Sakhapov via GitHub <sysbot+gh@w3.org>
- Date: Mon, 05 May 2025 12:56:18 +0000
- To: public-css-archive@w3.org
danielsakhapov has just created a new issue for https://github.com/w3c/csswg-drafts: == Add a property to the CSSPseudoElement IDL interface to determine if a pseudo element "exists" == Full context: https://github.com/danielsakhapov/CSSPseudoElementDoc?tab=readme-ov-file#21-existence-confusion Description: [CSSPseudoElement](https://www.w3.org/TR/css-pseudo-4/#CSSPseudoElement-interface) object is returned from [pseudo(type)](https://www.w3.org/TR/css-pseudo-4/#window-interface) if `type` is parsed correctly, whether the corresponding pseudo element is rendered or not doesn't matter. Developers might need a clear way to distinguish if the pseudo element is being "live" or rendered. Possible Solutions: * A dedicated `exists` property or `isGenerated()` method: * `pseudoElement.exists` (nullable boolean, read-only) * **Pros:** Explicit and clear, allows to specify the return value on a per pseudo element basis. * **Cons:** Adds new API surface. Defining "exists" precisely across all pseudo element types can be tricky (e.g., does `::selection` "exist" if nothing is selected but it could be styled? - potentially return `null` here). * `getComputedStyle()` inspection: * Check `getComputedStyle(pseudoElement).display !== 'none'`. For `::before`/`::after`, also check `getComputedStyle(pseudoElement).content !== 'none'`. * **Pros:** Uses existing mechanisms. * **Cons:** Indirect; might not cover all cases (e.g., a pseudo element that exists but has 0x0 dimensions and no visual content). For highlight pseudos, "display" might not be the relevant property. Sometimes depends on the originating element style. * Layout Information: * Methods like a hypothetical `pseudoElement.getBoundingClientRects()` returning an empty list or specific values could indicate non-existence or non-rendering. * **Pros:** Provides practical information. * **Cons:** Might be expensive to compute just for an existence check. **Recommendation:** Go with `exists`, as it gives more control for each pseudo element while unifying an interface to get the needed information. As new pseudo elements are added to be returned from `pseudo()`, the spec will be updated to define the meaning of `exists` for them. Otherwise: Relying on `getComputedStyle()` initially seems pragmatic, given the limited list of pseudos supported currently. For highlight pseudos, "existence" might mean "has associated ranges/segments." Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/12158 using your GitHub account -- Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Monday, 5 May 2025 12:56:19 UTC