@posx/core 5.5.326 → 5.5.329
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/build/index.d.ts +2 -0
- package/build/index.js +189 -12
- package/package.json +1 -1
- package/package.publish.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -4039,6 +4039,7 @@ declare class PrintTemplateCore implements IPrintTemplateCore {
|
|
|
4039
4039
|
}
|
|
4040
4040
|
type IPrintTemplate = IPrintTemplateCore & IAppBaseModel & {
|
|
4041
4041
|
printer_type: PrinterType;
|
|
4042
|
+
codepage?: Codepages;
|
|
4042
4043
|
report_code_name: string;
|
|
4043
4044
|
};
|
|
4044
4045
|
declare class PrintTemplate extends AppBaseModel implements IPrintTemplate {
|
|
@@ -4047,6 +4048,7 @@ declare class PrintTemplate extends AppBaseModel implements IPrintTemplate {
|
|
|
4047
4048
|
footer: string;
|
|
4048
4049
|
commands: string;
|
|
4049
4050
|
printer_type: PrinterType;
|
|
4051
|
+
codepage?: Codepages;
|
|
4050
4052
|
uid: string;
|
|
4051
4053
|
report_code_name: string;
|
|
4052
4054
|
constructor();
|
package/build/index.js
CHANGED
|
@@ -733,6 +733,159 @@ _defineProperty(ElectronSocket, "State", {
|
|
|
733
733
|
});
|
|
734
734
|
_defineProperty(ElectronSocket, "electronSocket", null);
|
|
735
735
|
|
|
736
|
+
//#endregion
|
|
737
|
+
//#region src/libs/viscii.encoding.ts
|
|
738
|
+
const VISCII_CODEPAGE = "69";
|
|
739
|
+
function isVISCIICodepage(codepage) {
|
|
740
|
+
return codepage === VISCII_CODEPAGE;
|
|
741
|
+
}
|
|
742
|
+
const VISCII_TABLE = {
|
|
743
|
+
"Ẳ": 2,
|
|
744
|
+
"Ẵ": 5,
|
|
745
|
+
"Ẫ": 6,
|
|
746
|
+
"Ỷ": 20,
|
|
747
|
+
"Ỹ": 25,
|
|
748
|
+
"Ỵ": 30,
|
|
749
|
+
"Ạ": 128,
|
|
750
|
+
"Ắ": 129,
|
|
751
|
+
"Ằ": 130,
|
|
752
|
+
"Ặ": 131,
|
|
753
|
+
"Ấ": 132,
|
|
754
|
+
"Ầ": 133,
|
|
755
|
+
"Ẩ": 134,
|
|
756
|
+
"Ậ": 135,
|
|
757
|
+
"Ẽ": 136,
|
|
758
|
+
"Ẹ": 137,
|
|
759
|
+
"Ế": 138,
|
|
760
|
+
"Ề": 139,
|
|
761
|
+
"Ể": 140,
|
|
762
|
+
"Ễ": 141,
|
|
763
|
+
"Ệ": 142,
|
|
764
|
+
"Ố": 143,
|
|
765
|
+
"Ồ": 144,
|
|
766
|
+
"Ổ": 145,
|
|
767
|
+
"Ỗ": 146,
|
|
768
|
+
"Ộ": 147,
|
|
769
|
+
"Ợ": 148,
|
|
770
|
+
"Ớ": 149,
|
|
771
|
+
"Ờ": 150,
|
|
772
|
+
"Ở": 151,
|
|
773
|
+
"Ị": 152,
|
|
774
|
+
"Ỏ": 153,
|
|
775
|
+
"Ọ": 154,
|
|
776
|
+
"Ỉ": 155,
|
|
777
|
+
"Ủ": 156,
|
|
778
|
+
"Ũ": 157,
|
|
779
|
+
"Ụ": 158,
|
|
780
|
+
"Ỳ": 159,
|
|
781
|
+
"Õ": 160,
|
|
782
|
+
"ắ": 161,
|
|
783
|
+
"ằ": 162,
|
|
784
|
+
"ặ": 163,
|
|
785
|
+
"ấ": 164,
|
|
786
|
+
"ầ": 165,
|
|
787
|
+
"ẩ": 166,
|
|
788
|
+
"ậ": 167,
|
|
789
|
+
"ẽ": 168,
|
|
790
|
+
"ẹ": 169,
|
|
791
|
+
"ế": 170,
|
|
792
|
+
"ề": 171,
|
|
793
|
+
"ể": 172,
|
|
794
|
+
"ễ": 173,
|
|
795
|
+
"ệ": 174,
|
|
796
|
+
"ố": 175,
|
|
797
|
+
"ồ": 176,
|
|
798
|
+
"ổ": 177,
|
|
799
|
+
"ỗ": 178,
|
|
800
|
+
"Ỡ": 179,
|
|
801
|
+
"Ơ": 180,
|
|
802
|
+
"ộ": 181,
|
|
803
|
+
"ờ": 182,
|
|
804
|
+
"ở": 183,
|
|
805
|
+
"ị": 184,
|
|
806
|
+
"Ự": 185,
|
|
807
|
+
"Ứ": 186,
|
|
808
|
+
"Ừ": 187,
|
|
809
|
+
"Ử": 188,
|
|
810
|
+
"ơ": 189,
|
|
811
|
+
"ớ": 190,
|
|
812
|
+
"Ư": 191,
|
|
813
|
+
"À": 192,
|
|
814
|
+
"Á": 193,
|
|
815
|
+
"Â": 194,
|
|
816
|
+
"Ã": 195,
|
|
817
|
+
"Ả": 196,
|
|
818
|
+
"Ă": 197,
|
|
819
|
+
"ẳ": 198,
|
|
820
|
+
"ẵ": 199,
|
|
821
|
+
"È": 200,
|
|
822
|
+
"É": 201,
|
|
823
|
+
"Ê": 202,
|
|
824
|
+
"Ẻ": 203,
|
|
825
|
+
"Ì": 204,
|
|
826
|
+
"Í": 205,
|
|
827
|
+
"Ĩ": 206,
|
|
828
|
+
"ỳ": 207,
|
|
829
|
+
"Đ": 208,
|
|
830
|
+
"ứ": 209,
|
|
831
|
+
"Ò": 210,
|
|
832
|
+
"Ó": 211,
|
|
833
|
+
"Ô": 212,
|
|
834
|
+
"ạ": 213,
|
|
835
|
+
"ỷ": 214,
|
|
836
|
+
"ừ": 215,
|
|
837
|
+
"ử": 216,
|
|
838
|
+
"Ù": 217,
|
|
839
|
+
"Ú": 218,
|
|
840
|
+
"ỹ": 219,
|
|
841
|
+
"ỵ": 220,
|
|
842
|
+
"Ý": 221,
|
|
843
|
+
"ỡ": 222,
|
|
844
|
+
"ư": 223,
|
|
845
|
+
"à": 224,
|
|
846
|
+
"á": 225,
|
|
847
|
+
"â": 226,
|
|
848
|
+
"ã": 227,
|
|
849
|
+
"ả": 228,
|
|
850
|
+
"ă": 229,
|
|
851
|
+
"ữ": 230,
|
|
852
|
+
"ẫ": 231,
|
|
853
|
+
"è": 232,
|
|
854
|
+
"é": 233,
|
|
855
|
+
"ê": 234,
|
|
856
|
+
"ẻ": 235,
|
|
857
|
+
"ì": 236,
|
|
858
|
+
"í": 237,
|
|
859
|
+
"ĩ": 238,
|
|
860
|
+
"ỉ": 239,
|
|
861
|
+
"đ": 240,
|
|
862
|
+
"ự": 241,
|
|
863
|
+
"ò": 242,
|
|
864
|
+
"ó": 243,
|
|
865
|
+
"ô": 244,
|
|
866
|
+
"õ": 245,
|
|
867
|
+
"ỏ": 246,
|
|
868
|
+
"ọ": 247,
|
|
869
|
+
"ụ": 248,
|
|
870
|
+
"ù": 249,
|
|
871
|
+
"ú": 250,
|
|
872
|
+
"ũ": 251,
|
|
873
|
+
"ủ": 252,
|
|
874
|
+
"ý": 253,
|
|
875
|
+
"ợ": 254,
|
|
876
|
+
"Ữ": 255
|
|
877
|
+
};
|
|
878
|
+
function utf8ToVISCII(text, fallback = 63) {
|
|
879
|
+
const bytes = [];
|
|
880
|
+
for (const ch of text) if (VISCII_TABLE[ch] !== void 0) bytes.push(VISCII_TABLE[ch]);
|
|
881
|
+
else {
|
|
882
|
+
const code = ch.charCodeAt(0);
|
|
883
|
+
if (code <= 127) bytes.push(code);
|
|
884
|
+
else bytes.push(fallback);
|
|
885
|
+
}
|
|
886
|
+
return Uint8Array.from(bytes);
|
|
887
|
+
}
|
|
888
|
+
|
|
736
889
|
//#endregion
|
|
737
890
|
//#region src/libs/escpos.printer.ts
|
|
738
891
|
function getSocket() {
|
|
@@ -811,8 +964,19 @@ var EscPosPrinter = class {
|
|
|
811
964
|
}
|
|
812
965
|
async interpret(template) {
|
|
813
966
|
const encoder = new EscPosEncoder();
|
|
814
|
-
if (template.codepage) encoder.codepage(template.codepage);
|
|
815
967
|
const printing = encoder.initialize();
|
|
968
|
+
if (template.codepage && !Object.values(Codepages).includes(template.codepage)) {
|
|
969
|
+
const codepageNum = parseInt(template.codepage, 10);
|
|
970
|
+
printing.raw([
|
|
971
|
+
31,
|
|
972
|
+
27,
|
|
973
|
+
31,
|
|
974
|
+
255,
|
|
975
|
+
codepageNum,
|
|
976
|
+
10,
|
|
977
|
+
0
|
|
978
|
+
]);
|
|
979
|
+
} else if (template.codepage && Object.values(Codepages).includes(template.codepage)) encoder.codepage(template.codepage);
|
|
816
980
|
for (const printItem of template.items) {
|
|
817
981
|
if (!printItem) throw new Error("Item is undefined or null");
|
|
818
982
|
switch (printItem.style) {
|
|
@@ -844,7 +1008,10 @@ var EscPosPrinter = class {
|
|
|
844
1008
|
sizeValue
|
|
845
1009
|
]);
|
|
846
1010
|
} else if (printItem.item.size) printing.size(printItem.item.size);
|
|
847
|
-
|
|
1011
|
+
if (isVISCIICodepage(template.codepage)) {
|
|
1012
|
+
const visciiBytes = utf8ToVISCII(printItem.item.text);
|
|
1013
|
+
printing.raw(Array.from(visciiBytes));
|
|
1014
|
+
} else printing.text(printItem.item.text, printItem.item.line_width ?? 48);
|
|
848
1015
|
if (printItem.item.size === PrintSize.Custom) printing.raw([
|
|
849
1016
|
29,
|
|
850
1017
|
33,
|
|
@@ -864,7 +1031,10 @@ var EscPosPrinter = class {
|
|
|
864
1031
|
]);
|
|
865
1032
|
} else if (printItem.table.size) printing.size(printItem.table.size);
|
|
866
1033
|
this.formatTable(printItem.table.items, printItem.table.line_width ?? 48).forEach((line) => {
|
|
867
|
-
|
|
1034
|
+
if (isVISCIICodepage(template.codepage)) {
|
|
1035
|
+
const visciiBytes = utf8ToVISCII(line);
|
|
1036
|
+
printing.raw(Array.from(visciiBytes));
|
|
1037
|
+
} else printing.text(line, printItem.table.line_width ?? 48);
|
|
868
1038
|
printing.newline();
|
|
869
1039
|
});
|
|
870
1040
|
if (printItem.table.size === PrintSize.Custom) printing.raw([
|
|
@@ -1208,6 +1378,7 @@ var PrintTemplate = class extends AppBaseModel {
|
|
|
1208
1378
|
_defineProperty(this, "footer", "");
|
|
1209
1379
|
_defineProperty(this, "commands", "");
|
|
1210
1380
|
_defineProperty(this, "printer_type", PrinterType.ReceiptPrinter);
|
|
1381
|
+
_defineProperty(this, "codepage", void 0);
|
|
1211
1382
|
_defineProperty(this, "uid", ModelPrefix.PrintTemplate + nanoid());
|
|
1212
1383
|
_defineProperty(this, "report_code_name", "");
|
|
1213
1384
|
}
|
|
@@ -5094,8 +5265,8 @@ var PrintTemplateService = class extends AppRemoteService {
|
|
|
5094
5265
|
}
|
|
5095
5266
|
async renderPrintTemplate(invoice, config, template, options = new RenderPrintTemplateOptions()) {
|
|
5096
5267
|
const printCommand = new PrintCommand();
|
|
5097
|
-
printCommand.codepage = this.getCodepageByCountryCode(config.
|
|
5098
|
-
|
|
5268
|
+
if (template.printer_type == PrinterType.KitchenPrinter || template.printer_type == PrinterType.OrderPrinter) printCommand.codepage = template.codepage || this.getCodepageByCountryCode(config.kitchen.language);
|
|
5269
|
+
else printCommand.codepage = template.codepage || this.getCodepageByCountryCode(config.receipt.language);
|
|
5099
5270
|
const templateData = new TemplateData();
|
|
5100
5271
|
templateData.invoice = invoice;
|
|
5101
5272
|
templateData.config = config;
|
|
@@ -5111,7 +5282,6 @@ var PrintTemplateService = class extends AppRemoteService {
|
|
|
5111
5282
|
const templateData = new TemplateData();
|
|
5112
5283
|
templateData.report_data = reportData;
|
|
5113
5284
|
templateData.config = config;
|
|
5114
|
-
printCommand.codepage = Codepages.SimplifiedChinese;
|
|
5115
5285
|
printCommand.items.push(...await this.renderPrintCommand(template.header, templateData));
|
|
5116
5286
|
printCommand.items.push(...await this.renderPrintCommand(template.body, templateData));
|
|
5117
5287
|
printCommand.items.push(...await this.renderPrintCommand(template.footer, templateData));
|
|
@@ -5131,32 +5301,39 @@ var PrintTemplateService = class extends AppRemoteService {
|
|
|
5131
5301
|
getCodepageByCountryCode(countryCode) {
|
|
5132
5302
|
const countryCodeToCodepage = {
|
|
5133
5303
|
US: Codepages.English,
|
|
5304
|
+
GR: Codepages.Greek,
|
|
5134
5305
|
DE: Codepages.WesternEurope,
|
|
5135
5306
|
LT: Codepages.BalticRim,
|
|
5136
5307
|
PL: Codepages.CentralEurope,
|
|
5137
5308
|
RU: Codepages.Cyrillic,
|
|
5309
|
+
TR: Codepages.Turkish,
|
|
5310
|
+
EU: Codepages.MultilingualLatin1WithEuro,
|
|
5138
5311
|
PT: Codepages.Portuguese,
|
|
5139
5312
|
IS: Codepages.Icelandic,
|
|
5313
|
+
IL: Codepages.Hebrew,
|
|
5140
5314
|
CA: Codepages.FrenchCanadian,
|
|
5141
5315
|
EG: Codepages.Arabic,
|
|
5142
5316
|
NO: Codepages.Nordic,
|
|
5143
|
-
|
|
5317
|
+
BY: Codepages.Russian,
|
|
5318
|
+
MK: Codepages.ModernGreek,
|
|
5319
|
+
CN: Codepages.SimplifiedChinese,
|
|
5144
5320
|
KR: Codepages.Korean,
|
|
5145
5321
|
TW: Codepages.TraditionalChinese,
|
|
5146
5322
|
FR: Codepages.WesternEuropeanLatin,
|
|
5323
|
+
AE: Codepages.ArabicISO,
|
|
5147
5324
|
JP: Codepages.Japanese,
|
|
5148
5325
|
CZ: Codepages.CentralEuropeanLatinWindows,
|
|
5149
5326
|
BG: Codepages.CyrillicWindows,
|
|
5150
5327
|
ES: Codepages.WesternEuropeanLatinWindows,
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5328
|
+
CY: Codepages.GreekWindows,
|
|
5329
|
+
AZ: Codepages.TurkishWindows,
|
|
5330
|
+
PS: Codepages.HebrewWindows,
|
|
5154
5331
|
SA: Codepages.ArabicWindows,
|
|
5155
5332
|
LV: Codepages.BalticWindows,
|
|
5156
5333
|
VN: Codepages.Vietnamese
|
|
5157
5334
|
};
|
|
5158
|
-
if (!countryCode) return countryCodeToCodepage["
|
|
5159
|
-
return countryCodeToCodepage[countryCode.toUpperCase()] || countryCodeToCodepage["
|
|
5335
|
+
if (!countryCode) return countryCodeToCodepage["CN"];
|
|
5336
|
+
return countryCodeToCodepage[countryCode.toUpperCase()] || countryCodeToCodepage["CN"];
|
|
5160
5337
|
}
|
|
5161
5338
|
async renderPrintCommand(template, data) {
|
|
5162
5339
|
try {
|
package/package.json
CHANGED