css-prefers-color-scheme 6.0.2 → 7.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/dist/browser.cjs CHANGED
@@ -1,93 +1,2 @@
1
- /* global document,window,matchMedia */
2
- var colorIndexRegExp = /((?:not )?all and )?(\(color-index: *(22|48|70)\))/i;
3
- var prefersColorSchemeRegExp = /prefers-color-scheme:/i;
4
-
5
- var prefersColorSchemeInit = function prefersColorSchemeInit(initialColorScheme) {
6
- var mediaQueryString = '(prefers-color-scheme: dark)';
7
- var mediaQueryList = window.matchMedia && matchMedia(mediaQueryString);
8
- var hasNativeSupport = mediaQueryList && mediaQueryList.media === mediaQueryString;
9
-
10
- var mediaQueryListener = function mediaQueryListener() {
11
- set(mediaQueryList.matches ? 'dark' : 'light');
12
- };
13
-
14
- var removeListener = function removeListener() {
15
- if (mediaQueryList) {
16
- mediaQueryList.removeListener(mediaQueryListener);
17
- }
18
- };
19
-
20
- var set = function set(colorScheme) {
21
- if (colorScheme !== currentColorScheme) {
22
- currentColorScheme = colorScheme;
23
-
24
- if (typeof result.onChange === 'function') {
25
- result.onChange();
26
- }
27
- }
28
-
29
- [].forEach.call(document.styleSheets || [], function (styleSheet) {
30
- // cssRules is a live list. Converting to an Array first.
31
- var rules = [];
32
- [].forEach.call(styleSheet.cssRules || [], function (cssRule) {
33
- rules.push(cssRule);
34
- });
35
- rules.forEach(function (cssRule) {
36
- var colorSchemeMatch = prefersColorSchemeRegExp.test(Object(cssRule.media).mediaText);
37
-
38
- if (colorSchemeMatch) {
39
- var index = [].indexOf.call(cssRule.parentStyleSheet.cssRules, cssRule);
40
- cssRule.parentStyleSheet.deleteRule(index);
41
- } else {
42
- var colorIndexMatch = (Object(cssRule.media).mediaText || '').match(colorIndexRegExp);
43
-
44
- if (colorIndexMatch) {
45
- // Old style which has poor browser support and can't handle complex media queries.
46
- cssRule.media.mediaText = ((/^dark$/i.test(colorScheme) ? colorIndexMatch[3] === '48' : /^light$/i.test(colorScheme) ? colorIndexMatch[3] === '70' : colorIndexMatch[3] === '22') ? 'not all and ' : '') + cssRule.media.mediaText.replace(colorIndexRegExp, '$2');
47
- } else {
48
- // New style which supports complex media queries.
49
- var colorDepthMatch = (Object(cssRule.media).mediaText || '').match(/\( *(?:color|max-color): *(48842621|70318723|22511989) *\)/i);
50
-
51
- if (colorDepthMatch && colorDepthMatch.length > 1) {
52
- if (/^dark$/i.test(colorScheme) && (colorDepthMatch[1] === '48842621' || colorDepthMatch[1] === '22511989')) {
53
- // No preference or preferred is dark and rule is dark.
54
- cssRule.media.mediaText = cssRule.media.mediaText.replace(/\( *color: *(?:48842621|70318723) *\)/i, "(max-color: " + colorDepthMatch[1] + ")");
55
- } else if (/^light$/i.test(colorScheme) && (colorDepthMatch[1] === '70318723' || colorDepthMatch[1] === '22511989')) {
56
- // No preference or preferred is light and rule is light.
57
- cssRule.media.mediaText = cssRule.media.mediaText.replace(/\( *color: *(?:48842621|22511989) *\)/i, "(max-color: " + colorDepthMatch[1] + ")");
58
- } else {
59
- cssRule.media.mediaText = cssRule.media.mediaText.replace(/\( *max-color: *(?:48842621|70318723|22511989) *\)/i, "(color: " + colorDepthMatch[1] + ")");
60
- }
61
- }
62
- }
63
- }
64
- });
65
- });
66
- };
67
-
68
- var result = Object.defineProperty({
69
- hasNativeSupport: hasNativeSupport,
70
- removeListener: removeListener
71
- }, 'scheme', {
72
- get: function get() {
73
- return currentColorScheme;
74
- },
75
- set: set
76
- }); // initialize the color scheme using the provided value, the system value, or light
77
-
78
- var currentColorScheme = initialColorScheme || (mediaQueryList && mediaQueryList.matches ? 'dark' : 'light');
79
- set(currentColorScheme); // listen for system changes
80
-
81
- if (mediaQueryList) {
82
- if ('addEventListener' in mediaQueryList) {
83
- mediaQueryList.addEventListener('change', mediaQueryListener);
84
- } else {
85
- mediaQueryList.addListener(mediaQueryListener);
86
- }
87
- }
88
-
89
- return result;
90
- };
91
-
92
- module.exports = prefersColorSchemeInit;
1
+ var e=/prefers-color-scheme:/i;module.exports=function(t,a){a||(a={}),a={debug:!!a.debug||!1};var r="(prefers-color-scheme: dark)",i="matchMedia"in window&&window.matchMedia(r),c=i&&i.media===r,o=function(){n(i&&i.matches?"dark":"light")},n=function(t){"dark"!==t&&"light"!==t&&(t=c&&i.matches?"dark":"light"),t!==l&&(l=t,"function"==typeof d.onChange&&d.onChange()),[].forEach.call(document.styleSheets||[],(function(r){try{var i=[];[].forEach.call(r.cssRules||[],(function(e){i.push(e)})),i.forEach((function(a){if(e.test(Object(a.media).mediaText)){var r=[].indexOf.call(a.parentStyleSheet.cssRules,a);a.parentStyleSheet.deleteRule(r)}else{var i=(Object(a.media).mediaText||"").match(/\( *(?:color|max-color): *(48842621|70318723) *\)/i);i&&i.length>1&&("dark"===t&&"48842621"===i[1]?a.media.mediaText=a.media.mediaText.replace(/\( *color: *(?:48842621) *\)/i,"(max-color: "+i[1]+")"):"light"===t&&"70318723"===i[1]?a.media.mediaText=a.media.mediaText.replace(/\( *color: *(?:70318723) *\)/i,"(max-color: "+i[1]+")"):a.media.mediaText=a.media.mediaText.replace(/\( *max-color: *(?:48842621|70318723) *\)/i,"(color: "+i[1]+")"))}}))}catch(e){a.debug&&console.error(e)}}))},d=Object.defineProperty({hasNativeSupport:c,removeListener:function(){i&&i.removeListener(o)}},"scheme",{get:function(){return l},set:n}),l=t||(i&&i.matches?"dark":"light");return n(l),i&&("addEventListener"in i?i.addEventListener("change",o):i.addListener(o)),d};
93
2
  //# sourceMappingURL=browser.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"browser.cjs","sources":["../src/browser.js"],"sourcesContent":["/* global document,window,matchMedia */\nconst 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\n\t\t\t// cssRules is a live list. Converting to an Array first.\n\t\t\tconst rules = [];\n\t\t\t[].forEach.call(styleSheet.cssRules || [], cssRule => {\n\t\t\t\trules.push(cssRule);\n\t\t\t});\n\n\t\t\trules.forEach(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\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\t// Old style which has poor browser support and can't handle complex media queries.\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\t: /^light$/i.test(colorScheme)\n\t\t\t\t\t\t\t\t\t? colorIndexMatch[3] === '70'\n\t\t\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\t: ''\n\t\t\t\t\t\t) + cssRule.media.mediaText.replace(colorIndexRegExp, '$2');\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\tconst colorDepthMatch = (Object(cssRule.media).mediaText || '').match(/\\( *(?:color|max-color): *(48842621|70318723|22511989) *\\)/i);\n\t\t\t\t\t\tif (colorDepthMatch && colorDepthMatch.length > 1) {\n\t\t\t\t\t\t\tif (/^dark$/i.test(colorScheme) && (colorDepthMatch[1] === '48842621' || colorDepthMatch[1] === '22511989')) {\n\t\t\t\t\t\t\t\t// No preference or preferred is dark and rule is dark.\n\t\t\t\t\t\t\t\tcssRule.media.mediaText = cssRule.media.mediaText.replace(/\\( *color: *(?:48842621|70318723) *\\)/i, `(max-color: ${colorDepthMatch[1]})`);\n\t\t\t\t\t\t\t} else if (/^light$/i.test(colorScheme) && (colorDepthMatch[1] === '70318723' || colorDepthMatch[1] === '22511989')) {\n\t\t\t\t\t\t\t\t// No preference or preferred is light and rule is light.\n\t\t\t\t\t\t\t\tcssRule.media.mediaText = cssRule.media.mediaText.replace(/\\( *color: *(?:48842621|22511989) *\\)/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|22511989) *\\)/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});\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\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":["colorIndexRegExp","prefersColorSchemeRegExp","prefersColorSchemeInit","initialColorScheme","mediaQueryString","mediaQueryList","window","matchMedia","hasNativeSupport","media","mediaQueryListener","set","matches","removeListener","colorScheme","currentColorScheme","result","onChange","forEach","call","document","styleSheets","styleSheet","rules","cssRules","cssRule","push","colorSchemeMatch","test","Object","mediaText","index","indexOf","parentStyleSheet","deleteRule","colorIndexMatch","match","replace","colorDepthMatch","length","defineProperty","get","addEventListener","addListener"],"mappings":"AAAA;AACA,IAAMA,gBAAgB,GAAG,qDAAzB;AACA,IAAMC,wBAAwB,GAAG,wBAAjC;;IAEMC,sBAAsB,GAAG,SAAzBA,sBAAyB,CAAAC,kBAAkB,EAAI;AACpD,MAAMC,gBAAgB,GAAG,8BAAzB;AACA,MAAMC,cAAc,GAAGC,MAAM,CAACC,UAAP,IAAqBA,UAAU,CAACH,gBAAD,CAAtD;AACA,MAAMI,gBAAgB,GAAGH,cAAc,IAAIA,cAAc,CAACI,KAAf,KAAyBL,gBAApE;;AACA,MAAMM,kBAAkB,GAAG,SAArBA,kBAAqB,GAAM;AAChCC,IAAAA,GAAG,CAACN,cAAc,CAACO,OAAf,GAAyB,MAAzB,GAAkC,OAAnC,CAAH;AACA,GAFD;;AAGA,MAAMC,cAAc,GAAG,SAAjBA,cAAiB,GAAM;AAC5B,QAAIR,cAAJ,EAAoB;AACnBA,MAAAA,cAAc,CAACQ,cAAf,CAA8BH,kBAA9B;AACA;AACD,GAJD;;AAKA,MAAMC,GAAG,GAAG,SAANA,GAAM,CAAAG,WAAW,EAAI;AAC1B,QAAIA,WAAW,KAAKC,kBAApB,EAAwC;AACvCA,MAAAA,kBAAkB,GAAGD,WAArB;;AAEA,UAAI,OAAOE,MAAM,CAACC,QAAd,KAA2B,UAA/B,EAA2C;AAC1CD,QAAAA,M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IAAAA,gBAAgB,EAAhBA,gBAAF;AAAoBK,IAAAA,cAAc,EAAdA;AAApB,GADc,EAEd,QAFc,EAGd;AAAE4B,IAAAA,GAAG,EAAE;AAAA,aAAM1B,kBAAN;AAAA,KAAP;AAAiCJ,IAAAA,GAAG,EAAHA;AAAjC,GAHc,CAAf,CApEoD;;AA2EpD,MAAII,kBAAkB,GAAGZ,kBAAkB,KAAKE,cAAc,IAAIA,cAAc,CAACO,OAAjC,GAA2C,MAA3C,GAAoD,OAAzD,CAA3C;AAEAD,EAAAA,GAAG,CAACI,kBAAD,CAAH,CA7EoD;;AAgFpD,MAAIV,cAAJ,EAAoB;AACnB,QAAI,sBAAsBA,cAA1B,EAA0C;AACzCA,MAAAA,cAAc,CAACqC,gBAAf,CAAgC,QAAhC,EAA0ChC,kBAA1C;AACA,KAFD,MAEO;AACNL,MAAAA,cAAc,CAACsC,WAAf,CAA2BjC,kBAA3B;AACA;AACD;;AAED,SAAOM,MAAP;AACA;;;;"}
1
+ {"version":3,"file":"browser.cjs","sources":["../src/browser.js"],"sourcesContent":["/* global document,window */\nconst prefersColorSchemeRegExp = /prefers-color-scheme:/i;\n\nconst 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\tconst mediaQueryString = '(prefers-color-scheme: dark)';\n\tconst mediaQueryList = ('matchMedia' in window) && window.matchMedia(mediaQueryString);\n\tconst hasNativeSupport = mediaQueryList && mediaQueryList.media === mediaQueryString;\n\tconst mediaQueryListener = () => {\n\t\tset((mediaQueryList && 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 !== '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 || [], styleSheet => {\n\t\t\ttry {\n\t\t\t\t// cssRules is a live list. Converting to an Array first.\n\t\t\t\tconst rules = [];\n\t\t\t\t[].forEach.call(styleSheet.cssRules || [], cssRule => {\n\t\t\t\t\trules.push(cssRule);\n\t\t\t\t});\n\n\t\t\t\trules.forEach(cssRule => {\n\t\t\t\t\tconst colorSchemeMatch = prefersColorSchemeRegExp.test(Object(cssRule.media).mediaText);\n\n\t\t\t\t\tif (colorSchemeMatch) {\n\t\t\t\t\t\tconst 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\tconst 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\tconsole.error(e);\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\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":["prefersColorSchemeRegExp","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,IAAMA,EAA2B,wCAEF,SAACC,EAAoBC,GAG7CA,IACJA,EAAU,CAAA,GAGXA,EAAU,CACTC,QAAUD,EAAQC,QAAU,GAI9B,IAAMC,EAAmB,+BACnBC,EAAkB,eAAgBC,QAAWA,OAAOC,WAAWH,GAC/DI,EAAmBH,GAAkBA,EAAe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WAAA,OAAM5B,CAAb,EAAiCH,IAAAA,IAI9BG,EAAqBb,IAAuBI,GAAkBA,EAAeO,QAAU,OAAS,SAapG,OAXAD,EAAIG,GAGAT,IACC,qBAAsBA,EACzBA,EAAesC,iBAAiB,SAAUjC,GAE1CL,EAAeuC,YAAYlC,IAItBK,CACP"}
package/dist/browser.mjs CHANGED
@@ -1,93 +1,2 @@
1
- /* global document,window,matchMedia */
2
- var colorIndexRegExp = /((?:not )?all and )?(\(color-index: *(22|48|70)\))/i;
3
- var prefersColorSchemeRegExp = /prefers-color-scheme:/i;
4
-
5
- var prefersColorSchemeInit = function prefersColorSchemeInit(initialColorScheme) {
6
- var mediaQueryString = '(prefers-color-scheme: dark)';
7
- var mediaQueryList = window.matchMedia && matchMedia(mediaQueryString);
8
- var hasNativeSupport = mediaQueryList && mediaQueryList.media === mediaQueryString;
9
-
10
- var mediaQueryListener = function mediaQueryListener() {
11
- set(mediaQueryList.matches ? 'dark' : 'light');
12
- };
13
-
14
- var removeListener = function removeListener() {
15
- if (mediaQueryList) {
16
- mediaQueryList.removeListener(mediaQueryListener);
17
- }
18
- };
19
-
20
- var set = function set(colorScheme) {
21
- if (colorScheme !== currentColorScheme) {
22
- currentColorScheme = colorScheme;
23
-
24
- if (typeof result.onChange === 'function') {
25
- result.onChange();
26
- }
27
- }
28
-
29
- [].forEach.call(document.styleSheets || [], function (styleSheet) {
30
- // cssRules is a live list. Converting to an Array first.
31
- var rules = [];
32
- [].forEach.call(styleSheet.cssRules || [], function (cssRule) {
33
- rules.push(cssRule);
34
- });
35
- rules.forEach(function (cssRule) {
36
- var colorSchemeMatch = prefersColorSchemeRegExp.test(Object(cssRule.media).mediaText);
37
-
38
- if (colorSchemeMatch) {
39
- var index = [].indexOf.call(cssRule.parentStyleSheet.cssRules, cssRule);
40
- cssRule.parentStyleSheet.deleteRule(index);
41
- } else {
42
- var colorIndexMatch = (Object(cssRule.media).mediaText || '').match(colorIndexRegExp);
43
-
44
- if (colorIndexMatch) {
45
- // Old style which has poor browser support and can't handle complex media queries.
46
- cssRule.media.mediaText = ((/^dark$/i.test(colorScheme) ? colorIndexMatch[3] === '48' : /^light$/i.test(colorScheme) ? colorIndexMatch[3] === '70' : colorIndexMatch[3] === '22') ? 'not all and ' : '') + cssRule.media.mediaText.replace(colorIndexRegExp, '$2');
47
- } else {
48
- // New style which supports complex media queries.
49
- var colorDepthMatch = (Object(cssRule.media).mediaText || '').match(/\( *(?:color|max-color): *(48842621|70318723|22511989) *\)/i);
50
-
51
- if (colorDepthMatch && colorDepthMatch.length > 1) {
52
- if (/^dark$/i.test(colorScheme) && (colorDepthMatch[1] === '48842621' || colorDepthMatch[1] === '22511989')) {
53
- // No preference or preferred is dark and rule is dark.
54
- cssRule.media.mediaText = cssRule.media.mediaText.replace(/\( *color: *(?:48842621|70318723) *\)/i, "(max-color: " + colorDepthMatch[1] + ")");
55
- } else if (/^light$/i.test(colorScheme) && (colorDepthMatch[1] === '70318723' || colorDepthMatch[1] === '22511989')) {
56
- // No preference or preferred is light and rule is light.
57
- cssRule.media.mediaText = cssRule.media.mediaText.replace(/\( *color: *(?:48842621|22511989) *\)/i, "(max-color: " + colorDepthMatch[1] + ")");
58
- } else {
59
- cssRule.media.mediaText = cssRule.media.mediaText.replace(/\( *max-color: *(?:48842621|70318723|22511989) *\)/i, "(color: " + colorDepthMatch[1] + ")");
60
- }
61
- }
62
- }
63
- }
64
- });
65
- });
66
- };
67
-
68
- var result = Object.defineProperty({
69
- hasNativeSupport: hasNativeSupport,
70
- removeListener: removeListener
71
- }, 'scheme', {
72
- get: function get() {
73
- return currentColorScheme;
74
- },
75
- set: set
76
- }); // initialize the color scheme using the provided value, the system value, or light
77
-
78
- var currentColorScheme = initialColorScheme || (mediaQueryList && mediaQueryList.matches ? 'dark' : 'light');
79
- set(currentColorScheme); // listen for system changes
80
-
81
- if (mediaQueryList) {
82
- if ('addEventListener' in mediaQueryList) {
83
- mediaQueryList.addEventListener('change', mediaQueryListener);
84
- } else {
85
- mediaQueryList.addListener(mediaQueryListener);
86
- }
87
- }
88
-
89
- return result;
90
- };
91
-
92
- export { prefersColorSchemeInit as default };
1
+ var e=/prefers-color-scheme:/i,t=function(t,a){a||(a={}),a={debug:!!a.debug||!1};var r="(prefers-color-scheme: dark)",i="matchMedia"in window&&window.matchMedia(r),c=i&&i.media===r,o=function(){n(i&&i.matches?"dark":"light")},n=function(t){"dark"!==t&&"light"!==t&&(t=c&&i.matches?"dark":"light"),t!==l&&(l=t,"function"==typeof d.onChange&&d.onChange()),[].forEach.call(document.styleSheets||[],(function(r){try{var i=[];[].forEach.call(r.cssRules||[],(function(e){i.push(e)})),i.forEach((function(a){if(e.test(Object(a.media).mediaText)){var r=[].indexOf.call(a.parentStyleSheet.cssRules,a);a.parentStyleSheet.deleteRule(r)}else{var i=(Object(a.media).mediaText||"").match(/\( *(?:color|max-color): *(48842621|70318723) *\)/i);i&&i.length>1&&("dark"===t&&"48842621"===i[1]?a.media.mediaText=a.media.mediaText.replace(/\( *color: *(?:48842621) *\)/i,"(max-color: "+i[1]+")"):"light"===t&&"70318723"===i[1]?a.media.mediaText=a.media.mediaText.replace(/\( *color: *(?:70318723) *\)/i,"(max-color: "+i[1]+")"):a.media.mediaText=a.media.mediaText.replace(/\( *max-color: *(?:48842621|70318723) *\)/i,"(color: "+i[1]+")"))}}))}catch(e){a.debug&&console.error(e)}}))},d=Object.defineProperty({hasNativeSupport:c,removeListener:function(){i&&i.removeListener(o)}},"scheme",{get:function(){return l},set:n}),l=t||(i&&i.matches?"dark":"light");return n(l),i&&("addEventListener"in i?i.addEventListener("change",o):i.addListener(o)),d};export{t as default};
93
2
  //# sourceMappingURL=browser.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"browser.mjs","sources":["../src/browser.js"],"sourcesContent":["/* global document,window,matchMedia */\nconst 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\n\t\t\t// cssRules is a live list. Converting to an Array first.\n\t\t\tconst rules = [];\n\t\t\t[].forEach.call(styleSheet.cssRules || [], cssRule => {\n\t\t\t\trules.push(cssRule);\n\t\t\t});\n\n\t\t\trules.forEach(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\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\t// Old style which has poor browser support and can't handle complex media queries.\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\t: /^light$/i.test(colorScheme)\n\t\t\t\t\t\t\t\t\t? colorIndexMatch[3] === '70'\n\t\t\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\t: ''\n\t\t\t\t\t\t) + cssRule.media.mediaText.replace(colorIndexRegExp, '$2');\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\tconst colorDepthMatch = (Object(cssRule.media).mediaText || '').match(/\\( *(?:color|max-color): *(48842621|70318723|22511989) *\\)/i);\n\t\t\t\t\t\tif (colorDepthMatch && colorDepthMatch.length > 1) {\n\t\t\t\t\t\t\tif (/^dark$/i.test(colorScheme) && (colorDepthMatch[1] === '48842621' || colorDepthMatch[1] === '22511989')) {\n\t\t\t\t\t\t\t\t// No preference or preferred is dark and rule is dark.\n\t\t\t\t\t\t\t\tcssRule.media.mediaText = cssRule.media.mediaText.replace(/\\( *color: *(?:48842621|70318723) *\\)/i, `(max-color: ${colorDepthMatch[1]})`);\n\t\t\t\t\t\t\t} else if (/^light$/i.test(colorScheme) && (colorDepthMatch[1] === '70318723' || colorDepthMatch[1] === '22511989')) {\n\t\t\t\t\t\t\t\t// No preference or preferred is light and rule is light.\n\t\t\t\t\t\t\t\tcssRule.media.mediaText = cssRule.media.mediaText.replace(/\\( *color: *(?:48842621|22511989) *\\)/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|22511989) *\\)/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});\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\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":["colorIndexRegExp","prefersColorSchemeRegExp","prefersColorSchemeInit","initialColorScheme","mediaQueryString","mediaQueryList","window","matchMedia","hasNativeSupport","media","mediaQueryListener","set","matches","removeListener","colorScheme","currentColorScheme","result","onChange","forEach","call","document","styleSheets","styleSheet","rules","cssRules","cssRule","push","colorSchemeMatch","test","Object","mediaText","index","indexOf","parentStyleSheet","deleteRule","colorIndexMatch","match","replace","colorDepthMatch","length","defineProperty","get","addEventListener","addListener"],"mappings":"AAAA;AACA,IAAMA,gBAAgB,GAAG,qDAAzB;AACA,IAAMC,wBAAwB,GAAG,wBAAjC;;IAEMC,sBAAsB,GAAG,SAAzBA,sBAAyB,CAAAC,kBAAkB,EAAI;AACpD,MAAMC,gBAAgB,GAAG,8BAAzB;AACA,MAAMC,cAAc,GAAGC,MAAM,CAACC,UAAP,IAAqBA,UAAU,CAACH,gBAAD,CAAtD;AACA,MAAMI,gBAAgB,GAAGH,cAAc,IAAIA,cAAc,CAACI,KAAf,KAAyBL,gBAApE;;AACA,MAAMM,kBAAkB,GAAG,SAArBA,kBAAqB,GAAM;AAChCC,IAAAA,GAAG,CAACN,cAAc,CAACO,OAAf,GAAyB,MAAzB,GAAkC,OAAnC,CAAH;AACA,GAFD;;AAGA,MAAMC,cAAc,GAAG,SAAjBA,cAAiB,GAAM;AAC5B,QAAIR,cAAJ,EAAoB;AACnBA,MAAAA,cAAc,CAACQ,cAAf,CAA8BH,kBAA9B;AACA;AACD,GAJD;;AAKA,MAAMC,GAAG,GAAG,SAANA,GAAM,CAAAG,WAAW,EAAI;AAC1B,QAAIA,WAAW,KAAKC,kBAApB,EAAwC;AACvCA,MAAAA,kBAAkB,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AAqCA,KA7CD;AA8CA,GAvDD;;AAwDA,MAAMtB,MAAM,GAAGa,MAAM,CAACW,cAAP,CACd;AAAEhC,IAAAA,gBAAgB,EAAhBA,gBAAF;AAAoBK,IAAAA,cAAc,EAAdA;AAApB,GADc,EAEd,QAFc,EAGd;AAAE4B,IAAAA,GAAG,EAAE;AAAA,aAAM1B,kBAAN;AAAA,KAAP;AAAiCJ,IAAAA,GAAG,EAAHA;AAAjC,GAHc,CAAf,CApEoD;;AA2EpD,MAAII,kBAAkB,GAAGZ,kBAAkB,KAAKE,cAAc,IAAIA,cAAc,CAACO,OAAjC,GAA2C,MAA3C,GAAoD,OAAzD,CAA3C;AAEAD,EAAAA,GAAG,CAACI,kBAAD,CAAH,CA7EoD;;AAgFpD,MAAIV,cAAJ,EAAoB;AACnB,QAAI,sBAAsBA,cAA1B,EAA0C;AACzCA,MAAAA,cAAc,CAACqC,gBAAf,CAAgC,QAAhC,EAA0ChC,kBAA1C;AACA,KAFD,MAEO;AACNL,MAAAA,cAAc,CAACsC,WAAf,CAA2BjC,kBAA3B;AACA;AACD;;AAED,SAAOM,MAAP;AACA;;;;"}
1
+ {"version":3,"file":"browser.mjs","sources":["../src/browser.js"],"sourcesContent":["/* global document,window */\nconst prefersColorSchemeRegExp = /prefers-color-scheme:/i;\n\nconst 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\tconst mediaQueryString = '(prefers-color-scheme: dark)';\n\tconst mediaQueryList = ('matchMedia' in window) && window.matchMedia(mediaQueryString);\n\tconst hasNativeSupport = mediaQueryList && mediaQueryList.media === mediaQueryString;\n\tconst mediaQueryListener = () => {\n\t\tset((mediaQueryList && 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 !== '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 || [], styleSheet => {\n\t\t\ttry {\n\t\t\t\t// cssRules is a live list. Converting to an Array first.\n\t\t\t\tconst rules = [];\n\t\t\t\t[].forEach.call(styleSheet.cssRules || [], cssRule => {\n\t\t\t\t\trules.push(cssRule);\n\t\t\t\t});\n\n\t\t\t\trules.forEach(cssRule => {\n\t\t\t\t\tconst colorSchemeMatch = prefersColorSchemeRegExp.test(Object(cssRule.media).mediaText);\n\n\t\t\t\t\tif (colorSchemeMatch) {\n\t\t\t\t\t\tconst 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\tconst 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\tconsole.error(e);\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\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":["prefersColorSchemeRegExp","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,IAAMA,EAA2B,yBAE3BC,EAAyB,SAACC,EAAoBC,GAG7CA,IACJA,EAAU,CAAA,GAGXA,EAAU,CACTC,QAA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B,EAASY,OAAOa,eACrB,CAAEhC,iBAAAA,EAAkBiC,eA5DE,WAClBpC,GACHA,EAAeoC,eAAe/B,KA2D/B,SACA,CAAEgC,IAAK,WAAA,OAAM5B,CAAb,EAAiCH,IAAAA,IAI9BG,EAAqBb,IAAuBI,GAAkBA,EAAeO,QAAU,OAAS,SAapG,OAXAD,EAAIG,GAGAT,IACC,qBAAsBA,EACzBA,EAAesC,iBAAiB,SAAUjC,GAE1CL,EAAeuC,YAAYlC,IAItBK,CACP"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const e=/^media$/i,r=/\(\s*prefers-color-scheme\s*:\s*(dark|light|no-preference)\s*\)/i,o={dark:48,light:70,"no-preference":22},s=(e,r)=>`(color-index: ${o[r.toLowerCase()]})`,c={dark:48842621,light:70318723,"no-preference":22511989},n=(e,r)=>`(color: ${c[r.toLowerCase()]})`,t=o=>{const c=!("preserve"in Object(o))||o.preserve,t={};return!("mediaQuery"in Object(o))||"color-index"!==o.mediaQuery&&"color"!==o.mediaQuery?(t["color-index"]=!0,t.color=!0):t[o.mediaQuery]=!0,{postcssPlugin:"postcss-prefers-color-scheme",AtRule:o=>{if(!e.test(o.name))return;const{params:l}=o,a=l.replace(r,s),i=l.replace(r,n);l!==a&&t["color-index"]&&o.cloneBefore({params:a}),l!==i&&t.color&&o.cloneBefore({params:i}),c||o.remove()}}};t.postcss=!0,module.exports=t;
1
+ "use strict";const e=/\(\s*prefers-color-scheme\s*:\s*(dark|light)\s*\)/gi,s={dark:"48842621",light:"70318723"},r=(e,r)=>`(color: ${s[r.toLowerCase()]})`,o=s=>{const o=Object.assign({preserve:!0},s);return{postcssPlugin:"postcss-prefers-color-scheme",AtRule:s=>{if("media"!==s.name.toLowerCase())return;const{params:t}=s,c=t.replace(e,r);t!==c&&(s.cloneBefore({params:c}),o.preserve||s.remove())}}};o.postcss=!0,module.exports=o;
@@ -0,0 +1,6 @@
1
+ import type { PluginCreator } from 'postcss';
2
+ declare type pluginOptions = {
3
+ preserve?: boolean;
4
+ };
5
+ declare const creator: PluginCreator<pluginOptions>;
6
+ export default creator;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- const e=/^media$/i,r=/\(\s*prefers-color-scheme\s*:\s*(dark|light|no-preference)\s*\)/i,o={dark:48,light:70,"no-preference":22},s=(e,r)=>`(color-index: ${o[r.toLowerCase()]})`,c={dark:48842621,light:70318723,"no-preference":22511989},a=(e,r)=>`(color: ${c[r.toLowerCase()]})`,n=o=>{const c=!("preserve"in Object(o))||o.preserve,n={};return!("mediaQuery"in Object(o))||"color-index"!==o.mediaQuery&&"color"!==o.mediaQuery?(n["color-index"]=!0,n.color=!0):n[o.mediaQuery]=!0,{postcssPlugin:"postcss-prefers-color-scheme",AtRule:o=>{if(!e.test(o.name))return;const{params:l}=o,t=l.replace(r,s),i=l.replace(r,a);l!==t&&n["color-index"]&&o.cloneBefore({params:t}),l!==i&&n.color&&o.cloneBefore({params:i}),c||o.remove()}}};n.postcss=!0;export{n as default};
1
+ const e=/\(\s*prefers-color-scheme\s*:\s*(dark|light)\s*\)/gi,s={dark:"48842621",light:"70318723"},r=(e,r)=>`(color: ${s[r.toLowerCase()]})`,o=s=>{const o=Object.assign({preserve:!0},s);return{postcssPlugin:"postcss-prefers-color-scheme",AtRule:s=>{if("media"!==s.name.toLowerCase())return;const{params:t}=s,a=t.replace(e,r);t!==a&&(s.cloneBefore({params:a}),o.preserve||s.remove())}}};o.postcss=!0;export{o as default};
package/package.json CHANGED
@@ -1,81 +1,103 @@
1
1
  {
2
- "name": "css-prefers-color-scheme",
3
- "version": "6.0.2",
4
- "description": "Use light and dark color schemes in all browsers",
5
- "author": "Jonathan Neal <jonathantneal@hotmail.com>",
6
- "license": "CC0-1.0",
7
- "homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/css-prefers-color-scheme#readme",
8
- "bugs": "https://github.com/csstools/postcss-plugins/issues",
9
- "main": "dist/index.cjs",
10
- "module": "dist/index.mjs",
11
- "exports": {
12
- ".": {
13
- "import": "./dist/index.mjs",
14
- "require": "./dist/index.cjs",
15
- "default": "./dist/index.mjs"
16
- },
17
- "./browser": {
18
- "import": "./dist/browser.mjs",
19
- "require": "./dist/browser.cjs",
20
- "default": "./dist/browser.mjs"
21
- },
22
- "./browser-global": {
23
- "default": "./dist/browser-global.js"
24
- }
25
- },
26
- "files": [
27
- "CHANGELOG.md",
28
- "LICENSE.md",
29
- "README.md",
30
- "dist",
31
- "browser.js",
32
- "browser.min.js"
33
- ],
34
- "bin": {
35
- "css-prefers-color-scheme": "dist/cli.cjs"
36
- },
37
- "scripts": {
38
- "build": "rollup -c ../../rollup/default.js && npm run copy-browser-scripts-to-old-location",
39
- "clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true });\"",
40
- "copy-browser-scripts-to-old-location": "node -e \"fs.copyFileSync('./dist/browser-global.js', './browser.js'); fs.copyFileSync('./dist/browser-global.js', './browser.min.js')\"",
41
- "lint": "eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern",
42
- "prepublishOnly": "npm run clean && npm run build && npm run test",
43
- "stryker": "stryker run --logLevel error",
44
- "test": "postcss-tape --ci && npm run test:exports",
45
- "test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
46
- },
47
- "engines": {
48
- "node": "^12 || ^14 || >=16"
49
- },
50
- "devDependencies": {
51
- "postcss": "^8.3.6",
52
- "postcss-tape": "^6.0.1"
53
- },
54
- "peerDependencies": {
55
- "postcss": "^8.3"
56
- },
57
- "keywords": [
58
- "postcss",
59
- "css",
60
- "postcss-plugin",
61
- "media",
62
- "query",
63
- "prefers",
64
- "color",
65
- "scheme",
66
- "dark",
67
- "light",
68
- "no-preference",
69
- "mode",
70
- "queries",
71
- "interface"
72
- ],
73
- "repository": {
74
- "type": "git",
75
- "url": "https://github.com/csstools/postcss-plugins.git",
76
- "directory": "plugins/css-prefers-color-scheme"
77
- },
78
- "volta": {
79
- "extends": "../../package.json"
80
- }
2
+ "name": "css-prefers-color-scheme",
3
+ "description": "Use light and dark color schemes in all browsers",
4
+ "version": "7.0.1",
5
+ "contributors": [
6
+ {
7
+ "name": "Antonio Laguna",
8
+ "email": "antonio@laguna.es",
9
+ "url": "https://antonio.laguna.es"
10
+ },
11
+ {
12
+ "name": "Romain Menke",
13
+ "email": "romainmenke@gmail.com"
14
+ },
15
+ {
16
+ "name": "Jonathan Neal",
17
+ "email": "jonathantneal@hotmail.com"
18
+ }
19
+ ],
20
+ "license": "CC0-1.0",
21
+ "funding": {
22
+ "type": "opencollective",
23
+ "url": "https://opencollective.com/csstools"
24
+ },
25
+ "engines": {
26
+ "node": "^12 || ^14 || >=16"
27
+ },
28
+ "main": "dist/index.cjs",
29
+ "module": "dist/index.mjs",
30
+ "types": "dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "import": "./dist/index.mjs",
34
+ "require": "./dist/index.cjs",
35
+ "default": "./dist/index.mjs"
36
+ },
37
+ "./browser": {
38
+ "import": "./dist/browser.mjs",
39
+ "require": "./dist/browser.cjs",
40
+ "default": "./dist/browser.mjs"
41
+ },
42
+ "./browser-global": {
43
+ "default": "./dist/browser-global.js"
44
+ }
45
+ },
46
+ "files": [
47
+ "CHANGELOG.md",
48
+ "LICENSE.md",
49
+ "README.md",
50
+ "dist"
51
+ ],
52
+ "peerDependencies": {
53
+ "postcss": "^8.2"
54
+ },
55
+ "devDependencies": {
56
+ "puppeteer": "^16.0.0"
57
+ },
58
+ "scripts": {
59
+ "build": "rollup -c ../../rollup/default.js",
60
+ "clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true });\"",
61
+ "docs": "node ../../.github/bin/generate-docs/install.mjs && node ../../.github/bin/generate-docs/readme.mjs",
62
+ "lint": "npm run lint:eslint && npm run lint:package-json",
63
+ "lint:eslint": "eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern",
64
+ "lint:package-json": "node ../../.github/bin/format-package-json.mjs",
65
+ "prepublishOnly": "npm run clean && npm run build && npm run test",
66
+ "test": "node .tape.mjs && npm run test:exports",
67
+ "test:browser": "node ./test/_browser.mjs",
68
+ "test:exports": "node ./test/_import.mjs && node ./test/_require.cjs",
69
+ "test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs"
70
+ },
71
+ "homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/css-prefers-color-scheme#readme",
72
+ "repository": {
73
+ "type": "git",
74
+ "url": "https://github.com/csstools/postcss-plugins.git",
75
+ "directory": "plugins/css-prefers-color-scheme"
76
+ },
77
+ "bugs": "https://github.com/csstools/postcss-plugins/issues",
78
+ "keywords": [
79
+ "color",
80
+ "css",
81
+ "dark",
82
+ "interface",
83
+ "light",
84
+ "media",
85
+ "mode",
86
+ "no-preference",
87
+ "postcss",
88
+ "postcss-plugin",
89
+ "prefers",
90
+ "queries",
91
+ "query",
92
+ "scheme"
93
+ ],
94
+ "csstools": {
95
+ "cssdbId": "prefers-color-scheme-query",
96
+ "exportName": "prefersColorScheme",
97
+ "humanReadableName": "Prefers Color Scheme",
98
+ "specUrl": "https://www.w3.org/TR/mediaqueries-5/#prefers-color-scheme"
99
+ },
100
+ "volta": {
101
+ "extends": "../../package.json"
102
+ }
81
103
  }
package/browser.js DELETED
@@ -1,100 +0,0 @@
1
- (function () {
2
-
3
- /* global document,window,matchMedia */
4
- var colorIndexRegExp = /((?:not )?all and )?(\(color-index: *(22|48|70)\))/i;
5
- var prefersColorSchemeRegExp = /prefers-color-scheme:/i;
6
-
7
- var prefersColorSchemeInit = function prefersColorSchemeInit(initialColorScheme) {
8
- var mediaQueryString = '(prefers-color-scheme: dark)';
9
- var mediaQueryList = window.matchMedia && matchMedia(mediaQueryString);
10
- var hasNativeSupport = mediaQueryList && mediaQueryList.media === mediaQueryString;
11
-
12
- var mediaQueryListener = function mediaQueryListener() {
13
- set(mediaQueryList.matches ? 'dark' : 'light');
14
- };
15
-
16
- var removeListener = function removeListener() {
17
- if (mediaQueryList) {
18
- mediaQueryList.removeListener(mediaQueryListener);
19
- }
20
- };
21
-
22
- var set = function set(colorScheme) {
23
- if (colorScheme !== currentColorScheme) {
24
- currentColorScheme = colorScheme;
25
-
26
- if (typeof result.onChange === 'function') {
27
- result.onChange();
28
- }
29
- }
30
-
31
- [].forEach.call(document.styleSheets || [], function (styleSheet) {
32
- // cssRules is a live list. Converting to an Array first.
33
- var rules = [];
34
- [].forEach.call(styleSheet.cssRules || [], function (cssRule) {
35
- rules.push(cssRule);
36
- });
37
- rules.forEach(function (cssRule) {
38
- var colorSchemeMatch = prefersColorSchemeRegExp.test(Object(cssRule.media).mediaText);
39
-
40
- if (colorSchemeMatch) {
41
- var index = [].indexOf.call(cssRule.parentStyleSheet.cssRules, cssRule);
42
- cssRule.parentStyleSheet.deleteRule(index);
43
- } else {
44
- var colorIndexMatch = (Object(cssRule.media).mediaText || '').match(colorIndexRegExp);
45
-
46
- if (colorIndexMatch) {
47
- // Old style which has poor browser support and can't handle complex media queries.
48
- cssRule.media.mediaText = ((/^dark$/i.test(colorScheme) ? colorIndexMatch[3] === '48' : /^light$/i.test(colorScheme) ? colorIndexMatch[3] === '70' : colorIndexMatch[3] === '22') ? 'not all and ' : '') + cssRule.media.mediaText.replace(colorIndexRegExp, '$2');
49
- } else {
50
- // New style which supports complex media queries.
51
- var colorDepthMatch = (Object(cssRule.media).mediaText || '').match(/\( *(?:color|max-color): *(48842621|70318723|22511989) *\)/i);
52
-
53
- if (colorDepthMatch && colorDepthMatch.length > 1) {
54
- if (/^dark$/i.test(colorScheme) && (colorDepthMatch[1] === '48842621' || colorDepthMatch[1] === '22511989')) {
55
- // No preference or preferred is dark and rule is dark.
56
- cssRule.media.mediaText = cssRule.media.mediaText.replace(/\( *color: *(?:48842621|70318723) *\)/i, "(max-color: " + colorDepthMatch[1] + ")");
57
- } else if (/^light$/i.test(colorScheme) && (colorDepthMatch[1] === '70318723' || colorDepthMatch[1] === '22511989')) {
58
- // No preference or preferred is light and rule is light.
59
- cssRule.media.mediaText = cssRule.media.mediaText.replace(/\( *color: *(?:48842621|22511989) *\)/i, "(max-color: " + colorDepthMatch[1] + ")");
60
- } else {
61
- cssRule.media.mediaText = cssRule.media.mediaText.replace(/\( *max-color: *(?:48842621|70318723|22511989) *\)/i, "(color: " + colorDepthMatch[1] + ")");
62
- }
63
- }
64
- }
65
- }
66
- });
67
- });
68
- };
69
-
70
- var result = Object.defineProperty({
71
- hasNativeSupport: hasNativeSupport,
72
- removeListener: removeListener
73
- }, 'scheme', {
74
- get: function get() {
75
- return currentColorScheme;
76
- },
77
- set: set
78
- }); // initialize the color scheme using the provided value, the system value, or light
79
-
80
- var currentColorScheme = initialColorScheme || (mediaQueryList && mediaQueryList.matches ? 'dark' : 'light');
81
- set(currentColorScheme); // listen for system changes
82
-
83
- if (mediaQueryList) {
84
- if ('addEventListener' in mediaQueryList) {
85
- mediaQueryList.addEventListener('change', mediaQueryListener);
86
- } else {
87
- mediaQueryList.addListener(mediaQueryListener);
88
- }
89
- }
90
-
91
- return result;
92
- };
93
-
94
- /* global self */
95
- self.prefersColorSchemeInit = prefersColorSchemeInit; // Legacy : there used to be a rollup config that exposed this function under a different name.
96
-
97
- self.initPrefersColorScheme = prefersColorSchemeInit;
98
-
99
- })();
100
- //# sourceMappingURL=browser-global.js.map