@hackersheet/next-document-content-components 0.1.0-alpha.31 → 0.1.0-alpha.32
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.
|
@@ -41,8 +41,12 @@ async function withSafeJsonStringify(fn) {
|
|
|
41
41
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
42
42
|
const safeReplacer = (_key, val) => {
|
|
43
43
|
if (typeof val === "object" && val !== null) {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
try {
|
|
45
|
+
if (seen.has(val)) return void 0;
|
|
46
|
+
seen.add(val);
|
|
47
|
+
} catch {
|
|
48
|
+
return void 0;
|
|
49
|
+
}
|
|
46
50
|
}
|
|
47
51
|
return val;
|
|
48
52
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/mermaid/mermaid-renderer.ts"],"sourcesContent":["'use client';\n\n/**\n * Mermaid diagram rendering functions.\n * Handles rendering with beautiful-mermaid and fallback to original mermaid library.\n * @module\n */\n\nimport { getErrorMessage, hasValidSvgDimensions, normalizeCode } from './mermaid-utils';\n\n/**\n * Result type for mermaid rendering operations.\n */\nexport type MermaidRenderResult = { success: true; svg: string } | { success: false; error: string };\n\n/**\n * Run a function with a patched JSON.stringify that handles circular references.\n * This is needed because mermaid's block-beta renderer tries to stringify DOM elements.\n *\n * @param fn - Async function to execute with safe JSON.stringify\n * @returns Result of the function\n * @internal\n */\nexport async function withSafeJsonStringify<T>(fn: () => Promise<T>): Promise<T> {\n const originalStringify = JSON.stringify;\n JSON.stringify = function (value, _replacer, space) {\n const seen = new WeakSet();\n const safeReplacer = (_key: string, val: unknown) => {\n if (typeof val === 'object' && val !== null) {\n if (seen.has(val)) return undefined;\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/mermaid/mermaid-renderer.ts"],"sourcesContent":["'use client';\n\n/**\n * Mermaid diagram rendering functions.\n * Handles rendering with beautiful-mermaid and fallback to original mermaid library.\n * @module\n */\n\nimport { getErrorMessage, hasValidSvgDimensions, normalizeCode } from './mermaid-utils';\n\n/**\n * Result type for mermaid rendering operations.\n */\nexport type MermaidRenderResult = { success: true; svg: string } | { success: false; error: string };\n\n/**\n * Run a function with a patched JSON.stringify that handles circular references.\n * This is needed because mermaid's block-beta renderer tries to stringify DOM elements.\n *\n * @param fn - Async function to execute with safe JSON.stringify\n * @returns Result of the function\n * @internal\n */\nexport async function withSafeJsonStringify<T>(fn: () => Promise<T>): Promise<T> {\n const originalStringify = JSON.stringify;\n JSON.stringify = function (value, _replacer, space) {\n const seen = new WeakSet();\n const safeReplacer = (_key: string, val: unknown) => {\n if (typeof val === 'object' && val !== null) {\n try {\n if (seen.has(val)) return undefined;\n seen.add(val);\n } catch {\n // Cross-origin objects (e.g., Window, iframe) throw security errors\n // when accessed via WeakSet operations. Skip tracking these objects.\n return undefined;\n }\n }\n return val;\n };\n return originalStringify(value, safeReplacer, space);\n };\n try {\n return await fn();\n } finally {\n JSON.stringify = originalStringify;\n }\n}\n\n/**\n * Render diagram using beautiful-mermaid library.\n * Uses dynamic import to reduce initial bundle size.\n *\n * @param code - Mermaid diagram code\n * @param isDark - Whether to use dark theme\n * @returns SVG string if successful, null otherwise\n */\nexport async function renderWithBeautifulMermaid(code: string, isDark: boolean): Promise<string | null> {\n const { renderMermaid, THEMES } = await import('beautiful-mermaid');\n const colors = isDark ? THEMES['github-dark'] : THEMES['github-light'];\n const normalizedCode = normalizeCode(code);\n const result = await renderMermaid(normalizedCode, {\n ...colors,\n transparent: true,\n });\n if (result && hasValidSvgDimensions(result)) {\n return result;\n }\n return null;\n}\n\n/**\n * Render diagram using original mermaid library as fallback.\n * Uses dynamic import to reduce initial bundle size.\n *\n * @param code - Mermaid diagram code\n * @param isDark - Whether to use dark theme\n * @param uniqueId - Unique identifier for the mermaid render container\n * @returns Result object with success status and SVG or error message\n */\nexport async function renderWithMermaidFallback(\n code: string,\n isDark: boolean,\n uniqueId: string\n): Promise<MermaidRenderResult> {\n const mermaid = (await import('mermaid')).default;\n const mermaidTheme = isDark ? 'dark' : 'default';\n mermaid.initialize({ startOnLoad: false, theme: mermaidTheme });\n try {\n const { svg } = await withSafeJsonStringify(() => mermaid.render(uniqueId, code));\n return { success: true, svg };\n } catch (error) {\n return { success: false, error: getErrorMessage(error) };\n } finally {\n document.getElementById(`d${uniqueId}`)?.remove();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,2BAAsE;AAetE,eAAsB,sBAAyB,IAAkC;AAC/E,QAAM,oBAAoB,KAAK;AAC/B,OAAK,YAAY,SAAU,OAAO,WAAW,OAAO;AAClD,UAAM,OAAO,oBAAI,QAAQ;AACzB,UAAM,eAAe,CAAC,MAAc,QAAiB;AACnD,UAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM;AAC3C,YAAI;AACF,cAAI,KAAK,IAAI,GAAG,EAAG,QAAO;AAC1B,eAAK,IAAI,GAAG;AAAA,QACd,QAAQ;AAGN,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT;AACA,WAAO,kBAAkB,OAAO,cAAc,KAAK;AAAA,EACrD;AACA,MAAI;AACF,WAAO,MAAM,GAAG;AAAA,EAClB,UAAE;AACA,SAAK,YAAY;AAAA,EACnB;AACF;AAUA,eAAsB,2BAA2B,MAAc,QAAyC;AACtG,QAAM,EAAE,eAAe,OAAO,IAAI,MAAM,OAAO,mBAAmB;AAClE,QAAM,SAAS,SAAS,OAAO,aAAa,IAAI,OAAO,cAAc;AACrE,QAAM,qBAAiB,oCAAc,IAAI;AACzC,QAAM,SAAS,MAAM,cAAc,gBAAgB;AAAA,IACjD,GAAG;AAAA,IACH,aAAa;AAAA,EACf,CAAC;AACD,MAAI,cAAU,4CAAsB,MAAM,GAAG;AAC3C,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAWA,eAAsB,0BACpB,MACA,QACA,UAC8B;AAC9B,QAAM,WAAW,MAAM,OAAO,SAAS,GAAG;AAC1C,QAAM,eAAe,SAAS,SAAS;AACvC,UAAQ,WAAW,EAAE,aAAa,OAAO,OAAO,aAAa,CAAC;AAC9D,MAAI;AACF,UAAM,EAAE,IAAI,IAAI,MAAM,sBAAsB,MAAM,QAAQ,OAAO,UAAU,IAAI,CAAC;AAChF,WAAO,EAAE,SAAS,MAAM,IAAI;AAAA,EAC9B,SAAS,OAAO;AACd,WAAO,EAAE,SAAS,OAAO,WAAO,sCAAgB,KAAK,EAAE;AAAA,EACzD,UAAE;AACA,aAAS,eAAe,IAAI,QAAQ,EAAE,GAAG,OAAO;AAAA,EAClD;AACF;","names":[]}
|
|
@@ -6,8 +6,12 @@ async function withSafeJsonStringify(fn) {
|
|
|
6
6
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
7
7
|
const safeReplacer = (_key, val) => {
|
|
8
8
|
if (typeof val === "object" && val !== null) {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
try {
|
|
10
|
+
if (seen.has(val)) return void 0;
|
|
11
|
+
seen.add(val);
|
|
12
|
+
} catch {
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
11
15
|
}
|
|
12
16
|
return val;
|
|
13
17
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/mermaid/mermaid-renderer.ts"],"sourcesContent":["'use client';\n\n/**\n * Mermaid diagram rendering functions.\n * Handles rendering with beautiful-mermaid and fallback to original mermaid library.\n * @module\n */\n\nimport { getErrorMessage, hasValidSvgDimensions, normalizeCode } from \"./mermaid-utils.mjs\";\n\n/**\n * Result type for mermaid rendering operations.\n */\nexport type MermaidRenderResult = { success: true; svg: string } | { success: false; error: string };\n\n/**\n * Run a function with a patched JSON.stringify that handles circular references.\n * This is needed because mermaid's block-beta renderer tries to stringify DOM elements.\n *\n * @param fn - Async function to execute with safe JSON.stringify\n * @returns Result of the function\n * @internal\n */\nexport async function withSafeJsonStringify<T>(fn: () => Promise<T>): Promise<T> {\n const originalStringify = JSON.stringify;\n JSON.stringify = function (value, _replacer, space) {\n const seen = new WeakSet();\n const safeReplacer = (_key: string, val: unknown) => {\n if (typeof val === 'object' && val !== null) {\n if (seen.has(val)) return undefined;\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/mermaid/mermaid-renderer.ts"],"sourcesContent":["'use client';\n\n/**\n * Mermaid diagram rendering functions.\n * Handles rendering with beautiful-mermaid and fallback to original mermaid library.\n * @module\n */\n\nimport { getErrorMessage, hasValidSvgDimensions, normalizeCode } from \"./mermaid-utils.mjs\";\n\n/**\n * Result type for mermaid rendering operations.\n */\nexport type MermaidRenderResult = { success: true; svg: string } | { success: false; error: string };\n\n/**\n * Run a function with a patched JSON.stringify that handles circular references.\n * This is needed because mermaid's block-beta renderer tries to stringify DOM elements.\n *\n * @param fn - Async function to execute with safe JSON.stringify\n * @returns Result of the function\n * @internal\n */\nexport async function withSafeJsonStringify<T>(fn: () => Promise<T>): Promise<T> {\n const originalStringify = JSON.stringify;\n JSON.stringify = function (value, _replacer, space) {\n const seen = new WeakSet();\n const safeReplacer = (_key: string, val: unknown) => {\n if (typeof val === 'object' && val !== null) {\n try {\n if (seen.has(val)) return undefined;\n seen.add(val);\n } catch {\n // Cross-origin objects (e.g., Window, iframe) throw security errors\n // when accessed via WeakSet operations. Skip tracking these objects.\n return undefined;\n }\n }\n return val;\n };\n return originalStringify(value, safeReplacer, space);\n };\n try {\n return await fn();\n } finally {\n JSON.stringify = originalStringify;\n }\n}\n\n/**\n * Render diagram using beautiful-mermaid library.\n * Uses dynamic import to reduce initial bundle size.\n *\n * @param code - Mermaid diagram code\n * @param isDark - Whether to use dark theme\n * @returns SVG string if successful, null otherwise\n */\nexport async function renderWithBeautifulMermaid(code: string, isDark: boolean): Promise<string | null> {\n const { renderMermaid, THEMES } = await import('beautiful-mermaid');\n const colors = isDark ? THEMES['github-dark'] : THEMES['github-light'];\n const normalizedCode = normalizeCode(code);\n const result = await renderMermaid(normalizedCode, {\n ...colors,\n transparent: true,\n });\n if (result && hasValidSvgDimensions(result)) {\n return result;\n }\n return null;\n}\n\n/**\n * Render diagram using original mermaid library as fallback.\n * Uses dynamic import to reduce initial bundle size.\n *\n * @param code - Mermaid diagram code\n * @param isDark - Whether to use dark theme\n * @param uniqueId - Unique identifier for the mermaid render container\n * @returns Result object with success status and SVG or error message\n */\nexport async function renderWithMermaidFallback(\n code: string,\n isDark: boolean,\n uniqueId: string\n): Promise<MermaidRenderResult> {\n const mermaid = (await import('mermaid')).default;\n const mermaidTheme = isDark ? 'dark' : 'default';\n mermaid.initialize({ startOnLoad: false, theme: mermaidTheme });\n try {\n const { svg } = await withSafeJsonStringify(() => mermaid.render(uniqueId, code));\n return { success: true, svg };\n } catch (error) {\n return { success: false, error: getErrorMessage(error) };\n } finally {\n document.getElementById(`d${uniqueId}`)?.remove();\n }\n}\n"],"mappings":";AAQA,SAAS,iBAAiB,uBAAuB,qBAAqB;AAetE,eAAsB,sBAAyB,IAAkC;AAC/E,QAAM,oBAAoB,KAAK;AAC/B,OAAK,YAAY,SAAU,OAAO,WAAW,OAAO;AAClD,UAAM,OAAO,oBAAI,QAAQ;AACzB,UAAM,eAAe,CAAC,MAAc,QAAiB;AACnD,UAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM;AAC3C,YAAI;AACF,cAAI,KAAK,IAAI,GAAG,EAAG,QAAO;AAC1B,eAAK,IAAI,GAAG;AAAA,QACd,QAAQ;AAGN,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT;AACA,WAAO,kBAAkB,OAAO,cAAc,KAAK;AAAA,EACrD;AACA,MAAI;AACF,WAAO,MAAM,GAAG;AAAA,EAClB,UAAE;AACA,SAAK,YAAY;AAAA,EACnB;AACF;AAUA,eAAsB,2BAA2B,MAAc,QAAyC;AACtG,QAAM,EAAE,eAAe,OAAO,IAAI,MAAM,OAAO,mBAAmB;AAClE,QAAM,SAAS,SAAS,OAAO,aAAa,IAAI,OAAO,cAAc;AACrE,QAAM,iBAAiB,cAAc,IAAI;AACzC,QAAM,SAAS,MAAM,cAAc,gBAAgB;AAAA,IACjD,GAAG;AAAA,IACH,aAAa;AAAA,EACf,CAAC;AACD,MAAI,UAAU,sBAAsB,MAAM,GAAG;AAC3C,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAWA,eAAsB,0BACpB,MACA,QACA,UAC8B;AAC9B,QAAM,WAAW,MAAM,OAAO,SAAS,GAAG;AAC1C,QAAM,eAAe,SAAS,SAAS;AACvC,UAAQ,WAAW,EAAE,aAAa,OAAO,OAAO,aAAa,CAAC;AAC9D,MAAI;AACF,UAAM,EAAE,IAAI,IAAI,MAAM,sBAAsB,MAAM,QAAQ,OAAO,UAAU,IAAI,CAAC;AAChF,WAAO,EAAE,SAAS,MAAM,IAAI;AAAA,EAC9B,SAAS,OAAO;AACd,WAAO,EAAE,SAAS,OAAO,OAAO,gBAAgB,KAAK,EAAE;AAAA,EACzD,UAAE;AACA,aAAS,eAAe,IAAI,QAAQ,EAAE,GAAG,OAAO;AAAA,EAClD;AACF;","names":[]}
|