@seed-design/stackflow 0.0.1-rc.1 → 0.0.1-rc.4

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.
Files changed (92) hide show
  1. package/lib/components/AppBar/AppBar.cjs +92 -0
  2. package/lib/components/AppBar/AppBar.d.ts +13 -12
  3. package/lib/components/AppBar/AppBar.js +81 -0
  4. package/lib/components/AppBar/AppBar.namespace.cjs +15 -0
  5. package/lib/components/AppBar/AppBar.namespace.d.ts +2 -2
  6. package/lib/components/AppBar/AppBar.namespace.js +1 -0
  7. package/lib/components/AppBar/index.cjs +17 -0
  8. package/lib/components/AppBar/index.d.ts +3 -3
  9. package/lib/components/AppBar/index.js +3 -0
  10. package/lib/components/AppScreen/AppScreen.cjs +58 -0
  11. package/lib/components/AppScreen/AppScreen.d.ts +8 -7
  12. package/lib/components/AppScreen/AppScreen.js +50 -0
  13. package/lib/components/AppScreen/AppScreen.namespace.cjs +13 -0
  14. package/lib/components/AppScreen/AppScreen.namespace.d.ts +2 -2
  15. package/lib/components/AppScreen/AppScreen.namespace.js +1 -0
  16. package/lib/components/AppScreen/index.cjs +15 -0
  17. package/lib/components/AppScreen/index.d.ts +3 -3
  18. package/lib/components/AppScreen/index.js +3 -0
  19. package/lib/components/index.cjs +25 -0
  20. package/lib/components/index.d.ts +2 -2
  21. package/lib/components/index.js +6 -0
  22. package/lib/index.cjs +29 -0
  23. package/lib/index.d.ts +3 -3
  24. package/lib/index.js +9 -786
  25. package/lib/plugin.cjs +16 -0
  26. package/lib/plugin.d.ts +1 -1
  27. package/lib/plugin.js +12 -0
  28. package/lib/primitive/AppBar/AppBar.cjs +43 -0
  29. package/lib/primitive/AppBar/AppBar.d.ts +7 -6
  30. package/lib/primitive/AppBar/AppBar.js +36 -0
  31. package/lib/primitive/AppBar/AppBar.namespace.cjs +12 -0
  32. package/lib/primitive/AppBar/AppBar.namespace.d.ts +1 -1
  33. package/lib/primitive/AppBar/AppBar.namespace.js +1 -0
  34. package/lib/primitive/AppBar/index.cjs +14 -0
  35. package/lib/primitive/AppBar/index.d.ts +2 -2
  36. package/lib/primitive/AppBar/index.js +3 -0
  37. package/lib/primitive/AppBar/useAppBar.cjs +38 -0
  38. package/lib/primitive/AppBar/useAppBar.d.ts +168 -167
  39. package/lib/primitive/AppBar/useAppBar.js +34 -0
  40. package/lib/primitive/AppBar/useAppBarContext.cjs +20 -0
  41. package/lib/primitive/AppBar/useAppBarContext.d.ts +3 -2
  42. package/lib/primitive/AppBar/useAppBarContext.js +15 -0
  43. package/lib/primitive/AppScreen/AppScreen.cjs +57 -0
  44. package/lib/primitive/AppScreen/AppScreen.d.ts +7 -6
  45. package/lib/primitive/AppScreen/AppScreen.js +50 -0
  46. package/lib/primitive/AppScreen/AppScreen.namespace.cjs +12 -0
  47. package/lib/primitive/AppScreen/AppScreen.namespace.d.ts +1 -1
  48. package/lib/primitive/AppScreen/AppScreen.namespace.js +1 -0
  49. package/lib/primitive/AppScreen/index.cjs +16 -0
  50. package/lib/primitive/AppScreen/index.d.ts +3 -3
  51. package/lib/primitive/AppScreen/index.js +4 -0
  52. package/lib/primitive/AppScreen/useAppScreen.cjs +64 -0
  53. package/lib/primitive/AppScreen/useAppScreen.d.ts +657 -655
  54. package/lib/primitive/AppScreen/useAppScreen.js +60 -0
  55. package/lib/primitive/AppScreen/useAppScreenContext.cjs +20 -0
  56. package/lib/primitive/AppScreen/useAppScreenContext.d.ts +3 -2
  57. package/lib/primitive/AppScreen/useAppScreenContext.js +15 -0
  58. package/lib/primitive/GlobalInteraction/GlobalInteraction.cjs +27 -0
  59. package/lib/primitive/GlobalInteraction/GlobalInteraction.d.ts +3 -2
  60. package/lib/primitive/GlobalInteraction/GlobalInteraction.js +23 -0
  61. package/lib/primitive/GlobalInteraction/index.cjs +11 -0
  62. package/lib/primitive/GlobalInteraction/index.d.ts +2 -2
  63. package/lib/primitive/GlobalInteraction/index.js +2 -0
  64. package/lib/primitive/GlobalInteraction/useGlobalInteraction.cjs +122 -0
  65. package/lib/primitive/GlobalInteraction/useGlobalInteraction.d.ts +5 -4
  66. package/lib/primitive/GlobalInteraction/useGlobalInteraction.js +118 -0
  67. package/lib/primitive/GlobalInteraction/useGlobalInteractionContext.cjs +20 -0
  68. package/lib/primitive/GlobalInteraction/useGlobalInteractionContext.d.ts +3 -2
  69. package/lib/primitive/GlobalInteraction/useGlobalInteractionContext.js +15 -0
  70. package/lib/primitive/GlobalInteraction/useSwipeBack.cjs +57 -0
  71. package/lib/primitive/GlobalInteraction/useSwipeBack.d.ts +1 -1
  72. package/lib/primitive/GlobalInteraction/useSwipeBack.js +53 -0
  73. package/lib/primitive/index.cjs +27 -0
  74. package/lib/primitive/index.d.ts +3 -3
  75. package/lib/primitive/index.js +9 -0
  76. package/lib/primitive/private/useElementOffset.cjs +53 -0
  77. package/lib/primitive/private/useElementOffset.js +30 -0
  78. package/lib/primitive/private/useTopActivity.cjs +31 -0
  79. package/lib/primitive/private/useTopActivity.js +27 -0
  80. package/lib/utils/createStyleContext.cjs +76 -0
  81. package/lib/utils/createStyleContext.js +72 -0
  82. package/lib/utils/createWithStateProps.d.ts +2 -1
  83. package/package.json +13 -14
  84. package/src/components/AppScreen/AppScreen.namespace.ts +1 -0
  85. package/src/components/AppScreen/{index.tsx → index.ts} +1 -0
  86. package/src/plugin.tsx +1 -1
  87. package/lib/index.js.map +0 -7
  88. package/lib/index.mjs +0 -759
  89. package/lib/index.mjs.map +0 -7
  90. /package/src/components/AppBar/{index.tsx → index.ts} +0 -0
  91. /package/src/components/{index.tsx → index.ts} +0 -0
  92. /package/src/primitive/{index.tsx → index.ts} +0 -0
package/lib/index.mjs DELETED
@@ -1,759 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- // src/components/AppScreen/AppScreen.tsx
8
- import { appScreen } from "@seed-design/css/recipes/app-screen";
9
- import { forwardRef as forwardRef6, useMemo as useMemo5 } from "react";
10
-
11
- // src/primitive/index.tsx
12
- var primitive_exports = {};
13
- __export(primitive_exports, {
14
- AppBar: () => AppBar_namespace_exports,
15
- AppBarLeft: () => AppBarLeft,
16
- AppBarMain: () => AppBarMain,
17
- AppBarRight: () => AppBarRight,
18
- AppBarRoot: () => AppBarRoot,
19
- AppScreen: () => AppScreen_namespace_exports,
20
- AppScreenDim: () => AppScreenDim,
21
- AppScreenEdge: () => AppScreenEdge,
22
- AppScreenLayer: () => AppScreenLayer,
23
- AppScreenRoot: () => AppScreenRoot,
24
- GlobalInteraction: () => GlobalInteraction,
25
- useAppScreenContext: () => useAppScreenContext,
26
- useGlobalInteractionContext: () => useGlobalInteractionContext
27
- });
28
-
29
- // src/primitive/AppScreen/AppScreen.tsx
30
- import { mergeProps } from "@seed-design/dom-utils";
31
- import { Primitive } from "@seed-design/react-primitive";
32
- import { forwardRef } from "react";
33
-
34
- // src/primitive/AppScreen/useAppScreen.tsx
35
- import { dataAttr, elementProps } from "@seed-design/dom-utils";
36
- import { useNullableActivity, useZIndexBase } from "@stackflow/react-ui-core";
37
- import { useMemo as useMemo2 } from "react";
38
-
39
- // src/primitive/GlobalInteraction/useSwipeBack.ts
40
- import { useEffect, useMemo } from "react";
41
-
42
- // src/primitive/GlobalInteraction/useGlobalInteractionContext.tsx
43
- import { createContext, useContext } from "react";
44
- var GlobalInteractionContext = createContext(null);
45
- var GlobalInteractionProvider = GlobalInteractionContext.Provider;
46
- function useGlobalInteractionContext({
47
- strict = true
48
- } = {}) {
49
- const context = useContext(GlobalInteractionContext);
50
- if (!context && strict) {
51
- throw new Error("useGlobalInteractionContext must be used within a GlobalInteractionProvider");
52
- }
53
- return context;
54
- }
55
-
56
- // src/primitive/GlobalInteraction/useSwipeBack.ts
57
- function useSwipeBack(props) {
58
- const globalInteraction = useGlobalInteractionContext();
59
- const events = globalInteraction.getSwipeBackEvents(props);
60
- useEffect(() => {
61
- return () => {
62
- events.reset();
63
- };
64
- }, [events]);
65
- return useMemo(
66
- () => ({
67
- activityProps: {
68
- "data-swipe-back": ""
69
- },
70
- layerProps: {
71
- onTransitionEnd: (e) => {
72
- if (e.target === e.currentTarget) {
73
- events.reset();
74
- }
75
- },
76
- onAnimationEnd: (e) => {
77
- if (e.target === e.currentTarget) {
78
- events.reset();
79
- }
80
- }
81
- },
82
- edgeProps: {
83
- tabIndex: -1,
84
- onTouchStart: (e) => {
85
- const x0 = e.touches[0].clientX;
86
- const t0 = Date.now();
87
- events.startSwipeBack({ x0, t0 });
88
- },
89
- onTouchMove: (e) => {
90
- const x = e.touches[0].clientX;
91
- const t = Date.now();
92
- events.moveSwipeBack({ x, t });
93
- },
94
- onTouchEnd: () => {
95
- events.endSwipeBack({});
96
- },
97
- onTouchCancel: () => {
98
- events.endSwipeBack({});
99
- }
100
- }
101
- }),
102
- [events]
103
- );
104
- }
105
-
106
- // src/primitive/AppScreen/useAppScreen.tsx
107
- function useAppScreen(props) {
108
- var _a;
109
- const activity = useNullableActivity();
110
- const transitionState = (_a = activity == null ? void 0 : activity.transitionState) != null ? _a : "enter-done";
111
- const { activityProps, layerProps, edgeProps } = useSwipeBack(props);
112
- const zIndexBase = useZIndexBase();
113
- const zIndexStyle = useMemo2(
114
- () => ({
115
- "--z-index-base": zIndexBase.toString()
116
- }),
117
- [zIndexBase]
118
- );
119
- const stateProps = useMemo2(
120
- () => ({
121
- "data-activity-is-top": dataAttr(activity == null ? void 0 : activity.isTop),
122
- "data-activity-is-active": dataAttr(activity == null ? void 0 : activity.isActive),
123
- "data-transition-state": transitionState
124
- }),
125
- [transitionState, activity == null ? void 0 : activity.isActive, activity == null ? void 0 : activity.isTop]
126
- );
127
- return useMemo2(
128
- () => ({
129
- activity,
130
- stateProps,
131
- activityProps: elementProps({
132
- "data-part": "activity",
133
- "data-activity-type": "full-screen",
134
- ...activityProps,
135
- ...stateProps,
136
- "data-activity-id": activity == null ? void 0 : activity.id,
137
- style: zIndexStyle,
138
- // FIXME: @stackflow/react should prevent activity.id hydration mismatch; this is temporal fix.
139
- suppressHydrationWarning: true
140
- }),
141
- dimProps: elementProps({
142
- "data-part": "dim",
143
- ...stateProps
144
- }),
145
- layerProps: elementProps({
146
- "data-part": "layer",
147
- ...stateProps,
148
- ...layerProps
149
- }),
150
- edgeProps: elementProps({
151
- "data-part": "edge",
152
- "aria-hidden": true,
153
- tabIndex: -1,
154
- ...edgeProps,
155
- ...stateProps
156
- })
157
- }),
158
- [activity, zIndexStyle, stateProps, activityProps, edgeProps, layerProps]
159
- );
160
- }
161
-
162
- // src/primitive/AppScreen/useAppScreenContext.ts
163
- import { createContext as createContext2, useContext as useContext2 } from "react";
164
- var AppScreenContext = createContext2(null);
165
- var AppScreenProvider = AppScreenContext.Provider;
166
- function useAppScreenContext({
167
- strict = true
168
- } = {}) {
169
- const context = useContext2(AppScreenContext);
170
- if (!context && strict) {
171
- throw new Error("useAppScreenContext must be used within a AppScreen");
172
- }
173
- return context;
174
- }
175
-
176
- // src/primitive/AppScreen/AppScreen.tsx
177
- import { jsx } from "react/jsx-runtime";
178
- var AppScreenRoot = forwardRef((props, ref) => {
179
- const {
180
- swipeBackDisplacementRatioThreshold,
181
- swipeBackVelocityThreshold,
182
- onSwipeBackEnd,
183
- onSwipeBackMove,
184
- onSwipeBackStart,
185
- ...otherProps
186
- } = props;
187
- const api = useAppScreen({
188
- swipeBackDisplacementRatioThreshold,
189
- swipeBackVelocityThreshold,
190
- onSwipeBackEnd,
191
- onSwipeBackMove,
192
- onSwipeBackStart
193
- });
194
- return /* @__PURE__ */ jsx(AppScreenProvider, { value: api, children: /* @__PURE__ */ jsx(
195
- Primitive.div,
196
- {
197
- ref,
198
- "data-stackflow-component-name": "AppScreen",
199
- ...mergeProps(api.activityProps, otherProps)
200
- }
201
- ) });
202
- });
203
- AppScreenRoot.displayName = "AppScreenRoot";
204
- var AppScreenDim = forwardRef((props, ref) => {
205
- const { dimProps } = useAppScreenContext();
206
- return /* @__PURE__ */ jsx(Primitive.div, { ref, ...mergeProps(dimProps, props) });
207
- });
208
- AppScreenDim.displayName = "AppScreenDim";
209
- var AppScreenEdge = forwardRef((props, ref) => {
210
- const { edgeProps } = useAppScreenContext();
211
- return /* @__PURE__ */ jsx(Primitive.div, { ref, ...mergeProps(edgeProps, props) });
212
- });
213
- AppScreenEdge.displayName = "AppScreenEdge";
214
- var AppScreenLayer = forwardRef((props, ref) => {
215
- const { layerProps } = useAppScreenContext();
216
- return /* @__PURE__ */ jsx(Primitive.div, { ref, ...mergeProps(layerProps, props) });
217
- });
218
- AppScreenLayer.displayName = "AppScreenLayer";
219
-
220
- // src/primitive/AppScreen/AppScreen.namespace.ts
221
- var AppScreen_namespace_exports = {};
222
- __export(AppScreen_namespace_exports, {
223
- Dim: () => AppScreenDim,
224
- Edge: () => AppScreenEdge,
225
- Layer: () => AppScreenLayer,
226
- Root: () => AppScreenRoot
227
- });
228
-
229
- // src/primitive/AppBar/AppBar.tsx
230
- import { Primitive as Primitive2 } from "@seed-design/react-primitive";
231
- import { forwardRef as forwardRef2 } from "react";
232
-
233
- // src/primitive/AppBar/useAppBar.tsx
234
- import { elementProps as elementProps2 } from "@seed-design/dom-utils";
235
- import { useMemo as useMemo3, useState as useState2 } from "react";
236
-
237
- // src/primitive/private/useElementOffset.ts
238
- import * as React from "react";
239
- var useLayoutEffect2 = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
240
- function useElementOffset(element) {
241
- const [offset, setOffset] = React.useState(
242
- void 0
243
- );
244
- useLayoutEffect2(() => {
245
- var _a;
246
- if (!element) {
247
- setOffset(void 0);
248
- return;
249
- }
250
- if (element) {
251
- setOffset({
252
- fromLeft: element.offsetLeft + element.offsetWidth,
253
- fromRight: ((_a = element.offsetParent) != null ? _a : document.body).clientWidth - element.offsetLeft
254
- });
255
- const resizeObserver = new ResizeObserver(() => {
256
- var _a2;
257
- const fromLeft = element.offsetLeft + element.offsetWidth;
258
- const fromRight = ((_a2 = element.offsetParent) != null ? _a2 : document.body).clientWidth - element.offsetLeft;
259
- setOffset({ fromLeft, fromRight });
260
- });
261
- resizeObserver.observe(element);
262
- return () => resizeObserver.unobserve(element);
263
- }
264
- }, [element]);
265
- return offset;
266
- }
267
-
268
- // src/primitive/AppBar/useAppBar.tsx
269
- function useAppBar(_props) {
270
- var _a, _b;
271
- const { stateProps } = useAppScreenContext();
272
- const [root, rootRef] = useState2(null);
273
- const [left, leftRef] = useState2(null);
274
- const [right, rightRef] = useState2(null);
275
- const leftOffset = useElementOffset(left);
276
- const rightOffset = useElementOffset(right);
277
- const centeredTitlePaddingX = root ? `${Math.max((_a = leftOffset == null ? void 0 : leftOffset.fromLeft) != null ? _a : 0, (_b = rightOffset == null ? void 0 : rightOffset.fromRight) != null ? _b : 0)}px` : "initial";
278
- return useMemo3(
279
- () => ({
280
- refs: {
281
- root: rootRef,
282
- left: leftRef,
283
- right: rightRef
284
- },
285
- stateProps,
286
- rootProps: elementProps2({
287
- "data-part": "appBar",
288
- ...stateProps,
289
- style: {
290
- "--centered-title-padding-x": centeredTitlePaddingX
291
- }
292
- })
293
- }),
294
- [stateProps, centeredTitlePaddingX]
295
- );
296
- }
297
-
298
- // src/primitive/AppBar/useAppBarContext.ts
299
- import { createContext as createContext3, useContext as useContext3 } from "react";
300
- var AppBarContext = createContext3(null);
301
- var AppBarProvider = AppBarContext.Provider;
302
- function useAppBarContext({
303
- strict = true
304
- } = {}) {
305
- const context = useContext3(AppBarContext);
306
- if (!context && strict) {
307
- throw new Error("useAppBarContext must be used within a AppBar");
308
- }
309
- return context;
310
- }
311
-
312
- // src/primitive/AppBar/AppBar.tsx
313
- import { mergeProps as mergeProps2 } from "@seed-design/dom-utils";
314
- import { composeRefs } from "@radix-ui/react-compose-refs";
315
- import { jsx as jsx2 } from "react/jsx-runtime";
316
- var AppBarRoot = forwardRef2((props, ref) => {
317
- const { ...otherProps } = props;
318
- const api = useAppBar({});
319
- return /* @__PURE__ */ jsx2(AppBarProvider, { value: api, children: /* @__PURE__ */ jsx2(
320
- Primitive2.div,
321
- {
322
- ref: composeRefs(api.refs.root, ref),
323
- ...mergeProps2(api.rootProps, otherProps)
324
- }
325
- ) });
326
- });
327
- AppBarRoot.displayName = "AppBarRoot";
328
- var AppBarLeft = forwardRef2((props, ref) => {
329
- const { refs, stateProps } = useAppBarContext();
330
- return /* @__PURE__ */ jsx2(Primitive2.div, { ref: composeRefs(refs.left, ref), ...mergeProps2(stateProps, props) });
331
- });
332
- AppBarLeft.displayName = "AppBarLeft";
333
- var AppBarRight = forwardRef2((props, ref) => {
334
- const { refs, stateProps } = useAppBarContext();
335
- return /* @__PURE__ */ jsx2(Primitive2.div, { ref: composeRefs(refs.right, ref), ...mergeProps2(stateProps, props) });
336
- });
337
- AppBarRight.displayName = "AppBarRight";
338
- var AppBarMain = forwardRef2((props, ref) => {
339
- const { stateProps } = useAppBarContext();
340
- return /* @__PURE__ */ jsx2(Primitive2.div, { ref, ...mergeProps2(stateProps, props) });
341
- });
342
-
343
- // src/primitive/AppBar/AppBar.namespace.ts
344
- var AppBar_namespace_exports = {};
345
- __export(AppBar_namespace_exports, {
346
- Left: () => AppBarLeft,
347
- Main: () => AppBarMain,
348
- Right: () => AppBarRight,
349
- Root: () => AppBarRoot
350
- });
351
-
352
- // src/primitive/GlobalInteraction/GlobalInteraction.tsx
353
- import { composeRefs as composeRefs2 } from "@radix-ui/react-compose-refs";
354
- import { mergeProps as mergeProps3 } from "@seed-design/dom-utils";
355
- import { Primitive as Primitive3 } from "@seed-design/react-primitive";
356
- import { forwardRef as forwardRef3 } from "react";
357
-
358
- // src/primitive/GlobalInteraction/useGlobalInteraction.ts
359
- import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
360
- import { useCallback, useMemo as useMemo4, useRef, useState as useState4 } from "react";
361
-
362
- // src/primitive/private/useTopActivity.ts
363
- import { useStack } from "@stackflow/react";
364
- import { useEffect as useEffect3, useState as useState3 } from "react";
365
- function useTopActivity() {
366
- var _a, _b;
367
- const stack = useStack();
368
- if (!stack) {
369
- throw new Error(
370
- "useStack is not available in the context. Make sure you are using @stackflow/react >= 1.4.1. (https://github.com/daangn/stackflow/blob/main/integrations/react/CHANGELOG.md#141)"
371
- );
372
- }
373
- const topId = (_a = stack.activities.find((activity) => activity.isTop)) == null ? void 0 : _a.id;
374
- const topActivity = stack.activities.find((activity) => activity.isTop);
375
- const transitionState = (_b = topActivity == null ? void 0 : topActivity.transitionState) != null ? _b : "enter-done";
376
- const [topEl, setTopEl] = useState3(null);
377
- const activityType = topEl == null ? void 0 : topEl.dataset["activityType"];
378
- useEffect3(() => {
379
- if (!topId) return;
380
- const el = document.querySelector(`[data-activity-id="${topId}"]`);
381
- setTopEl(el);
382
- }, [topId]);
383
- return {
384
- transitionState,
385
- activityType
386
- };
387
- }
388
-
389
- // src/primitive/GlobalInteraction/useGlobalInteraction.ts
390
- function useGlobalInteraction() {
391
- const [swipeBackState, setSwipeBackState] = useState4("idle");
392
- const swipeBackContextRef = useRef({
393
- x0: 0,
394
- t0: 0,
395
- displacement: 0,
396
- displacementRatio: 0,
397
- velocity: 0
398
- });
399
- const stackRef = useRef(null);
400
- const setSwipeBackContext = useCallback((ctx) => {
401
- var _a, _b;
402
- swipeBackContextRef.current = ctx;
403
- (_a = stackRef.current) == null ? void 0 : _a.style.setProperty(
404
- "--swipe-back-displacement",
405
- `${ctx.displacement.toString()}px`
406
- );
407
- (_b = stackRef.current) == null ? void 0 : _b.style.setProperty(
408
- "--swipe-back-displacement-ratio",
409
- ctx.displacementRatio.toString()
410
- );
411
- }, []);
412
- const getSwipeBackEvents = useCallback(
413
- (props) => {
414
- const {
415
- swipeBackDisplacementRatioThreshold: displacementRatioThreshold = 0.4,
416
- swipeBackVelocityThreshold: velocityThreshold = 1
417
- } = props;
418
- const onSwipeStart = useCallbackRef(props.onSwipeBackStart);
419
- const onSwipeMove = useCallbackRef(props.onSwipeBackMove);
420
- const onSwipeEnd = useCallbackRef(props.onSwipeBackEnd);
421
- const startSwipeBack = useCallback(
422
- ({ x0, t0 }) => {
423
- setSwipeBackContext({
424
- x0,
425
- t0,
426
- displacement: 0,
427
- displacementRatio: 0,
428
- velocity: 0
429
- });
430
- setSwipeBackState("swiping");
431
- onSwipeStart == null ? void 0 : onSwipeStart();
432
- },
433
- [onSwipeStart]
434
- );
435
- const moveSwipeBack = useCallback(
436
- ({ x, t }) => {
437
- const displacement = x - swipeBackContextRef.current.x0;
438
- const displacementRatio = displacement / window.innerWidth;
439
- const velocity = displacement / (t - swipeBackContextRef.current.t0);
440
- setSwipeBackContext({
441
- ...swipeBackContextRef.current,
442
- displacement,
443
- displacementRatio,
444
- velocity
445
- });
446
- setSwipeBackState("swiping");
447
- onSwipeMove == null ? void 0 : onSwipeMove({ displacement, displacementRatio });
448
- },
449
- [onSwipeMove]
450
- );
451
- const endSwipeBack = useCallback(
452
- (_) => {
453
- const swiped = swipeBackContextRef.current.displacementRatio > displacementRatioThreshold || swipeBackContextRef.current.velocity > velocityThreshold;
454
- setSwipeBackState("transitioning");
455
- onSwipeEnd == null ? void 0 : onSwipeEnd({ swiped });
456
- },
457
- [onSwipeEnd, displacementRatioThreshold, velocityThreshold]
458
- );
459
- const reset = useCallback(() => {
460
- setSwipeBackContext({
461
- x0: 0,
462
- t0: 0,
463
- displacement: 0,
464
- displacementRatio: 0,
465
- velocity: 0
466
- });
467
- setSwipeBackState("idle");
468
- }, []);
469
- return useMemo4(
470
- () => ({
471
- startSwipeBack,
472
- moveSwipeBack,
473
- endSwipeBack,
474
- reset
475
- }),
476
- [startSwipeBack, moveSwipeBack, endSwipeBack, reset]
477
- );
478
- },
479
- [setSwipeBackContext]
480
- );
481
- const topActivity = useTopActivity();
482
- const stackProps = useMemo4(
483
- () => ({
484
- "data-swipe-back-state": swipeBackState,
485
- "data-global-transition-state": topActivity.transitionState,
486
- "data-top-activity-type": topActivity.activityType
487
- }),
488
- [swipeBackState, topActivity.transitionState, topActivity.activityType]
489
- );
490
- return useMemo4(
491
- () => ({
492
- stackRef,
493
- swipeBackContextRef,
494
- swipeBackState,
495
- setSwipeBackState,
496
- setSwipeBackContext,
497
- getSwipeBackEvents,
498
- stackProps
499
- }),
500
- [swipeBackState, setSwipeBackContext, getSwipeBackEvents, stackProps]
501
- );
502
- }
503
-
504
- // src/primitive/GlobalInteraction/GlobalInteraction.tsx
505
- import { jsx as jsx3 } from "react/jsx-runtime";
506
- var GlobalInteraction = forwardRef3(
507
- (props, ref) => {
508
- const api = useGlobalInteraction();
509
- return /* @__PURE__ */ jsx3(GlobalInteractionProvider, { value: api, children: /* @__PURE__ */ jsx3(
510
- Primitive3.div,
511
- {
512
- ref: composeRefs2(api.stackRef, ref),
513
- ...mergeProps3(api.stackProps, props)
514
- }
515
- ) });
516
- }
517
- );
518
- GlobalInteraction.displayName = "GlobalInteraction";
519
-
520
- // src/utils/createStyleContext.tsx
521
- import clsx from "clsx";
522
- import { createContext as createContext4, forwardRef as forwardRef4, useContext as useContext4 } from "react";
523
- import { jsx as jsx4 } from "react/jsx-runtime";
524
- function createStyleContext(recipe) {
525
- const ClassNamesContext = createContext4(null);
526
- const PropsContext = createContext4(null);
527
- const ClassNamesProvider3 = ({
528
- children,
529
- value
530
- }) => {
531
- return /* @__PURE__ */ jsx4(ClassNamesContext.Provider, { value, children });
532
- };
533
- const PropsProvider3 = ({ children, value }) => {
534
- return /* @__PURE__ */ jsx4(PropsContext.Provider, { value, children });
535
- };
536
- function useClassNames2() {
537
- const context = useContext4(ClassNamesContext);
538
- if (context === null) {
539
- throw new Error(
540
- "useClassNames must be used within a ClassNamesProvider. Did you forget to wrap your component in a ClassNamesProvider?"
541
- );
542
- }
543
- return context;
544
- }
545
- function useProps3() {
546
- return useContext4(PropsContext);
547
- }
548
- const withRootProvider = (Component, options) => {
549
- const { defaultProps } = options != null ? options : {};
550
- const StyledComponent = (innerProps) => {
551
- const props = { ...defaultProps != null ? defaultProps : {}, ...useProps3(), ...innerProps };
552
- const [variantProps, otherProps] = recipe.splitVariantProps(props);
553
- const classNames = recipe(variantProps);
554
- return /* @__PURE__ */ jsx4(ClassNamesProvider3, { value: classNames, children: /* @__PURE__ */ jsx4(Component, { ...otherProps }) });
555
- };
556
- StyledComponent.displayName = Component.displayName || Component.name;
557
- return StyledComponent;
558
- };
559
- const withProvider = (Component, slot, options) => {
560
- const { defaultProps } = options != null ? options : {};
561
- const StyledComponent = forwardRef4((innerProps, ref) => {
562
- const props = { ...defaultProps != null ? defaultProps : {}, ...useProps3(), ...innerProps };
563
- const [variantProps, otherProps] = recipe.splitVariantProps(props);
564
- const classNames = recipe(variantProps);
565
- const className = classNames[slot];
566
- return /* @__PURE__ */ jsx4(ClassNamesProvider3, { value: classNames, children: /* @__PURE__ */ jsx4(Component, { ref, ...otherProps, className: clsx(className, props.className) }) });
567
- });
568
- StyledComponent.displayName = Component.displayName || Component.name;
569
- return StyledComponent;
570
- };
571
- const withContext3 = (Component, slot) => {
572
- const StyledComponent = forwardRef4((props, ref) => {
573
- const classNames = useClassNames2();
574
- const className = classNames == null ? void 0 : classNames[slot];
575
- return /* @__PURE__ */ jsx4(Component, { ref, ...props, className: clsx(className, props.className) });
576
- });
577
- StyledComponent.displayName = Component.displayName || Component.name;
578
- return StyledComponent;
579
- };
580
- return {
581
- ClassNamesProvider: ClassNamesProvider3,
582
- PropsProvider: PropsProvider3,
583
- useClassNames: useClassNames2,
584
- useProps: useProps3,
585
- withRootProvider,
586
- withProvider,
587
- withContext: withContext3
588
- };
589
- }
590
-
591
- // src/components/AppBar/AppBar.tsx
592
- import { Slot } from "@radix-ui/react-slot";
593
- import { mergeProps as mergeProps4 } from "@seed-design/dom-utils";
594
- import { Primitive as Primitive4 } from "@seed-design/react-primitive";
595
- import { appBar } from "@seed-design/css/recipes/app-bar";
596
- import clsx2 from "clsx";
597
- import { forwardRef as forwardRef5 } from "react";
598
- import { appBarMain } from "@seed-design/css/recipes/app-bar-main";
599
- import { jsx as jsx5 } from "react/jsx-runtime";
600
- var { PropsProvider, ClassNamesProvider, useProps, withContext, useClassNames } = createStyleContext(appBar);
601
- var {
602
- PropsProvider: MainPropsProvider,
603
- withProvider: withMainProvider,
604
- withContext: withMainContext
605
- } = createStyleContext(appBarMain);
606
- var AppBarPropsProvider = PropsProvider;
607
- var AppBarRoot2 = forwardRef5((props, ref) => {
608
- const contextProps = useProps();
609
- const [variantProps, otherProps] = appBar.splitVariantProps({ ...contextProps, ...props });
610
- const classNames = appBar(variantProps);
611
- return /* @__PURE__ */ jsx5(ClassNamesProvider, { value: classNames, children: /* @__PURE__ */ jsx5(
612
- MainPropsProvider,
613
- {
614
- value: {
615
- theme: variantProps.theme,
616
- transitionStyle: variantProps.transitionStyle,
617
- tone: variantProps.tone
618
- },
619
- children: /* @__PURE__ */ jsx5(
620
- AppBar_namespace_exports.Root,
621
- {
622
- ref,
623
- ...mergeProps4({ className: classNames.root }, otherProps)
624
- }
625
- )
626
- }
627
- ) });
628
- });
629
- AppBarRoot2.displayName = "AppBarRoot";
630
- var AppBarLeft2 = withContext(
631
- AppBar_namespace_exports.Left,
632
- "left"
633
- );
634
- var AppBarRight2 = withContext(
635
- AppBar_namespace_exports.Right,
636
- "right"
637
- );
638
- var AppBarMain2 = withMainProvider(
639
- AppBar_namespace_exports.Main,
640
- "root"
641
- );
642
- var AppBarTitle = withMainContext(
643
- Primitive4.span,
644
- "title"
645
- );
646
- var AppBarSubtitle = withMainContext(
647
- Primitive4.span,
648
- "subtitle"
649
- );
650
- var AppBarIconButton = forwardRef5(
651
- ({ children, className, ...otherProps }, ref) => {
652
- const { stateProps } = useAppBarContext();
653
- const classNames = useClassNames();
654
- return /* @__PURE__ */ jsx5(
655
- Primitive4.button,
656
- {
657
- ref,
658
- type: "button",
659
- className: clsx2(classNames.iconButton, className),
660
- ...mergeProps4(stateProps, otherProps),
661
- children: /* @__PURE__ */ jsx5(Slot, { className: classNames.icon, ...stateProps, children })
662
- }
663
- );
664
- }
665
- );
666
- AppBarIconButton.displayName = "IconButton";
667
-
668
- // src/components/AppScreen/AppScreen.tsx
669
- import { mergeProps as mergeProps5 } from "@seed-design/dom-utils";
670
- import { jsx as jsx6 } from "react/jsx-runtime";
671
- var { ClassNamesProvider: ClassNamesProvider2, PropsProvider: PropsProvider2, withContext: withContext2, useProps: useProps2 } = createStyleContext(appScreen);
672
- var AppScreenPropsProvider = PropsProvider2;
673
- var AppScreenRoot2 = forwardRef6((props, ref) => {
674
- var _a;
675
- const contextProps = useProps2();
676
- const [variantProps, otherProps] = appScreen.splitVariantProps({ ...contextProps, ...props });
677
- const transitionStyle = (_a = variantProps.transitionStyle) != null ? _a : variantProps.theme === "cupertino" ? "slideFromRightIOS" : "fadeFromBottomAndroid";
678
- const classNames = appScreen({
679
- ...variantProps,
680
- transitionStyle
681
- });
682
- return /* @__PURE__ */ jsx6(ClassNamesProvider2, { value: classNames, children: /* @__PURE__ */ jsx6(
683
- AppBarPropsProvider,
684
- {
685
- value: useMemo5(
686
- () => ({ theme: variantProps.theme, transitionStyle }),
687
- [variantProps.theme, transitionStyle]
688
- ),
689
- children: /* @__PURE__ */ jsx6(
690
- AppScreen_namespace_exports.Root,
691
- {
692
- ref,
693
- ...mergeProps5({ className: classNames.root }, otherProps)
694
- }
695
- )
696
- }
697
- ) });
698
- });
699
- AppScreenRoot2.displayName = "AppScreenRoot";
700
- var AppScreenDim2 = withContext2(
701
- AppScreen_namespace_exports.Dim,
702
- "dim"
703
- );
704
- var AppScreenEdge2 = withContext2(
705
- AppScreen_namespace_exports.Edge,
706
- "edge"
707
- );
708
- var AppScreenLayer2 = withContext2(
709
- AppScreen_namespace_exports.Layer,
710
- "layer"
711
- );
712
-
713
- // src/plugin.tsx
714
- import { jsx as jsx7 } from "react/jsx-runtime";
715
- var seedPlugin = (options) => () => ({
716
- key: "seed-design",
717
- wrapStack({ stack }) {
718
- return /* @__PURE__ */ jsx7(AppScreenPropsProvider, { value: options, children: /* @__PURE__ */ jsx7(GlobalInteraction, { children: stack.render() }) });
719
- }
720
- });
721
-
722
- // src/components/AppBar/AppBar.namespace.ts
723
- var AppBar_namespace_exports2 = {};
724
- __export(AppBar_namespace_exports2, {
725
- IconButton: () => AppBarIconButton,
726
- Left: () => AppBarLeft2,
727
- Main: () => AppBarMain2,
728
- Right: () => AppBarRight2,
729
- Root: () => AppBarRoot2,
730
- Subtitle: () => AppBarSubtitle,
731
- Title: () => AppBarTitle
732
- });
733
-
734
- // src/components/AppScreen/AppScreen.namespace.ts
735
- var AppScreen_namespace_exports2 = {};
736
- __export(AppScreen_namespace_exports2, {
737
- Dim: () => AppScreenDim2,
738
- Edge: () => AppScreenEdge2,
739
- Layer: () => AppScreenLayer2,
740
- Root: () => AppScreenRoot2
741
- });
742
- export {
743
- AppBar_namespace_exports2 as AppBar,
744
- AppBarIconButton,
745
- AppBarLeft2 as AppBarLeft,
746
- AppBarMain2 as AppBarMain,
747
- AppBarRight2 as AppBarRight,
748
- AppBarRoot2 as AppBarRoot,
749
- AppBarSubtitle,
750
- AppBarTitle,
751
- AppScreen_namespace_exports2 as AppScreen,
752
- AppScreenDim2 as AppScreenDim,
753
- AppScreenEdge2 as AppScreenEdge,
754
- AppScreenLayer2 as AppScreenLayer,
755
- AppScreenRoot2 as AppScreenRoot,
756
- primitive_exports as Primitive,
757
- seedPlugin
758
- };
759
- //# sourceMappingURL=index.mjs.map