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.
@@ -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;
@@ -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
- const matrix = QR(text, options.ec_level, options.parse_url);
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 ((color % 256) / 255);
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 pageSize = (matrix.length + 2 * margin) * size;
26777
- const page = document.addPage([pageSize, pageSize]);
26793
+ const page = document.addPage([imageSizePx, imageSizePx]);
26778
26794
  page.drawSquare({
26779
- size: pageSize,
26795
+ size: imageSizePx,
26780
26796
  color: rgb(...colorToRGB(bgColor)),
26781
26797
  });
26782
26798
  page.moveTo(0, page.getHeight());
26783
- const path = getSVGPath(matrix, size, margin * size, borderRadius);
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: page.getWidth() / 2 - (logoWidth / 100) * (page.getWidth() / 2),
26801
- y: page.getHeight() / 2 -
26802
- (logoHeight / 100) * (page.getWidth() / 2),
26803
- width: (logoWidth / 100) * page.getWidth(),
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();