@orioncactuscorp/ui 1.15.1 → 1.17.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.
Files changed (105) hide show
  1. package/CHANGELOG.md +146 -0
  2. package/README.md +54 -15
  3. package/dist/components/Accordion/Accordion.css +1 -1
  4. package/dist/components/ActionArea/ActionArea.css +1 -1
  5. package/dist/components/ActionArea/ActionArea.js +56 -55
  6. package/dist/components/BackgroundIconButton/BackgroundIconButton.css +1 -1
  7. package/dist/components/BackgroundIconButton/BackgroundIconButton.js +9 -9
  8. package/dist/components/Badge/Badge.css +1 -1
  9. package/dist/components/Badge/Badge.js +44 -39
  10. package/dist/components/Badge/Badge.module.scss.js +9 -8
  11. package/dist/components/Button/Button.css +1 -1
  12. package/dist/components/Button/Button.js +5 -5
  13. package/dist/components/Cell/Cell.css +1 -1
  14. package/dist/components/CheckMark/CheckMark.css +1 -1
  15. package/dist/components/CheckMark/CheckMark.js +6 -6
  16. package/dist/components/Checkbox/Checkbox.css +1 -1
  17. package/dist/components/Checkbox/Checkbox.js +15 -15
  18. package/dist/components/Field/Field.css +1 -1
  19. package/dist/components/Fieldset/Fieldset.css +1 -1
  20. package/dist/components/IconButton/IconButton.css +1 -1
  21. package/dist/components/IconButton/IconButton.js +9 -9
  22. package/dist/components/Interaction/Interaction.css +1 -1
  23. package/dist/components/Interaction/Interaction.js +19 -12
  24. package/dist/components/Modal/Modal.css +1 -1
  25. package/dist/components/Modal/Modal.js +555 -579
  26. package/dist/components/Modal/blockSize.js +7 -0
  27. package/dist/components/Modal/bottomSheetRelease.js +114 -0
  28. package/dist/components/Modal/cssTime.js +11 -0
  29. package/dist/components/Modal/modalResizeTarget.js +28 -0
  30. package/dist/components/Modal/modalScrollArbitration.js +57 -66
  31. package/dist/components/Modal/useBottomSheetIntrinsicHeight.js +55 -0
  32. package/dist/components/Modal/useMeasuredElement.js +20 -0
  33. package/dist/components/Modal/useModalContentBlockTransition.js +128 -49
  34. package/dist/components/Modal/useModalContentSizeSignal.js +30 -0
  35. package/dist/components/Modal/useModalDrag.js +994 -1017
  36. package/dist/components/PositionSnap/PositionSnap.css +1 -1
  37. package/dist/components/ProgressIndicator/ProgressIndicator.css +1 -1
  38. package/dist/components/Radio/Radio.css +1 -1
  39. package/dist/components/Radio/Radio.js +9 -9
  40. package/dist/components/ScrollArea/ScrollArea.css +1 -1
  41. package/dist/components/ScrollArea/ScrollArea.js +262 -264
  42. package/dist/components/Skeleton/Skeleton.css +1 -1
  43. package/dist/components/Switch/Switch.css +1 -1
  44. package/dist/components/Switch/Switch.js +7 -7
  45. package/dist/components/Tabs/Tabs.css +1 -1
  46. package/dist/components/TextButton/TextButton.css +1 -1
  47. package/dist/components/TextButton/TextButton.js +17 -17
  48. package/dist/components/internal/ModalPresentation.js +1 -1
  49. package/dist/foundations/touch.css +1 -0
  50. package/dist/foundations.css +1 -0
  51. package/dist/styles.css +22 -21
  52. package/dist/ui/src/components/ActionArea/ActionArea.d.ts.map +1 -1
  53. package/dist/ui/src/components/Badge/Badge.d.ts.map +1 -1
  54. package/dist/ui/src/components/Badge/types.d.ts +1 -1
  55. package/dist/ui/src/components/Badge/types.d.ts.map +1 -1
  56. package/dist/ui/src/components/Interaction/Interaction.d.ts.map +1 -1
  57. package/dist/ui/src/components/Interaction/types.d.ts +2 -0
  58. package/dist/ui/src/components/Interaction/types.d.ts.map +1 -1
  59. package/dist/ui/src/components/Modal/Modal.d.ts +1 -1
  60. package/dist/ui/src/components/Modal/Modal.d.ts.map +1 -1
  61. package/dist/ui/src/components/Modal/blockSize.d.ts +2 -0
  62. package/dist/ui/src/components/Modal/blockSize.d.ts.map +1 -0
  63. package/dist/ui/src/components/Modal/bottomSheetRelease.d.ts +19 -0
  64. package/dist/ui/src/components/Modal/bottomSheetRelease.d.ts.map +1 -0
  65. package/dist/ui/src/components/Modal/contexts.d.ts +1 -0
  66. package/dist/ui/src/components/Modal/contexts.d.ts.map +1 -1
  67. package/dist/ui/src/components/Modal/cssTime.d.ts +4 -0
  68. package/dist/ui/src/components/Modal/cssTime.d.ts.map +1 -0
  69. package/dist/ui/src/components/Modal/modalResizeTarget.d.ts +12 -0
  70. package/dist/ui/src/components/Modal/modalResizeTarget.d.ts.map +1 -0
  71. package/dist/ui/src/components/Modal/modalScrollArbitration.d.ts.map +1 -1
  72. package/dist/ui/src/components/Modal/types.d.ts +6 -0
  73. package/dist/ui/src/components/Modal/types.d.ts.map +1 -1
  74. package/dist/ui/src/components/Modal/useBottomSheetIntrinsicHeight.d.ts +21 -0
  75. package/dist/ui/src/components/Modal/useBottomSheetIntrinsicHeight.d.ts.map +1 -0
  76. package/dist/ui/src/components/Modal/{useElementSize.d.ts → useMeasuredElement.d.ts} +1 -1
  77. package/dist/ui/src/components/Modal/useMeasuredElement.d.ts.map +1 -0
  78. package/dist/ui/src/components/Modal/useModalContentBlockTransition.d.ts +20 -1
  79. package/dist/ui/src/components/Modal/useModalContentBlockTransition.d.ts.map +1 -1
  80. package/dist/ui/src/components/Modal/useModalContentSizeSignal.d.ts +22 -0
  81. package/dist/ui/src/components/Modal/useModalContentSizeSignal.d.ts.map +1 -0
  82. package/dist/ui/src/components/Modal/useModalDrag.d.ts.map +1 -1
  83. package/dist/ui/src/components/ScrollArea/ScrollArea.d.ts +1 -1
  84. package/dist/ui/src/components/ScrollArea/ScrollArea.d.ts.map +1 -1
  85. package/dist/ui/src/components/ScrollArea/index.d.ts +1 -1
  86. package/dist/ui/src/components/ScrollArea/index.d.ts.map +1 -1
  87. package/dist/ui/src/components/ScrollArea/types.d.ts +2 -0
  88. package/dist/ui/src/components/ScrollArea/types.d.ts.map +1 -1
  89. package/dist/ui/src/index.d.ts +1 -1
  90. package/dist/ui/src/index.d.ts.map +1 -1
  91. package/dist/vscode/oc-ui-vars.css +1 -0
  92. package/docs/api-conventions.md +5 -0
  93. package/docs/responsive-foundation-profile.md +1 -0
  94. package/docs/scss-helpers.md +1 -3
  95. package/docs/selector-contract.md +63 -12
  96. package/docs/tokens.md +6 -0
  97. package/package.json +1 -1
  98. package/src/scss/foundations/touch.scss +3 -0
  99. package/src/scss/foundations/touch.test.ts +37 -0
  100. package/src/scss/foundations/typo.scss +1 -1
  101. package/src/scss/index.scss +1 -0
  102. package/src/scss/mixins/_fluid.test.ts +0 -16
  103. package/src/scss/mixins/_utils.scss +0 -6
  104. package/dist/components/Modal/useElementSize.js +0 -23
  105. package/dist/ui/src/components/Modal/useElementSize.d.ts.map +0 -1
@@ -0,0 +1,7 @@
1
+ function i(t) {
2
+ const e = Number.parseFloat(window.getComputedStyle(t).height);
3
+ return Number.isFinite(e) && e > 0 ? e : t.getBoundingClientRect().height;
4
+ }
5
+ export {
6
+ i as getBlockSize
7
+ };
@@ -0,0 +1,114 @@
1
+ const m = {
2
+ flickVelocityPxPerMs: 0.55,
3
+ // Project dismissal momentum independently from detent snapping. A closed
4
+ // sheet is a terminal release target, while visible detents retain their
5
+ // existing bounded sequential-snap behavior.
6
+ dismissalProjectionSeconds: 0.2,
7
+ minDismissDistancePx: 24,
8
+ snapProjection: {
9
+ lookaheadSeconds: 0.16,
10
+ maxDistancePx: 24
11
+ }
12
+ };
13
+ function P(o) {
14
+ return [...new Set(o)].sort((n, s) => n - s);
15
+ }
16
+ function g(o, n, s) {
17
+ return Math.min(Math.max(o, n), s);
18
+ }
19
+ function j(o, n) {
20
+ return o.reduce(
21
+ (s, e) => Math.abs(e - n) < Math.abs(s - n) ? e : s
22
+ );
23
+ }
24
+ function x(o, n, s) {
25
+ if (s === "down")
26
+ return o.find((t) => t > n + 1) ?? o[o.length - 1] ?? 0;
27
+ for (let t = o.length - 1; t >= 0; t -= 1) {
28
+ const i = o[t];
29
+ if (i !== void 0 && i < n - 1)
30
+ return i;
31
+ }
32
+ return o[0] ?? 0;
33
+ }
34
+ function M({
35
+ currentTranslate: o,
36
+ direction: n,
37
+ projectedTranslate: s,
38
+ startTranslate: e,
39
+ targets: t
40
+ }) {
41
+ const d = x(t, e, n), h = n === "down" ? Math.max(o, s) : Math.min(o, s);
42
+ if (n === "down") {
43
+ if (t.filter(
44
+ (r) => r > e + 1 && r <= o + 1
45
+ ).length === 0) return d;
46
+ const f = t.filter(
47
+ (r) => r > e + 1 && r <= h + 1
48
+ );
49
+ return f[f.length - 1] ?? d;
50
+ }
51
+ return t.filter(
52
+ (c) => c < e - 1 && c >= o - 1
53
+ ).length === 0 ? d : t.filter(
54
+ (c) => c < e - 1 && c >= h - 1
55
+ )[0] ?? d;
56
+ }
57
+ function p(o, n) {
58
+ return o + n * m.dismissalProjectionSeconds;
59
+ }
60
+ function D(o, n) {
61
+ const { lookaheadSeconds: s, maxDistancePx: e } = m.snapProjection;
62
+ return o + g(n * s, -e, e);
63
+ }
64
+ function S({
65
+ closeThreshold: o,
66
+ currentTranslate: n,
67
+ deltaY: s,
68
+ dismissible: e,
69
+ peekTranslate: t,
70
+ releaseVelocity: i,
71
+ restingTranslates: d,
72
+ sheetHeight: h,
73
+ startTranslate: u
74
+ }) {
75
+ const l = t > 0, c = P([
76
+ ...d.length ? d : [0],
77
+ ...l ? [t] : []
78
+ ]), f = p(
79
+ n,
80
+ i
81
+ ), r = t + Math.max(
82
+ m.minDismissDistancePx,
83
+ (h - t) * o
84
+ ), a = e && !l;
85
+ return a && s > 0 && n >= r ? {
86
+ reason: "distance-dismiss",
87
+ target: "closed",
88
+ translate: h
89
+ } : a && i > 0 && f >= r ? {
90
+ reason: "momentum-dismiss",
91
+ target: "closed",
92
+ translate: h
93
+ } : Math.abs(i) / 1e3 > m.flickVelocityPxPerMs && c.length > 1 ? {
94
+ reason: "flick",
95
+ target: "rest",
96
+ translate: M({
97
+ currentTranslate: n,
98
+ direction: i > 0 ? "down" : "up",
99
+ projectedTranslate: D(
100
+ n,
101
+ i
102
+ ),
103
+ startTranslate: u,
104
+ targets: c
105
+ })
106
+ } : {
107
+ reason: "nearest",
108
+ target: "rest",
109
+ translate: j(c, n)
110
+ };
111
+ }
112
+ export {
113
+ S as resolveBottomSheetRelease
114
+ };
@@ -0,0 +1,11 @@
1
+ function s(t) {
2
+ const e = t.trim();
3
+ return e.endsWith("ms") ? Number.parseFloat(e) || 0 : e.endsWith("s") ? (Number.parseFloat(e) || 0) * 1e3 : 0;
4
+ }
5
+ function i(t) {
6
+ return t.split(",").reduce((e, r) => Math.max(e, s(r)), 0);
7
+ }
8
+ export {
9
+ i as getMaxCssTimeMs,
10
+ s as parseCssTimeMs
11
+ };
@@ -0,0 +1,28 @@
1
+ const r = "--oc-modal-resize-target-scrollport-height", o = '[data-oc-modal-resizing="true"]';
2
+ function s(e, t) {
3
+ e.dataset.ocModalResizing = "true", t !== null && e.style.setProperty(
4
+ r,
5
+ `${t}px`
6
+ );
7
+ }
8
+ function i(e) {
9
+ delete e.dataset.ocModalResizing, e.style.removeProperty(r);
10
+ }
11
+ function l(e) {
12
+ return e.dataset.ocModalResizing === "true";
13
+ }
14
+ function n(e) {
15
+ const t = e.closest(o);
16
+ if (!t) return null;
17
+ const a = Number.parseFloat(
18
+ t.style.getPropertyValue(r)
19
+ );
20
+ return Number.isFinite(a) ? a : null;
21
+ }
22
+ export {
23
+ r as MODAL_RESIZE_TARGET_SCROLLPORT_HEIGHT_PROPERTY,
24
+ i as clearModalResizeTarget,
25
+ l as isModalResizeTargetPublished,
26
+ s as publishModalResizeTarget,
27
+ n as readModalResizeTarget
28
+ };
@@ -1,80 +1,71 @@
1
- const L = "ocModalTouchScrollLock", r = {
1
+ import { readModalResizeTarget as S } from "./modalResizeTarget.js";
2
+ const c = 1, p = "ocModalTouchScrollLock", L = /* @__PURE__ */ new Set(["auto", "overlay", "scroll"]), r = {
2
3
  allowDrag: !1,
3
4
  preventDefault: !1,
4
5
  resetAnchor: !1
5
- }, S = {
6
+ }, D = {
6
7
  allowDrag: !1,
7
8
  preventDefault: !1,
8
9
  resetAnchor: !0
9
- }, O = {
10
+ }, g = {
10
11
  allowDrag: !0,
11
12
  preventDefault: !1,
12
13
  resetAnchor: !1
13
- }, u = {
14
+ }, s = {
14
15
  allowDrag: !0,
15
16
  preventDefault: !0,
16
17
  resetAnchor: !1
17
18
  };
18
- function T(e) {
19
- return e ? u : O;
19
+ function d(e) {
20
+ return e ? s : g;
20
21
  }
21
- function c(e) {
22
- return !!(e && e.scrollHeight > e.clientHeight + 1);
22
+ function u(e) {
23
+ if (!e) return !1;
24
+ const n = e.ownerDocument.defaultView?.getComputedStyle(e).overflowY;
25
+ return !!(n && L.has(n) && e.scrollHeight > e.clientHeight + c);
23
26
  }
24
- function s(e) {
25
- return !c(e) || e.scrollTop <= 1;
26
- }
27
- function p(e) {
28
- return !c(e) || e.scrollHeight - e.clientHeight - e.scrollTop <= 1;
27
+ function f(e) {
28
+ return !u(e) || e.scrollTop <= c;
29
29
  }
30
- function R(e) {
31
- const t = e.closest(
32
- '[data-oc-modal-sheet-resizing="true"]'
33
- );
34
- if (!t) return null;
35
- const n = Number.parseFloat(
36
- t.style.getPropertyValue(
37
- "--oc-modal-resize-target-scrollport-height"
38
- )
39
- );
40
- return Number.isFinite(n) ? n : null;
30
+ function A(e) {
31
+ return !u(e) || e.scrollHeight - e.clientHeight - e.scrollTop <= c;
41
32
  }
42
- function h(e) {
33
+ function O(e) {
43
34
  if (!e)
44
35
  return { canScroll: !1, scrolledFromTop: !1, scrolledToBottom: !0 };
45
- const t = R(e);
36
+ const t = S(e);
46
37
  if (t === null)
47
38
  return {
48
- canScroll: c(e),
49
- scrolledFromTop: !s(e),
50
- scrolledToBottom: p(e)
39
+ canScroll: u(e),
40
+ scrolledFromTop: !f(e),
41
+ scrolledToBottom: A(e)
51
42
  };
52
- const n = e.firstElementChild?.getBoundingClientRect().height ?? e.scrollHeight, o = n > t + 1;
43
+ const n = e.firstElementChild?.getBoundingClientRect().height ?? e.scrollHeight, o = n > t + c;
53
44
  return {
54
45
  canScroll: o,
55
- scrolledFromTop: o && e.scrollTop > 1,
56
- scrolledToBottom: !o || n - t - e.scrollTop <= 1
46
+ scrolledFromTop: o && e.scrollTop > c,
47
+ scrolledToBottom: !o || n - t - e.scrollTop <= c
57
48
  };
58
49
  }
59
- function m(e, t) {
50
+ function h(e, t) {
60
51
  let n = e;
61
52
  for (; n && n !== t; ) {
62
- if (n instanceof HTMLElement && c(n))
53
+ if (n instanceof HTMLElement && u(n))
63
54
  return n;
64
55
  n = n.parentElement;
65
56
  }
66
57
  return t;
67
58
  }
68
- function g(e, t) {
59
+ function w(e, t) {
69
60
  if (e) {
70
61
  if (t) {
71
- e.dataset[L] = "true";
62
+ e.dataset[p] = "true";
72
63
  return;
73
64
  }
74
- delete e.dataset[L];
65
+ delete e.dataset[p];
75
66
  }
76
67
  }
77
- function f(e) {
68
+ function a(e) {
78
69
  return typeof Element > "u" || !(e instanceof Element) ? !0 : !!e.closest(
79
70
  [
80
71
  "[data-oc-modal-no-drag]",
@@ -95,64 +86,64 @@ function f(e) {
95
86
  ].join(",")
96
87
  );
97
88
  }
98
- function _(e, t) {
89
+ function E(e, t) {
99
90
  return t ? t.ownerDocument : typeof Node < "u" && e instanceof Node ? e.ownerDocument : typeof document > "u" ? null : document;
100
91
  }
101
- function a({
92
+ function m({
102
93
  boundary: e,
103
94
  target: t
104
95
  }) {
105
- const n = _(t, e ?? null), o = n?.getSelection?.() ?? n?.defaultView?.getSelection?.();
96
+ const n = E(t, e ?? null), o = n?.getSelection?.() ?? n?.defaultView?.getSelection?.();
106
97
  if (!o || o.rangeCount === 0 || o.isCollapsed)
107
98
  return !1;
108
99
  const i = e ?? (typeof Node < "u" && t instanceof Node ? t : null);
109
100
  if (!i) return !0;
110
101
  for (let l = 0; l < o.rangeCount; l += 1) {
111
- const D = o.getRangeAt(l).commonAncestorContainer;
112
- if (i.contains(D) || D.contains(i))
102
+ const T = o.getRangeAt(l).commonAncestorContainer;
103
+ if (i.contains(T) || T.contains(i))
113
104
  return !0;
114
105
  }
115
106
  return !1;
116
107
  }
117
- function H({
108
+ function C({
118
109
  target: e,
119
110
  chrome: t,
120
111
  bodyNode: n
121
112
  }) {
122
- if (t || typeof Element > "u" || !(e instanceof Element) || f(e) || a({ target: e, boundary: n })) return !1;
123
- const o = m(e, n);
124
- return c(o) && s(o);
113
+ if (t || typeof Element > "u" || !(e instanceof Element) || a(e) || m({ target: e, boundary: n })) return !1;
114
+ const o = h(e, n);
115
+ return u(o) && f(o);
125
116
  }
126
- function d({
117
+ function R({
127
118
  target: e,
128
119
  deltaY: t,
129
120
  chrome: n,
130
121
  bodyNode: o,
131
122
  canExpand: i
132
123
  }) {
133
- if (typeof Element > "u" || !(e instanceof Element) || f(e)) return r;
134
- if (n) return T(t !== 0);
135
- if (a({ target: e, boundary: o }))
124
+ if (typeof Element > "u" || !(e instanceof Element) || a(e)) return r;
125
+ if (n) return d(t !== 0);
126
+ if (m({ target: e, boundary: o }))
136
127
  return r;
137
- const l = m(e, o);
138
- return c(l) ? t > 0 ? s(l) ? u : S : t < 0 ? i ? u : S : r : T(t !== 0);
128
+ const l = h(e, o);
129
+ return u(l) ? t > 0 ? f(l) ? s : D : t < 0 ? i ? s : D : r : d(t !== 0);
139
130
  }
140
- function A({
131
+ function H({
141
132
  target: e,
142
133
  bodyNode: t
143
134
  }) {
144
- return typeof Element > "u" || !(e instanceof Element) || f(e) || a({ target: e, boundary: t }) ? r : u;
135
+ return typeof Element > "u" || !(e instanceof Element) || a(e) || m({ target: e, boundary: t }) ? r : s;
145
136
  }
146
137
  export {
147
- d as getBottomTouchDragDecision,
148
- h as getModalScrollState,
149
- A as getPopupTouchDragDecision,
150
- m as getScrollableAncestor,
151
- a as hasActiveTextSelection,
152
- p as isAtScrollBottom,
153
- s as isAtScrollTop,
154
- c as isScrollableElement,
155
- g as setModalBodyTouchScrollLock,
156
- f as shouldIgnoreDragTarget,
157
- H as shouldLockModalBodyTouchScroll
138
+ R as getBottomTouchDragDecision,
139
+ O as getModalScrollState,
140
+ H as getPopupTouchDragDecision,
141
+ h as getScrollableAncestor,
142
+ m as hasActiveTextSelection,
143
+ A as isAtScrollBottom,
144
+ f as isAtScrollTop,
145
+ u as isScrollableElement,
146
+ w as setModalBodyTouchScrollLock,
147
+ a as shouldIgnoreDragTarget,
148
+ C as shouldLockModalBodyTouchScroll
158
149
  };
@@ -0,0 +1,55 @@
1
+ import { useState as p, useRef as S, useCallback as h, useLayoutEffect as C } from "react";
2
+ import { resolveContentSizedBottomSheetHeight as H } from "./bottomSheetGeometry.js";
3
+ import { useModalContentSizeSignal as x } from "./useModalContentSizeSignal.js";
4
+ function v(t) {
5
+ const e = t.trim();
6
+ if (!e.endsWith("px")) return;
7
+ const n = Number.parseFloat(e);
8
+ return Number.isFinite(n) && n > 0 ? n : void 0;
9
+ }
10
+ function w(t) {
11
+ if (!(!t || typeof window > "u"))
12
+ return v(window.getComputedStyle(t).maxHeight);
13
+ }
14
+ function V({
15
+ enabled: t,
16
+ bodyNode: e,
17
+ surfaceMotionNode: n,
18
+ snapSheetHeight: u,
19
+ viewportHeight: f,
20
+ discreteKey: g
21
+ }) {
22
+ const [o, m] = p(0), r = S(!1), i = h(() => {
23
+ const s = e?.firstElementChild;
24
+ if (!t || !s) {
25
+ r.current = !1;
26
+ return;
27
+ }
28
+ const d = s.getBoundingClientRect().height, c = H({
29
+ contentHeight: d,
30
+ maxHeight: w(n),
31
+ snapHeight: u
32
+ }), a = Math.abs(o - c) > 0.5;
33
+ r.current = a, a && m(c);
34
+ }, [
35
+ e,
36
+ t,
37
+ o,
38
+ u,
39
+ n
40
+ ]);
41
+ C(() => {
42
+ i();
43
+ }, [i, f]), x({
44
+ enabled: t,
45
+ bodyNode: e,
46
+ discreteKey: g,
47
+ onDiscreteChange: i,
48
+ onObservedChange: i
49
+ });
50
+ const l = h(() => r.current, []);
51
+ return { intrinsicSheetHeight: o, shouldDeferSettle: l };
52
+ }
53
+ export {
54
+ V as useBottomSheetIntrinsicHeight
55
+ };
@@ -0,0 +1,20 @@
1
+ import { useState as o, useCallback as a, useLayoutEffect as c } from "react";
2
+ import { getBlockSize as m } from "./blockSize.js";
3
+ function l() {
4
+ const [e, i] = o(null), [s, u] = o(0), r = a((n) => {
5
+ u(n ? m(n) : 0);
6
+ }, []);
7
+ return c(() => {
8
+ if (!e) return;
9
+ const n = window.requestAnimationFrame(() => r(e));
10
+ if (typeof ResizeObserver > "u")
11
+ return () => window.cancelAnimationFrame(n);
12
+ const t = new ResizeObserver(() => r(e));
13
+ return t.observe(e), () => {
14
+ window.cancelAnimationFrame(n), t.disconnect();
15
+ };
16
+ }, [r, e]), { node: e, setNode: i, height: e ? s : 0 };
17
+ }
18
+ export {
19
+ l as useMeasuredElement
20
+ };
@@ -1,63 +1,142 @@
1
- import { useRef as r, useCallback as T, useLayoutEffect as E, useEffect as S } from "react";
2
- const _ = 600, O = 4, B = 1;
3
- function g(e) {
4
- const n = Number.parseFloat(window.getComputedStyle(e).height);
5
- return Number.isFinite(n) && n > 0 ? n : e.getBoundingClientRect().height;
1
+ import { useRef as r, useLayoutEffect as b, useCallback as i, useEffect as k } from "react";
2
+ import { getBlockSize as f } from "./blockSize.js";
3
+ import { getMaxCssTimeMs as I } from "./cssTime.js";
4
+ import { publishModalResizeTarget as F, clearModalResizeTarget as G } from "./modalResizeTarget.js";
5
+ import { useModalContentSizeSignal as H } from "./useModalContentSizeSignal.js";
6
+ const X = 600, U = 250, x = 4, q = 1, V = 0.5;
7
+ function j(s) {
8
+ const c = window.getComputedStyle(s), p = c.transitionDuration;
9
+ return p ? I(p) + I(c.transitionDelay) : null;
6
10
  }
7
- function w({
8
- enabled: e,
9
- node: n
11
+ function nn({
12
+ enabled: s,
13
+ node: c,
14
+ resizeHost: p = null,
15
+ bodyNode: P = null,
16
+ discreteKey: K,
17
+ refreshScrollState: M
10
18
  }) {
11
- const a = r(null), c = r(null), l = r(null), h = r(null), f = r(!1), i = r(0), v = r(0), m = r(!1), d = T(() => {
12
- h.current?.(), h.current = null;
13
- }, []), u = T(() => {
14
- c.current !== null && (window.cancelAnimationFrame(c.current), c.current = null), l.current !== null && (window.clearTimeout(l.current), l.current = null), d();
15
- }, [d]), C = T(() => {
16
- const t = a.current;
17
- t && (u(), t.style.removeProperty("height"), t.dataset.ocContentTransitionState = "idle", f.current = !1, i.current = g(t));
18
- }, [u]), p = T(() => {
19
- const t = a.current;
20
- !t || !e || f.current || c.current === null && (c.current = window.requestAnimationFrame(() => {
21
- c.current = null;
22
- const s = i.current, o = g(t);
23
- if (!m.current) {
24
- m.current = !0, i.current = o;
19
+ const l = r(null), g = r(null), w = r(null), h = r(M), E = r(s), a = r(null), T = r(null), B = r(null), d = r(!1), o = r(0), z = r(0), C = r(!1);
20
+ b(() => {
21
+ g.current = p, w.current = P, h.current = M, E.current = s;
22
+ });
23
+ const y = i(() => {
24
+ B.current?.(), B.current = null;
25
+ }, []), u = i(() => {
26
+ a.current !== null && (window.cancelAnimationFrame(a.current), a.current = null), T.current !== null && (window.clearTimeout(T.current), T.current = null), y();
27
+ }, [y]), R = i((n) => {
28
+ const e = w.current;
29
+ F(
30
+ g.current ?? n,
31
+ e ? e.clientHeight : null
32
+ );
33
+ }, []), N = i((n) => {
34
+ G(g.current ?? n);
35
+ }, []), m = i(() => {
36
+ const n = l.current;
37
+ n && (u(), n.style.removeProperty("height"), N(n), n.dataset.ocContentTransitionState = "idle", d.current = !1, o.current = f(n), h.current?.());
38
+ }, [u, N]), S = i(
39
+ (n) => {
40
+ const e = j(n);
41
+ if (e === 0) {
42
+ m();
25
43
  return;
26
44
  }
27
- if (Math.abs(o - v.current) > B) {
28
- i.current = o;
45
+ const t = (O) => {
46
+ O.target !== n || O.propertyName !== "height" || (n.removeEventListener("transitionend", t), m());
47
+ };
48
+ y(), n.addEventListener("transitionend", t), B.current = () => {
49
+ n.removeEventListener("transitionend", t);
50
+ }, T.current !== null && window.clearTimeout(T.current), T.current = window.setTimeout(
51
+ () => {
52
+ m();
53
+ },
54
+ (e ?? X) + U
55
+ );
56
+ },
57
+ [m, y]
58
+ ), v = i(
59
+ (n, e, t) => {
60
+ R(n), d.current = !0, n.dataset.ocContentTransitionState = "changing", n.style.height = `${e}px`, n.getBoundingClientRect(), n.style.height = `${t}px`, o.current = t, S(n);
61
+ },
62
+ [S, R]
63
+ ), _ = i(
64
+ (n) => {
65
+ const e = f(n), t = n.style.getPropertyValue("transition"), O = n.style.getPropertyPriority("transition");
66
+ n.style.setProperty("transition", "none", "important"), n.style.removeProperty("height");
67
+ const L = f(n);
68
+ if (R(n), n.style.height = `${e}px`, n.getBoundingClientRect(), t ? n.style.setProperty(
69
+ "transition",
70
+ t,
71
+ O
72
+ ) : n.style.removeProperty("transition"), o.current = L, Math.abs(L - e) <= V) {
73
+ m();
29
74
  return;
30
75
  }
31
- if (s <= 0 || Math.abs(o - s) <= O) {
32
- i.current = o;
76
+ n.style.height = `${L}px`, S(n), h.current?.();
77
+ },
78
+ [S, m, R]
79
+ ), A = i(() => {
80
+ const n = l.current;
81
+ !n || !E.current || d.current || a.current === null && (a.current = window.requestAnimationFrame(() => {
82
+ a.current = null;
83
+ const e = o.current, t = f(n);
84
+ if (!C.current) {
85
+ C.current = !0, o.current = t;
33
86
  return;
34
87
  }
35
- f.current = !0, t.dataset.ocContentTransitionState = "changing", t.style.height = `${s}px`, t.getBoundingClientRect(), t.style.height = `${o}px`, i.current = o;
36
- const N = (R) => {
37
- R.target !== t || R.propertyName !== "height" || (t.removeEventListener("transitionend", N), C());
38
- };
39
- d(), t.addEventListener("transitionend", N), h.current = () => {
40
- t.removeEventListener("transitionend", N);
41
- }, l.current = window.setTimeout(() => {
42
- C();
43
- }, _);
88
+ if (Math.abs(t - z.current) > q) {
89
+ o.current = t;
90
+ return;
91
+ }
92
+ if (e <= 0 || Math.abs(t - e) <= x) {
93
+ o.current = t;
94
+ return;
95
+ }
96
+ v(n, e, t);
44
97
  }));
45
- }, [e, C, d]);
46
- E(() => {
47
- a.current = n;
48
- const t = a.current;
49
- t && (i.current = g(t), m.current = !1, e || (u(), t.style.removeProperty("height"), t.dataset.ocContentTransitionState = "idle", f.current = !1));
50
- }, [u, e, n]), S(() => {
51
- if (!n || !e || typeof ResizeObserver > "u")
98
+ }, [v]);
99
+ b(() => {
100
+ l.current = c;
101
+ const n = l.current;
102
+ n && (o.current = f(n), C.current = !1, s || (u(), n.style.removeProperty("height"), N(n), n.dataset.ocContentTransitionState = "idle", d.current = !1));
103
+ }, [u, N, s, c]);
104
+ const D = i(() => {
105
+ const n = l.current;
106
+ if (!n || !E.current) return;
107
+ if (d.current) {
108
+ _(n);
109
+ return;
110
+ }
111
+ const e = a.current !== null ? z.current : o.current;
112
+ u(), C.current = !0;
113
+ const t = f(n);
114
+ if (e <= 0 || Math.abs(t - e) <= x) {
115
+ o.current = t;
116
+ return;
117
+ }
118
+ v(n, e, t), h.current?.();
119
+ }, [u, _, v]), $ = i(() => {
120
+ const n = l.current;
121
+ !n || !d.current || _(n);
122
+ }, [_]);
123
+ H({
124
+ enabled: s,
125
+ bodyNode: P,
126
+ discreteKey: K,
127
+ onDiscreteChange: D,
128
+ onObservedChange: $
129
+ }), k(() => {
130
+ if (!c || !s || typeof ResizeObserver > "u")
52
131
  return;
53
- const t = new ResizeObserver(() => {
54
- const s = a.current;
55
- s && (v.current = g(s)), p();
132
+ const n = new ResizeObserver(() => {
133
+ const e = l.current;
134
+ e && (z.current = f(e)), A();
56
135
  });
57
- return t.observe(n), () => {
58
- t.disconnect();
136
+ return n.observe(c), () => {
137
+ n.disconnect();
59
138
  };
60
- }, [e, n, p]), S(
139
+ }, [s, c, A]), k(
61
140
  () => () => {
62
141
  u();
63
142
  },
@@ -65,5 +144,5 @@ function w({
65
144
  );
66
145
  }
67
146
  export {
68
- w as useModalContentBlockTransition
147
+ nn as useModalContentBlockTransition
69
148
  };
@@ -0,0 +1,30 @@
1
+ import { useRef as n, useLayoutEffect as b, useEffect as v } from "react";
2
+ function a({
3
+ enabled: e,
4
+ bodyNode: o,
5
+ discreteKey: t,
6
+ onDiscreteChange: u,
7
+ onObservedChange: c
8
+ }) {
9
+ const f = n(t), s = n(u), i = n(c);
10
+ b(() => {
11
+ s.current = u, i.current = c;
12
+ }), b(() => {
13
+ Object.is(f.current, t) || (f.current = t, e && s.current?.());
14
+ }, [t, e]), v(() => {
15
+ const r = o?.firstElementChild;
16
+ if (!r || !e || typeof ResizeObserver > "u" || // A fill-layout content box tracks the scrollport and would report the
17
+ // surface's own motion back as a content change.
18
+ r.getAttribute("data-oc-layout") === "fill")
19
+ return;
20
+ const R = new ResizeObserver(() => {
21
+ i.current?.();
22
+ });
23
+ return R.observe(r, { box: "border-box" }), () => {
24
+ R.disconnect();
25
+ };
26
+ }, [o, e]);
27
+ }
28
+ export {
29
+ a as useModalContentSizeSignal
30
+ };