diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml
deleted file mode 100644
index aa47c4e..0000000
--- a/.github/workflows/npm-publish.yml
+++ /dev/null
@@ -1,47 +0,0 @@
-# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
-# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
-
-name: Node.js Package
-
-on:
- release:
- types: [created]
-
-jobs:
- build:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - uses: actions/setup-node@v1
- with:
- node-version: 12
- - run: npm ci
- - run: npm test
-
- publish-npm:
- needs: build
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - uses: actions/setup-node@v1
- with:
- node-version: 12
- registry-url: https://registry.npmjs.org/
- - run: npm ci
- - run: npm publish
- env:
- NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
-
- publish-gpr:
- needs: build
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - uses: actions/setup-node@v1
- with:
- node-version: 12
- registry-url: https://npm.pkg.github.com/
- - run: npm ci
- - run: npm publish
- env:
- NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
diff --git a/docs/Captcha.html b/docs/Captcha.html
new file mode 100644
index 0000000..3a30fa3
--- /dev/null
+++ b/docs/Captcha.html
@@ -0,0 +1,1226 @@
+
+
+
+
+
+
- text |
+ option |
-string
+CreateCaptchaOptions
@@ -599,7 +599,7 @@ Parameters:
View Source
- extra.js, line 41
+ extra.js, line 36
@@ -653,6 +653,230 @@ Type Definitions
+
+ #
+
+
+ CreateCaptchaOptions
+
+
+
+
+
+
+
+
+ Create captcha options in functions.
+
+
+
+
+
+
+ Properties:
+
+
+
+
+
+
+
+ Name |
+
+
+ Type |
+
+
+ Attributes |
+
+
+
+
+ Description |
+
+
+
+
+
+
+
+
+ captcha |
+
+
+
+
+
+SetCaptchaOptions
+
+
+
+ |
+
+
+
+
+ <optional>
+
+
+
+ |
+
+
+
+
+ Captcha text options to customise text appearance and value. |
+
+
+
+
+
+
+ decoy |
+
+
+
+
+
+SetDecoyOptions
+
+
+
+ |
+
+
+
+
+ <optional>
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+
+
+
+ trace |
+
+
+
+
+
+SetTraceOptions
+
+
+
+ |
+
+
+
+
+ <optional>
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+
+
+
+ background |
+
+
+
+
+
+Image
+
+
+
+ |
+
+
+
+
+ <optional>
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ View Source
+
+ constants.js, line 66
+
+
+
+
+
+
+
+
+
+
+
+
+
#
diff --git a/js-script/CaptchaGenerator.d.ts b/js-script/CaptchaGenerator.d.ts
deleted file mode 100644
index 7f17fe2..0000000
--- a/js-script/CaptchaGenerator.d.ts
+++ /dev/null
@@ -1,131 +0,0 @@
-///
-import { Image } from "skia-canvas";
-import { SetCaptchaOption, SetDecoyOption, SetTraceOption } from "./constants";
-/**
- * Captcha generator class.
- */
-export declare class CaptchaGenerator {
- private height;
- private width;
- private captcha;
- private trace;
- private decoy;
- private background?;
- /**
- * Initatiates the creation of captcha image generation.
- * @example const captcha = new CaptchaGenerator({height: 200, width: 600});
- * @param {object} [options] Options for constructor.
- * @param {integer} [options.height=100] Height of captcha image.
- * @param {integer} [options.width=300] Width of captcha image.
- * @since 2.0.0
- */
- constructor(options?: {
- height: number;
- width: number;
- });
- /**
- * Get the text of captcha.
- * @type {string}
- * @since 2.0.3
- */
- get text(): string | undefined;
- /**
- * set dimension for your captcha image
- * @param {integer} height Height of captcha image.
- * @param {integer} width Width of captcha image.
- * @example
- * const { CaptchaGenerator } = require("captcha-canvas");
- * const fs = require("fs")
- * const captcha = new CaptchaGenerator();
- * captcha.setDimension(200, 600);
- * const buffer = await captcha.generate() //generate image
- *
- * fs.writeFileSync("image.png", buffer)
- * @since 2.0.0
- */
- setDimension(height: number, width: number): CaptchaGenerator;
- /**
- * Set background for captcha image.
- * @param {buffer} image Buffer/url/path of image.
- * @example
- * const { CaptchaGenerator } = require("captcha-canvas");
- * const fs = require("fs")
- * const captcha = new CaptchaGenerator();
- * captcha.setBackground("./path/toFile");
- * const buffer = await captcha.generate() //generate image
- *
- * fs.writeFileSync("image.png", buffer)
- * @since 2.0.0
- */
- setBackground(image: string | Buffer): this;
- /**
- * Change captcha text options
- * @param {SetCaptchaOptions} options Captcha appearance options.
- * @example
- * const { CaptchaGenerator } = require("captcha-canvas");
- * const fs = require("fs")
- * const captcha = new CaptchaGenerator();
- * const options = {font: "Comic Sans", size: 60}
- * captcha.setCaptcha(options)
- * const buffer = await captcha.generate() //generate image
- *
- * fs.writeFileSync("image.png", buffer)
- * @since 2.0.0
- */
- setCaptcha(option: SetCaptchaOption): this;
- /**
- * Change trace creation options.
- * @param {SetTraceOptions} options Trace Line appearance options.
- * @example
- * const { CaptchaGenerator } = require("captcha-canvas");
- * const fs = require("fs")
- * const captcha = new CaptchaGenerator();
- * const options = {size: 5, color: "deeppink"}
- * captcha.setTrace(options)
- * const buffer = await captcha.generate() //generate image
- *
- * fs.writeFileSync("image.png", buffer)
- * @since 2.0.0
- */
- setTrace(option: SetTraceOption): this;
- /**
- * Change decoy options
- * @param {SetDecoyOptions} options Decoy characters customisation options
- * @since 2.0.0
- */
- setDecoy(option: SetDecoyOption): this;
- /**
- * Method which returns image buffer
- * @async
- * @returns {Promise}
- * @example
- * const { CaptchaGenerator } = require("captcha-canvas");
- * const fs = require("fs")
- * const captcha = new CaptchaGenerator();
- * const buffer = await captcha.generate() //generate image
- *
- * fs.writeFileSync("image.png", buffer)
- * @since 2.0.0
- */
- generate(): Promise;
- /**
- * Non asynchronous method to generate captcha image.
- * > Note: It do not use `setBackground` method value for background image. If you want to set background
- * and also use generateSync method then use background option in genrateSync method.
- * @param {object} [options] Options to add extra values
- * @param {Image} [options.background] Add background image.
- * @example
- * const { CaptchaGenerator, resolveImage } = require("captcha-canvas");
- * const fs = require("fs");
- * const img = await resolveImage("./path/to/file");
- *
- * const captcha = new CaptchaGenerator()
- * .generateSync({background: img});
- *
- * fs.writeFileSync("image.png", captcha);
- * @since 2.2.0
- */
- generateSync(option?: {
- background?: Image;
- }): Buffer;
-}
diff --git a/js-script/CaptchaGenerator.js b/js-script/CaptchaGenerator.js
deleted file mode 100644
index 54563fa..0000000
--- a/js-script/CaptchaGenerator.js
+++ /dev/null
@@ -1,177 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.CaptchaGenerator = void 0;
-const skia_canvas_1 = require("skia-canvas");
-const _1 = require(".");
-const constants_1 = require("./constants");
-const util_1 = require("./util");
-/**
- * Captcha generator class.
- */
-class CaptchaGenerator {
- /**
- * Initatiates the creation of captcha image generation.
- * @example const captcha = new CaptchaGenerator({height: 200, width: 600});
- * @param {object} [options] Options for constructor.
- * @param {integer} [options.height=100] Height of captcha image.
- * @param {integer} [options.width=300] Width of captcha image.
- * @since 2.0.0
- */
- constructor(options = { height: 100, width: 300 }) {
- this.height = options.height;
- this.width = options.width;
- this.captcha = constants_1.defaultCaptchaOption;
- this.trace = constants_1.defaultTraceOptions;
- this.decoy = constants_1.defaultDecoyOptions;
- this.captcha.text = (0, util_1.randomText)(this.captcha.characters || 6);
- }
- /**
- * Get the text of captcha.
- * @type {string}
- * @since 2.0.3
- */
- get text() {
- return this.captcha.text;
- }
- /**
- * set dimension for your captcha image
- * @param {integer} height Height of captcha image.
- * @param {integer} width Width of captcha image.
- * @example
- * const { CaptchaGenerator } = require("captcha-canvas");
- * const fs = require("fs")
- * const captcha = new CaptchaGenerator();
- * captcha.setDimension(200, 600);
- * const buffer = await captcha.generate() //generate image
- *
- * fs.writeFileSync("image.png", buffer)
- * @since 2.0.0
- */
- setDimension(height, width) {
- this.height = height;
- this.width = width;
- return this;
- }
- /**
- * Set background for captcha image.
- * @param {buffer} image Buffer/url/path of image.
- * @example
- * const { CaptchaGenerator } = require("captcha-canvas");
- * const fs = require("fs")
- * const captcha = new CaptchaGenerator();
- * captcha.setBackground("./path/toFile");
- * const buffer = await captcha.generate() //generate image
- *
- * fs.writeFileSync("image.png", buffer)
- * @since 2.0.0
- */
- setBackground(image) {
- this.background = image;
- return this;
- }
- /**
- * Change captcha text options
- * @param {SetCaptchaOptions} options Captcha appearance options.
- * @example
- * const { CaptchaGenerator } = require("captcha-canvas");
- * const fs = require("fs")
- * const captcha = new CaptchaGenerator();
- * const options = {font: "Comic Sans", size: 60}
- * captcha.setCaptcha(options)
- * const buffer = await captcha.generate() //generate image
- *
- * fs.writeFileSync("image.png", buffer)
- * @since 2.0.0
- */
- setCaptcha(option) {
- this.captcha = { ...this.captcha, ...option };
- if (option.text)
- this.captcha.characters = option.text.length;
- if (!option.text && option.characters)
- this.captcha.text = (0, util_1.randomText)(option.characters);
- return this;
- }
- /**
- * Change trace creation options.
- * @param {SetTraceOptions} options Trace Line appearance options.
- * @example
- * const { CaptchaGenerator } = require("captcha-canvas");
- * const fs = require("fs")
- * const captcha = new CaptchaGenerator();
- * const options = {size: 5, color: "deeppink"}
- * captcha.setTrace(options)
- * const buffer = await captcha.generate() //generate image
- *
- * fs.writeFileSync("image.png", buffer)
- * @since 2.0.0
- */
- setTrace(option) {
- this.trace = { ...this.trace, ...option };
- return this;
- }
- /**
- * Change decoy options
- * @param {SetDecoyOptions} options Decoy characters customisation options
- * @since 2.0.0
- */
- setDecoy(option) {
- this.decoy = { ...this.decoy, ...option };
- return this;
- }
- /**
- * Method which returns image buffer
- * @async
- * @returns {Promise}
- * @example
- * const { CaptchaGenerator } = require("captcha-canvas");
- * const fs = require("fs")
- * const captcha = new CaptchaGenerator();
- * const buffer = await captcha.generate() //generate image
- *
- * fs.writeFileSync("image.png", buffer)
- * @since 2.0.0
- */
- async generate() {
- const captchaCanvas = new _1.Captcha(this.width, this.height);
- if (this.background)
- captchaCanvas.drawImage(await (0, skia_canvas_1.loadImage)(this.background));
- if (this.decoy.opacity)
- captchaCanvas.addDecoy(this.decoy);
- if (this.captcha.opacity)
- captchaCanvas.drawCaptcha(this.captcha);
- if (this.trace.opacity)
- captchaCanvas.drawTrace(this.trace);
- return captchaCanvas.png;
- }
- /**
- * Non asynchronous method to generate captcha image.
- * > Note: It do not use `setBackground` method value for background image. If you want to set background
- * and also use generateSync method then use background option in genrateSync method.
- * @param {object} [options] Options to add extra values
- * @param {Image} [options.background] Add background image.
- * @example
- * const { CaptchaGenerator, resolveImage } = require("captcha-canvas");
- * const fs = require("fs");
- * const img = await resolveImage("./path/to/file");
- *
- * const captcha = new CaptchaGenerator()
- * .generateSync({background: img});
- *
- * fs.writeFileSync("image.png", captcha);
- * @since 2.2.0
- */
- generateSync(option = {}) {
- const captchaCanvas = new _1.Captcha(this.width, this.height);
- captchaCanvas.async = false;
- if (option.background)
- captchaCanvas.drawImage(option.background);
- if (this.decoy.opacity)
- captchaCanvas.addDecoy(this.decoy);
- if (this.captcha.opacity)
- captchaCanvas.drawCaptcha(this.captcha);
- if (this.trace.opacity)
- captchaCanvas.drawTrace(this.trace);
- return captchaCanvas.png;
- }
-}
-exports.CaptchaGenerator = CaptchaGenerator;
diff --git a/js-script/captcha.d.ts b/js-script/captcha.d.ts
deleted file mode 100644
index 01518ca..0000000
--- a/js-script/captcha.d.ts
+++ /dev/null
@@ -1,61 +0,0 @@
-///
-import { Canvas, CanvasRenderingContext2D, Image } from "skia-canvas";
-import { SetCaptchaOption, SetDecoyOption, SetTraceOption } from "./constants";
-/**
- * Captcha Generator
- */
-export declare class Captcha {
- protected _height: number;
- protected _width: number;
- protected _captcha: SetCaptchaOption;
- protected _trace: SetTraceOption;
- protected _decoy: SetDecoyOption;
- protected _canvas: Canvas;
- protected _ctx: CanvasRenderingContext2D;
- protected _coordinates: number[][];
- async: Boolean;
- /**
- * Start captcha image creation.
- * @param {number} [width] Width of captcha image.
- * @param {number} [height] Height of captcha image.
- * @constructor
- */
- constructor(width?: number, height?: number);
- /**
- * Get Captcha text.
- * @returns {string} Get captcha text.
- */
- get text(): string;
- /**
- * Get png image of captcha.
- * @returns {Buffer | Promise} Get png image of captcha created.
- */
- get png(): Buffer | Promise;
- /**
- * Draw image on your captcha.
- * @param {Image} image Choose image you want to add.
- * @returns {Captcha}
- */
- drawImage(image: Image): Captcha;
- /**
- * Add decoy on your captcha image.
- * @param {SetDecoyOptions} [decoyOption] Decoy option you want to customise
- * @returns {Captcha}
- */
- addDecoy(decoyOption?: SetDecoyOption): Captcha;
- /**
- * Draw trace line over your captcha.
- *
- * Note: If you want to use custom text or change size of captcha text then drawCaptcha before drawTrace.
- * @param {SetTraceOptions} [traceOption]
- * @returns {Captcha}
- */
- drawTrace(traceOption?: SetTraceOption): Captcha;
- /**
- * Draw captcha text on captcha image.
- * @param {SetCaptchaOptions} [captchaOption]
- * @returns {Captcha}
- */
- drawCaptcha(captchaOption?: SetCaptchaOption): Captcha;
- toBuffer(): void;
-}
diff --git a/js-script/captcha.js b/js-script/captcha.js
deleted file mode 100644
index ba2ee52..0000000
--- a/js-script/captcha.js
+++ /dev/null
@@ -1,140 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.Captcha = void 0;
-const skia_canvas_1 = require("skia-canvas");
-const constants_1 = require("./constants");
-const util_1 = require("./util");
-/**
- * Captcha Generator
- */
-class Captcha {
- /**
- * Start captcha image creation.
- * @param {number} [width] Width of captcha image.
- * @param {number} [height] Height of captcha image.
- * @constructor
- */
- constructor(width = constants_1.defaultDimension.width, height = constants_1.defaultDimension.height) {
- this._height = height;
- this._width = width;
- this._captcha = constants_1.defaultCaptchaOption;
- this._trace = constants_1.defaultTraceOptions;
- this._decoy = constants_1.defaultDecoyOptions;
- const canvas = new skia_canvas_1.Canvas(width, height);
- const ctx = canvas.getContext('2d');
- ctx.lineJoin = 'miter';
- ctx.textBaseline = 'middle';
- this._canvas = canvas;
- this._ctx = ctx;
- this.async = true;
- this._coordinates = [];
- }
- /**
- * Get Captcha text.
- * @returns {string} Get captcha text.
- */
- get text() {
- return this._captcha.text || "";
- }
- /**
- * Get png image of captcha.
- * @returns {Buffer | Promise} Get png image of captcha created.
- */
- get png() {
- this._canvas.async = this.async;
- return this._canvas.png;
- }
- /**
- * Draw image on your captcha.
- * @param {Image} image Choose image you want to add.
- * @returns {Captcha}
- */
- drawImage(image) {
- this._ctx.drawImage(image, 0, 0, this._width, this._height);
- return this;
- }
- /**
- * Add decoy on your captcha image.
- * @param {SetDecoyOptions} [decoyOption] Decoy option you want to customise
- * @returns {Captcha}
- */
- addDecoy(decoyOption = {}) {
- const option = { ...this._decoy, ...decoyOption };
- if (!option.total)
- option.total = Math.floor(this._width * this._height / 10000);
- const decoyText = (0, util_1.randomText)(option.total);
- this._ctx.font = `${option.size}px ${option.font}`;
- this._ctx.globalAlpha = option.opacity;
- this._ctx.fillStyle = option.color;
- for (let i = 0; i < decoyText.length; i++) {
- this._ctx.fillText(decoyText[i], (0, util_1.getRandom)(30, this._width - 30), (0, util_1.getRandom)(30, this._height - 30));
- }
- return this;
- }
- /**
- * Draw trace line over your captcha.
- *
- * Note: If you want to use custom text or change size of captcha text then drawCaptcha before drawTrace.
- * @param {SetTraceOptions} [traceOption]
- * @returns {Captcha}
- */
- drawTrace(traceOption = {}) {
- const option = { ...this._trace, ...traceOption };
- if (!this._coordinates[0])
- this._coordinates = (0, util_1.getRandomCoordinate)(this._height, this._width, this._captcha.characters || 6);
- const coordinates = this._coordinates;
- this._ctx.strokeStyle = option.color;
- this._ctx.globalAlpha = option.opacity;
- this._ctx.beginPath();
- this._ctx.moveTo(coordinates[0][0], coordinates[0][1]);
- this._ctx.lineWidth = option.size;
- for (let i = 1; i < coordinates.length; i++) {
- this._ctx.lineTo(coordinates[i][0], coordinates[i][1]);
- }
- this._ctx.stroke();
- return this;
- }
- /**
- * Draw captcha text on captcha image.
- * @param {SetCaptchaOptions} [captchaOption]
- * @returns {Captcha}
- */
- drawCaptcha(captchaOption = {}) {
- var _a;
- const option = { ...this._captcha, ...captchaOption };
- if (captchaOption.text)
- option.characters = captchaOption.text.length;
- if (!captchaOption.text && captchaOption.characters)
- option.text = (0, util_1.randomText)(option.characters || 6);
- if (!option.text)
- option.text = (0, util_1.randomText)(option.characters || 6);
- this._captcha = option;
- if (!this._coordinates[0])
- this._coordinates = (0, util_1.getRandomCoordinate)(this._height, this._width, option.characters || 6);
- const coordinates = this._coordinates;
- this._ctx.font = `${option.size}px ${option.font}`;
- this._ctx.globalAlpha = option.opacity;
- this._ctx.fillStyle = option.color;
- for (let n = 0; n < coordinates.length; n++) {
- this._ctx.save();
- this._ctx.translate(coordinates[n][0], coordinates[n][1]);
- if (option.skew) {
- this._ctx.transform(1, Math.random(), (0, util_1.getRandom)(20) / 100, 1, 0, 0);
- }
- if (option.rotate && option.rotate > 0) {
- this._ctx.rotate((0, util_1.getRandom)(-option.rotate, option.rotate) * Math.PI / 180);
- }
- if (option.colors && ((_a = option.colors) === null || _a === void 0 ? void 0 : _a.length) > 2) {
- this._ctx.fillStyle = option.colors[(0, util_1.getRandom)(option.colors.length - 1)];
- }
- this._ctx.fillText(option.text[n], 0, 0);
- this._ctx.restore();
- }
- ;
- return this;
- }
- toBuffer() {
- this._canvas.toBuffer('png');
- }
-}
-exports.Captcha = Captcha;
diff --git a/js-script/constants.d.ts b/js-script/constants.d.ts
deleted file mode 100644
index acb8077..0000000
--- a/js-script/constants.d.ts
+++ /dev/null
@@ -1,64 +0,0 @@
-export interface SetDimensionOption {
- height: number;
- width: number;
-}
-export interface SetCaptchaOption {
- characters?: number;
- text?: string;
- color?: string;
- font?: string;
- skew?: boolean;
- colors?: string[] | [];
- rotate?: number;
- size?: number;
- opacity?: number;
-}
-export interface SetDecoyOption {
- color?: string;
- font?: string;
- size?: number;
- opacity?: number;
- total?: number;
-}
-export interface SetTraceOption {
- color?: string;
- size?: number;
- opacity?: number;
-}
-/**
- * Captcha text options to customise text appearance and value.
- * @typedef SetCaptchaOptions
- * @property {integer} [characters=6] Length of captcha text.
- * @property {string} [text="Random UpperCase string"] Text of captcha
- * @property {hexCode} [color="#32cf7e"] Color of captcha text.
- * @property {font} [font="Sans"] Font of captcha text.
- * @property {boolean} [skew=true] Skew captcha text.
- * @property {array} [colors=[]] Array of hexCode will override color property.
- * @property {number} [rotate=5] Range of angle to rotate text.
- * @property {number} [size=40] Size of captcha text.
- * @property {float} [opacity=1] Opcaity of captcha text.
- */
-export declare const defaultCaptchaOption: SetCaptchaOption;
-/**
- * @typedef SetTraceOptions
- * @property {hexCode} [color="#32cf7e"] Color of trace line.
- * @property {number} [size=3] Width of trace line.
- * @property {float} [opacity=1] Opacoty of trace line.
- */
-export declare const defaultTraceOptions: SetTraceOption;
-/**
- * @typedef SetDecoyOptions
- * @property {hexCode} [color="#646566"] Color of decoy characters.
- * @property {font} [font="Sans"] Font of decoy characters.
- * @property {number} [size=20] Size of decoy characters.
- * @property {float} [opacity=0.8] Opacity of decoy characters.
- * @property {number} [total] Total count of decoy characters.
- */
-export declare const defaultDecoyOptions: SetDecoyOption;
-/**
- * Customise dimension of captcha image.
- * @typedef SetDimensionOption
- * @property {integer} [height=100] Height of captcha image.
- * @property {integer} [width=300] Width of captcha image.
- */
-export declare const defaultDimension: SetDimensionOption;
diff --git a/js-script/constants.js b/js-script/constants.js
deleted file mode 100644
index 63b39a5..0000000
--- a/js-script/constants.js
+++ /dev/null
@@ -1,65 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.defaultDimension = exports.defaultDecoyOptions = exports.defaultTraceOptions = exports.defaultCaptchaOption = void 0;
-;
-;
-;
-;
-/**
- * Captcha text options to customise text appearance and value.
- * @typedef SetCaptchaOptions
- * @property {integer} [characters=6] Length of captcha text.
- * @property {string} [text="Random UpperCase string"] Text of captcha
- * @property {hexCode} [color="#32cf7e"] Color of captcha text.
- * @property {font} [font="Sans"] Font of captcha text.
- * @property {boolean} [skew=true] Skew captcha text.
- * @property {array} [colors=[]] Array of hexCode will override color property.
- * @property {number} [rotate=5] Range of angle to rotate text.
- * @property {number} [size=40] Size of captcha text.
- * @property {float} [opacity=1] Opcaity of captcha text.
- */
-exports.defaultCaptchaOption = {
- characters: 6,
- size: 40,
- font: 'Sans',
- skew: true,
- colors: [],
- rotate: 5,
- color: '#32cf7e',
- opacity: 0.8,
-};
-/**
- * @typedef SetTraceOptions
- * @property {hexCode} [color="#32cf7e"] Color of trace line.
- * @property {number} [size=3] Width of trace line.
- * @property {float} [opacity=1] Opacoty of trace line.
- */
-exports.defaultTraceOptions = {
- size: 3,
- color: '#32cf7e',
- opacity: 1,
-};
-/**
- * @typedef SetDecoyOptions
- * @property {hexCode} [color="#646566"] Color of decoy characters.
- * @property {font} [font="Sans"] Font of decoy characters.
- * @property {number} [size=20] Size of decoy characters.
- * @property {float} [opacity=0.8] Opacity of decoy characters.
- * @property {number} [total] Total count of decoy characters.
- */
-exports.defaultDecoyOptions = {
- color: '#646566',
- font: 'Sans',
- size: 20,
- opacity: 0.8,
-};
-/**
- * Customise dimension of captcha image.
- * @typedef SetDimensionOption
- * @property {integer} [height=100] Height of captcha image.
- * @property {integer} [width=300] Width of captcha image.
- */
-exports.defaultDimension = {
- height: 100,
- width: 300
-};
diff --git a/js-script/extra.d.ts b/js-script/extra.d.ts
deleted file mode 100644
index 72cd062..0000000
--- a/js-script/extra.d.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-///
-import { Image } from "skia-canvas";
-import { SetCaptchaOption, SetDecoyOption, SetTraceOption } from "./constants";
-interface captchaValueSync {
- image: Buffer;
- text: string;
-}
-interface captchaValue {
- image: Promise;
- text: string;
-}
-interface CreateCaptchaOptions {
- captcha?: SetCaptchaOption;
- trace?: SetTraceOption;
- decoy?: SetDecoyOption;
- background?: Image;
-}
-/**
- * Create custom captcha from scratch.
- * @async
- * @param {number} width Width of captcha image.
- * @param {number} height Height of captcha image.
- * @param {string} [text] Captcha text.
- * @returns
- */
-export declare function createCaptcha(width: number, height: number, option?: CreateCaptchaOptions): captchaValue;
-/**
- * Create captcha in sync mode.
- * @param {number} width captcha image width.
- * @param {number} height captcha image height.
- * @param {CreateCaptchaOptions} [option] Captcha text.
- * @returns
- */
-export declare function createCaptchaSync(width: number, height: number, option?: CreateCaptchaOptions): captchaValueSync;
-export {};
diff --git a/js-script/extra.js b/js-script/extra.js
deleted file mode 100644
index c6108d9..0000000
--- a/js-script/extra.js
+++ /dev/null
@@ -1,52 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.createCaptchaSync = exports.createCaptcha = void 0;
-const _1 = require(".");
-/**
- * Create custom captcha from scratch.
- * @async
- * @param {number} width Width of captcha image.
- * @param {number} height Height of captcha image.
- * @param {string} [text] Captcha text.
- * @returns
- */
-function createCaptcha(width, height, option = {}) {
- const captcha = new _1.Captcha(width, height);
- const decoyCount = Math.floor(width * height / 2500);
- if (!option.decoy)
- option.decoy = {};
- if (!option.decoy.total)
- option.decoy.total = decoyCount;
- captcha.addDecoy(option.decoy);
- captcha.drawCaptcha(option.captcha);
- const text = captcha.text;
- captcha.drawTrace(option.trace);
- captcha.addDecoy({ opacity: 1 });
- return { image: captcha.png, text: captcha.text };
-}
-exports.createCaptcha = createCaptcha;
-;
-/**
- * Create captcha in sync mode.
- * @param {number} width captcha image width.
- * @param {number} height captcha image height.
- * @param {CreateCaptchaOptions} [option] Captcha text.
- * @returns
- */
-function createCaptchaSync(width, height, option = {}) {
- const captcha = new _1.Captcha(width, height);
- const decoyCount = Math.floor(width * height / 2500);
- captcha.async = false;
- if (!option.decoy)
- option.decoy = {};
- if (!option.decoy.total)
- option.decoy.total = decoyCount;
- captcha.addDecoy(option.decoy);
- captcha.drawCaptcha(option.captcha);
- const text = captcha.text;
- captcha.drawTrace(option.trace);
- captcha.addDecoy({ opacity: 1 });
- return { image: captcha.png, text: captcha.text };
-}
-exports.createCaptchaSync = createCaptchaSync;
-;
diff --git a/js-script/index.d.ts b/js-script/index.d.ts
deleted file mode 100644
index f81c149..0000000
--- a/js-script/index.d.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-export { createCaptcha, createCaptchaSync } from "./extra";
-export { loadImage as resolveImage } from "skia-canvas";
-export { Captcha } from "./captcha";
-export { CaptchaGenerator } from "./CaptchaGenerator";
-export declare const version: string;
diff --git a/js-script/index.js b/js-script/index.js
deleted file mode 100644
index b8df6f4..0000000
--- a/js-script/index.js
+++ /dev/null
@@ -1,13 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.version = exports.CaptchaGenerator = exports.Captcha = exports.resolveImage = exports.createCaptchaSync = exports.createCaptcha = void 0;
-var extra_1 = require("./extra");
-Object.defineProperty(exports, "createCaptcha", { enumerable: true, get: function () { return extra_1.createCaptcha; } });
-Object.defineProperty(exports, "createCaptchaSync", { enumerable: true, get: function () { return extra_1.createCaptchaSync; } });
-var skia_canvas_1 = require("skia-canvas");
-Object.defineProperty(exports, "resolveImage", { enumerable: true, get: function () { return skia_canvas_1.loadImage; } });
-var captcha_1 = require("./captcha");
-Object.defineProperty(exports, "Captcha", { enumerable: true, get: function () { return captcha_1.Captcha; } });
-var CaptchaGenerator_1 = require("./CaptchaGenerator");
-Object.defineProperty(exports, "CaptchaGenerator", { enumerable: true, get: function () { return CaptchaGenerator_1.CaptchaGenerator; } });
-exports.version = require(`${__dirname}/../package.json`).version;
diff --git a/js-script/util.d.ts b/js-script/util.d.ts
deleted file mode 100644
index 9709291..0000000
--- a/js-script/util.d.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export declare function getRandom(start?: number, end?: number): number;
-export declare function randomText(characters: number): string;
-export declare function getRandomCoordinate(height: number, width: number, size: number): number[][];
diff --git a/js-script/util.js b/js-script/util.js
deleted file mode 100644
index 12c2689..0000000
--- a/js-script/util.js
+++ /dev/null
@@ -1,31 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.getRandomCoordinate = exports.randomText = exports.getRandom = void 0;
-const crypto_1 = require("crypto");
-function getRandom(start = 0, end = 0) {
- return Math.round(Math.random() * Math.abs(end - start)) + Math.min(start, end);
-}
-exports.getRandom = getRandom;
-;
-function randomText(characters) {
- return (0, crypto_1.randomBytes)(characters).toString('hex').toUpperCase().substr(0, characters);
-}
-exports.randomText = randomText;
-;
-function getRandomCoordinate(height, width, size) {
- let coordinates = [];
- for (let i = 0; i < size; i++) {
- const widthGap = Math.floor(width / size);
- const coordinate = [];
- const randomWidth = widthGap * (i + 0.2);
- coordinate.push(randomWidth);
- const randomHeight = getRandom(30, height - 30);
- coordinate.push(randomHeight);
- coordinates.push(coordinate);
- }
- ;
- coordinates = coordinates.sort((a, b) => a[0] - b[0]);
- return coordinates;
-}
-exports.getRandomCoordinate = getRandomCoordinate;
-;
diff --git a/test.js b/test.js
deleted file mode 100644
index 7b9ee0d..0000000
--- a/test.js
+++ /dev/null
@@ -1,10 +0,0 @@
-const { writeFileSync } = require('fs');
-const { createCaptchaSync } = require('./js-script/extra');
-
-const captcha = createCaptchaSync(900, 300, {
- captcha: {
- size: 80,
- },
-});
-
-writeFileSync('assets/captcha/default.png', captcha.image);
\ No newline at end of file
diff --git a/ts-script/constants.ts b/ts-script/constants.ts
index cbc480e..dd30c19 100644
--- a/ts-script/constants.ts
+++ b/ts-script/constants.ts
@@ -1,3 +1,5 @@
+import { Image } from "skia-canvas";
+
export interface SetDimensionOption {
height: number;
width: number;
@@ -28,6 +30,13 @@ export interface SetTraceOption {
size?: number;
opacity?: number;
};
+
+export interface CreateCaptchaOptions {
+ captcha?: SetCaptchaOption;
+ trace?: SetTraceOption;
+ decoy?: SetDecoyOption;
+ background?: Image;
+}
/**
* Captcha text options to customise text appearance and value.
* @typedef SetCaptchaOptions
@@ -86,3 +95,12 @@ export const defaultDimension: SetDimensionOption = {
height: 100,
width: 300
};
+/**
+ * Create captcha options in functions.
+ * @typedef CreateCaptchaOptions
+ * @property {SetCaptchaOptions} [captcha] Captcha text options to customise text appearance and value.
+ * @property {SetDecoyOptions} [decoy]
+ * @property {SetTraceOptions} [trace]
+ * @property {Image} [background]
+ */
+export const CreateCaptchaOptions = {};
\ No newline at end of file
diff --git a/ts-script/extra.ts b/ts-script/extra.ts
index d5e1ee6..05388b1 100644
--- a/ts-script/extra.ts
+++ b/ts-script/extra.ts
@@ -1,6 +1,5 @@
-import { Image } from "skia-canvas";
import { Captcha } from ".";
-import { SetCaptchaOption, SetDecoyOption, SetTraceOption } from "./constants";
+import { CreateCaptchaOptions } from "./constants";
interface captchaValueSync {
image: Buffer,
@@ -12,18 +11,12 @@ interface captchaValue {
text: string
}
-interface CreateCaptchaOptions {
- captcha?: SetCaptchaOption;
- trace?: SetTraceOption;
- decoy?: SetDecoyOption;
- background?: Image;
-}
/**
* Create custom captcha from scratch.
* @async
* @param {number} width Width of captcha image.
* @param {number} height Height of captcha image.
- * @param {string} [text] Captcha text.
+ * @param {CreateCaptchaOptions} [option] Captcha text.
* @returns
*/
export function createCaptcha(width: number, height: number, option: CreateCaptchaOptions = {}): captchaValue {
@@ -49,7 +42,7 @@ export function createCaptcha(width: number, height: number, option: CreateCaptc
* Create captcha in sync mode.
* @param {number} width captcha image width.
* @param {number} height captcha image height.
- * @param {CreateCaptchaOptions} [option] Captcha text.
+ * @param {CreateCaptchaOptions} [option] Captcha text.
* @returns
*/
export function createCaptchaSync(width: number, height: number, option: CreateCaptchaOptions = {}): captchaValueSync {
|