@frdt/frdt 0.2.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 +119 -0
- package/THIRD-PARTY-NOTICES.md +4952 -0
- package/frdt.wasi.cjs +2144 -0
- package/frdt.wasm32-wasi.wasm +0 -0
- package/index.d.ts +129 -0
- package/index.js +785 -0
- package/package.json +39 -0
- package/wasi-worker.mjs +186 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 rheniumNV
|
|
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
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# @frdt/frdt
|
|
2
|
+
|
|
3
|
+
Resonite の `.brson`(中身は FrDT 形式)を、JSON へ展開せずに読み、編集し、書き戻す Node.js パッケージです。中身は Rust クレート [frdt](https://crates.io/crates/frdt) で、TypeScript の型が付いています。
|
|
4
|
+
|
|
5
|
+
npm では、短い名前 `frdt` が既存のパッケージと似すぎているとして使えなかったため、組織 `frdt` のスコープ付きの `@frdt/frdt` で出しています。環境ごとのネイティブ版(`@frdt/binding-<platform>`)は npm が自動で選んで入れるので、直接入れる必要はありません。
|
|
6
|
+
|
|
7
|
+
Read and edit Resonite `.brson` (FrDT) files from Node.js without expanding them into JSON.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @frdt/frdt
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## どの環境で動くか
|
|
14
|
+
|
|
15
|
+
インストールすると、次の環境ではネイティブ版が入り、それが使われます。
|
|
16
|
+
|
|
17
|
+
- Windows x64
|
|
18
|
+
- Linux x64(glibc と musl)
|
|
19
|
+
- macOS arm64(Apple Silicon)
|
|
20
|
+
|
|
21
|
+
それ以外の環境では、パッケージに同梱した WebAssembly 版が使われます。どちらでも API は同じで、呼び出し側で選ぶ必要はありません。ネイティブ版の方が速く動きます。どちらが読み込まれたかは `__napiBindingTarget`(`'native'` か `'wasm32-wasi'`)で分かります。
|
|
22
|
+
|
|
23
|
+
Node.js は 20.19 以降の 20.x、22.13 以降の 22.x、23.5 以降が必要です。WebAssembly 版が使う `@napi-rs/wasm-runtime` と同じ範囲で、CI では 20、22、24 で両方の版を試しています。WebAssembly 版はスレッドを使うので、Node.js の `worker_threads` が使える環境で動きます。ブラウザは対象にしていません。
|
|
24
|
+
|
|
25
|
+
## 使い方
|
|
26
|
+
|
|
27
|
+
### 読む
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { readFileSync } from 'node:fs'
|
|
31
|
+
import { Document, summarize } from '@frdt/frdt'
|
|
32
|
+
|
|
33
|
+
const bytes = readFileSync('item.brson')
|
|
34
|
+
|
|
35
|
+
// 展開せずに数える
|
|
36
|
+
const s = summarize(bytes)
|
|
37
|
+
console.log(`${s.slotCount} slots, ${s.componentCount} components`)
|
|
38
|
+
|
|
39
|
+
// 開いて辿る
|
|
40
|
+
const doc = Document.open(bytes)
|
|
41
|
+
const root = doc.root()
|
|
42
|
+
console.log(root.name(), doc.versionNumber())
|
|
43
|
+
for (const child of root.children()) {
|
|
44
|
+
for (const c of child.components()) console.log(child.name(), c.typeName)
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 編集して書き出す
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { writeFileSync } from 'node:fs'
|
|
52
|
+
import { Document, type Value } from '@frdt/frdt'
|
|
53
|
+
|
|
54
|
+
const str = (value: string): Value => ({ kind: 'string', value })
|
|
55
|
+
|
|
56
|
+
const doc = Document.open(bytes)
|
|
57
|
+
const panel = doc.addSlot(doc.root(), 'Panel')
|
|
58
|
+
const { index } = doc.addComponent(panel, '[FrooxEngine]FrooxEngine.DynamicValueVariable<string>', null, [
|
|
59
|
+
{ name: 'VariableName', value: str('App.Title') },
|
|
60
|
+
{ name: 'Value', value: str('Hello') },
|
|
61
|
+
])
|
|
62
|
+
panel.setComponentValue(index, 'Value', str('Hello, Resonite'))
|
|
63
|
+
panel.set('Name', str('TitlePanel'))
|
|
64
|
+
|
|
65
|
+
writeFileSync('out.brson', doc.writeBrson())
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 別のファイルの部分木を、新しい木にまとめる
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
const part = Document.open(partBytes)
|
|
72
|
+
const source = part.slotById(slotId)
|
|
73
|
+
|
|
74
|
+
const out = Document.empty('Combined', part.versionNumber(), part.featureFlags())
|
|
75
|
+
const imported = out.import(out.root(), [source])
|
|
76
|
+
// 写した先の id は imported.newId(元の id) で引ける
|
|
77
|
+
out.rebuildTypes()
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## 値の形
|
|
81
|
+
|
|
82
|
+
フィールドの値は `{ kind, value }` で渡し、受け取ります。
|
|
83
|
+
|
|
84
|
+
| `kind` | `value` | Resonite での形 |
|
|
85
|
+
| --- | --- | --- |
|
|
86
|
+
| `'string'` | `string` | 文字列。参照は相手の id をこれで渡す |
|
|
87
|
+
| `'int'` | `number` | int64。2^53 までは正確 |
|
|
88
|
+
| `'float'` | `number` | double |
|
|
89
|
+
| `'bool'` | `boolean` | 真偽値 |
|
|
90
|
+
| `'float3'` | `number[]`(3つ) | double の配列 |
|
|
91
|
+
| `'floatQ'` | `number[]`(4つ) | double の配列 |
|
|
92
|
+
|
|
93
|
+
null は `null` です。
|
|
94
|
+
|
|
95
|
+
## 考え方
|
|
96
|
+
|
|
97
|
+
- **JSON を通さない。** 編集の実体は、展開した BSON 1枚と、スロットの位置を指す索引です。変えていない値はバイト列のままコピーします。
|
|
98
|
+
- **知らないものを落とさない。** コンポーネントごとのスキーマは持たず、触ったフィールドだけを読み書きします。
|
|
99
|
+
- **Resonite の形で書く。** 新しく書く値は、Resonite が保存するのと同じ形にします。
|
|
100
|
+
|
|
101
|
+
`Slot` は、編集のあとも同じスロットを指したままです。外したスロットの `Slot` は、エラーを返します。失敗はすべて `Error` を投げます。
|
|
102
|
+
|
|
103
|
+
## 対応している範囲
|
|
104
|
+
|
|
105
|
+
- 圧縮は Brotli(FrDT の圧縮種別 `0x03`)です。LZ4 と LZMA は読みません。
|
|
106
|
+
- BSON の日時型(`0x09`)は、まだ扱えません。
|
|
107
|
+
- 参照かどうかは、文字列が文書内の id と一致するかで決めます。
|
|
108
|
+
|
|
109
|
+
## 使われているところ
|
|
110
|
+
|
|
111
|
+
もともとは、Resonite 向けの UI フレームワーク MirageX と、アイテム共有サービス [UniPocket](https://github.com/uni-pocket/uni-pocket) のために作りました。
|
|
112
|
+
|
|
113
|
+
## 生成AI
|
|
114
|
+
|
|
115
|
+
このパッケージのコードと文書は、生成AIの支援を受けて作成しています。
|
|
116
|
+
|
|
117
|
+
## ライセンス
|
|
118
|
+
|
|
119
|
+
MIT License。バイナリに含まれるライブラリのライセンスは `THIRD-PARTY-NOTICES.md` にあります。
|