@tamagui/adapt 2.7.7 → 3.0.0-beta.643.1

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.
@@ -1,3 +1,4 @@
1
+
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -5,235 +6,477 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
6
  var __getProtoOf = Object.getPrototypeOf;
6
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
8
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
9
+ for (var name in all) __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true
12
+ });
12
13
  };
13
14
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
21
22
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
30
26
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
28
  var Adapt_exports = {};
35
29
  __export(Adapt_exports, {
36
- Adapt: () => Adapt,
37
- AdaptContents: () => AdaptContents,
38
- AdaptContext: () => AdaptContext,
39
- AdaptParent: () => AdaptParent,
40
- AdaptPortalContents: () => AdaptPortalContents,
41
- ProvideAdaptContext: () => ProvideAdaptContext,
42
- useAdaptContext: () => useAdaptContext,
43
- useAdaptIsActive: () => useAdaptIsActive
30
+ Adapt: () => Adapt,
31
+ AdaptCapabilities: () => AdaptCapabilities,
32
+ AdaptContents: () => AdaptContents,
33
+ AdaptContext: () => AdaptContext,
34
+ AdaptParent: () => AdaptParent,
35
+ AdaptPortalContents: () => AdaptPortalContents,
36
+ ProvideAdaptContext: () => ProvideAdaptContext,
37
+ useAdaptContext: () => useAdaptContext,
38
+ useAdaptIsActive: () => useAdaptIsActive,
39
+ useAdaptTarget: () => useAdaptTarget,
40
+ useAdaptedCapabilities: () => useAdaptedCapabilities
44
41
  });
45
42
  module.exports = __toCommonJS(Adapt_exports);
46
43
  var import_constants = require("@tamagui/constants");
47
44
  var import_core = require("@tamagui/core");
48
45
  var import_helpers = require("@tamagui/helpers");
49
- var import_native = require("@tamagui/native");
50
- var import_portal = require("@tamagui/portal");
51
46
  var import_z_index_stack = require("@tamagui/z-index-stack");
52
47
  var import_react = __toESM(require("react"), 1);
53
48
  var import_jsx_runtime = require("react/jsx-runtime");
54
- function createAdaptChildrenStore() {
55
- let children = null;
56
- const listeners = /* @__PURE__ */new Set();
57
- return {
58
- set(c) {
59
- children = c;
60
- for (const l of listeners) l();
61
- },
62
- get: () => children,
63
- subscribe(callback) {
64
- listeners.add(callback);
65
- return () => listeners.delete(callback);
66
- }
67
- };
49
+ function createAdaptSlotStore() {
50
+ const listeners = /* @__PURE__ */ new Set();
51
+ const store = {
52
+ element: null,
53
+ version: 0,
54
+ publish(element) {
55
+ store.element = element;
56
+ },
57
+ clear() {
58
+ store.element = null;
59
+ },
60
+ notify() {
61
+ store.version += 1;
62
+ for (const listener of listeners) {
63
+ listener();
64
+ }
65
+ },
66
+ getSnapshot() {
67
+ return store.version;
68
+ },
69
+ subscribe(callback) {
70
+ listeners.add(callback);
71
+ return () => {
72
+ listeners.delete(callback);
73
+ };
74
+ }
75
+ };
76
+ return store;
68
77
  }
69
- const AdaptChildrenStoreContext = (0, import_react.createContext)(null);
78
+ const adaptContextKeys = [
79
+ "Contents",
80
+ "scopeName",
81
+ "portalName",
82
+ "platform",
83
+ "setPlatform",
84
+ "when",
85
+ "setWhen",
86
+ "active",
87
+ "rawActive",
88
+ "setRawActive",
89
+ "slot",
90
+ "handoff",
91
+ "targetFullyHidden",
92
+ "registerTarget",
93
+ "unregisterTarget",
94
+ "registerContents",
95
+ "unregisterContents",
96
+ "registerRenderCallback",
97
+ "unregisterRenderCallback"
98
+ ];
70
99
  const AdaptContext = (0, import_core.createStyledContext)({
71
- Contents: null,
72
- scopeName: "",
73
- portalName: "",
74
- platform: null,
75
- setPlatform: x => {},
76
- when: null,
77
- setWhen: () => {}
78
- });
100
+ Contents: null,
101
+ scopeName: "",
102
+ portalName: "",
103
+ platform: null,
104
+ setPlatform: (x) => {},
105
+ when: null,
106
+ setWhen: () => {},
107
+ active: false,
108
+ rawActive: false,
109
+ setRawActive: () => {},
110
+ slot: null,
111
+ handoff: {
112
+ hidden: true,
113
+ onTransition: () => {}
114
+ },
115
+ targetFullyHidden: true,
116
+ registerTarget: () => {},
117
+ unregisterTarget: () => {},
118
+ registerContents: () => {},
119
+ unregisterContents: () => {},
120
+ registerRenderCallback: () => {},
121
+ unregisterRenderCallback: () => {}
122
+ }, { keys: adaptContextKeys });
123
+ const AdaptCapabilitiesContext = (0, import_react.createContext)({});
79
124
  const LastAdaptContextScope = (0, import_react.createContext)("");
80
- const ProvideAdaptContext = ({
81
- children,
82
- ...context
83
- }) => {
84
- const scope = context.scopeName || "";
85
- const lastScope = (0, import_react.useContext)(LastAdaptContextScope);
86
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(LastAdaptContextScope.Provider, {
87
- value: lastScope || context.lastScope || "",
88
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(AdaptContext.Provider, {
89
- scope,
90
- lastScope: lastScope || context.lastScope,
91
- ...context,
92
- children
93
- })
94
- });
125
+ const ProvideAdaptContext = ({ children, ...context }) => {
126
+ const scope = context.scopeName || "";
127
+ const lastScope = (0, import_react.useContext)(LastAdaptContextScope);
128
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LastAdaptContextScope.Provider, {
129
+ value: lastScope || context.lastScope || "",
130
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AdaptContext.Provider, {
131
+ scope,
132
+ lastScope: lastScope || context.lastScope,
133
+ ...context,
134
+ children
135
+ })
136
+ });
95
137
  };
96
- const useAdaptContext = scope => {
97
- const lastScope = (0, import_react.useContext)(LastAdaptContextScope);
98
- const adaptScope = scope ?? lastScope;
99
- return AdaptContext.useStyledContext(adaptScope);
138
+ const useAdaptContext = (scope) => {
139
+ const lastScope = (0, import_react.useContext)(LastAdaptContextScope);
140
+ const adaptScope = scope ?? lastScope;
141
+ return AdaptContext.useStyledContext(adaptScope);
100
142
  };
101
- const AdaptPortals = /* @__PURE__ */new Map();
102
- const AdaptParent = ({
103
- children,
104
- Contents,
105
- scope,
106
- portal
107
- }) => {
108
- const id = (0, import_react.useId)();
109
- const portalName = `AdaptPortal${scope}${id}`;
110
- const childrenStoreRef = import_react.default.useRef(null);
111
- if (!childrenStoreRef.current) childrenStoreRef.current = createAdaptChildrenStore();
112
- const isTeleport = false;
113
- const FinalContents = (0, import_react.useMemo)(() => {
114
- if (Contents) return Contents;
115
- if (AdaptPortals.has(portalName)) return AdaptPortals.get(portalName);
116
- const element = () => {
117
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.PortalHost, {
118
- name: portalName,
119
- forwardProps: typeof portal === "boolean" ? void 0 : portal?.forwardProps
120
- }, id);
121
- };
122
- AdaptPortals.set(portalName, element);
123
- return element;
124
- }, [portalName, Contents, isTeleport]);
125
- (0, import_constants.useIsomorphicLayoutEffect)(() => {
126
- AdaptPortals.set(portalName, FinalContents);
127
- return () => {
128
- AdaptPortals.delete(portalName);
129
- };
130
- }, [portalName, isTeleport]);
131
- const [when, setWhen] = import_react.default.useState(null);
132
- const [platform, setPlatform] = import_react.default.useState(null);
133
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(AdaptChildrenStoreContext.Provider, {
134
- value: childrenStoreRef.current,
135
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(LastAdaptContextScope.Provider, {
136
- value: scope,
137
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ProvideAdaptContext, {
138
- Contents: FinalContents,
139
- when,
140
- platform,
141
- setPlatform,
142
- setWhen,
143
- portalName,
144
- scopeName: scope,
145
- children
146
- })
147
- })
148
- });
143
+ const AdaptParent = ({ children, Contents, scope, open, onOpenChange, state }) => {
144
+ const id = (0, import_react.useId)();
145
+ const portalName = `AdaptPortal${scope}${id}`;
146
+ const slotRef = import_react.default.useRef(null);
147
+ if (!slotRef.current) {
148
+ slotRef.current = createAdaptSlotStore();
149
+ }
150
+ const [when, setWhen] = import_react.default.useState(null);
151
+ const [platform, setPlatform] = import_react.default.useState(null);
152
+ const [rawActive, setRawActive] = import_react.default.useState(false);
153
+ const [exiting, setExiting] = import_react.default.useState(false);
154
+ const [present, setPresent] = import_react.default.useState(false);
155
+ const [targetFullyHidden, setTargetFullyHidden] = import_react.default.useState(!open);
156
+ const targetCountRef = import_react.default.useRef(0);
157
+ const contentsCountRef = import_react.default.useRef(0);
158
+ const renderCallbackCountRef = import_react.default.useRef(0);
159
+ const rawActiveRef = import_react.default.useRef(false);
160
+ const openRef = import_react.default.useRef(open);
161
+ const wasTargetHiddenRef = import_react.default.useRef(!rawActive);
162
+ const hasHadActiveTargetRef = import_react.default.useRef(false);
163
+ const shouldStartExit = !rawActive && present && Boolean(open);
164
+ const active = rawActive || exiting || shouldStartExit;
165
+ const targetHidden = !rawActive;
166
+ const skipNextAnimation = Boolean(rawActive && wasTargetHiddenRef.current && hasHadActiveTargetRef.current && open);
167
+ rawActiveRef.current = rawActive;
168
+ openRef.current = open;
169
+ if (rawActive) {
170
+ hasHadActiveTargetRef.current = true;
171
+ }
172
+ wasTargetHiddenRef.current = targetHidden;
173
+ const releasePresenceLatch = import_react.default.useCallback(() => {
174
+ setExiting(false);
175
+ if (!rawActiveRef.current) {
176
+ setPresent(false);
177
+ }
178
+ }, []);
179
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
180
+ if (shouldStartExit) {
181
+ setExiting(true);
182
+ }
183
+ }, [shouldStartExit]);
184
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
185
+ if (open && rawActive) {
186
+ setTargetFullyHidden(false);
187
+ return;
188
+ }
189
+ if (!open && !active) {
190
+ setTargetFullyHidden(true);
191
+ }
192
+ }, [
193
+ active,
194
+ open,
195
+ rawActive
196
+ ]);
197
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
198
+ if (rawActive) {
199
+ setPresent(true);
200
+ } else if (!active) {
201
+ setPresent(false);
202
+ }
203
+ if (rawActive && exiting) {
204
+ setExiting(false);
205
+ }
206
+ }, [
207
+ active,
208
+ exiting,
209
+ rawActive
210
+ ]);
211
+ const handoff = import_react.default.useMemo(() => ({
212
+ hidden: targetHidden,
213
+ skipNextAnimation,
214
+ onTransition(e) {
215
+ if (e.phase !== "end" || e.finished === false) return;
216
+ if (e.cause !== "close") {
217
+ setTargetFullyHidden(false);
218
+ return;
219
+ }
220
+ if (openRef.current && rawActiveRef.current) {
221
+ setTargetFullyHidden(false);
222
+ return;
223
+ }
224
+ setTargetFullyHidden(true);
225
+ releasePresenceLatch();
226
+ }
227
+ }), [
228
+ releasePresenceLatch,
229
+ skipNextAnimation,
230
+ targetHidden
231
+ ]);
232
+ const registerTarget = import_react.default.useCallback(() => {
233
+ targetCountRef.current += 1;
234
+ if (process.env.NODE_ENV === "development" && targetCountRef.current > 1) {
235
+ console.error(`Adapt expected exactly one target in scope "${scope}", but ${targetCountRef.current} targets registered.`);
236
+ }
237
+ }, [scope]);
238
+ const unregisterTarget = import_react.default.useCallback(() => {
239
+ targetCountRef.current = Math.max(0, targetCountRef.current - 1);
240
+ }, []);
241
+ const registerContents = import_react.default.useCallback(() => {
242
+ contentsCountRef.current += 1;
243
+ }, []);
244
+ const unregisterContents = import_react.default.useCallback(() => {
245
+ contentsCountRef.current = Math.max(0, contentsCountRef.current - 1);
246
+ }, []);
247
+ const registerRenderCallback = import_react.default.useCallback(() => {
248
+ renderCallbackCountRef.current += 1;
249
+ }, []);
250
+ const unregisterRenderCallback = import_react.default.useCallback(() => {
251
+ renderCallbackCountRef.current = Math.max(0, renderCallbackCountRef.current - 1);
252
+ }, []);
253
+ import_react.default.useEffect(() => {
254
+ if (process.env.NODE_ENV !== "development") return;
255
+ if (!active) return;
256
+ const timer = setTimeout(() => {
257
+ if (rawActiveRef.current && targetCountRef.current === 0 && contentsCountRef.current === 0 && renderCallbackCountRef.current === 0) {
258
+ console.error(`Adapt is active in scope "${scope}" but no target registered with useAdaptTarget(), Adapt.Contents marker, or render callback consumed it.`);
259
+ }
260
+ });
261
+ return () => clearTimeout(timer);
262
+ }, [active, scope]);
263
+ const FinalContents = Contents || AdaptSlotContents;
264
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LastAdaptContextScope.Provider, {
265
+ value: scope,
266
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProvideAdaptContext, {
267
+ Contents: FinalContents,
268
+ when,
269
+ platform,
270
+ setPlatform,
271
+ setWhen,
272
+ active,
273
+ rawActive,
274
+ setRawActive,
275
+ portalName,
276
+ scopeName: scope,
277
+ slot: slotRef.current,
278
+ open,
279
+ onOpenChange,
280
+ state,
281
+ handoff,
282
+ targetFullyHidden,
283
+ registerTarget,
284
+ unregisterTarget,
285
+ registerContents,
286
+ unregisterContents,
287
+ registerRenderCallback,
288
+ unregisterRenderCallback,
289
+ children
290
+ })
291
+ });
149
292
  };
150
- const AdaptContents = ({
151
- scope,
152
- ...rest
153
- }) => {
154
- const context = useAdaptContext(scope);
155
- if (!context?.Contents) throw new Error(process.env.NODE_ENV === "production" ? `tamagui.dev/docs/intro/errors#warning-002` : `You're rendering a Tamagui <Adapt /> component without nesting it inside a parent that is able to adapt.`);
156
- return import_react.default.createElement(context.Contents, {
157
- ...rest,
158
- key: `stable`
159
- });
293
+ const AdaptContents = ({ scope, ...rest }) => {
294
+ const context = useAdaptContext(scope);
295
+ if (!context?.Contents) {
296
+ throw new Error(process.env.NODE_ENV === "production" ? `tamagui.dev/docs/intro/errors#warning-002` : `You're rendering a Tamagui <Adapt /> component without nesting it inside a parent that is able to adapt.`);
297
+ }
298
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
299
+ if (!context.active) return;
300
+ context.registerContents();
301
+ return () => {
302
+ context.unregisterContents();
303
+ };
304
+ }, [
305
+ context.active,
306
+ context.registerContents,
307
+ context.unregisterContents
308
+ ]);
309
+ return import_react.default.createElement(context.Contents, {
310
+ ...rest,
311
+ scope,
312
+ key: `stable`
313
+ });
160
314
  };
161
315
  AdaptContents.shouldForwardSpace = true;
162
316
  const Adapt = (0, import_helpers.withStaticProperties)(function Adapt2(props) {
163
- const {
164
- platform,
165
- when,
166
- children,
167
- scope
168
- } = props;
169
- const context = useAdaptContext(scope);
170
- const enabled = useAdaptIsActiveGiven(props);
171
- (0, import_constants.useIsomorphicLayoutEffect)(() => {
172
- context?.setWhen?.(when || enabled);
173
- context?.setPlatform?.(platform || null);
174
- }, [when, platform, enabled, context.setWhen, context.setPlatform]);
175
- (0, import_constants.useIsomorphicLayoutEffect)(() => {
176
- return () => {
177
- context?.setWhen?.(null);
178
- context?.setPlatform?.(null);
179
- };
180
- }, []);
181
- let output;
182
- if (typeof children === "function") {
183
- const Component = context?.Contents;
184
- output = children(Component ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(Component, {}) : null);
185
- } else output = children;
186
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_z_index_stack.StackZIndexContext, {
187
- children: !enabled ? null : output
188
- });
189
- }, {
190
- Contents: AdaptContents
191
- });
192
- const AdaptPortalContents = props => {
193
- const isActive = useAdaptIsActive(props.scope);
194
- const {
195
- portalName
196
- } = useAdaptContext(props.scope);
197
- const childrenStore = (0, import_react.useContext)(AdaptChildrenStoreContext);
198
- if (!import_constants.isWeb && (0, import_native.getPortal)().state.type === "teleport" && childrenStore) return /* @__PURE__ */(0, import_jsx_runtime.jsx)(AdaptPortalTeleport, {
199
- isActive,
200
- store: childrenStore,
201
- children: props.children
202
- });
203
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.PortalItem, {
204
- passThrough: !isActive,
205
- hostName: portalName,
206
- children: props.children
207
- });
317
+ const { platform, when, children, scope } = props;
318
+ const context = useAdaptContext(scope);
319
+ const rawEnabled = useAdaptIsActiveGiven(props);
320
+ const enabled = rawEnabled || context.active;
321
+ const isRenderCallback = typeof children === "function";
322
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
323
+ context?.setWhen?.(when || rawEnabled);
324
+ context?.setPlatform?.(platform || null);
325
+ context?.setRawActive?.(rawEnabled);
326
+ }, [
327
+ when,
328
+ platform,
329
+ rawEnabled,
330
+ context.setWhen,
331
+ context.setPlatform,
332
+ context.setRawActive
333
+ ]);
334
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
335
+ if (!enabled || !isRenderCallback) return;
336
+ context.registerRenderCallback();
337
+ return () => {
338
+ context.unregisterRenderCallback();
339
+ };
340
+ }, [
341
+ enabled,
342
+ isRenderCallback,
343
+ context.registerRenderCallback,
344
+ context.unregisterRenderCallback
345
+ ]);
346
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
347
+ return () => {
348
+ context?.setWhen?.(null);
349
+ context?.setPlatform?.(null);
350
+ context?.setRawActive?.(false);
351
+ };
352
+ }, []);
353
+ let output;
354
+ if (isRenderCallback) {
355
+ const Component = context?.Contents;
356
+ output = children(Component ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}) : null, getAdaptRenderState(context));
357
+ } else {
358
+ output = children;
359
+ }
360
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_z_index_stack.StackZIndexContext, { children: !enabled ? null : output });
361
+ }, { Contents: AdaptContents });
362
+ const AdaptPortalContents = (props) => {
363
+ const isActive = useAdaptIsActive(props.scope);
364
+ const { slot } = useAdaptContext(props.scope);
365
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AdaptSlotPublisher, {
366
+ isActive,
367
+ slot,
368
+ children: props.children
369
+ });
370
+ };
371
+ function AdaptSlotContents({ scope }) {
372
+ const { slot } = useAdaptContext(scope);
373
+ import_react.default.useSyncExternalStore(slot?.subscribe ?? emptySubscribe, slot?.getSnapshot ?? emptySnapshot, slot?.getSnapshot ?? emptySnapshot);
374
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: slot?.element ?? null });
375
+ }
376
+ function AdaptSlotPublisher({ isActive, slot, children }) {
377
+ const publishedRef = import_react.default.useRef(false);
378
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
379
+ if (!slot) return;
380
+ if (isActive) {
381
+ slot.publish(children);
382
+ publishedRef.current = true;
383
+ } else {
384
+ slot.clear();
385
+ publishedRef.current = false;
386
+ }
387
+ slot.notify();
388
+ });
389
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
390
+ return () => {
391
+ if (publishedRef.current) {
392
+ slot?.clear();
393
+ slot?.notify();
394
+ publishedRef.current = false;
395
+ }
396
+ };
397
+ }, [slot]);
398
+ return isActive ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
399
+ }
400
+ const emptySubscribe = () => () => {};
401
+ const emptySnapshot = () => 0;
402
+ const useAdaptIsActiveGiven = ({ when, platform }) => {
403
+ const media = (0, import_core.useMedia)();
404
+ if (when == null && platform == null) {
405
+ return false;
406
+ }
407
+ if (when === true) {
408
+ return true;
409
+ }
410
+ let enabled = false;
411
+ if (platform === "touch") enabled = import_constants.isTouchable;
412
+ else if (platform === "native") enabled = !import_constants.isWeb;
413
+ else if (platform === "web") enabled = import_constants.isWeb;
414
+ else if (platform === "ios") enabled = import_constants.isIos;
415
+ else if (platform === "android") enabled = import_constants.isAndroid;
416
+ if (platform && enabled == false) {
417
+ return false;
418
+ }
419
+ if (when && typeof when === "string") {
420
+ enabled = media[when];
421
+ }
422
+ return enabled;
423
+ };
424
+ const useAdaptIsActive = (scope) => {
425
+ const props = useAdaptContext(scope);
426
+ const isActiveGiven = useAdaptIsActiveGiven(props);
427
+ return props.active || isActiveGiven;
208
428
  };
209
- function AdaptPortalTeleport({
210
- isActive,
211
- store,
212
- children
213
- }) {
214
- (0, import_constants.useIsomorphicLayoutEffect)(() => {
215
- if (isActive) store.set(children);else store.set(null);
216
- });
217
- (0, import_constants.useIsomorphicLayoutEffect)(() => {
218
- return () => store.set(null);
219
- }, [store]);
220
- return isActive ? null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
221
- children
222
- });
429
+ function useAdaptTarget(scope) {
430
+ const context = useAdaptContext(scope);
431
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
432
+ if (!context.active) return;
433
+ context.registerTarget();
434
+ return () => {
435
+ context.unregisterTarget();
436
+ };
437
+ }, [
438
+ context.active,
439
+ context.registerTarget,
440
+ context.unregisterTarget
441
+ ]);
442
+ if (!context.active) {
443
+ return null;
444
+ }
445
+ return {
446
+ open: context.open,
447
+ onOpenChange: context.onOpenChange,
448
+ handoff: context.handoff,
449
+ state: context.state
450
+ };
223
451
  }
224
- const useAdaptIsActiveGiven = ({
225
- when,
226
- platform
227
- }) => {
228
- const media = (0, import_core.useMedia)();
229
- if (when == null && platform == null) return false;
230
- if (when === true) return true;
231
- let enabled = false;
232
- if (platform === "touch") enabled = import_constants.isTouchable;else if (platform === "native") enabled = !import_constants.isWeb;else if (platform === "web") enabled = import_constants.isWeb;else if (platform === "ios") enabled = import_constants.isIos;else if (platform === "android") enabled = import_constants.isAndroid;
233
- if (platform && enabled == false) return false;
234
- if (when && typeof when === "string") enabled = media[when];
235
- return enabled;
452
+ const AdaptCapabilities = ({ children, scroll, overlay, dismiss }) => {
453
+ const parent = (0, import_react.useContext)(AdaptCapabilitiesContext);
454
+ const value = import_react.default.useMemo(() => ({
455
+ scroll: scroll ?? parent.scroll,
456
+ overlay: overlay ?? parent.overlay,
457
+ dismiss: dismiss ?? parent.dismiss
458
+ }), [
459
+ dismiss,
460
+ overlay,
461
+ parent.dismiss,
462
+ parent.overlay,
463
+ parent.scroll,
464
+ scroll
465
+ ]);
466
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AdaptCapabilitiesContext.Provider, {
467
+ value,
468
+ children
469
+ });
236
470
  };
237
- const useAdaptIsActive = scope => {
238
- return useAdaptIsActiveGiven(useAdaptContext(scope));
239
- };
471
+ const useAdaptedCapabilities = () => {
472
+ return (0, import_react.useContext)(AdaptCapabilitiesContext);
473
+ };
474
+ function getAdaptRenderState(context) {
475
+ return {
476
+ active: context.active,
477
+ open: context.open,
478
+ onOpenChange: context.onOpenChange,
479
+ state: context.state,
480
+ handoff: context.handoff
481
+ };
482
+ }