Skip to content
This repository was archived by the owner on Feb 15, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

29 changes: 18 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand All @@ -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"
}
}
52 changes: 0 additions & 52 deletions rollup.config.js

This file was deleted.

83 changes: 83 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// import commonjs from '@rollup/plugin-commonjs'
import copy from 'rollup-plugin-copy'
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.captcha,
format: 'umd',
name: 'captcha',
sourcemap: true,
},
],
plugins: [
typescript({
outDir: './dist',
sourceMap: true,
tslib: require.resolve('tslib'),
}),

// copying assets
copy({
targets: [
{ src: 'src/assets/*', dest: 'dist/assets' },
{ src: 'src/pages/*', dest: 'dist/pages' },
],
}),
terser(),
// commonjs(),
],
},
{
input: CAPTCHA_LOADER_PATH,
output: [
{
file: pkg.captchaloader,
format: 'umd',
name: 'captcha-loader',
sourcemap: true,
},
],
plugins: [
typescript({
outDir: './dist',
sourceMap: true,
tslib: require.resolve('tslib'),
}),
terser(),
// commonjs(),
],
},
{
input: POW_WORKER_PATH,
output: [
{
file: 'dist/pow-worker.js',
format: 'iife',
name: 'powWorker',
sourcemap: true,
},
],
plugins: [
typescript({
outDir: './dist',
sourceMap: true,
tslib: require.resolve('tslib'),
}),
terser(),
// commonjs(),
],
},
]
33 changes: 2 additions & 31 deletions src/captcha-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ const DUMMY_PIDS = ['AP00000000000', 'FAIL000000000']

const isValidPID = (pid: string) => DUMMY_PIDS.includes(pid) || PID_REGEX.test(pid)

const FRAME_HEIGHT_MAPPING = {
default: '66px',
manual: '200px',
}
const FRAME_HEIGHT = '66px'

const getFrameID = (cid: string) => `${cid}-frame`

Expand Down Expand Up @@ -130,32 +127,6 @@ const postMessageCallback = (pmEvent: MessageEvent) => {

break
}

case 'manualStarted': {
const frame = document.getElementById(getFrameID(cid))

if (!frame) {
log(LOG_ACTIONS.error, '[PM -> manualStarted] Frame does not exist.')
return
}

frame.style.height = FRAME_HEIGHT_MAPPING.manual

break
}

case 'manualFinished': {
const frame = document.getElementById(getFrameID(cid))

if (!frame) {
log(LOG_ACTIONS.error, '[PM -> manualFinished] Frame does not exist.')
return
}

frame.style.height = FRAME_HEIGHT_MAPPING.default

break
}
}
}

Expand All @@ -168,7 +139,7 @@ const generateCaptchaFrame = (params: any) => {
theme === 'dark'
? appendParamsToURL(DARK_CAPTCHA_IFRAME_URL, params)
: appendParamsToURL(LIGHT_CAPTCHA_IFRAME_URL, params)
captchaFrame.style.height = FRAME_HEIGHT_MAPPING.default
captchaFrame.style.height = FRAME_HEIGHT
captchaFrame.title = 'Swetrix Captcha'
captchaFrame.style.border = 'none'
captchaFrame.style.width = '302px'
Expand Down
Loading