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