@f5xc-salesdemos/pi-utils 19.42.0 → 19.42.2

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@f5xc-salesdemos/pi-utils",
4
- "version": "19.42.0",
4
+ "version": "19.42.2",
5
5
  "description": "Shared utilities for pi packages",
6
6
  "homepage": "https://github.com/f5xc-salesdemos/xcsh",
7
7
  "author": "Can Boluk",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/bun": "^1.3",
42
- "@f5xc-salesdemos/pi-natives": "19.42.0"
42
+ "@f5xc-salesdemos/pi-natives": "19.42.2"
43
43
  },
44
44
  "engines": {
45
45
  "bun": ">=1.3.7"
@@ -26,6 +26,23 @@ export function pickColorMode({ noColor, trueColor }: ColorModeInput): MermaidCo
26
26
  return trueColor ? "truecolor" : "ansi256";
27
27
  }
28
28
 
29
+ /**
30
+ * Complexity ceiling for mermaid sources. beautiful-mermaid's ASCII edge router
31
+ * (A* pathfinder) can allocate unbounded memory and hang for tens of seconds —
32
+ * then throw `RangeError: Out of memory` — on large/dense graphs. Callers should
33
+ * reject sources past this limit BEFORE rendering rather than attempt the layout.
34
+ */
35
+ export const MERMAID_MAX_CHARS = 20000;
36
+ export const MERMAID_MAX_LINES = 400;
37
+
38
+ /** True when a mermaid source is too large to render safely (see limits above). */
39
+ export function mermaidSourceExceedsLimit(source: string): boolean {
40
+ if (source.length > MERMAID_MAX_CHARS) return true;
41
+ let lines = 1;
42
+ for (let i = 0; i < source.length; i++) if (source.charCodeAt(i) === 10 && ++lines > MERMAID_MAX_LINES) return true;
43
+ return false;
44
+ }
45
+
29
46
  export type MermaidDiagramType = "flowchart" | "sequence" | "class" | "er" | "state" | "xychart" | "unknown";
30
47
 
31
48
  /** Detect the diagram type from the first meaningful header line of mermaid source. */