Skip to content

Add CSSStyleDeclaration injection API for parsed rule styles#97

Open
domenic wants to merge 2 commits intoacemir:masterfrom
domenic:add-style-declaration-injection-api
Open

Add CSSStyleDeclaration injection API for parsed rule styles#97
domenic wants to merge 2 commits intoacemir:masterfrom
domenic:add-style-declaration-injection-api

Conversation

@domenic
Copy link

@domenic domenic commented Mar 3, 2026

Summary

  • add a styleDeclarationProvider abstraction to resolve the declaration constructor used when creating rule style objects
  • add public APIs in lib/index.js:
    • getCSSStyleDeclaration()
    • setCSSStyleDeclaration(CSSStyleDeclaration)
    • resetCSSStyleDeclaration()
  • extend setup() to accept CSSStyleDeclaration and wire it via provider
  • switch rule/clone construction sites to use the provider-backed constructor dynamically (avoids module load-order capture)
  • keep existing optional cssstyle fallback behavior by routing it through the same provider
  • document usage in README.mdown

Why

Consumers like jsdom need to inject their own CSSStyleDeclaration implementation. Reassigning require("@acemir/cssom/lib/CSSStyleDeclaration").CSSStyleDeclaration is not reliable because multiple modules capture constructor references during module initialization.

This PR provides an explicit integration point so parser-created rule declarations are consistently constructed with the consumer-provided class.

Validation

  • npm run build
  • runtime smoke checks from Node confirming:
    • default path still works
    • setup({ CSSStyleDeclaration }) causes parsed rule styles to use the injected constructor

@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2026

🦋 Changeset detected

Latest commit: e61c941

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@acemir/cssom Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@domenic
Copy link
Author

domenic commented Mar 3, 2026

This lets us remove the workaround from jsdom/jsdom#4089

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant