Skip to content

Commit

Permalink
Move typed om implementation into a separate folder
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesodland committed Feb 4, 2024
1 parent ecdca38 commit d3a49d3
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 130 deletions.
17 changes: 11 additions & 6 deletions src/numeric-values.js → src/css-typed-om/numeric-values.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import {simplifyCalculation} from '../simplify-calculation';
import {
tokenizeString
} from './tokenizer';
import {
CommaToken,
DelimToken,
DimensionToken,
FunctionToken, IdentToken,
FunctionToken,
IdentToken,
LeftCurlyBracketToken,
LeftParenthesisToken,
LeftSquareBracketToken,
NumberToken,
PercentageToken, RightCurlyBracketToken,
RightParenthesisToken, RightSquareBracketToken,
PercentageToken,
RightCurlyBracketToken,
RightParenthesisToken,
RightSquareBracketToken,
Token,
tokenizeString,
WhitespaceToken
} from './tokenizer';
import {simplifyCalculation} from './simplify-calculation';
} from './tokens';

/**
* @typedef {{[string]: integer}} UnitMap
Expand Down
2 changes: 1 addition & 1 deletion src/proxy-cssom.js → src/css-typed-om/proxy-cssom.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import {createAType, invertType, multiplyTypes, parseCSSNumericValue, to, toSum} from './numeric-values';
import {simplifyCalculation} from './simplify-calculation';
import {simplifyCalculation} from '../simplify-calculation';
import './tokenizer'

export function installCSSOM() {
Expand Down
148 changes: 26 additions & 122 deletions src/tokenizer.js → src/css-typed-om/tokenizer.js
Original file line number Diff line number Diff line change
@@ -1,125 +1,29 @@

export class Token {}

// The output of tokenization step is a stream of zero or more of the following tokens: <ident-token>, <function-token>,
// <at-keyword-token>, <hash-token>, <string-token>, <bad-string-token>, <url-token>, <bad-url-token>, <delim-token>,
// <number-token>, <percentage-token>, <dimension-token>, <whitespace-token>, <CDO-token>, <CDC-token>, <colon-token>,
// <semicolon-token>, <comma-token>, <[-token>, <]-token>, <(-token>, <)-token>, <{-token>, and <}-token>.
export class IdentToken extends Token {
value;
constructor(value) {
super();
this.value = value;
}
}

export class FunctionToken extends Token {
value;
constructor(value) {
super();
this.value = value;
}
}

export class AtKeywordToken extends Token {
value;
constructor(value) {
super();
this.value = value;
}
}

export class HashToken extends Token {
type;
value;
constructor(value, type = 'unrestricted') {
super();
this.value = value;
this.type = type;
}
}

export class StringToken extends Token {
value;
constructor(value) {
super();
this.value = value;
}
}

export class BadStringToken extends Token {}

export class UrlToken extends Token {
value;
constructor(value) {
super();
this.value = value;
}
}

export class BadUrlToken extends Token {}

export class DelimToken extends Token {
value;
constructor(value) {
super();
this.value = value;
}
}

export class NumberToken extends Token {
value;
type;
constructor(value, type = "integer") {
super();
this.value = value;
this.type = type;
}
}

export class PercentageToken extends Token {
value;
constructor(value) {
super();
this.value = value;
}
}

export class DimensionToken extends Token {
value;
type;
unit;
constructor(value, type, unit) {
super();
this.value = value;
this.type = type;
this.unit = unit;
}
}

export class WhitespaceToken extends Token {}

export class CDOToken extends Token {}

export class CDCToken extends Token {}

export class ColonToken extends Token {}

export class SemicolonToken extends Token {}

export class CommaToken extends Token {}

export class LeftSquareBracketToken extends Token {}

export class RightSquareBracketToken extends Token {}

export class LeftParenthesisToken extends Token {}

export class RightParenthesisToken extends Token {}

export class LeftCurlyBracketToken extends Token {}

export class RightCurlyBracketToken extends Token {}
import {
AtKeywordToken,
BadStringToken,
BadUrlToken,
CDCToken,
CDOToken,
ColonToken,
CommaToken,
DelimToken,
DimensionToken,
FunctionToken,
HashToken,
IdentToken,
LeftCurlyBracketToken,
LeftParenthesisToken,
LeftSquareBracketToken,
NumberToken,
PercentageToken,
RightCurlyBracketToken,
RightParenthesisToken,
RightSquareBracketToken,
SemicolonToken,
StringToken,
UrlToken,
WhitespaceToken
} from './tokens';

class InputStream {
input
Expand Down
122 changes: 122 additions & 0 deletions src/css-typed-om/tokens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@

export class Token {}

// The output of tokenization step is a stream of zero or more of the following tokens: <ident-token>, <function-token>,
// <at-keyword-token>, <hash-token>, <string-token>, <bad-string-token>, <url-token>, <bad-url-token>, <delim-token>,
// <number-token>, <percentage-token>, <dimension-token>, <whitespace-token>, <CDO-token>, <CDC-token>, <colon-token>,
// <semicolon-token>, <comma-token>, <[-token>, <]-token>, <(-token>, <)-token>, <{-token>, and <}-token>.
export class IdentToken extends Token {
value;
constructor(value) {
super();
this.value = value;
}
}

export class FunctionToken extends Token {
value;
constructor(value) {
super();
this.value = value;
}
}

export class AtKeywordToken extends Token {
value;
constructor(value) {
super();
this.value = value;
}
}

export class HashToken extends Token {
type;
value;
constructor(value, type = 'unrestricted') {
super();
this.value = value;
this.type = type;
}
}

export class StringToken extends Token {
value;
constructor(value) {
super();
this.value = value;
}
}

export class BadStringToken extends Token {}

export class UrlToken extends Token {
value;
constructor(value) {
super();
this.value = value;
}
}

export class BadUrlToken extends Token {}

export class DelimToken extends Token {
value;
constructor(value) {
super();
this.value = value;
}
}

export class NumberToken extends Token {
value;
type;
constructor(value, type = "integer") {
super();
this.value = value;
this.type = type;
}
}

export class PercentageToken extends Token {
value;
constructor(value) {
super();
this.value = value;
}
}

export class DimensionToken extends Token {
value;
type;
unit;
constructor(value, type, unit) {
super();
this.value = value;
this.type = type;
this.unit = unit;
}
}

export class WhitespaceToken extends Token {}

export class CDOToken extends Token {}

export class CDCToken extends Token {}

export class ColonToken extends Token {}

export class SemicolonToken extends Token {}

export class CommaToken extends Token {}

export class LeftSquareBracketToken extends Token {}

export class RightSquareBracketToken extends Token {}

export class LeftParenthesisToken extends Token {}

export class RightParenthesisToken extends Token {}

export class LeftCurlyBracketToken extends Token {}

export class RightCurlyBracketToken extends Token {}
2 changes: 1 addition & 1 deletion src/scroll-timeline-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {installCSSOM} from "./proxy-cssom.js";
import {installCSSOM} from "./css-typed-om/proxy-cssom.js";
import {simplifyCalculation} from "./simplify-calculation";
import {normalizeAxis, splitIntoComponentValues} from './utils.js';

Expand Down

0 comments on commit d3a49d3

Please sign in to comment.