qrbit 0.5.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/LICENSE +21 -0
- package/README.md +421 -0
- package/dist/native.d.ts +40 -0
- package/dist/native.js +566 -0
- package/dist/qrbit.cjs +394 -0
- package/dist/qrbit.cjs.map +1 -0
- package/dist/qrbit.d.cts +237 -0
- package/dist/qrbit.d.ts +237 -0
- package/dist/qrbit.darwin-arm64.node +0 -0
- package/dist/qrbit.darwin-x64.node +0 -0
- package/dist/qrbit.js +365 -0
- package/dist/qrbit.js.map +1 -0
- package/dist/qrbit.linux-x64-gnu.node +0 -0
- package/dist/qrbit.linux-x64-musl.node +0 -0
- package/dist/qrbit.win32-x64-msvc.node +0 -0
- package/package.json +96 -0
package/dist/qrbit.cjs
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
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/qrbit.ts
|
|
31
|
+
var qrbit_exports = {};
|
|
32
|
+
__export(qrbit_exports, {
|
|
33
|
+
QrBit: () => QrBit,
|
|
34
|
+
QrBitEvents: () => QrBitEvents
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(qrbit_exports);
|
|
37
|
+
var import_node_buffer = require("buffer");
|
|
38
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
39
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
40
|
+
var import_cacheable = require("cacheable");
|
|
41
|
+
var import_hookified = require("hookified");
|
|
42
|
+
var import_qrcode = __toESM(require("qrcode"), 1);
|
|
43
|
+
var import_native = require("./native.js");
|
|
44
|
+
var QrBitEvents = /* @__PURE__ */ ((QrBitEvents2) => {
|
|
45
|
+
QrBitEvents2["warn"] = "warn";
|
|
46
|
+
QrBitEvents2["info"] = "info";
|
|
47
|
+
QrBitEvents2["error"] = "error";
|
|
48
|
+
return QrBitEvents2;
|
|
49
|
+
})(QrBitEvents || {});
|
|
50
|
+
var logoFileDoesNotExistMessage = (logo) => `Logo file not found: ${logo}. Proceeding without logo.`;
|
|
51
|
+
var QrBit = class _QrBit extends import_hookified.Hookified {
|
|
52
|
+
/**
|
|
53
|
+
* Create a new QrBit instance.
|
|
54
|
+
* @param options - Configuration options for the QR code
|
|
55
|
+
*/
|
|
56
|
+
constructor(options) {
|
|
57
|
+
super();
|
|
58
|
+
this._napi = {
|
|
59
|
+
convertSvgToPng: import_native.convertSvgToPng,
|
|
60
|
+
generateQr: import_native.generateQr,
|
|
61
|
+
generateQrPng: import_native.generateQrPng,
|
|
62
|
+
generateQrPngWithBuffer: import_native.generateQrPngWithBuffer,
|
|
63
|
+
generateQrSvg: import_native.generateQrSvg,
|
|
64
|
+
generateQrSvgWithBuffer: import_native.generateQrSvgWithBuffer
|
|
65
|
+
};
|
|
66
|
+
this._text = options.text;
|
|
67
|
+
this._size = options.size ?? 200;
|
|
68
|
+
this._margin = options.margin ?? void 0;
|
|
69
|
+
this._logo = options.logo;
|
|
70
|
+
this._logoSizeRatio = options.logoSizeRatio ?? 0.2;
|
|
71
|
+
this._backgroundColor = options.backgroundColor ?? "#FFFFFF";
|
|
72
|
+
this._foregroundColor = options.foregroundColor ?? "#000000";
|
|
73
|
+
if (options.cache !== void 0) {
|
|
74
|
+
if (options.cache === true) {
|
|
75
|
+
this._cache = new import_cacheable.Cacheable();
|
|
76
|
+
} else if (options.cache !== false) {
|
|
77
|
+
this._cache = options.cache;
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
this._cache = new import_cacheable.Cacheable();
|
|
81
|
+
}
|
|
82
|
+
this.throwOnEmitError = true;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get the text content for the QR code.
|
|
86
|
+
* @returns {string} The text content
|
|
87
|
+
*/
|
|
88
|
+
get text() {
|
|
89
|
+
return this._text;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Set the text content for the QR code.
|
|
93
|
+
* @param value - The text content to encode
|
|
94
|
+
*/
|
|
95
|
+
set text(value) {
|
|
96
|
+
this._text = value;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get the size of the QR code in pixels.
|
|
100
|
+
* @returns {number} The size in pixels
|
|
101
|
+
* @default 200
|
|
102
|
+
*/
|
|
103
|
+
get size() {
|
|
104
|
+
return this._size;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Set the size of the QR code in pixels.
|
|
108
|
+
* @param value - The size in pixels
|
|
109
|
+
*/
|
|
110
|
+
set size(value) {
|
|
111
|
+
this._size = value;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get the margin around the QR code in pixels.
|
|
115
|
+
* @returns {number | undefined} The margin in pixels
|
|
116
|
+
*/
|
|
117
|
+
get margin() {
|
|
118
|
+
return this._margin;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Set the margin around the QR code in pixels.
|
|
122
|
+
* @param value - The margin in pixels
|
|
123
|
+
*/
|
|
124
|
+
set margin(value) {
|
|
125
|
+
this._margin = value;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get the logo path or buffer.
|
|
129
|
+
* @returns {string | Buffer | undefined} The logo path, buffer, or undefined if no logo
|
|
130
|
+
* @default undefined
|
|
131
|
+
*/
|
|
132
|
+
get logo() {
|
|
133
|
+
return this._logo;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Set the logo as a file path or buffer.
|
|
137
|
+
* @param value - The logo file path, buffer, or undefined to remove logo
|
|
138
|
+
*/
|
|
139
|
+
set logo(value) {
|
|
140
|
+
this._logo = value;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Get the logo size ratio relative to QR code size.
|
|
144
|
+
* @returns {number} The logo size ratio
|
|
145
|
+
* @default 0.2
|
|
146
|
+
*/
|
|
147
|
+
get logoSizeRatio() {
|
|
148
|
+
return this._logoSizeRatio;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Set the logo size ratio relative to QR code size.
|
|
152
|
+
* @param value - The logo size ratio (0.0 to 1.0)
|
|
153
|
+
*/
|
|
154
|
+
set logoSizeRatio(value) {
|
|
155
|
+
this._logoSizeRatio = value;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Get the background color of the QR code.
|
|
159
|
+
* @returns {string} The background color in hex format
|
|
160
|
+
* @default "#FFFFFF"
|
|
161
|
+
*/
|
|
162
|
+
get backgroundColor() {
|
|
163
|
+
return this._backgroundColor;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Set the background color of the QR code.
|
|
167
|
+
* @param value - The background color in hex format (e.g., "#FFFFFF")
|
|
168
|
+
*/
|
|
169
|
+
set backgroundColor(value) {
|
|
170
|
+
this._backgroundColor = value;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Get the foreground color of the QR code.
|
|
174
|
+
* @returns {string} The foreground color in hex format
|
|
175
|
+
* @default "#000000"
|
|
176
|
+
*/
|
|
177
|
+
get foregroundColor() {
|
|
178
|
+
return this._foregroundColor;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Set the foreground color of the QR code.
|
|
182
|
+
* @param value - The foreground color in hex format (e.g., "#000000")
|
|
183
|
+
*/
|
|
184
|
+
set foregroundColor(value) {
|
|
185
|
+
this._foregroundColor = value;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Get the cache instance.
|
|
189
|
+
* @returns {Cacheable | undefined} The cache instance or undefined if caching is disabled
|
|
190
|
+
*/
|
|
191
|
+
get cache() {
|
|
192
|
+
return this._cache;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Set the cache instance.
|
|
196
|
+
* @param value - The cache instance or undefined to disable caching
|
|
197
|
+
*/
|
|
198
|
+
set cache(value) {
|
|
199
|
+
this._cache = value;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Generate SVG QR code with optional caching.
|
|
203
|
+
* Uses QRCode library for simple cases, Rust implementation for logos.
|
|
204
|
+
* @param {toOptions} options - Generation options whether to use caching (default: true)
|
|
205
|
+
* @returns {Promise<string>} The SVG string
|
|
206
|
+
*/
|
|
207
|
+
async toSvg(options) {
|
|
208
|
+
let result = "";
|
|
209
|
+
let renderKey = `native-svg`;
|
|
210
|
+
if (this._logo) {
|
|
211
|
+
renderKey = `napi-svg`;
|
|
212
|
+
}
|
|
213
|
+
const qrOptions = {
|
|
214
|
+
text: this._text,
|
|
215
|
+
size: this._size,
|
|
216
|
+
margin: this._margin,
|
|
217
|
+
logo: this._logo,
|
|
218
|
+
logoSizeRatio: this._logoSizeRatio,
|
|
219
|
+
backgroundColor: this._backgroundColor,
|
|
220
|
+
foregroundColor: this._foregroundColor
|
|
221
|
+
};
|
|
222
|
+
if (this._cache && options?.cache !== false) {
|
|
223
|
+
const key = this.generateCacheKey(renderKey);
|
|
224
|
+
const cached = await this._cache.get(key);
|
|
225
|
+
if (cached) {
|
|
226
|
+
return cached;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (!this._logo) {
|
|
230
|
+
const qrCodeOptions = {
|
|
231
|
+
type: "svg",
|
|
232
|
+
width: qrOptions.size,
|
|
233
|
+
color: {
|
|
234
|
+
dark: qrOptions.foregroundColor,
|
|
235
|
+
light: qrOptions.backgroundColor
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
result = await import_qrcode.default.toString(this._text, qrCodeOptions);
|
|
239
|
+
} else {
|
|
240
|
+
result = await this.toSvgNapi();
|
|
241
|
+
}
|
|
242
|
+
if (this._cache && options?.cache !== false) {
|
|
243
|
+
const key = this.generateCacheKey(renderKey);
|
|
244
|
+
await this._cache.set(key, result);
|
|
245
|
+
}
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Generate SVG QR code using the native Rust implementation.
|
|
250
|
+
* Automatically chooses between file path and buffer functions.
|
|
251
|
+
* @returns {Promise<string>} The SVG string
|
|
252
|
+
*/
|
|
253
|
+
async toSvgNapi() {
|
|
254
|
+
if (this._logo && import_node_buffer.Buffer.isBuffer(this._logo)) {
|
|
255
|
+
const nativeOptionsBuffer = {
|
|
256
|
+
text: this._text,
|
|
257
|
+
size: this._size,
|
|
258
|
+
margin: this._margin,
|
|
259
|
+
logoBuffer: this._logo,
|
|
260
|
+
logoSizeRatio: this._logoSizeRatio,
|
|
261
|
+
backgroundColor: this._backgroundColor,
|
|
262
|
+
foregroundColor: this._foregroundColor
|
|
263
|
+
};
|
|
264
|
+
return this._napi.generateQrSvgWithBuffer(nativeOptionsBuffer);
|
|
265
|
+
} else {
|
|
266
|
+
const nativeOptions = {
|
|
267
|
+
text: this._text,
|
|
268
|
+
size: this._size,
|
|
269
|
+
margin: this._margin,
|
|
270
|
+
logoPath: this._logo,
|
|
271
|
+
logoSizeRatio: this._logoSizeRatio,
|
|
272
|
+
backgroundColor: this._backgroundColor,
|
|
273
|
+
foregroundColor: this._foregroundColor
|
|
274
|
+
};
|
|
275
|
+
if (this._logo && this.isLogoString()) {
|
|
276
|
+
if (!await this.logoFileExists(this._logo)) {
|
|
277
|
+
this.emit(
|
|
278
|
+
"error" /* error */,
|
|
279
|
+
logoFileDoesNotExistMessage(this._logo)
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return this._napi.generateQrSvg(nativeOptions);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Generate PNG QR code with optional caching.
|
|
288
|
+
* Generates the QR as Svg either in rust if it has a logo or native. Then does a conversion on it.
|
|
289
|
+
* @param options - Generation options
|
|
290
|
+
* @param options.cache - Whether to use caching (default: true)
|
|
291
|
+
* @returns {Promise<Buffer>} The PNG buffer
|
|
292
|
+
*/
|
|
293
|
+
async toPng(options) {
|
|
294
|
+
let result;
|
|
295
|
+
const renderKey = `napi-png`;
|
|
296
|
+
if (this._cache && options?.cache !== false) {
|
|
297
|
+
const key = this.generateCacheKey(renderKey);
|
|
298
|
+
const cached = await this._cache.get(key);
|
|
299
|
+
if (cached) {
|
|
300
|
+
return import_node_buffer.Buffer.from(cached);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
const svg = await this.toSvg();
|
|
304
|
+
result = _QrBit.convertSvgToPng(svg);
|
|
305
|
+
if (this._cache && options?.cache !== false) {
|
|
306
|
+
const key = this.generateCacheKey(renderKey);
|
|
307
|
+
await this._cache.set(key, result);
|
|
308
|
+
}
|
|
309
|
+
return result;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Generate PNG QR code and save it to a file.
|
|
313
|
+
* Creates directories if they don't exist.
|
|
314
|
+
* @param filePath - The file path where to save the PNG
|
|
315
|
+
* @param options - Generation options
|
|
316
|
+
* @param options.cache - Whether to use caching (default: true)
|
|
317
|
+
* @returns {Promise<void>} Resolves when file is written
|
|
318
|
+
*/
|
|
319
|
+
async toPngFile(filePath, options) {
|
|
320
|
+
const pngBuffer = await this.toPng(options);
|
|
321
|
+
const dir = import_node_path.default.dirname(filePath);
|
|
322
|
+
await import_node_fs.default.promises.mkdir(dir, { recursive: true });
|
|
323
|
+
await import_node_fs.default.promises.writeFile(filePath, pngBuffer);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Generate SVG QR code and save it to a file.
|
|
327
|
+
* Creates directories if they don't exist.
|
|
328
|
+
* @param filePath - The file path where to save the SVG
|
|
329
|
+
* @param options - Generation options
|
|
330
|
+
* @param options.cache - Whether to use caching (default: true)
|
|
331
|
+
* @returns {Promise<void>} Resolves when file is written
|
|
332
|
+
*/
|
|
333
|
+
async toSvgFile(filePath, options) {
|
|
334
|
+
const svgString = await this.toSvg(options);
|
|
335
|
+
const dir = import_node_path.default.dirname(filePath);
|
|
336
|
+
await import_node_fs.default.promises.mkdir(dir, { recursive: true });
|
|
337
|
+
await import_node_fs.default.promises.writeFile(filePath, svgString, "utf8");
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Convert SVG content to PNG buffer using the native Rust implementation.
|
|
341
|
+
* @param svgContent - The SVG content as a string
|
|
342
|
+
* @param width - Optional width for the PNG output
|
|
343
|
+
* @param height - Optional height for the PNG output
|
|
344
|
+
* @returns {Buffer} The PNG buffer
|
|
345
|
+
*/
|
|
346
|
+
static convertSvgToPng(svgContent, width, height) {
|
|
347
|
+
return (0, import_native.convertSvgToPng)(svgContent, width, height);
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Generate a cache key based on the current QR code options.
|
|
351
|
+
* @param {string} renderKey the format that you are rendering in such as `napi-png`, `native-svg`, `napi-svg`
|
|
352
|
+
* @returns {string} The cache key
|
|
353
|
+
*/
|
|
354
|
+
generateCacheKey(renderKey) {
|
|
355
|
+
const qrOptions = {
|
|
356
|
+
text: this._text,
|
|
357
|
+
size: this._size,
|
|
358
|
+
margin: this._margin,
|
|
359
|
+
logo: this._logo || void 0,
|
|
360
|
+
logoSizeRatio: this._logoSizeRatio,
|
|
361
|
+
backgroundColor: this._backgroundColor,
|
|
362
|
+
foregroundColor: this._foregroundColor,
|
|
363
|
+
renderKey
|
|
364
|
+
};
|
|
365
|
+
const cache = this._cache || new import_cacheable.Cacheable();
|
|
366
|
+
return cache.hash(qrOptions);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Check if the logo is a string (file path).
|
|
370
|
+
* @returns {boolean} True if logo is a string, false otherwise
|
|
371
|
+
*/
|
|
372
|
+
isLogoString() {
|
|
373
|
+
return typeof this._logo === "string";
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Check if a logo file exists at the specified path.
|
|
377
|
+
* @param filePath - The file path to check
|
|
378
|
+
* @returns {Promise<boolean>} True if file exists, false otherwise
|
|
379
|
+
*/
|
|
380
|
+
async logoFileExists(filePath) {
|
|
381
|
+
try {
|
|
382
|
+
await import_node_fs.default.promises.access(filePath, import_node_fs.default.constants.F_OK);
|
|
383
|
+
return true;
|
|
384
|
+
} catch (_error) {
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
390
|
+
0 && (module.exports = {
|
|
391
|
+
QrBit,
|
|
392
|
+
QrBitEvents
|
|
393
|
+
});
|
|
394
|
+
//# sourceMappingURL=qrbit.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/qrbit.ts"],"sourcesContent":["import { Buffer } from \"node:buffer\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { Cacheable } from \"cacheable\";\nimport { Hookified, type HookifiedOptions } from \"hookified\";\nimport QRCode, { type QRCodeToStringOptions } from \"qrcode\";\nimport {\n\tconvertSvgToPng as nativeConvertSvgToPng,\n\tgenerateQr as nativeGenerateQr,\n\tgenerateQrPng as nativeGenerateQrPng,\n\tgenerateQrPngWithBuffer as nativeGenerateQrPngWithBuffer,\n\tgenerateQrSvg as nativeGenerateQrSvg,\n\tgenerateQrSvgWithBuffer as nativeGenerateQrSvgWithBuffer,\n} from \"./native.js\";\n\nexport enum QrBitEvents {\n\twarn = \"warn\",\n\tinfo = \"info\",\n\terror = \"error\",\n}\n\nconst logoFileDoesNotExistMessage = (logo: string) =>\n\t`Logo file not found: ${logo}. Proceeding without logo.`;\n\nexport type QrOptions = {\n\t/**\n\t * The text content to encode in the QR code. It can be text or a url.\n\t * @type {string}\n\t */\n\ttext: string;\n\t/**\n\t * The size of the QR code in pixels.\n\t * @type {number}\n\t * @default 200\n\t */\n\tsize?: number;\n\t/**\n\t * The margin around the QR code in pixels.\n\t * @type {number}\n\t */\n\tmargin?: number;\n\t/**\n\t * The logo to embed in the QR code.\n\t * @type {string | Buffer}\n\t */\n\tlogo?: string | Buffer;\n\t/**\n\t * The logo size ratio relative to QR code size.\n\t * @type {number}\n\t * @default 0.2\n\t */\n\tlogoSizeRatio?: number;\n\t/**\n\t * The background color of the QR code.\n\t * @type {string}\n\t * @default \"#FFFFFF\"\n\t */\n\tbackgroundColor?: string;\n\t/**\n\t * The foreground color of the QR code.\n\t * @type {string}\n\t * @default \"#000000\"\n\t */\n\tforegroundColor?: string;\n\t/**\n\t * Caching is enabled by default. You can disable it by setting this option to false. You can also pass\n\t * a custom Cacheable instance.\n\t * @type {Cacheable | boolean}\n\t * @default true\n\t */\n\tcache?: Cacheable | boolean;\n} & HookifiedOptions;\n\nexport interface QrResult {\n\tsvg?: string;\n\tpng?: Buffer;\n\twidth: number;\n\theight: number;\n}\n\nexport type toOptions = {\n\tcache?: boolean;\n};\n\n/**\n * QR code generator with logo support and caching capabilities.\n * Supports both file path and buffer-based logos with automatic optimization.\n */\nexport class QrBit extends Hookified {\n\tprivate _text: string;\n\tprivate _size: number;\n\tprivate _margin: number | undefined;\n\tprivate _logo: string | Buffer | undefined;\n\tprivate _logoSizeRatio: number;\n\tprivate _backgroundColor: string;\n\tprivate _foregroundColor: string;\n\tprivate _cache: Cacheable | undefined;\n\tprivate _napi = {\n\t\tconvertSvgToPng: nativeConvertSvgToPng,\n\t\tgenerateQr: nativeGenerateQr,\n\t\tgenerateQrPng: nativeGenerateQrPng,\n\t\tgenerateQrPngWithBuffer: nativeGenerateQrPngWithBuffer,\n\t\tgenerateQrSvg: nativeGenerateQrSvg,\n\t\tgenerateQrSvgWithBuffer: nativeGenerateQrSvgWithBuffer,\n\t};\n\n\t/**\n\t * Create a new QrBit instance.\n\t * @param options - Configuration options for the QR code\n\t */\n\tconstructor(options: QrOptions) {\n\t\tsuper();\n\t\tthis._text = options.text;\n\t\tthis._size = options.size ?? 200;\n\t\tthis._margin = options.margin ?? undefined;\n\t\tthis._logo = options.logo;\n\t\tthis._logoSizeRatio = options.logoSizeRatio ?? 0.2;\n\t\tthis._backgroundColor = options.backgroundColor ?? \"#FFFFFF\";\n\t\tthis._foregroundColor = options.foregroundColor ?? \"#000000\";\n\t\tif (options.cache !== undefined) {\n\t\t\t// if it is boolean and true then create a new cacheable instance\n\t\t\tif (options.cache === true) {\n\t\t\t\tthis._cache = new Cacheable();\n\t\t\t} else if (options.cache !== false) {\n\t\t\t\t// it is a cacheable instance\n\t\t\t\tthis._cache = options.cache as Cacheable;\n\t\t\t}\n\t\t} else {\n\t\t\tthis._cache = new Cacheable();\n\t\t}\n\n\t\t// set throwOnEmitError to true if there are no listeners\n\t\tthis.throwOnEmitError = true;\n\t}\n\n\t/**\n\t * Get the text content for the QR code.\n\t * @returns {string} The text content\n\t */\n\tpublic get text(): string {\n\t\treturn this._text;\n\t}\n\n\t/**\n\t * Set the text content for the QR code.\n\t * @param value - The text content to encode\n\t */\n\tpublic set text(value: string) {\n\t\tthis._text = value;\n\t}\n\n\t/**\n\t * Get the size of the QR code in pixels.\n\t * @returns {number} The size in pixels\n\t * @default 200\n\t */\n\tpublic get size(): number {\n\t\treturn this._size;\n\t}\n\n\t/**\n\t * Set the size of the QR code in pixels.\n\t * @param value - The size in pixels\n\t */\n\tpublic set size(value: number) {\n\t\tthis._size = value;\n\t}\n\n\t/**\n\t * Get the margin around the QR code in pixels.\n\t * @returns {number | undefined} The margin in pixels\n\t */\n\tpublic get margin(): number | undefined {\n\t\treturn this._margin;\n\t}\n\n\t/**\n\t * Set the margin around the QR code in pixels.\n\t * @param value - The margin in pixels\n\t */\n\tpublic set margin(value: number | undefined) {\n\t\tthis._margin = value;\n\t}\n\n\t/**\n\t * Get the logo path or buffer.\n\t * @returns {string | Buffer | undefined} The logo path, buffer, or undefined if no logo\n\t * @default undefined\n\t */\n\tpublic get logo(): string | Buffer | undefined {\n\t\treturn this._logo;\n\t}\n\n\t/**\n\t * Set the logo as a file path or buffer.\n\t * @param value - The logo file path, buffer, or undefined to remove logo\n\t */\n\tpublic set logo(value: string | Buffer | undefined) {\n\t\tthis._logo = value;\n\t}\n\n\t/**\n\t * Get the logo size ratio relative to QR code size.\n\t * @returns {number} The logo size ratio\n\t * @default 0.2\n\t */\n\tpublic get logoSizeRatio(): number {\n\t\treturn this._logoSizeRatio;\n\t}\n\n\t/**\n\t * Set the logo size ratio relative to QR code size.\n\t * @param value - The logo size ratio (0.0 to 1.0)\n\t */\n\tpublic set logoSizeRatio(value: number) {\n\t\tthis._logoSizeRatio = value;\n\t}\n\n\t/**\n\t * Get the background color of the QR code.\n\t * @returns {string} The background color in hex format\n\t * @default \"#FFFFFF\"\n\t */\n\tpublic get backgroundColor(): string {\n\t\treturn this._backgroundColor;\n\t}\n\n\t/**\n\t * Set the background color of the QR code.\n\t * @param value - The background color in hex format (e.g., \"#FFFFFF\")\n\t */\n\tpublic set backgroundColor(value: string) {\n\t\tthis._backgroundColor = value;\n\t}\n\n\t/**\n\t * Get the foreground color of the QR code.\n\t * @returns {string} The foreground color in hex format\n\t * @default \"#000000\"\n\t */\n\tpublic get foregroundColor(): string {\n\t\treturn this._foregroundColor;\n\t}\n\n\t/**\n\t * Set the foreground color of the QR code.\n\t * @param value - The foreground color in hex format (e.g., \"#000000\")\n\t */\n\tpublic set foregroundColor(value: string) {\n\t\tthis._foregroundColor = value;\n\t}\n\n\t/**\n\t * Get the cache instance.\n\t * @returns {Cacheable | undefined} The cache instance or undefined if caching is disabled\n\t */\n\tpublic get cache(): Cacheable | undefined {\n\t\treturn this._cache;\n\t}\n\n\t/**\n\t * Set the cache instance.\n\t * @param value - The cache instance or undefined to disable caching\n\t */\n\tpublic set cache(value: Cacheable | undefined) {\n\t\tthis._cache = value;\n\t}\n\n\t/**\n\t * Generate SVG QR code with optional caching.\n\t * Uses QRCode library for simple cases, Rust implementation for logos.\n\t * @param {toOptions} options - Generation options whether to use caching (default: true)\n\t * @returns {Promise<string>} The SVG string\n\t */\n\tpublic async toSvg(options?: toOptions): Promise<string> {\n\t\tlet result = \"\";\n\t\tlet renderKey = `native-svg`;\n\n\t\tif (this._logo) {\n\t\t\trenderKey = `napi-svg`;\n\t\t}\n\n\t\t// set all the options\n\t\tconst qrOptions = {\n\t\t\ttext: this._text,\n\t\t\tsize: this._size,\n\t\t\tmargin: this._margin,\n\t\t\tlogo: this._logo,\n\t\t\tlogoSizeRatio: this._logoSizeRatio,\n\t\t\tbackgroundColor: this._backgroundColor,\n\t\t\tforegroundColor: this._foregroundColor,\n\t\t};\n\n\t\t// check the cache\n\t\tif (this._cache && options?.cache !== false) {\n\t\t\tconst key = this.generateCacheKey(renderKey);\n\t\t\tconst cached = await this._cache.get<string>(key);\n\t\t\tif (cached) {\n\t\t\t\treturn cached;\n\t\t\t}\n\t\t}\n\n\t\tif (!this._logo) {\n\t\t\tconst qrCodeOptions: QRCodeToStringOptions = {\n\t\t\t\ttype: \"svg\",\n\t\t\t\twidth: qrOptions.size,\n\t\t\t\tcolor: {\n\t\t\t\t\tdark: qrOptions.foregroundColor,\n\t\t\t\t\tlight: qrOptions.backgroundColor,\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tresult = await QRCode.toString(this._text, qrCodeOptions);\n\t\t} else {\n\t\t\t// If logoPath is set, use the Rust implementation\n\t\t\tresult = await this.toSvgNapi();\n\t\t}\n\n\t\tif (this._cache && options?.cache !== false) {\n\t\t\t// set the cache, generate the key from hash\n\t\t\tconst key = this.generateCacheKey(renderKey);\n\t\t\t// cache the value\n\t\t\tawait this._cache.set(key, result);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Generate SVG QR code using the native Rust implementation.\n\t * Automatically chooses between file path and buffer functions.\n\t * @returns {Promise<string>} The SVG string\n\t */\n\tpublic async toSvgNapi(): Promise<string> {\n\t\t// Choose optimal path based on logo type\n\t\tif (this._logo && Buffer.isBuffer(this._logo)) {\n\t\t\t// Logo is already a buffer - use buffer function\n\t\t\tconst nativeOptionsBuffer = {\n\t\t\t\ttext: this._text,\n\t\t\t\tsize: this._size,\n\t\t\t\tmargin: this._margin,\n\t\t\t\tlogoBuffer: this._logo,\n\t\t\t\tlogoSizeRatio: this._logoSizeRatio,\n\t\t\t\tbackgroundColor: this._backgroundColor,\n\t\t\t\tforegroundColor: this._foregroundColor,\n\t\t\t};\n\t\t\treturn this._napi.generateQrSvgWithBuffer(nativeOptionsBuffer);\n\t\t} else {\n\t\t\t// Logo is a string path or undefined - use original function\n\t\t\tconst nativeOptions = {\n\t\t\t\ttext: this._text,\n\t\t\t\tsize: this._size,\n\t\t\t\tmargin: this._margin,\n\t\t\t\tlogoPath: this._logo as string,\n\t\t\t\tlogoSizeRatio: this._logoSizeRatio,\n\t\t\t\tbackgroundColor: this._backgroundColor,\n\t\t\t\tforegroundColor: this._foregroundColor,\n\t\t\t};\n\n\t\t\tif (this._logo && this.isLogoString()) {\n\t\t\t\tif (!(await this.logoFileExists(this._logo as string))) {\n\t\t\t\t\tthis.emit(\n\t\t\t\t\t\tQrBitEvents.error,\n\t\t\t\t\t\tlogoFileDoesNotExistMessage(this._logo as string),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn this._napi.generateQrSvg(nativeOptions);\n\t\t}\n\t}\n\n\t/**\n\t * Generate PNG QR code with optional caching.\n\t * Generates the QR as Svg either in rust if it has a logo or native. Then does a conversion on it.\n\t * @param options - Generation options\n\t * @param options.cache - Whether to use caching (default: true)\n\t * @returns {Promise<Buffer>} The PNG buffer\n\t */\n\tpublic async toPng(options?: toOptions): Promise<Buffer> {\n\t\tlet result: Buffer;\n\t\tconst renderKey = `napi-png`;\n\n\t\t// check the cache\n\t\tif (this._cache && options?.cache !== false) {\n\t\t\tconst key = this.generateCacheKey(renderKey);\n\t\t\tconst cached = await this._cache.get<Buffer>(key);\n\t\t\tif (cached) {\n\t\t\t\t// Ensure we return a Buffer, not Uint8Array\n\t\t\t\treturn Buffer.from(cached);\n\t\t\t}\n\t\t}\n\n\t\tconst svg = await this.toSvg();\n\t\tresult = QrBit.convertSvgToPng(svg);\n\n\t\tif (this._cache && options?.cache !== false) {\n\t\t\t// set the cache, generate the key from hash\n\t\t\tconst key = this.generateCacheKey(renderKey);\n\t\t\t// cache the value\n\t\t\tawait this._cache.set(key, result);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Generate PNG QR code and save it to a file.\n\t * Creates directories if they don't exist.\n\t * @param filePath - The file path where to save the PNG\n\t * @param options - Generation options\n\t * @param options.cache - Whether to use caching (default: true)\n\t * @returns {Promise<void>} Resolves when file is written\n\t */\n\tpublic async toPngFile(filePath: string, options?: toOptions): Promise<void> {\n\t\tconst pngBuffer = await this.toPng(options);\n\n\t\t// Create directory if it doesn't exist\n\t\tconst dir = path.dirname(filePath);\n\t\tawait fs.promises.mkdir(dir, { recursive: true });\n\n\t\tawait fs.promises.writeFile(filePath, pngBuffer);\n\t}\n\n\t/**\n\t * Generate SVG QR code and save it to a file.\n\t * Creates directories if they don't exist.\n\t * @param filePath - The file path where to save the SVG\n\t * @param options - Generation options\n\t * @param options.cache - Whether to use caching (default: true)\n\t * @returns {Promise<void>} Resolves when file is written\n\t */\n\tpublic async toSvgFile(filePath: string, options?: toOptions): Promise<void> {\n\t\tconst svgString = await this.toSvg(options);\n\n\t\t// Create directory if it doesn't exist\n\t\tconst dir = path.dirname(filePath);\n\t\tawait fs.promises.mkdir(dir, { recursive: true });\n\n\t\tawait fs.promises.writeFile(filePath, svgString, \"utf8\");\n\t}\n\n\t/**\n\t * Convert SVG content to PNG buffer using the native Rust implementation.\n\t * @param svgContent - The SVG content as a string\n\t * @param width - Optional width for the PNG output\n\t * @param height - Optional height for the PNG output\n\t * @returns {Buffer} The PNG buffer\n\t */\n\tpublic static convertSvgToPng(\n\t\tsvgContent: string,\n\t\twidth?: number,\n\t\theight?: number,\n\t): Buffer {\n\t\treturn nativeConvertSvgToPng(svgContent, width, height);\n\t}\n\n\t/**\n\t * Generate a cache key based on the current QR code options.\n\t * @param {string} renderKey the format that you are rendering in such as `napi-png`, `native-svg`, `napi-svg`\n\t * @returns {string} The cache key\n\t */\n\tpublic generateCacheKey(renderKey: string): string {\n\t\tconst qrOptions = {\n\t\t\ttext: this._text,\n\t\t\tsize: this._size,\n\t\t\tmargin: this._margin,\n\t\t\tlogo: this._logo || undefined,\n\t\t\tlogoSizeRatio: this._logoSizeRatio,\n\t\t\tbackgroundColor: this._backgroundColor,\n\t\t\tforegroundColor: this._foregroundColor,\n\t\t\trenderKey,\n\t\t};\n\n\t\tconst cache = this._cache || new Cacheable();\n\n\t\treturn cache.hash(qrOptions);\n\t}\n\n\t/**\n\t * Check if the logo is a string (file path).\n\t * @returns {boolean} True if logo is a string, false otherwise\n\t */\n\tpublic isLogoString(): boolean {\n\t\treturn typeof this._logo === \"string\";\n\t}\n\n\t/**\n\t * Check if a logo file exists at the specified path.\n\t * @param filePath - The file path to check\n\t * @returns {Promise<boolean>} True if file exists, false otherwise\n\t */\n\tpublic async logoFileExists(filePath: string): Promise<boolean> {\n\t\ttry {\n\t\t\tawait fs.promises.access(filePath, fs.constants.F_OK);\n\t\t\treturn true;\n\t\t} catch (_error) {\n\t\t\treturn false;\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAuB;AACvB,qBAAe;AACf,uBAAiB;AACjB,uBAA0B;AAC1B,uBAAiD;AACjD,oBAAmD;AACnD,oBAOO;AAEA,IAAK,cAAL,kBAAKA,iBAAL;AACN,EAAAA,aAAA,UAAO;AACP,EAAAA,aAAA,UAAO;AACP,EAAAA,aAAA,WAAQ;AAHG,SAAAA;AAAA,GAAA;AAMZ,IAAM,8BAA8B,CAAC,SACpC,wBAAwB,IAAI;AAkEtB,IAAM,QAAN,MAAM,eAAc,2BAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBpC,YAAY,SAAoB;AAC/B,UAAM;AAdP,SAAQ,QAAQ;AAAA,MACf,iBAAiB,cAAAC;AAAA,MACjB,YAAY,cAAAC;AAAA,MACZ,eAAe,cAAAC;AAAA,MACf,yBAAyB,cAAAC;AAAA,MACzB,eAAe,cAAAC;AAAA,MACf,yBAAyB,cAAAC;AAAA,IAC1B;AAQC,SAAK,QAAQ,QAAQ;AACrB,SAAK,QAAQ,QAAQ,QAAQ;AAC7B,SAAK,UAAU,QAAQ,UAAU;AACjC,SAAK,QAAQ,QAAQ;AACrB,SAAK,iBAAiB,QAAQ,iBAAiB;AAC/C,SAAK,mBAAmB,QAAQ,mBAAmB;AACnD,SAAK,mBAAmB,QAAQ,mBAAmB;AACnD,QAAI,QAAQ,UAAU,QAAW;AAEhC,UAAI,QAAQ,UAAU,M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MACtB;AAAA,IACD;AAEA,UAAM,QAAQ,KAAK,UAAU,IAAI,2BAAU;AAE3C,WAAO,MAAM,KAAK,SAAS;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,eAAwB;AAC9B,WAAO,OAAO,KAAK,UAAU;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAa,eAAe,UAAoC;AAC/D,QAAI;AACH,YAAM,eAAAQ,QAAG,SAAS,OAAO,UAAU,eAAAA,QAAG,UAAU,IAAI;AACpD,aAAO;AAAA,IACR,SAAS,QAAQ;AAChB,aAAO;AAAA,IACR;AAAA,EACD;AACD;","names":["QrBitEvents","nativeConvertSvgToPng","nativeGenerateQr","nativeGenerateQrPng","nativeGenerateQrPngWithBuffer","nativeGenerateQrSvg","nativeGenerateQrSvgWithBuffer","QRCode","path","fs"]}
|
package/dist/qrbit.d.cts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { Cacheable } from 'cacheable';
|
|
3
|
+
import { HookifiedOptions, Hookified } from 'hookified';
|
|
4
|
+
|
|
5
|
+
declare enum QrBitEvents {
|
|
6
|
+
warn = "warn",
|
|
7
|
+
info = "info",
|
|
8
|
+
error = "error"
|
|
9
|
+
}
|
|
10
|
+
type QrOptions = {
|
|
11
|
+
/**
|
|
12
|
+
* The text content to encode in the QR code. It can be text or a url.
|
|
13
|
+
* @type {string}
|
|
14
|
+
*/
|
|
15
|
+
text: string;
|
|
16
|
+
/**
|
|
17
|
+
* The size of the QR code in pixels.
|
|
18
|
+
* @type {number}
|
|
19
|
+
* @default 200
|
|
20
|
+
*/
|
|
21
|
+
size?: number;
|
|
22
|
+
/**
|
|
23
|
+
* The margin around the QR code in pixels.
|
|
24
|
+
* @type {number}
|
|
25
|
+
*/
|
|
26
|
+
margin?: number;
|
|
27
|
+
/**
|
|
28
|
+
* The logo to embed in the QR code.
|
|
29
|
+
* @type {string | Buffer}
|
|
30
|
+
*/
|
|
31
|
+
logo?: string | Buffer;
|
|
32
|
+
/**
|
|
33
|
+
* The logo size ratio relative to QR code size.
|
|
34
|
+
* @type {number}
|
|
35
|
+
* @default 0.2
|
|
36
|
+
*/
|
|
37
|
+
logoSizeRatio?: number;
|
|
38
|
+
/**
|
|
39
|
+
* The background color of the QR code.
|
|
40
|
+
* @type {string}
|
|
41
|
+
* @default "#FFFFFF"
|
|
42
|
+
*/
|
|
43
|
+
backgroundColor?: string;
|
|
44
|
+
/**
|
|
45
|
+
* The foreground color of the QR code.
|
|
46
|
+
* @type {string}
|
|
47
|
+
* @default "#000000"
|
|
48
|
+
*/
|
|
49
|
+
foregroundColor?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Caching is enabled by default. You can disable it by setting this option to false. You can also pass
|
|
52
|
+
* a custom Cacheable instance.
|
|
53
|
+
* @type {Cacheable | boolean}
|
|
54
|
+
* @default true
|
|
55
|
+
*/
|
|
56
|
+
cache?: Cacheable | boolean;
|
|
57
|
+
} & HookifiedOptions;
|
|
58
|
+
interface QrResult {
|
|
59
|
+
svg?: string;
|
|
60
|
+
png?: Buffer;
|
|
61
|
+
width: number;
|
|
62
|
+
height: number;
|
|
63
|
+
}
|
|
64
|
+
type toOptions = {
|
|
65
|
+
cache?: boolean;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* QR code generator with logo support and caching capabilities.
|
|
69
|
+
* Supports both file path and buffer-based logos with automatic optimization.
|
|
70
|
+
*/
|
|
71
|
+
declare class QrBit extends Hookified {
|
|
72
|
+
private _text;
|
|
73
|
+
private _size;
|
|
74
|
+
private _margin;
|
|
75
|
+
private _logo;
|
|
76
|
+
private _logoSizeRatio;
|
|
77
|
+
private _backgroundColor;
|
|
78
|
+
private _foregroundColor;
|
|
79
|
+
private _cache;
|
|
80
|
+
private _napi;
|
|
81
|
+
/**
|
|
82
|
+
* Create a new QrBit instance.
|
|
83
|
+
* @param options - Configuration options for the QR code
|
|
84
|
+
*/
|
|
85
|
+
constructor(options: QrOptions);
|
|
86
|
+
/**
|
|
87
|
+
* Get the text content for the QR code.
|
|
88
|
+
* @returns {string} The text content
|
|
89
|
+
*/
|
|
90
|
+
get text(): string;
|
|
91
|
+
/**
|
|
92
|
+
* Set the text content for the QR code.
|
|
93
|
+
* @param value - The text content to encode
|
|
94
|
+
*/
|
|
95
|
+
set text(value: string);
|
|
96
|
+
/**
|
|
97
|
+
* Get the size of the QR code in pixels.
|
|
98
|
+
* @returns {number} The size in pixels
|
|
99
|
+
* @default 200
|
|
100
|
+
*/
|
|
101
|
+
get size(): number;
|
|
102
|
+
/**
|
|
103
|
+
* Set the size of the QR code in pixels.
|
|
104
|
+
* @param value - The size in pixels
|
|
105
|
+
*/
|
|
106
|
+
set size(value: number);
|
|
107
|
+
/**
|
|
108
|
+
* Get the margin around the QR code in pixels.
|
|
109
|
+
* @returns {number | undefined} The margin in pixels
|
|
110
|
+
*/
|
|
111
|
+
get margin(): number | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* Set the margin around the QR code in pixels.
|
|
114
|
+
* @param value - The margin in pixels
|
|
115
|
+
*/
|
|
116
|
+
set margin(value: number | undefined);
|
|
117
|
+
/**
|
|
118
|
+
* Get the logo path or buffer.
|
|
119
|
+
* @returns {string | Buffer | undefined} The logo path, buffer, or undefined if no logo
|
|
120
|
+
* @default undefined
|
|
121
|
+
*/
|
|
122
|
+
get logo(): string | Buffer | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Set the logo as a file path or buffer.
|
|
125
|
+
* @param value - The logo file path, buffer, or undefined to remove logo
|
|
126
|
+
*/
|
|
127
|
+
set logo(value: string | Buffer | undefined);
|
|
128
|
+
/**
|
|
129
|
+
* Get the logo size ratio relative to QR code size.
|
|
130
|
+
* @returns {number} The logo size ratio
|
|
131
|
+
* @default 0.2
|
|
132
|
+
*/
|
|
133
|
+
get logoSizeRatio(): number;
|
|
134
|
+
/**
|
|
135
|
+
* Set the logo size ratio relative to QR code size.
|
|
136
|
+
* @param value - The logo size ratio (0.0 to 1.0)
|
|
137
|
+
*/
|
|
138
|
+
set logoSizeRatio(value: number);
|
|
139
|
+
/**
|
|
140
|
+
* Get the background color of the QR code.
|
|
141
|
+
* @returns {string} The background color in hex format
|
|
142
|
+
* @default "#FFFFFF"
|
|
143
|
+
*/
|
|
144
|
+
get backgroundColor(): string;
|
|
145
|
+
/**
|
|
146
|
+
* Set the background color of the QR code.
|
|
147
|
+
* @param value - The background color in hex format (e.g., "#FFFFFF")
|
|
148
|
+
*/
|
|
149
|
+
set backgroundColor(value: string);
|
|
150
|
+
/**
|
|
151
|
+
* Get the foreground color of the QR code.
|
|
152
|
+
* @returns {string} The foreground color in hex format
|
|
153
|
+
* @default "#000000"
|
|
154
|
+
*/
|
|
155
|
+
get foregroundColor(): string;
|
|
156
|
+
/**
|
|
157
|
+
* Set the foreground color of the QR code.
|
|
158
|
+
* @param value - The foreground color in hex format (e.g., "#000000")
|
|
159
|
+
*/
|
|
160
|
+
set foregroundColor(value: string);
|
|
161
|
+
/**
|
|
162
|
+
* Get the cache instance.
|
|
163
|
+
* @returns {Cacheable | undefined} The cache instance or undefined if caching is disabled
|
|
164
|
+
*/
|
|
165
|
+
get cache(): Cacheable | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* Set the cache instance.
|
|
168
|
+
* @param value - The cache instance or undefined to disable caching
|
|
169
|
+
*/
|
|
170
|
+
set cache(value: Cacheable | undefined);
|
|
171
|
+
/**
|
|
172
|
+
* Generate SVG QR code with optional caching.
|
|
173
|
+
* Uses QRCode library for simple cases, Rust implementation for logos.
|
|
174
|
+
* @param {toOptions} options - Generation options whether to use caching (default: true)
|
|
175
|
+
* @returns {Promise<string>} The SVG string
|
|
176
|
+
*/
|
|
177
|
+
toSvg(options?: toOptions): Promise<string>;
|
|
178
|
+
/**
|
|
179
|
+
* Generate SVG QR code using the native Rust implementation.
|
|
180
|
+
* Automatically chooses between file path and buffer functions.
|
|
181
|
+
* @returns {Promise<string>} The SVG string
|
|
182
|
+
*/
|
|
183
|
+
toSvgNapi(): Promise<string>;
|
|
184
|
+
/**
|
|
185
|
+
* Generate PNG QR code with optional caching.
|
|
186
|
+
* Generates the QR as Svg either in rust if it has a logo or native. Then does a conversion on it.
|
|
187
|
+
* @param options - Generation options
|
|
188
|
+
* @param options.cache - Whether to use caching (default: true)
|
|
189
|
+
* @returns {Promise<Buffer>} The PNG buffer
|
|
190
|
+
*/
|
|
191
|
+
toPng(options?: toOptions): Promise<Buffer>;
|
|
192
|
+
/**
|
|
193
|
+
* Generate PNG QR code and save it to a file.
|
|
194
|
+
* Creates directories if they don't exist.
|
|
195
|
+
* @param filePath - The file path where to save the PNG
|
|
196
|
+
* @param options - Generation options
|
|
197
|
+
* @param options.cache - Whether to use caching (default: true)
|
|
198
|
+
* @returns {Promise<void>} Resolves when file is written
|
|
199
|
+
*/
|
|
200
|
+
toPngFile(filePath: string, options?: toOptions): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* Generate SVG QR code and save it to a file.
|
|
203
|
+
* Creates directories if they don't exist.
|
|
204
|
+
* @param filePath - The file path where to save the SVG
|
|
205
|
+
* @param options - Generation options
|
|
206
|
+
* @param options.cache - Whether to use caching (default: true)
|
|
207
|
+
* @returns {Promise<void>} Resolves when file is written
|
|
208
|
+
*/
|
|
209
|
+
toSvgFile(filePath: string, options?: toOptions): Promise<void>;
|
|
210
|
+
/**
|
|
211
|
+
* Convert SVG content to PNG buffer using the native Rust implementation.
|
|
212
|
+
* @param svgContent - The SVG content as a string
|
|
213
|
+
* @param width - Optional width for the PNG output
|
|
214
|
+
* @param height - Optional height for the PNG output
|
|
215
|
+
* @returns {Buffer} The PNG buffer
|
|
216
|
+
*/
|
|
217
|
+
static convertSvgToPng(svgContent: string, width?: number, height?: number): Buffer;
|
|
218
|
+
/**
|
|
219
|
+
* Generate a cache key based on the current QR code options.
|
|
220
|
+
* @param {string} renderKey the format that you are rendering in such as `napi-png`, `native-svg`, `napi-svg`
|
|
221
|
+
* @returns {string} The cache key
|
|
222
|
+
*/
|
|
223
|
+
generateCacheKey(renderKey: string): string;
|
|
224
|
+
/**
|
|
225
|
+
* Check if the logo is a string (file path).
|
|
226
|
+
* @returns {boolean} True if logo is a string, false otherwise
|
|
227
|
+
*/
|
|
228
|
+
isLogoString(): boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Check if a logo file exists at the specified path.
|
|
231
|
+
* @param filePath - The file path to check
|
|
232
|
+
* @returns {Promise<boolean>} True if file exists, false otherwise
|
|
233
|
+
*/
|
|
234
|
+
logoFileExists(filePath: string): Promise<boolean>;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export { QrBit, QrBitEvents, type QrOptions, type QrResult, type toOptions };
|