qreator 9.5.1 → 9.5.2
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/README.md +1 -1
- package/lib/browser/pdf.umd.js +96 -36
- package/lib/browser/pdf.umd.js.map +1 -1
- package/lib/pdf.js +37 -2
- package/lib/pdf.js.map +1 -1
- package/package.json +1 -1
- package/src/pdf.ts +48 -2
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ QR Code generator for browser and node.js with tree shaking and logo support
|
|
|
13
13
|
- support UTF-8
|
|
14
14
|
- supports color customization
|
|
15
15
|
- supports logos
|
|
16
|
+
- supports border-radius
|
|
16
17
|
- tree shaking support
|
|
17
18
|
- browser / node.js
|
|
18
19
|
|
|
@@ -89,4 +90,3 @@ getSVG with logo x 2,494 ops/sec ±0.19% (88 runs sampled)
|
|
|
89
90
|
## TODO
|
|
90
91
|
|
|
91
92
|
- Use lighter versions of PDF library
|
|
92
|
-
- Background
|
package/lib/browser/pdf.umd.js
CHANGED
|
@@ -9312,7 +9312,7 @@
|
|
|
9312
9312
|
PDFOperatorNames["BeginCompatibilitySection"] = "BX";
|
|
9313
9313
|
PDFOperatorNames["EndCompatibilitySection"] = "EX";
|
|
9314
9314
|
})(PDFOperatorNames || (PDFOperatorNames = {}));
|
|
9315
|
-
var
|
|
9315
|
+
var PDFOperatorNames$1 = PDFOperatorNames;
|
|
9316
9316
|
|
|
9317
9317
|
var PDFFlateStream = /** @class */ (function (_super) {
|
|
9318
9318
|
__extends(PDFFlateStream, _super);
|
|
@@ -9564,7 +9564,7 @@
|
|
|
9564
9564
|
return this.pushGraphicsStateContentStreamRef;
|
|
9565
9565
|
}
|
|
9566
9566
|
var dict = this.obj({});
|
|
9567
|
-
var op = PDFOperator.of(
|
|
9567
|
+
var op = PDFOperator.of(PDFOperatorNames$1.PushGraphicsState);
|
|
9568
9568
|
var stream = PDFContentStream.of(dict, [op]);
|
|
9569
9569
|
this.pushGraphicsStateContentStreamRef = this.register(stream);
|
|
9570
9570
|
return this.pushGraphicsStateContentStreamRef;
|
|
@@ -9580,7 +9580,7 @@
|
|
|
9580
9580
|
return this.popGraphicsStateContentStreamRef;
|
|
9581
9581
|
}
|
|
9582
9582
|
var dict = this.obj({});
|
|
9583
|
-
var op = PDFOperator.of(
|
|
9583
|
+
var op = PDFOperator.of(PDFOperatorNames$1.PopGraphicsState);
|
|
9584
9584
|
var stream = PDFContentStream.of(dict, [op]);
|
|
9585
9585
|
this.popGraphicsStateContentStreamRef = this.register(stream);
|
|
9586
9586
|
return this.popGraphicsStateContentStreamRef;
|
|
@@ -16734,11 +16734,11 @@
|
|
|
16734
16734
|
};
|
|
16735
16735
|
|
|
16736
16736
|
/* ==================== Clipping Path Operators ==================== */
|
|
16737
|
-
var clip = function () { return PDFOperator.of(
|
|
16737
|
+
var clip = function () { return PDFOperator.of(PDFOperatorNames$1.ClipNonZero); };
|
|
16738
16738
|
/* ==================== Graphics State Operators ==================== */
|
|
16739
16739
|
var cos = Math.cos, sin = Math.sin, tan = Math.tan;
|
|
16740
16740
|
var concatTransformationMatrix = function (a, b, c, d, e, f) {
|
|
16741
|
-
return PDFOperator.of(
|
|
16741
|
+
return PDFOperator.of(PDFOperatorNames$1.ConcatTransformationMatrix, [
|
|
16742
16742
|
asPDFNumber(a),
|
|
16743
16743
|
asPDFNumber(b),
|
|
16744
16744
|
asPDFNumber(c),
|
|
@@ -16763,7 +16763,7 @@
|
|
|
16763
16763
|
return concatTransformationMatrix(1, tan(asNumber(xSkewAngle)), tan(asNumber(ySkewAngle)), 1, 0, 0);
|
|
16764
16764
|
};
|
|
16765
16765
|
var setDashPattern = function (dashArray, dashPhase) {
|
|
16766
|
-
return PDFOperator.of(
|
|
16766
|
+
return PDFOperator.of(PDFOperatorNames$1.SetLineDashPattern, [
|
|
16767
16767
|
"[" + dashArray.map(asPDFNumber).join(' ') + "]",
|
|
16768
16768
|
asPDFNumber(dashPhase),
|
|
16769
16769
|
]);
|
|
@@ -16775,7 +16775,7 @@
|
|
|
16775
16775
|
LineCapStyle[LineCapStyle["Projecting"] = 2] = "Projecting";
|
|
16776
16776
|
})(LineCapStyle || (LineCapStyle = {}));
|
|
16777
16777
|
var setLineCap = function (style) {
|
|
16778
|
-
return PDFOperator.of(
|
|
16778
|
+
return PDFOperator.of(PDFOperatorNames$1.SetLineCapStyle, [asPDFNumber(style)]);
|
|
16779
16779
|
};
|
|
16780
16780
|
var LineJoinStyle;
|
|
16781
16781
|
(function (LineJoinStyle) {
|
|
@@ -16784,16 +16784,16 @@
|
|
|
16784
16784
|
LineJoinStyle[LineJoinStyle["Bevel"] = 2] = "Bevel";
|
|
16785
16785
|
})(LineJoinStyle || (LineJoinStyle = {}));
|
|
16786
16786
|
var setGraphicsState = function (state) {
|
|
16787
|
-
return PDFOperator.of(
|
|
16787
|
+
return PDFOperator.of(PDFOperatorNames$1.SetGraphicsStateParams, [asPDFName(state)]);
|
|
16788
16788
|
};
|
|
16789
|
-
var pushGraphicsState = function () { return PDFOperator.of(
|
|
16790
|
-
var popGraphicsState = function () { return PDFOperator.of(
|
|
16789
|
+
var pushGraphicsState = function () { return PDFOperator.of(PDFOperatorNames$1.PushGraphicsState); };
|
|
16790
|
+
var popGraphicsState = function () { return PDFOperator.of(PDFOperatorNames$1.PopGraphicsState); };
|
|
16791
16791
|
var setLineWidth = function (width) {
|
|
16792
|
-
return PDFOperator.of(
|
|
16792
|
+
return PDFOperator.of(PDFOperatorNames$1.SetLineWidth, [asPDFNumber(width)]);
|
|
16793
16793
|
};
|
|
16794
16794
|
/* ==================== Path Construction Operators ==================== */
|
|
16795
16795
|
var appendBezierCurve = function (x1, y1, x2, y2, x3, y3) {
|
|
16796
|
-
return PDFOperator.of(
|
|
16796
|
+
return PDFOperator.of(PDFOperatorNames$1.AppendBezierCurve, [
|
|
16797
16797
|
asPDFNumber(x1),
|
|
16798
16798
|
asPDFNumber(y1),
|
|
16799
16799
|
asPDFNumber(x2),
|
|
@@ -16803,37 +16803,37 @@
|
|
|
16803
16803
|
]);
|
|
16804
16804
|
};
|
|
16805
16805
|
var appendQuadraticCurve = function (x1, y1, x2, y2) {
|
|
16806
|
-
return PDFOperator.of(
|
|
16806
|
+
return PDFOperator.of(PDFOperatorNames$1.CurveToReplicateInitialPoint, [
|
|
16807
16807
|
asPDFNumber(x1),
|
|
16808
16808
|
asPDFNumber(y1),
|
|
16809
16809
|
asPDFNumber(x2),
|
|
16810
16810
|
asPDFNumber(y2),
|
|
16811
16811
|
]);
|
|
16812
16812
|
};
|
|
16813
|
-
var closePath = function () { return PDFOperator.of(
|
|
16813
|
+
var closePath = function () { return PDFOperator.of(PDFOperatorNames$1.ClosePath); };
|
|
16814
16814
|
var moveTo = function (xPos, yPos) {
|
|
16815
|
-
return PDFOperator.of(
|
|
16815
|
+
return PDFOperator.of(PDFOperatorNames$1.MoveTo, [asPDFNumber(xPos), asPDFNumber(yPos)]);
|
|
16816
16816
|
};
|
|
16817
16817
|
var lineTo = function (xPos, yPos) {
|
|
16818
|
-
return PDFOperator.of(
|
|
16818
|
+
return PDFOperator.of(PDFOperatorNames$1.LineTo, [asPDFNumber(xPos), asPDFNumber(yPos)]);
|
|
16819
16819
|
};
|
|
16820
16820
|
/* ==================== Path Painting Operators ==================== */
|
|
16821
|
-
var stroke = function () { return PDFOperator.of(
|
|
16822
|
-
var fill = function () { return PDFOperator.of(
|
|
16823
|
-
var fillAndStroke = function () { return PDFOperator.of(
|
|
16824
|
-
var endPath = function () { return PDFOperator.of(
|
|
16821
|
+
var stroke = function () { return PDFOperator.of(PDFOperatorNames$1.StrokePath); };
|
|
16822
|
+
var fill = function () { return PDFOperator.of(PDFOperatorNames$1.FillNonZero); };
|
|
16823
|
+
var fillAndStroke = function () { return PDFOperator.of(PDFOperatorNames$1.FillNonZeroAndStroke); };
|
|
16824
|
+
var endPath = function () { return PDFOperator.of(PDFOperatorNames$1.EndPath); };
|
|
16825
16825
|
/* ==================== Text Positioning Operators ==================== */
|
|
16826
|
-
var nextLine = function () { return PDFOperator.of(
|
|
16826
|
+
var nextLine = function () { return PDFOperator.of(PDFOperatorNames$1.NextLine); };
|
|
16827
16827
|
/* ==================== Text Showing Operators ==================== */
|
|
16828
16828
|
var showText = function (text) {
|
|
16829
|
-
return PDFOperator.of(
|
|
16829
|
+
return PDFOperator.of(PDFOperatorNames$1.ShowText, [text]);
|
|
16830
16830
|
};
|
|
16831
16831
|
/* ==================== Text State Operators ==================== */
|
|
16832
|
-
var beginText = function () { return PDFOperator.of(
|
|
16833
|
-
var endText = function () { return PDFOperator.of(
|
|
16834
|
-
var setFontAndSize = function (name, size) { return PDFOperator.of(
|
|
16832
|
+
var beginText = function () { return PDFOperator.of(PDFOperatorNames$1.BeginText); };
|
|
16833
|
+
var endText = function () { return PDFOperator.of(PDFOperatorNames$1.EndText); };
|
|
16834
|
+
var setFontAndSize = function (name, size) { return PDFOperator.of(PDFOperatorNames$1.SetFontAndSize, [asPDFName(name), asPDFNumber(size)]); };
|
|
16835
16835
|
var setLineHeight = function (lineHeight) {
|
|
16836
|
-
return PDFOperator.of(
|
|
16836
|
+
return PDFOperator.of(PDFOperatorNames$1.SetTextLineHeight, [asPDFNumber(lineHeight)]);
|
|
16837
16837
|
};
|
|
16838
16838
|
var TextRenderingMode;
|
|
16839
16839
|
(function (TextRenderingMode) {
|
|
@@ -16847,7 +16847,7 @@
|
|
|
16847
16847
|
TextRenderingMode[TextRenderingMode["Clip"] = 7] = "Clip";
|
|
16848
16848
|
})(TextRenderingMode || (TextRenderingMode = {}));
|
|
16849
16849
|
var setTextMatrix = function (a, b, c, d, e, f) {
|
|
16850
|
-
return PDFOperator.of(
|
|
16850
|
+
return PDFOperator.of(PDFOperatorNames$1.SetTextMatrix, [
|
|
16851
16851
|
asPDFNumber(a),
|
|
16852
16852
|
asPDFNumber(b),
|
|
16853
16853
|
asPDFNumber(c),
|
|
@@ -16861,31 +16861,31 @@
|
|
|
16861
16861
|
};
|
|
16862
16862
|
/* ==================== XObject Operator ==================== */
|
|
16863
16863
|
var drawObject = function (name) {
|
|
16864
|
-
return PDFOperator.of(
|
|
16864
|
+
return PDFOperator.of(PDFOperatorNames$1.DrawObject, [asPDFName(name)]);
|
|
16865
16865
|
};
|
|
16866
16866
|
/* ==================== Color Operators ==================== */
|
|
16867
16867
|
var setFillingGrayscaleColor = function (gray) {
|
|
16868
|
-
return PDFOperator.of(
|
|
16868
|
+
return PDFOperator.of(PDFOperatorNames$1.NonStrokingColorGray, [asPDFNumber(gray)]);
|
|
16869
16869
|
};
|
|
16870
16870
|
var setStrokingGrayscaleColor = function (gray) {
|
|
16871
|
-
return PDFOperator.of(
|
|
16871
|
+
return PDFOperator.of(PDFOperatorNames$1.StrokingColorGray, [asPDFNumber(gray)]);
|
|
16872
16872
|
};
|
|
16873
16873
|
var setFillingRgbColor = function (red, green, blue) {
|
|
16874
|
-
return PDFOperator.of(
|
|
16874
|
+
return PDFOperator.of(PDFOperatorNames$1.NonStrokingColorRgb, [
|
|
16875
16875
|
asPDFNumber(red),
|
|
16876
16876
|
asPDFNumber(green),
|
|
16877
16877
|
asPDFNumber(blue),
|
|
16878
16878
|
]);
|
|
16879
16879
|
};
|
|
16880
16880
|
var setStrokingRgbColor = function (red, green, blue) {
|
|
16881
|
-
return PDFOperator.of(
|
|
16881
|
+
return PDFOperator.of(PDFOperatorNames$1.StrokingColorRgb, [
|
|
16882
16882
|
asPDFNumber(red),
|
|
16883
16883
|
asPDFNumber(green),
|
|
16884
16884
|
asPDFNumber(blue),
|
|
16885
16885
|
]);
|
|
16886
16886
|
};
|
|
16887
16887
|
var setFillingCmykColor = function (cyan, magenta, yellow, key) {
|
|
16888
|
-
return PDFOperator.of(
|
|
16888
|
+
return PDFOperator.of(PDFOperatorNames$1.NonStrokingColorCmyk, [
|
|
16889
16889
|
asPDFNumber(cyan),
|
|
16890
16890
|
asPDFNumber(magenta),
|
|
16891
16891
|
asPDFNumber(yellow),
|
|
@@ -16893,7 +16893,7 @@
|
|
|
16893
16893
|
]);
|
|
16894
16894
|
};
|
|
16895
16895
|
var setStrokingCmykColor = function (cyan, magenta, yellow, key) {
|
|
16896
|
-
return PDFOperator.of(
|
|
16896
|
+
return PDFOperator.of(PDFOperatorNames$1.StrokingColorCmyk, [
|
|
16897
16897
|
asPDFNumber(cyan),
|
|
16898
16898
|
asPDFNumber(magenta),
|
|
16899
16899
|
asPDFNumber(yellow),
|
|
@@ -16902,9 +16902,9 @@
|
|
|
16902
16902
|
};
|
|
16903
16903
|
/* ==================== Marked Content Operators ==================== */
|
|
16904
16904
|
var beginMarkedContent = function (tag) {
|
|
16905
|
-
return PDFOperator.of(
|
|
16905
|
+
return PDFOperator.of(PDFOperatorNames$1.BeginMarkedContent, [asPDFName(tag)]);
|
|
16906
16906
|
};
|
|
16907
|
-
var endMarkedContent = function () { return PDFOperator.of(
|
|
16907
|
+
var endMarkedContent = function () { return PDFOperator.of(PDFOperatorNames$1.EndMarkedContent); };
|
|
16908
16908
|
|
|
16909
16909
|
var ColorTypes;
|
|
16910
16910
|
(function (ColorTypes) {
|
|
@@ -26908,6 +26908,31 @@
|
|
|
26908
26908
|
const defaults = type === "png" ? BITMAP_OPTIONS : VECTOR_OPTIONS;
|
|
26909
26909
|
return { ...defaults, ...inOptions };
|
|
26910
26910
|
}
|
|
26911
|
+
function getFindersSVGPath(matrix, size = 0, margin = 0, borderRadius = 0) {
|
|
26912
|
+
const matrixSize = matrix.length * size + margin * 2;
|
|
26913
|
+
let finderSize = 8;
|
|
26914
|
+
let finderEnd = finderSize - 1;
|
|
26915
|
+
const sides = [[0, 0], [1, 0], [0, 1]];
|
|
26916
|
+
const rectangles = [];
|
|
26917
|
+
for (const side of sides) {
|
|
26918
|
+
const signs = side.map(sidePoint => sidePoint == 0 ? 1 : -1);
|
|
26919
|
+
for (const offset of [0, 1, 2]) {
|
|
26920
|
+
let corners = [
|
|
26921
|
+
[matrixSize * side[0] + signs[0] * (margin + size * offset), matrixSize * side[1] + signs[1] * (margin + size * offset)],
|
|
26922
|
+
[matrixSize * side[0] + signs[0] * (margin + size * (finderEnd - offset)), matrixSize * side[1] + signs[1] * (margin + size * (finderEnd - offset))],
|
|
26923
|
+
];
|
|
26924
|
+
let rectangle = [
|
|
26925
|
+
'M', corners[0][0], corners[0][1],
|
|
26926
|
+
'L', corners[0][0], corners[1][1],
|
|
26927
|
+
'L', corners[1][0], corners[1][1],
|
|
26928
|
+
'L', corners[1][0], corners[0][1],
|
|
26929
|
+
'z',
|
|
26930
|
+
];
|
|
26931
|
+
rectangles.push(...rectangle);
|
|
26932
|
+
}
|
|
26933
|
+
}
|
|
26934
|
+
return rectangles.join(" ");
|
|
26935
|
+
}
|
|
26911
26936
|
function getDotsSVGPath(matrix, size, margin = 0, borderRadius = 0) {
|
|
26912
26937
|
let rectangles = [];
|
|
26913
26938
|
for (let x = 0; x < matrix.length; x++) {
|
|
@@ -26987,6 +27012,32 @@
|
|
|
26987
27012
|
}
|
|
26988
27013
|
return (color % 256) / 255;
|
|
26989
27014
|
}
|
|
27015
|
+
function patchContentStream(page) {
|
|
27016
|
+
page.prevGetContentStream = page.getContentStream;
|
|
27017
|
+
page.getContentStream = (...args) => {
|
|
27018
|
+
const contentStream = page.prevGetContentStream(...args);
|
|
27019
|
+
contentStream.prevPush = contentStream.push;
|
|
27020
|
+
contentStream.push = (...operators) => {
|
|
27021
|
+
contentStream.prevPush(...operators.map((op) => {
|
|
27022
|
+
if (op.name == PDFOperatorNames$1.FillNonZeroAndStroke) {
|
|
27023
|
+
return PDFOperator.of(PDFOperatorNames$1.FillEvenOddAndStroke, op.args);
|
|
27024
|
+
}
|
|
27025
|
+
if (op.name == PDFOperatorNames$1.FillNonZero) {
|
|
27026
|
+
return PDFOperator.of(PDFOperatorNames$1.FillEvenOdd, op.args);
|
|
27027
|
+
}
|
|
27028
|
+
if (op.name == PDFOperatorNames$1.FillNonZeroAndStroke) {
|
|
27029
|
+
return PDFOperator.of(PDFOperatorNames$1.FillEvenOddAndStroke, op.args);
|
|
27030
|
+
}
|
|
27031
|
+
return op;
|
|
27032
|
+
}));
|
|
27033
|
+
};
|
|
27034
|
+
return contentStream;
|
|
27035
|
+
};
|
|
27036
|
+
}
|
|
27037
|
+
function revertContentStream(page) {
|
|
27038
|
+
page.getContentStream = page.prevGetContentStream;
|
|
27039
|
+
page.contentStream.push = page.contentStream.prevPush;
|
|
27040
|
+
}
|
|
26990
27041
|
async function PDF({ matrix, margin, logo, logoWidth, logoHeight, color, bgColor, borderRadius, }) {
|
|
26991
27042
|
const size = 9;
|
|
26992
27043
|
const marginPx = margin * size;
|
|
@@ -27006,6 +27057,15 @@
|
|
|
27006
27057
|
borderColor: rgb(...colorToRGB(color)),
|
|
27007
27058
|
borderOpacity: getOpacity(color),
|
|
27008
27059
|
});
|
|
27060
|
+
const findersPath = getFindersSVGPath(matrix, size, marginPx, borderRadius);
|
|
27061
|
+
patchContentStream(page);
|
|
27062
|
+
page.drawSvgPath(findersPath, {
|
|
27063
|
+
color: rgb(...colorToRGB(color)),
|
|
27064
|
+
opacity: getOpacity(color),
|
|
27065
|
+
borderColor: rgb(...colorToRGB(color)),
|
|
27066
|
+
borderOpacity: getOpacity(color),
|
|
27067
|
+
});
|
|
27068
|
+
revertContentStream(page);
|
|
27009
27069
|
if (logo) {
|
|
27010
27070
|
let logoData;
|
|
27011
27071
|
const header = new Uint8Array(logo.slice(0, 4));
|