-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ecdca38
commit 9febccd
Showing
18 changed files
with
1,275 additions
and
1,223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export class CSSKeywordValue { | ||
#value; | ||
|
||
constructor(value) { | ||
this.#value = value; | ||
} | ||
|
||
toString() { | ||
return this.#value.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {invertType} from './procedures'; | ||
import {CSSMathValue} from './css-math-value'; | ||
|
||
export class CSSMathInvert extends CSSMathValue { | ||
constructor(values) { | ||
super([1, arguments[0]], 'invert', 'calc', ' / '); | ||
} | ||
|
||
get value() { | ||
return this.values[1]; | ||
} | ||
|
||
type() { | ||
// The type of a CSSUnitValue is the result of creating a type from its unit internal slot. | ||
return invertType(this.values[1].type()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {CSSMathValue} from './css-math-value'; | ||
|
||
export class CSSMathMax extends CSSMathValue { | ||
constructor() { | ||
super(arguments, 'max'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {CSSMathValue} from './css-math-value'; | ||
|
||
export class CSSMathMin extends CSSMathValue { | ||
constructor() { | ||
super(arguments, 'min'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {CSSMathValue} from './css-math-value'; | ||
|
||
export class CSSMathNegate extends CSSMathValue { | ||
constructor(values) { | ||
super([arguments[0]], 'negate', '-'); | ||
} | ||
|
||
get value() { | ||
return this.values[0]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {multiplyTypes, toSum} from './procedures'; | ||
import {CSSMathValue} from './css-math-value'; | ||
|
||
export class CSSMathProduct extends CSSMathValue { | ||
constructor(values) { | ||
super(arguments, 'product', 'calc', ' * '); | ||
} | ||
|
||
toSum(...units) { | ||
return toSum(this, ...units) | ||
} | ||
|
||
type() { | ||
// The type is the result of multiplying the types of each of the items in its values internal slot. | ||
return this.values.map(v => v.type()).reduce(multiplyTypes) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {CSSMathValue} from './css-math-value'; | ||
|
||
export class CSSMathSum extends CSSMathValue { | ||
constructor(values) { | ||
super(arguments, 'sum', 'calc', ' + '); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import {CSSNumericValue} from './css-numeric-value' | ||
function toCssUnitValue(v) { | ||
if (typeof v === 'number') | ||
return new CSSUnitValue(v, 'number'); | ||
return v; | ||
} | ||
|
||
function toCssNumericArray(values) { | ||
const result = []; | ||
for (let i = 0; i < values.length; i++) { | ||
result[i] = toCssUnitValue(values[i]); | ||
} | ||
return result; | ||
} | ||
|
||
export class CSSMathValue extends CSSNumericValue { | ||
#values; | ||
#operator; | ||
#name; | ||
#delimiter; | ||
|
||
constructor(values, operator, opt_name, opt_delimiter) { | ||
super(); | ||
this.#values = toCssNumericArray(values); | ||
this.#operator = operator; | ||
this.#name = opt_name || operator; | ||
this.#delimiter = opt_delimiter || ', '; | ||
} | ||
|
||
get operator() { | ||
return this.#operator; | ||
} | ||
|
||
get values() { | ||
return this.#values; | ||
} | ||
|
||
toString() { | ||
return `${this.#name}(${this.#values.join(this.#delimiter)})`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {parseCSSNumericValue} from './parse-numeric-value'; | ||
|
||
export class CSSNumericValue { | ||
static parse(value) { | ||
if (value instanceof CSSNumericValue) | ||
return value; | ||
|
||
return parseCSSNumericValue(value); | ||
} | ||
|
||
// TODO: Add other methods: add, sub, mul, div, … | ||
// Spec: https://drafts.css-houdini.org/css-typed-om/#numeric-value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {CSSNumericValue} from './css-numeric-value'; | ||
import {createAType, to, toSum} from './procedures'; | ||
|
||
function displayUnit(unit) { | ||
switch (unit) { | ||
case 'percent': | ||
return '%'; | ||
case 'number': | ||
return ''; | ||
default: | ||
return unit.toLowerCase(); | ||
} | ||
} | ||
|
||
export class CSSUnitValue extends CSSNumericValue { | ||
#value; | ||
#unit; | ||
|
||
constructor(value, unit) { | ||
super(); | ||
this.#value = value; | ||
this.#unit = unit; | ||
} | ||
|
||
get value() { | ||
return this.#value; | ||
} | ||
|
||
set value(value) { | ||
this.#value = value; | ||
} | ||
|
||
get unit() { | ||
return this.#unit; | ||
} | ||
|
||
to(unit) { | ||
return to(this, unit); | ||
} | ||
|
||
toSum(...units) { | ||
return toSum(this, ...units); | ||
} | ||
|
||
type() { | ||
// The type of a CSSUnitValue is the result of creating a type from its unit internal slot. | ||
return createAType(this.#unit); | ||
} | ||
|
||
toString() { | ||
return `${this.#value}${displayUnit(this.#unit)}`; | ||
} | ||
} |
Oops, something went wrong.