Skip to content

Commit f9c50ba

Browse files
committed
Initialization fix + local descriptions
1 parent 273c5e3 commit f9c50ba

File tree

9 files changed

+1180
-459
lines changed

9 files changed

+1180
-459
lines changed

app/page.tsx

Lines changed: 475 additions & 454 deletions
Large diffs are not rendered by default.

barcodes.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ function generateBarcodes() {
7474
bcid: symbology, // Barcode type
7575
text: barcodeValue, // Text to encode
7676
scale: 3, // 3x scaling factor
77-
height: 10, // Bar height, in millimeters
7877
includetext: addText, // Show human-readable text
7978
textxalign: 'center', // Always good to set this
8079
};

bwip-js-sample

Lines changed: 340 additions & 0 deletions
Large diffs are not rendered by default.

desc.js

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// file: bwip-js/lib/symdesc.js
2+
//
3+
// This code was automatically generated from:
4+
// Barcode Writer in Pure PostScript - Version 2024-06-18
5+
//
6+
// Copyright (c) 2011-2024 Mark Warren
7+
// Copyright (c) 2004-2024 Terry Burton
8+
//
9+
// Licensed MIT. See the LICENSE file in the bwip-js root directory
10+
// for the extended copyright notice.
11+
var symdesc = {
12+
"ean5":{ sym:"ean5",desc:"EAN-5 (5 digit addon)",text:"90200",opts:"includetext guardwhitespace" },
13+
"ean2":{ sym:"ean2",desc:"EAN-2 (2 digit addon)",text:"05",opts:"includetext guardwhitespace" },
14+
"ean13":{ sym:"ean13",desc:"EAN-13",text:"9520123456788",opts:"includetext guardwhitespace" },
15+
"ean8":{ sym:"ean8",desc:"EAN-8",text:"95200002",opts:"includetext guardwhitespace" },
16+
"upca":{ sym:"upca",desc:"UPC-A",text:"012345000058",opts:"includetext" },
17+
"upce":{ sym:"upce",desc:"UPC-E",text:"01234558",opts:"includetext" },
18+
"isbn":{ sym:"isbn",desc:"ISBN",text:"978-1-56581-231-4 90000",opts:"includetext guardwhitespace" },
19+
"ismn":{ sym:"ismn",desc:"ISMN",text:"979-0-2605-3211-3",opts:"includetext guardwhitespace" },
20+
"issn":{ sym:"issn",desc:"ISSN",text:"0311-175X 00 17",opts:"includetext guardwhitespace" },
21+
"mands":{ sym:"mands",desc:"Marks & Spencer",text:"0642118",opts:"includetext" },
22+
"code128":{ sym:"code128",desc:"Code 128",text:"Count01234567!",opts:"includetext" },
23+
"gs1-128":{ sym:"gs1-128",desc:"GS1-128",text:"(01)09521234543213(3103)000123",opts:"includetext" },
24+
"ean14":{ sym:"ean14",desc:"GS1-14",text:"(01) 0 952 8765 43210 8",opts:"includetext" },
25+
"sscc18":{ sym:"sscc18",desc:"SSCC-18",text:"(00) 0 9528765 432101234 6",opts:"includetext" },
26+
"code39":{ sym:"code39",desc:"Code 39",text:"THIS IS CODE 39",opts:"includetext includecheck includecheckintext" },
27+
"code39ext":{ sym:"code39ext",desc:"Code 39 Extended",text:"Code39 Ext!",opts:"includetext includecheck includecheckintext" },
28+
"code32":{ sym:"code32",desc:"Italian Pharmacode",text:"01234567",opts:"includetext" },
29+
"pzn":{ sym:"pzn",desc:"Pharmazentralnummer (PZN)",text:"123456",opts:"includetext" },
30+
"code93":{ sym:"code93",desc:"Code 93",text:"THIS IS CODE 93",opts:"includetext includecheck" },
31+
"code93ext":{ sym:"code93ext",desc:"Code 93 Extended",text:"Code93 Ext!",opts:"includetext includecheck" },
32+
"interleaved2of5":{ sym:"interleaved2of5",desc:"Interleaved 2 of 5 (ITF)",text:"2401234567",opts:"height=12 includecheck includetext includecheckintext" },
33+
"itf14":{ sym:"itf14",desc:"ITF-14",text:"0 952 1234 54321 3",opts:"includetext" },
34+
"identcode":{ sym:"identcode",desc:"Deutsche Post Identcode",text:"563102430313",opts:"includetext" },
35+
"leitcode":{ sym:"leitcode",desc:"Deutsche Post Leitcode",text:"21348075016401",opts:"includetext" },
36+
"databaromni":{ sym:"databaromni",desc:"GS1 DataBar Omnidirectional",text:"(01)09521234543213",opts:"" },
37+
"databarstacked":{ sym:"databarstacked",desc:"GS1 DataBar Stacked",text:"(01)09521234543213",opts:"" },
38+
"databarstackedomni":{ sym:"databarstackedomni",desc:"GS1 DataBar Stacked Omnidirectional",text:"(01)24012345678905",opts:"" },
39+
"databartruncated":{ sym:"databartruncated",desc:"GS1 DataBar Truncated",text:"(01)09521234543213",opts:"" },
40+
"databarlimited":{ sym:"databarlimited",desc:"GS1 DataBar Limited",text:"(01)09521234543213",opts:"" },
41+
"databarexpanded":{ sym:"databarexpanded",desc:"GS1 DataBar Expanded",text:"(01)09521234543213(3103)000123",opts:"" },
42+
"databarexpandedstacked":{ sym:"databarexpandedstacked",desc:"GS1 DataBar Expanded Stacked",text:"(01)09521234543213(3103)000123",opts:"segments=4" },
43+
"gs1northamericancoupon":{ sym:"gs1northamericancoupon",desc:"GS1 North American Coupon",text:"(8110)106141416543213500110000310123196000",opts:"includetext segments=8" },
44+
"pharmacode":{ sym:"pharmacode",desc:"Pharmaceutical Binary Code",text:"117480",opts:"showborder" },
45+
"pharmacode2":{ sym:"pharmacode2",desc:"Two-track Pharmacode",text:"117480",opts:"includetext showborder" },
46+
"code2of5":{ sym:"code2of5",desc:"Code 25",text:"01234567",opts:"includetext includecheck includecheckintext" },
47+
"industrial2of5":{ sym:"industrial2of5",desc:"Industrial 2 of 5",text:"01234567",opts:"includetext includecheck includecheckintext" },
48+
"iata2of5":{ sym:"iata2of5",desc:"IATA 2 of 5",text:"01234567",opts:"includetext includecheck includecheckintext" },
49+
"matrix2of5":{ sym:"matrix2of5",desc:"Matrix 2 of 5",text:"01234567",opts:"includetext includecheck includecheckintext" },
50+
"coop2of5":{ sym:"coop2of5",desc:"COOP 2 of 5",text:"01234567",opts:"includetext includecheck includecheckintext" },
51+
"datalogic2of5":{ sym:"datalogic2of5",desc:"Datalogic 2 of 5",text:"01234567",opts:"includetext includecheck includecheckintext" },
52+
"code11":{ sym:"code11",desc:"Code 11",text:"0123456789",opts:"includetext includecheck includecheckintext" },
53+
"bc412":{ sym:"bc412",desc:"BC412",text:"BC412SEMI",opts:"semi includetext includecheckintext" },
54+
"rationalizedCodabar":{ sym:"rationalizedCodabar",desc:"Codabar",text:"A0123456789B",opts:"includetext includecheck includecheckintext" },
55+
"onecode":{ sym:"onecode",desc:"USPS Intelligent Mail",text:"0123456709498765432101234567891",opts:"barcolor=FF0000" },
56+
"postnet":{ sym:"postnet",desc:"USPS POSTNET",text:"01234",opts:"includetext includecheckintext" },
57+
"planet":{ sym:"planet",desc:"USPS PLANET",text:"01234567890",opts:"includetext includecheckintext" },
58+
"royalmail":{ sym:"royalmail",desc:"Royal Mail 4 State Customer Code",text:"LE28HS9Z",opts:"includetext barcolor=FF0000" },
59+
"auspost":{ sym:"auspost",desc:"AusPost 4 State Customer Code",text:"5956439111ABA 9",opts:"includetext custinfoenc=character" },
60+
"kix":{ sym:"kix",desc:"Royal Dutch TPG Post KIX",text:"1231FZ13XHS",opts:"includetext" },
61+
"japanpost":{ sym:"japanpost",desc:"Japan Post 4 State Customer Code",text:"6540123789-A-K-Z",opts:"includetext includecheckintext" },
62+
"msi":{ sym:"msi",desc:"MSI Modified Plessey",text:"0123456789",opts:"includetext includecheck includecheckintext" },
63+
"plessey":{ sym:"plessey",desc:"Plessey UK",text:"01234ABCD",opts:"includetext includecheckintext" },
64+
"telepen":{ sym:"telepen",desc:"Telepen",text:"ABCDEF",opts:"includetext" },
65+
"telepennumeric":{ sym:"telepennumeric",desc:"Telepen Numeric",text:"01234567",opts:"includetext" },
66+
"posicode":{ sym:"posicode",desc:"PosiCode",text:"ABC123",opts:"version=b inkspread=-0.5 parsefnc includetext" },
67+
"codablockf":{ sym:"codablockf",desc:"Codablock F",text:"CODABLOCK F 34567890123456789010040digit",opts:"columns=8" },
68+
"code16k":{ sym:"code16k",desc:"Code 16K",text:"Abcd-1234567890-wxyZ",opts:"" },
69+
"code49":{ sym:"code49",desc:"Code 49",text:"MULTIPLE ROWS IN CODE 49",opts:"" },
70+
"channelcode":{ sym:"channelcode",desc:"Channel Code",text:"3493",opts:"height=12 includetext" },
71+
"flattermarken":{ sym:"flattermarken",desc:"Flattermarken",text:"11099",opts:"inkspread=-0.25 showborder borderleft=0 borderright=0" },
72+
"raw":{ sym:"raw",desc:"Custom 1D symbology",text:"331132131313411122131311333213114131131221323",opts:"height=12" },
73+
"daft":{ sym:"daft",desc:"Custom 4 state symbology",text:"FATDAFTDAD",opts:"" },
74+
"symbol":{ sym:"symbol",desc:"Miscellaneous symbols",text:"fima",opts:"backgroundcolor=DD000011" },
75+
"pdf417":{ sym:"pdf417",desc:"PDF417",text:"This is PDF417",opts:"columns=2" },
76+
"pdf417compact":{ sym:"pdf417compact",desc:"Compact PDF417",text:"This is compact PDF417",opts:"columns=2" },
77+
"micropdf417":{ sym:"micropdf417",desc:"MicroPDF417",text:"MicroPDF417",opts:"" },
78+
"datamatrix":{ sym:"datamatrix",desc:"Data Matrix",text:"This is Data Matrix!",opts:"" },
79+
"datamatrixrectangular":{ sym:"datamatrixrectangular",desc:"Data Matrix Rectangular",text:"1234",opts:"" },
80+
"datamatrixrectangularextension":{ sym:"datamatrixrectangularextension",desc:"Data Matrix Rectangular Extension",text:"1234",opts:"version=8x96" },
81+
"mailmark":{ sym:"mailmark",desc:"Royal Mail Mailmark",text:"JGB 012100123412345678AB19XY1A 0 www.xyz.com",opts:"type=29" },
82+
"qrcode":{ sym:"qrcode",desc:"QR Code",text:"http://goo.gl/0bis",opts:"eclevel=M" },
83+
"swissqrcode":{ sym:"swissqrcode",desc:"Swiss QR Code",text:"SPC^CR^LF0200^CR^LF1^CR^LFCH5800791123000889012^CR^LFS^CR^LFRobert Schneider AG^CR^LFRue du Lac^CR^LF1268^CR^LF2501^CR^LFBiel^CR^LFCH^CR^LF^CR^LF^CR^LF^CR^LF^CR^LF^CR^LF^CR^LF^CR^LF199.95^CR^LFCHF^CR^LFK^CR^LFPia-Maria Rutschmann-Schnyder^CR^LFGrosse Marktgasse 28^CR^LF9400 Rorschach^CR^LF^CR^LF^CR^LFCH^CR^LFSCOR^CR^LFRF18539007547034^CR^LF^CR^LFEPD",opts:"parse" },
84+
"microqrcode":{ sym:"microqrcode",desc:"Micro QR Code",text:"1234",opts:"" },
85+
"rectangularmicroqrcode":{ sym:"rectangularmicroqrcode",desc:"Rectangular Micro QR Code",text:"1234",opts:"version=R17x139" },
86+
"maxicode":{ sym:"maxicode",desc:"MaxiCode",text:"[)>^03001^02996152382802^029840^029001^0291Z00004951^029UPSN^02906X610^029159^0291234567^0291/1^029^029Y^029634 ALPHA DR^029PITTSBURGH^029PA^029^004",opts:"mode=2 parse" },
87+
"azteccode":{ sym:"azteccode",desc:"Aztec Code",text:"This is Aztec Code",opts:"format=full" },
88+
"azteccodecompact":{ sym:"azteccodecompact",desc:"Compact Aztec Code",text:"1234",opts:"" },
89+
"aztecrune":{ sym:"aztecrune",desc:"Aztec Runes",text:"1",opts:"" },
90+
"codeone":{ sym:"codeone",desc:"Code One",text:"Code One",opts:"" },
91+
"hanxin":{ sym:"hanxin",desc:"Han Xin Code",text:"This is Han Xin",opts:"" },
92+
"dotcode":{ sym:"dotcode",desc:"DotCode",text:"This is DotCode",opts:"inkspread=0.16" },
93+
"ultracode":{ sym:"ultracode",desc:"Ultracode",text:"Awesome colours!",opts:"eclevel=EC2" },
94+
"gs1-cc":{ sym:"gs1-cc",desc:"GS1 Composite 2D Component",text:"(01)09521234543213(3103)000123",opts:"ccversion=b cccolumns=4" },
95+
"ean13composite":{ sym:"ean13composite",desc:"EAN-13 Composite",text:"9520123456788|(99)1234-abcd",opts:"includetext" },
96+
"ean8composite":{ sym:"ean8composite",desc:"EAN-8 Composite",text:"95200002|(21)A12345678",opts:"includetext" },
97+
"upcacomposite":{ sym:"upcacomposite",desc:"UPC-A Composite",text:"012345000058|(99)1234-abcd",opts:"includetext" },
98+
"upcecomposite":{ sym:"upcecomposite",desc:"UPC-E Composite",text:"01234558|(15)021231",opts:"includetext" },
99+
"databaromnicomposite":{ sym:"databaromnicomposite",desc:"GS1 DataBar Omnidirectional Composite",text:"(01)09521234543213|(11)990102",opts:"" },
100+
"databarstackedcomposite":{ sym:"databarstackedcomposite",desc:"GS1 DataBar Stacked Composite",text:"(01)09521234543213|(17)010200",opts:"" },
101+
"databarstackedomnicomposite":{ sym:"databarstackedomnicomposite",desc:"GS1 DataBar Stacked Omnidirectional Composite",text:"(01)03612345678904|(11)990102",opts:"" },
102+
"databartruncatedcomposite":{ sym:"databartruncatedcomposite",desc:"GS1 DataBar Truncated Composite",text:"(01)09521234543213|(11)990102",opts:"" },
103+
"databarlimitedcomposite":{ sym:"databarlimitedcomposite",desc:"GS1 DataBar Limited Composite",text:"(01)09521234543213|(21)abcdefghijklmnopqrst",opts:"" },
104+
"databarexpandedcomposite":{ sym:"databarexpandedcomposite",desc:"GS1 DataBar Expanded Composite",text:"(01)09521234543213(3103)001234|(91)1A2B3C4D5E",opts:"" },
105+
"databarexpandedstackedcomposite":{ sym:"databarexpandedstackedcomposite",desc:"GS1 DataBar Expanded Stacked Composite",text:"(01)09521234543213(10)ABCDEF|(21)12345678",opts:"segments=4" },
106+
"gs1-128composite":{ sym:"gs1-128composite",desc:"GS1-128 Composite",text:"(00)095287654321012346|(02)09521234543213(37)24(10)1234567ABCDEFG",opts:"ccversion=c" },
107+
"gs1datamatrix":{ sym:"gs1datamatrix",desc:"GS1 Data Matrix",text:"(01)09521234543213(17)120508(10)ABCD1234(410)9501101020917",opts:"" },
108+
"gs1datamatrixrectangular":{ sym:"gs1datamatrixrectangular",desc:"GS1 Data Matrix Rectangular",text:"(01)09521234543213(17)120508(10)ABCD1234(410)9501101020917",opts:"" },
109+
"gs1dldatamatrix":{ sym:"gs1dldatamatrix",desc:"GS1 Digital Link Data Matrix",text:"https://id.gs1.org/01/09521234543213/22/ABC%2D123?99=XYZ-987",opts:"" },
110+
"gs1qrcode":{ sym:"gs1qrcode",desc:"GS1 QR Code",text:"(01)09521234543213(8200)http://www.abc.net(10)ABCD1234(410)9501101020917",opts:"" },
111+
"gs1dlqrcode":{ sym:"gs1dlqrcode",desc:"GS1 Digital Link QR Code",text:"HTTPS://ID.GS1.ORG/01/09521234543213/22/ABC%2D123?99=XYZ-987",opts:"" },
112+
"gs1dotcode":{ sym:"gs1dotcode",desc:"GS1 DotCode",text:"(235)5vBZIF%!<B;?oa%(01)09521234543213(8008)19052001",opts:"rows=16" },
113+
"hibccode39":{ sym:"hibccode39",desc:"HIBC Code 39",text:"A999BJC5D6E71",opts:"includetext" },
114+
"hibccode128":{ sym:"hibccode128",desc:"HIBC Code 128",text:"A999BJC5D6E71",opts:"includetext" },
115+
"hibcdatamatrix":{ sym:"hibcdatamatrix",desc:"HIBC Data Matrix",text:"A999BJC5D6E71",opts:"" },
116+
"hibcdatamatrixrectangular":{ sym:"hibcdatamatrixrectangular",desc:"HIBC Data Matrix Rectangular",text:"A999BJC5D6E71",opts:"" },
117+
"hibcpdf417":{ sym:"hibcpdf417",desc:"HIBC PDF417",text:"A999BJC5D6E71",opts:"" },
118+
"hibcmicropdf417":{ sym:"hibcmicropdf417",desc:"HIBC MicroPDF417",text:"A999BJC5D6E71",opts:"" },
119+
"hibcqrcode":{ sym:"hibcqrcode",desc:"HIBC QR Code",text:"A999BJC5D6E71",opts:"" },
120+
"hibccodablockf":{ sym:"hibccodablockf",desc:"HIBC Codablock F",text:"A999BJC5D6E71",opts:"" },
121+
"hibcazteccode":{ sym:"hibcazteccode",desc:"HIBC Aztec Code",text:"A999BJC5D6E71",opts:"" }
122+
};
123+
124+
if (typeof module == 'object' && typeof module.exports == 'object') {
125+
module.exports = symdesc;
126+
}

export.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
2222
crossorigin="anonymous"></script>
2323
<link rel="stylesheet" href="main.css">
24-
<script src="barcodes.js"></script>
25-
<script src="export.js"></script>
24+
<script src="public/scripts/barcodes.js"></script>
25+
<script src="public/scripts/export.js"></script>
2626
</head>
2727

2828

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
crossorigin="anonymous"></script>
2828
<link rel="stylesheet" href="main.css">
2929
<script type="text/javascript" src="bwip-js/dist/bwip-js-min.js"></script>
30-
<script src="barcodes.js"></script>
31-
<script src="export.js"></script>
30+
<script src="public/scripts/barcodes.js"></script>
31+
<script src="public/scripts/export.js"></script>
3232

3333
</head>
3434

public/scripts/barcodes.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
String.format = function () {
2+
var s = arguments[0];
3+
for (var i = 0; i < arguments.length - 1; i++) {
4+
var reg = new RegExp("\\{" + i + "\\}", "gm");
5+
s = s.replace(reg, arguments[i + 1]);
6+
}
7+
return s;
8+
}
9+
10+
function createBarcodeGrid(entries) {
11+
let html = [];
12+
html.push('<div class="grid-container">');
13+
14+
for (let i = 0; i < entries.length; i++) {
15+
const id = `barcode_image_${i}`;
16+
html.push(`<div class="barcode-container"><img id="${id}" class="barcode-image"></div>`);
17+
}
18+
19+
html.push('</div>');
20+
return html.join('');
21+
}
22+
23+
function generateBarcodes() {
24+
try {
25+
let str = document.getElementById("barcodesEntry").value;
26+
if (str == '') {
27+
document.getElementById("barcodesContainer").innerText = '';
28+
return
29+
}
30+
31+
localStorage.setItem('lastRequest', str);
32+
33+
var separator;
34+
if (str.includes('\n')) {
35+
separator = '\n'
36+
}
37+
else if (str.includes(' ')) {
38+
separator = ' '
39+
}
40+
else if (str.includes(';')) {
41+
separator = ';'
42+
}
43+
else if (str.includes(',')) {
44+
separator = ','
45+
}
46+
let entries = str.split(separator)
47+
const entriesCount = entries.length
48+
const columnsPerRow = 4
49+
var rows = 1
50+
if (entriesCount > columnsPerRow) {
51+
let mod = entriesCount % columnsPerRow
52+
if (mod > 0) {
53+
rows = entriesCount / columnsPerRow
54+
}
55+
else {
56+
rows = (entriesCount / columnsPerRow) + 1
57+
}
58+
}
59+
60+
let gridHtml = createBarcodeGrid(entries);
61+
document.getElementById("barcodesContainer").innerHTML = gridHtml;
62+
63+
64+
const symbology = document.getElementById("symbologySelector").value
65+
localStorage.setItem('lastSymbology', symbology);
66+
const addText = document.getElementById("addTextCheck").checked
67+
let canvas = document.createElement('canvas');
68+
69+
for (let i = 0; i < entries.length; i++) {
70+
const barcodeValue = entries[i].trim();
71+
const id = `barcode_image_${i}`;//this is the value used when creating the grid
72+
73+
var options = {
74+
bcid: symbology, // Barcode type
75+
text: barcodeValue, // Text to encode
76+
scale: 3, // 3x scaling factor
77+
includetext: addText, // Show human-readable text
78+
textxalign: 'center', // Always good to set this
79+
};
80+
try {
81+
82+
bwipjs.toCanvas(canvas, options);
83+
var img = document.getElementById(id);
84+
if (img != null) {
85+
img.src = canvas.toDataURL('image/png');
86+
}
87+
} catch (e) {
88+
console.error(e);
89+
}
90+
}
91+
}
92+
catch (error) {
93+
document.getElementById("barcodesContainer").innerText = error;
94+
}
95+
}

0 commit comments

Comments
 (0)