@gukhanmun/wasm 0.4.0-dev.235 → 0.4.0-dev.245
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +12 -621
- package/dist/index.js +52 -5
- package/dist/wasm/deno/gukhanmun_wasm.js +4 -0
- package/dist/wasm/deno/gukhanmun_wasm_bg.wasm +0 -0
- package/dist/wasm/nodejs/gukhanmun_wasm.js +4 -0
- package/dist/wasm/nodejs/gukhanmun_wasm_bg.wasm +0 -0
- package/dist/wasm/web/gukhanmun_wasm.js +4 -0
- package/dist/wasm/web/gukhanmun_wasm_bg.wasm +0 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,613 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
//#region index.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* Canonical TypeScript API contract for Gukhanmun.
|
|
5
|
-
*
|
|
6
|
-
* This package contains only TypeScript type declarations and carries no
|
|
7
|
-
* runtime code. Both `@gukhanmun/wasm` and `@gukhanmun/napi` satisfy this
|
|
8
|
-
* contract structurally. All TSDoc lives here as the single source of
|
|
9
|
-
* truth for the JavaScript API.
|
|
10
|
-
*
|
|
11
|
-
* @module @gukhanmun/types
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Named configuration preset that sets orthographic and lexical defaults.
|
|
15
|
-
*
|
|
16
|
-
* - `"ko-kr"` — South Korean orthography: dictionary-driven readings, the
|
|
17
|
-
* initial sound law applied to fallback fragments, per-block homophone
|
|
18
|
-
* disambiguation, and the bundled *Standard Korean Language Dictionary*
|
|
19
|
-
* (標準國語大辭典). Corresponds to Rust `Preset::KoKr`.
|
|
20
|
-
* - `"ko-kp"` — North Korean orthography: no initial sound law (래일,
|
|
21
|
-
* 류행, 녀자), no bundled dictionary data. Corresponds to Rust `Preset::KoKp`.
|
|
22
|
-
*
|
|
23
|
-
* Both presets default `rendering` to `"hangul-only"` and `segmentation` to
|
|
24
|
-
* `"lattice"`. Individual options passed to {@link GukhanmunOptions} override
|
|
25
|
-
* the preset.
|
|
26
|
-
*/
|
|
27
|
-
type Preset = "ko-kr" | "ko-kp";
|
|
28
|
-
/**
|
|
29
|
-
* Controls how the renderer expands each converted hanja annotation into
|
|
30
|
-
* output text or markup. Corresponds to Rust `RenderMode`.
|
|
31
|
-
*
|
|
32
|
-
* - `"hangul-only"` — Emit only the hangul reading. When `homophone` or
|
|
33
|
-
* `require_hanja` is set on an annotation the reading is followed by the
|
|
34
|
-
* original hanja in parentheses: `한글(漢字)`. Corresponds to Rust
|
|
35
|
-
* `RenderMode::HangulOnly`.
|
|
36
|
-
* - `"hangul-hanja-parens"` — Always emit `한글(漢字)`. Corresponds to
|
|
37
|
-
* Rust `RenderMode::HangulHanjaParens`.
|
|
38
|
-
* - `"hanja-hangul-parens"` — Always emit `漢字(한글)`. Useful for
|
|
39
|
-
* academic and historical-document styles. Corresponds to Rust
|
|
40
|
-
* `RenderMode::HanjaHangulParens`.
|
|
41
|
-
* - `"ruby-on-hangul"` — Emit `<ruby>한글<rt>漢字</rt></ruby>`. Falls
|
|
42
|
-
* back to parentheses when the current scope does not permit inline markup
|
|
43
|
-
* (e.g., inside `<pre>`). Corresponds to Rust
|
|
44
|
-
* `RenderMode::Ruby(RubyBase::OnHangul)`.
|
|
45
|
-
* - `"ruby-on-hanja"` — Emit `<ruby>漢字<rt>한글</rt></ruby>`.
|
|
46
|
-
* Corresponds to Rust `RenderMode::Ruby(RubyBase::OnHanja)`.
|
|
47
|
-
* - `"original"` — Keep the original mixed-script form; only annotations
|
|
48
|
-
* with `require_hangul` or a user directive receive a hangul gloss, which
|
|
49
|
-
* appears either in parentheses or as a ruby element depending on
|
|
50
|
-
* {@link GukhanmunOptions.originalGloss}. Corresponds to Rust
|
|
51
|
-
* `RenderMode::Original`.
|
|
52
|
-
*/
|
|
53
|
-
type RenderMode = "hangul-only" | "hangul-hanja-parens" | "hanja-hangul-parens" | "ruby-on-hangul" | "ruby-on-hanja" | "original";
|
|
54
|
-
/** The hanja variant set applied after dictionary recognition. */
|
|
55
|
-
type HanjaVariantSet = "as-dictionary" | "shinjitai" | "kanxi" | "simplified" | "asahimoji";
|
|
56
|
-
/**
|
|
57
|
-
* Selects how glosses are rendered when {@link RenderMode} is `"original"`.
|
|
58
|
-
*
|
|
59
|
-
* - `"parens"` — Wrap the gloss in parentheses: `漢字(한글)` (default).
|
|
60
|
-
* Corresponds to Rust `OriginalGloss::Parens`.
|
|
61
|
-
* - `"ruby"` — Wrap the gloss in a `<ruby>` element. Falls back to
|
|
62
|
-
* parentheses in scopes that do not permit inline markup. Corresponds to
|
|
63
|
-
* Rust `OriginalGloss::Ruby`.
|
|
64
|
-
*
|
|
65
|
-
* This option is ignored when `rendering` is not `"original"`.
|
|
66
|
-
*/
|
|
67
|
-
type OriginalGloss = "parens" | "ruby";
|
|
68
|
-
/**
|
|
69
|
-
* Controls how the engine segments a hanja-containing span into dictionary
|
|
70
|
-
* words and fallback fragments. Corresponds to Rust `SegmentationStrategy`.
|
|
71
|
-
*
|
|
72
|
-
* - `"lattice"` — Dynamic programming over all possible dictionary matches
|
|
73
|
-
* at each position; selects the segmentation that maximises dictionary
|
|
74
|
-
* coverage and then prefers fewer segments. This is the default and
|
|
75
|
-
* produces better results than greedy approaches when a longer prefix
|
|
76
|
-
* would leave a suffix uncovered by the dictionary. Corresponds to Rust
|
|
77
|
-
* `SegmentationStrategy::Lattice`.
|
|
78
|
-
* - `"eager"` — Left-to-right longest-match (greedy). Lower overhead per
|
|
79
|
-
* span at the cost of occasional mis-segmentation. Corresponds to Rust
|
|
80
|
-
* `SegmentationStrategy::Eager`.
|
|
81
|
-
*/
|
|
82
|
-
type Segmentation = "lattice" | "eager";
|
|
83
|
-
/**
|
|
84
|
-
* Controls how runs of hanja numerals are converted. Corresponds to Rust
|
|
85
|
-
* `NumeralStrategy`.
|
|
86
|
-
*
|
|
87
|
-
* | Strategy | `二〇一六年` | `十一月` | `一千二百三十四` |
|
|
88
|
-
* | --------------------- | ------------ | -------- | ---------------- |
|
|
89
|
-
* | `"hangul-phonetic"` | 이공일륙년 | 십일월 | 일천이백삼십사 |
|
|
90
|
-
* | `"positional-arabic"` | 2016년 | (n/a) | (n/a) |
|
|
91
|
-
* | `"additive-arabic"` | (n/a) | 11월 | 1234 |
|
|
92
|
-
* | `"smart"` | 2016년 | 11월 | 1234 |
|
|
93
|
-
*
|
|
94
|
-
* - `"hangul-phonetic"` — Read every digit character-by-character in
|
|
95
|
-
* Korean phonetics. This is Seonbi's behaviour and the preset default.
|
|
96
|
-
* Corresponds to Rust `NumeralStrategy::HangulPhonetic`.
|
|
97
|
-
* - `"positional-arabic"` — Treat a run of digit-only hanja
|
|
98
|
-
* (`〇一二三四五六七八九` and variants) as positional (place-value)
|
|
99
|
-
* notation and convert to Arabic. Corresponds to Rust
|
|
100
|
-
* `NumeralStrategy::PositionalArabic`.
|
|
101
|
-
* - `"additive-arabic"` — Parse sequences containing place markers
|
|
102
|
-
* (`十百千萬億兆京`) using stack-based accumulation and produce Arabic,
|
|
103
|
-
* respecting the Korean convention that bare `十` means 10 not `一十`.
|
|
104
|
-
* Corresponds to Rust `NumeralStrategy::AdditiveArabic`.
|
|
105
|
-
* - `"smart"` — Uses `"additive-arabic"` for additive numerals that
|
|
106
|
-
* begin with a digit, and for small-place-marker starts (`十`, `百`,
|
|
107
|
-
* `千`) unless the next character is an ambiguous non-unit hanja word
|
|
108
|
-
* character; uses `"positional-arabic"` for pure-digit runs of four or
|
|
109
|
-
* more characters (year convention) or when a unit hanja follows the
|
|
110
|
-
* digit run (`年月日時分秒號世紀` and others); otherwise falls back to
|
|
111
|
-
* `"hangul-phonetic"`. Corresponds to Rust `NumeralStrategy::Smart`.
|
|
112
|
-
*/
|
|
113
|
-
type NumeralStrategy = "hangul-phonetic" | "positional-arabic" | "additive-arabic" | "smart";
|
|
114
|
-
/**
|
|
115
|
-
* Defines the scope within which the homophone marker and first-occurrence
|
|
116
|
-
* filter track previously seen readings. Corresponds to Rust `ContextWindow`.
|
|
117
|
-
*
|
|
118
|
-
* - `"off"` — Disable the corresponding middleware entirely.
|
|
119
|
-
* - `"per-block"` — Reset at each block boundary (paragraph, list item,
|
|
120
|
-
* heading, …). This is the default for both homophone marking and first-
|
|
121
|
-
* occurrence filtering. In plain text, which has no block scopes, `per-block`
|
|
122
|
-
* is document-wide.
|
|
123
|
-
* - `"per-section"` — Reset at each heading boundary (HTML `<h1>`–`<h6>`,
|
|
124
|
-
* Markdown ATX/setext headings).
|
|
125
|
-
* - `"per-document"` — Track across the entire document. This buffers the
|
|
126
|
-
* entire token stream and is appropriate only for small inputs or when full
|
|
127
|
-
* accuracy matters more than latency.
|
|
128
|
-
*/
|
|
129
|
-
type ContextWindow = "off" | "per-block" | "per-section" | "per-document";
|
|
130
|
-
/**
|
|
131
|
-
* Selects how the homophone marker decides that a reading needs its hanja shown
|
|
132
|
-
* in `rendering: "hangul-only"`. Corresponds to Rust `HomophoneDetection`.
|
|
133
|
-
*
|
|
134
|
-
* - `"context-local"` — Gloss a reading only when a different-meaning homophone
|
|
135
|
-
* actually appears within the {@link ContextWindow}. This keeps hangul-only
|
|
136
|
-
* output clean and is the default.
|
|
137
|
-
* - `"dictionary-wide"` — Also gloss readings shared by other hanja forms
|
|
138
|
-
* anywhere in the dictionary, even when no homophone appears in the text.
|
|
139
|
-
* With a large reference dictionary this glosses most Sino-Korean words; words
|
|
140
|
-
* that should always be glossed are better expressed with `requireHanja`.
|
|
141
|
-
*/
|
|
142
|
-
type HomophoneDetection = "context-local" | "dictionary-wide";
|
|
143
|
-
/**
|
|
144
|
-
* Controls how the pipeline handles reader errors encountered during HTML
|
|
145
|
-
* scanning. Corresponds to Rust `Recovery`.
|
|
146
|
-
*
|
|
147
|
-
* - `"strict"` — Propagate the error and stop (default).
|
|
148
|
-
* - `"lenient"` — Log the error via `tracing` and emit a verbatim token for
|
|
149
|
-
* the unrecognised region so that downstream tokens continue to flow.
|
|
150
|
-
*
|
|
151
|
-
* This option is meaningful only for `format: "html"`. Markdown parsing does
|
|
152
|
-
* not produce recoverable errors, so this option is ignored for Markdown input.
|
|
153
|
-
*/
|
|
154
|
-
type Recovery = "strict" | "lenient";
|
|
155
|
-
/**
|
|
156
|
-
* A single dictionary entry returned by a dictionary lookup.
|
|
157
|
-
*/
|
|
158
|
-
interface DictionaryEntry {
|
|
159
|
-
/** The hanja form (key), e.g. `"漢字"`. */
|
|
160
|
-
readonly hanja: string;
|
|
161
|
-
/** The hangul reading, e.g. `"한자"`. */
|
|
162
|
-
readonly reading: string;
|
|
163
|
-
/**
|
|
164
|
-
* When `true`, the renderer should always show the original hanja
|
|
165
|
-
* alongside the hangul reading, regardless of ambiguity.
|
|
166
|
-
*
|
|
167
|
-
* Corresponds to Rust `MatchMark::require_hanja`.
|
|
168
|
-
*/
|
|
169
|
-
readonly requireHanja?: boolean;
|
|
170
|
-
/**
|
|
171
|
-
* When `true`, the renderer should always show a hangul gloss alongside
|
|
172
|
-
* the original hanja (used with `rendering: "original"`).
|
|
173
|
-
*
|
|
174
|
-
* Corresponds to Rust `MatchMark::require_hangul`.
|
|
175
|
-
*/
|
|
176
|
-
readonly requireHangul?: boolean;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Specifies a dictionary loaded from a binary file or URL.
|
|
180
|
-
*
|
|
181
|
-
* The `data` field accepts:
|
|
182
|
-
* - A `BufferSource` (`ArrayBuffer` or `ArrayBufferView`) — supported in all
|
|
183
|
-
* environments.
|
|
184
|
-
* - A `URL` — resolved via `fetch` in browsers; via `node:fs/promises`
|
|
185
|
-
* in Node.js, Deno 2.0+, and Bun.
|
|
186
|
-
* - A `string` — treated as a filesystem path; supported in Node.js,
|
|
187
|
-
* Deno 2.0+, and Bun only. Throws in browser environments.
|
|
188
|
-
*
|
|
189
|
-
* At runtime, a `FileDictionarySource` is distinguished from other values by
|
|
190
|
-
* the presence of a `format` property (`"format" in source`).
|
|
191
|
-
*/
|
|
192
|
-
interface FileDictionarySource {
|
|
193
|
-
/**
|
|
194
|
-
* The binary dictionary data or a reference to where it can be loaded.
|
|
195
|
-
*
|
|
196
|
-
* Pass a `BufferSource` for data already in memory, a `URL` for a remote
|
|
197
|
-
* or local URL (resolved via `fetch` or `readFile`), or a path `string`
|
|
198
|
-
* for filesystem paths (Node.js / Deno 2.0+ / Bun only).
|
|
199
|
-
*/
|
|
200
|
-
readonly data: ArrayBuffer | ArrayBufferView | URL | string;
|
|
201
|
-
/**
|
|
202
|
-
* The on-disk format of the dictionary file.
|
|
203
|
-
*
|
|
204
|
-
* - `"fst"` — Gukhanmun FST file (`*.gukfst`); preferred for small
|
|
205
|
-
* WebAssembly bundles. Supported in all runtimes.
|
|
206
|
-
* - `"cdb"` — Gukhanmun CDB-trie file (`*.gukcdb`); preferred when code
|
|
207
|
-
* auditability or trivial mmap support matters. Requires a filesystem
|
|
208
|
-
* or in-memory bytes; supported in Node-API and (with `from_bytes`) in
|
|
209
|
-
* WASM builds that include the `cdb` feature.
|
|
210
|
-
*
|
|
211
|
-
* The `"tsv"` format is reserved for future use; passing it throws
|
|
212
|
-
* `GukhanmunError` with code `"unsupported-content-type"`.
|
|
213
|
-
*/
|
|
214
|
-
readonly format: "fst" | "cdb";
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* A dictionary source accepted by {@link GukhanmunOptions.dictionaries}.
|
|
218
|
-
*
|
|
219
|
-
* Currently only {@link FileDictionarySource} (binary file / URL / path) is
|
|
220
|
-
* supported. Sources are tried in array order; the first match wins.
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* ```ts
|
|
224
|
-
* import { stdictFst } from "@gukhanmun/stdict-fst";
|
|
225
|
-
* const g = await load({ dictionaries: [await stdictFst()] });
|
|
226
|
-
* ```
|
|
227
|
-
*/
|
|
228
|
-
type DictionarySource = FileDictionarySource;
|
|
229
|
-
/**
|
|
230
|
-
* Fine-grained HTML preservation rules passed in
|
|
231
|
-
* {@link GukhanmunOptions.html}.
|
|
232
|
-
*
|
|
233
|
-
* These are additive: a scope is preserved when *any* rule matches. They
|
|
234
|
-
* correspond to the CLI flags `--html-preserve-class` and
|
|
235
|
-
* `--html-preserve-attr`, and to the Rust `Builder::html_preserve_when`
|
|
236
|
-
* predicate.
|
|
237
|
-
*/
|
|
238
|
-
interface HtmlOptions {
|
|
239
|
-
/**
|
|
240
|
-
* Class names whose containing element (and all descendants) should be
|
|
241
|
-
* treated as a preserved region—the engine skips their text content.
|
|
242
|
-
*
|
|
243
|
-
* Equivalent to passing `--html-preserve-class NAME` to the CLI one or
|
|
244
|
-
* more times.
|
|
245
|
-
*/
|
|
246
|
-
readonly preserveClasses?: readonly string[];
|
|
247
|
-
/**
|
|
248
|
-
* Attribute matchers; an element is preserved when it carries a matching
|
|
249
|
-
* attribute. Each entry is either:
|
|
250
|
-
* - A bare string — preserve any element that has the attribute, regardless
|
|
251
|
-
* of value (e.g. `"data-no-translate"`).
|
|
252
|
-
* - An object `{ name, value? }` — preserve elements where the attribute
|
|
253
|
-
* equals `value`, or has the attribute when `value` is omitted.
|
|
254
|
-
*
|
|
255
|
-
* Equivalent to `--html-preserve-attr KEY[=VALUE]` on the CLI.
|
|
256
|
-
*/
|
|
257
|
-
readonly preserveAttributes?: readonly (string | {
|
|
258
|
-
readonly name: string;
|
|
259
|
-
readonly value?: string;
|
|
260
|
-
})[];
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Per-hanja rendering directives that override the dictionary's own marks.
|
|
264
|
-
*
|
|
265
|
-
* Each list contains hanja forms (exact string matches, e.g. `"漢字"`).
|
|
266
|
-
* JavaScript bindings expose only the literal-set form; glob and predicate
|
|
267
|
-
* variants are available in the Rust API only.
|
|
268
|
-
*
|
|
269
|
-
* Corresponds to Rust `UserDirectives` with `DirectiveAction::RequireHanja`,
|
|
270
|
-
* `DirectiveAction::RequireHangul`, and `DirectiveAction::SkipAnnotation`.
|
|
271
|
-
*/
|
|
272
|
-
interface Directives {
|
|
273
|
-
/**
|
|
274
|
-
* Hanja forms that must always be shown with their original hanja
|
|
275
|
-
* alongside the hangul reading, as if `requireHanja` were set in the
|
|
276
|
-
* dictionary.
|
|
277
|
-
*/
|
|
278
|
-
readonly requireHanja?: readonly string[];
|
|
279
|
-
/**
|
|
280
|
-
* Hanja forms that must always be shown with a hangul gloss alongside the
|
|
281
|
-
* original hanja (relevant for `rendering: "original"`).
|
|
282
|
-
*/
|
|
283
|
-
readonly requireHangul?: readonly string[];
|
|
284
|
-
/**
|
|
285
|
-
* Hanja forms whose annotation should be suppressed entirely; the renderer
|
|
286
|
-
* emits only the primary plain text form (hangul or hanja depending on
|
|
287
|
-
* `rendering`).
|
|
288
|
-
*/
|
|
289
|
-
readonly skipAnnotation?: readonly string[];
|
|
290
|
-
}
|
|
291
|
-
/** Policy for ordinary spaces following an eligible stop. */
|
|
292
|
-
type SpaceAfter = "preserve" | "remove" | "single";
|
|
293
|
-
/** Built-in output style; input recognition is independent of this choice. */
|
|
294
|
-
type PunctuationPreset = "preserve" | "modern" | "traditional" | "traditional-vertical";
|
|
295
|
-
/** A single Unicode scalar and its following U+0020 policy. */
|
|
296
|
-
interface StopStyle {
|
|
297
|
-
/** One Unicode scalar, validated by the shared profile resolver. */
|
|
298
|
-
readonly mark: string;
|
|
299
|
-
/** Policy applied only to U+0020 following this stop. */
|
|
300
|
-
readonly after: SpaceAfter;
|
|
301
|
-
}
|
|
302
|
-
/** Opening and closing Unicode punctuation scalars. */
|
|
303
|
-
interface DelimiterStyle {
|
|
304
|
-
/** Opening scalar with Unicode category Ps or Pi. */
|
|
305
|
-
readonly open: string;
|
|
306
|
-
/** Closing scalar with Unicode category Pe or Pf. */
|
|
307
|
-
readonly close: string;
|
|
308
|
-
}
|
|
309
|
-
/** Partial overrides; omitted roles inherit, null preserves the role. */
|
|
310
|
-
interface CustomPunctuationProfile {
|
|
311
|
-
/** Inherited preset, defaulting to preserve. */
|
|
312
|
-
readonly base?: PunctuationPreset;
|
|
313
|
-
/** Comma style; omitted inherits, null preserves. */
|
|
314
|
-
readonly comma?: StopStyle | null;
|
|
315
|
-
/** Period style; omitted inherits, null preserves. */
|
|
316
|
-
readonly period?: StopStyle | null;
|
|
317
|
-
/** Single delimiters; omitted inherits, null preserves. */
|
|
318
|
-
readonly single?: DelimiterStyle | null;
|
|
319
|
-
/** Double delimiters; omitted inherits, null preserves. */
|
|
320
|
-
readonly double?: DelimiterStyle | null;
|
|
321
|
-
}
|
|
322
|
-
/** Fully resolved styles, copied and deeply frozen by each binding. */
|
|
323
|
-
interface ResolvedPunctuationProfile {
|
|
324
|
-
/** Comma style, or null for preservation. */
|
|
325
|
-
readonly comma: StopStyle | null;
|
|
326
|
-
/** Period style, or null for preservation. */
|
|
327
|
-
readonly period: StopStyle | null;
|
|
328
|
-
/** Single delimiters, or null for preservation. */
|
|
329
|
-
readonly single: DelimiterStyle | null;
|
|
330
|
-
/** Double delimiters, or null for preservation. */
|
|
331
|
-
readonly double: DelimiterStyle | null;
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Full set of options passed to {@link GukhanmunFactory.load} (or the
|
|
335
|
-
* top-level `load` function) to configure a {@link Gukhanmun} instance.
|
|
336
|
-
*
|
|
337
|
-
* All fields are optional. When a `preset` is specified it supplies
|
|
338
|
-
* defaults; individual fields override those defaults. When no preset is
|
|
339
|
-
* given, `"ko-kr"` is implicitly used.
|
|
340
|
-
*/
|
|
341
|
-
interface GukhanmunOptions {
|
|
342
|
-
/** Independent output punctuation policy. Defaults to preserve. */
|
|
343
|
-
readonly punctuation?: PunctuationPreset | CustomPunctuationProfile;
|
|
344
|
-
/**
|
|
345
|
-
* Named configuration preset. Defaults to `"ko-kr"`.
|
|
346
|
-
*
|
|
347
|
-
* @see {@link Preset}
|
|
348
|
-
*/
|
|
349
|
-
readonly preset?: Preset;
|
|
350
|
-
/**
|
|
351
|
-
* How annotations are rendered into output text or markup. Defaults to
|
|
352
|
-
* `"hangul-only"`.
|
|
353
|
-
*
|
|
354
|
-
* @see {@link RenderMode}
|
|
355
|
-
*/
|
|
356
|
-
readonly rendering?: RenderMode;
|
|
357
|
-
/**
|
|
358
|
-
* How glosses are rendered when `rendering` is `"original"`. Ignored for
|
|
359
|
-
* all other render modes. Defaults to `"parens"`.
|
|
360
|
-
*
|
|
361
|
-
* @see {@link OriginalGloss}
|
|
362
|
-
*/
|
|
363
|
-
readonly originalGloss?: OriginalGloss;
|
|
364
|
-
/** The hanja variant set. Defaults to `"as-dictionary"`. */
|
|
365
|
-
readonly hanjaVariantSet?: HanjaVariantSet;
|
|
366
|
-
/**
|
|
367
|
-
* Hanja-span segmentation algorithm. Defaults to `"lattice"`.
|
|
368
|
-
*
|
|
369
|
-
* @see {@link Segmentation}
|
|
370
|
-
*/
|
|
371
|
-
readonly segmentation?: Segmentation;
|
|
372
|
-
/**
|
|
373
|
-
* How runs of hanja numerals are converted. Defaults to
|
|
374
|
-
* `"hangul-phonetic"`.
|
|
375
|
-
*
|
|
376
|
-
* @see {@link NumeralStrategy}
|
|
377
|
-
*/
|
|
378
|
-
readonly numerals?: NumeralStrategy;
|
|
379
|
-
/**
|
|
380
|
-
* Whether to apply the Korean initial sound law (頭音法則) to fallback
|
|
381
|
-
* phonetic readings. Defaults to `true` for `"ko-kr"` and `false` for
|
|
382
|
-
* `"ko-kp"`.
|
|
383
|
-
*
|
|
384
|
-
* Note: dictionary entries are assumed to encode the correct reading
|
|
385
|
-
* already; this flag only affects the character-by-character fallback path.
|
|
386
|
-
*/
|
|
387
|
-
readonly initialSoundLaw?: boolean;
|
|
388
|
-
/**
|
|
389
|
-
* Context window for homophone disambiguation. The `HomophoneMarker`
|
|
390
|
-
* middleware sets `homophone = true` on annotations whose hangul reading
|
|
391
|
-
* collides within this window. Defaults to `"per-block"`.
|
|
392
|
-
*
|
|
393
|
-
* @see {@link ContextWindow}
|
|
394
|
-
*/
|
|
395
|
-
readonly homophoneWindow?: ContextWindow;
|
|
396
|
-
/**
|
|
397
|
-
* Strategy that decides which readings count as homophones needing a hanja
|
|
398
|
-
* gloss. Defaults to `"context-local"`, which glosses a reading only when a
|
|
399
|
-
* different-meaning homophone appears within {@link homophoneWindow}. Use
|
|
400
|
-
* `"dictionary-wide"` to also gloss readings shared by other dictionary
|
|
401
|
-
* entries.
|
|
402
|
-
*
|
|
403
|
-
* @see {@link HomophoneDetection}
|
|
404
|
-
*/
|
|
405
|
-
readonly homophoneDetection?: HomophoneDetection;
|
|
406
|
-
/**
|
|
407
|
-
* Context window for first-occurrence filtering. The
|
|
408
|
-
* `FirstOccurrenceFilter` middleware clears `requireHanja` /
|
|
409
|
-
* `requireHangul` on repeated occurrences of the same word within this
|
|
410
|
-
* window, so the gloss appears only the first time. Defaults to `"off"`
|
|
411
|
-
* (filter disabled) in both presets.
|
|
412
|
-
*
|
|
413
|
-
* @see {@link ContextWindow}
|
|
414
|
-
*/
|
|
415
|
-
readonly firstOccurrenceWindow?: ContextWindow;
|
|
416
|
-
/**
|
|
417
|
-
* Whether to collapse redundant parenthetical reading annotations. Defaults
|
|
418
|
-
* to `true`.
|
|
419
|
-
*
|
|
420
|
-
* When enabled, an explicit gloss such as `庫間(곳간)` or `곳간(庫間)` is
|
|
421
|
-
* recognised, the redundant parenthetical is removed, and the annotation is
|
|
422
|
-
* shown in both scripts in every render mode. A parenthetical that pins an
|
|
423
|
-
* alternative reading (for example `數字(수자)`) overrides the dictionary
|
|
424
|
-
* reading for that occurrence. A parenthetical that is a definition rather
|
|
425
|
-
* than a reading (for example `庫間(물건을 간직하여 두는 곳)`) is left
|
|
426
|
-
* untouched.
|
|
427
|
-
*/
|
|
428
|
-
readonly collapseRedundantParens?: boolean;
|
|
429
|
-
/**
|
|
430
|
-
* Error recovery policy for HTML scanning. Defaults to `"strict"`.
|
|
431
|
-
* Ignored for non-HTML input formats.
|
|
432
|
-
*
|
|
433
|
-
* @see {@link Recovery}
|
|
434
|
-
*/
|
|
435
|
-
readonly recovery?: Recovery;
|
|
436
|
-
/**
|
|
437
|
-
* Ordered list of dictionary sources. Sources are queried in order;
|
|
438
|
-
* earlier entries take precedence. When omitted (or empty), only the
|
|
439
|
-
* fallback Unihan character map is used (no bundled dictionaries).
|
|
440
|
-
*
|
|
441
|
-
* JavaScript presets do **not**
|
|
442
|
-
* automatically include bundled dictionary data. To use the *Standard
|
|
443
|
-
* Korean Language Dictionary*, add `@gukhanmun/stdict-fst` or
|
|
444
|
-
* `@gukhanmun/stdict-cdb` explicitly. To use Open Korean Dictionary
|
|
445
|
-
* categories, add `@gukhanmun/opendict-fst` or
|
|
446
|
-
* `@gukhanmun/opendict-cdb` explicitly. For NIKL loanword examples, load
|
|
447
|
-
* `@gukhanmun/loanwords-fst` or `@gukhanmun/loanwords-cdb`. Put user
|
|
448
|
-
* dictionaries first, then loanwords, then the preset dictionaries.
|
|
449
|
-
*
|
|
450
|
-
* @see {@link DictionarySource}
|
|
451
|
-
*/
|
|
452
|
-
readonly dictionaries?: readonly DictionarySource[];
|
|
453
|
-
/**
|
|
454
|
-
* Per-hanja rendering directives that override dictionary marks.
|
|
455
|
-
*
|
|
456
|
-
* @see {@link Directives}
|
|
457
|
-
*/
|
|
458
|
-
readonly directives?: Directives;
|
|
459
|
-
/**
|
|
460
|
-
* HTML-specific preservation rules. Ignored for non-HTML input formats.
|
|
461
|
-
*
|
|
462
|
-
* @see {@link HtmlOptions}
|
|
463
|
-
*/
|
|
464
|
-
readonly html?: HtmlOptions;
|
|
465
|
-
}
|
|
466
|
-
/**
|
|
467
|
-
* Input / output format for {@link Gukhanmun.convert} and
|
|
468
|
-
* {@link Gukhanmun.stream}.
|
|
469
|
-
*
|
|
470
|
-
* - `"text"` — Plain text (default). No markup interpretation; ruby
|
|
471
|
-
* rendering falls back to parentheses.
|
|
472
|
-
* - `"html"` — HTML fragment. The scanner is fragment-oriented and recovers
|
|
473
|
-
* from minor malformations.
|
|
474
|
-
* - `"markdown"` — CommonMark Markdown (GFM disabled by default).
|
|
475
|
-
* - `{ format: "markdown"; gfm?: boolean }` — Markdown with optional GFM
|
|
476
|
-
* extensions. Set `gfm: true` to enable GitHub Flavored Markdown tables,
|
|
477
|
-
* strikethrough, and task lists.
|
|
478
|
-
*
|
|
479
|
-
* The object form `{ format: "markdown" }` is equivalent to the string
|
|
480
|
-
* `"markdown"`.
|
|
481
|
-
*/
|
|
482
|
-
type Format = "text" | "html" | "markdown" | {
|
|
483
|
-
readonly format: "markdown";
|
|
484
|
-
readonly gfm?: boolean;
|
|
485
|
-
};
|
|
486
|
-
/**
|
|
487
|
-
* A configured hanja-to-hangul converter. Created by calling
|
|
488
|
-
* {@link GukhanmunFactory.load} (or the top-level `load` function).
|
|
489
|
-
*
|
|
490
|
-
* The instance is immutable after creation; call `load` again to obtain a
|
|
491
|
-
* converter with different options.
|
|
492
|
-
*/
|
|
493
|
-
interface Gukhanmun {
|
|
494
|
-
/**
|
|
495
|
-
* Converts `source` to hangul in one shot. Buffers the entire input
|
|
496
|
-
* before returning.
|
|
497
|
-
*
|
|
498
|
-
* @param source - The text to convert.
|
|
499
|
-
* @param format - Input / output format. Defaults to `"text"`.
|
|
500
|
-
* @returns The converted text.
|
|
501
|
-
* @throws {@link GukhanmunError} on conversion failure.
|
|
502
|
-
*/
|
|
503
|
-
convert(source: string, format?: Format): string;
|
|
504
|
-
/**
|
|
505
|
-
* Returns a `TransformStream<string, string>` that converts chunks
|
|
506
|
-
* incrementally. Chunks are JavaScript strings; byte-level encoding is
|
|
507
|
-
* the caller's responsibility (`TextDecoderStream` / `TextEncoderStream`).
|
|
508
|
-
*
|
|
509
|
-
* The stream guarantees that the concatenated output equals the result of
|
|
510
|
-
* calling `convert` on the concatenated input, regardless of chunk
|
|
511
|
-
* boundaries. Document-wide middlewares (e.g., homophone marking with
|
|
512
|
-
* `homophoneWindow: "per-document"`) buffer until the writable side is
|
|
513
|
-
* closed.
|
|
514
|
-
*
|
|
515
|
-
* @param format - Input / output format. Defaults to `"text"`.
|
|
516
|
-
* @returns A platform `TransformStream<string, string>`.
|
|
517
|
-
* @throws {@link GukhanmunError} on initialisation failure (not on chunk
|
|
518
|
-
* errors; those are signalled via the stream's error channel).
|
|
519
|
-
*/
|
|
520
|
-
stream(format?: Format): TransformStream<string, string>;
|
|
521
|
-
/**
|
|
522
|
-
* Read-only view of the resolved options (after preset defaults are
|
|
523
|
-
* applied). Excludes `dictionaries`, `directives`, `html`, and
|
|
524
|
-
* `originalGloss`, which are not meaningfully representable as plain
|
|
525
|
-
* values.
|
|
526
|
-
*/
|
|
527
|
-
readonly options: Readonly<Required<Omit<GukhanmunOptions, "dictionaries" | "directives" | "html" | "originalGloss" | "punctuation">> & {
|
|
528
|
-
readonly punctuation: ResolvedPunctuationProfile;
|
|
529
|
-
}>;
|
|
530
|
-
}
|
|
531
|
-
/**
|
|
532
|
-
* Factory interface satisfied by both `@gukhanmun/wasm` and
|
|
533
|
-
* `@gukhanmun/napi`.
|
|
534
|
-
*
|
|
535
|
-
* @example
|
|
536
|
-
* ```ts
|
|
537
|
-
* import { load } from "@gukhanmun/wasm";
|
|
538
|
-
* import { stdictFst } from "@gukhanmun/stdict-fst";
|
|
539
|
-
*
|
|
540
|
-
* const g = await load({
|
|
541
|
-
* preset: "ko-kr",
|
|
542
|
-
* dictionaries: [await stdictFst()],
|
|
543
|
-
* });
|
|
544
|
-
* console.log(g.convert("漢字를 한글로"));
|
|
545
|
-
* ```
|
|
546
|
-
*/
|
|
547
|
-
interface GukhanmunFactory {
|
|
548
|
-
/**
|
|
549
|
-
* Loads and initialises a {@link Gukhanmun} converter with the given
|
|
550
|
-
* options.
|
|
551
|
-
*
|
|
552
|
-
* In the WASM implementation this involves asynchronous `.wasm` binary
|
|
553
|
-
* initialisation; in the Node-API implementation the native addon is
|
|
554
|
-
* synchronously ready but still returns a `Promise` for API uniformity.
|
|
555
|
-
* Dictionary sources with `URL` or string `data` are fetched / read during
|
|
556
|
-
* this call.
|
|
557
|
-
*
|
|
558
|
-
* @param options - Conversion options. All fields are optional; unset
|
|
559
|
-
* fields inherit defaults from the selected `preset` (or `"ko-kr"` when
|
|
560
|
-
* no preset is given).
|
|
561
|
-
* @returns A ready-to-use {@link Gukhanmun} instance.
|
|
562
|
-
* @throws {@link GukhanmunError} when an option value is unrecognised
|
|
563
|
-
* (`code: "invalid-input"`) or a dictionary fails to load
|
|
564
|
-
* (`code: "dictionary-load"`).
|
|
565
|
-
*/
|
|
566
|
-
load(options?: GukhanmunOptions): Promise<Gukhanmun>;
|
|
567
|
-
}
|
|
568
|
-
/**
|
|
569
|
-
* Top-level entry point exported by both `@gukhanmun/wasm` and
|
|
570
|
-
* `@gukhanmun/napi` as a named export.
|
|
571
|
-
*
|
|
572
|
-
* Equivalent to `new GukhanmunFactory().load(options)`. Declared here so
|
|
573
|
-
* that code that `import { load }` from either implementation package
|
|
574
|
-
* type-checks against the same signature.
|
|
575
|
-
*/
|
|
576
|
-
|
|
577
|
-
/**
|
|
578
|
-
* Discriminant code carried by every {@link GukhanmunError}.
|
|
579
|
-
*
|
|
580
|
-
* - `"dictionary-load"` — A dictionary file could not be opened, read, or
|
|
581
|
-
* decoded.
|
|
582
|
-
* - `"segmentation"` — The lattice segmenter encountered an internal
|
|
583
|
-
* inconsistency.
|
|
584
|
-
* - `"invalid-reading"` — A dictionary entry's hangul reading is not valid
|
|
585
|
-
* hangul.
|
|
586
|
-
* - `"html-scan"` — The HTML scanner encountered an unrecoverable error.
|
|
587
|
-
* - `"html-malformed-attr"` — An HTML attribute string could not be parsed.
|
|
588
|
-
* - `"markdown"` — The Markdown adapter encountered a parsing error.
|
|
589
|
-
* - `"unsupported-content-type"` — An unrecognised format string was passed
|
|
590
|
-
* to `convert` or `stream`.
|
|
591
|
-
* - `"invalid-input"` — An option value is not in the expected set (e.g. an
|
|
592
|
-
* unrecognised preset or render mode string).
|
|
593
|
-
* - `"io"` — An I/O error occurred (file read, network, …).
|
|
594
|
-
* - `"internal"` — An internal invariant was violated; this is a bug.
|
|
595
|
-
* - `"other"` — Any other error not covered by the above codes.
|
|
596
|
-
*/
|
|
597
|
-
type ErrorCode = "dictionary-load" | "segmentation" | "invalid-reading" | "html-scan" | "html-malformed-attr" | "markdown" | "unsupported-content-type" | "invalid-input" | "io" | "internal" | "other";
|
|
598
|
-
/**
|
|
599
|
-
* Error class thrown by all Gukhanmun operations.
|
|
600
|
-
*
|
|
601
|
-
* Declared here as a `declare class` so this package remains purely
|
|
602
|
-
* type-level. The actual class (with identical shape) is provided by each
|
|
603
|
-
* runtime package (`@gukhanmun/wasm` and `@gukhanmun/napi`).
|
|
604
|
-
*
|
|
605
|
-
* The `chain` property exposes the Rust `Error::source()` chain materialised
|
|
606
|
-
* at the FFI boundary, allowing callers to inspect underlying causes without
|
|
607
|
-
* additional FFI calls.
|
|
608
|
-
*/
|
|
609
|
-
//#endregion
|
|
610
|
-
//#region index.d.ts
|
|
1
|
+
import { ContextWindow, CustomPunctuationProfile, DelimiterStyle, DictionaryEntry, DictionarySource, Directives, ErrorCode, ErrorCode as ErrorCode$1, FileDictionarySource, Format, Gukhanmun, Gukhanmun as Gukhanmun$1, GukhanmunFactory, GukhanmunOptions, GukhanmunOptions as GukhanmunOptions$1, HanjaVariantSet, HomophoneDetection, HtmlOptions, MapDictionarySource, NumeralStrategy, OriginalGloss, Preset, PunctuationPreset, Recovery, RenderMode, ResolvedPunctuationProfile, Segmentation, SpaceAfter, StopStyle } from "@gukhanmun/types";
|
|
611
2
|
/**
|
|
612
3
|
* Error thrown by `{@link load}`, `{@link Gukhanmun.convert}`, and
|
|
613
4
|
* `{@link Gukhanmun.stream}` when the Rust engine reports a failure.
|
|
@@ -616,20 +7,20 @@ type ErrorCode = "dictionary-load" | "segmentation" | "invalid-reading" | "html-
|
|
|
616
7
|
* materialised at the FFI boundary so callers do not need additional round
|
|
617
8
|
* trips.
|
|
618
9
|
*/
|
|
619
|
-
declare class GukhanmunError extends Error {
|
|
10
|
+
export declare class GukhanmunError extends Error {
|
|
620
11
|
/**
|
|
621
12
|
* Machine-readable error code.
|
|
622
13
|
*
|
|
623
14
|
* @see {@link ErrorCode}
|
|
624
15
|
*/
|
|
625
|
-
readonly code: ErrorCode;
|
|
16
|
+
readonly code: ErrorCode$1;
|
|
626
17
|
/**
|
|
627
18
|
* Full causal chain from the Rust `Error::source()` traversal, materialised
|
|
628
19
|
* at the FFI boundary. The first element is the root cause; the last is
|
|
629
20
|
* the immediate error.
|
|
630
21
|
*/
|
|
631
22
|
readonly chain: readonly {
|
|
632
|
-
readonly code: ErrorCode;
|
|
23
|
+
readonly code: ErrorCode$1;
|
|
633
24
|
readonly message: string;
|
|
634
25
|
}[];
|
|
635
26
|
/**
|
|
@@ -639,8 +30,8 @@ declare class GukhanmunError extends Error {
|
|
|
639
30
|
* @param message - Human-readable description.
|
|
640
31
|
* @param chain - Optional causal chain.
|
|
641
32
|
*/
|
|
642
|
-
constructor(code: ErrorCode, message: string, chain?: readonly {
|
|
643
|
-
code: ErrorCode;
|
|
33
|
+
constructor(code: ErrorCode$1, message: string, chain?: readonly {
|
|
34
|
+
code: ErrorCode$1;
|
|
644
35
|
message: string;
|
|
645
36
|
}[]);
|
|
646
37
|
}
|
|
@@ -648,9 +39,10 @@ declare class GukhanmunError extends Error {
|
|
|
648
39
|
* Creates a Gukhanmun converter with the given options.
|
|
649
40
|
*
|
|
650
41
|
* Initialises the WASM module on the first call (subsequent calls reuse the
|
|
651
|
-
* cached module).
|
|
652
|
-
* `{@link GukhanmunOptions.dictionaries}` are fetched
|
|
653
|
-
*
|
|
42
|
+
* cached module). Compiled dictionaries supplied via
|
|
43
|
+
* `{@link GukhanmunOptions.dictionaries}` are fetched, while
|
|
44
|
+
* `{@link MapDictionarySource}` entry lists are serialised and built in memory
|
|
45
|
+
* as Rust `MapDictionary` values.
|
|
654
46
|
*
|
|
655
47
|
* Note: unlike the Rust `ko-kr` preset, the JavaScript preset never includes a
|
|
656
48
|
* bundled dictionary. Pass `dictionaries: [await stdictFst()]` to include the
|
|
@@ -661,6 +53,5 @@ declare class GukhanmunError extends Error {
|
|
|
661
53
|
* @returns A `{@link Gukhanmun}` instance.
|
|
662
54
|
* @throws {@link GukhanmunError} on invalid options or dictionary load failure.
|
|
663
55
|
*/
|
|
664
|
-
declare function load(options?: GukhanmunOptions): Promise<Gukhanmun>;
|
|
665
|
-
|
|
666
|
-
export { type ContextWindow, type CustomPunctuationProfile, type DelimiterStyle, type DictionaryEntry, type DictionarySource, type Directives, type ErrorCode, type FileDictionarySource, type Format, type Gukhanmun, GukhanmunError, type GukhanmunFactory, type GukhanmunOptions, type HanjaVariantSet, type HomophoneDetection, type HtmlOptions, type NumeralStrategy, type OriginalGloss, type Preset, type PunctuationPreset, type Recovery, type RenderMode, type ResolvedPunctuationProfile, type Segmentation, type SpaceAfter, type StopStyle, load };
|
|
56
|
+
export declare function load(options?: GukhanmunOptions$1): Promise<Gukhanmun$1>;
|
|
57
|
+
export type { ContextWindow, CustomPunctuationProfile, DelimiterStyle, DictionaryEntry, DictionarySource, Directives, ErrorCode, FileDictionarySource, Format, Gukhanmun, GukhanmunFactory, GukhanmunOptions, HanjaVariantSet, HomophoneDetection, HtmlOptions, MapDictionarySource, NumeralStrategy, OriginalGloss, Preset, PunctuationPreset, Recovery, RenderMode, ResolvedPunctuationProfile, Segmentation, SpaceAfter, StopStyle };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// index.ts
|
|
2
2
|
function isNodeLike() {
|
|
3
3
|
return typeof globalThis.process?.versions?.node === "string";
|
|
4
4
|
}
|
|
@@ -77,7 +77,54 @@ function ensureWasm() {
|
|
|
77
77
|
}
|
|
78
78
|
return wasmInit;
|
|
79
79
|
}
|
|
80
|
+
/** Rejects a source that is not an object before any property is read. */
|
|
81
|
+
function isRecord(value) {
|
|
82
|
+
return typeof value === "object" && value !== null;
|
|
83
|
+
}
|
|
84
|
+
/** The entry fields {@link DictionaryEntry} declares, in serialisation order. */
|
|
85
|
+
const DICTIONARY_ENTRY_FIELDS = [
|
|
86
|
+
"hanja",
|
|
87
|
+
"reading",
|
|
88
|
+
"suffixReading",
|
|
89
|
+
"preference",
|
|
90
|
+
"requireHanja",
|
|
91
|
+
"requireHangul"
|
|
92
|
+
];
|
|
93
|
+
/**
|
|
94
|
+
* Encodes runtime dictionary entries for the WASM boundary.
|
|
95
|
+
*
|
|
96
|
+
* Each entry is copied field by field, so a class instance exposing its
|
|
97
|
+
* properties through getters serialises the same values it presents, and any
|
|
98
|
+
* extra property a caller carries is dropped rather than rejected. The copy
|
|
99
|
+
* also keeps `NaN` and `±Infinity` preferences visible: `JSON.stringify` would
|
|
100
|
+
* erase them to `null`, which the Rust side reads as "absent".
|
|
101
|
+
*/
|
|
102
|
+
function encodeEntries(entries) {
|
|
103
|
+
if (!Array.isArray(entries)) throw new GukhanmunError("invalid-input", "Dictionary 'entries' must be an array");
|
|
104
|
+
const records = [];
|
|
105
|
+
for (const [index, entry] of entries.entries()) {
|
|
106
|
+
if (!isRecord(entry)) {
|
|
107
|
+
records.push(entry);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const record = {};
|
|
111
|
+
for (const field of DICTIONARY_ENTRY_FIELDS) record[field] = entry[field];
|
|
112
|
+
const preference = record["preference"];
|
|
113
|
+
if (preference != null && !Number.isInteger(preference)) throw new GukhanmunError("invalid-input", `dictionary entry ${index} has a non-integer \`preference\`: ${String(preference)}`);
|
|
114
|
+
records.push(record);
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
return JSON.stringify(records);
|
|
118
|
+
} catch (e) {
|
|
119
|
+
throw new GukhanmunError("invalid-input", `Dictionary entries are not serialisable: ${e instanceof Error ? e.message : String(e)}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
80
122
|
async function resolveDictionary(source) {
|
|
123
|
+
if (typeof source !== "object" || source === null) throw new GukhanmunError("invalid-input", "Each dictionary must be an object");
|
|
124
|
+
if ("entries" in source) {
|
|
125
|
+
if ("format" in source || "data" in source) throw new GukhanmunError("invalid-input", "A dictionary must not combine 'entries' with 'format' or 'data'");
|
|
126
|
+
return { entriesJson: encodeEntries(source.entries) };
|
|
127
|
+
}
|
|
81
128
|
if (source.data instanceof ArrayBuffer) return {
|
|
82
129
|
format: source.format,
|
|
83
130
|
bytes: new Uint8Array(source.data)
|
|
@@ -223,9 +270,10 @@ function resolveOptions(opts = {}) {
|
|
|
223
270
|
* Creates a Gukhanmun converter with the given options.
|
|
224
271
|
*
|
|
225
272
|
* Initialises the WASM module on the first call (subsequent calls reuse the
|
|
226
|
-
* cached module).
|
|
227
|
-
* `{@link GukhanmunOptions.dictionaries}` are fetched
|
|
228
|
-
*
|
|
273
|
+
* cached module). Compiled dictionaries supplied via
|
|
274
|
+
* `{@link GukhanmunOptions.dictionaries}` are fetched, while
|
|
275
|
+
* `{@link MapDictionarySource}` entry lists are serialised and built in memory
|
|
276
|
+
* as Rust `MapDictionary` values.
|
|
229
277
|
*
|
|
230
278
|
* Note: unlike the Rust `ko-kr` preset, the JavaScript preset never includes a
|
|
231
279
|
* bundled dictionary. Pass `dictionaries: [await stdictFst()]` to include the
|
|
@@ -297,5 +345,4 @@ function punctuationJson(value) {
|
|
|
297
345
|
throw new GukhanmunError("invalid-input", error instanceof Error ? error.message : String(error));
|
|
298
346
|
}
|
|
299
347
|
}
|
|
300
|
-
//#endregion
|
|
301
348
|
export { GukhanmunError, load };
|
|
@@ -301,6 +301,10 @@ function __wbg_get_imports() {
|
|
|
301
301
|
const ret = arg0[arg1];
|
|
302
302
|
return ret;
|
|
303
303
|
},
|
|
304
|
+
__wbg_has_73740b27f436fed3: function() { return handleError(function (arg0, arg1) {
|
|
305
|
+
const ret = Reflect.has(arg0, arg1);
|
|
306
|
+
return ret;
|
|
307
|
+
}, arguments); },
|
|
304
308
|
__wbg_instanceof_ArrayBuffer_8f49811467741499: function(arg0) {
|
|
305
309
|
let result;
|
|
306
310
|
try {
|
|
Binary file
|
|
@@ -303,6 +303,10 @@ function __wbg_get_imports() {
|
|
|
303
303
|
const ret = arg0[arg1];
|
|
304
304
|
return ret;
|
|
305
305
|
},
|
|
306
|
+
__wbg_has_73740b27f436fed3: function() { return handleError(function (arg0, arg1) {
|
|
307
|
+
const ret = Reflect.has(arg0, arg1);
|
|
308
|
+
return ret;
|
|
309
|
+
}, arguments); },
|
|
306
310
|
__wbg_instanceof_ArrayBuffer_8f49811467741499: function(arg0) {
|
|
307
311
|
let result;
|
|
308
312
|
try {
|
|
Binary file
|
|
@@ -301,6 +301,10 @@ function __wbg_get_imports() {
|
|
|
301
301
|
const ret = arg0[arg1];
|
|
302
302
|
return ret;
|
|
303
303
|
},
|
|
304
|
+
__wbg_has_73740b27f436fed3: function() { return handleError(function (arg0, arg1) {
|
|
305
|
+
const ret = Reflect.has(arg0, arg1);
|
|
306
|
+
return ret;
|
|
307
|
+
}, arguments); },
|
|
304
308
|
__wbg_instanceof_ArrayBuffer_8f49811467741499: function(arg0) {
|
|
305
309
|
let result;
|
|
306
310
|
try {
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gukhanmun/wasm",
|
|
3
|
-
"version": "0.4.0-dev.
|
|
3
|
+
"version": "0.4.0-dev.245",
|
|
4
4
|
"description": "WebAssembly implementation of the Gukhanmun hanja-to-hangul converter.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@gukhanmun/types": "*"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@gukhanmun/types": "0.4.0-dev.
|
|
57
|
+
"@gukhanmun/types": "0.4.0-dev.245+223a736"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "tsdown && node -e \"const fs=require('node:fs'),p=require('node:path');fs.cpSync('wasm','dist/wasm',{recursive:true,force:true,filter:(s)=>p.basename(s)!=='.gitignore'})\""
|