@hanzo/ui 5.3.35 → 5.3.36
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/bin/create-registry.js +0 -0
- package/bin/npx-registry-mcp.js +0 -0
- package/bin/registry-mcp-wrapper.sh +0 -0
- package/bin/registry-mcp.js +0 -0
- package/bin/start-mcp-server.sh +0 -0
- package/bin/test-mcp.sh +0 -0
- package/dist/3d/button.js +1 -297
- package/dist/3d/button.mjs +1 -272
- package/dist/3d/card.js +1 -233
- package/dist/3d/card.mjs +1 -206
- package/dist/3d/carousel.js +1 -370
- package/dist/3d/carousel.mjs +1 -343
- package/dist/3d/grid.js +1 -361
- package/dist/3d/grid.mjs +1 -336
- package/dist/3d/index.js +1 -1517
- package/dist/3d/index.mjs +1 -1471
- package/dist/3d/marquee.js +1 -351
- package/dist/3d/marquee.mjs +1 -326
- package/dist/3d/pin.js +1 -45
- package/dist/3d/pin.mjs +1 -23
- package/dist/accordion.js +1 -79
- package/dist/accordion.mjs +1 -54
- package/dist/alert-dialog.js +1 -224
- package/dist/alert-dialog.mjs +1 -191
- package/dist/alert.js +1 -97
- package/dist/alert.mjs +1 -91
- package/dist/animation/animated-background.js +1 -423
- package/dist/animation/animated-background.mjs +1 -417
- package/dist/animation/animated-beam.js +1 -118
- package/dist/animation/animated-beam.mjs +1 -96
- package/dist/animation/animated-cursor.js +1 -274
- package/dist/animation/animated-cursor.mjs +1 -269
- package/dist/animation/animated-icon.js +2 -356
- package/dist/animation/animated-icon.mjs +2 -350
- package/dist/animation/animated-list.js +1 -338
- package/dist/animation/animated-list.mjs +1 -332
- package/dist/animation/animated-number.js +1 -282
- package/dist/animation/animated-number.mjs +1 -276
- package/dist/animation/animated-testimonials.js +1 -96
- package/dist/animation/animated-testimonials.mjs +1 -74
- package/dist/animation/animated-tooltip.js +1 -66
- package/dist/animation/animated-tooltip.mjs +1 -44
- package/dist/animation/apple-cards-carousel.js +1 -307
- package/dist/animation/apple-cards-carousel.mjs +1 -284
- package/dist/animation/apple-hello-effect.js +1 -59
- package/dist/animation/apple-hello-effect.mjs +1 -37
- package/dist/animation/index.js +2 -1951
- package/dist/animation/index.mjs +2 -1920
- package/dist/avatar.js +1 -70
- package/dist/avatar.mjs +1 -46
- package/dist/badge.js +1 -60
- package/dist/badge.mjs +1 -54
- package/dist/blocks/index.js +2 -1684
- package/dist/blocks/index.mjs +2 -1645
- package/dist/breadcrumb.js +1 -106
- package/dist/breadcrumb.mjs +1 -98
- package/dist/calendar-ext/index.js +1 -207
- package/dist/calendar-ext/index.mjs +1 -169
- package/dist/calendar.js +1 -193
- package/dist/calendar.mjs +1 -168
- package/dist/carousel.js +1 -282
- package/dist/carousel.mjs +1 -253
- package/dist/charts/index.js +6 -5840
- package/dist/charts/index.mjs +6 -5749
- package/dist/checkbox.js +1 -59
- package/dist/checkbox.mjs +1 -34
- package/dist/code/block.js +2 -225
- package/dist/code/block.mjs +2 -202
- package/dist/code/compare.js +5 -444
- package/dist/code/compare.mjs +5 -421
- package/dist/code/diff.js +12 -429
- package/dist/code/diff.mjs +11 -405
- package/dist/code/editor.js +1 -242
- package/dist/code/editor.mjs +1 -217
- package/dist/code/explorer.js +1 -290
- package/dist/code/explorer.mjs +1 -267
- package/dist/code/index.js +26 -2514
- package/dist/code/index.mjs +24 -2471
- package/dist/code/preview.js +6 -363
- package/dist/code/preview.mjs +6 -340
- package/dist/code/snippet.js +2 -273
- package/dist/code/snippet.mjs +2 -249
- package/dist/code/tabs.js +1 -74
- package/dist/code/tabs.mjs +1 -52
- package/dist/code/terminal.js +3 -436
- package/dist/code/terminal.mjs +3 -413
- package/dist/collapsible.js +1 -32
- package/dist/collapsible.mjs +1 -8
- package/dist/command.js +1 -282
- package/dist/command.mjs +1 -251
- package/dist/context-menu.js +1 -206
- package/dist/context-menu.mjs +1 -170
- package/dist/desktop/hooks.js +1 -223
- package/dist/desktop/hooks.mjs +1 -198
- package/dist/desktop/index.js +1 -685
- package/dist/desktop/index.mjs +1 -657
- package/dist/desktop/spotlight.js +1 -260
- package/dist/desktop/spotlight.mjs +1 -235
- package/dist/desktop/window.js +1 -273
- package/dist/desktop/window.mjs +1 -247
- package/dist/device/index.js +1 -2
- package/dist/device/index.mjs +0 -1
- package/dist/dialog.js +1 -245
- package/dist/dialog.mjs +1 -213
- package/dist/dock/basic.js +1 -173
- package/dist/dock/basic.mjs +1 -150
- package/dist/dock/index.js +1 -647
- package/dist/dock/index.mjs +1 -620
- package/dist/dock/limelight-nav.js +1 -314
- package/dist/dock/limelight-nav.mjs +1 -293
- package/dist/dock/macos.js +1 -140
- package/dist/dock/macos.mjs +1 -117
- package/dist/dock/menu.js +1 -69
- package/dist/dock/menu.mjs +1 -47
- package/dist/dock/message.js +1 -148
- package/dist/dock/message.mjs +1 -126
- package/dist/drawer.js +1 -114
- package/dist/drawer.mjs +1 -102
- package/dist/dropdown-menu.js +1 -201
- package/dist/dropdown-menu.mjs +1 -165
- package/dist/finance/AdvancedChart.js +2 -47
- package/dist/finance/AdvancedChart.mjs +2 -45
- package/dist/finance/CompanyProfile.js +2 -47
- package/dist/finance/CompanyProfile.mjs +2 -45
- package/dist/finance/CryptoScreener.js +2 -44
- package/dist/finance/CryptoScreener.mjs +2 -42
- package/dist/finance/Financials.js +2 -51
- package/dist/finance/Financials.mjs +2 -49
- package/dist/finance/ForexScreener.js +2 -45
- package/dist/finance/ForexScreener.mjs +2 -43
- package/dist/finance/MarketOverview.js +2 -103
- package/dist/finance/MarketOverview.mjs +2 -101
- package/dist/finance/NewsTimeline.js +2 -43
- package/dist/finance/NewsTimeline.mjs +2 -41
- package/dist/finance/OrderEntry.js +1 -130
- package/dist/finance/OrderEntry.mjs +1 -128
- package/dist/finance/OrdersHistory.js +1 -63
- package/dist/finance/OrdersHistory.mjs +1 -61
- package/dist/finance/PositionsList.js +1 -79
- package/dist/finance/PositionsList.mjs +1 -77
- package/dist/finance/StockScreener.js +2 -45
- package/dist/finance/StockScreener.mjs +2 -43
- package/dist/finance/SymbolInfo.js +2 -45
- package/dist/finance/SymbolInfo.mjs +2 -43
- package/dist/finance/TechnicalAnalysis.js +2 -53
- package/dist/finance/TechnicalAnalysis.mjs +2 -51
- package/dist/finance/TickerTape.js +2 -55
- package/dist/finance/TickerTape.mjs +2 -53
- package/dist/finance/TradingPanel.js +1 -190
- package/dist/finance/TradingPanel.mjs +1 -188
- package/dist/finance/index.js +2 -929
- package/dist/finance/index.mjs +2 -913
- package/dist/form/index.js +1 -153
- package/dist/form/index.mjs +1 -123
- package/dist/form.js +1 -171
- package/dist/form.mjs +1 -141
- package/dist/hover-card.js +1 -57
- package/dist/hover-card.mjs +1 -33
- package/dist/index.js +192 -9618
- package/dist/index.mjs +192 -9202
- package/dist/input-otp.js +1 -78
- package/dist/input-otp.mjs +1 -53
- package/dist/kanban/index.js +1 -593
- package/dist/kanban/index.mjs +1 -571
- package/dist/lib/utils.js +1 -28
- package/dist/lib/utils.mjs +1 -24
- package/dist/mermaid/index.js +1 -280
- package/dist/mermaid/index.mjs +1 -253
- package/dist/navigation/index.js +1 -97
- package/dist/navigation/index.mjs +1 -78
- package/dist/navigation-menu.js +1 -148
- package/dist/navigation-menu.mjs +1 -115
- package/dist/pattern/grid-pattern.js +3 -325
- package/dist/pattern/grid-pattern.mjs +3 -302
- package/dist/pattern/index.js +3 -325
- package/dist/pattern/index.mjs +3 -302
- package/dist/popover.js +1 -62
- package/dist/popover.mjs +1 -36
- package/dist/progress.js +1 -61
- package/dist/progress.mjs +1 -36
- package/dist/project/gantt.js +1 -64
- package/dist/project/gantt.mjs +1 -42
- package/dist/project/index.js +1 -635
- package/dist/project/index.mjs +1 -610
- package/dist/project/kanban.js +1 -596
- package/dist/project/kanban.mjs +1 -571
- package/dist/project/list.js +1 -34
- package/dist/project/list.mjs +1 -11
- package/dist/radio-group.js +1 -67
- package/dist/radio-group.mjs +1 -44
- package/dist/resizable.js +1 -71
- package/dist/resizable.mjs +1 -47
- package/dist/scroll-area.js +1 -88
- package/dist/scroll-area.mjs +1 -65
- package/dist/select.js +1 -139
- package/dist/select.mjs +1 -110
- package/dist/separator.js +1 -58
- package/dist/separator.mjs +1 -33
- package/dist/sheet.js +1 -147
- package/dist/sheet.mjs +1 -116
- package/dist/skeleton.js +1 -31
- package/dist/skeleton.mjs +1 -26
- package/dist/slider.js +1 -98
- package/dist/slider.mjs +1 -72
- package/dist/sonner.js +1 -33
- package/dist/sonner.mjs +1 -28
- package/dist/spline/index.js +1 -210
- package/dist/spline/index.mjs +1 -201
- package/dist/spline/media-stack.js +1 -192
- package/dist/spline/media-stack.mjs +1 -184
- package/dist/spline/player.js +1 -36
- package/dist/spline/player.mjs +1 -30
- package/dist/switch.js +1 -61
- package/dist/switch.mjs +1 -36
- package/dist/table.js +1 -109
- package/dist/table.mjs +1 -100
- package/dist/tabs.js +1 -127
- package/dist/tabs.mjs +1 -101
- package/dist/tailwind/index.mjs +1 -2011
- package/dist/textarea.js +1 -77
- package/dist/textarea.mjs +1 -55
- package/dist/toggle-group.js +1 -117
- package/dist/toggle-group.mjs +1 -92
- package/dist/toggle.js +1 -70
- package/dist/toggle.mjs +1 -47
- package/dist/tooltip.js +1 -66
- package/dist/tooltip.mjs +1 -39
- package/dist/types/index.mjs +1 -51
- package/dist/ui/announcement.js +1 -133
- package/dist/ui/announcement.mjs +1 -111
- package/dist/ui/avatar-group.js +1 -87
- package/dist/ui/avatar-group.mjs +1 -64
- package/dist/ui/banner.js +1 -84
- package/dist/ui/banner.mjs +1 -61
- package/dist/ui/cursor.js +1 -77
- package/dist/ui/cursor.mjs +1 -55
- package/dist/ui/index.js +1 -494
- package/dist/ui/index.mjs +1 -461
- package/dist/ui/marquee.js +1 -73
- package/dist/ui/marquee.mjs +1 -51
- package/dist/ui/pill.js +1 -84
- package/dist/ui/pill.mjs +1 -61
- package/dist/ui/spinner.js +1 -27
- package/dist/ui/spinner.mjs +1 -25
- package/dist/ui/tags.js +1 -116
- package/dist/ui/tags.mjs +1 -94
- package/dist/ui/ticker.js +1 -72
- package/dist/ui/ticker.mjs +1 -50
- package/dist/util/index.mjs +1 -404
- package/package.json +28 -27
- package/dist/primitives/index.js +0 -9619
- package/dist/primitives/index.mjs +0 -9203
- package/dist/primitives-export.js +0 -9619
- package/dist/primitives-export.mjs +0 -9203
package/dist/mermaid/index.js
CHANGED
|
@@ -1,281 +1,2 @@
|
|
|
1
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-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*="size-"])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive',
|
|
49
|
-
{
|
|
50
|
-
variants: {
|
|
51
|
-
variant: {
|
|
52
|
-
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
53
|
-
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
54
|
-
outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
55
|
-
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
56
|
-
ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
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 has-[>svg]:px-3",
|
|
65
|
-
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
66
|
-
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
67
|
-
icon: "size-9",
|
|
68
|
-
"icon-sm": "size-8",
|
|
69
|
-
"icon-lg": "size-10"
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
defaultVariants: {
|
|
73
|
-
variant: "default",
|
|
74
|
-
size: "default"
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
);
|
|
78
|
-
var Button = React__namespace.forwardRef(
|
|
79
|
-
({ className, variant = "default", size = "default", asChild = false, isLoading = false, children, ...props }, ref) => {
|
|
80
|
-
const Comp = asChild ? reactSlot.Slot : "button";
|
|
81
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
82
|
-
Comp,
|
|
83
|
-
{
|
|
84
|
-
"data-slot": "button",
|
|
85
|
-
"data-variant": variant,
|
|
86
|
-
"data-size": size,
|
|
87
|
-
className: cn(buttonVariants({ variant, size, className })),
|
|
88
|
-
ref,
|
|
89
|
-
...props,
|
|
90
|
-
children: [
|
|
91
|
-
isLoading ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
92
|
-
lucideReact.Loader2,
|
|
93
|
-
{
|
|
94
|
-
className: cn("h-4 w-4 animate-spin", size !== "icon" && size !== "icon-sm" && size !== "icon-lg" && "mr-2")
|
|
95
|
-
}
|
|
96
|
-
) : null,
|
|
97
|
-
isLoading && (size === "icon" || size === "icon-sm" || size === "icon-lg") ? null : children
|
|
98
|
-
]
|
|
99
|
-
}
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
);
|
|
103
|
-
Button.displayName = "Button";
|
|
104
|
-
var Tooltip = TooltipPrimitive__namespace.Root;
|
|
105
|
-
var TooltipTrigger = TooltipPrimitive__namespace.Trigger;
|
|
106
|
-
var TooltipContent = /* @__PURE__ */ __name(({
|
|
107
|
-
className,
|
|
108
|
-
sideOffset = 4,
|
|
109
|
-
showArrow = true,
|
|
110
|
-
...props
|
|
111
|
-
}) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
112
|
-
TooltipPrimitive__namespace.Content,
|
|
113
|
-
{
|
|
114
|
-
className: cn(
|
|
115
|
-
"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",
|
|
116
|
-
className
|
|
117
|
-
),
|
|
118
|
-
sideOffset,
|
|
119
|
-
...props,
|
|
120
|
-
children: [
|
|
121
|
-
props.children,
|
|
122
|
-
showArrow && /* @__PURE__ */ jsxRuntime.jsx(TooltipPrimitive__namespace.Arrow, { className: "fill-bg-dark -my-px drop-shadow-[0_1px_0_#313336]" })
|
|
123
|
-
]
|
|
124
|
-
}
|
|
125
|
-
), "TooltipContent");
|
|
126
|
-
TooltipContent.displayName = TooltipPrimitive__namespace.Content.displayName;
|
|
127
|
-
mermaid__default.default.initialize({
|
|
128
|
-
startOnLoad: true,
|
|
129
|
-
mindmap: {
|
|
130
|
-
useWidth: 800
|
|
131
|
-
},
|
|
132
|
-
theme: "dark",
|
|
133
|
-
fontSize: 18,
|
|
134
|
-
darkMode: true,
|
|
135
|
-
fontFamily: "Inter"
|
|
136
|
-
});
|
|
137
|
-
var generateId = /* @__PURE__ */ __name(() => `mermaid-${Math.random().toString(36).slice(2)}`, "generateId");
|
|
138
|
-
var downloadBlob = /* @__PURE__ */ __name(async (blob, filename) => {
|
|
139
|
-
try {
|
|
140
|
-
const link = document.createElement("a");
|
|
141
|
-
link.href = URL.createObjectURL(blob);
|
|
142
|
-
link.download = filename;
|
|
143
|
-
document.body.appendChild(link);
|
|
144
|
-
link.click();
|
|
145
|
-
document.body.removeChild(link);
|
|
146
|
-
URL.revokeObjectURL(link.href);
|
|
147
|
-
sonner.toast.success("Mermaid diagram saved successfully");
|
|
148
|
-
} catch (error) {
|
|
149
|
-
sonner.toast.error("Failed to download diagram");
|
|
150
|
-
}
|
|
151
|
-
}, "downloadBlob");
|
|
152
|
-
var MermaidDiagram = /* @__PURE__ */ __name(({
|
|
153
|
-
code,
|
|
154
|
-
className,
|
|
155
|
-
isRunning
|
|
156
|
-
}) => {
|
|
157
|
-
const ref = React.useRef(null);
|
|
158
|
-
const lastCode = React.useRef(null);
|
|
159
|
-
const [instance, setInstance] = React.useState(null);
|
|
160
|
-
const isComplete = !isRunning;
|
|
161
|
-
const resetZoom = React.useCallback(() => {
|
|
162
|
-
instance?.fit();
|
|
163
|
-
instance?.center();
|
|
164
|
-
}, [instance]);
|
|
165
|
-
const downloadSVG = React.useCallback(() => {
|
|
166
|
-
if (ref.current) {
|
|
167
|
-
const svg = ref.current.innerHTML;
|
|
168
|
-
const blob = new Blob([svg], { type: "image/svg+xml" });
|
|
169
|
-
void downloadBlob(blob, "mermaid-diagram.svg");
|
|
170
|
-
}
|
|
171
|
-
}, []);
|
|
172
|
-
const enableZoom = React.useCallback(() => {
|
|
173
|
-
instance?.enablePan();
|
|
174
|
-
instance?.enableZoom();
|
|
175
|
-
}, [instance]);
|
|
176
|
-
const disableZoom = React.useCallback(() => {
|
|
177
|
-
instance?.disablePan();
|
|
178
|
-
instance?.disableZoom();
|
|
179
|
-
}, [instance]);
|
|
180
|
-
const handleFocus = React.useCallback(() => {
|
|
181
|
-
enableZoom();
|
|
182
|
-
}, [enableZoom]);
|
|
183
|
-
const handleBlur = React.useCallback(() => {
|
|
184
|
-
disableZoom();
|
|
185
|
-
}, [disableZoom]);
|
|
186
|
-
const handleClick = React.useCallback(() => {
|
|
187
|
-
if (ref.current) {
|
|
188
|
-
ref.current.focus();
|
|
189
|
-
}
|
|
190
|
-
}, []);
|
|
191
|
-
React.useEffect(() => {
|
|
192
|
-
if (!isComplete || !ref.current || !code) return;
|
|
193
|
-
if (lastCode.current === code) return;
|
|
194
|
-
void (async () => {
|
|
195
|
-
try {
|
|
196
|
-
const id = generateId();
|
|
197
|
-
const { svg } = await mermaid__default.default.render(id, code);
|
|
198
|
-
if (ref.current) {
|
|
199
|
-
ref.current.innerHTML = svg;
|
|
200
|
-
const svgElement = ref.current.querySelector("svg");
|
|
201
|
-
if (svgElement) {
|
|
202
|
-
svgElement.setAttribute("height", "100%");
|
|
203
|
-
svgElement.setAttribute("width", "100%");
|
|
204
|
-
svgElement.style.height = "100%";
|
|
205
|
-
svgElement.style.width = "100%";
|
|
206
|
-
svgElement.style.position = "absolute";
|
|
207
|
-
svgElement.style.top = "0";
|
|
208
|
-
svgElement.style.left = "0";
|
|
209
|
-
const panZoomInstance = svgPanZoom__default.default(svgElement);
|
|
210
|
-
panZoomInstance.fit();
|
|
211
|
-
panZoomInstance.center();
|
|
212
|
-
panZoomInstance.zoomAtPoint(1, { x: 0, y: 0 });
|
|
213
|
-
panZoomInstance.disablePan();
|
|
214
|
-
panZoomInstance.disableZoom();
|
|
215
|
-
setInstance(panZoomInstance);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
lastCode.current = code;
|
|
219
|
-
} catch (e) {
|
|
220
|
-
console.warn("Failed to render Mermaid diagram:", e);
|
|
221
|
-
}
|
|
222
|
-
})();
|
|
223
|
-
}, [code, isComplete]);
|
|
224
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
|
|
225
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "absolute top-2 right-2 z-10 flex gap-1", children: [
|
|
226
|
-
/* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
|
|
227
|
-
/* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
228
|
-
Button,
|
|
229
|
-
{
|
|
230
|
-
variant: "ghost",
|
|
231
|
-
size: "icon",
|
|
232
|
-
onClick: resetZoom,
|
|
233
|
-
className: "text-text-secondary",
|
|
234
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.RotateCcw, { size: 14 })
|
|
235
|
-
}
|
|
236
|
-
) }),
|
|
237
|
-
/* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Reset Zoom" }) })
|
|
238
|
-
] }),
|
|
239
|
-
/* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
|
|
240
|
-
/* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
241
|
-
Button,
|
|
242
|
-
{
|
|
243
|
-
variant: "ghost",
|
|
244
|
-
size: "icon",
|
|
245
|
-
onClick: downloadSVG,
|
|
246
|
-
className: "text-text-secondary",
|
|
247
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Download, { size: 14 })
|
|
248
|
-
}
|
|
249
|
-
) }),
|
|
250
|
-
/* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Download SVG" }) })
|
|
251
|
-
] })
|
|
252
|
-
] }),
|
|
253
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
254
|
-
"div",
|
|
255
|
-
{
|
|
256
|
-
onClick: handleClick,
|
|
257
|
-
className: "text-text-secondary bg-bg-quaternary absolute right-2 bottom-2 z-10 rounded px-2 py-1 text-xs",
|
|
258
|
-
children: "Click to focus, then scroll to zoom & drag to pan"
|
|
259
|
-
}
|
|
260
|
-
),
|
|
261
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
262
|
-
"div",
|
|
263
|
-
{
|
|
264
|
-
ref,
|
|
265
|
-
tabIndex: 0,
|
|
266
|
-
onFocus: handleFocus,
|
|
267
|
-
onBlur: handleBlur,
|
|
268
|
-
onClick: handleClick,
|
|
269
|
-
className: cn(
|
|
270
|
-
"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",
|
|
271
|
-
className
|
|
272
|
-
),
|
|
273
|
-
style: { width: "100%", minHeight: "400px" },
|
|
274
|
-
children: "Drawing diagram..."
|
|
275
|
-
}
|
|
276
|
-
)
|
|
277
|
-
] });
|
|
278
|
-
}, "MermaidDiagram");
|
|
279
|
-
|
|
280
|
-
exports.Mermaid = MermaidDiagram;
|
|
281
|
-
exports.MermaidDiagram = MermaidDiagram;
|
|
2
|
+
'use strict';var lucideReact=require('lucide-react'),L=require('mermaid'),M=require('react'),sonner=require('sonner'),j=require('svg-pan-zoom'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),reactSlot=require('@radix-ui/react-slot'),classVarianceAuthority=require('class-variance-authority'),jsxRuntime=require('react/jsx-runtime'),r=require('@radix-ui/react-tooltip');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var L__default=/*#__PURE__*/_interopDefault(L);var M__namespace=/*#__PURE__*/_interopNamespace(M);var j__default=/*#__PURE__*/_interopDefault(j);var r__namespace=/*#__PURE__*/_interopNamespace(r);var A=Object.defineProperty;var l=(e,a)=>A(e,"name",{value:a,configurable:true});function d(...e){return tailwindMerge.twMerge(clsx.clsx(e))}l(d,"cn");var U=classVarianceAuthority.cva('inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*="size-"])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive',{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline",primary:"bg-primary text-primary-foreground shadow hover:bg-primary/90",linkFG:"text-primary underline-offset-4 hover:underline",linkMuted:"text-muted-foreground underline-offset-4 hover:underline hover:text-foreground"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9","icon-sm":"size-8","icon-lg":"size-10"}},defaultVariants:{variant:"default",size:"default"}}),f=M__namespace.forwardRef(({className:e,variant:a="default",size:t="default",asChild:o=false,isLoading:p=false,children:n,...h},g)=>jsxRuntime.jsxs(o?reactSlot.Slot:"button",{"data-slot":"button","data-variant":a,"data-size":t,className:d(U({variant:a,size:t,className:e})),ref:g,...h,children:[p?jsxRuntime.jsx(lucideReact.Loader2,{className:d("h-4 w-4 animate-spin",t!=="icon"&&t!=="icon-sm"&&t!=="icon-lg"&&"mr-2")}):null,p&&(t==="icon"||t==="icon-sm"||t==="icon-lg")?null:n]}));f.displayName="Button";var y=r__namespace.Root,T=r__namespace.Trigger;var v=l(({className:e,sideOffset:a=4,showArrow:t=true,...o})=>jsxRuntime.jsxs(r__namespace.Content,{className:d("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",e),sideOffset:a,...o,children:[o.children,t&&jsxRuntime.jsx(r__namespace.Arrow,{className:"fill-bg-dark -my-px drop-shadow-[0_1px_0_#313336]"})]}),"TooltipContent");v.displayName=r__namespace.Content.displayName;L__default.default.initialize({startOnLoad:true,mindmap:{useWidth:800},theme:"dark",fontSize:18,darkMode:true,fontFamily:"Inter"});var J=l(()=>`mermaid-${Math.random().toString(36).slice(2)}`,"generateId"),K=l(async(e,a)=>{try{let t=document.createElement("a");t.href=URL.createObjectURL(e),t.download=a,document.body.appendChild(t),t.click(),document.body.removeChild(t),URL.revokeObjectURL(t.href),sonner.toast.success("Mermaid diagram saved successfully");}catch{sonner.toast.error("Failed to download diagram");}},"downloadBlob"),N=l(({code:e,className:a,isRunning:t})=>{let o=M.useRef(null),p=M.useRef(null),[n,h]=M.useState(null),g=!t,w=M.useCallback(()=>{n?.fit(),n?.center();},[n]),z=M.useCallback(()=>{if(o.current){let u=o.current.innerHTML,x=new Blob([u],{type:"image/svg+xml"});K(x,"mermaid-diagram.svg");}},[]),P=M.useCallback(()=>{n?.enablePan(),n?.enableZoom();},[n]),C=M.useCallback(()=>{n?.disablePan(),n?.disableZoom();},[n]),D=M.useCallback(()=>{P();},[P]),S=M.useCallback(()=>{C();},[C]),k=M.useCallback(()=>{o.current&&o.current.focus();},[]);return M.useEffect(()=>{!g||!o.current||!e||p.current!==e&&(async()=>{try{let u=J(),{svg:x}=await L__default.default.render(u,e);if(o.current){o.current.innerHTML=x;let s=o.current.querySelector("svg");if(s){s.setAttribute("height","100%"),s.setAttribute("width","100%"),s.style.height="100%",s.style.width="100%",s.style.position="absolute",s.style.top="0",s.style.left="0";let m=j__default.default(s);m.fit(),m.center(),m.zoomAtPoint(1,{x:0,y:0}),m.disablePan(),m.disableZoom(),h(m);}}p.current=e;}catch(u){console.warn("Failed to render Mermaid diagram:",u);}})();},[e,g]),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsxs("div",{className:"absolute top-2 right-2 z-10 flex gap-1",children:[jsxRuntime.jsxs(y,{children:[jsxRuntime.jsx(T,{asChild:true,children:jsxRuntime.jsx(f,{variant:"ghost",size:"icon",onClick:w,className:"text-text-secondary",children:jsxRuntime.jsx(lucideReact.RotateCcw,{size:14})})}),jsxRuntime.jsx(v,{children:jsxRuntime.jsx("p",{children:"Reset Zoom"})})]}),jsxRuntime.jsxs(y,{children:[jsxRuntime.jsx(T,{asChild:true,children:jsxRuntime.jsx(f,{variant:"ghost",size:"icon",onClick:z,className:"text-text-secondary",children:jsxRuntime.jsx(lucideReact.Download,{size:14})})}),jsxRuntime.jsx(v,{children:jsxRuntime.jsx("p",{children:"Download SVG"})})]})]}),jsxRuntime.jsx("div",{onClick:k,className:"text-text-secondary bg-bg-quaternary absolute right-2 bottom-2 z-10 rounded px-2 py-1 text-xs",children:"Click to focus, then scroll to zoom & drag to pan"}),jsxRuntime.jsx("div",{ref:o,tabIndex:0,onFocus:D,onBlur:S,onClick:k,className:d("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",a),style:{width:"100%",minHeight:"400px"},children:"Drawing diagram..."})]})},"MermaidDiagram");exports.Mermaid=N;exports.MermaidDiagram=N;
|
package/dist/mermaid/index.mjs
CHANGED
|
@@ -1,254 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
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-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*="size-"])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive',
|
|
23
|
-
{
|
|
24
|
-
variants: {
|
|
25
|
-
variant: {
|
|
26
|
-
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
27
|
-
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
28
|
-
outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
29
|
-
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
30
|
-
ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
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 has-[>svg]:px-3",
|
|
39
|
-
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
40
|
-
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
41
|
-
icon: "size-9",
|
|
42
|
-
"icon-sm": "size-8",
|
|
43
|
-
"icon-lg": "size-10"
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
defaultVariants: {
|
|
47
|
-
variant: "default",
|
|
48
|
-
size: "default"
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
);
|
|
52
|
-
var Button = React.forwardRef(
|
|
53
|
-
({ className, variant = "default", size = "default", asChild = false, isLoading = false, children, ...props }, ref) => {
|
|
54
|
-
const Comp = asChild ? Slot : "button";
|
|
55
|
-
return /* @__PURE__ */ jsxs(
|
|
56
|
-
Comp,
|
|
57
|
-
{
|
|
58
|
-
"data-slot": "button",
|
|
59
|
-
"data-variant": variant,
|
|
60
|
-
"data-size": size,
|
|
61
|
-
className: cn(buttonVariants({ variant, size, className })),
|
|
62
|
-
ref,
|
|
63
|
-
...props,
|
|
64
|
-
children: [
|
|
65
|
-
isLoading ? /* @__PURE__ */ jsx(
|
|
66
|
-
Loader2,
|
|
67
|
-
{
|
|
68
|
-
className: cn("h-4 w-4 animate-spin", size !== "icon" && size !== "icon-sm" && size !== "icon-lg" && "mr-2")
|
|
69
|
-
}
|
|
70
|
-
) : null,
|
|
71
|
-
isLoading && (size === "icon" || size === "icon-sm" || size === "icon-lg") ? null : children
|
|
72
|
-
]
|
|
73
|
-
}
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
);
|
|
77
|
-
Button.displayName = "Button";
|
|
78
|
-
var Tooltip = TooltipPrimitive.Root;
|
|
79
|
-
var TooltipTrigger = TooltipPrimitive.Trigger;
|
|
80
|
-
var TooltipContent = /* @__PURE__ */ __name(({
|
|
81
|
-
className,
|
|
82
|
-
sideOffset = 4,
|
|
83
|
-
showArrow = true,
|
|
84
|
-
...props
|
|
85
|
-
}) => /* @__PURE__ */ jsxs(
|
|
86
|
-
TooltipPrimitive.Content,
|
|
87
|
-
{
|
|
88
|
-
className: cn(
|
|
89
|
-
"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",
|
|
90
|
-
className
|
|
91
|
-
),
|
|
92
|
-
sideOffset,
|
|
93
|
-
...props,
|
|
94
|
-
children: [
|
|
95
|
-
props.children,
|
|
96
|
-
showArrow && /* @__PURE__ */ jsx(TooltipPrimitive.Arrow, { className: "fill-bg-dark -my-px drop-shadow-[0_1px_0_#313336]" })
|
|
97
|
-
]
|
|
98
|
-
}
|
|
99
|
-
), "TooltipContent");
|
|
100
|
-
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
|
|
101
|
-
mermaid.initialize({
|
|
102
|
-
startOnLoad: true,
|
|
103
|
-
mindmap: {
|
|
104
|
-
useWidth: 800
|
|
105
|
-
},
|
|
106
|
-
theme: "dark",
|
|
107
|
-
fontSize: 18,
|
|
108
|
-
darkMode: true,
|
|
109
|
-
fontFamily: "Inter"
|
|
110
|
-
});
|
|
111
|
-
var generateId = /* @__PURE__ */ __name(() => `mermaid-${Math.random().toString(36).slice(2)}`, "generateId");
|
|
112
|
-
var downloadBlob = /* @__PURE__ */ __name(async (blob, filename) => {
|
|
113
|
-
try {
|
|
114
|
-
const link = document.createElement("a");
|
|
115
|
-
link.href = URL.createObjectURL(blob);
|
|
116
|
-
link.download = filename;
|
|
117
|
-
document.body.appendChild(link);
|
|
118
|
-
link.click();
|
|
119
|
-
document.body.removeChild(link);
|
|
120
|
-
URL.revokeObjectURL(link.href);
|
|
121
|
-
toast.success("Mermaid diagram saved successfully");
|
|
122
|
-
} catch (error) {
|
|
123
|
-
toast.error("Failed to download diagram");
|
|
124
|
-
}
|
|
125
|
-
}, "downloadBlob");
|
|
126
|
-
var MermaidDiagram = /* @__PURE__ */ __name(({
|
|
127
|
-
code,
|
|
128
|
-
className,
|
|
129
|
-
isRunning
|
|
130
|
-
}) => {
|
|
131
|
-
const ref = useRef(null);
|
|
132
|
-
const lastCode = useRef(null);
|
|
133
|
-
const [instance, setInstance] = useState(null);
|
|
134
|
-
const isComplete = !isRunning;
|
|
135
|
-
const resetZoom = useCallback(() => {
|
|
136
|
-
instance?.fit();
|
|
137
|
-
instance?.center();
|
|
138
|
-
}, [instance]);
|
|
139
|
-
const downloadSVG = useCallback(() => {
|
|
140
|
-
if (ref.current) {
|
|
141
|
-
const svg = ref.current.innerHTML;
|
|
142
|
-
const blob = new Blob([svg], { type: "image/svg+xml" });
|
|
143
|
-
void downloadBlob(blob, "mermaid-diagram.svg");
|
|
144
|
-
}
|
|
145
|
-
}, []);
|
|
146
|
-
const enableZoom = useCallback(() => {
|
|
147
|
-
instance?.enablePan();
|
|
148
|
-
instance?.enableZoom();
|
|
149
|
-
}, [instance]);
|
|
150
|
-
const disableZoom = useCallback(() => {
|
|
151
|
-
instance?.disablePan();
|
|
152
|
-
instance?.disableZoom();
|
|
153
|
-
}, [instance]);
|
|
154
|
-
const handleFocus = useCallback(() => {
|
|
155
|
-
enableZoom();
|
|
156
|
-
}, [enableZoom]);
|
|
157
|
-
const handleBlur = useCallback(() => {
|
|
158
|
-
disableZoom();
|
|
159
|
-
}, [disableZoom]);
|
|
160
|
-
const handleClick = useCallback(() => {
|
|
161
|
-
if (ref.current) {
|
|
162
|
-
ref.current.focus();
|
|
163
|
-
}
|
|
164
|
-
}, []);
|
|
165
|
-
useEffect(() => {
|
|
166
|
-
if (!isComplete || !ref.current || !code) return;
|
|
167
|
-
if (lastCode.current === code) return;
|
|
168
|
-
void (async () => {
|
|
169
|
-
try {
|
|
170
|
-
const id = generateId();
|
|
171
|
-
const { svg } = await mermaid.render(id, code);
|
|
172
|
-
if (ref.current) {
|
|
173
|
-
ref.current.innerHTML = svg;
|
|
174
|
-
const svgElement = ref.current.querySelector("svg");
|
|
175
|
-
if (svgElement) {
|
|
176
|
-
svgElement.setAttribute("height", "100%");
|
|
177
|
-
svgElement.setAttribute("width", "100%");
|
|
178
|
-
svgElement.style.height = "100%";
|
|
179
|
-
svgElement.style.width = "100%";
|
|
180
|
-
svgElement.style.position = "absolute";
|
|
181
|
-
svgElement.style.top = "0";
|
|
182
|
-
svgElement.style.left = "0";
|
|
183
|
-
const panZoomInstance = svgPanZoom(svgElement);
|
|
184
|
-
panZoomInstance.fit();
|
|
185
|
-
panZoomInstance.center();
|
|
186
|
-
panZoomInstance.zoomAtPoint(1, { x: 0, y: 0 });
|
|
187
|
-
panZoomInstance.disablePan();
|
|
188
|
-
panZoomInstance.disableZoom();
|
|
189
|
-
setInstance(panZoomInstance);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
lastCode.current = code;
|
|
193
|
-
} catch (e) {
|
|
194
|
-
console.warn("Failed to render Mermaid diagram:", e);
|
|
195
|
-
}
|
|
196
|
-
})();
|
|
197
|
-
}, [code, isComplete]);
|
|
198
|
-
return /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
199
|
-
/* @__PURE__ */ jsxs("div", { className: "absolute top-2 right-2 z-10 flex gap-1", children: [
|
|
200
|
-
/* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
201
|
-
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
202
|
-
Button,
|
|
203
|
-
{
|
|
204
|
-
variant: "ghost",
|
|
205
|
-
size: "icon",
|
|
206
|
-
onClick: resetZoom,
|
|
207
|
-
className: "text-text-secondary",
|
|
208
|
-
children: /* @__PURE__ */ jsx(RotateCcw, { size: 14 })
|
|
209
|
-
}
|
|
210
|
-
) }),
|
|
211
|
-
/* @__PURE__ */ jsx(TooltipContent, { children: /* @__PURE__ */ jsx("p", { children: "Reset Zoom" }) })
|
|
212
|
-
] }),
|
|
213
|
-
/* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
214
|
-
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
215
|
-
Button,
|
|
216
|
-
{
|
|
217
|
-
variant: "ghost",
|
|
218
|
-
size: "icon",
|
|
219
|
-
onClick: downloadSVG,
|
|
220
|
-
className: "text-text-secondary",
|
|
221
|
-
children: /* @__PURE__ */ jsx(Download, { size: 14 })
|
|
222
|
-
}
|
|
223
|
-
) }),
|
|
224
|
-
/* @__PURE__ */ jsx(TooltipContent, { children: /* @__PURE__ */ jsx("p", { children: "Download SVG" }) })
|
|
225
|
-
] })
|
|
226
|
-
] }),
|
|
227
|
-
/* @__PURE__ */ jsx(
|
|
228
|
-
"div",
|
|
229
|
-
{
|
|
230
|
-
onClick: handleClick,
|
|
231
|
-
className: "text-text-secondary bg-bg-quaternary absolute right-2 bottom-2 z-10 rounded px-2 py-1 text-xs",
|
|
232
|
-
children: "Click to focus, then scroll to zoom & drag to pan"
|
|
233
|
-
}
|
|
234
|
-
),
|
|
235
|
-
/* @__PURE__ */ jsx(
|
|
236
|
-
"div",
|
|
237
|
-
{
|
|
238
|
-
ref,
|
|
239
|
-
tabIndex: 0,
|
|
240
|
-
onFocus: handleFocus,
|
|
241
|
-
onBlur: handleBlur,
|
|
242
|
-
onClick: handleClick,
|
|
243
|
-
className: cn(
|
|
244
|
-
"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",
|
|
245
|
-
className
|
|
246
|
-
),
|
|
247
|
-
style: { width: "100%", minHeight: "400px" },
|
|
248
|
-
children: "Drawing diagram..."
|
|
249
|
-
}
|
|
250
|
-
)
|
|
251
|
-
] });
|
|
252
|
-
}, "MermaidDiagram");
|
|
253
|
-
|
|
254
|
-
export { MermaidDiagram as Mermaid, MermaidDiagram };
|
|
2
|
+
import {Loader2,RotateCcw,Download}from'lucide-react';import L from'mermaid';import*as M from'react';import {useRef,useState,useCallback,useEffect}from'react';import {toast}from'sonner';import j from'svg-pan-zoom';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {Slot}from'@radix-ui/react-slot';import {cva}from'class-variance-authority';import {jsxs,jsx}from'react/jsx-runtime';import*as r from'@radix-ui/react-tooltip';var A=Object.defineProperty;var l=(e,a)=>A(e,"name",{value:a,configurable:true});function d(...e){return twMerge(clsx(e))}l(d,"cn");var U=cva('inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*="size-"])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive',{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline",primary:"bg-primary text-primary-foreground shadow hover:bg-primary/90",linkFG:"text-primary underline-offset-4 hover:underline",linkMuted:"text-muted-foreground underline-offset-4 hover:underline hover:text-foreground"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9","icon-sm":"size-8","icon-lg":"size-10"}},defaultVariants:{variant:"default",size:"default"}}),f=M.forwardRef(({className:e,variant:a="default",size:t="default",asChild:o=false,isLoading:p=false,children:n,...h},g)=>jsxs(o?Slot:"button",{"data-slot":"button","data-variant":a,"data-size":t,className:d(U({variant:a,size:t,className:e})),ref:g,...h,children:[p?jsx(Loader2,{className:d("h-4 w-4 animate-spin",t!=="icon"&&t!=="icon-sm"&&t!=="icon-lg"&&"mr-2")}):null,p&&(t==="icon"||t==="icon-sm"||t==="icon-lg")?null:n]}));f.displayName="Button";var y=r.Root,T=r.Trigger;var v=l(({className:e,sideOffset:a=4,showArrow:t=true,...o})=>jsxs(r.Content,{className:d("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",e),sideOffset:a,...o,children:[o.children,t&&jsx(r.Arrow,{className:"fill-bg-dark -my-px drop-shadow-[0_1px_0_#313336]"})]}),"TooltipContent");v.displayName=r.Content.displayName;L.initialize({startOnLoad:true,mindmap:{useWidth:800},theme:"dark",fontSize:18,darkMode:true,fontFamily:"Inter"});var J=l(()=>`mermaid-${Math.random().toString(36).slice(2)}`,"generateId"),K=l(async(e,a)=>{try{let t=document.createElement("a");t.href=URL.createObjectURL(e),t.download=a,document.body.appendChild(t),t.click(),document.body.removeChild(t),URL.revokeObjectURL(t.href),toast.success("Mermaid diagram saved successfully");}catch{toast.error("Failed to download diagram");}},"downloadBlob"),N=l(({code:e,className:a,isRunning:t})=>{let o=useRef(null),p=useRef(null),[n,h]=useState(null),g=!t,w=useCallback(()=>{n?.fit(),n?.center();},[n]),z=useCallback(()=>{if(o.current){let u=o.current.innerHTML,x=new Blob([u],{type:"image/svg+xml"});K(x,"mermaid-diagram.svg");}},[]),P=useCallback(()=>{n?.enablePan(),n?.enableZoom();},[n]),C=useCallback(()=>{n?.disablePan(),n?.disableZoom();},[n]),D=useCallback(()=>{P();},[P]),S=useCallback(()=>{C();},[C]),k=useCallback(()=>{o.current&&o.current.focus();},[]);return useEffect(()=>{!g||!o.current||!e||p.current!==e&&(async()=>{try{let u=J(),{svg:x}=await L.render(u,e);if(o.current){o.current.innerHTML=x;let s=o.current.querySelector("svg");if(s){s.setAttribute("height","100%"),s.setAttribute("width","100%"),s.style.height="100%",s.style.width="100%",s.style.position="absolute",s.style.top="0",s.style.left="0";let m=j(s);m.fit(),m.center(),m.zoomAtPoint(1,{x:0,y:0}),m.disablePan(),m.disableZoom(),h(m);}}p.current=e;}catch(u){console.warn("Failed to render Mermaid diagram:",u);}})();},[e,g]),jsxs("div",{className:"relative",children:[jsxs("div",{className:"absolute top-2 right-2 z-10 flex gap-1",children:[jsxs(y,{children:[jsx(T,{asChild:true,children:jsx(f,{variant:"ghost",size:"icon",onClick:w,className:"text-text-secondary",children:jsx(RotateCcw,{size:14})})}),jsx(v,{children:jsx("p",{children:"Reset Zoom"})})]}),jsxs(y,{children:[jsx(T,{asChild:true,children:jsx(f,{variant:"ghost",size:"icon",onClick:z,className:"text-text-secondary",children:jsx(Download,{size:14})})}),jsx(v,{children:jsx("p",{children:"Download SVG"})})]})]}),jsx("div",{onClick:k,className:"text-text-secondary bg-bg-quaternary absolute right-2 bottom-2 z-10 rounded px-2 py-1 text-xs",children:"Click to focus, then scroll to zoom & drag to pan"}),jsx("div",{ref:o,tabIndex:0,onFocus:D,onBlur:S,onClick:k,className:d("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",a),style:{width:"100%",minHeight:"400px"},children:"Drawing diagram..."})]})},"MermaidDiagram");export{N as Mermaid,N as MermaidDiagram};
|