@h4md1/visual-image-tool 0.1.5 → 0.2.1
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 +156 -119
- package/dist/visual-image-tool.esm.js +921 -793
- package/dist/visual-image-tool.esm.js.map +1 -1
- package/dist/visual-image-tool.js +921 -793
- package/dist/visual-image-tool.js.map +1 -1
- package/dist/visual-image-tool.umd.js +1 -1
- package/dist/visual-image-tool.umd.js.map +1 -1
- package/package.json +48 -40
- package/src/index.js +1 -1
- package/src/visual-image-tool.js +924 -797
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# <img src="demo/android-chrome-192x192.png" alt="Visual Image Tool logo" width="48" height="48" style="vertical-align:middle; margin-right: 0.5em; border-radius: 8px;"> Visual Image Tool
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A lightweight vanilla JavaScript tool to define focus points and crop zones on images.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
- **
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
10
|
-
- **API
|
|
11
|
-
- **
|
|
12
|
-
- **Responsive
|
|
7
|
+
- **Focus point**: Set a point of interest on the image with a visual marker
|
|
8
|
+
- **Crop zone**: Define a crop zone with resize handles
|
|
9
|
+
- **No dependencies**: Works without external libraries
|
|
10
|
+
- **Simple API**: Clear and easy-to-use interface
|
|
11
|
+
- **Customizable**: Flexible configuration options
|
|
12
|
+
- **Responsive**: Adapts to screen resizing
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
@@ -17,179 +17,198 @@ Un outil léger en JavaScript vanilla pour définir des points focaux et zones d
|
|
|
17
17
|
npm install @h4md1/visual-image-tool
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## Quick Start Guide
|
|
21
21
|
|
|
22
|
-
### 1.
|
|
22
|
+
### 1. Import
|
|
23
23
|
|
|
24
24
|
```javascript
|
|
25
|
-
//
|
|
26
|
-
import VisualImageTool from
|
|
25
|
+
// ES modules import (recommended)
|
|
26
|
+
import VisualImageTool from "@h4md1/visual-image-tool";
|
|
27
27
|
|
|
28
|
-
//
|
|
29
|
-
const VisualImageTool = require(
|
|
28
|
+
// OR CommonJS import
|
|
29
|
+
const VisualImageTool = require("@h4md1/visual-image-tool");
|
|
30
30
|
|
|
31
|
-
//
|
|
31
|
+
// OR direct usage via script tag (UMD)
|
|
32
32
|
// <script src="node_modules/image-tool/dist/image-tool.umd.js"></script>
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
### 2.
|
|
35
|
+
### 2. Initialization
|
|
36
36
|
|
|
37
37
|
```javascript
|
|
38
|
-
//
|
|
38
|
+
// Create an instance with an image
|
|
39
39
|
const imageTool = new VisualImageTool.VisualImageTool({
|
|
40
|
-
imageElement: document.getElementById(
|
|
40
|
+
imageElement: document.getElementById("myImage"),
|
|
41
|
+
debug: true, // Enable debug logs for overlay positioning (optional)
|
|
41
42
|
onChange: (data) => {
|
|
42
|
-
console.log(
|
|
43
|
-
console.log(
|
|
44
|
-
}
|
|
43
|
+
console.log("Focus point:", data.focusPoint);
|
|
44
|
+
console.log("Crop zone:", data.cropZone);
|
|
45
|
+
},
|
|
45
46
|
});
|
|
46
47
|
```
|
|
47
48
|
|
|
48
|
-
### 3.
|
|
49
|
+
### 3. Using the Features
|
|
49
50
|
|
|
50
51
|
```javascript
|
|
51
|
-
//
|
|
52
|
+
// Enable the focus point
|
|
52
53
|
imageTool.toggleFocusPoint(true);
|
|
53
54
|
|
|
54
|
-
//
|
|
55
|
+
// Enable the crop zone
|
|
55
56
|
imageTool.toggleCropZone(true);
|
|
56
57
|
|
|
57
|
-
//
|
|
58
|
+
// Manually set a focus point
|
|
58
59
|
imageTool.setFocusPoint(x, y);
|
|
59
60
|
|
|
60
|
-
//
|
|
61
|
+
// Manually set a crop zone
|
|
61
62
|
imageTool.setCropZone(x, y, width, height);
|
|
62
63
|
|
|
63
|
-
//
|
|
64
|
+
// Get current values
|
|
64
65
|
const focusPoint = imageTool.getFocusPoint();
|
|
65
66
|
const cropZone = imageTool.getCropZone();
|
|
66
67
|
```
|
|
67
68
|
|
|
68
|
-
## Options
|
|
69
|
+
## Configuration Options
|
|
69
70
|
|
|
70
71
|
```javascript
|
|
71
72
|
const imageTool = new VisualImageTool.VisualImageTool({
|
|
72
|
-
//
|
|
73
|
-
imageElement:
|
|
74
|
-
|
|
75
|
-
//
|
|
73
|
+
// Image element (required) - can be a CSS selector or a DOM element
|
|
74
|
+
imageElement: "#myImage",
|
|
75
|
+
|
|
76
|
+
// Enable debug logs for overlay positioning (optional)
|
|
77
|
+
debug: true, // Set to true to see overlay positioning logs in the console
|
|
78
|
+
|
|
79
|
+
// Focus point configuration (optional)
|
|
76
80
|
focusPoint: {
|
|
77
|
-
enabled: true, //
|
|
81
|
+
enabled: true, // Enable/disable the feature
|
|
78
82
|
style: {
|
|
79
|
-
width:
|
|
80
|
-
height:
|
|
81
|
-
border:
|
|
82
|
-
boxShadow:
|
|
83
|
-
backgroundColor:
|
|
84
|
-
}
|
|
83
|
+
width: "30px",
|
|
84
|
+
height: "30px",
|
|
85
|
+
border: "3px solid white",
|
|
86
|
+
boxShadow: "0 0 0 2px black, 0 0 5px rgba(0,0,0,0.5)",
|
|
87
|
+
backgroundColor: "rgba(255, 0, 0, 0.5)",
|
|
88
|
+
},
|
|
85
89
|
},
|
|
86
|
-
|
|
87
|
-
//
|
|
90
|
+
|
|
91
|
+
// Crop zone configuration (optional)
|
|
88
92
|
cropZone: {
|
|
89
|
-
enabled: true, //
|
|
93
|
+
enabled: true, // Enable/disable the feature
|
|
90
94
|
style: {
|
|
91
|
-
border:
|
|
92
|
-
backgroundColor:
|
|
95
|
+
border: "1px dashed #fff",
|
|
96
|
+
backgroundColor: "rgba(0, 0, 0, 0.4)",
|
|
93
97
|
},
|
|
94
98
|
handleStyle: {
|
|
95
|
-
width:
|
|
96
|
-
height:
|
|
97
|
-
backgroundColor:
|
|
98
|
-
border:
|
|
99
|
-
boxShadow:
|
|
100
|
-
}
|
|
99
|
+
width: "14px",
|
|
100
|
+
height: "14px",
|
|
101
|
+
backgroundColor: "white",
|
|
102
|
+
border: "2px solid black",
|
|
103
|
+
boxShadow: "0 0 3px rgba(0,0,0,0.5)",
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
// Callback called on changes (optional)
|
|
108
|
+
onChange: function (data) {
|
|
109
|
+
// data contains focusPoint, cropZone, focusActive, cropActive
|
|
101
110
|
},
|
|
102
|
-
|
|
103
|
-
// Callback appelé lors des changements (optionnel)
|
|
104
|
-
onChange: function(data) {
|
|
105
|
-
// data contient focusPoint, cropZone, focusActive, cropActive
|
|
106
|
-
}
|
|
107
111
|
});
|
|
108
112
|
```
|
|
109
113
|
|
|
110
|
-
## API
|
|
114
|
+
## Full API
|
|
111
115
|
|
|
112
|
-
###
|
|
116
|
+
### Methods
|
|
113
117
|
|
|
114
118
|
#### `toggleFocusPoint(active)`
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
119
|
+
|
|
120
|
+
Enables or disables the focus point.
|
|
121
|
+
|
|
122
|
+
- `active` (boolean, optional): If set, forces the state to this value. If omitted, toggles the current state.
|
|
123
|
+
- Returns: The VisualImageTool instance for chaining.
|
|
118
124
|
|
|
119
125
|
#### `toggleCropZone(active)`
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
126
|
+
|
|
127
|
+
Enables or disables the crop zone.
|
|
128
|
+
|
|
129
|
+
- `active` (boolean, optional): If set, forces the state to this value. If omitted, toggles the current state.
|
|
130
|
+
- Returns: The VisualImageTool instance for chaining.
|
|
123
131
|
|
|
124
132
|
#### `setFocusPoint(x, y)`
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
-
|
|
133
|
+
|
|
134
|
+
Sets the position of the focus point.
|
|
135
|
+
|
|
136
|
+
- `x` (number): X coordinate in original pixels.
|
|
137
|
+
- `y` (number): Y coordinate in original pixels.
|
|
138
|
+
- Returns: The VisualImageTool instance for chaining.
|
|
129
139
|
|
|
130
140
|
#### `setCropZone(x, y, width, height)`
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
- `
|
|
135
|
-
- `
|
|
136
|
-
-
|
|
141
|
+
|
|
142
|
+
Sets the position and dimensions of the crop zone.
|
|
143
|
+
|
|
144
|
+
- `x` (number): X coordinate in original pixels.
|
|
145
|
+
- `y` (number): Y coordinate in original pixels.
|
|
146
|
+
- `width` (number): Width in original pixels.
|
|
147
|
+
- `height` (number): Height in original pixels.
|
|
148
|
+
- Returns: The VisualImageTool instance for chaining.
|
|
137
149
|
|
|
138
150
|
#### `getFocusPoint()`
|
|
139
|
-
|
|
140
|
-
|
|
151
|
+
|
|
152
|
+
Gets the current position of the focus point.
|
|
153
|
+
|
|
154
|
+
- Returns: An object `{x, y}` with coordinates in original pixels.
|
|
141
155
|
|
|
142
156
|
#### `getCropZone()`
|
|
143
|
-
|
|
144
|
-
|
|
157
|
+
|
|
158
|
+
Gets the current position and dimensions of the crop zone.
|
|
159
|
+
|
|
160
|
+
- Returns: An object `{x, y, width, height}` with values in original pixels.
|
|
145
161
|
|
|
146
162
|
#### `getImageDimensions()`
|
|
147
|
-
|
|
148
|
-
|
|
163
|
+
|
|
164
|
+
Gets the original dimensions of the image.
|
|
165
|
+
|
|
166
|
+
- Returns: An object `{width, height}` with dimensions in original pixels.
|
|
149
167
|
|
|
150
168
|
#### `destroy()`
|
|
151
|
-
Détruit l'instance et nettoie les ressources.
|
|
152
169
|
|
|
153
|
-
|
|
170
|
+
Destroys the instance and cleans up resources.
|
|
171
|
+
|
|
172
|
+
### Events
|
|
154
173
|
|
|
155
|
-
|
|
174
|
+
The tool uses the `onChange` callback to notify about changes. This callback receives an object with the following properties:
|
|
156
175
|
|
|
157
176
|
```javascript
|
|
158
177
|
{
|
|
159
|
-
focusPoint: {x, y},
|
|
160
|
-
cropZone: {x, y, width, height},
|
|
161
|
-
focusActive: true|false,
|
|
162
|
-
cropActive: true|false
|
|
178
|
+
focusPoint: {x, y}, // Position of the focus point
|
|
179
|
+
cropZone: {x, y, width, height}, // Position and dimensions of the crop zone
|
|
180
|
+
focusActive: true|false, // Activation state of the focus point
|
|
181
|
+
cropActive: true|false // Activation state of the crop zone
|
|
163
182
|
}
|
|
164
183
|
```
|
|
165
184
|
|
|
166
|
-
##
|
|
185
|
+
## Integration Examples with Frameworks
|
|
167
186
|
|
|
168
187
|
### React
|
|
169
188
|
|
|
170
189
|
```jsx
|
|
171
|
-
import React, { useEffect, useRef } from
|
|
172
|
-
import VisualImageTool from
|
|
190
|
+
import React, { useEffect, useRef } from "react";
|
|
191
|
+
import VisualImageTool from "@h4md1/visual-image-tool";
|
|
173
192
|
|
|
174
193
|
function ImageEditor() {
|
|
175
194
|
const imageRef = useRef(null);
|
|
176
195
|
const toolRef = useRef(null);
|
|
177
|
-
|
|
196
|
+
|
|
178
197
|
useEffect(() => {
|
|
179
198
|
if (imageRef.current && !toolRef.current) {
|
|
180
199
|
toolRef.current = new VisualImageTool({
|
|
181
200
|
imageElement: imageRef.current,
|
|
182
201
|
onChange: (data) => {
|
|
183
|
-
console.log(
|
|
184
|
-
}
|
|
202
|
+
console.log("Updated data:", data);
|
|
203
|
+
},
|
|
185
204
|
});
|
|
186
|
-
|
|
187
|
-
//
|
|
205
|
+
|
|
206
|
+
// Enable features
|
|
188
207
|
toolRef.current.toggleFocusPoint(true);
|
|
189
208
|
toolRef.current.toggleCropZone(true);
|
|
190
209
|
}
|
|
191
|
-
|
|
192
|
-
//
|
|
210
|
+
|
|
211
|
+
// Cleanup
|
|
193
212
|
return () => {
|
|
194
213
|
if (toolRef.current) {
|
|
195
214
|
toolRef.current.destroy();
|
|
@@ -197,10 +216,10 @@ function ImageEditor() {
|
|
|
197
216
|
}
|
|
198
217
|
};
|
|
199
218
|
}, []);
|
|
200
|
-
|
|
219
|
+
|
|
201
220
|
return (
|
|
202
221
|
<div>
|
|
203
|
-
<img ref={imageRef} src="path/to/image.jpg" alt="
|
|
222
|
+
<img ref={imageRef} src="path/to/image.jpg" alt="Editable" />
|
|
204
223
|
</div>
|
|
205
224
|
);
|
|
206
225
|
}
|
|
@@ -211,28 +230,28 @@ function ImageEditor() {
|
|
|
211
230
|
```vue
|
|
212
231
|
<template>
|
|
213
232
|
<div>
|
|
214
|
-
<img ref="editableImage" src="path/to/image.jpg" alt="
|
|
233
|
+
<img ref="editableImage" src="path/to/image.jpg" alt="Editable" />
|
|
215
234
|
</div>
|
|
216
235
|
</template>
|
|
217
236
|
|
|
218
237
|
<script>
|
|
219
|
-
import VisualImageTool from
|
|
238
|
+
import VisualImageTool from "@h4md1/visual-image-tool";
|
|
220
239
|
|
|
221
240
|
export default {
|
|
222
241
|
data() {
|
|
223
242
|
return {
|
|
224
|
-
imageTool: null
|
|
243
|
+
imageTool: null,
|
|
225
244
|
};
|
|
226
245
|
},
|
|
227
246
|
mounted() {
|
|
228
247
|
this.imageTool = new VisualImageTool({
|
|
229
248
|
imageElement: this.$refs.editableImage,
|
|
230
249
|
onChange: (data) => {
|
|
231
|
-
console.log(
|
|
232
|
-
}
|
|
250
|
+
console.log("Updated data:", data);
|
|
251
|
+
},
|
|
233
252
|
});
|
|
234
|
-
|
|
235
|
-
//
|
|
253
|
+
|
|
254
|
+
// Enable features
|
|
236
255
|
this.imageTool.toggleFocusPoint(true);
|
|
237
256
|
this.imageTool.toggleCropZone(true);
|
|
238
257
|
},
|
|
@@ -241,27 +260,45 @@ export default {
|
|
|
241
260
|
this.imageTool.destroy();
|
|
242
261
|
this.imageTool = null;
|
|
243
262
|
}
|
|
244
|
-
}
|
|
263
|
+
},
|
|
245
264
|
};
|
|
246
265
|
</script>
|
|
247
266
|
```
|
|
248
267
|
|
|
249
|
-
##
|
|
268
|
+
## Demos
|
|
269
|
+
|
|
270
|
+
The `demo/` folder contains the following examples:
|
|
271
|
+
|
|
272
|
+
- `basic-usage.html`: Basic usage example
|
|
273
|
+
- `custom-config.html`: Custom configuration demo with live controls
|
|
274
|
+
- `demo-esm.html`: ESM (ECMAScript Module) integration demo
|
|
275
|
+
- `demo-umd.html`: UMD (Universal Module Definition) integration demo
|
|
276
|
+
- `index2.html`: Alternate or experimental demo page
|
|
277
|
+
- `preact-importmap-demo.html`: Preact integration using importmap
|
|
278
|
+
- `react-integration.jsx`: React integration example
|
|
279
|
+
- `vue-importmap-demo.html`: Vue integration using importmap
|
|
280
|
+
- `vue-integration.js`: Vue integration script
|
|
281
|
+
|
|
282
|
+
## Browser Compatibility
|
|
283
|
+
|
|
284
|
+
- Chrome (latest versions)
|
|
285
|
+
- Firefox (latest versions)
|
|
286
|
+
- Safari (latest versions)
|
|
287
|
+
- Edge (latest versions)
|
|
250
288
|
|
|
251
|
-
|
|
289
|
+
## Code Formatting
|
|
252
290
|
|
|
253
|
-
|
|
254
|
-
- `custom-config.html` : Exemple avec configuration personnalisée
|
|
255
|
-
- `react-integration.jsx` : Exemple d'intégration avec React
|
|
256
|
-
- `vue-integration.js` : Exemple d'intégration avec Vue.js
|
|
291
|
+
This project uses a combination of tools for code formatting and linting to ensure consistency:
|
|
257
292
|
|
|
258
|
-
|
|
293
|
+
- **[Biome](https://biomejs.dev/)**: Handles formatting and linting for JavaScript (`.js`, `.jsx`), TypeScript (`.ts`, `.tsx`), and JSON (`.json`) files.
|
|
294
|
+
- Check: `npm run lint:check` (`biome check .`)
|
|
295
|
+
- Fix: `npm run lint:fix` (`biome check --write .`)
|
|
296
|
+
- **[Prettier](https://prettier.io/)**: Handles formatting for other file types like HTML, CSS, Markdown, etc.
|
|
297
|
+
- Check: `npm run format:check` (`prettier --check --ignore-unknown .`)
|
|
298
|
+
- Fix: `npm run format:write` (`prettier --write --ignore-unknown .`)
|
|
259
299
|
|
|
260
|
-
|
|
261
|
-
- Firefox (dernières versions)
|
|
262
|
-
- Safari (dernières versions)
|
|
263
|
-
- Edge (dernières versions)
|
|
300
|
+
These formatting checks are automatically enforced in the CI pipeline (see `.github/workflows/code-quality.yml`) to maintain code quality.
|
|
264
301
|
|
|
265
|
-
##
|
|
302
|
+
## License
|
|
266
303
|
|
|
267
304
|
MIT
|