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 +21 -0
- package/README.md +141 -0
- package/dist/ImageMagnifier.d.ts +3 -0
- package/dist/ImageMagnifier.types.d.ts +134 -0
- package/dist/assets/CloseIcon.d.ts +3 -0
- package/dist/components/BaseImage.d.ts +3 -0
- package/dist/components/FullscreenPortal.d.ts +6 -0
- package/dist/components/Image.d.ts +3 -0
- package/dist/components/ZoomImage.d.ts +4 -0
- package/dist/index.cjs +460 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +458 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/animation.constants.d.ts +16 -0
- package/dist/utils/animations.d.ts +2 -0
- package/dist/utils/dragUtils.d.ts +3 -0
- package/dist/utils/followUtils.d.ts +3 -0
- package/dist/utils/globalUtils.d.ts +46 -0
- package/dist/utils/imageMagnifierUtils.d.ts +34 -0
- package/dist/utils/movementUtils.d.ts +4 -0
- package/dist/utils/panUtils.d.ts +3 -0
- package/package.json +68 -0
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
|
+
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;
|