@ggraphic/editor-chrome 0.0.0-stage → 0.1.0-alpha.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.
@@ -0,0 +1,48 @@
1
+ interface UseMobileSheetOptions {
2
+ isOpen: boolean;
3
+ onClose: () => void;
4
+ /**
5
+ * Called once a drag has carried the sheet off-screen, right before
6
+ * `onClose` and in the same event — the owner can drop the sheet at once
7
+ * instead of playing its own exit from the top.
8
+ */
9
+ onDragClosed?: () => void;
10
+ /**
11
+ * What the sheet shows (e.g. its title). A change while a drag-close slides
12
+ * out aborts it — the close belonged to the previous content.
13
+ */
14
+ closeKey?: string | null;
15
+ threshold?: number;
16
+ velocityThreshold?: number;
17
+ }
18
+ interface UseMobileSheetReturn {
19
+ /** Header: wraps the grab handle and the title row. */
20
+ handleRef: React.RefObject<HTMLDivElement | null>;
21
+ sheetRef: React.RefObject<HTMLElement | null>;
22
+ /** The scroll container; pulls the sheet down only from its top. */
23
+ contentRef: React.RefObject<HTMLDivElement | null>;
24
+ isDragging: boolean;
25
+ }
26
+ /**
27
+ * Swipe-down-to-close for the mobile sheet. The drag writes the transform
28
+ * straight onto `sheetRef` — a React render per touchmove drops frames on a
29
+ * sheet full of tiles.
30
+ *
31
+ * The header (handle + title row, `touch-action: none`) drags with passive
32
+ * listeners. The content drags only when it sits at its top and the move goes
33
+ * down; anything else is left to native scrolling. Once the content has
34
+ * handed the gesture to the sheet, its touchmove calls `preventDefault` —
35
+ * the one non-passive listener — so the list does not scroll along.
36
+ *
37
+ * WebKit commits an unprevented first touchmove to native scrolling (the list
38
+ * rubber-bands at its top) and later moves are no longer cancelable, so the
39
+ * content claims the gesture on its FIRST move if that goes down steeply
40
+ * (dy >= 2·|dx|); the slop then only decides between drag and nothing. Whether the
41
+ * content may take over at all is settled at touchstart (list at its top, not
42
+ * inside a textarea, slider, horizontal or scrolled nested scroller): every other gesture
43
+ * returns from the non-passive touchmove at its first line. Passivity is fixed
44
+ * at registration and a listener added mid-gesture does not make that
45
+ * gesture's moves cancelable, so the one listener stays.
46
+ */
47
+ export declare function useMobileSheet({ isOpen, onClose, onDragClosed, closeKey, threshold, velocityThreshold, }: UseMobileSheetOptions): UseMobileSheetReturn;
48
+ export {};
@@ -0,0 +1,282 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ import { useState, useEffect, useRef } from 'react';
3
+ const SHEET_TRANSITION = 'transform 200ms var(--editor-ease-out)';
4
+ const SHEET_FADE = 'opacity 200ms var(--editor-ease-out)';
5
+ /** Movement before a touch counts as a drag, so taps (close button) stay taps. */
6
+ const DRAG_SLOP_PX = 6;
7
+ /** Release velocity is measured over the samples within this window. */
8
+ const VELOCITY_WINDOW_MS = 80;
9
+ const SAMPLE_COUNT = 16;
10
+ /** Upper bound for the 200 ms slide-out when `transitionend` never comes. */
11
+ const CLOSE_FALLBACK_MS = 350;
12
+ /**
13
+ * Swipe-down-to-close for the mobile sheet. The drag writes the transform
14
+ * straight onto `sheetRef` — a React render per touchmove drops frames on a
15
+ * sheet full of tiles.
16
+ *
17
+ * The header (handle + title row, `touch-action: none`) drags with passive
18
+ * listeners. The content drags only when it sits at its top and the move goes
19
+ * down; anything else is left to native scrolling. Once the content has
20
+ * handed the gesture to the sheet, its touchmove calls `preventDefault` —
21
+ * the one non-passive listener — so the list does not scroll along.
22
+ *
23
+ * WebKit commits an unprevented first touchmove to native scrolling (the list
24
+ * rubber-bands at its top) and later moves are no longer cancelable, so the
25
+ * content claims the gesture on its FIRST move if that goes down steeply
26
+ * (dy >= 2·|dx|); the slop then only decides between drag and nothing. Whether the
27
+ * content may take over at all is settled at touchstart (list at its top, not
28
+ * inside a textarea, slider, horizontal or scrolled nested scroller): every other gesture
29
+ * returns from the non-passive touchmove at its first line. Passivity is fixed
30
+ * at registration and a listener added mid-gesture does not make that
31
+ * gesture's moves cancelable, so the one listener stays.
32
+ */
33
+ export function useMobileSheet({ isOpen, onClose, onDragClosed, closeKey = null, threshold = 100, velocityThreshold = 0.5, }) {
34
+ const handleRef = useRef(null);
35
+ const sheetRef = useRef(null);
36
+ const contentRef = useRef(null);
37
+ const [isDragging, setIsDragging] = useState(false);
38
+ // Set while a drag-close slides out; aborts it and brings the sheet back.
39
+ const abortCloseRef = useRef(null);
40
+ const onCloseRef = useRef(onClose);
41
+ const onDragClosedRef = useRef(onDragClosed);
42
+ useEffect(() => {
43
+ onCloseRef.current = onClose;
44
+ onDragClosedRef.current = onDragClosed;
45
+ }, [onClose, onDragClosed]);
46
+ useEffect(() => {
47
+ const handle = handleRef.current;
48
+ const sheet = sheetRef.current;
49
+ if (!isOpen || !handle || !sheet)
50
+ return;
51
+ const content = contentRef.current;
52
+ // A reopened sheet must not keep a previous drag's inline styles.
53
+ sheet.style.transform = '';
54
+ sheet.style.transition = '';
55
+ sheet.style.opacity = '';
56
+ sheet.style.willChange = '';
57
+ // 'pending' until the touch moved past the slop; then the sheet drags, or
58
+ // (content only) the browser scrolls for the rest of the gesture.
59
+ let mode = 'idle';
60
+ let fromContent = false;
61
+ // Content only: the first move went down, so the browser must not scroll.
62
+ let claimed = false;
63
+ // The finger that owns the gesture; other fingers are ignored.
64
+ let activeId = 0;
65
+ let startScrollTop = 0;
66
+ let startX = 0;
67
+ let startY = 0;
68
+ let deltaY = 0;
69
+ // Ring buffer of the latest touch positions for the release velocity.
70
+ const samples = Array.from({ length: SAMPLE_COUNT }, () => ({ y: 0, t: 0 }));
71
+ let sampleIndex = 0;
72
+ let sampleCount = 0;
73
+ let closing = false;
74
+ let fallbackTimer = 0;
75
+ const record = (y) => {
76
+ const sample = samples[sampleIndex];
77
+ sample.y = y;
78
+ sample.t = Date.now();
79
+ sampleIndex = (sampleIndex + 1) % SAMPLE_COUNT;
80
+ sampleCount = Math.min(sampleCount + 1, SAMPLE_COUNT);
81
+ };
82
+ /** px/ms between the oldest and newest sample of the last 80 ms. */
83
+ const releaseVelocity = () => {
84
+ const now = Date.now();
85
+ let newest = null;
86
+ let oldest = null;
87
+ for (let i = 1; i <= sampleCount; i++) {
88
+ const sample = samples[(sampleIndex - i + SAMPLE_COUNT) % SAMPLE_COUNT];
89
+ if (now - sample.t > VELOCITY_WINDOW_MS)
90
+ break;
91
+ newest ??= sample;
92
+ oldest = sample;
93
+ }
94
+ if (!newest || !oldest || newest.t === oldest.t)
95
+ return 0;
96
+ return (newest.y - oldest.y) / (newest.t - oldest.t);
97
+ };
98
+ const reducedMotion = () => window.matchMedia('(prefers-reduced-motion: reduce)').matches;
99
+ const onTransitionEnd = (e) => {
100
+ if (e.target !== sheet)
101
+ return;
102
+ if (e.propertyName !== 'transform' && e.propertyName !== 'opacity')
103
+ return;
104
+ finishClose();
105
+ };
106
+ const finishClose = () => {
107
+ if (!closing)
108
+ return;
109
+ closing = false;
110
+ window.clearTimeout(fallbackTimer);
111
+ sheet.removeEventListener('transitionend', onTransitionEnd);
112
+ onDragClosedRef.current?.();
113
+ onCloseRef.current();
114
+ };
115
+ abortCloseRef.current = () => {
116
+ if (!closing)
117
+ return;
118
+ closing = false;
119
+ window.clearTimeout(fallbackTimer);
120
+ sheet.removeEventListener('transitionend', onTransitionEnd);
121
+ sheet.style.opacity = '';
122
+ snapBack();
123
+ };
124
+ const activeTouch = (list) => Array.from(list).find((t) => t.identifier === activeId) ?? null;
125
+ /** A horizontal scroller (chip/swatch row) pans sideways; claiming it would freeze it. */
126
+ const scrollsSideways = (el) => el.scrollWidth > el.clientWidth && /auto|scroll/.test(getComputedStyle(el).overflowX);
127
+ /**
128
+ * Touches the content must never claim: a textarea, a slider, a scrolled
129
+ * nested scroller, or a horizontal scroller between the touch and the content.
130
+ */
131
+ const startsInNestedScroll = (target) => {
132
+ for (let el = target instanceof Element ? target : null; el && el !== content;) {
133
+ if (el instanceof HTMLTextAreaElement ||
134
+ (el instanceof HTMLInputElement && el.type === 'range') ||
135
+ el.getAttribute('role') === 'slider' ||
136
+ el.scrollTop > 0 ||
137
+ scrollsSideways(el)) {
138
+ return true;
139
+ }
140
+ el = el.parentElement;
141
+ }
142
+ return false;
143
+ };
144
+ const start = (e, isContent) => {
145
+ // A second finger neither restarts nor ends the running gesture.
146
+ if (closing || mode !== 'idle' || e.touches.length > 1)
147
+ return;
148
+ const touch = e.touches[0];
149
+ activeId = touch.identifier;
150
+ fromContent = isContent;
151
+ claimed = false;
152
+ startScrollTop = isContent ? (content?.scrollTop ?? 0) : 0;
153
+ // Decided here, so a scrolling list's moves skip the handler at once.
154
+ mode =
155
+ isContent && (startScrollTop > 0 || startsInNestedScroll(e.target)) ? 'scroll' : 'pending';
156
+ startX = touch.clientX || 0;
157
+ startY = touch.clientY;
158
+ deltaY = 0;
159
+ sampleCount = 0;
160
+ record(startY);
161
+ };
162
+ const move = (e) => {
163
+ if (mode === 'idle' || mode === 'scroll')
164
+ return;
165
+ const touch = activeTouch(e.touches);
166
+ if (!touch)
167
+ return;
168
+ const dy = touch.clientY - startY;
169
+ record(touch.clientY);
170
+ if (mode === 'pending') {
171
+ const dx = (touch.clientX || 0) - startX;
172
+ if (fromContent && !claimed) {
173
+ if (dx === 0 && dy === 0)
174
+ return;
175
+ // First move: only a steep downward one claims it (a diagonal one may
176
+ // still turn into a sideways swipe); anything else scrolls.
177
+ if (dy < 2 * Math.abs(dx) || dy <= 0 || (content?.scrollTop ?? 0) > 0) {
178
+ mode = 'scroll';
179
+ return;
180
+ }
181
+ claimed = true;
182
+ }
183
+ if (claimed && e.cancelable)
184
+ e.preventDefault();
185
+ if (Math.max(Math.abs(dx), Math.abs(dy)) < DRAG_SLOP_PX)
186
+ return;
187
+ const scrolled = (content?.scrollTop ?? 0) > 0;
188
+ if (fromContent && (dy <= Math.abs(dx) || scrolled)) {
189
+ mode = 'scroll';
190
+ return;
191
+ }
192
+ if (dy <= 0)
193
+ return; // header: wait for a downward move
194
+ mode = 'drag';
195
+ sheet.style.transition = 'none';
196
+ sheet.style.willChange = 'transform';
197
+ setIsDragging(true);
198
+ }
199
+ if (fromContent && e.cancelable)
200
+ e.preventDefault();
201
+ deltaY = Math.max(0, dy);
202
+ sheet.style.transform = `translateY(${deltaY}px)`;
203
+ };
204
+ /** True if this touchend/cancel lifts the owning finger. */
205
+ const endsGesture = (e) => mode !== 'idle' && (e.touches.length === 0 || activeTouch(e.changedTouches) !== null);
206
+ /** Leaves drag mode; true if the sheet was being dragged. */
207
+ const release = () => {
208
+ const wasDragging = mode === 'drag';
209
+ mode = 'idle';
210
+ if (wasDragging) {
211
+ setIsDragging(false);
212
+ sheet.style.willChange = '';
213
+ }
214
+ return wasDragging;
215
+ };
216
+ const snapBack = () => {
217
+ sheet.style.transition = reducedMotion() ? 'none' : SHEET_TRANSITION;
218
+ sheet.style.transform = '';
219
+ };
220
+ // The system took the touch away (call, gesture, …): never a close.
221
+ const cancel = (e) => {
222
+ if (endsGesture(e) && release())
223
+ snapBack();
224
+ };
225
+ const end = (e) => {
226
+ if (!endsGesture(e) || !release())
227
+ return;
228
+ // A flick decides by itself; a long drag closes unless flicked back up.
229
+ const velocity = releaseVelocity();
230
+ const shouldClose = velocity > velocityThreshold || (deltaY > threshold && velocity >= -velocityThreshold);
231
+ if (!shouldClose) {
232
+ snapBack();
233
+ return;
234
+ }
235
+ // Slide on from where the finger let go; reduced motion fades in place.
236
+ closing = true;
237
+ sheet.addEventListener('transitionend', onTransitionEnd);
238
+ fallbackTimer = window.setTimeout(finishClose, CLOSE_FALLBACK_MS);
239
+ if (reducedMotion()) {
240
+ sheet.style.transition = SHEET_FADE;
241
+ sheet.style.opacity = '0';
242
+ }
243
+ else {
244
+ sheet.style.transition = SHEET_TRANSITION;
245
+ sheet.style.transform = 'translateY(100%)';
246
+ }
247
+ };
248
+ const onHandleStart = (e) => start(e, false);
249
+ const onContentStart = (e) => start(e, true);
250
+ handle.addEventListener('touchstart', onHandleStart, { passive: true });
251
+ handle.addEventListener('touchmove', move, { passive: true });
252
+ handle.addEventListener('touchend', end);
253
+ handle.addEventListener('touchcancel', cancel);
254
+ content?.addEventListener('touchstart', onContentStart, { passive: true });
255
+ content?.addEventListener('touchmove', move, { passive: false });
256
+ content?.addEventListener('touchend', end);
257
+ content?.addEventListener('touchcancel', cancel);
258
+ return () => {
259
+ abortCloseRef.current = null;
260
+ window.clearTimeout(fallbackTimer);
261
+ sheet.removeEventListener('transitionend', onTransitionEnd);
262
+ handle.removeEventListener('touchstart', onHandleStart);
263
+ handle.removeEventListener('touchmove', move);
264
+ handle.removeEventListener('touchend', end);
265
+ handle.removeEventListener('touchcancel', cancel);
266
+ content?.removeEventListener('touchstart', onContentStart);
267
+ content?.removeEventListener('touchmove', move);
268
+ content?.removeEventListener('touchend', end);
269
+ content?.removeEventListener('touchcancel', cancel);
270
+ };
271
+ }, [isOpen, threshold, velocityThreshold]);
272
+ // Another tab while the drag-close slides out: keep the sheet for it.
273
+ useEffect(() => {
274
+ abortCloseRef.current?.();
275
+ }, [closeKey]);
276
+ return {
277
+ handleRef,
278
+ sheetRef,
279
+ contentRef,
280
+ isDragging,
281
+ };
282
+ }
@@ -0,0 +1,17 @@
1
+ import { type FocusEvent, type KeyboardEvent } from 'react';
2
+ /** Knöpfe plus die Eingaben einer Leiste (Regler, Zahlenfeld, Auswahl). */
3
+ export declare const TOOLBAR_ITEMS_WITH_INPUTS = "button:not(:disabled), input:not(:disabled), select:not(:disabled)";
4
+ /**
5
+ * Roving tabindex for a horizontal `role="toolbar"` / `role="tablist"`: one Tab
6
+ * stop for the whole group, Left/Right/Home/End move between its items.
7
+ *
8
+ * Spread `{ ref, onKeyDown, onFocus }` onto the container. Items are found in
9
+ * the DOM (so conditional children just work) and the stop is re-applied after
10
+ * every render. The editor's global key handler leaves these keys alone on
11
+ * toolbars and tabs (`keyboardOwnership.ts`).
12
+ */
13
+ export declare function useRovingToolbar<T extends HTMLElement = HTMLDivElement>(itemSelector?: string): {
14
+ ref: import("react").RefObject<T | null>;
15
+ onKeyDown: (e: KeyboardEvent<T>) => void;
16
+ onFocus: (e: FocusEvent<T>) => void;
17
+ };
@@ -0,0 +1,76 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ import { useCallback, useEffect, useRef } from 'react';
3
+ const DEFAULT_ITEM_SELECTOR = 'button:not(:disabled)';
4
+ /** Knöpfe plus die Eingaben einer Leiste (Regler, Zahlenfeld, Auswahl). */
5
+ export const TOOLBAR_ITEMS_WITH_INPUTS = 'button:not(:disabled), input:not(:disabled), select:not(:disabled)';
6
+ // Regler, Textfeld und Auswahl brauchen die Pfeile selbst; von dort geht es mit Tab weiter (WAI-ARIA Toolbar).
7
+ const ownsArrows = (el) => el instanceof HTMLInputElement || el instanceof HTMLSelectElement;
8
+ /**
9
+ * Roving tabindex for a horizontal `role="toolbar"` / `role="tablist"`: one Tab
10
+ * stop for the whole group, Left/Right/Home/End move between its items.
11
+ *
12
+ * Spread `{ ref, onKeyDown, onFocus }` onto the container. Items are found in
13
+ * the DOM (so conditional children just work) and the stop is re-applied after
14
+ * every render. The editor's global key handler leaves these keys alone on
15
+ * toolbars and tabs (`keyboardOwnership.ts`).
16
+ */
17
+ export function useRovingToolbar(itemSelector = DEFAULT_ITEM_SELECTOR) {
18
+ const ref = useRef(null);
19
+ const current = useRef(null);
20
+ const getItems = useCallback(() => Array.from(ref.current?.querySelectorAll(itemSelector) ?? []), [itemSelector]);
21
+ const applyStop = useCallback(() => {
22
+ const items = getItems();
23
+ if (items.length === 0)
24
+ return;
25
+ const stop = (current.current && items.includes(current.current) ? current.current : null) ??
26
+ items.find((el) => el.getAttribute('aria-selected') === 'true') ??
27
+ items[0];
28
+ items.forEach((el) => {
29
+ el.tabIndex = el === stop ? 0 : -1;
30
+ });
31
+ }, [getItems]);
32
+ useEffect(() => {
33
+ applyStop();
34
+ });
35
+ const onFocus = useCallback((e) => {
36
+ const target = e.target;
37
+ if (!getItems().includes(target))
38
+ return;
39
+ current.current = target;
40
+ applyStop();
41
+ }, [getItems, applyStop]);
42
+ const onKeyDown = useCallback((e) => {
43
+ const items = getItems();
44
+ const target = e.target;
45
+ const index = items.indexOf(target);
46
+ if (index === -1)
47
+ return;
48
+ if (ownsArrows(target)) {
49
+ if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey)
50
+ return;
51
+ // Am Rand der Leiste verlässt Tab sie wie gewohnt.
52
+ const step = e.shiftKey ? index - 1 : index + 1;
53
+ if (step < 0 || step >= items.length)
54
+ return;
55
+ e.preventDefault();
56
+ items[step].focus();
57
+ return;
58
+ }
59
+ if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)
60
+ return;
61
+ let next;
62
+ if (e.key === 'ArrowRight')
63
+ next = (index + 1) % items.length;
64
+ else if (e.key === 'ArrowLeft')
65
+ next = (index - 1 + items.length) % items.length;
66
+ else if (e.key === 'Home')
67
+ next = 0;
68
+ else if (e.key === 'End')
69
+ next = items.length - 1;
70
+ else
71
+ return;
72
+ e.preventDefault();
73
+ items[next].focus();
74
+ }, [getItems]);
75
+ return { ref, onKeyDown, onFocus };
76
+ }
@@ -0,0 +1,11 @@
1
+ export { cn } from './cn.js';
2
+ export { CHROME_ROOT_ATTR, HIDDEN_SCROLLBAR, SIDEBAR_PANEL_ID } from './constants.js';
3
+ export { isFocusLost, isKeyboardModality } from './focus.js';
4
+ export { type EditorBox, EditorBoxProvider, useEditorBox, useEditorBoxRef, useMeasuredEditorBox, } from './hooks/editorBox.js';
5
+ export { CANVAS_MOBILE_QUERY, MOBILE_BREAKPOINT, useIsCanvasMobile, } from './hooks/useIsCanvasMobile.js';
6
+ export { useMobileSheet } from './hooks/useMobileSheet.js';
7
+ export { TOOLBAR_ITEMS_WITH_INPUTS, useRovingToolbar } from './hooks/useRovingToolbar.js';
8
+ export { SidebarPanel } from './SidebarPanel.js';
9
+ export { SidebarTabBar } from './SidebarTabBar.js';
10
+ export { type Subsection, SubsectionTabBar, type SubsectionTabBarProps, } from './SubsectionTabBar.js';
11
+ export { type SidebarPanelProps, type SidebarTab, type SidebarTabBarProps } from './types.js';
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ export { cn } from './cn.js';
3
+ export { CHROME_ROOT_ATTR, HIDDEN_SCROLLBAR, SIDEBAR_PANEL_ID } from './constants.js';
4
+ export { isFocusLost, isKeyboardModality } from './focus.js';
5
+ export { EditorBoxProvider, useEditorBox, useEditorBoxRef, useMeasuredEditorBox, } from './hooks/editorBox.js';
6
+ export { CANVAS_MOBILE_QUERY, MOBILE_BREAKPOINT, useIsCanvasMobile, } from './hooks/useIsCanvasMobile.js';
7
+ export { useMobileSheet } from './hooks/useMobileSheet.js';
8
+ export { TOOLBAR_ITEMS_WITH_INPUTS, useRovingToolbar } from './hooks/useRovingToolbar.js';
9
+ export { SidebarPanel } from './SidebarPanel.js';
10
+ export { SidebarTabBar } from './SidebarTabBar.js';
11
+ export { SubsectionTabBar, } from './SubsectionTabBar.js';
@@ -0,0 +1,77 @@
1
+ /* SPDX-License-Identifier: AGPL-3.0-only */
2
+ /**
3
+ * @ggraphic/editor-chrome — rules
4
+ *
5
+ * The parts of the chrome that utilities cannot say: the mobile sheet's slide and the thin
6
+ * scrollbar of the desktop panel. Reads the tokens of `tokens.css` (or the host's).
7
+ */
8
+
9
+ /* ── Mobile sheet: slides in from the bottom, its content fades in once the
10
+ slide is done, and it slides back out before it unmounts. The phase
11
+ lives in data-state (SidebarPanel); transitionend or a 350 ms fallback
12
+ moves it on. Only the mobile <section> carries data-state. ── */
13
+ .sidebar-panel[data-state] {
14
+ transition: transform 280ms var(--editor-ease-drawer);
15
+ }
16
+
17
+ @starting-style {
18
+ .sidebar-panel[data-state='entering'] {
19
+ transform: translateY(100%);
20
+ }
21
+ }
22
+
23
+ .sidebar-panel[data-state='closing'] {
24
+ transform: translateY(100%);
25
+ transition: transform 200ms var(--editor-ease-out);
26
+ }
27
+
28
+ .sidebar-panel__content--in {
29
+ animation: sheet-content-in 150ms var(--editor-ease-out) both;
30
+ }
31
+
32
+ @keyframes sheet-content-in {
33
+ from {
34
+ opacity: 0;
35
+ }
36
+ }
37
+
38
+ /* Reduced motion: the sheet fades instead of sliding; the content fade stays. */
39
+ @media (prefers-reduced-motion: reduce) {
40
+ .sidebar-panel[data-state] {
41
+ transition: opacity 150ms var(--editor-ease-out);
42
+ }
43
+
44
+ @starting-style {
45
+ .sidebar-panel[data-state='entering'] {
46
+ transform: none;
47
+ opacity: 0;
48
+ }
49
+ }
50
+
51
+ .sidebar-panel[data-state='closing'] {
52
+ transform: none;
53
+ opacity: 0;
54
+ transition: opacity 150ms var(--editor-ease-out);
55
+ }
56
+ }
57
+
58
+ /* ── Thin scrollbar: neutral colours from the tokens; a host with its own
59
+ palette re-declares these rules after the import. ── */
60
+ .scrollbar-thin {
61
+ scrollbar-width: thin;
62
+ scrollbar-color: var(--editor-border-strong) transparent;
63
+ }
64
+
65
+ .scrollbar-thin::-webkit-scrollbar {
66
+ width: 6px;
67
+ height: 6px;
68
+ }
69
+
70
+ .scrollbar-thin::-webkit-scrollbar-track {
71
+ background: transparent;
72
+ }
73
+
74
+ .scrollbar-thin::-webkit-scrollbar-thumb {
75
+ background-color: var(--editor-border-strong);
76
+ border-radius: 3px;
77
+ }
@@ -0,0 +1,87 @@
1
+ /* SPDX-License-Identifier: AGPL-3.0-only */
2
+ /**
3
+ * @ggraphic/editor-chrome — Tailwind v4 entry
4
+ *
5
+ * For hosts that build with Tailwind v4, after `@import 'tailwindcss'`:
6
+ *
7
+ * @import 'tailwindcss';
8
+ * @import '@ggraphic/editor-chrome/tokens.css';
9
+ * @import '@ggraphic/editor-chrome/styles.css';
10
+ * @import '@ggraphic/editor-chrome/tailwind.css';
11
+ *
12
+ * It scans the chrome for the classes it uses and adds what stock Tailwind does not have: the
13
+ * `touch-target` utility, the `kbd`, `max-canvas-mobile` and `canvas-mobile` variants and the
14
+ * subsection fade. A host with its own definitions of these names adds only the `@source`.
15
+ */
16
+
17
+ @source "../**/*.{js,jsx,ts,tsx}";
18
+
19
+ /* Trefferfläche auf 44px (WCAG 2.2 „Target Size") bringen, ohne die Optik
20
+ anzufassen: ein unsichtbares Pseudo-Element deckt die fehlenden Pixel ab.
21
+ Nur auf Zeigergeräten. Voraussetzung: kein Vorfahre mit `overflow: hidden`,
22
+ und das Element benutzt `::after` nicht schon selbst. */
23
+ @utility touch-target {
24
+ @media (pointer: coarse) {
25
+ position: relative;
26
+
27
+ &::after {
28
+ content: '';
29
+ position: absolute;
30
+ inset: 50%;
31
+ min-width: 44px;
32
+ min-height: 44px;
33
+ translate: -50% -50%;
34
+ }
35
+ }
36
+ }
37
+
38
+ /* `kbd:` applies only while the last input was a key (data-focus-modality is
39
+ set on <html> by the editor), so focus rings show for keyboard users only. */
40
+ @custom-variant kbd (&:where([data-focus-modality="keyboard"] *));
41
+
42
+ /* Mobile layout follows the editor's box: `CanvasEditorLayout` sets data-canvas-mobile on its root
43
+ while the root is narrower than 900px (`useIsCanvasMobile`). Portals sit outside the root and
44
+ fall back to the window; the root is never wider than the window, so inside it the media query
45
+ adds nothing. `canvas-mobile:` is the exact complement. */
46
+ @custom-variant max-canvas-mobile {
47
+ @media (max-width: 899px) {
48
+ @slot;
49
+ }
50
+ &:where([data-canvas-mobile], [data-canvas-mobile] *) {
51
+ @slot;
52
+ }
53
+ }
54
+ @custom-variant canvas-mobile {
55
+ @media (min-width: 900px) {
56
+ &:where(:not([data-canvas-mobile], [data-canvas-mobile] *)) {
57
+ @slot;
58
+ }
59
+ }
60
+ }
61
+
62
+ @theme {
63
+ --animate-subsection-fade-in: subsectionFadeIn 0.15s ease-out;
64
+ }
65
+
66
+ @keyframes subsectionFadeIn {
67
+ from {
68
+ opacity: 0;
69
+ transform: translateY(4px);
70
+ }
71
+ to {
72
+ opacity: 1;
73
+ transform: translateY(0);
74
+ }
75
+ }
76
+
77
+ /* Reduced motion: the fade stays, the movement goes. */
78
+ @media (prefers-reduced-motion: reduce) {
79
+ @keyframes subsectionFadeIn {
80
+ from {
81
+ opacity: 0;
82
+ }
83
+ to {
84
+ opacity: 1;
85
+ }
86
+ }
87
+ }
@@ -0,0 +1,58 @@
1
+ /* SPDX-License-Identifier: AGPL-3.0-only */
2
+ /**
3
+ * @ggraphic/editor-chrome — neutral token defaults
4
+ *
5
+ * The custom properties the chrome reads, with the same values as `@ggraphic/editor`'s
6
+ * `tokens.css` (a test in the editor keeps both equal). Defaults sit in `:where()`
7
+ * (specificity 0): a host value on `:root` or `[data-theme="dark"]` wins. A host that
8
+ * declares these tokens itself (or imports the editor's tokens) leaves this file out.
9
+ */
10
+
11
+ :where(:root) {
12
+ --editor-ease-out: cubic-bezier(0.23, 1, 0.32, 1);
13
+ --editor-ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
14
+ --editor-topbar-height: 56px;
15
+ --editor-surface: #ffffff;
16
+ --editor-surface-hover: #eeeeec;
17
+ --editor-border: #e7e7e5;
18
+ --editor-border-soft: #e2e2df;
19
+ --editor-border-strong: #d6d6d3;
20
+ --editor-tile: #f3f3f2;
21
+ --editor-text: #262626;
22
+ --editor-text-secondary: #4a4a48;
23
+ --editor-text-muted: #6a6a67;
24
+ --editor-accent: #2563eb;
25
+ --editor-active-bg: #dbeafe;
26
+ --editor-active-fg: #1d4ed8;
27
+ --image-studio-tab-bar-width: 76px;
28
+ }
29
+
30
+ @media (prefers-color-scheme: dark) {
31
+ :where(:root:not([data-theme='light'])) {
32
+ --editor-surface: #1e1e1e;
33
+ --editor-surface-hover: rgba(255, 255, 255, 0.06);
34
+ --editor-border: rgba(255, 255, 255, 0.08);
35
+ --editor-border-soft: rgba(255, 255, 255, 0.1);
36
+ --editor-border-strong: #656565;
37
+ --editor-tile: #464646;
38
+ --editor-text: #f0f0ee;
39
+ --editor-text-secondary: #bdbdbd;
40
+ --editor-text-muted: #b5b5b5;
41
+ --editor-active-bg: #1e3a8a;
42
+ --editor-active-fg: #93c5fd;
43
+ }
44
+ }
45
+
46
+ :where([data-theme='dark']) {
47
+ --editor-surface: #1e1e1e;
48
+ --editor-surface-hover: rgba(255, 255, 255, 0.06);
49
+ --editor-border: rgba(255, 255, 255, 0.08);
50
+ --editor-border-soft: rgba(255, 255, 255, 0.1);
51
+ --editor-border-strong: #656565;
52
+ --editor-tile: #464646;
53
+ --editor-text: #f0f0ee;
54
+ --editor-text-secondary: #bdbdbd;
55
+ --editor-text-muted: #b5b5b5;
56
+ --editor-active-bg: #1e3a8a;
57
+ --editor-active-fg: #93c5fd;
58
+ }