-
-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve case of css custom variables. Fixes #648
- Loading branch information
P-a
committed
Oct 25, 2018
1 parent
1b27f28
commit 4d0faf6
Showing
2 changed files
with
66 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,53 @@ | ||
import {list} from 'postcss'; | ||
import {isWidth, isStyle, isColor} from './validateWsc'; | ||
|
||
const none = /^\s*(none|medium)(\s+none(\s+(none|currentcolor))?)?\s*$/i; | ||
|
||
export default function parseWsc (value) { | ||
if (none.test(value)) { | ||
return [ 'medium', 'none', 'currentcolor']; | ||
} | ||
|
||
let width, style, color; | ||
|
||
const values = list.space(value); | ||
if (values.length > 1 && isStyle(values[1]) && values[0].toLowerCase() === 'none') { | ||
values.unshift(); | ||
width = '0'; | ||
} | ||
|
||
const unknown = []; | ||
|
||
values.forEach(v => { | ||
if (isStyle(v)) { | ||
style = v.toLowerCase(); | ||
} else if (isWidth(v)) { | ||
width = v.toLowerCase(); | ||
} else if (isColor(v)) { | ||
color = v.toLowerCase(); | ||
} else { | ||
unknown.push(v); | ||
} | ||
}); | ||
|
||
if (unknown.length) { | ||
if (!width && style && color) { | ||
width = unknown.pop(); | ||
} | ||
if (width && !style && color) { | ||
style = unknown.pop(); | ||
} | ||
if (width && style && !color) { | ||
color = unknown.pop(); | ||
} | ||
} | ||
|
||
return [ width, style, color ]; | ||
} | ||
import {list} from 'postcss'; | ||
import {isWidth, isStyle, isColor} from './validateWsc'; | ||
|
||
const none = /^\s*(none|medium)(\s+none(\s+(none|currentcolor))?)?\s*$/i; | ||
|
||
const varRE = /(^.*var)(.*\(.*--.*\))(.*)/i; | ||
const varPreserveCase = p => `${p[1].toLowerCase()}${p[2]}${p[3].toLowerCase()}`; | ||
const toLower = v => { | ||
const match = varRE.exec(v); | ||
return match ? varPreserveCase(match) : v.toLowerCase(); | ||
}; | ||
|
||
export default function parseWsc (value) { | ||
if (none.test(value)) { | ||
return [ 'medium', 'none', 'currentcolor']; | ||
} | ||
|
||
let width, style, color; | ||
|
||
const values = list.space(value); | ||
if (values.length > 1 && isStyle(values[1]) && values[0].toLowerCase() === 'none') { | ||
values.unshift(); | ||
width = '0'; | ||
} | ||
|
||
const unknown = []; | ||
|
||
values.forEach(v => { | ||
if (isStyle(v)) { | ||
style = toLower(v); | ||
} else if (isWidth(v)) { | ||
width = toLower(v); | ||
} else if (isColor(v)) { | ||
color = toLower(v); | ||
} else { | ||
unknown.push(v); | ||
} | ||
}); | ||
|
||
if (unknown.length) { | ||
if (!width && style && color) { | ||
width = unknown.pop(); | ||
} | ||
if (width && !style && color) { | ||
style = unknown.pop(); | ||
} | ||
if (width && style && !color) { | ||
color = unknown.pop(); | ||
} | ||
} | ||
|
||
return [ width, style, color ]; | ||
} |