-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix : csstools/css-has-pseudo#13 * fix code bug * wip * fix css-prefers-color-scheme * ensure old browser script location is published
- Loading branch information
1 parent
ea518da
commit 046e252
Showing
23 changed files
with
360 additions
and
40 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ node_modules | |
dist | ||
package-lock.json | ||
yarn.lock | ||
browser.js | ||
*.log* | ||
*.result.css | ||
*.result.css.map | ||
|
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 |
---|---|---|
|
@@ -32,6 +32,12 @@ Next, use your transformed CSS with this script: | |
<script>cssBlankPseudo(document)</script> | ||
``` | ||
|
||
⚠️ Please use a versioned url, like this : `https://unpkg.com/[email protected]/dist/browser-global.js` | ||
Without the version, you might unexpectedly get a new major version of the library with breaking changes. | ||
|
||
⚠️ If you were using an older version via a CDN, please update the entire url. | ||
The old URL will no longer work in a future release. | ||
|
||
That’s it. The script works in most browsers. | ||
|
||
## How it works | ||
|
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ node_modules | |
dist | ||
package-lock.json | ||
yarn.lock | ||
browser.js | ||
*.log* | ||
*.result.css | ||
*.result.css.map | ||
|
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 |
---|---|---|
|
@@ -42,6 +42,12 @@ Next, use your transformed CSS with this script: | |
<script>cssHasPseudo(document)</script> | ||
``` | ||
|
||
⚠️ Please use a versioned url, like this : `https://unpkg.com/[email protected]/dist/browser-global.js` | ||
Without the version, you might unexpectedly get a new major version of the library with breaking changes. | ||
|
||
⚠️ If you were using an older version via a CDN, please update the entire url. | ||
The old URL will no longer work in a future release. | ||
|
||
That’s it. The script is 765 bytes and works in most browser versions, including | ||
Internet Explorer 11. With a [Mutation Observer polyfill], the script will work | ||
down to Internet Explorer 9. | ||
|
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 |
---|---|---|
@@ -1,5 +1,23 @@ | ||
module.exports = { | ||
'basic': { | ||
message: 'supports basic usage' | ||
} | ||
'basic': { | ||
message: 'supports basic usage' | ||
}, | ||
'basic:color': { | ||
message: 'supports { mediaQuery: "color" } usage', | ||
options: { | ||
mediaQuery: 'color' | ||
} | ||
}, | ||
'basic:color-index': { | ||
message: 'supports { mediaQuery: "color-index" } usage', | ||
options: { | ||
mediaQuery: 'color-index' | ||
} | ||
}, | ||
'basic:preserve': { | ||
message: 'supports { preserve: true } usage', | ||
options: { | ||
preserve: true | ||
} | ||
} | ||
}; |
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 |
---|---|---|
|
@@ -28,7 +28,11 @@ colorScheme = initPrefersColorScheme('dark') // apply "dark" queries (you can ch | |
</script> | ||
``` | ||
|
||
Dependencies got you down? Don’t worry, this script is only 537 bytes. | ||
⚠️ Please use a versioned url, like this : `https://unpkg.com/[email protected]/dist/browser-global.js` | ||
Without the version, you might unexpectedly get a new major version of the library with breaking changes. | ||
|
||
⚠️ If you were using an older version via a CDN, please update the entire url. | ||
The old URL will no longer work in a future release. | ||
|
||
## Usage | ||
|
||
|
@@ -41,23 +45,28 @@ Dependencies got you down? Don’t worry, this script is only 537 bytes. | |
|
||
## How does it work? | ||
|
||
_This plugin used to work with `color-index` as detailed here : [color-index](https://github.com/csstools/css-prefers-color-scheme#how-does-it-work)._ | ||
_This is deprecated but will continue to work for now._ | ||
_`color` has better browser support and enables complex media queries._ | ||
|
||
[Prefers Color Scheme] uses a [PostCSS plugin](README-POSTCSS.md) to transform | ||
`prefers-color-scheme` queries into `color-index` queries. This changes | ||
`prefers-color-scheme: dark` into `(color-index: 48)`, | ||
`prefers-color-scheme: light` into `(color-index: 70)`, and | ||
`prefers-color-scheme: no-preference` into `(color-index: 22)`. | ||
`prefers-color-scheme` queries into `color` queries. This changes | ||
`prefers-color-scheme: dark` into `(color: 48842621)`, | ||
`prefers-color-scheme: light` into `(color: 70318723)`, and | ||
`prefers-color-scheme: no-preference` into `(color: 22511989)`. | ||
|
||
The frontend receives these `color-index` queries, which are understood in all | ||
major browsers going back to Internet Explorer 9. However, since browsers only | ||
apply `color-index` queries of `0`, our color scheme values are ignored. | ||
The frontend receives these `color` queries, which are understood in all | ||
major browsers going back to Internet Explorer 9. | ||
However, since browsers can only have a reasonably small number of bits per color, | ||
our color scheme values are ignored. | ||
|
||
[Prefers Color Scheme] uses a [browser script](README-BROWSER.md) to change | ||
`(color-index: 48)` queries into `not all and (color-index: 48)` in order to | ||
activate “dark mode” specific CSS, and it changes `(color-index: 70)` queries | ||
into `not all and (color-index: 48)` to activate “light mode” specific CSS. | ||
`(color: 48842621)` queries into `(max-color: 48842621)` in order to | ||
activate “dark mode” specific CSS, and it changes `(color: 70318723)` queries | ||
into `(max-color: 48842621)` to activate “light mode” specific CSS. | ||
|
||
```css | ||
@media (color-index: 70) { /* prefers-color-scheme: light */ | ||
@media (color: 70318723) { /* prefers-color-scheme: light */ | ||
body { | ||
background-color: white; | ||
color: black; | ||
|
@@ -73,6 +82,7 @@ parsing is required. | |
The value of `48` is chosen for dark mode because it is the keycode for `0`, | ||
the hexidecimal value of black. Likewise, `70` is chosen for light mode because | ||
it is the keycode for `f`, the hexidecimal value of white. | ||
These are suffixed with a random large number. | ||
|
||
[cli-img]: https://github.com/csstools/postcss-plugins/workflows/test/badge.svg | ||
[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test | ||
|
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
Oops, something went wrong.