@motion-proto/live-tokens 0.99.1 → 0.101.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.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.101.0 — Video lightbox controls
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **VideoLightbox takes `controls`.** With `controls`, the open clip carries
|
|
8
|
+
the native video controls, which show while paused and hide during
|
|
9
|
+
playback, and a click on the clip pauses and resumes it instead of closing
|
|
10
|
+
the lightbox. A click on the scrim, the close button and Escape still close
|
|
11
|
+
it. Without `controls` the lightbox behaves as before.
|
|
12
|
+
|
|
13
|
+
## 0.100.0 — Lightbox zoom and hand tools
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- **The `extended` ImageLightbox works like an image viewer.** A click no
|
|
18
|
+
longer closes it; the close button and Escape do. The zoom tool is the
|
|
19
|
+
default, with a magnifier cursor: a click zooms in at the pointer, an
|
|
20
|
+
Alt-click zooms out, and a click at the zoom cap returns to the fit. Holding
|
|
21
|
+
Space switches to the hand tool until release. The bottom toolbar gains a
|
|
22
|
+
zoom tool button and a hand tool button beside the zoom in and out buttons.
|
|
23
|
+
The wheel and drag work over the scrim as well as the image. A lightbox
|
|
24
|
+
without `extended` still closes on a click.
|
|
25
|
+
|
|
3
26
|
## 0.99.1 — Lightbox zoom uses the whole screen
|
|
4
27
|
|
|
5
28
|
### Fixed
|
package/package.json
CHANGED
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
The modal portals to <body>, out of reach of a wrapper around the tile,
|
|
78
78
|
so a page that wants its own scrim has to say so here. */
|
|
79
79
|
scrim?: string | undefined;
|
|
80
|
-
/** When true,
|
|
80
|
+
/** When true, the open modal becomes a zoom view. A bottom toolbar holds a zoom tool, a hand tool, zoom in/out buttons, and a percent; the wheel zooms and a drag pans. The zoom tool is the default: a click zooms in at the pointer, an Alt-click zooms out, and a click at the cap returns to the fit. Holding Space switches to the hand tool until release. Only the close button and Escape close it. Without `extended`, a click on the image or the scrim closes. The percent measures the image against its natural resolution: 100% shows one source pixel per CSS pixel, so a large image opens fitted below 100%. Until the natural size is known it measures against the fitted view. */
|
|
81
81
|
extended?: boolean;
|
|
82
82
|
/** Maximum zoom, as a multiple of the image's natural resolution: `1` = 100%
|
|
83
83
|
of the source's real pixels (1 source px = 1 screen px), `2` = 200%. The
|
|
@@ -205,6 +205,12 @@
|
|
|
205
205
|
// Pointer drag for pan (extended + zoomed only).
|
|
206
206
|
let dragState: { startX: number; startY: number; baseX: number; baseY: number; pointerId: number } | null = null;
|
|
207
207
|
let didDrag = false;
|
|
208
|
+
let panning = $state(false);
|
|
209
|
+
|
|
210
|
+
let tool = $state<'zoom' | 'hand'>('zoom');
|
|
211
|
+
let spaceHeld = $state(false);
|
|
212
|
+
let altHeld = $state(false);
|
|
213
|
+
const activeTool = $derived(spaceHeld ? 'hand' : tool);
|
|
208
214
|
|
|
209
215
|
const aspectOf = (it?: GalleryImage) => {
|
|
210
216
|
if (!it) return undefined;
|
|
@@ -435,6 +441,9 @@
|
|
|
435
441
|
scale = 1;
|
|
436
442
|
offset = { x: 0, y: 0 };
|
|
437
443
|
index = 0;
|
|
444
|
+
tool = 'zoom';
|
|
445
|
+
spaceHeld = false;
|
|
446
|
+
altHeld = false;
|
|
438
447
|
open = false;
|
|
439
448
|
mounted = false;
|
|
440
449
|
document.body.style.overflow = '';
|
|
@@ -599,7 +608,7 @@
|
|
|
599
608
|
if (!dragState) return;
|
|
600
609
|
const dx = e.clientX - dragState.startX;
|
|
601
610
|
const dy = e.clientY - dragState.startY;
|
|
602
|
-
if (!didDrag && Math.hypot(dx, dy) > 4) didDrag = true;
|
|
611
|
+
if (!didDrag && Math.hypot(dx, dy) > 4) didDrag = panning = true;
|
|
603
612
|
offset = clampOffset(dragState.baseX + dx, dragState.baseY + dy, scale);
|
|
604
613
|
applyTransform(scale, offset);
|
|
605
614
|
}
|
|
@@ -609,14 +618,41 @@
|
|
|
609
618
|
(e.currentTarget as HTMLElement).releasePointerCapture(dragState.pointerId);
|
|
610
619
|
dragState = null;
|
|
611
620
|
}
|
|
621
|
+
panning = false;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
const atCap = $derived(scale >= maxScale - 0.001);
|
|
625
|
+
|
|
626
|
+
const cursor = $derived.by(() => {
|
|
627
|
+
if (!extended) return undefined;
|
|
628
|
+
if (panning) return 'grabbing';
|
|
629
|
+
if (activeTool === 'hand') return 'grab';
|
|
630
|
+
return altHeld || atCap ? 'zoom-out' : 'zoom-in';
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
function onZoomClick(e: MouseEvent) {
|
|
634
|
+
if (activeTool !== 'zoom') return;
|
|
635
|
+
const at = { x: e.clientX, y: e.clientY };
|
|
636
|
+
if (e.altKey) zoomTo(scale / ZOOM_STEP, at);
|
|
637
|
+
else if (atCap) zoomTo(MIN_SCALE);
|
|
638
|
+
else zoomTo(scale * ZOOM_STEP, at);
|
|
612
639
|
}
|
|
613
640
|
|
|
614
|
-
function onStageClick() {
|
|
641
|
+
function onStageClick(e: MouseEvent) {
|
|
615
642
|
if (didDrag) {
|
|
616
643
|
didDrag = false;
|
|
617
644
|
return;
|
|
618
645
|
}
|
|
619
|
-
if (
|
|
646
|
+
if (extended) onZoomClick(e);
|
|
647
|
+
else if (!isGallery) closeLightbox();
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
function onOverlayClick(e: MouseEvent) {
|
|
651
|
+
if (!extended) {
|
|
652
|
+
closeLightbox();
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
onStageClick(e);
|
|
620
656
|
}
|
|
621
657
|
|
|
622
658
|
// The stage (tabindex -1) is no tab stop, so an image-only lightbox holds
|
|
@@ -632,6 +668,12 @@
|
|
|
632
668
|
if (!open) return;
|
|
633
669
|
if (e.key === 'Escape') {
|
|
634
670
|
closeLightbox();
|
|
671
|
+
} else if (extended && e.key === ' ') {
|
|
672
|
+
// Also blocks Space from pressing the focused button, which on open is Close.
|
|
673
|
+
e.preventDefault();
|
|
674
|
+
spaceHeld = true;
|
|
675
|
+
} else if (e.key === 'Alt') {
|
|
676
|
+
altHeld = true;
|
|
635
677
|
} else if (e.key === 'Tab') {
|
|
636
678
|
onTab(e);
|
|
637
679
|
} else if (isGallery && e.key === 'ArrowRight') {
|
|
@@ -642,6 +684,19 @@
|
|
|
642
684
|
prev();
|
|
643
685
|
}
|
|
644
686
|
};
|
|
687
|
+
const onKeyUp = (e: KeyboardEvent) => {
|
|
688
|
+
if (e.key === ' ' && spaceHeld) {
|
|
689
|
+
e.preventDefault();
|
|
690
|
+
spaceHeld = false;
|
|
691
|
+
} else if (e.key === 'Alt') {
|
|
692
|
+
altHeld = false;
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
// A key released while the window is unfocused never reports its keyup.
|
|
696
|
+
const onBlur = () => {
|
|
697
|
+
spaceHeld = false;
|
|
698
|
+
altHeld = false;
|
|
699
|
+
};
|
|
645
700
|
vw = window.innerWidth;
|
|
646
701
|
vh = window.innerHeight;
|
|
647
702
|
const onResize = () => {
|
|
@@ -654,10 +709,14 @@
|
|
|
654
709
|
const onMotionChange = (e: MediaQueryListEvent) => { reducedMotion = e.matches; };
|
|
655
710
|
motionQuery.addEventListener('change', onMotionChange);
|
|
656
711
|
document.addEventListener('keydown', onKey);
|
|
712
|
+
document.addEventListener('keyup', onKeyUp);
|
|
713
|
+
window.addEventListener('blur', onBlur);
|
|
657
714
|
window.addEventListener('resize', onResize);
|
|
658
715
|
return () => {
|
|
659
716
|
motionQuery.removeEventListener('change', onMotionChange);
|
|
660
717
|
document.removeEventListener('keydown', onKey);
|
|
718
|
+
document.removeEventListener('keyup', onKeyUp);
|
|
719
|
+
window.removeEventListener('blur', onBlur);
|
|
661
720
|
window.removeEventListener('resize', onResize);
|
|
662
721
|
document.body.style.overflow = '';
|
|
663
722
|
restoreEditorOverlay();
|
|
@@ -721,8 +780,15 @@
|
|
|
721
780
|
class="image-lightbox-overlay"
|
|
722
781
|
style:--imagelightbox-scrim-surface={scrim}
|
|
723
782
|
class:active={open}
|
|
783
|
+
class:extended
|
|
784
|
+
style:cursor
|
|
724
785
|
aria-hidden="true"
|
|
725
|
-
onclick={
|
|
786
|
+
onclick={onOverlayClick}
|
|
787
|
+
onpointerdown={onPointerDown}
|
|
788
|
+
onpointermove={onPointerMove}
|
|
789
|
+
onpointerup={onPointerUp}
|
|
790
|
+
onpointercancel={onPointerUp}
|
|
791
|
+
onwheel={onWheel}
|
|
726
792
|
role="presentation"
|
|
727
793
|
></div>
|
|
728
794
|
|
|
@@ -736,6 +802,8 @@
|
|
|
736
802
|
class:shadow-box={shadow === 'box'}
|
|
737
803
|
class:shadow-content={shadow === 'content'}
|
|
738
804
|
class:zoomed={scale > MIN_SCALE}
|
|
805
|
+
class:extended
|
|
806
|
+
style:cursor
|
|
739
807
|
role="presentation"
|
|
740
808
|
tabindex="-1"
|
|
741
809
|
onclick={onStageClick}
|
|
@@ -806,6 +874,33 @@
|
|
|
806
874
|
|
|
807
875
|
{#if extended}
|
|
808
876
|
<div bind:this={toolbarEl} class="image-lightbox-toolbar" class:active={open}>
|
|
877
|
+
<button
|
|
878
|
+
class="image-lightbox-chrome-button"
|
|
879
|
+
type="button"
|
|
880
|
+
aria-label="Zoom tool"
|
|
881
|
+
aria-pressed={activeTool === 'zoom'}
|
|
882
|
+
onclick={() => (tool = 'zoom')}
|
|
883
|
+
>
|
|
884
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
885
|
+
<circle cx="11" cy="11" r="7" />
|
|
886
|
+
<path d="M21 21l-4.35-4.35" />
|
|
887
|
+
</svg>
|
|
888
|
+
</button>
|
|
889
|
+
<button
|
|
890
|
+
class="image-lightbox-chrome-button"
|
|
891
|
+
type="button"
|
|
892
|
+
aria-label="Hand tool (hold Space)"
|
|
893
|
+
aria-pressed={activeTool === 'hand'}
|
|
894
|
+
onclick={() => (tool = 'hand')}
|
|
895
|
+
>
|
|
896
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
897
|
+
<path d="M18 11V6a2 2 0 0 0-4 0" />
|
|
898
|
+
<path d="M14 10V4a2 2 0 0 0-4 0v2" />
|
|
899
|
+
<path d="M10 10.5V6a2 2 0 0 0-4 0v8" />
|
|
900
|
+
<path d="M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15" />
|
|
901
|
+
</svg>
|
|
902
|
+
</button>
|
|
903
|
+
<span class="image-lightbox-toolbar-divider" aria-hidden="true"></span>
|
|
809
904
|
<button
|
|
810
905
|
class="image-lightbox-chrome-button"
|
|
811
906
|
type="button"
|
|
@@ -822,7 +917,7 @@
|
|
|
822
917
|
class="image-lightbox-chrome-button"
|
|
823
918
|
type="button"
|
|
824
919
|
aria-label="Zoom in"
|
|
825
|
-
disabled={
|
|
920
|
+
disabled={atCap}
|
|
826
921
|
onclick={() => zoomTo(scale * ZOOM_STEP)}
|
|
827
922
|
>
|
|
828
923
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
@@ -959,7 +1054,6 @@
|
|
|
959
1054
|
.image-lightbox-stage {
|
|
960
1055
|
position: fixed;
|
|
961
1056
|
z-index: var(--z-modal);
|
|
962
|
-
cursor: zoom-out;
|
|
963
1057
|
border: var(--imagelightbox-tile-border-width) solid var(--imagelightbox-tile-border);
|
|
964
1058
|
border-radius: var(--imagelightbox-tile-radius);
|
|
965
1059
|
}
|
|
@@ -971,8 +1065,8 @@
|
|
|
971
1065
|
overflow: hidden;
|
|
972
1066
|
}
|
|
973
1067
|
|
|
974
|
-
.image-lightbox-stage.
|
|
975
|
-
cursor:
|
|
1068
|
+
.image-lightbox-stage:not(.extended) {
|
|
1069
|
+
cursor: zoom-out;
|
|
976
1070
|
}
|
|
977
1071
|
|
|
978
1072
|
.image-lightbox-stage.zoomed .image-lightbox-clip {
|
|
@@ -1020,6 +1114,9 @@
|
|
|
1020
1114
|
|
|
1021
1115
|
.image-lightbox-overlay.active {
|
|
1022
1116
|
pointer-events: auto;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
.image-lightbox-overlay.active:not(.extended) {
|
|
1023
1120
|
cursor: zoom-out;
|
|
1024
1121
|
}
|
|
1025
1122
|
|
|
@@ -1142,10 +1239,18 @@
|
|
|
1142
1239
|
transition: background var(--duration-200) ease;
|
|
1143
1240
|
}
|
|
1144
1241
|
|
|
1145
|
-
.image-lightbox-chrome-button:hover:not(:disabled)
|
|
1242
|
+
.image-lightbox-chrome-button:hover:not(:disabled),
|
|
1243
|
+
.image-lightbox-chrome-button[aria-pressed='true'] {
|
|
1146
1244
|
background: var(--imagelightbox-chrome-hover-surface);
|
|
1147
1245
|
}
|
|
1148
1246
|
|
|
1247
|
+
.image-lightbox-toolbar-divider {
|
|
1248
|
+
align-self: stretch;
|
|
1249
|
+
width: var(--imagelightbox-chrome-border-width);
|
|
1250
|
+
margin: var(--space-4) var(--space-4);
|
|
1251
|
+
background: var(--imagelightbox-chrome-border);
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1149
1254
|
.image-lightbox-chrome-button:disabled {
|
|
1150
1255
|
opacity: 0.4;
|
|
1151
1256
|
cursor: not-allowed;
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
'`badge` lays a play badge over the thumbnail, so a still reads as a clip. `none` shows the still alone.',
|
|
16
16
|
inline: 'true renders the open lightbox in flow, without the thumbnail. The editor preview uses it.',
|
|
17
17
|
loop: 'true repeats the clip.',
|
|
18
|
+
controls:
|
|
19
|
+
'true gives the open clip the native video controls, which show while paused and hide during playback. A click on the clip then pauses and resumes it, and only the scrim, the close button and Escape close the lightbox. false leaves the clip bare, and a click on it closes the lightbox.',
|
|
18
20
|
hoverPlay:
|
|
19
21
|
'true plays the thumbnail muted under the pointer, and rewinds it on the way out. A reader who asked for less motion keeps the still.',
|
|
20
22
|
stretch:
|
|
@@ -42,6 +44,8 @@
|
|
|
42
44
|
width?: number;
|
|
43
45
|
height?: number;
|
|
44
46
|
loop?: boolean;
|
|
47
|
+
/** Native controls on the open clip; a click on the clip then toggles play instead of closing. */
|
|
48
|
+
controls?: boolean;
|
|
45
49
|
/** "badge" lays a play badge over the thumbnail. */
|
|
46
50
|
chrome?: 'badge' | 'none';
|
|
47
51
|
/** Renders the open lightbox in flow, without the thumbnail. Used by the editor preview. */
|
|
@@ -67,6 +71,7 @@
|
|
|
67
71
|
width = undefined,
|
|
68
72
|
height = undefined,
|
|
69
73
|
loop = false,
|
|
74
|
+
controls = false,
|
|
70
75
|
chrome = 'none',
|
|
71
76
|
inline = false,
|
|
72
77
|
hoverPlay = false,
|
|
@@ -209,8 +214,8 @@
|
|
|
209
214
|
</div>
|
|
210
215
|
|
|
211
216
|
{#if mounted}
|
|
212
|
-
<!--
|
|
213
|
-
|
|
217
|
+
<!-- A click closes it, as do the close button and Escape. With
|
|
218
|
+
`controls`, the clip keeps its own clicks for the native controls. -->
|
|
214
219
|
<div
|
|
215
220
|
bind:this={modalEl}
|
|
216
221
|
class="videolightbox-modal"
|
|
@@ -226,8 +231,19 @@
|
|
|
226
231
|
onkeydown={onModalKey}
|
|
227
232
|
>
|
|
228
233
|
<!-- No caption track ships with the source footage. -->
|
|
229
|
-
<!-- svelte-ignore a11y_media_has_caption -->
|
|
230
|
-
<video
|
|
234
|
+
<!-- svelte-ignore a11y_media_has_caption, a11y_click_events_have_key_events, a11y_no_noninteractive_element_interactions -->
|
|
235
|
+
<video
|
|
236
|
+
bind:this={videoEl}
|
|
237
|
+
class="videolightbox-video"
|
|
238
|
+
{src}
|
|
239
|
+
{poster}
|
|
240
|
+
{loop}
|
|
241
|
+
{controls}
|
|
242
|
+
controlslist={controls ? 'nodownload' : undefined}
|
|
243
|
+
playsinline
|
|
244
|
+
class:has-controls={controls}
|
|
245
|
+
onclick={controls ? (e) => e.stopPropagation() : undefined}
|
|
246
|
+
></video>
|
|
231
247
|
<button
|
|
232
248
|
bind:this={closeBtnEl}
|
|
233
249
|
type="button"
|
|
@@ -445,6 +461,10 @@
|
|
|
445
461
|
}
|
|
446
462
|
}
|
|
447
463
|
|
|
464
|
+
.videolightbox-video.has-controls {
|
|
465
|
+
cursor: default;
|
|
466
|
+
}
|
|
467
|
+
|
|
448
468
|
/* The clip plays at its own pixel size and shrinks only to fit the screen. */
|
|
449
469
|
.videolightbox-video {
|
|
450
470
|
display: block;
|