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/README.md
CHANGED
|
@@ -77,6 +77,41 @@ The package ships an ES module build (`import`), a CommonJS/UMD build (`require`
|
|
|
77
77
|
|
|
78
78
|
---
|
|
79
79
|
|
|
80
|
+
### React and Vue
|
|
81
|
+
|
|
82
|
+
The core stays framework-free. Thin wrappers ship in the same package; React and Vue are optional peer dependencies.
|
|
83
|
+
|
|
84
|
+
```jsx
|
|
85
|
+
import { QRCode } from "qr-code-styling-node/react";
|
|
86
|
+
|
|
87
|
+
function Poster() {
|
|
88
|
+
const qr = useRef();
|
|
89
|
+
return (
|
|
90
|
+
<>
|
|
91
|
+
<QRCode ref={qr} options={{ data: "https://example.com", dotsOptions: { type: "fluid" } }} />
|
|
92
|
+
<button onClick={() => qr.current.download({ extension: "png" })}>Download</button>
|
|
93
|
+
</>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
```vue
|
|
99
|
+
<script setup>
|
|
100
|
+
import { ref } from "vue";
|
|
101
|
+
import { QRCode } from "qr-code-styling-node/vue";
|
|
102
|
+
const qr = ref();
|
|
103
|
+
const options = ref({ data: "https://example.com", shape: "circle" });
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
<template>
|
|
107
|
+
<QRCode ref="qr" :options="options" @update="(qrCode) => console.log('drawn', qrCode)" />
|
|
108
|
+
<button @click="qr.share({ name: 'qr' })">Share</button>
|
|
109
|
+
</template>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Both redraw only when the options really change (a new but equal object does not redraw). The React ref is the
|
|
113
|
+
`QRCodeStyling` instance; the Vue ref exposes `qrCode`, `download`, `share` and `getRawData`.
|
|
114
|
+
|
|
80
115
|
### More styles, frames and labels
|
|
81
116
|
|
|
82
117
|
<img src="https://raw.githubusercontent.com/ducminhquan/qr-code-styling/master/src/assets/style_examples.png" width="720" />
|
|
@@ -231,6 +266,38 @@ const result = await qrCode.share({ name: "wifi", extension: "png", title: "Wi-F
|
|
|
231
266
|
// "shared", "cancelled" or "downloaded"
|
|
232
267
|
```
|
|
233
268
|
|
|
269
|
+
### Plugins
|
|
270
|
+
|
|
271
|
+
A plugin is a plain object with two optional hooks. `configure(options)` returns option changes to merge in before
|
|
272
|
+
drawing. `afterDraw(draw)` draws on top of the finished code, with the canvas context or the SVG element. It gets
|
|
273
|
+
the code's area in pixels (`x`, `y`, `size`, `dotSize`, `count`), and that area accounts for frames.
|
|
274
|
+
|
|
275
|
+
```js
|
|
276
|
+
const ring = {
|
|
277
|
+
name: "ring",
|
|
278
|
+
configure: (options) => (options.margin < 24 ? { margin: 24 } : undefined),
|
|
279
|
+
afterDraw: ({ type, area, context, svg, document }) => {
|
|
280
|
+
const cx = area.x + area.size / 2, cy = area.y + area.size / 2, r = area.size * 0.75;
|
|
281
|
+
if (type === "canvas") {
|
|
282
|
+
context.beginPath();
|
|
283
|
+
context.arc(cx, cy, r, 0, Math.PI * 2);
|
|
284
|
+
context.strokeStyle = "#e11d48";
|
|
285
|
+
context.stroke();
|
|
286
|
+
} else {
|
|
287
|
+
const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
288
|
+
Object.entries({ cx, cy, r, fill: "none", stroke: "#e11d48" }).forEach(([k, v]) => circle.setAttribute(k, v));
|
|
289
|
+
svg.appendChild(circle);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
new QRCodeStyling({ data: "https://example.com", plugins: [ring] });
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
Plugins run in order, and async `afterDraw` hooks are awaited. `configure` runs again on every `update()`, so it
|
|
298
|
+
should return the same changes for the same options. Check the result with `verify()` when a plugin draws near
|
|
299
|
+
the code.
|
|
300
|
+
|
|
234
301
|
### Checking that a code scans
|
|
235
302
|
|
|
236
303
|
`verify()` renders the code and decodes it with a QR decoder you pass in, so the library itself stays dependency-free.
|
|
@@ -268,6 +335,7 @@ height |number |`300` |Size of canvas
|
|
|
268
335
|
type |string (`'canvas' 'svg'`)|`canvas` |The type of the element that will be rendered
|
|
269
336
|
shape |string (`'square' 'circle'`)|`'square'` |`'circle'` draws a round code with decorative dots around the real one
|
|
270
337
|
svgOptions |object `{ mergePaths }` | |SVG only: `mergePaths: true` draws all dots as one path (smaller files)
|
|
338
|
+
plugins |array | |Plugins with `configure` and `afterDraw` hooks, see [Plugins](#plugins)
|
|
271
339
|
data |string | |The date will be encoded to the QR code
|
|
272
340
|
image |string | |The image will be copied to the center of the QR code
|
|
273
341
|
margin |number |`0` |Margin around canvas
|
package/lib/core/QRCanvas.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export default class QRCanvas {
|
|
|
18
18
|
clear(): void;
|
|
19
19
|
_drawFramed(qr: QRCode): Promise<void>;
|
|
20
20
|
drawQR(qr: QRCode): Promise<void>;
|
|
21
|
+
_drawCode(qr: QRCode): Promise<void>;
|
|
21
22
|
drawBackground(): void;
|
|
22
23
|
drawDots(filter?: FilterFunction): void;
|
|
23
24
|
_drawArtRects(rects: ArtRect[]): void;
|
package/lib/core/QRSVG.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export default class QRSVG {
|
|
|
27
27
|
_svgElement(name: string, attributes: Record<string, string | number>): SVGElement;
|
|
28
28
|
_drawFramed(qr: QRCode): Promise<void>;
|
|
29
29
|
drawQR(qr: QRCode): Promise<void>;
|
|
30
|
+
_drawCode(qr: QRCode): Promise<void>;
|
|
30
31
|
drawBackground(): void;
|
|
31
32
|
drawDots(filter?: FilterFunction): void;
|
|
32
33
|
drawCorners(): void;
|