@hanzo/ui 5.3.31 → 5.3.33
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/dist/calendar-ext/index.js +203 -0
- package/dist/calendar-ext/index.mjs +165 -0
- package/dist/charts/index.js +278 -0
- package/dist/charts/index.mjs +250 -0
- package/dist/index.js +0 -1
- package/dist/index.mjs +0 -1
- package/dist/kanban/index.js +594 -0
- package/dist/kanban/index.mjs +572 -0
- package/dist/mermaid/index.js +275 -0
- package/dist/mermaid/index.mjs +249 -0
- package/dist/primitives/index.js +0 -1
- package/dist/primitives/index.mjs +0 -1
- package/dist/primitives-export.js +0 -1
- package/dist/primitives-export.mjs +0 -1
- package/dist/spline/index.js +211 -0
- package/dist/spline/index.mjs +202 -0
- package/dist/spline/media-stack.js +193 -0
- package/dist/spline/media-stack.mjs +185 -0
- package/dist/spline/player.js +37 -0
- package/dist/spline/player.mjs +31 -0
- package/package.json +69 -14
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var lucideReact = require('lucide-react');
|
|
5
|
+
var mermaid = require('mermaid');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var sonner = require('sonner');
|
|
8
|
+
var svgPanZoom = require('svg-pan-zoom');
|
|
9
|
+
var clsx = require('clsx');
|
|
10
|
+
var tailwindMerge = require('tailwind-merge');
|
|
11
|
+
var reactSlot = require('@radix-ui/react-slot');
|
|
12
|
+
var classVarianceAuthority = require('class-variance-authority');
|
|
13
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
14
|
+
var TooltipPrimitive = require('@radix-ui/react-tooltip');
|
|
15
|
+
|
|
16
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
+
|
|
18
|
+
function _interopNamespace(e) {
|
|
19
|
+
if (e && e.__esModule) return e;
|
|
20
|
+
var n = Object.create(null);
|
|
21
|
+
if (e) {
|
|
22
|
+
Object.keys(e).forEach(function (k) {
|
|
23
|
+
if (k !== 'default') {
|
|
24
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
25
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () { return e[k]; }
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
n.default = e;
|
|
33
|
+
return Object.freeze(n);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var mermaid__default = /*#__PURE__*/_interopDefault(mermaid);
|
|
37
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
38
|
+
var svgPanZoom__default = /*#__PURE__*/_interopDefault(svgPanZoom);
|
|
39
|
+
var TooltipPrimitive__namespace = /*#__PURE__*/_interopNamespace(TooltipPrimitive);
|
|
40
|
+
|
|
41
|
+
var __defProp = Object.defineProperty;
|
|
42
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
43
|
+
function cn(...inputs) {
|
|
44
|
+
return tailwindMerge.twMerge(clsx.clsx(inputs));
|
|
45
|
+
}
|
|
46
|
+
__name(cn, "cn");
|
|
47
|
+
var buttonVariants = classVarianceAuthority.cva(
|
|
48
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
|
49
|
+
{
|
|
50
|
+
variants: {
|
|
51
|
+
variant: {
|
|
52
|
+
default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
|
53
|
+
destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
|
54
|
+
outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
|
55
|
+
secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
|
56
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
57
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
58
|
+
// Keep the additional Hanzo variants for backward compatibility
|
|
59
|
+
primary: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
|
60
|
+
linkFG: "text-primary underline-offset-4 hover:underline",
|
|
61
|
+
linkMuted: "text-muted-foreground underline-offset-4 hover:underline hover:text-foreground"
|
|
62
|
+
},
|
|
63
|
+
size: {
|
|
64
|
+
default: "h-9 px-4 py-2",
|
|
65
|
+
sm: "h-8 rounded-md px-3 text-xs",
|
|
66
|
+
lg: "h-10 rounded-md px-8",
|
|
67
|
+
icon: "h-9 w-9"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
defaultVariants: {
|
|
71
|
+
variant: "default",
|
|
72
|
+
size: "default"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
var Button = React__namespace.forwardRef(
|
|
77
|
+
({ className, variant, size, asChild = false, isLoading = false, children, ...props }, ref) => {
|
|
78
|
+
const Comp = asChild ? reactSlot.Slot : "button";
|
|
79
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
80
|
+
Comp,
|
|
81
|
+
{
|
|
82
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
83
|
+
ref,
|
|
84
|
+
...props,
|
|
85
|
+
children: [
|
|
86
|
+
isLoading ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
87
|
+
lucideReact.Loader2,
|
|
88
|
+
{
|
|
89
|
+
className: cn("h-4 w-4 animate-spin", size !== "icon" && "mr-2")
|
|
90
|
+
}
|
|
91
|
+
) : null,
|
|
92
|
+
isLoading && size === "icon" ? null : children
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
Button.displayName = "Button";
|
|
99
|
+
var Tooltip = TooltipPrimitive__namespace.Root;
|
|
100
|
+
var TooltipTrigger = TooltipPrimitive__namespace.Trigger;
|
|
101
|
+
var TooltipContent = /* @__PURE__ */ __name(({
|
|
102
|
+
className,
|
|
103
|
+
sideOffset = 4,
|
|
104
|
+
showArrow = true,
|
|
105
|
+
...props
|
|
106
|
+
}) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
107
|
+
TooltipPrimitive__namespace.Content,
|
|
108
|
+
{
|
|
109
|
+
className: cn(
|
|
110
|
+
"border-divider bg-bg-dark animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-w-[280px] rounded-lg border px-3 py-1.5 text-xs text-white",
|
|
111
|
+
className
|
|
112
|
+
),
|
|
113
|
+
sideOffset,
|
|
114
|
+
...props,
|
|
115
|
+
children: [
|
|
116
|
+
props.children,
|
|
117
|
+
showArrow && /* @__PURE__ */ jsxRuntime.jsx(TooltipPrimitive__namespace.Arrow, { className: "fill-bg-dark -my-px drop-shadow-[0_1px_0_#313336]" })
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
), "TooltipContent");
|
|
121
|
+
TooltipContent.displayName = TooltipPrimitive__namespace.Content.displayName;
|
|
122
|
+
mermaid__default.default.initialize({
|
|
123
|
+
startOnLoad: true,
|
|
124
|
+
mindmap: {
|
|
125
|
+
useWidth: 800
|
|
126
|
+
},
|
|
127
|
+
theme: "dark",
|
|
128
|
+
fontSize: 18,
|
|
129
|
+
darkMode: true,
|
|
130
|
+
fontFamily: "Inter"
|
|
131
|
+
});
|
|
132
|
+
var generateId = /* @__PURE__ */ __name(() => `mermaid-${Math.random().toString(36).slice(2)}`, "generateId");
|
|
133
|
+
var downloadBlob = /* @__PURE__ */ __name(async (blob, filename) => {
|
|
134
|
+
try {
|
|
135
|
+
const link = document.createElement("a");
|
|
136
|
+
link.href = URL.createObjectURL(blob);
|
|
137
|
+
link.download = filename;
|
|
138
|
+
document.body.appendChild(link);
|
|
139
|
+
link.click();
|
|
140
|
+
document.body.removeChild(link);
|
|
141
|
+
URL.revokeObjectURL(link.href);
|
|
142
|
+
sonner.toast.success("Mermaid diagram saved successfully");
|
|
143
|
+
} catch (error) {
|
|
144
|
+
sonner.toast.error("Failed to download diagram");
|
|
145
|
+
}
|
|
146
|
+
}, "downloadBlob");
|
|
147
|
+
var MermaidDiagram = /* @__PURE__ */ __name(({
|
|
148
|
+
code,
|
|
149
|
+
className,
|
|
150
|
+
isRunning
|
|
151
|
+
}) => {
|
|
152
|
+
const ref = React.useRef(null);
|
|
153
|
+
const lastCode = React.useRef(null);
|
|
154
|
+
const [instance, setInstance] = React.useState(null);
|
|
155
|
+
const isComplete = !isRunning;
|
|
156
|
+
const resetZoom = React.useCallback(() => {
|
|
157
|
+
instance?.fit();
|
|
158
|
+
instance?.center();
|
|
159
|
+
}, [instance]);
|
|
160
|
+
const downloadSVG = React.useCallback(() => {
|
|
161
|
+
if (ref.current) {
|
|
162
|
+
const svg = ref.current.innerHTML;
|
|
163
|
+
const blob = new Blob([svg], { type: "image/svg+xml" });
|
|
164
|
+
void downloadBlob(blob, "mermaid-diagram.svg");
|
|
165
|
+
}
|
|
166
|
+
}, []);
|
|
167
|
+
const enableZoom = React.useCallback(() => {
|
|
168
|
+
instance?.enablePan();
|
|
169
|
+
instance?.enableZoom();
|
|
170
|
+
}, [instance]);
|
|
171
|
+
const disableZoom = React.useCallback(() => {
|
|
172
|
+
instance?.disablePan();
|
|
173
|
+
instance?.disableZoom();
|
|
174
|
+
}, [instance]);
|
|
175
|
+
const handleFocus = React.useCallback(() => {
|
|
176
|
+
enableZoom();
|
|
177
|
+
}, [enableZoom]);
|
|
178
|
+
const handleBlur = React.useCallback(() => {
|
|
179
|
+
disableZoom();
|
|
180
|
+
}, [disableZoom]);
|
|
181
|
+
const handleClick = React.useCallback(() => {
|
|
182
|
+
if (ref.current) {
|
|
183
|
+
ref.current.focus();
|
|
184
|
+
}
|
|
185
|
+
}, []);
|
|
186
|
+
React.useEffect(() => {
|
|
187
|
+
if (!isComplete || !ref.current || !code) return;
|
|
188
|
+
if (lastCode.current === code) return;
|
|
189
|
+
void (async () => {
|
|
190
|
+
try {
|
|
191
|
+
const id = generateId();
|
|
192
|
+
const { svg } = await mermaid__default.default.render(id, code);
|
|
193
|
+
if (ref.current) {
|
|
194
|
+
ref.current.innerHTML = svg;
|
|
195
|
+
const svgElement = ref.current.querySelector("svg");
|
|
196
|
+
if (svgElement) {
|
|
197
|
+
svgElement.setAttribute("height", "100%");
|
|
198
|
+
svgElement.setAttribute("width", "100%");
|
|
199
|
+
svgElement.style.height = "100%";
|
|
200
|
+
svgElement.style.width = "100%";
|
|
201
|
+
svgElement.style.position = "absolute";
|
|
202
|
+
svgElement.style.top = "0";
|
|
203
|
+
svgElement.style.left = "0";
|
|
204
|
+
const panZoomInstance = svgPanZoom__default.default(svgElement);
|
|
205
|
+
panZoomInstance.fit();
|
|
206
|
+
panZoomInstance.center();
|
|
207
|
+
panZoomInstance.zoomAtPoint(1, { x: 0, y: 0 });
|
|
208
|
+
panZoomInstance.disablePan();
|
|
209
|
+
panZoomInstance.disableZoom();
|
|
210
|
+
setInstance(panZoomInstance);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
lastCode.current = code;
|
|
214
|
+
} catch (e) {
|
|
215
|
+
console.warn("Failed to render Mermaid diagram:", e);
|
|
216
|
+
}
|
|
217
|
+
})();
|
|
218
|
+
}, [code, isComplete]);
|
|
219
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
|
|
220
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "absolute top-2 right-2 z-10 flex gap-1", children: [
|
|
221
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
|
|
222
|
+
/* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
223
|
+
Button,
|
|
224
|
+
{
|
|
225
|
+
variant: "ghost",
|
|
226
|
+
size: "icon",
|
|
227
|
+
onClick: resetZoom,
|
|
228
|
+
className: "text-text-secondary",
|
|
229
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.RotateCcw, { size: 14 })
|
|
230
|
+
}
|
|
231
|
+
) }),
|
|
232
|
+
/* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Reset Zoom" }) })
|
|
233
|
+
] }),
|
|
234
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
|
|
235
|
+
/* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
236
|
+
Button,
|
|
237
|
+
{
|
|
238
|
+
variant: "ghost",
|
|
239
|
+
size: "icon",
|
|
240
|
+
onClick: downloadSVG,
|
|
241
|
+
className: "text-text-secondary",
|
|
242
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Download, { size: 14 })
|
|
243
|
+
}
|
|
244
|
+
) }),
|
|
245
|
+
/* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Download SVG" }) })
|
|
246
|
+
] })
|
|
247
|
+
] }),
|
|
248
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
249
|
+
"div",
|
|
250
|
+
{
|
|
251
|
+
onClick: handleClick,
|
|
252
|
+
className: "text-text-secondary bg-bg-quaternary absolute right-2 bottom-2 z-10 rounded px-2 py-1 text-xs",
|
|
253
|
+
children: "Click to focus, then scroll to zoom & drag to pan"
|
|
254
|
+
}
|
|
255
|
+
),
|
|
256
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
257
|
+
"div",
|
|
258
|
+
{
|
|
259
|
+
ref,
|
|
260
|
+
tabIndex: 0,
|
|
261
|
+
onFocus: handleFocus,
|
|
262
|
+
onBlur: handleBlur,
|
|
263
|
+
onClick: handleClick,
|
|
264
|
+
className: cn(
|
|
265
|
+
"text-text-secondary bg-bg-quaternary focus:ring-opacity-50 relative w-full cursor-grab overflow-hidden rounded-b-lg p-4 py-10 text-center text-sm focus:cursor-grabbing focus:ring-2 focus:ring-blue-500 focus:outline-none",
|
|
266
|
+
className
|
|
267
|
+
),
|
|
268
|
+
style: { width: "100%", minHeight: "400px" },
|
|
269
|
+
children: "Drawing diagram..."
|
|
270
|
+
}
|
|
271
|
+
)
|
|
272
|
+
] });
|
|
273
|
+
}, "MermaidDiagram");
|
|
274
|
+
|
|
275
|
+
exports.MermaidDiagram = MermaidDiagram;
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Loader2, RotateCcw, Download } from 'lucide-react';
|
|
3
|
+
import mermaid from 'mermaid';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { useRef, useState, useCallback, useEffect } from 'react';
|
|
6
|
+
import { toast } from 'sonner';
|
|
7
|
+
import svgPanZoom from 'svg-pan-zoom';
|
|
8
|
+
import { clsx } from 'clsx';
|
|
9
|
+
import { twMerge } from 'tailwind-merge';
|
|
10
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
11
|
+
import { cva } from 'class-variance-authority';
|
|
12
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
13
|
+
import * as TooltipPrimitive from '@radix-ui/react-tooltip';
|
|
14
|
+
|
|
15
|
+
var __defProp = Object.defineProperty;
|
|
16
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
+
function cn(...inputs) {
|
|
18
|
+
return twMerge(clsx(inputs));
|
|
19
|
+
}
|
|
20
|
+
__name(cn, "cn");
|
|
21
|
+
var buttonVariants = cva(
|
|
22
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
|
23
|
+
{
|
|
24
|
+
variants: {
|
|
25
|
+
variant: {
|
|
26
|
+
default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
|
27
|
+
destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
|
28
|
+
outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
|
29
|
+
secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
|
30
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
31
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
32
|
+
// Keep the additional Hanzo variants for backward compatibility
|
|
33
|
+
primary: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
|
34
|
+
linkFG: "text-primary underline-offset-4 hover:underline",
|
|
35
|
+
linkMuted: "text-muted-foreground underline-offset-4 hover:underline hover:text-foreground"
|
|
36
|
+
},
|
|
37
|
+
size: {
|
|
38
|
+
default: "h-9 px-4 py-2",
|
|
39
|
+
sm: "h-8 rounded-md px-3 text-xs",
|
|
40
|
+
lg: "h-10 rounded-md px-8",
|
|
41
|
+
icon: "h-9 w-9"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
defaultVariants: {
|
|
45
|
+
variant: "default",
|
|
46
|
+
size: "default"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
var Button = React.forwardRef(
|
|
51
|
+
({ className, variant, size, asChild = false, isLoading = false, children, ...props }, ref) => {
|
|
52
|
+
const Comp = asChild ? Slot : "button";
|
|
53
|
+
return /* @__PURE__ */ jsxs(
|
|
54
|
+
Comp,
|
|
55
|
+
{
|
|
56
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
57
|
+
ref,
|
|
58
|
+
...props,
|
|
59
|
+
children: [
|
|
60
|
+
isLoading ? /* @__PURE__ */ jsx(
|
|
61
|
+
Loader2,
|
|
62
|
+
{
|
|
63
|
+
className: cn("h-4 w-4 animate-spin", size !== "icon" && "mr-2")
|
|
64
|
+
}
|
|
65
|
+
) : null,
|
|
66
|
+
isLoading && size === "icon" ? null : children
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
Button.displayName = "Button";
|
|
73
|
+
var Tooltip = TooltipPrimitive.Root;
|
|
74
|
+
var TooltipTrigger = TooltipPrimitive.Trigger;
|
|
75
|
+
var TooltipContent = /* @__PURE__ */ __name(({
|
|
76
|
+
className,
|
|
77
|
+
sideOffset = 4,
|
|
78
|
+
showArrow = true,
|
|
79
|
+
...props
|
|
80
|
+
}) => /* @__PURE__ */ jsxs(
|
|
81
|
+
TooltipPrimitive.Content,
|
|
82
|
+
{
|
|
83
|
+
className: cn(
|
|
84
|
+
"border-divider bg-bg-dark animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-w-[280px] rounded-lg border px-3 py-1.5 text-xs text-white",
|
|
85
|
+
className
|
|
86
|
+
),
|
|
87
|
+
sideOffset,
|
|
88
|
+
...props,
|
|
89
|
+
children: [
|
|
90
|
+
props.children,
|
|
91
|
+
showArrow && /* @__PURE__ */ jsx(TooltipPrimitive.Arrow, { className: "fill-bg-dark -my-px drop-shadow-[0_1px_0_#313336]" })
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
), "TooltipContent");
|
|
95
|
+
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
|
|
96
|
+
mermaid.initialize({
|
|
97
|
+
startOnLoad: true,
|
|
98
|
+
mindmap: {
|
|
99
|
+
useWidth: 800
|
|
100
|
+
},
|
|
101
|
+
theme: "dark",
|
|
102
|
+
fontSize: 18,
|
|
103
|
+
darkMode: true,
|
|
104
|
+
fontFamily: "Inter"
|
|
105
|
+
});
|
|
106
|
+
var generateId = /* @__PURE__ */ __name(() => `mermaid-${Math.random().toString(36).slice(2)}`, "generateId");
|
|
107
|
+
var downloadBlob = /* @__PURE__ */ __name(async (blob, filename) => {
|
|
108
|
+
try {
|
|
109
|
+
const link = document.createElement("a");
|
|
110
|
+
link.href = URL.createObjectURL(blob);
|
|
111
|
+
link.download = filename;
|
|
112
|
+
document.body.appendChild(link);
|
|
113
|
+
link.click();
|
|
114
|
+
document.body.removeChild(link);
|
|
115
|
+
URL.revokeObjectURL(link.href);
|
|
116
|
+
toast.success("Mermaid diagram saved successfully");
|
|
117
|
+
} catch (error) {
|
|
118
|
+
toast.error("Failed to download diagram");
|
|
119
|
+
}
|
|
120
|
+
}, "downloadBlob");
|
|
121
|
+
var MermaidDiagram = /* @__PURE__ */ __name(({
|
|
122
|
+
code,
|
|
123
|
+
className,
|
|
124
|
+
isRunning
|
|
125
|
+
}) => {
|
|
126
|
+
const ref = useRef(null);
|
|
127
|
+
const lastCode = useRef(null);
|
|
128
|
+
const [instance, setInstance] = useState(null);
|
|
129
|
+
const isComplete = !isRunning;
|
|
130
|
+
const resetZoom = useCallback(() => {
|
|
131
|
+
instance?.fit();
|
|
132
|
+
instance?.center();
|
|
133
|
+
}, [instance]);
|
|
134
|
+
const downloadSVG = useCallback(() => {
|
|
135
|
+
if (ref.current) {
|
|
136
|
+
const svg = ref.current.innerHTML;
|
|
137
|
+
const blob = new Blob([svg], { type: "image/svg+xml" });
|
|
138
|
+
void downloadBlob(blob, "mermaid-diagram.svg");
|
|
139
|
+
}
|
|
140
|
+
}, []);
|
|
141
|
+
const enableZoom = useCallback(() => {
|
|
142
|
+
instance?.enablePan();
|
|
143
|
+
instance?.enableZoom();
|
|
144
|
+
}, [instance]);
|
|
145
|
+
const disableZoom = useCallback(() => {
|
|
146
|
+
instance?.disablePan();
|
|
147
|
+
instance?.disableZoom();
|
|
148
|
+
}, [instance]);
|
|
149
|
+
const handleFocus = useCallback(() => {
|
|
150
|
+
enableZoom();
|
|
151
|
+
}, [enableZoom]);
|
|
152
|
+
const handleBlur = useCallback(() => {
|
|
153
|
+
disableZoom();
|
|
154
|
+
}, [disableZoom]);
|
|
155
|
+
const handleClick = useCallback(() => {
|
|
156
|
+
if (ref.current) {
|
|
157
|
+
ref.current.focus();
|
|
158
|
+
}
|
|
159
|
+
}, []);
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
if (!isComplete || !ref.current || !code) return;
|
|
162
|
+
if (lastCode.current === code) return;
|
|
163
|
+
void (async () => {
|
|
164
|
+
try {
|
|
165
|
+
const id = generateId();
|
|
166
|
+
const { svg } = await mermaid.render(id, code);
|
|
167
|
+
if (ref.current) {
|
|
168
|
+
ref.current.innerHTML = svg;
|
|
169
|
+
const svgElement = ref.current.querySelector("svg");
|
|
170
|
+
if (svgElement) {
|
|
171
|
+
svgElement.setAttribute("height", "100%");
|
|
172
|
+
svgElement.setAttribute("width", "100%");
|
|
173
|
+
svgElement.style.height = "100%";
|
|
174
|
+
svgElement.style.width = "100%";
|
|
175
|
+
svgElement.style.position = "absolute";
|
|
176
|
+
svgElement.style.top = "0";
|
|
177
|
+
svgElement.style.left = "0";
|
|
178
|
+
const panZoomInstance = svgPanZoom(svgElement);
|
|
179
|
+
panZoomInstance.fit();
|
|
180
|
+
panZoomInstance.center();
|
|
181
|
+
panZoomInstance.zoomAtPoint(1, { x: 0, y: 0 });
|
|
182
|
+
panZoomInstance.disablePan();
|
|
183
|
+
panZoomInstance.disableZoom();
|
|
184
|
+
setInstance(panZoomInstance);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
lastCode.current = code;
|
|
188
|
+
} catch (e) {
|
|
189
|
+
console.warn("Failed to render Mermaid diagram:", e);
|
|
190
|
+
}
|
|
191
|
+
})();
|
|
192
|
+
}, [code, isComplete]);
|
|
193
|
+
return /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
194
|
+
/* @__PURE__ */ jsxs("div", { className: "absolute top-2 right-2 z-10 flex gap-1", children: [
|
|
195
|
+
/* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
196
|
+
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
197
|
+
Button,
|
|
198
|
+
{
|
|
199
|
+
variant: "ghost",
|
|
200
|
+
size: "icon",
|
|
201
|
+
onClick: resetZoom,
|
|
202
|
+
className: "text-text-secondary",
|
|
203
|
+
children: /* @__PURE__ */ jsx(RotateCcw, { size: 14 })
|
|
204
|
+
}
|
|
205
|
+
) }),
|
|
206
|
+
/* @__PURE__ */ jsx(TooltipContent, { children: /* @__PURE__ */ jsx("p", { children: "Reset Zoom" }) })
|
|
207
|
+
] }),
|
|
208
|
+
/* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
209
|
+
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
210
|
+
Button,
|
|
211
|
+
{
|
|
212
|
+
variant: "ghost",
|
|
213
|
+
size: "icon",
|
|
214
|
+
onClick: downloadSVG,
|
|
215
|
+
className: "text-text-secondary",
|
|
216
|
+
children: /* @__PURE__ */ jsx(Download, { size: 14 })
|
|
217
|
+
}
|
|
218
|
+
) }),
|
|
219
|
+
/* @__PURE__ */ jsx(TooltipContent, { children: /* @__PURE__ */ jsx("p", { children: "Download SVG" }) })
|
|
220
|
+
] })
|
|
221
|
+
] }),
|
|
222
|
+
/* @__PURE__ */ jsx(
|
|
223
|
+
"div",
|
|
224
|
+
{
|
|
225
|
+
onClick: handleClick,
|
|
226
|
+
className: "text-text-secondary bg-bg-quaternary absolute right-2 bottom-2 z-10 rounded px-2 py-1 text-xs",
|
|
227
|
+
children: "Click to focus, then scroll to zoom & drag to pan"
|
|
228
|
+
}
|
|
229
|
+
),
|
|
230
|
+
/* @__PURE__ */ jsx(
|
|
231
|
+
"div",
|
|
232
|
+
{
|
|
233
|
+
ref,
|
|
234
|
+
tabIndex: 0,
|
|
235
|
+
onFocus: handleFocus,
|
|
236
|
+
onBlur: handleBlur,
|
|
237
|
+
onClick: handleClick,
|
|
238
|
+
className: cn(
|
|
239
|
+
"text-text-secondary bg-bg-quaternary focus:ring-opacity-50 relative w-full cursor-grab overflow-hidden rounded-b-lg p-4 py-10 text-center text-sm focus:cursor-grabbing focus:ring-2 focus:ring-blue-500 focus:outline-none",
|
|
240
|
+
className
|
|
241
|
+
),
|
|
242
|
+
style: { width: "100%", minHeight: "400px" },
|
|
243
|
+
children: "Drawing diagram..."
|
|
244
|
+
}
|
|
245
|
+
)
|
|
246
|
+
] });
|
|
247
|
+
}, "MermaidDiagram");
|
|
248
|
+
|
|
249
|
+
export { MermaidDiagram };
|
package/dist/primitives/index.js
CHANGED