@open-slide/core 1.13.0 → 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,10 +1,10 @@
|
|
|
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
|
|
5
|
-
import * as react_jsx_runtime3 from "react/jsx-runtime";
|
|
4
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
6
5
|
import * as react_jsx_runtime1 from "react/jsx-runtime";
|
|
7
|
-
import * as
|
|
6
|
+
import * as react_jsx_runtime4 from "react/jsx-runtime";
|
|
7
|
+
import * as react_jsx_runtime5 from "react/jsx-runtime";
|
|
8
8
|
|
|
9
9
|
//#region src/app/components/image-placeholder.d.ts
|
|
10
10
|
type ImagePlaceholderProps = {
|
|
@@ -21,7 +21,7 @@ declare function ImagePlaceholder({
|
|
|
21
21
|
style,
|
|
22
22
|
className,
|
|
23
23
|
...rest
|
|
24
|
-
}: ImagePlaceholderProps):
|
|
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):
|
|
39
|
+
}: unstable_SharedElementProps): react_jsx_runtime1.JSX.Element;
|
|
40
40
|
|
|
41
41
|
//#endregion
|
|
42
42
|
//#region src/app/lib/design.d.ts
|
|
@@ -117,7 +117,7 @@ declare const CANVAS_HEIGHT = 1080;
|
|
|
117
117
|
type StepsProps = PropsWithChildren;
|
|
118
118
|
declare function Steps({
|
|
119
119
|
children
|
|
120
|
-
}: StepsProps):
|
|
120
|
+
}: StepsProps): react_jsx_runtime4.JSX.Element;
|
|
121
121
|
type StepProps = PropsWithChildren<{
|
|
122
122
|
duration?: number;
|
|
123
123
|
}>;
|
|
@@ -128,7 +128,7 @@ declare function Step({
|
|
|
128
128
|
children,
|
|
129
129
|
duration,
|
|
130
130
|
_revealed
|
|
131
|
-
}: InternalStepProps):
|
|
131
|
+
}: InternalStepProps): react_jsx_runtime5.JSX.Element;
|
|
132
132
|
|
|
133
133
|
//#endregion
|
|
134
134
|
export { CANVAS_HEIGHT, CANVAS_WIDTH, DesignFonts, DesignPalette, DesignSystem, DesignTypeScale, ImagePlaceholder, ImagePlaceholderProps, Locale, OpenSlideConfig, Page, Plural, SharedElementTransition, SlideMeta, SlideModule, SlideTransition, Step, StepProps, Steps, StepsProps, TransitionPhase, cssVarsToString, defaultDesign, designToCssVars, unstable_SharedElement, unstable_SharedElementProps, useSlidePageNumber };
|
package/package.json
CHANGED
|
@@ -45,6 +45,46 @@ const SHARED_ELEMENT_VISUAL_PROPERTIES = [
|
|
|
45
45
|
'fill',
|
|
46
46
|
'stroke',
|
|
47
47
|
] as const;
|
|
48
|
+
const BORDER_COLOR_PROPERTIES = [
|
|
49
|
+
'border-top-color',
|
|
50
|
+
'border-right-color',
|
|
51
|
+
'border-bottom-color',
|
|
52
|
+
'border-left-color',
|
|
53
|
+
] as const;
|
|
54
|
+
const BORDER_SIDE_PROPERTIES = [
|
|
55
|
+
{
|
|
56
|
+
width: 'borderTopWidth',
|
|
57
|
+
style: 'borderTopStyle',
|
|
58
|
+
color: 'borderTopColor',
|
|
59
|
+
cssWidth: 'border-top-width',
|
|
60
|
+
cssStyle: 'border-top-style',
|
|
61
|
+
cssColor: 'border-top-color',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
width: 'borderRightWidth',
|
|
65
|
+
style: 'borderRightStyle',
|
|
66
|
+
color: 'borderRightColor',
|
|
67
|
+
cssWidth: 'border-right-width',
|
|
68
|
+
cssStyle: 'border-right-style',
|
|
69
|
+
cssColor: 'border-right-color',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
width: 'borderBottomWidth',
|
|
73
|
+
style: 'borderBottomStyle',
|
|
74
|
+
color: 'borderBottomColor',
|
|
75
|
+
cssWidth: 'border-bottom-width',
|
|
76
|
+
cssStyle: 'border-bottom-style',
|
|
77
|
+
cssColor: 'border-bottom-color',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
width: 'borderLeftWidth',
|
|
81
|
+
style: 'borderLeftStyle',
|
|
82
|
+
color: 'borderLeftColor',
|
|
83
|
+
cssWidth: 'border-left-width',
|
|
84
|
+
cssStyle: 'border-left-style',
|
|
85
|
+
cssColor: 'border-left-color',
|
|
86
|
+
},
|
|
87
|
+
] as const;
|
|
48
88
|
const INHERITED_VISUAL_PROPERTIES = new Set<string>([
|
|
49
89
|
'color',
|
|
50
90
|
'text-decoration-color',
|
|
@@ -222,13 +262,27 @@ function sharedElementTransform(
|
|
|
222
262
|
.join(' ');
|
|
223
263
|
}
|
|
224
264
|
|
|
265
|
+
function sharedElementTranslateTransform(rect: LocalRect, local: string): string {
|
|
266
|
+
return [`translate(${rect.left}px, ${rect.top}px)`, local].filter(Boolean).join(' ');
|
|
267
|
+
}
|
|
268
|
+
|
|
225
269
|
function getStyleProperty(styles: CSSStyleDeclaration, css: string): string {
|
|
226
270
|
return styles.getPropertyValue(css);
|
|
227
271
|
}
|
|
228
272
|
|
|
229
|
-
function visualStyleKeyframe(
|
|
273
|
+
function visualStyleKeyframe(
|
|
274
|
+
styles: CSSStyleDeclaration,
|
|
275
|
+
opacity?: string,
|
|
276
|
+
options: { includeBorderColors?: boolean } = {},
|
|
277
|
+
): Keyframe {
|
|
230
278
|
const frame: Record<string, string> = {};
|
|
231
279
|
for (const prop of SHARED_ELEMENT_VISUAL_PROPERTIES) {
|
|
280
|
+
if (
|
|
281
|
+
options.includeBorderColors === false &&
|
|
282
|
+
(BORDER_COLOR_PROPERTIES as readonly string[]).includes(prop)
|
|
283
|
+
) {
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
232
286
|
const value = getStyleProperty(styles, prop);
|
|
233
287
|
if (prop === TEXT_FILL_COLOR_PROPERTY && value === styles.color) continue;
|
|
234
288
|
if (value) frame[prop] = value;
|
|
@@ -237,6 +291,80 @@ function visualStyleKeyframe(styles: CSSStyleDeclaration, opacity?: string): Key
|
|
|
237
291
|
return frame;
|
|
238
292
|
}
|
|
239
293
|
|
|
294
|
+
function hideBorderColors(el: HTMLElement): void {
|
|
295
|
+
for (const { color } of BORDER_SIDE_PROPERTIES) {
|
|
296
|
+
el.style[color] = 'transparent';
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function isVisibleBorderSide(
|
|
301
|
+
styles: CSSStyleDeclaration,
|
|
302
|
+
side: (typeof BORDER_SIDE_PROPERTIES)[number],
|
|
303
|
+
): boolean {
|
|
304
|
+
const width = parsePx(getStyleProperty(styles, side.cssWidth)) ?? 0;
|
|
305
|
+
const borderStyle = getStyleProperty(styles, side.cssStyle);
|
|
306
|
+
return width > 0 && borderStyle !== 'none' && borderStyle !== 'hidden';
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function hasVisibleBorder(styles: CSSStyleDeclaration): boolean {
|
|
310
|
+
return BORDER_SIDE_PROPERTIES.some((side) => isVisibleBorderSide(styles, side));
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function borderFrameKeyframe(
|
|
314
|
+
rect: LocalRect,
|
|
315
|
+
styles: CSSStyleDeclaration,
|
|
316
|
+
opacity: string,
|
|
317
|
+
): Keyframe {
|
|
318
|
+
const frame: Keyframe = {
|
|
319
|
+
width: `${rect.width}px`,
|
|
320
|
+
height: `${rect.height}px`,
|
|
321
|
+
opacity,
|
|
322
|
+
transform: sharedElementTranslateTransform(rect, localTransform(styles)),
|
|
323
|
+
...radiusKeyframe(styles),
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
for (const side of BORDER_SIDE_PROPERTIES) {
|
|
327
|
+
frame[side.width] = getStyleProperty(styles, side.cssWidth);
|
|
328
|
+
frame[side.color] = getStyleProperty(styles, side.cssColor);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return frame;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function appendBorderFrame(
|
|
335
|
+
wrapper: HTMLElement,
|
|
336
|
+
overlay: HTMLElement,
|
|
337
|
+
sourceStyles: CSSStyleDeclaration,
|
|
338
|
+
targetStyles: CSSStyleDeclaration,
|
|
339
|
+
rect: LocalRect,
|
|
340
|
+
): HTMLElement {
|
|
341
|
+
if (!overlay.parentElement) wrapper.appendChild(overlay);
|
|
342
|
+
|
|
343
|
+
const frame = document.createElement('div');
|
|
344
|
+
Object.assign(frame.style, {
|
|
345
|
+
position: 'absolute',
|
|
346
|
+
left: '0',
|
|
347
|
+
top: '0',
|
|
348
|
+
width: `${rect.width}px`,
|
|
349
|
+
height: `${rect.height}px`,
|
|
350
|
+
margin: '0',
|
|
351
|
+
transformOrigin: 'top left',
|
|
352
|
+
pointerEvents: 'none',
|
|
353
|
+
boxSizing: 'border-box',
|
|
354
|
+
background: 'transparent',
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
for (const side of BORDER_SIDE_PROPERTIES) {
|
|
358
|
+
const styles = isVisibleBorderSide(sourceStyles, side) ? sourceStyles : targetStyles;
|
|
359
|
+
frame.style[side.style] = getStyleProperty(styles, side.cssStyle);
|
|
360
|
+
frame.style[side.width] = getStyleProperty(sourceStyles, side.cssWidth);
|
|
361
|
+
frame.style[side.color] = getStyleProperty(sourceStyles, side.cssColor);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
overlay.appendChild(frame);
|
|
365
|
+
return frame;
|
|
366
|
+
}
|
|
367
|
+
|
|
240
368
|
function hasVisualStyleChange(from: CSSStyleDeclaration, to: CSSStyleDeclaration): boolean {
|
|
241
369
|
for (const prop of SHARED_ELEMENT_VISUAL_PROPERTIES) {
|
|
242
370
|
if (getStyleProperty(from, prop) !== getStyleProperty(to, prop)) return true;
|
|
@@ -456,20 +584,40 @@ function runSharedElementTransition(
|
|
|
456
584
|
const targetStyles = getComputedStyle(target);
|
|
457
585
|
const fromOpacity = effectiveOpacity(source, outgoingLayer);
|
|
458
586
|
const toOpacity = effectiveOpacity(target, incomingLayer);
|
|
587
|
+
const needsBorderFrame = hasVisibleBorder(sourceStyles) || hasVisibleBorder(targetStyles);
|
|
459
588
|
const scaleX = to.width / from.width;
|
|
460
589
|
const scaleY = to.height / from.height;
|
|
461
590
|
const fromTransform = sharedElementTransform(from, 1, 1, localTransform(sourceStyles));
|
|
462
591
|
const toTransform = sharedElementTransform(to, scaleX, scaleY, localTransform(targetStyles));
|
|
592
|
+
|
|
593
|
+
if (needsBorderFrame) {
|
|
594
|
+
hideBorderColors(clone);
|
|
595
|
+
const borderFrame = appendBorderFrame(wrapper, overlay, sourceStyles, targetStyles, from);
|
|
596
|
+
animations.push(
|
|
597
|
+
borderFrame.animate(
|
|
598
|
+
[
|
|
599
|
+
borderFrameKeyframe(from, sourceStyles, fromOpacity),
|
|
600
|
+
borderFrameKeyframe(to, targetStyles, toOpacity),
|
|
601
|
+
],
|
|
602
|
+
sharedElementAnimationOptions(phase),
|
|
603
|
+
),
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
|
|
463
607
|
animations.push(
|
|
464
608
|
clone.animate(
|
|
465
609
|
[
|
|
466
610
|
{
|
|
467
|
-
...visualStyleKeyframe(sourceStyles, fromOpacity
|
|
611
|
+
...visualStyleKeyframe(sourceStyles, fromOpacity, {
|
|
612
|
+
includeBorderColors: !needsBorderFrame,
|
|
613
|
+
}),
|
|
468
614
|
...radiusKeyframe(sourceStyles),
|
|
469
615
|
transform: fromTransform,
|
|
470
616
|
},
|
|
471
617
|
{
|
|
472
|
-
...visualStyleKeyframe(targetStyles, toOpacity
|
|
618
|
+
...visualStyleKeyframe(targetStyles, toOpacity, {
|
|
619
|
+
includeBorderColors: !needsBorderFrame,
|
|
620
|
+
}),
|
|
473
621
|
...radiusKeyframe(targetStyles, scaleX, scaleY),
|
|
474
622
|
transform: toTransform,
|
|
475
623
|
},
|
|
@@ -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, 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,14 @@ 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;
|
|
70
|
+
const VERTICAL_THUMB_PADDING_Y = 12;
|
|
71
|
+
const VERTICAL_THUMB_GAP = 8;
|
|
72
|
+
const VIRTUAL_OVERSCAN = 4;
|
|
65
73
|
|
|
66
74
|
export function ThumbnailRail({
|
|
67
75
|
pages,
|
|
@@ -89,132 +97,105 @@ export function ThumbnailRail({
|
|
|
89
97
|
});
|
|
90
98
|
}, [current]);
|
|
91
99
|
|
|
92
|
-
if (orientation === 'horizontal') {
|
|
93
|
-
const scale = HORIZONTAL_THUMB_HEIGHT / CANVAS_HEIGHT;
|
|
94
|
-
const width = CANVAS_WIDTH * scale;
|
|
95
|
-
return (
|
|
96
|
-
<div className="bg-sidebar">
|
|
97
|
-
<div className="overflow-x-auto overflow-y-hidden">
|
|
98
|
-
<div className="flex items-center gap-2 px-3 py-2.5">
|
|
99
|
-
{pages.map((PageComp, i) => {
|
|
100
|
-
const active = i === current;
|
|
101
|
-
const button = (
|
|
102
|
-
<button
|
|
103
|
-
// biome-ignore lint/suspicious/noArrayIndexKey: pages list is render-stable
|
|
104
|
-
key={i}
|
|
105
|
-
type="button"
|
|
106
|
-
ref={active ? activeRef : undefined}
|
|
107
|
-
onClick={() => onSelect(i)}
|
|
108
|
-
aria-label={format(t.thumbnailRail.goToPageAria, { n: i + 1 })}
|
|
109
|
-
aria-current={active ? 'true' : undefined}
|
|
110
|
-
className={cn('group/thumb relative flex shrink-0 flex-col items-center gap-1.5')}
|
|
111
|
-
>
|
|
112
|
-
<span
|
|
113
|
-
className={cn(
|
|
114
|
-
'font-mono text-[9.5px] font-medium tracking-[0.06em] tabular-nums uppercase',
|
|
115
|
-
active ? 'text-brand' : 'text-muted-foreground/70',
|
|
116
|
-
)}
|
|
117
|
-
>
|
|
118
|
-
{(i + 1).toString().padStart(2, '0')}
|
|
119
|
-
</span>
|
|
120
|
-
<div
|
|
121
|
-
className={cn(
|
|
122
|
-
'relative shrink-0 overflow-hidden rounded-[4px] border bg-card motion-safe:transition-[border-color,box-shadow]',
|
|
123
|
-
active
|
|
124
|
-
? 'border-brand shadow-[0_0_0_1px_var(--brand)]'
|
|
125
|
-
: 'border-hairline group-hover/thumb:border-foreground/25',
|
|
126
|
-
)}
|
|
127
|
-
style={{ width, height: HORIZONTAL_THUMB_HEIGHT }}
|
|
128
|
-
>
|
|
129
|
-
<SlideCanvas scale={scale} center={false} flat freezeMotion design={design}>
|
|
130
|
-
<SlidePageProvider index={i} total={pages.length}>
|
|
131
|
-
<PageComp />
|
|
132
|
-
</SlidePageProvider>
|
|
133
|
-
</SlideCanvas>
|
|
134
|
-
</div>
|
|
135
|
-
</button>
|
|
136
|
-
);
|
|
137
|
-
if (!actions) return button;
|
|
138
|
-
return (
|
|
139
|
-
<ThumbContextMenu
|
|
140
|
-
// biome-ignore lint/suspicious/noArrayIndexKey: pages list is render-stable
|
|
141
|
-
key={i}
|
|
142
|
-
index={i}
|
|
143
|
-
actions={actions}
|
|
144
|
-
pageCount={pages.length}
|
|
145
|
-
ariaLabel={format(t.thumbnailRail.pageActionsAria, { n: i + 1 })}
|
|
146
|
-
>
|
|
147
|
-
{button}
|
|
148
|
-
</ThumbContextMenu>
|
|
149
|
-
);
|
|
150
|
-
})}
|
|
151
|
-
</div>
|
|
152
|
-
</div>
|
|
153
|
-
</div>
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
100
|
const thumbWidth =
|
|
158
101
|
width != null
|
|
159
102
|
? Math.max(MIN_VERTICAL_THUMB_WIDTH, width - VERTICAL_RAIL_CHROME)
|
|
160
103
|
: DEFAULT_VERTICAL_THUMB_WIDTH;
|
|
161
104
|
const scale = thumbWidth / CANVAS_WIDTH;
|
|
162
105
|
const height = CANVAS_HEIGHT * scale;
|
|
106
|
+
const rowHeight = height + VERTICAL_THUMB_PADDING_Y + VERTICAL_THUMB_GAP;
|
|
163
107
|
|
|
164
|
-
const renderThumb = (
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
108
|
+
const renderThumb = useCallback(
|
|
109
|
+
(PageComp: Page, i: number) => {
|
|
110
|
+
const active = i === current;
|
|
111
|
+
const inner = (
|
|
112
|
+
<ThumbContents
|
|
113
|
+
index={i}
|
|
114
|
+
total={pages.length}
|
|
115
|
+
active={active}
|
|
116
|
+
page={PageComp}
|
|
117
|
+
design={design}
|
|
118
|
+
scale={scale}
|
|
119
|
+
thumbWidth={thumbWidth}
|
|
120
|
+
height={height}
|
|
121
|
+
moduleTransition={moduleTransition}
|
|
122
|
+
/>
|
|
123
|
+
);
|
|
179
124
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
125
|
+
const node = onReorder ? (
|
|
126
|
+
<SortableThumb
|
|
127
|
+
index={i}
|
|
128
|
+
active={active}
|
|
129
|
+
activeRef={active ? activeRef : undefined}
|
|
130
|
+
onSelect={() => onSelect(i)}
|
|
131
|
+
ariaLabel={format(t.thumbnailRail.goToPageAria, { n: i + 1 })}
|
|
132
|
+
>
|
|
133
|
+
{inner}
|
|
134
|
+
</SortableThumb>
|
|
135
|
+
) : (
|
|
136
|
+
<button
|
|
137
|
+
type="button"
|
|
138
|
+
ref={active ? activeRef : undefined}
|
|
139
|
+
onClick={() => onSelect(i)}
|
|
140
|
+
aria-label={format(t.thumbnailRail.goToPageAria, { n: i + 1 })}
|
|
141
|
+
aria-current={active ? 'true' : undefined}
|
|
142
|
+
className={thumbButtonClass(active)}
|
|
143
|
+
>
|
|
144
|
+
{inner}
|
|
145
|
+
</button>
|
|
146
|
+
);
|
|
202
147
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
148
|
+
if (!actions) {
|
|
149
|
+
return <Fragment key={i}>{node}</Fragment>;
|
|
150
|
+
}
|
|
151
|
+
return (
|
|
152
|
+
<ThumbContextMenu
|
|
153
|
+
key={i}
|
|
154
|
+
index={i}
|
|
155
|
+
actions={actions}
|
|
156
|
+
pageCount={pages.length}
|
|
157
|
+
ariaLabel={format(t.thumbnailRail.pageActionsAria, { n: i + 1 })}
|
|
158
|
+
>
|
|
159
|
+
{node}
|
|
160
|
+
</ThumbContextMenu>
|
|
161
|
+
);
|
|
162
|
+
},
|
|
163
|
+
[
|
|
164
|
+
actions,
|
|
165
|
+
current,
|
|
166
|
+
design,
|
|
167
|
+
height,
|
|
168
|
+
moduleTransition,
|
|
169
|
+
onReorder,
|
|
170
|
+
onSelect,
|
|
171
|
+
pages.length,
|
|
172
|
+
scale,
|
|
173
|
+
thumbWidth,
|
|
174
|
+
t.thumbnailRail.goToPageAria,
|
|
175
|
+
t.thumbnailRail.pageActionsAria,
|
|
176
|
+
],
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
if (orientation === 'horizontal') {
|
|
180
|
+
const scale = HORIZONTAL_THUMB_HEIGHT / CANVAS_HEIGHT;
|
|
181
|
+
const horizontalWidth = CANVAS_WIDTH * scale;
|
|
206
182
|
return (
|
|
207
|
-
<
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
183
|
+
<div className="bg-sidebar">
|
|
184
|
+
<div className="overflow-x-auto overflow-y-hidden">
|
|
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
|
+
/>
|
|
195
|
+
</div>
|
|
196
|
+
</div>
|
|
216
197
|
);
|
|
217
|
-
}
|
|
198
|
+
}
|
|
218
199
|
|
|
219
200
|
const list = (
|
|
220
201
|
<aside className="flex flex-col gap-2 px-3 pb-3">
|
|
@@ -247,7 +228,13 @@ export function ThumbnailRail({
|
|
|
247
228
|
</div>
|
|
248
229
|
</div>
|
|
249
230
|
</div>
|
|
250
|
-
|
|
231
|
+
<VirtualThumbList
|
|
232
|
+
pages={pages}
|
|
233
|
+
current={current}
|
|
234
|
+
rowHeight={rowHeight}
|
|
235
|
+
activeRef={activeRef}
|
|
236
|
+
renderThumb={renderThumb}
|
|
237
|
+
/>
|
|
251
238
|
</aside>
|
|
252
239
|
);
|
|
253
240
|
|
|
@@ -280,6 +267,297 @@ function thumbButtonClass(active: boolean): string {
|
|
|
280
267
|
);
|
|
281
268
|
}
|
|
282
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
|
+
|
|
430
|
+
function VirtualThumbList({
|
|
431
|
+
pages,
|
|
432
|
+
current,
|
|
433
|
+
rowHeight,
|
|
434
|
+
activeRef,
|
|
435
|
+
renderThumb,
|
|
436
|
+
}: {
|
|
437
|
+
pages: Page[];
|
|
438
|
+
current: number;
|
|
439
|
+
rowHeight: number;
|
|
440
|
+
activeRef: React.MutableRefObject<HTMLButtonElement | null>;
|
|
441
|
+
renderThumb: (page: Page, index: number) => React.ReactNode;
|
|
442
|
+
}) {
|
|
443
|
+
const rootRef = useRef<HTMLDivElement | null>(null);
|
|
444
|
+
const viewportRef = useRef<HTMLElement | null>(null);
|
|
445
|
+
const [range, setRange] = useState(() => getInitialVisibleRange(current, pages.length));
|
|
446
|
+
|
|
447
|
+
const updateRange = useCallback(() => {
|
|
448
|
+
const viewport = viewportRef.current;
|
|
449
|
+
const root = rootRef.current;
|
|
450
|
+
if (!viewport || !root) return;
|
|
451
|
+
const scrollTop = Math.max(0, viewport.scrollTop - root.offsetTop);
|
|
452
|
+
setRange(getVisibleRange(scrollTop, pages.length, viewport.clientHeight, rowHeight));
|
|
453
|
+
}, [pages.length, rowHeight]);
|
|
454
|
+
|
|
455
|
+
useEffect(() => {
|
|
456
|
+
const root = rootRef.current;
|
|
457
|
+
if (!root) return;
|
|
458
|
+
const viewport = root.closest('[data-slot="scroll-area-viewport"]') as HTMLElement | null;
|
|
459
|
+
if (!viewport) return;
|
|
460
|
+
viewportRef.current = viewport;
|
|
461
|
+
|
|
462
|
+
let frame = 0;
|
|
463
|
+
const scheduleUpdate = () => {
|
|
464
|
+
cancelAnimationFrame(frame);
|
|
465
|
+
frame = requestAnimationFrame(updateRange);
|
|
466
|
+
};
|
|
467
|
+
const resizeObserver = new ResizeObserver(scheduleUpdate);
|
|
468
|
+
|
|
469
|
+
viewport.addEventListener('scroll', scheduleUpdate, { passive: true });
|
|
470
|
+
resizeObserver.observe(viewport);
|
|
471
|
+
scheduleUpdate();
|
|
472
|
+
|
|
473
|
+
return () => {
|
|
474
|
+
cancelAnimationFrame(frame);
|
|
475
|
+
viewport.removeEventListener('scroll', scheduleUpdate);
|
|
476
|
+
resizeObserver.disconnect();
|
|
477
|
+
if (viewportRef.current === viewport) viewportRef.current = null;
|
|
478
|
+
};
|
|
479
|
+
}, [updateRange]);
|
|
480
|
+
|
|
481
|
+
useEffect(() => {
|
|
482
|
+
const viewport = viewportRef.current;
|
|
483
|
+
const root = rootRef.current;
|
|
484
|
+
if (!viewport || !root) return;
|
|
485
|
+
|
|
486
|
+
const top = root.offsetTop + current * rowHeight;
|
|
487
|
+
const bottom = top + rowHeight;
|
|
488
|
+
const viewportTop = viewport.scrollTop;
|
|
489
|
+
const viewportBottom = viewportTop + viewport.clientHeight;
|
|
490
|
+
|
|
491
|
+
if (top < viewportTop) {
|
|
492
|
+
viewport.scrollTo({ top, behavior: scrollBehavior() });
|
|
493
|
+
} else if (bottom > viewportBottom) {
|
|
494
|
+
viewport.scrollTo({ top: bottom - viewport.clientHeight, behavior: scrollBehavior() });
|
|
495
|
+
} else {
|
|
496
|
+
activeRef.current?.scrollIntoView({
|
|
497
|
+
block: 'nearest',
|
|
498
|
+
inline: 'nearest',
|
|
499
|
+
behavior: scrollBehavior(),
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
}, [activeRef, current, rowHeight]);
|
|
503
|
+
|
|
504
|
+
const visibleRange = clampVisibleRange(range, current, pages.length);
|
|
505
|
+
const visible = [];
|
|
506
|
+
for (let i = visibleRange.start; i < visibleRange.end; i++) {
|
|
507
|
+
visible.push(
|
|
508
|
+
<div
|
|
509
|
+
key={i}
|
|
510
|
+
className="absolute right-0 left-0"
|
|
511
|
+
style={{ top: i * rowHeight, height: rowHeight }}
|
|
512
|
+
>
|
|
513
|
+
{renderThumb(pages[i], i)}
|
|
514
|
+
</div>,
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
return (
|
|
519
|
+
<div ref={rootRef} className="relative" style={{ height: pages.length * rowHeight }}>
|
|
520
|
+
{visible}
|
|
521
|
+
</div>
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
type VisibleRange = { start: number; end: number };
|
|
526
|
+
|
|
527
|
+
function clampVisibleRange(range: VisibleRange, current: number, count: number): VisibleRange {
|
|
528
|
+
if (count <= 0) return { start: 0, end: 0 };
|
|
529
|
+
if (range.start >= 0 && range.start < count && range.start < range.end) {
|
|
530
|
+
return { start: range.start, end: Math.min(range.end, count) };
|
|
531
|
+
}
|
|
532
|
+
const clampedCurrent = Math.min(Math.max(current, 0), count - 1);
|
|
533
|
+
return getInitialVisibleRange(clampedCurrent, count);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function getVisibleRange(
|
|
537
|
+
scrollTop: number,
|
|
538
|
+
count: number,
|
|
539
|
+
viewportHeight: number,
|
|
540
|
+
rowHeight: number,
|
|
541
|
+
): VisibleRange {
|
|
542
|
+
if (count <= 0) return { start: 0, end: 0 };
|
|
543
|
+
const visibleRows = Math.max(1, Math.ceil(viewportHeight / rowHeight));
|
|
544
|
+
const firstVisible = Math.min(count - 1, Math.max(0, Math.floor(scrollTop / rowHeight)));
|
|
545
|
+
const start = Math.max(0, firstVisible - VIRTUAL_OVERSCAN);
|
|
546
|
+
const end = Math.min(count, firstVisible + visibleRows + VIRTUAL_OVERSCAN + 1);
|
|
547
|
+
return { start, end };
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function getInitialVisibleRange(current: number, count: number): VisibleRange {
|
|
551
|
+
if (count <= 0) return { start: 0, end: 0 };
|
|
552
|
+
const start = Math.max(0, current - VIRTUAL_OVERSCAN);
|
|
553
|
+
const end = Math.min(count, current + VIRTUAL_OVERSCAN + 1);
|
|
554
|
+
return { start, end };
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function scrollBehavior(): ScrollBehavior {
|
|
558
|
+
return window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth';
|
|
559
|
+
}
|
|
560
|
+
|
|
283
561
|
function ThumbContents({
|
|
284
562
|
index,
|
|
285
563
|
total,
|