@open-slide/core 1.13.6 → 1.15.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 (64) hide show
  1. package/dist/{build-OAZ8maw5.js → build-BsaslS8C.js} +1 -1
  2. package/dist/cli/bin.js +3 -3
  3. package/dist/{config-CU_NISD6.js → config-BOc3-oDV.js} +38 -3
  4. package/dist/{config-CvzwK0tq.d.ts → config-CE2sKgqH.d.ts} +1 -1
  5. package/dist/dev-BU7OY0ai.js +94 -0
  6. package/dist/{format-CXtO6ORA.js → format-afijk371.js} +140 -8
  7. package/dist/index.d.ts +7 -7
  8. package/dist/index.js +4 -2
  9. package/dist/locale/index.d.ts +1 -1
  10. package/dist/locale/index.js +1 -1
  11. package/dist/{preview-DZLZ3L9v.js → preview-DbL7Wt77.js} +1 -1
  12. package/dist/{types-DucrShh9.d.ts → types-GA4ekcYB.d.ts} +37 -0
  13. package/dist/vite/index.d.ts +2 -2
  14. package/dist/vite/index.js +1 -1
  15. package/package.json +2 -2
  16. package/src/app/components/asset-view.tsx +762 -63
  17. package/src/app/components/inspector/image-crop-dialog.tsx +3 -3
  18. package/src/app/components/inspector/inspect-overlay.tsx +44 -32
  19. package/src/app/components/inspector/inspector-panel.tsx +31 -26
  20. package/src/app/components/language-toggle.tsx +1 -1
  21. package/src/app/components/overview-grid.tsx +14 -12
  22. package/src/app/components/present/control-bar.tsx +24 -21
  23. package/src/app/components/present/progress-bar.tsx +1 -1
  24. package/src/app/components/sidebar/folder-item.tsx +26 -22
  25. package/src/app/components/sidebar/icon-picker.tsx +8 -8
  26. package/src/app/components/sidebar/sidebar-footer.tsx +100 -31
  27. package/src/app/components/sidebar/sidebar.tsx +22 -18
  28. package/src/app/components/style-panel/style-panel.tsx +8 -4
  29. package/src/app/components/theme-toggle.tsx +3 -3
  30. package/src/app/components/themes/theme-detail.tsx +2 -2
  31. package/src/app/components/themes/themes-gallery.tsx +1 -1
  32. package/src/app/components/thumbnail-rail-scroll.test.ts +60 -0
  33. package/src/app/components/thumbnail-rail-scroll.ts +33 -0
  34. package/src/app/components/thumbnail-rail.tsx +235 -66
  35. package/src/app/components/ui/badge.tsx +16 -13
  36. package/src/app/components/ui/button.tsx +4 -10
  37. package/src/app/components/ui/context-menu.tsx +46 -36
  38. package/src/app/components/ui/dialog.tsx +11 -13
  39. package/src/app/components/ui/dropdown-menu.tsx +59 -37
  40. package/src/app/components/ui/label.tsx +2 -5
  41. package/src/app/components/ui/popover.tsx +25 -18
  42. package/src/app/components/ui/progress.tsx +8 -6
  43. package/src/app/components/ui/scroll-area.tsx +5 -5
  44. package/src/app/components/ui/select.tsx +40 -41
  45. package/src/app/components/ui/separator.tsx +3 -5
  46. package/src/app/components/ui/slider.tsx +25 -18
  47. package/src/app/components/ui/tabs.tsx +8 -8
  48. package/src/app/components/ui/toggle-group.tsx +8 -7
  49. package/src/app/components/ui/toggle.tsx +5 -5
  50. package/src/app/components/ui/tooltip.tsx +39 -22
  51. package/src/app/lib/asset-filter.test.ts +176 -0
  52. package/src/app/lib/asset-filter.ts +80 -0
  53. package/src/app/lib/assets.ts +19 -4
  54. package/src/app/routes/home-shell.tsx +24 -20
  55. package/src/app/routes/home.tsx +48 -42
  56. package/src/app/routes/presenter.tsx +1 -1
  57. package/src/app/routes/slide.tsx +54 -47
  58. package/src/app/styles.css +86 -110
  59. package/src/locale/en.ts +34 -1
  60. package/src/locale/ja.ts +34 -2
  61. package/src/locale/types.ts +37 -0
  62. package/src/locale/zh-cn.ts +34 -1
  63. package/src/locale/zh-tw.ts +34 -1
  64. package/dist/dev-C78J1TLR.js +0 -20
@@ -1,5 +1,5 @@
1
1
  import config from 'virtual:open-slide/config';
2
- import { Loader2, RefreshCw } from 'lucide-react';
2
+ import { Loader2, RefreshCw, RotateCw } from 'lucide-react';
3
3
  import { useEffect, useState } from 'react';
4
4
  import { toast } from 'sonner';
5
5
  import { Button } from '@/components/ui/button';
@@ -7,12 +7,25 @@ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/comp
7
7
  import { format, useLocale } from '@/lib/use-locale';
8
8
 
9
9
  type UpdateCheck = { current: string; latest: string | null; outdated: boolean };
10
+ type ServerStatus = { executionId: string; canRestart: boolean };
10
11
  type UpdateStatus = 'idle' | 'running' | 'done' | 'error';
11
12
 
13
+ const buttonClassName =
14
+ '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';
15
+
16
+ async function fetchServerStatus(): Promise<ServerStatus | null> {
17
+ const res = await fetch('/__server-status');
18
+ if (!res.ok) return null;
19
+ return (await res.json()) as ServerStatus;
20
+ }
21
+
12
22
  export function SidebarFooter() {
13
23
  const t = useLocale();
14
24
  const [update, setUpdate] = useState<UpdateCheck | null>(null);
15
25
  const [updateStatus, setUpdateStatus] = useState<UpdateStatus>('idle');
26
+ const [canRestart, setCanRestart] = useState(false);
27
+ const [restarting, setRestarting] = useState(false);
28
+ const [open, setOpen] = useState(false);
16
29
 
17
30
  useEffect(() => {
18
31
  if (!import.meta.env.DEV) return;
@@ -23,6 +36,11 @@ export function SidebarFooter() {
23
36
  if (!cancelled && data?.outdated) setUpdate(data);
24
37
  })
25
38
  .catch(() => {});
39
+ fetchServerStatus()
40
+ .then((status) => {
41
+ if (!cancelled && status) setCanRestart(status.canRestart);
42
+ })
43
+ .catch(() => {});
26
44
  return () => {
27
45
  cancelled = true;
28
46
  };
@@ -30,10 +48,12 @@ export function SidebarFooter() {
30
48
 
31
49
  const label = `v${config.version}`;
32
50
  const isUpdating = updateStatus === 'running';
51
+ const keepOpen = updateStatus === 'running' || restarting;
33
52
 
34
53
  async function updatePackage() {
35
54
  if (isUpdating) return;
36
55
  setUpdateStatus('running');
56
+ setOpen(true);
37
57
  try {
38
58
  const res = await fetch('/__update-package', { method: 'POST' });
39
59
  if (!res.ok) throw new Error('update failed');
@@ -45,6 +65,29 @@ export function SidebarFooter() {
45
65
  }
46
66
  }
47
67
 
68
+ async function restartServer() {
69
+ if (restarting) return;
70
+ setRestarting(true);
71
+ try {
72
+ const before = await fetchServerStatus();
73
+ if (!before) throw new Error('server status unavailable');
74
+ const res = await fetch('/__restart-server', { method: 'POST' });
75
+ if (!res.ok) throw new Error('restart failed');
76
+ for (let attempt = 0; attempt < 30; attempt++) {
77
+ await new Promise((resolve) => setTimeout(resolve, 500));
78
+ const status = await fetchServerStatus().catch(() => null);
79
+ if (status && status.executionId !== before.executionId) {
80
+ window.location.reload();
81
+ return;
82
+ }
83
+ }
84
+ throw new Error('restart timed out');
85
+ } catch {
86
+ setRestarting(false);
87
+ toast.error(t.home.restartServerFailed);
88
+ }
89
+ }
90
+
48
91
  const versionRow = (
49
92
  <span className="inline-flex cursor-default items-center gap-1.5">
50
93
  {update?.latest && <span className="size-1.5 rounded-full bg-brand" aria-hidden />}
@@ -55,9 +98,15 @@ export function SidebarFooter() {
55
98
  return (
56
99
  <div className="px-4 py-3 text-[11px] text-muted-foreground/70 tabular-nums">
57
100
  {update?.latest ? (
58
- <TooltipProvider delayDuration={200}>
59
- <Tooltip>
60
- <TooltipTrigger asChild>{versionRow}</TooltipTrigger>
101
+ <TooltipProvider delay={200}>
102
+ <Tooltip
103
+ open={open}
104
+ onOpenChange={(next) => {
105
+ if (!next && keepOpen) return;
106
+ setOpen(next);
107
+ }}
108
+ >
109
+ <TooltipTrigger render={versionRow} />
61
110
  <TooltipContent
62
111
  side="top"
63
112
  align="start"
@@ -66,33 +115,53 @@ export function SidebarFooter() {
66
115
  collisionPadding={12}
67
116
  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
117
  >
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>
118
+ {updateStatus === 'done' ? (
119
+ <>
120
+ <span className="pr-1 text-background/92">{t.home.updatePackageDone}</span>
121
+ {canRestart && (
122
+ <Button
123
+ type="button"
124
+ size="xs"
125
+ variant="secondary"
126
+ className={buttonClassName}
127
+ disabled={restarting}
128
+ onClick={restartServer}
129
+ >
130
+ {restarting ? (
131
+ <Loader2 className="animate-spin" aria-hidden />
132
+ ) : (
133
+ <RotateCw aria-hidden />
134
+ )}
135
+ {restarting ? t.home.restartingServer : t.home.restartServer}
136
+ </Button>
137
+ )}
138
+ </>
139
+ ) : (
140
+ <>
141
+ <span className="pr-1 text-background/92">
142
+ {format(t.home.updateAvailable, { version: update.latest })}
143
+ </span>
144
+ <Button
145
+ type="button"
146
+ size="xs"
147
+ variant="secondary"
148
+ className={buttonClassName}
149
+ disabled={isUpdating}
150
+ onClick={updatePackage}
151
+ >
152
+ {isUpdating ? (
153
+ <Loader2 className="animate-spin" aria-hidden />
154
+ ) : (
155
+ <RefreshCw aria-hidden />
156
+ )}
157
+ {isUpdating ? t.home.updatingPackage : t.home.updatePackage}
158
+ </Button>
159
+ {updateStatus === 'error' && (
160
+ <span className="text-[11px] leading-4 text-background/65">
161
+ {t.home.updatePackageFailed}
162
+ </span>
163
+ )}
164
+ </>
96
165
  )}
97
166
  </TooltipContent>
98
167
  </Tooltip>
@@ -118,7 +118,7 @@ export function Sidebar({
118
118
  const target = e.target as HTMLElement | null;
119
119
  if (!target) return;
120
120
  if (target.closest('[data-folder-create]')) return;
121
- if (target.closest('[data-radix-popper-content-wrapper]')) return;
121
+ if (target.closest('[data-slot="popover-content"]')) return;
122
122
  commitCreate();
123
123
  };
124
124
  document.addEventListener('mousedown', onDown);
@@ -126,7 +126,7 @@ export function Sidebar({
126
126
  }, [creating]);
127
127
 
128
128
  return (
129
- <aside className="paper relative flex h-full w-[16.5rem] shrink-0 flex-col border-r border-hairline bg-sidebar text-sidebar-foreground">
129
+ <aside className="relative flex h-full w-[16.5rem] shrink-0 flex-col border-r border-hairline bg-sidebar text-sidebar-foreground">
130
130
  <div className="flex items-center justify-between px-4 pt-5 pb-4">
131
131
  <h1 className="font-heading text-lg font-bold tracking-tight">{t.home.appTitle}</h1>
132
132
  <div className="-mr-1.5 flex items-center">
@@ -150,13 +150,15 @@ export function Sidebar({
150
150
  onSelect={() => onSelect(THEMES_ID)}
151
151
  onDropSlide={() => {}}
152
152
  />
153
- <FolderItem
154
- row={{ kind: 'assets' }}
155
- count={assetsCount}
156
- selected={selectedId === ASSETS_ID}
157
- onSelect={() => onSelect(ASSETS_ID)}
158
- onDropSlide={() => {}}
159
- />
153
+ {import.meta.env.DEV && (
154
+ <FolderItem
155
+ row={{ kind: 'assets' }}
156
+ count={assetsCount}
157
+ selected={selectedId === ASSETS_ID}
158
+ onSelect={() => onSelect(ASSETS_ID)}
159
+ onDropSlide={() => {}}
160
+ />
161
+ )}
160
162
  </div>
161
163
 
162
164
  <div className="mt-5 flex items-center gap-2 px-4 pb-1.5">
@@ -247,15 +249,17 @@ export function Sidebar({
247
249
  className="mt-1 flex items-center gap-2.5 rounded-[5px] border border-dashed border-foreground/30 bg-card px-2 py-[5px]"
248
250
  >
249
251
  <Popover open={iconOpen} onOpenChange={setIconOpen}>
250
- <PopoverTrigger asChild>
251
- <button
252
- type="button"
253
- className="flex size-5 shrink-0 items-center justify-center rounded transition-transform hover:scale-110"
254
- aria-label={t.home.pickIcon}
255
- >
256
- <FolderIconChip icon={newIcon} />
257
- </button>
258
- </PopoverTrigger>
252
+ <PopoverTrigger
253
+ render={
254
+ <button
255
+ type="button"
256
+ className="flex size-5 shrink-0 items-center justify-center rounded transition-transform hover:scale-110"
257
+ aria-label={t.home.pickIcon}
258
+ >
259
+ <FolderIconChip icon={newIcon} />
260
+ </button>
261
+ }
262
+ />
259
263
  <PopoverContent side="right" align="start" className="w-auto p-2">
260
264
  <IconPicker value={newIcon} onChange={setNewIcon} />
261
265
  </PopoverContent>
@@ -85,8 +85,8 @@ export function DesignPanel({ open, onClose }: DesignPanelProps) {
85
85
  }
86
86
  banner={
87
87
  warning && (
88
- <div className="flex gap-2 border-b border-hairline bg-[oklch(0.97_0.04_85)] px-3 py-2 text-[11px] leading-relaxed text-[oklch(0.35_0.08_45)] dark:bg-[oklch(0.25_0.04_60)] dark:text-[oklch(0.85_0.08_85)]">
89
- <span aria-hidden className="mt-0.5 size-1.5 shrink-0 rounded-full bg-brand" />
88
+ <div className="flex gap-2 border-b border-hairline bg-amber-500/10 px-3 py-2 text-[11px] leading-relaxed text-amber-800 dark:bg-amber-400/10 dark:text-amber-200">
89
+ <span aria-hidden className="mt-0.5 size-1.5 shrink-0 rounded-full bg-amber-500" />
90
90
  <span>{warning}</span>
91
91
  </div>
92
92
  )
@@ -273,9 +273,13 @@ function FontField({
273
273
  return (
274
274
  <Field label={label}>
275
275
  <Select
276
+ items={{
277
+ ...Object.fromEntries(FONT_PRESETS.map((p) => [p.value, p.label])),
278
+ __custom__: tFont.stylePanel.fontPresetCustom,
279
+ }}
276
280
  value={matched ? matched.value : '__custom__'}
277
281
  onValueChange={(v) => {
278
- if (v !== '__custom__') onChange(v);
282
+ if (typeof v === 'string' && v !== '__custom__') onChange(v);
279
283
  }}
280
284
  >
281
285
  <SelectTrigger size="sm" className="h-8 flex-1 text-xs">
@@ -322,7 +326,7 @@ function SliderField({
322
326
  max={max}
323
327
  step={step}
324
328
  value={[value]}
325
- onValueChange={([v]) => onChange(v ?? value)}
329
+ onValueChange={(next) => onChange((Array.isArray(next) ? next[0] : next) ?? value)}
326
330
  className="flex-1"
327
331
  />
328
332
  <NumberField
@@ -33,21 +33,21 @@ export function ThemeToggle() {
33
33
  </DropdownMenuTrigger>
34
34
  <DropdownMenuContent align="end" className="min-w-[140px]">
35
35
  <DropdownMenuItem
36
- onSelect={() => setTheme('light')}
36
+ onClick={() => setTheme('light')}
37
37
  data-active={mounted && theme === 'light'}
38
38
  >
39
39
  <Sun />
40
40
  {t.themeToggle.light}
41
41
  </DropdownMenuItem>
42
42
  <DropdownMenuItem
43
- onSelect={() => setTheme('dark')}
43
+ onClick={() => setTheme('dark')}
44
44
  data-active={mounted && theme === 'dark'}
45
45
  >
46
46
  <Moon />
47
47
  {t.themeToggle.dark}
48
48
  </DropdownMenuItem>
49
49
  <DropdownMenuItem
50
- onSelect={() => setTheme('system')}
50
+ onClick={() => setTheme('system')}
51
51
  data-active={mounted && theme === 'system'}
52
52
  >
53
53
  <Monitor />
@@ -102,7 +102,7 @@ export function ThemeDetail({ themeId, onBack }: { themeId: string; onBack: () =
102
102
  {!theme.hasDemo ? (
103
103
  <NoDemoLargeState />
104
104
  ) : !demo ? (
105
- <div className="grid h-full w-full place-items-center text-[11px] tracking-[0.16em] uppercase text-muted-foreground/60">
105
+ <div className="grid h-full w-full place-items-center text-[11px] tracking-[0.08em] uppercase text-muted-foreground/60">
106
106
  {t.common.loading}
107
107
  </div>
108
108
  ) : Current ? (
@@ -236,7 +236,7 @@ function ThemeSlideCard({ id }: { id: string }) {
236
236
  </SlideCanvas>
237
237
  </div>
238
238
  ) : (
239
- <div className="grid h-full w-full place-items-center text-[10px] tracking-[0.16em] uppercase text-muted-foreground/60">
239
+ <div className="grid h-full w-full place-items-center text-[10px] tracking-[0.08em] uppercase text-muted-foreground/60">
240
240
  {t.common.loading}
241
241
  </div>
242
242
  )}
@@ -68,7 +68,7 @@ function ThemePreview({ theme }: { theme: Theme }) {
68
68
  }
69
69
  if (!demo) {
70
70
  return (
71
- <div className="grid h-full w-full place-items-center text-[10px] tracking-[0.16em] uppercase text-muted-foreground/60">
71
+ <div className="grid h-full w-full place-items-center text-[10px] tracking-[0.08em] uppercase text-muted-foreground/60">
72
72
  {t.common.loading}
73
73
  </div>
74
74
  );
@@ -0,0 +1,60 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ getCenteredThumbnailScrollTop,
4
+ getThumbnailOffscreenDirection,
5
+ } from './thumbnail-rail-scroll';
6
+
7
+ describe('getThumbnailOffscreenDirection', () => {
8
+ const visibleBounds = { visibleTop: 40, visibleBottom: 540 };
9
+
10
+ it('reports a thumbnail fully above the visible area', () => {
11
+ expect(getThumbnailOffscreenDirection({ itemTop: -80, itemBottom: 40, ...visibleBounds })).toBe(
12
+ 'above',
13
+ );
14
+ });
15
+
16
+ it('reports a thumbnail fully below the visible area', () => {
17
+ expect(
18
+ getThumbnailOffscreenDirection({ itemTop: 540, itemBottom: 660, ...visibleBounds }),
19
+ ).toBe('below');
20
+ });
21
+
22
+ it('keeps the control hidden while a thumbnail is fully visible', () => {
23
+ expect(
24
+ getThumbnailOffscreenDirection({ itemTop: 120, itemBottom: 240, ...visibleBounds }),
25
+ ).toBeNull();
26
+ });
27
+
28
+ it('keeps the control hidden while either edge remains visible', () => {
29
+ expect(
30
+ getThumbnailOffscreenDirection({ itemTop: 20, itemBottom: 80, ...visibleBounds }),
31
+ ).toBeNull();
32
+ expect(
33
+ getThumbnailOffscreenDirection({ itemTop: 500, itemBottom: 580, ...visibleBounds }),
34
+ ).toBeNull();
35
+ });
36
+ });
37
+
38
+ describe('getCenteredThumbnailScrollTop', () => {
39
+ it('centers the thumbnail inside the unobscured viewport', () => {
40
+ expect(
41
+ getCenteredThumbnailScrollTop({
42
+ itemTop: 1040,
43
+ itemHeight: 120,
44
+ viewportHeight: 600,
45
+ topInset: 40,
46
+ }),
47
+ ).toBe(780);
48
+ });
49
+
50
+ it('does not scroll before the start of the list', () => {
51
+ expect(
52
+ getCenteredThumbnailScrollTop({
53
+ itemTop: 40,
54
+ itemHeight: 120,
55
+ viewportHeight: 600,
56
+ topInset: 40,
57
+ }),
58
+ ).toBe(0);
59
+ });
60
+ });
@@ -0,0 +1,33 @@
1
+ export type ThumbnailOffscreenDirection = 'above' | 'below' | null;
2
+
3
+ export function getThumbnailOffscreenDirection({
4
+ itemTop,
5
+ itemBottom,
6
+ visibleTop,
7
+ visibleBottom,
8
+ }: {
9
+ itemTop: number;
10
+ itemBottom: number;
11
+ visibleTop: number;
12
+ visibleBottom: number;
13
+ }): ThumbnailOffscreenDirection {
14
+ if (itemBottom <= visibleTop) return 'above';
15
+ if (itemTop >= visibleBottom) return 'below';
16
+ return null;
17
+ }
18
+
19
+ export function getCenteredThumbnailScrollTop({
20
+ itemTop,
21
+ itemHeight,
22
+ viewportHeight,
23
+ topInset,
24
+ }: {
25
+ itemTop: number;
26
+ itemHeight: number;
27
+ viewportHeight: number;
28
+ topInset: number;
29
+ }): number {
30
+ const visibleHeight = Math.max(0, viewportHeight - topInset);
31
+ const centerOffset = Math.max(0, (visibleHeight - itemHeight) / 2);
32
+ return Math.max(0, itemTop - topInset - centerOffset);
33
+ }