@zaptcha/widget 1.0.0 → 1.0.2

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/src/zaptcha.js DELETED
@@ -1,249 +0,0 @@
1
- /* @ts-self-types="./zaptcha.d.ts" */
2
-
3
- /**
4
- * @param {string} token
5
- * @param {number} difficulty
6
- * @param {number} challenge_count
7
- * @param {number} salt_length
8
- * @param {Function} progress_callback
9
- * @returns {Uint32Array}
10
- */
11
- export function solve_challenge(token, difficulty, challenge_count, salt_length, progress_callback) {
12
- const ptr0 = passStringToWasm0(token, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
13
- const len0 = WASM_VECTOR_LEN;
14
- const ret = wasm.solve_challenge(ptr0, len0, difficulty, challenge_count, salt_length, progress_callback);
15
- var v2 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
16
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
17
- return v2;
18
- }
19
-
20
- function __wbg_get_imports() {
21
- const import0 = {
22
- __proto__: null,
23
- __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
24
- throw new Error(getStringFromWasm0(arg0, arg1));
25
- },
26
- __wbg_call_dcc2662fa17a72cf: function() { return handleError(function (arg0, arg1, arg2, arg3) {
27
- const ret = arg0.call(arg1, arg2, arg3);
28
- return ret;
29
- }, arguments); },
30
- __wbindgen_cast_0000000000000001: function(arg0) {
31
- // Cast intrinsic for `F64 -> Externref`.
32
- const ret = arg0;
33
- return ret;
34
- },
35
- __wbindgen_init_externref_table: function() {
36
- const table = wasm.__wbindgen_externrefs;
37
- const offset = table.grow(4);
38
- table.set(0, undefined);
39
- table.set(offset + 0, undefined);
40
- table.set(offset + 1, null);
41
- table.set(offset + 2, true);
42
- table.set(offset + 3, false);
43
- },
44
- };
45
- return {
46
- __proto__: null,
47
- "./zaptcha_bg.js": import0,
48
- };
49
- }
50
-
51
- function addToExternrefTable0(obj) {
52
- const idx = wasm.__externref_table_alloc();
53
- wasm.__wbindgen_externrefs.set(idx, obj);
54
- return idx;
55
- }
56
-
57
- function getArrayU32FromWasm0(ptr, len) {
58
- ptr = ptr >>> 0;
59
- return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
60
- }
61
-
62
- function getStringFromWasm0(ptr, len) {
63
- ptr = ptr >>> 0;
64
- return decodeText(ptr, len);
65
- }
66
-
67
- let cachedUint32ArrayMemory0 = null;
68
- function getUint32ArrayMemory0() {
69
- if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
70
- cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
71
- }
72
- return cachedUint32ArrayMemory0;
73
- }
74
-
75
- let cachedUint8ArrayMemory0 = null;
76
- function getUint8ArrayMemory0() {
77
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
78
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
79
- }
80
- return cachedUint8ArrayMemory0;
81
- }
82
-
83
- function handleError(f, args) {
84
- try {
85
- return f.apply(this, args);
86
- } catch (e) {
87
- const idx = addToExternrefTable0(e);
88
- wasm.__wbindgen_exn_store(idx);
89
- }
90
- }
91
-
92
- function passStringToWasm0(arg, malloc, realloc) {
93
- if (realloc === undefined) {
94
- const buf = cachedTextEncoder.encode(arg);
95
- const ptr = malloc(buf.length, 1) >>> 0;
96
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
97
- WASM_VECTOR_LEN = buf.length;
98
- return ptr;
99
- }
100
-
101
- let len = arg.length;
102
- let ptr = malloc(len, 1) >>> 0;
103
-
104
- const mem = getUint8ArrayMemory0();
105
-
106
- let offset = 0;
107
-
108
- for (; offset < len; offset++) {
109
- const code = arg.charCodeAt(offset);
110
- if (code > 0x7F) break;
111
- mem[ptr + offset] = code;
112
- }
113
- if (offset !== len) {
114
- if (offset !== 0) {
115
- arg = arg.slice(offset);
116
- }
117
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
118
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
119
- const ret = cachedTextEncoder.encodeInto(arg, view);
120
-
121
- offset += ret.written;
122
- ptr = realloc(ptr, len, offset, 1) >>> 0;
123
- }
124
-
125
- WASM_VECTOR_LEN = offset;
126
- return ptr;
127
- }
128
-
129
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
130
- cachedTextDecoder.decode();
131
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
132
- let numBytesDecoded = 0;
133
- function decodeText(ptr, len) {
134
- numBytesDecoded += len;
135
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
136
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
137
- cachedTextDecoder.decode();
138
- numBytesDecoded = len;
139
- }
140
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
141
- }
142
-
143
- const cachedTextEncoder = new TextEncoder();
144
-
145
- if (!('encodeInto' in cachedTextEncoder)) {
146
- cachedTextEncoder.encodeInto = function (arg, view) {
147
- const buf = cachedTextEncoder.encode(arg);
148
- view.set(buf);
149
- return {
150
- read: arg.length,
151
- written: buf.length
152
- };
153
- };
154
- }
155
-
156
- let WASM_VECTOR_LEN = 0;
157
-
158
- let wasmModule, wasm;
159
- function __wbg_finalize_init(instance, module) {
160
- wasm = instance.exports;
161
- wasmModule = module;
162
- cachedUint32ArrayMemory0 = null;
163
- cachedUint8ArrayMemory0 = null;
164
- wasm.__wbindgen_start();
165
- return wasm;
166
- }
167
-
168
- async function __wbg_load(module, imports) {
169
- if (typeof Response === 'function' && module instanceof Response) {
170
- if (typeof WebAssembly.instantiateStreaming === 'function') {
171
- try {
172
- return await WebAssembly.instantiateStreaming(module, imports);
173
- } catch (e) {
174
- const validResponse = module.ok && expectedResponseType(module.type);
175
-
176
- if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
177
- console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
178
-
179
- } else { throw e; }
180
- }
181
- }
182
-
183
- const bytes = await module.arrayBuffer();
184
- return await WebAssembly.instantiate(bytes, imports);
185
- } else {
186
- const instance = await WebAssembly.instantiate(module, imports);
187
-
188
- if (instance instanceof WebAssembly.Instance) {
189
- return { instance, module };
190
- } else {
191
- return instance;
192
- }
193
- }
194
-
195
- function expectedResponseType(type) {
196
- switch (type) {
197
- case 'basic': case 'cors': case 'default': return true;
198
- }
199
- return false;
200
- }
201
- }
202
-
203
- function initSync(module) {
204
- if (wasm !== undefined) return wasm;
205
-
206
-
207
- if (module !== undefined) {
208
- if (Object.getPrototypeOf(module) === Object.prototype) {
209
- ({module} = module)
210
- } else {
211
- console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
212
- }
213
- }
214
-
215
- const imports = __wbg_get_imports();
216
- if (!(module instanceof WebAssembly.Module)) {
217
- module = new WebAssembly.Module(module);
218
- }
219
- const instance = new WebAssembly.Instance(module, imports);
220
- return __wbg_finalize_init(instance, module);
221
- }
222
-
223
- async function __wbg_init(module_or_path) {
224
- if (wasm !== undefined) return wasm;
225
-
226
-
227
- if (module_or_path !== undefined) {
228
- if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
229
- ({module_or_path} = module_or_path)
230
- } else {
231
- console.warn('using deprecated parameters for the initialization function; pass a single object instead')
232
- }
233
- }
234
-
235
- if (module_or_path === undefined) {
236
- module_or_path = new URL('zaptcha_bg.wasm', import.meta.url);
237
- }
238
- const imports = __wbg_get_imports();
239
-
240
- if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
241
- module_or_path = fetch(module_or_path);
242
- }
243
-
244
- const { instance, module } = await __wbg_load(await module_or_path, imports);
245
-
246
- return __wbg_finalize_init(instance, module);
247
- }
248
-
249
- export { initSync, __wbg_init as default };
Binary file