@gukhanmun/napi 0.1.0-dev.16 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,18 @@
1
1
  @gukhanmun/napi
2
2
  ===============
3
3
 
4
+ [![npm][npm badge]][npm]
5
+ [![License: GPL-3.0-only][GPL badge]][GPL]
6
+
4
7
  Node.js native addon implementation of the Gukhanmun hanja-to-hangul converter,
5
8
  built with napi-rs. Requires Node.js 20+. For environments other than Node.js
6
9
  (browsers, Deno, Bun via WASM), use `@gukhanmun/wasm` instead.
7
10
 
11
+ [npm badge]: https://img.shields.io/npm/v/@gukhanmun/napi?logo=npm
12
+ [npm]: https://www.npmjs.com/package/@gukhanmun/napi
13
+ [GPL badge]: https://img.shields.io/npm/l/%40gukhanmun%2Fnapi
14
+ [GPL]: https://www.gnu.org/licenses/gpl-3.0.html
15
+
8
16
 
9
17
  Installation
10
18
  ------------
package/dist/index.d.ts CHANGED
@@ -123,6 +123,19 @@ type NumeralStrategy = "hangul-phonetic" | "positional-arabic" | "additive-arabi
123
123
  * accuracy matters more than latency.
124
124
  */
125
125
  type ContextWindow = "off" | "per-block" | "per-section" | "per-document";
126
+ /**
127
+ * Selects how the homophone marker decides that a reading needs its hanja shown
128
+ * in `rendering: "hangul-only"`. Corresponds to Rust `HomophoneDetection`.
129
+ *
130
+ * - `"context-local"` — Gloss a reading only when a different-meaning homophone
131
+ * actually appears within the {@link ContextWindow}. This keeps hangul-only
132
+ * output clean and is the default.
133
+ * - `"dictionary-wide"` — Also gloss readings shared by other hanja forms
134
+ * anywhere in the dictionary, even when no homophone appears in the text.
135
+ * With a large reference dictionary this glosses most Sino-Korean words; words
136
+ * that should always be glossed are better expressed with `requireHanja`.
137
+ */
138
+ type HomophoneDetection = "context-local" | "dictionary-wide";
126
139
  /**
127
140
  * Controls how the pipeline handles reader errors encountered during HTML
128
141
  * scanning. Corresponds to Rust `Recovery`.
@@ -221,7 +234,7 @@ type DictionarySource = FileDictionarySource;
221
234
  interface HtmlOptions {
222
235
  /**
223
236
  * Class names whose containing element (and all descendants) should be
224
- * treated as a preserved region the engine skips their text content.
237
+ * treated as a preserved region—the engine skips their text content.
225
238
  *
226
239
  * Equivalent to passing `--html-preserve-class NAME` to the CLI one or
227
240
  * more times.
@@ -324,13 +337,22 @@ interface GukhanmunOptions {
324
337
  readonly initialSoundLaw?: boolean;
325
338
  /**
326
339
  * Context window for homophone disambiguation. The `HomophoneMarker`
327
- * middleware sets `homophone = true` on annotations whose hangul reading is
328
- * shared by another hanja form within this window. Defaults to
329
- * `"per-block"`.
340
+ * middleware sets `homophone = true` on annotations whose hangul reading
341
+ * collides within this window. Defaults to `"per-block"`.
330
342
  *
331
343
  * @see {@link ContextWindow}
332
344
  */
333
345
  readonly homophoneWindow?: ContextWindow;
346
+ /**
347
+ * Strategy that decides which readings count as homophones needing a hanja
348
+ * gloss. Defaults to `"context-local"`, which glosses a reading only when a
349
+ * different-meaning homophone appears within {@link homophoneWindow}. Use
350
+ * `"dictionary-wide"` to also gloss readings shared by other dictionary
351
+ * entries.
352
+ *
353
+ * @see {@link HomophoneDetection}
354
+ */
355
+ readonly homophoneDetection?: HomophoneDetection;
334
356
  /**
335
357
  * Context window for first-occurrence filtering. The
336
358
  * `FirstOccurrenceFilter` middleware clears `requireHanja` /
@@ -571,4 +593,4 @@ declare class GukhanmunError extends Error {
571
593
  */
572
594
  declare function load(options?: GukhanmunOptions): Promise<Gukhanmun>;
573
595
  //#endregion
574
- export { type ContextWindow, type DictionaryEntry, type DictionarySource, type Directives, type ErrorCode, type FileDictionarySource, type Format, type Gukhanmun, GukhanmunError, type GukhanmunFactory, type GukhanmunOptions, type HtmlOptions, type NumeralStrategy, type OriginalGloss, type Preset, type Recovery, type RenderMode, type Segmentation, load };
596
+ export { type ContextWindow, type DictionaryEntry, type DictionarySource, type Directives, type ErrorCode, type FileDictionarySource, type Format, type Gukhanmun, GukhanmunError, type GukhanmunFactory, type GukhanmunOptions, type HomophoneDetection, type HtmlOptions, type NumeralStrategy, type OriginalGloss, type Preset, type Recovery, type RenderMode, type Segmentation, load };
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
13
13
  * locally with `mise run napi-build`.
14
14
  *
15
15
  * The `load()` factory is asynchronous for API uniformity with the WASM
16
- * backend, but the native addon is synchronously ready dictionary data is
16
+ * backend, but the native addon is synchronously ready—dictionary data is
17
17
  * the only async part.
18
18
  *
19
19
  * @example
@@ -45,19 +45,22 @@ function detectPlatformPackage() {
45
45
  /**
46
46
  * Loads the native addon at module initialisation time.
47
47
  *
48
- * When installed from npm the platform-specific optional dependency is tried
49
- * first. Falls back to a locally-built binary (produced by
50
- * `mise run napi-build`) for development.
48
+ * A locally-built binary (produced by `mise run napi-build`) is tried first so
49
+ * development and CI exercise the freshly compiled addon; a stale platform
50
+ * optional-dependency binary must never shadow it. A published install ships
51
+ * only `dist/` (see the package `files` field), so no local binary is present
52
+ * there and resolution falls through to the platform-specific optional
53
+ * dependency.
51
54
  */
52
55
  const nativeAddon = (() => {
53
56
  const req = createRequire(import.meta.url);
54
57
  try {
55
- return req(detectPlatformPackage());
58
+ return req("./gukhanmun_napi.node");
56
59
  } catch {
57
60
  try {
58
- return req("./gukhanmun_napi.node");
59
- } catch {
60
61
  return req("../gukhanmun_napi.node");
62
+ } catch {
63
+ return req(detectPlatformPackage());
61
64
  }
62
65
  }
63
66
  })();
@@ -154,6 +157,7 @@ function resolveOptions(opts = {}) {
154
157
  numerals: opts.numerals ?? "hangul-phonetic",
155
158
  initialSoundLaw: opts.initialSoundLaw ?? (koKp ? false : true),
156
159
  homophoneWindow: opts.homophoneWindow ?? (koKp ? "off" : "per-block"),
160
+ homophoneDetection: opts.homophoneDetection ?? "context-local",
157
161
  firstOccurrenceWindow: opts.firstOccurrenceWindow ?? "off",
158
162
  recovery: opts.recovery ?? "strict"
159
163
  };
@@ -166,6 +170,7 @@ function buildRawOptions(opts, resolved) {
166
170
  numerals: resolved.numerals,
167
171
  initialSoundLaw: resolved.initialSoundLaw,
168
172
  homophoneWindow: resolved.homophoneWindow,
173
+ homophoneDetection: resolved.homophoneDetection,
169
174
  firstOccurrenceWindow: resolved.firstOccurrenceWindow,
170
175
  recovery: resolved.recovery
171
176
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gukhanmun/napi",
3
- "version": "0.1.0-dev.16",
3
+ "version": "0.1.0",
4
4
  "description": "Node.js native addon (napi-rs) for the Gukhanmun hanja-to-hangul converter.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -14,12 +14,12 @@
14
14
  "dist"
15
15
  ],
16
16
  "optionalDependencies": {
17
- "@gukhanmun/napi-aarch64-apple-darwin": "0.1.0-dev.16+395401fa8b3429703127c66d1db02c435606d87b",
18
- "@gukhanmun/napi-x86_64-apple-darwin": "0.1.0-dev.16+395401fa8b3429703127c66d1db02c435606d87b",
19
- "@gukhanmun/napi-x86_64-pc-windows-msvc": "0.1.0-dev.16+395401fa8b3429703127c66d1db02c435606d87b",
20
- "@gukhanmun/napi-aarch64-pc-windows-msvc": "0.1.0-dev.16+395401fa8b3429703127c66d1db02c435606d87b",
21
- "@gukhanmun/napi-aarch64-unknown-linux-gnu": "0.1.0-dev.16+395401fa8b3429703127c66d1db02c435606d87b",
22
- "@gukhanmun/napi-x86_64-unknown-linux-gnu": "0.1.0-dev.16+395401fa8b3429703127c66d1db02c435606d87b"
17
+ "@gukhanmun/napi-x86_64-apple-darwin": "0.1.0",
18
+ "@gukhanmun/napi-x86_64-pc-windows-msvc": "0.1.0",
19
+ "@gukhanmun/napi-aarch64-apple-darwin": "0.1.0",
20
+ "@gukhanmun/napi-aarch64-unknown-linux-gnu": "0.1.0",
21
+ "@gukhanmun/napi-aarch64-pc-windows-msvc": "0.1.0",
22
+ "@gukhanmun/napi-x86_64-unknown-linux-gnu": "0.1.0"
23
23
  },
24
24
  "homepage": "https://github.com/dahlia/gukhanmun",
25
25
  "bugs": "https://github.com/dahlia/gukhanmun/issues",
@@ -52,7 +52,7 @@
52
52
  "@gukhanmun/types": "*"
53
53
  },
54
54
  "devDependencies": {
55
- "@gukhanmun/types": "0.1.0-dev.16+395401fa8b3429703127c66d1db02c435606d87b"
55
+ "@gukhanmun/types": "0.1.0"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "tsdown"