veryfi-lens-wasm 2.0.5-beta.2 → 2.0.5-beta.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.
@@ -169,6 +169,7 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
169
169
  submitButton.style.display = 'none';
170
170
  cropButton.style.display = 'inline-block';
171
171
  resetButton.style.display = 'inline-block';
172
+ fileInput.value = '';
172
173
  };
173
174
 
174
175
  const handleFileSelect = (file) => {
@@ -221,7 +222,20 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
221
222
  imagePreview.style.display = 'block';
222
223
 
223
224
  cropButton.style.display = 'none';
224
- submitButton.style.display = 'inline-block';
225
+
226
+ // Check if submit button should be shown based on enableSubmit setting
227
+ if (container.dataset.enableSubmit !== 'false') {
228
+ submitButton.style.display = 'inline-block';
229
+ } else {
230
+ // If submit is disabled, call the callback directly with the processed image
231
+ // Format the result to match the document flavor format
232
+ console.log("Submit disabled, returning processed image directly");
233
+ onSubmit({
234
+ image: processedImage,
235
+ // Add any other properties that might be expected
236
+ doc_type: 'receipt'
237
+ });
238
+ }
225
239
  } catch (error) {
226
240
  console.error('Error during image processing:', error);
227
241
  alert(`An error occurred: ${error.message}. Please try again or check your connection. If the problem persists, contact support.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfi-lens-wasm",
3
- "version": "2.0.5-beta.2",
3
+ "version": "2.0.5-beta.4",
4
4
  "description": "Lens For Web SDK with WASM",
5
5
  "main": "veryfi-lens.js",
6
6
  "type": "module",
package/veryfi-lens.js CHANGED
@@ -1141,36 +1141,46 @@ const VeryfiLens = (function () {
1141
1141
 
1142
1142
  const removeOverlay = () => {
1143
1143
  try {
1144
- // Clear any existing intervals first
1145
- if (state.intervalRef) {
1146
- clearInterval(state.intervalRef);
1147
- state.intervalRef = null;
1148
- }
1144
+ // Clear any existing intervals first
1145
+ if (state.intervalRef) {
1146
+ clearInterval(state.intervalRef);
1147
+ state.intervalRef = null;
1148
+ }
1149
1149
 
1150
- // Then proceed with other cleanup
1151
- if (state.videoRef && state.videoRef.srcObject) {
1152
- const tracks = state.videoRef.srcObject.getTracks();
1153
- tracks.forEach(track => track.stop());
1154
- }
1150
+ // Then proceed with other cleanup
1151
+ if (state.videoRef && state.videoRef.srcObject) {
1152
+ const tracks = state.videoRef.srcObject.getTracks();
1153
+ tracks.forEach(track => track.stop());
1154
+ }
1155
1155
 
1156
- // Reset WASM wrapper
1157
- if (wasmWrapper) {
1158
- wasmWrapper.release();
1159
- wasmWrapper = null;
1160
- }
1161
- if (state.usingOverlayContainer) {
1162
- stopLens();
1163
- document.body.removeChild(state.container);
1164
- state.usingOverlayContainer = false;
1165
- } else {
1166
- stopLens();
1167
- }
1156
+ // Reset WASM wrapper
1157
+ if (wasmWrapper) {
1158
+ wasmWrapper.release();
1159
+ wasmWrapper = null;
1160
+ }
1168
1161
 
1169
- // Continue with other cleanup...
1170
- resetState();
1171
-
1162
+ // Clean up file upload component if it exists
1163
+ if (state.fileUpload) {
1164
+ state.fileUpload = null;
1165
+ }
1166
+
1167
+ if (state.usingOverlayContainer) {
1168
+ stopLens();
1169
+ document.body.removeChild(state.container);
1170
+ state.usingOverlayContainer = false;
1171
+ } else {
1172
+ stopLens();
1173
+ // Clear container contents if not using overlay
1174
+ if (state.container) {
1175
+ state.container.innerHTML = '';
1176
+ }
1177
+ }
1178
+
1179
+ // Continue with other cleanup...
1180
+ resetState();
1181
+
1172
1182
  } catch (error) {
1173
- console.error("Error in removeOverlay:", error);
1183
+ console.error("Error in removeOverlay:", error);
1174
1184
  }
1175
1185
  };
1176
1186
 
@@ -1933,6 +1943,7 @@ const VeryfiLens = (function () {
1933
1943
  showCamera: async (setter) => {
1934
1944
  try {
1935
1945
  state.debug_mode && console.log("Starting camera initialization");
1946
+ console.log(setter);
1936
1947
  setter && (state.resultSetter = setter);
1937
1948
 
1938
1949
  // Ensure container exists
@@ -1944,6 +1955,9 @@ const VeryfiLens = (function () {
1944
1955
  }
1945
1956
  }
1946
1957
 
1958
+ // Pass enableSubmit setting to container for use by components
1959
+ state.container.dataset.enableSubmit = state.enableSubmit.toString();
1960
+
1947
1961
  // Create core elements and verify success
1948
1962
  const elementsCreated = await createCoreElements();
1949
1963
 
@@ -1957,7 +1971,24 @@ const VeryfiLens = (function () {
1957
1971
  // Render appropriate UI elements based on lens flavor
1958
1972
  switch (state.lensFlavor) {
1959
1973
  case 'upload':
1960
- !state.fileUpload && (state.fileUpload = createFileUpload(state.container, captureUploaded, handleSubmit));
1974
+ !state.fileUpload && (state.fileUpload = createFileUpload(state.container, captureUploaded, (result) => {
1975
+ // Ensure consistent format for the result
1976
+ const formattedResult = typeof result === 'string'
1977
+ ? { image: result, doc_type: 'receipt' }
1978
+ : result;
1979
+
1980
+ // If enableSubmit is false, we'll get the image here directly after cropping
1981
+ if (!state.enableSubmit) {
1982
+ state.debug_mode && console.log("Submit disabled, handling image directly");
1983
+ if (state.resultSetter && typeof state.resultSetter === 'function') {
1984
+ state.resultSetter(formattedResult);
1985
+ }
1986
+ // Don't call handleSubmit here, just return the image
1987
+ } else {
1988
+ // Normal flow when enableSubmit is true
1989
+ handleSubmit(formattedResult.image);
1990
+ }
1991
+ }));
1961
1992
  // Add exit button for upload flavor
1962
1993
  if (state.exitButton) {
1963
1994
  createExitButton(state.container, {