Skip to content

Commit 8632943

Browse files
domenicclaude
andcommitted
Add resolveProperty callback option
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d798e0a commit 8632943

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

lib/CSSStyleDeclaration.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CSSStyleDeclaration {
2727
* @param {object} [opt] - Options.
2828
* @param {object} [opt.context] - The context object (Window, Element, or CSSRule).
2929
*/
30-
constructor(onChangeCallback, { context } = {}) {
30+
constructor(onChangeCallback, { context, resolveProperty } = {}) {
3131
// Internals for jsdom
3232
this._global = globalThis;
3333
this._onChange = onChangeCallback;
@@ -40,6 +40,10 @@ class CSSStyleDeclaration {
4040
this._readonly = false;
4141
this._updating = false;
4242

43+
// Lazy resolution callback
44+
this._resolveProperty = resolveProperty || null;
45+
this._resolvedValues = resolveProperty ? new Map() : null;
46+
4347
// Other internals
4448
this._length = 0;
4549
this._propertyIndices = new Map();
@@ -243,6 +247,16 @@ class CSSStyleDeclaration {
243247
* @returns {string} The property value, or empty string if not set.
244248
*/
245249
getPropertyValue(property) {
250+
if (this._resolveProperty && this._readonly) {
251+
if (this._resolvedValues.has(property)) {
252+
return this._resolvedValues.get(property);
253+
}
254+
const resolved = this._resolveProperty(property);
255+
if (resolved !== undefined) {
256+
this._resolvedValues.set(property, resolved);
257+
return resolved;
258+
}
259+
}
246260
if (this._values.has(property)) {
247261
return this._values.get(property).toString();
248262
}

0 commit comments

Comments
 (0)