tinky 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.
Files changed (99) hide show
  1. package/LICENSE +47 -0
  2. package/README.ja-JP.md +350 -0
  3. package/README.md +350 -0
  4. package/README.zh-CN.md +350 -0
  5. package/lib/colorize.d.ts +16 -0
  6. package/lib/colorize.js +55 -0
  7. package/lib/components/AccessibilityContext.d.ts +9 -0
  8. package/lib/components/AccessibilityContext.js +10 -0
  9. package/lib/components/App.d.ts +169 -0
  10. package/lib/components/App.js +314 -0
  11. package/lib/components/AppContext.d.ts +14 -0
  12. package/lib/components/AppContext.js +11 -0
  13. package/lib/components/BackgroundContext.d.ts +10 -0
  14. package/lib/components/BackgroundContext.js +5 -0
  15. package/lib/components/Box.d.ts +153 -0
  16. package/lib/components/Box.js +57 -0
  17. package/lib/components/ErrorOverview.d.ts +9 -0
  18. package/lib/components/ErrorOverview.js +49 -0
  19. package/lib/components/FocusContext.d.ts +51 -0
  20. package/lib/components/FocusContext.js +35 -0
  21. package/lib/components/Newline.d.ts +29 -0
  22. package/lib/components/Newline.js +21 -0
  23. package/lib/components/Spacer.d.ts +19 -0
  24. package/lib/components/Spacer.js +23 -0
  25. package/lib/components/Static.d.ts +48 -0
  26. package/lib/components/Static.js +46 -0
  27. package/lib/components/StderrContext.d.ts +21 -0
  28. package/lib/components/StderrContext.js +12 -0
  29. package/lib/components/StdinContext.d.ts +36 -0
  30. package/lib/components/StdinContext.js +16 -0
  31. package/lib/components/StdoutContext.d.ts +22 -0
  32. package/lib/components/StdoutContext.js +13 -0
  33. package/lib/components/Text.d.ts +84 -0
  34. package/lib/components/Text.js +74 -0
  35. package/lib/components/Transform.d.ts +41 -0
  36. package/lib/components/Transform.js +32 -0
  37. package/lib/devtools-window-polyfill.d.ts +1 -0
  38. package/lib/devtools-window-polyfill.js +70 -0
  39. package/lib/devtools.d.ts +1 -0
  40. package/lib/devtools.js +8 -0
  41. package/lib/dom.d.ts +130 -0
  42. package/lib/dom.js +209 -0
  43. package/lib/get-max-width.d.ts +9 -0
  44. package/lib/get-max-width.js +14 -0
  45. package/lib/hooks/use-app.d.ts +26 -0
  46. package/lib/hooks/use-app.js +28 -0
  47. package/lib/hooks/use-focus-manager.d.ts +40 -0
  48. package/lib/hooks/use-focus-manager.js +18 -0
  49. package/lib/hooks/use-focus.d.ts +67 -0
  50. package/lib/hooks/use-focus.js +65 -0
  51. package/lib/hooks/use-input.d.ts +118 -0
  52. package/lib/hooks/use-input.js +101 -0
  53. package/lib/hooks/use-is-screen-reader-enabled.d.ts +7 -0
  54. package/lib/hooks/use-is-screen-reader-enabled.js +12 -0
  55. package/lib/hooks/use-stderr.d.ts +6 -0
  56. package/lib/hooks/use-stderr.js +8 -0
  57. package/lib/hooks/use-stdin.d.ts +6 -0
  58. package/lib/hooks/use-stdin.js +8 -0
  59. package/lib/hooks/use-stdout.d.ts +7 -0
  60. package/lib/hooks/use-stdout.js +9 -0
  61. package/lib/index.d.ts +22 -0
  62. package/lib/index.js +20 -0
  63. package/lib/instances.d.ts +10 -0
  64. package/lib/instances.js +9 -0
  65. package/lib/log-update.d.ts +32 -0
  66. package/lib/log-update.js +147 -0
  67. package/lib/measure-element.d.ts +19 -0
  68. package/lib/measure-element.js +13 -0
  69. package/lib/measure-text.d.ts +13 -0
  70. package/lib/measure-text.js +26 -0
  71. package/lib/output.d.ts +73 -0
  72. package/lib/output.js +190 -0
  73. package/lib/parse-keypress.d.ts +20 -0
  74. package/lib/parse-keypress.js +228 -0
  75. package/lib/reconciler.d.ts +12 -0
  76. package/lib/reconciler.js +282 -0
  77. package/lib/render-background.d.ts +11 -0
  78. package/lib/render-background.js +32 -0
  79. package/lib/render-border.d.ts +13 -0
  80. package/lib/render-border.js +82 -0
  81. package/lib/render-node-to-output.d.ts +43 -0
  82. package/lib/render-node-to-output.js +179 -0
  83. package/lib/render.d.ts +129 -0
  84. package/lib/render.js +84 -0
  85. package/lib/renderer.d.ts +27 -0
  86. package/lib/renderer.js +62 -0
  87. package/lib/signal-exit.d.ts +11 -0
  88. package/lib/signal-exit.js +24 -0
  89. package/lib/squash-text-nodes.d.ts +10 -0
  90. package/lib/squash-text-nodes.js +36 -0
  91. package/lib/styles.d.ts +402 -0
  92. package/lib/styles.js +633 -0
  93. package/lib/taffy-node.d.ts +39 -0
  94. package/lib/taffy-node.js +60 -0
  95. package/lib/tinky.d.ts +153 -0
  96. package/lib/tinky.js +396 -0
  97. package/lib/wrap-text.d.ts +11 -0
  98. package/lib/wrap-text.js +38 -0
  99. package/package.json +87 -0
package/LICENSE ADDED
@@ -0,0 +1,47 @@
1
+ MIT License
2
+
3
+ Copyright (c) ByteLand Technology Limited
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.
22
+
23
+ ---
24
+
25
+ This project is based on Ink (https://github.com/vadimdemedes/ink),
26
+ which is licensed under the MIT License:
27
+
28
+ Copyright (c) Vadym Demedes <vadimdemedes@hey.com> (https://github.com/vadimdemedes)
29
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining a copy
32
+ of this software and associated documentation files (the "Software"), to deal
33
+ in the Software without restriction, including without limitation the rights
34
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
35
+ copies of the Software, and to permit persons to whom the Software is
36
+ furnished to do so, subject to the following conditions:
37
+
38
+ The above copyright notice and this permission notice shall be included in all
39
+ copies or substantial portions of the Software.
40
+
41
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
44
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
46
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
47
+ SOFTWARE.
@@ -0,0 +1,350 @@
1
+ <p align="center">
2
+ <h1 align="center">Tinky</h1>
3
+ <p align="center">
4
+ <strong>Taffy レイアウトエンジンで再構築された React CLI フレームワーク</strong>
5
+ </p>
6
+ <p align="center">
7
+ <a href="./README.md">English</a> · <a href="./README.zh-CN.md">中文</a>
8
+ </p>
9
+ </p>
10
+
11
+ ---
12
+
13
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
14
+ [![npm version](https://img.shields.io/npm/v/tinky.svg)](https://www.npmjs.com/package/tinky)
15
+
16
+ Tinky は、美しくインタラクティブなコマンドラインインターフェースを構築するための、モダンな React ベースのフレームワークです。強力な [Taffy](https://github.com/DioxusLabs/taffy) レイアウトエンジンを活用し、ターミナルで **CSS Flexbox と Grid** レイアウトをサポートします。
17
+
18
+ ## ✨ 特徴
19
+
20
+ - 🎨 **React コンポーネント** — 使い慣れた React パターンと JSX 構文で CLI を構築
21
+ - 📐 **Flexbox & Grid レイアウト** — Taffy による完全な CSS Flexbox と CSS Grid サポート
22
+ - ⌨️ **キーボード入力** — キーボード入力とフォーカス管理のための組み込みフック
23
+ - 🎯 **フォーカス管理** — Tab/Shift+Tab ナビゲーションとカスタマイズ可能なフォーカス動作
24
+ - 🖼️ **ボーダーと背景** — ボーダー、背景色などの豊富なスタイリング
25
+ - ♿ **アクセシビリティ** — ARIA 属性によるスクリーンリーダーサポート
26
+ - 🔄 **ホットリロード** — React DevTools サポートによる高速開発
27
+ - 📦 **TypeScript ファースト** — 包括的な型定義による完全な TypeScript サポート
28
+
29
+ ## 📦 インストール
30
+
31
+ ```bash
32
+ # npm を使用
33
+ npm install tinky react
34
+
35
+ # yarn を使用
36
+ yarn add tinky react
37
+
38
+ # pnpm を使用
39
+ pnpm add tinky react
40
+
41
+ # bun を使用
42
+ bun add tinky react
43
+ ```
44
+
45
+ ## 🚀 クイックスタート
46
+
47
+ ```tsx
48
+ import { render, Box, Text } from "tinky";
49
+
50
+ function App() {
51
+ return (
52
+ <Box flexDirection="column" padding={1}>
53
+ <Text color="green" bold>
54
+ こんにちは、Tinky!🎉
55
+ </Text>
56
+ <Text>React で美しい CLI を構築しよう</Text>
57
+ </Box>
58
+ );
59
+ }
60
+
61
+ render(<App />);
62
+ ```
63
+
64
+ ## 📚 コンポーネント
65
+
66
+ ### Box
67
+
68
+ `<Box>` コンポーネントは基本的な構成要素です。ブラウザの `<div>` のようなもので、Flexbox と Grid レイアウトをサポートします。
69
+
70
+ ```tsx
71
+ import { Box, Text } from "tinky";
72
+
73
+ // Flexbox レイアウト
74
+ <Box flexDirection="row" gap={2}>
75
+ <Text>左</Text>
76
+ <Text>右</Text>
77
+ </Box>
78
+
79
+ // Grid レイアウト
80
+ <Box display="grid" gridTemplateColumns="1fr 2fr 1fr" gap={1}>
81
+ <Text>列 1</Text>
82
+ <Text>列 2</Text>
83
+ <Text>列 3</Text>
84
+ </Box>
85
+
86
+ // ボーダーとパディング付き
87
+ <Box borderStyle="round" borderColor="cyan" padding={1}>
88
+ <Text>スタイル付き Box</Text>
89
+ </Box>
90
+ ```
91
+
92
+ ### Text
93
+
94
+ `<Text>` コンポーネントは、色、太字、斜体などのスタイル付きテキストをレンダリングします。
95
+
96
+ ```tsx
97
+ import { Text } from "tinky";
98
+
99
+ <Text color="blue">青いテキスト</Text>
100
+ <Text backgroundColor="red" color="white">ハイライト</Text>
101
+ <Text bold italic underline>スタイル付きテキスト</Text>
102
+ <Text color="#ff6600">16進数カラーも使えます!</Text>
103
+ ```
104
+
105
+ ### Static
106
+
107
+ `<Static>` コンポーネントは、更新されない静的コンテンツをレンダリングします。ログや履歴に最適です。
108
+
109
+ ```tsx
110
+ import { Static, Text } from "tinky";
111
+
112
+ const logs = ["ログ 1", "ログ 2", "ログ 3"];
113
+
114
+ <Static items={logs}>{(log, index) => <Text key={index}>{log}</Text>}</Static>;
115
+ ```
116
+
117
+ ### Transform
118
+
119
+ `<Transform>` コンポーネントを使用すると、子要素の出力を変換できます。
120
+
121
+ ```tsx
122
+ import { Transform, Text } from "tinky";
123
+
124
+ <Transform transform={(output) => output.toUpperCase()}>
125
+ <Text>hello</Text>
126
+ </Transform>;
127
+ // レンダリング結果: HELLO
128
+ ```
129
+
130
+ ### Newline と Spacer
131
+
132
+ ```tsx
133
+ import { Box, Text, Newline, Spacer } from "tinky";
134
+
135
+ // Newline - 垂直方向のスペースを追加
136
+ <Box flexDirection="column">
137
+ <Text>1行目</Text>
138
+ <Newline count={2} />
139
+ <Text>2行目</Text>
140
+ </Box>
141
+
142
+ // Spacer - flex コンテナ内の柔軟なスペース
143
+ <Box>
144
+ <Text>左</Text>
145
+ <Spacer />
146
+ <Text>右</Text>
147
+ </Box>
148
+ ```
149
+
150
+ ## 🪝 フック
151
+
152
+ ### useInput
153
+
154
+ コンポーネント内でキーボード入力を処理します。
155
+
156
+ ```tsx
157
+ import { useInput, useApp } from "tinky";
158
+
159
+ function MyComponent() {
160
+ const { exit } = useApp();
161
+
162
+ useInput((input, key) => {
163
+ if (key.escape) {
164
+ exit();
165
+ }
166
+ if (key.upArrow) {
167
+ // 上矢印キーを処理
168
+ }
169
+ if (input === "q") {
170
+ exit();
171
+ }
172
+ });
173
+
174
+ return <Text>'q' を押して終了</Text>;
175
+ }
176
+ ```
177
+
178
+ ### useApp
179
+
180
+ アプリインスタンスにアクセスして終了動作を制御します。
181
+
182
+ ```tsx
183
+ import { useApp } from "tinky";
184
+
185
+ function MyComponent() {
186
+ const { exit } = useApp();
187
+
188
+ // エラーで終了
189
+ exit(new Error("エラーが発生しました"));
190
+
191
+ // 正常終了
192
+ exit();
193
+ }
194
+ ```
195
+
196
+ ### useFocus と useFocusManager
197
+
198
+ インタラクティブコンポーネントのフォーカスを管理します。
199
+
200
+ ```tsx
201
+ import { useFocus, Box, Text } from "tinky";
202
+
203
+ function FocusableItem({ label }: { label: string }) {
204
+ const { isFocused } = useFocus();
205
+
206
+ return (
207
+ <Box borderStyle={isFocused ? "bold" : "single"}>
208
+ <Text color={isFocused ? "green" : "white"}>{label}</Text>
209
+ </Box>
210
+ );
211
+ }
212
+ ```
213
+
214
+ ### useStdin、useStdout、useStderr
215
+
216
+ stdin、stdout、stderr ストリームに直接アクセスします。
217
+
218
+ ```tsx
219
+ import { useStdout, useEffect } from "tinky";
220
+
221
+ function MyComponent() {
222
+ const { write } = useStdout();
223
+
224
+ useEffect(() => {
225
+ write("stdout からこんにちは!\n");
226
+ }, []);
227
+
228
+ return null;
229
+ }
230
+ ```
231
+
232
+ ## 🎨 スタイリング
233
+
234
+ ### Flexbox プロパティ
235
+
236
+ ```tsx
237
+ <Box
238
+ flexDirection="row" // row, row-reverse, column, column-reverse
239
+ justifyContent="center" // flex-start, flex-end, center, space-between, space-around
240
+ alignItems="center" // flex-start, flex-end, center, stretch
241
+ flexWrap="wrap" // nowrap, wrap, wrap-reverse
242
+ flexGrow={1}
243
+ flexShrink={0}
244
+ gap={2}
245
+ />
246
+ ```
247
+
248
+ ### Grid プロパティ
249
+
250
+ ```tsx
251
+ <Box
252
+ display="grid"
253
+ gridTemplateColumns="1fr 2fr 1fr"
254
+ gridTemplateRows="auto 1fr"
255
+ columnGap={1}
256
+ rowGap={1}
257
+ justifyItems="center"
258
+ alignItems="center"
259
+ />
260
+ ```
261
+
262
+ ### ボーダースタイル
263
+
264
+ ```tsx
265
+ <Box borderStyle="single" /> // ┌─┐
266
+ <Box borderStyle="double" /> // ╔═╗
267
+ <Box borderStyle="round" /> // ╭─╮
268
+ <Box borderStyle="bold" /> // ┏━┓
269
+ <Box borderStyle="classic" /> // +--+
270
+ ```
271
+
272
+ ### カラー
273
+
274
+ Tinky は複数のカラー形式をサポートしています:
275
+
276
+ ```tsx
277
+ <Text color="red" /> // 名前付きカラー
278
+ <Text color="#ff6600" /> // 16進数カラー
279
+ <Text color="rgb(255, 102, 0)" /> // RGB カラー
280
+ <Text color="ansi256:208" /> // ANSI 256 カラー
281
+ ```
282
+
283
+ ## 🔧 API リファレンス
284
+
285
+ ### render(element, options?)
286
+
287
+ React 要素をターミナルにレンダリングします。
288
+
289
+ ```tsx
290
+ import { render } from "tinky";
291
+
292
+ const { unmount, waitUntilExit, rerender, clear } = render(<App />, {
293
+ stdout: process.stdout,
294
+ stdin: process.stdin,
295
+ stderr: process.stderr,
296
+ exitOnCtrlC: true,
297
+ patchConsole: true,
298
+ });
299
+
300
+ // アプリの終了を待機
301
+ await waitUntilExit();
302
+
303
+ // 新しい props で再レンダリング
304
+ rerender(<App newProp={true} />);
305
+
306
+ // アプリをアンマウント
307
+ unmount();
308
+
309
+ // 出力をクリア
310
+ clear();
311
+ ```
312
+
313
+ ### measureElement(ref)
314
+
315
+ レンダリングされた要素のサイズを測定します。
316
+
317
+ ```tsx
318
+ import { measureElement, Box, useRef, useEffect } from "tinky";
319
+
320
+ function MyComponent() {
321
+ const ref = useRef(null);
322
+
323
+ useEffect(() => {
324
+ if (ref.current) {
325
+ const { width, height } = measureElement(ref.current);
326
+ console.log(`サイズ: ${width}x${height}`);
327
+ }
328
+ }, []);
329
+
330
+ return <Box ref={ref}>コンテンツ</Box>;
331
+ }
332
+ ```
333
+
334
+ ## 🧪 テスト
335
+
336
+ Tinky は Bun を使用してテストを行います。テストスイートを実行:
337
+
338
+ ```bash
339
+ bun test
340
+ ```
341
+
342
+ ## 📄 ライセンス
343
+
344
+ MIT © [ByteLandTechnology](https://github.com/ByteLandTechnology)
345
+
346
+ ## 🙏 謝辞
347
+
348
+ - [Ink](https://github.com/vadimdemedes/ink) — オリジナルの React CLI フレームワーク
349
+ - [Taffy](https://github.com/DioxusLabs/taffy) — 高性能 CSS レイアウトエンジン
350
+ - [React](https://reactjs.org/) — これを可能にした UI ライブラリ