qrdx 0.0.49 → 0.0.50
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 +13 -1
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -7
- package/dist/index.mjs.map +1 -1
- package/dist/node.js +6 -0
- package/dist/node.js.map +1 -0
- package/dist/node.mjs +6 -0
- package/dist/node.mjs.map +1 -0
- package/dist/qr-code-canvas.js +1 -1
- package/dist/qr-code-canvas.js.map +1 -1
- package/dist/qr-code-canvas.mjs +1 -1
- package/dist/qr-code-canvas.mjs.map +1 -1
- package/dist/src/api.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/node.d.ts +23 -0
- package/dist/src/node.d.ts.map +1 -0
- package/dist/src/part-markers.d.ts +15 -0
- package/dist/src/part-markers.d.ts.map +1 -0
- package/dist/src/qr-code-canvas.d.ts.map +1 -1
- package/dist/src/qr-code.d.ts +1 -1
- package/dist/src/qr-code.d.ts.map +1 -1
- package/dist/src/rasterize.d.ts +25 -0
- package/dist/src/rasterize.d.ts.map +1 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/types/qr.d.ts +1 -0
- package/dist/types/qr.d.ts.map +1 -1
- package/package.json +21 -2
- package/src/api.tsx +1 -0
- package/src/index.tsx +10 -1
- package/src/node.ts +61 -0
- package/src/part-markers.ts +40 -0
- package/src/qr-code-canvas.tsx +1 -0
- package/src/qr-code.tsx +2 -0
- package/src/rasterize.ts +282 -0
- package/src/utils.tsx +62 -19
- package/types/qr.ts +5 -0
package/README.md
CHANGED
|
@@ -11,10 +11,11 @@ npm install qrdx
|
|
|
11
11
|
# or: pnpm add qrdx / yarn add qrdx
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
`react` and `react-dom` (18 or newer) are peer dependencies. PDF export also needs the optional `jspdf` peer:
|
|
14
|
+
`react` and `react-dom` (18 or newer) are peer dependencies. PDF export also needs the optional `jspdf` peer, and PNG export in Node (`getQRAsPNG`, imported from `qrdx/node`) needs one of the optional rasterizer peers (`@resvg/resvg-js` draws the SVG — logos included — the way browsers do; `sharp` also works):
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
17
|
npm install jspdf
|
|
18
|
+
npm install @resvg/resvg-js # or: npm install sharp
|
|
18
19
|
```
|
|
19
20
|
|
|
20
21
|
## Quick start
|
|
@@ -352,6 +353,7 @@ const props = { value: "https://example.com", bodyPattern: "rounded" as const };
|
|
|
352
353
|
await downloadQRCode(props, { format: "png", size: PRESET_SIZES.large }); // png | jpg | webp | svg | pdf | eps
|
|
353
354
|
await downloadQRCode(props, { format: "webp", size: PRESET_SIZES.large }); // lossless WebP
|
|
354
355
|
const webp = await getQRAsWebP({ ...props, size: 1024 }); // a Blob; { quality: 0.9 } makes it lossy
|
|
356
|
+
const png = await getQRAsPNG({ ...props, size: 1024 }); // PNG bytes, plain Node — import from "qrdx/node"
|
|
355
357
|
await downloadQRCode(props, { format: "pdf", size: { width: 1200, height: 1200 }, filename: "qr.pdf" });
|
|
356
358
|
const dataUrl = await getQRCodeDataUrl(props, "svg", { width: 512, height: 512 });
|
|
357
359
|
await copyQRCodeToClipboard(props, { width: 512, height: 512 }); // PNG to the clipboard
|
|
@@ -360,6 +362,16 @@ const svgMarkup = await getSVGString(props);
|
|
|
360
362
|
|
|
361
363
|
Sizes must be square and between 50 and 5000 pixels (`validateSize`); with a frame the file is larger by the frame. For `eps`, `size.width` is in PostScript points (72 per inch). When `props.size` is set, a logo laid out for that size is scaled with the export (`withQRSize`). PDF export loads `jspdf` on demand and throws a clear error if it is not installed; EPS needs no extra package.
|
|
362
364
|
|
|
365
|
+
**PNG on a server.** `getQRAsPNG(props, { size })` returns PNG bytes and runs in plain Node without a DOM (handy where the browser helpers can't go). It lives behind its own subpath, so the browser bundle never sees the rasterizer:
|
|
366
|
+
|
|
367
|
+
```js
|
|
368
|
+
import { getQRAsPNG } from "qrdx/node";
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
It rasterizes the SVG the library renders with an optional peer dependency loaded only when the function is called: `@resvg/resvg-js` (recommended — it draws embedded logos the way browsers do, supporting PNG, JPEG, GIF, WebP and SVG images) or `sharp` (whose SVG renderer skips embedded images, so the logo is composited onto the pixels). Installing `qrdx` alone never pulls in a native module.
|
|
372
|
+
|
|
373
|
+
Logos are conservative by default, since a library function that runs on servers shouldn't fetch or read on a caller's behalf: a `src` that is a **data URL** is always used, while **http(s) URLs and local paths are only loaded with `loadExternalLogos: true`** (fetches are capped at 1 MB and refuse redirects). A logo that isn't loaded or can't be is left out, like in the browser. Frame label text needs a font on the machine. The CLI passes `loadExternalLogos: true` for its PNG and WebP output, since the person running it picked the source.
|
|
374
|
+
|
|
363
375
|
WebP is lossless by default, so module edges stay exact, and a transparent background stays transparent. `quality` (0 to 1, in `downloadQRCode` options or `getQRAsWebP`) asks for a smaller lossy file instead. The browser's canvas encodes it where it can; where it can't (Safari hands back a PNG for `image/webp`), QRdx encodes the pixels itself with a small built-in lossless encoder, so a `.webp` file is always WebP. `canvasToWebP(canvas)` does the same for any canvas, and `encodeWebPLossless(rgba, width, height)` encodes raw RGBA pixels without a DOM. Lower-level helpers: `getQRAsSVGDataUri(props)` and `getQRAsCanvas(props, mimeType, returnCanvas?)`.
|
|
364
376
|
|
|
365
377
|
Vector output writes coordinates with at most 3 decimals (0.001 px in SVG, 0.001 pt in PDF and EPS; scale factors keep 6), so edges move by at most 0.0005 px and SVG markup is roughly 30% smaller than with full-precision numbers.
|