forked from sveltejs/svelte
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes sveltejs#5876. Adds single value function support to media que…
…ries and media query range syntax / MQ level 4 support. (sveltejs#8430)
- Loading branch information
Showing
9 changed files
with
161 additions
and
65 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
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
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 @@ | ||
export * as Comparison from './comparison'; | ||
export * as ContainerFeatureStyle from './container_feature_style'; | ||
export * as ContainerQuery from './container_query'; | ||
export * as MediaQuery from './media_query'; | ||
export * as QueryFeature from './query_feature'; | ||
export * as QueryFeatureRange from './query_feature_range'; | ||
export * as QueryCSSFunction from './query_css_function'; |
44 changes: 44 additions & 0 deletions
44
src/compiler/parse/read/css-tree-cq/node/lookahead_is_range.ts
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,44 @@ | ||
// @ts-nocheck | ||
import { | ||
EOF, | ||
WhiteSpace, | ||
Delim, | ||
RightParenthesis, | ||
LeftCurlyBracket, | ||
Colon | ||
} from 'css-tree/tokenizer'; | ||
|
||
/** | ||
* Looks ahead to determine if query feature is a range query. This involves locating at least one delimiter and no | ||
* colon tokens. | ||
* | ||
* @returns {boolean} Is potential range query. | ||
*/ | ||
export function lookahead_is_range() { | ||
let type; | ||
let offset = 0; | ||
|
||
let count = 0; | ||
let delim_found = false; | ||
let no_colon = true; | ||
|
||
// A range query has maximum 5 tokens when formatted as 'mf-range' / | ||
// '<mf-value> <mf-lt> <mf-name> <mf-lt> <mf-value>'. So only look ahead maximum of 6 non-whitespace tokens. | ||
do { | ||
type = this.lookupNonWSType(offset++); | ||
if (type !== WhiteSpace) { | ||
count++; | ||
} | ||
if (type === Delim) { | ||
delim_found = true; | ||
} | ||
if (type === Colon) { | ||
no_colon = false; | ||
} | ||
if (type === LeftCurlyBracket || type === RightParenthesis) { | ||
break; | ||
} | ||
} while (type !== EOF && count <= 6); | ||
|
||
return delim_found && no_colon; | ||
} |
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,64 @@ | ||
// @ts-nocheck | ||
import { | ||
WhiteSpace, | ||
Comment, | ||
Ident, | ||
LeftParenthesis | ||
} from 'css-tree/tokenizer'; | ||
|
||
import { lookahead_is_range } from './lookahead_is_range'; | ||
|
||
export const name = 'MediaQuery'; | ||
export const structure = { | ||
children: [[ | ||
'Identifier', | ||
'QueryFeature', | ||
'QueryFeatureRange', | ||
'WhiteSpace' | ||
]] | ||
}; | ||
|
||
export function parse() { | ||
const children = this.createList(); | ||
let child = null; | ||
|
||
this.skipSC(); | ||
|
||
scan: | ||
while (!this.eof) { | ||
switch (this.tokenType) { | ||
case Comment: | ||
case WhiteSpace: | ||
this.next(); | ||
continue; | ||
|
||
case Ident: | ||
child = this.Identifier(); | ||
break; | ||
|
||
case LeftParenthesis: | ||
// Lookahead to determine if range feature. | ||
child = lookahead_is_range.call(this) ? this.QueryFeatureRange() : this.QueryFeature(); | ||
break; | ||
|
||
default: | ||
break scan; | ||
} | ||
|
||
children.push(child); | ||
} | ||
|
||
if (child === null) { | ||
this.error('Identifier or parenthesis is expected'); | ||
} | ||
|
||
return { | ||
type: 'MediaQuery', | ||
loc: this.getLocationFromList(children), | ||
children | ||
}; | ||
} | ||
|
||
export function generate(node) { | ||
this.children(node); | ||
} |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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