-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support curly braces multipliers for groups and map infinite mu…
- Loading branch information
1 parent
ee24316
commit 347f251
Showing
10 changed files
with
851 additions
and
77 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,23 @@ | ||
import { ICssMultiplierTokenType } from '@johanneslumpe/css-value-declaration-grammer-lexer'; | ||
import { forEach } from 'lodash/fp'; | ||
|
||
import { RawToken } from '../types'; | ||
import { isAsteriskMultiplier } from './isAsteriskMultiplier'; | ||
import { isPlusMultiplier } from './isPlusMultiplier'; | ||
|
||
/** | ||
* Converts infinite multipliers like `+` and `*` to opinionated, finite `{}` versions. | ||
* Opinionated, because they will be capped at 8 repetitions | ||
* @param tokens | ||
* @param suffix | ||
*/ | ||
export function convertInfiniteMultiplersToFinite(tokens: RawToken[]) { | ||
forEach(token => { | ||
const isPlus = isPlusMultiplier(token); | ||
const isAsterisk = isAsteriskMultiplier(token); | ||
if (isPlus || isAsterisk) { | ||
token.data!.subType = ICssMultiplierTokenType.CURLY_BRACES; | ||
token.value = isPlus ? '{1,8}' : '{0,8}'; | ||
} | ||
}, tokens); | ||
} |
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,14 @@ | ||
import { | ||
ICssMultiplierTokenType, | ||
ICssTokenType, | ||
} from '@johanneslumpe/css-value-declaration-grammer-lexer'; | ||
|
||
import { RawToken } from '../types'; | ||
|
||
export function isAsteriskMultiplier(token: RawToken) { | ||
return ( | ||
token.type === ICssTokenType.MULTIPLIER && | ||
token.data && | ||
token.data.subType === ICssMultiplierTokenType.ASTERISK | ||
); | ||
} |
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 { ICssMultiplierTokenType } from '@johanneslumpe/css-value-declaration-grammer-lexer'; | ||
|
||
import { IComponent } from '../types'; | ||
|
||
export function isCurlyBraceMultiplierArray(arr: IComponent[]): boolean { | ||
return arr.every( | ||
component => | ||
!!( | ||
component.multiplier && | ||
component.multiplier.type === ICssMultiplierTokenType.CURLY_BRACES | ||
), | ||
); | ||
} |
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,14 @@ | ||
import { | ||
ICssMultiplierTokenType, | ||
ICssTokenType, | ||
} from '@johanneslumpe/css-value-declaration-grammer-lexer'; | ||
|
||
import { RawToken } from '../types'; | ||
|
||
export function isPlusMultiplier(token: RawToken) { | ||
return ( | ||
token.type === ICssTokenType.MULTIPLIER && | ||
token.data && | ||
token.data.subType === ICssMultiplierTokenType.PLUS | ||
); | ||
} |