@tamagui/next-theme 2.7.7 → 3.0.0-beta.643.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.
Files changed (41) hide show
  1. package/dist/cjs/NextTheme.cjs +10 -11
  2. package/dist/cjs/NextThemeProvider.cjs +182 -201
  3. package/dist/cjs/ThemeSettingContext.cjs +18 -21
  4. package/dist/cjs/UseThemeProps.cjs +10 -11
  5. package/dist/cjs/constants.cjs +17 -18
  6. package/dist/cjs/helpers.cjs +30 -31
  7. package/dist/cjs/index.cjs +10 -11
  8. package/dist/cjs/types.cjs +10 -11
  9. package/dist/cjs/useRootTheme.cjs +22 -27
  10. package/dist/cjs/useTheme.cjs +15 -20
  11. package/dist/esm/NextTheme.mjs +15 -9
  12. package/dist/esm/NextThemeProvider.mjs +166 -175
  13. package/dist/esm/NextThemeProvider.mjs.map +1 -1
  14. package/dist/esm/ThemeSettingContext.mjs +5 -3
  15. package/dist/esm/ThemeSettingContext.mjs.map +1 -1
  16. package/dist/esm/UseThemeProps.mjs +0 -2
  17. package/dist/esm/constants.mjs +1 -0
  18. package/dist/esm/constants.mjs.map +1 -1
  19. package/dist/esm/helpers.mjs +15 -13
  20. package/dist/esm/helpers.mjs.map +1 -1
  21. package/dist/esm/index.js +3 -3
  22. package/dist/esm/index.mjs +3 -3
  23. package/dist/esm/types.mjs +0 -2
  24. package/dist/esm/useRootTheme.mjs +9 -9
  25. package/dist/esm/useRootTheme.mjs.map +1 -1
  26. package/dist/esm/useTheme.mjs +3 -2
  27. package/dist/esm/useTheme.mjs.map +1 -1
  28. package/package.json +5 -5
  29. package/src/NextThemeProvider.tsx +0 -1
  30. package/src/UseThemeProps.tsx +0 -2
  31. package/src/useTheme.tsx +0 -6
  32. package/types/NextThemeProvider.d.ts.map +1 -1
  33. package/types/UseThemeProps.d.ts +0 -2
  34. package/types/UseThemeProps.d.ts.map +2 -2
  35. package/types/useTheme.d.ts +0 -4
  36. package/types/useTheme.d.ts.map +2 -2
  37. package/dist/esm/NextTheme.mjs.map +0 -1
  38. package/dist/esm/UseThemeProps.mjs.map +0 -1
  39. package/dist/esm/index.js.map +0 -1
  40. package/dist/esm/index.mjs.map +0 -1
  41. package/dist/esm/types.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"names":["useIsomorphicLayoutEffect","useEvent","Script","React","memo","useEffect","useMemo","useState","MEDIA","colorSchemes","getSystemTheme","getTheme","ThemeSettingContext","jsx","jsxs","NextThemeProvider","forcedTheme","disableTransitionOnChange","enableSystem","enableColorScheme","storageKey","themes","defaultTheme","attribute","skipNextHead","onChangeTheme","value","dark","light","children","theme","setThemeState","resolvedTheme","setResolvedTheme","attrs","Object","values","handleMediaQuery","e","_","update","startTransition","handleChangeTheme","updateStorage","updateDOM","name","theme2","localStorage","setItem","resolved","replace","d","document","documentElement","classList","remove","add","setAttribute","media","window","matchMedia","addListener","removeListener","set","newTheme","handleStorage","key","newValue","addEventListener","removeEventListener","colorScheme","includes","userPrefers","matches","wePrefer","style","setProperty","toggle","order","next","indexOf","length","systemTheme","contextValue","current","Provider","ThemeScript","optimization","removeClasses","map","t","join","literal","val","defaultSystem","scriptContent","JSON","stringify","dangerouslySetInnerHTML","__html","id","strategy","prevProps","nextProps"],"sources":["../../src/NextThemeProvider.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,yBAAA,QAAiC;AAC1C,SAASC,QAAA,QAAgB;AACzB,OAAOC,MAAA,MAAY;AACnB,YAAYC,KAAA,MAAW;AACvB,SAASC,IAAA,EAAMC,SAAA,EAAWC,OAAA,EAASC,QAAA,QAAgB;AAEnD,SAASC,KAAA,EAAOC,YAAA,QAAoB;AACpC,SAASC,cAAA,EAAgBC,QAAA,QAAgB;AACzC,SAASC,mBAAA,QAA2B;AAiL9B,SACEC,GAAA,EADFC,IAAA;AA7KC,MAAMC,iBAAA,GAAiEX,IAAA,CAC5E,CAAC;EACCY,WAAA;EACAC,yBAAA,GAA4B;EAC5BC,YAAA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extThemeProvider.js","names":[],"sources":["esm/NextThemeProvider.js"],"sourcesContent":["import { useIsomorphicLayoutEffect } from \"@tamagui/constants\";\nimport { useEvent } from \"@tamagui/use-event\";\nimport Script from \"next/script\";\nimport * as React from \"react\";\nimport { memo, useEffect, useMemo, useState } from \"react\";\nimport { MEDIA, colorSchemes } from \"./constants\";\nimport { getSystemTheme, getTheme } from \"./helpers\";\nimport { ThemeSettingContext } from \"./ThemeSettingContext\";\nimport { jsx, jsxs } from \"react/jsx-runtime\";\nconst NextThemeProvider = memo(\n ({\n forcedTheme,\n disableTransitionOnChange = false,\n enableSystem = true,\n enableColorScheme = true,\n storageKey = \"theme\",\n themes = colorSchemes,\n defaultTheme = enableSystem ? \"system\" : \"light\",\n attribute = \"class\",\n skipNextHead,\n onChangeTheme,\n value = {\n dark: \"t_dark\",\n light: \"t_light\"\n },\n children\n }) => {\n const [theme, setThemeState] = useState(() => getTheme(storageKey, defaultTheme));\n const [resolvedTheme, setResolvedTheme] = useState(() => getTheme(storageKey));\n const attrs = !value ? themes : Object.values(value);\n const handleMediaQuery = useEvent((e) => {\n const _ = getSystemTheme(e);\n const update = () => setResolvedTheme(_);\n if (disableTransitionOnChange) {\n update();\n } else {\n React.startTransition(() => update());\n }\n if (theme === \"system\" && !forcedTheme) {\n handleChangeTheme(_, false);\n }\n });\n const handleChangeTheme = useEvent(\n (theme2, updateStorage = true, updateDOM = true) => {\n let name = value?.[theme2] || theme2;\n if (updateStorage) {\n try {\n localStorage.setItem(storageKey, theme2);\n } catch (e) {\n }\n }\n if (theme2 === \"system\" && enableSystem) {\n const resolved = getSystemTheme();\n name = value?.[resolved] || resolved;\n }\n onChangeTheme?.(name.replace(\"t_\", \"\"));\n if (updateDOM) {\n const d = document.documentElement;\n if (attribute === \"class\") {\n d.classList.remove(...attrs);\n d.classList.add(name);\n } else {\n d.setAttribute(attribute, name);\n }\n }\n }\n );\n useIsomorphicLayoutEffect(() => {\n const media = window.matchMedia(MEDIA);\n media.addListener(handleMediaQuery);\n handleMediaQuery(media);\n return () => {\n media.removeListener(handleMediaQuery);\n };\n }, []);\n const set = useEvent((newTheme) => {\n if (forcedTheme) {\n return;\n }\n handleChangeTheme(newTheme);\n setThemeState(newTheme);\n });\n useEffect(() => {\n const handleStorage = (e) => {\n if (e.key !== storageKey) {\n return;\n }\n const theme2 = e.newValue || defaultTheme;\n set(theme2);\n };\n window.addEventListener(\"storage\", handleStorage);\n return () => {\n window.removeEventListener(\"storage\", handleStorage);\n };\n }, [defaultTheme, set, storageKey]);\n useIsomorphicLayoutEffect(() => {\n if (!enableColorScheme) return;\n const colorScheme = (\n // If theme is forced to light or dark, use that\n forcedTheme && colorSchemes.includes(forcedTheme) ? forcedTheme : (\n // If regular theme is light or dark\n theme && colorSchemes.includes(theme) ? theme : (\n // If theme is system, use the resolved version\n theme === \"system\" ? resolvedTheme || null : null\n )\n )\n );\n const userPrefers = typeof window !== \"undefined\" && window.matchMedia && window.matchMedia(\"(prefers-color-scheme: dark)\").matches ? \"dark\" : \"light\";\n const wePrefer = colorScheme || \"light\";\n if (userPrefers !== wePrefer) {\n document.documentElement.style.setProperty(\"color-scheme\", colorScheme);\n }\n }, [enableColorScheme, theme, resolvedTheme, forcedTheme]);\n const toggle = useEvent(() => {\n const order = resolvedTheme === \"dark\" ? [\"system\", \"light\", \"dark\"] : [\"system\", \"dark\", \"light\"];\n const next = order[(order.indexOf(theme) + 1) % order.length];\n set(next);\n });\n const systemTheme = enableSystem ? resolvedTheme : void 0;\n const contextValue = useMemo(() => {\n const value2 = {\n current: theme,\n set,\n toggle,\n forcedTheme,\n resolvedTheme: theme === \"system\" ? resolvedTheme : theme,\n themes: enableSystem ? [...themes, \"system\"] : themes,\n systemTheme\n };\n return value2;\n }, [\n theme,\n set,\n toggle,\n forcedTheme,\n resolvedTheme,\n enableSystem,\n themes,\n systemTheme\n ]);\n return /* @__PURE__ */ jsxs(ThemeSettingContext.Provider, { value: contextValue, children: [\n /* @__PURE__ */ jsx(\n ThemeScript,\n {\n ...{\n forcedTheme,\n storageKey,\n systemTheme: resolvedTheme,\n attribute,\n value,\n enableSystem,\n defaultTheme,\n attrs,\n skipNextHead\n }\n }\n ),\n children\n ] });\n }\n);\nconst ThemeScript = memo(\n ({\n forcedTheme,\n storageKey,\n attribute,\n enableSystem,\n defaultTheme,\n value,\n attrs,\n skipNextHead\n }) => {\n const optimization = (() => {\n if (attribute === \"class\") {\n const removeClasses = attrs.map((t) => `d.remove('${t}')`).join(\";\");\n return `var d=document.documentElement.classList;${removeClasses};`;\n }\n return `var d=document.documentElement;`;\n })();\n const updateDOM = (name, literal) => {\n name = value?.[name] || name;\n const val = literal ? name : `'${name}'`;\n if (attribute === \"class\") {\n return `d.add(${val})`;\n }\n return `d.setAttribute('${attribute}', ${val})`;\n };\n const defaultSystem = defaultTheme === \"system\";\n const scriptContent = forcedTheme ? `!function(){${optimization}${updateDOM(forcedTheme)}}()` : enableSystem ? `!function(){try {${optimization}var e=localStorage.getItem('${storageKey}');if(\"system\"===e||(!e&&${defaultSystem})){var t=\"${MEDIA}\",m=window.matchMedia(t);m.media!==t||m.matches?${updateDOM(\n \"dark\"\n )}:${updateDOM(\"light\")}}else if(e){${value ? `var x=${JSON.stringify(value)};` : \"\"}${updateDOM(value ? \"x[e]\" : \"e\", true)}}${!defaultSystem ? `else{${updateDOM(defaultTheme)}}` : \"\"}}catch(e){}}()` : `!function(){try{${optimization}var e=localStorage.getItem(\"${storageKey}\");if(e){${value ? `var x=${JSON.stringify(value)};` : \"\"}${updateDOM(value ? \"x[e]\" : \"e\", true)}}else{${updateDOM(\n defaultTheme\n )};}}catch(t){}}();`;\n if (skipNextHead) {\n return /* @__PURE__ */ jsx(\n \"script\",\n {\n dangerouslySetInnerHTML: { __html: scriptContent }\n },\n \"next-themes-script\"\n );\n }\n return /* @__PURE__ */ jsx(\n Script,\n {\n id: \"next-themes-script\",\n strategy: \"beforeInteractive\",\n dangerouslySetInnerHTML: { __html: scriptContent }\n }\n );\n },\n (prevProps, nextProps) => {\n if (prevProps.forcedTheme !== nextProps.forcedTheme) return false;\n return true;\n }\n);\nexport {\n NextThemeProvider\n};\n//# sourceMappingURL=NextThemeProvider.js.map\n"],"mappings":";;;;;;;;;;;AASA,MAAM,oBAAoB,MACvB,EACC,aACA,4BAA4B,OAC5B,eAAe,MACf,oBAAoB,MACpB,aAAa,SACb,SAAS,cACT,eAAe,eAAe,WAAW,SACzC,YAAY,SACZ,cACA,eACA,QAAQ;CACN,MAAM;CACN,OAAO;AACT,GACA,eACI;CACJ,MAAM,CAAC,OAAO,iBAAiB,eAAe,SAAS,YAAY,YAAY,CAAC;CAChF,MAAM,CAAC,eAAe,oBAAoB,eAAe,SAAS,UAAU,CAAC;CAC7E,MAAM,QAAQ,CAAC,QAAQ,SAAS,OAAO,OAAO,KAAK;CACnD,MAAM,mBAAmB,UAAU,MAAM;EACvC,MAAM,IAAI,eAAe,CAAC;EAC1B,MAAM,eAAe,iBAAiB,CAAC;EACvC,IAAI,2BAA2B;GAC7B,OAAO;EACT,OAAO;GACL,MAAM,sBAAsB,OAAO,CAAC;EACtC;EACA,IAAI,UAAU,YAAY,CAAC,aAAa;GACtC,kBAAkB,GAAG,KAAK;EAC5B;CACF,CAAC;CACD,MAAM,oBAAoB,UACvB,QAAQ,gBAAgB,MAAM,YAAY,SAAS;EAClD,IAAI,OAAO,QAAQ,WAAW;EAC9B,IAAI,eAAe;GACjB,IAAI;IACF,aAAa,QAAQ,YAAY,MAAM;GACzC,SAAS,GAAG,CACZ;EACF;EACA,IAAI,WAAW,YAAY,cAAc;GACvC,MAAM,WAAW,eAAe;GAChC,OAAO,QAAQ,aAAa;EAC9B;EACA,gBAAgB,KAAK,QAAQ,MAAM,EAAE,CAAC;EACtC,IAAI,WAAW;GACb,MAAM,IAAI,SAAS;GACnB,IAAI,cAAc,SAAS;IACzB,EAAE,UAAU,OAAO,GAAG,KAAK;IAC3B,EAAE,UAAU,IAAI,IAAI;GACtB,OAAO;IACL,EAAE,aAAa,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S,KAAK,UAAU,KAAK,EAAE,KAAK,KAAK,UAAU,QAAQ,SAAS,KAAK,IAAI,EAAE,QAAQ,UAC5X,YACF,EAAE;CACF,IAAI,cAAc;EAChB,OAAuB,oBACrB,UACA,EACE,yBAAyB,EAAE,QAAQ,cAAc,EACnD,GACA,oBACF;CACF;CACA,OAAuB,oBACrB,QACA;EACE,IAAI;EACJ,UAAU;EACV,yBAAyB,EAAE,QAAQ,cAAc;CACnD,CACF;AACF,IACC,WAAW,cAAc;CACxB,IAAI,UAAU,gBAAgB,UAAU,aAAa,OAAO;CAC5D,OAAO;AACT,CACF"}
@@ -1,8 +1,10 @@
1
1
  import { createContext } from "react";
2
+
2
3
  const ThemeSettingContext = createContext({
3
- toggle: () => {},
4
- set: _ => {},
5
- themes: []
4
+ toggle: () => {},
5
+ set: (_) => {},
6
+ themes: []
6
7
  });
8
+
7
9
  export { ThemeSettingContext };
8
10
  //# sourceMappingURL=ThemeSettingContext.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["createContext","ThemeSettingContext","toggle","set","_","themes"],"sources":["../../src/ThemeSettingContext.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,aAAA,QAAmC;AAIrC,MAAMC,mBAAA,GAA8CD,aAAA,CAA6B;EACtFE,MAAA,EAAQA,CAAA,KAAM,CAAC;EACfC,GAAA,EAAMC,CAAA,IAAM,CAAC;EACbC,MAAA,EAAQ;AACV,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"ThemeSettingContext.js","names":[],"sources":["esm/ThemeSettingContext.js"],"sourcesContent":["import { createContext } from \"react\";\nconst ThemeSettingContext = createContext({\n toggle: () => {\n },\n set: (_) => {\n },\n themes: []\n});\nexport {\n ThemeSettingContext\n};\n//# sourceMappingURL=ThemeSettingContext.js.map\n"],"mappings":";;;AACA,MAAM,sBAAsB,cAAc;CACxC,cAAc,CACd;CACA,MAAM,MAAM,CACZ;CACA,QAAQ,CAAC;AACX,CAAC"}
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=UseThemeProps.mjs.map
@@ -1,5 +1,6 @@
1
1
  const constants = {};
2
2
  const colorSchemes = ["light", "dark"];
3
3
  const MEDIA = "(prefers-color-scheme: dark)";
4
+
4
5
  export { MEDIA, colorSchemes, constants };
5
6
  //# sourceMappingURL=constants.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["constants","colorSchemes","MEDIA"],"sources":["../../src/constants.tsx"],"sourcesContent":[null],"mappings":"AAAO,MAAMA,SAAA,GAAY,CAAC;AACnB,MAAMC,YAAA,GAAe,CAAC,SAAS,MAAM;AACrC,MAAMC,KAAA,GAAQ","ignoreList":[]}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["esm/constants.js"],"sourcesContent":["const constants = {};\nconst colorSchemes = [\"light\", \"dark\"];\nconst MEDIA = \"(prefers-color-scheme: dark)\";\nexport {\n MEDIA,\n colorSchemes,\n constants\n};\n//# sourceMappingURL=constants.js.map\n"],"mappings":";AAAA,MAAM,YAAY,CAAC;AACnB,MAAM,eAAe,CAAC,SAAS,MAAM;AACrC,MAAM,QAAQ"}
@@ -1,20 +1,22 @@
1
1
  import { MEDIA } from "./constants.mjs";
2
+
2
3
  const helpers = {};
3
4
  const getTheme = (key, fallback) => {
4
- if (typeof window === "undefined") return void 0;
5
- let theme;
6
- try {
7
- theme = localStorage.getItem(key) || void 0;
8
- } catch (e) {}
9
- return theme || fallback;
5
+ if (typeof window === "undefined") return void 0;
6
+ let theme;
7
+ try {
8
+ theme = localStorage.getItem(key) || void 0;
9
+ } catch (e) {}
10
+ return theme || fallback;
10
11
  };
11
- const getSystemTheme = e => {
12
- if (!e) {
13
- e = window.matchMedia(MEDIA);
14
- }
15
- const isDark = e.matches;
16
- const systemTheme = isDark ? "dark" : "light";
17
- return systemTheme;
12
+ const getSystemTheme = (e) => {
13
+ if (!e) {
14
+ e = window.matchMedia(MEDIA);
15
+ }
16
+ const isDark = e.matches;
17
+ const systemTheme = isDark ? "dark" : "light";
18
+ return systemTheme;
18
19
  };
20
+
19
21
  export { getSystemTheme, getTheme, helpers };
20
22
  //# sourceMappingURL=helpers.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["MEDIA","helpers","getTheme","key","fallback","window","theme","localStorage","getItem","e","getSystemTheme","matchMedia","isDark","matches","systemTheme"],"sources":["../../src/helpers.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,KAAA,QAAa;AAEf,MAAMC,OAAA,GAAU,CAAC;AAGjB,MAAMC,QAAA,GAAWA,CAACC,GAAA,EAAaC,QAAA,KAA2B;EAC/D,IAAI,OAAOC,MAAA,KAAW,aAAa,OAAO;EAC1C,IAAIC,KAAA;EACJ,IAAI;IACFA,KAAA,GAAQC,YAAA,CAAaC,OAAA,CAAQL,GAAG,KAAK;EACvC,SAASM,CAAA,EAAG,CAEZ;EACA,OAAOH,KAAA,IAASF,QAAA;AAClB;AAEO,MAAMM,cAAA,GAAkBD,CAAA,IAAyC;EACtE,IAAI,CAACA,CAAA,EAAG;IACNA,CAAA,GAAIJ,MAAA,CAAOM,UAAA,CAAWX,KAAK;EAC7B;EAEA,MAAMY,MAAA,GAASH,CAAA,CAAEI,OAAA;EACjB,MAAMC,WAAA,GAAcF,MAAA,GAAS,SAAS;EACtC,OAAOE,WAAA;AACT","ignoreList":[]}
1
+ {"version":3,"file":"helpers.js","names":[],"sources":["esm/helpers.js"],"sourcesContent":["import { MEDIA } from \"./constants\";\nconst helpers = {};\nconst getTheme = (key, fallback) => {\n if (typeof window === \"undefined\") return void 0;\n let theme;\n try {\n theme = localStorage.getItem(key) || void 0;\n } catch (e) {\n }\n return theme || fallback;\n};\nconst getSystemTheme = (e) => {\n if (!e) {\n e = window.matchMedia(MEDIA);\n }\n const isDark = e.matches;\n const systemTheme = isDark ? \"dark\" : \"light\";\n return systemTheme;\n};\nexport {\n getSystemTheme,\n getTheme,\n helpers\n};\n//# sourceMappingURL=helpers.js.map\n"],"mappings":";;;AACA,MAAM,UAAU,CAAC;AACjB,MAAM,YAAY,KAAK,aAAa;CAClC,IAAI,OAAO,WAAW,aAAa,OAAO,KAAK;CAC/C,IAAI;CACJ,IAAI;EACF,QAAQ,aAAa,QAAQ,GAAG,KAAK,KAAK;CAC5C,SAAS,GAAG,CACZ;CACA,OAAO,SAAS;AAClB;AACA,MAAM,kBAAkB,MAAM;CAC5B,IAAI,CAAC,GAAG;EACN,IAAI,OAAO,WAAW,KAAK;CAC7B;CACA,MAAM,SAAS,EAAE;CACjB,MAAM,cAAc,SAAS,SAAS;CACtC,OAAO;AACT"}
package/dist/esm/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./NextTheme.mjs";
2
- export * from "./types.mjs";
3
- //# sourceMappingURL=index.js.map
1
+ export * from "./NextTheme.mjs"
2
+
3
+ export * from "./types.mjs"
@@ -1,3 +1,3 @@
1
- export * from "./NextTheme.mjs";
2
- export * from "./types.mjs";
3
- //# sourceMappingURL=index.mjs.map
1
+ export * from "./NextTheme.mjs"
2
+
3
+ export * from "./types.mjs"
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=types.mjs.map
@@ -1,14 +1,14 @@
1
1
  import { useState } from "react";
2
2
  import { isClient } from "@tamagui/constants";
3
- const useRootTheme = ({
4
- fallback = "light"
5
- } = {}) => {
6
- let initialVal = fallback;
7
- if (isClient) {
8
- const classes = document.documentElement.classList;
9
- initialVal = classes.contains("t_dark") ? "dark" : classes.contains("t_light") ? "light" : fallback;
10
- }
11
- return useState(initialVal);
3
+
4
+ const useRootTheme = ({ fallback = "light" } = {}) => {
5
+ let initialVal = fallback;
6
+ if (isClient) {
7
+ const classes = document.documentElement.classList;
8
+ initialVal = classes.contains("t_dark") ? "dark" : classes.contains("t_light") ? "light" : fallback;
9
+ }
10
+ return useState(initialVal);
12
11
  };
12
+
13
13
  export { useRootTheme };
14
14
  //# sourceMappingURL=useRootTheme.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["useState","isClient","useRootTheme","fallback","initialVal","classes","document","documentElement","classList","contains"],"sources":["../../src/useRootTheme.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,QAAA,QAAoD;AAC7D,SAASC,QAAA,QAAgB;AAIlB,MAAMC,YAAA,GAAeA,CAAC;EAAEC,QAAA,GAAW;AAAQ,IAAgC,CAAC,MAG9E;EACH,IAAIC,UAAA,GAAaD,QAAA;EAEjB,IAAIF,QAAA,EAAU;IACZ,MAAMI,OAAA,GAAUC,QAAA,CAASC,eAAA,CAAgBC,SAAA;IACzCJ,UAAA,GAAaC,OAAA,CAAQI,QAAA,CAAS,QAAQ,IAClC,SACAJ,OAAA,CAAQI,QAAA,CAAS,SAAS,IACxB,UACAN,QAAA;EACR;EAEA,OAAOH,QAAA,CAAsBI,UAAU;AACzC","ignoreList":[]}
1
+ {"version":3,"file":"useRootTheme.js","names":[],"sources":["esm/useRootTheme.js"],"sourcesContent":["import { useState } from \"react\";\nimport { isClient } from \"@tamagui/constants\";\nconst useRootTheme = ({ fallback = \"light\" } = {}) => {\n let initialVal = fallback;\n if (isClient) {\n const classes = document.documentElement.classList;\n initialVal = classes.contains(\"t_dark\") ? \"dark\" : classes.contains(\"t_light\") ? \"light\" : fallback;\n }\n return useState(initialVal);\n};\nexport {\n useRootTheme\n};\n//# sourceMappingURL=useRootTheme.js.map\n"],"mappings":";;;;AAEA,MAAM,gBAAgB,EAAE,WAAW,YAAY,CAAC,MAAM;CACpD,IAAI,aAAa;CACjB,IAAI,UAAU;EACZ,MAAM,UAAU,SAAS,gBAAgB;EACzC,aAAa,QAAQ,SAAS,QAAQ,IAAI,SAAS,QAAQ,SAAS,SAAS,IAAI,UAAU;CAC7F;CACA,OAAO,SAAS,UAAU;AAC5B"}
@@ -1,6 +1,7 @@
1
1
  import { useContext } from "react";
2
2
  import { ThemeSettingContext } from "./ThemeSettingContext.mjs";
3
- const useTheme = () => useContext(ThemeSettingContext);
3
+
4
4
  const useThemeSetting = () => useContext(ThemeSettingContext);
5
- export { useTheme, useThemeSetting };
5
+
6
+ export { useThemeSetting };
6
7
  //# sourceMappingURL=useTheme.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["useContext","ThemeSettingContext","useTheme","useThemeSetting"],"sources":["../../src/useTheme.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AAE3B,SAASC,mBAAA,QAA2B;AAO7B,MAAMC,QAAA,GAAWA,CAAA,KAAqBF,UAAA,CAAWC,mBAAmB;AAEpE,MAAME,eAAA,GAAkBA,CAAA,KAAqBH,UAAA,CAAWC,mBAAmB","ignoreList":[]}
1
+ {"version":3,"file":"useTheme.js","names":[],"sources":["esm/useTheme.js"],"sourcesContent":["import { useContext } from \"react\";\nimport { ThemeSettingContext } from \"./ThemeSettingContext\";\nconst useThemeSetting = () => useContext(ThemeSettingContext);\nexport {\n useThemeSetting\n};\n//# sourceMappingURL=useTheme.js.map\n"],"mappings":";;;;AAEA,MAAM,wBAAwB,WAAW,mBAAmB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/next-theme",
3
- "version": "2.7.7",
3
+ "version": "3.0.0-beta.643.1",
4
4
  "source": "src/index.ts",
5
5
  "files": [
6
6
  "src",
@@ -19,7 +19,7 @@
19
19
  "module": "./dist/esm/index.mjs",
20
20
  "import": "./dist/esm/index.mjs",
21
21
  "require": "./dist/cjs/index.cjs",
22
- "default": "./dist/cjs/index.js"
22
+ "default": "./dist/esm/index.mjs"
23
23
  }
24
24
  },
25
25
  "publishConfig": {
@@ -32,11 +32,11 @@
32
32
  "clean:build": "tamagui-build clean:build"
33
33
  },
34
34
  "dependencies": {
35
- "@tamagui/constants": "2.7.7",
36
- "@tamagui/use-event": "2.7.7"
35
+ "@tamagui/constants": "3.0.0-beta.643.1",
36
+ "@tamagui/use-event": "3.0.0-beta.643.1"
37
37
  },
38
38
  "devDependencies": {
39
- "@tamagui/build": "2.7.7",
39
+ "@tamagui/build": "3.0.0-beta.643.1",
40
40
  "next": "16.1.1",
41
41
  "react": ">=19"
42
42
  },
@@ -161,7 +161,6 @@ export const NextThemeProvider: React.FunctionComponent<ThemeProviderProps> = me
161
161
 
162
162
  const contextValue = useMemo(() => {
163
163
  const value: UseThemeProps = {
164
- theme,
165
164
  current: theme,
166
165
  set,
167
166
  toggle,
@@ -10,8 +10,6 @@ export interface UseThemeProps {
10
10
  toggle: () => void
11
11
  /** Active theme name - will return "system" if not overriden, see "resolvedTheme" for getting resolved system value */
12
12
  current?: string
13
- /** @deprecated Use `current` instead (deprecating avoid confusion with useTheme) */
14
- theme?: string
15
13
  /** If `enableSystem` is true and the active theme is "system", this returns whether the system preference resolved to "dark" or "light". Otherwise, identical to `theme` */
16
14
  resolvedTheme?: string
17
15
  /** If enableSystem is true, returns the System theme preference ("dark" or "light"), regardless what the active theme is */
package/src/useTheme.tsx CHANGED
@@ -3,10 +3,4 @@ import { useContext } from 'react'
3
3
  import { ThemeSettingContext } from './ThemeSettingContext'
4
4
  import type { UseThemeProps } from './UseThemeProps'
5
5
 
6
- /**
7
- * @deprecated renamed to `useThemeSetting` to avoid confusion with core `useTheme` hook
8
- */
9
-
10
- export const useTheme = (): UseThemeProps => useContext(ThemeSettingContext)
11
-
12
6
  export const useThemeSetting = (): UseThemeProps => useContext(ThemeSettingContext)
@@ -6,6 +6,6 @@
6
6
  ],
7
7
  "version": 3,
8
8
  "sourcesContent": [
9
- "import { useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { useEvent } from '@tamagui/use-event'\nimport Script from 'next/script'\nimport * as React from 'react'\nimport { memo, useEffect, useMemo, useState } from 'react'\n\nimport { MEDIA, colorSchemes } from './constants'\nimport { getSystemTheme, getTheme } from './helpers'\nimport { ThemeSettingContext } from './ThemeSettingContext'\nimport type { ValueObject } from './types'\nimport type { ThemeProviderProps, UseThemeProps } from './UseThemeProps'\n\nexport const NextThemeProvider: React.FunctionComponent<ThemeProviderProps> = memo(\n ({\n forcedTheme,\n disableTransitionOnChange = false,\n enableSystem = true,\n enableColorScheme = true,\n storageKey = 'theme',\n themes = colorSchemes,\n defaultTheme = enableSystem ? 'system' : 'light',\n attribute = 'class',\n skipNextHead,\n onChangeTheme,\n value = {\n dark: 't_dark',\n light: 't_light',\n },\n children,\n }) => {\n const [theme, setThemeState] = useState(() => getTheme(storageKey, defaultTheme))\n const [resolvedTheme, setResolvedTheme] = useState(() => getTheme(storageKey))\n const attrs = !value ? themes : Object.values(value)\n\n const handleMediaQuery = useEvent((e?) => {\n const _ = getSystemTheme(e)\n const update = () => setResolvedTheme(_)\n if (disableTransitionOnChange) {\n update()\n } else {\n React.startTransition(() => update())\n }\n if (theme === 'system' && !forcedTheme) {\n handleChangeTheme(_, false)\n }\n })\n\n const handleChangeTheme = useEvent(\n (theme, updateStorage = true, updateDOM = true) => {\n let name = value?.[theme] || theme\n\n if (updateStorage) {\n try {\n localStorage.setItem(storageKey, theme)\n } catch (e) {\n // Unsupported\n }\n }\n\n if (theme === 'system' && enableSystem) {\n const resolved = getSystemTheme()\n name = value?.[resolved] || resolved\n }\n\n onChangeTheme?.(name.replace('t_', ''))\n\n if (updateDOM) {\n const d = document.documentElement\n if (attribute === 'class') {\n d.classList.remove(...attrs)\n d.classList.add(name)\n } else {\n d.setAttribute(attribute, name)\n }\n }\n }\n )\n\n useIsomorphicLayoutEffect(() => {\n // Always listen to System preference\n const media = window.matchMedia(MEDIA)\n // Intentionally use deprecated listener methods to support iOS & old browsers\n media.addListener(handleMediaQuery)\n handleMediaQuery(media)\n return () => {\n media.removeListener(handleMediaQuery)\n }\n }, [])\n\n const set = useEvent((newTheme) => {\n if (forcedTheme) {\n // when forcedTheme is active, block all updates to avoid desync\n return\n }\n handleChangeTheme(newTheme)\n setThemeState(newTheme)\n })\n\n // localStorage event handling\n useEffect(() => {\n const handleStorage = (e: StorageEvent) => {\n if (e.key !== storageKey) {\n return\n }\n // If default theme set, use it if localstorage === null (happens on local storage manual deletion)\n const theme = e.newValue || defaultTheme\n set(theme)\n }\n window.addEventListener('storage', handleStorage)\n return () => {\n window.removeEventListener('storage', handleStorage)\n }\n }, [defaultTheme, set, storageKey])\n\n // color-scheme handling\n useIsomorphicLayoutEffect(() => {\n if (!enableColorScheme) return\n\n const colorScheme =\n // If theme is forced to light or dark, use that\n forcedTheme && colorSchemes.includes(forcedTheme as 'light' | 'dark')\n ? forcedTheme\n : // If regular theme is light or dark\n theme && colorSchemes.includes(theme)\n ? theme\n : // If theme is system, use the resolved version\n theme === 'system'\n ? resolvedTheme || null\n : null\n\n // color-scheme tells browser how to render built-in elements like forms, scrollbars, etc.\n // if color-scheme is null, this will remove the property\n const userPrefers =\n typeof window !== 'undefined' &&\n window.matchMedia &&\n window.matchMedia('(prefers-color-scheme: dark)').matches\n ? 'dark'\n : 'light'\n\n const wePrefer = colorScheme || 'light'\n\n // avoid running this because it causes full page reflow\n if (userPrefers !== wePrefer) {\n document.documentElement.style.setProperty('color-scheme', colorScheme)\n }\n }, [enableColorScheme, theme, resolvedTheme, forcedTheme])\n\n const toggle = useEvent(() => {\n const order =\n resolvedTheme === 'dark'\n ? ['system', 'light', 'dark']\n : ['system', 'dark', 'light']\n const next = order[(order.indexOf(theme) + 1) % order.length]\n set(next)\n })\n\n const systemTheme = (enableSystem ? resolvedTheme : undefined) as\n | 'light'\n | 'dark'\n | undefined\n\n const contextValue = useMemo(() => {\n const value: UseThemeProps = {\n theme,\n current: theme,\n set,\n toggle,\n forcedTheme,\n resolvedTheme: theme === 'system' ? resolvedTheme : theme,\n themes: enableSystem ? [...themes, 'system'] : (themes as string[]),\n systemTheme,\n } as const\n return value\n }, [\n theme,\n set,\n toggle,\n forcedTheme,\n resolvedTheme,\n enableSystem,\n themes,\n systemTheme,\n ])\n\n return (\n <ThemeSettingContext.Provider value={contextValue}>\n <ThemeScript\n {...{\n forcedTheme,\n storageKey,\n systemTheme: resolvedTheme,\n attribute,\n value,\n enableSystem,\n defaultTheme,\n attrs,\n skipNextHead,\n }}\n />\n {children}\n </ThemeSettingContext.Provider>\n )\n }\n)\n\nconst ThemeScript = memo(\n ({\n forcedTheme,\n storageKey,\n attribute,\n enableSystem,\n defaultTheme,\n value,\n attrs,\n skipNextHead,\n }: {\n forcedTheme?: string\n storageKey: string\n attribute?: string\n enableSystem?: boolean\n defaultTheme: string\n value?: ValueObject\n attrs: any\n skipNextHead?: boolean\n }) => {\n // Code-golfing the amount of characters in the script\n const optimization = (() => {\n if (attribute === 'class') {\n const removeClasses = attrs.map((t: string) => `d.remove('${t}')`).join(';')\n return `var d=document.documentElement.classList;${removeClasses};`\n }\n return `var d=document.documentElement;`\n })()\n\n const updateDOM = (name: string, literal?: boolean) => {\n name = value?.[name] || name\n const val = literal ? name : `'${name}'`\n\n if (attribute === 'class') {\n return `d.add(${val})`\n }\n\n return `d.setAttribute('${attribute}', ${val})`\n }\n\n const defaultSystem = defaultTheme === 'system'\n\n const scriptContent = forcedTheme\n ? `!function(){${optimization}${updateDOM(forcedTheme)}}()`\n : enableSystem\n ? `!function(){try {${optimization}var e=localStorage.getItem('${storageKey}');if(\"system\"===e||(!e&&${defaultSystem})){var t=\"${MEDIA}\",m=window.matchMedia(t);m.media!==t||m.matches?${updateDOM(\n 'dark'\n )}:${updateDOM('light')}}else if(e){${\n value ? `var x=${JSON.stringify(value)};` : ''\n }${updateDOM(value ? 'x[e]' : 'e', true)}}${\n !defaultSystem ? `else{${updateDOM(defaultTheme)}}` : ''\n }}catch(e){}}()`\n : `!function(){try{${optimization}var e=localStorage.getItem(\"${storageKey}\");if(e){${\n value ? `var x=${JSON.stringify(value)};` : ''\n }${updateDOM(value ? 'x[e]' : 'e', true)}}else{${updateDOM(\n defaultTheme\n )};}}catch(t){}}();`\n\n // skipNextHead returns raw script for useServerInsertedHTML usage\n if (skipNextHead) {\n return (\n <script\n key=\"next-themes-script\"\n dangerouslySetInnerHTML={{ __html: scriptContent }}\n />\n )\n }\n\n return (\n <Script\n id=\"next-themes-script\"\n strategy=\"beforeInteractive\"\n dangerouslySetInnerHTML={{ __html: scriptContent }}\n />\n )\n },\n (prevProps, nextProps) => {\n // Only re-render when forcedTheme changes\n // the rest of the props should be completely stable\n if (prevProps.forcedTheme !== nextProps.forcedTheme) return false\n return true\n }\n)\n"
9
+ "import { useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { useEvent } from '@tamagui/use-event'\nimport Script from 'next/script'\nimport * as React from 'react'\nimport { memo, useEffect, useMemo, useState } from 'react'\n\nimport { MEDIA, colorSchemes } from './constants'\nimport { getSystemTheme, getTheme } from './helpers'\nimport { ThemeSettingContext } from './ThemeSettingContext'\nimport type { ValueObject } from './types'\nimport type { ThemeProviderProps, UseThemeProps } from './UseThemeProps'\n\nexport const NextThemeProvider: React.FunctionComponent<ThemeProviderProps> = memo(\n ({\n forcedTheme,\n disableTransitionOnChange = false,\n enableSystem = true,\n enableColorScheme = true,\n storageKey = 'theme',\n themes = colorSchemes,\n defaultTheme = enableSystem ? 'system' : 'light',\n attribute = 'class',\n skipNextHead,\n onChangeTheme,\n value = {\n dark: 't_dark',\n light: 't_light',\n },\n children,\n }) => {\n const [theme, setThemeState] = useState(() => getTheme(storageKey, defaultTheme))\n const [resolvedTheme, setResolvedTheme] = useState(() => getTheme(storageKey))\n const attrs = !value ? themes : Object.values(value)\n\n const handleMediaQuery = useEvent((e?) => {\n const _ = getSystemTheme(e)\n const update = () => setResolvedTheme(_)\n if (disableTransitionOnChange) {\n update()\n } else {\n React.startTransition(() => update())\n }\n if (theme === 'system' && !forcedTheme) {\n handleChangeTheme(_, false)\n }\n })\n\n const handleChangeTheme = useEvent(\n (theme, updateStorage = true, updateDOM = true) => {\n let name = value?.[theme] || theme\n\n if (updateStorage) {\n try {\n localStorage.setItem(storageKey, theme)\n } catch (e) {\n // Unsupported\n }\n }\n\n if (theme === 'system' && enableSystem) {\n const resolved = getSystemTheme()\n name = value?.[resolved] || resolved\n }\n\n onChangeTheme?.(name.replace('t_', ''))\n\n if (updateDOM) {\n const d = document.documentElement\n if (attribute === 'class') {\n d.classList.remove(...attrs)\n d.classList.add(name)\n } else {\n d.setAttribute(attribute, name)\n }\n }\n }\n )\n\n useIsomorphicLayoutEffect(() => {\n // Always listen to System preference\n const media = window.matchMedia(MEDIA)\n // Intentionally use deprecated listener methods to support iOS & old browsers\n media.addListener(handleMediaQuery)\n handleMediaQuery(media)\n return () => {\n media.removeListener(handleMediaQuery)\n }\n }, [])\n\n const set = useEvent((newTheme) => {\n if (forcedTheme) {\n // when forcedTheme is active, block all updates to avoid desync\n return\n }\n handleChangeTheme(newTheme)\n setThemeState(newTheme)\n })\n\n // localStorage event handling\n useEffect(() => {\n const handleStorage = (e: StorageEvent) => {\n if (e.key !== storageKey) {\n return\n }\n // If default theme set, use it if localstorage === null (happens on local storage manual deletion)\n const theme = e.newValue || defaultTheme\n set(theme)\n }\n window.addEventListener('storage', handleStorage)\n return () => {\n window.removeEventListener('storage', handleStorage)\n }\n }, [defaultTheme, set, storageKey])\n\n // color-scheme handling\n useIsomorphicLayoutEffect(() => {\n if (!enableColorScheme) return\n\n const colorScheme =\n // If theme is forced to light or dark, use that\n forcedTheme && colorSchemes.includes(forcedTheme as 'light' | 'dark')\n ? forcedTheme\n : // If regular theme is light or dark\n theme && colorSchemes.includes(theme)\n ? theme\n : // If theme is system, use the resolved version\n theme === 'system'\n ? resolvedTheme || null\n : null\n\n // color-scheme tells browser how to render built-in elements like forms, scrollbars, etc.\n // if color-scheme is null, this will remove the property\n const userPrefers =\n typeof window !== 'undefined' &&\n window.matchMedia &&\n window.matchMedia('(prefers-color-scheme: dark)').matches\n ? 'dark'\n : 'light'\n\n const wePrefer = colorScheme || 'light'\n\n // avoid running this because it causes full page reflow\n if (userPrefers !== wePrefer) {\n document.documentElement.style.setProperty('color-scheme', colorScheme)\n }\n }, [enableColorScheme, theme, resolvedTheme, forcedTheme])\n\n const toggle = useEvent(() => {\n const order =\n resolvedTheme === 'dark'\n ? ['system', 'light', 'dark']\n : ['system', 'dark', 'light']\n const next = order[(order.indexOf(theme) + 1) % order.length]\n set(next)\n })\n\n const systemTheme = (enableSystem ? resolvedTheme : undefined) as\n | 'light'\n | 'dark'\n | undefined\n\n const contextValue = useMemo(() => {\n const value: UseThemeProps = {\n current: theme,\n set,\n toggle,\n forcedTheme,\n resolvedTheme: theme === 'system' ? resolvedTheme : theme,\n themes: enableSystem ? [...themes, 'system'] : (themes as string[]),\n systemTheme,\n } as const\n return value\n }, [\n theme,\n set,\n toggle,\n forcedTheme,\n resolvedTheme,\n enableSystem,\n themes,\n systemTheme,\n ])\n\n return (\n <ThemeSettingContext.Provider value={contextValue}>\n <ThemeScript\n {...{\n forcedTheme,\n storageKey,\n systemTheme: resolvedTheme,\n attribute,\n value,\n enableSystem,\n defaultTheme,\n attrs,\n skipNextHead,\n }}\n />\n {children}\n </ThemeSettingContext.Provider>\n )\n }\n)\n\nconst ThemeScript = memo(\n ({\n forcedTheme,\n storageKey,\n attribute,\n enableSystem,\n defaultTheme,\n value,\n attrs,\n skipNextHead,\n }: {\n forcedTheme?: string\n storageKey: string\n attribute?: string\n enableSystem?: boolean\n defaultTheme: string\n value?: ValueObject\n attrs: any\n skipNextHead?: boolean\n }) => {\n // Code-golfing the amount of characters in the script\n const optimization = (() => {\n if (attribute === 'class') {\n const removeClasses = attrs.map((t: string) => `d.remove('${t}')`).join(';')\n return `var d=document.documentElement.classList;${removeClasses};`\n }\n return `var d=document.documentElement;`\n })()\n\n const updateDOM = (name: string, literal?: boolean) => {\n name = value?.[name] || name\n const val = literal ? name : `'${name}'`\n\n if (attribute === 'class') {\n return `d.add(${val})`\n }\n\n return `d.setAttribute('${attribute}', ${val})`\n }\n\n const defaultSystem = defaultTheme === 'system'\n\n const scriptContent = forcedTheme\n ? `!function(){${optimization}${updateDOM(forcedTheme)}}()`\n : enableSystem\n ? `!function(){try {${optimization}var e=localStorage.getItem('${storageKey}');if(\"system\"===e||(!e&&${defaultSystem})){var t=\"${MEDIA}\",m=window.matchMedia(t);m.media!==t||m.matches?${updateDOM(\n 'dark'\n )}:${updateDOM('light')}}else if(e){${\n value ? `var x=${JSON.stringify(value)};` : ''\n }${updateDOM(value ? 'x[e]' : 'e', true)}}${\n !defaultSystem ? `else{${updateDOM(defaultTheme)}}` : ''\n }}catch(e){}}()`\n : `!function(){try{${optimization}var e=localStorage.getItem(\"${storageKey}\");if(e){${\n value ? `var x=${JSON.stringify(value)};` : ''\n }${updateDOM(value ? 'x[e]' : 'e', true)}}else{${updateDOM(\n defaultTheme\n )};}}catch(t){}}();`\n\n // skipNextHead returns raw script for useServerInsertedHTML usage\n if (skipNextHead) {\n return (\n <script\n key=\"next-themes-script\"\n dangerouslySetInnerHTML={{ __html: scriptContent }}\n />\n )\n }\n\n return (\n <Script\n id=\"next-themes-script\"\n strategy=\"beforeInteractive\"\n dangerouslySetInnerHTML={{ __html: scriptContent }}\n />\n )\n },\n (prevProps, nextProps) => {\n // Only re-render when forcedTheme changes\n // the rest of the props should be completely stable\n if (prevProps.forcedTheme !== nextProps.forcedTheme) return false\n return true\n }\n)\n"
10
10
  ]
11
11
  }
@@ -9,8 +9,6 @@ export interface UseThemeProps {
9
9
  toggle: () => void;
10
10
  /** Active theme name - will return "system" if not overriden, see "resolvedTheme" for getting resolved system value */
11
11
  current?: string;
12
- /** @deprecated Use `current` instead (deprecating avoid confusion with useTheme) */
13
- theme?: string;
14
12
  /** If `enableSystem` is true and the active theme is "system", this returns whether the system preference resolved to "dark" or "light". Otherwise, identical to `theme` */
15
13
  resolvedTheme?: string;
16
14
  /** If enableSystem is true, returns the System theme preference ("dark" or "light"), regardless what the active theme is */
@@ -1,11 +1,11 @@
1
1
  {
2
- "mappings": "AAAA,cAAc,mBAAmB;AAEjC,iBAAiB,cAAc;;CAE7B;;CAEA;;CAEA,MAAM;CACN;;CAEA;;CAEA;;CAEA;;CAEA,cAAc,SAAS;;AAGzB,iBAAiB,mBAAmB;CAClC;;CAEA;;CAEA;;CAEA;CACA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA,qBAAqB;;CAErB,QAAQ;CACR,iBAAiB;CAGjB",
2
+ "mappings": "AAAA,cAAc,mBAAmB;AAEjC,iBAAiB,cAAc;;CAE7B;;CAEA;;CAEA,MAAM;CACN;;CAEA;;CAEA;;CAEA,cAAc,SAAS;;AAGzB,iBAAiB,mBAAmB;CAClC;;CAEA;;CAEA;;CAEA;CACA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA,qBAAqB;;CAErB,QAAQ;CACR,iBAAiB;CAGjB",
3
3
  "names": [],
4
4
  "sources": [
5
5
  "src/UseThemeProps.tsx"
6
6
  ],
7
7
  "version": 3,
8
8
  "sourcesContent": [
9
- "import type { ValueObject } from './types'\n\nexport interface UseThemeProps {\n /** List of all available theme names */\n themes: string[]\n /** Forced theme name for the current page */\n forcedTheme?: string\n /** Update the theme */\n set: (theme: string) => void\n toggle: () => void\n /** Active theme name - will return \"system\" if not overriden, see \"resolvedTheme\" for getting resolved system value */\n current?: string\n /** @deprecated Use `current` instead (deprecating avoid confusion with useTheme) */\n theme?: string\n /** If `enableSystem` is true and the active theme is \"system\", this returns whether the system preference resolved to \"dark\" or \"light\". Otherwise, identical to `theme` */\n resolvedTheme?: string\n /** If enableSystem is true, returns the System theme preference (\"dark\" or \"light\"), regardless what the active theme is */\n systemTheme?: 'dark' | 'light'\n}\n\nexport interface ThemeProviderProps {\n children?: any\n /** List of all available theme names */\n themes?: string[]\n /** Forced theme name for the current page */\n forcedTheme?: string\n /** Whether to switch between dark and light themes based on prefers-color-scheme */\n enableSystem?: boolean\n systemTheme?: string\n /** Disable all CSS transitions when switching themes */\n disableTransitionOnChange?: boolean\n /** Whether to indicate to browsers which color scheme is used (dark or light) for built-in UI like inputs and buttons */\n enableColorScheme?: boolean\n /** Key used to store theme setting in localStorage */\n storageKey?: string\n /** Default theme name (for v0.0.12 and lower the default was light). If `enableSystem` is false, the default theme is light */\n defaultTheme?: string\n /** HTML attribute modified based on the active theme. Accepts `class` and `data-*` (meaning any data attribute, `data-mode`, `data-color`, etc.) */\n attribute?: string | 'class'\n /** Mapping of theme name to HTML attribute value. Object where key is the theme name and value is the attribute value */\n value?: ValueObject\n onChangeTheme?: (name: string) => void\n\n // avoids warning\n skipNextHead?: boolean\n}\n"
9
+ "import type { ValueObject } from './types'\n\nexport interface UseThemeProps {\n /** List of all available theme names */\n themes: string[]\n /** Forced theme name for the current page */\n forcedTheme?: string\n /** Update the theme */\n set: (theme: string) => void\n toggle: () => void\n /** Active theme name - will return \"system\" if not overriden, see \"resolvedTheme\" for getting resolved system value */\n current?: string\n /** If `enableSystem` is true and the active theme is \"system\", this returns whether the system preference resolved to \"dark\" or \"light\". Otherwise, identical to `theme` */\n resolvedTheme?: string\n /** If enableSystem is true, returns the System theme preference (\"dark\" or \"light\"), regardless what the active theme is */\n systemTheme?: 'dark' | 'light'\n}\n\nexport interface ThemeProviderProps {\n children?: any\n /** List of all available theme names */\n themes?: string[]\n /** Forced theme name for the current page */\n forcedTheme?: string\n /** Whether to switch between dark and light themes based on prefers-color-scheme */\n enableSystem?: boolean\n systemTheme?: string\n /** Disable all CSS transitions when switching themes */\n disableTransitionOnChange?: boolean\n /** Whether to indicate to browsers which color scheme is used (dark or light) for built-in UI like inputs and buttons */\n enableColorScheme?: boolean\n /** Key used to store theme setting in localStorage */\n storageKey?: string\n /** Default theme name (for v0.0.12 and lower the default was light). If `enableSystem` is false, the default theme is light */\n defaultTheme?: string\n /** HTML attribute modified based on the active theme. Accepts `class` and `data-*` (meaning any data attribute, `data-mode`, `data-color`, etc.) */\n attribute?: string | 'class'\n /** Mapping of theme name to HTML attribute value. Object where key is the theme name and value is the attribute value */\n value?: ValueObject\n onChangeTheme?: (name: string) => void\n\n // avoids warning\n skipNextHead?: boolean\n}\n"
10
10
  ]
11
11
  }
@@ -1,8 +1,4 @@
1
1
  import type { UseThemeProps } from "./UseThemeProps";
2
- /**
3
- * @deprecated renamed to `useThemeSetting` to avoid confusion with core `useTheme` hook
4
- */
5
- export declare const useTheme: () => UseThemeProps;
6
2
  export declare const useThemeSetting: () => UseThemeProps;
7
3
 
8
4
  //# sourceMappingURL=useTheme.d.ts.map
@@ -1,11 +1,11 @@
1
1
  {
2
- "mappings": "AAGA,cAAc,qBAAqB;;;;AAMnC,OAAO,cAAM,gBAAe;AAE5B,OAAO,cAAM,uBAAsB",
2
+ "mappings": "AAGA,cAAc,qBAAqB;AAEnC,OAAO,cAAM,uBAAsB",
3
3
  "names": [],
4
4
  "sources": [
5
5
  "src/useTheme.tsx"
6
6
  ],
7
7
  "version": 3,
8
8
  "sourcesContent": [
9
- "import { useContext } from 'react'\n\nimport { ThemeSettingContext } from './ThemeSettingContext'\nimport type { UseThemeProps } from './UseThemeProps'\n\n/**\n * @deprecated renamed to `useThemeSetting` to avoid confusion with core `useTheme` hook\n */\n\nexport const useTheme = (): UseThemeProps => useContext(ThemeSettingContext)\n\nexport const useThemeSetting = (): UseThemeProps => useContext(ThemeSettingContext)\n"
9
+ "import { useContext } from 'react'\n\nimport { ThemeSettingContext } from './ThemeSettingContext'\nimport type { UseThemeProps } from './UseThemeProps'\n\nexport const useThemeSetting = (): UseThemeProps => useContext(ThemeSettingContext)\n"
10
10
  ]
11
11
  }
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["../../src/NextTheme.tsx"],"sourcesContent":[null],"mappings":"AAGA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}