@levischuck/tiny-qr 0.0.1

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/mode.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { Version, Mode } from './types';
2
+ /** Computes the number of bits needed to encode the data length */
3
+ export declare function modeLengthBitsCount(mode: Mode, version: Version): number;
4
+ /** Computes the number of bits needed to encode data of a given length */
5
+ export declare function modeDataBitsCount(mode: Mode, rawDataLen: number): number;
6
+ /** Find the lowest common mode which both modes are compatible with */
7
+ export declare function modeMax(a: Mode, b: Mode): Mode;
@@ -0,0 +1,45 @@
1
+ import { Mode, Version } from './types.ts';
2
+ /** A segment of data committed to an encoding mode */
3
+ export interface Segment {
4
+ mode: Mode;
5
+ begin: number;
6
+ end: number;
7
+ }
8
+ /** Parser state */
9
+ declare enum State {
10
+ Init = 0,
11
+ Numeric = 5,
12
+ Alpha = 10,
13
+ Byte = 15
14
+ }
15
+ /** Parser state for classifying input into segments */
16
+ export interface ParserState {
17
+ readonly data: Uint8Array;
18
+ readonly index: number;
19
+ readonly ended: boolean;
20
+ readonly state: State;
21
+ readonly begin: number;
22
+ }
23
+ /** Creates a new parser state */
24
+ export declare function createParser(data: Uint8Array): ParserState;
25
+ /** Advances the parser and returns the next segment and updated state */
26
+ export declare function parserNext(parser: ParserState): [Segment | null, ParserState];
27
+ /** Collect all segments from a parser */
28
+ export declare function parserCollect(parser: ParserState): Segment[];
29
+ /** Optimizer state that combines adjacent segments when beneficial */
30
+ export interface OptimizerState {
31
+ readonly parser: ParserState;
32
+ readonly lastSegment: Segment | null;
33
+ readonly lastSegmentSize: number;
34
+ readonly version: Version;
35
+ readonly ended: boolean;
36
+ }
37
+ /** Creates a new optimizer state */
38
+ export declare function createOptimizer(parser: ParserState, version: Version): OptimizerState;
39
+ /** Advances the optimizer and returns the next optimized segment and updated state */
40
+ export declare function optimizerNext(optimizer: OptimizerState): [Segment | null, OptimizerState];
41
+ /** Collect all optimized segments */
42
+ export declare function optimizerCollect(optimizer: OptimizerState): Segment[];
43
+ /** Computes the total encoded length of all segments */
44
+ export declare function totalEncodedLen(segments: Segment[], version: Version): number;
45
+ export {};
@@ -0,0 +1,45 @@
1
+ /** The color of a module */
2
+ export declare enum Color {
3
+ Light = 0,
4
+ Dark = 1
5
+ }
6
+ /** Error correction level */
7
+ export declare enum EcLevel {
8
+ /** Low error correction. Allows up to 7% of wrong blocks. */
9
+ L = 0,
10
+ /** Medium error correction. Allows up to 15% of wrong blocks. */
11
+ M = 1,
12
+ /** "Quartile" error correction. Allows up to 25% of wrong blocks. */
13
+ Q = 2,
14
+ /** High error correction. Allows up to 30% of wrong blocks. */
15
+ H = 3
16
+ }
17
+ /** QR code version (1-40) */
18
+ export type Version = number;
19
+ /** Encoding mode */
20
+ export declare enum Mode {
21
+ /** Numeric mode (0-9) */
22
+ Numeric = 0,
23
+ /** Alphanumeric mode (0-9, A-Z, space, $, %, *, +, -, ., /, :) */
24
+ Alphanumeric = 1,
25
+ /** Byte mode (arbitrary binary data) */
26
+ Byte = 2
27
+ }
28
+ /** QR code result object */
29
+ export interface QrResult {
30
+ /** 2D array of booleans (true = dark, false = light) */
31
+ matrix: boolean[][];
32
+ /** Width of the QR code in modules */
33
+ width: number;
34
+ /** QR code version (1-40) */
35
+ version: Version;
36
+ /** Error correction level used */
37
+ ec: EcLevel;
38
+ }
39
+ /** Options for generating a QR code */
40
+ export interface QrOptions {
41
+ /** Data to encode (string or binary data) */
42
+ data: string | Uint8Array;
43
+ /** Error correction level (defaults to Medium) */
44
+ ec?: EcLevel;
45
+ }
@@ -0,0 +1,7 @@
1
+ import { EcLevel, Version } from './types';
2
+ /** Gets the width of the QR code in modules */
3
+ export declare function versionWidth(version: Version): number;
4
+ /** Gets the number of bits needed to encode the mode indicator */
5
+ export declare function versionModeBitsCount(version: Version): number;
6
+ /** Fetches a value from a lookup table */
7
+ export declare function versionFetch<T>(version: Version, ecLevel: EcLevel, table: ReadonlyArray<readonly [T, T, T, T]>): T;
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@levischuck/tiny-qr",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/levischuck/tiny-packages.git"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md",
25
+ "LICENSE.txt"
26
+ ],
27
+ "scripts": {
28
+ "build": "vite build",
29
+ "prepublishOnly": "bun run build",
30
+ "type-check": "bunx tsc --noEmit"
31
+ },
32
+ "devDependencies": {
33
+ "@types/bun": "^1.3.5"
34
+ },
35
+ "peerDependencies": {
36
+ "typescript": "^5"
37
+ }
38
+ }