From 8ab63621f2410639da307da54ae8c8f207f6a6bd Mon Sep 17 00:00:00 2001 From: Yeasir H Date: Thu, 1 Feb 2024 03:02:59 -0800 Subject: [PATCH 1/6] add setPrinter & fitPage functionality --- docs/options.md | 1 + src/BrotherSdk.ts | 44 ++++++++++++++++++++++------------- src/adapter.ts | 46 +++++++++++++++++++++++-------------- src/helpers.ts | 5 +++- src/types.ts | 16 +++++++++++-- tests/browser/playground.js | 6 +++-- tests/helpers.spec.ts | 4 ++++ 7 files changed, 84 insertions(+), 38 deletions(-) diff --git a/docs/options.md b/docs/options.md index 68ce94d..bc954ad 100644 --- a/docs/options.md +++ b/docs/options.md @@ -22,6 +22,7 @@ Properties are applicable exclusively to models that support each respective fun | color | boolean | false |Print in color.| | mono | boolean | false |Print in monochrome.| | continue | boolean | false |Front margin not output.| +| fitPage | boolean | false |Specify whether to adjust the size and position of objects in the template in accordance with layout changes resulting from media changes. If set to true, adjustments will be made; otherwise, if set to false or undefined, no adjustments will be applied..| ## Supported Export Extensions | **Description** | **Extension** | diff --git a/src/BrotherSdk.ts b/src/BrotherSdk.ts index 90d2217..c577ddf 100644 --- a/src/BrotherSdk.ts +++ b/src/BrotherSdk.ts @@ -8,6 +8,7 @@ import { Data, PrintConfig, ImageOptions, + Constructor, } from "./types"; import { openTemplate, @@ -20,6 +21,7 @@ import { printOut, endPrint, exportTemplate, + setPrinter, } from "./adapter"; export default class BrotherSdk { @@ -27,7 +29,9 @@ export default class BrotherSdk { templatePath: string; - exportDir: string; + printer: undefined | string; + + exportDir: undefined | string; // One mutation observer, regardless of instances. static #observer: MutationObserver | undefined; @@ -64,16 +68,14 @@ export default class BrotherSdk { * The path for exporting generated templates. * - Win path: "C:\\\path\\\to\\\your\\\" * - Unix path: "/home/templates/" + * @param {String} [object.printer = undefined] + * The name of the printer used for printing. Specify the printer name, not the path. + * - Example: "Brother QL-820NWB" */ - constructor({ - templatePath, - exportDir, - }: { - templatePath: string; - exportDir?: string; - }) { + constructor({ templatePath, exportDir, printer }: Constructor) { this.templatePath = templatePath; - this.exportDir = exportDir || ""; + this.exportDir = exportDir; + this.printer = printer; this.#ready = false; this.#initialize(); } @@ -86,12 +88,12 @@ export default class BrotherSdk { return; } - if (targetNode.classList.contains(className)) { - this.#ready = true; + if (BrotherSdk.#observer) { return; } - if (BrotherSdk.#observer) { + if (targetNode.classList.contains(className)) { + this.#ready = true; return; } @@ -180,17 +182,27 @@ export default class BrotherSdk { * @param {boolean} [config.continue = false] * Combines with printing for the following DoPrint( ) so that it is a single print job. * As a result, when the next DoPrints are called up, the front margins are not output. + * @param {boolean} [config.fitPage = false] + * Specify whether to adjust the size and position of objects in the template in accordance + * with layout changes resulting from media changes. If set to true, adjustments + * will be made; otherwise, if set to false or undefined, no adjustments will be applied. */ async print(data: Data, config?: PrintConfig): Promise { - const { copies = 1, printName = "BPAC-Document", ...rest } = config || {}; - - const bitmaskNumber = getStartPrintOptions(rest); + const { + copies = 1, + printName = "BPAC-Document", + fitPage = false, + ...opts + } = config || {}; await this.#isPrintReady(); + const bitMask = getStartPrintOptions(opts); + await openTemplate(this.templatePath); + await setPrinter(this.printer, fitPage); await populateObjectsInTemplate(data); - await startPrint(printName, bitmaskNumber); + await startPrint(printName, bitMask); await printOut(copies); await endPrint(); await closeTemplate(); diff --git a/src/adapter.ts b/src/adapter.ts index 2555222..b03d3bd 100644 --- a/src/adapter.ts +++ b/src/adapter.ts @@ -1,22 +1,34 @@ import * as bpac from "./vendor/bpac-v3.4"; import { Data, ObjectTypes } from "./types"; -const doc = bpac.IDocument; +const Doc = bpac.IDocument; -export const openTemplate = async (path: string): Promise => { - const isOpen:boolean = await doc.Open(path); +export const openTemplate = async (path: string): Promise => { + const isOpen:boolean = await Doc.Open(path); if (!isOpen) { + throw new Error("Failed to open the template file."); + } +}; + +export const setPrinter = async (printer: string | undefined, fitPage: boolean): Promise => { + if (printer === undefined && fitPage === false) return; + + if (printer === undefined && fitPage === true) { + throw new Error("To use fitPage, you must manually set the printer name."); + } + + const isPrinter:boolean = await Doc.SetPrinter(printer, fitPage); + + if (!isPrinter) { throw new Error( - "Failed to open template file.", + `Failed to set the printer. The specified printer "${printer}" may not exist or is not accessible.`, ); } - - return true; }; export const closeTemplate = async (): Promise => { - const isClosed = await doc.Close(); + const isClosed = await Doc.Close(); if (!isClosed) { throw new Error("Failed to close template file."); @@ -26,7 +38,7 @@ export const closeTemplate = async (): Promise => { }; export const startPrint = async (printName:string, bitmask:number): Promise => { - const isStarted:boolean = await doc.StartPrint(printName, bitmask); + const isStarted:boolean = await Doc.StartPrint(printName, bitmask); if (!isStarted) { await closeTemplate(); @@ -37,18 +49,18 @@ export const startPrint = async (printName:string, bitmask:number): Promise => { - const isPrinted:boolean = await doc.PrintOut(copies, 0); + const isPrinted:boolean = await Doc.PrintOut(copies, 0); if (!isPrinted) { await closeTemplate(); - throw new Error("Failed to print out."); + throw new Error("Failed to print, please verify the printer name is correct for the template."); } return true; }; export const endPrint = async () => { - const hasEnded:boolean = await doc.EndPrint(); + const hasEnded:boolean = await Doc.EndPrint(); if (!hasEnded) { await closeTemplate(); @@ -59,23 +71,23 @@ export const endPrint = async () => { }; export const imageData = async (width:number, height:number): Promise => { - const data = await doc.GetImageData(4, width, height); + const data = await Doc.GetImageData(4, width, height); return data; }; export const getPrinterName = async (): Promise => { - const printerName: string = await doc.GetPrinterName(); + const printerName: string = await Doc.GetPrinterName(); return printerName; }; export const getPrinters = async (): Promise => { - const obj = await doc.GetPrinter(); + const obj = await Doc.GetPrinter(); const printers = await obj.GetInstalledPrinters(); return printers; }; export const exportTemplate = async (type:number, dest:string, res:number): Promise => { - const isExported:boolean = await doc.Export(type, dest, res); + const isExported:boolean = await Doc.Export(type, dest, res); if (!isExported) { await closeTemplate(); @@ -91,7 +103,7 @@ export const populateObjectsInTemplate = async (data: Data): Promise => // eslint-disable-next-line no-restricted-syntax for (const prop of keys) { const value = data[prop]; - const obj = await doc.GetObject(prop); + const obj = await Doc.GetObject(prop); if (!obj) { await closeTemplate(); @@ -113,7 +125,7 @@ export const populateObjectsInTemplate = async (data: Data): Promise => await obj.SetData(0, value); break; case ObjectTypes.Barcode: - await doc.SetBarcodeData(0, value); + await Doc.SetBarcodeData(0, value); break; case ObjectTypes.ClipArt: await obj.SetData(0, value, 0); diff --git a/src/helpers.ts b/src/helpers.ts index 1827301..bc789bf 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -19,7 +19,10 @@ const optionBitmaskMap: { [key in keyof StartPrintOptions]: number } = { continue: 0x40000000, }; -export const getAbsolutePath = (basePath: string, filePathOrFileName: string): string => { +export const getAbsolutePath = ( + basePath: string | undefined, + filePathOrFileName: string, +): string => { // eslint-disable-next-line no-useless-escape const isPath = /^(.*[\\\/])([^\\\/]+)\.([^.]+)$/; diff --git a/src/types.ts b/src/types.ts index a7b56b8..9e609b5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,12 @@ -export type Data = Record; +export type Data = { + [key:string] : string | Date +}; + +export type Constructor = { + templatePath: string; + exportDir?: string; + printer?: string; +}; export type PrintOptions = { copies?: number; @@ -24,7 +32,11 @@ export type StartPrintOptions = { continue?: boolean, }; -export type PrintConfig = PrintOptions & StartPrintOptions; +export type FitPage = { + fitPage: boolean; +}; + +export type PrintConfig = PrintOptions & StartPrintOptions & FitPage; export type ImageOptions = { width?: number; diff --git a/tests/browser/playground.js b/tests/browser/playground.js index 0007042..47f876d 100644 --- a/tests/browser/playground.js +++ b/tests/browser/playground.js @@ -11,16 +11,18 @@ const tag = new BrotherSdk({ exportDir: "C:/Users/YMH/Desktop/Exported Labels/", }); + const data = { title: "Test Label", date: new Date("1/1/23"), barcode: "074608352052", image: "C:/Users/YMH/Desktop/Storage Drive Files/Logos/Monogram/my-logo.png", }; -/* {autoCut: true, mirroring: true, specialTape:true} */ + const printTag = async () => { try { - const complete = await tag.print(data, { highResolution: true, autoCut:true }); + //tag.printer = "Brother QL-820NWB"; + const complete = await tag.print(data, { highSpeed: true, autoCut:true, fitPage: false }); console.log({ complete }); } catch (error) { console.log({ error }); diff --git a/tests/helpers.spec.ts b/tests/helpers.spec.ts index efd5772..9464fd6 100644 --- a/tests/helpers.spec.ts +++ b/tests/helpers.spec.ts @@ -53,6 +53,10 @@ describe("Helpers", () => { expect(() => getAbsolutePath()).to.throw(Error); }); + it("Should throw an error when only one arg is passed.", () => { + expect(() => getAbsolutePath(undefined, dir.fileName)).to.throw(Error); + }); + it("Should combine path and filename (backslashes).", () => { const result = getAbsolutePath(dir.winBase, dir.fileName); expect(result).to.have.string("C:\\Templates\\label.lbx"); From 7859db0d5fb0bd8fa5c016c96577dd1f4f00b595 Mon Sep 17 00:00:00 2001 From: Yeasir H Date: Sat, 3 Feb 2024 00:14:40 -0800 Subject: [PATCH 2/6] refactor & doc update --- .github/images/auto-cut.png | Bin 0 -> 2665 bytes .github/images/auto-half-chain.png | Bin 0 -> 2215 bytes .github/images/auto-half-cut.png | Bin 0 -> 2177 bytes .github/images/chain-print.png | Bin 0 -> 1513 bytes .github/images/half-cut-chain.png | Bin 0 -> 1792 bytes .github/images/half-cut.png | Bin 0 -> 2393 bytes .github/images/no-cut.png | Bin 0 -> 2017 bytes docs/options.md | 31 +++-- docs/usage.md | 2 +- src/BrotherSdk.ts | 175 ++++++++++++++--------------- src/adapter.ts | 2 +- src/helpers.ts | 19 ++-- src/types.ts | 3 +- tests/browser/index.html | 1 + tests/browser/playground.js | 38 ++++++- 15 files changed, 152 insertions(+), 119 deletions(-) create mode 100644 .github/images/auto-cut.png create mode 100644 .github/images/auto-half-chain.png create mode 100644 .github/images/auto-half-cut.png create mode 100644 .github/images/chain-print.png create mode 100644 .github/images/half-cut-chain.png create mode 100644 .github/images/half-cut.png create mode 100644 .github/images/no-cut.png diff --git a/.github/images/auto-cut.png b/.github/images/auto-cut.png new file mode 100644 index 0000000000000000000000000000000000000000..163ae3203aee49abec40e922bf85724c82a31d1e GIT binary patch literal 2665 zcmV-v3YPVWP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN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$x|uLKUq1DVSCVW^3AldKUzOB0U=?fFiY4ABTI!8q zNciCn#CyvFUWyLe{IG-I$AeUcpp~35ndQ)+l33borf-?H(&e_xB4;TGwL+ z{xsA!V8kSQ%F>TajD7}Byl>sQ1%FyP9q8g!nHn1(a$G7>6l8GTEs7)pl3+D8TX<}v6)ZmpSCo@e+H-CbJ%D_)^5C4ngSF1pj)ZA^8G7eNt z9+8dEu|gCEJAKGW2O5Q>c#MuJ#6FIqV^OO!U=zkffAe!%Ek%-y?pITL{y zl6~$v%2$nQ zRhAOsf>DhU(v+AnfeJzz8>KeoOcVqWE}GAtJ*xx^pyF%60f1Q|>JiO$JtGcTU9Ija z3_U$`#=+NNcph=|EjdTDnUc4yh#keID>A5F)4<9~Uuh#`sV%-<^T^SNylV#BeS0Xh=zI59VrYh2$-HS1OY@@nP;DhRos zeXiuAD6dR@uM7zD*~F6Vfq{X);i-h5(c)*7m?#Hw3OnI$mmCx(_l*k0>r!=UA8hT7 p&-5aI(KvIL&;JPh&j5FH{0WA@+^<4|hOGbq002ovPDHLkV1j6pH2(kq literal 0 HcmV?d00001 diff --git a/.github/images/auto-half-cut.png b/.github/images/auto-half-cut.png new file mode 100644 index 0000000000000000000000000000000000000000..67f3fbad517f3bcaeec673fb0ace94bb65957eeb GIT binary patch literal 2177 zcmV-{2!8j8P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&2o_01K~!i%?V4Fn zlvxml+d;)0G$JmM3xB0IgyjMgy>f{c{sV4E3?iZ+OVcclfSMpgBXI>6+&55h=K1<* ziyqQA(?c_JVZRqA_0?CWPM!Bu)pt6O`s3Hb_wU~smzI`%{PN|?h7B7U8yk@a1_t{2 z`o_k_IyyQgCMJf5hcoG+GDkU%8X6jqdwYBP`}?n4xiUF9+0)b0)zwwzD1jW+*VivD zE|NHK^m`WF-Q9QY+$nREK#qeWTaec3FN4`xtW%9?%cVf zM~@yqe*E<5(-$sWpyJ9LC6J?3Dz$a%Rz|^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phK7csq9R&W zRaKR8xS{*U9lE+{Bq%+1Z!p|G&9uC7ko zXvM|FJ_QLQ_HCCEmRs1OQv6XP}z@MY0==oEZ#D$gUqge5k0Xz*c@FM2%q> zv;=TQ>hyHw?Y9 z*lGhXL!7X$z#)vl3!01>Lre|6%wyZA`!fMH0VsM9wnti=fvv4ATV&HvKcgE1wIrZK zT{ky3i4bloBCM^g@w(uZ9nKXaO)wz8wD5P+`!jJrBZfzUvP~G7LC5+K%^60VLv`ti zT@`#2Ars~WGmZkAg^a|+fC(Exk4qxDh5suil$HV$ft;LSBwc2ztE(}rs}14i2{zzU z{ew_BHqHR@@!oTWjrhWX&57sn{!GBH)a62KD4``Hvl(M}d+?F!hrhM(HNrtxfl%TO zsI9HVw!NMc9=#i|fk7C_{Ql}+9=2(i7AR8TPtA6QDoNrV?5N6iiScp+eOS>k=LfLek7g-c`&n@@e2Hd2`ce zXlO_#*b$TP{TCo*4R6nM1Bzv=tgK`VS4+f%ubloPY++#`kw{EVPV#Fe9*^^TKdtck z^=oeS_V)HCPo6w}{FtK0VllpkQIJ|oGY6fH?6M7;Oj>rF(NqqJ%zBkRAcZN_a P00000NkvXXu0mjfy;;WZ literal 0 HcmV?d00001 diff --git a/.github/images/half-cut-chain.png b/.github/images/half-cut-chain.png new file mode 100644 index 0000000000000000000000000000000000000000..466e666b10d8e1cb524f3d96f167b65c512fbc27 GIT binary patch literal 1792 zcmV+b2mknqP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&29-%fK~z{r)z`~T zlvxl5aJsz!UO@4#Q6uOZj5CkGdyu#xaqrHRx-;QjG%+!5oB`v+70d(#6rxcP@P0uq zqx0+U-}wNiH9D*AiaFG&Q&p$_bva*K`SRsUTPx6~PoH+}+I8j1mBGQm2M->6{P^+1 zhYx%9>{(t~i9$7hnx8s4I{qnW=gysP-n^NcnPtW-HI6QT7T-R-SQjLLufn&#xJ$m%0udh#c>9=2h`7Ng{ zgG5cXZr!?l`*!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kP;4uDT*IEIxQDs1Rag1azX2@C|HS1g27)-0H1X_3S5(+;QICJj9__rS%pR} zP!90b^3AuE-L3%k%7L!bhEW0%w2F<>gwv^ROY74BgYdXL^v;xRO4hsSxGq* zd{N)9yS+yikPebFF8p? z&>B} - * a promise that resolves to an array of installed printers - * compatible with the 'bpac' SDK. - * @throws {Error} - * will throw an err if the method fails. - * - */ - static async getPrinterList(): Promise { - const printers = await getPrinters(); - return printers; - } + static #ready: boolean = false; /** - * @constructor - * Constructs a new instance of the BrotherSdk class, used - * for interacting with Brother SDK functionality. + * **BPAC-JS Class Object** + * + * Create a new instance of this class to interact with the Brother SDK + * in JavaScript. This object facilitates communication and integration + * with the SDK functionalities. * @param {Object} object * @param {String} object.templatePath - * Specifies the path to the template file (supports various formats) + * Specifies the path to the template file * - Win path: "C:\\\path\\\to\\\your\\\template.lbx" * - Unix path: "/home/templates/template.lbx" * - UNC path: "\\\server\share\template.lbx" * - Remote URL: "http://yourserver.com/templates/label.lbx" * @param {String} [object.exportDir = ""] - * The path for exporting generated templates. + * The path for exporting generated assets. * - Win path: "C:\\\path\\\to\\\your\\\" * - Unix path: "/home/templates/" * @param {String} [object.printer = undefined] @@ -76,59 +61,7 @@ export default class BrotherSdk { this.templatePath = templatePath; this.exportDir = exportDir; this.printer = printer; - this.#ready = false; - this.#initialize(); - } - - #initialize() { - const targetNode = document.body; - const className = "bpac-extension-installed"; - - if (this.#ready) { - return; - } - - if (BrotherSdk.#observer) { - return; - } - - if (targetNode.classList.contains(className)) { - this.#ready = true; - return; - } - - BrotherSdk.#observer = new MutationObserver(() => { - if (targetNode.classList.contains(className)) { - this.#ready = true; - BrotherSdk.#observer?.disconnect(); - BrotherSdk.#observer = undefined; - } - }); - - BrotherSdk.#observer.observe(targetNode, { - attributes: true, - attributeFilter: ["class"], - }); - } - - async #isPrintReady(timeout: number = 3000): Promise { - if (this.#ready) { - return true; - } - - return new Promise((resolve, reject) => { - setTimeout(() => { - if (this.#ready) { - resolve(true); - } else { - reject( - new Error( - "Cannot establish printer communication: b-PAC extension missing or inactive. Install/enable.", - ), - ); - } - }, timeout); - }); + BrotherSdk.#initialize(); } /** @@ -179,9 +112,6 @@ export default class BrotherSdk { * @param {boolean} [config.mono = false] * Monochrome printing is performed. Valid only with models supporting * the color printing function. - * @param {boolean} [config.continue = false] - * Combines with printing for the following DoPrint( ) so that it is a single print job. - * As a result, when the next DoPrints are called up, the front margins are not output. * @param {boolean} [config.fitPage = false] * Specify whether to adjust the size and position of objects in the template in accordance * with layout changes resulting from media changes. If set to true, adjustments @@ -195,14 +125,14 @@ export default class BrotherSdk { ...opts } = config || {}; - await this.#isPrintReady(); + await BrotherSdk.printerIsReady(); - const bitMask = getStartPrintOptions(opts); + const hexValue = getStartPrintOptions(opts); await openTemplate(this.templatePath); await setPrinter(this.printer, fitPage); await populateObjectsInTemplate(data); - await startPrint(printName, bitMask); + await startPrint(printName, hexValue); await printOut(copies); await endPrint(); await closeTemplate(); @@ -236,7 +166,7 @@ export default class BrotherSdk { const height = options?.height || 0; const width = options?.width || 0; - await this.#isPrintReady(); + await BrotherSdk.printerIsReady(); await openTemplate(this.templatePath); await populateObjectsInTemplate(data); const base64Data = await imageData(width, height); @@ -257,11 +187,11 @@ export default class BrotherSdk { * */ async getPrinterName(): Promise { - await this.#isPrintReady(); + await BrotherSdk.printerIsReady(); await openTemplate(this.templatePath); - const printer = getPrinterName(); + const printerName = getPrinterName(); await closeTemplate(); - return printer; + return printerName; } /** @@ -296,7 +226,7 @@ export default class BrotherSdk { filePathOrFileName, ); - await this.#isPrintReady(); + await BrotherSdk.printerIsReady(); await openTemplate(this.templatePath); await populateObjectsInTemplate(data); const status = await exportTemplate(fileType, path, resolution); @@ -310,4 +240,73 @@ export default class BrotherSdk { return true; } + + static #initialize():void { + const targetNode = document.body; + const className = "bpac-extension-installed"; + + if (BrotherSdk.#ready) { + return; + } + + if (BrotherSdk.#observer) { + return; + } + + if (targetNode.classList.contains(className)) { + BrotherSdk.#ready = true; + return; + } + + BrotherSdk.#observer = new MutationObserver(() => { + if (targetNode.classList.contains(className)) { + BrotherSdk.#ready = true; + BrotherSdk.#observer?.disconnect(); + BrotherSdk.#observer = null; + } + }); + + BrotherSdk.#observer.observe(targetNode, { + attributes: true, + attributeFilter: ["class"], + }); + } + + /** + * **Get List Of Installed Printers** + * + * asynchronously retrieves the list of installed printers compatible with the bpac SDK. + * + * @returns {Promise} + * a promise that resolves to an array of installed printers + * compatible with the 'bpac' SDK. + * @throws {Error} + * will throw an err if the method fails. + * + */ + static async getPrinterList(): Promise { + await BrotherSdk.printerIsReady(); + const printers = await getPrinters(); + return printers; + } + + static async printerIsReady(timeout: number = 3000): Promise { + if (BrotherSdk.#ready) { + return true; + } + + return new Promise((resolve, reject) => { + setTimeout(() => { + if (BrotherSdk.#ready) { + resolve(true); + } else { + reject( + new Error( + "Cannot establish printer communication: b-PAC extension missing or inactive. Install/enable.", + ), + ); + } + }, timeout); + }); + } } diff --git a/src/adapter.ts b/src/adapter.ts index b03d3bd..ddf02f0 100644 --- a/src/adapter.ts +++ b/src/adapter.ts @@ -15,7 +15,7 @@ export const setPrinter = async (printer: string | undefined, fitPage: boolean): if (printer === undefined && fitPage === false) return; if (printer === undefined && fitPage === true) { - throw new Error("To use fitPage, you must manually set the printer name."); + throw new Error("To use fitPage, you must explicity set the printer name."); } const isPrinter:boolean = await Doc.SetPrinter(printer, fitPage); diff --git a/src/helpers.ts b/src/helpers.ts index bc789bf..a7841fd 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,6 +1,6 @@ import { StartPrintOptions } from "./types"; -const optionBitmaskMap: { [key in keyof StartPrintOptions]: number } = { +const optionToHexMap: { [key:string]: number } = { autoCut: 0x1, cutPause: 0x1, cutMark: 0x2, @@ -16,7 +16,6 @@ const optionBitmaskMap: { [key in keyof StartPrintOptions]: number } = { highResolution: 0x02000000, color: 0x8, mono: 0x10000000, - continue: 0x40000000, }; export const getAbsolutePath = ( @@ -54,22 +53,20 @@ export const getExportType = (fileExt:string) => { }; export const getStartPrintOptions = (options: StartPrintOptions): number => { - const combinedBitmask: number[] = []; + const combinedHexArray: number[] = []; - Object.entries(options).forEach(([key, value]) => { - const k = key as keyof StartPrintOptions; + Object.entries(options).forEach(([key, value]): void => { + if (value === true && optionToHexMap[key] !== undefined) { + const hexadecimal = optionToHexMap[key]; - if (value === true && optionBitmaskMap[k] !== undefined) { - const bitmaskValue: number | undefined = optionBitmaskMap[k]; - - if (bitmaskValue !== undefined) { - combinedBitmask.push(bitmaskValue); + if (hexadecimal !== undefined) { + combinedHexArray.push(hexadecimal); } } }); // eslint-disable-next-line no-bitwise - return combinedBitmask.reduce((acc, val) => acc | val, 0x0); + return combinedHexArray.reduce((acc, val) => acc | val, 0x0); }; export const getFileExtension = (filePathOrFileName:string): string => { diff --git a/src/types.ts b/src/types.ts index 9e609b5..badc8e6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -29,11 +29,10 @@ export type StartPrintOptions = { highResolution?: boolean, color?: boolean, mono?: boolean, - continue?: boolean, }; export type FitPage = { - fitPage: boolean; + fitPage?: boolean; }; export type PrintConfig = PrintOptions & StartPrintOptions & FitPage; diff --git a/tests/browser/index.html b/tests/browser/index.html index bda6a03..2b3235e 100644 --- a/tests/browser/index.html +++ b/tests/browser/index.html @@ -12,6 +12,7 @@

bpac test

+ diff --git a/tests/browser/playground.js b/tests/browser/playground.js index 47f876d..085fa35 100644 --- a/tests/browser/playground.js +++ b/tests/browser/playground.js @@ -4,13 +4,16 @@ import { BrotherSdk } from "../../dist/index.js"; const printBtn = document.getElementById("print-btn"); const previewBtn = document.getElementById("preview-btn"); const exportBtn = document.getElementById("export-btn"); +const getPrintersBtn = document.getElementById("get-printers-btn"); const preview = document.getElementById("preview"); const tag = new BrotherSdk({ templatePath: "C:/Users/YMH/Desktop/example.lbx", exportDir: "C:/Users/YMH/Desktop/Exported Labels/", + printer: "Brother QL-820NWB" }); +// tag.printer = "Brother PT-9800PCN"; const data = { title: "Test Label", @@ -19,11 +22,25 @@ const data = { image: "C:/Users/YMH/Desktop/Storage Drive Files/Logos/Monogram/my-logo.png", }; +const dataOne = { + title: "Test Label One", + date: new Date("1/1/23"), + barcode: "074608352052", + image: "C:/Users/YMH/Desktop/Storage Drive Files/Logos/Monogram/my-logo.png", +}; + +const dataTwo = { + title: "Test Label Two", + date: new Date("1/1/24"), + barcode: "074608352052", + image: "C:/Users/YMH/Desktop/Storage Drive Files/Logos/Monogram/my-logo.png", +}; + const printTag = async () => { try { - //tag.printer = "Brother QL-820NWB"; - const complete = await tag.print(data, { highSpeed: true, autoCut:true, fitPage: false }); - console.log({ complete }); + for (const record of [dataOne/* , dataTwo */]){ + await tag.print(record, {copies: 2, cutAtEnd: true}); + } } catch (error) { console.log({ error }); } @@ -31,8 +48,7 @@ const printTag = async () => { const previewTag = async () => { try { - preview.src = ""; - const imgData = await tag.getImageData(data, {height: 120}); + const imgData = await tag.getImageData(data, { height: 120 }); preview.src = imgData; } catch (error) { console.log({ error }); @@ -48,6 +64,16 @@ const exportTag = async () => { } }; +const getPrinters = async () => { + try { + const printers = await BrotherSdk.getPrinterList(); + console.log({ printers }) + } catch (error) { + console.log({ error }); + } +}; + printBtn.addEventListener("click", printTag); previewBtn.addEventListener("click", previewTag); -exportBtn.addEventListener("click", exportTag); \ No newline at end of file +exportBtn.addEventListener("click", exportTag); +getPrintersBtn.addEventListener("click", getPrinters); \ No newline at end of file From 1c6ca5497f477a190af7b0ead391790763839cc6 Mon Sep 17 00:00:00 2001 From: Yeasir H Date: Fri, 9 Feb 2024 16:52:09 -0800 Subject: [PATCH 3/6] refactor Data type --> TemplateData --- src/BrotherSdk.ts | 29 ++++++++++++----------------- src/adapter.ts | 29 +++++++++++++---------------- src/types.ts | 2 +- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/BrotherSdk.ts b/src/BrotherSdk.ts index 5a81094..7006b99 100644 --- a/src/BrotherSdk.ts +++ b/src/BrotherSdk.ts @@ -5,7 +5,7 @@ import { getStartPrintOptions, } from "./helpers"; import { - Data, + TemplateData, PrintConfig, ImageOptions, Constructor, @@ -56,6 +56,9 @@ export default class BrotherSdk { * @param {String} [object.printer = undefined] * The name of the printer used for printing. Specify the printer name, not the path. * - Example: "Brother QL-820NWB" + * @example + * //use the static method getPrinterList() to obtain a list of installed printers. + * BrotherSdk.getPrinterList() */ constructor({ templatePath, exportDir, printer }: Constructor) { this.templatePath = templatePath; @@ -117,7 +120,7 @@ export default class BrotherSdk { * with layout changes resulting from media changes. If set to true, adjustments * will be made; otherwise, if set to false or undefined, no adjustments will be applied. */ - async print(data: Data, config?: PrintConfig): Promise { + async print(data: TemplateData, config?: PrintConfig): Promise { const { copies = 1, printName = "BPAC-Document", @@ -160,7 +163,7 @@ export default class BrotherSdk { * A promise that resolves to a Base64 encoded string representing the image data. */ async getImageData( - data: Data, + data: TemplateData, options: ImageOptions, ): Promise { const height = options?.height || 0; @@ -182,8 +185,6 @@ export default class BrotherSdk { * * @returns {Promise} * A promise that resolves with the name of the printer. - * @throws {Error} - * Fails to get the printer name. * */ async getPrinterName(): Promise { @@ -214,10 +215,12 @@ export default class BrotherSdk { * If a value of 0 is specified, the printer resolution is used. * * The resolution param is only valid for .lbi and .bmp extensions. - * @throws {Error} - * Fails to export. */ - async export(data: Data, filePathOrFileName: string, resolution: number = 0): Promise { + async export( + data: TemplateData, + filePathOrFileName: string, + resolution: number = 0, + ): Promise { const fileExt = getFileExtension(filePathOrFileName); const fileType = getExportType(fileExt); @@ -229,15 +232,9 @@ export default class BrotherSdk { await BrotherSdk.printerIsReady(); await openTemplate(this.templatePath); await populateObjectsInTemplate(data); - const status = await exportTemplate(fileType, path, resolution); + await exportTemplate(fileType, path, resolution); await closeTemplate(); - if (!status) { - throw new Error( - "Export failed: Please check the export directory and filename.", - ); - } - return true; } @@ -280,8 +277,6 @@ export default class BrotherSdk { * @returns {Promise} * a promise that resolves to an array of installed printers * compatible with the 'bpac' SDK. - * @throws {Error} - * will throw an err if the method fails. * */ static async getPrinterList(): Promise { diff --git a/src/adapter.ts b/src/adapter.ts index ddf02f0..d876522 100644 --- a/src/adapter.ts +++ b/src/adapter.ts @@ -1,5 +1,5 @@ import * as bpac from "./vendor/bpac-v3.4"; -import { Data, ObjectTypes } from "./types"; +import { TemplateData, ObjectTypes } from "./types"; const Doc = bpac.IDocument; @@ -12,15 +12,15 @@ export const openTemplate = async (path: string): Promise => { }; export const setPrinter = async (printer: string | undefined, fitPage: boolean): Promise => { - if (printer === undefined && fitPage === false) return; + if (printer === undefined && fitPage === false) { return; } if (printer === undefined && fitPage === true) { throw new Error("To use fitPage, you must explicity set the printer name."); } - const isPrinter:boolean = await Doc.SetPrinter(printer, fitPage); + const isPrinterSet:boolean = await Doc.SetPrinter(printer, fitPage); - if (!isPrinter) { + if (!isPrinterSet) { throw new Error( `Failed to set the printer. The specified printer "${printer}" may not exist or is not accessible.`, ); @@ -86,33 +86,30 @@ export const getPrinters = async (): Promise => { return printers; }; -export const exportTemplate = async (type:number, dest:string, res:number): Promise => { +export const exportTemplate = async (type:number, dest:string, res:number): Promise => { const isExported:boolean = await Doc.Export(type, dest, res); if (!isExported) { await closeTemplate(); throw new Error(`Failed to export file to ${dest}.`); } - - return true; }; -export const populateObjectsInTemplate = async (data: Data): Promise => { - const keys: string[] = Object.keys(data); - +export const populateObjectsInTemplate = async (data: TemplateData): Promise => { // eslint-disable-next-line no-restricted-syntax - for (const prop of keys) { - const value = data[prop]; - const obj = await Doc.GetObject(prop); + for (const key of Object.keys(data)) { + const value = data[key]; + + const obj = await Doc.GetObject(key); if (!obj) { await closeTemplate(); throw new Error( - `There is no object in the specified template with the name of "${prop}".`, + `There is no object in the specified template with the name of "${key}".`, ); } - const type = await obj.Type; + const type:number = await obj.Type; switch (type) { case ObjectTypes.Text: @@ -131,7 +128,7 @@ export const populateObjectsInTemplate = async (data: Data): Promise => await obj.SetData(0, value, 0); break; default: - throw new Error(`Unknown type for "${prop}" prop.`); + throw new Error(`Unknown type for "${key}" property.`); } } diff --git a/src/types.ts b/src/types.ts index badc8e6..7893e82 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -export type Data = { +export type TemplateData = { [key:string] : string | Date }; From a1ffb7a46dd006c3b565733b61c22f8c9c09c24e Mon Sep 17 00:00:00 2001 From: Yeasir H Date: Fri, 9 Feb 2024 16:52:35 -0800 Subject: [PATCH 4/6] update docs - print options --- .github/images/auto-cut-chain-print.png | Bin 0 -> 2251 bytes .github/images/auto-cut-half-chain.png | Bin 0 -> 2215 bytes .github/images/auto-cut-half-cut.png | Bin 0 -> 2177 bytes .github/images/ncp-cut-mark.png | Bin 0 -> 1480 bytes .github/images/ncp-no-cut.png | Bin 0 -> 1820 bytes .github/images/special-tape.png | Bin 0 -> 1820 bytes .vscode/settings.json | 3 ++ docs/options.md | 60 +++++++++++++++++++----- docs/usage.md | 8 ++-- 9 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 .github/images/auto-cut-chain-print.png create mode 100644 .github/images/auto-cut-half-chain.png create mode 100644 .github/images/auto-cut-half-cut.png create mode 100644 .github/images/ncp-cut-mark.png create mode 100644 .github/images/ncp-no-cut.png create mode 100644 .github/images/special-tape.png diff --git a/.github/images/auto-cut-chain-print.png b/.github/images/auto-cut-chain-print.png new file mode 100644 index 0000000000000000000000000000000000000000..67b4dc86a4c1a07d685e5fb4ee6b0e8c3b99e3e5 GIT binary patch literal 2251 zcmV;+2sHPJP)8d00001b5ch_0Itp) z=>Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&2w+J>K~!i%<=MGz zlt~Z=aL*VU8=L#S4?C|jL z&!0b?)a&)0o*vAK6)WmZ@nuUuS^@k1{X0CXR;`+yowdclIW;v!U~Ft`+2aiL_xD@j zw5ssRl`Am-fBW{Wx3_oo>eb60XY0GuqOgsQj#|Hd{W>@}xOVN@iHQkWSoSz;wHkQg z`}+D66Dlj-`IaqPwC=}`AAg6wot&Hm%*YuS7#JTP->_kWdcyh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keID>A5F)4<9~Uuh#`sV%-<^T^SNylV#BeS0Xh=zI59VrYh2$-HS1OY@@nP;DhRos zeXiuAD6dR@uM7zD*~F6Vfq{X);i-h5(c)*7m?#Hw3OnI$mmCx(_l*k0>r!=UA8hT7 p&-5aI(KvIL&;JPh&j5FH{0WA@+^<4|hOGbq002ovPDHLkV1j6pH2(kq literal 0 HcmV?d00001 diff --git a/.github/images/auto-cut-half-cut.png b/.github/images/auto-cut-half-cut.png new file mode 100644 index 0000000000000000000000000000000000000000..67f3fbad517f3bcaeec673fb0ace94bb65957eeb GIT binary patch literal 2177 zcmV-{2!8j8P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&2o_01K~!i%?V4Fn zlvxml+d;)0G$JmM3xB0IgyjMgy>f{c{sV4E3?iZ+OVcclfSMpgBXI>6+&55h=K1<* ziyqQA(?c_JVZRqA_0?CWPM!Bu)pt6O`s3Hb_wU~smzI`%{PN|?h7B7U8yk@a1_t{2 z`o_k_IyyQgCMJf5hcoG+GDkU%8X6jqdwYBP`}?n4xiUF9+0)b0)zwwzD1jW+*VivD zE|NHK^m`WF-Q9QY+$nREK#qeWTaec3FN4`xtW%9?%cVf zM~@yqe*E<5(-$sWpyJ9LC6J?3Dz$a%Rz|^FijLltJ2Q{%4-n7&?U@l`pj$nh!5uIDU(4$$-Bb+kXm4Lw!P(ipcU?_%#p3%+V z=l1Q}3Ph;^z@BJO0+s+gI#C4aPo6wch~2UujC~9naUJDs0)Z<G;d`}Q%4%F0Rwm4;MRRh8AH>gwv) zFyHTli7Y7|f6*M()YLq9@Zjakmr#z2I1L;X#Qgj`Z}sBAqGXJWc=+%kBd$EdIBH`u zn>bY{qu?Juer$c=gabg(9y4shC&|lnG`v+wdOGp_`}aOF5|z_^Bog=<8X7_dL5czY zLynSfzs~^*fsq1E_$Y)ho1L9i_HfV;v=OTT>`mE?g&wdj9}Z<^y?XVE{kVFp0@$Zq z1jxH+WNJKD%FV}E3vaB#_nXI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git a/.github/images/special-tape.png b/.github/images/special-tape.png new file mode 100644 index 0000000000000000000000000000000000000000..437115bbb0142140f83d3ebdf31f21a828f223d3 GIT binary patch literal 1820 zcmV+%2jlpOP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&2C+#*K~z{r?U~t6 zTSpYe4PMyIUfNO#iT{t6Ds8DKRq7%hqCm^vP_++LmxPqC8G|ukY%pMwKqVvy%LDtq z7z1{H*Pk_Usz!o{R<_hn=;++>%-r*xZRQGFGN*8Mc6M@dB0VoJudS^unMe)|`X(lM|twA$E9pDCOqn26=IDVYAsUr`Slv=H_Nn(K|3iT~TR^ul|IXiY=Fj zK}O2e)fFY@cDp+}JBb*nNFGAz$!||lC^=%7OT^%VBpYFfUS3|_)YSC&QO9>3-+%t# zi-%u-^WzUcjg5{&@AdL(j@4KuNJYvl-)7IV<$wHPJ@V}2oVd~YDLISS(b18n$|a;S zokt_L$KKu^Qk5;JkEtrIudmq_g>I&Cz0164XJ-d_dV0zPjR*$^2S{yle0+>#p*lXq z{C+>pomf@4DE)~+uJDGQw9MU1ehR7SS-R| zV`D>#9L?H=g#{^0Hf;m2AzMK#91hb7AAI^5toWmmOot;-rIGNft+BC@GoiG!w6e0& zdbZi@c63SxkK7v=A(u3WUQkegbT}NEP*_-4Utcdh zbGO>sS|rn|s;W>5oQ3rteFCf6>JM(N5>J2crg?BuTk}>|S8+B$!{5e#c<4@G2|1>W zQaYI?Cg>6Oo1<3Kcx1WBWCb6rt*s$3$=o?IVeBMIe{}blh|SNv2#!zoJ@2=Cke-o( zl84Nexwi+alwH6SEeXjWw>z;iISH^BN=jWV2T)bw=|ZSq0W-Cye4+X5X3vA zFb3U#5mBwEsNj*D*PckoaCRwToN07L{;Vq%S*8%0@!Da*^t z96RXBRceVCVwOofz+~!zXy9CcQxq9yikl?BFT87MX~}v>BsrjA<;Zs?Z;~9%x;HY} zhO=cEp8i`>-5%_Ncgo7jls`P0;L9MSwuLrkp#Y62QJqdFOEeis!6fG3CM;xvsW<&f z7I1cPpEAS<7k!e1w7QcL7l@w8_;*3`nXHTz0oiJ-p^u>`AR3fZlhBKh=HrS~Bun9} zh3ugD0AlEnrw#7!?=ymhfaR7GZ<2Hid!9qhgA&@p-NX6 z(oX8?>d+N@)tKfW(FJtOwhX>6V!Ruf>K$)25A`>6jmr+jlgMZlbBr&52|J)$rq88R z;c21l0TeBg!qekhxW|ZTK9gmc2_R5*nRI0<6BBK#B|K^qI4~k#XcZ$!el@f+ePL`< z7FbK(MaB(k!y;`MrA)z#JY_)$m8mtVn(OYp^6jN5(Bv**?&Sdlf^ zNLHW|aWXBdAoIvQ%2n4Fh!GMlP@ae1x=YKIigPnj!eyl*Gcpr8n}O3a>)A?2lGE;j zlFLy*LdIiP1AT+k7;LRe3T}WKUO`vH7|Awder{qX6~uRUYisM}MVvs9gh;-ir^Au{ z-hogsoKD4D0oQ=EmWr6iLc^Kt^BXZjqeX#IaIbwI-kN!*Zpj9K4fnv@gxpV;`===fh`I;PyJj?^yz0000< KMNUMnLSTaGAX$?D literal 0 HcmV?d00001 diff --git a/.vscode/settings.json b/.vscode/settings.json index c9ae1ca..8535c35 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,5 +13,8 @@ "files.eol": "\n", "[github-actions-workflow]": { "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[markdown]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" } } \ No newline at end of file diff --git a/docs/options.md b/docs/options.md index 83dcf81..fef96ec 100644 --- a/docs/options.md +++ b/docs/options.md @@ -1,7 +1,7 @@ # Notice Properties are applicable exclusively to models that support each respective function. If a model does not support a particular function, the configuration becomes invalid, even if a prop is specified. -## Supported Ext Types (File Export) +## Supported Ext Types - For Exporting Files | **Description** | **Extension** | |---|:---:| | LBX type | .lbx | @@ -10,7 +10,7 @@ Properties are applicable exclusively to models that support each respective fun | BMP Image | .bmp | | PAF Type | .paf | -## Print Option Props +## Print Options | **Key** | **Type** | **Default** | **Description** | |---|---|:---:|---| | copies | number | 1 |Number of copies to print.| @@ -33,13 +33,51 @@ Properties are applicable exclusively to models that support each respective fun | fitPage | boolean | false |Specify whether to adjust the size and position of objects in the template in accordance with layout changes resulting from media changes. If set to true, adjustments will be made; otherwise, if set to false or undefined, no adjustments will be applied..| ## PT-9500PC / PT-9600 / PT-3600 -| **noCut** | **autoCut** | **halfCut** | **cutMark** | **chainPrint** | **cutAtEnd** | **specialTape** | **Result** | -|:---:|:---:|:---:|:---:|:---:|:---:|:---:|---:| -|✔️|-|-|-|-|-|-|![no cut](../.github/images/no-cut.png) | -|-|-|-|-|✔️|-|-|![chain print](../.github/images/chain-print.png) | -|-|-|✔️|-|-|-|-|![half cut](../.github/images/half-cut.png) | -|-|-|✔️|-|✔️|-|-|![half cut chain](../.github/images/half-cut-chain.png) | -|-|✔️|-|-|-|-|-|![auto cut](../.github/images/auto-cut.png) | -|-|✔️|✔️|-|-|-|-|![auto cut half cut](../.github/images/auto-half-cut.png) | -|-|✔️|✔️|-|✔️|-|-|![auto half chain](../.github/images/auto-half-chain.png) | +| **noCut** | **autoCut** | **halfCut**| **chainPrint** | **Result** | +|:---:|:---:|:---:|:---:|---:| +|✔️|-|-|-|![noCut](../.github/images/no-cut.png) | +|-|-|-|✔️|![chainPrint](../.github/images/chain-print.png) | +|-|-|✔️|-|![halfCut](../.github/images/half-cut.png) | +|-|-|✔️|✔️|![halfCut chainPrint](../.github/images/half-cut-chain.png) | +|-|✔️|-|-|![autoCut](../.github/images/auto-cut.png) | +|-|✔️|-|✔️|![autoCut chainPrint](../.github/images/auto-cut-chain-print.png) | +|-|✔️|✔️|-|![autoCut halfCut](../.github/images/auto-cut-half-cut.png) | +|-|✔️|✔️|✔️|![autoCut halfCut chainPrint](../.github/images/auto-cut-half-chain.png) | +## PT-9700PC / PT-9800PCN / PT-P750W / PT-P910BT / PT-E550W +| **noCut** | **autoCut** | **halfCut** | **chainPrint** | **specialTape** | **Result** | +|:---:|:---:|:---:|:---:|:---:|---:| +|✔️|-|-|-|-|![noCut](../.github/images/no-cut.png) | +|-|-|-|✔️|-|![chainPrint](../.github/images/chain-print.png) | +|-|-|✔️|-|-|![halfCut](../.github/images/half-cut.png) | +|-|-|✔️|✔️|-|![halfCut chainPrint](../.github/images/half-cut-chain.png) | +|-|✔️|-|-|-|![autoCut](../.github/images/auto-cut.png) | +|-|✔️|-|✔️|-|![autoCut chainPrint](../.github/images/auto-cut-chain-print.png) | +|-|✔️|✔️|-|-|![autoCut halfCut](../.github/images/auto-cut-half-cut.png) | +|-|✔️|✔️|✔️|-|![autoCut halfCut chainPrint](../.github/images/auto-cut-half-chain.png) | +|-|-|-|-|✔️|![specialTape](../.github/images/special-tape.png) | + +## PT-D450 +| **noCut** | **cutMark** | **chainPrint** | **Result** | +|:---:|:---:|:---:|---:| +|✔️|-|-|![noCut](../.github/images/ncp-no-cut.png) | +|-|-|✔️|![chainPrint](../.github/images/chain-print.png) | +|-|✔️|-|![cutMark](../.github/images/ncp-cut-mark.png) | +|-|✔️|✔️|![cutMark chainPrint](../.github/images/half-cut-chain.png) | + +## PT-E800T / PT-E800TK / PT-E850TKW +| **Media** | **noCut** | **autoCut** | **halfCut** | **chainPrint** | **specialTape** | **Result** | +|:----------|:---:|:---:|:---:|:---:|:---:|---:| +| TZe |✔️|-|-|-|-|![noCut](../.github/images/no-cut.png) | 1 +| TZe |-|-|-|✔️|-|![chainPrint](../.github/images/chain-print.png) | 2 +| TZe |-|-|✔️|-|-|![halfCut](../.github/images/half-cut.png) | 3 +| TZe |-|-|✔️|✔️|-|![halfCut chainPrint](../.github/images/half-cut-chain.png) | 4 +| TZe |-|-|-|-|-|![autoCut](../.github/images/auto-cut.png) | 5 +| TZe |-|-|-|-|-|![autoCut](../.github/images/auto-cut.png) | 6 +| TZe |-|-|-|-|-|![autoCut](../.github/images/auto-cut.png) | 7 +| TZe |-|-|-|-|-|![autoCut](../.github/images/auto-cut.png) | 8 +| TZe |-|-|-|-|-|![autoCut](../.github/images/auto-cut.png) | 9 +| PVC Tube |-|-|-|-|-|![autoCut chainPrint](../.github/images/auto-cut-chain-print.png) | 10 +| PVC Tube |-|-|-|-|-|![autoCut halfCut](../.github/images/auto-cut-half-cut.png) | 11 +| FLe |-|-|-|-|-|![autoCut halfCut chainPrint](../.github/images/auto-cut-half-chain.png) | 12 +| FLe |-|-|-|-|-|![specialTape](../.github/images/special-tape.png) | 13 diff --git a/docs/usage.md b/docs/usage.md index 308630c..f329f95 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -94,7 +94,7 @@ const data = { date: new Date("2024-1-20"), }; -// Docs >> Options >> Print Config Options - for all options +// Docs >> Options >> Print Options - for all options const options = { copies: 1, printName: "Air Force Label", @@ -158,7 +158,7 @@ previewBtn.addEventListener("click", previewImage); // script.js file import BrotherSdk from "https://cdn.jsdelivr.net/npm/bpac-js@latest/dist/index.mjs"; -const expBtn = document.getElementById("export-btn"); +const exp = document.getElementById("export-btn"); const tag = new BrotherSdk({ templatePath: "C:/Templates/shoe-template.lbx", @@ -175,7 +175,7 @@ const data = { const exportFile = async () => { try { - // Docs >> Options >> Supported Export Extensions - for support file types + // Docs >> Options >> Supported Ext Types - for support file types const success = await tag.export(data, "Air-Force.bmp", 300); console.log({success}) // Output: {success: true} } catch (error) { @@ -183,6 +183,6 @@ const exportFile = async () => { } }; -expBtn.addEventListener("click", exportFile); +exp.addEventListener("click", exportFile); ``` From ceeb5ebefc01a59e96b42b4f7983842a2bacb671 Mon Sep 17 00:00:00 2001 From: Yeasir H Date: Sun, 11 Feb 2024 11:17:06 -0800 Subject: [PATCH 5/6] finished print options in docs --- .github/images/auto-cut-no-margin.png | Bin 0 -> 2412 bytes .github/images/cp-cut-mark.png | Bin 0 -> 2082 bytes .github/images/no-cut-no-margin.png | Bin 0 -> 2046 bytes .github/images/no-margin-no-cut.png | Bin 0 -> 1576 bytes docs/options.md | 144 ++++++++++++++++++++------ 5 files changed, 113 insertions(+), 31 deletions(-) create mode 100644 .github/images/auto-cut-no-margin.png create mode 100644 .github/images/cp-cut-mark.png create mode 100644 .github/images/no-cut-no-margin.png create mode 100644 .github/images/no-margin-no-cut.png diff --git a/.github/images/auto-cut-no-margin.png b/.github/images/auto-cut-no-margin.png new file mode 100644 index 0000000000000000000000000000000000000000..23df12579a4bdbbc31918d5e0a001cef5d21682c GIT binary patch literal 2412 zcmV-y36u7TP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&2?0q&K~z{r-Pp-) z6;}`jVBd@Jz&wMQMXJSj|7nd0ii_VSwL(NV8d5*Z06C% zvv0n>ztggaL3UO#B~-4iu2WTiRh@JCQmNHy4Ks&6efl&uHa2hGJaV;KJ$drvcSpZ# zztqv%+B$dc+y@UH%%4Ah(V|6zgM-y9`2W-U_wVsJbs`K53}{Jze?PfWsmz)+i^1m2 zo12=NhK7bde*8FNfXO(*@bIvvL6R;F4~;BezFdoF-n@AegiDqznK8h?z(LXwhn(C8aZ9vvNJ)6&x7amD~c#t*8r4w$~aK3lH2rRl?m4+|GA1Z>r+RbG*MdU|FO zu(XQ+gMnPIV8MzND+ULKR<2wLp|QMu`?jXNe*GH4nRF_`V*U z;4fdkjI166uW_X5xH-nNSsCP<^@tmT(hQZBd3^i!Ev|}rM5Sk&Bmy!&crppaq0x%N zk|uWI{Q2`;U0o-BIPv`XbB}Z8wkEEAR;|o-bZFvk0H=y<5}xoW*s%j|Yir|P5MF^=dXaKbomyl=+g%$KkYS{2ntBoB}DHEHfcy!@#JSaY`8R zD8oUO6M=r+x^+@CMRjKdWzSG%z&Q7)f*uh|ZA6Ml83Xvsb0UBlcpJ@hsQ{*6DY>!K zD=>7X{~nhs5o1r6faqhwOziL)?88Xv`MBqRyt5tWd5WL&!P z$Y#(zsgr3kw|0WZHEY&*s|1-JIWZ{rRVc%0l~+8ou@J$43ksXokr@jLWO`UO&GPc} zPw6M6s>S)x64J!y_CSGQWj2Pl%EmII@2xE%Dz1}K`7DO*>Ma14cm+8RIv-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l|4Gl?7sF{w9jj3ex6*+++7XpF6d%L6kj)W*(F}mS0g1C$naJ@vPr>7A%H8oL^ zFvG*c2#GGi1_c^q<2N^fAlH=#3ISixJ>W?u?z#BsMxFpC3%E|Xdp#Zx+L+D=BL0jV z6#@v7k&Bb_x3;#D0!mm?15m=@Fh%iwORMEVj6+A`PA+J@6$LBdNigus2*PLGjv}7P zK+w?8zz98h^ho7NE>I5ORsYr3B}Jt|!Rz*ggOQ%D-gL9IBFtRkvDDVq#;wdtnJL#3 zBS54+9;n92h{A#*Ao#4hW_xpoEFc{`gI?!N3R(aGuJFnQB$+}uOv3BE$T=x~9oy}8 zU%h&@qoV^}?~%sFMyHAHA8f8~t*)%W_`L!80_l*3Dho)L5v_qU1C4GmU_z*0F)b}E z@I;>YkB?2ib5ITm`wH6j3E4{Ba#mI%uDG=Y1=Ie3O8=tfB}Md zEaCI``+EnvJ9`qtBcVX}-&{~fOiwZgg|xdV(v6@O2U(!kB#FQSmtS;L1VSDN06`&4 zJeZ^w$c2vf&g`j(BjmJzf8K8t2)V!`0-lo}|NDf3^Y;mbNH`ez8)IwgNFeFvDF6Tf M07*qoM6N<$f>E-;pa1{> literal 0 HcmV?d00001 diff --git a/.github/images/no-cut-no-margin.png b/.github/images/no-cut-no-margin.png new file mode 100644 index 0000000000000000000000000000000000000000..9e2ed4e75fa6a97e4c521c408e0a543943ddc4a1 GIT binary patch literal 2046 zcmVPx#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&2a`!eK~z{r)!0dE zm01u5;M^}JPH~>2f;fSK;3B4REw~r|L6%v&5!?uZhVs?dQAi^_qoVxeaS6MNJb)Yild$)_3pTwY9ZbA3l62Dz78dG?9G%{Q2?Y$6{EtXc1n6RVtM= zYu40`o2$Dde&ND}pFVwh`SRtKEnAi@U3%@>HSyHQaZUG^C)Mcb=~=sW?cKX~H*MOa zyYyRk*Kav(nn=`S)~s3W?d|53aqOKCYO|ri;V6{dm09-m>C^BgH|EQiF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xG^HF}BS60I!8f-DP~OvN}6J*Et13nNmRn;bYfCB4s|KVLaDN#p~Y zF=|BuEs2ef7_VjfK!JWeaGFnabpsP2wsrE zVmdC!vJ#9ygz)er{9($PthW;GjF18mLm3ezVsYEHZA_^&_wV2L?5Zi%_#nP7H%L5^ z?}-SAo;LN`hgy5TefyR|wr}5VL6U`_9P!1iIF=2@RViP2OJtcTwa0S@J+*`?^0Th~ zVPjV@FQGns_<*xryLK5-XY2EoSQA)@gW?68Ic~9_jVr@z#)(&O>ONk*B@`Q(rCUp( zOYml?L7w6}3ZC#8izqb0uBlu-jv?3LHHe))Q577O^?$@sQ<;3Oo9k%z?%mdV9ZRSx z!&68I4x;451j)9K9z(JbUc=YIzc=FCVdi3bNefx6d;l={x z$FHhJgqJ)-EFI_gUld7%NokIz*d8*~1*TG0-C0-=%T>qrS-J#bdoL<&WarMEfTHc` z)2CH+MuU(9$T{fY#>ip`gQ*}yqA9TXbr(shLgT@uZFs7w0uTb?GJN=Tr^`FuG=fzs zVMVvPr!3;8I4carMBV9&Aoxg`i9mDg*fE<*6asH6tA&pnoy9}LRH`ET zC~<4<-Md#8D Date: Sat, 17 Feb 2024 01:05:39 -0800 Subject: [PATCH 6/6] refactor docs --- docs/usage.md | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index f329f95..02afb84 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -16,7 +16,7 @@ import { BrotherBrotherSdk } from "bpac-js"; ``` ### CDN -Include import at the top of your script file. And set type to module in .html (requires live-server or equivalent). +Include import at the top of your script file, and set script type to module in .html (load using live-server or equivalent). ```javascript import BrotherSdk from "https://cdn.jsdelivr.net/npm/bpac-js@{version#}/dist/index.js"; @@ -31,17 +31,16 @@ import BrotherSdk from "https://cdn.jsdelivr.net/npm/bpac-js@{version#}/dist/ind ### Get Printer Name ```javascript // script.js file -import BrotherSdk from "https://cdn.jsdelivr.net/npm/bpac-js@latest/dist/index.js"; - const getNameBtn = document.getElementById("get-name-btn"); const tag = new BrotherSdk({ templatePath: "C:/Templates/shoe-template.lbx", exportPath: "C:/Users/YourProfile/Desktop/Exported_Labels/", + printer: "Brother QL-820NWB" }); // Returns the printer associated with the template in string format -const getName = async () => { +const getPrinter = async () => { try { const printer = await tag.getPrinterName(); console.log({printer}) // Output: {printer: "Brother QL-820NWB"} @@ -50,18 +49,16 @@ const getName = async () => { } }; -getNameBtn.addEventListener("click", getName); +getNameBtn.addEventListener("click", getPrinter); ``` ### Get List Of Printers ```javascript // script.js file -import BrotherSdk from "https://cdn.jsdelivr.net/npm/bpac-js@latest/dist/index.js"; - const getNameBtn = document.getElementById("get-name-btn"); -const getNames = async () => { +const getPrinters = async () => { try { const printers = await BrotherSdk.getPrinterList(); console.log({printers}) // Output: {printers: ["Brother QL-820NWB", "Brother PT-9800PCN"]} @@ -70,20 +67,19 @@ const getNames = async () => { } }; -getNameBtn.addEventListener("click", getNames); +getNameBtn.addEventListener("click", getPrinters); ``` ### Print ```javascript // script.js file -import BrotherSdk from "https://cdn.jsdelivr.net/npm/bpac-js@latest/dist/index.js"; - const printBtn = document.getElementById("print-btn"); const tag = new BrotherSdk({ templatePath: "C:/Templates/shoe-template.lbx", exportPath: "C:/Users/YourProfile/Desktop/Exported_Labels/", + printer: "Brother QL-820NWB" }); // The keys and values must match the objects/types in the template file. @@ -101,7 +97,7 @@ const options = { highResolution: true } -const sendToPrinter = async () => { +const handlePrint = async () => { try { const isPrinted = await tag.print(data, options); console.log({isPrinted}) @@ -110,21 +106,20 @@ const sendToPrinter = async () => { } }; -printBtn.addEventListener("click", sendToPrinter); +printBtn.addEventListener("click", handlePrint); ``` ### Preview ```javascript // script.js file -import BrotherSdk from "https://cdn.jsdelivr.net/npm/bpac-js@latest/dist/index.mjs"; - const previewBtn = document.getElementById("preview-btn"); const imgOutput = document.getElementById("img") const tag = new BrotherSdk({ templatePath: "C:/Templates/shoe-template.lbx", exportPath: "C:/Users/YourProfile/Desktop/Exported_Labels/", + printer: "Brother QL-820NWB" }); // The keys and values must match the objects/types in the template file. @@ -140,7 +135,7 @@ const options = { height: 0 // Optional - Defaults to 0 } -const previewImage = async () => { +const handlePreview = async () => { try { const data = await tag.getImageData(data, options); //image data imgOutput.src = data; @@ -149,20 +144,19 @@ const previewImage = async () => { } }; -previewBtn.addEventListener("click", previewImage); +previewBtn.addEventListener("click", handlePreview); ``` ### Export ```javascript // script.js file -import BrotherSdk from "https://cdn.jsdelivr.net/npm/bpac-js@latest/dist/index.mjs"; - const exp = document.getElementById("export-btn"); const tag = new BrotherSdk({ templatePath: "C:/Templates/shoe-template.lbx", exportPath: "C:/Users/YourProfile/Desktop/Exported_Labels/", + printer: "Brother QL-820NWB" }); // The keys and values must match the objects/types in the template file. @@ -173,7 +167,7 @@ const data = { date: new Date("2024-1-20"), }; -const exportFile = async () => { +const handleExport = async () => { try { // Docs >> Options >> Supported Ext Types - for support file types const success = await tag.export(data, "Air-Force.bmp", 300); @@ -183,6 +177,6 @@ const exportFile = async () => { } }; -exp.addEventListener("click", exportFile); +exp.addEventListener("click", handleExport); ```