css-prefers-color-scheme 4.0.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/browser.js.map +1 -1
- package/browser.min.js +1 -1
- package/index.js.map +1 -1
- package/index.mjs +1 -1
- package/index.mjs.map +1 -1
- package/package.json +15 -19
- package/postcss.js +23 -22
- package/postcss.mjs +23 -20
- package/CHANGELOG.md +0 -32
package/README.md
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
[Prefers Color Scheme] lets you use light and dark color schemes in all
|
|
8
8
|
browsers, following the [Media Queries] specification.
|
|
9
9
|
|
|
10
|
+
[](https://caniuse.com/#feat=prefers-color-scheme)
|
|
11
|
+
|
|
10
12
|
## Usage
|
|
11
13
|
|
|
12
14
|
From the command line, transform CSS files that use `prefers-color-scheme`
|
|
@@ -72,8 +74,8 @@ The value of `48` is chosen for dark mode because it is the keycode for `0`,
|
|
|
72
74
|
the hexidecimal value of black. Likewise, `70` is chosen for light mode because
|
|
73
75
|
it is the keycode for `f`, the hexidecimal value of white.
|
|
74
76
|
|
|
75
|
-
[cli-img]: https://
|
|
76
|
-
[cli-url]: https://
|
|
77
|
+
[cli-img]: https://github.com/csstools/css-prefers-color-scheme/workflows/test/badge.svg
|
|
78
|
+
[cli-url]: https://github.com/csstools/css-prefers-color-scheme/actions/workflows/test.yml?query=workflow/test
|
|
77
79
|
[git-img]: https://img.shields.io/badge/support-chat-blue.svg
|
|
78
80
|
[git-url]: https://gitter.im/postcss/postcss
|
|
79
81
|
[npm-img]: https://img.shields.io/npm/v/css-prefers-color-scheme.svg
|
package/browser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.js","sources":["src/browser.js"],"sourcesContent":["const colorIndexRegExp = /((?:not )?all and )?(\\(color-index: *(22|48|70)\\))/i;\nconst prefersColorSchemeRegExp = /prefers-color-scheme:/i;\n\nconst prefersColorSchemeInit = initialColorScheme => {\n\tconst mediaQueryString = '(prefers-color-scheme: dark)';\n\tconst mediaQueryList = window.matchMedia && matchMedia(mediaQueryString);\n\tconst hasNativeSupport = mediaQueryList && mediaQueryList.media === mediaQueryString;\n\tconst mediaQueryListener = () => {\n\t\tset(mediaQueryList.matches ? 'dark' : 'light');\n\t};\n\tconst removeListener = () => {\n\t\tif (mediaQueryList) {\n\t\t\tmediaQueryList.removeListener(mediaQueryListener);\n\t\t}\n\t};\n\tconst set = colorScheme => {\n\t\tif (colorScheme !== currentColorScheme) {\n\t\t\tcurrentColorScheme = colorScheme;\n\n\t\t\tif (typeof result.onChange === 'function') {\n\t\t\t\tresult.onChange();\n\t\t\t}\n\t\t}\n\n\t\t[].forEach.call(document.styleSheets || [], styleSheet => {\n\t\t\t[].forEach.call(styleSheet.cssRules || [], cssRule => {\n\t\t\t\tconst colorSchemeMatch = prefersColorSchemeRegExp.test(Object(cssRule.media).mediaText);\n\n\t\t\t\tif (colorSchemeMatch) {\n\t\t\t\t\tconst index = [].indexOf.call(cssRule.parentStyleSheet.cssRules, cssRule);\n\n\t\t\t\t\tcssRule.parentStyleSheet.deleteRule(index);\n\t\t\t\t} else {\n\t\t\t\t\tconst colorIndexMatch = (Object(cssRule.media).mediaText || '').match(colorIndexRegExp);\n\n\t\t\t\t\tif (colorIndexMatch) {\n\t\t\t\t\t\tcssRule.media.mediaText = (\n\t\t\t\t\t\t\t(/^dark$/i.test(colorScheme)\n\t\t\t\t\t\t\t\t? colorIndexMatch[3] === '48'\n\t\t\t\t\t\t\t: /^light$/i.test(colorScheme)\n\t\t\t\t\t\t\t\t? colorIndexMatch[3] === '70'\n\t\t\t\t\t\t\t: colorIndexMatch[3] === '22')\n\t\t\t\t\t\t\t\t? 'not all and '\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t) + cssRule.media.mediaText.replace(colorIndexRegExp, '$2');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t};\n\tconst result = Object.defineProperty(\n\t\t{ hasNativeSupport, removeListener },\n\t\t'scheme',\n\t\t{ get: () => currentColorScheme, set }\n\t);\n\n\t// initialize the color scheme using the provided value, the system value, or light\n\tlet currentColorScheme = initialColorScheme || (mediaQueryList && mediaQueryList.matches ? 'dark' : 'light');\n\n\tset(currentColorScheme);\n\n\t// listen for system changes\n\tif (mediaQueryList) {\n\t\tmediaQueryList.addListener(mediaQueryListener);\n\t}\n\n\treturn result;\n};\n\nexport default prefersColorSchemeInit;\n"],"names":["colorIndexRegExp","prefersColorSchemeRegExp","prefersColorSchemeInit","initialColorScheme","mediaQueryString","mediaQueryList","window","matchMedia","hasNativeSupport","media","mediaQueryListener","set","matches","removeListener","colorScheme","currentColorScheme","result","onChange","forEach","call","document","styleSheets","styleSheet","cssRules","cssRule","colorSchemeMatch","test","Object","mediaText","index","indexOf","parentStyleSheet","deleteRule","colorIndexMatch","match","replace","defineProperty","get","addListener"],"mappings":";;;CAAA,IAAMA,gBAAgB,GAAG,qDAAzB;CACA,IAAMC,wBAAwB,GAAG,wBAAjC;;
|
|
1
|
+
{"version":3,"file":"browser.js","sources":["src/browser.js"],"sourcesContent":["const colorIndexRegExp = /((?:not )?all and )?(\\(color-index: *(22|48|70)\\))/i;\nconst prefersColorSchemeRegExp = /prefers-color-scheme:/i;\n\nconst prefersColorSchemeInit = initialColorScheme => {\n\tconst mediaQueryString = '(prefers-color-scheme: dark)';\n\tconst mediaQueryList = window.matchMedia && matchMedia(mediaQueryString);\n\tconst hasNativeSupport = mediaQueryList && mediaQueryList.media === mediaQueryString;\n\tconst mediaQueryListener = () => {\n\t\tset(mediaQueryList.matches ? 'dark' : 'light');\n\t};\n\tconst removeListener = () => {\n\t\tif (mediaQueryList) {\n\t\t\tmediaQueryList.removeListener(mediaQueryListener);\n\t\t}\n\t};\n\tconst set = colorScheme => {\n\t\tif (colorScheme !== currentColorScheme) {\n\t\t\tcurrentColorScheme = colorScheme;\n\n\t\t\tif (typeof result.onChange === 'function') {\n\t\t\t\tresult.onChange();\n\t\t\t}\n\t\t}\n\n\t\t[].forEach.call(document.styleSheets || [], styleSheet => {\n\t\t\t[].forEach.call(styleSheet.cssRules || [], cssRule => {\n\t\t\t\tconst colorSchemeMatch = prefersColorSchemeRegExp.test(Object(cssRule.media).mediaText);\n\n\t\t\t\tif (colorSchemeMatch) {\n\t\t\t\t\tconst index = [].indexOf.call(cssRule.parentStyleSheet.cssRules, cssRule);\n\n\t\t\t\t\tcssRule.parentStyleSheet.deleteRule(index);\n\t\t\t\t} else {\n\t\t\t\t\tconst colorIndexMatch = (Object(cssRule.media).mediaText || '').match(colorIndexRegExp);\n\n\t\t\t\t\tif (colorIndexMatch) {\n\t\t\t\t\t\tcssRule.media.mediaText = (\n\t\t\t\t\t\t\t(/^dark$/i.test(colorScheme)\n\t\t\t\t\t\t\t\t? colorIndexMatch[3] === '48'\n\t\t\t\t\t\t\t: /^light$/i.test(colorScheme)\n\t\t\t\t\t\t\t\t? colorIndexMatch[3] === '70'\n\t\t\t\t\t\t\t: colorIndexMatch[3] === '22')\n\t\t\t\t\t\t\t\t? 'not all and '\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t) + cssRule.media.mediaText.replace(colorIndexRegExp, '$2');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t};\n\tconst result = Object.defineProperty(\n\t\t{ hasNativeSupport, removeListener },\n\t\t'scheme',\n\t\t{ get: () => currentColorScheme, set }\n\t);\n\n\t// initialize the color scheme using the provided value, the system value, or light\n\tlet currentColorScheme = initialColorScheme || (mediaQueryList && mediaQueryList.matches ? 'dark' : 'light');\n\n\tset(currentColorScheme);\n\n\t// listen for system changes\n\tif (mediaQueryList) {\n\t\tmediaQueryList.addListener(mediaQueryListener);\n\t}\n\n\treturn result;\n};\n\nexport default prefersColorSchemeInit;\n"],"names":["colorIndexRegExp","prefersColorSchemeRegExp","prefersColorSchemeInit","initialColorScheme","mediaQueryString","mediaQueryList","window","matchMedia","hasNativeSupport","media","mediaQueryListener","set","matches","removeListener","colorScheme","currentColorScheme","result","onChange","forEach","call","document","styleSheets","styleSheet","cssRules","cssRule","colorSchemeMatch","test","Object","mediaText","index","indexOf","parentStyleSheet","deleteRule","colorIndexMatch","match","replace","defineProperty","get","addListener"],"mappings":";;;CAAA,IAAMA,gBAAgB,GAAG,qDAAzB;CACA,IAAMC,wBAAwB,GAAG,wBAAjC;;KAEMC,sBAAsB,GAAG,SAAzBA,sBAAyB,CAAAC,kBAAkB,EAAI;CACpD,MAAMC,gBAAgB,GAAG,8BAAzB;CACA,MAAMC,cAAc,GAAGC,MAAM,CAACC,UAAP,IAAqBA,UAAU,CAACH,gBAAD,CAAtD;CACA,MAAMI,gBAAgB,GAAGH,cAAc,IAAIA,cAAc,CAACI,KAAf,KAAyBL,gBAApE;;CACA,MAAMM,kBAAkB,GAAG,SAArBA,kBAAqB,GAAM;CAChCC,IAAAA,GAAG,CAACN,cAAc,CAACO,OAAf,GAAyB,MAAzB,GAAkC,OAAnC,CAAH;CACA,GAFD;;CAGA,MAAMC,cAAc,GAAG,SAAjBA,cAAiB,GAAM;CAC5B,QAAIR,cAAJ,EAAoB;CACnBA,MAAAA,cAAc,CAACQ,cAAf,CAA8BH,kBAA9B;CACA;CACD,GAJD;;CAKA,MAAMC,GAAG,GAAG,SAANA,GAAM,CAAAG,WAAW,EAAI;CAC1B,QAAIA,WAAW,KAAKC,kBAApB,EAAwC;CACvCA,MAAAA,kBAAkB,GAAGD,WAArB;;CAEA,UAAI,OAAOE,MAAM,CAACC,QAAd,KAA2B,UAA/B,EAA2C;CAC1CD,QAAAA,MAAM,CAACC,QAAP;CACA;CACD;;CAED,OAAGC,OAAH,CAAWC,IAAX,CAAgBC,QAAQ,CAACC,WAAT,IAAwB,EAAxC,EAA4C,UAAAC,UAAU,EAAI;CACzD,SAAGJ,OAAH,CAAWC,IAAX,CAAgBG,UAAU,CAACC,QAAX,IAAuB,EAAvC,EAA2C,UAAAC,OAAO,EAAI;CACr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AAkB,GAAGZ,kBAAkB,KAAKE,cAAc,IAAIA,cAAc,CAACO,OAAjC,GAA2C,MAA3C,GAAoD,OAAzD,CAA3C;CAEAD,EAAAA,GAAG,CAACI,kBAAD,CAAH,CAxDoD;;CA2DpD,MAAIV,cAAJ,EAAoB;CACnBA,IAAAA,cAAc,CAACiC,WAAf,CAA2B5B,kBAA3B;CACA;;CAED,SAAOM,MAAP;CACA;;;;;;;;"}
|
package/browser.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var initPrefersColorScheme=function(){"use strict";var e=/((?:not )?all and )?(\(color-index: *(22|48|70)\))/i,t=/prefers-color-scheme:/i;return function(a){var
|
|
1
|
+
var initPrefersColorScheme=function(){"use strict";var e=/((?:not )?all and )?(\(color-index: *(22|48|70)\))/i,t=/prefers-color-scheme:/i;return function(a){var n="(prefers-color-scheme: dark)",i=window.matchMedia&&matchMedia(n),r=i&&i.media===n,c=function(){o(i.matches?"dark":"light")},o=function(a){a!==l&&(l=a,"function"==typeof s.onChange&&s.onChange()),[].forEach.call(document.styleSheets||[],(function(n){[].forEach.call(n.cssRules||[],(function(n){if(t.test(Object(n.media).mediaText)){var i=[].indexOf.call(n.parentStyleSheet.cssRules,n);n.parentStyleSheet.deleteRule(i)}else{var r=(Object(n.media).mediaText||"").match(e);r&&(n.media.mediaText=((/^dark$/i.test(a)?"48"===r[3]:/^light$/i.test(a)?"70"===r[3]:"22"===r[3])?"not all and ":"")+n.media.mediaText.replace(e,"$2"))}}))}))},s=Object.defineProperty({hasNativeSupport:r,removeListener:function(){i&&i.removeListener(c)}},"scheme",{get:function(){return l},set:o}),l=a||(i&&i.matches?"dark":"light");return o(l),i&&i.addListener(c),s}}();
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["src/browser.js"],"sourcesContent":["const colorIndexRegExp = /((?:not )?all and )?(\\(color-index: *(22|48|70)\\))/i;\nconst prefersColorSchemeRegExp = /prefers-color-scheme:/i;\n\nconst prefersColorSchemeInit = initialColorScheme => {\n\tconst mediaQueryString = '(prefers-color-scheme: dark)';\n\tconst mediaQueryList = window.matchMedia && matchMedia(mediaQueryString);\n\tconst hasNativeSupport = mediaQueryList && mediaQueryList.media === mediaQueryString;\n\tconst mediaQueryListener = () => {\n\t\tset(mediaQueryList.matches ? 'dark' : 'light');\n\t};\n\tconst removeListener = () => {\n\t\tif (mediaQueryList) {\n\t\t\tmediaQueryList.removeListener(mediaQueryListener);\n\t\t}\n\t};\n\tconst set = colorScheme => {\n\t\tif (colorScheme !== currentColorScheme) {\n\t\t\tcurrentColorScheme = colorScheme;\n\n\t\t\tif (typeof result.onChange === 'function') {\n\t\t\t\tresult.onChange();\n\t\t\t}\n\t\t}\n\n\t\t[].forEach.call(document.styleSheets || [], styleSheet => {\n\t\t\t[].forEach.call(styleSheet.cssRules || [], cssRule => {\n\t\t\t\tconst colorSchemeMatch = prefersColorSchemeRegExp.test(Object(cssRule.media).mediaText);\n\n\t\t\t\tif (colorSchemeMatch) {\n\t\t\t\t\tconst index = [].indexOf.call(cssRule.parentStyleSheet.cssRules, cssRule);\n\n\t\t\t\t\tcssRule.parentStyleSheet.deleteRule(index);\n\t\t\t\t} else {\n\t\t\t\t\tconst colorIndexMatch = (Object(cssRule.media).mediaText || '').match(colorIndexRegExp);\n\n\t\t\t\t\tif (colorIndexMatch) {\n\t\t\t\t\t\tcssRule.media.mediaText = (\n\t\t\t\t\t\t\t(/^dark$/i.test(colorScheme)\n\t\t\t\t\t\t\t\t? colorIndexMatch[3] === '48'\n\t\t\t\t\t\t\t: /^light$/i.test(colorScheme)\n\t\t\t\t\t\t\t\t? colorIndexMatch[3] === '70'\n\t\t\t\t\t\t\t: colorIndexMatch[3] === '22')\n\t\t\t\t\t\t\t\t? 'not all and '\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t) + cssRule.media.mediaText.replace(colorIndexRegExp, '$2');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t};\n\tconst result = Object.defineProperty(\n\t\t{ hasNativeSupport, removeListener },\n\t\t'scheme',\n\t\t{ get: () => currentColorScheme, set }\n\t);\n\n\t// initialize the color scheme using the provided value, the system value, or light\n\tlet currentColorScheme = initialColorScheme || (mediaQueryList && mediaQueryList.matches ? 'dark' : 'light');\n\n\tset(currentColorScheme);\n\n\t// listen for system changes\n\tif (mediaQueryList) {\n\t\tmediaQueryList.addListener(mediaQueryListener);\n\t}\n\n\treturn result;\n};\n\nexport default prefersColorSchemeInit;\n"],"names":["colorIndexRegExp","prefersColorSchemeRegExp","prefersColorSchemeInit","initialColorScheme","mediaQueryString","mediaQueryList","window","matchMedia","hasNativeSupport","media","mediaQueryListener","set","matches","removeListener","colorScheme","currentColorScheme","result","onChange","forEach","call","document","styleSheets","styleSheet","cssRules","cssRule","colorSchemeMatch","test","Object","mediaText","index","indexOf","parentStyleSheet","deleteRule","colorIndexMatch","match","replace","defineProperty","get","addListener"],"mappings":";;AAAA,MAAMA,gBAAgB,GAAG,qDAAzB;AACA,MAAMC,wBAAwB,GAAG,wBAAjC;;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["src/browser.js"],"sourcesContent":["const colorIndexRegExp = /((?:not )?all and )?(\\(color-index: *(22|48|70)\\))/i;\nconst prefersColorSchemeRegExp = /prefers-color-scheme:/i;\n\nconst prefersColorSchemeInit = initialColorScheme => {\n\tconst mediaQueryString = '(prefers-color-scheme: dark)';\n\tconst mediaQueryList = window.matchMedia && matchMedia(mediaQueryString);\n\tconst hasNativeSupport = mediaQueryList && mediaQueryList.media === mediaQueryString;\n\tconst mediaQueryListener = () => {\n\t\tset(mediaQueryList.matches ? 'dark' : 'light');\n\t};\n\tconst removeListener = () => {\n\t\tif (mediaQueryList) {\n\t\t\tmediaQueryList.removeListener(mediaQueryListener);\n\t\t}\n\t};\n\tconst set = colorScheme => {\n\t\tif (colorScheme !== currentColorScheme) {\n\t\t\tcurrentColorScheme = colorScheme;\n\n\t\t\tif (typeof result.onChange === 'function') {\n\t\t\t\tresult.onChange();\n\t\t\t}\n\t\t}\n\n\t\t[].forEach.call(document.styleSheets || [], styleSheet => {\n\t\t\t[].forEach.call(styleSheet.cssRules || [], cssRule => {\n\t\t\t\tconst colorSchemeMatch = prefersColorSchemeRegExp.test(Object(cssRule.media).mediaText);\n\n\t\t\t\tif (colorSchemeMatch) {\n\t\t\t\t\tconst index = [].indexOf.call(cssRule.parentStyleSheet.cssRules, cssRule);\n\n\t\t\t\t\tcssRule.parentStyleSheet.deleteRule(index);\n\t\t\t\t} else {\n\t\t\t\t\tconst colorIndexMatch = (Object(cssRule.media).mediaText || '').match(colorIndexRegExp);\n\n\t\t\t\t\tif (colorIndexMatch) {\n\t\t\t\t\t\tcssRule.media.mediaText = (\n\t\t\t\t\t\t\t(/^dark$/i.test(colorScheme)\n\t\t\t\t\t\t\t\t? colorIndexMatch[3] === '48'\n\t\t\t\t\t\t\t: /^light$/i.test(colorScheme)\n\t\t\t\t\t\t\t\t? colorIndexMatch[3] === '70'\n\t\t\t\t\t\t\t: colorIndexMatch[3] === '22')\n\t\t\t\t\t\t\t\t? 'not all and '\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t) + cssRule.media.mediaText.replace(colorIndexRegExp, '$2');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t};\n\tconst result = Object.defineProperty(\n\t\t{ hasNativeSupport, removeListener },\n\t\t'scheme',\n\t\t{ get: () => currentColorScheme, set }\n\t);\n\n\t// initialize the color scheme using the provided value, the system value, or light\n\tlet currentColorScheme = initialColorScheme || (mediaQueryList && mediaQueryList.matches ? 'dark' : 'light');\n\n\tset(currentColorScheme);\n\n\t// listen for system changes\n\tif (mediaQueryList) {\n\t\tmediaQueryList.addListener(mediaQueryListener);\n\t}\n\n\treturn result;\n};\n\nexport default prefersColorSchemeInit;\n"],"names":["colorIndexRegExp","prefersColorSchemeRegExp","prefersColorSchemeInit","initialColorScheme","mediaQueryString","mediaQueryList","window","matchMedia","hasNativeSupport","media","mediaQueryListener","set","matches","removeListener","colorScheme","currentColorScheme","result","onChange","forEach","call","document","styleSheets","styleSheet","cssRules","cssRule","colorSchemeMatch","test","Object","mediaText","index","indexOf","parentStyleSheet","deleteRule","colorIndexMatch","match","replace","defineProperty","get","addListener"],"mappings":";;AAAA,MAAMA,gBAAgB,GAAG,qDAAzB;AACA,MAAMC,wBAAwB,GAAG,wBAAjC;;MAEMC,sBAAsB,GAAGC,kBAAkB,IAAI;AACpD,QAAMC,gBAAgB,GAAG,8BAAzB;AACA,QAAMC,cAAc,GAAGC,MAAM,CAACC,UAAP,IAAqBA,UAAU,CAACH,gBAAD,CAAtD;AACA,QAAMI,gBAAgB,GAAGH,cAAc,IAAIA,cAAc,CAACI,KAAf,KAAyBL,gBAApE;;AACA,QAAMM,kBAAkB,GAAG,MAAM;AAChCC,IAAAA,GAAG,CAACN,cAAc,CAACO,OAAf,GAAyB,MAAzB,GAAkC,OAAnC,CAAH;AACA,GAFD;;AAGA,QAAMC,cAAc,GAAG,MAAM;AAC5B,QAAIR,cAAJ,EAAoB;AACnBA,MAAAA,cAAc,CAACQ,cAAf,CAA8BH,kBAA9B;AACA;AACD,GAJD;;AAKA,QAAMC,GAAG,GAAGG,WAAW,IAAI;AAC1B,QAAIA,WAAW,KAAKC,kBAApB,EAAwC;AACvCA,MAAAA,kBAAkB,GAAGD,WAArB;;AAEA,UAAI,OAAOE,MAAM,CAACC,QAAd,KAA2B,UAA/B,EAA2C;AAC1CD,QAAAA,MAAM,CAACC,QAAP;AACA;AACD;;AAED,OAAGC,OAAH,CAAWC,IAAX,CAAgBC,QAAQ,CAACC,WAAT,IAAwB,EAAxC,EAA4CC,UAAU,IAAI;AACzD,SAAGJ,OAAH,CAAWC,IAAX,CAAgBG,UAAU,CAACC,QAAX,IAAuB,EAAvC,EAA2CC,OAAO,IAAI;AACrD,cAAMC,gBAAgB,GAAGxB,wBAAwB,CAACyB,IAAzB,CAA8BC,M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,CAACI,kBAAD,CAAH,CAxDoD;;AA2DpD,MAAIV,cAAJ,EAAoB;AACnBA,IAAAA,cAAc,CAACiC,WAAf,CAA2B5B,kBAA3B;AACA;;AAED,SAAOM,MAAP;AACA;;;;"}
|
package/index.mjs
CHANGED
package/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["src/browser.js"],"sourcesContent":["const colorIndexRegExp = /((?:not )?all and )?(\\(color-index: *(22|48|70)\\))/i;\nconst prefersColorSchemeRegExp = /prefers-color-scheme:/i;\n\nconst prefersColorSchemeInit = initialColorScheme => {\n\tconst mediaQueryString = '(prefers-color-scheme: dark)';\n\tconst mediaQueryList = window.matchMedia && matchMedia(mediaQueryString);\n\tconst hasNativeSupport = mediaQueryList && mediaQueryList.media === mediaQueryString;\n\tconst mediaQueryListener = () => {\n\t\tset(mediaQueryList.matches ? 'dark' : 'light');\n\t};\n\tconst removeListener = () => {\n\t\tif (mediaQueryList) {\n\t\t\tmediaQueryList.removeListener(mediaQueryListener);\n\t\t}\n\t};\n\tconst set = colorScheme => {\n\t\tif (colorScheme !== currentColorScheme) {\n\t\t\tcurrentColorScheme = colorScheme;\n\n\t\t\tif (typeof result.onChange === 'function') {\n\t\t\t\tresult.onChange();\n\t\t\t}\n\t\t}\n\n\t\t[].forEach.call(document.styleSheets || [], styleSheet => {\n\t\t\t[].forEach.call(styleSheet.cssRules || [], cssRule => {\n\t\t\t\tconst colorSchemeMatch = prefersColorSchemeRegExp.test(Object(cssRule.media).mediaText);\n\n\t\t\t\tif (colorSchemeMatch) {\n\t\t\t\t\tconst index = [].indexOf.call(cssRule.parentStyleSheet.cssRules, cssRule);\n\n\t\t\t\t\tcssRule.parentStyleSheet.deleteRule(index);\n\t\t\t\t} else {\n\t\t\t\t\tconst colorIndexMatch = (Object(cssRule.media).mediaText || '').match(colorIndexRegExp);\n\n\t\t\t\t\tif (colorIndexMatch) {\n\t\t\t\t\t\tcssRule.media.mediaText = (\n\t\t\t\t\t\t\t(/^dark$/i.test(colorScheme)\n\t\t\t\t\t\t\t\t? colorIndexMatch[3] === '48'\n\t\t\t\t\t\t\t: /^light$/i.test(colorScheme)\n\t\t\t\t\t\t\t\t? colorIndexMatch[3] === '70'\n\t\t\t\t\t\t\t: colorIndexMatch[3] === '22')\n\t\t\t\t\t\t\t\t? 'not all and '\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t) + cssRule.media.mediaText.replace(colorIndexRegExp, '$2');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t};\n\tconst result = Object.defineProperty(\n\t\t{ hasNativeSupport, removeListener },\n\t\t'scheme',\n\t\t{ get: () => currentColorScheme, set }\n\t);\n\n\t// initialize the color scheme using the provided value, the system value, or light\n\tlet currentColorScheme = initialColorScheme || (mediaQueryList && mediaQueryList.matches ? 'dark' : 'light');\n\n\tset(currentColorScheme);\n\n\t// listen for system changes\n\tif (mediaQueryList) {\n\t\tmediaQueryList.addListener(mediaQueryListener);\n\t}\n\n\treturn result;\n};\n\nexport default prefersColorSchemeInit;\n"],"names":["colorIndexRegExp","prefersColorSchemeRegExp","prefersColorSchemeInit","initialColorScheme","mediaQueryString","mediaQueryList","window","matchMedia","hasNativeSupport","media","mediaQueryListener","set","matches","removeListener","colorScheme","currentColorScheme","result","onChange","forEach","call","document","styleSheets","styleSheet","cssRules","cssRule","colorSchemeMatch","test","Object","mediaText","index","indexOf","parentStyleSheet","deleteRule","colorIndexMatch","match","replace","defineProperty","get","addListener"],"mappings":"AAAA,MAAMA,gBAAgB,GAAG,qDAAzB;AACA,MAAMC,wBAAwB,GAAG,wBAAjC;;
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["src/browser.js"],"sourcesContent":["const colorIndexRegExp = /((?:not )?all and )?(\\(color-index: *(22|48|70)\\))/i;\nconst prefersColorSchemeRegExp = /prefers-color-scheme:/i;\n\nconst prefersColorSchemeInit = initialColorScheme => {\n\tconst mediaQueryString = '(prefers-color-scheme: dark)';\n\tconst mediaQueryList = window.matchMedia && matchMedia(mediaQueryString);\n\tconst hasNativeSupport = mediaQueryList && mediaQueryList.media === mediaQueryString;\n\tconst mediaQueryListener = () => {\n\t\tset(mediaQueryList.matches ? 'dark' : 'light');\n\t};\n\tconst removeListener = () => {\n\t\tif (mediaQueryList) {\n\t\t\tmediaQueryList.removeListener(mediaQueryListener);\n\t\t}\n\t};\n\tconst set = colorScheme => {\n\t\tif (colorScheme !== currentColorScheme) {\n\t\t\tcurrentColorScheme = colorScheme;\n\n\t\t\tif (typeof result.onChange === 'function') {\n\t\t\t\tresult.onChange();\n\t\t\t}\n\t\t}\n\n\t\t[].forEach.call(document.styleSheets || [], styleSheet => {\n\t\t\t[].forEach.call(styleSheet.cssRules || [], cssRule => {\n\t\t\t\tconst colorSchemeMatch = prefersColorSchemeRegExp.test(Object(cssRule.media).mediaText);\n\n\t\t\t\tif (colorSchemeMatch) {\n\t\t\t\t\tconst index = [].indexOf.call(cssRule.parentStyleSheet.cssRules, cssRule);\n\n\t\t\t\t\tcssRule.parentStyleSheet.deleteRule(index);\n\t\t\t\t} else {\n\t\t\t\t\tconst colorIndexMatch = (Object(cssRule.media).mediaText || '').match(colorIndexRegExp);\n\n\t\t\t\t\tif (colorIndexMatch) {\n\t\t\t\t\t\tcssRule.media.mediaText = (\n\t\t\t\t\t\t\t(/^dark$/i.test(colorScheme)\n\t\t\t\t\t\t\t\t? colorIndexMatch[3] === '48'\n\t\t\t\t\t\t\t: /^light$/i.test(colorScheme)\n\t\t\t\t\t\t\t\t? colorIndexMatch[3] === '70'\n\t\t\t\t\t\t\t: colorIndexMatch[3] === '22')\n\t\t\t\t\t\t\t\t? 'not all and '\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t) + cssRule.media.mediaText.replace(colorIndexRegExp, '$2');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t};\n\tconst result = Object.defineProperty(\n\t\t{ hasNativeSupport, removeListener },\n\t\t'scheme',\n\t\t{ get: () => currentColorScheme, set }\n\t);\n\n\t// initialize the color scheme using the provided value, the system value, or light\n\tlet currentColorScheme = initialColorScheme || (mediaQueryList && mediaQueryList.matches ? 'dark' : 'light');\n\n\tset(currentColorScheme);\n\n\t// listen for system changes\n\tif (mediaQueryList) {\n\t\tmediaQueryList.addListener(mediaQueryListener);\n\t}\n\n\treturn result;\n};\n\nexport default prefersColorSchemeInit;\n"],"names":["colorIndexRegExp","prefersColorSchemeRegExp","prefersColorSchemeInit","initialColorScheme","mediaQueryString","mediaQueryList","window","matchMedia","hasNativeSupport","media","mediaQueryListener","set","matches","removeListener","colorScheme","currentColorScheme","result","onChange","forEach","call","document","styleSheets","styleSheet","cssRules","cssRule","colorSchemeMatch","test","Object","mediaText","index","indexOf","parentStyleSheet","deleteRule","colorIndexMatch","match","replace","defineProperty","get","addListener"],"mappings":"AAAA,MAAMA,gBAAgB,GAAG,qDAAzB;AACA,MAAMC,wBAAwB,GAAG,wBAAjC;;MAEMC,sBAAsB,GAAGC,kBAAkB,IAAI;AACpD,QAAMC,gBAAgB,GAAG,8BAAzB;AACA,QAAMC,cAAc,GAAGC,MAAM,CAACC,UAAP,IAAqBA,UAAU,CAACH,gBAAD,CAAtD;AACA,QAAMI,gBAAgB,GAAGH,cAAc,IAAIA,cAAc,CAACI,KAAf,KAAyBL,gBAApE;;AACA,QAAMM,kBAAkB,GAAG,MAAM;AAChCC,IAAAA,GAAG,CAACN,cAAc,CAACO,OAAf,GAAyB,MAAzB,GAAkC,OAAnC,CAAH;AACA,GAFD;;AAGA,QAAMC,cAAc,GAAG,MAAM;AAC5B,QAAIR,cAAJ,EAAoB;AACnBA,MAAAA,cAAc,CAACQ,cAAf,CAA8BH,kBAA9B;AACA;AACD,GAJD;;AAKA,QAAMC,GAAG,GAAGG,WAAW,IAAI;AAC1B,QAAIA,WAAW,KAAKC,kBAApB,EAAwC;AACvCA,MAAAA,kBAAkB,GAAGD,WAArB;;AAEA,UAA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;;AAmCA,QAAMgB,MAAM,GAAGW,MAAM,CAACS,cAAP,CACd;AAAE5B,IAAAA,gBAAF;AAAoBK,IAAAA;AAApB,GADc,EAEd,QAFc,EAGd;AAAEwB,IAAAA,GAAG,EAAE,MAAMtB,kBAAb;AAAiCJ,IAAAA;AAAjC,GAHc,CAAf,CA/CoD;;AAsDpD,MAAII,kBAAkB,GAAGZ,kBAAkB,KAAKE,cAAc,IAAIA,cAAc,CAACO,OAAjC,GAA2C,MAA3C,GAAoD,OAAzD,CAA3C;AAEAD,EAAAA,GAAG,CAACI,kBAAD,CAAH,CAxDoD;;AA2DpD,MAAIV,cAAJ,EAAoB;AACnBA,IAAAA,cAAc,CAACiC,WAAf,CAA2B5B,kBAA3B;AACA;;AAED,SAAOM,MAAP;AACA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-prefers-color-scheme",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Use light and dark color schemes in all browsers",
|
|
5
5
|
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
|
|
6
6
|
"license": "CC0-1.0",
|
|
@@ -38,24 +38,22 @@
|
|
|
38
38
|
"test:tape": "postcss-tape --plugin postcss.js"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
|
-
"node": ">=
|
|
41
|
+
"node": ">=12"
|
|
42
42
|
},
|
|
43
|
-
"
|
|
44
|
-
"postcss": "^
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"postcss": "^8.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@babel/core": "
|
|
48
|
-
"@babel/preset-env": "
|
|
49
|
-
"babel
|
|
50
|
-
"cross-env": "
|
|
51
|
-
"eslint": "
|
|
52
|
-
"
|
|
53
|
-
"postcss-tape": "
|
|
54
|
-
"pre-commit": "
|
|
55
|
-
"rollup": "
|
|
56
|
-
"rollup-plugin-
|
|
57
|
-
"rollup-plugin-terser": "^5.0.0",
|
|
58
|
-
"uglify-js": "^3.5.15"
|
|
47
|
+
"@babel/core": "7.15.5",
|
|
48
|
+
"@babel/preset-env": "7.15.6",
|
|
49
|
+
"@rollup/plugin-babel": "5.3.0",
|
|
50
|
+
"cross-env": "7.0.3",
|
|
51
|
+
"eslint": "7.32.0",
|
|
52
|
+
"postcss": "8.3.6",
|
|
53
|
+
"postcss-tape": "6.0.1",
|
|
54
|
+
"pre-commit": "1.2.2",
|
|
55
|
+
"rollup": "2.56.3",
|
|
56
|
+
"rollup-plugin-terser": "7.0.2"
|
|
59
57
|
},
|
|
60
58
|
"eslintConfig": {
|
|
61
59
|
"env": {
|
|
@@ -64,10 +62,8 @@
|
|
|
64
62
|
"node": true
|
|
65
63
|
},
|
|
66
64
|
"extends": "eslint:recommended",
|
|
67
|
-
"parser": "babel-eslint",
|
|
68
65
|
"parserOptions": {
|
|
69
|
-
"ecmaVersion":
|
|
70
|
-
"impliedStrict": true,
|
|
66
|
+
"ecmaVersion": 2020,
|
|
71
67
|
"sourceType": "module"
|
|
72
68
|
},
|
|
73
69
|
"root": true
|
package/postcss.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
2
|
-
|
|
3
|
-
var postcss$1 = _interopDefault(require('postcss'));
|
|
4
|
-
|
|
5
1
|
const mediaRegExp = /^media$/i;
|
|
6
2
|
const prefersInterfaceRegExp = /\(\s*prefers-color-scheme\s*:\s*(dark|light|no-preference)\s*\)/i;
|
|
7
3
|
const colorIndexByStyle = {
|
|
@@ -12,27 +8,32 @@ const colorIndexByStyle = {
|
|
|
12
8
|
|
|
13
9
|
const prefersInterfaceReplacer = ($0, style) => `(color-index: ${colorIndexByStyle[style.toLowerCase()]})`;
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
const creator = opts => {
|
|
16
12
|
const preserve = 'preserve' in Object(opts) ? opts.preserve : true;
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
return {
|
|
14
|
+
postcssPlugin: 'postcss-prefers-color-scheme',
|
|
15
|
+
Once: root => {
|
|
16
|
+
root.walkAtRules(mediaRegExp, atRule => {
|
|
17
|
+
const {
|
|
18
|
+
params
|
|
19
|
+
} = atRule;
|
|
20
|
+
const altParams = params.replace(prefersInterfaceRegExp, prefersInterfaceReplacer);
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
if (params !== altParams) {
|
|
23
|
+
if (preserve) {
|
|
24
|
+
atRule.cloneBefore({
|
|
25
|
+
params: altParams
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
atRule.params = altParams;
|
|
29
|
+
}
|
|
31
30
|
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
34
33
|
};
|
|
35
|
-
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
creator.postcss = true;
|
|
36
37
|
|
|
37
|
-
module.exports =
|
|
38
|
+
module.exports = creator;
|
|
38
39
|
//# sourceMappingURL=postcss.js.map
|
package/postcss.mjs
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import postcss$1 from 'postcss';
|
|
2
|
-
|
|
3
1
|
const mediaRegExp = /^media$/i;
|
|
4
2
|
const prefersInterfaceRegExp = /\(\s*prefers-color-scheme\s*:\s*(dark|light|no-preference)\s*\)/i;
|
|
5
3
|
const colorIndexByStyle = {
|
|
@@ -10,27 +8,32 @@ const colorIndexByStyle = {
|
|
|
10
8
|
|
|
11
9
|
const prefersInterfaceReplacer = ($0, style) => `(color-index: ${colorIndexByStyle[style.toLowerCase()]})`;
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
const creator = opts => {
|
|
14
12
|
const preserve = 'preserve' in Object(opts) ? opts.preserve : true;
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
return {
|
|
14
|
+
postcssPlugin: 'postcss-prefers-color-scheme',
|
|
15
|
+
Once: root => {
|
|
16
|
+
root.walkAtRules(mediaRegExp, atRule => {
|
|
17
|
+
const {
|
|
18
|
+
params
|
|
19
|
+
} = atRule;
|
|
20
|
+
const altParams = params.replace(prefersInterfaceRegExp, prefersInterfaceReplacer);
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
if (params !== altParams) {
|
|
23
|
+
if (preserve) {
|
|
24
|
+
atRule.cloneBefore({
|
|
25
|
+
params: altParams
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
atRule.params = altParams;
|
|
29
|
+
}
|
|
29
30
|
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
32
33
|
};
|
|
33
|
-
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
creator.postcss = true;
|
|
34
37
|
|
|
35
|
-
export default
|
|
38
|
+
export { creator as default };
|
|
36
39
|
//# sourceMappingURL=postcss.mjs.map
|
package/CHANGELOG.md
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# Changes to Prefers Color Scheme
|
|
2
|
-
|
|
3
|
-
### 4.0.0 (May 24, 2019)
|
|
4
|
-
|
|
5
|
-
- Updated: `postcss` to 7.0.16 (patch)
|
|
6
|
-
- Updated: Node 8+ compatibility (major)
|
|
7
|
-
|
|
8
|
-
### 3.1.1 (November 10, 2018)
|
|
9
|
-
|
|
10
|
-
- Updated: Project organization. No functional changes.
|
|
11
|
-
|
|
12
|
-
### 3.1.0 (November 10, 2018)
|
|
13
|
-
|
|
14
|
-
- Include CLI tool for transforming CSS without any installation
|
|
15
|
-
- Update documentation
|
|
16
|
-
|
|
17
|
-
### 3.0.0 (November 4, 2018)
|
|
18
|
-
|
|
19
|
-
- Preserve `prefers-color-scheme` queries by default for non-JS environments
|
|
20
|
-
- Remove `prefers-color-scheme` queries on the frontend for JS environments
|
|
21
|
-
|
|
22
|
-
### 2.0.0 (November 3, 2018)
|
|
23
|
-
|
|
24
|
-
- The client library now returns an object with various features, including:
|
|
25
|
-
- `scheme` to get or set the preferred color scheme
|
|
26
|
-
- `hasNativeSupport` to report whether `prefers-color-scheme` is supported
|
|
27
|
-
- `onChange` to listen for when the preferred color scheme changes
|
|
28
|
-
- `removeListener` to destroy the native `prefers-color-scheme` listener
|
|
29
|
-
|
|
30
|
-
### 1.0.0 (September 24, 2018)
|
|
31
|
-
|
|
32
|
-
- Initial version
|