@san-siva/blogkit 1.1.34 → 1.1.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.
Files changed (50) hide show
  1. package/dist/assets/collapse.svg +16 -0
  2. package/dist/assets/expand.svg +4 -0
  3. package/dist/assets/info.svg +1 -1
  4. package/dist/assets/reset.svg +4 -0
  5. package/dist/assets/tick.svg +1 -1
  6. package/dist/assets/zoom-in.svg +17 -0
  7. package/dist/assets/zoom-out.svg +17 -0
  8. package/dist/cjs/components/MermaidControls.js +17 -0
  9. package/dist/cjs/components/MermaidControls.js.map +1 -0
  10. package/dist/cjs/components/MermaidViewport.js +14 -0
  11. package/dist/cjs/components/MermaidViewport.js.map +1 -0
  12. package/dist/cjs/dynamicComponents/MermaidDynamic.js +52 -75
  13. package/dist/cjs/dynamicComponents/MermaidDynamic.js.map +1 -1
  14. package/dist/cjs/hooks/usePanZoom.js +77 -0
  15. package/dist/cjs/hooks/usePanZoom.js.map +1 -0
  16. package/dist/cjs/index.css +1 -1
  17. package/dist/cjs/index.css.map +1 -1
  18. package/dist/cjs/styles/Mermaid.module.scss.js +1 -1
  19. package/dist/esm/components/MermaidControls.js +13 -0
  20. package/dist/esm/components/MermaidControls.js.map +1 -0
  21. package/dist/esm/components/MermaidViewport.js +10 -0
  22. package/dist/esm/components/MermaidViewport.js.map +1 -0
  23. package/dist/esm/dynamicComponents/MermaidDynamic.js +52 -75
  24. package/dist/esm/dynamicComponents/MermaidDynamic.js.map +1 -1
  25. package/dist/esm/hooks/usePanZoom.js +75 -0
  26. package/dist/esm/hooks/usePanZoom.js.map +1 -0
  27. package/dist/esm/index.css +1 -1
  28. package/dist/esm/index.css.map +1 -1
  29. package/dist/esm/styles/Mermaid.module.scss.js +1 -1
  30. package/dist/types/components/MermaidControls.d.ts +11 -0
  31. package/dist/types/components/MermaidControls.d.ts.map +1 -0
  32. package/dist/types/components/MermaidViewport.d.ts +12 -0
  33. package/dist/types/components/MermaidViewport.d.ts.map +1 -0
  34. package/dist/types/dynamicComponents/MermaidDynamic.d.ts.map +1 -1
  35. package/dist/types/hooks/usePanZoom.d.ts +23 -0
  36. package/dist/types/hooks/usePanZoom.d.ts.map +1 -0
  37. package/package.json +1 -1
  38. package/src/assets/collapse.svg +16 -0
  39. package/src/assets/expand.svg +4 -0
  40. package/src/assets/info.svg +1 -1
  41. package/src/assets/reset.svg +4 -0
  42. package/src/assets/tick.svg +1 -1
  43. package/src/assets/zoom-in.svg +17 -0
  44. package/src/assets/zoom-out.svg +17 -0
  45. package/src/components/MermaidControls.tsx +54 -0
  46. package/src/components/MermaidViewport.tsx +40 -0
  47. package/src/dynamicComponents/MermaidDynamic.tsx +101 -131
  48. package/src/hooks/usePanZoom.ts +105 -0
  49. package/src/styles/Mermaid.module.scss +72 -4
  50. package/src/styles/Mermaid.module.scss.d.ts +10 -0
@@ -1,4 +1,4 @@
1
- var styles = {"margin-top--1":"Mermaid-module_margin-top--1__W10B7","margin-bottom--2":"Mermaid-module_margin-bottom--2__w3Zct","mermaid":"Mermaid-module_mermaid__02iRo","mermaid__controls":"Mermaid-module_mermaid__controls__0YNFR","mermaid__controls__btn":"Mermaid-module_mermaid__controls__btn__w04sa","mermaid__viewport":"Mermaid-module_mermaid__viewport__KVL-A","mermaid__viewport--dragging":"Mermaid-module_mermaid__viewport--dragging__WjBzf"};
1
+ var styles = {"margin-top--1":"Mermaid-module_margin-top--1__W10B7","margin-bottom--2":"Mermaid-module_margin-bottom--2__w3Zct","mermaid":"Mermaid-module_mermaid__02iRo","mermaid__controls":"Mermaid-module_mermaid__controls__0YNFR","mermaid__controls__btn":"Mermaid-module_mermaid__controls__btn__w04sa","mermaid__controls__btn--zoom-in":"Mermaid-module_mermaid__controls__btn--zoom-in__KX5QE","mermaid__controls__btn--zoom-out":"Mermaid-module_mermaid__controls__btn--zoom-out__Zffvt","mermaid__controls__btn--reset":"Mermaid-module_mermaid__controls__btn--reset__njRg-","mermaid__controls__btn--expand":"Mermaid-module_mermaid__controls__btn--expand__ZriXV","mermaid__controls__btn--collapse":"Mermaid-module_mermaid__controls__btn--collapse__3z9Fo","mermaid__viewport":"Mermaid-module_mermaid__viewport__KVL-A","mermaid__viewport--dragging":"Mermaid-module_mermaid__viewport--dragging__WjBzf","mermaid__modal":"Mermaid-module_mermaid__modal__wkcDB","mermaid__modal__content":"Mermaid-module_mermaid__modal__content__LTlQS","mermaid__modal__controls":"Mermaid-module_mermaid__modal__controls__S3kxt","mermaid__modal__viewport":"Mermaid-module_mermaid__modal__viewport__wxddc","mermaid__modal__viewport--dragging":"Mermaid-module_mermaid__modal__viewport--dragging__fFm72"};
2
2
 
3
3
  export { styles as default };
4
4
  //# sourceMappingURL=Mermaid.module.scss.js.map
@@ -0,0 +1,11 @@
1
+ interface MermaidControlsProps {
2
+ className: string;
3
+ isExpanded: boolean;
4
+ onZoomIn: () => void;
5
+ onZoomOut: () => void;
6
+ onReset: () => void;
7
+ onToggleExpand: () => void;
8
+ }
9
+ declare const MermaidControls: ({ className, isExpanded, onZoomIn, onZoomOut, onReset, onToggleExpand, }: MermaidControlsProps) => import("react/jsx-runtime").JSX.Element;
10
+ export default MermaidControls;
11
+ //# sourceMappingURL=MermaidControls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MermaidControls.d.ts","sourceRoot":"","sources":["../../../src/components/MermaidControls.tsx"],"names":[],"mappings":"AAEA,UAAU,oBAAoB;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,cAAc,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,QAAA,MAAM,eAAe,GAAI,0EAOtB,oBAAoB,4CAiCtB,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { PanZoom } from '../hooks/usePanZoom';
2
+ interface MermaidViewportProps {
3
+ className: string;
4
+ draggingClassName: string;
5
+ pan: PanZoom;
6
+ contentRef: React.RefObject<HTMLDivElement>;
7
+ contentId?: string;
8
+ hidden?: boolean;
9
+ }
10
+ declare const MermaidViewport: ({ className, draggingClassName, pan, contentRef, contentId, hidden, }: MermaidViewportProps) => import("react/jsx-runtime").JSX.Element;
11
+ export default MermaidViewport;
12
+ //# sourceMappingURL=MermaidViewport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MermaidViewport.d.ts","sourceRoot":"","sources":["../../../src/components/MermaidViewport.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,UAAU,oBAAoB;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,GAAG,EAAE,OAAO,CAAC;IACb,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,QAAA,MAAM,eAAe,GAAI,uEAOtB,oBAAoB,4CAmBtB,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"MermaidDynamic.d.ts","sourceRoot":"","sources":["../../../src/dynamicComponents/MermaidDynamic.tsx"],"names":[],"mappings":"AASA,UAAU,iBAAiB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAuBD,QAAA,MAAM,OAAO,GAAI,2CAKd,iBAAiB,4CAqKnB,CAAC;AAEF,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"MermaidDynamic.d.ts","sourceRoot":"","sources":["../../../src/dynamicComponents/MermaidDynamic.tsx"],"names":[],"mappings":"AAaA,UAAU,iBAAiB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAmBD,QAAA,MAAM,OAAO,GAAI,2CAKd,iBAAiB,4CAuInB,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -0,0 +1,23 @@
1
+ export interface Transform {
2
+ scale: number;
3
+ x: number;
4
+ y: number;
5
+ }
6
+ export interface UsePanZoomOptions {
7
+ initialTransform?: Transform;
8
+ minScale?: number;
9
+ maxScale?: number;
10
+ zoomStep?: number;
11
+ }
12
+ export declare const usePanZoom: ({ initialTransform, minScale, maxScale, zoomStep, }?: UsePanZoomOptions) => {
13
+ transform: Transform;
14
+ isDragging: boolean;
15
+ onMouseDown: (e: React.MouseEvent) => void;
16
+ onMouseMove: (e: React.MouseEvent) => void;
17
+ onMouseUp: () => void;
18
+ zoomIn: () => void;
19
+ zoomOut: () => void;
20
+ reset: () => void;
21
+ };
22
+ export type PanZoom = ReturnType<typeof usePanZoom>;
23
+ //# sourceMappingURL=usePanZoom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePanZoom.d.ts","sourceRoot":"","sources":["../../../src/hooks/usePanZoom.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,SAAS;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACV;AAED,MAAM,WAAW,iBAAiB;IACjC,gBAAgB,CAAC,EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAOD,eAAO,MAAM,UAAU,GAAI,sDAKxB,iBAAsB;;;qBAkBY,KAAK,CAAC,UAAU;qBAa/C,KAAK,CAAC,UAAU;;;;;CA8CrB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@san-siva/blogkit",
3
- "version": "1.1.34",
3
+ "version": "1.1.36",
4
4
  "description": "A reusable blog component library for React/Next.js applications with code highlighting, diagrams, and rich content features",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+
3
+ <svg width="800px" height="800px" viewBox="0 0 48 48" fill="#313030" xmlns="http://www.w3.org/2000/svg">
4
+ <title>collapse-fullscreen</title>
5
+ <g id="Layer_2" data-name="Layer 2">
6
+ <g id="invisible_box" data-name="invisible box">
7
+ <rect width="48" height="48" fill="none"/>
8
+ </g>
9
+ <g id="icons_Q2" data-name="icons Q2">
10
+ <g>
11
+ <path d="M8,26a2,2,0,0,0-2,2.3A2.1,2.1,0,0,0,8.1,30h7.1L4.7,40.5a2,2,0,0,0-.2,2.8A1.8,1.8,0,0,0,6,44a2,2,0,0,0,1.4-.6L18,32.8v7.1A2.1,2.1,0,0,0,19.7,42,2,2,0,0,0,22,40V28a2,2,0,0,0-2-2Z"/>
12
+ <path d="M43.7,4.8a2,2,0,0,0-3.1-.2L30,15.2V8.1A2.1,2.1,0,0,0,28.3,6,2,2,0,0,0,26,8V20a2,2,0,0,0,2,2H39.9A2.1,2.1,0,0,0,42,20.3,2,2,0,0,0,40,18H32.8L43.4,7.5A2.3,2.3,0,0,0,43.7,4.8Z"/>
13
+ </g>
14
+ </g>
15
+ </g>
16
+ </svg>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
2
+ <svg width="800px" height="800px" viewBox="-2 -2 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
3
+ <path d="M14 10L21 3M21 3H16.5M21 3V7.5M10 14L3 21M3 21H7.5M3 21L3 16.5" stroke="#313030" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
4
+ </svg>
@@ -1,3 +1,3 @@
1
1
  <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <path d="M12 17C12.2833 17 12.5208 16.9042 12.7125 16.7125C12.9042 16.5208 13 16.2833 13 16C13 15.7167 12.9042 15.4792 12.7125 15.2875C12.5208 15.0958 12.2833 15 12 15C11.7167 15 11.4792 15.0958 11.2875 15.2875C11.0958 15.4792 11 15.7167 11 16C11 16.2833 11.0958 16.5208 11.2875 16.7125C11.4792 16.9042 11.7167 17 12 17ZM11 13H13V7H11V13ZM12 22C10.6167 22 9.31667 21.7375 8.1 21.2125C6.88333 20.6875 5.825 19.975 4.925 19.075C4.025 18.175 3.3125 17.1167 2.7875 15.9C2.2625 14.6833 2 13.3833 2 12C2 10.6167 2.2625 9.31667 2.7875 8.1C3.3125 6.88333 4.025 5.825 4.925 4.925C5.825 4.025 6.88333 3.3125 8.1 2.7875C9.31667 2.2625 10.6167 2 12 2C13.3833 2 14.6833 2.2625 15.9 2.7875C17.1167 3.3125 18.175 4.025 19.075 4.925C19.975 5.825 20.6875 6.88333 21.2125 8.1C21.7375 9.31667 22 10.6167 22 12C22 13.3833 21.7375 14.6833 21.2125 15.9C20.6875 17.1167 19.975 18.175 19.075 19.075C18.175 19.975 17.1167 20.6875 15.9 21.2125C14.6833 21.7375 13.3833 22 12 22Z" fill="#4242FA"/>
2
+ <path d="M12 17C12.2833 17 12.5208 16.9042 12.7125 16.7125C12.9042 16.5208 13 16.2833 13 16C13 15.7167 12.9042 15.4792 12.7125 15.2875C12.5208 15.0958 12.2833 15 12 15C11.7167 15 11.4792 15.0958 11.2875 15.2875C11.0958 15.4792 11 15.7167 11 16C11 16.2833 11.0958 16.5208 11.2875 16.7125C11.4792 16.9042 11.7167 17 12 17ZM11 13H13V7H11V13ZM12 22C10.6167 22 9.31667 21.7375 8.1 21.2125C6.88333 20.6875 5.825 19.975 4.925 19.075C4.025 18.175 3.3125 17.1167 2.7875 15.9C2.2625 14.6833 2 13.3833 2 12C2 10.6167 2.2625 9.31667 2.7875 8.1C3.3125 6.88333 4.025 5.825 4.925 4.925C5.825 4.025 6.88333 3.3125 8.1 2.7875C9.31667 2.2625 10.6167 2 12 2C13.3833 2 14.6833 2.2625 15.9 2.7875C17.1167 3.3125 18.175 4.025 19.075 4.925C19.975 5.825 20.6875 6.88333 21.2125 8.1C21.7375 9.31667 22 10.6167 22 12C22 13.3833 21.7375 14.6833 21.2125 15.9C20.6875 17.1167 19.975 18.175 19.075 19.075C18.175 19.975 17.1167 20.6875 15.9 21.2125C14.6833 21.7375 13.3833 22 12 22Z" fill="#3F51B5"/>
3
3
  </svg>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
2
+ <svg fill="#313030" width="800px" height="800px" viewBox="0 0 1920 1920" xmlns="http://www.w3.org/2000/svg">
3
+ <path d="M960 0v213.333c411.627 0 746.667 334.934 746.667 746.667S1371.627 1706.667 960 1706.667 213.333 1371.733 213.333 960c0-197.013 78.4-382.507 213.334-520.747v254.08H640V106.667H53.333V320h191.04C88.64 494.08 0 720.96 0 960c0 529.28 430.613 960 960 960s960-430.72 960-960S1489.387 0 960 0" fill-rule="evenodd"/>
4
+ </svg>
@@ -1,3 +1,3 @@
1
1
  <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <path d="M21.3333 35.7707L8.78133 23.2187L12.552 19.448L21.3333 28.2293L48 1.56267V0H0V48H48V26.6667V9.104L21.3333 35.7707Z" fill="#4242FA"/>
2
+ <path d="M21.3333 35.7707L8.78133 23.2187L12.552 19.448L21.3333 28.2293L48 1.56267V0H0V48H48V26.6667V9.104L21.3333 35.7707Z" fill="#3F51B5"/>
3
3
  </svg>
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
3
+ <svg width="800px" height="800px" viewBox="-1 -1 34 34" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
4
+
5
+ <title>zoom-in</title>
6
+ <desc>Created with Sketch Beta.</desc>
7
+ <defs>
8
+
9
+ </defs>
10
+ <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
11
+ <g id="Icon-Set" sketch:type="MSLayerGroup" transform="translate(-308.000000, -1139.000000)" fill="#313030" stroke="#313030" stroke-width="1.5" stroke-linejoin="round">
12
+ <path d="M321.46,1163.45 C315.17,1163.45 310.07,1158.44 310.07,1152.25 C310.07,1146.06 315.17,1141.04 321.46,1141.04 C327.75,1141.04 332.85,1146.06 332.85,1152.25 C332.85,1158.44 327.75,1163.45 321.46,1163.45 L321.46,1163.45 Z M339.688,1169.25 L331.429,1161.12 C333.592,1158.77 334.92,1155.67 334.92,1152.25 C334.92,1144.93 328.894,1139 321.46,1139 C314.026,1139 308,1144.93 308,1152.25 C308,1159.56 314.026,1165.49 321.46,1165.49 C324.672,1165.49 327.618,1164.38 329.932,1162.53 L338.225,1170.69 C338.629,1171.09 339.284,1171.09 339.688,1170.69 C340.093,1170.3 340.093,1169.65 339.688,1169.25 L339.688,1169.25 Z M326.519,1151.41 L322.522,1151.41 L322.522,1147.41 C322.522,1146.85 322.075,1146.41 321.523,1146.41 C320.972,1146.41 320.524,1146.85 320.524,1147.41 L320.524,1151.41 L316.529,1151.41 C315.978,1151.41 315.53,1151.59 315.53,1152.14 C315.53,1152.7 315.978,1153.41 316.529,1153.41 L320.524,1153.41 L320.524,1157.41 C320.524,1157.97 320.972,1158.41 321.523,1158.41 C322.075,1158.41 322.522,1157.97 322.522,1157.41 L322.522,1153.41 L326.519,1153.41 C327.07,1153.41 327.518,1152.96 327.518,1152.41 C327.518,1151.86 327.07,1151.41 326.519,1151.41 L326.519,1151.41 Z" id="zoom-in" sketch:type="MSShapeGroup">
13
+
14
+ </path>
15
+ </g>
16
+ </g>
17
+ </svg>
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
3
+ <svg width="800px" height="800px" viewBox="-1 -1 34 34" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
4
+
5
+ <title>zoom-out</title>
6
+ <desc>Created with Sketch Beta.</desc>
7
+ <defs>
8
+
9
+ </defs>
10
+ <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
11
+ <g id="Icon-Set" sketch:type="MSLayerGroup" transform="translate(-360.000000, -1139.000000)" fill="#313030" stroke="#313030" stroke-width="1.5" stroke-linejoin="round">
12
+ <path d="M373.46,1163.45 C367.17,1163.45 362.071,1158.44 362.071,1152.25 C362.071,1146.06 367.17,1141.04 373.46,1141.04 C379.75,1141.04 384.85,1146.06 384.85,1152.25 C384.85,1158.44 379.75,1163.45 373.46,1163.45 L373.46,1163.45 Z M391.688,1169.25 L383.429,1161.12 C385.592,1158.77 386.92,1155.67 386.92,1152.25 C386.92,1144.93 380.894,1139 373.46,1139 C366.026,1139 360,1144.93 360,1152.25 C360,1159.56 366.026,1165.49 373.46,1165.49 C376.672,1165.49 379.618,1164.38 381.932,1162.53 L390.225,1170.69 C390.629,1171.09 391.284,1171.09 391.688,1170.69 C392.093,1170.3 392.093,1169.65 391.688,1169.25 L391.688,1169.25 Z M378.689,1151.41 L368.643,1151.41 C368.102,1151.41 367.663,1151.84 367.663,1152.37 C367.663,1152.9 368.102,1153.33 368.643,1153.33 L378.689,1153.33 C379.23,1153.33 379.669,1152.9 379.669,1152.37 C379.669,1151.84 379.23,1151.41 378.689,1151.41 L378.689,1151.41 Z" id="zoom-out" sketch:type="MSShapeGroup">
13
+
14
+ </path>
15
+ </g>
16
+ </g>
17
+ </svg>
@@ -0,0 +1,54 @@
1
+ import styles from '../styles/Mermaid.module.scss';
2
+
3
+ interface MermaidControlsProps {
4
+ className: string;
5
+ isExpanded: boolean;
6
+ onZoomIn: () => void;
7
+ onZoomOut: () => void;
8
+ onReset: () => void;
9
+ onToggleExpand: () => void;
10
+ }
11
+
12
+ const MermaidControls = ({
13
+ className,
14
+ isExpanded,
15
+ onZoomIn,
16
+ onZoomOut,
17
+ onReset,
18
+ onToggleExpand,
19
+ }: MermaidControlsProps) => {
20
+ const toggleLabel = isExpanded ? 'Close fullscreen' : 'Expand to fullscreen';
21
+ const toggleModifier = isExpanded
22
+ ? styles['mermaid__controls__btn--collapse']
23
+ : styles['mermaid__controls__btn--expand'];
24
+ return (
25
+ <div className={className}>
26
+ <button
27
+ className={`${styles['mermaid__controls__btn']} ${styles['mermaid__controls__btn--zoom-in']}`}
28
+ onClick={onZoomIn}
29
+ aria-label="Zoom in"
30
+ title="Zoom in"
31
+ />
32
+ <button
33
+ className={`${styles['mermaid__controls__btn']} ${styles['mermaid__controls__btn--zoom-out']}`}
34
+ onClick={onZoomOut}
35
+ aria-label="Zoom out"
36
+ title="Zoom out"
37
+ />
38
+ <button
39
+ className={`${styles['mermaid__controls__btn']} ${styles['mermaid__controls__btn--reset']}`}
40
+ onClick={onReset}
41
+ aria-label="Reset view"
42
+ title="Reset view"
43
+ />
44
+ <button
45
+ className={`${styles['mermaid__controls__btn']} ${toggleModifier}`}
46
+ onClick={onToggleExpand}
47
+ aria-label={toggleLabel}
48
+ title={toggleLabel}
49
+ />
50
+ </div>
51
+ );
52
+ };
53
+
54
+ export default MermaidControls;
@@ -0,0 +1,40 @@
1
+ import type { PanZoom } from '../hooks/usePanZoom';
2
+
3
+ interface MermaidViewportProps {
4
+ className: string;
5
+ draggingClassName: string;
6
+ pan: PanZoom;
7
+ contentRef: React.RefObject<HTMLDivElement>;
8
+ contentId?: string;
9
+ hidden?: boolean;
10
+ }
11
+
12
+ const MermaidViewport = ({
13
+ className,
14
+ draggingClassName,
15
+ pan,
16
+ contentRef,
17
+ contentId,
18
+ hidden,
19
+ }: MermaidViewportProps) => (
20
+ <div
21
+ className={`${className} ${pan.isDragging ? draggingClassName : ''}`}
22
+ style={hidden ? { display: 'none' } : undefined}
23
+ onMouseDown={pan.onMouseDown}
24
+ onMouseMove={pan.onMouseMove}
25
+ onMouseUp={pan.onMouseUp}
26
+ onMouseLeave={pan.onMouseUp}
27
+ >
28
+ <div
29
+ style={{
30
+ transform: `translate(${pan.transform.x}px, ${pan.transform.y}px) scale(${pan.transform.scale})`,
31
+ transformOrigin: '0 0',
32
+ transition: pan.isDragging ? 'none' : 'transform 0.1s ease',
33
+ }}
34
+ >
35
+ <div ref={contentRef} id={contentId} />
36
+ </div>
37
+ </div>
38
+ );
39
+
40
+ export default MermaidViewport;
@@ -1,9 +1,13 @@
1
1
  'use client';
2
2
 
3
3
  import { useCallback, useEffect, useRef, useState } from 'react';
4
+ import { createPortal } from 'react-dom';
4
5
 
5
6
  import mermaid from 'mermaid';
6
7
 
8
+ import MermaidControls from '../components/MermaidControls';
9
+ import MermaidViewport from '../components/MermaidViewport';
10
+ import { usePanZoom } from '../hooks/usePanZoom';
7
11
  import CalloutStatic from '../staticComponents/CalloutStatic';
8
12
  import styles from '../styles/Mermaid.module.scss';
9
13
 
@@ -31,10 +35,6 @@ mermaid.initialize({
31
35
  },
32
36
  });
33
37
 
34
- const MIN_SCALE = 0.5;
35
- const MAX_SCALE = 4;
36
- const ZOOM_STEP = 0.15;
37
-
38
38
  const Mermaid = ({
39
39
  code = '',
40
40
  id = '',
@@ -43,109 +43,69 @@ const Mermaid = ({
43
43
  }: MermaidProperties) => {
44
44
  const [enabled, setEnabled] = useState(false);
45
45
  const [error, setError] = useState<string | null>(null);
46
- const [transform, setTransform] = useState({ scale: 1, x: 0, y: 0 });
47
- const [isDragging, setIsDragging] = useState(false);
46
+ const [isExpanded, setIsExpanded] = useState(false);
48
47
 
49
48
  const mermaidReference = useRef<HTMLDivElement>(null);
50
- const viewportRef = useRef<HTMLDivElement>(null);
49
+ const modalMermaidReference = useRef<HTMLDivElement>(null);
51
50
  const renderCount = useRef(0);
52
- const transformRef = useRef({ scale: 1, x: 0, y: 0 });
53
- const isDraggingRef = useRef(false);
54
- const dragStart = useRef({
55
- mouseX: 0,
56
- mouseY: 0,
57
- transformX: 0,
58
- transformY: 0,
59
- });
60
51
 
61
- const applyTransform = useCallback(
62
- (
63
- updater: (
64
- prev: typeof transformRef.current
65
- ) => typeof transformRef.current
66
- ) => {
67
- const next = updater(transformRef.current);
68
- transformRef.current = next;
69
- setTransform(next);
52
+ const inline = usePanZoom();
53
+ const modal = usePanZoom();
54
+
55
+ const renderInto = useCallback(
56
+ async (target: HTMLDivElement | null, prefix: string) => {
57
+ if (!target || !code) return false;
58
+ const renderId = `${prefix}-${id}-${++renderCount.current}`;
59
+ try {
60
+ const { svg, bindFunctions } = await mermaid.render(renderId, code);
61
+ if (!svg) return false;
62
+ target.innerHTML = svg;
63
+ bindFunctions?.(target);
64
+ return true;
65
+ } catch (err) {
66
+ const message =
67
+ err instanceof Error ? err.message : 'Failed to render diagram';
68
+ setError(message);
69
+ return false;
70
+ }
70
71
  },
71
- []
72
+ [code, id]
72
73
  );
73
74
 
74
- const initializeMermaid = useCallback(async () => {
75
- if (!mermaidReference.current || !code) return;
76
- const renderId = `mermaid-diagram-${id}-${++renderCount.current}`;
77
- document.getElementById(renderId)?.remove();
78
- try {
79
- const { svg, bindFunctions } = await mermaid.render(renderId, code);
80
- if (!mermaidReference.current || !svg) return;
81
- mermaidReference.current.innerHTML = svg;
82
- bindFunctions?.(mermaidReference.current);
83
- setEnabled(true);
84
- } catch (err) {
85
- const message =
86
- err instanceof Error ? err.message : 'Failed to render diagram';
87
- setError(message);
88
- }
89
- }, [code, id]);
90
-
91
75
  useEffect(() => {
92
76
  if (!code) return;
93
77
  setError(null);
94
- applyTransform(() => ({ scale: 1, x: 0, y: 0 }));
95
- const timer = setTimeout(initializeMermaid, 100);
78
+ inline.reset();
79
+ const timer = setTimeout(() => {
80
+ renderInto(mermaidReference.current, 'mermaid-diagram').then(ok => {
81
+ if (ok) setEnabled(true);
82
+ });
83
+ }, 100);
96
84
  return () => clearTimeout(timer);
97
- }, [code, initializeMermaid, applyTransform]);
98
-
85
+ }, [code, renderInto, inline.reset]);
99
86
 
87
+ useEffect(() => {
88
+ if (!isExpanded) return;
89
+ modal.reset();
90
+ const timer = setTimeout(() => {
91
+ renderInto(modalMermaidReference.current, 'mermaid-modal');
92
+ }, 0);
93
+ return () => clearTimeout(timer);
94
+ }, [isExpanded, renderInto, modal.reset]);
100
95
 
101
- const handleMouseDown = useCallback((e: React.MouseEvent) => {
102
- e.preventDefault();
103
- isDraggingRef.current = true;
104
- setIsDragging(true);
105
- dragStart.current = {
106
- mouseX: e.clientX,
107
- mouseY: e.clientY,
108
- transformX: transformRef.current.x,
109
- transformY: transformRef.current.y,
96
+ useEffect(() => {
97
+ if (!isExpanded) return;
98
+ const onKey = (e: KeyboardEvent) => {
99
+ if (e.key === 'Escape') setIsExpanded(false);
110
100
  };
111
- }, []);
112
-
113
- const handleMouseMove = useCallback(
114
- (e: React.MouseEvent) => {
115
- if (!isDraggingRef.current) return;
116
- applyTransform(prev => ({
117
- ...prev,
118
- x:
119
- dragStart.current.transformX + (e.clientX - dragStart.current.mouseX),
120
- y:
121
- dragStart.current.transformY + (e.clientY - dragStart.current.mouseY),
122
- }));
123
- },
124
- [applyTransform]
125
- );
126
-
127
- const handleMouseUp = useCallback(() => {
128
- isDraggingRef.current = false;
129
- setIsDragging(false);
130
- }, []);
131
-
132
- const zoomIn = useCallback(() => {
133
- applyTransform(prev => ({
134
- ...prev,
135
- scale: Math.min(prev.scale * (1 + ZOOM_STEP), MAX_SCALE),
136
- }));
137
- }, [applyTransform]);
138
-
139
- const zoomOut = useCallback(() => {
140
- applyTransform(prev => ({
141
- ...prev,
142
- scale: Math.max(prev.scale * (1 - ZOOM_STEP), MIN_SCALE),
143
- }));
144
- }, [applyTransform]);
145
-
146
- const resetView = useCallback(() => {
147
- applyTransform(() => ({ scale: 1, x: 0, y: 0 }));
148
- }, [applyTransform]);
101
+ const previousOverflow = document.body.style.overflow;
102
+ document.body.style.overflow = 'hidden';
103
+ window.addEventListener('keydown', onKey);
104
+ return () => {
105
+ document.body.style.overflow = previousOverflow;
106
+ window.removeEventListener('keydown', onKey);
107
+ };
108
+ }, [isExpanded]);
149
109
 
150
110
  return (
151
111
  <div
@@ -164,45 +124,55 @@ const Mermaid = ({
164
124
  <p>Rendering diagram...</p>
165
125
  </CalloutStatic>
166
126
  ) : (
167
- <div className={styles['mermaid__controls']}>
168
- <button className={styles['mermaid__controls__btn']} onClick={zoomIn}>
169
- +
170
- </button>
171
- <button
172
- className={styles['mermaid__controls__btn']}
173
- onClick={zoomOut}
174
- >
175
-
176
- </button>
177
- <button
178
- className={styles['mermaid__controls__btn']}
179
- onClick={resetView}
180
- >
181
- Reset
182
- </button>
183
- </div>
127
+ <MermaidControls
128
+ className={styles['mermaid__controls']}
129
+ isExpanded={false}
130
+ onZoomIn={inline.zoomIn}
131
+ onZoomOut={inline.zoomOut}
132
+ onReset={inline.reset}
133
+ onToggleExpand={() => setIsExpanded(true)}
134
+ />
184
135
  )}
185
- <div
186
- ref={viewportRef}
187
- className={`${styles['mermaid__viewport']} ${
188
- isDragging ? styles['mermaid__viewport--dragging'] : ''
189
- }`}
190
- style={enabled ? undefined : { display: 'none' }}
191
- onMouseDown={handleMouseDown}
192
- onMouseMove={handleMouseMove}
193
- onMouseUp={handleMouseUp}
194
- onMouseLeave={handleMouseUp}
195
- >
196
- <div
197
- style={{
198
- transform: `translate(${transform.x}px, ${transform.y}px) scale(${transform.scale})`,
199
- transformOrigin: '0 0',
200
- transition: isDragging ? 'none' : 'transform 0.1s ease',
201
- }}
202
- >
203
- <div ref={mermaidReference} id={id} />
204
- </div>
205
- </div>
136
+ <MermaidViewport
137
+ className={styles['mermaid__viewport']}
138
+ draggingClassName={styles['mermaid__viewport--dragging']}
139
+ pan={inline}
140
+ contentRef={mermaidReference}
141
+ contentId={id}
142
+ hidden={!enabled}
143
+ />
144
+
145
+ {isExpanded &&
146
+ typeof document !== 'undefined' &&
147
+ createPortal(
148
+ <div
149
+ className={styles['mermaid__modal']}
150
+ onClick={() => setIsExpanded(false)}
151
+ role="dialog"
152
+ aria-modal="true"
153
+ >
154
+ <div
155
+ className={styles['mermaid__modal__content']}
156
+ onClick={e => e.stopPropagation()}
157
+ >
158
+ <MermaidControls
159
+ className={styles['mermaid__modal__controls']}
160
+ isExpanded={true}
161
+ onZoomIn={modal.zoomIn}
162
+ onZoomOut={modal.zoomOut}
163
+ onReset={modal.reset}
164
+ onToggleExpand={() => setIsExpanded(false)}
165
+ />
166
+ <MermaidViewport
167
+ className={styles['mermaid__modal__viewport']}
168
+ draggingClassName={styles['mermaid__modal__viewport--dragging']}
169
+ pan={modal}
170
+ contentRef={modalMermaidReference}
171
+ />
172
+ </div>
173
+ </div>,
174
+ document.body
175
+ )}
206
176
  </div>
207
177
  );
208
178
  };
@@ -0,0 +1,105 @@
1
+ import { useCallback, useRef, useState } from 'react';
2
+
3
+ export interface Transform {
4
+ scale: number;
5
+ x: number;
6
+ y: number;
7
+ }
8
+
9
+ export interface UsePanZoomOptions {
10
+ initialTransform?: Transform;
11
+ minScale?: number;
12
+ maxScale?: number;
13
+ zoomStep?: number;
14
+ }
15
+
16
+ const DEFAULT_INITIAL_TRANSFORM: Transform = { scale: 1, x: 0, y: 0 };
17
+ const DEFAULT_MIN_SCALE = 0.5;
18
+ const DEFAULT_MAX_SCALE = 4;
19
+ const DEFAULT_ZOOM_STEP = 0.15;
20
+
21
+ export const usePanZoom = ({
22
+ initialTransform = DEFAULT_INITIAL_TRANSFORM,
23
+ minScale = DEFAULT_MIN_SCALE,
24
+ maxScale = DEFAULT_MAX_SCALE,
25
+ zoomStep = DEFAULT_ZOOM_STEP,
26
+ }: UsePanZoomOptions = {}) => {
27
+ const [transform, setTransform] = useState<Transform>(initialTransform);
28
+ const [isDragging, setIsDragging] = useState(false);
29
+ const transformRef = useRef<Transform>(initialTransform);
30
+ const isDraggingRef = useRef(false);
31
+ const dragStart = useRef({
32
+ mouseX: 0,
33
+ mouseY: 0,
34
+ transformX: 0,
35
+ transformY: 0,
36
+ });
37
+
38
+ const apply = useCallback((updater: (prev: Transform) => Transform) => {
39
+ const next = updater(transformRef.current);
40
+ transformRef.current = next;
41
+ setTransform(next);
42
+ }, []);
43
+
44
+ const onMouseDown = useCallback((e: React.MouseEvent) => {
45
+ e.preventDefault();
46
+ isDraggingRef.current = true;
47
+ setIsDragging(true);
48
+ dragStart.current = {
49
+ mouseX: e.clientX,
50
+ mouseY: e.clientY,
51
+ transformX: transformRef.current.x,
52
+ transformY: transformRef.current.y,
53
+ };
54
+ }, []);
55
+
56
+ const onMouseMove = useCallback(
57
+ (e: React.MouseEvent) => {
58
+ if (!isDraggingRef.current) return;
59
+ apply(prev => ({
60
+ ...prev,
61
+ x:
62
+ dragStart.current.transformX + (e.clientX - dragStart.current.mouseX),
63
+ y:
64
+ dragStart.current.transformY + (e.clientY - dragStart.current.mouseY),
65
+ }));
66
+ },
67
+ [apply]
68
+ );
69
+
70
+ const onMouseUp = useCallback(() => {
71
+ isDraggingRef.current = false;
72
+ setIsDragging(false);
73
+ }, []);
74
+
75
+ const zoomIn = useCallback(() => {
76
+ apply(prev => ({
77
+ ...prev,
78
+ scale: Math.min(prev.scale * (1 + zoomStep), maxScale),
79
+ }));
80
+ }, [apply, zoomStep, maxScale]);
81
+
82
+ const zoomOut = useCallback(() => {
83
+ apply(prev => ({
84
+ ...prev,
85
+ scale: Math.max(prev.scale * (1 - zoomStep), minScale),
86
+ }));
87
+ }, [apply, zoomStep, minScale]);
88
+
89
+ const reset = useCallback(() => {
90
+ apply(() => initialTransform);
91
+ }, [apply, initialTransform]);
92
+
93
+ return {
94
+ transform,
95
+ isDragging,
96
+ onMouseDown,
97
+ onMouseMove,
98
+ onMouseUp,
99
+ zoomIn,
100
+ zoomOut,
101
+ reset,
102
+ };
103
+ };
104
+
105
+ export type PanZoom = ReturnType<typeof usePanZoom>;