@filekit-studio/diagram 0.0.0-stage → 1.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 FileKit-Studio
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
+
package/README.md CHANGED
@@ -1,3 +1,170 @@
1
- # Temporary Holding Version
1
+ # @filekit-studio/diagram
2
+
3
+ > Declarative Diagram-as-Code & JSON graph compiler for `@filekit-studio/sketch`.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@filekit-studio/diagram.svg)](https://www.npmjs.com/package/@filekit-studio/diagram)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ `@filekit-studio/diagram` lets you generate and render beautiful hand-drawn whiteboards, architecture diagrams, and flowcharts directly from declarative JSON or Diagram-as-Code in React and Next.js.
9
+
10
+ - ⚡️ **Zero Coordinates Required**: Provide nodes, edges, and clusters — the deterministic DAG layout engine positions and aligns everything automatically.
11
+ - 🎨 **Sketch Aesthetics**: Powered by `@filekit-studio/sketch`, rendering organic hand-drawn shapes, rough fills, and magnetic connector arrows.
12
+ - 📐 **Directional Flows**: Supports Left-to-Right (`LR`), Top-to-Bottom (`TB`), Right-to-Left (`RL`), and Bottom-to-Top (`BT`).
13
+ - 📦 **Excalidraw Native**: Direct conversion from `.excalidraw` schema files and element arrays.
14
+ - 🔒 **100% Client-Side**: Zero server calls, zero tracking, works fully offline.
15
+
16
+ ---
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ bun add @filekit-studio/diagram @filekit-studio/sketch
22
+ # or
23
+ npm install @filekit-studio/diagram @filekit-studio/sketch
24
+ # or
25
+ pnpm add @filekit-studio/diagram @filekit-studio/sketch
26
+ ```
27
+
28
+ Ensure `@filekit-studio/sketch/styles.css` is imported in your application:
29
+
30
+ ```tsx
31
+ import '@filekit-studio/sketch/styles.css'
32
+ ```
33
+
34
+ ---
35
+
36
+ ## Quickstart
37
+
38
+ ### 1. Declarative `<Diagram />` Component
39
+
40
+ ```tsx
41
+ 'use client'
42
+
43
+ import React from 'react'
44
+ import { Diagram, type DiagramData } from '@filekit-studio/diagram'
45
+ import '@filekit-studio/sketch/styles.css'
46
+
47
+ const architecture: DiagramData = {
48
+ title: 'Cloud Payment Pipeline',
49
+ direction: 'LR',
50
+ nodes: [
51
+ {
52
+ id: 'client',
53
+ label: 'Client Browser\n(React / Next.js)',
54
+ shape: 'rectangle',
55
+ color: 'indigo',
56
+ badge: 'FRONTEND',
57
+ },
58
+ {
59
+ id: 'gateway',
60
+ label: 'API Gateway',
61
+ description: 'Kong / Cloudflare',
62
+ shape: 'rounded',
63
+ color: 'blue',
64
+ },
65
+ {
66
+ id: 'auth',
67
+ label: 'Auth Service',
68
+ description: 'JWT / OAuth2',
69
+ shape: 'diamond',
70
+ color: 'amber',
71
+ },
72
+ {
73
+ id: 'db',
74
+ label: 'Primary Database\n(PostgreSQL)',
75
+ shape: 'cylinder',
76
+ color: 'emerald',
77
+ badge: 'STORAGE',
78
+ },
79
+ ],
80
+ edges: [
81
+ { from: 'client', to: 'gateway', label: 'HTTPS POST' },
82
+ { from: 'gateway', to: 'auth', label: 'Verify Token' },
83
+ { from: 'auth', to: 'db', label: 'SQL Query' },
84
+ ],
85
+ groups: [
86
+ {
87
+ id: 'backend',
88
+ label: 'Internal VPC Cluster',
89
+ nodeIds: ['gateway', 'auth', 'db'],
90
+ color: 'indigo',
91
+ },
92
+ ],
93
+ }
94
+
95
+ export default function ArchitectureDoc() {
96
+ return (
97
+ <div className="w-full h-[500px] rounded-xl overflow-hidden border">
98
+ <Diagram
99
+ data={architecture}
100
+ mode="viewer"
101
+ theme="system"
102
+ autoFit={true}
103
+ showCopyButton={true}
104
+ />
105
+ </div>
106
+ )
107
+ }
108
+ ```
109
+
110
+ ---
111
+
112
+ ### 2. Programmatic Compilation (`diagramToSketch`)
113
+
114
+ If you want to compile graph JSON into a `SketchDocument` to save or manipulate:
115
+
116
+ ```tsx
117
+ import { diagramToSketch } from '@filekit-studio/diagram'
118
+
119
+ const sketchDoc = diagramToSketch(architecture, {
120
+ direction: 'LR',
121
+ nodeSpacing: 70,
122
+ rankSpacing: 130,
123
+ })
124
+
125
+ console.log(sketchDoc.elements) // Array of SketchBoardElement objects
126
+ ```
127
+
128
+ ---
129
+
130
+ ### 3. Rendering Excalidraw JSON Files
131
+
132
+ ```tsx
133
+ import { Diagram } from '@filekit-studio/diagram'
134
+ import excalidrawFile from './diagram.excalidraw.json'
135
+
136
+ export function ExcalidrawViewer() {
137
+ return (
138
+ <div className="w-full h-[600px]">
139
+ <Diagram data={excalidrawFile} mode="viewer" autoFit={true} />
140
+ </div>
141
+ )
142
+ }
143
+ ```
144
+
145
+ ---
146
+
147
+ ## `<Diagram />` Props Reference
148
+
149
+ | Prop | Type | Default | Description |
150
+ | :--- | :--- | :--- | :--- |
151
+ | `data` | `DiagramData \| string` | *required* | Diagram specification object or JSON string. |
152
+ | `mode` | `'viewer' \| 'editor'` | `'viewer'` | Display mode: clean doc viewer or full whiteboard studio. |
153
+ | `direction` | `'TB' \| 'BT' \| 'LR' \| 'RL'` | `'LR'` | Flow direction for the DAG auto-layout engine. |
154
+ | `uiConfig` | `SketchUIConfig` | `{}` | Granular toggle flags for all 54 UI controls and menus. |
155
+ | `theme` | `'light' \| 'dark' \| 'system'` | `'system'` | Color theme mode. |
156
+ | `canvasBackground` | `string` | `'#f0f4f8'` | Hex background color override. |
157
+ | `gridStyle` | `'grid' \| 'dots' \| 'cross' \| 'none'` | `'dots'` | Canvas grid pattern. |
158
+ | `autoFit` | `boolean` | `true` | Scale and center elements to fit container on mount. |
159
+ | `interactive` | `boolean` | `true` | Allow click-and-drag panning and wheel zooming. |
160
+ | `showCopyButton` | `boolean` | `true` | Display 1-click clipboard PNG image export button. |
161
+ | `showZoomControls` | `boolean` | `false` | Display zoom percentage and +/- buttons in corner. |
162
+ | `layoutOptions` | `DiagramLayoutOptions` | `{}` | Fine-tuning for spacing, margins, and padding. |
163
+ | `controllerRef` | `Ref<SketchController>` | `undefined` | Ref to imperative controller methods (`zoomToFit`, etc.). |
164
+
165
+ ---
166
+
167
+ ## License
168
+
169
+ MIT © [FileKit Studio](https://tools.kanaddev.me)
2
170
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.