foliojs / linebreak Goto Github PK
View Code? Open in Web Editor NEWA JS implementation of the Unicode Line Breaking Algorithm (UAX #14)
License: MIT License
A JS implementation of the Unicode Line Breaking Algorithm (UAX #14)
License: MIT License
Hello,
Please publish a new version of linebreak and update its dependency for pdfkit.
in the source code "const data = base64.toByteArray(fs.readFileSync(__dirname + '/classes.trie', 'base64'));"
since browser doesn't have fs.readFileSync supports, some pre build transform is needed to load the classes.tire during build time. Anyone has some guidelines how I can do this in ReactJS? Thanks!
-- recommendations for author , instead of loading the file using fs, we might use
// const data = base64.toByteArray(fs.readFileSync(__dirname + '/classes.trie', 'base64'));
// convert the classes.tire as base64 string in JS files
const classData = "AA4IAAAAAAAAAhqg5VV7NJtZvz7fTC8zU5d.........";
const data = base64.toByteArray(classData);
Hi @devongovett
Linebreak works on big endian machines only if classes.trie is generated on big endian machine too. Otherwise there is an error
reak/src/linebreaker.js:122
switch (pairTable[this.curClass][this.nextClass]) {
^
TypeError: Cannot read property 'undefined' of undefined
Seen by @lcurcio at "IBM I" POWER system and by me on Debian MIPS
I mean your lib is really useful, but it's a pitty that it can be run only on nodejs.
So, can u make some change to make it can be run on browser?
Thank you so much.
It'll reduce your module size from 1.1M to 180K.
Currently i'm using webpack 3 with pdfkit 0.10.0, it appears pdfkit is using this lib and the error I got was
Uncaught Error: File 'classes.trie' not found in virtual file system
readFileSync virtual-fs.js:22
<anonymous> linebreaker.js:15
<anonymous> linebreaker.js:161
<anonymous> linebreaker.js:163
js main.bundle.js:33462
__webpack_require__ main.bundle.js:679
fn main.bundle.js:89
<anonymous> pdfkit.es5.js:1
<anonymous> pdfkit.es5.js:5741
js main.bundle.js:37199
__webpack_require__ main.bundle.js:679
fn main.bundle.js:89
<anonymous> ImportPatientDialog.js:26
<anonymous> ImportPatientDialog.js:1397
js main.bundle.js:49567
__webpack_require__ main.bundle.js:679
fn main.bundle.js:89
<anonymous> DataEntry.js:15
<anonymous> DataEntry.js:307
js main.bundle.js:49671
__webpack_require__ main.bundle.js:679
fn main.bundle.js:89
<anonymous> SettingContent.js:24
<anonymous> SettingContent.js:256
js main.bundle.js:49415
__webpack_require__ main.bundle.js:679
fn main.bundle.js:89
<anonymous> Settings.js:16
<anonymous> Settings.js:313
js main.bundle.js:49431
__webpack_require__ main.bundle.js:679
fn main.bundle.js:89
<anonymous> AppNoSplit.js:42
<anonymous> AppNoSplit.js:312
js main.bundle.js:44352
__webpack_require__ main.bundle.js:679
fn main.bundle.js:89
<anonymous> index.js:18
<anonymous> index.js:147
js main.bundle.js:50751
__webpack_require__ main.bundle.js:679
fn main.bundle.js:89
0 main.bundle.js:51371
__webpack_require__ main.bundle.js:679
<anonymous> main.bundle.js:725
<anonymous> main.bundle.js:728
virtual-fs.js:22
I don't really understand the meaning behind this, how do I fix this?
If a string ends with '\r\n' the final returned line break position doesn't have the 'required' flag set.
This line should include a check and return appropriately:
Line 194 in 9096a22
eg: perhaps this:
var required = (this.curClass === BK) || ((this.curClass === CR) && (this.nextClass !== LF));
return new Break(this.string.length, required)
I was porting this to C# and getting "not all control paths return a value" errors. Pretty sure this 'if' statement is redundant due to the preceding "while" statement's condition.
Line 191 in 9096a22
Thanks for your work on this :)
hi, how to support cjk ?
Module not found: Error: Can't resolve 'fs' in node_modules/linebreak/src'
@ .//linebreak/src/linebreaker.js 7:7-20/react-canvas/lib/measureText.js
@ ./
@ ./~/react-canvas/lib/ReactCanvas.js
ERROR in ./~/{my lib}/~/linebreak/src/linebreaker.js
Module not found: Error: Cannot resolve module 'fs' in {my lib}/node_modules/linebreak/src
@ ./~/{my lib}/~/linebreak/src/linebreaker.js 7:7-20
Texts with dashes are wrapped incorrectly. Tested on uuid strings.
Example 1:
Source text:
67e404e5-d4fb-2732-be14-2f60cf8b3cc2
Actual result:
67e404e5-
d4fb-2732-
be14-2f60cf8b3cc2
Expected result:
67e404e5-
d4fb-
2732-
be14-
2f60cf8b3cc2
Example 2:
Source text:
9847b959-135a-7014-3ad5-5223f4d2eaf5
Actual result:
9847b959-135a-7014-3ad5-5223f4d2eaf5
Expected result:
9847b959-
135a-
7014-
3ad5-
5223f4d2eaf5
Please, could it be fixed?
I found 2 license-related problems:
LICENSE
file at top of repo
LICENSE
file in the release tarball (under https://registry.npmjs.org/)There are mainly two issues:
I was just going through cleaning up my version of this code that I ported to C# and noticed a possible problem with the way the trie data is generated for the line break data.
See this line of code
linebreak/src/generate_data.js
Line 31 in 9096a22
Seems this code is trying to coalesce consecutive ranges with the same class into a single trie.setRange call. The problem is that it's checking for a change of class, but not that the ranges are consecutive and without gaps.
Shouldn't that line read something like this:
if (((type != null) && (rangeType !== type)) || parseInt(rangeStart, 16) != parseInt(end, 16) + 1)
Also, it seems the UnicodeTrieBuilder already coalesces runs so this isn't even necessary. I reduced it to this:
var re = /^([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s*;\s*(.*?)\s*#/gm
var m;
while (m = re.exec(data))
{
var from = parseInt(m[1], 16);
var to = m[2] === undefined ? from : parseInt(m[2], 16);
var prop = m[3];
lineBreakClassesTrie.setRange(from, to, LineBreakClass[prop], true);
}
Unfortunately none of this resolves any of those 30 non-passing tests.
Would it be possible to move brfs
to devDependencies
? PDFKit has it in the devDependencies
, which would fix the npm audit
warnings about security vulnerabilities for both these libraries. See also bpampuch/pdfmake#1639.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.