yet-another-react-lightbox 3.21.2 → 3.21.4

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { LightboxExternalProps, LightboxProps, Labels, Slide, SlideImage, LengthOrPercentage, ContainerRect, ToolbarSettings, CarouselSettings, Component, Module, Node as Node$1, Plugin, Augmentation, EventTypes, ComponentProps, LightboxStateSwipeAction, LightboxStateUpdateAction, LightboxState, Render, ControllerSettings, ControllerRef, Callback, RenderFunction } from './types.js';
2
+ import { LightboxExternalProps, LightboxProps, Labels, Label, Slide, SlideImage, LengthOrPercentage, ContainerRect, ToolbarSettings, CarouselSettings, Component, Module, Node as Node$1, Plugin, Augmentation, EventTypes, ComponentProps, LightboxStateSwipeAction, LightboxStateUpdateAction, LightboxState, Render, ControllerSettings, ControllerRef, Callback, RenderFunction } from './types.js';
3
3
  export { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_ERROR, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, AnimationSettings, CLASS_FLEX_CENTER, CLASS_FULLSIZE, CLASS_NO_SCROLL, CLASS_NO_SCROLL_PADDING, CLASS_SLIDE_WRAPPER, CLASS_SLIDE_WRAPPER_INTERACTIVE, Callbacks, ClickCallbackProps, DeepPartial, DeepPartialValue, ELEMENT_BUTTON, ELEMENT_ICON, EVENT_ON_KEY_DOWN, EVENT_ON_KEY_UP, EVENT_ON_POINTER_CANCEL, EVENT_ON_POINTER_DOWN, EVENT_ON_POINTER_LEAVE, EVENT_ON_POINTER_MOVE, EVENT_ON_POINTER_UP, EVENT_ON_WHEEL, GenericSlide, IMAGE_FIT_CONTAIN, IMAGE_FIT_COVER, ImageFit, ImageSource, MODULE_CAROUSEL, MODULE_CONTROLLER, MODULE_NAVIGATION, MODULE_NO_SCROLL, MODULE_PORTAL, MODULE_ROOT, MODULE_TOOLBAR, NavigationAction, NoScrollSettings, PLUGIN_CAPTIONS, PLUGIN_COUNTER, PLUGIN_DOWNLOAD, PLUGIN_FULLSCREEN, PLUGIN_INLINE, PLUGIN_SHARE, PLUGIN_SLIDESHOW, PLUGIN_THUMBNAILS, PLUGIN_ZOOM, PluginProps, PortalSettings, RenderSlideContainerProps, RenderSlideFooterProps, RenderSlideHeaderProps, RenderSlideProps, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLACEHOLDER, SLIDE_STATUS_PLAYING, SlideStatus, SlideTypeKey, SlideTypes, Slot, SlotStyles, SlotType, ToolbarButtonKey, ToolbarButtonKeys, UNKNOWN_ACTION_TYPE, VK_ARROW_LEFT, VK_ARROW_RIGHT, VK_ESCAPE, ViewCallbackProps, activeSlideStatus } from './types.js';
4
4
 
5
5
  /** Lightbox component */
@@ -12,7 +12,7 @@ declare function cssClass(name: string): string;
12
12
  declare function cssVar(name: string): string;
13
13
  declare function composePrefix(base: string, prefix?: string): string;
14
14
  declare function makeComposePrefix(base: string): (prefix?: string) => string;
15
- declare function label(labels: Labels | undefined, defaultLabel: string): string;
15
+ declare function label(labels: Labels | undefined, defaultLabel: Label): string;
16
16
  declare function cleanup(...cleaners: (() => void)[]): () => void;
17
17
  declare function makeUseContext<T>(name: string, contextName: string, context: React.Context<T | null>): () => NonNullable<T>;
18
18
  declare function hasWindow(): boolean;
@@ -162,7 +162,7 @@ declare const useTimeouts: () => TimeoutsContextType;
162
162
  declare function TimeoutsProvider({ children }: React.PropsWithChildren): React.JSX.Element;
163
163
 
164
164
  type IconButtonProps = React.ComponentProps<"button"> & {
165
- label: string;
165
+ label: Label;
166
166
  icon: React.ElementType;
167
167
  renderIcon?: () => React.ReactNode;
168
168
  };
@@ -249,7 +249,7 @@ declare function Controller({ children, ...props }: ComponentProps): React.JSX.E
249
249
  declare const ControllerModule: Module;
250
250
 
251
251
  type NavigationButtonProps = {
252
- label: string;
252
+ label: Label;
253
253
  icon: React.ElementType;
254
254
  renderIcon?: RenderFunction;
255
255
  action: "prev" | "next";
@@ -280,4 +280,4 @@ declare const RootModule: Module;
280
280
  declare function Toolbar({ toolbar: { buttons }, render: { buttonClose, iconClose }, styles }: ComponentProps): React.JSX.Element;
281
281
  declare const ToolbarModule: Module;
282
282
 
283
- export { Augmentation, Callback, Carousel, CarouselModule, CarouselSettings, CloseIcon, Component, ComponentProps, type ComputeAnimation, ContainerRect, Controller, ControllerContext, type ControllerContextType, ControllerModule, ControllerRef, ControllerSettings, DocumentContext, DocumentContextProvider, type DocumentContextProviderProps, type DocumentContextType, ErrorIcon, type Event, type EventCallback, EventTypes, EventsContext, type EventsContextType, EventsProvider, IconButton, type IconButtonProps, ImageSlide, type ImageSlideProps, type KeyboardEventType, Labels, LengthOrPercentage, Lightbox, LightboxDefaultProps, LightboxDispatchContext, type LightboxDispatchContextType, LightboxExternalProps, LightboxProps, LightboxPropsContext, type LightboxPropsContextType, LightboxPropsProvider, LightboxRoot, LightboxState, type LightboxStateAction, LightboxStateContext, type LightboxStateContextType, LightboxStateProvider, type LightboxStateProviderProps, LightboxStateSwipeAction, LightboxStateUpdateAction, LoadingIcon, Module, Navigation, NavigationButton, type NavigationButtonProps, NavigationModule, NextIcon, NoScroll, NoScrollModule, Node$1 as Node, Plugin, type PointerEventType, Portal, PortalModule, PreviousIcon, type Publish, type ReactEventType, type RegisterSensors, Render, RenderFunction, Root, RootModule, type SensorCallback, Slide, SlideImage, type Subscribe, type SubscribeSensors, type SupportedEventType, SwipeState, TimeoutsContext, type TimeoutsContextType, TimeoutsProvider, Toolbar, ToolbarModule, ToolbarSettings, type Topic, type Unsubscribe, type UseSensors, type WheelEventType, addToolbarButton, calculatePreload, cleanup, clsx, composePrefix, computeSlideRect, createIcon, createIconDisabled, createModule, createNode, cssClass, cssVar, Lightbox as default, devicePixelRatio, getSlide, getSlideIfPresent, getSlideIndex, getSlideKey, hasSlides, hasWindow, isImageFitCover, isImageSlide, label, makeComposePrefix, makeUseContext, parseInt, parseLengthPercentage, round, setRef, stopNavigationEventsPropagation, useAnimation, useContainerRect, useController, useDelay, useDocumentContext, useEventCallback, useEvents, useForkRef, useKeyboardNavigation, useLayoutEffect, useLightboxDispatch, useLightboxProps, useLightboxState, useLoseFocus, useMotionPreference, useNavigationState, usePointerSwipe, usePreventWheelDefaults, useRTL, useSensors, useThrottle, useTimeouts, useWheelSwipe, withPlugins };
283
+ export { Augmentation, Callback, Carousel, CarouselModule, CarouselSettings, CloseIcon, Component, ComponentProps, type ComputeAnimation, ContainerRect, Controller, ControllerContext, type ControllerContextType, ControllerModule, ControllerRef, ControllerSettings, DocumentContext, DocumentContextProvider, type DocumentContextProviderProps, type DocumentContextType, ErrorIcon, type Event, type EventCallback, EventTypes, EventsContext, type EventsContextType, EventsProvider, IconButton, type IconButtonProps, ImageSlide, type ImageSlideProps, type KeyboardEventType, Label, Labels, LengthOrPercentage, Lightbox, LightboxDefaultProps, LightboxDispatchContext, type LightboxDispatchContextType, LightboxExternalProps, LightboxProps, LightboxPropsContext, type LightboxPropsContextType, LightboxPropsProvider, LightboxRoot, LightboxState, type LightboxStateAction, LightboxStateContext, type LightboxStateContextType, LightboxStateProvider, type LightboxStateProviderProps, LightboxStateSwipeAction, LightboxStateUpdateAction, LoadingIcon, Module, Navigation, NavigationButton, type NavigationButtonProps, NavigationModule, NextIcon, NoScroll, NoScrollModule, Node$1 as Node, Plugin, type PointerEventType, Portal, PortalModule, PreviousIcon, type Publish, type ReactEventType, type RegisterSensors, Render, RenderFunction, Root, RootModule, type SensorCallback, Slide, SlideImage, type Subscribe, type SubscribeSensors, type SupportedEventType, SwipeState, TimeoutsContext, type TimeoutsContextType, TimeoutsProvider, Toolbar, ToolbarModule, ToolbarSettings, type Topic, type Unsubscribe, type UseSensors, type WheelEventType, addToolbarButton, calculatePreload, cleanup, clsx, composePrefix, computeSlideRect, createIcon, createIconDisabled, createModule, createNode, cssClass, cssVar, Lightbox as default, devicePixelRatio, getSlide, getSlideIfPresent, getSlideIndex, getSlideKey, hasSlides, hasWindow, isImageFitCover, isImageSlide, label, makeComposePrefix, makeUseContext, parseInt, parseLengthPercentage, round, setRef, stopNavigationEventsPropagation, useAnimation, useContainerRect, useController, useDelay, useDocumentContext, useEventCallback, useEvents, useForkRef, useKeyboardNavigation, useLayoutEffect, useLightboxDispatch, useLightboxProps, useLightboxState, useLoseFocus, useMotionPreference, useNavigationState, usePointerSwipe, usePreventWheelDefaults, useRTL, useSensors, useThrottle, useTimeouts, useWheelSwipe, withPlugins };
@@ -47,6 +47,10 @@ declare module "yet-another-react-lightbox" {
47
47
  /** render custom Captions button */
48
48
  buttonCaptions?: RenderFunction<CaptionsRef>;
49
49
  }
50
+ interface Labels {
51
+ "Show captions"?: string;
52
+ "Hide captions"?: string;
53
+ }
50
54
  /** Captions plugin ref */
51
55
  interface CaptionsRef {
52
56
  /** if `true`, captions are visible */
@@ -29,6 +29,9 @@ declare module "yet-another-react-lightbox" {
29
29
  /** render custom Download icon */
30
30
  iconDownload?: RenderFunction;
31
31
  }
32
+ interface Labels {
33
+ Download?: string;
34
+ }
32
35
  interface Callbacks {
33
36
  /** a callback called on slide download */
34
37
  download?: Callback<DownloadCallbackProps>;
@@ -22,6 +22,10 @@ declare module "yet-another-react-lightbox" {
22
22
  /** render custom Exit Fullscreen icon */
23
23
  iconExitFullscreen?: RenderFunction;
24
24
  }
25
+ interface Labels {
26
+ "Enter Fullscreen"?: string;
27
+ "Exit Fullscreen"?: string;
28
+ }
25
29
  interface Callbacks {
26
30
  /** a callback called when the lightbox enters fullscreen mode */
27
31
  enterFullscreen?: Callback;
@@ -29,6 +29,9 @@ declare module "yet-another-react-lightbox" {
29
29
  /** render custom Share icon */
30
30
  iconShare?: RenderFunction;
31
31
  }
32
+ interface Labels {
33
+ Share?: string;
34
+ }
32
35
  interface Callbacks {
33
36
  /** a callback called on slide share */
34
37
  share?: Callback<ShareCallbackProps>;
@@ -24,6 +24,10 @@ declare module "yet-another-react-lightbox" {
24
24
  /** render custom Slideshow button */
25
25
  buttonSlideshow?: RenderFunction<SlideshowRef>;
26
26
  }
27
+ interface Labels {
28
+ Play?: string;
29
+ Pause?: string;
30
+ }
27
31
  interface Callbacks {
28
32
  /** a callback called on slideshow playback start */
29
33
  slideshowStart?: Callback;
@@ -52,6 +52,10 @@ declare module "yet-another-react-lightbox" {
52
52
  /** render custom Thumbnails button */
53
53
  buttonThumbnails?: RenderFunction<ThumbnailsRef>;
54
54
  }
55
+ interface Labels {
56
+ "Show thumbnails"?: string;
57
+ "Hide thumbnails"?: string;
58
+ }
55
59
  /** `render.thumbnail` render function props */
56
60
  type RenderThumbnailProps = {
57
61
  slide: Slide;
@@ -42,6 +42,10 @@ declare module "yet-another-react-lightbox" {
42
42
  /** render custom Zoom Out icon */
43
43
  iconZoomOut?: RenderFunction;
44
44
  }
45
+ interface Labels {
46
+ "Zoom in"?: string;
47
+ "Zoom out"?: string;
48
+ }
45
49
  interface RenderSlideProps {
46
50
  /** current zoom level */
47
51
  zoom?: number;
@@ -115,6 +115,9 @@ function useZoomImageRect(slideRect, imageDimensions) {
115
115
  function distance(pointerA, pointerB) {
116
116
  return ((pointerA.clientX - pointerB.clientX) ** 2 + (pointerA.clientY - pointerB.clientY) ** 2) ** 0.5;
117
117
  }
118
+ function scaleZoom(value, delta, factor = 100, clamp = 2) {
119
+ return value * Math.min(1 + Math.abs(delta / factor), clamp) ** Math.sign(delta);
120
+ }
118
121
  function useZoomSensors(zoom, maxZoom, disabled, changeZoom, changeOffsets, zoomWrapperRef) {
119
122
  const activePointers = React.useRef([]);
120
123
  const lastPointerDown = React.useRef(0);
@@ -174,7 +177,7 @@ function useZoomSensors(zoom, maxZoom, disabled, changeZoom, changeOffsets, zoom
174
177
  if (event.ctrlKey || scrollToZoom) {
175
178
  if (Math.abs(event.deltaY) > Math.abs(event.deltaX)) {
176
179
  event.stopPropagation();
177
- changeZoom(zoom * (1 - event.deltaY / wheelZoomDistanceFactor), true, ...translateCoordinates(event));
180
+ changeZoom(scaleZoom(zoom, -event.deltaY, wheelZoomDistanceFactor), true, ...translateCoordinates(event));
178
181
  return;
179
182
  }
180
183
  }
@@ -197,7 +200,8 @@ function useZoomSensors(zoom, maxZoom, disabled, changeZoom, changeOffsets, zoom
197
200
  const onPointerDown = useEventCallback((event) => {
198
201
  var _a;
199
202
  const pointers = activePointers.current;
200
- if (!((_a = zoomWrapperRef === null || zoomWrapperRef === void 0 ? void 0 : zoomWrapperRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.target))) {
203
+ if ((event.pointerType === "mouse" && event.buttons > 1) ||
204
+ !((_a = zoomWrapperRef === null || zoomWrapperRef === void 0 ? void 0 : zoomWrapperRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.target))) {
201
205
  return;
202
206
  }
203
207
  if (zoom > 1) {
@@ -226,7 +230,7 @@ function useZoomSensors(zoom, maxZoom, disabled, changeZoom, changeOffsets, zoom
226
230
  const currentDistance = distance(pointers[0], pointers[1]);
227
231
  const delta = currentDistance - pinchZoomDistance.current;
228
232
  if (Math.abs(delta) > 0) {
229
- changeZoom(zoom * (1 + delta / pinchZoomDistanceFactor), true, ...pointers
233
+ changeZoom(scaleZoom(zoom, delta, pinchZoomDistanceFactor), true, ...pointers
230
234
  .map((x) => translateCoordinates(x))
231
235
  .reduce((acc, coordinate) => coordinate.map((x, i) => acc[i] + x / 2)));
232
236
  pinchZoomDistance.current = currentDistance;
package/dist/types.d.ts CHANGED
@@ -68,7 +68,7 @@ interface LightboxProps {
68
68
  slides: Slide[];
69
69
  /** custom render functions */
70
70
  render: Render;
71
- /** custom UI labels */
71
+ /** custom UI labels / translations */
72
72
  labels: Labels;
73
73
  /** enabled plugins */
74
74
  plugins: Plugin[];
@@ -375,10 +375,13 @@ interface Callbacks {
375
375
  /** a callback called when the portal closes */
376
376
  exited?: Callback;
377
377
  }
378
- /** Custom UI labels */
379
- type Labels = {
380
- [key: string]: string;
381
- };
378
+ /** Custom UI labels / translations */
379
+ interface Labels {
380
+ Previous?: string;
381
+ Next?: string;
382
+ Close?: string;
383
+ }
384
+ type Label = keyof Labels;
382
385
  /** Toolbar settings */
383
386
  interface ToolbarSettings {
384
387
  /** buttons to render in the toolbar */
@@ -429,4 +432,4 @@ type DeepPartialValue<T, E extends string = never> = T extends any[] ? T : T ext
429
432
  [P in keyof T]?: P extends E ? T[P] : DeepPartialValue<T[P], E>;
430
433
  } : T;
431
434
 
432
- export { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_ERROR, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, type AnimationSettings, type Augmentation, CLASS_FLEX_CENTER, CLASS_FULLSIZE, CLASS_NO_SCROLL, CLASS_NO_SCROLL_PADDING, CLASS_SLIDE_WRAPPER, CLASS_SLIDE_WRAPPER_INTERACTIVE, type Callback, type Callbacks, type CarouselSettings, type ClickCallbackProps, type Component, type ComponentProps, type ContainerRect, type ControllerRef, type ControllerSettings, type DeepPartial, type DeepPartialValue, ELEMENT_BUTTON, ELEMENT_ICON, EVENT_ON_KEY_DOWN, EVENT_ON_KEY_UP, EVENT_ON_POINTER_CANCEL, EVENT_ON_POINTER_DOWN, EVENT_ON_POINTER_LEAVE, EVENT_ON_POINTER_MOVE, EVENT_ON_POINTER_UP, EVENT_ON_WHEEL, type EventTypes, type GenericSlide, IMAGE_FIT_CONTAIN, IMAGE_FIT_COVER, type ImageFit, type ImageSource, type Labels, type LengthOrPercentage, type LightboxExternalProps, type LightboxProps, type LightboxState, type LightboxStateSwipeAction, type LightboxStateUpdateAction, MODULE_CAROUSEL, MODULE_CONTROLLER, MODULE_NAVIGATION, MODULE_NO_SCROLL, MODULE_PORTAL, MODULE_ROOT, MODULE_TOOLBAR, type Module, type NavigationAction, type NoScrollSettings, type Node, PLUGIN_CAPTIONS, PLUGIN_COUNTER, PLUGIN_DOWNLOAD, PLUGIN_FULLSCREEN, PLUGIN_INLINE, PLUGIN_SHARE, PLUGIN_SLIDESHOW, PLUGIN_THUMBNAILS, PLUGIN_ZOOM, type Plugin, type PluginProps, type PortalSettings, type Render, type RenderFunction, type RenderSlideContainerProps, type RenderSlideFooterProps, type RenderSlideHeaderProps, type RenderSlideProps, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLACEHOLDER, SLIDE_STATUS_PLAYING, type Slide, type SlideImage, type SlideStatus, type SlideTypeKey, type SlideTypes, type Slot, type SlotStyles, type SlotType, type ToolbarButtonKey, type ToolbarButtonKeys, type ToolbarSettings, UNKNOWN_ACTION_TYPE, VK_ARROW_LEFT, VK_ARROW_RIGHT, VK_ESCAPE, type ViewCallbackProps, activeSlideStatus };
435
+ export { ACTION_CLOSE, ACTION_NEXT, ACTION_PREV, ACTION_SWIPE, ACTIVE_SLIDE_COMPLETE, ACTIVE_SLIDE_ERROR, ACTIVE_SLIDE_LOADING, ACTIVE_SLIDE_PLAYING, type AnimationSettings, type Augmentation, CLASS_FLEX_CENTER, CLASS_FULLSIZE, CLASS_NO_SCROLL, CLASS_NO_SCROLL_PADDING, CLASS_SLIDE_WRAPPER, CLASS_SLIDE_WRAPPER_INTERACTIVE, type Callback, type Callbacks, type CarouselSettings, type ClickCallbackProps, type Component, type ComponentProps, type ContainerRect, type ControllerRef, type ControllerSettings, type DeepPartial, type DeepPartialValue, ELEMENT_BUTTON, ELEMENT_ICON, EVENT_ON_KEY_DOWN, EVENT_ON_KEY_UP, EVENT_ON_POINTER_CANCEL, EVENT_ON_POINTER_DOWN, EVENT_ON_POINTER_LEAVE, EVENT_ON_POINTER_MOVE, EVENT_ON_POINTER_UP, EVENT_ON_WHEEL, type EventTypes, type GenericSlide, IMAGE_FIT_CONTAIN, IMAGE_FIT_COVER, type ImageFit, type ImageSource, type Label, type Labels, type LengthOrPercentage, type LightboxExternalProps, type LightboxProps, type LightboxState, type LightboxStateSwipeAction, type LightboxStateUpdateAction, MODULE_CAROUSEL, MODULE_CONTROLLER, MODULE_NAVIGATION, MODULE_NO_SCROLL, MODULE_PORTAL, MODULE_ROOT, MODULE_TOOLBAR, type Module, type NavigationAction, type NoScrollSettings, type Node, PLUGIN_CAPTIONS, PLUGIN_COUNTER, PLUGIN_DOWNLOAD, PLUGIN_FULLSCREEN, PLUGIN_INLINE, PLUGIN_SHARE, PLUGIN_SLIDESHOW, PLUGIN_THUMBNAILS, PLUGIN_ZOOM, type Plugin, type PluginProps, type PortalSettings, type Render, type RenderFunction, type RenderSlideContainerProps, type RenderSlideFooterProps, type RenderSlideHeaderProps, type RenderSlideProps, SLIDE_STATUS_COMPLETE, SLIDE_STATUS_ERROR, SLIDE_STATUS_LOADING, SLIDE_STATUS_PLACEHOLDER, SLIDE_STATUS_PLAYING, type Slide, type SlideImage, type SlideStatus, type SlideTypeKey, type SlideTypes, type Slot, type SlotStyles, type SlotType, type ToolbarButtonKey, type ToolbarButtonKeys, type ToolbarSettings, UNKNOWN_ACTION_TYPE, VK_ARROW_LEFT, VK_ARROW_RIGHT, VK_ESCAPE, type ViewCallbackProps, activeSlideStatus };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yet-another-react-lightbox",
3
- "version": "3.21.2",
3
+ "version": "3.21.4",
4
4
  "description": "Modern React lightbox component",
5
5
  "author": "Igor Danchenko",
6
6
  "license": "MIT",