@vxrn/color-scheme 1.1.309 → 1.1.310
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/cjs/index.cjs +118 -0
- package/package.json +6 -6
- package/dist/cjs/index.js +0 -119
- /package/dist/cjs/{index.js.map → index.cjs.map} +0 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
MetaTheme: () => MetaTheme,
|
|
24
|
+
SchemeProvider: () => SchemeProvider,
|
|
25
|
+
getColorScheme: () => import_universal_color_scheme2.getColorScheme,
|
|
26
|
+
onColorSchemeChange: () => import_universal_color_scheme2.onColorSchemeChange,
|
|
27
|
+
setSchemeSetting: () => setSchemeSetting,
|
|
28
|
+
useColorScheme: () => useColorScheme,
|
|
29
|
+
useSchemeSetting: () => useSchemeSetting
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(src_exports);
|
|
32
|
+
var import_universal_color_scheme = require("@vxrn/universal-color-scheme"),
|
|
33
|
+
import_use_isomorphic_layout_effect = require("@vxrn/use-isomorphic-layout-effect"),
|
|
34
|
+
import_react = require("react"),
|
|
35
|
+
import_universal_color_scheme2 = require("@vxrn/universal-color-scheme"),
|
|
36
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
37
|
+
const storageKey = "vxrn-scheme",
|
|
38
|
+
getSetting = () => typeof localStorage < "u" && localStorage.getItem(storageKey) || "system",
|
|
39
|
+
SchemeContext = (0, import_react.createContext)({
|
|
40
|
+
setting: "system",
|
|
41
|
+
scheme: "light"
|
|
42
|
+
}),
|
|
43
|
+
useColorScheme = () => {
|
|
44
|
+
const [state] = (0, import_universal_color_scheme.useColorScheme)();
|
|
45
|
+
return [state, setSchemeSetting];
|
|
46
|
+
};
|
|
47
|
+
function useSchemeSetting() {
|
|
48
|
+
return [(0, import_react.useContext)(SchemeContext), setSchemeSetting];
|
|
49
|
+
}
|
|
50
|
+
function setSchemeSetting(next) {
|
|
51
|
+
typeof localStorage < "u" && localStorage.setItem(storageKey, next), (0, import_universal_color_scheme.setColorScheme)(next);
|
|
52
|
+
}
|
|
53
|
+
function SchemeProvider({
|
|
54
|
+
children,
|
|
55
|
+
// defaults to tamagui-compatible
|
|
56
|
+
getClassName = name => `t_${name}`
|
|
57
|
+
}) {
|
|
58
|
+
const [colorSchemeSetting] = (0, import_universal_color_scheme.useColorSchemeSetting)(),
|
|
59
|
+
[colorScheme] = useColorScheme();
|
|
60
|
+
return (0, import_use_isomorphic_layout_effect.useIsomorphicLayoutEffect)(() => {
|
|
61
|
+
(0, import_universal_color_scheme.setColorScheme)(getSetting());
|
|
62
|
+
const toAdd = getClassName(colorScheme),
|
|
63
|
+
{
|
|
64
|
+
classList
|
|
65
|
+
} = document.documentElement;
|
|
66
|
+
if (!classList.contains(toAdd)) {
|
|
67
|
+
const toRemove = colorScheme === "light" ? "dark" : "light";
|
|
68
|
+
classList.remove(getClassName(toRemove)), classList.add(toAdd);
|
|
69
|
+
}
|
|
70
|
+
}, [colorScheme]), /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
71
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)("script", {
|
|
72
|
+
dangerouslySetInnerHTML: {
|
|
73
|
+
__html: `let d = document.documentElement.classList
|
|
74
|
+
d.remove('${getClassName("light")}')
|
|
75
|
+
d.remove('${getClassName("dark")}')
|
|
76
|
+
let e = localStorage.getItem('${storageKey}')
|
|
77
|
+
let t =
|
|
78
|
+
'system' === e || !e
|
|
79
|
+
? window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
80
|
+
: e === 'dark'
|
|
81
|
+
t ? d.add('${getClassName("dark")}') : d.add('${getClassName("light")}')
|
|
82
|
+
`
|
|
83
|
+
}
|
|
84
|
+
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(SchemeContext.Provider, {
|
|
85
|
+
value: (0, import_react.useMemo)(() => ({
|
|
86
|
+
scheme: colorScheme,
|
|
87
|
+
setting: colorSchemeSetting
|
|
88
|
+
}), [colorScheme, colorSchemeSetting]),
|
|
89
|
+
children
|
|
90
|
+
})]
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const MetaTheme = ({
|
|
94
|
+
color,
|
|
95
|
+
darkColor,
|
|
96
|
+
lightColor
|
|
97
|
+
}) => {
|
|
98
|
+
const [colorScheme] = useColorScheme();
|
|
99
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
100
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)("meta", {
|
|
101
|
+
itemProp: "__deopt",
|
|
102
|
+
suppressHydrationWarning: !0,
|
|
103
|
+
id: "vxrn-theme-color",
|
|
104
|
+
name: "theme-color",
|
|
105
|
+
content: color ?? (colorScheme === "dark" ? darkColor : lightColor)
|
|
106
|
+
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)("script", {
|
|
107
|
+
id: "meta-theme-hydrate",
|
|
108
|
+
dangerouslySetInnerHTML: {
|
|
109
|
+
__html: `
|
|
110
|
+
let dc = document.getElementById('vxrn-theme-color')
|
|
111
|
+
let e1 = localStorage.getItem('${storageKey}')
|
|
112
|
+
let isD = 'system' === e1 || !e1 ? window.matchMedia('(prefers-color-scheme: dark)').matches : e1 === 'dark'
|
|
113
|
+
dc.setAttribute('content', isD ? '${darkColor}' : '${lightColor}')
|
|
114
|
+
`
|
|
115
|
+
}
|
|
116
|
+
})]
|
|
117
|
+
});
|
|
118
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vxrn/color-scheme",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.310",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"react-native": "./dist/cjs/index.native.js",
|
|
14
14
|
"types": "./types/index.d.ts",
|
|
15
15
|
"import": "./dist/esm/index.mjs",
|
|
16
|
-
"require": "./dist/cjs/index.
|
|
16
|
+
"require": "./dist/cjs/index.cjs"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"clean:build": "tamagui-build clean:build"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@tamagui/use-did-finish-ssr": "^1.
|
|
34
|
-
"@vxrn/universal-color-scheme": "1.1.
|
|
35
|
-
"@vxrn/use-isomorphic-layout-effect": "1.1.
|
|
33
|
+
"@tamagui/use-did-finish-ssr": "^1.115.0",
|
|
34
|
+
"@vxrn/universal-color-scheme": "1.1.310",
|
|
35
|
+
"@vxrn/use-isomorphic-layout-effect": "1.1.310"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@tamagui/build": "^1.
|
|
38
|
+
"@tamagui/build": "^1.115.0",
|
|
39
39
|
"react": "^18.2.0 || ^19.0.0",
|
|
40
40
|
"react-native": "0.74.5"
|
|
41
41
|
},
|
package/dist/cjs/index.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
-
var src_exports = {};
|
|
16
|
-
__export(src_exports, {
|
|
17
|
-
MetaTheme: () => MetaTheme,
|
|
18
|
-
SchemeProvider: () => SchemeProvider,
|
|
19
|
-
getColorScheme: () => import_universal_color_scheme2.getColorScheme,
|
|
20
|
-
onColorSchemeChange: () => import_universal_color_scheme2.onColorSchemeChange,
|
|
21
|
-
setSchemeSetting: () => setSchemeSetting,
|
|
22
|
-
useColorScheme: () => useColorScheme,
|
|
23
|
-
useSchemeSetting: () => useSchemeSetting
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(src_exports);
|
|
26
|
-
var import_universal_color_scheme = require("@vxrn/universal-color-scheme"), import_use_isomorphic_layout_effect = require("@vxrn/use-isomorphic-layout-effect"), import_react = require("react"), import_universal_color_scheme2 = require("@vxrn/universal-color-scheme"), import_jsx_runtime = require("react/jsx-runtime");
|
|
27
|
-
const storageKey = "vxrn-scheme", getSetting = () => typeof localStorage < "u" && localStorage.getItem(storageKey) || "system", SchemeContext = (0, import_react.createContext)({
|
|
28
|
-
setting: "system",
|
|
29
|
-
scheme: "light"
|
|
30
|
-
}), useColorScheme = () => {
|
|
31
|
-
const [state] = (0, import_universal_color_scheme.useColorScheme)();
|
|
32
|
-
return [state, setSchemeSetting];
|
|
33
|
-
};
|
|
34
|
-
function useSchemeSetting() {
|
|
35
|
-
return [(0, import_react.useContext)(SchemeContext), setSchemeSetting];
|
|
36
|
-
}
|
|
37
|
-
function setSchemeSetting(next) {
|
|
38
|
-
typeof localStorage < "u" && localStorage.setItem(storageKey, next), (0, import_universal_color_scheme.setColorScheme)(next);
|
|
39
|
-
}
|
|
40
|
-
function SchemeProvider({
|
|
41
|
-
children,
|
|
42
|
-
// defaults to tamagui-compatible
|
|
43
|
-
getClassName = (name) => `t_${name}`
|
|
44
|
-
}) {
|
|
45
|
-
const [colorSchemeSetting] = (0, import_universal_color_scheme.useColorSchemeSetting)(), [colorScheme] = useColorScheme();
|
|
46
|
-
return (0, import_use_isomorphic_layout_effect.useIsomorphicLayoutEffect)(() => {
|
|
47
|
-
(0, import_universal_color_scheme.setColorScheme)(getSetting());
|
|
48
|
-
const toAdd = getClassName(colorScheme), { classList } = document.documentElement;
|
|
49
|
-
if (!classList.contains(toAdd)) {
|
|
50
|
-
const toRemove = colorScheme === "light" ? "dark" : "light";
|
|
51
|
-
classList.remove(getClassName(toRemove)), classList.add(toAdd);
|
|
52
|
-
}
|
|
53
|
-
}, [colorScheme]), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
54
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
55
|
-
"script",
|
|
56
|
-
{
|
|
57
|
-
dangerouslySetInnerHTML: {
|
|
58
|
-
__html: `let d = document.documentElement.classList
|
|
59
|
-
d.remove('${getClassName("light")}')
|
|
60
|
-
d.remove('${getClassName("dark")}')
|
|
61
|
-
let e = localStorage.getItem('${storageKey}')
|
|
62
|
-
let t =
|
|
63
|
-
'system' === e || !e
|
|
64
|
-
? window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
65
|
-
: e === 'dark'
|
|
66
|
-
t ? d.add('${getClassName("dark")}') : d.add('${getClassName("light")}')
|
|
67
|
-
`
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
),
|
|
71
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
72
|
-
SchemeContext.Provider,
|
|
73
|
-
{
|
|
74
|
-
value: (0, import_react.useMemo)(
|
|
75
|
-
() => ({
|
|
76
|
-
scheme: colorScheme,
|
|
77
|
-
setting: colorSchemeSetting
|
|
78
|
-
}),
|
|
79
|
-
[colorScheme, colorSchemeSetting]
|
|
80
|
-
),
|
|
81
|
-
children
|
|
82
|
-
}
|
|
83
|
-
)
|
|
84
|
-
] });
|
|
85
|
-
}
|
|
86
|
-
const MetaTheme = ({
|
|
87
|
-
color,
|
|
88
|
-
darkColor,
|
|
89
|
-
lightColor
|
|
90
|
-
}) => {
|
|
91
|
-
const [colorScheme] = useColorScheme();
|
|
92
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
93
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
94
|
-
"meta",
|
|
95
|
-
{
|
|
96
|
-
itemProp: "__deopt",
|
|
97
|
-
suppressHydrationWarning: !0,
|
|
98
|
-
id: "vxrn-theme-color",
|
|
99
|
-
name: "theme-color",
|
|
100
|
-
content: color ?? (colorScheme === "dark" ? darkColor : lightColor)
|
|
101
|
-
}
|
|
102
|
-
),
|
|
103
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
104
|
-
"script",
|
|
105
|
-
{
|
|
106
|
-
id: "meta-theme-hydrate",
|
|
107
|
-
dangerouslySetInnerHTML: {
|
|
108
|
-
__html: `
|
|
109
|
-
let dc = document.getElementById('vxrn-theme-color')
|
|
110
|
-
let e1 = localStorage.getItem('${storageKey}')
|
|
111
|
-
let isD = 'system' === e1 || !e1 ? window.matchMedia('(prefers-color-scheme: dark)').matches : e1 === 'dark'
|
|
112
|
-
dc.setAttribute('content', isD ? '${darkColor}' : '${lightColor}')
|
|
113
|
-
`
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
)
|
|
117
|
-
] });
|
|
118
|
-
};
|
|
119
|
-
//# sourceMappingURL=index.js.map
|
|
File without changes
|