@open-slide/core 1.12.1 → 1.13.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.
@@ -29,6 +29,7 @@ type Props = {
29
29
  windowed: boolean;
30
30
  onPrev: () => void;
31
31
  onNext: () => void;
32
+ onMobileInteraction: () => void;
32
33
  onOverview: () => void;
33
34
  onBlackout: (mode: 'black' | 'white') => void;
34
35
  onLaser: () => void;
@@ -55,6 +56,7 @@ export function PresentControlBar({
55
56
  windowed,
56
57
  onPrev,
57
58
  onNext,
59
+ onMobileInteraction,
58
60
  onOverview,
59
61
  onBlackout,
60
62
  onLaser,
@@ -65,11 +67,17 @@ export function PresentControlBar({
65
67
  tooltipContainer,
66
68
  }: Props) {
67
69
  const t = useLocale();
70
+ const fullscreenAria = windowed ? t.present.enterFullscreenAria : t.present.exitFullscreenAria;
71
+ const handleMobileAction = (action: () => void) => {
72
+ action();
73
+ onMobileInteraction();
74
+ };
75
+
68
76
  return (
69
77
  <div
70
78
  data-state={visible ? 'visible' : 'hidden'}
71
79
  className={cn(
72
- 'pointer-events-none absolute inset-x-0 bottom-0 z-40 flex justify-center px-4 pb-4',
80
+ 'pointer-events-none absolute inset-x-0 bottom-0 z-40 flex justify-center px-3 pb-[calc(0.75rem+env(safe-area-inset-bottom))] md:px-4 md:pb-4',
73
81
  'will-change-[translate,scale,opacity,filter]',
74
82
  'motion-safe:transition-[translate,scale,opacity,filter]',
75
83
  'motion-safe:duration-[420ms] motion-safe:[transition-timing-function:cubic-bezier(0.22,1,0.36,1)]',
@@ -80,7 +88,12 @@ export function PresentControlBar({
80
88
  >
81
89
  <TooltipProvider delayDuration={300}>
82
90
  <TooltipContainerCtx.Provider value={tooltipContainer ?? null}>
83
- <div className="pointer-events-auto flex h-11 items-center gap-1 rounded-full border border-white/10 bg-black/55 px-2 text-white/85 shadow-[0_8px_30px_-8px_oklch(0_0_0/0.6)] backdrop-blur-md">
91
+ <div
92
+ className={cn(
93
+ 'hidden h-11 items-center gap-1 rounded-full border border-white/10 bg-black/55 px-2 text-white/85 shadow-[0_8px_30px_-8px_oklch(0_0_0/0.6)] backdrop-blur-md md:flex',
94
+ visible ? 'pointer-events-auto' : 'pointer-events-none',
95
+ )}
96
+ >
84
97
  <BarButton label={t.present.prevSlideAria} onClick={onPrev} disabled={index === 0}>
85
98
  <ChevronLeft className="size-4" />
86
99
  </BarButton>
@@ -129,10 +142,7 @@ export function PresentControlBar({
129
142
  <BarButton label={t.present.presenterAria} onClick={onPresenter}>
130
143
  <MonitorSpeaker className="size-4" />
131
144
  </BarButton>
132
- <BarButton
133
- label={windowed ? t.present.enterFullscreenAria : t.present.exitFullscreenAria}
134
- onClick={onToggleFullscreen}
135
- >
145
+ <BarButton label={fullscreenAria} onClick={onToggleFullscreen}>
136
146
  {windowed ? <Maximize className="size-4" /> : <Minimize className="size-4" />}
137
147
  </BarButton>
138
148
  <BarButton label={t.present.helpAria} onClick={onHelp}>
@@ -148,12 +158,91 @@ export function PresentControlBar({
148
158
  </>
149
159
  )}
150
160
  </div>
161
+
162
+ <div
163
+ className={cn(
164
+ 'flex w-fit max-w-[calc(100vw-1.5rem)] md:hidden',
165
+ visible ? 'pointer-events-auto' : 'pointer-events-none',
166
+ )}
167
+ >
168
+ <div className="flex h-10 w-fit items-center gap-0.5 rounded-full border border-white/10 bg-black/60 px-1 text-white/85 shadow-[0_8px_30px_-8px_oklch(0_0_0/0.65)] backdrop-blur-md">
169
+ <MobileBarButton
170
+ label={t.present.prevSlideAria}
171
+ onClick={() => handleMobileAction(onPrev)}
172
+ disabled={index === 0}
173
+ >
174
+ <ChevronLeft className="size-4" />
175
+ </MobileBarButton>
176
+ <span className="min-w-[3.5rem] px-1 text-center font-mono text-[11.5px] tabular-nums text-white/80 select-none">
177
+ <span className="text-white">{index + 1}</span>
178
+ <span className="px-1 text-white/35">/</span>
179
+ <span>{total}</span>
180
+ </span>
181
+ <MobileBarButton
182
+ label={t.present.nextSlideAria}
183
+ onClick={() => handleMobileAction(onNext)}
184
+ disabled={index >= total - 1}
185
+ >
186
+ <ChevronRight className="size-4" />
187
+ </MobileBarButton>
188
+ <MobileDivider />
189
+ <MobileBarButton
190
+ label={t.present.overviewAria}
191
+ onClick={() => handleMobileAction(onOverview)}
192
+ >
193
+ <Grid2x2 className="size-4" />
194
+ </MobileBarButton>
195
+ {allowExit && (
196
+ <MobileBarButton
197
+ label={t.present.exitAria}
198
+ onClick={() => handleMobileAction(onExit)}
199
+ >
200
+ <LogOut className="size-4" />
201
+ </MobileBarButton>
202
+ )}
203
+ </div>
204
+ </div>
151
205
  </TooltipContainerCtx.Provider>
152
206
  </TooltipProvider>
153
207
  </div>
154
208
  );
155
209
  }
156
210
 
211
+ function MobileBarButton({
212
+ children,
213
+ label,
214
+ onClick,
215
+ disabled,
216
+ }: {
217
+ children: React.ReactNode;
218
+ label: string;
219
+ onClick: () => void;
220
+ disabled?: boolean;
221
+ }) {
222
+ return (
223
+ <button
224
+ type="button"
225
+ aria-label={label}
226
+ disabled={disabled}
227
+ onClick={(event) => {
228
+ event.stopPropagation();
229
+ onClick();
230
+ }}
231
+ className={cn(
232
+ 'inline-flex size-8 shrink-0 touch-manipulation items-center justify-center rounded-full transition-colors',
233
+ 'text-white/85 hover:bg-white/12 focus-visible:bg-white/12 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/35',
234
+ 'disabled:pointer-events-none disabled:opacity-30',
235
+ )}
236
+ >
237
+ {children}
238
+ </button>
239
+ );
240
+ }
241
+
242
+ function MobileDivider() {
243
+ return <span aria-hidden className="mx-0.5 h-3.5 w-px shrink-0 bg-white/15" />;
244
+ }
245
+
157
246
  function BarButton({
158
247
  children,
159
248
  label,
@@ -175,7 +264,10 @@ function BarButton({
175
264
  type="button"
176
265
  aria-label={label}
177
266
  disabled={disabled}
178
- onClick={onClick}
267
+ onClick={(event) => {
268
+ event.stopPropagation();
269
+ onClick();
270
+ }}
179
271
  className={cn(
180
272
  'inline-flex size-8 items-center justify-center rounded-full transition-colors',
181
273
  'hover:bg-white/12 focus-visible:bg-white/12 focus-visible:outline-none',
@@ -0,0 +1,48 @@
1
+ import {
2
+ Children,
3
+ type CSSProperties,
4
+ cloneElement,
5
+ isValidElement,
6
+ type ReactElement,
7
+ type ReactNode,
8
+ } from 'react';
9
+
10
+ export type unstable_SharedElementProps = {
11
+ id: string;
12
+ children: ReactNode;
13
+ className?: string;
14
+ style?: CSSProperties;
15
+ };
16
+
17
+ type SharedElementChildProps = {
18
+ className?: string;
19
+ style?: CSSProperties;
20
+ 'data-osd-shared-element'?: string;
21
+ };
22
+
23
+ export function unstable_SharedElement({
24
+ id,
25
+ children,
26
+ className,
27
+ style,
28
+ }: unstable_SharedElementProps) {
29
+ const child = Children.toArray(children)[0] ?? null;
30
+
31
+ if (
32
+ Children.count(children) === 1 &&
33
+ isValidElement<SharedElementChildProps>(child) &&
34
+ typeof child.type === 'string'
35
+ ) {
36
+ return cloneElement(child as ReactElement<SharedElementChildProps>, {
37
+ 'data-osd-shared-element': id,
38
+ className: [child.props.className, className].filter(Boolean).join(' ') || undefined,
39
+ style: style ? { ...child.props.style, ...style } : child.props.style,
40
+ });
41
+ }
42
+
43
+ return (
44
+ <div className={className} style={style} data-osd-shared-element={id}>
45
+ {children}
46
+ </div>
47
+ );
48
+ }
@@ -47,6 +47,7 @@ export function SlideCanvas({
47
47
  const s = measured ?? 1;
48
48
  const scaledW = CANVAS_WIDTH * s;
49
49
  const scaledH = CANVAS_HEIGHT * s;
50
+ const designVars = design ? designToCssVars(design) : undefined;
50
51
 
51
52
  return (
52
53
  <div ref={containerRef} className={cn('relative h-full w-full overflow-hidden', className)}>
@@ -57,19 +58,27 @@ export function SlideCanvas({
57
58
  // can't be clipped by the parent's overflow-hidden.
58
59
  !flat && 'rounded-[6px] shadow-[inset_0_0_0_1px_oklch(0_0_0/0.08)]',
59
60
  )}
60
- style={{
61
- width: scaledW,
62
- height: scaledH,
63
- visibility: measured === null ? 'hidden' : undefined,
64
- ...(center
65
- ? {
66
- position: 'absolute',
67
- left: '50%',
68
- top: '50%',
69
- transform: `translate(-50%, -50%)`,
70
- }
71
- : {}),
72
- }}
61
+ style={
62
+ {
63
+ width: scaledW,
64
+ height: scaledH,
65
+ visibility: measured === null ? 'hidden' : undefined,
66
+ ...(designVars
67
+ ? {
68
+ ...designVars,
69
+ background: 'var(--osd-bg)',
70
+ }
71
+ : {}),
72
+ ...(center
73
+ ? {
74
+ position: 'absolute',
75
+ left: '50%',
76
+ top: '50%',
77
+ transform: `translate(-50%, -50%)`,
78
+ }
79
+ : {}),
80
+ } as CSSProperties
81
+ }
73
82
  >
74
83
  <div
75
84
  data-osd-canvas
@@ -80,7 +89,7 @@ export function SlideCanvas({
80
89
  height: CANVAS_HEIGHT,
81
90
  transform: `scale(${s})`,
82
91
  transformOrigin: 'top left',
83
- ...(design ? designToCssVars(design) : {}),
92
+ ...(designVars ?? {}),
84
93
  } as CSSProperties
85
94
  }
86
95
  >