@vxrn/color-scheme 1.1.320 → 1.1.321

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.
@@ -0,0 +1,119 @@
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vxrn/color-scheme",
3
- "version": "1.1.320",
3
+ "version": "1.1.321",
4
4
  "sideEffects": false,
5
5
  "source": "src/index.ts",
6
6
  "types": "./types/index.d.ts",
@@ -30,12 +30,12 @@
30
30
  "clean:build": "tamagui-build clean:build"
31
31
  },
32
32
  "dependencies": {
33
- "@tamagui/use-did-finish-ssr": "^1.115.0",
34
- "@vxrn/universal-color-scheme": "1.1.320",
35
- "@vxrn/use-isomorphic-layout-effect": "1.1.320"
33
+ "@tamagui/use-did-finish-ssr": "^1.116.4",
34
+ "@vxrn/universal-color-scheme": "1.1.321",
35
+ "@vxrn/use-isomorphic-layout-effect": "1.1.321"
36
36
  },
37
37
  "devDependencies": {
38
- "@tamagui/build": "^1.115.0",
38
+ "@tamagui/build": "^1.116.4",
39
39
  "react": "^18.2.0 || ^19.0.0",
40
40
  "react-native": "0.74.5"
41
41
  },
File without changes