qr-code-styling-node 1.12.0 → 1.14.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/README.md +68 -0
- package/lib/core/QRCanvas.d.ts +1 -0
- package/lib/core/QRSVG.d.ts +1 -0
- package/lib/qr-code-styling.common.js +1 -1
- package/lib/qr-code-styling.common.js.map +1 -1
- package/lib/qr-code-styling.js +1 -1
- package/lib/qr-code-styling.js.map +1 -1
- package/lib/qr-code-styling.mjs +161 -98
- package/lib/qr-code-styling.mjs.map +3 -3
- package/lib/react/index.d.ts +20 -0
- package/lib/react.cjs +101 -0
- package/lib/react.cjs.map +7 -0
- package/lib/react.mjs +70 -0
- package/lib/react.mjs.map +7 -0
- package/lib/tools/plugins.d.ts +7 -0
- package/lib/tools/sameOptions.d.ts +9 -0
- package/lib/types/index.d.ts +36 -0
- package/lib/vue/index.d.ts +27 -0
- package/lib/vue.cjs +122 -0
- package/lib/vue.cjs.map +7 -0
- package/lib/vue.mjs +91 -0
- package/lib/vue.mjs.map +7 -0
- package/package.json +28 -1
package/lib/qr-code-styling.mjs
CHANGED
|
@@ -851,37 +851,6 @@ function getQRArea(options, count) {
|
|
|
851
851
|
};
|
|
852
852
|
}
|
|
853
853
|
|
|
854
|
-
// src/tools/cornerTypes.ts
|
|
855
|
-
var SOLID_CORNER_DOT_TYPES = ["diamond", "small-square", "vertical-lines", "horizontal-lines"];
|
|
856
|
-
var ROUND_DOT_TYPES = [
|
|
857
|
-
"dots",
|
|
858
|
-
"rounded",
|
|
859
|
-
"extra-rounded",
|
|
860
|
-
"classy-rounded",
|
|
861
|
-
"fluid",
|
|
862
|
-
"wave",
|
|
863
|
-
"blob",
|
|
864
|
-
"circuit"
|
|
865
|
-
];
|
|
866
|
-
var SOLID_ROUND_DOT_TYPES = ["fluid", "wave", "blob", "circuit"];
|
|
867
|
-
var needsSolidAlignment = (type) => SOLID_ROUND_DOT_TYPES.indexOf(type) !== -1 || SOLID_CORNER_DOT_TYPES.indexOf(type) !== -1;
|
|
868
|
-
function getCornerTypes(options) {
|
|
869
|
-
var _a, _b, _c, _d, _e;
|
|
870
|
-
const type = options.dotsOptions.type;
|
|
871
|
-
if (((_a = options.art) == null ? void 0 : _a.mode) === "blend" || options.shape === "circle" || SOLID_ROUND_DOT_TYPES.indexOf(type) !== -1) {
|
|
872
|
-
const round2 = ROUND_DOT_TYPES.indexOf(type) !== -1;
|
|
873
|
-
return {
|
|
874
|
-
square: ((_b = options.cornersSquareOptions) == null ? void 0 : _b.type) || (round2 ? "rounded" : "square"),
|
|
875
|
-
dot: ((_c = options.cornersDotOptions) == null ? void 0 : _c.type) || (round2 ? "rounded" : "square")
|
|
876
|
-
};
|
|
877
|
-
}
|
|
878
|
-
const solid = SOLID_CORNER_DOT_TYPES.indexOf(type) !== -1;
|
|
879
|
-
return {
|
|
880
|
-
square: ((_d = options.cornersSquareOptions) == null ? void 0 : _d.type) || (solid ? "square" : void 0),
|
|
881
|
-
dot: ((_e = options.cornersDotOptions) == null ? void 0 : _e.type) || (solid ? "square" : void 0)
|
|
882
|
-
};
|
|
883
|
-
}
|
|
884
|
-
|
|
885
854
|
// src/tools/frameLayout.ts
|
|
886
855
|
var hasFrame = (options) => {
|
|
887
856
|
var _a;
|
|
@@ -941,7 +910,8 @@ var innerOptions = (options, size) => ({
|
|
|
941
910
|
height: size,
|
|
942
911
|
margin: 0,
|
|
943
912
|
frameOptions: void 0,
|
|
944
|
-
labelOptions: void 0
|
|
913
|
+
labelOptions: void 0,
|
|
914
|
+
plugins: void 0
|
|
945
915
|
});
|
|
946
916
|
var getLogoPlate = (options, dx, dy, width, height) => {
|
|
947
917
|
var _a;
|
|
@@ -955,6 +925,136 @@ var getLogoPlate = (options, dx, dy, width, height) => {
|
|
|
955
925
|
};
|
|
956
926
|
};
|
|
957
927
|
|
|
928
|
+
// src/tools/sanitizeOptions.ts
|
|
929
|
+
function sanitizeGradient(gradient) {
|
|
930
|
+
const newGradient = { ...gradient };
|
|
931
|
+
if (!newGradient.colorStops || !newGradient.colorStops.length) {
|
|
932
|
+
throw "Field 'colorStops' is required in gradient";
|
|
933
|
+
}
|
|
934
|
+
if (newGradient.rotation) {
|
|
935
|
+
newGradient.rotation = Number(newGradient.rotation);
|
|
936
|
+
} else {
|
|
937
|
+
newGradient.rotation = 0;
|
|
938
|
+
}
|
|
939
|
+
newGradient.colorStops = newGradient.colorStops.map((colorStop) => ({
|
|
940
|
+
...colorStop,
|
|
941
|
+
offset: Number(colorStop.offset)
|
|
942
|
+
}));
|
|
943
|
+
return newGradient;
|
|
944
|
+
}
|
|
945
|
+
function sanitizeOptions(options) {
|
|
946
|
+
const newOptions = { ...options };
|
|
947
|
+
newOptions.width = Number(newOptions.width);
|
|
948
|
+
newOptions.height = Number(newOptions.height);
|
|
949
|
+
newOptions.margin = Number(newOptions.margin);
|
|
950
|
+
newOptions.imageOptions = {
|
|
951
|
+
...newOptions.imageOptions,
|
|
952
|
+
hideBackgroundDots: Boolean(newOptions.imageOptions.hideBackgroundDots),
|
|
953
|
+
imageSize: Number(newOptions.imageOptions.imageSize),
|
|
954
|
+
margin: Number(newOptions.imageOptions.margin)
|
|
955
|
+
};
|
|
956
|
+
if (newOptions.margin > Math.min(newOptions.width, newOptions.height)) {
|
|
957
|
+
newOptions.margin = Math.min(newOptions.width, newOptions.height);
|
|
958
|
+
}
|
|
959
|
+
newOptions.dotsOptions = {
|
|
960
|
+
...newOptions.dotsOptions
|
|
961
|
+
};
|
|
962
|
+
if (newOptions.dotsOptions.gradient) {
|
|
963
|
+
newOptions.dotsOptions.gradient = sanitizeGradient(newOptions.dotsOptions.gradient);
|
|
964
|
+
}
|
|
965
|
+
if (newOptions.cornersSquareOptions) {
|
|
966
|
+
newOptions.cornersSquareOptions = {
|
|
967
|
+
...newOptions.cornersSquareOptions
|
|
968
|
+
};
|
|
969
|
+
if (newOptions.cornersSquareOptions.gradient) {
|
|
970
|
+
newOptions.cornersSquareOptions.gradient = sanitizeGradient(newOptions.cornersSquareOptions.gradient);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
if (newOptions.cornersDotOptions) {
|
|
974
|
+
newOptions.cornersDotOptions = {
|
|
975
|
+
...newOptions.cornersDotOptions
|
|
976
|
+
};
|
|
977
|
+
if (newOptions.cornersDotOptions.gradient) {
|
|
978
|
+
newOptions.cornersDotOptions.gradient = sanitizeGradient(newOptions.cornersDotOptions.gradient);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
if (newOptions.backgroundOptions) {
|
|
982
|
+
newOptions.backgroundOptions = {
|
|
983
|
+
...newOptions.backgroundOptions
|
|
984
|
+
};
|
|
985
|
+
if (newOptions.backgroundOptions.gradient) {
|
|
986
|
+
newOptions.backgroundOptions.gradient = sanitizeGradient(newOptions.backgroundOptions.gradient);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
return newOptions;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
// src/tools/plugins.ts
|
|
993
|
+
function configurePlugins(options) {
|
|
994
|
+
let result = options;
|
|
995
|
+
(options.plugins || []).forEach((plugin) => {
|
|
996
|
+
var _a;
|
|
997
|
+
const changes = (_a = plugin.configure) == null ? void 0 : _a.call(plugin, result);
|
|
998
|
+
if (changes) result = sanitizeOptions(mergeDeep(result, changes));
|
|
999
|
+
});
|
|
1000
|
+
return result;
|
|
1001
|
+
}
|
|
1002
|
+
function getPluginArea(options, count) {
|
|
1003
|
+
let offsetX = 0;
|
|
1004
|
+
let offsetY = 0;
|
|
1005
|
+
let codeOptions = options;
|
|
1006
|
+
if (hasFrame(options)) {
|
|
1007
|
+
const layout = getFrameLayout(options);
|
|
1008
|
+
offsetX = layout.qr.x;
|
|
1009
|
+
offsetY = layout.qr.y;
|
|
1010
|
+
codeOptions = innerOptions(options, layout.qr.size);
|
|
1011
|
+
}
|
|
1012
|
+
const area = getQRArea(codeOptions, count);
|
|
1013
|
+
return {
|
|
1014
|
+
x: area.x + offsetX,
|
|
1015
|
+
y: area.y + offsetY,
|
|
1016
|
+
size: count * area.dotSize,
|
|
1017
|
+
dotSize: area.dotSize,
|
|
1018
|
+
count
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
async function runAfterDraw(options, draw) {
|
|
1022
|
+
for (const plugin of options.plugins || []) {
|
|
1023
|
+
if (plugin.afterDraw) await plugin.afterDraw({ ...draw, options });
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
// src/tools/cornerTypes.ts
|
|
1028
|
+
var SOLID_CORNER_DOT_TYPES = ["diamond", "small-square", "vertical-lines", "horizontal-lines"];
|
|
1029
|
+
var ROUND_DOT_TYPES = [
|
|
1030
|
+
"dots",
|
|
1031
|
+
"rounded",
|
|
1032
|
+
"extra-rounded",
|
|
1033
|
+
"classy-rounded",
|
|
1034
|
+
"fluid",
|
|
1035
|
+
"wave",
|
|
1036
|
+
"blob",
|
|
1037
|
+
"circuit"
|
|
1038
|
+
];
|
|
1039
|
+
var SOLID_ROUND_DOT_TYPES = ["fluid", "wave", "blob", "circuit"];
|
|
1040
|
+
var needsSolidAlignment = (type) => SOLID_ROUND_DOT_TYPES.indexOf(type) !== -1 || SOLID_CORNER_DOT_TYPES.indexOf(type) !== -1;
|
|
1041
|
+
function getCornerTypes(options) {
|
|
1042
|
+
var _a, _b, _c, _d, _e;
|
|
1043
|
+
const type = options.dotsOptions.type;
|
|
1044
|
+
if (((_a = options.art) == null ? void 0 : _a.mode) === "blend" || options.shape === "circle" || SOLID_ROUND_DOT_TYPES.indexOf(type) !== -1) {
|
|
1045
|
+
const round2 = ROUND_DOT_TYPES.indexOf(type) !== -1;
|
|
1046
|
+
return {
|
|
1047
|
+
square: ((_b = options.cornersSquareOptions) == null ? void 0 : _b.type) || (round2 ? "rounded" : "square"),
|
|
1048
|
+
dot: ((_c = options.cornersDotOptions) == null ? void 0 : _c.type) || (round2 ? "rounded" : "square")
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
const solid = SOLID_CORNER_DOT_TYPES.indexOf(type) !== -1;
|
|
1052
|
+
return {
|
|
1053
|
+
square: ((_d = options.cornersSquareOptions) == null ? void 0 : _d.type) || (solid ? "square" : void 0),
|
|
1054
|
+
dot: ((_e = options.cornersDotOptions) == null ? void 0 : _e.type) || (solid ? "square" : void 0)
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
|
|
958
1058
|
// src/art/functionModules.ts
|
|
959
1059
|
var ALIGNMENT_POSITIONS = [
|
|
960
1060
|
[],
|
|
@@ -1529,6 +1629,19 @@ var QRCanvas = class _QRCanvas {
|
|
|
1529
1629
|
}
|
|
1530
1630
|
}
|
|
1531
1631
|
async drawQR(qr) {
|
|
1632
|
+
var _a;
|
|
1633
|
+
await this._drawCode(qr);
|
|
1634
|
+
if ((_a = this._options.plugins) == null ? void 0 : _a.length) {
|
|
1635
|
+
await runAfterDraw(this._options, {
|
|
1636
|
+
type: "canvas",
|
|
1637
|
+
area: getPluginArea(this._options, qr.getModuleCount()),
|
|
1638
|
+
width: this._options.width,
|
|
1639
|
+
height: this._options.height,
|
|
1640
|
+
context: this.context
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
async _drawCode(qr) {
|
|
1532
1645
|
var _a;
|
|
1533
1646
|
if (hasFrame(this._options)) {
|
|
1534
1647
|
this._qr = qr;
|
|
@@ -2722,6 +2835,20 @@ var QRSVG = class _QRSVG {
|
|
|
2722
2835
|
}
|
|
2723
2836
|
}
|
|
2724
2837
|
async drawQR(qr) {
|
|
2838
|
+
var _a;
|
|
2839
|
+
await this._drawCode(qr);
|
|
2840
|
+
if ((_a = this._options.plugins) == null ? void 0 : _a.length) {
|
|
2841
|
+
await runAfterDraw(this._options, {
|
|
2842
|
+
type: "svg",
|
|
2843
|
+
area: getPluginArea(this._options, qr.getModuleCount()),
|
|
2844
|
+
width: this._options.width,
|
|
2845
|
+
height: this._options.height,
|
|
2846
|
+
svg: this._element,
|
|
2847
|
+
document: this._window.document
|
|
2848
|
+
});
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
async _drawCode(qr) {
|
|
2725
2852
|
if (hasFrame(this._options)) {
|
|
2726
2853
|
this._qr = qr;
|
|
2727
2854
|
return this._drawFramed(qr);
|
|
@@ -3303,70 +3430,6 @@ var defaultOptions = {
|
|
|
3303
3430
|
};
|
|
3304
3431
|
var QROptions_default = defaultOptions;
|
|
3305
3432
|
|
|
3306
|
-
// src/tools/sanitizeOptions.ts
|
|
3307
|
-
function sanitizeGradient(gradient) {
|
|
3308
|
-
const newGradient = { ...gradient };
|
|
3309
|
-
if (!newGradient.colorStops || !newGradient.colorStops.length) {
|
|
3310
|
-
throw "Field 'colorStops' is required in gradient";
|
|
3311
|
-
}
|
|
3312
|
-
if (newGradient.rotation) {
|
|
3313
|
-
newGradient.rotation = Number(newGradient.rotation);
|
|
3314
|
-
} else {
|
|
3315
|
-
newGradient.rotation = 0;
|
|
3316
|
-
}
|
|
3317
|
-
newGradient.colorStops = newGradient.colorStops.map((colorStop) => ({
|
|
3318
|
-
...colorStop,
|
|
3319
|
-
offset: Number(colorStop.offset)
|
|
3320
|
-
}));
|
|
3321
|
-
return newGradient;
|
|
3322
|
-
}
|
|
3323
|
-
function sanitizeOptions(options) {
|
|
3324
|
-
const newOptions = { ...options };
|
|
3325
|
-
newOptions.width = Number(newOptions.width);
|
|
3326
|
-
newOptions.height = Number(newOptions.height);
|
|
3327
|
-
newOptions.margin = Number(newOptions.margin);
|
|
3328
|
-
newOptions.imageOptions = {
|
|
3329
|
-
...newOptions.imageOptions,
|
|
3330
|
-
hideBackgroundDots: Boolean(newOptions.imageOptions.hideBackgroundDots),
|
|
3331
|
-
imageSize: Number(newOptions.imageOptions.imageSize),
|
|
3332
|
-
margin: Number(newOptions.imageOptions.margin)
|
|
3333
|
-
};
|
|
3334
|
-
if (newOptions.margin > Math.min(newOptions.width, newOptions.height)) {
|
|
3335
|
-
newOptions.margin = Math.min(newOptions.width, newOptions.height);
|
|
3336
|
-
}
|
|
3337
|
-
newOptions.dotsOptions = {
|
|
3338
|
-
...newOptions.dotsOptions
|
|
3339
|
-
};
|
|
3340
|
-
if (newOptions.dotsOptions.gradient) {
|
|
3341
|
-
newOptions.dotsOptions.gradient = sanitizeGradient(newOptions.dotsOptions.gradient);
|
|
3342
|
-
}
|
|
3343
|
-
if (newOptions.cornersSquareOptions) {
|
|
3344
|
-
newOptions.cornersSquareOptions = {
|
|
3345
|
-
...newOptions.cornersSquareOptions
|
|
3346
|
-
};
|
|
3347
|
-
if (newOptions.cornersSquareOptions.gradient) {
|
|
3348
|
-
newOptions.cornersSquareOptions.gradient = sanitizeGradient(newOptions.cornersSquareOptions.gradient);
|
|
3349
|
-
}
|
|
3350
|
-
}
|
|
3351
|
-
if (newOptions.cornersDotOptions) {
|
|
3352
|
-
newOptions.cornersDotOptions = {
|
|
3353
|
-
...newOptions.cornersDotOptions
|
|
3354
|
-
};
|
|
3355
|
-
if (newOptions.cornersDotOptions.gradient) {
|
|
3356
|
-
newOptions.cornersDotOptions.gradient = sanitizeGradient(newOptions.cornersDotOptions.gradient);
|
|
3357
|
-
}
|
|
3358
|
-
}
|
|
3359
|
-
if (newOptions.backgroundOptions) {
|
|
3360
|
-
newOptions.backgroundOptions = {
|
|
3361
|
-
...newOptions.backgroundOptions
|
|
3362
|
-
};
|
|
3363
|
-
if (newOptions.backgroundOptions.gradient) {
|
|
3364
|
-
newOptions.backgroundOptions.gradient = sanitizeGradient(newOptions.backgroundOptions.gradient);
|
|
3365
|
-
}
|
|
3366
|
-
}
|
|
3367
|
-
return newOptions;
|
|
3368
|
-
}
|
|
3369
|
-
|
|
3370
3433
|
// src/core/QRCodeStyling.ts
|
|
3371
3434
|
import qrcode from "qrcode-generator";
|
|
3372
3435
|
|
|
@@ -3457,7 +3520,7 @@ var payloads_default = { wifi, vCard, event, email, phone, sms, geo };
|
|
|
3457
3520
|
// src/core/QRCodeStyling.ts
|
|
3458
3521
|
var _QRCodeStyling = class _QRCodeStyling {
|
|
3459
3522
|
constructor(options) {
|
|
3460
|
-
this._options = options ? sanitizeOptions(mergeDeep(QROptions_default, options)) : QROptions_default;
|
|
3523
|
+
this._options = options ? configurePlugins(sanitizeOptions(mergeDeep(QROptions_default, options))) : QROptions_default;
|
|
3461
3524
|
this.update();
|
|
3462
3525
|
}
|
|
3463
3526
|
/** Canvas output needs a browser canvas or node-canvas. */
|
|
@@ -3503,7 +3566,7 @@ var _QRCodeStyling = class _QRCodeStyling {
|
|
|
3503
3566
|
}
|
|
3504
3567
|
update(options) {
|
|
3505
3568
|
_QRCodeStyling._clearContainer(this._container);
|
|
3506
|
-
this._options = options ? sanitizeOptions(mergeDeep(this._options, options)) : this._options;
|
|
3569
|
+
this._options = options ? configurePlugins(sanitizeOptions(mergeDeep(this._options, options))) : this._options;
|
|
3507
3570
|
if (!this._options.data) {
|
|
3508
3571
|
return;
|
|
3509
3572
|
}
|