brother-smooth-print-uri 1.0.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 ADDED
@@ -0,0 +1,28 @@
1
+ # Brother Smooth Print URI Generator
2
+
3
+ This is a simple URI generator for printing using the Brother Smooth Print app.
4
+
5
+ Learn more about Brother Smooth Print [here](https://support.brother.com/g/s/es/dev/en/specific/smooth_print/index.html).
6
+
7
+ ## Usage
8
+
9
+ ```typescript
10
+ import { generatePrintUri } from "brother-smooth-print-uri";
11
+
12
+ const uri = generatePrintUri({
13
+ filename: "https://example.com/Simple.lbx",
14
+ size: "https://example.com/26x76.bin",
15
+ });
16
+ ```
17
+
18
+ See more examples in the tests: [src/uri-generator.test.ts](src/uri-generator.test.ts).
19
+
20
+ This package only creates the URI, it does not initiate the actual print job.
21
+
22
+ ## Limitations
23
+
24
+ - It doesn't include all parameters.
25
+ - It only supports single layout printing.
26
+ - Does not describe which printer series supports what.
27
+
28
+ Feel free to contribute.
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Brother Smooth Print arguments as defined here: https://support.brother.com/g/s/es/dev/en/specific/smooth_print/index.html?c=eu_ot&lang=en&comple=on&redirect=on
3
+ */
4
+ interface BrotherArgs {
5
+ /**
6
+ * Single layout template file (.lbx)
7
+ * @example https://example.com/Simple.lbx
8
+ */
9
+ filename: string;
10
+ /**
11
+ * Media settings file (bin)
12
+ * @example https://example.com/26x76.bin
13
+ */
14
+ size: string;
15
+ /**
16
+ * Number of copies to print
17
+ * @example 1
18
+ * @default 1
19
+ */
20
+ copies?: number;
21
+ /**
22
+ * Set one of the following options:
23
+ * threshold (Binary)
24
+ * pattern_dither (Dither)
25
+ * error_difusion (Error Diffusion)
26
+ * @default pattern_dither
27
+ */
28
+ halftone?: "threshold" | "pattern_dither" | "error_diffusion";
29
+ /**
30
+ * Set the brightness between -5 (light) and 5 (dark).
31
+ * @default 0
32
+ */
33
+ rjDensity?: -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5;
34
+ /**
35
+ * Rotate the printed image 180 degrees.
36
+ * @default false
37
+ */
38
+ rotate180?: boolean;
39
+ /**
40
+ * Automatically peel labels while printing.
41
+ * @default false
42
+ */
43
+ peelMode?: boolean;
44
+ /**
45
+ * Set one of the following options:
46
+ * normal = higher quality, but slower printing.
47
+ * double_speed = lower quality, but faster printing.
48
+ * @default normal
49
+ */
50
+ printQuality?: "normal" | "double_speed";
51
+ /**
52
+ * Set the paper orientation
53
+ * Defaults to the settings in the LBX file.
54
+ * @default landscape
55
+ */
56
+ orientation?: "portrait" | "landscape";
57
+ /**
58
+ * Set one of the print sizes:
59
+ * original = actual print size
60
+ * fit_to_page = adjust to the page size
61
+ * scale = increase or decrease the print ratio
62
+ * fit_to_paper = adjust the paper size
63
+ * @default fit_to_page
64
+ */
65
+ printMode?: "original" | "fit_to_page" | "scale" | "fit_to_paper";
66
+ /**
67
+ * Set a numeric value to scale the print out.
68
+ * Valid when printMode is set to "scale"
69
+ * Set 1 or less for PDF printing
70
+ * @default 1
71
+ */
72
+ scaleValue?: number;
73
+ /**
74
+ * Type an object name you specified for the text in P-touch Editor.
75
+ * (single layout)
76
+ *
77
+ * For "text_object_name" and "barcode_object_name", type the name you assigned to the text
78
+ * or barcode specified in the P-touch Editor layout file.
79
+ * For example, if you want to print a text string with the object name "TEXT",
80
+ * the parameter name must be "text_TEXT".
81
+ */
82
+ text_object_name?: string;
83
+ /**
84
+ * Type an object name you specified for the barcode in P-touch Editor.
85
+ * (single layout)
86
+ *
87
+ * For "text_object_name" and "barcode_object_name", type the name you assigned to the text
88
+ * or barcode specified in the P-touch Editor layout file.
89
+ * For example, if you want to print a text string with the object name "TEXT",
90
+ * the parameter name must be "text_TEXT".
91
+ */
92
+ barcode_object_name?: string;
93
+ /**
94
+ * Type an object name you specified for the image in P-touch Editor.
95
+ * (single layout)
96
+ * Supported format: jpg, jpeg, bmp, png
97
+ */
98
+ image_object_name?: string;
99
+ /**
100
+ * Set the base64 data as a print file to attach to a URL scheme.
101
+ * (single layout)
102
+ */
103
+ fileattach?: string;
104
+ /**
105
+ * Set the base64 data as a media information file to attach to a URL scheme.
106
+ */
107
+ sizeattach?: string;
108
+ /**
109
+ * Update and save files.
110
+ * @default false
111
+ */
112
+ formatarchiveupdate?: boolean;
113
+ /**
114
+ * Set a value (in pixels) to extend the length of the print area.
115
+ * When "formatarchiveupdate" is set to 1 (=On) and the attached file name is the same as the name of the existing file, newer files will overwrite the existing files.
116
+ * @default false
117
+ */
118
+ forceStretchPrintableArea?: boolean;
119
+ }
120
+
121
+ declare const generatePrintUri: (args: BrotherArgs) => URL;
122
+
123
+ export { type BrotherArgs, generatePrintUri };
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Brother Smooth Print arguments as defined here: https://support.brother.com/g/s/es/dev/en/specific/smooth_print/index.html?c=eu_ot&lang=en&comple=on&redirect=on
3
+ */
4
+ interface BrotherArgs {
5
+ /**
6
+ * Single layout template file (.lbx)
7
+ * @example https://example.com/Simple.lbx
8
+ */
9
+ filename: string;
10
+ /**
11
+ * Media settings file (bin)
12
+ * @example https://example.com/26x76.bin
13
+ */
14
+ size: string;
15
+ /**
16
+ * Number of copies to print
17
+ * @example 1
18
+ * @default 1
19
+ */
20
+ copies?: number;
21
+ /**
22
+ * Set one of the following options:
23
+ * threshold (Binary)
24
+ * pattern_dither (Dither)
25
+ * error_difusion (Error Diffusion)
26
+ * @default pattern_dither
27
+ */
28
+ halftone?: "threshold" | "pattern_dither" | "error_diffusion";
29
+ /**
30
+ * Set the brightness between -5 (light) and 5 (dark).
31
+ * @default 0
32
+ */
33
+ rjDensity?: -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5;
34
+ /**
35
+ * Rotate the printed image 180 degrees.
36
+ * @default false
37
+ */
38
+ rotate180?: boolean;
39
+ /**
40
+ * Automatically peel labels while printing.
41
+ * @default false
42
+ */
43
+ peelMode?: boolean;
44
+ /**
45
+ * Set one of the following options:
46
+ * normal = higher quality, but slower printing.
47
+ * double_speed = lower quality, but faster printing.
48
+ * @default normal
49
+ */
50
+ printQuality?: "normal" | "double_speed";
51
+ /**
52
+ * Set the paper orientation
53
+ * Defaults to the settings in the LBX file.
54
+ * @default landscape
55
+ */
56
+ orientation?: "portrait" | "landscape";
57
+ /**
58
+ * Set one of the print sizes:
59
+ * original = actual print size
60
+ * fit_to_page = adjust to the page size
61
+ * scale = increase or decrease the print ratio
62
+ * fit_to_paper = adjust the paper size
63
+ * @default fit_to_page
64
+ */
65
+ printMode?: "original" | "fit_to_page" | "scale" | "fit_to_paper";
66
+ /**
67
+ * Set a numeric value to scale the print out.
68
+ * Valid when printMode is set to "scale"
69
+ * Set 1 or less for PDF printing
70
+ * @default 1
71
+ */
72
+ scaleValue?: number;
73
+ /**
74
+ * Type an object name you specified for the text in P-touch Editor.
75
+ * (single layout)
76
+ *
77
+ * For "text_object_name" and "barcode_object_name", type the name you assigned to the text
78
+ * or barcode specified in the P-touch Editor layout file.
79
+ * For example, if you want to print a text string with the object name "TEXT",
80
+ * the parameter name must be "text_TEXT".
81
+ */
82
+ text_object_name?: string;
83
+ /**
84
+ * Type an object name you specified for the barcode in P-touch Editor.
85
+ * (single layout)
86
+ *
87
+ * For "text_object_name" and "barcode_object_name", type the name you assigned to the text
88
+ * or barcode specified in the P-touch Editor layout file.
89
+ * For example, if you want to print a text string with the object name "TEXT",
90
+ * the parameter name must be "text_TEXT".
91
+ */
92
+ barcode_object_name?: string;
93
+ /**
94
+ * Type an object name you specified for the image in P-touch Editor.
95
+ * (single layout)
96
+ * Supported format: jpg, jpeg, bmp, png
97
+ */
98
+ image_object_name?: string;
99
+ /**
100
+ * Set the base64 data as a print file to attach to a URL scheme.
101
+ * (single layout)
102
+ */
103
+ fileattach?: string;
104
+ /**
105
+ * Set the base64 data as a media information file to attach to a URL scheme.
106
+ */
107
+ sizeattach?: string;
108
+ /**
109
+ * Update and save files.
110
+ * @default false
111
+ */
112
+ formatarchiveupdate?: boolean;
113
+ /**
114
+ * Set a value (in pixels) to extend the length of the print area.
115
+ * When "formatarchiveupdate" is set to 1 (=On) and the attached file name is the same as the name of the existing file, newer files will overwrite the existing files.
116
+ * @default false
117
+ */
118
+ forceStretchPrintableArea?: boolean;
119
+ }
120
+
121
+ declare const generatePrintUri: (args: BrotherArgs) => URL;
122
+
123
+ export { type BrotherArgs, generatePrintUri };
package/dist/index.js ADDED
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ generatePrintUri: () => generatePrintUri
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+
27
+ // src/uri-generator.ts
28
+ var generatePrintUri = (args) => {
29
+ const searchParams = convertArgsToSearchParams(args);
30
+ return new URL(`brotherwebprint://print?${searchParams.toString()}`);
31
+ };
32
+ var convertArgsToSearchParams = (args) => {
33
+ const searchParams = new URLSearchParams();
34
+ let property;
35
+ for (property in args) {
36
+ const value = convertValueToString(args[property]);
37
+ if (value) {
38
+ searchParams.append(property, value);
39
+ }
40
+ }
41
+ return searchParams;
42
+ };
43
+ var convertValueToString = (value) => {
44
+ switch (typeof value) {
45
+ case "string":
46
+ return value;
47
+ case "number":
48
+ return value.toString();
49
+ case "boolean":
50
+ return value ? "1" : "0";
51
+ case "undefined":
52
+ return null;
53
+ default:
54
+ throw new Error(`Unsupported type: ${typeof value}`);
55
+ }
56
+ };
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ generatePrintUri
60
+ });
61
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/uri-generator.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./uri-generator\";\n","import { BrotherArgs } from \"./types\";\n\nexport const generatePrintUri = (args: BrotherArgs): URL => {\n const searchParams = convertArgsToSearchParams(args);\n return new URL(`brotherwebprint://print?${searchParams.toString()}`);\n};\n\nconst convertArgsToSearchParams = (args: BrotherArgs): URLSearchParams => {\n const searchParams = new URLSearchParams();\n\n let property: keyof typeof args;\n for (property in args) {\n const value = convertValueToString(args[property]);\n if (value) {\n searchParams.append(property, value);\n }\n }\n\n return searchParams;\n};\n\nconst convertValueToString = (\n value: BrotherArgs[keyof BrotherArgs]\n): string | null => {\n switch (typeof value) {\n case \"string\":\n return value;\n case \"number\":\n return value.toString();\n case \"boolean\":\n return value ? \"1\" : \"0\";\n case \"undefined\":\n return null;\n default:\n throw new Error(`Unsupported type: ${typeof value}`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,mBAAmB,CAAC,SAA2B;AAC1D,QAAM,eAAe,0BAA0B,IAAI;AACnD,SAAO,IAAI,IAAI,2BAA2B,aAAa,SAAS,CAAC,EAAE;AACrE;AAEA,IAAM,4BAA4B,CAAC,SAAuC;AACxE,QAAM,eAAe,IAAI,gBAAgB;AAEzC,MAAI;AACJ,OAAK,YAAY,MAAM;AACrB,UAAM,QAAQ,qBAAqB,KAAK,QAAQ,CAAC;AACjD,QAAI,OAAO;AACT,mBAAa,OAAO,UAAU,KAAK;AAAA,IACrC;AAAA,EACF;AAEA,SAAO;AACT;AAEA,IAAM,uBAAuB,CAC3B,UACkB;AAClB,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO,MAAM,SAAS;AAAA,IACxB,KAAK;AACH,aAAO,QAAQ,MAAM;AAAA,IACvB,KAAK;AACH,aAAO;AAAA,IACT;AACE,YAAM,IAAI,MAAM,qBAAqB,OAAO,KAAK,EAAE;AAAA,EACvD;AACF;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,34 @@
1
+ // src/uri-generator.ts
2
+ var generatePrintUri = (args) => {
3
+ const searchParams = convertArgsToSearchParams(args);
4
+ return new URL(`brotherwebprint://print?${searchParams.toString()}`);
5
+ };
6
+ var convertArgsToSearchParams = (args) => {
7
+ const searchParams = new URLSearchParams();
8
+ let property;
9
+ for (property in args) {
10
+ const value = convertValueToString(args[property]);
11
+ if (value) {
12
+ searchParams.append(property, value);
13
+ }
14
+ }
15
+ return searchParams;
16
+ };
17
+ var convertValueToString = (value) => {
18
+ switch (typeof value) {
19
+ case "string":
20
+ return value;
21
+ case "number":
22
+ return value.toString();
23
+ case "boolean":
24
+ return value ? "1" : "0";
25
+ case "undefined":
26
+ return null;
27
+ default:
28
+ throw new Error(`Unsupported type: ${typeof value}`);
29
+ }
30
+ };
31
+ export {
32
+ generatePrintUri
33
+ };
34
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/uri-generator.ts"],"sourcesContent":["import { BrotherArgs } from \"./types\";\n\nexport const generatePrintUri = (args: BrotherArgs): URL => {\n const searchParams = convertArgsToSearchParams(args);\n return new URL(`brotherwebprint://print?${searchParams.toString()}`);\n};\n\nconst convertArgsToSearchParams = (args: BrotherArgs): URLSearchParams => {\n const searchParams = new URLSearchParams();\n\n let property: keyof typeof args;\n for (property in args) {\n const value = convertValueToString(args[property]);\n if (value) {\n searchParams.append(property, value);\n }\n }\n\n return searchParams;\n};\n\nconst convertValueToString = (\n value: BrotherArgs[keyof BrotherArgs]\n): string | null => {\n switch (typeof value) {\n case \"string\":\n return value;\n case \"number\":\n return value.toString();\n case \"boolean\":\n return value ? \"1\" : \"0\";\n case \"undefined\":\n return null;\n default:\n throw new Error(`Unsupported type: ${typeof value}`);\n }\n};\n"],"mappings":";AAEO,IAAM,mBAAmB,CAAC,SAA2B;AAC1D,QAAM,eAAe,0BAA0B,IAAI;AACnD,SAAO,IAAI,IAAI,2BAA2B,aAAa,SAAS,CAAC,EAAE;AACrE;AAEA,IAAM,4BAA4B,CAAC,SAAuC;AACxE,QAAM,eAAe,IAAI,gBAAgB;AAEzC,MAAI;AACJ,OAAK,YAAY,MAAM;AACrB,UAAM,QAAQ,qBAAqB,KAAK,QAAQ,CAAC;AACjD,QAAI,OAAO;AACT,mBAAa,OAAO,UAAU,KAAK;AAAA,IACrC;AAAA,EACF;AAEA,SAAO;AACT;AAEA,IAAM,uBAAuB,CAC3B,UACkB;AAClB,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO,MAAM,SAAS;AAAA,IACxB,KAAK;AACH,aAAO,QAAQ,MAAM;AAAA,IACvB,KAAK;AACH,aAAO;AAAA,IACT;AACE,YAAM,IAAI,MAAM,qBAAqB,OAAO,KAAK,EAAE;AAAA,EACvD;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "brother-smooth-print-uri",
3
+ "version": "1.0.0",
4
+ "description": "URI Generator for Brother Smooth Print",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsup",
13
+ "test": "jest",
14
+ "prepublishOnly": "npm run build && npm test"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/lajtmaN/brother-smooth-print-uri.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/lajtmaN/brother-smooth-print-uri/issues"
22
+ },
23
+ "homepage": "https://github.com/lajtmaN/brother-smooth-print-uri#readme",
24
+ "keywords": [
25
+ "brother",
26
+ "printer",
27
+ "label",
28
+ "smooth-print",
29
+ "uri",
30
+ "generator",
31
+ "printing"
32
+ ],
33
+ "author": "Tim Gjøderum",
34
+ "license": "ISC",
35
+ "engines": {
36
+ "node": ">=14.0.0"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "devDependencies": {
42
+ "@types/jest": "^29.5.12",
43
+ "jest": "^29.7.0",
44
+ "ts-jest": "^29.1.2",
45
+ "ts-node": "^10.9.2",
46
+ "tsup": "^8.0.2",
47
+ "typescript": "^5.4.4"
48
+ }
49
+ }