@didit-protocol/sdk-web 0.5.1 → 0.6.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Didit SDK for Web v0.5.1
2
+ * Didit SDK for Web v0.6.0
3
3
  * (c) 2026 Didit
4
4
  * @license MIT
5
5
  */
@@ -22,12 +22,14 @@ 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
- embedded: "didit-embedded"
29
+ embedded: "didit-embedded",
30
+ curtain: "didit-modal-curtain"
29
31
  };
30
- const SDK_VERSION = "0.5.1";
32
+ const SDK_VERSION = "0.6.0";
31
33
  /**
32
34
  * The permissions the verification iframe gets, in a modal and embedded:
33
35
  * camera and microphone for capture, clipboard-write for the flow's copy
@@ -53,9 +55,16 @@ const PRESENTATION_QUERY_PARAMS = {
53
55
  presentation: "sdk_presentation",
54
56
  closeButton: "sdk_close_button"
55
57
  };
58
+ /**
59
+ * The verification-URL query parameter that carries the device id this page
60
+ * already keeps for Didit, when it keeps one. A browser gives the flow in the
61
+ * frame storage of its own, apart from this page's, so without it a
62
+ * verification and this site's events never share a device id.
63
+ */
64
+ const DEVICE_ID_QUERY_PARAM = "sdk_device_id";
56
65
  /**
57
66
  * 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
67
+ * `data: { contentHeight, colorScheme?, dir?, kind? }` (`kind` is `handoff` or `step`, `step` when missing). The modal then grows to the
59
68
  * handoff card on a computer and follows the content height in a narrow
60
69
  * window. Handled by the modal and never delivered to `onEvent`.
61
70
  */
@@ -179,15 +188,21 @@ const CAMERA_SWITCH_OPTIONS = ["showDocumentCameraSwitchButton", "showLivenessCa
179
188
  * `showDocumentCameraSwitchButton` -> `document_camera_switch=true|false`,
180
189
  * `showLivenessCameraSwitchButton` -> `liveness_camera_switch=true|false`.
181
190
  * How the SDK presents the flow is always added: `sdk_presentation=modal|embedded`
182
- * and, in a modal, `sdk_close_button=true|false`.
191
+ * and, in a modal, `sdk_close_button=true|false`. `storedDeviceId`, when the
192
+ * page has one, is added as `sdk_device_id`.
183
193
  * Each parameter is set (not appended) so the configuration wins over a value
184
194
  * already on the URL; existing query parameters and the hash are kept. A
185
195
  * value of the wrong shape is ignored with a warning rather than forwarded,
186
196
  * and a URL the browser cannot parse is returned as it came (the modal
187
197
  * reports it when it loads).
188
198
  */
189
- function buildVerificationUrl(url, configuration = {}) {
199
+ function buildVerificationUrl(url, configuration = {}, storedDeviceId = null) {
190
200
  const params = presentationParams(configuration);
201
+ // The id this page already keeps for Didit (see getStoredDeviceId): the flow in the frame, whose
202
+ // own storage the browser keeps apart from this page's, can then be told apart as the same
203
+ // device as this site's events. Absent when the page keeps none; nothing is created for it.
204
+ if (storedDeviceId)
205
+ params.push([DEVICE_ID_QUERY_PARAM, storedDeviceId]);
191
206
  for (const option of CAMERA_LENS_OPTIONS) {
192
207
  const value = configuration[option];
193
208
  if (value === undefined)
@@ -689,6 +704,12 @@ function getTranslations(language) {
689
704
  return translationsMap[language] ?? EN;
690
705
  }
691
706
 
707
+ /** The length of the one animation when the flow moves from the handoff card to a step or back. */
708
+ const SIZE_ANIMATION_MS = 300;
709
+ /** How long the modal waits for the first layout before it shows at step size, so it can never hang. */
710
+ const FIRST_LAYOUT_TIMEOUT_MS = 3000;
711
+ /** The flow's ground (site-ground in the design system), which a full-screen modal paints the page with. */
712
+ const FLOW_GROUND = { light: "#ffffff", dark: "#0b0b0d" };
692
713
  class VerificationModal {
693
714
  constructor(configuration, callbacks) {
694
715
  this.state = {
@@ -706,11 +727,14 @@ class VerificationModal {
706
727
  this.boundHandleKeydown = null;
707
728
  this.boundHandleFocusChange = null;
708
729
  this.confirmationFocusTimeout = null;
730
+ this.firstLayoutTimeout = null;
731
+ this.sizeTimeout = null;
709
732
  this.embedded = false;
710
733
  this.embeddedContainer = null;
711
734
  this.language = "en";
712
- /** body.style.overflow value observed right before this modal locked scroll, restored on close(). */
713
- this.previousBodyOverflow = null;
735
+ /** The ground below the layout viewport (see showCurtain), while this modal is open. */
736
+ this.curtain = null;
737
+ this.boundPlaceCurtain = null;
714
738
  this.modalId = generateModalId();
715
739
  this.config = {
716
740
  zIndex: configuration?.zIndex ?? DEFAULT_CONFIG.zIndex,
@@ -753,9 +777,9 @@ class VerificationModal {
753
777
  .${CSS_CLASSES.container} {
754
778
  position: relative;
755
779
  width: 100%;
756
- max-width: 500px;
757
- max-height: 90vh;
758
- max-height: 90dvh;
780
+ max-width: 440px;
781
+ height: min(860px, calc(100vh - 2rem));
782
+ height: min(860px, calc(100dvh - 2rem));
759
783
  border-radius: 16px;
760
784
  overflow: hidden;
761
785
  background: transparent;
@@ -767,9 +791,7 @@ class VerificationModal {
767
791
 
768
792
  .${CSS_CLASSES.iframe} {
769
793
  width: 100%;
770
- height: 90vh;
771
- height: 90dvh;
772
- max-height: 700px;
794
+ height: 100%;
773
795
  border: none;
774
796
  display: block;
775
797
  }
@@ -806,10 +828,17 @@ class VerificationModal {
806
828
  display: flex;
807
829
  align-items: center;
808
830
  justify-content: center;
809
- background: #fafafa;
831
+ /* The flow's ground, so a phone's loader meets the ground below the viewport without a seam. */
832
+ background: ${FLOW_GROUND.light};
810
833
  z-index: 5;
811
834
  }
812
835
 
836
+ @media (prefers-color-scheme: dark) {
837
+ .${CSS_CLASSES.loading} {
838
+ background: ${FLOW_GROUND.dark};
839
+ }
840
+ }
841
+
813
842
  .${CSS_CLASSES.loading}.hidden {
814
843
  display: none;
815
844
  }
@@ -931,6 +960,58 @@ class VerificationModal {
931
960
  outline-offset: 2px;
932
961
  }
933
962
 
963
+ /*
964
+ * Steps are phone-sized (440 x 860, above). On a computer the handoff card is wider
965
+ * (board Start-Embedded): 960 x 660 on a window of 1000px or more, never wider than the
966
+ * window less its margin and never taller than 90% of it. In a narrower window the
967
+ * page stacks and the height follows its content (--didit-content-height, set from the
968
+ * flow's layout message). Until the flow reports what it shows, the modal is the handoff
969
+ * card at its final size with the spinner inside it (the flow stays hidden and lays itself
970
+ * out for that size): it never opens small and grows. The first change of kind (a step
971
+ * instead of the handoff, or the person continues on this computer) animates once.
972
+ */
973
+ @media (min-width: 541px) {
974
+ .${CSS_CLASSES.container}[data-didit-kind="handoff"],
975
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] {
976
+ max-width: min(960px, calc(100vw - 2rem));
977
+ height: min(var(--didit-content-height, 660px), calc(100vh * 0.9));
978
+ height: min(var(--didit-content-height, 660px), calc(100dvh * 0.9));
979
+ }
980
+
981
+ .${CSS_CLASSES.container}.${CSS_CLASSES.sizeAnimated} {
982
+ transition: max-width 0.25s ease, height 0.25s ease;
983
+ }
984
+
985
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] .${CSS_CLASSES.iframe} {
986
+ visibility: hidden;
987
+ }
988
+ }
989
+
990
+ /*
991
+ * While pending the card already looks like the first screen (ground, radius, shadow and
992
+ * close button come from the flow-sized rules below, with the device theme); the loader
993
+ * sits inside it on the card's own ground.
994
+ */
995
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] .${CSS_CLASSES.loading} {
996
+ background: transparent;
997
+ }
998
+
999
+ .${CSS_CLASSES.container}[data-didit-kind="pending"][data-didit-theme="dark"] .${CSS_CLASSES.loading} circle {
1000
+ stroke: rgba(255, 255, 255, 0.16);
1001
+ }
1002
+
1003
+ .${CSS_CLASSES.container}[data-didit-kind="pending"][data-didit-theme="dark"] .${CSS_CLASSES.loading} path {
1004
+ stroke: #f5f5f7;
1005
+ }
1006
+
1007
+ @media (min-width: 1000px) {
1008
+ .${CSS_CLASSES.container}[data-didit-kind="handoff"],
1009
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] {
1010
+ height: min(660px, calc(100vh * 0.9));
1011
+ height: min(660px, calc(100dvh * 0.9));
1012
+ }
1013
+ }
1014
+
934
1015
  @media (max-width: 540px) {
935
1016
  .${CSS_CLASSES.overlay} {
936
1017
  padding: 0;
@@ -938,23 +1019,50 @@ class VerificationModal {
938
1019
 
939
1020
  .${CSS_CLASSES.container} {
940
1021
  max-width: 100%;
941
- max-height: 100vh;
942
- max-height: 100dvh;
1022
+ height: 100vh;
1023
+ height: 100dvh;
943
1024
  border-radius: 0;
944
1025
  }
1026
+ }
945
1027
 
946
- .${CSS_CLASSES.iframe} {
947
- height: 100vh;
948
- height: 100dvh;
949
- max-height: none;
1028
+ /*
1029
+ * The flow's ground right below the layout viewport, in the page itself (see showCurtain):
1030
+ * on a phone, iOS browsers with their toolbars collapsed show a band of the page there,
1031
+ * below every fixed element, the full-screen modal included.
1032
+ */
1033
+ .${CSS_CLASSES.curtain} {
1034
+ display: none;
1035
+ position: absolute;
1036
+ top: 0;
1037
+ left: 0;
1038
+ width: 100vw;
1039
+ height: 100vh;
1040
+ margin: 0;
1041
+ pointer-events: none;
1042
+ /* Under the modal where they meet for a frame while the toolbars move, above the page. */
1043
+ z-index: ${this.config.zIndex - 1};
1044
+ background: ${FLOW_GROUND.light};
1045
+ }
1046
+
1047
+ .${CSS_CLASSES.curtain}[data-didit-theme="dark"] {
1048
+ background: ${FLOW_GROUND.dark};
1049
+ }
1050
+
1051
+ /* The exit confirmation's dimming continues over the ground below the viewport. */
1052
+ .${CSS_CLASSES.curtain}[data-didit-dimmed] {
1053
+ background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5));
1054
+ }
1055
+
1056
+ @media (max-width: 540px) {
1057
+ .${CSS_CLASSES.curtain} {
1058
+ display: block;
950
1059
  }
951
1060
  }
952
1061
 
953
1062
  /*
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.
1063
+ * The hosted flow's layout message (didit:layout) brings the modal's size
1064
+ * (see above), theme and direction. Colours are the design system tokens
1065
+ * named beside them.
958
1066
  */
959
1067
  .${CSS_CLASSES.container}.${CSS_CLASSES.flowSized} {
960
1068
  --didit-ground: #ffffff; /* site-ground */
@@ -964,7 +1072,6 @@ class VerificationModal {
964
1072
  --didit-close-fill: rgba(0, 0, 0, 0.06);
965
1073
  --didit-drop: rgba(17, 24, 39, 0.35);
966
1074
  --didit-ring: rgba(0, 0, 0, 0.06);
967
- max-width: 500px;
968
1075
  background: var(--didit-ground);
969
1076
  box-shadow: 0 30px 80px -24px var(--didit-drop), 0 0 0 1px var(--didit-ring);
970
1077
  }
@@ -979,12 +1086,6 @@ class VerificationModal {
979
1086
  --didit-ring: rgba(255, 255, 255, 0.08); /* c-shadow-pop, dark */
980
1087
  }
981
1088
 
982
- .${CSS_CLASSES.flowSized} .${CSS_CLASSES.iframe} {
983
- height: var(--didit-flow-height);
984
- max-height: 90vh;
985
- max-height: 90dvh;
986
- }
987
-
988
1089
  .${CSS_CLASSES.closeIcon} {
989
1090
  display: none;
990
1091
  }
@@ -1058,28 +1159,11 @@ class VerificationModal {
1058
1159
  flex-wrap: wrap;
1059
1160
  }
1060
1161
 
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
1162
  @media (max-width: 540px) {
1073
1163
  .${CSS_CLASSES.container}.${CSS_CLASSES.flowSized} {
1074
1164
  max-width: 100%;
1075
1165
  box-shadow: none;
1076
1166
  }
1077
-
1078
- .${CSS_CLASSES.flowSized} .${CSS_CLASSES.iframe} {
1079
- height: 100vh;
1080
- height: 100dvh;
1081
- max-height: none;
1082
- }
1083
1167
  }
1084
1168
 
1085
1169
  .${CSS_CLASSES.embedded} {
@@ -1312,12 +1396,13 @@ class VerificationModal {
1312
1396
  */
1313
1397
  readFlowLayout(data) {
1314
1398
  const fields = typeof data === "object" && data !== null ? data : {};
1315
- const { contentHeight, colorScheme, dir } = fields;
1399
+ const { contentHeight, colorScheme, dir, kind } = fields;
1316
1400
  if (typeof contentHeight !== "number" || !Number.isFinite(contentHeight) || contentHeight <= 0) {
1317
1401
  return null;
1318
1402
  }
1319
1403
  const prefersDark = window.matchMedia?.("(prefers-color-scheme: dark)").matches ?? false;
1320
1404
  return {
1405
+ kind: kind === "handoff" ? "handoff" : "step",
1321
1406
  contentHeight: Math.ceil(contentHeight),
1322
1407
  colorScheme: colorScheme === "light" || colorScheme === "dark" ? colorScheme : prefersDark ? "dark" : "light",
1323
1408
  dir: dir === "ltr" || dir === "rtl" ? dir : isRtlLanguage(this.language) ? "rtl" : "ltr"
@@ -1329,18 +1414,222 @@ class VerificationModal {
1329
1414
  return;
1330
1415
  SDKLogger.log("Flow layout:", layout);
1331
1416
  this.container.classList.add(CSS_CLASSES.flowSized);
1332
- this.container.style.setProperty("--didit-flow-height", `${layout.contentHeight}px`);
1333
1417
  this.container.dataset.diditTheme = layout.colorScheme;
1334
1418
  this.container.dataset.diditDir = layout.dir;
1419
+ // The height the person sees now, before the reported content height can change it.
1420
+ const shownHeight = this.container.offsetHeight;
1421
+ this.container.style.setProperty("--didit-content-height", `${layout.contentHeight}px`);
1422
+ this.matchPageBackground(layout.colorScheme);
1423
+ if (this.curtain)
1424
+ this.curtain.dataset.diditTheme = layout.colorScheme;
1425
+ this.setModalKind(layout.kind, layout.kind === "handoff" && this.handoffHeight(layout) === shownHeight);
1426
+ }
1427
+ /** Whether the window is a computer-sized one: a phone is full screen and never waits for a layout. */
1428
+ isPhoneWindow() {
1429
+ return window.matchMedia?.("(max-width: 540px)").matches ?? false;
1430
+ }
1431
+ /** The height the handoff card takes for a layout, as the size rules above compute it (rounded like offsetHeight). */
1432
+ handoffHeight(layout) {
1433
+ const cap = window.innerHeight * 0.9;
1434
+ return Math.round(Math.min(window.innerWidth >= 1000 ? 660 : layout.contentHeight, cap));
1435
+ }
1436
+ /**
1437
+ * Sets what the modal is sized for. Leaving "pending" shows the modal at its final size with no
1438
+ * transition; any later change animates once.
1439
+ */
1440
+ setModalKind(kind, sizeUnchanged = false) {
1441
+ if (!this.container)
1442
+ return;
1443
+ const previous = this.container.dataset.diditKind;
1444
+ if (previous === kind)
1445
+ return;
1446
+ if (this.firstLayoutTimeout !== null && kind !== "pending") {
1447
+ window.clearTimeout(this.firstLayoutTimeout);
1448
+ this.firstLayoutTimeout = null;
1449
+ }
1450
+ // Every change of kind animates, the pending card included (it is on screen), and only for the
1451
+ // length of the change, so resizing the window never lags behind.
1452
+ // Pending already is the handoff card: a handoff first layout of the same size moves nothing,
1453
+ // while a different reported height (a narrow window) animates the correction once.
1454
+ const staysPut = previous === "pending" && kind === "handoff" && sizeUnchanged;
1455
+ if (previous !== undefined && !staysPut)
1456
+ this.animateSizeOnce();
1457
+ this.container.dataset.diditKind = kind;
1458
+ // The final size is in place before the loader goes; a flow still loading keeps its loader.
1459
+ if (previous === "pending" && !this.state.isLoading)
1460
+ this.loadingEl?.classList.add("hidden");
1461
+ }
1462
+ animateSizeOnce() {
1463
+ this.container?.classList.add(CSS_CLASSES.sizeAnimated);
1464
+ if (this.sizeTimeout !== null)
1465
+ window.clearTimeout(this.sizeTimeout);
1466
+ this.sizeTimeout = window.setTimeout(() => {
1467
+ this.sizeTimeout = null;
1468
+ this.container?.classList.remove(CSS_CLASSES.sizeAnimated);
1469
+ }, SIZE_ANIMATION_MS);
1470
+ }
1471
+ /** A flow that reports no layout (an older one) still shows, at step size, after a short wait. */
1472
+ waitForFirstLayout() {
1473
+ if (!this.container)
1474
+ return;
1475
+ // The card looks like the first screen from the first frame, in the device's theme.
1476
+ this.container.classList.add(CSS_CLASSES.flowSized);
1477
+ this.container.dataset.diditTheme = window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
1478
+ this.setModalKind("pending");
1479
+ this.firstLayoutTimeout = window.setTimeout(() => {
1480
+ this.firstLayoutTimeout = null;
1481
+ // A flow that never reported is an older one that paints itself: no card look around it.
1482
+ this.container?.classList.remove(CSS_CLASSES.flowSized);
1483
+ delete this.container?.dataset.diditTheme;
1484
+ this.setModalKind("step");
1485
+ }, FIRST_LAYOUT_TIMEOUT_MS);
1335
1486
  }
1336
- /** Back to the fixed 500 x 700 modal until the newly loaded flow reports its layout. */
1487
+ /**
1488
+ * On a phone Safari paints the bottom edge of the screen with the page's own background, past
1489
+ * any fixed overlay, and shows it when the keyboard moves the page. A full-screen modal lends
1490
+ * the page its ground colour while it is open, so no strip of the host page shows around it.
1491
+ */
1492
+ matchPageBackground(colorScheme) {
1493
+ if (!window.matchMedia?.("(max-width: 540px)").matches)
1494
+ return;
1495
+ VerificationModal.pageBackground ?? (VerificationModal.pageBackground = {
1496
+ saved: { root: document.documentElement.style.backgroundColor, body: document.body.style.backgroundColor },
1497
+ grounds: new Map()
1498
+ });
1499
+ VerificationModal.pageBackground.grounds.set(this, colorScheme);
1500
+ VerificationModal.paintPageBackground();
1501
+ }
1502
+ restorePageBackground() {
1503
+ const background = VerificationModal.pageBackground;
1504
+ if (!background?.grounds.delete(this))
1505
+ return;
1506
+ if (background.grounds.size > 0) {
1507
+ VerificationModal.paintPageBackground();
1508
+ return;
1509
+ }
1510
+ VerificationModal.pageBackground = null;
1511
+ document.documentElement.style.backgroundColor = background.saved.root;
1512
+ document.body.style.backgroundColor = background.saved.body;
1513
+ }
1514
+ /** The page shows the ground of the topmost open modal that lends one. */
1515
+ static paintPageBackground() {
1516
+ const background = VerificationModal.pageBackground;
1517
+ if (!background)
1518
+ return;
1519
+ const lender = [...VerificationModal.openModals].reverse().find((modal) => background.grounds.has(modal));
1520
+ const colorScheme = lender ? background.grounds.get(lender) : [...background.grounds.values()].pop();
1521
+ if (!colorScheme)
1522
+ return;
1523
+ document.documentElement.style.backgroundColor = FLOW_GROUND[colorScheme];
1524
+ document.body.style.backgroundColor = FLOW_GROUND[colorScheme];
1525
+ }
1526
+ /**
1527
+ * Stops the page scrolling under the modal. The lock is on the root element: Chrome for iOS keeps
1528
+ * scrolling a page whose body alone is `overflow: hidden` (a swipe over the modal scrolls the page
1529
+ * and toggles the browser's toolbars), and stops only when the root element is. A page that
1530
+ * scrolls its body instead of the window has its body locked too. The first modal to open keeps
1531
+ * the page's own values and the last one to close gives them back.
1532
+ */
1533
+ lockPageScroll() {
1534
+ const lock = VerificationModal.pageScrollLock;
1535
+ if (lock) {
1536
+ lock.holders.add(this);
1537
+ return;
1538
+ }
1539
+ const root = document.documentElement;
1540
+ const body = document.body;
1541
+ // The body's overflow is the viewport's only while the root's is visible; otherwise a body with
1542
+ // an overflow of its own is a scroll container. Locking a body that is not one would clip the page
1543
+ // to the body's box.
1544
+ const clips = (overflow) => overflow !== "" && overflow !== "visible";
1545
+ const bodyScrollsItself = clips(window.getComputedStyle(root).overflowY) && clips(window.getComputedStyle(body).overflowY);
1546
+ VerificationModal.pageScrollLock = {
1547
+ holders: new Set([this]),
1548
+ root: { overflow: root.style.overflow, overscrollBehavior: root.style.overscrollBehavior },
1549
+ body: bodyScrollsItself ? { overflow: body.style.overflow } : null
1550
+ };
1551
+ root.style.overflow = "hidden";
1552
+ root.style.overscrollBehavior = "none";
1553
+ if (bodyScrollsItself)
1554
+ body.style.overflow = "hidden";
1555
+ }
1556
+ unlockPageScroll() {
1557
+ const lock = VerificationModal.pageScrollLock;
1558
+ if (!lock || !lock.holders.delete(this) || lock.holders.size > 0)
1559
+ return;
1560
+ VerificationModal.pageScrollLock = null;
1561
+ const root = document.documentElement;
1562
+ root.style.overflow = lock.root.overflow;
1563
+ root.style.overscrollBehavior = lock.root.overscrollBehavior;
1564
+ if (lock.body)
1565
+ document.body.style.overflow = lock.body.overflow;
1566
+ }
1567
+ /**
1568
+ * On a phone, Chrome for iOS (and the other iOS browsers built on WebKit's web view) shows a band
1569
+ * of the page below the layout viewport while its toolbars are collapsed: the home indicator's
1570
+ * area, and more while the toolbars move. Fixed elements end at the layout viewport, so the
1571
+ * full-screen modal cannot cover it and the host page's own content showed under the flow. The
1572
+ * curtain is part of the page instead: right below the viewport, in the flow's ground, so that band
1573
+ * shows the modal's ground. The page cannot scroll while the modal is open (lockPageScroll), and the
1574
+ * curtain follows the viewport when it resizes. Only phone-sized windows draw it (see the styles).
1575
+ */
1576
+ showCurtain() {
1577
+ if (!this.curtain) {
1578
+ const curtain = document.createElement("div");
1579
+ curtain.className = CSS_CLASSES.curtain;
1580
+ curtain.setAttribute("aria-hidden", "true");
1581
+ document.body.appendChild(curtain);
1582
+ this.curtain = curtain;
1583
+ this.boundPlaceCurtain = () => this.placeCurtain();
1584
+ window.addEventListener("resize", this.boundPlaceCurtain);
1585
+ window.addEventListener("scroll", this.boundPlaceCurtain);
1586
+ window.visualViewport?.addEventListener("resize", this.boundPlaceCurtain);
1587
+ }
1588
+ // The device's theme until the newly loaded flow reports its own (applyFlowLayout).
1589
+ this.curtain.dataset.diditTheme = window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
1590
+ this.placeCurtain();
1591
+ }
1592
+ /** Puts the curtain's top at the bottom of the layout viewport, whatever its containing block is. */
1593
+ placeCurtain() {
1594
+ const curtain = this.curtain;
1595
+ if (!curtain)
1596
+ return;
1597
+ curtain.style.top = "0px";
1598
+ curtain.style.left = "0px";
1599
+ // At 0, 0 the curtain's box starts at its containing block's corner (the page's, or a positioned
1600
+ // body's), in viewport coordinates: the offset that brings its top to the viewport's bottom edge.
1601
+ const origin = curtain.getBoundingClientRect();
1602
+ curtain.style.top = `${window.innerHeight - origin.top}px`;
1603
+ curtain.style.left = `${-origin.left}px`;
1604
+ }
1605
+ removeCurtain() {
1606
+ if (this.boundPlaceCurtain) {
1607
+ window.removeEventListener("resize", this.boundPlaceCurtain);
1608
+ window.removeEventListener("scroll", this.boundPlaceCurtain);
1609
+ window.visualViewport?.removeEventListener("resize", this.boundPlaceCurtain);
1610
+ this.boundPlaceCurtain = null;
1611
+ }
1612
+ this.curtain?.remove();
1613
+ this.curtain = null;
1614
+ }
1615
+ /** Back to the neutral look until the newly loaded flow reports its theme and direction. */
1337
1616
  resetFlowLayout() {
1338
1617
  if (this.embedded || !this.container)
1339
1618
  return;
1340
- this.container.classList.remove(CSS_CLASSES.flowSized);
1341
- this.container.style.removeProperty("--didit-flow-height");
1619
+ this.restorePageBackground();
1620
+ this.container.classList.remove(CSS_CLASSES.flowSized, CSS_CLASSES.sizeAnimated);
1342
1621
  delete this.container.dataset.diditTheme;
1343
1622
  delete this.container.dataset.diditDir;
1623
+ delete this.container.dataset.diditKind;
1624
+ this.container.style.removeProperty("--didit-content-height");
1625
+ if (this.firstLayoutTimeout !== null) {
1626
+ window.clearTimeout(this.firstLayoutTimeout);
1627
+ this.firstLayoutTimeout = null;
1628
+ }
1629
+ if (this.sizeTimeout !== null) {
1630
+ window.clearTimeout(this.sizeTimeout);
1631
+ this.sizeTimeout = null;
1632
+ }
1344
1633
  }
1345
1634
  handleKeydown(event) {
1346
1635
  if (!this.state.isOpen)
@@ -1376,7 +1665,9 @@ class VerificationModal {
1376
1665
  handleIframeLoad() {
1377
1666
  if (this.iframe?.src && this.iframe.src !== "about:blank") {
1378
1667
  this.state.isLoading = false;
1379
- this.loadingEl?.classList.add("hidden");
1668
+ // A modal still waiting for its first layout keeps the loader over the hidden flow.
1669
+ if (this.container?.dataset.diditKind !== "pending")
1670
+ this.loadingEl?.classList.add("hidden");
1380
1671
  this.callbacks.onIframeLoad();
1381
1672
  }
1382
1673
  }
@@ -1397,6 +1688,7 @@ class VerificationModal {
1397
1688
  : this.container?.querySelector(`.${CSS_CLASSES.closeButton}`) ?? this.iframe);
1398
1689
  this.state.showConfirmation = true;
1399
1690
  this.confirmOverlay.classList.add("active");
1691
+ this.curtain?.setAttribute("data-didit-dimmed", "");
1400
1692
  if (this.iframe)
1401
1693
  this.iframe.inert = true;
1402
1694
  const close = this.container?.querySelector(`.${CSS_CLASSES.closeButton}`);
@@ -1420,6 +1712,7 @@ class VerificationModal {
1420
1712
  return;
1421
1713
  this.state.showConfirmation = false;
1422
1714
  this.confirmOverlay?.classList.remove("active");
1715
+ this.curtain?.removeAttribute("data-didit-dimmed");
1423
1716
  if (this.iframe)
1424
1717
  this.iframe.inert = false;
1425
1718
  const close = this.container?.querySelector(`.${CSS_CLASSES.closeButton}`);
@@ -1447,11 +1740,6 @@ class VerificationModal {
1447
1740
  this.callbacks.onCloseConfirmed();
1448
1741
  }
1449
1742
  open(verificationUrl) {
1450
- // Whether this modal already held its scroll lock before this call. Re-opening
1451
- // an already-open instance must not re-capture previousBodyOverflow, or it
1452
- // would record this modal's own "hidden" lock and close() could never restore
1453
- // the real pre-lock value.
1454
- const wasAlreadyOpen = this.state.isOpen;
1455
1743
  this.language = detectLanguageFromUrl(verificationUrl);
1456
1744
  if (!this.overlay && !this.container) {
1457
1745
  this.createDOM();
@@ -1465,6 +1753,8 @@ class VerificationModal {
1465
1753
  this.hideConfirmation();
1466
1754
  this.loadingEl?.classList.remove("hidden");
1467
1755
  this.resetFlowLayout();
1756
+ if (!this.embedded && !this.isPhoneWindow())
1757
+ this.waitForFirstLayout();
1468
1758
  if (this.iframe) {
1469
1759
  this.iframe.src = verificationUrl;
1470
1760
  }
@@ -1474,16 +1764,10 @@ class VerificationModal {
1474
1764
  return;
1475
1765
  }
1476
1766
  this.overlay?.classList.add("active");
1477
- // Capture whatever overflow value is currently in effect (which may
1478
- // already be "hidden" because another modal is open) so close() can
1479
- // restore exactly that value instead of clobbering a scroll lock owned
1480
- // by a concurrently open modal. Skip the capture on a re-open: the value
1481
- // in effect is this modal's own lock, and previousBodyOverflow already
1482
- // holds the correct pre-lock value.
1483
- if (!wasAlreadyOpen) {
1484
- this.previousBodyOverflow = document.body.style.overflow;
1485
- }
1486
- document.body.style.overflow = "hidden";
1767
+ // Idempotent: a re-open of a modal that is still open keeps its one hold on the lock, so
1768
+ // close() still gives the page back the values it had before any modal opened.
1769
+ this.lockPageScroll();
1770
+ this.showCurtain();
1487
1771
  }
1488
1772
  close() {
1489
1773
  SDKLogger.log("Closing");
@@ -1501,8 +1785,8 @@ class VerificationModal {
1501
1785
  return;
1502
1786
  }
1503
1787
  this.overlay?.classList.remove("active");
1504
- document.body.style.overflow = this.previousBodyOverflow ?? "";
1505
- this.previousBodyOverflow = null;
1788
+ this.removeCurtain();
1789
+ this.unlockPageScroll();
1506
1790
  }
1507
1791
  destroy() {
1508
1792
  SDKLogger.log("Destroying");
@@ -1534,6 +1818,16 @@ class VerificationModal {
1534
1818
  * a transaction action modal stacked over the verification modal).
1535
1819
  */
1536
1820
  VerificationModal.openModals = [];
1821
+ /**
1822
+ * The page's own background colours, kept while full-screen modals lend it their ground, shared by
1823
+ * every open modal: the topmost one's ground shows and the last one to give it back restores them.
1824
+ */
1825
+ VerificationModal.pageBackground = null;
1826
+ /**
1827
+ * The page's scroll styles from before the first open modal locked them, shared by every open
1828
+ * modal: the last one to close gives them back.
1829
+ */
1830
+ VerificationModal.pageScrollLock = null;
1537
1831
 
1538
1832
  const DEFAULT_TRANSACTION_BASE_URL = "https://verification.didit.me";
1539
1833
  const ACTION_POLL_INTERVAL_MS = 1500;
@@ -1853,6 +2147,18 @@ function assertEmbeddedHostExists(configuration) {
1853
2147
  throw new Error(`Embedded container "#${containerId}" was not found in the page.`);
1854
2148
  }
1855
2149
  }
2150
+ /**
2151
+ * The device id this page already keeps for Didit (it has sent events, transactions or sign-ins),
2152
+ * or null. Reading it never creates one, and a browser that refuses the read is not an error.
2153
+ */
2154
+ function storedDeviceId() {
2155
+ try {
2156
+ return signals.getStoredDeviceId();
2157
+ }
2158
+ catch {
2159
+ return null;
2160
+ }
2161
+ }
1856
2162
  class DiditSdk {
1857
2163
  static get shared() {
1858
2164
  if (!DiditSdk._instance) {
@@ -1926,7 +2232,7 @@ class DiditSdk {
1926
2232
  onMessage: (event) => this.handleVerificationEvent(event),
1927
2233
  onIframeLoad: () => this.handleIframeLoad()
1928
2234
  });
1929
- this._url = buildVerificationUrl(url, config);
2235
+ this._url = buildVerificationUrl(url, config, storedDeviceId());
1930
2236
  this.setState("loading");
1931
2237
  this.emitInternalEvent("didit:started", {});
1932
2238
  this._modal?.open(this._url);