point-focus 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Adrian Perdomo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the β€œSoftware”), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED β€œAS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # πŸš€ point-focus
2
+
3
+ **point-focus** is a modern, highly customizable, and SSR-friendly React image magnifier and zoom component. Add intuitive zoom, drag, and pan capabilities to your imagesβ€”ideal for product galleries, portfolios, or any app that demands detailed inspection. Designed with performance, accessibility, and developer experience in mind.
4
+
5
+ ## ✨ Features
6
+
7
+ - **SSR Friendly** – Seamlessly compatible with Next.js, Gatsby, and other server-rendering frameworks.
8
+ - **Click, Hover, or Programmatic Zoom Activation** – Fully customizable interaction types.
9
+ - **Smooth Drag & Inertia** – Physics-based panning with momentum.
10
+ - **Responsive & Touch Ready** – Optimized for both desktop and mobile experiences.
11
+ - **Accessible** – Full ARIA support and keyboard navigation.
12
+ - **Custom Loading & Error UI** – Placeholders for both base and zoomed images.
13
+ - **External Zoom State Control** – Fully controlled or uncontrolled behavior.
14
+ - **Easy Styling:** Modern, modular CSS/SCSS for effortless customization.
15
+ - **Lightweight** – No external dependencies except React.
16
+
17
+ ## πŸ› οΈ Technologies
18
+
19
+ - **React** – Declarative UI
20
+ - **TypeScript** – Safer development
21
+ - **SCSS Modules** – Scoped styling
22
+
23
+ **Requirements:**
24
+ - React 17+
25
+ - Node.js with npm or yarn
26
+
27
+ ## βš™οΈ Installation
28
+
29
+ ```bash
30
+ npm install point-focus
31
+ # or
32
+ yarn add point-focus
33
+ ```
34
+
35
+ ## πŸš€ Usage
36
+
37
+ ```tsx
38
+ import ImageMagnifier from 'point-focus'
39
+
40
+ function Example() {
41
+ return (
42
+ <ImageMagnifier
43
+ src="/images/sample.jpg"
44
+ zoomSrc="/images/sample-large.jpg"
45
+ moveType="drag"
46
+ zoomType="click"
47
+ alt='Image alt'
48
+ zoomScale={2}
49
+ />
50
+ )
51
+ }
52
+ ```
53
+
54
+ ## πŸ”§ Props Overview
55
+
56
+ | Prop | Type | Default | Description |
57
+ |-------------------------|-------------------------------|-------------|-------------|
58
+ | `src` | `string` | β€” (required) | Main image source |
59
+ | `zoomSrc` | `string` | `src` | High-res zoom source |
60
+ | `sources` | `array` | β€” | `<source>` tags for `<picture>` |
61
+ | `width` / `height` | `number` | β€” | Container dimensions |
62
+ | `zoomScale` | `number` | `1` | Magnification ratio |
63
+ | `zoomPreload` | `boolean` | `false` | Preload zoom image on mount |
64
+ | `fadeDuration` | `number` | `150` | Animation duration in ms |
65
+ | `moveType` | `'follow' | 'drag' | 'pinch'` | `'follow'` | Pan behavior during zoom |
66
+ | `zoomType` | `'click' | 'hover'` | `'click'` | How zoom is activated |
67
+ | `clickToZoomOut` | `boolean` | `false` | Allow clicking image to zoom out |
68
+ | `hideCloseButton` | `boolean` | `false` | Hide zoom-close button |
69
+ | `alt` | `string` | `''` | Alt text for both images |
70
+ | `tabIndex` | `number` | `0` | Keyboard navigation index |
71
+ | `containerClassName` | `string` | β€” | Extra class for the wrapper |
72
+ | `baseImageClassName` | `string` | β€” | Extra class for the base image |
73
+ | `zoomImageClassName` | `string` | β€” | Extra class for zoom image |
74
+ | `closeButtonClassName` | `string` | β€” | Custom class for close button |
75
+ | `containerAriaLabel` | `string` | β€” | Accessibility label for container |
76
+ | `zoomImageAriaLabel` | `string` | β€” | ARIA label for zoom image |
77
+ | `closeButtonAriaLabel` | `string` | β€” | ARIA label for close button |
78
+ | `closeButtonContent` | `ReactNode` | `X` icon | Replace the default close icon |
79
+ | `overlay` | `ReactNode` | β€” | Optional overlay inside zoom container |
80
+ | `loadingPlaceholder` | `ReactNode` | β€” | Shown while zoom image loads |
81
+ | `errorPlaceholder` | `ReactNode` | β€” | Shown if zoom image fails |
82
+ | `externalZoomState` | `boolean` | β€” | For controlled zoom state |
83
+ | `setExternalZoomState` | `(val: boolean) => void` | β€” | Setter for external zoom state |
84
+ | `onMouseEnter` | `() => void` | β€” | Called on hover enter |
85
+ | `onMouseLeave` | `() => void` | β€” | Called on hover leave |
86
+ | `onClickImage` | `() => void` | β€” | Called when image is clicked |
87
+ | `onZoom` | `() => void` | β€” | Called when zoom starts |
88
+ | `onClose` | `() => void` | β€” | Called when zoom closes |
89
+ | `afterZoomImgLoaded` | `() => void` | β€” | Called when zoom image loads |
90
+ | `afterZoomOut` | `() => void` | β€” | Called after zoom exits |
91
+ | `onBaseImageError` | `() => void` | β€” | Called if base image fails to load |
92
+ | `onZoomImageError` | `() => void` | β€” | Called if zoom image fails to load |
93
+ | `onDragStart` | `() => void` | β€” | Called on drag start |
94
+ | `onDragEnd` | `() => void` | β€” | Called on drag end |
95
+
96
+ ## 🧭 Roadmap
97
+
98
+ ### βœ… Already Implemented
99
+ - SSR support (Next.js, Gatsby)
100
+ - Click or hover zoom trigger
101
+ - Follow mouse or drag pan
102
+ - Inertia and momentum
103
+ - Touch & mobile compatibility
104
+ - Custom placeholders (loading/error)
105
+ - Close button toggle
106
+ - External zoom state (controlled usage)
107
+ - ARIA and keyboard support
108
+ - Custom class names for styling
109
+ - `picture` element support for responsive images
110
+ - Custom overlays, labels, and alt text
111
+ - Programmatic zoom positioning setup via `onLoadCallback`
112
+
113
+ ### 🚧 Planned Features
114
+ - [ ] **Pinch-to-zoom** for touch devices
115
+ - [ ] **Zoom lens / magnifier glass** effect
116
+ - [ ] **Zoom on scroll / mouse wheel**
117
+ - [ ] **Double-click or double-tap to zoom**
118
+ - [ ] **Animated transitions with easing customization**
119
+ - [ ] **Programmatic zoom in/out methods**
120
+ - [ ] **Granular keyboard navigation**
121
+ - [ ] **Fallback UI for broken zoom images**
122
+ - [ ] **Built-in modal/lightbox integration**
123
+
124
+ ## 🀝 Contributing
125
+
126
+ PRs and issues welcome!
127
+
128
+ 1. Fork it
129
+ 2. Create a branch (`git checkout -b feature/myFeature`)
130
+ 3. Commit your changes
131
+ 4. Push to your branch
132
+ 5. Open a pull request
133
+
134
+ ## πŸ“„ License
135
+
136
+ MIT License.
137
+
138
+ ## πŸ“ž Contact
139
+
140
+ **Adrian Perdomo**
141
+ GitHub: [aperdomoll90/point-focus](https://github.com/aperdomoll90/point-focus)
@@ -0,0 +1,3 @@
1
+ import { IImageMagnifierTypes } from './ImageMagnifier.types';
2
+ declare const ImageMagnifier: ({ src, sources, width, height, zoomSrc, zoomScale, zoomPreload, fadeDuration, moveType, zoomType, baseImageStyle, hideCloseButton, containerClassName, baseImageClassName, zoomImageClassName, closeButtonClassName, onMouseEnter, onZoomedMouseMove, onMouseLeave, onClickImage, onZoom, onClose, afterZoomImgLoaded, afterZoomOut, onBaseImageError, onZoomImageError, onDragStart, onDragEnd, alt, containerAriaLabel, closeButtonAriaLabel, zoomImageAriaLabel, tabIndex, closeButtonContent, overlay, disableDrag, disableInertia, loadingPlaceholder, errorPlaceholder, clickToZoomOut, externalZoomState, setExternalZoomState, }: IImageMagnifierTypes) => import("react/jsx-runtime").JSX.Element;
3
+ export default ImageMagnifier;
@@ -0,0 +1,134 @@
1
+ export type ImageSource = React.SourceHTMLAttributes<HTMLSourceElement>;
2
+ export interface IImageMagnifierTypes {
3
+ src: string;
4
+ sources?: ImageSource[];
5
+ width?: number | undefined;
6
+ height?: number | undefined;
7
+ zoomSrc?: string | undefined;
8
+ zoomScale?: number | undefined;
9
+ zoomPreload?: boolean | undefined;
10
+ fadeDuration?: number | undefined;
11
+ moveType?: 'follow' | 'drag' | 'pinch';
12
+ zoomType?: 'click' | 'hover';
13
+ externalZoomState?: boolean | undefined;
14
+ setExternalZoomState?: (value: boolean) => void | undefined;
15
+ clickToZoomOut?: boolean | undefined;
16
+ containerClassName?: string | undefined;
17
+ baseImageClassName?: string | undefined;
18
+ zoomImageClassName?: string | undefined;
19
+ closeButtonClassName?: string | undefined;
20
+ alt: string;
21
+ containerAriaLabel?: string;
22
+ closeButtonAriaLabel?: string;
23
+ zoomImageAriaLabel?: string;
24
+ tabIndex?: number;
25
+ hideCloseButton?: boolean | undefined;
26
+ closeButtonContent?: React.ReactNode | undefined;
27
+ overlay?: React.ReactNode | undefined;
28
+ baseImageStyle?: React.CSSProperties | undefined;
29
+ onMouseEnter?: (() => void) | undefined;
30
+ onMouseLeave?: (() => void) | undefined;
31
+ onClickImage?: (() => void) | undefined;
32
+ onZoom?: (() => void) | undefined;
33
+ onClose?: (() => void) | undefined;
34
+ afterZoomImgLoaded?: (() => void) | undefined;
35
+ afterZoomOut?: (() => void) | undefined;
36
+ onBaseImageError?: (() => void) | undefined;
37
+ onZoomImageError?: (() => void) | undefined;
38
+ onDragStart?: (() => void) | undefined;
39
+ onDragEnd?: (() => void) | undefined;
40
+ onZoomedMouseMove?: (() => void) | undefined;
41
+ disableDrag?: boolean;
42
+ disableInertia?: boolean;
43
+ loadingPlaceholder?: React.ReactNode;
44
+ errorPlaceholder?: React.ReactNode;
45
+ }
46
+ type ICoordinateObject = {
47
+ x: number;
48
+ y: number;
49
+ };
50
+ export type IImageTypes = {
51
+ onLoadCallback: (() => void) | null;
52
+ bounds: DOMRect | Record<string, number>;
53
+ offsets: ICoordinateObject;
54
+ ratios: ICoordinateObject;
55
+ scaledDimensions: {
56
+ width: number;
57
+ height: number;
58
+ };
59
+ wasDragging: boolean;
60
+ velocity: {
61
+ vx: number;
62
+ vy: number;
63
+ } | null;
64
+ dragStartCoords: ICoordinateObject;
65
+ prevDragCoords: {
66
+ x: number;
67
+ y: number;
68
+ time: number;
69
+ } | null;
70
+ lastDragCoords: {
71
+ x: number;
72
+ y: number;
73
+ time: number;
74
+ } | null;
75
+ };
76
+ export type IZoomImageTypes = {
77
+ src: string;
78
+ fadeDuration: number;
79
+ top: number;
80
+ left: number;
81
+ isZoomed: boolean;
82
+ onLoad?: (e: React.SyntheticEvent<HTMLImageElement>) => void;
83
+ onError?: () => void;
84
+ onClose?: (e: React.MouseEvent) => void;
85
+ onFadeOut?: (e: React.TransitionEvent<HTMLImageElement>) => void;
86
+ closeButtonRef: React.RefObject<HTMLButtonElement>;
87
+ onDragStart?: (e: React.MouseEvent | React.TouchEvent) => void | undefined;
88
+ onDragEnd?: (e: React.MouseEvent | React.TouchEvent) => void | undefined;
89
+ onTouchStart: (e: React.MouseEvent | React.TouchEvent) => void;
90
+ onTouchEnd: (e: React.MouseEvent | React.TouchEvent) => void;
91
+ zoomImageClassName?: string | undefined;
92
+ closeButtonClassName?: string | undefined;
93
+ alt: string;
94
+ closeButtonAriaLabel?: string;
95
+ zoomImageAriaLabel?: string;
96
+ onKeyDown: (e: React.KeyboardEvent) => void;
97
+ closeButtonContent?: React.ReactNode | undefined;
98
+ loadingPlaceholder?: React.ReactNode;
99
+ errorPlaceholder?: React.ReactNode;
100
+ };
101
+ export type IBaseImageTypes = {
102
+ src: string;
103
+ sources?: ImageSource[];
104
+ width?: number;
105
+ height?: number;
106
+ baseImageClassName?: string;
107
+ baseImageStyle?: React.CSSProperties;
108
+ isZoomed?: boolean;
109
+ fadeDuration?: number;
110
+ alt: string;
111
+ loadingPlaceholder?: React.ReactNode;
112
+ errorPlaceholder?: React.ReactNode;
113
+ onError?: (() => void) | undefined;
114
+ };
115
+ export type InertiaOptions = {
116
+ initialLeft: number;
117
+ initialTop: number;
118
+ velocity: {
119
+ vx: number;
120
+ vy: number;
121
+ };
122
+ setLeft: (left: number) => void;
123
+ setTop: (top: number) => void;
124
+ bounds: {
125
+ minLeft: number;
126
+ maxLeft: number;
127
+ minTop: number;
128
+ maxTop: number;
129
+ };
130
+ friction?: number;
131
+ minVelocity?: number;
132
+ onEnd?: () => void;
133
+ };
134
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const CloseIcon: ({ className }: {
2
+ className?: string;
3
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,3 @@
1
+ import { IBaseImageTypes } from '../ImageMagnifier.types';
2
+ declare const BaseImage: ({ src, sources, baseImageStyle, isZoomed, fadeDuration, baseImageClassName, alt, loadingPlaceholder, errorPlaceholder, onError, }: IBaseImageTypes) => import("react/jsx-runtime").JSX.Element;
3
+ export default BaseImage;
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ type FullscreenPortalProps = {
3
+ children: React.ReactElement;
4
+ };
5
+ declare const FullscreenPortal: ({ children }: FullscreenPortalProps) => React.ReactPortal;
6
+ export default FullscreenPortal;
@@ -0,0 +1,3 @@
1
+ import { ImageProps } from '../ImageMagnifier.types';
2
+ declare const Image: ({ src, sources, width, height, hasSpacer, imgAttributes, isZoomed, fadeDuration }: ImageProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default Image;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { IZoomImageTypes } from '../ImageMagnifier.types';
3
+ declare const ZoomImage: React.ForwardRefExoticComponent<IZoomImageTypes & React.RefAttributes<HTMLImageElement>>;
4
+ export default ZoomImage;