@htmlbricks/hb-captcha-google-recaptcha-v2-invisible 0.71.35 → 0.71.36

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.
Files changed (3) hide show
  1. package/README.md +66 -23
  2. package/manifest.json +14 -6
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,40 +1,83 @@
1
- ## `hb-captcha-google-recaptcha-v2-invisible` — captcha-google-recaptcha-v2-invisible
1
+ # `hb-captcha-google-recaptcha-v2-invisible`
2
2
 
3
- **Category:** utilities | **Tags:** utilities, security
3
+ **Category:** utilities · **Tags:** utilities, security
4
4
 
5
- ### What it does
5
+ ## Summary
6
6
 
7
- Loads the Google reCAPTCHA v2 invisible SDK, renders the widget with your `api_key`, and exposes `grecaptcha.execute()` / reset when the `get` attribute changes after render. Dispatches `googleRecaptchaRendered` once mounted and `googleRecaptchaV2Response` with the token from the verification callback.
7
+ Custom element that loads Google’s reCAPTCHA v2 **explicit** API, mounts an **invisible** widget in the document **light DOM**, runs execution when the SDK is ready, and surfaces the verification token and render lifecycle through **custom events**.
8
8
 
9
- ### Custom element
9
+ ## What it does
10
10
 
11
- `hb-captcha-google-recaptcha-v2-invisible`
11
+ - Injects `https://www.google.com/recaptcha/api.js?render=explicit` (async/defer) into `document.head` with a stable script id (`recaptchav2-sdk`), if not already present.
12
+ - Ensures a host div exists on `document.body` with id `recaptchav2-element`, `data-size="invisible"`, then calls `grecaptcha.render()` with your site key (`api_key`) and a callback that dispatches the response event.
13
+ - After a successful render, dispatches **`googleRecaptchaRendered`**, then from `onMount`’s load path calls **`grecaptcha.execute()`** once the widget is ready.
14
+ - Polls (starting after 1s, then 2s retries) until `window.grecaptcha` is available **and** `api_key` is set before rendering.
15
+ - On teardown, removes that script node and body div, clears the polling timer, and assigns `window.grecaptcha` to `undefined`.
12
16
 
13
- ### Attributes / props (snake_case)
17
+ ## How it renders
14
18
 
15
- | Property | Type | Notes |
19
+ - **Shadow root:** Forwards Bulma + component SCSS (`styles/bulma.scss`, `styles/webcomponent.scss`); there is **no** visible captcha UI inside the shadow tree.
20
+ - **Light DOM / Google widget:** The actual reCAPTCHA widget is attached via the **`recaptchav2-element`** div appended to **`document.body`** (not inside the custom element). Integrators should assume global script injection and a body-level placeholder, not a child of `<hb-captcha-google-recaptcha-v2-invisible>`.
21
+
22
+ ## Logic: site key, token, and `get`
23
+
24
+ - **Site key:** The `api_key` prop is passed to `grecaptcha.render(..., { sitekey: api_key, callback })`.
25
+ - **Token:** When Google invokes the callback, the component dispatches **`googleRecaptchaV2Response`** with **`detail.response`** (string). The implementation also toggles internal state so a later programmatic run can **`reset()`** then **`execute()`** if a response was already produced (`execCaptcha()`).
26
+ - **`get`:** An `$effect` runs when reactive dependencies change (including `get`). After the widget has rendered and an internal “ready” latch is set, if **`get !== null`** it calls `execCaptcha()` again (execute, or reset+execute if a response was already received). So **`null`** suppresses that path; **`undefined`** and other non-`null` values still satisfy `get !== null` once the latch is set—align testing with that condition, not only “attribute changed”.
27
+
28
+ ## Attributes / props (`Component`, snake_case)
29
+
30
+ | Name | Type (authoring) | Role |
16
31
  | --- | --- | --- |
17
- | `id` | string (optional) | Element identifier. |
18
- | `style` | string (optional) | Inline style string. |
19
- | `api_key` | string (optional) | Google reCAPTCHA site key. |
20
- | `get` | any (optional) | Trigger prop: changing after render drives execute/reset (see component behavior). |
32
+ | `api_key` | `string` (optional) | reCAPTCHA **site key** passed to `grecaptcha.render` as `sitekey`. |
33
+ | `get` | optional (typed `any`) | Participates in the post-render `$effect` / `execCaptcha()` flow; see above (`get !== null`). |
34
+ | `id` | `string` (optional) | Declared on `Component`; standard host id if your toolchain maps it. |
35
+ | `style` | `string` (optional) | Declared on `Component`; standard host inline style if your toolchain maps it. |
36
+
37
+ HTML consumers should follow your platform’s rules for string attributes (e.g. booleans as `yes` / `no` where applicable).
38
+
39
+ ## Events (`CustomEvent`)
40
+
41
+ | Event | `detail` (TypeScript) |
42
+ | --- | --- |
43
+ | `googleRecaptchaV2Response` | `{ response: string }` — verification token from the callback. |
44
+ | `googleRecaptchaRendered` | `{ render: true }` — fired once after `grecaptcha.render` completes in this component. |
45
+
46
+ ## Styling
21
47
 
22
- **Bootstrap theme vars** in metadata. **CSS part:** `invalid-feedback`. No slots.
48
+ - Bulma theme tokens are forwarded onto **`:host`** even though the captcha UI is not in the shadow tree (`extra/docs.ts`).
49
+ - Documented CSS custom properties for catalog/style setup: **`--bulma-link`**, **`--bulma-text`** (colors; defaults follow the forwarded Bulma theme).
23
50
 
24
- ### Events (`CustomEvent` names)
51
+ ## Parts and slots
25
52
 
26
- - **`googleRecaptchaV2Response`** `{ response: string }` Verification token from Google.
27
- - **`googleRecaptchaRendered`** `{ render: true }` Widget finished rendering.
53
+ - **`::part`:** none (`cssParts` is empty).
54
+ - **Slots:** none (`htmlSlots` is empty).
28
55
 
29
- ### Usage notes
56
+ ## Typings
30
57
 
31
- - Uses Bootstrap form-feedback styling via the `invalid-feedback` part.
32
- - Requires loading Google’s script; CSP and domain allowlisting apply outside the component.
33
- - Shadow DOM wraps the widget; style invalid states through the exposed part.
34
- - No i18n in `docs.ts`.
58
+ Authoring types live in `types/webcomponent.type.d.ts`:
35
59
 
36
- ### Minimal HTML example
60
+ - **`Component`:** `id?`, `style?`, `api_key?`, `get?`
61
+ - **`Events`:** `googleRecaptchaV2Response` → `{ response: string }`; `googleRecaptchaRendered` → `{ render: true }`
62
+
63
+ ## Example
64
+
65
+ Google’s public **test** site key for v2 (always passes in test mode); replace with your production key.
37
66
 
38
67
  ```html
39
- <hb-captcha-google-recaptcha-v2-invisible api_key="YOUR_SITE_KEY"></hb-captcha-google-recaptcha-v2-invisible>
68
+ <hb-captcha-google-recaptcha-v2-invisible api_key="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"></hb-captcha-google-recaptcha-v2-invisible>
40
69
  ```
70
+
71
+ ```js
72
+ const el = document.querySelector("hb-captcha-google-recaptcha-v2-invisible");
73
+
74
+ el.addEventListener("googleRecaptchaRendered", (e) => {
75
+ console.log("rendered", e.detail); // { render: true }
76
+ });
77
+
78
+ el.addEventListener("googleRecaptchaV2Response", (e) => {
79
+ console.log("token", e.detail.response);
80
+ });
81
+ ```
82
+
83
+ **Integrator note:** CSP, domain allowlisting, and Google’s key/domain configuration apply outside this component.
package/manifest.json CHANGED
@@ -84,13 +84,21 @@
84
84
  }
85
85
  },
86
86
  "styleSetup": {
87
- "vars": [],
88
- "parts": [
87
+ "vars": [
89
88
  {
90
- "name": "invalid-feedback",
91
- "description": ""
89
+ "name": "--bulma-link",
90
+ "valueType": "color",
91
+ "defaultValue": "(theme)",
92
+ "description": "Typical accent if you extend the host with custom markup; matches the global Bulma token stack on `:host`."
93
+ },
94
+ {
95
+ "name": "--bulma-text",
96
+ "valueType": "color",
97
+ "defaultValue": "(theme)",
98
+ "description": "Default text token from the forwarded Bulma theme on `:host`."
92
99
  }
93
- ]
100
+ ],
101
+ "parts": []
94
102
  },
95
103
  "contributors": [],
96
104
  "htmlSlots": [],
@@ -148,5 +156,5 @@
148
156
  "size": {},
149
157
  "iifePath": "main.iife.js",
150
158
  "repoName": "@htmlbricks/hb-captcha-google-recaptcha-v2-invisible",
151
- "version": "0.71.35"
159
+ "version": "0.71.36"
152
160
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlbricks/hb-captcha-google-recaptcha-v2-invisible",
3
- "version": "0.71.35",
3
+ "version": "0.71.36",
4
4
  "contributors": [],
5
5
  "description": "Loads the Google reCAPTCHA v2 invisible SDK, renders the widget with your `api_key`, and exposes `grecaptcha.execute()` / reset when the `get` attribute changes after render. Dispatches `googleRecaptchaRendered` once mounted and `googleRecaptchaV2Response` with the token from the verification callback.",
6
6
  "licenses": [