@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
  */
@@ -787,12 +787,13 @@ const CSS_CLASSES = {
787
787
  closeIcon: "didit-close-icon",
788
788
  closeIconLegacy: "didit-close-icon-legacy",
789
789
  flowSized: "didit-flow-sized",
790
+ sizeAnimated: "didit-size-animated",
790
791
  loading: "didit-loading",
791
792
  confirmOverlay: "didit-confirm-overlay",
792
793
  confirmBox: "didit-confirm-box",
793
794
  embedded: "didit-embedded"
794
795
  };
795
- const SDK_VERSION = "0.5.1";
796
+ const SDK_VERSION = "0.5.3";
796
797
  /**
797
798
  * The permissions the verification iframe gets, in a modal and embedded:
798
799
  * camera and microphone for capture, clipboard-write for the flow's copy
@@ -820,7 +821,7 @@ const PRESENTATION_QUERY_PARAMS = {
820
821
  };
821
822
  /**
822
823
  * Posted by the hosted flow when it lays itself out for the modal, with
823
- * `data: { contentHeight, colorScheme?, dir? }`. The modal then grows to the
824
+ * `data: { contentHeight, colorScheme?, dir?, kind? }` (`kind` is `handoff` or `step`, `step` when missing). The modal then grows to the
824
825
  * handoff card on a computer and follows the content height in a narrow
825
826
  * window. Handled by the modal and never delivered to `onEvent`.
826
827
  */
@@ -1454,6 +1455,10 @@ function getTranslations(language) {
1454
1455
  return translationsMap[language] ?? EN;
1455
1456
  }
1456
1457
 
1458
+ /** The length of the one animation when the flow moves from the handoff card to a step or back. */
1459
+ const SIZE_ANIMATION_MS = 300;
1460
+ /** How long the modal waits for the first layout before it shows at step size, so it can never hang. */
1461
+ const FIRST_LAYOUT_TIMEOUT_MS = 3000;
1457
1462
  class VerificationModal {
1458
1463
  constructor(configuration, callbacks) {
1459
1464
  this.state = {
@@ -1471,9 +1476,13 @@ class VerificationModal {
1471
1476
  this.boundHandleKeydown = null;
1472
1477
  this.boundHandleFocusChange = null;
1473
1478
  this.confirmationFocusTimeout = null;
1479
+ this.firstLayoutTimeout = null;
1480
+ this.sizeTimeout = null;
1474
1481
  this.embedded = false;
1475
1482
  this.embeddedContainer = null;
1476
1483
  this.language = "en";
1484
+ /** The page's own background colours, kept while a full-screen modal paints over them. */
1485
+ this.pageBackground = null;
1477
1486
  /** body.style.overflow value observed right before this modal locked scroll, restored on close(). */
1478
1487
  this.previousBodyOverflow = null;
1479
1488
  this.modalId = generateModalId();
@@ -1518,9 +1527,9 @@ class VerificationModal {
1518
1527
  .${CSS_CLASSES.container} {
1519
1528
  position: relative;
1520
1529
  width: 100%;
1521
- max-width: 500px;
1522
- max-height: 90vh;
1523
- max-height: 90dvh;
1530
+ max-width: 440px;
1531
+ height: min(860px, calc(100vh - 2rem));
1532
+ height: min(860px, calc(100dvh - 2rem));
1524
1533
  border-radius: 16px;
1525
1534
  overflow: hidden;
1526
1535
  background: transparent;
@@ -1532,9 +1541,7 @@ class VerificationModal {
1532
1541
 
1533
1542
  .${CSS_CLASSES.iframe} {
1534
1543
  width: 100%;
1535
- height: 90vh;
1536
- height: 90dvh;
1537
- max-height: 700px;
1544
+ height: 100%;
1538
1545
  border: none;
1539
1546
  display: block;
1540
1547
  }
@@ -1575,6 +1582,12 @@ class VerificationModal {
1575
1582
  z-index: 5;
1576
1583
  }
1577
1584
 
1585
+ @media (prefers-color-scheme: dark) {
1586
+ .${CSS_CLASSES.loading} {
1587
+ background: #0b0b0d;
1588
+ }
1589
+ }
1590
+
1578
1591
  .${CSS_CLASSES.loading}.hidden {
1579
1592
  display: none;
1580
1593
  }
@@ -1696,6 +1709,58 @@ class VerificationModal {
1696
1709
  outline-offset: 2px;
1697
1710
  }
1698
1711
 
1712
+ /*
1713
+ * Steps are phone-sized (440 x 860, above). On a computer the handoff card is wider
1714
+ * (board Start-Embedded): 960 x 660 on a window of 1000px or more, never wider than the
1715
+ * window less its margin and never taller than 90% of it. In a narrower window the
1716
+ * page stacks and the height follows its content (--didit-content-height, set from the
1717
+ * flow's layout message). Until the flow reports what it shows, the modal is the handoff
1718
+ * card at its final size with the spinner inside it (the flow stays hidden and lays itself
1719
+ * out for that size): it never opens small and grows. The first change of kind (a step
1720
+ * instead of the handoff, or the person continues on this computer) animates once.
1721
+ */
1722
+ @media (min-width: 541px) {
1723
+ .${CSS_CLASSES.container}[data-didit-kind="handoff"],
1724
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] {
1725
+ max-width: min(960px, calc(100vw - 2rem));
1726
+ height: min(var(--didit-content-height, 660px), calc(100vh * 0.9));
1727
+ height: min(var(--didit-content-height, 660px), calc(100dvh * 0.9));
1728
+ }
1729
+
1730
+ .${CSS_CLASSES.container}.${CSS_CLASSES.sizeAnimated} {
1731
+ transition: max-width 0.25s ease, height 0.25s ease;
1732
+ }
1733
+
1734
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] .${CSS_CLASSES.iframe} {
1735
+ visibility: hidden;
1736
+ }
1737
+ }
1738
+
1739
+ /*
1740
+ * While pending the card already looks like the first screen (ground, radius, shadow and
1741
+ * close button come from the flow-sized rules below, with the device theme); the loader
1742
+ * sits inside it on the card's own ground.
1743
+ */
1744
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] .${CSS_CLASSES.loading} {
1745
+ background: transparent;
1746
+ }
1747
+
1748
+ .${CSS_CLASSES.container}[data-didit-kind="pending"][data-didit-theme="dark"] .${CSS_CLASSES.loading} circle {
1749
+ stroke: rgba(255, 255, 255, 0.16);
1750
+ }
1751
+
1752
+ .${CSS_CLASSES.container}[data-didit-kind="pending"][data-didit-theme="dark"] .${CSS_CLASSES.loading} path {
1753
+ stroke: #f5f5f7;
1754
+ }
1755
+
1756
+ @media (min-width: 1000px) {
1757
+ .${CSS_CLASSES.container}[data-didit-kind="handoff"],
1758
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] {
1759
+ height: min(660px, calc(100vh * 0.9));
1760
+ height: min(660px, calc(100dvh * 0.9));
1761
+ }
1762
+ }
1763
+
1699
1764
  @media (max-width: 540px) {
1700
1765
  .${CSS_CLASSES.overlay} {
1701
1766
  padding: 0;
@@ -1703,23 +1768,16 @@ class VerificationModal {
1703
1768
 
1704
1769
  .${CSS_CLASSES.container} {
1705
1770
  max-width: 100%;
1706
- max-height: 100vh;
1707
- max-height: 100dvh;
1708
- border-radius: 0;
1709
- }
1710
-
1711
- .${CSS_CLASSES.iframe} {
1712
1771
  height: 100vh;
1713
1772
  height: 100dvh;
1714
- max-height: none;
1773
+ border-radius: 0;
1715
1774
  }
1716
1775
  }
1717
1776
 
1718
1777
  /*
1719
- * Once the hosted flow reports its layout (didit:layout), the modal
1720
- * grows to the handoff card on a computer (960 x 660, at most 90% of
1721
- * the window) and follows the flow's content height in a narrow
1722
- * window. Colours are the design system tokens named beside them.
1778
+ * The hosted flow's layout message (didit:layout) brings the modal's size
1779
+ * (see above), theme and direction. Colours are the design system tokens
1780
+ * named beside them.
1723
1781
  */
1724
1782
  .${CSS_CLASSES.container}.${CSS_CLASSES.flowSized} {
1725
1783
  --didit-ground: #ffffff; /* site-ground */
@@ -1729,7 +1787,6 @@ class VerificationModal {
1729
1787
  --didit-close-fill: rgba(0, 0, 0, 0.06);
1730
1788
  --didit-drop: rgba(17, 24, 39, 0.35);
1731
1789
  --didit-ring: rgba(0, 0, 0, 0.06);
1732
- max-width: 500px;
1733
1790
  background: var(--didit-ground);
1734
1791
  box-shadow: 0 30px 80px -24px var(--didit-drop), 0 0 0 1px var(--didit-ring);
1735
1792
  }
@@ -1744,12 +1801,6 @@ class VerificationModal {
1744
1801
  --didit-ring: rgba(255, 255, 255, 0.08); /* c-shadow-pop, dark */
1745
1802
  }
1746
1803
 
1747
- .${CSS_CLASSES.flowSized} .${CSS_CLASSES.iframe} {
1748
- height: var(--didit-flow-height);
1749
- max-height: 90vh;
1750
- max-height: 90dvh;
1751
- }
1752
-
1753
1804
  .${CSS_CLASSES.closeIcon} {
1754
1805
  display: none;
1755
1806
  }
@@ -1823,28 +1874,11 @@ class VerificationModal {
1823
1874
  flex-wrap: wrap;
1824
1875
  }
1825
1876
 
1826
- @media (min-width: 1024px) {
1827
- .${CSS_CLASSES.container}.${CSS_CLASSES.flowSized} {
1828
- width: 90vw;
1829
- max-width: 960px;
1830
- }
1831
-
1832
- .${CSS_CLASSES.flowSized} .${CSS_CLASSES.iframe} {
1833
- height: 660px;
1834
- }
1835
- }
1836
-
1837
1877
  @media (max-width: 540px) {
1838
1878
  .${CSS_CLASSES.container}.${CSS_CLASSES.flowSized} {
1839
1879
  max-width: 100%;
1840
1880
  box-shadow: none;
1841
1881
  }
1842
-
1843
- .${CSS_CLASSES.flowSized} .${CSS_CLASSES.iframe} {
1844
- height: 100vh;
1845
- height: 100dvh;
1846
- max-height: none;
1847
- }
1848
1882
  }
1849
1883
 
1850
1884
  .${CSS_CLASSES.embedded} {
@@ -2077,12 +2111,13 @@ class VerificationModal {
2077
2111
  */
2078
2112
  readFlowLayout(data) {
2079
2113
  const fields = typeof data === "object" && data !== null ? data : {};
2080
- const { contentHeight, colorScheme, dir } = fields;
2114
+ const { contentHeight, colorScheme, dir, kind } = fields;
2081
2115
  if (typeof contentHeight !== "number" || !Number.isFinite(contentHeight) || contentHeight <= 0) {
2082
2116
  return null;
2083
2117
  }
2084
2118
  const prefersDark = window.matchMedia?.("(prefers-color-scheme: dark)").matches ?? false;
2085
2119
  return {
2120
+ kind: kind === "handoff" ? "handoff" : "step",
2086
2121
  contentHeight: Math.ceil(contentHeight),
2087
2122
  colorScheme: colorScheme === "light" || colorScheme === "dark" ? colorScheme : prefersDark ? "dark" : "light",
2088
2123
  dir: dir === "ltr" || dir === "rtl" ? dir : isRtlLanguage(this.language) ? "rtl" : "ltr"
@@ -2094,18 +2129,113 @@ class VerificationModal {
2094
2129
  return;
2095
2130
  SDKLogger.log("Flow layout:", layout);
2096
2131
  this.container.classList.add(CSS_CLASSES.flowSized);
2097
- this.container.style.setProperty("--didit-flow-height", `${layout.contentHeight}px`);
2098
2132
  this.container.dataset.diditTheme = layout.colorScheme;
2099
2133
  this.container.dataset.diditDir = layout.dir;
2134
+ // The height the person sees now, before the reported content height can change it.
2135
+ const shownHeight = this.container.offsetHeight;
2136
+ this.container.style.setProperty("--didit-content-height", `${layout.contentHeight}px`);
2137
+ this.matchPageBackground(layout.colorScheme);
2138
+ this.setModalKind(layout.kind, layout.kind === "handoff" && this.handoffHeight(layout) === shownHeight);
2139
+ }
2140
+ /** Whether the window is a computer-sized one: a phone is full screen and never waits for a layout. */
2141
+ isPhoneWindow() {
2142
+ return window.matchMedia?.("(max-width: 540px)").matches ?? false;
2143
+ }
2144
+ /** The height the handoff card takes for a layout, as the size rules above compute it (rounded like offsetHeight). */
2145
+ handoffHeight(layout) {
2146
+ const cap = window.innerHeight * 0.9;
2147
+ return Math.round(Math.min(window.innerWidth >= 1000 ? 660 : layout.contentHeight, cap));
2148
+ }
2149
+ /**
2150
+ * Sets what the modal is sized for. Leaving "pending" shows the modal at its final size with no
2151
+ * transition; any later change animates once.
2152
+ */
2153
+ setModalKind(kind, sizeUnchanged = false) {
2154
+ if (!this.container)
2155
+ return;
2156
+ const previous = this.container.dataset.diditKind;
2157
+ if (previous === kind)
2158
+ return;
2159
+ if (this.firstLayoutTimeout !== null && kind !== "pending") {
2160
+ window.clearTimeout(this.firstLayoutTimeout);
2161
+ this.firstLayoutTimeout = null;
2162
+ }
2163
+ // Every change of kind animates, the pending card included (it is on screen), and only for the
2164
+ // length of the change, so resizing the window never lags behind.
2165
+ // Pending already is the handoff card: a handoff first layout of the same size moves nothing,
2166
+ // while a different reported height (a narrow window) animates the correction once.
2167
+ const staysPut = previous === "pending" && kind === "handoff" && sizeUnchanged;
2168
+ if (previous !== undefined && !staysPut)
2169
+ this.animateSizeOnce();
2170
+ this.container.dataset.diditKind = kind;
2171
+ // The final size is in place before the loader goes; a flow still loading keeps its loader.
2172
+ if (previous === "pending" && !this.state.isLoading)
2173
+ this.loadingEl?.classList.add("hidden");
2100
2174
  }
2101
- /** Back to the fixed 500 x 700 modal until the newly loaded flow reports its layout. */
2175
+ animateSizeOnce() {
2176
+ this.container?.classList.add(CSS_CLASSES.sizeAnimated);
2177
+ if (this.sizeTimeout !== null)
2178
+ window.clearTimeout(this.sizeTimeout);
2179
+ this.sizeTimeout = window.setTimeout(() => {
2180
+ this.sizeTimeout = null;
2181
+ this.container?.classList.remove(CSS_CLASSES.sizeAnimated);
2182
+ }, SIZE_ANIMATION_MS);
2183
+ }
2184
+ /** A flow that reports no layout (an older one) still shows, at step size, after a short wait. */
2185
+ waitForFirstLayout() {
2186
+ if (!this.container)
2187
+ return;
2188
+ // The card looks like the first screen from the first frame, in the device's theme.
2189
+ this.container.classList.add(CSS_CLASSES.flowSized);
2190
+ this.container.dataset.diditTheme = window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
2191
+ this.setModalKind("pending");
2192
+ this.firstLayoutTimeout = window.setTimeout(() => {
2193
+ this.firstLayoutTimeout = null;
2194
+ // A flow that never reported is an older one that paints itself: no card look around it.
2195
+ this.container?.classList.remove(CSS_CLASSES.flowSized);
2196
+ delete this.container?.dataset.diditTheme;
2197
+ this.setModalKind("step");
2198
+ }, FIRST_LAYOUT_TIMEOUT_MS);
2199
+ }
2200
+ /**
2201
+ * On a phone Safari paints the bottom edge of the screen with the page's own background, past
2202
+ * any fixed overlay, and shows it when the keyboard moves the page. A full-screen modal lends
2203
+ * the page its ground colour while it is open, so no strip of the host page shows around it.
2204
+ */
2205
+ matchPageBackground(colorScheme) {
2206
+ if (!window.matchMedia?.("(max-width: 540px)").matches)
2207
+ return;
2208
+ const root = document.documentElement;
2209
+ this.pageBackground ?? (this.pageBackground = { root: root.style.backgroundColor, body: document.body.style.backgroundColor });
2210
+ const ground = colorScheme === "dark" ? "#0b0b0d" : "#ffffff";
2211
+ root.style.backgroundColor = ground;
2212
+ document.body.style.backgroundColor = ground;
2213
+ }
2214
+ restorePageBackground() {
2215
+ if (!this.pageBackground)
2216
+ return;
2217
+ document.documentElement.style.backgroundColor = this.pageBackground.root;
2218
+ document.body.style.backgroundColor = this.pageBackground.body;
2219
+ this.pageBackground = null;
2220
+ }
2221
+ /** Back to the neutral look until the newly loaded flow reports its theme and direction. */
2102
2222
  resetFlowLayout() {
2103
2223
  if (this.embedded || !this.container)
2104
2224
  return;
2105
- this.container.classList.remove(CSS_CLASSES.flowSized);
2106
- this.container.style.removeProperty("--didit-flow-height");
2225
+ this.restorePageBackground();
2226
+ this.container.classList.remove(CSS_CLASSES.flowSized, CSS_CLASSES.sizeAnimated);
2107
2227
  delete this.container.dataset.diditTheme;
2108
2228
  delete this.container.dataset.diditDir;
2229
+ delete this.container.dataset.diditKind;
2230
+ this.container.style.removeProperty("--didit-content-height");
2231
+ if (this.firstLayoutTimeout !== null) {
2232
+ window.clearTimeout(this.firstLayoutTimeout);
2233
+ this.firstLayoutTimeout = null;
2234
+ }
2235
+ if (this.sizeTimeout !== null) {
2236
+ window.clearTimeout(this.sizeTimeout);
2237
+ this.sizeTimeout = null;
2238
+ }
2109
2239
  }
2110
2240
  handleKeydown(event) {
2111
2241
  if (!this.state.isOpen)
@@ -2141,7 +2271,9 @@ class VerificationModal {
2141
2271
  handleIframeLoad() {
2142
2272
  if (this.iframe?.src && this.iframe.src !== "about:blank") {
2143
2273
  this.state.isLoading = false;
2144
- this.loadingEl?.classList.add("hidden");
2274
+ // A modal still waiting for its first layout keeps the loader over the hidden flow.
2275
+ if (this.container?.dataset.diditKind !== "pending")
2276
+ this.loadingEl?.classList.add("hidden");
2145
2277
  this.callbacks.onIframeLoad();
2146
2278
  }
2147
2279
  }
@@ -2230,6 +2362,8 @@ class VerificationModal {
2230
2362
  this.hideConfirmation();
2231
2363
  this.loadingEl?.classList.remove("hidden");
2232
2364
  this.resetFlowLayout();
2365
+ if (!this.embedded && !this.isPhoneWindow())
2366
+ this.waitForFirstLayout();
2233
2367
  if (this.iframe) {
2234
2368
  this.iframe.src = verificationUrl;
2235
2369
  }