@tamagui/core 1.0.2 → 1.0.4
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/config.js +1 -1
- package/dist/cjs/config.js.map +2 -2
- package/dist/cjs/createComponent.js +51 -95
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/createTamagui.js +7 -4
- package/dist/cjs/createTamagui.js.map +2 -2
- package/dist/cjs/createVariable.js +1 -1
- package/dist/cjs/createVariable.js.map +2 -2
- package/dist/cjs/createVariables.js +12 -3
- package/dist/cjs/createVariables.js.map +2 -2
- package/dist/cjs/helpers/ThemeManager.js +12 -2
- package/dist/cjs/helpers/ThemeManager.js.map +2 -2
- package/dist/cjs/helpers/getSize.js +9 -5
- package/dist/cjs/helpers/getSize.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.js +39 -45
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/getStylesAtomic.js +32 -26
- package/dist/cjs/helpers/getStylesAtomic.js.map +2 -2
- package/dist/cjs/helpers/getStylesAtomic.native.js +6 -2
- package/dist/cjs/helpers/getStylesAtomic.native.js.map +2 -2
- package/dist/cjs/helpers/insertStyleRule.js +12 -1
- package/dist/cjs/helpers/insertStyleRule.js.map +2 -2
- package/dist/cjs/helpers/normalizeColor.js +8 -7
- package/dist/cjs/helpers/normalizeColor.js.map +2 -2
- package/dist/cjs/hooks/useMedia.js +37 -36
- package/dist/cjs/hooks/useMedia.js.map +2 -2
- package/dist/cjs/hooks/useTheme.js +28 -42
- package/dist/cjs/hooks/useTheme.js.map +3 -3
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/styled.js +4 -1
- package/dist/cjs/styled.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/views/Slot.js +1 -33
- package/dist/cjs/views/Slot.js.map +3 -3
- package/dist/cjs/views/Stack.test.js +4 -6
- package/dist/cjs/views/Stack.test.js.map +2 -2
- package/dist/cjs/views/Theme.js +45 -41
- package/dist/cjs/views/Theme.js.map +2 -2
- package/dist/cjs/views/ThemeProvider.js +1 -1
- package/dist/cjs/views/ThemeProvider.js.map +2 -2
- package/dist/esm/config.js +1 -1
- package/dist/esm/config.js.map +2 -2
- package/dist/esm/createComponent.js +53 -97
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/createTamagui.js +8 -5
- package/dist/esm/createTamagui.js.map +2 -2
- package/dist/esm/createVariable.js +1 -1
- package/dist/esm/createVariable.js.map +2 -2
- package/dist/esm/createVariables.js +10 -2
- package/dist/esm/createVariables.js.map +2 -2
- package/dist/esm/helpers/ThemeManager.js +13 -3
- package/dist/esm/helpers/ThemeManager.js.map +2 -2
- package/dist/esm/helpers/getSize.js +9 -5
- package/dist/esm/helpers/getSize.js.map +2 -2
- package/dist/esm/helpers/getSplitStyles.js +39 -45
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/getStylesAtomic.js +31 -26
- package/dist/esm/helpers/getStylesAtomic.js.map +2 -2
- package/dist/esm/helpers/getStylesAtomic.native.js +4 -1
- package/dist/esm/helpers/getStylesAtomic.native.js.map +2 -2
- package/dist/esm/helpers/insertStyleRule.js +12 -1
- package/dist/esm/helpers/insertStyleRule.js.map +2 -2
- package/dist/esm/helpers/normalizeColor.js +8 -7
- package/dist/esm/helpers/normalizeColor.js.map +2 -2
- package/dist/esm/hooks/useMedia.js +37 -37
- package/dist/esm/hooks/useMedia.js.map +2 -2
- package/dist/esm/hooks/useTheme.js +25 -39
- package/dist/esm/hooks/useTheme.js.map +3 -3
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/styled.js +4 -1
- package/dist/esm/styled.js.map +2 -2
- package/dist/esm/views/Slot.js +1 -33
- package/dist/esm/views/Slot.js.map +3 -3
- package/dist/esm/views/Stack.test.js +1 -3
- package/dist/esm/views/Stack.test.js.map +2 -2
- package/dist/esm/views/Theme.js +44 -40
- package/dist/esm/views/Theme.js.map +2 -2
- package/dist/esm/views/ThemeProvider.js +1 -1
- package/dist/esm/views/ThemeProvider.js.map +2 -2
- package/package.json +11 -11
- package/reset.css +4 -0
- package/src/__snapshots__/createTokens.test.ts.snap +90 -195
- package/src/config.ts +1 -1
- package/src/createComponent.tsx +72 -152
- package/src/createTamagui.ts +8 -5
- package/src/createVariable.ts +2 -1
- package/src/createVariables.ts +14 -1
- package/src/helpers/ThemeManager.tsx +13 -3
- package/src/helpers/getSplitStyles.tsx +43 -53
- package/src/helpers/getStylesAtomic.native.ts +2 -0
- package/src/helpers/getStylesAtomic.ts +36 -31
- package/src/helpers/insertStyleRule.tsx +12 -2
- package/src/helpers/normalizeColor.ts +8 -7
- package/src/hooks/useMedia.tsx +53 -48
- package/src/hooks/useTheme.tsx +37 -56
- package/src/index.ts +0 -1
- package/src/styled.tsx +4 -1
- package/src/types.tsx +7 -3
- package/src/views/Slot.tsx +3 -59
- package/src/views/Stack.test.tsx +1 -4
- package/src/views/Theme.tsx +60 -54
- package/src/views/ThemeProvider.tsx +1 -1
- package/types/createVariables.d.ts +1 -0
- package/types/helpers/ThemeManager.d.ts +1 -1
- package/types/helpers/getSplitStyles.d.ts +2 -3
- package/types/helpers/getStylesAtomic.d.ts +1 -0
- package/types/helpers/getStylesAtomic.native.d.ts +1 -0
- package/types/hooks/useMedia.d.ts +8 -4
- package/types/hooks/useTheme.d.ts +16 -2
- package/types/index.d.ts +0 -1
- package/types/types.d.ts +3 -2
- package/types/views/Slot.d.ts +5 -4
- package/types/views/Theme.d.ts +5 -2
- package/src/helpers/cache.ts +0 -13
- package/src/helpers/getSize.ts +0 -23
|
@@ -39,7 +39,7 @@ var import_config = require("../config");
|
|
|
39
39
|
var import_createProxy = require("../helpers/createProxy");
|
|
40
40
|
var import_matchMedia = require("../helpers/matchMedia");
|
|
41
41
|
var import_useSafeRef = require("./useSafeRef");
|
|
42
|
-
|
|
42
|
+
let mediaState = process.env.NODE_ENV === "development" ? (0, import_createProxy.createProxy)(
|
|
43
43
|
{},
|
|
44
44
|
{
|
|
45
45
|
get(target, key) {
|
|
@@ -98,7 +98,7 @@ function setupMediaListeners() {
|
|
|
98
98
|
const next = !!getMatch().matches;
|
|
99
99
|
if (next === mediaState[key])
|
|
100
100
|
return;
|
|
101
|
-
mediaState[key]
|
|
101
|
+
mediaState = { ...mediaState, [key]: next };
|
|
102
102
|
updateCurrentState();
|
|
103
103
|
};
|
|
104
104
|
var update = update2;
|
|
@@ -123,56 +123,57 @@ function useMediaListeners(config) {
|
|
|
123
123
|
}, []);
|
|
124
124
|
}
|
|
125
125
|
const currentStateListeners = /* @__PURE__ */ new Set();
|
|
126
|
+
let isFlushing = false;
|
|
126
127
|
function updateCurrentState() {
|
|
127
|
-
|
|
128
|
+
if (isFlushing)
|
|
129
|
+
return;
|
|
130
|
+
isFlushing = true;
|
|
131
|
+
setTimeout(() => {
|
|
132
|
+
(0, import_react.startTransition)(() => {
|
|
133
|
+
currentStateListeners.forEach((cb) => cb(mediaState));
|
|
134
|
+
});
|
|
135
|
+
isFlushing = false;
|
|
136
|
+
}, 0);
|
|
137
|
+
}
|
|
138
|
+
const shouldUpdate = /* @__PURE__ */ new WeakMap();
|
|
139
|
+
function setMediaShouldUpdate(ref, props) {
|
|
140
|
+
return shouldUpdate.set(ref, props);
|
|
128
141
|
}
|
|
129
142
|
function subscribe(subscriber) {
|
|
130
143
|
currentStateListeners.add(subscriber);
|
|
131
144
|
return () => currentStateListeners.delete(subscriber);
|
|
132
145
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
initialUseState || (initialUseState = {
|
|
141
|
-
prev: initState,
|
|
142
|
-
next: empty
|
|
143
|
-
});
|
|
144
|
-
const keys = (0, import_useSafeRef.useSafeRef)(initialUseState);
|
|
146
|
+
function useMedia(uid, debug) {
|
|
147
|
+
const internal = (0, import_useSafeRef.useSafeRef)(void 0);
|
|
148
|
+
if (!internal.current) {
|
|
149
|
+
internal.current = {
|
|
150
|
+
prev: initState
|
|
151
|
+
};
|
|
152
|
+
}
|
|
145
153
|
const state = (0, import_react.useSyncExternalStore)(
|
|
146
154
|
subscribe,
|
|
147
155
|
() => {
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
if (
|
|
151
|
-
return
|
|
152
|
-
}
|
|
153
|
-
let didUpdate = false;
|
|
154
|
-
const next = {};
|
|
155
|
-
for (const key in curState.next) {
|
|
156
|
-
const val = mediaState[key];
|
|
157
|
-
if (curState.prev[key] !== val) {
|
|
158
|
-
didUpdate = true;
|
|
159
|
-
}
|
|
160
|
-
next[key] = val;
|
|
156
|
+
const { touched, prev } = internal.current;
|
|
157
|
+
const componentState = uid ? shouldUpdate.get(uid) : void 0;
|
|
158
|
+
if ((componentState == null ? void 0 : componentState.enabled) === false) {
|
|
159
|
+
return prev;
|
|
161
160
|
}
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
const testKeys = (componentState == null ? void 0 : componentState.keys) ?? ((componentState == null ? void 0 : componentState.enabled) && touched ? [...touched] : null);
|
|
162
|
+
if (testKeys == null ? void 0 : testKeys.every((key) => mediaState[key] === prev[key])) {
|
|
163
|
+
return prev;
|
|
164
164
|
}
|
|
165
|
-
|
|
166
|
-
return
|
|
165
|
+
internal.current.prev = mediaState;
|
|
166
|
+
return mediaState;
|
|
167
167
|
},
|
|
168
168
|
() => initState
|
|
169
169
|
);
|
|
170
170
|
return (0, import_react.useMemo)(() => {
|
|
171
|
-
return new Proxy(state
|
|
171
|
+
return new Proxy(state, {
|
|
172
172
|
get(_, key) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
var _a;
|
|
174
|
+
if (typeof key === "string") {
|
|
175
|
+
(_a = internal.current).touched || (_a.touched = /* @__PURE__ */ new Set());
|
|
176
|
+
internal.current.touched.add(key);
|
|
176
177
|
}
|
|
177
178
|
return Reflect.get(state, key);
|
|
178
179
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useMedia.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useEffect, useMemo, useSyncExternalStore } from 'react'\n\nimport { getConfig } from '../config'\nimport { createProxy } from '../helpers/createProxy'\nimport { matchMedia } from '../helpers/matchMedia'\nimport {\n MediaQueries,\n MediaQueryKey,\n MediaQueryObject,\n MediaQueryState,\n TamaguiInternalConfig,\n} from '../types'\nimport { useSafeRef } from './useSafeRef'\n\nexport
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { startTransition, useEffect, useMemo, useSyncExternalStore } from 'react'\n\nimport { getConfig } from '../config'\nimport { createProxy } from '../helpers/createProxy'\nimport { matchMedia } from '../helpers/matchMedia'\nimport {\n MediaQueries,\n MediaQueryKey,\n MediaQueryObject,\n MediaQueryState,\n TamaguiInternalConfig,\n} from '../types'\nimport { useSafeRef } from './useSafeRef'\n\nexport let mediaState: MediaQueryState =\n // development only safeguard\n process.env.NODE_ENV === 'development'\n ? createProxy(\n {},\n {\n get(target, key) {\n if (\n typeof key === 'string' &&\n key[0] === '$' &&\n // dont error on $$typeof\n key[1] !== '$'\n ) {\n throw new Error(`Access mediaState should not use \"$\": ${key}`)\n }\n return Reflect.get(target, key)\n },\n }\n )\n : ({} as any)\n\nexport const mediaQueryConfig: MediaQueries = {}\nexport const getMedia = () => mediaState\nexport const mediaKeysWithAndWithout$ = new Set<string>()\n\n// for SSR capture it at time of startup\nlet initState: MediaQueryState\nexport const getInitialMediaState = () => {\n return (getConfig().disableSSR ? mediaState : initState) || {}\n}\n\nlet mediaKeysOrdered: string[]\nexport const getMediaKeyImportance = (key: string) => {\n if (process.env.NODE_ENV === 'development' && key[0] === '$') {\n throw new Error('use short key')\n }\n // + 2 because we set base usedKeys=1 in getSplitStyles and all media go above 1\n return mediaKeysOrdered.indexOf(key) + 2\n}\n\nconst dispose = new Set<Function>()\n\nexport const configureMedia = (config: TamaguiInternalConfig) => {\n const { media, mediaQueryDefaultActive } = config\n if (!media) return\n for (const key in media) {\n mediaState[key] = mediaQueryDefaultActive?.[key] || false\n mediaKeysWithAndWithout$.add(key)\n mediaKeysWithAndWithout$.add(`$${key}`)\n }\n Object.assign(mediaQueryConfig, media)\n initState = { ...mediaState }\n updateCurrentState()\n mediaKeysOrdered = Object.keys(media)\n if (config.disableSSR) {\n setupMediaListeners()\n }\n}\n\nfunction unlisten() {\n dispose.forEach((cb) => cb())\n dispose.clear()\n}\n\n/**\n * Note: This should *not* set the state on the first render!\n * Because to avoid hydration issues SSR must match the server\n * *and then* re-render with the actual media query state.\n */\nlet configuredKey = ''\nfunction setupMediaListeners() {\n // avoid setting up more than once per config\n const nextKey = JSON.stringify(mediaQueryConfig)\n if (nextKey === configuredKey) return\n configuredKey = nextKey\n\n // hmr, undo existing before re-binding\n unlisten()\n\n for (const key in mediaQueryConfig) {\n const str = mediaObjectToString(mediaQueryConfig[key])\n const getMatch = () => matchMedia(str)\n const match = getMatch()\n if (!match) {\n throw new Error('\u26A0\uFE0F No match')\n }\n // react native needs these deprecated apis for now\n match.addListener(update)\n dispose.add(() => {\n match.removeListener(update)\n })\n\n update()\n\n function update() {\n const next = !!getMatch().matches\n if (next === mediaState[key]) return\n mediaState = { ...mediaState, [key]: next }\n updateCurrentState()\n }\n }\n}\n\nexport function useMediaListeners(config: TamaguiInternalConfig) {\n if (config.disableSSR) return\n useEffect(() => {\n setupMediaListeners()\n }, [])\n}\n\nconst currentStateListeners = new Set<any>()\nlet isFlushing = false\n\nfunction updateCurrentState() {\n if (isFlushing) return\n isFlushing = true\n setTimeout(() => {\n startTransition(() => {\n currentStateListeners.forEach((cb) => cb(mediaState))\n })\n isFlushing = false\n }, 0)\n}\n\ntype MediaKeysState = {\n [key: string]: any\n}\n\ntype UseMediaState = {\n [key in MediaQueryKey]: boolean\n}\n\ntype UpdateState = {\n enabled: boolean\n keys: MediaQueryKey[]\n}\n\nconst shouldUpdate = new WeakMap<any, UpdateState>()\n\nexport function setMediaShouldUpdate(ref: any, props: UpdateState) {\n return shouldUpdate.set(ref, props)\n}\n\ntype UseMediaInternalState = {\n prev: MediaKeysState\n touched?: Set<string>\n}\n\nfunction subscribe(subscriber: any) {\n currentStateListeners.add(subscriber)\n return () => currentStateListeners.delete(subscriber)\n}\n\nexport function useMedia(uid?: any, debug?: any): UseMediaState {\n const internal = useSafeRef<UseMediaInternalState>(undefined as any)\n if (!internal.current) {\n internal.current = {\n prev: initState,\n }\n }\n const state = useSyncExternalStore<MediaQueryState>(\n subscribe,\n () => {\n const { touched, prev } = internal.current\n const componentState = uid ? shouldUpdate.get(uid) : undefined\n if (componentState?.enabled === false) {\n return prev\n }\n const testKeys =\n componentState?.keys ?? (componentState?.enabled && touched ? [...touched] : null)\n\n if (testKeys?.every((key) => mediaState[key] === prev[key])) {\n return prev\n }\n\n internal.current.prev = mediaState\n return mediaState\n },\n () => initState\n )\n\n return useMemo(() => {\n return new Proxy(state, {\n get(_, key) {\n if (typeof key === 'string') {\n internal.current.touched ||= new Set()\n internal.current.touched.add(key)\n }\n return Reflect.get(state, key)\n },\n })\n }, [state])\n}\n\n/**\n * Useful for more complex components that need access to the currently active props,\n * accounting for the currently active media queries.\n *\n * Use sparingly, it will loop props and trigger re-render on all media queries.\n *\n * */\nexport function useMediaPropsActive<A extends Object>(\n props: A\n): {\n // remove all media\n [Key in keyof A extends `$${string}` ? never : keyof A]?: A[Key]\n} {\n const media = useMedia()\n\n return useMemo(() => {\n const next = {} as A\n const importancesUsed = {}\n const propNames = Object.keys(props)\n\n for (let i = propNames.length - 1; i >= 0; i--) {\n const key = propNames[i]\n const val = props[key]\n if (key[0] === '$') {\n const mediaKey = key.slice(1)\n if (!media[mediaKey]) continue\n if (val && typeof val === 'object') {\n const subKeys = Object.keys(val)\n for (let j = subKeys.length; j--; j >= 0) {\n const subKey = subKeys[j]\n mergeMediaByImportance(next, mediaKey, subKey, val[subKey], importancesUsed)\n }\n }\n } else {\n mergeMediaByImportance(next, '', key, val, importancesUsed)\n }\n }\n\n return next\n }, [media, props])\n}\n\nexport const getMediaImportanceIfMoreImportant = (\n mediaKey: string,\n key: string,\n importancesUsed: Record<string, number>\n) => {\n const importance = getMediaKeyImportance(mediaKey)\n return !importancesUsed[key] || importance > importancesUsed[key] ? importance : null\n}\n\nexport function mergeMediaByImportance(\n onto: Record<string, any>,\n mediaKey: string,\n key: string,\n value: any,\n importancesUsed: Record<string, number>\n) {\n const importance = getMediaImportanceIfMoreImportant(mediaKey, key, importancesUsed)\n if (importance === null) {\n return false\n }\n importancesUsed[key] = importance\n onto[key] = value\n return true\n}\n\nfunction camelToHyphen(str: string) {\n return str.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`).toLowerCase()\n}\n\nexport function mediaObjectToString(query: string | MediaQueryObject) {\n if (typeof query === 'string') {\n return query\n }\n return Object.entries(query)\n .map(([feature, value]) => {\n feature = camelToHyphen(feature)\n if (typeof value === 'string') {\n return `(${feature}: ${value})`\n }\n if (typeof value === 'number' && /[height|width]$/.test(feature)) {\n value = `${value}px`\n }\n return `(${feature}: ${value})`\n })\n .join(' and ')\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0E;AAE1E,oBAA0B;AAC1B,yBAA4B;AAC5B,wBAA2B;AAQ3B,wBAA2B;AAEpB,IAAI,aAET,QAAQ,IAAI,aAAa,oBACrB;AAAA,EACE,CAAC;AAAA,EACD;AAAA,IACE,IAAI,QAAQ,KAAK;A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heme_exports = {};
|
|
20
20
|
__export(useTheme_exports, {
|
|
21
21
|
activeThemeManagers: () => activeThemeManagers,
|
|
22
|
-
|
|
23
|
-
getThemeManager: () => getThemeManager,
|
|
22
|
+
getThemeProxied: () => getThemeProxied,
|
|
24
23
|
useChangeThemeEffect: () => useChangeThemeEffect,
|
|
25
|
-
useTheme: () => useTheme
|
|
24
|
+
useTheme: () => useTheme,
|
|
25
|
+
useThemeWithState: () => useThemeWithState
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(useTheme_exports);
|
|
28
28
|
var import_constants = require("@tamagui/constants");
|
|
@@ -44,10 +44,11 @@ function getDefaultThemeProxied() {
|
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
const useTheme = (props = emptyProps) => {
|
|
47
|
+
var _a;
|
|
48
|
+
return (import_constants.isRSC ? null : (_a = useThemeWithState(props)) == null ? void 0 : _a.theme) || getDefaultThemeProxied();
|
|
49
|
+
};
|
|
50
|
+
const useThemeWithState = (props) => {
|
|
47
51
|
var _a, _b;
|
|
48
|
-
if (import_constants.isRSC) {
|
|
49
|
-
return getDefaultThemeProxied();
|
|
50
|
-
}
|
|
51
52
|
const state = (0, import_useServerHooks.useServerRef)();
|
|
52
53
|
if (import_constants.isClient && !state.current) {
|
|
53
54
|
state.current = {
|
|
@@ -55,11 +56,15 @@ const useTheme = (props = emptyProps) => {
|
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
58
|
(_a = state.current) == null ? void 0 : _a.keys.clear();
|
|
58
|
-
const
|
|
59
|
+
const changedTheme = useChangeThemeEffect(
|
|
59
60
|
props,
|
|
60
61
|
false,
|
|
61
|
-
import_constants.isClient ? () =>
|
|
62
|
+
import_constants.isClient ? () => {
|
|
63
|
+
var _a2;
|
|
64
|
+
return ((_a2 = props.shouldUpdate) == null ? void 0 : _a2.call(props)) ?? state.current.keys.size === 0;
|
|
65
|
+
} : void 0
|
|
62
66
|
);
|
|
67
|
+
const { themeManager, isNewTheme, theme, name, className } = changedTheme;
|
|
63
68
|
if (process.env.NODE_ENV === "development") {
|
|
64
69
|
if (import_constants.isWeb && isNewTheme && className === ((_b = themeManager == null ? void 0 : themeManager.parentManager) == null ? void 0 : _b.state.className)) {
|
|
65
70
|
console.error("Should always change, duplicating ThemeMananger bug", themeManager);
|
|
@@ -73,29 +78,23 @@ const useTheme = (props = emptyProps) => {
|
|
|
73
78
|
console.groupEnd();
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
|
-
if (!theme) {
|
|
81
|
+
if (!changedTheme.theme) {
|
|
77
82
|
if (process.env.NODE_ENV === "development") {
|
|
78
83
|
console.warn("No theme found", name, props, themeManager);
|
|
79
84
|
}
|
|
80
|
-
return
|
|
85
|
+
return null;
|
|
81
86
|
}
|
|
82
|
-
|
|
83
|
-
return getThemeProxied(
|
|
84
|
-
isNewTheme,
|
|
85
|
-
theme,
|
|
86
|
-
name,
|
|
87
|
-
className,
|
|
88
|
-
themeManager,
|
|
89
|
-
state
|
|
90
|
-
});
|
|
87
|
+
const proxiedTheme = (0, import_react.useMemo)(() => {
|
|
88
|
+
return getThemeProxied(changedTheme);
|
|
91
89
|
}, [theme, isNewTheme, name, className, themeManager]);
|
|
90
|
+
return {
|
|
91
|
+
...changedTheme,
|
|
92
|
+
theme: proxiedTheme
|
|
93
|
+
};
|
|
92
94
|
};
|
|
93
95
|
function getThemeProxied({
|
|
94
96
|
theme,
|
|
95
|
-
name,
|
|
96
|
-
className,
|
|
97
97
|
themeManager,
|
|
98
|
-
isNewTheme,
|
|
99
98
|
state
|
|
100
99
|
}) {
|
|
101
100
|
return (0, import_createProxy.createProxy)(theme, {
|
|
@@ -110,21 +109,12 @@ function getThemeProxied({
|
|
|
110
109
|
get(_, key) {
|
|
111
110
|
if (key === import_getThemeUnwrapped.GetThemeUnwrapped) {
|
|
112
111
|
return theme;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
} else if (key === GetIsNewTheme) {
|
|
116
|
-
return isNewTheme;
|
|
117
|
-
} else if (key === "name") {
|
|
118
|
-
return name;
|
|
119
|
-
} else if (key === "className") {
|
|
120
|
-
return className;
|
|
121
|
-
} else if (!name || key === "__proto__" || typeof key === "symbol" || key === "$typeof") {
|
|
112
|
+
}
|
|
113
|
+
if (key === "undefined" || key === "__proto__" || key === "$typeof" || typeof key !== "string" || !themeManager) {
|
|
122
114
|
return Reflect.get(_, key);
|
|
123
115
|
}
|
|
124
|
-
if (key[0] === "$")
|
|
116
|
+
if (key[0] === "$") {
|
|
125
117
|
key = key.slice(1);
|
|
126
|
-
if (!themeManager) {
|
|
127
|
-
return theme[key];
|
|
128
118
|
}
|
|
129
119
|
const val = themeManager.getValue(key);
|
|
130
120
|
if (val && state) {
|
|
@@ -143,10 +133,6 @@ function getThemeProxied({
|
|
|
143
133
|
}
|
|
144
134
|
});
|
|
145
135
|
}
|
|
146
|
-
const GetThemeManager = Symbol();
|
|
147
|
-
const GetIsNewTheme = Symbol();
|
|
148
|
-
const getThemeManager = (theme) => theme == null ? void 0 : theme[GetThemeManager];
|
|
149
|
-
const getThemeIsNewTheme = (theme) => theme == null ? void 0 : theme[GetIsNewTheme];
|
|
150
136
|
const activeThemeManagers = /* @__PURE__ */ new Set();
|
|
151
137
|
const useChangeThemeEffect = (props, root = false, disableUpdate) => {
|
|
152
138
|
if (import_constants.isRSC) {
|
|
@@ -162,7 +148,7 @@ const useChangeThemeEffect = (props, root = false, disableUpdate) => {
|
|
|
162
148
|
} = props;
|
|
163
149
|
if (disable) {
|
|
164
150
|
if (!parentManager)
|
|
165
|
-
throw
|
|
151
|
+
throw `\u274C`;
|
|
166
152
|
return {
|
|
167
153
|
...parentManager.state,
|
|
168
154
|
isNewTheme: false,
|
|
@@ -238,9 +224,9 @@ const useChangeThemeEffect = (props, root = false, disableUpdate) => {
|
|
|
238
224
|
// Annotate the CommonJS export names for ESM import in node:
|
|
239
225
|
0 && (module.exports = {
|
|
240
226
|
activeThemeManagers,
|
|
241
|
-
|
|
242
|
-
getThemeManager,
|
|
227
|
+
getThemeProxied,
|
|
243
228
|
useChangeThemeEffect,
|
|
244
|
-
useTheme
|
|
229
|
+
useTheme,
|
|
230
|
+
useThemeWithState
|
|
245
231
|
});
|
|
246
232
|
//# sourceMappingURL=useTheme.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useTheme.tsx"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable no-console */\nimport { isClient, isRSC, isServer, isWeb } from '@tamagui/constants'\nimport { useContext, useEffect, useMemo, useState } from 'react'\n\nimport { getConfig } from '../config'\nimport { isDevTools } from '../constants/isDevTools'\nimport { createProxy } from '../helpers/createProxy'\nimport {\n ThemeManager,\n ThemeManagerState,\n hasNoThemeUpdatingProps,\n} from '../helpers/ThemeManager'\nimport { ThemeManagerContext } from '../helpers/ThemeManagerContext'\nimport { ThemeParsed, ThemeProps } from '../types'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped'\nimport { useServerRef } from './useServerHooks'\n\nexport type ChangedThemeResponse = {\n themeManager: ThemeManager | null\n name: string\n isNewTheme?: boolean\n theme?: ThemeParsed | null\n className?: string\n}\n\nconst emptyProps = { name: null }\n\nfunction getDefaultThemeProxied() {\n const config = getConfig()\n const name = Object.keys(config.themes)[0]\n return getThemeProxied({\n theme: config.themes[name],\n name,\n })\n}\n\ninterface UseThemeState {\n keys: Set<string>\n}\n\nexport const useTheme = (props: ThemeProps = emptyProps): ThemeParsed => {\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAiD;AACjD,mBAAyD;AAEzD,oBAA0B;AAC1B,wBAA2B;AAC3B,yBAA4B;AAC5B,0BAIO;AACP,iCAAoC;AAEpC,+BAAkC;AAClC,4BAA6B;AAU7B,MAAM,aAAa,EAAE,MAAM,KAAK;AAEhC,SAAS,yBAAyB;AAChC,QAAM,aAAS,yBAAU;AACzB,QAAM,OAAO,OAAO,KAAK,OAAO,MAAM,EAAE;AACxC,SAAO,gBAAgB;AAAA,IACrB,OAAO,OAAO,OAAO;AAAA,IACrB;AAAA,EACF,CAAC;AACH;AAMO,MAAM,WAAW,CAAC,QAAoB,eAA4B;AAxCzE;AAyCE,
|
|
6
|
-
"names": ["_", "isNewTheme", "mounted"]
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-console */\nimport { isClient, isRSC, isServer, isWeb } from '@tamagui/constants'\nimport { useContext, useEffect, useMemo, useState } from 'react'\n\nimport { getConfig } from '../config'\nimport { isDevTools } from '../constants/isDevTools'\nimport { createProxy } from '../helpers/createProxy'\nimport {\n ThemeManager,\n ThemeManagerState,\n hasNoThemeUpdatingProps,\n} from '../helpers/ThemeManager'\nimport { ThemeManagerContext } from '../helpers/ThemeManagerContext'\nimport { ThemeParsed, ThemeProps } from '../types'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped'\nimport { useServerRef } from './useServerHooks'\n\nexport type ChangedThemeResponse = {\n themeManager: ThemeManager | null\n name: string\n isNewTheme?: boolean\n theme?: ThemeParsed | null\n className?: string\n}\n\nconst emptyProps = { name: null }\n\nfunction getDefaultThemeProxied() {\n const config = getConfig()\n const name = Object.keys(config.themes)[0]\n return getThemeProxied({\n theme: config.themes[name],\n name,\n })\n}\n\ninterface UseThemeState {\n keys: Set<string>\n}\n\nexport const useTheme = (props: ThemeProps = emptyProps): ThemeParsed => {\n return (isRSC ? null : useThemeWithState(props)?.theme) || getDefaultThemeProxied()\n}\n\nexport const useThemeWithState = (props: ThemeProps) => {\n const state = useServerRef() as React.MutableRefObject<UseThemeState>\n if (isClient && !state.current) {\n state.current = {\n keys: new Set(),\n }\n }\n\n // clear at start of every render to track usages\n state.current?.keys.clear()\n\n const changedTheme = useChangeThemeEffect(\n props,\n false,\n isClient\n ? () => {\n return props.shouldUpdate?.() ?? state.current.keys.size === 0\n }\n : undefined\n )\n\n const { themeManager, isNewTheme, theme, name, className } = changedTheme\n\n if (process.env.NODE_ENV === 'development') {\n // ensure we aren't creating too many ThemeManagers\n // prettier-ignore\n if (isWeb && isNewTheme && className === themeManager?.parentManager?.state.className) {\n console.error('Should always change, duplicating ThemeMananger bug', themeManager)\n }\n if (props.debug === 'verbose') {\n console.groupCollapsed(' \uD83D\uDD39 useTheme =>', name)\n const logs = { ...props, name, className, ...(isDevTools && { theme }) }\n for (const key in logs) {\n console.log(' ', key, logs[key])\n }\n console.groupEnd()\n }\n }\n\n if (!changedTheme.theme) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('No theme found', name, props, themeManager)\n }\n return null\n }\n\n const proxiedTheme = useMemo(() => {\n return getThemeProxied(changedTheme as any)\n }, [theme, isNewTheme, name, className, themeManager])\n\n return {\n ...changedTheme,\n theme: proxiedTheme,\n }\n}\n\nexport function getThemeProxied({\n theme,\n themeManager,\n state,\n}: Partial<ChangedThemeResponse> & {\n theme: ThemeParsed\n state?: React.RefObject<UseThemeState>\n}) {\n return createProxy(theme, {\n has(_, key) {\n if (typeof key === 'string') {\n if (key[0] === '$') key = key.slice(1)\n return themeManager?.allKeys.has(key)\n }\n return Reflect.has(theme, key)\n },\n get(_, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n }\n if (\n key === 'undefined' ||\n key === '__proto__' ||\n key === '$typeof' ||\n typeof key !== 'string' ||\n !themeManager\n ) {\n return Reflect.get(_, key)\n }\n // auto convert variables to plain\n if (key[0] === '$') {\n key = key.slice(1)\n }\n const val = themeManager.getValue(key)\n if (val && state) {\n if (isClient) {\n return new Proxy(val as any, {\n get(_, subkey) {\n if (subkey === 'val') {\n state.current!.keys.add(key as any)\n }\n return Reflect.get(val as any, subkey)\n },\n })\n }\n }\n return val\n },\n })\n}\n\nexport const activeThemeManagers = new Set<ThemeManager>()\n\nexport const useChangeThemeEffect = (\n props: ThemeProps,\n root = false,\n disableUpdate?: () => boolean\n): ChangedThemeResponse => {\n if (isRSC) {\n // we need context working for this to work well\n return {\n ...createState().state,\n themeManager: null,\n }\n }\n const parentManager = useContext(ThemeManagerContext)\n\n const {\n debug,\n // @ts-expect-error internal use only\n disable,\n } = props\n\n if (disable) {\n if (!parentManager) throw `\u274C`\n return {\n ...parentManager.state,\n isNewTheme: false,\n themeManager: parentManager,\n }\n }\n\n type State = {\n isNewTheme: boolean\n state: ThemeManagerState\n themeManager: ThemeManager\n mounted?: boolean\n }\n\n const [themeState, setThemeState] = useState<State>(createState)\n const { isNewTheme, state, themeManager, mounted } = themeState\n\n if (!isServer) {\n useEffect(() => {\n if (disable) return\n // SSR safe inverse (because server can't know prefers scheme)\n // could be done through fancy selectors like how we do prefers-media\n // but may be a bit of explosion of selectors\n if (props.inverse && !mounted) {\n setThemeState({ ...themeState, mounted: true })\n return\n }\n activeThemeManagers.add(themeManager)\n // const disposeChangeListener = parentManager?.onChangeTheme((name, manager) => {\n // // console.log('hi', props, state, name, manager)\n // if (state.theme !== manager.state.theme) {\n // console.warn('now update to', manager.state.name)\n // updateState(manager)\n // }\n // })\n return () => {\n activeThemeManagers.delete(themeManager)\n // disposeChangeListener?.()\n }\n }, [disable, state, isNewTheme, debug])\n }\n\n const isInversingOnMount = Boolean(!themeState.mounted && props.inverse)\n const shouldReturnParentState = hasNoThemeUpdatingProps(props) || isInversingOnMount\n\n if (shouldReturnParentState) {\n if (!parentManager) throw 'impossible'\n // prettier-ignore\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') console.log('useTheme hasNoThemeUpdatingProps', parentManager.state.name, 'isInversingOnMount', isInversingOnMount)\n return {\n ...parentManager.state,\n className: isInversingOnMount ? '' : parentManager.state.className,\n themeManager: parentManager,\n isNewTheme: false,\n }\n }\n\n // run inline in render\n updateState()\n\n return {\n ...state,\n isNewTheme,\n themeManager,\n }\n\n function createState(prev?: State) {\n if (prev && disableUpdate?.()) {\n return prev\n }\n // returns previous theme manager if no change\n const _ = new ThemeManager(props, root ? 'root' : parentManager)\n const isNewTheme = _ !== parentManager\n // prettier-ignore\n\n // if (prev?.isNewTheme && _.state.theme !== parentManager?.state.theme) {\n // console.warn('notify')\n // _.notify()\n // }\n\n // only inverse relies on this for ssr\n const mounted = !props.inverse ? true : root || prev?.mounted\n return {\n // ThemeManager returns parentManager if no change\n isNewTheme,\n state: { ..._.state },\n themeManager: _,\n mounted,\n }\n }\n\n function updateState(updatingManager?: ThemeManager) {\n if (disableUpdate?.()) {\n return\n }\n const manager = updatingManager ?? themeManager\n const next = manager.getState(props, parentManager)\n const shouldChange = manager.getStateShouldChange(next, isNewTheme ? state : null)\n // console.log(`got it`, next, isNewTheme, shouldChange, { ...updatingManager?.state })\n if (shouldChange) {\n setThemeState(createState)\n } else {\n if (!next && parentManager?.state.name !== state.name) {\n // were changing back to parent state\n setThemeState(createState)\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAiD;AACjD,mBAAyD;AAEzD,oBAA0B;AAC1B,wBAA2B;AAC3B,yBAA4B;AAC5B,0BAIO;AACP,iCAAoC;AAEpC,+BAAkC;AAClC,4BAA6B;AAU7B,MAAM,aAAa,EAAE,MAAM,KAAK;AAEhC,SAAS,yBAAyB;AAChC,QAAM,aAAS,yBAAU;AACzB,QAAM,OAAO,OAAO,KAAK,OAAO,MAAM,EAAE;AACxC,SAAO,gBAAgB;AAAA,IACrB,OAAO,OAAO,OAAO;AAAA,IACrB;AAAA,EACF,CAAC;AACH;AAMO,MAAM,WAAW,CAAC,QAAoB,eAA4B;AAxCzE;AAyCE,UAAQ,yBAAQ,QAAO,uBAAkB,KAAK,MAAvB,mBAA0B,UAAU,uBAAuB;AACpF;AAEO,MAAM,oBAAoB,CAAC,UAAsB;AA5CxD;AA6CE,QAAM,YAAQ,oCAAa;AAC3B,MAAI,6BAAY,CAAC,MAAM,SAAS;AAC9B,UAAM,UAAU;AAAA,MACd,MAAM,oBAAI,IAAI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A,UAAM,UAAU,mBAAmB;AACnC,UAAM,OAAO,QAAQ,SAAS,OAAO,aAAa;AAClD,UAAM,eAAe,QAAQ,qBAAqB,MAAM,aAAa,QAAQ,IAAI;AAEjF,QAAI,cAAc;AAChB,oBAAc,WAAW;AAAA,IAC3B,OAAO;AACL,UAAI,CAAC,SAAQ,+CAAe,MAAM,UAAS,MAAM,MAAM;AAErD,sBAAc,WAAW;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["_a", "_", "isNewTheme", "mounted"]
|
|
7
7
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -53,7 +53,6 @@ __reExport(src_exports, require("./helpers/useShallowSetState"), module.exports)
|
|
|
53
53
|
__reExport(src_exports, require("./helpers/getVariantExtras"), module.exports);
|
|
54
54
|
__reExport(src_exports, require("./helpers/getAnimationDriver"), module.exports);
|
|
55
55
|
__reExport(src_exports, require("./helpers/getExpandedShorthands"), module.exports);
|
|
56
|
-
__reExport(src_exports, require("./helpers/getSize"), module.exports);
|
|
57
56
|
__reExport(src_exports, require("./helpers/getSplitStyles"), module.exports);
|
|
58
57
|
__reExport(src_exports, require("./helpers/getStylesAtomic"), module.exports);
|
|
59
58
|
__reExport(src_exports, require("./helpers/pseudoDescriptors"), module.exports);
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './Tamagui'\nexport * from './createComponent'\nexport * from './createShorthands'\nexport * from './createTheme'\nexport * from './createTamagui'\nexport * from './createFont'\nexport * from './createTokens'\nexport * from './createVariable'\nexport * from './createVariables'\nexport * from './insertFont'\nexport * from './addTheme'\nexport * from './updateTheme'\nexport * from './styled'\nexport * from './types'\nexport * from './setupReactNative'\n\n// for type portability\nexport type { RNWTextProps, RNWViewProps } from './types-rnw'\nexport { getConfig, getThemes, getTokens, onConfiguredOnce } from './config'\n\nexport * from './constants/constants'\n\nexport * from './helpers/useShallowSetState'\nexport * from './helpers/getVariantExtras'\nexport * from './helpers/getAnimationDriver'\nexport * from './helpers/getExpandedShorthands'\nexport * from './helpers/
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,sBAAd;AACA,wBAAc,8BADd;AAEA,wBAAc,+BAFd;AAGA,wBAAc,0BAHd;AAIA,wBAAc,4BAJd;AAKA,wBAAc,yBALd;AAMA,wBAAc,2BANd;AAOA,wBAAc,6BAPd;AAQA,wBAAc,8BARd;AASA,wBAAc,yBATd;AAUA,wBAAc,uBAVd;AAWA,wBAAc,0BAXd;AAYA,wBAAc,qBAZd;AAaA,wBAAc,oBAbd;AAcA,wBAAc,+BAdd;AAkBA,oBAAkE;AAElE,wBAAc,kCApBd;AAsBA,wBAAc,yCAtBd;AAuBA,wBAAc,uCAvBd;AAwBA,wBAAc,yCAxBd;AAyBA,wBAAc,4CAzBd;AA0BA,wBAAc,
|
|
4
|
+
"sourcesContent": ["export * from './Tamagui'\nexport * from './createComponent'\nexport * from './createShorthands'\nexport * from './createTheme'\nexport * from './createTamagui'\nexport * from './createFont'\nexport * from './createTokens'\nexport * from './createVariable'\nexport * from './createVariables'\nexport * from './insertFont'\nexport * from './addTheme'\nexport * from './updateTheme'\nexport * from './styled'\nexport * from './types'\nexport * from './setupReactNative'\n\n// for type portability\nexport type { RNWTextProps, RNWViewProps } from './types-rnw'\nexport { getConfig, getThemes, getTokens, onConfiguredOnce } from './config'\n\nexport * from './constants/constants'\n\nexport * from './helpers/useShallowSetState'\nexport * from './helpers/getVariantExtras'\nexport * from './helpers/getAnimationDriver'\nexport * from './helpers/getExpandedShorthands'\nexport * from './helpers/getSplitStyles'\nexport * from './helpers/getStylesAtomic'\nexport * from './helpers/pseudoDescriptors'\nexport * from './helpers/mergeProps'\nexport * from './helpers/expandStyles'\nexport * from './helpers/isTamaguiElement'\nexport * from './helpers/isTamaguiComponent'\nexport * from './helpers/matchMedia'\nexport * from './helpers/themeable'\nexport * from './helpers/withStaticProperties'\n\nexport * from './contexts/ButtonNestingContext'\n\nexport * from './hooks/useId'\nexport * from './hooks/useIsTouchDevice'\n\nexport {\n configureMedia,\n getMedia,\n mediaState,\n useMedia,\n useMediaPropsActive,\n mediaObjectToString,\n mediaQueryConfig,\n} from './hooks/useMedia'\nexport * from './hooks/useTheme'\nexport * from './hooks/useThemeName'\nexport * from './hooks/useSafeRef'\n\nexport * from './views/Slot'\nexport * from './views/Stack'\nexport * from './views/Text'\nexport * from './contexts/TextAncestorContext'\nexport * from './views/Theme'\nexport * from './views/ThemeProvider'\nexport * from './views/FontLanguage'\nexport * from './views/TamaguiProvider'\n\nexport * from '@tamagui/use-force-update'\nexport * from '@tamagui/use-did-finish-ssr'\nexport * from '@tamagui/use-event'\nexport * from '@tamagui/compose-refs'\nexport * from '@tamagui/helpers'\nexport * from '@tamagui/constants'\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,sBAAd;AACA,wBAAc,8BADd;AAEA,wBAAc,+BAFd;AAGA,wBAAc,0BAHd;AAIA,wBAAc,4BAJd;AAKA,wBAAc,yBALd;AAMA,wBAAc,2BANd;AAOA,wBAAc,6BAPd;AAQA,wBAAc,8BARd;AASA,wBAAc,yBATd;AAUA,wBAAc,uBAVd;AAWA,wBAAc,0BAXd;AAYA,wBAAc,qBAZd;AAaA,wBAAc,oBAbd;AAcA,wBAAc,+BAdd;AAkBA,oBAAkE;AAElE,wBAAc,kCApBd;AAsBA,wBAAc,yCAtBd;AAuBA,wBAAc,uCAvBd;AAwBA,wBAAc,yCAxBd;AAyBA,wBAAc,4CAzBd;AA0BA,wBAAc,qCA1Bd;AA2BA,wBAAc,sCA3Bd;AA4BA,wBAAc,wCA5Bd;AA6BA,wBAAc,iCA7Bd;AA8BA,wBAAc,mCA9Bd;AA+BA,wBAAc,uCA/Bd;AAgCA,wBAAc,yCAhCd;AAiCA,wBAAc,iCAjCd;AAkCA,wBAAc,gCAlCd;AAmCA,wBAAc,2CAnCd;AAqCA,wBAAc,4CArCd;AAuCA,wBAAc,0BAvCd;AAwCA,wBAAc,qCAxCd;AA0CA,sBAQO;AACP,wBAAc,6BAnDd;AAoDA,wBAAc,iCApDd;AAqDA,wBAAc,+BArDd;AAuDA,wBAAc,yBAvDd;AAwDA,wBAAc,0BAxDd;AAyDA,wBAAc,yBAzDd;AA0DA,wBAAc,2CA1Dd;AA2DA,wBAAc,0BA3Dd;AA4DA,wBAAc,kCA5Dd;AA6DA,wBAAc,iCA7Dd;AA8DA,wBAAc,oCA9Dd;AAgEA,wBAAc,sCAhEd;AAiEA,wBAAc,wCAjEd;AAkEA,wBAAc,+BAlEd;AAmEA,wBAAc,kCAnEd;AAoEA,wBAAc,6BApEd;AAqEA,wBAAc,+BArEd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/styled.js
CHANGED
|
@@ -25,7 +25,10 @@ var import_helpers = require("@tamagui/helpers");
|
|
|
25
25
|
var import_createComponent = require("./createComponent");
|
|
26
26
|
var import_setupReactNative = require("./setupReactNative");
|
|
27
27
|
function styled(Component, options, staticExtractionOptions) {
|
|
28
|
-
if (process.env.NODE_ENV
|
|
28
|
+
if (process.env.NODE_ENV !== "production") {
|
|
29
|
+
if (!Component) {
|
|
30
|
+
throw new Error(`No component given to styled()`);
|
|
31
|
+
}
|
|
29
32
|
if (options == null ? void 0 : options.variants) {
|
|
30
33
|
for (const key in options.variants) {
|
|
31
34
|
if (key in import_helpers.stylePropsAll) {
|
package/dist/cjs/styled.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/styled.tsx"],
|
|
4
|
-
"sourcesContent": ["import { stylePropsAll } from '@tamagui/helpers'\n\nimport { createComponent } from './createComponent'\nimport { ReactNativeStaticConfigs } from './setupReactNative'\nimport {\n GetProps,\n GetVariantValues,\n MediaProps,\n PseudoProps,\n StaticConfig,\n StylableComponent,\n TamaguiComponent,\n TamaguiElement,\n VariantDefinitions,\n VariantSpreadFunction,\n} from './types'\n\n// TODO may be able to use this in the options?: arg below directly\nexport type StyledOptions<ParentComponent extends StylableComponent> =\n GetProps<ParentComponent> & {\n name?: string\n variants?: VariantDefinitions<ParentComponent> | undefined\n defaultVariants?: { [key: string]: any }\n }\n\n// can't infer from styled(<YStack />) which would be nice\n// * excessively deep type instantiation\n\ntype GetBaseProps<A extends StylableComponent> =\n // A extends TamaguiReactElement\n // ? GetBaseProps<A['type']> :\n A extends TamaguiComponent<any, any, infer P> ? P : GetProps<A>\n\ntype GetVariantProps<A extends StylableComponent> =\n // A extends TamaguiReactElement\n // ? GetVariantProps<A['type']>\n // :\n A extends TamaguiComponent<any, any, any, infer V> ? V : {}\n\nexport function styled<\n ParentComponent extends StylableComponent,\n Variants extends VariantDefinitions<ParentComponent> | void = VariantDefinitions<ParentComponent> | void\n>(\n Component: ParentComponent,\n // this should be Partial<GetProps<ParentComponent>> but causes excessively deep type issues\n options?: GetProps<ParentComponent> & {\n name?: string\n variants?: Variants | undefined\n // thought i had this typed, but can't get it linked\n defaultVariants?: { [key: string]: any }\n acceptsClassName?: boolean\n },\n staticExtractionOptions?: Partial<StaticConfig>\n) {\n // allows passing styled(<H1 bc=\"red\" />)\n // but to get types right would be tricky\n // if (isValidElement(Component) && isTamaguiComponent(Component.type)) {\n // const props = Component.props\n // if (props && typeof props === 'object') {\n // Component = Component.type as any\n // options = options ? ({ ...props, ...options } as any) : props\n // }\n // }\n\n // validate not using a variant over an existing valid style\n if (process.env.NODE_ENV
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA8B;AAE9B,6BAAgC;AAChC,8BAAyC;AAoClC,SAAS,OAId,WAEA,SAOA,yBACA;AAYA,MAAI,QAAQ,IAAI,aAAa,
|
|
4
|
+
"sourcesContent": ["import { stylePropsAll } from '@tamagui/helpers'\n\nimport { createComponent } from './createComponent'\nimport { ReactNativeStaticConfigs } from './setupReactNative'\nimport {\n GetProps,\n GetVariantValues,\n MediaProps,\n PseudoProps,\n StaticConfig,\n StylableComponent,\n TamaguiComponent,\n TamaguiElement,\n VariantDefinitions,\n VariantSpreadFunction,\n} from './types'\n\n// TODO may be able to use this in the options?: arg below directly\nexport type StyledOptions<ParentComponent extends StylableComponent> =\n GetProps<ParentComponent> & {\n name?: string\n variants?: VariantDefinitions<ParentComponent> | undefined\n defaultVariants?: { [key: string]: any }\n }\n\n// can't infer from styled(<YStack />) which would be nice\n// * excessively deep type instantiation\n\ntype GetBaseProps<A extends StylableComponent> =\n // A extends TamaguiReactElement\n // ? GetBaseProps<A['type']> :\n A extends TamaguiComponent<any, any, infer P> ? P : GetProps<A>\n\ntype GetVariantProps<A extends StylableComponent> =\n // A extends TamaguiReactElement\n // ? GetVariantProps<A['type']>\n // :\n A extends TamaguiComponent<any, any, any, infer V> ? V : {}\n\nexport function styled<\n ParentComponent extends StylableComponent,\n Variants extends VariantDefinitions<ParentComponent> | void = VariantDefinitions<ParentComponent> | void\n>(\n Component: ParentComponent,\n // this should be Partial<GetProps<ParentComponent>> but causes excessively deep type issues\n options?: GetProps<ParentComponent> & {\n name?: string\n variants?: Variants | undefined\n // thought i had this typed, but can't get it linked\n defaultVariants?: { [key: string]: any }\n acceptsClassName?: boolean\n },\n staticExtractionOptions?: Partial<StaticConfig>\n) {\n // allows passing styled(<H1 bc=\"red\" />)\n // but to get types right would be tricky\n // if (isValidElement(Component) && isTamaguiComponent(Component.type)) {\n // const props = Component.props\n // if (props && typeof props === 'object') {\n // Component = Component.type as any\n // options = options ? ({ ...props, ...options } as any) : props\n // }\n // }\n\n // validate not using a variant over an existing valid style\n if (process.env.NODE_ENV !== 'production') {\n if (!Component) {\n throw new Error(`No component given to styled()`)\n }\n if (options?.variants) {\n for (const key in options.variants) {\n if (key in stylePropsAll) {\n console.error(\n `Invalid variant key overlaps with style key: ${key}. Tamagui prevents defining variants that use valid style keys to reduce implementation complexity.`\n )\n }\n }\n }\n }\n\n const staticConfigProps = (() => {\n const parentStaticConfig =\n 'staticConfig' in Component ? (Component.staticConfig as StaticConfig) : null\n\n if (options) {\n const {\n variants,\n name,\n defaultVariants,\n acceptsClassName: acceptsClassNameProp,\n ...defaultProps\n } = options\n if (defaultVariants) {\n Object.assign(defaultProps, defaultVariants)\n }\n const isReactNative = Boolean(\n ReactNativeStaticConfigs.has(Component) ||\n ReactNativeStaticConfigs.has(parentStaticConfig?.Component) ||\n parentStaticConfig?.isReactNative ||\n staticExtractionOptions?.isReactNative\n )\n const isTamagui = !isReactNative && !!parentStaticConfig\n\n const Comp = isReactNative\n ? parentStaticConfig?.Component || Component\n : (Component as any)\n const nativeConf = (isReactNative && ReactNativeStaticConfigs.get(Comp)) || null\n\n const isText = Boolean(\n staticExtractionOptions?.isText || parentStaticConfig?.isText\n )\n const acceptsClassName = acceptsClassNameProp ?? (isTamagui || isReactNative)\n\n const conf: Partial<StaticConfig> = {\n ...staticExtractionOptions,\n ...(!isTamagui && {\n Component: Comp,\n }),\n // this type gets messed up by options?: Partial<GetProps<ParentComponent>> above\n // take away the Partial<> and it's fine\n variants,\n defaultProps,\n defaultVariants,\n componentName: name,\n isReactNative,\n isText,\n acceptsClassName,\n ...nativeConf,\n }\n\n // bail on non className views as well\n if (defaultProps.children || !acceptsClassName) {\n conf.neverFlatten = true\n }\n\n return conf\n }\n return {}\n })()\n\n const component = createComponent(staticConfigProps, Component)\n\n // get parent props without pseudos and medias so we can rebuild both with new variants\n // get parent props without pseudos and medias so we can rebuild both with new variants\n type ParentPropsBase = GetBaseProps<ParentComponent>\n type ParentVariants = GetVariantProps<ParentComponent>\n\n type OurVariants = Variants extends void\n ? {}\n : {\n [Key in keyof Variants]?: Variants[Key] extends VariantSpreadFunction<\n any,\n infer Val\n >\n ? Val\n : GetVariantValues<keyof Variants[Key]>\n }\n\n type VariantProps = Omit<ParentVariants, keyof OurVariants> & OurVariants\n type OurPropsBase = ParentPropsBase & VariantProps\n\n type Props = Variants extends void\n ? GetProps<ParentComponent>\n : // start with base props\n OurPropsBase &\n // add in media (+ pseudos nested)\n MediaProps<Partial<OurPropsBase>> &\n // add in pseudos\n PseudoProps<Partial<OurPropsBase>>\n\n type StyledComponent = TamaguiComponent<\n Props,\n TamaguiElement,\n ParentPropsBase,\n ParentVariants & OurVariants\n >\n\n return component as StyledComponent\n}\n\n// sanity check types\n// import { Stack } from './views/Stack'\n// const X = styled(Stack, {\n// variants: {\n// size: {\n// '...size': (val) => {\n// return {\n// pointerEvents: 'auto'\n// }\n// }\n// },\n// disabled: {\n// true: {\n// alignContent: 'center',\n// opacity: 0.5,\n// pointerEvents: 'none',\n// },\n// },\n// } as const\n// })\n// // type variants = GetStyledVariants<typeof X>\n// const y = <X disabled size=\"$10\" />\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA8B;AAE9B,6BAAgC;AAChC,8BAAyC;AAoClC,SAAS,OAId,WAEA,SAOA,yBACA;AAYA,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,MAAM,gCAAgC;AAAA,IAClD;AACA,QAAI,mCAAS,UAAU;AACrB,iBAAW,OAAO,QAAQ,UAAU;AAClC,YAAI,OAAO,8BAAe;AACxB,kBAAQ;AAAA,YACN,gDAAgD;AAAA,UAClD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,qBAAqB,MAAM;AAC/B,UAAM,qBACJ,kBAAkB,YAAa,UAAU,eAAgC;AA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