{"version":3,"file":"PresenceChild.js","names":[],"sources":["esm/PresenceChild.js"],"sourcesContent":["import { useConstant } from \"@tamagui/use-constant\";\nimport { PresenceContext } from \"@tamagui/use-presence\";\nimport * as React from \"react\";\nimport { useId } from \"react\";\nimport { jsx } from \"react/jsx-runtime\";\nconst PresenceChild = React.memo(\n  ({\n    children,\n    initial,\n    isPresent,\n    onExitComplete,\n    presenceAffectsLayout,\n    custom\n  }) => {\n    const presenceChildren = useConstant(newChildrenMap);\n    const id = useId() || \"\";\n    const context = React.useMemo(\n      () => {\n        return {\n          id,\n          initial,\n          isPresent,\n          custom,\n          onExitComplete: () => {\n            presenceChildren.set(id, true);\n            for (const isComplete of presenceChildren.values()) {\n              if (!isComplete) {\n                return;\n              }\n            }\n            onExitComplete?.();\n          },\n          register: () => {\n            presenceChildren.set(id, false);\n            return () => presenceChildren.delete(id);\n          }\n        };\n      },\n      /**\n       * If the presence of a child affects the layout of the components around it,\n       * we want to make a new context value to ensure they get re-rendered\n       * so they can detect that layout change.\n       */\n      // @ts-expect-error its ok\n      presenceAffectsLayout ? void 0 : [isPresent, custom]\n    );\n    React.useMemo(() => {\n      presenceChildren.forEach((_, key) => presenceChildren.set(key, false));\n    }, [isPresent]);\n    React.useEffect(() => {\n      !isPresent && !presenceChildren.size && onExitComplete?.();\n    }, [isPresent]);\n    return /* @__PURE__ */ jsx(PresenceContext.Provider, { value: context, children });\n  }\n);\nfunction newChildrenMap() {\n  return /* @__PURE__ */ new Map();\n}\nexport {\n  PresenceChild\n};\n//# sourceMappingURL=PresenceChild.js.map\n"],"mappings":";;;;;;;AAKA,MAAM,gBAAgB,MAAM,MACzB,EACC,UACA,SACA,WACA,gBACA,uBACA,aACI;CACJ,MAAM,mBAAmB,YAAY,cAAc;CACnD,MAAM,KAAK,MAAM,KAAK;CACtB,MAAM,UAAU,MAAM;QACd;GACJ,OAAO;IACL;IACA;IACA;IACA;IACA,sBAAsB;KACpB,iBAAiB,IAAI,IAAI,IAAI;KAC7B,KAAK,MAAM,cAAc,iBAAiB,OAAO,GAAG;MAClD,IAAI,CAAC,YAAY;OACf;MACF;KACF;KACA,iBAAiB;IACnB;IACA,gBAAgB;KACd,iBAAiB,IAAI,IAAI,KAAK;KAC9B,aAAa,iBAAiB,OAAO,EAAE;IACzC;GACF;EACF;;;;;;EAOA,wBAAwB,KAAK,IAAI,CAAC,WAAW,MAAM;CACrD;CACA,MAAM,cAAc;EAClB,iBAAiB,SAAS,GAAG,QAAQ,iBAAiB,IAAI,KAAK,KAAK,CAAC;CACvE,GAAG,CAAC,SAAS,CAAC;CACd,MAAM,gBAAgB;EACpB,CAAC,aAAa,CAAC,iBAAiB,QAAQ,iBAAiB;CAC3D,GAAG,CAAC,SAAS,CAAC;CACd,OAAuB,oBAAI,gBAAgB,UAAU;EAAE,OAAO;EAAS;CAAS,CAAC;AACnF,CACF;AACA,SAAS,iBAAiB;CACxB,uBAAuB,IAAI,IAAI;AACjC"}