@shellui/core 0.7.0-alpha.9 → 0.7.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/README.md +1 -1
- package/package.json +24 -7
- package/src/components/ui/drawer.tsx +47 -30
- package/src/components/ui/sheet.tsx +18 -12
- package/src/components/ui/shell-divider.spec.tsx +63 -0
- package/src/components/ui/shell-divider.tsx +20 -0
- package/src/components/ui/sidebar.tsx +26 -12
- package/src/components/ui/tooltip.tsx +4 -2
- package/src/features/admin/AdminView.tsx +9 -6
- package/src/features/auth/components/LoginButton.spec.tsx +203 -0
- package/src/features/auth/components/LoginButton.tsx +77 -28
- package/src/features/auth/components/LoginButtonIcons.tsx +4 -8
- package/src/features/chromeActions/ChromeActionsHost.tsx +5 -1
- package/src/features/chromeActions/computeActionInsets.ts +7 -4
- package/src/features/layouts/OverlayShell.tsx +58 -40
- package/src/features/layouts/appbar/AppBarItemIcon.spec.tsx +45 -0
- package/src/features/layouts/appbar/AppBarItemIcon.tsx +19 -0
- package/src/features/layouts/appbar/AppBarLayout.tsx +115 -110
- package/src/features/layouts/appbar/appBarOverflow.spec.ts +27 -0
- package/src/features/layouts/appbar/appBarOverflow.ts +42 -0
- package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +13 -24
- package/src/features/layouts/chrome/ContentDragOverlay.tsx +5 -6
- package/src/features/layouts/chrome/DesktopChrome.tsx +37 -0
- package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +15 -4
- package/src/features/layouts/chrome/MacStrip.tsx +33 -0
- package/src/features/layouts/chrome/constants.ts +36 -8
- package/src/features/layouts/chrome/index.ts +8 -0
- package/src/features/layouts/chrome/stripDragMap.ts +35 -0
- package/src/features/layouts/chrome/stripNoDrag.spec.tsx +103 -0
- package/src/features/layouts/chrome/useScrollHideChrome.ts +3 -8
- package/src/features/layouts/chrome/viewport.ts +11 -4
- package/src/features/layouts/floating/FloatingBottomDock.tsx +263 -43
- package/src/features/layouts/floating/FloatingLayout.tsx +14 -8
- package/src/features/layouts/floating/FloatingSidebar.tsx +178 -81
- package/src/features/layouts/floating/computeFloatingInsets.ts +22 -4
- package/src/features/layouts/floating/moreSections.spec.ts +28 -0
- package/src/features/layouts/floating/moreSections.ts +31 -0
- package/src/features/layouts/floating/useFloatingChrome.ts +3 -1
- package/src/features/layouts/floating/useSoftKeyboard.spec.ts +39 -0
- package/src/features/layouts/floating/useSoftKeyboard.ts +82 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.spec.tsx +68 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.tsx +47 -10
- package/src/features/layouts/sidebar/NavigationContent.tsx +17 -9
- package/src/features/layouts/sidebar/SidebarIcons.tsx +70 -9
- package/src/features/layouts/sidebar/SidebarInner.spec.tsx +149 -0
- package/src/features/layouts/sidebar/SidebarInner.tsx +103 -43
- package/src/features/layouts/sidebar/SidebarLayout.tsx +24 -17
- package/src/features/layouts/windows/DesktopDots.tsx +76 -0
- package/src/features/layouts/windows/WindowsLayout.tsx +265 -160
- package/src/features/layouts/windows/deskDots.spec.ts +54 -0
- package/src/features/layouts/windows/deskDots.ts +314 -0
- package/src/features/overlays/ResponsiveModal.tsx +5 -3
- package/src/features/overlays/overlaySize.spec.ts +56 -16
- package/src/features/overlays/overlaySize.ts +114 -31
- package/src/features/overlays/phoneDrawerAnchoring.spec.ts +187 -0
- package/src/features/overlays/useOverlayReportedSize.ts +8 -3
- package/src/features/theme/applyTheme.ts +8 -0
- package/src/features/theme/navContrast.spec.ts +49 -0
- package/src/features/theme/navContrast.ts +108 -0
- package/src/i18n/translations/en/common.json +26 -0
- package/src/i18n/translations/fr/common.json +26 -0
- package/src/index.css +1156 -77
- package/src/service-worker/devCaches.spec.ts +32 -0
- package/src/service-worker/devCaches.ts +27 -0
- package/src/service-worker/sw-dev.ts +23 -23
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { DESK_DOTS, bucketAlpha, gridSize, isAccentDot } from './deskDots';
|
|
4
|
+
import { isDesktopCovered } from './DesktopDots';
|
|
5
|
+
|
|
6
|
+
describe('DESK_DOTS', () => {
|
|
7
|
+
it('runs at the website normal speed, capped at 30 fps', () => {
|
|
8
|
+
expect(DESK_DOTS.fps).toBe(30);
|
|
9
|
+
expect(DESK_DOTS.dprMax).toBe(2);
|
|
10
|
+
expect(DESK_DOTS.gustPx).toBe(7);
|
|
11
|
+
expect(DESK_DOTS.frontWidth).toBe(70);
|
|
12
|
+
expect(DESK_DOTS.crossMs).toEqual([6700, 10000]);
|
|
13
|
+
expect(DESK_DOTS.everyMs).toEqual([1000, 3000]);
|
|
14
|
+
expect([DESK_DOTS.spring, DESK_DOTS.damp]).toEqual([0.06, 0.82]);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('bucketAlpha', () => {
|
|
19
|
+
it('starts near the base alpha and rises with the gust', () => {
|
|
20
|
+
expect(bucketAlpha(false, 0, false)).toBeCloseTo(0.15 + 0.16 / 12, 5);
|
|
21
|
+
expect(bucketAlpha(false, 0, true)).toBeCloseTo(0.11 + 0.16 / 12, 5);
|
|
22
|
+
expect(bucketAlpha(false, 5, false)).toBeGreaterThan(bucketAlpha(false, 0, false));
|
|
23
|
+
expect(bucketAlpha(true, 0, false)).toBeGreaterThan(bucketAlpha(false, 0, false));
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('gridSize', () => {
|
|
28
|
+
it('covers the host with a 24 px grid', () => {
|
|
29
|
+
expect(gridSize(1440, 900)).toEqual({ cols: 60, rows: 38, count: 2280 });
|
|
30
|
+
expect(gridSize(0, 900).count).toBe(0);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('isAccentDot', () => {
|
|
35
|
+
it('tints about one dot in eleven', () => {
|
|
36
|
+
let accents = 0;
|
|
37
|
+
for (let r = 0; r < 22; r++) for (let c = 0; c < 22; c++) if (isAccentDot(c, r)) accents++;
|
|
38
|
+
expect(accents / (22 * 22)).toBeCloseTo(1 / 11, 1);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('isDesktopCovered', () => {
|
|
43
|
+
it('pauses for a focused maximized window or a drag, not for a background maximized one', () => {
|
|
44
|
+
const root = document.createElement('div');
|
|
45
|
+
root.innerHTML =
|
|
46
|
+
'<div data-shellui-window data-focused="false" data-maximized="true"></div><div data-shellui-window data-focused="true" data-maximized="false"></div>';
|
|
47
|
+
expect(isDesktopCovered(root)).toBe(false);
|
|
48
|
+
root.lastElementChild?.setAttribute('data-interacting', 'true');
|
|
49
|
+
expect(isDesktopCovered(root)).toBe(true);
|
|
50
|
+
root.lastElementChild?.removeAttribute('data-interacting');
|
|
51
|
+
root.firstElementChild?.setAttribute('data-focused', 'true');
|
|
52
|
+
expect(isDesktopCovered(root)).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows layout desktop: dot field on a canvas.
|
|
3
|
+
* Ported from the layouts redesign reference (`desk-dots.js`), itself derived from
|
|
4
|
+
* the shellui.com hero dots at the website's normal speed and travel, no pointer play.
|
|
5
|
+
* Decorative only. The caller mounts it on an `aria-hidden` host.
|
|
6
|
+
*/
|
|
7
|
+
export const DESK_DOTS = {
|
|
8
|
+
/** Grid spacing in px (same as the website). */
|
|
9
|
+
spacing: 24,
|
|
10
|
+
/** Dot radius in px. */
|
|
11
|
+
radius: 1.1,
|
|
12
|
+
/** Base alpha of `--foreground` in light mode. */
|
|
13
|
+
alphaLight: 0.15,
|
|
14
|
+
/** Base alpha of `--foreground` in dark mode. */
|
|
15
|
+
alphaDark: 0.11,
|
|
16
|
+
/** One dot in this many is tinted with `--primary`. */
|
|
17
|
+
accentEvery: 11,
|
|
18
|
+
/** Accent base alpha; rises with the gust. */
|
|
19
|
+
accentAlpha: 0.22,
|
|
20
|
+
/** Extra alpha at full displacement. */
|
|
21
|
+
gustLift: 0.16,
|
|
22
|
+
/** Max displacement in px. */
|
|
23
|
+
gustPx: 7,
|
|
24
|
+
/** Width of a wind front in px. */
|
|
25
|
+
frontWidth: 70,
|
|
26
|
+
/** Front slant in degrees. */
|
|
27
|
+
slantDeg: 18,
|
|
28
|
+
/** Time for one front to cross the desktop, ms range. */
|
|
29
|
+
crossMs: [6700, 10000] as const,
|
|
30
|
+
/** Gap between fronts, ms range. */
|
|
31
|
+
everyMs: [1000, 3000] as const,
|
|
32
|
+
spring: 0.06,
|
|
33
|
+
damp: 0.82,
|
|
34
|
+
/** Frame cap. */
|
|
35
|
+
fps: 30,
|
|
36
|
+
/** Device pixel ratio cap. */
|
|
37
|
+
dprMax: 2,
|
|
38
|
+
} as const;
|
|
39
|
+
|
|
40
|
+
export type DeskDotsOptions = Partial<{
|
|
41
|
+
[K in keyof typeof DESK_DOTS]: (typeof DESK_DOTS)[K] extends readonly [number, number]
|
|
42
|
+
? readonly [number, number]
|
|
43
|
+
: number;
|
|
44
|
+
}>;
|
|
45
|
+
|
|
46
|
+
export interface DeskDotsHandle {
|
|
47
|
+
/** True while the desktop is covered (maximized window) or a window is dragged or resized. */
|
|
48
|
+
pause: (paused: boolean) => void;
|
|
49
|
+
/** Draw count and total draw time, for profiling. */
|
|
50
|
+
stats: { frames: number; ms: number };
|
|
51
|
+
destroy: () => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type Rgb = [number, number, number];
|
|
55
|
+
|
|
56
|
+
const BUCKETS = 6;
|
|
57
|
+
|
|
58
|
+
/** Alpha for a bucket: base dots and accent dots rise with the gust. */
|
|
59
|
+
export function bucketAlpha(
|
|
60
|
+
accent: boolean,
|
|
61
|
+
bucket: number,
|
|
62
|
+
dark: boolean,
|
|
63
|
+
p: { alphaLight: number; alphaDark: number; accentAlpha: number; gustLift: number } = DESK_DOTS,
|
|
64
|
+
): number {
|
|
65
|
+
const m = (bucket + 0.5) / BUCKETS;
|
|
66
|
+
if (accent) return p.accentAlpha + p.gustLift * 1.6 * m;
|
|
67
|
+
return (dark ? p.alphaDark : p.alphaLight) + p.gustLift * m;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Grid size for a host box: columns and rows of dots. */
|
|
71
|
+
export function gridSize(width: number, height: number, spacing: number = DESK_DOTS.spacing) {
|
|
72
|
+
const cols = Math.max(0, Math.ceil(width / spacing));
|
|
73
|
+
const rows = Math.max(0, Math.ceil(height / spacing));
|
|
74
|
+
return { cols, rows, count: cols * rows };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Same 1 in N pattern as the reference: stable across relayouts. */
|
|
78
|
+
export function isAccentDot(col: number, row: number, every: number = DESK_DOTS.accentEvery) {
|
|
79
|
+
return (col * 7 + row * 3) % every === 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function mountDeskDots(host: HTMLElement, opts: DeskDotsOptions = {}): DeskDotsHandle {
|
|
83
|
+
const P = { ...DESK_DOTS, ...opts };
|
|
84
|
+
const stats = { frames: 0, ms: 0 };
|
|
85
|
+
const canvas = document.createElement('canvas');
|
|
86
|
+
canvas.setAttribute('aria-hidden', 'true');
|
|
87
|
+
canvas.style.position = 'absolute';
|
|
88
|
+
canvas.style.inset = '0';
|
|
89
|
+
canvas.style.width = '100%';
|
|
90
|
+
canvas.style.height = '100%';
|
|
91
|
+
canvas.style.pointerEvents = 'none';
|
|
92
|
+
const ctx = canvas.getContext('2d', { alpha: true });
|
|
93
|
+
if (!ctx) {
|
|
94
|
+
return { pause: () => {}, stats, destroy: () => {} };
|
|
95
|
+
}
|
|
96
|
+
host.appendChild(canvas);
|
|
97
|
+
host.setAttribute('data-live', 'true');
|
|
98
|
+
|
|
99
|
+
const slant = Math.tan((P.slantDeg * Math.PI) / 180);
|
|
100
|
+
const smooth = (t: number) => t * t * (3 - 2 * t);
|
|
101
|
+
const rnd = (a: number, b: number) => a + Math.random() * (b - a);
|
|
102
|
+
|
|
103
|
+
let w = 0;
|
|
104
|
+
let h = 0;
|
|
105
|
+
let n = 0;
|
|
106
|
+
let X = new Float32Array(0);
|
|
107
|
+
let Y = new Float32Array(0);
|
|
108
|
+
let OX = new Float32Array(0);
|
|
109
|
+
let OY = new Float32Array(0);
|
|
110
|
+
let VX = new Float32Array(0);
|
|
111
|
+
let VY = new Float32Array(0);
|
|
112
|
+
let S = new Float32Array(0);
|
|
113
|
+
let PH = new Float32Array(0);
|
|
114
|
+
let AC = new Uint8Array(0);
|
|
115
|
+
let fronts: { t: number; v: number; x: number }[] = [];
|
|
116
|
+
let nextAt = 0;
|
|
117
|
+
let raf = 0;
|
|
118
|
+
let last = 0;
|
|
119
|
+
let paused = false;
|
|
120
|
+
let settled = false;
|
|
121
|
+
let destroyed = false;
|
|
122
|
+
let idleTimer: ReturnType<typeof setTimeout> | undefined;
|
|
123
|
+
let layoutTimer: ReturnType<typeof setTimeout> | undefined;
|
|
124
|
+
let fg: Rgb = [17, 24, 39];
|
|
125
|
+
let pr: Rgb = [227, 165, 18];
|
|
126
|
+
let dark = false;
|
|
127
|
+
|
|
128
|
+
// Theme colours: resolve any CSS colour (oklch included) through a 1 x 1 canvas.
|
|
129
|
+
const probe = document.createElement('canvas');
|
|
130
|
+
probe.width = 1;
|
|
131
|
+
probe.height = 1;
|
|
132
|
+
const pctx = probe.getContext('2d', { willReadFrequently: true });
|
|
133
|
+
const toRgb = (css: string, fallback: Rgb): Rgb => {
|
|
134
|
+
if (!pctx || !css) return fallback;
|
|
135
|
+
pctx.clearRect(0, 0, 1, 1);
|
|
136
|
+
pctx.fillStyle = '#000';
|
|
137
|
+
pctx.fillStyle = css;
|
|
138
|
+
pctx.fillRect(0, 0, 1, 1);
|
|
139
|
+
const d = pctx.getImageData(0, 0, 1, 1).data;
|
|
140
|
+
return [d[0], d[1], d[2]];
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const paths: Path2D[] = new Array(BUCKETS * 2);
|
|
144
|
+
function draw() {
|
|
145
|
+
if (!ctx) return;
|
|
146
|
+
const t0 = performance.now();
|
|
147
|
+
ctx.clearRect(0, 0, w, h);
|
|
148
|
+
for (let k = 0; k < paths.length; k++) paths[k] = new Path2D();
|
|
149
|
+
for (let i = 0; i < n; i++) {
|
|
150
|
+
const m = Math.min(1, Math.hypot(OX[i], OY[i]) / P.gustPx);
|
|
151
|
+
const b = Math.min(BUCKETS - 1, (m * BUCKETS) | 0);
|
|
152
|
+
const p = paths[AC[i] * BUCKETS + b];
|
|
153
|
+
const x = X[i] + OX[i];
|
|
154
|
+
const y = Y[i] + OY[i];
|
|
155
|
+
p.moveTo(x + P.radius, y);
|
|
156
|
+
p.arc(x, y, P.radius, 0, Math.PI * 2);
|
|
157
|
+
}
|
|
158
|
+
for (let a = 0; a < 2; a++) {
|
|
159
|
+
const c = a ? pr : fg;
|
|
160
|
+
for (let b = 0; b < BUCKETS; b++) {
|
|
161
|
+
const al = bucketAlpha(a === 1, b, dark, P);
|
|
162
|
+
ctx.fillStyle = `rgba(${c[0]},${c[1]},${c[2]},${al.toFixed(3)})`;
|
|
163
|
+
ctx.fill(paths[a * BUCKETS + b]);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
stats.frames++;
|
|
167
|
+
stats.ms += performance.now() - t0;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function readTheme() {
|
|
171
|
+
const cs = getComputedStyle(host);
|
|
172
|
+
fg = toRgb(cs.getPropertyValue('--foreground').trim(), fg);
|
|
173
|
+
pr = toRgb(cs.getPropertyValue('--primary').trim(), pr);
|
|
174
|
+
dark = document.documentElement.classList.contains('dark');
|
|
175
|
+
settled = false;
|
|
176
|
+
draw();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function layout() {
|
|
180
|
+
if (!ctx) return;
|
|
181
|
+
const dpr = Math.min(window.devicePixelRatio || 1, P.dprMax);
|
|
182
|
+
w = host.clientWidth;
|
|
183
|
+
h = host.clientHeight;
|
|
184
|
+
canvas.width = Math.round(w * dpr);
|
|
185
|
+
canvas.height = Math.round(h * dpr);
|
|
186
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
187
|
+
const { cols, rows, count } = gridSize(w, h, P.spacing);
|
|
188
|
+
n = count;
|
|
189
|
+
X = new Float32Array(n);
|
|
190
|
+
Y = new Float32Array(n);
|
|
191
|
+
OX = new Float32Array(n);
|
|
192
|
+
OY = new Float32Array(n);
|
|
193
|
+
VX = new Float32Array(n);
|
|
194
|
+
VY = new Float32Array(n);
|
|
195
|
+
S = new Float32Array(n);
|
|
196
|
+
PH = new Float32Array(n);
|
|
197
|
+
AC = new Uint8Array(n);
|
|
198
|
+
const x0 = (w - (cols - 1) * P.spacing) / 2;
|
|
199
|
+
const y0 = P.spacing / 2;
|
|
200
|
+
let i = 0;
|
|
201
|
+
for (let r = 0; r < rows; r++) {
|
|
202
|
+
for (let c = 0; c < cols; c++, i++) {
|
|
203
|
+
X[i] = x0 + c * P.spacing;
|
|
204
|
+
Y[i] = y0 + r * P.spacing;
|
|
205
|
+
S[i] = 0.6 + Math.random() * 0.4;
|
|
206
|
+
PH[i] = Math.random() * Math.PI * 2;
|
|
207
|
+
AC[i] = isAccentDot(c, r, P.accentEvery) ? 1 : 0;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
settled = false;
|
|
211
|
+
draw();
|
|
212
|
+
kick();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function step(now: number) {
|
|
216
|
+
raf = 0;
|
|
217
|
+
if (paused || destroyed || document.hidden) return;
|
|
218
|
+
if (now - last < 1000 / P.fps - 1) {
|
|
219
|
+
raf = requestAnimationFrame(step);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
last = now;
|
|
223
|
+
if (!nextAt) nextAt = now + rnd(800, 2500);
|
|
224
|
+
if (now >= nextAt) {
|
|
225
|
+
fronts.push({
|
|
226
|
+
t: now,
|
|
227
|
+
v: (w + 2 * P.frontWidth + h * slant) / rnd(P.crossMs[0], P.crossMs[1]),
|
|
228
|
+
x: 0,
|
|
229
|
+
});
|
|
230
|
+
nextAt = now + rnd(P.everyMs[0], P.everyMs[1]);
|
|
231
|
+
}
|
|
232
|
+
for (const f of fronts) f.x = (now - f.t) * f.v - P.frontWidth - h * slant;
|
|
233
|
+
fronts = fronts.filter((f) => f.x < w + P.frontWidth);
|
|
234
|
+
let energy = 0;
|
|
235
|
+
for (let i = 0; i < n; i++) {
|
|
236
|
+
let tx = 0;
|
|
237
|
+
let ty = 0;
|
|
238
|
+
for (const f of fronts) {
|
|
239
|
+
const k = 1 - Math.abs(X[i] - f.x - (h - Y[i]) * slant) / P.frontWidth;
|
|
240
|
+
if (k > 0) {
|
|
241
|
+
const g = P.gustPx * S[i] * smooth(k);
|
|
242
|
+
tx += g;
|
|
243
|
+
ty += g * 0.25 * Math.sin(PH[i]);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
VX[i] = (VX[i] + (tx - OX[i]) * P.spring) * P.damp;
|
|
247
|
+
VY[i] = (VY[i] + (ty - OY[i]) * P.spring) * P.damp;
|
|
248
|
+
OX[i] += VX[i];
|
|
249
|
+
OY[i] += VY[i];
|
|
250
|
+
energy += Math.abs(VX[i]) + Math.abs(VY[i]) + Math.abs(OX[i]);
|
|
251
|
+
}
|
|
252
|
+
// Idle: no front on screen and every dot at rest. Stop until the next front.
|
|
253
|
+
if (!fronts.length && energy < n * 0.002) {
|
|
254
|
+
if (!settled) {
|
|
255
|
+
OX.fill(0);
|
|
256
|
+
OY.fill(0);
|
|
257
|
+
draw();
|
|
258
|
+
settled = true;
|
|
259
|
+
}
|
|
260
|
+
clearTimeout(idleTimer);
|
|
261
|
+
idleTimer = setTimeout(kick, Math.max(0, nextAt - performance.now()));
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
settled = false;
|
|
265
|
+
draw();
|
|
266
|
+
raf = requestAnimationFrame(step);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function kick() {
|
|
270
|
+
if (!raf && !paused && !destroyed && !document.hidden) raf = requestAnimationFrame(step);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function stop() {
|
|
274
|
+
cancelAnimationFrame(raf);
|
|
275
|
+
raf = 0;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const ro =
|
|
279
|
+
typeof ResizeObserver !== 'undefined'
|
|
280
|
+
? new ResizeObserver(() => {
|
|
281
|
+
clearTimeout(layoutTimer);
|
|
282
|
+
layoutTimer = setTimeout(layout, 150);
|
|
283
|
+
})
|
|
284
|
+
: null;
|
|
285
|
+
ro?.observe(host);
|
|
286
|
+
// applyTheme writes vars inline on <html>, so watch style as well as class.
|
|
287
|
+
const mo = new MutationObserver(readTheme);
|
|
288
|
+
mo.observe(document.documentElement, { attributes: true, attributeFilter: ['class', 'style'] });
|
|
289
|
+
const onVisibility = () => (document.hidden ? stop() : kick());
|
|
290
|
+
document.addEventListener('visibilitychange', onVisibility);
|
|
291
|
+
|
|
292
|
+
readTheme();
|
|
293
|
+
layout();
|
|
294
|
+
|
|
295
|
+
return {
|
|
296
|
+
pause(value: boolean) {
|
|
297
|
+
paused = value;
|
|
298
|
+
if (paused) stop();
|
|
299
|
+
else kick();
|
|
300
|
+
},
|
|
301
|
+
stats,
|
|
302
|
+
destroy() {
|
|
303
|
+
destroyed = true;
|
|
304
|
+
stop();
|
|
305
|
+
clearTimeout(idleTimer);
|
|
306
|
+
clearTimeout(layoutTimer);
|
|
307
|
+
ro?.disconnect();
|
|
308
|
+
mo.disconnect();
|
|
309
|
+
document.removeEventListener('visibilitychange', onVisibility);
|
|
310
|
+
canvas.remove();
|
|
311
|
+
host.removeAttribute('data-live');
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { Dialog, DialogContent, DialogDescription, DialogTitle } from '../../components/ui/dialog';
|
|
12
12
|
import { cn } from '../../lib/utils';
|
|
13
13
|
import { sheetExpandedHeightPx } from './overlaySize';
|
|
14
|
+
import { readDrawerBottomOffset } from '../layouts/chrome/viewport';
|
|
14
15
|
|
|
15
16
|
export type ResponsiveModalPresentation = 'dialog' | 'sheet';
|
|
16
17
|
|
|
@@ -452,7 +453,8 @@ export function ResponsiveModal({
|
|
|
452
453
|
(rawDelta >= SWIPE_DISMISS_PX || rawDelta >= height * SWIPE_DISMISS_RATIO);
|
|
453
454
|
if (shouldDismiss) {
|
|
454
455
|
setDismissMode('swipe');
|
|
455
|
-
|
|
456
|
+
// Past the bottom offset and shadow so no strip stays on screen
|
|
457
|
+
setSheetDragOffset(Math.max(rawDelta, height + readDrawerBottomOffset() + 48));
|
|
456
458
|
setSheetDragHeight(null);
|
|
457
459
|
onOpenChange(false);
|
|
458
460
|
return;
|
|
@@ -570,7 +572,7 @@ export function ResponsiveModal({
|
|
|
570
572
|
className={cn(
|
|
571
573
|
'gap-0 p-0 overflow-hidden flex flex-col',
|
|
572
574
|
isSheet
|
|
573
|
-
? 'left-
|
|
575
|
+
? 'left-[var(--shellui-drawer-left)] right-[var(--shellui-drawer-right)] top-auto bottom-[var(--shellui-drawer-bottom)] max-w-none w-auto translate-x-0 translate-y-0 rounded-[var(--shellui-sheet-radius)] border border-[var(--shellui-drawer-border)] shadow-[var(--shellui-drawer-shadow)]'
|
|
574
576
|
: cn('rounded-lg', hasCustomGeometry && 'translate-x-0 translate-y-0 max-w-none'),
|
|
575
577
|
className,
|
|
576
578
|
)}
|
|
@@ -647,7 +649,7 @@ export function ResponsiveModal({
|
|
|
647
649
|
>
|
|
648
650
|
{/* Centered tall hit target only — rest of the strip is click-through */}
|
|
649
651
|
<div
|
|
650
|
-
className="pointer-events-auto relative h-11 w-28 shrink-0 cursor-grab touch-none active:cursor-grabbing after:absolute after:left-1/2 after:top-1.5 after:h-[
|
|
652
|
+
className="pointer-events-auto relative h-11 w-28 shrink-0 cursor-grab touch-none active:cursor-grabbing after:absolute after:left-1/2 after:top-1.5 after:h-[5px] after:w-9 after:-translate-x-1/2 after:rounded-full after:bg-[color-mix(in_oklch,var(--foreground)_22%,transparent)] after:content-['']"
|
|
651
653
|
onPointerDown={handleSheetPointerDown}
|
|
652
654
|
onPointerMove={handleSheetPointerMove}
|
|
653
655
|
onPointerUp={handleSheetPointerUp}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
resolveDrawerSize,
|
|
10
10
|
resolveDrawerSizeForViewport,
|
|
11
11
|
resolveEffectiveDrawerPosition,
|
|
12
|
-
|
|
12
|
+
sheetExpandedHeightPx,
|
|
13
13
|
SHEET_EXPANDED_TOP_GAP_PX,
|
|
14
14
|
toCssLength,
|
|
15
15
|
} from './overlaySize';
|
|
@@ -69,18 +69,32 @@ describe('overlaySize', () => {
|
|
|
69
69
|
expect(resolveEffectiveDrawerPosition('right', false)).toBe('right');
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
it('
|
|
72
|
+
it('sizes phone sheets to content, keeping the requested height as fallback', () => {
|
|
73
73
|
const desktop = resolveDrawerSizeForViewport({ size: '60vw' }, 'right', false);
|
|
74
74
|
expect(desktop.drawerSize).toBe('60vw');
|
|
75
|
+
expect(desktop.contentSized).toBe(false);
|
|
75
76
|
|
|
77
|
+
const cap = 'var(--shellui-drawer-max-height)';
|
|
76
78
|
const mobile = resolveDrawerSizeForViewport({ size: '60vw' }, 'right', true);
|
|
77
|
-
expect(mobile.
|
|
79
|
+
expect(mobile.contentSized).toBe(true);
|
|
80
|
+
expect(mobile.drawerSize).toBeNull();
|
|
81
|
+
expect(mobile.style.height).toBe('auto');
|
|
82
|
+
expect(mobile.style.maxHeight).toBe(cap);
|
|
83
|
+
// Horizontal freeform width never becomes a sheet height
|
|
84
|
+
expect(mobile.fallbackHeight).toBe(
|
|
85
|
+
`min(calc(var(--shellui-overlay-max-height) * 0.8), ${cap})`,
|
|
86
|
+
);
|
|
78
87
|
|
|
79
88
|
const preset = resolveDrawerSizeForViewport({ size: 'md' }, 'right', true);
|
|
80
|
-
expect(preset.
|
|
89
|
+
expect(preset.fallbackHeight).toBe(
|
|
90
|
+
`min(calc(var(--shellui-overlay-max-height) * 0.55), ${cap})`,
|
|
91
|
+
);
|
|
81
92
|
|
|
82
93
|
const fromTop = resolveDrawerSizeForViewport({ size: '60vh' }, 'top', true);
|
|
83
|
-
expect(fromTop.
|
|
94
|
+
expect(fromTop.fallbackHeight).toBe(`min(60vh, ${cap})`);
|
|
95
|
+
|
|
96
|
+
const content = resolveDrawerSizeForViewport({ size: 'content' }, 'left', true);
|
|
97
|
+
expect(content.fallbackHeight).toBeNull();
|
|
84
98
|
});
|
|
85
99
|
|
|
86
100
|
it('defaults dismiss options', () => {
|
|
@@ -99,17 +113,43 @@ describe('overlaySize', () => {
|
|
|
99
113
|
});
|
|
100
114
|
|
|
101
115
|
it('resolves bottom sheet snap points for expand / collapse', () => {
|
|
102
|
-
// viewport 1000, no safe
|
|
103
|
-
|
|
104
|
-
expect(
|
|
105
|
-
expect(resolveBottomSheetSnapPoints(
|
|
106
|
-
expect(resolveBottomSheetSnapPoints(
|
|
107
|
-
expect(resolveBottomSheetSnapPoints({ size: '
|
|
108
|
-
expect(resolveBottomSheetSnapPoints({ size: '
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
// viewport 1000, no safe area, 8px bottom gap → sheet 932px, Vaul offset 68px
|
|
117
|
+
expect(sheetExpandedHeightPx(1000, 0, 8)).toBe(1000 - SHEET_EXPANDED_TOP_GAP_PX - 8);
|
|
118
|
+
expect(resolveBottomSheetSnapPoints({ size: 'md' }, null, 1000, 0, 8)).toEqual([0.618, 1]);
|
|
119
|
+
expect(resolveBottomSheetSnapPoints(null, null, 1000, 0, 8)).toEqual([0.868, 1]);
|
|
120
|
+
expect(resolveBottomSheetSnapPoints({ size: '400px' }, null, 1000, 0, 8)).toEqual([0.468, 1]);
|
|
121
|
+
expect(resolveBottomSheetSnapPoints({ size: 'full' }, null, 1000, 0, 8)).toBeNull();
|
|
122
|
+
expect(resolveBottomSheetSnapPoints({ size: 'sm' }, 700, 1000, 0, 8)).toEqual([0.768, 1]);
|
|
123
|
+
// Content close to the expanded height: nothing to expand to
|
|
124
|
+
expect(resolveBottomSheetSnapPoints({ size: 'sm' }, 920, 1000, 0, 8)).toBeNull();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('keeps the expanded phone sheet on screen (390 x 844, notch)', () => {
|
|
128
|
+
const H = 844;
|
|
129
|
+
const safeTop = 47;
|
|
130
|
+
const bottom = 8 + 34; // gap + home indicator
|
|
131
|
+
const h = sheetExpandedHeightPx(H, safeTop, bottom);
|
|
132
|
+
expect(h).toBe(695);
|
|
133
|
+
const snaps = resolveBottomSheetSnapPoints({ size: 'md' }, null, H, safeTop, bottom);
|
|
134
|
+
expect(snaps).not.toBeNull();
|
|
135
|
+
const [normal, expanded] = snaps ?? [0, 0];
|
|
136
|
+
// Expanded snap = no translate: top at 60px + safe area, bottom 8px above the indicator
|
|
137
|
+
expect(expanded).toBe(1);
|
|
138
|
+
const sheetTop = H - bottom - h;
|
|
139
|
+
const translate = (snap: number) => H - snap * H;
|
|
140
|
+
expect(sheetTop + translate(expanded)).toBe(SHEET_EXPANDED_TOP_GAP_PX + safeTop);
|
|
141
|
+
expect(sheetTop + translate(expanded) + h).toBe(H - bottom);
|
|
142
|
+
// First snap still shows the requested height (55%) above the bottom offset
|
|
143
|
+
const visibleAboveGap = H - bottom - (sheetTop + translate(normal));
|
|
144
|
+
expect(Math.abs(visibleAboveGap - 0.55 * H)).toBeLessThan(1);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('leaves the drawer gap around full drawers', () => {
|
|
148
|
+
expect(resolveDrawerSize({ size: 'full' }, 'right').drawerSize).toBe(
|
|
149
|
+
'calc(100% - 2 * var(--shellui-drawer-gap))',
|
|
150
|
+
);
|
|
151
|
+
expect(resolveDrawerSize({ size: 'full' }, 'top').drawerSize).toBe(
|
|
152
|
+
'var(--shellui-drawer-max-height)',
|
|
113
153
|
);
|
|
114
154
|
});
|
|
115
155
|
});
|