123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- /// <reference types="miniprogram-api-typings" />
- import { canvasContainer } from "../type";
- export declare type ComponentOptions = {
- /**
- * Component options for data/ECC.
- */
- data?: {
- /**
- * Scale factor for data/ECC dots.
- * @default 1
- */
- scale?: number;
- };
- /**
- * Component options for timing patterns.
- */
- timing?: {
- /**
- * Scale factor for timing patterns.
- * @default 1
- */
- scale?: number;
- /**
- * Protector for timing patterns.
- * @default false
- */
- protectors?: boolean;
- };
- /**
- * Component options for alignment patterns.
- */
- alignment?: {
- /**
- * Scale factor for alignment patterns.
- * @default 1
- */
- scale?: number;
- /**
- * Protector for alignment patterns.
- * @default false
- */
- protectors?: boolean;
- };
- /**
- * Component options for alignment pattern on the bottom-right corner.
- */
- cornerAlignment?: {
- /**
- * Scale factor for alignment pattern on the bottom-right corner.
- * @default 1
- */
- scale?: number;
- /**
- * Protector for alignment pattern on the bottom-right corner.
- * @default true
- */
- protectors?: boolean;
- };
- };
- export declare type Options = {
- /**
- * Text to be encoded in the QR code.
- */
- text: string;
- /**
- * Size of the QR code in pixel.
- *
- * @defaultValue 400
- */
- size?: number;
- /**
- * Size of margins around the QR code body in pixel.
- *
- * @defaultValue 20
- */
- margin?: number;
- /**
- * Error correction level of the QR code.
- *
- * Accepts a value provided by _QRErrorCorrectLevel_.
- *
- * For more information, please refer to [https://www.qrcode.com/en/about/error_correction.html](https://www.qrcode.com/en/about/error_correction.html).
- *
- * @defaultValue 0
- */
- correctLevel?: number;
- /**
- * **This is an advanced option.**
- *
- * Specify the mask pattern to be used in QR code encoding.
- *
- * Accepts a value provided by _QRMaskPattern_.
- *
- * To find out all eight mask patterns, please refer to [https://en.wikipedia.org/wiki/File:QR_Code_Mask_Patterns.svg](https://en.wikipedia.org/wiki/File:QR_Code_Mask_Patterns.svg)
- *
- * For more information, please refer to [https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Masking](https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Masking).
- */
- maskPattern?: number;
- /**
- * **This is an advanced option.**
- *
- * Specify the version to be used in QR code encoding.
- *
- * Accepts an integer in range [1, 40].
- *
- * For more information, please refer to [https://www.qrcode.com/en/about/version.html](https://www.qrcode.com/en/about/version.html).
- */
- version?: number;
- /**
- * Options to control components in the QR code.
- *
- * @deafultValue undefined
- */
- components?: ComponentOptions;
- /**
- * Color of the blocks on the QR code.
- *
- * Accepts a CSS <color>.
- *
- * For more information about CSS <color>, please refer to [https://developer.mozilla.org/en-US/docs/Web/CSS/color_value](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
- *
- * @defaultValue "#000000"
- */
- colorDark?: string;
- /**
- * Color of the empty areas on the QR code.
- *
- * Accepts a CSS <color>.
- *
- * For more information about CSS <color>, please refer to [https://developer.mozilla.org/en-US/docs/Web/CSS/color_value](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
- *
- * @defaultValue "#ffffff"
- */
- colorLight?: string;
- /**
- * Automatically calculate the _colorLight_ value from the QR code's background.
- *
- * @defaultValue true
- */
- autoColor?: boolean;
- /**
- * Background image to be used in the QR code.
- *
- * Accepts a `data:` string in web browsers or a Buffer in Node.js.
- *
- * @defaultValue undefined
- */
- backgroundImage?: string;
- /**
- * Color of the dimming mask above the background image.
- *
- * Accepts a CSS <color>.
- *
- * For more information about CSS <color>, please refer to [https://developer.mozilla.org/en-US/docs/Web/CSS/color_value](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
- *
- * @defaultValue "rgba(0, 0, 0, 0)"
- */
- backgroundDimming?: string;
- /**
- * Use a white margin instead of a transparent one which reveals the background of the QR code on margins.
- *
- * @defaultValue true
- */
- whiteMargin?: boolean;
- /**
- * Logo image to be displayed at the center of the QR code.
- *
- * Accepts a `data:` string in web browsers or a Buffer in Node.js.
- *
- * When set to `undefined` or `null`, the logo is disabled.
- *
- * @defaultValue undefined
- */
- logoImage?: string;
- /**
- * Ratio of the logo size to the QR code size.
- *
- * @defaultValue 0.2
- */
- logoScale?: number;
- /**
- * Size of margins around the logo image in pixels.
- *
- * @defaultValue 6
- */
- logoMargin?: number;
- /**
- * Corner radius of the logo image in pixels.
- *
- * @defaultValue 8
- */
- logoCornerRadius?: number;
- /**
- * @deprecated
- *
- * Ratio of the real size to the full size of the blocks.
- *
- * This can be helpful when you want to make more parts of the background visible.
- *
- * @deafultValue 0.4
- */
- dotScale?: number;
- /**
- *
- * 由于微信不能直接通过createElement生成canvas,目前通过传参形式进行
- *
- */
- canvasContainer?: Record<canvasContainer, WechatMiniprogram.Canvas>;
- };
- export declare class AwesomeQR {
- private canvas;
- private canvasContext;
- private qrCode?;
- private options;
- static CorrectLevel: {
- L: number;
- M: number;
- Q: number;
- H: number;
- };
- private static defaultComponentOptions;
- static defaultOptions: Options;
- constructor(options: Partial<Options>);
- draw(): Promise<string | undefined>;
- setOptions(options: Partial<Options>): Options;
- private _clear;
- private static _prepareRoundedCornerClip;
- private static _prepareRoundedCornerClipReverse;
- private static _getAverageRGB;
- private static _drawDot;
- private static _drawAlignProtector;
- private static _drawAlign;
- private _draw;
- getDataUrl(type?: string, encoderOptions?: number): string;
- }
|