text-shaper 0.1.2 → 0.1.4
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/README.md +413 -38
- package/dist/aat/state-machine.d.ts +18 -6
- package/dist/buffer/glyph-buffer.d.ts +35 -1
- package/dist/buffer/unicode-buffer.d.ts +2 -0
- package/dist/fluent/bitmap-builder.d.ts +146 -0
- package/dist/fluent/index.d.ts +102 -0
- package/dist/fluent/path-builder.d.ts +230 -0
- package/dist/fluent/pipe.d.ts +200 -0
- package/dist/fluent/types.d.ts +93 -0
- package/dist/font/brotli/decode.d.ts +42 -0
- package/dist/font/face.d.ts +2 -0
- package/dist/font/font.d.ts +14 -0
- package/dist/font/tables/cff.d.ts +3 -1
- package/dist/font/tables/cff2.d.ts +63 -0
- package/dist/font/tables/colr.d.ts +4 -1
- package/dist/font/tables/fvar.d.ts +3 -1
- package/dist/font/tables/glyf.d.ts +13 -0
- package/dist/font/tables/gpos.d.ts +24 -1
- package/dist/font/tables/gsub.d.ts +20 -0
- package/dist/font/tables/gvar.d.ts +10 -1
- package/dist/font/tables/head.d.ts +5 -0
- package/dist/font/tables/hhea.d.ts +5 -0
- package/dist/font/tables/loca.d.ts +3 -0
- package/dist/font/tables/maxp.d.ts +5 -0
- package/dist/font/tables/name.d.ts +5 -0
- package/dist/font/tables/os2.d.ts +5 -0
- package/dist/font/tables/post.d.ts +5 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +12 -10
- package/dist/index.js.map +105 -99
- package/dist/layout/justify.d.ts +15 -2
- package/dist/layout/structures/class-def.d.ts +61 -8
- package/dist/layout/structures/coverage.d.ts +57 -10
- package/dist/layout/structures/device.d.ts +26 -5
- package/dist/layout/structures/layout-common.d.ts +18 -3
- package/dist/layout/structures/set-digest.d.ts +59 -0
- package/dist/raster/asymmetric-stroke.d.ts +9 -5
- package/dist/raster/bitmap-utils.d.ts +67 -0
- package/dist/raster/blur.d.ts +11 -0
- package/dist/raster/cascade-blur.d.ts +9 -10
- package/dist/raster/cell.d.ts +24 -0
- package/dist/raster/fixed-point.d.ts +1 -1
- package/dist/raster/gradient.d.ts +15 -0
- package/dist/raster/gray-raster.d.ts +7 -1
- package/dist/raster/lcd-filter.d.ts +15 -0
- package/dist/raster/msdf.d.ts +27 -5
- package/dist/raster/outline-decompose.d.ts +16 -17
- package/dist/raster/rasterize.d.ts +19 -2
- package/dist/raster/sdf.d.ts +3 -0
- package/dist/raster/stroker.d.ts +3 -0
- package/dist/raster/types.d.ts +9 -0
- package/dist/render/path.d.ts +56 -1
- package/dist/shaper/complex/arabic.d.ts +1 -0
- package/dist/shaper/shape-plan.d.ts +11 -8
- package/dist/shaper/shaper.d.ts +189 -4
- package/dist/unicode/bidi/brackets.d.ts +15 -0
- package/dist/unicode/bidi/char-types.d.ts +4 -0
- package/dist/unicode/bidi/embedding-levels.d.ts +3 -0
- package/dist/unicode/bidi/mirroring.d.ts +10 -0
- package/dist/unicode/bidi/reordering.d.ts +15 -0
- package/dist/unicode/normalize.d.ts +23 -0
- package/dist/unicode/script.d.ts +17 -0
- package/dist/unicode/segmentation.d.ts +18 -0
- package/package.json +11 -2
|
@@ -2,9 +2,19 @@
|
|
|
2
2
|
* Bidi character mirroring
|
|
3
3
|
* Port of bidi-js mirroring.js
|
|
4
4
|
*/
|
|
5
|
+
/**
|
|
6
|
+
* Get the mirrored version of a character for BiDi display
|
|
7
|
+
* @param char Character to mirror
|
|
8
|
+
* @returns Mirrored character, or null if character has no mirror
|
|
9
|
+
*/
|
|
5
10
|
export declare function getMirroredCharacter(char: string): string | null;
|
|
6
11
|
/**
|
|
7
12
|
* Given a string and its resolved embedding levels, build a map of indices to replacement chars
|
|
8
13
|
* for any characters in right-to-left segments that have defined mirrored characters.
|
|
14
|
+
* @param string Text string to process
|
|
15
|
+
* @param embeddingLevels Resolved embedding levels from getEmbeddingLevels
|
|
16
|
+
* @param start Start index (defaults to 0)
|
|
17
|
+
* @param end End index (defaults to string length - 1)
|
|
18
|
+
* @returns Map of character indices to their mirrored replacements
|
|
9
19
|
*/
|
|
10
20
|
export declare function getMirroredCharactersMap(string: string, embeddingLevels: Uint8Array, start?: number, end?: number): Map<number, string>;
|
|
@@ -6,13 +6,28 @@ import type { EmbeddingLevelsResult } from "./embedding-levels.ts";
|
|
|
6
6
|
/**
|
|
7
7
|
* Given a start and end denoting a single line within a string, and a set of precalculated
|
|
8
8
|
* bidi embedding levels, produce a list of segments whose ordering should be flipped, in sequence.
|
|
9
|
+
* @param string Text string to process
|
|
10
|
+
* @param embeddingLevelsResult Result from getEmbeddingLevels
|
|
11
|
+
* @param start Start index (defaults to 0)
|
|
12
|
+
* @param end End index (defaults to string length - 1)
|
|
13
|
+
* @returns Array of segment ranges [start, end] to be reversed
|
|
9
14
|
*/
|
|
10
15
|
export declare function getReorderSegments(string: string, embeddingLevelsResult: EmbeddingLevelsResult, start?: number, end?: number): Array<[number, number]>;
|
|
11
16
|
/**
|
|
12
17
|
* Get the reordered string with bidi segments reversed
|
|
18
|
+
* @param string Text string to reorder
|
|
19
|
+
* @param embedLevelsResult Result from getEmbeddingLevels
|
|
20
|
+
* @param start Start index (defaults to 0)
|
|
21
|
+
* @param end End index (defaults to string length - 1)
|
|
22
|
+
* @returns Reordered string with BiDi applied
|
|
13
23
|
*/
|
|
14
24
|
export declare function getReorderedString(string: string, embedLevelsResult: EmbeddingLevelsResult, start?: number, end?: number): string;
|
|
15
25
|
/**
|
|
16
26
|
* Get an array with character indices in their new bidi order
|
|
27
|
+
* @param string Text string to process
|
|
28
|
+
* @param embedLevelsResult Result from getEmbeddingLevels
|
|
29
|
+
* @param start Start index (defaults to 0)
|
|
30
|
+
* @param end End index (defaults to string length - 1)
|
|
31
|
+
* @returns Array mapping new positions to original character indices
|
|
17
32
|
*/
|
|
18
33
|
export declare function getReorderedIndices(string: string, embedLevelsResult: EmbeddingLevelsResult, start?: number, end?: number): number[];
|
|
@@ -15,22 +15,45 @@ export declare enum NormalizationMode {
|
|
|
15
15
|
/**
|
|
16
16
|
* Canonical Combining Class (ccc) for combining marks
|
|
17
17
|
* Based on Unicode 15.0
|
|
18
|
+
*
|
|
19
|
+
* Optimized with early-exit for common non-combining ranges:
|
|
20
|
+
* - Basic Latin (0000-007F)
|
|
21
|
+
* - Latin-1 Supplement (0080-00FF)
|
|
22
|
+
* - Latin Extended-A/B (0100-024F)
|
|
23
|
+
* - IPA Extensions (0250-02AF)
|
|
24
|
+
* - Spacing Modifier Letters (02B0-02FF) - most are spacing
|
|
25
|
+
* - Greek and Coptic (0370-03FF) - base chars only
|
|
26
|
+
* - Cyrillic (0400-04FF)
|
|
27
|
+
* - Cyrillic Supplement (0500-052F)
|
|
28
|
+
* - CJK ranges (3000+)
|
|
29
|
+
* - Hangul (AC00-D7AF)
|
|
30
|
+
* @param cp Unicode codepoint to check
|
|
31
|
+
* @returns Canonical combining class (0 for non-combining characters, 1-255 for combining marks)
|
|
18
32
|
*/
|
|
19
33
|
export declare function getCombiningClass(cp: number): number;
|
|
20
34
|
/**
|
|
21
35
|
* Reorder combining marks according to canonical combining class
|
|
36
|
+
* @param infos Array of glyph information objects (modified in place)
|
|
22
37
|
*/
|
|
23
38
|
export declare function reorderMarks(infos: GlyphInfo[]): void;
|
|
24
39
|
/**
|
|
25
40
|
* Decompose a codepoint if it has a canonical decomposition
|
|
41
|
+
* @param cp Unicode codepoint to decompose
|
|
42
|
+
* @returns Array of decomposed codepoints, or null if character has no decomposition
|
|
26
43
|
*/
|
|
27
44
|
export declare function decompose(cp: number): number[] | null;
|
|
28
45
|
/**
|
|
29
46
|
* Try to compose a base character with a combining mark
|
|
30
47
|
* Returns the composed character or null if no composition exists
|
|
48
|
+
* @param base Base character codepoint
|
|
49
|
+
* @param combining Combining mark codepoint
|
|
50
|
+
* @returns Composed character codepoint, or null if no composition exists
|
|
31
51
|
*/
|
|
32
52
|
export declare function tryCompose(base: number, combining: number): number | null;
|
|
33
53
|
/**
|
|
34
54
|
* Apply normalization to glyph infos
|
|
55
|
+
* @param infos Array of glyph information objects
|
|
56
|
+
* @param mode Normalization mode (None, Decompose, Compose, or Auto)
|
|
57
|
+
* @returns Normalized array of glyph information objects
|
|
35
58
|
*/
|
|
36
59
|
export declare function normalize(infos: GlyphInfo[], mode: NormalizationMode): GlyphInfo[];
|
package/dist/unicode/script.d.ts
CHANGED
|
@@ -173,19 +173,28 @@ export declare enum Script {
|
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
175
175
|
* Get script for a codepoint using binary search
|
|
176
|
+
* @param cp Unicode codepoint to check
|
|
177
|
+
* @returns The script for the given codepoint
|
|
176
178
|
*/
|
|
177
179
|
export declare function getScript(cp: number): Script;
|
|
178
180
|
/**
|
|
179
181
|
* Get script for a string (returns the dominant non-Common/Inherited script)
|
|
182
|
+
* @param text Text string to analyze
|
|
183
|
+
* @returns The dominant script found in the text (most frequent non-Common/Inherited script)
|
|
180
184
|
*/
|
|
181
185
|
export declare function detectScript(text: string): Script;
|
|
182
186
|
/**
|
|
183
187
|
* Get all scripts present in text
|
|
188
|
+
* @param text Text string to analyze
|
|
189
|
+
* @returns Array of all scripts found in the text
|
|
184
190
|
*/
|
|
185
191
|
export declare function getScripts(text: string): Script[];
|
|
186
192
|
/**
|
|
187
193
|
* Check if text contains only characters from a specific script
|
|
188
194
|
* (Common and Inherited are allowed)
|
|
195
|
+
* @param text Text string to check
|
|
196
|
+
* @param script Script to check against
|
|
197
|
+
* @returns True if text contains only characters from the specified script (plus Common/Inherited)
|
|
189
198
|
*/
|
|
190
199
|
export declare function isScript(text: string, script: Script): boolean;
|
|
191
200
|
/**
|
|
@@ -199,17 +208,25 @@ export interface ScriptRun {
|
|
|
199
208
|
}
|
|
200
209
|
/**
|
|
201
210
|
* Split text into script runs
|
|
211
|
+
* @param text Text string to split
|
|
212
|
+
* @returns Array of script runs, where each run is a contiguous sequence of characters with the same script
|
|
202
213
|
*/
|
|
203
214
|
export declare function getScriptRuns(text: string): ScriptRun[];
|
|
204
215
|
/**
|
|
205
216
|
* Get OpenType script tag for a Unicode script
|
|
217
|
+
* @param script Unicode script to convert
|
|
218
|
+
* @returns OpenType script tag (4-character string like "latn", "arab", etc.)
|
|
206
219
|
*/
|
|
207
220
|
export declare function getScriptTag(script: Script): string;
|
|
208
221
|
/**
|
|
209
222
|
* Check if a script requires complex shaping
|
|
223
|
+
* @param script Script to check
|
|
224
|
+
* @returns True if the script requires complex shaping (e.g., Arabic, Devanagari, Thai)
|
|
210
225
|
*/
|
|
211
226
|
export declare function isComplexScript(script: Script): boolean;
|
|
212
227
|
/**
|
|
213
228
|
* Get script direction (LTR or RTL)
|
|
229
|
+
* @param script Script to check
|
|
230
|
+
* @returns Direction of the script: "ltr" for left-to-right or "rtl" for right-to-left
|
|
214
231
|
*/
|
|
215
232
|
export declare function getScriptDirection(script: Script): "ltr" | "rtl";
|
|
@@ -50,10 +50,14 @@ export declare enum WordBreakProperty {
|
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Get grapheme break property for codepoint
|
|
53
|
+
* @param cp Unicode codepoint to check
|
|
54
|
+
* @returns Grapheme break property for the codepoint
|
|
53
55
|
*/
|
|
54
56
|
export declare function getGraphemeBreakProperty(cp: number): GraphemeBreakProperty;
|
|
55
57
|
/**
|
|
56
58
|
* Get word break property for codepoint
|
|
59
|
+
* @param cp Unicode codepoint to check
|
|
60
|
+
* @returns Word break property for the codepoint
|
|
57
61
|
*/
|
|
58
62
|
export declare function getWordBreakProperty(cp: number): WordBreakProperty;
|
|
59
63
|
/**
|
|
@@ -67,6 +71,8 @@ export interface GraphemeBoundaries {
|
|
|
67
71
|
}
|
|
68
72
|
/**
|
|
69
73
|
* Find grapheme cluster boundaries in codepoints
|
|
74
|
+
* @param codepoints Array of Unicode codepoints
|
|
75
|
+
* @returns Object containing boundary positions and grapheme break properties
|
|
70
76
|
*/
|
|
71
77
|
export declare function findGraphemeBoundaries(codepoints: number[]): GraphemeBoundaries;
|
|
72
78
|
/**
|
|
@@ -80,25 +86,37 @@ export interface WordBoundaries {
|
|
|
80
86
|
}
|
|
81
87
|
/**
|
|
82
88
|
* Find word boundaries in codepoints
|
|
89
|
+
* @param codepoints Array of Unicode codepoints
|
|
90
|
+
* @returns Object containing boundary positions and word break properties
|
|
83
91
|
*/
|
|
84
92
|
export declare function findWordBoundaries(codepoints: number[]): WordBoundaries;
|
|
85
93
|
/**
|
|
86
94
|
* Split text into grapheme clusters
|
|
95
|
+
* @param text Text string to split
|
|
96
|
+
* @returns Array of grapheme cluster strings
|
|
87
97
|
*/
|
|
88
98
|
export declare function splitGraphemes(text: string): string[];
|
|
89
99
|
/**
|
|
90
100
|
* Split text into words
|
|
101
|
+
* @param text Text string to split
|
|
102
|
+
* @returns Array of word strings (whitespace-only segments are filtered out)
|
|
91
103
|
*/
|
|
92
104
|
export declare function splitWords(text: string): string[];
|
|
93
105
|
/**
|
|
94
106
|
* Count grapheme clusters in text
|
|
107
|
+
* @param text Text string to analyze
|
|
108
|
+
* @returns Number of grapheme clusters in the text
|
|
95
109
|
*/
|
|
96
110
|
export declare function countGraphemes(text: string): number;
|
|
97
111
|
/**
|
|
98
112
|
* Analyze grapheme boundaries for glyph infos
|
|
113
|
+
* @param infos Array of glyph information objects
|
|
114
|
+
* @returns Object containing boundary positions and grapheme break properties
|
|
99
115
|
*/
|
|
100
116
|
export declare function analyzeGraphemesForGlyphs(infos: GlyphInfo[]): GraphemeBoundaries;
|
|
101
117
|
/**
|
|
102
118
|
* Analyze word boundaries for glyph infos
|
|
119
|
+
* @param infos Array of glyph information objects
|
|
120
|
+
* @returns Object containing boundary positions and word break properties
|
|
103
121
|
*/
|
|
104
122
|
export declare function analyzeWordsForGlyphs(infos: GlyphInfo[]): WordBoundaries;
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "text-shaper",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@biomejs/biome": "2.3.8",
|
|
8
8
|
"@types/bun": "latest",
|
|
9
|
+
"@types/opentype.js": "^1.3.8",
|
|
10
|
+
"freetype2": "^2.1.0",
|
|
11
|
+
"harfbuzzjs": "^0.4.13",
|
|
12
|
+
"opentype.js": "^1.3.4",
|
|
9
13
|
"vitepress": "^2.0.0-alpha.15",
|
|
10
14
|
"vitepress-plugin-llms": "^1.9.3"
|
|
11
15
|
},
|
|
@@ -43,6 +47,8 @@
|
|
|
43
47
|
],
|
|
44
48
|
"license": "MIT",
|
|
45
49
|
"scripts": {
|
|
50
|
+
"postinstall": "node scripts/patch-pkg-prebuilds.js",
|
|
51
|
+
"bench": "bun test ./bench/ --timeout 120000",
|
|
46
52
|
"build": "bun build ./src/index.ts --outdir ./dist --target browser --minify --sourcemap=linked",
|
|
47
53
|
"build:prod": "bun build ./src/index.ts --outdir ./dist --target browser --production --sourcemap=external",
|
|
48
54
|
"build:analyze": "bun build ./src/index.ts --outdir ./dist --target browser --minify --metafile=./dist/meta.json",
|
|
@@ -56,5 +62,8 @@
|
|
|
56
62
|
"docs:preview": "vitepress preview docs"
|
|
57
63
|
},
|
|
58
64
|
"type": "module",
|
|
59
|
-
"types": "./dist/index.d.ts"
|
|
65
|
+
"types": "./dist/index.d.ts",
|
|
66
|
+
"trustedDependencies": [
|
|
67
|
+
"freetype2"
|
|
68
|
+
]
|
|
60
69
|
}
|