@kensio/pinyinjs 0.1.0-beta.0 → 1.0.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 +87 -0
- package/NOTICE +7 -0
- package/README.md +144 -19
- package/data/full.entries +13400 -13400
- package/data/manifest.json +4 -4
- package/data/standard.entries +2492 -2492
- package/dist/cli/arguments.d.ts +67 -0
- package/dist/cli/arguments.d.ts.map +1 -1
- package/dist/cli/arguments.js +79 -0
- package/dist/cli/arguments.js.map +1 -1
- package/dist/cli/colour.d.ts +77 -0
- package/dist/cli/colour.d.ts.map +1 -0
- package/dist/cli/colour.js +117 -0
- package/dist/cli/colour.js.map +1 -0
- package/dist/cli/commands.d.ts +49 -1
- package/dist/cli/commands.d.ts.map +1 -1
- package/dist/cli/commands.js +404 -42
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/environment.d.ts.map +1 -1
- package/dist/cli/environment.js +20 -0
- package/dist/cli/environment.js.map +1 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +43 -16
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/run.d.ts +11 -0
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +4 -2
- package/dist/cli/run.js.map +1 -1
- package/dist/decode/convert.d.ts +20 -0
- package/dist/decode/convert.d.ts.map +1 -1
- package/dist/decode/convert.js +170 -12
- package/dist/decode/convert.js.map +1 -1
- package/dist/decode/decode.d.ts +3 -2
- package/dist/decode/decode.d.ts.map +1 -1
- package/dist/decode/decode.js +17 -4
- package/dist/decode/decode.js.map +1 -1
- package/dist/decode/reading-rules.d.ts +56 -0
- package/dist/decode/reading-rules.d.ts.map +1 -0
- package/dist/decode/reading-rules.js +107 -0
- package/dist/decode/reading-rules.js.map +1 -0
- package/dist/decode/rules.d.ts +66 -0
- package/dist/decode/rules.d.ts.map +1 -0
- package/dist/decode/rules.js +138 -0
- package/dist/decode/rules.js.map +1 -0
- package/dist/decode/sandhi.d.ts +1 -1
- package/dist/decode/sandhi.d.ts.map +1 -1
- package/dist/decode/sandhi.js +60 -1
- package/dist/decode/sandhi.js.map +1 -1
- package/dist/decode/word.d.ts +18 -0
- package/dist/decode/word.d.ts.map +1 -1
- package/dist/dictionary/artifact.d.ts.map +1 -1
- package/dist/dictionary/artifact.js +28 -1
- package/dist/dictionary/artifact.js.map +1 -1
- package/dist/dictionary/dictionary.d.ts +9 -0
- package/dist/dictionary/dictionary.d.ts.map +1 -1
- package/dist/dictionary/dictionary.js +7 -0
- package/dist/dictionary/dictionary.js.map +1 -1
- package/dist/dictionary/entry.d.ts +12 -0
- package/dist/dictionary/entry.d.ts.map +1 -1
- package/dist/dictionary/entry.js.map +1 -1
- package/dist/dictionary/merge.d.ts +3 -1
- package/dist/dictionary/merge.d.ts.map +1 -1
- package/dist/dictionary/merge.js +19 -1
- package/dist/dictionary/merge.js.map +1 -1
- package/dist/format/transcription.d.ts +52 -0
- package/dist/format/transcription.d.ts.map +1 -0
- package/dist/format/transcription.js +88 -0
- package/dist/format/transcription.js.map +1 -0
- package/dist/index.d.ts +24 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/dist/numerals/cardinal.d.ts +39 -0
- package/dist/numerals/cardinal.d.ts.map +1 -0
- package/dist/numerals/cardinal.js +111 -0
- package/dist/numerals/cardinal.js.map +1 -0
- package/dist/numerals/characters.d.ts +31 -0
- package/dist/numerals/characters.d.ts.map +1 -0
- package/dist/numerals/characters.js +80 -0
- package/dist/numerals/characters.js.map +1 -0
- package/dist/numerals/numerals.d.ts +76 -0
- package/dist/numerals/numerals.d.ts.map +1 -0
- package/dist/numerals/numerals.js +119 -0
- package/dist/numerals/numerals.js.map +1 -0
- package/dist/numerals/text.d.ts +52 -0
- package/dist/numerals/text.d.ts.map +1 -0
- package/dist/numerals/text.js +248 -0
- package/dist/numerals/text.js.map +1 -0
- package/dist/orthography/grouping.d.ts +56 -11
- package/dist/orthography/grouping.d.ts.map +1 -1
- package/dist/orthography/grouping.js +109 -35
- package/dist/orthography/grouping.js.map +1 -1
- package/dist/orthography/idiom-list.d.ts +56 -0
- package/dist/orthography/idiom-list.d.ts.map +1 -0
- package/dist/orthography/idiom-list.js +296 -0
- package/dist/orthography/idiom-list.js.map +1 -0
- package/dist/orthography/idioms.d.ts +18 -0
- package/dist/orthography/idioms.d.ts.map +1 -0
- package/dist/orthography/idioms.js +22 -0
- package/dist/orthography/idioms.js.map +1 -0
- package/dist/orthography/reduplication.d.ts +52 -0
- package/dist/orthography/reduplication.d.ts.map +1 -0
- package/dist/orthography/reduplication.js +99 -0
- package/dist/orthography/reduplication.js.map +1 -0
- package/dist/orthography/rule.d.ts +50 -0
- package/dist/orthography/rule.d.ts.map +1 -0
- package/dist/orthography/rule.js +101 -0
- package/dist/orthography/rule.js.map +1 -0
- package/dist/sources/cedict.d.ts +23 -0
- package/dist/sources/cedict.d.ts.map +1 -1
- package/dist/sources/cedict.js +28 -0
- package/dist/sources/cedict.js.map +1 -1
- package/dist/syllable/syllable.d.ts +1 -1
- package/dist/syllable/syllable.d.ts.map +1 -1
- package/dist/syllable/syllable.js +2 -37
- package/dist/syllable/syllable.js.map +1 -1
- package/dist/tone/tone-mark.d.ts +23 -0
- package/dist/tone/tone-mark.d.ts.map +1 -1
- package/dist/tone/tone-mark.js +49 -0
- package/dist/tone/tone-mark.js.map +1 -1
- package/dist/transcription/bopomofo.d.ts +46 -0
- package/dist/transcription/bopomofo.d.ts.map +1 -0
- package/dist/transcription/bopomofo.js +371 -0
- package/dist/transcription/bopomofo.js.map +1 -0
- package/dist/transcription/gwoyeu.d.ts +32 -0
- package/dist/transcription/gwoyeu.d.ts.map +1 -0
- package/dist/transcription/gwoyeu.js +491 -0
- package/dist/transcription/gwoyeu.js.map +1 -0
- package/dist/transcription/ipa.d.ts +40 -0
- package/dist/transcription/ipa.d.ts.map +1 -0
- package/dist/transcription/ipa.js +221 -0
- package/dist/transcription/ipa.js.map +1 -0
- package/dist/transcription/spelling-index.d.ts +23 -0
- package/dist/transcription/spelling-index.d.ts.map +1 -0
- package/dist/transcription/spelling-index.js +61 -0
- package/dist/transcription/spelling-index.js.map +1 -0
- package/dist/transcription/wade-giles.d.ts +108 -0
- package/dist/transcription/wade-giles.d.ts.map +1 -0
- package/dist/transcription/wade-giles.js +656 -0
- package/dist/transcription/wade-giles.js.map +1 -0
- package/dist/transcription/yale.d.ts +43 -0
- package/dist/transcription/yale.d.ts.map +1 -0
- package/dist/transcription/yale.js +242 -0
- package/dist/transcription/yale.js.map +1 -0
- package/package.json +9 -5
package/dist/cli/arguments.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ConvertOptions } from "../decode/convert.js";
|
|
2
|
+
import type { ColourDepth } from "./colour.js";
|
|
2
3
|
import type { Tier } from "../dictionary/tiers.js";
|
|
3
4
|
import type { HtmlOptions } from "../format/html.js";
|
|
4
5
|
/**
|
|
@@ -36,6 +37,9 @@ declare const FLAGS: {
|
|
|
36
37
|
readonly "no-grouping": {
|
|
37
38
|
readonly type: "boolean";
|
|
38
39
|
};
|
|
40
|
+
readonly "keep-numbers": {
|
|
41
|
+
readonly type: "boolean";
|
|
42
|
+
};
|
|
39
43
|
readonly "third-tone": {
|
|
40
44
|
readonly type: "boolean";
|
|
41
45
|
};
|
|
@@ -45,12 +49,42 @@ declare const FLAGS: {
|
|
|
45
49
|
readonly greedy: {
|
|
46
50
|
readonly type: "boolean";
|
|
47
51
|
};
|
|
52
|
+
readonly digits: {
|
|
53
|
+
readonly type: "boolean";
|
|
54
|
+
};
|
|
55
|
+
readonly yao: {
|
|
56
|
+
readonly type: "boolean";
|
|
57
|
+
};
|
|
58
|
+
readonly "no-liang": {
|
|
59
|
+
readonly type: "boolean";
|
|
60
|
+
};
|
|
61
|
+
readonly percent: {
|
|
62
|
+
readonly type: "boolean";
|
|
63
|
+
};
|
|
64
|
+
readonly from: {
|
|
65
|
+
readonly type: "string";
|
|
66
|
+
};
|
|
67
|
+
readonly system: {
|
|
68
|
+
readonly type: "string";
|
|
69
|
+
};
|
|
48
70
|
readonly "no-tone-classes": {
|
|
49
71
|
readonly type: "boolean";
|
|
50
72
|
};
|
|
51
73
|
readonly "no-uncertain": {
|
|
52
74
|
readonly type: "boolean";
|
|
53
75
|
};
|
|
76
|
+
readonly colour: {
|
|
77
|
+
readonly type: "boolean";
|
|
78
|
+
};
|
|
79
|
+
readonly color: {
|
|
80
|
+
readonly type: "boolean";
|
|
81
|
+
};
|
|
82
|
+
readonly "no-colour": {
|
|
83
|
+
readonly type: "boolean";
|
|
84
|
+
};
|
|
85
|
+
readonly "no-color": {
|
|
86
|
+
readonly type: "boolean";
|
|
87
|
+
};
|
|
54
88
|
readonly json: {
|
|
55
89
|
readonly type: "boolean";
|
|
56
90
|
};
|
|
@@ -109,6 +143,39 @@ export declare function parseArguments(argv: readonly string[]): ParsedArguments
|
|
|
109
143
|
* --no-uncertain` would look like it had been honoured.
|
|
110
144
|
*/
|
|
111
145
|
export declare function checkFlags(flags: Flags, allowed: readonly FlagName[], command: string): void;
|
|
146
|
+
/**
|
|
147
|
+
* Which system the text handed to `transcribe` is written in.
|
|
148
|
+
*
|
|
149
|
+
* `auto` reads bopomofo as bopomofo and everything else as pinyin, which is as
|
|
150
|
+
* far as detection can honestly go: bopomofo has a script of its own, while
|
|
151
|
+
* `chi` is a well-formed spelling in both pinyin and Wade-Giles and means
|
|
152
|
+
* different syllables in each.
|
|
153
|
+
*/
|
|
154
|
+
export type TranscriptionSource = "auto" | "pinyin" | "wade-giles" | "bopomofo" | "yale" | "gwoyeu" | "ipa";
|
|
155
|
+
/**
|
|
156
|
+
* Read the `--from` flag.
|
|
157
|
+
*/
|
|
158
|
+
export declare function transcriptionSource(flags: Flags): TranscriptionSource;
|
|
159
|
+
/**
|
|
160
|
+
* Read the `--system` flag.
|
|
161
|
+
*/
|
|
162
|
+
export declare function transcriptionSystem(flags: Flags): TranscriptionSource | undefined;
|
|
163
|
+
/**
|
|
164
|
+
* How much colour a run should write, given what the terminal offered.
|
|
165
|
+
*
|
|
166
|
+
* `--colour` and `--no-colour` force it either way, and `--color` is accepted
|
|
167
|
+
* as a spelling because every other tool spells it that way and nobody should
|
|
168
|
+
* have to discover which this one chose.
|
|
169
|
+
*
|
|
170
|
+
* **`--json` is never coloured**, whatever the flags say: the option is about
|
|
171
|
+
* the plain output, and the JSON already carries the tone as a number for a
|
|
172
|
+
* caller that will do its own rendering.
|
|
173
|
+
*
|
|
174
|
+
* Forcing colour where the environment offered none — into a pipe, or past
|
|
175
|
+
* `NO_COLOR` — gets the sixteen every terminal has, because nothing is known
|
|
176
|
+
* about where that output is going.
|
|
177
|
+
*/
|
|
178
|
+
export declare function colourDepth(flags: Flags, offered: ColourDepth): ColourDepth;
|
|
112
179
|
/**
|
|
113
180
|
* Which dictionary a run should read.
|
|
114
181
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arguments.d.ts","sourceRoot":"","sources":["../../src/cli/arguments.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOrD;;;;;;;GAOG;AACH,QAAA,MAAM,KAAK;;iBACD,IAAI,EAAE,QAAQ;;;iBACd,IAAI,EAAE,QAAQ;;;iBACV,IAAI,EAAE,QAAQ;iBAAE,KAAK,EAAE,GAAG;;;iBAC5B,IAAI,EAAE,QAAQ;iBAAE,KAAK,EAAE,GAAG;;;iBACtB,IAAI,EAAE,QAAQ;;;iBAChB,IAAI,EAAE,QAAQ;;;iBACX,IAAI,EAAE,QAAQ;;;iBACZ,IAAI,EAAE,SAAS;;;
|
|
1
|
+
{"version":3,"file":"arguments.d.ts","sourceRoot":"","sources":["../../src/cli/arguments.ts"],"names":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C;IACpB,uEAAuE;IACvE,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;CACxC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,gBAAgB,CAM/D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,cAAc,CAqB3D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,WAAW,CAMrD"}
|
package/dist/cli/arguments.js
CHANGED
|
@@ -16,11 +16,22 @@ const FLAGS = {
|
|
|
16
16
|
capitals: { type: "string" },
|
|
17
17
|
punctuation: { type: "string" },
|
|
18
18
|
"no-grouping": { type: "boolean" },
|
|
19
|
+
"keep-numbers": { type: "boolean" },
|
|
19
20
|
"third-tone": { type: "boolean" },
|
|
20
21
|
"no-sandhi": { type: "boolean" },
|
|
21
22
|
greedy: { type: "boolean" },
|
|
23
|
+
digits: { type: "boolean" },
|
|
24
|
+
yao: { type: "boolean" },
|
|
25
|
+
"no-liang": { type: "boolean" },
|
|
26
|
+
percent: { type: "boolean" },
|
|
27
|
+
from: { type: "string" },
|
|
28
|
+
system: { type: "string" },
|
|
22
29
|
"no-tone-classes": { type: "boolean" },
|
|
23
30
|
"no-uncertain": { type: "boolean" },
|
|
31
|
+
colour: { type: "boolean" },
|
|
32
|
+
color: { type: "boolean" },
|
|
33
|
+
"no-colour": { type: "boolean" },
|
|
34
|
+
"no-color": { type: "boolean" },
|
|
24
35
|
json: { type: "boolean" },
|
|
25
36
|
help: { type: "boolean", short: "h" },
|
|
26
37
|
version: { type: "boolean", short: "v" },
|
|
@@ -31,6 +42,10 @@ const FLAGS = {
|
|
|
31
42
|
export const GLOBAL_FLAGS = [
|
|
32
43
|
"data",
|
|
33
44
|
"tier",
|
|
45
|
+
"colour",
|
|
46
|
+
"color",
|
|
47
|
+
"no-colour",
|
|
48
|
+
"no-color",
|
|
34
49
|
"json",
|
|
35
50
|
"help",
|
|
36
51
|
"version",
|
|
@@ -46,6 +61,7 @@ export const CONVERT_FLAGS = [
|
|
|
46
61
|
"capitals",
|
|
47
62
|
"punctuation",
|
|
48
63
|
"no-grouping",
|
|
64
|
+
"keep-numbers",
|
|
49
65
|
"third-tone",
|
|
50
66
|
"no-sandhi",
|
|
51
67
|
];
|
|
@@ -115,6 +131,68 @@ const APOSTROPHES = ["always", "standard", "never"];
|
|
|
115
131
|
const CAPITALS = ["auto", "proper", "none"];
|
|
116
132
|
const PUNCTUATION = ["latin", "keep"];
|
|
117
133
|
const TIERS = ["core", "standard", "full"];
|
|
134
|
+
const SOURCES = [
|
|
135
|
+
"auto",
|
|
136
|
+
"pinyin",
|
|
137
|
+
"wade-giles",
|
|
138
|
+
"bopomofo",
|
|
139
|
+
"yale",
|
|
140
|
+
"gwoyeu",
|
|
141
|
+
"ipa",
|
|
142
|
+
];
|
|
143
|
+
/**
|
|
144
|
+
* Read the `--from` flag.
|
|
145
|
+
*/
|
|
146
|
+
export function transcriptionSource(flags) {
|
|
147
|
+
return chosen(flags, "from", SOURCES) ?? "auto";
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Which system a conversion should be written in.
|
|
151
|
+
*
|
|
152
|
+
* `pinyin` is not a value: writing pinyin is what `convert` does with no flag
|
|
153
|
+
* at all, and offering a name for the default would suggest the others are
|
|
154
|
+
* alternatives to it rather than things it is put through afterwards.
|
|
155
|
+
*/
|
|
156
|
+
const SYSTEMS_WRITTEN = [
|
|
157
|
+
"bopomofo",
|
|
158
|
+
"wade-giles",
|
|
159
|
+
"yale",
|
|
160
|
+
"gwoyeu",
|
|
161
|
+
"ipa",
|
|
162
|
+
];
|
|
163
|
+
/**
|
|
164
|
+
* Read the `--system` flag.
|
|
165
|
+
*/
|
|
166
|
+
export function transcriptionSystem(flags) {
|
|
167
|
+
return chosen(flags, "system", SYSTEMS_WRITTEN);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* How much colour a run should write, given what the terminal offered.
|
|
171
|
+
*
|
|
172
|
+
* `--colour` and `--no-colour` force it either way, and `--color` is accepted
|
|
173
|
+
* as a spelling because every other tool spells it that way and nobody should
|
|
174
|
+
* have to discover which this one chose.
|
|
175
|
+
*
|
|
176
|
+
* **`--json` is never coloured**, whatever the flags say: the option is about
|
|
177
|
+
* the plain output, and the JSON already carries the tone as a number for a
|
|
178
|
+
* caller that will do its own rendering.
|
|
179
|
+
*
|
|
180
|
+
* Forcing colour where the environment offered none — into a pipe, or past
|
|
181
|
+
* `NO_COLOR` — gets the sixteen every terminal has, because nothing is known
|
|
182
|
+
* about where that output is going.
|
|
183
|
+
*/
|
|
184
|
+
export function colourDepth(flags, offered) {
|
|
185
|
+
if (flags.json === true) {
|
|
186
|
+
return 0;
|
|
187
|
+
}
|
|
188
|
+
if (flags["no-colour"] === true || flags["no-color"] === true) {
|
|
189
|
+
return 0;
|
|
190
|
+
}
|
|
191
|
+
if (flags.colour === true || flags.color === true) {
|
|
192
|
+
return offered === 0 ? 16 : offered;
|
|
193
|
+
}
|
|
194
|
+
return offered;
|
|
195
|
+
}
|
|
118
196
|
/**
|
|
119
197
|
* Read the dictionary flags.
|
|
120
198
|
*/
|
|
@@ -142,6 +220,7 @@ export function convertOptions(flags) {
|
|
|
142
220
|
const capitals = chosen(flags, "capitals", CAPITALS);
|
|
143
221
|
const punctuation = chosen(flags, "punctuation", PUNCTUATION);
|
|
144
222
|
return {
|
|
223
|
+
...(flags["keep-numbers"] === true && { numbers: "keep" }),
|
|
145
224
|
...(notation !== undefined && { notation }),
|
|
146
225
|
...(locale !== undefined && { locale }),
|
|
147
226
|
...(apostrophe !== undefined && { apostrophe }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arguments.js","sourceRoot":"","sources":["../../src/cli/arguments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,SAAS,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"arguments.js","sourceRoot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C,GAAG,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,CAAC;QAC/C,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,QAAQ,EAAE,CAAC;QAC3C,GAAG,CAAC,WAAW,KAAK,SAAS,IAAI,EAAE,WAAW,EAAE,CAAC;QACjD,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,IAAI,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;QACzD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;KAClD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAY;IACtC,OAAO;QACL,GAAG,cAAc,CAAC,KAAK,CAAC;QACxB,GAAG,CAAC,KAAK,CAAC,iBAAiB,CAAC,KAAK,IAAI,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;QAChE,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,IAAI,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;KAChE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Tone } from "../tone/tone.js";
|
|
2
|
+
/**
|
|
3
|
+
* How much colour the output can carry.
|
|
4
|
+
*
|
|
5
|
+
* Two tiers rather than one because the sixteen colours every terminal has
|
|
6
|
+
* cannot carry this palette: the nearest basic yellow to MDBG's second tone is
|
|
7
|
+
* `#cdcd00`, which is ΔE00 22.7 away and contrasts 1.70:1 against a white
|
|
8
|
+
* background. The 256-colour cube gets every tone within ΔE00 8.6 and above
|
|
9
|
+
* 3:1 on both backgrounds. See {@link TONE_COLOURS} for the numbers.
|
|
10
|
+
*/
|
|
11
|
+
export type ColourDepth = 0 | 16 | 256;
|
|
12
|
+
/**
|
|
13
|
+
* Paint one syllable's text in its tone's colour.
|
|
14
|
+
*
|
|
15
|
+
* Takes the tone rather than the syllable so that a system spelling its
|
|
16
|
+
* syllables some other way — bopomofo, Wade-Giles — paints them the same. A
|
|
17
|
+
* tone the source never wrote is not painted, for the same reason tone 5 is
|
|
18
|
+
* not: MDBG has no colour for either.
|
|
19
|
+
*/
|
|
20
|
+
export type Painter = (text: string, tone: Tone | undefined) => string;
|
|
21
|
+
/**
|
|
22
|
+
* One tone's colour, as the docs and their guards need it.
|
|
23
|
+
*/
|
|
24
|
+
export interface PaletteEntry {
|
|
25
|
+
readonly tone: Tone;
|
|
26
|
+
/** MDBG's own value, so a page quoting it cannot drift from the source. */
|
|
27
|
+
readonly mdbg: string;
|
|
28
|
+
readonly escape: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Everything the palette knows, at a given depth.
|
|
32
|
+
*/
|
|
33
|
+
export declare function paletteAt(depth: ColourDepth): readonly PaletteEntry[];
|
|
34
|
+
/**
|
|
35
|
+
* A painter that hands text back exactly as it was.
|
|
36
|
+
*/
|
|
37
|
+
export declare const PLAIN: Painter;
|
|
38
|
+
/**
|
|
39
|
+
* A painter for a terminal of a given depth.
|
|
40
|
+
*
|
|
41
|
+
* Depth 0 is {@link PLAIN}, so a caller never has to ask twice.
|
|
42
|
+
*/
|
|
43
|
+
export declare function painterFor(depth: ColourDepth): Painter;
|
|
44
|
+
/**
|
|
45
|
+
* A line with its colour taken back off.
|
|
46
|
+
*/
|
|
47
|
+
export declare function stripColour(text: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* How many characters of a string a reader actually sees.
|
|
50
|
+
*
|
|
51
|
+
* A column padded with `padEnd` counts the escapes, so a coloured cell comes
|
|
52
|
+
* out short by however many bytes its colour took.
|
|
53
|
+
*/
|
|
54
|
+
export declare function visibleLength(text: string): number;
|
|
55
|
+
/**
|
|
56
|
+
* What a terminal says about itself.
|
|
57
|
+
*/
|
|
58
|
+
export interface TerminalSignals {
|
|
59
|
+
/** Whether the output is going to a terminal rather than a pipe or a file. */
|
|
60
|
+
readonly isTerminal: boolean;
|
|
61
|
+
/** `NO_COLOR`, honoured whenever it is set to anything but the empty string. */
|
|
62
|
+
readonly noColour: string | undefined;
|
|
63
|
+
readonly term: string | undefined;
|
|
64
|
+
readonly colorterm: string | undefined;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* How much colour to write, from what the terminal says about itself.
|
|
68
|
+
*
|
|
69
|
+
* Pure, and separate from the Node adapter that reads the signals, so that both
|
|
70
|
+
* answers can be asked for in a test rather than sniffed at run time.
|
|
71
|
+
*
|
|
72
|
+
* A file full of escape sequences is worse than no colour at all, so a pipe
|
|
73
|
+
* gets none; `NO_COLOR` is honoured because it is the convention every other
|
|
74
|
+
* tool honours; and `TERM=dumb` means what it says.
|
|
75
|
+
*/
|
|
76
|
+
export declare function depthFrom(signals: TerminalSignals): ColourDepth;
|
|
77
|
+
//# sourceMappingURL=colour.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colour.d.ts","sourceRoot":"","sources":["../../src/cli/colour.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,SAAS,KAAK,MAAM,CAAC;AA6DvE;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG,SAAS,YAAY,EAAE,CAMrE;AAED;;GAEG;AACH,eAAO,MAAM,KAAK,EAAE,OAAwB,CAAC;AAE7C;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAatD;AAYD;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;CACxC;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,eAAe,GAAG,WAAW,CAgB/D"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The palette, pinned against MDBG's stylesheet rather than guessed at.
|
|
3
|
+
*
|
|
4
|
+
* | Tone | MDBG | 256 | ΔE00 | 16 | ΔE00 |
|
|
5
|
+
* | ---: | --- | --- | ---: | --- | ---: |
|
|
6
|
+
* | 1 | `#ff0000` | 196 `#ff0000` | 0.0 | bright red | 0.0 |
|
|
7
|
+
* | 2 | `#d09000` | 136 `#af8700` | 7.8 | yellow | 22.7 |
|
|
8
|
+
* | 3 | `#00a000` | 28 `#008700` | 8.6 | green | 12.7 |
|
|
9
|
+
* | 4 | `#0044ff` | 27 `#005fff` | 7.7 | bright blue | 8.3 |
|
|
10
|
+
*
|
|
11
|
+
* **Tone 5 is not here, and that is MDBG's answer rather than an omission.**
|
|
12
|
+
* Its fifth colour is `#000000` on a light page and `#ffffff` on a dark one —
|
|
13
|
+
* the plain text colour, which in a terminal means writing no escape at all.
|
|
14
|
+
* The grey the roadmap recorded is Pleco's fifth colour, not MDBG's.
|
|
15
|
+
*
|
|
16
|
+
* A tone that was never written gets no colour either. MDBG's stylesheet
|
|
17
|
+
* carries a sixth class, `.mptd` `#808080`, but no page it serves uses it, so
|
|
18
|
+
* there is nothing attested to copy.
|
|
19
|
+
*/
|
|
20
|
+
const TONE_COLOURS = [
|
|
21
|
+
{ tone: 1, mdbg: "#ff0000", basic: 91, extended: 196 },
|
|
22
|
+
{ tone: 2, mdbg: "#d09000", basic: 33, extended: 136 },
|
|
23
|
+
{ tone: 3, mdbg: "#00a000", basic: 32, extended: 28 },
|
|
24
|
+
{ tone: 4, mdbg: "#0044ff", basic: 94, extended: 27 },
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* The escape that puts a terminal back to its own colours.
|
|
28
|
+
*/
|
|
29
|
+
const RESET = "\u{1B}[0m";
|
|
30
|
+
/**
|
|
31
|
+
* The escape sequence a tone is written in, at a given depth.
|
|
32
|
+
*/
|
|
33
|
+
function escapeFor(colour, depth) {
|
|
34
|
+
return depth === 256
|
|
35
|
+
? `\u{1B}[38;5;${String(colour.extended)}m`
|
|
36
|
+
: `\u{1B}[${String(colour.basic)}m`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Everything the palette knows, at a given depth.
|
|
40
|
+
*/
|
|
41
|
+
export function paletteAt(depth) {
|
|
42
|
+
return TONE_COLOURS.map((colour) => ({
|
|
43
|
+
tone: colour.tone,
|
|
44
|
+
mdbg: colour.mdbg,
|
|
45
|
+
escape: escapeFor(colour, depth),
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A painter that hands text back exactly as it was.
|
|
50
|
+
*/
|
|
51
|
+
export const PLAIN = (text) => text;
|
|
52
|
+
/**
|
|
53
|
+
* A painter for a terminal of a given depth.
|
|
54
|
+
*
|
|
55
|
+
* Depth 0 is {@link PLAIN}, so a caller never has to ask twice.
|
|
56
|
+
*/
|
|
57
|
+
export function painterFor(depth) {
|
|
58
|
+
if (depth === 0) {
|
|
59
|
+
return PLAIN;
|
|
60
|
+
}
|
|
61
|
+
const escapes = new Map(TONE_COLOURS.map((colour) => [colour.tone, escapeFor(colour, depth)]));
|
|
62
|
+
return (text, tone) => {
|
|
63
|
+
const escape = tone === undefined ? undefined : escapes.get(tone);
|
|
64
|
+
return escape === undefined || text === ""
|
|
65
|
+
? text
|
|
66
|
+
: `${escape}${text}${RESET}`;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The escape sequences a painter writes, for measuring a line's real width.
|
|
71
|
+
*
|
|
72
|
+
* The control character is the thing being matched — it is what a terminal
|
|
73
|
+
* reads and a reader never sees — so `no-control-regex` has nothing to say
|
|
74
|
+
* here.
|
|
75
|
+
*/
|
|
76
|
+
// eslint-disable-next-line no-control-regex
|
|
77
|
+
const ESCAPES = /\u{1B}\[[\d;]*m/gu;
|
|
78
|
+
/**
|
|
79
|
+
* A line with its colour taken back off.
|
|
80
|
+
*/
|
|
81
|
+
export function stripColour(text) {
|
|
82
|
+
return text.replaceAll(ESCAPES, "");
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* How many characters of a string a reader actually sees.
|
|
86
|
+
*
|
|
87
|
+
* A column padded with `padEnd` counts the escapes, so a coloured cell comes
|
|
88
|
+
* out short by however many bytes its colour took.
|
|
89
|
+
*/
|
|
90
|
+
export function visibleLength(text) {
|
|
91
|
+
return stripColour(text).length;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* How much colour to write, from what the terminal says about itself.
|
|
95
|
+
*
|
|
96
|
+
* Pure, and separate from the Node adapter that reads the signals, so that both
|
|
97
|
+
* answers can be asked for in a test rather than sniffed at run time.
|
|
98
|
+
*
|
|
99
|
+
* A file full of escape sequences is worse than no colour at all, so a pipe
|
|
100
|
+
* gets none; `NO_COLOR` is honoured because it is the convention every other
|
|
101
|
+
* tool honours; and `TERM=dumb` means what it says.
|
|
102
|
+
*/
|
|
103
|
+
export function depthFrom(signals) {
|
|
104
|
+
const { isTerminal, noColour, term = "", colorterm = "" } = signals;
|
|
105
|
+
if (!isTerminal ||
|
|
106
|
+
(noColour ?? "") !== "" ||
|
|
107
|
+
term === "dumb" ||
|
|
108
|
+
term === "") {
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
const isExtended = colorterm === "truecolor" ||
|
|
112
|
+
colorterm === "24bit" ||
|
|
113
|
+
term.includes("256color") ||
|
|
114
|
+
term.includes("direct");
|
|
115
|
+
return isExtended ? 256 : 16;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=colour.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colour.js","sourceRoot":"","sources":["../../src/cli/colour.ts"],"names":[],"mappings":"AA0CA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,YAAY,GAA0B;IAC1C,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE;IACtD,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE;IACtD,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;IACrD,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;CACtD,CAAC;AAEF;;GAEG;AACH,MAAM,KAAK,GAAG,WAAW,CAAC;AAE1B;;GAEG;AACH,SAAS,SAAS,CAAC,MAAkB,EAAE,KAAkB;IACvD,OAAO,KAAK,KAAK,GAAG;QAClB,CAAC,CAAC,eAAe,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,GAA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AAC,IAAY;IACtC,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;AAClC,CAAC;AAcD;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CAAC,OAAwB;IAChD,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IACpE,IACE,CAAC,UAAU;QACX,CAAC,QAAQ,IAAI,EAAE,CAAC,KAAK,EAAE;QACvB,IAAI,KAAK,MAAM;QACf,IAAI,KAAK,EAAE,EACX,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,UAAU,GACd,SAAS,KAAK,WAAW;QACzB,SAAS,KAAK,OAAO;QACrB,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;QACzB,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC1B,OAAO,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/B,CAAC"}
|
package/dist/cli/commands.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Dictionary } from "../dictionary/dictionary.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type Syllable } from "../syllable/syllable.js";
|
|
3
|
+
import { type DictionaryChoice, type Flags, type FlagName, type TranscriptionSource } from "./arguments.js";
|
|
4
|
+
import { type Painter } from "./colour.js";
|
|
3
5
|
/**
|
|
4
6
|
* What a command is given to work with.
|
|
5
7
|
*/
|
|
@@ -10,6 +12,15 @@ export interface CommandInput {
|
|
|
10
12
|
/** Loaded for the commands that declare they need one. */
|
|
11
13
|
readonly dictionary: Dictionary | undefined;
|
|
12
14
|
readonly choice: DictionaryChoice;
|
|
15
|
+
/**
|
|
16
|
+
* How to write a syllable, which is where tone colour is applied.
|
|
17
|
+
*
|
|
18
|
+
* Handed in rather than worked out, because whether the output is a terminal
|
|
19
|
+
* is a fact about the run and not about the command. A command that writes no
|
|
20
|
+
* syllables never calls it, and `html` deliberately does not: markup is a
|
|
21
|
+
* format for a machine, exactly as `--json` is.
|
|
22
|
+
*/
|
|
23
|
+
readonly paint: Painter;
|
|
13
24
|
}
|
|
14
25
|
/**
|
|
15
26
|
* One answer, in both the forms the CLI can write it.
|
|
@@ -44,6 +55,43 @@ export interface Command {
|
|
|
44
55
|
readonly needsDictionary: boolean;
|
|
45
56
|
readonly run: (input: CommandInput) => readonly Reported[];
|
|
46
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* How one system writes a word: a syllable at a time, and what it joins on.
|
|
60
|
+
*
|
|
61
|
+
* The `write*Word` helpers are each a map and a join, and this takes them apart
|
|
62
|
+
* so that every syllable can be painted its own colour. That duplicates five
|
|
63
|
+
* separators, so each entry carries the helper it stands in for and
|
|
64
|
+
* `commands.test.ts` asserts the two agree over the whole inventory in every
|
|
65
|
+
* tone state — rather than the list being trusted.
|
|
66
|
+
*/
|
|
67
|
+
export interface System {
|
|
68
|
+
/** What `--from` and `--system` call it. */
|
|
69
|
+
readonly name: TranscriptionSource;
|
|
70
|
+
readonly write: (syllable: Syllable) => string;
|
|
71
|
+
readonly separator: string;
|
|
72
|
+
/**
|
|
73
|
+
* How the system writes a word, with its tones or without them.
|
|
74
|
+
*
|
|
75
|
+
* `--notation none` can only be honoured where the tone is written
|
|
76
|
+
* separately*: Wade-Giles, Yale and IPA all have a way to leave it off.
|
|
77
|
+
* Bopomofo marks it with a symbol of the script and Gwoyeu Romatzyh spells
|
|
78
|
+
* it into the syllable, so for those two there is nothing to leave off and
|
|
79
|
+
* the flag is ignored rather than approximated.
|
|
80
|
+
*/
|
|
81
|
+
readonly word: (syllables: readonly Syllable[], hasTones: boolean) => string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Every system `transcribe` writes a column for, for the guard above.
|
|
85
|
+
*/
|
|
86
|
+
export declare const SYSTEMS: readonly System[];
|
|
87
|
+
/**
|
|
88
|
+
* The system a `--system` or `--from` name stands for.
|
|
89
|
+
*/
|
|
90
|
+
export declare function systemNamed(name: TranscriptionSource | undefined): System | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Write a run of syllables in one system, each syllable in its tone's colour.
|
|
93
|
+
*/
|
|
94
|
+
export declare function writtenWith(syllables: readonly Syllable[], system: System, paint: Painter): string;
|
|
47
95
|
/**
|
|
48
96
|
* Every subcommand, in the order the help lists them.
|
|
49
97
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/cli/commands.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/cli/commands.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AA6B9D,OAAO,EAEL,KAAK,QAAQ,EAGd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,KAAK,EACV,KAAK,QAAQ,EAEb,KAAK,mBAAmB,EAIzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,OAAO,EAAwB,MAAM,aAAa,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,qEAAqE;IACrE,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,0DAA0D;IAC1D,QAAQ,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC;;;;;;;OAOG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;GAOG;AACH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