tdesign-mobile-vue
Version:
tdesign-mobile-vue
122 lines (118 loc) • 3.76 kB
JavaScript
/**
* tdesign v1.12.1
* (c) 2025 TDesign Group
* @license MIT
*/
import { Ecc } from './qrcodegen.js';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import '@babel/runtime/helpers/defineProperty';
var ERROR_LEVEL_MAP = {
L: Ecc.LOW,
M: Ecc.MEDIUM,
Q: Ecc.QUARTILE,
H: Ecc.HIGH
};
var DEFAULT_SIZE = 160;
var DEFAULT_LEVEL = "M";
var DEFAULT_BACKGROUND_COLOR = "#FFFFFF";
var DEFAULT_FRONT_COLOR = "#000000";
var DEFAULT_NEED_MARGIN = false;
var DEFAULT_MINVERSION = 1;
var SPEC_MARGIN_SIZE = 4;
var DEFAULT_MARGIN_SIZE = 0;
var DEFAULT_IMG_SCALE = 0.1;
var 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("");
};
var 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;
});
});
};
var 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
};
};
var getMarginSize = function getMarginSize(needMargin, marginSize) {
if (marginSize != null) {
return Math.max(Math.floor(marginSize), 0);
}
return needMargin ? SPEC_MARGIN_SIZE : DEFAULT_MARGIN_SIZE;
};
var isSupportPath2d = function () {
try {
new Path2D().addPath(new Path2D());
} catch (_unused) {
return false;
}
return true;
}();
export { DEFAULT_BACKGROUND_COLOR, DEFAULT_FRONT_COLOR, DEFAULT_IMG_SCALE, DEFAULT_LEVEL, DEFAULT_MARGIN_SIZE, DEFAULT_MINVERSION, DEFAULT_NEED_MARGIN, DEFAULT_SIZE, ERROR_LEVEL_MAP, SPEC_MARGIN_SIZE, excavateModules, generatePath, getImageSettings, getMarginSize, isSupportPath2d };
//# sourceMappingURL=utils.js.map