From b6d959b68111699b5ff5d680dd7af585a625749f Mon Sep 17 00:00:00 2001 From: Bramus Date: Thu, 1 Feb 2024 21:12:08 +0100 Subject: [PATCH 1/5] Fix inheritance of various CSSOM classes - Rename MathOperation to CSSMathValue - Have CSSUnitValue extend CSSNumericValue - Also register CSSMathValue and CSSNumericValue --- src/proxy-cssom.js | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/proxy-cssom.js b/src/proxy-cssom.js index ffcf5db..e705995 100644 --- a/src/proxy-cssom.js +++ b/src/proxy-cssom.js @@ -46,7 +46,7 @@ export function installCSSOM() { return result; } - class MathOperation { + class CSSMathValue { constructor(values, operator, opt_name, opt_delimiter) { privateDetails.set(this, { values: toCssNumericArray(values), @@ -70,14 +70,19 @@ export function installCSSOM() { } } + class CSSNumericValue { + static parse(value) { + return simplifyCalculation(parseCSSNumericValue(value), {}); + } + + // TODO: Add other methods: add, sub, mul, div, … + // Spec: https://drafts.css-houdini.org/css-typed-om/#numeric-value + } + const cssOMTypes = { - 'CSSNumericValue': class { - static parse(value) { - return parseCSSNumericValue(value); - } - }, - 'CSSUnitValue': class { + 'CSSUnitValue': class extends CSSNumericValue { constructor(value, unit) { + super(); privateDetails.set(this, { value: value, unit: unit @@ -126,13 +131,13 @@ export function installCSSOM() { } }, - 'CSSMathSum': class extends MathOperation { + 'CSSMathSum': class extends CSSMathValue { constructor(values) { super(arguments, 'sum', 'calc', ' + '); } }, - 'CSSMathProduct': class extends MathOperation { + 'CSSMathProduct': class extends CSSMathValue { constructor(values) { super(arguments, 'product', 'calc', ' * '); } @@ -148,7 +153,7 @@ export function installCSSOM() { } }, - 'CSSMathNegate': class extends MathOperation { + 'CSSMathNegate': class extends CSSMathValue { constructor(values) { super([arguments[0]], 'negate', '-'); } @@ -158,7 +163,7 @@ export function installCSSOM() { } }, - 'CSSMathInvert': class extends MathOperation { + 'CSSMathInvert': class extends CSSMathValue { constructor(values) { super([1, arguments[0]], 'invert', 'calc', ' / '); } @@ -174,13 +179,13 @@ export function installCSSOM() { } }, - 'CSSMathMax': class extends MathOperation { + 'CSSMathMax': class extends CSSMathValue { constructor() { super(arguments, 'max'); } }, - 'CSSMathMin': class extends MathOperation { + 'CSSMathMin': class extends CSSMathValue { constructor() { super(arguments, 'min'); } @@ -237,10 +242,10 @@ export function installCSSOM() { }); } - for (let type in cssOMTypes) { + for (let [type, value] of Object.entries({'CSSMathValue': CSSMathValue, 'CSSNumericValue': CSSNumericValue, ...cssOMTypes})) { if (type in window) continue; - if (!Reflect.defineProperty(window, type, { value: cssOMTypes[type] })) + if (!Reflect.defineProperty(window, type, { value })) throw Error(`Error installing CSSOM support for ${type}`); } } From 708d1aa280b3b821e8c2acd52235984722d3fbcd Mon Sep 17 00:00:00 2001 From: Bramus Date: Thu, 1 Feb 2024 21:14:42 +0100 Subject: [PATCH 2/5] =?UTF-8?q?Don=E2=80=99t=20parse=20a=20numeric=20value?= =?UTF-8?q?=20if=20it=20already=20is=20a=20CSSNumericValue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/proxy-cssom.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/proxy-cssom.js b/src/proxy-cssom.js index e705995..73b34d2 100644 --- a/src/proxy-cssom.js +++ b/src/proxy-cssom.js @@ -72,6 +72,8 @@ export function installCSSOM() { class CSSNumericValue { static parse(value) { + if (value instanceof CSSNumericValue) return value; + return simplifyCalculation(parseCSSNumericValue(value), {}); } From 8fd46e269e10b33372fd1f998fa5132f2e2e8eb5 Mon Sep 17 00:00:00 2001 From: Bramus Date: Sun, 4 Feb 2024 09:48:00 +0100 Subject: [PATCH 3/5] CSSMathValue should also extend CSSNumericValue --- src/proxy-cssom.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/proxy-cssom.js b/src/proxy-cssom.js index 73b34d2..0c63579 100644 --- a/src/proxy-cssom.js +++ b/src/proxy-cssom.js @@ -46,8 +46,20 @@ export function installCSSOM() { return result; } - class CSSMathValue { + class CSSNumericValue { + static parse(value) { + if (value instanceof CSSNumericValue) return value; + + return simplifyCalculation(parseCSSNumericValue(value), {}); + } + + // TODO: Add other methods: add, sub, mul, div, … + // Spec: https://drafts.css-houdini.org/css-typed-om/#numeric-value + } + + class CSSMathValue extends CSSNumericValue { constructor(values, operator, opt_name, opt_delimiter) { + super(); privateDetails.set(this, { values: toCssNumericArray(values), operator: operator, @@ -70,17 +82,6 @@ export function installCSSOM() { } } - class CSSNumericValue { - static parse(value) { - if (value instanceof CSSNumericValue) return value; - - return simplifyCalculation(parseCSSNumericValue(value), {}); - } - - // TODO: Add other methods: add, sub, mul, div, … - // Spec: https://drafts.css-houdini.org/css-typed-om/#numeric-value - } - const cssOMTypes = { 'CSSUnitValue': class extends CSSNumericValue { constructor(value, unit) { From 211186324a0f623df80e6f29bf53dab157cf9769 Mon Sep 17 00:00:00 2001 From: Robert Flack Date: Fri, 2 Feb 2024 17:13:27 +0000 Subject: [PATCH 4/5] Add CSSMathValue and CSSNumericValue to cssOMTypes directly. --- src/proxy-cssom.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/proxy-cssom.js b/src/proxy-cssom.js index 0c63579..02101e9 100644 --- a/src/proxy-cssom.js +++ b/src/proxy-cssom.js @@ -83,6 +83,8 @@ export function installCSSOM() { } const cssOMTypes = { + 'CSSNumericValue': CSSNumericValue, + 'CSSMathValue': CSSMathValue, 'CSSUnitValue': class extends CSSNumericValue { constructor(value, unit) { super(); @@ -245,7 +247,7 @@ export function installCSSOM() { }); } - for (let [type, value] of Object.entries({'CSSMathValue': CSSMathValue, 'CSSNumericValue': CSSNumericValue, ...cssOMTypes})) { + for (let [type, value] of Object.entries({cssOMTypes})) { if (type in window) continue; if (!Reflect.defineProperty(window, type, { value })) From b22d7fdadc6620dd3224891926adb5b07a53cf58 Mon Sep 17 00:00:00 2001 From: Robert Flack Date: Fri, 2 Feb 2024 19:07:59 +0000 Subject: [PATCH 5/5] Remove object construction - use entries of cssOMTypes. --- src/proxy-cssom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proxy-cssom.js b/src/proxy-cssom.js index 02101e9..33f9268 100644 --- a/src/proxy-cssom.js +++ b/src/proxy-cssom.js @@ -247,7 +247,7 @@ export function installCSSOM() { }); } - for (let [type, value] of Object.entries({cssOMTypes})) { + for (let [type, value] of Object.entries(cssOMTypes)) { if (type in window) continue; if (!Reflect.defineProperty(window, type, { value }))