veryfi-lens-wasm 2.0.7-beta.2 → 2.0.7-beta.3

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.
@@ -210,7 +210,6 @@ export const createBottleCapOverlay = (container, options = {}) => {
210
210
 
211
211
  const videoRect = videoElement.getBoundingClientRect();
212
212
  const circleDiameter = Math.min(videoRect.width, videoRect.height) * circleRadius;
213
- const squareSize = circleDiameter * 0.7; // Square inside the circle
214
213
 
215
214
  // Calculate scaling factors between screen and video dimensions
216
215
  const scaleX = videoElement.videoWidth / videoRect.width;
@@ -220,24 +219,25 @@ export const createBottleCapOverlay = (container, options = {}) => {
220
219
  const centerX = (videoRect.width / 2) * scaleX;
221
220
  const centerY = (videoRect.height / 2) * scaleY;
222
221
 
223
- // Calculate the square's dimensions in video coordinates
224
- const squareVideoSize = squareSize * Math.max(scaleX, scaleY);
222
+ // Calculate the circle dimensions in video coordinates
223
+ // Use the same scale factor for width and height to maintain aspect ratio
224
+ const circleDiameterInVideo = circleDiameter * scaleX;
225
225
 
226
- // Calculate the top-left corner of the square in video coordinates
227
- const cropX = centerX - (squareVideoSize / 2);
228
- const cropY = centerY - (squareVideoSize / 2);
226
+ // Calculate the top-left corner of the circle in video coordinates
227
+ const cropX = centerX - (circleDiameterInVideo / 2);
228
+ const cropY = centerY - (circleDiameterInVideo / 2);
229
229
 
230
- // Set cropImgRef dimensions to match the crop size - make sure width and height are equal
231
- cropImgRef.width = squareVideoSize;
232
- cropImgRef.height = squareVideoSize;
230
+ // Set cropImgRef dimensions to match the circle size - make sure width and height are equal
231
+ cropImgRef.width = circleDiameterInVideo;
232
+ cropImgRef.height = circleDiameterInVideo;
233
233
 
234
234
  // Draw the cropped portion to the cropImgRef canvas
235
235
  const ctx = cropImgRef.getContext('2d');
236
236
  ctx.clearRect(0, 0, cropImgRef.width, cropImgRef.height);
237
237
  ctx.drawImage(
238
238
  videoElement,
239
- cropX, cropY, squareVideoSize, squareVideoSize,
240
- 0, 0, squareVideoSize, squareVideoSize
239
+ cropX, cropY, circleDiameterInVideo, circleDiameterInVideo,
240
+ 0, 0, circleDiameterInVideo, circleDiameterInVideo
241
241
  );
242
242
 
243
243
  // Apply square display styling if the method exists
@@ -223,29 +223,30 @@ export const createCodeStripsOverlay = (container, options = {}) => {
223
223
  const centerX = (videoRect.width / 2) * scaleX;
224
224
  const centerY = (videoRect.height / 2) * scaleY;
225
225
 
226
- // Instead of using the rectangle dimensions, use a square with side length equal to the rectangle width
227
- const squareSize = rectWidth_px * scaleX; // Use the width of the rectangle for the square size
226
+ // Calculate actual crop dimensions in video coordinates
227
+ const cropWidth = rectWidth_px * scaleX;
228
+ const cropHeight = rectHeight_px * scaleY;
228
229
 
229
- // Calculate the top-left corner of the square in video coordinates
230
- const cropX = centerX - (squareSize / 2);
231
- const cropY = centerY - (squareSize / 2); // Center the square vertically
230
+ // Calculate the top-left corner of the rectangle in video coordinates
231
+ const cropX = centerX - (cropWidth / 2);
232
+ const cropY = centerY - (cropHeight / 2);
232
233
 
233
- // Set cropImgRef dimensions to match the square size (equal width and height)
234
- cropImgRef.width = squareSize;
235
- cropImgRef.height = squareSize;
234
+ // Set cropImgRef dimensions to match the rectangle dimensions
235
+ cropImgRef.width = cropWidth;
236
+ cropImgRef.height = cropHeight;
236
237
 
237
238
  // Draw the cropped portion to the cropImgRef canvas
238
239
  const ctx = cropImgRef.getContext('2d');
239
240
  ctx.clearRect(0, 0, cropImgRef.width, cropImgRef.height);
240
241
  ctx.drawImage(
241
242
  videoElement,
242
- cropX, cropY, squareSize, squareSize,
243
- 0, 0, squareSize, squareSize
243
+ cropX, cropY, cropWidth, cropHeight,
244
+ 0, 0, cropWidth, cropHeight
244
245
  );
245
246
 
246
- // Set square display if the method exists
247
- if (typeof cropImgRef.setSquareDisplay === 'function') {
248
- cropImgRef.setSquareDisplay();
247
+ // Set rectangle display if the method exists
248
+ if (typeof cropImgRef.setRectangleDisplay === 'function') {
249
+ cropImgRef.setRectangleDisplay();
249
250
  }
250
251
 
251
252
  // Convert to base64
@@ -130,6 +130,40 @@ export const createCroppedImage = (container) => {
130
130
  cropImgCanvas.style.border = '3px solid #00FA6C';
131
131
  cropImgCanvas.style.borderRadius = '10px';
132
132
  },
133
- setSquareDisplay
133
+ setSquareDisplay,
134
+ setRectangleDisplay: () => {
135
+ // Get the natural aspect ratio of the canvas
136
+ const aspectRatio = cropImgCanvas.width / cropImgCanvas.height;
137
+
138
+ // Calculate a reasonable size that fits well on the screen
139
+ const maxWidth = Math.min(500, window.innerWidth * 0.9);
140
+ const maxHeight = window.innerHeight * 0.6;
141
+
142
+ // Determine dimensions while preserving aspect ratio
143
+ let width, height;
144
+ if (aspectRatio > maxWidth / maxHeight) {
145
+ // Width is the limiting factor
146
+ width = maxWidth;
147
+ height = width / aspectRatio;
148
+ } else {
149
+ // Height is the limiting factor
150
+ height = maxHeight;
151
+ width = height * aspectRatio;
152
+ }
153
+
154
+ // Apply styles
155
+ cropImgCanvas.style.width = `${width}px`;
156
+ cropImgCanvas.style.height = `${height}px`;
157
+ cropImgCanvas.style.maxWidth = `${width}px`;
158
+ cropImgCanvas.style.maxHeight = `${height}px`;
159
+ cropImgCanvas.style.position = 'fixed';
160
+ cropImgCanvas.style.top = '50%';
161
+ cropImgCanvas.style.left = '50%';
162
+ cropImgCanvas.style.transform = 'translate(-50%, -50%)';
163
+ cropImgCanvas.style.objectFit = 'contain';
164
+ cropImgCanvas.style.display = 'block';
165
+ cropImgCanvas.style.margin = 'auto';
166
+ cropImgCanvas.style.borderRadius = '5px'; // Slightly rounded corners for the rectangle
167
+ }
134
168
  });
135
169
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfi-lens-wasm",
3
- "version": "2.0.7-beta.2",
3
+ "version": "2.0.7-beta.3",
4
4
  "description": "Lens For Web SDK with WASM",
5
5
  "main": "veryfi-lens.js",
6
6
  "type": "module",