@turingpaper/ui 0.0.1-test.8 → 0.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.
@@ -0,0 +1,8 @@
1
+ import { RenderOptions } from 'beautiful-mermaid';
2
+ export interface MermaidDiagramProps {
3
+ className?: string;
4
+ code: string;
5
+ filename?: string;
6
+ options?: RenderOptions;
7
+ }
8
+ export declare const MermaidDiagram: import('react').ForwardRefExoticComponent<Omit<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof MermaidDiagramProps> & MermaidDiagramProps, "ref"> & import('react').RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,144 @@
1
+ import { jsx as r, jsxs as v } from "react/jsx-runtime";
2
+ import { cn as b } from "./utils.mjs";
3
+ import { forwardRef as p, useMemo as f, useState as x, useCallback as h } from "react";
4
+ import { THEMES as S, renderMermaidSVG as w } from "beautiful-mermaid";
5
+ import { TransformWrapper as C, TransformComponent as k, useControls as E } from "react-zoom-pan-pinch";
6
+ import { ZoomIn as N, ZoomOut as O, RotateCcw as T, Check as y, Copy as I, Download as z } from "lucide-react";
7
+ const R = "script, foreignObject, iframe, object, embed", M = /^on/i;
8
+ function j(e) {
9
+ let t;
10
+ try {
11
+ t = new DOMParser().parseFromString(e, "image/svg+xml");
12
+ } catch {
13
+ return null;
14
+ }
15
+ const o = t.documentElement;
16
+ if (o.tagName !== "svg" || t.querySelector("parsererror") || o.querySelectorAll(R).length > 0) return null;
17
+ const n = o.querySelectorAll("*");
18
+ for (const s of n)
19
+ for (const a of s.attributes)
20
+ if (M.test(a.name)) return null;
21
+ return e;
22
+ }
23
+ const L = {
24
+ ...S["github-light"],
25
+ transparent: !0
26
+ };
27
+ function _(e) {
28
+ if (!e) return "mermaid-diagram.svg";
29
+ const t = Math.max(e.lastIndexOf("/"), e.lastIndexOf("\\")), o = t >= 0 ? e.substring(t + 1) : e, n = o.lastIndexOf(".");
30
+ return `${(n > 0 ? o.substring(0, n) : o).replace(/[^a-zA-Z0-9_-]/g, "") || "mermaid-diagram"}.svg`;
31
+ }
32
+ const G = p(({ className: e, code: t, filename: o, options: n, ...s }, a) => {
33
+ const i = f(() => _(o), [o]), { svg: l, error: u } = f(() => {
34
+ if (!t.trim())
35
+ return { svg: null, error: "Empty diagram" };
36
+ let d;
37
+ try {
38
+ d = w(t, { ...L, ...n });
39
+ } catch (c) {
40
+ return {
41
+ svg: null,
42
+ error: c instanceof Error ? c.message : "Invalid diagram"
43
+ };
44
+ }
45
+ return j(d) ? { svg: d, error: null } : { svg: null, error: "Invalid SVG" };
46
+ }, [t, n]);
47
+ return u ? /* @__PURE__ */ r(
48
+ "div",
49
+ {
50
+ ref: a,
51
+ className: b(
52
+ "flex items-center justify-center text-muted-foreground text-sm",
53
+ e
54
+ ),
55
+ ...s,
56
+ children: u
57
+ }
58
+ ) : /* @__PURE__ */ r(
59
+ "div",
60
+ {
61
+ ref: a,
62
+ className: b("relative w-full h-full overflow-hidden", e),
63
+ ...s,
64
+ children: /* @__PURE__ */ v(
65
+ C,
66
+ {
67
+ initialScale: 1,
68
+ minScale: 0.25,
69
+ maxScale: 4,
70
+ centerOnInit: !0,
71
+ children: [
72
+ /* @__PURE__ */ r(A, { code: t, svg: l, svgFilename: i }),
73
+ /* @__PURE__ */ r(
74
+ k,
75
+ {
76
+ wrapperClass: "!w-full !h-full",
77
+ contentClass: "!w-full",
78
+ children: /* @__PURE__ */ r(
79
+ "div",
80
+ {
81
+ className: "w-full [&>svg]:w-full [&>svg]:h-auto",
82
+ dangerouslySetInnerHTML: { __html: l }
83
+ }
84
+ )
85
+ }
86
+ )
87
+ ]
88
+ }
89
+ )
90
+ }
91
+ );
92
+ }), A = ({ code: e, svg: t, svgFilename: o }) => {
93
+ const { zoomIn: n, zoomOut: s, resetTransform: a } = E(), [i, l] = x(!1), u = h(async () => {
94
+ await navigator.clipboard.writeText(e), l(!0), setTimeout(() => l(!1), 2e3);
95
+ }, [e]), d = h(() => {
96
+ const g = new Blob([t], { type: "image/svg+xml" }), c = URL.createObjectURL(g), m = document.createElement("a");
97
+ m.href = c, m.download = o, m.click(), URL.revokeObjectURL(c);
98
+ }, [t, o]);
99
+ return /* @__PURE__ */ v("div", { className: "absolute top-2 right-2 z-10 flex gap-1", children: [
100
+ /* @__PURE__ */ r(
101
+ "button",
102
+ {
103
+ onClick: () => n(),
104
+ className: "p-1.5 rounded-md bg-background/80 border border-border hover:bg-muted text-foreground",
105
+ children: /* @__PURE__ */ r(N, { size: 16 })
106
+ }
107
+ ),
108
+ /* @__PURE__ */ r(
109
+ "button",
110
+ {
111
+ onClick: () => s(),
112
+ className: "p-1.5 rounded-md bg-background/80 border border-border hover:bg-muted text-foreground",
113
+ children: /* @__PURE__ */ r(O, { size: 16 })
114
+ }
115
+ ),
116
+ /* @__PURE__ */ r(
117
+ "button",
118
+ {
119
+ onClick: () => a(),
120
+ className: "p-1.5 rounded-md bg-background/80 border border-border hover:bg-muted text-foreground",
121
+ children: /* @__PURE__ */ r(T, { size: 16 })
122
+ }
123
+ ),
124
+ /* @__PURE__ */ r(
125
+ "button",
126
+ {
127
+ onClick: u,
128
+ className: "p-1.5 rounded-md bg-background/80 border border-border hover:bg-muted text-foreground",
129
+ children: i ? /* @__PURE__ */ r(y, { size: 16 }) : /* @__PURE__ */ r(I, { size: 16 })
130
+ }
131
+ ),
132
+ /* @__PURE__ */ r(
133
+ "button",
134
+ {
135
+ onClick: d,
136
+ className: "p-1.5 rounded-md bg-background/80 border border-border hover:bg-muted text-foreground",
137
+ children: /* @__PURE__ */ r(z, { size: 16 })
138
+ }
139
+ )
140
+ ] });
141
+ };
142
+ export {
143
+ G as MermaidDiagram
144
+ };