@tamagui/core 1.0.0-alpha.2 → 1.0.0-alpha.7
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/createComponent.js +43 -29
- package/dist/createComponent.js.map +2 -2
- package/dist/createFont.js +4 -0
- package/dist/createFont.js.map +2 -2
- package/dist/createTamagui.js +7 -0
- package/dist/createTamagui.js.map +2 -2
- package/dist/createTokens.js +4 -0
- package/dist/createTokens.js.map +2 -2
- package/dist/createVariable.js +3 -0
- package/dist/createVariable.js.map +2 -2
- package/dist/helpers/getSplitStyles.js +1 -13
- package/dist/helpers/getSplitStyles.js.map +2 -2
- package/dist/helpers/isComponent.js +10 -0
- package/dist/helpers/isComponent.js.map +7 -0
- package/dist/helpers/isTamaguiComponent.js +10 -0
- package/dist/helpers/isTamaguiComponent.js.map +7 -0
- package/dist/helpers/isTamaguiElement.js +10 -0
- package/dist/helpers/isTamaguiElement.js.map +7 -0
- package/dist/helpers/validate.js +60 -0
- package/dist/helpers/validate.js.map +7 -0
- package/dist/helpers/validateConfig.js +46 -0
- package/dist/helpers/validateConfig.js.map +7 -0
- package/dist/helpers/validateTokens.js +29 -0
- package/dist/helpers/validateTokens.js.map +7 -0
- package/dist/hooks/useMedia.js +1 -1
- package/dist/hooks/useMedia.js.map +2 -2
- package/dist/hooks/useTheme.js +1 -1
- package/dist/hooks/useTheme.js.map +2 -2
- package/dist/index.cjs +223 -137
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +1 -2
- package/dist/index.js.map +2 -2
- package/dist/views/Theme.js +16 -7
- package/dist/views/Theme.js.map +2 -2
- package/dist/views/ThemeInverse.js +0 -1
- package/dist/views/ThemeInverse.js.map +2 -2
- package/dist/views/ThemeManagerContext.js +7 -1
- package/dist/views/ThemeManagerContext.js.map +2 -2
- package/package.json +12 -5
- package/src/createComponent.tsx +49 -38
- package/src/createFont.ts +5 -0
- package/src/createTamagui.ts +8 -0
- package/src/createTokens.ts +6 -1
- package/src/createVariable.ts +4 -0
- package/src/helpers/getSplitStyles.tsx +3 -16
- package/src/helpers/isTamaguiElement.tsx +5 -0
- package/src/helpers/validate.ts +59 -0
- package/src/hooks/useMedia.tsx +1 -1
- package/src/hooks/useTheme.tsx +1 -1
- package/src/index.ts +1 -2
- package/src/types.tsx +1 -0
- package/src/views/Theme.tsx +26 -9
- package/src/views/ThemeInverse.tsx +0 -1
- package/src/views/ThemeManagerContext.tsx +11 -1
- package/types.d.ts +3 -5
- package/.ultra.cache.json +0 -1
- package/_/constants/constants.js +0 -14
- package/_/constants/constants.js.map +0 -7
- package/_/constants/platform.js +0 -20
- package/_/constants/platform.js.map +0 -7
- package/_/constants/pseudos.js +0 -18
- package/_/constants/pseudos.js.map +0 -7
- package/_/constants/rnw.js +0 -22
- package/_/constants/rnw.js.map +0 -7
- package/_/createComponent.js +0 -427
- package/_/createComponent.js.map +0 -7
- package/_/createShorthands.js +0 -10
- package/_/createShorthands.js.map +0 -7
- package/_/createTamagui.js +0 -122
- package/_/createTamagui.js.map +0 -7
- package/_/createTheme.js +0 -20
- package/_/createTheme.js.map +0 -7
- package/_/createTokens.js +0 -29
- package/_/createTokens.js.map +0 -7
- package/_/createVariable.js +0 -22
- package/_/createVariable.js.map +0 -7
- package/_/helpers/addStylesUsingClassname.js +0 -32
- package/_/helpers/addStylesUsingClassname.js.map +0 -7
- package/_/helpers/createMediaStyle.js +0 -34
- package/_/helpers/createMediaStyle.js.map +0 -7
- package/_/helpers/createTamaguiProvider.js +0 -42
- package/_/helpers/createTamaguiProvider.js.map +0 -7
- package/_/helpers/extendStaticConfig.js +0 -176
- package/_/helpers/extendStaticConfig.js.map +0 -7
- package/_/helpers/fixNativeShadow.js +0 -8
- package/_/helpers/fixNativeShadow.js.map +0 -7
- package/_/helpers/fixNativeShadow.native.js +0 -30
- package/_/helpers/fixNativeShadow.native.js.map +0 -7
- package/_/helpers/getSplitStyles.js +0 -160
- package/_/helpers/getSplitStyles.js.map +0 -7
- package/_/helpers/getStylesAtomic.js +0 -84
- package/_/helpers/getStylesAtomic.js.map +0 -7
- package/_/helpers/getStylesAtomic.native.js +0 -10
- package/_/helpers/getStylesAtomic.native.js.map +0 -7
- package/_/helpers/insertStyleRule.js +0 -24
- package/_/helpers/insertStyleRule.js.map +0 -7
- package/_/helpers/matchMedia.js +0 -15
- package/_/helpers/matchMedia.js.map +0 -7
- package/_/helpers/matchMedia.native.js +0 -8
- package/_/helpers/matchMedia.native.js.map +0 -7
- package/_/helpers/themeable.js +0 -26
- package/_/helpers/themeable.js.map +0 -7
- package/_/hooks/useConstant.js +0 -15
- package/_/hooks/useConstant.js.map +0 -7
- package/_/hooks/useFeatures.js +0 -75
- package/_/hooks/useFeatures.js.map +0 -7
- package/_/hooks/useForceUpdate.js +0 -28
- package/_/hooks/useForceUpdate.js.map +0 -7
- package/_/hooks/useMedia.js +0 -173
- package/_/hooks/useMedia.js.map +0 -7
- package/_/hooks/usePressable.js +0 -14
- package/_/hooks/usePressable.js.map +0 -7
- package/_/hooks/useTheme.js +0 -94
- package/_/hooks/useTheme.js.map +0 -7
- package/_/index.js +0 -30
- package/_/index.js.map +0 -7
- package/_/static/postProcessStyles.js +0 -18
- package/_/static/postProcessStyles.js.map +0 -7
- package/_/static.js +0 -12
- package/_/static.js.map +0 -7
- package/_/styled.js +0 -21
- package/_/styled.js.map +0 -7
- package/_/types.js +0 -1
- package/_/types.js.map +0 -7
- package/_/views/Animated.js +0 -79
- package/_/views/Animated.js.map +0 -7
- package/_/views/Stack.js +0 -12
- package/_/views/Stack.js.map +0 -7
- package/_/views/Text.js +0 -60
- package/_/views/Text.js.map +0 -7
- package/_/views/TextAncestorContext.js +0 -19
- package/_/views/TextAncestorContext.js.map +0 -7
- package/_/views/Theme.js +0 -57
- package/_/views/Theme.js.map +0 -7
- package/_/views/ThemeContext.js +0 -6
- package/_/views/ThemeContext.js.map +0 -7
- package/_/views/ThemeInverse.js +0 -27
- package/_/views/ThemeInverse.js.map +0 -7
- package/_/views/ThemeManagerContext.js +0 -56
- package/_/views/ThemeManagerContext.js.map +0 -7
- package/_/views/ThemeProvider.js +0 -45
- package/_/views/ThemeProvider.js.map +0 -7
- package/src/hooks/useForceUpdate.tsx +0 -26
- package/src/views/SafeAreaProvider.tsx +0 -33
- package/tsconfig.json +0 -8
package/dist/createComponent.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
import { concatClassName, stylePropsView } from "@tamagui/helpers";
|
|
4
|
+
import { useForceUpdate } from "@tamagui/use-force-update";
|
|
4
5
|
import React, {
|
|
5
6
|
Children,
|
|
6
7
|
Fragment,
|
|
@@ -21,7 +22,6 @@ import { addStylesUsingClassname, useStylesAsClassname } from "./helpers/addStyl
|
|
|
21
22
|
import { extendStaticConfig, parseStaticConfig } from "./helpers/extendStaticConfig";
|
|
22
23
|
import { getSplitStyles } from "./helpers/getSplitStyles";
|
|
23
24
|
import { useFeatures } from "./hooks/useFeatures";
|
|
24
|
-
import { useForceUpdate } from "./hooks/useForceUpdate";
|
|
25
25
|
import { usePressable } from "./hooks/usePressable";
|
|
26
26
|
import { TextAncestorContext } from "./views/TextAncestorContext";
|
|
27
27
|
import { ThemeManagerContext } from "./views/ThemeManagerContext";
|
|
@@ -47,6 +47,38 @@ function createComponent(configIn) {
|
|
|
47
47
|
let defaultsClassName = "";
|
|
48
48
|
let initialTheme;
|
|
49
49
|
const component = forwardRef((props, forwardedRef) => {
|
|
50
|
+
const forceUpdate = useForceUpdate();
|
|
51
|
+
const features = useFeatures(props, { forceUpdate });
|
|
52
|
+
const manager = useContext(ThemeManagerContext);
|
|
53
|
+
const [state, set_] = useState(() => ({
|
|
54
|
+
hover: false,
|
|
55
|
+
press: false,
|
|
56
|
+
pressIn: false,
|
|
57
|
+
theme: manager.name
|
|
58
|
+
}));
|
|
59
|
+
const set = /* @__PURE__ */ __name((next) => set_((prev) => {
|
|
60
|
+
for (const key in next) {
|
|
61
|
+
if (prev[key] !== next[key]) {
|
|
62
|
+
return { ...prev, ...next };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return prev;
|
|
66
|
+
}), "set");
|
|
67
|
+
if (process.env.NODE_ENV === "development" && !isText && isWeb) {
|
|
68
|
+
Children.toArray(props.children).forEach((item) => {
|
|
69
|
+
if (typeof item === "string") {
|
|
70
|
+
console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const hasTextAncestor = isWeb ? useContext(TextAncestorContext) : false;
|
|
75
|
+
const hostRef = useRef(null);
|
|
76
|
+
const {
|
|
77
|
+
viewProps: viewPropsIn,
|
|
78
|
+
pseudos,
|
|
79
|
+
style,
|
|
80
|
+
classNames
|
|
81
|
+
} = getSplitStyles(props, staticConfig, manager.theme || initialTheme);
|
|
50
82
|
const {
|
|
51
83
|
tag,
|
|
52
84
|
hitSlop,
|
|
@@ -80,34 +112,17 @@ function createComponent(configIn) {
|
|
|
80
112
|
onStartShouldSetResponderCapture,
|
|
81
113
|
onMouseDown,
|
|
82
114
|
onClick,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}));
|
|
94
|
-
const set = /* @__PURE__ */ __name((next) => set_((prev) => {
|
|
95
|
-
for (const key in next) {
|
|
96
|
-
if (prev[key] !== next[key]) {
|
|
97
|
-
return { ...prev, ...next };
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return prev;
|
|
101
|
-
}), "set");
|
|
102
|
-
if (process.env.NODE_ENV === "development" && !isText && isWeb) {
|
|
103
|
-
Children.toArray(props.children).forEach((item) => {
|
|
104
|
-
if (typeof item === "string") {
|
|
105
|
-
console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
115
|
+
accessible,
|
|
116
|
+
accessibilityRole,
|
|
117
|
+
onLayout,
|
|
118
|
+
...viewProps
|
|
119
|
+
} = viewPropsIn;
|
|
120
|
+
if (!isWeb) {
|
|
121
|
+
if (accessible)
|
|
122
|
+
viewProps.accessible = accessible;
|
|
123
|
+
if (accessibilityRole)
|
|
124
|
+
viewProps.accessibilityRole = accessibilityRole;
|
|
108
125
|
}
|
|
109
|
-
const hasTextAncestor = isWeb ? useContext(TextAncestorContext) : false;
|
|
110
|
-
const hostRef = useRef(null);
|
|
111
126
|
if (isWeb) {
|
|
112
127
|
rnw.useResponderEvents(hostRef, {
|
|
113
128
|
onMoveShouldSetResponder,
|
|
@@ -129,7 +144,6 @@ function createComponent(configIn) {
|
|
|
129
144
|
});
|
|
130
145
|
}
|
|
131
146
|
const isTracking = useRef(false);
|
|
132
|
-
const { viewProps, pseudos, style, classNames } = getSplitStyles(props, staticConfig, manager.theme || initialTheme);
|
|
133
147
|
const internal = useRef();
|
|
134
148
|
if (!internal.current) {
|
|
135
149
|
internal.current = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/createComponent.tsx"],
|
|
4
|
-
"sourcesContent": ["import { concatClassName, stylePropsView } from '@tamagui/helpers'\nimport React, {\n Children,\n Fragment,\n createElement,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react'\nimport { StyleSheet, Text, View, ViewStyle } from 'react-native'\n\nimport { stackDefaultStyles } from './constants/constants'\nimport { isTouchDevice, isWeb } from './constants/platform'\nimport { rnw } from './constants/rnw'\nimport { onConfiguredOnce } from './createTamagui'\nimport { addStylesUsingClassname, useStylesAsClassname } from './helpers/addStylesUsingClassname'\nimport { extendStaticConfig, parseStaticConfig } from './helpers/extendStaticConfig'\nimport { getSplitStyles } from './helpers/getSplitStyles'\nimport { useFeatures } from './hooks/useFeatures'\nimport { useForceUpdate } from './hooks/useForceUpdate'\nimport { usePressable } from './hooks/usePressable'\nimport {\n SpaceTokens,\n StaticComponent,\n StaticConfig,\n StaticConfigParsed,\n TamaguiInternalConfig,\n} from './types'\nimport { TextAncestorContext } from './views/TextAncestorContext'\nimport { ThemeManagerContext } from './views/ThemeManagerContext'\n\nexport const mouseUps = new Set<Function>()\n\nif (typeof document !== 'undefined') {\n document.addEventListener('mouseup', () => {\n mouseUps.forEach((x) => x())\n mouseUps.clear()\n })\n}\n\ntype DefaultProps = {}\n\nexport function createComponent<A extends Object = DefaultProps>(\n configIn: Partial<StaticConfig> | StaticConfigParsed\n) {\n let staticConfig: StaticConfigParsed\n if ('parsed' in configIn) {\n staticConfig = configIn\n } else {\n staticConfig = parseStaticConfig(configIn)\n }\n\n const { Component, validStyles, isText, isZStack } = staticConfig\n const validStyleProps = validStyles ?? stylePropsView\n\n // split out default styles vs props so we can assign it to component.defaultProps\n let defaultProps = null as any\n let tamaguiConfig: TamaguiInternalConfig\n\n // web uses className, native uses style\n let defaultsStyle: any\n let defaultsClassName = ''\n let initialTheme: any\n\n // see onConfiguredOnce below which attaches a name then to this component\n\n const component = forwardRef<View, A>((props: any, forwardedRef) => {\n const {\n tag,\n hitSlop,\n children,\n pointerEvents,\n onPress,\n onPressIn,\n onPressOut,\n onHoverIn,\n onHoverOut,\n space,\n disabled,\n onMouseEnter,\n onMouseLeave,\n hrefAttrs,\n onMoveShouldSetResponder,\n onMoveShouldSetResponderCapture,\n onResponderEnd,\n onResponderGrant,\n onResponderMove,\n onResponderReject,\n onResponderRelease,\n onResponderStart,\n onResponderTerminate,\n onResponderTerminationRequest,\n onScrollShouldSetResponder,\n onScrollShouldSetResponderCapture,\n onSelectionChangeShouldSetResponder,\n onSelectionChangeShouldSetResponderCapture,\n onStartShouldSetResponder,\n onStartShouldSetResponderCapture,\n onMouseDown,\n onClick,\n // TODO feature load layou hook\n onLayout,\n } = props\n\n const forceUpdate = useForceUpdate()\n const features = useFeatures(props, { forceUpdate })\n const manager = useContext(ThemeManagerContext)\n const [state, set_] = useState(() => ({\n hover: false,\n press: false,\n pressIn: false,\n theme: manager.name,\n }))\n const set = (next: Partial<typeof state>) =>\n set_((prev) => {\n for (const key in next) {\n if (prev[key] !== next[key]) {\n return { ...prev, ...next }\n }\n }\n return prev\n })\n\n // from react-native-web\n if (process.env.NODE_ENV === 'development' && !isText && isWeb) {\n Children.toArray(props.children).forEach((item) => {\n if (typeof item === 'string') {\n console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`)\n }\n })\n }\n\n const hasTextAncestor = isWeb ? useContext(TextAncestorContext) : false\n const hostRef = useRef(null)\n\n if (isWeb) {\n // from react-native-web\n rnw.useResponderEvents(hostRef, {\n onMoveShouldSetResponder,\n onMoveShouldSetResponderCapture,\n onResponderEnd,\n onResponderGrant,\n onResponderMove,\n onResponderReject,\n onResponderRelease,\n onResponderStart,\n onResponderTerminate,\n onResponderTerminationRequest,\n onScrollShouldSetResponder,\n onScrollShouldSetResponderCapture,\n onSelectionChangeShouldSetResponder,\n onSelectionChangeShouldSetResponderCapture,\n onStartShouldSetResponder,\n onStartShouldSetResponderCapture,\n })\n }\n\n const isTracking = useRef(false)\n\n const { viewProps, pseudos, style, classNames } = getSplitStyles(\n props,\n staticConfig,\n (manager.theme as any) || initialTheme\n )\n\n // hasEverHadEvents prevents repareting if you remove onPress or similar...\n const internal = useRef<{ isMounted: boolean; hasEverHadEvents?: boolean }>()\n if (!internal.current) {\n internal.current = {\n isMounted: true,\n }\n }\n\n useEffect(() => {\n internal.current!.isMounted = true\n const dispose = manager?.onChangeTheme((name) => {\n if (isTracking.current) {\n set({ theme: name })\n }\n })\n return () => {\n dispose()\n mouseUps.delete(unPress)\n isTracking.current = false\n internal.current!.isMounted = false\n }\n }, [manager])\n\n // element\n const element = isWeb\n ? !Component || typeof Component === 'string'\n ? // default to tag, fallback to component (when both strings)\n tag || Component\n : Component\n : Component\n const ReactView = !isWeb ? View : element || (hasTextAncestor ? 'span' : 'div')\n const ReactText = !isWeb ? Text : element || 'span'\n const ViewComponent = isText ? ReactText : ReactView\n\n // styles\n const isHovering = !isTouchDevice && !disabled && pseudos && state.hover\n const isPressing = !disabled && pseudos && state.press\n\n const styles = [\n // parity w react-native-web, only for text in text\n // TODO this should be able to be done w css to replicate after extraction:\n // (.text .text { display: inline-flex; }) (but if they set display we'd need stronger precendence)\n // isText && hasTextAncestor && isWeb ? { display: 'inline-flex' } : null,\n style,\n isHovering ? pseudos.hoverStyle || null : null,\n isPressing ? pseudos.pressStyle || null : null,\n ]\n\n if (isWeb) {\n const stylesClassNames = useStylesAsClassname(styles)\n const classList = isText\n ? [\n defaultsClassName,\n // hasTextAncestor === true && cssText.textHasAncestor,\n // TODO MOVE TO VARIANTS [number] [any]\n // numberOfLines != null && numberOfLines > 1 && cssText.textMultiLine,\n classNames,\n stylesClassNames,\n props.className,\n ]\n : [defaultsClassName, props.className, classNames, stylesClassNames]\n\n // @ts-expect-error\n const className = concatClassName(...classList)\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n // prettier-ignore\n console.log('\uD83E\uDD5A className', { style, styles, classList, stylesClassNames, className })\n }\n }\n viewProps.className = className\n } else {\n viewProps.style = styles\n }\n\n if (pointerEvents) {\n viewProps.pointerEvents = pointerEvents\n }\n\n if (isWeb) {\n // from react-native-web\n const platformMethodsRef = rnw.usePlatformMethods(viewProps)\n const setRef = rnw.useMergeRefs(hostRef, platformMethodsRef, forwardedRef)\n viewProps.ref = setRef\n if (props.href != null && hrefAttrs != null) {\n const { download, rel, target } = hrefAttrs\n if (download != null) {\n viewProps.download = download\n }\n if (rel != null) {\n viewProps.rel = rel\n }\n if (typeof target === 'string') {\n viewProps.target = target.charAt(0) !== '_' ? '_' + target : target\n }\n }\n } else {\n if (forwardedRef) {\n viewProps.ref = forwardedRef\n }\n }\n\n const attachPress = !!(\n (pseudos && pseudos.pressStyle) ||\n onPress ||\n onPressOut ||\n onPressIn ||\n onClick\n )\n const attachHover =\n isWeb &&\n !isTouchDevice &&\n !!((pseudos && pseudos.hoverStyle) || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave)\n\n // check presence to prevent reparenting bugs, allows for onPress={x ? function : undefined} usage\n // while avoiding reparenting...\n // once proper reparenting is supported, we can remove this and use that...\n const shouldAttach =\n internal.current.hasEverHadEvents ||\n attachPress ||\n attachHover ||\n 'pressStyle' in props ||\n 'onPress' in props ||\n 'onPressIn' in props ||\n 'onPressOut' in props ||\n (isWeb &&\n ('hoverStyle' in props ||\n 'onClick' in props ||\n 'onHoverIn' in props ||\n 'onHoverOut' in props ||\n 'onMouseEnter' in props ||\n 'onMouseLeave' in props))\n\n // never remove events as we wrap in a div (for now, may be able to remove..)\n if (shouldAttach) {\n internal.current.hasEverHadEvents = true\n }\n\n const unPress = useCallback(() => {\n if (!internal.current!.isMounted) return\n set({\n press: false,\n pressIn: false,\n })\n }, [])\n\n const events = shouldAttach\n ? {\n ...(!isWeb && {\n // non web\n onPressOut: (e) => {\n unPress()\n onPressOut?.(e)\n },\n }),\n ...(isWeb &&\n !isTouchDevice && {\n onMouseEnter:\n attachHover || attachPress\n ? (e) => {\n let next: Partial<typeof state> = {}\n if (attachHover) {\n next.hover = true\n }\n if (state.pressIn) {\n next.press = true\n }\n if (Object.keys(next).length) {\n set(next)\n }\n onHoverIn?.(e)\n onMouseEnter?.(e)\n }\n : undefined,\n onMouseLeave:\n attachHover || attachPress\n ? (e) => {\n let next: Partial<typeof state> = {}\n mouseUps.add(unPress)\n if (attachHover) {\n next.hover = false\n }\n if (state.pressIn) {\n next.press = false\n next.pressIn = false\n }\n if (Object.keys(next).length) {\n set(next)\n }\n onHoverOut?.(e)\n onMouseLeave?.(e)\n }\n : undefined,\n }),\n onMouseDown: attachPress\n ? (e) => {\n set({\n press: true,\n pressIn: true,\n })\n onPressIn?.(e)\n onMouseDown?.(e)\n }\n : (onPressIn as any),\n onClick: attachPress\n ? (e) => {\n // this caused issue with next.js passing href\n // e.preventDefault()\n onPress?.(e)\n onClick?.(e)\n unPress()\n onPressOut?.(e)\n }\n : (onPressOut as any),\n }\n : null\n\n if (events) {\n if (typeof ViewComponent !== 'string') {\n // TODO once we do the above we can then rely entirely on pressStyle returned here isntead of above pressStyle logic\n const [pressProps] = usePressable({\n disabled,\n hitSlop,\n onPressIn: events.onMouseDown,\n onPressOut: events.onPressOut,\n onPress: events.onClick,\n })\n Object.assign(viewProps, pressProps)\n } else {\n Object.assign(viewProps, events)\n }\n }\n\n const childEls = spacedChildren({\n children,\n space,\n flexDirection: props.flexDirection || defaultProps?.flexDirection,\n isZStack: isZStack,\n })\n\n let content: any\n\n // replicate react-native-web's `createElement`\n if (isWeb && rnw) {\n const domProps = rnw.createDOMProps(viewProps)\n const className =\n domProps.className && domProps.className !== viewProps.className\n ? `${domProps.className} ${viewProps.className}`\n : viewProps.className\n Object.assign(viewProps, domProps)\n viewProps.className = className\n content = createElement(ViewComponent, viewProps, childEls)\n } else {\n content = createElement(ViewComponent, viewProps, childEls)\n }\n\n const shouldWrapTextAncestor = isWeb && isText && !hasTextAncestor\n if (shouldWrapTextAncestor) {\n // from react-native-web\n // @ts-ignore\n content = createElement(TextAncestorContext.Provider, { value: true }, content)\n }\n\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n viewProps['debug'] = true\n console.log('\uD83E\uDD5A props in:', props)\n console.log('\uD83E\uDD5A props out:', viewProps)\n console.log(props.onClick?.toString())\n // prettier-ignore\n console.log('\uD83E\uDD5A etc:', { shouldAttach, ViewComponent, viewProps, styles, pseudos, content, childEls })\n // only on browser because node expands it huge\n if (isWeb) {\n console.log('\uD83E\uDD5A component info', { staticConfig, tamaguiConfig })\n }\n }\n }\n\n return (\n <>\n {features}\n {content}\n </>\n )\n })\n\n // Once configuration is run and all components are registered\n // get default props + className and analyze styles\n onConfiguredOnce((conf) => {\n tamaguiConfig = conf\n initialTheme = conf.themes[conf.defaultTheme || Object.keys(conf.themes)[0]]\n const next = getSplitStyles(staticConfig.defaultProps, staticConfig, initialTheme, true)\n if (isWeb) {\n if (next.classNames) {\n defaultsClassName += next.classNames + ' '\n }\n defaultsClassName += addStylesUsingClassname([next.style, next.pseudos])\n } else {\n if (!hasWarnedOnce) {\n hasWarnedOnce = true\n console.log('\u26A0\uFE0F we need to account for default styles for media queries')\n }\n }\n // @ts-ignore\n component.defaultProps = {\n ...next.viewProps,\n ...component.defaultProps,\n }\n if (process.env.NODE_ENV === 'development') {\n if (staticConfig.defaultProps?.debug) {\n console.log('tamagui debug component:', next, defaultsClassName, component.defaultProps)\n }\n }\n })\n\n component['staticConfig'] = {\n validStyles: validStyleProps,\n ...staticConfig,\n }\n\n const res = component as any as StaticComponent<A, void>\n\n // add extractable HoC\n res['extractable'] = (Component: any) => {\n Component['staticConfig'] = extendStaticConfig(res, {\n neverFlatten: true,\n defaultProps: Component.defaultProps,\n })\n return Component\n }\n\n return res\n}\n\nlet hasWarnedOnce = false\n\n// dont used styled() here to avoid circular deps\n// keep inline to avoid circular deps\n\nexport const Spacer = createComponent<{ size?: number | SpaceTokens; flex?: boolean | number }>({\n defaultProps: {\n ...stackDefaultStyles,\n size: true,\n },\n variants: {\n size: {\n '...size': (size, { tokens }) => {\n size = size == true ? '$true' : size\n return {\n width: tokens.size[size] ?? size,\n height: tokens.size[size] ?? size,\n }\n },\n },\n\n direction: {\n horizontal: {\n height: 0,\n },\n vertical: {\n width: 0,\n },\n },\n },\n})\n\nexport function spacedChildren({\n isZStack,\n children,\n space,\n flexDirection,\n}: {\n isZStack?: boolean\n children: any\n space?: any\n flexDirection?: ViewStyle['flexDirection']\n}) {\n if (!space && !isZStack) {\n return children\n }\n const childrenList = Children.toArray(children)\n const len = childrenList.length\n if (len === 1) {\n return children\n }\n const next: any[] = []\n for (const [index, child] of childrenList.entries()) {\n if (child === null || child === undefined) {\n continue\n }\n\n const key = `${child?.['key'] ?? index}`\n\n next.push(<Fragment key={key}>{isZStack ? <Absolute>{child}</Absolute> : child}</Fragment>)\n\n // allows for custom visually hidden components that dont insert spacing\n if (child?.['type']?.['isVisuallyHidden']) {\n continue\n }\n\n if (index !== len - 1) {\n if (space) {\n next.push(\n <Spacer\n key={`${key}_spacer`}\n // @ts-ignore TODO\n direction={\n flexDirection === 'row' || flexDirection === 'row-reverse' ? 'horizontal' : 'vertical'\n }\n size={space}\n />\n )\n }\n }\n }\n return next\n}\n\n// for now not so \"tamagui-y\"\nconst Absolute = ({ children }) => <View style={sheet.fullscreen}>{children}</View>\nconst sheet = StyleSheet.create({\n fullscreen: {\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n },\n})\n"],
|
|
5
|
-
"mappings": ";;AAAA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;
|
|
4
|
+
"sourcesContent": ["import { concatClassName, stylePropsView } from '@tamagui/helpers'\nimport { useForceUpdate } from '@tamagui/use-force-update'\nimport React, {\n Children,\n Fragment,\n createElement,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react'\nimport { StyleSheet, Text, View, ViewStyle } from 'react-native'\n\nimport { stackDefaultStyles } from './constants/constants'\nimport { isTouchDevice, isWeb } from './constants/platform'\nimport { rnw } from './constants/rnw'\nimport { onConfiguredOnce } from './createTamagui'\nimport { addStylesUsingClassname, useStylesAsClassname } from './helpers/addStylesUsingClassname'\nimport { extendStaticConfig, parseStaticConfig } from './helpers/extendStaticConfig'\nimport { getSplitStyles } from './helpers/getSplitStyles'\nimport { useFeatures } from './hooks/useFeatures'\nimport { usePressable } from './hooks/usePressable'\nimport {\n SpaceTokens,\n StaticComponent,\n StaticConfig,\n StaticConfigParsed,\n TamaguiInternalConfig,\n} from './types'\nimport { TextAncestorContext } from './views/TextAncestorContext'\nimport { ThemeManagerContext } from './views/ThemeManagerContext'\n\nexport const mouseUps = new Set<Function>()\n\nif (typeof document !== 'undefined') {\n document.addEventListener('mouseup', () => {\n mouseUps.forEach((x) => x())\n mouseUps.clear()\n })\n}\n\ntype DefaultProps = {}\n\nexport function createComponent<A extends Object = DefaultProps>(\n configIn: Partial<StaticConfig> | StaticConfigParsed\n) {\n let staticConfig: StaticConfigParsed\n if ('parsed' in configIn) {\n staticConfig = configIn\n } else {\n staticConfig = parseStaticConfig(configIn)\n }\n\n const { Component, validStyles, isText, isZStack } = staticConfig\n const validStyleProps = validStyles ?? stylePropsView\n\n // split out default styles vs props so we can assign it to component.defaultProps\n let defaultProps = null as any\n let tamaguiConfig: TamaguiInternalConfig\n\n // web uses className, native uses style\n let defaultsStyle: any\n let defaultsClassName = ''\n let initialTheme: any\n\n // see onConfiguredOnce below which attaches a name then to this component\n\n const component = forwardRef<View, A>((props: any, forwardedRef) => {\n const forceUpdate = useForceUpdate()\n const features = useFeatures(props, { forceUpdate })\n const manager = useContext(ThemeManagerContext)\n const [state, set_] = useState(() => ({\n hover: false,\n press: false,\n pressIn: false,\n theme: manager.name,\n }))\n const set = (next: Partial<typeof state>) =>\n set_((prev) => {\n for (const key in next) {\n if (prev[key] !== next[key]) {\n return { ...prev, ...next }\n }\n }\n return prev\n })\n\n // from react-native-web\n if (process.env.NODE_ENV === 'development' && !isText && isWeb) {\n Children.toArray(props.children).forEach((item) => {\n if (typeof item === 'string') {\n console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`)\n }\n })\n }\n\n const hasTextAncestor = isWeb ? useContext(TextAncestorContext) : false\n const hostRef = useRef(null)\n\n const {\n viewProps: viewPropsIn,\n pseudos,\n style,\n classNames,\n } = getSplitStyles(props, staticConfig, (manager.theme as any) || initialTheme)\n\n const {\n tag,\n hitSlop,\n children,\n pointerEvents,\n onPress,\n onPressIn,\n onPressOut,\n onHoverIn,\n onHoverOut,\n space,\n disabled,\n onMouseEnter,\n onMouseLeave,\n hrefAttrs,\n onMoveShouldSetResponder,\n onMoveShouldSetResponderCapture,\n onResponderEnd,\n onResponderGrant,\n onResponderMove,\n onResponderReject,\n onResponderRelease,\n onResponderStart,\n onResponderTerminate,\n onResponderTerminationRequest,\n onScrollShouldSetResponder,\n onScrollShouldSetResponderCapture,\n onSelectionChangeShouldSetResponder,\n onSelectionChangeShouldSetResponderCapture,\n onStartShouldSetResponder,\n onStartShouldSetResponderCapture,\n onMouseDown,\n onClick,\n\n accessible,\n accessibilityRole,\n\n // TODO feature load layout hook\n onLayout,\n ...viewProps\n } = viewPropsIn\n\n if (!isWeb) {\n if (accessible) viewProps.accessible = accessible\n if (accessibilityRole) viewProps.accessibilityRole = accessibilityRole\n }\n\n if (isWeb) {\n // from react-native-web\n rnw.useResponderEvents(hostRef, {\n onMoveShouldSetResponder,\n onMoveShouldSetResponderCapture,\n onResponderEnd,\n onResponderGrant,\n onResponderMove,\n onResponderReject,\n onResponderRelease,\n onResponderStart,\n onResponderTerminate,\n onResponderTerminationRequest,\n onScrollShouldSetResponder,\n onScrollShouldSetResponderCapture,\n onSelectionChangeShouldSetResponder,\n onSelectionChangeShouldSetResponderCapture,\n onStartShouldSetResponder,\n onStartShouldSetResponderCapture,\n })\n }\n\n const isTracking = useRef(false)\n\n // hasEverHadEvents prevents repareting if you remove onPress or similar...\n const internal = useRef<{ isMounted: boolean; hasEverHadEvents?: boolean }>()\n if (!internal.current) {\n internal.current = {\n isMounted: true,\n }\n }\n\n useEffect(() => {\n internal.current!.isMounted = true\n const dispose = manager?.onChangeTheme((name) => {\n if (isTracking.current) {\n set({ theme: name })\n }\n })\n return () => {\n dispose()\n mouseUps.delete(unPress)\n isTracking.current = false\n internal.current!.isMounted = false\n }\n }, [manager])\n\n // element\n const element = isWeb\n ? !Component || typeof Component === 'string'\n ? // default to tag, fallback to component (when both strings)\n tag || Component\n : Component\n : Component\n const ReactView = !isWeb ? View : element || (hasTextAncestor ? 'span' : 'div')\n const ReactText = !isWeb ? Text : element || 'span'\n const ViewComponent = isText ? ReactText : ReactView\n\n // styles\n const isHovering = !isTouchDevice && !disabled && pseudos && state.hover\n const isPressing = !disabled && pseudos && state.press\n\n const styles = [\n // parity w react-native-web, only for text in text\n // TODO this should be able to be done w css to replicate after extraction:\n // (.text .text { display: inline-flex; }) (but if they set display we'd need stronger precendence)\n // isText && hasTextAncestor && isWeb ? { display: 'inline-flex' } : null,\n style,\n isHovering ? pseudos.hoverStyle || null : null,\n isPressing ? pseudos.pressStyle || null : null,\n ]\n\n if (isWeb) {\n const stylesClassNames = useStylesAsClassname(styles)\n const classList = isText\n ? [\n defaultsClassName,\n // hasTextAncestor === true && cssText.textHasAncestor,\n // TODO MOVE TO VARIANTS [number] [any]\n // numberOfLines != null && numberOfLines > 1 && cssText.textMultiLine,\n classNames,\n stylesClassNames,\n props.className,\n ]\n : [defaultsClassName, props.className, classNames, stylesClassNames]\n\n // @ts-expect-error\n const className = concatClassName(...classList)\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n // prettier-ignore\n console.log('\uD83E\uDD5A className', { style, styles, classList, stylesClassNames, className })\n }\n }\n viewProps.className = className\n } else {\n viewProps.style = styles\n }\n\n if (pointerEvents) {\n viewProps.pointerEvents = pointerEvents\n }\n\n if (isWeb) {\n // from react-native-web\n const platformMethodsRef = rnw.usePlatformMethods(viewProps)\n const setRef = rnw.useMergeRefs(hostRef, platformMethodsRef, forwardedRef)\n viewProps.ref = setRef\n if (props.href != null && hrefAttrs != null) {\n const { download, rel, target } = hrefAttrs\n if (download != null) {\n viewProps.download = download\n }\n if (rel != null) {\n viewProps.rel = rel\n }\n if (typeof target === 'string') {\n viewProps.target = target.charAt(0) !== '_' ? '_' + target : target\n }\n }\n } else {\n if (forwardedRef) {\n viewProps.ref = forwardedRef\n }\n }\n\n const attachPress = !!(\n (pseudos && pseudos.pressStyle) ||\n onPress ||\n onPressOut ||\n onPressIn ||\n onClick\n )\n const attachHover =\n isWeb &&\n !isTouchDevice &&\n !!((pseudos && pseudos.hoverStyle) || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave)\n\n // check presence to prevent reparenting bugs, allows for onPress={x ? function : undefined} usage\n // while avoiding reparenting...\n // once proper reparenting is supported, we can remove this and use that...\n const shouldAttach =\n internal.current.hasEverHadEvents ||\n attachPress ||\n attachHover ||\n 'pressStyle' in props ||\n 'onPress' in props ||\n 'onPressIn' in props ||\n 'onPressOut' in props ||\n (isWeb &&\n ('hoverStyle' in props ||\n 'onClick' in props ||\n 'onHoverIn' in props ||\n 'onHoverOut' in props ||\n 'onMouseEnter' in props ||\n 'onMouseLeave' in props))\n\n // never remove events as we wrap in a div (for now, may be able to remove..)\n if (shouldAttach) {\n internal.current.hasEverHadEvents = true\n }\n\n const unPress = useCallback(() => {\n if (!internal.current!.isMounted) return\n set({\n press: false,\n pressIn: false,\n })\n }, [])\n\n const events = shouldAttach\n ? {\n ...(!isWeb && {\n // non web\n onPressOut: (e) => {\n unPress()\n onPressOut?.(e)\n },\n }),\n ...(isWeb &&\n !isTouchDevice && {\n onMouseEnter:\n attachHover || attachPress\n ? (e) => {\n let next: Partial<typeof state> = {}\n if (attachHover) {\n next.hover = true\n }\n if (state.pressIn) {\n next.press = true\n }\n if (Object.keys(next).length) {\n set(next)\n }\n onHoverIn?.(e)\n onMouseEnter?.(e)\n }\n : undefined,\n onMouseLeave:\n attachHover || attachPress\n ? (e) => {\n let next: Partial<typeof state> = {}\n mouseUps.add(unPress)\n if (attachHover) {\n next.hover = false\n }\n if (state.pressIn) {\n next.press = false\n next.pressIn = false\n }\n if (Object.keys(next).length) {\n set(next)\n }\n onHoverOut?.(e)\n onMouseLeave?.(e)\n }\n : undefined,\n }),\n onMouseDown: attachPress\n ? (e) => {\n set({\n press: true,\n pressIn: true,\n })\n onPressIn?.(e)\n onMouseDown?.(e)\n }\n : (onPressIn as any),\n onClick: attachPress\n ? (e) => {\n // this caused issue with next.js passing href\n // e.preventDefault()\n onPress?.(e)\n onClick?.(e)\n unPress()\n onPressOut?.(e)\n }\n : (onPressOut as any),\n }\n : null\n\n if (events) {\n if (typeof ViewComponent !== 'string') {\n // TODO once we do the above we can then rely entirely on pressStyle returned here isntead of above pressStyle logic\n const [pressProps] = usePressable({\n disabled,\n hitSlop,\n onPressIn: events.onMouseDown,\n onPressOut: events.onPressOut,\n onPress: events.onClick,\n })\n Object.assign(viewProps, pressProps)\n } else {\n Object.assign(viewProps, events)\n }\n }\n\n const childEls = spacedChildren({\n children,\n space,\n flexDirection: props.flexDirection || defaultProps?.flexDirection,\n isZStack: isZStack,\n })\n\n let content: any\n\n // replicate react-native-web's `createElement`\n if (isWeb && rnw) {\n const domProps = rnw.createDOMProps(viewProps)\n const className =\n domProps.className && domProps.className !== viewProps.className\n ? `${domProps.className} ${viewProps.className}`\n : viewProps.className\n Object.assign(viewProps, domProps)\n viewProps.className = className\n content = createElement(ViewComponent, viewProps, childEls)\n } else {\n content = createElement(ViewComponent, viewProps, childEls)\n }\n\n const shouldWrapTextAncestor = isWeb && isText && !hasTextAncestor\n if (shouldWrapTextAncestor) {\n // from react-native-web\n // @ts-ignore\n content = createElement(TextAncestorContext.Provider, { value: true }, content)\n }\n\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n viewProps['debug'] = true\n console.log('\uD83E\uDD5A props in:', props)\n console.log('\uD83E\uDD5A props out:', viewProps)\n console.log(props.onClick?.toString())\n // prettier-ignore\n console.log('\uD83E\uDD5A etc:', { shouldAttach, ViewComponent, viewProps, styles, pseudos, content, childEls })\n // only on browser because node expands it huge\n if (isWeb) {\n console.log('\uD83E\uDD5A component info', { staticConfig, tamaguiConfig })\n }\n }\n }\n\n return (\n <>\n {features}\n {content}\n </>\n )\n })\n\n // Once configuration is run and all components are registered\n // get default props + className and analyze styles\n onConfiguredOnce((conf) => {\n tamaguiConfig = conf\n initialTheme = conf.themes[conf.defaultTheme || Object.keys(conf.themes)[0]]\n const next = getSplitStyles(staticConfig.defaultProps, staticConfig, initialTheme, true)\n if (isWeb) {\n if (next.classNames) {\n defaultsClassName += next.classNames + ' '\n }\n defaultsClassName += addStylesUsingClassname([next.style, next.pseudos])\n } else {\n if (!hasWarnedOnce) {\n hasWarnedOnce = true\n console.log('\u26A0\uFE0F we need to account for default styles for media queries')\n }\n }\n // @ts-ignore\n component.defaultProps = {\n ...next.viewProps,\n ...component.defaultProps,\n }\n if (process.env.NODE_ENV === 'development') {\n if (staticConfig.defaultProps?.debug) {\n console.log('tamagui debug component:', next, defaultsClassName, component.defaultProps)\n }\n }\n })\n\n component['staticConfig'] = {\n validStyles: validStyleProps,\n ...staticConfig,\n }\n\n const res = component as any as StaticComponent<A, void>\n\n // add extractable HoC\n res['extractable'] = (Component: any) => {\n Component['staticConfig'] = extendStaticConfig(res, {\n neverFlatten: true,\n defaultProps: Component.defaultProps,\n })\n return Component\n }\n\n return res\n}\n\nlet hasWarnedOnce = false\n\n// dont used styled() here to avoid circular deps\n// keep inline to avoid circular deps\n\nexport const Spacer = createComponent<{ size?: number | SpaceTokens; flex?: boolean | number }>({\n defaultProps: {\n ...stackDefaultStyles,\n size: true,\n },\n variants: {\n size: {\n '...size': (size, { tokens }) => {\n size = size == true ? '$true' : size\n return {\n width: tokens.size[size] ?? size,\n height: tokens.size[size] ?? size,\n }\n },\n },\n\n direction: {\n horizontal: {\n height: 0,\n },\n vertical: {\n width: 0,\n },\n },\n },\n})\n\nexport function spacedChildren({\n isZStack,\n children,\n space,\n flexDirection,\n}: {\n isZStack?: boolean\n children: any\n space?: any\n flexDirection?: ViewStyle['flexDirection']\n}) {\n if (!space && !isZStack) {\n return children\n }\n const childrenList = Children.toArray(children)\n const len = childrenList.length\n if (len === 1) {\n return children\n }\n const next: any[] = []\n for (const [index, child] of childrenList.entries()) {\n if (child === null || child === undefined) {\n continue\n }\n\n const key = `${child?.['key'] ?? index}`\n\n next.push(<Fragment key={key}>{isZStack ? <Absolute>{child}</Absolute> : child}</Fragment>)\n\n // allows for custom visually hidden components that dont insert spacing\n if (child?.['type']?.['isVisuallyHidden']) {\n continue\n }\n\n if (index !== len - 1) {\n if (space) {\n next.push(\n <Spacer\n key={`${key}_spacer`}\n // @ts-ignore TODO\n direction={\n flexDirection === 'row' || flexDirection === 'row-reverse' ? 'horizontal' : 'vertical'\n }\n size={space}\n />\n )\n }\n }\n }\n return next\n}\n\n// for now not so \"tamagui-y\"\nconst Absolute = ({ children }) => <View style={sheet.fullscreen}>{children}</View>\nconst sheet = StyleSheet.create({\n fullscreen: {\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n },\n})\n"],
|
|
5
|
+
"mappings": ";;AAAA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAQA;AACA;AAEO,MAAM,WAAW,IAAI;AAE5B,IAAI,OAAO,aAAa,aAAa;AACnC,WAAS,iBAAiB,WAAW,MAAM;AACzC,aAAS,QAAQ,CAAC,MAAM;AACxB,aAAS;AAAA;AAAA;AAMN,yBACL,UACA;AACA,MAAI;AACJ,MAAI,YAAY,UAAU;AACxB,mBAAe;AAAA,SACV;AACL,mBAAe,kBAAkB;AAAA;AAGnC,QAAM,EAAE,WAAW,aAAa,QAAQ,aAAa;AACrD,QAAM,kBAAkB,eAAe;AAGvC,MAAI,eAAe;AACnB,MAAI;AAGJ,MAAI;AACJ,MAAI,oBAAoB;AACxB,MAAI;AAIJ,QAAM,YAAY,WAAoB,CAAC,OAAY,iBAAiB;AAClE,UAAM,cAAc;AACpB,UAAM,WAAW,YAAY,OAAO,EAAE;AACtC,UAAM,UAAU,WAAW;AAC3B,UAAM,CAAC,OAAO,QAAQ,SAAS,MAAO;AAAA,MACpC,OAAO;AAAA,MACP,OAAO;AAAA,MACP,SAAS;AAAA,MACT,OAAO,QAAQ;AAAA;AAEjB,UAAM,MAAM,wBAAC,SACX,KAAK,CAAC,SAAS;AACb,iBAAW,OAAO,MAAM;AACtB,YAAI,KAAK,SAAS,KAAK,MAAM;AAC3B,iBAAO,KAAK,SAAS;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M;AAAA,GAAa,WAAlD;AACjB,MAAM,QAAQ,WAAW,OAAO;AAAA,EAC9B,YAAY;AAAA,IACV,UAAU;AAAA,IACV,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/createFont.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { validateFont } from "./helpers/validate";
|
|
3
4
|
const createFont = /* @__PURE__ */ __name((font) => {
|
|
5
|
+
if (process.env.NODE_ENV === "development") {
|
|
6
|
+
validateFont(font);
|
|
7
|
+
}
|
|
4
8
|
const sizeKeys = Object.keys(font.size);
|
|
5
9
|
for (const key in font) {
|
|
6
10
|
if (key === "size" || key === "family")
|
package/dist/createFont.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/createFont.ts"],
|
|
4
|
-
"sourcesContent": ["import { GenericFont } from './types'\n\nexport const createFont = <A extends GenericFont>(font: A): A => {\n // fills in any missing values based on size keys being standard\n const sizeKeys = Object.keys(font.size)\n\n for (const key in font) {\n if (key === 'size' || key === 'family') continue\n const section = font[key]\n const keys = Object.keys(section)\n\n // fill with first filled in value to start\n let fillVal = section[keys[0]]\n\n for (const sKey of sizeKeys) {\n if (!(sKey in section)) {\n section[sKey] = fillVal\n } else {\n // if exists, set as the fillVal\n fillVal = section[sKey]\n }\n }\n }\n\n return Object.freeze(font)\n}\n"],
|
|
5
|
-
"mappings": ";;
|
|
4
|
+
"sourcesContent": ["import { validateFont } from './helpers/validate'\nimport { GenericFont } from './types'\n\nexport const createFont = <A extends GenericFont>(font: A): A => {\n if (process.env.NODE_ENV === 'development') {\n validateFont(font)\n }\n\n // fills in any missing values based on size keys being standard\n const sizeKeys = Object.keys(font.size)\n\n for (const key in font) {\n if (key === 'size' || key === 'family') continue\n const section = font[key]\n const keys = Object.keys(section)\n\n // fill with first filled in value to start\n let fillVal = section[keys[0]]\n\n for (const sKey of sizeKeys) {\n if (!(sKey in section)) {\n section[sKey] = fillVal\n } else {\n // if exists, set as the fillVal\n fillVal = section[sKey]\n }\n }\n }\n\n return Object.freeze(font)\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAGO,MAAM,aAAa,wBAAwB,SAAe;AAC/D,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,iBAAa;AAAA;AAIf,QAAM,WAAW,OAAO,KAAK,KAAK;AAElC,aAAW,OAAO,MAAM;AACtB,QAAI,QAAQ,UAAU,QAAQ;AAAU;AACxC,UAAM,UAAU,KAAK;AACrB,UAAM,OAAO,OAAO,KAAK;AAGzB,QAAI,UAAU,QAAQ,KAAK;AAE3B,eAAW,QAAQ,UAAU;AAC3B,UAAI,CAAE,SAAQ,UAAU;AACtB,gBAAQ,QAAQ;AAAA,aACX;AAEL,kBAAU,QAAQ;AAAA;AAAA;AAAA;AAKxB,SAAO,OAAO,OAAO;AAAA,GA1BG;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/createTamagui.js
CHANGED
|
@@ -3,6 +3,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
3
3
|
import { getStyleRules } from "@tamagui/helpers";
|
|
4
4
|
import { Variable, createVariable, isVariable } from "./createVariable";
|
|
5
5
|
import { createTamaguiProvider } from "./helpers/createTamaguiProvider";
|
|
6
|
+
import { validateConfig } from "./helpers/validate";
|
|
6
7
|
import { configureMedia } from "./hooks/useMedia";
|
|
7
8
|
let conf;
|
|
8
9
|
const getHasConfigured = /* @__PURE__ */ __name(() => !!conf, "getHasConfigured");
|
|
@@ -17,6 +18,11 @@ const onConfiguredOnce = /* @__PURE__ */ __name((cb) => {
|
|
|
17
18
|
}, "onConfiguredOnce");
|
|
18
19
|
const PREFIX = `theme--`;
|
|
19
20
|
function createTamagui(config) {
|
|
21
|
+
if (process.env.NODE_ENV === "development") {
|
|
22
|
+
if (!config["parsed"]) {
|
|
23
|
+
validateConfig(config);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
20
26
|
if (conf) {
|
|
21
27
|
console.warn("Called createTamagui twice! Should never do so");
|
|
22
28
|
}
|
|
@@ -104,6 +110,7 @@ ${vars}
|
|
|
104
110
|
themeConfig,
|
|
105
111
|
themeParsed,
|
|
106
112
|
tokensParsed,
|
|
113
|
+
parsed: true,
|
|
107
114
|
getCSS() {
|
|
108
115
|
return `${themeConfig.css}
|
|
109
116
|
${[...getStyleRules()].join("\n")}`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/createTamagui.ts"],
|
|
4
|
-
"sourcesContent": ["import { getStyleRules } from '@tamagui/helpers'\n\nimport { Variable, createVariable, isVariable } from './createVariable'\nimport { createTamaguiProvider } from './helpers/createTamaguiProvider'\nimport { configureMedia } from './hooks/useMedia'\nimport {\n CreateTamaguiConfig,\n GenericTamaguiConfig,\n MediaQueryKey,\n TamaguiInternalConfig,\n TamaguiProviderProps,\n} from './types'\n\nexport type CreateTamaguiProps = TamaguiProviderProps &\n // we omit and re-declare it because we need to allow instantation types to be flexible\n // user then re-defines the types after createTamagui returns the typed object they want\n Omit<GenericTamaguiConfig, 'themes'> & {\n themes: {\n [key: string]: {\n [key: string]: string | number | Variable\n }\n }\n // for ssr/native, will default to active\n mediaQueryDefaultActive?: MediaQueryKey[]\n }\n\nlet conf: TamaguiInternalConfig | null\n\nexport const getHasConfigured = () => !!conf\nexport const getTamaguiConfig = () => conf!\n\ntype ConfigListener = (conf: TamaguiInternalConfig) => void\nconst configListeners = new Set<ConfigListener>()\nexport const onConfiguredOnce = (cb: ConfigListener) => {\n if (conf) {\n cb(conf)\n } else {\n configListeners.add(cb)\n }\n}\n\nconst PREFIX = `theme--`\n\nexport function createTamagui<Conf extends CreateTamaguiProps>(\n config: Conf\n): Conf extends CreateTamaguiConfig<infer A, infer B, infer C, infer D>\n ? TamaguiInternalConfig<A, B, C, D>\n : unknown {\n // test env loads a few times as it runs diff tests\n if (conf) {\n console.warn('Called createTamagui twice! Should never do so')\n // throw new Error(`#000 createTamagui called twice`)\n }\n\n configureMedia({\n queries: config.media as any,\n defaultActive: config.mediaQueryDefaultActive,\n })\n\n // TODO can avoid some of this CSS creation on native\n const themeConfig = (() => {\n let cssRules: string[] = []\n\n // tokens\n let tokenRule = `:root {`\n const varsByValue = new Map<string, Variable>()\n const addVar = (v: Variable) => {\n varsByValue[v.val] = v\n const rule = `--${v.name}:${typeof v.val === 'number' ? `${v.val}px` : v.val};`\n tokenRule += rule\n }\n\n for (const key in config.tokens) {\n for (const skey in config.tokens[key]) {\n const val = config.tokens[key][skey]\n if (key === 'font') {\n for (const fkey in val) {\n if (fkey === 'family') {\n addVar(val[fkey])\n } else {\n for (const fskey in val[fkey]) {\n addVar(val[fkey][fskey])\n }\n }\n }\n } else {\n addVar(val)\n }\n }\n }\n cssRules.push(`${tokenRule}\\n}`)\n\n // themes\n for (const themeName in config.themes) {\n // to allow using the same theme with diff names, be sure we don't mutate!\n config.themes[themeName] = { ...config.themes[themeName] }\n const theme = config.themes[themeName]\n let vars = ''\n for (const themeKey in theme) {\n const val = theme[themeKey]\n const getVariableCSS = (inv: any) => {\n const v = varsByValue[inv] ?? inv\n return isVariable(v) ? `--${themeKey}:var(--${v.name});` : `--${themeKey}:${v};`\n }\n vars += getVariableCSS(val)\n // TODO sanity check is necessary\n // make everything a variable that gets put into css\n if (!isVariable(val)) {\n theme[themeKey] = createVariable({\n name: themeKey,\n val,\n })\n }\n }\n\n const [themeClassName, parentName] = themeName.includes('-')\n ? themeName.split('-')\n : [themeName, '']\n // tiny hack for now assuming light/dark are typical parentName\n const oppositeName = parentName === 'dark' ? 'light' : 'dark'\n const cssParentSel = parentName ? `.${PREFIX}${parentName}` : ''\n const cssChildSel = `.${PREFIX}${themeClassName}`\n const cssSel = `${cssParentSel} ${cssChildSel}`\n // we need to force specificity\n const cssRule = `${cssSel}, .${PREFIX}${oppositeName} ${cssSel} {\\n${vars}\\n}`\n cssRules.push(cssRule)\n }\n\n Object.freeze(cssRules)\n\n return {\n cssRules,\n css: cssRules.join('\\n'),\n }\n })()\n\n // faster lookups token keys become $keys to match input\n const tokensParsed: any = parseTokens(config.tokens)\n // all themes should match key and we just need variable name\n // TODO once w react native we'd want to have a reverse lookup back to value\n const themeParsed: any = {}\n const firstKey = Object.keys(config.themes)[0]\n for (const key in config.themes[firstKey]) {\n // themeParsed[`$${key}`] = config.themes[firstKey][key]\n const val = config.themes[firstKey][key].val\n themeParsed[`$${key}`] = new Variable({ val, name: key })\n }\n\n const next: TamaguiInternalConfig = {\n // @ts-ignore\n shorthands: {},\n ...config,\n Provider: createTamaguiProvider({\n defaultTheme: 'light',\n ...config,\n }),\n themeConfig,\n themeParsed,\n tokensParsed,\n getCSS() {\n return `${themeConfig.css}\\n${[...getStyleRules()].join('\\n')}`\n },\n }\n conf = next\n\n if (configListeners.size) {\n configListeners.forEach((cb) => cb(next))\n configListeners.clear()\n }\n\n // @ts-expect-error\n return next\n}\n\nexport function getThemeParentClassName(themeName?: string | null) {\n return `theme-parent ${themeName ? `${PREFIX}${themeName}` : ''}`\n}\n\nconst parseTokens = (tokens: any) => {\n const res: any = {}\n for (const key in tokens) {\n res[key] = {}\n if (key === 'font') {\n for (const family in tokens.font) {\n const obj = {}\n res.font[`$${family}`] = obj\n for (const attrKey in tokens.font[family]) {\n const attr = tokens.font[family][attrKey]\n if (attrKey === 'family') {\n obj[attrKey] = attr\n continue\n }\n obj[attrKey] = Object.keys(attr).reduce((acc, cur) => {\n acc[`$${cur}`] = attr[cur]\n return acc\n }, {})\n }\n }\n continue\n }\n for (const skey in tokens[key]) {\n res[key][`$${skey}`] = tokens[key][skey]\n }\n }\n\n return res\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA;AAEA;AACA;AACA;AAsBA,IAAI;AAEG,MAAM,mBAAmB,6BAAM,CAAC,CAAC,MAAR;AACzB,MAAM,mBAAmB,6BAAM,MAAN;AAGhC,MAAM,kBAAkB,IAAI;AACrB,MAAM,mBAAmB,wBAAC,OAAuB;AACtD,MAAI,MAAM;AACR,OAAG;AAAA,SACE;AACL,oBAAgB,IAAI;AAAA;AAAA,GAJQ;AAQhC,MAAM,SAAS;AAER,uBACL,QAGU;
|
|
4
|
+
"sourcesContent": ["import { getStyleRules } from '@tamagui/helpers'\n\nimport { Variable, createVariable, isVariable } from './createVariable'\nimport { createTamaguiProvider } from './helpers/createTamaguiProvider'\nimport { validateConfig } from './helpers/validate'\nimport { configureMedia } from './hooks/useMedia'\nimport {\n CreateTamaguiConfig,\n GenericTamaguiConfig,\n MediaQueryKey,\n TamaguiInternalConfig,\n TamaguiProviderProps,\n} from './types'\n\nexport type CreateTamaguiProps = TamaguiProviderProps &\n // we omit and re-declare it because we need to allow instantation types to be flexible\n // user then re-defines the types after createTamagui returns the typed object they want\n Omit<GenericTamaguiConfig, 'themes'> & {\n themes: {\n [key: string]: {\n [key: string]: string | number | Variable\n }\n }\n // for ssr/native, will default to active\n mediaQueryDefaultActive?: MediaQueryKey[]\n }\n\nlet conf: TamaguiInternalConfig | null\n\nexport const getHasConfigured = () => !!conf\nexport const getTamaguiConfig = () => conf!\n\ntype ConfigListener = (conf: TamaguiInternalConfig) => void\nconst configListeners = new Set<ConfigListener>()\nexport const onConfiguredOnce = (cb: ConfigListener) => {\n if (conf) {\n cb(conf)\n } else {\n configListeners.add(cb)\n }\n}\n\nconst PREFIX = `theme--`\n\nexport function createTamagui<Conf extends CreateTamaguiProps>(\n config: Conf\n): Conf extends CreateTamaguiConfig<infer A, infer B, infer C, infer D>\n ? TamaguiInternalConfig<A, B, C, D>\n : unknown {\n if (process.env.NODE_ENV === 'development') {\n // config is re-run by the @tamagui/static, dont double validate\n if (!config['parsed']) {\n validateConfig(config)\n }\n }\n // test env loads a few times as it runs diff tests\n if (conf) {\n console.warn('Called createTamagui twice! Should never do so')\n // throw new Error(`#000 createTamagui called twice`)\n }\n\n configureMedia({\n queries: config.media as any,\n defaultActive: config.mediaQueryDefaultActive,\n })\n\n // TODO can avoid some of this CSS creation on native\n const themeConfig = (() => {\n let cssRules: string[] = []\n\n // tokens\n let tokenRule = `:root {`\n const varsByValue = new Map<string, Variable>()\n const addVar = (v: Variable) => {\n varsByValue[v.val] = v\n const rule = `--${v.name}:${typeof v.val === 'number' ? `${v.val}px` : v.val};`\n tokenRule += rule\n }\n\n for (const key in config.tokens) {\n for (const skey in config.tokens[key]) {\n const val = config.tokens[key][skey]\n if (key === 'font') {\n for (const fkey in val) {\n if (fkey === 'family') {\n addVar(val[fkey])\n } else {\n for (const fskey in val[fkey]) {\n addVar(val[fkey][fskey])\n }\n }\n }\n } else {\n addVar(val)\n }\n }\n }\n cssRules.push(`${tokenRule}\\n}`)\n\n // themes\n for (const themeName in config.themes) {\n // to allow using the same theme with diff names, be sure we don't mutate!\n config.themes[themeName] = { ...config.themes[themeName] }\n const theme = config.themes[themeName]\n let vars = ''\n for (const themeKey in theme) {\n const val = theme[themeKey]\n const getVariableCSS = (inv: any) => {\n const v = varsByValue[inv] ?? inv\n return isVariable(v) ? `--${themeKey}:var(--${v.name});` : `--${themeKey}:${v};`\n }\n vars += getVariableCSS(val)\n // TODO sanity check is necessary\n // make everything a variable that gets put into css\n if (!isVariable(val)) {\n theme[themeKey] = createVariable({\n name: themeKey,\n val,\n })\n }\n }\n\n const [themeClassName, parentName] = themeName.includes('-')\n ? themeName.split('-')\n : [themeName, '']\n // tiny hack for now assuming light/dark are typical parentName\n const oppositeName = parentName === 'dark' ? 'light' : 'dark'\n const cssParentSel = parentName ? `.${PREFIX}${parentName}` : ''\n const cssChildSel = `.${PREFIX}${themeClassName}`\n const cssSel = `${cssParentSel} ${cssChildSel}`\n // we need to force specificity\n const cssRule = `${cssSel}, .${PREFIX}${oppositeName} ${cssSel} {\\n${vars}\\n}`\n cssRules.push(cssRule)\n }\n\n Object.freeze(cssRules)\n\n return {\n cssRules,\n css: cssRules.join('\\n'),\n }\n })()\n\n // faster lookups token keys become $keys to match input\n const tokensParsed: any = parseTokens(config.tokens)\n // all themes should match key and we just need variable name\n // TODO once w react native we'd want to have a reverse lookup back to value\n const themeParsed: any = {}\n const firstKey = Object.keys(config.themes)[0]\n for (const key in config.themes[firstKey]) {\n // themeParsed[`$${key}`] = config.themes[firstKey][key]\n const val = config.themes[firstKey][key].val\n themeParsed[`$${key}`] = new Variable({ val, name: key })\n }\n\n const next: TamaguiInternalConfig = {\n // @ts-ignore\n shorthands: {},\n ...config,\n Provider: createTamaguiProvider({\n defaultTheme: 'light',\n ...config,\n }),\n themeConfig,\n themeParsed,\n tokensParsed,\n parsed: true,\n getCSS() {\n return `${themeConfig.css}\\n${[...getStyleRules()].join('\\n')}`\n },\n }\n conf = next\n\n if (configListeners.size) {\n configListeners.forEach((cb) => cb(next))\n configListeners.clear()\n }\n\n // @ts-expect-error\n return next\n}\n\nexport function getThemeParentClassName(themeName?: string | null) {\n return `theme-parent ${themeName ? `${PREFIX}${themeName}` : ''}`\n}\n\nconst parseTokens = (tokens: any) => {\n const res: any = {}\n for (const key in tokens) {\n res[key] = {}\n if (key === 'font') {\n for (const family in tokens.font) {\n const obj = {}\n res.font[`$${family}`] = obj\n for (const attrKey in tokens.font[family]) {\n const attr = tokens.font[family][attrKey]\n if (attrKey === 'family') {\n obj[attrKey] = attr\n continue\n }\n obj[attrKey] = Object.keys(attr).reduce((acc, cur) => {\n acc[`$${cur}`] = attr[cur]\n return acc\n }, {})\n }\n }\n continue\n }\n for (const skey in tokens[key]) {\n res[key][`$${skey}`] = tokens[key][skey]\n }\n }\n\n return res\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAEA;AACA;AACA;AACA;AAsBA,IAAI;AAEG,MAAM,mBAAmB,6BAAM,CAAC,CAAC,MAAR;AACzB,MAAM,mBAAmB,6BAAM,MAA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A0IT,iCAAiC,WAA2B;AACjE,SAAO,gBAAgB,YAAY,GAAG,SAAS,cAAc;AAAA;AAD/C;AAIhB,MAAM,cAAc,wBAAC,WAAgB;AACnC,QAAM,MAAW;AACjB,aAAW,OAAO,QAAQ;AACxB,QAAI,OAAO;AACX,QAAI,QAAQ,QAAQ;AAClB,iBAAW,UAAU,OAAO,MAAM;AAChC,cAAM,MAAM;AACZ,YAAI,KAAK,IAAI,YAAY;AACzB,mBAAW,WAAW,OAAO,KAAK,SAAS;AACzC,gBAAM,OAAO,OAAO,KAAK,QAAQ;AACjC,cAAI,YAAY,UAAU;AACxB,gBAAI,WAAW;AACf;AAAA;AAEF,cAAI,WAAW,OAAO,KAAK,MAAM,OAAO,CAAC,KAAK,QAAQ;AACpD,gBAAI,IAAI,SAAS,KAAK;AACtB,mBAAO;AAAA,aACN;AAAA;AAAA;AAGP;AAAA;AAEF,eAAW,QAAQ,OAAO,MAAM;AAC9B,UAAI,KAAK,IAAI,UAAU,OAAO,KAAK;AAAA;AAAA;AAIvC,SAAO;AAAA,GA3BW;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/createTokens.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
import { createVariable } from "./createVariable";
|
|
4
|
+
import { validateTokens } from "./helpers/validate";
|
|
4
5
|
function createTokens(tokens) {
|
|
6
|
+
if (process.env.NODE_ENV === "development") {
|
|
7
|
+
validateTokens(tokens);
|
|
8
|
+
}
|
|
5
9
|
return setupTokens(tokens);
|
|
6
10
|
}
|
|
7
11
|
__name(createTokens, "createTokens");
|
package/dist/createTokens.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/createTokens.ts"],
|
|
4
|
-
"sourcesContent": ["import { Variable, createVariable } from './createVariable'\nimport { CreateTokens } from './types'\n\n// tokens.color.dark.red ===>{ var: `color-dark-red`, val: '' }\n\nexport function createTokens<T extends CreateTokens>(tokens: T): MakeTokens<T> {\n return setupTokens(tokens) as any\n}\n\nfunction setupTokens(tokens: any) {\n return mapTokensToVariables(tokens)\n}\n\nexport const mapTokensToVariables = (\n tokens: CreateTokens,\n parentPath = ''\n): CreateTokens<Variable> => {\n const res = {}\n for (const key in tokens) {\n const val = tokens[key]\n const name = parentPath ? `${parentPath}-${key}` : key\n if (val && typeof val === 'object') {\n res[key] = mapTokensToVariables(tokens[key], name)\n } else {\n res[key] = createVariable({ val, name })\n }\n }\n // @ts-expect-error\n return res\n}\n\n// verbose but gives us nice types...\ntype MakeTokens<T> = T extends {\n font: {\n [key in infer A]: {\n size: infer B\n lineHeight: infer C\n letterSpacing: infer D\n weight: infer Z\n family: infer Y\n }\n }\n color: infer E\n space: infer F\n size: infer G\n radius: infer H\n zIndex: infer J\n}\n ? {\n font: {\n [key in A]: {\n size: {\n [key in keyof B]: Variable\n }\n lineHeight: {\n [key in keyof C]: Variable\n }\n letterSpacing: {\n [key in keyof D]: Variable\n }\n weight: {\n [key in keyof Z]: Variable\n }\n family: Y\n }\n }\n color: {\n [key in keyof E]: Variable\n }\n space: {\n [key in keyof F]: Variable\n }\n size: {\n [key in keyof G]: Variable\n }\n radius: {\n [key in keyof H]: Variable\n }\n zIndex: {\n [key in keyof J]: Variable\n }\n }\n : never\n"],
|
|
5
|
-
"mappings": ";;AAAA;AAKO,sBAA8C,QAA0B;AAC7E,SAAO,YAAY;AAAA;
|
|
4
|
+
"sourcesContent": ["import { Variable, createVariable } from './createVariable'\nimport { validateTokens } from './helpers/validate'\nimport { CreateTokens } from './types'\n\n// tokens.color.dark.red ===> { var: `color-dark-red`, val: '' }\n\nexport function createTokens<T extends CreateTokens>(tokens: T): MakeTokens<T> {\n if (process.env.NODE_ENV === 'development') {\n validateTokens(tokens)\n }\n\n return setupTokens(tokens) as any\n}\n\nfunction setupTokens(tokens: any) {\n return mapTokensToVariables(tokens)\n}\n\nexport const mapTokensToVariables = (\n tokens: CreateTokens,\n parentPath = ''\n): CreateTokens<Variable> => {\n const res = {}\n for (const key in tokens) {\n const val = tokens[key]\n const name = parentPath ? `${parentPath}-${key}` : key\n if (val && typeof val === 'object') {\n res[key] = mapTokensToVariables(tokens[key], name)\n } else {\n res[key] = createVariable({ val, name })\n }\n }\n // @ts-expect-error\n return res\n}\n\n// verbose but gives us nice types...\ntype MakeTokens<T> = T extends {\n font: {\n [key in infer A]: {\n size: infer B\n lineHeight: infer C\n letterSpacing: infer D\n weight: infer Z\n family: infer Y\n }\n }\n color: infer E\n space: infer F\n size: infer G\n radius: infer H\n zIndex: infer J\n}\n ? {\n font: {\n [key in A]: {\n size: {\n [key in keyof B]: Variable\n }\n lineHeight: {\n [key in keyof C]: Variable\n }\n letterSpacing: {\n [key in keyof D]: Variable\n }\n weight: {\n [key in keyof Z]: Variable\n }\n family: Y\n }\n }\n color: {\n [key in keyof E]: Variable\n }\n space: {\n [key in keyof F]: Variable\n }\n size: {\n [key in keyof G]: Variable\n }\n radius: {\n [key in keyof H]: Variable\n }\n zIndex: {\n [key in keyof J]: Variable\n }\n }\n : never\n"],
|
|
5
|
+
"mappings": ";;AAAA;AACA;AAKO,sBAA8C,QAA0B;AAC7E,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,mBAAe;AAAA;AAGjB,SAAO,YAAY;AAAA;AALL;AAQhB,qBAAqB,QAAa;AAChC,SAAO,qBAAqB;AAAA;AADrB;AAIF,MAAM,uBAAuB,wBAClC,QACA,aAAa,OACc;AAC3B,QAAM,MAAM;AACZ,aAAW,OAAO,QAAQ;AACxB,UAAM,MAAM,OAAO;AACnB,UAAM,OAAO,aAAa,GAAG,cAAc,QAAQ;AACnD,QAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,UAAI,OAAO,qBAAqB,OAAO,MAAM;AAAA,WACxC;AACL,UAAI,OAAO,eAAe,EAAE,KAAK;AAAA;AAAA;AAIrC,SAAO;AAAA,GAf2B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/createVariable.js
CHANGED
|
@@ -7,6 +7,9 @@ class Variable {
|
|
|
7
7
|
this.name = name;
|
|
8
8
|
this.variable = isWeb ? `var(--${name})` : this.val;
|
|
9
9
|
}
|
|
10
|
+
toString() {
|
|
11
|
+
return isWeb ? this.variable : this.val;
|
|
12
|
+
}
|
|
10
13
|
}
|
|
11
14
|
__name(Variable, "Variable");
|
|
12
15
|
const createVariable = /* @__PURE__ */ __name((props) => new Variable(props), "createVariable");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/createVariable.ts"],
|
|
4
|
-
"sourcesContent": ["import { isWeb } from './constants/platform'\n\nexport class Variable {\n name: string\n val: string | number\n variable: string | number\n\n constructor({ val, name }: VariableIn) {\n // converting to px breaks rn\n this.val = val //typeof val === 'string' ? val : `${val}px`\n this.name = name\n this.variable = isWeb ? `var(--${name})` : this.val\n }\n}\n\ntype VariableIn = { val: string | number; name: string }\n\nexport const createVariable = (props: VariableIn) => new Variable(props)\n\nexport function isVariable(v: Variable | any): v is Variable {\n return v instanceof Variable\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA;AAEO,eAAe;AAAA,EAKpB,YAAY,EAAE,KAAK,QAAoB;AAErC,SAAK,MAAM;AACX,SAAK,OAAO;AACZ,SAAK,WAAW,QAAQ,SAAS,UAAU,KAAK;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { isWeb } from './constants/platform'\n\nexport class Variable {\n name: string\n val: string | number\n variable: string | number\n\n constructor({ val, name }: VariableIn) {\n // converting to px breaks rn\n this.val = val //typeof val === 'string' ? val : `${val}px`\n this.name = name\n this.variable = isWeb ? `var(--${name})` : this.val\n }\n\n toString() {\n return isWeb ? this.variable : this.val\n }\n}\n\ntype VariableIn = { val: string | number; name: string }\n\nexport const createVariable = (props: VariableIn) => new Variable(props)\n\nexport function isVariable(v: Variable | any): v is Variable {\n return v instanceof Variable\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAEO,eAAe;AAAA,EAKpB,YAAY,EAAE,KAAK,QAAoB;AAErC,SAAK,MAAM;AACX,SAAK,OAAO;AACZ,SAAK,WAAW,QAAQ,SAAS,UAAU,KAAK;AAAA;AAAA,EAGlD,WAAW;AACT,WAAO,QAAQ,KAAK,WAAW,KAAK;AAAA;AAAA;AAbjC;AAmBA,MAAM,iBAAiB,wBAAC,UAAsB,IAAI,SAAS,QAApC;AAEvB,oBAAoB,GAAkC;AAC3D,SAAO,aAAa;AAAA;AADN;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -17,7 +17,6 @@ const getSplitStyles = /* @__PURE__ */ __name((props, staticConfig, theme, isSpl
|
|
|
17
17
|
const validStyleProps = staticConfig.isText ? stylePropsText : validStyles;
|
|
18
18
|
const viewProps = {};
|
|
19
19
|
const style = [];
|
|
20
|
-
const blacklistProps = isSplittingDefaultProps ? blacklistDefaultProps : blacklistFinalProps;
|
|
21
20
|
let pseudos = null;
|
|
22
21
|
let cur = null;
|
|
23
22
|
let classNames = null;
|
|
@@ -96,7 +95,7 @@ const getSplitStyles = /* @__PURE__ */ __name((props, staticConfig, theme, isSpl
|
|
|
96
95
|
cur[key] = val;
|
|
97
96
|
continue;
|
|
98
97
|
}
|
|
99
|
-
if (!
|
|
98
|
+
if (!staticConfig.variants || !(key in staticConfig.variants)) {
|
|
100
99
|
viewProps[key] = val;
|
|
101
100
|
}
|
|
102
101
|
}
|
|
@@ -134,17 +133,6 @@ const getSubStyle = /* @__PURE__ */ __name((styleIn, staticConfig, theme, props)
|
|
|
134
133
|
fixNativeShadow(styleOut);
|
|
135
134
|
return styleOut;
|
|
136
135
|
}, "getSubStyle");
|
|
137
|
-
const blacklistDefaultProps = {
|
|
138
|
-
...validStyles,
|
|
139
|
-
...stylePropsText
|
|
140
|
-
};
|
|
141
|
-
const blacklistFinalProps = {
|
|
142
|
-
...blacklistDefaultProps,
|
|
143
|
-
tag: true,
|
|
144
|
-
debug: true,
|
|
145
|
-
space: true,
|
|
146
|
-
hitSlop: true
|
|
147
|
-
};
|
|
148
136
|
const mapTransformKeys = {
|
|
149
137
|
x: "translateX",
|
|
150
138
|
y: "translateY"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/helpers/getSplitStyles.tsx"],
|
|
4
|
-
"sourcesContent": ["import {\n AllRules,\n stylePropsText,\n stylePropsTransform,\n validStyles,\n validStylesPseudo,\n} from '@tamagui/helpers'\nimport { ViewStyle } from 'react-native'\n\nimport { isWeb } from '../constants/platform'\nimport { mediaQueryConfig } from '../hooks/useMedia'\nimport { StaticConfigParsed, ThemeObject } from '../types'\nimport { createMediaStyle } from './createMediaStyle'\nimport { fixNativeShadow } from './fixNativeShadow'\nimport { getStylesAtomic } from './getStylesAtomic'\nimport { insertStyleRule } from './insertStyleRule'\n\nexport type SplitStyles = ReturnType<typeof getSplitStyles>\n\n// TODO run over this, should be able to cut it down quite a bit\n\nexport const getSplitStyles = (\n props: { [key: string]: any },\n staticConfig: StaticConfigParsed,\n theme: ThemeObject,\n isSplittingDefaultProps?: boolean\n) => {\n const validStyleProps = staticConfig.isText ? stylePropsText : validStyles\n const viewProps: Record<string, any> = {}\n const style: any[] = []\n
|
|
5
|
-
"mappings": ";;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA;AACA;AAEA;AACA;AACA;AACA;AAMO,MAAM,iBAAiB,wBAC5B,OACA,cACA,OACA,4BACG;AACH,QAAM,kBAAkB,aAAa,SAAS,iBAAiB;AAC/D,QAAM,YAAiC;AACvC,QAAM,QAAe;
|
|
4
|
+
"sourcesContent": ["import {\n AllRules,\n stylePropsText,\n stylePropsTransform,\n validStyles,\n validStylesPseudo,\n} from '@tamagui/helpers'\nimport { ViewStyle } from 'react-native'\n\nimport { isWeb } from '../constants/platform'\nimport { mediaQueryConfig } from '../hooks/useMedia'\nimport { StaticConfigParsed, ThemeObject } from '../types'\nimport { createMediaStyle } from './createMediaStyle'\nimport { fixNativeShadow } from './fixNativeShadow'\nimport { getStylesAtomic } from './getStylesAtomic'\nimport { insertStyleRule } from './insertStyleRule'\n\nexport type SplitStyles = ReturnType<typeof getSplitStyles>\n\n// TODO run over this, should be able to cut it down quite a bit\n\nexport const getSplitStyles = (\n props: { [key: string]: any },\n staticConfig: StaticConfigParsed,\n theme: ThemeObject,\n isSplittingDefaultProps?: boolean\n) => {\n const validStyleProps = staticConfig.isText ? stylePropsText : validStyles\n const viewProps: Record<string, any> = {}\n const style: any[] = []\n\n let pseudos: { hoverStyle?: ViewStyle; pressStyle?: ViewStyle } | null = null\n let cur: ViewStyle | null = null\n let classNames: string[] | null = null\n\n for (const keyInit in props) {\n // be sure to sync next few lines below to getSubStyle (*1)\n const valInit = props[keyInit]\n\n // media\n if (keyInit[0] === '$') {\n const mediaKey = keyInit.slice(1)\n\n if (!mediaQueryConfig[mediaKey]) {\n // this isn't a media key, pass through\n viewProps[keyInit] = valInit\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 const mediaProps = { ...props, ...valInit }\n // TODO media + hover\n const mediaStyle = getSubStyle(valInit, staticConfig, theme, props)\n const mediaStyles = getStylesAtomic(mediaStyle)\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n console.log('mediaStyles', keyInit, { mediaProps, mediaStyle, mediaStyles })\n }\n }\n for (const style of mediaStyles) {\n if (isWeb) {\n const out = createMediaStyle(style, mediaKey, mediaQueryConfig)\n classNames = classNames || []\n classNames.push(out.identifier)\n AllRules.add(out.styleRule)\n insertStyleRule(out.styleRule)\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.log('mediaProp', style.identifier, out, mediaProps, mediaStyle, mediaStyles)\n }\n } else {\n console.log('TODO native media style logic')\n }\n }\n continue\n }\n\n // pseudo\n if (validStylesPseudo[keyInit]) {\n if (!valInit) continue\n pseudos = pseudos || {}\n pseudos[keyInit] = getSubStyle(valInit, staticConfig, theme, props)\n continue\n }\n\n const out = staticConfig.propMapper(keyInit, valInit, theme, props)\n\n const expanded = out === true || !out ? [[keyInit, valInit]] : Object.entries(out)\n\n for (const [key, val] of expanded) {\n // const val = valueMap(valInit) ?? valInit\n const keyFirstChar = key[0]\n if (key === 'style' || (keyFirstChar === '_' && key.startsWith('_style'))) {\n if (cur) {\n // process last\n fixNativeShadow(cur)\n style.push(cur)\n cur = null\n }\n fixNativeShadow(val)\n style.push(val)\n continue\n }\n // expand flex so it merged with flexShrink etc properly\n // TODO this shouldn't be here...\n if (key === 'flex') {\n cur = cur || {}\n // see spec for flex shorthand https://developer.mozilla.org/en-US/docs/Web/CSS/flex\n // TODO this fixed a behavior but need to find / document / test\n Object.assign(cur, {\n flexGrow: val,\n flexShrink: 1,\n })\n continue\n }\n if (!isWeb && key === 'pointerEvents') {\n viewProps[key] = val\n continue\n }\n if (validStyleProps[key]) {\n // transforms\n if (key in stylePropsTransform) {\n cur = cur || {}\n mergeTransform(cur, key, val)\n continue\n }\n cur = cur || {}\n cur[key] = val\n continue\n }\n\n // pass to view props\n if (!staticConfig.variants || !(key in staticConfig.variants)) {\n viewProps[key] = val\n }\n }\n }\n // push last style\n if (cur) {\n fixNativeShadow(cur)\n style.push(cur)\n }\n\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n console.log(' \uD83E\uDD5A splitProps:', { props, viewProps, style })\n }\n }\n\n return {\n viewProps,\n style,\n pseudos,\n classNames,\n }\n}\n\nconst getSubStyle = (\n styleIn: Object,\n staticConfig: StaticConfigParsed,\n theme: ThemeObject,\n props: any\n): ViewStyle => {\n const styleOut: ViewStyle = {}\n for (const key in styleIn) {\n // be sure to sync next few lines below to loop above (*1)\n const val = styleIn[key]\n const out = staticConfig.propMapper(key, val, theme, props)\n const expanded = out === true || !out ? [[key, val]] : Object.entries(out)\n for (const [skey, sval] of expanded) {\n // const sval = valueMap(valInit)\n if (skey in stylePropsTransform) {\n mergeTransform(styleOut, skey, sval)\n } else {\n styleOut[skey] = sval\n }\n }\n }\n fixNativeShadow(styleOut)\n return styleOut\n}\n\nconst mapTransformKeys = {\n x: 'translateX',\n y: 'translateY',\n}\n\nconst mergeTransform = (obj: ViewStyle, key: string, val: any) => {\n const transform: any[] = obj.transform\n ? Array.isArray(obj.transform)\n ? obj.transform\n : [obj.transform]\n : []\n transform.push({ [mapTransformKeys[key] || key]: val })\n obj.transform = transform\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA;AACA;AAEA;AACA;AACA;AACA;AAMO,MAAM,iBAAiB,wBAC5B,OACA,cACA,OACA,4BACG;AACH,QAAM,kBAAkB,aAAa,SAAS,iBAAiB;AAC/D,QAAM,YAAiC;AACvC,QAAM,QAAe;AAErB,MAAI,UAAqE;AACzE,MAAI,MAAwB;AAC5B,MAAI,aAA8B;AAElC,aAAW,WAAW,OAAO;AAE3B,UAAM,UAAU,MAAM;AAGtB,QAAI,QAAQ,OAAO,KAAK;AACtB,YAAM,WAAW,QAAQ,MAAM;AAE/B,UAAI,CAAC,iBAAiB,WAAW;AAE/B,kBAAU,WAAW;AACrB;AAAA;AAMF,YAAM,aAAa,KAAK,UAAU;AAElC,YAAM,aAAa,YAAY,SAAS,cAAc,OAAO;AAC7D,YAAM,cAAc,gBAAgB;AACpC,UAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,YAAI,MAAM,UAAU;AAClB,kBAAQ,IAAI,eAAe,SAAS,EAAE,YAAY,YAAY;AAAA;AAAA;AAGlE,iBAAW,UAAS,aAAa;AAC/B,YAAI,OAAO;AACT,gBAAM,OAAM,iBAAiB,QAAO,UAAU;AAC9C,uBAAa,cAAc;AAC3B,qBAAW,KAAK,KAAI;AACpB,mBAAS,IAAI,KAAI;AACjB,0BAAgB,KAAI;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Q,IAAI,0BAAmB,EAAE,OAAO,WAAW;AAAA;AAAA;AAIvD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA,GArI0B;AAyI9B,MAAM,cAAc,wBAClB,SACA,cACA,OACA,UACc;AACd,QAAM,WAAsB;AAC5B,aAAW,OAAO,SAAS;AAEzB,UAAM,MAAM,QAAQ;AACpB,UAAM,MAAM,aAAa,WAAW,KAAK,KAAK,OAAO;AACrD,UAAM,WAAW,QAAQ,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,QAAQ,OAAO,QAAQ;AACtE,eAAW,CAAC,MAAM,SAAS,UAAU;AAEnC,UAAI,QAAQ,qBAAqB;AAC/B,uBAAe,UAAU,MAAM;AAAA,aAC1B;AACL,iBAAS,QAAQ;AAAA;AAAA;AAAA;AAIvB,kBAAgB;AAChB,SAAO;AAAA,GAtBW;AAyBpB,MAAM,mBAAmB;AAAA,EACvB,GAAG;AAAA,EACH,GAAG;AAAA;AAGL,MAAM,iBAAiB,wBAAC,KAAgB,KAAa,QAAa;AAChE,QAAM,YAAmB,IAAI,YACzB,MAAM,QAAQ,IAAI,aAChB,IAAI,YACJ,CAAC,IAAI,aACP;AACJ,YAAU,KAAK,GAAG,iBAAiB,QAAQ,MAAM;AACjD,MAAI,YAAY;AAAA,GAPK;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { isValidElement } from "react";
|
|
4
|
+
const isTamaguiComponent = /* @__PURE__ */ __name((child) => {
|
|
5
|
+
return isValidElement(child) && child.type["staticConfig"]?.parsed;
|
|
6
|
+
}, "isTamaguiComponent");
|
|
7
|
+
export {
|
|
8
|
+
isTamaguiComponent
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=isComponent.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/helpers/isComponent.tsx"],
|
|
4
|
+
"sourcesContent": ["import { isValidElement } from 'react'\n\nexport const isTamaguiComponent = (child: any) => {\n return isValidElement(child) && child.type['staticConfig']?.parsed\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAEO,MAAM,qBAAqB,wBAAC,UAAe;AAChD,SAAO,eAAe,UAAU,MAAM,KAAK,iBAAiB;AAAA,GAD5B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { isValidElement } from "react";
|
|
4
|
+
const isTamaguiComponent = /* @__PURE__ */ __name((child) => {
|
|
5
|
+
return isValidElement(child) && !!child.type["staticConfig"]?.parsed;
|
|
6
|
+
}, "isTamaguiComponent");
|
|
7
|
+
export {
|
|
8
|
+
isTamaguiComponent
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=isTamaguiComponent.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/helpers/isTamaguiComponent.tsx"],
|
|
4
|
+
"sourcesContent": ["import React, { isValidElement } from 'react'\n\nexport const isTamaguiComponent = (child: any): child is React.ReactElement => {\n return isValidElement(child) && !!child.type['staticConfig']?.parsed\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAEO,MAAM,qBAAqB,wBAAC,UAA4C;AAC7E,SAAO,eAAe,UAAU,CAAC,CAAC,MAAM,KAAK,iBAAiB;AAAA,GAD9B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { isValidElement } from "react";
|
|
4
|
+
const isTamaguiElement = /* @__PURE__ */ __name((child) => {
|
|
5
|
+
return isValidElement(child) && !!child.type["staticConfig"]?.parsed;
|
|
6
|
+
}, "isTamaguiElement");
|
|
7
|
+
export {
|
|
8
|
+
isTamaguiElement
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=isTamaguiElement.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/helpers/isTamaguiElement.tsx"],
|
|
4
|
+
"sourcesContent": ["import React, { isValidElement } from 'react'\n\nexport const isTamaguiElement = (child: any): child is React.ReactElement => {\n return isValidElement(child) && !!child.type['staticConfig']?.parsed\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAEO,MAAM,mBAAmB,wBAAC,UAA4C;AAC3E,SAAO,eAAe,UAAU,CAAC,CAAC,MAAM,KAAK,iBAAiB;AAAA,GADhC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import ow from "@tamagui/ow";
|
|
4
|
+
const validateConfig = /* @__PURE__ */ __name((conf) => {
|
|
5
|
+
if (!conf) {
|
|
6
|
+
console.warn("no conf?");
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
ow(conf, validConfig);
|
|
11
|
+
} catch (err) {
|
|
12
|
+
console.log("Given config:\n", JSON.stringify(conf, null, 2));
|
|
13
|
+
throw err;
|
|
14
|
+
}
|
|
15
|
+
}, "validateConfig");
|
|
16
|
+
const validConfig = ow.object.exactShape({
|
|
17
|
+
defaultTheme: ow.optional.string,
|
|
18
|
+
disableRootThemeClass: ow.optional.boolean,
|
|
19
|
+
shorthands: ow.optional.object.valuesOfType(ow.string),
|
|
20
|
+
themes: ow.object.valuesOfType(ow.object),
|
|
21
|
+
tokens: ow.object.valuesOfType(ow.object),
|
|
22
|
+
media: ow.object.valuesOfType(ow.object)
|
|
23
|
+
});
|
|
24
|
+
const validFont = ow.object.exactShape({
|
|
25
|
+
family: ow.string,
|
|
26
|
+
size: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
27
|
+
lineHeight: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
28
|
+
weight: ow.object.nonEmpty.valuesOfType(ow.string),
|
|
29
|
+
letterSpacing: ow.object.nonEmpty.valuesOfType(ow.number)
|
|
30
|
+
});
|
|
31
|
+
const validTokens = ow.object.exactShape({
|
|
32
|
+
font: ow.object.valuesOfType(validFont),
|
|
33
|
+
size: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
34
|
+
space: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
35
|
+
zIndex: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
36
|
+
radius: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
37
|
+
color: ow.object.nonEmpty.valuesOfType(ow.string)
|
|
38
|
+
});
|
|
39
|
+
const validateTokens = /* @__PURE__ */ __name((tokens) => {
|
|
40
|
+
try {
|
|
41
|
+
ow(tokens, validTokens);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
console.log("Given tokens:\n", JSON.stringify(tokens, null, 2));
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
}, "validateTokens");
|
|
47
|
+
const validateFont = /* @__PURE__ */ __name((font) => {
|
|
48
|
+
try {
|
|
49
|
+
ow(font, validFont);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
console.log("Given font:\n", JSON.stringify(font, null, 2));
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
}, "validateFont");
|
|
55
|
+
export {
|
|
56
|
+
validateConfig,
|
|
57
|
+
validateFont,
|
|
58
|
+
validateTokens
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=validate.js.map
|