Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Add i18n support

Blue Mouse9cc528de76d5
diff --git a/src/captcha-loader.ts b/src/captcha-loader.ts
index 49e43fd62..485220cc8 100644
--- a/src/captcha-loader.ts
+++ b/src/captcha-loader.ts
@@ -2,6 +2,9 @@
const isDevelopment = window.__SWETRIX_CAPTCHA_DEV || false
const CAPTCHA_SELECTOR = '.swecaptcha'
+const SUPPORTED_LOCALES = ['en', 'de', 'fr', 'pl', 'uk'] as const
+type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]
+const DEFAULT_LOCALE: SupportedLocale = 'en'
const LIGHT_CAPTCHA_IFRAME_URL = isDevelopment ? './light.html' : 'https://cdn.swetrixcaptcha.com/pages/light'
const DARK_CAPTCHA_IFRAME_URL = isDevelopment ? './dark.html' : 'https://cdn.swetrixcaptcha.com/pages/dark'
const DEFAULT_RESPONSE_INPUT_NAME = 'swetrix-captcha-response'
@@ -42,6 +45,70 @@ const detectPreferredTheme = (): 'light' | 'dark' => {
return 'light'
}
+const isSupportedLocale = (locale: string): locale is SupportedLocale => {
+ return SUPPORTED_LOCALES.includes(locale as SupportedLocale)
+}
+
+const normalizeLocale = (locale: string): SupportedLocale => {
+ const lowered = locale.toLowerCase()
+ const primary = lowered.split('-')[0].split('_')[0]
+
+ if (isSupportedLocale(primary)) {
+ return primary
+ }
+
+ return DEFAULT_LOCALE
+}
+
+const detectBrowserLocale = (): SupportedLocale => {
+ if (typeof navigator === 'undefined') {
+ return DEFAULT_LOCALE
+ }
+
+ const languages = navigator.languages || [navigator.language]
+
+ for (const lang of languages) {
+ const normalized = normalizeLocale(lang)
+ if (normalized !== DEFAULT_LOCALE || lang.toLowerCase().startsWith('en')) {
+ return normalized
+ }
+ }
+
+ return DEFAULT_LOCALE
+}
+
+const findHtmlLangAttribute = (element: Element): string | null => {
+ let current: Element | null = element
+
+ while (current) {
+ const lang = current.getAttribute('lang')
+ if (lang) {
+ return lang
+ }
+ current = current.parentElement
+ }
+
+ return null
+}
+
+const detectLanguage = (container: Element): SupportedLocale => {
+ // First priority: data-lang attribute on the widget element
+ const forcedLang = container.getAttribute('data-lang')
+ console.log('forcedLang', forcedLang)
+ if (forcedLang) {
+ return normalizeLocale(forcedLang)
+ }
+
+ // Second priority: lang attribute on ancestor elements (e.g., <html lang="de">)
+ const ancestorLang = findHtmlLangAttribute(container.parentElement as Element)
+ if (ancestorLang) {
+ return normalizeLocale(ancestorLang)
+ }
+
+ // Fallback: browser language
+ return detectBrowserLocale()
+}
+
const resolveTheme = (theme: string | null): 'light' | 'dark' => {
if (!theme || theme === 'auto') {
return detectPreferredTheme()
@@ -233,6 +300,7 @@ const parseParams = (container: Element): object => {
pid: container.getAttribute('data-project-id'),
respName: container.getAttribute('data-response-input-name') || DEFAULT_RESPONSE_INPUT_NAME,
theme: container.getAttribute('data-theme') || DEFAULT_THEME,
+ lang: detectLanguage(container),
}
// Optional custom API URL
diff --git a/src/captcha.ts b/src/captcha.ts
index 61f8b6985..2de986acb 100644
--- a/src/captcha.ts
+++ b/src/captcha.ts
@@ -1,3 +1,6 @@
+import { getTranslations, normalizeLocale, detectBrowserLocale, type SupportedLocale } from './i18n'
+import { logger } from './logger'
+
export {}
// @ts-ignore
@@ -51,7 +54,24 @@ interface PowProgress {
let activeAction: ACTION = ACTION.checkbox
let powWorker: Worker | null = null
-let progressStartTime: number = 0
+
+const getLocaleFromUrl = (): SupportedLocale => {
+ const urlParams = new URLSearchParams(window.location.search)
+ const lang = urlParams.get('lang')
+
+ logger.log('lang', lang)
+
+ if (lang) {
+ return normalizeLocale(lang)
+ }
+
+ return detectBrowserLocale()
+}
+
+const currentLocale = getLocaleFromUrl()
+const t = getTranslations(currentLocale)
+
+logger.log('t:', t)
const sendMessageToLoader = (event: IFRAME_MESSAGE_TYPES, data = {}) => {
window.parent.postMessage(
@@ -123,28 +143,25 @@ const updateAriaState = (action: ACTION) => {
captchaComponent.setAttribute('role', 'checkbox')
captchaComponent.setAttribute('aria-checked', 'false')
captchaComponent.setAttribute('aria-busy', 'false')
- captchaComponent.setAttribute(
- 'aria-label',
- 'Human verification checkbox. Press Enter or Space to verify you are human.',
- )
+ captchaComponent.setAttribute('aria-label', t.ariaCheckbox)
break
case ACTION.loading:
captchaComponent.setAttribute('role', 'status')
captchaComponent.setAttribute('aria-checked', 'mixed')
captchaComponent.setAttribute('aria-busy', 'true')
- captchaComponent.setAttribute('aria-label', 'Verifying that you are human. Please wait.')
+ captchaComponent.setAttribute('aria-label', t.ariaVerifying)
break
case ACTION.completed:
captchaComponent.setAttribute('role', 'checkbox')
captchaComponent.setAttribute('aria-checked', 'true')
captchaComponent.setAttribute('aria-busy', 'false')
- captchaComponent.setAttribute('aria-label', 'Verification successful. You have been verified as human.')
+ captchaComponent.setAttribute('aria-label', t.ariaSuccess)
break
case ACTION.failure:
captchaComponent.setAttribute('role', 'checkbox')
captchaComponent.setAttribute('aria-checked', 'false')
captchaComponent.setAttribute('aria-busy', 'false')
- captchaComponent.setAttribute('aria-label', 'Verification failed. Press Enter or Space to try again.')
+ captchaComponent.setAttribute('aria-label', t.ariaFailed)
break
}
@@ -153,13 +170,13 @@ const updateAriaState = (action: ACTION) => {
if (srStatus) {
switch (action) {
case ACTION.loading:
- srStatus.textContent = 'Verification in progress. Please wait.'
+ srStatus.textContent = t.srLoading
break
case ACTION.completed:
- srStatus.textContent = 'Verification successful!'
+ srStatus.textContent = t.srSuccess
break
case ACTION.failure:
- srStatus.textContent = 'Verification failed. Please try again.'
+ srStatus.textContent = t.srFailed
break
default:
srStatus.textContent = ''
@@ -208,7 +225,6 @@ const activateAction = (action: ACTION) => {
updateProgressBar(0) // Hide progress bar on failure
} else if (action === 'loading') {
statusComputing?.classList.remove('hidden')
- progressStartTime = Date.now()
updateProgressBar(-1) // Start with indeterminate progress
} else if (action === 'completed') {
statusDefault?.classList.remove('hidden')
@@ -255,7 +271,8 @@ const generateChallenge = async (): Promise<PowChallenge | null> => {
}
return await response.json()
- } catch (e) {
+ } catch (reason) {
+ logger.error('Failed to generate challenge:', reason)
sendMessageToLoader(IFRAME_MESSAGE_TYPES.FAILURE)
activateAction(ACTION.failure)
return null
@@ -289,7 +306,8 @@ const verifySolution = async (challenge: string, nonce: number, solution: string
}
return data.token
- } catch (e) {
+ } catch (reason) {
+ logger.error('Failed to verify solution:', reason)
sendMessageToLoader(IFRAME_MESSAGE_TYPES.FAILURE)
activateAction(ACTION.failure)
return null
@@ -325,7 +343,8 @@ const solveChallenge = async (challenge: PowChallenge): Promise<void> => {
try {
powWorker = new Worker(WORKER_URL)
- } catch (e) {
+ } catch (reason) {
+ logger.warn('Failed to create worker:', reason)
// Fallback: solve in main thread if worker fails
solveInMainThread(challenge).then(resolve).catch(reject)
return
@@ -348,7 +367,7 @@ const solveChallenge = async (challenge: PowChallenge): Promise<void> => {
if (data.type === 'timeout') {
// Worker timed out or hit max iterations
- console.error('PoW worker timeout:', (data as { type: 'timeout'; reason: string }).reason)
+ logger.error('PoW worker timeout:', (data as { type: 'timeout'; reason: string }).reason)
sendMessageToLoader(IFRAME_MESSAGE_TYPES.FAILURE)
activateAction(ACTION.failure)
powWorker?.terminate()
@@ -377,7 +396,7 @@ const solveChallenge = async (challenge: PowChallenge): Promise<void> => {
// Handle error message from worker
if (data.type === 'error') {
const errorData = data as { type: 'error'; message?: string }
- console.error('PoW worker error message:', errorData.message || 'Unknown error')
+ logger.error('PoW worker error message:', errorData.message || 'Unknown error')
sendMessageToLoader(IFRAME_MESSAGE_TYPES.FAILURE)
activateAction(ACTION.failure)
powWorker?.terminate()
@@ -387,7 +406,7 @@ const solveChallenge = async (challenge: PowChallenge): Promise<void> => {
}
// Fallback for unexpected message types
- console.warn('PoW worker received unexpected message type:', (data as { type?: unknown }).type, 'Raw data:', data)
+ logger.warn('PoW worker received unexpected message type:', (data as { type?: unknown }).type, 'Raw data:', data)
sendMessageToLoader(IFRAME_MESSAGE_TYPES.FAILURE)
activateAction(ACTION.failure)
powWorker?.terminate()
@@ -396,7 +415,7 @@ const solveChallenge = async (challenge: PowChallenge): Promise<void> => {
}
powWorker.onerror = (error) => {
- console.error('PoW worker error:', error)
+ logger.error('PoW worker error:', error)
powWorker?.terminate()
powWorker = null
@@ -438,7 +457,7 @@ const solveInMainThread = async (challenge: PowChallenge): Promise<void> => {
// Check overall timeout
const elapsedMs = Date.now() - startTime
if (elapsedMs >= TIMEOUT_MS) {
- console.error(`PoW main-thread timeout: ${TIMEOUT_MS}ms elapsed after ${nonce} attempts`)
+ logger.error(`PoW main-thread timeout: ${TIMEOUT_MS}ms elapsed after ${nonce} attempts`)
sendMessageToLoader(IFRAME_MESSAGE_TYPES.FAILURE)
activateAction(ACTION.failure)
return
@@ -469,7 +488,7 @@ const solveInMainThread = async (challenge: PowChallenge): Promise<void> => {
}
// Max iterations reached without finding solution
- console.error(`PoW main-thread max iterations reached: ${MAX_ITERATIONS} attempts`)
+ logger.error(`PoW main-thread max iterations reached: ${MAX_ITERATIONS} attempts`)
sendMessageToLoader(IFRAME_MESSAGE_TYPES.FAILURE)
activateAction(ACTION.failure)
}
@@ -498,10 +517,26 @@ const handleCaptchaActivation = async () => {
await solveChallenge(challenge)
}
+const applyTranslations = () => {
+ const statusDefault = document.querySelector('#status-default')
+ const statusFailure = document.querySelector('#status-failure')
+ const statusComputing = document.querySelector('#status-computing span')
+ const progressBarContainer = document.querySelector('#progress-bar-container')
+
+ if (statusDefault) statusDefault.textContent = t.iAmHuman
+ if (statusFailure) statusFailure.textContent = t.verificationFailed
+ if (statusComputing) statusComputing.textContent = t.verifying
+ if (progressBarContainer) progressBarContainer.setAttribute('aria-label', t.ariaProgress)
+
+ document.documentElement.lang = currentLocale
+}
+
document.addEventListener('DOMContentLoaded', () => {
const captchaComponent = document.querySelector('#swetrix-captcha')
const branding = document.querySelector('#branding')
+ applyTranslations()
+
branding?.addEventListener('click', (e: Event) => {
e.stopPropagation()
})
diff --git a/src/i18n.ts b/src/i18n.ts
new file mode 100644
index 000000000..b2da5dee4
--- /dev/null
+++ b/src/i18n.ts
@@ -0,0 +1,122 @@
+export const SUPPORTED_LOCALES = ['en', 'de', 'fr', 'pl', 'uk'] as const
+export type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]
+
+export const DEFAULT_LOCALE: SupportedLocale = 'en'
+
+interface Translations {
+ iAmHuman: string
+ verificationFailed: string
+ verifying: string
+ ariaCheckbox: string
+ ariaVerifying: string
+ ariaSuccess: string
+ ariaFailed: string
+ srLoading: string
+ srSuccess: string
+ srFailed: string
+ ariaProgress: string
+}
+
+export const translations: Record<SupportedLocale, Translations> = {
+ en: {
+ iAmHuman: 'I am human',
+ verificationFailed: 'Verification failed, click to retry',
+ verifying: 'Verifying...',
+ ariaCheckbox: 'Human verification checkbox. Press Enter or Space to verify you are human.',
+ ariaVerifying: 'Verifying that you are human. Please wait.',
+ ariaSuccess: 'Verification successful. You have been verified as human.',
+ ariaFailed: 'Verification failed. Press Enter or Space to try again.',
+ srLoading: 'Verification in progress. Please wait.',
+ srSuccess: 'Verification successful!',
+ srFailed: 'Verification failed. Please try again.',
+ ariaProgress: 'Verification progress',
+ },
+ de: {
+ iAmHuman: 'Ich bin ein Mensch',
+ verificationFailed: 'Verifizierung fehlgeschlagen, klicken Sie zum Wiederholen',
+ verifying: 'Verifizierung...',
+ ariaCheckbox: 'Kontrollkästchen zur menschlichen Verifizierung. Drücken Sie Enter oder Leertaste, um zu bestätigen, dass Sie ein Mensch sind.',
+ ariaVerifying: 'Verifizierung, dass Sie ein Mensch sind. Bitte warten.',
+ ariaSuccess: 'Verifizierung erfolgreich. Sie wurden als Mensch verifiziert.',
+ ariaFailed: 'Verifizierung fehlgeschlagen. Drücken Sie Enter oder Leertaste, um es erneut zu versuchen.',
+ srLoading: 'Verifizierung läuft. Bitte warten.',
+ srSuccess: 'Verifizierung erfolgreich!',
+ srFailed: 'Verifizierung fehlgeschlagen. Bitte versuchen Sie es erneut.',
+ ariaProgress: 'Verifizierungsfortschritt',
+ },
+ fr: {
+ iAmHuman: 'Je suis humain',
+ verificationFailed: 'Vérification échouée, cliquez pour réessayer',
+ verifying: 'Vérification...',
+ ariaCheckbox: 'Case de vérification humaine. Appuyez sur Entrée ou Espace pour confirmer que vous êtes humain.',
+ ariaVerifying: 'Vérification en cours. Veuillez patienter.',
+ ariaSuccess: 'Vérification réussie. Vous avez été vérifié comme humain.',
+ ariaFailed: 'Vérification échouée. Appuyez sur Entrée ou Espace pour réessayer.',
+ srLoading: 'Vérification en cours. Veuillez patienter.',
+ srSuccess: 'Vérification réussie !',
+ srFailed: 'Vérification échouée. Veuillez réessayer.',
+ ariaProgress: 'Progression de la vérification',
+ },
+ pl: {
+ iAmHuman: 'Jestem człowiekiem',
+ verificationFailed: 'Weryfikacja nie powiodła się, kliknij, aby spróbować ponownie',
+ verifying: 'Weryfikacja...',
+ ariaCheckbox: 'Pole wyboru weryfikacji człowieka. Naciśnij Enter lub Spację, aby potwierdzić, że jesteś człowiekiem.',
+ ariaVerifying: 'Trwa weryfikacja, że jesteś człowiekiem. Proszę czekać.',
+ ariaSuccess: 'Weryfikacja zakończona pomyślnie. Zostałeś zweryfikowany jako człowiek.',
+ ariaFailed: 'Weryfikacja nie powiodła się. Naciśnij Enter lub Spację, aby spróbować ponownie.',
+ srLoading: 'Weryfikacja w toku. Proszę czekać.',
+ srSuccess: 'Weryfikacja zakończona pomyślnie!',
+ srFailed: 'Weryfikacja nie powiodła się. Spróbuj ponownie.',
+ ariaProgress: 'Postęp weryfikacji',
+ },
+ uk: {
+ iAmHuman: 'Я людина',
+ verificationFailed: 'Перевірка не вдалася, натисніть, щоб спробувати знову',
+ verifying: 'Перевірка...',
+ ariaCheckbox: 'Прапорець перевірки людини. Натисніть Enter або Пробіл, щоб підтвердити, що ви людина.',
+ ariaVerifying: 'Перевіряємо, що ви людина. Будь ласка, зачекайте.',
+ ariaSuccess: 'Перевірка успішна. Вас підтверджено як людину.',
+ ariaFailed: 'Перевірка не вдалася. Натисніть Enter або Пробіл, щоб спробувати знову.',
+ srLoading: 'Перевірка триває. Будь ласка, зачекайте.',
+ srSuccess: 'Перевірка успішна!',
+ srFailed: 'Перевірка не вдалася. Будь ласка, спробуйте ще раз.',
+ ariaProgress: 'Прогрес перевірки',
+ },
+}
+
+export const isSupportedLocale = (locale: string): locale is SupportedLocale => {
+ return SUPPORTED_LOCALES.includes(locale as SupportedLocale)
+}
+
+export const normalizeLocale = (locale: string): SupportedLocale => {
+ const lowered = locale.toLowerCase()
+ const primary = lowered.split('-')[0].split('_')[0]
+
+ if (isSupportedLocale(primary)) {
+ return primary
+ }
+
+ return DEFAULT_LOCALE
+}
+
+export const detectBrowserLocale = (): SupportedLocale => {
+ if (typeof navigator === 'undefined') {
+ return DEFAULT_LOCALE
+ }
+
+ const languages = navigator.languages || [navigator.language]
+
+ for (const lang of languages) {
+ const normalized = normalizeLocale(lang)
+ if (normalized !== DEFAULT_LOCALE || lang.toLowerCase().startsWith('en')) {
+ return normalized
+ }
+ }
+
+ return DEFAULT_LOCALE
+}
+
+export const getTranslations = (locale: SupportedLocale) => {
+ return translations[locale] || translations[DEFAULT_LOCALE]
+}
diff --git a/src/pages/dark.html b/src/pages/dark.html
index 77b07f2cb..c6b38f0ec 100644
--- a/src/pages/dark.html
+++ b/src/pages/dark.html
@@ -1,421 +1,469 @@
-<!DOCTYPE html>
+<!doctype html>
<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <title>Swetrix Captcha</title>
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+
+ <style>
+ html {
+ font-family:
+ "-apple-system", "system-ui", "BlinkMacSystemFont", "Inter", "Cantarell",
+ "Helvetica Neue", "Roboto", "Oxygen", "Ubuntu", sans-serif;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+ }
-<head>
- <meta charset="utf-8">
- <title>Swetrix Captcha</title>
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1">
-
- <style>
- html {
- font-family: '-apple-system', 'system-ui', 'BlinkMacSystemFont', 'Inter', 'Cantarell', 'Helvetica Neue', 'Roboto', 'Oxygen', 'Ubuntu', sans-serif;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
- }
-
- body {
- margin: 0;
- padding: 0;
- height: auto;
- overflow: auto;
- }
-
- #swetrix-captcha {
- display: flex;
- justify-content: center;
- align-items: center;
- position: relative;
-
- /* 300 - 20px (padding) */
- width: 280px;
-
- background-color: #0f172a;
- border: 1px solid #1e293b;
- border-radius: 4px;
- height: 64px;
- -webkit-user-select: none;
- user-select: none;
- padding-left: 10px;
- padding-right: 10px;
-
- cursor: pointer;
- }
-
- #swetrix-captcha:hover {
- background-color: #1e293b;
- }
-
- /* Focus styles for accessibility - only show on keyboard navigation */
- #swetrix-captcha:focus {
- outline: none;
- }
-
- #swetrix-captcha:focus-visible {
- outline: 2px solid #60a5fa;
- outline-offset: 2px;
- }
-
- /* Fallback for browsers without :focus-visible support */
- #swetrix-captcha.keyboard-focus {
- outline: 2px solid #60a5fa;
- outline-offset: 2px;
- }
-
- /* Progress bar at the top */
- #progress-bar-container {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- height: 2px;
- background-color: #1e293b;
- border-radius: 4px 4px 0 0;
- overflow: hidden;
- opacity: 0;
- transition: opacity 0.3s ease;
- }
-
- #progress-bar-container.show {
- opacity: 1;
- }
-
- #progress-bar {
- height: 100%;
- width: 0%;
- background: linear-gradient(90deg, #3b82f6, #60a5fa);
- transition: width 0.3s ease, opacity 0.3s ease;
- }
-
- #progress-bar.indeterminate {
- width: 30%;
- animation: indeterminate 1.5s ease-in-out infinite;
- }
-
- @keyframes indeterminate {
- 0% {
- transform: translateX(-100%);
- }
- 100% {
- transform: translateX(400%);
- }
- }
-
- #challenge {
- display: flex;
- align-items: center;
- cursor: pointer;
- flex: 1;
- }
-
- #action {
- margin-right: 10px;
- position: relative;
- width: 28px;
- height: 28px;
- }
-
- #checkbox {
- background-color: #111827;
- border: 1px solid #374151;
- height: 25px;
- width: 25px;
- border-radius: 3px;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- transition: opacity 0.25s ease, transform 0.25s ease, border-color 0.2s ease, box-shadow 0.2s ease;
- }
-
- #checkbox:hover {
- border-color: #4b5563;
- }
-
- /* Focus indicator for checkbox when parent is focused */
- #swetrix-captcha:focus-visible #checkbox {
- border-color: #60a5fa;
- box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.3);
- }
-
- #status {
- font-size: 14px;
- color: #f9fafb;
- }
-
- #status span {
- transition: opacity 0.2s ease;
- }
-
- #status-computing {
- display: flex;
- flex-direction: column;
- }
-
- .hidden {
- display: none !important;
- }
-
- /* Fade out animation for hiding elements */
- .fade-out {
- opacity: 0 !important;
- transform: translate(-50%, -50%) scale(0.8) !important;
- pointer-events: none;
- }
-
- /* Fade in animation for showing elements */
- .fade-in {
- opacity: 1;
- transform: translate(-50%, -50%) scale(1);
- }
-
- #branding {
- position: absolute;
- bottom: 4px;
- right: 10px;
- }
-
- #branding a {
- font-size: 9px;
- color: #6b7280;
- text-decoration: none;
- transition: color 0.2s ease;
- }
-
- #branding a:hover {
- color: #9ca3af;
- text-decoration: underline;
- }
-
- #branding a:focus-visible {
- outline: 1px solid #60a5fa;
- outline-offset: 1px;
- }
-
- #action svg {
- width: 28px;
- height: 28px;
- }
-
- #failure > svg {
- /* bg-red-500 */
- color: #d6292a;
- }
-
- #completed > svg {
- /* bg-green-600 */
- color: #16a24c;
- }
-
- #completed,
- #failure {
- display: flex;
- align-items: center;
- justify-content: center;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%) scale(0.8);
- opacity: 0;
- transition: opacity 0.3s ease, transform 0.3s ease;
- }
-
- #completed.show,
- #failure.show {
- opacity: 1;
- transform: translate(-50%, -50%) scale(1);
- }
-
- /* Checkmark draw animation */
- #completed.show svg path {
- stroke-dasharray: 24;
- stroke-dashoffset: 24;
- animation: drawCheck 0.4s ease forwards 0.1s;
- }
-
- @keyframes drawCheck {
- to {
- stroke-dashoffset: 0;
- }
- }
-
- /* Failure shake animation */
- #failure.show {
- animation: shake 0.4s ease;
- }
-
- @keyframes shake {
- 0%, 100% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
- 25% { transform: translate(-50%, -50%) scale(1) rotate(-5deg); }
- 75% { transform: translate(-50%, -50%) scale(1) rotate(5deg); }
- }
-
- /* Loading indicator - Material Design style spinner */
- #loading {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- width: 24px;
- height: 24px;
- opacity: 0;
- transition: opacity 0.25s ease;
- }
-
- #loading.show {
- opacity: 1;
- }
-
- #loading svg {
- width: 24px;
- height: 24px;
- animation: rotate 1.4s linear infinite;
- }
-
- #loading svg circle {
- stroke: #60a5fa;
- stroke-linecap: round;
- animation: dash 1.4s ease-in-out infinite;
- }
-
- @keyframes rotate {
- 100% {
- transform: rotate(360deg);
- }
- }
-
- @keyframes dash {
- 0% {
- stroke-dasharray: 1, 150;
- stroke-dashoffset: 0;
- }
- 50% {
- stroke-dasharray: 90, 150;
- stroke-dashoffset: -35;
- }
- 100% {
- stroke-dasharray: 90, 150;
- stroke-dashoffset: -124;
- }
- }
-
- /* Reduced motion preference */
- @media (prefers-reduced-motion: reduce) {
- #checkbox,
- #completed,
- #failure,
- #loading,
- #status span,
- #progress-bar,
- #branding a {
- transition: none;
+ body {
+ margin: 0;
+ padding: 0;
+ height: auto;
+ overflow: auto;
}
- #loading svg,
- #loading svg circle,
- #completed.show svg path,
- #failure.show,
- #progress-bar.indeterminate {
- animation: none;
+ #swetrix-captcha {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ position: relative;
+
+ /* 300 - 20px (padding) */
+ width: 280px;
+
+ background-color: #0f172a;
+ border: 1px solid #1e293b;
+ border-radius: 4px;
+ height: 64px;
+ -webkit-user-select: none;
+ user-select: none;
+ padding-left: 10px;
+ padding-right: 10px;
+
+ cursor: pointer;
+ }
+
+ #swetrix-captcha:hover {
+ background-color: #1e293b;
+ }
+
+ /* Focus styles for accessibility - only show on keyboard navigation */
+ #swetrix-captcha:focus {
+ outline: none;
+ }
+
+ #swetrix-captcha:focus-visible {
+ outline: 2px solid #60a5fa;
+ outline-offset: 2px;
+ }
+
+ /* Fallback for browsers without :focus-visible support */
+ #swetrix-captcha.keyboard-focus {
+ outline: 2px solid #60a5fa;
+ outline-offset: 2px;
+ }
+
+ /* Progress bar at the top */
+ #progress-bar-container {
+ position: absolute;
+ top: 0;
+ left: 0;
+ right: 0;
+ height: 2px;
+ background-color: #1e293b;
+ border-radius: 4px 4px 0 0;
+ overflow: hidden;
+ opacity: 0;
+ transition: opacity 0.3s ease;
+ }
+
+ #progress-bar-container.show {
+ opacity: 1;
+ }
+
+ #progress-bar {
+ height: 100%;
+ width: 0%;
+ background: linear-gradient(90deg, #3b82f6, #60a5fa);
+ transition:
+ width 0.3s ease,
+ opacity 0.3s ease;
}
#progress-bar.indeterminate {
- width: 100%;
+ width: 30%;
+ animation: indeterminate 1.5s ease-in-out infinite;
}
- /* Show static loading circle when animations are disabled */
- #loading svg circle {
- stroke-dasharray: 90, 150;
- stroke-dashoffset: 0;
+ @keyframes indeterminate {
+ 0% {
+ transform: translateX(-100%);
+ }
+ 100% {
+ transform: translateX(400%);
+ }
}
- /* Show checkmark immediately when animations are disabled */
- #completed.show svg path {
- stroke-dashoffset: 0;
+ #challenge {
+ display: flex;
+ align-items: center;
+ cursor: pointer;
+ flex: 1;
}
- }
- /* High contrast mode support */
- @media (forced-colors: active) {
- #swetrix-captcha {
- border: 2px solid CanvasText;
+ #action {
+ margin-right: 10px;
+ position: relative;
+ width: 28px;
+ height: 28px;
}
#checkbox {
- border: 2px solid CanvasText;
+ background-color: #111827;
+ border: 1px solid #374151;
+ height: 25px;
+ width: 25px;
+ border-radius: 3px;
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ transition:
+ opacity 0.25s ease,
+ transform 0.25s ease,
+ border-color 0.2s ease,
+ box-shadow 0.2s ease;
}
- #progress-bar {
- background: Highlight;
- }
- }
- </style>
- <script>
- window.__SWETRIX_CAPTCHA_THEME = 'dark'
- const urlParams = new URLSearchParams(window.location.search)
- const pid = urlParams.get('pid')
- const cid = urlParams.get('cid')
- const apiUrl = urlParams.get('apiUrl')
-
- window.__SWETRIX_CAPTCHA_ID = cid
- window.__SWETRIX_PROJECT_ID = pid
- if (apiUrl) {
- window.__SWETRIX_API_URL = apiUrl
- }
- </script>
- <script src="../captcha.js" defer></script>
-</head>
-
-<body>
- <div
- id="swetrix-captcha"
- role="checkbox"
- aria-checked="false"
- aria-label="Human verification checkbox. Press Enter or Space to verify you are human."
- tabindex="0"
- >
- <!-- Progress bar at the top -->
- <div id="progress-bar-container" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" aria-label="Verification progress">
- <div id="progress-bar"></div>
- </div>
-
- <div id="challenge">
- <div id="action">
- <!-- Can contain a checkbox itself / a red cross (with a retry action) / a green check mark -->
- <div id="checkbox" aria-hidden="true"></div>
- <div id="failure" aria-hidden="true">
- <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
- <path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/>
- <path d="M12 9v4"/>
- <path d="M12 17h.01"/>
- </svg>
- </div>
- <div id="completed" aria-hidden="true">
- <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
- <path d="M20 6 9 17l-5-5"/>
- </svg>
+ #checkbox:hover {
+ border-color: #4b5563;
+ }
+
+ /* Focus indicator for checkbox when parent is focused */
+ #swetrix-captcha:focus-visible #checkbox {
+ border-color: #60a5fa;
+ box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.3);
+ }
+
+ #status {
+ font-size: 14px;
+ color: #f9fafb;
+ }
+
+ #status span {
+ transition: opacity 0.2s ease;
+ }
+
+ #status-computing {
+ display: flex;
+ flex-direction: column;
+ }
+
+ .hidden {
+ display: none !important;
+ }
+
+ /* Fade out animation for hiding elements */
+ .fade-out {
+ opacity: 0 !important;
+ transform: translate(-50%, -50%) scale(0.8) !important;
+ pointer-events: none;
+ }
+
+ /* Fade in animation for showing elements */
+ .fade-in {
+ opacity: 1;
+ transform: translate(-50%, -50%) scale(1);
+ }
+
+ #branding {
+ position: absolute;
+ bottom: 4px;
+ right: 10px;
+ }
+
+ #branding a {
+ font-size: 9px;
+ color: #6b7280;
+ text-decoration: none;
+ transition: color 0.2s ease;
+ }
+
+ #branding a:hover {
+ color: #9ca3af;
+ text-decoration: underline;
+ }
+
+ #branding a:focus-visible {
+ outline: 1px solid #60a5fa;
+ outline-offset: 1px;
+ }
+
+ #action svg {
+ width: 28px;
+ height: 28px;
+ }
+
+ #failure > svg {
+ /* bg-red-500 */
+ color: #d6292a;
+ }
+
+ #completed > svg {
+ /* bg-green-600 */
+ color: #16a24c;
+ }
+
+ #completed,
+ #failure {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%) scale(0.8);
+ opacity: 0;
+ transition:
+ opacity 0.3s ease,
+ transform 0.3s ease;
+ }
+
+ #completed.show,
+ #failure.show {
+ opacity: 1;
+ transform: translate(-50%, -50%) scale(1);
+ }
+
+ /* Checkmark draw animation */
+ #completed.show svg path {
+ stroke-dasharray: 24;
+ stroke-dashoffset: 24;
+ animation: drawCheck 0.4s ease forwards 0.1s;
+ }
+
+ @keyframes drawCheck {
+ to {
+ stroke-dashoffset: 0;
+ }
+ }
+
+ /* Failure shake animation */
+ #failure.show {
+ animation: shake 0.4s ease;
+ }
+
+ @keyframes shake {
+ 0%,
+ 100% {
+ transform: translate(-50%, -50%) scale(1) rotate(0deg);
+ }
+ 25% {
+ transform: translate(-50%, -50%) scale(1) rotate(-5deg);
+ }
+ 75% {
+ transform: translate(-50%, -50%) scale(1) rotate(5deg);
+ }
+ }
+
+ /* Loading indicator - Material Design style spinner */
+ #loading {
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ width: 24px;
+ height: 24px;
+ opacity: 0;
+ transition: opacity 0.25s ease;
+ }
+
+ #loading.show {
+ opacity: 1;
+ }
+
+ #loading svg {
+ width: 24px;
+ height: 24px;
+ animation: rotate 1.4s linear infinite;
+ }
+
+ #loading svg circle {
+ stroke: #60a5fa;
+ stroke-linecap: round;
+ animation: dash 1.4s ease-in-out infinite;
+ }
+
+ @keyframes rotate {
+ 100% {
+ transform: rotate(360deg);
+ }
+ }
+
+ @keyframes dash {
+ 0% {
+ stroke-dasharray: 1, 150;
+ stroke-dashoffset: 0;
+ }
+ 50% {
+ stroke-dasharray: 90, 150;
+ stroke-dashoffset: -35;
+ }
+ 100% {
+ stroke-dasharray: 90, 150;
+ stroke-dashoffset: -124;
+ }
+ }
+
+ /* Reduced motion preference */
+ @media (prefers-reduced-motion: reduce) {
+ #checkbox,
+ #completed,
+ #failure,
+ #loading,
+ #status span,
+ #progress-bar,
+ #branding a {
+ transition: none;
+ }
+
+ #loading svg,
+ #loading svg circle,
+ #completed.show svg path,
+ #failure.show,
+ #progress-bar.indeterminate {
+ animation: none;
+ }
+
+ #progress-bar.indeterminate {
+ width: 100%;
+ }
+
+ /* Show static loading circle when animations are disabled */
+ #loading svg circle {
+ stroke-dasharray: 90, 150;
+ stroke-dashoffset: 0;
+ }
+
+ /* Show checkmark immediately when animations are disabled */
+ #completed.show svg path {
+ stroke-dashoffset: 0;
+ }
+ }
+
+ /* High contrast mode support */
+ @media (forced-colors: active) {
+ #swetrix-captcha {
+ border: 2px solid CanvasText;
+ }
+
+ #checkbox {
+ border: 2px solid CanvasText;
+ }
+
+ #progress-bar {
+ background: Highlight;
+ }
+ }
+ </style>
+ <script>
+ window.__SWETRIX_CAPTCHA_THEME = "dark";
+ const urlParams = new URLSearchParams(window.location.search);
+ const pid = urlParams.get("pid");
+ const cid = urlParams.get("cid");
+ const apiUrl = urlParams.get("apiUrl");
+ const lang = urlParams.get("lang");
+
+ window.__SWETRIX_CAPTCHA_ID = cid;
+ window.__SWETRIX_PROJECT_ID = pid;
+ if (apiUrl) {
+ window.__SWETRIX_API_URL = apiUrl;
+ }
+ if (lang) {
+ document.documentElement.lang = lang;
+ }
+ </script>
+ <script src="../captcha.js" defer></script>
+ </head>
+
+ <body>
+ <div
+ id="swetrix-captcha"
+ role="checkbox"
+ aria-checked="false"
+ aria-label="Human verification checkbox. Press Enter or Space to verify you are human."
+ tabindex="0"
+ >
+ <!-- Progress bar at the top -->
+ <div
+ id="progress-bar-container"
+ role="progressbar"
+ aria-valuemin="0"
+ aria-valuemax="100"
+ aria-valuenow="0"
+ aria-label="Verification progress"
+ >
+ <div id="progress-bar"></div>
+ </div>
+
+ <div id="challenge">
+ <div id="action">
+ <!-- Can contain a checkbox itself / a red cross (with a retry action) / a green check mark -->
+ <div id="checkbox" aria-hidden="true"></div>
+ <div id="failure" aria-hidden="true">
+ <svg
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ aria-hidden="true"
+ >
+ <path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" />
+ <path d="M12 9v4" />
+ <path d="M12 17h.01" />
+ </svg>
+ </div>
+ <div id="completed" aria-hidden="true">
+ <svg
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ aria-hidden="true"
+ >
+ <path d="M20 6 9 17l-5-5" />
+ </svg>
+ </div>
+ <div id="loading" aria-hidden="true">
+ <svg viewBox="0 0 50 50" aria-hidden="true">
+ <circle cx="25" cy="25" r="20" fill="none" stroke-width="4"></circle>
+ </svg>
+ </div>
</div>
- <div id="loading" aria-hidden="true">
- <svg viewBox="0 0 50 50" aria-hidden="true">
- <circle cx="25" cy="25" r="20" fill="none" stroke-width="4"></circle>
- </svg>
+ <div id="status" aria-live="polite" aria-atomic="true">
+ <span id="status-default">I am human</span>
+ <span id="status-failure" class="hidden">Verification failed, click to retry</span>
+ <span id="status-computing" class="hidden">
+ <span>Verifying...</span>
+ </span>
</div>
</div>
- <div id="status" aria-live="polite" aria-atomic="true">
- <span id="status-default">I am human</span>
- <span id="status-failure" class="hidden">Verification failed, click to retry</span>
- <span id="status-computing" class="hidden">
- <span>Verifying...</span>
- </span>
+ <div id="branding">
+ <a
+ href="https://swetrix.com/captcha"
+ target="_blank"
+ rel="noopener noreferrer"
+ aria-label="Swetrix Captcha - opens in new window"
+ >Swetrix Captcha</a
+ >
</div>
- </div>
- <div id="branding">
- <a href="https://swetrix.com/captcha" target="_blank" rel="noopener noreferrer" aria-label="Swetrix Captcha - opens in new window">Swetrix Captcha</a>
- </div>
-
- <!-- Screen reader only live region for status updates -->
- <div id="sr-status" class="hidden" aria-live="assertive" aria-atomic="true"></div>
- </div>
-</body>
+ <!-- Screen reader only live region for status updates -->
+ <div id="sr-status" class="hidden" aria-live="assertive" aria-atomic="true"></div>
+ </div>
+ </body>
</html>
diff --git a/src/pages/light.html b/src/pages/light.html
index 17e3f7791..03892bb90 100644
--- a/src/pages/light.html
+++ b/src/pages/light.html
@@ -1,423 +1,471 @@
-<!DOCTYPE html>
+<!doctype html>
<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <title>Swetrix Captcha</title>
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+
+ <style>
+ html {
+ font-family:
+ "-apple-system", "system-ui", "BlinkMacSystemFont", "Inter", "Cantarell",
+ "Helvetica Neue", "Roboto", "Oxygen", "Ubuntu", sans-serif;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+ }
-<head>
- <meta charset="utf-8">
- <title>Swetrix Captcha</title>
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1">
-
- <style>
- html {
- font-family: '-apple-system', 'system-ui', 'BlinkMacSystemFont', 'Inter', 'Cantarell', 'Helvetica Neue', 'Roboto', 'Oxygen', 'Ubuntu', sans-serif;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
- }
-
- body {
- margin: 0;
- padding: 0;
- height: auto;
- overflow: auto;
- }
-
- #swetrix-captcha {
- display: flex;
- justify-content: center;
- align-items: center;
- position: relative;
-
- /* 300 - 20px (padding) */
- width: 280px;
-
- /* bg-gray-100 */
- background-color: #f9fafb;
- border: 1px solid #e9e9e9;
- border-radius: 4px;
- height: 64px;
- -webkit-user-select: none;
- user-select: none;
- padding-left: 10px;
- padding-right: 10px;
-
- cursor: pointer;
- }
-
- #swetrix-captcha:hover {
- /* bg-gray-200 */
- background-color: #f3f4f6;
- }
-
- /* Focus styles for accessibility - only show on keyboard navigation */
- #swetrix-captcha:focus {
- outline: none;
- }
-
- #swetrix-captcha:focus-visible {
- outline: 2px solid #3b82f6;
- outline-offset: 2px;
- }
-
- /* Fallback for browsers without :focus-visible support */
- #swetrix-captcha.keyboard-focus {
- outline: 2px solid #3b82f6;
- outline-offset: 2px;
- }
-
- /* Progress bar at the top */
- #progress-bar-container {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- height: 2px;
- background-color: #e5e7eb;
- border-radius: 4px 4px 0 0;
- overflow: hidden;
- opacity: 0;
- transition: opacity 0.3s ease;
- }
-
- #progress-bar-container.show {
- opacity: 1;
- }
-
- #progress-bar {
- height: 100%;
- width: 0%;
- background: linear-gradient(90deg, #3b82f6, #2563eb);
- transition: width 0.3s ease, opacity 0.3s ease;
- }
-
- #progress-bar.indeterminate {
- width: 30%;
- animation: indeterminate 1.5s ease-in-out infinite;
- }
-
- @keyframes indeterminate {
- 0% {
- transform: translateX(-100%);
- }
- 100% {
- transform: translateX(400%);
- }
- }
-
- #challenge {
- display: flex;
- align-items: center;
- cursor: pointer;
- flex: 1;
- }
-
- #action {
- margin-right: 10px;
- position: relative;
- width: 28px;
- height: 28px;
- }
-
- #checkbox {
- background-color: #fff;
- border: 1px solid #c4c4c4;
- height: 25px;
- width: 25px;
- border-radius: 3px;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- transition: opacity 0.25s ease, transform 0.25s ease, border-color 0.2s ease, box-shadow 0.2s ease;
- }
-
- #checkbox:hover {
- border-color: #a0a0a0;
- }
-
- /* Focus indicator for checkbox when parent is focused */
- #swetrix-captcha:focus-visible #checkbox {
- border-color: #3b82f6;
- box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
- }
-
- #status {
- font-size: 14px;
- color: #0f0f0f;
- }
-
- #status span {
- transition: opacity 0.2s ease;
- }
-
- #status-computing {
- display: flex;
- flex-direction: column;
- }
-
- .hidden {
- display: none !important;
- }
-
- /* Fade out animation for hiding elements */
- .fade-out {
- opacity: 0 !important;
- transform: translate(-50%, -50%) scale(0.8) !important;
- pointer-events: none;
- }
-
- /* Fade in animation for showing elements */
- .fade-in {
- opacity: 1;
- transform: translate(-50%, -50%) scale(1);
- }
-
- #branding {
- position: absolute;
- bottom: 4px;
- right: 10px;
- }
-
- #branding a {
- font-size: 9px;
- color: #6b7280;
- text-decoration: none;
- transition: color 0.2s ease;
- }
-
- #branding a:hover {
- color: #374151;
- text-decoration: underline;
- }
-
- #branding a:focus-visible {
- outline: 1px solid #3b82f6;
- outline-offset: 1px;
- }
-
- #action svg {
- width: 28px;
- height: 28px;
- }
-
- #failure > svg {
- /* bg-red-500 */
- color: #d6292a;
- }
-
- #completed > svg {
- /* bg-green-600 */
- color: #16a24c;
- }
-
- #completed,
- #failure {
- display: flex;
- align-items: center;
- justify-content: center;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%) scale(0.8);
- opacity: 0;
- transition: opacity 0.3s ease, transform 0.3s ease;
- }
-
- #completed.show,
- #failure.show {
- opacity: 1;
- transform: translate(-50%, -50%) scale(1);
- }
-
- /* Checkmark draw animation */
- #completed.show svg path {
- stroke-dasharray: 24;
- stroke-dashoffset: 24;
- animation: drawCheck 0.4s ease forwards 0.1s;
- }
-
- @keyframes drawCheck {
- to {
- stroke-dashoffset: 0;
- }
- }
-
- /* Failure shake animation */
- #failure.show {
- animation: shake 0.4s ease;
- }
-
- @keyframes shake {
- 0%, 100% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
- 25% { transform: translate(-50%, -50%) scale(1) rotate(-5deg); }
- 75% { transform: translate(-50%, -50%) scale(1) rotate(5deg); }
- }
-
- /* Loading indicator - Material Design style spinner */
- #loading {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- width: 24px;
- height: 24px;
- opacity: 0;
- transition: opacity 0.25s ease;
- }
-
- #loading.show {
- opacity: 1;
- }
-
- #loading svg {
- width: 24px;
- height: 24px;
- animation: rotate 1.4s linear infinite;
- }
-
- #loading svg circle {
- stroke: #3b82f6;
- stroke-linecap: round;
- animation: dash 1.4s ease-in-out infinite;
- }
-
- @keyframes rotate {
- 100% {
- transform: rotate(360deg);
- }
- }
-
- @keyframes dash {
- 0% {
- stroke-dasharray: 1, 150;
- stroke-dashoffset: 0;
- }
- 50% {
- stroke-dasharray: 90, 150;
- stroke-dashoffset: -35;
- }
- 100% {
- stroke-dasharray: 90, 150;
- stroke-dashoffset: -124;
- }
- }
-
- /* Reduced motion preference */
- @media (prefers-reduced-motion: reduce) {
- #checkbox,
- #completed,
- #failure,
- #loading,
- #status span,
- #progress-bar,
- #branding a {
- transition: none;
+ body {
+ margin: 0;
+ padding: 0;
+ height: auto;
+ overflow: auto;
}
- #loading svg,
- #loading svg circle,
- #completed.show svg path,
- #failure.show,
- #progress-bar.indeterminate {
- animation: none;
+ #swetrix-captcha {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ position: relative;
+
+ /* 300 - 20px (padding) */
+ width: 280px;
+
+ /* bg-gray-100 */
+ background-color: #f9fafb;
+ border: 1px solid #e9e9e9;
+ border-radius: 4px;
+ height: 64px;
+ -webkit-user-select: none;
+ user-select: none;
+ padding-left: 10px;
+ padding-right: 10px;
+
+ cursor: pointer;
+ }
+
+ #swetrix-captcha:hover {
+ /* bg-gray-200 */
+ background-color: #f3f4f6;
+ }
+
+ /* Focus styles for accessibility - only show on keyboard navigation */
+ #swetrix-captcha:focus {
+ outline: none;
+ }
+
+ #swetrix-captcha:focus-visible {
+ outline: 2px solid #3b82f6;
+ outline-offset: 2px;
+ }
+
+ /* Fallback for browsers without :focus-visible support */
+ #swetrix-captcha.keyboard-focus {
+ outline: 2px solid #3b82f6;
+ outline-offset: 2px;
+ }
+
+ /* Progress bar at the top */
+ #progress-bar-container {
+ position: absolute;
+ top: 0;
+ left: 0;
+ right: 0;
+ height: 2px;
+ background-color: #e5e7eb;
+ border-radius: 4px 4px 0 0;
+ overflow: hidden;
+ opacity: 0;
+ transition: opacity 0.3s ease;
+ }
+
+ #progress-bar-container.show {
+ opacity: 1;
+ }
+
+ #progress-bar {
+ height: 100%;
+ width: 0%;
+ background: linear-gradient(90deg, #3b82f6, #2563eb);
+ transition:
+ width 0.3s ease,
+ opacity 0.3s ease;
}
#progress-bar.indeterminate {
- width: 100%;
+ width: 30%;
+ animation: indeterminate 1.5s ease-in-out infinite;
}
- /* Show static loading circle when animations are disabled */
- #loading svg circle {
- stroke-dasharray: 90, 150;
- stroke-dashoffset: 0;
+ @keyframes indeterminate {
+ 0% {
+ transform: translateX(-100%);
+ }
+ 100% {
+ transform: translateX(400%);
+ }
}
- /* Show checkmark immediately when animations are disabled */
- #completed.show svg path {
- stroke-dashoffset: 0;
+ #challenge {
+ display: flex;
+ align-items: center;
+ cursor: pointer;
+ flex: 1;
}
- }
- /* High contrast mode support */
- @media (forced-colors: active) {
- #swetrix-captcha {
- border: 2px solid CanvasText;
+ #action {
+ margin-right: 10px;
+ position: relative;
+ width: 28px;
+ height: 28px;
}
#checkbox {
- border: 2px solid CanvasText;
+ background-color: #fff;
+ border: 1px solid #c4c4c4;
+ height: 25px;
+ width: 25px;
+ border-radius: 3px;
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ transition:
+ opacity 0.25s ease,
+ transform 0.25s ease,
+ border-color 0.2s ease,
+ box-shadow 0.2s ease;
}
- #progress-bar {
- background: Highlight;
- }
- }
- </style>
- <script>
- window.__SWETRIX_CAPTCHA_THEME = 'light'
- const urlParams = new URLSearchParams(window.location.search)
- const pid = urlParams.get('pid')
- const cid = urlParams.get('cid')
- const apiUrl = urlParams.get('apiUrl')
-
- window.__SWETRIX_CAPTCHA_ID = cid
- window.__SWETRIX_PROJECT_ID = pid
- if (apiUrl) {
- window.__SWETRIX_API_URL = apiUrl
- }
- </script>
- <script src="../captcha.js" defer></script>
-</head>
-
-<body>
- <div
- id="swetrix-captcha"
- role="checkbox"
- aria-checked="false"
- aria-label="Human verification checkbox. Press Enter or Space to verify you are human."
- tabindex="0"
- >
- <!-- Progress bar at the top -->
- <div id="progress-bar-container" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" aria-label="Verification progress">
- <div id="progress-bar"></div>
- </div>
-
- <div id="challenge">
- <div id="action">
- <!-- Can contain a checkbox itself / a red cross (with a retry action) / a green check mark -->
- <div id="checkbox" aria-hidden="true"></div>
- <div id="failure" aria-hidden="true">
- <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
- <path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/>
- <path d="M12 9v4"/>
- <path d="M12 17h.01"/>
- </svg>
- </div>
- <div id="completed" aria-hidden="true">
- <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
- <path d="M20 6 9 17l-5-5"/>
- </svg>
+ #checkbox:hover {
+ border-color: #a0a0a0;
+ }
+
+ /* Focus indicator for checkbox when parent is focused */
+ #swetrix-captcha:focus-visible #checkbox {
+ border-color: #3b82f6;
+ box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
+ }
+
+ #status {
+ font-size: 14px;
+ color: #0f0f0f;
+ }
+
+ #status span {
+ transition: opacity 0.2s ease;
+ }
+
+ #status-computing {
+ display: flex;
+ flex-direction: column;
+ }
+
+ .hidden {
+ display: none !important;
+ }
+
+ /* Fade out animation for hiding elements */
+ .fade-out {
+ opacity: 0 !important;
+ transform: translate(-50%, -50%) scale(0.8) !important;
+ pointer-events: none;
+ }
+
+ /* Fade in animation for showing elements */
+ .fade-in {
+ opacity: 1;
+ transform: translate(-50%, -50%) scale(1);
+ }
+
+ #branding {
+ position: absolute;
+ bottom: 4px;
+ right: 10px;
+ }
+
+ #branding a {
+ font-size: 9px;
+ color: #6b7280;
+ text-decoration: none;
+ transition: color 0.2s ease;
+ }
+
+ #branding a:hover {
+ color: #374151;
+ text-decoration: underline;
+ }
+
+ #branding a:focus-visible {
+ outline: 1px solid #3b82f6;
+ outline-offset: 1px;
+ }
+
+ #action svg {
+ width: 28px;
+ height: 28px;
+ }
+
+ #failure > svg {
+ /* bg-red-500 */
+ color: #d6292a;
+ }
+
+ #completed > svg {
+ /* bg-green-600 */
+ color: #16a24c;
+ }
+
+ #completed,
+ #failure {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%) scale(0.8);
+ opacity: 0;
+ transition:
+ opacity 0.3s ease,
+ transform 0.3s ease;
+ }
+
+ #completed.show,
+ #failure.show {
+ opacity: 1;
+ transform: translate(-50%, -50%) scale(1);
+ }
+
+ /* Checkmark draw animation */
+ #completed.show svg path {
+ stroke-dasharray: 24;
+ stroke-dashoffset: 24;
+ animation: drawCheck 0.4s ease forwards 0.1s;
+ }
+
+ @keyframes drawCheck {
+ to {
+ stroke-dashoffset: 0;
+ }
+ }
+
+ /* Failure shake animation */
+ #failure.show {
+ animation: shake 0.4s ease;
+ }
+
+ @keyframes shake {
+ 0%,
+ 100% {
+ transform: translate(-50%, -50%) scale(1) rotate(0deg);
+ }
+ 25% {
+ transform: translate(-50%, -50%) scale(1) rotate(-5deg);
+ }
+ 75% {
+ transform: translate(-50%, -50%) scale(1) rotate(5deg);
+ }
+ }
+
+ /* Loading indicator - Material Design style spinner */
+ #loading {
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ width: 24px;
+ height: 24px;
+ opacity: 0;
+ transition: opacity 0.25s ease;
+ }
+
+ #loading.show {
+ opacity: 1;
+ }
+
+ #loading svg {
+ width: 24px;
+ height: 24px;
+ animation: rotate 1.4s linear infinite;
+ }
+
+ #loading svg circle {
+ stroke: #3b82f6;
+ stroke-linecap: round;
+ animation: dash 1.4s ease-in-out infinite;
+ }
+
+ @keyframes rotate {
+ 100% {
+ transform: rotate(360deg);
+ }
+ }
+
+ @keyframes dash {
+ 0% {
+ stroke-dasharray: 1, 150;
+ stroke-dashoffset: 0;
+ }
+ 50% {
+ stroke-dasharray: 90, 150;
+ stroke-dashoffset: -35;
+ }
+ 100% {
+ stroke-dasharray: 90, 150;
+ stroke-dashoffset: -124;
+ }
+ }
+
+ /* Reduced motion preference */
+ @media (prefers-reduced-motion: reduce) {
+ #checkbox,
+ #completed,
+ #failure,
+ #loading,
+ #status span,
+ #progress-bar,
+ #branding a {
+ transition: none;
+ }
+
+ #loading svg,
+ #loading svg circle,
+ #completed.show svg path,
+ #failure.show,
+ #progress-bar.indeterminate {
+ animation: none;
+ }
+
+ #progress-bar.indeterminate {
+ width: 100%;
+ }
+
+ /* Show static loading circle when animations are disabled */
+ #loading svg circle {
+ stroke-dasharray: 90, 150;
+ stroke-dashoffset: 0;
+ }
+
+ /* Show checkmark immediately when animations are disabled */
+ #completed.show svg path {
+ stroke-dashoffset: 0;
+ }
+ }
+
+ /* High contrast mode support */
+ @media (forced-colors: active) {
+ #swetrix-captcha {
+ border: 2px solid CanvasText;
+ }
+
+ #checkbox {
+ border: 2px solid CanvasText;
+ }
+
+ #progress-bar {
+ background: Highlight;
+ }
+ }
+ </style>
+ <script>
+ window.__SWETRIX_CAPTCHA_THEME = "light";
+ const urlParams = new URLSearchParams(window.location.search);
+ const pid = urlParams.get("pid");
+ const cid = urlParams.get("cid");
+ const apiUrl = urlParams.get("apiUrl");
+ const lang = urlParams.get("lang");
+
+ window.__SWETRIX_CAPTCHA_ID = cid;
+ window.__SWETRIX_PROJECT_ID = pid;
+ if (apiUrl) {
+ window.__SWETRIX_API_URL = apiUrl;
+ }
+ if (lang) {
+ document.documentElement.lang = lang;
+ }
+ </script>
+ <script src="../captcha.js" defer></script>
+ </head>
+
+ <body>
+ <div
+ id="swetrix-captcha"
+ role="checkbox"
+ aria-checked="false"
+ aria-label="Human verification checkbox. Press Enter or Space to verify you are human."
+ tabindex="0"
+ >
+ <!-- Progress bar at the top -->
+ <div
+ id="progress-bar-container"
+ role="progressbar"
+ aria-valuemin="0"
+ aria-valuemax="100"
+ aria-valuenow="0"
+ aria-label="Verification progress"
+ >
+ <div id="progress-bar"></div>
+ </div>
+
+ <div id="challenge">
+ <div id="action">
+ <!-- Can contain a checkbox itself / a red cross (with a retry action) / a green check mark -->
+ <div id="checkbox" aria-hidden="true"></div>
+ <div id="failure" aria-hidden="true">
+ <svg
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ aria-hidden="true"
+ >
+ <path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" />
+ <path d="M12 9v4" />
+ <path d="M12 17h.01" />
+ </svg>
+ </div>
+ <div id="completed" aria-hidden="true">
+ <svg
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ aria-hidden="true"
+ >
+ <path d="M20 6 9 17l-5-5" />
+ </svg>
+ </div>
+ <div id="loading" aria-hidden="true">
+ <svg viewBox="0 0 50 50" aria-hidden="true">
+ <circle cx="25" cy="25" r="20" fill="none" stroke-width="4"></circle>
+ </svg>
+ </div>
</div>
- <div id="loading" aria-hidden="true">
- <svg viewBox="0 0 50 50" aria-hidden="true">
- <circle cx="25" cy="25" r="20" fill="none" stroke-width="4"></circle>
- </svg>
+ <div id="status" aria-live="polite" aria-atomic="true">
+ <span id="status-default">I am human</span>
+ <span id="status-failure" class="hidden">Verification failed, click to retry</span>
+ <span id="status-computing" class="hidden">
+ <span>Verifying...</span>
+ </span>
</div>
</div>
- <div id="status" aria-live="polite" aria-atomic="true">
- <span id="status-default">I am human</span>
- <span id="status-failure" class="hidden">Verification failed, click to retry</span>
- <span id="status-computing" class="hidden">
- <span>Verifying...</span>
- </span>
+ <div id="branding">
+ <a
+ href="https://swetrix.com/captcha"
+ target="_blank"
+ rel="noopener noreferrer"
+ aria-label="Swetrix Captcha - opens in new window"
+ >Swetrix Captcha</a
+ >
</div>
- </div>
- <div id="branding">
- <a href="https://swetrix.com/captcha" target="_blank" rel="noopener noreferrer" aria-label="Swetrix Captcha - opens in new window">Swetrix Captcha</a>
- </div>
-
- <!-- Screen reader only live region for status updates -->
- <div id="sr-status" class="hidden" aria-live="assertive" aria-atomic="true"></div>
- </div>
-</body>
+ <!-- Screen reader only live region for status updates -->
+ <div id="sr-status" class="hidden" aria-live="assertive" aria-atomic="true"></div>
+ </div>
+ </body>
</html>
diff --git a/src/pages/test.html b/src/pages/test.html
index 5c3741bea..dfda553bd 100644
--- a/src/pages/test.html
+++ b/src/pages/test.html
@@ -1,34 +1,32 @@
<!-- Generate a form with several inputs -->
<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>Test</title>
+ <style>
+ .form {
+ display: flex;
+ flex-direction: column;
+ width: 400px;
+ margin: 0 auto;
+ }
-<head>
- <meta charset="utf-8">
- <title>Test</title>
- <style>
- .form {
- display: flex;
- flex-direction: column;
- width: 400px;
- margin: 0 auto;
- }
+ .form > * {
+ margin-top: 10px;
+ }
+ </style>
- .form>* {
- margin-top: 10px;
- }
- </style>
-
- <script src="../../dist/captcha-loader.js" defer></script>
-</head>
-
-<body>
- <form class="form" action="test.html" method="post">
- <input type="text" name="name" value="name">
- <input type="text" name="email" value="email">
- <input type="number" name="number" value="number">
- <div class="swecaptcha" data-project-id="AP00000000000" data-theme="auto"></div>
- <!-- <div class="swecaptcha" data-project-id="79eF2Z9rNNvv" data-theme="auto"></div> -->
- <input type="submit" value="Submit">
- </form>
-</body>
+ <script src="../../dist/captcha-loader.js" defer></script>
+ </head>
+ <body>
+ <form class="form" action="test.html" method="post">
+ <input type="text" name="name" value="name" />
+ <input type="text" name="email" value="email" />
+ <input type="number" name="number" value="number" />
+ <div class="swecaptcha" data-project-id="AP00000000000" data-theme="auto"></div>
+ <!-- <div class="swecaptcha" data-project-id="79eF2Z9rNNvv" data-theme="auto"></div> -->
+ <input type="submit" value="Submit" />
+ </form>
+ </body>
</html>