@didit-protocol/sdk-web 0.5.1 → 0.5.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Didit SDK for Web v0.5.1
2
+ * Didit SDK for Web v0.5.3
3
3
  * (c) 2026 Didit
4
4
  * @license MIT
5
5
  */
@@ -22,12 +22,13 @@ const CSS_CLASSES = {
22
22
  closeIcon: "didit-close-icon",
23
23
  closeIconLegacy: "didit-close-icon-legacy",
24
24
  flowSized: "didit-flow-sized",
25
+ sizeAnimated: "didit-size-animated",
25
26
  loading: "didit-loading",
26
27
  confirmOverlay: "didit-confirm-overlay",
27
28
  confirmBox: "didit-confirm-box",
28
29
  embedded: "didit-embedded"
29
30
  };
30
- const SDK_VERSION = "0.5.1";
31
+ const SDK_VERSION = "0.5.3";
31
32
  /**
32
33
  * The permissions the verification iframe gets, in a modal and embedded:
33
34
  * camera and microphone for capture, clipboard-write for the flow's copy
@@ -55,7 +56,7 @@ const PRESENTATION_QUERY_PARAMS = {
55
56
  };
56
57
  /**
57
58
  * Posted by the hosted flow when it lays itself out for the modal, with
58
- * `data: { contentHeight, colorScheme?, dir? }`. The modal then grows to the
59
+ * `data: { contentHeight, colorScheme?, dir?, kind? }` (`kind` is `handoff` or `step`, `step` when missing). The modal then grows to the
59
60
  * handoff card on a computer and follows the content height in a narrow
60
61
  * window. Handled by the modal and never delivered to `onEvent`.
61
62
  */
@@ -689,6 +690,10 @@ function getTranslations(language) {
689
690
  return translationsMap[language] ?? EN;
690
691
  }
691
692
 
693
+ /** The length of the one animation when the flow moves from the handoff card to a step or back. */
694
+ const SIZE_ANIMATION_MS = 300;
695
+ /** How long the modal waits for the first layout before it shows at step size, so it can never hang. */
696
+ const FIRST_LAYOUT_TIMEOUT_MS = 3000;
692
697
  class VerificationModal {
693
698
  constructor(configuration, callbacks) {
694
699
  this.state = {
@@ -706,9 +711,13 @@ class VerificationModal {
706
711
  this.boundHandleKeydown = null;
707
712
  this.boundHandleFocusChange = null;
708
713
  this.confirmationFocusTimeout = null;
714
+ this.firstLayoutTimeout = null;
715
+ this.sizeTimeout = null;
709
716
  this.embedded = false;
710
717
  this.embeddedContainer = null;
711
718
  this.language = "en";
719
+ /** The page's own background colours, kept while a full-screen modal paints over them. */
720
+ this.pageBackground = null;
712
721
  /** body.style.overflow value observed right before this modal locked scroll, restored on close(). */
713
722
  this.previousBodyOverflow = null;
714
723
  this.modalId = generateModalId();
@@ -753,9 +762,9 @@ class VerificationModal {
753
762
  .${CSS_CLASSES.container} {
754
763
  position: relative;
755
764
  width: 100%;
756
- max-width: 500px;
757
- max-height: 90vh;
758
- max-height: 90dvh;
765
+ max-width: 440px;
766
+ height: min(860px, calc(100vh - 2rem));
767
+ height: min(860px, calc(100dvh - 2rem));
759
768
  border-radius: 16px;
760
769
  overflow: hidden;
761
770
  background: transparent;
@@ -767,9 +776,7 @@ class VerificationModal {
767
776
 
768
777
  .${CSS_CLASSES.iframe} {
769
778
  width: 100%;
770
- height: 90vh;
771
- height: 90dvh;
772
- max-height: 700px;
779
+ height: 100%;
773
780
  border: none;
774
781
  display: block;
775
782
  }
@@ -810,6 +817,12 @@ class VerificationModal {
810
817
  z-index: 5;
811
818
  }
812
819
 
820
+ @media (prefers-color-scheme: dark) {
821
+ .${CSS_CLASSES.loading} {
822
+ background: #0b0b0d;
823
+ }
824
+ }
825
+
813
826
  .${CSS_CLASSES.loading}.hidden {
814
827
  display: none;
815
828
  }
@@ -931,6 +944,58 @@ class VerificationModal {
931
944
  outline-offset: 2px;
932
945
  }
933
946
 
947
+ /*
948
+ * Steps are phone-sized (440 x 860, above). On a computer the handoff card is wider
949
+ * (board Start-Embedded): 960 x 660 on a window of 1000px or more, never wider than the
950
+ * window less its margin and never taller than 90% of it. In a narrower window the
951
+ * page stacks and the height follows its content (--didit-content-height, set from the
952
+ * flow's layout message). Until the flow reports what it shows, the modal is the handoff
953
+ * card at its final size with the spinner inside it (the flow stays hidden and lays itself
954
+ * out for that size): it never opens small and grows. The first change of kind (a step
955
+ * instead of the handoff, or the person continues on this computer) animates once.
956
+ */
957
+ @media (min-width: 541px) {
958
+ .${CSS_CLASSES.container}[data-didit-kind="handoff"],
959
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] {
960
+ max-width: min(960px, calc(100vw - 2rem));
961
+ height: min(var(--didit-content-height, 660px), calc(100vh * 0.9));
962
+ height: min(var(--didit-content-height, 660px), calc(100dvh * 0.9));
963
+ }
964
+
965
+ .${CSS_CLASSES.container}.${CSS_CLASSES.sizeAnimated} {
966
+ transition: max-width 0.25s ease, height 0.25s ease;
967
+ }
968
+
969
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] .${CSS_CLASSES.iframe} {
970
+ visibility: hidden;
971
+ }
972
+ }
973
+
974
+ /*
975
+ * While pending the card already looks like the first screen (ground, radius, shadow and
976
+ * close button come from the flow-sized rules below, with the device theme); the loader
977
+ * sits inside it on the card's own ground.
978
+ */
979
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] .${CSS_CLASSES.loading} {
980
+ background: transparent;
981
+ }
982
+
983
+ .${CSS_CLASSES.container}[data-didit-kind="pending"][data-didit-theme="dark"] .${CSS_CLASSES.loading} circle {
984
+ stroke: rgba(255, 255, 255, 0.16);
985
+ }
986
+
987
+ .${CSS_CLASSES.container}[data-didit-kind="pending"][data-didit-theme="dark"] .${CSS_CLASSES.loading} path {
988
+ stroke: #f5f5f7;
989
+ }
990
+
991
+ @media (min-width: 1000px) {
992
+ .${CSS_CLASSES.container}[data-didit-kind="handoff"],
993
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] {
994
+ height: min(660px, calc(100vh * 0.9));
995
+ height: min(660px, calc(100dvh * 0.9));
996
+ }
997
+ }
998
+
934
999
  @media (max-width: 540px) {
935
1000
  .${CSS_CLASSES.overlay} {
936
1001
  padding: 0;
@@ -938,23 +1003,16 @@ class VerificationModal {
938
1003
 
939
1004
  .${CSS_CLASSES.container} {
940
1005
  max-width: 100%;
941
- max-height: 100vh;
942
- max-height: 100dvh;
943
- border-radius: 0;
944
- }
945
-
946
- .${CSS_CLASSES.iframe} {
947
1006
  height: 100vh;
948
1007
  height: 100dvh;
949
- max-height: none;
1008
+ border-radius: 0;
950
1009
  }
951
1010
  }
952
1011
 
953
1012
  /*
954
- * Once the hosted flow reports its layout (didit:layout), the modal
955
- * grows to the handoff card on a computer (960 x 660, at most 90% of
956
- * the window) and follows the flow's content height in a narrow
957
- * window. Colours are the design system tokens named beside them.
1013
+ * The hosted flow's layout message (didit:layout) brings the modal's size
1014
+ * (see above), theme and direction. Colours are the design system tokens
1015
+ * named beside them.
958
1016
  */
959
1017
  .${CSS_CLASSES.container}.${CSS_CLASSES.flowSized} {
960
1018
  --didit-ground: #ffffff; /* site-ground */
@@ -964,7 +1022,6 @@ class VerificationModal {
964
1022
  --didit-close-fill: rgba(0, 0, 0, 0.06);
965
1023
  --didit-drop: rgba(17, 24, 39, 0.35);
966
1024
  --didit-ring: rgba(0, 0, 0, 0.06);
967
- max-width: 500px;
968
1025
  background: var(--didit-ground);
969
1026
  box-shadow: 0 30px 80px -24px var(--didit-drop), 0 0 0 1px var(--didit-ring);
970
1027
  }
@@ -979,12 +1036,6 @@ class VerificationModal {
979
1036
  --didit-ring: rgba(255, 255, 255, 0.08); /* c-shadow-pop, dark */
980
1037
  }
981
1038
 
982
- .${CSS_CLASSES.flowSized} .${CSS_CLASSES.iframe} {
983
- height: var(--didit-flow-height);
984
- max-height: 90vh;
985
- max-height: 90dvh;
986
- }
987
-
988
1039
  .${CSS_CLASSES.closeIcon} {
989
1040
  display: none;
990
1041
  }
@@ -1058,28 +1109,11 @@ class VerificationModal {
1058
1109
  flex-wrap: wrap;
1059
1110
  }
1060
1111
 
1061
- @media (min-width: 1024px) {
1062
- .${CSS_CLASSES.container}.${CSS_CLASSES.flowSized} {
1063
- width: 90vw;
1064
- max-width: 960px;
1065
- }
1066
-
1067
- .${CSS_CLASSES.flowSized} .${CSS_CLASSES.iframe} {
1068
- height: 660px;
1069
- }
1070
- }
1071
-
1072
1112
  @media (max-width: 540px) {
1073
1113
  .${CSS_CLASSES.container}.${CSS_CLASSES.flowSized} {
1074
1114
  max-width: 100%;
1075
1115
  box-shadow: none;
1076
1116
  }
1077
-
1078
- .${CSS_CLASSES.flowSized} .${CSS_CLASSES.iframe} {
1079
- height: 100vh;
1080
- height: 100dvh;
1081
- max-height: none;
1082
- }
1083
1117
  }
1084
1118
 
1085
1119
  .${CSS_CLASSES.embedded} {
@@ -1312,12 +1346,13 @@ class VerificationModal {
1312
1346
  */
1313
1347
  readFlowLayout(data) {
1314
1348
  const fields = typeof data === "object" && data !== null ? data : {};
1315
- const { contentHeight, colorScheme, dir } = fields;
1349
+ const { contentHeight, colorScheme, dir, kind } = fields;
1316
1350
  if (typeof contentHeight !== "number" || !Number.isFinite(contentHeight) || contentHeight <= 0) {
1317
1351
  return null;
1318
1352
  }
1319
1353
  const prefersDark = window.matchMedia?.("(prefers-color-scheme: dark)").matches ?? false;
1320
1354
  return {
1355
+ kind: kind === "handoff" ? "handoff" : "step",
1321
1356
  contentHeight: Math.ceil(contentHeight),
1322
1357
  colorScheme: colorScheme === "light" || colorScheme === "dark" ? colorScheme : prefersDark ? "dark" : "light",
1323
1358
  dir: dir === "ltr" || dir === "rtl" ? dir : isRtlLanguage(this.language) ? "rtl" : "ltr"
@@ -1329,18 +1364,113 @@ class VerificationModal {
1329
1364
  return;
1330
1365
  SDKLogger.log("Flow layout:", layout);
1331
1366
  this.container.classList.add(CSS_CLASSES.flowSized);
1332
- this.container.style.setProperty("--didit-flow-height", `${layout.contentHeight}px`);
1333
1367
  this.container.dataset.diditTheme = layout.colorScheme;
1334
1368
  this.container.dataset.diditDir = layout.dir;
1369
+ // The height the person sees now, before the reported content height can change it.
1370
+ const shownHeight = this.container.offsetHeight;
1371
+ this.container.style.setProperty("--didit-content-height", `${layout.contentHeight}px`);
1372
+ this.matchPageBackground(layout.colorScheme);
1373
+ this.setModalKind(layout.kind, layout.kind === "handoff" && this.handoffHeight(layout) === shownHeight);
1374
+ }
1375
+ /** Whether the window is a computer-sized one: a phone is full screen and never waits for a layout. */
1376
+ isPhoneWindow() {
1377
+ return window.matchMedia?.("(max-width: 540px)").matches ?? false;
1378
+ }
1379
+ /** The height the handoff card takes for a layout, as the size rules above compute it (rounded like offsetHeight). */
1380
+ handoffHeight(layout) {
1381
+ const cap = window.innerHeight * 0.9;
1382
+ return Math.round(Math.min(window.innerWidth >= 1000 ? 660 : layout.contentHeight, cap));
1383
+ }
1384
+ /**
1385
+ * Sets what the modal is sized for. Leaving "pending" shows the modal at its final size with no
1386
+ * transition; any later change animates once.
1387
+ */
1388
+ setModalKind(kind, sizeUnchanged = false) {
1389
+ if (!this.container)
1390
+ return;
1391
+ const previous = this.container.dataset.diditKind;
1392
+ if (previous === kind)
1393
+ return;
1394
+ if (this.firstLayoutTimeout !== null && kind !== "pending") {
1395
+ window.clearTimeout(this.firstLayoutTimeout);
1396
+ this.firstLayoutTimeout = null;
1397
+ }
1398
+ // Every change of kind animates, the pending card included (it is on screen), and only for the
1399
+ // length of the change, so resizing the window never lags behind.
1400
+ // Pending already is the handoff card: a handoff first layout of the same size moves nothing,
1401
+ // while a different reported height (a narrow window) animates the correction once.
1402
+ const staysPut = previous === "pending" && kind === "handoff" && sizeUnchanged;
1403
+ if (previous !== undefined && !staysPut)
1404
+ this.animateSizeOnce();
1405
+ this.container.dataset.diditKind = kind;
1406
+ // The final size is in place before the loader goes; a flow still loading keeps its loader.
1407
+ if (previous === "pending" && !this.state.isLoading)
1408
+ this.loadingEl?.classList.add("hidden");
1335
1409
  }
1336
- /** Back to the fixed 500 x 700 modal until the newly loaded flow reports its layout. */
1410
+ animateSizeOnce() {
1411
+ this.container?.classList.add(CSS_CLASSES.sizeAnimated);
1412
+ if (this.sizeTimeout !== null)
1413
+ window.clearTimeout(this.sizeTimeout);
1414
+ this.sizeTimeout = window.setTimeout(() => {
1415
+ this.sizeTimeout = null;
1416
+ this.container?.classList.remove(CSS_CLASSES.sizeAnimated);
1417
+ }, SIZE_ANIMATION_MS);
1418
+ }
1419
+ /** A flow that reports no layout (an older one) still shows, at step size, after a short wait. */
1420
+ waitForFirstLayout() {
1421
+ if (!this.container)
1422
+ return;
1423
+ // The card looks like the first screen from the first frame, in the device's theme.
1424
+ this.container.classList.add(CSS_CLASSES.flowSized);
1425
+ this.container.dataset.diditTheme = window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
1426
+ this.setModalKind("pending");
1427
+ this.firstLayoutTimeout = window.setTimeout(() => {
1428
+ this.firstLayoutTimeout = null;
1429
+ // A flow that never reported is an older one that paints itself: no card look around it.
1430
+ this.container?.classList.remove(CSS_CLASSES.flowSized);
1431
+ delete this.container?.dataset.diditTheme;
1432
+ this.setModalKind("step");
1433
+ }, FIRST_LAYOUT_TIMEOUT_MS);
1434
+ }
1435
+ /**
1436
+ * On a phone Safari paints the bottom edge of the screen with the page's own background, past
1437
+ * any fixed overlay, and shows it when the keyboard moves the page. A full-screen modal lends
1438
+ * the page its ground colour while it is open, so no strip of the host page shows around it.
1439
+ */
1440
+ matchPageBackground(colorScheme) {
1441
+ if (!window.matchMedia?.("(max-width: 540px)").matches)
1442
+ return;
1443
+ const root = document.documentElement;
1444
+ this.pageBackground ?? (this.pageBackground = { root: root.style.backgroundColor, body: document.body.style.backgroundColor });
1445
+ const ground = colorScheme === "dark" ? "#0b0b0d" : "#ffffff";
1446
+ root.style.backgroundColor = ground;
1447
+ document.body.style.backgroundColor = ground;
1448
+ }
1449
+ restorePageBackground() {
1450
+ if (!this.pageBackground)
1451
+ return;
1452
+ document.documentElement.style.backgroundColor = this.pageBackground.root;
1453
+ document.body.style.backgroundColor = this.pageBackground.body;
1454
+ this.pageBackground = null;
1455
+ }
1456
+ /** Back to the neutral look until the newly loaded flow reports its theme and direction. */
1337
1457
  resetFlowLayout() {
1338
1458
  if (this.embedded || !this.container)
1339
1459
  return;
1340
- this.container.classList.remove(CSS_CLASSES.flowSized);
1341
- this.container.style.removeProperty("--didit-flow-height");
1460
+ this.restorePageBackground();
1461
+ this.container.classList.remove(CSS_CLASSES.flowSized, CSS_CLASSES.sizeAnimated);
1342
1462
  delete this.container.dataset.diditTheme;
1343
1463
  delete this.container.dataset.diditDir;
1464
+ delete this.container.dataset.diditKind;
1465
+ this.container.style.removeProperty("--didit-content-height");
1466
+ if (this.firstLayoutTimeout !== null) {
1467
+ window.clearTimeout(this.firstLayoutTimeout);
1468
+ this.firstLayoutTimeout = null;
1469
+ }
1470
+ if (this.sizeTimeout !== null) {
1471
+ window.clearTimeout(this.sizeTimeout);
1472
+ this.sizeTimeout = null;
1473
+ }
1344
1474
  }
1345
1475
  handleKeydown(event) {
1346
1476
  if (!this.state.isOpen)
@@ -1376,7 +1506,9 @@ class VerificationModal {
1376
1506
  handleIframeLoad() {
1377
1507
  if (this.iframe?.src && this.iframe.src !== "about:blank") {
1378
1508
  this.state.isLoading = false;
1379
- this.loadingEl?.classList.add("hidden");
1509
+ // A modal still waiting for its first layout keeps the loader over the hidden flow.
1510
+ if (this.container?.dataset.diditKind !== "pending")
1511
+ this.loadingEl?.classList.add("hidden");
1380
1512
  this.callbacks.onIframeLoad();
1381
1513
  }
1382
1514
  }
@@ -1465,6 +1597,8 @@ class VerificationModal {
1465
1597
  this.hideConfirmation();
1466
1598
  this.loadingEl?.classList.remove("hidden");
1467
1599
  this.resetFlowLayout();
1600
+ if (!this.embedded && !this.isPhoneWindow())
1601
+ this.waitForFirstLayout();
1468
1602
  if (this.iframe) {
1469
1603
  this.iframe.src = verificationUrl;
1470
1604
  }