@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
  */
@@ -793,12 +793,13 @@
793
793
  closeIcon: "didit-close-icon",
794
794
  closeIconLegacy: "didit-close-icon-legacy",
795
795
  flowSized: "didit-flow-sized",
796
+ sizeAnimated: "didit-size-animated",
796
797
  loading: "didit-loading",
797
798
  confirmOverlay: "didit-confirm-overlay",
798
799
  confirmBox: "didit-confirm-box",
799
800
  embedded: "didit-embedded"
800
801
  };
801
- const SDK_VERSION = "0.5.1";
802
+ const SDK_VERSION = "0.5.3";
802
803
  /**
803
804
  * The permissions the verification iframe gets, in a modal and embedded:
804
805
  * camera and microphone for capture, clipboard-write for the flow's copy
@@ -826,7 +827,7 @@
826
827
  };
827
828
  /**
828
829
  * Posted by the hosted flow when it lays itself out for the modal, with
829
- * `data: { contentHeight, colorScheme?, dir? }`. The modal then grows to the
830
+ * `data: { contentHeight, colorScheme?, dir?, kind? }` (`kind` is `handoff` or `step`, `step` when missing). The modal then grows to the
830
831
  * handoff card on a computer and follows the content height in a narrow
831
832
  * window. Handled by the modal and never delivered to `onEvent`.
832
833
  */
@@ -1460,6 +1461,10 @@
1460
1461
  return translationsMap[language] ?? EN;
1461
1462
  }
1462
1463
 
1464
+ /** The length of the one animation when the flow moves from the handoff card to a step or back. */
1465
+ const SIZE_ANIMATION_MS = 300;
1466
+ /** How long the modal waits for the first layout before it shows at step size, so it can never hang. */
1467
+ const FIRST_LAYOUT_TIMEOUT_MS = 3000;
1463
1468
  class VerificationModal {
1464
1469
  constructor(configuration, callbacks) {
1465
1470
  this.state = {
@@ -1477,9 +1482,13 @@
1477
1482
  this.boundHandleKeydown = null;
1478
1483
  this.boundHandleFocusChange = null;
1479
1484
  this.confirmationFocusTimeout = null;
1485
+ this.firstLayoutTimeout = null;
1486
+ this.sizeTimeout = null;
1480
1487
  this.embedded = false;
1481
1488
  this.embeddedContainer = null;
1482
1489
  this.language = "en";
1490
+ /** The page's own background colours, kept while a full-screen modal paints over them. */
1491
+ this.pageBackground = null;
1483
1492
  /** body.style.overflow value observed right before this modal locked scroll, restored on close(). */
1484
1493
  this.previousBodyOverflow = null;
1485
1494
  this.modalId = generateModalId();
@@ -1524,9 +1533,9 @@
1524
1533
  .${CSS_CLASSES.container} {
1525
1534
  position: relative;
1526
1535
  width: 100%;
1527
- max-width: 500px;
1528
- max-height: 90vh;
1529
- max-height: 90dvh;
1536
+ max-width: 440px;
1537
+ height: min(860px, calc(100vh - 2rem));
1538
+ height: min(860px, calc(100dvh - 2rem));
1530
1539
  border-radius: 16px;
1531
1540
  overflow: hidden;
1532
1541
  background: transparent;
@@ -1538,9 +1547,7 @@
1538
1547
 
1539
1548
  .${CSS_CLASSES.iframe} {
1540
1549
  width: 100%;
1541
- height: 90vh;
1542
- height: 90dvh;
1543
- max-height: 700px;
1550
+ height: 100%;
1544
1551
  border: none;
1545
1552
  display: block;
1546
1553
  }
@@ -1581,6 +1588,12 @@
1581
1588
  z-index: 5;
1582
1589
  }
1583
1590
 
1591
+ @media (prefers-color-scheme: dark) {
1592
+ .${CSS_CLASSES.loading} {
1593
+ background: #0b0b0d;
1594
+ }
1595
+ }
1596
+
1584
1597
  .${CSS_CLASSES.loading}.hidden {
1585
1598
  display: none;
1586
1599
  }
@@ -1702,6 +1715,58 @@
1702
1715
  outline-offset: 2px;
1703
1716
  }
1704
1717
 
1718
+ /*
1719
+ * Steps are phone-sized (440 x 860, above). On a computer the handoff card is wider
1720
+ * (board Start-Embedded): 960 x 660 on a window of 1000px or more, never wider than the
1721
+ * window less its margin and never taller than 90% of it. In a narrower window the
1722
+ * page stacks and the height follows its content (--didit-content-height, set from the
1723
+ * flow's layout message). Until the flow reports what it shows, the modal is the handoff
1724
+ * card at its final size with the spinner inside it (the flow stays hidden and lays itself
1725
+ * out for that size): it never opens small and grows. The first change of kind (a step
1726
+ * instead of the handoff, or the person continues on this computer) animates once.
1727
+ */
1728
+ @media (min-width: 541px) {
1729
+ .${CSS_CLASSES.container}[data-didit-kind="handoff"],
1730
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] {
1731
+ max-width: min(960px, calc(100vw - 2rem));
1732
+ height: min(var(--didit-content-height, 660px), calc(100vh * 0.9));
1733
+ height: min(var(--didit-content-height, 660px), calc(100dvh * 0.9));
1734
+ }
1735
+
1736
+ .${CSS_CLASSES.container}.${CSS_CLASSES.sizeAnimated} {
1737
+ transition: max-width 0.25s ease, height 0.25s ease;
1738
+ }
1739
+
1740
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] .${CSS_CLASSES.iframe} {
1741
+ visibility: hidden;
1742
+ }
1743
+ }
1744
+
1745
+ /*
1746
+ * While pending the card already looks like the first screen (ground, radius, shadow and
1747
+ * close button come from the flow-sized rules below, with the device theme); the loader
1748
+ * sits inside it on the card's own ground.
1749
+ */
1750
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] .${CSS_CLASSES.loading} {
1751
+ background: transparent;
1752
+ }
1753
+
1754
+ .${CSS_CLASSES.container}[data-didit-kind="pending"][data-didit-theme="dark"] .${CSS_CLASSES.loading} circle {
1755
+ stroke: rgba(255, 255, 255, 0.16);
1756
+ }
1757
+
1758
+ .${CSS_CLASSES.container}[data-didit-kind="pending"][data-didit-theme="dark"] .${CSS_CLASSES.loading} path {
1759
+ stroke: #f5f5f7;
1760
+ }
1761
+
1762
+ @media (min-width: 1000px) {
1763
+ .${CSS_CLASSES.container}[data-didit-kind="handoff"],
1764
+ .${CSS_CLASSES.container}[data-didit-kind="pending"] {
1765
+ height: min(660px, calc(100vh * 0.9));
1766
+ height: min(660px, calc(100dvh * 0.9));
1767
+ }
1768
+ }
1769
+
1705
1770
  @media (max-width: 540px) {
1706
1771
  .${CSS_CLASSES.overlay} {
1707
1772
  padding: 0;
@@ -1709,23 +1774,16 @@
1709
1774
 
1710
1775
  .${CSS_CLASSES.container} {
1711
1776
  max-width: 100%;
1712
- max-height: 100vh;
1713
- max-height: 100dvh;
1714
- border-radius: 0;
1715
- }
1716
-
1717
- .${CSS_CLASSES.iframe} {
1718
1777
  height: 100vh;
1719
1778
  height: 100dvh;
1720
- max-height: none;
1779
+ border-radius: 0;
1721
1780
  }
1722
1781
  }
1723
1782
 
1724
1783
  /*
1725
- * Once the hosted flow reports its layout (didit:layout), the modal
1726
- * grows to the handoff card on a computer (960 x 660, at most 90% of
1727
- * the window) and follows the flow's content height in a narrow
1728
- * window. Colours are the design system tokens named beside them.
1784
+ * The hosted flow's layout message (didit:layout) brings the modal's size
1785
+ * (see above), theme and direction. Colours are the design system tokens
1786
+ * named beside them.
1729
1787
  */
1730
1788
  .${CSS_CLASSES.container}.${CSS_CLASSES.flowSized} {
1731
1789
  --didit-ground: #ffffff; /* site-ground */
@@ -1735,7 +1793,6 @@
1735
1793
  --didit-close-fill: rgba(0, 0, 0, 0.06);
1736
1794
  --didit-drop: rgba(17, 24, 39, 0.35);
1737
1795
  --didit-ring: rgba(0, 0, 0, 0.06);
1738
- max-width: 500px;
1739
1796
  background: var(--didit-ground);
1740
1797
  box-shadow: 0 30px 80px -24px var(--didit-drop), 0 0 0 1px var(--didit-ring);
1741
1798
  }
@@ -1750,12 +1807,6 @@
1750
1807
  --didit-ring: rgba(255, 255, 255, 0.08); /* c-shadow-pop, dark */
1751
1808
  }
1752
1809
 
1753
- .${CSS_CLASSES.flowSized} .${CSS_CLASSES.iframe} {
1754
- height: var(--didit-flow-height);
1755
- max-height: 90vh;
1756
- max-height: 90dvh;
1757
- }
1758
-
1759
1810
  .${CSS_CLASSES.closeIcon} {
1760
1811
  display: none;
1761
1812
  }
@@ -1829,28 +1880,11 @@
1829
1880
  flex-wrap: wrap;
1830
1881
  }
1831
1882
 
1832
- @media (min-width: 1024px) {
1833
- .${CSS_CLASSES.container}.${CSS_CLASSES.flowSized} {
1834
- width: 90vw;
1835
- max-width: 960px;
1836
- }
1837
-
1838
- .${CSS_CLASSES.flowSized} .${CSS_CLASSES.iframe} {
1839
- height: 660px;
1840
- }
1841
- }
1842
-
1843
1883
  @media (max-width: 540px) {
1844
1884
  .${CSS_CLASSES.container}.${CSS_CLASSES.flowSized} {
1845
1885
  max-width: 100%;
1846
1886
  box-shadow: none;
1847
1887
  }
1848
-
1849
- .${CSS_CLASSES.flowSized} .${CSS_CLASSES.iframe} {
1850
- height: 100vh;
1851
- height: 100dvh;
1852
- max-height: none;
1853
- }
1854
1888
  }
1855
1889
 
1856
1890
  .${CSS_CLASSES.embedded} {
@@ -2083,12 +2117,13 @@
2083
2117
  */
2084
2118
  readFlowLayout(data) {
2085
2119
  const fields = typeof data === "object" && data !== null ? data : {};
2086
- const { contentHeight, colorScheme, dir } = fields;
2120
+ const { contentHeight, colorScheme, dir, kind } = fields;
2087
2121
  if (typeof contentHeight !== "number" || !Number.isFinite(contentHeight) || contentHeight <= 0) {
2088
2122
  return null;
2089
2123
  }
2090
2124
  const prefersDark = window.matchMedia?.("(prefers-color-scheme: dark)").matches ?? false;
2091
2125
  return {
2126
+ kind: kind === "handoff" ? "handoff" : "step",
2092
2127
  contentHeight: Math.ceil(contentHeight),
2093
2128
  colorScheme: colorScheme === "light" || colorScheme === "dark" ? colorScheme : prefersDark ? "dark" : "light",
2094
2129
  dir: dir === "ltr" || dir === "rtl" ? dir : isRtlLanguage(this.language) ? "rtl" : "ltr"
@@ -2100,18 +2135,113 @@
2100
2135
  return;
2101
2136
  SDKLogger.log("Flow layout:", layout);
2102
2137
  this.container.classList.add(CSS_CLASSES.flowSized);
2103
- this.container.style.setProperty("--didit-flow-height", `${layout.contentHeight}px`);
2104
2138
  this.container.dataset.diditTheme = layout.colorScheme;
2105
2139
  this.container.dataset.diditDir = layout.dir;
2140
+ // The height the person sees now, before the reported content height can change it.
2141
+ const shownHeight = this.container.offsetHeight;
2142
+ this.container.style.setProperty("--didit-content-height", `${layout.contentHeight}px`);
2143
+ this.matchPageBackground(layout.colorScheme);
2144
+ this.setModalKind(layout.kind, layout.kind === "handoff" && this.handoffHeight(layout) === shownHeight);
2145
+ }
2146
+ /** Whether the window is a computer-sized one: a phone is full screen and never waits for a layout. */
2147
+ isPhoneWindow() {
2148
+ return window.matchMedia?.("(max-width: 540px)").matches ?? false;
2149
+ }
2150
+ /** The height the handoff card takes for a layout, as the size rules above compute it (rounded like offsetHeight). */
2151
+ handoffHeight(layout) {
2152
+ const cap = window.innerHeight * 0.9;
2153
+ return Math.round(Math.min(window.innerWidth >= 1000 ? 660 : layout.contentHeight, cap));
2154
+ }
2155
+ /**
2156
+ * Sets what the modal is sized for. Leaving "pending" shows the modal at its final size with no
2157
+ * transition; any later change animates once.
2158
+ */
2159
+ setModalKind(kind, sizeUnchanged = false) {
2160
+ if (!this.container)
2161
+ return;
2162
+ const previous = this.container.dataset.diditKind;
2163
+ if (previous === kind)
2164
+ return;
2165
+ if (this.firstLayoutTimeout !== null && kind !== "pending") {
2166
+ window.clearTimeout(this.firstLayoutTimeout);
2167
+ this.firstLayoutTimeout = null;
2168
+ }
2169
+ // Every change of kind animates, the pending card included (it is on screen), and only for the
2170
+ // length of the change, so resizing the window never lags behind.
2171
+ // Pending already is the handoff card: a handoff first layout of the same size moves nothing,
2172
+ // while a different reported height (a narrow window) animates the correction once.
2173
+ const staysPut = previous === "pending" && kind === "handoff" && sizeUnchanged;
2174
+ if (previous !== undefined && !staysPut)
2175
+ this.animateSizeOnce();
2176
+ this.container.dataset.diditKind = kind;
2177
+ // The final size is in place before the loader goes; a flow still loading keeps its loader.
2178
+ if (previous === "pending" && !this.state.isLoading)
2179
+ this.loadingEl?.classList.add("hidden");
2106
2180
  }
2107
- /** Back to the fixed 500 x 700 modal until the newly loaded flow reports its layout. */
2181
+ animateSizeOnce() {
2182
+ this.container?.classList.add(CSS_CLASSES.sizeAnimated);
2183
+ if (this.sizeTimeout !== null)
2184
+ window.clearTimeout(this.sizeTimeout);
2185
+ this.sizeTimeout = window.setTimeout(() => {
2186
+ this.sizeTimeout = null;
2187
+ this.container?.classList.remove(CSS_CLASSES.sizeAnimated);
2188
+ }, SIZE_ANIMATION_MS);
2189
+ }
2190
+ /** A flow that reports no layout (an older one) still shows, at step size, after a short wait. */
2191
+ waitForFirstLayout() {
2192
+ if (!this.container)
2193
+ return;
2194
+ // The card looks like the first screen from the first frame, in the device's theme.
2195
+ this.container.classList.add(CSS_CLASSES.flowSized);
2196
+ this.container.dataset.diditTheme = window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
2197
+ this.setModalKind("pending");
2198
+ this.firstLayoutTimeout = window.setTimeout(() => {
2199
+ this.firstLayoutTimeout = null;
2200
+ // A flow that never reported is an older one that paints itself: no card look around it.
2201
+ this.container?.classList.remove(CSS_CLASSES.flowSized);
2202
+ delete this.container?.dataset.diditTheme;
2203
+ this.setModalKind("step");
2204
+ }, FIRST_LAYOUT_TIMEOUT_MS);
2205
+ }
2206
+ /**
2207
+ * On a phone Safari paints the bottom edge of the screen with the page's own background, past
2208
+ * any fixed overlay, and shows it when the keyboard moves the page. A full-screen modal lends
2209
+ * the page its ground colour while it is open, so no strip of the host page shows around it.
2210
+ */
2211
+ matchPageBackground(colorScheme) {
2212
+ if (!window.matchMedia?.("(max-width: 540px)").matches)
2213
+ return;
2214
+ const root = document.documentElement;
2215
+ this.pageBackground ?? (this.pageBackground = { root: root.style.backgroundColor, body: document.body.style.backgroundColor });
2216
+ const ground = colorScheme === "dark" ? "#0b0b0d" : "#ffffff";
2217
+ root.style.backgroundColor = ground;
2218
+ document.body.style.backgroundColor = ground;
2219
+ }
2220
+ restorePageBackground() {
2221
+ if (!this.pageBackground)
2222
+ return;
2223
+ document.documentElement.style.backgroundColor = this.pageBackground.root;
2224
+ document.body.style.backgroundColor = this.pageBackground.body;
2225
+ this.pageBackground = null;
2226
+ }
2227
+ /** Back to the neutral look until the newly loaded flow reports its theme and direction. */
2108
2228
  resetFlowLayout() {
2109
2229
  if (this.embedded || !this.container)
2110
2230
  return;
2111
- this.container.classList.remove(CSS_CLASSES.flowSized);
2112
- this.container.style.removeProperty("--didit-flow-height");
2231
+ this.restorePageBackground();
2232
+ this.container.classList.remove(CSS_CLASSES.flowSized, CSS_CLASSES.sizeAnimated);
2113
2233
  delete this.container.dataset.diditTheme;
2114
2234
  delete this.container.dataset.diditDir;
2235
+ delete this.container.dataset.diditKind;
2236
+ this.container.style.removeProperty("--didit-content-height");
2237
+ if (this.firstLayoutTimeout !== null) {
2238
+ window.clearTimeout(this.firstLayoutTimeout);
2239
+ this.firstLayoutTimeout = null;
2240
+ }
2241
+ if (this.sizeTimeout !== null) {
2242
+ window.clearTimeout(this.sizeTimeout);
2243
+ this.sizeTimeout = null;
2244
+ }
2115
2245
  }
2116
2246
  handleKeydown(event) {
2117
2247
  if (!this.state.isOpen)
@@ -2147,7 +2277,9 @@
2147
2277
  handleIframeLoad() {
2148
2278
  if (this.iframe?.src && this.iframe.src !== "about:blank") {
2149
2279
  this.state.isLoading = false;
2150
- this.loadingEl?.classList.add("hidden");
2280
+ // A modal still waiting for its first layout keeps the loader over the hidden flow.
2281
+ if (this.container?.dataset.diditKind !== "pending")
2282
+ this.loadingEl?.classList.add("hidden");
2151
2283
  this.callbacks.onIframeLoad();
2152
2284
  }
2153
2285
  }
@@ -2236,6 +2368,8 @@
2236
2368
  this.hideConfirmation();
2237
2369
  this.loadingEl?.classList.remove("hidden");
2238
2370
  this.resetFlowLayout();
2371
+ if (!this.embedded && !this.isPhoneWindow())
2372
+ this.waitForFirstLayout();
2239
2373
  if (this.iframe) {
2240
2374
  this.iframe.src = verificationUrl;
2241
2375
  }