@gukhanmun/napi 0.3.0-dev.196 → 0.3.0-dev.208

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 CHANGED
@@ -288,6 +288,48 @@ interface Directives {
288
288
  */
289
289
  readonly skipAnnotation?: readonly string[];
290
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
+ }
291
333
  /**
292
334
  * Full set of options passed to {@link GukhanmunFactory.load} (or the
293
335
  * top-level `load` function) to configure a {@link Gukhanmun} instance.
@@ -297,6 +339,8 @@ interface Directives {
297
339
  * given, `"ko-kr"` is implicitly used.
298
340
  */
299
341
  interface GukhanmunOptions {
342
+ /** Independent output punctuation policy. Defaults to preserve. */
343
+ readonly punctuation?: PunctuationPreset | CustomPunctuationProfile;
300
344
  /**
301
345
  * Named configuration preset. Defaults to `"ko-kr"`.
302
346
  *
@@ -480,7 +524,9 @@ interface Gukhanmun {
480
524
  * `originalGloss`, which are not meaningfully representable as plain
481
525
  * values.
482
526
  */
483
- readonly options: Readonly<Required<Omit<GukhanmunOptions, "dictionaries" | "directives" | "html" | "originalGloss">>>;
527
+ readonly options: Readonly<Required<Omit<GukhanmunOptions, "dictionaries" | "directives" | "html" | "originalGloss" | "punctuation">> & {
528
+ readonly punctuation: ResolvedPunctuationProfile;
529
+ }>;
484
530
  }
485
531
  /**
486
532
  * Factory interface satisfied by both `@gukhanmun/wasm` and
@@ -616,4 +662,4 @@ declare class GukhanmunError extends Error {
616
662
  */
617
663
  declare function load(options?: GukhanmunOptions): Promise<Gukhanmun>;
618
664
  //#endregion
619
- export { type ContextWindow, 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 Recovery, type RenderMode, type Segmentation, load };
665
+ 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 };
package/dist/index.js CHANGED
@@ -151,6 +151,12 @@ function resolveOptions(opts = {}) {
151
151
  const preset = opts.preset ?? "ko-kr";
152
152
  const koKp = preset === "ko-kp";
153
153
  return {
154
+ punctuation: {
155
+ comma: null,
156
+ period: null,
157
+ single: null,
158
+ double: null
159
+ },
154
160
  preset,
155
161
  rendering: opts.rendering ?? "hangul-only",
156
162
  hanjaVariantSet: opts.hanjaVariantSet ?? "as-dictionary",
@@ -166,6 +172,7 @@ function resolveOptions(opts = {}) {
166
172
  }
167
173
  function buildRawOptions(opts, resolved) {
168
174
  const raw = {
175
+ punctuationJson: punctuationJson(opts.punctuation),
169
176
  preset: resolved.preset,
170
177
  rendering: resolved.rendering,
171
178
  hanjaVariantSet: resolved.hanjaVariantSet,
@@ -275,7 +282,27 @@ async function load(options = {}) {
275
282
  } catch (e) {
276
283
  throw liftNapiError(e);
277
284
  }
278
- return new GukhanmunImpl(handle, resolved);
285
+ const punctuation = JSON.parse(handle.punctuationProfileJson());
286
+ for (const style of Object.values(punctuation)) if (style != null) Object.freeze(style);
287
+ Object.freeze(punctuation);
288
+ return new GukhanmunImpl(handle, {
289
+ ...resolved,
290
+ punctuation
291
+ });
292
+ }
293
+ /** Reject ill-formed UTF-16 before a native boundary could replace surrogates. */
294
+ function punctuationJson(value) {
295
+ try {
296
+ return JSON.stringify(value === void 0 ? "preserve" : value, (_key, v) => {
297
+ if (typeof v === "string" && Array.from(v).some((c) => {
298
+ const code = c.codePointAt(0);
299
+ return code >= 55296 && code <= 57343;
300
+ })) throw new Error("Punctuation strings must contain Unicode scalars");
301
+ return v;
302
+ });
303
+ } catch (error) {
304
+ throw new GukhanmunError("invalid-input", error instanceof Error ? error.message : String(error));
305
+ }
279
306
  }
280
307
  //#endregion
281
308
  export { GukhanmunError, load };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gukhanmun/napi",
3
- "version": "0.3.0-dev.196",
3
+ "version": "0.3.0-dev.208",
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.3.0-dev.196+0b574b5",
18
- "@gukhanmun/napi-x86_64-apple-darwin": "0.3.0-dev.196+0b574b5",
19
- "@gukhanmun/napi-aarch64-pc-windows-msvc": "0.3.0-dev.196+0b574b5",
20
- "@gukhanmun/napi-x86_64-pc-windows-msvc": "0.3.0-dev.196+0b574b5",
21
- "@gukhanmun/napi-aarch64-unknown-linux-gnu": "0.3.0-dev.196+0b574b5",
22
- "@gukhanmun/napi-x86_64-unknown-linux-gnu": "0.3.0-dev.196+0b574b5"
17
+ "@gukhanmun/napi-aarch64-apple-darwin": "0.3.0-dev.208+62a742c",
18
+ "@gukhanmun/napi-x86_64-apple-darwin": "0.3.0-dev.208+62a742c",
19
+ "@gukhanmun/napi-aarch64-pc-windows-msvc": "0.3.0-dev.208+62a742c",
20
+ "@gukhanmun/napi-x86_64-pc-windows-msvc": "0.3.0-dev.208+62a742c",
21
+ "@gukhanmun/napi-aarch64-unknown-linux-gnu": "0.3.0-dev.208+62a742c",
22
+ "@gukhanmun/napi-x86_64-unknown-linux-gnu": "0.3.0-dev.208+62a742c"
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.3.0-dev.196+0b574b5"
55
+ "@gukhanmun/types": "0.3.0-dev.208+62a742c"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "tsdown"