point-focus 1.0.5 → 2.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/README.md +125 -0
- package/dist/index.cjs +259 -225
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +259 -225
- package/dist/index.js.map +1 -1
- package/package.json +9 -26
- 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,6 +14,17 @@
|
|
|
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
|
|
@@ -87,6 +98,120 @@ function Example() {
|
|
|
87
98
|
| `onDragStart` | `() => void` | — | Called on drag start |
|
|
88
99
|
| `onDragEnd` | `() => void` | — | Called on drag end |
|
|
89
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
|
+
- Keyboard users can zoom without hovering first: Tab to the image, then Enter or Space.
|
|
184
|
+
- Focus now moves to the close button when zoom opens (it was hidden at that moment, so browsers ignored it).
|
|
185
|
+
|
|
186
|
+
### Changed
|
|
187
|
+
|
|
188
|
+
- 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.
|
|
189
|
+
- 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.
|
|
190
|
+
- `react` and `react-dom` are peer dependencies only, and the package has no other dependencies.
|
|
191
|
+
- The stylesheet adds a visible keyboard focus outline and respects `prefers-reduced-motion`.
|
|
192
|
+
|
|
193
|
+
### Migrating from 1.x
|
|
194
|
+
|
|
195
|
+
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.
|
|
196
|
+
|
|
197
|
+
## Development
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
packages/core point-focus-core: engine, web component, stylesheet
|
|
201
|
+
packages/react point-focus: the React component, with the core engine bundled in
|
|
202
|
+
playground a page rendering both versions side by side
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
npm install
|
|
207
|
+
npm run dev # playground at http://localhost:5174
|
|
208
|
+
npm test # all tests (Jest, Testing Library, jest-axe)
|
|
209
|
+
npm run typecheck
|
|
210
|
+
npm run build # builds core, then React
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
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.
|
|
214
|
+
|
|
90
215
|
## 🧭 Roadmap
|
|
91
216
|
|
|
92
217
|
### ✅ Already Implemented
|