@tamagui/core 1.88.12 → 1.89.0-1706308641099
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/LICENSE +21 -0
- package/dist/esm/createOptimizedView.mjs +2 -0
- package/dist/esm/getBaseViews.mjs +4 -0
- package/dist/esm/helpers/getBoundingClientRect.mjs +4 -0
- package/dist/esm/helpers/getRect.mjs +20 -0
- package/dist/esm/hooks/useElementLayout.mjs +87 -0
- package/dist/esm/hooks/usePlatformMethods.mjs +20 -0
- package/dist/esm/index.mjs +90 -0
- package/dist/esm/inject-styles.mjs +13 -0
- package/dist/esm/reactNativeTypes.mjs +0 -0
- package/dist/esm/vendor/Pressability.mjs +3 -0
- package/dist/native.js +9 -3
- package/dist/native.js.map +1 -1
- package/dist/test.native.js +5 -1
- package/dist/test.native.js.map +1 -1
- package/package.json +6 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { getBoundingClientRect } from "./getBoundingClientRect.mjs";
|
|
2
|
+
const getRect = node => {
|
|
3
|
+
const rect = getBoundingClientRect(node);
|
|
4
|
+
if (!rect) return;
|
|
5
|
+
const {
|
|
6
|
+
x,
|
|
7
|
+
y,
|
|
8
|
+
top,
|
|
9
|
+
left
|
|
10
|
+
} = rect;
|
|
11
|
+
return {
|
|
12
|
+
x,
|
|
13
|
+
y,
|
|
14
|
+
width: node.offsetWidth,
|
|
15
|
+
height: node.offsetHeight,
|
|
16
|
+
top,
|
|
17
|
+
left
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export { getRect };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
|
+
import { getBoundingClientRect } from "../helpers/getBoundingClientRect.mjs";
|
|
3
|
+
const LayoutHandlers = /* @__PURE__ */new WeakMap();
|
|
4
|
+
let resizeObserver = null;
|
|
5
|
+
typeof window < "u" && "ResizeObserver" in window && (resizeObserver = new ResizeObserver(entries => {
|
|
6
|
+
for (const {
|
|
7
|
+
target
|
|
8
|
+
} of entries) {
|
|
9
|
+
const onLayout = LayoutHandlers.get(target);
|
|
10
|
+
if (typeof onLayout != "function") return;
|
|
11
|
+
measureLayout(target, null, (x, y, width, height, left, top) => {
|
|
12
|
+
onLayout({
|
|
13
|
+
nativeEvent: {
|
|
14
|
+
layout: {
|
|
15
|
+
x,
|
|
16
|
+
y,
|
|
17
|
+
width,
|
|
18
|
+
height,
|
|
19
|
+
left,
|
|
20
|
+
top
|
|
21
|
+
},
|
|
22
|
+
target
|
|
23
|
+
},
|
|
24
|
+
timeStamp: Date.now()
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}));
|
|
29
|
+
const cache = /* @__PURE__ */new WeakMap(),
|
|
30
|
+
measureLayout = (node, relativeTo, callback) => {
|
|
31
|
+
const relativeNode = relativeTo || node?.parentNode;
|
|
32
|
+
if (relativeNode instanceof HTMLElement) {
|
|
33
|
+
const now = Date.now();
|
|
34
|
+
cache.set(node, now), Promise.all([getBoundingClientRectAsync(node), getBoundingClientRectAsync(relativeNode)]).then(([nodeDim, relativeNodeDim]) => {
|
|
35
|
+
if (relativeNodeDim && nodeDim && cache.get(node) === now) {
|
|
36
|
+
const {
|
|
37
|
+
x,
|
|
38
|
+
y,
|
|
39
|
+
width,
|
|
40
|
+
height,
|
|
41
|
+
left,
|
|
42
|
+
top
|
|
43
|
+
} = getRelativeDimensions(nodeDim, relativeNodeDim);
|
|
44
|
+
callback(x, y, width, height, left, top);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
getRelativeDimensions = (a, b) => {
|
|
50
|
+
const {
|
|
51
|
+
height,
|
|
52
|
+
left,
|
|
53
|
+
top,
|
|
54
|
+
width
|
|
55
|
+
} = a,
|
|
56
|
+
x = left - b.left,
|
|
57
|
+
y = top - b.top;
|
|
58
|
+
return {
|
|
59
|
+
x,
|
|
60
|
+
y,
|
|
61
|
+
width,
|
|
62
|
+
height,
|
|
63
|
+
left,
|
|
64
|
+
top
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
getBoundingClientRectAsync = element => new Promise(resolve => {
|
|
68
|
+
function fallbackToSync() {
|
|
69
|
+
resolve(getBoundingClientRect(element));
|
|
70
|
+
}
|
|
71
|
+
const tm = setTimeout(fallbackToSync, 10);
|
|
72
|
+
new IntersectionObserver((entries, ob) => {
|
|
73
|
+
clearTimeout(tm), ob.disconnect(), resolve(entries[0]?.boundingClientRect);
|
|
74
|
+
}, {
|
|
75
|
+
threshold: 1e-4
|
|
76
|
+
}).observe(element);
|
|
77
|
+
});
|
|
78
|
+
function useElementLayout(ref, onLayout) {
|
|
79
|
+
useIsomorphicLayoutEffect(() => {
|
|
80
|
+
if (!resizeObserver || !onLayout) return;
|
|
81
|
+
const node = ref.current;
|
|
82
|
+
if (node) return LayoutHandlers.set(node, onLayout), resizeObserver.observe(node), () => {
|
|
83
|
+
resizeObserver?.unobserve(node);
|
|
84
|
+
};
|
|
85
|
+
}, [ref, onLayout]);
|
|
86
|
+
}
|
|
87
|
+
export { measureLayout, useElementLayout };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
|
+
import { getRect } from "../helpers/getRect.mjs";
|
|
3
|
+
import { measureLayout } from "./useElementLayout.mjs";
|
|
4
|
+
function usePlatformMethods(hostRef) {
|
|
5
|
+
useIsomorphicLayoutEffect(() => {
|
|
6
|
+
const node = hostRef.current;
|
|
7
|
+
node && (node.measure ||= callback => measureLayout(node, null, callback), node.measureLayout ||= (relativeToNode, success) => measureLayout(node, relativeToNode, success), node.measureInWindow ||= callback => {
|
|
8
|
+
node && setTimeout(() => {
|
|
9
|
+
const {
|
|
10
|
+
height,
|
|
11
|
+
left,
|
|
12
|
+
top,
|
|
13
|
+
width
|
|
14
|
+
} = getRect(node);
|
|
15
|
+
callback(left, top, width, height);
|
|
16
|
+
}, 0);
|
|
17
|
+
});
|
|
18
|
+
}, [hostRef]);
|
|
19
|
+
}
|
|
20
|
+
export { usePlatformMethods };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { useResponderEvents } from "@tamagui/react-native-use-responder-events";
|
|
2
|
+
import { Stack as WebStack, Text as WebText, View as WebView, setupHooks } from "@tamagui/web";
|
|
3
|
+
import "react";
|
|
4
|
+
import "./createOptimizedView.mjs";
|
|
5
|
+
import { getBaseViews } from "./getBaseViews.mjs";
|
|
6
|
+
import { useElementLayout } from "./hooks/useElementLayout.mjs";
|
|
7
|
+
import { usePlatformMethods } from "./hooks/usePlatformMethods.mjs";
|
|
8
|
+
import "./vendor/Pressability.mjs";
|
|
9
|
+
export * from "@tamagui/web";
|
|
10
|
+
export * from "./reactNativeTypes.mjs";
|
|
11
|
+
const baseViews = getBaseViews();
|
|
12
|
+
setupHooks({
|
|
13
|
+
getBaseViews,
|
|
14
|
+
usePropsTransform(elementType, propsIn, stateRef, willHydrate) {
|
|
15
|
+
{
|
|
16
|
+
const isDOM = typeof elementType == "string",
|
|
17
|
+
{
|
|
18
|
+
// event props
|
|
19
|
+
onMoveShouldSetResponder,
|
|
20
|
+
onMoveShouldSetResponderCapture,
|
|
21
|
+
onResponderEnd,
|
|
22
|
+
onResponderGrant,
|
|
23
|
+
onResponderMove,
|
|
24
|
+
onResponderReject,
|
|
25
|
+
onResponderRelease,
|
|
26
|
+
onResponderStart,
|
|
27
|
+
onResponderTerminate,
|
|
28
|
+
onResponderTerminationRequest,
|
|
29
|
+
onScrollShouldSetResponder,
|
|
30
|
+
onScrollShouldSetResponderCapture,
|
|
31
|
+
onSelectionChangeShouldSetResponder,
|
|
32
|
+
onSelectionChangeShouldSetResponderCapture,
|
|
33
|
+
onStartShouldSetResponder,
|
|
34
|
+
onStartShouldSetResponderCapture,
|
|
35
|
+
// android
|
|
36
|
+
collapsable,
|
|
37
|
+
focusable,
|
|
38
|
+
// deprecated,
|
|
39
|
+
accessible,
|
|
40
|
+
accessibilityDisabled,
|
|
41
|
+
onLayout,
|
|
42
|
+
hrefAttrs,
|
|
43
|
+
...plainDOMProps
|
|
44
|
+
} = propsIn;
|
|
45
|
+
if (willHydrate || isDOM) {
|
|
46
|
+
const hostRef = {
|
|
47
|
+
get current() {
|
|
48
|
+
return stateRef.current.host;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
usePlatformMethods(hostRef), useElementLayout(hostRef, isDOM ? onLayout : void 0), useResponderEvents(hostRef, isDOM ? {
|
|
52
|
+
onMoveShouldSetResponder,
|
|
53
|
+
onMoveShouldSetResponderCapture,
|
|
54
|
+
onResponderEnd,
|
|
55
|
+
onResponderGrant,
|
|
56
|
+
onResponderMove,
|
|
57
|
+
onResponderReject,
|
|
58
|
+
onResponderRelease,
|
|
59
|
+
onResponderStart,
|
|
60
|
+
onResponderTerminate,
|
|
61
|
+
onResponderTerminationRequest,
|
|
62
|
+
onScrollShouldSetResponder,
|
|
63
|
+
onScrollShouldSetResponderCapture,
|
|
64
|
+
onSelectionChangeShouldSetResponder,
|
|
65
|
+
onSelectionChangeShouldSetResponderCapture,
|
|
66
|
+
onStartShouldSetResponder,
|
|
67
|
+
onStartShouldSetResponderCapture
|
|
68
|
+
} : void 0);
|
|
69
|
+
}
|
|
70
|
+
if (isDOM) {
|
|
71
|
+
if (plainDOMProps.href && hrefAttrs) {
|
|
72
|
+
const {
|
|
73
|
+
download,
|
|
74
|
+
rel,
|
|
75
|
+
target
|
|
76
|
+
} = hrefAttrs;
|
|
77
|
+
download != null && (plainDOMProps.download = download), rel && (plainDOMProps.rel = rel), typeof target == "string" && (plainDOMProps.target = target.charAt(0) !== "_" ? `_${target}` : target);
|
|
78
|
+
}
|
|
79
|
+
return plainDOMProps;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
useEvents(viewProps, events, {
|
|
84
|
+
pseudos
|
|
85
|
+
}, setStateShallow, staticConfig) {}
|
|
86
|
+
});
|
|
87
|
+
const View = WebView,
|
|
88
|
+
Stack = WebStack,
|
|
89
|
+
Text = WebText;
|
|
90
|
+
export { Stack, Text, View };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const stylesheets = {},
|
|
2
|
+
injectStyles = ({
|
|
3
|
+
filePath,
|
|
4
|
+
css
|
|
5
|
+
}) => {
|
|
6
|
+
let stylesheet = stylesheets[filePath];
|
|
7
|
+
if (!stylesheet) {
|
|
8
|
+
const styleEl = document.createElement("style");
|
|
9
|
+
styleEl.setAttribute("data-file", filePath), styleEl.setAttribute("type", "text/css"), stylesheet = stylesheets[filePath] = styleEl, document.head.appendChild(styleEl);
|
|
10
|
+
}
|
|
11
|
+
stylesheet.innerHTML = css;
|
|
12
|
+
};
|
|
13
|
+
export { injectStyles };
|
|
File without changes
|
package/dist/native.js
CHANGED
|
@@ -4077,7 +4077,7 @@ var require_getSplitStyles_native = __commonJS({
|
|
|
4077
4077
|
continue;
|
|
4078
4078
|
let shouldPassProp = !isStyleProp || // is in parent variants
|
|
4079
4079
|
isHOC && (parentStaticConfig == null ? void 0 : parentStaticConfig.variants) && keyInit in parentStaticConfig.variants || (inlineProps == null ? void 0 : inlineProps.has(keyInit)), parentVariant = (_a = parentStaticConfig == null ? void 0 : parentStaticConfig.variants) == null ? void 0 : _a[keyInit], isHOCShouldPassThrough = !!(isHOC && (isShorthand || isValidStyleKeyInit || isMediaOrPseudo || parentVariant || keyInit in skipProps)), shouldPassThrough = shouldPassProp || isHOCShouldPassThrough;
|
|
4080
|
-
if (process.env.NODE_ENV === "development" && debug === "verbose" && (console.groupCollapsed(
|
|
4080
|
+
if (process.env.NODE_ENV === "development" && debug === "verbose" && (console.groupEnd(), console.groupEnd(), console.groupCollapsed(
|
|
4081
4081
|
` \u{1F511} ${keyOg}${keyInit !== keyOg ? ` (shorthand for ${keyInit})` : ""} ${shouldPassThrough ? "(pass)" : ""}`
|
|
4082
4082
|
), (0, import_log.log)({ isVariant, valInit, shouldPassProp }), import_constants.isClient && (0, import_log.log)({
|
|
4083
4083
|
variants,
|
|
@@ -4862,7 +4862,11 @@ var require_createComponent_native = __commonJS({
|
|
|
4862
4862
|
let exv = exitVariant ?? enterExitVariant, env = enterVariant ?? enterExitVariant;
|
|
4863
4863
|
state.unmounted && env && staticConfig.variants[env] ? (process.env.NODE_ENV === "development" && debugProp === "verbose" && console.warn(`Animating presence ENTER "${env}"`), props[env] = !0) : isExiting && exv && (process.env.NODE_ENV === "development" && debugProp === "verbose" && console.warn(`Animating presence EXIT "${exv}"`), props[exv] = exitVariant !== enterExitVariant);
|
|
4864
4864
|
}
|
|
4865
|
-
let shouldAvoidClasses = !!(!import_constants.isWeb || isAnimated && !supportsCSSVars || !staticConfig.acceptsClassName ||
|
|
4865
|
+
let shouldAvoidClasses = !!(!import_constants.isWeb || isAnimated && !supportsCSSVars || !staticConfig.acceptsClassName || // on server for SSR and animation compat added the && isHydrated but perhaps we want
|
|
4866
|
+
// disableClassName="until-hydrated" to be more straightforward
|
|
4867
|
+
// see issue if not, Button sets disableClassName to true <Button animation="" /> with
|
|
4868
|
+
// the react-native driver errors because it tries to animate var(--color) to rbga(..)
|
|
4869
|
+
propsIn.disableClassName && isHydrated), shouldForcePseudo = !!propsIn.forceStyle, noClassNames = shouldAvoidClasses || shouldForcePseudo, groupName = props.group, groupClassName = groupName ? `t_group_${props.group}` : "";
|
|
4866
4870
|
if (groupName && !curState.group) {
|
|
4867
4871
|
let listeners = /* @__PURE__ */ new Set();
|
|
4868
4872
|
curState.group = {
|
|
@@ -4910,7 +4914,9 @@ var require_createComponent_native = __commonJS({
|
|
|
4910
4914
|
if (console.info(
|
|
4911
4915
|
`%c ${banner} (hydrated: ${isHydrated}) (unmounted: ${state.unmounted})`,
|
|
4912
4916
|
"background: green; color: white;"
|
|
4913
|
-
),
|
|
4917
|
+
), import_constants.isServer)
|
|
4918
|
+
(0, import_log.log)({ noClassNames, isAnimated, shouldAvoidClasses, isWeb: import_constants.isWeb, supportsCSSVars });
|
|
4919
|
+
else {
|
|
4914
4920
|
console.groupEnd();
|
|
4915
4921
|
let stateLog = `${`${state.press || state.pressIn ? " PRESS " : ""}`}${state.hover ? " HOVER " : ""}${state.focus ? " FOCUS" : " "}`, ch = propsIn.children, childLog = typeof ch == "string" ? ch.length > 4 ? ch.slice(0, 4) + "..." : ch : "";
|
|
4916
4922
|
childLog.length && (childLog = `(children: ${childLog})`), console.groupCollapsed(`${childLog}${stateLog}Props:`), (0, import_log.log)("props in:", propsIn), (0, import_log.log)("final props:", props), (0, import_log.log)({ state, staticConfig, elementType, themeStateProps }), (0, import_log.log)({ contextProps: styledContextProps, overriddenContextProps }), (0, import_log.log)({ presence, isAnimated, isHOC, hasAnimationProp, useAnimations }), console.groupEnd();
|