@zeyolabs/ui 2026.11.33 → 2026.11.34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeyolabs/ui",
3
- "version": "2026.11.33",
3
+ "version": "2026.11.34",
4
4
  "description": "Shared Svelte 5 components, form fields and design tokens for SvelteKit 3 apps.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -27,6 +27,7 @@
27
27
  "showcase:deploy": "pnpm --filter showcase cf-deploy"
28
28
  },
29
29
  "files": [
30
+ "!**/*.test.ts",
30
31
  "account",
31
32
  "back-button",
32
33
  "badge",
@@ -67,8 +68,8 @@
67
68
  "text",
68
69
  "theme",
69
70
  "tokens.css",
70
- "typography.css",
71
- "!**/*.test.ts"
71
+ "turnstile",
72
+ "typography.css"
72
73
  ],
73
74
  "exports": {
74
75
  "./template.css": "./template.css",
@@ -128,7 +129,8 @@
128
129
  "./layout/*": "./layout/*",
129
130
  "./gallery/*": "./gallery/*",
130
131
  "./theme/theme.svelte": "./theme/theme.svelte.ts",
131
- "./theme/*": "./theme/*"
132
+ "./theme/*": "./theme/*",
133
+ "./turnstile/*": "./turnstile/*"
132
134
  },
133
135
  "peerDependencies": {
134
136
  "@zeyolabs/kit": ">=2026.11.6",
@@ -0,0 +1,55 @@
1
+ <script lang="ts">
2
+ import { onMount } from 'svelte';
3
+
4
+ import { loadTurnstile } from './load';
5
+
6
+ /**
7
+ * Cloudflare Turnstile, rendered explicitly once its script has loaded. `onToken` gets each
8
+ * solved token; an expired or timed-out challenge resets itself. Bind `reset` to start over
9
+ * after the token is spent. If the script never loads, nothing renders and the server-side
10
+ * check rejects the form.
11
+ */
12
+ let {
13
+ onToken,
14
+ reset = $bindable(),
15
+ siteKey,
16
+ theme = 'auto',
17
+ }: {
18
+ onToken: (token: string) => void;
19
+ reset?: () => void;
20
+ siteKey: string;
21
+ theme?: 'auto' | 'dark' | 'light';
22
+ } = $props();
23
+
24
+ let container: HTMLDivElement;
25
+
26
+ onMount(() => {
27
+ let removed = false;
28
+ let remove = () => {};
29
+ loadTurnstile().then((turnstile) => {
30
+ if (removed || !turnstile) return;
31
+ let widgetId: string | undefined;
32
+ const restart = () => {
33
+ if (widgetId) turnstile.reset(widgetId);
34
+ };
35
+ widgetId = turnstile.render(container, {
36
+ callback: (token) => onToken(token),
37
+ 'expired-callback': restart,
38
+ 'response-field': false,
39
+ sitekey: siteKey,
40
+ theme,
41
+ 'timeout-callback': restart,
42
+ });
43
+ reset = restart;
44
+ remove = () => {
45
+ if (widgetId) turnstile.remove(widgetId);
46
+ };
47
+ });
48
+ return () => {
49
+ removed = true;
50
+ remove();
51
+ };
52
+ });
53
+ </script>
54
+
55
+ <div bind:this={container}></div>
@@ -0,0 +1,49 @@
1
+ /** The part of Cloudflare's `window.turnstile` that `Turnstile.svelte` uses. */
2
+ export type TurnstileApi = {
3
+ remove(widgetId: string): void;
4
+ render(
5
+ container: HTMLElement,
6
+ options: {
7
+ callback: (token: string) => void;
8
+ 'expired-callback': () => void;
9
+ 'response-field': boolean;
10
+ sitekey: string;
11
+ theme: 'auto' | 'dark' | 'light';
12
+ 'timeout-callback': () => void;
13
+ }
14
+ ): string | undefined;
15
+ reset(widgetId: string): void;
16
+ };
17
+
18
+ const SCRIPT_URL = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit';
19
+
20
+ let loading: Promise<null | TurnstileApi> | undefined;
21
+
22
+ function api(): null | TurnstileApi {
23
+ return (window as { turnstile?: TurnstileApi }).turnstile ?? null;
24
+ }
25
+
26
+ /**
27
+ * Cloudflare's Turnstile API, loading its script once per page. Null when the script fails to
28
+ * load or loads without defining `window.turnstile` (blocked, rewritten by an extension or a bot).
29
+ */
30
+ export function loadTurnstile(): Promise<null | TurnstileApi> {
31
+ if (api()) return Promise.resolve(api());
32
+ loading ??= new Promise((resolve) => {
33
+ const script = document.createElement('script');
34
+ script.src = SCRIPT_URL;
35
+ script.async = true;
36
+ script.addEventListener('load', () => resolve(api()), { once: true });
37
+ script.addEventListener(
38
+ 'error',
39
+ () => {
40
+ loading = undefined;
41
+ script.remove();
42
+ resolve(null);
43
+ },
44
+ { once: true }
45
+ );
46
+ document.head.append(script);
47
+ });
48
+ return loading;
49
+ }