Skip to content
Merged
Changes from all 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
40 changes: 25 additions & 15 deletions src/proxy-cssom.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,20 @@ export function installCSSOM() {
return result;
}

class MathOperation {
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,
Expand All @@ -71,13 +83,11 @@ export function installCSSOM() {
}

const cssOMTypes = {
'CSSNumericValue': class {
static parse(value) {
return parseCSSNumericValue(value);
}
},
'CSSUnitValue': class {
'CSSNumericValue': CSSNumericValue,
'CSSMathValue': CSSMathValue,
'CSSUnitValue': class extends CSSNumericValue {
constructor(value, unit) {
super();
privateDetails.set(this, {
value: value,
unit: unit
Expand Down Expand Up @@ -126,13 +136,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', ' * ');
}
Expand All @@ -148,7 +158,7 @@ export function installCSSOM() {
}
},

'CSSMathNegate': class extends MathOperation {
'CSSMathNegate': class extends CSSMathValue {
constructor(values) {
super([arguments[0]], 'negate', '-');
}
Expand All @@ -158,7 +168,7 @@ export function installCSSOM() {
}
},

'CSSMathInvert': class extends MathOperation {
'CSSMathInvert': class extends CSSMathValue {
constructor(values) {
super([1, arguments[0]], 'invert', 'calc', ' / ');
}
Expand All @@ -174,13 +184,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');
}
Expand Down Expand Up @@ -237,10 +247,10 @@ export function installCSSOM() {
});
}

for (let type in cssOMTypes) {
for (let [type, value] of Object.entries(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}`);
}
}