taffy-layout 2.0.0 → 2.0.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.md CHANGED
@@ -1,6 +1,6 @@
1
- # ![Taffy Layout Logo](./taffy.svg) Taffy Layout
1
+ # ![Taffy Layout Logo](docs/taffy.svg) Taffy Layout
2
2
 
3
- [English](README.md) | [简体中文](README.zh-CN.md) | [日本語](README.ja-JP.md)
3
+ [English](README.md) | [简体中文](docs/i18n/zh-CN/README.md) | [日本語](docs/i18n/ja-JP/README.md)
4
4
 
5
5
  [![npm version](https://badge.fury.io/js/taffy-layout.svg)](https://www.npmjs.com/package/taffy-layout)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
@@ -90,6 +90,15 @@ console.log(
90
90
  );
91
91
  ```
92
92
 
93
+ ## 📚 Documentation
94
+
95
+ - [Introduction](docs/intro.md)
96
+ - [Getting Started](docs/getting-started/installation.md)
97
+ - [Core Concepts](docs/core-concepts/overview.md)
98
+ - [Styling Guide](docs/styling/index.md)
99
+ - [Advanced Usage](docs/advanced/index.md)
100
+ - [Cookbook](docs/cookbook/index.md)
101
+
93
102
  ## 📖 API Reference
94
103
 
95
104
  ### TaffyTree
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taffy-layout",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "WebAssembly bindings for Taffy layout library",
5
5
  "keywords": [
6
6
  "layout",
@@ -59,10 +59,14 @@
59
59
  "@semantic-release/npm": "^13.1.3",
60
60
  "@semantic-release/release-notes-generator": "^14.1.0",
61
61
  "@types/node": "^22.0.0",
62
+ "@types/react": "^19.2.9",
63
+ "@types/react-dom": "^19.2.3",
62
64
  "conventional-changelog-conventionalcommits": "^9.1.0",
63
65
  "husky": "^9.1.7",
64
66
  "lint-staged": "^16.2.7",
65
67
  "prettier": "^3.7.4",
68
+ "react": "^19.2.3",
69
+ "react-dom": "^19.2.3",
66
70
  "semantic-release": "^25.0.2",
67
71
  "tsx": "^4.0.0",
68
72
  "typedoc": "^0.28.15",
package/pkg/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # ![Taffy Layout Logo](./taffy.svg) Taffy Layout
1
+ # ![Taffy Layout Logo](docs/taffy.svg) Taffy Layout
2
2
 
3
- [English](README.md) | [简体中文](README.zh-CN.md) | [日本語](README.ja-JP.md)
3
+ [English](README.md) | [简体中文](docs/i18n/zh-CN/README.md) | [日本語](docs/i18n/ja-JP/README.md)
4
4
 
5
5
  [![npm version](https://badge.fury.io/js/taffy-layout.svg)](https://www.npmjs.com/package/taffy-layout)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
@@ -90,6 +90,15 @@ console.log(
90
90
  );
91
91
  ```
92
92
 
93
+ ## 📚 Documentation
94
+
95
+ - [Introduction](docs/intro.md)
96
+ - [Getting Started](docs/getting-started/installation.md)
97
+ - [Core Concepts](docs/core-concepts/overview.md)
98
+ - [Styling Guide](docs/styling/index.md)
99
+ - [Advanced Usage](docs/advanced/index.md)
100
+ - [Cookbook](docs/cookbook/index.md)
101
+
93
102
  ## 📖 API Reference
94
103
 
95
104
  ### TaffyTree
Binary file
package/README.ja-JP.md DELETED
@@ -1,276 +0,0 @@
1
- # ![Taffy Layout Logo](./taffy.svg) Taffy Layout
2
-
3
- [English](README.md) | [简体中文](README.zh-CN.md) | [日本語](README.ja-JP.md)
4
-
5
- [![npm version](https://badge.fury.io/js/taffy-layout.svg)](https://www.npmjs.com/package/taffy-layout)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
-
8
- WebAssembly で高速に動作する [Taffy](https://github.com/DioxusLabs/taffy) レイアウトエンジンの JavaScript バインディング。CSS の Flexbox と Grid をほぼネイティブ性能で利用できます。
9
-
10
- ## ✨ 特徴
11
-
12
- - **🚀 高性能**:WebAssembly によるレイアウト計算
13
- - **📦 充実の CSS 対応**:Flexbox と CSS Grid を実装
14
- - **🔧 カスタム計測**:テキスト/コンテンツ計測用コールバックに対応
15
- - **📝 TypeScript 対応**:型定義を同梱
16
- - **🌳 ツリー型 API**:複雑な階層構造にも効率的
17
- - **💡 なじみやすい API**:CSS 風のプロパティ名と値
18
-
19
- ## 📦 インストール
20
-
21
- ```bash
22
- npm install taffy-layout
23
- ```
24
-
25
- ## 🚀 クイックスタート
26
-
27
- ```typescript
28
- import {
29
- loadTaffy,
30
- TaffyTree,
31
- Style,
32
- Display,
33
- FlexDirection,
34
- AlignItems,
35
- } from "taffy-layout";
36
-
37
- // WebAssembly モジュールを初期化
38
- await loadTaffy();
39
-
40
- // レイアウトツリーを作成
41
- const tree = new TaffyTree();
42
-
43
- // コンテナのスタイル
44
- const containerStyle = new Style();
45
- containerStyle.display = Display.Flex;
46
- containerStyle.flexDirection = FlexDirection.Column;
47
- containerStyle.alignItems = AlignItems.Center;
48
-
49
- // size オブジェクトで設定
50
- containerStyle.size = { width: 300, height: 200 };
51
-
52
- // または個別の width/height プロパティを使用
53
- containerStyle.width = 300;
54
- containerStyle.height = 200;
55
-
56
- // padding オブジェクトで設定
57
- containerStyle.padding = { left: 10, right: 10, top: 10, bottom: 10 };
58
-
59
- // または個別の padding プロパティを使用
60
- containerStyle.paddingLeft = 10;
61
- containerStyle.paddingRight = 10;
62
- containerStyle.paddingTop = 10;
63
- containerStyle.paddingBottom = 10;
64
-
65
- // 子要素のスタイル
66
- const childStyle = new Style();
67
- childStyle.flexGrow = 1;
68
- childStyle.width = "100%";
69
- childStyle.height = "auto";
70
-
71
- // ノードを生成
72
- const child1 = tree.newLeaf(childStyle);
73
- const child2 = tree.newLeaf(childStyle);
74
- const container = tree.newWithChildren(containerStyle, [child1, child2]);
75
-
76
- // レイアウト計算
77
- tree.computeLayout(container, { width: 300, height: 200 });
78
-
79
- // 計算結果を取得
80
- const containerLayout = tree.getLayout(container);
81
- const child1Layout = tree.getLayout(child1);
82
- const child2Layout = tree.getLayout(child2);
83
-
84
- console.log(`Container: ${containerLayout.width}x${containerLayout.height}`);
85
- console.log(
86
- `Child 1: ${child1Layout.width}x${child1Layout.height} at (${child1Layout.x}, ${child1Layout.y})`,
87
- );
88
- console.log(
89
- `Child 2: ${child2Layout.width}x${child2Layout.height} at (${child2Layout.x}, ${child2Layout.y})`,
90
- );
91
- ```
92
-
93
- ## 📖 API リファレンス
94
-
95
- ### TaffyTree
96
-
97
- レイアウトツリーを管理するメインクラス。
98
-
99
- [ドキュメントを見る](./docs/api/classes/TaffyTree.md)
100
-
101
- ### Style
102
-
103
- ノードのレイアウトプロパティを設定するオブジェクト。
104
-
105
- [ドキュメントを見る](./docs/api/classes/Style.md)
106
-
107
- ### Layout
108
-
109
- 計算後のレイアウト結果 (読み取り専用)。
110
-
111
- [ドキュメントを見る](./docs/api/classes/Layout.md)
112
-
113
- ### 列挙型
114
-
115
- [ドキュメントを見る](./docs/api/index.md#enumerations)
116
-
117
- ### 型エイリアス
118
-
119
- [ドキュメントを見る](./docs/api/index.md#type-aliases)
120
-
121
- ## 📐 カスタムテキスト計測
122
-
123
- テキストなど動的な計測が必要な場合は、測定コールバックを渡せます。
124
-
125
- ```typescript
126
- const tree = new TaffyTree();
127
- const textStyle = new Style();
128
- const rootNode = tree.newLeaf(new Style());
129
- const measureTextWidth = (text: string) => text.length * 8;
130
- const measureTextHeight = (text: string, width: number) => 20;
131
-
132
- const textNode = tree.newLeafWithContext(textStyle, { text: "Hello, World!" });
133
-
134
- tree.computeLayoutWithMeasure(
135
- rootNode,
136
- { width: 800, height: "max-content" },
137
- (known, available, node, context, style) => {
138
- if (context?.text) {
139
- // ここに独自のテキスト計測ロジックを実装
140
- const width = measureTextWidth(context.text);
141
- const height = measureTextHeight(context.text, available.width as number);
142
- return { width, height };
143
- }
144
- return { width: 0, height: 0 };
145
- },
146
- );
147
- ```
148
-
149
- ## 🔧 エラーハンドリング
150
-
151
- 失敗する可能性のあるメソッドは `TaffyError` をスローします。try-catch で処理してください。
152
-
153
- ```typescript
154
- try {
155
- const tree = new TaffyTree();
156
- const style = new Style();
157
- const nodeId = tree.newLeaf(style);
158
- console.log("Created node:", nodeId);
159
- } catch (e) {
160
- if (e instanceof TaffyError) {
161
- console.error("Error:", e.message);
162
- }
163
- }
164
- ```
165
-
166
- ## 🌐 ブラウザ対応
167
-
168
- WebAssembly をサポートするモダンブラウザで動作します。
169
-
170
- - Chrome 57+
171
- - Firefox 52+
172
- - Safari 11+
173
- - Edge 16+
174
-
175
- ## 📚 サンプル
176
-
177
- ### Flexbox 行レイアウト
178
-
179
- ```typescript
180
- const rowStyle = new Style();
181
- rowStyle.display = Display.Flex;
182
- rowStyle.flexDirection = FlexDirection.Row;
183
- rowStyle.justifyContent = JustifyContent.SpaceBetween;
184
- rowStyle.gap = { width: 10, height: 0 };
185
- ```
186
-
187
- ### CSS Grid レイアウト
188
-
189
- ```typescript
190
- import { Style, Display, GridAutoFlow } from "taffy-layout";
191
-
192
- const gridStyle = new Style();
193
- gridStyle.display = Display.Grid;
194
- gridStyle.gridAutoFlow = GridAutoFlow.Row;
195
- gridStyle.gap = { width: 10, height: 10 };
196
-
197
- // グリッドアイテムの配置
198
- const itemStyle = new Style();
199
- itemStyle.gridRow = { start: 1, end: 3 }; // 2 行分
200
- itemStyle.gridColumn = { start: 1, end: { span: 2 } }; // 2 列分
201
- ```
202
-
203
- ### グリッドテンプレート領域
204
-
205
- ```typescript
206
- const gridStyle = new Style();
207
- gridStyle.display = Display.Grid;
208
- gridStyle.gridTemplateAreas = [
209
- { name: "header", rowStart: 1, rowEnd: 2, columnStart: 1, columnEnd: 4 },
210
- { name: "sidebar", rowStart: 2, rowEnd: 4, columnStart: 1, columnEnd: 2 },
211
- { name: "main", rowStart: 2, rowEnd: 4, columnStart: 2, columnEnd: 4 },
212
- { name: "footer", rowStart: 4, rowEnd: 5, columnStart: 1, columnEnd: 4 },
213
- ];
214
-
215
- // 名前付きグリッドライン
216
- gridStyle.gridTemplateRowNames = [
217
- ["header-start"],
218
- ["header-end", "content-start"],
219
- ["content-end", "footer-start"],
220
- ["footer-end"],
221
- ];
222
- ```
223
-
224
- ### 絶対配置
225
-
226
- ```typescript
227
- const absoluteStyle = new Style();
228
- absoluteStyle.position = Position.Absolute;
229
- absoluteStyle.inset = { left: 10, top: 10, right: "auto", bottom: "auto" };
230
- absoluteStyle.size = { width: 100, height: 50 };
231
- ```
232
-
233
- ### パーセントサイズ
234
-
235
- ```typescript
236
- const percentStyle = new Style();
237
- percentStyle.size = {
238
- width: "50%", // 親幅の 50%
239
- height: "100%", // 親高の 100%
240
- };
241
- ```
242
-
243
- ### 置換要素のブロックレイアウト
244
-
245
- ```typescript
246
- const imgStyle = new Style();
247
- imgStyle.itemIsReplaced = true;
248
- imgStyle.aspectRatio = 16 / 9; // 16:9
249
- imgStyle.size = { width: "100%", height: "auto" };
250
- ```
251
-
252
- ## 🏗️ ソースからのビルド
253
-
254
- ```bash
255
- # リポジトリを取得
256
- git clone https://github.com/ByteLandTechnology/taffy-layout.git
257
- cd taffy-layout
258
-
259
- # 依存関係をインストール
260
- npm install
261
-
262
- # WebAssembly モジュールをビルド
263
- npm run build
264
-
265
- # テストを実行
266
- npm test
267
- ```
268
-
269
- ## 📄 ライセンス
270
-
271
- MIT License - 詳細は [LICENSE](LICENSE) を参照してください。
272
-
273
- ## 🙏 謝辞
274
-
275
- - [Taffy](https://github.com/DioxusLabs/taffy) - 本プロジェクトがラップしている Rust 製レイアウトエンジン
276
- - [wasm-bindgen](https://github.com/rustwasm/wasm-bindgen) - Rust/WebAssembly の相互運用を支えるツール
package/README.zh-CN.md DELETED
@@ -1,276 +0,0 @@
1
- # ![Taffy Layout Logo](./taffy.svg) Taffy Layout
2
-
3
- [English](README.md) | [简体中文](README.zh-CN.md) | [日本語](README.ja-JP.md)
4
-
5
- [![npm version](https://badge.fury.io/js/taffy-layout.svg)](https://www.npmjs.com/package/taffy-layout)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
-
8
- 基于 WebAssembly 的高性能 [Taffy](https://github.com/DioxusLabs/taffy) 布局引擎 JavaScript 绑定,将 CSS Flexbox 和 Grid 布局算法带到前端,接近原生性能。
9
-
10
- ## ✨ 特性
11
-
12
- - **🚀 高性能**:WebAssembly 驱动的布局计算
13
- - **📦 完整 CSS 支持**:实现 Flexbox 与 CSS Grid
14
- - **🔧 自定义测量**:支持自定义文本/内容测量回调
15
- - **📝 TypeScript 友好**:完整类型定义
16
- - **🌳 基于树的 API**:适合复杂场景的高效树结构
17
- - **💡 熟悉的 API**:类 CSS 的属性名称与取值
18
-
19
- ## 📦 安装
20
-
21
- ```bash
22
- npm install taffy-layout
23
- ```
24
-
25
- ## 🚀 快速上手
26
-
27
- ```typescript
28
- import {
29
- loadTaffy,
30
- TaffyTree,
31
- Style,
32
- Display,
33
- FlexDirection,
34
- AlignItems,
35
- } from "taffy-layout";
36
-
37
- // 初始化 WebAssembly 模块
38
- await loadTaffy();
39
-
40
- // 创建布局树
41
- const tree = new TaffyTree();
42
-
43
- // 容器样式
44
- const containerStyle = new Style();
45
- containerStyle.display = Display.Flex;
46
- containerStyle.flexDirection = FlexDirection.Column;
47
- containerStyle.alignItems = AlignItems.Center;
48
-
49
- // 可以设置 size 对象
50
- containerStyle.size = { width: 300, height: 200 };
51
-
52
- // 或使用独立的 width/height 属性
53
- containerStyle.width = 300;
54
- containerStyle.height = 200;
55
-
56
- // 设置 padding 对象
57
- containerStyle.padding = { left: 10, right: 10, top: 10, bottom: 10 };
58
-
59
- // 或使用独立的 padding 属性
60
- containerStyle.paddingLeft = 10;
61
- containerStyle.paddingRight = 10;
62
- containerStyle.paddingTop = 10;
63
- containerStyle.paddingBottom = 10;
64
-
65
- // 子元素样式
66
- const childStyle = new Style();
67
- childStyle.flexGrow = 1;
68
- childStyle.width = "100%";
69
- childStyle.height = "auto";
70
-
71
- // 创建节点
72
- const child1 = tree.newLeaf(childStyle);
73
- const child2 = tree.newLeaf(childStyle);
74
- const container = tree.newWithChildren(containerStyle, [child1, child2]);
75
-
76
- // 计算布局
77
- tree.computeLayout(container, { width: 300, height: 200 });
78
-
79
- // 读取结果
80
- const containerLayout = tree.getLayout(container);
81
- const child1Layout = tree.getLayout(child1);
82
- const child2Layout = tree.getLayout(child2);
83
-
84
- console.log(`Container: ${containerLayout.width}x${containerLayout.height}`);
85
- console.log(
86
- `Child 1: ${child1Layout.width}x${child1Layout.height} at (${child1Layout.x}, ${child1Layout.y})`,
87
- );
88
- console.log(
89
- `Child 2: ${child2Layout.width}x${child2Layout.height} at (${child2Layout.x}, ${child2Layout.y})`,
90
- );
91
- ```
92
-
93
- ## 📖 API 参考
94
-
95
- ### TaffyTree
96
-
97
- 管理布局树的核心类。
98
-
99
- [查看文档](./docs/api/classes/TaffyTree.md)
100
-
101
- ### Style
102
-
103
- 用于配置节点布局属性的对象。
104
-
105
- [查看文档](./docs/api/classes/Style.md)
106
-
107
- ### Layout
108
-
109
- 只读的布局计算结果。
110
-
111
- [查看文档](./docs/api/classes/Layout.md)
112
-
113
- ### 枚举
114
-
115
- [查看文档](./docs/api/index.md#enumerations)
116
-
117
- ### 类型别名
118
-
119
- [查看文档](./docs/api/index.md#type-aliases)
120
-
121
- ## 📐 自定义文本测量
122
-
123
- 对文本节点或需要动态测量的内容,可传入测量回调:
124
-
125
- ```typescript
126
- const tree = new TaffyTree();
127
- const textStyle = new Style();
128
- const rootNode = tree.newLeaf(new Style());
129
- const measureTextWidth = (text: string) => text.length * 8;
130
- const measureTextHeight = (text: string, width: number) => 20;
131
-
132
- const textNode = tree.newLeafWithContext(textStyle, { text: "Hello, World!" });
133
-
134
- tree.computeLayoutWithMeasure(
135
- rootNode,
136
- { width: 800, height: "max-content" },
137
- (known, available, node, context, style) => {
138
- if (context?.text) {
139
- // 在这里实现文本测量逻辑
140
- const width = measureTextWidth(context.text);
141
- const height = measureTextHeight(context.text, available.width as number);
142
- return { width, height };
143
- }
144
- return { width: 0, height: 0 };
145
- },
146
- );
147
- ```
148
-
149
- ## 🔧 错误处理
150
-
151
- 可能失败的方法会抛出 `TaffyError`。使用 try-catch 处理:
152
-
153
- ```typescript
154
- try {
155
- const tree = new TaffyTree();
156
- const style = new Style();
157
- const nodeId = tree.newLeaf(style);
158
- console.log("Created node:", nodeId);
159
- } catch (e) {
160
- if (e instanceof TaffyError) {
161
- console.error("Error:", e.message);
162
- }
163
- }
164
- ```
165
-
166
- ## 🌐 浏览器支持
167
-
168
- 支持所有具备 WebAssembly 的现代浏览器:
169
-
170
- - Chrome 57+
171
- - Firefox 52+
172
- - Safari 11+
173
- - Edge 16+
174
-
175
- ## 📚 示例
176
-
177
- ### Flexbox 行布局
178
-
179
- ```typescript
180
- const rowStyle = new Style();
181
- rowStyle.display = Display.Flex;
182
- rowStyle.flexDirection = FlexDirection.Row;
183
- rowStyle.justifyContent = JustifyContent.SpaceBetween;
184
- rowStyle.gap = { width: 10, height: 0 };
185
- ```
186
-
187
- ### CSS Grid 布局
188
-
189
- ```typescript
190
- import { Style, Display, GridAutoFlow } from "taffy-layout";
191
-
192
- const gridStyle = new Style();
193
- gridStyle.display = Display.Grid;
194
- gridStyle.gridAutoFlow = GridAutoFlow.Row;
195
- gridStyle.gap = { width: 10, height: 10 };
196
-
197
- // 网格项定位
198
- const itemStyle = new Style();
199
- itemStyle.gridRow = { start: 1, end: 3 }; // 跨 2 行
200
- itemStyle.gridColumn = { start: 1, end: { span: 2 } }; // 跨 2 列
201
- ```
202
-
203
- ### 网格区域模板
204
-
205
- ```typescript
206
- const gridStyle = new Style();
207
- gridStyle.display = Display.Grid;
208
- gridStyle.gridTemplateAreas = [
209
- { name: "header", rowStart: 1, rowEnd: 2, columnStart: 1, columnEnd: 4 },
210
- { name: "sidebar", rowStart: 2, rowEnd: 4, columnStart: 1, columnEnd: 2 },
211
- { name: "main", rowStart: 2, rowEnd: 4, columnStart: 2, columnEnd: 4 },
212
- { name: "footer", rowStart: 4, rowEnd: 5, columnStart: 1, columnEnd: 4 },
213
- ];
214
-
215
- // 命名网格线
216
- gridStyle.gridTemplateRowNames = [
217
- ["header-start"],
218
- ["header-end", "content-start"],
219
- ["content-end", "footer-start"],
220
- ["footer-end"],
221
- ];
222
- ```
223
-
224
- ### 绝对定位
225
-
226
- ```typescript
227
- const absoluteStyle = new Style();
228
- absoluteStyle.position = Position.Absolute;
229
- absoluteStyle.inset = { left: 10, top: 10, right: "auto", bottom: "auto" };
230
- absoluteStyle.size = { width: 100, height: 50 };
231
- ```
232
-
233
- ### 百分比尺寸
234
-
235
- ```typescript
236
- const percentStyle = new Style();
237
- percentStyle.size = {
238
- width: "50%", // 父级宽度的 50%
239
- height: "100%", // 父级高度的 100%
240
- };
241
- ```
242
-
243
- ### 替换元素的块级布局
244
-
245
- ```typescript
246
- const imgStyle = new Style();
247
- imgStyle.itemIsReplaced = true;
248
- imgStyle.aspectRatio = 16 / 9; // 16:9 宽高比
249
- imgStyle.size = { width: "100%", height: "auto" };
250
- ```
251
-
252
- ## 🏗️ 从源码构建
253
-
254
- ```bash
255
- # 克隆仓库
256
- git clone https://github.com/ByteLandTechnology/taffy-layout.git
257
- cd taffy-layout
258
-
259
- # 安装依赖
260
- npm install
261
-
262
- # 构建 WebAssembly 模块
263
- npm run build
264
-
265
- # 运行测试
266
- npm test
267
- ```
268
-
269
- ## 📄 许可证
270
-
271
- MIT License - 详见 [LICENSE](LICENSE)。
272
-
273
- ## 🙏 致谢
274
-
275
- - [Taffy](https://github.com/DioxusLabs/taffy) - 本项目封装的 Rust 布局引擎
276
- - [wasm-bindgen](https://github.com/rustwasm/wasm-bindgen) - Rust/WebAssembly 互操作工具