@ilyankin/tachibana 0.0.0-stage → 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/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +104 -2
- package/THIRD_PARTY_NOTICES.md +36 -0
- package/dist/client.d.ts +103 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +276 -0
- package/dist/client.js.map +1 -0
- package/dist/coordinator.d.ts +74 -0
- package/dist/coordinator.d.ts.map +1 -0
- package/dist/coordinator.js +484 -0
- package/dist/coordinator.js.map +1 -0
- package/dist/error.d.ts +31 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +57 -0
- package/dist/error.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +93 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +36 -0
- package/dist/protocol.js.map +1 -0
- package/dist/sudachi-opfs.d.ts +37 -0
- package/dist/sudachi-opfs.d.ts.map +1 -0
- package/dist/sudachi-opfs.js +279 -0
- package/dist/sudachi-opfs.js.map +1 -0
- package/dist/types.d.ts +92 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/worker.d.ts +8 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +194 -0
- package/dist/worker.js.map +1 -0
- package/licenses/kanji-processor-LICENSE +21 -0
- package/licenses/sudachi-LICENSE +201 -0
- package/licenses/unicode-license.txt +39 -0
- package/package.json +62 -4
- package/wasm/tachibana_wasm.d.ts +2166 -0
- package/wasm/tachibana_wasm.js +1264 -0
- package/wasm/tachibana_wasm_bg.wasm +0 -0
- package/wasm/tachibana_wasm_bg.wasm.d.ts +65 -0
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ilyankin
|
|
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,3 +1,105 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@ilyankin/tachibana`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Offline Japanese dictionary engine for browsers, powered by WebAssembly, SQLite on OPFS (`opfs-sahpool`), Web Workers, transparent multi-tab coordination, and optional Sudachi morphological ranking.
|
|
4
|
+
|
|
5
|
+
No `Cross-Origin-Opener-Policy` / `Cross-Origin-Embedder-Policy` headers required.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @ilyankin/tachibana
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Tachibana } from "@ilyankin/tachibana";
|
|
17
|
+
|
|
18
|
+
const db = await Tachibana.open();
|
|
19
|
+
|
|
20
|
+
// Install any Yomitan v3 dictionary or frequency ZIP (persisted in OPFS).
|
|
21
|
+
await db.install(zipFile, {
|
|
22
|
+
onProgress: (p) => console.log(p.phase, p.processed_bytes, p.total_bytes),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Tap lookup using JavaScript UTF-16 string indices by default.
|
|
26
|
+
const result = await db.lookupReaderCards({
|
|
27
|
+
text: "😀パンを食べました",
|
|
28
|
+
position: 5, // index of '食'
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
console.log(result.cards[0]?.word.term); // "食べる"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Vite configuration
|
|
35
|
+
|
|
36
|
+
Exclude `@ilyankin/tachibana` from Vite's dev pre-bundler so `import.meta.url` keeps pointing at the Worker and `.wasm` assets:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
// vite.config.ts
|
|
40
|
+
import { defineConfig } from "vite";
|
|
41
|
+
|
|
42
|
+
export default defineConfig({
|
|
43
|
+
optimizeDeps: {
|
|
44
|
+
exclude: ["@ilyankin/tachibana"],
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
If a custom bundler or strict CSP requires hosting the Worker or `.wasm` at explicit URLs, pass `workerUrl` and `wasmUrl` to `Tachibana.open({ workerUrl, wasmUrl })`.
|
|
50
|
+
|
|
51
|
+
## Multi-tab coordination
|
|
52
|
+
|
|
53
|
+
`opfs-sahpool` holds exclusive file handles per OPFS directory. In `"opfs"` mode (the default), `Tachibana.open()` elects one leader tab via the Web Locks API (`navigator.locks`) to own the Dedicated Worker, and follower tabs proxy calls transparently over `BroadcastChannel`:
|
|
54
|
+
|
|
55
|
+
- Mutations (`install`, `delete`, `rename`, `setEnabled`, `setOrder`, `configure`, Sudachi changes) emit `onChange` events across all open tabs.
|
|
56
|
+
- When the leader tab closes or crashes, a standby tab acquires the lock, starts its Worker on the same OPFS directory, and replays in-flight read queries automatically.
|
|
57
|
+
- For ephemeral demos, tests, or environments without OPFS (such as non-HTTPS origins), open with `{ storage: "memory" }`.
|
|
58
|
+
|
|
59
|
+
## Optional Sudachi analyzer
|
|
60
|
+
|
|
61
|
+
Dictionary lookup works immediately without Sudachi. To enable contextual ranking and `analyzeText`, stream a SudachiDict `system.dic` (or `.dic.gz`) once into OPFS:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
// First visit: download (auto-decompresses .gz), cache in OPFS, and stream into WASM in 2 MiB chunks.
|
|
65
|
+
await db.installSudachi("https://cdn.example.com/sudachi/system_small.dic.gz", {
|
|
66
|
+
onProgress: (p) => console.log(p.phase, p.loadedBytes, p.totalBytes),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Subsequent visits: load directly from OPFS with zero network traffic.
|
|
70
|
+
if (await db.hasCachedSudachi()) {
|
|
71
|
+
await db.loadCachedSudachi();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const analysis = await db.analyzeText({ text: "国家公務員です" });
|
|
75
|
+
|
|
76
|
+
// Free ~115 MB WASM memory when leaving the reader (keeps OPFS cache intact).
|
|
77
|
+
await db.unloadSudachi();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Installed frequency ranking
|
|
81
|
+
|
|
82
|
+
Install a Yomitan frequency ZIP via `db.install(...)` and enable it on the engine:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
await db.configure({
|
|
86
|
+
frequency: { type: "Installed" },
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Structured errors and `bigint` fields
|
|
91
|
+
|
|
92
|
+
- Engine and lifecycle errors reject with `TachibanaError`, exposing `code`, `message`, `requestId`, and `conflict` (populated on `AlreadyInstalled` so the UI can prompt for `{ replace: err.conflict.dictionary_id }`).
|
|
93
|
+
- 64-bit contract fields (`request_id`, `entry_id`, `sequence`, `entry_count`, `size_bytes`, etc.) are represented as JavaScript `bigint` to preserve exact precision. Text offsets (`position`, `Span`) are `number`.
|
|
94
|
+
|
|
95
|
+
## Entrypoints
|
|
96
|
+
|
|
97
|
+
| Import | Contents |
|
|
98
|
+
|---|---|
|
|
99
|
+
| `@ilyankin/tachibana` | `Tachibana` client, `TachibanaError`, full TypeScript contract types |
|
|
100
|
+
| `@ilyankin/tachibana/worker` | Dedicated Web Worker script |
|
|
101
|
+
| `@ilyankin/tachibana/wasm` | Raw `wasm-bindgen --target web` bindings and `.wasm` binary |
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
Dual-licensed under MIT OR Apache-2.0. Includes third-party notices for vendored Sudachi (`Apache-2.0`) and Unicode/kanji variant tables (`THIRD_PARTY_NOTICES.md`, `licenses/`).
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
Tachibana uses [MIT](LICENSE-MIT) or [Apache-2.0](LICENSE-APACHE).
|
|
4
|
+
|
|
5
|
+
## Embedded data
|
|
6
|
+
|
|
7
|
+
- **`kanji-processor` (`1.0.2`)** — MIT License, Copyright (c) 2024 Lyroxide.
|
|
8
|
+
- Used in [`src/language/kanji_variants.rs`](src/language/kanji_variants.rs).
|
|
9
|
+
- License text: [`third_party/kanji-variants/kanji-processor-LICENSE`](third_party/kanji-variants/kanji-processor-LICENSE).
|
|
10
|
+
- **Unicode Character Database / Unihan (`18.0`, `kJapaneseNewVariant`)** — Unicode License v3, Copyright (c) 1991-2026 Unicode, Inc.
|
|
11
|
+
- Used in [`src/language/kanji_variants.rs`](src/language/kanji_variants.rs).
|
|
12
|
+
- License text: [`third_party/kanji-variants/unicode-license.txt`](third_party/kanji-variants/unicode-license.txt).
|
|
13
|
+
|
|
14
|
+
## Vendored Sudachi
|
|
15
|
+
|
|
16
|
+
- **`WorksApplications/sudachi.rs`** (`Apache-2.0`, used only by the `tachibana-sudachi` crate, not by the published library)
|
|
17
|
+
- A copy of commit `1c21940` with the patches `0001-android-and-32-bit-targets.patch` and `0002-wasm32.patch` applied lives in [`third_party/sudachi-rs/`](third_party/sudachi-rs/README.md), together with its `LICENSE`.
|
|
18
|
+
- The patches adapt plugin loading and 32-bit/WASM targets for Android and `wasm32-unknown-unknown`; the changed lines are marked `tachibana:`, and the original copyright and Apache-2.0 terms are kept.
|
|
19
|
+
|
|
20
|
+
## Test data
|
|
21
|
+
|
|
22
|
+
- **`j-unimorph` (`paradigms.tsv`)** — Creative Commons Attribution 4.0 International (`CC-BY-4.0`).
|
|
23
|
+
- Used only in integration tests ([`tests/paradigms.rs`](tests/paradigms.rs)) and fixture scripts ([`scripts/junimorph-fixture.py`](scripts/junimorph-fixture.py)).
|
|
24
|
+
- License text and provenance: [`third_party/j-unimorph/LICENSE.txt`](third_party/j-unimorph/LICENSE.txt), [`third_party/j-unimorph/README.md`](third_party/j-unimorph/README.md).
|
|
25
|
+
|
|
26
|
+
## Cargo dependencies
|
|
27
|
+
|
|
28
|
+
Runtime and optional feature dependencies are declared in [`Cargo.toml`](Cargo.toml) and pinned in [`Cargo.lock`](Cargo.lock), including:
|
|
29
|
+
|
|
30
|
+
- Permissive `MIT` / `Apache-2.0` crates (`rusqlite`, `serde`, `serde_json`, `sha2`, `structured-zstd`, `zip`, `unicode-normalization`, `uuid`, `tempfile`, `tsify`, `wasm-bindgen`, etc.; `clap` only in the `tachibana-cli` crate).
|
|
31
|
+
- `BSD-3-Clause` / `BSD-2-Clause` (`zstd` / `zstd-safe` / `zstd-sys`, enabled by the `zstd-c` feature, which is on by default).
|
|
32
|
+
- `Zlib` (`foldhash`, `zlib-rs`) and `ISC` (`libloading` via Sudachi in `tachibana-sudachi` on non-WASM targets).
|
|
33
|
+
- `MPL-2.0` (`uniffi`, enabled only by the optional `uniffi` feature; file-level weak copyleft covering the UniFFI crate files).
|
|
34
|
+
|
|
35
|
+
When distributing compiled binaries, WebAssembly bundles, or applications that enable the corresponding features, retain the applicable third-party copyright and license notices (for example via `cargo-about` / `cargo-license` or your application's Open Source Licenses screen).
|
|
36
|
+
External Yomitan dictionaries and Sudachi UniDic dictionary files (`system.dic`) loaded at runtime are governed by their own licenses.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { AnalyzeTextInput, AnalyzeTextResponse, ArticleResponse, ArticlesResponse, ChangeEvent, DictionarySource, EntryRef, ExactLookupInput, ExactLookupResponse, FormOfInput, FormOfResponse, HostEngineOptions, InstalledDictionary, InstallOptions, JapaneseLookupAtInput, JapaneseLookupAtResponse, JapaneseLookupInput, JapaneseLookupResponse, LookupAtInput, LookupAtResponse, MetadataResponse, OpenOptions, ReaderCardsResponse, ReaderLookupResponse, ReaderTapInput, SudachiInstallOptions, SudachiProgress, SudachiSource, TagsResponse, TermMetaInput, TermMetaResponse, WasmStatus } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Browser client for the Tachibana offline Japanese dictionary engine.
|
|
4
|
+
*
|
|
5
|
+
* Runs SQLite + WebAssembly inside a Dedicated Web Worker (persisting dictionaries in OPFS via
|
|
6
|
+
* `opfs-sahpool` without requiring COOP/COEP headers) and coordinates multiple open tabs
|
|
7
|
+
* transparently through Web Locks + `BroadcastChannel`.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Tachibana {
|
|
10
|
+
private readonly coordinator;
|
|
11
|
+
private nextRequestId;
|
|
12
|
+
private constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Opens a Tachibana dictionary installation in the browser.
|
|
15
|
+
*
|
|
16
|
+
* Defaults to persistent OPFS storage (`directory: "tachibana"`) with automatic multi-tab
|
|
17
|
+
* coordination. Pass `{ storage: "memory" }` for ephemeral sessions (tests, incognito, HTTP).
|
|
18
|
+
*/
|
|
19
|
+
static open(options?: OpenOptions): Promise<Tachibana>;
|
|
20
|
+
/** Whether this tab currently owns the Dedicated Worker (`true` in memory mode or leader tab). */
|
|
21
|
+
get isLeader(): boolean;
|
|
22
|
+
/** Unique identifier of this tab instance (matches `ChangeEvent.sourceTabId`). */
|
|
23
|
+
get tabId(): string;
|
|
24
|
+
/** Subscribes to dictionary/configuration/Sudachi mutations across all open tabs. */
|
|
25
|
+
onChange(listener: (event: ChangeEvent) => void): () => void;
|
|
26
|
+
private allocRequestId;
|
|
27
|
+
/** Installs a Yomitan dictionary or frequency ZIP archive and returns its catalog summary. */
|
|
28
|
+
install(source: DictionarySource, options?: InstallOptions): Promise<InstalledDictionary>;
|
|
29
|
+
/**
|
|
30
|
+
* Aborts an in-flight import on the leader tab by terminating and restarting the Worker,
|
|
31
|
+
* then automatically reclaiming any partial snapshot files.
|
|
32
|
+
*/
|
|
33
|
+
cancelImport(): Promise<void>;
|
|
34
|
+
/** Lists all installed dictionaries in lookup priority order. */
|
|
35
|
+
list(): Promise<InstalledDictionary[]>;
|
|
36
|
+
/** Deletes dictionary `dictionaryId` and immediately reclaims its OPFS snapshot file. */
|
|
37
|
+
delete(dictionaryId: string): Promise<void>;
|
|
38
|
+
/** Sets or clears (`null`/`undefined`) the user-visible display title for `dictionaryId`. */
|
|
39
|
+
rename(dictionaryId: string, title?: string | null): Promise<void>;
|
|
40
|
+
/** Enables or disables `dictionaryId` for subsequent lookups. */
|
|
41
|
+
setEnabled(dictionaryId: string, enabled: boolean): Promise<void>;
|
|
42
|
+
/** Sets the dictionary lookup priority order; `ids` must include every installed ID once. */
|
|
43
|
+
setOrder(ids: string[]): Promise<void>;
|
|
44
|
+
/** Removes unreferenced snapshots and leftovers from interrupted imports. */
|
|
45
|
+
collectGarbage(): Promise<void>;
|
|
46
|
+
/** Updates engine configuration (for example, enabling installed frequency ranking). */
|
|
47
|
+
configure(options: HostEngineOptions): Promise<void>;
|
|
48
|
+
/** Verifies SQLite integrity of the catalog and all active snapshots; returns verified count. */
|
|
49
|
+
verifyIntegrity(): Promise<bigint>;
|
|
50
|
+
/** Returns current storage, dictionary count, frequency, pool capacity, and Sudachi state. */
|
|
51
|
+
status(): Promise<WasmStatus>;
|
|
52
|
+
/**
|
|
53
|
+
* Looks up a reader tap and returns ready-to-render cards with articles, tags, frequency,
|
|
54
|
+
* pitch accents, IPA, and optional Sudachi context analysis.
|
|
55
|
+
*
|
|
56
|
+
* `position` defaults to UTF-16 code units (matching JS `string` indices and DOM ranges).
|
|
57
|
+
*/
|
|
58
|
+
lookupReaderCards(input: ReaderTapInput): Promise<ReaderCardsResponse>;
|
|
59
|
+
/** Phase-1 reader tap lookup returning grouped headwords and highlight span without article bodies. */
|
|
60
|
+
lookupReader(input: ReaderTapInput): Promise<ReaderLookupResponse>;
|
|
61
|
+
/** Exact term or reading lookup. */
|
|
62
|
+
lookupExact(input: ExactLookupInput): Promise<ExactLookupResponse>;
|
|
63
|
+
/** Direct prefix scan at `input.position` without morphological deinflection. */
|
|
64
|
+
lookupAt(input: LookupAtInput): Promise<LookupAtResponse>;
|
|
65
|
+
/** Whole-query Japanese normalization and deinflection lookup. */
|
|
66
|
+
lookupJapanese(input: JapaneseLookupInput): Promise<JapaneseLookupResponse>;
|
|
67
|
+
/** Position-based Japanese normalization, deinflection, and optional context lookup. */
|
|
68
|
+
lookupJapaneseAt(input: JapaneseLookupAtInput): Promise<JapaneseLookupAtResponse>;
|
|
69
|
+
/** Tokenizes `input.text` with readings and spans using the loaded Sudachi analyzer. */
|
|
70
|
+
analyzeText(input: AnalyzeTextInput): Promise<AnalyzeTextResponse>;
|
|
71
|
+
/** Traverses outgoing `FormOf` links from `input.entry`. */
|
|
72
|
+
resolveFormOf(input: FormOfInput): Promise<FormOfResponse>;
|
|
73
|
+
/** Loads the article body for a single `EntryRef`. */
|
|
74
|
+
loadArticle(entry: EntryRef, requestId?: bigint): Promise<ArticleResponse>;
|
|
75
|
+
/** Loads multiple article bodies in one batch call. */
|
|
76
|
+
loadArticles(entries: EntryRef[], requestId?: bigint): Promise<ArticlesResponse>;
|
|
77
|
+
/** Loads raw bytes for a dictionary resource file (`styles.css`, images, etc.) or `null` if absent. */
|
|
78
|
+
loadResource(snapshotId: string, path: string, requestId?: bigint): Promise<Uint8Array | null>;
|
|
79
|
+
/** Reads `index.json` metadata of a pinned snapshot. */
|
|
80
|
+
metadata(snapshotId: string, requestId?: bigint): Promise<MetadataResponse>;
|
|
81
|
+
/** Fetches aggregated frequency, pitch, and IPA metadata for the requested `(term, reading)` keys. */
|
|
82
|
+
termMeta(input: TermMetaInput): Promise<TermMetaResponse>;
|
|
83
|
+
/** Reads the tag bank definitions of a pinned snapshot. */
|
|
84
|
+
tags(snapshotId: string, requestId?: bigint): Promise<TagsResponse>;
|
|
85
|
+
/**
|
|
86
|
+
* Downloads or reads a Sudachi `system.dic` (optionally `.gz`), caches it in OPFS (in OPFS mode),
|
|
87
|
+
* and streams it into WASM in 2 MiB chunks to minimize peak RAM usage.
|
|
88
|
+
*/
|
|
89
|
+
installSudachi(source: SudachiSource, options?: SudachiInstallOptions): Promise<WasmStatus>;
|
|
90
|
+
/** Loads a previously cached Sudachi `system.dic` directly from OPFS without network traffic. */
|
|
91
|
+
loadCachedSudachi(options?: {
|
|
92
|
+
onProgress?: (progress: SudachiProgress) => void;
|
|
93
|
+
}): Promise<WasmStatus>;
|
|
94
|
+
/** Unloads the Sudachi analyzer from WASM memory while keeping any OPFS cached file intact. */
|
|
95
|
+
unloadSudachi(): Promise<void>;
|
|
96
|
+
/** Unloads Sudachi from memory and deletes the cached `system.dic` from OPFS. */
|
|
97
|
+
deleteSudachi(): Promise<void>;
|
|
98
|
+
/** Returns `true` when a complete cached `system.dic` is stored in OPFS. */
|
|
99
|
+
hasCachedSudachi(): Promise<boolean>;
|
|
100
|
+
/** Closes the client, releasing OPFS locks/handles and allowing standby tabs to take over. */
|
|
101
|
+
close(): Promise<void>;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,QAAQ,EACR,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,cAAc,EACd,iBAAiB,EAGjB,mBAAmB,EACnB,cAAc,EACd,qBAAqB,EACrB,wBAAwB,EACxB,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EACd,qBAAqB,EACrB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB;;;;;;GAMG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,aAAa,CAAM;IAE3B,OAAO;IAIP;;;;;OAKG;WACU,IAAI,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,SAAS,CAAC;IAYhE,kGAAkG;IAClG,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,kFAAkF;IAClF,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,qFAAqF;IACrF,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,K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