@tamagui/core 1.0.1-beta.135 → 1.0.1-beta.138
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/addTheme.js +74 -0
- package/dist/cjs/addTheme.js.map +7 -0
- package/dist/cjs/contexts/TextAncestorContext.js +44 -0
- package/dist/cjs/contexts/TextAncestorContext.js.map +7 -0
- package/dist/cjs/contexts/ThemeContext.js +30 -0
- package/dist/cjs/contexts/ThemeContext.js.map +7 -0
- package/dist/cjs/createComponent.js +2 -2
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/createTamagui.js +18 -118
- package/dist/cjs/createTamagui.js.map +2 -2
- package/dist/cjs/createTheme.js +2 -5
- package/dist/cjs/createTheme.js.map +2 -2
- package/dist/cjs/ensureThemeVariable.js +152 -0
- package/dist/cjs/ensureThemeVariable.js.map +7 -0
- package/dist/cjs/helpers/ThemeManager.js +209 -0
- package/dist/cjs/helpers/ThemeManager.js.map +7 -0
- package/dist/cjs/helpers/createTamaguiProvider.js +1 -1
- package/dist/cjs/helpers/createTamaguiProvider.js.map +2 -2
- package/dist/cjs/helpers/ensureThemeVariable.js +152 -0
- package/dist/cjs/helpers/ensureThemeVariable.js.map +7 -0
- package/dist/cjs/helpers/getThemeCSSRules.js +98 -0
- package/dist/cjs/helpers/getThemeCSSRules.js.map +7 -0
- package/dist/cjs/helpers/getThemeCSSRules.native.js +31 -0
- package/dist/cjs/helpers/getThemeCSSRules.native.js.map +7 -0
- package/dist/cjs/helpers/themes.js +79 -0
- package/dist/cjs/helpers/themes.js.map +7 -0
- package/dist/cjs/hooks/useTheme.js +20 -11
- package/dist/cjs/hooks/useTheme.js.map +2 -2
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/loadTheme.js +64 -0
- package/dist/cjs/loadTheme.js.map +7 -0
- package/dist/cjs/updateTheme.js +44 -0
- package/dist/cjs/updateTheme.js.map +7 -0
- package/dist/cjs/vendor/Pressability.js +32 -0
- package/dist/cjs/vendor/Pressability.js.map +7 -0
- package/dist/cjs/vendor/Pressability.native.js +32 -0
- package/dist/cjs/vendor/Pressability.native.js.map +7 -0
- package/dist/cjs/views/Theme.js +1 -1
- package/dist/cjs/views/Theme.js.map +2 -2
- package/dist/cjs/views/ThemeInverse.js +8 -12
- package/dist/cjs/views/ThemeInverse.js.map +2 -2
- package/dist/cjs/views/ThemeProvider.js +1 -1
- package/dist/cjs/views/ThemeProvider.js.map +1 -1
- package/dist/cjs/views/ThemeReset.js +1 -1
- package/dist/cjs/views/ThemeReset.js.map +1 -1
- package/dist/esm/addTheme.js +50 -0
- package/dist/esm/addTheme.js.map +7 -0
- package/dist/esm/contexts/TextAncestorContext.js +15 -0
- package/dist/esm/contexts/TextAncestorContext.js.map +7 -0
- package/dist/esm/contexts/ThemeContext.js +6 -0
- package/dist/esm/contexts/ThemeContext.js.map +7 -0
- package/dist/esm/createComponent.js +2 -2
- package/dist/esm/createComponent.js.map +1 -1
- package/dist/esm/createTamagui.js +17 -117
- package/dist/esm/createTamagui.js.map +2 -2
- package/dist/esm/createTheme.js +1 -3
- package/dist/esm/createTheme.js.map +2 -2
- package/dist/esm/ensureThemeVariable.js +125 -0
- package/dist/esm/ensureThemeVariable.js.map +7 -0
- package/dist/esm/helpers/ThemeManager.js +183 -0
- package/dist/esm/helpers/ThemeManager.js.map +7 -0
- package/dist/esm/helpers/createTamaguiProvider.js +1 -1
- package/dist/esm/helpers/createTamaguiProvider.js.map +2 -2
- package/dist/esm/helpers/ensureThemeVariable.js +125 -0
- package/dist/esm/helpers/ensureThemeVariable.js.map +7 -0
- package/dist/esm/helpers/getThemeCSSRules.js +74 -0
- package/dist/esm/helpers/getThemeCSSRules.js.map +7 -0
- package/dist/esm/helpers/getThemeCSSRules.native.js +7 -0
- package/dist/esm/helpers/getThemeCSSRules.native.js.map +7 -0
- package/dist/esm/helpers/themes.js +54 -0
- package/dist/esm/helpers/themes.js.map +7 -0
- package/dist/esm/hooks/useTheme.js +23 -11
- package/dist/esm/hooks/useTheme.js.map +2 -2
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/loadTheme.js +40 -0
- package/dist/esm/loadTheme.js.map +7 -0
- package/dist/esm/updateTheme.js +20 -0
- package/dist/esm/updateTheme.js.map +7 -0
- package/dist/esm/vendor/Pressability.js +7 -0
- package/dist/esm/vendor/Pressability.js.map +7 -0
- package/dist/esm/vendor/Pressability.native.js +7 -0
- package/dist/esm/vendor/Pressability.native.js.map +7 -0
- package/dist/esm/views/Theme.js +1 -1
- package/dist/esm/views/Theme.js.map +1 -1
- package/dist/esm/views/ThemeInverse.js +7 -10
- package/dist/esm/views/ThemeInverse.js.map +2 -2
- package/dist/esm/views/ThemeProvider.js +1 -1
- package/dist/esm/views/ThemeProvider.js.map +1 -1
- package/dist/esm/views/ThemeReset.js +1 -1
- package/dist/esm/views/ThemeReset.js.map +1 -1
- package/package.json +8 -8
- package/types/addTheme.d.ts +11 -0
- package/types/{views → contexts}/TextAncestorContext.d.ts +0 -0
- package/types/{ThemeContext.d.ts → contexts/ThemeContext.d.ts} +1 -1
- package/types/createTheme.d.ts +0 -1
- package/types/{ThemeManager.d.ts → helpers/ThemeManager.d.ts} +5 -5
- package/types/helpers/createTamaguiProvider.d.ts +1 -0
- package/types/helpers/getThemeCSSRules.d.ts +8 -0
- package/types/helpers/getThemeCSSRules.native.d.ts +2 -0
- package/types/helpers/themes.d.ts +4 -0
- package/types/hooks/useTheme.d.ts +2 -1
- package/types/index.d.ts +3 -1
- package/types/updateTheme.d.ts +9 -0
- package/types/{Pressability.d.ts → vendor/Pressability.d.ts} +0 -0
- package/types/{Pressability.native.d.ts → vendor/Pressability.native.d.ts} +0 -0
- package/types/views/FontLanguage.d.ts +1 -0
- package/types/views/FontLanguage.native.d.ts +1 -0
- package/types/views/Theme.d.ts +1 -1
- package/types/views/ThemeInverse.d.ts +0 -5
- package/types/views/ThemeProvider.d.ts +1 -0
- package/types/defaultComponentState.d.ts +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/views/ThemeProvider.tsx"],
|
|
4
|
-
"sourcesContent": ["import React, { useLayoutEffect, useMemo } from 'react'\n\nimport { getHasConfigured } from '../conf'\nimport { THEME_CLASSNAME_PREFIX } from '../constants/constants'\nimport { ThemeContext } from '../ThemeContext'\nimport { Theme } from './Theme'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\nexport type ThemeProviderProps = {\n className?: string\n themes: any\n defaultTheme: string\n disableRootThemeClass?: boolean\n themeClassNameOnRoot?: boolean\n children?: any\n reset?: boolean\n}\n\nexport const ThemeProvider = (props: ThemeProviderProps) => {\n if (!getHasConfigured()) {\n throw new Error(`Missing configureThemes() call, add to your root file`)\n }\n\n // ensure theme is attached to root body node as well to work with modals by default\n if (typeof document !== 'undefined') {\n useLayoutEffect(() => {\n if (props.disableRootThemeClass) {\n return\n }\n const cn = `${THEME_CLASSNAME_PREFIX}${props.defaultTheme}`\n const target = props.themeClassNameOnRoot ? document.documentElement : document.body\n target.classList.add(cn)\n return () => {\n target.classList.remove(cn)\n }\n }, [props.defaultTheme, props.disableRootThemeClass])\n }\n\n const themeContext = useMemo(() => {\n return {\n themes: props.themes,\n defaultTheme: props.defaultTheme,\n }\n }, [props.themes])\n\n return (\n <ThemeContext.Provider value={themeContext}>\n <Theme\n className={props.className}\n name={props.defaultTheme}\n disableThemeClass={props.disableRootThemeClass}\n >\n {props.children}\n </Theme>\n </ThemeContext.Provider>\n )\n}\n"],
|
|
4
|
+
"sourcesContent": ["import React, { useLayoutEffect, useMemo } from 'react'\n\nimport { getHasConfigured } from '../conf'\nimport { THEME_CLASSNAME_PREFIX } from '../constants/constants'\nimport { ThemeContext } from '../contexts/ThemeContext'\nimport { Theme } from './Theme'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\nexport type ThemeProviderProps = {\n className?: string\n themes: any\n defaultTheme: string\n disableRootThemeClass?: boolean\n themeClassNameOnRoot?: boolean\n children?: any\n reset?: boolean\n}\n\nexport const ThemeProvider = (props: ThemeProviderProps) => {\n if (!getHasConfigured()) {\n throw new Error(`Missing configureThemes() call, add to your root file`)\n }\n\n // ensure theme is attached to root body node as well to work with modals by default\n if (typeof document !== 'undefined') {\n useLayoutEffect(() => {\n if (props.disableRootThemeClass) {\n return\n }\n const cn = `${THEME_CLASSNAME_PREFIX}${props.defaultTheme}`\n const target = props.themeClassNameOnRoot ? document.documentElement : document.body\n target.classList.add(cn)\n return () => {\n target.classList.remove(cn)\n }\n }, [props.defaultTheme, props.disableRootThemeClass])\n }\n\n const themeContext = useMemo(() => {\n return {\n themes: props.themes,\n defaultTheme: props.defaultTheme,\n }\n }, [props.themes])\n\n return (\n <ThemeContext.Provider value={themeContext}>\n <Theme\n className={props.className}\n name={props.defaultTheme}\n disableThemeClass={props.disableRootThemeClass}\n >\n {props.children}\n </Theme>\n </ThemeContext.Provider>\n )\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgD;AAEhD,kBAAiC;AACjC,uBAAuC;AACvC,0BAA6B;AAC7B,mBAAsB;AAGtB,qBAAM;AAYC,MAAM,gBAAgB,CAAC,UAA8B;AAC1D,MAAI,CAAC,kCAAiB,GAAG;AACvB,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAGA,MAAI,OAAO,aAAa,aAAa;AACnC,sCAAgB,MAAM;AACpB,UAAI,MAAM,uBAAuB;AAC/B;AAAA,MACF;AACA,YAAM,KAAK,GAAG,0CAAyB,MAAM;AAC7C,YAAM,SAAS,MAAM,uBAAuB,SAAS,kBAAkB,SAAS;AAChF,aAAO,UAAU,IAAI,EAAE;AACvB,aAAO,MAAM;AACX,eAAO,UAAU,OAAO,EAAE;AAAA,MAC5B;AAAA,IACF,GAAG,CAAC,MAAM,cAAc,MAAM,qBAAqB,CAAC;AAAA,EACtD;AAEA,QAAM,eAAe,0BAAQ,MAAM;AACjC,WAAO;AAAA,MACL,QAAQ,MAAM;AAAA,MACd,cAAc,MAAM;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,MAAM,MAAM,CAAC;AAEjB,SACE,mDAAC,iCAAa,UAAb;AAAA,IAAsB,OAAO;AAAA,KAC5B,mDAAC;AAAA,IACC,WAAW,MAAM;AAAA,IACjB,MAAM,MAAM;AAAA,IACZ,mBAAmB,MAAM;AAAA,KAExB,MAAM,QACT,CACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -26,7 +26,7 @@ __export(ThemeReset_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(ThemeReset_exports);
|
|
27
27
|
var import_react = __toESM(require("react"));
|
|
28
28
|
var import_platform = require("../constants/platform");
|
|
29
|
-
var import_ThemeManager = require("../ThemeManager");
|
|
29
|
+
var import_ThemeManager = require("../helpers/ThemeManager");
|
|
30
30
|
var import_Theme = require("./Theme");
|
|
31
31
|
import_react.default["createElement"];
|
|
32
32
|
const ThemeReset = (props) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/views/ThemeReset.tsx"],
|
|
4
|
-
"sourcesContent": ["import React, { useContext, useLayoutEffect, useState } from 'react'\n\nimport { isWeb } from '../constants/platform'\nimport { ThemeManagerContext } from '../ThemeManager'\nimport { Theme } from './Theme'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\n// resets the theme to the parent theme\nexport const ThemeReset = (props: { children?: any }) => {\n const themeManager = useContext(ThemeManagerContext)\n const [name, setName] = useState<string | null>(null)\n\n // this component doesn't work with SSR, so must run only client side\n // we could at least prevent more flickering by having the ssr head script\n // that changes to dark initially also go through and change all of these\n if (!isWeb || typeof document !== 'undefined') {\n useLayoutEffect(() => {\n if (!themeManager) return\n if (name !== themeManager.parentName) {\n setName(themeManager.parentName)\n }\n }, [themeManager?.parentName])\n\n useLayoutEffect(() => {\n if (!themeManager) return\n return themeManager.onChangeTheme(() => {\n setName(themeManager.parentName)\n })\n }, [])\n }\n\n if (!themeManager || !props.children) {\n return props.children || null\n }\n\n return (\n <Theme className=\"tui-theme-reset\" reset name={name}>\n {props.children}\n </Theme>\n )\n}\n"],
|
|
4
|
+
"sourcesContent": ["import React, { useContext, useLayoutEffect, useState } from 'react'\n\nimport { isWeb } from '../constants/platform'\nimport { ThemeManagerContext } from '../helpers/ThemeManager'\nimport { Theme } from './Theme'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\n// resets the theme to the parent theme\nexport const ThemeReset = (props: { children?: any }) => {\n const themeManager = useContext(ThemeManagerContext)\n const [name, setName] = useState<string | null>(null)\n\n // this component doesn't work with SSR, so must run only client side\n // we could at least prevent more flickering by having the ssr head script\n // that changes to dark initially also go through and change all of these\n if (!isWeb || typeof document !== 'undefined') {\n useLayoutEffect(() => {\n if (!themeManager) return\n if (name !== themeManager.parentName) {\n setName(themeManager.parentName)\n }\n }, [themeManager?.parentName])\n\n useLayoutEffect(() => {\n if (!themeManager) return\n return themeManager.onChangeTheme(() => {\n setName(themeManager.parentName)\n })\n }, [])\n }\n\n if (!themeManager || !props.children) {\n return props.children || null\n }\n\n return (\n <Theme className=\"tui-theme-reset\" reset name={name}>\n {props.children}\n </Theme>\n )\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA6D;AAE7D,sBAAsB;AACtB,0BAAoC;AACpC,mBAAsB;AAGtB,qBAAM;AAGC,MAAM,aAAa,CAAC,UAA8B;AACvD,QAAM,eAAe,6BAAW,uCAAmB;AACnD,QAAM,CAAC,MAAM,WAAW,2BAAwB,IAAI;AAKpD,MAAI,CAAC,yBAAS,OAAO,aAAa,aAAa;AAC7C,sCAAgB,MAAM;AACpB,UAAI,CAAC;AAAc;AACnB,UAAI,SAAS,aAAa,YAAY;AACpC,gBAAQ,aAAa,UAAU;AAAA,MACjC;AAAA,IACF,GAAG,CAAC,6CAAc,UAAU,CAAC;AAE7B,sCAAgB,MAAM;AACpB,UAAI,CAAC;AAAc;AACnB,aAAO,aAAa,cAAc,MAAM;AACtC,gBAAQ,aAAa,UAAU;AAAA,MACjC,CAAC;AAAA,IACH,GAAG,CAAC,CAAC;AAAA,EACP;AAEA,MAAI,CAAC,gBAAgB,CAAC,MAAM,UAAU;AACpC,WAAO,MAAM,YAAY;AAAA,EAC3B;AAEA,SACE,mDAAC;AAAA,IAAM,WAAU;AAAA,IAAkB,OAAK;AAAA,IAAC;AAAA,KACtC,MAAM,QACT;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { getConfig } from "./conf";
|
|
2
|
+
import { isWeb } from "./constants/platform";
|
|
3
|
+
import { getThemeCSSRules } from "./helpers/getThemeCSSRules";
|
|
4
|
+
import { ensureThemeVariable, proxyThemeToParents } from "./helpers/themes";
|
|
5
|
+
function addTheme({
|
|
6
|
+
name: themeName,
|
|
7
|
+
theme: themeIn,
|
|
8
|
+
insertCSS,
|
|
9
|
+
update
|
|
10
|
+
}) {
|
|
11
|
+
var _a;
|
|
12
|
+
const config = getConfig();
|
|
13
|
+
if (!config) {
|
|
14
|
+
throw new Error(`Must run createTamagui once before loading theme`);
|
|
15
|
+
}
|
|
16
|
+
if (!update && config.themes[themeName]) {
|
|
17
|
+
throw new Error(`Already defined theme "${themeName}", use updateTheme to change values`);
|
|
18
|
+
}
|
|
19
|
+
const theme = { ...themeIn };
|
|
20
|
+
for (const key in theme) {
|
|
21
|
+
ensureThemeVariable(theme, key);
|
|
22
|
+
}
|
|
23
|
+
const cssRules = getThemeCSSRules({
|
|
24
|
+
config,
|
|
25
|
+
themeName,
|
|
26
|
+
names: [themeName],
|
|
27
|
+
theme
|
|
28
|
+
});
|
|
29
|
+
const themeProxied = proxyThemeToParents(themeName, theme, config.themes);
|
|
30
|
+
config.themes[themeName] = themeProxied;
|
|
31
|
+
if (insertCSS && isWeb) {
|
|
32
|
+
const id = `tamagui_theme_style_${themeName}`;
|
|
33
|
+
const existing = document.querySelector(`#${id}`);
|
|
34
|
+
const style = document.createElement("style");
|
|
35
|
+
style.id = id;
|
|
36
|
+
style.appendChild(document.createTextNode(cssRules.join("\n")));
|
|
37
|
+
document.head.appendChild(style);
|
|
38
|
+
if (existing) {
|
|
39
|
+
(_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
theme: themeProxied,
|
|
44
|
+
cssRules
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
addTheme
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=addTheme.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/addTheme.ts"],
|
|
4
|
+
"sourcesContent": ["import { getConfig } from './conf'\nimport { isWeb } from './constants/platform'\nimport { getThemeCSSRules } from './helpers/getThemeCSSRules'\nimport { ensureThemeVariable, proxyThemeToParents } from './helpers/themes'\nimport { ThemeObject } from './types'\n\nexport function addTheme({\n name: themeName,\n theme: themeIn,\n insertCSS,\n update,\n}: {\n name: string\n theme: ThemeObject\n insertCSS?: boolean\n update?: boolean\n}) {\n const config = getConfig()\n if (!config) {\n throw new Error(`Must run createTamagui once before loading theme`)\n }\n if (!update && config.themes[themeName]) {\n throw new Error(`Already defined theme \"${themeName}\", use updateTheme to change values`)\n }\n const theme = { ...themeIn }\n for (const key in theme) {\n ensureThemeVariable(theme, key)\n }\n const cssRules = getThemeCSSRules({\n config,\n themeName,\n names: [themeName],\n theme,\n })\n const themeProxied = proxyThemeToParents(themeName, theme, config.themes)\n config.themes[themeName] = themeProxied\n\n if (insertCSS && isWeb) {\n const id = `tamagui_theme_style_${themeName}`\n const existing = document.querySelector(`#${id}`)\n const style = document.createElement('style')\n style.id = id\n style.appendChild(document.createTextNode(cssRules.join('\\n')))\n document.head.appendChild(style)\n if (existing) {\n existing.parentElement?.removeChild(existing)\n }\n }\n\n return {\n theme: themeProxied,\n cssRules,\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AACA;AACA;AACA;AAGO,kBAAkB;AAAA,EACvB,MAAM;AAAA,EACN,OAAO;AAAA,EACP;AAAA,EACA;AAAA,GAMC;AAhBH;AAiBE,QAAM,SAAS,UAAU;AACzB,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACpE;AACA,MAAI,CAAC,UAAU,OAAO,OAAO,YAAY;AACvC,UAAM,IAAI,MAAM,0BAA0B,8CAA8C;AAAA,EAC1F;AACA,QAAM,QAAQ,EAAE,GAAG,QAAQ;AAC3B,aAAW,OAAO,OAAO;AACvB,wBAAoB,OAAO,GAAG;AAAA,EAChC;AACA,QAAM,WAAW,iBAAiB;AAAA,IAChC;AAAA,IACA;AAAA,IACA,OAAO,CAAC,SAAS;AAAA,IACjB;AAAA,EACF,CAAC;AACD,QAAM,eAAe,oBAAoB,WAAW,OAAO,OAAO,MAAM;AACxE,SAAO,OAAO,aAAa;AAE3B,MAAI,aAAa,OAAO;AACtB,UAAM,KAAK,uBAAuB;AAClC,UAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,UAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,UAAM,KAAK;AACX,UAAM,YAAY,SAAS,eAAe,SAAS,KAAK,IAAI,CAAC,CAAC;AAC9D,aAAS,KAAK,YAAY,KAAK;AAC/B,QAAI,UAAU;AACZ,qBAAS,kBAAT,mBAAwB,YAAY;AAAA,IACtC;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TextAncestorContext as RNWTextAncestorContext } from "@tamagui/rnw";
|
|
2
|
+
import React, { createContext } from "react";
|
|
3
|
+
const FallbackNativeContext = createContext(false);
|
|
4
|
+
const TextAncestorContext = RNWTextAncestorContext ?? FallbackNativeContext;
|
|
5
|
+
const TextAncestorProvider = (props) => {
|
|
6
|
+
return /* @__PURE__ */ React.createElement(TextAncestorContext.Provider, {
|
|
7
|
+
value: false
|
|
8
|
+
}, props.children);
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
FallbackNativeContext,
|
|
12
|
+
TextAncestorContext,
|
|
13
|
+
TextAncestorProvider
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=TextAncestorContext.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/contexts/TextAncestorContext.tsx"],
|
|
4
|
+
"sourcesContent": ["import { TextAncestorContext as RNWTextAncestorContext } from '@tamagui/rnw'\nimport React, { createContext } from 'react'\n\nexport const FallbackNativeContext = createContext(false)\n\nexport const TextAncestorContext = RNWTextAncestorContext ?? FallbackNativeContext\n\nexport const TextAncestorProvider = (props) => {\n return <TextAncestorContext.Provider value={false}>{props.children}</TextAncestorContext.Provider>\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AACA;AAEO,MAAM,wBAAwB,cAAc,KAAK;AAEjD,MAAM,sBAAsB,0BAA0B;AAEtD,MAAM,uBAAuB,CAAC,UAAU;AAC7C,SAAO,oCAAC,oBAAoB,UAApB;AAAA,IAA6B,OAAO;AAAA,KAAQ,MAAM,QAAS;AACrE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/contexts/ThemeContext.tsx"],
|
|
4
|
+
"sourcesContent": ["import { createContext } from 'react'\n\nimport { ThemeName, Themes } from '../types'\n\nexport const ThemeContext = createContext<{ themes: Themes; defaultTheme: ThemeName } | null>(null)\n"],
|
|
5
|
+
"mappings": "AAAA;AAIO,MAAM,eAAe,cAAkE,IAAI;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -27,6 +27,7 @@ import { getConfig, onConfiguredOnce } from "./conf";
|
|
|
27
27
|
import { stackDefaultStyles } from "./constants/constants";
|
|
28
28
|
import { isWeb, useIsomorphicLayoutEffect } from "./constants/platform";
|
|
29
29
|
import { FontLanguageContext } from "./contexts/FontLanguageContext";
|
|
30
|
+
import { TextAncestorContext } from "./contexts/TextAncestorContext";
|
|
30
31
|
import { assignNativePropsToWeb } from "./helpers/assignNativePropsToWeb";
|
|
31
32
|
import { getReturnVariablesAs } from "./helpers/createPropMapper";
|
|
32
33
|
import { createShallowUpdate } from "./helpers/createShallowUpdate";
|
|
@@ -39,9 +40,8 @@ import { useFeatures } from "./hooks/useFeatures";
|
|
|
39
40
|
import { mediaState } from "./hooks/useMedia";
|
|
40
41
|
import { usePressable } from "./hooks/usePressable";
|
|
41
42
|
import { getThemeManager, useTheme } from "./hooks/useTheme";
|
|
42
|
-
import { usePressability } from "./Pressability";
|
|
43
|
+
import { usePressability } from "./vendor/Pressability";
|
|
43
44
|
import { Slot, mergeEvent } from "./views/Slot";
|
|
44
|
-
import { TextAncestorContext } from "./views/TextAncestorContext";
|
|
45
45
|
import { wrapThemeManagerContext } from "./views/Theme";
|
|
46
46
|
React["keep"];
|
|
47
47
|
const defaultComponentState = Object.freeze({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/createComponent.tsx"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable react-hooks/rules-of-hooks */\nimport {\n composeEventHandlers,\n stylePropsView,\n validPseudoKeys,\n validStyles,\n} from '@tamagui/helpers'\nimport {\n useElementLayout,\n useMergeRefs,\n usePlatformMethods,\n useResponderEvents,\n} from '@tamagui/rnw'\nimport { useForceUpdate } from '@tamagui/use-force-update'\nimport React, {\n Children,\n Fragment,\n createElement,\n forwardRef,\n memo,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n} from 'react'\nimport { StyleSheet, Text, View, ViewStyle } from 'react-native'\n\nimport { getConfig, onConfiguredOnce } from './conf'\nimport { stackDefaultStyles } from './constants/constants'\nimport { isWeb, useIsomorphicLayoutEffect } from './constants/platform'\nimport { FontLanguageContext } from './contexts/FontLanguageContext'\nimport { assignNativePropsToWeb } from './helpers/assignNativePropsToWeb'\nimport { getReturnVariablesAs } from './helpers/createPropMapper'\nimport { createShallowUpdate } from './helpers/createShallowUpdate'\nimport { extendStaticConfig, parseStaticConfig } from './helpers/extendStaticConfig'\nimport { SplitStyleResult, insertSplitStyles, useSplitStyles } from './helpers/getSplitStyles'\nimport { getAllSelectors } from './helpers/insertStyleRule'\nimport { mergeProps } from './helpers/mergeProps'\nimport { proxyThemeVariables } from './helpers/proxyThemeVariables'\nimport { useFeatures } from './hooks/useFeatures'\nimport { mediaState } from './hooks/useMedia'\nimport { usePressable } from './hooks/usePressable'\nimport { getThemeManager, useTheme } from './hooks/useTheme'\nimport { usePressability } from './Pressability'\nimport {\n SpaceDirection,\n SpaceTokens,\n SpacerProps,\n StaticConfig,\n StaticConfigParsed,\n StylableComponent,\n TamaguiComponent,\n TamaguiComponentState,\n TamaguiConfig,\n TamaguiElement,\n TamaguiInternalConfig,\n UseAnimationHook,\n} from './types'\nimport { Slot, mergeEvent } from './views/Slot'\nimport { TextAncestorContext } from './views/TextAncestorContext'\nimport { wrapThemeManagerContext } from './views/Theme'\n\nReact['keep']\n\nconst defaultComponentState: TamaguiComponentState = Object.freeze({\n hover: false,\n press: false,\n pressIn: false,\n focus: false,\n // only used by enterStyle\n mounted: false,\n animation: null,\n})\n\nexport const mouseUps = new Set<Function>()\nif (typeof document !== 'undefined') {\n document.addEventListener('mouseup', () => {\n mouseUps.forEach((x) => x())\n mouseUps.clear()\n })\n document.addEventListener('touchend', () => {\n mouseUps.forEach((x) => x())\n mouseUps.clear()\n })\n document.addEventListener('touchcancel', () => {\n mouseUps.forEach((x) => x())\n mouseUps.clear()\n })\n}\n\n// mutates\nfunction mergeShorthands({ defaultProps }: StaticConfigParsed, { shorthands }: TamaguiConfig) {\n // they are defined in correct order already { ...parent, ...child }\n for (const key in defaultProps) {\n defaultProps[shorthands[key] || key] = defaultProps[key]\n }\n}\n\nlet initialTheme: any\nlet config: TamaguiInternalConfig\n\nexport function createComponent<\n ComponentPropTypes extends Object = {},\n Ref = TamaguiElement,\n BaseProps = never\n>(configIn: Partial<StaticConfig> | StaticConfigParsed, ParentComponent?: StylableComponent) {\n const staticConfig = (() => {\n const next = extendStaticConfig(configIn, ParentComponent)\n if ('parsed' in next) {\n return next\n } else {\n return parseStaticConfig(next)\n }\n })()\n\n const defaultComponentClassName = `is_${staticConfig.componentName}`\n let tamaguiConfig: TamaguiInternalConfig\n let AnimatedText: any\n let AnimatedView: any\n let avoidClasses = true\n let defaultNativeStyle: any\n let defaultNativeStyleSheet: StyleSheet.NamedStyles<{ base: {} }>\n let tamaguiDefaultProps: any\n let initialSplitStyles: SplitStyleResult\n\n // see onConfiguredOnce below which attaches a name then to this component\n const component = forwardRef<Ref, ComponentPropTypes>((propsIn: any, forwardedRef) => {\n // React inserts default props after your props for some reason...\n // order important so we do loops, you can't just spread because JS does weird things\n let props: any\n if (tamaguiDefaultProps && !propsIn.asChild) {\n props = mergeProps(tamaguiDefaultProps, propsIn)[0]\n } else {\n props = propsIn\n }\n\n const hostRef = useRef<HTMLElement | View>(null)\n const { Component, isText, isZStack } = staticConfig\n const componentName = props.componentName || staticConfig.componentName\n const componentClassName = props.asChild\n ? ''\n : props.componentName\n ? `is_${props.componentName}`\n : defaultComponentClassName\n\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n const name = `${\n componentName || Component?.displayName || Component?.name || '[Unnamed Component]'\n }`\n const banner = `${name} ${propsIn['data-is'] || ''}`\n console.group(`%c \uD83D\uDC1B ${banner}`, 'background: yellow;')\n console.log('props', propsIn)\n console.log('ref', hostRef, '(click to view)')\n if (props['debug'] === 'break') {\n debugger\n }\n }\n }\n\n const forceUpdate = useForceUpdate()\n const theme = useTheme(props.theme, componentName, props, forceUpdate)\n const states = useState<TamaguiComponentState>(defaultComponentState)\n const state = propsIn.forceStyle ? { ...states[0], [propsIn.forceStyle]: true } : states[0]\n const setState = states[1]\n const setStateShallow = createShallowUpdate(setState)\n const languageContext = useContext(FontLanguageContext)\n\n const shouldAvoidClasses = !!(props.animation && avoidClasses)\n const shouldForcePseudo = !!propsIn.forceStyle\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const hasTextAncestor = !!(isWeb && isText ? useContext(TextAncestorContext) : false)\n const splitStyleState =\n !shouldAvoidClasses && !shouldForcePseudo\n ? {\n ...state,\n hasTextAncestor,\n dynamicStylesInline: true,\n }\n : ({\n ...state,\n noClassNames: true,\n dynamicStylesInline: true,\n hasTextAncestor,\n resolveVariablesAs: 'value',\n } as const)\n\n const splitStyles = useSplitStyles(\n props,\n staticConfig,\n theme,\n splitStyleState,\n props.asChild ? null : initialSplitStyles.classNames,\n languageContext || undefined,\n props['debug']\n )\n\n const { viewProps: viewPropsIn, pseudos, medias, style, classNames } = splitStyles\n const useAnimations = tamaguiConfig.animations?.useAnimations as UseAnimationHook | undefined\n const isAnimated = !!(useAnimations && props.animation)\n const hasEnterStyle = !!props.enterStyle\n\n const animationFeatureStylesIn = props.animation ? { ...defaultNativeStyle, ...style } : null\n\n const features = useFeatures(props, {\n forceUpdate,\n setStateShallow,\n useAnimations,\n state,\n style: animationFeatureStylesIn,\n pseudos,\n staticConfig,\n theme,\n hostRef,\n onDidAnimate: props.onDidAnimate,\n })\n\n const {\n tag,\n hitSlop,\n asChild,\n children,\n onPress,\n onPressIn,\n onPressOut,\n onHoverIn,\n onHoverOut,\n themeShallow,\n space: spaceProp,\n spaceDirection: _spaceDirection,\n disabled: disabledProp,\n onMouseUp,\n onMouseDown,\n onMouseEnter,\n onMouseLeave,\n hrefAttrs,\n separator,\n // ignore from here on out\n forceStyle: _forceStyle,\n // @ts-ignore for next/link compat etc\n onClick,\n theme: _themeProp,\n // @ts-ignore\n defaultVariants,\n\n ...nonTamaguiProps\n } = viewPropsIn\n\n // get the right component\n const isTaggable = !Component || typeof Component === 'string'\n\n // default to tag, fallback to component (when both strings)\n const element = isWeb ? (isTaggable ? tag || Component : Component) : Component\n const BaseTextComponent = !isWeb ? Text : element || 'span'\n const BaseViewComponent = !isWeb ? View : element || (hasTextAncestor ? 'span' : 'div')\n let elementType = isText\n ? (isAnimated ? AnimatedText || Text : null) || BaseTextComponent\n : (isAnimated ? AnimatedView || View : null) || BaseViewComponent\n\n elementType = Component || elementType\n const isStringElement = typeof elementType === 'string'\n\n const disabled =\n (props.accessibilityState != null && props.accessibilityState.disabled === true) ||\n props.accessibilityDisabled\n\n // these can ultimately be for DOM, react-native-web views, or animated views\n // so the type is pretty loose\n let viewProps: Record<string, any>\n\n // if react-native-web view just pass all props down\n if (process.env.TAMAGUI_TARGET === 'web' && !staticConfig.isReactNativeWeb) {\n // otherwise replicate react-native-web functionality\n const {\n // event props\n onMoveShouldSetResponder,\n onMoveShouldSetResponderCapture,\n onResponderEnd,\n onResponderGrant,\n onResponderMove,\n onResponderReject,\n onResponderRelease,\n onResponderStart,\n onResponderTerminate,\n onResponderTerminationRequest,\n onScrollShouldSetResponder,\n onScrollShouldSetResponderCapture,\n onSelectionChangeShouldSetResponder,\n onSelectionChangeShouldSetResponderCapture,\n onStartShouldSetResponder,\n onStartShouldSetResponderCapture,\n\n // react-native props\n nativeID,\n\n // react-native-web accessibility props\n // @ts-ignore\n accessibilityActiveDescendant,\n // @ts-ignore\n accessibilityAtomic,\n // @ts-ignore\n accessibilityAutoComplete,\n // @ts-ignore\n accessibilityBusy,\n // @ts-ignore\n accessibilityChecked,\n // @ts-ignore\n accessibilityColumnCount,\n // @ts-ignore\n accessibilityColumnIndex,\n // @ts-ignore\n accessibilityColumnSpan,\n // @ts-ignore\n accessibilityControls,\n // @ts-ignore\n accessibilityCurrent,\n // @ts-ignore\n accessibilityDescribedBy,\n // @ts-ignore\n accessibilityDetails,\n // @ts-ignore\n accessibilityDisabled,\n // @ts-ignore\n accessibilityErrorMessage,\n // @ts-ignore\n accessibilityExpanded,\n // @ts-ignore\n accessibilityFlowTo,\n // @ts-ignore\n accessibilityHasPopup,\n // @ts-ignore\n accessibilityHidden,\n // @ts-ignore\n accessibilityInvalid,\n // @ts-ignore\n accessibilityKeyShortcuts,\n // @ts-ignore\n accessibilityLabel,\n // @ts-ignore\n accessibilityLabelledBy,\n // @ts-ignore\n accessibilityLevel,\n // @ts-ignore\n accessibilityLiveRegion,\n // @ts-ignore\n accessibilityModal,\n // @ts-ignore\n accessibilityMultiline,\n // @ts-ignore\n accessibilityMultiSelectable,\n // @ts-ignore\n accessibilityOrientation,\n // @ts-ignore\n accessibilityOwns,\n // @ts-ignore\n accessibilityPlaceholder,\n // @ts-ignore\n accessibilityPosInSet,\n // @ts-ignore\n accessibilityPressed,\n // @ts-ignore\n accessibilityReadOnly,\n // @ts-ignore\n accessibilityRequired,\n // @ts-ignore\n accessibilityRole,\n // @ts-ignore\n accessibilityRoleDescription,\n // @ts-ignore\n accessibilityRowCount,\n // @ts-ignore\n accessibilityRowIndex,\n // @ts-ignore\n accessibilityRowSpan,\n // @ts-ignore\n accessibilitySelected,\n // @ts-ignore\n accessibilitySetSize,\n // @ts-ignore\n accessibilitySort,\n // @ts-ignore\n accessibilityValueMax,\n // @ts-ignore\n accessibilityValueMin,\n // @ts-ignore\n accessibilityValueNow,\n // @ts-ignore\n accessibilityValueText,\n\n // deprecated\n accessible,\n accessibilityState,\n accessibilityValue,\n\n // android\n collapsable,\n focusable,\n\n onLayout,\n\n ...webProps\n } = nonTamaguiProps\n\n viewProps = webProps\n\n assignNativePropsToWeb(elementType, viewProps, nonTamaguiProps)\n\n useElementLayout(hostRef, onLayout)\n\n // from react-native-web\n useResponderEvents(hostRef, {\n onMoveShouldSetResponder,\n onMoveShouldSetResponderCapture,\n onResponderEnd,\n onResponderGrant,\n onResponderMove,\n onResponderReject,\n onResponderRelease,\n onResponderStart,\n onResponderTerminate,\n onResponderTerminationRequest,\n onScrollShouldSetResponder,\n onScrollShouldSetResponderCapture,\n onSelectionChangeShouldSetResponder,\n onSelectionChangeShouldSetResponderCapture,\n onStartShouldSetResponder,\n onStartShouldSetResponderCapture,\n })\n\n // from react-native-web\n const platformMethodsRef = usePlatformMethods(viewProps)\n\n const setRef = useMergeRefs(hostRef, platformMethodsRef, forwardedRef as any)\n viewProps.ref = setRef\n\n if (props.href != undefined && hrefAttrs != undefined) {\n const { download, rel, target } = hrefAttrs\n if (download != null) {\n viewProps.download = download\n }\n if (rel != null) {\n viewProps.rel = rel\n }\n if (typeof target === 'string') {\n viewProps.target = target.charAt(0) !== '_' ? '_' + target : target\n }\n }\n\n // FOCUS\n // \"focusable\" indicates that an element may be a keyboard tab-stop.\n const _focusable = focusable != undefined ? focusable : accessible\n const role = viewProps.role\n if (_focusable === false) {\n viewProps.tabIndex = '-1'\n }\n if (\n // These native elements are focusable by default\n elementType === 'a' ||\n elementType === 'button' ||\n elementType === 'input' ||\n elementType === 'select' ||\n elementType === 'textarea'\n ) {\n if (_focusable === false || accessibilityDisabled === true) {\n viewProps.tabIndex = '-1'\n }\n } else if (\n // These roles are made focusable by default\n role === 'button' ||\n role === 'checkbox' ||\n role === 'link' ||\n role === 'radio' ||\n role === 'textbox' ||\n role === 'switch'\n ) {\n if (_focusable !== false) {\n viewProps.tabIndex = '0'\n }\n }\n // Everything else must explicitly set the prop\n if (_focusable === true) {\n viewProps.tabIndex = '0'\n }\n } else {\n viewProps = nonTamaguiProps\n if (forwardedRef) {\n // @ts-ignore\n viewProps.ref = forwardedRef\n }\n }\n\n if (process.env.NODE_ENV === 'development' && !isText && isWeb) {\n Children.toArray(props.children).forEach((item) => {\n if (typeof item === 'string') {\n console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`)\n }\n })\n }\n\n // isMounted\n const internal = useRef<{ isMounted: boolean; unmountEffects?: Function[] }>()\n if (!internal.current) {\n internal.current = {\n isMounted: true,\n }\n }\n\n useIsomorphicLayoutEffect(() => {\n // we need to use state to properly have mounted go from false => true\n if (typeof window !== 'undefined' && (hasEnterStyle || props.animation)) {\n // for SSR we never set mounted, ensuring enterStyle={{}} is set by default\n setStateShallow({\n mounted: true,\n })\n }\n\n internal.current!.isMounted = true\n return () => {\n mouseUps.delete(unPress)\n internal.current!.isMounted = false\n internal.current!.unmountEffects?.forEach((cb) => cb())\n }\n }, [hasEnterStyle, props.animation])\n\n let styles: any[]\n\n const animationStyles = state.animation ? state.animation.style : null\n\n if (isStringElement && shouldAvoidClasses && !shouldForcePseudo) {\n styles = {\n ...defaultNativeStyle,\n ...(animationStyles ?? style),\n ...medias,\n }\n } else {\n styles = [\n isWeb ? null : defaultNativeStyleSheet ? (defaultNativeStyleSheet.base as ViewStyle) : null,\n animationStyles ?? style,\n medias,\n ]\n if (!animationStyles) {\n const initPseudos = initialSplitStyles.pseudos\n const force = shouldForcePseudo\n !state.mounted && addPseudoToStyles(styles, initPseudos, pseudos, 'enterStyle')\n state.hover && addPseudoToStyles(styles, initPseudos, pseudos, 'hoverStyle', force)\n state.focus && addPseudoToStyles(styles, initPseudos, pseudos, 'focusStyle', force)\n state.press && addPseudoToStyles(styles, initPseudos, pseudos, 'pressStyle', force)\n }\n // ugly but for now...\n if (shouldForcePseudo) {\n const next = {}\n for (const style of styles) {\n if (style) {\n Object.assign(next, style)\n }\n }\n // @ts-ignore\n Object.assign(splitStyles.style, next)\n }\n }\n\n if (process.env.TAMAGUI_TARGET === 'web') {\n const fontFamilyName = isText\n ? props.fontFamily || staticConfig.defaultProps.fontFamily\n : null\n\n let fontFamily: string | null = null\n if (fontFamilyName) {\n if (fontFamilyName[0] === '$') {\n fontFamily = fontFamilyName.slice(1)\n }\n }\n\n const classList = [\n componentName ? componentClassName : '',\n fontFamily ? `font_${fontFamily}` : '',\n theme.className,\n classNames ? Object.values(classNames).join(' ') : '',\n ]\n\n const className = classList.join(' ')\n const style = animationStyles ?? splitStyles.style\n\n // TODO this is specific to reanimated rn\n const isAnimatedReactNativeWeb = props.animation && avoidClasses\n\n if (staticConfig.isReactNativeWeb || isAnimatedReactNativeWeb) {\n viewProps.dataSet = {\n ...viewProps.dataSet,\n className,\n id: props.id,\n }\n if (props['data-is']) {\n viewProps.dataSet.is = props['data-is']\n }\n } else {\n viewProps.className = className\n }\n\n viewProps.style = style\n } else {\n viewProps.style = styles\n }\n\n // TODO need to loop active variants and see if they have matchin pseudos and apply as well\n const initialPseudos = initialSplitStyles.pseudos\n const attachPress = !!(\n pseudos?.pressStyle ||\n initialPseudos?.pressStyle ||\n onPress ||\n onPressOut ||\n onPressIn ||\n onClick\n )\n\n const isHoverable = isWeb\n const attachHover =\n isHoverable &&\n !!((pseudos && pseudos.hoverStyle) || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave)\n\n const handlesPressEvents = !isStringElement && !asChild\n const pressKey = handlesPressEvents ? 'onPress' : 'onClick'\n const pressInKey = handlesPressEvents ? 'onPressIn' : 'onMouseDown'\n const pressOutKey = handlesPressEvents ? 'onPressOut' : 'onMouseUp'\n\n // check presence to prevent reparenting bugs, allows for onPress={x ? function : undefined} usage\n const shouldAttach =\n !asChild &&\n (attachPress ||\n attachHover ||\n 'pressStyle' in props ||\n 'onPress' in props ||\n 'onPressIn' in props ||\n 'onPressOut' in props ||\n (isWeb &&\n ('hoverStyle' in props ||\n 'onHoverIn' in props ||\n 'onHoverOut' in props ||\n 'onMouseEnter' in props ||\n 'onMouseLeave' in props)))\n\n const unPress = useCallback(() => {\n if (!internal.current!.isMounted) return\n setStateShallow({\n press: false,\n pressIn: false,\n })\n }, [])\n\n const events = shouldAttach\n ? {\n [pressOutKey]: attachPress\n ? (e) => {\n unPress()\n onPressOut?.(e)\n onMouseUp?.(e)\n }\n : undefined,\n ...(isHoverable && {\n onMouseEnter: attachHover\n ? (e) => {\n const next: Partial<typeof state> = {}\n if (attachHover) {\n next.hover = true\n }\n if (state.pressIn) {\n next.press = true\n }\n if (Object.keys(next).length) {\n setStateShallow(next)\n }\n onHoverIn?.(e)\n onMouseEnter?.(e)\n }\n : undefined,\n onMouseLeave: attachHover\n ? (e) => {\n const next: Partial<typeof state> = {}\n mouseUps.add(unPress)\n if (attachHover) {\n next.hover = false\n }\n if (state.pressIn) {\n next.press = false\n next.pressIn = false\n }\n if (Object.keys(next).length) {\n setStateShallow(next)\n }\n onHoverOut?.(e)\n onMouseLeave?.(e)\n }\n : undefined,\n }),\n [pressInKey]: attachPress\n ? (e) => {\n setStateShallow({\n press: true,\n pressIn: true,\n hover: false,\n })\n onPressIn?.(e)\n onMouseDown?.(e)\n if (isWeb) {\n mouseUps.add(unPress)\n }\n }\n : null,\n [pressKey]: attachPress\n ? (e) => {\n unPress()\n onClick?.(e)\n onPress?.(e)\n }\n : null,\n\n // replicating TouchableWithoutFeedback\n ...(!isWeb && {\n cancelable: !props.rejectResponderTermination,\n disabled: props.disabled !== null ? props.disabled : props.accessibilityState?.disabled,\n hitSlop: props.hitSlop,\n delayLongPress: props.delayLongPress,\n delayPressIn: props.delayPressIn,\n delayPressOut: props.delayPressOut,\n focusable: viewProps.focusable ?? true,\n minPressDuration: 0,\n }),\n }\n : null\n\n let space = spaceProp\n // find space by media query\n if (features.enabled.mediaQuery) {\n for (const key in mediaState) {\n if (!mediaState[key]) continue\n if (props[key] && props[key].space !== undefined) {\n space = props[key].space\n }\n }\n }\n\n const themeManager = getThemeManager(theme)\n\n const shouldSetChildrenThemeToParent = Boolean(\n themeShallow && themeManager && themeManager.didChangeTheme\n )\n\n const shouldProvideThemeManager =\n shouldSetChildrenThemeToParent || (themeManager && themeManager.didChangeTheme)\n\n const childEls =\n !children || asChild\n ? children\n : wrapThemeManagerContext(\n spacedChildren({\n separator,\n children,\n space,\n direction: props.spaceDirection || 'both',\n isZStack,\n }),\n // only set context if changed theme\n shouldProvideThemeManager ? themeManager : undefined,\n shouldSetChildrenThemeToParent\n )\n\n let content: any\n\n if (asChild) {\n elementType = Slot\n viewProps = {\n ...viewProps,\n onPress,\n onPressIn,\n onPressOut,\n }\n }\n\n // EVENTS: web\n if (isWeb) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [pressableProps] = usePressable(\n events\n ? {\n disabled,\n ...(hitSlop && {\n hitSlop,\n }),\n onPressOut: events[pressOutKey],\n onPressIn: events[pressInKey],\n onPress: events[pressKey],\n }\n : {\n disabled: true,\n }\n )\n if (events) {\n if (handlesPressEvents) {\n Object.assign(viewProps, pressableProps)\n } else {\n Object.assign(viewProps, events)\n }\n }\n }\n\n // add focus events\n if (process.env.TAMAGUI_TARGET === 'native') {\n const attachFocus = !!(\n (pseudos && pseudos.focusStyle) ||\n (initialPseudos && initialPseudos.focusStyle)\n )\n if (attachFocus) {\n viewProps.onFocus = mergeEvent(viewProps.onFocus, () => {\n setStateShallow({ focus: true })\n })\n viewProps.onBlur = mergeEvent(viewProps.onBlur, () => {\n setStateShallow({ focus: false })\n })\n }\n }\n\n // EVENTS native\n // use Pressability to get smooth unPress when you press + hold + move out\n if (process.env.TAMAGUI_TARGET === 'native') {\n // only ever create once, use .configure() to update later\n const pressability = usePressability(events)\n if (attachPress && events) {\n const dontComposePressabilityKeys = {\n onClick: true,\n }\n if (hitSlop) {\n viewProps.hitSlop = hitSlop\n }\n for (const key in pressability) {\n const og = props[key]\n const val = pressability[key]\n viewProps[key] =\n og && !dontComposePressabilityKeys[key] ? composeEventHandlers(og, val) : val\n }\n }\n }\n\n content = createElement(elementType, viewProps, childEls)\n\n if (process.env.TAMAGUI_TARGET === 'web') {\n // only necessary when animating because some AnimatedView which wraps RNW View doesn't forward dataSet className\n const isAnimatedRNWView = isAnimated && typeof elementType !== 'string' // assuming for now as reanimated is only driver\n const shouldWrapWithComponentTheme =\n isAnimatedRNWView && getReturnVariablesAs(props, splitStyleState) === 'non-color-value'\n const shouldWrapWithHover = events && attachHover\n\n if (shouldWrapWithHover || shouldWrapWithComponentTheme) {\n const themeClassName = shouldWrapWithComponentTheme ? `${theme.className}` : ''\n const hoverClassName = shouldWrapWithHover ? 't_Hoverable' : ''\n content = (\n <span\n className={`${hoverClassName} ${themeClassName}`}\n style={{\n display: 'contents',\n }}\n {...(shouldWrapWithHover && {\n onMouseEnter: events.onMouseEnter,\n onMouseLeave: events.onMouseLeave,\n })}\n >\n {content}\n </span>\n )\n }\n }\n\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n // prettier-ignore\n console.groupCollapsed('props out', viewProps, typeof elementType === 'string' ? elementType : 'Component')\n for (const key in viewProps) {\n console.log(key, viewProps[key])\n }\n console.log('children', content)\n console.groupEnd()\n if (typeof window !== 'undefined') {\n // prettier-ignore\n console.log({ state, shouldProvideThemeManager, tamaguiDefaultProps, viewProps, splitStyles, animationStyles, handlesPressEvents, isStringElement, classNamesIn: props.className?.split(' '), classNamesOut: viewProps.className?.split(' '), events, shouldAttach, styles, pseudos, content, childEls, shouldAvoidClasses, avoidClasses, animation: props.animation, style, defaultNativeStyle, initialSplitStyles, ...(typeof window !== 'undefined' ? { theme, themeClassName: theme.className, staticConfig, tamaguiConfig, events, shouldAvoidClasses, shouldForcePseudo, classNames: Object.fromEntries(Object.entries(classNames).map(([k, v]) => [v, getAllSelectors()[v]])) } : null) })\n }\n console.groupEnd()\n }\n }\n\n return features.elements.length ? (\n <>\n {features.elements}\n {content}\n </>\n ) : (\n content\n )\n })\n\n if (staticConfig.componentName) {\n component.displayName = staticConfig.componentName\n }\n\n // Once configuration is run and all components are registered\n // get default props + className and analyze styles\n onConfiguredOnce((conf) => {\n if (process.env.IS_STATIC === 'is_static') {\n // in static mode we just use these to lookup configuration\n return\n }\n\n tamaguiConfig = conf\n\n // do this to make sure shorthands don't duplicate with.. longhands\n mergeShorthands(staticConfig, tamaguiConfig)\n\n if (tamaguiConfig.animations) {\n avoidClasses = !!tamaguiConfig.animations.avoidClasses\n AnimatedText = tamaguiConfig.animations.Text\n AnimatedView = tamaguiConfig.animations.View\n }\n\n initialTheme =\n initialTheme ||\n proxyThemeVariables(conf.themes[conf.defaultTheme || Object.keys(conf.themes)[0]])\n\n // adds in user defined default props\n config = getConfig()\n\n let defaultPropsIn = staticConfig.defaultProps || {}\n\n // because we run createTamagui after styled() defs, have to do some work here\n // gather defaults props one time and merge downwards\n // find last unprocessed and process\n const parentNames = [...(staticConfig.parentNames || []), staticConfig.componentName]\n\n if (config.defaultProps && parentNames && staticConfig.componentName) {\n defaultPropsIn = mergeConfigDefaultProps(\n staticConfig.componentName,\n defaultPropsIn,\n config.defaultProps,\n parentNames\n )\n }\n\n const debug = process.env.NODE_ENV === 'development' ? defaultPropsIn['debug'] : false\n\n if (process.env.NODE_ENV === 'development' && debug === 'break') {\n debugger\n }\n\n // remove all classNames\n const [parentProps, parentClassNames] = mergeProps(defaultPropsIn, {}, true)\n\n initialSplitStyles = insertSplitStyles(\n parentProps,\n staticConfig,\n initialTheme,\n {\n mounted: true,\n hover: false,\n press: false,\n pressIn: false,\n focus: false,\n resolveVariablesAs: 'both',\n keepVariantsAsProps: true,\n },\n undefined,\n undefined,\n debug\n )\n\n if (debug) {\n console.log('initialSplitStyles', initialSplitStyles)\n }\n\n // must preserve prop order\n // leave out className because we handle that already with initialSplitStyles.classNames\n // otherwise it confuses variant functions getting className props\n const [defaults, defaultsClassnames] = mergeProps(\n component.defaultProps as any,\n initialSplitStyles.viewProps,\n true\n )\n\n // avoid passing className props to variants\n initialSplitStyles.classNames = {\n ...parentClassNames,\n ...defaultsClassnames,\n ...initialSplitStyles.classNames,\n }\n\n defaultNativeStyle = {}\n\n const validStyles = staticConfig.validStyles || stylePropsView\n\n // split - keep variables on props to be processed using theme values at runtime (native)\n if (!isWeb) {\n for (const key in staticConfig.defaultProps) {\n const val = staticConfig.defaultProps[key]\n if (validPseudoKeys[key]) continue\n if ((typeof val === 'string' && val[0] === '$') || !validStyles[key]) {\n defaults[key] = val\n } else {\n defaultNativeStyle[key] = val\n }\n }\n }\n\n defaultNativeStyleSheet = StyleSheet.create({\n base: defaultNativeStyle,\n })\n\n if (Object.keys(defaults).length) {\n tamaguiDefaultProps = defaults\n }\n\n // add debug logs\n if (process.env.NODE_ENV === 'development' && debug) {\n if (process.env.IS_STATIC !== 'is_static') {\n console.log(`\uD83D\uDC1B [${staticConfig.componentName || 'Component'}]`, {\n staticConfig,\n initialSplitStyles,\n tamaguiDefaultProps,\n defaultNativeStyle,\n defaults,\n defaultPropsIn,\n })\n }\n }\n })\n\n let res: TamaguiComponent<ComponentPropTypes, Ref, BaseProps> = component as any\n\n if (configIn.memo) {\n res = memo(res) as any\n }\n\n res.staticConfig = {\n validStyles: staticConfig.validStyles || stylePropsView,\n ...staticConfig,\n }\n\n // res.extractable HoC\n res.extractable = (Component: any, conf?: Partial<StaticConfig>) => {\n Component.staticConfig = extendStaticConfig(\n {\n Component,\n ...conf,\n neverFlatten: true,\n isExtractable: true,\n defaultProps: {\n ...Component.defaultProps,\n ...conf?.defaultProps,\n },\n },\n res\n )\n return Component\n }\n\n return res\n}\n\n// for elements to avoid spacing\nexport const Unspaced = (props: { children?: any }) => {\n return props.children\n}\nUnspaced['isUnspaced'] = true\n\n// dont used styled() here to avoid circular deps\n// keep inline to avoid circular deps\n\nexport const Spacer = createComponent<SpacerProps>({\n memo: true,\n componentName: 'Spacer',\n validStyles,\n defaultProps: {\n ...stackDefaultStyles,\n size: true,\n },\n variants: {\n size: {\n '...size': (size, { tokens }) => {\n size = size == true ? '$true' : size\n const sizePx = tokens.space[size] ?? size\n return {\n width: sizePx,\n height: sizePx,\n minWidth: sizePx,\n minHeight: sizePx,\n }\n },\n },\n\n flex: {\n true: {\n flexGrow: 1,\n },\n },\n\n direction: {\n horizontal: {\n height: 0,\n minHeight: 0,\n },\n vertical: {\n width: 0,\n minWidth: 0,\n },\n both: {},\n },\n },\n\n defaultVariants: {\n direction: 'both',\n },\n})\n\nexport type SpacedChildrenProps = {\n isZStack?: boolean\n children?: React.ReactNode\n space?: SpaceTokens | number | null\n spaceFlex?: boolean | number\n direction?: SpaceDirection\n separator?: React.ReactNode\n}\n\nexport function spacedChildren({\n isZStack,\n children,\n space,\n direction,\n spaceFlex,\n separator,\n}: SpacedChildrenProps) {\n const hasSpace = !!(space || spaceFlex)\n const hasSeparator = !(separator === undefined || separator === null)\n if (!hasSpace && !hasSeparator && !isZStack) {\n return children\n }\n const childrenList = Children.toArray(children)\n if (childrenList.length <= 1 && !isZStack) {\n return childrenList\n }\n const final: React.ReactNode[] = []\n for (const [index, child] of childrenList.entries()) {\n const isEmpty =\n child === null || child === undefined || (Array.isArray(child) && child.length === 0)\n\n // push them all, but wrap some in Fragment\n if (isEmpty || !child || (child['key'] && !isZStack)) {\n final.push(child)\n } else {\n final.push(\n <Fragment key={index}>{isZStack ? <AbsoluteFill>{child}</AbsoluteFill> : child}</Fragment>\n )\n }\n\n // first child unspaced avoid insert space\n if (isUnspaced(child) && index === 0) {\n continue\n }\n\n // no spacing on ZStack\n if (isZStack) {\n continue\n }\n\n const next = childrenList[index + 1]\n\n if (next && !isUnspaced(next)) {\n if (separator) {\n if (hasSpace) {\n final.push(\n createSpacer({\n key: `_${index}_before_sep_spacer`,\n direction,\n space,\n spaceFlex,\n })\n )\n }\n final.push(\n React.isValidElement(separator)\n ? React.cloneElement(separator, { key: `sep_${index}` })\n : separator\n )\n if (hasSpace) {\n final.push(\n createSpacer({\n key: `_${index}_after_sep_spacer`,\n direction,\n space,\n spaceFlex,\n })\n )\n }\n } else {\n final.push(\n createSpacer({\n key: `_${index}_spacer`,\n direction,\n space,\n spaceFlex,\n })\n )\n }\n }\n }\n\n return final\n}\n\ntype CreateSpacerProps = SpacedChildrenProps & { key: string }\n\nfunction createSpacer({ key, direction, space, spaceFlex }: CreateSpacerProps) {\n return (\n <Spacer\n key={key}\n size={space}\n direction={direction}\n {...(spaceFlex && {\n flex: spaceFlex,\n })}\n />\n )\n}\n\nfunction isUnspaced(child: React.ReactNode) {\n // console.log('unspaced?', child, getMedia())\n return child?.['type']?.['isVisuallyHidden'] || child?.['type']?.['isUnspaced']\n}\n\nfunction AbsoluteFill(props: { children?: any }) {\n return (\n <View pointerEvents=\"box-none\" style={StyleSheet.absoluteFill}>\n {props.children}\n </View>\n )\n}\n\n// this can be done with CSS entirely right?\n// const shouldWrapTextAncestor = isWeb && isText && !hasTextAncestor\n// if (shouldWrapTextAncestor) {\n// // from react-native-web\n// content = createElement(TextAncestorContext.Provider, { value: true }, content)\n// }\n\nexport function processIDRefList(idRefList: string | Array<string>): string {\n return Array.isArray(idRefList) ? idRefList.join(' ') : idRefList\n}\n\nexport const accessibilityRoleToWebRole = {\n adjustable: 'slider',\n button: 'button',\n header: 'heading',\n image: 'img',\n imagebutton: null,\n keyboardkey: null,\n label: null,\n link: 'link',\n none: 'presentation',\n search: 'search',\n summary: 'region',\n text: null,\n}\n\nfunction addPseudoToStyles(\n styles: any[],\n initialPseudos: SplitStyleResult['pseudos'],\n pseudos: any,\n name: string,\n force = false\n) {\n // on web use pseudo object { hoverStyle } to keep specificity with concatClassName\n const pseudoStyle = pseudos[name]\n const shouldNestObject = isWeb && name !== 'enterStyle' && name !== 'exitStyle'\n const defaultPseudoStyle = initialPseudos[name]\n const style = defaultPseudoStyle ? { ...defaultPseudoStyle, ...pseudoStyle } : pseudoStyle\n if (style) {\n styles.push(shouldNestObject && !force ? { [name]: style } : style)\n }\n}\n\nconst DefaultProps = new Map()\n\nfunction mergeConfigDefaultProps(\n name: string,\n props: Record<string, any>,\n configDefaults: Record<string, Object>,\n parentNames: (string | undefined)[]\n) {\n const len = parentNames.length\n let prev\n\n for (let i = 0; i < len; i++) {\n const n = parentNames[i]\n if (!n) continue\n if (DefaultProps.has(n)) {\n prev = DefaultProps.get(n)\n continue\n }\n const props = configDefaults[n]\n if (!props) {\n if (prev) {\n DefaultProps.set(n, prev)\n }\n continue\n }\n prev = mergeProps(prev || {}, props)[0]\n console.log('set prev', prev)\n DefaultProps.set(n, prev)\n }\n\n // overwrite the user defined defaults on top of internal defined defaults\n const ourDefaultsMerged = DefaultProps.get(name)\n if (ourDefaultsMerged) {\n return mergeProps(props, ourDefaultsMerged)[0]\n }\n return props\n}\n"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable react-hooks/rules-of-hooks */\nimport {\n composeEventHandlers,\n stylePropsView,\n validPseudoKeys,\n validStyles,\n} from '@tamagui/helpers'\nimport {\n useElementLayout,\n useMergeRefs,\n usePlatformMethods,\n useResponderEvents,\n} from '@tamagui/rnw'\nimport { useForceUpdate } from '@tamagui/use-force-update'\nimport React, {\n Children,\n Fragment,\n createElement,\n forwardRef,\n memo,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n} from 'react'\nimport { StyleSheet, Text, View, ViewStyle } from 'react-native'\n\nimport { getConfig, onConfiguredOnce } from './conf'\nimport { stackDefaultStyles } from './constants/constants'\nimport { isWeb, useIsomorphicLayoutEffect } from './constants/platform'\nimport { FontLanguageContext } from './contexts/FontLanguageContext'\nimport { TextAncestorContext } from './contexts/TextAncestorContext'\nimport { assignNativePropsToWeb } from './helpers/assignNativePropsToWeb'\nimport { getReturnVariablesAs } from './helpers/createPropMapper'\nimport { createShallowUpdate } from './helpers/createShallowUpdate'\nimport { extendStaticConfig, parseStaticConfig } from './helpers/extendStaticConfig'\nimport { SplitStyleResult, insertSplitStyles, useSplitStyles } from './helpers/getSplitStyles'\nimport { getAllSelectors } from './helpers/insertStyleRule'\nimport { mergeProps } from './helpers/mergeProps'\nimport { proxyThemeVariables } from './helpers/proxyThemeVariables'\nimport { useFeatures } from './hooks/useFeatures'\nimport { mediaState } from './hooks/useMedia'\nimport { usePressable } from './hooks/usePressable'\nimport { getThemeManager, useTheme } from './hooks/useTheme'\nimport {\n SpaceDirection,\n SpaceTokens,\n SpacerProps,\n StaticConfig,\n StaticConfigParsed,\n StylableComponent,\n TamaguiComponent,\n TamaguiComponentState,\n TamaguiConfig,\n TamaguiElement,\n TamaguiInternalConfig,\n UseAnimationHook,\n} from './types'\nimport { usePressability } from './vendor/Pressability'\nimport { Slot, mergeEvent } from './views/Slot'\nimport { wrapThemeManagerContext } from './views/Theme'\n\nReact['keep']\n\nconst defaultComponentState: TamaguiComponentState = Object.freeze({\n hover: false,\n press: false,\n pressIn: false,\n focus: false,\n // only used by enterStyle\n mounted: false,\n animation: null,\n})\n\nexport const mouseUps = new Set<Function>()\nif (typeof document !== 'undefined') {\n document.addEventListener('mouseup', () => {\n mouseUps.forEach((x) => x())\n mouseUps.clear()\n })\n document.addEventListener('touchend', () => {\n mouseUps.forEach((x) => x())\n mouseUps.clear()\n })\n document.addEventListener('touchcancel', () => {\n mouseUps.forEach((x) => x())\n mouseUps.clear()\n })\n}\n\n// mutates\nfunction mergeShorthands({ defaultProps }: StaticConfigParsed, { shorthands }: TamaguiConfig) {\n // they are defined in correct order already { ...parent, ...child }\n for (const key in defaultProps) {\n defaultProps[shorthands[key] || key] = defaultProps[key]\n }\n}\n\nlet initialTheme: any\nlet config: TamaguiInternalConfig\n\nexport function createComponent<\n ComponentPropTypes extends Object = {},\n Ref = TamaguiElement,\n BaseProps = never\n>(configIn: Partial<StaticConfig> | StaticConfigParsed, ParentComponent?: StylableComponent) {\n const staticConfig = (() => {\n const next = extendStaticConfig(configIn, ParentComponent)\n if ('parsed' in next) {\n return next\n } else {\n return parseStaticConfig(next)\n }\n })()\n\n const defaultComponentClassName = `is_${staticConfig.componentName}`\n let tamaguiConfig: TamaguiInternalConfig\n let AnimatedText: any\n let AnimatedView: any\n let avoidClasses = true\n let defaultNativeStyle: any\n let defaultNativeStyleSheet: StyleSheet.NamedStyles<{ base: {} }>\n let tamaguiDefaultProps: any\n let initialSplitStyles: SplitStyleResult\n\n // see onConfiguredOnce below which attaches a name then to this component\n const component = forwardRef<Ref, ComponentPropTypes>((propsIn: any, forwardedRef) => {\n // React inserts default props after your props for some reason...\n // order important so we do loops, you can't just spread because JS does weird things\n let props: any\n if (tamaguiDefaultProps && !propsIn.asChild) {\n props = mergeProps(tamaguiDefaultProps, propsIn)[0]\n } else {\n props = propsIn\n }\n\n const hostRef = useRef<HTMLElement | View>(null)\n const { Component, isText, isZStack } = staticConfig\n const componentName = props.componentName || staticConfig.componentName\n const componentClassName = props.asChild\n ? ''\n : props.componentName\n ? `is_${props.componentName}`\n : defaultComponentClassName\n\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n const name = `${\n componentName || Component?.displayName || Component?.name || '[Unnamed Component]'\n }`\n const banner = `${name} ${propsIn['data-is'] || ''}`\n console.group(`%c \uD83D\uDC1B ${banner}`, 'background: yellow;')\n console.log('props', propsIn)\n console.log('ref', hostRef, '(click to view)')\n if (props['debug'] === 'break') {\n debugger\n }\n }\n }\n\n const forceUpdate = useForceUpdate()\n const theme = useTheme(props.theme, componentName, props, forceUpdate)\n const states = useState<TamaguiComponentState>(defaultComponentState)\n const state = propsIn.forceStyle ? { ...states[0], [propsIn.forceStyle]: true } : states[0]\n const setState = states[1]\n const setStateShallow = createShallowUpdate(setState)\n const languageContext = useContext(FontLanguageContext)\n\n const shouldAvoidClasses = !!(props.animation && avoidClasses)\n const shouldForcePseudo = !!propsIn.forceStyle\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const hasTextAncestor = !!(isWeb && isText ? useContext(TextAncestorContext) : false)\n const splitStyleState =\n !shouldAvoidClasses && !shouldForcePseudo\n ? {\n ...state,\n hasTextAncestor,\n dynamicStylesInline: true,\n }\n : ({\n ...state,\n noClassNames: true,\n dynamicStylesInline: true,\n hasTextAncestor,\n resolveVariablesAs: 'value',\n } as const)\n\n const splitStyles = useSplitStyles(\n props,\n staticConfig,\n theme,\n splitStyleState,\n props.asChild ? null : initialSplitStyles.classNames,\n languageContext || undefined,\n props['debug']\n )\n\n const { viewProps: viewPropsIn, pseudos, medias, style, classNames } = splitStyles\n const useAnimations = tamaguiConfig.animations?.useAnimations as UseAnimationHook | undefined\n const isAnimated = !!(useAnimations && props.animation)\n const hasEnterStyle = !!props.enterStyle\n\n const animationFeatureStylesIn = props.animation ? { ...defaultNativeStyle, ...style } : null\n\n const features = useFeatures(props, {\n forceUpdate,\n setStateShallow,\n useAnimations,\n state,\n style: animationFeatureStylesIn,\n pseudos,\n staticConfig,\n theme,\n hostRef,\n onDidAnimate: props.onDidAnimate,\n })\n\n const {\n tag,\n hitSlop,\n asChild,\n children,\n onPress,\n onPressIn,\n onPressOut,\n onHoverIn,\n onHoverOut,\n themeShallow,\n space: spaceProp,\n spaceDirection: _spaceDirection,\n disabled: disabledProp,\n onMouseUp,\n onMouseDown,\n onMouseEnter,\n onMouseLeave,\n hrefAttrs,\n separator,\n // ignore from here on out\n forceStyle: _forceStyle,\n // @ts-ignore for next/link compat etc\n onClick,\n theme: _themeProp,\n // @ts-ignore\n defaultVariants,\n\n ...nonTamaguiProps\n } = viewPropsIn\n\n // get the right component\n const isTaggable = !Component || typeof Component === 'string'\n\n // default to tag, fallback to component (when both strings)\n const element = isWeb ? (isTaggable ? tag || Component : Component) : Component\n const BaseTextComponent = !isWeb ? Text : element || 'span'\n const BaseViewComponent = !isWeb ? View : element || (hasTextAncestor ? 'span' : 'div')\n let elementType = isText\n ? (isAnimated ? AnimatedText || Text : null) || BaseTextComponent\n : (isAnimated ? AnimatedView || View : null) || BaseViewComponent\n\n elementType = Component || elementType\n const isStringElement = typeof elementType === 'string'\n\n const disabled =\n (props.accessibilityState != null && props.accessibilityState.disabled === true) ||\n props.accessibilityDisabled\n\n // these can ultimately be for DOM, react-native-web views, or animated views\n // so the type is pretty loose\n let viewProps: Record<string, any>\n\n // if react-native-web view just pass all props down\n if (process.env.TAMAGUI_TARGET === 'web' && !staticConfig.isReactNativeWeb) {\n // otherwise replicate react-native-web functionality\n const {\n // event props\n onMoveShouldSetResponder,\n onMoveShouldSetResponderCapture,\n onResponderEnd,\n onResponderGrant,\n onResponderMove,\n onResponderReject,\n onResponderRelease,\n onResponderStart,\n onResponderTerminate,\n onResponderTerminationRequest,\n onScrollShouldSetResponder,\n onScrollShouldSetResponderCapture,\n onSelectionChangeShouldSetResponder,\n onSelectionChangeShouldSetResponderCapture,\n onStartShouldSetResponder,\n onStartShouldSetResponderCapture,\n\n // react-native props\n nativeID,\n\n // react-native-web accessibility props\n // @ts-ignore\n accessibilityActiveDescendant,\n // @ts-ignore\n accessibilityAtomic,\n // @ts-ignore\n accessibilityAutoComplete,\n // @ts-ignore\n accessibilityBusy,\n // @ts-ignore\n accessibilityChecked,\n // @ts-ignore\n accessibilityColumnCount,\n // @ts-ignore\n accessibilityColumnIndex,\n // @ts-ignore\n accessibilityColumnSpan,\n // @ts-ignore\n accessibilityControls,\n // @ts-ignore\n accessibilityCurrent,\n // @ts-ignore\n accessibilityDescribedBy,\n // @ts-ignore\n accessibilityDetails,\n // @ts-ignore\n accessibilityDisabled,\n // @ts-ignore\n accessibilityErrorMessage,\n // @ts-ignore\n accessibilityExpanded,\n // @ts-ignore\n accessibilityFlowTo,\n // @ts-ignore\n accessibilityHasPopup,\n // @ts-ignore\n accessibilityHidden,\n // @ts-ignore\n accessibilityInvalid,\n // @ts-ignore\n accessibilityKeyShortcuts,\n // @ts-ignore\n accessibilityLabel,\n // @ts-ignore\n accessibilityLabelledBy,\n // @ts-ignore\n accessibilityLevel,\n // @ts-ignore\n accessibilityLiveRegion,\n // @ts-ignore\n accessibilityModal,\n // @ts-ignore\n accessibilityMultiline,\n // @ts-ignore\n accessibilityMultiSelectable,\n // @ts-ignore\n accessibilityOrientation,\n // @ts-ignore\n accessibilityOwns,\n // @ts-ignore\n accessibilityPlaceholder,\n // @ts-ignore\n accessibilityPosInSet,\n // @ts-ignore\n accessibilityPressed,\n // @ts-ignore\n accessibilityReadOnly,\n // @ts-ignore\n accessibilityRequired,\n // @ts-ignore\n accessibilityRole,\n // @ts-ignore\n accessibilityRoleDescription,\n // @ts-ignore\n accessibilityRowCount,\n // @ts-ignore\n accessibilityRowIndex,\n // @ts-ignore\n accessibilityRowSpan,\n // @ts-ignore\n accessibilitySelected,\n // @ts-ignore\n accessibilitySetSize,\n // @ts-ignore\n accessibilitySort,\n // @ts-ignore\n accessibilityValueMax,\n // @ts-ignore\n accessibilityValueMin,\n // @ts-ignore\n accessibilityValueNow,\n // @ts-ignore\n accessibilityValueText,\n\n // deprecated\n accessible,\n accessibilityState,\n accessibilityValue,\n\n // android\n collapsable,\n focusable,\n\n onLayout,\n\n ...webProps\n } = nonTamaguiProps\n\n viewProps = webProps\n\n assignNativePropsToWeb(elementType, viewProps, nonTamaguiProps)\n\n useElementLayout(hostRef, onLayout)\n\n // from react-native-web\n useResponderEvents(hostRef, {\n onMoveShouldSetResponder,\n onMoveShouldSetResponderCapture,\n onResponderEnd,\n onResponderGrant,\n onResponderMove,\n onResponderReject,\n onResponderRelease,\n onResponderStart,\n onResponderTerminate,\n onResponderTerminationRequest,\n onScrollShouldSetResponder,\n onScrollShouldSetResponderCapture,\n onSelectionChangeShouldSetResponder,\n onSelectionChangeShouldSetResponderCapture,\n onStartShouldSetResponder,\n onStartShouldSetResponderCapture,\n })\n\n // from react-native-web\n const platformMethodsRef = usePlatformMethods(viewProps)\n\n const setRef = useMergeRefs(hostRef, platformMethodsRef, forwardedRef as any)\n viewProps.ref = setRef\n\n if (props.href != undefined && hrefAttrs != undefined) {\n const { download, rel, target } = hrefAttrs\n if (download != null) {\n viewProps.download = download\n }\n if (rel != null) {\n viewProps.rel = rel\n }\n if (typeof target === 'string') {\n viewProps.target = target.charAt(0) !== '_' ? '_' + target : target\n }\n }\n\n // FOCUS\n // \"focusable\" indicates that an element may be a keyboard tab-stop.\n const _focusable = focusable != undefined ? focusable : accessible\n const role = viewProps.role\n if (_focusable === false) {\n viewProps.tabIndex = '-1'\n }\n if (\n // These native elements are focusable by default\n elementType === 'a' ||\n elementType === 'button' ||\n elementType === 'input' ||\n elementType === 'select' ||\n elementType === 'textarea'\n ) {\n if (_focusable === false || accessibilityDisabled === true) {\n viewProps.tabIndex = '-1'\n }\n } else if (\n // These roles are made focusable by default\n role === 'button' ||\n role === 'checkbox' ||\n role === 'link' ||\n role === 'radio' ||\n role === 'textbox' ||\n role === 'switch'\n ) {\n if (_focusable !== false) {\n viewProps.tabIndex = '0'\n }\n }\n // Everything else must explicitly set the prop\n if (_focusable === true) {\n viewProps.tabIndex = '0'\n }\n } else {\n viewProps = nonTamaguiProps\n if (forwardedRef) {\n // @ts-ignore\n viewProps.ref = forwardedRef\n }\n }\n\n if (process.env.NODE_ENV === 'development' && !isText && isWeb) {\n Children.toArray(props.children).forEach((item) => {\n if (typeof item === 'string') {\n console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`)\n }\n })\n }\n\n // isMounted\n const internal = useRef<{ isMounted: boolean; unmountEffects?: Function[] }>()\n if (!internal.current) {\n internal.current = {\n isMounted: true,\n }\n }\n\n useIsomorphicLayoutEffect(() => {\n // we need to use state to properly have mounted go from false => true\n if (typeof window !== 'undefined' && (hasEnterStyle || props.animation)) {\n // for SSR we never set mounted, ensuring enterStyle={{}} is set by default\n setStateShallow({\n mounted: true,\n })\n }\n\n internal.current!.isMounted = true\n return () => {\n mouseUps.delete(unPress)\n internal.current!.isMounted = false\n internal.current!.unmountEffects?.forEach((cb) => cb())\n }\n }, [hasEnterStyle, props.animation])\n\n let styles: any[]\n\n const animationStyles = state.animation ? state.animation.style : null\n\n if (isStringElement && shouldAvoidClasses && !shouldForcePseudo) {\n styles = {\n ...defaultNativeStyle,\n ...(animationStyles ?? style),\n ...medias,\n }\n } else {\n styles = [\n isWeb ? null : defaultNativeStyleSheet ? (defaultNativeStyleSheet.base as ViewStyle) : null,\n animationStyles ?? style,\n medias,\n ]\n if (!animationStyles) {\n const initPseudos = initialSplitStyles.pseudos\n const force = shouldForcePseudo\n !state.mounted && addPseudoToStyles(styles, initPseudos, pseudos, 'enterStyle')\n state.hover && addPseudoToStyles(styles, initPseudos, pseudos, 'hoverStyle', force)\n state.focus && addPseudoToStyles(styles, initPseudos, pseudos, 'focusStyle', force)\n state.press && addPseudoToStyles(styles, initPseudos, pseudos, 'pressStyle', force)\n }\n // ugly but for now...\n if (shouldForcePseudo) {\n const next = {}\n for (const style of styles) {\n if (style) {\n Object.assign(next, style)\n }\n }\n // @ts-ignore\n Object.assign(splitStyles.style, next)\n }\n }\n\n if (process.env.TAMAGUI_TARGET === 'web') {\n const fontFamilyName = isText\n ? props.fontFamily || staticConfig.defaultProps.fontFamily\n : null\n\n let fontFamily: string | null = null\n if (fontFamilyName) {\n if (fontFamilyName[0] === '$') {\n fontFamily = fontFamilyName.slice(1)\n }\n }\n\n const classList = [\n componentName ? componentClassName : '',\n fontFamily ? `font_${fontFamily}` : '',\n theme.className,\n classNames ? Object.values(classNames).join(' ') : '',\n ]\n\n const className = classList.join(' ')\n const style = animationStyles ?? splitStyles.style\n\n // TODO this is specific to reanimated rn\n const isAnimatedReactNativeWeb = props.animation && avoidClasses\n\n if (staticConfig.isReactNativeWeb || isAnimatedReactNativeWeb) {\n viewProps.dataSet = {\n ...viewProps.dataSet,\n className,\n id: props.id,\n }\n if (props['data-is']) {\n viewProps.dataSet.is = props['data-is']\n }\n } else {\n viewProps.className = className\n }\n\n viewProps.style = style\n } else {\n viewProps.style = styles\n }\n\n // TODO need to loop active variants and see if they have matchin pseudos and apply as well\n const initialPseudos = initialSplitStyles.pseudos\n const attachPress = !!(\n pseudos?.pressStyle ||\n initialPseudos?.pressStyle ||\n onPress ||\n onPressOut ||\n onPressIn ||\n onClick\n )\n\n const isHoverable = isWeb\n const attachHover =\n isHoverable &&\n !!((pseudos && pseudos.hoverStyle) || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave)\n\n const handlesPressEvents = !isStringElement && !asChild\n const pressKey = handlesPressEvents ? 'onPress' : 'onClick'\n const pressInKey = handlesPressEvents ? 'onPressIn' : 'onMouseDown'\n const pressOutKey = handlesPressEvents ? 'onPressOut' : 'onMouseUp'\n\n // check presence to prevent reparenting bugs, allows for onPress={x ? function : undefined} usage\n const shouldAttach =\n !asChild &&\n (attachPress ||\n attachHover ||\n 'pressStyle' in props ||\n 'onPress' in props ||\n 'onPressIn' in props ||\n 'onPressOut' in props ||\n (isWeb &&\n ('hoverStyle' in props ||\n 'onHoverIn' in props ||\n 'onHoverOut' in props ||\n 'onMouseEnter' in props ||\n 'onMouseLeave' in props)))\n\n const unPress = useCallback(() => {\n if (!internal.current!.isMounted) return\n setStateShallow({\n press: false,\n pressIn: false,\n })\n }, [])\n\n const events = shouldAttach\n ? {\n [pressOutKey]: attachPress\n ? (e) => {\n unPress()\n onPressOut?.(e)\n onMouseUp?.(e)\n }\n : undefined,\n ...(isHoverable && {\n onMouseEnter: attachHover\n ? (e) => {\n const next: Partial<typeof state> = {}\n if (attachHover) {\n next.hover = true\n }\n if (state.pressIn) {\n next.press = true\n }\n if (Object.keys(next).length) {\n setStateShallow(next)\n }\n onHoverIn?.(e)\n onMouseEnter?.(e)\n }\n : undefined,\n onMouseLeave: attachHover\n ? (e) => {\n const next: Partial<typeof state> = {}\n mouseUps.add(unPress)\n if (attachHover) {\n next.hover = false\n }\n if (state.pressIn) {\n next.press = false\n next.pressIn = false\n }\n if (Object.keys(next).length) {\n setStateShallow(next)\n }\n onHoverOut?.(e)\n onMouseLeave?.(e)\n }\n : undefined,\n }),\n [pressInKey]: attachPress\n ? (e) => {\n setStateShallow({\n press: true,\n pressIn: true,\n hover: false,\n })\n onPressIn?.(e)\n onMouseDown?.(e)\n if (isWeb) {\n mouseUps.add(unPress)\n }\n }\n : null,\n [pressKey]: attachPress\n ? (e) => {\n unPress()\n onClick?.(e)\n onPress?.(e)\n }\n : null,\n\n // replicating TouchableWithoutFeedback\n ...(!isWeb && {\n cancelable: !props.rejectResponderTermination,\n disabled: props.disabled !== null ? props.disabled : props.accessibilityState?.disabled,\n hitSlop: props.hitSlop,\n delayLongPress: props.delayLongPress,\n delayPressIn: props.delayPressIn,\n delayPressOut: props.delayPressOut,\n focusable: viewProps.focusable ?? true,\n minPressDuration: 0,\n }),\n }\n : null\n\n let space = spaceProp\n // find space by media query\n if (features.enabled.mediaQuery) {\n for (const key in mediaState) {\n if (!mediaState[key]) continue\n if (props[key] && props[key].space !== undefined) {\n space = props[key].space\n }\n }\n }\n\n const themeManager = getThemeManager(theme)\n\n const shouldSetChildrenThemeToParent = Boolean(\n themeShallow && themeManager && themeManager.didChangeTheme\n )\n\n const shouldProvideThemeManager =\n shouldSetChildrenThemeToParent || (themeManager && themeManager.didChangeTheme)\n\n const childEls =\n !children || asChild\n ? children\n : wrapThemeManagerContext(\n spacedChildren({\n separator,\n children,\n space,\n direction: props.spaceDirection || 'both',\n isZStack,\n }),\n // only set context if changed theme\n shouldProvideThemeManager ? themeManager : undefined,\n shouldSetChildrenThemeToParent\n )\n\n let content: any\n\n if (asChild) {\n elementType = Slot\n viewProps = {\n ...viewProps,\n onPress,\n onPressIn,\n onPressOut,\n }\n }\n\n // EVENTS: web\n if (isWeb) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [pressableProps] = usePressable(\n events\n ? {\n disabled,\n ...(hitSlop && {\n hitSlop,\n }),\n onPressOut: events[pressOutKey],\n onPressIn: events[pressInKey],\n onPress: events[pressKey],\n }\n : {\n disabled: true,\n }\n )\n if (events) {\n if (handlesPressEvents) {\n Object.assign(viewProps, pressableProps)\n } else {\n Object.assign(viewProps, events)\n }\n }\n }\n\n // add focus events\n if (process.env.TAMAGUI_TARGET === 'native') {\n const attachFocus = !!(\n (pseudos && pseudos.focusStyle) ||\n (initialPseudos && initialPseudos.focusStyle)\n )\n if (attachFocus) {\n viewProps.onFocus = mergeEvent(viewProps.onFocus, () => {\n setStateShallow({ focus: true })\n })\n viewProps.onBlur = mergeEvent(viewProps.onBlur, () => {\n setStateShallow({ focus: false })\n })\n }\n }\n\n // EVENTS native\n // use Pressability to get smooth unPress when you press + hold + move out\n if (process.env.TAMAGUI_TARGET === 'native') {\n // only ever create once, use .configure() to update later\n const pressability = usePressability(events)\n if (attachPress && events) {\n const dontComposePressabilityKeys = {\n onClick: true,\n }\n if (hitSlop) {\n viewProps.hitSlop = hitSlop\n }\n for (const key in pressability) {\n const og = props[key]\n const val = pressability[key]\n viewProps[key] =\n og && !dontComposePressabilityKeys[key] ? composeEventHandlers(og, val) : val\n }\n }\n }\n\n content = createElement(elementType, viewProps, childEls)\n\n if (process.env.TAMAGUI_TARGET === 'web') {\n // only necessary when animating because some AnimatedView which wraps RNW View doesn't forward dataSet className\n const isAnimatedRNWView = isAnimated && typeof elementType !== 'string' // assuming for now as reanimated is only driver\n const shouldWrapWithComponentTheme =\n isAnimatedRNWView && getReturnVariablesAs(props, splitStyleState) === 'non-color-value'\n const shouldWrapWithHover = events && attachHover\n\n if (shouldWrapWithHover || shouldWrapWithComponentTheme) {\n const themeClassName = shouldWrapWithComponentTheme ? `${theme.className}` : ''\n const hoverClassName = shouldWrapWithHover ? 't_Hoverable' : ''\n content = (\n <span\n className={`${hoverClassName} ${themeClassName}`}\n style={{\n display: 'contents',\n }}\n {...(shouldWrapWithHover && {\n onMouseEnter: events.onMouseEnter,\n onMouseLeave: events.onMouseLeave,\n })}\n >\n {content}\n </span>\n )\n }\n }\n\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n // prettier-ignore\n console.groupCollapsed('props out', viewProps, typeof elementType === 'string' ? elementType : 'Component')\n for (const key in viewProps) {\n console.log(key, viewProps[key])\n }\n console.log('children', content)\n console.groupEnd()\n if (typeof window !== 'undefined') {\n // prettier-ignore\n console.log({ state, shouldProvideThemeManager, tamaguiDefaultProps, viewProps, splitStyles, animationStyles, handlesPressEvents, isStringElement, classNamesIn: props.className?.split(' '), classNamesOut: viewProps.className?.split(' '), events, shouldAttach, styles, pseudos, content, childEls, shouldAvoidClasses, avoidClasses, animation: props.animation, style, defaultNativeStyle, initialSplitStyles, ...(typeof window !== 'undefined' ? { theme, themeClassName: theme.className, staticConfig, tamaguiConfig, events, shouldAvoidClasses, shouldForcePseudo, classNames: Object.fromEntries(Object.entries(classNames).map(([k, v]) => [v, getAllSelectors()[v]])) } : null) })\n }\n console.groupEnd()\n }\n }\n\n return features.elements.length ? (\n <>\n {features.elements}\n {content}\n </>\n ) : (\n content\n )\n })\n\n if (staticConfig.componentName) {\n component.displayName = staticConfig.componentName\n }\n\n // Once configuration is run and all components are registered\n // get default props + className and analyze styles\n onConfiguredOnce((conf) => {\n if (process.env.IS_STATIC === 'is_static') {\n // in static mode we just use these to lookup configuration\n return\n }\n\n tamaguiConfig = conf\n\n // do this to make sure shorthands don't duplicate with.. longhands\n mergeShorthands(staticConfig, tamaguiConfig)\n\n if (tamaguiConfig.animations) {\n avoidClasses = !!tamaguiConfig.animations.avoidClasses\n AnimatedText = tamaguiConfig.animations.Text\n AnimatedView = tamaguiConfig.animations.View\n }\n\n initialTheme =\n initialTheme ||\n proxyThemeVariables(conf.themes[conf.defaultTheme || Object.keys(conf.themes)[0]])\n\n // adds in user defined default props\n config = getConfig()\n\n let defaultPropsIn = staticConfig.defaultProps || {}\n\n // because we run createTamagui after styled() defs, have to do some work here\n // gather defaults props one time and merge downwards\n // find last unprocessed and process\n const parentNames = [...(staticConfig.parentNames || []), staticConfig.componentName]\n\n if (config.defaultProps && parentNames && staticConfig.componentName) {\n defaultPropsIn = mergeConfigDefaultProps(\n staticConfig.componentName,\n defaultPropsIn,\n config.defaultProps,\n parentNames\n )\n }\n\n const debug = process.env.NODE_ENV === 'development' ? defaultPropsIn['debug'] : false\n\n if (process.env.NODE_ENV === 'development' && debug === 'break') {\n debugger\n }\n\n // remove all classNames\n const [parentProps, parentClassNames] = mergeProps(defaultPropsIn, {}, true)\n\n initialSplitStyles = insertSplitStyles(\n parentProps,\n staticConfig,\n initialTheme,\n {\n mounted: true,\n hover: false,\n press: false,\n pressIn: false,\n focus: false,\n resolveVariablesAs: 'both',\n keepVariantsAsProps: true,\n },\n undefined,\n undefined,\n debug\n )\n\n if (debug) {\n console.log('initialSplitStyles', initialSplitStyles)\n }\n\n // must preserve prop order\n // leave out className because we handle that already with initialSplitStyles.classNames\n // otherwise it confuses variant functions getting className props\n const [defaults, defaultsClassnames] = mergeProps(\n component.defaultProps as any,\n initialSplitStyles.viewProps,\n true\n )\n\n // avoid passing className props to variants\n initialSplitStyles.classNames = {\n ...parentClassNames,\n ...defaultsClassnames,\n ...initialSplitStyles.classNames,\n }\n\n defaultNativeStyle = {}\n\n const validStyles = staticConfig.validStyles || stylePropsView\n\n // split - keep variables on props to be processed using theme values at runtime (native)\n if (!isWeb) {\n for (const key in staticConfig.defaultProps) {\n const val = staticConfig.defaultProps[key]\n if (validPseudoKeys[key]) continue\n if ((typeof val === 'string' && val[0] === '$') || !validStyles[key]) {\n defaults[key] = val\n } else {\n defaultNativeStyle[key] = val\n }\n }\n }\n\n defaultNativeStyleSheet = StyleSheet.create({\n base: defaultNativeStyle,\n })\n\n if (Object.keys(defaults).length) {\n tamaguiDefaultProps = defaults\n }\n\n // add debug logs\n if (process.env.NODE_ENV === 'development' && debug) {\n if (process.env.IS_STATIC !== 'is_static') {\n console.log(`\uD83D\uDC1B [${staticConfig.componentName || 'Component'}]`, {\n staticConfig,\n initialSplitStyles,\n tamaguiDefaultProps,\n defaultNativeStyle,\n defaults,\n defaultPropsIn,\n })\n }\n }\n })\n\n let res: TamaguiComponent<ComponentPropTypes, Ref, BaseProps> = component as any\n\n if (configIn.memo) {\n res = memo(res) as any\n }\n\n res.staticConfig = {\n validStyles: staticConfig.validStyles || stylePropsView,\n ...staticConfig,\n }\n\n // res.extractable HoC\n res.extractable = (Component: any, conf?: Partial<StaticConfig>) => {\n Component.staticConfig = extendStaticConfig(\n {\n Component,\n ...conf,\n neverFlatten: true,\n isExtractable: true,\n defaultProps: {\n ...Component.defaultProps,\n ...conf?.defaultProps,\n },\n },\n res\n )\n return Component\n }\n\n return res\n}\n\n// for elements to avoid spacing\nexport const Unspaced = (props: { children?: any }) => {\n return props.children\n}\nUnspaced['isUnspaced'] = true\n\n// dont used styled() here to avoid circular deps\n// keep inline to avoid circular deps\n\nexport const Spacer = createComponent<SpacerProps>({\n memo: true,\n componentName: 'Spacer',\n validStyles,\n defaultProps: {\n ...stackDefaultStyles,\n size: true,\n },\n variants: {\n size: {\n '...size': (size, { tokens }) => {\n size = size == true ? '$true' : size\n const sizePx = tokens.space[size] ?? size\n return {\n width: sizePx,\n height: sizePx,\n minWidth: sizePx,\n minHeight: sizePx,\n }\n },\n },\n\n flex: {\n true: {\n flexGrow: 1,\n },\n },\n\n direction: {\n horizontal: {\n height: 0,\n minHeight: 0,\n },\n vertical: {\n width: 0,\n minWidth: 0,\n },\n both: {},\n },\n },\n\n defaultVariants: {\n direction: 'both',\n },\n})\n\nexport type SpacedChildrenProps = {\n isZStack?: boolean\n children?: React.ReactNode\n space?: SpaceTokens | number | null\n spaceFlex?: boolean | number\n direction?: SpaceDirection\n separator?: React.ReactNode\n}\n\nexport function spacedChildren({\n isZStack,\n children,\n space,\n direction,\n spaceFlex,\n separator,\n}: SpacedChildrenProps) {\n const hasSpace = !!(space || spaceFlex)\n const hasSeparator = !(separator === undefined || separator === null)\n if (!hasSpace && !hasSeparator && !isZStack) {\n return children\n }\n const childrenList = Children.toArray(children)\n if (childrenList.length <= 1 && !isZStack) {\n return childrenList\n }\n const final: React.ReactNode[] = []\n for (const [index, child] of childrenList.entries()) {\n const isEmpty =\n child === null || child === undefined || (Array.isArray(child) && child.length === 0)\n\n // push them all, but wrap some in Fragment\n if (isEmpty || !child || (child['key'] && !isZStack)) {\n final.push(child)\n } else {\n final.push(\n <Fragment key={index}>{isZStack ? <AbsoluteFill>{child}</AbsoluteFill> : child}</Fragment>\n )\n }\n\n // first child unspaced avoid insert space\n if (isUnspaced(child) && index === 0) {\n continue\n }\n\n // no spacing on ZStack\n if (isZStack) {\n continue\n }\n\n const next = childrenList[index + 1]\n\n if (next && !isUnspaced(next)) {\n if (separator) {\n if (hasSpace) {\n final.push(\n createSpacer({\n key: `_${index}_before_sep_spacer`,\n direction,\n space,\n spaceFlex,\n })\n )\n }\n final.push(\n React.isValidElement(separator)\n ? React.cloneElement(separator, { key: `sep_${index}` })\n : separator\n )\n if (hasSpace) {\n final.push(\n createSpacer({\n key: `_${index}_after_sep_spacer`,\n direction,\n space,\n spaceFlex,\n })\n )\n }\n } else {\n final.push(\n createSpacer({\n key: `_${index}_spacer`,\n direction,\n space,\n spaceFlex,\n })\n )\n }\n }\n }\n\n return final\n}\n\ntype CreateSpacerProps = SpacedChildrenProps & { key: string }\n\nfunction createSpacer({ key, direction, space, spaceFlex }: CreateSpacerProps) {\n return (\n <Spacer\n key={key}\n size={space}\n direction={direction}\n {...(spaceFlex && {\n flex: spaceFlex,\n })}\n />\n )\n}\n\nfunction isUnspaced(child: React.ReactNode) {\n // console.log('unspaced?', child, getMedia())\n return child?.['type']?.['isVisuallyHidden'] || child?.['type']?.['isUnspaced']\n}\n\nfunction AbsoluteFill(props: { children?: any }) {\n return (\n <View pointerEvents=\"box-none\" style={StyleSheet.absoluteFill}>\n {props.children}\n </View>\n )\n}\n\n// this can be done with CSS entirely right?\n// const shouldWrapTextAncestor = isWeb && isText && !hasTextAncestor\n// if (shouldWrapTextAncestor) {\n// // from react-native-web\n// content = createElement(TextAncestorContext.Provider, { value: true }, content)\n// }\n\nexport function processIDRefList(idRefList: string | Array<string>): string {\n return Array.isArray(idRefList) ? idRefList.join(' ') : idRefList\n}\n\nexport const accessibilityRoleToWebRole = {\n adjustable: 'slider',\n button: 'button',\n header: 'heading',\n image: 'img',\n imagebutton: null,\n keyboardkey: null,\n label: null,\n link: 'link',\n none: 'presentation',\n search: 'search',\n summary: 'region',\n text: null,\n}\n\nfunction addPseudoToStyles(\n styles: any[],\n initialPseudos: SplitStyleResult['pseudos'],\n pseudos: any,\n name: string,\n force = false\n) {\n // on web use pseudo object { hoverStyle } to keep specificity with concatClassName\n const pseudoStyle = pseudos[name]\n const shouldNestObject = isWeb && name !== 'enterStyle' && name !== 'exitStyle'\n const defaultPseudoStyle = initialPseudos[name]\n const style = defaultPseudoStyle ? { ...defaultPseudoStyle, ...pseudoStyle } : pseudoStyle\n if (style) {\n styles.push(shouldNestObject && !force ? { [name]: style } : style)\n }\n}\n\nconst DefaultProps = new Map()\n\nfunction mergeConfigDefaultProps(\n name: string,\n props: Record<string, any>,\n configDefaults: Record<string, Object>,\n parentNames: (string | undefined)[]\n) {\n const len = parentNames.length\n let prev\n\n for (let i = 0; i < len; i++) {\n const n = parentNames[i]\n if (!n) continue\n if (DefaultProps.has(n)) {\n prev = DefaultProps.get(n)\n continue\n }\n const props = configDefaults[n]\n if (!props) {\n if (prev) {\n DefaultProps.set(n, prev)\n }\n continue\n }\n prev = mergeProps(prev || {}, props)[0]\n console.log('set prev', prev)\n DefaultProps.set(n, prev)\n }\n\n // overwrite the user defined defaults on top of internal defined defaults\n const ourDefaultsMerged = DefaultProps.get(name)\n if (ourDefaultsMerged) {\n return mergeProps(props, ourDefaultsMerged)[0]\n }\n return props\n}\n"],
|
|
5
5
|
"mappings": "AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAeA;AACA;AACA;AAEA,MAAM;AAEN,MAAM,wBAA+C,OAAO,OAAO;AAAA,EACjE,OAAO;AAAA,EACP,OAAO;AAAA,EACP,SAAS;AAAA,EACT,OAAO;AAAA,EAEP,SAAS;AAAA,EACT,WAAW;AACb,CAAC;AAEM,MAAM,WAAW,oBAAI,IAAc;AAC1C,IAAI,OAAO,aAAa,aAAa;AACnC,WAAS,iBAAiB,WAAW,MAAM;AACzC,aAAS,QAAQ,CAAC,MAAM,EAAE,CAAC;AAC3B,aAAS,MAAM;AAAA,EACjB,CAAC;AACD,WAAS,iBAAiB,YAAY,MAAM;AAC1C,aAAS,QAAQ,CAAC,MAAM,EAAE,CAAC;AAC3B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AAS;AACpE,QAAM,qBAAqB,eAAe;AAC1C,QAAM,QAAQ,qBAAqB,EAAE,GAAG,oBAAoB,GAAG,YAAY,IAAI;AAC/E,MAAI,OAAO;AACT,WAAO,KAAK,oBAAoB,CAAC,QAAQ,EAAE,CAAC,OAAO,MAAM,IAAI,KAAK;AAAA,EACpE;AACF;AAEA,MAAM,eAAe,oBAAI,IAAI;AAE7B,iCACE,MACA,OACA,gBACA,aACA;AACA,QAAM,MAAM,YAAY;AACxB,MAAI;AAEJ,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC5B,UAAM,IAAI,YAAY;AACtB,QAAI,CAAC;AAAG;AACR,QAAI,aAAa,IAAI,CAAC,GAAG;AACvB,aAAO,aAAa,IAAI,CAAC;AACzB;AAAA,IACF;AACA,UAAM,SAAQ,eAAe;AAC7B,QAAI,CAAC,QAAO;AACV,UAAI,MAAM;AACR,qBAAa,IAAI,GAAG,IAAI;AAAA,MAC1B;AACA;AAAA,IACF;AACA,WAAO,WAAW,QAAQ,CAAC,GAAG,MAAK,EAAE;AACrC,YAAQ,IAAI,YAAY,IAAI;AAC5B,iBAAa,IAAI,GAAG,IAAI;AAAA,EAC1B;AAGA,QAAM,oBAAoB,aAAa,IAAI,IAAI;AAC/C,MAAI,mBAAmB;AACrB,WAAO,WAAW,OAAO,iBAAiB,EAAE;AAAA,EAC9C;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { configListeners, setConfig } from "./conf";
|
|
2
|
-
import { THEME_CLASSNAME_PREFIX } from "./constants/constants";
|
|
3
2
|
import { isWeb } from "./constants/platform";
|
|
4
|
-
import { themeToVariableToValueMap } from "./createTheme";
|
|
5
|
-
import { createVariable, isVariable } from "./createVariable";
|
|
6
3
|
import { createVariables } from "./createVariables";
|
|
7
4
|
import { createTamaguiProvider } from "./helpers/createTamaguiProvider";
|
|
5
|
+
import { getThemeCSSRules } from "./helpers/getThemeCSSRules";
|
|
8
6
|
import { getAllRules } from "./helpers/insertStyleRule";
|
|
9
7
|
import {
|
|
10
8
|
registerCSSVariable,
|
|
11
9
|
tokensValueToVariable,
|
|
12
10
|
variableToCSS
|
|
13
11
|
} from "./helpers/registerCSSVariable";
|
|
14
|
-
import {
|
|
12
|
+
import { ensureThemeVariable, proxyThemeToParents } from "./helpers/themes";
|
|
15
13
|
import { configureMedia } from "./hooks/useMedia";
|
|
16
14
|
import { parseFont, registerFontVariables } from "./insertFont";
|
|
17
15
|
import { Tamagui } from "./Tamagui";
|
|
@@ -45,7 +43,7 @@ function createTamagui(config) {
|
|
|
45
43
|
})();
|
|
46
44
|
const themeConfig = (() => {
|
|
47
45
|
const themes = { ...config.themes };
|
|
48
|
-
|
|
46
|
+
let cssRuleSets = [];
|
|
49
47
|
if (isWeb) {
|
|
50
48
|
let declarationsToRuleSet2 = function(decs, selector = "") {
|
|
51
49
|
return `:root${selector} {${sep}${[...decs].join(`;${sep}`)}${sep}}`;
|
|
@@ -70,17 +68,15 @@ function createTamagui(config) {
|
|
|
70
68
|
cssRuleSets.push(declarationsToRuleSet2(declarations));
|
|
71
69
|
if (fontDeclarations) {
|
|
72
70
|
for (const key in fontDeclarations) {
|
|
73
|
-
const { name, declarations: declarations2, language } = fontDeclarations[key];
|
|
74
|
-
const languageSelector = ` .t_lang-${name}-${language || "default"}`;
|
|
71
|
+
const { name, declarations: declarations2, language = "default" } = fontDeclarations[key];
|
|
75
72
|
const fontSelector = `.font_${name}`;
|
|
76
|
-
const
|
|
73
|
+
const langSelector = `:root .t_lang-${name}-${language} ${fontSelector}`;
|
|
74
|
+
const selectors = language === "default" ? ` ${fontSelector}, ${langSelector}` : langSelector;
|
|
77
75
|
const specificRuleSet = declarationsToRuleSet2(declarations2, selectors);
|
|
78
76
|
cssRuleSets.push(specificRuleSet);
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
79
|
}
|
|
82
|
-
const hasDarkLight = "light" in config.themes && "dark" in config.themes;
|
|
83
|
-
const CNP = `.${THEME_CLASSNAME_PREFIX}`;
|
|
84
80
|
const dedupedThemes = {};
|
|
85
81
|
const existing = /* @__PURE__ */ new WeakMap();
|
|
86
82
|
for (const themeName in themes) {
|
|
@@ -91,7 +87,7 @@ function createTamagui(config) {
|
|
|
91
87
|
e.names.push(themeName);
|
|
92
88
|
continue;
|
|
93
89
|
}
|
|
94
|
-
const theme = { ...
|
|
90
|
+
const theme = { ...rawTheme };
|
|
95
91
|
for (const key in theme) {
|
|
96
92
|
ensureThemeVariable(theme, key);
|
|
97
93
|
}
|
|
@@ -100,99 +96,22 @@ function createTamagui(config) {
|
|
|
100
96
|
names: [themeName],
|
|
101
97
|
theme
|
|
102
98
|
};
|
|
103
|
-
existing.set(
|
|
99
|
+
existing.set(rawTheme, dedupedThemes[themeName]);
|
|
104
100
|
}
|
|
105
101
|
if (isWeb) {
|
|
106
102
|
for (const themeName in dedupedThemes) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
varToValMap[variable.variable] = variable.val;
|
|
116
|
-
}
|
|
117
|
-
if (variable.isFloating || !tokensValueToVariable.has(variable.val)) {
|
|
118
|
-
value = variable.val;
|
|
119
|
-
} else {
|
|
120
|
-
value = tokensValueToVariable.get(variable.val).variable;
|
|
121
|
-
}
|
|
122
|
-
vars += `--${themeKey}:${value};`;
|
|
123
|
-
}
|
|
124
|
-
const isDarkOrLightBase = themeName === "dark" || themeName === "light";
|
|
125
|
-
const selectors = names.map((name) => {
|
|
126
|
-
return `${CNP}${name}`;
|
|
127
|
-
});
|
|
128
|
-
if (hasDarkLight) {
|
|
129
|
-
for (const subName of names) {
|
|
130
|
-
const isDark = isDarkOrLightBase || subName.startsWith("dark_");
|
|
131
|
-
const childSelector = `${CNP}${subName.replace(isDark ? "dark_" : "light_", "")}`;
|
|
132
|
-
const order = isDark ? ["dark", "light"] : ["light", "dark"];
|
|
133
|
-
if (isDarkOrLightBase) {
|
|
134
|
-
order.reverse();
|
|
135
|
-
}
|
|
136
|
-
const [stronger, weaker] = order;
|
|
137
|
-
const max = config.maxDarkLightNesting ?? 3;
|
|
138
|
-
new Array(Math.round(max * 1.5)).fill(void 0).forEach((_, pi) => {
|
|
139
|
-
const isOdd = pi % 2 === 1;
|
|
140
|
-
if (isOdd && pi < 3)
|
|
141
|
-
return;
|
|
142
|
-
const parents = new Array(pi + 1).fill(void 0).map((_2, psi) => {
|
|
143
|
-
return `${CNP}${psi % 2 === 0 ? stronger : weaker}`;
|
|
144
|
-
});
|
|
145
|
-
let parentSelectors = parents.length > 1 ? parents.slice(1) : parents;
|
|
146
|
-
if (isOdd) {
|
|
147
|
-
const [_first, second, ...rest] = parentSelectors;
|
|
148
|
-
parentSelectors = [second, ...rest, second];
|
|
149
|
-
}
|
|
150
|
-
const lastParentSelector = parentSelectors[parentSelectors.length - 1];
|
|
151
|
-
selectors.push(`${parentSelectors.join(" ")} ${childSelector === lastParentSelector ? "" : childSelector}`);
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
const rootSep = config.themeClassNameOnRoot ? "" : " ";
|
|
156
|
-
const css2 = `${selectors.map((x) => `:root${rootSep}${x}`).join(", ")} {${vars}}`;
|
|
157
|
-
cssRuleSets.push(css2);
|
|
158
|
-
if (config.shouldAddPrefersColorThemes && isDarkOrLightBase) {
|
|
159
|
-
const isDark = themeName.startsWith("dark");
|
|
160
|
-
cssRuleSets.push(`@media(prefers-color-scheme: ${isDark ? "dark" : "light"}) {
|
|
161
|
-
body { background:${theme.background}; color: ${theme.color} }
|
|
162
|
-
:root {${vars} }
|
|
163
|
-
}`);
|
|
164
|
-
}
|
|
103
|
+
cssRuleSets = [
|
|
104
|
+
...cssRuleSets,
|
|
105
|
+
...getThemeCSSRules({
|
|
106
|
+
config,
|
|
107
|
+
themeName,
|
|
108
|
+
...dedupedThemes[themeName]
|
|
109
|
+
})
|
|
110
|
+
];
|
|
165
111
|
}
|
|
166
112
|
}
|
|
167
113
|
for (const themeName in themes) {
|
|
168
|
-
|
|
169
|
-
const parents = themeName.split("_").slice(0, -1).map((part) => {
|
|
170
|
-
cur.push(part);
|
|
171
|
-
return cur.join("_");
|
|
172
|
-
});
|
|
173
|
-
if (!parents.length)
|
|
174
|
-
continue;
|
|
175
|
-
const og = themes[themeName];
|
|
176
|
-
themes[themeName] = new Proxy(og, {
|
|
177
|
-
get(target, key) {
|
|
178
|
-
if (key === GetThemeUnwrapped) {
|
|
179
|
-
return og;
|
|
180
|
-
}
|
|
181
|
-
if (Reflect.has(target, key)) {
|
|
182
|
-
return Reflect.get(target, key);
|
|
183
|
-
}
|
|
184
|
-
for (let i = parents.length - 1; i >= 0; i--) {
|
|
185
|
-
const parent = themes[parents[i]];
|
|
186
|
-
if (!parent) {
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
if (Reflect.has(parent, key)) {
|
|
190
|
-
return Reflect.get(parent, key);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return Reflect.get(target, key);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
114
|
+
themes[themeName] = proxyThemeToParents(themeName, themes[themeName], themes);
|
|
196
115
|
}
|
|
197
116
|
tokensValueToVariable.clear();
|
|
198
117
|
Object.freeze(cssRuleSets);
|
|
@@ -249,25 +168,6 @@ const parseTokens = (tokens) => {
|
|
|
249
168
|
}
|
|
250
169
|
return res;
|
|
251
170
|
};
|
|
252
|
-
function ensureThemeVariable(theme, key) {
|
|
253
|
-
const val = theme[key];
|
|
254
|
-
const themeKey = key;
|
|
255
|
-
if (!isVariable(val)) {
|
|
256
|
-
theme[key] = createVariable({
|
|
257
|
-
key: themeKey,
|
|
258
|
-
name: themeKey,
|
|
259
|
-
val
|
|
260
|
-
});
|
|
261
|
-
} else {
|
|
262
|
-
if (val.name !== themeKey) {
|
|
263
|
-
theme[key] = createVariable({
|
|
264
|
-
key: val.name,
|
|
265
|
-
name: themeKey,
|
|
266
|
-
val: val.val
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
171
|
export {
|
|
272
172
|
createTamagui
|
|
273
173
|
};
|