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.
@@ -0,0 +1,20 @@
1
+ /**
2
+ * React wrapper: `import { QRCode } from "qr-code-styling-node/react"`.
3
+ *
4
+ * <QRCode options={{ data: "https://example.com", dotsOptions: { type: "rounded" } }} />
5
+ *
6
+ * The ref gives the QRCodeStyling instance (download, share, getRawData, verify...).
7
+ */
8
+ import { CSSProperties } from "react";
9
+ import QRCodeStyling from "../core/QRCodeStyling";
10
+ import { Options } from "../types";
11
+ export interface QRCodeProps {
12
+ options: Partial<Options>;
13
+ className?: string;
14
+ style?: CSSProperties;
15
+ /** Called with the instance once the code is drawn, and again after each change. */
16
+ onUpdate?: (qrCode: QRCodeStyling) => void;
17
+ }
18
+ export declare const QRCode: import("react").ForwardRefExoticComponent<QRCodeProps & import("react").RefAttributes<QRCodeStyling | undefined>>;
19
+ export default QRCode;
20
+ export { QRCodeStyling };
package/lib/react.cjs ADDED
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/react/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ QRCode: () => QRCode,
34
+ QRCodeStyling: () => import_QRCodeStyling.default,
35
+ default: () => index_default
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+ var import_react = require("react");
39
+ var import_QRCodeStyling = __toESM(require("./qr-code-styling.js"));
40
+
41
+ // src/tools/sameOptions.ts
42
+ function sameOptions(a, b) {
43
+ if (a === b) return true;
44
+ if (!a || !b) return false;
45
+ const references = [[], []];
46
+ const serialize = (options, index) => JSON.stringify(options, (_key, value) => {
47
+ if (typeof value === "function" || value && typeof value === "object" && !isPlain(value)) {
48
+ references[index].push(value);
49
+ return `#ref${references[index].length}`;
50
+ }
51
+ return value;
52
+ });
53
+ if (serialize(a, 0) !== serialize(b, 1)) return false;
54
+ return references[0].every((value, index) => value === references[1][index]);
55
+ }
56
+ var isPlain = (value) => {
57
+ if (Array.isArray(value)) return true;
58
+ const prototype = Object.getPrototypeOf(value);
59
+ return prototype === Object.prototype || prototype === null;
60
+ };
61
+ function snapshotOptions(value) {
62
+ if (Array.isArray(value)) return value.map(snapshotOptions);
63
+ if (value && typeof value === "object" && isPlain(value)) {
64
+ const copy = {};
65
+ Object.keys(value).forEach((key) => {
66
+ copy[key] = snapshotOptions(value[key]);
67
+ });
68
+ return copy;
69
+ }
70
+ return value;
71
+ }
72
+
73
+ // src/react/index.ts
74
+ var QRCode = (0, import_react.forwardRef)(function QRCode2({ options, className, style, onUpdate }, ref) {
75
+ const container = (0, import_react.useRef)(null);
76
+ const instance = (0, import_react.useRef)();
77
+ const drawn = (0, import_react.useRef)();
78
+ const appended = (0, import_react.useRef)(false);
79
+ if (!instance.current) {
80
+ instance.current = new import_QRCodeStyling.default(options);
81
+ drawn.current = snapshotOptions(options);
82
+ }
83
+ (0, import_react.useImperativeHandle)(ref, () => instance.current, []);
84
+ (0, import_react.useEffect)(() => {
85
+ const qrCode = instance.current;
86
+ if (!container.current) return;
87
+ if (!appended.current) {
88
+ qrCode.append(container.current);
89
+ appended.current = true;
90
+ } else if (!sameOptions(drawn.current, options)) {
91
+ qrCode.update(options);
92
+ drawn.current = snapshotOptions(options);
93
+ } else {
94
+ return;
95
+ }
96
+ onUpdate == null ? void 0 : onUpdate(qrCode);
97
+ });
98
+ return (0, import_react.createElement)("div", { ref: container, className, style });
99
+ });
100
+ var index_default = QRCode;
101
+ //# sourceMappingURL=react.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/react/index.ts", "../src/tools/sameOptions.ts"],
4
+ "sourcesContent": ["/**\n * React wrapper: `import { QRCode } from \"qr-code-styling-node/react\"`.\n *\n * <QRCode options={{ data: \"https://example.com\", dotsOptions: { type: \"rounded\" } }} />\n *\n * The ref gives the QRCodeStyling instance (download, share, getRawData, verify...).\n */\nimport { createElement, CSSProperties, forwardRef, useEffect, useImperativeHandle, useRef } from \"react\";\nimport QRCodeStyling from \"../core/QRCodeStyling\";\nimport sameOptions, { snapshotOptions } from \"../tools/sameOptions\";\nimport { Options } from \"../types\";\n\nexport interface QRCodeProps {\n options: Partial<Options>;\n className?: string;\n style?: CSSProperties;\n /** Called with the instance once the code is drawn, and again after each change. */\n onUpdate?: (qrCode: QRCodeStyling) => void;\n}\n\nexport const QRCode = forwardRef<QRCodeStyling | undefined, QRCodeProps>(function QRCode(\n { options, className, style, onUpdate },\n ref\n) {\n const container = useRef<HTMLDivElement>(null);\n const instance = useRef<QRCodeStyling>();\n const drawn = useRef<Partial<Options>>();\n const appended = useRef(false);\n\n // Created during the first render so the ref is ready as soon as the component mounts.\n if (!instance.current) {\n instance.current = new QRCodeStyling(options);\n drawn.current = snapshotOptions(options);\n }\n\n useImperativeHandle(ref, () => instance.current, []);\n\n useEffect(() => {\n const qrCode = instance.current as QRCodeStyling;\n if (!container.current) return;\n if (!appended.current) {\n qrCode.append(container.current);\n appended.current = true;\n } else if (!sameOptions(drawn.current, options)) {\n // update() redraws into the same container.\n qrCode.update(options);\n drawn.current = snapshotOptions(options);\n } else {\n return;\n }\n onUpdate?.(qrCode);\n });\n\n return createElement(\"div\", { ref: container, className, style });\n});\n\nexport default QRCode;\nexport { QRCodeStyling };\n", "import { Options } from \"../types\";\n\n/**\n * True when two options objects describe the same code, so wrappers can skip redrawing when a parent\n * re-renders with a new but equal object. Functions and objects like nodeCanvas or plugins are compared by\n * reference; everything else by value.\n */\nexport default function sameOptions(a?: Partial<Options>, b?: Partial<Options>): boolean {\n if (a === b) return true;\n if (!a || !b) return false;\n const references: unknown[][] = [[], []];\n const serialize = (options: Partial<Options>, index: number): string =>\n JSON.stringify(options, (_key, value) => {\n if (typeof value === \"function\" || (value && typeof value === \"object\" && !isPlain(value))) {\n references[index].push(value);\n return `#ref${references[index].length}`;\n }\n return value;\n });\n if (serialize(a, 0) !== serialize(b, 1)) return false;\n return references[0].every((value, index) => value === references[1][index]);\n}\n\nconst isPlain = (value: object): boolean => {\n if (Array.isArray(value)) return true;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n};\n\n/** Copy of the options for a later sameOptions() check: plain objects and arrays are copied, the rest kept. */\nexport function snapshotOptions<T>(value: T): T {\n if (Array.isArray(value)) return value.map(snapshotOptions) as unknown as T;\n if (value && typeof value === \"object\" && isPlain(value as unknown as object)) {\n const copy: Record<string, unknown> = {};\n Object.keys(value as unknown as object).forEach((key) => {\n copy[key] = snapshotOptions((value as unknown as Record<string, unknown>)[key]);\n });\n return copy as T;\n }\n return value;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;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AE,SAAS,WAAW,OAAO,SAAS,GACtC,KACA;AACA,QAAM,gBAAY,qBAAuB,IAAI;AAC7C,QAAM,eAAW,qBAAsB;AACvC,QAAM,YAAQ,qBAAyB;AACvC,QAAM,eAAW,qBAAO,KAAK;AAG7B,MAAI,CAAC,SAAS,SAAS;AACrB,aAAS,UAAU,IAAI,qBAAAC,QAAc,OAAO;AAC5C,UAAM,UAAU,gBAAgB,OAAO;AAAA,EACzC;AAEA,wCAAoB,KAAK,MAAM,SAAS,SAAS,CAAC,CAAC;AAEnD,8BAAU,MAAM;AACd,UAAM,SAAS,SAAS;AACxB,QAAI,CAAC,UAAU,QAAS;AACxB,QAAI,CAAC,SAAS,SAAS;AACrB,aAAO,OAAO,UAAU,OAAO;AAC/B,eAAS,UAAU;AAAA,IACrB,WAAW,CAAC,YAAY,MAAM,SAAS,OAAO,GAAG;AAE/C,aAAO,OAAO,OAAO;AACrB,YAAM,UAAU,gBAAgB,OAAO;AAAA,IACzC,OAAO;AACL;AAAA,IACF;AACA,yCAAW;AAAA,EACb,CAAC;AAED,aAAO,4BAAc,OAAO,EAAE,KAAK,WAAW,WAAW,MAAM,CAAC;AAClE,CAAC;AAED,IAAO,gBAAQ;",
6
+ "names": ["QRCodeStyling", "QRCode", "QRCodeStyling"]
7
+ }
package/lib/react.mjs ADDED
@@ -0,0 +1,70 @@
1
+ // src/react/index.ts
2
+ import { createElement, forwardRef, useEffect, useImperativeHandle, useRef } from "react";
3
+ import QRCodeStyling from "./qr-code-styling.mjs";
4
+
5
+ // src/tools/sameOptions.ts
6
+ function sameOptions(a, b) {
7
+ if (a === b) return true;
8
+ if (!a || !b) return false;
9
+ const references = [[], []];
10
+ const serialize = (options, index) => JSON.stringify(options, (_key, value) => {
11
+ if (typeof value === "function" || value && typeof value === "object" && !isPlain(value)) {
12
+ references[index].push(value);
13
+ return `#ref${references[index].length}`;
14
+ }
15
+ return value;
16
+ });
17
+ if (serialize(a, 0) !== serialize(b, 1)) return false;
18
+ return references[0].every((value, index) => value === references[1][index]);
19
+ }
20
+ var isPlain = (value) => {
21
+ if (Array.isArray(value)) return true;
22
+ const prototype = Object.getPrototypeOf(value);
23
+ return prototype === Object.prototype || prototype === null;
24
+ };
25
+ function snapshotOptions(value) {
26
+ if (Array.isArray(value)) return value.map(snapshotOptions);
27
+ if (value && typeof value === "object" && isPlain(value)) {
28
+ const copy = {};
29
+ Object.keys(value).forEach((key) => {
30
+ copy[key] = snapshotOptions(value[key]);
31
+ });
32
+ return copy;
33
+ }
34
+ return value;
35
+ }
36
+
37
+ // src/react/index.ts
38
+ var QRCode = forwardRef(function QRCode2({ options, className, style, onUpdate }, ref) {
39
+ const container = useRef(null);
40
+ const instance = useRef();
41
+ const drawn = useRef();
42
+ const appended = useRef(false);
43
+ if (!instance.current) {
44
+ instance.current = new QRCodeStyling(options);
45
+ drawn.current = snapshotOptions(options);
46
+ }
47
+ useImperativeHandle(ref, () => instance.current, []);
48
+ useEffect(() => {
49
+ const qrCode = instance.current;
50
+ if (!container.current) return;
51
+ if (!appended.current) {
52
+ qrCode.append(container.current);
53
+ appended.current = true;
54
+ } else if (!sameOptions(drawn.current, options)) {
55
+ qrCode.update(options);
56
+ drawn.current = snapshotOptions(options);
57
+ } else {
58
+ return;
59
+ }
60
+ onUpdate == null ? void 0 : onUpdate(qrCode);
61
+ });
62
+ return createElement("div", { ref: container, className, style });
63
+ });
64
+ var index_default = QRCode;
65
+ export {
66
+ QRCode,
67
+ QRCodeStyling,
68
+ index_default as default
69
+ };
70
+ //# sourceMappingURL=react.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/react/index.ts", "../src/tools/sameOptions.ts"],
4
+ "sourcesContent": ["/**\n * React wrapper: `import { QRCode } from \"qr-code-styling-node/react\"`.\n *\n * <QRCode options={{ data: \"https://example.com\", dotsOptions: { type: \"rounded\" } }} />\n *\n * The ref gives the QRCodeStyling instance (download, share, getRawData, verify...).\n */\nimport { createElement, CSSProperties, forwardRef, useEffect, useImperativeHandle, useRef } from \"react\";\nimport QRCodeStyling from \"../core/QRCodeStyling\";\nimport sameOptions, { snapshotOptions } from \"../tools/sameOptions\";\nimport { Options } from \"../types\";\n\nexport interface QRCodeProps {\n options: Partial<Options>;\n className?: string;\n style?: CSSProperties;\n /** Called with the instance once the code is drawn, and again after each change. */\n onUpdate?: (qrCode: QRCodeStyling) => void;\n}\n\nexport const QRCode = forwardRef<QRCodeStyling | undefined, QRCodeProps>(function QRCode(\n { options, className, style, onUpdate },\n ref\n) {\n const container = useRef<HTMLDivElement>(null);\n const instance = useRef<QRCodeStyling>();\n const drawn = useRef<Partial<Options>>();\n const appended = useRef(false);\n\n // Created during the first render so the ref is ready as soon as the component mounts.\n if (!instance.current) {\n instance.current = new QRCodeStyling(options);\n drawn.current = snapshotOptions(options);\n }\n\n useImperativeHandle(ref, () => instance.current, []);\n\n useEffect(() => {\n const qrCode = instance.current as QRCodeStyling;\n if (!container.current) return;\n if (!appended.current) {\n qrCode.append(container.current);\n appended.current = true;\n } else if (!sameOptions(drawn.current, options)) {\n // update() redraws into the same container.\n qrCode.update(options);\n drawn.current = snapshotOptions(options);\n } else {\n return;\n }\n onUpdate?.(qrCode);\n });\n\n return createElement(\"div\", { ref: container, className, style });\n});\n\nexport default QRCode;\nexport { QRCodeStyling };\n", "import { Options } from \"../types\";\n\n/**\n * True when two options objects describe the same code, so wrappers can skip redrawing when a parent\n * re-renders with a new but equal object. Functions and objects like nodeCanvas or plugins are compared by\n * reference; everything else by value.\n */\nexport default function sameOptions(a?: Partial<Options>, b?: Partial<Options>): boolean {\n if (a === b) return true;\n if (!a || !b) return false;\n const references: unknown[][] = [[], []];\n const serialize = (options: Partial<Options>, index: number): string =>\n JSON.stringify(options, (_key, value) => {\n if (typeof value === \"function\" || (value && typeof value === \"object\" && !isPlain(value))) {\n references[index].push(value);\n return `#ref${references[index].length}`;\n }\n return value;\n });\n if (serialize(a, 0) !== serialize(b, 1)) return false;\n return references[0].every((value, index) => value === references[1][index]);\n}\n\nconst isPlain = (value: object): boolean => {\n if (Array.isArray(value)) return true;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n};\n\n/** Copy of the options for a later sameOptions() check: plain objects and arrays are copied, the rest kept. */\nexport function snapshotOptions<T>(value: T): T {\n if (Array.isArray(value)) return value.map(snapshotOptions) as unknown as T;\n if (value && typeof value === \"object\" && isPlain(value as unknown as object)) {\n const copy: Record<string, unknown> = {};\n Object.keys(value as unknown as object).forEach((key) => {\n copy[key] = snapshotOptions((value as unknown as Record<string, unknown>)[key]);\n });\n return copy as T;\n }\n return value;\n}\n"],
5
+ "mappings": ";AAOA,SAAS,eAA8B,YAAY,WAAW,qBAAqB,cAAc;AACjG,OAAO,mBAAmB;;;ACDX,SAAR,YAA6B,GAAsB,GAA+B;AACvF,MAAI,MAAM,EAAG,QAAO;AACpB,MAAI,CAAC,KAAK,CAAC,EAAG,QAAO;AACrB,QAAM,aAA0B,CAAC,CAAC,GAAG,CAAC,CAAC;AACvC,QAAM,YAAY,CAAC,SAA2B,UAC5C,KAAK,UAAU,SAAS,CAAC,MAAM,UAAU;AACvC,QAAI,OAAO,UAAU,cAAe,SAAS,OAAO,UAAU,YAAY,CAAC,QAAQ,KAAK,GAAI;AAC1F,iBAAW,KAAK,EAAE,KAAK,KAAK;AAC5B,aAAO,OAAO,WAAW,KAAK,EAAE,MAAM;AAAA,IACxC;AACA,WAAO;AAAA,EACT,CAAC;AACH,MAAI,UAAU,GAAG,CAAC,MAAM,UAAU,GAAG,CAAC,EAAG,QAAO;AAChD,SAAO,WAAW,CAAC,EAAE,MAAM,CAAC,OAAO,UAAU,UAAU,WAAW,CAAC,EAAE,KAAK,CAAC;AAC7E;AAEA,IAAM,UAAU,CAAC,UAA2B;AAC1C,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO;AACjC,QAAM,YAAY,OAAO,eAAe,KAAK;AAC7C,SAAO,cAAc,OAAO,aAAa,cAAc;AACzD;AAGO,SAAS,gBAAmB,OAAa;AAC9C,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO,MAAM,IAAI,eAAe;AAC1D,MAAI,SAAS,OAAO,UAAU,YAAY,QAAQ,KAA0B,GAAG;AAC7E,UAAM,OAAgC,CAAC;AACvC,WAAO,KAAK,KAA0B,EAAE,QAAQ,CAAC,QAAQ;AACvD,WAAK,GAAG,IAAI,gBAAiB,MAA6C,GAAG,CAAC;AAAA,IAChF,CAAC;AACD,WAAO;AAAA,EACT;AACA,SAAO;AACT;;;ADpBO,IAAM,SAAS,WAAmD,SAASA,QAChF,EAAE,SAAS,WAAW,OAAO,SAAS,GACtC,KACA;AACA,QAAM,YAAY,OAAuB,IAAI;AAC7C,QAAM,WAAW,OAAsB;AACvC,QAAM,QAAQ,OAAyB;AACvC,QAAM,WAAW,OAAO,KAAK;AAG7B,MAAI,CAAC,SAAS,SAAS;AACrB,aAAS,UAAU,IAAI,cAAc,OAAO;AAC5C,UAAM,UAAU,gBAAgB,OAAO;AAAA,EACzC;AAEA,sBAAoB,KAAK,MAAM,SAAS,SAAS,CAAC,CAAC;AAEnD,YAAU,MAAM;AACd,UAAM,SAAS,SAAS;AACxB,QAAI,CAAC,UAAU,QAAS;AACxB,QAAI,CAAC,SAAS,SAAS;AACrB,aAAO,OAAO,UAAU,OAAO;AAC/B,eAAS,UAAU;AAAA,IACrB,WAAW,CAAC,YAAY,MAAM,SAAS,OAAO,GAAG;AAE/C,aAAO,OAAO,OAAO;AACrB,YAAM,UAAU,gBAAgB,OAAO;AAAA,IACzC,OAAO;AACL;AAAA,IACF;AACA,yCAAW;AAAA,EACb,CAAC;AAED,SAAO,cAAc,OAAO,EAAE,KAAK,WAAW,WAAW,MAAM,CAAC;AAClE,CAAC;AAED,IAAO,gBAAQ;",
6
+ "names": ["QRCode"]
7
+ }
@@ -0,0 +1,7 @@
1
+ import { RequiredOptions } from "../core/QROptions";
2
+ import { PluginArea, PluginDrawContext } from "../types";
3
+ /** Lets each plugin's configure() adjust the options, in order. */
4
+ export declare function configurePlugins(options: RequiredOptions): RequiredOptions;
5
+ /** Where the code is drawn in the output, frames included. */
6
+ export declare function getPluginArea(options: RequiredOptions, count: number): PluginArea;
7
+ export declare function runAfterDraw(options: RequiredOptions, draw: Omit<PluginDrawContext, "options">): Promise<void>;
@@ -0,0 +1,9 @@
1
+ import { Options } from "../types";
2
+ /**
3
+ * True when two options objects describe the same code, so wrappers can skip redrawing when a parent
4
+ * re-renders with a new but equal object. Functions and objects like nodeCanvas or plugins are compared by
5
+ * reference; everything else by value.
6
+ */
7
+ export default function sameOptions(a?: Partial<Options>, b?: Partial<Options>): boolean;
8
+ /** Copy of the options for a later sameOptions() check: plain objects and arrays are copied, the rest kept. */
9
+ export declare function snapshotOptions<T>(value: T): T;
@@ -162,6 +162,8 @@ export type Options = {
162
162
  */
163
163
  shape?: ShapeType;
164
164
  /** SVG output only. */
165
+ /** Plugins that adjust options and draw on top of the code. See QRPlugin. */
166
+ plugins?: QRPlugin[];
165
167
  svgOptions?: {
166
168
  /** Draw all dots as one path instead of one element per module: smaller files, faster rendering. Default false. */
167
169
  mergePaths?: boolean;
@@ -260,4 +262,38 @@ export type RotateFigureArgsCanvas = RotateFigureArgs & {
260
262
  context: CanvasRenderingContext2D;
261
263
  };
262
264
  export type GetNeighbor = (x: number, y: number) => boolean;
265
+ /** Where the code (without margin and frame) is drawn in the output, in pixels. */
266
+ export interface PluginArea {
267
+ x: number;
268
+ y: number;
269
+ /** Width and height of the code. */
270
+ size: number;
271
+ /** Size of one module. */
272
+ dotSize: number;
273
+ /** Modules across. */
274
+ count: number;
275
+ }
276
+ export interface PluginDrawContext {
277
+ type: DrawType;
278
+ options: Options;
279
+ area: PluginArea;
280
+ width: number;
281
+ height: number;
282
+ /** Canvas output: the 2D context to draw on. */
283
+ context?: CanvasRenderingContext2D;
284
+ /** SVG output: the root <svg> element, and the document to create elements with. */
285
+ svg?: SVGElement;
286
+ document?: Document;
287
+ }
288
+ /**
289
+ * A plugin. Both hooks are optional.
290
+ * - configure(options): return option changes to merge in before drawing (called again on every update, so
291
+ * return the same changes for the same options).
292
+ * - afterDraw(draw): draw extra things on top, on the canvas context or into the SVG.
293
+ */
294
+ export interface QRPlugin {
295
+ name?: string;
296
+ configure?: (options: Options) => Partial<Options> | void;
297
+ afterDraw?: (draw: PluginDrawContext) => void | Promise<void>;
298
+ }
263
299
  export {};
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Vue 3 wrapper: `import { QRCode } from "qr-code-styling-node/vue"`.
3
+ *
4
+ * <QRCode :options="{ data: 'https://example.com', dotsOptions: { type: 'rounded' } }" />
5
+ *
6
+ * A template ref exposes `qrCode` (the QRCodeStyling instance), plus `download`, `share` and `getRawData`.
7
+ */
8
+ import { PropType } from "vue";
9
+ import QRCodeStyling from "../core/QRCodeStyling";
10
+ import { Options } from "../types";
11
+ export declare const QRCode: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
12
+ options: {
13
+ type: PropType<Partial<Options>>;
14
+ required: true;
15
+ };
16
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
17
+ [key: string]: any;
18
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "update"[], "update", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
19
+ options: {
20
+ type: PropType<Partial<Options>>;
21
+ required: true;
22
+ };
23
+ }>> & Readonly<{
24
+ onUpdate?: ((...args: any[]) => any) | undefined;
25
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
26
+ export default QRCode;
27
+ export { QRCodeStyling };
package/lib/vue.cjs ADDED
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/vue/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ QRCode: () => QRCode,
34
+ QRCodeStyling: () => import_QRCodeStyling.default,
35
+ default: () => index_default
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+ var import_vue = require("vue");
39
+ var import_QRCodeStyling = __toESM(require("./qr-code-styling.js"));
40
+
41
+ // src/tools/sameOptions.ts
42
+ function sameOptions(a, b) {
43
+ if (a === b) return true;
44
+ if (!a || !b) return false;
45
+ const references = [[], []];
46
+ const serialize = (options, index) => JSON.stringify(options, (_key, value) => {
47
+ if (typeof value === "function" || value && typeof value === "object" && !isPlain(value)) {
48
+ references[index].push(value);
49
+ return `#ref${references[index].length}`;
50
+ }
51
+ return value;
52
+ });
53
+ if (serialize(a, 0) !== serialize(b, 1)) return false;
54
+ return references[0].every((value, index) => value === references[1][index]);
55
+ }
56
+ var isPlain = (value) => {
57
+ if (Array.isArray(value)) return true;
58
+ const prototype = Object.getPrototypeOf(value);
59
+ return prototype === Object.prototype || prototype === null;
60
+ };
61
+ function snapshotOptions(value) {
62
+ if (Array.isArray(value)) return value.map(snapshotOptions);
63
+ if (value && typeof value === "object" && isPlain(value)) {
64
+ const copy = {};
65
+ Object.keys(value).forEach((key) => {
66
+ copy[key] = snapshotOptions(value[key]);
67
+ });
68
+ return copy;
69
+ }
70
+ return value;
71
+ }
72
+
73
+ // src/vue/index.ts
74
+ var QRCode = (0, import_vue.defineComponent)({
75
+ name: "QRCode",
76
+ props: {
77
+ options: { type: Object, required: true }
78
+ },
79
+ emits: ["update"],
80
+ setup(props, { emit, expose }) {
81
+ const container = (0, import_vue.ref)();
82
+ const qrCode = (0, import_vue.shallowRef)();
83
+ let drawn;
84
+ const draw = (options) => {
85
+ if (!container.value) return;
86
+ if (!qrCode.value) {
87
+ qrCode.value = new import_QRCodeStyling.default(snapshotOptions(options));
88
+ qrCode.value.append(container.value);
89
+ } else if (!sameOptions(drawn, options)) {
90
+ qrCode.value.update(snapshotOptions(options));
91
+ } else {
92
+ return;
93
+ }
94
+ drawn = snapshotOptions(options);
95
+ emit("update", qrCode.value);
96
+ };
97
+ (0, import_vue.onMounted)(() => draw(props.options));
98
+ (0, import_vue.watch)(
99
+ () => props.options,
100
+ (options) => draw(options),
101
+ { deep: true }
102
+ );
103
+ expose({
104
+ qrCode,
105
+ download: (options) => {
106
+ var _a;
107
+ return (_a = qrCode.value) == null ? void 0 : _a.download(options);
108
+ },
109
+ share: (options) => {
110
+ var _a;
111
+ return (_a = qrCode.value) == null ? void 0 : _a.share(options);
112
+ },
113
+ getRawData: (extension) => {
114
+ var _a;
115
+ return (_a = qrCode.value) == null ? void 0 : _a.getRawData(extension);
116
+ }
117
+ });
118
+ return () => (0, import_vue.h)("div", { ref: container });
119
+ }
120
+ });
121
+ var index_default = QRCode;
122
+ //# sourceMappingURL=vue.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/vue/index.ts", "../src/tools/sameOptions.ts"],
4
+ "sourcesContent": ["/**\n * Vue 3 wrapper: `import { QRCode } from \"qr-code-styling-node/vue\"`.\n *\n * <QRCode :options=\"{ data: 'https://example.com', dotsOptions: { type: 'rounded' } }\" />\n *\n * A template ref exposes `qrCode` (the QRCodeStyling instance), plus `download`, `share` and `getRawData`.\n */\nimport { defineComponent, h, onMounted, PropType, ref, shallowRef, watch } from \"vue\";\nimport QRCodeStyling from \"../core/QRCodeStyling\";\nimport sameOptions, { snapshotOptions } from \"../tools/sameOptions\";\nimport { DownloadOptions, Extension, Options, ShareOptions } from \"../types\";\n\nexport const QRCode = defineComponent({\n name: \"QRCode\",\n props: {\n options: { type: Object as PropType<Partial<Options>>, required: true }\n },\n emits: [\"update\"],\n setup(props, { emit, expose }) {\n const container = ref<HTMLDivElement>();\n const qrCode = shallowRef<QRCodeStyling>();\n let drawn: Partial<Options> | undefined;\n\n const draw = (options: Partial<Options>): void => {\n if (!container.value) return;\n if (!qrCode.value) {\n qrCode.value = new QRCodeStyling(snapshotOptions(options));\n qrCode.value.append(container.value);\n } else if (!sameOptions(drawn, options)) {\n qrCode.value.update(snapshotOptions(options));\n } else {\n return;\n }\n // Vue may change the same object in place, so keep a copy to compare with.\n drawn = snapshotOptions(options);\n emit(\"update\", qrCode.value);\n };\n\n onMounted(() => draw(props.options));\n watch(\n () => props.options,\n (options) => draw(options),\n { deep: true }\n );\n\n expose({\n qrCode,\n download: (options?: Partial<DownloadOptions>) => qrCode.value?.download(options),\n share: (options?: ShareOptions) => qrCode.value?.share(options),\n getRawData: (extension?: Extension) => qrCode.value?.getRawData(extension)\n });\n\n return () => h(\"div\", { ref: container });\n }\n});\n\nexport default QRCode;\nexport { QRCodeStyling };\n", "import { Options } from \"../types\";\n\n/**\n * True when two options objects describe the same code, so wrappers can skip redrawing when a parent\n * re-renders with a new but equal object. Functions and objects like nodeCanvas or plugins are compared by\n * reference; everything else by value.\n */\nexport default function sameOptions(a?: Partial<Options>, b?: Partial<Options>): boolean {\n if (a === b) return true;\n if (!a || !b) return false;\n const references: unknown[][] = [[], []];\n const serialize = (options: Partial<Options>, index: number): string =>\n JSON.stringify(options, (_key, value) => {\n if (typeof value === \"function\" || (value && typeof value === \"object\" && !isPlain(value))) {\n references[index].push(value);\n return `#ref${references[index].length}`;\n }\n return value;\n });\n if (serialize(a, 0) !== serialize(b, 1)) return false;\n return references[0].every((value, index) => value === references[1][index]);\n}\n\nconst isPlain = (value: object): boolean => {\n if (Array.isArray(value)) return true;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n};\n\n/** Copy of the options for a later sameOptions() check: plain objects and arrays are copied, the rest kept. */\nexport function snapshotOptions<T>(value: T): T {\n if (Array.isArray(value)) return value.map(snapshotOptions) as unknown as T;\n if (value && typeof value === \"object\" && isPlain(value as unknown as object)) {\n const copy: Record<string, unknown> = {};\n Object.keys(value as unknown as object).forEach((key) => {\n copy[key] = snapshotOptions((value as unknown as Record<string, unknown>)[key]);\n });\n return copy as T;\n }\n return value;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,4CAAAA;AAAA,EAAA;AAAA;AAAA;AAOA,iBAAgF;AAChF,2BAA0B;;;ACDX,SAAR,YAA6B,GAAsB,GAA+B;AACvF,MAAI,MAAM,EAAG,QAAO;AACpB,MAAI,CAAC,KAAK,CAAC,EAAG,QAAO;AACrB,QAAM,aAA0B,CAAC,CAAC,GAAG,CAAC,CAAC;AACvC,QAAM,YAAY,CAAC,SAA2B,UAC5C,KAAK,UAAU,SAAS,CAAC,MAAM,UAAU;AACvC,QAAI,OAAO,UAAU,cAAe,SAAS,OAAO,UAAU,YAAY,CAAC,QAAQ,KAAK,GAAI;AAC1F,iBAAW,KAAK,EAAE,KAAK,KAAK;AAC5B,aAAO,OAAO,WAAW,KAAK,EAAE,MAAM;AAAA,IACxC;AACA,WAAO;AAAA,EACT,CAAC;AAC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F;AAEA,cAAQ,gBAAgB,OAAO;AAC/B,WAAK,UAAU,OAAO,KAAK;AAAA,IAC7B;AAEA,8BAAU,MAAM,KAAK,MAAM,OAAO,CAAC;AACnC;AAAA,MACE,MAAM,MAAM;AAAA,MACZ,CAAC,YAAY,KAAK,OAAO;AAAA,MACzB,EAAE,MAAM,KAAK;AAAA,IACf;AAEA,WAAO;AAAA,MACL;AAAA,MACA,UAAU,CAAC,YAAoC;AA/CrD;AA+CwD,4BAAO,UAAP,mBAAc,SAAS;AAAA;AAAA,MACzE,OAAO,CAAC,YAAwB;AAhDtC;AAgDyC,4BAAO,UAAP,mBAAc,MAAM;AAAA;AAAA,MACvD,YAAY,CAAC,cAAuB;AAjD1C;AAiD6C,4BAAO,UAAP,mBAAc,WAAW;AAAA;AAAA,IAClE,CAAC;AAED,WAAO,UAAM,cAAE,OAAO,EAAE,KAAK,UAAU,CAAC;AAAA,EAC1C;AACF,CAAC;AAED,IAAO,gBAAQ;",
6
+ "names": ["QRCodeStyling", "QRCodeStyling"]
7
+ }
package/lib/vue.mjs ADDED
@@ -0,0 +1,91 @@
1
+ // src/vue/index.ts
2
+ import { defineComponent, h, onMounted, ref, shallowRef, watch } from "vue";
3
+ import QRCodeStyling from "./qr-code-styling.mjs";
4
+
5
+ // src/tools/sameOptions.ts
6
+ function sameOptions(a, b) {
7
+ if (a === b) return true;
8
+ if (!a || !b) return false;
9
+ const references = [[], []];
10
+ const serialize = (options, index) => JSON.stringify(options, (_key, value) => {
11
+ if (typeof value === "function" || value && typeof value === "object" && !isPlain(value)) {
12
+ references[index].push(value);
13
+ return `#ref${references[index].length}`;
14
+ }
15
+ return value;
16
+ });
17
+ if (serialize(a, 0) !== serialize(b, 1)) return false;
18
+ return references[0].every((value, index) => value === references[1][index]);
19
+ }
20
+ var isPlain = (value) => {
21
+ if (Array.isArray(value)) return true;
22
+ const prototype = Object.getPrototypeOf(value);
23
+ return prototype === Object.prototype || prototype === null;
24
+ };
25
+ function snapshotOptions(value) {
26
+ if (Array.isArray(value)) return value.map(snapshotOptions);
27
+ if (value && typeof value === "object" && isPlain(value)) {
28
+ const copy = {};
29
+ Object.keys(value).forEach((key) => {
30
+ copy[key] = snapshotOptions(value[key]);
31
+ });
32
+ return copy;
33
+ }
34
+ return value;
35
+ }
36
+
37
+ // src/vue/index.ts
38
+ var QRCode = defineComponent({
39
+ name: "QRCode",
40
+ props: {
41
+ options: { type: Object, required: true }
42
+ },
43
+ emits: ["update"],
44
+ setup(props, { emit, expose }) {
45
+ const container = ref();
46
+ const qrCode = shallowRef();
47
+ let drawn;
48
+ const draw = (options) => {
49
+ if (!container.value) return;
50
+ if (!qrCode.value) {
51
+ qrCode.value = new QRCodeStyling(snapshotOptions(options));
52
+ qrCode.value.append(container.value);
53
+ } else if (!sameOptions(drawn, options)) {
54
+ qrCode.value.update(snapshotOptions(options));
55
+ } else {
56
+ return;
57
+ }
58
+ drawn = snapshotOptions(options);
59
+ emit("update", qrCode.value);
60
+ };
61
+ onMounted(() => draw(props.options));
62
+ watch(
63
+ () => props.options,
64
+ (options) => draw(options),
65
+ { deep: true }
66
+ );
67
+ expose({
68
+ qrCode,
69
+ download: (options) => {
70
+ var _a;
71
+ return (_a = qrCode.value) == null ? void 0 : _a.download(options);
72
+ },
73
+ share: (options) => {
74
+ var _a;
75
+ return (_a = qrCode.value) == null ? void 0 : _a.share(options);
76
+ },
77
+ getRawData: (extension) => {
78
+ var _a;
79
+ return (_a = qrCode.value) == null ? void 0 : _a.getRawData(extension);
80
+ }
81
+ });
82
+ return () => h("div", { ref: container });
83
+ }
84
+ });
85
+ var index_default = QRCode;
86
+ export {
87
+ QRCode,
88
+ QRCodeStyling,
89
+ index_default as default
90
+ };
91
+ //# sourceMappingURL=vue.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/vue/index.ts", "../src/tools/sameOptions.ts"],
4
+ "sourcesContent": ["/**\n * Vue 3 wrapper: `import { QRCode } from \"qr-code-styling-node/vue\"`.\n *\n * <QRCode :options=\"{ data: 'https://example.com', dotsOptions: { type: 'rounded' } }\" />\n *\n * A template ref exposes `qrCode` (the QRCodeStyling instance), plus `download`, `share` and `getRawData`.\n */\nimport { defineComponent, h, onMounted, PropType, ref, shallowRef, watch } from \"vue\";\nimport QRCodeStyling from \"../core/QRCodeStyling\";\nimport sameOptions, { snapshotOptions } from \"../tools/sameOptions\";\nimport { DownloadOptions, Extension, Options, ShareOptions } from \"../types\";\n\nexport const QRCode = defineComponent({\n name: \"QRCode\",\n props: {\n options: { type: Object as PropType<Partial<Options>>, required: true }\n },\n emits: [\"update\"],\n setup(props, { emit, expose }) {\n const container = ref<HTMLDivElement>();\n const qrCode = shallowRef<QRCodeStyling>();\n let drawn: Partial<Options> | undefined;\n\n const draw = (options: Partial<Options>): void => {\n if (!container.value) return;\n if (!qrCode.value) {\n qrCode.value = new QRCodeStyling(snapshotOptions(options));\n qrCode.value.append(container.value);\n } else if (!sameOptions(drawn, options)) {\n qrCode.value.update(snapshotOptions(options));\n } else {\n return;\n }\n // Vue may change the same object in place, so keep a copy to compare with.\n drawn = snapshotOptions(options);\n emit(\"update\", qrCode.value);\n };\n\n onMounted(() => draw(props.options));\n watch(\n () => props.options,\n (options) => draw(options),\n { deep: true }\n );\n\n expose({\n qrCode,\n download: (options?: Partial<DownloadOptions>) => qrCode.value?.download(options),\n share: (options?: ShareOptions) => qrCode.value?.share(options),\n getRawData: (extension?: Extension) => qrCode.value?.getRawData(extension)\n });\n\n return () => h(\"div\", { ref: container });\n }\n});\n\nexport default QRCode;\nexport { QRCodeStyling };\n", "import { Options } from \"../types\";\n\n/**\n * True when two options objects describe the same code, so wrappers can skip redrawing when a parent\n * re-renders with a new but equal object. Functions and objects like nodeCanvas or plugins are compared by\n * reference; everything else by value.\n */\nexport default function sameOptions(a?: Partial<Options>, b?: Partial<Options>): boolean {\n if (a === b) return true;\n if (!a || !b) return false;\n const references: unknown[][] = [[], []];\n const serialize = (options: Partial<Options>, index: number): string =>\n JSON.stringify(options, (_key, value) => {\n if (typeof value === \"function\" || (value && typeof value === \"object\" && !isPlain(value))) {\n references[index].push(value);\n return `#ref${references[index].length}`;\n }\n return value;\n });\n if (serialize(a, 0) !== serialize(b, 1)) return false;\n return references[0].every((value, index) => value === references[1][index]);\n}\n\nconst isPlain = (value: object): boolean => {\n if (Array.isArray(value)) return true;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n};\n\n/** Copy of the options for a later sameOptions() check: plain objects and arrays are copied, the rest kept. */\nexport function snapshotOptions<T>(value: T): T {\n if (Array.isArray(value)) return value.map(snapshotOptions) as unknown as T;\n if (value && typeof value === \"object\" && isPlain(value as unknown as object)) {\n const copy: Record<string, unknown> = {};\n Object.keys(value as unknown as object).forEach((key) => {\n copy[key] = snapshotOptions((value as unknown as Record<string, unknown>)[key]);\n });\n return copy as T;\n }\n return value;\n}\n"],
5
+ "mappings": ";AAOA,SAAS,iBAAiB,GAAG,WAAqB,KAAK,YAAY,aAAa;AAChF,OAAO,mBAAmB;;;ACDX,SAAR,YAA6B,GAAsB,GAA+B;AACvF,MAAI,MAAM,EAAG,QAAO;AACpB,MAAI,CAAC,KAAK,CAAC,EAAG,QAAO;AACrB,QAAM,aAA0B,CAAC,CAAC,GAAG,CAAC,CAAC;AACvC,QAAM,YAAY,CAAC,SAA2B,UAC5C,KAAK,UAAU,SAAS,CAAC,MAAM,UAAU;AACvC,QAAI,OAAO,UAAU,cAAe,SAAS,OAAO,UAAU,YAAY,CAAC,QAAQ,KAAK,GAAI;AAC1F,iBAAW,KAAK,EAAE,KAAK,KAAK;AAC5B,aAAO,OAAO,WAAW,KAAK,EAAE,MAAM;AAAA,IACxC;AACA,WAAO;AAAA,EACT,CAAC;AACH,MAAI,UAAU,GAAG,CAAC,MAAM,UAAU,GAAG,CAAC,EAAG,QAAO;AAChD,SAAO,WAAW,CAAC,EAAE,MAAM,CAAC,OAAO,UAAU,UAAU,WAAW,CAAC,EAAE,KA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,CAAC,YAAY,KAAK,OAAO;AAAA,MACzB,EAAE,MAAM,KAAK;AAAA,IACf;AAEA,WAAO;AAAA,MACL;AAAA,MACA,UAAU,CAAC,YAAoC;AA/CrD;AA+CwD,4BAAO,UAAP,mBAAc,SAAS;AAAA;AAAA,MACzE,OAAO,CAAC,YAAwB;AAhDtC;AAgDyC,4BAAO,UAAP,mBAAc,MAAM;AAAA;AAAA,MACvD,YAAY,CAAC,cAAuB;AAjD1C;AAiD6C,4BAAO,UAAP,mBAAc,WAAW;AAAA;AAAA,IAClE,CAAC;AAED,WAAO,MAAM,EAAE,OAAO,EAAE,KAAK,UAAU,CAAC;AAAA,EAC1C;AACF,CAAC;AAED,IAAO,gBAAQ;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qr-code-styling-node",
3
- "version": "1.12.0",
3
+ "version": "1.14.0",
4
4
  "description": "Style your QR codes: dots, corners, gradients and a logo. Works in the browser and on Node.js.",
5
5
  "keywords": [
6
6
  "qr",
@@ -45,6 +45,16 @@
45
45
  "require": "./lib/qr-code-styling.js",
46
46
  "default": "./lib/qr-code-styling.js"
47
47
  },
48
+ "./react": {
49
+ "types": "./lib/react/index.d.ts",
50
+ "import": "./lib/react.mjs",
51
+ "require": "./lib/react.cjs"
52
+ },
53
+ "./vue": {
54
+ "types": "./lib/vue/index.d.ts",
55
+ "import": "./lib/vue.mjs",
56
+ "require": "./lib/vue.cjs"
57
+ },
48
58
  "./lib/*": "./lib/*",
49
59
  "./package.json": "./package.json"
50
60
  },
@@ -80,10 +90,24 @@
80
90
  "dependencies": {
81
91
  "qrcode-generator": "^1.4.3"
82
92
  },
93
+ "peerDependencies": {
94
+ "react": ">=16.8.0",
95
+ "vue": ">=3.0.0"
96
+ },
97
+ "peerDependenciesMeta": {
98
+ "react": {
99
+ "optional": true
100
+ },
101
+ "vue": {
102
+ "optional": true
103
+ }
104
+ },
83
105
  "devDependencies": {
84
106
  "@eslint/js": "^9.39.5",
85
107
  "@resvg/resvg-js": "^2.6.2",
86
108
  "@types/node": "^22.20.5",
109
+ "@types/react": "^18.3.12",
110
+ "@types/react-dom": "^18.3.1",
87
111
  "@vitest/coverage-v8": "^2.1.9",
88
112
  "canvas": "^3.2.3",
89
113
  "esbuild": "^0.24.2",
@@ -96,10 +120,13 @@
96
120
  "jsqr": "^1.4.0",
97
121
  "prettier": "^3.10.1",
98
122
  "qr-code-styling-node-v1-5": "npm:qr-code-styling-node@1.5.0",
123
+ "react": "^18.3.1",
124
+ "react-dom": "^18.3.1",
99
125
  "ts-loader": "^9.6.2",
100
126
  "typescript": "^5.9.3",
101
127
  "typescript-eslint": "^8.73.0",
102
128
  "vitest": "^2.1.9",
129
+ "vue": "^3.5.13",
103
130
  "webpack": "^5.113.0",
104
131
  "webpack-cli": "^6.0.1",
105
132
  "webpack-dev-server": "^5.2.7",