@rubenpazch/image-viewer 1.1.0 → 1.2.1

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 CHANGED
@@ -34,6 +34,8 @@ restablece y Escape cierra (sin llegar a lo que está debajo, como un Drawer).
34
34
 
35
35
  ## DEFAULT_IMAGE_VIEWER_LABELS
36
36
 
37
+ Textos en castellano (los del diccionario `es`). Con `UiLocaleProvider` cambian solos.
38
+
37
39
  _Sin props documentadas._
38
40
 
39
41
  Tipos: `ImageViewerProps`, `ImageViewerItem`, `ImageViewerLabels`.
@@ -30,6 +30,7 @@ export interface ImageViewerLabels {
30
30
  hintTouch: string;
31
31
  hintMouse: string;
32
32
  }
33
+ /** Textos en castellano (los del diccionario `es`). Con `UiLocaleProvider` cambian solos. */
33
34
  export declare const DEFAULT_IMAGE_VIEWER_LABELS: ImageViewerLabels;
34
35
  export interface ImageViewerProps {
35
36
  /** Imágenes que se pueden recorrer. */
@@ -1 +1 @@
1
- {"version":3,"file":"ImageViewer.d.ts","sourceRoot":"","sources":["../src/ImageViewer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAYxE,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;IAC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
5
  var require$$0 = require('react');
6
+ var shared = require('@rubenpazch/shared');
6
7
  var reactDom = require('react-dom');
7
8
 
8
9
  var jsxRuntime = {exports: {}};
@@ -500,22 +501,8 @@ var css_248z = "/* Visor a pantalla completa, siempre oscuro (como cualquier vis
500
501
  var styles = {"viewer":"ImageViewer-module_viewer__v3SKG","topBar":"ImageViewer-module_topBar__4-SPt","titleBlock":"ImageViewer-module_titleBlock__SjK5s","caption":"ImageViewer-module_caption__PGC81","counter":"ImageViewer-module_counter__876EK","toolButton":"ImageViewer-module_toolButton__I3tsO","textButton":"ImageViewer-module_textButton__X4vCS","zoomLevel":"ImageViewer-module_zoomLevel__WMnO8","navButton":"ImageViewer-module_navButton__GjdVy","stage":"ImageViewer-module_stage__FSXpq","stageZoomed":"ImageViewer-module_stageZoomed__MKYnY","image":"ImageViewer-module_image__N9r-N","message":"ImageViewer-module_message__9cqSZ","spinner":"ImageViewer-module_spinner__UnShS","navPrevious":"ImageViewer-module_navPrevious__HoaU-","navNext":"ImageViewer-module_navNext__MTxYT","bottomBar":"ImageViewer-module_bottomBar__4YMQv","zoomGroup":"ImageViewer-module_zoomGroup__7o0RD","hint":"ImageViewer-module_hint__DkWO1"};
501
502
  styleInject(css_248z);
502
503
 
503
- const DEFAULT_IMAGE_VIEWER_LABELS = {
504
- title: "Vista previa de {name}",
505
- counter: "{current} de {total}",
506
- close: "Cerrar",
507
- download: "Descargar",
508
- openInNewTab: "Abrir en una pestaña nueva",
509
- zoomIn: "Acercar",
510
- zoomOut: "Alejar",
511
- reset: "Restablecer zoom",
512
- previous: "Imagen anterior",
513
- next: "Imagen siguiente",
514
- loading: "Cargando imagen…",
515
- loadFailed: "No se pudo cargar la imagen.",
516
- hintTouch: "Pellizca o haz doble toque para hacer zoom. Arrastra para moverte.",
517
- hintMouse: "Usa la rueda del mouse, doble clic o los botones para hacer zoom. Arrastra para moverte.",
518
- };
504
+ /** Textos en castellano (los del diccionario `es`). Con `UiLocaleProvider` cambian solos. */
505
+ const DEFAULT_IMAGE_VIEWER_LABELS = shared.uiMessagesEs.imageViewer;
519
506
  const MIN_SCALE = 1;
520
507
  const MAX_SCALE = 5;
521
508
  const BUTTON_STEP = 1.5;
@@ -573,17 +560,24 @@ const midpoint = (a, b) => ({
573
560
  * restablece y Escape cierra (sin llegar a lo que está debajo, como un Drawer).
574
561
  */
575
562
  const ImageViewer = ({ images, initialIndex = 0, index: controlledIndex, onIndexChange, onClose, onDownload, onOpenInNewTab, labels: labelsProp, }) => {
576
- const labels = { ...DEFAULT_IMAGE_VIEWER_LABELS, ...labelsProp };
563
+ const labels = shared.useUiMessages("imageViewer", labelsProp);
577
564
  const last = Math.max(0, images.length - 1);
578
565
  const [ownIndex, setOwnIndex] = require$$0.useState(() => clamp(initialIndex, 0, last));
579
566
  const index = clamp(controlledIndex ?? ownIndex, 0, last);
580
- // La vista (zoom y posición) guarda a qué imagen pertenece: al cambiar de
581
- // imagen vuelve sola al 100 %, sin efectos que reinicien el estado.
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 });
582
574
  const [stored, setStored] = require$$0.useState({
583
- index,
575
+ visit: 0,
584
576
  view: IDENTITY,
585
577
  });
586
- const view = stored.index === index ? stored.view : IDENTITY;
578
+ const view = visit.index === index && stored.visit === visit.number
579
+ ? stored.view
580
+ : IDENTITY;
587
581
  const viewRef = require$$0.useRef(stored);
588
582
  // Mientras hay un gesto, el zoom sigue al dedo sin animación
589
583
  const [dragging, setDragging] = require$$0.useState(false);
@@ -610,7 +604,7 @@ const ImageViewer = ({ images, initialIndex = 0, index: controlledIndex, onIndex
610
604
  const center = stageCenter();
611
605
  return { x: point.x - center.x, y: point.y - center.y };
612
606
  };
613
- const currentView = require$$0.useCallback(() => (viewRef.current.index === index ? viewRef.current.view : IDENTITY), [index]);
607
+ const currentView = require$$0.useCallback(() => viewRef.current.visit === visit.number ? viewRef.current.view : IDENTITY, [visit.number]);
614
608
  const setView = require$$0.useCallback((next) => {
615
609
  const stage = stageRef.current;
616
610
  const img = imageRef.current;
@@ -619,9 +613,9 @@ const ImageViewer = ({ images, initialIndex = 0, index: controlledIndex, onIndex
619
613
  : next.scale <= MIN_SCALE
620
614
  ? IDENTITY
621
615
  : { ...next, scale: clamp(next.scale, MIN_SCALE, MAX_SCALE) };
622
- viewRef.current = { index, view: clamped };
623
- setStored({ index, view: clamped });
624
- }, [index]);
616
+ viewRef.current = { visit: visit.number, view: clamped };
617
+ setStored({ visit: visit.number, view: clamped });
618
+ }, [visit.number]);
625
619
  const zoomBy = require$$0.useCallback((factor, anchor = { x: 0, y: 0 }) => setView(zoomAround(currentView(), currentView().scale * factor, anchor)), [setView, currentView]);
626
620
  const reset = require$$0.useCallback(() => setView(IDENTITY), [setView]);
627
621
  const go = require$$0.useCallback((step) => {
package/dist/index.d.ts CHANGED
@@ -31,6 +31,7 @@ interface ImageViewerLabels {
31
31
  hintTouch: string;
32
32
  hintMouse: string;
33
33
  }
34
+ /** Textos en castellano (los del diccionario `es`). Con `UiLocaleProvider` cambian solos. */
34
35
  declare const DEFAULT_IMAGE_VIEWER_LABELS: ImageViewerLabels;
35
36
  interface ImageViewerProps {
36
37
  /** Imágenes que se pueden recorrer. */
package/dist/index.esm.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import require$$0, { useState, useRef, useCallback, useEffect } from 'react';
2
+ import { uiMessagesEs, useUiMessages } from '@rubenpazch/shared';
2
3
  import { createPortal } from 'react-dom';
3
4
 
4
5
  var jsxRuntime = {exports: {}};
@@ -496,22 +497,8 @@ var css_248z = "/* Visor a pantalla completa, siempre oscuro (como cualquier vis
496
497
  var styles = {"viewer":"ImageViewer-module_viewer__v3SKG","topBar":"ImageViewer-module_topBar__4-SPt","titleBlock":"ImageViewer-module_titleBlock__SjK5s","caption":"ImageViewer-module_caption__PGC81","counter":"ImageViewer-module_counter__876EK","toolButton":"ImageViewer-module_toolButton__I3tsO","textButton":"ImageViewer-module_textButton__X4vCS","zoomLevel":"ImageViewer-module_zoomLevel__WMnO8","navButton":"ImageViewer-module_navButton__GjdVy","stage":"ImageViewer-module_stage__FSXpq","stageZoomed":"ImageViewer-module_stageZoomed__MKYnY","image":"ImageViewer-module_image__N9r-N","message":"ImageViewer-module_message__9cqSZ","spinner":"ImageViewer-module_spinner__UnShS","navPrevious":"ImageViewer-module_navPrevious__HoaU-","navNext":"ImageViewer-module_navNext__MTxYT","bottomBar":"ImageViewer-module_bottomBar__4YMQv","zoomGroup":"ImageViewer-module_zoomGroup__7o0RD","hint":"ImageViewer-module_hint__DkWO1"};
497
498
  styleInject(css_248z);
498
499
 
499
- const DEFAULT_IMAGE_VIEWER_LABELS = {
500
- title: "Vista previa de {name}",
501
- counter: "{current} de {total}",
502
- close: "Cerrar",
503
- download: "Descargar",
504
- openInNewTab: "Abrir en una pestaña nueva",
505
- zoomIn: "Acercar",
506
- zoomOut: "Alejar",
507
- reset: "Restablecer zoom",
508
- previous: "Imagen anterior",
509
- next: "Imagen siguiente",
510
- loading: "Cargando imagen…",
511
- loadFailed: "No se pudo cargar la imagen.",
512
- hintTouch: "Pellizca o haz doble toque para hacer zoom. Arrastra para moverte.",
513
- hintMouse: "Usa la rueda del mouse, doble clic o los botones para hacer zoom. Arrastra para moverte.",
514
- };
500
+ /** Textos en castellano (los del diccionario `es`). Con `UiLocaleProvider` cambian solos. */
501
+ const DEFAULT_IMAGE_VIEWER_LABELS = uiMessagesEs.imageViewer;
515
502
  const MIN_SCALE = 1;
516
503
  const MAX_SCALE = 5;
517
504
  const BUTTON_STEP = 1.5;
@@ -569,17 +556,24 @@ const midpoint = (a, b) => ({
569
556
  * restablece y Escape cierra (sin llegar a lo que está debajo, como un Drawer).
570
557
  */
571
558
  const ImageViewer = ({ images, initialIndex = 0, index: controlledIndex, onIndexChange, onClose, onDownload, onOpenInNewTab, labels: labelsProp, }) => {
572
- const labels = { ...DEFAULT_IMAGE_VIEWER_LABELS, ...labelsProp };
559
+ const labels = useUiMessages("imageViewer", labelsProp);
573
560
  const last = Math.max(0, images.length - 1);
574
561
  const [ownIndex, setOwnIndex] = useState(() => clamp(initialIndex, 0, last));
575
562
  const index = clamp(controlledIndex ?? ownIndex, 0, last);
576
- // La vista (zoom y posición) guarda a qué imagen pertenece: al cambiar de
577
- // imagen vuelve sola al 100 %, sin efectos que reinicien el estado.
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 });
578
570
  const [stored, setStored] = useState({
579
- index,
571
+ visit: 0,
580
572
  view: IDENTITY,
581
573
  });
582
- const view = stored.index === index ? stored.view : IDENTITY;
574
+ const view = visit.index === index && stored.visit === visit.number
575
+ ? stored.view
576
+ : IDENTITY;
583
577
  const viewRef = useRef(stored);
584
578
  // Mientras hay un gesto, el zoom sigue al dedo sin animación
585
579
  const [dragging, setDragging] = useState(false);
@@ -606,7 +600,7 @@ const ImageViewer = ({ images, initialIndex = 0, index: controlledIndex, onIndex
606
600
  const center = stageCenter();
607
601
  return { x: point.x - center.x, y: point.y - center.y };
608
602
  };
609
- const currentView = useCallback(() => (viewRef.current.index === index ? viewRef.current.view : IDENTITY), [index]);
603
+ const currentView = useCallback(() => viewRef.current.visit === visit.number ? viewRef.current.view : IDENTITY, [visit.number]);
610
604
  const setView = useCallback((next) => {
611
605
  const stage = stageRef.current;
612
606
  const img = imageRef.current;
@@ -615,9 +609,9 @@ const ImageViewer = ({ images, initialIndex = 0, index: controlledIndex, onIndex
615
609
  : next.scale <= MIN_SCALE
616
610
  ? IDENTITY
617
611
  : { ...next, scale: clamp(next.scale, MIN_SCALE, MAX_SCALE) };
618
- viewRef.current = { index, view: clamped };
619
- setStored({ index, view: clamped });
620
- }, [index]);
612
+ viewRef.current = { visit: visit.number, view: clamped };
613
+ setStored({ visit: visit.number, view: clamped });
614
+ }, [visit.number]);
621
615
  const zoomBy = useCallback((factor, anchor = { x: 0, y: 0 }) => setView(zoomAround(currentView(), currentView().scale * factor, anchor)), [setView, currentView]);
622
616
  const reset = useCallback(() => setView(IDENTITY), [setView]);
623
617
  const go = useCallback((step) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rubenpazch/image-viewer",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "ImageViewer component",
5
5
  "private": false,
6
6
  "main": "dist/index.cjs.js",
@@ -32,12 +32,13 @@
32
32
  "@rubenpazch/tokens": "0.5.0"
33
33
  },
34
34
  "dependencies": {
35
- "@rubenpazch/icons": "^6.6.0"
35
+ "@rubenpazch/icons": "^6.6.1",
36
+ "@rubenpazch/shared": "5.4.0"
36
37
  },
37
38
  "devDependencies": {
38
39
  "@rubenpazch/eslint-config": "4.0.0",
39
40
  "@rubenpazch/typescript-config": "3.0.0",
40
- "@rubenpazch/button": "^6.2.5"
41
+ "@rubenpazch/button": "^6.2.6"
41
42
  },
42
43
  "publishConfig": {
43
44
  "access": "public"