@lunarisapp/hyphen 1.0.0 → 1.1.0
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/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +49 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -16
package/dist/index.d.mts
CHANGED
|
@@ -5,6 +5,10 @@ declare const beBy: HyphenDict;
|
|
|
5
5
|
declare const bgBG: HyphenDict;
|
|
6
6
|
declare const ca: HyphenDict;
|
|
7
7
|
declare const daDK: HyphenDict;
|
|
8
|
+
declare const deAT: HyphenDict;
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use `deAT` instead.
|
|
11
|
+
*/
|
|
8
12
|
declare const deDT: HyphenDict;
|
|
9
13
|
declare const deCH: HyphenDict;
|
|
10
14
|
declare const deDE: HyphenDict;
|
|
@@ -101,12 +105,13 @@ type Language = keyof typeof dictionaries;
|
|
|
101
105
|
declare class TextHyphen {
|
|
102
106
|
private readonly left;
|
|
103
107
|
private readonly right;
|
|
104
|
-
private hd;
|
|
108
|
+
private readonly hd;
|
|
105
109
|
constructor(props?: {
|
|
106
110
|
lang?: Language;
|
|
107
111
|
left?: number;
|
|
108
112
|
right?: number;
|
|
109
113
|
});
|
|
114
|
+
private filteredPositions;
|
|
110
115
|
/**
|
|
111
116
|
* Get the positions of possible hyphenation points in a word
|
|
112
117
|
* @param word
|
|
@@ -137,4 +142,4 @@ declare class TextHyphen {
|
|
|
137
142
|
inserted(word: string, hyphen?: string): string;
|
|
138
143
|
}
|
|
139
144
|
|
|
140
|
-
export { type Language, TextHyphen, afZa, asIn, beBy, bgBG, ca, daDK, deCH, deDE, deDT, dictionaries, enGB, enUS, eo, es, etEE, fr, gl, hrHR, huHU, idID, is, itIT, knIN, lt, lvLV, mnMN, mrIN, nbNO, nlNL, nnNO, paIN, plPL, ptBR, ptPT, roRO, ruRU, saIN, skSK, slSI, sqAL, sr, srLatn, sv, teIN, thTH, ukUA, zuZA };
|
|
145
|
+
export { type Language, TextHyphen, afZa, asIn, beBy, bgBG, ca, daDK, deAT, deCH, deDE, deDT, dictionaries, enGB, enUS, eo, es, etEE, fr, gl, hrHR, huHU, idID, is, itIT, knIN, lt, lvLV, mnMN, mrIN, nbNO, nlNL, nnNO, paIN, plPL, ptBR, ptPT, roRO, ruRU, saIN, skSK, slSI, sqAL, sr, srLatn, sv, teIN, thTH, ukUA, zuZA };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ declare const beBy: HyphenDict;
|
|
|
5
5
|
declare const bgBG: HyphenDict;
|
|
6
6
|
declare const ca: HyphenDict;
|
|
7
7
|
declare const daDK: HyphenDict;
|
|
8
|
+
declare const deAT: HyphenDict;
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use `deAT` instead.
|
|
11
|
+
*/
|
|
8
12
|
declare const deDT: HyphenDict;
|
|
9
13
|
declare const deCH: HyphenDict;
|
|
10
14
|
declare const deDE: HyphenDict;
|
|
@@ -101,12 +105,13 @@ type Language = keyof typeof dictionaries;
|
|
|
101
105
|
declare class TextHyphen {
|
|
102
106
|
private readonly left;
|
|
103
107
|
private readonly right;
|
|
104
|
-
private hd;
|
|
108
|
+
private readonly hd;
|
|
105
109
|
constructor(props?: {
|
|
106
110
|
lang?: Language;
|
|
107
111
|
left?: number;
|
|
108
112
|
right?: number;
|
|
109
113
|
});
|
|
114
|
+
private filteredPositions;
|
|
110
115
|
/**
|
|
111
116
|
* Get the positions of possible hyphenation points in a word
|
|
112
117
|
* @param word
|
|
@@ -137,4 +142,4 @@ declare class TextHyphen {
|
|
|
137
142
|
inserted(word: string, hyphen?: string): string;
|
|
138
143
|
}
|
|
139
144
|
|
|
140
|
-
export { type Language, TextHyphen, afZa, asIn, beBy, bgBG, ca, daDK, deCH, deDE, deDT, dictionaries, enGB, enUS, eo, es, etEE, fr, gl, hrHR, huHU, idID, is, itIT, knIN, lt, lvLV, mnMN, mrIN, nbNO, nlNL, nnNO, paIN, plPL, ptBR, ptPT, roRO, ruRU, saIN, skSK, slSI, sqAL, sr, srLatn, sv, teIN, thTH, ukUA, zuZA };
|
|
145
|
+
export { type Language, TextHyphen, afZa, asIn, beBy, bgBG, ca, daDK, deAT, deCH, deDE, deDT, dictionaries, enGB, enUS, eo, es, etEE, fr, gl, hrHR, huHU, idID, is, itIT, knIN, lt, lvLV, mnMN, mrIN, nbNO, nlNL, nnNO, paIN, plPL, ptBR, ptPT, roRO, ruRU, saIN, skSK, slSI, sqAL, sr, srLatn, sv, teIN, thTH, ukUA, zuZA };
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __export(index_exports, {
|
|
|
27
27
|
bgBG: () => bgBG,
|
|
28
28
|
ca: () => ca,
|
|
29
29
|
daDK: () => daDK,
|
|
30
|
+
deAT: () => deAT,
|
|
30
31
|
deCH: () => deCH,
|
|
31
32
|
deDE: () => deDE,
|
|
32
33
|
deDT: () => deDT,
|
|
@@ -239254,6 +239255,7 @@ var beBy = hyph_be_BY_default;
|
|
|
239254
239255
|
var bgBG = hyph_bg_BG_default;
|
|
239255
239256
|
var ca = hyph_ca_default;
|
|
239256
239257
|
var daDK = hyph_da_DK_default;
|
|
239258
|
+
var deAT = hyph_de_AT_default;
|
|
239257
239259
|
var deDT = hyph_de_AT_default;
|
|
239258
239260
|
var deCH = hyph_de_CH_default;
|
|
239259
239261
|
var deDE = hyph_de_DE_default;
|
|
@@ -239369,50 +239371,61 @@ var HyphenDictParser = class {
|
|
|
239369
239371
|
this.cache = /* @__PURE__ */ new Map();
|
|
239370
239372
|
this.maxLen = 0;
|
|
239371
239373
|
const lines = content.split("\n");
|
|
239372
|
-
|
|
239373
|
-
|
|
239374
|
-
if (!
|
|
239375
|
-
|
|
239374
|
+
for (const line of lines) {
|
|
239375
|
+
const trimmedLine = line.trim();
|
|
239376
|
+
if (!trimmedLine || IGNORED.some((i) => trimmedLine.startsWith(i))) {
|
|
239377
|
+
continue;
|
|
239378
|
+
}
|
|
239379
|
+
const pattern = trimmedLine.replace(
|
|
239376
239380
|
/\^{2}([0-9a-f]{2})/g,
|
|
239377
|
-
(
|
|
239381
|
+
(_match, hex) => String.fromCharCode(Number.parseInt(hex, 16))
|
|
239378
239382
|
);
|
|
239379
239383
|
const parts = Array.from(pattern.matchAll(/(\d?)(\D?)/g));
|
|
239380
239384
|
const tags = [];
|
|
239381
239385
|
const values = [];
|
|
239382
|
-
|
|
239383
|
-
tags.push(char);
|
|
239384
|
-
values.push(num ? parseInt(num) : 0);
|
|
239385
|
-
}
|
|
239386
|
-
if (Math.max(...values) === 0)
|
|
239386
|
+
for (const [, num, char] of parts) {
|
|
239387
|
+
tags.push(char ?? "");
|
|
239388
|
+
values.push(num ? Number.parseInt(num, 10) : 0);
|
|
239389
|
+
}
|
|
239390
|
+
if (Math.max(...values) === 0) {
|
|
239391
|
+
continue;
|
|
239392
|
+
}
|
|
239387
239393
|
let start = 0, end = values.length;
|
|
239388
|
-
while (!values[start])
|
|
239389
|
-
|
|
239394
|
+
while (!values[start]) {
|
|
239395
|
+
start++;
|
|
239396
|
+
}
|
|
239397
|
+
while (!values[end - 1]) {
|
|
239398
|
+
end--;
|
|
239399
|
+
}
|
|
239390
239400
|
this.patterns.set(tags.join(""), [start, values.slice(start, end)]);
|
|
239391
|
-
}
|
|
239392
|
-
this.
|
|
239393
|
-
|
|
239394
|
-
);
|
|
239401
|
+
}
|
|
239402
|
+
const lengths = Array.from(this.patterns.keys()).map((k) => k.length);
|
|
239403
|
+
this.maxLen = lengths.length > 0 ? Math.max(...lengths) : 0;
|
|
239395
239404
|
}
|
|
239396
239405
|
positions(word) {
|
|
239397
|
-
|
|
239398
|
-
if (this.cache.has(
|
|
239399
|
-
|
|
239400
|
-
|
|
239406
|
+
const lowerWord = word.toLowerCase();
|
|
239407
|
+
if (this.cache.has(lowerWord)) {
|
|
239408
|
+
return this.cache.get(lowerWord);
|
|
239409
|
+
}
|
|
239410
|
+
const references = new Array(lowerWord.length + 2).fill(0);
|
|
239411
|
+
const extendedWord = `.${lowerWord}.`;
|
|
239401
239412
|
for (let i = 0; i < extendedWord.length - 1; i++) {
|
|
239402
239413
|
for (let j = i + 1; j < Math.min(i + this.maxLen, extendedWord.length) + 1; j++) {
|
|
239403
239414
|
const pattern = this.patterns.get(extendedWord.slice(i, j));
|
|
239404
|
-
if (!pattern)
|
|
239415
|
+
if (!pattern) {
|
|
239416
|
+
continue;
|
|
239417
|
+
}
|
|
239405
239418
|
const [offset, values] = pattern;
|
|
239406
|
-
values.
|
|
239419
|
+
for (let idx = 0; idx < values.length; idx++) {
|
|
239407
239420
|
references[i + offset + idx] = Math.max(
|
|
239408
|
-
|
|
239421
|
+
values[idx],
|
|
239409
239422
|
references[i + offset + idx]
|
|
239410
239423
|
);
|
|
239411
|
-
}
|
|
239424
|
+
}
|
|
239412
239425
|
}
|
|
239413
239426
|
}
|
|
239414
239427
|
const positions = references.map((val, idx) => val % 2 ? new DataInt(idx - 1) : null).filter(Boolean);
|
|
239415
|
-
this.cache.set(
|
|
239428
|
+
this.cache.set(lowerWord, positions);
|
|
239416
239429
|
return positions;
|
|
239417
239430
|
}
|
|
239418
239431
|
};
|
|
@@ -239424,20 +239437,23 @@ var TextHyphen = class {
|
|
|
239424
239437
|
const dict = dictionaries[lang] || enUS;
|
|
239425
239438
|
this.hd = new HyphenDictParser(dict);
|
|
239426
239439
|
}
|
|
239440
|
+
filteredPositions(word) {
|
|
239441
|
+
const rightLimit = word.length - this.right;
|
|
239442
|
+
return this.hd.positions(word).filter((pos) => this.left <= pos.value && pos.value <= rightLimit);
|
|
239443
|
+
}
|
|
239427
239444
|
/**
|
|
239428
239445
|
* Get the positions of possible hyphenation points in a word
|
|
239429
239446
|
* @param word
|
|
239430
239447
|
*/
|
|
239431
239448
|
positions(word) {
|
|
239432
|
-
|
|
239433
|
-
return this.hd.positions(word).map((pos) => pos.value).filter((pos) => this.left <= pos && pos <= rightLimit);
|
|
239449
|
+
return this.filteredPositions(word).map((pos) => pos.value);
|
|
239434
239450
|
}
|
|
239435
239451
|
/**
|
|
239436
239452
|
* Get iterator for all possible variants of hyphenating the word.
|
|
239437
239453
|
* @param word
|
|
239438
239454
|
*/
|
|
239439
239455
|
*iterate(word) {
|
|
239440
|
-
for (const position of this.
|
|
239456
|
+
for (const position of this.filteredPositions(word).reverse()) {
|
|
239441
239457
|
if (position.data) {
|
|
239442
239458
|
const [change, index, cut] = position.data;
|
|
239443
239459
|
const updatedIndex = index + position.value;
|
|
@@ -239469,9 +239485,9 @@ var TextHyphen = class {
|
|
|
239469
239485
|
* @param hyphen
|
|
239470
239486
|
*/
|
|
239471
239487
|
wrap(word, width, hyphen = "-") {
|
|
239472
|
-
width
|
|
239488
|
+
const effectiveWidth = width - hyphen.length;
|
|
239473
239489
|
for (const [w1, w2] of this.iterate(word)) {
|
|
239474
|
-
if (w1.length <=
|
|
239490
|
+
if (w1.length <= effectiveWidth) {
|
|
239475
239491
|
return [w1 + hyphen, w2];
|
|
239476
239492
|
}
|
|
239477
239493
|
}
|
|
@@ -239484,9 +239500,9 @@ var TextHyphen = class {
|
|
|
239484
239500
|
*/
|
|
239485
239501
|
inserted(word, hyphen = "-") {
|
|
239486
239502
|
const letters = [...word];
|
|
239487
|
-
this.positions(word).reverse()
|
|
239503
|
+
for (const pos of this.positions(word).reverse()) {
|
|
239488
239504
|
letters.splice(pos, 0, hyphen);
|
|
239489
|
-
}
|
|
239505
|
+
}
|
|
239490
239506
|
return letters.join("");
|
|
239491
239507
|
}
|
|
239492
239508
|
};
|
|
@@ -239499,6 +239515,7 @@ var TextHyphen = class {
|
|
|
239499
239515
|
bgBG,
|
|
239500
239516
|
ca,
|
|
239501
239517
|
daDK,
|
|
239518
|
+
deAT,
|
|
239502
239519
|
deCH,
|
|
239503
239520
|
deDE,
|
|
239504
239521
|
deDT,
|