feat: init
This commit is contained in:
commit
66bca689d6
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
dist/
|
||||
node_modules
|
17
build.config.ts
Normal file
17
build.config.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { defineBuildConfig } from 'unbuild'
|
||||
import { join } from "node:path"
|
||||
export default defineBuildConfig({
|
||||
entries: ['src/index'],
|
||||
clean: true,
|
||||
declaration: true,
|
||||
rollup: {
|
||||
emitCJS: true,
|
||||
inlineDependencies: true,
|
||||
esbuild: {
|
||||
minify: true,
|
||||
},
|
||||
},
|
||||
alias: {
|
||||
"@": join(__dirname, 'src')
|
||||
},
|
||||
})
|
34
package.json
Normal file
34
package.json
Normal file
@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "@taoya7/print-help",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"keywords": [
|
||||
"佳博打印机"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"sideEffects": false,
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"push": ""
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"@types/node": "^20.11.25",
|
||||
"typescript": "^5.4.2",
|
||||
"unbuild": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash-es": "^4.17.21"
|
||||
}
|
||||
}
|
1859
pnpm-lock.yaml
Normal file
1859
pnpm-lock.yaml
Normal file
File diff suppressed because it is too large
Load Diff
401
src/command/Label.ts
Normal file
401
src/command/Label.ts
Normal file
@ -0,0 +1,401 @@
|
||||
|
||||
import _ from 'lodash-es';
|
||||
|
||||
export enum FOOT {
|
||||
F2 = 0,
|
||||
F5 = 1
|
||||
}
|
||||
export enum SPEED {
|
||||
SPEED1DIV5 = 15,
|
||||
SPEED2 = 20,
|
||||
SPEED3 = 30,
|
||||
SPEED4 = 40,
|
||||
SPEED5 = 50,
|
||||
SPEED6 = 60,
|
||||
SPEED7 = 70,
|
||||
SPEED8 = 80,
|
||||
SPEED9 = 90,
|
||||
SPEED10 = 100,
|
||||
SPEED11 = 110,
|
||||
SPEED12 = 120
|
||||
}
|
||||
|
||||
export enum DENSITY {
|
||||
DNESITY0 = 0,
|
||||
DNESITY1 = 1,
|
||||
DNESITY2 = 2,
|
||||
DNESITY3 = 3,
|
||||
DNESITY4 = 4,
|
||||
DNESITY5 = 5,
|
||||
DNESITY6 = 6,
|
||||
DNESITY7 = 7,
|
||||
DNESITY8 = 8,
|
||||
DNESITY9 = 9,
|
||||
DNESITY10 = 10,
|
||||
DNESITY11 = 11,
|
||||
DNESITY12 = 12,
|
||||
DNESITY13 = 13,
|
||||
DNESITY14 = 14,
|
||||
DNESITY15 = 15
|
||||
}
|
||||
|
||||
export enum DIRECTION {
|
||||
FORWARD = 0,
|
||||
BACKWARD = 1
|
||||
}
|
||||
|
||||
export enum MIRROR {
|
||||
NORMAL = 0,
|
||||
MIRROR = 1
|
||||
}
|
||||
export enum CODEPAGE {
|
||||
PC437 = 437,
|
||||
PC850 = 850,
|
||||
PC852 = 852,
|
||||
PC860 = 860,
|
||||
PC863 = 863,
|
||||
PC865 = 865,
|
||||
WPC1250 = 1250,
|
||||
WPC1252 = 1252,
|
||||
WPC1253 = 1253,
|
||||
WPC1254 = 1254
|
||||
}
|
||||
export enum FONTTYPE {
|
||||
FONT_0 = "0.TTF",
|
||||
Bold = "1.TTF",
|
||||
SongTi = "2.TTF",
|
||||
Thai = "4.TTF",
|
||||
FONT_1 = "1",
|
||||
FONT_2 = "2",
|
||||
FONT_3 = "3",
|
||||
FONT_4 = "4",
|
||||
FONT_5 = "5",
|
||||
FONT_6 = "6",
|
||||
FONT_7 = "7",
|
||||
FONT_8 = "8",
|
||||
FONT_9 = "9",
|
||||
FONT_10 = "10",
|
||||
SIMPLIFIED_16_CHINESE = "TSS16.BF2",
|
||||
SIMPLIFIED_20_CHINESE = "TSS20.BF2",
|
||||
SIMPLIFIED_24_CHINESE = "TSS24.BF2",
|
||||
SIMPLIFIED__32_CHINESE = "TSS32.BF2",
|
||||
TRADITIONAL_CHINESE = "TST24.BF2",
|
||||
KOREAN = "K"
|
||||
}
|
||||
export enum ROTATION {
|
||||
ROTATION_0 = 0,
|
||||
ROTATION_90 = 90,
|
||||
ROTATION_180 = 180,
|
||||
ROTATION_270 = 270
|
||||
}
|
||||
export enum FONTMUL {
|
||||
MUL_1 = 1,
|
||||
MUL_2 = 2,
|
||||
MUL_3 = 3,
|
||||
MUL_4 = 4,
|
||||
MUL_5 = 5,
|
||||
MUL_6 = 6,
|
||||
MUL_7 = 7,
|
||||
MUL_8 = 8,
|
||||
MUL_9 = 9,
|
||||
MUL_10 = 10
|
||||
}
|
||||
export enum BITMAP_MODE {
|
||||
OVERWRITE = 0,
|
||||
OR = 1,
|
||||
XOR = 2
|
||||
}
|
||||
export enum READABEL {
|
||||
DISABLE = 0,
|
||||
EANBEL = 1,
|
||||
}
|
||||
export enum Shape {
|
||||
Square = "0",
|
||||
Rectangle = "1",
|
||||
}
|
||||
export enum EEC {
|
||||
LEVEL_L = "L",
|
||||
LEVEL_M = "M",
|
||||
LEVEL_Q = "Q",
|
||||
LEVEL_H = "H"
|
||||
}
|
||||
export enum BARCODETYPE {
|
||||
CODE128 = "128",
|
||||
CODE128M = "128M",
|
||||
EAN128 = "EAN128",
|
||||
ITF25 = "25",
|
||||
ITF25C = "25C",
|
||||
CODE39 = "39",
|
||||
CODE39C = "39C",
|
||||
CODE39S = "39S",
|
||||
CODE93 = "93",
|
||||
EAN13 = "EAN13",
|
||||
EAN13_2 = "EAN13+2",
|
||||
EAN13_5 = "EAN13+5",
|
||||
EAN8 = "EAN8",
|
||||
EAN8_2 = "EAN8+2",
|
||||
EAN8_5 = "EAN8+5",
|
||||
CODABAR = "CODA",
|
||||
POST = "POST",
|
||||
UPCA = "UPCA",
|
||||
UPCA_2 = "UPCA+2",
|
||||
UPCA_5 = "UPCA+5",
|
||||
UPCE = "UPCE13",
|
||||
UPCE_2 = "UPCE13+2",
|
||||
UPCE_5 = "UPCE13+5",
|
||||
CPOST = "CPOST",
|
||||
MSI = "MSI",
|
||||
MSIC = "MSIC",
|
||||
PLESSEY = "PLESSEY",
|
||||
ITF14 = "ITF14",
|
||||
EAN14 = "EAN14"
|
||||
}
|
||||
export enum RESPONSE_MODE {
|
||||
ON = "ON",
|
||||
OFF = "OFF",
|
||||
BATCH = "BATCH"
|
||||
}
|
||||
export enum ENABLE {
|
||||
ON = "ON",
|
||||
OFF = "OFF"
|
||||
}
|
||||
|
||||
export class LabelCommand {
|
||||
command: number[] = [];
|
||||
constructor(width: number, height: number, gap: number) {
|
||||
this.command = new Array();
|
||||
this.addSize(width, height);
|
||||
this.addGap(gap);
|
||||
}
|
||||
public clrCommand() {
|
||||
this.command = [];
|
||||
}
|
||||
private addStrToCommand(str: string): void {
|
||||
if (str !== "") {
|
||||
let bs: Buffer = Buffer.from(str, 'utf8');
|
||||
for (let i = 0; i < bs.length; ++i) {
|
||||
this.command.push(bs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 定义两张标签之间的间隙距离
|
||||
*/
|
||||
addGap(gap: number) {
|
||||
let str = "GAP " + gap + " mm," + 0 + " mm\r\n";
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
/**
|
||||
* 设定黑标高度及使用者定义标签印完后标签额外送出的长度
|
||||
*/
|
||||
addBline(bline: number) {
|
||||
let str = "BLINE " + bline + " mm," + 0 + " mm\r\n";
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
/**
|
||||
* 定义标签纸的宽度及高度
|
||||
*/
|
||||
addSize(width: number, height: number): void {
|
||||
const str = "SIZE " + width + " mm," + height + " mm\r\n";
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addCashdrwer(m: FOOT, t1: number, t2: number): void {
|
||||
let str: string = `CASHDRAWER ${m},${t1},${t2}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addOffset(offset: number): void {
|
||||
let str: string = `OFFSET ${offset} mm\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addSpeed(speed: SPEED): void {
|
||||
let str: string = `SPEED ${speed / 10}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addDensity(density: DENSITY): void {
|
||||
let str: string = `DENSITY ${density}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addDirection(direction: DIRECTION, mirror: MIRROR): void {
|
||||
let str: string = `DIRECTION ${direction}, ${mirror}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addReference(x: number, y: number): void {
|
||||
let str: string = `REFERENCE ${x}, ${y}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addShift(shift: number): void {
|
||||
let str: string = `SHIFT ${shift}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addCls(): void {
|
||||
let str: string = `CLS\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addFeed(dot: number): void {
|
||||
let str: string = `FEED ${dot}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addBackFeed(dot: number): void {
|
||||
let str: string = `BACKFEED ${dot}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addFormFeed(): void {
|
||||
let str: string = `FORMFEED\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addHome(): void {
|
||||
let str: string = `HOME\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addPrint(m: number, n?: number): void {
|
||||
let str: string = n ? `PRINT ${m}, ${n}\r\n` : `PRINT ${m}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addCodePage(page: CODEPAGE): void {
|
||||
let str: string = `CODEPAGE ${page}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addSound(level: number, interval: number): void {
|
||||
let str: string = `SOUND ${level}, ${interval}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addLimitFeed(n: number): void {
|
||||
let str: string = `LIMITFEED ${n}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addSelfTest(): void {
|
||||
let str: string = `SELFTEST\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addBar(x: number, y: number, width: number, height: number): void {
|
||||
let str: string = `BAR ${x}, ${y}, ${width}, ${height}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addText(x: number, y: number, font: FONTTYPE, rotation: ROTATION, Xscal: FONTMUL, Yscal: FONTMUL, text: string): void {
|
||||
let str: string = `TEXT ${x}, ${y}, "${font}", ${rotation}, ${Xscal}, ${Yscal}, "${text}"\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addUserCommand(command: string): void {
|
||||
this.addStrToCommand(command);
|
||||
}
|
||||
addCOUNTER(number: number, step: number): void {
|
||||
let str: string = `SET COUNTER @${number} ${step}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addQueryPrinterStatus(mode: RESPONSE_MODE): void {
|
||||
let str: string = `SET RESPONSE ${mode}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addPartialCutter(enable: ENABLE): void {
|
||||
let str: string = `SET PARTIAL_CUTTER ${enable}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addPrintKey(m: number | ENABLE) {
|
||||
if (typeof m == 'number') {
|
||||
let str: string = "SET PRINTKEY " + m + "\r\n";
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
else {
|
||||
let str: string = "SET PRINTKEY " + m + "\r\n";
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
}
|
||||
addCutterBatch() {
|
||||
const str = "SET CUTTER BATCH\r\n";
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addCutterPieces(number: number) {
|
||||
const str = "SET CUTTER " + number + "\r\n";
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addQueryPrinterCodePage() {
|
||||
const str = "~!I\r\n";
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addQueryPrinterFile() {
|
||||
const str = "~!F\r\n";
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addQueryPrinterMemory() {
|
||||
const str = "~!A\r\n";
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addQueryPrinterLife() {
|
||||
const str = "~!@\r\n";
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addResetPrinter(): void {
|
||||
this.command.push(27, 33, 82);
|
||||
}
|
||||
addReprint(enable: RESPONSE_MODE): void {
|
||||
let str: string = `SET REPRINT ${enable}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addHead(enable: ENABLE): void {
|
||||
let str: string = `SET HEAD ${enable}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
|
||||
addRibbon(enable: ENABLE): void {
|
||||
let str: string = `SET RIBBON ${enable}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
|
||||
addKeyOne(enable: ENABLE): void {
|
||||
let str: string = `SET KEY1 ${enable}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
|
||||
addKeyTwo(enable: ENABLE): void {
|
||||
let str: string = `SET KEY2 ${enable}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addPeel(enable: RESPONSE_MODE): void {
|
||||
let str: string = `SET PEEL ${enable}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
|
||||
addTear(mode: RESPONSE_MODE): void {
|
||||
let str: string = `SET TEAR ${mode}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
|
||||
addCutter(enable: RESPONSE_MODE): void {
|
||||
let str: string = `SET CUTTER ${enable}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
getCommand() {
|
||||
return this.command.join(',');
|
||||
}
|
||||
addQueryPrinterType(): void {
|
||||
let str: string = `~!T\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
public addQRCode(x: number, y: number, level: EEC, cellwidth: number, rotation: ROTATION, data: string): void {
|
||||
let str: string = `QRCODE ${x}, ${y}, ${level}, ${cellwidth}, A, ${rotation}, "${data}"\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addReverse(x: number, y: number, xwidth: number, yheight: number): void {
|
||||
let str = `REVERSE ${x}, ${y}, ${xwidth}, ${yheight}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addErase(x: number, y: number, xwidth: number, yheight: number): void {
|
||||
let str = `ERASE ${x},${y},${xwidth},${yheight}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
addDMATRIX(x: number, y: number, width: number, height: number, content: string): void {
|
||||
let str = `DMATRIX ${x},${y},${width},${height},"${content}"\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
add1DBarcode(x: number, y: number, type: BARCODETYPE, height: number, readable: READABEL, rotation: ROTATION, narrow: number, width: number, content: string): void {
|
||||
let str = `BARCODE ${x},${y},"${type}",${height},${readable},${rotation},${narrow},${width},"${content}"\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
|
||||
addBox(x: number, y: number, xend: number, yend: number, thickness: number): void {
|
||||
let str = `BOX ${x},${y},${xend},${yend},${thickness}\r\n`;
|
||||
this.addStrToCommand(str);
|
||||
}
|
||||
|
||||
}
|
||||
|
1
src/command/index.ts
Normal file
1
src/command/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './Label'
|
9
src/index.ts
Normal file
9
src/index.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export * from './command'
|
||||
|
||||
import { LabelCommand } from '@/command/Label'
|
||||
|
||||
function main() {
|
||||
let label = new LabelCommand(50, 30, 0);
|
||||
console.log(label.getCommand());
|
||||
}
|
||||
main();
|
32
tsconfig.json
Normal file
32
tsconfig.json
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"jsx": "preserve",
|
||||
"lib": [
|
||||
"DOM",
|
||||
"ESNext"
|
||||
],
|
||||
"baseUrl": ".",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "node",
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"./src/*"
|
||||
]
|
||||
},
|
||||
"resolveJsonModule": true,
|
||||
"types": [
|
||||
"node"
|
||||
],
|
||||
"strict": true,
|
||||
"strictNullChecks": true,
|
||||
"noUnusedLocals": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user