veryfi-lens-wasm 2.0.9 → 2.0.11

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.
@@ -4,99 +4,110 @@ export const createBlurModal = (container, croppedImage, onRetake, onSubmit, opt
4
4
  modal.style.display = 'none';
5
5
 
6
6
  const defaultStyles = {
7
- position: 'absolute',
8
- top: '20%',
9
- left: '50%',
10
- transform: 'translateX(-50%)',
11
- backgroundColor: 'rgba(255, 255, 255, 0.8)',
7
+ position: 'fixed',
12
8
  width: '300px',
13
- height: '350px',
14
- borderRadius: '8px',
15
- boxShadow: '0 4px 6px rgba(0, 0, 0, 0.1)',
9
+ height: '250px',
10
+ display: 'flex',
11
+ justifyContent: 'center',
12
+ alignItems: 'center',
16
13
  zIndex: '1000',
14
+ backgroundColor: 'white',
15
+ borderRadius: '8px',
16
+ padding: '20px',
17
+ maxWidth: '300px',
17
18
  textColor: '#1e293b',
18
19
  textFontFamily: "'NB International Pro', sans-serif",
19
- textFontSize: '24px',
20
- buttonWidth: '90%',
21
- buttonPadding: '24px 16px',
20
+ textFontSize: '17px',
21
+ buttonWidth: '100%',
22
+ buttonPadding: '12px',
22
23
  buttonBorderRadius: '4px',
23
24
  buttonFontFamily: "'DIN Pro', sans-serif",
24
25
  buttonFontSize: '14px',
25
- buttonFontWeight: '500',
26
- buttonTextTransform: 'uppercase',
27
- primaryButtonBackground: 'linear-gradient(302deg, #2DB5D2 0%, #00FA6C 48%, #2DB5D2 100%)',
28
- primaryButtonColor: '#1e293b',
26
+ buttonFontWeight: '700',
27
+ primaryButtonBackground: '#00AA00',
28
+ primaryButtonColor: 'white',
29
29
  secondaryButtonBackground: 'transparent',
30
- secondaryButtonBorder: '1px solid #1e293b',
31
- secondaryButtonColor: '#1e293b'
30
+ secondaryButtonBorder: '1px solid #333',
31
+ secondaryButtonColor: '#333'
32
32
  };
33
33
 
34
34
  const defaultOptions = {
35
- blurModalMessage: 'Oops, The image is too blurry to process'
35
+ blurModalMessage: 'Oops, The image is too blurry to process',
36
+ retakeButtonText: 'Retake a picture',
37
+ submitButtonText: 'Submit Anyway',
38
+ enforced: false
36
39
  };
37
40
 
38
41
  // Merge provided options with defaults
39
42
  const modalOptions = { ...defaultOptions, ...options };
40
- // Apply styles with fallback to default values
43
+
44
+ // Apply styles with fallback to default values (exclude display to prevent overriding initial display: none)
41
45
  Object.entries(defaultStyles).forEach(([key, value]) => {
42
- const cssVar = `--blur-modal-${key.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)}`;
43
- modal.style.setProperty(key, `var(${cssVar}, ${value})`);
46
+ if (key !== 'display') {
47
+ const cssVar = `--blur-modal-${key.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)}`;
48
+ modal.style.setProperty(key, `var(${cssVar}, ${value})`);
49
+ }
44
50
  });
45
51
 
46
- modal.style.backgroundColor = `var(--modal-background-color, ${defaultStyles.backgroundColor})`;
47
52
  modal.style.borderRadius = `var(--modal-border-radius, ${defaultStyles.borderRadius})`;
48
53
  modal.style.zIndex = `var(--modal-z-index, ${defaultStyles.zIndex})`;
54
+ modal.style.width = `var(--modal-width, ${defaultStyles.width})`;
55
+ modal.style.height = `var(--modal-height, ${modalOptions.enforced ? '190px' : defaultStyles.height})`;
56
+ modal.style.top = `var(--modal-top, ${defaultStyles.top})`;
57
+ modal.style.left = `var(--modal-left, ${defaultStyles.left})`;
58
+ modal.style.transform = `var(--modal-transform, ${defaultStyles.transform})`;
49
59
 
50
60
  modal.innerHTML = `
51
- <p style="
52
- padding: 20px;
53
- margin-top: 20px;
54
- text-align: center;
55
- color: var(--blur-modal-text-color, ${defaultStyles.textColor});
56
- font-size: var(--blur-modal-text-font-size, ${defaultStyles.textFontSize});
57
- font-family: var(--blur-modal-text-font-family, ${defaultStyles.textFontFamily});
61
+ <div style="
62
+ background-color: var(--blur-modal-background-color, ${defaultStyles.backgroundColor});
63
+ border-radius: var(--blur-modal-border-radius, ${defaultStyles.borderRadius});
64
+ padding: var(--blur-modal-padding, ${defaultStyles.padding});
65
+ width: var(--blur-modal-width, ${defaultStyles.width});
66
+ max-width: var(--blur-modal-max-width, ${defaultStyles.maxWidth});
58
67
  ">
59
- ${modalOptions.blurModalMessage.replace(/</g, '&lt;').replace(/>/g, '&gt;')}
60
- </p>
61
- <div style="display: flex; flex-direction: column; align-items: center; gap: 8px;">
68
+ <p style="
69
+ text-align: center;
70
+ margin-bottom: 20px;
71
+ color: var(--blur-modal-text-color, ${defaultStyles.textColor});
72
+ font-size: var(--blur-modal-text-font-size, ${defaultStyles.textFontSize});
73
+ font-family: var(--blur-modal-text-font-family, ${defaultStyles.textFontFamily});
74
+ ">
75
+ ${modalOptions.blurModalMessage.replace(/</g, '&lt;').replace(/>/g, '&gt;')}
76
+ </p>
62
77
  <button id="veryfi-retake-blur" style="
63
78
  width: var(--blur-modal-button-width, ${defaultStyles.buttonWidth});
64
79
  padding: var(--blur-modal-button-padding, ${defaultStyles.buttonPadding});
80
+ margin-top: 10px;
65
81
  border-radius: var(--blur-modal-button-border-radius, ${defaultStyles.buttonBorderRadius});
66
- background-image: var(--blur-modal-primary-button-background, ${defaultStyles.primaryButtonBackground});
82
+ background-color: var(--blur-modal-primary-button-background, ${defaultStyles.primaryButtonBackground});
83
+ color: var(--blur-modal-primary-button-color, ${defaultStyles.primaryButtonColor});
67
84
  border: none;
68
85
  cursor: pointer;
86
+ font-weight: var(--blur-modal-button-font-weight, ${defaultStyles.buttonFontWeight});
87
+ font-family: var(--blur-modal-button-font-family, ${defaultStyles.buttonFontFamily});
88
+ font-size: var(--blur-modal-button-font-size, ${defaultStyles.buttonFontSize});
89
+ transition: all 0.3s ease;
69
90
  ">
70
- <p style="
71
- text-align: center;
72
- color: var(--blur-modal-primary-button-color, ${defaultStyles.primaryButtonColor});
73
- font-size: var(--blur-modal-button-font-size, ${defaultStyles.buttonFontSize});
74
- font-weight: var(--blur-modal-button-font-weight, ${defaultStyles.buttonFontWeight});
75
- font-family: var(--blur-modal-button-font-family, ${defaultStyles.buttonFontFamily});
76
- text-transform: var(--blur-modal-button-text-transform, ${defaultStyles.buttonTextTransform});
77
- ">
78
- ${modalOptions.retakeButtonText.replace(/</g, '&lt;').replace(/>/g, '&gt;')}
79
- </p>
91
+ ${modalOptions.retakeButtonText.replace(/</g, '&lt;').replace(/>/g, '&gt;')}
80
92
  </button>
93
+ ${!modalOptions.enforced ? `
81
94
  <button id="veryfi-submit-blur" style="
82
95
  width: var(--blur-modal-button-width, ${defaultStyles.buttonWidth});
83
96
  padding: var(--blur-modal-button-padding, ${defaultStyles.buttonPadding});
97
+ margin-top: 10px;
84
98
  border-radius: var(--blur-modal-button-border-radius, ${defaultStyles.buttonBorderRadius});
85
99
  background-color: var(--blur-modal-secondary-button-background, ${defaultStyles.secondaryButtonBackground});
100
+ color: var(--blur-modal-secondary-button-color, ${defaultStyles.secondaryButtonColor});
86
101
  border: var(--blur-modal-secondary-button-border, ${defaultStyles.secondaryButtonBorder});
87
102
  cursor: pointer;
103
+ font-weight: var(--blur-modal-button-font-weight, ${defaultStyles.buttonFontWeight});
104
+ font-family: var(--blur-modal-button-font-family, ${defaultStyles.buttonFontFamily});
105
+ font-size: var(--blur-modal-button-font-size, ${defaultStyles.buttonFontSize});
106
+ transition: all 0.3s ease;
88
107
  ">
89
- <p style="
90
- text-align: center;
91
- color: var(--blur-modal-secondary-button-color, ${defaultStyles.secondaryButtonColor});
92
- font-size: var(--blur-modal-button-font-size, ${defaultStyles.buttonFontSize});
93
- font-weight: var(--blur-modal-button-font-weight, ${defaultStyles.buttonFontWeight});
94
- font-family: var(--blur-modal-button-font-family, ${defaultStyles.buttonFontFamily});
95
- text-transform: var(--blur-modal-button-text-transform, ${defaultStyles.buttonTextTransform});
96
- ">
97
- ${modalOptions.submitButtonText.replace(/</g, '&lt;').replace(/>/g, '&gt;')}
98
- </p>
108
+ ${modalOptions.submitButtonText.replace(/</g, '&lt;').replace(/>/g, '&gt;')}
99
109
  </button>
110
+ ` : ''}
100
111
  </div>
101
112
  `;
102
113
 
@@ -115,15 +126,17 @@ export const createBlurModal = (container, croppedImage, onRetake, onSubmit, opt
115
126
  onRetake();
116
127
  });
117
128
 
118
- submitButton.addEventListener('click', () => {
119
- modal.style.display = 'none';
120
- croppedImage.hideBorder();
121
- onSubmit();
122
- });
129
+ if (submitButton) {
130
+ submitButton.addEventListener('click', () => {
131
+ modal.style.display = 'none';
132
+ croppedImage.hideBorder();
133
+ onSubmit();
134
+ });
135
+ }
123
136
 
124
137
  return {
125
138
  show: () => {
126
- modal.style.display = 'block';
139
+ modal.style.display = 'flex';
127
140
  croppedImage.showBorder();
128
141
  },
129
142
  hide: () => {
@@ -1,4 +1,4 @@
1
- export const createCheckCaptureModal = (container, croppedImage, onCaptureBothSides, onCaptureOneSide) => {
1
+ export const createCheckCaptureModal = (container, croppedImage, onCaptureBothSides, onCaptureOneSide, options = {}) => {
2
2
  const modal = document.createElement('div');
3
3
  modal.id = 'veryfi-check-capture-modal';
4
4
  modal.style.display = 'none';
@@ -11,38 +11,67 @@ export const createCheckCaptureModal = (container, croppedImage, onCaptureBothSi
11
11
  justifyContent: 'center',
12
12
  alignItems: 'center',
13
13
  zIndex: '1000',
14
+ backgroundColor: 'white',
15
+ borderRadius: '8px',
16
+ padding: '20px',
17
+ maxWidth: '300px',
14
18
  textColor: '#1e293b',
15
19
  textFontFamily: "'NB International Pro', sans-serif",
16
- textFontSize: '18px',
20
+ textFontSize: '17px',
17
21
  buttonWidth: '100%',
18
22
  buttonPadding: '12px',
19
23
  buttonBorderRadius: '4px',
20
24
  buttonFontFamily: "'DIN Pro', sans-serif",
21
25
  buttonFontSize: '14px',
22
26
  buttonFontWeight: '700',
23
- primaryButtonBackground: '#00FA6C',
27
+ primaryButtonBackground: '#00AA00',
24
28
  primaryButtonColor: 'white',
25
29
  secondaryButtonBackground: 'transparent',
26
30
  secondaryButtonBorder: '1px solid #333',
27
31
  secondaryButtonColor: '#333'
28
32
  };
29
33
 
30
- // Apply styles with fallback to default values
34
+ const defaultOptions = {
35
+ enforcedModalMessage: 'Please flip the check and capture the back side',
36
+ optionalModalMessage: 'Do you want to capture the back side of the check?',
37
+ continueButtonText: 'Continue',
38
+ yesButtonText: 'Yes',
39
+ noButtonText: 'No'
40
+ };
41
+
42
+ // Merge provided options with defaults
43
+ const modalOptions = { ...defaultOptions, ...options };
44
+
45
+ // Apply styles with fallback to default values (exclude display to prevent overriding initial display: none)
31
46
  Object.entries(defaultStyles).forEach(([key, value]) => {
32
- const cssVar = `--check-modal-${key.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)}`;
33
- modal.style.setProperty(key, `var(${cssVar}, ${value})`);
47
+ if (key !== 'display') {
48
+ const cssVar = `--check-modal-${key.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)}`;
49
+ modal.style.setProperty(key, `var(${cssVar}, ${value})`);
50
+ }
34
51
  });
35
52
 
53
+ const isEnforced = onCaptureOneSide === null;
54
+ const modalText = isEnforced
55
+ ? modalOptions.enforcedModalMessage
56
+ : modalOptions.optionalModalMessage;
57
+ const buttonText = isEnforced ? modalOptions.continueButtonText : modalOptions.yesButtonText;
58
+
36
59
  modal.style.borderRadius = `var(--modal-border-radius, ${defaultStyles.borderRadius})`;
37
60
  modal.style.zIndex = `var(--modal-z-index, ${defaultStyles.zIndex})`;
61
+ modal.style.width = `var(--modal-width, ${defaultStyles.width})`;
62
+ modal.style.height = `var(--modal-height, ${isEnforced ? '190px' : defaultStyles.height})`;
63
+ modal.style.top = `var(--modal-top, ${defaultStyles.top})`;
64
+ modal.style.left = `var(--modal-left, ${defaultStyles.left})`;
65
+ modal.style.transform = `var(--modal-transform, ${defaultStyles.transform})`;
66
+
38
67
 
39
68
  modal.innerHTML = `
40
69
  <div style="
41
- background-color: white;
42
- border-radius: 8px;
43
- padding: 20px;
44
- width: 90%;
45
- max-width: 300px;
70
+ background-color: var(--check-modal-background-color, ${defaultStyles.backgroundColor});
71
+ border-radius: var(--check-modal-border-radius, ${defaultStyles.borderRadius});
72
+ padding: var(--check-modal-padding, ${defaultStyles.padding});
73
+ width: var(--check-modal-width, ${defaultStyles.width});
74
+ max-width: var(--check-modal-max-width, ${defaultStyles.maxWidth});
46
75
  ">
47
76
  <p style="
48
77
  text-align: center;
@@ -51,7 +80,7 @@ export const createCheckCaptureModal = (container, croppedImage, onCaptureBothSi
51
80
  font-size: var(--check-modal-text-font-size, ${defaultStyles.textFontSize});
52
81
  font-family: var(--check-modal-text-font-family, ${defaultStyles.textFontFamily});
53
82
  ">
54
- Do you want to capture the back side of the check?
83
+ ${modalText.replace(/</g, '&lt;').replace(/>/g, '&gt;')}
55
84
  </p>
56
85
  <button id="veryfi-capture-both-sides" style="
57
86
  width: var(--check-modal-button-width, ${defaultStyles.buttonWidth});
@@ -67,8 +96,9 @@ export const createCheckCaptureModal = (container, croppedImage, onCaptureBothSi
67
96
  font-size: var(--check-modal-button-font-size, ${defaultStyles.buttonFontSize});
68
97
  transition: all 0.3s ease;
69
98
  ">
70
- Yes
99
+ ${buttonText.replace(/</g, '&lt;').replace(/>/g, '&gt;')}
71
100
  </button>
101
+ ${!isEnforced ? `
72
102
  <button id="veryfi-capture-one-side" style="
73
103
  width: var(--check-modal-button-width, ${defaultStyles.buttonWidth});
74
104
  padding: var(--check-modal-button-padding, ${defaultStyles.buttonPadding});
@@ -83,8 +113,9 @@ export const createCheckCaptureModal = (container, croppedImage, onCaptureBothSi
83
113
  font-size: var(--check-modal-button-font-size, ${defaultStyles.buttonFontSize});
84
114
  transition: all 0.3s ease;
85
115
  ">
86
- No
116
+ ${modalOptions.noButtonText.replace(/</g, '&lt;').replace(/>/g, '&gt;')}
87
117
  </button>
118
+ ` : ''}
88
119
  </div>
89
120
  `;
90
121
 
@@ -104,10 +135,12 @@ export const createCheckCaptureModal = (container, croppedImage, onCaptureBothSi
104
135
  onCaptureBothSides();
105
136
  });
106
137
 
107
- captureOneSideButton.addEventListener('click', () => {
108
- modal.style.display = 'none';
109
- onCaptureOneSide();
110
- });
138
+ if (captureOneSideButton && onCaptureOneSide) {
139
+ captureOneSideButton.addEventListener('click', () => {
140
+ modal.style.display = 'none';
141
+ onCaptureOneSide();
142
+ });
143
+ }
111
144
 
112
145
  return {
113
146
  show: () => {
@@ -1,18 +1,35 @@
1
1
  export const createCheckImages = (container) => {
2
2
  let imagesContainer = null;
3
+
4
+ const defaultStyles = {
5
+ containerDisplay: 'flex',
6
+ containerFlexDirection: 'column',
7
+ containerJustifyContent: 'center',
8
+ containerAlignItems: 'center',
9
+ containerWidth: '100%',
10
+ containerHeight: '100%',
11
+ containerOverflow: 'auto',
12
+ imageMaxWidthPortrait: '48%',
13
+ imageMaxHeightPortrait: '96%',
14
+ imageMaxWidthLandscape: '96%',
15
+ imageMaxHeightLandscape: '48%',
16
+ imageObjectFit: 'contain',
17
+ imageMargin: '1%'
18
+ };
3
19
 
4
20
  const createContainer = () => {
5
21
  imagesContainer = document.createElement('div');
6
22
  imagesContainer.id = 'check-images-container';
7
- imagesContainer.style.cssText = `
8
- display: flex;
9
- flex-direction: column;
10
- justify-content: center;
11
- align-items: center;
12
- width: 100%;
13
- height: 100%;
14
- overflow: auto;
15
- `;
23
+
24
+ // Apply container styles with CSS variables
25
+ imagesContainer.style.setProperty('display', `var(--check-images-container-display, ${defaultStyles.containerDisplay})`);
26
+ imagesContainer.style.setProperty('flex-direction', `var(--check-images-container-flex-direction, ${defaultStyles.containerFlexDirection})`);
27
+ imagesContainer.style.setProperty('justify-content', `var(--check-images-container-justify-content, ${defaultStyles.containerJustifyContent})`);
28
+ imagesContainer.style.setProperty('align-items', `var(--check-images-container-align-items, ${defaultStyles.containerAlignItems})`);
29
+ imagesContainer.style.setProperty('width', `var(--check-images-container-width, ${defaultStyles.containerWidth})`);
30
+ imagesContainer.style.setProperty('height', `var(--check-images-container-height, ${defaultStyles.containerHeight})`);
31
+ imagesContainer.style.setProperty('overflow', `var(--check-images-container-overflow, ${defaultStyles.containerOverflow})`);
32
+
16
33
  container.appendChild(imagesContainer);
17
34
  return imagesContainer;
18
35
  };
@@ -29,12 +46,20 @@ export const createCheckImages = (container) => {
29
46
  const imgElement = document.createElement('img');
30
47
  imgElement.src = img.src;
31
48
  imgElement.alt = alt;
32
- imgElement.style.cssText = `
33
- max-width: ${isPortrait ? '48%' : '96%'};
34
- max-height: ${isPortrait ? '96%' : '48%'};
35
- object-fit: contain;
36
- margin: 1%;
37
- `;
49
+
50
+ // Apply image styles with CSS variables based on orientation
51
+ const maxWidth = isPortrait
52
+ ? `var(--check-images-max-width-portrait, ${defaultStyles.imageMaxWidthPortrait})`
53
+ : `var(--check-images-max-width-landscape, ${defaultStyles.imageMaxWidthLandscape})`;
54
+ const maxHeight = isPortrait
55
+ ? `var(--check-images-max-height-portrait, ${defaultStyles.imageMaxHeightPortrait})`
56
+ : `var(--check-images-max-height-landscape, ${defaultStyles.imageMaxHeightLandscape})`;
57
+
58
+ imgElement.style.setProperty('max-width', maxWidth);
59
+ imgElement.style.setProperty('max-height', maxHeight);
60
+ imgElement.style.setProperty('object-fit', `var(--check-images-object-fit, ${defaultStyles.imageObjectFit})`);
61
+ imgElement.style.setProperty('margin', `var(--check-images-margin, ${defaultStyles.imageMargin})`);
62
+
38
63
  return imgElement;
39
64
  };
40
65
 
@@ -55,8 +80,11 @@ export const createCheckImages = (container) => {
55
80
 
56
81
  const isPortrait = frontAspectRatio < containerAspectRatio && backAspectRatio < containerAspectRatio;
57
82
 
58
- // Update container orientation
59
- imagesContainer.style.flexDirection = isPortrait ? 'row' : 'column';
83
+ // Update container orientation with CSS variables
84
+ const flexDirection = isPortrait
85
+ ? `var(--check-images-container-flex-direction-portrait, row)`
86
+ : `var(--check-images-container-flex-direction-landscape, column)`;
87
+ imagesContainer.style.setProperty('flex-direction', flexDirection);
60
88
 
61
89
  // Create and append image elements
62
90
  const frontImageElement = createImageElement(frontImg, 'Front of check', isPortrait);
@@ -83,12 +111,12 @@ export const createCheckImages = (container) => {
83
111
  renderCheckImages,
84
112
  hide: () => {
85
113
  if (imagesContainer) {
86
- imagesContainer.style.display = 'none';
114
+ imagesContainer.style.setProperty('display', 'var(--check-images-container-display-hidden, none)');
87
115
  }
88
116
  },
89
117
  show: () => {
90
118
  if (imagesContainer) {
91
- imagesContainer.style.display = 'flex';
119
+ imagesContainer.style.setProperty('display', `var(--check-images-container-display, ${defaultStyles.containerDisplay})`);
92
120
  }
93
121
  }
94
122
  };
@@ -8,11 +8,20 @@ export const createCroppedImage = (container) => {
8
8
  height: 'auto',
9
9
  maxWidth: '350px',
10
10
  maxHeight: '100%',
11
- zIndex: '130'
11
+ zIndex: '130',
12
+ borderWidth: '3px',
13
+ borderColorError: 'red',
14
+ borderColorSuccess: '#00AA00',
15
+ borderRadius: '10px',
16
+ borderRadiusRectangle: '5px'
12
17
  };
13
18
 
19
+ // Apply default styles with CSS variables
14
20
  Object.entries(defaultStyles).forEach(([key, value]) => {
15
- cropImgCanvas.style[key] = value;
21
+ if (!['borderWidth', 'borderColorError', 'borderColorSuccess', 'borderRadius', 'borderRadiusRectangle'].includes(key)) {
22
+ const cssVar = `--cropped-image-${key.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)}`;
23
+ cropImgCanvas.style.setProperty(key, `var(${cssVar}, ${value})`);
24
+ }
16
25
  });
17
26
 
18
27
  // Override the putImageData method to handle rotation automatically
@@ -52,39 +61,36 @@ export const createCroppedImage = (container) => {
52
61
 
53
62
  if (isBottleCapsMode) {
54
63
  // For bottle caps, maintain square aspect ratio
55
- const squareSize = Math.min(350, Math.min(window.innerWidth * 0.8, window.innerHeight * 0.6));
56
- cropImgCanvas.style.width = `${squareSize}px`;
57
- cropImgCanvas.style.height = `${squareSize}px`;
58
- cropImgCanvas.style.maxWidth = `${squareSize}px`;
59
- cropImgCanvas.style.maxHeight = `${squareSize}px`;
60
- cropImgCanvas.style.position = 'fixed';
61
- cropImgCanvas.style.top = '50%';
62
- cropImgCanvas.style.left = '50%';
63
- cropImgCanvas.style.transform = 'translate(-50%, -50%)';
64
- cropImgCanvas.style.objectFit = 'contain';
65
- cropImgCanvas.style.display = 'block';
66
- cropImgCanvas.style.margin = 'auto';
64
+ const baseSquareSize = Math.min(350, Math.min(window.innerWidth * 0.8, window.innerHeight * 0.6));
65
+ const squareSize = `var(--cropped-image-square-size, ${baseSquareSize}px)`;
66
+ cropImgCanvas.style.setProperty('width', squareSize);
67
+ cropImgCanvas.style.setProperty('height', squareSize);
68
+ cropImgCanvas.style.setProperty('max-width', squareSize);
69
+ cropImgCanvas.style.setProperty('max-height', squareSize);
70
+ cropImgCanvas.style.setProperty('position', 'var(--cropped-image-square-position, fixed)');
71
+ cropImgCanvas.style.setProperty('top', 'var(--cropped-image-square-top, 50%)');
72
+ cropImgCanvas.style.setProperty('left', 'var(--cropped-image-square-left, 50%)');
73
+ cropImgCanvas.style.setProperty('transform', 'var(--cropped-image-square-transform, translate(-50%, -50%))');
74
+ cropImgCanvas.style.setProperty('object-fit', 'var(--cropped-image-object-fit, contain)');
75
+ cropImgCanvas.style.setProperty('display', 'var(--cropped-image-display, block)');
76
+ cropImgCanvas.style.setProperty('margin', 'var(--cropped-image-margin, auto)');
67
77
  } else if (isMobile) {
68
- cropImgCanvas.style.width = '370px';
69
- cropImgCanvas.style.height = '95vh';
70
- cropImgCanvas.style.maxWidth = '350px';
71
- cropImgCanvas.style.position = 'fixed';
78
+ const mobileWidth = isLandscape ? 'var(--cropped-image-mobile-landscape-width, 170px)' : 'var(--cropped-image-mobile-width, 370px)';
79
+ const mobileHeight = isLandscape ? 'var(--cropped-image-mobile-landscape-height, 85vh)' : 'var(--cropped-image-mobile-height, 95vh)';
80
+ const mobileMaxWidth = isLandscape ? 'var(--cropped-image-mobile-landscape-max-width, 200px)' : 'var(--cropped-image-mobile-max-width, 350px)';
81
+
82
+ cropImgCanvas.style.setProperty('width', mobileWidth);
83
+ cropImgCanvas.style.setProperty('height', mobileHeight);
84
+ cropImgCanvas.style.setProperty('max-width', mobileMaxWidth);
85
+ cropImgCanvas.style.setProperty('position', 'var(--cropped-image-mobile-position, fixed)');
72
86
  cropImgCanvas.style.top = '';
73
87
  cropImgCanvas.style.left = '';
74
88
  cropImgCanvas.style.transform = '';
75
- if (isLandscape) {
76
- cropImgCanvas.style.width = '170px';
77
- cropImgCanvas.style.height = '85vh';
78
- cropImgCanvas.style.maxWidth = '200px';
79
- cropImgCanvas.style.position = 'fixed';
80
- cropImgCanvas.style.top = '';
81
- cropImgCanvas.style.left = '';
82
- }
83
89
  } else {
84
- cropImgCanvas.style.width = '100%';
85
- cropImgCanvas.style.height = '95%';
86
- cropImgCanvas.style.maxWidth = '370px';
87
- cropImgCanvas.style.position = 'absolute';
90
+ cropImgCanvas.style.setProperty('width', 'var(--cropped-image-desktop-width, 100%)');
91
+ cropImgCanvas.style.setProperty('height', 'var(--cropped-image-desktop-height, 95%)');
92
+ cropImgCanvas.style.setProperty('max-width', 'var(--cropped-image-desktop-max-width, 370px)');
93
+ cropImgCanvas.style.setProperty('position', 'var(--cropped-image-desktop-position, absolute)');
88
94
  cropImgCanvas.style.top = '';
89
95
  cropImgCanvas.style.left = '';
90
96
  cropImgCanvas.style.transform = '';
@@ -102,33 +108,40 @@ export const createCroppedImage = (container) => {
102
108
 
103
109
  // Add a specific method for bottle caps to ensure square display
104
110
  const setSquareDisplay = () => {
105
- const squareSize = Math.min(350, Math.min(window.innerWidth * 0.8, window.innerHeight * 0.6));
106
- cropImgCanvas.style.width = `${squareSize}px`;
107
- cropImgCanvas.style.height = `${squareSize}px`;
108
- cropImgCanvas.style.maxWidth = `${squareSize}px`;
109
- cropImgCanvas.style.maxHeight = `${squareSize}px`;
110
- cropImgCanvas.style.position = 'fixed';
111
- cropImgCanvas.style.top = '50%';
112
- cropImgCanvas.style.left = '50%';
113
- cropImgCanvas.style.transform = 'translate(-50%, -50%)';
114
- cropImgCanvas.style.objectFit = 'contain';
115
- cropImgCanvas.style.display = 'block';
116
- cropImgCanvas.style.margin = 'auto';
111
+ const baseSquareSize = Math.min(350, Math.min(window.innerWidth * 0.8, window.innerHeight * 0.6));
112
+ const squareSize = `var(--cropped-image-square-size, ${baseSquareSize}px)`;
113
+ cropImgCanvas.style.setProperty('width', squareSize);
114
+ cropImgCanvas.style.setProperty('height', squareSize);
115
+ cropImgCanvas.style.setProperty('max-width', squareSize);
116
+ cropImgCanvas.style.setProperty('max-height', squareSize);
117
+ cropImgCanvas.style.setProperty('position', 'var(--cropped-image-square-position, fixed)');
118
+ cropImgCanvas.style.setProperty('top', 'var(--cropped-image-square-top, 50%)');
119
+ cropImgCanvas.style.setProperty('left', 'var(--cropped-image-square-left, 50%)');
120
+ cropImgCanvas.style.setProperty('transform', 'var(--cropped-image-square-transform, translate(-50%, -50%))');
121
+ cropImgCanvas.style.setProperty('object-fit', 'var(--cropped-image-object-fit, contain)');
122
+ cropImgCanvas.style.setProperty('display', 'var(--cropped-image-display, block)');
123
+ cropImgCanvas.style.setProperty('margin', 'var(--cropped-image-margin, auto)');
117
124
  };
118
125
 
119
126
  return Object.assign(cropImgCanvas, {
120
127
  cleanup,
121
128
  showBorder: () => {
122
- cropImgCanvas.style.border = '3px solid red';
123
- cropImgCanvas.style.borderRadius = '10px';
129
+ const borderWidth = `var(--cropped-image-border-width, ${defaultStyles.borderWidth})`;
130
+ const borderColor = `var(--cropped-image-border-color-error, ${defaultStyles.borderColorError})`;
131
+ const borderRadius = `var(--cropped-image-border-radius, ${defaultStyles.borderRadius})`;
132
+ cropImgCanvas.style.setProperty('border', `${borderWidth} solid ${borderColor}`);
133
+ cropImgCanvas.style.setProperty('border-radius', borderRadius);
124
134
  },
125
135
  hideBorder: () => {
126
- cropImgCanvas.style.border = 'none';
127
- cropImgCanvas.style.borderRadius = '0';
136
+ cropImgCanvas.style.setProperty('border', 'var(--cropped-image-border-hidden, none)');
137
+ cropImgCanvas.style.setProperty('border-radius', 'var(--cropped-image-border-radius-hidden, 0)');
128
138
  },
129
139
  showSuccessBorder: () => {
130
- cropImgCanvas.style.border = '3px solid #00FA6C';
131
- cropImgCanvas.style.borderRadius = '10px';
140
+ const borderWidth = `var(--cropped-image-border-width, ${defaultStyles.borderWidth})`;
141
+ const borderColor = `var(--cropped-image-border-color-success, ${defaultStyles.borderColorSuccess})`;
142
+ const borderRadius = `var(--cropped-image-border-radius, ${defaultStyles.borderRadius})`;
143
+ cropImgCanvas.style.setProperty('border', `${borderWidth} solid ${borderColor}`);
144
+ cropImgCanvas.style.setProperty('border-radius', borderRadius);
132
145
  },
133
146
  setSquareDisplay,
134
147
  setRectangleDisplay: () => {
@@ -136,34 +149,36 @@ export const createCroppedImage = (container) => {
136
149
  const aspectRatio = cropImgCanvas.width / cropImgCanvas.height;
137
150
 
138
151
  // 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;
152
+ const baseMaxWidth = Math.min(500, window.innerWidth * 0.9);
153
+ const baseMaxHeight = window.innerHeight * 0.6;
154
+ const maxWidth = `var(--cropped-image-rectangle-max-width, ${baseMaxWidth}px)`;
155
+ const maxHeight = `var(--cropped-image-rectangle-max-height, ${baseMaxHeight}px)`;
141
156
 
142
157
  // Determine dimensions while preserving aspect ratio
143
158
  let width, height;
144
- if (aspectRatio > maxWidth / maxHeight) {
159
+ if (aspectRatio > baseMaxWidth / baseMaxHeight) {
145
160
  // Width is the limiting factor
146
- width = maxWidth;
161
+ width = baseMaxWidth;
147
162
  height = width / aspectRatio;
148
163
  } else {
149
164
  // Height is the limiting factor
150
- height = maxHeight;
165
+ height = baseMaxHeight;
151
166
  width = height * aspectRatio;
152
167
  }
153
168
 
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
169
+ // Apply styles with CSS variables
170
+ cropImgCanvas.style.setProperty('width', `var(--cropped-image-rectangle-width, ${width}px)`);
171
+ cropImgCanvas.style.setProperty('height', `var(--cropped-image-rectangle-height, ${height}px)`);
172
+ cropImgCanvas.style.setProperty('max-width', `var(--cropped-image-rectangle-max-width, ${width}px)`);
173
+ cropImgCanvas.style.setProperty('max-height', `var(--cropped-image-rectangle-max-height, ${height}px)`);
174
+ cropImgCanvas.style.setProperty('position', 'var(--cropped-image-rectangle-position, fixed)');
175
+ cropImgCanvas.style.setProperty('top', 'var(--cropped-image-rectangle-top, 50%)');
176
+ cropImgCanvas.style.setProperty('left', 'var(--cropped-image-rectangle-left, 50%)');
177
+ cropImgCanvas.style.setProperty('transform', 'var(--cropped-image-rectangle-transform, translate(-50%, -50%))');
178
+ cropImgCanvas.style.setProperty('object-fit', 'var(--cropped-image-object-fit, contain)');
179
+ cropImgCanvas.style.setProperty('display', 'var(--cropped-image-display, block)');
180
+ cropImgCanvas.style.setProperty('margin', 'var(--cropped-image-margin, auto)');
181
+ cropImgCanvas.style.setProperty('border-radius', `var(--cropped-image-border-radius-rectangle, ${defaultStyles.borderRadiusRectangle})`);
167
182
  }
168
183
  });
169
184
  };