add all frontend files

This commit is contained in:
2026-01-17 15:16:36 -05:00
parent ff16ae7858
commit e40287e4aa
25704 changed files with 1935289 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
import React from 'react';
declare const QRCodeCanvas: React.ForwardRefExoticComponent<import("./interface").QRProps & React.CanvasHTMLAttributes<HTMLCanvasElement> & React.RefAttributes<HTMLCanvasElement>>;
export { QRCodeCanvas };

140
node_modules/@rc-component/qrcode/lib/QRCodeCanvas.js generated vendored Normal file
View File

@@ -0,0 +1,140 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.QRCodeCanvas = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireDefault(require("react"));
var _useQRCode2 = require("./hooks/useQRCode");
var _utils = require("./utils");
var _excluded = ["value", "size", "level", "bgColor", "fgColor", "includeMargin", "minVersion", "marginSize", "style", "imageSettings", "boostLevel"];
var QRCodeCanvas = exports.QRCodeCanvas = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
var value = props.value,
_props$size = props.size,
size = _props$size === void 0 ? _utils.DEFAULT_SIZE : _props$size,
_props$level = props.level,
level = _props$level === void 0 ? _utils.DEFAULT_LEVEL : _props$level,
_props$bgColor = props.bgColor,
bgColor = _props$bgColor === void 0 ? _utils.DEFAULT_BACKGROUND_COLOR : _props$bgColor,
_props$fgColor = props.fgColor,
fgColor = _props$fgColor === void 0 ? _utils.DEFAULT_FRONT_COLOR : _props$fgColor,
_props$includeMargin = props.includeMargin,
includeMargin = _props$includeMargin === void 0 ? _utils.DEFAULT_NEED_MARGIN : _props$includeMargin,
_props$minVersion = props.minVersion,
minVersion = _props$minVersion === void 0 ? _utils.DEFAULT_MINVERSION : _props$minVersion,
marginSize = props.marginSize,
style = props.style,
imageSettings = props.imageSettings,
boostLevel = props.boostLevel,
otherProps = (0, _objectWithoutProperties2.default)(props, _excluded);
var imgSrc = imageSettings === null || imageSettings === void 0 ? void 0 : imageSettings.src;
var _canvas = _react.default.useRef(null);
var _image = _react.default.useRef(null);
var setCanvasRef = _react.default.useCallback(function (node) {
_canvas.current = node;
if (typeof ref === 'function') {
ref(node);
} else if (ref) {
ref.current = node;
}
}, [ref]);
var _React$useState = _react.default.useState(false),
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
setIsImageLoaded = _React$useState2[1];
var _useQRCode = (0, _useQRCode2.useQRCode)({
value: value,
level: level,
minVersion: minVersion,
includeMargin: includeMargin,
marginSize: marginSize,
imageSettings: imageSettings,
size: size,
boostLevel: boostLevel
}),
margin = _useQRCode.margin,
cells = _useQRCode.cells,
numCells = _useQRCode.numCells,
calculatedImageSettings = _useQRCode.calculatedImageSettings;
_react.default.useEffect(function () {
if (_canvas.current) {
var canvas = _canvas.current;
var ctx = canvas.getContext('2d');
if (!ctx) {
return;
}
var cellsToDraw = cells;
var image = _image.current;
var haveImageToRender = calculatedImageSettings != null && image !== null && image.complete && image.naturalHeight !== 0 && image.naturalWidth !== 0;
if (haveImageToRender) {
if (calculatedImageSettings.excavation != null) {
cellsToDraw = (0, _utils.excavateModules)(cells, calculatedImageSettings.excavation);
}
}
var pixelRatio = window.devicePixelRatio || 1;
canvas.height = canvas.width = size * pixelRatio;
var scale = size / numCells * pixelRatio;
ctx.scale(scale, scale);
ctx.fillStyle = bgColor;
ctx.fillRect(0, 0, numCells, numCells);
ctx.fillStyle = fgColor;
if (_utils.isSupportPath2d) {
ctx.fill(new Path2D((0, _utils.generatePath)(cellsToDraw, margin)));
} else {
cells.forEach(function (row, rdx) {
row.forEach(function (cell, cdx) {
if (cell) {
ctx.fillRect(cdx + margin, rdx + margin, 1, 1);
}
});
});
}
if (calculatedImageSettings) {
ctx.globalAlpha = calculatedImageSettings.opacity;
}
if (haveImageToRender) {
ctx.drawImage(image, calculatedImageSettings.x + margin, calculatedImageSettings.y + margin, calculatedImageSettings.w, calculatedImageSettings.h);
}
}
});
_react.default.useEffect(function () {
setIsImageLoaded(false);
}, [imgSrc]);
var canvasStyle = (0, _objectSpread2.default)({
height: size,
width: size
}, style);
var img = null;
if (imgSrc != null) {
img = /*#__PURE__*/_react.default.createElement("img", {
alt: "QR-Code",
src: imgSrc,
key: imgSrc,
style: {
display: 'none'
},
onLoad: function onLoad() {
setIsImageLoaded(true);
},
ref: _image
// when crossOrigin is not set, the image will be tainted
// and the canvas cannot be exported to an image
,
crossOrigin: calculatedImageSettings === null || calculatedImageSettings === void 0 ? void 0 : calculatedImageSettings.crossOrigin
});
}
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("canvas", (0, _extends2.default)({
style: canvasStyle,
height: size,
width: size,
ref: setCanvasRef,
role: "img"
}, otherProps)), img);
});
if (process.env.NODE_ENV !== 'production') {
QRCodeCanvas.displayName = 'QRCodeCanvas';
}

3
node_modules/@rc-component/qrcode/lib/QRCodeSVG.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
import React from 'react';
declare const QRCodeSVG: React.ForwardRefExoticComponent<import("./interface").QRProps & React.SVGAttributes<SVGSVGElement> & React.RefAttributes<SVGSVGElement>>;
export { QRCodeSVG };

86
node_modules/@rc-component/qrcode/lib/QRCodeSVG.js generated vendored Normal file
View File

@@ -0,0 +1,86 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.QRCodeSVG = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireDefault(require("react"));
var _utils = require("./utils");
var _useQRCode2 = require("./hooks/useQRCode");
var _excluded = ["value", "size", "level", "bgColor", "fgColor", "includeMargin", "minVersion", "title", "marginSize", "imageSettings", "boostLevel"];
var QRCodeSVG = exports.QRCodeSVG = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
var value = props.value,
_props$size = props.size,
size = _props$size === void 0 ? _utils.DEFAULT_SIZE : _props$size,
_props$level = props.level,
level = _props$level === void 0 ? _utils.DEFAULT_LEVEL : _props$level,
_props$bgColor = props.bgColor,
bgColor = _props$bgColor === void 0 ? _utils.DEFAULT_BACKGROUND_COLOR : _props$bgColor,
_props$fgColor = props.fgColor,
fgColor = _props$fgColor === void 0 ? _utils.DEFAULT_FRONT_COLOR : _props$fgColor,
_props$includeMargin = props.includeMargin,
includeMargin = _props$includeMargin === void 0 ? _utils.DEFAULT_NEED_MARGIN : _props$includeMargin,
_props$minVersion = props.minVersion,
minVersion = _props$minVersion === void 0 ? _utils.DEFAULT_MINVERSION : _props$minVersion,
title = props.title,
marginSize = props.marginSize,
imageSettings = props.imageSettings,
boostLevel = props.boostLevel,
otherProps = (0, _objectWithoutProperties2.default)(props, _excluded);
var _useQRCode = (0, _useQRCode2.useQRCode)({
value: value,
level: level,
minVersion: minVersion,
includeMargin: includeMargin,
marginSize: marginSize,
imageSettings: imageSettings,
size: size,
boostLevel: boostLevel
}),
margin = _useQRCode.margin,
cells = _useQRCode.cells,
numCells = _useQRCode.numCells,
calculatedImageSettings = _useQRCode.calculatedImageSettings;
var cellsToDraw = cells;
var image = null;
if (imageSettings != null && calculatedImageSettings != null) {
if (calculatedImageSettings.excavation != null) {
cellsToDraw = (0, _utils.excavateModules)(cells, calculatedImageSettings.excavation);
}
image = /*#__PURE__*/_react.default.createElement("image", {
href: imageSettings.src,
height: calculatedImageSettings.h,
width: calculatedImageSettings.w,
x: calculatedImageSettings.x + margin,
y: calculatedImageSettings.y + margin,
preserveAspectRatio: "none",
opacity: calculatedImageSettings.opacity
// when crossOrigin is not set, the image will be tainted
// and the canvas cannot be exported to an image
,
crossOrigin: calculatedImageSettings.crossOrigin
});
}
var fgPath = (0, _utils.generatePath)(cellsToDraw, margin);
return /*#__PURE__*/_react.default.createElement("svg", (0, _extends2.default)({
height: size,
width: size,
viewBox: "0 0 ".concat(numCells, " ").concat(numCells),
ref: ref,
role: "img"
}, otherProps), !!title && /*#__PURE__*/_react.default.createElement("title", null, title), /*#__PURE__*/_react.default.createElement("path", {
fill: bgColor,
d: "M0,0 h".concat(numCells, "v").concat(numCells, "H0z"),
shapeRendering: "crispEdges"
}), /*#__PURE__*/_react.default.createElement("path", {
fill: fgColor,
d: fgPath,
shapeRendering: "crispEdges"
}), image);
});
if (process.env.NODE_ENV !== 'production') {
QRCodeSVG.displayName = 'QRCodeSVG';
}

View File

@@ -0,0 +1,28 @@
import { QrCode } from '../libs/qrcodegen';
import type { ErrorCorrectionLevel, ImageSettings } from '../interface';
interface Options {
value: string | string[];
level: ErrorCorrectionLevel;
minVersion: number;
includeMargin: boolean;
marginSize?: number;
imageSettings?: ImageSettings;
size: number;
boostLevel?: boolean;
}
export declare const useQRCode: (opt: Options) => {
cells: boolean[][];
margin: number;
numCells: number;
calculatedImageSettings: {
x: number;
y: number;
h: number;
w: number;
excavation: import("../interface").Excavation;
opacity: number;
crossOrigin: import("../interface").CrossOrigin;
};
qrcode: QrCode;
};
export {};

View File

@@ -0,0 +1,42 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useQRCode = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _qrcodegen = require("../libs/qrcodegen");
var _utils = require("../utils");
var _react = _interopRequireDefault(require("react"));
var useQRCode = exports.useQRCode = function useQRCode(opt) {
var value = opt.value,
level = opt.level,
minVersion = opt.minVersion,
includeMargin = opt.includeMargin,
marginSize = opt.marginSize,
imageSettings = opt.imageSettings,
size = opt.size,
boostLevel = opt.boostLevel;
var memoizedQrcode = _react.default.useMemo(function () {
var values = Array.isArray(value) ? value : [value];
var segments = values.reduce(function (acc, val) {
acc.push.apply(acc, (0, _toConsumableArray2.default)(_qrcodegen.QrSegment.makeSegments(val)));
return acc;
}, []);
return _qrcodegen.QrCode.encodeSegments(segments, _utils.ERROR_LEVEL_MAP[level], minVersion, undefined, undefined, boostLevel);
}, [value, level, minVersion, boostLevel]);
return _react.default.useMemo(function () {
var cs = memoizedQrcode.getModules();
var mg = (0, _utils.getMarginSize)(includeMargin, marginSize);
var ncs = cs.length + mg * 2;
var cis = (0, _utils.getImageSettings)(cs, size, mg, imageSettings);
return {
cells: cs,
margin: mg,
numCells: ncs,
calculatedImageSettings: cis,
qrcode: memoizedQrcode
};
}, [memoizedQrcode, size, imageSettings, includeMargin, marginSize]);
};

4
node_modules/@rc-component/qrcode/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,4 @@
export type * from './interface';
export * from './utils';
export * from './QRCodeCanvas';
export * from './QRCodeSVG';

38
node_modules/@rc-component/qrcode/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _utils = require("./utils");
Object.keys(_utils).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _utils[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _utils[key];
}
});
});
var _QRCodeCanvas = require("./QRCodeCanvas");
Object.keys(_QRCodeCanvas).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _QRCodeCanvas[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _QRCodeCanvas[key];
}
});
});
var _QRCodeSVG = require("./QRCodeSVG");
Object.keys(_QRCodeSVG).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _QRCodeSVG[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _QRCodeSVG[key];
}
});
});

131
node_modules/@rc-component/qrcode/lib/interface.d.ts generated vendored Normal file
View File

@@ -0,0 +1,131 @@
import type React from 'react';
import type { Ecc, QrCode } from './libs/qrcodegen';
export type Modules = ReturnType<QrCode['getModules']>;
export type Excavation = {
x: number;
y: number;
w: number;
h: number;
};
export type ErrorCorrectionLevel = 'L' | 'M' | 'Q' | 'H';
export type CrossOrigin = 'anonymous' | 'use-credentials' | '' | undefined;
export type ERROR_LEVEL_MAPPED_TYPE = {
[index in ErrorCorrectionLevel]: Ecc;
};
export type ImageSettings = {
/**
* The URI of the embedded image.
*/
src: string;
/**
* The height, in pixels, of the image.
*/
height: number;
/**
* The width, in pixels, of the image.
*/
width: number;
/**
* Whether or not to "excavate" the modules around the embedded image. This
* means that any modules the embedded image overlaps will use the background
* color.
*/
excavate: boolean;
/**
* The horiztonal offset of the embedded image, starting from the top left corner.
* Will center if not specified.
*/
x?: number;
/**
* The vertical offset of the embedded image, starting from the top left corner.
* Will center if not specified.
*/
y?: number;
/**
* The opacity of the embedded image in the range of 0-1.
* @defaultValue 1
*/
opacity?: number;
/**
* The cross-origin value to use when loading the image. This is used to
* ensure compatibility with CORS, particularly when extracting image data
* from QRCodeCanvas.
* Note: `undefined` is treated differently than the seemingly equivalent
* empty string. This is intended to align with HTML behavior where omitting
* the attribute behaves differently than the empty string.
*/
crossOrigin?: CrossOrigin;
};
export type QRProps = {
/**
* The value to encode into the QR Code. An array of strings can be passed in
* to represent multiple segments to further optimize the QR Code.
*/
value: string | string[];
/**
* If enabled, the Error Correction Level of the result may be higher than
* the specified Error Correction Level option if it can be done without
* increasing the version.
* @defaultValue true
*/
boostLevel?: boolean;
/**
* The size, in pixels, to render the QR Code.
* @defaultValue 128
*/
size?: number;
/**
* The Error Correction Level to use.
* @see https://www.qrcode.com/en/about/error_correction.html
* @defaultValue L
*/
level?: ErrorCorrectionLevel;
/**
* The background color used to render the QR Code.
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
* @defaultValue #FFFFFF
*/
bgColor?: string;
/**
* The foregtound color used to render the QR Code.
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
* @defaultValue #000000
*/
fgColor?: string;
/**
* The style to apply to the QR Code.
*/
style?: React.CSSProperties;
/**
* Whether or not a margin of 4 modules should be rendered as a part of the
* QR Code.
* @deprecated Use `marginSize` instead.
* @defaultValue false
*/
includeMargin?: boolean;
/**
* The number of _modules_ to use for margin. The QR Code specification
* requires `4`, however you can specify any number. Values will be turned to
* integers with `Math.floor`. Overrides `includeMargin` when both are specified.
* @defaultValue 0
*/
marginSize?: number;
/**
* The settings for the embedded image.
*/
imageSettings?: ImageSettings;
/**
* The title to assign to the QR Code. Used for accessibility reasons.
*/
title?: string;
/**
* The minimum version used when encoding the QR Code. Valid values are 1-40
* with higher values resulting in more complex QR Codes. The optimal
* (lowest) version is determined for the `value` provided, using `minVersion`
* as the lower bound.
* @defaultValue 1
*/
minVersion?: number;
};
export type QRPropsCanvas = QRProps & React.CanvasHTMLAttributes<HTMLCanvasElement>;
export type QRPropsSVG = QRProps & React.SVGAttributes<SVGSVGElement>;

5
node_modules/@rc-component/qrcode/lib/interface.js generated vendored Normal file
View File

@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});

View File

@@ -0,0 +1,80 @@
export declare class Mode {
static readonly NUMERIC: Mode;
static readonly ALPHANUMERIC: Mode;
static readonly BYTE: Mode;
static readonly KANJI: Mode;
static readonly ECI: Mode;
modeBits: number;
private numBitsCharCount;
private constructor();
numCharCountBits(ver: number): number;
}
export declare class Ecc {
static readonly LOW: Ecc;
static readonly MEDIUM: Ecc;
static readonly QUARTILE: Ecc;
static readonly HIGH: Ecc;
ordinal: number;
formatBits: number;
private constructor();
}
export declare class QrSegment {
static makeBytes(data: Readonly<number[]>): QrSegment;
static makeNumeric(digits: string): QrSegment;
static makeAlphanumeric(text: string): QrSegment;
static makeSegments(text: string): QrSegment[];
static makeEci(assignVal: number): QrSegment;
static isNumeric(text: string): boolean;
static isAlphanumeric(text: string): boolean;
mode: Mode;
numChars: number;
private bitData;
constructor(mode: Mode, numChars: number, bitData: number[]);
getData(): number[];
static getTotalBits(segs: Readonly<QrSegment[]>, version: number): number;
private static toUtf8ByteArray;
private static readonly NUMERIC_REGEX;
private static readonly ALPHANUMERIC_REGEX;
private static readonly ALPHANUMERIC_CHARSET;
}
export declare class QrCode {
static encodeText(text: string, ecl: Ecc): QrCode;
static encodeBinary(data: Readonly<number[]>, ecl: Ecc): QrCode;
static encodeSegments(segs: Readonly<QrSegment[]>, oriEcl: Ecc, minVersion?: number, maxVersion?: number, mask?: number, boostEcl?: boolean): QrCode;
readonly size: number;
readonly mask: number;
private readonly modules;
private readonly isFunction;
version: number;
errorCorrectionLevel: Ecc;
constructor(version: number, errorCorrectionLevel: Ecc, dataCodewords: Readonly<number[]>, oriMsk: number);
getModule(x: number, y: number): boolean;
getModules(): boolean[][];
private drawFunctionPatterns;
private drawFormatBits;
private drawVersion;
private drawFinderPattern;
private drawAlignmentPattern;
private setFunctionModule;
private addEccAndInterleave;
private drawCodewords;
private applyMask;
private getPenaltyScore;
private getAlignmentPatternPositions;
private static getNumRawDataModules;
private static getNumDataCodewords;
private static reedSolomonComputeDivisor;
private static reedSolomonComputeRemainder;
private static reedSolomonMultiply;
private finderPenaltyCountPatterns;
private finderPenaltyTerminateAndCount;
private finderPenaltyAddHistory;
static readonly MIN_VERSION: number;
static readonly MAX_VERSION: number;
private static readonly PENALTY_N1;
private static readonly PENALTY_N2;
private static readonly PENALTY_N3;
private static readonly PENALTY_N4;
private static readonly ECC_CODEWORDS_PER_BLOCK;
private static readonly NUM_ERROR_CORRECTION_BLOCKS;
}

1119
node_modules/@rc-component/qrcode/lib/libs/qrcodegen.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

53
node_modules/@rc-component/qrcode/lib/utils.d.ts generated vendored Normal file
View File

@@ -0,0 +1,53 @@
import type { CrossOrigin, ERROR_LEVEL_MAPPED_TYPE, ErrorCorrectionLevel, Excavation, ImageSettings } from './interface';
export declare const ERROR_LEVEL_MAP: ERROR_LEVEL_MAPPED_TYPE;
export declare const DEFAULT_SIZE = 128;
export declare const DEFAULT_LEVEL: ErrorCorrectionLevel;
export declare const DEFAULT_BACKGROUND_COLOR = "#FFFFFF";
export declare const DEFAULT_FRONT_COLOR = "#000000";
export declare const DEFAULT_NEED_MARGIN = false;
export declare const DEFAULT_MINVERSION = 1;
export declare const SPEC_MARGIN_SIZE = 4;
export declare const DEFAULT_MARGIN_SIZE = 0;
export declare const DEFAULT_IMG_SCALE = 0.1;
/**
* Generate a path string from modules
* @param modules
* @param margin
* @returns
*/
export declare const generatePath: (modules: boolean[][], margin?: number) => string;
/**
* Excavate modules
* @param modules
* @param excavation
* @returns
*/
export declare const excavateModules: (modules: boolean[][], excavation: Excavation) => boolean[][];
/**
* Get image settings
* @param cells The modules of the QR code
* @param size The size of the QR code
* @param margin
* @param imageSettings
* @returns
*/
export declare const getImageSettings: (cells: boolean[][], size: number, margin: number, imageSettings?: ImageSettings) => {
x: number;
y: number;
h: number;
w: number;
excavation: Excavation | null;
opacity: number;
crossOrigin: CrossOrigin;
};
/**
* Get margin size
* @param needMargin Whether need margin
* @param marginSize Custom margin size
* @returns
*/
export declare const getMarginSize: (needMargin: boolean, marginSize?: number) => number;
/**
* Check if Path2D is supported
*/
export declare const isSupportPath2d: boolean;

157
node_modules/@rc-component/qrcode/lib/utils.js generated vendored Normal file
View File

@@ -0,0 +1,157 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isSupportPath2d = exports.getMarginSize = exports.getImageSettings = exports.generatePath = exports.excavateModules = exports.SPEC_MARGIN_SIZE = exports.ERROR_LEVEL_MAP = exports.DEFAULT_SIZE = exports.DEFAULT_NEED_MARGIN = exports.DEFAULT_MINVERSION = exports.DEFAULT_MARGIN_SIZE = exports.DEFAULT_LEVEL = exports.DEFAULT_IMG_SCALE = exports.DEFAULT_FRONT_COLOR = exports.DEFAULT_BACKGROUND_COLOR = void 0;
var _qrcodegen = require("./libs/qrcodegen");
// Part logic is from `qrcode.react`. (ISC License)
// https://github.com/zpao/qrcode.react
// ==========================================================
// =================== ERROR_LEVEL ==========================
var ERROR_LEVEL_MAP = exports.ERROR_LEVEL_MAP = {
L: _qrcodegen.Ecc.LOW,
M: _qrcodegen.Ecc.MEDIUM,
Q: _qrcodegen.Ecc.QUARTILE,
H: _qrcodegen.Ecc.HIGH
};
// =================== DEFAULT_VALUE ==========================
var DEFAULT_SIZE = exports.DEFAULT_SIZE = 128;
var DEFAULT_LEVEL = exports.DEFAULT_LEVEL = 'L';
var DEFAULT_BACKGROUND_COLOR = exports.DEFAULT_BACKGROUND_COLOR = '#FFFFFF';
var DEFAULT_FRONT_COLOR = exports.DEFAULT_FRONT_COLOR = '#000000';
var DEFAULT_NEED_MARGIN = exports.DEFAULT_NEED_MARGIN = false;
var DEFAULT_MINVERSION = exports.DEFAULT_MINVERSION = 1;
var SPEC_MARGIN_SIZE = exports.SPEC_MARGIN_SIZE = 4;
var DEFAULT_MARGIN_SIZE = exports.DEFAULT_MARGIN_SIZE = 0;
var DEFAULT_IMG_SCALE = exports.DEFAULT_IMG_SCALE = 0.1;
// =================== UTILS ==========================
/**
* Generate a path string from modules
* @param modules
* @param margin
* @returns
*/
var generatePath = exports.generatePath = function generatePath(modules) {
var margin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var ops = [];
modules.forEach(function (row, y) {
var start = null;
row.forEach(function (cell, x) {
if (!cell && start !== null) {
ops.push("M".concat(start + margin, " ").concat(y + margin, "h").concat(x - start, "v1H").concat(start + margin, "z"));
start = null;
return;
}
if (x === row.length - 1) {
if (!cell) {
return;
}
if (start === null) {
ops.push("M".concat(x + margin, ",").concat(y + margin, " h1v1H").concat(x + margin, "z"));
} else {
ops.push("M".concat(start + margin, ",").concat(y + margin, " h").concat(x + 1 - start, "v1H").concat(start + margin, "z"));
}
return;
}
if (cell && start === null) {
start = x;
}
});
});
return ops.join('');
};
/**
* Excavate modules
* @param modules
* @param excavation
* @returns
*/
var excavateModules = exports.excavateModules = function excavateModules(modules, excavation) {
return modules.slice().map(function (row, y) {
if (y < excavation.y || y >= excavation.y + excavation.h) {
return row;
}
return row.map(function (cell, x) {
if (x < excavation.x || x >= excavation.x + excavation.w) {
return cell;
}
return false;
});
});
};
/**
* Get image settings
* @param cells The modules of the QR code
* @param size The size of the QR code
* @param margin
* @param imageSettings
* @returns
*/
var getImageSettings = exports.getImageSettings = function getImageSettings(cells, size, margin, imageSettings) {
if (imageSettings == null) {
return null;
}
var numCells = cells.length + margin * 2;
var defaultSize = Math.floor(size * DEFAULT_IMG_SCALE);
var scale = numCells / size;
var w = (imageSettings.width || defaultSize) * scale;
var h = (imageSettings.height || defaultSize) * scale;
var x = imageSettings.x == null ? cells.length / 2 - w / 2 : imageSettings.x * scale;
var y = imageSettings.y == null ? cells.length / 2 - h / 2 : imageSettings.y * scale;
var opacity = imageSettings.opacity == null ? 1 : imageSettings.opacity;
var excavation = null;
if (imageSettings.excavate) {
var floorX = Math.floor(x);
var floorY = Math.floor(y);
var ceilW = Math.ceil(w + x - floorX);
var ceilH = Math.ceil(h + y - floorY);
excavation = {
x: floorX,
y: floorY,
w: ceilW,
h: ceilH
};
}
var crossOrigin = imageSettings.crossOrigin;
return {
x: x,
y: y,
h: h,
w: w,
excavation: excavation,
opacity: opacity,
crossOrigin: crossOrigin
};
};
/**
* Get margin size
* @param needMargin Whether need margin
* @param marginSize Custom margin size
* @returns
*/
var getMarginSize = exports.getMarginSize = function getMarginSize(needMargin, marginSize) {
if (marginSize != null) {
return Math.max(Math.floor(marginSize), 0);
}
return needMargin ? SPEC_MARGIN_SIZE : DEFAULT_MARGIN_SIZE;
};
/**
* Check if Path2D is supported
*/
var isSupportPath2d = exports.isSupportPath2d = function () {
try {
new Path2D().addPath(new Path2D());
} catch (_unused) {
return false;
}
return true;
}();