@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 CHANGED
@@ -1,15 +1,15 @@
1
- # VisualImageTool
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
- Un outil léger en JavaScript vanilla pour définir des points focaux et zones de recadrage sur des images.
3
+ A lightweight vanilla JavaScript tool to define focus points and crop zones on images.
4
4
 
5
- ## Fonctionnalités
5
+ ## Features
6
6
 
7
- - **Point focal** : Définissez un point d'intérêt sur l'image avec un marqueur visuel
8
- - **Zone de recadrage** : Définissez une zone de recadrage avec poignées de redimensionnement
9
- - **Sans dépendances** : Fonctionne sans bibliothèques externes
10
- - **API simple** : Interface claire et facile à utiliser
11
- - **Personnalisable** : Options de configuration flexibles
12
- - **Responsive** : S'adapte aux redimensionnements d'écran
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
- ## Guide de démarrage rapide
20
+ ## Quick Start Guide
21
21
 
22
- ### 1. Importation
22
+ ### 1. Import
23
23
 
24
24
  ```javascript
25
- // Importation ES modules (recommandé)
26
- import VisualImageTool from '@h4md1/visual-image-tool';
25
+ // ES modules import (recommended)
26
+ import VisualImageTool from "@h4md1/visual-image-tool";
27
27
 
28
- // OU importation CommonJS
29
- const VisualImageTool = require('@h4md1/visual-image-tool');
28
+ // OR CommonJS import
29
+ const VisualImageTool = require("@h4md1/visual-image-tool");
30
30
 
31
- // OU utilisation directe via balise script (UMD)
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. Initialisation
35
+ ### 2. Initialization
36
36
 
37
37
  ```javascript
38
- // Créer une instance avec une image
38
+ // Create an instance with an image
39
39
  const imageTool = new VisualImageTool.VisualImageTool({
40
- imageElement: document.getElementById('myImage'),
40
+ imageElement: document.getElementById("myImage"),
41
+ debug: true, // Enable debug logs for overlay positioning (optional)
41
42
  onChange: (data) => {
42
- console.log('Point focal:', data.focusPoint);
43
- console.log('Zone de recadrage:', data.cropZone);
44
- }
43
+ console.log("Focus point:", data.focusPoint);
44
+ console.log("Crop zone:", data.cropZone);
45
+ },
45
46
  });
46
47
  ```
47
48
 
48
- ### 3. Utilisation des fonctionnalités
49
+ ### 3. Using the Features
49
50
 
50
51
  ```javascript
51
- // Activer le point focal
52
+ // Enable the focus point
52
53
  imageTool.toggleFocusPoint(true);
53
54
 
54
- // Activer la zone de recadrage
55
+ // Enable the crop zone
55
56
  imageTool.toggleCropZone(true);
56
57
 
57
- // Définir manuellement un point focal
58
+ // Manually set a focus point
58
59
  imageTool.setFocusPoint(x, y);
59
60
 
60
- // Définir manuellement une zone de recadrage
61
+ // Manually set a crop zone
61
62
  imageTool.setCropZone(x, y, width, height);
62
63
 
63
- // Obtenir les valeurs actuelles
64
+ // Get current values
64
65
  const focusPoint = imageTool.getFocusPoint();
65
66
  const cropZone = imageTool.getCropZone();
66
67
  ```
67
68
 
68
- ## Options de configuration
69
+ ## Configuration Options
69
70
 
70
71
  ```javascript
71
72
  const imageTool = new VisualImageTool.VisualImageTool({
72
- // Élément image (obligatoire) - peut être un sélecteur CSS ou un élément DOM
73
- imageElement: '#myImage',
74
-
75
- // Configuration du point focal (optionnel)
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, // Activer/désactiver la fonctionnalité
81
+ enabled: true, // Enable/disable the feature
78
82
  style: {
79
- width: '30px',
80
- height: '30px',
81
- border: '3px solid white',
82
- boxShadow: '0 0 0 2px black, 0 0 5px rgba(0,0,0,0.5)',
83
- backgroundColor: 'rgba(255, 0, 0, 0.5)'
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
- // Configuration de la zone de recadrage (optionnel)
90
+
91
+ // Crop zone configuration (optional)
88
92
  cropZone: {
89
- enabled: true, // Activer/désactiver la fonctionnalité
93
+ enabled: true, // Enable/disable the feature
90
94
  style: {
91
- border: '1px dashed #fff',
92
- backgroundColor: 'rgba(0, 0, 0, 0.4)'
95
+ border: "1px dashed #fff",
96
+ backgroundColor: "rgba(0, 0, 0, 0.4)",
93
97
  },
94
98
  handleStyle: {
95
- width: '14px',
96
- height: '14px',
97
- backgroundColor: 'white',
98
- border: '2px solid black',
99
- boxShadow: '0 0 3px rgba(0,0,0,0.5)'
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 complète
114
+ ## Full API
111
115
 
112
- ### Méthodes
116
+ ### Methods
113
117
 
114
118
  #### `toggleFocusPoint(active)`
115
- Active ou désactive le point focal.
116
- - `active` (boolean, optionnel): Si défini, force l'état à cette valeur. Si omis, inverse l'état actuel.
117
- - Retourne: L'instance VisualImageTool pour le chaînage.
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
- Active ou désactive la zone de recadrage.
121
- - `active` (boolean, optionnel): Si défini, force l'état à cette valeur. Si omis, inverse l'état actuel.
122
- - Retourne: L'instance VisualImageTool pour le chaînage.
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
- Définit la position du point focal.
126
- - `x` (number): Coordonnée X en pixels originaux.
127
- - `y` (number): Coordonnée Y en pixels originaux.
128
- - Retourne: L'instance VisualImageTool pour le chaînage.
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
- Définit la position et les dimensions de la zone de recadrage.
132
- - `x` (number): Coordonnée X en pixels originaux.
133
- - `y` (number): Coordonnée Y en pixels originaux.
134
- - `width` (number): Largeur en pixels originaux.
135
- - `height` (number): Hauteur en pixels originaux.
136
- - Retourne: L'instance VisualImageTool pour le chaînage.
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
- Obtient la position actuelle du point focal.
140
- - Retourne: Un objet `{x, y}` avec les coordonnées en pixels originaux.
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
- Obtient la position et les dimensions actuelles de la zone de recadrage.
144
- - Retourne: Un objet `{x, y, width, height}` avec les valeurs en pixels originaux.
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
- Obtient les dimensions originales de l'image.
148
- - Retourne: Un objet `{width, height}` avec les dimensions en pixels originaux.
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
- ### Événements
170
+ Destroys the instance and cleans up resources.
171
+
172
+ ### Events
154
173
 
155
- L'outil utilise le callback `onChange` pour notifier des changements. Ce callback reçoit un objet avec les propriétés suivantes:
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}, // Position du point focal
160
- cropZone: {x, y, width, height}, // Position et dimensions de la zone de recadrage
161
- focusActive: true|false, // État d'activation du point focal
162
- cropActive: true|false // État d'activation de la zone de recadrage
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
- ## Exemples d'intégration avec des frameworks
185
+ ## Integration Examples with Frameworks
167
186
 
168
187
  ### React
169
188
 
170
189
  ```jsx
171
- import React, { useEffect, useRef } from 'react';
172
- import VisualImageTool from '@h4md1/visual-image-tool';
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('Données mises à jour:', data);
184
- }
202
+ console.log("Updated data:", data);
203
+ },
185
204
  });
186
-
187
- // Activer les fonctionnalités
205
+
206
+ // Enable features
188
207
  toolRef.current.toggleFocusPoint(true);
189
208
  toolRef.current.toggleCropZone(true);
190
209
  }
191
-
192
- // Nettoyage
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="Éditable" />
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="Éditable" />
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 '@h4md1/visual-image-tool';
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('Données mises à jour:', data);
232
- }
250
+ console.log("Updated data:", data);
251
+ },
233
252
  });
234
-
235
- // Activer les fonctionnalités
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
- ## Démos
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
- Consultez le dossier `demos/` pour des exemples complets :
289
+ ## Code Formatting
252
290
 
253
- - `basic-usage.html` : Exemple d'utilisation basique
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
- ## Compatibilité navigateur
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
- - Chrome (dernières versions)
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
- ## Licence
302
+ ## License
266
303
 
267
304
  MIT