point-focus 1.0.5 → 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 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,118 @@ 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
+
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.
212
+
90
213
  ## 🧭 Roadmap
91
214
 
92
215
  ### ✅ Already Implemented