@adminiumjs/public-client 0.3.38 → 0.3.40
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/dist/qr.d.ts +9 -3
- package/dist/qr.d.ts.map +1 -1
- package/dist/qr.js +9 -5
- package/dist/qr.js.map +1 -1
- package/package.json +1 -1
package/dist/qr.d.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
/** The longest text a code carries: a ticket code or a share token, never a page's address. */
|
|
2
2
|
export declare const QR_MAX_BYTES = 64;
|
|
3
|
+
/** The longest page address a code carries when asked for with `{ page: true }` (a form's link). */
|
|
4
|
+
export declare const QR_PAGE_MAX_BYTES = 256;
|
|
3
5
|
/** Modules of white around the code. */
|
|
4
6
|
export declare const QR_QUIET = 4;
|
|
7
|
+
/** What a code is of: a short code (the default), or a page's address. */
|
|
8
|
+
export interface QrOptions {
|
|
9
|
+
page?: boolean | undefined;
|
|
10
|
+
}
|
|
5
11
|
/**
|
|
6
12
|
* The modules of the QR code of `text`, row by row, `true` for a dark one,
|
|
7
13
|
* with no quiet zone. Throws for an empty text or one longer than
|
|
8
|
-
* {@link QR_MAX_BYTES} bytes.
|
|
14
|
+
* {@link QR_MAX_BYTES} bytes ({@link QR_PAGE_MAX_BYTES} for a page's address).
|
|
9
15
|
*/
|
|
10
|
-
export declare function qrMatrix(text: string): boolean[][];
|
|
16
|
+
export declare function qrMatrix(text: string, opts?: QrOptions): boolean[][];
|
|
11
17
|
/**
|
|
12
18
|
* The QR code of `text` as an SVG document on a white square (never
|
|
13
19
|
* transparent: a dark page would swallow the quiet zone), `size` pixels
|
|
@@ -15,5 +21,5 @@ export declare function qrMatrix(text: string): boolean[][];
|
|
|
15
21
|
*/
|
|
16
22
|
export declare function qrSvg(text: string, opts?: {
|
|
17
23
|
size?: number;
|
|
18
|
-
}): string;
|
|
24
|
+
} & QrOptions): string;
|
|
19
25
|
//# sourceMappingURL=qr.d.ts.map
|
package/dist/qr.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qr.d.ts","sourceRoot":"","sources":["../src/qr.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"qr.d.ts","sourceRoot":"","sources":["../src/qr.ts"],"names":[],"mappings":"AAkBA,+FAA+F;AAC/F,eAAO,MAAM,YAAY,KAAK,CAAC;AAE/B,oGAAoG;AACpG,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC,wCAAwC;AACxC,eAAO,MAAM,QAAQ,IAAI,CAAC;AAE1B,0EAA0E;AAC1E,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC5B;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,SAAc,GAAG,OAAO,EAAE,EAAE,CAOxE;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAc,GAAG,MAAM,CAkBpF"}
|
package/dist/qr.js
CHANGED
|
@@ -11,21 +11,25 @@
|
|
|
11
11
|
* ```ts
|
|
12
12
|
* import { qrSvg } from '@adminium/public-client/qr';
|
|
13
13
|
* ticketEl.innerHTML = qrSvg(ticket.code, { size: 180 });
|
|
14
|
+
* formEl.innerHTML = qrSvg(formLink, { size: 176, page: true });
|
|
14
15
|
* ```
|
|
15
16
|
*/
|
|
16
17
|
import { encodeQR } from 'qr';
|
|
17
18
|
/** The longest text a code carries: a ticket code or a share token, never a page's address. */
|
|
18
19
|
export const QR_MAX_BYTES = 64;
|
|
20
|
+
/** The longest page address a code carries when asked for with `{ page: true }` (a form's link). */
|
|
21
|
+
export const QR_PAGE_MAX_BYTES = 256;
|
|
19
22
|
/** Modules of white around the code. */
|
|
20
23
|
export const QR_QUIET = 4;
|
|
21
24
|
/**
|
|
22
25
|
* The modules of the QR code of `text`, row by row, `true` for a dark one,
|
|
23
26
|
* with no quiet zone. Throws for an empty text or one longer than
|
|
24
|
-
* {@link QR_MAX_BYTES} bytes.
|
|
27
|
+
* {@link QR_MAX_BYTES} bytes ({@link QR_PAGE_MAX_BYTES} for a page's address).
|
|
25
28
|
*/
|
|
26
|
-
export function qrMatrix(text) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
export function qrMatrix(text, opts = {}) {
|
|
30
|
+
const most = opts.page === true ? QR_PAGE_MAX_BYTES : QR_MAX_BYTES;
|
|
31
|
+
if (typeof text !== 'string' || text === '' || new TextEncoder().encode(text).length > most) {
|
|
32
|
+
throw new RangeError(`A QR code carries 1 to ${String(most)} bytes of text.`);
|
|
29
33
|
}
|
|
30
34
|
const framed = encodeQR(text, 'raw', { ecc: 'medium', border: 1 });
|
|
31
35
|
return framed.slice(1, -1).map((row) => row.slice(1, -1));
|
|
@@ -36,7 +40,7 @@ export function qrMatrix(text) {
|
|
|
36
40
|
* across when given. Safe to put in the page: it holds no text of the code.
|
|
37
41
|
*/
|
|
38
42
|
export function qrSvg(text, opts = {}) {
|
|
39
|
-
const modules = qrMatrix(text);
|
|
43
|
+
const modules = qrMatrix(text, opts);
|
|
40
44
|
const width = modules.length + 2 * QR_QUIET;
|
|
41
45
|
const path = [];
|
|
42
46
|
modules.forEach((row, y) => {
|
package/dist/qr.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qr.js","sourceRoot":"","sources":["../src/qr.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC
|
|
1
|
+
{"version":3,"file":"qr.js","sourceRoot":"","sources":["../src/qr.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAE9B,+FAA+F;AAC/F,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC;AAE/B,oGAAoG;AACpG,MAA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