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