@ac-kit/text-unicode 0.0.0-stage → 0.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/CHANGELOG.md +51 -0
- package/LICENSE +75 -0
- package/README.md +51 -2
- package/dist/_code-point-runs.d.ts +19 -0
- package/dist/_code-point-runs.d.ts.map +1 -0
- package/dist/_code-point-runs.js +46 -0
- package/dist/_code-point-runs.js.map +1 -0
- package/dist/bidi/_bidi-classes.d.ts +4 -0
- package/dist/bidi/_bidi-classes.d.ts.map +1 -0
- package/dist/bidi/_bidi-classes.js +17 -0
- package/dist/bidi/_bidi-classes.js.map +1 -0
- package/dist/bidi/first-strong-direction.d.ts +46 -0
- package/dist/bidi/first-strong-direction.d.ts.map +1 -0
- package/dist/bidi/first-strong-direction.js +92 -0
- package/dist/bidi/first-strong-direction.js.map +1 -0
- package/dist/display/normalize-display-text.d.ts +38 -0
- package/dist/display/normalize-display-text.d.ts.map +1 -0
- package/dist/display/normalize-display-text.js +50 -0
- package/dist/display/normalize-display-text.js.map +1 -0
- package/dist/display/slugify.d.ts +20 -0
- package/dist/display/slugify.d.ts.map +1 -0
- package/dist/display/slugify.js +25 -0
- package/dist/display/slugify.js.map +1 -0
- package/dist/fold/strip-diacritics.d.ts +11 -0
- package/dist/fold/strip-diacritics.d.ts.map +1 -0
- package/dist/fold/strip-diacritics.js +14 -0
- package/dist/fold/strip-diacritics.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/width/_east-asian-width-runs.d.ts +4 -0
- package/dist/width/_east-asian-width-runs.d.ts.map +1 -0
- package/dist/width/_east-asian-width-runs.js +16 -0
- package/dist/width/_east-asian-width-runs.js.map +1 -0
- package/dist/width/east-asian-width.d.ts +30 -0
- package/dist/width/east-asian-width.d.ts.map +1 -0
- package/dist/width/east-asian-width.js +41 -0
- package/dist/width/east-asian-width.js.map +1 -0
- package/package.json +66 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @ac-kit/text-unicode
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 34e8cfa: New package `@ac-kit/text-unicode`, the first of the `text-*` group: text by
|
|
8
|
+
Unicode character properties and UAX algorithms. It holds
|
|
9
|
+
`firstStrongDirection(text)`, the direction (`"ltr"`, `"rtl"` or `undefined`)
|
|
10
|
+
of the first character of Unicode bidirectional class L, or R and AL, which is
|
|
11
|
+
HTML's `dir="auto"` rule and UAX #9's rule P2: characters inside an isolate are
|
|
12
|
+
skipped, an unmatched PDI is ignored, characters inside embeddings and overrides
|
|
13
|
+
count, numbers are weak and a paragraph separator closes open isolates; and
|
|
14
|
+
`eastAsianWidth(codePoint)`, the `East_Asian_Width` of a code point (UAX #11) as
|
|
15
|
+
`"F"`, `"H"`, `"W"`, `"Na"`, `"A"` or `"N"`, unassigned code points included,
|
|
16
|
+
O(1) below U+0800 and O(log r) above. Classes and widths come from the Unicode
|
|
17
|
+
17.0.0 Character Database, so the package's licence is
|
|
18
|
+
`BSD-3-Clause AND Unicode-3.0`.
|
|
19
|
+
|
|
20
|
+
`@ac-kit/core` no longer exports `normalizeDisplayText`,
|
|
21
|
+
`NormalizeDisplayTextOptions`, `stripDiacritics`, `slugify` or `SlugifyOptions`.
|
|
22
|
+
Their behaviour is unchanged: import them from `@ac-kit/text-unicode` instead.
|
|
23
|
+
|
|
24
|
+
`@ac-kit/format-monospace` reads widths through `eastAsianWidth`; the widths it
|
|
25
|
+
computes are unchanged and it no longer depends on `@ac-kit/algo`.
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [34e8cfa]
|
|
30
|
+
- Updated dependencies [34e8cfa]
|
|
31
|
+
- Updated dependencies [34e8cfa]
|
|
32
|
+
- Updated dependencies [34e8cfa]
|
|
33
|
+
- Updated dependencies [34e8cfa]
|
|
34
|
+
- Updated dependencies [34e8cfa]
|
|
35
|
+
- Updated dependencies [34e8cfa]
|
|
36
|
+
- Updated dependencies [34e8cfa]
|
|
37
|
+
- Updated dependencies [34e8cfa]
|
|
38
|
+
- Updated dependencies [34e8cfa]
|
|
39
|
+
- Updated dependencies [34e8cfa]
|
|
40
|
+
- Updated dependencies [34e8cfa]
|
|
41
|
+
- Updated dependencies [34e8cfa]
|
|
42
|
+
- Updated dependencies [34e8cfa]
|
|
43
|
+
- Updated dependencies [34e8cfa]
|
|
44
|
+
- Updated dependencies [34e8cfa]
|
|
45
|
+
- Updated dependencies [34e8cfa]
|
|
46
|
+
- Updated dependencies [34e8cfa]
|
|
47
|
+
- Updated dependencies [34e8cfa]
|
|
48
|
+
- Updated dependencies [34e8cfa]
|
|
49
|
+
- Updated dependencies [34e8cfa]
|
|
50
|
+
- @ac-kit/algo@0.5.0
|
|
51
|
+
- @ac-kit/core@0.12.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Anthony Champagne and contributors
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29
|
+
|
|
30
|
+
--------------------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
Portions of this package (src/bidi/_bidi-classes.ts,
|
|
33
|
+
src/width/_east-asian-width-runs.ts, and the test cases in
|
|
34
|
+
src/bidi/__fixtures__/bidi-auto-levels.ts) are derived from the Unicode
|
|
35
|
+
Character Database (https://www.unicode.org/ucd/), under the following licence:
|
|
36
|
+
|
|
37
|
+
UNICODE LICENSE V3
|
|
38
|
+
|
|
39
|
+
COPYRIGHT AND PERMISSION NOTICE
|
|
40
|
+
|
|
41
|
+
Copyright © 1991-2025 Unicode, Inc.
|
|
42
|
+
|
|
43
|
+
NOTICE TO USER: Carefully read the following legal agreement. BY
|
|
44
|
+
DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
|
|
45
|
+
SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
|
|
46
|
+
TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT
|
|
47
|
+
DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
|
|
48
|
+
|
|
49
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
|
50
|
+
copy of data files and any associated documentation (the "Data Files") or
|
|
51
|
+
software and any associated documentation (the "Software") to deal in the
|
|
52
|
+
Data Files or Software without restriction, including without limitation
|
|
53
|
+
the rights to use, copy, modify, merge, publish, distribute, and/or sell
|
|
54
|
+
copies of the Data Files or Software, and to permit persons to whom the
|
|
55
|
+
Data Files or Software are furnished to do so, provided that either (a)
|
|
56
|
+
this copyright and permission notice appear with all copies of the Data
|
|
57
|
+
Files or Software, or (b) this copyright and permission notice appear in
|
|
58
|
+
associated Documentation.
|
|
59
|
+
|
|
60
|
+
THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
|
61
|
+
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
62
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
|
63
|
+
THIRD PARTY RIGHTS.
|
|
64
|
+
|
|
65
|
+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE
|
|
66
|
+
BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES,
|
|
67
|
+
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
68
|
+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
69
|
+
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA
|
|
70
|
+
FILES OR SOFTWARE.
|
|
71
|
+
|
|
72
|
+
Except as contained in this notice, the name of a copyright holder shall
|
|
73
|
+
not be used in advertising or otherwise to promote the sale, use or other
|
|
74
|
+
dealings in these Data Files or Software without prior written
|
|
75
|
+
authorization of the copyright holder.
|
package/README.md
CHANGED
|
@@ -1,3 +1,52 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ac-kit/text-unicode
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Text by Unicode character properties and UAX algorithms. A function belongs
|
|
4
|
+
here when its contract is stated in Unicode character properties or a UAX/UTS
|
|
5
|
+
algorithm — a table, `\p{…}`, `normalize()` or `Intl.Segmenter` alike.
|
|
6
|
+
Encoding-level code (UTF-16 units, surrogates, code points, UTF codecs) stays in
|
|
7
|
+
`@ac-kit/core`. This package never reimplements `Intl.Collator`,
|
|
8
|
+
`String.prototype.normalize` or `Intl.Segmenter`.
|
|
9
|
+
|
|
10
|
+
Portable: no Node.js built-ins; depends on `@ac-kit/core` and `@ac-kit/algo` only.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import {
|
|
14
|
+
eastAsianWidth,
|
|
15
|
+
firstStrongDirection,
|
|
16
|
+
normalizeDisplayText,
|
|
17
|
+
slugify,
|
|
18
|
+
stripDiacritics,
|
|
19
|
+
} from "@ac-kit/text-unicode";
|
|
20
|
+
|
|
21
|
+
firstStrongDirection("שלום, world"); // "rtl"
|
|
22
|
+
eastAsianWidth(0x4e2d); // "W"
|
|
23
|
+
normalizeDisplayText(" Ann\u202E\u200B Lee "); // "Ann Lee"
|
|
24
|
+
stripDiacritics("Café à la mode"); // "Cafe a la mode"
|
|
25
|
+
slugify("Crème brûlée"); // "creme-brulee"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- `firstStrongDirection` gives the direction of a text's first strong
|
|
29
|
+
character, `"ltr"`, `"rtl"` or `undefined`, skipping isolates (UAX #9 rule
|
|
30
|
+
P2): HTML's `dir="auto"` rule, for a Canvas 2D `direction` that has no
|
|
31
|
+
`"auto"`.
|
|
32
|
+
- `eastAsianWidth` is the `East_Asian_Width` of a code point (UAX #11): `"F"`,
|
|
33
|
+
`"H"`, `"W"`, `"Na"`, `"A"` or `"N"`, defaults of unassigned code points
|
|
34
|
+
included. A terminal draws `"W"` and `"F"` in two columns.
|
|
35
|
+
- `normalizeDisplayText` makes free text fit to show on one line: controls,
|
|
36
|
+
bidirectional overrides and zero-width characters removed, whitespace
|
|
37
|
+
collapsed, length capped.
|
|
38
|
+
- `stripDiacritics` folds accented letters onto their base letters, and
|
|
39
|
+
`slugify` makes a lowercase ASCII slug, safe as a URL segment and a file
|
|
40
|
+
name.
|
|
41
|
+
|
|
42
|
+
See the
|
|
43
|
+
[generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/text-unicode/)
|
|
44
|
+
for the full reference.
|
|
45
|
+
|
|
46
|
+
## Credits and licence
|
|
47
|
+
|
|
48
|
+
The code is `BSD-3-Clause`. The bidi class and East Asian width tables, and the
|
|
49
|
+
bidi test cases, are generated from the
|
|
50
|
+
[Unicode Character Database](https://www.unicode.org/ucd/) (17.0.0, Unicode
|
|
51
|
+
License V3, Copyright © 1991-2025 Unicode, Inc.), whose notice is in `LICENSE`;
|
|
52
|
+
the package's licence is `BSD-3-Clause AND Unicode-3.0`.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** A property of every code point, decoded from a generated run table. */
|
|
2
|
+
export type CodePointRuns = {
|
|
3
|
+
readonly runStarts: Uint32Array;
|
|
4
|
+
readonly runKinds: Uint8Array;
|
|
5
|
+
readonly direct: Uint8Array;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Decodes a table of runs of consecutive code points sharing one value, as the
|
|
9
|
+
* generators write it: comma-separated runs, each the value's digit followed by
|
|
10
|
+
* the run's first code point minus the previous run's, in base 36 (the first
|
|
11
|
+
* run starts at U+0000).
|
|
12
|
+
*/
|
|
13
|
+
export declare function decodeCodePointRuns(encoded: string): CodePointRuns;
|
|
14
|
+
/**
|
|
15
|
+
* The value of `codePoint`: O(1) below U+0800, O(log r) above, r the number of
|
|
16
|
+
* runs.
|
|
17
|
+
*/
|
|
18
|
+
export declare function lookupCodePointRun(runs: CodePointRuns, codePoint: number): number;
|
|
19
|
+
//# sourceMappingURL=_code-point-runs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_code-point-runs.d.ts","sourceRoot":"","sources":["../src/_code-point-runs.ts"],"names":[],"mappings":"AAOA,0EAA0E;AAC1E,MAAM,MAAM,aAAa,GAAG;IAC3B,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;CAC5B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CAoBlE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CACjC,IAAI,EAAE,aAAa,EACnB,SAAS,EAAE,MAAM,GACf,MAAM,CAYR"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { binarySearch } from "@ac-kit/algo";
|
|
2
|
+
const RUN_RADIX_ = 36;
|
|
3
|
+
// Latin, Greek, Cyrillic, Armenian, Hebrew, Arabic, Syriac and Thaana are
|
|
4
|
+
// looked up directly, the rest by binary search over the runs.
|
|
5
|
+
const DIRECT_LOOKUP_END_ = 2048;
|
|
6
|
+
/**
|
|
7
|
+
* Decodes a table of runs of consecutive code points sharing one value, as the
|
|
8
|
+
* generators write it: comma-separated runs, each the value's digit followed by
|
|
9
|
+
* the run's first code point minus the previous run's, in base 36 (the first
|
|
10
|
+
* run starts at U+0000).
|
|
11
|
+
*/
|
|
12
|
+
export function decodeCodePointRuns(encoded) {
|
|
13
|
+
const runs = encoded.split(",");
|
|
14
|
+
const runStarts = new Uint32Array(runs.length);
|
|
15
|
+
const runKinds = new Uint8Array(runs.length);
|
|
16
|
+
let start = 0;
|
|
17
|
+
for (let index = 0; index < runs.length; index++) {
|
|
18
|
+
const run = runs[index] ?? "";
|
|
19
|
+
start += Number.parseInt(run.slice(1), RUN_RADIX_);
|
|
20
|
+
runStarts[index] = start;
|
|
21
|
+
runKinds[index] = run.charCodeAt(0) - 0x30;
|
|
22
|
+
}
|
|
23
|
+
const direct = new Uint8Array(DIRECT_LOOKUP_END_);
|
|
24
|
+
for (let index = 0; index < runs.length; index++) {
|
|
25
|
+
const runStart = runStarts[index] ?? 0;
|
|
26
|
+
if (runStart >= DIRECT_LOOKUP_END_) {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
direct.fill(runKinds[index] ?? 0, runStart);
|
|
30
|
+
}
|
|
31
|
+
return { runStarts, runKinds, direct };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The value of `codePoint`: O(1) below U+0800, O(log r) above, r the number of
|
|
35
|
+
* runs.
|
|
36
|
+
*/
|
|
37
|
+
export function lookupCodePointRun(runs, codePoint) {
|
|
38
|
+
if (codePoint < DIRECT_LOOKUP_END_) {
|
|
39
|
+
return runs.direct[codePoint] ?? 0;
|
|
40
|
+
}
|
|
41
|
+
const { runStarts, runKinds } = runs;
|
|
42
|
+
// The first run starting after the code point, less one; run 0 starts at 0.
|
|
43
|
+
const after = binarySearch(0, runStarts.length, (index) => (runStarts[index] ?? 0) <= codePoint);
|
|
44
|
+
return runKinds[after - 1] ?? 0;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=_code-point-runs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_code-point-runs.js","sourceRoot":"","sources":["../src/_code-point-runs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,0EAA0E;AAC1E,+DAA+D;AAC/D,MAAM,kBAAkB,GAAG,IAAM,CAAC;AASlC;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe;IAClD,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,SAAS,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC7C,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAClD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAC9B,KAAK,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;QACnD,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;QACzB,QAAQ,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAC5C,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAClD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAClD,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,QAAQ,IAAI,kBAAkB,EAAE,CAAC;YACpC,MAAM;QACP,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AACxC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CACjC,IAAmB,EACnB,SAAiB;IAEjB,IAAI,SAAS,GAAG,kBAAkB,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IACD,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IACrC,4EAA4E;IAC5E,MAAM,KAAK,GAAG,YAAY,CACzB,CAAC,EACD,SAAS,CAAC,MAAM,EAChB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,SAAS,CAC/C,CAAC;IACF,OAAO,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/*! Derived from the Unicode Character Database 17.0.0, Copyright © 1991-2025 Unicode, Inc., Unicode License V3 — see LICENSE. */
|
|
2
|
+
declare const _default = "00,3a,01,32,01,3e,03,1y,0q,16,0q,3a,01,110,01,1a,01,14,01,15,0n,11,0v,11,0ch,12,07,1e,02,1e,05,19,01,13l,04,12,08,11,05,12,01,11,032,11,03w,17,074,11,02,23,01,219,01,21,01,22,01,22,01,21,01k,28,01,22,01,21,01,2d,01c,2y,03,21,02t,2f,02,27,02,2a,0n,21,0u,2r,02j,2b,01m,29,02,24,03,21,0o,24,01,29,01,23,01,25,017,23,01g,22,05,29,016,11l,01j,11,01,11,04,18,04,11,03,17,0a,12,0t,11,01m,11,04,14,08,11,0k,12,0e,12,07,11,02,11,02,12,01l,11,04,12,04,12,02,13,03,11,0u,12,03,11,0b,12,01l,11,04,15,01,12,04,11,0k,12,0d,11,08,16,01,11,01m,11,02,11,01,14,08,11,07,12,0b,12,0u,11,01p,11,0c,11,011,18,05,11,03,11,01j,11,01,13,05,13,01,14,07,12,0b,12,0k,17,02,11,01m,11,0f,12,0k,12,0s,12,01l,12,04,14,08,11,0k,12,0t,11,020,11,07,13,01,11,02i,11,02,17,04,11,07,18,02q,11,02,19,0b,17,021,12,0r,11,01,11,01,15,01f,1e,01,15,01,12,05,1b,01,110,09,11,02u,14,01,16,01,12,02,12,0p,12,04,13,0g,14,0d,11,02,12,06,11,0f,11,0jj,13,01c,1a,02u,11,0hr,11,0q,12,039,13,0t,12,0u,12,0u,12,01s,12,01,17,08,11,02,1b,07,11,01,11,0i,1a,06,1g,039,12,0y,11,03a,13,04,12,09,11,06,13,04,11,03,12,048,1y,0n,12,02,11,01m,11,01,17,01,11,01,11,02,18,06,1a,02,11,01c,11a,02,1c,0k,14,01c,11,01,15,01,11,05,11,014,19,0c,12,0w,14,02,12,01,13,01k,11,01,12,03,11,01,13,01m,18,02,12,048,13,01,1d,01,17,04,11,06,11,03,12,05i,11s,0cd,11,01,13,0b,13,0d,13,0d,13,0d,12,01,1e,21,01,3p,01,41o,53,01,17,03,1b,01,1f,0h,129,0f,12,01,14,01,12,0a,11,01,13,05,16,01,11,01,11,01,11,04,11,0b,12,04,15,05,14,02,1g,015,13,04,1bq,01x,1q,01,144,0m,1b,0l,11o,026,1ci,01,19f,074,1hg,02,13u,06d,16,04,13,07,17,03j,11,02o,13i,0y,1q,01,12h,0c,15y,0q,1l,03,1p,09,14,02,11,05,12,05,13,02h,14,03,11,02i,11,05g,112,09,11,019,12,01d,1g,0s,13,01e,1f,0c,14,04n,14,02r,12,0v,11,0534,11s,0h3k,11j,092,13,02n,1h,0u,12,028,12,0e,1y,02u,11,03d,11,03,11,04,11,0p,12,01,15,0b,12,01m,14,024,12,0q,1i,0d,11,012,18,0p,1b,01a,13,01c,11,02,14,02,12,013,11,01v,16,02,12,02,12,0c,11,08,11,01b,11,01f,11,01,13,02,12,05,12,01,11,016,12,08,11,037,12,03d,11,02,11,04,11,2fn3,01,21,0a,21,049,2g,0a3,2i,01s,22,01i,214,0d,1t,06,11f,01,1j,01,14,24,03z,11,01,1w,0q,16,0q,1b,03e,17,01,17,01,1g,075,11,01q,125,03,1d,03,11,02k,11,06a,1s,03e,15,2w5,07z,21,069,23,01,22,05,24,014,23,04,21,04l,22,02a,27,0dg,24,08,2a,06,2a,0v,26,06p,2v,018,22,0z,29,0x,26,01y,2b,01d,24,13e,01,11,01i,1f,0b,1k,0a,11,02,12,0a,13,01d,14,02,12,07,11,01p,13,010,15,01,18,01q,11,0c,12,01g,19,0a,14,02,11,02n,13,02,11,01,12,06,11,02,11,04d,11,03,18,0l,12,01l,12,03,11,011,17,03,15,01y,16,0d,11,01,11,01,11,0e,12,02d,18,02,13,01,11,0n,11,02c,16,01,11,04,12,01,12,06m,14,06,12,01,12,0r,12,02d,18,02,11,01,12,0v,1d,01q,11,01,11,02,16,01,11,02t,11,01,11,02,14,01,15,077,19,01,12,074,12,01,11,04,11,040,14,02,12,04,11,0w,16,02,12,014,16,02,14,08,11,09,16,02,13,01a,1d,01,12,05i,11,01,13,01,11,05l,17,01,16,02c,1m,02,17,01,12,01,12,03e,16,03,11,01,12,01,17,01,11,020,12,03,11,01,11,09n,12,0b,12,01g,15,05,11,01,11,0n,11,03e,1t,040e,11,06,1f,08ug,1c,03,13,01xc,15,01n,17,0t4,11,01r,14,027,11,01,11,0f5k,12,01,14,0318,15y,0q,1d,03,1c4,06,1n,0f,1h,0f,11a,02,1n,0f4,13,09,1g,02,17,0u,14,01n,12,0l,11y,056,12f,0oa,11,0p,11,0v,11,0p,11,0v,11,0p,11,0v,11,0p,11,0v,11,0p,11,0a,11e,0e8,11j,04,11e,08,11,0e,11,0m,15,01,1f,011s,17,01,1h,02,17,01,12,01,15,02s,11,04g,17,0af,11,01p,14,0f,11,0do,14,072,12,06r,11,02,11,07,12,05,11,27e,05s,27,031,27,0145,22,07i,118,04,12s,0c,1f,02,1f,01,1f,01,111,0a,1g,0v,11,01m,16,01p,11,04y,16,04a,1rd,03,1h,03,1d,03,162,06,1c,04,11,0f,1c,04,11k,08,1a,06,114,08,1u,02,1c,04,12,0e,19,013,19k,08,1e,02,1d,03,1b,03,11l,01,11,04,1g,02,1c,04,1a,07,143,01,12v,0sj,12,01eke,12,01eke,12,01eke,12,01eke,12,01eke,12,01eke,12,01eke,12,01eke,12,01eke,12,01eke,12,01eke,12,01eke,135u,01bem,12,01eke,12,01eke";
|
|
3
|
+
export default _default;
|
|
4
|
+
//# sourceMappingURL=_bidi-classes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_bidi-classes.d.ts","sourceRoot":"","sources":["../../src/bidi/_bidi-classes.ts"],"names":[],"mappings":"AAAA,iIAAiI"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*! Derived from the Unicode Character Database 17.0.0, Copyright © 1991-2025 Unicode, Inc., Unicode License V3 — see LICENSE. */
|
|
2
|
+
// Generated by `yarn workspace @ac-kit/text-unicode run generate:unicode-tables`
|
|
3
|
+
// from https://www.unicode.org/Public/17.0.0/ucd/extracted/DerivedBidiClass.txt (Unicode 17.0.0). Do not edit by hand.
|
|
4
|
+
//
|
|
5
|
+
// The Bidi_Class of every code point, U+0000 to U+10FFFF, reduced to what
|
|
6
|
+
// `firstStrongDirection` reads, as 1136 runs of consecutive code points
|
|
7
|
+
// of one kind. Runs are comma-separated; each is its kind's digit followed by
|
|
8
|
+
// its first code point minus the previous run's, in base 36 (the first run
|
|
9
|
+
// starts at U+0000). Kinds:
|
|
10
|
+
// 0: any other class (weak, neutral, explicit embeddings)
|
|
11
|
+
// 1: L
|
|
12
|
+
// 2: R, AL
|
|
13
|
+
// 3: B (paragraph separator)
|
|
14
|
+
// 4: LRI, RLI, FSI (isolate initiators)
|
|
15
|
+
// 5: PDI
|
|
16
|
+
export default "00,3a,01,32,01,3e,03,1y,0q,16,0q,3a,01,110,01,1a,01,14,01,15,0n,11,0v,11,0ch,12,07,1e,02,1e,05,19,01,13l,04,12,08,11,05,12,01,11,032,11,03w,17,074,11,02,23,01,219,01,21,01,22,01,22,01,21,01k,28,01,22,01,21,01,2d,01c,2y,03,21,02t,2f,02,27,02,2a,0n,21,0u,2r,02j,2b,01m,29,02,24,03,21,0o,24,01,29,01,23,01,25,017,23,01g,22,05,29,016,11l,01j,11,01,11,04,18,04,11,03,17,0a,12,0t,11,01m,11,04,14,08,11,0k,12,0e,12,07,11,02,11,02,12,01l,11,04,12,04,12,02,13,03,11,0u,12,03,11,0b,12,01l,11,04,15,01,12,04,11,0k,12,0d,11,08,16,01,11,01m,11,02,11,01,14,08,11,07,12,0b,12,0u,11,01p,11,0c,11,011,18,05,11,03,11,01j,11,01,13,05,13,01,14,07,12,0b,12,0k,17,02,11,01m,11,0f,12,0k,12,0s,12,01l,12,04,14,08,11,0k,12,0t,11,020,11,07,13,01,11,02i,11,02,17,04,11,07,18,02q,11,02,19,0b,17,021,12,0r,11,01,11,01,15,01f,1e,01,15,01,12,05,1b,01,110,09,11,02u,14,01,16,01,12,02,12,0p,12,04,13,0g,14,0d,11,02,12,06,11,0f,11,0jj,13,01c,1a,02u,11,0hr,11,0q,12,039,13,0t,12,0u,12,0u,12,01s,12,01,17,08,11,02,1b,07,11,01,11,0i,1a,06,1g,039,12,0y,11,03a,13,04,12,09,11,06,13,04,11,03,12,048,1y,0n,12,02,11,01m,11,01,17,01,11,01,11,02,18,06,1a,02,11,01c,11a,02,1c,0k,14,01c,11,01,15,01,11,05,11,014,19,0c,12,0w,14,02,12,01,13,01k,11,01,12,03,11,01,13,01m,18,02,12,048,13,01,1d,01,17,04,11,06,11,03,12,05i,11s,0cd,11,01,13,0b,13,0d,13,0d,13,0d,12,01,1e,21,01,3p,01,41o,53,01,17,03,1b,01,1f,0h,129,0f,12,01,14,01,12,0a,11,01,13,05,16,01,11,01,11,01,11,04,11,0b,12,04,15,05,14,02,1g,015,13,04,1bq,01x,1q,01,144,0m,1b,0l,11o,026,1ci,01,19f,074,1hg,02,13u,06d,16,04,13,07,17,03j,11,02o,13i,0y,1q,01,12h,0c,15y,0q,1l,03,1p,09,14,02,11,05,12,05,13,02h,14,03,11,02i,11,05g,112,09,11,019,12,01d,1g,0s,13,01e,1f,0c,14,04n,14,02r,12,0v,11,0534,11s,0h3k,11j,092,13,02n,1h,0u,12,028,12,0e,1y,02u,11,03d,11,03,11,04,11,0p,12,01,15,0b,12,01m,14,024,12,0q,1i,0d,11,012,18,0p,1b,01a,13,01c,11,02,14,02,12,013,11,01v,16,02,12,02,12,0c,11,08,11,01b,11,01f,11,01,13,02,12,05,12,01,11,016,12,08,11,037,12,03d,11,02,11,04,11,2fn3,01,21,0a,21,049,2g,0a3,2i,01s,22,01i,214,0d,1t,06,11f,01,1j,01,14,24,03z,11,01,1w,0q,16,0q,1b,03e,17,01,17,01,1g,075,11,01q,125,03,1d,03,11,02k,11,06a,1s,03e,15,2w5,07z,21,069,23,01,22,05,24,014,23,04,21,04l,22,02a,27,0dg,24,08,2a,06,2a,0v,26,06p,2v,018,22,0z,29,0x,26,01y,2b,01d,24,13e,01,11,01i,1f,0b,1k,0a,11,02,12,0a,13,01d,14,02,12,07,11,01p,13,010,15,01,18,01q,11,0c,12,01g,19,0a,14,02,11,02n,13,02,11,01,12,06,11,02,11,04d,11,03,18,0l,12,01l,12,03,11,011,17,03,15,01y,16,0d,11,01,11,01,11,0e,12,02d,18,02,13,01,11,0n,11,02c,16,01,11,04,12,01,12,06m,14,06,12,01,12,0r,12,02d,18,02,11,01,12,0v,1d,01q,11,01,11,02,16,01,11,02t,11,01,11,02,14,01,15,077,19,01,12,074,12,01,11,04,11,040,14,02,12,04,11,0w,16,02,12,014,16,02,14,08,11,09,16,02,13,01a,1d,01,12,05i,11,01,13,01,11,05l,17,01,16,02c,1m,02,17,01,12,01,12,03e,16,03,11,01,12,01,17,01,11,020,12,03,11,01,11,09n,12,0b,12,01g,15,05,11,01,11,0n,11,03e,1t,040e,11,06,1f,08ug,1c,03,13,01xc,15,01n,17,0t4,11,01r,14,027,11,01,11,0f5k,12,01,14,0318,15y,0q,1d,03,1c4,06,1n,0f,1h,0f,11a,02,1n,0f4,13,09,1g,02,17,0u,14,01n,12,0l,11y,056,12f,0oa,11,0p,11,0v,11,0p,11,0v,11,0p,11,0v,11,0p,11,0v,11,0p,11,0a,11e,0e8,11j,04,11e,08,11,0e,11,0m,15,01,1f,011s,17,01,1h,02,17,01,12,01,15,02s,11,04g,17,0af,11,01p,14,0f,11,0do,14,072,12,06r,11,02,11,07,12,05,11,27e,05s,27,031,27,0145,22,07i,118,04,12s,0c,1f,02,1f,01,1f,01,111,0a,1g,0v,11,01m,16,01p,11,04y,16,04a,1rd,03,1h,03,1d,03,162,06,1c,04,11,0f,1c,04,11k,08,1a,06,114,08,1u,02,1c,04,12,0e,19,013,19k,08,1e,02,1d,03,1b,03,11l,01,11,04,1g,02,1c,04,1a,07,143,01,12v,0sj,12,01eke,12,01eke,12,01eke,12,01eke,12,01eke,12,01eke,12,01eke,12,01eke,12,01eke,12,01eke,12,01eke,12,01eke,135u,01bem,12,01eke,12,01eke";
|
|
17
|
+
//# sourceMappingURL=_bidi-classes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_bidi-classes.js","sourceRoot":"","sources":["../../src/bidi/_bidi-classes.ts"],"names":[],"mappings":"AAAA,iIAAiI;AACjI,iFAAiF;AACjF,uHAAuH;AACvH,EAAE;AACF,0EAA0E;AAC1E,wEAAwE;AACxE,8EAA8E;AAC9E,2EAA2E;AAC3E,4BAA4B;AAC5B,0DAA0D;AAC1D,OAAO;AACP,WAAW;AACX,6BAA6B;AAC7B,wCAAwC;AACxC,SAAS;AACT,eAAe,6lHAA6lH,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The direction of the first strong character of `text`: `"ltr"` for Unicode
|
|
3
|
+
* bidirectional class L, `"rtl"` for R or AL, `undefined` when there is none
|
|
4
|
+
* (empty text, digits, punctuation, symbols). It is how HTML's `dir="auto"`
|
|
5
|
+
* picks a direction ([text node
|
|
6
|
+
* directionality](https://html.spec.whatwg.org/multipage/dom.html#text-node-directionality),
|
|
7
|
+
* HTML §3.2.6.4), and what Canvas 2D lacks, its `direction` taking no `"auto"`:
|
|
8
|
+
* resolve it here, then let the renderer's bidirectional algorithm order the
|
|
9
|
+
* text.
|
|
10
|
+
*
|
|
11
|
+
* Characters inside an isolate are skipped, as UAX #9 rule P2 does when it
|
|
12
|
+
* finds a paragraph's direction (and as HTML skips `<bdi>` and elements with a
|
|
13
|
+
* `dir` attribute): from LRI, RLI or FSI to its matching PDI, nested isolates
|
|
14
|
+
* included, or to the end of the paragraph when unmatched. A PDI with no
|
|
15
|
+
* initiator open is ignored. Embeddings and overrides (LRE, RLE, LRO, RLO, PDF)
|
|
16
|
+
* are not skipped: their controls are not strong and the characters inside them
|
|
17
|
+
* count, so `"\u202Eabc"` is `"ltr"` (P2, "embedding initiators (but not
|
|
18
|
+
* characters within the embedding) are ignored"). A paragraph separator (class
|
|
19
|
+
* B: line feed, carriage return, U+001C–U+001E, U+0085, U+2029) closes every
|
|
20
|
+
* open isolate (UAX #9 X8), and the search goes on into the next paragraph, as
|
|
21
|
+
* HTML's rule scans the whole text. Numbers are weak (EN, AN), so `"123 שלום"`
|
|
22
|
+
* is `"rtl"` and `"١٢٣"` is `undefined`.
|
|
23
|
+
*
|
|
24
|
+
* Classes are those of the Unicode Character Database (17.0.0), defaults
|
|
25
|
+
* included: an unassigned code point in a right-to-left block (Hebrew, Arabic,
|
|
26
|
+
* Phoenician…) is R or AL, elsewhere L; a private-use code point and a lone
|
|
27
|
+
* surrogate are L, as browsers treat them.
|
|
28
|
+
*
|
|
29
|
+
* Browsers differ on isolates in a text node: Chromium does not skip them for
|
|
30
|
+
* `dir="auto"`, while this function follows P2.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* firstStrongDirection("שלום, world"); // "rtl"
|
|
34
|
+
* firstStrongDirection("2024 — مرحبا"); // "rtl"
|
|
35
|
+
* firstStrongDirection("\u2067שלום\u2069 hello"); // "ltr", the isolate is skipped
|
|
36
|
+
* firstStrongDirection("42 %"); // undefined
|
|
37
|
+
*
|
|
38
|
+
* @param text The text, read by code point (a lone surrogate is one).
|
|
39
|
+
* @returns `"ltr"`, `"rtl"`, or `undefined` when no strong character lies
|
|
40
|
+
* outside an isolate. Complexity: O(n) time up to the first strong character,
|
|
41
|
+
* O(1) per code point below U+0800 and O(log r) above, r ≈ 1 100 runs of
|
|
42
|
+
* classes; O(1) memory, after about 8 KB of tables decoded on the first
|
|
43
|
+
* call.
|
|
44
|
+
*/
|
|
45
|
+
export declare function firstStrongDirection(text: string): "ltr" | "rtl" | undefined;
|
|
46
|
+
//# sourceMappingURL=first-strong-direction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"first-strong-direction.d.ts","sourceRoot":"","sources":["../../src/bidi/first-strong-direction.ts"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,CAoC5E"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { SUPPLEMENTARY_PLANE_START } from "@ac-kit/core";
|
|
2
|
+
import { decodeCodePointRuns, lookupCodePointRun, } from "../_code-point-runs.js";
|
|
3
|
+
import BIDI_CLASS_RUNS_ from "./_bidi-classes.js";
|
|
4
|
+
// Kinds as `_bidi-classes.ts` encodes them.
|
|
5
|
+
const LEFT_TO_RIGHT_ = 1;
|
|
6
|
+
const RIGHT_TO_LEFT_ = 2;
|
|
7
|
+
const PARAGRAPH_SEPARATOR_ = 3;
|
|
8
|
+
const ISOLATE_INITIATOR_ = 4;
|
|
9
|
+
const POP_DIRECTIONAL_ISOLATE_ = 5;
|
|
10
|
+
let tables_;
|
|
11
|
+
/**
|
|
12
|
+
* The direction of the first strong character of `text`: `"ltr"` for Unicode
|
|
13
|
+
* bidirectional class L, `"rtl"` for R or AL, `undefined` when there is none
|
|
14
|
+
* (empty text, digits, punctuation, symbols). It is how HTML's `dir="auto"`
|
|
15
|
+
* picks a direction ([text node
|
|
16
|
+
* directionality](https://html.spec.whatwg.org/multipage/dom.html#text-node-directionality),
|
|
17
|
+
* HTML §3.2.6.4), and what Canvas 2D lacks, its `direction` taking no `"auto"`:
|
|
18
|
+
* resolve it here, then let the renderer's bidirectional algorithm order the
|
|
19
|
+
* text.
|
|
20
|
+
*
|
|
21
|
+
* Characters inside an isolate are skipped, as UAX #9 rule P2 does when it
|
|
22
|
+
* finds a paragraph's direction (and as HTML skips `<bdi>` and elements with a
|
|
23
|
+
* `dir` attribute): from LRI, RLI or FSI to its matching PDI, nested isolates
|
|
24
|
+
* included, or to the end of the paragraph when unmatched. A PDI with no
|
|
25
|
+
* initiator open is ignored. Embeddings and overrides (LRE, RLE, LRO, RLO, PDF)
|
|
26
|
+
* are not skipped: their controls are not strong and the characters inside them
|
|
27
|
+
* count, so `"\u202Eabc"` is `"ltr"` (P2, "embedding initiators (but not
|
|
28
|
+
* characters within the embedding) are ignored"). A paragraph separator (class
|
|
29
|
+
* B: line feed, carriage return, U+001C–U+001E, U+0085, U+2029) closes every
|
|
30
|
+
* open isolate (UAX #9 X8), and the search goes on into the next paragraph, as
|
|
31
|
+
* HTML's rule scans the whole text. Numbers are weak (EN, AN), so `"123 שלום"`
|
|
32
|
+
* is `"rtl"` and `"١٢٣"` is `undefined`.
|
|
33
|
+
*
|
|
34
|
+
* Classes are those of the Unicode Character Database (17.0.0), defaults
|
|
35
|
+
* included: an unassigned code point in a right-to-left block (Hebrew, Arabic,
|
|
36
|
+
* Phoenician…) is R or AL, elsewhere L; a private-use code point and a lone
|
|
37
|
+
* surrogate are L, as browsers treat them.
|
|
38
|
+
*
|
|
39
|
+
* Browsers differ on isolates in a text node: Chromium does not skip them for
|
|
40
|
+
* `dir="auto"`, while this function follows P2.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* firstStrongDirection("שלום, world"); // "rtl"
|
|
44
|
+
* firstStrongDirection("2024 — مرحبا"); // "rtl"
|
|
45
|
+
* firstStrongDirection("\u2067שלום\u2069 hello"); // "ltr", the isolate is skipped
|
|
46
|
+
* firstStrongDirection("42 %"); // undefined
|
|
47
|
+
*
|
|
48
|
+
* @param text The text, read by code point (a lone surrogate is one).
|
|
49
|
+
* @returns `"ltr"`, `"rtl"`, or `undefined` when no strong character lies
|
|
50
|
+
* outside an isolate. Complexity: O(n) time up to the first strong character,
|
|
51
|
+
* O(1) per code point below U+0800 and O(log r) above, r ≈ 1 100 runs of
|
|
52
|
+
* classes; O(1) memory, after about 8 KB of tables decoded on the first
|
|
53
|
+
* call.
|
|
54
|
+
*/
|
|
55
|
+
export function firstStrongDirection(text) {
|
|
56
|
+
tables_ ??= decodeCodePointRuns(BIDI_CLASS_RUNS_);
|
|
57
|
+
const tables = tables_;
|
|
58
|
+
let isolateDepth = 0;
|
|
59
|
+
for (let index = 0; index < text.length; index++) {
|
|
60
|
+
const codePoint = text.codePointAt(index) ?? 0;
|
|
61
|
+
if (codePoint >= SUPPLEMENTARY_PLANE_START) {
|
|
62
|
+
index++;
|
|
63
|
+
}
|
|
64
|
+
switch (lookupCodePointRun(tables, codePoint)) {
|
|
65
|
+
case LEFT_TO_RIGHT_:
|
|
66
|
+
if (isolateDepth === 0) {
|
|
67
|
+
return "ltr";
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
case RIGHT_TO_LEFT_:
|
|
71
|
+
if (isolateDepth === 0) {
|
|
72
|
+
return "rtl";
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
case ISOLATE_INITIATOR_:
|
|
76
|
+
isolateDepth++;
|
|
77
|
+
break;
|
|
78
|
+
case POP_DIRECTIONAL_ISOLATE_:
|
|
79
|
+
if (isolateDepth > 0) {
|
|
80
|
+
isolateDepth--;
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
case PARAGRAPH_SEPARATOR_:
|
|
84
|
+
isolateDepth = 0;
|
|
85
|
+
break;
|
|
86
|
+
default:
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=first-strong-direction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"first-strong-direction.js","sourceRoot":"","sources":["../../src/bidi/first-strong-direction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAEzD,OAAO,EAEN,mBAAmB,EACnB,kBAAkB,GAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAElD,4CAA4C;AAC5C,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAEnC,IAAI,OAAkC,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAChD,OAAO,KAAK,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,OAAO,CAAC;IACvB,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAClD,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,SAAS,IAAI,yBAAyB,EAAE,CAAC;YAC5C,KAAK,EAAE,CAAC;QACT,CAAC;QACD,QAAQ,kBAAkB,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC;YAC/C,KAAK,cAAc;gBAClB,IAAI,YAAY,KAAK,CAAC,EAAE,CAAC;oBACxB,OAAO,KAAK,CAAC;gBACd,CAAC;gBACD,MAAM;YACP,KAAK,cAAc;gBAClB,IAAI,YAAY,KAAK,CAAC,EAAE,CAAC;oBACxB,OAAO,KAAK,CAAC;gBACd,CAAC;gBACD,MAAM;YACP,KAAK,kBAAkB;gBACtB,YAAY,EAAE,CAAC;gBACf,MAAM;YACP,KAAK,wBAAwB;gBAC5B,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;oBACtB,YAAY,EAAE,CAAC;gBAChB,CAAC;gBACD,MAAM;YACP,KAAK,oBAAoB;gBACxB,YAAY,GAAG,CAAC,CAAC;gBACjB,MAAM;YACP;gBACC,MAAM;QACR,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Options of {@link normalizeDisplayText}. */
|
|
2
|
+
export type NormalizeDisplayTextOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* The most UTF-16 code units kept, a surrogate pair never split: the text is
|
|
5
|
+
* cut there, then trimmed again. Unlimited when omitted.
|
|
6
|
+
*/
|
|
7
|
+
maxLength?: number;
|
|
8
|
+
/**
|
|
9
|
+
* Whether to keep the zero-width joiner and non-joiner (U+200D, U+200C),
|
|
10
|
+
* which join emoji sequences (👨👩👧) and shape Indic, Arabic and Persian
|
|
11
|
+
* script. `false` by default, so a name cannot hide them; every other format
|
|
12
|
+
* character goes either way.
|
|
13
|
+
*/
|
|
14
|
+
keepJoiners?: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* `text` made fit to show as one line — a display name, a title, a label typed
|
|
18
|
+
* by someone else: control and format characters and lone surrogates removed,
|
|
19
|
+
* every run of Unicode whitespace (line breaks included) made one space, the
|
|
20
|
+
* ends trimmed, and the length capped. Bidirectional overrides and zero-width
|
|
21
|
+
* characters, which make two texts look alike or reorder what is around them,
|
|
22
|
+
* are among what is removed.
|
|
23
|
+
*
|
|
24
|
+
* It does not make look-alike texts equal: Unicode normalization (`normalize`)
|
|
25
|
+
* and confusable detection are separate steps. Use `truncate` instead to cut
|
|
26
|
+
* text with an ellipsis.
|
|
27
|
+
*
|
|
28
|
+
* Time and memory are linear in `text`'s length.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* normalizeDisplayText(" Ada\u202E\n Lovelace\u0000 "); // "Ada Lovelace"
|
|
32
|
+
* normalizeDisplayText("Ada Lovelace", { maxLength: 4 }); // "Ada"
|
|
33
|
+
*
|
|
34
|
+
* @returns The normalized text; `""` when nothing visible is left.
|
|
35
|
+
* @throws {RangeError} When `maxLength` is negative or not an integer.
|
|
36
|
+
*/
|
|
37
|
+
export declare function normalizeDisplayText(text: string, options?: NormalizeDisplayTextOptions): string;
|
|
38
|
+
//# sourceMappingURL=normalize-display-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-display-text.d.ts","sourceRoot":"","sources":["../../src/display/normalize-display-text.ts"],"names":[],"mappings":"AAEA,+CAA+C;AAC/C,MAAM,MAAM,2BAA2B,GAAG;IACzC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAUF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CACnC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,2BAA2B,GACnC,MAAM,CA8BR"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { describeValue, isHighSurrogate } from "@ac-kit/core";
|
|
2
|
+
// Controls, format characters (bidirectional overrides, zero-width spaces,
|
|
3
|
+
// U+FEFF) and lone surrogates; whitespace controls (tab, line feed, U+0085) are
|
|
4
|
+
// left for the collapse, so that they still separate words.
|
|
5
|
+
const INVISIBLE_ = /(?!\p{White_Space})[\p{Cc}\p{Cf}\p{Cs}]/gu;
|
|
6
|
+
const INVISIBLE_BUT_JOINERS_ = /(?![\p{White_Space}\u200C\u200D])[\p{Cc}\p{Cf}\p{Cs}]/gu;
|
|
7
|
+
const WHITESPACE_RUN_ = /\p{White_Space}+/gu;
|
|
8
|
+
/**
|
|
9
|
+
* `text` made fit to show as one line — a display name, a title, a label typed
|
|
10
|
+
* by someone else: control and format characters and lone surrogates removed,
|
|
11
|
+
* every run of Unicode whitespace (line breaks included) made one space, the
|
|
12
|
+
* ends trimmed, and the length capped. Bidirectional overrides and zero-width
|
|
13
|
+
* characters, which make two texts look alike or reorder what is around them,
|
|
14
|
+
* are among what is removed.
|
|
15
|
+
*
|
|
16
|
+
* It does not make look-alike texts equal: Unicode normalization (`normalize`)
|
|
17
|
+
* and confusable detection are separate steps. Use `truncate` instead to cut
|
|
18
|
+
* text with an ellipsis.
|
|
19
|
+
*
|
|
20
|
+
* Time and memory are linear in `text`'s length.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* normalizeDisplayText(" Ada\u202E\n Lovelace\u0000 "); // "Ada Lovelace"
|
|
24
|
+
* normalizeDisplayText("Ada Lovelace", { maxLength: 4 }); // "Ada"
|
|
25
|
+
*
|
|
26
|
+
* @returns The normalized text; `""` when nothing visible is left.
|
|
27
|
+
* @throws {RangeError} When `maxLength` is negative or not an integer.
|
|
28
|
+
*/
|
|
29
|
+
export function normalizeDisplayText(text, options) {
|
|
30
|
+
const maxLength = options?.maxLength ?? Number.POSITIVE_INFINITY;
|
|
31
|
+
if (maxLength < 0 ||
|
|
32
|
+
(!Number.isInteger(maxLength) && maxLength !== Number.POSITIVE_INFINITY)) {
|
|
33
|
+
throw new RangeError(`maxLength must be a non-negative integer, got ${describeValue(maxLength)}`);
|
|
34
|
+
}
|
|
35
|
+
const normalized = text
|
|
36
|
+
.replaceAll(options?.keepJoiners === true ? INVISIBLE_BUT_JOINERS_ : INVISIBLE_, "")
|
|
37
|
+
.replaceAll(WHITESPACE_RUN_, " ")
|
|
38
|
+
.trim();
|
|
39
|
+
if (normalized.length <= maxLength) {
|
|
40
|
+
return normalized;
|
|
41
|
+
}
|
|
42
|
+
let end = maxLength;
|
|
43
|
+
const last = normalized.charCodeAt(end - 1);
|
|
44
|
+
// Lone surrogates are gone, so a high surrogate here starts a pair.
|
|
45
|
+
if (isHighSurrogate(last)) {
|
|
46
|
+
end--;
|
|
47
|
+
}
|
|
48
|
+
return normalized.slice(0, end).trimEnd();
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=normalize-display-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-display-text.js","sourceRoot":"","sources":["../../src/display/normalize-display-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAmB9D,2EAA2E;AAC3E,gFAAgF;AAChF,4DAA4D;AAC5D,MAAM,UAAU,GAAG,2CAA2C,CAAC;AAC/D,MAAM,sBAAsB,GAC3B,yDAAyD,CAAC;AAC3D,MAAM,eAAe,GAAG,oBAAoB,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,oBAAoB,CACnC,IAAY,EACZ,OAAqC;IAErC,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,MAAM,CAAC,iBAAiB,CAAC;IACjE,IACC,SAAS,GAAG,CAAC;QACb,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,SAAS,KAAK,MAAM,CAAC,iBAAiB,CAAC,EACvE,CAAC;QACF,MAAM,IAAI,UAAU,CACnB,iDAAiD,aAAa,CAAC,SAAS,CAAC,EAAE,CAC3E,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAG,IAAI;SACrB,UAAU,CACV,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,UAAU,EACnE,EAAE,CACF;SACA,UAAU,CAAC,eAAe,EAAE,GAAG,CAAC;SAChC,IAAI,EAAE,CAAC;IACT,IAAI,UAAU,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;QACpC,OAAO,UAAU,CAAC;IACnB,CAAC;IAED,IAAI,GAAG,GAAG,SAAS,CAAC;IACpB,MAAM,IAAI,GAAG,UAAU,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IAC5C,oEAAoE;IACpE,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,GAAG,EAAE,CAAC;IACP,CAAC;IAED,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type SlugifyOptions = {
|
|
2
|
+
/** Joins the retained runs. Defaults to `"-"`. */
|
|
3
|
+
separator?: string | null;
|
|
4
|
+
/** Returned when no alphanumeric character survives. Defaults to `""`. */
|
|
5
|
+
fallback?: string | null;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Lowercase ASCII slug of `input`: diacritics folded onto their base letters,
|
|
9
|
+
* every other run of characters collapsed into `separator`, and no leading or
|
|
10
|
+
* trailing separator.
|
|
11
|
+
*
|
|
12
|
+
* The result is safe both as a URL path segment and as a file name on every
|
|
13
|
+
* platform, since only `a-z`, `0-9` and `separator` survive.
|
|
14
|
+
*
|
|
15
|
+
* Letters Unicode defines no decomposition for (`Æ`, `Ø`, `Ł`, and every
|
|
16
|
+
* non-Latin script) have no ASCII base to fold onto and are dropped with the
|
|
17
|
+
* rest — a name written entirely in such letters yields `fallback`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function slugify(input: string, options?: SlugifyOptions): string;
|
|
20
|
+
//# sourceMappingURL=slugify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slugify.d.ts","sourceRoot":"","sources":["../../src/display/slugify.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,cAAc,GAAG;IAC5B,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAIF;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,MAAM,CAWvE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { stripDiacritics } from "../fold/strip-diacritics.js";
|
|
2
|
+
const NON_SLUG_RUN = /[^a-z0-9]+/;
|
|
3
|
+
/**
|
|
4
|
+
* Lowercase ASCII slug of `input`: diacritics folded onto their base letters,
|
|
5
|
+
* every other run of characters collapsed into `separator`, and no leading or
|
|
6
|
+
* trailing separator.
|
|
7
|
+
*
|
|
8
|
+
* The result is safe both as a URL path segment and as a file name on every
|
|
9
|
+
* platform, since only `a-z`, `0-9` and `separator` survive.
|
|
10
|
+
*
|
|
11
|
+
* Letters Unicode defines no decomposition for (`Æ`, `Ø`, `Ł`, and every
|
|
12
|
+
* non-Latin script) have no ASCII base to fold onto and are dropped with the
|
|
13
|
+
* rest — a name written entirely in such letters yields `fallback`.
|
|
14
|
+
*/
|
|
15
|
+
export function slugify(input, options) {
|
|
16
|
+
const parts = stripDiacritics(input)
|
|
17
|
+
.toLowerCase()
|
|
18
|
+
.split(NON_SLUG_RUN)
|
|
19
|
+
.filter((part) => part !== "");
|
|
20
|
+
if (parts.length === 0) {
|
|
21
|
+
return options?.fallback ?? "";
|
|
22
|
+
}
|
|
23
|
+
return parts.join(options?.separator ?? "-");
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=slugify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slugify.js","sourceRoot":"","sources":["../../src/display/slugify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAS9D,MAAM,YAAY,GAAG,YAAY,CAAC;AAElC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,OAAwB;IAC9D,MAAM,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC;SAClC,WAAW,EAAE;SACb,KAAK,CAAC,YAAY,CAAC;SACnB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;IAEhC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,OAAO,EAAE,QAAQ,IAAI,EAAE,CAAC;IAChC,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,IAAI,GAAG,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strips diacritics (accents) from `str` by decomposing each accented character
|
|
3
|
+
* into its base letter plus combining marks (Unicode compatibility
|
|
4
|
+
* decomposition, NFKD) and dropping the marks.
|
|
5
|
+
*
|
|
6
|
+
* Does not affect letters with no decomposition at all — ligatures and special
|
|
7
|
+
* letters like `Æ`, `Œ`, `Ø`, `Đ`, `Ł` pass through unchanged, since Unicode
|
|
8
|
+
* defines no decomposition (canonical or compatibility) for them.
|
|
9
|
+
*/
|
|
10
|
+
export declare function stripDiacritics(str: string): string;
|
|
11
|
+
//# sourceMappingURL=strip-diacritics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strip-diacritics.d.ts","sourceRoot":"","sources":["../../src/fold/strip-diacritics.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEnD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const COMBINING_MARK_PATTERN = /\p{Mn}/gu;
|
|
2
|
+
/**
|
|
3
|
+
* Strips diacritics (accents) from `str` by decomposing each accented character
|
|
4
|
+
* into its base letter plus combining marks (Unicode compatibility
|
|
5
|
+
* decomposition, NFKD) and dropping the marks.
|
|
6
|
+
*
|
|
7
|
+
* Does not affect letters with no decomposition at all — ligatures and special
|
|
8
|
+
* letters like `Æ`, `Œ`, `Ø`, `Đ`, `Ł` pass through unchanged, since Unicode
|
|
9
|
+
* defines no decomposition (canonical or compatibility) for them.
|
|
10
|
+
*/
|
|
11
|
+
export function stripDiacritics(str) {
|
|
12
|
+
return str.normalize("NFKD").replace(COMBINING_MARK_PATTERN, "");
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=strip-diacritics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strip-diacritics.js","sourceRoot":"","sources":["../../src/fold/strip-diacritics.ts"],"names":[],"mappings":"AAAA,MAAM,sBAAsB,GAAG,UAAU,CAAC;AAE1C;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW;IAC1C,OAAO,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC,CAAC;AAClE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./bidi/first-strong-direction.js";
|
|
2
|
+
export * from "./display/normalize-display-text.js";
|
|
3
|
+
export * from "./display/slugify.js";
|
|
4
|
+
export * from "./fold/strip-diacritics.js";
|
|
5
|
+
export * from "./width/east-asian-width.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,qCAAqC,CAAC;AACpD,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./bidi/first-strong-direction.js";
|
|
2
|
+
export * from "./display/normalize-display-text.js";
|
|
3
|
+
export * from "./display/slugify.js";
|
|
4
|
+
export * from "./fold/strip-diacritics.js";
|
|
5
|
+
export * from "./width/east-asian-width.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,qCAAqC,CAAC;AACpD,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/*! Derived from the Unicode Character Database 17.0.0, Copyright © 1991-2025 Unicode, Inc., Unicode License V3 — see LICENSE. */
|
|
2
|
+
declare const _default = "00,1w,02n,5y,11,52,11,52,02,51,01,11,51,12,51,05,51,05,51,04,56,01,59,01,56,02,55,04,54,01,51,03,51,02,52,01,51,02,53,04,51,01,51,01,52,01,5f,01,51,01,57,01,5a,02,53,01,55,03,54,01,56,04,51,01,53,04,51,01,54,02,5i,02,53,01,52q,01,51,01,51,01,51,01,51,01,51,01,51,01,51,01,538,01,5f,01,52q,01,52,01,51,03,51,01,52,01,57,04,51,01,51,01,5w,034,5x,0h,51,07,57,0h,51,07,51j,01,5e,01s,51,01,22i6,02o,52wg,01,52,04,51,02,52,02,52,03,51,04,58,01,51,02,51,01,55,01,52,01,51h,01,5a,01,51,04,410,01,52,01,52e,01,51,01,53,01,59,01,52,01,5a,02,53,01,54,01,513,02,56,04,51,0c,54,0a,5f,01,56,0a,5u,02,5o,01,51,01,5i,01,5o,01,51,02,53,02,52,01,53,01,51,01,53,01,54,01,52,04,52,01,51,01,51,06,51,01,55,04,54,02,5a,01,53,01,55,01,5d,02,52,04,52,02,52,02,5i,02,52,02,5d,01,53,01,5b,01,5p,01,52a,01,27,02,2d,02,25a,04,23,01,22,01,530,03u,51,02p,54,010,5c,0g,52,04,5a,02,51,07,58,02,52,02,54,02,52,02,54,03,52,01,52,04,5g,04,59,01,2d,02,56,02,52,01,54,02,24,02,56,01,51,01,2h,08,58,01,51,01,25,0c,5c,02,51,03,51,04,51,02,51,01,2f,01,2a,06,23,01,5a,02,21,01,28,02,2h,52,01,24,52,28,51,25,51,0d,51,01,54,22,51,27,52,21,51,24,51,22,51,02,25,01,24,02,2s,01,5k,01,2e,01,21,01,24,03,21,01,5u,0a,2l,03,2o,01,2e,01,112,08,1bb,02,2b8,02,21f,01,24,51,04,2me,0q,21,02h,2c,05y,2q,3g,21,01q,22,02e,22,02v,25,017,21,02m,21,02e,29,01c,21,514,28,0mkd,23,01j,2wp,0t,2hv,08mc,51ng,24xs,0e8,5lc,2g,0a,2m,0z,21,0j,21,04,345,42o,02m,43,06,42,06,42,06,42,03,33,07,41,07,5e,01,2m3m,05,2b,07,29,05p2,215,0w,22p,037,26pp,04,21,07,21,02,21,083,2f,01,2t,03,22,01,2e,04,28,0b0,26bo,02f,29,0n,25n1,01,25m,01,51c,0b,55,0u,52,01m,56,2u,51,22,5a,0i,22b,03,2d,018,24,09,27,02,2e,06,24a,0x,2c,09,21,01y,21,0m,2c,017,24,05,2c,0h,23,01,23,01z,21,01,21,057,22,01r,2d,04,21,0o,2i,01,2q,02,2d,01,22e,02d,21c,01y,26,01,23,03,22,04,23,04,2b,02,27,09,26b,0c,24,01,27v,01b,21,0a,21,055,234,0d,23,0b,23,01l,21,01,24,0g,22,0c,24,0a,2zr,01eke,22,01eke,5e1vm,06o,51e6o,01eke,52,01eke";
|
|
3
|
+
export default _default;
|
|
4
|
+
//# sourceMappingURL=_east-asian-width-runs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_east-asian-width-runs.d.ts","sourceRoot":"","sources":["../../src/width/_east-asian-width-runs.ts"],"names":[],"mappings":"AAAA,iIAAiI"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*! Derived from the Unicode Character Database 17.0.0, Copyright © 1991-2025 Unicode, Inc., Unicode License V3 — see LICENSE. */
|
|
2
|
+
// Generated by `yarn workspace @ac-kit/text-unicode run generate:unicode-tables`
|
|
3
|
+
// from https://www.unicode.org/Public/17.0.0/ucd/EastAsianWidth.txt (Unicode 17.0.0). Do not edit by hand.
|
|
4
|
+
//
|
|
5
|
+
// The East_Asian_Width of every code point, U+0000 to U+10FFFF, as 602
|
|
6
|
+
// runs of consecutive code points of one value. Runs are comma-separated; each
|
|
7
|
+
// is its value's digit followed by its first code point minus the previous
|
|
8
|
+
// run's, in base 36 (the first run starts at U+0000). Values:
|
|
9
|
+
// 0: N (neutral)
|
|
10
|
+
// 1: Na (narrow)
|
|
11
|
+
// 2: W (wide)
|
|
12
|
+
// 3: F (fullwidth)
|
|
13
|
+
// 4: H (halfwidth)
|
|
14
|
+
// 5: A (ambiguous)
|
|
15
|
+
export default "00,1w,02n,5y,11,52,11,52,02,51,01,11,51,12,51,05,51,05,51,04,56,01,59,01,56,02,55,04,54,01,51,03,51,02,52,01,51,02,53,04,51,01,51,01,52,01,5f,01,51,01,57,01,5a,02,53,01,55,03,54,01,56,04,51,01,53,04,51,01,54,02,5i,02,53,01,52q,01,51,01,51,01,51,01,51,01,51,01,51,01,51,01,538,01,5f,01,52q,01,52,01,51,03,51,01,52,01,57,04,51,01,51,01,5w,034,5x,0h,51,07,57,0h,51,07,51j,01,5e,01s,51,01,22i6,02o,52wg,01,52,04,51,02,52,02,52,03,51,04,58,01,51,02,51,01,55,01,52,01,51h,01,5a,01,51,04,410,01,52,01,52e,01,51,01,53,01,59,01,52,01,5a,02,53,01,54,01,513,02,56,04,51,0c,54,0a,5f,01,56,0a,5u,02,5o,01,51,01,5i,01,5o,01,51,02,53,02,52,01,53,01,51,01,53,01,54,01,52,04,52,01,51,01,51,06,51,01,55,04,54,02,5a,01,53,01,55,01,5d,02,52,04,52,02,52,02,5i,02,52,02,5d,01,53,01,5b,01,5p,01,52a,01,27,02,2d,02,25a,04,23,01,22,01,530,03u,51,02p,54,010,5c,0g,52,04,5a,02,51,07,58,02,52,02,54,02,52,02,54,03,52,01,52,04,5g,04,59,01,2d,02,56,02,52,01,54,02,24,02,56,01,51,01,2h,08,58,01,51,01,25,0c,5c,02,51,03,51,04,51,02,51,01,2f,01,2a,06,23,01,5a,02,21,01,28,02,2h,52,01,24,52,28,51,25,51,0d,51,01,54,22,51,27,52,21,51,24,51,22,51,02,25,01,24,02,2s,01,5k,01,2e,01,21,01,24,03,21,01,5u,0a,2l,03,2o,01,2e,01,112,08,1bb,02,2b8,02,21f,01,24,51,04,2me,0q,21,02h,2c,05y,2q,3g,21,01q,22,02e,22,02v,25,017,21,02m,21,02e,29,01c,21,514,28,0mkd,23,01j,2wp,0t,2hv,08mc,51ng,24xs,0e8,5lc,2g,0a,2m,0z,21,0j,21,04,345,42o,02m,43,06,42,06,42,06,42,03,33,07,41,07,5e,01,2m3m,05,2b,07,29,05p2,215,0w,22p,037,26pp,04,21,07,21,02,21,083,2f,01,2t,03,22,01,2e,04,28,0b0,26bo,02f,29,0n,25n1,01,25m,01,51c,0b,55,0u,52,01m,56,2u,51,22,5a,0i,22b,03,2d,018,24,09,27,02,2e,06,24a,0x,2c,09,21,01y,21,0m,2c,017,24,05,2c,0h,23,01,23,01z,21,01,21,057,22,01r,2d,04,21,0o,2i,01,2q,02,2d,01,22e,02d,21c,01y,26,01,23,03,22,04,23,04,2b,02,27,09,26b,0c,24,01,27v,01b,21,0a,21,055,234,0d,23,0b,23,01l,21,01,24,0g,22,0c,24,0a,2zr,01eke,22,01eke,5e1vm,06o,51e6o,01eke,52,01eke";
|
|
16
|
+
//# sourceMappingURL=_east-asian-width-runs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_east-asian-width-runs.js","sourceRoot":"","sources":["../../src/width/_east-asian-width-runs.ts"],"names":[],"mappings":"AAAA,iIAAiI;AACjI,iFAAiF;AACjF,2GAA2G;AAC3G,EAAE;AACF,uEAAuE;AACvE,+EAA+E;AAC/E,2EAA2E;AAC3E,8DAA8D;AAC9D,iBAAiB;AACjB,iBAAiB;AACjB,cAAc;AACd,mBAAmB;AACnB,mBAAmB;AACnB,mBAAmB;AACnB,eAAe,63DAA63D,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `East_Asian_Width` property of a code point ([UAX
|
|
3
|
+
* #11](https://www.unicode.org/reports/tr11/)): `"F"` fullwidth, `"H"`
|
|
4
|
+
* halfwidth, `"W"` wide, `"Na"` narrow, `"A"` ambiguous (narrow or wide
|
|
5
|
+
* depending on the context, as in East Asian legacy character sets), `"N"`
|
|
6
|
+
* neutral (every other code point).
|
|
7
|
+
*/
|
|
8
|
+
export type EastAsianWidth = "F" | "H" | "W" | "Na" | "A" | "N";
|
|
9
|
+
/**
|
|
10
|
+
* The `East_Asian_Width` of `codePoint`, from the Unicode Character Database
|
|
11
|
+
* (17.0.0), the defaults of unassigned code points included: an unassigned code
|
|
12
|
+
* point in a CJK ideograph block or plane 2 or 3 is `"W"`, any other `"N"`.
|
|
13
|
+
* Terminals draw `"W"` and `"F"` in two columns.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* eastAsianWidth(0x41); // "Na"
|
|
17
|
+
* eastAsianWidth(0x4e2d); // "W"
|
|
18
|
+
* eastAsianWidth(0xff21); // "F"
|
|
19
|
+
* eastAsianWidth(0xff71); // "H"
|
|
20
|
+
* eastAsianWidth(0xa1); // "A"
|
|
21
|
+
* eastAsianWidth(0x0e01); // "N"
|
|
22
|
+
*
|
|
23
|
+
* @param codePoint An integer from 0 to 0x10FFFF; a surrogate is `"N"`.
|
|
24
|
+
* @returns The width class. Complexity: O(1) below U+0800 and O(log r) above, r
|
|
25
|
+
* = 602 runs; O(1) memory, after about 5 KB of tables decoded on the first
|
|
26
|
+
* call.
|
|
27
|
+
* @throws {RangeError} If `codePoint` is not an integer from 0 to 0x10FFFF.
|
|
28
|
+
*/
|
|
29
|
+
export declare function eastAsianWidth(codePoint: number): EastAsianWidth;
|
|
30
|
+
//# sourceMappingURL=east-asian-width.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"east-asian-width.d.ts","sourceRoot":"","sources":["../../src/width/east-asian-width.ts"],"names":[],"mappings":"AAQA;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC;AAchE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,CAMhE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { isIntegerInRange, MAX_CODE_POINT } from "@ac-kit/core";
|
|
2
|
+
import { decodeCodePointRuns, lookupCodePointRun, } from "../_code-point-runs.js";
|
|
3
|
+
import EAST_ASIAN_WIDTH_RUNS_ from "./_east-asian-width-runs.js";
|
|
4
|
+
// In the order of the kinds `_east-asian-width-runs.ts` encodes them.
|
|
5
|
+
const EAST_ASIAN_WIDTHS_ = [
|
|
6
|
+
"N",
|
|
7
|
+
"Na",
|
|
8
|
+
"W",
|
|
9
|
+
"F",
|
|
10
|
+
"H",
|
|
11
|
+
"A",
|
|
12
|
+
];
|
|
13
|
+
let runs_;
|
|
14
|
+
/**
|
|
15
|
+
* The `East_Asian_Width` of `codePoint`, from the Unicode Character Database
|
|
16
|
+
* (17.0.0), the defaults of unassigned code points included: an unassigned code
|
|
17
|
+
* point in a CJK ideograph block or plane 2 or 3 is `"W"`, any other `"N"`.
|
|
18
|
+
* Terminals draw `"W"` and `"F"` in two columns.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* eastAsianWidth(0x41); // "Na"
|
|
22
|
+
* eastAsianWidth(0x4e2d); // "W"
|
|
23
|
+
* eastAsianWidth(0xff21); // "F"
|
|
24
|
+
* eastAsianWidth(0xff71); // "H"
|
|
25
|
+
* eastAsianWidth(0xa1); // "A"
|
|
26
|
+
* eastAsianWidth(0x0e01); // "N"
|
|
27
|
+
*
|
|
28
|
+
* @param codePoint An integer from 0 to 0x10FFFF; a surrogate is `"N"`.
|
|
29
|
+
* @returns The width class. Complexity: O(1) below U+0800 and O(log r) above, r
|
|
30
|
+
* = 602 runs; O(1) memory, after about 5 KB of tables decoded on the first
|
|
31
|
+
* call.
|
|
32
|
+
* @throws {RangeError} If `codePoint` is not an integer from 0 to 0x10FFFF.
|
|
33
|
+
*/
|
|
34
|
+
export function eastAsianWidth(codePoint) {
|
|
35
|
+
if (!isIntegerInRange(codePoint, 0, MAX_CODE_POINT + 1)) {
|
|
36
|
+
throw new RangeError("A code point is an integer from 0 to 0x10FFFF.");
|
|
37
|
+
}
|
|
38
|
+
runs_ ??= decodeCodePointRuns(EAST_ASIAN_WIDTH_RUNS_);
|
|
39
|
+
return EAST_ASIAN_WIDTHS_[lookupCodePointRun(runs_, codePoint)] ?? "N";
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=east-asian-width.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"east-asian-width.js","sourceRoot":"","sources":["../../src/width/east-asian-width.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,EACN,mBAAmB,EACnB,kBAAkB,GAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,sBAAsB,MAAM,6BAA6B,CAAC;AAWjE,sEAAsE;AACtE,MAAM,kBAAkB,GAA8B;IACrD,GAAG;IACH,IAAI;IACJ,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;CACH,CAAC;AAEF,IAAI,KAAyD,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,cAAc,CAAC,SAAiB;IAC/C,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,EAAE,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,UAAU,CAAC,gDAAgD,CAAC,CAAC;IACxE,CAAC;IACD,KAAK,KAAK,mBAAmB,CAAC,sBAAsB,CAAC,CAAC;IACtD,OAAO,kBAAkB,CAAC,kBAAkB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,IAAI,GAAG,CAAC;AACxE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ac-kit/text-unicode",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Text by Unicode character properties and UAX algorithms: first strong direction (UAX #9), East Asian width (UAX #11), display-text normalisation, diacritic stripping and slugs.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"bidi",
|
|
7
|
+
"east-asian-width",
|
|
8
|
+
"slug",
|
|
9
|
+
"text",
|
|
10
|
+
"unicode"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://anthochamp.pages.grenadine.io/node-essentials/api/text-unicode/",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://git.grenadine.io/anthochamp/node-essentials/issues"
|
|
15
|
+
},
|
|
16
|
+
"license": "BSD-3-Clause AND Unicode-3.0",
|
|
17
|
+
"author": "Anthony Champagne <dev@anthonychampagne.fr>",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://git.grenadine.io/anthochamp/node-essentials.git",
|
|
21
|
+
"directory": "packages/text-unicode"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"main": "./dist/index.js",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"compile": "tsc -p ./tsconfig.build.json -outDir dist",
|
|
41
|
+
"compile:check": "tsc -noEmit -p ./tsconfig.json",
|
|
42
|
+
"clean": "rimraf dist",
|
|
43
|
+
"build": "yarn clean && yarn compile",
|
|
44
|
+
"generate:unicode-tables": "node --import tsx ./scripts/generate-unicode-tables.ts",
|
|
45
|
+
"generate:check": "node --import tsx ./scripts/generate-unicode-tables.ts --check",
|
|
46
|
+
"test": "yarn run -T vitest run",
|
|
47
|
+
"prepack": "yarn build"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@ac-kit/algo": "^0.5.0",
|
|
51
|
+
"@ac-kit/core": "^0.12.0",
|
|
52
|
+
"@types/web": "^0.0.367"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@ac-kit/codegen-util": "0.1.0",
|
|
56
|
+
"@ac-kit/math-random": "0.4.0",
|
|
57
|
+
"@ac-kit/tsconfig": "0.1.0",
|
|
58
|
+
"@ac-kit/typedoc-config": "0.1.0",
|
|
59
|
+
"@ac-kit/vitest-config": "0.2.0",
|
|
60
|
+
"@typescript/native": "typescript@7.0.2",
|
|
61
|
+
"rimraf": "6.1.4",
|
|
62
|
+
"tsx": "4.23.15",
|
|
63
|
+
"typedoc": "0.28.20",
|
|
64
|
+
"typescript": "@typescript/typescript6@6.0.2"
|
|
65
|
+
},
|
|
66
|
+
"engines": {
|
|
67
|
+
"node": ">=24"
|
|
68
|
+
}
|
|
6
69
|
}
|