@open-slide/core 1.12.0 → 1.13.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 (34) hide show
  1. package/README.md +2 -0
  2. package/dist/{build-L2yL1hTo.js → build-OAZ8maw5.js} +1 -1
  3. package/dist/cli/bin.js +3 -3
  4. package/dist/{config-OT4T-im0.js → config-CU_NISD6.js} +49 -4
  5. package/dist/{config-C2C3cut3.d.ts → config-x493taft.d.ts} +1 -1
  6. package/dist/{dev-DJUpPCGT.js → dev-C78J1TLR.js} +1 -1
  7. package/dist/{format-zplQGJPI.js → format-7j0EzhuV.js} +4 -0
  8. package/dist/index.d.ts +31 -9
  9. package/dist/index.js +22 -2
  10. package/dist/locale/index.d.ts +1 -1
  11. package/dist/locale/index.js +1 -1
  12. package/dist/{preview-Bf8up6-P.js → preview-DZLZ3L9v.js} +1 -1
  13. package/dist/{types-uNHQlioH.d.ts → types-CHmFPIG_.d.ts} +1 -0
  14. package/dist/vite/index.d.ts +2 -2
  15. package/dist/vite/index.js +1 -1
  16. package/package.json +5 -5
  17. package/src/app/components/inspector/inspect-overlay.tsx +39 -18
  18. package/src/app/components/inspector/inspector-panel.tsx +5 -1
  19. package/src/app/components/inspector/inspector-provider.tsx +54 -6
  20. package/src/app/components/overview-grid.tsx +200 -69
  21. package/src/app/components/player.tsx +66 -3
  22. package/src/app/components/present/control-bar.tsx +99 -7
  23. package/src/app/components/shared-element.tsx +48 -0
  24. package/src/app/components/slide-canvas.tsx +24 -14
  25. package/src/app/components/slide-transition-layer.tsx +506 -4
  26. package/src/app/lib/export-html.ts +1 -1
  27. package/src/app/lib/transition.ts +7 -0
  28. package/src/app/lib/use-click-page-navigation.ts +10 -2
  29. package/src/app/routes/slide.tsx +175 -143
  30. package/src/locale/en.ts +1 -0
  31. package/src/locale/ja.ts +1 -0
  32. package/src/locale/types.ts +1 -0
  33. package/src/locale/zh-cn.ts +1 -0
  34. package/src/locale/zh-tw.ts +1 -0
@@ -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,13 +89,14 @@ 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
  >
87
96
  {children}
88
97
  </div>
89
98
  </div>
99
+ {freezeMotion && <div aria-hidden className="absolute inset-0 z-10" />}
90
100
  </div>
91
101
  );
92
102
  }
@@ -1,4 +1,4 @@
1
- import { type MutableRefObject, useEffect, useRef, useState } from 'react';
1
+ import { type MutableRefObject, useEffect, useLayoutEffect, useRef, useState } from 'react';
2
2
  import { SlidePageProvider } from '../lib/page-context';
3
3
  import type { Page } from '../lib/sdk';
4
4
  import {
@@ -7,7 +7,12 @@ import {
7
7
  type StepController,
8
8
  StepHost,
9
9
  } from '../lib/step-context';
10
- import { resolveTransition, type SlideTransition, type TransitionPhase } from '../lib/transition';
10
+ import {
11
+ resolveTransition,
12
+ type SharedElementTransition,
13
+ type SlideTransition,
14
+ type TransitionPhase,
15
+ } from '../lib/transition';
11
16
 
12
17
  type Props = {
13
18
  pages: Page[];
@@ -23,6 +28,31 @@ type Props = {
23
28
  type Direction = 'forward' | 'backward';
24
29
 
25
30
  const DEFAULT_EASING = 'cubic-bezier(.4, 0, .2, 1)';
31
+ const SHARED_ELEMENT_SELECTOR = '[data-osd-shared-element]';
32
+ const TEXT_FILL_COLOR_PROPERTY = '-webkit-text-fill-color';
33
+ const SHARED_ELEMENT_VISUAL_PROPERTIES = [
34
+ 'opacity',
35
+ 'color',
36
+ 'background-color',
37
+ 'border-top-color',
38
+ 'border-right-color',
39
+ 'border-bottom-color',
40
+ 'border-left-color',
41
+ 'outline-color',
42
+ 'text-decoration-color',
43
+ TEXT_FILL_COLOR_PROPERTY,
44
+ '-webkit-text-stroke-color',
45
+ 'fill',
46
+ 'stroke',
47
+ ] as const;
48
+ const INHERITED_VISUAL_PROPERTIES = new Set<string>([
49
+ 'color',
50
+ 'text-decoration-color',
51
+ TEXT_FILL_COLOR_PROPERTY,
52
+ '-webkit-text-stroke-color',
53
+ 'fill',
54
+ 'stroke',
55
+ ]);
26
56
 
27
57
  function runPhase(
28
58
  el: HTMLElement,
@@ -39,6 +69,453 @@ function runPhase(
39
69
  });
40
70
  }
41
71
 
72
+ type ResolvedSharedElementTransition = Required<SharedElementTransition>;
73
+
74
+ function resolveSharedElementTransition(
75
+ sharedElements: SlideTransition['sharedElements'],
76
+ fallbackDuration: number,
77
+ fallbackEasing: string,
78
+ ): ResolvedSharedElementTransition | null {
79
+ if (!sharedElements) return null;
80
+ if (sharedElements === true) {
81
+ return { duration: fallbackDuration, easing: fallbackEasing, delay: 0 };
82
+ }
83
+ return {
84
+ duration: sharedElements.duration ?? fallbackDuration,
85
+ easing: sharedElements.easing ?? fallbackEasing,
86
+ delay: sharedElements.delay ?? 0,
87
+ };
88
+ }
89
+
90
+ type LocalRect = {
91
+ left: number;
92
+ top: number;
93
+ width: number;
94
+ height: number;
95
+ };
96
+
97
+ function measureUntransformedClientRect(el: HTMLElement): DOMRect {
98
+ const styles = getComputedStyle(el);
99
+ if (!localTransform(styles)) return el.getBoundingClientRect();
100
+
101
+ const value = el.style.getPropertyValue('transform');
102
+ const priority = el.style.getPropertyPriority('transform');
103
+ el.style.setProperty('transform', 'none', 'important');
104
+ try {
105
+ return el.getBoundingClientRect();
106
+ } finally {
107
+ if (value) el.style.setProperty('transform', value, priority);
108
+ else el.style.removeProperty('transform');
109
+ }
110
+ }
111
+
112
+ function measureLocalRect(el: HTMLElement, wrapper: HTMLElement, wrapperRect: DOMRect): LocalRect {
113
+ const rect = measureUntransformedClientRect(el);
114
+ const scaleX = wrapperRect.width / (wrapper.offsetWidth || wrapperRect.width || 1) || 1;
115
+ const scaleY = wrapperRect.height / (wrapper.offsetHeight || wrapperRect.height || 1) || 1;
116
+ return {
117
+ left: (rect.left - wrapperRect.left) / scaleX,
118
+ top: (rect.top - wrapperRect.top) / scaleY,
119
+ width: rect.width / scaleX,
120
+ height: rect.height / scaleY,
121
+ };
122
+ }
123
+
124
+ function hasUsableRect(rect: LocalRect): boolean {
125
+ return rect.width > 0 && rect.height > 0;
126
+ }
127
+
128
+ function collectSharedElements(root: HTMLElement): Map<string, HTMLElement> {
129
+ const elements = new Map<string, HTMLElement>();
130
+ for (const el of root.querySelectorAll<HTMLElement>(SHARED_ELEMENT_SELECTOR)) {
131
+ const id = el.dataset.osdSharedElement;
132
+ if (id && !elements.has(id)) elements.set(id, el);
133
+ }
134
+ return elements;
135
+ }
136
+
137
+ function shouldSkipCopiedStyle(
138
+ source: HTMLElement,
139
+ styles: CSSStyleDeclaration,
140
+ prop: string,
141
+ preserveInheritedVisualStyle: boolean,
142
+ ): boolean {
143
+ if (prop === TEXT_FILL_COLOR_PROPERTY && getStyleProperty(styles, prop) === styles.color) {
144
+ return true;
145
+ }
146
+
147
+ if (!preserveInheritedVisualStyle || !INHERITED_VISUAL_PROPERTIES.has(prop)) return false;
148
+
149
+ const parent = source.parentElement;
150
+ if (!parent) return false;
151
+
152
+ const parentStyles = getComputedStyle(parent);
153
+ return getStyleProperty(styles, prop) === getStyleProperty(parentStyles, prop);
154
+ }
155
+
156
+ function copyComputedStyles(
157
+ source: HTMLElement,
158
+ target: HTMLElement,
159
+ preserveInheritedVisualStyle = false,
160
+ ): void {
161
+ const styles = getComputedStyle(source);
162
+ for (let i = 0; i < styles.length; i++) {
163
+ const prop = styles[i];
164
+ if (shouldSkipCopiedStyle(source, styles, prop, preserveInheritedVisualStyle)) continue;
165
+ target.style.setProperty(prop, styles.getPropertyValue(prop), styles.getPropertyPriority(prop));
166
+ }
167
+
168
+ const sourceChildren = source.querySelectorAll<HTMLElement>('*');
169
+ const targetChildren = target.querySelectorAll<HTMLElement>('*');
170
+ for (let i = 0; i < sourceChildren.length; i++) {
171
+ const child = targetChildren[i];
172
+ if (!child) continue;
173
+ copyComputedStyles(sourceChildren[i], child, true);
174
+ }
175
+ }
176
+
177
+ function cloneSharedElement(source: HTMLElement): HTMLElement {
178
+ const clone = source.cloneNode(true) as HTMLElement;
179
+ copyComputedStyles(source, clone);
180
+ clone.removeAttribute('data-osd-shared-element');
181
+ return clone;
182
+ }
183
+
184
+ function parsePx(value: string): number | null {
185
+ const match = value.trim().match(/^(-?\d*\.?\d+)px$/);
186
+ if (!match) return null;
187
+ const n = Number.parseFloat(match[1]);
188
+ return Number.isFinite(n) ? n : null;
189
+ }
190
+
191
+ function scaleRadius(value: string, scaleX: number, scaleY: number): string {
192
+ const parts = value.trim().split(/\s+/);
193
+ const x = parsePx(parts[0] ?? '');
194
+ const y = parsePx(parts[1] ?? parts[0] ?? '');
195
+ if (x === null || y === null) return value;
196
+ const nextX = x / scaleX;
197
+ const nextY = y / scaleY;
198
+ return Math.abs(nextX - nextY) < 0.001 ? `${nextX}px` : `${nextX}px ${nextY}px`;
199
+ }
200
+
201
+ function radiusKeyframe(styles: CSSStyleDeclaration, scaleX = 1, scaleY = 1): Keyframe {
202
+ return {
203
+ borderTopLeftRadius: scaleRadius(styles.borderTopLeftRadius, scaleX, scaleY),
204
+ borderTopRightRadius: scaleRadius(styles.borderTopRightRadius, scaleX, scaleY),
205
+ borderBottomRightRadius: scaleRadius(styles.borderBottomRightRadius, scaleX, scaleY),
206
+ borderBottomLeftRadius: scaleRadius(styles.borderBottomLeftRadius, scaleX, scaleY),
207
+ };
208
+ }
209
+
210
+ function localTransform(styles: CSSStyleDeclaration): string {
211
+ return styles.transform && styles.transform !== 'none' ? styles.transform : '';
212
+ }
213
+
214
+ function sharedElementTransform(
215
+ rect: LocalRect,
216
+ scaleX: number,
217
+ scaleY: number,
218
+ local: string,
219
+ ): string {
220
+ return [`translate(${rect.left}px, ${rect.top}px)`, `scale(${scaleX}, ${scaleY})`, local]
221
+ .filter(Boolean)
222
+ .join(' ');
223
+ }
224
+
225
+ function getStyleProperty(styles: CSSStyleDeclaration, css: string): string {
226
+ return styles.getPropertyValue(css);
227
+ }
228
+
229
+ function visualStyleKeyframe(styles: CSSStyleDeclaration, opacity?: string): Keyframe {
230
+ const frame: Record<string, string> = {};
231
+ for (const prop of SHARED_ELEMENT_VISUAL_PROPERTIES) {
232
+ const value = getStyleProperty(styles, prop);
233
+ if (prop === TEXT_FILL_COLOR_PROPERTY && value === styles.color) continue;
234
+ if (value) frame[prop] = value;
235
+ }
236
+ if (opacity !== undefined) frame.opacity = opacity;
237
+ return frame;
238
+ }
239
+
240
+ function hasVisualStyleChange(from: CSSStyleDeclaration, to: CSSStyleDeclaration): boolean {
241
+ for (const prop of SHARED_ELEMENT_VISUAL_PROPERTIES) {
242
+ if (getStyleProperty(from, prop) !== getStyleProperty(to, prop)) return true;
243
+ }
244
+ return false;
245
+ }
246
+
247
+ function effectiveOpacity(el: HTMLElement, boundary: HTMLElement): string {
248
+ let opacity = 1;
249
+ let node: HTMLElement | null = el;
250
+ while (node && node !== boundary) {
251
+ const value = Number.parseFloat(getComputedStyle(node).opacity);
252
+ if (Number.isFinite(value)) opacity *= value;
253
+ node = node.parentElement;
254
+ }
255
+ return String(opacity);
256
+ }
257
+
258
+ function hideOriginal(el: HTMLElement): () => void {
259
+ const value = el.style.getPropertyValue('visibility');
260
+ const priority = el.style.getPropertyPriority('visibility');
261
+ el.style.setProperty('visibility', 'hidden', 'important');
262
+ return () => {
263
+ if (value) el.style.setProperty('visibility', value, priority);
264
+ else el.style.removeProperty('visibility');
265
+ };
266
+ }
267
+
268
+ function appendPositionedClone(
269
+ wrapper: HTMLElement,
270
+ overlay: HTMLElement,
271
+ source: HTMLElement,
272
+ rect: LocalRect,
273
+ ): HTMLElement {
274
+ if (!overlay.parentElement) wrapper.appendChild(overlay);
275
+
276
+ const clone = cloneSharedElement(source);
277
+ Object.assign(clone.style, {
278
+ position: 'absolute',
279
+ left: '0',
280
+ top: '0',
281
+ width: `${rect.width}px`,
282
+ height: `${rect.height}px`,
283
+ margin: '0',
284
+ transformOrigin: 'top left',
285
+ pointerEvents: 'none',
286
+ boxSizing: 'border-box',
287
+ });
288
+ overlay.appendChild(clone);
289
+ return clone;
290
+ }
291
+
292
+ function sharedElementAnimationOptions(
293
+ phase: ResolvedSharedElementTransition,
294
+ ): KeyframeAnimationOptions {
295
+ return {
296
+ duration: phase.duration,
297
+ easing: phase.easing,
298
+ delay: phase.delay,
299
+ fill: 'both',
300
+ };
301
+ }
302
+
303
+ function runDescendantVisualStyleTransitions(
304
+ clone: HTMLElement,
305
+ source: HTMLElement,
306
+ target: HTMLElement,
307
+ phase: ResolvedSharedElementTransition,
308
+ ): Animation[] {
309
+ const animations: Animation[] = [];
310
+ const cloneChildren = clone.querySelectorAll<HTMLElement>('*');
311
+ const sourceChildren = source.querySelectorAll<HTMLElement>('*');
312
+ const targetChildren = target.querySelectorAll<HTMLElement>('*');
313
+
314
+ for (let i = 0; i < sourceChildren.length; i++) {
315
+ const cloneChild = cloneChildren[i];
316
+ const targetChild = targetChildren[i];
317
+ if (!cloneChild || !targetChild) continue;
318
+
319
+ const sourceStyles = getComputedStyle(sourceChildren[i]);
320
+ const targetStyles = getComputedStyle(targetChild);
321
+ if (!hasVisualStyleChange(sourceStyles, targetStyles)) continue;
322
+
323
+ animations.push(
324
+ cloneChild.animate(
325
+ [visualStyleKeyframe(sourceStyles), visualStyleKeyframe(targetStyles)],
326
+ sharedElementAnimationOptions(phase),
327
+ ),
328
+ );
329
+ }
330
+
331
+ return animations;
332
+ }
333
+
334
+ function runStationarySharedElementAnimation(
335
+ clone: HTMLElement,
336
+ rect: LocalRect,
337
+ styles: CSSStyleDeclaration,
338
+ fromOpacity: string,
339
+ toOpacity: string,
340
+ phase: ResolvedSharedElementTransition,
341
+ ): Animation {
342
+ const transform = sharedElementTransform(rect, 1, 1, localTransform(styles));
343
+ return clone.animate(
344
+ [
345
+ {
346
+ ...visualStyleKeyframe(styles, fromOpacity),
347
+ ...radiusKeyframe(styles),
348
+ transform,
349
+ },
350
+ {
351
+ ...visualStyleKeyframe(styles, toOpacity),
352
+ ...radiusKeyframe(styles),
353
+ transform,
354
+ },
355
+ ],
356
+ sharedElementAnimationOptions(phase),
357
+ );
358
+ }
359
+
360
+ function runSharedElementTransition(
361
+ wrapper: HTMLElement,
362
+ outgoingLayer: HTMLElement,
363
+ incomingLayer: HTMLElement,
364
+ phase: ResolvedSharedElementTransition,
365
+ ): { animations: Animation[]; cleanup: () => void } {
366
+ const wrapperRect = wrapper.getBoundingClientRect();
367
+ if (wrapperRect.width === 0 || wrapperRect.height === 0) {
368
+ return { animations: [], cleanup: () => {} };
369
+ }
370
+
371
+ const incoming = collectSharedElements(incomingLayer);
372
+ const overlay = document.createElement('div');
373
+ overlay.setAttribute('data-osd-shared-layer', '');
374
+ Object.assign(overlay.style, {
375
+ position: 'absolute',
376
+ inset: '0',
377
+ zIndex: '2147483647',
378
+ pointerEvents: 'none',
379
+ });
380
+
381
+ const animations: Animation[] = [];
382
+ const restore: Array<() => void> = [];
383
+ const outgoing = collectSharedElements(outgoingLayer);
384
+ const handledIncoming = new Set<string>();
385
+
386
+ for (const [id, source] of outgoing) {
387
+ const target = incoming.get(id);
388
+ const from = measureLocalRect(source, wrapper, wrapperRect);
389
+ if (!hasUsableRect(from)) {
390
+ if (target) {
391
+ const to = measureLocalRect(target, wrapper, wrapperRect);
392
+ if (hasUsableRect(to)) {
393
+ handledIncoming.add(id);
394
+ const clone = appendPositionedClone(wrapper, overlay, target, to);
395
+ restore.push(hideOriginal(target));
396
+
397
+ const targetStyles = getComputedStyle(target);
398
+ animations.push(
399
+ runStationarySharedElementAnimation(
400
+ clone,
401
+ to,
402
+ targetStyles,
403
+ '0',
404
+ effectiveOpacity(target, incomingLayer),
405
+ phase,
406
+ ),
407
+ );
408
+ }
409
+ }
410
+ continue;
411
+ }
412
+
413
+ if (!target) {
414
+ const clone = appendPositionedClone(wrapper, overlay, source, from);
415
+ restore.push(hideOriginal(source));
416
+
417
+ const sourceStyles = getComputedStyle(source);
418
+ animations.push(
419
+ runStationarySharedElementAnimation(
420
+ clone,
421
+ from,
422
+ sourceStyles,
423
+ effectiveOpacity(source, outgoingLayer),
424
+ '0',
425
+ phase,
426
+ ),
427
+ );
428
+ continue;
429
+ }
430
+
431
+ const to = measureLocalRect(target, wrapper, wrapperRect);
432
+ if (!hasUsableRect(to)) {
433
+ const clone = appendPositionedClone(wrapper, overlay, source, from);
434
+ restore.push(hideOriginal(source));
435
+
436
+ const sourceStyles = getComputedStyle(source);
437
+ animations.push(
438
+ runStationarySharedElementAnimation(
439
+ clone,
440
+ from,
441
+ sourceStyles,
442
+ effectiveOpacity(source, outgoingLayer),
443
+ '0',
444
+ phase,
445
+ ),
446
+ );
447
+ continue;
448
+ }
449
+
450
+ handledIncoming.add(id);
451
+
452
+ const clone = appendPositionedClone(wrapper, overlay, source, from);
453
+ restore.push(hideOriginal(source), hideOriginal(target));
454
+
455
+ const sourceStyles = getComputedStyle(source);
456
+ const targetStyles = getComputedStyle(target);
457
+ const fromOpacity = effectiveOpacity(source, outgoingLayer);
458
+ const toOpacity = effectiveOpacity(target, incomingLayer);
459
+ const scaleX = to.width / from.width;
460
+ const scaleY = to.height / from.height;
461
+ const fromTransform = sharedElementTransform(from, 1, 1, localTransform(sourceStyles));
462
+ const toTransform = sharedElementTransform(to, scaleX, scaleY, localTransform(targetStyles));
463
+ animations.push(
464
+ clone.animate(
465
+ [
466
+ {
467
+ ...visualStyleKeyframe(sourceStyles, fromOpacity),
468
+ ...radiusKeyframe(sourceStyles),
469
+ transform: fromTransform,
470
+ },
471
+ {
472
+ ...visualStyleKeyframe(targetStyles, toOpacity),
473
+ ...radiusKeyframe(targetStyles, scaleX, scaleY),
474
+ transform: toTransform,
475
+ },
476
+ ],
477
+ sharedElementAnimationOptions(phase),
478
+ ),
479
+ ...runDescendantVisualStyleTransitions(clone, source, target, phase),
480
+ );
481
+ }
482
+
483
+ for (const [id, target] of incoming) {
484
+ if (handledIncoming.has(id) || outgoing.has(id)) continue;
485
+
486
+ const to = measureLocalRect(target, wrapper, wrapperRect);
487
+ if (!hasUsableRect(to)) continue;
488
+
489
+ const clone = appendPositionedClone(wrapper, overlay, target, to);
490
+ restore.push(hideOriginal(target));
491
+
492
+ const targetStyles = getComputedStyle(target);
493
+ animations.push(
494
+ runStationarySharedElementAnimation(
495
+ clone,
496
+ to,
497
+ targetStyles,
498
+ '0',
499
+ effectiveOpacity(target, incomingLayer),
500
+ phase,
501
+ ),
502
+ );
503
+ }
504
+
505
+ if (animations.length === 0) overlay.remove();
506
+
507
+ let cleaned = false;
508
+ return {
509
+ animations,
510
+ cleanup: () => {
511
+ if (cleaned) return;
512
+ cleaned = true;
513
+ for (const fn of restore) fn();
514
+ overlay.remove();
515
+ },
516
+ };
517
+ }
518
+
42
519
  export function SlideTransitionLayer({
43
520
  pages,
44
521
  index,
@@ -57,6 +534,7 @@ export function SlideTransitionLayer({
57
534
  const outgoingLayerRef = useRef<HTMLDivElement | null>(null);
58
535
  const incomingLayerRef = useRef<HTMLDivElement | null>(null);
59
536
  const animsRef = useRef<Animation[]>([]);
537
+ const cleanupRef = useRef<(() => void) | null>(null);
60
538
  const currentRef = useRef(current);
61
539
  currentRef.current = current;
62
540
 
@@ -74,6 +552,8 @@ export function SlideTransitionLayer({
74
552
  } catch {}
75
553
  }
76
554
  animsRef.current = [];
555
+ cleanupRef.current?.();
556
+ cleanupRef.current = null;
77
557
 
78
558
  const transition = resolveTransition(pages, next, moduleTransition);
79
559
  if (disabled || !transition) {
@@ -87,7 +567,7 @@ export function SlideTransitionLayer({
87
567
  setCurrent(next);
88
568
  }, [index, pages, moduleTransition, disabled]);
89
569
 
90
- useEffect(() => {
570
+ useLayoutEffect(() => {
91
571
  if (outgoing === null) return;
92
572
 
93
573
  const transition = resolveTransition(pages, current, moduleTransition);
@@ -110,17 +590,37 @@ export function SlideTransitionLayer({
110
590
  const enterAnim = runPhase(inc, transition.enter, duration, easing);
111
591
  if (exitAnim) anims.push(exitAnim);
112
592
  if (enterAnim) anims.push(enterAnim);
593
+
594
+ const cleanups: Array<() => void> = [];
595
+ const sharedPhase = resolveSharedElementTransition(transition.sharedElements, duration, easing);
596
+ if (sharedPhase) {
597
+ const shared = runSharedElementTransition(wrapper, out, inc, sharedPhase);
598
+ anims.push(...shared.animations);
599
+ cleanups.push(shared.cleanup);
600
+ if (!exitAnim && shared.animations.length > 0) cleanups.push(hideOriginal(out));
601
+ }
113
602
  animsRef.current = anims;
114
603
 
115
604
  if (anims.length === 0) {
605
+ for (const fn of cleanups) fn();
116
606
  setOutgoing(null);
117
607
  return;
118
608
  }
119
609
 
610
+ let cleaned = false;
611
+ const cleanup = () => {
612
+ if (cleaned) return;
613
+ cleaned = true;
614
+ for (const fn of cleanups) fn();
615
+ if (cleanupRef.current === cleanup) cleanupRef.current = null;
616
+ };
617
+ cleanupRef.current = cleanup;
618
+
120
619
  let cancelled = false;
121
620
  Promise.all(anims.map((a) => a.finished))
122
621
  .then(() => {
123
622
  if (cancelled) return;
623
+ cleanup();
124
624
  animsRef.current = [];
125
625
  setOutgoing(null);
126
626
  })
@@ -141,6 +641,8 @@ export function SlideTransitionLayer({
141
641
  } catch {}
142
642
  }
143
643
  animsRef.current = [];
644
+ cleanupRef.current?.();
645
+ cleanupRef.current = null;
144
646
  };
145
647
  }, []);
146
648
 
@@ -159,7 +661,7 @@ export function SlideTransitionLayer({
159
661
  return (
160
662
  <div
161
663
  ref={wrapperRef}
162
- className="relative h-full w-full"
664
+ className="relative h-full w-full overflow-hidden"
163
665
  style={{ background: 'var(--osd-bg)' }}
164
666
  >
165
667
  {OutgoingPage && outgoing !== null ? (
@@ -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; }
@@ -12,6 +12,13 @@ export type SlideTransition = {
12
12
  easing?: string;
13
13
  enter?: TransitionPhase;
14
14
  exit?: TransitionPhase;
15
+ sharedElements?: boolean | SharedElementTransition;
16
+ };
17
+
18
+ export type SharedElementTransition = {
19
+ duration?: number;
20
+ easing?: string;
21
+ delay?: number;
15
22
  };
16
23
 
17
24
  export function resolveTransition(