📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Better UI, update dependencies
Blue Mouse87ad75b7d1c0
diff --git a/.npmrc b/.npmrcdeleted file mode 100644index 319e41e69..000000000--- a/.npmrc+++ /dev/null@@ -1 +0,0 @@-strict-peer-dependencies=falsediff --git a/package.json b/package.jsonindex d4844faf0..7a6ce8d04 100644--- a/package.json+++ b/package.json@@ -1,15 +1,24 @@{"name": "@swetrix/captcha",- "version": "2.0.0",+ "version": "3.0.0","description": "Swetrix CAPTCHA",+ "type": "module","captchaloader": "dist/captcha-loader.js","captcha": "dist/captcha.js","esnext": "dist/esnext/index.js","typings": "dist/esnext/index.d.ts",+ "exports": {+ ".": {+ "import": "./dist/esnext/index.js",+ "require": "./dist/captcha.cjs.js",+ "types": "./dist/esnext/index.d.ts",+ "default": "./dist/captcha.js"+ }+ },"scripts": {"prebuild": "rimraf dist","prepublish": "npm run build",- "build": "rollup -c && tsc -p tsconfig.esnext.json",+ "build": "rollup -c","start": "rollup -c -w","tsc": "tsc -p tsconfig.esnext.json"},@@ -31,17 +40,15 @@"url": "https://github.com/Swetrix/swetrix-js/issues"},"homepage": "https://swetrix.com/docs",- "dependencies": {- "@types/node": "^20.12.12",- "rollup-plugin-copy": "^3.5.0",- "tslib": "^2.6.2"- },"devDependencies": {+ "@rollup/plugin-terser": "^0.4.4",+ "@rollup/plugin-typescript": "^12.3.0",+ "@types/node": "^22.15.21",+ "rollup-plugin-copy": "^3.5.0",+ "tslib": "^2.8.1","@blaumaus/rollup-plugin-uglify": "^7.0.1","rimraf": "^5.0.7",- "rollup": "^2.79.1",- "rollup-plugin-sourcemaps": "^0.6.3",- "rollup-plugin-typescript2": "^0.36.0",- "typescript": "^5.4.5"+ "rollup": "^4.54.0",+ "typescript": "^5.9.3"}}diff --git a/rollup.config.js b/rollup.config.mjssimilarity index 55%rename from rollup.config.jsrename to rollup.config.mjsindex 1d582664b..a0892e6b6 100644--- a/rollup.config.js+++ b/rollup.config.mjs@@ -1,30 +1,33 @@-// import { nodeResolve } from '@rollup/plugin-node-resolve'// import commonjs from '@rollup/plugin-commonjs'-import sourceMaps from 'rollup-plugin-sourcemaps'-import typescript from 'rollup-plugin-typescript2'-import { uglify } from '@blaumaus/rollup-plugin-uglify'import copy from 'rollup-plugin-copy'-import pkg from './package.json'+import typescript from '@rollup/plugin-typescript'+import terser from '@rollup/plugin-terser'+import pkg from './package.json' with { type: 'json' }+import { createRequire } from 'node:module'const CAPTCHA_PATH = 'src/captcha.ts'const CAPTCHA_LOADER_PATH = 'src/captcha-loader.ts'const POW_WORKER_PATH = 'src/pow-worker.ts'+const require = createRequire(import.meta.url)+export default [{input: CAPTCHA_PATH,output: [- // { file: pkg.main, format: 'cjs' },- // { file: pkg.module, format: 'es' },{file: pkg.captcha,format: 'umd',name: 'captcha',+ sourcemap: true,},],plugins: [- typescript(),- uglify(),+ typescript({+ outDir: './dist',+ sourceMap: true,+ tslib: require.resolve('tslib'),+ }),// copying assetscopy({@@ -33,6 +36,8 @@ export default [{ src: 'src/pages/*', dest: 'dist/pages' },],}),+ terser(),+ // commonjs(),],},{@@ -42,12 +47,17 @@ export default [file: pkg.captchaloader,format: 'umd',name: 'captcha-loader',+ sourcemap: true,},],plugins: [- typescript(),- sourceMaps(),- uglify(),+ typescript({+ outDir: './dist',+ sourceMap: true,+ tslib: require.resolve('tslib'),+ }),+ terser(),+ // commonjs(),],},{@@ -57,11 +67,17 @@ export default [file: 'dist/pow-worker.js',format: 'iife',name: 'powWorker',+ sourcemap: true,},],plugins: [- typescript(),- uglify(),+ typescript({+ outDir: './dist',+ sourceMap: true,+ tslib: require.resolve('tslib'),+ }),+ terser(),+ // commonjs(),],},]diff --git a/src/captcha.ts b/src/captcha.tsindex 0150140a0..2eeebeffa 100644--- a/src/captcha.ts+++ b/src/captcha.ts@@ -1,7 +1,7 @@export {}// @ts-ignore-const isDevelopment = window.__SWETRIX_CAPTCHA_DEV || false+const isDevelopment = true // window.__SWETRIX_CAPTCHA_DEV || falseconst API_URL = isDevelopment ? 'http://localhost:5005/v1/captcha' : 'https://api.swetrix.com/v1/captcha'const WORKER_URL = isDevelopment ? './pow-worker.js' : 'https://cap.swetrix.com/pow-worker.js'@@ -64,7 +64,7 @@ const sendMessageToLoader = (event: IFRAME_MESSAGE_TYPES, data = {}) => {}/**- * Sets the provided action visible and the rest hidden+ * Sets the provided action visible and the rest hidden with smooth transitions* @param {*} action checkbox | failure | completed | loading*/const activateAction = (action: ACTION) => {@@ -81,11 +81,18 @@ const activateAction = (action: ACTION) => {loading: document.querySelector('#loading'),}- // Apply hidden class to all actions- actions.checkbox?.classList.add('hidden')- actions.failure?.classList.add('hidden')- actions.completed?.classList.add('hidden')- actions.loading?.classList.add('hidden')+ // Hide all action elements with transitions+ // Checkbox uses fade-out class for smooth transition+ if (action !== ACTION.checkbox) {+ actions.checkbox?.classList.add('fade-out')+ } else {+ actions.checkbox?.classList.remove('fade-out')+ }++ // Loading, failure, completed use .show class for visibility+ actions.loading?.classList.remove('show')+ actions.failure?.classList.remove('show')+ actions.completed?.classList.remove('show')// Change the status textstatusDefault?.classList.add('hidden')@@ -100,14 +107,12 @@ const activateAction = (action: ACTION) => {statusDefault?.classList.remove('hidden')}- // Remove hidden class from the provided action- actions[action]?.classList.remove('hidden')-}--const updateProgress = (attempts: number, hashRate: number) => {- const progressEl = document.querySelector('#pow-progress')- if (progressEl) {- progressEl.textContent = `${(attempts / 1000).toFixed(0)}k hashes (${hashRate}/s)`+ // Show the active action element with animation+ if (action !== ACTION.checkbox) {+ // Small delay to ensure CSS transitions work properly+ requestAnimationFrame(() => {+ actions[action]?.classList.add('show')+ })}}@@ -200,7 +205,6 @@ const solveChallenge = async (challenge: PowChallenge): Promise<void> => {const data = event.dataif (data.type === 'progress') {- updateProgress((data as PowProgress).attempts, (data as PowProgress).hashRate)return}@@ -315,16 +319,6 @@ const solveInMainThread = async (challenge: PowChallenge): Promise<void> => {}nonce++-- // Update progress every 10k iterations- if (nonce % 10000 === 0) {- const elapsed = (Date.now() - startTime) / 1000- const hashRate = Math.round(nonce / elapsed)- updateProgress(nonce, hashRate)-- // Yield to the main thread to prevent blocking- await new Promise((r) => setTimeout(r, 0))- }}// Max iterations reached without finding solutiondiff --git a/src/pages/dark.html b/src/pages/dark.htmlindex 8350db2ab..37e96e41c 100644--- a/src/pages/dark.html+++ b/src/pages/dark.html@@ -24,6 +24,7 @@display: flex;justify-content: center;align-items: center;+ position: relative;/* 300 - 20px (padding) */width: 280px;@@ -47,21 +48,31 @@display: flex;align-items: center;cursor: pointer;-- /* divide the space between #challenge and #branding as a proportion of 5 to 1 using flex */- flex: 5;+ flex: 1;}#action {margin-right: 10px;+ position: relative;+ width: 28px;+ height: 28px;}#checkbox {background-color: #111827;- border: 1px solid #1e293b;+ 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;+ }++ #checkbox:hover {+ border-color: #4b5563;}#status {@@ -69,46 +80,48 @@color: #f9fafb;}+ #status span {+ transition: opacity 0.2s ease;+ }+#status-computing {display: flex;flex-direction: column;}- #pow-progress {- font-size: 10px;- color: #9ca3af;- margin-top: 2px;- }-.hidden {display: none !important;}- #branding {- display: flex;- flex-direction: column;- align-items: flex-end;- flex: 1;+ /* Fade out animation for hiding elements */+ .fade-out {+ opacity: 0 !important;+ transform: translate(-50%, -50%) scale(0.8) !important;+ pointer-events: none;}- #legal {- font-size: 10px;+ /* Fade in animation for showing elements */+ .fade-in {+ opacity: 1;+ transform: translate(-50%, -50%) scale(1);}- #legal>a {- color: #f9fafb;- text-decoration: none;- cursor: pointer;+ #branding {+ position: absolute;+ bottom: 4px;+ right: 10px;}- #legal>a:hover {- text-decoration: underline;+ #branding a {+ font-size: 9px;+ color: #6b7280;+ text-decoration: none;+ transition: color 0.2s ease;}- #legal>.separator::before {- content: "-";- margin: 0 2px;- color: #f9fafb;+ #branding a:hover {+ color: #9ca3af;+ text-decoration: underline;}#action svg {@@ -116,40 +129,106 @@height: 28px;}- #failure>svg {+ #failure > svg {/* bg-red-500 */color: #d6292a;}- #completed>svg {+ #completed > svg {/* bg-green-600 */color: #16a24c;}- #completed, #failure {+ #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;}- /* Loading indicator */- @keyframes spin {- 0% {- transform: rotate(0deg);+ #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);}}- #loading {- border-radius: 50%;- width: 17px;- height: 17px;- border: 4px solid #111827;- border-top-color: #4b5563;- animation: spin 2s infinite linear;+ @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;+ }}</style><script>@@ -170,36 +249,34 @@<div id="action"><!-- Can contain a checkbox itself / a red cross (with a retry action) / a green check mark --><div id="checkbox"></div>- <div id="failure" class="hidden">- <svg fill="transparent" fill-opacity="0" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">- <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />+ <div id="failure">+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">+ <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" class="hidden">- <svg fill="transparent" fill-opacity="0" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor">- <path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5" />+ <div id="completed">+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">+ <path d="M20 6 9 17l-5-5"/>+ </svg>+ </div>+ <div id="loading">+ <svg viewBox="0 0 50 50">+ <circle cx="25" cy="25" r="20" fill="none" stroke-width="4"></circle></svg></div>- <div id="loading" class="hidden"></div></div><div id="status"><span id="status-default">I am human</span><span id="status-failure" class="hidden">Failure, please retry</span><span id="status-computing" class="hidden"><span>Verifying...</span>- <span id="pow-progress"></span></span></div></div><div id="branding">- <a href="https://swetrix.com" target="_blank" rel="noopener noreferrer">- <img src="../assets/logo_white.png" alt="Swetrix" width="81" height="18" />- </a>- <div id="legal">- <a href="https://swetrix.com/privacy" target="_blank" rel="noopener noreferrer">Privacy</a>- <span class="separator"></span>- <a href="https://swetrix.com/terms" target="_blank" rel="noopener noreferrer">Terms</a>- </div>+ <a href="https://swetrix.com/captcha" target="_blank" rel="noopener noreferrer">Swetrix Captcha</a></div></div></body>diff --git a/src/pages/light.html b/src/pages/light.htmlindex 290a2c358..d32684079 100644--- a/src/pages/light.html+++ b/src/pages/light.html@@ -24,6 +24,7 @@display: flex;justify-content: center;align-items: center;+ position: relative;/* 300 - 20px (padding) */width: 280px;@@ -49,21 +50,31 @@display: flex;align-items: center;cursor: pointer;-- /* divide the space between #challenge and #branding as a proportion of 5 to 1 using flex */- flex: 5;+ flex: 1;}#action {margin-right: 10px;+ position: relative;+ width: 28px;+ height: 28px;}#checkbox {background-color: #fff;- border: 1px solid #e9e9e9;+ 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;+ }++ #checkbox:hover {+ border-color: #a0a0a0;}#status {@@ -71,46 +82,48 @@color: #0f0f0f;}+ #status span {+ transition: opacity 0.2s ease;+ }+#status-computing {display: flex;flex-direction: column;}- #pow-progress {- font-size: 10px;- color: #6b7280;- margin-top: 2px;- }-.hidden {display: none !important;}- #branding {- display: flex;- flex-direction: column;- align-items: flex-end;- flex: 1;+ /* Fade out animation for hiding elements */+ .fade-out {+ opacity: 0 !important;+ transform: translate(-50%, -50%) scale(0.8) !important;+ pointer-events: none;}- #legal {- font-size: 10px;+ /* Fade in animation for showing elements */+ .fade-in {+ opacity: 1;+ transform: translate(-50%, -50%) scale(1);}- #legal>a {- color: #0f0f0f;- text-decoration: none;- cursor: pointer;+ #branding {+ position: absolute;+ bottom: 4px;+ right: 10px;}- #legal>a:hover {- text-decoration: underline;+ #branding a {+ font-size: 9px;+ color: #6b7280;+ text-decoration: none;+ transition: color 0.2s ease;}- #legal>.separator::before {- content: "-";- margin: 0 2px;- color: #0f0f0f;+ #branding a:hover {+ color: #374151;+ text-decoration: underline;}#action svg {@@ -118,40 +131,106 @@height: 28px;}- #failure>svg {+ #failure > svg {/* bg-red-500 */color: #d6292a;}- #completed>svg {+ #completed > svg {/* bg-green-600 */color: #16a24c;}- #completed, #failure {+ #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;}- /* Loading indicator */- @keyframes spin {- 0% {- transform: rotate(0deg);+ #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);}}- #loading {- border-radius: 50%;- width: 17px;- height: 17px;- border: 4px solid #b4b4b4;- border-top-color: #fff;- animation: spin 2s infinite linear;+ @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;+ }}</style><script>@@ -172,36 +251,34 @@<div id="action"><!-- Can contain a checkbox itself / a red cross (with a retry action) / a green check mark --><div id="checkbox"></div>- <div id="failure" class="hidden">- <svg fill="transparent" fill-opacity="0" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">- <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />+ <div id="failure">+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">+ <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" class="hidden">- <svg fill="transparent" fill-opacity="0" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor">- <path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5" />+ <div id="completed">+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">+ <path d="M20 6 9 17l-5-5"/>+ </svg>+ </div>+ <div id="loading">+ <svg viewBox="0 0 50 50">+ <circle cx="25" cy="25" r="20" fill="none" stroke-width="4"></circle></svg></div>- <div id="loading" class="hidden"></div></div><div id="status"><span id="status-default">I am human</span><span id="status-failure" class="hidden">Failure, please retry</span><span id="status-computing" class="hidden"><span>Verifying...</span>- <span id="pow-progress"></span></span></div></div><div id="branding">- <a href="https://swetrix.com" target="_blank" rel="noopener noreferrer">- <img src="../assets/logo_blue.png" alt="Swetrix" width="81" height="18" />- </a>- <div id="legal">- <a href="https://swetrix.com/privacy" target="_blank" rel="noopener noreferrer">Privacy</a>- <span class="separator"></span>- <a href="https://swetrix.com/terms" target="_blank" rel="noopener noreferrer">Terms</a>- </div>+ <a href="https://swetrix.com/captcha" target="_blank" rel="noopener noreferrer">Swetrix Captcha</a></div></div></body>diff --git a/tsconfig.esnext.json b/tsconfig.esnext.jsonindex 901fb91ab..08290bee7 100644--- a/tsconfig.esnext.json+++ b/tsconfig.esnext.json@@ -1,17 +1,15 @@{"compilerOptions": {"moduleResolution": "node",- "target": "es2020",- "module": "es2015",- "lib": ["dom"],+ "target": "ES2020",+ "module": "ESNext",+ "lib": ["ES2020", "DOM"],"strict": true,"sourceMap": true,"declaration": true,- "allowSyntheticDefaultImports": true,- "experimentalDecorators": true,- "emitDecoratorMetadata": true,"outDir": "dist/esnext",- "typeRoots": ["node_modules/@types"]+ "typeRoots": ["node_modules/@types"],+ "skipLibCheck": true},"include": ["src"]-}+}\ No newline at end of filediff --git a/tsconfig.json b/tsconfig.jsonindex 3fe10f8db..0892225fc 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -1,17 +1,14 @@{"compilerOptions": {"moduleResolution": "node",- "target": "es5",- "module": "es2015",- "lib": ["es2015", "es2016", "es2017", "dom"],+ "target": "ES2018",+ "module": "ESNext",+ "lib": ["ES2018", "DOM"],"strict": true,- "allowSyntheticDefaultImports": true,- "experimentalDecorators": true,- "emitDecoratorMetadata": true,"sourceMap": true,"declaration": false,- "outDir": "dist/lib",- "typeRoots": ["node_modules/@types"]+ "allowSyntheticDefaultImports": true,+ "skipLibCheck": true},"include": ["src"]}