Skip to content

Commit cf7e79a

Browse files
committed
Enhance CSSStyleDeclaration constructor options
1 parent d798e0a commit cf7e79a

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

lib/CSSStyleDeclaration.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,46 @@ class CSSStyleDeclaration {
2323
/**
2424
* Creates a new CSSStyleDeclaration instance.
2525
*
26+
* TODO: constructor(globalObject, args, { computed, context, ... })
2627
* @param {Function} [onChangeCallback] - Callback triggered when style changes.
2728
* @param {object} [opt] - Options.
28-
* @param {object} [opt.context] - The context object (Window, Element, or CSSRule).
29+
* @param {boolean} [opt.computed] - The computed flag.
30+
* @param {object} [opt.context] - The context object (Element, or CSSRule).
31+
* @param {object} [opt.globalObject] - The global object, i.e.) Window.
32+
* @param {number} [opt.fontSizeMedium] - The medium font size in pixels.
33+
* @param {object} [opt.systemColors] - The system colors.
2934
*/
30-
constructor(onChangeCallback, { context } = {}) {
31-
// Internals for jsdom
32-
this._global = globalThis;
35+
constructor(onChangeCallback, { computed, context, globalObject, fontSizeMedium, systemColors } = {}) {
36+
// Internals for jsdom.
37+
// TODO: Remove globalThis fallback.
38+
this._global = globalObject ?? globalThis;
3339
this._onChange = onChangeCallback;
40+
this._fontSizeMedium = fontSizeMedium;
41+
this._systemColors = systemColors;
3442

35-
// Internals for CSS declaration block
43+
// Internals for CSS declaration block.
3644
// @see https://drafts.csswg.org/cssom/#css-declaration-blocks
37-
this._computed = false;
45+
this._computed = Boolean(computed);
3846
this._ownerNode = null;
3947
this._parentRule = null;
4048
this._readonly = false;
4149
this._updating = false;
4250

43-
// Other internals
51+
// Other internals.
4452
this._length = 0;
4553
this._propertyIndices = new Map();
4654
this._priorities = new Map();
4755
this._values = new Map();
4856

57+
// Options for computed style.
58+
// TODO: Add private method to prepare options.
59+
this._computedStyleOpts = null;
60+
4961
if (context) {
50-
if (typeof context.getComputedStyle === "function") {
51-
this._global = context;
52-
this._computed = true;
53-
// FIXME: The `_readonly` flag should initially be `false` to be editable,
54-
// but should eventually be set to `true`.
55-
// this._readonly = true;
56-
} else if (context.nodeType === 1 && Object.hasOwn(context, "style")) {
57-
this._global = context.ownerDocument.defaultView;
62+
if (context.nodeType === 1) {
5863
this._ownerNode = context;
5964
} else if (Object.hasOwn(context, "parentRule")) {
6065
this._parentRule = context;
61-
// Find Window from the owner node of the StyleSheet.
62-
const window = context?.parentStyleSheet?.ownerNode?.ownerDocument?.defaultView;
63-
if (window) {
64-
this._global = window;
65-
}
6666
}
6767
}
6868
}
@@ -318,7 +318,7 @@ class CSSStyleDeclaration {
318318
this.removeProperty(property);
319319
return;
320320
}
321-
// Custom property
321+
// Custom property.
322322
if (property.startsWith("--")) {
323323
this._setProperty(property, value, priority);
324324
return;

0 commit comments

Comments
 (0)