@prosopo/client-bundle-example 2.10.12 → 2.10.18

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 (42) hide show
  1. package/.turbo/turbo-build$colon$cjs.log +6 -6
  2. package/.turbo/turbo-build$colon$tsc.log +14 -14
  3. package/.turbo/turbo-build.log +7 -7
  4. package/CHANGELOG.md +46 -0
  5. package/README.md +3 -1
  6. package/env.development +7 -0
  7. package/env.production +6 -0
  8. package/env.staging +2 -2
  9. package/package.json +10 -5
  10. package/src/assets/dummy.txt +0 -0
  11. package/src/frictionless-explicit-web3.html +249 -0
  12. package/src/frictionless-explicit.html +208 -0
  13. package/src/frictionless-implicit.html +218 -0
  14. package/src/image-explicit-web3.html +198 -0
  15. package/src/image-explicit.html +158 -0
  16. package/src/index.html +207 -0
  17. package/src/index.ts +76 -0
  18. package/src/invisible-frictionless-explicit.html +132 -0
  19. package/src/invisible-frictionless-implicit.html +204 -0
  20. package/src/invisible-image-explicit.html +161 -0
  21. package/src/invisible-image-implicit.html +203 -0
  22. package/src/invisible-pow-explicit.html +161 -0
  23. package/src/invisible-pow-implicit.html +106 -0
  24. package/src/invisible-puzzle-explicit.html +160 -0
  25. package/src/invisible-puzzle-implicit.html +106 -0
  26. package/src/plugins/explanation-injector.ts +294 -0
  27. package/src/plugins/form-filler-injector.ts +233 -0
  28. package/src/plugins/navigation-injector.ts +602 -0
  29. package/src/plugins/status-log-injector.ts +199 -0
  30. package/src/pow-explicit-web3.html +195 -0
  31. package/src/pow-explicit.html +158 -0
  32. package/src/pow-implicit.html +207 -0
  33. package/src/puzzle-explicit.html +158 -0
  34. package/src/puzzle-implicit.html +207 -0
  35. package/src/styles/captcha.css +78 -0
  36. package/src/styles/field.css +12 -0
  37. package/tsconfig.cjs.json +25 -0
  38. package/tsconfig.json +31 -0
  39. package/tsconfig.tsbuildinfo +1 -0
  40. package/tsconfig.types.json +9 -0
  41. package/vite.cjs.config.ts +1 -1
  42. package/vite.config.ts +37 -4
@@ -0,0 +1,602 @@
1
+ // Copyright 2021-2026 Prosopo (UK) Ltd.
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.
14
+ // Vite plugin to inject navigation into HTML files
15
+ import path from "node:path";
16
+ import {
17
+ type IndexHtmlTransformContext,
18
+ type Plugin,
19
+ normalizePath,
20
+ } from "vite";
21
+
22
+ interface CaptchaTypeDetails {
23
+ path: string;
24
+ exists: boolean;
25
+ }
26
+
27
+ interface CaptchaType {
28
+ [key: string]: CaptchaTypeDetails;
29
+ }
30
+
31
+ interface CaptchaTypes {
32
+ [key: string]: CaptchaType;
33
+ }
34
+
35
+ export default function navigationInjector(): Plugin {
36
+ // Define all pages, including existing and planned
37
+ const pageDefinitions = {
38
+ standard: {
39
+ image: {
40
+ implicit: { path: "index.html", exists: true },
41
+ explicit: { path: "image-explicit.html", exists: true },
42
+ },
43
+ pow: {
44
+ implicit: { path: "pow-implicit.html", exists: true },
45
+ explicit: { path: "pow-explicit.html", exists: true },
46
+ },
47
+ frictionless: {
48
+ implicit: { path: "frictionless-implicit.html", exists: true },
49
+ explicit: { path: "frictionless-explicit.html", exists: true },
50
+ },
51
+ puzzle: {
52
+ implicit: { path: "puzzle-implicit.html", exists: true },
53
+ explicit: { path: "puzzle-explicit.html", exists: true },
54
+ },
55
+ },
56
+ invisible: {
57
+ image: {
58
+ implicit: { path: "invisible-image-implicit.html", exists: true },
59
+ explicit: { path: "invisible-image-explicit.html", exists: true },
60
+ },
61
+ pow: {
62
+ implicit: { path: "invisible-pow-implicit.html", exists: true },
63
+ explicit: { path: "invisible-pow-explicit.html", exists: true },
64
+ },
65
+ frictionless: {
66
+ implicit: {
67
+ path: "invisible-frictionless-implicit.html",
68
+ exists: true,
69
+ },
70
+ explicit: {
71
+ path: "invisible-frictionless-explicit.html",
72
+ exists: true,
73
+ },
74
+ },
75
+ puzzle: {
76
+ implicit: { path: "invisible-puzzle-implicit.html", exists: true },
77
+ explicit: { path: "invisible-puzzle-explicit.html", exists: true },
78
+ },
79
+ },
80
+ };
81
+
82
+ // Style for the navigation bar
83
+ const navStyle = `
84
+ <style>
85
+ .nav-topbar {
86
+ background-color: #2196F3;
87
+ padding: 0;
88
+ margin-bottom: 20px;
89
+ transition: all 0.3s ease;
90
+ overflow: hidden;
91
+ max-height: 500px;
92
+ box-shadow: 0 2px 5px rgba(0,0,0,0.2);
93
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
94
+ }
95
+ .nav-topbar.collapsed {
96
+ max-height: 60px;
97
+ }
98
+ .nav-container {
99
+ max-width: 1200px;
100
+ margin: 0 auto;
101
+ padding: 0 20px;
102
+ position: relative;
103
+ }
104
+ .nav-header {
105
+ display: flex;
106
+ justify-content: space-between;
107
+ align-items: center;
108
+ padding: 12px 0;
109
+ position: relative;
110
+ z-index: 20;
111
+ }
112
+ .nav-title {
113
+ color: white;
114
+ font-size: 1.25rem;
115
+ font-weight: 600;
116
+ margin: 0;
117
+ display: flex;
118
+ align-items: center;
119
+ gap: 8px;
120
+ }
121
+ .nav-title-text {
122
+ margin-right: 8px;
123
+ }
124
+ .nav-title-hint {
125
+ font-size: 0.875rem;
126
+ font-weight: normal;
127
+ opacity: 0;
128
+ transition: opacity 0.3s ease;
129
+ color: rgba(255,255,255,0.8);
130
+ }
131
+ .collapsed .nav-title-hint {
132
+ opacity: 0.8;
133
+ }
134
+ .nav-toggle {
135
+ background-color: rgba(255,255,255,0.1);
136
+ color: white;
137
+ border: none;
138
+ padding: 8px 12px;
139
+ cursor: pointer;
140
+ border-radius: 6px;
141
+ z-index: 10;
142
+ display: flex;
143
+ align-items: center;
144
+ justify-content: center;
145
+ transition: background-color 0.2s ease;
146
+ }
147
+ .nav-toggle:hover {
148
+ background-color: rgba(255,255,255,0.2);
149
+ }
150
+ .nav-toggle-icon {
151
+ width: 24px;
152
+ height: 24px;
153
+ display: inline-block;
154
+ position: relative;
155
+ }
156
+ .nav-toggle-icon svg {
157
+ position: absolute;
158
+ top: 0;
159
+ left: 0;
160
+ transition: opacity 0.3s ease;
161
+ }
162
+ .nav-toggle-icon .icon-collapse {
163
+ opacity: 1;
164
+ }
165
+ .nav-toggle-icon .icon-expand {
166
+ opacity: 0;
167
+ }
168
+ .collapsed .nav-toggle-icon .icon-collapse {
169
+ opacity: 0;
170
+ }
171
+ .collapsed .nav-toggle-icon .icon-expand {
172
+ opacity: 1;
173
+ }
174
+ .nav-content {
175
+ padding: 0 0 20px 0;
176
+ transition: opacity 0.3s ease;
177
+ }
178
+ .collapsed .nav-content {
179
+ opacity: 0;
180
+ }
181
+ .nav-sections {
182
+ display: flex;
183
+ flex-wrap: wrap;
184
+ gap: 20px;
185
+ }
186
+ .nav-section {
187
+ flex: 1;
188
+ min-width: 280px;
189
+ }
190
+ .nav-section h3 {
191
+ color: white;
192
+ font-size: 1rem;
193
+ font-weight: 600;
194
+ margin: 0 0 12px 0;
195
+ padding-bottom: 8px;
196
+ border-bottom: 1px solid rgba(255,255,255,0.2);
197
+ }
198
+ .nav-group {
199
+ background: rgba(255,255,255,0.1);
200
+ border-radius: 8px;
201
+ padding: 12px;
202
+ margin-bottom: 12px;
203
+ }
204
+ .nav-group-title {
205
+ color: rgba(255,255,255,0.9);
206
+ font-size: 0.875rem;
207
+ font-weight: 500;
208
+ margin: 0 0 8px 0;
209
+ text-transform: uppercase;
210
+ letter-spacing: 0.5px;
211
+ }
212
+ .nav-group-links {
213
+ list-style: none;
214
+ margin: 0;
215
+ padding: 0;
216
+ }
217
+ .nav-group-links li {
218
+ margin: 6px 0;
219
+ }
220
+ .nav-group-links a {
221
+ color: white;
222
+ text-decoration: none;
223
+ font-weight: 500;
224
+ padding: 6px 8px;
225
+ display: inline-block;
226
+ border-radius: 4px;
227
+ transition: background-color 0.2s ease;
228
+ }
229
+ .nav-group-links a:hover {
230
+ background-color: rgba(255,255,255,0.2);
231
+ }
232
+ .nav-group-links .active {
233
+ background-color: rgba(255,255,255,0.2);
234
+ font-weight: 600;
235
+ }
236
+ .nav-group-links .disabled {
237
+ color: rgba(255,255,255,0.5);
238
+ cursor: not-allowed;
239
+ opacity: 0.7;
240
+ }
241
+
242
+ @media (max-width: 768px) {
243
+ .nav-container {
244
+ padding: 0 16px;
245
+ }
246
+ .nav-title {
247
+ font-size: 1.125rem;
248
+ }
249
+ .nav-title-hint {
250
+ display: none;
251
+ }
252
+ .nav-sections {
253
+ flex-direction: column;
254
+ gap: 16px;
255
+ }
256
+ .nav-section {
257
+ min-width: 100%;
258
+ }
259
+ .nav-section h3 {
260
+ font-size: 0.875rem;
261
+ }
262
+ .nav-group {
263
+ padding: 10px;
264
+ }
265
+ .nav-group-title {
266
+ font-size: 0.8125rem;
267
+ }
268
+ .nav-group-links a {
269
+ padding: 8px 10px;
270
+ width: 100%;
271
+ }
272
+ }
273
+
274
+ @media (max-width: 480px) {
275
+ .nav-topbar {
276
+ max-height: 60px;
277
+ }
278
+ .nav-topbar.collapsed {
279
+ max-height: 60px;
280
+ }
281
+ .nav-title {
282
+ font-size: 1rem;
283
+ }
284
+ .nav-toggle {
285
+ padding: 6px 10px;
286
+ }
287
+ }
288
+
289
+ .nav-group-dropdown {
290
+ position: relative;
291
+ display: inline-block;
292
+ }
293
+
294
+ .nav-group-dropdown-btn {
295
+ background: none;
296
+ border: none;
297
+ color: white;
298
+ font-weight: 500;
299
+ padding: 6px 8px;
300
+ cursor: pointer;
301
+ display: flex;
302
+ align-items: center;
303
+ gap: 4px;
304
+ border-radius: 4px;
305
+ transition: background-color 0.2s ease;
306
+ }
307
+
308
+ .nav-group-dropdown-btn:hover {
309
+ background-color: rgba(255,255,255,0.2);
310
+ }
311
+
312
+ .nav-group-dropdown-btn svg {
313
+ width: 16px;
314
+ height: 16px;
315
+ transition: transform 0.2s ease;
316
+ }
317
+
318
+ .nav-group-dropdown-btn.open svg {
319
+ transform: rotate(180deg);
320
+ }
321
+
322
+ .nav-group-dropdown-content {
323
+ display: none;
324
+ position: absolute;
325
+ background-color: rgba(33, 150, 243, 0.95);
326
+ min-width: 160px;
327
+ box-shadow: 0 8px 16px rgba(0,0,0,0.2);
328
+ z-index: 1;
329
+ border-radius: 4px;
330
+ padding: 8px 0;
331
+ margin-top: 4px;
332
+ }
333
+
334
+ .nav-group-dropdown-btn.open + .nav-group-dropdown-content {
335
+ display: block;
336
+ }
337
+
338
+ .nav-group-dropdown-content a {
339
+ color: white;
340
+ padding: 8px 16px;
341
+ text-decoration: none;
342
+ display: block;
343
+ transition: background-color 0.2s ease;
344
+ }
345
+
346
+ .nav-group-dropdown-content a:hover {
347
+ background-color: rgba(255,255,255,0.2);
348
+ }
349
+
350
+ .nav-group-dropdown-content a.active {
351
+ background-color: rgba(255,255,255,0.2);
352
+ font-weight: 600;
353
+ }
354
+
355
+ @media (max-width: 768px) {
356
+ .nav-group-dropdown-content {
357
+ position: static;
358
+ box-shadow: none;
359
+ background-color: rgba(255,255,255,0.1);
360
+ margin-top: 8px;
361
+ }
362
+ }
363
+ </style>
364
+ `;
365
+
366
+ // JavaScript for toggling navigation
367
+ const navScript = `
368
+ <script>
369
+ document.addEventListener('DOMContentLoaded', function() {
370
+ const toggleBtn = document.getElementById('nav-toggle');
371
+ const navBar = document.getElementById('nav-topbar');
372
+ const navHeader = document.getElementById('nav-header');
373
+ const isMobile = window.innerWidth <= 768;
374
+
375
+ // Check if navigation was previously collapsed
376
+ const navCollapsed = localStorage.getItem('navCollapsed') === 'true';
377
+ if (navCollapsed) {
378
+ navBar.classList.add('collapsed');
379
+ }
380
+
381
+ // Function to expand the navigation
382
+ function expandNav() {
383
+ if (navBar.classList.contains('collapsed')) {
384
+ navBar.classList.remove('collapsed');
385
+ localStorage.setItem('navCollapsed', 'false');
386
+ }
387
+ }
388
+
389
+ // Function to collapse the navigation
390
+ function collapseNav() {
391
+ if (!navBar.classList.contains('collapsed')) {
392
+ navBar.classList.add('collapsed');
393
+ localStorage.setItem('navCollapsed', 'true');
394
+ }
395
+ }
396
+
397
+ // Function to toggle the navigation
398
+ function toggleNav() {
399
+ navBar.classList.toggle('collapsed');
400
+ localStorage.setItem('navCollapsed', navBar.classList.contains('collapsed'));
401
+ }
402
+
403
+ // Toggle on button click
404
+ toggleBtn.addEventListener('click', function(e) {
405
+ e.stopPropagation();
406
+ toggleNav();
407
+ });
408
+
409
+ // Expand on toggle button hover when collapsed (desktop only)
410
+ if (!isMobile) {
411
+ toggleBtn.addEventListener('mouseenter', function() {
412
+ if (navBar.classList.contains('collapsed')) {
413
+ expandNav();
414
+ }
415
+ });
416
+ }
417
+
418
+ // Toggle on header click
419
+ navHeader.addEventListener('click', function(e) {
420
+ if (e.target.tagName === 'A') {
421
+ return;
422
+ }
423
+ toggleNav();
424
+ });
425
+
426
+ // Make the header appear clickable with cursor style
427
+ navHeader.style.cursor = 'pointer';
428
+
429
+ // Handle window resize
430
+ window.addEventListener('resize', function() {
431
+ const newIsMobile = window.innerWidth <= 768;
432
+ if (newIsMobile !== isMobile) {
433
+ if (newIsMobile) {
434
+ // On mobile, collapse the nav by default
435
+ collapseNav();
436
+ } else {
437
+ // On desktop, expand the nav by default
438
+ expandNav();
439
+ }
440
+ }
441
+ });
442
+
443
+ // Handle dropdown toggles
444
+ document.querySelectorAll('.nav-group-dropdown-btn').forEach(button => {
445
+ button.addEventListener('click', function(e) {
446
+ e.stopPropagation();
447
+ this.classList.toggle('open');
448
+ });
449
+ });
450
+
451
+ // Close dropdowns when clicking outside
452
+ document.addEventListener('click', function(e) {
453
+ if (!e.target.closest('.nav-group-dropdown')) {
454
+ document.querySelectorAll('.nav-group-dropdown-btn').forEach(button => {
455
+ button.classList.remove('open');
456
+ });
457
+ }
458
+ });
459
+ });
460
+ </script>
461
+ `;
462
+
463
+ return {
464
+ name: "navigation-injector",
465
+ transformIndexHtml: {
466
+ enforce: "pre",
467
+ transform(html: string, ctx: IndexHtmlTransformContext): string {
468
+ // Get the relative path from the root
469
+ const relativePath = ctx.filename
470
+ ? normalizePath(path.relative(process.cwd(), ctx.filename))
471
+ : "";
472
+
473
+ // Extract the page path relative to src or dist directory
474
+ let pagePath = "";
475
+ const srcDir = "src/";
476
+ const distDir = "dist/";
477
+
478
+ if (relativePath.includes(srcDir)) {
479
+ pagePath = relativePath.substring(
480
+ relativePath.indexOf(srcDir) + srcDir.length,
481
+ );
482
+ } else if (relativePath.includes(distDir)) {
483
+ pagePath = relativePath.substring(
484
+ relativePath.indexOf(distDir) + distDir.length,
485
+ );
486
+ }
487
+
488
+ console.log(`Processing file: ${relativePath}, pagePath: ${pagePath}`);
489
+
490
+ // Build navigation structure
491
+ const standardNav = buildCaptchaNavGroup(
492
+ "Standard Captchas",
493
+ pageDefinitions.standard,
494
+ pagePath,
495
+ );
496
+ const invisibleNav = buildCaptchaNavGroup(
497
+ "Invisible Captchas",
498
+ pageDefinitions.invisible,
499
+ pagePath,
500
+ );
501
+
502
+ const navHtml = `
503
+ <div id="nav-topbar" class="nav-topbar">
504
+ <div class="nav-container">
505
+ <div id="nav-header" class="nav-header">
506
+ <h1 class="nav-title">
507
+ <span class="nav-title-text">Procaptcha Demo Playground</span>
508
+ <span class="nav-title-hint">(Click anywhere to see more examples)</span>
509
+ </h1>
510
+ <button id="nav-toggle" class="nav-toggle" aria-label="Toggle navigation">
511
+ <span class="nav-toggle-icon">
512
+ <svg class="icon-collapse" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
513
+ <polyline points="18 15 12 9 6 15"></polyline>
514
+ </svg>
515
+ <svg class="icon-expand" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
516
+ <polyline points="6 9 12 15 18 9"></polyline>
517
+ </svg>
518
+ </span>
519
+ </button>
520
+ </div>
521
+ <div class="nav-content">
522
+ <div class="nav-sections">
523
+ ${standardNav}
524
+ ${invisibleNav}
525
+ </div>
526
+ </div>
527
+ </div>
528
+ </div>
529
+ `;
530
+
531
+ // Inject navigation after <body> tag and script before </body>
532
+ if (html.includes("<body>") && html.includes("</body>")) {
533
+ return html
534
+ .replace("</head>", `${navStyle}</head>`)
535
+ .replace("<body>", `<body>\n${navHtml}`)
536
+ .replace("</body>", `${navScript}\n</body>`);
537
+ }
538
+
539
+ return html;
540
+ },
541
+ },
542
+ };
543
+
544
+ // Helper function to build a navigation group for each captcha type
545
+ function buildCaptchaNavGroup(
546
+ title: string,
547
+ captchaTypes: CaptchaTypes,
548
+ currentPath: string,
549
+ ): string {
550
+ const navGroups: string[] = [];
551
+
552
+ for (const [typeName, captchaType] of Object.entries(captchaTypes)) {
553
+ const typeTitle = typeName.charAt(0).toUpperCase() + typeName.slice(1);
554
+ const links: string[] = [];
555
+
556
+ // Create simple buttons for each implementation
557
+ for (const [implName, implDetails] of Object.entries(
558
+ captchaType as CaptchaType,
559
+ )) {
560
+ const pagePath = implDetails.path;
561
+ const pageExists = implDetails.exists;
562
+ const implTitle = implName.charAt(0).toUpperCase() + implName.slice(1);
563
+
564
+ // Calculate relative path
565
+ let href: string;
566
+ if (currentPath.includes("/")) {
567
+ const depth = (currentPath.match(/\//g) || []).length;
568
+ href = "../".repeat(depth) + pagePath;
569
+ } else {
570
+ href = pagePath;
571
+ }
572
+
573
+ if (pageExists) {
574
+ const activeClass = currentPath === pagePath ? ' class="active"' : "";
575
+ links.push(`<a href="${href}"${activeClass}>${implTitle}</a>`);
576
+ } else {
577
+ links.push(
578
+ `<span class="disabled" title="Coming Soon">${implTitle}</span>`,
579
+ );
580
+ }
581
+ }
582
+
583
+ navGroups.push(`
584
+ <div class="nav-group">
585
+ <div class="nav-group-title">${typeTitle}</div>
586
+ <div class="nav-group-links">
587
+ ${links.join("\n ")}
588
+ </div>
589
+ </div>
590
+ `);
591
+ }
592
+
593
+ return `
594
+ <div class="nav-section">
595
+ <h3>${title}</h3>
596
+ <div class="nav-row">
597
+ ${navGroups.join("\n ")}
598
+ </div>
599
+ </div>
600
+ `;
601
+ }
602
+ }