kakidash 0.0.8 → 0.0.10

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.ja.md CHANGED
@@ -87,7 +87,13 @@ import { Kakidash } from 'kakidash';
87
87
  const container = document.getElementById('mindmap-container');
88
88
 
89
89
  // インスタンス化
90
- const kakidash = new Kakidash(container);
90
+ // インスタンス化 (オプション指定可能)
91
+ const kakidash = new Kakidash(container, {
92
+ maxNodeWidth: 200, // オプション: ノードの最大幅
93
+ customStyles: { // オプション: 初期のカスタムスタイル
94
+ rootNode: { border: '2px solid red' }
95
+ }
96
+ });
91
97
 
92
98
  // 必要に応じて初期データをロードしたり、ノードを追加したりします
93
99
  kakidash.addNode(kakidash.getRootId(), 'Hello World');
@@ -113,19 +119,73 @@ kakidash.addNode(kakidash.getRootId(), 'Hello World');
113
119
  const container = document.getElementById('mindmap-container');
114
120
  const kakidash = new Kakidash(container);
115
121
 
122
+ // 動作確認
116
123
  // 動作確認
117
124
  console.log('Kakidash initialized:', kakidash);
118
125
  </script>
119
126
  ```
120
127
 
128
+ ## スタイルのカスタマイズ
129
+
130
+ `updateGlobalStyles` を使用してカスタムスタイルを定義できます。設定は保存され、テーマが `'custom'` の場合に適用されます。
131
+
132
+ ```javascript
133
+ // 1. カスタムスタイルを定義(いつでも実行可能)
134
+ // 設定は内部に保存されます
135
+ kakidash.updateGlobalStyles({
136
+ // ルートノード(中心)のスタイル
137
+ rootNode: {
138
+ border: '4px solid gold',
139
+ background: '#ffeeee',
140
+ color: '#333' // フォント色
141
+ },
142
+
143
+ // 子ノード(枝)のスタイル
144
+ childNode: {
145
+ border: '2px dashed blue',
146
+ background: 'white',
147
+ color: '#555' // フォント色
148
+ },
149
+
150
+ // 接続線の色
151
+ connection: {
152
+ color: 'orange'
153
+ },
154
+
155
+ // マインドマップ全体の背景
156
+ canvas: {
157
+ background: '#fafafa' // 透明にする場合は 'transparent'
158
+ }
159
+ });
160
+
161
+ // 2. カスタムテーマを有効化してスタイルを反映
162
+ kakidash.setTheme('custom');
163
+ ```
164
+
165
+ ### 指定可能なプロパティ一覧
166
+
167
+ すべての値は標準的なCSSの文字列として指定可能です。
168
+
169
+ | オブジェクト | プロパティ | 説明 | 例 |
170
+ | --- | --- | --- | --- |
171
+ | `rootNode`, `childNode` | `border` | 枠線の指定 | `'2px solid red'`, `'none'` |
172
+ | | `background` | 背景色 | `'#ffffff'`, `'rgba(0,0,0,0.5)'`, `'transparent'` |
173
+ | | `color` | 文字色 | `'#333'`, `'black'` |
174
+ | `connection` | `color` | 接続線の色 | `'#ccc'`, `'orange'` |
175
+ | `canvas` | `background` | キャンバス全体の背景 | `'#f0f0f0'`, `'transparent'` |
176
+
121
177
  ## API Reference
122
178
 
123
179
  ### Methods
124
180
 
125
- - **`new Kakidash(container: HTMLElement)`**: インスタンスを生成します。
181
+ - **`new Kakidash(container: HTMLElement, options?: KakidashOptions)`**: インスタンスを生成します。
182
+ - `options.shortcuts`: キーボードショートカットのカスタマイズ。
183
+ - `options.maxNodeWidth`: テキストノードの最大幅 (ピクセル)。
184
+ - `options.customStyles`: 初期のカスタムスタイル。
126
185
  - **`kakidash.addNode(parentId, topic)`**: 指定した親ノードに新しい子ノードを追加します。
127
186
  - **`kakidash.getData()`**: 現在のマインドマップデータをJSONオブジェクトとして取得します。
128
187
  - **`kakidash.loadData(data)`**: JSONデータを読み込み、マインドマップを描画します。
188
+ - **`kakidash.updateGlobalStyles(styles)`**: グローバルスタイルを更新します ('custom' テーマ選択時のみ有効)。
129
189
  - **`kakidash.updateLayout(mode)`**: レイアウトモードを変更します ('Standard', 'Left', 'Right')。
130
190
  - **`kakidash.setReadOnly(boolean)`**: 読み取り専用モードを切り替えます。
131
191
  - **`kakidash.setMaxNodeWidth(width: number)`**: テキストノードの最大幅を設定します(-1で無制限)。
@@ -315,3 +375,13 @@ npm test
315
375
  ```bash
316
376
  npm run lint
317
377
  ```
378
+
379
+ ### Documentation
380
+
381
+ TypeDocを使用してAPIドキュメントを生成します:
382
+
383
+ ```bash
384
+ npm run docs
385
+ ```
386
+
387
+ `docs/` ディレクトリにドキュメントが生成されます。
package/README.md CHANGED
@@ -84,7 +84,13 @@ import { Kakidash } from 'kakidash';
84
84
  const container = document.getElementById('mindmap-container');
85
85
 
86
86
  // Instantiate
87
- const kakidash = new Kakidash(container);
87
+ // Instantiate with optional configuration
88
+ const kakidash = new Kakidash(container, {
89
+ maxNodeWidth: 200, // Optional: Maximum width for nodes
90
+ customStyles: { // Optional: Initial custom styles
91
+ rootNode: { border: '2px solid red' }
92
+ }
93
+ });
88
94
 
89
95
  // Add initial data or nodes if needed
90
96
  kakidash.addNode(kakidash.getRootId(), 'Hello World');
@@ -113,14 +119,67 @@ Use the built `umd` file. The library will be exposed under the global variable
113
119
  </script>
114
120
  ```
115
121
 
122
+ ## Custom Styling
123
+
124
+ You can define custom styles using `updateGlobalStyles`. These settings are persisted and applied whenever the theme is `'custom'`.
125
+
126
+ ```javascript
127
+ // 1. Apply custom styles (Can be done anytime)
128
+ // These settings are saved internally.
129
+ kakidash.updateGlobalStyles({
130
+ // Root node style
131
+ rootNode: {
132
+ border: '4px solid gold',
133
+ background: '#ffeeee',
134
+ color: '#333' // Font color
135
+ },
136
+
137
+ // Child nodes style
138
+ childNode: {
139
+ border: '2px dashed blue',
140
+ background: 'white',
141
+ color: '#555' // Font color
142
+ },
143
+
144
+ // Connection line color
145
+ connection: {
146
+ color: 'orange'
147
+ },
148
+
149
+ // Entire canvas background
150
+ canvas: {
151
+ background: '#fafafa' // Use 'transparent' for transparency
152
+ }
153
+ });
154
+
155
+ // 2. Activate the custom theme to see your changes
156
+ kakidash.setTheme('custom');
157
+ ```
158
+
159
+ ### Supported Properties
160
+
161
+ All values accept standard CSS strings.
162
+
163
+ | Object | Property | Description | Example |
164
+ | --- | --- | --- | --- |
165
+ | `rootNode`, `childNode` | `border` | Node border | `'2px solid red'`, `'none'` |
166
+ | | `background` | Node background | `'#ffffff'`, `'rgba(0,0,0,0.5)'`, `'transparent'` |
167
+ | | `color` | Text color | `'#333'`, `'black'` |
168
+ | `connection` | `color` | Connection line color | `'#ccc'`, `'orange'` |
169
+ | `canvas` | `background` | Canvas background | `'#f0f0f0'`, `'transparent'` |
170
+
116
171
  ## API Reference
117
172
 
118
173
  ### Methods
119
174
 
120
- - **`new Kakidash(container: HTMLElement)`**: Creates a new instance.
175
+ - **`new Kakidash(container: HTMLElement, options?: KakidashOptions)`**: Creates a new instance.
176
+ - `options.shortcuts`: Custom keyboard shortcuts.
177
+ - `options.maxNodeWidth`: Maximum width for text nodes (pixels).
178
+ - `options.customStyles`: Initial custom styles.
121
179
  - **`kakidash.addNode(parentId, topic)`**: Adds a new child node to the specified parent node.
122
180
  - **`kakidash.getData()`**: Retrieves current mindmap data as a JSON object.
123
181
  - **`kakidash.loadData(data)`**: Loads JSON data and renders the mindmap.
182
+ - **`kakidash.updateGlobalStyles(styles)`**: Updates global styles (only active when theme is 'custom').
124
183
  - **`kakidash.updateLayout(mode)`**: Changes layout mode ('Standard', 'Left', 'Right').
125
184
  - **`kakidash.setReadOnly(boolean)`**: Toggles read-only mode.
126
185
  - **`kakidash.setMaxNodeWidth(width: number)`**: Sets main node width (-1 for unlimited).
@@ -310,3 +369,13 @@ npm test
310
369
  ```bash
311
370
  npm run lint
312
371
  ```
372
+
373
+ ### Documentation
374
+
375
+ Generate API documentation using TypeDoc:
376
+
377
+ ```bash
378
+ npm run docs
379
+ ```
380
+
381
+ The documentation will be generated in `docs/` directory.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  declare type Direction = 'Up' | 'Down' | 'Left' | 'Right';
2
2
 
3
+ /**
4
+ * The main class for the Kakidash mind map library.
5
+ * It manages the mind map data, interaction, and rendering.
6
+ */
3
7
  export declare class Kakidash extends TypedEventEmitter<KakidashEventMap> {
4
8
  private mindMap;
5
9
  private service;
@@ -22,10 +26,23 @@ export declare class Kakidash extends TypedEventEmitter<KakidashEventMap> {
22
26
  private isBatching;
23
27
  private animationFrameId;
24
28
  private maxWidth;
29
+ private savedCustomStyles;
30
+ /**
31
+ * Creates a new Kakidash instance.
32
+ *
33
+ * @param container - The HTML element to mount the mind map into. Must have defined width and height.
34
+ * @param options - Optional configuration options.
35
+ */
25
36
  constructor(container: HTMLElement, options?: KakidashOptions);
26
37
  /**
27
38
  * Adds a new child node to the specified parent.
28
39
  * This is a pure data operation and does not trigger UI actions like auto-focus or scroll.
40
+ *
41
+ * @param parentId - The ID of the parent node.
42
+ * @param topic - The content of the new node.
43
+ * @param layoutSide - For 'Both' layout mode, which side to place the node (root children only).
44
+ * @param options - Options for the operation.
45
+ * @returns The newly created Node object, or null if failed.
29
46
  */
30
47
  addNode(parentId: string, topic?: string, layoutSide?: 'left' | 'right', options?: {
31
48
  emitChange?: boolean;
@@ -53,10 +70,18 @@ export declare class Kakidash extends TypedEventEmitter<KakidashEventMap> {
53
70
  /**
54
71
  * Updates a node's topic or style.
55
72
  * This is a pure data operation.
56
- */
57
- /**
58
- * Updates a node's topic or style.
59
- * This is a pure data operation.
73
+ *
74
+ * @param nodeId - The ID of the node to update.
75
+ * @param updates - Object containing the fields to update.
76
+ *
77
+ * @example
78
+ * **Rename and style a node:**
79
+ * ```typescript
80
+ * kakidash.updateNode('node-1', {
81
+ * topic: 'Important Idea',
82
+ * style: { background: '#ffff00', color: 'black' }
83
+ * });
84
+ * ```
60
85
  */
61
86
  updateNode(nodeId: string, updates: {
62
87
  topic?: string;
@@ -78,7 +103,30 @@ export declare class Kakidash extends TypedEventEmitter<KakidashEventMap> {
78
103
  * Get the ID of the currently selected node.
79
104
  */
80
105
  getSelectedNodeId(): string | null;
106
+ /**
107
+ * Updates the style of a specific node.
108
+ * This applies styles directly to the node instance, overriding global themes.
109
+ *
110
+ * @param nodeId - The ID of the node to update.
111
+ * @param style - Partial style object. Properties set to `undefined` or empty strings might reset to default depending on implementation.
112
+ *
113
+ * @example
114
+ * **Highlight a node:**
115
+ * ```typescript
116
+ * kakidash.updateNodeStyle('node-id-123', {
117
+ * color: 'red',
118
+ * fontWeight: 'bold',
119
+ * fontSize: '20px'
120
+ * });
121
+ * ```
122
+ */
81
123
  updateNodeStyle(nodeId: string, style: Partial<NodeStyle>): void;
124
+ /**
125
+ * Sets the theme of the mind map.
126
+ *
127
+ * @param theme - The theme name ('default' | 'simple' | 'colorful' | 'custom').
128
+ * If 'custom' is selected, previously saved custom styles (via updateGlobalStyles) are applied.
129
+ */
82
130
  setTheme(theme: Theme): void;
83
131
  getMindMap(): MindMap;
84
132
  getNode(nodeId: string): Node_2 | undefined;
@@ -86,6 +134,50 @@ export declare class Kakidash extends TypedEventEmitter<KakidashEventMap> {
86
134
  findNodes(predicate: (node: Node_2) => boolean): Node_2[];
87
135
  setMaxNodeWidth(width: number): void;
88
136
  getMaxNodeWidth(): number;
137
+ /**
138
+ * Updates global styles for the mind map using CSS variables.
139
+ * This allows batch updating of visual appearance without deep re-renders.
140
+ * Styles are persisted in `savedCustomStyles` and applied immediately if the current theme is 'custom'.
141
+ *
142
+ * @param styles - Object containing style definitions for various elements.
143
+ *
144
+ * @example
145
+ * **Apply a dark theme style:**
146
+ * ```typescript
147
+ * kakidash.updateGlobalStyles({
148
+ * rootNode: {
149
+ * border: '2px solid #555',
150
+ * background: '#333',
151
+ * color: '#fff'
152
+ * },
153
+ * childNode: {
154
+ * border: '1px solid #444',
155
+ * background: '#222',
156
+ * color: '#eee'
157
+ * },
158
+ * connection: {
159
+ * color: '#666'
160
+ * },
161
+ * canvas: {
162
+ * background: '#1a1a1a'
163
+ * }
164
+ * });
165
+ * ```
166
+ *
167
+ * @example
168
+ * **Reset specific local styles (by passing empty string):**
169
+ * ```typescript
170
+ * // Reverts root node border to default
171
+ * kakidash.updateGlobalStyles({
172
+ * rootNode: { border: '' }
173
+ * });
174
+ * ```
175
+ */
176
+ updateGlobalStyles(styles: MindMapStyles): void;
177
+ /**
178
+ * Helper to apply a set of styles to the DOM via CSS variables.
179
+ */
180
+ private applyCustomStylesToDOM;
89
181
  setReadOnly(readOnly: boolean): void;
90
182
  destroy(): void;
91
183
  batch(callback: () => void): void;
@@ -147,6 +239,15 @@ export declare type KakidashEventMap = {
147
239
 
148
240
  export declare interface KakidashOptions {
149
241
  shortcuts?: ShortcutConfig;
242
+ /**
243
+ * Maximum width for mind map nodes in pixels.
244
+ * If not provided, defaults to unlimited (fitting content).
245
+ */
246
+ maxNodeWidth?: number;
247
+ /**
248
+ * Custom styles to apply to the mind map initially.
249
+ */
250
+ customStyles?: MindMapStyles;
150
251
  }
151
252
 
152
253
  declare interface KeyBinding {
@@ -196,6 +297,33 @@ declare interface MindMapNodeData {
196
297
  layoutSide?: 'left' | 'right';
197
298
  }
198
299
 
300
+ /**
301
+ * Configuration for global mind map styles.
302
+ * All properties accept standard CSS value strings (e.g., "blue", "1px solid red", "#ff0000").
303
+ */
304
+ export declare interface MindMapStyles {
305
+ /** Styles for the root node. */
306
+ rootNode?: {
307
+ border?: string;
308
+ background?: string;
309
+ color?: string;
310
+ };
311
+ /** Styles for all child nodes (non-root). */
312
+ childNode?: {
313
+ border?: string;
314
+ background?: string;
315
+ color?: string;
316
+ };
317
+ /** Styles for connection lines. */
318
+ connection?: {
319
+ color?: string;
320
+ };
321
+ /** Styles for the canvas/background. */
322
+ canvas?: {
323
+ background?: string;
324
+ };
325
+ }
326
+
199
327
  declare class Node_2 {
200
328
  id: string;
201
329
  topic: string;
@@ -225,7 +353,7 @@ declare type ShortcutAction = 'navUp' | 'navDown' | 'navLeft' | 'navRight' | 'ad
225
353
 
226
354
  export declare type ShortcutConfig = Partial<Record<ShortcutAction, KeyBinding[]>>;
227
355
 
228
- declare type Theme = 'default' | 'simple' | 'colorful';
356
+ declare type Theme = 'default' | 'simple' | 'colorful' | 'custom';
229
357
 
230
358
  declare class TypedEventEmitter<EventMap extends Record<string, any>> {
231
359
  private listeners;