cap-widget 0.1.46
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/LICENSE +13 -0
- package/README.md +5 -0
- package/cap-floating.min.js +1 -0
- package/cap.compat.min.js +408 -0
- package/cap.d.ts +122 -0
- package/cap.min.js +1 -0
- package/package.json +56 -0
- package/src/cap-floating.js +116 -0
- package/src/cap.css +268 -0
- package/src/cap.js +1363 -0
- package/src/worker.js +198 -0
- package/wasm-hashes.min.js +327 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2025 Tiago
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{const t=t=>{const e=t.getAttribute("data-cap-floating");if(!e)return;const o=document.querySelector(e);if(!document.contains(o)&&!o.solve)throw new Error(`[cap floating] "${e}" doesn't exist or isn't a Cap widget`);o.style.display="none";let n=!1;t.addEventListener("click",e=>{if(n)return void(n=!1);e.stopImmediatePropagation(),e.preventDefault(),((t,e)=>{const o=parseInt(t.getAttribute("data-cap-floating-offset"))||8,n=t.getAttribute("data-cap-floating-position")||"top";Object.assign(e.style,{display:"block",position:"absolute",zIndex:"99999",opacity:"0",transform:"scale(0.98)",marginTop:"-4px",boxShadow:"rgba(0, 0, 0, 0.05) 0px 6px 24px 0px",borderRadius:"14px",transition:"opacity 0.15s, margin-top 0.2s, transform 0.2s"}),setTimeout(()=>{e.style.transform="scale(1)",e.style.opacity="1",e.style.marginTop="0"},5);const s=t.getBoundingClientRect(),a=(e.offsetParent??document.documentElement).getBoundingClientRect(),i=s.left+(s.width-e.offsetWidth)/2,r=Math.max(2,Math.min(i,window.innerWidth-e.offsetWidth));if(e.style.left=r-a.left+"px","top"===n){const t=s.top-e.offsetHeight-o,n=Math.max(0,t);e.style.top=n-a.top+"px"}else{const t=s.bottom+o,n=Math.min(t,window.innerHeight-e.offsetHeight);e.style.top=n-a.top+"px"}e.solve()})(t,o);const s=({detail:e})=>{o.removeEventListener("solve",s),t.setAttribute("data-cap-token",e.token),t.setAttribute("data-cap-progress","done"),setTimeout(()=>{n=!0,t.click()},500),(t=>{setTimeout(()=>{t.style.transform="scale(0.98)",t.style.opacity="0",t.style.marginTop="-4px"},500),setTimeout(()=>{t.style.display="none"},700)})(o)};o.addEventListener("solve",s)},!0)},e=e=>{t(e),e.querySelectorAll("[data-cap-floating]").forEach(t)};e(document.body),new MutationObserver(t=>t.forEach(t=>t.addedNodes.forEach(t=>{t.nodeType===Node.ELEMENT_NODE&&e(t)}))).observe(document.body,{childList:!0,subtree:!0})})();
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
!(function () {
|
|
2
|
+
let e;
|
|
3
|
+
const t = "0.0.5",
|
|
4
|
+
r = function () {
|
|
5
|
+
return window?.CAP_CUSTOM_FETCH ? window.CAP_CUSTOM_FETCH(...arguments) : fetch(...arguments);
|
|
6
|
+
};
|
|
7
|
+
window.CAP_CUSTOM_WASM_URL ||
|
|
8
|
+
[
|
|
9
|
+
`https://cdn.jsdelivr.net/npm/@cap.js/wasm@${t}/browser/cap_wasm.min.js`,
|
|
10
|
+
`https://cdn.jsdelivr.net/npm/@cap.js/wasm@${t}/browser/cap_wasm_bg.wasm`,
|
|
11
|
+
].forEach((e) => {
|
|
12
|
+
const t = document.createElement("link");
|
|
13
|
+
((t.rel = "prefetch"),
|
|
14
|
+
(t.href = e),
|
|
15
|
+
(t.as = e.endsWith(".wasm") ? "fetch" : "script"),
|
|
16
|
+
document.head.appendChild(t));
|
|
17
|
+
});
|
|
18
|
+
class s extends HTMLElement {
|
|
19
|
+
#e = "";
|
|
20
|
+
#t = null;
|
|
21
|
+
#r = navigator.hardwareConcurrency || 8;
|
|
22
|
+
token = null;
|
|
23
|
+
#s;
|
|
24
|
+
#i;
|
|
25
|
+
#n;
|
|
26
|
+
#a = !1;
|
|
27
|
+
#o;
|
|
28
|
+
getI18nText(e, t) {
|
|
29
|
+
return this.getAttribute(`data-cap-i18n-${e}`) || t;
|
|
30
|
+
}
|
|
31
|
+
static get observedAttributes() {
|
|
32
|
+
return [
|
|
33
|
+
"onsolve",
|
|
34
|
+
"onprogress",
|
|
35
|
+
"onreset",
|
|
36
|
+
"onerror",
|
|
37
|
+
"data-cap-worker-count",
|
|
38
|
+
"data-cap-i18n-initial-state",
|
|
39
|
+
"[cap]",
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
constructor() {
|
|
43
|
+
(super(),
|
|
44
|
+
this.#o &&
|
|
45
|
+
this.#o.forEach((e, t) => {
|
|
46
|
+
this.removeEventListener(t.slice(2), e);
|
|
47
|
+
}),
|
|
48
|
+
(this.#o = new Map()),
|
|
49
|
+
(this.boundHandleProgress = this.handleProgress.bind(this)),
|
|
50
|
+
(this.boundHandleSolve = this.handleSolve.bind(this)),
|
|
51
|
+
(this.boundHandleError = this.handleError.bind(this)),
|
|
52
|
+
(this.boundHandleReset = this.handleReset.bind(this)));
|
|
53
|
+
}
|
|
54
|
+
initialize() {
|
|
55
|
+
this.#e = URL.createObjectURL(new Blob([e], { type: "application/javascript" }));
|
|
56
|
+
}
|
|
57
|
+
attributeChangedCallback(e, t, r) {
|
|
58
|
+
if (e.startsWith("on")) {
|
|
59
|
+
const t = e.slice(2),
|
|
60
|
+
s = this.#o.get(e);
|
|
61
|
+
if ((s && this.removeEventListener(t, s), r)) {
|
|
62
|
+
const r = (t) => {
|
|
63
|
+
const r = this.getAttribute(e);
|
|
64
|
+
"function" == typeof window[r] && window[r].call(this, t);
|
|
65
|
+
};
|
|
66
|
+
(this.#o.set(e, r), this.addEventListener(t, r));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
("data-cap-worker-count" === e && this.setWorkersCount(parseInt(r)),
|
|
70
|
+
"data-cap-i18n-initial-state" === e &&
|
|
71
|
+
this.#i &&
|
|
72
|
+
this.#i?.querySelector("p")?.innerText &&
|
|
73
|
+
(this.#i.querySelector("p").innerText = this.getI18nText(
|
|
74
|
+
"initial-state",
|
|
75
|
+
"I'm a human",
|
|
76
|
+
)));
|
|
77
|
+
}
|
|
78
|
+
async connectedCallback() {
|
|
79
|
+
((this.#n = this),
|
|
80
|
+
(this.#s = this.attachShadow({ mode: "open" })),
|
|
81
|
+
(this.#i = document.createElement("div")),
|
|
82
|
+
this.createUI(),
|
|
83
|
+
this.addEventListeners(),
|
|
84
|
+
await this.initialize(),
|
|
85
|
+
this.#i.removeAttribute("disabled"));
|
|
86
|
+
const e = this.getAttribute("data-cap-worker-count"),
|
|
87
|
+
t = e ? parseInt(e, 10) : null;
|
|
88
|
+
this.setWorkersCount(t || navigator.hardwareConcurrency || 8);
|
|
89
|
+
const r = this.getAttribute("data-cap-hidden-field-name") || "cap-token";
|
|
90
|
+
this.#n.innerHTML = `<input type="hidden" name="${r}">`;
|
|
91
|
+
}
|
|
92
|
+
async solve() {
|
|
93
|
+
if (!this.#a)
|
|
94
|
+
try {
|
|
95
|
+
((this.#a = !0),
|
|
96
|
+
this.updateUI("verifying", this.getI18nText("verifying-label", "Verifying..."), !0),
|
|
97
|
+
this.dispatchEvent("progress", { progress: 0 }));
|
|
98
|
+
try {
|
|
99
|
+
const e = this.getAttribute("data-cap-api-endpoint");
|
|
100
|
+
if (!e) throw new Error("Missing API endpoint");
|
|
101
|
+
const { challenge: t, token: s } = await (
|
|
102
|
+
await r(`${e}challenge`, { method: "POST" })
|
|
103
|
+
).json(),
|
|
104
|
+
i = await this.solveChallenges(t),
|
|
105
|
+
n = await (
|
|
106
|
+
await r(`${e}redeem`, {
|
|
107
|
+
method: "POST",
|
|
108
|
+
body: JSON.stringify({ token: s, solutions: i }),
|
|
109
|
+
headers: { "Content-Type": "application/json" },
|
|
110
|
+
})
|
|
111
|
+
).json();
|
|
112
|
+
if ((this.dispatchEvent("progress", { progress: 100 }), !n.success))
|
|
113
|
+
throw new Error("Invalid solution");
|
|
114
|
+
const a = this.getAttribute("data-cap-hidden-field-name") || "cap-token";
|
|
115
|
+
(this.querySelector(`input[name='${a}']`) &&
|
|
116
|
+
(this.querySelector(`input[name='${a}']`).value = n.token),
|
|
117
|
+
this.dispatchEvent("solve", { token: n.token }),
|
|
118
|
+
(this.token = n.token),
|
|
119
|
+
this.#t && clearTimeout(this.#t));
|
|
120
|
+
const o = new Date(n.expires).getTime() - Date.now();
|
|
121
|
+
return (
|
|
122
|
+
o > 0 && o < 864e5
|
|
123
|
+
? (this.#t = setTimeout(() => this.reset(), o))
|
|
124
|
+
: this.error("Invalid expiration time"),
|
|
125
|
+
{ success: !0, token: this.token }
|
|
126
|
+
);
|
|
127
|
+
} catch (e) {
|
|
128
|
+
throw (this.error(e.message), e);
|
|
129
|
+
}
|
|
130
|
+
} finally {
|
|
131
|
+
this.#a = !1;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async solveChallenges(e) {
|
|
135
|
+
const r = e.length;
|
|
136
|
+
let s = 0;
|
|
137
|
+
const i = Array(this.#r)
|
|
138
|
+
.fill(null)
|
|
139
|
+
.map(() => {
|
|
140
|
+
try {
|
|
141
|
+
return new Worker(this.#e);
|
|
142
|
+
} catch (e) {
|
|
143
|
+
throw (
|
|
144
|
+
console.error("[cap] Failed to create worker:", e),
|
|
145
|
+
new Error("Worker creation failed")
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
}),
|
|
149
|
+
n = ([e, n], a) =>
|
|
150
|
+
new Promise((o, c) => {
|
|
151
|
+
const d = i[a];
|
|
152
|
+
if (!d) return void c(new Error("Worker not available"));
|
|
153
|
+
const h = setTimeout(
|
|
154
|
+
() => {
|
|
155
|
+
try {
|
|
156
|
+
(d.terminate(), (i[a] = new Worker(this.#e)));
|
|
157
|
+
} catch (e) {
|
|
158
|
+
console.error("[cap] Error terminating/recreating worker:", e);
|
|
159
|
+
}
|
|
160
|
+
c(new Error("Worker timeout"));
|
|
161
|
+
},
|
|
162
|
+
3e4,
|
|
163
|
+
);
|
|
164
|
+
((d.onmessage = ({ data: t }) => {
|
|
165
|
+
t.found &&
|
|
166
|
+
(clearTimeout(h),
|
|
167
|
+
s++,
|
|
168
|
+
this.dispatchEvent("progress", { progress: Math.round((s / r) * 100) }),
|
|
169
|
+
o([e, n, t.nonce]));
|
|
170
|
+
}),
|
|
171
|
+
(d.onerror = (e) => {
|
|
172
|
+
(clearTimeout(h), this.error(`Error in worker: ${e.message || e}`), c(e));
|
|
173
|
+
}),
|
|
174
|
+
d.postMessage({
|
|
175
|
+
salt: e,
|
|
176
|
+
target: n,
|
|
177
|
+
wasmUrl:
|
|
178
|
+
window.CAP_CUSTOM_WASM_URL ||
|
|
179
|
+
`https://cdn.jsdelivr.net/npm/@cap.js/wasm@${t}/browser/cap_wasm.min.js`,
|
|
180
|
+
}));
|
|
181
|
+
}),
|
|
182
|
+
a = [];
|
|
183
|
+
try {
|
|
184
|
+
for (let t = 0; t < e.length; t += this.#r) {
|
|
185
|
+
const r = e.slice(t, Math.min(t + this.#r, e.length)),
|
|
186
|
+
s = await Promise.all(r.map((e, t) => n(e, t)));
|
|
187
|
+
a.push(...s);
|
|
188
|
+
}
|
|
189
|
+
} finally {
|
|
190
|
+
i.forEach((e) => {
|
|
191
|
+
if (e)
|
|
192
|
+
try {
|
|
193
|
+
e.terminate();
|
|
194
|
+
} catch (e) {
|
|
195
|
+
console.error("[cap] Error terminating worker:", e);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return a;
|
|
200
|
+
}
|
|
201
|
+
setWorkersCount(e) {
|
|
202
|
+
const t = parseInt(e, 10),
|
|
203
|
+
r = Math.min(navigator.hardwareConcurrency || 8, 16);
|
|
204
|
+
this.#r = !isNaN(t) && t > 0 && t <= r ? t : navigator.hardwareConcurrency || 8;
|
|
205
|
+
}
|
|
206
|
+
createUI() {
|
|
207
|
+
(this.#i.classList.add("captcha"),
|
|
208
|
+
this.#i.setAttribute("role", "button"),
|
|
209
|
+
this.#i.setAttribute("tabindex", "0"),
|
|
210
|
+
this.#i.setAttribute("disabled", "true"),
|
|
211
|
+
(this.#i.innerHTML = `<div class="checkbox"></div><p>${this.getI18nText("initial-state", "I'm a human")}</p><a href="https://trycap.dev/" class="credits" target="_blank" rel="follow noopener"><span>Secured by </span>Cap</a>`),
|
|
212
|
+
(this.#s.innerHTML =
|
|
213
|
+
'<style>\n\n.captcha * {box-sizing:border-box;}\n\n.captcha{background-color:var(--cap-background,#fdfdfd);border:1px solid var(--cap-border-color,#dddddd8f);border-radius:var(--cap-border-radius,14px);\nuser-select:none;\n\nheight:var(--cap-widget-height, 30px);\n\nwidth:var(--cap-widget-width, 230px);display:flex;align-items:center;padding:var(--cap-widget-padding,14px);gap:var(--cap-gap,15px);cursor:pointer;transition:filter .2s,transform .2s;position:relative;-webkit-tap-highlight-color:rgba(255,255,255,0);overflow:hidden;color:var(--cap-color,#212121)}.captcha:hover{filter:brightness(98%)}\n\n.checkbox{width:var(--cap-checkbox-size,25px);height:var(--cap-checkbox-size,25px);border:var(--cap-checkbox-border,1px solid #aaaaaad1);border-radius:var(--cap-checkbox-border-radius,6px);background-color:var(--cap-checkbox-background,#fafafa91);transition:opacity .2s;margin-top:var(--cap-checkbox-margin,2px);margin-bottom:var(--cap-checkbox-margin,2px)}.captcha *{font-family:var(--cap-font,system,-apple-system,"BlinkMacSystemFont",".SFNSText-Regular","San Francisco","Roboto","Segoe UI","Helvetica Neue","Lucida Grande","Ubuntu","arial",sans-serif)}\n\n.captcha p{margin:0;font-weight:500;font-size:15px;user-select:none;transition:opacity .2s}.captcha[data-state=verifying] .checkbox{background: none;display:flex;align-items:center;justify-content:center;transform: scale(1.1);border: none;border-radius: 50%;background: conic-gradient(var(--cap-spinner-color,#000) 0%, var(--cap-spinner-color,#000) var(--progress, 0%), var(--cap-spinner-background-color,#eee) var(--progress, 0%), var(--cap-spinner-background-color,#eee) 100%);position: relative;}.captcha[data-state=verifying] .checkbox::after {content: "";background-color: var(--cap-background,#fdfdfd);width: calc(100% - var(--cap-spinner-thickness,5px));height: calc(100% - var(--cap-spinner-thickness,5px));border-radius: 50%;margin:calc(var(--cap-spinner-thickness,5px) / 2)}.captcha[data-state=done] .checkbox{border:1px solid transparent;background-image:var(--cap-checkmark,url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cstyle%3E%40keyframes%20anim%7B0%25%7Bstroke-dashoffset%3A23.21320343017578px%7Dto%7Bstroke-dashoffset%3A0%7D%7D%3C%2Fstyle%3E%3Cpath%20fill%3D%22none%22%20stroke%3D%22%2300a67d%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%20stroke-width%3D%222%22%20d%3D%22m5%2012%205%205L20%207%22%20style%3D%22stroke-dashoffset%3A0%3Bstroke-dasharray%3A23.21320343017578px%3Banimation%3Aanim%20.5s%20ease%22%2F%3E%3C%2Fsvg%3E"));background-size:cover}.captcha[data-state=error] .checkbox{border:1px solid transparent;background-image:var(--cap-error-cross,url("data:image/svg+xml,%3Csvg xmlns=\'http://www.w3.org/2000/svg\' width=\'96\' height=\'96\' viewBox=\'0 0 24 24\'%3E%3Cpath fill=\'%23f55b50\' d=\'M11 15h2v2h-2zm0-8h2v6h-2zm1-5C6.47 2 2 6.5 2 12a10 10 0 0 0 10 10a10 10 0 0 0 10-10A10 10 0 0 0 12 2m0 18a8 8 0 0 1-8-8a8 8 0 0 1 8-8a8 8 0 0 1 8 8a8 8 0 0 1-8 8\'/%3E%3C/svg%3E"));background-size:cover}.captcha[disabled]{cursor:not-allowed}.captcha[disabled][data-state=verifying]{cursor:progress}.captcha[disabled][data-state=done]{cursor:default}.captcha .credits{position:absolute;bottom:10px;right:10px;font-size:var(--cap-credits-font-size,12px);color:var(--cap-color,#212121);opacity:var(--cap-opacity-hover,0.8)}.captcha .credits span{display:none;text-decoration:underline}.captcha .credits:hover span{display:inline-block}</style>'),
|
|
214
|
+
this.#s.appendChild(this.#i));
|
|
215
|
+
}
|
|
216
|
+
addEventListeners() {
|
|
217
|
+
this.#i &&
|
|
218
|
+
(this.#i.querySelector("a").addEventListener("click", (e) => {
|
|
219
|
+
(e.stopPropagation(), e.preventDefault(), window.open("https://trycap.dev", "_blank"));
|
|
220
|
+
}),
|
|
221
|
+
this.#i.addEventListener("click", () => {
|
|
222
|
+
this.#i.hasAttribute("disabled") || this.solve();
|
|
223
|
+
}),
|
|
224
|
+
this.#i.addEventListener("keydown", (e) => {
|
|
225
|
+
("Enter" !== e.key && " " !== e.key) ||
|
|
226
|
+
this.#i.hasAttribute("disabled") ||
|
|
227
|
+
(e.preventDefault(), this.solve());
|
|
228
|
+
}),
|
|
229
|
+
this.addEventListener("progress", this.boundHandleProgress),
|
|
230
|
+
this.addEventListener("solve", this.boundHandleSolve),
|
|
231
|
+
this.addEventListener("error", this.boundHandleError),
|
|
232
|
+
this.addEventListener("reset", this.boundHandleReset));
|
|
233
|
+
}
|
|
234
|
+
updateUI(e, t, r = !1) {
|
|
235
|
+
this.#i &&
|
|
236
|
+
(this.#i.setAttribute("data-state", e),
|
|
237
|
+
(this.#i.querySelector("p").innerText = t),
|
|
238
|
+
r ? this.#i.setAttribute("disabled", "true") : this.#i.removeAttribute("disabled"));
|
|
239
|
+
}
|
|
240
|
+
handleProgress(e) {
|
|
241
|
+
if (!this.#i) return;
|
|
242
|
+
const t = this.#i.querySelector("p"),
|
|
243
|
+
r = this.#i.querySelector(".checkbox");
|
|
244
|
+
(t &&
|
|
245
|
+
r &&
|
|
246
|
+
(r.style.setProperty("--progress", `${e.detail.progress}%`),
|
|
247
|
+
(t.innerText = `${this.getI18nText("verifying-label", "Verifying...")} ${e.detail.progress}%`)),
|
|
248
|
+
this.executeAttributeCode("onprogress", e));
|
|
249
|
+
}
|
|
250
|
+
handleSolve(e) {
|
|
251
|
+
(this.updateUI("done", this.getI18nText("solved-label", "You're a human"), !0),
|
|
252
|
+
this.executeAttributeCode("onsolve", e));
|
|
253
|
+
}
|
|
254
|
+
handleError(e) {
|
|
255
|
+
(this.updateUI("error", this.getI18nText("error-label", "Error. Try again.")),
|
|
256
|
+
this.executeAttributeCode("onerror", e));
|
|
257
|
+
}
|
|
258
|
+
handleReset(e) {
|
|
259
|
+
(this.updateUI("", this.getI18nText("initial-state", "I'm a human")),
|
|
260
|
+
this.executeAttributeCode("onreset", e));
|
|
261
|
+
}
|
|
262
|
+
executeAttributeCode(e, t) {
|
|
263
|
+
const r = this.getAttribute(e);
|
|
264
|
+
if (r)
|
|
265
|
+
try {
|
|
266
|
+
new Function("event", r).call(this, t);
|
|
267
|
+
} catch (t) {
|
|
268
|
+
console.error(`[cap] Error executing ${e}:`, t);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
error(e = "Unknown error") {
|
|
272
|
+
(console.error("[cap] Error:", e), this.dispatchEvent("error", { isCap: !0, message: e }));
|
|
273
|
+
}
|
|
274
|
+
dispatchEvent(e, t = {}) {
|
|
275
|
+
const r = new CustomEvent(e, { bubbles: !0, composed: !0, detail: t });
|
|
276
|
+
super.dispatchEvent(r);
|
|
277
|
+
}
|
|
278
|
+
reset() {
|
|
279
|
+
(this.#t && (clearTimeout(this.#t), (this.#t = null)),
|
|
280
|
+
this.dispatchEvent("reset"),
|
|
281
|
+
(this.token = null));
|
|
282
|
+
const e = this.getAttribute("data-cap-hidden-field-name") || "cap-token";
|
|
283
|
+
this.querySelector(`input[name='${e}']`) &&
|
|
284
|
+
(this.querySelector(`input[name='${e}']`).value = "");
|
|
285
|
+
}
|
|
286
|
+
get tokenValue() {
|
|
287
|
+
return this.token;
|
|
288
|
+
}
|
|
289
|
+
disconnectedCallback() {
|
|
290
|
+
(this.removeEventListener("progress", this.boundHandleProgress),
|
|
291
|
+
this.removeEventListener("solve", this.boundHandleSolve),
|
|
292
|
+
this.removeEventListener("error", this.boundHandleError),
|
|
293
|
+
this.removeEventListener("reset", this.boundHandleReset),
|
|
294
|
+
this.#o.forEach((e, t) => {
|
|
295
|
+
this.removeEventListener(t.slice(2), e);
|
|
296
|
+
}),
|
|
297
|
+
this.#o.clear(),
|
|
298
|
+
this.#s && (this.#s.innerHTML = ""),
|
|
299
|
+
this.reset(),
|
|
300
|
+
this.cleanup());
|
|
301
|
+
}
|
|
302
|
+
cleanup() {
|
|
303
|
+
(this.#t && (clearTimeout(this.#t), (this.#t = null)),
|
|
304
|
+
this.#e && (URL.revokeObjectURL(this.#e), (this.#e = "")));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
class i {
|
|
308
|
+
constructor(e = {}, t) {
|
|
309
|
+
let r = t || document.createElement("cap-widget");
|
|
310
|
+
if (
|
|
311
|
+
(Object.entries(e).forEach(([e, t]) => {
|
|
312
|
+
r.setAttribute(e, t);
|
|
313
|
+
}),
|
|
314
|
+
!e.apiEndpoint)
|
|
315
|
+
)
|
|
316
|
+
throw (r.remove(), new Error("Missing API endpoint"));
|
|
317
|
+
(r.setAttribute("data-cap-api-endpoint", e.apiEndpoint),
|
|
318
|
+
(this.widget = r),
|
|
319
|
+
(this.solve = this.widget.solve.bind(this.widget)),
|
|
320
|
+
(this.reset = this.widget.reset.bind(this.widget)),
|
|
321
|
+
(this.addEventListener = this.widget.addEventListener.bind(this.widget)),
|
|
322
|
+
Object.defineProperty(this, "token", {
|
|
323
|
+
get: () => r.token,
|
|
324
|
+
configurable: !0,
|
|
325
|
+
enumerable: !0,
|
|
326
|
+
}),
|
|
327
|
+
t || ((r.style.display = "none"), document.documentElement.appendChild(r)));
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
((e = `(() => {${function () {
|
|
331
|
+
if ("object" != typeof WebAssembly || "function" != typeof WebAssembly?.instantiate)
|
|
332
|
+
return (
|
|
333
|
+
(self.onmessage = async ({ data: { salt: e, target: t } }) => {
|
|
334
|
+
let r = 0;
|
|
335
|
+
let s = 0;
|
|
336
|
+
const i = new TextEncoder(),
|
|
337
|
+
n = new Uint8Array(t.length / 2);
|
|
338
|
+
for (let e = 0; e < n.length; e++) n[e] = parseInt(t.substring(2 * e, 2 * e + 2), 16);
|
|
339
|
+
const a = n.length;
|
|
340
|
+
for (;;)
|
|
341
|
+
try {
|
|
342
|
+
for (let t = 0; t < 5e4; t++) {
|
|
343
|
+
const t = e + r,
|
|
344
|
+
s = i.encode(t),
|
|
345
|
+
o = await crypto.subtle.digest("SHA-256", s),
|
|
346
|
+
c = new Uint8Array(o, 0, a);
|
|
347
|
+
let d = !0;
|
|
348
|
+
for (let e = 0; e < a; e++)
|
|
349
|
+
if (c[e] !== n[e]) {
|
|
350
|
+
d = !1;
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
if (d) return void self.postMessage({ nonce: r, found: !0 });
|
|
354
|
+
r++;
|
|
355
|
+
}
|
|
356
|
+
s += 5e4;
|
|
357
|
+
} catch (e) {
|
|
358
|
+
return (
|
|
359
|
+
console.error("[cap] fallback worker error", e),
|
|
360
|
+
void self.postMessage({ found: !1, error: e.message })
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
}),
|
|
364
|
+
console.warn("[cap] WebAssembly is not supported, falling back to alternative solver.")
|
|
365
|
+
);
|
|
366
|
+
let e, t;
|
|
367
|
+
((self.onmessage = async ({ data: { salt: r, target: s, wasmUrl: i } }) => {
|
|
368
|
+
e !== i &&
|
|
369
|
+
((e = i),
|
|
370
|
+
await import(i)
|
|
371
|
+
.then((e) =>
|
|
372
|
+
e.default().then((r) => {
|
|
373
|
+
t = (r && r.exports ? r.exports : e).solve_pow;
|
|
374
|
+
}),
|
|
375
|
+
)
|
|
376
|
+
.catch((e) => {
|
|
377
|
+
console.error("[cap] using fallback solver due to error:", e);
|
|
378
|
+
}));
|
|
379
|
+
try {
|
|
380
|
+
const e = performance.now(),
|
|
381
|
+
i = t(r, s),
|
|
382
|
+
n = performance.now();
|
|
383
|
+
self.postMessage({ nonce: Number(i), found: !0, durationMs: (n - e).toFixed(2) });
|
|
384
|
+
} catch (e) {
|
|
385
|
+
(console.error("[cap] solver error", e),
|
|
386
|
+
self.postMessage({ found: !1, error: e.message || String(e) }));
|
|
387
|
+
}
|
|
388
|
+
}),
|
|
389
|
+
(self.onerror = (e) => {
|
|
390
|
+
self.postMessage({ found: !1, error: `Worker error: ${e.message || e}` });
|
|
391
|
+
}));
|
|
392
|
+
}
|
|
393
|
+
.toString()
|
|
394
|
+
.replace(/^function\s*\([^\)]*\)\s*{|\}$/g, "")
|
|
395
|
+
.trim()}})()`),
|
|
396
|
+
(window.Cap = i),
|
|
397
|
+
customElements.get("cap-widget")
|
|
398
|
+
? console.warn("The cap-widget element has already been defined. Skipping re-defining it.")
|
|
399
|
+
: customElements.define("cap-widget", s),
|
|
400
|
+
"object" == typeof exports && "undefined" != typeof module
|
|
401
|
+
? (module.exports = i)
|
|
402
|
+
: "function" == typeof define &&
|
|
403
|
+
define.amd &&
|
|
404
|
+
define([], function () {
|
|
405
|
+
return i;
|
|
406
|
+
}),
|
|
407
|
+
"undefined" != typeof exports && (exports.default = i));
|
|
408
|
+
})();
|
package/cap.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
CAP_CUSTOM_FETCH?: typeof fetch;
|
|
4
|
+
CAP_CUSTOM_WASM_URL?: string;
|
|
5
|
+
CAP_CSS_NONCE?: string;
|
|
6
|
+
CAP_DONT_SKIP_REDEFINE?: boolean;
|
|
7
|
+
Cap: typeof Cap;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface CapProgressEventDetail {
|
|
12
|
+
progress: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface CapSolveEventDetail {
|
|
16
|
+
token: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface CapErrorEventDetail {
|
|
20
|
+
isCap: boolean;
|
|
21
|
+
message: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface CapProgressEvent extends CustomEvent {
|
|
25
|
+
detail: CapProgressEventDetail;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface CapSolveEvent extends CustomEvent {
|
|
29
|
+
detail: CapSolveEventDetail;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface CapErrorEvent extends CustomEvent {
|
|
33
|
+
detail: CapErrorEventDetail;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface CapResetEvent extends CustomEvent {
|
|
37
|
+
detail: Record<string, never>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface SolveResult {
|
|
41
|
+
success: boolean;
|
|
42
|
+
token: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface CapConfig {
|
|
46
|
+
apiEndpoint?: string;
|
|
47
|
+
"data-cap-api-endpoint"?: string;
|
|
48
|
+
"data-cap-worker-count"?: string;
|
|
49
|
+
"data-cap-hidden-field-name"?: string;
|
|
50
|
+
"data-cap-i18n-initial-state"?: string;
|
|
51
|
+
"data-cap-i18n-verifying-label"?: string;
|
|
52
|
+
"data-cap-i18n-solved-label"?: string;
|
|
53
|
+
"data-cap-i18n-error-label"?: string;
|
|
54
|
+
"data-cap-i18n-verify-aria-label"?: string;
|
|
55
|
+
"data-cap-i18n-verifying-aria-label"?: string;
|
|
56
|
+
"data-cap-i18n-verified-aria-label"?: string;
|
|
57
|
+
"data-cap-i18n-error-aria-label"?: string;
|
|
58
|
+
"data-cap-i18n-wasm-disabled"?: string;
|
|
59
|
+
"data-cap-i18n-required-label"?: string;
|
|
60
|
+
"data-cap-troubleshooting-url"?: string;
|
|
61
|
+
required?: boolean | "";
|
|
62
|
+
onsolve?: string;
|
|
63
|
+
onprogress?: string;
|
|
64
|
+
onreset?: string;
|
|
65
|
+
onerror?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface CapWidget extends HTMLElement {
|
|
69
|
+
readonly token: string | null;
|
|
70
|
+
readonly tokenValue: string | null;
|
|
71
|
+
|
|
72
|
+
solve(): Promise<SolveResult>;
|
|
73
|
+
reset(): void;
|
|
74
|
+
setWorkersCount(workers: number): void;
|
|
75
|
+
|
|
76
|
+
addEventListener(type: "progress", listener: (event: CapProgressEvent) => void): void;
|
|
77
|
+
addEventListener(type: "solve", listener: (event: CapSolveEvent) => void): void;
|
|
78
|
+
addEventListener(type: "error", listener: (event: CapErrorEvent) => void): void;
|
|
79
|
+
addEventListener(type: "reset", listener: (event: CapResetEvent) => void): void;
|
|
80
|
+
addEventListener(type: string, listener: EventListener): void;
|
|
81
|
+
|
|
82
|
+
removeEventListener(type: "progress", listener: (event: CapProgressEvent) => void): void;
|
|
83
|
+
removeEventListener(type: "solve", listener: (event: CapSolveEvent) => void): void;
|
|
84
|
+
removeEventListener(type: "error", listener: (event: CapErrorEvent) => void): void;
|
|
85
|
+
removeEventListener(type: "reset", listener: (event: CapResetEvent) => void): void;
|
|
86
|
+
removeEventListener(type: string, listener: EventListener): void;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare class Cap {
|
|
90
|
+
readonly widget: CapWidget;
|
|
91
|
+
readonly token: string | null;
|
|
92
|
+
|
|
93
|
+
constructor(config?: CapConfig, el?: CapWidget);
|
|
94
|
+
|
|
95
|
+
solve(): Promise<SolveResult>;
|
|
96
|
+
reset(): void;
|
|
97
|
+
|
|
98
|
+
addEventListener(type: "progress", listener: (event: CapProgressEvent) => void): void;
|
|
99
|
+
addEventListener(type: "solve", listener: (event: CapSolveEvent) => void): void;
|
|
100
|
+
addEventListener(type: "error", listener: (event: CapErrorEvent) => void): void;
|
|
101
|
+
addEventListener(type: "reset", listener: (event: CapResetEvent) => void): void;
|
|
102
|
+
addEventListener(type: string, listener: EventListener): void;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
declare global {
|
|
106
|
+
interface HTMLElementTagNameMap {
|
|
107
|
+
"cap-widget": CapWidget;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export {
|
|
112
|
+
Cap,
|
|
113
|
+
type CapWidget,
|
|
114
|
+
type CapConfig,
|
|
115
|
+
type CapProgressEvent,
|
|
116
|
+
type CapSolveEvent,
|
|
117
|
+
type CapErrorEvent,
|
|
118
|
+
type CapResetEvent,
|
|
119
|
+
type SolveResult,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export default Cap;
|
package/cap.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{const e="vibrate"in navigator&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches;if("undefined"==typeof window)return;const t=(e,t={})=>window?.CAP_CUSTOM_FETCH?window.CAP_CUSTOM_FETCH(e,t):fetch(e,t);function i(e,t){let i=function(e){let t=2166136261;for(let i=0;i<e.length;i++)t^=e.charCodeAt(i),t+=(t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24);return t>>>0}(e),s="";function r(){return i^=i<<13,i^=i>>>17,i^=i<<5,i>>>0}for(;s.length<t;){s+=r().toString(16).padStart(8,"0")}return s.substring(0,t)}async function s(e){var t=(e=>{const t=atob(e),i=new Uint8Array(t.length);for(let e=0;e<t.length;e++)i[e]=t.charCodeAt(e);return i})(e);const i=await new Promise((e,i)=>{try{var s=new DecompressionStream("deflate-raw"),r=s.writable.getWriter(),a=s.readable.getReader(),n=[];a.read().then(function t(s){if(s.done){for(var r=0,o=0,l=0;l<n.length;l++)r+=n[l].length;var c=new Uint8Array(r);for(l=0;l<n.length;l++)c.set(n[l],o),o+=n[l].length;e((new TextDecoder).decode(c))}else n.push(s.value),a.read().then(t).catch(i)}).catch(i),r.write(t).then(()=>{r.close()}).catch(i)}catch(e){i(e)}});return new Promise(e=>{var t=setTimeout(()=>{a(),e({__timeout:!0})},2e4),s=document.createElement("iframe");s.setAttribute("sandbox","allow-scripts"),s.setAttribute("aria-hidden","true"),s.style.cssText="position:absolute;width:1px;height:1px;top:-9999px;left:-9999px;border:none;opacity:0;pointer-events:none;";var r=!1;function a(){r||(r=!0,clearTimeout(t),window.removeEventListener("message",n),s.parentNode&&s.parentNode.removeChild(s))}function n(t){var i=t.data;i&&"object"==typeof i&&("cap:instr"===i.type?(a(),i.blocked?e({__blocked:!0,blockReason:i.blockReason||"automated_browser"}):i.result?e(i.result):e({__timeout:!0})):"cap:error"===i.type&&(a(),e({__timeout:!0})))}window.addEventListener("message",n),s.srcdoc='<!DOCTYPE html><html><head><meta charset="UTF-8"></head><body><script>'+i+"\n<\/script></body></html>",document.body.appendChild(s)})}let r=null;const a=()=>{if(r)return r;const e=window.CAP_CUSTOM_WASM_URL||"https://cdn.jsdelivr.net/npm/@cap.js/wasm@0.0.6/browser/cap_wasm_bg.wasm";return r=fetch(e).then(e=>{if(!e.ok)throw new Error(`Failed to fetch wasm: ${e.status}`);return e.arrayBuffer()}).then(e=>WebAssembly.compile(e)).catch(e=>{throw r=null,e}),r};"object"==typeof WebAssembly&&"function"==typeof WebAssembly.compile&&a().catch(()=>{});let n=null;function o(){return n||(n=URL.createObjectURL(new Blob(['(()=>{const e=async({salt:e,target:t})=>{let n=0;const r=new TextEncoder,o=4*t.length,s=Math.floor(o/8),l=o%8,a=t.length%2==0?t:t+"0",c=a.length/2,i=new Uint8Array(c);for(let e=0;e<c;e++)i[e]=parseInt(a.substring(2*e,2*e+2),16);const f=l>0?255<<8-l&255:0;for(;;)try{for(let t=0;t<5e4;t++){const t=e+n,o=r.encode(t),a=await crypto.subtle.digest("SHA-256",o),c=new Uint8Array(a);let g=!0;for(let e=0;e<s;e++)if(c[e]!==i[e]){g=!1;break}if(g&&l>0&&(c[s]&f)!==(i[s]&f)&&(g=!1),g)return void self.postMessage({nonce:n,found:!0});n++}}catch(e){return console.error("[cap worker]",e),void self.postMessage({found:!1,error:e.message})}};if("object"!=typeof WebAssembly||"function"!=typeof WebAssembly?.instantiate)return console.warn("[cap worker] wasm not supported, falling back to alternative solver. this will be significantly slower."),void(self.onmessage=async({data:{salt:t,target:n}})=>e({salt:t,target:n}));let t=null;self.onmessage=async({data:{salt:n,target:r,wasmModule:o}})=>{if(o instanceof WebAssembly.Module&&null===t){const s=(e=>{try{let n,r=0,o=null;const s=()=>(null!==o&&0!==o.byteLength||(o=new Uint8Array(n.memory.buffer)),o),l=new TextEncoder,a=(e,t,n)=>{if(void 0===n){const n=l.encode(e),o=t(n.length,1)>>>0;return s().subarray(o,o+n.length).set(n),r=n.length,o}let o=e.length,a=t(o,1)>>>0;const c=s();let i=0;for(;i<o;i++){const t=e.charCodeAt(i);if(t>127)break;c[a+i]=t}if(i!==o){0!==i&&(e=e.slice(i)),a=n(a,o,o=i+3*e.length,1)>>>0;const t=s().subarray(a+i,a+o),{written:r}=l.encodeInto(e,t);i+=r,a=n(a,o,i,1)>>>0}return r=i,a},c={wbg:{}};c.wbg.__wbindgen_init_externref_table=()=>{const e=n.__wbindgen_export_0,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,!0),e.set(t+3,!1)};const i=new WebAssembly.Instance(e,c);return n=i.exports,n.__wbindgen_start&&n.__wbindgen_start(),t=(e,t)=>{const o=a(e,n.__wbindgen_malloc,n.__wbindgen_realloc),s=r,l=a(t,n.__wbindgen_malloc,n.__wbindgen_realloc),c=r;return BigInt.asUintN(64,n.solve_pow(o,s,l,c))},!0}catch(e){return console.error("[cap worker] failed to init wasm from module:",e),!1}})(o);if(!s)return console.warn("[cap worker] wasm init failed, falling back to JS solver."),e({salt:n,target:r})}if(null===t)return console.warn("[cap worker] no wasm module provided, falling back to JS solver."),e({salt:n,target:r});try{const e=performance.now(),o=t(n,r),s=performance.now();self.postMessage({nonce:Number(o),found:!0,durationMs:(s-e).toFixed(2)})}catch(e){console.error("[cap worker]",e),self.postMessage({found:!1,error:e.message||String(e)})}},self.onerror=e=>{self.postMessage({found:!1,error:e})}})();'],{type:"application/javascript"})),n)}class l{constructor(e){this._size=e,this._workers=[],this._idle=[],this._queue=[],this._wasmModule=null,this._spawnFailures=0}setWasm(e){this._wasmModule=e}_spawn(){const e=o(),t=new Worker(e);return t._busy=!1,this._workers.push(t),this._idle.push(t),t}_replaceWorker(e){const t=this._workers.indexOf(e);-1!==t&&this._workers.splice(t,1);const i=this._idle.indexOf(e);-1!==i&&this._idle.splice(i,1);try{e.terminate()}catch{}return this._spawnFailures++,this._spawnFailures>3?(console.error("[cap] worker spawn failed repeatedly, not retrying"),null):this._spawn()}_ensureSize(e){for(;this._workers.length<e;)this._spawn()}run(e,t){return new Promise((i,s)=>{this._queue.push({salt:e,target:t,resolve:i,reject:s}),this._dispatch()})}_dispatch(){for(;this._idle.length>0&&this._queue.length>0;){const e=this._idle.shift(),{salt:t,target:i,resolve:s,reject:r}=this._queue.shift();let a=!1;const n=({data:t})=>{a||(a=!0,e.removeEventListener("message",n),e.removeEventListener("error",o),this._spawnFailures=0,this._idle.push(e),t.found?s(t.nonce):r(new Error(t.error||"worker failed")),this._dispatch())},o=t=>{if(a)return;a=!0,e.removeEventListener("message",n),e.removeEventListener("error",o);const i=this._replaceWorker(e);r(t),i&&this._dispatch()};e.addEventListener("message",n),e.addEventListener("error",o),this._wasmModule?e.postMessage({salt:t,target:i,wasmModule:this._wasmModule},[]):e.postMessage({salt:t,target:i})}}terminate(){for(const e of this._workers)try{e.terminate()}catch{}this._workers=[],this._idle=[],this._queue=[]}}class c extends HTMLElement{static formAssociated=!0;#e=null;#t=navigator.hardwareConcurrency||8;token=null;#i;#s;#r;#a=!1;#n;#o;#l=null;#c=null;#h=null;#d=null;get#p(){return e&&!window.CAP_DISABLE_HAPTICS&&!this.hasAttribute("data-cap-disable-haptics")}#u(){return{state:"idle",challengeResp:null,challenges:null,results:[],completedCount:0,solvePromise:null,promoteFn:null,_listeners:[],pendingPromotion:null,token:null,tokenExpires:null,notify(){for(const e of this._listeners)e();this._listeners=[]},onSettled(e){"done"===this.state||"error"===this.state?e():this._listeners.push(e)}}}#v(){this.#l=this.#u(),this.#m()}#g(){this.#d&&(window.removeEventListener("mousemove",this.#d),window.removeEventListener("touchstart",this.#d),window.removeEventListener("keydown",this.#d),this.#d=null)}#m(){this.#g();const e=()=>{this.#g(),this.#b()};this.#d=e,window.addEventListener("mousemove",e,{passive:!0}),window.addEventListener("touchstart",e,{passive:!0}),window.addEventListener("keydown",e,{passive:!0})}#f(){return"function"==typeof this.checkVisibility?this.checkVisibility({checkOpacity:!0,checkVisibilityCSS:!0}):!!(this.offsetParent||this.getClientRects().length>0)}#b(){"idle"===this.#l.state&&this.#f()&&(this.#l.state="waiting",this.#c=setTimeout(()=>{this.#w()},2500))}async#w(){if("waiting"!==this.#l.state)return;this.#l.state="fetching";let e=this.getAttribute("data-cap-api-endpoint");if(!e&&window?.CAP_CUSTOM_FETCH&&(e="/"),e){e.endsWith("/")||(e+="/");try{const s=await t(`${e}challenge`,{method:"POST"});let r;try{r=await s.json()}catch{throw new Error("Failed to parse speculative challenge response")}if(r.error)throw new Error(r.error);r._apiEndpoint=e,this.#l.challengeResp=r;const{challenge:a,token:n}=r;let o=a;if(!Array.isArray(o)){let e=0;o=Array.from({length:a.c},()=>(e++,[i(`${n}${e}`,a.s),i(`${n}${e}d`,a.d)]))}this.#l.challenges=o,this.#l.state="solving",this.#l.solvePromise=this.#y(o)}catch(e){console.warn("[cap] speculative challenge fetch failed:",e),this.#l.state="error",this.#l.notify()}}else this.#l.state="idle"}async#y(e){o();let t=null;try{t=await a()}catch{}this.#h||(this.#h=new l(1),this.#h._spawn()),this.#h.setWasm(t);const i=e.length,s=new Array(i);let r=1,n=!1;this.#l.promoteFn=e=>{n||(n=!0,r=e,this.#h._size=e,this.#h._ensureSize(e))},null!==this.#l.pendingPromotion&&(this.#l.promoteFn(this.#l.pendingPromotion),this.#l.pendingPromotion=null);let c=0;for(;c<i;){const t=r,a=[],o=[];for(let s=0;s<t&&c<i;s++)o.push(c),a.push(e[c]),c++;this.#h._ensureSize(Math.max(r,t));const l=await Promise.all(a.map(e=>this.#h.run(e[0],e[1]).then(e=>(this.#l.completedCount++,e))));for(let e=0;e<o.length;e++)s[o[e]]=l[e];!n&&c<i&&await new Promise(e=>setTimeout(e,120))}return this.#l.results=s,this.#l.state="redeeming",this.#k(s),s}async#k(e){try{const i=this.#l.challengeResp,r=i._apiEndpoint;if(!r)throw new Error("[cap] speculative redeem: missing apiEndpoint");let a=null;if(i.instrumentation&&(a=await s(i.instrumentation),a?.__timeout||a?.__blocked))return this.#l.state="done",void this.#l.notify();const n=await t(`${r}redeem`,{method:"POST",body:JSON.stringify({token:i.token,solutions:e,...a&&{instr:a}}),headers:{"Content-Type":"application/json"}});let o;try{o=await n.json()}catch{throw new Error("Failed to parse speculative redeem response")}if(!o.success)throw new Error(o.error||"Speculative redeem failed");this.#l.token=o.token,this.#l.tokenExpires=new Date(o.expires).getTime(),this.#l.state="done",this.#l.notify()}catch(e){console.warn("[cap] speculative redeem failed (will redo on click):",e),this.#l.state="done",this.#l.notify()}}getI18nText(e,t){return this.getAttribute(`data-cap-i18n-${e}`)||t}static get observedAttributes(){return["onsolve","onprogress","onreset","onerror","data-cap-worker-count","data-cap-i18n-initial-state","required"]}constructor(){super(),this.#n&&this.#n.forEach((e,t)=>{this.removeEventListener(t.slice(2),e)}),this.#n=new Map,this.boundHandleProgress=this.handleProgress.bind(this),this.boundHandleSolve=this.handleSolve.bind(this),this.boundHandleError=this.handleError.bind(this),this.boundHandleReset=this.handleReset.bind(this);try{this.#o=this.attachInternals()}catch{}}#x(){this.#o?.setValidity&&(this.hasAttribute("required")&&!this.token?this.#o.setValidity({valueMissing:!0},this.getI18nText("required-label","Please verify you're human"),this.#s||this):this.#o.setValidity({}))}initialize(){o(),this.#l||(this.#l=this.#u()),this.#h||(this.#h=new l(1),this.#h._spawn())}attributeChangedCallback(e,t,i){if(e.startsWith("on")){const t=e.slice(2),s=this.#n.get(e);if(s&&this.removeEventListener(t,s),i){const i=t=>{const i=this.getAttribute(e);"function"==typeof window[i]&&window[i].call(this,t)};this.#n.set(e,i),this.addEventListener(t,i)}}"data-cap-worker-count"===e&&this.setWorkersCount(parseInt(i,10)),"data-cap-i18n-initial-state"===e&&this.#s&&this.#s?.querySelector(".label.active")&&this.animateLabel(this.getI18nText("initial-state","Verify you're human")),"required"===e&&this.#x()}async connectedCallback(){this.#r=this,this.#i=this.attachShadow({mode:"open"}),this.#s=document.createElement("div"),this.createUI(),this.addEventListeners(),this.initialize(),this.#s.removeAttribute("disabled");const e=this.getAttribute("data-cap-worker-count"),t=e?parseInt(e,10):null;this.setWorkersCount(t||navigator.hardwareConcurrency||8);const i=this.getAttribute("data-cap-hidden-field-name")||"cap-token";this.#r.innerHTML=`<input type="hidden" name="${i}">`,this.#m(),this.#x(),this.addEventListener("invalid",this.#E)}#E=()=>{if(this.#s){try{this.scrollIntoView({behavior:"smooth",block:"center"})}catch{this.scrollIntoView()}this.#s.classList.remove("invalid"),this.#s.offsetWidth,this.#s.classList.add("invalid"),setTimeout(()=>this.#s?.classList.remove("invalid"),1500)}};async solve(){if(!this.#a)try{this.#a=!0,this.updateUI("verifying",this.getI18nText("verifying-label","Verifying..."),!0),this.#s.setAttribute("aria-label",this.getI18nText("verifying-aria-label","Verifying you're a human, please wait")),this.dispatchEvent("progress",{progress:0});try{let e,r,a=this.getAttribute("data-cap-api-endpoint");if(!a&&window?.CAP_CUSTOM_FETCH)a="/";else if(!a)throw new Error("Missing API endpoint. Either custom fetch or an API endpoint must be provided.");if(a.endsWith("/")||(a+="/"),"done"===this.#l.state&&this.#l.token&&this.#l.tokenExpires&&Date.now()<this.#l.tokenExpires){this.dispatchEvent("progress",{progress:100});const e=this.getAttribute("data-cap-hidden-field-name")||"cap-token";this.querySelector(`input[name='${e}']`)&&(this.querySelector(`input[name='${e}']`).value=this.#l.token),this.dispatchEvent("solve",{token:this.#l.token}),this.token=this.#l.token;const t=this.#l.tokenExpires-Date.now();return this.#e&&clearTimeout(this.#e),this.#e=setTimeout(()=>this.reset(),t),this.#s.setAttribute("aria-label",this.getI18nText("verified-aria-label","We have verified you're a human, you may now continue")),this.#p&&navigator.vibrate([10,50,20,30,40]),this.#v(),this.#a=!1,{success:!0,token:this.token}}if("done"===this.#l.state)e=this.#l.results,r=this.#l.challengeResp,this.dispatchEvent("progress",{progress:100});else if("solving"===this.#l.state||"redeeming"===this.#l.state||"fetching"===this.#l.state||"waiting"===this.#l.state){"waiting"===this.#l.state&&(this.#c&&(clearTimeout(this.#c),this.#c=null),this.#l.state="waiting",this.#w()),this.#l.pendingPromotion=this.#t,this.#l.promoteFn&&this.#l.promoteFn(this.#t);const t=setInterval(()=>{const e=this.#l.state;if("done"===e||"error"===e)return void clearInterval(t);const i=this.#l.challenges?this.#l.challenges.length:1,s=this.#l.completedCount,r="redeeming"===e?99:"fetching"===e||"waiting"===e?0:Math.min(98,Math.round(s/i*100));this.dispatchEvent("progress",{progress:r})},150);if(await new Promise(e=>this.#l.onSettled(e)),clearInterval(t),"done"!==this.#l.state)throw new Error("Speculative solve failed – please try again");if(this.#l.token&&this.#l.tokenExpires&&Date.now()<this.#l.tokenExpires){this.dispatchEvent("progress",{progress:100});const e=this.getAttribute("data-cap-hidden-field-name")||"cap-token";this.querySelector(`input[name='${e}']`)&&(this.querySelector(`input[name='${e}']`).value=this.#l.token),this.dispatchEvent("solve",{token:this.#l.token}),this.token=this.#l.token;const t=this.#l.tokenExpires-Date.now();return this.#e&&clearTimeout(this.#e),this.#e=setTimeout(()=>this.reset(),t),this.#s.setAttribute("aria-label",this.getI18nText("verified-aria-label","We have verified you're a human, you may now continue")),this.#p&&navigator.vibrate([10,50,20,30,40]),this.#v(),this.#a=!1,{success:!0,token:this.token}}e=this.#l.results,r=this.#l.challengeResp,this.dispatchEvent("progress",{progress:100})}else{const s=await t(`${a}challenge`,{method:"POST"});try{r=await s.json()}catch{throw new Error("Failed to parse challenge response from server")}if(r.error)throw new Error(r.error);const{challenge:n,token:o}=r;let l=n;if(!Array.isArray(l)){let e=0;l=Array.from({length:n.c},()=>(e++,[i(`${o}${e}`,n.s),i(`${o}${e}d`,n.d)]))}e=await this.solveChallenges(l)}const n=r.instrumentation?s(r.instrumentation):Promise.resolve(null),o=await n;if(o?.__timeout||o?.__blocked){this.updateUIBlocked(this.getI18nText("error-label","Error"),o?.__blocked),this.#s.setAttribute("aria-label",this.getI18nText("error-aria-label","An error occurred, please try again")),this.removeEventListener("error",this.boundHandleError);const e=new CustomEvent("error",{bubbles:!0,composed:!0,detail:{isCap:!0,message:"Instrumentation failed"}});return super.dispatchEvent(e),this.addEventListener("error",this.boundHandleError),this.executeAttributeCode("onerror",e),console.error("[cap]","Instrumentation failed"),void(this.#a=!1)}const{token:l}=r,c=await t(`${a}redeem`,{method:"POST",body:JSON.stringify({token:l,solutions:e,...o&&{instr:o}}),headers:{"Content-Type":"application/json"}});let h;try{h=await c.json()}catch{throw new Error("Failed to parse server response")}if(this.dispatchEvent("progress",{progress:100}),!h.success)throw new Error(h.error||"Invalid solution");const d=this.getAttribute("data-cap-hidden-field-name")||"cap-token";this.querySelector(`input[name='${d}']`)&&(this.querySelector(`input[name='${d}']`).value=h.token),this.dispatchEvent("solve",{token:h.token}),this.token=h.token,this.#v(),this.#e&&clearTimeout(this.#e);const p=new Date(h.expires).getTime()-Date.now();return p>0&&p<864e5?this.#e=setTimeout(()=>this.reset(),p):this.error("Invalid expiration time"),this.#s.setAttribute("aria-label",this.getI18nText("verified-aria-label","We have verified you're a human, you may now continue")),this.#p&&navigator.vibrate([10,50,20,30,40]),{success:!0,token:this.token}}catch(e){throw this.#s.setAttribute("aria-label",this.getI18nText("error-aria-label","An error occurred, please try again")),this.error(e.message),e}}finally{this.#a=!1}}async solveChallenges(e){const t=e.length;let i=0;let s=null;const r="object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate;if(r)try{s=await a()}catch(e){console.warn("[cap] wasm unavailable, falling back to JS solver:",e)}if(!r&&!this.#i.querySelector(".warning")){const e=document.createElement("div");e.className="warning",e.style.cssText="width:var(--cap-widget-width,230px);background:rgb(237,56,46);color:white;padding:4px 6px;padding-bottom:calc(var(--cap-border-radius,14px) + 5px);font-size:10px;box-sizing:border-box;font-family:system-ui;border-top-left-radius:8px;border-top-right-radius:8px;text-align:center;user-select:none;margin-bottom:-35.5px;opacity:0;transition:margin-bottom .3s,opacity .3s;",e.innerText=this.getI18nText("wasm-disabled","Enable WASM for significantly faster solving"),this.#i.insertBefore(e,this.#i.firstChild),setTimeout(()=>{e.style.marginBottom="calc(-1 * var(--cap-border-radius, 14px))",e.style.opacity=1},10)}const n=new l(this.#t);n.setWasm(s),n._ensureSize(this.#t);const o=[];try{for(let s=0;s<e.length;s+=this.#t){const r=e.slice(s,Math.min(s+this.#t,e.length)),a=await Promise.all(r.map(([e,s])=>n.run(e,s).then(e=>{i++;const s=Math.min(99,Math.round((0+i)/t*100));return this.dispatchEvent("progress",{progress:s}),e})));o.push(...a)}}finally{n.terminate()}return o}setWorkersCount(e){const t=parseInt(e,10),i=Math.min(navigator.hardwareConcurrency||8,16);this.#t=!Number.isNaN(t)&&t>0&&t<=i?t:navigator.hardwareConcurrency||8}createUI(){this.#s.classList.add("captcha"),this.#s.setAttribute("role","button"),this.#s.setAttribute("tabindex","0"),this.#s.setAttribute("aria-label",this.getI18nText("verify-aria-label","Click to verify you're a human")),this.#s.setAttribute("aria-live","polite"),this.#s.setAttribute("disabled","true"),this.#s.innerHTML=`<div class="checkbox" part="checkbox"><svg class="progress-ring" viewBox="0 0 32 32"><circle class="progress-ring-bg" cx="16" cy="16" r="14"></circle><circle class="progress-ring-circle" cx="16" cy="16" r="14"></circle></svg></div><p part="label" class="label-wrapper"><span class="label active">${this.getI18nText("initial-state","Verify you're human")}</span></p><a part="attribution" aria-label="Secured by Cap" href="https://trycap.dev/" class="credits" target="_blank" rel="follow noopener" title="Secured by Cap: Self-hosted CAPTCHA for the modern web.">Cap</a>`,this.#i.innerHTML=`<style${window.CAP_CSS_NONCE?` nonce=${window.CAP_CSS_NONCE}`:""}>@media (prefers-reduced-motion:reduce){.captcha,.captcha *{transition:none!important;animation:none!important}.label{filter:none!important;opacity:1!important;transition:none!important;transform:none!important}.label:not(.active),.label.exit{display:none!important}}.captcha,.captcha *{box-sizing:border-box}.captcha{background-color:var(--cap-background,#fdfdfd);border:1px solid var(--cap-border-color,#dddddd8f);border-radius:var(--cap-border-radius,14px);-webkit-user-select:none;user-select:none;height:var(--cap-widget-height,58px);width:var(--cap-widget-width,260px);padding:var(--cap-widget-padding,14px);align-items:center;gap:var(--cap-gap,15px);cursor:pointer;-webkit-tap-highlight-color:#fff0;color:var(--cap-color,#212121);transition:filter .2s,transform .2s;display:flex;position:relative;overflow:hidden}.captcha:not([data-state]):active{transform:scale(.97)}.captcha:hover{filter:brightness(98%)}.captcha *{font-family:var(--cap-font,system, -apple-system, "BlinkMacSystemFont", ".SFNSText-Regular", "San Francisco", "Roboto", "Segoe UI", "Helvetica Neue", "Lucida Grande", "Ubuntu", "arial", sans-serif)}.checkbox{width:var(--cap-checkbox-size,25px);height:var(--cap-checkbox-size,25px);border:var(--cap-checkbox-border,1px solid #aaaaaad1);border-radius:var(--cap-checkbox-border-radius,6px);background-color:var(--cap-checkbox-background,#fafafa91);margin-top:var(--cap-checkbox-margin,2px);margin-bottom:var(--cap-checkbox-margin,2px);transition:opacity .2s}.captcha p{-webkit-user-select:none;user-select:none;margin:0;font-size:15px;font-weight:500}.label-wrapper{flex:1;align-items:center;min-width:0;height:2em;display:flex;position:relative;overflow:hidden}.label-wrapper:before,.label-wrapper:after{content:"";pointer-events:none;z-index:1;width:100%;height:.6em;position:absolute;left:0}.label-wrapper:before{background:linear-gradient(to bottom, var(--cap-background,#fdfdfd), transparent);top:0}.label-wrapper:after{background:linear-gradient(to top, var(--cap-background,#fdfdfd), transparent);bottom:0}.label{white-space:nowrap;opacity:0;filter:blur(2px);transition:transform .5s cubic-bezier(.25,1,.5,1),opacity .5s,filter .5s;position:absolute;transform:translateY(100%)}.label.active{opacity:1;filter:none;transform:translateY(0)}.label.exit{opacity:0;filter:blur(2px);transform:translateY(-100%)}.checkbox .progress-ring{width:100%;height:100%;display:none;transform:rotate(-90deg)}.checkbox .progress-ring-bg{fill:none;stroke:var(--cap-spinner-background-color,#eee);stroke-width:var(--cap-spinner-thickness,3)}.checkbox .progress-ring-circle{fill:none;stroke:var(--cap-spinner-color,#000);stroke-width:var(--cap-spinner-thickness,3);stroke-linecap:round;stroke-dasharray:87.96;stroke-dashoffset:87.96px;transition:stroke-dashoffset .3s}.captcha[data-state=verifying] .checkbox{background:0 0;border:none;border-radius:50%;justify-content:center;align-items:center;display:flex;transform:scale(1.1)}.captcha[data-state=verifying] .checkbox .progress-ring{display:block}.captcha[data-state=done] .checkbox{background-image:var(--cap-checkmark,url(data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cstyle%3E%40keyframes%20anim%7B0%25%7Bstroke-dashoffset%3A23.21320343017578px%7Dto%7Bstroke-dashoffset%3A0%7D%7D%3C%2Fstyle%3E%3Cpath%20fill%3D%22none%22%20stroke%3D%22%2300a67d%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%20stroke-width%3D%222%22%20d%3D%22m5%2012%205%205L20%207%22%20style%3D%22stroke-dashoffset%3A0%3Bstroke-dasharray%3A23.21320343017578px%3Banimation%3Aanim%20.5s%20ease%22%2F%3E%3C%2Fsvg%3E));background-size:cover;border:1px solid #0000}.captcha[data-state=done] .checkbox .progress-ring{display:none}.captcha[data-state=error] .checkbox{background-image:var(--cap-error-cross,url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96' viewBox='0 0 24 24'%3E%3Cpath fill='%23f55b50' d='M11 15h2v2h-2zm0-8h2v6h-2zm1-5C6.47 2 2 6.5 2 12a10 10 0 0 0 10 10a10 10 0 0 0 10-10A10 10 0 0 0 12 2m0 18a8 8 0 0 1-8-8a8 8 0 0 1 8-8a8 8 0 0 1 8 8a8 8 0 0 1-8 8'/%3E%3C%2Fsvg%3E"));background-size:cover;border:1px solid #0000}.captcha[data-state=error] .checkbox .progress-ring{display:none}.captcha.invalid{border-color:var(--cap-invalid-border-color,#f55b50);box-shadow:0 0 0 3px var(--cap-invalid-ring-color,#f55b5033);animation:.5s cubic-bezier(.36,.07,.19,.97) cap-shake}@keyframes cap-shake{10%,90%{transform:translate(-1px)}20%,80%{transform:translate(2px)}30%,50%,70%{transform:translate(-4px)}40%,60%{transform:translate(4px)}}@media (prefers-reduced-motion:reduce){.captcha.invalid{animation:none!important}}.captcha[disabled]{cursor:not-allowed}.captcha[disabled][data-state=verifying]{cursor:progress}.captcha[disabled][data-state=done]{cursor:default}.captcha .credits{color:var(--cap-color,#212121);text-underline-offset:.18em;z-index:6;text-decoration-thickness:.08em;position:absolute;bottom:10px;right:10px;opacity:.8!important;font-size:12px!important;display:block!important}.cap-troubleshoot-link{color:#06c;text-underline-offset:.15em;cursor:pointer;font-weight:500;font-size:inherit;text-decoration:underline;text-decoration-thickness:.08em}.cap-troubleshoot-link:hover{opacity:.8}</style>`,this.#i.appendChild(this.#s)}addEventListeners(){this.#s&&(this.#s.querySelector("a").addEventListener("click",e=>{e.stopPropagation(),e.preventDefault(),window.open("https://trycap.dev","_blank")}),this.#s.addEventListener("click",()=>{this.#s.hasAttribute("disabled")||this.solve()}),this.#s.addEventListener("mousedown",()=>{!this.#s.hasAttribute("disabled")&&this.#p&&navigator.vibrate(5)}),this.#s.addEventListener("keydown",e=>{"Enter"!==e.key&&" "!==e.key||this.#s.hasAttribute("disabled")||(e.preventDefault(),e.stopPropagation(),this.solve())}),this.addEventListener("progress",this.boundHandleProgress),this.addEventListener("solve",this.boundHandleSolve),this.addEventListener("error",this.boundHandleError),this.addEventListener("reset",this.boundHandleReset))}animateLabel(e){if(!this.#s)return;const t=this.#s.querySelector(".label-wrapper");if(!t)return;if(window.matchMedia?.("(prefers-reduced-motion: reduce)").matches){const i=t.querySelector(".label.active");if(i)i.textContent=e;else{const i=document.createElement("span");i.className="label active",i.textContent=e,t.appendChild(i)}return}const i=t.querySelector(".label.active"),s=document.createElement("span");s.className="label",s.textContent=e,t.appendChild(s),s.offsetWidth,s.classList.add("active"),i&&(i.classList.remove("active"),i.classList.add("exit"),i.addEventListener("transitionend",()=>i.remove(),{once:!0}))}updateUI(e,t,i=!1){this.#s&&(this.#s.setAttribute("data-state",e),this.animateLabel(t),i?this.#s.setAttribute("disabled","true"):this.#s.removeAttribute("disabled"))}updateUIBlocked(e,t=!1){if(!this.#s)return;this.#s.setAttribute("data-state","error"),this.#s.removeAttribute("disabled");const i=this.#s.querySelector(".label-wrapper");if(!i)return;const s=this.getAttribute("data-cap-troubleshooting-url")||"https://trycap.dev/guide/troubleshooting/instrumentation.html",r=i.querySelector(".label.active"),a=document.createElement("span");a.className="label",a.innerHTML=t?`${e} · <a class="cap-troubleshoot-link" href="${s}" target="_blank" rel="noopener">${this.getI18nText("troubleshooting-label","Troubleshoot")}</a>`:e,i.appendChild(a),a.offsetWidth,a.classList.add("active"),r&&(r.classList.remove("active"),r.classList.add("exit"),r.addEventListener("transitionend",()=>r.remove(),{once:!0}));const n=a.querySelector(".cap-troubleshoot-link");n&&n.addEventListener("click",e=>{e.stopPropagation()})}handleProgress(e){if(!this.#s)return;const t=this.#s.querySelector(".progress-ring-circle");if(t){const i=2*Math.PI*14,s=i-e.detail.progress/100*i;t.style.strokeDashoffset=s}const i=this.#s.querySelector(".label-wrapper");if(i){const e=i.querySelector(".label.active");e&&(e.textContent=`${this.getI18nText("verifying-label","Verifying...")}`)}this.executeAttributeCode("onprogress",e)}handleSolve(e){this.updateUI("done",this.getI18nText("solved-label","You're a human"),!0),this.executeAttributeCode("onsolve",e),this.#o?.setValidity?.({}),this.#s?.classList.remove("invalid")}handleError(e){this.updateUI("error",this.getI18nText("error-label","Error. Try again.")),this.executeAttributeCode("onerror",e),this.#p&&navigator.vibrate([10,40,10])}handleReset(e){this.updateUI("",this.getI18nText("initial-state","I'm a human")),this.executeAttributeCode("onreset",e),this.#x()}executeAttributeCode(e,t){const i=this.getAttribute(e);i&&(console.error("[cap] using `onxxx='…'` is strongly discouraged and will be deprecated soon. please use `addEventListener` callbacks instead."),new Function("event",i).call(this,t))}error(e="Unknown error"){console.error("[cap]",e),this.dispatchEvent("error",{isCap:!0,message:e})}dispatchEvent(e,t={}){const i=new CustomEvent(e,{bubbles:!0,composed:!0,detail:t});super.dispatchEvent(i)}reset(){this.#e&&(clearTimeout(this.#e),this.#e=null),this.token=null,this.dispatchEvent("reset");const e=this.getAttribute("data-cap-hidden-field-name")||"cap-token";this.querySelector(`input[name='${e}']`)&&(this.querySelector(`input[name='${e}']`).value="")}get tokenValue(){return this.token}disconnectedCallback(){this.removeEventListener("progress",this.boundHandleProgress),this.removeEventListener("solve",this.boundHandleSolve),this.removeEventListener("error",this.boundHandleError),this.removeEventListener("reset",this.boundHandleReset),this.#n.forEach((e,t)=>{this.removeEventListener(t.slice(2),e)}),this.#n.clear(),this.#i&&(this.#i.innerHTML=""),this.reset(),this.cleanup()}cleanup(){this.#e&&(clearTimeout(this.#e),this.#e=null),this.#g(),this.#c&&(clearTimeout(this.#c),this.#c=null),this.#h&&(this.#h.terminate(),this.#h=null),this.#l&&(this.#l.state="error",this.#l.notify(),this.#l=null)}}class h{constructor(e={},t){const i=t||document.createElement("cap-widget");if(Object.entries(e).forEach(([e,t])=>{i.setAttribute(e,t)}),!e.apiEndpoint&&!window?.CAP_CUSTOM_FETCH)throw i.remove(),new Error("Missing API endpoint. Either custom fetch or an API endpoint must be provided.");e.apiEndpoint&&i.setAttribute("data-cap-api-endpoint",e.apiEndpoint),t||i.hasAttribute("data-cap-disable-haptics")||i.setAttribute("data-cap-disable-haptics",""),this.widget=i,this.solve=this.widget.solve.bind(this.widget),this.reset=this.widget.reset.bind(this.widget),this.addEventListener=this.widget.addEventListener.bind(this.widget),Object.defineProperty(this,"token",{get:()=>i.token,configurable:!0,enumerable:!0}),t||(i.style.display="none",document.documentElement.appendChild(i))}}window.Cap=h,customElements.get("cap-widget")||window?.CAP_DONT_SKIP_REDEFINE?customElements.get("cap-widget")&&console.warn("[cap] the cap-widget element has already been defined, skipping re-defining it.\nto prevent this, set window.CAP_DONT_SKIP_REDEFINE to true"):customElements.define("cap-widget",c),"object"==typeof exports&&"undefined"!=typeof module?module.exports=h:"function"==typeof define&&define.amd&&define([],()=>h),"undefined"!=typeof exports&&(exports.default=h)})();
|