@soliton-id/web-sdk 1.3.0 → 1.4.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/CHANGELOG.md CHANGED
@@ -4,6 +4,21 @@ All notable changes to `@soliton-id/web-sdk`. The `soliton-v1` postMessage
4
4
  protocol is frozen: changes are additive only, so older SDK versions keep
5
5
  working against the hosted flow.
6
6
 
7
+ ## 1.4.0 — 2026-11-11
8
+
9
+ Additive only. Calls without the new option are unchanged, as are the
10
+ `soliton-v1` and `idv-v1` protocols.
11
+
12
+ - `open()` takes an optional `theme` on both the default and the
13
+ `/white-label` import: light and dark color palettes for the hosted
14
+ verification screens, the camera screen (`cameraBackground`, `oval`,
15
+ `ovalProgress`), the overlay backdrop and the close button
16
+ (`closeButton`), plus `colorScheme` (`auto`, `light` or `dark`). Colors are
17
+ opaque hex (`#rgb` or `#rrggbb`); anything else is ignored with one console
18
+ warning and never stops `open()`. Only the light flashes during the check
19
+ keep their own colors. Exports `VerificationTheme`, `ThemeColors` and
20
+ `ThemeColorKey`. Needs the matching hosted verification release.
21
+
7
22
  ## 1.3.0 — 2026-11-09
8
23
 
9
24
  Additive only. The default import, its `open()` and the `soliton-v1`
package/README.md CHANGED
@@ -191,7 +191,7 @@ const handle = open({
191
191
  },
192
192
  onError: ({ code, message }) => {
193
193
  // link_expired | link_invalid | origin_not_allowed |
194
- // storage_unavailable | internal | load_timeout
194
+ // storage_unavailable | link_already_used | capture_failed | internal | load_timeout
195
195
  },
196
196
  onClose: () => {
197
197
  // The flow closed before completion (dismissal or initial load timeout).
@@ -361,7 +361,16 @@ attempt ended, not that verification passed; fetch the verdict server-to-server.
361
361
  terminal state. It carries ONLY the verification id, never a verdict.
362
362
  - `onError({ code, message })`: flow-level errors (`link_expired`,
363
363
  `link_invalid`, `origin_not_allowed`, `storage_unavailable` when the user's
364
- browser blocks the session storage the flow needs, `internal`). The overlay
364
+ browser blocks the session storage the flow needs, `link_already_used` when
365
+ the capture was already started from this link in another browser or on
366
+ another device, or the check had already finished when this browser came back
367
+ to it (a reload or a new tab in the same browser otherwise continues the
368
+ capture; start a new session for the user), `capture_failed` when the
369
+ capture could not be completed on this device (its last try never reached
370
+ Soliton, so there is no verdict; the check stays open and expires unfinished;
371
+ start a new session for the user), `internal`). Using up the tries
372
+ ends with `onComplete`, as after a final failed take, not with an error. The
373
+ overlay
365
374
  stays open so the hosted page can show its own error card; call
366
375
  `handle.close()` if you want it gone. If the frame has not become ready or
367
376
  reported an error within 30 seconds, `load_timeout` is emitted instead and
package/dist/core.d.ts CHANGED
@@ -39,6 +39,8 @@ export interface OpenOptions {
39
39
  }) => void;
40
40
  onClose?: () => void;
41
41
  locale?: string;
42
+ /** Untrusted input: pre-filtered by prepareTheme, never trusted as typed. */
43
+ theme?: unknown;
42
44
  }
43
45
  export interface OpenHandle {
44
46
  close(): void;
package/dist/index.cjs CHANGED
@@ -27,11 +27,192 @@ __export(index_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(index_exports);
29
29
 
30
+ // sdk/src/theme.ts
31
+ var MAX_THEME_PARAM_LENGTH = 4096;
32
+ var COLOR_KEYS = {
33
+ background: true,
34
+ surface: true,
35
+ surfaceMuted: true,
36
+ text: true,
37
+ textMuted: true,
38
+ border: true,
39
+ primary: true,
40
+ primaryPressed: true,
41
+ onPrimary: true,
42
+ accent: true,
43
+ progress: true,
44
+ success: true,
45
+ warning: true,
46
+ error: true,
47
+ illustration: true,
48
+ overlay: true,
49
+ cameraBackground: true,
50
+ oval: true,
51
+ ovalProgress: true,
52
+ closeButton: true
53
+ };
54
+ var COLOR_KEY_ORDER = Object.keys(COLOR_KEYS);
55
+ var COLOR_SCHEMES = ["auto", "light", "dark"];
56
+ var HEX_COLOR_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
57
+ var MAX_LISTED = 20;
58
+ var MAX_LISTED_NAME = 40;
59
+ var hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
60
+ function isRecord(value) {
61
+ return typeof value === "object" && value !== null && !Array.isArray(value);
62
+ }
63
+ function isUnset(value) {
64
+ return value === void 0 || value === null;
65
+ }
66
+ function isHexColor(value) {
67
+ return typeof value === "string" && value.length <= 7 && HEX_COLOR_RE.test(value);
68
+ }
69
+ function filterPalette(value, path, ignored) {
70
+ if (!isRecord(value)) {
71
+ ignored.push(path);
72
+ return void 0;
73
+ }
74
+ const valid = {};
75
+ for (const key of Object.keys(value)) {
76
+ const color = value[key];
77
+ if (isUnset(color)) continue;
78
+ if (hasOwn(COLOR_KEYS, key) && isHexColor(color)) {
79
+ valid[key] = color;
80
+ } else {
81
+ ignored.push(`${path}.${key}`);
82
+ }
83
+ }
84
+ const out = {};
85
+ let kept = false;
86
+ for (const key of COLOR_KEY_ORDER) {
87
+ const color = valid[key];
88
+ if (color !== void 0) {
89
+ out[key] = color;
90
+ kept = true;
91
+ }
92
+ }
93
+ return kept ? out : void 0;
94
+ }
95
+ function filterTheme(input, ignored) {
96
+ let colorScheme;
97
+ let colors;
98
+ let darkColors;
99
+ for (const key of Object.keys(input)) {
100
+ const value = input[key];
101
+ if (isUnset(value)) continue;
102
+ if (key === "colorScheme") {
103
+ if (typeof value === "string" && COLOR_SCHEMES.indexOf(value) !== -1) {
104
+ colorScheme = value;
105
+ } else {
106
+ ignored.push(key);
107
+ }
108
+ } else if (key === "colors") {
109
+ colors = filterPalette(value, key, ignored);
110
+ } else if (key === "darkColors") {
111
+ darkColors = filterPalette(value, key, ignored);
112
+ } else {
113
+ ignored.push(key);
114
+ }
115
+ }
116
+ if (colorScheme === void 0 && colors === void 0 && darkColors === void 0) {
117
+ return null;
118
+ }
119
+ const theme = {};
120
+ if (colorScheme !== void 0) theme.colorScheme = colorScheme;
121
+ if (colors !== void 0) theme.colors = colors;
122
+ if (darkColors !== void 0) theme.darkColors = darkColors;
123
+ return theme;
124
+ }
125
+ function listNames(names) {
126
+ const shown = names.slice(0, MAX_LISTED).map((name) => name.length > MAX_LISTED_NAME ? `${name.slice(0, MAX_LISTED_NAME)}...` : name);
127
+ const more = names.length - shown.length;
128
+ return shown.join(", ") + (more > 0 ? ` and ${more} more` : "");
129
+ }
130
+ function warn(message) {
131
+ try {
132
+ if (typeof console !== "undefined" && typeof console.warn === "function") {
133
+ console.warn(message);
134
+ }
135
+ } catch (e) {
136
+ }
137
+ }
138
+ function prepareTheme(source, warnPrefix, maxLength = MAX_THEME_PARAM_LENGTH) {
139
+ const ignored = [];
140
+ let theme = null;
141
+ let whole = "";
142
+ try {
143
+ const input = source.theme;
144
+ if (isUnset(input)) return { theme: null, param: null };
145
+ if (isRecord(input)) {
146
+ theme = filterTheme(input, ignored);
147
+ } else {
148
+ whole = "it is not an object";
149
+ }
150
+ } catch (e) {
151
+ theme = null;
152
+ whole = "it could not be read";
153
+ }
154
+ let param = null;
155
+ if (theme !== null) {
156
+ const json = JSON.stringify(theme);
157
+ if (json.length > maxLength) {
158
+ theme = null;
159
+ whole = `it is longer than ${maxLength} characters`;
160
+ } else {
161
+ param = json;
162
+ }
163
+ }
164
+ if (whole !== "") {
165
+ warn(`${warnPrefix} theme ignored: ${whole}.`);
166
+ } else if (ignored.length > 0) {
167
+ warn(
168
+ `${warnPrefix} theme: ignored ${listNames(ignored)}. Colors must be "#rgb" or "#rrggbb" and colorScheme "auto", "light" or "dark".`
169
+ );
170
+ }
171
+ return { theme, param };
172
+ }
173
+ function prefersDark() {
174
+ try {
175
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: dark)").matches === true;
176
+ } catch (e) {
177
+ return false;
178
+ }
179
+ }
180
+ function activePalette(theme) {
181
+ var _a;
182
+ if (theme === null) return void 0;
183
+ const scheme = (_a = theme.colorScheme) != null ? _a : "auto";
184
+ const dark = scheme === "dark" || scheme === "auto" && prefersDark();
185
+ return dark ? theme.darkColors : theme.colors;
186
+ }
187
+ function relativeLuminance(hex) {
188
+ const digits = hex.length === 4 ? hex.slice(1).split("").map((digit) => digit + digit).join("") : hex.slice(1);
189
+ const channel = (offset) => {
190
+ const value = parseInt(digits.slice(offset, offset + 2), 16) / 255;
191
+ return value <= 0.04045 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);
192
+ };
193
+ return 0.2126 * channel(0) + 0.7152 * channel(2) + 0.0722 * channel(4);
194
+ }
195
+ function contrastRatio(a, b) {
196
+ const la = relativeLuminance(a);
197
+ const lb = relativeLuminance(b);
198
+ return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
199
+ }
200
+
30
201
  // sdk/src/overlay.ts
31
202
  var MAX_Z_INDEX = "2147483647";
203
+ var DEFAULT_BACKDROP = "#0f110b";
204
+ var DEFAULT_CLOSE_FILL = "rgba(0,0,0,0.45)";
205
+ var LIGHT_INK = { hex: "#ffffff", rgb: "255,255,255" };
206
+ var DARK_INK = { hex: DEFAULT_BACKDROP, rgb: "15,17,11" };
207
+ function inkOn(backdrop) {
208
+ return contrastRatio(DARK_INK.hex, backdrop) > contrastRatio(LIGHT_INK.hex, backdrop) ? DARK_INK.rgb : LIGHT_INK.rgb;
209
+ }
32
210
  var openOverlayCount = 0;
33
211
  var savedBodyOverflow = "";
34
- function createOverlay(iframeSrc, onCloseClick, names) {
212
+ function createOverlay(iframeSrc, onCloseClick, names, backdrop, closeFill) {
213
+ const background = backdrop != null ? backdrop : DEFAULT_BACKDROP;
214
+ const ink = backdrop === void 0 ? LIGHT_INK.rgb : inkOn(backdrop);
215
+ const closeInk = closeFill === void 0 ? LIGHT_INK.rgb : inkOn(closeFill);
35
216
  const doc = document;
36
217
  const container = doc.createElement("div");
37
218
  container.setAttribute(names.marker, "overlay");
@@ -39,7 +220,7 @@ function createOverlay(iframeSrc, onCloseClick, names) {
39
220
  "position:fixed",
40
221
  "inset:0",
41
222
  `z-index:${MAX_Z_INDEX}`,
42
- "background:#0f110b",
223
+ `background:${background}`,
43
224
  "display:block"
44
225
  ].join(";");
45
226
  const style = doc.createElement("style");
@@ -55,7 +236,7 @@ function createOverlay(iframeSrc, onCloseClick, names) {
55
236
  "align-items:center",
56
237
  "justify-content:center",
57
238
  "gap:14px",
58
- "color:rgba(255,255,255,0.75)",
239
+ `color:rgba(${ink},0.75)`,
59
240
  "font:14px/1.4 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif"
60
241
  ].join(";");
61
242
  const spinner = doc.createElement("div");
@@ -63,8 +244,8 @@ function createOverlay(iframeSrc, onCloseClick, names) {
63
244
  "width:22px",
64
245
  "height:22px",
65
246
  "border-radius:999px",
66
- "border:2px solid rgba(255,255,255,0.25)",
67
- "border-top-color:rgba(255,255,255,0.9)",
247
+ `border:2px solid rgba(${ink},0.25)`,
248
+ `border-top-color:rgba(${ink},0.9)`,
68
249
  `animation:${names.animation} 0.8s linear infinite`
69
250
  ].join(";");
70
251
  const loadingText = doc.createElement("div");
@@ -96,9 +277,9 @@ function createOverlay(iframeSrc, onCloseClick, names) {
96
277
  "width:36px",
97
278
  "height:36px",
98
279
  "border-radius:999px",
99
- "border:1px solid rgba(255,255,255,0.3)",
100
- "background:rgba(0,0,0,0.45)",
101
- "color:rgba(255,255,255,0.85)",
280
+ `border:1px solid rgba(${closeInk},0.3)`,
281
+ `background:${closeFill != null ? closeFill : DEFAULT_CLOSE_FILL}`,
282
+ `color:rgba(${closeInk},0.85)`,
102
283
  "font:20px/1 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif",
103
284
  "cursor:pointer",
104
285
  "padding:0"
@@ -148,12 +329,21 @@ function openOverlay(options, names, parseUrl) {
148
329
  src.searchParams.set("sdk", "1");
149
330
  for (const [key, value] of (_a = names.params) != null ? _a : []) src.searchParams.set(key, value);
150
331
  if (options.locale) src.searchParams.set("locale", options.locale);
332
+ const theme = prepareTheme(options, names.errorPrefix);
333
+ if (theme.param !== null) src.searchParams.set("theme", theme.param);
151
334
  let closed = false;
152
335
  let terminalDelivered = false;
153
336
  let loadTimedOut = false;
154
337
  let autoCloseTimer = null;
155
338
  let readyTimer = null;
156
- const overlay = createOverlay(src.toString(), () => close(), names.overlay);
339
+ const palette = activePalette(theme.theme);
340
+ const overlay = createOverlay(
341
+ src.toString(),
342
+ () => close(),
343
+ names.overlay,
344
+ palette == null ? void 0 : palette.overlay,
345
+ palette == null ? void 0 : palette.closeButton
346
+ );
157
347
  let helloPings = 0;
158
348
  const postHello = () => {
159
349
  var _a2;
package/dist/index.d.ts CHANGED
@@ -15,8 +15,10 @@
15
15
  * public/sdk/v1/soliton-web-sdk.esm.js ESM, `import { open } ...`
16
16
  * sdk/dist/index.mjs + index.cjs npm package `@soliton-id/web-sdk`
17
17
  */
18
+ import type { ThemeColorKey, ThemeColors, VerificationTheme } from "./theme";
18
19
  import type { SolitonVerifyHandle, SolitonVerifyOptions } from "./types";
19
20
  export type { SolitonVerifyHandle, SolitonVerifyOptions };
21
+ export type { ThemeColorKey, ThemeColors, VerificationTheme };
20
22
  export declare function open(options: SolitonVerifyOptions): SolitonVerifyHandle;
21
23
  export declare const SolitonVerify: {
22
24
  open: typeof open;
package/dist/index.mjs CHANGED
@@ -1,10 +1,191 @@
1
1
  /* Soliton Web SDK v1. Built from sdk/src via `npm run build:sdk`; do not edit by hand. */
2
2
 
3
+ // sdk/src/theme.ts
4
+ var MAX_THEME_PARAM_LENGTH = 4096;
5
+ var COLOR_KEYS = {
6
+ background: true,
7
+ surface: true,
8
+ surfaceMuted: true,
9
+ text: true,
10
+ textMuted: true,
11
+ border: true,
12
+ primary: true,
13
+ primaryPressed: true,
14
+ onPrimary: true,
15
+ accent: true,
16
+ progress: true,
17
+ success: true,
18
+ warning: true,
19
+ error: true,
20
+ illustration: true,
21
+ overlay: true,
22
+ cameraBackground: true,
23
+ oval: true,
24
+ ovalProgress: true,
25
+ closeButton: true
26
+ };
27
+ var COLOR_KEY_ORDER = Object.keys(COLOR_KEYS);
28
+ var COLOR_SCHEMES = ["auto", "light", "dark"];
29
+ var HEX_COLOR_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
30
+ var MAX_LISTED = 20;
31
+ var MAX_LISTED_NAME = 40;
32
+ var hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
33
+ function isRecord(value) {
34
+ return typeof value === "object" && value !== null && !Array.isArray(value);
35
+ }
36
+ function isUnset(value) {
37
+ return value === void 0 || value === null;
38
+ }
39
+ function isHexColor(value) {
40
+ return typeof value === "string" && value.length <= 7 && HEX_COLOR_RE.test(value);
41
+ }
42
+ function filterPalette(value, path, ignored) {
43
+ if (!isRecord(value)) {
44
+ ignored.push(path);
45
+ return void 0;
46
+ }
47
+ const valid = {};
48
+ for (const key of Object.keys(value)) {
49
+ const color = value[key];
50
+ if (isUnset(color)) continue;
51
+ if (hasOwn(COLOR_KEYS, key) && isHexColor(color)) {
52
+ valid[key] = color;
53
+ } else {
54
+ ignored.push(`${path}.${key}`);
55
+ }
56
+ }
57
+ const out = {};
58
+ let kept = false;
59
+ for (const key of COLOR_KEY_ORDER) {
60
+ const color = valid[key];
61
+ if (color !== void 0) {
62
+ out[key] = color;
63
+ kept = true;
64
+ }
65
+ }
66
+ return kept ? out : void 0;
67
+ }
68
+ function filterTheme(input, ignored) {
69
+ let colorScheme;
70
+ let colors;
71
+ let darkColors;
72
+ for (const key of Object.keys(input)) {
73
+ const value = input[key];
74
+ if (isUnset(value)) continue;
75
+ if (key === "colorScheme") {
76
+ if (typeof value === "string" && COLOR_SCHEMES.indexOf(value) !== -1) {
77
+ colorScheme = value;
78
+ } else {
79
+ ignored.push(key);
80
+ }
81
+ } else if (key === "colors") {
82
+ colors = filterPalette(value, key, ignored);
83
+ } else if (key === "darkColors") {
84
+ darkColors = filterPalette(value, key, ignored);
85
+ } else {
86
+ ignored.push(key);
87
+ }
88
+ }
89
+ if (colorScheme === void 0 && colors === void 0 && darkColors === void 0) {
90
+ return null;
91
+ }
92
+ const theme = {};
93
+ if (colorScheme !== void 0) theme.colorScheme = colorScheme;
94
+ if (colors !== void 0) theme.colors = colors;
95
+ if (darkColors !== void 0) theme.darkColors = darkColors;
96
+ return theme;
97
+ }
98
+ function listNames(names) {
99
+ const shown = names.slice(0, MAX_LISTED).map((name) => name.length > MAX_LISTED_NAME ? `${name.slice(0, MAX_LISTED_NAME)}...` : name);
100
+ const more = names.length - shown.length;
101
+ return shown.join(", ") + (more > 0 ? ` and ${more} more` : "");
102
+ }
103
+ function warn(message) {
104
+ try {
105
+ if (typeof console !== "undefined" && typeof console.warn === "function") {
106
+ console.warn(message);
107
+ }
108
+ } catch (e) {
109
+ }
110
+ }
111
+ function prepareTheme(source, warnPrefix, maxLength = MAX_THEME_PARAM_LENGTH) {
112
+ const ignored = [];
113
+ let theme = null;
114
+ let whole = "";
115
+ try {
116
+ const input = source.theme;
117
+ if (isUnset(input)) return { theme: null, param: null };
118
+ if (isRecord(input)) {
119
+ theme = filterTheme(input, ignored);
120
+ } else {
121
+ whole = "it is not an object";
122
+ }
123
+ } catch (e) {
124
+ theme = null;
125
+ whole = "it could not be read";
126
+ }
127
+ let param = null;
128
+ if (theme !== null) {
129
+ const json = JSON.stringify(theme);
130
+ if (json.length > maxLength) {
131
+ theme = null;
132
+ whole = `it is longer than ${maxLength} characters`;
133
+ } else {
134
+ param = json;
135
+ }
136
+ }
137
+ if (whole !== "") {
138
+ warn(`${warnPrefix} theme ignored: ${whole}.`);
139
+ } else if (ignored.length > 0) {
140
+ warn(
141
+ `${warnPrefix} theme: ignored ${listNames(ignored)}. Colors must be "#rgb" or "#rrggbb" and colorScheme "auto", "light" or "dark".`
142
+ );
143
+ }
144
+ return { theme, param };
145
+ }
146
+ function prefersDark() {
147
+ try {
148
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: dark)").matches === true;
149
+ } catch (e) {
150
+ return false;
151
+ }
152
+ }
153
+ function activePalette(theme) {
154
+ var _a;
155
+ if (theme === null) return void 0;
156
+ const scheme = (_a = theme.colorScheme) != null ? _a : "auto";
157
+ const dark = scheme === "dark" || scheme === "auto" && prefersDark();
158
+ return dark ? theme.darkColors : theme.colors;
159
+ }
160
+ function relativeLuminance(hex) {
161
+ const digits = hex.length === 4 ? hex.slice(1).split("").map((digit) => digit + digit).join("") : hex.slice(1);
162
+ const channel = (offset) => {
163
+ const value = parseInt(digits.slice(offset, offset + 2), 16) / 255;
164
+ return value <= 0.04045 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);
165
+ };
166
+ return 0.2126 * channel(0) + 0.7152 * channel(2) + 0.0722 * channel(4);
167
+ }
168
+ function contrastRatio(a, b) {
169
+ const la = relativeLuminance(a);
170
+ const lb = relativeLuminance(b);
171
+ return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
172
+ }
173
+
3
174
  // sdk/src/overlay.ts
4
175
  var MAX_Z_INDEX = "2147483647";
176
+ var DEFAULT_BACKDROP = "#0f110b";
177
+ var DEFAULT_CLOSE_FILL = "rgba(0,0,0,0.45)";
178
+ var LIGHT_INK = { hex: "#ffffff", rgb: "255,255,255" };
179
+ var DARK_INK = { hex: DEFAULT_BACKDROP, rgb: "15,17,11" };
180
+ function inkOn(backdrop) {
181
+ return contrastRatio(DARK_INK.hex, backdrop) > contrastRatio(LIGHT_INK.hex, backdrop) ? DARK_INK.rgb : LIGHT_INK.rgb;
182
+ }
5
183
  var openOverlayCount = 0;
6
184
  var savedBodyOverflow = "";
7
- function createOverlay(iframeSrc, onCloseClick, names) {
185
+ function createOverlay(iframeSrc, onCloseClick, names, backdrop, closeFill) {
186
+ const background = backdrop != null ? backdrop : DEFAULT_BACKDROP;
187
+ const ink = backdrop === void 0 ? LIGHT_INK.rgb : inkOn(backdrop);
188
+ const closeInk = closeFill === void 0 ? LIGHT_INK.rgb : inkOn(closeFill);
8
189
  const doc = document;
9
190
  const container = doc.createElement("div");
10
191
  container.setAttribute(names.marker, "overlay");
@@ -12,7 +193,7 @@ function createOverlay(iframeSrc, onCloseClick, names) {
12
193
  "position:fixed",
13
194
  "inset:0",
14
195
  `z-index:${MAX_Z_INDEX}`,
15
- "background:#0f110b",
196
+ `background:${background}`,
16
197
  "display:block"
17
198
  ].join(";");
18
199
  const style = doc.createElement("style");
@@ -28,7 +209,7 @@ function createOverlay(iframeSrc, onCloseClick, names) {
28
209
  "align-items:center",
29
210
  "justify-content:center",
30
211
  "gap:14px",
31
- "color:rgba(255,255,255,0.75)",
212
+ `color:rgba(${ink},0.75)`,
32
213
  "font:14px/1.4 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif"
33
214
  ].join(";");
34
215
  const spinner = doc.createElement("div");
@@ -36,8 +217,8 @@ function createOverlay(iframeSrc, onCloseClick, names) {
36
217
  "width:22px",
37
218
  "height:22px",
38
219
  "border-radius:999px",
39
- "border:2px solid rgba(255,255,255,0.25)",
40
- "border-top-color:rgba(255,255,255,0.9)",
220
+ `border:2px solid rgba(${ink},0.25)`,
221
+ `border-top-color:rgba(${ink},0.9)`,
41
222
  `animation:${names.animation} 0.8s linear infinite`
42
223
  ].join(";");
43
224
  const loadingText = doc.createElement("div");
@@ -69,9 +250,9 @@ function createOverlay(iframeSrc, onCloseClick, names) {
69
250
  "width:36px",
70
251
  "height:36px",
71
252
  "border-radius:999px",
72
- "border:1px solid rgba(255,255,255,0.3)",
73
- "background:rgba(0,0,0,0.45)",
74
- "color:rgba(255,255,255,0.85)",
253
+ `border:1px solid rgba(${closeInk},0.3)`,
254
+ `background:${closeFill != null ? closeFill : DEFAULT_CLOSE_FILL}`,
255
+ `color:rgba(${closeInk},0.85)`,
75
256
  "font:20px/1 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif",
76
257
  "cursor:pointer",
77
258
  "padding:0"
@@ -121,12 +302,21 @@ function openOverlay(options, names, parseUrl) {
121
302
  src.searchParams.set("sdk", "1");
122
303
  for (const [key, value] of (_a = names.params) != null ? _a : []) src.searchParams.set(key, value);
123
304
  if (options.locale) src.searchParams.set("locale", options.locale);
305
+ const theme = prepareTheme(options, names.errorPrefix);
306
+ if (theme.param !== null) src.searchParams.set("theme", theme.param);
124
307
  let closed = false;
125
308
  let terminalDelivered = false;
126
309
  let loadTimedOut = false;
127
310
  let autoCloseTimer = null;
128
311
  let readyTimer = null;
129
- const overlay = createOverlay(src.toString(), () => close(), names.overlay);
312
+ const palette = activePalette(theme.theme);
313
+ const overlay = createOverlay(
314
+ src.toString(),
315
+ () => close(),
316
+ names.overlay,
317
+ palette == null ? void 0 : palette.overlay,
318
+ palette == null ? void 0 : palette.closeButton
319
+ );
130
320
  let helloPings = 0;
131
321
  const postHello = () => {
132
322
  var _a2;
package/dist/overlay.d.ts CHANGED
@@ -26,4 +26,8 @@ export interface Overlay {
26
26
  /** Remove the overlay from the DOM and restore body scroll. Idempotent. */
27
27
  destroy(): void;
28
28
  }
29
- export declare function createOverlay(iframeSrc: string, onCloseClick: () => void, names: OverlayNames): Overlay;
29
+ /**
30
+ * `backdrop` and `closeFill` are already validated opaque hex colors ("#rgb"
31
+ * / "#rrggbb") from the theme, or undefined for the defaults.
32
+ */
33
+ export declare function createOverlay(iframeSrc: string, onCloseClick: () => void, names: OverlayNames, backdrop?: string, closeFill?: string): Overlay;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Optional colors for the hosted verification screens: the public types, the
3
+ * pre-filter applied before a theme goes on the iframe URL as its `theme`
4
+ * query parameter, and the colors of the overlay's own backdrop and close
5
+ * button.
6
+ *
7
+ * The pre-filter applies the hosted page's own rules, so an integrator sees
8
+ * in the console what was ignored: known keys only, opaque "#rgb" or
9
+ * "#rrggbb" strings only, colorScheme in its enum. Everything else is dropped
10
+ * with one console.warn. Nothing here throws: a theme must never stop or
11
+ * delay a verification. The hosted page validates the parameter again, so
12
+ * this is a courtesy, not a security boundary.
13
+ *
14
+ * Shared by every SDK entry: keep it free of any entry's names.
15
+ */
16
+ /** Names of the colors a theme can set. */
17
+ export type ThemeColorKey = "background" | "surface" | "surfaceMuted" | "text" | "textMuted" | "border" | "primary" | "primaryPressed" | "onPrimary" | "accent" | "progress" | "success" | "warning" | "error" | "illustration" | "overlay" | "cameraBackground" | "oval" | "ovalProgress" | "closeButton";
18
+ /** Colors as opaque hex strings, "#rgb" or "#rrggbb". Unknown keys and other values are ignored. */
19
+ export type ThemeColors = Partial<Record<ThemeColorKey, string>>;
20
+ /**
21
+ * Colors for the hosted verification screens, the camera screen and the close
22
+ * button included. Only the light flashes during the check keep their own
23
+ * colors.
24
+ */
25
+ export interface VerificationTheme {
26
+ /** "auto" (the default) follows the device's light or dark setting. */
27
+ colorScheme?: "auto" | "light" | "dark";
28
+ /** Light palette. The camera screen always uses this one. */
29
+ colors?: ThemeColors;
30
+ /** Dark palette. */
31
+ darkColors?: ThemeColors;
32
+ }
33
+ /** The pre-filtered theme and its query parameter value; both null when nothing valid remains. */
34
+ export interface PreparedTheme {
35
+ theme: VerificationTheme | null;
36
+ param: string | null;
37
+ }
38
+ /** Longest `theme` parameter value the hosted page accepts. */
39
+ export declare const MAX_THEME_PARAM_LENGTH = 4096;
40
+ /**
41
+ * Pre-filter `source.theme` and serialize what remains. Never throws; warns
42
+ * once (prefixed with `warnPrefix`) when anything was ignored. An unset theme
43
+ * (undefined or null) is silently absent.
44
+ */
45
+ export declare function prepareTheme(source: {
46
+ theme?: unknown;
47
+ }, warnPrefix: string, maxLength?: number): PreparedTheme;
48
+ /**
49
+ * The palette active when open() runs: colorScheme "light" or "dark" forces
50
+ * one, "auto" (the default) follows the device. A light value is never
51
+ * carried into the dark scheme. Asks no media query without a theme.
52
+ */
53
+ export declare function activePalette(theme: VerificationTheme | null): ThemeColors | undefined;
54
+ /** The active palette's `overlay` color, or undefined when it sets none. */
55
+ export declare function overlayBackdrop(theme: VerificationTheme | null): string | undefined;
56
+ /** The active palette's `closeButton` color, or undefined when it sets none. */
57
+ export declare function closeButtonFill(theme: VerificationTheme | null): string | undefined;
58
+ /** WCAG relative luminance of an opaque "#rgb" or "#rrggbb" color. */
59
+ export declare function relativeLuminance(hex: string): number;
60
+ /** WCAG contrast ratio between two opaque hex colors (1 to 21). */
61
+ export declare function contrastRatio(a: string, b: string): number;
package/dist/types.d.ts CHANGED
@@ -11,6 +11,7 @@
11
11
  * are safe. Never rename a type, never remove or retype a field, and never
12
12
  * add payload fields the wrapper is required to understand.
13
13
  */
14
+ import type { VerificationTheme } from "./theme";
14
15
  export interface SolitonVerifyOptions {
15
16
  /**
16
17
  * Hosted URL from the v1 verification API or v2 session link API. Choose
@@ -37,8 +38,17 @@ export interface SolitonVerifyOptions {
37
38
  verificationId: string;
38
39
  }) => void;
39
40
  /** Flow-level errors: link_expired, link_invalid, origin_not_allowed,
40
- * storage_unavailable, link_unavailable, consent_required, internal,
41
- * load_timeout. consent_required means your account requires consent, you
41
+ * storage_unavailable, link_unavailable, link_already_used,
42
+ * consent_required, capture_failed, internal, load_timeout. link_already_used means the
43
+ * capture was already started from this link in another browser or device,
44
+ * or the check had already finished when this browser came back to it (a
45
+ * reload or a new tab in the same browser otherwise continues it): start a
46
+ * new session for the user. Using up the tries ends with onComplete, as
47
+ * after a final failed take. capture_failed means the capture could not be
48
+ * completed on this device (its last try never reached the server): there is
49
+ * no verdict, the check stays open and expires unfinished; start a new
50
+ * session for the user.
51
+ * consent_required means your account requires consent, you
42
52
  * skipped the instructions screen (intro=skip) and sent none, and the account
43
53
  * is set to refuse such checks. A load_timeout closes the overlay after this
44
54
  * callback and invokes onClose, never onComplete. */
@@ -50,6 +60,12 @@ export interface SolitonVerifyOptions {
50
60
  onClose?: () => void;
51
61
  /** Reserved; passed through to the hosted page as a query param. */
52
62
  locale?: string;
63
+ /**
64
+ * Optional colors for the hosted verification screens, the camera screen
65
+ * and the close button included. Only the light flashes during the check
66
+ * keep their own colors.
67
+ */
68
+ theme?: VerificationTheme;
53
69
  }
54
70
  export interface SolitonVerifyHandle {
55
71
  close(): void;
@@ -42,11 +42,192 @@ __export(white_label_exports, {
42
42
  });
43
43
  module.exports = __toCommonJS(white_label_exports);
44
44
 
45
+ // sdk/src/theme.ts
46
+ var MAX_THEME_PARAM_LENGTH = 4096;
47
+ var COLOR_KEYS = {
48
+ background: true,
49
+ surface: true,
50
+ surfaceMuted: true,
51
+ text: true,
52
+ textMuted: true,
53
+ border: true,
54
+ primary: true,
55
+ primaryPressed: true,
56
+ onPrimary: true,
57
+ accent: true,
58
+ progress: true,
59
+ success: true,
60
+ warning: true,
61
+ error: true,
62
+ illustration: true,
63
+ overlay: true,
64
+ cameraBackground: true,
65
+ oval: true,
66
+ ovalProgress: true,
67
+ closeButton: true
68
+ };
69
+ var COLOR_KEY_ORDER = Object.keys(COLOR_KEYS);
70
+ var COLOR_SCHEMES = ["auto", "light", "dark"];
71
+ var HEX_COLOR_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
72
+ var MAX_LISTED = 20;
73
+ var MAX_LISTED_NAME = 40;
74
+ var hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
75
+ function isRecord(value) {
76
+ return typeof value === "object" && value !== null && !Array.isArray(value);
77
+ }
78
+ function isUnset(value) {
79
+ return value === void 0 || value === null;
80
+ }
81
+ function isHexColor(value) {
82
+ return typeof value === "string" && value.length <= 7 && HEX_COLOR_RE.test(value);
83
+ }
84
+ function filterPalette(value, path, ignored) {
85
+ if (!isRecord(value)) {
86
+ ignored.push(path);
87
+ return void 0;
88
+ }
89
+ const valid = {};
90
+ for (const key of Object.keys(value)) {
91
+ const color = value[key];
92
+ if (isUnset(color)) continue;
93
+ if (hasOwn(COLOR_KEYS, key) && isHexColor(color)) {
94
+ valid[key] = color;
95
+ } else {
96
+ ignored.push(`${path}.${key}`);
97
+ }
98
+ }
99
+ const out = {};
100
+ let kept = false;
101
+ for (const key of COLOR_KEY_ORDER) {
102
+ const color = valid[key];
103
+ if (color !== void 0) {
104
+ out[key] = color;
105
+ kept = true;
106
+ }
107
+ }
108
+ return kept ? out : void 0;
109
+ }
110
+ function filterTheme(input, ignored) {
111
+ let colorScheme;
112
+ let colors;
113
+ let darkColors;
114
+ for (const key of Object.keys(input)) {
115
+ const value = input[key];
116
+ if (isUnset(value)) continue;
117
+ if (key === "colorScheme") {
118
+ if (typeof value === "string" && COLOR_SCHEMES.indexOf(value) !== -1) {
119
+ colorScheme = value;
120
+ } else {
121
+ ignored.push(key);
122
+ }
123
+ } else if (key === "colors") {
124
+ colors = filterPalette(value, key, ignored);
125
+ } else if (key === "darkColors") {
126
+ darkColors = filterPalette(value, key, ignored);
127
+ } else {
128
+ ignored.push(key);
129
+ }
130
+ }
131
+ if (colorScheme === void 0 && colors === void 0 && darkColors === void 0) {
132
+ return null;
133
+ }
134
+ const theme = {};
135
+ if (colorScheme !== void 0) theme.colorScheme = colorScheme;
136
+ if (colors !== void 0) theme.colors = colors;
137
+ if (darkColors !== void 0) theme.darkColors = darkColors;
138
+ return theme;
139
+ }
140
+ function listNames(names) {
141
+ const shown = names.slice(0, MAX_LISTED).map((name) => name.length > MAX_LISTED_NAME ? `${name.slice(0, MAX_LISTED_NAME)}...` : name);
142
+ const more = names.length - shown.length;
143
+ return shown.join(", ") + (more > 0 ? ` and ${more} more` : "");
144
+ }
145
+ function warn(message) {
146
+ try {
147
+ if (typeof console !== "undefined" && typeof console.warn === "function") {
148
+ console.warn(message);
149
+ }
150
+ } catch (e) {
151
+ }
152
+ }
153
+ function prepareTheme(source, warnPrefix, maxLength = MAX_THEME_PARAM_LENGTH) {
154
+ const ignored = [];
155
+ let theme = null;
156
+ let whole = "";
157
+ try {
158
+ const input = source.theme;
159
+ if (isUnset(input)) return { theme: null, param: null };
160
+ if (isRecord(input)) {
161
+ theme = filterTheme(input, ignored);
162
+ } else {
163
+ whole = "it is not an object";
164
+ }
165
+ } catch (e) {
166
+ theme = null;
167
+ whole = "it could not be read";
168
+ }
169
+ let param = null;
170
+ if (theme !== null) {
171
+ const json = JSON.stringify(theme);
172
+ if (json.length > maxLength) {
173
+ theme = null;
174
+ whole = `it is longer than ${maxLength} characters`;
175
+ } else {
176
+ param = json;
177
+ }
178
+ }
179
+ if (whole !== "") {
180
+ warn(`${warnPrefix} theme ignored: ${whole}.`);
181
+ } else if (ignored.length > 0) {
182
+ warn(
183
+ `${warnPrefix} theme: ignored ${listNames(ignored)}. Colors must be "#rgb" or "#rrggbb" and colorScheme "auto", "light" or "dark".`
184
+ );
185
+ }
186
+ return { theme, param };
187
+ }
188
+ function prefersDark() {
189
+ try {
190
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: dark)").matches === true;
191
+ } catch (e) {
192
+ return false;
193
+ }
194
+ }
195
+ function activePalette(theme) {
196
+ var _a;
197
+ if (theme === null) return void 0;
198
+ const scheme = (_a = theme.colorScheme) != null ? _a : "auto";
199
+ const dark = scheme === "dark" || scheme === "auto" && prefersDark();
200
+ return dark ? theme.darkColors : theme.colors;
201
+ }
202
+ function relativeLuminance(hex) {
203
+ const digits = hex.length === 4 ? hex.slice(1).split("").map((digit) => digit + digit).join("") : hex.slice(1);
204
+ const channel = (offset) => {
205
+ const value = parseInt(digits.slice(offset, offset + 2), 16) / 255;
206
+ return value <= 0.04045 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);
207
+ };
208
+ return 0.2126 * channel(0) + 0.7152 * channel(2) + 0.0722 * channel(4);
209
+ }
210
+ function contrastRatio(a, b) {
211
+ const la = relativeLuminance(a);
212
+ const lb = relativeLuminance(b);
213
+ return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
214
+ }
215
+
45
216
  // sdk/src/overlay.ts
46
217
  var MAX_Z_INDEX = "2147483647";
218
+ var DEFAULT_BACKDROP = "#0f110b";
219
+ var DEFAULT_CLOSE_FILL = "rgba(0,0,0,0.45)";
220
+ var LIGHT_INK = { hex: "#ffffff", rgb: "255,255,255" };
221
+ var DARK_INK = { hex: DEFAULT_BACKDROP, rgb: "15,17,11" };
222
+ function inkOn(backdrop) {
223
+ return contrastRatio(DARK_INK.hex, backdrop) > contrastRatio(LIGHT_INK.hex, backdrop) ? DARK_INK.rgb : LIGHT_INK.rgb;
224
+ }
47
225
  var openOverlayCount = 0;
48
226
  var savedBodyOverflow = "";
49
- function createOverlay(iframeSrc, onCloseClick, names) {
227
+ function createOverlay(iframeSrc, onCloseClick, names, backdrop, closeFill) {
228
+ const background = backdrop != null ? backdrop : DEFAULT_BACKDROP;
229
+ const ink = backdrop === void 0 ? LIGHT_INK.rgb : inkOn(backdrop);
230
+ const closeInk = closeFill === void 0 ? LIGHT_INK.rgb : inkOn(closeFill);
50
231
  const doc = document;
51
232
  const container = doc.createElement("div");
52
233
  container.setAttribute(names.marker, "overlay");
@@ -54,7 +235,7 @@ function createOverlay(iframeSrc, onCloseClick, names) {
54
235
  "position:fixed",
55
236
  "inset:0",
56
237
  `z-index:${MAX_Z_INDEX}`,
57
- "background:#0f110b",
238
+ `background:${background}`,
58
239
  "display:block"
59
240
  ].join(";");
60
241
  const style = doc.createElement("style");
@@ -70,7 +251,7 @@ function createOverlay(iframeSrc, onCloseClick, names) {
70
251
  "align-items:center",
71
252
  "justify-content:center",
72
253
  "gap:14px",
73
- "color:rgba(255,255,255,0.75)",
254
+ `color:rgba(${ink},0.75)`,
74
255
  "font:14px/1.4 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif"
75
256
  ].join(";");
76
257
  const spinner = doc.createElement("div");
@@ -78,8 +259,8 @@ function createOverlay(iframeSrc, onCloseClick, names) {
78
259
  "width:22px",
79
260
  "height:22px",
80
261
  "border-radius:999px",
81
- "border:2px solid rgba(255,255,255,0.25)",
82
- "border-top-color:rgba(255,255,255,0.9)",
262
+ `border:2px solid rgba(${ink},0.25)`,
263
+ `border-top-color:rgba(${ink},0.9)`,
83
264
  `animation:${names.animation} 0.8s linear infinite`
84
265
  ].join(";");
85
266
  const loadingText = doc.createElement("div");
@@ -111,9 +292,9 @@ function createOverlay(iframeSrc, onCloseClick, names) {
111
292
  "width:36px",
112
293
  "height:36px",
113
294
  "border-radius:999px",
114
- "border:1px solid rgba(255,255,255,0.3)",
115
- "background:rgba(0,0,0,0.45)",
116
- "color:rgba(255,255,255,0.85)",
295
+ `border:1px solid rgba(${closeInk},0.3)`,
296
+ `background:${closeFill != null ? closeFill : DEFAULT_CLOSE_FILL}`,
297
+ `color:rgba(${closeInk},0.85)`,
117
298
  "font:20px/1 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif",
118
299
  "cursor:pointer",
119
300
  "padding:0"
@@ -163,12 +344,21 @@ function openOverlay(options, names, parseUrl) {
163
344
  src.searchParams.set("sdk", "1");
164
345
  for (const [key, value] of (_a = names.params) != null ? _a : []) src.searchParams.set(key, value);
165
346
  if (options.locale) src.searchParams.set("locale", options.locale);
347
+ const theme = prepareTheme(options, names.errorPrefix);
348
+ if (theme.param !== null) src.searchParams.set("theme", theme.param);
166
349
  let closed = false;
167
350
  let terminalDelivered = false;
168
351
  let loadTimedOut = false;
169
352
  let autoCloseTimer = null;
170
353
  let readyTimer = null;
171
- const overlay = createOverlay(src.toString(), () => close(), names.overlay);
354
+ const palette = activePalette(theme.theme);
355
+ const overlay = createOverlay(
356
+ src.toString(),
357
+ () => close(),
358
+ names.overlay,
359
+ palette == null ? void 0 : palette.overlay,
360
+ palette == null ? void 0 : palette.closeButton
361
+ );
172
362
  let helloPings = 0;
173
363
  const postHello = () => {
174
364
  var _a2;
@@ -17,6 +17,8 @@
17
17
  * Keep this module and everything it imports free of the default entry's
18
18
  * names: sdk/build.mjs fails the build if its output contains them.
19
19
  */
20
+ import type { ThemeColorKey, ThemeColors, VerificationTheme } from "./theme";
21
+ export type { ThemeColorKey, ThemeColors, VerificationTheme };
20
22
  export interface VerificationOptions {
21
23
  /**
22
24
  * Hosted verification URL minted by your backend. Its origin must equal
@@ -39,8 +41,17 @@ export interface VerificationOptions {
39
41
  verificationId: string;
40
42
  }) => void;
41
43
  /** Flow-level errors: link_expired, link_invalid, origin_not_allowed,
42
- * storage_unavailable, link_unavailable, consent_required, internal,
43
- * load_timeout. A load_timeout closes the overlay after this callback and
44
+ * storage_unavailable, link_unavailable, link_already_used,
45
+ * consent_required, capture_failed, internal, load_timeout. link_already_used means the
46
+ * capture was already started from this link in another browser or device,
47
+ * or the check had already finished when this browser came back to it (a
48
+ * reload or a new tab in the same browser otherwise continues it): start a
49
+ * new session for the user. Using up the tries ends with onComplete, as
50
+ * after a final failed take. capture_failed means the capture could not be
51
+ * completed on this device (its last try never reached the server): there is
52
+ * no verdict, the check stays open and expires unfinished; start a new
53
+ * session for the user.
54
+ * A load_timeout closes the overlay after this callback and
44
55
  * invokes onClose, never onComplete. */
45
56
  onError?: (e: {
46
57
  code: string;
@@ -52,6 +63,12 @@ export interface VerificationOptions {
52
63
  locale?: string;
53
64
  /** Accessible title of the iframe. Defaults to "Identity verification". */
54
65
  title?: string;
66
+ /**
67
+ * Optional colors for the hosted verification screens, the camera screen
68
+ * and the close button included. Only the light flashes during the check
69
+ * keep their own colors.
70
+ */
71
+ theme?: VerificationTheme;
55
72
  }
56
73
  export interface VerificationHandle {
57
74
  close(): void;
@@ -18,11 +18,192 @@ var __spreadValues = (a, b) => {
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
 
21
+ // sdk/src/theme.ts
22
+ var MAX_THEME_PARAM_LENGTH = 4096;
23
+ var COLOR_KEYS = {
24
+ background: true,
25
+ surface: true,
26
+ surfaceMuted: true,
27
+ text: true,
28
+ textMuted: true,
29
+ border: true,
30
+ primary: true,
31
+ primaryPressed: true,
32
+ onPrimary: true,
33
+ accent: true,
34
+ progress: true,
35
+ success: true,
36
+ warning: true,
37
+ error: true,
38
+ illustration: true,
39
+ overlay: true,
40
+ cameraBackground: true,
41
+ oval: true,
42
+ ovalProgress: true,
43
+ closeButton: true
44
+ };
45
+ var COLOR_KEY_ORDER = Object.keys(COLOR_KEYS);
46
+ var COLOR_SCHEMES = ["auto", "light", "dark"];
47
+ var HEX_COLOR_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
48
+ var MAX_LISTED = 20;
49
+ var MAX_LISTED_NAME = 40;
50
+ var hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
51
+ function isRecord(value) {
52
+ return typeof value === "object" && value !== null && !Array.isArray(value);
53
+ }
54
+ function isUnset(value) {
55
+ return value === void 0 || value === null;
56
+ }
57
+ function isHexColor(value) {
58
+ return typeof value === "string" && value.length <= 7 && HEX_COLOR_RE.test(value);
59
+ }
60
+ function filterPalette(value, path, ignored) {
61
+ if (!isRecord(value)) {
62
+ ignored.push(path);
63
+ return void 0;
64
+ }
65
+ const valid = {};
66
+ for (const key of Object.keys(value)) {
67
+ const color = value[key];
68
+ if (isUnset(color)) continue;
69
+ if (hasOwn(COLOR_KEYS, key) && isHexColor(color)) {
70
+ valid[key] = color;
71
+ } else {
72
+ ignored.push(`${path}.${key}`);
73
+ }
74
+ }
75
+ const out = {};
76
+ let kept = false;
77
+ for (const key of COLOR_KEY_ORDER) {
78
+ const color = valid[key];
79
+ if (color !== void 0) {
80
+ out[key] = color;
81
+ kept = true;
82
+ }
83
+ }
84
+ return kept ? out : void 0;
85
+ }
86
+ function filterTheme(input, ignored) {
87
+ let colorScheme;
88
+ let colors;
89
+ let darkColors;
90
+ for (const key of Object.keys(input)) {
91
+ const value = input[key];
92
+ if (isUnset(value)) continue;
93
+ if (key === "colorScheme") {
94
+ if (typeof value === "string" && COLOR_SCHEMES.indexOf(value) !== -1) {
95
+ colorScheme = value;
96
+ } else {
97
+ ignored.push(key);
98
+ }
99
+ } else if (key === "colors") {
100
+ colors = filterPalette(value, key, ignored);
101
+ } else if (key === "darkColors") {
102
+ darkColors = filterPalette(value, key, ignored);
103
+ } else {
104
+ ignored.push(key);
105
+ }
106
+ }
107
+ if (colorScheme === void 0 && colors === void 0 && darkColors === void 0) {
108
+ return null;
109
+ }
110
+ const theme = {};
111
+ if (colorScheme !== void 0) theme.colorScheme = colorScheme;
112
+ if (colors !== void 0) theme.colors = colors;
113
+ if (darkColors !== void 0) theme.darkColors = darkColors;
114
+ return theme;
115
+ }
116
+ function listNames(names) {
117
+ const shown = names.slice(0, MAX_LISTED).map((name) => name.length > MAX_LISTED_NAME ? `${name.slice(0, MAX_LISTED_NAME)}...` : name);
118
+ const more = names.length - shown.length;
119
+ return shown.join(", ") + (more > 0 ? ` and ${more} more` : "");
120
+ }
121
+ function warn(message) {
122
+ try {
123
+ if (typeof console !== "undefined" && typeof console.warn === "function") {
124
+ console.warn(message);
125
+ }
126
+ } catch (e) {
127
+ }
128
+ }
129
+ function prepareTheme(source, warnPrefix, maxLength = MAX_THEME_PARAM_LENGTH) {
130
+ const ignored = [];
131
+ let theme = null;
132
+ let whole = "";
133
+ try {
134
+ const input = source.theme;
135
+ if (isUnset(input)) return { theme: null, param: null };
136
+ if (isRecord(input)) {
137
+ theme = filterTheme(input, ignored);
138
+ } else {
139
+ whole = "it is not an object";
140
+ }
141
+ } catch (e) {
142
+ theme = null;
143
+ whole = "it could not be read";
144
+ }
145
+ let param = null;
146
+ if (theme !== null) {
147
+ const json = JSON.stringify(theme);
148
+ if (json.length > maxLength) {
149
+ theme = null;
150
+ whole = `it is longer than ${maxLength} characters`;
151
+ } else {
152
+ param = json;
153
+ }
154
+ }
155
+ if (whole !== "") {
156
+ warn(`${warnPrefix} theme ignored: ${whole}.`);
157
+ } else if (ignored.length > 0) {
158
+ warn(
159
+ `${warnPrefix} theme: ignored ${listNames(ignored)}. Colors must be "#rgb" or "#rrggbb" and colorScheme "auto", "light" or "dark".`
160
+ );
161
+ }
162
+ return { theme, param };
163
+ }
164
+ function prefersDark() {
165
+ try {
166
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: dark)").matches === true;
167
+ } catch (e) {
168
+ return false;
169
+ }
170
+ }
171
+ function activePalette(theme) {
172
+ var _a;
173
+ if (theme === null) return void 0;
174
+ const scheme = (_a = theme.colorScheme) != null ? _a : "auto";
175
+ const dark = scheme === "dark" || scheme === "auto" && prefersDark();
176
+ return dark ? theme.darkColors : theme.colors;
177
+ }
178
+ function relativeLuminance(hex) {
179
+ const digits = hex.length === 4 ? hex.slice(1).split("").map((digit) => digit + digit).join("") : hex.slice(1);
180
+ const channel = (offset) => {
181
+ const value = parseInt(digits.slice(offset, offset + 2), 16) / 255;
182
+ return value <= 0.04045 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);
183
+ };
184
+ return 0.2126 * channel(0) + 0.7152 * channel(2) + 0.0722 * channel(4);
185
+ }
186
+ function contrastRatio(a, b) {
187
+ const la = relativeLuminance(a);
188
+ const lb = relativeLuminance(b);
189
+ return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
190
+ }
191
+
21
192
  // sdk/src/overlay.ts
22
193
  var MAX_Z_INDEX = "2147483647";
194
+ var DEFAULT_BACKDROP = "#0f110b";
195
+ var DEFAULT_CLOSE_FILL = "rgba(0,0,0,0.45)";
196
+ var LIGHT_INK = { hex: "#ffffff", rgb: "255,255,255" };
197
+ var DARK_INK = { hex: DEFAULT_BACKDROP, rgb: "15,17,11" };
198
+ function inkOn(backdrop) {
199
+ return contrastRatio(DARK_INK.hex, backdrop) > contrastRatio(LIGHT_INK.hex, backdrop) ? DARK_INK.rgb : LIGHT_INK.rgb;
200
+ }
23
201
  var openOverlayCount = 0;
24
202
  var savedBodyOverflow = "";
25
- function createOverlay(iframeSrc, onCloseClick, names) {
203
+ function createOverlay(iframeSrc, onCloseClick, names, backdrop, closeFill) {
204
+ const background = backdrop != null ? backdrop : DEFAULT_BACKDROP;
205
+ const ink = backdrop === void 0 ? LIGHT_INK.rgb : inkOn(backdrop);
206
+ const closeInk = closeFill === void 0 ? LIGHT_INK.rgb : inkOn(closeFill);
26
207
  const doc = document;
27
208
  const container = doc.createElement("div");
28
209
  container.setAttribute(names.marker, "overlay");
@@ -30,7 +211,7 @@ function createOverlay(iframeSrc, onCloseClick, names) {
30
211
  "position:fixed",
31
212
  "inset:0",
32
213
  `z-index:${MAX_Z_INDEX}`,
33
- "background:#0f110b",
214
+ `background:${background}`,
34
215
  "display:block"
35
216
  ].join(";");
36
217
  const style = doc.createElement("style");
@@ -46,7 +227,7 @@ function createOverlay(iframeSrc, onCloseClick, names) {
46
227
  "align-items:center",
47
228
  "justify-content:center",
48
229
  "gap:14px",
49
- "color:rgba(255,255,255,0.75)",
230
+ `color:rgba(${ink},0.75)`,
50
231
  "font:14px/1.4 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif"
51
232
  ].join(";");
52
233
  const spinner = doc.createElement("div");
@@ -54,8 +235,8 @@ function createOverlay(iframeSrc, onCloseClick, names) {
54
235
  "width:22px",
55
236
  "height:22px",
56
237
  "border-radius:999px",
57
- "border:2px solid rgba(255,255,255,0.25)",
58
- "border-top-color:rgba(255,255,255,0.9)",
238
+ `border:2px solid rgba(${ink},0.25)`,
239
+ `border-top-color:rgba(${ink},0.9)`,
59
240
  `animation:${names.animation} 0.8s linear infinite`
60
241
  ].join(";");
61
242
  const loadingText = doc.createElement("div");
@@ -87,9 +268,9 @@ function createOverlay(iframeSrc, onCloseClick, names) {
87
268
  "width:36px",
88
269
  "height:36px",
89
270
  "border-radius:999px",
90
- "border:1px solid rgba(255,255,255,0.3)",
91
- "background:rgba(0,0,0,0.45)",
92
- "color:rgba(255,255,255,0.85)",
271
+ `border:1px solid rgba(${closeInk},0.3)`,
272
+ `background:${closeFill != null ? closeFill : DEFAULT_CLOSE_FILL}`,
273
+ `color:rgba(${closeInk},0.85)`,
93
274
  "font:20px/1 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif",
94
275
  "cursor:pointer",
95
276
  "padding:0"
@@ -139,12 +320,21 @@ function openOverlay(options, names, parseUrl) {
139
320
  src.searchParams.set("sdk", "1");
140
321
  for (const [key, value] of (_a = names.params) != null ? _a : []) src.searchParams.set(key, value);
141
322
  if (options.locale) src.searchParams.set("locale", options.locale);
323
+ const theme = prepareTheme(options, names.errorPrefix);
324
+ if (theme.param !== null) src.searchParams.set("theme", theme.param);
142
325
  let closed = false;
143
326
  let terminalDelivered = false;
144
327
  let loadTimedOut = false;
145
328
  let autoCloseTimer = null;
146
329
  let readyTimer = null;
147
- const overlay = createOverlay(src.toString(), () => close(), names.overlay);
330
+ const palette = activePalette(theme.theme);
331
+ const overlay = createOverlay(
332
+ src.toString(),
333
+ () => close(),
334
+ names.overlay,
335
+ palette == null ? void 0 : palette.overlay,
336
+ palette == null ? void 0 : palette.closeButton
337
+ );
148
338
  let helloPings = 0;
149
339
  const postHello = () => {
150
340
  var _a2;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "//": "Publishable manifest for the npm Web SDK. No devDependencies and no own node_modules by design: every build runs from the front-end repository root with its existing toolchain (npm run build:sdk), so the lockfile never grows for packaging. dist/ is rebuilt automatically by the prepack hook and is not committed.",
3
3
  "name": "@soliton-id/web-sdk",
4
- "version": "1.3.0",
4
+ "version": "1.4.0",
5
5
  "description": "Soliton identity verification for the browser: opens the hosted verification flow in a full-viewport overlay iframe on your page and reports lifecycle events. Verdicts and portraits are fetched by your backend, never exposed in the browser.",
6
6
  "license": "MIT",
7
7
  "author": "Soliton",