@mittwald/flow-react-components 1.6.0-next.68 → 1.6.0-next.69

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 (37) hide show
  1. package/dist/assets/component-index.json +1 -1
  2. package/dist/assets/doc-properties.json +1 -1
  3. package/dist/css/all-layered.css +1 -1
  4. package/dist/css/all.css +1 -1
  5. package/dist/js/_virtual/_22.locale.mjs +6 -2
  6. package/dist/js/default.mjs +2 -1
  7. package/dist/js/packages/components/src/components/FileCard/components/FileSizeText/FileSizeText.mjs +25 -6
  8. package/dist/js/packages/components/src/components/FileCard/components/FileSizeText/FileSizeText.mjs.map +1 -1
  9. package/dist/js/packages/components/src/components/LightBox/LightBox.mjs +16 -8
  10. package/dist/js/packages/components/src/components/LightBox/LightBox.mjs.map +1 -1
  11. package/dist/js/packages/components/src/components/LightBox/LightBox.module.mjs +3 -1
  12. package/dist/js/packages/components/src/components/LightBox/LightBox.module.mjs.map +1 -1
  13. package/dist/js/packages/components/src/components/LightBox/components/LightBoxGallery/LightBoxGallery.mjs +15 -12
  14. package/dist/js/packages/components/src/components/LightBox/components/LightBoxGallery/LightBoxGallery.mjs.map +1 -1
  15. package/dist/js/packages/components/src/components/LightBox/components/LightBoxGallery/LightBoxGallery.module.mjs.map +1 -1
  16. package/dist/js/packages/components/src/components/LightBox/components/LightBoxGalleryItem/LightBoxGalleryItem.mjs +7 -6
  17. package/dist/js/packages/components/src/components/LightBox/components/LightBoxGalleryItem/LightBoxGalleryItem.mjs.map +1 -1
  18. package/dist/js/packages/components/src/components/LightBox/components/LightBoxZoom/LightBoxZoom.mjs +82 -0
  19. package/dist/js/packages/components/src/components/LightBox/components/LightBoxZoom/LightBoxZoom.mjs.map +1 -0
  20. package/dist/js/packages/components/src/components/LightBox/components/LightBoxZoom/LightBoxZoom.module.mjs +20 -0
  21. package/dist/js/packages/components/src/components/LightBox/components/LightBoxZoom/LightBoxZoom.module.mjs.map +1 -0
  22. package/dist/js/packages/components/src/components/LightBox/components/LightBoxZoom/hooks/useZoom.mjs +282 -0
  23. package/dist/js/packages/components/src/components/LightBox/components/LightBoxZoom/hooks/useZoom.mjs.map +1 -0
  24. package/dist/js/packages/components/src/components/LightBox/components/LightBoxZoom/lib/zoomTransform.mjs +58 -0
  25. package/dist/js/packages/components/src/components/LightBox/components/LightBoxZoom/lib/zoomTransform.mjs.map +1 -0
  26. package/dist/js/packages/components/src/views/LightBoxZoomView.mjs +15 -0
  27. package/dist/js/packages/components/src/views/LightBoxZoomView.mjs.map +1 -0
  28. package/dist/types/components/LightBox/LightBox.d.ts +6 -0
  29. package/dist/types/components/LightBox/components/LightBoxGalleryItem/LightBoxGalleryItem.d.ts +3 -4
  30. package/dist/types/components/LightBox/components/LightBoxZoom/LightBoxZoom.d.ts +12 -0
  31. package/dist/types/components/LightBox/components/LightBoxZoom/hooks/useZoom.d.ts +16 -0
  32. package/dist/types/components/LightBox/components/LightBoxZoom/index.d.ts +2 -0
  33. package/dist/types/components/LightBox/components/LightBoxZoom/lib/zoomTransform.d.ts +43 -0
  34. package/dist/types/components/LightBox/components/LightBoxZoom/view.d.ts +7 -0
  35. package/dist/types/components/LightBox/index.d.ts +1 -0
  36. package/dist/types/views/LightBoxZoomView.d.ts +4 -0
  37. package/package.json +10 -10
@@ -0,0 +1,282 @@
1
+ "use client"
2
+ /* */
3
+ import { clampTranslation, initialZoomTransform, isZoomed, panBy, zoomTo } from "../lib/zoomTransform.mjs";
4
+ import { useEffect, useRef, useState } from "react";
5
+ // src/components/LightBox/components/LightBoxZoom/hooks/useZoom.ts
6
+ /** Raised for an image whose natural size needs more. */
7
+ var minMaxScale = 3;
8
+ /** The scale a click, a double tap or Enter zooms to. */
9
+ var toggleScale = 2;
10
+ var keyboardScaleStep = .5;
11
+ var keyboardPanStep = 50;
12
+ /** Movement in px below which a press still counts as a click or tap. */
13
+ var tapTolerance = 4;
14
+ var doubleTapDelay = 300;
15
+ var doubleTapDistance = 30;
16
+ var wheelLineHeight = 16;
17
+ /** The zoom area is not scaled itself, only its content. */
18
+ var frameOf = (element) => {
19
+ const rect = element?.getBoundingClientRect();
20
+ if (!rect) return {
21
+ width: 0,
22
+ height: 0,
23
+ screen: {
24
+ left: 0,
25
+ right: 0,
26
+ top: 0,
27
+ bottom: 0
28
+ }
29
+ };
30
+ const centerX = rect.left + rect.width / 2;
31
+ const centerY = rect.top + rect.height / 2;
32
+ return {
33
+ width: rect.width,
34
+ height: rect.height,
35
+ screen: {
36
+ left: -centerX,
37
+ right: window.innerWidth - centerX,
38
+ top: -centerY,
39
+ bottom: window.innerHeight - centerY
40
+ }
41
+ };
42
+ };
43
+ /**
44
+ * Far enough to show an image at its natural size. `offsetWidth` is the width
45
+ * before the zoom's transform.
46
+ */
47
+ var maxScaleOf = (element) => {
48
+ const image = element?.querySelector("img");
49
+ if (!image?.naturalWidth || !image.offsetWidth) return minMaxScale;
50
+ return Math.max(minMaxScale, image.naturalWidth / image.offsetWidth);
51
+ };
52
+ /** Client coordinates as an offset from the center of the zoom area. */
53
+ var pointIn = (element, clientX, clientY) => {
54
+ const rect = element?.getBoundingClientRect();
55
+ if (!rect) return {
56
+ x: 0,
57
+ y: 0
58
+ };
59
+ return {
60
+ x: clientX - rect.left - rect.width / 2,
61
+ y: clientY - rect.top - rect.height / 2
62
+ };
63
+ };
64
+ var distance = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
65
+ var midpoint = (a, b) => ({
66
+ x: (a.x + b.x) / 2,
67
+ y: (a.y + b.y) / 2
68
+ });
69
+ var useZoom = (ref, isEnabled) => {
70
+ const [transform, setTransform] = useState(initialZoomTransform);
71
+ const [isAnimated, setIsAnimated] = useState(false);
72
+ const [isDragging, setIsDragging] = useState(false);
73
+ const [frame, setFrame] = useState(null);
74
+ const pointers = useRef(/* @__PURE__ */ new Map());
75
+ const gesture = useRef(null);
76
+ const pressStart = useRef(null);
77
+ const hasMoved = useRef(false);
78
+ const isOwnPress = useRef(false);
79
+ const lastTap = useRef(null);
80
+ const getFrame = () => frameOf(ref.current);
81
+ const getMaxScale = () => maxScaleOf(ref.current);
82
+ const toPoint = (clientX, clientY) => pointIn(ref.current, clientX, clientY);
83
+ const update = (next, animated) => {
84
+ setIsAnimated(animated);
85
+ setFrame(getFrame());
86
+ setTransform(next);
87
+ };
88
+ const toggleAt = (point) => update((current) => isZoomed(current) ? initialZoomTransform : zoomTo(current, toggleScale, getMaxScale(), getFrame(), point), true);
89
+ const zoomBy = (step) => update((current) => zoomTo(current, current.scale + step, getMaxScale(), getFrame(), {
90
+ x: 0,
91
+ y: 0
92
+ }), true);
93
+ useEffect(() => {
94
+ const element = ref.current;
95
+ if (!element || !isEnabled) return;
96
+ const zoomByFactor = (factor, clientX, clientY) => {
97
+ if (document.activeElement !== element) element.focus({ preventScroll: true });
98
+ const point = pointIn(element, clientX, clientY);
99
+ setIsAnimated(false);
100
+ setFrame(frameOf(element));
101
+ setTransform((current) => zoomTo(current, current.scale * factor, maxScaleOf(element), frameOf(element), point));
102
+ };
103
+ const handleWheel = (event) => {
104
+ if (event.deltaY === 0) return;
105
+ event.preventDefault();
106
+ const deltaY = event.deltaMode === WheelEvent.DOM_DELTA_LINE ? event.deltaY * wheelLineHeight : event.deltaY;
107
+ const factor = Math.exp(-deltaY * (event.ctrlKey ? .01 : .002));
108
+ zoomByFactor(factor, event.clientX, event.clientY);
109
+ };
110
+ let gestureScale = 1;
111
+ const handleGestureStart = (event) => {
112
+ event.preventDefault();
113
+ gestureScale = 1;
114
+ };
115
+ const handleGestureChange = (event) => {
116
+ event.preventDefault();
117
+ const { scale, clientX, clientY } = event;
118
+ zoomByFactor(scale / gestureScale, clientX, clientY);
119
+ gestureScale = scale;
120
+ };
121
+ element.addEventListener("wheel", handleWheel, { passive: false });
122
+ element.addEventListener("gesturestart", handleGestureStart);
123
+ element.addEventListener("gesturechange", handleGestureChange);
124
+ return () => {
125
+ element.removeEventListener("wheel", handleWheel);
126
+ element.removeEventListener("gesturestart", handleGestureStart);
127
+ element.removeEventListener("gesturechange", handleGestureChange);
128
+ };
129
+ }, [ref, isEnabled]);
130
+ const zoomed = isZoomed(transform);
131
+ useEffect(() => {
132
+ if (!zoomed) return;
133
+ const handleResize = () => {
134
+ const nextFrame = frameOf(ref.current);
135
+ setIsAnimated(false);
136
+ setFrame(nextFrame);
137
+ setTransform((current) => clampTranslation(current, nextFrame));
138
+ };
139
+ window.addEventListener("resize", handleResize);
140
+ return () => window.removeEventListener("resize", handleResize);
141
+ }, [ref, zoomed]);
142
+ const startGesture = () => {
143
+ const [first, second] = Array.from(pointers.current.values());
144
+ if (first && second) gesture.current = {
145
+ type: "pinch",
146
+ startDistance: distance(first, second),
147
+ startMidpoint: midpoint(first, second),
148
+ startTransform: transform
149
+ };
150
+ else if (first && isZoomed(transform)) gesture.current = {
151
+ type: "pan",
152
+ start: first,
153
+ startTransform: transform
154
+ };
155
+ else gesture.current = null;
156
+ setIsDragging(gesture.current !== null);
157
+ };
158
+ const onPointerDown = (event) => {
159
+ if (event.pointerType === "mouse" && event.button !== 0) return;
160
+ const point = toPoint(event.clientX, event.clientY);
161
+ pointers.current.set(event.pointerId, point);
162
+ if (pointers.current.size === 1) {
163
+ pressStart.current = point;
164
+ hasMoved.current = false;
165
+ isOwnPress.current = isZoomed(transform);
166
+ } else {
167
+ isOwnPress.current = true;
168
+ hasMoved.current = true;
169
+ }
170
+ if (isOwnPress.current) event.stopPropagation();
171
+ event.currentTarget.setPointerCapture(event.pointerId);
172
+ startGesture();
173
+ };
174
+ const onPointerMove = (event) => {
175
+ if (!pointers.current.has(event.pointerId)) return;
176
+ const point = toPoint(event.clientX, event.clientY);
177
+ pointers.current.set(event.pointerId, point);
178
+ if (pressStart.current && distance(pressStart.current, point) > tapTolerance) hasMoved.current = true;
179
+ const current = gesture.current;
180
+ if (!current) return;
181
+ event.stopPropagation();
182
+ if (current.type === "pan") {
183
+ const delta = {
184
+ x: point.x - current.start.x,
185
+ y: point.y - current.start.y
186
+ };
187
+ update(() => panBy(current.startTransform, delta, getFrame()), false);
188
+ return;
189
+ }
190
+ const [first, second] = Array.from(pointers.current.values());
191
+ if (!first || !second) return;
192
+ const scale = current.startTransform.scale * distance(first, second) / current.startDistance;
193
+ update(() => zoomTo(current.startTransform, scale, getMaxScale(), getFrame(), current.startMidpoint, midpoint(first, second)), false);
194
+ };
195
+ const handleTap = (event, point) => {
196
+ if (event.pointerType !== "touch") {
197
+ toggleAt(point);
198
+ return;
199
+ }
200
+ const now = event.timeStamp;
201
+ const previous = lastTap.current;
202
+ if (previous && now - previous.time < doubleTapDelay && distance(previous.point, point) < doubleTapDistance) {
203
+ lastTap.current = null;
204
+ toggleAt(point);
205
+ } else lastTap.current = {
206
+ time: now,
207
+ point
208
+ };
209
+ };
210
+ const endPointer = (event, isTap) => {
211
+ if (!pointers.current.delete(event.pointerId)) return;
212
+ if (isOwnPress.current) event.stopPropagation();
213
+ if (pointers.current.size > 0) {
214
+ startGesture();
215
+ return;
216
+ }
217
+ if (isTap && !hasMoved.current) handleTap(event, toPoint(event.clientX, event.clientY));
218
+ gesture.current = null;
219
+ pressStart.current = null;
220
+ setIsDragging(false);
221
+ };
222
+ const onPointerUp = (event) => endPointer(event, true);
223
+ const onPointerCancel = (event) => endPointer(event, false);
224
+ const onKeyDown = (event) => {
225
+ if (event.ctrlKey || event.metaKey || event.altKey) return;
226
+ const pan = (x, y) => {
227
+ if (!isZoomed(transform)) return;
228
+ event.preventDefault();
229
+ event.stopPropagation();
230
+ update((current) => panBy(current, {
231
+ x,
232
+ y
233
+ }, getFrame()), true);
234
+ };
235
+ switch (event.key) {
236
+ case "+":
237
+ case "=":
238
+ event.preventDefault();
239
+ zoomBy(keyboardScaleStep);
240
+ break;
241
+ case "-":
242
+ event.preventDefault();
243
+ zoomBy(-.5);
244
+ break;
245
+ case "Enter":
246
+ case " ":
247
+ event.preventDefault();
248
+ toggleAt({
249
+ x: 0,
250
+ y: 0
251
+ });
252
+ break;
253
+ case "ArrowLeft":
254
+ pan(keyboardPanStep, 0);
255
+ break;
256
+ case "ArrowRight":
257
+ pan(-50, 0);
258
+ break;
259
+ case "ArrowUp":
260
+ pan(0, keyboardPanStep);
261
+ break;
262
+ case "ArrowDown": pan(0, -50);
263
+ }
264
+ };
265
+ return {
266
+ transform,
267
+ frame,
268
+ isZoomed: zoomed,
269
+ isAnimated,
270
+ isDragging,
271
+ handlers: {
272
+ onPointerDown,
273
+ onPointerMove,
274
+ onPointerUp,
275
+ onPointerCancel,
276
+ onKeyDown
277
+ }
278
+ };
279
+ };
280
+ export { useZoom };
281
+
282
+ //# sourceMappingURL=useZoom.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useZoom.mjs","names":[],"sources":["../../../../../../../../../../src/components/LightBox/components/LightBoxZoom/hooks/useZoom.ts"],"sourcesContent":["import {\n type KeyboardEvent,\n type PointerEvent,\n type RefObject,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport {\n clampTranslation,\n initialZoomTransform,\n isZoomed,\n panBy,\n type Point,\n zoomTo,\n type ZoomFrame,\n type ZoomTransform,\n} from \"../lib/zoomTransform\";\n\n/** Raised for an image whose natural size needs more. */\nconst minMaxScale = 3;\n/** The scale a click, a double tap or Enter zooms to. */\nconst toggleScale = 2;\nconst keyboardScaleStep = 0.5;\nconst keyboardPanStep = 50;\n/** Movement in px below which a press still counts as a click or tap. */\nconst tapTolerance = 4;\nconst doubleTapDelay = 300;\nconst doubleTapDistance = 30;\nconst wheelLineHeight = 16;\n\ntype Gesture =\n | { type: \"pan\"; start: Point; startTransform: ZoomTransform }\n | {\n type: \"pinch\";\n startDistance: number;\n startMidpoint: Point;\n startTransform: ZoomTransform;\n };\n\ninterface Tap {\n time: number;\n point: Point;\n}\n\n/** Safari's `GestureEvent`, which the DOM typings do not know. */\ninterface SafariGestureEvent extends UIEvent {\n scale: number;\n clientX: number;\n clientY: number;\n}\n\n/** The zoom area is not scaled itself, only its content. */\nconst frameOf = (element: HTMLElement | null): ZoomFrame => {\n const rect = element?.getBoundingClientRect();\n if (!rect) {\n return {\n width: 0,\n height: 0,\n screen: { left: 0, right: 0, top: 0, bottom: 0 },\n };\n }\n const centerX = rect.left + rect.width / 2;\n const centerY = rect.top + rect.height / 2;\n\n return {\n width: rect.width,\n height: rect.height,\n screen: {\n left: -centerX,\n right: window.innerWidth - centerX,\n top: -centerY,\n bottom: window.innerHeight - centerY,\n },\n };\n};\n\n/**\n * Far enough to show an image at its natural size. `offsetWidth` is the width\n * before the zoom's transform.\n */\nconst maxScaleOf = (element: HTMLElement | null) => {\n const image = element?.querySelector(\"img\");\n if (!image?.naturalWidth || !image.offsetWidth) {\n return minMaxScale;\n }\n return Math.max(minMaxScale, image.naturalWidth / image.offsetWidth);\n};\n\n/** Client coordinates as an offset from the center of the zoom area. */\nconst pointIn = (\n element: HTMLElement | null,\n clientX: number,\n clientY: number,\n): Point => {\n const rect = element?.getBoundingClientRect();\n if (!rect) {\n return { x: 0, y: 0 };\n }\n return {\n x: clientX - rect.left - rect.width / 2,\n y: clientY - rect.top - rect.height / 2,\n };\n};\n\nconst distance = (a: Point, b: Point) => Math.hypot(a.x - b.x, a.y - b.y);\n\nconst midpoint = (a: Point, b: Point): Point => ({\n x: (a.x + b.x) / 2,\n y: (a.y + b.y) / 2,\n});\n\nexport const useZoom = (\n ref: RefObject<HTMLDivElement | null>,\n isEnabled: boolean,\n) => {\n const [transform, setTransform] = useState(initialZoomTransform);\n /* Discrete steps animate, continuous gestures follow the pointer. */\n const [isAnimated, setIsAnimated] = useState(false);\n const [isDragging, setIsDragging] = useState(false);\n /* Where the zoom area was on screen at the last change. */\n const [frame, setFrame] = useState<ZoomFrame | null>(null);\n\n const pointers = useRef(new Map<number, Point>());\n const gesture = useRef<Gesture | null>(null);\n const pressStart = useRef<Point | null>(null);\n const hasMoved = useRef(false);\n /* A press that started while zoomed, or became a pinch, belongs to the zoom:\n a surrounding gallery must not read it as a swipe. */\n const isOwnPress = useRef(false);\n const lastTap = useRef<Tap | null>(null);\n\n const getFrame = () => frameOf(ref.current);\n const getMaxScale = () => maxScaleOf(ref.current);\n const toPoint = (clientX: number, clientY: number) =>\n pointIn(ref.current, clientX, clientY);\n\n const update = (\n next: (current: ZoomTransform) => ZoomTransform,\n animated: boolean,\n ) => {\n setIsAnimated(animated);\n setFrame(getFrame());\n setTransform(next);\n };\n\n const toggleAt = (point: Point) =>\n update(\n (current) =>\n isZoomed(current)\n ? initialZoomTransform\n : zoomTo(current, toggleScale, getMaxScale(), getFrame(), point),\n true,\n );\n\n const zoomBy = (step: number) =>\n update(\n (current) =>\n zoomTo(current, current.scale + step, getMaxScale(), getFrame(), {\n x: 0,\n y: 0,\n }),\n true,\n );\n\n /* React registers `wheel` as passive, which cannot prevent the scroll, and\n knows no gesture events. */\n useEffect(() => {\n const element = ref.current;\n if (!element || !isEnabled) {\n return;\n }\n\n const zoomByFactor = (factor: number, clientX: number, clientY: number) => {\n /* Without focus, the arrows would still page a surrounding gallery. */\n if (document.activeElement !== element) {\n element.focus({ preventScroll: true });\n }\n\n const point = pointIn(element, clientX, clientY);\n\n setIsAnimated(false);\n setFrame(frameOf(element));\n setTransform((current) =>\n zoomTo(\n current,\n current.scale * factor,\n maxScaleOf(element),\n frameOf(element),\n point,\n ),\n );\n };\n\n const handleWheel = (event: WheelEvent) => {\n /* A horizontal trackpad swipe has no zoom direction. */\n if (event.deltaY === 0) {\n return;\n }\n event.preventDefault();\n\n const deltaY =\n event.deltaMode === WheelEvent.DOM_DELTA_LINE\n ? event.deltaY * wheelLineHeight\n : event.deltaY;\n /* A trackpad pinch arrives as a wheel event with `ctrlKey` and small\n deltas. */\n const factor = Math.exp(-deltaY * (event.ctrlKey ? 0.01 : 0.002));\n zoomByFactor(factor, event.clientX, event.clientY);\n };\n\n /* Safari reports a trackpad pinch as gesture events, not as wheel\n events, and zooms the page unless they are prevented. */\n let gestureScale = 1;\n\n const handleGestureStart = (event: Event) => {\n event.preventDefault();\n gestureScale = 1;\n };\n\n const handleGestureChange = (event: Event) => {\n event.preventDefault();\n const { scale, clientX, clientY } = event as SafariGestureEvent;\n zoomByFactor(scale / gestureScale, clientX, clientY);\n gestureScale = scale;\n };\n\n element.addEventListener(\"wheel\", handleWheel, { passive: false });\n element.addEventListener(\"gesturestart\", handleGestureStart);\n element.addEventListener(\"gesturechange\", handleGestureChange);\n return () => {\n element.removeEventListener(\"wheel\", handleWheel);\n element.removeEventListener(\"gesturestart\", handleGestureStart);\n element.removeEventListener(\"gesturechange\", handleGestureChange);\n };\n }, [ref, isEnabled]);\n\n const zoomed = isZoomed(transform);\n\n /* The bounds depend on where the zoom area is on screen. */\n useEffect(() => {\n if (!zoomed) {\n return;\n }\n\n const handleResize = () => {\n const nextFrame = frameOf(ref.current);\n setIsAnimated(false);\n setFrame(nextFrame);\n setTransform((current) => clampTranslation(current, nextFrame));\n };\n\n window.addEventListener(\"resize\", handleResize);\n return () => window.removeEventListener(\"resize\", handleResize);\n }, [ref, zoomed]);\n\n const startGesture = () => {\n const [first, second] = Array.from(pointers.current.values());\n\n if (first && second) {\n gesture.current = {\n type: \"pinch\",\n startDistance: distance(first, second),\n startMidpoint: midpoint(first, second),\n startTransform: transform,\n };\n } else if (first && isZoomed(transform)) {\n gesture.current = {\n type: \"pan\",\n start: first,\n startTransform: transform,\n };\n } else {\n gesture.current = null;\n }\n\n setIsDragging(gesture.current !== null);\n };\n\n const onPointerDown = (event: PointerEvent<HTMLDivElement>) => {\n if (event.pointerType === \"mouse\" && event.button !== 0) {\n return;\n }\n\n const point = toPoint(event.clientX, event.clientY);\n pointers.current.set(event.pointerId, point);\n\n if (pointers.current.size === 1) {\n pressStart.current = point;\n hasMoved.current = false;\n isOwnPress.current = isZoomed(transform);\n } else {\n isOwnPress.current = true;\n hasMoved.current = true;\n }\n\n if (isOwnPress.current) {\n event.stopPropagation();\n }\n\n event.currentTarget.setPointerCapture(event.pointerId);\n startGesture();\n };\n\n const onPointerMove = (event: PointerEvent<HTMLDivElement>) => {\n if (!pointers.current.has(event.pointerId)) {\n return;\n }\n\n const point = toPoint(event.clientX, event.clientY);\n pointers.current.set(event.pointerId, point);\n\n if (\n pressStart.current &&\n distance(pressStart.current, point) > tapTolerance\n ) {\n hasMoved.current = true;\n }\n\n const current = gesture.current;\n if (!current) {\n return;\n }\n event.stopPropagation();\n\n if (current.type === \"pan\") {\n const delta = {\n x: point.x - current.start.x,\n y: point.y - current.start.y,\n };\n update(() => panBy(current.startTransform, delta, getFrame()), false);\n return;\n }\n\n const [first, second] = Array.from(pointers.current.values());\n if (!first || !second) {\n return;\n }\n const scale =\n (current.startTransform.scale * distance(first, second)) /\n current.startDistance;\n\n update(\n () =>\n zoomTo(\n current.startTransform,\n scale,\n getMaxScale(),\n getFrame(),\n current.startMidpoint,\n midpoint(first, second),\n ),\n false,\n );\n };\n\n const handleTap = (event: PointerEvent<HTMLDivElement>, point: Point) => {\n if (event.pointerType !== \"touch\") {\n toggleAt(point);\n return;\n }\n\n const now = event.timeStamp;\n const previous = lastTap.current;\n\n if (\n previous &&\n now - previous.time < doubleTapDelay &&\n distance(previous.point, point) < doubleTapDistance\n ) {\n lastTap.current = null;\n toggleAt(point);\n } else {\n lastTap.current = { time: now, point };\n }\n };\n\n const endPointer = (event: PointerEvent<HTMLDivElement>, isTap: boolean) => {\n if (!pointers.current.delete(event.pointerId)) {\n return;\n }\n\n if (isOwnPress.current) {\n event.stopPropagation();\n }\n\n if (pointers.current.size > 0) {\n /* A pinch that loses a finger goes on as a pan. */\n startGesture();\n return;\n }\n\n if (isTap && !hasMoved.current) {\n handleTap(event, toPoint(event.clientX, event.clientY));\n }\n\n gesture.current = null;\n pressStart.current = null;\n setIsDragging(false);\n };\n\n const onPointerUp = (event: PointerEvent<HTMLDivElement>) =>\n endPointer(event, true);\n\n const onPointerCancel = (event: PointerEvent<HTMLDivElement>) =>\n endPointer(event, false);\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n /* Ctrl/Cmd with `+`/`-` zooms the page, Alt with the arrows navigates. */\n if (event.ctrlKey || event.metaKey || event.altKey) {\n return;\n }\n\n const pan = (x: number, y: number) => {\n if (!isZoomed(transform)) {\n /* Unzoomed, the arrows are a surrounding gallery's. */\n return;\n }\n event.preventDefault();\n event.stopPropagation();\n update((current) => panBy(current, { x, y }, getFrame()), true);\n };\n\n switch (event.key) {\n case \"+\":\n case \"=\":\n event.preventDefault();\n zoomBy(keyboardScaleStep);\n break;\n case \"-\":\n event.preventDefault();\n zoomBy(-keyboardScaleStep);\n break;\n case \"Enter\":\n case \" \":\n event.preventDefault();\n toggleAt({ x: 0, y: 0 });\n break;\n case \"ArrowLeft\":\n pan(keyboardPanStep, 0);\n break;\n case \"ArrowRight\":\n pan(-keyboardPanStep, 0);\n break;\n case \"ArrowUp\":\n pan(0, keyboardPanStep);\n break;\n case \"ArrowDown\":\n pan(0, -keyboardPanStep);\n break;\n }\n };\n\n return {\n transform,\n frame,\n isZoomed: zoomed,\n isAnimated,\n isDragging,\n handlers: {\n onPointerDown,\n onPointerMove,\n onPointerUp,\n onPointerCancel,\n onKeyDown,\n },\n };\n};\n"],"mappings":";;;;;;AAoBA,IAAM,cAAc;;AAEpB,IAAM,cAAc;AACpB,IAAM,oBAAoB;AAC1B,IAAM,kBAAkB;;AAExB,IAAM,eAAe;AACrB,IAAM,iBAAiB;AACvB,IAAM,oBAAoB;AAC1B,IAAM,kBAAkB;;AAwBxB,IAAM,WAAW,YAA2C;CAC1D,MAAM,OAAO,SAAS,sBAAsB;CAC5C,IAAI,CAAC,MACH,OAAO;EACL,OAAO;EACP,QAAQ;EACR,QAAQ;GAAE,MAAM;GAAG,OAAO;GAAG,KAAK;GAAG,QAAQ;EAAE;CACjD;CAEF,MAAM,UAAU,KAAK,OAAO,KAAK,QAAQ;CACzC,MAAM,UAAU,KAAK,MAAM,KAAK,SAAS;CAEzC,OAAO;EACL,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb,QAAQ;GACN,MAAM,CAAC;GACP,OAAO,OAAO,aAAa;GAC3B,KAAK,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,0 +1,58 @@
1
+ "use client"
2
+ /* */
3
+ // src/components/LightBox/components/LightBoxZoom/lib/zoomTransform.ts
4
+ var initialZoomTransform = {
5
+ scale: 1,
6
+ x: 0,
7
+ y: 0
8
+ };
9
+ var clamp = (value, min, max) => Math.min(max, Math.max(min, value));
10
+ var clampAxis = (offset, scaledSize, screenStart, screenEnd) => {
11
+ const startAtScreenStart = screenStart + scaledSize / 2;
12
+ const endAtScreenEnd = screenEnd - scaledSize / 2;
13
+ return clamp(offset, Math.min(startAtScreenStart, endAtScreenEnd), Math.max(startAtScreenStart, endAtScreenEnd));
14
+ };
15
+ var clampTranslation = (transform, frame) => ({
16
+ scale: transform.scale,
17
+ x: clampAxis(transform.x, frame.width * transform.scale, frame.screen.left, frame.screen.right),
18
+ y: clampAxis(transform.y, frame.height * transform.scale, frame.screen.top, frame.screen.bottom)
19
+ });
20
+ /**
21
+ * Scales to `scale`, keeping the content under `origin` in place. `pointer` is
22
+ * where that content ends up — the same point, unless a pinch moved its
23
+ * midpoint.
24
+ */
25
+ var zoomTo = (transform, scale, maxScale, frame, origin, pointer = origin) => {
26
+ const nextScale = clamp(scale, 1, maxScale);
27
+ if (nextScale === 1) return initialZoomTransform;
28
+ const ratio = nextScale / transform.scale;
29
+ return clampTranslation({
30
+ scale: nextScale,
31
+ x: pointer.x - (origin.x - transform.x) * ratio,
32
+ y: pointer.y - (origin.y - transform.y) * ratio
33
+ }, frame);
34
+ };
35
+ var panBy = (transform, delta, frame) => isZoomed(transform) ? clampTranslation({
36
+ ...transform,
37
+ x: transform.x + delta.x,
38
+ y: transform.y + delta.y
39
+ }, frame) : transform;
40
+ var isZoomed = (transform) => transform.scale > 1;
41
+ /** The part of the scaled content on screen, from the area's top left corner. */
42
+ var visibleArea = (transform, frame) => {
43
+ const halfWidth = frame.width * transform.scale / 2;
44
+ const halfHeight = frame.height * transform.scale / 2;
45
+ const left = Math.max(transform.x - halfWidth, frame.screen.left);
46
+ const right = Math.min(transform.x + halfWidth, frame.screen.right);
47
+ const top = Math.max(transform.y - halfHeight, frame.screen.top);
48
+ const bottom = Math.min(transform.y + halfHeight, frame.screen.bottom);
49
+ return {
50
+ left: left + frame.width / 2,
51
+ top: top + frame.height / 2,
52
+ width: right - left,
53
+ height: bottom - top
54
+ };
55
+ };
56
+ export { clampTranslation, initialZoomTransform, isZoomed, panBy, visibleArea, zoomTo };
57
+
58
+ //# sourceMappingURL=zoomTransform.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zoomTransform.mjs","names":[],"sources":["../../../../../../../../../../src/components/LightBox/components/LightBoxZoom/lib/zoomTransform.ts"],"sourcesContent":["export interface ZoomTransform {\n scale: number;\n /** Translation in px, applied after scaling around the center. */\n x: number;\n y: number;\n}\n\n/** An offset from the center of the zoom area, in px. */\nexport interface Point {\n x: number;\n y: number;\n}\n\n/**\n * The unscaled size of the zoom area and the edges of the screen around it, as\n * offsets from the area's center.\n */\nexport interface ZoomFrame {\n width: number;\n height: number;\n screen: { left: number; right: number; top: number; bottom: number };\n}\n\nexport const initialZoomTransform: ZoomTransform = { scale: 1, x: 0, y: 0 };\n\nconst clamp = (value: number, min: number, max: number) =>\n Math.min(max, Math.max(min, value));\n\n/*\n * Content larger than the screen covers it, so no edge moves into view. Content\n * smaller than the screen stays inside it.\n */\nconst clampAxis = (\n offset: number,\n scaledSize: number,\n screenStart: number,\n screenEnd: number,\n) => {\n const startAtScreenStart = screenStart + scaledSize / 2;\n const endAtScreenEnd = screenEnd - scaledSize / 2;\n\n return clamp(\n offset,\n Math.min(startAtScreenStart, endAtScreenEnd),\n Math.max(startAtScreenStart, endAtScreenEnd),\n );\n};\n\nexport const clampTranslation = (\n transform: ZoomTransform,\n frame: ZoomFrame,\n): ZoomTransform => ({\n scale: transform.scale,\n x: clampAxis(\n transform.x,\n frame.width * transform.scale,\n frame.screen.left,\n frame.screen.right,\n ),\n y: clampAxis(\n transform.y,\n frame.height * transform.scale,\n frame.screen.top,\n frame.screen.bottom,\n ),\n});\n\n/**\n * Scales to `scale`, keeping the content under `origin` in place. `pointer` is\n * where that content ends up — the same point, unless a pinch moved its\n * midpoint.\n */\nexport const zoomTo = (\n transform: ZoomTransform,\n scale: number,\n maxScale: number,\n frame: ZoomFrame,\n origin: Point,\n pointer: Point = origin,\n): ZoomTransform => {\n const nextScale = clamp(scale, 1, maxScale);\n\n if (nextScale === 1) {\n return initialZoomTransform;\n }\n\n const ratio = nextScale / transform.scale;\n\n return clampTranslation(\n {\n scale: nextScale,\n x: pointer.x - (origin.x - transform.x) * ratio,\n y: pointer.y - (origin.y - transform.y) * ratio,\n },\n frame,\n );\n};\n\nexport const panBy = (\n transform: ZoomTransform,\n delta: Point,\n frame: ZoomFrame,\n): ZoomTransform =>\n isZoomed(transform)\n ? clampTranslation(\n { ...transform, x: transform.x + delta.x, y: transform.y + delta.y },\n frame,\n )\n : transform;\n\nexport const isZoomed = (transform: ZoomTransform) => transform.scale > 1;\n\nexport interface Area {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\n/** The part of the scaled content on screen, from the area's top left corner. */\nexport const visibleArea = (\n transform: ZoomTransform,\n frame: ZoomFrame,\n): Area => {\n const halfWidth = (frame.width * transform.scale) / 2;\n const halfHeight = (frame.height * transform.scale) / 2;\n\n const left = Math.max(transform.x - halfWidth, frame.screen.left);\n const right = Math.min(transform.x + halfWidth, frame.screen.right);\n const top = Math.max(transform.y - halfHeight, frame.screen.top);\n const bottom = Math.min(transform.y + halfHeight, frame.screen.bottom);\n\n return {\n left: left + frame.width / 2,\n top: top + frame.height / 2,\n width: right - left,\n height: bottom - top,\n };\n};\n"],"mappings":";;;AAuBA,IAAa,uBAAsC;CAAE,OAAO;CAAG,GAAG;CAAG,GAAG;AAAE;AAE1E,IAAM,SAAS,OAAe,KAAa,QACzC,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK,CAAC;AAMpC,IAAM,aACJ,QACA,YACA,aACA,cACG;CACH,MAAM,qBAAqB,cAAc,aAAa;CACtD,MAA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AAO;EACL,MAAM,OAAO,MAAM,QAAQ;EAC3B,KAAK,MAAM,MAAM,SAAS;EAC1B,OAAO,QAAQ;EACf,QAAQ,SAAS;CACnB;AACF"}
@@ -0,0 +1,15 @@
1
+ "use client"
2
+ /* */
3
+ import { viewComponentContext } from "../lib/viewComponentContext/viewComponentContext.mjs";
4
+ import { LightBoxZoom } from "../components/LightBox/components/LightBoxZoom/LightBoxZoom.mjs";
5
+ import { memo, useContext } from "react";
6
+ import { jsx } from "react/jsx-runtime";
7
+ // src/views/LightBoxZoomView.tsx
8
+ var LightBoxZoomView = memo((props) => {
9
+ const View = useContext(viewComponentContext)["LightBoxZoom"] ?? LightBoxZoom;
10
+ return /* @__PURE__ */ jsx(View, { ...props });
11
+ });
12
+ LightBoxZoomView.displayName = "LightBoxZoomView";
13
+ export { LightBoxZoomView as default };
14
+
15
+ //# sourceMappingURL=LightBoxZoomView.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LightBoxZoomView.mjs","names":[],"sources":["../../../../../../src/views/LightBoxZoomView.tsx"],"sourcesContent":["/* prettier-ignore */\n/* This file is auto-generated with the remote-components-generator */\nimport React, { memo, type FC, useContext } from \"react\";\nimport {\n LightBoxZoom,\n type LightBoxZoomProps,\n} from \"@/components/LightBox/components/LightBoxZoom/LightBoxZoom\";\nimport { viewComponentContext } from \"@/lib/viewComponentContext/viewComponentContext\";\n\nconst LightBoxZoomView: FC<LightBoxZoomProps> = memo((props) => {\n const View = useContext(viewComponentContext)[\"LightBoxZoom\"] ?? LightBoxZoom;\n return <View {...props} />;\n});\nLightBoxZoomView.displayName = \"LightBoxZoomView\";\n\nexport default LightBoxZoomView;\n"],"mappings":";;;;;;;AASA,IAAM,mBAA0C,MAAM,UAAU;CAC9D,MAAM,OAAO,WAAW,oBAAoB,CAAC,CAAC,mBAAmB;CACjE,OAAO,oBAAC,MAAD,EAAM,GAAI,MAAQ,CAAA;AAC3B,CAAC;AACD,iBAAiB,cAAc"}
@@ -10,6 +10,12 @@ export interface LightBoxProps extends PropsWithChildren, FlowComponentProps, Pr
10
10
  * screen. @default true
11
11
  */
12
12
  fitScreen?: boolean;
13
+ /**
14
+ * Whether the content can be zoomed. Applies to the items of a
15
+ * `LightBoxGallery` as well. The content then always fits the screen,
16
+ * whatever `fitScreen` says. @default false
17
+ */
18
+ withZoom?: boolean;
13
19
  }
14
20
  export declare const LightBox: import('react').FunctionComponent<LightBoxProps & import('react').RefAttributes<HTMLDivElement>>;
15
21
  export default LightBox;
@@ -1,8 +1,7 @@
1
1
  import { FlowComponentProps } from '../../../../lib/componentFactory/flowComponent';
2
2
  import { PropsWithChildren } from 'react';
3
- export type LightBoxGalleryItemProps = PropsWithChildren & Omit<FlowComponentProps, "ref">;
3
+ export interface LightBoxGalleryItemProps extends PropsWithChildren, Omit<FlowComponentProps, "ref"> {
4
+ }
4
5
  /** @flr-generate all */
5
- export declare const LightBoxGalleryItem: import('react').FunctionComponent<{
6
- children?: import('react').ReactNode | undefined;
7
- } & Omit<FlowComponentProps<HTMLDivElement>, "ref"> & import('react').RefAttributes<unknown>>;
6
+ export declare const LightBoxGalleryItem: import('react').FunctionComponent<LightBoxGalleryItemProps & import('react').RefAttributes<unknown>>;
8
7
  export default LightBoxGalleryItem;
@@ -0,0 +1,12 @@
1
+ import { FC, PropsWithChildren } from 'react';
2
+ import { PropsWithClassName } from '../../../../lib/types/props';
3
+ export interface LightBoxZoomProps extends PropsWithChildren, PropsWithClassName {
4
+ }
5
+ /**
6
+ * The zoomable area of a `LightBox` with `withZoom`. Not a `flowComponent`: it
7
+ * passes the light box's props context through to its children.
8
+ *
9
+ * @flr-generate all
10
+ */
11
+ export declare const LightBoxZoom: FC<LightBoxZoomProps>;
12
+ export default LightBoxZoom;
@@ -0,0 +1,16 @@
1
+ import { KeyboardEvent, PointerEvent, RefObject } from 'react';
2
+ import { ZoomFrame, ZoomTransform } from '../lib/zoomTransform';
3
+ export declare const useZoom: (ref: RefObject<HTMLDivElement | null>, isEnabled: boolean) => {
4
+ transform: ZoomTransform;
5
+ frame: ZoomFrame | null;
6
+ isZoomed: boolean;
7
+ isAnimated: boolean;
8
+ isDragging: boolean;
9
+ handlers: {
10
+ onPointerDown: (event: PointerEvent<HTMLDivElement>) => void;
11
+ onPointerMove: (event: PointerEvent<HTMLDivElement>) => void;
12
+ onPointerUp: (event: PointerEvent<HTMLDivElement>) => void;
13
+ onPointerCancel: (event: PointerEvent<HTMLDivElement>) => void;
14
+ onKeyDown: (event: KeyboardEvent<HTMLDivElement>) => void;
15
+ };
16
+ };
@@ -0,0 +1,2 @@
1
+ export { type LightBoxZoomProps, LightBoxZoom } from './LightBoxZoom';
2
+ export { default } from './LightBoxZoom';
@@ -0,0 +1,43 @@
1
+ export interface ZoomTransform {
2
+ scale: number;
3
+ /** Translation in px, applied after scaling around the center. */
4
+ x: number;
5
+ y: number;
6
+ }
7
+ /** An offset from the center of the zoom area, in px. */
8
+ export interface Point {
9
+ x: number;
10
+ y: number;
11
+ }
12
+ /**
13
+ * The unscaled size of the zoom area and the edges of the screen around it, as
14
+ * offsets from the area's center.
15
+ */
16
+ export interface ZoomFrame {
17
+ width: number;
18
+ height: number;
19
+ screen: {
20
+ left: number;
21
+ right: number;
22
+ top: number;
23
+ bottom: number;
24
+ };
25
+ }
26
+ export declare const initialZoomTransform: ZoomTransform;
27
+ export declare const clampTranslation: (transform: ZoomTransform, frame: ZoomFrame) => ZoomTransform;
28
+ /**
29
+ * Scales to `scale`, keeping the content under `origin` in place. `pointer` is
30
+ * where that content ends up — the same point, unless a pinch moved its
31
+ * midpoint.
32
+ */
33
+ export declare const zoomTo: (transform: ZoomTransform, scale: number, maxScale: number, frame: ZoomFrame, origin: Point, pointer?: Point) => ZoomTransform;
34
+ export declare const panBy: (transform: ZoomTransform, delta: Point, frame: ZoomFrame) => ZoomTransform;
35
+ export declare const isZoomed: (transform: ZoomTransform) => boolean;
36
+ export interface Area {
37
+ left: number;
38
+ top: number;
39
+ width: number;
40
+ height: number;
41
+ }
42
+ /** The part of the scaled content on screen, from the area's top left corner. */
43
+ export declare const visibleArea: (transform: ZoomTransform, frame: ZoomFrame) => Area;
@@ -0,0 +1,7 @@
1
+ import { LightBoxZoom } from './LightBoxZoom';
2
+ import { ViewComponent } from '../../../../lib/viewComponentContext';
3
+ declare global {
4
+ interface FlowViewComponents {
5
+ LightBoxZoom: ViewComponent<typeof LightBoxZoom>;
6
+ }
7
+ }
@@ -1,5 +1,6 @@
1
1
  export * from './components/LightBoxTrigger';
2
2
  export * from './components/LightBoxGallery';
3
3
  export * from './components/LightBoxGalleryItem';
4
+ export * from './components/LightBoxZoom';
4
5
  export { type LightBoxProps, LightBox } from './LightBox';
5
6
  export { default } from './LightBox';
@@ -0,0 +1,4 @@
1
+ import { FC } from 'react';
2
+ import { LightBoxZoomProps } from '../components/LightBox/components/LightBoxZoom/LightBoxZoom';
3
+ declare const LightBoxZoomView: FC<LightBoxZoomProps>;
4
+ export default LightBoxZoomView;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/flow-react-components",
3
- "version": "1.6.0-next.68",
3
+ "version": "1.6.0-next.69",
4
4
  "type": "module",
5
5
  "description": "A React implementation of Flow, mittwald’s design system",
6
6
  "homepage": "https://flow.mittwald.de",
@@ -84,9 +84,9 @@
84
84
  "@internationalized/string-compiler": "^3.4.1",
85
85
  "@lezer/common": "^1.5.2",
86
86
  "@lezer/highlight": "^1.2.3",
87
- "@mittwald/flow-icons": "^1.6.0-next.68",
87
+ "@mittwald/flow-icons": "^1.6.0-next.69",
88
88
  "@mittwald/password-tools-js": "^3.0.0",
89
- "@mittwald/react-tunnel": "^1.6.0-next.68",
89
+ "@mittwald/react-tunnel": "^1.6.0-next.69",
90
90
  "@mittwald/react-use-promise": "^4.2.2",
91
91
  "@react-aria/form": "^3.2.1",
92
92
  "@react-aria/i18n": "^3.13.1",
@@ -139,13 +139,13 @@
139
139
  "@internationalized/date": "^3.12.3",
140
140
  "@lezer/generator": "^1.8.0",
141
141
  "@lezer/lr": "^1.4.10",
142
- "@mittwald/flow-components-base": "1.6.0-next.68",
143
- "@mittwald/flow-core": "1.6.0-next.68",
144
- "@mittwald/flow-design-tokens": "1.6.0-next.68",
145
- "@mittwald/flow-icons-base": "1.6.0-next.68",
142
+ "@mittwald/flow-components-base": "1.6.0-next.69",
143
+ "@mittwald/flow-core": "1.6.0-next.69",
144
+ "@mittwald/flow-design-tokens": "1.6.0-next.69",
145
+ "@mittwald/flow-icons-base": "1.6.0-next.69",
146
146
  "@mittwald/react-use-promise": "^4.2.2",
147
147
  "@mittwald/remote-dom-react": "1.2.2-mittwald.10",
148
- "@mittwald/typescript-config": "1.6.0-next.68",
148
+ "@mittwald/typescript-config": "1.6.0-next.69",
149
149
  "@nx/storybook": "^22.7.6",
150
150
  "@storybook/addon-a11y": "^10.5.10",
151
151
  "@storybook/addon-actions": "^9.0.8",
@@ -199,7 +199,7 @@
199
199
  },
200
200
  "peerDependencies": {
201
201
  "@internationalized/date": "^3.12.2",
202
- "@mittwald/flow-icons-pro": "1.6.0-next.68",
202
+ "@mittwald/flow-icons-pro": "1.6.0-next.69",
203
203
  "@mittwald/react-use-promise": "^4.2.2",
204
204
  "next": "^16.2.3",
205
205
  "react": "^19.2.0",
@@ -223,5 +223,5 @@
223
223
  "browserslist": [
224
224
  "baseline widely available"
225
225
  ],
226
- "gitHead": "b4504a4c6976754472ab63a3207af2e962245dc5"
226
+ "gitHead": "b3447d9249d526c4e96abe08458acc6c468084d2"
227
227
  }