@shellui/core 0.5.0-beta.2 → 0.5.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 (70) hide show
  1. package/README.md +5 -5
  2. package/package.json +3 -2
  3. package/schemas/shellui.config.schema.json +10 -2
  4. package/src/app.tsx +8 -4
  5. package/src/components/ContentView.tsx +12 -5
  6. package/src/components/ui/alert-dialog.tsx +1 -1
  7. package/src/components/ui/dialog.tsx +5 -1
  8. package/src/components/ui/dropdown-menu.tsx +39 -4
  9. package/src/components/ui/sheet.tsx +1 -1
  10. package/src/components/ui/sidebar.tsx +60 -20
  11. package/src/components/ui/tabs.tsx +52 -0
  12. package/src/constants/urls.ts +1 -0
  13. package/src/features/auth/AuthProvider.tsx +17 -6
  14. package/src/features/chromeActions/ChromeActionIcons.tsx +261 -0
  15. package/src/features/chromeActions/ChromeActionsDemoView.tsx +149 -0
  16. package/src/features/chromeActions/ChromeActionsHost.tsx +1511 -0
  17. package/src/features/chromeActions/ChromeActionsProvider.tsx +141 -0
  18. package/src/features/chromeActions/chromeActionsStore.spec.ts +61 -0
  19. package/src/features/chromeActions/chromeActionsStore.ts +77 -0
  20. package/src/features/chromeActions/computeActionInsets.spec.ts +360 -0
  21. package/src/features/chromeActions/computeActionInsets.ts +326 -0
  22. package/src/features/chromeActions/index.ts +26 -0
  23. package/src/features/chromeActions/resolveUuidForRemoveIframe.spec.ts +49 -0
  24. package/src/features/config/types.ts +16 -2
  25. package/src/features/layouts/AppLayout.tsx +30 -3
  26. package/src/features/layouts/OverlayShell.tsx +63 -13
  27. package/src/features/layouts/app-bar-inset/AppBarInsetLayout.tsx +22 -0
  28. package/src/features/layouts/appbar/AppBarLayout.tsx +230 -86
  29. package/src/features/layouts/chrome/DesktopChrome.tsx +17 -3
  30. package/src/features/layouts/chrome/InsetMobileRadiusOverlay.tsx +18 -0
  31. package/src/features/layouts/chrome/index.ts +8 -0
  32. package/src/features/layouts/chrome/runtime.ts +73 -0
  33. package/src/features/layouts/chrome/useScrollHideChrome.ts +210 -0
  34. package/src/features/layouts/floating/FloatingBottomDock.tsx +410 -0
  35. package/src/features/layouts/floating/FloatingLayout.tsx +152 -0
  36. package/src/features/layouts/floating/FloatingSidebar.tsx +327 -0
  37. package/src/features/layouts/floating/FloatingStatusScrim.tsx +36 -0
  38. package/src/features/layouts/floating/computeFloatingInsets.spec.ts +83 -0
  39. package/src/features/layouts/floating/computeFloatingInsets.ts +155 -0
  40. package/src/features/layouts/floating/isShellOwnedPath.spec.ts +25 -0
  41. package/src/features/layouts/floating/isShellOwnedPath.ts +17 -0
  42. package/src/features/layouts/floating/layoutChromeStore.spec.ts +138 -0
  43. package/src/features/layouts/floating/layoutChromeStore.ts +209 -0
  44. package/src/features/layouts/floating/scrollChrome.spec.ts +49 -0
  45. package/src/features/layouts/floating/useFloatingChrome.ts +206 -0
  46. package/src/features/layouts/sidebar/SidebarLayout.tsx +119 -37
  47. package/src/features/layouts/sidebar/types.ts +4 -0
  48. package/src/features/layouts/sidebar-inset/SidebarInsetLayout.tsx +15 -0
  49. package/src/features/layouts/windows/WindowsLayout.tsx +240 -110
  50. package/src/features/overlays/ResponsiveModal.tsx +201 -21
  51. package/src/features/overlays/overlaySize.spec.ts +18 -0
  52. package/src/features/overlays/overlaySize.ts +89 -0
  53. package/src/features/settings/SettingsProvider.tsx +36 -9
  54. package/src/features/settings/SettingsView.tsx +6 -6
  55. package/src/features/settings/components/Develop.tsx +33 -13
  56. package/src/features/settings/components/develop/ChromeActionsTestButtons.tsx +63 -0
  57. package/src/features/settings/utils/buildSettingsForPropagation.ts +16 -0
  58. package/src/features/storage/StoragePickerContext.tsx +1 -0
  59. package/src/features/storage/uploads/uploadQueue.spec.ts +56 -1
  60. package/src/features/storage/uploads/uploadQueue.ts +42 -1
  61. package/src/features/theme/applyTheme.ts +23 -5
  62. package/src/hooks/use-mobile.tsx +21 -7
  63. package/src/hooks/use-viewport.ts +40 -0
  64. package/src/i18n/translations/en/settings.json +17 -2
  65. package/src/i18n/translations/fr/settings.json +17 -2
  66. package/src/index.css +473 -12
  67. package/src/index.html +6 -4
  68. package/src/index.ts +8 -0
  69. package/src/routes/components/RouteFallback.tsx +21 -2
  70. package/src/routes/routes.tsx +14 -0
@@ -0,0 +1,155 @@
1
+ import type { LayoutChromeInsets, LayoutChromeViewport } from '@shellui/sdk';
2
+
3
+ /** Floating tab bar content height (icon + short label) — phone. */
4
+ export const FLOATING_TAB_BAR_HEIGHT = 56;
5
+ /** Tablet floating dock — taller touch targets. */
6
+ export const FLOATING_TAB_BAR_HEIGHT_TABLET = 64;
7
+ /** Gap between floating chrome and screen edge. */
8
+ export const FLOATING_CHROME_MARGIN = 12;
9
+ /**
10
+ * Extra horizontal inset for the bottom nav so it doesn’t hug the window edge.
11
+ * Applied on top of FLOATING_CHROME_MARGIN + safe-area.
12
+ */
13
+ export const FLOATING_DOCK_SIDE_INSET = 8;
14
+ /** Extra clearance so the last content row clears the floating chrome comfortably. */
15
+ export const FLOATING_CONTENT_CLEARANCE = 12;
16
+ /** Desktop floating sidebar width. */
17
+ export const FLOATING_SIDEBAR_WIDTH = 240;
18
+ /**
19
+ * Soft cap used as the initial slot guess before ResizeObserver measures.
20
+ * Actual visible count is derived from available width / min slot width.
21
+ * iPhone 15 (~393px) fits 5 with FAB after side insets + FAB reserve.
22
+ */
23
+ export const FLOATING_MAX_TAB_SLOTS = 5;
24
+ /**
25
+ * Phone-only cap when the corner FAB is present — keeps the bar from feeling crowded.
26
+ * Tablet keeps `FLOATING_MAX_TAB_SLOTS` even with a FAB.
27
+ */
28
+ export const FLOATING_MAX_TAB_SLOTS_WITH_FAB = 4;
29
+ /** Minimum equal-width slot for a bottom-nav tab (icon + readable label). */
30
+ export const FLOATING_MIN_TAB_SLOT_WIDTH = 56;
31
+ /** Tablet floating dock slots — wider so labels stay readable. */
32
+ export const FLOATING_MIN_TAB_SLOT_WIDTH_TABLET = 96;
33
+ /** Gap between the phone nav bar and the corner FAB (keep tight). */
34
+ export const FLOATING_FAB_NAV_GAP = 6;
35
+
36
+ export function floatingTabBarHeight(viewport: LayoutChromeViewport): number {
37
+ return viewport === 'tablet' ? FLOATING_TAB_BAR_HEIGHT_TABLET : FLOATING_TAB_BAR_HEIGHT;
38
+ }
39
+
40
+ export function floatingMinTabSlotWidth(viewport: LayoutChromeViewport): number {
41
+ return viewport === 'tablet' ? FLOATING_MIN_TAB_SLOT_WIDTH_TABLET : FLOATING_MIN_TAB_SLOT_WIDTH;
42
+ }
43
+
44
+ /**
45
+ * Padding under the floating tab bar (chrome margin + safe-area).
46
+ * Phone uses half so the bar sits lower on iPhone home-indicator devices.
47
+ */
48
+ export function floatingTabBarBottomPadPx(
49
+ safeBottom: number,
50
+ viewport: LayoutChromeViewport,
51
+ ): number {
52
+ const full = FLOATING_CHROME_MARGIN + safeBottom;
53
+ return viewport === 'mobile' ? full / 2 : full;
54
+ }
55
+
56
+ /**
57
+ * Same bottom pad as the floating dock, as a CSS value so
58
+ * `--shellui-safe-area-bottom` / env() apply on iPhone (not a snapped 0px number).
59
+ */
60
+ export function floatingTabBarBottomPadCss(viewport: LayoutChromeViewport): string {
61
+ if (viewport === 'mobile') {
62
+ return `calc((${FLOATING_CHROME_MARGIN}px + var(--shellui-safe-area-bottom, 0px)) / 2)`;
63
+ }
64
+ return `calc(${FLOATING_CHROME_MARGIN}px + var(--shellui-safe-area-bottom, 0px))`;
65
+ }
66
+ /** Collapsed desktop toggle control size (glass chip). */
67
+ export const FLOATING_SIDEBAR_TOGGLE_SIZE = 36;
68
+ /**
69
+ * Extra leading pad for chrome actions when the desktop sidebar is collapsed
70
+ * (toggle size + clearance). Content itself stays full-bleed — only the action
71
+ * row clears the expand chip.
72
+ */
73
+ export const FLOATING_COLLAPSED_ACTIONS_LEADING_EXTRA =
74
+ FLOATING_SIDEBAR_TOGGLE_SIZE + FLOATING_CONTENT_CLEARANCE;
75
+ /**
76
+ * Floating sidebar brand header: `py-2.5` (10+10) + `size-8` toggle (32).
77
+ * Keep in sync with FloatingSidebar brand row.
78
+ */
79
+ export const FLOATING_SIDEBAR_BRAND_ROW_HEIGHT = 52;
80
+ /** Floating sidebar nav scroll pad (`p-2`). Keep in sync with FloatingSidebar. */
81
+ export const FLOATING_SIDEBAR_NAV_PAD = 8;
82
+ /**
83
+ * Distance from viewport top to the first sidebar nav item (panel margin +
84
+ * brand row + nav pad). Geometry reference for the floating sidebar panel.
85
+ */
86
+ export const FLOATING_SIDEBAR_FIRST_NAV_TOP =
87
+ FLOATING_CHROME_MARGIN + FLOATING_SIDEBAR_BRAND_ROW_HEIGHT + FLOATING_SIDEBAR_NAV_PAD;
88
+
89
+ export type FloatingSafeArea = LayoutChromeInsets;
90
+
91
+ export function computeFloatingInsets(options: {
92
+ viewport: LayoutChromeViewport;
93
+ chromeVisible: boolean;
94
+ /** Desktop only: sidebar hidden — no left content inset (chip cleared by actions pad). */
95
+ sidebarCollapsed?: boolean;
96
+ safeArea?: Partial<FloatingSafeArea>;
97
+ }): LayoutChromeInsets {
98
+ const safe: FloatingSafeArea = {
99
+ top: options.safeArea?.top ?? 0,
100
+ right: options.safeArea?.right ?? 0,
101
+ bottom: options.safeArea?.bottom ?? 0,
102
+ left: options.safeArea?.left ?? 0,
103
+ };
104
+
105
+ if (!options.chromeVisible) {
106
+ return { ...safe };
107
+ }
108
+
109
+ const { viewport } = options;
110
+ if (viewport === 'mobile' || viewport === 'tablet') {
111
+ return {
112
+ top: safe.top,
113
+ right: safe.right,
114
+ bottom:
115
+ floatingTabBarBottomPadPx(safe.bottom, viewport) +
116
+ floatingTabBarHeight(viewport) +
117
+ FLOATING_CHROME_MARGIN +
118
+ FLOATING_CONTENT_CLEARANCE,
119
+ left: safe.left,
120
+ };
121
+ }
122
+
123
+ if (options.sidebarCollapsed) {
124
+ return {
125
+ top: safe.top,
126
+ right: safe.right,
127
+ bottom: safe.bottom,
128
+ left: safe.left,
129
+ };
130
+ }
131
+
132
+ return {
133
+ top: safe.top,
134
+ right: safe.right,
135
+ bottom: safe.bottom,
136
+ left:
137
+ safe.left + FLOATING_SIDEBAR_WIDTH + FLOATING_CHROME_MARGIN * 2 + FLOATING_CONTENT_CLEARANCE,
138
+ };
139
+ }
140
+
141
+ /** Read shell safe-area CSS vars as pixel numbers (0 when unavailable). */
142
+ export function readShellSafeAreaPx(el: HTMLElement = document.documentElement): FloatingSafeArea {
143
+ const styles = getComputedStyle(el);
144
+ const parse = (name: string): number => {
145
+ const raw = styles.getPropertyValue(name).trim();
146
+ const n = parseFloat(raw);
147
+ return Number.isFinite(n) ? n : 0;
148
+ };
149
+ return {
150
+ top: parse('--shellui-safe-area-top'),
151
+ right: parse('--shellui-safe-area-right'),
152
+ bottom: parse('--shellui-safe-area-bottom'),
153
+ left: parse('--shellui-safe-area-left'),
154
+ };
155
+ }
@@ -0,0 +1,25 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { isShellOwnedPath } from './isShellOwnedPath';
3
+
4
+ describe('isShellOwnedPath', () => {
5
+ it('matches settings and nested settings routes', () => {
6
+ expect(isShellOwnedPath('/__settings')).toBe(true);
7
+ expect(isShellOwnedPath('/__settings/')).toBe(true);
8
+ expect(isShellOwnedPath('/__settings/developpers')).toBe(true);
9
+ expect(isShellOwnedPath('/__settings/appearance')).toBe(true);
10
+ });
11
+
12
+ it('matches other shell pages', () => {
13
+ expect(isShellOwnedPath('/login')).toBe(true);
14
+ expect(isShellOwnedPath('/admin')).toBe(true);
15
+ expect(isShellOwnedPath('/legal/privacy-policy')).toBe(true);
16
+ expect(isShellOwnedPath('/__overlay-demo')).toBe(true);
17
+ expect(isShellOwnedPath('/__chrome-actions-demo')).toBe(true);
18
+ });
19
+
20
+ it('rejects embedded app paths', () => {
21
+ expect(isShellOwnedPath('/')).toBe(false);
22
+ expect(isShellOwnedPath('/home')).toBe(false);
23
+ expect(isShellOwnedPath('/dashboard')).toBe(false);
24
+ });
25
+ });
@@ -0,0 +1,17 @@
1
+ import urls from '../../../constants/urls';
2
+
3
+ const SHELL_OWNED_PREFIXES = [
4
+ urls.settings,
5
+ urls.cookiePreferences,
6
+ urls.overlayDemo,
7
+ urls.chromeActionsDemo,
8
+ urls.login,
9
+ urls.admin,
10
+ urls.legalDocuments,
11
+ ] as const;
12
+
13
+ /** True for shell React pages (settings, login, admin, …) — not embedded iframe apps. */
14
+ export function isShellOwnedPath(pathname: string): boolean {
15
+ const path = pathname.replace(/\/+$/, '') || '/';
16
+ return SHELL_OWNED_PREFIXES.some((prefix) => path === prefix || path.startsWith(`${prefix}/`));
17
+ }
@@ -0,0 +1,138 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { buildFrameLayoutChrome } from './layoutChromeStore';
3
+ import {
4
+ CHROME_ACTIONS_CONTENT_CLEARANCE,
5
+ CHROME_ACTIONS_FAB_EDGE_MARGIN,
6
+ CHROME_ACTIONS_FAB_GAP,
7
+ CHROME_ACTIONS_FAB_SIZE_DESKTOP,
8
+ CHROME_ACTIONS_TOP_BAR_HEIGHT,
9
+ CHROME_ACTIONS_TOP_BAR_HEIGHT_NARROW,
10
+ CHROME_ACTIONS_TOP_MARGIN,
11
+ CHROME_ACTIONS_TOP_MARGIN_DESKTOP,
12
+ CHROME_ACTIONS_TOP_MARGIN_MINIMAL,
13
+ } from '../../chromeActions/computeActionInsets';
14
+ import { FLOATING_CONTENT_CLEARANCE } from './computeFloatingInsets';
15
+
16
+ const CLEARED = {
17
+ layout: 'none',
18
+ viewport: 'desktop' as const,
19
+ insets: { top: 0, right: 0, bottom: 0, left: 0 },
20
+ chromeVisible: false,
21
+ autoPadding: true,
22
+ };
23
+
24
+ const FLOATING = {
25
+ layout: 'floating',
26
+ viewport: 'desktop' as const,
27
+ insets: { top: 0, right: 0, bottom: 72, left: 280 },
28
+ chromeVisible: true,
29
+ autoPadding: true,
30
+ };
31
+
32
+ describe('buildFrameLayoutChrome', () => {
33
+ it('promotes layout none → actions so sidebar/app-bar get safe padding', () => {
34
+ const chrome = buildFrameLayoutChrome(CLEARED, { hasTop: true, hasPrimary: true });
35
+ expect(chrome.layout).toBe('actions');
36
+ expect(chrome.chromeVisible).toBe(true);
37
+ expect(chrome.insets.top).toBe(
38
+ CHROME_ACTIONS_TOP_MARGIN_MINIMAL +
39
+ CHROME_ACTIONS_TOP_BAR_HEIGHT +
40
+ CHROME_ACTIONS_CONTENT_CLEARANCE,
41
+ );
42
+ expect(chrome.insets.bottom).toBe(
43
+ CHROME_ACTIONS_FAB_EDGE_MARGIN + CHROME_ACTIONS_FAB_SIZE_DESKTOP + FLOATING_CONTENT_CLEARANCE,
44
+ );
45
+ });
46
+
47
+ it('keeps floating desktop expanded actions one margin below the brand row', () => {
48
+ const chrome = buildFrameLayoutChrome(FLOATING, { hasTop: true, hasPrimary: true });
49
+ expect(chrome.layout).toBe('floating');
50
+ expect(chrome.insets.left).toBe(280);
51
+ expect(chrome.insets.top).toBe(
52
+ CHROME_ACTIONS_TOP_MARGIN_DESKTOP +
53
+ CHROME_ACTIONS_TOP_BAR_HEIGHT +
54
+ CHROME_ACTIONS_CONTENT_CLEARANCE,
55
+ );
56
+ // Desktop floating: FAB still sits above existing bottom inset (corner FAB).
57
+ expect(chrome.insets.bottom).toBe(
58
+ 72 + CHROME_ACTIONS_FAB_SIZE_DESKTOP + CHROME_ACTIONS_FAB_GAP,
59
+ );
60
+ });
61
+
62
+ it('keeps floating desktop collapsed near the expand chip', () => {
63
+ const collapsed = {
64
+ ...FLOATING,
65
+ chromeVisible: false,
66
+ insets: { ...FLOATING.insets, left: 0 },
67
+ };
68
+ const chrome = buildFrameLayoutChrome(collapsed, { hasTop: true, hasPrimary: false });
69
+ expect(chrome.insets.top).toBe(
70
+ CHROME_ACTIONS_TOP_MARGIN_DESKTOP +
71
+ CHROME_ACTIONS_TOP_BAR_HEIGHT +
72
+ CHROME_ACTIONS_CONTENT_CLEARANCE,
73
+ );
74
+ });
75
+
76
+ it('does not stack FAB inset when floating phone/tablet docks the primary', () => {
77
+ const mobileFloating = {
78
+ ...FLOATING,
79
+ viewport: 'mobile' as const,
80
+ insets: { top: 0, right: 0, bottom: 88, left: 0 },
81
+ };
82
+ const chrome = buildFrameLayoutChrome(mobileFloating, { hasTop: true, hasPrimary: true });
83
+ expect(chrome.insets.bottom).toBe(88);
84
+ expect(chrome.insets.top).toBe(
85
+ CHROME_ACTIONS_TOP_MARGIN +
86
+ CHROME_ACTIONS_TOP_BAR_HEIGHT_NARROW +
87
+ CHROME_ACTIONS_CONTENT_CLEARANCE,
88
+ );
89
+ });
90
+
91
+ it('stacks the floating chrome margin above safe-area top when merging insets', () => {
92
+ const safeTop = 47;
93
+ const mobileFloating = {
94
+ ...FLOATING,
95
+ viewport: 'mobile' as const,
96
+ insets: { top: safeTop, right: 0, bottom: 88, left: 0 },
97
+ };
98
+ const chrome = buildFrameLayoutChrome(mobileFloating, { hasTop: true, hasPrimary: true });
99
+ expect(chrome.insets.top).toBe(
100
+ safeTop +
101
+ CHROME_ACTIONS_TOP_MARGIN +
102
+ CHROME_ACTIONS_TOP_BAR_HEIGHT_NARROW +
103
+ CHROME_ACTIONS_CONTENT_CLEARANCE,
104
+ );
105
+ });
106
+
107
+ it('leaves cleared chrome unchanged when no actions', () => {
108
+ expect(buildFrameLayoutChrome(CLEARED, { hasTop: false, hasPrimary: false })).toEqual(CLEARED);
109
+ });
110
+
111
+ it('skips top inset when actions live in the windows title bar', () => {
112
+ const chrome = buildFrameLayoutChrome(
113
+ CLEARED,
114
+ { hasTop: true, hasPrimary: true },
115
+ { topInTitleBar: true },
116
+ );
117
+ expect(chrome.layout).toBe('actions');
118
+ expect(chrome.insets.top).toBe(0);
119
+ expect(chrome.insets.bottom).toBeGreaterThan(0);
120
+ });
121
+
122
+ it('keeps shell header inset but skips action top pad when title-bar hosted', () => {
123
+ const base = {
124
+ ...CLEARED,
125
+ layout: 'sidebar' as const,
126
+ viewport: 'mobile' as const,
127
+ chromeVisible: true,
128
+ insets: { top: 90, right: 0, bottom: 0, left: 0 },
129
+ };
130
+ const chrome = buildFrameLayoutChrome(
131
+ base,
132
+ { hasTop: true, hasPrimary: true },
133
+ { topInTitleBar: true },
134
+ );
135
+ expect(chrome.insets.top).toBe(90);
136
+ expect(chrome.insets.bottom).toBeGreaterThan(0);
137
+ });
138
+ });
@@ -0,0 +1,209 @@
1
+ import { applyLayoutChromeStyles, shellui, type LayoutChrome } from '@shellui/sdk';
2
+ import { resolveViewport } from '../../../hooks/use-viewport';
3
+ import { getChromeActionsForFrame } from '../../chromeActions/chromeActionsStore';
4
+ import {
5
+ actionChromeFlags,
6
+ computeActionInsets,
7
+ mergeInsets,
8
+ type ActionChromeFlags,
9
+ } from '../../chromeActions/computeActionInsets';
10
+ import { readShellSafeAreaPx } from './computeFloatingInsets';
11
+
12
+ let currentChrome: LayoutChrome | null = null;
13
+
14
+ type LayoutChromeListener = () => void;
15
+ const layoutChromeListeners = new Set<LayoutChromeListener>();
16
+
17
+ function emitLayoutChrome(): void {
18
+ for (const listener of layoutChromeListeners) {
19
+ try {
20
+ listener();
21
+ } catch {
22
+ // Ignore subscriber errors.
23
+ }
24
+ }
25
+ }
26
+
27
+ /** Current layout-chrome snapshot (shell-side). Used when building settings for iframes. */
28
+ export function getPublishedLayoutChrome(): LayoutChrome | null {
29
+ return currentChrome;
30
+ }
31
+
32
+ /** Subscribe to published layout-chrome changes (e.g. floating hide-on-scroll). */
33
+ export function subscribeLayoutChrome(listener: LayoutChromeListener): () => void {
34
+ layoutChromeListeners.add(listener);
35
+ return () => {
36
+ layoutChromeListeners.delete(listener);
37
+ };
38
+ }
39
+
40
+ /** Main layout content iframes only (not modal / drawer / picker overlays). */
41
+ export function isMainLayoutFrame(iframe: HTMLIFrameElement | null | undefined): boolean {
42
+ if (!iframe) return false;
43
+ return iframe.dataset.shelluiFrame !== 'overlay';
44
+ }
45
+
46
+ const CLEARED_CHROME: LayoutChrome = {
47
+ layout: 'none',
48
+ viewport: 'desktop',
49
+ insets: { top: 0, right: 0, bottom: 0, left: 0 },
50
+ chromeVisible: false,
51
+ autoPadding: true,
52
+ };
53
+
54
+ /** Base chrome when no layout publisher is active (sidebar / app-bar / fullscreen). */
55
+ function resolveClearedChrome(): LayoutChrome {
56
+ const viewport =
57
+ typeof window !== 'undefined' ? resolveViewport(window.innerWidth) : CLEARED_CHROME.viewport;
58
+ return { ...CLEARED_CHROME, viewport };
59
+ }
60
+
61
+ function isWindowsLayout(): boolean {
62
+ if (typeof document === 'undefined') return false;
63
+ return Boolean(document.querySelector('[data-shellui-windows-layout]'));
64
+ }
65
+
66
+ /**
67
+ * Top actions are inlined in shell chrome (not a floating overlay):
68
+ * - windows title bars
69
+ * - mobile sidebar / sidebar-inset header
70
+ */
71
+ function isTopActionsInTitleBar(base: LayoutChrome): boolean {
72
+ if (isWindowsLayout()) return true;
73
+ if (base.viewport !== 'mobile') return false;
74
+ if (base.layout === 'sidebar' || base.layout === 'sidebar-inset') return true;
75
+ if (typeof document === 'undefined') return false;
76
+ return Boolean(document.querySelector('[data-shellui-sidebar-layout]'));
77
+ }
78
+
79
+ /**
80
+ * Merge per-frame action-button insets into a base layout-chrome snapshot.
81
+ * Sidebar / app-bar / fullscreen never publish floating chrome (`layout: 'none'`);
82
+ * when actions are present we promote to `layout: 'actions'` so the SDK treats
83
+ * insets as active and applies safe padding (same as overlay frames).
84
+ */
85
+ export function buildFrameLayoutChrome(
86
+ base: LayoutChrome,
87
+ flags: ActionChromeFlags,
88
+ options?: { topInTitleBar?: boolean },
89
+ ): LayoutChrome {
90
+ const primaryInDock =
91
+ base.layout === 'floating' && (base.viewport === 'mobile' || base.viewport === 'tablet');
92
+ // Floating desktop publishes chromeVisible=false when the sidebar is collapsed.
93
+ const sidebarExpanded =
94
+ base.layout === 'floating' && base.viewport === 'desktop' ? base.chromeVisible : undefined;
95
+ const safeArea =
96
+ typeof document !== 'undefined'
97
+ ? readShellSafeAreaPx()
98
+ : { top: 0, right: 0, bottom: 0, left: 0 };
99
+ const extra = computeActionInsets(flags, {
100
+ topInTitleBar: options?.topInTitleBar,
101
+ existingBottomInset: base.insets.bottom,
102
+ existingTopInset: base.insets.top,
103
+ primaryInDock,
104
+ viewport: base.viewport,
105
+ layout: base.layout,
106
+ sidebarExpanded,
107
+ // Docked / tab-bar bottoms already include safe-area; corner FABs need it here.
108
+ safeAreaBottom: primaryInDock || base.insets.bottom > 0 ? 0 : safeArea.bottom,
109
+ });
110
+ const insets = mergeInsets(base.insets, extra);
111
+ const hasActions = flags.hasTop || flags.hasPrimary;
112
+ if (!hasActions) {
113
+ return { ...base, insets };
114
+ }
115
+ if (base.layout === 'none') {
116
+ return {
117
+ ...base,
118
+ layout: 'actions',
119
+ chromeVisible: true,
120
+ insets,
121
+ };
122
+ }
123
+ return { ...base, insets };
124
+ }
125
+
126
+ function chromePayloadForFrame(uuid: string, base: LayoutChrome): LayoutChrome {
127
+ const actions = getChromeActionsForFrame(uuid);
128
+ return buildFrameLayoutChrome(base, actionChromeFlags(actions), {
129
+ topInTitleBar: isTopActionsInTitleBar(base),
130
+ });
131
+ }
132
+
133
+ /**
134
+ * Overlay / modal / drawer frames do not get floating sidebar / tab-bar insets.
135
+ * They only receive padding for shellui.actions chrome (top bar + primary FAB)
136
+ * so iframe content can clear those controls — and animate when set/clear.
137
+ */
138
+ function chromePayloadForOverlayFrame(
139
+ uuid: string,
140
+ viewport: LayoutChrome['viewport'],
141
+ ): LayoutChrome {
142
+ const actions = getChromeActionsForFrame(uuid);
143
+ const flags = actionChromeFlags(actions);
144
+ const safeArea =
145
+ typeof document !== 'undefined'
146
+ ? readShellSafeAreaPx()
147
+ : { top: 0, right: 0, bottom: 0, left: 0 };
148
+ const insets = computeActionInsets(flags, {
149
+ topInTitleBar: false,
150
+ viewport,
151
+ layout: 'actions',
152
+ safeAreaBottom: safeArea.bottom,
153
+ });
154
+ const hasActions = flags.hasTop || flags.hasPrimary;
155
+ return {
156
+ layout: hasActions ? 'actions' : 'none',
157
+ viewport,
158
+ chromeVisible: hasActions,
159
+ autoPadding: true,
160
+ insets,
161
+ };
162
+ }
163
+
164
+ /**
165
+ * Publish layout chrome to iframes.
166
+ * - Main frames: floating/nav insets + per-frame action chrome extras.
167
+ * - Overlay frames: action chrome insets only (so set/clear animates content pad).
168
+ * Apps apply insets via CSS vars / `shellui-apply-layout-chrome-pad`.
169
+ *
170
+ * Works for every shell layout (floating, sidebar, app-bar, …): when the base
171
+ * chrome is cleared/`none`, action insets alone still activate padding.
172
+ */
173
+ export function publishLayoutChrome(chrome: LayoutChrome | null): void {
174
+ currentChrome = chrome;
175
+ emitLayoutChrome();
176
+ if (typeof window === 'undefined') return;
177
+
178
+ const payload: LayoutChrome = chrome ?? resolveClearedChrome();
179
+
180
+ // Host shell document: vars only (no padding on the outer shell).
181
+ applyLayoutChromeStyles(payload, { autoPadding: false });
182
+
183
+ for (const [uuid, iframe] of shellui.frameRegistry.getAllIframes()) {
184
+ if (isMainLayoutFrame(iframe)) {
185
+ shellui.sendMessage({
186
+ type: 'SHELLUI_LAYOUT_CHROME',
187
+ payload: { layoutChrome: chromePayloadForFrame(uuid, payload) },
188
+ to: [uuid],
189
+ });
190
+ continue;
191
+ }
192
+
193
+ shellui.sendMessage({
194
+ type: 'SHELLUI_LAYOUT_CHROME',
195
+ payload: {
196
+ layoutChrome: chromePayloadForOverlayFrame(uuid, payload.viewport),
197
+ },
198
+ to: [uuid],
199
+ });
200
+ }
201
+ }
202
+
203
+ /**
204
+ * Re-apply the current published chrome (with fresh per-frame action insets).
205
+ * Call after chrome actions set/clear/frame removal.
206
+ */
207
+ export function republishLayoutChromeWithActions(): void {
208
+ publishLayoutChrome(currentChrome);
209
+ }
@@ -0,0 +1,49 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { resolveViewport } from '../../../hooks/use-viewport';
3
+ import { reduceScrollChromeVisibility } from '@shellui/sdk';
4
+
5
+ describe('resolveViewport', () => {
6
+ it('maps widths to mobile / tablet / desktop', () => {
7
+ expect(resolveViewport(320)).toBe('mobile');
8
+ expect(resolveViewport(767)).toBe('mobile');
9
+ expect(resolveViewport(768)).toBe('tablet');
10
+ expect(resolveViewport(1023)).toBe('tablet');
11
+ expect(resolveViewport(1024)).toBe('desktop');
12
+ });
13
+ });
14
+
15
+ describe('reduceScrollChromeVisibility', () => {
16
+ it('reveals chrome near the top', () => {
17
+ const next = reduceScrollChromeVisibility({ visible: false, lastY: 100 }, 10);
18
+ expect(next.visible).toBe(true);
19
+ });
20
+
21
+ it('hides chrome when scrolling down past threshold', () => {
22
+ const next = reduceScrollChromeVisibility({ visible: true, lastY: 40 }, 60);
23
+ expect(next.visible).toBe(false);
24
+ });
25
+
26
+ it('shows chrome when scrolling up past threshold', () => {
27
+ const next = reduceScrollChromeVisibility({ visible: false, lastY: 80 }, 60);
28
+ expect(next.visible).toBe(true);
29
+ });
30
+
31
+ it('ignores small deltas (hysteresis)', () => {
32
+ const next = reduceScrollChromeVisibility({ visible: true, lastY: 50 }, 55);
33
+ expect(next.visible).toBe(true);
34
+ });
35
+
36
+ it('reveals chrome near the bottom of the scroller', () => {
37
+ const next = reduceScrollChromeVisibility({ visible: false, lastY: 400 }, 480, {
38
+ distanceFromBottom: 40,
39
+ });
40
+ expect(next.visible).toBe(true);
41
+ });
42
+
43
+ it('keeps chrome hidden when still far from the bottom while scrolling down', () => {
44
+ const next = reduceScrollChromeVisibility({ visible: true, lastY: 200 }, 260, {
45
+ distanceFromBottom: 200,
46
+ });
47
+ expect(next.visible).toBe(false);
48
+ });
49
+ });