-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New major version (4.0) discussion #263
Comments
|
Also, if we drop the CDN support. We could remove the not so nice gulp scripts. |
Something I would like to do in the next version it support better tree shaking. The problem is that it would require an API that is not as clean (as I see it). I imagine something like this. import jsbarcode, { code128, canvasRenderer } from 'jsbarcode';
jsbarcode(value, element, {
format: code128,
render: canvasRenderer,
}); I think this will work in webpack 4 but not in the lower versions. To support lower versions I think this will be needed import jsbarcode from 'jsbarcode';
import code128 from 'jsbarcode/format/code128';
import canvasRenderer from 'jsbarcode/render/canvas';
jsbarcode(value, element, {
format: code128,
render: canvasRenderer,
}); In either case, no default value for the format or renderer may be set. |
I see, thanks. Now I know that my thoughts close with yours :) |
Here is another good point #273 |
I will slowly begin to rewrite jsbarcode now. Will post when I have something to show 🙂 |
I've made some changes now that should be a start to JsBarcode 4. The answers to all the question in the first post are no. I've been thinking about it, and I want to keep the core as simple as possible so that it can easily be expanded on outside of this library if someone needs it. And also to keep the impact of using the library as small as possible. Here is an example https://github.com/lindell/JsBarcode/blob/jsbarcode-v4/example/index.js the structure is not correct but used what I had to get something to work as quickly as possible (and enable code splitting). Building is done with |
@lindell wow, great work! Thx.
👍 I'll try it in my project. |
With new API you can create your custom JsBarcode function: import flatEncodings from '../lib/help/linearizeEncodings';
import EAN13 from '../lib/barcodes/EAN_UPC/EAN13';
import SVGRender from '../lib/renderers/svg';
const options = {
width: 2,
height: 100,
displayValue: true,
fontOptions: '',
font: 'monospace',
textMargin: 2,
fontSize: 20,
margin: 10,
marginTop: 10,
marginBottom: 10,
marginLeft: 10,
marginRight: 10,
};
const encoder = new EAN13('9780199532179', options);
if (encoder.valid()) {
const svg = document.querySelector('#barcode');
const encodings = flatEncodings(encoder.encode());
new SVGRender(svg, encodings, options).render();
} |
You can even use promises 😁 : import flatEncodings from '../lib/help/linearizeEncodings';
import EAN13 from '../lib/barcodes/EAN_UPC/EAN13';
import SVGRender from '../lib/renderers/svg';
const OPTIONS = {
width: 2,
height: 100,
displayValue: true,
fontOptions: '',
font: 'monospace',
textMargin: 2,
fontSize: 20,
margin: 10,
marginTop: 10,
marginBottom: 10,
marginLeft: 10,
marginRight: 10,
};
function barcode(element, text, options) {
return new Promise((resolve, reject) => {
options = { ...OPTIONS, ...options };
const encoder = new EAN13(text, options);
if (encoder.valid()) {
const encodings = flatEncodings(encoder.encode());
new SVGRender(element, encodings, options).render();
resolve();
} else {
reject(new Error('Invalid data'));
}
});
}
// usage
(async function() {
try {
const svg = document.querySelector('#barcode');
await barcode(svg, '978019953217', { textMargin: 0 });
// do something next
} catch (error) {
// handle errors
}
})(); |
Yes, everything will become much more modularized :) It will also be much easier to create your own renderer or barcode without having it as a part of jsbarcode. |
That's nice, but the promise part is not even necessary :) (since nothing in jsbarcode is asynchronous ) import flatEncodings from '../lib/help/linearizeEncodings';
import EAN13 from '../lib/barcodes/EAN_UPC/EAN13';
import SVGRender from '../lib/renderers/svg';
const OPTIONS = {
width: 2,
height: 100,
displayValue: true,
fontOptions: '',
font: 'monospace',
textMargin: 2,
fontSize: 20,
margin: 10,
marginTop: 10,
marginBottom: 10,
marginLeft: 10,
marginRight: 10,
};
function barcode(element, text, options) {
options = { ...OPTIONS, ...options };
const encoder = new EAN13(text, options);
if (encoder.valid()) {
const encodings = flatEncodings(encoder.encode());
new SVGRender(element, encodings, options).render();
} else {
throw new Error('Invalid data');
}
}
// usage
try {
const svg = document.querySelector('#barcode');
barcode(svg, '978019953217', { textMargin: 0 });
// do something next
} catch (error) {
// handle errors
} |
@lindell I've tried to install |
I will have a look at it! |
|
Some things needs to be decided before we can publish the first beta of v4. I'm also thinking about changing the renderer and barcodes from classes to functions since I don't see any reason for them to be classes that is instantiated. The problem is that the barcodes has valid function that is also used right now, two alternatives there is to let the barcode throw the |
The I also have a problem with |
Also I thought about typescript 😅but I don't have time for that 😔 |
A feature I sought out for a while was how to render a barcode inside javascript to use it with jspdf. I got around it using |
@halvardssm To get a base64 encoded blob with jsbarcode is already very simple and is not something that will be added to jsbarcode 4. The goal with it is to strip out as much as possible that can be done easily anyways, Code for JsBarcode 3: function textToBase64BarcodeBlob(text){
const canvas = document.createElement("canvas");
JsBarcode(canvas, text);
return canvas.toDataURL("image/png");
} |
Hi, just started using you lib, and have some issues when i installed via yarn, it grabbed "^4.0.0-alpha.5" which i am assuming is still in dev going by this thread |
Hey, I just ran across this thread and I though I suggest things, if this is open to conversation? @SanichKotikov asked four things:do you wanna keep
|
@lgrayland I will take a look at it. Thought alpha tags would not be used as default |
@Crackroach JsBarcode("#id", Instead of $("#id").JsBarcode( Do you see any reason to still keep it? |
@lindell |
@lgrayland npm apparently sets the |
can provide 'pt' for print diff dpi |
Perhaps this is not the thread for this "suggestion", but I would like to see if it is possible to have the option to have SVG elements or paths. This is because I mainly use this library to embed the barcode in PDFs, I used pdfKit and pdfMake:
thanks! |
It would be nice for it to support 2D barcodes like PDF417, QR Codes, etc. |
@lindell Code 39, mod43 typing is not included in jsbarcode.d.ts: |
It would be nice for it to support 2D barcodes like datamatrix,PDF417, QR Codes, etc. |
2D Barcodes will not be included in JsBarcode. The focus is and will remain 1D barcodes. There already exists a lot of amazing libraries for specific 2D barcodes :) |
Your script is just done right, thank you. Do you have a recommendation for a QR Code script, one that you'd use if you needed to? |
Is there any plan to make it easy to specify switching between code128 sub-types for substrings of an input value? Issue #365 describes the desired behaviour more or less. |
does this supports vue3 with vite ? I have tried to install jsbarcode but while building my project, i gets error - cannot call namespace ('jsBarCode'). Any help will be much appreciated. |
|
need support without nodeJS |
planned support cli ? |
Just thought I'd add my thoughts to the questions posed originally Q. do you wanna keep jQuery support? Q. do you wanna keep html element's properties (as options for a barcode) support? Q. do you wanna keep *.min.js files (cdn links), to use the library without npm? Q. do you wanna keep bower support? |
Hello, very nice and all, but I would like a printing interface that makes it easy to grab the image with the barcode and send it to print to a label printer, or perhaps to a network/USB printer... also make the coffee... but that's too much to ask. |
You can do this already but putting the image on an HTML page and using CSS to set it up for the label size you want to do. Then you can use JavaScript to trigger the browser print. I'm doing this for a client but loading a print ready html page into a hidden iframe on the page and then triggering the print so they can choose the network printer to print to |
@lindell Hi,
Some questions about next version:
jQuery
support?*.min.js
files (cdn links), to use the library withoutnpm
?bower
support?Any other thoughts about next major version?
The text was updated successfully, but these errors were encountered: