@tamagui/core 1.0.1-beta.191 → 1.0.1-beta.193
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/createComponent.js +15 -7
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/helpers/createProxy.js +43 -0
- package/dist/cjs/helpers/createProxy.js.map +7 -0
- package/dist/cjs/helpers/getSplitStyles.js +13 -12
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/getVariantExtras.js +2 -1
- package/dist/cjs/helpers/getVariantExtras.js.map +2 -2
- package/dist/cjs/helpers/proxyThemeVariables.js +2 -5
- package/dist/cjs/helpers/proxyThemeVariables.js.map +2 -2
- package/dist/cjs/hooks/useMedia.js +2 -1
- package/dist/cjs/hooks/useMedia.js.map +2 -2
- package/dist/cjs/hooks/useTheme.js +2 -1
- package/dist/cjs/hooks/useTheme.js.map +2 -2
- package/dist/esm/createComponent.js +15 -7
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/helpers/createProxy.js +19 -0
- package/dist/esm/helpers/createProxy.js.map +7 -0
- package/dist/esm/helpers/getSplitStyles.js +13 -12
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/getVariantExtras.js +2 -1
- package/dist/esm/helpers/getVariantExtras.js.map +2 -2
- package/dist/esm/helpers/proxyThemeVariables.js +2 -5
- package/dist/esm/helpers/proxyThemeVariables.js.map +2 -2
- package/dist/esm/hooks/useMedia.js +2 -1
- package/dist/esm/hooks/useMedia.js.map +2 -2
- package/dist/esm/hooks/useTheme.js +2 -1
- package/dist/esm/hooks/useTheme.js.map +2 -2
- package/package.json +11 -11
- package/src/createComponent.tsx +17 -8
- package/src/helpers/createProxy.ts +16 -0
- package/src/helpers/getSplitStyles.tsx +12 -12
- package/src/helpers/getVariantExtras.tsx +2 -1
- package/src/helpers/proxyThemeVariables.tsx +3 -6
- package/src/hooks/useMedia.tsx +2 -1
- package/src/hooks/useTheme.tsx +2 -1
- package/types/helpers/createProxy.d.ts +2 -0
- package/src/helpers/validate.ts +0 -80
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/getSplitStyles.tsx"],
|
|
4
|
-
"sourcesContent": ["import { isClient, isRSC, isWeb, useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { stylePropsText, stylePropsTransform, validPseudoKeys, validStyles } from '@tamagui/helpers'\nimport { useInsertionEffect } from 'react'\nimport type { ViewStyle } from 'react-native'\n\nimport { getConfig } from '../config'\nimport { isDevTools } from '../constants/isDevTools'\nimport { mediaState as globalMediaState, mediaQueryConfig } from '../hooks/useMedia'\nimport type {\n DebugProp,\n MediaQueryKey,\n PseudoPropKeys,\n PseudoStyles,\n SplitStyleState,\n StackProps,\n StaticConfigParsed,\n TamaguiInternalConfig,\n ThemeParsed,\n} from '../types'\nimport { FontLanguageProps, LanguageContextType } from '../views/FontLanguage.types'\nimport { createMediaStyle } from './createMediaStyle'\nimport { getPropMappedFontFamily } from './createPropMapper'\nimport { fixStyles } from './expandStyles'\nimport { getAtomicStyle, getStylesAtomic, styleToCSS } from './getStylesAtomic'\nimport {\n PartialStyleObject,\n RulesToInsert,\n insertStyleRules,\n insertedTransforms,\n shouldInsertStyleRules,\n updateInserted,\n updateRules,\n} from './insertStyleRule'\nimport { mergeProps } from './mergeProps'\nimport { mergeTransform } from './mergeTransform'\nimport { normalizeValueWithProperty } from './normalizeValueWithProperty.js'\nimport { pseudoDescriptors } from './pseudoDescriptors'\n\nexport type SplitStyles = ReturnType<typeof getSplitStyles>\nexport type ClassNamesObject = Record<string, string>\nexport type SplitStyleResult = ReturnType<typeof getSplitStyles>\n\nconst skipProps = {\n animation: true,\n animateOnly: true,\n debug: true,\n componentName: true,\n\n ...(!isWeb && {\n tag: true,\n whiteSpace: true,\n wordWrap: true,\n textOverflow: true,\n textDecorationDistance: true,\n userSelect: true,\n selectable: true,\n cursor: true,\n contain: true,\n boxSizing: true,\n boxShadow: true,\n }),\n}\n\ntype TransformNamespaceKey = 'transform' | PseudoPropKeys | MediaQueryKey\n\nlet conf: TamaguiInternalConfig\n\ntype StyleSplitter = (\n props: { [key: string]: any },\n staticConfig: StaticConfigParsed,\n theme: ThemeParsed,\n state: SplitStyleState,\n defaultClassNames?: any,\n languageContext?: LanguageContextType,\n debug?: DebugProp\n) => {\n pseudos: PseudoStyles\n medias: Record<MediaQueryKey, ViewStyle>\n style: ViewStyle\n classNames: ClassNamesObject\n rulesToInsert: RulesToInsert\n viewProps: StackProps\n fontFamily: string | undefined\n mediaKeys: string[]\n}\n\nexport const PROP_SPLIT = '-'\n\n// this is how compiler outputs psueodo identifier\n// TODO remove in next refactor\nexport const pseudoCNInverse = {\n hover: 'hoverStyle',\n focus: 'focusStyle',\n press: 'pressStyle',\n}\n\n// loop props backwards\n// track used keys:\n// const keys = new Set<string>()\n// keep classnames and styles separate:\n// const styles = {}\n// const classNames = {}\n\nexport const getSplitStyles: StyleSplitter = (\n props,\n staticConfig,\n theme,\n state,\n defaultClassNames,\n languageContext,\n debug\n) => {\n conf = conf || getConfig()\n const validStyleProps = staticConfig.isText ? stylePropsText : validStyles\n const mediaKeys: string[] = []\n const viewProps: StackProps = {}\n const pseudos: PseudoStyles = {}\n const medias: Record<MediaQueryKey, ViewStyle> = {}\n const mediaState = state.mediaState || globalMediaState\n const usedKeys = new Set<string>()\n const propKeys = Object.keys(props)\n const shouldDoClasses =\n staticConfig.acceptsClassName &&\n (isWeb || process.env.IS_STATIC === 'is_static') &&\n !state.noClassNames &&\n !props.animation\n const len = propKeys.length\n const rulesToInsert: RulesToInsert = []\n const style: ViewStyle = {}\n // TODO make this CSS, not compile-friendly\n if (state.hasTextAncestor) {\n // parity with react-native-web\n style.display = 'inline-flex' as any\n }\n const classNames: ClassNamesObject = {}\n // we need to gather these specific to each media query / pseudo\n // value is [hash, val], so [\"-jnjad-asdnjk\", \"scaleX(1) rotate(10deg)\"]\n const transforms: Record<TransformNamespaceKey, [string, string]> = {}\n // fontFamily is our special baby, ensure we grab the latest set one always\n let fontFamily: string | undefined\n\n // loop backwards so we can skip already-used props\n for (let i = len - 1; i >= 0; i--) {\n let keyInit = propKeys[i]\n const valInit = props[keyInit]\n\n // normalize shorthands up front\n const expandedKey = conf.shorthands[keyInit]\n if (expandedKey) {\n keyInit = expandedKey\n }\n\n if (usedKeys.has(keyInit)) continue\n if (skipProps[keyInit]) continue\n if (!isWeb && keyInit.startsWith('data-')) continue\n\n if (keyInit === 'style' || keyInit.startsWith('_style')) {\n if (!valInit) continue\n for (const key in valInit) {\n if (usedKeys.has(key)) continue\n if (valInit && typeof valInit === 'object') {\n // newer react native versions return a full object instead of ID\n for (const skey in valInit) {\n if (usedKeys.has(skey)) continue\n usedKeys.add(skey)\n style[skey] = valInit[skey]\n }\n } else {\n usedKeys.add(key)\n style[key] = valInit\n }\n }\n continue\n }\n\n if (process.env.TAMAGUI_TARGET === 'web') {\n if (keyInit === 'className') {\n let nonTamaguis = ''\n if (!valInit) continue\n for (const cn of valInit.split(' ')) {\n if (cn[0] === '_') {\n // tamagui, merge it expanded on key, eventually this will go away with better compiler\n const [shorthand, mediaOrPseudo] = cn.slice(1).split('-')\n const isMedia = mediaOrPseudo[0] === '_'\n const isPseudo = mediaOrPseudo[0] === '0'\n const isMediaOrPseudo = isMedia || isPseudo\n let fullKey = conf.shorthands[shorthand]\n if (isMedia) {\n // is media\n let mediaShortKey = mediaOrPseudo.slice(1)\n mediaShortKey = mediaShortKey.slice(0, mediaShortKey.indexOf('_'))\n fullKey += `${PROP_SPLIT}${mediaShortKey}`\n } else if (isPseudo) {\n // is pseudo\n const pseudoShortKey = mediaOrPseudo.slice(1)\n fullKey += `${PROP_SPLIT}${pseudoShortKey}`\n }\n usedKeys.add(fullKey)\n mergeClassName(transforms, classNames, fullKey, cn, isMediaOrPseudo)\n } else {\n nonTamaguis += ' ' + cn\n }\n }\n if (nonTamaguis) {\n usedKeys.add(keyInit)\n mergeClassName(transforms, classNames, keyInit, nonTamaguis)\n }\n continue\n }\n\n if (valInit && valInit[0] === '_') {\n // if valid style key (or pseudo like color-hover):\n // this conditional and esp the pseudo check rarely runs so not a perf issue\n const isValidClassName = validStyles[keyInit]\n const isMediaOrPseudo =\n !isValidClassName &&\n keyInit.includes(PROP_SPLIT) &&\n validStyles[keyInit.split(PROP_SPLIT)[0]]\n if (isValidClassName || isMediaOrPseudo) {\n usedKeys.add(keyInit)\n mergeClassName(transforms, classNames, keyInit, valInit, isMediaOrPseudo)\n continue\n }\n }\n }\n\n if (state.keepVariantsAsProps) {\n if (\n (staticConfig.defaultVariants && keyInit in staticConfig.defaultVariants) ||\n // may want to just: not compile styled() into classnames, always do this, and always pass in all values in extras.props\n // but we'd want to add styled({ extracted: true }) or something at compile time to save on parsing a bit...\n (staticConfig.variants && keyInit in staticConfig.variants)\n ) {\n viewProps[keyInit] = valInit\n }\n }\n\n /**\n * There's (some) reason to this madness: we want to allow returning media/pseudo from variants\n * Say you have a variant hoverable: { true: { hoverStyle: {} } }\n * We run propMapper first to expand variant, then we run the inner loop and look again\n * for if there's a pseudo/media returned from it.\n */\n\n let isMedia = keyInit[0] === '$'\n let isPseudo = validPseudoKeys[keyInit]\n let isMediaOrPseudo = isMedia || isPseudo\n\n if (\n !isMedia &&\n !isPseudo &&\n !staticConfig.variants?.[keyInit] &&\n !validStyleProps[keyInit] &&\n !conf.shorthands[keyInit]\n ) {\n usedKeys.add(keyInit)\n viewProps[keyInit] = valInit\n continue\n }\n\n if (process.env.NODE_ENV === 'development' && debug === 'verbose') {\n // eslint-disable-next-line no-console\n console.groupCollapsed(' \uD83D\uDD39 styles', keyInit, valInit)\n }\n\n const expanded =\n isMedia || isPseudo\n ? [[keyInit, valInit]]\n : staticConfig.propMapper(\n keyInit,\n valInit,\n theme,\n props,\n state,\n languageContext,\n undefined,\n debug\n )\n\n if (!fontFamily) {\n fontFamily = getPropMappedFontFamily(expanded)\n }\n\n if (process.env.NODE_ENV === 'development' && debug === 'verbose') {\n // eslint-disable-next-line no-console\n console.log('expanded', expanded)\n // eslint-disable-next-line no-console\n console.log('usedKeys', [...usedKeys])\n // eslint-disable-next-line no-console\n console.groupEnd()\n }\n\n if (!expanded) {\n continue\n }\n\n for (const [key, val] of expanded) {\n if (val === undefined) continue\n\n isMedia = key[0] === '$'\n isPseudo = validPseudoKeys[key]\n isMediaOrPseudo = isMedia || isPseudo\n\n if (!isMediaOrPseudo) {\n if (usedKeys.has(key)) continue\n }\n\n if (\n (staticConfig.deoptProps && staticConfig.deoptProps.has(key)) ||\n (staticConfig.inlineProps && staticConfig.inlineProps.has(key)) ||\n (staticConfig.inlineWhenUnflattened && staticConfig.inlineWhenUnflattened.has(key))\n ) {\n usedKeys.add(key)\n viewProps[key] = props[key] ?? val\n }\n\n // pseudo\n if (isPseudo) {\n if (!val) continue\n if (key === 'enterStyle' && state.mounted) {\n // once mounted we can ignore enterStyle\n continue\n }\n pseudos[key] = pseudos[key] || {}\n const pseudoStyleObject = getSubStyle(\n key,\n val,\n staticConfig,\n theme,\n props,\n state,\n conf,\n languageContext,\n true\n )\n\n pseudos[key] = {\n ...pseudoStyleObject,\n ...pseudos[key],\n }\n\n if (shouldDoClasses && key !== 'enterStyle' && key !== 'exitStyle') {\n const pseudoStyles = getAtomicStyle(pseudoStyleObject, pseudoDescriptors[key])\n for (const style of pseudoStyles) {\n const postfix = pseudoDescriptors[key]?.name || key // exitStyle/enterStyle dont have pseudoDescriptors\n const fullKey = `${style.property}${PROP_SPLIT}${postfix}`\n if (!usedKeys.has(fullKey)) {\n usedKeys.add(fullKey)\n addStyleToInsertRules(rulesToInsert, style)\n mergeClassName(transforms, classNames, fullKey, style.identifier, isMediaOrPseudo)\n }\n }\n }\n continue\n }\n\n // media\n if (isMedia) {\n const mediaKey = key\n const mediaKeyShort = mediaKey.slice(1)\n\n mediaKeys.push(mediaKeyShort)\n\n if (!mediaQueryConfig[mediaKeyShort]) {\n if (process.env.NODE_ENV === 'development' && debug) {\n // eslint-disable-next-line no-console\n console.warn(\n `Warning: using a $ prefixed prop that doesn't match to a media query, may be an error`,\n key\n )\n }\n if (!usedKeys.has(key)) {\n // this isn't a media key, pass through\n viewProps[key] = val\n }\n continue\n }\n\n // dont check if media is active, we just apply *all* media styles\n // we combine the media props on top regular props, could proxy this\n // TODO test proxy here instead of merge\n // THIS USED TO PROXY BACK TO REGULAR PROPS BUT THAT IS THE WRONG BEHAVIOR\n // we avoid passing in default props for media queries because that would confuse things like SizableText.size:\n const mediaStyle = getSubStyle(\n key,\n val,\n staticConfig,\n theme,\n props,\n state,\n conf,\n languageContext\n )\n\n if (process.env.NODE_ENV === 'development' && debug === 'verbose') {\n // prettier-ignore\n // eslint-disable-next-line no-console\n console.log(` \uD83D\uDCFA ${mediaKey}`, mediaState[mediaKeyShort], { mediaKey, mediaStyle, props, shouldDoClasses, mediaState: { ...mediaState } })\n }\n\n if (shouldDoClasses) {\n const mediaStyles = getStylesAtomic(mediaStyle)\n for (const style of mediaStyles) {\n const out = createMediaStyle(style, mediaKeyShort, mediaQueryConfig)\n const fullKey = `${style.property}${PROP_SPLIT}${mediaKeyShort}`\n if (!usedKeys.has(fullKey)) {\n usedKeys.add(fullKey)\n addStyleToInsertRules(rulesToInsert, out)\n mergeClassName(transforms, classNames, fullKey, out.identifier, true)\n }\n }\n } else {\n if (mediaState[mediaKeyShort]) {\n if (process.env.NODE_ENV === 'development' && debug) {\n // eslint-disable-next-line no-console\n console.log('apply media style', mediaKey, mediaState)\n }\n if (shouldDoClasses) {\n Object.assign(medias, mediaStyle)\n } else {\n for (const key in mediaStyle) {\n // TODO we should likely account for importance here to match CSS, right??\n usedKeys.add(key)\n style[key] = mediaStyle[key]\n if (key === 'fontFamily') {\n fontFamily = mediaStyle[key]\n }\n }\n }\n }\n }\n continue\n }\n\n if (!isWeb && key === 'pointerEvents') {\n usedKeys.add(key)\n viewProps[key] = val\n continue\n }\n\n if (key === 'fontFamily' && !fontFamily && valInit && val) {\n fontFamily = valInit[0] === '$' ? valInit : val\n }\n\n if (validStyleProps[key]) {\n usedKeys.add(key)\n if (val && val[0] === '_') {\n classNames[key] = val\n } else if (key in stylePropsTransform) {\n mergeTransform(style, key, val, true)\n } else {\n style[key] = normalizeValueWithProperty(val, key)\n }\n continue\n }\n\n // pass to view props\n if (!staticConfig.variants || !(key in staticConfig.variants)) {\n if (!skipProps[key]) {\n viewProps[key] = val\n usedKeys.add(key)\n }\n }\n }\n }\n\n fixStyles(style)\n if (isWeb) {\n styleToCSS(style)\n }\n\n // add in defaults if not set:\n if (defaultClassNames) {\n for (const key in defaultClassNames) {\n if (!(key in classNames)) {\n classNames[key] = defaultClassNames[key]\n }\n }\n }\n\n if (shouldDoClasses) {\n const atomic = getStylesAtomic(style)\n for (const atomicStyle of atomic) {\n const key = atomicStyle.property\n // pointerEvents box-none must be CSS-ified\n // should probably have a few more exceptions here!\n if (key === 'pointerEvents' || !state.dynamicStylesInline) {\n addStyleToInsertRules(rulesToInsert, atomicStyle)\n mergeClassName(transforms, classNames, key, atomicStyle.identifier)\n } else {\n style[key] = atomicStyle.value\n }\n }\n }\n\n // else {\n // if (classNames && state.resolveVariablesAs === 'value') {\n // getting real values for colors for animations (reverse mapped from CSS)\n // this isn't beautiful, but will do relatively fine performance for now\n // has a bug still - try adding <Switch theme=\"bouncy\" /> should animate bg color on active\n // const selectors = getAllSelectors()\n // for (const key in classNames) {\n // if (key.endsWith('Color')) {\n // const selector = classNames[key]\n // let value = selectorValuesCache[selector]\n // if (!value) {\n // const css = selectors[selector]\n // value = css.replace(/.*:/, '').replace(/;.*/, '')\n // if (value) {\n // const themeUnwrapped = getThemeUnwrapped(theme)\n // const map = themeToVariableToValueMap.get(themeUnwrapped)\n // if (map && value.startsWith('var(')) {\n // value = map[value]\n // }\n // if (value) {\n // selectorValuesCache[selector] = value\n // }\n // } else {\n // // err\n // continue\n // }\n // }\n // if (value) {\n // style[key] = value\n // }\n // }\n // }\n // }\n // }\n\n if (process.env.TAMAGUI_TARGET === 'web') {\n if (transforms) {\n for (const namespace in transforms) {\n if (!transforms[namespace]) {\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn('Error no transform', transforms, namespace)\n }\n continue\n }\n const [hash, val] = transforms[namespace]\n const identifier = `_transform${hash}`\n if (isClient) {\n if (!insertedTransforms[identifier]) {\n const rule = `.${identifier} { transform: ${val}; }`\n addStyleToInsertRules(rulesToInsert, {\n identifier,\n rules: [rule],\n property: namespace,\n })\n }\n }\n classNames[namespace] = identifier\n }\n }\n }\n\n if (process.env.NODE_ENV === 'development' && debug === 'verbose') {\n if (isDevTools) {\n // prettier-ignore\n // eslint-disable-next-line no-console\n console.groupCollapsed(' \uD83D\uDD39 styles =>')\n const logs = { style, pseudos, medias, classNames, viewProps, state, rulesToInsert }\n for (const key in logs) {\n // eslint-disable-next-line no-console\n console.log(key, logs[key])\n }\n // eslint-disable-next-line no-console\n console.groupEnd()\n }\n }\n\n return {\n fontFamily,\n viewProps,\n style,\n medias,\n mediaKeys,\n pseudos,\n classNames,\n rulesToInsert,\n }\n}\n\nfunction mergeClassName(\n transforms: Record<string, any[]>,\n classNames: Record<string, string>,\n key: string,\n val: string,\n isMediaOrPseudo = false\n) {\n if (process.env.TAMAGUI_TARGET === 'web') {\n // empty classnames passed by compiler sometimes\n if (!val) return\n if (val.startsWith('_transform-')) {\n const namespace: TransformNamespaceKey = isMediaOrPseudo ? key : 'transform'\n let transform = insertedTransforms[val]\n if (isClient) {\n if (!transform) {\n // HMR or loaded a new chunk\n updateInserted()\n transform = insertedTransforms[val]\n if (process.env.NODE_ENV === 'development') {\n if (!transform) {\n // eslint-disable-next-line no-console\n console.warn('no transform found', { insertedTransforms, val })\n }\n }\n }\n if (!transform) {\n if (isWeb && val[0] !== '_') {\n // runtime insert\n transform = val\n }\n }\n }\n transforms[namespace] = transforms[namespace] || ['', '']\n const identifier = val.replace('_transform', '')\n transforms[namespace][0] += identifier\n // ssr doesn't need to do anything just make the right classname\n if (transform) {\n transforms[namespace][1] += transform\n }\n } else {\n classNames[key] = val\n }\n }\n}\n\n/**\n * getSubStyle calls propMapper with props\n * those should be specific to the substyle, but fallback to the base props\n * so given props:\n *\n * { fontSize: 12, color: 'red', $sm: { color: 'blue' } }\n *\n * getSubStyle props should be a proxy that ends up like:\n *\n * { fontSize: 12, color: 'blue' }\n *\n * and to avoid re-creating it over and over, use a WeakMap\n */\nconst propProxies = new WeakMap()\nfunction getSubStyleProxiedProps(defaultProps: Object, baseProps: Object, specificProps: Object) {\n if (!specificProps) {\n // functional variants may want to eventually do something like:\n // have a hooks-like rule (no conditionals)\n // then we run them once on compile with a proxy to capture the keys accessed\n // then add those keys to `inlineProps` so we know we must inline them\n // for now this will trigger because compiled away\n // right now also we don't pass in any pre-extracted styled() props but we should pass them in..\n return baseProps\n }\n // can cache based only on specific it's always referentially consistent with base\n if (propProxies.has(specificProps)) {\n return propProxies.get(specificProps)\n }\n const next = new Proxy(specificProps, {\n has(_, key) {\n return key in defaultProps || key in specificProps || key in baseProps\n },\n get(_, key) {\n return defaultProps[key] ?? specificProps[key] ?? baseProps[key]\n },\n })\n propProxies.set(specificProps, next)\n return next\n}\n\nexport const getSubStyle = (\n subKey: string,\n styleIn: Object,\n staticConfig: StaticConfigParsed,\n theme: ThemeParsed,\n props: any,\n state: SplitStyleState,\n conf: TamaguiInternalConfig,\n languageContext?: FontLanguageProps,\n avoidDefaultProps?: boolean\n): ViewStyle => {\n const styleOut: ViewStyle = {}\n for (let key in styleIn) {\n const val = styleIn[key]\n key = conf.shorthands[key] || key\n const expanded = staticConfig.propMapper(\n key,\n val,\n theme,\n getSubStyleProxiedProps(staticConfig.defaultProps, props, props[subKey]),\n state,\n languageContext,\n avoidDefaultProps\n )\n if (!expanded) continue\n for (const [skey, sval] of expanded) {\n if (skey in stylePropsTransform) {\n mergeTransform(styleOut, skey, sval)\n } else {\n styleOut[skey] = normalizeValueWithProperty(sval, key)\n }\n }\n }\n\n fixStyles(styleOut)\n\n return styleOut\n}\n\nexport const insertSplitStyles: StyleSplitter = (...args) => {\n const res = getSplitStyles(...args)\n insertStyleRules(res.rulesToInsert)\n return res\n}\n\n// on native no need to insert any css\nconst useInsertEffectCompat = isWeb ? useInsertionEffect || useIsomorphicLayoutEffect : () => {}\n\nexport const useSplitStyles: StyleSplitter = (...args) => {\n const res = getSplitStyles(...args)\n\n if (!isRSC) {\n useInsertEffectCompat(() => {\n insertStyleRules(res.rulesToInsert)\n }, [res.rulesToInsert])\n }\n\n return res\n}\n\nfunction addStyleToInsertRules(rulesToInsert: RulesToInsert, styleObject: PartialStyleObject) {\n if (process.env.TAMAGUI_TARGET === 'web') {\n if (!shouldInsertStyleRules(styleObject)) {\n return\n }\n updateRules(styleObject.identifier, styleObject.rules)\n rulesToInsert.push(styleObject)\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,OAAO,OAAO,iCAAiC;AAClE,SAAS,gBAAgB,qBAAqB,iBAAiB,mBAAmB;AAClF,SAAS,0BAA0B;AAGnC,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,cAAc,kBAAkB,wBAAwB;AAajE,SAAS,wBAAwB;AACjC,SAAS,+BAA+B;AACxC,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB,iBAAiB,kBAAkB;AAC5D;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,sBAAsB;AAC/B,SAAS,kCAAkC;AAC3C,SAAS,yBAAyB;AAMlC,MAAM,YAAY;AAAA,EAChB,WAAW;AAAA,EACX,aAAa;AAAA,EACb,OAAO;AAAA,EACP,eAAe;
|
|
4
|
+
"sourcesContent": ["import { isClient, isRSC, isWeb, useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { stylePropsText, stylePropsTransform, validPseudoKeys, validStyles } from '@tamagui/helpers'\nimport { useInsertionEffect } from 'react'\nimport type { ViewStyle } from 'react-native'\n\nimport { getConfig } from '../config'\nimport { isDevTools } from '../constants/isDevTools'\nimport { mediaState as globalMediaState, mediaQueryConfig } from '../hooks/useMedia'\nimport type {\n DebugProp,\n MediaQueryKey,\n PseudoPropKeys,\n PseudoStyles,\n SplitStyleState,\n StackProps,\n StaticConfigParsed,\n TamaguiInternalConfig,\n ThemeParsed,\n} from '../types'\nimport { FontLanguageProps, LanguageContextType } from '../views/FontLanguage.types'\nimport { createMediaStyle } from './createMediaStyle'\nimport { getPropMappedFontFamily } from './createPropMapper'\nimport { createProxy } from './createProxy'\nimport { fixStyles } from './expandStyles'\nimport { getAtomicStyle, getStylesAtomic, styleToCSS } from './getStylesAtomic'\nimport {\n PartialStyleObject,\n RulesToInsert,\n insertStyleRules,\n insertedTransforms,\n shouldInsertStyleRules,\n updateInserted,\n updateRules,\n} from './insertStyleRule'\nimport { mergeProps } from './mergeProps'\nimport { mergeTransform } from './mergeTransform'\nimport { normalizeValueWithProperty } from './normalizeValueWithProperty.js'\nimport { pseudoDescriptors } from './pseudoDescriptors'\n\nexport type SplitStyles = ReturnType<typeof getSplitStyles>\nexport type ClassNamesObject = Record<string, string>\nexport type SplitStyleResult = ReturnType<typeof getSplitStyles>\n\nconst skipProps = {\n animation: true,\n animateOnly: true,\n debug: true,\n componentName: true,\n}\n\n// native only skips\nif (process.env.TAMAGUI_TARGET === 'native') {\n Object.assign(skipProps, {\n tag: true,\n whiteSpace: true,\n wordWrap: true,\n textOverflow: true,\n textDecorationDistance: true,\n userSelect: true,\n selectable: true,\n cursor: true,\n contain: true,\n boxSizing: true,\n boxShadow: true,\n })\n}\n\ntype TransformNamespaceKey = 'transform' | PseudoPropKeys | MediaQueryKey\n\nlet conf: TamaguiInternalConfig\n\ntype StyleSplitter = (\n props: { [key: string]: any },\n staticConfig: StaticConfigParsed,\n theme: ThemeParsed,\n state: SplitStyleState,\n defaultClassNames?: any,\n languageContext?: LanguageContextType,\n debug?: DebugProp\n) => {\n pseudos: PseudoStyles\n medias: Record<MediaQueryKey, ViewStyle>\n style: ViewStyle\n classNames: ClassNamesObject\n rulesToInsert: RulesToInsert\n viewProps: StackProps\n fontFamily: string | undefined\n mediaKeys: string[]\n}\n\nexport const PROP_SPLIT = '-'\n\n// this is how compiler outputs psueodo identifier\n// TODO remove in next refactor\nexport const pseudoCNInverse = {\n hover: 'hoverStyle',\n focus: 'focusStyle',\n press: 'pressStyle',\n}\n\n// loop props backwards\n// track used keys:\n// const keys = new Set<string>()\n// keep classnames and styles separate:\n// const styles = {}\n// const classNames = {}\n\nexport const getSplitStyles: StyleSplitter = (\n props,\n staticConfig,\n theme,\n state,\n defaultClassNames,\n languageContext,\n debug\n) => {\n conf = conf || getConfig()\n const validStyleProps = staticConfig.isText ? stylePropsText : validStyles\n const mediaKeys: string[] = []\n const viewProps: StackProps = {}\n const pseudos: PseudoStyles = {}\n const medias: Record<MediaQueryKey, ViewStyle> = {}\n const mediaState = state.mediaState || globalMediaState\n const usedKeys = new Set<string>()\n const propKeys = Object.keys(props)\n const shouldDoClasses =\n staticConfig.acceptsClassName &&\n (isWeb || process.env.IS_STATIC === 'is_static') &&\n !state.noClassNames &&\n !props.animation\n const len = propKeys.length\n const rulesToInsert: RulesToInsert = []\n const style: ViewStyle = {}\n // TODO make this CSS, not compile-friendly\n if (state.hasTextAncestor) {\n // parity with react-native-web\n style.display = 'inline-flex' as any\n }\n const classNames: ClassNamesObject = {}\n // we need to gather these specific to each media query / pseudo\n // value is [hash, val], so [\"-jnjad-asdnjk\", \"scaleX(1) rotate(10deg)\"]\n const transforms: Record<TransformNamespaceKey, [string, string]> = {}\n // fontFamily is our special baby, ensure we grab the latest set one always\n let fontFamily: string | undefined\n\n // loop backwards so we can skip already-used props\n for (let i = len - 1; i >= 0; i--) {\n let keyInit = propKeys[i]\n const valInit = props[keyInit]\n\n // normalize shorthands up front\n const expandedKey = conf.shorthands[keyInit]\n if (expandedKey) {\n keyInit = expandedKey\n }\n\n if (usedKeys.has(keyInit)) continue\n if (skipProps[keyInit]) continue\n if (!isWeb && keyInit.startsWith('data-')) continue\n\n if (keyInit === 'style' || keyInit.startsWith('_style')) {\n if (!valInit) continue\n for (const key in valInit) {\n if (usedKeys.has(key)) continue\n if (valInit && typeof valInit === 'object') {\n // newer react native versions return a full object instead of ID\n for (const skey in valInit) {\n if (usedKeys.has(skey)) continue\n usedKeys.add(skey)\n style[skey] = valInit[skey]\n }\n } else {\n usedKeys.add(key)\n style[key] = valInit\n }\n }\n continue\n }\n\n if (process.env.TAMAGUI_TARGET === 'web') {\n if (keyInit === 'className') {\n let nonTamaguis = ''\n if (!valInit) continue\n for (const cn of valInit.split(' ')) {\n if (cn[0] === '_') {\n // tamagui, merge it expanded on key, eventually this will go away with better compiler\n const [shorthand, mediaOrPseudo] = cn.slice(1).split('-')\n const isMedia = mediaOrPseudo[0] === '_'\n const isPseudo = mediaOrPseudo[0] === '0'\n const isMediaOrPseudo = isMedia || isPseudo\n let fullKey = conf.shorthands[shorthand]\n if (isMedia) {\n // is media\n let mediaShortKey = mediaOrPseudo.slice(1)\n mediaShortKey = mediaShortKey.slice(0, mediaShortKey.indexOf('_'))\n fullKey += `${PROP_SPLIT}${mediaShortKey}`\n } else if (isPseudo) {\n // is pseudo\n const pseudoShortKey = mediaOrPseudo.slice(1)\n fullKey += `${PROP_SPLIT}${pseudoShortKey}`\n }\n usedKeys.add(fullKey)\n mergeClassName(transforms, classNames, fullKey, cn, isMediaOrPseudo)\n } else {\n nonTamaguis += ' ' + cn\n }\n }\n if (nonTamaguis) {\n usedKeys.add(keyInit)\n mergeClassName(transforms, classNames, keyInit, nonTamaguis)\n }\n continue\n }\n\n if (valInit && valInit[0] === '_') {\n // if valid style key (or pseudo like color-hover):\n // this conditional and esp the pseudo check rarely runs so not a perf issue\n const isValidClassName = validStyles[keyInit]\n const isMediaOrPseudo =\n !isValidClassName &&\n keyInit.includes(PROP_SPLIT) &&\n validStyles[keyInit.split(PROP_SPLIT)[0]]\n if (isValidClassName || isMediaOrPseudo) {\n usedKeys.add(keyInit)\n mergeClassName(transforms, classNames, keyInit, valInit, isMediaOrPseudo)\n continue\n }\n }\n }\n\n if (state.keepVariantsAsProps) {\n if (\n (staticConfig.defaultVariants && keyInit in staticConfig.defaultVariants) ||\n // may want to just: not compile styled() into classnames, always do this, and always pass in all values in extras.props\n // but we'd want to add styled({ extracted: true }) or something at compile time to save on parsing a bit...\n (staticConfig.variants && keyInit in staticConfig.variants)\n ) {\n viewProps[keyInit] = valInit\n }\n }\n\n /**\n * There's (some) reason to this madness: we want to allow returning media/pseudo from variants\n * Say you have a variant hoverable: { true: { hoverStyle: {} } }\n * We run propMapper first to expand variant, then we run the inner loop and look again\n * for if there's a pseudo/media returned from it.\n */\n\n let isMedia = keyInit[0] === '$'\n let isPseudo = validPseudoKeys[keyInit]\n let isMediaOrPseudo = isMedia || isPseudo\n\n if (\n !isMedia &&\n !isPseudo &&\n !staticConfig.variants?.[keyInit] &&\n !validStyleProps[keyInit] &&\n !conf.shorthands[keyInit]\n ) {\n usedKeys.add(keyInit)\n viewProps[keyInit] = valInit\n continue\n }\n\n if (process.env.NODE_ENV === 'development' && debug === 'verbose') {\n // eslint-disable-next-line no-console\n console.groupCollapsed(' \uD83D\uDD39 styles', keyInit, valInit)\n }\n\n const expanded =\n isMedia || isPseudo\n ? [[keyInit, valInit]]\n : staticConfig.propMapper(\n keyInit,\n valInit,\n theme,\n props,\n state,\n languageContext,\n undefined,\n debug\n )\n\n if (!fontFamily) {\n fontFamily = getPropMappedFontFamily(expanded)\n }\n\n if (process.env.NODE_ENV === 'development' && debug === 'verbose') {\n // eslint-disable-next-line no-console\n console.log('expanded', expanded)\n // eslint-disable-next-line no-console\n console.log('usedKeys', [...usedKeys])\n // eslint-disable-next-line no-console\n console.groupEnd()\n }\n\n if (!expanded) {\n continue\n }\n\n for (const [key, val] of expanded) {\n if (val === undefined) continue\n\n isMedia = key[0] === '$'\n isPseudo = validPseudoKeys[key]\n isMediaOrPseudo = isMedia || isPseudo\n\n if (!isMediaOrPseudo) {\n if (usedKeys.has(key)) continue\n }\n\n if (\n (staticConfig.deoptProps && staticConfig.deoptProps.has(key)) ||\n (staticConfig.inlineProps && staticConfig.inlineProps.has(key)) ||\n (staticConfig.inlineWhenUnflattened && staticConfig.inlineWhenUnflattened.has(key))\n ) {\n usedKeys.add(key)\n viewProps[key] = props[key] ?? val\n }\n\n // pseudo\n if (isPseudo) {\n if (!val) continue\n if (key === 'enterStyle' && state.mounted) {\n // once mounted we can ignore enterStyle\n continue\n }\n pseudos[key] = pseudos[key] || {}\n const pseudoStyleObject = getSubStyle(\n key,\n val,\n staticConfig,\n theme,\n props,\n state,\n conf,\n languageContext,\n true\n )\n\n pseudos[key] = {\n ...pseudoStyleObject,\n ...pseudos[key],\n }\n\n if (shouldDoClasses && key !== 'enterStyle' && key !== 'exitStyle') {\n const pseudoStyles = getAtomicStyle(pseudoStyleObject, pseudoDescriptors[key])\n for (const style of pseudoStyles) {\n const postfix = pseudoDescriptors[key]?.name || key // exitStyle/enterStyle dont have pseudoDescriptors\n const fullKey = `${style.property}${PROP_SPLIT}${postfix}`\n if (!usedKeys.has(fullKey)) {\n usedKeys.add(fullKey)\n addStyleToInsertRules(rulesToInsert, style)\n mergeClassName(transforms, classNames, fullKey, style.identifier, isMediaOrPseudo)\n }\n }\n }\n continue\n }\n\n // media\n if (isMedia) {\n const mediaKey = key\n const mediaKeyShort = mediaKey.slice(1)\n\n mediaKeys.push(mediaKeyShort)\n\n if (!mediaQueryConfig[mediaKeyShort]) {\n if (process.env.NODE_ENV === 'development' && debug) {\n // eslint-disable-next-line no-console\n console.warn(\n `Warning: using a $ prefixed prop that doesn't match to a media query, may be an error`,\n key\n )\n }\n if (!usedKeys.has(key)) {\n // this isn't a media key, pass through\n viewProps[key] = val\n }\n continue\n }\n\n // dont check if media is active, we just apply *all* media styles\n // we combine the media props on top regular props, could proxy this\n // TODO test proxy here instead of merge\n // THIS USED TO PROXY BACK TO REGULAR PROPS BUT THAT IS THE WRONG BEHAVIOR\n // we avoid passing in default props for media queries because that would confuse things like SizableText.size:\n const mediaStyle = getSubStyle(\n key,\n val,\n staticConfig,\n theme,\n props,\n state,\n conf,\n languageContext\n )\n\n if (process.env.NODE_ENV === 'development' && debug === 'verbose') {\n // prettier-ignore\n // eslint-disable-next-line no-console\n console.log(` \uD83D\uDCFA ${mediaKey}`, mediaState[mediaKeyShort], { mediaKey, mediaStyle, props, shouldDoClasses, mediaState: { ...mediaState } })\n }\n\n if (shouldDoClasses) {\n const mediaStyles = getStylesAtomic(mediaStyle)\n for (const style of mediaStyles) {\n const out = createMediaStyle(style, mediaKeyShort, mediaQueryConfig)\n const fullKey = `${style.property}${PROP_SPLIT}${mediaKeyShort}`\n if (!usedKeys.has(fullKey)) {\n usedKeys.add(fullKey)\n addStyleToInsertRules(rulesToInsert, out)\n mergeClassName(transforms, classNames, fullKey, out.identifier, true)\n }\n }\n } else {\n if (mediaState[mediaKeyShort]) {\n if (process.env.NODE_ENV === 'development' && debug) {\n // eslint-disable-next-line no-console\n console.log('apply media style', mediaKey, mediaState)\n }\n if (shouldDoClasses) {\n Object.assign(medias, mediaStyle)\n } else {\n for (const key in mediaStyle) {\n // TODO we should likely account for importance here to match CSS, right??\n usedKeys.add(key)\n style[key] = mediaStyle[key]\n if (key === 'fontFamily') {\n fontFamily = mediaStyle[key]\n }\n }\n }\n }\n }\n continue\n }\n\n if (!isWeb && key === 'pointerEvents') {\n usedKeys.add(key)\n viewProps[key] = val\n continue\n }\n\n if (key === 'fontFamily' && !fontFamily && valInit && val) {\n fontFamily = valInit[0] === '$' ? valInit : val\n }\n\n if (validStyleProps[key]) {\n usedKeys.add(key)\n if (val && val[0] === '_') {\n classNames[key] = val\n } else if (key in stylePropsTransform) {\n mergeTransform(style, key, val, true)\n } else {\n style[key] = normalizeValueWithProperty(val, key)\n }\n continue\n }\n\n // pass to view props\n if (!staticConfig.variants || !(key in staticConfig.variants)) {\n if (!skipProps[key]) {\n viewProps[key] = val\n usedKeys.add(key)\n }\n }\n }\n }\n\n fixStyles(style)\n if (isWeb) {\n styleToCSS(style)\n }\n\n // add in defaults if not set:\n if (defaultClassNames) {\n for (const key in defaultClassNames) {\n if (!(key in classNames)) {\n classNames[key] = defaultClassNames[key]\n }\n }\n }\n\n if (process.env.TAMAGUI_TARGET === 'web') {\n if (shouldDoClasses) {\n const atomic = getStylesAtomic(style)\n for (const atomicStyle of atomic) {\n const key = atomicStyle.property\n addStyleToInsertRules(rulesToInsert, atomicStyle)\n mergeClassName(transforms, classNames, key, atomicStyle.identifier)\n }\n }\n }\n\n // else {\n // if (classNames && state.resolveVariablesAs === 'value') {\n // getting real values for colors for animations (reverse mapped from CSS)\n // this isn't beautiful, but will do relatively fine performance for now\n // has a bug still - try adding <Switch theme=\"bouncy\" /> should animate bg color on active\n // const selectors = getAllSelectors()\n // for (const key in classNames) {\n // if (key.endsWith('Color')) {\n // const selector = classNames[key]\n // let value = selectorValuesCache[selector]\n // if (!value) {\n // const css = selectors[selector]\n // value = css.replace(/.*:/, '').replace(/;.*/, '')\n // if (value) {\n // const themeUnwrapped = getThemeUnwrapped(theme)\n // const map = themeToVariableToValueMap.get(themeUnwrapped)\n // if (map && value.startsWith('var(')) {\n // value = map[value]\n // }\n // if (value) {\n // selectorValuesCache[selector] = value\n // }\n // } else {\n // // err\n // continue\n // }\n // }\n // if (value) {\n // style[key] = value\n // }\n // }\n // }\n // }\n // }\n\n if (process.env.TAMAGUI_TARGET === 'web') {\n if (transforms) {\n for (const namespace in transforms) {\n if (!transforms[namespace]) {\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn('Error no transform', transforms, namespace)\n }\n continue\n }\n const [hash, val] = transforms[namespace]\n const identifier = `_transform${hash}`\n if (isClient) {\n if (!insertedTransforms[identifier]) {\n const rule = `.${identifier} { transform: ${val}; }`\n addStyleToInsertRules(rulesToInsert, {\n identifier,\n rules: [rule],\n property: namespace,\n })\n }\n }\n classNames[namespace] = identifier\n }\n }\n }\n\n if (process.env.NODE_ENV === 'development' && debug === 'verbose') {\n if (isDevTools) {\n // prettier-ignore\n // eslint-disable-next-line no-console\n console.groupCollapsed(' \uD83D\uDD39 styles =>')\n const logs = { style, pseudos, medias, classNames, viewProps, state, rulesToInsert }\n for (const key in logs) {\n // eslint-disable-next-line no-console\n console.log(key, logs[key])\n }\n // eslint-disable-next-line no-console\n console.groupEnd()\n }\n }\n\n return {\n fontFamily,\n viewProps,\n style,\n medias,\n mediaKeys,\n pseudos,\n classNames,\n rulesToInsert,\n }\n}\n\nfunction mergeClassName(\n transforms: Record<string, any[]>,\n classNames: Record<string, string>,\n key: string,\n val: string,\n isMediaOrPseudo = false\n) {\n if (process.env.TAMAGUI_TARGET === 'web') {\n // empty classnames passed by compiler sometimes\n if (!val) return\n if (val.startsWith('_transform-')) {\n const namespace: TransformNamespaceKey = isMediaOrPseudo ? key : 'transform'\n let transform = insertedTransforms[val]\n if (isClient) {\n if (!transform) {\n // HMR or loaded a new chunk\n updateInserted()\n transform = insertedTransforms[val]\n if (process.env.NODE_ENV === 'development') {\n if (!transform) {\n // eslint-disable-next-line no-console\n console.warn('no transform found', { insertedTransforms, val })\n }\n }\n }\n if (!transform) {\n if (isWeb && val[0] !== '_') {\n // runtime insert\n transform = val\n }\n }\n }\n transforms[namespace] = transforms[namespace] || ['', '']\n const identifier = val.replace('_transform', '')\n transforms[namespace][0] += identifier\n // ssr doesn't need to do anything just make the right classname\n if (transform) {\n transforms[namespace][1] += transform\n }\n } else {\n classNames[key] = val\n }\n }\n}\n\n/**\n * getSubStyle calls propMapper with props\n * those should be specific to the substyle, but fallback to the base props\n * so given props:\n *\n * { fontSize: 12, color: 'red', $sm: { color: 'blue' } }\n *\n * getSubStyle props should be a proxy that ends up like:\n *\n * { fontSize: 12, color: 'blue' }\n *\n * and to avoid re-creating it over and over, use a WeakMap\n */\nconst propProxies = new WeakMap()\nfunction getSubStyleProxiedProps(defaultProps: Object, baseProps: Object, specificProps: Object) {\n if (!specificProps) {\n // functional variants may want to eventually do something like:\n // have a hooks-like rule (no conditionals)\n // then we run them once on compile with a proxy to capture the keys accessed\n // then add those keys to `inlineProps` so we know we must inline them\n // for now this will trigger because compiled away\n // right now also we don't pass in any pre-extracted styled() props but we should pass them in..\n return baseProps\n }\n // can cache based only on specific it's always referentially consistent with base\n if (propProxies.has(specificProps)) {\n return propProxies.get(specificProps)\n }\n const next = createProxy(specificProps, {\n has(_, key) {\n return key in defaultProps || key in specificProps || key in baseProps\n },\n get(_, key) {\n return defaultProps[key] ?? specificProps[key] ?? baseProps[key]\n },\n })\n propProxies.set(specificProps, next)\n return next\n}\n\nexport const getSubStyle = (\n subKey: string,\n styleIn: Object,\n staticConfig: StaticConfigParsed,\n theme: ThemeParsed,\n props: any,\n state: SplitStyleState,\n conf: TamaguiInternalConfig,\n languageContext?: FontLanguageProps,\n avoidDefaultProps?: boolean\n): ViewStyle => {\n const styleOut: ViewStyle = {}\n for (let key in styleIn) {\n const val = styleIn[key]\n key = conf.shorthands[key] || key\n const expanded = staticConfig.propMapper(\n key,\n val,\n theme,\n getSubStyleProxiedProps(staticConfig.defaultProps, props, props[subKey]),\n state,\n languageContext,\n avoidDefaultProps\n )\n if (!expanded) continue\n for (const [skey, sval] of expanded) {\n if (skey in stylePropsTransform) {\n mergeTransform(styleOut, skey, sval)\n } else {\n styleOut[skey] = normalizeValueWithProperty(sval, key)\n }\n }\n }\n\n fixStyles(styleOut)\n\n return styleOut\n}\n\nexport const insertSplitStyles: StyleSplitter = (...args) => {\n const res = getSplitStyles(...args)\n insertStyleRules(res.rulesToInsert)\n return res\n}\n\n// on native no need to insert any css\nconst useInsertEffectCompat = isWeb ? useInsertionEffect || useIsomorphicLayoutEffect : () => {}\n\nexport const useSplitStyles: StyleSplitter = (...args) => {\n const res = getSplitStyles(...args)\n\n if (!isRSC) {\n useInsertEffectCompat(() => {\n insertStyleRules(res.rulesToInsert)\n }, [res.rulesToInsert])\n }\n\n return res\n}\n\nfunction addStyleToInsertRules(rulesToInsert: RulesToInsert, styleObject: PartialStyleObject) {\n if (process.env.TAMAGUI_TARGET === 'web') {\n if (!shouldInsertStyleRules(styleObject)) {\n return\n }\n updateRules(styleObject.identifier, styleObject.rules)\n rulesToInsert.push(styleObject)\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,OAAO,OAAO,iCAAiC;AAClE,SAAS,gBAAgB,qBAAqB,iBAAiB,mBAAmB;AAClF,SAAS,0BAA0B;AAGnC,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,cAAc,kBAAkB,wBAAwB;AAajE,SAAS,wBAAwB;AACjC,SAAS,+BAA+B;AACxC,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB,iBAAiB,kBAAkB;AAC5D;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,sBAAsB;AAC/B,SAAS,kCAAkC;AAC3C,SAAS,yBAAyB;AAMlC,MAAM,YAAY;AAAA,EAChB,WAAW;AAAA,EACX,aAAa;AAAA,EACb,OAAO;AAAA,EACP,eAAe;AACjB;AAGA,IAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,SAAO,OAAO,WAAW;AAAA,IACvB,KAAK;AAAA,IACL,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,cAAc;AAAA,IACd,wBAAwB;AAAA,IACxB,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,WAAW;AAAA,IACX,WAAW;AAAA,EACb,CAAC;AACH;AAIA,IAAI;AAqBG,MAAM,aAAa;AAInB,MAAM,kBAAkB;AAAA,EAC7B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACT;AASO,MAAM,iBAAgC,CAC3C,OACA,cACA,OACA,OACA,mBACA,iBACA,UACG;AAnHL;AAoHE,SAAO,QAAQ,UAAU;AACzB,QAA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ClC,SAAO;AACT;AAGA,MAAM,wBAAwB,QAAQ,sBAAsB,4BAA4B,MAAM;AAAC;AAExF,MAAM,iBAAgC,IAAI,SAAS;AACxD,QAAM,MAAM,eAAe,GAAG,IAAI;AAElC,MAAI,CAAC,OAAO;AACV,0BAAsB,MAAM;AAC1B,uBAAiB,IAAI,aAAa;AAAA,IACpC,GAAG,CAAC,IAAI,aAAa,CAAC;AAAA,EACxB;AAEA,SAAO;AACT;AAEA,SAAS,sBAAsB,eAA8B,aAAiC;AAC5F,MAAI,QAAQ,IAAI,mBAAmB,OAAO;AACxC,QAAI,CAAC,uBAAuB,WAAW,GAAG;AACxC;AAAA,IACF;AACA,gBAAY,YAAY,YAAY,YAAY,KAAK;AACrD,kBAAc,KAAK,WAAW;AAAA,EAChC;AACF;",
|
|
6
6
|
"names": ["isMedia", "isPseudo", "isMediaOrPseudo", "style", "key", "conf"]
|
|
7
7
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getConfig } from "../config";
|
|
2
|
+
import { createProxy } from "./createProxy";
|
|
2
3
|
const extrasCache = /* @__PURE__ */ new WeakMap();
|
|
3
4
|
function getVariantExtras(props, languageContext, theme, defaultProps, avoidDefaultProps = false) {
|
|
4
5
|
const conf = getConfig();
|
|
@@ -13,7 +14,7 @@ function getVariantExtras(props, languageContext, theme, defaultProps, avoidDefa
|
|
|
13
14
|
fonts,
|
|
14
15
|
tokens: conf.tokensParsed,
|
|
15
16
|
theme,
|
|
16
|
-
props: avoidDefaultProps ? props :
|
|
17
|
+
props: avoidDefaultProps ? props : createProxy(props, {
|
|
17
18
|
get(target, key) {
|
|
18
19
|
const shorthand = conf.inverseShorthands[key];
|
|
19
20
|
if (shorthand && Reflect.has(target, shorthand)) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/getVariantExtras.tsx"],
|
|
4
|
-
"sourcesContent": ["import { getConfig } from '../config'\nimport { GenericFonts } from '../types'\nimport { LanguageContextType } from '../views/FontLanguage.types'\n\nconst extrasCache = new WeakMap()\n\nexport function getVariantExtras(\n props: any,\n languageContext?: LanguageContextType,\n theme?: any,\n defaultProps?: any,\n avoidDefaultProps = false\n) {\n const conf = getConfig()\n\n if (extrasCache.has(props)) {\n return extrasCache.get(props)\n }\n\n let fonts = conf.fontsParsed\n if (languageContext) {\n fonts = getFontsForLanguage(conf.fontsParsed, languageContext)\n }\n\n const next = {\n fonts,\n tokens: conf.tokensParsed,\n theme,\n // TODO do this in splitstlye\n // we avoid passing in default props for media queries because that would confuse things like SizableText.size:\n props: avoidDefaultProps\n ? props\n :
|
|
5
|
-
"mappings": "AAAA,SAAS,iBAAiB;
|
|
4
|
+
"sourcesContent": ["import { getConfig } from '../config'\nimport { GenericFonts } from '../types'\nimport { LanguageContextType } from '../views/FontLanguage.types'\nimport { createProxy } from './createProxy'\n\nconst extrasCache = new WeakMap()\n\nexport function getVariantExtras(\n props: any,\n languageContext?: LanguageContextType,\n theme?: any,\n defaultProps?: any,\n avoidDefaultProps = false\n) {\n const conf = getConfig()\n\n if (extrasCache.has(props)) {\n return extrasCache.get(props)\n }\n\n let fonts = conf.fontsParsed\n if (languageContext) {\n fonts = getFontsForLanguage(conf.fontsParsed, languageContext)\n }\n\n const next = {\n fonts,\n tokens: conf.tokensParsed,\n theme,\n // TODO do this in splitstlye\n // we avoid passing in default props for media queries because that would confuse things like SizableText.size:\n props: avoidDefaultProps\n ? props\n : createProxy(props, {\n // handles shorthands\n get(target, key) {\n const shorthand = conf.inverseShorthands[key as any]\n // shorthands before longhand because a styled() with longhand combined with inline shorthand\n // shorthand will always be the overriding key\n if (shorthand && Reflect.has(target, shorthand)) {\n return Reflect.get(target, shorthand)\n }\n if (Reflect.has(target, key)) {\n return Reflect.get(target, key)\n }\n // these props may be extracted into classNames, but we still want to access them\n // at runtime, so we proxy back to defaultProps but don't pass them\n if (defaultProps) {\n if (shorthand && Reflect.has(defaultProps, shorthand)) {\n return Reflect.get(defaultProps, shorthand)\n }\n if (Reflect.has(defaultProps, key)) {\n return Reflect.get(defaultProps, key)\n }\n }\n },\n }),\n }\n\n extrasCache.set(props, next)\n\n return next\n}\n\nconst fontLanguageCache = new WeakMap()\n\nexport function getFontsForLanguage(fonts: GenericFonts, language: LanguageContextType) {\n if (fontLanguageCache.has(language)) {\n return fontLanguageCache.get(language)\n }\n const next = {\n ...fonts,\n ...Object.fromEntries(\n Object.entries(language).map(([name, lang]) => {\n if (lang === 'default') {\n return []\n }\n const langKey = `$${name}_${lang}`\n return [`$${name}`, fonts[langKey]]\n })\n ),\n }\n fontLanguageCache.set(language, next)\n return next\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAG1B,SAAS,mBAAmB;AAE5B,MAAM,cAAc,oBAAI,QAAQ;AAEzB,SAAS,iBACd,OACA,iBACA,OACA,cACA,oBAAoB,OACpB;AACA,QAAM,OAAO,UAAU;AAEvB,MAAI,YAAY,IAAI,KAAK,GAAG;AAC1B,WAAO,YAAY,IAAI,KAAK;AAAA,EAC9B;AAEA,MAAI,QAAQ,KAAK;AACjB,MAAI,iBAAiB;AACnB,YAAQ,oBAAoB,KAAK,aAAa,eAAe;AAAA,EAC/D;AAEA,QAAM,OAAO;AAAA,IACX;AAAA,IACA,QAAQ,KAAK;AAAA,IACb;AAAA,IAGA,OAAO,oBACH,QACA,YAAY,OAAO;AAAA,MAEjB,IAAI,QAAQ,KAAK;AACf,cAAM,YAAY,KAAK,kBAAkB;AAGzC,YAAI,aAAa,QAAQ,IAAI,QAAQ,SAAS,GAAG;AAC/C,iBAAO,QAAQ,IAAI,QAAQ,SAAS;AAAA,QACtC;AACA,YAAI,QAAQ,IAAI,QAAQ,GAAG,GAAG;AAC5B,iBAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,QAChC;AAGA,YAAI,cAAc;AAChB,cAAI,aAAa,QAAQ,IAAI,cAAc,SAAS,GAAG;AACrD,mBAAO,QAAQ,IAAI,cAAc,SAAS;AAAA,UAC5C;AACA,cAAI,QAAQ,IAAI,cAAc,GAAG,GAAG;AAClC,mBAAO,QAAQ,IAAI,cAAc,GAAG;AAAA,UACtC;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACP;AAEA,cAAY,IAAI,OAAO,IAAI;AAE3B,SAAO;AACT;AAEA,MAAM,oBAAoB,oBAAI,QAAQ;AAE/B,SAAS,oBAAoB,OAAqB,UAA+B;AACtF,MAAI,kBAAkB,IAAI,QAAQ,GAAG;AACnC,WAAO,kBAAkB,IAAI,QAAQ;AAAA,EACvC;AACA,QAAM,OAAO;AAAA,IACX,GAAG;AAAA,IACH,GAAG,OAAO;AAAA,MACR,OAAO,QAAQ,QAAQ,EAAE,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM;AAC7C,YAAI,SAAS,WAAW;AACtB,iBAAO,CAAC;AAAA,QACV;AACA,cAAM,UAAU,IAAI,QAAQ;AAC5B,eAAO,CAAC,IAAI,QAAQ,MAAM,QAAQ;AAAA,MACpC,CAAC;AAAA,IACH;AAAA,EACF;AACA,oBAAkB,IAAI,UAAU,IAAI;AACpC,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
+
import { createProxy } from "./createProxy";
|
|
1
2
|
function proxyThemeVariables(obj) {
|
|
2
|
-
|
|
3
|
-
console.trace(`empty value for proxyThemeVariables`, obj);
|
|
4
|
-
return obj;
|
|
5
|
-
}
|
|
6
|
-
return new Proxy(obj || {}, {
|
|
3
|
+
return createProxy(obj || {}, {
|
|
7
4
|
has(target, key) {
|
|
8
5
|
return Reflect.has(target, removeStarting$(key));
|
|
9
6
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/proxyThemeVariables.tsx"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { createProxy } from './createProxy'\n\nexport function proxyThemeVariables<A extends Object>(obj: A): A {\n return createProxy<A>(obj || {}, {\n has(target, key) {\n return Reflect.has(target, removeStarting$(key))\n },\n get(target, key) {\n return Reflect.get(target, removeStarting$(key))\n },\n })\n}\n\nconst removeStarting$ = (str: string | symbol) =>\n typeof str === 'string' && str[0] === '$' ? str.slice(1) : str\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,mBAAmB;AAErB,SAAS,oBAAsC,KAAW;AAC/D,SAAO,YAAe,OAAO,CAAC,GAAG;AAAA,IAC/B,IAAI,QAAQ,KAAK;AACf,aAAO,QAAQ,IAAI,QAAQ,gBAAgB,GAAG,CAAC;AAAA,IACjD;AAAA,IACA,IAAI,QAAQ,KAAK;AACf,aAAO,QAAQ,IAAI,QAAQ,gBAAgB,GAAG,CAAC;AAAA,IACjD;AAAA,EACF,CAAC;AACH;AAEA,MAAM,kBAAkB,CAAC,QACvB,OAAO,QAAQ,YAAY,IAAI,OAAO,MAAM,IAAI,MAAM,CAAC,IAAI;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
2
|
import { startTransition, useEffect, useMemo, useState } from "react";
|
|
3
3
|
import { getConfig } from "../config";
|
|
4
|
+
import { createProxy } from "../helpers/createProxy";
|
|
4
5
|
import { matchMedia } from "../helpers/matchMedia";
|
|
5
6
|
import { useSafeRef } from "./useSafeRef";
|
|
6
|
-
const mediaState = process.env.NODE_ENV === "development" ?
|
|
7
|
+
const mediaState = process.env.NODE_ENV === "development" ? createProxy(
|
|
7
8
|
{},
|
|
8
9
|
{
|
|
9
10
|
get(target, key) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useMedia.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { startTransition, useEffect, useMemo, useState } from 'react'\n\nimport { getConfig } from '../config'\nimport { matchMedia } from '../helpers/matchMedia'\nimport {\n MediaQueries,\n MediaQueryKey,\n MediaQueryObject,\n MediaQueryState,\n TamaguiInternalConfig,\n} from '../types'\nimport { useSafeRef } from './useSafeRef'\n\nexport const mediaState: MediaQueryState =\n // development time safeguard\n process.env.NODE_ENV === 'development'\n ?
|
|
5
|
-
"mappings": "AAAA,SAAS,iCAAiC;AAC1C,SAAS,iBAAiB,WAAW,SAAS,gBAAgB;AAE9D,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAQ3B,SAAS,kBAAkB;AAEpB,MAAM,aAEX,QAAQ,IAAI,aAAa,gBACrB
|
|
4
|
+
"sourcesContent": ["import { useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { startTransition, useEffect, useMemo, useState } from 'react'\n\nimport { getConfig } from '../config'\nimport { createProxy } from '../helpers/createProxy'\nimport { matchMedia } from '../helpers/matchMedia'\nimport {\n MediaQueries,\n MediaQueryKey,\n MediaQueryObject,\n MediaQueryState,\n TamaguiInternalConfig,\n} from '../types'\nimport { useSafeRef } from './useSafeRef'\n\nexport const mediaState: MediaQueryState =\n // development time safeguard\n process.env.NODE_ENV === 'development'\n ? createProxy(\n {},\n {\n get(target, key) {\n if (typeof key === 'string' && key[0] === '$') {\n throw new Error(`Access of mediaState should never include $`)\n }\n return Reflect.get(target, key)\n },\n }\n )\n : ({} as any)\n\ntype MediaListener = (next: boolean) => void\n\nconst mediaQueryListeners: { [key: string]: Set<MediaListener> } = {}\n\nexport function addMediaQueryListener(key: MediaQueryKey, cb: MediaListener) {\n if (process.env.NODE_ENV === 'development' && key[0] === '$') {\n // eslint-disable-next-line no-console\n console.warn(`Warning, listening to media queries shouldn't use the \"$\" prefix`)\n }\n mediaQueryListeners[key] = mediaQueryListeners[key] || new Set()\n mediaQueryListeners[key].add(cb)\n return () => removeMediaQueryListener(key, cb)\n}\n\nexport function removeMediaQueryListener(key: MediaQueryKey, cb: MediaListener) {\n mediaQueryListeners[key]?.delete(cb)\n}\n\nexport const mediaQueryConfig: MediaQueries = {}\n\nexport const getMedia = () => {\n return mediaState\n}\n\n// for SSR capture it at time of startup\nlet currentMediaState: MediaQueryState | null\nlet initialMediaState: MediaQueryState | null\n\nexport const getInitialMediaState = () => {\n if (getConfig().disableSSR) {\n return currentMediaState || {}\n }\n return initialMediaState || {}\n}\n\nconst dispose = new Set<Function>()\n\nexport const configureMedia = (config: TamaguiInternalConfig) => {\n const { media, mediaQueryDefaultActive } = config\n if (!media) return\n for (const key in media) {\n mediaState[key] = mediaQueryDefaultActive?.[key] || false\n }\n Object.assign(mediaQueryConfig, media)\n currentMediaState = { ...mediaState }\n initialMediaState = currentMediaState\n if (config.disableSSR) {\n setupMediaListeners()\n }\n}\n\nfunction unlisten() {\n dispose.forEach((cb) => cb())\n dispose.clear()\n}\n\n/**\n * Note: This should *not* set the state on the first render!\n * Because to avoid hydration issues SSR must match the server\n * *and then* re-render with the actual media query state.\n */\nlet configuredKey = ''\nfunction setupMediaListeners() {\n // avoid setting up more than once per config\n const nextKey = JSON.stringify(mediaQueryConfig)\n if (nextKey === configuredKey) {\n return\n }\n configuredKey = nextKey\n\n // hmr, undo existing before re-binding\n unlisten()\n\n // theoretically this should make media reactions smoother but potentially delayed?\n // but i believe consistent, so that's a nicer default (we'll see)\n startTransition(() => {\n for (const key in mediaQueryConfig) {\n const str = mediaObjectToString(mediaQueryConfig[key])\n const getMatch = () => matchMedia(str)\n const match = getMatch()\n if (!match) {\n throw new Error('\u26A0\uFE0F No match')\n }\n // react native needs these deprecated apis for now\n match.addListener(update)\n dispose.add(() => match.removeListener(update))\n\n update()\n\n function update() {\n const next = !!getMatch().matches\n if (next === mediaState[key]) return\n mediaState[key] = next\n currentMediaState = { ...mediaState }\n const listeners = mediaQueryListeners[key]\n if (listeners?.size) {\n listeners.forEach((cb) => cb(next))\n }\n }\n }\n })\n}\n\nexport function useMediaQueryListeners(config: TamaguiInternalConfig) {\n if (config.disableSSR) {\n return\n }\n useEffect(() => {\n setupMediaListeners()\n return unlisten\n }, [])\n}\n\nexport function useMedia(): {\n [key in MediaQueryKey]: boolean\n} {\n const [state, setState] = useState<MediaQueryState>(initialMediaState || {})\n const keys = useSafeRef({} as Record<string, boolean>)\n\n function updateState() {\n setState((prev) => {\n for (const key in keys.current) {\n if (prev[key] !== mediaState[key]) {\n return { ...mediaState }\n }\n }\n return prev\n })\n }\n\n useIsomorphicLayoutEffect(() => {\n const disposes: Function[] = Object.keys(keys.current).map((key) =>\n addMediaQueryListener(key, updateState)\n )\n updateState()\n return () => {\n disposes.forEach((cb) => cb())\n }\n })\n\n return useMemo(\n () =>\n new Proxy(state, {\n get(_, key: string) {\n if (process.env.NODE_ENV === 'development') {\n if (!currentMediaState) {\n throw new Error(\n `To use useMedia() you must pass in media configuration to createTamagui, none was found.`\n )\n }\n }\n if (!keys.current[key]) {\n keys.current[key] = true\n }\n return Reflect.get(state, key)\n },\n }),\n [state, keys]\n )\n}\n\n/**\n * Useful for more complex components that need access to the currently active props,\n * accounting for the currently active media queries.\n *\n * Use sparingly, is will loop props and trigger re-render on all media queries.\n *\n * */\nexport function useMediaPropsActive<A extends Object>(\n props: A\n): {\n // remove all media\n [Key in keyof A extends `$${string}` ? never : keyof A]?: A[Key]\n} {\n const media = useMedia()\n\n return useMemo(() => {\n const evaluated = {} as A\n const lastSetImportanceForKey = {}\n const propNames = Object.keys(props)\n const mediaKeysOrdered = Object.keys(getMedia())\n\n function update(k: string, v: any, importance = 0) {\n if (lastSetImportanceForKey[k] > importance) {\n return\n }\n lastSetImportanceForKey[k] = importance\n evaluated[k] = v\n }\n\n for (let i = propNames.length - 1; i >= 0; i--) {\n const key = propNames[i]\n const val = props[key]\n if (key[0] === '$') {\n const shortKey = key.slice(1)\n if (!media[shortKey]) {\n continue\n }\n if (val && typeof val === 'object') {\n const subPropNames = Object.keys(val)\n const mediaImportance = mediaKeysOrdered.indexOf(shortKey)\n for (let j = subPropNames.length; j--; j >= 0) {\n const skey = subPropNames[j]\n update(skey, val[skey], mediaImportance)\n }\n }\n } else {\n update(key, val)\n }\n }\n\n return evaluated\n }, [media, props])\n}\n\nfunction camelToHyphen(str: string) {\n return str.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`).toLowerCase()\n}\n\nexport function mediaObjectToString(query: string | MediaQueryObject) {\n if (typeof query === 'string') {\n return query\n }\n return Object.entries(query)\n .map(([feature, value]) => {\n feature = camelToHyphen(feature)\n if (typeof value === 'string') {\n return `(${feature}: ${value})`\n }\n if (typeof value === 'number' && /[height|width]$/.test(feature)) {\n value = `${value}px`\n }\n return `(${feature}: ${value})`\n })\n .join(' and ')\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iCAAiC;AAC1C,SAAS,iBAAiB,WAAW,SAAS,gBAAgB;AAE9D,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAQ3B,SAAS,kBAAkB;AAEpB,MAAM,aAEX,QAAQ,IAAI,aAAa,gBACrB;AAAA,EACE,CAAC;AAAA,EACD;AAAA,IACE,IAAI,QAAQ,KAAK;AACf,UAAI,OAAO,QAAQ,YAAY,IAAI,OAAO,KAAK;AAC7C,cAAM,IAAI,MAAM,6CAA6C;AAAA,MAC/D;AACA,aAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,IAChC;AAAA,EACF;AACF,IACC,CAAC;AAIR,MAAM,sBAA6D,CAAC;AAE7D,SAAS,sBAAsB,KAAoB,IAAmB;AAC3E,MAAI,QAAQ,IAAI,aAAa,iBAAiB,IAAI,OAAO,KAAK;AAE5D,YAAQ,KAAK,kEAAkE;AAAA,EACjF;AACA,sBAAoB,OAAO,oBAAoB,QAAQ,oBAAI,IAAI;AAC/D,sBAAoB,KAAK,IAAI,EAAE;AAC/B,SAAO,MAAM,yBAAyB,KAAK,EAAE;AAC/C;AAEO,SAAS,yBAAyB,KAAoB,I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AAO;AAAA,EACT;AACA,SAAO,OAAO,QAAQ,KAAK,EACxB,IAAI,CAAC,CAAC,SAAS,KAAK,MAAM;AACzB,cAAU,cAAc,OAAO;AAC/B,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO,IAAI,YAAY;AAAA,IACzB;AACA,QAAI,OAAO,UAAU,YAAY,kBAAkB,KAAK,OAAO,GAAG;AAChE,cAAQ,GAAG;AAAA,IACb;AACA,WAAO,IAAI,YAAY;AAAA,EACzB,CAAC,EACA,KAAK,OAAO;AACjB;",
|
|
6
6
|
"names": ["update"]
|
|
7
7
|
}
|
|
@@ -5,6 +5,7 @@ import { getConfig } from "../config";
|
|
|
5
5
|
import { isDevTools } from "../constants/isDevTools";
|
|
6
6
|
import { ThemeContext } from "../contexts/ThemeContext";
|
|
7
7
|
import { areEqualSets } from "../helpers/areEqualSets";
|
|
8
|
+
import { createProxy } from "../helpers/createProxy";
|
|
8
9
|
import {
|
|
9
10
|
ThemeManager,
|
|
10
11
|
ThemeManagerContext,
|
|
@@ -64,7 +65,7 @@ const useTheme = (themeName, componentName, props, forceUpdate) => {
|
|
|
64
65
|
}, [theme, name, className, themeManager, state, debugProp]);
|
|
65
66
|
};
|
|
66
67
|
function getThemeProxied(theme, name, className, themeManager, state, debugProp) {
|
|
67
|
-
return
|
|
68
|
+
return createProxy(theme, {
|
|
68
69
|
has(_, key) {
|
|
69
70
|
if (typeof key === "string" && key[0] === "$") {
|
|
70
71
|
key = key.slice(1);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useTheme.tsx"],
|
|
4
|
-
"sourcesContent": ["import { isRSC, isServer, useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { useForceUpdate } from '@tamagui/use-force-update'\nimport React, { useContext, useLayoutEffect, useMemo, useRef, useState } from 'react'\n\nimport { getConfig } from '../config'\nimport { isDevTools } from '../constants/isDevTools'\nimport { ThemeContext } from '../contexts/ThemeContext'\nimport { areEqualSets } from '../helpers/areEqualSets'\nimport {\n GetNextThemeProps,\n ThemeManager,\n ThemeManagerContext,\n emptyManager,\n} from '../helpers/ThemeManager'\nimport { ThemeName, ThemeParsed } from '../types'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped'\nimport { useConstant } from './useConstant'\nimport { useServerRef } from './useServerHooks'\n\nexport interface ThemeProps {\n className?: string\n disableThemeClass?: boolean\n name: Exclude<ThemeName, number> | null\n componentName?: string\n children?: any\n reset?: boolean\n debug?: boolean | 'verbose'\n}\n\ninterface UseThemeState {\n uuid: Object\n keys: Set<string>\n isRendering: boolean\n}\n\nexport const useTheme = (\n themeName?: string | null,\n componentName?: string,\n props?: ThemeProps,\n forceUpdate?: any\n): ThemeParsed => {\n // TODO this can use useChangeThemeEffect almost ready\n if (isRSC) {\n const config = getConfig()\n // @ts-ignore\n return getThemeProxied(config.themes[config.defaultTheme], config.defaultTheme)\n }\n\n const state = useServerRef() as React.MutableRefObject<UseThemeState>\n if (!state.current) {\n state.current = {\n uuid: {},\n keys: new Set(),\n isRendering: true,\n }\n }\n\n const { name, theme, themes, themeManager, className } = useChangeThemeEffect(\n themeName,\n componentName,\n props,\n forceUpdate,\n state.current.uuid\n )\n\n if (process.env.NODE_ENV === 'development') {\n if (props?.debug === 'verbose') {\n // eslint-disable-next-line no-console\n console.groupCollapsed(' \uD83D\uDD39 useTheme =>', name)\n const logs = { themeName, componentName, name, className, ...(isDevTools && { theme }) }\n for (const key in logs) {\n // eslint-disable-next-line no-console\n console.log(' ', key, logs[key])\n }\n // eslint-disable-next-line no-console\n console.groupEnd()\n }\n }\n\n // track usage\n state.current.isRendering = true\n useIsomorphicLayoutEffect(() => {\n const st = state.current\n st.isRendering = false\n const cur = themeManager?.keys.get(st.uuid)\n if (!cur || !areEqualSets(st.keys, cur)) {\n themeManager?.track(st.uuid, st.keys)\n }\n })\n\n const debugProp = props && props['debug']\n\n if (!theme) {\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn('No theme with name', themeName)\n }\n return themes[getConfig().defaultTheme || 'light']\n }\n\n return useMemo(() => {\n return getThemeProxied(theme, name, className, themeManager, state, debugProp)\n }, [theme, name, className, themeManager, state, debugProp])\n}\n\nfunction getThemeProxied(\n theme: any,\n name: string,\n className?: string,\n themeManager?: ThemeManager | null,\n state?: React.MutableRefObject<UseThemeState>,\n debugProp?: boolean | 'verbose'\n) {\n return
|
|
5
|
-
"mappings": "AAAA,SAAS,OAAO,UAAU,iCAAiC;AAC3D,SAAS,sBAAsB;AAC/B,SAAgB,YAAY,iBAAiB,SAAiB,gBAAgB;AAE9E,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAkBtB,MAAM,WAAW,CACtB,WACA,eACA,OACA,gBACgB;AAEhB,MAAI,OAAO;AACT,UAAM,SAAS,UAAU;AAEzB,WAAO,gBAAgB,OAAO,OAAO,OAAO,eAAe,OAAO,YAAY;AAAA,EAChF;AAEA,QAAM,QAAQ,aAAa;AAC3B,MAAI,CAAC,MAAM,SAAS;AAClB,UAAM,UAAU;AAAA,MACd,MAAM,CAAC;AAAA,MACP,MAAM,oBAAI,IAAI;AAAA,MACd,aAAa;AAAA,IACf;AAAA,EACF;AAEA,QAAM,EAAE,MAAM,OAAO,QAAQ,cAAc,UAAU,IAAI;AAAA,IACvD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,QAAQ;AAAA,EAChB;AAEA,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,SAAI,+BAAO,WAAU,WAAW;AAE9B,cAAQ,eAAe,2BAAoB,IAAI;AAC/C,YAAM,OAAO,EAAE,WAAW,eAAe,MAAM,WAAW,GAAI,cAAc,EAAE,MAAM,EAAG;AACvF,iBAAW,OAAO,MAAM;AAEtB,gBAAQ,IAAI,MAAM,KAAK,KAAK,IAAI;AAAA,MAClC;AAEA,cAAQ,SAAS;AAAA,IACnB;AAAA,EACF;AAGA,QAAM,QAAQ,cAAc;AAC5B,4BAA0B,MAAM;AAC9B,UAAM,KAAK,MAAM;AACjB,OAAG,cAAc;AACjB,UAAM,MAAM,6CAAc,KAAK,IAAI,GAAG;AACtC,QAAI,CAAC,OAAO,CAAC,aAAa,GAAG,MAAM,GAAG,GAAG;AACvC,mDAAc,MAAM,GAAG,MAAM,GAAG;AAAA,IAClC;AAAA,EACF,CAAC;AAED,QAAM,YAAY,SAAS,MAAM;AAEjC,MAAI,CAAC,OAAO;AACV,QAAI,QAAQ,IAAI,aAAa,eAAe;AAE1C,cAAQ,KAAK,sBAAsB,SAAS;AAAA,IAC9C;AACA,WAAO,OAAO,UAAU,EAAE,gBAAgB;AAAA,EAC5C;AAEA,SAAO,QAAQ,MAAM;AACnB,WAAO,gBAAgB,OAAO,MAAM,WAAW,cAAc,OAAO,SAAS;AAAA,EAC/E,GAAG,CAAC,OAAO,MAAM,WAAW,cAAc,OAAO,SAAS,CAAC;AAC7D;AAEA,SAAS,gBACP,OACA,MACA,WACA,cACA,OACA,WACA;AACA,SAAO,
|
|
4
|
+
"sourcesContent": ["import { isRSC, isServer, useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { useForceUpdate } from '@tamagui/use-force-update'\nimport React, { useContext, useLayoutEffect, useMemo, useRef, useState } from 'react'\n\nimport { getConfig } from '../config'\nimport { isDevTools } from '../constants/isDevTools'\nimport { ThemeContext } from '../contexts/ThemeContext'\nimport { areEqualSets } from '../helpers/areEqualSets'\nimport { createProxy } from '../helpers/createProxy'\nimport {\n GetNextThemeProps,\n ThemeManager,\n ThemeManagerContext,\n emptyManager,\n} from '../helpers/ThemeManager'\nimport { ThemeName, ThemeParsed } from '../types'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped'\nimport { useConstant } from './useConstant'\nimport { useServerRef } from './useServerHooks'\n\nexport interface ThemeProps {\n className?: string\n disableThemeClass?: boolean\n name: Exclude<ThemeName, number> | null\n componentName?: string\n children?: any\n reset?: boolean\n debug?: boolean | 'verbose'\n}\n\ninterface UseThemeState {\n uuid: Object\n keys: Set<string>\n isRendering: boolean\n}\n\nexport const useTheme = (\n themeName?: string | null,\n componentName?: string,\n props?: ThemeProps,\n forceUpdate?: any\n): ThemeParsed => {\n // TODO this can use useChangeThemeEffect almost ready\n if (isRSC) {\n const config = getConfig()\n // @ts-ignore\n return getThemeProxied(config.themes[config.defaultTheme], config.defaultTheme)\n }\n\n const state = useServerRef() as React.MutableRefObject<UseThemeState>\n if (!state.current) {\n state.current = {\n uuid: {},\n keys: new Set(),\n isRendering: true,\n }\n }\n\n const { name, theme, themes, themeManager, className } = useChangeThemeEffect(\n themeName,\n componentName,\n props,\n forceUpdate,\n state.current.uuid\n )\n\n if (process.env.NODE_ENV === 'development') {\n if (props?.debug === 'verbose') {\n // eslint-disable-next-line no-console\n console.groupCollapsed(' \uD83D\uDD39 useTheme =>', name)\n const logs = { themeName, componentName, name, className, ...(isDevTools && { theme }) }\n for (const key in logs) {\n // eslint-disable-next-line no-console\n console.log(' ', key, logs[key])\n }\n // eslint-disable-next-line no-console\n console.groupEnd()\n }\n }\n\n // track usage\n state.current.isRendering = true\n useIsomorphicLayoutEffect(() => {\n const st = state.current\n st.isRendering = false\n const cur = themeManager?.keys.get(st.uuid)\n if (!cur || !areEqualSets(st.keys, cur)) {\n themeManager?.track(st.uuid, st.keys)\n }\n })\n\n const debugProp = props && props['debug']\n\n if (!theme) {\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn('No theme with name', themeName)\n }\n return themes[getConfig().defaultTheme || 'light']\n }\n\n return useMemo(() => {\n return getThemeProxied(theme, name, className, themeManager, state, debugProp)\n }, [theme, name, className, themeManager, state, debugProp])\n}\n\nfunction getThemeProxied(\n theme: any,\n name: string,\n className?: string,\n themeManager?: ThemeManager | null,\n state?: React.MutableRefObject<UseThemeState>,\n debugProp?: boolean | 'verbose'\n) {\n return createProxy(theme, {\n has(_, key) {\n if (typeof key === 'string' && key[0] === '$') {\n key = key.slice(1)\n }\n return Reflect.has(theme, key)\n },\n get(_, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n }\n if (key === GetThemeManager) {\n return themeManager\n }\n if (key === 'name') {\n return name\n }\n if (key === 'className') {\n return className\n }\n if (!name || key === '__proto__' || typeof key === 'symbol' || key === '$typeof') {\n return Reflect.get(_, key)\n }\n // auto convert variables to plain\n if (key[0] === '$') {\n key = key.slice(1)\n }\n if (!themeManager) {\n return theme[key]\n }\n if (state) {\n if (state.current.isRendering && !state.current.keys.has(key)) {\n state.current.keys.add(key)\n if (process.env.NODE_ENV === 'development' && debugProp === 'verbose') {\n // eslint-disable-next-line no-console\n console.log(' \uD83D\uDD38 tracking theme', key)\n }\n }\n }\n return themeManager.getValue(key)\n },\n })\n}\n\nconst GetThemeManager = Symbol()\n\nexport const getThemeManager = (theme: any): ThemeManager | undefined => {\n if (!theme) return\n return theme[GetThemeManager]\n}\n\nexport const useThemeName = (opts?: { parent?: true }) => {\n if (isRSC) {\n const config = getConfig()\n return config.defaultTheme || 'light'\n }\n const parent = useContext(ThemeManagerContext)\n const [name, setName] = useState(parent?.name || '')\n\n useIsomorphicLayoutEffect(() => {\n if (!parent) return\n return parent.onChangeTheme((next, manager) => {\n const name = opts?.parent ? manager.parentName || next : next\n if (!name) return\n setName(name)\n })\n }, [parent])\n\n return name\n}\n\nexport const useDefaultThemeName = () => {\n return useContext(ThemeContext)?.defaultTheme\n}\n\nexport const activeThemeManagers = new Set<ThemeManager>()\n\nexport const useChangeThemeEffect = (\n name?: string | null,\n componentName?: string,\n props?: ThemeProps,\n forceUpdateProp?: any,\n uuid?: Object\n): {\n themes: Record<string, ThemeParsed>\n themeManager: ThemeManager | null\n name: string\n theme: ThemeParsed | null\n className?: string\n} => {\n const config = getConfig()\n\n if (process.env.NODE_ENV === 'development') {\n if (!config) {\n throw new Error(\n `Missing tamagui config, you either have a duplicate config, or haven't set it up. Be sure createTamagui is called before renderig.`\n )\n }\n }\n\n const { themes } = config\n\n if (isRSC) {\n // we need context working for this to work well\n const parentManager = new ThemeManager('light', 'light', themes.light)\n const next = parentManager.getNextTheme({\n name,\n componentName,\n themes,\n reset: props?.reset,\n })\n return {\n ...next,\n themes,\n themeManager: null,\n }\n }\n\n const debug = props && props['debug']\n const parentManager = useContext(ThemeManagerContext) || emptyManager\n const reset = props?.reset || false\n const getThemeProps: GetNextThemeProps = {\n name,\n componentName,\n themes,\n reset,\n }\n const next = parentManager.getNextTheme(getThemeProps, debug)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const forceUpdate = forceUpdateProp || useForceUpdate()\n\n const themeManager = useConstant(() => {\n return new ThemeManager(next.name, next.className, next.theme, parentManager, reset)\n })\n\n // not concurrent safe but fixes native (but breaks SSR and not needed on web (i think) so leave only on native)\n let didChange = false\n if (process.env.TAMAGUI_TARGET === 'native') {\n didChange = Boolean(\n next?.name !== themeManager.name || next?.className !== themeManager.className\n )\n if (didChange) {\n themeManager.update(next, false, false)\n }\n }\n\n if (!isServer) {\n useLayoutEffect(() => {\n themeManager.update(next, didChange)\n activeThemeManagers.add(themeManager)\n\n const disposeParentOnChange = parentManager.onChangeTheme(() => {\n const next = parentManager.getNextTheme(getThemeProps, debug)\n if (!next) return\n if (themeManager.update(next)) {\n if (uuid && !themeManager.isTracking(uuid)) {\n // no need to re-render if not tracking any keys\n return\n }\n if (process.env.NODE_ENV === 'development' && debug) {\n // eslint-disable-next-line no-console\n console.log('Changed theme', componentName, next, { props })\n }\n forceUpdate()\n }\n })\n\n return () => {\n activeThemeManagers.delete(themeManager)\n disposeParentOnChange()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [didChange, themes, next?.name, next?.className, componentName, debug])\n }\n\n return {\n ...(parentManager && {\n name: parentManager.name,\n theme: parentManager.theme,\n }),\n ...next,\n className: next.className === parentManager.className ? undefined : next.className,\n themes,\n themeManager,\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,UAAU,iCAAiC;AAC3D,SAAS,sBAAsB;AAC/B,SAAgB,YAAY,iBAAiB,SAAiB,gBAAgB;AAE9E,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAkBtB,MAAM,WAAW,CACtB,WACA,eACA,OACA,gBACgB;AAEhB,MAAI,OAAO;AACT,UAAM,SAAS,UAAU;AAEzB,WAAO,gBAAgB,OAAO,OAAO,OAAO,eAAe,OAAO,YAAY;AAAA,EAChF;AAEA,QAAM,QAAQ,aAAa;AAC3B,MAAI,CAAC,MAAM,SAAS;AAClB,UAAM,UAAU;AAAA,MACd,MAAM,CAAC;AAAA,MACP,MAAM,oBAAI,IAAI;AAAA,MACd,aAAa;AAAA,IACf;AAAA,EACF;AAEA,QAAM,EAAE,MAAM,OAAO,QAAQ,cAAc,UAAU,IAAI;AAAA,IACvD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,QAAQ;AAAA,EAChB;AAEA,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,SAAI,+BAAO,WAAU,WAAW;AAE9B,cAAQ,eAAe,2BAAoB,IAAI;AAC/C,YAAM,OAAO,EAAE,WAAW,eAAe,MAAM,WAAW,GAAI,cAAc,EAAE,MAAM,EAAG;AACvF,iBAAW,OAAO,MAAM;AAEtB,gBAAQ,IAAI,MAAM,KAAK,KAAK,IAAI;AAAA,MAClC;AAEA,cAAQ,SAAS;AAAA,IACnB;AAAA,EACF;AAGA,QAAM,QAAQ,cAAc;AAC5B,4BAA0B,MAAM;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aAAa,iBAAiB,OAAO;AAEnD,oBAAQ,IAAI,iBAAiB,eAAeA,OAAM,EAAE,MAAM,CAAC;AAAA,UAC7D;AACA,sBAAY;AAAA,QACd;AAAA,MACF,CAAC;AAED,aAAO,MAAM;AACX,4BAAoB,OAAO,YAAY;AACvC,8BAAsB;AAAA,MACxB;AAAA,IAEF,GAAG,CAAC,WAAW,QAAQ,6BAAM,MAAM,6BAAM,WAAW,eAAe,KAAK,CAAC;AAAA,EAC3E;AAEA,SAAO;AAAA,IACL,GAAI,iBAAiB;AAAA,MACnB,MAAM,cAAc;AAAA,MACpB,OAAO,cAAc;AAAA,IACvB;AAAA,IACA,GAAG;AAAA,IACH,WAAW,KAAK,cAAc,cAAc,YAAY,SAAY,KAAK;AAAA,IACzE;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["name", "parentManager", "next"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/core",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.193",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@expo/match-media": "^0.3.0",
|
|
31
|
-
"@tamagui/compose-refs": "^1.0.1-beta.
|
|
32
|
-
"@tamagui/constants": "^1.0.1-beta.
|
|
33
|
-
"@tamagui/helpers": "^1.0.1-beta.
|
|
34
|
-
"@tamagui/normalize-css-color-lite": "^1.0.1-beta.
|
|
35
|
-
"@tamagui/rnw": "^1.0.1-beta.
|
|
36
|
-
"@tamagui/rnw-lite": "^1.0.1-beta.
|
|
37
|
-
"@tamagui/use-did-finish-ssr": "^1.0.1-beta.
|
|
38
|
-
"@tamagui/use-event": "^1.0.1-beta.
|
|
39
|
-
"@tamagui/use-force-update": "^1.0.1-beta.
|
|
31
|
+
"@tamagui/compose-refs": "^1.0.1-beta.193",
|
|
32
|
+
"@tamagui/constants": "^1.0.1-beta.193",
|
|
33
|
+
"@tamagui/helpers": "^1.0.1-beta.193",
|
|
34
|
+
"@tamagui/normalize-css-color-lite": "^1.0.1-beta.193",
|
|
35
|
+
"@tamagui/rnw": "^1.0.1-beta.193",
|
|
36
|
+
"@tamagui/rnw-lite": "^1.0.1-beta.193",
|
|
37
|
+
"@tamagui/use-did-finish-ssr": "^1.0.1-beta.193",
|
|
38
|
+
"@tamagui/use-event": "^1.0.1-beta.193",
|
|
39
|
+
"@tamagui/use-force-update": "^1.0.1-beta.193",
|
|
40
40
|
"expo-screen-orientation": "^4.3.0",
|
|
41
41
|
"hyphenate-style-name": "^1.0.4",
|
|
42
42
|
"ts-toolbelt": "^9.6.0"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"react-dom": "*"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
49
|
+
"@tamagui/build": "^1.0.1-beta.193",
|
|
50
50
|
"@types/node": "^16.11.9",
|
|
51
51
|
"@types/react": "^18.0.15",
|
|
52
52
|
"csstype": "^3.0.10",
|
package/src/createComponent.tsx
CHANGED
|
@@ -109,7 +109,7 @@ export function createComponent<
|
|
|
109
109
|
let tamaguiConfig: TamaguiInternalConfig
|
|
110
110
|
let AnimatedText: any
|
|
111
111
|
let AnimatedView: any
|
|
112
|
-
let
|
|
112
|
+
let avoidClassesWhileAnimating = true
|
|
113
113
|
let defaultNativeStyle: any
|
|
114
114
|
let tamaguiDefaultProps: any
|
|
115
115
|
let initialSplitStyles: SplitStyleResult
|
|
@@ -142,7 +142,8 @@ export function createComponent<
|
|
|
142
142
|
const states = useServerState<TamaguiComponentState>(defaultComponentState!)
|
|
143
143
|
const state = propsIn.forceStyle ? { ...states[0], [propsIn.forceStyle]: true } : states[0]
|
|
144
144
|
|
|
145
|
-
const shouldAvoidClasses =
|
|
145
|
+
const shouldAvoidClasses =
|
|
146
|
+
!!(props.animation && avoidClassesWhileAnimating) || !staticConfig.acceptsClassName
|
|
146
147
|
const shouldForcePseudo = !!propsIn.forceStyle
|
|
147
148
|
const hasTextAncestor = !!(isWeb && isText ? useContext(TextAncestorContext) : false)
|
|
148
149
|
const splitStyleState =
|
|
@@ -738,18 +739,27 @@ export function createComponent<
|
|
|
738
739
|
const style = animationStyles ?? splitStyles.style
|
|
739
740
|
|
|
740
741
|
// TODO this is specific to reanimated rn
|
|
741
|
-
const isAnimatedReactNativeWeb = props.animation &&
|
|
742
|
+
const isAnimatedReactNativeWeb = props.animation && avoidClassesWhileAnimating
|
|
742
743
|
|
|
743
|
-
|
|
744
|
+
// temp fix for animated react-native-web restore pre-styleq functionality
|
|
745
|
+
if (isAnimatedReactNativeWeb) {
|
|
746
|
+
viewProps.style = style
|
|
744
747
|
viewProps.dataSet = {
|
|
745
748
|
...viewProps.dataSet,
|
|
746
749
|
className,
|
|
747
750
|
id: props.id,
|
|
748
751
|
}
|
|
752
|
+
} else if (staticConfig.isReactNativeWeb) {
|
|
753
|
+
const rnwStyle = { $$css: true }
|
|
754
|
+
for (const name of className.split(' ')) {
|
|
755
|
+
rnwStyle[name] = name
|
|
756
|
+
}
|
|
757
|
+
viewProps.style = [rnwStyle, ...(Array.isArray(style) ? style : [style])]
|
|
749
758
|
if (process.env.NODE_ENV === 'development') {
|
|
750
759
|
// turn debug data- props into dataSet in dev mode
|
|
751
760
|
Object.keys(viewProps).forEach((key) => {
|
|
752
761
|
if (key.startsWith('data-')) {
|
|
762
|
+
viewProps.dataSet ??= {}
|
|
753
763
|
viewProps.dataSet[key.replace('data-', '')] = viewProps[key]
|
|
754
764
|
delete viewProps[key]
|
|
755
765
|
}
|
|
@@ -757,9 +767,8 @@ export function createComponent<
|
|
|
757
767
|
}
|
|
758
768
|
} else {
|
|
759
769
|
viewProps.className = className
|
|
770
|
+
viewProps.style = style
|
|
760
771
|
}
|
|
761
|
-
|
|
762
|
-
viewProps.style = style
|
|
763
772
|
}
|
|
764
773
|
|
|
765
774
|
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
@@ -1075,7 +1084,7 @@ export function createComponent<
|
|
|
1075
1084
|
if (typeof window !== 'undefined') {
|
|
1076
1085
|
// prettier-ignore
|
|
1077
1086
|
// eslint-disable-next-line no-console
|
|
1078
|
-
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: splitStylesStyle, 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) })
|
|
1087
|
+
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: avoidClassesWhileAnimating, animation: props.animation, style: splitStylesStyle, 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) })
|
|
1079
1088
|
}
|
|
1080
1089
|
// eslint-disable-next-line no-console
|
|
1081
1090
|
console.groupEnd()
|
|
@@ -1115,7 +1124,7 @@ export function createComponent<
|
|
|
1115
1124
|
mergeShorthands(staticConfig, tamaguiConfig)
|
|
1116
1125
|
|
|
1117
1126
|
if (tamaguiConfig.animations) {
|
|
1118
|
-
|
|
1127
|
+
avoidClassesWhileAnimating = !!tamaguiConfig.animations.avoidClasses
|
|
1119
1128
|
AnimatedText = tamaguiConfig.animations.Text
|
|
1120
1129
|
AnimatedView = tamaguiConfig.animations.View
|
|
1121
1130
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function createProxy<A extends object>(target: A, handler: ProxyHandler<A>) {
|
|
2
|
+
if (process.env.NODE_ENV === 'development') {
|
|
3
|
+
if (typeof target !== 'object' || !target) {
|
|
4
|
+
// eslint-disable-next-line no-console
|
|
5
|
+
console.warn(
|
|
6
|
+
`Invalid object given for proxy:`,
|
|
7
|
+
target,
|
|
8
|
+
`
|
|
9
|
+
|
|
10
|
+
This can be due to a missing theme or configuration given to Tamagui.`,
|
|
11
|
+
new Error().stack
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return new Proxy(target || {}, handler)
|
|
16
|
+
}
|