@lynx-js/lynx-ui-presence 3.135.3 → 3.136.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @lynx-js/lynx-ui-presence
2
2
 
3
+ ## 3.136.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`0257f8b`](https://github.com/lynx-family/lynx-ui/commit/0257f8bc9fbe6b8a51df00663c7860827ce468b2)]:
8
+ - @lynx-js/lynx-ui-common@3.136.0
9
+
10
+ ## 3.135.4
11
+
12
+ ### Patch Changes
13
+
14
+ - Upgrade the Lynx and Rsbuild toolchain dependencies used to build lynx-ui packages. ([#233](https://github.com/lynx-family/lynx-ui/pull/233))
15
+
16
+ - Adopt the workspace catalog for `@rslib/core` to prevent package-level version drift. ([#233](https://github.com/lynx-family/lynx-ui/pull/233))
17
+
18
+ - Updated dependencies [[`753556b`](https://github.com/lynx-family/lynx-ui/commit/753556bc1acb77e05567aba3b8b5ab057b9f670b)]:
19
+ - @lynx-js/lynx-ui-common@3.135.4
20
+
3
21
  ## 3.135.3
4
22
 
5
23
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"Presence.jsx","sources":["webpack://@lynx-js/lynx-ui-presence/./src/Presence.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { createContext, useState } from '@lynx-js/react'\n\nimport type {\n PresenceAnimationStatus,\n PresenceContextType,\n PresenceProps,\n} from './types'\nimport { usePresence } from './usePresence'\nimport { PresenceState, resolveAnimationStatus } from './utils'\n\nexport const PresenceContext = createContext<PresenceContextType>(null!)\n\nexport const renderPresenceChildren = (\n props: {\n children: PresenceProps['children']\n status: PresenceAnimationStatus\n },\n) => {\n const { children, status } = props\n return typeof children === 'function'\n ? children(status)\n : children\n}\n\nexport function Presence(props: PresenceProps) {\n const {\n show,\n forceMount,\n state,\n setPresenceState,\n children,\n enableDelay = false,\n onOpen,\n onClose,\n debugLog,\n } = props\n const [internalState, setInternalState] = useState<PresenceState>(\n PresenceState.Left,\n )\n const presence = usePresence({\n show,\n state: state ?? internalState,\n setPresenceState: setPresenceState ?? setInternalState,\n enableDelay,\n onOpen,\n onClose,\n debugLog,\n })\n const { mount } = presence.controllers\n const status = resolveAnimationStatus({\n state: state ?? internalState,\n enableDelay,\n })\n\n return (\n <PresenceContext.Provider value={presence}>\n {(mount || forceMount) && renderPresenceChildren({ children, status })}\n </PresenceContext.Provider>\n )\n}\n"],"names":["PresenceContext","createContext","renderPresenceChildren","props","children","status","Presence","show","forceMount","state","setPresenceState","enableDelay","onOpen","onClose","debugLog","internalState","setInternalState","useState","PresenceState","presence","usePresence","mount","resolveAnimationStatus"],"mappings":";;;AAcO,MAAMA,kBAAkBC,cAAmC;AAE3D,MAAMC,yBAAyB,CACpCC;IAKA,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAGF;IAC7B,OAAO,AAAoB,cAApB,OAAOC,WACVA,SAASC,UACTD;AACN;AAEO,SAASE,SAASH,KAAoB;IAC3C,MAAM,EACJI,IAAI,EACJC,UAAU,EACVC,KAAK,EACLC,gBAAgB,EAChBN,QAAQ,EACRO,cAAc,KAAK,EACnBC,MAAM,EACNC,OAAO,EACPC,QAAQ,EACT,GAAGX;IACJ,MAAM,CAACY,eAAeC,iBAAiB,GAAGC,SACxCC,cAAc,IAAI;IAEpB,MAAMC,WAAWC,YAAY;QAC3Bb;QACA,OAAOE,SAASM;QAChB,kBAAkBL,oBAAoBM;QACtCL;QACAC;QACAC;QACAC;IACF;IACA,MAAM,EAAEO,KAAK,EAAE,GAAGF,SAAS,WAAW;IACtC,MAAMd,SAASiB,uBAAuB;QACpC,OAAOb,SAASM;QAChBJ;IACF;IAEA,QACGX,gBAAgB,SAAS,OAAOmB,UAAU;MACzC,CAAEE,AAAAA,CAAAA,SAASb,UAAS,KAAMN,uBAAuB;QAAEE;QAAUC;IAAO,GAAG;IACzE,EAAEL,gBAAgB;AAEtB"}
1
+ {"version":3,"file":"Presence.jsx","sources":["../src/Presence.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { createContext, useState } from '@lynx-js/react'\n\nimport type {\n PresenceAnimationStatus,\n PresenceContextType,\n PresenceProps,\n} from './types'\nimport { usePresence } from './usePresence'\nimport { PresenceState, resolveAnimationStatus } from './utils'\n\nexport const PresenceContext = createContext<PresenceContextType>(null!)\n\nexport const renderPresenceChildren = (\n props: {\n children: PresenceProps['children']\n status: PresenceAnimationStatus\n },\n) => {\n const { children, status } = props\n return typeof children === 'function'\n ? children(status)\n : children\n}\n\nexport function Presence(props: PresenceProps) {\n const {\n show,\n forceMount,\n state,\n setPresenceState,\n children,\n enableDelay = false,\n onOpen,\n onClose,\n debugLog,\n } = props\n const [internalState, setInternalState] = useState<PresenceState>(\n PresenceState.Left,\n )\n const presence = usePresence({\n show,\n state: state ?? internalState,\n setPresenceState: setPresenceState ?? setInternalState,\n enableDelay,\n onOpen,\n onClose,\n debugLog,\n })\n const { mount } = presence.controllers\n const status = resolveAnimationStatus({\n state: state ?? internalState,\n enableDelay,\n })\n\n return (\n <PresenceContext.Provider value={presence}>\n {(mount || forceMount) && renderPresenceChildren({ children, status })}\n </PresenceContext.Provider>\n )\n}\n"],"names":["PresenceContext","createContext","renderPresenceChildren","props","children","status","Presence","show","forceMount","state","setPresenceState","enableDelay","onOpen","onClose","debugLog","internalState","setInternalState","useState","PresenceState","presence","usePresence","mount","resolveAnimationStatus"],"mappings":";;;AAcO,MAAMA,kBAAkBC,cAAmC;AAE3D,MAAMC,yBAAyB,CACpCC;IAKA,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAGF;IAC7B,OAAO,AAAoB,cAApB,OAAOC,WACVA,SAASC,UACTD;AACN;AAEO,SAASE,SAASH,KAAoB;IAC3C,MAAM,EACJI,IAAI,EACJC,UAAU,EACVC,KAAK,EACLC,gBAAgB,EAChBN,QAAQ,EACRO,cAAc,KAAK,EACnBC,MAAM,EACNC,OAAO,EACPC,QAAQ,EACT,GAAGX;IACJ,MAAM,CAACY,eAAeC,iBAAiB,GAAGC,SACxCC,cAAc,IAAI;IAEpB,MAAMC,WAAWC,YAAY;QAC3Bb;QACA,OAAOE,SAASM;QAChB,kBAAkBL,oBAAoBM;QACtCL;QACAC;QACAC;QACAC;IACF;IACA,MAAM,EAAEO,KAAK,EAAE,GAAGF,SAAS,WAAW;IACtC,MAAMd,SAASiB,uBAAuB;QACpC,OAAOb,SAASM;QAChBJ;IACF;IAEA,QACGX,gBAAgB,SAAS,OAAOmB,UAAU;MACzC,CAAEE,AAAAA,CAAAA,SAASb,UAAS,KAAMN,uBAAuB;QAAEE;QAAUC;IAAO,GAAG;IACzE,EAAEL,gBAAgB;AAEtB"}
package/dist/index.jsx CHANGED
@@ -1,5 +1,4 @@
1
- import { Presence, PresenceContext, renderPresenceChildren } from "./Presence.jsx";
2
- import { PresenceState, presenceClassVariants, resolveAnimationStatus } from "./utils.jsx";
3
- import { usePresenceGroup } from "./usePresenceGroup.jsx";
4
- import { useVisibilityFromPresence } from "./useVisibilityFromPresence.jsx";
5
- export { Presence, PresenceContext, PresenceState, presenceClassVariants, renderPresenceChildren, resolveAnimationStatus, usePresenceGroup, useVisibilityFromPresence };
1
+ export { Presence, PresenceContext, renderPresenceChildren } from "./Presence.jsx";
2
+ export { PresenceState, presenceClassVariants, resolveAnimationStatus } from "./utils.jsx";
3
+ export { usePresenceGroup } from "./usePresenceGroup.jsx";
4
+ export { useVisibilityFromPresence } from "./useVisibilityFromPresence.jsx";
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -1 +1 @@
1
- {"version":3,"file":"usePresence.jsx","sources":["webpack://@lynx-js/lynx-ui-presence/./src/usePresence.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { createContext, useEffect, useRef, useState } from '@lynx-js/react'\n\nimport { delayFrames, log } from '@lynx-js/lynx-ui-common'\nimport type { AnimationEvent, TransitionEvent } from '@lynx-js/types'\n\nimport type {\n PresenceAnimationStatus,\n PresenceContextType,\n PresenceProps,\n usePresenceProps,\n usePresenceReturnType,\n} from './types'\nimport { PresenceState } from './utils'\n\nexport const PresenceContext = createContext<PresenceContextType>(null!)\n\nexport function usePresence(props: usePresenceProps): usePresenceReturnType {\n const {\n show,\n state,\n enableDelay = false,\n setPresenceState,\n onOpen,\n onClose,\n debugLog = false,\n } = props\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] init, show: ${show}, state: ${state}, enableDelay: ${enableDelay}`,\n )\n const enteringStateWithDelay = enableDelay\n ? PresenceState.DelayedEntering\n : PresenceState.Entering\n\n const isTransitionAnimating = useRef<boolean>(false)\n const isKFAnimating = useRef<boolean>(false)\n // Track the initial render, to prevent effects from running on mount.\n const isInitialRender = useRef(true)\n const hasNotifiedOpen = useRef(false)\n const showRef = useRef(show)\n // The core state to control the mounting and unmounting of the component.\n const [mount, setMount] = useState<boolean>(false)\n // These three id record the loop ID for the entering progress animation and show state to prevent race conditions.\n const enteringLoopIdRef = useRef<number>(0)\n const leavingLoopIdRef = useRef<number>(0)\n const showScheduleIdRef = useRef(0)\n // Two timing windows to wait for the animation to start before forcing a state change.\n const enteringWaitFramesRef = useRef<number>(0)\n const leavingWaitFramesRef = useRef<number>(0)\n\n // The maximum number of frames to wait for an animation to start before forcing a state change.\n const MAX_WAIT_FRAMES = 24\n\n showRef.current = show\n\n const cancelShowTimer = () => {\n showScheduleIdRef.current += 1\n }\n\n const cancelEnteringWait = () => {\n enteringLoopIdRef.current += 1\n }\n\n const cancelLeavingWait = () => {\n leavingLoopIdRef.current += 1\n }\n\n const scheduleShow = () => {\n const scheduleId = showScheduleIdRef.current\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] set mount=true',\n )\n setMount(true)\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] schedule set Entering in 8 frames',\n )\n delayFrames(8, () => {\n if (scheduleId !== showScheduleIdRef.current || !showRef.current) return\n setPresenceState(PresenceState.Entering)\n })\n if (enableDelay) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] schedule set DelayedEntering in 16 frames',\n )\n delayFrames(16, () => {\n if (scheduleId !== showScheduleIdRef.current || !showRef.current) {\n return\n }\n setPresenceState(PresenceState.DelayedEntering)\n })\n }\n }\n\n const restartShow = () => {\n cancelShowTimer()\n scheduleShow()\n }\n\n const notAnimating = () => (isKFAnimating.current === false\n && isTransitionAnimating.current === false)\n\n const handleAnimationStart = () => {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] handleAnimationStart state:${state}, show:${show}, isTransition:${isTransitionAnimating.current}, isKFAnimating:${isKFAnimating.current}`,\n )\n }\n\n const handleAnimationEnd = () => {\n // still need to check if the other kind of animation is running.\n if (\n (state === PresenceState.Entering\n || state === PresenceState.DelayedEntering)\n && notAnimating()\n ) {\n if (showRef.current) {\n setPresenceState(PresenceState.Entered)\n } else {\n // Safeguard: entering animation may still fire after show turns false.\n // Why not Left? Because Left will also cancel the ongoing leaving animation.\n setPresenceState(PresenceState.Leaving)\n }\n }\n if (state === PresenceState.Leaving && notAnimating()) {\n cancelLeavingWait()\n if (showRef.current) {\n restartShow()\n } else {\n setPresenceState(PresenceState.Left)\n }\n }\n }\n\n // ==== Animation events =====\n const handleKFStart = () => {\n isKFAnimating.current = true\n enteringLoopIdRef.current += 1\n leavingLoopIdRef.current += 1\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] KF start, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationStart()\n }\n\n const handleTransitionStart = () => {\n isTransitionAnimating.current = true\n enteringLoopIdRef.current += 1\n leavingLoopIdRef.current += 1\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] Transition start, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationStart()\n }\n\n const handleKFEnd = (_e: AnimationEvent) => {\n isKFAnimating.current = false\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] KF end, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationEnd()\n }\n\n const handleKFCancel = () => {\n isKFAnimating.current = false\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] KF cancel, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationEnd()\n }\n\n const handleTransitionCancel = () => {\n isTransitionAnimating.current = false\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] Transition cancel, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationEnd()\n }\n\n const handleTransitionEnd = (_e: TransitionEvent) => {\n isTransitionAnimating.current = false\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] Transition end, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationEnd()\n }\n\n // ==== state controller ====\n const handleStateEntered = () => {\n if (hasNotifiedOpen.current) {\n return\n }\n hasNotifiedOpen.current = true\n onOpen?.()\n }\n\n const handleStateLeft = () => {\n if (showRef.current) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] skip mount=false because show=true (Left)',\n )\n restartShow()\n return\n }\n if (!isInitialRender.current && hasNotifiedOpen.current) {\n hasNotifiedOpen.current = false\n onClose?.()\n }\n log(debugLog, '[lynx-ui-presence][usePresence] set mount=false (Left)')\n setMount(false)\n }\n\n const handleStateLeaving = () => {\n cancelEnteringWait()\n leavingWaitFramesRef.current = 0\n leavingLoopIdRef.current += 1\n const loopId = leavingLoopIdRef.current\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] leaving loop scheduled, loopId: ${loopId}`,\n )\n const tryLeft = () => {\n // The loopId is inconsistent with the current animation state, means the animation started during the delay period, so we should stop this trying.\n if (loopId !== leavingLoopIdRef.current) return\n if (!notAnimating()) return\n // timeout reached => treat as no animation\n if (leavingWaitFramesRef.current >= MAX_WAIT_FRAMES) {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] leaving timeout reached, loopId: ${loopId}, frames: ${leavingWaitFramesRef.current}`,\n )\n if (showRef.current) {\n restartShow()\n } else {\n setPresenceState(PresenceState.Left)\n }\n return\n }\n leavingWaitFramesRef.current += 1\n delayFrames(1, tryLeft)\n }\n\n delayFrames(1, tryLeft)\n }\n\n const handleStateEnteringWithDelay = () => {\n cancelLeavingWait()\n enteringWaitFramesRef.current = 0\n enteringLoopIdRef.current += 1\n const loopId = enteringLoopIdRef.current\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] entering loop scheduled, loopId: ${loopId}`,\n )\n const tryEntered = () => {\n // The loopId is inconsistent with the current animation state, means the animation started during the delay period, so we should stop this trying.\n if (loopId !== enteringLoopIdRef.current) return\n if (!notAnimating()) return\n if (enteringWaitFramesRef.current >= MAX_WAIT_FRAMES) {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] entering timeout reached, loopId: ${loopId}, frames: ${enteringWaitFramesRef.current}`,\n )\n if (showRef.current) {\n setPresenceState(PresenceState.Entered)\n } else {\n setPresenceState(PresenceState.Leaving)\n }\n return\n }\n enteringWaitFramesRef.current += 1\n delayFrames(1, tryEntered)\n }\n\n delayFrames(1, tryEntered)\n }\n\n useEffect(() => {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] state effect, state: ${state}, show: ${show}, enableDelay: ${enableDelay}, isTransitionAnimating: ${isTransitionAnimating.current}, isKFAnimating: ${isKFAnimating.current}`,\n )\n if (state === PresenceState.Entered) {\n handleStateEntered()\n }\n if (state === PresenceState.Left) {\n handleStateLeft()\n }\n if (state === PresenceState.Leaving) {\n handleStateLeaving()\n }\n if (state === enteringStateWithDelay) {\n handleStateEnteringWithDelay()\n }\n }, [state])\n\n // ==== Show change part ====\n const handleDismiss = () => {\n if (\n state === PresenceState.Entered || state === PresenceState.Entering\n || state === PresenceState.DelayedEntering\n ) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] show=false -> set PresenceState.Leaving',\n )\n cancelEnteringWait()\n setPresenceState(PresenceState.Leaving)\n } else if (\n (state === PresenceState.Initial || state === PresenceState.Left) && mount\n ) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] show=false before entering -> set mount=false',\n )\n setMount(false)\n }\n }\n\n useEffect(() => {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] show effect show:${show}, enableDelay:${enableDelay}, state:${state}, mount:${mount}`,\n )\n if (show) {\n restartShow()\n } else {\n cancelShowTimer()\n handleDismiss()\n }\n }, [show, enableDelay])\n\n useEffect(() => {\n isInitialRender.current = false\n }, [])\n\n return {\n controllers: { state, mount, setPresenceState },\n animationHandlers: {\n handleKFStart,\n handleKFCancel,\n handleKFEnd,\n handleTransitionStart,\n handleTransitionCancel,\n handleTransitionEnd,\n },\n }\n}\n\nexport const renderPresenceChildren = (\n props: {\n children: PresenceProps['children']\n status: PresenceAnimationStatus\n },\n) => {\n const { children, status } = props\n return typeof children === 'function'\n ? children(status)\n : children\n}\n"],"names":["PresenceContext","createContext","usePresence","props","show","state","enableDelay","setPresenceState","onOpen","onClose","debugLog","log","enteringStateWithDelay","PresenceState","isTransitionAnimating","useRef","isKFAnimating","isInitialRender","hasNotifiedOpen","showRef","mount","setMount","useState","enteringLoopIdRef","leavingLoopIdRef","showScheduleIdRef","enteringWaitFramesRef","leavingWaitFramesRef","MAX_WAIT_FRAMES","cancelShowTimer","cancelEnteringWait","cancelLeavingWait","scheduleShow","scheduleId","delayFrames","restartShow","notAnimating","handleAnimationStart","handleAnimationEnd","handleKFStart","handleTransitionStart","handleKFEnd","_e","handleKFCancel","handleTransitionCancel","handleTransitionEnd","handleStateEntered","handleStateLeft","handleStateLeaving","loopId","tryLeft","handleStateEnteringWithDelay","tryEntered","useEffect","handleDismiss","renderPresenceChildren","children","status"],"mappings":";;;AAkBO,MAAMA,kBAAkBC,cAAmC;AAE3D,SAASC,YAAYC,KAAuB;IAC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,EAAEe,OAAO;QAExH,IAAIhB,MACF+B;aACK;YACLN;YACAyB;QACF;IACF,GAAG;QAAClD;QAAME;KAAY;IAEtB+C,UAAU;QACRpC,gBAAgB,OAAO,GAAG;IAC5B,GAAG,EAAE;IAEL,OAAO;QACL,aAAa;YAAEZ;YAAOe;YAAOb;QAAiB;QAC9C,mBAAmB;YACjBgC;YACAI;YACAF;YACAD;YACAI;YACAC;QACF;IACF;AACF;AAEO,MAAMU,yBAAyB,CACpCpD;IAKA,MAAM,EAAEqD,QAAQ,EAAEC,MAAM,EAAE,GAAGtD;IAC7B,OAAO,AAAoB,cAApB,OAAOqD,WACVA,SAASC,UACTD;AACN"}
1
+ {"version":3,"file":"usePresence.jsx","sources":["../src/usePresence.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { createContext, useEffect, useRef, useState } from '@lynx-js/react'\n\nimport { delayFrames, log } from '@lynx-js/lynx-ui-common'\nimport type { AnimationEvent, TransitionEvent } from '@lynx-js/types'\n\nimport type {\n PresenceAnimationStatus,\n PresenceContextType,\n PresenceProps,\n usePresenceProps,\n usePresenceReturnType,\n} from './types'\nimport { PresenceState } from './utils'\n\nexport const PresenceContext = createContext<PresenceContextType>(null!)\n\nexport function usePresence(props: usePresenceProps): usePresenceReturnType {\n const {\n show,\n state,\n enableDelay = false,\n setPresenceState,\n onOpen,\n onClose,\n debugLog = false,\n } = props\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] init, show: ${show}, state: ${state}, enableDelay: ${enableDelay}`,\n )\n const enteringStateWithDelay = enableDelay\n ? PresenceState.DelayedEntering\n : PresenceState.Entering\n\n const isTransitionAnimating = useRef<boolean>(false)\n const isKFAnimating = useRef<boolean>(false)\n // Track the initial render, to prevent effects from running on mount.\n const isInitialRender = useRef(true)\n const hasNotifiedOpen = useRef(false)\n const showRef = useRef(show)\n // The core state to control the mounting and unmounting of the component.\n const [mount, setMount] = useState<boolean>(false)\n // These three id record the loop ID for the entering progress animation and show state to prevent race conditions.\n const enteringLoopIdRef = useRef<number>(0)\n const leavingLoopIdRef = useRef<number>(0)\n const showScheduleIdRef = useRef(0)\n // Two timing windows to wait for the animation to start before forcing a state change.\n const enteringWaitFramesRef = useRef<number>(0)\n const leavingWaitFramesRef = useRef<number>(0)\n\n // The maximum number of frames to wait for an animation to start before forcing a state change.\n const MAX_WAIT_FRAMES = 24\n\n showRef.current = show\n\n const cancelShowTimer = () => {\n showScheduleIdRef.current += 1\n }\n\n const cancelEnteringWait = () => {\n enteringLoopIdRef.current += 1\n }\n\n const cancelLeavingWait = () => {\n leavingLoopIdRef.current += 1\n }\n\n const scheduleShow = () => {\n const scheduleId = showScheduleIdRef.current\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] set mount=true',\n )\n setMount(true)\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] schedule set Entering in 8 frames',\n )\n delayFrames(8, () => {\n if (scheduleId !== showScheduleIdRef.current || !showRef.current) return\n setPresenceState(PresenceState.Entering)\n })\n if (enableDelay) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] schedule set DelayedEntering in 16 frames',\n )\n delayFrames(16, () => {\n if (scheduleId !== showScheduleIdRef.current || !showRef.current) {\n return\n }\n setPresenceState(PresenceState.DelayedEntering)\n })\n }\n }\n\n const restartShow = () => {\n cancelShowTimer()\n scheduleShow()\n }\n\n const notAnimating = () => (isKFAnimating.current === false\n && isTransitionAnimating.current === false)\n\n const handleAnimationStart = () => {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] handleAnimationStart state:${state}, show:${show}, isTransition:${isTransitionAnimating.current}, isKFAnimating:${isKFAnimating.current}`,\n )\n }\n\n const handleAnimationEnd = () => {\n // still need to check if the other kind of animation is running.\n if (\n (state === PresenceState.Entering\n || state === PresenceState.DelayedEntering)\n && notAnimating()\n ) {\n if (showRef.current) {\n setPresenceState(PresenceState.Entered)\n } else {\n // Safeguard: entering animation may still fire after show turns false.\n // Why not Left? Because Left will also cancel the ongoing leaving animation.\n setPresenceState(PresenceState.Leaving)\n }\n }\n if (state === PresenceState.Leaving && notAnimating()) {\n cancelLeavingWait()\n if (showRef.current) {\n restartShow()\n } else {\n setPresenceState(PresenceState.Left)\n }\n }\n }\n\n // ==== Animation events =====\n const handleKFStart = () => {\n isKFAnimating.current = true\n enteringLoopIdRef.current += 1\n leavingLoopIdRef.current += 1\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] KF start, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationStart()\n }\n\n const handleTransitionStart = () => {\n isTransitionAnimating.current = true\n enteringLoopIdRef.current += 1\n leavingLoopIdRef.current += 1\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] Transition start, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationStart()\n }\n\n const handleKFEnd = (_e: AnimationEvent) => {\n isKFAnimating.current = false\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] KF end, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationEnd()\n }\n\n const handleKFCancel = () => {\n isKFAnimating.current = false\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] KF cancel, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationEnd()\n }\n\n const handleTransitionCancel = () => {\n isTransitionAnimating.current = false\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] Transition cancel, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationEnd()\n }\n\n const handleTransitionEnd = (_e: TransitionEvent) => {\n isTransitionAnimating.current = false\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] Transition end, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationEnd()\n }\n\n // ==== state controller ====\n const handleStateEntered = () => {\n if (hasNotifiedOpen.current) {\n return\n }\n hasNotifiedOpen.current = true\n onOpen?.()\n }\n\n const handleStateLeft = () => {\n if (showRef.current) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] skip mount=false because show=true (Left)',\n )\n restartShow()\n return\n }\n if (!isInitialRender.current && hasNotifiedOpen.current) {\n hasNotifiedOpen.current = false\n onClose?.()\n }\n log(debugLog, '[lynx-ui-presence][usePresence] set mount=false (Left)')\n setMount(false)\n }\n\n const handleStateLeaving = () => {\n cancelEnteringWait()\n leavingWaitFramesRef.current = 0\n leavingLoopIdRef.current += 1\n const loopId = leavingLoopIdRef.current\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] leaving loop scheduled, loopId: ${loopId}`,\n )\n const tryLeft = () => {\n // The loopId is inconsistent with the current animation state, means the animation started during the delay period, so we should stop this trying.\n if (loopId !== leavingLoopIdRef.current) return\n if (!notAnimating()) return\n // timeout reached => treat as no animation\n if (leavingWaitFramesRef.current >= MAX_WAIT_FRAMES) {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] leaving timeout reached, loopId: ${loopId}, frames: ${leavingWaitFramesRef.current}`,\n )\n if (showRef.current) {\n restartShow()\n } else {\n setPresenceState(PresenceState.Left)\n }\n return\n }\n leavingWaitFramesRef.current += 1\n delayFrames(1, tryLeft)\n }\n\n delayFrames(1, tryLeft)\n }\n\n const handleStateEnteringWithDelay = () => {\n cancelLeavingWait()\n enteringWaitFramesRef.current = 0\n enteringLoopIdRef.current += 1\n const loopId = enteringLoopIdRef.current\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] entering loop scheduled, loopId: ${loopId}`,\n )\n const tryEntered = () => {\n // The loopId is inconsistent with the current animation state, means the animation started during the delay period, so we should stop this trying.\n if (loopId !== enteringLoopIdRef.current) return\n if (!notAnimating()) return\n if (enteringWaitFramesRef.current >= MAX_WAIT_FRAMES) {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] entering timeout reached, loopId: ${loopId}, frames: ${enteringWaitFramesRef.current}`,\n )\n if (showRef.current) {\n setPresenceState(PresenceState.Entered)\n } else {\n setPresenceState(PresenceState.Leaving)\n }\n return\n }\n enteringWaitFramesRef.current += 1\n delayFrames(1, tryEntered)\n }\n\n delayFrames(1, tryEntered)\n }\n\n useEffect(() => {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] state effect, state: ${state}, show: ${show}, enableDelay: ${enableDelay}, isTransitionAnimating: ${isTransitionAnimating.current}, isKFAnimating: ${isKFAnimating.current}`,\n )\n if (state === PresenceState.Entered) {\n handleStateEntered()\n }\n if (state === PresenceState.Left) {\n handleStateLeft()\n }\n if (state === PresenceState.Leaving) {\n handleStateLeaving()\n }\n if (state === enteringStateWithDelay) {\n handleStateEnteringWithDelay()\n }\n }, [state])\n\n // ==== Show change part ====\n const handleDismiss = () => {\n if (\n state === PresenceState.Entered || state === PresenceState.Entering\n || state === PresenceState.DelayedEntering\n ) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] show=false -> set PresenceState.Leaving',\n )\n cancelEnteringWait()\n setPresenceState(PresenceState.Leaving)\n } else if (\n (state === PresenceState.Initial || state === PresenceState.Left) && mount\n ) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] show=false before entering -> set mount=false',\n )\n setMount(false)\n }\n }\n\n useEffect(() => {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] show effect show:${show}, enableDelay:${enableDelay}, state:${state}, mount:${mount}`,\n )\n if (show) {\n restartShow()\n } else {\n cancelShowTimer()\n handleDismiss()\n }\n }, [show, enableDelay])\n\n useEffect(() => {\n isInitialRender.current = false\n }, [])\n\n return {\n controllers: { state, mount, setPresenceState },\n animationHandlers: {\n handleKFStart,\n handleKFCancel,\n handleKFEnd,\n handleTransitionStart,\n handleTransitionCancel,\n handleTransitionEnd,\n },\n }\n}\n\nexport const renderPresenceChildren = (\n props: {\n children: PresenceProps['children']\n status: PresenceAnimationStatus\n },\n) => {\n const { children, status } = props\n return typeof children === 'function'\n ? children(status)\n : children\n}\n"],"names":["PresenceContext","createContext","usePresence","props","show","state","enableDelay","setPresenceState","onOpen","onClose","debugLog","log","enteringStateWithDelay","PresenceState","isTransitionAnimating","useRef","isKFAnimating","isInitialRender","hasNotifiedOpen","showRef","mount","setMount","useState","enteringLoopIdRef","leavingLoopIdRef","showScheduleIdRef","enteringWaitFramesRef","leavingWaitFramesRef","MAX_WAIT_FRAMES","cancelShowTimer","cancelEnteringWait","cancelLeavingWait","scheduleShow","scheduleId","delayFrames","restartShow","notAnimating","handleAnimationStart","handleAnimationEnd","handleKFStart","handleTransitionStart","handleKFEnd","_e","handleKFCancel","handleTransitionCancel","handleTransitionEnd","handleStateEntered","handleStateLeft","handleStateLeaving","loopId","tryLeft","handleStateEnteringWithDelay","tryEntered","useEffect","handleDismiss","renderPresenceChildren","children","status"],"mappings":";;;AAkBO,MAAMA,kBAAkBC,cAAmC;AAE3D,SAASC,YAAYC,KAAuB;IACjD,MAAM,EACJC,IAAI,EACJC,KAAK,EACLC,cAAc,KAAK,EACnBC,gBAAgB,EAChBC,MAAM,EACNC,OAAO,EACPC,WAAW,KAAK,EACjB,GAAGP;IACJQ,IACED,UACA,CAAC,4CAA4C,EAAEN,KAAK,SAAS,EAAEC,MAAM,eAAe,EAAEC,aAAa;IAErG,MAAMM,yBAAyBN,cAC3BO,cAAc,eAAe,GAC7BA,cAAc,QAAQ;IAE1B,MAAMC,wBAAwBC,OAAgB;IAC9C,MAAMC,gBAAgBD,OAAgB;IAEtC,MAAME,kBAAkBF,OAAO;IAC/B,MAAMG,kBAAkBH,OAAO;IAC/B,MAAMI,UAAUJ,OAAOX;IAEvB,MAAM,CAACgB,OAAOC,SAAS,GAAGC,SAAkB;IAE5C,MAAMC,oBAAoBR,OAAe;IACzC,MAAMS,mBAAmBT,OAAe;IACxC,MAAMU,oBAAoBV,OAAO;IAEjC,MAAMW,wBAAwBX,OAAe;IAC7C,MAAMY,uBAAuBZ,OAAe;IAG5C,MAAMa,kBAAkB;IAExBT,QAAQ,OAAO,GAAGf;IAElB,MAAMyB,kBAAkB;QACtBJ,kBAAkB,OAAO,IAAI;IAC/B;IAEA,MAAMK,qBAAqB;QACzBP,kBAAkB,OAAO,IAAI;I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UAAUO,wBACZuC;IAEJ,GAAG;QAAC9C;KAAM;IAGV,MAAMiD,gBAAgB;QACpB,IACEjD,UAAUQ,cAAc,OAAO,IAAIR,UAAUQ,cAAc,QAAQ,IAChER,UAAUQ,cAAc,eAAe,EAC1C;YACAF,IACED,UACA;YAEFoB;YACAvB,iBAAiBM,cAAc,OAAO;QACxC,OAAO,IACJR,AAAAA,CAAAA,UAAUQ,cAAc,OAAO,IAAIR,UAAUQ,cAAc,IAAG,KAAMO,OACrE;YACAT,IACED,UACA;YAEFW,SAAS;QACX;IACF;IAEAgC,UAAU;QACR1C,IACED,UACA,CAAC,iDAAiD,EAAEN,KAAK,cAAc,EAAEE,YAAY,QAAQ,EAAED,MAAM,QAAQ,EAAEe,OAAO;QAExH,IAAIhB,MACF+B;aACK;YACLN;YACAyB;QACF;IACF,GAAG;QAAClD;QAAME;KAAY;IAEtB+C,UAAU;QACRpC,gBAAgB,OAAO,GAAG;IAC5B,GAAG,EAAE;IAEL,OAAO;QACL,aAAa;YAAEZ;YAAOe;YAAOb;QAAiB;QAC9C,mBAAmB;YACjBgC;YACAI;YACAF;YACAD;YACAI;YACAC;QACF;IACF;AACF;AAEO,MAAMU,yBAAyB,CACpCpD;IAKA,MAAM,EAAEqD,QAAQ,EAAEC,MAAM,EAAE,GAAGtD;IAC7B,OAAO,AAAoB,cAApB,OAAOqD,WACVA,SAASC,UACTD;AACN"}
@@ -1 +1 @@
1
- {"version":3,"file":"usePresenceGroup.jsx","sources":["webpack://@lynx-js/lynx-ui-presence/./src/usePresenceGroup.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport {\n createContext,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from '@lynx-js/react'\nimport type { ReactNode } from '@lynx-js/react'\n\nimport { Presence } from './Presence'\nimport type { PresenceChildrenType, PresenceContextType } from './types'\nimport { PresenceState } from './utils'\n\nexport const PresenceContext = createContext<PresenceContextType>(null!)\n\nexport interface usePresenceGroupProps {\n show: boolean\n forceMount: boolean\n setGroupState?: (state: PresenceState) => void\n enableDelay?: boolean\n children?:\n | ReactNode\n | PresenceChildrenType\n | Array<ReactNode | PresenceChildrenType>\n onOpen?: () => void\n onClose?: () => void\n debugLog?: boolean\n}\n\nexport interface usePresenceGroupReturnType {\n renderChildren: ReactNode\n mountView: boolean\n}\n// Manage a group of Presence components.\n// Wrap all child nodes with Presence and ensure that the onOpen and onClose events are triggered after all animations are completed.\nexport const usePresenceGroup: (\n props: usePresenceGroupProps,\n) => usePresenceGroupReturnType = (props) => {\n const {\n show,\n forceMount = false,\n children,\n enableDelay = false,\n onOpen,\n onClose,\n setGroupState,\n debugLog,\n } = props\n\n const [_, setMountingChildrenCount] = useState<number>(\n 0,\n )\n const [mountView, setMountView] = useState<boolean>(show)\n\n const childrenSize = Array.isArray(children)\n ? children.length\n : (children ? 1 : 0)\n const [stateGroup, setStateGroup] = useState<PresenceState[]>(\n Array.from({ length: childrenSize }, () => PresenceState.Left),\n )\n\n // Determine the overall state based on the stateGroup\n const getGroupState = (states: PresenceState[]): PresenceState => {\n // The state in Presence will stop the PresenceState from changing to DelayedEntering if the delay is disabled. No need to double check it in upper presence group.\n if (\n states.some(state => state === PresenceState.DelayedEntering)\n ) {\n return PresenceState.DelayedEntering\n }\n if (\n states.some(state => state === PresenceState.Entering)\n ) {\n return PresenceState.Entering\n }\n if (states.some(state => state === PresenceState.Leaving)) {\n return PresenceState.Leaving\n }\n if (states.every(state => state === PresenceState.Entered)) {\n return PresenceState.Entered\n }\n if (states.every(state => state === PresenceState.Left)) {\n return PresenceState.Left\n }\n return PresenceState.Left\n }\n\n const updateStateGroup = (index: number, newState: PresenceState) => {\n setStateGroup(prev => {\n const newStateGroup = [...prev]\n newStateGroup[index] = newState\n if (setGroupState) {\n setGroupState(getGroupState(newStateGroup))\n }\n return newStateGroup\n })\n }\n\n const onChildOpen = useCallback(() => {\n setMountingChildrenCount((prev) => {\n const count = prev + 1\n if (\n children\n && ((Array.isArray(children) && count === children.length)\n || (!Array.isArray(children) && count === 1))\n ) {\n onOpen?.()\n }\n return count\n })\n }, [children, onOpen])\n\n const onChildClose = useCallback(() => {\n setMountingChildrenCount((prev) => {\n const count = prev - 1\n if (count === 0) {\n onClose?.()\n }\n return count\n })\n }, [onClose])\n\n const renderChildren = useMemo(() => {\n return Array.isArray(children)\n ? children.map(\n (child: ReactNode | PresenceChildrenType, index: number) => {\n return (\n <Presence\n key={index}\n show={show}\n forceMount={forceMount}\n state={stateGroup[index]}\n setPresenceState={(state: PresenceState) =>\n updateStateGroup(index, state)}\n enableDelay={enableDelay}\n onOpen={onChildOpen}\n onClose={onChildClose}\n debugLog={debugLog}\n >\n {child}\n </Presence>\n )\n },\n )\n : (children\n ? (\n <Presence\n show={show}\n forceMount={forceMount}\n state={stateGroup[0]}\n setPresenceState={(state: PresenceState) =>\n updateStateGroup(0, state)}\n enableDelay={enableDelay}\n onOpen={onChildOpen}\n onClose={onChildClose}\n debugLog={debugLog}\n >\n {children}\n </Presence>\n )\n : null)\n }, [\n show,\n children,\n stateGroup,\n onChildClose,\n onChildOpen,\n forceMount,\n enableDelay,\n debugLog,\n ])\n\n useEffect(() => {\n if (show) {\n setMountView(true)\n } else if (stateGroup.every(state => state === PresenceState.Left)) {\n setMountView(false)\n }\n }, [show, stateGroup])\n\n return {\n renderChildren,\n mountView,\n }\n}\n"],"names":["PresenceContext","createContext","usePresenceGroup","props","show","forceMount","children","enableDelay","onOpen","onClose","setGroupState","debugLog","_","setMountingChildrenCount","useState","mountView","setMountView","childrenSize","Array","stateGroup","setStateGroup","PresenceState","getGroupState","states","state","updateStateGroup","index","newState","prev","newStateGroup","onChildOpen","useCallback","count","onChildClose","renderChildren","useMemo","child","Presence","useEffect"],"mappings":";;;AAiBO,MAAMA,kBAAkBC,cAAmC;AAsB3D,MAAMC,mBAEqB,CAACC;IACjC,MAAM,EACJC,IAAI,EACJC,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O,CAACZ,aAAa0B,AAAU,MAAVA,KAAU,GAE5CxB;YAEF,OAAOwB;QACT;IACF,GAAG;QAAC1B;QAAUE;KAAO;IAErB,MAAMyB,eAAeF,YAAY;QAC/BlB,yBAAyB,CAACe;YACxB,MAAMI,QAAQJ,OAAO;YACrB,IAAII,AAAU,MAAVA,OACFvB;YAEF,OAAOuB;QACT;IACF,GAAG;QAACvB;KAAQ;IAEZ,MAAMyB,iBAAiBC,QAAQ,IACtBjB,MAAM,OAAO,CAACZ,YACjBA,SAAS,GAAG,CACZ,CAAC8B,OAAyCV,SAErCW,SACC,KAAKX,OACL,MAAMtB,MACN,YAAYC,YACZ,OAAOc,UAAU,CAACO,MAAM,EACxB,kBAAkB,CAACF,QACjBC,iBAAiBC,OAAOF,QAC1B,aAAajB,aACb,QAAQuB,aACR,SAASG,cACT,UAAUtB,UACX;cACC,CAACyB,MAAM;YACT,EAAEC,aAIL/B,YAEE+B,SACC,MAAMjC,MACN,YAAYC,YACZ,OAAOc,UAAU,CAAC,EAAE,EACpB,kBAAkB,CAACK,QACjBC,iBAAiB,GAAGD,QACtB,aAAajB,aACb,QAAQuB,aACR,SAASG,cACT,UAAUtB,UACX;YACC,CAACL,SAAS;UACZ,EAAE+B,YAEF,MACL;QACDjC;QACAE;QACAa;QACAc;QACAH;QACAzB;QACAE;QACAI;KACD;IAED2B,UAAU;QACR,IAAIlC,MACFY,aAAa;aACR,IAAIG,WAAW,KAAK,CAACK,CAAAA,QAASA,UAAUH,cAAc,IAAI,GAC/DL,aAAa;IAEjB,GAAG;QAACZ;QAAMe;KAAW;IAErB,OAAO;QACLe;QACAnB;IACF;AACF"}
1
+ {"version":3,"file":"usePresenceGroup.jsx","sources":["../src/usePresenceGroup.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport {\n createContext,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from '@lynx-js/react'\nimport type { ReactNode } from '@lynx-js/react'\n\nimport { Presence } from './Presence'\nimport type { PresenceChildrenType, PresenceContextType } from './types'\nimport { PresenceState } from './utils'\n\nexport const PresenceContext = createContext<PresenceContextType>(null!)\n\nexport interface usePresenceGroupProps {\n show: boolean\n forceMount: boolean\n setGroupState?: (state: PresenceState) => void\n enableDelay?: boolean\n children?:\n | ReactNode\n | PresenceChildrenType\n | Array<ReactNode | PresenceChildrenType>\n onOpen?: () => void\n onClose?: () => void\n debugLog?: boolean\n}\n\nexport interface usePresenceGroupReturnType {\n renderChildren: ReactNode\n mountView: boolean\n}\n// Manage a group of Presence components.\n// Wrap all child nodes with Presence and ensure that the onOpen and onClose events are triggered after all animations are completed.\nexport const usePresenceGroup: (\n props: usePresenceGroupProps,\n) => usePresenceGroupReturnType = (props) => {\n const {\n show,\n forceMount = false,\n children,\n enableDelay = false,\n onOpen,\n onClose,\n setGroupState,\n debugLog,\n } = props\n\n const [_, setMountingChildrenCount] = useState<number>(\n 0,\n )\n const [mountView, setMountView] = useState<boolean>(show)\n\n const childrenSize = Array.isArray(children)\n ? children.length\n : (children ? 1 : 0)\n const [stateGroup, setStateGroup] = useState<PresenceState[]>(\n Array.from({ length: childrenSize }, () => PresenceState.Left),\n )\n\n // Determine the overall state based on the stateGroup\n const getGroupState = (states: PresenceState[]): PresenceState => {\n // The state in Presence will stop the PresenceState from changing to DelayedEntering if the delay is disabled. No need to double check it in upper presence group.\n if (\n states.some(state => state === PresenceState.DelayedEntering)\n ) {\n return PresenceState.DelayedEntering\n }\n if (\n states.some(state => state === PresenceState.Entering)\n ) {\n return PresenceState.Entering\n }\n if (states.some(state => state === PresenceState.Leaving)) {\n return PresenceState.Leaving\n }\n if (states.every(state => state === PresenceState.Entered)) {\n return PresenceState.Entered\n }\n if (states.every(state => state === PresenceState.Left)) {\n return PresenceState.Left\n }\n return PresenceState.Left\n }\n\n const updateStateGroup = (index: number, newState: PresenceState) => {\n setStateGroup(prev => {\n const newStateGroup = [...prev]\n newStateGroup[index] = newState\n if (setGroupState) {\n setGroupState(getGroupState(newStateGroup))\n }\n return newStateGroup\n })\n }\n\n const onChildOpen = useCallback(() => {\n setMountingChildrenCount((prev) => {\n const count = prev + 1\n if (\n children\n && ((Array.isArray(children) && count === children.length)\n || (!Array.isArray(children) && count === 1))\n ) {\n onOpen?.()\n }\n return count\n })\n }, [children, onOpen])\n\n const onChildClose = useCallback(() => {\n setMountingChildrenCount((prev) => {\n const count = prev - 1\n if (count === 0) {\n onClose?.()\n }\n return count\n })\n }, [onClose])\n\n const renderChildren = useMemo(() => {\n return Array.isArray(children)\n ? children.map(\n (child: ReactNode | PresenceChildrenType, index: number) => {\n return (\n <Presence\n key={index}\n show={show}\n forceMount={forceMount}\n state={stateGroup[index]}\n setPresenceState={(state: PresenceState) =>\n updateStateGroup(index, state)}\n enableDelay={enableDelay}\n onOpen={onChildOpen}\n onClose={onChildClose}\n debugLog={debugLog}\n >\n {child}\n </Presence>\n )\n },\n )\n : (children\n ? (\n <Presence\n show={show}\n forceMount={forceMount}\n state={stateGroup[0]}\n setPresenceState={(state: PresenceState) =>\n updateStateGroup(0, state)}\n enableDelay={enableDelay}\n onOpen={onChildOpen}\n onClose={onChildClose}\n debugLog={debugLog}\n >\n {children}\n </Presence>\n )\n : null)\n }, [\n show,\n children,\n stateGroup,\n onChildClose,\n onChildOpen,\n forceMount,\n enableDelay,\n debugLog,\n ])\n\n useEffect(() => {\n if (show) {\n setMountView(true)\n } else if (stateGroup.every(state => state === PresenceState.Left)) {\n setMountView(false)\n }\n }, [show, stateGroup])\n\n return {\n renderChildren,\n mountView,\n }\n}\n"],"names":["PresenceContext","createContext","usePresenceGroup","props","show","forceMount","children","enableDelay","onOpen","onClose","setGroupState","debugLog","_","setMountingChildrenCount","useState","mountView","setMountView","childrenSize","Array","stateGroup","setStateGroup","PresenceState","getGroupState","states","state","updateStateGroup","index","newState","prev","newStateGroup","onChildOpen","useCallback","count","onChildClose","renderChildren","useMemo","child","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,QAAQJ,OAAO;YACrB,IACEtB,YACKY,CAAAA,MAAM,OAAO,CAACZ,aAAa0B,UAAU1B,SAAS,MAAM,IACnD,CAACY,MAAM,OAAO,CAACZ,aAAa0B,AAAU,MAAVA,KAAU,GAE5CxB;YAEF,OAAOwB;QACT;IACF,GAAG;QAAC1B;QAAUE;KAAO;IAErB,MAAMyB,eAAeF,YAAY;QAC/BlB,yBAAyB,CAACe;YACxB,MAAMI,QAAQJ,OAAO;YACrB,IAAII,AAAU,MAAVA,OACFvB;YAEF,OAAOuB;QACT;IACF,GAAG;QAACvB;KAAQ;IAEZ,MAAMyB,iBAAiBC,QAAQ,IACtBjB,MAAM,OAAO,CAACZ,YACjBA,SAAS,GAAG,CACZ,CAAC8B,OAAyCV,SAErCW,SACC,KAAKX,OACL,MAAMtB,MACN,YAAYC,YACZ,OAAOc,UAAU,CAACO,MAAM,EACxB,kBAAkB,CAACF,QACjBC,iBAAiBC,OAAOF,QAC1B,aAAajB,aACb,QAAQuB,aACR,SAASG,cACT,UAAUtB,UACX;cACC,CAACyB,MAAM;YACT,EAAEC,aAIL/B,YAEE+B,SACC,MAAMjC,MACN,YAAYC,YACZ,OAAOc,UAAU,CAAC,EAAE,EACpB,kBAAkB,CAACK,QACjBC,iBAAiB,GAAGD,QACtB,aAAajB,aACb,QAAQuB,aACR,SAASG,cACT,UAAUtB,UACX;YACC,CAACL,SAAS;UACZ,EAAE+B,YAEF,MACL;QACDjC;QACAE;QACAa;QACAc;QACAH;QACAzB;QACAE;QACAI;KACD;IAED2B,UAAU;QACR,IAAIlC,MACFY,aAAa;aACR,IAAIG,WAAW,KAAK,CAACK,CAAAA,QAASA,UAAUH,cAAc,IAAI,GAC/DL,aAAa;IAEjB,GAAG;QAACZ;QAAMe;KAAW;IAErB,OAAO;QACLe;QACAnB;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"useVisibilityFromPresence.jsx","sources":["webpack://@lynx-js/lynx-ui-presence/./src/useVisibilityFromPresence.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useEffect, useState } from '@lynx-js/react'\n\nimport type { CSSProperties } from '@lynx-js/types'\n\nimport { PresenceState } from './utils'\n\n/**\n * A hook that derives visibility state from a PresenceState.\n * It returns 'visible' when the presence state indicates the component\n * is entering, present, or leaving, and 'hidden' otherwise.\n *\n * @param state The current PresenceState.\n * @returns CSSProperties['visibility'] ('visible' or 'hidden').\n */\nexport function useVisibilityFromPresence(\n state: PresenceState,\n): CSSProperties['visibility'] {\n const [visibility, setVisibility] = useState<CSSProperties['visibility']>(\n 'hidden',\n )\n\n useEffect(() => {\n if (\n state === PresenceState.DelayedEntering\n || state === PresenceState.Entered\n || state === PresenceState.Leaving\n ) {\n setVisibility('visible')\n } else {\n setVisibility('hidden')\n }\n }, [state])\n\n return visibility\n}\n"],"names":["useVisibilityFromPresence","state","visibility","setVisibility","useState","useEffect","PresenceState"],"mappings":";;AAkBO,SAASA,0BACdC,KAAoB;IAEpB,MAAM,CAACC,YAAYC,cAAc,GAAGC,SAClC;IAGFC,UAAU;QAENJ,UAAUK,cAAc,eAAe,IACpCL,UAAUK,cAAc,OAAO,IAC/BL,UAAUK,cAAc,OAAO,GAElCH,cAAc,aAEdA,cAAc;IAElB,GAAG;QAACF;KAAM;IAEV,OAAOC;AACT"}
1
+ {"version":3,"file":"useVisibilityFromPresence.jsx","sources":["../src/useVisibilityFromPresence.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useEffect, useState } from '@lynx-js/react'\n\nimport type { CSSProperties } from '@lynx-js/types'\n\nimport { PresenceState } from './utils'\n\n/**\n * A hook that derives visibility state from a PresenceState.\n * It returns 'visible' when the presence state indicates the component\n * is entering, present, or leaving, and 'hidden' otherwise.\n *\n * @param state The current PresenceState.\n * @returns CSSProperties['visibility'] ('visible' or 'hidden').\n */\nexport function useVisibilityFromPresence(\n state: PresenceState,\n): CSSProperties['visibility'] {\n const [visibility, setVisibility] = useState<CSSProperties['visibility']>(\n 'hidden',\n )\n\n useEffect(() => {\n if (\n state === PresenceState.DelayedEntering\n || state === PresenceState.Entered\n || state === PresenceState.Leaving\n ) {\n setVisibility('visible')\n } else {\n setVisibility('hidden')\n }\n }, [state])\n\n return visibility\n}\n"],"names":["useVisibilityFromPresence","state","visibility","setVisibility","useState","useEffect","PresenceState"],"mappings":";;AAkBO,SAASA,0BACdC,KAAoB;IAEpB,MAAM,CAACC,YAAYC,cAAc,GAAGC,SAClC;IAGFC,UAAU;QAENJ,UAAUK,cAAc,eAAe,IACpCL,UAAUK,cAAc,OAAO,IAC/BL,UAAUK,cAAc,OAAO,GAElCH,cAAc,aAEdA,cAAc;IAElB,GAAG;QAACF;KAAM;IAEV,OAAOC;AACT"}
package/dist/utils.jsx CHANGED
@@ -40,6 +40,6 @@ const presenceClassVariants = ({ state, enableDelay, className, transition, grou
40
40
  'ui-closed': status.closed
41
41
  });
42
42
  };
43
- export { utils_PresenceState as PresenceState, presenceClassVariants, resolveAnimationStatus };
43
+ export { presenceClassVariants, resolveAnimationStatus, utils_PresenceState as PresenceState };
44
44
 
45
45
  //# sourceMappingURL=utils.jsx.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.jsx","sources":["webpack://@lynx-js/lynx-ui-presence/./src/utils.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { clsx } from 'clsx'\n\nimport type { PresenceAnimationStatus } from './types'\n\nexport enum PresenceState {\n Initial = 0,\n Entering = 1,\n DelayedEntering = 2, // Special state for delaying the showAnimation. This is used to prevent the content from being layout before the showAnimation.\n Entered = 3,\n Leaving = 4,\n Left = 5,\n}\n\n// Convert abstract state to clear animation status for users\nexport const resolveAnimationStatus: ({\n state,\n enableDelay,\n grouped,\n}: {\n state: PresenceState\n enableDelay: boolean\n grouped?: boolean\n}) => PresenceAnimationStatus = ({\n state,\n enableDelay,\n grouped = false,\n}) => {\n const enteringStateWithDelay = enableDelay\n ? PresenceState.DelayedEntering\n : PresenceState.Entering\n const isOpen = state === enteringStateWithDelay\n || state === PresenceState.Entered\n const groupedOpen = isOpen || state === PresenceState.Leaving\n\n const isClose = state === PresenceState.Leaving\n || state === PresenceState.Left\n || (enableDelay && state === PresenceState.Entering)\n const groupedClosed = state === PresenceState.Left\n return {\n leaving: state === PresenceState.Leaving,\n entering: state === enteringStateWithDelay,\n animating: state === PresenceState.Leaving\n || state === enteringStateWithDelay,\n\n // In grouped state, even the member has entered their animation(leaving) state, it has to remain open so it won't hide its children.\n // grouped: open = entering/delayedEntering/entered/leaving\n // normal: open = entering/delayedEntering/entered\n open: grouped ? groupedOpen : isOpen,\n // In grouped state, the grouped element has to wait all its member exit their animations.\n // grouped: closed = left\n // normal: closed = leaving/left\n closed: grouped ? groupedClosed : isClose,\n }\n}\n\ninterface PresenceClassVariantsProps {\n state: PresenceState\n enableDelay: boolean\n className?: string\n transition?: boolean\n grouped?: boolean\n}\n\nexport const presenceClassVariants = ({\n state,\n enableDelay,\n className,\n transition,\n grouped,\n}: PresenceClassVariantsProps) => {\n const status = resolveAnimationStatus({\n state,\n enableDelay,\n grouped,\n })\n if (transition) {\n return clsx(\n className,\n {\n 'ui-entering': status.entering,\n 'ui-leaving': status.leaving,\n 'ui-animating': status.animating,\n 'ui-open': status.open,\n 'ui-closed': status.closed,\n },\n )\n } else {\n return clsx(className, {\n 'ui-open': status.open,\n 'ui-closed': status.closed,\n })\n }\n}\n"],"names":["PresenceState","resolveAnimationStatus","state","enableDelay","grouped","enteringStateWithDelay","isOpen","groupedOpen","isClose","groupedClosed","presenceClassVariants","className","transition","status","clsx"],"mappings":";AAQO,IAAKA,sBAAaA,WAAAA,GAAAA,SAAbA,aAAa;;;;;;;WAAbA;;AAUL,MAAMC,yBAQmB,CAAC,EAC/BC,KAAK,EACLC,WAAW,EACXC,UAAU,KAAK,EAChB;IACC,MAAMC,yBAAyBF,cAAAA,IAAAA;IAG/B,MAAMG,SAASJ,UAAUG,0BACpBH,AAAU,MAAVA;IACL,MAAMK,cAAcD,UAAUJ,AAAU,MAAVA;IAE9B,MAAMM,UAAUN,AAAU,MAAVA,SACXA,AAAU,MAAVA,SACCC,eAAeD,AAAU,MAAVA;IACrB,MAAMO,gBAAgBP,AAAU,MAAVA;IACtB,OAAO;QACL,SAASA,AAAU,MAAVA;QACT,UAAUA,UAAUG;QACpB,WAAWH,AAAU,MAAVA,SACNA,UAAUG;QAKf,MAAMD,UAAUG,cAAcD;QAI9B,QAAQF,UAAUK,gBAAgBD;IACpC;AACF;AAUO,MAAME,wBAAwB,CAAC,EACpCR,KAAK,EACLC,WAAW,EACXQ,SAAS,EACTC,UAAU,EACVR,OAAO,EACoB;IAC3B,MAAMS,SAASZ,uBAAuB;QACpCC;QACAC;QACAC;IACF;IACA,IAAIQ,YACF,OAAOE,KACLH,WACA;QACE,eAAeE,OAAO,QAAQ;QAC9B,cAAcA,OAAO,OAAO;QAC5B,gBAAgBA,OAAO,SAAS;QAChC,WAAWA,OAAO,IAAI;QACtB,aAAaA,OAAO,MAAM;IAC5B;IAGF,OAAOC,KAAKH,WAAW;QACrB,WAAWE,OAAO,IAAI;QACtB,aAAaA,OAAO,MAAM;IAC5B;AAEJ"}
1
+ {"version":3,"file":"utils.jsx","sources":["../src/utils.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { clsx } from 'clsx'\n\nimport type { PresenceAnimationStatus } from './types'\n\nexport enum PresenceState {\n Initial = 0,\n Entering = 1,\n DelayedEntering = 2, // Special state for delaying the showAnimation. This is used to prevent the content from being layout before the showAnimation.\n Entered = 3,\n Leaving = 4,\n Left = 5,\n}\n\n// Convert abstract state to clear animation status for users\nexport const resolveAnimationStatus: ({\n state,\n enableDelay,\n grouped,\n}: {\n state: PresenceState\n enableDelay: boolean\n grouped?: boolean\n}) => PresenceAnimationStatus = ({\n state,\n enableDelay,\n grouped = false,\n}) => {\n const enteringStateWithDelay = enableDelay\n ? PresenceState.DelayedEntering\n : PresenceState.Entering\n const isOpen = state === enteringStateWithDelay\n || state === PresenceState.Entered\n const groupedOpen = isOpen || state === PresenceState.Leaving\n\n const isClose = state === PresenceState.Leaving\n || state === PresenceState.Left\n || (enableDelay && state === PresenceState.Entering)\n const groupedClosed = state === PresenceState.Left\n return {\n leaving: state === PresenceState.Leaving,\n entering: state === enteringStateWithDelay,\n animating: state === PresenceState.Leaving\n || state === enteringStateWithDelay,\n\n // In grouped state, even the member has entered their animation(leaving) state, it has to remain open so it won't hide its children.\n // grouped: open = entering/delayedEntering/entered/leaving\n // normal: open = entering/delayedEntering/entered\n open: grouped ? groupedOpen : isOpen,\n // In grouped state, the grouped element has to wait all its member exit their animations.\n // grouped: closed = left\n // normal: closed = leaving/left\n closed: grouped ? groupedClosed : isClose,\n }\n}\n\ninterface PresenceClassVariantsProps {\n state: PresenceState\n enableDelay: boolean\n className?: string\n transition?: boolean\n grouped?: boolean\n}\n\nexport const presenceClassVariants = ({\n state,\n enableDelay,\n className,\n transition,\n grouped,\n}: PresenceClassVariantsProps) => {\n const status = resolveAnimationStatus({\n state,\n enableDelay,\n grouped,\n })\n if (transition) {\n return clsx(\n className,\n {\n 'ui-entering': status.entering,\n 'ui-leaving': status.leaving,\n 'ui-animating': status.animating,\n 'ui-open': status.open,\n 'ui-closed': status.closed,\n },\n )\n } else {\n return clsx(className, {\n 'ui-open': status.open,\n 'ui-closed': status.closed,\n })\n }\n}\n"],"names":["PresenceState","resolveAnimationStatus","state","enableDelay","grouped","enteringStateWithDelay","isOpen","groupedOpen","isClose","groupedClosed","presenceClassVariants","className","transition","status","clsx"],"mappings":";AAQO,IAAKA,sBAAaA,WAAAA,GAAAA,SAAbA,aAAa;;;;;;;WAAbA;;AAUL,MAAMC,yBAQmB,CAAC,EAC/BC,KAAK,EACLC,WAAW,EACXC,UAAU,KAAK,EAChB;IACC,MAAMC,yBAAyBF,cAAAA,IAAAA;IAG/B,MAAMG,SAASJ,UAAUG,0BACpBH,AAAU,MAAVA;IACL,MAAMK,cAAcD,UAAUJ,AAAU,MAAVA;IAE9B,MAAMM,UAAUN,AAAU,MAAVA,SACXA,AAAU,MAAVA,SACCC,eAAeD,AAAU,MAAVA;IACrB,MAAMO,gBAAgBP,AAAU,MAAVA;IACtB,OAAO;QACL,SAASA,AAAU,MAAVA;QACT,UAAUA,UAAUG;QACpB,WAAWH,AAAU,MAAVA,SACNA,UAAUG;QAKf,MAAMD,UAAUG,cAAcD;QAI9B,QAAQF,UAAUK,gBAAgBD;IACpC;AACF;AAUO,MAAME,wBAAwB,CAAC,EACpCR,KAAK,EACLC,WAAW,EACXQ,SAAS,EACTC,UAAU,EACVR,OAAO,EACoB;IAC3B,MAAMS,SAASZ,uBAAuB;QACpCC;QACAC;QACAC;IACF;IACA,IAAIQ,YACF,OAAOE,KACLH,WACA;QACE,eAAeE,OAAO,QAAQ;QAC9B,cAAcA,OAAO,OAAO;QAC5B,gBAAgBA,OAAO,SAAS;QAChC,WAAWA,OAAO,IAAI;QACtB,aAAaA,OAAO,MAAM;IAC5B;IAGF,OAAOC,KAAKH,WAAW;QACrB,WAAWE,OAAO,IAAI;QACtB,aAAaA,OAAO,MAAM;IAC5B;AAEJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/lynx-ui-presence",
3
- "version": "3.135.3",
3
+ "version": "3.136.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lynx-family/lynx-ui.git",
@@ -25,14 +25,14 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "clsx": "^2.1.1",
28
- "@lynx-js/lynx-ui-common": "3.135.3"
28
+ "@lynx-js/lynx-ui-common": "3.136.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@lynx-js/react": "0.114.0",
32
- "@lynx-js/types": "3.6.0",
33
- "@rslib/core": "^0.16.0",
31
+ "@lynx-js/react": "0.123.1",
32
+ "@lynx-js/types": "4.1.0",
33
+ "@rslib/core": "0.23.2",
34
34
  "@types/react": "^18.3.8",
35
- "typescript": "^5.5.3"
35
+ "typescript": "^5.8.0"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@lynx-js/react": ">=0.100.0",
package/tsconfig.json CHANGED
@@ -6,4 +6,9 @@
6
6
  "include": [
7
7
  "src",
8
8
  ],
9
+ "exclude": [
10
+ "**/*.test.ts",
11
+ "**/*.test.tsx",
12
+ "**/__tests__/**",
13
+ ],
9
14
  }