Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions lib/CSSStyleDeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,45 @@ class CSSStyleDeclaration {
/**
* Creates a new CSSStyleDeclaration instance.
*
* @param {Function} [onChangeCallback] - Callback triggered when style changes.
* @param {object} globalObject - The global object (Window).
* @param {Array} args - The arguments (not actually used).
* @param {object} [opt] - Options.
* @param {object} [opt.context] - The context object (Window, Element, or CSSRule).
* @param {boolean} [opt.computed] - The computed flag.
* @param {object} [opt.context] - The context object (Element, or CSSRule).
* @param {number} [opt.fontSizeMedium] - Font size in pixels for the keyword "medium".
* @param {Function} [opt.onChangeCallback] - Callback triggered when style changes.
* @param {object} [opt.systemColors] - The system colors.
*/
constructor(onChangeCallback, { context } = {}) {
// Internals for jsdom
this._global = globalThis;
constructor(globalObject, args, { computed, context, fontSizeMedium, onChangeCallback, systemColors } = {}) {
// Internals for jsdom.
this._global = globalObject;
this._onChange = onChangeCallback;
this._fontSizeMedium = fontSizeMedium;
this._systemColors = systemColors;

// Internals for CSS declaration block
// Internals for CSS declaration block.
// @see https://drafts.csswg.org/cssom/#css-declaration-blocks
this._computed = false;
this._computed = Boolean(computed);
this._ownerNode = null;
this._parentRule = null;
this._readonly = false;
this._updating = false;

// Other internals
// Other internals.
this._length = 0;
this._propertyIndices = new Map();
this._priorities = new Map();
this._values = new Map();

// TODO: Add private method to prepare options.
// Options for computed style.
this._computedStyleOpts = null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this for now, at least until something is actually using it?


if (context) {
if (typeof context.getComputedStyle === "function") {
this._global = context;
this._computed = true;
// FIXME: The `_readonly` flag should initially be `false` to be editable,
// but should eventually be set to `true`.
// this._readonly = true;
} else if (context.nodeType === 1 && Object.hasOwn(context, "style")) {
this._global = context.ownerDocument.defaultView;
if (context.nodeType === 1) {
this._ownerNode = context;
} else if (Object.hasOwn(context, "parentRule")) {
this._parentRule = context;
// Find Window from the owner node of the StyleSheet.
const window = context?.parentStyleSheet?.ownerNode?.ownerDocument?.defaultView;
if (window) {
this._global = window;
}
}
}
}
Expand Down Expand Up @@ -318,7 +317,7 @@ class CSSStyleDeclaration {
this.removeProperty(property);
return;
}
// Custom property
// Custom property.
if (property.startsWith("--")) {
this._setProperty(property, value, priority);
return;
Expand Down
Loading