@open-slide/core 1.11.1 → 1.12.1
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/dist/{build-CtmQSpg-.js → build-L2yL1hTo.js} +1 -1
- package/dist/cli/bin.js +3 -3
- package/dist/{config-Bk2i4eJ1.js → config-OT4T-im0.js} +123 -4
- package/dist/{config-14qk4fP8.d.ts → config-x493taft.d.ts} +1 -1
- package/dist/{dev-DplvRqZx.js → dev-DJUpPCGT.js} +1 -1
- package/dist/{format-BvBmqbNW.js → format-7j0EzhuV.js} +28 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/locale/index.d.ts +1 -1
- package/dist/locale/index.js +1 -1
- package/dist/{preview-p4gcc8ip.js → preview-Bf8up6-P.js} +1 -1
- package/dist/{types-D_q_ylIe.d.ts → types-CHmFPIG_.d.ts} +6 -0
- package/dist/vite/index.d.ts +2 -2
- package/dist/vite/index.js +1 -1
- package/package.json +5 -5
- package/skills/slide-authoring/SKILL.md +20 -0
- package/src/app/components/inspector/inspector-panel.tsx +5 -1
- package/src/app/components/overview-grid.tsx +363 -0
- package/src/app/components/player.tsx +5 -2
- package/src/app/components/sidebar/sidebar-footer.tsx +57 -3
- package/src/app/components/slide-canvas.tsx +1 -0
- package/src/app/components/thumbnail-rail.tsx +37 -7
- package/src/app/lib/export-html.ts +1 -1
- package/src/app/lib/print-ready.test.ts +32 -0
- package/src/app/lib/print-ready.ts +4 -7
- package/src/app/routes/slide.tsx +198 -144
- package/src/locale/en.ts +6 -0
- package/src/locale/ja.ts +6 -0
- package/src/locale/types.ts +6 -0
- package/src/locale/zh-cn.ts +6 -0
- package/src/locale/zh-tw.ts +6 -0
- package/src/app/components/present/overview-grid.tsx +0 -177
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { ListOrdered, type LucideIcon, Sparkles, X } from 'lucide-react';
|
|
2
|
+
import { type Ref, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
|
4
|
+
import { format, useLocale } from '@/lib/use-locale';
|
|
5
|
+
import { cn } from '@/lib/utils';
|
|
6
|
+
import type { DesignSystem } from '../lib/design';
|
|
7
|
+
import { SlidePageProvider } from '../lib/page-context';
|
|
8
|
+
import type { Page } from '../lib/sdk';
|
|
9
|
+
import { CANVAS_HEIGHT, CANVAS_WIDTH } from '../lib/sdk';
|
|
10
|
+
import type { SlideTransition } from '../lib/transition';
|
|
11
|
+
import { SlideCanvas } from './slide-canvas';
|
|
12
|
+
|
|
13
|
+
const THUMB_W = 320;
|
|
14
|
+
const THUMB_H = (THUMB_W * CANVAS_HEIGHT) / CANVAS_WIDTH;
|
|
15
|
+
|
|
16
|
+
export type OverviewVariant = 'present' | 'editor';
|
|
17
|
+
|
|
18
|
+
type Props = {
|
|
19
|
+
pages: Page[];
|
|
20
|
+
design?: DesignSystem;
|
|
21
|
+
open: boolean;
|
|
22
|
+
current: number;
|
|
23
|
+
onClose: () => void;
|
|
24
|
+
onSelect: (index: number) => void;
|
|
25
|
+
variant?: OverviewVariant;
|
|
26
|
+
moduleTransition?: SlideTransition;
|
|
27
|
+
tooltipContainer?: HTMLElement | null;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export function OverviewGrid({
|
|
31
|
+
pages,
|
|
32
|
+
design,
|
|
33
|
+
open,
|
|
34
|
+
current,
|
|
35
|
+
onClose,
|
|
36
|
+
onSelect,
|
|
37
|
+
variant = 'present',
|
|
38
|
+
moduleTransition,
|
|
39
|
+
tooltipContainer,
|
|
40
|
+
}: Props) {
|
|
41
|
+
const [focused, setFocused] = useState(current);
|
|
42
|
+
const gridRef = useRef<HTMLDivElement>(null);
|
|
43
|
+
const focusedRef = useRef<HTMLButtonElement | null>(null);
|
|
44
|
+
const t = useLocale();
|
|
45
|
+
|
|
46
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: only re-sync on open transition
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (open) setFocused(current);
|
|
49
|
+
}, [open]);
|
|
50
|
+
|
|
51
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: `focused` swaps which button holds the ref; we must re-run to focus the new node
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (!open) return;
|
|
54
|
+
focusedRef.current?.focus();
|
|
55
|
+
focusedRef.current?.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
|
|
56
|
+
}, [focused, open]);
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (!open) return;
|
|
60
|
+
const onKey = (e: KeyboardEvent) => {
|
|
61
|
+
if (e.target instanceof HTMLElement && e.target.matches('input, textarea')) return;
|
|
62
|
+
const cols = computeCols(gridRef.current);
|
|
63
|
+
if (e.key === 'ArrowRight') {
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
e.stopPropagation();
|
|
66
|
+
setFocused((i) => Math.min(pages.length - 1, i + 1));
|
|
67
|
+
} else if (e.key === 'ArrowLeft') {
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
e.stopPropagation();
|
|
70
|
+
setFocused((i) => Math.max(0, i - 1));
|
|
71
|
+
} else if (e.key === 'ArrowDown') {
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
e.stopPropagation();
|
|
74
|
+
setFocused((i) => Math.min(pages.length - 1, i + cols));
|
|
75
|
+
} else if (e.key === 'ArrowUp') {
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
e.stopPropagation();
|
|
78
|
+
setFocused((i) => Math.max(0, i - cols));
|
|
79
|
+
} else if (e.key === 'Home') {
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
e.stopPropagation();
|
|
82
|
+
setFocused(0);
|
|
83
|
+
} else if (e.key === 'End') {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
e.stopPropagation();
|
|
86
|
+
setFocused(pages.length - 1);
|
|
87
|
+
} else if (e.key === 'Enter') {
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
e.stopPropagation();
|
|
90
|
+
onSelect(focused);
|
|
91
|
+
onClose();
|
|
92
|
+
} else if (e.key === 'Escape') {
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
e.stopPropagation();
|
|
95
|
+
onClose();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
window.addEventListener('keydown', onKey, true);
|
|
99
|
+
return () => window.removeEventListener('keydown', onKey, true);
|
|
100
|
+
}, [open, pages.length, focused, onClose, onSelect]);
|
|
101
|
+
|
|
102
|
+
if (!open) return null;
|
|
103
|
+
|
|
104
|
+
const styles = variant === 'present' ? presentStyles : editorStyles;
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<div
|
|
108
|
+
role="dialog"
|
|
109
|
+
aria-modal="true"
|
|
110
|
+
aria-label={t.present.overviewDialogAria}
|
|
111
|
+
className={cn('absolute inset-0 z-50 flex flex-col backdrop-blur-sm', styles.surface)}
|
|
112
|
+
>
|
|
113
|
+
<div className="flex shrink-0 items-center justify-between px-8 pt-6 pb-3">
|
|
114
|
+
<span className={cn('eyebrow', styles.eyebrow)}>{t.present.overviewEyebrow}</span>
|
|
115
|
+
<div className="flex items-center gap-3">
|
|
116
|
+
<span className={cn('font-mono text-[11px] tabular-nums', styles.eyebrow)}>
|
|
117
|
+
{(focused + 1).toString().padStart(2, '0')} · {pages.length.toString().padStart(2, '0')}
|
|
118
|
+
</span>
|
|
119
|
+
<button
|
|
120
|
+
type="button"
|
|
121
|
+
onClick={onClose}
|
|
122
|
+
aria-label={t.common.close}
|
|
123
|
+
className={cn(
|
|
124
|
+
'flex size-6 items-center justify-center rounded-[4px] outline-none transition-colors',
|
|
125
|
+
styles.closeButton,
|
|
126
|
+
)}
|
|
127
|
+
>
|
|
128
|
+
<X className="size-3.5" />
|
|
129
|
+
</button>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
<div ref={gridRef} className="min-h-0 flex-1 overflow-auto px-8 pb-8">
|
|
133
|
+
<TooltipProvider delayDuration={200}>
|
|
134
|
+
<div
|
|
135
|
+
className="grid justify-center gap-5"
|
|
136
|
+
style={{
|
|
137
|
+
gridTemplateColumns: `repeat(auto-fill, ${THUMB_W}px)`,
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
{pages.map((PageComp, i) => {
|
|
141
|
+
const isFocused = i === focused;
|
|
142
|
+
const isCurrent = i === current;
|
|
143
|
+
return (
|
|
144
|
+
<OverviewThumb
|
|
145
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: pages list is render-stable
|
|
146
|
+
key={i}
|
|
147
|
+
buttonRef={isFocused ? focusedRef : undefined}
|
|
148
|
+
page={PageComp}
|
|
149
|
+
index={i}
|
|
150
|
+
total={pages.length}
|
|
151
|
+
design={design}
|
|
152
|
+
isFocused={isFocused}
|
|
153
|
+
isCurrent={isCurrent}
|
|
154
|
+
styles={styles}
|
|
155
|
+
moduleTransition={moduleTransition}
|
|
156
|
+
tooltipContainer={tooltipContainer}
|
|
157
|
+
onFocus={() => setFocused(i)}
|
|
158
|
+
onSelect={() => {
|
|
159
|
+
onSelect(i);
|
|
160
|
+
onClose();
|
|
161
|
+
}}
|
|
162
|
+
/>
|
|
163
|
+
);
|
|
164
|
+
})}
|
|
165
|
+
</div>
|
|
166
|
+
</TooltipProvider>
|
|
167
|
+
</div>
|
|
168
|
+
</div>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function OverviewThumb({
|
|
173
|
+
page: PageComp,
|
|
174
|
+
index,
|
|
175
|
+
total,
|
|
176
|
+
design,
|
|
177
|
+
isFocused,
|
|
178
|
+
isCurrent,
|
|
179
|
+
styles,
|
|
180
|
+
moduleTransition,
|
|
181
|
+
tooltipContainer,
|
|
182
|
+
onFocus,
|
|
183
|
+
onSelect,
|
|
184
|
+
buttonRef,
|
|
185
|
+
}: {
|
|
186
|
+
page: Page;
|
|
187
|
+
index: number;
|
|
188
|
+
total: number;
|
|
189
|
+
design?: DesignSystem;
|
|
190
|
+
isFocused: boolean;
|
|
191
|
+
isCurrent: boolean;
|
|
192
|
+
styles: OverviewStyles;
|
|
193
|
+
moduleTransition?: SlideTransition;
|
|
194
|
+
tooltipContainer?: HTMLElement | null;
|
|
195
|
+
onFocus: () => void;
|
|
196
|
+
onSelect: () => void;
|
|
197
|
+
buttonRef?: Ref<HTMLButtonElement>;
|
|
198
|
+
}) {
|
|
199
|
+
const t = useLocale();
|
|
200
|
+
const boxRef = useRef<HTMLDivElement | null>(null);
|
|
201
|
+
const [hasSteps, setHasSteps] = useState(false);
|
|
202
|
+
const hasTransition = Boolean(PageComp.transition ?? moduleTransition);
|
|
203
|
+
|
|
204
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: re-detect when the page at this slot changes
|
|
205
|
+
useEffect(() => {
|
|
206
|
+
setHasSteps(boxRef.current?.querySelector('[data-osd-step]') != null);
|
|
207
|
+
}, [PageComp]);
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<button
|
|
211
|
+
ref={buttonRef}
|
|
212
|
+
type="button"
|
|
213
|
+
onClick={onSelect}
|
|
214
|
+
onMouseEnter={onFocus}
|
|
215
|
+
onFocus={onFocus}
|
|
216
|
+
aria-label={format(t.present.overviewGoToAria, { n: index + 1 })}
|
|
217
|
+
aria-current={isCurrent ? 'true' : undefined}
|
|
218
|
+
className={cn(
|
|
219
|
+
'group/thumb flex flex-col items-start gap-2 rounded-[6px] p-1.5 outline-none transition-colors',
|
|
220
|
+
isFocused ? styles.thumbFocused : styles.thumbHover,
|
|
221
|
+
)}
|
|
222
|
+
>
|
|
223
|
+
<div
|
|
224
|
+
ref={boxRef}
|
|
225
|
+
className={cn(
|
|
226
|
+
'relative w-full overflow-hidden rounded-[4px] ring-1 transition-shadow',
|
|
227
|
+
styles.thumbSurface,
|
|
228
|
+
isFocused ? 'ring-2 ring-[var(--brand,#ef4444)]' : styles.thumbRing,
|
|
229
|
+
)}
|
|
230
|
+
style={{ height: THUMB_H }}
|
|
231
|
+
>
|
|
232
|
+
<SlideCanvas
|
|
233
|
+
scale={THUMB_W / CANVAS_WIDTH}
|
|
234
|
+
center={false}
|
|
235
|
+
flat
|
|
236
|
+
freezeMotion
|
|
237
|
+
design={design}
|
|
238
|
+
>
|
|
239
|
+
<SlidePageProvider index={index} total={total}>
|
|
240
|
+
<PageComp />
|
|
241
|
+
</SlidePageProvider>
|
|
242
|
+
</SlideCanvas>
|
|
243
|
+
{isCurrent && (
|
|
244
|
+
<span
|
|
245
|
+
aria-hidden
|
|
246
|
+
className="pointer-events-none absolute top-1.5 right-1.5 rounded-[3px] bg-[var(--brand,#ef4444)] px-1.5 py-0.5 font-mono text-[9.5px] tracking-[0.06em] uppercase text-white"
|
|
247
|
+
>
|
|
248
|
+
{t.present.nowBadge}
|
|
249
|
+
</span>
|
|
250
|
+
)}
|
|
251
|
+
</div>
|
|
252
|
+
<div className="flex h-4 w-full items-center justify-between gap-2">
|
|
253
|
+
<span
|
|
254
|
+
className={cn(
|
|
255
|
+
'font-mono text-[10.5px] tracking-[0.08em] tabular-nums uppercase',
|
|
256
|
+
isFocused || isCurrent ? styles.labelActive : styles.labelMuted,
|
|
257
|
+
)}
|
|
258
|
+
>
|
|
259
|
+
{(index + 1).toString().padStart(2, '0')}
|
|
260
|
+
</span>
|
|
261
|
+
{(hasTransition || hasSteps) && (
|
|
262
|
+
<span className="flex items-center gap-1">
|
|
263
|
+
{hasTransition && (
|
|
264
|
+
<OverviewIndicator
|
|
265
|
+
icon={Sparkles}
|
|
266
|
+
label={t.thumbnailRail.transitionIndicator}
|
|
267
|
+
className={styles.indicator}
|
|
268
|
+
tooltipContainer={tooltipContainer}
|
|
269
|
+
/>
|
|
270
|
+
)}
|
|
271
|
+
{hasSteps && (
|
|
272
|
+
<OverviewIndicator
|
|
273
|
+
icon={ListOrdered}
|
|
274
|
+
label={t.thumbnailRail.stepsIndicator}
|
|
275
|
+
className={styles.indicator}
|
|
276
|
+
tooltipContainer={tooltipContainer}
|
|
277
|
+
/>
|
|
278
|
+
)}
|
|
279
|
+
</span>
|
|
280
|
+
)}
|
|
281
|
+
</div>
|
|
282
|
+
</button>
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function OverviewIndicator({
|
|
287
|
+
icon: Icon,
|
|
288
|
+
label,
|
|
289
|
+
className,
|
|
290
|
+
tooltipContainer,
|
|
291
|
+
}: {
|
|
292
|
+
icon: LucideIcon;
|
|
293
|
+
label: string;
|
|
294
|
+
className: string;
|
|
295
|
+
tooltipContainer?: HTMLElement | null;
|
|
296
|
+
}) {
|
|
297
|
+
return (
|
|
298
|
+
<Tooltip>
|
|
299
|
+
<TooltipTrigger asChild>
|
|
300
|
+
<span
|
|
301
|
+
role="img"
|
|
302
|
+
aria-label={label}
|
|
303
|
+
className={cn('flex size-4 items-center justify-center', className)}
|
|
304
|
+
>
|
|
305
|
+
<Icon className="size-3.5" strokeWidth={1.9} />
|
|
306
|
+
</span>
|
|
307
|
+
</TooltipTrigger>
|
|
308
|
+
<TooltipContent side="top" sideOffset={6} container={tooltipContainer ?? undefined}>
|
|
309
|
+
{label}
|
|
310
|
+
</TooltipContent>
|
|
311
|
+
</Tooltip>
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
type OverviewStyles = {
|
|
316
|
+
surface: string;
|
|
317
|
+
eyebrow: string;
|
|
318
|
+
thumbFocused: string;
|
|
319
|
+
thumbHover: string;
|
|
320
|
+
thumbSurface: string;
|
|
321
|
+
thumbRing: string;
|
|
322
|
+
labelActive: string;
|
|
323
|
+
labelMuted: string;
|
|
324
|
+
indicator: string;
|
|
325
|
+
closeButton: string;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const presentStyles = {
|
|
329
|
+
surface: 'bg-black/95',
|
|
330
|
+
eyebrow: 'text-white/55',
|
|
331
|
+
thumbFocused: 'bg-white/10',
|
|
332
|
+
thumbHover: 'hover:bg-white/5',
|
|
333
|
+
thumbSurface: 'bg-black',
|
|
334
|
+
thumbRing: 'ring-white/10',
|
|
335
|
+
labelActive: 'text-white/85',
|
|
336
|
+
labelMuted: 'text-white/45',
|
|
337
|
+
indicator: 'text-white/45 transition-colors group-hover/thumb:text-white/75',
|
|
338
|
+
closeButton:
|
|
339
|
+
'text-white/55 hover:bg-white/10 hover:text-white focus-visible:ring-2 focus-visible:ring-white/40',
|
|
340
|
+
} as const;
|
|
341
|
+
|
|
342
|
+
const editorStyles = {
|
|
343
|
+
surface: 'bg-background/95',
|
|
344
|
+
eyebrow: 'text-muted-foreground',
|
|
345
|
+
thumbFocused: 'bg-muted',
|
|
346
|
+
thumbHover: 'hover:bg-muted/60',
|
|
347
|
+
thumbSurface: 'bg-card',
|
|
348
|
+
thumbRing: 'ring-hairline',
|
|
349
|
+
labelActive: 'text-foreground',
|
|
350
|
+
labelMuted: 'text-muted-foreground/60',
|
|
351
|
+
indicator: 'text-muted-foreground/60 transition-colors group-hover/thumb:text-muted-foreground',
|
|
352
|
+
closeButton:
|
|
353
|
+
'text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring',
|
|
354
|
+
} as const;
|
|
355
|
+
|
|
356
|
+
function computeCols(grid: HTMLDivElement | null) {
|
|
357
|
+
if (!grid) return 4;
|
|
358
|
+
const inner = grid.firstElementChild as HTMLElement | null;
|
|
359
|
+
if (!inner) return 4;
|
|
360
|
+
const cs = getComputedStyle(inner);
|
|
361
|
+
const cols = cs.gridTemplateColumns.split(' ').filter(Boolean).length;
|
|
362
|
+
return Math.max(1, cols);
|
|
363
|
+
}
|
|
@@ -7,12 +7,12 @@ import type { Page } from '../lib/sdk';
|
|
|
7
7
|
import type { EntryDirection, StepAggregate, StepController } from '../lib/step-context';
|
|
8
8
|
import type { SlideTransition } from '../lib/transition';
|
|
9
9
|
import { usePrefersReducedMotion } from '../lib/use-prefers-reduced-motion';
|
|
10
|
+
import { OverviewGrid } from './overview-grid';
|
|
10
11
|
import { PresentBlackoutOverlay } from './present/blackout-overlay';
|
|
11
12
|
import { PresentControlBar } from './present/control-bar';
|
|
12
13
|
import { PresentHelpOverlay } from './present/help-overlay';
|
|
13
14
|
import { PresentJumpInput } from './present/jump-input';
|
|
14
15
|
import { PresentLaserPointer } from './present/laser-pointer';
|
|
15
|
-
import { PresentOverviewGrid } from './present/overview-grid';
|
|
16
16
|
import { PresentProgressBar } from './present/progress-bar';
|
|
17
17
|
import { useIdle } from './present/use-idle';
|
|
18
18
|
import { usePointerNearBottom } from './present/use-pointer-near-bottom';
|
|
@@ -380,13 +380,16 @@ export function Player({
|
|
|
380
380
|
onHelp={() => setHelpOpen(true)}
|
|
381
381
|
onExit={onExit}
|
|
382
382
|
/>
|
|
383
|
-
<
|
|
383
|
+
<OverviewGrid
|
|
384
384
|
pages={pages}
|
|
385
385
|
design={design}
|
|
386
386
|
open={overviewOpen}
|
|
387
387
|
current={index}
|
|
388
388
|
onClose={() => setOverviewOpen(false)}
|
|
389
389
|
onSelect={handleIndexChange}
|
|
390
|
+
variant="present"
|
|
391
|
+
moduleTransition={transition}
|
|
392
|
+
tooltipContainer={rootEl}
|
|
390
393
|
/>
|
|
391
394
|
<PresentHelpOverlay open={helpOpen} onOpenChange={setHelpOpen} container={rootEl} />
|
|
392
395
|
</div>
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import config from 'virtual:open-slide/config';
|
|
2
|
+
import { Loader2, RefreshCw } from 'lucide-react';
|
|
2
3
|
import { useEffect, useState } from 'react';
|
|
4
|
+
import { toast } from 'sonner';
|
|
5
|
+
import { Button } from '@/components/ui/button';
|
|
3
6
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
|
4
7
|
import { format, useLocale } from '@/lib/use-locale';
|
|
5
8
|
|
|
6
9
|
type UpdateCheck = { current: string; latest: string | null; outdated: boolean };
|
|
10
|
+
type UpdateStatus = 'idle' | 'running' | 'done' | 'error';
|
|
7
11
|
|
|
8
12
|
export function SidebarFooter() {
|
|
9
13
|
const t = useLocale();
|
|
10
14
|
const [update, setUpdate] = useState<UpdateCheck | null>(null);
|
|
15
|
+
const [updateStatus, setUpdateStatus] = useState<UpdateStatus>('idle');
|
|
11
16
|
|
|
12
17
|
useEffect(() => {
|
|
13
18
|
if (!import.meta.env.DEV) return;
|
|
@@ -24,9 +29,24 @@ export function SidebarFooter() {
|
|
|
24
29
|
}, []);
|
|
25
30
|
|
|
26
31
|
const label = `v${config.version}`;
|
|
32
|
+
const isUpdating = updateStatus === 'running';
|
|
33
|
+
|
|
34
|
+
async function updatePackage() {
|
|
35
|
+
if (isUpdating) return;
|
|
36
|
+
setUpdateStatus('running');
|
|
37
|
+
try {
|
|
38
|
+
const res = await fetch('/__update-package', { method: 'POST' });
|
|
39
|
+
if (!res.ok) throw new Error('update failed');
|
|
40
|
+
setUpdateStatus('done');
|
|
41
|
+
toast.success(t.home.updatePackageDone);
|
|
42
|
+
} catch {
|
|
43
|
+
setUpdateStatus('error');
|
|
44
|
+
toast.error(t.home.updatePackageFailed);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
27
47
|
|
|
28
48
|
const versionRow = (
|
|
29
|
-
<span className="inline-flex items-center gap-1.5">
|
|
49
|
+
<span className="inline-flex cursor-default items-center gap-1.5">
|
|
30
50
|
{update?.latest && <span className="size-1.5 rounded-full bg-brand" aria-hidden />}
|
|
31
51
|
{label}
|
|
32
52
|
</span>
|
|
@@ -38,8 +58,42 @@ export function SidebarFooter() {
|
|
|
38
58
|
<TooltipProvider delayDuration={200}>
|
|
39
59
|
<Tooltip>
|
|
40
60
|
<TooltipTrigger asChild>{versionRow}</TooltipTrigger>
|
|
41
|
-
<TooltipContent
|
|
42
|
-
|
|
61
|
+
<TooltipContent
|
|
62
|
+
side="top"
|
|
63
|
+
align="start"
|
|
64
|
+
alignOffset={-8}
|
|
65
|
+
sideOffset={9}
|
|
66
|
+
collisionPadding={12}
|
|
67
|
+
className="flex w-[232px] max-w-[calc(100vw-24px)] flex-col gap-2.5 rounded-[8px] border border-background/10 bg-foreground/95 p-2.5 text-[11.5px] leading-4 shadow-[0_12px_32px_oklch(0_0_0/0.28)] backdrop-blur"
|
|
68
|
+
>
|
|
69
|
+
<span className="pr-1 text-background/92">
|
|
70
|
+
{format(t.home.updateAvailable, { version: update.latest })}
|
|
71
|
+
</span>
|
|
72
|
+
<Button
|
|
73
|
+
type="button"
|
|
74
|
+
size="xs"
|
|
75
|
+
variant="secondary"
|
|
76
|
+
className="h-6 w-fit rounded-[5px] border border-background/15 bg-background/8 px-2 text-[11px] text-background shadow-none hover:bg-background/14"
|
|
77
|
+
disabled={isUpdating || updateStatus === 'done'}
|
|
78
|
+
onClick={updatePackage}
|
|
79
|
+
>
|
|
80
|
+
{isUpdating ? (
|
|
81
|
+
<Loader2 className="animate-spin" aria-hidden />
|
|
82
|
+
) : (
|
|
83
|
+
<RefreshCw aria-hidden />
|
|
84
|
+
)}
|
|
85
|
+
{isUpdating ? t.home.updatingPackage : t.home.updatePackage}
|
|
86
|
+
</Button>
|
|
87
|
+
{updateStatus === 'done' && (
|
|
88
|
+
<span className="text-[11px] leading-4 text-background/65">
|
|
89
|
+
{t.home.updatePackageDone}
|
|
90
|
+
</span>
|
|
91
|
+
)}
|
|
92
|
+
{updateStatus === 'error' && (
|
|
93
|
+
<span className="text-[11px] leading-4 text-background/65">
|
|
94
|
+
{t.home.updatePackageFailed}
|
|
95
|
+
</span>
|
|
96
|
+
)}
|
|
43
97
|
</TooltipContent>
|
|
44
98
|
</Tooltip>
|
|
45
99
|
</TooltipProvider>
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
verticalListSortingStrategy,
|
|
16
16
|
} from '@dnd-kit/sortable';
|
|
17
17
|
import { CSS } from '@dnd-kit/utilities';
|
|
18
|
-
import { Copy, ListOrdered, type LucideIcon, Sparkles, Trash2 } from 'lucide-react';
|
|
18
|
+
import { Copy, Grid2x2, ListOrdered, type LucideIcon, Sparkles, Trash2 } from 'lucide-react';
|
|
19
19
|
import { Fragment, useEffect, useRef, useState } from 'react';
|
|
20
20
|
import {
|
|
21
21
|
ContextMenu,
|
|
@@ -54,6 +54,8 @@ type Props = {
|
|
|
54
54
|
width?: number;
|
|
55
55
|
/** Deck-level transition default; used to flag pages that inherit a transition. */
|
|
56
56
|
moduleTransition?: SlideTransition;
|
|
57
|
+
/** When provided, the vertical rail header renders a button that opens the overview grid. */
|
|
58
|
+
onOverview?: () => void;
|
|
57
59
|
};
|
|
58
60
|
|
|
59
61
|
const DEFAULT_VERTICAL_THUMB_WIDTH = 184;
|
|
@@ -71,6 +73,7 @@ export function ThumbnailRail({
|
|
|
71
73
|
orientation = 'vertical',
|
|
72
74
|
width,
|
|
73
75
|
moduleTransition,
|
|
76
|
+
onOverview,
|
|
74
77
|
}: Props) {
|
|
75
78
|
const activeRef = useRef<HTMLButtonElement | null>(null);
|
|
76
79
|
const t = useLocale();
|
|
@@ -214,10 +217,35 @@ export function ThumbnailRail({
|
|
|
214
217
|
};
|
|
215
218
|
|
|
216
219
|
const list = (
|
|
217
|
-
<aside className="flex flex-col gap-2 px-3
|
|
218
|
-
<div className="
|
|
219
|
-
<
|
|
220
|
-
|
|
220
|
+
<aside className="flex flex-col gap-2 px-3 pb-3">
|
|
221
|
+
<div className="-mx-3 sticky top-0 z-10 bg-sidebar px-4 pt-3 pb-1">
|
|
222
|
+
<div className="flex items-center justify-between gap-2">
|
|
223
|
+
<span className="eyebrow">{t.thumbnailRail.pages}</span>
|
|
224
|
+
<div className="flex items-center gap-1.5">
|
|
225
|
+
<span className="folio">{pages.length.toString().padStart(2, '0')}</span>
|
|
226
|
+
{onOverview && (
|
|
227
|
+
<Tooltip>
|
|
228
|
+
<TooltipTrigger asChild>
|
|
229
|
+
<button
|
|
230
|
+
type="button"
|
|
231
|
+
onClick={onOverview}
|
|
232
|
+
aria-label={t.thumbnailRail.overviewAria}
|
|
233
|
+
className={cn(
|
|
234
|
+
'flex size-5 items-center justify-center rounded-[3px] text-muted-foreground/70 outline-none',
|
|
235
|
+
'motion-safe:transition-colors hover:bg-muted hover:text-foreground',
|
|
236
|
+
'focus-visible:ring-1 focus-visible:ring-brand',
|
|
237
|
+
)}
|
|
238
|
+
>
|
|
239
|
+
<Grid2x2 className="size-3.5" strokeWidth={1.75} />
|
|
240
|
+
</button>
|
|
241
|
+
</TooltipTrigger>
|
|
242
|
+
<TooltipContent side="bottom" sideOffset={6}>
|
|
243
|
+
{t.thumbnailRail.overviewAria}
|
|
244
|
+
</TooltipContent>
|
|
245
|
+
</Tooltip>
|
|
246
|
+
)}
|
|
247
|
+
</div>
|
|
248
|
+
</div>
|
|
221
249
|
</div>
|
|
222
250
|
{pages.map(renderThumb)}
|
|
223
251
|
</aside>
|
|
@@ -226,14 +254,16 @@ export function ThumbnailRail({
|
|
|
226
254
|
if (!onReorder) {
|
|
227
255
|
return (
|
|
228
256
|
<TooltipProvider delayDuration={200}>
|
|
229
|
-
<ScrollArea className="h-full border-r border-hairline bg-sidebar">
|
|
257
|
+
<ScrollArea className="h-full border-r border-hairline bg-sidebar [&_[data-slot=scroll-area-scrollbar]]:z-20">
|
|
258
|
+
{list}
|
|
259
|
+
</ScrollArea>
|
|
230
260
|
</TooltipProvider>
|
|
231
261
|
);
|
|
232
262
|
}
|
|
233
263
|
|
|
234
264
|
return (
|
|
235
265
|
<TooltipProvider delayDuration={200}>
|
|
236
|
-
<ScrollArea className="h-full border-r border-hairline bg-sidebar">
|
|
266
|
+
<ScrollArea className="h-full border-r border-hairline bg-sidebar [&_[data-slot=scroll-area-scrollbar]]:z-20">
|
|
237
267
|
<SortableRail pages={pages} onReorder={onReorder} onSelect={onSelect}>
|
|
238
268
|
{list}
|
|
239
269
|
</SortableRail>
|
|
@@ -260,7 +260,7 @@ ${opts.externalLinks}
|
|
|
260
260
|
<style>
|
|
261
261
|
html, body { margin: 0; height: 100%; background: #000; overflow: hidden; font-family: system-ui, sans-serif; }
|
|
262
262
|
.os-stage { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
|
|
263
|
-
.os-frame { width: 1920px; height: 1080px; background: #fff; color: #000; transform-origin: center center; overflow: hidden; position: relative; }
|
|
263
|
+
.os-frame { width: 1920px; height: 1080px; flex-shrink: 0; background: #fff; color: #000; transform-origin: center center; overflow: hidden; position: relative; }
|
|
264
264
|
.os-page { position: absolute; inset: 0; }
|
|
265
265
|
.os-page[hidden] { display: none !important; }
|
|
266
266
|
.os-counter { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); color: #fff; background: rgba(0,0,0,.5); padding: 2px 10px; border-radius: 999px; font-size: 12px; z-index: 10; font-variant-numeric: tabular-nums; }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { waitForFonts } from './print-ready';
|
|
3
|
+
|
|
4
|
+
afterEach(() => {
|
|
5
|
+
vi.unstubAllGlobals();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
describe('waitForFonts', () => {
|
|
9
|
+
it('awaits document.fonts.ready without force-loading any face', async () => {
|
|
10
|
+
const load = vi.fn();
|
|
11
|
+
const faces = [
|
|
12
|
+
{ status: 'loaded', load },
|
|
13
|
+
{ status: 'unloaded', load },
|
|
14
|
+
{ status: 'unloaded', load },
|
|
15
|
+
];
|
|
16
|
+
const fonts = {
|
|
17
|
+
ready: Promise.resolve(),
|
|
18
|
+
[Symbol.iterator]: () => faces[Symbol.iterator](),
|
|
19
|
+
};
|
|
20
|
+
vi.stubGlobal('document', { fonts });
|
|
21
|
+
|
|
22
|
+
await waitForFonts();
|
|
23
|
+
|
|
24
|
+
expect(load).not.toHaveBeenCalled();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('resolves when the FontFaceSet API is unavailable', async () => {
|
|
28
|
+
vi.stubGlobal('document', {});
|
|
29
|
+
|
|
30
|
+
await expect(waitForFonts()).resolves.toBeUndefined();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
const DEFAULT_WAITFOR_TIMEOUT_MS = 10_000;
|
|
2
2
|
|
|
3
|
+
// `document.fonts.ready` already waits for every in-flight face. Never call
|
|
4
|
+
// `face.load()` on the rest: unloaded faces were never requested by CSS, and
|
|
5
|
+
// `load()` ignores `unicode-range`, so a subsetted CJK family (hundreds of
|
|
6
|
+
// faces) would be force-downloaded in full and hang or crash the tab.
|
|
3
7
|
export async function waitForFonts(): Promise<void> {
|
|
4
8
|
if (!('fonts' in document)) return;
|
|
5
9
|
await document.fonts.ready;
|
|
6
|
-
const pending: Promise<unknown>[] = [];
|
|
7
|
-
for (const face of document.fonts) {
|
|
8
|
-
if (face.status !== 'loaded') pending.push(face.load());
|
|
9
|
-
}
|
|
10
|
-
if (pending.length) {
|
|
11
|
-
await Promise.all(pending.map((p) => p.catch(() => undefined)));
|
|
12
|
-
}
|
|
13
10
|
}
|
|
14
11
|
|
|
15
12
|
export async function waitForDataWaitfor(
|