css-prefers-color-scheme 11.0.0 → 11.0.1
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/CHANGELOG.md +3 -4
- package/README.md +3 -3
- package/dist/browser-global.js +1 -1
- package/dist/browser-global.js.map +1 -1
- package/dist/browser.cjs +1 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.mjs +1 -1
- package/dist/browser.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Changes to Prefers Color Scheme
|
|
2
2
|
|
|
3
|
-
### 11.0.
|
|
3
|
+
### 11.0.1
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
_July 22, 2026_
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
- Removed: `commonjs` API. In supported Node versions `require(esm)` will work without needing to make code changes.
|
|
7
|
+
- Rewritten browser polyfill as ES3
|
|
9
8
|
|
|
10
9
|
[Full CHANGELOG](https://github.com/csstools/postcss-plugins/tree/main/plugins/css-prefers-color-scheme/CHANGELOG.md)
|
package/README.md
CHANGED
|
@@ -133,12 +133,12 @@ or
|
|
|
133
133
|
|
|
134
134
|
```html
|
|
135
135
|
<!-- When using a CDN url you will have to manually update the version number -->
|
|
136
|
-
<script src="https://unpkg.com/css-prefers-color-scheme@11.0.
|
|
136
|
+
<script src="https://unpkg.com/css-prefers-color-scheme@11.0.1/dist/browser-global.js"></script>
|
|
137
137
|
<script>prefersColorSchemeInit()</script>
|
|
138
138
|
```
|
|
139
139
|
|
|
140
140
|
> [!TIP]
|
|
141
|
-
> Please use a versioned url, like this : `https://unpkg.com/css-prefers-color-scheme@11.0.
|
|
141
|
+
> Please use a versioned url, like this : `https://unpkg.com/css-prefers-color-scheme@11.0.1/dist/browser-global.js`
|
|
142
142
|
> Without the version, you might unexpectedly get a new major version of the library with breaking changes.
|
|
143
143
|
|
|
144
144
|
[Prefers Color Scheme] works in all major browsers, including Safari 6+ and
|
|
@@ -212,7 +212,7 @@ const prefersColorScheme = prefersColorSchemeInit('light', { debug: true });
|
|
|
212
212
|
```
|
|
213
213
|
|
|
214
214
|
```html
|
|
215
|
-
<script src="https://unpkg.com/css-prefers-color-scheme@11.0.
|
|
215
|
+
<script src="https://unpkg.com/css-prefers-color-scheme@11.0.1/dist/browser-global.js"></script>
|
|
216
216
|
<script>prefersColorSchemeInit('light', { debug: true })</script>
|
|
217
217
|
```
|
|
218
218
|
|
package/dist/browser-global.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(){
|
|
1
|
+
!function(){function prefersColorSchemeInit(e,t){t||(t={}),t={debug:!!t.debug||!1};var r="(prefers-color-scheme: dark)",a="matchMedia"in window&&window.matchMedia(r),i=a&&a.media===r,o=function mediaQueryListener(){c(a&&a.matches?"dark":"light")},c=function set(e){"dark"!==e&&"light"!==e&&(e=i&&a.matches?"dark":"light"),e!==d&&(d=e,"function"==typeof n.onChange&&n.onChange()),[].forEach.call(document.styleSheets||[],function(r){try{var a=[];[].forEach.call(r.cssRules||[],function(e){a.push(e)}),a.forEach(function(t){if(/prefers-color-scheme:/i.test(Object(t.media).mediaText)){var r=[].indexOf.call(t.parentStyleSheet.cssRules,t);t.parentStyleSheet.deleteRule(r)}else{var a=(Object(t.media).mediaText||"").match(/\( *(?:color|max-color): *(48842621|70318723) *\)/i);a&&a.length>1&&("dark"===e&&"48842621"===a[1]?t.media.mediaText=t.media.mediaText.replace(/\( *color: *(?:48842621) *\)/i,"(max-color: "+a[1]+")"):"light"===e&&"70318723"===a[1]?t.media.mediaText=t.media.mediaText.replace(/\( *color: *(?:70318723) *\)/i,"(max-color: "+a[1]+")"):t.media.mediaText=t.media.mediaText.replace(/\( *max-color: *(?:48842621|70318723) *\)/i,"(color: "+a[1]+")"))}})}catch(i){t.debug&&console.error(i)}})},n=Object.defineProperty({hasNativeSupport:i,removeListener:function removeListener(){a&&a.removeListener(o)}},"scheme",{get:function get(){return d},set:c}),d=e||(a&&a.matches?"dark":"light");return c(d),a&&("addEventListener"in a?a.addEventListener("change",o):a.addListener(o)),n}("object"==typeof window&&window||"object"==typeof self&&self||{}).prefersColorSchemeInit=prefersColorSchemeInit}();
|
|
2
2
|
//# sourceMappingURL=browser-global.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-global.js","sources":["../src/browser.js","../src/browser-global.js"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"browser-global.js","sources":["../src/browser.js","../src/browser-global.js"],"sourcesContent":["/* eslint-disable comma-dangle */\nfunction prefersColorSchemeInit(initialColorScheme, options) {\n\t// OPTIONS\n\t{\n\t\tif (!options) {\n\t\t\toptions = {};\n\t\t}\n\n\t\toptions = {\n\t\t\tdebug: (!!options.debug) || false,\n\t\t};\n\t}\n\n\tvar mediaQueryString = '(prefers-color-scheme: dark)';\n\tvar mediaQueryList = ('matchMedia' in window) && window.matchMedia(mediaQueryString);\n\tvar hasNativeSupport = mediaQueryList && mediaQueryList.media === mediaQueryString;\n\tvar mediaQueryListener = function mediaQueryListener() {\n\t\tset((mediaQueryList && mediaQueryList.matches) ? 'dark' : 'light');\n\t};\n\tvar removeListener = function removeListener() {\n\t\tif (mediaQueryList) {\n\t\t\tmediaQueryList.removeListener(mediaQueryListener);\n\t\t}\n\t};\n\tvar set = function set(colorScheme) {\n\t\tif (colorScheme !== 'dark' && colorScheme !== 'light') {\n\t\t\tif (hasNativeSupport) {\n\t\t\t\tcolorScheme = mediaQueryList.matches ? 'dark' : 'light';\n\t\t\t} else {\n\t\t\t\tcolorScheme = 'light';\n\t\t\t}\n\t\t}\n\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 || [], function(styleSheet) {\n\t\t\ttry {\n\t\t\t\t// cssRules is a live list. Converting to an Array first.\n\t\t\t\tvar rules = [];\n\t\t\t\t[].forEach.call(styleSheet.cssRules || [], function(cssRule) {\n\t\t\t\t\trules.push(cssRule);\n\t\t\t\t});\n\n\t\t\t\trules.forEach(function(cssRule) {\n\t\t\t\t\tvar colorSchemeMatch = /prefers-color-scheme:/i.test(Object(cssRule.media).mediaText);\n\n\t\t\t\t\tif (colorSchemeMatch) {\n\t\t\t\t\t\tvar index = [].indexOf.call(cssRule.parentStyleSheet.cssRules, cssRule);\n\t\t\t\t\t\tcssRule.parentStyleSheet.deleteRule(index);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// New style which supports complex media queries.\n\t\t\t\t\t\tvar colorDepthMatch = (Object(cssRule.media).mediaText || '').match(/\\( *(?:color|max-color): *(48842621|70318723) *\\)/i);\n\t\t\t\t\t\tif (colorDepthMatch && colorDepthMatch.length > 1) {\n\t\t\t\t\t\t\tif (colorScheme === 'dark' && (colorDepthMatch[1] === '48842621')) {\n\t\t\t\t\t\t\t\t// preferred is dark and rule is dark.\n\t\t\t\t\t\t\t\tcssRule.media.mediaText = cssRule.media.mediaText.replace(/\\( *color: *(?:48842621) *\\)/i, '(max-color: ' + colorDepthMatch[1] + ')');\n\t\t\t\t\t\t\t} else if (colorScheme === 'light' && (colorDepthMatch[1] === '70318723')) {\n\t\t\t\t\t\t\t\t// preferred is light and rule is light.\n\t\t\t\t\t\t\t\tcssRule.media.mediaText = cssRule.media.mediaText.replace(/\\( *color: *(?:70318723) *\\)/i, '(max-color: ' + colorDepthMatch[1] + ')');\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcssRule.media.mediaText = cssRule.media.mediaText.replace(/\\( *max-color: *(?:48842621|70318723) *\\)/i, '(color: ' + colorDepthMatch[1] + ')');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} catch (e) {\n\t\t\t\tif (options.debug) {\n\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.error(e);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t};\n\tvar result = Object.defineProperty(\n\t\t{ hasNativeSupport, removeListener },\n\t\t'scheme',\n\t\t{\n\t\t\tget: function get() {\n\t\t\t\treturn currentColorScheme;\n\t\t\t},\n\t\t\tset: set\n\t\t}\n\t);\n\n\t// initialize the color scheme using the provided value, the system value, or light\n\tvar currentColorScheme = initialColorScheme || (mediaQueryList && mediaQueryList.matches ? 'dark' : 'light');\n\n\tset(currentColorScheme);\n\n\t// listen for system changes\n\tif (mediaQueryList) {\n\t\tif ('addEventListener' in mediaQueryList) {\n\t\t\tmediaQueryList.addEventListener('change', mediaQueryListener);\n\t\t} else {\n\t\t\tmediaQueryList.addListener(mediaQueryListener);\n\t\t}\n\t}\n\n\treturn result;\n};\n\nexport default prefersColorSchemeInit;\n","import { default as prefersColorSchemeInit } from './browser';\n\n(function (global) {\n\tglobal.prefersColorSchemeInit = prefersColorSchemeInit;\n}('object' === typeof window && window || 'object' === typeof self && self || {}));\n"],"names":["prefersColorSchemeInit","initialColorScheme","options","debug","mediaQueryString","mediaQueryList","window","matchMedia","hasNativeSupport","media","mediaQueryListener","set","matches","colorScheme","currentColorScheme","result","onChange","forEach","call","document","styleSheets","styleSheet","rules","cssRules","cssRule","push","test","Object","mediaText","index","indexOf","parentStyleSheet","deleteRule","colorDepthMatch","match","length","replace","e","console","error","defineProperty","removeListener","get","addEventListener","addListener","self"],"mappings":"YACA,SAASA,uBAAuBC,EAAoBC,GAG7CA,IACJA,EAAU,CAAA,GAGXA,EAAU,CACTC,QAAUD,EAAQC,QAAU,GAI9B,IAAIC,EAAmB,+BACnBC,EAAkB,eAAgBC,QAAWA,OAAOC,WAAWH,GAC/DI,EAAmBH,GAAkBA,EAAeI,QAAUL,EAC9DM,EAAqB,SAASA,qBACjCC,EAAKN,GAAkBA,EAAeO,QAAW,OAAS,QAC3D,EAMID,EAAM,SAASA,IAAIE,GACF,SAAhBA,GAA0C,UAAhBA,IAE5BA,EADGL,GACWH,EAAeO,QAAU,OAEzB,SAIZC,IAAgBC,IACnBA,EAAqBD,EAEU,mBAApBE,EAAOC,UACjBD,EAAOC,YAIT,GAAGC,QAAQC,KAAKC,SAASC,aAAe,GAAI,SAASC,GACpD,IAEC,IAAIC,EAAQ,GACZ,GAAGL,QAAQC,KAAKG,EAAWE,UAAY,GAAI,SAASC,GACnDF,EAAMG,KAAKD,EACZ,GAEAF,EAAML,QAAQ,SAASO,GAGtB,GAFuB,yBAAyBE,KAAKC,OAAOH,EAAQf,OAAOmB,WAErD,CACrB,IAAIC,EAAQ,GAAGC,QAAQZ,KAAKM,EAAQO,iBAAiBR,SAAUC,GAC/DA,EAAQO,iBAAiBC,WAAWH,EACrC,KAAO,CAEN,IAAII,GAAmBN,OAAOH,EAAQf,OAAOmB,WAAa,IAAIM,MAAM,sDAChED,GAAmBA,EAAgBE,OAAS,IAC3B,SAAhBtB,GAAkD,aAAvBoB,EAAgB,GAE9CT,EAAQf,MAAMmB,UAAYJ,EAAQf,MAAMmB,UAAUQ,QAAQ,gCAAiC,eAAiBH,EAAgB,GAAK,KACvG,UAAhBpB,GAAmD,aAAvBoB,EAAgB,GAEtDT,EAAQf,MAAMmB,UAAYJ,EAAQf,MAAMmB,UAAUQ,QAAQ,gCAAiC,eAAiBH,EAAgB,GAAK,KAEjIT,EAAQf,MAAMmB,UAAYJ,EAAQf,MAAMmB,UAAUQ,QAAQ,6CAA8C,WAAaH,EAAgB,GAAK,KAG7I,CACD,EACD,CAAE,MAAOI,GACJnC,EAAQC,OAEXmC,QAAQC,MAAMF,EAEhB,CACD,EACD,EACItB,EAASY,OAAOa,eACnB,CAAEhC,mBAAkBiC,eA7DA,SAASA,iBACzBpC,GACHA,EAAeoC,eAAe/B,EAEhC,GA0DC,SACA,CACCgC,IAAK,SAASA,MACb,OAAO5B,CACR,EACAH,IAAKA,IAKHG,EAAqBb,IAAuBI,GAAkBA,EAAeO,QAAU,OAAS,SAapG,OAXAD,EAAIG,GAGAT,IACC,qBAAsBA,EACzBA,EAAesC,iBAAiB,SAAUjC,GAE1CL,EAAeuC,YAAYlC,IAItBK,CACR,ECrGE,iBAAoBT,QAAUA,QAAU,iBAAoBuC,MAAQA,MAAQ,IADtE7C,uBAAyBA"}
|
package/dist/browser.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
module.exports=function prefersColorSchemeInit(e,t){t||(t={}),t={debug:!!t.debug||!1};var a="(prefers-color-scheme: dark)",r="matchMedia"in window&&window.matchMedia(a),i=r&&r.media===a,o=function mediaQueryListener(){c(r&&r.matches?"dark":"light")},c=function set(e){"dark"!==e&&"light"!==e&&(e=i&&r.matches?"dark":"light"),e!==d&&(d=e,"function"==typeof n.onChange&&n.onChange()),[].forEach.call(document.styleSheets||[],function(a){try{var r=[];[].forEach.call(a.cssRules||[],function(e){r.push(e)}),r.forEach(function(t){if(/prefers-color-scheme:/i.test(Object(t.media).mediaText)){var a=[].indexOf.call(t.parentStyleSheet.cssRules,t);t.parentStyleSheet.deleteRule(a)}else{var r=(Object(t.media).mediaText||"").match(/\( *(?:color|max-color): *(48842621|70318723) *\)/i);r&&r.length>1&&("dark"===e&&"48842621"===r[1]?t.media.mediaText=t.media.mediaText.replace(/\( *color: *(?:48842621) *\)/i,"(max-color: "+r[1]+")"):"light"===e&&"70318723"===r[1]?t.media.mediaText=t.media.mediaText.replace(/\( *color: *(?:70318723) *\)/i,"(max-color: "+r[1]+")"):t.media.mediaText=t.media.mediaText.replace(/\( *max-color: *(?:48842621|70318723) *\)/i,"(color: "+r[1]+")"))}})}catch(i){t.debug&&console.error(i)}})},n=Object.defineProperty({hasNativeSupport:i,removeListener:function removeListener(){r&&r.removeListener(o)}},"scheme",{get:function get(){return d},set:c}),d=e||(r&&r.matches?"dark":"light");return c(d),r&&("addEventListener"in r?r.addEventListener("change",o):r.addListener(o)),n};
|
|
2
2
|
//# sourceMappingURL=browser.cjs.map
|
package/dist/browser.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.cjs","sources":["../src/browser.js"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"browser.cjs","sources":["../src/browser.js"],"sourcesContent":["/* eslint-disable comma-dangle */\nfunction prefersColorSchemeInit(initialColorScheme, options) {\n\t// OPTIONS\n\t{\n\t\tif (!options) {\n\t\t\toptions = {};\n\t\t}\n\n\t\toptions = {\n\t\t\tdebug: (!!options.debug) || false,\n\t\t};\n\t}\n\n\tvar mediaQueryString = '(prefers-color-scheme: dark)';\n\tvar mediaQueryList = ('matchMedia' in window) && window.matchMedia(mediaQueryString);\n\tvar hasNativeSupport = mediaQueryList && mediaQueryList.media === mediaQueryString;\n\tvar mediaQueryListener = function mediaQueryListener() {\n\t\tset((mediaQueryList && mediaQueryList.matches) ? 'dark' : 'light');\n\t};\n\tvar removeListener = function removeListener() {\n\t\tif (mediaQueryList) {\n\t\t\tmediaQueryList.removeListener(mediaQueryListener);\n\t\t}\n\t};\n\tvar set = function set(colorScheme) {\n\t\tif (colorScheme !== 'dark' && colorScheme !== 'light') {\n\t\t\tif (hasNativeSupport) {\n\t\t\t\tcolorScheme = mediaQueryList.matches ? 'dark' : 'light';\n\t\t\t} else {\n\t\t\t\tcolorScheme = 'light';\n\t\t\t}\n\t\t}\n\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 || [], function(styleSheet) {\n\t\t\ttry {\n\t\t\t\t// cssRules is a live list. Converting to an Array first.\n\t\t\t\tvar rules = [];\n\t\t\t\t[].forEach.call(styleSheet.cssRules || [], function(cssRule) {\n\t\t\t\t\trules.push(cssRule);\n\t\t\t\t});\n\n\t\t\t\trules.forEach(function(cssRule) {\n\t\t\t\t\tvar colorSchemeMatch = /prefers-color-scheme:/i.test(Object(cssRule.media).mediaText);\n\n\t\t\t\t\tif (colorSchemeMatch) {\n\t\t\t\t\t\tvar index = [].indexOf.call(cssRule.parentStyleSheet.cssRules, cssRule);\n\t\t\t\t\t\tcssRule.parentStyleSheet.deleteRule(index);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// New style which supports complex media queries.\n\t\t\t\t\t\tvar colorDepthMatch = (Object(cssRule.media).mediaText || '').match(/\\( *(?:color|max-color): *(48842621|70318723) *\\)/i);\n\t\t\t\t\t\tif (colorDepthMatch && colorDepthMatch.length > 1) {\n\t\t\t\t\t\t\tif (colorScheme === 'dark' && (colorDepthMatch[1] === '48842621')) {\n\t\t\t\t\t\t\t\t// preferred is dark and rule is dark.\n\t\t\t\t\t\t\t\tcssRule.media.mediaText = cssRule.media.mediaText.replace(/\\( *color: *(?:48842621) *\\)/i, '(max-color: ' + colorDepthMatch[1] + ')');\n\t\t\t\t\t\t\t} else if (colorScheme === 'light' && (colorDepthMatch[1] === '70318723')) {\n\t\t\t\t\t\t\t\t// preferred is light and rule is light.\n\t\t\t\t\t\t\t\tcssRule.media.mediaText = cssRule.media.mediaText.replace(/\\( *color: *(?:70318723) *\\)/i, '(max-color: ' + colorDepthMatch[1] + ')');\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcssRule.media.mediaText = cssRule.media.mediaText.replace(/\\( *max-color: *(?:48842621|70318723) *\\)/i, '(color: ' + colorDepthMatch[1] + ')');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} catch (e) {\n\t\t\t\tif (options.debug) {\n\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.error(e);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t};\n\tvar result = Object.defineProperty(\n\t\t{ hasNativeSupport, removeListener },\n\t\t'scheme',\n\t\t{\n\t\t\tget: function get() {\n\t\t\t\treturn currentColorScheme;\n\t\t\t},\n\t\t\tset: set\n\t\t}\n\t);\n\n\t// initialize the color scheme using the provided value, the system value, or light\n\tvar currentColorScheme = initialColorScheme || (mediaQueryList && mediaQueryList.matches ? 'dark' : 'light');\n\n\tset(currentColorScheme);\n\n\t// listen for system changes\n\tif (mediaQueryList) {\n\t\tif ('addEventListener' in mediaQueryList) {\n\t\t\tmediaQueryList.addEventListener('change', mediaQueryListener);\n\t\t} else {\n\t\t\tmediaQueryList.addListener(mediaQueryListener);\n\t\t}\n\t}\n\n\treturn result;\n};\n\nexport default prefersColorSchemeInit;\n"],"names":["prefersColorSchemeInit","initialColorScheme","options","debug","mediaQueryString","mediaQueryList","window","matchMedia","hasNativeSupport","media","mediaQueryListener","set","matches","colorScheme","currentColorScheme","result","onChange","forEach","call","document","styleSheets","styleSheet","rules","cssRules","cssRule","push","test","Object","mediaText","index","indexOf","parentStyleSheet","deleteRule","colorDepthMatch","match","length","replace","e","console","error","defineProperty","removeListener","get","addEventListener","addListener"],"mappings":"eACA,SAASA,uBAAuBC,EAAoBC,GAG7CA,IACJA,EAAU,CAAA,GAGXA,EAAU,CACTC,QAAUD,EAAQC,QAAU,GAI9B,IAAIC,EAAmB,+BACnBC,EAAkB,eAAgBC,QAAWA,OAAOC,WAAWH,GAC/DI,EAAmBH,GAAkBA,EAAeI,QAAUL,EAC9DM,EAAqB,SAASA,qBACjCC,EAAKN,GAAkBA,EAAeO,QAAW,OAAS,QAC3D,EAMID,EAAM,SAASA,IAAIE,GACF,SAAhBA,GAA0C,UAAhBA,IAE5BA,EADGL,GACWH,EAAeO,QAAU,OAEzB,SAIZC,IAAgBC,IACnBA,EAAqBD,EAEU,mBAApBE,EAAOC,UACjBD,EAAOC,YAIT,GAAGC,QAAQC,KAAKC,SAASC,aAAe,GAAI,SAASC,GACpD,IAEC,IAAIC,EAAQ,GACZ,GAAGL,QAAQC,KAAKG,EAAWE,UAAY,GAAI,SAASC,GACnDF,EAAMG,KAAKD,EACZ,GAEAF,EAAML,QAAQ,SAASO,GAGtB,GAFuB,yBAAyBE,KAAKC,OAAOH,EAAQf,OAAOmB,WAErD,CACrB,IAAIC,EAAQ,GAAGC,QAAQZ,KAAKM,EAAQO,iBAAiBR,SAAUC,GAC/DA,EAAQO,iBAAiBC,WAAWH,EACrC,KAAO,CAEN,IAAII,GAAmBN,OAAOH,EAAQf,OAAOmB,WAAa,IAAIM,MAAM,sDAChED,GAAmBA,EAAgBE,OAAS,IAC3B,SAAhBtB,GAAkD,aAAvBoB,EAAgB,GAE9CT,EAAQf,MAAMmB,UAAYJ,EAAQf,MAAMmB,UAAUQ,QAAQ,gCAAiC,eAAiBH,EAAgB,GAAK,KACvG,UAAhBpB,GAAmD,aAAvBoB,EAAgB,GAEtDT,EAAQf,MAAMmB,UAAYJ,EAAQf,MAAMmB,UAAUQ,QAAQ,gCAAiC,eAAiBH,EAAgB,GAAK,KAEjIT,EAAQf,MAAMmB,UAAYJ,EAAQf,MAAMmB,UAAUQ,QAAQ,6CAA8C,WAAaH,EAAgB,GAAK,KAG7I,CACD,EACD,CAAE,MAAOI,GACJnC,EAAQC,OAEXmC,QAAQC,MAAMF,EAEhB,CACD,EACD,EACItB,EAASY,OAAOa,eACnB,CAAEhC,mBAAkBiC,eA7DA,SAASA,iBACzBpC,GACHA,EAAeoC,eAAe/B,EAEhC,GA0DC,SACA,CACCgC,IAAK,SAASA,MACb,OAAO5B,CACR,EACAH,IAAKA,IAKHG,EAAqBb,IAAuBI,GAAkBA,EAAeO,QAAU,OAAS,SAapG,OAXAD,EAAIG,GAGAT,IACC,qBAAsBA,EACzBA,EAAesC,iBAAiB,SAAUjC,GAE1CL,EAAeuC,YAAYlC,IAItBK,CACR"}
|
package/dist/browser.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
function prefersColorSchemeInit(e,t){t||(t={}),t={debug:!!t.debug||!1};var a="(prefers-color-scheme: dark)",r="matchMedia"in window&&window.matchMedia(a),i=r&&r.media===a,o=function mediaQueryListener(){c(r&&r.matches?"dark":"light")},c=function set(e){"dark"!==e&&"light"!==e&&(e=i&&r.matches?"dark":"light"),e!==d&&(d=e,"function"==typeof n.onChange&&n.onChange()),[].forEach.call(document.styleSheets||[],function(a){try{var r=[];[].forEach.call(a.cssRules||[],function(e){r.push(e)}),r.forEach(function(t){if(/prefers-color-scheme:/i.test(Object(t.media).mediaText)){var a=[].indexOf.call(t.parentStyleSheet.cssRules,t);t.parentStyleSheet.deleteRule(a)}else{var r=(Object(t.media).mediaText||"").match(/\( *(?:color|max-color): *(48842621|70318723) *\)/i);r&&r.length>1&&("dark"===e&&"48842621"===r[1]?t.media.mediaText=t.media.mediaText.replace(/\( *color: *(?:48842621) *\)/i,"(max-color: "+r[1]+")"):"light"===e&&"70318723"===r[1]?t.media.mediaText=t.media.mediaText.replace(/\( *color: *(?:70318723) *\)/i,"(max-color: "+r[1]+")"):t.media.mediaText=t.media.mediaText.replace(/\( *max-color: *(?:48842621|70318723) *\)/i,"(color: "+r[1]+")"))}})}catch(i){t.debug&&console.error(i)}})},n=Object.defineProperty({hasNativeSupport:i,removeListener:function removeListener(){r&&r.removeListener(o)}},"scheme",{get:function get(){return d},set:c}),d=e||(r&&r.matches?"dark":"light");return c(d),r&&("addEventListener"in r?r.addEventListener("change",o):r.addListener(o)),n}export{prefersColorSchemeInit as default};
|
|
2
2
|
//# sourceMappingURL=browser.mjs.map
|
package/dist/browser.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.mjs","sources":["../src/browser.js"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"browser.mjs","sources":["../src/browser.js"],"sourcesContent":["/* eslint-disable comma-dangle */\nfunction prefersColorSchemeInit(initialColorScheme, options) {\n\t// OPTIONS\n\t{\n\t\tif (!options) {\n\t\t\toptions = {};\n\t\t}\n\n\t\toptions = {\n\t\t\tdebug: (!!options.debug) || false,\n\t\t};\n\t}\n\n\tvar mediaQueryString = '(prefers-color-scheme: dark)';\n\tvar mediaQueryList = ('matchMedia' in window) && window.matchMedia(mediaQueryString);\n\tvar hasNativeSupport = mediaQueryList && mediaQueryList.media === mediaQueryString;\n\tvar mediaQueryListener = function mediaQueryListener() {\n\t\tset((mediaQueryList && mediaQueryList.matches) ? 'dark' : 'light');\n\t};\n\tvar removeListener = function removeListener() {\n\t\tif (mediaQueryList) {\n\t\t\tmediaQueryList.removeListener(mediaQueryListener);\n\t\t}\n\t};\n\tvar set = function set(colorScheme) {\n\t\tif (colorScheme !== 'dark' && colorScheme !== 'light') {\n\t\t\tif (hasNativeSupport) {\n\t\t\t\tcolorScheme = mediaQueryList.matches ? 'dark' : 'light';\n\t\t\t} else {\n\t\t\t\tcolorScheme = 'light';\n\t\t\t}\n\t\t}\n\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 || [], function(styleSheet) {\n\t\t\ttry {\n\t\t\t\t// cssRules is a live list. Converting to an Array first.\n\t\t\t\tvar rules = [];\n\t\t\t\t[].forEach.call(styleSheet.cssRules || [], function(cssRule) {\n\t\t\t\t\trules.push(cssRule);\n\t\t\t\t});\n\n\t\t\t\trules.forEach(function(cssRule) {\n\t\t\t\t\tvar colorSchemeMatch = /prefers-color-scheme:/i.test(Object(cssRule.media).mediaText);\n\n\t\t\t\t\tif (colorSchemeMatch) {\n\t\t\t\t\t\tvar index = [].indexOf.call(cssRule.parentStyleSheet.cssRules, cssRule);\n\t\t\t\t\t\tcssRule.parentStyleSheet.deleteRule(index);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// New style which supports complex media queries.\n\t\t\t\t\t\tvar colorDepthMatch = (Object(cssRule.media).mediaText || '').match(/\\( *(?:color|max-color): *(48842621|70318723) *\\)/i);\n\t\t\t\t\t\tif (colorDepthMatch && colorDepthMatch.length > 1) {\n\t\t\t\t\t\t\tif (colorScheme === 'dark' && (colorDepthMatch[1] === '48842621')) {\n\t\t\t\t\t\t\t\t// preferred is dark and rule is dark.\n\t\t\t\t\t\t\t\tcssRule.media.mediaText = cssRule.media.mediaText.replace(/\\( *color: *(?:48842621) *\\)/i, '(max-color: ' + colorDepthMatch[1] + ')');\n\t\t\t\t\t\t\t} else if (colorScheme === 'light' && (colorDepthMatch[1] === '70318723')) {\n\t\t\t\t\t\t\t\t// preferred is light and rule is light.\n\t\t\t\t\t\t\t\tcssRule.media.mediaText = cssRule.media.mediaText.replace(/\\( *color: *(?:70318723) *\\)/i, '(max-color: ' + colorDepthMatch[1] + ')');\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcssRule.media.mediaText = cssRule.media.mediaText.replace(/\\( *max-color: *(?:48842621|70318723) *\\)/i, '(color: ' + colorDepthMatch[1] + ')');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} catch (e) {\n\t\t\t\tif (options.debug) {\n\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.error(e);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t};\n\tvar result = Object.defineProperty(\n\t\t{ hasNativeSupport, removeListener },\n\t\t'scheme',\n\t\t{\n\t\t\tget: function get() {\n\t\t\t\treturn currentColorScheme;\n\t\t\t},\n\t\t\tset: set\n\t\t}\n\t);\n\n\t// initialize the color scheme using the provided value, the system value, or light\n\tvar currentColorScheme = initialColorScheme || (mediaQueryList && mediaQueryList.matches ? 'dark' : 'light');\n\n\tset(currentColorScheme);\n\n\t// listen for system changes\n\tif (mediaQueryList) {\n\t\tif ('addEventListener' in mediaQueryList) {\n\t\t\tmediaQueryList.addEventListener('change', mediaQueryListener);\n\t\t} else {\n\t\t\tmediaQueryList.addListener(mediaQueryListener);\n\t\t}\n\t}\n\n\treturn result;\n};\n\nexport default prefersColorSchemeInit;\n"],"names":["prefersColorSchemeInit","initialColorScheme","options","debug","mediaQueryString","mediaQueryList","window","matchMedia","hasNativeSupport","media","mediaQueryListener","set","matches","colorScheme","currentColorScheme","result","onChange","forEach","call","document","styleSheets","styleSheet","rules","cssRules","cssRule","push","test","Object","mediaText","index","indexOf","parentStyleSheet","deleteRule","colorDepthMatch","match","length","replace","e","console","error","defineProperty","removeListener","get","addEventListener","addListener"],"mappings":"AACA,SAASA,uBAAuBC,EAAoBC,GAG7CA,IACJA,EAAU,CAAA,GAGXA,EAAU,CACTC,QAAUD,EAAQC,QAAU,GAI9B,IAAIC,EAAmB,+BACnBC,EAAkB,eAAgBC,QAAWA,OAAOC,WAAWH,GAC/DI,EAAmBH,GAAkBA,EAAeI,QAAUL,EAC9DM,EAAqB,SAASA,qBACjCC,EAAKN,GAAkBA,EAAeO,QAAW,OAAS,QAC3D,EAMID,EAAM,SAASA,IAAIE,GACF,SAAhBA,GAA0C,UAAhBA,IAE5BA,EADGL,GACWH,EAAeO,QAAU,OAEzB,SAIZC,IAAgBC,IACnBA,EAAqBD,EAEU,mBAApBE,EAAOC,UACjBD,EAAOC,YAIT,GAAGC,QAAQC,KAAKC,SAASC,aAAe,GAAI,SAASC,GACpD,IAEC,IAAIC,EAAQ,GACZ,GAAGL,QAAQC,KAAKG,EAAWE,UAAY,GAAI,SAASC,GACnDF,EAAMG,KAAKD,EACZ,GAEAF,EAAML,QAAQ,SAASO,GAGtB,GAFuB,yBAAyBE,KAAKC,OAAOH,EAAQf,OAAOmB,WAErD,CACrB,IAAIC,EAAQ,GAAGC,QAAQZ,KAAKM,EAAQO,iBAAiBR,SAAUC,GAC/DA,EAAQO,iBAAiBC,WAAWH,EACrC,KAAO,CAEN,IAAII,GAAmBN,OAAOH,EAAQf,OAAOmB,WAAa,IAAIM,MAAM,sDAChED,GAAmBA,EAAgBE,OAAS,IAC3B,SAAhBtB,GAAkD,aAAvBoB,EAAgB,GAE9CT,EAAQf,MAAMmB,UAAYJ,EAAQf,MAAMmB,UAAUQ,QAAQ,gCAAiC,eAAiBH,EAAgB,GAAK,KACvG,UAAhBpB,GAAmD,aAAvBoB,EAAgB,GAEtDT,EAAQf,MAAMmB,UAAYJ,EAAQf,MAAMmB,UAAUQ,QAAQ,gCAAiC,eAAiBH,EAAgB,GAAK,KAEjIT,EAAQf,MAAMmB,UAAYJ,EAAQf,MAAMmB,UAAUQ,QAAQ,6CAA8C,WAAaH,EAAgB,GAAK,KAG7I,CACD,EACD,CAAE,MAAOI,GACJnC,EAAQC,OAEXmC,QAAQC,MAAMF,EAEhB,CACD,EACD,EACItB,EAASY,OAAOa,eACnB,CAAEhC,mBAAkBiC,eA7DA,SAASA,iBACzBpC,GACHA,EAAeoC,eAAe/B,EAEhC,GA0DC,SACA,CACCgC,IAAK,SAASA,MACb,OAAO5B,CACR,EACAH,IAAKA,IAKHG,EAAqBb,IAAuBI,GAAkBA,EAAeO,QAAU,OAAS,SAapG,OAXAD,EAAIG,GAGAT,IACC,qBAAsBA,EACzBA,EAAesC,iBAAiB,SAAUjC,GAE1CL,EAAeuC,YAAYlC,IAItBK,CACR"}
|