@sushichan044/kg-core 0.6.1 → 0.6.3
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 +44 -10
- package/dist/index.d.mts +21865 -7994
- package/dist/index.mjs +757 -291
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -19,9 +19,10 @@ pnpm add @sushichan044/kg-core
|
|
|
19
19
|
import {
|
|
20
20
|
ComposeError,
|
|
21
21
|
composeManuscript,
|
|
22
|
+
createNovelComposer,
|
|
22
23
|
createDefaultProofreadingRules,
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
NovelCompositionSettings,
|
|
25
|
+
novelComposer,
|
|
25
26
|
ParseError,
|
|
26
27
|
parseManuscript,
|
|
27
28
|
kakuyomuParser,
|
|
@@ -34,8 +35,8 @@ const parsed = parseManuscript(source, { parser: kakuyomuParser });
|
|
|
34
35
|
if (!parsed.ok) throw new Error(ParseError.describe(parsed.error));
|
|
35
36
|
|
|
36
37
|
const composed = composeManuscript(parsed.value, {
|
|
37
|
-
composer:
|
|
38
|
-
settings:
|
|
38
|
+
composer: novelComposer,
|
|
39
|
+
settings: NovelCompositionSettings.defaults,
|
|
39
40
|
});
|
|
40
41
|
if (!composed.ok) throw new Error(ComposeError.describe(composed.error));
|
|
41
42
|
|
|
@@ -52,11 +53,44 @@ const diagnostics = [...parsed.warnings, ...proofread.value];
|
|
|
52
53
|
normalizes Kakuyomu ruby and emphasis marks. Malformed or unknown notation remains
|
|
53
54
|
visible and produces a parser warning.
|
|
54
55
|
|
|
55
|
-
`composeManuscript` requires a composer. The built-in
|
|
56
|
-
self-contained snapshot containing the parsed manuscript, accepted settings,
|
|
57
|
-
geometry, statistics, and page/stage/line
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
`composeManuscript` requires a composer. The built-in `novelComposer` produces
|
|
57
|
+
a self-contained snapshot containing the parsed manuscript, accepted settings,
|
|
58
|
+
geometry, statistics, and a page/stage/line hierarchy. Lines contain positioned
|
|
59
|
+
graphemes, suppressed source graphemes, and annotation fragments. The composer
|
|
60
|
+
owns Japanese line-start and line-end restrictions, inseparable punctuation,
|
|
61
|
+
hanging punctuation, question/exclamation gap suppression, and ruby placement.
|
|
62
|
+
|
|
63
|
+
The composer classifies vertical text before measuring and breaking lines. Following
|
|
64
|
+
[JLReq](https://www.w3.org/TR/jlreq/#handling_of_western_text_in_vertical_writing),
|
|
65
|
+
upright Latin initials and abbreviations advance by one em per character, Western
|
|
66
|
+
words remain unbroken and render sideways, and two ASCII digits form one
|
|
67
|
+
tate-chu-yoko unit. The resulting `VerticalTextPresentation` is carried by every
|
|
68
|
+
positioned grapheme, so renderers do not need to infer orientation independently.
|
|
69
|
+
|
|
70
|
+
The default logical measurer uses East Asian Width in a Japanese context. Upright
|
|
71
|
+
ASCII advances by one em; proportional ASCII and the members of a tate-chu-yoko unit
|
|
72
|
+
advance by half an em. Supply a synchronous measurer when the caller has more accurate
|
|
73
|
+
font metrics. Base-text requests also include the selected `presentation`:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
const composer = createNovelComposer({
|
|
77
|
+
measurer: (request) =>
|
|
78
|
+
measureWithAvailableFont(request.text, {
|
|
79
|
+
role: request.role,
|
|
80
|
+
fontPreset: request.fontPreset,
|
|
81
|
+
writingMode: request.writingMode,
|
|
82
|
+
...(request.role === "base" ? { presentation: request.presentation } : {}),
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
A measurer returns logical em units. Negative or non-finite results reject the
|
|
88
|
+
composition instead of producing a partial layout.
|
|
89
|
+
|
|
90
|
+
Ruby annotations retain one of three associations: `group` for one reading over
|
|
91
|
+
the entire base, `mono` for one reading segment per base grapheme, and `jukugo`
|
|
92
|
+
for a compound whose segments remain associated with each base grapheme. A
|
|
93
|
+
parser result with mismatched `mono` or `jukugo` segment counts is invalid.
|
|
60
94
|
|
|
61
95
|
## Extensions and validation
|
|
62
96
|
|
|
@@ -72,7 +106,7 @@ construct core's error types.
|
|
|
72
106
|
|
|
73
107
|
Each concept lives in its own module as a type plus a companion object of the
|
|
74
108
|
same name, holding its schema and operations: `ManuscriptRange.merge`,
|
|
75
|
-
`PaperSize.of`, `
|
|
109
|
+
`PaperSize.of`, `NovelCompositionSettings.defaults`, and so on. Types are
|
|
76
110
|
inferred from the schemas with `v.InferOutput`; source, display, and grapheme
|
|
77
111
|
ranges are distinct branded types, and plugin IDs are branded `NamespacedId`.
|
|
78
112
|
|