kanbun-typesetter 0.1.0 → 0.1.1
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.en.md +12 -16
- package/README.ja.md +12 -16
- package/README.md +12 -20
- package/package.json +1 -2
- package/src/react/README.md +1 -1
- package/docs/architecture.md +0 -151
- package/docs/publishing.md +0 -95
- package/docs/punctuation.md +0 -36
- package/docs/react.md +0 -53
- package/docs/reference/furigana-okurigana-aki-chromium.png +0 -0
- package/docs/reference/furigana-okurigana-aki-webkit.png +0 -0
- package/docs/reference/group-okurigana-aki-chromium.png +0 -0
- package/docs/reference/group-okurigana-aki-webkit.png +0 -0
- package/docs/reference/group-short-aki-chromium.png +0 -0
- package/docs/reference/group-short-aki-webkit.png +0 -0
- package/docs/reference/observations.json +0 -4727
- package/docs/reference-study.md +0 -41
- package/docs/rules.md +0 -45
- package/docs/syntax.md +0 -52
- package/docs/validation.md +0 -111
package/README.en.md
CHANGED
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
A TypeScript typesetter for annotated kanbun, with a standalone HTML renderer and a React TSX component. It handles furigana, okurigana, rereading annotations, compound return marks, punctuation, connecting strokes, and grouped ruby. Layout uses browser-measured text dimensions. The output remains selectable and copyable text.
|
|
6
6
|
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install kanbun-typesetter
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
[npm: kanbun-typesetter](https://www.npmjs.com/package/kanbun-typesetter) · Current version: `0.1.1`.
|
|
14
|
+
|
|
7
15
|
## Directory layout
|
|
8
16
|
|
|
9
17
|
```text
|
|
@@ -16,15 +24,13 @@ src/
|
|
|
16
24
|
examples/
|
|
17
25
|
html/ Standalone demo code and interface CSS
|
|
18
26
|
index.html Demo entry page
|
|
19
|
-
tests/ Unit tests, browser tests, and React test fixtures
|
|
20
|
-
docs/ Rules, implementation notes, and validation records
|
|
21
27
|
```
|
|
22
28
|
|
|
23
29
|
[HTML directory](src/html/README.md) · [React directory](src/react/README.md)
|
|
24
30
|
|
|
25
31
|
## Run locally
|
|
26
32
|
|
|
27
|
-
Use Node.js 22.12 or newer; the project was validated with Node.js 24.
|
|
33
|
+
Use Node.js 22.12 or newer; the project was validated with Node.js 24.
|
|
28
34
|
|
|
29
35
|
```sh
|
|
30
36
|
npm ci
|
|
@@ -35,12 +41,8 @@ Open the [local demo](http://127.0.0.1:5188/). The demo interface is currently i
|
|
|
35
41
|
|
|
36
42
|
```sh
|
|
37
43
|
npm run build # Type checking, demo build, library and declarations
|
|
38
|
-
npm test # Parser and layout unit tests
|
|
39
|
-
npm run test:browser # Chrome and WebKit checks
|
|
40
44
|
```
|
|
41
45
|
|
|
42
|
-
Browser tests require system Chrome (`channel: chrome`) and Playwright WebKit. Install the latter with `npx playwright install webkit`.
|
|
43
|
-
|
|
44
46
|
## Defaults and spacing
|
|
45
47
|
|
|
46
48
|
- Fixed-spacing layout: `spacingMode: 'aki'`.
|
|
@@ -78,7 +80,7 @@ export function Reading({ text }: { text: string }) {
|
|
|
78
80
|
}
|
|
79
81
|
```
|
|
80
82
|
|
|
81
|
-
Pass layout options directly as JSX props, such as `baseSpacing={1}` or `kanjiFontSize={40}`. The component handles updates, automatic column height, `onLayout` / `onError` callbacks, and unmount cleanup. React is optional and only required for the React entry. See the [React directory](src/react/README.md)
|
|
83
|
+
Pass layout options directly as JSX props, such as `baseSpacing={1}` or `kanjiFontSize={40}`. The component handles updates, automatic column height, `onLayout` / `onError` callbacks, and unmount cleanup. React is optional and only required for the React entry. See the [React directory](src/react/README.md).
|
|
82
84
|
|
|
83
85
|
## Markup
|
|
84
86
|
|
|
@@ -93,22 +95,16 @@ Pass layout options directly as JSX props, such as `baseSpacing={1}` or `kanjiFo
|
|
|
93
95
|
| `胡-蝶`, `胡‐蝶`, `胡―蝶` | Connecting stroke between adjacent main characters |
|
|
94
96
|
| Space / newline | One full blank character slot / a new column |
|
|
95
97
|
|
|
96
|
-
See the [syntax guide](docs/syntax.md) (Chinese) for the complete notation and input examples.
|
|
97
|
-
|
|
98
98
|
## Package entries and documentation
|
|
99
99
|
|
|
100
|
-
`npm run build` writes the library to `dist/lib`.
|
|
101
|
-
|
|
102
|
-
Further documentation is currently in Chinese: [architecture and options](docs/architecture.md), [rules and sources](docs/rules.md), [punctuation](docs/punctuation.md), [reference implementation study](docs/reference-study.md), and [validation](docs/validation.md).
|
|
100
|
+
`npm run build` writes the library to `dist/lib`. Use `kanbun-typesetter`, `kanbun-typesetter/html`, `kanbun-typesetter/react`, and `kanbun-typesetter/styles.css`. The package is available on npm and can also be used through local references or links during development.
|
|
103
101
|
|
|
104
102
|
HTML and React are implemented; Canvas is not yet implemented. Font measurement and layout require a browser. React SSR outputs a host container, with actual typesetting performed on the client.
|
|
105
103
|
|
|
106
|
-
Run `npm run pack:check` to build, pack, install, and validate the actual tarball. Artifacts are written to `artifacts/npm/`. See the [packaging guide](docs/publishing.md) (Chinese) for local installation and outstanding release decisions.
|
|
107
|
-
|
|
108
104
|
## License
|
|
109
105
|
|
|
110
106
|
This project is licensed under the [MIT License](LICENSE). Third-party materials retain their respective rights and licenses.
|
|
111
107
|
|
|
112
108
|
## Acknowledgments
|
|
113
109
|
|
|
114
|
-
Thanks to Phesoca for creating and sharing [kanbunHTML](https://github.com/untunt/kanbunHTML) and its [online demo](https://phesoca.com/kanbun-html/). The implementation and examples informed this project's study of typesetting behavior. We measured text boxes and grapheme coordinates in the public demo using browsers and recorded these observations as comparison data for validating selected annotation positions.
|
|
110
|
+
Thanks to Phesoca for creating and sharing [kanbunHTML](https://github.com/untunt/kanbunHTML) and its [online demo](https://phesoca.com/kanbun-html/). The implementation and examples informed this project's study of typesetting behavior. We measured text boxes and grapheme coordinates in the public demo using browsers and recorded these observations as comparison data for validating selected annotation positions.
|
package/README.ja.md
CHANGED
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
TypeScript による漢文訓読組版ツールです。独立した HTML レンダラーと React TSX コンポーネントを提供します。振り仮名、送り仮名、再読文字の注記、複合返り点、句読点、つなぎ線、熟語単位のルビに対応します。ブラウザーで文字の寸法を測定して配置を計算し、選択・コピーできるテキストとして表示します。
|
|
6
6
|
|
|
7
|
+
## インストール
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install kanbun-typesetter
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
[npm: kanbun-typesetter](https://www.npmjs.com/package/kanbun-typesetter) · 現在のバージョン:`0.1.1`。
|
|
14
|
+
|
|
7
15
|
## ディレクトリ構成
|
|
8
16
|
|
|
9
17
|
```text
|
|
@@ -16,15 +24,13 @@ src/
|
|
|
16
24
|
examples/
|
|
17
25
|
html/ 独立 HTML デモのコードと画面用 CSS
|
|
18
26
|
index.html デモの入口
|
|
19
|
-
tests/ 単体テスト、ブラウザーテスト、React テスト用ページ
|
|
20
|
-
docs/ 規則、実装の説明、検証記録
|
|
21
27
|
```
|
|
22
28
|
|
|
23
29
|
[HTML ディレクトリ](src/html/README.md) · [React ディレクトリ](src/react/README.md)
|
|
24
30
|
|
|
25
31
|
## ローカルで実行
|
|
26
32
|
|
|
27
|
-
Node.js 22.12 以降を使用してください。検証環境は Node.js 24
|
|
33
|
+
Node.js 22.12 以降を使用してください。検証環境は Node.js 24 です。
|
|
28
34
|
|
|
29
35
|
```sh
|
|
30
36
|
npm ci
|
|
@@ -35,12 +41,8 @@ npm run dev -- --port 5188 --strictPort
|
|
|
35
41
|
|
|
36
42
|
```sh
|
|
37
43
|
npm run build # 型検査、デモ、ライブラリーと型定義の生成
|
|
38
|
-
npm test # パーサーと組版の単体テスト
|
|
39
|
-
npm run test:browser # Chrome・WebKit での検証
|
|
40
44
|
```
|
|
41
45
|
|
|
42
|
-
ブラウザーテストにはシステムにインストールされた Chrome(`channel: chrome`)と Playwright WebKit が必要です。後者は `npx playwright install webkit` で導入できます。
|
|
43
|
-
|
|
44
46
|
## 既定値と組み方
|
|
45
47
|
|
|
46
48
|
- アキ組:`spacingMode: 'aki'`。
|
|
@@ -78,7 +80,7 @@ export function Reading({ text }: { text: string }) {
|
|
|
78
80
|
}
|
|
79
81
|
```
|
|
80
82
|
|
|
81
|
-
組版設定は `baseSpacing={1}`、`kanjiFontSize={40}` のように JSX の props として渡します。内容・設定の更新、自動列高、`onLayout` / `onError`、アンマウント時の後処理に対応します。React は任意依存で、React 用の入口を使用する場合だけ必要です。[React ディレクトリ](src/react/README.md)
|
|
83
|
+
組版設定は `baseSpacing={1}`、`kanjiFontSize={40}` のように JSX の props として渡します。内容・設定の更新、自動列高、`onLayout` / `onError`、アンマウント時の後処理に対応します。React は任意依存で、React 用の入口を使用する場合だけ必要です。[React ディレクトリ](src/react/README.md)を参照してください。
|
|
82
84
|
|
|
83
85
|
## 入力記法
|
|
84
86
|
|
|
@@ -93,22 +95,16 @@ export function Reading({ text }: { text: string }) {
|
|
|
93
95
|
| `胡-蝶`、`胡‐蝶`、`胡―蝶` | 隣り合う親文字間のつなぎ線 |
|
|
94
96
|
| 空白 / 改行 | 全角 1 字分の空白字位 / 列の区切り |
|
|
95
97
|
|
|
96
|
-
記法の詳細と入力例は[入力記法の説明](docs/syntax.md)(中国語)を参照してください。
|
|
97
|
-
|
|
98
98
|
## パッケージの入口と資料
|
|
99
99
|
|
|
100
|
-
`npm run build` で `dist/lib`
|
|
101
|
-
|
|
102
|
-
詳細資料は現在中国語です:[実装と設定](docs/architecture.md)、[組版規則と出典](docs/rules.md)、[句読点](docs/punctuation.md)、[既存実装の調査](docs/reference-study.md)、[検証記録](docs/validation.md)。
|
|
100
|
+
`npm run build` で `dist/lib` を生成します。`kanbun-typesetter`、`kanbun-typesetter/html`、`kanbun-typesetter/react`、`kanbun-typesetter/styles.css` を使用できます。npm からインストールでき、開発時はローカル参照やリンクでも利用できます。
|
|
103
101
|
|
|
104
102
|
HTML と React に対応しており、Canvas 版は未実装です。フォント測定と配置にはブラウザーが必要です。React の SSR はコンテナーのみを出力し、実際の組版はクライアント側で行います。
|
|
105
103
|
|
|
106
|
-
`npm run pack:check` で実際の tarball を生成・インストールして検証します。成果物は `artifacts/npm/` に出力します。ローカルでの利用と公開前の確認事項は[npm パッケージの説明](docs/publishing.md)(中国語)を参照してください。
|
|
107
|
-
|
|
108
104
|
## ライセンス
|
|
109
105
|
|
|
110
106
|
本プロジェクトは [MIT ライセンス](LICENSE)で公開しています。第三者の資料に関する権利とライセンスは変更されません。
|
|
111
107
|
|
|
112
108
|
## 謝辞
|
|
113
109
|
|
|
114
|
-
[漢文HTML](https://github.com/untunt/kanbunHTML)と[オンラインデモ](https://phesoca.com/kanbun-html/)を開発・公開された Phesoca
|
|
110
|
+
[漢文HTML](https://github.com/untunt/kanbunHTML)と[オンラインデモ](https://phesoca.com/kanbun-html/)を開発・公開された Phesoca 氏に感謝いたします。公開された実装と用例は、本プロジェクトの組版動作の調査と用例の検証において参考となりました。公開デモの文字ボックスと書記素の座標をブラウザーで計測し、一部の注記位置を検証するための比較データとして記録しています。
|
package/README.md
CHANGED
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
用 TypeScript 实现的漢文訓読排版工具,提供独立 HTML 渲染器和 React TSX 组件。支持振假名、送假名、再读文字、复合返点、标点、连接线及多字联合注音。浏览器实测字体尺寸后计算布局,正文保留为可选择、可复制的文字。
|
|
6
6
|
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install kanbun-typesetter
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
[npm:kanbun-typesetter](https://www.npmjs.com/package/kanbun-typesetter) · 当前版本 `0.1.1`。
|
|
14
|
+
|
|
7
15
|
## 项目目录
|
|
8
16
|
|
|
9
17
|
```text
|
|
@@ -16,15 +24,13 @@ src/
|
|
|
16
24
|
examples/
|
|
17
25
|
html/ 独立 HTML 演示页面的代码和界面样式
|
|
18
26
|
index.html 演示页面入口
|
|
19
|
-
tests/ 单元测试、浏览器测试和 React 测试页面
|
|
20
|
-
docs/ 规则依据、实现说明及验证记录
|
|
21
27
|
```
|
|
22
28
|
|
|
23
29
|
[HTML 目录说明](src/html/README.md) · [React 目录说明](src/react/README.md)
|
|
24
30
|
|
|
25
31
|
## 本地运行
|
|
26
32
|
|
|
27
|
-
建议使用 Node.js 22.12 或更新版本;项目在 Node.js 24
|
|
33
|
+
建议使用 Node.js 22.12 或更新版本;项目在 Node.js 24 下验证。
|
|
28
34
|
|
|
29
35
|
```sh
|
|
30
36
|
npm ci
|
|
@@ -35,12 +41,8 @@ npm run dev -- --port 5188 --strictPort
|
|
|
35
41
|
|
|
36
42
|
```sh
|
|
37
43
|
npm run build # 类型检查、演示页构建、库与类型声明
|
|
38
|
-
npm test # 解析器和排版单元测试
|
|
39
|
-
npm run test:browser # Chrome 与 WebKit 浏览器检查
|
|
40
44
|
```
|
|
41
45
|
|
|
42
|
-
浏览器测试需要系统 Chrome(`channel: chrome`)和 Playwright WebKit;可用 `npx playwright install webkit` 安装后者。
|
|
43
|
-
|
|
44
46
|
## 默认排版
|
|
45
47
|
|
|
46
48
|
- 疏排:`spacingMode: 'aki'`。
|
|
@@ -79,7 +81,7 @@ export function Reading({ text }: { text: string }) {
|
|
|
79
81
|
}
|
|
80
82
|
```
|
|
81
83
|
|
|
82
|
-
所有排版参数都可以直接作为 JSX 属性传入,例如 `baseSpacing={1}`、`kanjiFontSize={40}`。组件支持参数更新、自动列高、`onLayout` / `onError` 回调和卸载清理。React 是可选依赖,只有 React 入口需要它。见 [React
|
|
84
|
+
所有排版参数都可以直接作为 JSX 属性传入,例如 `baseSpacing={1}`、`kanjiFontSize={40}`。组件支持参数更新、自动列高、`onLayout` / `onError` 回调和卸载清理。React 是可选依赖,只有 React 入口需要它。见 [React 目录说明](src/react/README.md)。
|
|
83
85
|
|
|
84
86
|
## 输入语法
|
|
85
87
|
|
|
@@ -94,26 +96,16 @@ export function Reading({ text }: { text: string }) {
|
|
|
94
96
|
| `胡-蝶`、`胡‐蝶`、`胡―蝶` | 相邻正文字符之间的连接线 |
|
|
95
97
|
| 空格 / 换行 | 一个完整空白字位 / 分列 |
|
|
96
98
|
|
|
97
|
-
完整记法与输入示例见[输入记法说明](docs/syntax.md)。
|
|
98
|
-
|
|
99
99
|
## 库入口与文档
|
|
100
100
|
|
|
101
|
-
`npm run build` 生成 `dist/lib
|
|
102
|
-
|
|
103
|
-
- [排版实现及参数](docs/architecture.md)
|
|
104
|
-
- [排版规则与依据](docs/rules.md)
|
|
105
|
-
- [标点处理](docs/punctuation.md)
|
|
106
|
-
- [既有实现的源码研究](docs/reference-study.md)
|
|
107
|
-
- [验证记录](docs/validation.md)
|
|
101
|
+
`npm run build` 生成 `dist/lib`。可使用 `kanbun-typesetter`、`kanbun-typesetter/html`、`kanbun-typesetter/react` 和 `kanbun-typesetter/styles.css`。可通过 npm 安装,也可在开发时使用本地引用或链接。
|
|
108
102
|
|
|
109
103
|
当前提供 HTML 和 React 渲染方式。Canvas 版本尚未实现。字体测量和排版需要浏览器;React 服务端渲染只输出宿主容器,在客户端完成实际排版。
|
|
110
104
|
|
|
111
|
-
本地打包与实际安装验证:`npm run pack:check`。产物位于 `artifacts/npm/`,使用步骤及发布前待确认事项见[npm 打包说明](docs/publishing.md)。
|
|
112
|
-
|
|
113
105
|
## 许可证
|
|
114
106
|
|
|
115
107
|
本项目采用 [MIT 许可证](LICENSE)。第三方材料的权利及许可不因本项目的许可证而改变。
|
|
116
108
|
|
|
117
109
|
## 鸣谢
|
|
118
110
|
|
|
119
|
-
感谢绯索卡(Phesoca)开发并公开[漢文HTML](https://github.com/untunt/kanbunHTML)及其[在线演示](https://phesoca.com/kanbun-html/)
|
|
111
|
+
感谢绯索卡(Phesoca)开发并公开[漢文HTML](https://github.com/untunt/kanbunHTML)及其[在线演示](https://phesoca.com/kanbun-html/),为本项目的排版行为研究和样例验证提供参考。本项目在浏览器中测量其公开演示的文字框与字素坐标,记录为布局对照数据,用于验证部分注音定位行为。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kanbun-typesetter",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite --host 127.0.0.1",
|
|
@@ -61,7 +61,6 @@
|
|
|
61
61
|
"files": [
|
|
62
62
|
"dist/lib",
|
|
63
63
|
"README*.md",
|
|
64
|
-
"docs",
|
|
65
64
|
"src/html/README.md",
|
|
66
65
|
"src/react/README.md",
|
|
67
66
|
"LICENSE"
|
package/src/react/README.md
CHANGED
|
@@ -27,7 +27,7 @@ export function Reading({ text }: { text: string }) {
|
|
|
27
27
|
}
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
示例使用安装后的包入口。`source` 必填,全部 `LayoutOptions` 可直接作为 props;可传入容器属性和 `debug`。默认疏排、字间 1.0em、超长送假名右移。组件复用 `../html`,不接受 `children` 或 `dangerouslySetInnerHTML`。SSR
|
|
30
|
+
示例使用安装后的包入口。`source` 必填,全部 `LayoutOptions` 可直接作为 props;可传入容器属性和 `debug`。默认疏排、字间 1.0em、超长送假名右移。组件复用 `../html`,不接受 `children` 或 `dangerouslySetInnerHTML`。SSR 仅输出容器,客户端完成实际排版。卸载时自动清理。
|
|
31
31
|
|
|
32
32
|
Examples use the installed package entries. `source` is required; all `LayoutOptions` are accepted as direct props, alongside container attributes and `debug`. Defaults: aki layout, 1.0em base gap, overflow okurigana shifting enabled. The component uses `../html` and does not accept `children` or `dangerouslySetInnerHTML`. SSR outputs only the host; typesetting runs on the client. Cleanup is automatic on unmount.
|
|
33
33
|
|
package/docs/architecture.md
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
# 排版实现与参数说明
|
|
2
|
-
|
|
3
|
-
独立 TypeScript 漢文訓読引擎,HTML 优先。包含 AST 解析、浏览器批量测量、逻辑坐标布局、约束避让、换列、可选择的 DOM 文本、可视化调试和演示页。没有运行时框架依赖。
|
|
4
|
-
|
|
5
|
-
```sh
|
|
6
|
-
npm install
|
|
7
|
-
npm run dev -- --port 5188 --strictPort
|
|
8
|
-
# 打开 http://127.0.0.1:5188
|
|
9
|
-
npm run build
|
|
10
|
-
npm test
|
|
11
|
-
npx playwright install webkit
|
|
12
|
-
# 测试使用系统 Google Chrome;其他系统可将 playwright.config.ts 的 channel 删除并安装 chromium
|
|
13
|
-
npm run test:browser
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
`dist/` 为演示页构建结果;`dist/lib/` 为核心 ES 模块及 TypeScript 声明,适合由宿主 bundler 引入。样式需单独引入。开发环境 Node 24;构建工具 Vite 7。
|
|
17
|
-
|
|
18
|
-
代码示例的导入路径以项目根目录为基准。目录及快速接入见[项目 README](../README.md)。
|
|
19
|
-
|
|
20
|
-
## API
|
|
21
|
-
|
|
22
|
-
```ts
|
|
23
|
-
import { parseKanbun, layoutKanbun, renderKanbun, DOMTextMeasurer,
|
|
24
|
-
serializeKanbun, verifyRenderedGeometry } from './src/index';
|
|
25
|
-
import './src/html/styles.css';
|
|
26
|
-
|
|
27
|
-
const ast = parseKanbun('瀝(そそ)グ[二]`朱岩`(しゆがん)[一]ニ');
|
|
28
|
-
const measurer = new DOMTextMeasurer(); // 跨次布局复用测量缓存
|
|
29
|
-
const result = await layoutKanbun(ast, {
|
|
30
|
-
writingMode: 'vertical-rl',
|
|
31
|
-
spacingMode: 'aki', // 默认疏排;'beta' 为密排
|
|
32
|
-
kanjiFontSize: 32,
|
|
33
|
-
annotationScale: .5,
|
|
34
|
-
baseSpacing: 1, // em,仅 aki 生效
|
|
35
|
-
annotationGap: .25, // em,期望保留的注音间距
|
|
36
|
-
shiftOverflowOkurigana: true, // 默认开启:超长送假名右移并对齐下一字头
|
|
37
|
-
columnHeight: 560, // px,未包含页边距
|
|
38
|
-
columnGap: 24, // px,正文与普通右注音轨道间的列空白,再读注音复用此处
|
|
39
|
-
collisionPolicy: 'strict',
|
|
40
|
-
collisionTolerance: 0.05, // 主字 em;0 为不容许边缘交叠
|
|
41
|
-
}, measurer);
|
|
42
|
-
const root = renderKanbun(result, document.querySelector('#preview')!, {
|
|
43
|
-
showBoxes: true, showUnits: true, showCollisions: true,
|
|
44
|
-
});
|
|
45
|
-
console.log(result.diagnostics, verifyRenderedGeometry(result, root));
|
|
46
|
-
console.log(serializeKanbun(ast)); // 与输入完全相同
|
|
47
|
-
console.log(serializeKanbun(ast, 'canonical')); // 省略的送假名括号显式化
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
自动处理字体完成加载、内容更新和容器高度变化:
|
|
51
|
-
|
|
52
|
-
```ts
|
|
53
|
-
import { KanbunViewer } from './src/index';
|
|
54
|
-
const viewer = new KanbunViewer(host, {
|
|
55
|
-
source, autoColumnHeight: true,
|
|
56
|
-
layout: { kanjiFontSize: 32 },
|
|
57
|
-
onLayout: result => console.log(result.diagnostics),
|
|
58
|
-
onError: console.error,
|
|
59
|
-
});
|
|
60
|
-
viewer.setSource(nextSource);
|
|
61
|
-
viewer.setOptions({ spacingMode: 'aki' });
|
|
62
|
-
// 卸载时
|
|
63
|
-
viewer.destroy();
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
`autoColumnHeight` 需要宿主有明确高度(横排时为宽度),不能让宿主高度随内部页面无限增长。关闭时 `columnHeight` 控制列高,容器宽度只影响滚动视口。纯函数 API 的缓存失效由调用方负责:外部字体加载后执行 `measurer.clear()`。Viewer 自动监听 `document.fonts.loadingdone`。复用同一 AST 时不要直接修改 `raw` 与 `text` 后期待无损序列化自动同步;见下文。
|
|
67
|
-
|
|
68
|
-
## 输入及数据
|
|
69
|
-
|
|
70
|
-
- `字(かな){カナ}[レ]`、省略括号的片假名、`<かな>|カナ|` 和重复标记均保留;渲染时同类标注按出现顺序合并。
|
|
71
|
-
- 默认将括号振假名前连续、尚未附注的汉字串作为整体:`斜光(しやくわう)`、`漫漫(まんまん)トシテ` 和 `朱岩(しゆがん)` 都形成多字注音单元。先前注音、标点、空白、换行和显式分组会截断这个范围。原始输入保持不变。
|
|
72
|
-
- `` `漢字`(かな) `` 仍可明确范围;例如 `` 春眠不覺`曉`(あかつき) `` 只标「曉」。默认规则按输入边界确定范围,并非语言学分词;长串汉字内部需要不同范围时使用显式分组。`parseKanbun(source, { implicitRubyGroups: false })` 可恢复参考工具中裸注音只附前一字的兼容行为。规范化序列化会用显式分组表达解析结果,无损序列化仍返回原输入。
|
|
73
|
-
- 正文每个空格(包括全角空格、制表符)渲染为一个全角空白字符 `U+3000`,占一个完整主字位;连续空格逐个保留。疏排空白字位也按固定字间推进。空白会隔断隐式整体注音范围,换行仍用于断列。无损序列化和“复制原文”保留原始空格,规范化序列化输出全角空白。
|
|
74
|
-
- Unicode 扩展汉字、IVS、`㆐–㆟`、`―`、`〻`,中日标点、空格、CRLF 和空行均保留。`Intl.Segmenter` 按字素分段。
|
|
75
|
-
- `document.children` 为段落节点;每个源换行形成一个显式断列节点,空行也保留。`sourceRange` 使用 UTF-16 偏移,与 textarea 的选区 API 一致。
|
|
76
|
-
- 不完整、孤立或嵌套标记产生诊断;原文作为 `unknown` 节点可见,不进入 HTML 解释器。
|
|
77
|
-
- `serializeKanbun(ast)` 拼接 AST 节点的 `raw` 与段落分隔符,无损返回。`canonical` 从语义字段生成显式括号,保留重复注释、次序和未知内容。编辑 AST 后应使用 `canonical`,或重新解析生成的新 source。
|
|
78
|
-
- 普通选择/复制为真实 DOM 文本;“复制原文”复制完整带标注源文本。附加的 `application/x-kanbun` 剪贴板格式只供支持此格式的宿主读取。
|
|
79
|
-
|
|
80
|
-
## 疏排与密排的定义
|
|
81
|
-
|
|
82
|
-
这里的“字间”是沿文字行进方向相邻主字**外框**之间的间隔。纵排时指上下间隔;不是左右列距,也不是两个字的可见墨迹之间的空白。
|
|
83
|
-
|
|
84
|
-
- **密排(ベタ組)**:不预留基础字间,即 0 em。没有标注约束时主字外框相接;长读音、送假名、返点等需要空间时,仅在相关位置增加间距。因此密排不保证整篇字间始终为零。
|
|
85
|
-
- **疏排(アキ組)**:主字按设定的固定字间排列,本演示默认 1.0 em(一字空),可自行设定。长标注不推开主字,也不自动放大全篇字距;先在已有空白内调整注音位置,超长时按可选策略在侧边折返。仍无法满足约束才报告诊断。
|
|
86
|
-
|
|
87
|
-
1 em 为主字字号,例如主字 32px、疏排固定字间 0.5em 时,普通单字的主字外框固定间隔 16px。这里的数值是额外间隔,不包含字框本身的高度。`baseSpacing` 只在疏排生效;注音间距 `annotationGap` 与列距 `columnGap` 是另外两个独立参数。
|
|
88
|
-
|
|
89
|
-
本版固定疏排依据:[《訓点漢文組版要件》§3.1](https://kanbun-req.mkpo.li/)。JAGAT 使用“最低字间”的另一种表述;本版不把这一惯例混入固定等距疏排。
|
|
90
|
-
|
|
91
|
-
## 布局及调试
|
|
92
|
-
|
|
93
|
-
核心只使用 inline / block 轴;垂直与水平模式通过最后的坐标变换共享求解器。DOM 顺序与输入一致,视觉列由右向左推进。
|
|
94
|
-
|
|
95
|
-
测量阶段等待字体加载,按文本、字体、字号、字距、方向和复合返点样式缓存。一次批量写入不可见 DOM,之后统一读取元素与 Range 框;渲染使用相同样式。没有用字符数量代替实际尺寸。同时测量 Range 相对元素的偏移,使用外框包围元素框与 Range 框,并按校准偏移定位内部文字;字体 fallback 的基线偏移也进入碰撞约束。返回的是保守的**文字布局框**,不是字体轮廓的墨迹边界。渲染后校验元素位置和 Range 是否越界;缩放后的校验需先恢复 100% 坐标比例。
|
|
96
|
-
|
|
97
|
-
每个单位包括主字、右侧读音、左侧再读音、返点和连接点。振假名与送假名分别测量,分别定位,HTML 中使用两个独立的 `div.kanbun-furigana` / `div.kanbun-okurigana`;再读侧对应 `div.kanbun-reread-furigana` / `div.kanbun-reread-okurigana`。内部字素仍按解算后的坐标排列,整体注音分布及折返后也保持分组。`LayoutPart.annotationKind` 保留具体标注类型,`kind` 继续表示所在的 reading/reread 轨道。注音优先定位振假名,再追加送假名。疏排默认 `akiReadingAlign: "contextual"`:单字有振假名及送假名时,振假名末端对齐主字末端,送假名紧随其后;只有振假名时居中。再读音独立定位。选择 `configured` 才使用自设的单字肩付き/中付き。返点位于主字后方、外框左端对齐;复合返点的每个字使用普通返点字号,分别输出独立 div,沿纵向排列并使上下部分重叠;不缩小字号。`[一レ]` 组合额外上移普通返点字号的 0.3em(主字 32px、返点 16px 时为 4.8px),允许只与所属母字底部有这一小段框重叠;其他复合返点不套用此许可。返点与再读音分离。再读振假名、送假名使用已有行间空白,不参与正文列距计算;即使再读注音折返也不因此扩大列距。最外列的长标注只在必要时延展页面外缘显示范围。连接标记 `-`、`‐`、`―` 绘成细线,位于相邻母字框之间的中央;密排保持半字长短线并在实际空隙居中,疏排线段填满固定字间。二の字点保留为单独可附注单元。
|
|
98
|
-
|
|
99
|
-
密排字间由基础 advance、所有在同一侧边区间可能相交的框,以及注音间距约束共同求最大下界,局部推移需要避让的后字。疏排直接使用固定 advance,不应用这个推移量;多字组内部也保留相同固定字间,整组仍不可拆列。密排 Strict 禁止前字假名挂到后字主体高度。固定疏排按实际同列的前后主字确定可用边界,在注音保持顺序及间隔的条件下求解移位;末单元可用本列余下空间,不虚设一个后字限制它。仅当这一步无解时才尝试折返,最后检查碰撞。
|
|
100
|
-
|
|
101
|
-
可调惯例:字体、主字/注音/返点字号、密排/疏排、肩付き/中付き、送假名起点 0.5/0.75em、注音间距、列高、列距、Unicode/原返点字形、溢出策略。Traditional 仅对 **0.75em 起点、无振假名的送假名** 放宽,越界量最多 0.25em,这一越界变体用于密排;疏排通过空白内移位和侧边注音重排保持主字固定。注音边缘交叠默认容许 0.05 主字 em,可设为 0;相交区域的横、纵深度只要至少一个不超过容差,就视为浅交叠。它作用于含普通/再读注音的配对,正文彼此和连接线仍严格检查。此设置是字框容差,并非字体墨迹碰撞测量。出处与详细差异见 [docs/rules.md](rules.md);源码分析及实测对照见 [docs/reference-study.md](reference-study.md)。
|
|
102
|
-
|
|
103
|
-
多字整体注音使用独立的 `groupRubyAlign`,不套用单字的 `furiganaAlign`。当振假名比主字组短时,默认 `space-between` 对齐首尾,均分内部空白;也可用 `space-around` 按端空 : 内部间隔 : 端空 = 1 : 2 : 1 分配,或 `start` / `center` / `end` 保持注音密排并分别靠起端、居中、靠末端(纵排对应顶部、中央、底部;横排对应左、中、右)。按实际字素测量计算,只改变注音内部间隔和位置,不改变主字字距。送假名在已分布的振假名末端紧接排列,不参与振假名的对齐计算。长度相等时自然首尾齐平;较长时 `start` / `center` / `end` 仍按所选边缘定位,分布模式则退回居中,再接受疏排可用空间及折返约束。演示页的“多字联合注音对齐”可即时切换这些模式。依据:[JLREQ §3.3.6](https://www.w3.org/TR/jlreq/#positioning_of_groupruby_with_respect_to_base_characters)。
|
|
104
|
-
|
|
105
|
-
可选开关 `shiftOverflowOkurigana`(演示页“超长送假名右移”,默认开启):同时有振假名和送假名时,先在前后实际可用空白内尝试整段移位;疏排的保序避让仍无解、且分离送假名确实能减少冲突时,才把送假名完整移到振假名右侧一行。密排也先检查整段是否可在已有字位内排下;最终按实际布局使其末字底部与下一主字顶部齐平。触发以实测尺寸判断,不按固定假名个数猜测。密排、疏排均可使用,疏排不改变主字字距。送假名继续使用独立 div,不加入振假名的折返流。
|
|
106
|
-
|
|
107
|
-
密排在换列时将当前单元与用于对齐的下一主字放在同列;疏排只在已有同列下一主字时启用,不跨列寻找对齐点。没有后续主字(包括段末)时不启用;仅有送假名或未超长时仍按原规则。再读侧保持原策略。这是可选排版方式,不宣称来自统一传统规范。右移送假名使用既有列间空白,不增加正文列距或页面宽度;极端长送假名与其他右侧标注发生交叠时仍报告碰撞。
|
|
108
|
-
|
|
109
|
-
疏排的 `akiAnnotationOverflow` 支持:
|
|
110
|
-
|
|
111
|
-
- `wrap`(默认):先在固定字间的空白中移位,中心对齐允许负偏移,不再把长注音一律截到主字上端。每段振假名和送假名仍按原顺序连续;装不下时,以实测的完整字素为界,在同一汉字单元的侧边换成更多注音子列,字体大小不变。右侧子列按纵排右到左阅读;左侧再读音独立处理。主字和所有子列始终整体换列。
|
|
112
|
-
- `report`:仍尝试已有空白内的位置调整,但不折返;约束无法满足时报告错误。
|
|
113
|
-
|
|
114
|
-
折返用实际单字素尺寸布局,`annotationLine` 标识子列。列轨道根据重排后的标注总宽度计算,因此长注音增加的是侧边所需空间,不是汉字字距。无字形缩放、遮盖或裁切;如果所设空间连一个完整注音字形也容纳不了,会产生 `ANNOTATION_OVERFLOW`。这种子列策略是可配置实现,并非来自 JAGAT 的统一算法;文献可直接支持的部分是半字号、先读音后送假名、再读的另一侧配置、普通 ruby 的中付き及允许的空白内越界。
|
|
115
|
-
|
|
116
|
-
`extraSpacing` 记录密排在基础 advance 之外被推移的距离;固定疏排中始终为 0。调试模式显示主字蓝框、注音橙框、再读紫框、返点绿框、单元虚框、扩张量和红色碰撞区域。
|
|
117
|
-
|
|
118
|
-
句读(`、。,.`)及常用括号使用主字字号、半角字位,开括号前与句读/闭括号后默认留半字空白;连续标点按类别合并空白,行首开括号不留前空。长送假名不会把句读从母字后推走,而由后字避让。返点和紧接的句读按规则共享一格,保留完整字体框,因此这一对允许字体框相交;不将其报告为文字碰撞。疏排将标点放入实际固定字间,不增加一个主字位;空白不足时保留诊断。详见 [标点实现记录](punctuation.md)。
|
|
119
|
-
|
|
120
|
-
禁则以开括号与后字、句末标点与前字建立不可断列组合;根据包括注释在内的完整占用判断换列。过长组合只产生一次 `UNIT_OVERFLOW` 警告:`expand` 扩展页面,`report` 保留可见溢出,均不裁切、不缩小。可用 `result.diagnostics` 阻止有诊断的结果进入正式出版流程。
|
|
121
|
-
|
|
122
|
-
## 验收与范围
|
|
123
|
-
|
|
124
|
-
实测结果、测试覆盖和当前缺项见 [docs/validation.md](validation.md)。本版是可运行、可验证的 HTML 基础版本,尚不能声称覆盖所有正式古典文献排版规范。
|
|
125
|
-
|
|
126
|
-
- 疏排注音折返是本引擎可选的长注音处理策略,不代表所有传统印本的惯例,也不宣称是 JAGAT 的强制要求。严格单列注音可选择 `akiAnnotationOverflow: "report"`;这个策略无法容纳的输入会返回诊断。
|
|
127
|
-
- 已提供 React 包装;尚无 Canvas、SVG、纸张分页和多页导出。Canvas 后续可消费 `KanbunLayout.units[].parts` 的物理框与文字样式,不需重写约束求解器;但必须校准其字体绘制原点与纵排字形。
|
|
128
|
-
- 句读及常用括号已实现半角字位、连续标点间空白压缩、返点与句读共位和基本禁则。尚未实现行末悬挂、齐行时的标点伸缩及完整 JLREQ 禁则表;省略号、感叹号等保持各自原有字幅。
|
|
129
|
-
- 字体缺字由 CSS fallback 链处理,可选择原字返点回退;不包含内嵌字体或可靠的逐字缺字探测。不同机器字体不能保证像素一致。复合返点以同字号字符上下重叠组合,尚未绘制专用传统合字;固定字间不足时利用已有左侧列间空白避让,不通过缩字解决。
|
|
130
|
-
- 不提供字体 outline/ink 精确测量。极端字体的外溢会报告几何诊断;宿主可增加校准或替换 `TextMeasurer`。不通过遮盖或裁切掩盖问题。
|
|
131
|
-
- 具备测量缓存和分段输入,但编辑仍重算整篇几何;尚未实现段落增量布局、虚拟化或长文性能指标。一个 Viewer 应复用一个测量器;没有 DOM 位置反复试探循环。
|
|
132
|
-
- 横排共享逻辑核心,有单元测试;当前视觉验收聚焦纵排。默认示例的训读只用于展示排版,不代表语文学审定。
|
|
133
|
-
|
|
134
|
-
演示页输入框默认载入用户指定的五段原文。预览只显示正文,不再显示纸张框、标题、页脚或示例选择菜单;缩放和复制原文放在输入区上方。
|
|
135
|
-
|
|
136
|
-
送假名右移遇到相邻列再读标注时,先在实际前后字边界内整体移动再读标注,再尝试把两侧标注排进已有列间空隙。仍无解则撤销该处右移,按实测字素在原侧折返;真正放不下时保留原文、字号并报告 `INTERCOLUMN_CONFLICT`。这一步不改变正文位置、字距或列距。界面的“密排送假名下挂”仅控制上述 0.75em 起点的密排惯例,疏排隐藏。
|
|
137
|
-
|
|
138
|
-
## React TSX
|
|
139
|
-
|
|
140
|
-
独立组件位于 `src/react/Kanbun.tsx`,不改变原有 HTML 演示页和核心 API:
|
|
141
|
-
|
|
142
|
-
```tsx
|
|
143
|
-
import { Kanbun } from './src/react';
|
|
144
|
-
import './src/html/styles.css';
|
|
145
|
-
|
|
146
|
-
<Kanbun source={text} spacingMode="aki" baseSpacing={1} />
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
支持全部排版参数、正文更新、容器属性、排版回调与卸载清理。完整接入及本地包导出见 [React 使用说明](react.md)。
|
|
150
|
-
|
|
151
|
-
当前默认设置:疏排(`spacingMode: 'aki'`)、固定字间 `1.0em`(`baseSpacing: 1`),开启超长送假名右移另列(`shiftOverflowOkurigana: true`)。HTML 演示页、引擎及 React 组件使用相同默认值。
|
package/docs/publishing.md
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
# npm 打包与发布准备
|
|
2
|
-
|
|
3
|
-
当前包名为 `kanbun-typesetter`,版本 `0.1.0`。采用 MIT 许可证(见根目录 `LICENSE`);首版版本为 `0.1.0`,包已配置为可公开发布。本地构建、打包和验证不会上传到 registry。
|
|
4
|
-
|
|
5
|
-
## 构建与打包
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
npm ci
|
|
9
|
-
npm test
|
|
10
|
-
npm run pack:check
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
`pack:check` 会执行真实的 `npm pack`(通过 `prepack` 自动构建),在隔离临时目录中从 tarball 离线安装,再验证:
|
|
14
|
-
|
|
15
|
-
- 发布清单与全部 `exports` 目标存在,不包含测试、演示代码或开发脚本。
|
|
16
|
-
- 没有安装 React 时,核心与 HTML 入口可以由 Node 原生 ESM 导入。
|
|
17
|
-
- 消费者的 TypeScript `NodeNext` 类型检查。
|
|
18
|
-
- React 组件的原生 Node SSR 和 TSX 类型声明。
|
|
19
|
-
- Vite 消费者项目构建,包含独立 CSS 导出。
|
|
20
|
-
- Chrome 与 WebKit 中从实际安装包加载 HTML、React,检查字体测量、连接线和再读记法。
|
|
21
|
-
|
|
22
|
-
工具依赖来自本项目的开发依赖,库代码始终来自隔离目录安装的 tarball。浏览器检查需要系统 Chrome 和 Playwright WebKit。包不会被上传到 registry。
|
|
23
|
-
|
|
24
|
-
成功后生成:
|
|
25
|
-
|
|
26
|
-
```text
|
|
27
|
-
artifacts/npm/kanbun-typesetter-0.1.0.tgz
|
|
28
|
-
artifacts/npm/report.json
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
报告包含包名、版本、完整文件清单、大小、integrity 和通过的检查。临时消费者会自动清理,产物目录不进入 Git。
|
|
32
|
-
|
|
33
|
-
只想查看清单或生成 tarball 时:
|
|
34
|
-
|
|
35
|
-
```sh
|
|
36
|
-
npm pack --dry-run
|
|
37
|
-
npm pack
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
这些命令也会运行 `prepack`,自动构建。生成的包携带 `dist/lib`、`LICENSE`、三语言 README、文档和两个接入目录的 README;React 为可选 peer dependency,不捆绑进库代码。库使用 ESM,不提供 CommonJS 构建。
|
|
41
|
-
|
|
42
|
-
## 本地安装
|
|
43
|
-
|
|
44
|
-
在另一个项目中安装生成的包:
|
|
45
|
-
|
|
46
|
-
```sh
|
|
47
|
-
npm install /绝对路径/kanbun-typesetter/artifacts/npm/kanbun-typesetter-0.1.0.tgz
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
HTML:
|
|
51
|
-
|
|
52
|
-
```ts
|
|
53
|
-
import { KanbunViewer } from 'kanbun-typesetter/html';
|
|
54
|
-
import 'kanbun-typesetter/styles.css';
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
React 项目还需要安装宿主依赖:
|
|
58
|
-
|
|
59
|
-
```sh
|
|
60
|
-
npm install react react-dom
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
```tsx
|
|
64
|
-
import { Kanbun } from 'kanbun-typesetter/react';
|
|
65
|
-
import 'kanbun-typesetter/styles.css';
|
|
66
|
-
|
|
67
|
-
<Kanbun source={'胡-蝶\n未(いま)ダ<ず>|ンバ|知'} />
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
核心入口为 `kanbun-typesetter`。CSS 位于包内的 `dist/lib/html/styles.css`,建议通过公开的 `kanbun-typesetter/styles.css` 导入。浏览器负责实际测量;Node 可以导入 API,并可对 React 组件执行 SSR,SSR 输出宿主容器。
|
|
71
|
-
|
|
72
|
-
## 发布前待确认
|
|
73
|
-
|
|
74
|
-
1. 包名确定为 `kanbun-typesetter`;正式发布时再次核对 registry 可用性。
|
|
75
|
-
2. 核对发布包包含 MIT `LICENSE`,且 `package.json` 的 `license` 为 `MIT`。保留第三方材料的来源及其适用许可;本项目的许可证不重新授权第三方材料。
|
|
76
|
-
3. 补充真实的作者、仓库与问题反馈地址(如有)。不使用占位账号或虚构地址。
|
|
77
|
-
4. 确定版本号,确认三语言 README 的安装说明与发布状态。
|
|
78
|
-
5. 确认发布元数据后执行:
|
|
79
|
-
|
|
80
|
-
```sh
|
|
81
|
-
npm run check:release
|
|
82
|
-
npm run pack:check
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
`check:release` 检查包未被标记为 private,并检查许可证字段及文件。`prepublishOnly` 会在发布时运行这一检查与单元测试。
|
|
86
|
-
|
|
87
|
-
## 确认后手动发布
|
|
88
|
-
|
|
89
|
-
```sh
|
|
90
|
-
npm login
|
|
91
|
-
npm whoami
|
|
92
|
-
npm publish --access public
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
按 npm 提示完成账户认证与双重验证。当前准备工作不执行这些命令。发布后更新 README 的发布状态,后续版本增加版本号再发布。
|
package/docs/punctuation.md
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# 句读与括号
|
|
2
|
-
|
|
3
|
-
依据:[JAGAT 56「句読点・括弧類の配置処理」「返り点の配置処理」](https://www.jagat.or.jp/archives/21315)。标点与返点共位的参考观察见[参考实现研究](reference-study.md)。
|
|
4
|
-
|
|
5
|
-
此前的缺口是把标点分类成独立节点后,仍以普通全角主字的方式布局。现在保留独立 AST 节点和原文范围,但使用专门的字位及间距处理。
|
|
6
|
-
|
|
7
|
-
- `、。,.` 与 `「」『』()〔〕【】〈〉《》` 保留主字字号,使用半字字位。没有把句读缩成半字号。
|
|
8
|
-
- 密排中,开括号前留半字空白,句读和闭括号后留半字空白;连续闭括号及句读之间不叠加空白,闭括号接开括号时只保留一份半字空白。连续开括号不插额外空白。行首开括号的具体位置由正文齐头设置控制。
|
|
9
|
-
- 长送假名从母字下方伸出时,句读仍贴着母字后,后字满足注音避让条件后才开始。
|
|
10
|
-
- 返点与紧随的句读可以共享母字后的字位:返点靠左,句读的字形靠右。两者完整字体框可以相交。这是有明确附着关系的许可,其他注音相交仍产生诊断。
|
|
11
|
-
- 疏排把句读、括号放进既有间隔,不为它们增加普通主字位。若连续标点超出可用空白,保留碰撞诊断,不扩大固定主字间距。
|
|
12
|
-
- 句读和闭括号不得拆至行首,开括号不得拆在行末。禁则组合连同其注音整体换列。
|
|
13
|
-
|
|
14
|
-
## 字体测量和 HTML
|
|
15
|
-
|
|
16
|
-
测量与渲染均启用 `vhal`(纵排)/`halt`(横排),由字体提供原字号的半角标点布局。当前 Playwright WebKit 不执行纵排 `vhal`,因此使用日文标点本身的半字空白侧处理:开括号去前空,闭括号及句读去后空。外层为半字的排版字位,内层保留实测的完整字体框,允许空白部分伸出字位。没有裁切、缩放或替换文本字符。
|
|
17
|
-
|
|
18
|
-
因此需要区分“字位”和“字体框”:几何校验对这类标点检查完整的内层测量框,对其他文字仍检查外层框。返点/句读的共位例外同时用于布局报告和独立浏览器检查;不会把所有同单元相交都一概忽略。测试截图用于复核实际字形。
|
|
19
|
-
|
|
20
|
-
省略号、感叹号、问号和二の字点未按上述半字标点压缩。尚无行末悬挂、齐行伸缩或完整 JLREQ 标点组合表。装饰性字体若不遵循日文标点的空白侧惯例,需要额外校准;当前浏览器验收使用本机明朝字体。
|
|
21
|
-
|
|
22
|
-
## 行首开括号
|
|
23
|
-
|
|
24
|
-
`lineStartBracket` 控制实际列首(段落起首或自动换列)的开括号,界面为“行首开括号”:
|
|
25
|
-
|
|
26
|
-
| 值 | 方式 |
|
|
27
|
-
| --- | --- |
|
|
28
|
-
| `hang`(默认) | 开括号按实测半字位向前悬挂,正文首字从列首网格起点开始。竖排向上,横排向左,页面边距保留标点的可见空间。 |
|
|
29
|
-
| `half` | 开括号占半字位,正文紧接其后起排。 |
|
|
30
|
-
| `full` | 每个行首开括号占完整正文格;字形保持原字号并位于该格后半部,正文从下一格开始。疏排保留配置的固定字间。 |
|
|
31
|
-
|
|
32
|
-
例如主字 32px、疏排字间 1em 时,`「天` 的正文「天」在三种模式下分别从 0px、16px、64px 开始。密排的对应位置为 0px、16px、32px。连续开括号按所选方式依次占位,开括号与后面正文保持一起换列。
|
|
33
|
-
|
|
34
|
-
该选项不改变段内开括号的位置、正文固定字距或字号;显式空白仍占自己的字位。布尔参数 `hangOpeningBrackets` 也可选择上悬(`true`)或半字位(`false`);若同时指定,以 `lineStartBracket` 为准。
|
|
35
|
-
|
|
36
|
-
[JLREQ §3.1.5](https://www.w3.org/TR/jlreq/#positioning_of_opening_brackets_at_line_head) 记录了多种行首开括号配置。本项目提供可选的起排策略,不将其中任一种表述为所有文献唯一通行的方式。
|
package/docs/react.md
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# React TSX 组件
|
|
2
|
-
|
|
3
|
-
源码入口为 `src/react/index.ts`,组件为 `src/react/Kanbun.tsx`。React 封装与核心引擎分开;核心入口 `src/index.ts` 不引入 React。现有演示页继续使用独立 HTML 渲染器。
|
|
4
|
-
|
|
5
|
-
在本项目或复制源码后使用:
|
|
6
|
-
|
|
7
|
-
```tsx
|
|
8
|
-
import { Kanbun } from './src/react';
|
|
9
|
-
import './src/html/styles.css';
|
|
10
|
-
|
|
11
|
-
export function Reading({ text }: { text: string }) {
|
|
12
|
-
return (
|
|
13
|
-
<Kanbun
|
|
14
|
-
source={text}
|
|
15
|
-
spacingMode="aki"
|
|
16
|
-
baseSpacing={1}
|
|
17
|
-
kanjiFontSize={32}
|
|
18
|
-
columnHeight={560}
|
|
19
|
-
className="reading"
|
|
20
|
-
style={{ overflow: 'auto' }}
|
|
21
|
-
onLayout={result => console.log(result.diagnostics)}
|
|
22
|
-
onError={error => console.error(error)}
|
|
23
|
-
/>
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
组件接受全部 `LayoutOptions`,直接作为 JSX 属性传入;未指定的参数采用引擎默认值。`source` 为必填的汉文标记文本,输入语法与演示页相同。默认疏排、固定字间 `1.0em`,并开启超长送假名右移另列。修改正文或排版参数会自动更新;移除曾经传入的参数会恢复其默认值。
|
|
29
|
-
|
|
30
|
-
另外支持:
|
|
31
|
-
|
|
32
|
-
- `debug={{ showBoxes: true, showUnits: true, showCollisions: true }}`:显示几何调试标记。
|
|
33
|
-
- `autoColumnHeight`:根据容器实际高度(横排时为宽度)计算列长。请给容器指定尺寸,例如 `style={{ height: 500, overflow: 'auto' }}`。
|
|
34
|
-
- `onLayout(result)`:排版并渲染完成后的通知;排版诊断在 `result.diagnostics` 中。
|
|
35
|
-
- `onError(error)`:参数无效、字体测量等运行错误的通知。
|
|
36
|
-
- `className`、`style`、`id`、`aria-*` 等普通容器属性。
|
|
37
|
-
|
|
38
|
-
React 管理外层 `div`,内部文字节点由 HTML 渲染器管理,因此组件不接受 `children` 或 `dangerouslySetInnerHTML`。它保留实际文字的选择和复制行为,不把正文转换为图片。
|
|
39
|
-
|
|
40
|
-
挂载后才进行浏览器字体测量;SSR 只输出空容器,在客户端完成排版。组件包含 `use client` 声明。卸载时会断开尺寸观察、移除字体加载监听并取消尚未完成的渲染。React StrictMode 的挂载清理流程已经验证。
|
|
41
|
-
|
|
42
|
-
## 作为本地包接入
|
|
43
|
-
|
|
44
|
-
项目尚未发布到 npm。执行 `npm run build` 后,可通过本地包引用或链接在其他项目使用这些导出入口:
|
|
45
|
-
|
|
46
|
-
```tsx
|
|
47
|
-
import { Kanbun, type KanbunProps } from 'kanbun-typesetter/react';
|
|
48
|
-
import 'kanbun-typesetter/styles.css';
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
组件入口需要宿主项目安装 React(peer dependency 为 React 18 或以上;本次浏览器验证使用 React 19)。`react-dom` 只用于本项目的组件集成测试,不是排版核心的运行依赖。构建会生成 `dist/lib/react` 下的组件 JavaScript 和类型声明。
|
|
52
|
-
|
|
53
|
-
行首开括号通过 `lineStartBracket` 控制,支持 `"hang"`(默认,正文首字齐头)、`"half"`(半字位)与 `"full"`(完整第一字位)。例如 `<Kanbun source={text} lineStartBracket="full" />` 让正文从第二格开始。
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|