@sushichan044/kg-core 0.0.0 → 0.4.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/LICENSE +21 -0
- package/README.md +99 -43
- package/dist/index.d.mts +14667 -0
- package/dist/index.mjs +1500 -0
- package/package.json +58 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 sushichan044
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,45 +1,101 @@
|
|
|
1
1
|
# @sushichan044/kg-core
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
##
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
3
|
+
Framework-independent parsing, composition, and proofreading for Japanese
|
|
4
|
+
manuscripts.
|
|
5
|
+
|
|
6
|
+
The package exposes plain readonly data transfer objects and pure processing
|
|
7
|
+
functions. It does not own application state, persistence, React components,
|
|
8
|
+
or DOM behavior.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
pnpm add @sushichan044/kg-core
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Processing pipeline
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import {
|
|
20
|
+
ComposeError,
|
|
21
|
+
composeManuscript,
|
|
22
|
+
createDefaultProofreadingRules,
|
|
23
|
+
ManuscriptCompositionSettings,
|
|
24
|
+
manuscriptGridComposer,
|
|
25
|
+
ParseError,
|
|
26
|
+
parseManuscript,
|
|
27
|
+
pixivParser,
|
|
28
|
+
ProofreadError,
|
|
29
|
+
proofreadManuscript,
|
|
30
|
+
} from "@sushichan044/kg-core";
|
|
31
|
+
|
|
32
|
+
const parsed = parseManuscript(source, { parser: pixivParser });
|
|
33
|
+
if (!parsed.ok) throw new Error(ParseError.describe(parsed.error));
|
|
34
|
+
|
|
35
|
+
const composed = composeManuscript(parsed.value, {
|
|
36
|
+
composer: manuscriptGridComposer,
|
|
37
|
+
settings: ManuscriptCompositionSettings.defaults,
|
|
38
|
+
});
|
|
39
|
+
if (!composed.ok) throw new Error(ComposeError.describe(composed.error));
|
|
40
|
+
|
|
41
|
+
const proofread = proofreadManuscript(composed.value, {
|
|
42
|
+
rules: createDefaultProofreadingRules(),
|
|
43
|
+
});
|
|
44
|
+
if (!proofread.ok) throw new Error(ProofreadError.describe(proofread.error));
|
|
45
|
+
|
|
46
|
+
const diagnostics = [...parsed.warnings, ...proofread.value];
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`parseManuscript` uses `plainTextParser` when no parser is supplied. The Pixiv
|
|
50
|
+
parser normalizes ruby, bold, italic, and emphasis notation into a closed
|
|
51
|
+
annotation union. Malformed or unknown notation remains visible and produces a
|
|
52
|
+
parser warning.
|
|
53
|
+
|
|
54
|
+
`composeManuscript` requires a composer. The built-in grid composer produces a
|
|
55
|
+
self-contained snapshot containing the parsed manuscript, accepted settings,
|
|
56
|
+
geometry, statistics, and page/stage/line/cell hierarchy. Every occupied
|
|
57
|
+
element has source, display, and grapheme ranges; empty placement elements use
|
|
58
|
+
`null`.
|
|
59
|
+
|
|
60
|
+
## Extensions and validation
|
|
61
|
+
|
|
62
|
+
Parsers implement `ManuscriptParser`. Composers implement `ManuscriptComposer`
|
|
63
|
+
and provide Valibot schemas for their settings and layout. Proofreading rules
|
|
64
|
+
carry `kind: "parsed"` or `kind: "composed"` to declare which manuscript they
|
|
65
|
+
need, and report findings through `context.report`.
|
|
66
|
+
|
|
67
|
+
A plugin signals its own failure with a `Rejection` — a plain reason string.
|
|
68
|
+
Core turns that into a variant of the stage's error union, so plugins never
|
|
69
|
+
construct core's error types.
|
|
70
|
+
|
|
71
|
+
Each concept lives in its own module as a type plus a companion object of the
|
|
72
|
+
same name, holding its schema and operations: `ManuscriptRange.merge`,
|
|
73
|
+
`PaperSize.of`, `ManuscriptCompositionSettings.defaults`, and so on. Types are
|
|
74
|
+
inferred from the schemas with `v.InferOutput`; source, display, and grapheme
|
|
75
|
+
ranges are distinct branded types, and plugin IDs are branded `NamespacedId`.
|
|
76
|
+
|
|
77
|
+
Processing functions return `ManuscriptResult`: success carries warnings, and
|
|
78
|
+
failure carries exactly one error from a discriminated union, so callers can
|
|
79
|
+
`switch` on `error.kind` exhaustively. Each error variant exposes its context
|
|
80
|
+
as typed fields; `describe` renders one for display. Invalid settings and
|
|
81
|
+
plugin output fail explicitly; values are never clamped or partially trusted.
|
|
82
|
+
|
|
83
|
+
## Source mapping
|
|
84
|
+
|
|
85
|
+
Source and display ranges are zero-based, end-exclusive UTF-16 offsets.
|
|
86
|
+
Grapheme ranges index the normalized grapheme array. Diagnostics include
|
|
87
|
+
one-based source line and column positions, so renderers do not need to search
|
|
88
|
+
or recalculate locations.
|
|
89
|
+
|
|
90
|
+
The default proofreading rules report common Japanese novel-style issues and
|
|
91
|
+
Unicode variation sequences. Diagnostics do not modify the source and do not
|
|
92
|
+
contain automatic fixes.
|
|
93
|
+
|
|
94
|
+
## Browser support
|
|
95
|
+
|
|
96
|
+
The package targets browser features that are Baseline Widely Available. It
|
|
97
|
+
does not include polyfills.
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
MIT
|