allaw-ui 5.1.3 → 5.1.4

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.
@@ -239,35 +239,45 @@ var FileUploader = function (_a) {
239
239
  cropAreaWidth = 320;
240
240
  cropAreaHeight = 60;
241
241
  }
242
- // Le zoom dans cropMetadata est déjà le zoom total (baseZoom * zoom relatif)
243
- // Comme calculé dans ImageCropperModal ligne 318: zoom: baseZoom * zoom
242
+ // Le zoom dans cropMetadata est le zoom total (baseZoom * zoom relatif)
243
+ // baseZoom est calculé dans le modal comme Math.max(cropWidth / imgWidth, cropHeight / imgHeight)
244
+ // puis multiplié par le zoom relatif (1-3) pour obtenir le zoom total
244
245
  var totalZoom = cropMetadata.zoom;
245
- // Dimensions de l'image après zoom
246
- var scaledImgWidth = img.width * totalZoom;
247
- var scaledImgHeight = img.height * totalZoom;
248
- // Dans le modal, l'image est centrée dans le container
249
- // Le container a les mêmes dimensions que le viewport du modal
250
- // La cropArea est centrée dans ce container
251
- // Les offsets (offsetX, offsetY) représentent le déplacement de l'image depuis le centre
252
- // Position du centre de l'image zoomée (qui correspond au centre du container)
253
- var imgCenterX = scaledImgWidth / 2;
254
- var imgCenterY = scaledImgHeight / 2;
255
- // Position du centre de la cropArea dans l'image zoomée
256
- // Les offsets sont la position de l'image par rapport au centre du container
257
- // Donc le centre de la cropArea dans l'image zoomée est :
258
- var cropCenterX = imgCenterX - cropMetadata.offsetX;
259
- var cropCenterY = imgCenterY - cropMetadata.offsetY;
260
- // Coordonnées du coin supérieur gauche de la zone à cropper dans l'image zoomée
261
- var cropXInScaledImg = cropCenterX - cropAreaWidth / 2;
262
- var cropYInScaledImg = cropCenterY - cropAreaHeight / 2;
263
- // Convertir ces coordonnées en coordonnées de l'image originale (diviser par le zoom)
264
- var sourceX = cropXInScaledImg / totalZoom;
265
- var sourceY = cropYInScaledImg / totalZoom;
266
- var sourceWidth = cropAreaWidth / totalZoom;
267
- var sourceHeight = cropAreaHeight / totalZoom;
268
- // S'assurer que les coordonnées sont valides
269
- var clampedSourceX = Math.max(0, Math.min(sourceX, img.width - sourceWidth));
270
- var clampedSourceY = Math.max(0, Math.min(sourceY, img.height - sourceHeight));
246
+ // Dans le modal, la transform CSS est appliquée sur le container de l'image :
247
+ // transform: translate(offsetX, offsetY) scale(totalZoom)
248
+ // transform-origin: center
249
+ //
250
+ // L'ordre d'application est : scale d'abord (depuis le centre), puis translate
251
+ // Géométriquement, cela signifie :
252
+ // 1. L'image est agrandie avec scale(totalZoom) depuis son centre
253
+ // 2. L'image agrandie est déplacée de (offsetX, offsetY)
254
+ //
255
+ // La cropArea est fixe et centrée dans le container
256
+ // Pour trouver quelle partie de l'image originale correspond à la cropArea :
257
+ // - Le centre de la cropArea correspond au point (0, 0) dans le système de coordonnées du container
258
+ // - Ce point (0, 0) dans l'image transformée correspond à (-offsetX, -offsetY) dans l'image agrandie
259
+ // - Ce point dans l'image agrandie correspond à (-offsetX/totalZoom, -offsetY/totalZoom) dans l'image originale
260
+ // Centre de l'image originale
261
+ var imgCenterX = img.width / 2;
262
+ var imgCenterY = img.height / 2;
263
+ // Position du centre de la cropArea dans l'image originale
264
+ // Si l'image transformée est déplacée de offsetX vers la droite,
265
+ // alors le centre de la cropArea (qui reste au centre du container)
266
+ // correspond à un point qui est offsetX pixels à gauche du centre de l'image transformée
267
+ // Converti en coordonnées de l'image originale :
268
+ var cropCenterXInOriginal = imgCenterX - cropMetadata.offsetX / totalZoom;
269
+ var cropCenterYInOriginal = imgCenterY - cropMetadata.offsetY / totalZoom;
270
+ // Dimensions de la zone de crop dans l'image originale
271
+ var cropWidthInOriginal = cropAreaWidth / totalZoom;
272
+ var cropHeightInOriginal = cropAreaHeight / totalZoom;
273
+ // Coordonnées du coin supérieur gauche de la zone à cropper dans l'image originale
274
+ var sourceX = cropCenterXInOriginal - cropWidthInOriginal / 2;
275
+ var sourceY = cropCenterYInOriginal - cropHeightInOriginal / 2;
276
+ var sourceWidth = cropWidthInOriginal;
277
+ var sourceHeight = cropHeightInOriginal;
278
+ // S'assurer que les coordonnées sont valides (pas en dehors de l'image)
279
+ var clampedSourceX = Math.max(0, Math.min(sourceX, img.width - 1));
280
+ var clampedSourceY = Math.max(0, Math.min(sourceY, img.height - 1));
271
281
  var clampedSourceWidth = Math.min(sourceWidth, img.width - clampedSourceX);
272
282
  var clampedSourceHeight = Math.min(sourceHeight, img.height - clampedSourceY);
273
283
  // Dessiner l'image croppée sur le canvas
@@ -330,8 +340,7 @@ var FileUploader = function (_a) {
330
340
  case 1:
331
341
  _a.trys.push([1, 4, , 5]);
332
342
  dimensions = cropOutputDimensions[cropMetadata.shape] ||
333
- cropOutputDimensions.square ||
334
- { width: 200, height: 200 };
343
+ cropOutputDimensions.square || { width: 200, height: 200 };
335
344
  return [4 /*yield*/, cropImageToBlob(previewUrl, cropMetadata, dimensions.width, dimensions.height)];
336
345
  case 2:
337
346
  croppedBlob = _a.sent();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "allaw-ui",
3
- "version": "5.1.3",
3
+ "version": "5.1.4",
4
4
  "description": "Composants UI pour l'application Allaw",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",