@rubenpazch/image-viewer 1.2.0 → 1.2.2
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/dist/ImageViewer.d.ts.map +1 -1
- package/dist/index.cjs.js +15 -8
- package/dist/index.esm.js +15 -8
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageViewer.d.ts","sourceRoot":"","sources":["../src/ImageViewer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAaxE,MAAM,WAAW,eAAe;IAC9B,4EAA4E;IAC5E,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,MAAM,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;IACd,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,6FAA6F;AAC7F,eAAO,MAAM,2BAA2B,EAAE,iBAChB,CAAC;AAE3B,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,8CAA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AE,eAAe,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjE,qDAAqD;IACrD,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACrC;AAED,UAAU,SAAS;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,UAAU,IAAI;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,KAAK;IACb,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAyBD;;;GAGG;AACH,eAAO,MAAM,SAAS,GACpB,MAAM,SAAS,EACf,OAAO,IAAI,EACX,OAAO,IAAI,KACV,SAWF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,GACrB,MAAM,SAAS,EACf,OAAO,MAAM,EACb,QAAQ,KAAK,KACZ,SAQF,CAAC;AAyBF;;;;;;GAMG;AACH,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CA8b3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -564,13 +564,20 @@ const ImageViewer = ({ images, initialIndex = 0, index: controlledIndex, onIndex
|
|
|
564
564
|
const last = Math.max(0, images.length - 1);
|
|
565
565
|
const [ownIndex, setOwnIndex] = require$$0.useState(() => clamp(initialIndex, 0, last));
|
|
566
566
|
const index = clamp(controlledIndex ?? ownIndex, 0, last);
|
|
567
|
-
//
|
|
568
|
-
//
|
|
567
|
+
// Cada vez que cambia la imagen visible es una visita nueva, y la vista (zoom
|
|
568
|
+
// y posición) guarda a qué visita pertenece: al cambiar de imagen vuelve sola
|
|
569
|
+
// al 100 %, también al regresar a una ya vista (antes guardaba la imagen y,
|
|
570
|
+
// de vuelta en ella sin hacer zoom en otra, recuperaba el zoom anterior).
|
|
571
|
+
const [visit, setVisit] = require$$0.useState({ index, number: 0 });
|
|
572
|
+
if (visit.index !== index)
|
|
573
|
+
setVisit({ index, number: visit.number + 1 });
|
|
569
574
|
const [stored, setStored] = require$$0.useState({
|
|
570
|
-
|
|
575
|
+
visit: 0,
|
|
571
576
|
view: IDENTITY,
|
|
572
577
|
});
|
|
573
|
-
const view =
|
|
578
|
+
const view = visit.index === index && stored.visit === visit.number
|
|
579
|
+
? stored.view
|
|
580
|
+
: IDENTITY;
|
|
574
581
|
const viewRef = require$$0.useRef(stored);
|
|
575
582
|
// Mientras hay un gesto, el zoom sigue al dedo sin animación
|
|
576
583
|
const [dragging, setDragging] = require$$0.useState(false);
|
|
@@ -597,7 +604,7 @@ const ImageViewer = ({ images, initialIndex = 0, index: controlledIndex, onIndex
|
|
|
597
604
|
const center = stageCenter();
|
|
598
605
|
return { x: point.x - center.x, y: point.y - center.y };
|
|
599
606
|
};
|
|
600
|
-
const currentView = require$$0.useCallback(() =>
|
|
607
|
+
const currentView = require$$0.useCallback(() => viewRef.current.visit === visit.number ? viewRef.current.view : IDENTITY, [visit.number]);
|
|
601
608
|
const setView = require$$0.useCallback((next) => {
|
|
602
609
|
const stage = stageRef.current;
|
|
603
610
|
const img = imageRef.current;
|
|
@@ -606,9 +613,9 @@ const ImageViewer = ({ images, initialIndex = 0, index: controlledIndex, onIndex
|
|
|
606
613
|
: next.scale <= MIN_SCALE
|
|
607
614
|
? IDENTITY
|
|
608
615
|
: { ...next, scale: clamp(next.scale, MIN_SCALE, MAX_SCALE) };
|
|
609
|
-
viewRef.current = {
|
|
610
|
-
setStored({
|
|
611
|
-
}, [
|
|
616
|
+
viewRef.current = { visit: visit.number, view: clamped };
|
|
617
|
+
setStored({ visit: visit.number, view: clamped });
|
|
618
|
+
}, [visit.number]);
|
|
612
619
|
const zoomBy = require$$0.useCallback((factor, anchor = { x: 0, y: 0 }) => setView(zoomAround(currentView(), currentView().scale * factor, anchor)), [setView, currentView]);
|
|
613
620
|
const reset = require$$0.useCallback(() => setView(IDENTITY), [setView]);
|
|
614
621
|
const go = require$$0.useCallback((step) => {
|
package/dist/index.esm.js
CHANGED
|
@@ -560,13 +560,20 @@ const ImageViewer = ({ images, initialIndex = 0, index: controlledIndex, onIndex
|
|
|
560
560
|
const last = Math.max(0, images.length - 1);
|
|
561
561
|
const [ownIndex, setOwnIndex] = useState(() => clamp(initialIndex, 0, last));
|
|
562
562
|
const index = clamp(controlledIndex ?? ownIndex, 0, last);
|
|
563
|
-
//
|
|
564
|
-
//
|
|
563
|
+
// Cada vez que cambia la imagen visible es una visita nueva, y la vista (zoom
|
|
564
|
+
// y posición) guarda a qué visita pertenece: al cambiar de imagen vuelve sola
|
|
565
|
+
// al 100 %, también al regresar a una ya vista (antes guardaba la imagen y,
|
|
566
|
+
// de vuelta en ella sin hacer zoom en otra, recuperaba el zoom anterior).
|
|
567
|
+
const [visit, setVisit] = useState({ index, number: 0 });
|
|
568
|
+
if (visit.index !== index)
|
|
569
|
+
setVisit({ index, number: visit.number + 1 });
|
|
565
570
|
const [stored, setStored] = useState({
|
|
566
|
-
|
|
571
|
+
visit: 0,
|
|
567
572
|
view: IDENTITY,
|
|
568
573
|
});
|
|
569
|
-
const view =
|
|
574
|
+
const view = visit.index === index && stored.visit === visit.number
|
|
575
|
+
? stored.view
|
|
576
|
+
: IDENTITY;
|
|
570
577
|
const viewRef = useRef(stored);
|
|
571
578
|
// Mientras hay un gesto, el zoom sigue al dedo sin animación
|
|
572
579
|
const [dragging, setDragging] = useState(false);
|
|
@@ -593,7 +600,7 @@ const ImageViewer = ({ images, initialIndex = 0, index: controlledIndex, onIndex
|
|
|
593
600
|
const center = stageCenter();
|
|
594
601
|
return { x: point.x - center.x, y: point.y - center.y };
|
|
595
602
|
};
|
|
596
|
-
const currentView = useCallback(() =>
|
|
603
|
+
const currentView = useCallback(() => viewRef.current.visit === visit.number ? viewRef.current.view : IDENTITY, [visit.number]);
|
|
597
604
|
const setView = useCallback((next) => {
|
|
598
605
|
const stage = stageRef.current;
|
|
599
606
|
const img = imageRef.current;
|
|
@@ -602,9 +609,9 @@ const ImageViewer = ({ images, initialIndex = 0, index: controlledIndex, onIndex
|
|
|
602
609
|
: next.scale <= MIN_SCALE
|
|
603
610
|
? IDENTITY
|
|
604
611
|
: { ...next, scale: clamp(next.scale, MIN_SCALE, MAX_SCALE) };
|
|
605
|
-
viewRef.current = {
|
|
606
|
-
setStored({
|
|
607
|
-
}, [
|
|
612
|
+
viewRef.current = { visit: visit.number, view: clamped };
|
|
613
|
+
setStored({ visit: visit.number, view: clamped });
|
|
614
|
+
}, [visit.number]);
|
|
608
615
|
const zoomBy = useCallback((factor, anchor = { x: 0, y: 0 }) => setView(zoomAround(currentView(), currentView().scale * factor, anchor)), [setView, currentView]);
|
|
609
616
|
const reset = useCallback(() => setView(IDENTITY), [setView]);
|
|
610
617
|
const go = useCallback((step) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rubenpazch/image-viewer",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "ImageViewer component",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"@rubenpazch/tokens": "0.5.0"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@rubenpazch/icons": "^6.6.
|
|
36
|
-
"@rubenpazch/shared": "5.
|
|
35
|
+
"@rubenpazch/icons": "^6.6.2",
|
|
36
|
+
"@rubenpazch/shared": "5.5.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@rubenpazch/eslint-config": "4.0.0",
|
|
40
40
|
"@rubenpazch/typescript-config": "3.0.0",
|
|
41
|
-
"@rubenpazch/button": "^6.2.
|
|
41
|
+
"@rubenpazch/button": "^6.2.7"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|