qreator 9.3.0 → 9.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/matrix.d.ts +1 -0
- package/lib/browser/pdf.umd.js +34 -17
- package/lib/browser/pdf.umd.js.map +1 -1
- package/lib/browser/png.umd.js +36 -13
- package/lib/browser/png.umd.js.map +1 -1
- package/lib/browser/svg.umd.js +234 -214
- package/lib/browser/svg.umd.js.map +1 -1
- package/lib/matrix.d.ts +1 -0
- package/lib/matrix.js +15 -0
- package/lib/matrix.js.map +1 -1
- package/lib/pdf.js +19 -16
- package/lib/pdf.js.map +1 -1
- package/lib/png.js +24 -12
- package/lib/png.js.map +1 -1
- package/lib/png_browser.js +22 -13
- package/lib/png_browser.js.map +1 -1
- package/lib/svg.js +25 -19
- package/lib/svg.js.map +1 -1
- package/lib/utils.js +1 -1
- package/lib/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/matrix.ts +21 -0
- package/src/pdf.ts +23 -17
- package/src/png.ts +34 -14
- package/src/png_browser.ts +28 -17
- package/src/svg.ts +34 -26
- package/src/utils.ts +10 -10
package/lib/browser/matrix.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export declare const fillReserved: (matrix: Matrix, ec_level: EcLevel, mask: num
|
|
|
7
7
|
export declare const fillData: (matrix: Matrix, data: Data, mask: number) => void;
|
|
8
8
|
export declare function calculatePenalty(matrix: Matrix): number;
|
|
9
9
|
export declare function getMatrix(data: Data): number[][];
|
|
10
|
+
export declare function clearMatrixCenter(matrix: Matrix, widthPct: number, heightPct: number): Matrix;
|
package/lib/browser/pdf.umd.js
CHANGED
|
@@ -26095,6 +26095,21 @@
|
|
|
26095
26095
|
fillReserved(matrix, data.ec_level, bestMask);
|
|
26096
26096
|
return matrix.map((row) => row.map((cell) => cell & 1));
|
|
26097
26097
|
}
|
|
26098
|
+
function clearMatrixCenter(matrix, widthPct, heightPct) {
|
|
26099
|
+
matrix = matrix.map((x) => x.slice());
|
|
26100
|
+
const mW = matrix.length;
|
|
26101
|
+
const cW = Math.ceil(((mW * widthPct) / 100 + (mW % 2)) / 2) * 2 - (mW % 2);
|
|
26102
|
+
const mH = matrix[0]?.length ?? 0;
|
|
26103
|
+
const cH = Math.ceil(((mH * heightPct) / 100 + (mH % 2)) / 2) * 2 - (mH % 2);
|
|
26104
|
+
const clearStartX = Math.round((mW - cW) / 2);
|
|
26105
|
+
const clearStartY = Math.round((mH - cH) / 2);
|
|
26106
|
+
for (let x = clearStartX; x < clearStartX + cW; x += 1) {
|
|
26107
|
+
for (let y = clearStartY; y < clearStartY + cH; y += 1) {
|
|
26108
|
+
matrix[x][y] = 0;
|
|
26109
|
+
}
|
|
26110
|
+
}
|
|
26111
|
+
return matrix;
|
|
26112
|
+
}
|
|
26098
26113
|
|
|
26099
26114
|
const EC_LEVELS = ["L", "M", "Q", "H"];
|
|
26100
26115
|
function getTemplate(message, ec_level) {
|
|
@@ -26705,7 +26720,7 @@
|
|
|
26705
26720
|
rectangle.push(`M ${leftX} ${topY + borderRadius}`);
|
|
26706
26721
|
rectangle.push(`L ${leftX} ${bottomY - borderRadius}`);
|
|
26707
26722
|
if (borderRadius > 0) {
|
|
26708
|
-
rectangle.push(`A ${borderRadius} ${borderRadius} 0 0 0 ${leftX + borderRadius} ${bottomY}
|
|
26723
|
+
rectangle.push(`A ${borderRadius} ${borderRadius} 0 0 0 ${leftX + borderRadius} ${bottomY}`);
|
|
26709
26724
|
}
|
|
26710
26725
|
rectangle.push(`L ${rightX - borderRadius} ${bottomY}`);
|
|
26711
26726
|
if (borderRadius > 0) {
|
|
@@ -26750,7 +26765,10 @@
|
|
|
26750
26765
|
const textDec = new TextDecoder();
|
|
26751
26766
|
async function getPDF(text, inOptions) {
|
|
26752
26767
|
const options = getOptions(inOptions);
|
|
26753
|
-
|
|
26768
|
+
let matrix = QR(text, options.ec_level, options.parse_url);
|
|
26769
|
+
if (options.logo && options.logoWidth && options.logoHeight) {
|
|
26770
|
+
matrix = clearMatrixCenter(matrix, options.logoWidth, options.logoHeight);
|
|
26771
|
+
}
|
|
26754
26772
|
return PDF({ matrix, ...options });
|
|
26755
26773
|
}
|
|
26756
26774
|
function colorToRGB(color) {
|
|
@@ -26758,29 +26776,27 @@
|
|
|
26758
26776
|
const [red, green, blue] = colorString.get.rgb(color);
|
|
26759
26777
|
return [red / 255, green / 255, blue / 255];
|
|
26760
26778
|
}
|
|
26761
|
-
return [
|
|
26762
|
-
((color >>> 24) % 256) / 255,
|
|
26763
|
-
((color >>> 16) % 256) / 255,
|
|
26764
|
-
((color >>> 8) % 256) / 255,
|
|
26765
|
-
];
|
|
26779
|
+
return [((color >>> 24) % 256) / 255, ((color >>> 16) % 256) / 255, ((color >>> 8) % 256) / 255];
|
|
26766
26780
|
}
|
|
26767
26781
|
function getOpacity(color) {
|
|
26768
26782
|
if (typeof color === "string") {
|
|
26769
26783
|
return colorString.get.rgb(color)[3];
|
|
26770
26784
|
}
|
|
26771
|
-
return (
|
|
26785
|
+
return (color % 256) / 255;
|
|
26772
26786
|
}
|
|
26773
26787
|
async function PDF({ matrix, margin, logo, logoWidth, logoHeight, color, bgColor, borderRadius, }) {
|
|
26774
26788
|
const size = 9;
|
|
26789
|
+
const marginPx = margin * size;
|
|
26790
|
+
const matrixSizePx = matrix.length * size;
|
|
26791
|
+
const imageSizePx = matrixSizePx + 2 * marginPx;
|
|
26775
26792
|
const document = await PDFDocument.create();
|
|
26776
|
-
const
|
|
26777
|
-
const page = document.addPage([pageSize, pageSize]);
|
|
26793
|
+
const page = document.addPage([imageSizePx, imageSizePx]);
|
|
26778
26794
|
page.drawSquare({
|
|
26779
|
-
size:
|
|
26795
|
+
size: imageSizePx,
|
|
26780
26796
|
color: rgb(...colorToRGB(bgColor)),
|
|
26781
26797
|
});
|
|
26782
26798
|
page.moveTo(0, page.getHeight());
|
|
26783
|
-
const path = getSVGPath(matrix, size,
|
|
26799
|
+
const path = getSVGPath(matrix, size, marginPx, borderRadius);
|
|
26784
26800
|
page.drawSvgPath(path, {
|
|
26785
26801
|
color: rgb(...colorToRGB(color)),
|
|
26786
26802
|
opacity: getOpacity(color),
|
|
@@ -26796,12 +26812,13 @@
|
|
|
26796
26812
|
else {
|
|
26797
26813
|
logoData = await document.embedJpg(logo);
|
|
26798
26814
|
}
|
|
26815
|
+
const logoWidthPx = (logoWidth / 100) * matrixSizePx;
|
|
26816
|
+
const logoHeightPx = (logoHeight / 100) * matrixSizePx;
|
|
26799
26817
|
page.drawImage(logoData, {
|
|
26800
|
-
x:
|
|
26801
|
-
y:
|
|
26802
|
-
|
|
26803
|
-
|
|
26804
|
-
height: (logoHeight / 100) * page.getHeight(),
|
|
26818
|
+
x: (imageSizePx - logoWidthPx) / 2,
|
|
26819
|
+
y: (imageSizePx - logoHeightPx) / 2,
|
|
26820
|
+
width: logoWidthPx,
|
|
26821
|
+
height: logoHeightPx,
|
|
26805
26822
|
});
|
|
26806
26823
|
}
|
|
26807
26824
|
return document.save();
|