PromoCursed/node_modules/.cache/babel-loader/e4b8c7641dbd1914f8206162698e7566f28b71a3623c35c97dc9d5ed658ce035.json

1 line
14 KiB
JSON
Raw Normal View History

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