@tamagui/web 1.2.5
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/README.md +1 -0
- package/dist/cjs/Tamagui.js +77 -0
- package/dist/cjs/Tamagui.js.map +7 -0
- package/dist/cjs/addTheme.js +78 -0
- package/dist/cjs/addTheme.js.map +7 -0
- package/dist/cjs/config.js +91 -0
- package/dist/cjs/config.js.map +7 -0
- package/dist/cjs/constants/constants.js +49 -0
- package/dist/cjs/constants/constants.js.map +7 -0
- package/dist/cjs/constants/isDevTools.js +37 -0
- package/dist/cjs/constants/isDevTools.js.map +7 -0
- package/dist/cjs/contexts/ButtonNestingContext.js +30 -0
- package/dist/cjs/contexts/ButtonNestingContext.js.map +7 -0
- package/dist/cjs/contexts/FontLanguageContext.js +30 -0
- package/dist/cjs/contexts/FontLanguageContext.js.map +7 -0
- package/dist/cjs/contexts/TextAncestorContext.js +30 -0
- package/dist/cjs/contexts/TextAncestorContext.js.map +7 -0
- package/dist/cjs/createComponent.js +874 -0
- package/dist/cjs/createComponent.js.map +7 -0
- package/dist/cjs/createFont.js +69 -0
- package/dist/cjs/createFont.js.map +7 -0
- package/dist/cjs/createShorthands.js +31 -0
- package/dist/cjs/createShorthands.js.map +7 -0
- package/dist/cjs/createTamagui.js +206 -0
- package/dist/cjs/createTamagui.js.map +7 -0
- package/dist/cjs/createTheme.js +31 -0
- package/dist/cjs/createTheme.js.map +7 -0
- package/dist/cjs/createTokens.js +39 -0
- package/dist/cjs/createTokens.js.map +7 -0
- package/dist/cjs/createVariable.js +111 -0
- package/dist/cjs/createVariable.js.map +7 -0
- package/dist/cjs/createVariables.js +60 -0
- package/dist/cjs/createVariables.js.map +7 -0
- package/dist/cjs/helpers/RNComponents.js +40 -0
- package/dist/cjs/helpers/RNComponents.js.map +7 -0
- package/dist/cjs/helpers/ThemeManager.js +234 -0
- package/dist/cjs/helpers/ThemeManager.js.map +7 -0
- package/dist/cjs/helpers/ThemeManagerContext.js +30 -0
- package/dist/cjs/helpers/ThemeManagerContext.js.map +7 -0
- package/dist/cjs/helpers/createMediaStyle.js +67 -0
- package/dist/cjs/helpers/createMediaStyle.js.map +7 -0
- package/dist/cjs/helpers/createPropMapper.js +423 -0
- package/dist/cjs/helpers/createPropMapper.js.map +7 -0
- package/dist/cjs/helpers/createProxy.js +43 -0
- package/dist/cjs/helpers/createProxy.js.map +7 -0
- package/dist/cjs/helpers/expandStyle.js +95 -0
- package/dist/cjs/helpers/expandStyle.js.map +7 -0
- package/dist/cjs/helpers/expandStyles.js +116 -0
- package/dist/cjs/helpers/expandStyles.js.map +7 -0
- package/dist/cjs/helpers/extendStaticConfig.js +91 -0
- package/dist/cjs/helpers/extendStaticConfig.js.map +7 -0
- package/dist/cjs/helpers/getAnimationDriver.js +32 -0
- package/dist/cjs/helpers/getAnimationDriver.js.map +7 -0
- package/dist/cjs/helpers/getExpandedShorthands.js +40 -0
- package/dist/cjs/helpers/getExpandedShorthands.js.map +7 -0
- package/dist/cjs/helpers/getFontLanguage.js +29 -0
- package/dist/cjs/helpers/getFontLanguage.js.map +7 -0
- package/dist/cjs/helpers/getSplitStyles.js +850 -0
- package/dist/cjs/helpers/getSplitStyles.js.map +7 -0
- package/dist/cjs/helpers/getStylesAtomic.js +226 -0
- package/dist/cjs/helpers/getStylesAtomic.js.map +7 -0
- package/dist/cjs/helpers/getStylesAtomic.native.js +38 -0
- package/dist/cjs/helpers/getStylesAtomic.native.js.map +7 -0
- package/dist/cjs/helpers/getThemeCSSRules.js +110 -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/getVariantExtras.js +92 -0
- package/dist/cjs/helpers/getVariantExtras.js.map +7 -0
- package/dist/cjs/helpers/insertStyleRule.js +218 -0
- package/dist/cjs/helpers/insertStyleRule.js.map +7 -0
- package/dist/cjs/helpers/isObj.js +29 -0
- package/dist/cjs/helpers/isObj.js.map +7 -0
- package/dist/cjs/helpers/isTamaguiComponent.js +32 -0
- package/dist/cjs/helpers/isTamaguiComponent.js.map +7 -0
- package/dist/cjs/helpers/isTamaguiElement.js +33 -0
- package/dist/cjs/helpers/isTamaguiElement.js.map +7 -0
- package/dist/cjs/helpers/matchMedia.js +42 -0
- package/dist/cjs/helpers/matchMedia.js.map +7 -0
- package/dist/cjs/helpers/matchMedia.native.js +48 -0
- package/dist/cjs/helpers/matchMedia.native.js.map +7 -0
- package/dist/cjs/helpers/mergeProps.js +54 -0
- package/dist/cjs/helpers/mergeProps.js.map +7 -0
- package/dist/cjs/helpers/mergeTransform.js +47 -0
- package/dist/cjs/helpers/mergeTransform.js.map +7 -0
- package/dist/cjs/helpers/normalizeColor.js +71 -0
- package/dist/cjs/helpers/normalizeColor.js.map +7 -0
- package/dist/cjs/helpers/normalizeValueWithProperty.js +138 -0
- package/dist/cjs/helpers/normalizeValueWithProperty.js.map +7 -0
- package/dist/cjs/helpers/proxyThemeVariables.js +40 -0
- package/dist/cjs/helpers/proxyThemeVariables.js.map +7 -0
- package/dist/cjs/helpers/pseudoDescriptors.js +53 -0
- package/dist/cjs/helpers/pseudoDescriptors.js.map +7 -0
- package/dist/cjs/helpers/registerCSSVariable.js +40 -0
- package/dist/cjs/helpers/registerCSSVariable.js.map +7 -0
- package/dist/cjs/helpers/themeable.js +62 -0
- package/dist/cjs/helpers/themeable.js.map +7 -0
- package/dist/cjs/helpers/themes.js +78 -0
- package/dist/cjs/helpers/themes.js.map +7 -0
- package/dist/cjs/helpers/timer.js +35 -0
- package/dist/cjs/helpers/timer.js.map +7 -0
- package/dist/cjs/helpers/useShallowSetState.js +59 -0
- package/dist/cjs/helpers/useShallowSetState.js.map +7 -0
- package/dist/cjs/helpers/warnOnce.js +38 -0
- package/dist/cjs/helpers/warnOnce.js.map +7 -0
- package/dist/cjs/helpers/withStaticProperties.js +32 -0
- package/dist/cjs/helpers/withStaticProperties.js.map +7 -0
- package/dist/cjs/hooks/getThemeUnwrapped.js +34 -0
- package/dist/cjs/hooks/getThemeUnwrapped.js.map +7 -0
- package/dist/cjs/hooks/useId.js +29 -0
- package/dist/cjs/hooks/useId.js.map +7 -0
- package/dist/cjs/hooks/useIsTouchDevice.js +33 -0
- package/dist/cjs/hooks/useIsTouchDevice.js.map +7 -0
- package/dist/cjs/hooks/useMedia.js +263 -0
- package/dist/cjs/hooks/useMedia.js.map +7 -0
- package/dist/cjs/hooks/useSafeRef.js +59 -0
- package/dist/cjs/hooks/useSafeRef.js.map +7 -0
- package/dist/cjs/hooks/useServerHooks.js +36 -0
- package/dist/cjs/hooks/useServerHooks.js.map +7 -0
- package/dist/cjs/hooks/useStyle.js +61 -0
- package/dist/cjs/hooks/useStyle.js.map +7 -0
- package/dist/cjs/hooks/useTheme.js +230 -0
- package/dist/cjs/hooks/useTheme.js.map +7 -0
- package/dist/cjs/hooks/useThemeName.js +52 -0
- package/dist/cjs/hooks/useThemeName.js.map +7 -0
- package/dist/cjs/index.js +104 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/inject-styles.js +40 -0
- package/dist/cjs/inject-styles.js.map +7 -0
- package/dist/cjs/insertFont.js +93 -0
- package/dist/cjs/insertFont.js.map +7 -0
- package/dist/cjs/setupHooks.js +34 -0
- package/dist/cjs/setupHooks.js.map +7 -0
- package/dist/cjs/setupReactNative.js +51 -0
- package/dist/cjs/setupReactNative.js.map +7 -0
- package/dist/cjs/styled.js +95 -0
- package/dist/cjs/styled.js.map +7 -0
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/cjs/updateTheme.js +47 -0
- package/dist/cjs/updateTheme.js.map +7 -0
- package/dist/cjs/views/FontLanguage.js +41 -0
- package/dist/cjs/views/FontLanguage.js.map +7 -0
- package/dist/cjs/views/FontLanguage.native.js +35 -0
- package/dist/cjs/views/FontLanguage.native.js.map +7 -0
- package/dist/cjs/views/FontLanguage.types.js +17 -0
- package/dist/cjs/views/FontLanguage.types.js.map +7 -0
- package/dist/cjs/views/Slot.js +92 -0
- package/dist/cjs/views/Slot.js.map +7 -0
- package/dist/cjs/views/Stack.js +38 -0
- package/dist/cjs/views/Stack.js.map +7 -0
- package/dist/cjs/views/TamaguiProvider.js +90 -0
- package/dist/cjs/views/TamaguiProvider.js.map +7 -0
- package/dist/cjs/views/Text.js +94 -0
- package/dist/cjs/views/Text.js.map +7 -0
- package/dist/cjs/views/Theme.js +88 -0
- package/dist/cjs/views/Theme.js.map +7 -0
- package/dist/cjs/views/ThemeProvider.js +70 -0
- package/dist/cjs/views/ThemeProvider.js.map +7 -0
- package/dist/esm/Tamagui.js +41 -0
- package/dist/esm/Tamagui.js.map +7 -0
- package/dist/esm/addTheme.js +54 -0
- package/dist/esm/addTheme.js.map +7 -0
- package/dist/esm/config.js +58 -0
- package/dist/esm/config.js.map +7 -0
- package/dist/esm/constants/constants.js +22 -0
- package/dist/esm/constants/constants.js.map +7 -0
- package/dist/esm/constants/isDevTools.js +13 -0
- package/dist/esm/constants/isDevTools.js.map +7 -0
- package/dist/esm/contexts/ButtonNestingContext.js +6 -0
- package/dist/esm/contexts/ButtonNestingContext.js.map +7 -0
- package/dist/esm/contexts/FontLanguageContext.js +6 -0
- package/dist/esm/contexts/FontLanguageContext.js.map +7 -0
- package/dist/esm/contexts/TextAncestorContext.js +6 -0
- package/dist/esm/contexts/TextAncestorContext.js.map +7 -0
- package/dist/esm/createComponent.js +849 -0
- package/dist/esm/createComponent.js.map +7 -0
- package/dist/esm/createFont.js +45 -0
- package/dist/esm/createFont.js.map +7 -0
- package/dist/esm/createShorthands.js +7 -0
- package/dist/esm/createShorthands.js.map +7 -0
- package/dist/esm/createTamagui.js +190 -0
- package/dist/esm/createTamagui.js.map +7 -0
- package/dist/esm/createTheme.js +7 -0
- package/dist/esm/createTheme.js.map +7 -0
- package/dist/esm/createTokens.js +15 -0
- package/dist/esm/createTokens.js.map +7 -0
- package/dist/esm/createVariable.js +78 -0
- package/dist/esm/createVariable.js.map +7 -0
- package/dist/esm/createVariables.js +35 -0
- package/dist/esm/createVariables.js.map +7 -0
- package/dist/esm/helpers/RNComponents.js +16 -0
- package/dist/esm/helpers/RNComponents.js.map +7 -0
- package/dist/esm/helpers/ThemeManager.js +209 -0
- package/dist/esm/helpers/ThemeManager.js.map +7 -0
- package/dist/esm/helpers/ThemeManagerContext.js +6 -0
- package/dist/esm/helpers/ThemeManagerContext.js.map +7 -0
- package/dist/esm/helpers/createMediaStyle.js +42 -0
- package/dist/esm/helpers/createMediaStyle.js.map +7 -0
- package/dist/esm/helpers/createPropMapper.js +396 -0
- package/dist/esm/helpers/createPropMapper.js.map +7 -0
- package/dist/esm/helpers/createProxy.js +19 -0
- package/dist/esm/helpers/createProxy.js.map +7 -0
- package/dist/esm/helpers/expandStyle.js +71 -0
- package/dist/esm/helpers/expandStyle.js.map +7 -0
- package/dist/esm/helpers/expandStyles.js +90 -0
- package/dist/esm/helpers/expandStyles.js.map +7 -0
- package/dist/esm/helpers/extendStaticConfig.js +66 -0
- package/dist/esm/helpers/extendStaticConfig.js.map +7 -0
- package/dist/esm/helpers/getAnimationDriver.js +8 -0
- package/dist/esm/helpers/getAnimationDriver.js.map +7 -0
- package/dist/esm/helpers/getExpandedShorthands.js +16 -0
- package/dist/esm/helpers/getExpandedShorthands.js.map +7 -0
- package/dist/esm/helpers/getFontLanguage.js +5 -0
- package/dist/esm/helpers/getFontLanguage.js.map +7 -0
- package/dist/esm/helpers/getSplitStyles.js +849 -0
- package/dist/esm/helpers/getSplitStyles.js.map +7 -0
- package/dist/esm/helpers/getStylesAtomic.js +200 -0
- package/dist/esm/helpers/getStylesAtomic.js.map +7 -0
- package/dist/esm/helpers/getStylesAtomic.native.js +12 -0
- package/dist/esm/helpers/getStylesAtomic.native.js.map +7 -0
- package/dist/esm/helpers/getThemeCSSRules.js +86 -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/getVariantExtras.js +67 -0
- package/dist/esm/helpers/getVariantExtras.js.map +7 -0
- package/dist/esm/helpers/insertStyleRule.js +186 -0
- package/dist/esm/helpers/insertStyleRule.js.map +7 -0
- package/dist/esm/helpers/isObj.js +5 -0
- package/dist/esm/helpers/isObj.js.map +7 -0
- package/dist/esm/helpers/isTamaguiComponent.js +8 -0
- package/dist/esm/helpers/isTamaguiComponent.js.map +7 -0
- package/dist/esm/helpers/isTamaguiElement.js +9 -0
- package/dist/esm/helpers/isTamaguiElement.js.map +7 -0
- package/dist/esm/helpers/matchMedia.js +17 -0
- package/dist/esm/helpers/matchMedia.js.map +7 -0
- package/dist/esm/helpers/matchMedia.native.js +23 -0
- package/dist/esm/helpers/matchMedia.native.js.map +7 -0
- package/dist/esm/helpers/mergeProps.js +30 -0
- package/dist/esm/helpers/mergeProps.js.map +7 -0
- package/dist/esm/helpers/mergeTransform.js +21 -0
- package/dist/esm/helpers/mergeTransform.js.map +7 -0
- package/dist/esm/helpers/normalizeColor.js +36 -0
- package/dist/esm/helpers/normalizeColor.js.map +7 -0
- package/dist/esm/helpers/normalizeValueWithProperty.js +113 -0
- package/dist/esm/helpers/normalizeValueWithProperty.js.map +7 -0
- package/dist/esm/helpers/proxyThemeVariables.js +16 -0
- package/dist/esm/helpers/proxyThemeVariables.js.map +7 -0
- package/dist/esm/helpers/pseudoDescriptors.js +29 -0
- package/dist/esm/helpers/pseudoDescriptors.js.map +7 -0
- package/dist/esm/helpers/registerCSSVariable.js +14 -0
- package/dist/esm/helpers/registerCSSVariable.js.map +7 -0
- package/dist/esm/helpers/themeable.js +28 -0
- package/dist/esm/helpers/themeable.js.map +7 -0
- package/dist/esm/helpers/themes.js +53 -0
- package/dist/esm/helpers/themes.js.map +7 -0
- package/dist/esm/helpers/timer.js +11 -0
- package/dist/esm/helpers/timer.js.map +7 -0
- package/dist/esm/helpers/useShallowSetState.js +35 -0
- package/dist/esm/helpers/useShallowSetState.js.map +7 -0
- package/dist/esm/helpers/warnOnce.js +14 -0
- package/dist/esm/helpers/warnOnce.js.map +7 -0
- package/dist/esm/helpers/withStaticProperties.js +8 -0
- package/dist/esm/helpers/withStaticProperties.js.map +7 -0
- package/dist/esm/hooks/getThemeUnwrapped.js +9 -0
- package/dist/esm/hooks/getThemeUnwrapped.js.map +7 -0
- package/dist/esm/hooks/useId.js +5 -0
- package/dist/esm/hooks/useId.js.map +7 -0
- package/dist/esm/hooks/useIsTouchDevice.js +9 -0
- package/dist/esm/hooks/useIsTouchDevice.js.map +7 -0
- package/dist/esm/hooks/useMedia.js +225 -0
- package/dist/esm/hooks/useMedia.js.map +7 -0
- package/dist/esm/hooks/useSafeRef.js +35 -0
- package/dist/esm/hooks/useSafeRef.js.map +7 -0
- package/dist/esm/hooks/useServerHooks.js +11 -0
- package/dist/esm/hooks/useServerHooks.js.map +7 -0
- package/dist/esm/hooks/useStyle.js +37 -0
- package/dist/esm/hooks/useStyle.js.map +7 -0
- package/dist/esm/hooks/useTheme.js +205 -0
- package/dist/esm/hooks/useTheme.js.map +7 -0
- package/dist/esm/hooks/useThemeName.js +28 -0
- package/dist/esm/hooks/useThemeName.js.map +7 -0
- package/dist/esm/index.js +77 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/inject-styles.js +16 -0
- package/dist/esm/inject-styles.js.map +7 -0
- package/dist/esm/insertFont.js +67 -0
- package/dist/esm/insertFont.js.map +7 -0
- package/dist/esm/setupHooks.js +9 -0
- package/dist/esm/setupHooks.js.map +7 -0
- package/dist/esm/setupReactNative.js +25 -0
- package/dist/esm/setupReactNative.js.map +7 -0
- package/dist/esm/styled.js +71 -0
- package/dist/esm/styled.js.map +7 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/esm/updateTheme.js +23 -0
- package/dist/esm/updateTheme.js.map +7 -0
- package/dist/esm/views/FontLanguage.js +17 -0
- package/dist/esm/views/FontLanguage.js.map +7 -0
- package/dist/esm/views/FontLanguage.native.js +11 -0
- package/dist/esm/views/FontLanguage.native.js.map +7 -0
- package/dist/esm/views/FontLanguage.types.js +1 -0
- package/dist/esm/views/FontLanguage.types.js.map +7 -0
- package/dist/esm/views/Slot.js +66 -0
- package/dist/esm/views/Slot.js.map +7 -0
- package/dist/esm/views/Stack.js +14 -0
- package/dist/esm/views/Stack.js.map +7 -0
- package/dist/esm/views/TamaguiProvider.js +56 -0
- package/dist/esm/views/TamaguiProvider.js.map +7 -0
- package/dist/esm/views/Text.js +70 -0
- package/dist/esm/views/Text.js.map +7 -0
- package/dist/esm/views/Theme.js +63 -0
- package/dist/esm/views/Theme.js.map +7 -0
- package/dist/esm/views/ThemeProvider.js +45 -0
- package/dist/esm/views/ThemeProvider.js.map +7 -0
- package/package.json +73 -0
- package/reset.css +37 -0
- package/src/Tamagui.ts +48 -0
- package/src/addTheme.ts +65 -0
- package/src/config.ts +62 -0
- package/src/constants/constants.ts +17 -0
- package/src/constants/isDevTools.ts +12 -0
- package/src/contexts/ButtonNestingContext.tsx +3 -0
- package/src/contexts/FontLanguageContext.tsx +5 -0
- package/src/contexts/TextAncestorContext.tsx +3 -0
- package/src/createComponent.tsx +1133 -0
- package/src/createFont.ts +50 -0
- package/src/createShorthands.ts +7 -0
- package/src/createTamagui.ts +253 -0
- package/src/createTheme.ts +13 -0
- package/src/createTokens.ts +46 -0
- package/src/createVariable.ts +93 -0
- package/src/createVariables.ts +55 -0
- package/src/helpers/RNComponents.tsx +14 -0
- package/src/helpers/ThemeManager.tsx +285 -0
- package/src/helpers/ThemeManagerContext.tsx +5 -0
- package/src/helpers/createMediaStyle.ts +55 -0
- package/src/helpers/createPropMapper.ts +562 -0
- package/src/helpers/createProxy.ts +16 -0
- package/src/helpers/expandStyle.ts +82 -0
- package/src/helpers/expandStyles.ts +107 -0
- package/src/helpers/extendStaticConfig.ts +78 -0
- package/src/helpers/getAnimationDriver.tsx +5 -0
- package/src/helpers/getExpandedShorthands.ts +17 -0
- package/src/helpers/getFontLanguage.ts +2 -0
- package/src/helpers/getSplitStyles.tsx +1133 -0
- package/src/helpers/getStylesAtomic.native.ts +8 -0
- package/src/helpers/getStylesAtomic.ts +274 -0
- package/src/helpers/getThemeCSSRules.native.ts +3 -0
- package/src/helpers/getThemeCSSRules.ts +120 -0
- package/src/helpers/getVariantExtras.tsx +85 -0
- package/src/helpers/insertStyleRule.tsx +218 -0
- package/src/helpers/isObj.ts +1 -0
- package/src/helpers/isTamaguiComponent.tsx +11 -0
- package/src/helpers/isTamaguiElement.tsx +11 -0
- package/src/helpers/matchMedia.native.ts +23 -0
- package/src/helpers/matchMedia.ts +16 -0
- package/src/helpers/mergeProps.ts +56 -0
- package/src/helpers/mergeTransform.ts +30 -0
- package/src/helpers/normalizeColor.ts +38 -0
- package/src/helpers/normalizeValueWithProperty.ts +129 -0
- package/src/helpers/proxyThemeVariables.tsx +15 -0
- package/src/helpers/pseudoDescriptors.ts +40 -0
- package/src/helpers/registerCSSVariable.ts +13 -0
- package/src/helpers/themeable.tsx +44 -0
- package/src/helpers/themes.ts +67 -0
- package/src/helpers/timer.ts +9 -0
- package/src/helpers/useShallowSetState.tsx +41 -0
- package/src/helpers/warnOnce.tsx +11 -0
- package/src/helpers/withStaticProperties.tsx +7 -0
- package/src/hooks/getThemeUnwrapped.tsx +5 -0
- package/src/hooks/useId.tsx +1 -0
- package/src/hooks/useIsTouchDevice.tsx +6 -0
- package/src/hooks/useMedia.tsx +298 -0
- package/src/hooks/useSafeRef.ts +45 -0
- package/src/hooks/useServerHooks.tsx +12 -0
- package/src/hooks/useStyle.tsx +49 -0
- package/src/hooks/useTheme.tsx +274 -0
- package/src/hooks/useThemeName.tsx +27 -0
- package/src/index.ts +72 -0
- package/src/inject-styles.ts +20 -0
- package/src/insertFont.ts +73 -0
- package/src/setupHooks.ts +35 -0
- package/src/setupReactNative.ts +22 -0
- package/src/styled.tsx +195 -0
- package/src/types.tsx +1459 -0
- package/src/updateTheme.ts +26 -0
- package/src/views/FontLanguage.native.tsx +12 -0
- package/src/views/FontLanguage.tsx +16 -0
- package/src/views/FontLanguage.types.ts +13 -0
- package/src/views/Slot.tsx +95 -0
- package/src/views/Stack.tsx +25 -0
- package/src/views/TamaguiProvider.tsx +65 -0
- package/src/views/Text.tsx +87 -0
- package/src/views/Theme.tsx +83 -0
- package/src/views/ThemeProvider.tsx +55 -0
- package/types/Tamagui.d.ts +30 -0
- package/types/Tamagui.d.ts.map +1 -0
- package/types/addTheme.d.ts +32 -0
- package/types/addTheme.d.ts.map +1 -0
- package/types/config.d.ts +49 -0
- package/types/config.d.ts.map +1 -0
- package/types/constants/constants.d.ts +21 -0
- package/types/constants/constants.d.ts.map +1 -0
- package/types/constants/isDevTools.d.ts +2 -0
- package/types/constants/isDevTools.d.ts.map +1 -0
- package/types/contexts/ButtonNestingContext.d.ts +3 -0
- package/types/contexts/ButtonNestingContext.d.ts.map +1 -0
- package/types/contexts/FontLanguageContext.d.ts +5 -0
- package/types/contexts/FontLanguageContext.d.ts.map +1 -0
- package/types/contexts/TextAncestorContext.d.ts +3 -0
- package/types/contexts/TextAncestorContext.d.ts.map +1 -0
- package/types/createComponent.d.ts +23 -0
- package/types/createComponent.d.ts.map +1 -0
- package/types/createFont.d.ts +3 -0
- package/types/createFont.d.ts.map +1 -0
- package/types/createShorthands.d.ts +3 -0
- package/types/createShorthands.d.ts.map +1 -0
- package/types/createTamagui.d.ts +3 -0
- package/types/createTamagui.d.ts.map +1 -0
- package/types/createTheme.d.ts +7 -0
- package/types/createTheme.d.ts.map +1 -0
- package/types/createTokens.d.ts +28 -0
- package/types/createTokens.d.ts.map +1 -0
- package/types/createVariable.d.ts +26 -0
- package/types/createVariable.d.ts.map +1 -0
- package/types/createVariables.d.ts +11 -0
- package/types/createVariables.d.ts.map +1 -0
- package/types/helpers/RNComponents.d.ts +2 -0
- package/types/helpers/RNComponents.d.ts.map +1 -0
- package/types/helpers/ThemeManager.d.ts +36 -0
- package/types/helpers/ThemeManager.d.ts.map +1 -0
- package/types/helpers/ThemeManagerContext.d.ts +4 -0
- package/types/helpers/ThemeManagerContext.d.ts.map +1 -0
- package/types/helpers/createMediaStyle.d.ts +5 -0
- package/types/helpers/createMediaStyle.d.ts.map +1 -0
- package/types/helpers/createPropMapper.d.ts +7 -0
- package/types/helpers/createPropMapper.d.ts.map +1 -0
- package/types/helpers/createProxy.d.ts +2 -0
- package/types/helpers/createProxy.d.ts.map +1 -0
- package/types/helpers/expandStyle.d.ts +6 -0
- package/types/helpers/expandStyle.d.ts.map +1 -0
- package/types/helpers/expandStyles.d.ts +26 -0
- package/types/helpers/expandStyles.d.ts.map +1 -0
- package/types/helpers/extendStaticConfig.d.ts +4 -0
- package/types/helpers/extendStaticConfig.d.ts.map +1 -0
- package/types/helpers/getAnimationDriver.d.ts +6 -0
- package/types/helpers/getAnimationDriver.d.ts.map +1 -0
- package/types/helpers/getExpandedShorthands.d.ts +3 -0
- package/types/helpers/getExpandedShorthands.d.ts.map +1 -0
- package/types/helpers/getFontLanguage.d.ts +2 -0
- package/types/helpers/getFontLanguage.d.ts.map +1 -0
- package/types/helpers/getSplitStyles.d.ts +31 -0
- package/types/helpers/getSplitStyles.d.ts.map +1 -0
- package/types/helpers/getStylesAtomic.d.ts +18 -0
- package/types/helpers/getStylesAtomic.d.ts.map +1 -0
- package/types/helpers/getStylesAtomic.native.d.ts +4 -0
- package/types/helpers/getStylesAtomic.native.d.ts.map +1 -0
- package/types/helpers/getThemeCSSRules.d.ts +8 -0
- package/types/helpers/getThemeCSSRules.d.ts.map +1 -0
- package/types/helpers/getThemeCSSRules.native.d.ts +2 -0
- package/types/helpers/getThemeCSSRules.native.d.ts.map +1 -0
- package/types/helpers/getVariantExtras.d.ts +5 -0
- package/types/helpers/getVariantExtras.d.ts.map +1 -0
- package/types/helpers/insertStyleRule.d.ts +11 -0
- package/types/helpers/insertStyleRule.d.ts.map +1 -0
- package/types/helpers/isObj.d.ts +2 -0
- package/types/helpers/isObj.d.ts.map +1 -0
- package/types/helpers/isTamaguiComponent.d.ts +5 -0
- package/types/helpers/isTamaguiComponent.d.ts.map +1 -0
- package/types/helpers/isTamaguiElement.d.ts +3 -0
- package/types/helpers/isTamaguiElement.d.ts.map +1 -0
- package/types/helpers/matchMedia.d.ts +6 -0
- package/types/helpers/matchMedia.d.ts.map +1 -0
- package/types/helpers/matchMedia.native.d.ts +4 -0
- package/types/helpers/matchMedia.native.d.ts.map +1 -0
- package/types/helpers/mergeProps.d.ts +17 -0
- package/types/helpers/mergeProps.d.ts.map +1 -0
- package/types/helpers/mergeTransform.d.ts +9 -0
- package/types/helpers/mergeTransform.d.ts.map +1 -0
- package/types/helpers/normalizeColor.d.ts +4 -0
- package/types/helpers/normalizeColor.d.ts.map +1 -0
- package/types/helpers/normalizeValueWithProperty.d.ts +7 -0
- package/types/helpers/normalizeValueWithProperty.d.ts.map +1 -0
- package/types/helpers/proxyThemeVariables.d.ts +2 -0
- package/types/helpers/proxyThemeVariables.d.ts.map +1 -0
- package/types/helpers/pseudoDescriptors.d.ts +10 -0
- package/types/helpers/pseudoDescriptors.d.ts.map +1 -0
- package/types/helpers/registerCSSVariable.d.ts +5 -0
- package/types/helpers/registerCSSVariable.d.ts.map +1 -0
- package/types/helpers/themeable.d.ts +12 -0
- package/types/helpers/themeable.d.ts.map +1 -0
- package/types/helpers/themes.d.ts +4 -0
- package/types/helpers/themes.d.ts.map +1 -0
- package/types/helpers/timer.d.ts +2 -0
- package/types/helpers/timer.d.ts.map +1 -0
- package/types/helpers/useShallowSetState.d.ts +5 -0
- package/types/helpers/useShallowSetState.d.ts.map +1 -0
- package/types/helpers/warnOnce.d.ts +2 -0
- package/types/helpers/warnOnce.d.ts.map +1 -0
- package/types/helpers/withStaticProperties.d.ts +2 -0
- package/types/helpers/withStaticProperties.d.ts.map +1 -0
- package/types/hooks/getThemeUnwrapped.d.ts +3 -0
- package/types/hooks/getThemeUnwrapped.d.ts.map +1 -0
- package/types/hooks/useId.d.ts +2 -0
- package/types/hooks/useId.d.ts.map +1 -0
- package/types/hooks/useIsTouchDevice.d.ts +2 -0
- package/types/hooks/useIsTouchDevice.d.ts.map +1 -0
- package/types/hooks/useMedia.d.ts +33 -0
- package/types/hooks/useMedia.d.ts.map +1 -0
- package/types/hooks/useSafeRef.d.ts +4 -0
- package/types/hooks/useSafeRef.d.ts.map +1 -0
- package/types/hooks/useServerHooks.d.ts +4 -0
- package/types/hooks/useServerHooks.d.ts.map +1 -0
- package/types/hooks/useStyle.d.ts +8 -0
- package/types/hooks/useStyle.d.ts.map +1 -0
- package/types/hooks/useTheme.d.ts +25 -0
- package/types/hooks/useTheme.d.ts.map +1 -0
- package/types/hooks/useThemeName.d.ts +5 -0
- package/types/hooks/useThemeName.d.ts.map +1 -0
- package/types/index.d.ts +56 -0
- package/types/index.d.ts.map +1 -0
- package/types/inject-styles.d.ts +7 -0
- package/types/inject-styles.d.ts.map +1 -0
- package/types/insertFont.d.ts +9 -0
- package/types/insertFont.d.ts.map +1 -0
- package/types/setupHooks.d.ts +14 -0
- package/types/setupHooks.d.ts.map +1 -0
- package/types/setupReactNative.d.ts +5 -0
- package/types/setupReactNative.d.ts.map +1 -0
- package/types/styled.d.ts +20 -0
- package/types/styled.d.ts.map +1 -0
- package/types/types.d.ts +715 -0
- package/types/types.d.ts.map +1 -0
- package/types/updateTheme.d.ts +30 -0
- package/types/updateTheme.d.ts.map +1 -0
- package/types/views/FontLanguage.d.ts +4 -0
- package/types/views/FontLanguage.d.ts.map +1 -0
- package/types/views/FontLanguage.native.d.ts +4 -0
- package/types/views/FontLanguage.native.d.ts.map +1 -0
- package/types/views/FontLanguage.types.d.ts +11 -0
- package/types/views/FontLanguage.types.d.ts.map +1 -0
- package/types/views/Slot.d.ts +11 -0
- package/types/views/Slot.d.ts.map +1 -0
- package/types/views/Stack.d.ts +4 -0
- package/types/views/Stack.d.ts.map +1 -0
- package/types/views/TamaguiProvider.d.ts +4 -0
- package/types/views/TamaguiProvider.d.ts.map +1 -0
- package/types/views/Text.d.ts +4 -0
- package/types/views/Text.d.ts.map +1 -0
- package/types/views/Theme.d.ts +8 -0
- package/types/views/Theme.d.ts.map +1 -0
- package/types/views/ThemeProvider.d.ts +12 -0
- package/types/views/ThemeProvider.d.ts.map +1 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Some parts adapted from react-native-web
|
|
3
|
+
* Copyright (c) Nicolas Gallagher licensed under the MIT license.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { StyleObject, simpleHash } from '@tamagui/helpers'
|
|
7
|
+
import type { TextStyle, ViewStyle } from 'react-native'
|
|
8
|
+
|
|
9
|
+
import { getConfig } from '../config'
|
|
10
|
+
import { TamaguiInternalConfig } from '../types'
|
|
11
|
+
import { defaultOffset } from './expandStyles'
|
|
12
|
+
import { normalizeValueWithProperty } from './normalizeValueWithProperty.js'
|
|
13
|
+
import { PseudoDescriptor, pseudoDescriptors } from './pseudoDescriptors'
|
|
14
|
+
|
|
15
|
+
// refactor this file away next...
|
|
16
|
+
|
|
17
|
+
type ViewOrTextStyle = ViewStyle | TextStyle
|
|
18
|
+
|
|
19
|
+
export type ViewStyleWithPseudos = ViewOrTextStyle & {
|
|
20
|
+
hoverStyle?: ViewOrTextStyle
|
|
21
|
+
pressStyle?: ViewOrTextStyle
|
|
22
|
+
focusStyle?: ViewOrTextStyle
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// matching order of the below *0
|
|
26
|
+
const pseudosOrdered = [
|
|
27
|
+
pseudoDescriptors.hoverStyle,
|
|
28
|
+
pseudoDescriptors.pressStyle,
|
|
29
|
+
pseudoDescriptors.focusStyle,
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
export function getStylesAtomic(stylesIn: ViewStyleWithPseudos) {
|
|
33
|
+
// performance optimization
|
|
34
|
+
if (!(stylesIn.hoverStyle || stylesIn.pressStyle || stylesIn.focusStyle)) {
|
|
35
|
+
return getAtomicStyle(stylesIn)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// only for pseudos
|
|
39
|
+
const { hoverStyle, pressStyle, focusStyle, ...base } = stylesIn
|
|
40
|
+
let res: StyleObject[] = []
|
|
41
|
+
// *1 order matched to *0
|
|
42
|
+
for (const [index, style] of [hoverStyle, pressStyle, focusStyle, base].entries()) {
|
|
43
|
+
if (!style) continue
|
|
44
|
+
const pseudo = pseudosOrdered[index]
|
|
45
|
+
res = [...res, ...getAtomicStyle(style, pseudo)]
|
|
46
|
+
}
|
|
47
|
+
return res
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const cache = new Map()
|
|
51
|
+
|
|
52
|
+
export function getAtomicStyle(
|
|
53
|
+
style: ViewOrTextStyle,
|
|
54
|
+
pseudo?: PseudoDescriptor
|
|
55
|
+
): StyleObject[] {
|
|
56
|
+
if (!style) return []
|
|
57
|
+
const key = JSON.stringify(style) + (pseudo ? JSON.stringify(pseudo) : '')
|
|
58
|
+
if (cache.has(key)) {
|
|
59
|
+
return cache.get(key)
|
|
60
|
+
}
|
|
61
|
+
if (cache.size > 800) {
|
|
62
|
+
cache.clear()
|
|
63
|
+
}
|
|
64
|
+
if (process.env.NODE_ENV === 'development') {
|
|
65
|
+
if (!style || typeof style !== 'object') {
|
|
66
|
+
throw new Error(`Wrong style type: "${typeof style}": ${style}`)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const out = generateAtomicStyles(style, pseudo)
|
|
70
|
+
cache.set(key, out)
|
|
71
|
+
return out
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let conf: TamaguiInternalConfig
|
|
75
|
+
|
|
76
|
+
const generateAtomicStyles = (
|
|
77
|
+
styleIn: ViewStyle & TextStyle,
|
|
78
|
+
pseudo?: PseudoDescriptor
|
|
79
|
+
): StyleObject[] => {
|
|
80
|
+
conf = conf || getConfig()
|
|
81
|
+
|
|
82
|
+
// were converting to css styles
|
|
83
|
+
const style = styleIn as Record<string, string | null | undefined>
|
|
84
|
+
|
|
85
|
+
// transform
|
|
86
|
+
if (style.transform && Array.isArray(style.transform)) {
|
|
87
|
+
style.transform = style.transform
|
|
88
|
+
.map(
|
|
89
|
+
// { scale: 2 } => 'scale(2)'
|
|
90
|
+
// { translateX: 20 } => 'translateX(20px)'
|
|
91
|
+
// { matrix: [1,2,3,4,5,6] } => 'matrix(1,2,3,4,5,6)'
|
|
92
|
+
(transform) => {
|
|
93
|
+
const type = Object.keys(transform)[0]
|
|
94
|
+
const value = transform[type]
|
|
95
|
+
if (type === 'matrix' || type === 'matrix3d') {
|
|
96
|
+
return `${type}(${value.join(',')})`
|
|
97
|
+
}
|
|
98
|
+
return `${type}(${normalizeValueWithProperty(value, type)})`
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
.join(' ')
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
styleToCSS(style)
|
|
105
|
+
|
|
106
|
+
const out: StyleObject[] = []
|
|
107
|
+
for (const key in style) {
|
|
108
|
+
const value = style[key]
|
|
109
|
+
if (value == null || value == undefined) continue
|
|
110
|
+
const hash = presetHashes[value]
|
|
111
|
+
? value
|
|
112
|
+
: typeof value === 'string'
|
|
113
|
+
? simpleHash(value)
|
|
114
|
+
: `${value}`.replace('.', 'dot')
|
|
115
|
+
|
|
116
|
+
const pseudoPrefix = pseudo ? `0${pseudo.name}-` : ''
|
|
117
|
+
const shortProp = conf.inverseShorthands[key] || key
|
|
118
|
+
const identifier = `_${shortProp}-${pseudoPrefix}${hash}`
|
|
119
|
+
const rules = createAtomicRules(identifier, key, value, pseudo)
|
|
120
|
+
const styleObject: StyleObject = {
|
|
121
|
+
property: key,
|
|
122
|
+
pseudo: pseudo?.name as any,
|
|
123
|
+
value,
|
|
124
|
+
identifier,
|
|
125
|
+
rules,
|
|
126
|
+
}
|
|
127
|
+
out.push(styleObject)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return out
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const presetHashes = {
|
|
134
|
+
none: true,
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const n = normalizeValueWithProperty
|
|
138
|
+
|
|
139
|
+
export function styleToCSS(style: Record<string, any>) {
|
|
140
|
+
// box-shadow
|
|
141
|
+
const { shadowOffset, shadowRadius, shadowColor } = style
|
|
142
|
+
if (style.shadowRadius !== undefined) {
|
|
143
|
+
const offset = shadowOffset || defaultOffset
|
|
144
|
+
const shadow = `${n(offset.width)} ${n(offset.height)} ${n(
|
|
145
|
+
shadowRadius
|
|
146
|
+
)} ${shadowColor}`
|
|
147
|
+
style.boxShadow = style.boxShadow ? `${style.boxShadow}, ${shadow}` : shadow
|
|
148
|
+
style.shadowOffset = undefined
|
|
149
|
+
style.shadowRadius = undefined
|
|
150
|
+
style.shadowColor = undefined
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// text-shadow
|
|
154
|
+
const { textShadowColor, textShadowOffset, textShadowRadius } = style
|
|
155
|
+
if (textShadowColor || textShadowOffset || textShadowRadius) {
|
|
156
|
+
const { height, width } = textShadowOffset || defaultOffset
|
|
157
|
+
const radius = textShadowRadius || 0
|
|
158
|
+
const color = normalizeValueWithProperty(textShadowColor, 'textShadowColor')
|
|
159
|
+
if (color && (height !== 0 || width !== 0 || radius !== 0)) {
|
|
160
|
+
const blurRadius = normalizeValueWithProperty(radius)
|
|
161
|
+
const offsetX = normalizeValueWithProperty(width)
|
|
162
|
+
const offsetY = normalizeValueWithProperty(height)
|
|
163
|
+
style.textShadow = `${offsetX} ${offsetY} ${blurRadius} ${color}`
|
|
164
|
+
}
|
|
165
|
+
style.textShadowColor = undefined
|
|
166
|
+
style.textShadowOffset = undefined
|
|
167
|
+
style.textShadowRadius = undefined
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function createDeclarationBlock(style: Record<string, any>, important = false) {
|
|
172
|
+
let next = ''
|
|
173
|
+
for (const key in style) {
|
|
174
|
+
const prop = hyphenateStyleName(key)
|
|
175
|
+
const value = style[key]
|
|
176
|
+
next += `${prop}:${value}${important ? ' !important' : ''};`
|
|
177
|
+
}
|
|
178
|
+
return `{${next}}`
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const hcache = {}
|
|
182
|
+
const toHyphenLower = (match: string) => `-${match.toLowerCase()}`
|
|
183
|
+
const hyphenateStyleName = (key: string) => {
|
|
184
|
+
let val = hcache[key]
|
|
185
|
+
if (val) return val
|
|
186
|
+
hcache[key] = val = key.replace(/[A-Z]/g, toHyphenLower)
|
|
187
|
+
return val
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const pseudoSelectorPrefixes = (() => {
|
|
191
|
+
const res: Record<string, string> = {}
|
|
192
|
+
for (const key in pseudoDescriptors) {
|
|
193
|
+
const pseudo = pseudoDescriptors[key]
|
|
194
|
+
res[pseudo.name] = `${[...Array(pseudo.priority)].map(() => ':root').join('')} `
|
|
195
|
+
}
|
|
196
|
+
return res
|
|
197
|
+
})()
|
|
198
|
+
|
|
199
|
+
function createAtomicRules(
|
|
200
|
+
identifier: string,
|
|
201
|
+
property: string,
|
|
202
|
+
value: any,
|
|
203
|
+
pseudo?: PseudoDescriptor
|
|
204
|
+
): string[] {
|
|
205
|
+
const selector = pseudo
|
|
206
|
+
? `${pseudoSelectorPrefixes[pseudo.name]} .${identifier}:${pseudo.name}`
|
|
207
|
+
: `.${identifier}`
|
|
208
|
+
const important = !!pseudo
|
|
209
|
+
|
|
210
|
+
let rules: string[] = []
|
|
211
|
+
|
|
212
|
+
// Handle non-standard properties and object values that require multiple
|
|
213
|
+
// CSS rules to be created.
|
|
214
|
+
switch (property) {
|
|
215
|
+
// Equivalent to using '::placeholder'
|
|
216
|
+
case 'placeholderTextColor': {
|
|
217
|
+
const block = createDeclarationBlock({ color: value, opacity: 1 }, important)
|
|
218
|
+
rules.push(`${selector}::placeholder${block}`)
|
|
219
|
+
break
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// all webkit prefixed rules
|
|
223
|
+
case 'backgroundClip':
|
|
224
|
+
case 'userSelect': {
|
|
225
|
+
const propertyCapitalized = `${property[0].toUpperCase()}${property.slice(1)}`
|
|
226
|
+
const webkitProperty = `Webkit${propertyCapitalized}`
|
|
227
|
+
const block = createDeclarationBlock(
|
|
228
|
+
{ [property]: value, [webkitProperty]: value },
|
|
229
|
+
important
|
|
230
|
+
)
|
|
231
|
+
rules.push(`${selector}${block}`)
|
|
232
|
+
break
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Polyfill for additional 'pointer-events' values
|
|
236
|
+
case 'pointerEvents': {
|
|
237
|
+
let finalValue = value
|
|
238
|
+
if (value === 'auto' || value === 'box-only') {
|
|
239
|
+
finalValue = 'auto'
|
|
240
|
+
if (value === 'box-only') {
|
|
241
|
+
rules.push(`${selector}>*${boxOnly}`)
|
|
242
|
+
}
|
|
243
|
+
} else if (value === 'none' || value === 'box-none') {
|
|
244
|
+
finalValue = 'none'
|
|
245
|
+
if (value === 'box-none') {
|
|
246
|
+
rules.push(`${selector}>*${boxNone}`)
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const block = createDeclarationBlock({ pointerEvents: finalValue }, true)
|
|
250
|
+
rules.push(`${selector}${block}`)
|
|
251
|
+
break
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
default: {
|
|
255
|
+
const block = createDeclarationBlock({ [property]: value }, important)
|
|
256
|
+
rules.push(`${selector}${block}`)
|
|
257
|
+
break
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// hover styles need to be conditional
|
|
262
|
+
// perhaps this can be generalized but for now lets just shortcut
|
|
263
|
+
// and hardcode for hover styles, if we need to later we can
|
|
264
|
+
// WEIRD SYNTAX, SEE:
|
|
265
|
+
// https://stackoverflow.com/questions/40532204/media-query-for-devices-supporting-hover
|
|
266
|
+
if (pseudo && pseudo.name === 'hover') {
|
|
267
|
+
rules = rules.map((r) => `@media not all and (hover: none) { ${r} }`)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return rules
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const boxNone = createDeclarationBlock({ pointerEvents: 'auto' }, true)
|
|
274
|
+
const boxOnly = createDeclarationBlock({ pointerEvents: 'none' }, true)
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { simpleHash } from '@tamagui/helpers'
|
|
2
|
+
|
|
3
|
+
import { THEME_CLASSNAME_PREFIX } from '../constants/constants'
|
|
4
|
+
import { Variable, variableToString } from '../createVariable'
|
|
5
|
+
import { CreateTamaguiProps, ThemeParsed } from '../types'
|
|
6
|
+
import { tokensValueToVariable } from './registerCSSVariable'
|
|
7
|
+
|
|
8
|
+
export function getThemeCSSRules({
|
|
9
|
+
config,
|
|
10
|
+
themeName,
|
|
11
|
+
theme,
|
|
12
|
+
names,
|
|
13
|
+
}: {
|
|
14
|
+
config: CreateTamaguiProps
|
|
15
|
+
themeName: string
|
|
16
|
+
theme: ThemeParsed
|
|
17
|
+
names: string[]
|
|
18
|
+
}) {
|
|
19
|
+
const cssRuleSets: string[] = []
|
|
20
|
+
|
|
21
|
+
// special case for SSR
|
|
22
|
+
const hasDarkLight = 'light' in config.themes && 'dark' in config.themes
|
|
23
|
+
const CNP = `.${THEME_CLASSNAME_PREFIX}`
|
|
24
|
+
let vars = ''
|
|
25
|
+
|
|
26
|
+
// themeToVariableToValueMap.set(theme, {})
|
|
27
|
+
// const varToValMap = themeToVariableToValueMap.get(theme)
|
|
28
|
+
for (const themeKey in theme) {
|
|
29
|
+
const variable = theme[themeKey] as Variable
|
|
30
|
+
let value: any = null
|
|
31
|
+
// if (varToValMap) {
|
|
32
|
+
// varToValMap[variable.variable] = variable.val
|
|
33
|
+
// }
|
|
34
|
+
if (!tokensValueToVariable.has(variable.val)) {
|
|
35
|
+
value = variable.val
|
|
36
|
+
} else {
|
|
37
|
+
value = tokensValueToVariable.get(variable.val)!.variable
|
|
38
|
+
}
|
|
39
|
+
// Hash themeKey in case it has invalid chars too
|
|
40
|
+
vars += `--${simpleHash(themeKey, 40)}:${value};`
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const isDarkOrLightBase = themeName === 'dark' || themeName === 'light'
|
|
44
|
+
const selectors = names.map((name) => {
|
|
45
|
+
return `${CNP}${name}`
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
// since we dont specify dark/light in classnames we have to do an awkward specificity war
|
|
49
|
+
// use config.maxDarkLightNesting to determine how deep you can nest until it breaks
|
|
50
|
+
if (hasDarkLight) {
|
|
51
|
+
for (const subName of names) {
|
|
52
|
+
const isDark = isDarkOrLightBase || subName.startsWith('dark_')
|
|
53
|
+
const max = config.maxDarkLightNesting ?? 3
|
|
54
|
+
|
|
55
|
+
if (!(isDark || subName.startsWith('light_'))) {
|
|
56
|
+
// neither light nor dark subtheme, just generate one selector with :root:root which
|
|
57
|
+
// will override all :root light/dark selectors generated below
|
|
58
|
+
selectors.push(`:root:root ${CNP}${subName}`)
|
|
59
|
+
continue
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const childSelector = `${CNP}${subName.replace(isDark ? 'dark_' : 'light_', '')}`
|
|
63
|
+
const order = isDark ? ['dark', 'light'] : ['light', 'dark']
|
|
64
|
+
if (isDarkOrLightBase) {
|
|
65
|
+
order.reverse()
|
|
66
|
+
}
|
|
67
|
+
const [stronger, weaker] = order
|
|
68
|
+
const numSelectors = Math.round(max * 1.5)
|
|
69
|
+
|
|
70
|
+
for (let pi = 0; pi < numSelectors; pi++) {
|
|
71
|
+
const isOdd = pi % 2 === 1
|
|
72
|
+
if (isOdd && pi < 3) continue
|
|
73
|
+
const parents = new Array(pi + 1).fill(undefined).map((_, psi) => {
|
|
74
|
+
return `${CNP}${psi % 2 === 0 ? stronger : weaker}`
|
|
75
|
+
})
|
|
76
|
+
let parentSelectors = parents.length > 1 ? parents.slice(1) : parents
|
|
77
|
+
if (isOdd) {
|
|
78
|
+
const [_first, second, ...rest] = parentSelectors
|
|
79
|
+
parentSelectors = [second, ...rest, second]
|
|
80
|
+
}
|
|
81
|
+
// avoid .t_light .t_light at the end (make sure child is unique from last parent)
|
|
82
|
+
const lastParentSelector = parentSelectors[parentSelectors.length - 1]
|
|
83
|
+
selectors.push(
|
|
84
|
+
`${parentSelectors.join(' ')} ${
|
|
85
|
+
childSelector === lastParentSelector ? '' : childSelector
|
|
86
|
+
}`
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const selectorsString = selectors.map((x) => {
|
|
93
|
+
// only do our :root attach if it's not light/dark - not support sub themes on root saves a lot of effort/size
|
|
94
|
+
// this isBaseTheme logic could probably be done more efficiently above
|
|
95
|
+
const isBaseTheme =
|
|
96
|
+
x === '.t_dark' ||
|
|
97
|
+
x === '.t_light' ||
|
|
98
|
+
x.startsWith('.t_dark ') ||
|
|
99
|
+
x.startsWith('.t_light ')
|
|
100
|
+
const rootSep = isBaseTheme && config.themeClassNameOnRoot ? '' : ' '
|
|
101
|
+
return `:root${rootSep}${x}`
|
|
102
|
+
})
|
|
103
|
+
const css = `${selectorsString.join(', ')} {${vars}}`
|
|
104
|
+
cssRuleSets.push(css)
|
|
105
|
+
|
|
106
|
+
if (config.shouldAddPrefersColorThemes && isDarkOrLightBase) {
|
|
107
|
+
// add media prefers for dark/light base
|
|
108
|
+
const isDark = themeName.startsWith('dark')
|
|
109
|
+
cssRuleSets.push(
|
|
110
|
+
`@media(prefers-color-scheme: ${isDark ? 'dark' : 'light'}) {
|
|
111
|
+
body { background:${variableToString(theme.background)}; color: ${variableToString(
|
|
112
|
+
theme.color
|
|
113
|
+
)} }
|
|
114
|
+
:root {${vars} }
|
|
115
|
+
}`
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return cssRuleSets
|
|
120
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { getConfig } from '../config'
|
|
2
|
+
import { GenericFonts } from '../types'
|
|
3
|
+
import { LanguageContextType } from '../views/FontLanguage.types'
|
|
4
|
+
import { createProxy } from './createProxy'
|
|
5
|
+
|
|
6
|
+
const extrasCache = new WeakMap()
|
|
7
|
+
|
|
8
|
+
export function getVariantExtras(
|
|
9
|
+
props: any,
|
|
10
|
+
languageContext?: LanguageContextType,
|
|
11
|
+
theme?: any,
|
|
12
|
+
defaultProps?: any,
|
|
13
|
+
avoidDefaultProps = false
|
|
14
|
+
) {
|
|
15
|
+
const conf = getConfig()
|
|
16
|
+
|
|
17
|
+
if (extrasCache.has(props)) {
|
|
18
|
+
return extrasCache.get(props)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let fonts = conf.fontsParsed
|
|
22
|
+
if (languageContext) {
|
|
23
|
+
fonts = getFontsForLanguage(conf.fontsParsed, languageContext)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const next = {
|
|
27
|
+
fonts,
|
|
28
|
+
tokens: conf.tokensParsed,
|
|
29
|
+
theme,
|
|
30
|
+
// TODO do this in splitstlye
|
|
31
|
+
// we avoid passing in default props for media queries because that would confuse things like SizableText.size:
|
|
32
|
+
props: avoidDefaultProps
|
|
33
|
+
? props
|
|
34
|
+
: createProxy(props, {
|
|
35
|
+
// handles shorthands
|
|
36
|
+
get(target, key) {
|
|
37
|
+
const shorthand = conf.inverseShorthands[key as any]
|
|
38
|
+
// shorthands before longhand because a styled() with longhand combined with inline shorthand
|
|
39
|
+
// shorthand will always be the overriding key
|
|
40
|
+
if (shorthand && Reflect.has(target, shorthand)) {
|
|
41
|
+
return Reflect.get(target, shorthand)
|
|
42
|
+
}
|
|
43
|
+
if (Reflect.has(target, key)) {
|
|
44
|
+
return Reflect.get(target, key)
|
|
45
|
+
}
|
|
46
|
+
// these props may be extracted into classNames, but we still want to access them
|
|
47
|
+
// at runtime, so we proxy back to defaultProps but don't pass them
|
|
48
|
+
if (defaultProps) {
|
|
49
|
+
if (shorthand && Reflect.has(defaultProps, shorthand)) {
|
|
50
|
+
return Reflect.get(defaultProps, shorthand)
|
|
51
|
+
}
|
|
52
|
+
if (Reflect.has(defaultProps, key)) {
|
|
53
|
+
return Reflect.get(defaultProps, key)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
}),
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
extrasCache.set(props, next)
|
|
61
|
+
|
|
62
|
+
return next
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const fontLanguageCache = new WeakMap()
|
|
66
|
+
|
|
67
|
+
export function getFontsForLanguage(fonts: GenericFonts, language: LanguageContextType) {
|
|
68
|
+
if (fontLanguageCache.has(language)) {
|
|
69
|
+
return fontLanguageCache.get(language)
|
|
70
|
+
}
|
|
71
|
+
const next = {
|
|
72
|
+
...fonts,
|
|
73
|
+
...Object.fromEntries(
|
|
74
|
+
Object.entries(language).map(([name, lang]) => {
|
|
75
|
+
if (lang === 'default') {
|
|
76
|
+
return []
|
|
77
|
+
}
|
|
78
|
+
const langKey = `$${name}_${lang}`
|
|
79
|
+
return [`$${name}`, fonts[langKey]]
|
|
80
|
+
})
|
|
81
|
+
),
|
|
82
|
+
}
|
|
83
|
+
fontLanguageCache.set(language, next)
|
|
84
|
+
return next
|
|
85
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import type { StyleObject } from '@tamagui/helpers'
|
|
2
|
+
|
|
3
|
+
import { PartialStyleObject, RulesToInsert } from '../types'
|
|
4
|
+
|
|
5
|
+
const allSelectors: Record<string, string> = {}
|
|
6
|
+
const allRules: Record<string, string> = {}
|
|
7
|
+
export const insertedTransforms = {}
|
|
8
|
+
|
|
9
|
+
export const getAllSelectors = () => allSelectors
|
|
10
|
+
export const getAllRules = () => Object.values(allRules)
|
|
11
|
+
export const getAllTransforms = () => insertedTransforms
|
|
12
|
+
|
|
13
|
+
// keep transforms in map for merging later
|
|
14
|
+
function addTransform(identifier: string, css: string, rule?: CSSRule) {
|
|
15
|
+
const s = css.indexOf('transform:')
|
|
16
|
+
if (s === -1) {
|
|
17
|
+
if (process.env.NODE_ENV === 'development') {
|
|
18
|
+
console.error(`❌ Invalid transform, likely used deg/% improperly ${identifier}`)
|
|
19
|
+
}
|
|
20
|
+
return false
|
|
21
|
+
}
|
|
22
|
+
const startI = s + 'transform:'.length
|
|
23
|
+
const endI = css.indexOf(';')
|
|
24
|
+
const value = css.slice(startI, endI)
|
|
25
|
+
if (!insertedTransforms[identifier]) {
|
|
26
|
+
insertedTransforms[identifier] = value
|
|
27
|
+
return true
|
|
28
|
+
}
|
|
29
|
+
return false
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const isClient = typeof document !== 'undefined'
|
|
33
|
+
|
|
34
|
+
// gets existing ones (client side)
|
|
35
|
+
// takes ~0.1ms for a fairly large page
|
|
36
|
+
// used now for three things:
|
|
37
|
+
// 1. debugging at dev time
|
|
38
|
+
// 2. avoid duplicate insert styles at runtime
|
|
39
|
+
// 3. used now for merging transforms atomically
|
|
40
|
+
|
|
41
|
+
// multiple sheets could have the same ids so we have to count
|
|
42
|
+
|
|
43
|
+
// only cache tamagui styles
|
|
44
|
+
const scannedCache = new WeakMap<CSSStyleSheet, string>()
|
|
45
|
+
const totalSheetSelectors = new Map<string, number>()
|
|
46
|
+
|
|
47
|
+
export function listenForSheetChanges() {
|
|
48
|
+
if (!isClient) return
|
|
49
|
+
function handleNode(node: Node, remove = false) {
|
|
50
|
+
if (node instanceof HTMLStyleElement && node.sheet) {
|
|
51
|
+
updateSheetStyles(node.sheet, remove)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const mo = new MutationObserver((entries) => {
|
|
55
|
+
for (const entry of entries) {
|
|
56
|
+
entry.addedNodes.forEach((node) => handleNode(node))
|
|
57
|
+
entry.removedNodes.forEach((node) => handleNode(node, true))
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
mo.observe(document.head, {
|
|
61
|
+
childList: true,
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function scanAllSheets() {
|
|
66
|
+
if (process.env.NODE_ENV === 'test') return
|
|
67
|
+
if (!isClient) return
|
|
68
|
+
const sheets = document.styleSheets
|
|
69
|
+
if (!sheets) return
|
|
70
|
+
for (let i = 0; i < sheets.length; i++) {
|
|
71
|
+
const sheet = sheets[i]
|
|
72
|
+
if (!sheet) continue
|
|
73
|
+
updateSheetStyles(sheet)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function track(id: string, remove = false) {
|
|
78
|
+
const next = (totalSheetSelectors.get(id) || 0) + (remove ? -1 : 1)
|
|
79
|
+
totalSheetSelectors.set(id, next)
|
|
80
|
+
return next
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function updateSheetStyles(sheet: CSSStyleSheet, remove = false) {
|
|
84
|
+
// avoid errors on cross origin sheets
|
|
85
|
+
// https://stackoverflow.com/questions/49993633/uncaught-domexception-failed-to-read-the-cssrules-property
|
|
86
|
+
let rules: CSSRuleList
|
|
87
|
+
try {
|
|
88
|
+
rules = sheet.cssRules
|
|
89
|
+
} catch {
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// not tamagui stylesheet
|
|
94
|
+
const firstSelector = getTamaguiSelector(rules[0])?.[0]
|
|
95
|
+
if (!firstSelector) {
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const lastSelector = getTamaguiSelector(rules[rules.length - 1])?.[0]
|
|
100
|
+
|
|
101
|
+
const cacheKey = `${rules.length}${firstSelector}${lastSelector}`
|
|
102
|
+
const lastScanned = scannedCache.get(sheet)
|
|
103
|
+
if (!remove) {
|
|
104
|
+
// avoid re-scanning
|
|
105
|
+
if (lastScanned === cacheKey) {
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const len = rules.length
|
|
111
|
+
for (let i = 0; i < len; i++) {
|
|
112
|
+
const rule = rules[i]
|
|
113
|
+
const response = getTamaguiSelector(rule)
|
|
114
|
+
if (!response) {
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const [identifier, cssRule] = response
|
|
119
|
+
|
|
120
|
+
// track references
|
|
121
|
+
const total = track(identifier, remove)
|
|
122
|
+
|
|
123
|
+
if (remove) {
|
|
124
|
+
if (total === 0) {
|
|
125
|
+
delete allSelectors[identifier]
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
if (!(identifier in allSelectors)) {
|
|
129
|
+
const isTransform = identifier.startsWith('_transform')
|
|
130
|
+
const shouldInsert = isTransform
|
|
131
|
+
? addTransform(identifier, cssRule.cssText, cssRule)
|
|
132
|
+
: true
|
|
133
|
+
if (shouldInsert) {
|
|
134
|
+
allSelectors[identifier] = cssRule.cssText
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
scannedCache.set(sheet, cacheKey)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function getTamaguiSelector(
|
|
144
|
+
rule: CSSRule | null
|
|
145
|
+
): readonly [string, CSSStyleRule] | null {
|
|
146
|
+
if (rule instanceof CSSStyleRule) {
|
|
147
|
+
const text = rule.selectorText
|
|
148
|
+
if (text[0] === '.' && text[1] === '_') {
|
|
149
|
+
return [text.slice(1), rule]
|
|
150
|
+
}
|
|
151
|
+
if (text.startsWith(':root') && text.includes('._')) {
|
|
152
|
+
return [getIdentifierFromTamaguiSelector(text), rule]
|
|
153
|
+
}
|
|
154
|
+
} else if (rule instanceof CSSMediaRule) {
|
|
155
|
+
// tamagui only ever inserts 1 rule per media
|
|
156
|
+
if (rule.cssRules.length > 1) return null
|
|
157
|
+
return getTamaguiSelector(rule.cssRules[0])
|
|
158
|
+
}
|
|
159
|
+
return null
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const getIdentifierFromTamaguiSelector = (selector: string) =>
|
|
163
|
+
selector
|
|
164
|
+
.replace(/(:root)+\s+/, '')
|
|
165
|
+
.replace(/:[a-z]+$/, '')
|
|
166
|
+
.slice(1)
|
|
167
|
+
|
|
168
|
+
const sheet = isClient
|
|
169
|
+
? document.head.appendChild(document.createElement('style')).sheet
|
|
170
|
+
: null
|
|
171
|
+
|
|
172
|
+
export function updateRules(identifier: string, rules: string[]) {
|
|
173
|
+
if (allRules[identifier]) return false
|
|
174
|
+
allRules[identifier] = rules.join(' ')
|
|
175
|
+
if (identifier.startsWith('_transform')) {
|
|
176
|
+
return addTransform(identifier, rules[0])
|
|
177
|
+
}
|
|
178
|
+
return true
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function insertStyleRules(rulesToInsert: RulesToInsert) {
|
|
182
|
+
if (!rulesToInsert.length) return
|
|
183
|
+
if (isClient && !sheet) {
|
|
184
|
+
if (process.env.NODE_ENV === 'development') throw 'impossible'
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
for (const { identifier, rules } of rulesToInsert) {
|
|
188
|
+
if (identifier in allSelectors) continue
|
|
189
|
+
allSelectors[identifier] =
|
|
190
|
+
process.env.NODE_ENV === 'development' ? rules.join('\n') : ' '
|
|
191
|
+
updateRules(identifier, rules)
|
|
192
|
+
if (sheet) {
|
|
193
|
+
for (const rule of rules) {
|
|
194
|
+
try {
|
|
195
|
+
sheet.insertRule(rule, sheet.cssRules.length)
|
|
196
|
+
} catch (err) {
|
|
197
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
198
|
+
console.groupCollapsed(
|
|
199
|
+
`Error inserting rule into CSSStyleSheet: ${String(err)}`
|
|
200
|
+
)
|
|
201
|
+
console.log({ rule, rulesToInsert })
|
|
202
|
+
console.trace()
|
|
203
|
+
console.groupEnd()
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const IS_STATIC = process.env.IS_STATIC === 'is_static'
|
|
212
|
+
|
|
213
|
+
export function shouldInsertStyleRules(styleObject: PartialStyleObject) {
|
|
214
|
+
if (IS_STATIC) {
|
|
215
|
+
return true
|
|
216
|
+
}
|
|
217
|
+
return !(styleObject.identifier in allSelectors)
|
|
218
|
+
}
|