@motion-proto/live-tokens 0.99.0 → 0.100.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 +24 -0
- package/package.json +1 -1
- package/src/system/components/ImageLightbox.svelte +136 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.100.0 — Lightbox zoom and hand tools
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- **The `extended` ImageLightbox works like an image viewer.** A click no
|
|
8
|
+
longer closes it; the close button and Escape do. The zoom tool is the
|
|
9
|
+
default, with a magnifier cursor: a click zooms in at the pointer, an
|
|
10
|
+
Alt-click zooms out, and a click at the zoom cap returns to the fit. Holding
|
|
11
|
+
Space switches to the hand tool until release. The bottom toolbar gains a
|
|
12
|
+
zoom tool button and a hand tool button beside the zoom in and out buttons.
|
|
13
|
+
The wheel and drag work over the scrim as well as the image. A lightbox
|
|
14
|
+
without `extended` still closes on a click.
|
|
15
|
+
|
|
16
|
+
## 0.99.1 — Lightbox zoom uses the whole screen
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- **ImageLightbox zoom fills the viewport.** With `extended`, a zoomed image
|
|
21
|
+
used to stay clipped to its fitted frame, so a tall screenshot zoomed in
|
|
22
|
+
showed only a narrow column. The zoomed image now spills past the frame
|
|
23
|
+
across the whole viewport. An image larger than the viewport pans until
|
|
24
|
+
its edge meets the viewport's edge; a smaller one pans until an edge would
|
|
25
|
+
leave the screen. The cursor shows `grab` while zoomed.
|
|
26
|
+
|
|
3
27
|
## 0.99.0 — Accessibility reports by theme
|
|
4
28
|
|
|
5
29
|
### Changed
|
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;
|
|
@@ -248,14 +254,23 @@
|
|
|
248
254
|
};
|
|
249
255
|
}
|
|
250
256
|
|
|
257
|
+
// The zoomed image spills past the stage onto the whole viewport. Larger than
|
|
258
|
+
// the viewport on an axis, it pans until an edge meets the viewport's edge;
|
|
259
|
+
// smaller, it pans until an edge would leave the screen.
|
|
260
|
+
function clampAxis(v: number, start: number, size: number, s: number, view: number) {
|
|
261
|
+
const half = (size * s) / 2;
|
|
262
|
+
const center = start + size / 2;
|
|
263
|
+
const toNear = half - center;
|
|
264
|
+
const toFar = view - center - half;
|
|
265
|
+
return Math.max(Math.min(toNear, toFar), Math.min(Math.max(toNear, toFar), v));
|
|
266
|
+
}
|
|
267
|
+
|
|
251
268
|
function clampOffset(x: number, y: number, s: number) {
|
|
252
269
|
if (!stageEl) return { x: 0, y: 0 };
|
|
253
270
|
const r = stageEl.getBoundingClientRect();
|
|
254
|
-
const maxX = Math.max(0, (r.width * s - r.width) / 2);
|
|
255
|
-
const maxY = Math.max(0, (r.height * s - r.height) / 2);
|
|
256
271
|
return {
|
|
257
|
-
x:
|
|
258
|
-
y:
|
|
272
|
+
x: clampAxis(x, r.left, r.width, s, vw),
|
|
273
|
+
y: clampAxis(y, r.top, r.height, s, vh),
|
|
259
274
|
};
|
|
260
275
|
}
|
|
261
276
|
|
|
@@ -426,6 +441,9 @@
|
|
|
426
441
|
scale = 1;
|
|
427
442
|
offset = { x: 0, y: 0 };
|
|
428
443
|
index = 0;
|
|
444
|
+
tool = 'zoom';
|
|
445
|
+
spaceHeld = false;
|
|
446
|
+
altHeld = false;
|
|
429
447
|
open = false;
|
|
430
448
|
mounted = false;
|
|
431
449
|
document.body.style.overflow = '';
|
|
@@ -590,7 +608,7 @@
|
|
|
590
608
|
if (!dragState) return;
|
|
591
609
|
const dx = e.clientX - dragState.startX;
|
|
592
610
|
const dy = e.clientY - dragState.startY;
|
|
593
|
-
if (!didDrag && Math.hypot(dx, dy) > 4) didDrag = true;
|
|
611
|
+
if (!didDrag && Math.hypot(dx, dy) > 4) didDrag = panning = true;
|
|
594
612
|
offset = clampOffset(dragState.baseX + dx, dragState.baseY + dy, scale);
|
|
595
613
|
applyTransform(scale, offset);
|
|
596
614
|
}
|
|
@@ -600,14 +618,41 @@
|
|
|
600
618
|
(e.currentTarget as HTMLElement).releasePointerCapture(dragState.pointerId);
|
|
601
619
|
dragState = null;
|
|
602
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);
|
|
603
639
|
}
|
|
604
640
|
|
|
605
|
-
function onStageClick() {
|
|
641
|
+
function onStageClick(e: MouseEvent) {
|
|
606
642
|
if (didDrag) {
|
|
607
643
|
didDrag = false;
|
|
608
644
|
return;
|
|
609
645
|
}
|
|
610
|
-
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);
|
|
611
656
|
}
|
|
612
657
|
|
|
613
658
|
// The stage (tabindex -1) is no tab stop, so an image-only lightbox holds
|
|
@@ -623,6 +668,12 @@
|
|
|
623
668
|
if (!open) return;
|
|
624
669
|
if (e.key === 'Escape') {
|
|
625
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;
|
|
626
677
|
} else if (e.key === 'Tab') {
|
|
627
678
|
onTab(e);
|
|
628
679
|
} else if (isGallery && e.key === 'ArrowRight') {
|
|
@@ -633,6 +684,19 @@
|
|
|
633
684
|
prev();
|
|
634
685
|
}
|
|
635
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
|
+
};
|
|
636
700
|
vw = window.innerWidth;
|
|
637
701
|
vh = window.innerHeight;
|
|
638
702
|
const onResize = () => {
|
|
@@ -645,10 +709,14 @@
|
|
|
645
709
|
const onMotionChange = (e: MediaQueryListEvent) => { reducedMotion = e.matches; };
|
|
646
710
|
motionQuery.addEventListener('change', onMotionChange);
|
|
647
711
|
document.addEventListener('keydown', onKey);
|
|
712
|
+
document.addEventListener('keyup', onKeyUp);
|
|
713
|
+
window.addEventListener('blur', onBlur);
|
|
648
714
|
window.addEventListener('resize', onResize);
|
|
649
715
|
return () => {
|
|
650
716
|
motionQuery.removeEventListener('change', onMotionChange);
|
|
651
717
|
document.removeEventListener('keydown', onKey);
|
|
718
|
+
document.removeEventListener('keyup', onKeyUp);
|
|
719
|
+
window.removeEventListener('blur', onBlur);
|
|
652
720
|
window.removeEventListener('resize', onResize);
|
|
653
721
|
document.body.style.overflow = '';
|
|
654
722
|
restoreEditorOverlay();
|
|
@@ -712,8 +780,15 @@
|
|
|
712
780
|
class="image-lightbox-overlay"
|
|
713
781
|
style:--imagelightbox-scrim-surface={scrim}
|
|
714
782
|
class:active={open}
|
|
783
|
+
class:extended
|
|
784
|
+
style:cursor
|
|
715
785
|
aria-hidden="true"
|
|
716
|
-
onclick={
|
|
786
|
+
onclick={onOverlayClick}
|
|
787
|
+
onpointerdown={onPointerDown}
|
|
788
|
+
onpointermove={onPointerMove}
|
|
789
|
+
onpointerup={onPointerUp}
|
|
790
|
+
onpointercancel={onPointerUp}
|
|
791
|
+
onwheel={onWheel}
|
|
717
792
|
role="presentation"
|
|
718
793
|
></div>
|
|
719
794
|
|
|
@@ -726,7 +801,10 @@
|
|
|
726
801
|
class="image-lightbox-stage"
|
|
727
802
|
class:shadow-box={shadow === 'box'}
|
|
728
803
|
class:shadow-content={shadow === 'content'}
|
|
729
|
-
|
|
804
|
+
class:zoomed={scale > MIN_SCALE}
|
|
805
|
+
class:extended
|
|
806
|
+
style:cursor
|
|
807
|
+
role="presentation"
|
|
730
808
|
tabindex="-1"
|
|
731
809
|
onclick={onStageClick}
|
|
732
810
|
onpointerdown={onPointerDown}
|
|
@@ -796,6 +874,33 @@
|
|
|
796
874
|
|
|
797
875
|
{#if extended}
|
|
798
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>
|
|
799
904
|
<button
|
|
800
905
|
class="image-lightbox-chrome-button"
|
|
801
906
|
type="button"
|
|
@@ -812,7 +917,7 @@
|
|
|
812
917
|
class="image-lightbox-chrome-button"
|
|
813
918
|
type="button"
|
|
814
919
|
aria-label="Zoom in"
|
|
815
|
-
disabled={
|
|
920
|
+
disabled={atCap}
|
|
816
921
|
onclick={() => zoomTo(scale * ZOOM_STEP)}
|
|
817
922
|
>
|
|
818
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">
|
|
@@ -949,7 +1054,6 @@
|
|
|
949
1054
|
.image-lightbox-stage {
|
|
950
1055
|
position: fixed;
|
|
951
1056
|
z-index: var(--z-modal);
|
|
952
|
-
cursor: zoom-out;
|
|
953
1057
|
border: var(--imagelightbox-tile-border-width) solid var(--imagelightbox-tile-border);
|
|
954
1058
|
border-radius: var(--imagelightbox-tile-radius);
|
|
955
1059
|
}
|
|
@@ -961,6 +1065,14 @@
|
|
|
961
1065
|
overflow: hidden;
|
|
962
1066
|
}
|
|
963
1067
|
|
|
1068
|
+
.image-lightbox-stage:not(.extended) {
|
|
1069
|
+
cursor: zoom-out;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
.image-lightbox-stage.zoomed .image-lightbox-clip {
|
|
1073
|
+
overflow: visible;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
964
1076
|
.image-lightbox-transform {
|
|
965
1077
|
position: absolute;
|
|
966
1078
|
inset: 0;
|
|
@@ -1002,6 +1114,9 @@
|
|
|
1002
1114
|
|
|
1003
1115
|
.image-lightbox-overlay.active {
|
|
1004
1116
|
pointer-events: auto;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
.image-lightbox-overlay.active:not(.extended) {
|
|
1005
1120
|
cursor: zoom-out;
|
|
1006
1121
|
}
|
|
1007
1122
|
|
|
@@ -1124,10 +1239,18 @@
|
|
|
1124
1239
|
transition: background var(--duration-200) ease;
|
|
1125
1240
|
}
|
|
1126
1241
|
|
|
1127
|
-
.image-lightbox-chrome-button:hover:not(:disabled)
|
|
1242
|
+
.image-lightbox-chrome-button:hover:not(:disabled),
|
|
1243
|
+
.image-lightbox-chrome-button[aria-pressed='true'] {
|
|
1128
1244
|
background: var(--imagelightbox-chrome-hover-surface);
|
|
1129
1245
|
}
|
|
1130
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
|
+
|
|
1131
1254
|
.image-lightbox-chrome-button:disabled {
|
|
1132
1255
|
opacity: 0.4;
|
|
1133
1256
|
cursor: not-allowed;
|