@tamagui/animations-css 1.74.3 → 1.74.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,96 @@
1
+ import {
2
+ Stack,
3
+ Text,
4
+ useIsomorphicLayoutEffect
5
+ } from "@tamagui/core";
6
+ import { animate } from "@tamagui/cubic-bezier-animator";
7
+ import { usePresence } from "@tamagui/use-presence";
8
+ import { useRef, useState } from "react";
9
+ function createAnimations(animations) {
10
+ return {
11
+ View: Stack,
12
+ Text,
13
+ animations,
14
+ usePresence,
15
+ supportsCSSVars: !0,
16
+ useAnimatedNumber(initial) {
17
+ const [val, setVal] = useState(initial);
18
+ return {
19
+ getInstance() {
20
+ return val;
21
+ },
22
+ getValue() {
23
+ return val;
24
+ },
25
+ setValue(next) {
26
+ setVal(next);
27
+ },
28
+ stop() {
29
+ }
30
+ };
31
+ },
32
+ useAnimatedNumberReaction({ hostRef, value }, onValue) {
33
+ useIsomorphicLayoutEffect(() => {
34
+ if (!hostRef.current)
35
+ return;
36
+ const onTransitionEvent = (e) => {
37
+ onValue(value.getValue());
38
+ }, node = hostRef.current;
39
+ return node.addEventListener("transitionstart", onTransitionEvent), node.addEventListener("transitioncancel", onTransitionEvent), node.addEventListener("transitionend", onTransitionEvent), () => {
40
+ node.removeEventListener("transitionstart", onTransitionEvent), node.removeEventListener("transitioncancel", onTransitionEvent), node.removeEventListener("transitionend", onTransitionEvent);
41
+ };
42
+ }, [hostRef, onValue]);
43
+ },
44
+ useAnimatedNumberStyle(val, getStyle) {
45
+ return getStyle(val.getValue());
46
+ },
47
+ useAnimations: ({ props, presence, style, componentState, hostRef }) => {
48
+ const isEntering = !!componentState.unmounted, isExiting = presence?.[0] === !1, sendExitComplete = presence?.[1], initialPositionRef = useRef(null), animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation, animation = animations[animationKey], keys = props.animateOnly ? props.animateOnly.join(" ") : "all";
49
+ return useIsomorphicLayoutEffect(() => {
50
+ if (!sendExitComplete || !isExiting || !hostRef.current)
51
+ return;
52
+ const node = hostRef.current, onFinishAnimation = () => {
53
+ sendExitComplete?.();
54
+ };
55
+ return node.addEventListener("transitionend", onFinishAnimation), node.addEventListener("transitioncancel", onFinishAnimation), () => {
56
+ node.removeEventListener("transitionend", onFinishAnimation), node.removeEventListener("transitioncancel", onFinishAnimation);
57
+ };
58
+ }, [sendExitComplete, isExiting]), useIsomorphicLayoutEffect(() => {
59
+ if (!hostRef.current || !props.layout)
60
+ return;
61
+ const boundingBox = hostRef.current?.getBoundingClientRect();
62
+ if (isChanged(initialPositionRef.current, boundingBox)) {
63
+ const transform = invert(
64
+ hostRef.current,
65
+ boundingBox,
66
+ initialPositionRef.current
67
+ );
68
+ animate({
69
+ from: transform,
70
+ to: { x: 0, y: 0, scaleX: 1, scaleY: 1 },
71
+ duration: 1e3,
72
+ onUpdate: ({ x, y, scaleX, scaleY }) => {
73
+ hostRef.current.style.transform = `translate(${x}px, ${y}px) scaleX(${scaleX}) scaleY(${scaleY})`;
74
+ },
75
+ // TODO: extract ease-in from string and convert/map it to a cubicBezier array
76
+ cubicBezier: [0, 1.38, 1, -0.41]
77
+ });
78
+ }
79
+ initialPositionRef.current = boundingBox;
80
+ }), animation ? (style.transition = `${keys} ${animation}${props.layout ? ",width 0s, height 0s, margin 0s, padding 0s, transform" : ""}`, process.env.NODE_ENV === "development" && props.debug && console.log("CSS animation", style, { isEntering, isExiting }), { style }) : null;
81
+ }
82
+ };
83
+ }
84
+ const isChanged = (initialBox, finalBox) => !initialBox || !finalBox ? !1 : JSON.stringify(initialBox) !== JSON.stringify(finalBox), invert = (el, from, to) => {
85
+ const { x: fromX, y: fromY, width: fromWidth, height: fromHeight } = from, { x, y, width, height } = to, transform = {
86
+ x: x - fromX - (fromWidth - width) / 2,
87
+ y: y - fromY - (fromHeight - height) / 2,
88
+ scaleX: width / fromWidth,
89
+ scaleY: height / fromHeight
90
+ };
91
+ return el.style.transform = `translate(${transform.x}px, ${transform.y}px) scaleX(${transform.scaleX}) scaleY(${transform.scaleY})`, transform;
92
+ };
93
+ export {
94
+ createAnimations
95
+ };
96
+ //# sourceMappingURL=createAnimations.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/createAnimations.tsx"],
4
+ "mappings": "AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAC5B,SAAS,QAAQ,gBAAgB;AAE1B,SAAS,iBAAmC,YAAmC;AACpF,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,IAEjB,kBAAkB,SAA0C;AAC1D,YAAM,CAAC,KAAK,MAAM,IAAI,SAAS,OAAO;AAEtC,aAAO;AAAA,QACL,cAAc;AACZ,iBAAO;AAAA,QACT;AAAA,QACA,WAAW;AACT,iBAAO;AAAA,QACT;AAAA,QACA,SAAS,MAAM;AACb,iBAAO,IAAI;AAAA,QACb;AAAA,QACA,OAAO;AAAA,QAAC;AAAA,MACV;AAAA,IACF;AAAA,IAEA,0BAA0B,EAAE,SAAS,MAAM,GAAG,SAAS;AAErD,gCAA0B,MAAM;AAC9B,YAAI,CAAC,QAAQ;AAAS;AACtB,cAAM,oBAAoB,CAAC,MAAuB;AAChD,kBAAQ,MAAM,SAAS,CAAC;AAAA,QAC1B,GAEM,OAAO,QAAQ;AACrB,oBAAK,iBAAiB,mBAAmB,iBAAiB,GAC1D,KAAK,iBAAiB,oBAAoB,iBAAiB,GAC3D,KAAK,iBAAiB,iBAAiB,iBAAiB,GACjD,MAAM;AACX,eAAK,oBAAoB,mBAAmB,iBAAiB,GAC7D,KAAK,oBAAoB,oBAAoB,iBAAiB,GAC9D,KAAK,oBAAoB,iBAAiB,iBAAiB;AAAA,QAC7D;AAAA,MACF,GAAG,CAAC,SAAS,OAAO,CAAC;AAAA,IACvB;AAAA,IAEA,uBAA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,MAAM,YAAY,aAAa,CAAC,OAAO,CAAC,cAAc,MAAM,YAAY,MAAM;AAAA,YAKhG;AAAA;AAAA,YAEA,aAAa,CAAC,GAAG,MAAM,GAAG,KAAK;AAAA,UACjC,CAAC;AAAA,QACH;AACA,2BAAmB,UAAU;AAAA,MAC/B,CAAC,GAEI,aAOL,MAAM,aAAa,GAAG,IAAI,IAAI,SAAS,GACrC,MAAM,SAAS,2DAA2D,EAC5E,IAEI,QAAQ,IAAI,aAAa,iBAAiB,MAAM,SAElD,QAAQ,IAAI,iBAAiB,OAAO,EAAE,YAAY,UAAU,CAAC,GAGxD,EAAE,MAAM,KAfN;AAAA,IAgBX;AAAA,EACF;AACF;AAEA,MAAM,YAAY,CAAC,YAAiB,aAE9B,CAAC,cAAc,CAAC,WAAiB,KAG9B,KAAK,UAAU,UAAU,MAAM,KAAK,UAAU,QAAQ,GAGzD,SAAS,CAAC,IAAI,MAAM,OAAO;AAC/B,QAAM,EAAE,GAAG,OAAO,GAAG,OAAO,OAAO,WAAW,QAAQ,WAAW,IAAI,MAC/D,EAAE,GAAG,GAAG,OAAO,OAAO,IAAI,IAE1B,YAAY;AAAA,IAChB,GAAG,IAAI,SAAS,YAAY,SAAS;AAAA,IACrC,GAAG,IAAI,SAAS,aAAa,UAAU;AAAA,IACvC,QAAQ,QAAQ;AAAA,IAChB,QAAQ,SAAS;AAAA,EACnB;AAEA,YAAG,MAAM,YAAY,aAAa,UAAU,CAAC,OAAO,UAAU,CAAC,cAAc,UAAU,MAAM,YAAY,UAAU,MAAM,KAElH;AACT;",
5
+ "names": []
6
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./createAnimations";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.tsx"],
4
+ "mappings": "AAAA,cAAc;",
5
+ "names": []
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/animations-css",
3
- "version": "1.74.3",
3
+ "version": "1.74.5",
4
4
  "source": "src/index.ts",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",
@@ -13,12 +13,12 @@
13
13
  "dist"
14
14
  ],
15
15
  "dependencies": {
16
- "@tamagui/cubic-bezier-animator": "1.74.3",
17
- "@tamagui/use-presence": "1.74.3",
18
- "@tamagui/web": "1.74.3"
16
+ "@tamagui/cubic-bezier-animator": "1.74.5",
17
+ "@tamagui/use-presence": "1.74.5",
18
+ "@tamagui/web": "1.74.5"
19
19
  },
20
20
  "devDependencies": {
21
- "@tamagui/build": "1.74.3"
21
+ "@tamagui/build": "1.74.5"
22
22
  },
23
23
  "scripts": {
24
24
  "build": "tamagui-build",