point-focus 1.0.5 → 2.0.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/README.md +125 -0
- package/dist/index.cjs +259 -225
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +259 -225
- package/dist/index.js.map +1 -1
- package/package.json +9 -26
- package/dist/ImageMagnifier.d.ts +0 -3
- package/dist/ImageMagnifier.types.d.ts +0 -191
- package/dist/assets/CloseIcon.d.ts +0 -3
- package/dist/assets/svgCollection.d.ts +0 -6
- package/dist/components/BaseImage.d.ts +0 -3
- package/dist/components/FullscreenPortal.d.ts +0 -6
- package/dist/components/Image.d.ts +0 -3
- package/dist/components/ImageStatusPlaceholder.d.ts +0 -10
- package/dist/components/ZoomImage.d.ts +0 -4
- package/dist/utils/animation.constants.d.ts +0 -16
- package/dist/utils/animations.d.ts +0 -4
- package/dist/utils/dragUtils.d.ts +0 -3
- package/dist/utils/followUtils.d.ts +0 -3
- package/dist/utils/globalUtils.d.ts +0 -50
- package/dist/utils/imageMagnifierUtils.d.ts +0 -34
- package/dist/utils/movementUtils.d.ts +0 -4
- package/dist/utils/panUtils.d.ts +0 -3
package/dist/index.js
CHANGED
|
@@ -28,47 +28,49 @@ function styleInject(css, ref) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
var css_248z = ":root{--button-icon-color:#1e1c1c;--loader-background:#19181891;--loader-color:#fff}.
|
|
32
|
-
var styles = {"c-point-focus":"styles-module_c-point-focus__Glxyg","c-point-focus__zoom-img":"styles-module_c-point-focus__zoom-img__HP-hu","c-point-focus__overlay":"styles-module_c-point-focus__overlay__T8nCD","c-point-focus__placeholder":"styles-module_c-point-focus__placeholder__dHGk6","c-point-focus__img":"styles-module_c-point-focus__img__jCS0m","c-point-focus__button":"styles-module_c-point-focus__button__oCELz","c-point-focus__loader":"styles-module_c-point-focus__loader__AIAkB","animloader":"styles-module_animloader__7LeVS","c-fp-fallback-image":"styles-module_c-fp-fallback-image__sROkG"};
|
|
31
|
+
var css_248z = ":root{--button-icon-color:#1e1c1c;--loader-background:#19181891;--loader-color:#fff}point-focus-image{display:block}.c-point-focus{align-items:center;cursor:zoom-in;display:flex;height:100%;justify-content:center;margin:0;overflow:hidden;position:relative;width:100%;&[data-movetype=follow] .c-point-focus__zoom-img{cursor:crosshair}&[data-movetype=drag] .c-point-focus__zoom-img{cursor:grab}&:focus-visible{outline:.125rem solid currentColor;outline-offset:.125rem}}.c-point-focus__overlay{inset:0;pointer-events:none;position:absolute;z-index:1}.c-point-focus__placeholder{align-items:center;background:var(--loader-background);display:flex;inset:0;justify-content:center;position:absolute;z-index:2;&[hidden]{display:none}}.c-point-focus__img{-webkit-user-drag:none;aspect-ratio:4/3;display:block;height:100%;object-fit:contain;opacity:1;pointer-events:none;transition-delay:var(--fade-duration,0ms);transition-duration:0ms;transition-property:opacity,visibility;transition-timing-function:linear;user-select:none;visibility:visible;width:100%;&[data-hidden=true]{opacity:0;visibility:hidden}}.c-point-focus__zoom-img{-webkit-user-drag:none;-webkit-touch-callout:none;display:block;left:0;max-width:none!important;opacity:0;pointer-events:none;position:absolute;top:0;transform-origin:top left;transition-duration:var(--fade-duration,.15s);transition-property:opacity,visibility;transition-timing-function:linear;user-select:none;visibility:hidden;width:auto!important;will-change:transform;&[data-visible=true]{cursor:zoom-out;opacity:1;pointer-events:auto;touch-action:none;visibility:visible}}.c-point-focus__button{align-items:center;appearance:none;background:transparent;border:none;cursor:pointer;display:flex;justify-content:center;opacity:0;outline:none;padding:.3rem;position:absolute;right:2%;text-decoration:none;top:2%;transform-origin:center center;transition-delay:0ms,var(--fade-duration,.15s);transition-duration:var(--fade-duration,.15s),0ms;transition-property:opacity,visibility;transition-timing-function:linear;visibility:hidden;z-index:3;&[data-visible=true]{opacity:1;transition-delay:0ms,0ms;visibility:visible}&:focus-visible{outline:.125rem solid currentColor}& svg{filter:drop-shadow(0 0 .625rem rgba(0,0,0,.7));height:1rem;transform-origin:center;transition:transform .2s ease-in-out;width:1rem;& path{fill:var(--button-icon-color)}}&:hover svg{transform:scale(1.2)}&:active svg{transform:scale(1)}}.c-point-focus__loader{display:inline-block;height:3rem;position:relative;width:3rem;&:after,&:before{animation:c-point-focus-loader 2s linear infinite;border:.125rem solid var(--loader-color);border-radius:50%;box-sizing:border-box;content:\"\";height:3rem;left:0;position:absolute;top:0;width:3rem}&:after{animation-delay:1s}}.c-point-focus .c-fp-fallback-image{height:100%;inset:0;object-fit:cover;object-position:center center;position:absolute;width:100%;z-index:2}@keyframes c-point-focus-loader{0%{opacity:1;transform:scale(0)}to{opacity:0;transform:scale(2)}}@media (prefers-reduced-motion:reduce){.c-point-focus__button,.c-point-focus__img,.c-point-focus__zoom-img{transition-duration:0ms}.c-point-focus__loader:after,.c-point-focus__loader:before{animation-duration:0s}}";
|
|
33
32
|
styleInject(css_248z);
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const EMPTY_BOUNDS = { left: 0, top: 0, width: 0, height: 0 };
|
|
35
|
+
function isTouchEvent(event) {
|
|
36
|
+
return 'touches' in event;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
return { x:
|
|
38
|
+
function getPageCoords(source, fallbackElement) {
|
|
39
|
+
const event = source;
|
|
40
|
+
if (event.touches && event.touches.length > 0) {
|
|
41
|
+
return { x: event.touches[0].pageX, y: event.touches[0].pageY };
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
return { x:
|
|
43
|
+
if (typeof event.pageX === 'number' && typeof event.pageY === 'number') {
|
|
44
|
+
return { x: event.pageX, y: event.pageY };
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
x: rect.left + rect.width / 2,
|
|
50
|
-
y: rect.top + rect.height / 2,
|
|
51
|
-
};
|
|
46
|
+
if (fallbackElement) {
|
|
47
|
+
return getElementCenter(fallbackElement);
|
|
52
48
|
}
|
|
53
49
|
return { x: 0, y: 0 };
|
|
54
50
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
51
|
+
function getElementCenter(element) {
|
|
52
|
+
const rect = element.getBoundingClientRect();
|
|
53
|
+
const scrollX = typeof window === 'undefined' ? 0 : window.scrollX;
|
|
54
|
+
const scrollY = typeof window === 'undefined' ? 0 : window.scrollY;
|
|
55
|
+
return { x: rect.left + scrollX + rect.width / 2, y: rect.top + scrollY + rect.height / 2 };
|
|
56
|
+
}
|
|
57
|
+
function getOffsets(pageX, pageY, left, top) {
|
|
58
|
+
return { x: pageX - left, y: pageY - top };
|
|
59
|
+
}
|
|
60
|
+
function getBounds(container) {
|
|
61
|
+
if (!container)
|
|
62
|
+
return { ...EMPTY_BOUNDS };
|
|
63
|
+
const { left, top, width, height } = container.getBoundingClientRect();
|
|
64
|
+
return { left, top, width, height };
|
|
65
|
+
}
|
|
66
|
+
function getRatios(bounds, natural, zoomScale) {
|
|
67
|
+
if (bounds.width === 0 || bounds.height === 0)
|
|
68
|
+
return { x: 0, y: 0 };
|
|
67
69
|
return {
|
|
68
|
-
x: (
|
|
69
|
-
y: (
|
|
70
|
+
x: (natural.width * zoomScale - bounds.width) / bounds.width,
|
|
71
|
+
y: (natural.height * zoomScale - bounds.height) / bounds.height,
|
|
70
72
|
};
|
|
71
|
-
}
|
|
73
|
+
}
|
|
72
74
|
function clampToBounds(left, top, bounds) {
|
|
73
75
|
return {
|
|
74
76
|
left: Math.max(Math.min(left, bounds.maxLeft), bounds.minLeft),
|
|
@@ -76,26 +78,157 @@ function clampToBounds(left, top, bounds) {
|
|
|
76
78
|
};
|
|
77
79
|
}
|
|
78
80
|
function calculateDragPosition(pageX, pageY, offsets) {
|
|
79
|
-
return {
|
|
80
|
-
left: pageX - offsets.x,
|
|
81
|
-
top: pageY - offsets.y,
|
|
82
|
-
};
|
|
81
|
+
return { left: pageX - offsets.x, top: pageY - offsets.y };
|
|
83
82
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
};
|
|
98
|
-
};
|
|
83
|
+
function clampZoomScale(zoomScale) {
|
|
84
|
+
return Math.max(1, Math.min(zoomScale, 5));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const FRAME_SECONDS = 1 / 60;
|
|
88
|
+
const DRAG_THRESHOLD_PX = 3;
|
|
89
|
+
class ZoomEngine {
|
|
90
|
+
onPosition;
|
|
91
|
+
friction;
|
|
92
|
+
minVelocity;
|
|
93
|
+
now;
|
|
94
|
+
bounds = { ...EMPTY_BOUNDS };
|
|
95
|
+
ratios = { x: 0, y: 0 };
|
|
96
|
+
pageOffsets = { x: 0, y: 0 };
|
|
97
|
+
dragOffsets = { x: 0, y: 0 };
|
|
98
|
+
dragOrigin = { x: 0, y: 0 };
|
|
99
|
+
previousSample = null;
|
|
100
|
+
lastSample = null;
|
|
101
|
+
frameId = null;
|
|
102
|
+
dragging = false;
|
|
103
|
+
dragMoved = false;
|
|
104
|
+
current = { left: 0, top: 0 };
|
|
105
|
+
constructor({ onPosition, friction = 0.95, minVelocity = 10, now = () => Date.now() }) {
|
|
106
|
+
this.onPosition = onPosition;
|
|
107
|
+
this.friction = friction;
|
|
108
|
+
this.minVelocity = minVelocity;
|
|
109
|
+
this.now = now;
|
|
110
|
+
}
|
|
111
|
+
get position() {
|
|
112
|
+
return { ...this.current };
|
|
113
|
+
}
|
|
114
|
+
get isDragging() {
|
|
115
|
+
return this.dragging;
|
|
116
|
+
}
|
|
117
|
+
get containerBounds() {
|
|
118
|
+
return { ...this.bounds };
|
|
119
|
+
}
|
|
120
|
+
measure(container, natural, zoomScale) {
|
|
121
|
+
this.bounds = getBounds(container);
|
|
122
|
+
this.ratios = getRatios(this.bounds, natural, zoomScale);
|
|
123
|
+
}
|
|
124
|
+
startFollow(pageX, pageY, container) {
|
|
125
|
+
if (typeof window === 'undefined' || !container) {
|
|
126
|
+
this.bounds = { ...EMPTY_BOUNDS };
|
|
127
|
+
this.pageOffsets = { x: 0, y: 0 };
|
|
128
|
+
this.setPosition({ left: 0, top: 0 });
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this.bounds = getBounds(container);
|
|
132
|
+
this.pageOffsets = getOffsets(window.scrollX, window.scrollY, -this.bounds.left, -this.bounds.top);
|
|
133
|
+
this.follow(pageX, pageY);
|
|
134
|
+
}
|
|
135
|
+
follow(pageX, pageY) {
|
|
136
|
+
const { left, top } = calculateDragPosition(pageX, pageY, this.pageOffsets);
|
|
137
|
+
const clamped = clampToBounds(left, top, { minLeft: 0, maxLeft: this.bounds.width, minTop: 0, maxTop: this.bounds.height });
|
|
138
|
+
this.setPosition({ left: clamped.left * -this.ratios.x, top: clamped.top * -this.ratios.y });
|
|
139
|
+
}
|
|
140
|
+
beginDrag(pageX, pageY) {
|
|
141
|
+
this.cancelInertia();
|
|
142
|
+
this.dragging = true;
|
|
143
|
+
this.dragMoved = false;
|
|
144
|
+
this.dragOrigin = { x: pageX, y: pageY };
|
|
145
|
+
this.dragOffsets = getOffsets(pageX, pageY, this.current.left, this.current.top);
|
|
146
|
+
this.previousSample = null;
|
|
147
|
+
this.lastSample = null;
|
|
148
|
+
}
|
|
149
|
+
moveDrag(pageX, pageY) {
|
|
150
|
+
if (!this.dragging)
|
|
151
|
+
return;
|
|
152
|
+
this.previousSample = this.lastSample;
|
|
153
|
+
this.lastSample = { x: pageX, y: pageY, time: this.now() };
|
|
154
|
+
if (Math.hypot(pageX - this.dragOrigin.x, pageY - this.dragOrigin.y) > DRAG_THRESHOLD_PX) {
|
|
155
|
+
this.dragMoved = true;
|
|
156
|
+
}
|
|
157
|
+
const { left, top } = calculateDragPosition(pageX, pageY, this.dragOffsets);
|
|
158
|
+
this.setPosition(clampToBounds(left, top, this.dragLimits()));
|
|
159
|
+
}
|
|
160
|
+
endDrag(withInertia) {
|
|
161
|
+
if (!this.dragging)
|
|
162
|
+
return null;
|
|
163
|
+
this.dragging = false;
|
|
164
|
+
const velocity = this.releaseVelocity();
|
|
165
|
+
const final = { x: this.current.left, y: this.current.top };
|
|
166
|
+
if (withInertia)
|
|
167
|
+
this.startInertia(velocity);
|
|
168
|
+
return { velocity, final, moved: this.dragMoved };
|
|
169
|
+
}
|
|
170
|
+
reset() {
|
|
171
|
+
this.cancelInertia();
|
|
172
|
+
this.dragging = false;
|
|
173
|
+
this.dragMoved = false;
|
|
174
|
+
this.previousSample = null;
|
|
175
|
+
this.lastSample = null;
|
|
176
|
+
this.setPosition({ left: 0, top: 0 });
|
|
177
|
+
}
|
|
178
|
+
destroy() {
|
|
179
|
+
this.cancelInertia();
|
|
180
|
+
this.dragging = false;
|
|
181
|
+
}
|
|
182
|
+
dragLimits() {
|
|
183
|
+
return {
|
|
184
|
+
minLeft: this.bounds.width * -this.ratios.x,
|
|
185
|
+
maxLeft: 0,
|
|
186
|
+
minTop: this.bounds.height * -this.ratios.y,
|
|
187
|
+
maxTop: 0,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
releaseVelocity() {
|
|
191
|
+
const last = this.lastSample;
|
|
192
|
+
const previous = this.previousSample;
|
|
193
|
+
if (!last || !previous)
|
|
194
|
+
return { vx: 0, vy: 0 };
|
|
195
|
+
const seconds = (last.time - previous.time) / 1000;
|
|
196
|
+
if (seconds <= 0)
|
|
197
|
+
return { vx: 0, vy: 0 };
|
|
198
|
+
return { vx: (last.x - previous.x) / seconds, vy: (last.y - previous.y) / seconds };
|
|
199
|
+
}
|
|
200
|
+
startInertia(initial) {
|
|
201
|
+
const limits = this.dragLimits();
|
|
202
|
+
let { vx, vy } = initial;
|
|
203
|
+
let { left, top } = this.current;
|
|
204
|
+
const step = () => {
|
|
205
|
+
vx *= this.friction;
|
|
206
|
+
vy *= this.friction;
|
|
207
|
+
left += vx * FRAME_SECONDS;
|
|
208
|
+
top += vy * FRAME_SECONDS;
|
|
209
|
+
const clamped = clampToBounds(left, top, limits);
|
|
210
|
+
this.setPosition(clamped);
|
|
211
|
+
if (Math.abs(vx) > this.minVelocity || Math.abs(vy) > this.minVelocity) {
|
|
212
|
+
this.frameId = requestAnimationFrame(step);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
this.frameId = null;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
this.frameId = requestAnimationFrame(step);
|
|
219
|
+
}
|
|
220
|
+
cancelInertia() {
|
|
221
|
+
if (this.frameId !== null) {
|
|
222
|
+
cancelAnimationFrame(this.frameId);
|
|
223
|
+
this.frameId = null;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
setPosition(position) {
|
|
227
|
+
this.current = position;
|
|
228
|
+
this.onPosition(position);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
99
232
|
class ZoomFallbackBoundary extends React.Component {
|
|
100
233
|
constructor(props) {
|
|
101
234
|
super(props);
|
|
@@ -115,46 +248,6 @@ class ZoomFallbackBoundary extends React.Component {
|
|
|
115
248
|
}
|
|
116
249
|
}
|
|
117
250
|
|
|
118
|
-
const applyMouseMove = (pageX, pageY, zoomContextRef, setLeft, setTop) => {
|
|
119
|
-
const { left, top } = calculateDragPosition(pageX, pageY, zoomContextRef.current.offsets);
|
|
120
|
-
const bounds = { minLeft: 0, maxLeft: zoomContextRef.current.bounds.width, minTop: 0, maxTop: zoomContextRef.current.bounds.height };
|
|
121
|
-
const clamped = clampToBounds(left, top, bounds);
|
|
122
|
-
setLeft(clamped.left * -zoomContextRef.current.ratios.x);
|
|
123
|
-
setTop(clamped.top * -zoomContextRef.current.ratios.y);
|
|
124
|
-
};
|
|
125
|
-
const initializeFollowZoomPosition = (pageX, pageY, container, zoomContextRef, setLeft, setTop) => {
|
|
126
|
-
// SSR check: only run if window and container are available
|
|
127
|
-
if (typeof window === 'undefined' || !container) {
|
|
128
|
-
zoomContextRef.current.bounds = { left: 0, top: 0, width: 0, height: 0 };
|
|
129
|
-
zoomContextRef.current.offsets = { x: 0, y: 0 };
|
|
130
|
-
setLeft(0);
|
|
131
|
-
setTop(0);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
const bounds = getBounds(container);
|
|
135
|
-
zoomContextRef.current.bounds = bounds;
|
|
136
|
-
const offsets = getOffsets(window.pageXOffset, window.pageYOffset, -bounds.left, -bounds.top);
|
|
137
|
-
zoomContextRef.current.offsets = offsets;
|
|
138
|
-
applyMouseMove(pageX, pageY, zoomContextRef, setLeft, setTop);
|
|
139
|
-
};
|
|
140
|
-
function applyDragMove(x, y, zoomContextRef, setLeft, setTop) {
|
|
141
|
-
// This is setting up the animation
|
|
142
|
-
const now = Date.now();
|
|
143
|
-
zoomContextRef.current.prevDragCoords = zoomContextRef.current.lastDragCoords;
|
|
144
|
-
zoomContextRef.current.lastDragCoords = { x, y, time: now };
|
|
145
|
-
// Calculate new position using the stored offset
|
|
146
|
-
const { left: newLeft, top: newTop } = calculateDragPosition(x, y, zoomContextRef.current.dragStartCoords);
|
|
147
|
-
// Clamp to bounds
|
|
148
|
-
const { width, height } = zoomContextRef.current.bounds;
|
|
149
|
-
const maxLeft = 0;
|
|
150
|
-
const minLeft = width * -zoomContextRef.current.ratios.x;
|
|
151
|
-
const maxTop = 0;
|
|
152
|
-
const minTop = height * -zoomContextRef.current.ratios.y;
|
|
153
|
-
const clamped = clampToBounds(newLeft, newTop, { minLeft, maxLeft, minTop, maxTop });
|
|
154
|
-
setLeft(clamped.left);
|
|
155
|
-
setTop(clamped.top);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
251
|
const CloseIcon = ({ className = 'c-zoom-close-button-icon' }) => (jsx("svg", { xmlns: 'http://www.w3.org/2000/svg', className: className, viewBox: '0 0 24 24', fill: 'none', children: jsx("path", { fillRule: 'evenodd', clipRule: 'evenodd', d: 'M5.29289 5.29289C5.68342 4.90237 6.31658 4.90237 6.70711 5.29289L12 10.5858L17.2929 5.29289C17.6834 4.90237 18.3166 4.90237 18.7071 5.29289C19.0976 5.68342 19.0976 6.31658 18.7071 6.70711L13.4142 12L18.7071 17.2929C19.0976 17.6834 19.0976 18.3166 18.7071 18.7071C18.3166 19.0976 17.6834 19.0976 17.2929 18.7071L12 13.4142L6.70711 18.7071C6.31658 19.0976 5.68342 19.0976 5.29289 18.7071C4.90237 18.3166 4.90237 17.6834 5.29289 17.2929L10.5858 12L5.29289 6.70711C4.90237 6.31658 4.90237 5.68342 5.29289 5.29289Z', fill: '#000' }) }));
|
|
159
252
|
const FallbackImage = ({ className = 'c-fp-fallback-image' }) => (jsxs("svg", { className: className, viewBox: '0 0 2153 1548', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', children: [jsx("rect", { width: '100%', height: '100%', fill: 'white' }), jsx("path", { d: 'M762 504.5H1392C1425.97 504.5 1453.5 532.034 1453.5 566V982C1453.5 1015.97 1425.97 1043.5 1392 1043.5H762C728.034 1043.5 700.5 1015.97 700.5 982V566C700.5 532.034 728.034 504.5 762 504.5Z', fill: '#EBEEF0', stroke: '#8495A2', strokeWidth: '25' }), jsx("path", { d: 'M901.252 812.329C880.253 832.829 710.25 1012.23 707.251 1014.33C704.252 1016.43 728.751 1038.83 745.252 1038.83C761.752 1038.83 1381.75 1039.33 1388.25 1038.83C1394.75 1038.33 1443.75 1036.33 1445.75 981.832C1447.75 927.332 1445.75 946.332 1445.75 946.332C1445.75 946.332 1243.75 723.83 1225.75 705.829C1207.75 687.827 1194.25 681.832 1170.25 705.829C1146.25 729.826 1012.47 866.329 1012.47 866.329C1012.47 866.329 976.253 827.329 957.752 808.829C939.252 790.329 922.252 791.829 901.252 812.329Z', fill: '#CBD4DB' }), jsx("path", { d: 'M1056.25 912.329L1012.47 866.329M1012.47 866.329C1012.47 866.329 976.253 827.329 957.752 808.829C939.252 790.329 922.252 791.829 901.252 812.329C880.253 832.829 710.25 1012.23 707.251 1014.33C704.252 1016.43 728.751 1038.83 745.252 1038.83C761.752 1038.83 1381.75 1039.33 1388.25 1038.83C1394.75 1038.33 1443.75 1036.33 1445.75 981.832C1447.75 927.332 1445.75 946.332 1445.75 946.332C1445.75 946.332 1243.75 723.83 1225.75 705.829C1207.75 687.827 1194.25 681.832 1170.25 705.829C1146.25 729.826 1012.47 866.329 1012.47 866.329Z', stroke: '#8595A1', strokeWidth: '25', strokeLinecap: 'round' }), jsx("circle", { cx: '891.5', cy: '689.5', r: '60', fill: '#CBD4DA', stroke: '#8496A2', strokeWidth: '25' })] }));
|
|
160
253
|
|
|
@@ -184,12 +277,12 @@ const BaseImage = ({ src, sources, baseImageStyle = {}, isZoomed, fadeDuration,
|
|
|
184
277
|
'--fade-duration': `${isZoomed ? fadeDuration : 0}ms`,
|
|
185
278
|
...baseImageStyle,
|
|
186
279
|
}), [isZoomed, fadeDuration, baseImageStyle]);
|
|
187
|
-
const imageClass = [
|
|
280
|
+
const imageClass = ['c-point-focus__img', baseImageClassName].filter(Boolean).join(' ');
|
|
188
281
|
const defaultImg = !hasError && src ? (jsx("img", { ref: imgRef, alt: alt, src: src, style: imageStyle, onLoad: handleLoad, onError: handleError, className: imageClass, "data-hidden": isZoomed, "data-testid": 'pf-base-image', crossOrigin: 'anonymous' })) : null;
|
|
189
282
|
const wrappedImage = sources && sources.length > 0 ? (jsxs("picture", { style: { width: '100%', height: '100%' }, children: [sources
|
|
190
283
|
.filter(s => s.srcSet)
|
|
191
284
|
.map((source, i) => (jsx("source", { ...source }, i))), defaultImg] })) : (defaultImg);
|
|
192
|
-
return (jsxs(Fragment, { children: [wrappedImage, !disableLoadingFallbacks && isLoading && !hasError && (jsx("div", { className:
|
|
285
|
+
return (jsxs(Fragment, { children: [wrappedImage, !disableLoadingFallbacks && isLoading && !hasError && (jsx("div", { className: 'c-point-focus__placeholder', style: { zIndex: 0 }, "data-testid": 'pf-base-loading', children: loadingPlaceholder ?? jsx("span", { className: 'c-point-focus__loader' }) })), !disableErrorFallbacks && hasError && (jsx("div", { className: 'c-point-focus__placeholder', style: { zIndex: 0 }, "data-testid": 'pf-base-error', children: errorPlaceholder ?? jsx(FallbackImage, {}) }))] }));
|
|
193
286
|
};
|
|
194
287
|
|
|
195
288
|
const ZoomImage = React.forwardRef(({ src, fadeDuration, top, left, isZoomed, onLoad, onDragStart, onDragEnd, onClose, onFadeOut, closeButtonRef, onTouchStart, onTouchEnd, zoomImageClassName, closeButtonClassName, alt, closeButtonAriaLabel, zoomImageAriaLabel, onKeyDown, closeButtonContent, onError, loadingPlaceholder, errorPlaceholder, zoomScale, disableLoadingFallbacks = false, disableErrorFallbacks = false, }, ref) => {
|
|
@@ -210,57 +303,42 @@ const ZoomImage = React.forwardRef(({ src, fadeDuration, top, left, isZoomed, on
|
|
|
210
303
|
setHasError(true);
|
|
211
304
|
onError?.();
|
|
212
305
|
};
|
|
213
|
-
const zoomImgClass = [
|
|
306
|
+
const zoomImgClass = ['c-point-focus__zoom-img', zoomImageClassName].filter(Boolean).join(' ');
|
|
214
307
|
return (jsxs(Fragment, { children: [jsx("img", { ref: ref, "data-testid": 'pf-zoom-image', "data-visible": isZoomed, className: zoomImgClass, style: {
|
|
215
308
|
transform: `translate(${left}px, ${top}px) scale(${zoomScale})`,
|
|
216
309
|
transformOrigin: 'top left',
|
|
217
310
|
transition: `opacity ${fadeDuration}ms linear, visibility ${fadeDuration}ms linear`,
|
|
218
|
-
}, src: src, onLoad: handleLoad, onError: handleError, onMouseDown: onDragStart, onMouseUp: onDragEnd, onTouchStart: onTouchStart, onTouchEnd: onTouchEnd, onTransitionEnd: onFadeOut, draggable: false, alt: `${alt} zoomed`, "aria-label": zoomImageAriaLabel, onKeyDown: onKeyDown, tabIndex: 0 }), !disableErrorFallbacks && hasError && isZoomed && (jsx("div", { className:
|
|
219
|
-
transition: `opacity ${fadeDuration}ms linear, visibility ${fadeDuration}ms
|
|
311
|
+
}, src: src, onLoad: handleLoad, onError: handleError, onMouseDown: onDragStart, onMouseUp: onDragEnd, onTouchStart: onTouchStart, onTouchEnd: onTouchEnd, onTransitionEnd: onFadeOut, draggable: false, alt: `${alt} zoomed`, "aria-label": zoomImageAriaLabel, onKeyDown: onKeyDown, tabIndex: 0 }), !disableErrorFallbacks && hasError && isZoomed && (jsx("div", { className: 'c-point-focus__placeholder', "data-testid": 'pf-zoom-error', children: errorPlaceholder ?? jsx(FallbackImage, {}) })), !disableLoadingFallbacks && isLoading && !hasError && isZoomed && (jsx("div", { className: 'c-point-focus__placeholder', "data-testid": 'pf-zoom-loading', children: loadingPlaceholder ?? jsx("span", { className: 'c-point-focus__loader' }) })), onClose && (jsx("button", { type: 'button', ref: closeButtonRef, title: 'Close Zoom', "data-testid": 'pf-close-button', "aria-label": closeButtonAriaLabel ?? 'Zoom out', "data-visible": isZoomed, "data-action-type": 'close', className: closeButtonClassName || 'c-point-focus__button', style: {
|
|
312
|
+
transition: `opacity ${fadeDuration}ms linear, visibility 0ms linear ${isZoomed ? 0 : fadeDuration}ms`,
|
|
220
313
|
}, onClick: () => onClose?.('click'), onKeyDown: onKeyDown, children: closeButtonContent ?? jsx(CloseIcon, {}) }))] }));
|
|
221
314
|
});
|
|
222
315
|
ZoomImage.displayName = 'ZoomImage';
|
|
223
316
|
|
|
224
|
-
|
|
225
|
-
let left = initialLeft;
|
|
226
|
-
let top = initialTop;
|
|
227
|
-
let vx = velocity.vx;
|
|
228
|
-
let vy = velocity.vy;
|
|
229
|
-
function step() {
|
|
230
|
-
vx *= friction;
|
|
231
|
-
vy *= friction;
|
|
232
|
-
left += vx * (1 / 60);
|
|
233
|
-
top += vy * (1 / 60);
|
|
234
|
-
const clamped = clampToBounds(left, top, bounds);
|
|
235
|
-
setLeft(clamped.left);
|
|
236
|
-
setTop(clamped.top);
|
|
237
|
-
if (Math.abs(vx) > minVelocity || Math.abs(vy) > minVelocity) {
|
|
238
|
-
contextRef.current.rafId = requestAnimationFrame(step); // 👈 Store rafId
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
contextRef.current.rafId = null;
|
|
242
|
-
setLeft(clamped.left);
|
|
243
|
-
setTop(clamped.top);
|
|
244
|
-
onEnd?.();
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
contextRef.current.rafId = requestAnimationFrame(step);
|
|
248
|
-
}
|
|
249
|
-
|
|
317
|
+
const createSession = () => ({ onLoadCallback: null, wasDragging: false, lastMoveEvent: null, moveFrameId: null });
|
|
250
318
|
const ImageMagnifier = ({ src, sources, width, height, zoomSrc, zoomScale = 1, zoomPreload, fadeDuration = 150, moveType = 'follow', zoomType = 'click', baseImageStyle, hideCloseButton, containerClassName, baseImageClassName, zoomImageClassName, closeButtonClassName, onMouseEnter, onZoomedMouseMove, onMouseLeave, onClickImage, onZoom, onClose, afterZoomImgLoaded, afterZoomOut, onBaseImageError, onZoomImageError, onDragStart, onDragEnd, alt, containerAriaLabel, closeButtonAriaLabel, zoomImageAriaLabel, tabIndex = 0, closeButtonContent, overlay, disableDrag, disableInertia, loadingPlaceholder, errorPlaceholder, clickToZoomOut = false, externalZoomState, setExternalZoomState, disableMobile, disableLoadingFallbacks, disableErrorFallbacks, }) => {
|
|
251
319
|
const containerRef = React.useRef(null);
|
|
252
320
|
const closeButtonRef = React.useRef(null);
|
|
253
321
|
const zoomedImgRef = React.useRef(null);
|
|
254
|
-
const
|
|
322
|
+
const sessionRef = React.useRef(createSession());
|
|
323
|
+
const engineRef = React.useRef(null);
|
|
324
|
+
if (!engineRef.current) {
|
|
325
|
+
engineRef.current = new ZoomEngine({
|
|
326
|
+
onPosition: ({ left, top }) => {
|
|
327
|
+
if (zoomedImgRef.current)
|
|
328
|
+
zoomedImgRef.current.style.transform = `translate(${left}px, ${top}px) scale(${safeZoomScaleRef.current})`;
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
const engine = engineRef.current;
|
|
255
333
|
const isControlled = externalZoomState !== undefined;
|
|
256
334
|
const [internalZoom, setInternalZoom] = React.useState(false);
|
|
257
335
|
const isZoomed = isControlled ? externalZoomState : internalZoom;
|
|
258
336
|
const [isActive, setIsActive] = React.useState(zoomPreload);
|
|
259
337
|
const [isDragging, setIsDragging] = React.useState(false);
|
|
260
338
|
const [isFading, setIsFading] = React.useState(false);
|
|
261
|
-
const
|
|
262
|
-
const
|
|
263
|
-
|
|
339
|
+
const safeZoomScale = clampZoomScale(zoomScale);
|
|
340
|
+
const safeZoomScaleRef = React.useRef(safeZoomScale);
|
|
341
|
+
safeZoomScaleRef.current = safeZoomScale;
|
|
264
342
|
const updateZoomState = (val) => {
|
|
265
343
|
if (isControlled) {
|
|
266
344
|
setExternalZoomState?.(val);
|
|
@@ -271,7 +349,7 @@ const ImageMagnifier = ({ src, sources, width, height, zoomSrc, zoomScale = 1, z
|
|
|
271
349
|
};
|
|
272
350
|
const zoomIn = (pageX, pageY, method) => {
|
|
273
351
|
updateZoomState(true);
|
|
274
|
-
|
|
352
|
+
engine.startFollow(pageX, pageY, containerRef.current);
|
|
275
353
|
onZoom?.({ at: { x: pageX, y: pageY }, method: method });
|
|
276
354
|
setTimeout(() => {
|
|
277
355
|
closeButtonRef.current?.focus();
|
|
@@ -281,98 +359,45 @@ const ImageMagnifier = ({ src, sources, width, height, zoomSrc, zoomScale = 1, z
|
|
|
281
359
|
if (!zoomPreload) {
|
|
282
360
|
setIsFading(true);
|
|
283
361
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
zoomContextRef.current.velocity = null;
|
|
288
|
-
zoomContextRef.current.prevDragCoords = null;
|
|
289
|
-
zoomContextRef.current.lastDragCoords = null;
|
|
290
|
-
setLeft(0);
|
|
291
|
-
setTop(0);
|
|
362
|
+
sessionRef.current.onLoadCallback = null;
|
|
363
|
+
sessionRef.current.wasDragging = false;
|
|
364
|
+
engine.reset();
|
|
292
365
|
updateZoomState(false);
|
|
293
366
|
};
|
|
294
367
|
const handleDragStart = React.useCallback((e) => {
|
|
295
368
|
if (!isZoomed || disableDrag || (disableMobile && isTouchEvent(e)))
|
|
296
369
|
return;
|
|
297
|
-
if (zoomContextRef.current.rafId != null) {
|
|
298
|
-
cancelAnimationFrame(zoomContextRef.current.rafId);
|
|
299
|
-
zoomContextRef.current.rafId = null;
|
|
300
|
-
}
|
|
301
370
|
const { x, y } = getPageCoords(e);
|
|
371
|
+
engine.beginDrag(x, y);
|
|
302
372
|
setIsDragging(true);
|
|
303
|
-
zoomContextRef.current.dragStartCoords = getOffsets(x, y, left, top);
|
|
304
373
|
onDragStart?.({
|
|
305
374
|
start: { x, y },
|
|
306
375
|
source: isTouchEvent(e) ? 'touch' : 'mouse',
|
|
307
376
|
});
|
|
308
|
-
}, [isZoomed, disableDrag, disableMobile,
|
|
377
|
+
}, [isZoomed, disableDrag, disableMobile, engine, onDragStart]);
|
|
309
378
|
const handleDragMove = React.useCallback((e) => {
|
|
310
|
-
if (!isDragging)
|
|
379
|
+
if (!engine.isDragging)
|
|
311
380
|
return;
|
|
312
381
|
const { x, y } = getPageCoords(e);
|
|
313
|
-
|
|
382
|
+
engine.moveDrag(x, y);
|
|
314
383
|
if ('touches' in e)
|
|
315
384
|
e.preventDefault?.();
|
|
316
|
-
}, [
|
|
385
|
+
}, [engine]);
|
|
317
386
|
const handleDragEnd = React.useCallback(() => {
|
|
387
|
+
const result = engine.endDrag(!disableInertia);
|
|
388
|
+
if (!result)
|
|
389
|
+
return;
|
|
318
390
|
setIsDragging(false);
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const prev = zoomContextRef.current.prevDragCoords;
|
|
324
|
-
let vx = 0, vy = 0;
|
|
325
|
-
if (last && prev) {
|
|
326
|
-
const dt = (last.time - prev.time) / 1000;
|
|
327
|
-
if (dt > 0) {
|
|
328
|
-
vx = (last.x - prev.x) / dt;
|
|
329
|
-
vy = (last.y - prev.y) / dt;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
zoomContextRef.current.velocity = { vx, vy };
|
|
333
|
-
// Calculate bounds
|
|
334
|
-
const { width, height } = zoomContextRef.current.bounds;
|
|
335
|
-
const maxLeft = 0;
|
|
336
|
-
const minLeft = width * -zoomContextRef.current.ratios.x;
|
|
337
|
-
const maxTop = 0;
|
|
338
|
-
const minTop = height * -zoomContextRef.current.ratios.y;
|
|
339
|
-
if (!disableInertia) {
|
|
340
|
-
startInertia({
|
|
341
|
-
initialLeft: left,
|
|
342
|
-
initialTop: top,
|
|
343
|
-
velocity: { vx, vy },
|
|
344
|
-
setLeft,
|
|
345
|
-
setTop,
|
|
346
|
-
bounds: { minLeft, maxLeft, minTop, maxTop },
|
|
347
|
-
friction: 0.95,
|
|
348
|
-
minVelocity: 10,
|
|
349
|
-
onEnd: () => {
|
|
350
|
-
// Optionally, snap to bounds or do something else
|
|
351
|
-
},
|
|
352
|
-
contextRef: zoomContextRef,
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
onDragEnd?.({
|
|
356
|
-
velocity: { vx, vy },
|
|
357
|
-
final: { x: left, y: top },
|
|
358
|
-
});
|
|
359
|
-
}, [disableInertia, left, top, setLeft, setTop, onDragEnd]);
|
|
391
|
+
if (result.moved)
|
|
392
|
+
sessionRef.current.wasDragging = true;
|
|
393
|
+
onDragEnd?.({ velocity: result.velocity, final: result.final });
|
|
394
|
+
}, [engine, disableInertia, onDragEnd]);
|
|
360
395
|
const applyImageLoad = (el) => {
|
|
361
|
-
const naturalDimensions = {
|
|
362
|
-
width: el.naturalWidth,
|
|
363
|
-
height: el.naturalHeight,
|
|
364
|
-
};
|
|
365
|
-
const bounds = getBounds(containerRef.current);
|
|
366
396
|
zoomedImgRef.current = el;
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
zoomContextRef.current.bounds = bounds;
|
|
372
|
-
zoomContextRef.current.ratios = getRatios(bounds, naturalDimensions, safeZoomScale);
|
|
373
|
-
if (zoomContextRef.current.onLoadCallback) {
|
|
374
|
-
zoomContextRef.current.onLoadCallback();
|
|
375
|
-
zoomContextRef.current.onLoadCallback = null;
|
|
397
|
+
engine.measure(containerRef.current, { width: el.naturalWidth, height: el.naturalHeight }, safeZoomScale);
|
|
398
|
+
if (sessionRef.current.onLoadCallback) {
|
|
399
|
+
sessionRef.current.onLoadCallback();
|
|
400
|
+
sessionRef.current.onLoadCallback = null;
|
|
376
401
|
}
|
|
377
402
|
};
|
|
378
403
|
const handleLoad = React.useCallback((e) => {
|
|
@@ -388,8 +413,8 @@ const ImageMagnifier = ({ src, sources, width, height, zoomSrc, zoomScale = 1, z
|
|
|
388
413
|
return;
|
|
389
414
|
const { x, y } = getPageCoords(e);
|
|
390
415
|
onClickImage?.({ x, y, source: isTouchEvent(e) ? 'touch' : 'mouse' });
|
|
391
|
-
if (
|
|
392
|
-
|
|
416
|
+
if (sessionRef.current.wasDragging) {
|
|
417
|
+
sessionRef.current.wasDragging = false;
|
|
393
418
|
return;
|
|
394
419
|
}
|
|
395
420
|
if (isZoomed) {
|
|
@@ -403,20 +428,32 @@ const ImageMagnifier = ({ src, sources, width, height, zoomSrc, zoomScale = 1, z
|
|
|
403
428
|
zoomIn(x, y, method);
|
|
404
429
|
}
|
|
405
430
|
else {
|
|
406
|
-
|
|
431
|
+
sessionRef.current.onLoadCallback = () => zoomIn(x, y, method);
|
|
407
432
|
}
|
|
408
433
|
}, [disableMobile, isTouchEvent, getPageCoords, onClickImage, isZoomed, clickToZoomOut, handleClose, applyImageLoad, zoomIn]);
|
|
409
434
|
const handleKeyDown = React.useCallback((e) => {
|
|
410
435
|
if ((e.key === 'Enter' || e.key === ' ') && !isZoomed) {
|
|
411
436
|
e.preventDefault();
|
|
412
437
|
const { x, y } = getPageCoords(e, containerRef.current);
|
|
413
|
-
|
|
438
|
+
const image = zoomedImgRef.current;
|
|
439
|
+
if (image && image.naturalWidth > 0) {
|
|
440
|
+
applyImageLoad(image);
|
|
441
|
+
zoomIn(x, y, 'keyboard');
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
setIsActive(true);
|
|
445
|
+
sessionRef.current.onLoadCallback = () => zoomIn(x, y, 'keyboard');
|
|
446
|
+
}
|
|
414
447
|
}
|
|
415
448
|
if (e.key === 'Escape' && isZoomed) {
|
|
416
449
|
e.preventDefault();
|
|
417
450
|
handleClose('keyboard');
|
|
418
451
|
}
|
|
419
|
-
}, [isZoomed, getPageCoords, zoomIn, handleClose]);
|
|
452
|
+
}, [isZoomed, getPageCoords, zoomIn, handleClose, applyImageLoad]);
|
|
453
|
+
const handleFocus = React.useCallback(() => {
|
|
454
|
+
setIsActive(true);
|
|
455
|
+
setIsFading(false);
|
|
456
|
+
}, []);
|
|
420
457
|
const handleZoomLayerKeyDown = React.useCallback((e) => {
|
|
421
458
|
if (e.key === 'Escape' && isZoomed) {
|
|
422
459
|
e.preventDefault();
|
|
@@ -424,14 +461,14 @@ const ImageMagnifier = ({ src, sources, width, height, zoomSrc, zoomScale = 1, z
|
|
|
424
461
|
}
|
|
425
462
|
}, [isZoomed, handleClose]);
|
|
426
463
|
const throttledZoomedMouseMove = React.useCallback((x, y, bounds) => {
|
|
427
|
-
|
|
428
|
-
if (
|
|
429
|
-
|
|
430
|
-
const evt =
|
|
464
|
+
sessionRef.current.lastMoveEvent = { x, y, bounds };
|
|
465
|
+
if (sessionRef.current.moveFrameId == null) {
|
|
466
|
+
sessionRef.current.moveFrameId = window.requestAnimationFrame(() => {
|
|
467
|
+
const evt = sessionRef.current.lastMoveEvent;
|
|
431
468
|
if (evt && onZoomedMouseMove) {
|
|
432
469
|
onZoomedMouseMove(evt);
|
|
433
470
|
}
|
|
434
|
-
|
|
471
|
+
sessionRef.current.moveFrameId = null;
|
|
435
472
|
});
|
|
436
473
|
}
|
|
437
474
|
}, [onZoomedMouseMove]);
|
|
@@ -446,13 +483,10 @@ const ImageMagnifier = ({ src, sources, width, height, zoomSrc, zoomScale = 1, z
|
|
|
446
483
|
const handleMouseMove = React.useCallback((e) => {
|
|
447
484
|
if (moveType === 'follow' && isZoomed) {
|
|
448
485
|
const { x, y } = getPageCoords(e);
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
return;
|
|
452
|
-
throttledZoomedMouseMove(x, y, zoomContextRef.current.bounds);
|
|
453
|
-
applyMouseMove(x, y, zoomContextRef, setLeft, setTop);
|
|
486
|
+
throttledZoomedMouseMove(x, y, engine.containerBounds);
|
|
487
|
+
engine.follow(x, y);
|
|
454
488
|
}
|
|
455
|
-
}, [moveType, isZoomed, throttledZoomedMouseMove,
|
|
489
|
+
}, [moveType, isZoomed, throttledZoomedMouseMove, engine]);
|
|
456
490
|
const handleMouseLeave = React.useCallback((e) => {
|
|
457
491
|
onMouseLeave?.({ source: isTouchEvent(e) ? 'touch' : 'mouse' });
|
|
458
492
|
handleClose('hover');
|
|
@@ -461,7 +495,7 @@ const ImageMagnifier = ({ src, sources, width, height, zoomSrc, zoomScale = 1, z
|
|
|
461
495
|
if (noTransition || (e && 'propertyName' in e && e.propertyName === 'opacity' && containerRef?.current?.contains(e.target))) {
|
|
462
496
|
if (!zoomPreload) {
|
|
463
497
|
zoomedImgRef.current = null;
|
|
464
|
-
|
|
498
|
+
sessionRef.current = createSession();
|
|
465
499
|
setIsActive(false);
|
|
466
500
|
}
|
|
467
501
|
setIsFading(false);
|
|
@@ -469,14 +503,14 @@ const ImageMagnifier = ({ src, sources, width, height, zoomSrc, zoomScale = 1, z
|
|
|
469
503
|
}
|
|
470
504
|
}, [zoomPreload, setIsActive, setIsFading, afterZoomOut]);
|
|
471
505
|
React.useEffect(() => {
|
|
472
|
-
zoomContextRef.current = getDefaults();
|
|
473
506
|
return () => {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
507
|
+
engine.destroy();
|
|
508
|
+
if (sessionRef.current.moveFrameId != null) {
|
|
509
|
+
cancelAnimationFrame(sessionRef.current.moveFrameId);
|
|
510
|
+
sessionRef.current.moveFrameId = null;
|
|
477
511
|
}
|
|
478
512
|
};
|
|
479
|
-
}, []);
|
|
513
|
+
}, [engine]);
|
|
480
514
|
React.useEffect(() => {
|
|
481
515
|
if (isDragging && !disableDrag) {
|
|
482
516
|
window.addEventListener('mousemove', handleDragMove);
|
|
@@ -490,12 +524,12 @@ const ImageMagnifier = ({ src, sources, width, height, zoomSrc, zoomScale = 1, z
|
|
|
490
524
|
window.removeEventListener('touchend', handleDragEnd);
|
|
491
525
|
};
|
|
492
526
|
}
|
|
493
|
-
}, [isDragging]);
|
|
527
|
+
}, [isDragging, disableDrag, handleDragMove, handleDragEnd]);
|
|
494
528
|
const zoomImageProps = {
|
|
495
529
|
src: zoomSrc || src,
|
|
496
530
|
fadeDuration: fadeDuration,
|
|
497
|
-
top,
|
|
498
|
-
left,
|
|
531
|
+
top: engine.position.top,
|
|
532
|
+
left: engine.position.left,
|
|
499
533
|
isZoomed,
|
|
500
534
|
onLoad: handleLoad,
|
|
501
535
|
onError: onZoomImageError,
|
|
@@ -519,12 +553,12 @@ const ImageMagnifier = ({ src, sources, width, height, zoomSrc, zoomScale = 1, z
|
|
|
519
553
|
disableLoadingFallbacks: disableLoadingFallbacks,
|
|
520
554
|
disableErrorFallbacks: disableErrorFallbacks,
|
|
521
555
|
};
|
|
522
|
-
const containerClass = [
|
|
556
|
+
const containerClass = ['c-point-focus', containerClassName].filter(Boolean).join(' ');
|
|
523
557
|
return (jsxs("figure", { role: 'group', ref: containerRef, tabIndex: tabIndex, "data-movetype": moveType, "data-testid": 'pf-image-magnifier-container', "aria-label": containerAriaLabel ?? 'Zoomable image', className: containerClass, style: { width: width, height: height }, onClick: e => handleClick(e, 'hover'), onTouchStart: e => {
|
|
524
558
|
if (disableMobile) {
|
|
525
559
|
e.preventDefault();
|
|
526
560
|
}
|
|
527
|
-
}, onKeyDown: handleKeyDown, onMouseEnter: handleMouseEnter, onMouseMove: isZoomed ? handleMouseMove : undefined, onMouseLeave: handleMouseLeave, children: [jsx(BaseImage, { src: src, alt: alt, sources: sources, width: width, height: height, baseImageStyle: baseImageStyle, baseImageClassName: baseImageClassName, fadeDuration: fadeDuration, isZoomed: isZoomed, onError: onBaseImageError, loadingPlaceholder: loadingPlaceholder, errorPlaceholder: errorPlaceholder, disableLoadingFallbacks: disableLoadingFallbacks, disableErrorFallbacks: disableErrorFallbacks }), isActive && (jsxs(Fragment, { children: [overlay && (jsx("div", { className:
|
|
561
|
+
}, onKeyDown: handleKeyDown, onFocus: handleFocus, onMouseEnter: handleMouseEnter, onMouseMove: isZoomed ? handleMouseMove : undefined, onMouseLeave: handleMouseLeave, children: [jsx(BaseImage, { src: src, alt: alt, sources: sources, width: width, height: height, baseImageStyle: baseImageStyle, baseImageClassName: baseImageClassName, fadeDuration: fadeDuration, isZoomed: isZoomed, onError: onBaseImageError, loadingPlaceholder: loadingPlaceholder, errorPlaceholder: errorPlaceholder, disableLoadingFallbacks: disableLoadingFallbacks, disableErrorFallbacks: disableErrorFallbacks }), isActive && (jsxs(Fragment, { children: [overlay && (jsx("div", { className: 'c-point-focus__overlay', "data-testid": 'pf-overlay', children: overlay })), jsx(ZoomFallbackBoundary, { fallback: errorPlaceholder ?? jsx(FallbackImage, {}), children: jsx(ZoomImage, { ref: zoomedImgRef, ...zoomImageProps }, isZoomed && clickToZoomOut ? 'zoomed' : 'unzoomed') })] }))] }));
|
|
528
562
|
};
|
|
529
563
|
|
|
530
564
|
export { ImageMagnifier as default };
|