ink-framework-barcode 0.0.0-stage → 0.1.0-alpha.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vandam Dinh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 1,
3
+ "modules": {
4
+ "src/generate.ts": [
5
+ "barcode-generate",
6
+ "image"
7
+ ],
8
+ "src/scan.ts": [
9
+ "code-scanner"
10
+ ]
11
+ }
12
+ }
package/package.json CHANGED
@@ -1,6 +1,24 @@
1
1
  {
2
2
  "name": "ink-framework-barcode",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-alpha.1",
4
+ "exports": {
5
+ ".": "./src/generate.ts",
6
+ "./scan": "./src/scan.ts"
7
+ },
8
+ "peerDependencies": {
9
+ "ink": "npm:ink-framework@0.1.0-alpha.1",
10
+ "react": "19.2.8",
11
+ "@ink/camera": "npm:ink-framework-camera@0.1.0-alpha.1"
12
+ },
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/No-Scrolling/ink.git",
17
+ "directory": "packages/barcode"
18
+ },
19
+ "files": [
20
+ "src",
21
+ "*.json",
22
+ "*.ts"
23
+ ]
24
+ }
@@ -0,0 +1,20 @@
1
+ import { createElement } from "react";
2
+
3
+ export const supportedFormats = ["qr", "aztec", "data-matrix", "pdf417", "ean-13", "ean-8", "upc-a", "upc-e", "code-39", "code-93", "code-128", "itf", "codabar"] as const;
4
+ export type BarcodeFormat = typeof supportedFormats[number];
5
+
6
+ export function Barcode(props: {
7
+ format: BarcodeFormat;
8
+ value: string;
9
+ /** Display width in Ink layout units; height follows the generated code. */
10
+ size: number;
11
+ /** Print the encoded value beneath a linear barcode. */
12
+ showValue?: boolean;
13
+ }) {
14
+ if (!supportedFormats.includes(props.format)) throw new Error("Unsupported barcode format");
15
+ if (!props.value.length) throw new Error("Barcode value must not be empty");
16
+ if (!Number.isFinite(props.size) || props.size <= 0 || props.size > 1080) {
17
+ throw new RangeError("Barcode size must be greater than zero and at most 1080");
18
+ }
19
+ return createElement("Barcode", props);
20
+ }
package/src/scan.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { NativeError } from "ink/native";
2
+ import { useSession, codeFormats, type CodeFormat, type CodeScan } from "@ink/camera/internal";
3
+ export { CameraPreview, codeFormats, type CodeFormat, type CodeScan } from "@ink/camera/internal";
4
+
5
+ function codeFormat(value: unknown): CodeFormat {
6
+ const format = codeFormats.find(format => format === value);
7
+ if (!format) throw new NativeError("protocol", "Invalid barcode format");
8
+ return format;
9
+ }
10
+ function decodeCode(value: unknown): CodeScan {
11
+ if (typeof value !== "object" || value === null || !("text" in value) || typeof value.text !== "string" || !("format" in value)) throw new NativeError("protocol", "Invalid scanned code");
12
+ if (!("rawBytes" in value) || (value.rawBytes !== null && (!Array.isArray(value.rawBytes)
13
+ || !value.rawBytes.every((byte: unknown) => typeof byte === "number" && Number.isInteger(byte) && byte >= 0 && byte <= 255)))) throw new NativeError("protocol", "Invalid barcode bytes");
14
+ return { text: value.text, format: codeFormat(value.format), rawBytes: value.rawBytes === null ? null : new Uint8Array(value.rawBytes) };
15
+ }
16
+
17
+ export function useCodeScanner({ formats = [...codeFormats], continuous = false, intervalMs = 1000, facing = "back" }: { formats?: readonly CodeFormat[]; continuous?: boolean; intervalMs?: number; facing?: "back" | "front" } = {}) {
18
+ if (!Number.isSafeInteger(intervalMs) || intervalMs < 100 || intervalMs > 60_000) throw new RangeError("Scan interval must be between 100 and 60000 milliseconds");
19
+ if (!formats.length) throw new TypeError("Choose at least one barcode format");
20
+ return useSession("scanner", decodeCode, JSON.stringify({ formats: formats.map(codeFormat), continuous, intervalMs, facing }));
21
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.