@gukhanmun/types 0.3.1 → 0.4.0-dev.236

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 CHANGED
@@ -40,13 +40,15 @@ conventions and output format. `GukhanmunOptions` is the options bag passed to
40
40
  `load()`; it covers preset, rendering, segmentation, numerals, initial sound
41
41
  law, homophone window, first-occurrence window, recovery, directives, and HTML
42
42
  options. `Gukhanmun` is the converter interface returned by `load()`, with
43
- `convert()` and `convertStream()` methods. `GukhanmunError` is the structured
44
- error class with a typed `code` property and a `chain` array of causes.
45
-
46
- `DictionarySource` describes how to supply a dictionary: as a
47
- `{ format, bytes }` record pointing to already-loaded binary data. `Format` is
48
- the input format selector: `"text/plain"`, `"text/html"`, `"text/markdown"`, or
49
- a `{ format: "text/markdown", gfm: boolean }` object.
43
+ `convert()` and `stream()` methods. `GukhanmunError` is the structured error
44
+ class with a typed `code` property and a `chain` array of causes.
45
+
46
+ `DictionarySource` describes how to supply a dictionary, either as a
47
+ `FileDictionarySource` (`{ format, data }` pointing at FST or CDB bytes, a URL,
48
+ or a path) or as a `MapDictionarySource` (`{ entries }` with hanja, reading,
49
+ positional reading, preference, and mark fields) for readings computed at
50
+ runtime. `Format` is the input format selector: `"text"`, `"html"`,
51
+ `"markdown"`, or a `{ format: "markdown", gfm: boolean }` object.
50
52
 
51
53
  All TSDoc comments live in this package as the single source of truth for the
52
54
  JavaScript API. Refer to the declarations in `index.ts` for the full details.
package/dist/index.d.ts CHANGED
@@ -152,13 +152,39 @@ type HomophoneDetection = "context-local" | "dictionary-wide";
152
152
  */
153
153
  type Recovery = "strict" | "lenient";
154
154
  /**
155
- * A single dictionary entry returned by a dictionary lookup.
155
+ * A single dictionary entry: a hanja key with one hangul reading.
156
+ *
157
+ * Callers pass these in {@link MapDictionarySource.entries} to build a
158
+ * dictionary at runtime. Fields mirror the Rust `ReadingCandidate` type plus
159
+ * the hanja key.
156
160
  */
157
161
  interface DictionaryEntry {
158
- /** The hanja form (key), e.g. `"漢字"`. */
162
+ /** The hanja form (dictionary key), e.g. `"漢字"`. */
159
163
  readonly hanja: string;
160
- /** The hangul reading, e.g. `"한자"`. */
164
+ /** The word-initial hangul reading, e.g. `"한자"`. */
161
165
  readonly reading: string;
166
+ /**
167
+ * The reading used when the match is not word-initial, when it differs from
168
+ * {@link reading}. For example a `年代` entry with `reading: "연대"` and
169
+ * `suffixReading: "년대"` reads `1990年代` as `1990년대` but `年代` alone as
170
+ * `연대`.
171
+ *
172
+ * Corresponds to Rust `ReadingCandidate::suffix_reading`.
173
+ */
174
+ readonly suffixReading?: string;
175
+ /**
176
+ * Relative default preference for this reading within its hanja key, a
177
+ * non-negative integer. Larger values win, so an entry listed twice with
178
+ * different preferences keeps competing readings and uses the higher one by
179
+ * default. Absent means `0`.
180
+ *
181
+ * List order never selects the default: when two readings share a preference
182
+ * the tie is broken by reading spelling. Set distinct preferences to choose
183
+ * a default deliberately.
184
+ *
185
+ * Corresponds to Rust `ReadingCandidate::preference`.
186
+ */
187
+ readonly preference?: number;
162
188
  /**
163
189
  * When `true`, the renderer should always show the original hanja
164
190
  * alongside the hangul reading, regardless of ambiguity.
@@ -186,7 +212,8 @@ interface DictionaryEntry {
186
212
  * Deno 2.0+, and Bun only. Throws in browser environments.
187
213
  *
188
214
  * At runtime, a `FileDictionarySource` is distinguished from other values by
189
- * the presence of a `format` property (`"format" in source`).
215
+ * the absence of an `entries` property (`"entries" in source` selects a
216
+ * {@link MapDictionarySource}).
190
217
  */
191
218
  interface FileDictionarySource {
192
219
  /**
@@ -207,16 +234,59 @@ interface FileDictionarySource {
207
234
  * or in-memory bytes; supported in Node-API and (with `from_bytes`) in
208
235
  * WASM builds that include the `cdb` feature.
209
236
  *
210
- * The `"tsv"` format is reserved for future use; passing it throws
211
- * `GukhanmunError` with code `"unsupported-content-type"`.
237
+ * The `"tsv"` format is reserved and never accepted. Pass entries in memory
238
+ * through {@link MapDictionarySource} instead of compiling a table.
212
239
  */
213
240
  readonly format: "fst" | "cdb";
214
241
  }
242
+ /**
243
+ * A dictionary built from entries computed at runtime, such as per-document
244
+ * reading overrides.
245
+ *
246
+ * Use this instead of compiling a TSV file with `gukhanmun-mkdict` when the
247
+ * entries do not exist on disk, for example in a browser, an edge runtime, or a
248
+ * site generator that derives entries per document.
249
+ *
250
+ * A source is distinguished from a {@link FileDictionarySource} by the presence
251
+ * of an `entries` property.
252
+ *
253
+ * @example
254
+ * ```ts
255
+ * import { stdictFst } from "@gukhanmun/stdict-fst";
256
+ * const g = await load({
257
+ * dictionaries: [
258
+ * {
259
+ * entries: [
260
+ * { hanja: "高橋", reading: "다카하시" },
261
+ * { hanja: "東京", reading: "도쿄", preference: 10 },
262
+ * { hanja: "年代", reading: "연대", suffixReading: "년대" },
263
+ * ],
264
+ * },
265
+ * await stdictFst(),
266
+ * ],
267
+ * });
268
+ * ```
269
+ */
270
+ interface MapDictionarySource {
271
+ /**
272
+ * The entries of this dictionary.
273
+ *
274
+ * Repeated `hanja` keys append competing readings instead of replacing each
275
+ * other, and {@link DictionaryEntry.preference} decides which reading is the
276
+ * context-free default. Several readings for one key also let the engine
277
+ * pick a reading from a following particle (`東京을` versus `東京를`).
278
+ *
279
+ * An empty list contributes nothing, which is a convenient way to express
280
+ * "this document has no overrides".
281
+ */
282
+ readonly entries: readonly DictionaryEntry[];
283
+ }
215
284
  /**
216
285
  * A dictionary source accepted by {@link GukhanmunOptions.dictionaries}.
217
286
  *
218
- * Currently only {@link FileDictionarySource} (binary file / URL / path) is
219
- * supported. Sources are tried in array order; the first match wins.
287
+ * Sources are tried in array order; the first match for a hanja key wins, and
288
+ * every source listed before a compiled dictionary overrides that dictionary
289
+ * for the keys it carries.
220
290
  *
221
291
  * @example
222
292
  * ```ts
@@ -224,7 +294,7 @@ interface FileDictionarySource {
224
294
  * const g = await load({ dictionaries: [await stdictFst()] });
225
295
  * ```
226
296
  */
227
- type DictionarySource = FileDictionarySource;
297
+ type DictionarySource = FileDictionarySource | MapDictionarySource;
228
298
  /**
229
299
  * Fine-grained HTML preservation rules passed in
230
300
  * {@link GukhanmunOptions.html}.
@@ -446,6 +516,10 @@ interface GukhanmunOptions {
446
516
  * `@gukhanmun/loanwords-fst` or `@gukhanmun/loanwords-cdb`. Put user
447
517
  * dictionaries first, then loanwords, then the preset dictionaries.
448
518
  *
519
+ * Entries computed at runtime need no package and no `gukhanmun-mkdict` run:
520
+ * pass {@link MapDictionarySource} (`{ entries: [...] }`) at the position
521
+ * where those overrides should take precedence.
522
+ *
449
523
  * @see {@link DictionarySource}
450
524
  */
451
525
  readonly dictionaries?: readonly DictionarySource[];
@@ -624,4 +698,4 @@ declare class GukhanmunError extends Error {
624
698
  }[];
625
699
  }
626
700
  //#endregion
627
- export { ContextWindow, CustomPunctuationProfile, DelimiterStyle, DictionaryEntry, DictionarySource, Directives, ErrorCode, FileDictionarySource, Format, Gukhanmun, GukhanmunError, GukhanmunFactory, GukhanmunOptions, HanjaVariantSet, HomophoneDetection, HtmlOptions, NumeralStrategy, OriginalGloss, Preset, PunctuationPreset, Recovery, RenderMode, ResolvedPunctuationProfile, Segmentation, SpaceAfter, StopStyle, load };
701
+ export { ContextWindow, CustomPunctuationProfile, DelimiterStyle, DictionaryEntry, DictionarySource, Directives, ErrorCode, FileDictionarySource, Format, Gukhanmun, GukhanmunError, GukhanmunFactory, GukhanmunOptions, HanjaVariantSet, HomophoneDetection, HtmlOptions, MapDictionarySource, NumeralStrategy, OriginalGloss, Preset, PunctuationPreset, Recovery, RenderMode, ResolvedPunctuationProfile, Segmentation, SpaceAfter, StopStyle, load };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gukhanmun/types",
3
- "version": "0.3.1",
3
+ "version": "0.4.0-dev.236",
4
4
  "description": "TypeScript API contract for Gukhanmun (type declarations only, no runtime code).",
5
5
  "type": "module",
6
6
  "exports": {