point-focus 1.0.4 → 2.0.0-beta.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/README.md +176 -57
- package/dist/index.cjs +244 -222
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +244 -222
- package/dist/index.js.map +1 -1
- package/package.json +11 -28
- package/dist/ImageMagnifier.d.ts +0 -3
- package/dist/ImageMagnifier.types.d.ts +0 -191
- package/dist/assets/CloseIcon.d.ts +0 -3
- package/dist/assets/svgCollection.d.ts +0 -6
- package/dist/components/BaseImage.d.ts +0 -3
- package/dist/components/FullscreenPortal.d.ts +0 -6
- package/dist/components/Image.d.ts +0 -3
- package/dist/components/ImageStatusPlaceholder.d.ts +0 -10
- package/dist/components/ZoomImage.d.ts +0 -4
- package/dist/utils/animation.constants.d.ts +0 -16
- package/dist/utils/animations.d.ts +0 -4
- package/dist/utils/dragUtils.d.ts +0 -3
- package/dist/utils/followUtils.d.ts +0 -3
- package/dist/utils/globalUtils.d.ts +0 -50
- package/dist/utils/imageMagnifierUtils.d.ts +0 -34
- package/dist/utils/movementUtils.d.ts +0 -4
- package/dist/utils/panUtils.d.ts +0 -3
package/README.md
CHANGED
|
@@ -14,13 +14,25 @@
|
|
|
14
14
|
- **Easy Styling:** Modern, modular CSS/SCSS for effortless customization.
|
|
15
15
|
- **Lightweight** – No external dependencies except React.
|
|
16
16
|
|
|
17
|
+
## Packages
|
|
18
|
+
|
|
19
|
+
Since 2.0 this repository is a monorepo with two packages built on one shared zoom engine. Install the one you need:
|
|
20
|
+
|
|
21
|
+
| Package | Use it when | Size (gzip) |
|
|
22
|
+
|----------------------|----------------------------------------------------------------------------|-----------------------------|
|
|
23
|
+
| `point-focus` | You build with React. Same API as 1.x. | 7.6 KB, engine included |
|
|
24
|
+
| `point-focus-core` | You need no framework: plain HTML, Shopify themes, Vue, Svelte, and so on. | 4.2 KB as a drop-in script |
|
|
25
|
+
|
|
26
|
+
Both are built from the same engine source, so drag, follow and inertia behave identically. Neither depends on the other.
|
|
27
|
+
|
|
17
28
|
## 🛠️ Technologies
|
|
18
29
|
|
|
19
30
|
- **React** – Declarative UI
|
|
20
31
|
- **TypeScript** – Safer development
|
|
21
32
|
- **SCSS Modules** – Scoped styling
|
|
22
33
|
|
|
23
|
-
**Requirements:**
|
|
34
|
+
**Requirements:**
|
|
35
|
+
|
|
24
36
|
- React 17+
|
|
25
37
|
- Node.js with npm or yarn
|
|
26
38
|
|
|
@@ -38,64 +50,170 @@ yarn add point-focus
|
|
|
38
50
|
import ImageMagnifier from 'point-focus'
|
|
39
51
|
|
|
40
52
|
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
|
-
)
|
|
53
|
+
return <ImageMagnifier src='/images/sample.jpg' zoomSrc='/images/sample-large.jpg' moveType='drag' zoomType='click' alt='Image alt' zoomScale={2} />
|
|
51
54
|
}
|
|
52
55
|
```
|
|
53
56
|
|
|
54
57
|
## 🔧 Props Overview
|
|
55
58
|
|
|
56
|
-
| Prop
|
|
57
|
-
|
|
58
|
-
| `src`
|
|
59
|
-
| `zoomSrc`
|
|
60
|
-
| `sources`
|
|
61
|
-
| `width` / `height`
|
|
62
|
-
| `zoomScale`
|
|
63
|
-
| `zoomPreload`
|
|
64
|
-
| `fadeDuration`
|
|
65
|
-
| `moveType`
|
|
66
|
-
| `zoomType`
|
|
67
|
-
| `clickToZoomOut`
|
|
68
|
-
| `hideCloseButton`
|
|
69
|
-
| `alt`
|
|
70
|
-
| `tabIndex`
|
|
71
|
-
| `containerClassName`
|
|
72
|
-
| `baseImageClassName`
|
|
73
|
-
| `zoomImageClassName`
|
|
74
|
-
| `closeButtonClassName`
|
|
75
|
-
| `containerAriaLabel`
|
|
76
|
-
| `zoomImageAriaLabel`
|
|
77
|
-
| `closeButtonAriaLabel`
|
|
78
|
-
| `closeButtonContent`
|
|
79
|
-
| `overlay`
|
|
80
|
-
| `loadingPlaceholder`
|
|
81
|
-
| `
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
87
|
-
| `
|
|
88
|
-
| `
|
|
89
|
-
| `
|
|
90
|
-
| `
|
|
91
|
-
| `
|
|
92
|
-
| `
|
|
93
|
-
| `
|
|
94
|
-
| `
|
|
59
|
+
| Prop | Type | Default | Description |
|
|
60
|
+
| ---------------------- | ------------------------ | ------------ | -------------------------------------- |
|
|
61
|
+
| `src` | `string` | — (required) | Main image source |
|
|
62
|
+
| `zoomSrc` | `string` | `src` | High-res zoom source |
|
|
63
|
+
| `sources` | `array` | — | `<source>` tags for `<picture>` |
|
|
64
|
+
| `width` / `height` | `number` | — | Container dimensions |
|
|
65
|
+
| `zoomScale` | `number` | `1` | Magnification ratio |
|
|
66
|
+
| `zoomPreload` | `boolean` | `false` | Preload zoom image on mount |
|
|
67
|
+
| `fadeDuration` | `number` | `150` | Animation duration in ms |
|
|
68
|
+
| `moveType` | `follow`, `drag`, `pinch`| `follow` | Pan behavior during zoom |
|
|
69
|
+
| `zoomType` | `click`, `hover` | `click` | How zoom is activated |
|
|
70
|
+
| `clickToZoomOut` | `boolean` | `false` | Allow clicking image to zoom out |
|
|
71
|
+
| `hideCloseButton` | `boolean` | `false` | Hide zoom-close button |
|
|
72
|
+
| `alt` | `string` | `''` | Alt text for both images |
|
|
73
|
+
| `tabIndex` | `number` | `0` | Keyboard navigation index |
|
|
74
|
+
| `containerClassName` | `string` | — | Extra class for the wrapper |
|
|
75
|
+
| `baseImageClassName` | `string` | — | Extra class for the base image |
|
|
76
|
+
| `zoomImageClassName` | `string` | — | Extra class for zoom image |
|
|
77
|
+
| `closeButtonClassName` | `string` | — | Custom class for close button |
|
|
78
|
+
| `containerAriaLabel` | `string` | — | Accessibility label for container |
|
|
79
|
+
| `zoomImageAriaLabel` | `string` | — | ARIA label for zoom image |
|
|
80
|
+
| `closeButtonAriaLabel` | `string` | — | ARIA label for close button |
|
|
81
|
+
| `closeButtonContent` | `ReactNode` | `X` icon | Replace the default close icon |
|
|
82
|
+
| `overlay` | `ReactNode` | — | Optional overlay inside zoom container |
|
|
83
|
+
| `loadingPlaceholder` | `ReactNode` | — | Shown while zoom image loads |
|
|
84
|
+
| `disableLoadingFallbacks` | `boolean` | `false` | Prevents/Disables loading fallbacks |
|
|
85
|
+
| `errorPlaceholder` | `ReactNode` | — | Shown if zoom image fails |
|
|
86
|
+
| `disableErrorFallbacks` | `boolean` | `false` | Prevents/Disables error fallbacks |
|
|
87
|
+
| `externalZoomState` | `boolean` | — | For controlled zoom state |
|
|
88
|
+
| `setExternalZoomState` | `(val: boolean) => void` | — | Setter for external zoom state |
|
|
89
|
+
| `onMouseEnter` | `() => void` | — | Called on hover enter |
|
|
90
|
+
| `onMouseLeave` | `() => void` | — | Called on hover leave |
|
|
91
|
+
| `onClickImage` | `() => void` | — | Called when image is clicked |
|
|
92
|
+
| `onZoom` | `() => void` | — | Called when zoom starts |
|
|
93
|
+
| `onClose` | `() => void` | — | Called when zoom closes |
|
|
94
|
+
| `afterZoomImgLoaded` | `() => void` | — | Called when zoom image loads |
|
|
95
|
+
| `afterZoomOut` | `() => void` | — | Called after zoom exits |
|
|
96
|
+
| `onBaseImageError` | `() => void` | — | Called if base image fails to load |
|
|
97
|
+
| `onZoomImageError` | `() => void` | — | Called if zoom image fails to load |
|
|
98
|
+
| `onDragStart` | `() => void` | — | Called on drag start |
|
|
99
|
+
| `onDragEnd` | `() => void` | — | Called on drag end |
|
|
100
|
+
|
|
101
|
+
## Without React: `point-focus-core`
|
|
102
|
+
|
|
103
|
+
The core package ships a `<point-focus-image>` web component. It renders plain HTML (no shadow DOM), so the BEM classes below can be styled from any stylesheet.
|
|
104
|
+
|
|
105
|
+
### Install
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npm install point-focus-core
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import { definePointFocus } from 'point-focus-core'
|
|
113
|
+
import 'point-focus-core/point-focus.css'
|
|
114
|
+
|
|
115
|
+
definePointFocus()
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Or, with no build step, load the self-registering script and the stylesheet:
|
|
119
|
+
|
|
120
|
+
```html
|
|
121
|
+
<link rel="stylesheet" href="https://unpkg.com/point-focus-core/dist/point-focus.css" />
|
|
122
|
+
<script src="https://unpkg.com/point-focus-core/dist/point-focus.min.js" defer></script>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Usage
|
|
126
|
+
|
|
127
|
+
```html
|
|
128
|
+
<point-focus-image src="/images/sample.jpg" zoom-src="/images/sample-large.jpg" alt="Image alt" move-type="drag" zoom-scale="2"></point-focus-image>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Attributes
|
|
132
|
+
|
|
133
|
+
| Attribute | Values | Default | Description |
|
|
134
|
+
|----------------------|--------------------|------------------|----------------------------------------------|
|
|
135
|
+
| `src` | URL | required | Main image source |
|
|
136
|
+
| `zoom-src` | URL | `src` | High-res zoom source |
|
|
137
|
+
| `alt` | text | empty | Alt text; the zoom image gets "`alt` zoomed" |
|
|
138
|
+
| `zoom-scale` | 1 to 5 | `1` | Magnification ratio |
|
|
139
|
+
| `move-type` | `follow`, `drag` | `follow` | Pan behavior during zoom |
|
|
140
|
+
| `zoom-type` | `click`, `hover` | `click` | How zoom is activated |
|
|
141
|
+
| `fade-duration` | milliseconds | `150` | Fade in and out duration |
|
|
142
|
+
| `container-label` | text | `Zoomable image` | Accessible name of the container |
|
|
143
|
+
| `close-label` | text | `Zoom out` | Accessible name of the close button |
|
|
144
|
+
| `zoom-preload` | flag | off | Load the zoom image on mount |
|
|
145
|
+
| `click-to-zoom-out` | flag | off | Clicking the zoomed image closes it |
|
|
146
|
+
| `hide-close-button` | flag | off | Hide the close button |
|
|
147
|
+
| `disable-drag` | flag | off | Turn off dragging |
|
|
148
|
+
| `disable-inertia` | flag | off | Stop immediately on release, no glide |
|
|
149
|
+
|
|
150
|
+
### Events and methods
|
|
151
|
+
|
|
152
|
+
| Event | `event.detail` |
|
|
153
|
+
|-----------------|-------------------------------------------------|
|
|
154
|
+
| `pf-zoom` | `{ at: { x, y }, method }` |
|
|
155
|
+
| `pf-close` | `{ triggeredBy }` |
|
|
156
|
+
| `pf-drag-start` | `{ start: { x, y }, source }` |
|
|
157
|
+
| `pf-drag-end` | `{ velocity: { vx, vy }, final: { x, y } }` |
|
|
158
|
+
|
|
159
|
+
Methods: `element.zoomIn(pageX?, pageY?)`, `element.zoomOut()`, and the read-only `element.isZoomed`.
|
|
160
|
+
|
|
161
|
+
### Custom error content
|
|
162
|
+
|
|
163
|
+
Put a `<template data-error>` inside the element. Its content replaces the default fallback image when the zoom image fails to load.
|
|
164
|
+
|
|
165
|
+
```html
|
|
166
|
+
<point-focus-image src="/a.jpg" alt="A boat">
|
|
167
|
+
<template data-error><p>Zoom unavailable</p></template>
|
|
168
|
+
</point-focus-image>
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Using the engine directly
|
|
172
|
+
|
|
173
|
+
`ZoomEngine` holds all the zoom math (follow, drag, inertia, clamping) with no DOM of its own. Use it to build an adapter for another framework: it reports every position through one `onPosition({ left, top })` callback.
|
|
174
|
+
|
|
175
|
+
## What's new in 2.0
|
|
176
|
+
|
|
177
|
+
### Fixed
|
|
178
|
+
|
|
179
|
+
- Releasing a drag without momentum no longer snaps the image back to where the drag started.
|
|
180
|
+
- With `clickToZoomOut`, finishing a drag no longer closes the zoom.
|
|
181
|
+
- Releasing over the image no longer starts two overlapping glide animations.
|
|
182
|
+
- Zooming with the keyboard centers correctly on a scrolled page.
|
|
183
|
+
|
|
184
|
+
### Changed
|
|
185
|
+
|
|
186
|
+
- Drag, follow and inertia run in the shared `point-focus-core` engine. The image position is written straight to the element, so the component no longer re-renders on every animation frame.
|
|
187
|
+
- Class names are now plain BEM (`c-point-focus`, `c-point-focus__zoom-img`, and so on) instead of hashed CSS-module names, so they can be styled directly.
|
|
188
|
+
- `react` and `react-dom` are peer dependencies only, and the package has no other dependencies.
|
|
189
|
+
- The stylesheet adds a visible keyboard focus outline and respects `prefers-reduced-motion`.
|
|
190
|
+
|
|
191
|
+
### Migrating from 1.x
|
|
192
|
+
|
|
193
|
+
Upgrade with `npm install point-focus@2`. Props, callbacks and markup are unchanged. Only CSS that targeted the old hashed class names needs updating to the new BEM names.
|
|
194
|
+
|
|
195
|
+
## Development
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
packages/core point-focus-core: engine, web component, stylesheet
|
|
199
|
+
packages/react point-focus: the React component, with the core engine bundled in
|
|
200
|
+
playground a page rendering both versions side by side
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
npm install
|
|
205
|
+
npm run dev # playground at http://localhost:5174
|
|
206
|
+
npm test # all tests (Jest, Testing Library, jest-axe)
|
|
207
|
+
npm run typecheck
|
|
208
|
+
npm run build # builds core, then React
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
The playground runs from source, so edits reload live. A pre-commit hook runs the typecheck and tests, and GitHub Actions runs the typecheck, tests and build on every pull request.
|
|
95
212
|
|
|
96
213
|
## 🧭 Roadmap
|
|
97
214
|
|
|
98
215
|
### ✅ Already Implemented
|
|
216
|
+
|
|
99
217
|
- SSR support (Next.js, Gatsby)
|
|
100
218
|
- Click or hover zoom trigger
|
|
101
219
|
- Follow mouse or drag pan
|
|
@@ -111,13 +229,14 @@ function Example() {
|
|
|
111
229
|
- Programmatic zoom positioning setup via `onLoadCallback`
|
|
112
230
|
|
|
113
231
|
### 🚧 Planned Features
|
|
114
|
-
|
|
115
|
-
- [ ] **
|
|
116
|
-
- [ ] **Zoom
|
|
117
|
-
- [ ] **
|
|
118
|
-
- [ ] **
|
|
119
|
-
- [ ] **
|
|
120
|
-
- [ ] **
|
|
232
|
+
|
|
233
|
+
- [ ] **Pinch-to-zoom** for touch devices
|
|
234
|
+
- [ ] **Zoom lens / magnifier glass** effect
|
|
235
|
+
- [ ] **Zoom on scroll / mouse wheel**
|
|
236
|
+
- [ ] **Double-click or double-tap to zoom**
|
|
237
|
+
- [ ] **Animated transitions with easing customization**
|
|
238
|
+
- [ ] **Programmatic zoom in/out methods**
|
|
239
|
+
- [ ] **Granular keyboard navigation**
|
|
121
240
|
- [ ] **Fallback UI for broken zoom images**
|
|
122
241
|
- [ ] **Built-in modal/lightbox integration**
|
|
123
242
|
|