@opentui/qrcode 0.0.0-20260528-8a59fd68

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/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./lib/qrcode.js";
2
+ export * from "./renderables/QRCode.js";
package/index.js ADDED
@@ -0,0 +1,22 @@
1
+ // @bun
2
+ import {
3
+ EciAssignment,
4
+ ErrorCorrectionLevel,
5
+ QRCode,
6
+ QRCodeRenderable,
7
+ QrSegment,
8
+ createQrSvg,
9
+ encodeTextBytes
10
+ } from "./chunk-p6dynys3.js";
11
+ export {
12
+ encodeTextBytes,
13
+ createQrSvg,
14
+ QrSegment,
15
+ QRCodeRenderable,
16
+ QRCode,
17
+ ErrorCorrectionLevel,
18
+ EciAssignment
19
+ };
20
+
21
+ //# debugId=B3F12B4C1D75482564756E2164756E21
22
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [
5
+ ],
6
+ "mappings": "",
7
+ "debugId": "B3F12B4C1D75482564756E2164756E21",
8
+ "names": []
9
+ }
@@ -0,0 +1,183 @@
1
+ import { type ByteEncoding } from "./qrcode.encoding.js";
2
+ import { type TerminalRenderOptions } from "./qrcode.render.js";
3
+ export { EciAssignment, encodeTextBytes, type ByteEncoding } from "./qrcode.encoding.js";
4
+ export type { TerminalRenderOptions } from "./qrcode.render.js";
5
+ export declare enum ErrorCorrectionLevel {
6
+ /** Recovers about 7% data damage. QR format bits: 01. */
7
+ L = "L",
8
+ /** Recovers about 15% data damage. QR format bits: 00. */
9
+ M = "M",
10
+ /** Recovers about 25% data damage. QR format bits: 11. */
11
+ Q = "Q",
12
+ /** Recovers about 30% data damage. QR format bits: 10. */
13
+ H = "H"
14
+ }
15
+ export interface StructuredAppendInfo {
16
+ /** 1-based position of this symbol in the structured append sequence. */
17
+ position: number;
18
+ /** Total number of symbols in the structured append sequence, 2..16. */
19
+ total: number;
20
+ /** 8-bit parity value, normally computed with QRCode.computeStructuredAppendParity(). */
21
+ parity: number;
22
+ }
23
+ export interface Fnc1SecondPositionInfo {
24
+ /** Two decimal digits, a number 0..99, or one Latin alphabetic character. */
25
+ applicationIndicator: string | number;
26
+ }
27
+ export interface EncodeOptions {
28
+ /** Minimum QR Code Model 2 version, inclusive. Default: 1. */
29
+ minVersion?: number;
30
+ /** Maximum QR Code Model 2 version, inclusive. Default: 40. */
31
+ maxVersion?: number;
32
+ /** Force QR mask pattern 0..7. Default: auto-select by penalty score. */
33
+ mask?: number;
34
+ /** Upgrade ECC level if the data still fits in the selected version. Default: true. */
35
+ boostEcl?: boolean;
36
+ /** Use DP mixed-mode optimization for text. Default: true. */
37
+ optimize?: boolean;
38
+ /** Allow Kanji mode for characters encodable in Shift JIS Kanji ranges. Default: false. */
39
+ kanji?: boolean;
40
+ /** Byte-segment character encoding for text fallback. Default: utf-8. */
41
+ byteEncoding?: ByteEncoding;
42
+ /** Prefix UTF-8 byte-mode text with ECI assignment 26. Default: true when byteEncoding is utf-8. */
43
+ eciForUtf8?: boolean;
44
+ /** Override the ECI assignment emitted before byte segments; set null to suppress ECI. */
45
+ eciAssignment?: number | null;
46
+ /** Insert FNC1 in first position immediately after any structured append/ECI header. */
47
+ fnc1First?: boolean;
48
+ /** Insert FNC1 in second position immediately after any structured append/ECI header. */
49
+ fnc1Second?: Fnc1SecondPositionInfo;
50
+ /** Insert a structured append header at the start of the symbol. */
51
+ structuredAppend?: StructuredAppendInfo;
52
+ }
53
+ export interface Gs1Element {
54
+ /** Application identifier, e.g. "01", "17", "10". Parentheses are not encoded. */
55
+ ai: string;
56
+ /** Element-string data. */
57
+ data: string;
58
+ /** Add a FNC1 field separator after this element. Do not set on the last element. */
59
+ separatorAfter?: boolean;
60
+ }
61
+ declare class BitBuffer {
62
+ private readonly bits;
63
+ get length(): number;
64
+ appendBits(value: number, bitCount: number): void;
65
+ appendData(other: BitBuffer): void;
66
+ getBit(index: number): number;
67
+ toBytes(): number[];
68
+ }
69
+ declare class Mode {
70
+ readonly name: string;
71
+ readonly modeBits: number;
72
+ private readonly charCountBitsForVersionRange;
73
+ readonly hasCharacterCount: boolean;
74
+ static readonly NUMERIC: Mode;
75
+ static readonly ALPHANUMERIC: Mode;
76
+ static readonly BYTE: Mode;
77
+ static readonly KANJI: Mode;
78
+ static readonly ECI: Mode;
79
+ static readonly STRUCTURED_APPEND: Mode;
80
+ static readonly FNC1_FIRST: Mode;
81
+ static readonly FNC1_SECOND: Mode;
82
+ private constructor();
83
+ numCharCountBits(version: number): number;
84
+ }
85
+ export declare class QrSegment {
86
+ readonly mode: Mode;
87
+ readonly numChars: number;
88
+ readonly data: BitBuffer;
89
+ readonly parityBytes: readonly number[];
90
+ private static readonly ALPHANUMERIC_CHARSET;
91
+ private constructor();
92
+ static makeNumeric(digits: string): QrSegment;
93
+ static makeAlphanumeric(text: string): QrSegment;
94
+ static makeBytes(bytes: Uint8Array | number[]): QrSegment;
95
+ static makeBytesFromText(text: string, encoding?: ByteEncoding): QrSegment;
96
+ static makeKanji(text: string): QrSegment;
97
+ static makeKanjiFromShiftJis(bytes: Uint8Array | number[]): QrSegment;
98
+ static makeEci(assignVal: number): QrSegment;
99
+ static makeStructuredAppendHeader(position: number, total: number, parity: number): QrSegment;
100
+ static makeFnc1FirstPosition(): QrSegment;
101
+ static makeFnc1SecondPosition(applicationIndicator: string | number): QrSegment;
102
+ static isNumeric(text: string): boolean;
103
+ static isAlphanumeric(text: string): boolean;
104
+ static isKanji(text: string): boolean;
105
+ static makeSegments(text: string, options?: Pick<EncodeOptions, "eciForUtf8" | "kanji" | "byteEncoding" | "eciAssignment">): QrSegment[];
106
+ static makeOptimizedSegments(text: string, version: number, options?: Pick<EncodeOptions, "eciForUtf8" | "kanji" | "byteEncoding" | "eciAssignment">): QrSegment[];
107
+ static makeEciSegmentsFromEscapedText(escapedText: string, options?: {
108
+ defaultEncoding?: ByteEncoding;
109
+ defaultEci?: number | null;
110
+ }): QrSegment[];
111
+ getTotalBits(version: number): number;
112
+ private static addEciIfNeeded;
113
+ private static makeOptimizedSegmentsInternal;
114
+ }
115
+ export declare class QRCode {
116
+ readonly version: number;
117
+ readonly errorCorrectionLevel: ErrorCorrectionLevel;
118
+ readonly mask: number;
119
+ private static readonly MIN_VERSION;
120
+ private static readonly MAX_VERSION;
121
+ private static readonly ECC_CODEWORDS_PER_BLOCK;
122
+ private static readonly NUM_ERROR_CORRECTION_BLOCKS;
123
+ private static readonly FORMAT_BITS_BY_ECL;
124
+ private static readonly ECL_ORDER;
125
+ readonly size: number;
126
+ readonly symbologyIdentifier: string;
127
+ readonly containsEci: boolean;
128
+ readonly fnc1: "none" | "first" | "second";
129
+ private readonly modules;
130
+ private readonly functionModules;
131
+ private constructor();
132
+ static encodeText(text: string, ecl?: ErrorCorrectionLevel, options?: EncodeOptions): QRCode;
133
+ static encodeBytes(bytes: Uint8Array | number[], ecl?: ErrorCorrectionLevel, options?: EncodeOptions): QRCode;
134
+ static encodeEciText(escapedText: string, ecl?: ErrorCorrectionLevel, options?: EncodeOptions): QRCode;
135
+ static encodeGs1Text(gs1Data: string | Gs1Element[], ecl?: ErrorCorrectionLevel, options?: EncodeOptions): QRCode;
136
+ static encodeStructuredAppend(parts: readonly (readonly QrSegment[])[], ecl?: ErrorCorrectionLevel, options?: EncodeOptions): QRCode[];
137
+ static computeStructuredAppendParity(segments: readonly QrSegment[]): number;
138
+ static encodeSegments(segments: QrSegment[], ecl?: ErrorCorrectionLevel, options?: EncodeOptions): QRCode;
139
+ getModule(x: number, y: number): boolean;
140
+ /** Returns a deep copy of the QR module matrix. True is dark, false is light. */
141
+ toMatrix(): boolean[][];
142
+ /** Render as SVG. The border is the quiet zone in modules; ISO QR Code requires at least 4. */
143
+ toSvgString(options?: {
144
+ border?: number;
145
+ moduleSize?: number;
146
+ lightColor?: string;
147
+ darkColor?: string;
148
+ }): string;
149
+ /**
150
+ * Render as terminal text. Default quiet zone is 4 modules, matching the QR Code minimum.
151
+ * Use { ansi: true } for scanner-facing terminal output with explicit black/white backgrounds.
152
+ */
153
+ toTerminalString(options?: number | TerminalRenderOptions): string;
154
+ static validateVersionPublic(version: number): void;
155
+ private static applyPrefixSegments;
156
+ private static validateQrSegmentOrder;
157
+ private static collectMetadata;
158
+ private static makeSymbologyIdentifier;
159
+ private static makeWithBestMask;
160
+ private drawFunctionPatterns;
161
+ private drawFinderPattern;
162
+ private drawAlignmentPattern;
163
+ private drawFormatBits;
164
+ private drawVersionBits;
165
+ private drawCodewords;
166
+ private applyMask;
167
+ private getPenaltyScore;
168
+ private addEccAndInterleave;
169
+ private getAlignmentPatternPositions;
170
+ private setFunctionModule;
171
+ private static getTotalBits;
172
+ private static getNumDataCodewords;
173
+ private static getNumRawDataModules;
174
+ static maskCondition(mask: number, x: number, y: number): boolean;
175
+ private static eclIndex;
176
+ private static validateVersion;
177
+ private static validateMask;
178
+ }
179
+ export declare function createQrSvg(text: string, options?: EncodeOptions & {
180
+ ecl?: ErrorCorrectionLevel;
181
+ border?: number;
182
+ moduleSize?: number;
183
+ }): string;
@@ -0,0 +1,12 @@
1
+ export type ByteEncoding = "utf-8" | "iso-8859-1" | "shift-jis";
2
+ export declare const EciAssignment: {
3
+ readonly ISO_8859_1: 3;
4
+ readonly SHIFT_JIS: 20;
5
+ readonly UTF_8: 26;
6
+ };
7
+ export declare function encodeTextBytes(text: string, encoding?: ByteEncoding): Uint8Array;
8
+ export declare function shiftJisCodeForCharacter(ch: string): number;
9
+ export declare function isKanjiModeShiftJisValue(value: number): boolean;
10
+ export declare function encodingForKnownEci(eci: number): ByteEncoding | null;
11
+ export declare function validateBytes(bytes: number[]): number[];
12
+ export declare function asciiBytes(text: string): number[];
@@ -0,0 +1,19 @@
1
+ export interface TerminalRenderOptions {
2
+ /** Quiet zone in modules. ISO requires at least 4 for QR Code. */
3
+ border?: number;
4
+ /**
5
+ * Render using ANSI background colors. Recommended when a real scanner will read the terminal.
6
+ * The ANSI renderer paints light modules white and dark modules black independent of terminal theme.
7
+ */
8
+ ansi?: boolean;
9
+ /** Swap light and dark output. Leave false for normal black-on-white scanner-facing output. */
10
+ invert?: boolean;
11
+ }
12
+ export interface NormalizedTerminalRenderOptions {
13
+ border: number;
14
+ ansi: boolean;
15
+ invert: boolean;
16
+ }
17
+ export declare function matrixToSvg(matrix: boolean[][], border: number, minimumBorder: number, moduleSize: number, lightColor: string, darkColor: string): string;
18
+ export declare function normalizeTerminalOptions(options: number | TerminalRenderOptions, defaultBorder: number, minimumBorder: number): NormalizedTerminalRenderOptions;
19
+ export declare function matrixToTerminal(matrix: boolean[][], options: NormalizedTerminalRenderOptions): string;
@@ -0,0 +1 @@
1
+ export declare const SHIFT_JIS_CODE_BY_CHAR: Record<string, number>;
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@opentui/qrcode",
3
+ "module": "index.js",
4
+ "main": "index.js",
5
+ "types": "index.d.ts",
6
+ "type": "module",
7
+ "version": "0.0.0-20260528-8a59fd68",
8
+ "description": "QR code encoder and renderable for OpenTUI",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/anomalyco/opentui",
13
+ "directory": "packages/qrcode"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "import": "./index.js",
18
+ "require": "./index.js",
19
+ "types": "./index.d.ts"
20
+ },
21
+ "./react": {
22
+ "import": "./react.js",
23
+ "require": "./react.js",
24
+ "types": "./react.d.ts"
25
+ },
26
+ "./solid": {
27
+ "import": "./solid.js",
28
+ "require": "./solid.js",
29
+ "types": "./solid.d.ts"
30
+ }
31
+ },
32
+ "dependencies": {
33
+ "@opentui/core": "0.0.0-20260528-8a59fd68",
34
+ "yoga-layout": "3.2.1"
35
+ },
36
+ "devDependencies": {
37
+ "@opentui/react": "workspace:*",
38
+ "@opentui/solid": "workspace:*",
39
+ "@types/bun": "latest",
40
+ "@types/node": "^24.0.0",
41
+ "typescript": "^5"
42
+ },
43
+ "peerDependencies": {
44
+ "@opentui/react": "0.0.0-20260528-8a59fd68",
45
+ "@opentui/solid": "0.0.0-20260528-8a59fd68"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "@opentui/react": {
49
+ "optional": true
50
+ },
51
+ "@opentui/solid": {
52
+ "optional": true
53
+ }
54
+ }
55
+ }
package/react.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { QRCodeRenderable } from "./renderables/QRCode.js";
2
+ declare module "@opentui/react" {
3
+ interface OpenTUIComponents {
4
+ "qr-code": typeof QRCodeRenderable;
5
+ }
6
+ }
7
+ export declare function registerQRCode(): void;
8
+ export * from "./index.js";
package/react.js ADDED
@@ -0,0 +1,29 @@
1
+ // @bun
2
+ import {
3
+ EciAssignment,
4
+ ErrorCorrectionLevel,
5
+ QRCode,
6
+ QRCodeRenderable,
7
+ QrSegment,
8
+ createQrSvg,
9
+ encodeTextBytes
10
+ } from "./chunk-p6dynys3.js";
11
+
12
+ // src/react.ts
13
+ import { extend } from "@opentui/react";
14
+ function registerQRCode() {
15
+ extend({ "qr-code": QRCodeRenderable });
16
+ }
17
+ export {
18
+ registerQRCode,
19
+ encodeTextBytes,
20
+ createQrSvg,
21
+ QrSegment,
22
+ QRCodeRenderable,
23
+ QRCode,
24
+ ErrorCorrectionLevel,
25
+ EciAssignment
26
+ };
27
+
28
+ //# debugId=DDFCE424C87C54B764756E2164756E21
29
+ //# sourceMappingURL=react.js.map
package/react.js.map ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/react.ts"],
4
+ "sourcesContent": [
5
+ "import { extend } from \"@opentui/react\"\nimport { QRCodeRenderable } from \"./renderables/QRCode.js\"\n\ndeclare module \"@opentui/react\" {\n interface OpenTUIComponents {\n \"qr-code\": typeof QRCodeRenderable\n }\n}\n\nexport function registerQRCode(): void {\n extend({ \"qr-code\": QRCodeRenderable })\n}\n\nexport * from \"./index.js\"\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;AAAA;AASO,SAAS,cAAc,GAAS;AAAA,EACrC,OAAO,EAAE,WAAW,iBAAiB,CAAC;AAAA;",
8
+ "debugId": "DDFCE424C87C54B764756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,99 @@
1
+ import { OptimizedBuffer, RGBA, Renderable, type ColorInput, type RenderableOptions, type RenderContext } from "@opentui/core";
2
+ import { ErrorCorrectionLevel, QRCode } from "../lib/qrcode.js";
3
+ export type QRCodeFitMode = "contain" | "none";
4
+ interface EncodedQRCode<TVersion extends number> {
5
+ readonly version: TVersion;
6
+ readonly size: number;
7
+ toMatrix(): boolean[][];
8
+ }
9
+ interface QRCodeSharedOptions<TRenderable extends Renderable, TEcl> extends RenderableOptions<TRenderable> {
10
+ content?: string;
11
+ errorCorrectionLevel?: TEcl;
12
+ quietZone?: number;
13
+ scale?: number;
14
+ fit?: QRCodeFitMode;
15
+ foregroundColor?: ColorInput;
16
+ backgroundColor?: ColorInput;
17
+ fallbackContent?: string;
18
+ fallbackColor?: ColorInput;
19
+ }
20
+ export interface QRCodeOptions extends QRCodeSharedOptions<QRCodeRenderable, ErrorCorrectionLevel> {
21
+ }
22
+ interface QRCodeRenderableDefaults<TEcl> {
23
+ content: string;
24
+ errorCorrectionLevel: TEcl;
25
+ quietZone: number;
26
+ scale: number;
27
+ fit: QRCodeFitMode;
28
+ foregroundColor: RGBA;
29
+ backgroundColor: RGBA;
30
+ fallbackContent: string;
31
+ fallbackColor: RGBA;
32
+ }
33
+ declare abstract class BaseQRCodeRenderable<TEcl, TVersion extends number, TEncoded extends EncodedQRCode<TVersion>> extends Renderable {
34
+ private readonly minimumQuietZone;
35
+ private readonly encodeContent;
36
+ private _content;
37
+ private _errorCorrectionLevel;
38
+ private _quietZone;
39
+ private _scale;
40
+ private _fit;
41
+ private _foregroundColor;
42
+ private _backgroundColor;
43
+ private _fallbackContent;
44
+ private _fallbackColor;
45
+ private encoded;
46
+ private modules;
47
+ private renderBuffer;
48
+ private renderBufferDirty;
49
+ protected constructor(ctx: RenderContext, options: QRCodeSharedOptions<any, TEcl>, defaults: QRCodeRenderableDefaults<TEcl>, minimumQuietZone: number, encodeContent: (content: string, errorCorrectionLevel: TEcl) => TEncoded);
50
+ get content(): string;
51
+ set content(value: string);
52
+ get errorCorrectionLevel(): TEcl;
53
+ set errorCorrectionLevel(value: TEcl);
54
+ get quietZone(): number;
55
+ set quietZone(value: number);
56
+ get scale(): number;
57
+ set scale(value: number);
58
+ get fit(): QRCodeFitMode;
59
+ set fit(value: QRCodeFitMode);
60
+ get foregroundColor(): RGBA;
61
+ set foregroundColor(value: ColorInput);
62
+ get backgroundColor(): RGBA;
63
+ set backgroundColor(value: ColorInput);
64
+ get fallbackContent(): string;
65
+ set fallbackContent(value: string);
66
+ get fallbackColor(): RGBA;
67
+ set fallbackColor(value: ColorInput);
68
+ get version(): TVersion;
69
+ get moduleCount(): number;
70
+ protected renderSelf(buffer: OptimizedBuffer): void;
71
+ protected onResize(width: number, height: number): void;
72
+ protected destroySelf(): void;
73
+ private paintRenderBuffer;
74
+ private rebuildMatrix;
75
+ private remeasure;
76
+ private invalidateRenderBuffer;
77
+ private getRenderBuffer;
78
+ private setupMeasureFunc;
79
+ private resolveMeasuredScale;
80
+ private resolveRenderScale;
81
+ private resolveScaleForBounds;
82
+ private isDarkAtScaledPixel;
83
+ private paintFallback;
84
+ }
85
+ export declare class QRCodeRenderable extends BaseQRCodeRenderable<ErrorCorrectionLevel, number, QRCode> {
86
+ protected static readonly _defaultOptions: {
87
+ content: string;
88
+ errorCorrectionLevel: ErrorCorrectionLevel.M;
89
+ quietZone: number;
90
+ scale: number;
91
+ fit: QRCodeFitMode;
92
+ foregroundColor: RGBA;
93
+ backgroundColor: RGBA;
94
+ fallbackContent: string;
95
+ fallbackColor: RGBA;
96
+ };
97
+ constructor(ctx: RenderContext, options?: QRCodeOptions);
98
+ }
99
+ export {};
package/solid.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { QRCodeRenderable } from "./renderables/QRCode.js";
2
+ declare module "@opentui/solid" {
3
+ interface OpenTUIComponents {
4
+ qr_code: typeof QRCodeRenderable;
5
+ }
6
+ }
7
+ export declare function registerQRCode(): void;
8
+ export * from "./index.js";
package/solid.js ADDED
@@ -0,0 +1,29 @@
1
+ // @bun
2
+ import {
3
+ EciAssignment,
4
+ ErrorCorrectionLevel,
5
+ QRCode,
6
+ QRCodeRenderable,
7
+ QrSegment,
8
+ createQrSvg,
9
+ encodeTextBytes
10
+ } from "./chunk-p6dynys3.js";
11
+
12
+ // src/solid.ts
13
+ import { extend } from "@opentui/solid/components";
14
+ function registerQRCode() {
15
+ extend({ qr_code: QRCodeRenderable });
16
+ }
17
+ export {
18
+ registerQRCode,
19
+ encodeTextBytes,
20
+ createQrSvg,
21
+ QrSegment,
22
+ QRCodeRenderable,
23
+ QRCode,
24
+ ErrorCorrectionLevel,
25
+ EciAssignment
26
+ };
27
+
28
+ //# debugId=7BC890A66B23EA5864756E2164756E21
29
+ //# sourceMappingURL=solid.js.map
package/solid.js.map ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/solid.ts"],
4
+ "sourcesContent": [
5
+ "import { extend } from \"@opentui/solid/components\"\nimport { QRCodeRenderable } from \"./renderables/QRCode.js\"\n\ndeclare module \"@opentui/solid\" {\n interface OpenTUIComponents {\n qr_code: typeof QRCodeRenderable\n }\n}\n\nexport function registerQRCode(): void {\n extend({ qr_code: QRCodeRenderable })\n}\n\nexport * from \"./index.js\"\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;AAAA;AASO,SAAS,cAAc,GAAS;AAAA,EACrC,OAAO,EAAE,SAAS,iBAAiB,CAAC;AAAA;",
8
+ "debugId": "7BC890A66B23EA5864756E2164756E21",
9
+ "names": []
10
+ }