@smileid/web-components 2.0.2 → 10.0.0

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.
Files changed (125) hide show
  1. package/dist/DocumentCaptureScreens-Dwl7UqVH.js +1534 -0
  2. package/dist/DocumentCaptureScreens-Dwl7UqVH.js.map +1 -0
  3. package/dist/EndUserConsent-C5hZdJzH.js +715 -0
  4. package/dist/EndUserConsent-C5hZdJzH.js.map +1 -0
  5. package/dist/Navigation-juBE4qOw.js +136 -0
  6. package/dist/Navigation-juBE4qOw.js.map +1 -0
  7. package/dist/PoweredBySmileId-CxbaihMu.js +33 -0
  8. package/dist/PoweredBySmileId-CxbaihMu.js.map +1 -0
  9. package/dist/SelfieCaptureScreens-CQc251hz.js +7618 -0
  10. package/dist/SelfieCaptureScreens-CQc251hz.js.map +1 -0
  11. package/dist/SignaturePad-C7MtmT8m.js +324 -0
  12. package/dist/SignaturePad-C7MtmT8m.js.map +1 -0
  13. package/dist/TotpConsent-CQU5jQi4.js +730 -0
  14. package/dist/TotpConsent-CQU5jQi4.js.map +1 -0
  15. package/dist/combobox.js +300 -0
  16. package/dist/combobox.js.map +1 -0
  17. package/dist/document.js +5 -0
  18. package/dist/document.js.map +1 -0
  19. package/dist/end-user-consent.js +5 -0
  20. package/dist/end-user-consent.js.map +1 -0
  21. package/dist/main.js +22 -0
  22. package/dist/main.js.map +1 -0
  23. package/dist/navigation.js +5 -0
  24. package/dist/navigation.js.map +1 -0
  25. package/dist/package-Oi2Yil3b.js +105 -0
  26. package/dist/package-Oi2Yil3b.js.map +1 -0
  27. package/dist/selfie.js +5 -0
  28. package/dist/selfie.js.map +1 -0
  29. package/dist/signature-pad.js +5 -0
  30. package/dist/signature-pad.js.map +1 -0
  31. package/dist/smart-camera-web.js +303 -0
  32. package/dist/smart-camera-web.js.map +1 -0
  33. package/dist/styles-BUWNxWeQ.js +406 -0
  34. package/dist/styles-BUWNxWeQ.js.map +1 -0
  35. package/dist/totp-consent.js +5 -0
  36. package/dist/totp-consent.js.map +1 -0
  37. package/dist/types/combobox.d.ts +21 -0
  38. package/dist/types/document.d.ts +21 -0
  39. package/dist/types/end-user-consent.d.ts +21 -0
  40. package/dist/types/main.d.ts +331 -0
  41. package/dist/types/navigation.d.ts +21 -0
  42. package/dist/types/selfie.d.ts +21 -0
  43. package/dist/types/signature-pad.d.ts +21 -0
  44. package/dist/types/smart-camera-web.d.ts +21 -0
  45. package/dist/types/totp-consent.d.ts +21 -0
  46. package/{src → lib}/components/selfie/src/SelfieCaptureScreens.js +188 -37
  47. package/{src → lib}/components/selfie/src/index.js +0 -2
  48. package/{src → lib}/components/selfie/src/selfie-capture/SelfieCapture.js +3 -3
  49. package/{src → lib}/components/selfie/src/selfie-capture-review/SelfieCaptureReview.js +0 -7
  50. package/lib/components/selfie/src/selfie-capture-wrapper/SelfieCaptureWrapper.tsx +227 -0
  51. package/lib/components/selfie/src/selfie-capture-wrapper/index.ts +1 -0
  52. package/lib/components/selfie/src/smartselfie-capture/OvalProgress.tsx +81 -0
  53. package/lib/components/selfie/src/smartselfie-capture/SmartSelfieCapture.tsx +224 -0
  54. package/lib/components/selfie/src/smartselfie-capture/components/AlertDisplay.tsx +34 -0
  55. package/lib/components/selfie/src/smartselfie-capture/components/CameraPreview.tsx +97 -0
  56. package/lib/components/selfie/src/smartselfie-capture/components/CaptureControls.tsx +74 -0
  57. package/lib/components/selfie/src/smartselfie-capture/components/index.ts +3 -0
  58. package/lib/components/selfie/src/smartselfie-capture/constants.ts +23 -0
  59. package/lib/components/selfie/src/smartselfie-capture/hooks/index.ts +2 -0
  60. package/lib/components/selfie/src/smartselfie-capture/hooks/useCamera.ts +94 -0
  61. package/lib/components/selfie/src/smartselfie-capture/hooks/useFaceCapture.ts +558 -0
  62. package/lib/components/selfie/src/smartselfie-capture/index.ts +1 -0
  63. package/lib/components/selfie/src/smartselfie-capture/utils/alertMessages.ts +12 -0
  64. package/lib/components/selfie/src/smartselfie-capture/utils/canvas.ts +105 -0
  65. package/lib/components/selfie/src/smartselfie-capture/utils/faceDetection.ts +129 -0
  66. package/lib/components/selfie/src/smartselfie-capture/utils/imageCapture.ts +64 -0
  67. package/lib/components/selfie/src/smartselfie-capture/utils/index.ts +4 -0
  68. package/lib/components/selfie/src/smartselfie-capture/utils/mediapipeManager.ts +60 -0
  69. package/{src → lib}/components/signature-pad/package.json +1 -1
  70. package/{src → lib}/components/smart-camera-web/src/README.md +0 -1
  71. package/package.json +75 -24
  72. package/src/index.js +0 -5
  73. /package/{src → lib}/components/README.md +0 -0
  74. /package/{src → lib}/components/attribution/PoweredBySmileId.js +0 -0
  75. /package/{src → lib}/components/camera-permission/CameraPermission.js +0 -0
  76. /package/{src → lib}/components/camera-permission/CameraPermission.stories.js +0 -0
  77. /package/{src → lib}/components/combobox/src/Combobox.js +0 -0
  78. /package/{src → lib}/components/combobox/src/index.js +0 -0
  79. /package/{src → lib}/components/document/src/DocumentCaptureScreens.js +0 -0
  80. /package/{src → lib}/components/document/src/DocumentCaptureScreens.stories.js +0 -0
  81. /package/{src → lib}/components/document/src/README.md +0 -0
  82. /package/{src → lib}/components/document/src/document-capture/DocumentCapture.js +0 -0
  83. /package/{src → lib}/components/document/src/document-capture/DocumentCapture.stories.js +0 -0
  84. /package/{src → lib}/components/document/src/document-capture/README.md +0 -0
  85. /package/{src → lib}/components/document/src/document-capture/index.js +0 -0
  86. /package/{src → lib}/components/document/src/document-capture-instructions/DocumentCaptureInstructions.js +0 -0
  87. /package/{src → lib}/components/document/src/document-capture-instructions/DocumentCaptureInstructions.stories.js +0 -0
  88. /package/{src → lib}/components/document/src/document-capture-instructions/README.md +0 -0
  89. /package/{src → lib}/components/document/src/document-capture-instructions/index.js +0 -0
  90. /package/{src → lib}/components/document/src/document-capture-review/DocumentCaptureReview.js +0 -0
  91. /package/{src → lib}/components/document/src/document-capture-review/DocumentCaptureReview.stories.js +0 -0
  92. /package/{src → lib}/components/document/src/document-capture-review/README.md +0 -0
  93. /package/{src → lib}/components/document/src/document-capture-review/index.js +0 -0
  94. /package/{src → lib}/components/document/src/index.js +0 -0
  95. /package/{src → lib}/components/end-user-consent/src/EndUserConsent.js +0 -0
  96. /package/{src → lib}/components/end-user-consent/src/EndUserConsent.stories.js +0 -0
  97. /package/{src → lib}/components/end-user-consent/src/index.js +0 -0
  98. /package/{src → lib}/components/navigation/src/Navigation.js +0 -0
  99. /package/{src → lib}/components/navigation/src/Navigation.stories.js +0 -0
  100. /package/{src → lib}/components/navigation/src/index.js +0 -0
  101. /package/{src → lib}/components/selfie/README.md +0 -0
  102. /package/{src → lib}/components/selfie/src/SelfieCaptureScreens.stories.js +0 -0
  103. /package/{src → lib}/components/selfie/src/selfie-capture/SelfieCapture.stories.js +0 -0
  104. /package/{src → lib}/components/selfie/src/selfie-capture/index.js +0 -0
  105. /package/{src → lib}/components/selfie/src/selfie-capture-instructions/SelfieCaptureInstructions.js +0 -0
  106. /package/{src → lib}/components/selfie/src/selfie-capture-instructions/SelfieCaptureInstructions.stories.js +0 -0
  107. /package/{src → lib}/components/selfie/src/selfie-capture-instructions/index.js +0 -0
  108. /package/{src → lib}/components/selfie/src/selfie-capture-review/SelfieCaptureReview.stories.js +0 -0
  109. /package/{src → lib}/components/selfie/src/selfie-capture-review/index.js +0 -0
  110. /package/{src → lib}/components/signature-pad/package-lock.json +0 -0
  111. /package/{src → lib}/components/signature-pad/src/SignaturePad.js +0 -0
  112. /package/{src → lib}/components/signature-pad/src/SignaturePad.stories.js +0 -0
  113. /package/{src → lib}/components/signature-pad/src/index.js +0 -0
  114. /package/{src → lib}/components/smart-camera-web/src/SmartCameraWeb.js +0 -0
  115. /package/{src → lib}/components/smart-camera-web/src/SmartCameraWeb.stories.js +0 -0
  116. /package/{src → lib}/components/totp-consent/src/TotpConsent.js +0 -0
  117. /package/{src → lib}/components/totp-consent/src/index.js +0 -0
  118. /package/{src → lib}/domain/camera/src/README.md +0 -0
  119. /package/{src → lib}/domain/camera/src/SmartCamera.js +0 -0
  120. /package/{src → lib}/domain/constants/src/Constants.js +0 -0
  121. /package/{src → lib}/domain/file-upload/README.md +0 -0
  122. /package/{src → lib}/domain/file-upload/src/SmartFileUpload.js +0 -0
  123. /package/{src → lib}/styles/README.md +0 -0
  124. /package/{src → lib}/styles/src/styles.js +0 -0
  125. /package/{src → lib}/styles/src/typography.js +0 -0
@@ -1,6 +1,6 @@
1
- import './selfie-capture';
2
1
  import './selfie-capture-instructions';
3
2
  import './selfie-capture-review';
3
+ import './selfie-capture-wrapper/index.ts';
4
4
  import SmartCamera from '../../../domain/camera/src/SmartCamera';
5
5
  import styles from '../../../styles/src/styles';
6
6
  import packageJson from '../../../../package.json';
@@ -37,10 +37,76 @@ async function getPermissions(captureScreen, facingMode = 'user') {
37
37
  }
38
38
  }
39
39
 
40
+ const cropImageFromDataUri = (
41
+ dataUri,
42
+ cropPercentX = 0,
43
+ cropPercentY = 0,
44
+ quality = 0.9,
45
+ ) =>
46
+ new Promise((resolve, reject) => {
47
+ if (!dataUri || typeof dataUri !== 'string') {
48
+ reject(new Error('Invalid data URI provided'));
49
+ return;
50
+ }
51
+
52
+ if (
53
+ cropPercentX < 0 ||
54
+ cropPercentX >= 99 ||
55
+ cropPercentY < 0 ||
56
+ cropPercentY >= 99
57
+ ) {
58
+ reject(new Error('Crop percentages must be between 0 and 99'));
59
+ return;
60
+ }
61
+
62
+ const img = new Image();
63
+
64
+ img.onload = () => {
65
+ try {
66
+ const canvas = document.createElement('canvas');
67
+ const ctx = canvas.getContext('2d');
68
+
69
+ const originalWidth = img.width;
70
+ const originalHeight = img.height;
71
+ const cropAmountX = (originalWidth * cropPercentX) / 100;
72
+ const cropAmountY = (originalHeight * cropPercentY) / 100;
73
+
74
+ const newWidth = originalWidth - cropAmountX * 2;
75
+ const newHeight = originalHeight - cropAmountY * 2;
76
+ canvas.width = newWidth;
77
+ canvas.height = newHeight;
78
+
79
+ ctx.drawImage(
80
+ img,
81
+ cropAmountX,
82
+ cropAmountY,
83
+ newWidth,
84
+ newHeight,
85
+ 0,
86
+ 0,
87
+ newWidth,
88
+ newHeight,
89
+ );
90
+
91
+ const croppedDataUri = canvas.toDataURL('image/jpeg', quality);
92
+ resolve(croppedDataUri);
93
+ } catch (error) {
94
+ reject(new Error(`Failed to process image: ${error.message}`));
95
+ }
96
+ };
97
+
98
+ img.onerror = () => {
99
+ reject(new Error('Failed to load image from data URI'));
100
+ };
101
+
102
+ img.src = dataUri;
103
+ });
104
+
40
105
  class SelfieCaptureScreens extends HTMLElement {
41
106
  constructor() {
42
107
  super();
43
108
  this.activeScreen = null;
109
+ this._remountKey = 0; // Counter for forcing wrapper remounts
44
110
  smartCameraWeb?.dispatchEvent(new CustomEvent('metadata.initialize'));
45
111
  }
46
112
 
@@ -49,7 +115,7 @@ class SelfieCaptureScreens extends HTMLElement {
49
115
  ${styles(this.themeColor)}
50
116
  <div>
51
117
  <selfie-capture-instructions theme-color='${this.themeColor}' ${this.showNavigation} ${this.hideAttribution} ${this.hideBack} hidden></selfie-capture-instructions>
52
- <selfie-capture theme-color='${this.themeColor}' ${this.showNavigation} ${this.allowAgentMode} ${this.allowAgentModeTests} ${this.hideAttribution} ${this.disableImageTests} hidden></selfie-capture>
118
+ <selfie-capture-wrapper theme-color='${this.themeColor}' ${this.showNavigation} ${this.allowAgentMode} ${this.allowAgentModeTests} ${this.hideAttribution} ${this.disableImageTests} key="${this._remountKey}" start-countdown="false" hidden></selfie-capture-wrapper>
53
119
  <selfie-capture-review theme-color='${this.themeColor}' ${this.showNavigation} ${this.hideAttribution} hidden></selfie-capture-review>
54
120
  </div>
55
121
  `;
@@ -60,9 +126,8 @@ class SelfieCaptureScreens extends HTMLElement {
60
126
  libraryVersion: COMPONENTS_VERSION,
61
127
  },
62
128
  };
63
-
64
129
  this.selfieInstruction = this.querySelector('selfie-capture-instructions');
65
- this.selfieCapture = this.querySelector('selfie-capture');
130
+ this.selfieCapture = this.querySelector('selfie-capture-wrapper');
66
131
  this.selfieReview = this.querySelector('selfie-capture-review');
67
132
 
68
133
  if (this.hideInstructions && !this.hasAttribute('hidden')) {
@@ -124,27 +189,8 @@ class SelfieCaptureScreens extends HTMLElement {
124
189
  this.handleBackEvents();
125
190
  },
126
191
  );
127
-
128
- this.selfieCapture.addEventListener('selfie-capture.cancelled', () => {
129
- this.selfieCapture.reset();
130
- SmartCamera.stopMedia();
131
- if (this.hideInstructions) {
132
- this.handleBackEvents();
133
- return;
134
- }
135
-
136
- this.setActiveScreen(this.selfieInstruction);
137
- });
138
-
139
- this.selfieCapture.addEventListener('selfie-capture.publish', (event) => {
140
- smartCameraWeb?.dispatchEvent(
141
- new CustomEvent('metadata.selfie-capture-end'),
142
- );
143
- this.selfieReview.setAttribute('data-image', event.detail.referenceImage);
144
- this._data.images = event.detail.images;
145
- SmartCamera.stopMedia();
146
- this.setActiveScreen(this.selfieReview);
147
- });
192
+ // Setup selfie-wrapper event listeners
193
+ this.setupSelfieWrapperEventListeners();
148
194
 
149
195
  this.selfieReview.addEventListener(
150
196
  'selfie-capture-review.rejected',
@@ -154,6 +200,10 @@ class SelfieCaptureScreens extends HTMLElement {
154
200
  );
155
201
  this.selfieReview.removeAttribute('data-image');
156
202
  this._data.images = [];
203
+
204
+ // Force remount by incrementing key
205
+ this.forceWrapperRemount();
206
+
157
207
  if (this.hideInstructions) {
158
208
  this.setActiveScreen(this.selfieCapture);
159
209
  await getPermissions(this.selfieCapture, this.getAgentMode());
@@ -182,6 +232,113 @@ class SelfieCaptureScreens extends HTMLElement {
182
232
  );
183
233
  }
184
234
 
235
+ // Force remount of selfie-capture-wrapper component for clean state
236
+ forceWrapperRemount() {
237
+ this._remountKey++;
238
+ const container = this.querySelector('div');
239
+ const oldSelfieCapture = this.selfieCapture;
240
+
241
+ // Create new selfie-capture-wrapper element with same attributes
242
+ const newSelfieCapture = document.createElement('selfie-capture-wrapper');
243
+ newSelfieCapture.setAttribute('theme-color', this.themeColor);
244
+ newSelfieCapture.setAttribute('key', this._remountKey.toString());
245
+ newSelfieCapture.setAttribute('start-countdown', 'false');
246
+
247
+ // Copy all the correct attributes based on the getter logic
248
+ const showNav = this.hasAttribute('show-navigation');
249
+ const allowAgent = this.getAttribute('allow-agent-mode') === 'true';
250
+ const allowAgentTests = this.hasAttribute('show-agent-mode-for-tests');
251
+ const hideAttr = this.hasAttribute('hide-attribution');
252
+ const disableTests = this.hasAttribute('disable-image-tests');
253
+
254
+ if (showNav) newSelfieCapture.setAttribute('show-navigation', '');
255
+ if (allowAgent) newSelfieCapture.setAttribute('allow-agent-mode', 'true');
256
+ if (allowAgentTests)
257
+ newSelfieCapture.setAttribute('show-agent-mode-for-tests', '');
258
+ if (hideAttr) newSelfieCapture.setAttribute('hide-attribution', '');
259
+ if (disableTests) newSelfieCapture.setAttribute('disable-image-tests', '');
260
+ newSelfieCapture.setAttribute('hidden', '');
261
+
262
+ // Replace old element with new one
263
+ container.replaceChild(newSelfieCapture, oldSelfieCapture);
264
+
265
+ // Update reference
266
+ this.selfieCapture = newSelfieCapture;
267
+
268
+ // Re-add event listeners for the new element
269
+ this.setupSelfieWrapperEventListeners();
270
+ }
271
+
272
+ // Override setActiveScreen to enable countdown when selfie-capture is active
273
+ setActiveScreen(screen) {
274
+ this.activeScreen?.setAttribute('hidden', '');
275
+ screen.removeAttribute('hidden');
276
+ this.activeScreen = screen;
277
+
278
+ // If activating selfie-capture-wrapper, enable the countdown and ensure permissions
279
+ if (screen === this.selfieCapture) {
280
+ screen.setAttribute('start-countdown', 'true');
281
+ getPermissions(this.selfieCapture, this.getAgentMode());
282
+ } else if (this.selfieCapture) {
283
+ // Disable countdown when not on capture screen
284
+ this.selfieCapture.setAttribute('start-countdown', 'false');
285
+ }
286
+ }
287
+
288
+ setupSelfieWrapperEventListeners() {
289
+ window.addEventListener('selfie-capture.cancelled', () => {
290
+ SmartCamera.stopMedia();
291
+
292
+ // Force remount of selfie-capture-wrapper for clean state on next visit
293
+ this.forceWrapperRemount();
294
+
295
+ if (this.hideInstructions) {
296
+ this.handleBackEvents();
297
+ return;
298
+ }
299
+
300
+ this.setActiveScreen(this.selfieInstruction);
301
+ });
302
+
303
+ // Add specific close event handler for selfie-capture-wrapper
304
+ window.addEventListener('selfie-capture.close', () => {
305
+ SmartCamera.stopMedia();
306
+
307
+ // Force remount of selfie-capture-wrapper for clean state on next visit
308
+ this.forceWrapperRemount();
309
+
310
+ this.handleCloseEvent();
311
+ });
312
+
313
+ window.addEventListener('selfie-capture.publish', async (event) => {
314
+ smartCameraWeb?.dispatchEvent(
315
+ new CustomEvent('metadata.selfie-capture-end'),
316
+ );
317
+ this.selfieReview.setAttribute(
318
+ 'data-image',
319
+ await cropImageFromDataUri(event.detail.referenceImage, 20, 20),
320
+ );
321
+ this._data.images = event.detail.images;
322
+ SmartCamera.stopMedia();
323
+ this.setActiveScreen(this.selfieReview);
324
+ });
325
+
326
+ // Also listen for the publish event on the parent SelfieCaptureScreens element
327
+ // in case smartselfie-capture dispatches it there
328
+ this.addEventListener('selfie-capture.publish', async (event) => {
329
+ smartCameraWeb?.dispatchEvent(
330
+ new CustomEvent('metadata.selfie-capture-end'),
331
+ );
332
+ this.selfieReview.setAttribute(
333
+ 'data-image',
334
+ await cropImageFromDataUri(event.detail.referenceImage, 20, 20),
335
+ );
336
+ this._data.images = event.detail.images;
337
+ SmartCamera.stopMedia();
338
+ this.setActiveScreen(this.selfieReview);
339
+ });
340
+ }
341
+
185
342
  _publishSelectedImages() {
186
343
  this.dispatchEvent(
187
344
  new CustomEvent('selfie-capture-screens.publish', { detail: this._data }),
@@ -193,7 +350,7 @@ class SelfieCaptureScreens extends HTMLElement {
193
350
  }
194
351
 
195
352
  get hideAttribution() {
196
- return this.hasAttribute('hide-attribution') ? 'hide-attribution' : '';
353
+ return this.hasAttribute('hide-attribution') ? 'hide-attribution=""' : '';
197
354
  }
198
355
 
199
356
  get hideBackOfId() {
@@ -201,7 +358,7 @@ class SelfieCaptureScreens extends HTMLElement {
201
358
  }
202
359
 
203
360
  get showNavigation() {
204
- return this.hasAttribute('show-navigation') ? 'show-navigation' : '';
361
+ return this.hasAttribute('show-navigation') ? 'show-navigation=""' : '';
205
362
  }
206
363
 
207
364
  get inAgentMode() {
@@ -209,25 +366,25 @@ class SelfieCaptureScreens extends HTMLElement {
209
366
  }
210
367
 
211
368
  get allowAgentMode() {
212
- return this.inAgentMode ? "allow-agent-mode='true'" : '';
369
+ return this.inAgentMode ? 'allow-agent-mode="true"' : '';
213
370
  }
214
371
 
215
372
  get allowAgentModeTests() {
216
373
  return this.hasAttribute('show-agent-mode-for-tests')
217
- ? 'show-agent-mode-for-tests'
374
+ ? 'show-agent-mode-for-tests=""'
218
375
  : '';
219
376
  }
220
377
 
221
378
  get hideBack() {
222
379
  return this.hasAttribute('hide-back-to-host') ||
223
380
  this.hasAttribute('hide-back')
224
- ? 'hide-back'
381
+ ? 'hide-back=""'
225
382
  : '';
226
383
  }
227
384
 
228
385
  get disableImageTests() {
229
386
  return this.hasAttribute('disable-image-tests')
230
- ? 'disable-image-tests'
387
+ ? 'disable-image-tests=""'
231
388
  : '';
232
389
  }
233
390
 
@@ -235,12 +392,6 @@ class SelfieCaptureScreens extends HTMLElement {
235
392
  return this.getAttribute('theme-color') || '#001096';
236
393
  }
237
394
 
238
- setActiveScreen(screen) {
239
- this.activeScreen?.setAttribute('hidden', '');
240
- screen.removeAttribute('hidden');
241
- this.activeScreen = screen;
242
- }
243
-
244
395
  handleBackEvents() {
245
396
  this.dispatchEvent(new CustomEvent('selfie-capture-screens.cancelled'));
246
397
  }
@@ -1,5 +1,3 @@
1
1
  import SelfieCaptureScreens from './SelfieCaptureScreens';
2
- import SelfieCapture from './selfie-capture/SelfieCapture';
3
2
 
4
3
  export default SelfieCaptureScreens;
5
- export { SelfieCapture };
@@ -358,7 +358,7 @@ function templateString() {
358
358
  left: 50%;
359
359
  min-width: auto;
360
360
  position: absolute;
361
- top: calc(50% - 3px);
361
+ top: 50%;
362
362
  transform: translateX(-50%) translateY(50%);
363
363
  }
364
364
 
@@ -381,7 +381,7 @@ function templateString() {
381
381
  }
382
382
 
383
383
  .video-container video {
384
- min-height: 100%;
384
+ height: 150%;
385
385
  transform: scaleX(-1) translateX(50%) translateY(-50%);
386
386
  }
387
387
 
@@ -520,7 +520,7 @@ function templateString() {
520
520
  <div class='video-container'>
521
521
  <div class='video'>
522
522
  </div>
523
- <svg id="image-outline" width="215" height="245" viewBox="0 0 215 245" fill="none" xmlns="http://www.w3.org/2000/svg">
523
+ <svg id="image-outline" width="215" height="245" viewBox="0 0 215 245" fill="none" xmlns="http://www.w3.org/2000/svg" style="position: relative;">
524
524
  <path d="M210.981 122.838C210.981 188.699 164.248 241.268 107.55 241.268C50.853 241.268 4.12018 188.699 4.12018 122.838C4.12018 56.9763 50.853 4.40771 107.55 4.40771C164.248 4.40771 210.981 56.9763 210.981 122.838Z" stroke="${this.themeColor}" stroke-width="7.13965"/>
525
525
  </svg>
526
526
  <div id="smile-cta-box">
@@ -126,13 +126,6 @@ function templateString() {
126
126
  z-index: 1;
127
127
  block-size: 100%;
128
128
  }
129
-
130
- .selfie-container,
131
- .selfie-review-container.landscape {
132
- height: auto;
133
- clip-path: inset(15% 20% 20% 20% round 10px);
134
- overflow: hidden;
135
- }
136
129
 
137
130
  .selfie-container img {
138
131
  background-color: black;
@@ -0,0 +1,227 @@
1
+ import { useState, useEffect } from 'preact/hooks';
2
+ import { IconLoader2 } from '@tabler/icons-preact';
3
+ import register from 'preact-custom-element';
4
+ import type { FunctionComponent } from 'preact';
5
+
6
+ import { getBoolProp } from '@/utils/props';
7
+ import SmartSelfieCapture from '../smartselfie-capture/SmartSelfieCapture';
8
+ import '../selfie-capture/SelfieCapture';
9
+ import { getMediapipeInstance } from '../smartselfie-capture/utils/mediapipeManager';
10
+
11
+ declare const h: any;
12
+
13
+ interface Props {
14
+ timeout?: number;
15
+ interval?: number;
16
+ duration?: number;
17
+ 'theme-color'?: string;
18
+ 'show-navigation'?: string | boolean;
19
+ 'allow-agent-mode'?: string | boolean;
20
+ 'show-agent-mode-for-tests'?: string | boolean;
21
+ 'hide-attribution'?: string | boolean;
22
+ 'disable-image-tests'?: string | boolean;
23
+ key?: string;
24
+ 'start-countdown'?: string | boolean;
25
+ hidden?: string | boolean;
26
+ }
27
+
28
+ const SelfieCaptureWrapper: FunctionComponent<Props> = ({
29
+ timeout = 10000,
30
+ 'start-countdown': startCountdownProp = false,
31
+ hidden: hiddenProp = false,
32
+ ...props
33
+ }) => {
34
+ const hidden = getBoolProp(hiddenProp);
35
+ const startCountdown = getBoolProp(startCountdownProp);
36
+ const [mediapipeReady, setMediapipeReady] = useState(false);
37
+ const [loadingProgress, setLoadingProgress] = useState(0);
38
+ const [initialSessionCompleted, setInitialSessionCompleted] = useState(false);
39
+ const [mediapipeLoading, setMediapipeLoading] = useState(false);
40
+ const [usingSelfieCapture, setUsingSelfieCapture] = useState(false);
41
+
42
+ useEffect(() => {
43
+ if (mediapipeReady || mediapipeLoading) return;
44
+
45
+ const loadMediapipe = async () => {
46
+ setMediapipeLoading(true);
47
+ try {
48
+ await getMediapipeInstance();
49
+ setMediapipeReady(true);
50
+ } catch (error) {
51
+ console.error('Failed to load Mediapipe:', error);
52
+ }
53
+ setMediapipeLoading(false);
54
+ };
55
+
56
+ loadMediapipe();
57
+ }, [mediapipeReady, mediapipeLoading]);
58
+
59
+ useEffect(() => {
60
+ if (hidden || !startCountdown || mediapipeReady) return undefined;
61
+
62
+ const timer = setInterval(() => {
63
+ setLoadingProgress((prev: number) => Math.min(prev + 1, 100));
64
+ }, timeout / 100);
65
+
66
+ return () => {
67
+ clearInterval(timer);
68
+ };
69
+ }, [hidden, startCountdown, timeout, mediapipeReady]);
70
+
71
+ useEffect(() => {
72
+ if (hidden || mediapipeReady || loadingProgress < 100) return undefined;
73
+
74
+ const setupEventForwarding = () => {
75
+ const selfieCapture = document.querySelector('selfie-capture');
76
+ if (
77
+ selfieCapture &&
78
+ !selfieCapture.hasAttribute('data-backup-events-setup')
79
+ ) {
80
+ selfieCapture.setAttribute('data-backup-events-setup', 'true');
81
+
82
+ const forwardEvent = (event: Event) => {
83
+ const customEvent = event as CustomEvent;
84
+ window.dispatchEvent(
85
+ new CustomEvent(customEvent.type, {
86
+ detail: customEvent.detail,
87
+ bubbles: true,
88
+ }),
89
+ );
90
+ };
91
+
92
+ selfieCapture.addEventListener('selfie-capture.publish', forwardEvent);
93
+ selfieCapture.addEventListener(
94
+ 'selfie-capture.cancelled',
95
+ forwardEvent,
96
+ );
97
+ selfieCapture.addEventListener('selfie-capture.close', forwardEvent);
98
+
99
+ return () => {
100
+ selfieCapture.removeEventListener(
101
+ 'selfie-capture.publish',
102
+ forwardEvent,
103
+ );
104
+ selfieCapture.removeEventListener(
105
+ 'selfie-capture.cancelled',
106
+ forwardEvent,
107
+ );
108
+ selfieCapture.removeEventListener(
109
+ 'selfie-capture.close',
110
+ forwardEvent,
111
+ );
112
+ };
113
+ }
114
+ return undefined;
115
+ };
116
+
117
+ const timeoutId = setTimeout(setupEventForwarding, 200);
118
+ return () => {
119
+ clearTimeout(timeoutId);
120
+ };
121
+ }, [hidden, mediapipeReady, loadingProgress]);
122
+
123
+ if (hidden) {
124
+ return null;
125
+ }
126
+
127
+ // on retakes, prefer SmartSelfieCapture if Mediapipe is ready
128
+ if (initialSessionCompleted && mediapipeReady && !usingSelfieCapture) {
129
+ return <SmartSelfieCapture {...props} />;
130
+ }
131
+
132
+ // use SmartSelfieCapture if mediapipe loads
133
+ if (!initialSessionCompleted && mediapipeReady && !usingSelfieCapture) {
134
+ return <SmartSelfieCapture {...props} />;
135
+ }
136
+
137
+ if (loadingProgress >= 100) {
138
+ if (!usingSelfieCapture) {
139
+ setUsingSelfieCapture(true);
140
+ }
141
+
142
+ const propsWithoutHidden = { ...props };
143
+ delete (propsWithoutHidden as any).hidden;
144
+
145
+ const selfieCapture = h('selfie-capture', {
146
+ ...propsWithoutHidden,
147
+ ref: (el: HTMLElement) => {
148
+ if (el && !el.hasAttribute('data-events-setup')) {
149
+ el.setAttribute('data-events-setup', 'true');
150
+
151
+ const forwardEvent = (event: Event) => {
152
+ const customEvent = event as CustomEvent;
153
+
154
+ if (
155
+ customEvent.type === 'selfie-capture.publish' ||
156
+ customEvent.type === 'selfie-capture.cancelled' ||
157
+ customEvent.type === 'selfie-capture.close'
158
+ ) {
159
+ setInitialSessionCompleted(true);
160
+ }
161
+
162
+ window.dispatchEvent(
163
+ new CustomEvent(customEvent.type, {
164
+ detail: customEvent.detail,
165
+ bubbles: true,
166
+ }),
167
+ );
168
+ };
169
+
170
+ el.addEventListener('selfie-capture.publish', forwardEvent);
171
+ el.addEventListener('selfie-capture.cancelled', forwardEvent);
172
+ el.addEventListener('selfie-capture.close', forwardEvent);
173
+ }
174
+ },
175
+ });
176
+
177
+ return selfieCapture;
178
+ }
179
+
180
+ return (
181
+ <div style={{ textAlign: 'center', marginTop: '20%' }}>
182
+ <div
183
+ style={{
184
+ marginBottom: '16px',
185
+ display: 'flex',
186
+ justifyContent: 'center',
187
+ }}
188
+ >
189
+ <IconLoader2
190
+ size={48}
191
+ style={{ animation: 'spin 1s linear infinite' }}
192
+ />
193
+ </div>
194
+ <p>Loading... {loadingProgress}%</p>
195
+ <style>{`
196
+ @keyframes spin {
197
+ from { transform: rotate(0deg); }
198
+ to { transform: rotate(360deg); }
199
+ }
200
+ `}</style>
201
+ </div>
202
+ );
203
+ };
204
+
205
+ if (!customElements.get('selfie-capture-wrapper')) {
206
+ register(
207
+ SelfieCaptureWrapper,
208
+ 'selfie-capture-wrapper',
209
+ [
210
+ 'timeout',
211
+ 'interval',
212
+ 'duration',
213
+ 'theme-color',
214
+ 'show-navigation',
215
+ 'allow-agent-mode',
216
+ 'show-agent-mode-for-tests',
217
+ 'hide-attribution',
218
+ 'disable-image-tests',
219
+ 'key',
220
+ 'start-countdown',
221
+ 'hidden',
222
+ ],
223
+ { shadow: true },
224
+ );
225
+ }
226
+
227
+ export default SelfieCaptureWrapper;
@@ -0,0 +1 @@
1
+ export { default as SelfieCaptureWrapper } from './SelfieCaptureWrapper';
@@ -0,0 +1,81 @@
1
+ import { useEffect, useRef } from 'preact/hooks';
2
+
3
+ interface OvalProgressProps {
4
+ progress: number;
5
+ duration?: number;
6
+ themeColor?: string;
7
+ }
8
+
9
+ const OvalProgress = ({
10
+ progress,
11
+ duration = 1000,
12
+ themeColor = '#001096',
13
+ }: OvalProgressProps) => {
14
+ const pathRef = useRef<SVGPathElement>(null);
15
+ const prevProgress = useRef(progress);
16
+
17
+ useEffect(() => {
18
+ const path = pathRef.current;
19
+ if (!path) return;
20
+
21
+ const pathLength = path.getTotalLength();
22
+ path.style.opacity = progress > 0 ? '1' : '0';
23
+ const fromOffset = pathLength * (1 - prevProgress.current);
24
+ const toOffset = pathLength * (1 - progress);
25
+
26
+ // If no change, skip
27
+ if (fromOffset === toOffset) return;
28
+
29
+ path.style.transition = 'none';
30
+ path.style.strokeDasharray = `${pathLength} ${pathLength}`;
31
+ path.style.strokeDashoffset = `${fromOffset}`;
32
+
33
+ // Force style flush
34
+ path.getBoundingClientRect();
35
+
36
+ path.style.transition = `stroke-dashoffset ${duration}ms ease-out`;
37
+ path.style.strokeDashoffset = `${toOffset}`;
38
+
39
+ prevProgress.current = progress;
40
+ }, [progress, duration]);
41
+
42
+ return (
43
+ <div
44
+ style={{
45
+ position: 'absolute',
46
+ top: '0',
47
+ left: '0',
48
+ width: '100%',
49
+ height: '100%',
50
+ pointerEvents: 'none',
51
+ }}
52
+ >
53
+ <svg
54
+ viewBox="0 0 285 380"
55
+ preserveAspectRatio="xMidYMid meet"
56
+ style={{ width: '100%', height: '100%' }}
57
+ >
58
+ {/* id is referenced by parent */}
59
+ <clipPath id="selfie-clip-path" clipPathUnits="objectBoundingBox">
60
+ <path d="M0.085 0.382 C0.087 0.357 0.092 0.294 0.131 0.236 C0.200 0.133 0.340 0.063 0.501 0.063 C0.730 0.063 0.915 0.205 0.915 0.382 C0.915 0.424 0.899 0.513 0.891 0.549 C0.882 0.588 0.871 0.626 0.857 0.664 C0.792 0.825 0.639 0.937 0.501 0.937 C0.314 0.937 0.182 0.755 0.144 0.666 C0.126 0.624 0.110 0.557 0.107 0.547 C0.092 0.485 0.081 0.439 0.085 0.382 Z" />
61
+ </clipPath>
62
+ <path
63
+ d="M142.693 24C208.319 24 261 77.97 261 145.008C261 160.97 256.319 194.788 254.129 208.356C251.64 223.188 248.348 237.875 244.27 252.35C225.747 313.203 182.328 356 142.693 356C89.414 356 51.871 286.667 41.016 252.948C35.937 236.987 31.356 211.748 30.559 207.857C26.277 184.114 22.991 166.556 24.285 145.008C24.883 135.631 26.277 111.789 37.431 89.742C57.049 50.636 96.983 24 142.693 24Z"
64
+ stroke={themeColor}
65
+ fill="none"
66
+ style={{ strokeWidth: '8' }}
67
+ />
68
+ <path
69
+ ref={pathRef}
70
+ d="M142.693 24C208.319 24 261 77.97 261 145.008C261 160.97 256.319 194.788 254.129 208.356C251.64 223.188 248.348 237.875 244.27 252.35C225.747 313.203 182.328 356 142.693 356C89.414 356 51.871 286.667 41.016 252.948C35.937 236.987 31.356 211.748 30.559 207.857C26.277 184.114 22.991 166.556 24.285 145.008C24.883 135.631 26.277 111.789 37.431 89.742C57.049 50.636 96.983 24 142.693 24Z"
71
+ stroke="#22c55e"
72
+ style={{ strokeWidth: '8' }}
73
+ fill="none"
74
+ strokeLinecap="round"
75
+ />
76
+ </svg>
77
+ </div>
78
+ );
79
+ };
80
+
81
+ export default OvalProgress;