@tamagui/core 1.0.1-rc.7 → 1.0.1-rc.9
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/Pressability.js +32 -0
- package/dist/cjs/Pressability.js.map +7 -0
- package/dist/cjs/Pressability.native.js +32 -0
- package/dist/cjs/Pressability.native.js.map +7 -0
- package/dist/cjs/ThemeContext.js +30 -0
- package/dist/cjs/ThemeContext.js.map +7 -0
- package/dist/cjs/ThemeManager.js +211 -0
- package/dist/cjs/ThemeManager.js.map +7 -0
- package/dist/cjs/conf.js +70 -0
- package/dist/cjs/conf.js.map +7 -0
- package/dist/cjs/constants/platform.js +4 -10
- package/dist/cjs/constants/platform.js.map +2 -2
- package/dist/cjs/constants/rnw.native.js +28 -0
- package/dist/cjs/constants/rnw.native.js.map +7 -0
- package/dist/cjs/contexts/ButtonInsideButtonContext.js.map +1 -1
- package/dist/cjs/createTamagui.js +2 -0
- package/dist/cjs/createTamagui.js.map +2 -2
- package/dist/cjs/defaultComponentState.js +2 -0
- package/dist/cjs/defaultComponentState.js.map +7 -0
- package/dist/cjs/helpers/assignNativePropsToWeb.js.map +1 -1
- package/dist/cjs/helpers/assignNativePropsToWeb.native.js.map +1 -1
- package/dist/cjs/helpers/calc.js.map +2 -2
- package/dist/cjs/helpers/createShallowUpdate.js +9 -12
- package/dist/cjs/helpers/createShallowUpdate.js.map +1 -1
- package/dist/cjs/helpers/createTamaguiProvider.js +65 -0
- package/dist/cjs/helpers/createTamaguiProvider.js.map +7 -0
- package/dist/cjs/helpers/cssHash.js +51 -0
- package/dist/cjs/helpers/cssHash.js.map +7 -0
- package/dist/cjs/helpers/expandStyle.test.js +10 -0
- package/dist/cjs/helpers/expandStyle.test.js.map +7 -0
- package/dist/cjs/helpers/getFont.js +2 -6
- package/dist/cjs/helpers/getFont.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.js +14 -9
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/getStackSize.js.map +1 -1
- package/dist/cjs/helpers/insertStyleRule.js +60 -27
- package/dist/cjs/helpers/insertStyleRule.js.map +3 -3
- package/dist/cjs/helpers/nativeGestureHandler.native.js +19 -0
- package/dist/cjs/helpers/nativeGestureHandler.native.js.map +7 -0
- package/dist/cjs/helpers/normalizeValueWithProperty.js +3 -3
- package/dist/cjs/helpers/normalizeValueWithProperty.js.map +2 -2
- package/dist/cjs/helpers/startTransition.js +1 -4
- package/dist/cjs/helpers/startTransition.js.map +2 -2
- package/dist/cjs/helpers/themeable.js +2 -2
- package/dist/cjs/helpers/themeable.js.map +2 -2
- package/dist/cjs/helpers/wrapThemeManagerContext.js +37 -0
- package/dist/cjs/helpers/wrapThemeManagerContext.js.map +7 -0
- package/dist/cjs/hooks/useConstant.js +0 -3
- package/dist/cjs/hooks/useConstant.js.map +2 -2
- package/dist/cjs/hooks/useElementLayout.js +1 -1
- package/dist/cjs/hooks/useElementLayout.js.map +2 -2
- package/dist/cjs/hooks/useFeatures.js +201 -0
- package/dist/cjs/hooks/useFeatures.js.map +7 -0
- package/dist/cjs/hooks/useIsMounted.js.map +1 -1
- package/dist/cjs/hooks/useIsSSR.js +6 -10
- package/dist/cjs/hooks/useIsSSR.js.map +2 -2
- package/dist/cjs/hooks/useMedia.js +5 -0
- package/dist/cjs/hooks/useMedia.js.map +2 -2
- package/dist/cjs/hooks/usePressable.js.map +1 -1
- package/dist/cjs/hooks/usePrevious.js +1 -0
- package/dist/cjs/hooks/usePrevious.js.map +7 -0
- package/dist/cjs/hooks/useUnmountEffect.js.map +1 -1
- package/dist/cjs/styled.js +12 -0
- package/dist/cjs/styled.js.map +2 -2
- package/dist/cjs/views/TextAncestorContext.js +44 -0
- package/dist/cjs/views/TextAncestorContext.js.map +7 -0
- package/dist/cjs/views/ThemeInverse.js +20 -21
- package/dist/cjs/views/ThemeInverse.js.map +2 -2
- package/dist/cjs/views/ThemeReset.js +5 -10
- package/dist/cjs/views/ThemeReset.js.map +3 -3
- package/dist/esm/Pressability.js +7 -0
- package/dist/esm/Pressability.js.map +7 -0
- package/dist/esm/Pressability.native.js +7 -0
- package/dist/esm/Pressability.native.js.map +7 -0
- package/dist/esm/ThemeContext.js +6 -0
- package/dist/esm/ThemeContext.js.map +7 -0
- package/dist/esm/ThemeManager.js +185 -0
- package/dist/esm/ThemeManager.js.map +7 -0
- package/dist/esm/conf.js +39 -0
- package/dist/esm/conf.js.map +7 -0
- package/dist/esm/constants/platform.js +3 -7
- package/dist/esm/constants/platform.js.map +2 -2
- package/dist/esm/constants/rnw.native.js +5 -0
- package/dist/esm/constants/rnw.native.js.map +7 -0
- package/dist/esm/contexts/ButtonInsideButtonContext.js.map +1 -1
- package/dist/esm/createTamagui.js +7 -1
- package/dist/esm/createTamagui.js.map +2 -2
- package/dist/esm/defaultComponentState.js +1 -0
- package/dist/esm/defaultComponentState.js.map +7 -0
- package/dist/esm/helpers/assignNativePropsToWeb.js.map +1 -1
- package/dist/esm/helpers/assignNativePropsToWeb.native.js.map +1 -1
- package/dist/esm/helpers/calc.js.map +2 -2
- package/dist/esm/helpers/createShallowUpdate.js +9 -12
- package/dist/esm/helpers/createShallowUpdate.js.map +1 -1
- package/dist/esm/helpers/createTamaguiProvider.js +38 -0
- package/dist/esm/helpers/createTamaguiProvider.js.map +7 -0
- package/dist/esm/helpers/cssHash.js +27 -0
- package/dist/esm/helpers/cssHash.js.map +7 -0
- package/dist/esm/helpers/expandStyle.test.js +9 -0
- package/dist/esm/helpers/expandStyle.test.js.map +7 -0
- package/dist/esm/helpers/getFont.js +2 -6
- package/dist/esm/helpers/getFont.js.map +2 -2
- package/dist/esm/helpers/getSplitStyles.js +16 -10
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/getStackSize.js.map +1 -1
- package/dist/esm/helpers/insertStyleRule.js +58 -26
- package/dist/esm/helpers/insertStyleRule.js.map +3 -3
- package/dist/esm/helpers/nativeGestureHandler.native.js +2 -0
- package/dist/esm/helpers/nativeGestureHandler.native.js.map +7 -0
- package/dist/esm/helpers/normalizeValueWithProperty.js +3 -3
- package/dist/esm/helpers/normalizeValueWithProperty.js.map +2 -2
- package/dist/esm/helpers/startTransition.js.map +1 -1
- package/dist/esm/helpers/themeable.js +2 -2
- package/dist/esm/helpers/themeable.js.map +2 -2
- package/dist/esm/helpers/wrapThemeManagerContext.js +11 -0
- package/dist/esm/helpers/wrapThemeManagerContext.js.map +7 -0
- package/dist/esm/hooks/useConstant.js +1 -4
- package/dist/esm/hooks/useConstant.js.map +2 -2
- package/dist/esm/hooks/useElementLayout.js +1 -1
- package/dist/esm/hooks/useElementLayout.js.map +2 -2
- package/dist/esm/hooks/useFeatures.js +174 -0
- package/dist/esm/hooks/useFeatures.js.map +7 -0
- package/dist/esm/hooks/useIsMounted.js.map +1 -1
- package/dist/esm/hooks/useIsSSR.js +8 -12
- package/dist/esm/hooks/useIsSSR.js.map +2 -2
- package/dist/esm/hooks/useMedia.js +4 -0
- package/dist/esm/hooks/useMedia.js.map +2 -2
- package/dist/esm/hooks/usePressable.js.map +1 -1
- package/dist/esm/hooks/usePrevious.js +1 -0
- package/dist/esm/hooks/usePrevious.js.map +7 -0
- package/dist/esm/hooks/useUnmountEffect.js.map +1 -1
- package/dist/esm/styled.js +12 -0
- package/dist/esm/styled.js.map +2 -2
- package/dist/esm/views/TextAncestorContext.js +15 -0
- package/dist/esm/views/TextAncestorContext.js.map +7 -0
- package/dist/esm/views/ThemeInverse.js +15 -20
- package/dist/esm/views/ThemeInverse.js.map +2 -2
- package/dist/esm/views/ThemeReset.js +4 -6
- package/dist/esm/views/ThemeReset.js.map +2 -2
- package/package.json +10 -11
- package/src/createTamagui.ts +8 -1
- package/src/helpers/getSplitStyles.tsx +17 -9
- package/src/helpers/insertStyleRule.tsx +70 -38
- package/src/helpers/normalizeValueWithProperty.ts +3 -3
- package/src/helpers/themeable.tsx +3 -3
- package/src/hooks/useElementLayout.tsx +1 -1
- package/src/hooks/useMedia.tsx +3 -0
- package/src/styled.tsx +15 -0
- package/types/helpers/insertStyleRule.d.ts +2 -1
- package/types/helpers/themeable.d.ts +1 -1
- package/types/hooks/useMedia.d.ts +1 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useElementLayout.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { useEvent } from '@tamagui/use-event'\nimport { RefObject } from 'react'\n\nimport { getBoundingClientRect } from '../helpers/getBoundingClientRect'\nimport { getRect } from '../helpers/getRect'\n\nconst LayoutHandlers = new WeakMap<Element, Function>()\n\nexport type LayoutValue = {\n x: number\n y: number\n width: number\n height: number\n left: number\n top: number\n}\n\nexport type LayoutEvent = {\n nativeEvent: {\n layout: LayoutValue\n target: any\n }\n timeStamp: number\n}\n\nlet resizeObserver: ResizeObserver | null = null\n\nif (typeof window !== 'undefined' && 'ResizeObserver' in window) {\n resizeObserver = new ResizeObserver((entries) => {\n for (const { target } of entries) {\n const onLayout = LayoutHandlers.get(target)\n if (typeof onLayout !== 'function') return\n measureLayout(target as HTMLElement, null, (x, y, width, height, left, top) => {\n onLayout({\n nativeEvent: {\n layout: { x, y, width, height, left, top },\n target,\n },\n timeStamp: Date.now(),\n })\n })\n }\n })\n}\n\nexport const measureLayout = (\n node: HTMLElement,\n relativeTo: HTMLElement | null,\n callback: Function\n) => {\n const relativeNode = relativeTo || node?.parentNode\n if (relativeNode instanceof HTMLElement) {\n setTimeout(() => {\n const relativeRect = getBoundingClientRect(relativeNode)!\n const { height, left, top, width } = getRect(node)!\n const x = left - relativeRect.left\n const y = top - relativeRect.top\n callback(x, y, width, height, left, top)\n }, 0)\n }\n}\n\nconst idFn = () => {}\n\nexport function useElementLayout(\n ref: RefObject<Element>,\n onLayout?: ((e: LayoutEvent) => void) | null\n) {\n const hasLayoutEvent = !!onLayout\n const onLayoutEvent = useEvent(onLayout || idFn)\n\n // Observing is done in a separate effect to avoid this effect running\n // when 'onLayout' changes.\n useIsomorphicLayoutEffect(() => {\n if (!
|
|
5
|
-
"mappings": "AAAA,SAAS,iCAAiC;AAC1C,SAAS,gBAAgB;AAGzB,SAAS,6BAA6B;AACtC,SAAS,eAAe;AAExB,MAAM,iBAAiB,oBAAI,QAA2B;AAmBtD,IAAI,iBAAwC;AAE5C,IAAI,OAAO,WAAW,eAAe,oBAAoB,QAAQ;AAC/D,mBAAiB,IAAI,eAAe,CAAC,YAAY;AAC/C,eAAW,EAAE,OAAO,KAAK,SAAS;AAChC,YAAM,WAAW,eAAe,IAAI,MAAM;AAC1C,UAAI,OAAO,aAAa;AAAY;AACpC,oBAAc,QAAuB,MAAM,CAAC,GAAG,GAAG,OAAO,QAAQ,MAAM,QAAQ;AAC7E,iBAAS;AAAA,UACP,aAAa;AAAA,YACX,QAAQ,EAAE,GAAG,GAAG,OAAO,QAAQ,MAAM,IAAI;AAAA,YACzC;AAAA,UACF;AAAA,UACA,WAAW,KAAK,IAAI;AAAA,QACtB,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH;AAEO,MAAM,gBAAgB,CAC3B,MACA,YACA,aACG;AACH,QAAM,eAAe,eAAc,6BAAM;AACzC,MAAI,wBAAwB,aAAa;AACvC,eAAW,MAAM;AACf,YAAM,eAAe,sBAAsB,YAAY;AACvD,YAAM,EAAE,QAAQ,MAAM,KAAK,MAAM,IAAI,QAAQ,IAAI;AACjD,YAAM,IAAI,OAAO,aAAa;AAC9B,YAAM,IAAI,MAAM,aAAa;AAC7B,eAAS,GAAG,GAAG,OAAO,QAAQ,MAAM,GAAG;AAAA,IACzC,GAAG,CAAC;AAAA,EACN;AACF;AAEA,MAAM,OAAO,MAAM;AAAC;AAEb,SAAS,iBACd,KACA,UACA;AACA,QAAM,iBAAiB,CAAC,CAAC;AACzB,QAAM,gBAAgB,SAAS,YAAY,IAAI;AAI/C,4BAA0B,MAAM;AAC9B,QAAI,
|
|
4
|
+
"sourcesContent": ["import { useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { useEvent } from '@tamagui/use-event'\nimport { RefObject } from 'react'\n\nimport { getBoundingClientRect } from '../helpers/getBoundingClientRect'\nimport { getRect } from '../helpers/getRect'\n\nconst LayoutHandlers = new WeakMap<Element, Function>()\n\nexport type LayoutValue = {\n x: number\n y: number\n width: number\n height: number\n left: number\n top: number\n}\n\nexport type LayoutEvent = {\n nativeEvent: {\n layout: LayoutValue\n target: any\n }\n timeStamp: number\n}\n\nlet resizeObserver: ResizeObserver | null = null\n\nif (typeof window !== 'undefined' && 'ResizeObserver' in window) {\n resizeObserver = new ResizeObserver((entries) => {\n for (const { target } of entries) {\n const onLayout = LayoutHandlers.get(target)\n if (typeof onLayout !== 'function') return\n measureLayout(target as HTMLElement, null, (x, y, width, height, left, top) => {\n onLayout({\n nativeEvent: {\n layout: { x, y, width, height, left, top },\n target,\n },\n timeStamp: Date.now(),\n })\n })\n }\n })\n}\n\nexport const measureLayout = (\n node: HTMLElement,\n relativeTo: HTMLElement | null,\n callback: Function\n) => {\n const relativeNode = relativeTo || node?.parentNode\n if (relativeNode instanceof HTMLElement) {\n setTimeout(() => {\n const relativeRect = getBoundingClientRect(relativeNode)!\n const { height, left, top, width } = getRect(node)!\n const x = left - relativeRect.left\n const y = top - relativeRect.top\n callback(x, y, width, height, left, top)\n }, 0)\n }\n}\n\nconst idFn = () => {}\n\nexport function useElementLayout(\n ref: RefObject<Element>,\n onLayout?: ((e: LayoutEvent) => void) | null\n) {\n const hasLayoutEvent = !!onLayout\n const onLayoutEvent = useEvent(onLayout || idFn)\n\n // Observing is done in a separate effect to avoid this effect running\n // when 'onLayout' changes.\n useIsomorphicLayoutEffect(() => {\n if (!resizeObserver || !hasLayoutEvent) return\n const node = ref.current\n if (!node) return\n LayoutHandlers.set(node, onLayoutEvent)\n resizeObserver.observe(node)\n return () => {\n resizeObserver?.unobserve(node)\n }\n }, [ref, hasLayout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AI,CAAC;AAAM;AACX,mBAAe,IAAI,MAAM,aAAa;AACtC,mBAAe,QAAQ,IAAI;AAC3B,WAAO,MAAM;AACX,uDAAgB,UAAU;AAAA,IAC5B;AAAA,EACF,GAAG,CAAC,KAAK,cAAc,CAAC;AAC1B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { getConfig } from "../conf";
|
|
3
|
+
import { useIsomorphicLayoutEffect } from "../constants/platform";
|
|
4
|
+
import { getSubStyle } from "../helpers/getSplitStyles";
|
|
5
|
+
import { addMediaQueryListener, mediaState, removeMediaQueryListener } from "./useMedia";
|
|
6
|
+
const createDefinition = ({
|
|
7
|
+
Component,
|
|
8
|
+
propNames
|
|
9
|
+
}) => ({
|
|
10
|
+
isEnabled: (props) => propNames.some((name) => !!props[name]),
|
|
11
|
+
Component
|
|
12
|
+
});
|
|
13
|
+
let featureDefinitions = null;
|
|
14
|
+
let tamaguiConfig;
|
|
15
|
+
const useFeatures = (props, utils) => {
|
|
16
|
+
if (!featureDefinitions) {
|
|
17
|
+
featureDefinitions = loadFeatures();
|
|
18
|
+
}
|
|
19
|
+
const elements = [];
|
|
20
|
+
const enabled = {};
|
|
21
|
+
for (const name in featureDefinitions) {
|
|
22
|
+
const { isEnabled, Component } = featureDefinitions[name];
|
|
23
|
+
if (isEnabled(props) && Component) {
|
|
24
|
+
enabled[name] = true;
|
|
25
|
+
elements.push(/* @__PURE__ */ React.createElement(Component, {
|
|
26
|
+
key: name,
|
|
27
|
+
...props,
|
|
28
|
+
_utils: utils
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
elements,
|
|
34
|
+
enabled
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
function loadFeatures() {
|
|
38
|
+
return {
|
|
39
|
+
animation: loadAnimationFeature(),
|
|
40
|
+
mediaQuery: loadMediaQueryFeature()
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function loadAnimationFeature() {
|
|
44
|
+
tamaguiConfig = tamaguiConfig || getConfig();
|
|
45
|
+
return createDefinition({
|
|
46
|
+
Component: ({ _utils, ...props }) => {
|
|
47
|
+
const {
|
|
48
|
+
state,
|
|
49
|
+
useAnimations,
|
|
50
|
+
pseudos,
|
|
51
|
+
style: inStyle,
|
|
52
|
+
setStateShallow,
|
|
53
|
+
staticConfig,
|
|
54
|
+
theme,
|
|
55
|
+
onDidAnimate
|
|
56
|
+
} = _utils;
|
|
57
|
+
if (!useAnimations) {
|
|
58
|
+
console.error("no useAnimations hook provided");
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const propsWithAnimation = props;
|
|
62
|
+
const res = useAnimations(propsWithAnimation, {
|
|
63
|
+
state,
|
|
64
|
+
pseudos,
|
|
65
|
+
onDidAnimate,
|
|
66
|
+
staticConfig,
|
|
67
|
+
getStyle({ isExiting, isEntering, exitVariant, enterVariant } = {}) {
|
|
68
|
+
var _a, _b, _c, _d;
|
|
69
|
+
const style = inStyle || {};
|
|
70
|
+
const enterStyle = isEntering ? enterVariant && ((_a = staticConfig.variants) == null ? void 0 : _a[enterVariant]["true"]) ? getSubStyle("", (_b = staticConfig.variants) == null ? void 0 : _b[enterVariant]["true"], staticConfig, theme, props, state, tamaguiConfig) || pseudos.enterStyle : pseudos.enterStyle : null;
|
|
71
|
+
const exitStyle = isExiting ? exitVariant && ((_c = staticConfig.variants) == null ? void 0 : _c[exitVariant]["true"]) ? getSubStyle("", (_d = staticConfig.variants) == null ? void 0 : _d[exitVariant]["true"], staticConfig, theme, props, state, tamaguiConfig) || pseudos.exitStyle : pseudos.exitStyle : null;
|
|
72
|
+
ensureBaseHasDefaults(style, enterStyle, pseudos.hoverStyle, pseudos.focusStyle, pseudos.pressStyle, pseudos.pressStyle);
|
|
73
|
+
enterStyle && merge(style, enterStyle);
|
|
74
|
+
state.hover && pseudos.hoverStyle && merge(style, pseudos.hoverStyle);
|
|
75
|
+
state.focus && pseudos.focusStyle && merge(style, pseudos.focusStyle);
|
|
76
|
+
state.press && pseudos.pressStyle && merge(style, pseudos.pressStyle);
|
|
77
|
+
exitStyle && merge(style, exitStyle);
|
|
78
|
+
return style;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
useIsomorphicLayoutEffect(() => {
|
|
82
|
+
setStateShallow({
|
|
83
|
+
animation: res
|
|
84
|
+
});
|
|
85
|
+
}, [res]);
|
|
86
|
+
return null;
|
|
87
|
+
},
|
|
88
|
+
propNames: ["animation"]
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const defaults = {
|
|
92
|
+
left: 0,
|
|
93
|
+
right: 0,
|
|
94
|
+
top: 0,
|
|
95
|
+
bottom: 0,
|
|
96
|
+
opacity: 1,
|
|
97
|
+
translateX: 0,
|
|
98
|
+
translateY: 0,
|
|
99
|
+
skew: 0,
|
|
100
|
+
skewX: 0,
|
|
101
|
+
skewY: 0,
|
|
102
|
+
scale: 1,
|
|
103
|
+
rotate: "0deg",
|
|
104
|
+
rotateY: "0deg",
|
|
105
|
+
rotateX: "0deg"
|
|
106
|
+
};
|
|
107
|
+
function ensureBaseHasDefaults(base, ...pseudos) {
|
|
108
|
+
for (const pseudo of pseudos) {
|
|
109
|
+
if (!pseudo)
|
|
110
|
+
continue;
|
|
111
|
+
for (const key in pseudo) {
|
|
112
|
+
const val = pseudo[key];
|
|
113
|
+
if (key === "transform") {
|
|
114
|
+
for (const t of val) {
|
|
115
|
+
const tkey = Object.keys(t)[0];
|
|
116
|
+
const defaultVal = defaults[tkey];
|
|
117
|
+
const tDefaultVal = { [tkey]: defaultVal };
|
|
118
|
+
if (!base.transform) {
|
|
119
|
+
base.transform = [tDefaultVal];
|
|
120
|
+
} else {
|
|
121
|
+
if (!base.transform.find((x) => x[tkey])) {
|
|
122
|
+
base.transform.push(tDefaultVal);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
if (!(key in base)) {
|
|
128
|
+
base[key] = defaults[key];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function merge(base, next) {
|
|
135
|
+
if (!next.transform || !base.transform) {
|
|
136
|
+
Object.assign(base, next);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const { transform, ...rest } = next;
|
|
140
|
+
Object.assign(base, rest);
|
|
141
|
+
for (const t of transform) {
|
|
142
|
+
const key = Object.keys(t)[0];
|
|
143
|
+
const existing = base.transform.find((x) => key in x);
|
|
144
|
+
if (existing) {
|
|
145
|
+
existing[key] = t[key];
|
|
146
|
+
} else {
|
|
147
|
+
base.transform.push(t);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function loadMediaQueryFeature() {
|
|
152
|
+
const mediaPropNames = Object.keys(mediaState);
|
|
153
|
+
return createDefinition({
|
|
154
|
+
Component: (props) => {
|
|
155
|
+
const mediaKeys = mediaPropNames.filter((x) => x in props);
|
|
156
|
+
useIsomorphicLayoutEffect(() => {
|
|
157
|
+
for (const key of mediaKeys) {
|
|
158
|
+
addMediaQueryListener(key, props._utils.forceUpdate);
|
|
159
|
+
}
|
|
160
|
+
return () => {
|
|
161
|
+
for (const key of mediaKeys) {
|
|
162
|
+
removeMediaQueryListener(key, props._utils.forceUpdate);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}, [mediaKeys.join(",")]);
|
|
166
|
+
return null;
|
|
167
|
+
},
|
|
168
|
+
propNames: mediaPropNames
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
export {
|
|
172
|
+
useFeatures
|
|
173
|
+
};
|
|
174
|
+
//# sourceMappingURL=useFeatures.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/useFeatures.tsx"],
|
|
4
|
+
"sourcesContent": ["import React from 'react'\nimport { RefObject } from 'react'\nimport { View, ViewStyle } from 'react-native'\n\nimport { getConfig } from '../conf'\nimport { useIsomorphicLayoutEffect } from '../constants/platform'\nimport { getSubStyle } from '../helpers/getSplitStyles'\nimport {\n PseudoStyles,\n SplitStyleState,\n StaticConfigParsed,\n TamaguiComponentState,\n TamaguiInternalConfig,\n UseAnimationHook,\n UseAnimationProps,\n} from '../types'\nimport { addMediaQueryListener, mediaState, removeMediaQueryListener } from './useMedia'\n\ntype FeatureDefinition = {\n isEnabled: (props: any) => boolean\n Component: any\n}\n\ntype FeatureUtils = {\n forceUpdate: Function\n state: SplitStyleState\n setStateShallow: (next: Partial<TamaguiComponentState>) => void\n useAnimations?: UseAnimationHook\n pseudos: PseudoStyles\n style: ViewStyle | null | undefined\n staticConfig: StaticConfigParsed\n theme: any\n onDidAnimate?: () => void\n hostRef: RefObject<HTMLElement | View>\n}\n\nconst createDefinition = ({\n Component,\n propNames,\n}: {\n Component: (props: { _utils: FeatureUtils; [key: string]: any }) => void\n propNames: string[]\n}): FeatureDefinition => ({\n isEnabled: (props: any) => propNames.some((name) => !!props[name]),\n Component,\n})\n\nlet featureDefinitions: Record<string, FeatureDefinition> | null = null\nlet tamaguiConfig: TamaguiInternalConfig\n\ntype FeatureKeys = keyof ReturnType<typeof loadFeatures>\n\nexport const useFeatures = (props: any, utils?: FeatureUtils) => {\n if (!featureDefinitions) {\n featureDefinitions = loadFeatures()\n }\n const elements: JSX.Element[] = []\n const enabled: { [key in FeatureKeys]?: boolean } = {}\n for (const name in featureDefinitions) {\n const { isEnabled, Component } = featureDefinitions[name]\n if (isEnabled(props) && Component) {\n enabled[name] = true\n elements.push(<Component key={name} {...props} _utils={utils} />)\n }\n }\n return {\n elements,\n enabled,\n }\n}\n\nfunction loadFeatures() {\n return {\n // loads animations and sets state with the results\n animation: loadAnimationFeature(),\n\n // will update the parent whenever media query changes\n // no need on web, media queries are inserted and run in css\n mediaQuery: loadMediaQueryFeature(),\n } as const\n}\n\nfunction loadAnimationFeature() {\n tamaguiConfig = tamaguiConfig || getConfig()\n\n return createDefinition({\n Component: ({ _utils, ...props }) => {\n const {\n state,\n useAnimations,\n pseudos,\n style: inStyle,\n setStateShallow,\n staticConfig,\n theme,\n onDidAnimate,\n } = _utils\n\n if (!useAnimations) {\n console.error('no useAnimations hook provided')\n return null\n }\n\n // we always have .animation set\n const propsWithAnimation = props as UseAnimationProps\n\n const res = useAnimations(propsWithAnimation, {\n state,\n pseudos,\n onDidAnimate,\n staticConfig,\n getStyle({ isExiting, isEntering, exitVariant, enterVariant } = {}) {\n // we have to merge such that transforms keys all exist\n const style = inStyle || {}\n\n const enterStyle = isEntering\n ? enterVariant && staticConfig.variants?.[enterVariant]['true']\n ? getSubStyle(\n '',\n staticConfig.variants?.[enterVariant]['true'],\n staticConfig,\n theme,\n props,\n state,\n tamaguiConfig\n ) || pseudos.enterStyle\n : null || pseudos.enterStyle\n : null\n\n const exitStyle = isExiting\n ? exitVariant && staticConfig.variants?.[exitVariant]['true']\n ? getSubStyle(\n '',\n staticConfig.variants?.[exitVariant]['true'],\n staticConfig,\n theme,\n props,\n state,\n tamaguiConfig\n ) || pseudos.exitStyle\n : null || pseudos.exitStyle\n : null\n\n // if you have hoverStyle={{ scale: 1.1 }} and don't have scale set on the base style\n // no animation will run! this is really confusing. this will look at all variants,\n // and fill in base styles if they don't exist. eg:\n // input:\n // base: {}\n // hoverStyle: { scale: 2 }\n // enterStyle: { x: 100 }\n // output:\n // base: { x: 0, scale: 1 }\n ensureBaseHasDefaults(\n style,\n enterStyle,\n pseudos.hoverStyle,\n pseudos.focusStyle,\n pseudos.pressStyle,\n pseudos.pressStyle\n )\n\n enterStyle && merge(style, enterStyle)\n state.hover && pseudos.hoverStyle && merge(style, pseudos.hoverStyle)\n state.focus && pseudos.focusStyle && merge(style, pseudos.focusStyle)\n state.press && pseudos.pressStyle && merge(style, pseudos.pressStyle)\n exitStyle && merge(style, exitStyle)\n\n return style\n },\n //, delay\n })\n\n useIsomorphicLayoutEffect(() => {\n setStateShallow({\n animation: res,\n })\n }, [res])\n\n return null\n },\n propNames: ['animation'],\n })\n}\n\nconst defaults = {\n left: 0,\n right: 0,\n top: 0,\n bottom: 0,\n opacity: 1,\n translateX: 0,\n translateY: 0,\n skew: 0,\n skewX: 0,\n skewY: 0,\n scale: 1,\n rotate: '0deg',\n rotateY: '0deg',\n rotateX: '0deg',\n}\n\nfunction ensureBaseHasDefaults(base: ViewStyle, ...pseudos: (ViewStyle | null | undefined)[]) {\n for (const pseudo of pseudos) {\n if (!pseudo) continue\n for (const key in pseudo) {\n const val = pseudo[key]\n if (key === 'transform') {\n for (const t of val) {\n const tkey = Object.keys(t)[0]\n const defaultVal = defaults[tkey]\n const tDefaultVal = { [tkey]: defaultVal } as any\n if (!base.transform) {\n base.transform = [tDefaultVal]\n } else {\n if (!base.transform.find((x) => x[tkey])) {\n base.transform.push(tDefaultVal)\n }\n }\n }\n } else {\n if (!(key in base)) {\n base[key] = defaults[key]\n }\n }\n }\n }\n}\n\nfunction merge(base: ViewStyle, next: ViewStyle) {\n if (!next.transform || !base.transform) {\n Object.assign(base, next)\n return\n }\n const { transform, ...rest } = next\n Object.assign(base, rest)\n for (const t of transform) {\n const key = Object.keys(t)[0]\n const existing = base.transform.find((x) => key in x)\n if (existing) {\n existing[key] = t[key]\n } else {\n base.transform.push(t)\n }\n }\n}\n\nfunction loadMediaQueryFeature() {\n const mediaPropNames = Object.keys(mediaState)\n\n return createDefinition({\n Component: (props: any) => {\n const mediaKeys = mediaPropNames.filter((x) => x in props)\n\n useIsomorphicLayoutEffect(() => {\n for (const key of mediaKeys) {\n addMediaQueryListener(key, props._utils.forceUpdate)\n }\n return () => {\n for (const key of mediaKeys) {\n removeMediaQueryListener(key, props._utils.forceUpdate)\n }\n }\n }, [mediaKeys.join(',')])\n\n return null\n },\n propNames: mediaPropNames,\n })\n}\n\n// TODO\n// measureLayout: createDefinition({\n// Component: (props) => {\n// console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AW,OAAO,WAAW;AAC3B,gCAAsB,KAAK,MAAM,OAAO,WAAW;AAAA,QACrD;AACA,eAAO,MAAM;AACX,qBAAW,OAAO,WAAW;AAC3B,qCAAyB,KAAK,MAAM,OAAO,WAAW;AAAA,UACxD;AAAA,QACF;AAAA,MACF,GAAG,CAAC,UAAU,KAAK,GAAG,CAAC,CAAC;AAExB,aAAO;AAAA,IACT;AAAA,IACA,WAAW;AAAA,EACb,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useIsMounted.ts"],
|
|
4
4
|
"sourcesContent": ["import { useRef } from 'react'\n\nimport { useIsomorphicLayoutEffect } from '../constants/platform'\n\nexport function useIsMounted() {\n const isMounted = useRef(false)\n\n useIsomorphicLayoutEffect(() => {\n isMounted.current = true\n\n return () => {\n isMounted.current = false\n }\n }, [])\n\n return isMounted\n}\n"],
|
|
5
|
-
"mappings": "AAAA
|
|
5
|
+
"mappings": "AAAA;AAEA;AAEO,wBAAwB;AAC7B,QAAM,YAAY,OAAO,KAAK;AAE9B,4BAA0B,MAAM;AAC9B,cAAU,UAAU;AAEpB,WAAO,MAAM;AACX,gBAAU,UAAU;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
2
|
-
import {
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { isSSR, isWeb } from "../constants/platform";
|
|
3
3
|
import { startTransition } from "../helpers/startTransition";
|
|
4
|
-
const useIsSSR = (
|
|
5
|
-
const [val, setVal] = useState(
|
|
6
|
-
|
|
7
|
-
if (isWeb && !
|
|
8
|
-
|
|
4
|
+
const useIsSSR = () => {
|
|
5
|
+
const [val, setVal] = useState(isSSR);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (isWeb && !isSSR) {
|
|
8
|
+
startTransition(() => {
|
|
9
9
|
setVal(false);
|
|
10
|
-
}
|
|
11
|
-
startTransition(() => {
|
|
12
|
-
setVal(false);
|
|
13
|
-
});
|
|
14
|
-
}
|
|
10
|
+
});
|
|
15
11
|
}
|
|
16
12
|
}, []);
|
|
17
13
|
return val;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useIsSSR.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useState } from 'react'\n\nimport {
|
|
5
|
-
"mappings": "AAAA
|
|
4
|
+
"sourcesContent": ["import { useEffect, useState } from 'react'\n\nimport { isSSR, isWeb } from '../constants/platform'\nimport { startTransition } from '../helpers/startTransition'\n\n// because any change before first useEffect causes hydration / mismatch issues\n\nexport const useIsSSR = () => {\n const [val, setVal] = useState(isSSR)\n\n useEffect(() => {\n if (isWeb && !isSSR) {\n startTransition(() => {\n setVal(false)\n })\n }\n }, [])\n\n return val\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AAEA;AACA;AAIO,MAAM,WAAW,MAAM;AAC5B,QAAM,CAAC,KAAK,UAAU,SAAS,KAAK;AAEpC,YAAU,MAAM;AACd,QAAI,SAAS,CAAC,OAAO;AACnB,sBAAgB,MAAM;AACpB,eAAO,KAAK;AAAA,MACd,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -16,6 +16,7 @@ const mediaState = process.env.NODE_ENV === "development" ? createProxy(
|
|
|
16
16
|
) : {};
|
|
17
17
|
const mediaQueryConfig = {};
|
|
18
18
|
const getMedia = () => mediaState;
|
|
19
|
+
const mediaKeysWithAndWithout$ = /* @__PURE__ */ new Set();
|
|
19
20
|
let initState;
|
|
20
21
|
const getInitialMediaState = () => {
|
|
21
22
|
return (getConfig().disableSSR ? mediaState : initState) || {};
|
|
@@ -34,6 +35,8 @@ const configureMedia = (config) => {
|
|
|
34
35
|
return;
|
|
35
36
|
for (const key in media) {
|
|
36
37
|
mediaState[key] = (mediaQueryDefaultActive == null ? void 0 : mediaQueryDefaultActive[key]) || false;
|
|
38
|
+
mediaKeysWithAndWithout$.add(key);
|
|
39
|
+
mediaKeysWithAndWithout$.add(`$${key}`);
|
|
37
40
|
}
|
|
38
41
|
Object.assign(mediaQueryConfig, media);
|
|
39
42
|
initState = { ...mediaState };
|
|
@@ -204,6 +207,7 @@ export {
|
|
|
204
207
|
getMedia,
|
|
205
208
|
getMediaImportanceIfMoreImportant,
|
|
206
209
|
getMediaKeyImportance,
|
|
210
|
+
mediaKeysWithAndWithout$,
|
|
207
211
|
mediaObjectToString,
|
|
208
212
|
mediaQueryConfig,
|
|
209
213
|
mediaState,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useMedia.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useEffect, useMemo, useSyncExternalStore } from 'react'\n\nimport { getConfig } from '../config'\nimport { createProxy } from '../helpers/createProxy'\nimport { matchMedia } from '../helpers/matchMedia'\nimport {\n MediaQueries,\n MediaQueryKey,\n MediaQueryObject,\n MediaQueryState,\n TamaguiInternalConfig,\n} from '../types'\nimport { useSafeRef } from './useSafeRef'\n\nexport const mediaState: MediaQueryState =\n // development only safeguard\n process.env.NODE_ENV === 'development'\n ? createProxy(\n {},\n {\n get(target, key) {\n if (\n typeof key === 'string' &&\n key[0] === '$' &&\n // dont error on $$typeof\n key[1] !== '$'\n ) {\n throw new Error(`Access mediaState should not use \"$\": ${key}`)\n }\n return Reflect.get(target, key)\n },\n }\n )\n : ({} as any)\n\nexport const mediaQueryConfig: MediaQueries = {}\nexport const getMedia = () => mediaState\n\n// for SSR capture it at time of startup\nlet initState: MediaQueryState\nexport const getInitialMediaState = () => {\n return (getConfig().disableSSR ? mediaState : initState) || {}\n}\n\nlet mediaKeysOrdered: string[]\nexport const getMediaKeyImportance = (key: string) => {\n if (process.env.NODE_ENV === 'development' && key[0] === '$') {\n throw new Error('use short key')\n }\n // + 2 because we set base usedKeys=1 in getSplitStyles and all media go above 1\n return mediaKeysOrdered.indexOf(key) + 2\n}\n\nconst dispose = new Set<Function>()\n\nexport const configureMedia = (config: TamaguiInternalConfig) => {\n const { media, mediaQueryDefaultActive } = config\n if (!media) return\n for (const key in media) {\n mediaState[key] = mediaQueryDefaultActive?.[key] || false\n }\n Object.assign(mediaQueryConfig, media)\n initState = { ...mediaState }\n updateCurrentState()\n mediaKeysOrdered = Object.keys(media)\n if (config.disableSSR) {\n setupMediaListeners()\n }\n}\n\nfunction unlisten() {\n dispose.forEach((cb) => cb())\n dispose.clear()\n}\n\n/**\n * Note: This should *not* set the state on the first render!\n * Because to avoid hydration issues SSR must match the server\n * *and then* re-render with the actual media query state.\n */\nlet configuredKey = ''\nfunction setupMediaListeners() {\n // avoid setting up more than once per config\n const nextKey = JSON.stringify(mediaQueryConfig)\n if (nextKey === configuredKey) return\n configuredKey = nextKey\n\n // hmr, undo existing before re-binding\n unlisten()\n\n for (const key in mediaQueryConfig) {\n const str = mediaObjectToString(mediaQueryConfig[key])\n const getMatch = () => matchMedia(str)\n const match = getMatch()\n if (!match) {\n throw new Error('\u26A0\uFE0F No match')\n }\n // react native needs these deprecated apis for now\n match.addListener(update)\n dispose.add(() => {\n match.removeListener(update)\n })\n\n update()\n\n function update() {\n const next = !!getMatch().matches\n if (next === mediaState[key]) return\n mediaState[key] = next\n updateCurrentState()\n }\n }\n}\n\nexport function useMediaListeners(config: TamaguiInternalConfig) {\n if (config.disableSSR) return\n useEffect(() => {\n setupMediaListeners()\n }, [])\n}\n\nconst currentStateListeners = new Set<any>()\nfunction updateCurrentState() {\n currentStateListeners.forEach((cb) => cb(mediaState))\n}\nfunction subscribe(subscriber: any) {\n currentStateListeners.add(subscriber)\n return () => currentStateListeners.delete(subscriber)\n}\n\ntype MediaKeysState = {\n [key: string]: any\n}\n\ntype UseMediaState = {\n [key in MediaQueryKey]: boolean\n}\n\nconst shouldUpdate = new WeakMap<any, boolean>()\nexport function setMediaShouldUpdate(ref: any, val: boolean) {\n return shouldUpdate.set(ref, val)\n}\n\ntype UseMediaInternalState = { prev: MediaKeysState; next: MediaKeysState }\nconst empty = {}\nlet initialUseState: UseMediaInternalState\n\nexport function useMedia(): UseMediaState {\n // setup once\n initialUseState ||= {\n prev: initState,\n next: empty,\n }\n\n const keys = useSafeRef<UseMediaInternalState>(initialUseState)\n const state = useSyncExternalStore<MediaQueryState>(\n subscribe,\n () => {\n const curState = keys.current\n const preventUpdate = arguments[0] && shouldUpdate.get(arguments[0]) !== true\n if (preventUpdate) {\n return curState.prev\n }\n\n let didUpdate = false\n\n // ensure we keep the minimal object of only used keys\n const next = {}\n\n for (const key in curState.next) {\n const val = mediaState[key]\n if (curState.prev[key] !== val) {\n didUpdate = true\n }\n next[key] = val\n }\n\n if (!didUpdate) {\n return curState.prev\n }\n\n keys.current = { next, prev: next }\n return next\n },\n () => initState\n )\n\n return useMemo(() => {\n return new Proxy(state === empty ? initState : state, {\n get(_, key: string) {\n if (!(key in keys.current.next)) {\n keys.current.next[key] = true\n keys.current = { ...keys.current }\n }\n return Reflect.get(state, key)\n },\n })\n }, [state])\n}\n\n/**\n * Useful for more complex components that need access to the currently active props,\n * accounting for the currently active media queries.\n *\n * Use sparingly, 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 next = {} as A\n const importancesUsed = {}\n const propNames = Object.keys(props)\n\n for (let i = propNames.length - 1; i >= 0; i--) {\n const key = propNames[i]\n const val = props[key]\n if (key[0] === '$') {\n const mediaKey = key.slice(1)\n if (!media[mediaKey]) continue\n if (val && typeof val === 'object') {\n const subKeys = Object.keys(val)\n for (let j = subKeys.length; j--; j >= 0) {\n const subKey = subKeys[j]\n mergeMediaByImportance(next, mediaKey, subKey, val[subKey], importancesUsed)\n }\n }\n } else {\n mergeMediaByImportance(next, '', key, val, importancesUsed)\n }\n }\n\n return next\n }, [media, props])\n}\n\nexport const getMediaImportanceIfMoreImportant = (\n mediaKey: string,\n key: string,\n importancesUsed: Record<string, number>\n) => {\n const importance = getMediaKeyImportance(mediaKey)\n return !importancesUsed[key] || importance > importancesUsed[key] ? importance : null\n}\n\nexport function mergeMediaByImportance(\n onto: Record<string, any>,\n mediaKey: string,\n key: string,\n value: any,\n importancesUsed: Record<string, number>\n) {\n const importance = getMediaImportanceIfMoreImportant(mediaKey, key, importancesUsed)\n if (importance === null) {\n return false\n }\n importancesUsed[key] = importance\n onto[key] = value\n return true\n}\n\nfunction camelToHyphen(str: string) {\n return str.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`).toLowerCase()\n}\n\nexport function mediaObjectToString(query: string | MediaQueryObject) {\n if (typeof query === 'string') {\n return query\n }\n return Object.entries(query)\n .map(([feature, value]) => {\n feature = camelToHyphen(feature)\n if (typeof value === 'string') {\n return `(${feature}: ${value})`\n }\n if (typeof value === 'number' && /[height|width]$/.test(feature)) {\n value = `${value}px`\n }\n return `(${feature}: ${value})`\n })\n .join(' and ')\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAW,SAAS,4BAA4B;AAEzD,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,UACE,OAAO,QAAQ,YACf,IAAI,OAAO,OAEX,IAAI,OAAO,KACX;AACA,cAAM,IAAI,MAAM,yCAAyC,KAAK;AAAA,MAChE;AACA,aAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,IAChC;AAAA,EACF;AACF,IACC,CAAC;AAED,MAAM,mBAAiC,CAAC;AACxC,MAAM,WAAW,MAAM;
|
|
4
|
+
"sourcesContent": ["import { useEffect, useMemo, useSyncExternalStore } from 'react'\n\nimport { getConfig } from '../config'\nimport { createProxy } from '../helpers/createProxy'\nimport { matchMedia } from '../helpers/matchMedia'\nimport {\n MediaQueries,\n MediaQueryKey,\n MediaQueryObject,\n MediaQueryState,\n TamaguiInternalConfig,\n} from '../types'\nimport { useSafeRef } from './useSafeRef'\n\nexport const mediaState: MediaQueryState =\n // development only safeguard\n process.env.NODE_ENV === 'development'\n ? createProxy(\n {},\n {\n get(target, key) {\n if (\n typeof key === 'string' &&\n key[0] === '$' &&\n // dont error on $$typeof\n key[1] !== '$'\n ) {\n throw new Error(`Access mediaState should not use \"$\": ${key}`)\n }\n return Reflect.get(target, key)\n },\n }\n )\n : ({} as any)\n\nexport const mediaQueryConfig: MediaQueries = {}\nexport const getMedia = () => mediaState\nexport const mediaKeysWithAndWithout$ = new Set<string>()\n\n// for SSR capture it at time of startup\nlet initState: MediaQueryState\nexport const getInitialMediaState = () => {\n return (getConfig().disableSSR ? mediaState : initState) || {}\n}\n\nlet mediaKeysOrdered: string[]\nexport const getMediaKeyImportance = (key: string) => {\n if (process.env.NODE_ENV === 'development' && key[0] === '$') {\n throw new Error('use short key')\n }\n // + 2 because we set base usedKeys=1 in getSplitStyles and all media go above 1\n return mediaKeysOrdered.indexOf(key) + 2\n}\n\nconst dispose = new Set<Function>()\n\nexport const configureMedia = (config: TamaguiInternalConfig) => {\n const { media, mediaQueryDefaultActive } = config\n if (!media) return\n for (const key in media) {\n mediaState[key] = mediaQueryDefaultActive?.[key] || false\n mediaKeysWithAndWithout$.add(key)\n mediaKeysWithAndWithout$.add(`$${key}`)\n }\n Object.assign(mediaQueryConfig, media)\n initState = { ...mediaState }\n updateCurrentState()\n mediaKeysOrdered = Object.keys(media)\n if (config.disableSSR) {\n setupMediaListeners()\n }\n}\n\nfunction unlisten() {\n dispose.forEach((cb) => cb())\n dispose.clear()\n}\n\n/**\n * Note: This should *not* set the state on the first render!\n * Because to avoid hydration issues SSR must match the server\n * *and then* re-render with the actual media query state.\n */\nlet configuredKey = ''\nfunction setupMediaListeners() {\n // avoid setting up more than once per config\n const nextKey = JSON.stringify(mediaQueryConfig)\n if (nextKey === configuredKey) return\n configuredKey = nextKey\n\n // hmr, undo existing before re-binding\n unlisten()\n\n for (const key in mediaQueryConfig) {\n const str = mediaObjectToString(mediaQueryConfig[key])\n const getMatch = () => matchMedia(str)\n const match = getMatch()\n if (!match) {\n throw new Error('\u26A0\uFE0F No match')\n }\n // react native needs these deprecated apis for now\n match.addListener(update)\n dispose.add(() => {\n match.removeListener(update)\n })\n\n update()\n\n function update() {\n const next = !!getMatch().matches\n if (next === mediaState[key]) return\n mediaState[key] = next\n updateCurrentState()\n }\n }\n}\n\nexport function useMediaListeners(config: TamaguiInternalConfig) {\n if (config.disableSSR) return\n useEffect(() => {\n setupMediaListeners()\n }, [])\n}\n\nconst currentStateListeners = new Set<any>()\nfunction updateCurrentState() {\n currentStateListeners.forEach((cb) => cb(mediaState))\n}\nfunction subscribe(subscriber: any) {\n currentStateListeners.add(subscriber)\n return () => currentStateListeners.delete(subscriber)\n}\n\ntype MediaKeysState = {\n [key: string]: any\n}\n\ntype UseMediaState = {\n [key in MediaQueryKey]: boolean\n}\n\nconst shouldUpdate = new WeakMap<any, boolean>()\nexport function setMediaShouldUpdate(ref: any, val: boolean) {\n return shouldUpdate.set(ref, val)\n}\n\ntype UseMediaInternalState = { prev: MediaKeysState; next: MediaKeysState }\nconst empty = {}\nlet initialUseState: UseMediaInternalState\n\nexport function useMedia(): UseMediaState {\n // setup once\n initialUseState ||= {\n prev: initState,\n next: empty,\n }\n\n const keys = useSafeRef<UseMediaInternalState>(initialUseState)\n const state = useSyncExternalStore<MediaQueryState>(\n subscribe,\n () => {\n const curState = keys.current\n const preventUpdate = arguments[0] && shouldUpdate.get(arguments[0]) !== true\n if (preventUpdate) {\n return curState.prev\n }\n\n let didUpdate = false\n\n // ensure we keep the minimal object of only used keys\n const next = {}\n\n for (const key in curState.next) {\n const val = mediaState[key]\n if (curState.prev[key] !== val) {\n didUpdate = true\n }\n next[key] = val\n }\n\n if (!didUpdate) {\n return curState.prev\n }\n\n keys.current = { next, prev: next }\n return next\n },\n () => initState\n )\n\n return useMemo(() => {\n return new Proxy(state === empty ? initState : state, {\n get(_, key: string) {\n if (!(key in keys.current.next)) {\n keys.current.next[key] = true\n keys.current = { ...keys.current }\n }\n return Reflect.get(state, key)\n },\n })\n }, [state])\n}\n\n/**\n * Useful for more complex components that need access to the currently active props,\n * accounting for the currently active media queries.\n *\n * Use sparingly, 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 next = {} as A\n const importancesUsed = {}\n const propNames = Object.keys(props)\n\n for (let i = propNames.length - 1; i >= 0; i--) {\n const key = propNames[i]\n const val = props[key]\n if (key[0] === '$') {\n const mediaKey = key.slice(1)\n if (!media[mediaKey]) continue\n if (val && typeof val === 'object') {\n const subKeys = Object.keys(val)\n for (let j = subKeys.length; j--; j >= 0) {\n const subKey = subKeys[j]\n mergeMediaByImportance(next, mediaKey, subKey, val[subKey], importancesUsed)\n }\n }\n } else {\n mergeMediaByImportance(next, '', key, val, importancesUsed)\n }\n }\n\n return next\n }, [media, props])\n}\n\nexport const getMediaImportanceIfMoreImportant = (\n mediaKey: string,\n key: string,\n importancesUsed: Record<string, number>\n) => {\n const importance = getMediaKeyImportance(mediaKey)\n return !importancesUsed[key] || importance > importancesUsed[key] ? importance : null\n}\n\nexport function mergeMediaByImportance(\n onto: Record<string, any>,\n mediaKey: string,\n key: string,\n value: any,\n importancesUsed: Record<string, number>\n) {\n const importance = getMediaImportanceIfMoreImportant(mediaKey, key, importancesUsed)\n if (importance === null) {\n return false\n }\n importancesUsed[key] = importance\n onto[key] = value\n return true\n}\n\nfunction camelToHyphen(str: string) {\n return str.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`).toLowerCase()\n}\n\nexport function mediaObjectToString(query: string | MediaQueryObject) {\n if (typeof query === 'string') {\n return query\n }\n return Object.entries(query)\n .map(([feature, value]) => {\n feature = camelToHyphen(feature)\n if (typeof value === 'string') {\n return `(${feature}: ${value})`\n }\n if (typeof value === 'number' && /[height|width]$/.test(feature)) {\n value = `${value}px`\n }\n return `(${feature}: ${value})`\n })\n .join(' and ')\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAW,SAAS,4BAA4B;AAEzD,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,UACE,OAAO,QAAQ,YACf,IAAI,OAAO,OAEX,IAAI,OAAO,KACX;AACA,cAAM,IAAI,MAAM,yCAAyC,KAAK;AAAA,MAChE;AACA,aAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,IAChC;AAAA,EACF;AACF,IACC,CAAC;AAED,MAAM,mBAAiC,CAAC;AACxC,MAAM,WAAW,MAAM;AACvB,MAAM,2BAA2B,oBAAI,IAAY;AAGxD,IAAI;AACG,MAAM,uBAAuB,MAAM;AACxC,UAAQ,UAAU,EAAE,aAAa,aAAa,cAAc,CAAC;AAC/D;AAEA,IAAI;AACG,MAAM,wBAAwB,CAAC,QAAgB;AACpD,MAAI,QAAQ,IAAI,aAAa,iBAAiB,IAAI,OAAO,KAAK;AAC5D,UAAM,IAAI,MAAM,eAAe;AAAA,EACjC;AAEA,SAAO,iBAAiB,QAAQ,GAAG,IAAI;AACzC;AAEA,MAAM,UAAU,oBAAI,IAAc;AAE3B,MAAM,i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Y;AACzE;AAEO,SAAS,oBAAoB,OAAkC;AACpE,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO;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
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/usePressable.tsx"],
|
|
4
4
|
"sourcesContent": ["import { Pressable, PressableProps } from 'react-native'\n\nconst getPressable = Pressable?.['type']?.['render']\n\nexport const usePressable = (props: PressableProps) => {\n const out = getPressable(props)\n const { children, style, ...pressableProps } = out.props\n return [pressableProps, style] as const\n}\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA
|
|
5
|
+
"mappings": "AAAA;AAAA;AAEA,MAAM,eAAe,6CAAY,YAAZ,mBAAsB;AAEpC,MAAM,eAAe,CAAC,UAA0B;AACrD,QAAM,MAAM,aAAa,KAAK;AAC9B,QAAM,EAAE,UAAU,UAAU,mBAAmB,IAAI;AACnD,SAAO,CAAC,gBAAgB,KAAK;AAC/B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=usePrevious.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useUnmountEffect.ts"],
|
|
4
4
|
"sourcesContent": ["import { useEffect } from 'react'\n\nexport function useUnmountEffect(callback: () => void) {\n return useEffect(() => () => callback(), [])\n}\n"],
|
|
5
|
-
"mappings": "AAAA
|
|
5
|
+
"mappings": "AAAA;AAEO,0BAA0B,UAAsB;AACrD,SAAO,UAAU,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC;AAC7C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/styled.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
import { stylePropsAll } from "@tamagui/helpers";
|
|
1
2
|
import { createComponent } from "./createComponent";
|
|
2
3
|
import { ReactNativeStaticConfigs } from "./setupReactNative";
|
|
3
4
|
function styled(Component, options, staticExtractionOptions) {
|
|
5
|
+
if (process.env.NODE_ENV === "development") {
|
|
6
|
+
if (options == null ? void 0 : options.variants) {
|
|
7
|
+
for (const key in options.variants) {
|
|
8
|
+
if (key in stylePropsAll) {
|
|
9
|
+
console.error(
|
|
10
|
+
`Invalid variant key overlaps with style key: ${key}. Tamagui prevents defining variants that use valid style keys to reduce implementation complexity.`
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
4
16
|
const staticConfigProps = (() => {
|
|
5
17
|
const parentStaticConfig = "staticConfig" in Component ? Component.staticConfig : null;
|
|
6
18
|
if (options) {
|
package/dist/esm/styled.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/styled.tsx"],
|
|
4
|
-
"sourcesContent": ["import { createComponent } from './createComponent'\nimport { ReactNativeStaticConfigs } from './setupReactNative'\nimport {\n GetProps,\n GetVariantValues,\n MediaProps,\n PseudoProps,\n StaticConfig,\n StylableComponent,\n TamaguiComponent,\n TamaguiElement,\n VariantDefinitions,\n VariantSpreadFunction,\n} from './types'\n\n// TODO may be able to use this in the options?: arg below directly\nexport type StyledOptions<ParentComponent extends StylableComponent> =\n GetProps<ParentComponent> & {\n name?: string\n variants?: VariantDefinitions<ParentComponent> | undefined\n defaultVariants?: { [key: string]: any }\n }\n\n// can't infer from styled(<YStack />) which would be nice\n// * excessively deep type instantiation\n\ntype GetBaseProps<A extends StylableComponent> =\n // A extends TamaguiReactElement\n // ? GetBaseProps<A['type']> :\n A extends TamaguiComponent<any, any, infer P> ? P : GetProps<A>\n\ntype GetVariantProps<A extends StylableComponent> =\n // A extends TamaguiReactElement\n // ? GetVariantProps<A['type']>\n // :\n A extends TamaguiComponent<any, any, any, infer V> ? V : {}\n\nexport function styled<\n ParentComponent extends StylableComponent,\n Variants extends VariantDefinitions<ParentComponent> | void = VariantDefinitions<ParentComponent> | void\n>(\n Component: ParentComponent,\n // this should be Partial<GetProps<ParentComponent>> but causes excessively deep type issues\n options?: GetProps<ParentComponent> & {\n name?: string\n variants?: Variants | undefined\n // thought i had this typed, but can't get it linked\n defaultVariants?: { [key: string]: any }\n acceptsClassName?: boolean\n },\n staticExtractionOptions?: Partial<StaticConfig>\n) {\n // allows passing styled(<H1 bc=\"red\" />)\n // but to get types right would be tricky\n // if (isValidElement(Component) && isTamaguiComponent(Component.type)) {\n // const props = Component.props\n // if (props && typeof props === 'object') {\n // Component = Component.type as any\n // options = options ? ({ ...props, ...options } as any) : props\n // }\n // }\n\n const staticConfigProps = (() => {\n const parentStaticConfig =\n 'staticConfig' in Component ? (Component.staticConfig as StaticConfig) : null\n\n if (options) {\n const {\n variants,\n name,\n defaultVariants,\n acceptsClassName: acceptsClassNameProp,\n ...defaultProps\n } = options\n if (defaultVariants) {\n Object.assign(defaultProps, defaultVariants)\n }\n const isReactNative = Boolean(\n ReactNativeStaticConfigs.has(Component) ||\n ReactNativeStaticConfigs.has(parentStaticConfig?.Component) ||\n parentStaticConfig?.isReactNative ||\n staticExtractionOptions?.isReactNative\n )\n const isTamagui = !isReactNative && !!parentStaticConfig\n\n const Comp = isReactNative\n ? parentStaticConfig?.Component || Component\n : (Component as any)\n const nativeConf = (isReactNative && ReactNativeStaticConfigs.get(Comp)) || null\n\n const isText = Boolean(\n staticExtractionOptions?.isText || parentStaticConfig?.isText\n )\n const acceptsClassName = acceptsClassNameProp ?? (isTamagui || isReactNative)\n\n const conf: Partial<StaticConfig> = {\n ...staticExtractionOptions,\n ...(!isTamagui && {\n Component: Comp,\n }),\n // this type gets messed up by options?: Partial<GetProps<ParentComponent>> above\n // take away the Partial<> and it's fine\n variants,\n defaultProps,\n defaultVariants,\n componentName: name,\n isReactNative,\n isText,\n acceptsClassName,\n ...nativeConf,\n }\n\n // bail on non className views as well\n if (defaultProps.children || !acceptsClassName) {\n conf.neverFlatten = true\n }\n\n return conf\n }\n return {}\n })()\n\n const component = createComponent(staticConfigProps, Component)\n\n // get parent props without pseudos and medias so we can rebuild both with new variants\n // get parent props without pseudos and medias so we can rebuild both with new variants\n type ParentPropsBase = GetBaseProps<ParentComponent>\n type ParentVariants = GetVariantProps<ParentComponent>\n\n type OurVariants = Variants extends void\n ? {}\n : {\n [Key in keyof Variants]?: Variants[Key] extends VariantSpreadFunction<\n any,\n infer Val\n >\n ? Val\n : GetVariantValues<keyof Variants[Key]>\n }\n\n type VariantProps = Omit<ParentVariants, keyof OurVariants> & OurVariants\n type OurPropsBase = ParentPropsBase & VariantProps\n\n type Props = Variants extends void\n ? GetProps<ParentComponent>\n : // start with base props\n OurPropsBase &\n // add in media (+ pseudos nested)\n MediaProps<Partial<OurPropsBase>> &\n // add in pseudos\n PseudoProps<Partial<OurPropsBase>>\n\n type StyledComponent = TamaguiComponent<\n Props,\n TamaguiElement,\n ParentPropsBase,\n ParentVariants & OurVariants\n >\n\n return component as StyledComponent\n}\n\n// sanity check types\n// import { Stack } from './views/Stack'\n// const X = styled(Stack, {\n// variants: {\n// size: {\n// '...size': (val) => {\n// return {\n// pointerEvents: 'auto'\n// }\n// }\n// },\n// disabled: {\n// true: {\n// alignContent: 'center',\n// opacity: 0.5,\n// pointerEvents: 'none',\n// },\n// },\n// } as const\n// })\n// // type variants = GetStyledVariants<typeof X>\n// const y = <X disabled size=\"$10\" />\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,uBAAuB;AAChC,SAAS,gCAAgC;AAoClC,SAAS,OAId,WAEA,SAOA,yBACA;
|
|
4
|
+
"sourcesContent": ["import { stylePropsAll, validStyles } from '@tamagui/helpers'\n\nimport { createComponent } from './createComponent'\nimport { ReactNativeStaticConfigs } from './setupReactNative'\nimport {\n GetProps,\n GetVariantValues,\n MediaProps,\n PseudoProps,\n StaticConfig,\n StylableComponent,\n TamaguiComponent,\n TamaguiElement,\n VariantDefinitions,\n VariantSpreadFunction,\n} from './types'\n\n// TODO may be able to use this in the options?: arg below directly\nexport type StyledOptions<ParentComponent extends StylableComponent> =\n GetProps<ParentComponent> & {\n name?: string\n variants?: VariantDefinitions<ParentComponent> | undefined\n defaultVariants?: { [key: string]: any }\n }\n\n// can't infer from styled(<YStack />) which would be nice\n// * excessively deep type instantiation\n\ntype GetBaseProps<A extends StylableComponent> =\n // A extends TamaguiReactElement\n // ? GetBaseProps<A['type']> :\n A extends TamaguiComponent<any, any, infer P> ? P : GetProps<A>\n\ntype GetVariantProps<A extends StylableComponent> =\n // A extends TamaguiReactElement\n // ? GetVariantProps<A['type']>\n // :\n A extends TamaguiComponent<any, any, any, infer V> ? V : {}\n\nexport function styled<\n ParentComponent extends StylableComponent,\n Variants extends VariantDefinitions<ParentComponent> | void = VariantDefinitions<ParentComponent> | void\n>(\n Component: ParentComponent,\n // this should be Partial<GetProps<ParentComponent>> but causes excessively deep type issues\n options?: GetProps<ParentComponent> & {\n name?: string\n variants?: Variants | undefined\n // thought i had this typed, but can't get it linked\n defaultVariants?: { [key: string]: any }\n acceptsClassName?: boolean\n },\n staticExtractionOptions?: Partial<StaticConfig>\n) {\n // allows passing styled(<H1 bc=\"red\" />)\n // but to get types right would be tricky\n // if (isValidElement(Component) && isTamaguiComponent(Component.type)) {\n // const props = Component.props\n // if (props && typeof props === 'object') {\n // Component = Component.type as any\n // options = options ? ({ ...props, ...options } as any) : props\n // }\n // }\n\n // validate not using a variant over an existing valid style\n if (process.env.NODE_ENV === 'development') {\n if (options?.variants) {\n for (const key in options.variants) {\n if (key in stylePropsAll) {\n console.error(\n `Invalid variant key overlaps with style key: ${key}. Tamagui prevents defining variants that use valid style keys to reduce implementation complexity.`\n )\n }\n }\n }\n }\n\n const staticConfigProps = (() => {\n const parentStaticConfig =\n 'staticConfig' in Component ? (Component.staticConfig as StaticConfig) : null\n\n if (options) {\n const {\n variants,\n name,\n defaultVariants,\n acceptsClassName: acceptsClassNameProp,\n ...defaultProps\n } = options\n if (defaultVariants) {\n Object.assign(defaultProps, defaultVariants)\n }\n const isReactNative = Boolean(\n ReactNativeStaticConfigs.has(Component) ||\n ReactNativeStaticConfigs.has(parentStaticConfig?.Component) ||\n parentStaticConfig?.isReactNative ||\n staticExtractionOptions?.isReactNative\n )\n const isTamagui = !isReactNative && !!parentStaticConfig\n\n const Comp = isReactNative\n ? parentStaticConfig?.Component || Component\n : (Component as any)\n const nativeConf = (isReactNative && ReactNativeStaticConfigs.get(Comp)) || null\n\n const isText = Boolean(\n staticExtractionOptions?.isText || parentStaticConfig?.isText\n )\n const acceptsClassName = acceptsClassNameProp ?? (isTamagui || isReactNative)\n\n const conf: Partial<StaticConfig> = {\n ...staticExtractionOptions,\n ...(!isTamagui && {\n Component: Comp,\n }),\n // this type gets messed up by options?: Partial<GetProps<ParentComponent>> above\n // take away the Partial<> and it's fine\n variants,\n defaultProps,\n defaultVariants,\n componentName: name,\n isReactNative,\n isText,\n acceptsClassName,\n ...nativeConf,\n }\n\n // bail on non className views as well\n if (defaultProps.children || !acceptsClassName) {\n conf.neverFlatten = true\n }\n\n return conf\n }\n return {}\n })()\n\n const component = createComponent(staticConfigProps, Component)\n\n // get parent props without pseudos and medias so we can rebuild both with new variants\n // get parent props without pseudos and medias so we can rebuild both with new variants\n type ParentPropsBase = GetBaseProps<ParentComponent>\n type ParentVariants = GetVariantProps<ParentComponent>\n\n type OurVariants = Variants extends void\n ? {}\n : {\n [Key in keyof Variants]?: Variants[Key] extends VariantSpreadFunction<\n any,\n infer Val\n >\n ? Val\n : GetVariantValues<keyof Variants[Key]>\n }\n\n type VariantProps = Omit<ParentVariants, keyof OurVariants> & OurVariants\n type OurPropsBase = ParentPropsBase & VariantProps\n\n type Props = Variants extends void\n ? GetProps<ParentComponent>\n : // start with base props\n OurPropsBase &\n // add in media (+ pseudos nested)\n MediaProps<Partial<OurPropsBase>> &\n // add in pseudos\n PseudoProps<Partial<OurPropsBase>>\n\n type StyledComponent = TamaguiComponent<\n Props,\n TamaguiElement,\n ParentPropsBase,\n ParentVariants & OurVariants\n >\n\n return component as StyledComponent\n}\n\n// sanity check types\n// import { Stack } from './views/Stack'\n// const X = styled(Stack, {\n// variants: {\n// size: {\n// '...size': (val) => {\n// return {\n// pointerEvents: 'auto'\n// }\n// }\n// },\n// disabled: {\n// true: {\n// alignContent: 'center',\n// opacity: 0.5,\n// pointerEvents: 'none',\n// },\n// },\n// } as const\n// })\n// // type variants = GetStyledVariants<typeof X>\n// const y = <X disabled size=\"$10\" />\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,qBAAkC;AAE3C,SAAS,uBAAuB;AAChC,SAAS,gCAAgC;AAoClC,SAAS,OAId,WAEA,SAOA,yBACA;AAYA,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,mCAAS,UAAU;AACrB,iBAAW,OAAO,QAAQ,UAAU;AAClC,YAAI,OAAO,eAAe;AACxB,kBAAQ;AAAA,YACN,gDAAgD;AAAA,UAClD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,qBAAqB,MAAM;AAC/B,UAAM,qBACJ,kBAAkB,YAAa,UAAU,eAAgC;AAE3E,QAAI,SAAS;AACX,YAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA,kBAAkB;AAAA,WACf;AAAA,MACL,IAAI;AACJ,UAAI,iBAAiB;AACnB,eAAO,OAAO,cAAc,eAAe;AAAA,MAC7C;AACA,YAAM,gBAAgB;AAAA,QACpB,yBAAyB,IAAI,SAAS,KACpC,yBAAyB,IAAI,yDAAoB,SAAS,MAC1D,yDAAoB,mBACpB,mEAAyB;AAAA,MAC7B;AACA,YAAM,YAAY,CAAC,iBAAiB,CAAC,CAAC;AAEtC,YAAM,OAAO,iBACT,yDAAoB,cAAa,YAChC;AACL,YAAM,aAAc,iBAAiB,yBAAyB,IAAI,IAAI,KAAM;AAE5E,YAAM,SAAS;AAAA,SACb,mEAAyB,YAAU,yDAAoB;AAAA,MACzD;AACA,YAAM,mBAAmB,yBAAyB,aAAa;AAE/D,YAAM,OAA8B;AAAA,QAClC,GAAG;AAAA,QACH,GAAI,CAAC,aAAa;AAAA,UAChB,WAAW;AAAA,QACb;AAAA,QAGA;AAAA,QACA;AAAA,QACA;AAAA,QACA,eAAe;AAAA,QACf;AAAA,QACA;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACL;AAGA,UAAI,aAAa,YAAY,CAAC,kBAAkB;AAC9C,aAAK,eAAe;AAAA,MACtB;AAEA,aAAO;AAAA,IACT;AACA,WAAO,CAAC;AAAA,EACV,GAAG;AAEH,QAAM,YAAY,gBAAgB,mBAAmB,SAAS;AAqC9D,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TextAncestorContext as RNWTextAncestorContext } from "@tamagui/rnw";
|
|
2
|
+
import React, { createContext } from "react";
|
|
3
|
+
const FallbackNativeContext = createContext(false);
|
|
4
|
+
const TextAncestorContext = RNWTextAncestorContext ?? FallbackNativeContext;
|
|
5
|
+
const TextAncestorProvider = (props) => {
|
|
6
|
+
return /* @__PURE__ */ React.createElement(TextAncestorContext.Provider, {
|
|
7
|
+
value: false
|
|
8
|
+
}, props.children);
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
FallbackNativeContext,
|
|
12
|
+
TextAncestorContext,
|
|
13
|
+
TextAncestorProvider
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=TextAncestorContext.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/views/TextAncestorContext.tsx"],
|
|
4
|
+
"sourcesContent": ["import { TextAncestorContext as RNWTextAncestorContext } from '@tamagui/rnw'\nimport React, { createContext } from 'react'\n\nexport const FallbackNativeContext = createContext(false)\n\nexport const TextAncestorContext = RNWTextAncestorContext ?? FallbackNativeContext\n\nexport const TextAncestorProvider = (props) => {\n return <TextAncestorContext.Provider value={false}>{props.children}</TextAncestorContext.Provider>\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AACA;AAEO,MAAM,wBAAwB,cAAc,KAAK;AAEjD,MAAM,sBAAsB,0BAA0B;AAEtD,MAAM,uBAAuB,CAAC,UAAU;AAC7C,SAAO,oCAAC,oBAAoB,UAApB;AAAA,IAA6B,OAAO;AAAA,KAAQ,MAAM,QAAS;AACrE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,32 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useState } from "react";
|
|
1
|
+
import React, { useState } from "react";
|
|
3
2
|
import { useIsomorphicLayoutEffect } from "../constants/platform";
|
|
4
3
|
import { useDefaultThemeName, useThemeName } from "../hooks/useTheme";
|
|
5
4
|
import { Theme } from "./Theme";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
5
|
+
let inversions = {
|
|
6
|
+
light: "dark",
|
|
7
|
+
dark: "light"
|
|
8
|
+
};
|
|
9
|
+
function setThemeInversions(next) {
|
|
10
|
+
inversions = next;
|
|
11
|
+
}
|
|
12
|
+
const ThemeInverse = (props) => {
|
|
10
13
|
const themeName = useThemeName();
|
|
11
14
|
const defaultTheme = useDefaultThemeName();
|
|
12
15
|
const [name, setName] = useState(null);
|
|
13
16
|
useIsomorphicLayoutEffect(() => {
|
|
14
|
-
|
|
15
|
-
setName("light");
|
|
16
|
-
}
|
|
17
|
-
if (themeName.startsWith("light")) {
|
|
18
|
-
setName("dark");
|
|
19
|
-
}
|
|
17
|
+
setName(inversions[themeName] || inversions[defaultTheme || ""] || null);
|
|
20
18
|
}, [defaultTheme, themeName]);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
return /* @__PURE__ */ jsx(Theme, {
|
|
25
|
-
name,
|
|
26
|
-
children
|
|
27
|
-
});
|
|
19
|
+
return /* @__PURE__ */ React.createElement(Theme, {
|
|
20
|
+
name
|
|
21
|
+
}, props.children);
|
|
28
22
|
};
|
|
29
23
|
export {
|
|
30
|
-
ThemeInverse
|
|
24
|
+
ThemeInverse,
|
|
25
|
+
setThemeInversions
|
|
31
26
|
};
|
|
32
27
|
//# sourceMappingURL=ThemeInverse.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/views/ThemeInverse.tsx"],
|
|
4
|
-
"sourcesContent": ["import React, { useState } from 'react'\n\nimport { useIsomorphicLayoutEffect } from '../constants/platform'\nimport { useDefaultThemeName, useThemeName } from '../hooks/useTheme'\nimport { Theme } from './Theme'\n\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import React, { useState } from 'react'\n\nimport { useIsomorphicLayoutEffect } from '../constants/platform'\nimport { useDefaultThemeName, useThemeName } from '../hooks/useTheme'\nimport { Theme } from './Theme'\n\ntype StringRecord = { [key: string]: string }\n\nlet inversions: StringRecord = {\n light: 'dark',\n dark: 'light',\n}\n\nexport function setThemeInversions(next: StringRecord) {\n inversions = next\n}\n\nexport const ThemeInverse = (props: { children: any }) => {\n const themeName = useThemeName()\n const defaultTheme = useDefaultThemeName()\n const [name, setName] = useState<null | string>(null)\n\n // ssr\n useIsomorphicLayoutEffect(() => {\n setName(inversions[themeName] || inversions[defaultTheme || ''] || null)\n }, [defaultTheme, themeName])\n\n return <Theme name={name}>{props.children}</Theme>\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AAEA;AACA;AACA;AAIA,IAAI,aAA2B;AAAA,EAC7B,OAAO;AAAA,EACP,MAAM;AACR;AAEO,4BAA4B,MAAoB;AACrD,eAAa;AACf;AAEO,MAAM,eAAe,CAAC,UAA6B;AACxD,QAAM,YAAY,aAAa;AAC/B,QAAM,eAAe,oBAAoB;AACzC,QAAM,CAAC,MAAM,WAAW,SAAwB,IAAI;AAGpD,4BAA0B,MAAM;AAC9B,YAAQ,WAAW,cAAc,WAAW,gBAAgB,OAAO,IAAI;AAAA,EACzE,GAAG,CAAC,cAAc,SAAS,CAAC;AAE5B,SAAO,oCAAC;AAAA,IAAM;AAAA,KAAa,MAAM,QAAS;AAC5C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
1
|
import React, { useContext, useLayoutEffect, useState } from "react";
|
|
3
2
|
import { isWeb } from "../constants/platform";
|
|
4
|
-
import { ThemeManagerContext } from "../
|
|
3
|
+
import { ThemeManagerContext } from "../ThemeManager";
|
|
5
4
|
import { Theme } from "./Theme";
|
|
6
5
|
React["createElement"];
|
|
7
6
|
const ThemeReset = (props) => {
|
|
@@ -26,12 +25,11 @@ const ThemeReset = (props) => {
|
|
|
26
25
|
if (!themeManager || !props.children) {
|
|
27
26
|
return props.children || null;
|
|
28
27
|
}
|
|
29
|
-
return /* @__PURE__ */
|
|
28
|
+
return /* @__PURE__ */ React.createElement(Theme, {
|
|
30
29
|
className: "tui-theme-reset",
|
|
31
30
|
reset: true,
|
|
32
|
-
name
|
|
33
|
-
|
|
34
|
-
});
|
|
31
|
+
name
|
|
32
|
+
}, props.children);
|
|
35
33
|
};
|
|
36
34
|
export {
|
|
37
35
|
ThemeReset
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/views/ThemeReset.tsx"],
|
|
4
|
-
"sourcesContent": ["import React, { useContext, useLayoutEffect, useState } from 'react'\n\nimport { isWeb } from '../constants/platform'\nimport { ThemeManagerContext } from '../
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import React, { useContext, useLayoutEffect, useState } from 'react'\n\nimport { isWeb } from '../constants/platform'\nimport { ThemeManagerContext } from '../ThemeManager'\nimport { Theme } from './Theme'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\n// resets the theme to the parent theme\nexport const ThemeReset = (props: { children?: any }) => {\n const themeManager = useContext(ThemeManagerContext)\n const [name, setName] = useState<string | null>(null)\n\n // this component doesn't work with SSR, so must run only client side\n // we could at least prevent more flickering by having the ssr head script\n // that changes to dark initially also go through and change all of these\n if (!isWeb || typeof document !== 'undefined') {\n useLayoutEffect(() => {\n if (!themeManager) return\n if (name !== themeManager.parentName) {\n setName(themeManager.parentName)\n }\n }, [themeManager?.parentName])\n\n useLayoutEffect(() => {\n if (!themeManager) return\n return themeManager.onChangeTheme(() => {\n setName(themeManager.parentName)\n })\n }, [])\n }\n\n if (!themeManager || !props.children) {\n return props.children || null\n }\n\n return (\n <Theme className=\"tui-theme-reset\" reset name={name}>\n {props.children}\n </Theme>\n )\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AAEA;AACA;AACA;AAGA,MAAM;AAGC,MAAM,aAAa,CAAC,UAA8B;AACvD,QAAM,eAAe,WAAW,mBAAmB;AACnD,QAAM,CAAC,MAAM,WAAW,SAAwB,IAAI;AAKpD,MAAI,CAAC,SAAS,OAAO,aAAa,aAAa;AAC7C,oBAAgB,MAAM;AACpB,UAAI,CAAC;AAAc;AACnB,UAAI,SAAS,aAAa,YAAY;AACpC,gBAAQ,aAAa,UAAU;AAAA,MACjC;AAAA,IACF,GAAG,CAAC,6CAAc,UAAU,CAAC;AAE7B,oBAAgB,MAAM;AACpB,UAAI,CAAC;AAAc;AACnB,aAAO,aAAa,cAAc,MAAM;AACtC,gBAAQ,aAAa,UAAU;AAAA,MACjC,CAAC;AAAA,IACH,GAAG,CAAC,CAAC;AAAA,EACP;AAEA,MAAI,CAAC,gBAAgB,CAAC,MAAM,UAAU;AACpC,WAAO,MAAM,YAAY;AAAA,EAC3B;AAEA,SACE,oCAAC;AAAA,IAAM,WAAU;AAAA,IAAkB,OAAK;AAAA,IAAC;AAAA,KACtC,MAAM,QACT;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|