@hubpav/hwio-web-runtime 0.7.6 → 0.7.7
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/dist/turnstile.d.ts +2 -0
- package/dist/turnstile.js +17 -1
- package/package.json +1 -1
package/dist/turnstile.d.ts
CHANGED
|
@@ -2,10 +2,12 @@ interface TurnstileApi {
|
|
|
2
2
|
render: (el: HTMLElement, opts: {
|
|
3
3
|
sitekey: string;
|
|
4
4
|
theme?: 'light' | 'dark' | 'auto';
|
|
5
|
+
size?: HWioTurnstileSize;
|
|
5
6
|
}) => string | undefined;
|
|
6
7
|
reset: (id?: string) => void;
|
|
7
8
|
remove: (id: string) => void;
|
|
8
9
|
}
|
|
10
|
+
type HWioTurnstileSize = 'normal' | 'compact' | 'flexible';
|
|
9
11
|
export type HWioTurnstileForm = HTMLFormElement & {
|
|
10
12
|
hwioLoadTurnstile?: () => void;
|
|
11
13
|
hwioTurnstileWidgetId?: string;
|
package/dist/turnstile.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import { hwioMount } from './mount.js';
|
|
2
2
|
import { hwioResolvedScheme } from './theme.js';
|
|
3
3
|
const SRC = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit';
|
|
4
|
+
/**
|
|
5
|
+
* The widget has a fixed width (normal 300 px, compact 150 x 140 px), so a phone-width card or
|
|
6
|
+
* column narrower than 300 px gets the compact one instead of a widget that runs past the screen.
|
|
7
|
+
* A `data-size` on the container wins.
|
|
8
|
+
*/
|
|
9
|
+
function widgetSize(container) {
|
|
10
|
+
const requested = container.dataset.size;
|
|
11
|
+
if (requested === 'normal' || requested === 'compact' || requested === 'flexible')
|
|
12
|
+
return requested;
|
|
13
|
+
const slot = container.parentElement;
|
|
14
|
+
if (!slot)
|
|
15
|
+
return 'normal';
|
|
16
|
+
const style = getComputedStyle(slot);
|
|
17
|
+
const width = slot.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);
|
|
18
|
+
return width < 300 ? 'compact' : 'normal';
|
|
19
|
+
}
|
|
4
20
|
function loadApi() {
|
|
5
21
|
if (window.turnstile)
|
|
6
22
|
return Promise.resolve(window.turnstile);
|
|
@@ -52,7 +68,7 @@ export function hwioTurnstileRuntime() {
|
|
|
52
68
|
if (signal.aborted || !container.isConnected || state === 'rendered')
|
|
53
69
|
return;
|
|
54
70
|
state = 'rendered';
|
|
55
|
-
const id = api.render(container, { sitekey: container.dataset.sitekey ?? '', theme: hwioResolvedScheme() });
|
|
71
|
+
const id = api.render(container, { sitekey: container.dataset.sitekey ?? '', theme: hwioResolvedScheme(), size: widgetSize(container) });
|
|
56
72
|
if (id !== undefined) {
|
|
57
73
|
widgetIds.push(id);
|
|
58
74
|
form.hwioTurnstileWidgetId = id;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubpav/hwio-web-runtime",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.7",
|
|
4
4
|
"description": "Framework-free browser runtime for the HARDWARIO websites: consent (Consent Mode v2 + GTM), HubSpot forms with Turnstile, attribution, theme, CTA tracking and small behaviours. View-transition safe.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|