@open-slide/core 1.13.1 → 1.13.2

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/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Locale, Plural } from "./types-CHmFPIG_.js";
2
2
  import { OpenSlideConfig } from "./config-x493taft.js";
3
3
  import { CSSProperties, ComponentType, HTMLAttributes, PropsWithChildren, ReactNode } from "react";
4
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
4
5
  import * as react_jsx_runtime1 from "react/jsx-runtime";
5
- import * as react_jsx_runtime2 from "react/jsx-runtime";
6
6
  import * as react_jsx_runtime4 from "react/jsx-runtime";
7
7
  import * as react_jsx_runtime5 from "react/jsx-runtime";
8
8
 
@@ -21,7 +21,7 @@ declare function ImagePlaceholder({
21
21
  style,
22
22
  className,
23
23
  ...rest
24
- }: ImagePlaceholderProps): react_jsx_runtime1.JSX.Element;
24
+ }: ImagePlaceholderProps): react_jsx_runtime0.JSX.Element;
25
25
 
26
26
  //#endregion
27
27
  //#region src/app/components/shared-element.d.ts
@@ -36,7 +36,7 @@ declare function unstable_SharedElement({
36
36
  children,
37
37
  className,
38
38
  style
39
- }: unstable_SharedElementProps): react_jsx_runtime2.JSX.Element;
39
+ }: unstable_SharedElementProps): react_jsx_runtime1.JSX.Element;
40
40
 
41
41
  //#endregion
42
42
  //#region src/app/lib/design.d.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-slide/core",
3
- "version": "1.13.1",
3
+ "version": "1.13.2",
4
4
  "description": "Runtime and CLI for open-slide — write slides in slides/, we handle the rest.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -16,7 +16,7 @@ import {
16
16
  } from '@dnd-kit/sortable';
17
17
  import { CSS } from '@dnd-kit/utilities';
18
18
  import { Copy, Grid2x2, ListOrdered, type LucideIcon, Sparkles, Trash2 } from 'lucide-react';
19
- import { Fragment, useCallback, useEffect, useRef, useState } from 'react';
19
+ import { Fragment, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
20
20
  import {
21
21
  ContextMenu,
22
22
  ContextMenuContent,
@@ -62,6 +62,11 @@ const DEFAULT_VERTICAL_THUMB_WIDTH = 184;
62
62
  const VERTICAL_RAIL_CHROME = 80;
63
63
  const MIN_VERTICAL_THUMB_WIDTH = 120;
64
64
  const HORIZONTAL_THUMB_HEIGHT = 64;
65
+ const HORIZONTAL_THUMB_GAP = 8;
66
+ const HORIZONTAL_RAIL_PADDING_X = 12;
67
+ const HORIZONTAL_RAIL_PADDING_Y = 10;
68
+ const HORIZONTAL_LABEL_HEIGHT = 12;
69
+ const HORIZONTAL_LABEL_GAP = 6;
65
70
  const VERTICAL_THUMB_PADDING_Y = 12;
66
71
  const VERTICAL_THUMB_GAP = 8;
67
72
  const VIRTUAL_OVERSCAN = 4;
@@ -177,60 +182,16 @@ export function ThumbnailRail({
177
182
  return (
178
183
  <div className="bg-sidebar">
179
184
  <div className="overflow-x-auto overflow-y-hidden">
180
- <div className="flex items-center gap-2 px-3 py-2.5">
181
- {pages.map((PageComp, i) => {
182
- const active = i === current;
183
- const button = (
184
- <button
185
- // biome-ignore lint/suspicious/noArrayIndexKey: pages list is render-stable
186
- key={i}
187
- type="button"
188
- ref={active ? activeRef : undefined}
189
- onClick={() => onSelect(i)}
190
- aria-label={format(t.thumbnailRail.goToPageAria, { n: i + 1 })}
191
- aria-current={active ? 'true' : undefined}
192
- className={cn('group/thumb relative flex shrink-0 flex-col items-center gap-1.5')}
193
- >
194
- <span
195
- className={cn(
196
- 'font-mono text-[9.5px] font-medium tracking-[0.06em] tabular-nums uppercase',
197
- active ? 'text-brand' : 'text-muted-foreground/70',
198
- )}
199
- >
200
- {(i + 1).toString().padStart(2, '0')}
201
- </span>
202
- <div
203
- className={cn(
204
- 'relative shrink-0 overflow-hidden rounded-[4px] border bg-card motion-safe:transition-[border-color,box-shadow]',
205
- active
206
- ? 'border-brand shadow-[0_0_0_1px_var(--brand)]'
207
- : 'border-hairline group-hover/thumb:border-foreground/25',
208
- )}
209
- style={{ width: horizontalWidth, height: HORIZONTAL_THUMB_HEIGHT }}
210
- >
211
- <SlideCanvas scale={scale} center={false} flat freezeMotion design={design}>
212
- <SlidePageProvider index={i} total={pages.length}>
213
- <PageComp />
214
- </SlidePageProvider>
215
- </SlideCanvas>
216
- </div>
217
- </button>
218
- );
219
- if (!actions) return button;
220
- return (
221
- <ThumbContextMenu
222
- // biome-ignore lint/suspicious/noArrayIndexKey: pages list is render-stable
223
- key={i}
224
- index={i}
225
- actions={actions}
226
- pageCount={pages.length}
227
- ariaLabel={format(t.thumbnailRail.pageActionsAria, { n: i + 1 })}
228
- >
229
- {button}
230
- </ThumbContextMenu>
231
- );
232
- })}
233
- </div>
185
+ <HorizontalVirtualThumbList
186
+ pages={pages}
187
+ design={design}
188
+ current={current}
189
+ actions={actions}
190
+ activeRef={activeRef}
191
+ onSelect={onSelect}
192
+ scale={scale}
193
+ thumbWidth={horizontalWidth}
194
+ />
234
195
  </div>
235
196
  </div>
236
197
  );
@@ -306,6 +267,166 @@ function thumbButtonClass(active: boolean): string {
306
267
  );
307
268
  }
308
269
 
270
+ function HorizontalVirtualThumbList({
271
+ pages,
272
+ design,
273
+ current,
274
+ actions,
275
+ activeRef,
276
+ onSelect,
277
+ scale,
278
+ thumbWidth,
279
+ }: {
280
+ pages: Page[];
281
+ design?: DesignSystem;
282
+ current: number;
283
+ actions?: ThumbnailActions;
284
+ activeRef: React.MutableRefObject<HTMLButtonElement | null>;
285
+ onSelect: (index: number) => void;
286
+ scale: number;
287
+ thumbWidth: number;
288
+ }) {
289
+ const rootRef = useRef<HTMLDivElement | null>(null);
290
+ const viewportRef = useRef<HTMLElement | null>(null);
291
+ const t = useLocale();
292
+ const itemWidth = thumbWidth + HORIZONTAL_THUMB_GAP;
293
+ const listHeight =
294
+ HORIZONTAL_RAIL_PADDING_Y * 2 +
295
+ HORIZONTAL_LABEL_HEIGHT +
296
+ HORIZONTAL_LABEL_GAP +
297
+ HORIZONTAL_THUMB_HEIGHT;
298
+ const [range, setRange] = useState(() => getInitialVisibleRange(current, pages.length));
299
+
300
+ const updateRange = useCallback(() => {
301
+ const viewport = viewportRef.current;
302
+ if (!viewport) return;
303
+ const scrollLeft = Math.max(0, viewport.scrollLeft - HORIZONTAL_RAIL_PADDING_X);
304
+ setRange(getVisibleRange(scrollLeft, pages.length, viewport.clientWidth, itemWidth));
305
+ }, [itemWidth, pages.length]);
306
+
307
+ useLayoutEffect(() => {
308
+ const root = rootRef.current;
309
+ const viewport = root?.parentElement;
310
+ if (!viewport) return;
311
+ viewportRef.current = viewport;
312
+
313
+ let frame = 0;
314
+ const scheduleUpdate = () => {
315
+ cancelAnimationFrame(frame);
316
+ frame = requestAnimationFrame(updateRange);
317
+ };
318
+ const resizeObserver = new ResizeObserver(scheduleUpdate);
319
+
320
+ viewport.addEventListener('scroll', scheduleUpdate, { passive: true });
321
+ resizeObserver.observe(viewport);
322
+ scheduleUpdate();
323
+
324
+ return () => {
325
+ cancelAnimationFrame(frame);
326
+ viewport.removeEventListener('scroll', scheduleUpdate);
327
+ resizeObserver.disconnect();
328
+ if (viewportRef.current === viewport) viewportRef.current = null;
329
+ };
330
+ }, [updateRange]);
331
+
332
+ useLayoutEffect(() => {
333
+ if (pages.length <= 0) return;
334
+ const viewport = viewportRef.current ?? rootRef.current?.parentElement;
335
+ if (!viewport) return;
336
+ viewportRef.current = viewport;
337
+
338
+ const clampedCurrent = Math.min(Math.max(current, 0), pages.length - 1);
339
+ const left = HORIZONTAL_RAIL_PADDING_X + clampedCurrent * itemWidth;
340
+ const right = left + thumbWidth;
341
+ const viewportLeft = viewport.scrollLeft;
342
+ const viewportRight = viewportLeft + viewport.clientWidth;
343
+
344
+ if (left < viewportLeft) {
345
+ viewport.scrollLeft = left;
346
+ } else if (right > viewportRight) {
347
+ viewport.scrollLeft = right - viewport.clientWidth;
348
+ }
349
+
350
+ const scrollLeft = Math.max(0, viewport.scrollLeft - HORIZONTAL_RAIL_PADDING_X);
351
+ setRange(getVisibleRange(scrollLeft, pages.length, viewport.clientWidth, itemWidth));
352
+ }, [current, itemWidth, pages.length, thumbWidth]);
353
+
354
+ const visibleRange = clampVisibleRange(range, current, pages.length);
355
+ const visible = [];
356
+ for (let i = visibleRange.start; i < visibleRange.end; i++) {
357
+ const PageComp = pages[i];
358
+ const active = i === current;
359
+ const button = (
360
+ <button
361
+ type="button"
362
+ ref={active ? activeRef : undefined}
363
+ onClick={() => onSelect(i)}
364
+ aria-label={format(t.thumbnailRail.goToPageAria, { n: i + 1 })}
365
+ aria-current={active ? 'true' : undefined}
366
+ className={cn('group/thumb relative flex shrink-0 flex-col items-center gap-1.5')}
367
+ >
368
+ <span
369
+ className={cn(
370
+ 'font-mono text-[9.5px] font-medium tracking-[0.06em] tabular-nums uppercase',
371
+ active ? 'text-brand' : 'text-muted-foreground/70',
372
+ )}
373
+ >
374
+ {(i + 1).toString().padStart(2, '0')}
375
+ </span>
376
+ <div
377
+ className={cn(
378
+ 'relative shrink-0 overflow-hidden rounded-[4px] border bg-card motion-safe:transition-[border-color,box-shadow]',
379
+ active
380
+ ? 'border-brand shadow-[0_0_0_1px_var(--brand)]'
381
+ : 'border-hairline group-hover/thumb:border-foreground/25',
382
+ )}
383
+ style={{ width: thumbWidth, height: HORIZONTAL_THUMB_HEIGHT }}
384
+ >
385
+ <SlideCanvas scale={scale} center={false} flat freezeMotion design={design}>
386
+ <SlidePageProvider index={i} total={pages.length}>
387
+ <PageComp />
388
+ </SlidePageProvider>
389
+ </SlideCanvas>
390
+ </div>
391
+ </button>
392
+ );
393
+
394
+ visible.push(
395
+ <div
396
+ key={i}
397
+ className="absolute top-2.5"
398
+ style={{ left: HORIZONTAL_RAIL_PADDING_X + i * itemWidth, width: thumbWidth }}
399
+ >
400
+ {actions ? (
401
+ <ThumbContextMenu
402
+ index={i}
403
+ actions={actions}
404
+ pageCount={pages.length}
405
+ ariaLabel={format(t.thumbnailRail.pageActionsAria, { n: i + 1 })}
406
+ >
407
+ {button}
408
+ </ThumbContextMenu>
409
+ ) : (
410
+ button
411
+ )}
412
+ </div>,
413
+ );
414
+ }
415
+
416
+ return (
417
+ <div
418
+ ref={rootRef}
419
+ className="relative"
420
+ style={{
421
+ width: HORIZONTAL_RAIL_PADDING_X * 2 + pages.length * itemWidth - HORIZONTAL_THUMB_GAP,
422
+ height: listHeight,
423
+ }}
424
+ >
425
+ {visible}
426
+ </div>
427
+ );
428
+ }
429
+
309
430
  function VirtualThumbList({
310
431
  pages,
311
432
  current,