markdown-flow-ui 0.1.100-beta.4 → 0.1.100-beta.40

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 (101) hide show
  1. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-input@1.8.0_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-input/es/BaseInput.cjs.js +1 -1
  2. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-input@1.8.0_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-input/es/BaseInput.es.js +1 -1
  3. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/ResizableTextArea.cjs.js +1 -1
  4. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/ResizableTextArea.es.js +1 -1
  5. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/TextArea.cjs.js +1 -1
  6. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/TextArea.es.js +1 -1
  7. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/index.cjs.js +1 -1
  8. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/index.es.js +1 -1
  9. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-custom-variable.cjs.js +1 -1
  10. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-custom-variable.es.js +1 -1
  11. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-interaction.cjs.js +1 -1
  12. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-interaction.es.js +1 -1
  13. package/dist/_virtual/index.cjs3.js +1 -1
  14. package/dist/_virtual/index.cjs4.js +1 -1
  15. package/dist/_virtual/index.es3.js +4 -5
  16. package/dist/_virtual/index.es3.js.map +1 -1
  17. package/dist/_virtual/index.es4.js +5 -4
  18. package/dist/_virtual/index.es4.js.map +1 -1
  19. package/dist/assets/markdown-flow-ui.css +1 -1
  20. package/dist/components/ContentRender/ContentRender.cjs.js +2 -2
  21. package/dist/components/ContentRender/ContentRender.cjs.js.map +1 -1
  22. package/dist/components/ContentRender/ContentRender.d.ts +13 -10
  23. package/dist/components/ContentRender/ContentRender.es.js +184 -160
  24. package/dist/components/ContentRender/ContentRender.es.js.map +1 -1
  25. package/dist/components/ContentRender/IframeSandbox.cjs.js +5 -4
  26. package/dist/components/ContentRender/IframeSandbox.cjs.js.map +1 -1
  27. package/dist/components/ContentRender/IframeSandbox.d.ts +1 -0
  28. package/dist/components/ContentRender/IframeSandbox.es.js +307 -210
  29. package/dist/components/ContentRender/IframeSandbox.es.js.map +1 -1
  30. package/dist/components/ContentRender/SandboxApp.cjs.js +3 -3
  31. package/dist/components/ContentRender/SandboxApp.cjs.js.map +1 -1
  32. package/dist/components/ContentRender/SandboxApp.d.ts +4 -0
  33. package/dist/components/ContentRender/SandboxApp.es.js +87 -80
  34. package/dist/components/ContentRender/SandboxApp.es.js.map +1 -1
  35. package/dist/components/ContentRender/index.cjs.js +1 -1
  36. package/dist/components/ContentRender/index.es.js +5 -6
  37. package/dist/components/ContentRender/plugins/CustomVariable.cjs.js +1 -1
  38. package/dist/components/ContentRender/plugins/CustomVariable.cjs.js.map +1 -1
  39. package/dist/components/ContentRender/plugins/CustomVariable.es.js +68 -64
  40. package/dist/components/ContentRender/plugins/CustomVariable.es.js.map +1 -1
  41. package/dist/components/MarkdownFlow/MarkdownFlow.cjs.js +1 -1
  42. package/dist/components/MarkdownFlow/MarkdownFlow.cjs.js.map +1 -1
  43. package/dist/components/MarkdownFlow/MarkdownFlow.d.ts +3 -0
  44. package/dist/components/MarkdownFlow/MarkdownFlow.es.js +21 -18
  45. package/dist/components/MarkdownFlow/MarkdownFlow.es.js.map +1 -1
  46. package/dist/components/Slide/Player.cjs.js +1 -1
  47. package/dist/components/Slide/Player.cjs.js.map +1 -1
  48. package/dist/components/Slide/Player.d.ts +3 -2
  49. package/dist/components/Slide/Player.es.js +228 -170
  50. package/dist/components/Slide/Player.es.js.map +1 -1
  51. package/dist/components/Slide/Slide.cjs.js +1 -1
  52. package/dist/components/Slide/Slide.cjs.js.map +1 -1
  53. package/dist/components/Slide/Slide.d.ts +10 -0
  54. package/dist/components/Slide/Slide.es.js +422 -270
  55. package/dist/components/Slide/Slide.es.js.map +1 -1
  56. package/dist/components/Slide/Slide.stories.d.ts +27 -1
  57. package/dist/components/Slide/index.d.ts +3 -3
  58. package/dist/components/Slide/types.d.ts +5 -6
  59. package/dist/components/Slide/useSlide.cjs.js +1 -1
  60. package/dist/components/Slide/useSlide.cjs.js.map +1 -1
  61. package/dist/components/Slide/useSlide.d.ts +4 -1
  62. package/dist/components/Slide/useSlide.es.js +125 -83
  63. package/dist/components/Slide/useSlide.es.js.map +1 -1
  64. package/dist/components/Slide/useWakePlayerFromIframe.cjs.js +2 -0
  65. package/dist/components/Slide/useWakePlayerFromIframe.cjs.js.map +1 -0
  66. package/dist/components/Slide/useWakePlayerFromIframe.d.ts +7 -0
  67. package/dist/components/Slide/useWakePlayerFromIframe.es.js +89 -0
  68. package/dist/components/Slide/useWakePlayerFromIframe.es.js.map +1 -0
  69. package/dist/components/Slide/utils/playerCustomActions.cjs.js +2 -0
  70. package/dist/components/Slide/utils/playerCustomActions.cjs.js.map +1 -0
  71. package/dist/components/Slide/utils/playerCustomActions.d.ts +3 -0
  72. package/dist/components/Slide/utils/playerCustomActions.es.js +7 -0
  73. package/dist/components/Slide/utils/playerCustomActions.es.js.map +1 -0
  74. package/dist/components/index.d.ts +4 -2
  75. package/dist/components/ui/inputGroup/textarea.cjs.js +1 -1
  76. package/dist/components/ui/inputGroup/textarea.es.js +1 -1
  77. package/dist/index.cjs.js +1 -1
  78. package/dist/index.es.js +24 -22
  79. package/dist/lib/interaction-defaults.cjs.js +2 -0
  80. package/dist/lib/interaction-defaults.cjs.js.map +1 -0
  81. package/dist/lib/interaction-defaults.es.js +106 -0
  82. package/dist/lib/interaction-defaults.es.js.map +1 -0
  83. package/dist/lib/sandboxInteraction.cjs.js +2 -0
  84. package/dist/lib/sandboxInteraction.cjs.js.map +1 -0
  85. package/dist/lib/sandboxInteraction.d.ts +8 -0
  86. package/dist/lib/sandboxInteraction.es.js +12 -0
  87. package/dist/lib/sandboxInteraction.es.js.map +1 -0
  88. package/dist/markdown-flow-ui-lib.css +1 -1
  89. package/dist/renderer.cjs.js +1 -1
  90. package/dist/renderer.d.ts +5 -3
  91. package/dist/renderer.es.js +18 -16
  92. package/package.json +17 -2
  93. package/dist/components/Slide/interaction-defaults.cjs.js +0 -2
  94. package/dist/components/Slide/interaction-defaults.cjs.js.map +0 -1
  95. package/dist/components/Slide/interaction-defaults.es.js +0 -85
  96. package/dist/components/Slide/interaction-defaults.es.js.map +0 -1
  97. package/dist/lib/browserUserActivation.cjs.js +0 -2
  98. package/dist/lib/browserUserActivation.cjs.js.map +0 -1
  99. package/dist/lib/browserUserActivation.es.js +0 -13
  100. package/dist/lib/browserUserActivation.es.js.map +0 -1
  101. /package/dist/{components/Slide → lib}/interaction-defaults.d.ts +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"IframeSandbox.es.js","sources":["../../../src/components/ContentRender/IframeSandbox.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport { Loader2 } from \"lucide-react\";\nimport SandboxApp from \"./SandboxApp\";\nimport { splitContentSegments } from \"./utils/split-content\";\nimport ContentRender from \"./ContentRender\";\n\ntype InjectBlackboardLibraries =\n typeof import(\"./blackboard-vendor\").injectBlackboardLibraries;\n\n// Cache the sandbox vendor loader so every iframe reuses the same preload request.\nlet blackboardVendorPromise: Promise<InjectBlackboardLibraries> | null = null;\n\nconst loadBlackboardVendor = () => {\n if (!blackboardVendorPromise) {\n blackboardVendorPromise = import(\"./blackboard-vendor\").then(\n (m) => m.injectBlackboardLibraries\n );\n }\n\n return blackboardVendorPromise;\n};\n\n// Warm the sandbox vendor chunk as early as possible in the browser.\nif (typeof window !== \"undefined\") {\n void loadBlackboardVendor();\n}\n\nconst COMPLETE_IMAGE_TAG_PATTERN = /<img\\b[^>]*>/i;\nconst POST_IMAGE_STREAM_DEBOUNCE_MS = 180;\nconst SANDBOX_INTERACTION_MESSAGE_SOURCE = \"markdown-flow-ui:sandbox\";\nconst SANDBOX_INTERACTION_MESSAGE_TYPE = \"interaction\";\nconst SANDBOX_INTERACTION_THROTTLE_MS = 240;\nexport interface IframeSandboxProps {\n content: string;\n className?: string;\n loadingText?: string;\n styleLoadingText?: string;\n scriptLoadingText?: string;\n fullScreenButtonText?: string;\n hideFullScreen?: boolean;\n mode?: \"content\" | \"blackboard\";\n type: \"sandbox\" | \"markdown\";\n}\n\nconst normalizeTailwindHeightTokens = (className: string) =>\n className\n .split(/\\s+/)\n .filter(Boolean)\n .map((token) => token.split(\":\").pop() || token);\n\nconst parseViewportHeightCss = (value: string) => {\n const normalized = value.trim().toLowerCase();\n if (!normalized) return null;\n const matched = normalized.match(/^([0-9.]+)(vh|dvh|svh|lvh)$/i);\n if (!matched) return null;\n return `${matched[1]}${matched[2].toLowerCase()}`;\n};\n\nconst extractViewportHeightFromTailwindClass = (className: string) => {\n if (!className.trim()) return null;\n const normalizedTokens = normalizeTailwindHeightTokens(className);\n if (\n normalizedTokens.includes(\"h-screen\") ||\n normalizedTokens.includes(\"h-dvh\")\n ) {\n return \"100dvh\";\n }\n if (normalizedTokens.includes(\"h-svh\")) {\n return \"100svh\";\n }\n if (normalizedTokens.includes(\"h-lvh\")) {\n return \"100lvh\";\n }\n const arbitraryToken = normalizedTokens.find((token) =>\n /^h-\\[[0-9.]+(vh|dvh|svh|lvh)\\]$/i.test(token)\n );\n if (!arbitraryToken) return null;\n const matched = arbitraryToken.match(/^h-\\[([0-9.]+)(vh|dvh|svh|lvh)\\]$/i);\n if (!matched) return null;\n return `${matched[1]}${matched[2].toLowerCase()}`;\n};\n\nconst IframeSandbox: React.FC<IframeSandboxProps> = ({\n content,\n type,\n className,\n loadingText,\n styleLoadingText,\n scriptLoadingText,\n fullScreenButtonText,\n hideFullScreen = false,\n mode = \"content\",\n}) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const iframeRef = useRef<HTMLIFrameElement>(null);\n const rootRef = useRef<Root | null>(null);\n const docRef = useRef<Document | null>(null);\n const updateHeightRef = useRef<() => void>(() => {});\n const [height, setHeight] = useState(480);\n const lastSandboxInteractionTimeRef = useRef(0);\n const [resetToken, setResetToken] = useState(0);\n const [isFullscreen, setIsFullscreen] = useState(false);\n const [isSandboxVendorReady, setIsSandboxVendorReady] = useState(\n type !== \"sandbox\"\n );\n const isBlackboardMode = mode === \"blackboard\";\n const prevHtmlRef = useRef<string>(\"\");\n const htmlContent = React.useMemo(() => {\n const segments = splitContentSegments(content);\n // console.log('segments=====', segments);\n const sandboxSegments = segments.filter((seg) => seg.type === \"sandbox\");\n const sandboxContent =\n mode === \"blackboard\"\n ? sandboxSegments[sandboxSegments.length - 1]?.value || \"\"\n : sandboxSegments.map((seg) => seg.value).join(\"\\n\");\n return sandboxContent || \"\";\n }, [content, mode]);\n const [renderHtmlContent, setRenderHtmlContent] = useState(htmlContent);\n const prevIncomingHtmlRef = useRef(htmlContent);\n const pendingHtmlRef = useRef(htmlContent);\n const deferRenderTimerRef = useRef<number | null>(null);\n\n const emitSandboxInteraction = useCallback((eventType: string) => {\n if (typeof window === \"undefined\") {\n return;\n }\n const now = Date.now();\n if (\n now - lastSandboxInteractionTimeRef.current <\n SANDBOX_INTERACTION_THROTTLE_MS\n ) {\n return;\n }\n lastSandboxInteractionTimeRef.current = now;\n window.postMessage(\n {\n source: SANDBOX_INTERACTION_MESSAGE_SOURCE,\n type: SANDBOX_INTERACTION_MESSAGE_TYPE,\n eventType,\n },\n window.location.origin\n );\n }, []);\n\n const clearDeferredRenderTimer = () => {\n if (deferRenderTimerRef.current === null) return;\n window.clearTimeout(deferRenderTimerRef.current);\n deferRenderTimerRef.current = null;\n };\n\n useEffect(\n () => () => {\n clearDeferredRenderTimer();\n },\n []\n );\n\n useEffect(() => {\n const prevIncomingHtml = prevIncomingHtmlRef.current;\n prevIncomingHtmlRef.current = htmlContent;\n\n const isAppendOnlyStream =\n !!prevIncomingHtml &&\n htmlContent.length > prevIncomingHtml.length &&\n htmlContent.startsWith(prevIncomingHtml);\n const containsCompleteImage = COMPLETE_IMAGE_TAG_PATTERN.test(htmlContent);\n const shouldDeferRender = isAppendOnlyStream && containsCompleteImage;\n\n if (!shouldDeferRender) {\n clearDeferredRenderTimer();\n pendingHtmlRef.current = htmlContent;\n setRenderHtmlContent(htmlContent);\n return;\n }\n\n pendingHtmlRef.current = htmlContent;\n clearDeferredRenderTimer();\n deferRenderTimerRef.current = window.setTimeout(() => {\n setRenderHtmlContent(pendingHtmlRef.current);\n deferRenderTimerRef.current = null;\n }, POST_IMAGE_STREAM_DEBOUNCE_MS);\n }, [htmlContent]);\n\n const rootViewportHeightCss = React.useMemo(() => {\n const normalized = renderHtmlContent.trim();\n if (!normalized) return null;\n const rootMatch = normalized.match(/^<([a-zA-Z][\\w:-]*)(\\s[^>]*?)?>/);\n if (!rootMatch) return null;\n const attrs = rootMatch[2] || \"\";\n const heightAttrMatch = attrs.match(/\\bheight\\s*=\\s*[\"']([^\"']+)[\"']/i);\n if (heightAttrMatch) {\n const explicitHeightCss = parseViewportHeightCss(heightAttrMatch[1]);\n if (explicitHeightCss) return explicitHeightCss;\n }\n const styleAttrMatch = attrs.match(/\\bstyle\\s*=\\s*[\"']([^\"']+)[\"']/i)?.[1];\n const styleHeightMatch = styleAttrMatch?.match(\n /\\bheight\\s*:\\s*([^;]+)/i\n )?.[1];\n if (styleHeightMatch) {\n const styleHeightCss = parseViewportHeightCss(styleHeightMatch);\n if (styleHeightCss) return styleHeightCss;\n }\n const classAttrMatch = attrs.match(/\\bclass\\s*=\\s*[\"']([^\"']+)[\"']/i)?.[1];\n if (!classAttrMatch) return null;\n return extractViewportHeightFromTailwindClass(classAttrMatch);\n }, [renderHtmlContent]);\n const hasRootVhHeight = Boolean(rootViewportHeightCss);\n const shouldInjectSandboxVendor = type === \"sandbox\";\n const sandboxViewportHeight =\n isBlackboardMode && type === \"sandbox\"\n ? (rootViewportHeightCss ?? `${height}px`)\n : undefined;\n useEffect(() => {\n if (mode !== \"blackboard\") {\n prevHtmlRef.current = htmlContent;\n return;\n }\n const prev = prevHtmlRef.current;\n const isContinuation = prev && htmlContent.startsWith(prev);\n if (!isContinuation && prev) {\n setResetToken((token) => token + 1);\n }\n prevHtmlRef.current = htmlContent;\n }, [htmlContent, mode]);\n\n useEffect(() => {\n const iframe = iframeRef.current;\n if (!iframe) return undefined;\n\n const doc = iframe.contentDocument;\n if (!doc) return undefined;\n\n doc.open();\n doc.write(`<!DOCTYPE html>\n<html${mode === \"blackboard\" ? ' style=\"height: 100%;\"' : \"\"}>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <style>\n html, body, #root { width: 100%; height: 100%; }\n html, body { margin: 0; padding: 0; overflow: auto; }\n *, *::before, *::after { box-sizing: border-box; }\n </style>\n </head>\n <body>\n <div id=\"root\"></div>\n </body>\n</html>`);\n doc.close();\n\n docRef.current = doc;\n\n const shouldBridgeSandboxInteraction =\n isBlackboardMode && type === \"sandbox\";\n const handleSandboxPointerDown = () =>\n emitSandboxInteraction(\"pointerdown\");\n const handleSandboxMouseDown = () => emitSandboxInteraction(\"mousedown\");\n const handleSandboxTouchStart = () => emitSandboxInteraction(\"touchstart\");\n\n if (shouldBridgeSandboxInteraction) {\n doc.addEventListener(\"pointerdown\", handleSandboxPointerDown, true);\n doc.addEventListener(\"mousedown\", handleSandboxMouseDown, true);\n doc.addEventListener(\"touchstart\", handleSandboxTouchStart, true);\n }\n\n const rootEl = doc.getElementById(\"root\");\n if (!rootEl) return undefined;\n\n const root = createRoot(rootEl);\n rootRef.current = root;\n let isDestroyed = false;\n\n const parseExplicitHeight = (\n value: string,\n parentViewportHeight: number\n ) => {\n const normalized = value.trim().toLowerCase();\n if (!normalized) return null;\n const numeric = Number.parseFloat(normalized);\n if (Number.isNaN(numeric)) return null;\n if (/(dvh|svh|lvh|vh)$/i.test(normalized)) {\n return (numeric / 100) * parentViewportHeight;\n }\n if (normalized.endsWith(\"px\") || /^[0-9.]+$/.test(normalized)) {\n return numeric;\n }\n return null;\n };\n const parseTailwindHeightClass = (\n className: string,\n parentViewportHeight: number\n ) => {\n if (!className.trim()) return null;\n const viewportHeightCss =\n extractViewportHeightFromTailwindClass(className);\n if (viewportHeightCss) {\n return parseExplicitHeight(viewportHeightCss, parentViewportHeight);\n }\n const normalizedTokens = normalizeTailwindHeightTokens(className);\n const arbitraryToken = normalizedTokens.find((token) =>\n /^h-\\[[0-9.]+px\\]$/i.test(token)\n );\n if (!arbitraryToken) return null;\n const matched = arbitraryToken.match(/^h-\\[([0-9.]+)px\\]$/i);\n if (!matched) return null;\n const numeric = Number.parseFloat(matched[1]);\n if (Number.isNaN(numeric)) return null;\n return numeric;\n };\n\n const resolveExplicitHeight = () => {\n if (!iframeRef.current || !doc.body) return null;\n const wrapper = doc.body.querySelector(\n \".sandbox-wrapper\"\n ) as HTMLElement | null;\n const container = wrapper?.firstElementChild as HTMLElement | null;\n if (!container) return null;\n const elements = Array.from(container.children) as HTMLElement[];\n if (elements.length !== 1) return null;\n const target = elements[0];\n const heightValue = target.style.height || target.getAttribute(\"height\");\n const parentViewportHeight =\n iframeRef.current.ownerDocument?.documentElement?.clientHeight ||\n window.innerHeight;\n const parsed = heightValue\n ? parseExplicitHeight(heightValue, parentViewportHeight)\n : null;\n if (parsed !== null) {\n return Math.ceil(parsed);\n }\n const classHeight = parseTailwindHeightClass(\n target.getAttribute(\"class\") || \"\",\n parentViewportHeight\n );\n return classHeight !== null ? Math.ceil(classHeight) : null;\n };\n\n const updateHeight = () => {\n if (!iframeRef.current || !doc.body) return;\n const bodyRect = doc.body.getBoundingClientRect();\n const htmlRect = doc.documentElement?.getBoundingClientRect();\n const bodyHeight = bodyRect.height;\n const htmlHeight = htmlRect?.height || 0;\n const contentHeight = Math.max(bodyHeight, htmlHeight);\n const explicitHeight = resolveExplicitHeight();\n const nextHeight = Math.max(\n 200,\n explicitHeight ?? Math.ceil(contentHeight)\n );\n setHeight(nextHeight);\n };\n const scheduleHeightUpdate = () => {\n requestAnimationFrame(() => {\n if (isDestroyed) return;\n updateHeight();\n });\n };\n updateHeightRef.current = scheduleHeightUpdate;\n\n updateHeight();\n scheduleHeightUpdate();\n\n if (!shouldInjectSandboxVendor) {\n setIsSandboxVendorReady(true);\n } else {\n // Inject Tailwind/DaisyUI/GSAP before rendering sandbox content to avoid FOUC.\n loadBlackboardVendor()\n .then((inject) => {\n if (isDestroyed) return;\n inject(doc);\n requestAnimationFrame(() => {\n if (isDestroyed) return;\n setIsSandboxVendorReady(true);\n scheduleHeightUpdate();\n });\n })\n .catch(() => {\n if (isDestroyed) return;\n setIsSandboxVendorReady(true);\n scheduleHeightUpdate();\n });\n }\n\n const resizeObserver = new ResizeObserver(() => updateHeight());\n resizeObserver.observe(doc.body);\n if (rootEl) {\n resizeObserver.observe(rootEl);\n }\n\n return () => {\n isDestroyed = true;\n resizeObserver.disconnect();\n if (shouldBridgeSandboxInteraction) {\n doc.removeEventListener(\"pointerdown\", handleSandboxPointerDown, true);\n doc.removeEventListener(\"mousedown\", handleSandboxMouseDown, true);\n doc.removeEventListener(\"touchstart\", handleSandboxTouchStart, true);\n }\n // Defer unmount to avoid React warning when parent is mid-render\n setTimeout(() => {\n root.unmount();\n rootRef.current = null;\n docRef.current = null;\n updateHeightRef.current = () => {};\n }, 0);\n };\n }, []);\n\n useEffect(() => {\n const onFullscreenChange = () => {\n setIsFullscreen(Boolean(document.fullscreenElement));\n };\n document.addEventListener(\"fullscreenchange\", onFullscreenChange);\n return () =>\n document.removeEventListener(\"fullscreenchange\", onFullscreenChange);\n }, []);\n\n const toggleFullscreen = () => {\n const target = containerRef.current || iframeRef.current;\n if (!target) return;\n if (document.fullscreenElement) {\n document.exitFullscreen().catch(() => {});\n return;\n }\n if (target.requestFullscreen) {\n target.requestFullscreen().catch(() => {});\n }\n };\n\n useEffect(() => {\n const root = rootRef.current;\n if (!root || !isSandboxVendorReady) return;\n\n root.render(\n <SandboxApp\n html={renderHtmlContent}\n loadingText={loadingText}\n styleLoadingText={styleLoadingText}\n scriptLoadingText={scriptLoadingText}\n fullScreenButtonText={fullScreenButtonText}\n hideFullScreen={hideFullScreen}\n resetToken={resetToken}\n hasRootVhHeight={hasRootVhHeight}\n mode={mode}\n />\n );\n requestAnimationFrame(() => updateHeightRef.current?.());\n }, [\n renderHtmlContent,\n loadingText,\n styleLoadingText,\n scriptLoadingText,\n fullScreenButtonText,\n resetToken,\n mode,\n isSandboxVendorReady,\n ]);\n const containerClassName = [\n \"w-full relative content-render-iframe-sandbox\",\n isBlackboardMode\n ? \"h-full overflow-auto flex flex-col\"\n : \"aspect-[16/9] overflow-hidden flex items-center justify-center\",\n ]\n .filter(Boolean)\n .join(\" \");\n\n const shouldShowSandboxLoading =\n shouldInjectSandboxVendor && !isSandboxVendorReady;\n\n return (\n <div\n ref={containerRef}\n data-root-vh={hasRootVhHeight ? \"true\" : \"false\"}\n className={containerClassName}\n style={\n sandboxViewportHeight\n ? {\n height: sandboxViewportHeight,\n minHeight: sandboxViewportHeight,\n }\n : undefined\n }\n >\n {!hideFullScreen && (\n <button\n type=\"button\"\n onClick={toggleFullscreen}\n className={\n \"absolute top-2 right-2 z-50 p-1.5 bg-black/75 text-white rounded-md cursor-pointer\"\n }\n >\n {isFullscreen ? \"退出全屏\" : fullScreenButtonText || \"全屏浏览\"}\n </button>\n )}\n {mode === \"blackboard\" && type === \"markdown\" ? (\n <div\n onMouseDown={() => emitSandboxInteraction(\"mousedown\")}\n onPointerDown={() => emitSandboxInteraction(\"pointerdown\")}\n onTouchStart={() => emitSandboxInteraction(\"touchstart\")}\n >\n <ContentRender content={content} />\n </div>\n ) : (\n <>\n <iframe\n ref={iframeRef}\n sandbox=\"allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox\"\n allow=\"fullscreen\"\n allowFullScreen\n className={[className, \"w-full h-full mx-auto my-auto block\"]\n .filter(Boolean)\n .join(\" \")}\n style={{\n height: sandboxViewportHeight ?? \"100%\",\n minHeight: sandboxViewportHeight,\n margin: \"auto\",\n visibility: shouldShowSandboxLoading ? \"hidden\" : \"visible\",\n }}\n />\n {shouldShowSandboxLoading ? (\n <div className=\"pointer-events-none absolute inset-0 z-20 flex items-center justify-center\">\n <Loader2\n aria-label={loadingText || \"Preparing sandbox styles\"}\n className=\"text-primary h-7 w-7 animate-spin\"\n />\n </div>\n ) : null}\n </>\n )}\n </div>\n );\n};\n\nexport default IframeSandbox;\n"],"names":["blackboardVendorPromise","loadBlackboardVendor","m","COMPLETE_IMAGE_TAG_PATTERN","POST_IMAGE_STREAM_DEBOUNCE_MS","SANDBOX_INTERACTION_MESSAGE_SOURCE","SANDBOX_INTERACTION_MESSAGE_TYPE","SANDBOX_INTERACTION_THROTTLE_MS","normalizeTailwindHeightTokens","className","token","parseViewportHeightCss","value","normalized","matched","extractViewportHeightFromTailwindClass","normalizedTokens","arbitraryToken","IframeSandbox","content","type","loadingText","styleLoadingText","scriptLoadingText","fullScreenButtonText","hideFullScreen","mode","containerRef","useRef","iframeRef","rootRef","docRef","updateHeightRef","height","setHeight","useState","lastSandboxInteractionTimeRef","resetToken","setResetToken","isFullscreen","setIsFullscreen","isSandboxVendorReady","setIsSandboxVendorReady","isBlackboardMode","prevHtmlRef","htmlContent","React","sandboxSegments","splitContentSegments","seg","renderHtmlContent","setRenderHtmlContent","prevIncomingHtmlRef","pendingHtmlRef","deferRenderTimerRef","emitSandboxInteraction","useCallback","eventType","now","clearDeferredRenderTimer","useEffect","prevIncomingHtml","isAppendOnlyStream","containsCompleteImage","rootViewportHeightCss","rootMatch","attrs","heightAttrMatch","explicitHeightCss","styleHeightMatch","styleHeightCss","classAttrMatch","hasRootVhHeight","shouldInjectSandboxVendor","sandboxViewportHeight","prev","iframe","doc","shouldBridgeSandboxInteraction","handleSandboxPointerDown","handleSandboxMouseDown","handleSandboxTouchStart","rootEl","root","createRoot","isDestroyed","parseExplicitHeight","parentViewportHeight","numeric","parseTailwindHeightClass","viewportHeightCss","resolveExplicitHeight","container","elements","target","heightValue","parsed","classHeight","updateHeight","bodyRect","htmlRect","bodyHeight","htmlHeight","contentHeight","explicitHeight","nextHeight","scheduleHeightUpdate","inject","resizeObserver","onFullscreenChange","toggleFullscreen","jsx","SandboxApp","containerClassName","shouldShowSandboxLoading","jsxs","ContentRender","Fragment","Loader2"],"mappings":";;;;;;;AAWA,IAAIA,IAAqE;AAEzE,MAAMC,KAAuB,OACtBD,MACHA,IAA0B,OAAO,2BAAqB,EAAE;AAAA,EACtD,CAACE,MAAMA,EAAE;AAAA,IAINF;AAIL,OAAO,SAAW,OACfC,GAAA;AAGP,MAAME,KAA6B,iBAC7BC,KAAgC,KAChCC,KAAqC,4BACrCC,KAAmC,eACnCC,KAAkC,KAalCC,KAAgC,CAACC,MACrCA,EACG,MAAM,KAAK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AAA,gBACX,QAAQ;AAAA,gBACR,YAAYwC,KAA2B,WAAW;AAAA,cAAA;AAAA,YACpD;AAAA,UAAA;AAAA,UAEDA,KACCH,gBAAAA,EAAAA,IAAC,OAAA,EAAI,WAAU,8EACb,UAAAA,gBAAAA,EAAAA;AAAAA,YAACO;AAAAA,YAAA;AAAA,cACC,cAAYjG,KAAe;AAAA,cAC3B,WAAU;AAAA,YAAA;AAAA,UAAA,GAEd,IACE;AAAA,QAAA,EAAA,CACN;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAIR;"}
1
+ {"version":3,"file":"IframeSandbox.es.js","sources":["../../../src/components/ContentRender/IframeSandbox.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport { Loader2 } from \"lucide-react\";\nimport SandboxApp from \"./SandboxApp\";\nimport { splitContentSegments } from \"./utils/split-content\";\nimport ContentRender from \"./ContentRender\";\nimport {\n SANDBOX_INTERACTION_MESSAGE_SOURCE,\n SANDBOX_INTERACTION_MESSAGE_TYPE,\n} from \"../../lib/sandboxInteraction\";\n\ntype InjectBlackboardLibraries =\n typeof import(\"./blackboard-vendor\").injectBlackboardLibraries;\n\n// Cache the sandbox vendor loader so every iframe reuses the same preload request.\nlet blackboardVendorPromise: Promise<InjectBlackboardLibraries> | null = null;\n\nconst loadBlackboardVendor = () => {\n if (!blackboardVendorPromise) {\n blackboardVendorPromise = import(\"./blackboard-vendor\").then(\n (m) => m.injectBlackboardLibraries\n );\n }\n\n return blackboardVendorPromise;\n};\n\nconst loadBlackboardVendorOnDemandWithMetrics = () => {\n const loadStart = performance.now();\n const startedAt = new Date().toISOString();\n console.log(\"[IframeSandbox][SandboxLoad] start\", { startedAt });\n\n return loadBlackboardVendor()\n .then((inject) => {\n console.log(\"[IframeSandbox][SandboxLoad] done\", {\n startedAt,\n endedAt: new Date().toISOString(),\n durationMs: Number((performance.now() - loadStart).toFixed(2)),\n });\n return inject;\n })\n .catch((error) => {\n console.error(\"[IframeSandbox][SandboxLoad] failed\", {\n startedAt,\n endedAt: new Date().toISOString(),\n durationMs: Number((performance.now() - loadStart).toFixed(2)),\n error,\n });\n throw error;\n });\n};\n\nconst COMPLETE_IMAGE_TAG_PATTERN = /<img\\b[^>]*>/i;\nconst POST_IMAGE_STREAM_DEBOUNCE_MS = 180;\nconst SANDBOX_INTERACTION_THROTTLE_MS = 240;\n\nexport interface IframeSandboxProps {\n content: string;\n className?: string;\n loadingText?: string;\n styleLoadingText?: string;\n scriptLoadingText?: string;\n fullScreenButtonText?: string;\n hideFullScreen?: boolean;\n mode?: \"content\" | \"blackboard\";\n type: \"sandbox\" | \"markdown\";\n replaceRootScreenHeightWithFull?: boolean;\n}\n\nconst normalizeTailwindHeightTokens = (className: string) =>\n className\n .split(/\\s+/)\n .filter(Boolean)\n .map((token) => token.split(\":\").pop() || token);\n\nconst parseViewportHeightCss = (value: string) => {\n const normalized = value.trim().toLowerCase();\n if (!normalized) return null;\n const matched = normalized.match(/^([0-9.]+)(vh|dvh|svh|lvh)$/i);\n if (!matched) return null;\n return `${matched[1]}${matched[2].toLowerCase()}`;\n};\n\nconst extractViewportHeightFromTailwindClass = (className: string) => {\n if (!className.trim()) return null;\n const normalizedTokens = normalizeTailwindHeightTokens(className);\n if (\n normalizedTokens.includes(\"h-screen\") ||\n normalizedTokens.includes(\"h-dvh\") ||\n normalizedTokens.includes(\"min-h-screen\") ||\n normalizedTokens.includes(\"min-h-dvh\")\n ) {\n return \"100dvh\";\n }\n if (\n normalizedTokens.includes(\"h-svh\") ||\n normalizedTokens.includes(\"min-h-svh\")\n ) {\n return \"100svh\";\n }\n if (\n normalizedTokens.includes(\"h-lvh\") ||\n normalizedTokens.includes(\"min-h-lvh\")\n ) {\n return \"100lvh\";\n }\n const arbitraryToken = normalizedTokens.find((token) =>\n /^(h|min-h)-\\[[0-9.]+(vh|dvh|svh|lvh)\\]$/i.test(token)\n );\n if (!arbitraryToken) return null;\n const matched = arbitraryToken.match(\n /^(h|min-h)-\\[([0-9.]+)(vh|dvh|svh|lvh)\\]$/i\n );\n if (!matched) return null;\n return `${matched[2]}${matched[3].toLowerCase()}`;\n};\n\nconst SANDBOX_IGNORED_TAG_NAMES = new Set([\n \"base\",\n \"link\",\n \"meta\",\n \"script\",\n \"style\",\n \"template\",\n \"title\",\n]);\n\nconst isSandboxRenderableElement = (element: Element) =>\n !SANDBOX_IGNORED_TAG_NAMES.has(element.tagName.toLowerCase());\n\nconst getFirstRenderableElementChild = (root: ParentNode) =>\n Array.from(root.childNodes).find(\n (node): node is HTMLElement =>\n node.nodeType === Node.ELEMENT_NODE &&\n isSandboxRenderableElement(node as HTMLElement)\n ) || null;\n\nconst getInspectableSandboxElementChain = (root: ParentNode) => {\n const chain: HTMLElement[] = [];\n let current = getFirstRenderableElementChild(root);\n\n while (current) {\n chain.push(current);\n\n const childElements = Array.from(current.children).filter(\n (element): element is HTMLElement => isSandboxRenderableElement(element)\n );\n\n if (childElements.length !== 1) {\n break;\n }\n\n current = childElements[0];\n }\n\n return chain;\n};\n\nconst extractViewportHeightFromElement = (element: HTMLElement) => {\n const heightAttrValue = element.getAttribute(\"height\");\n const attrViewportHeight = heightAttrValue\n ? parseViewportHeightCss(heightAttrValue)\n : null;\n\n if (attrViewportHeight) {\n return attrViewportHeight;\n }\n\n const styleHeightValue =\n element.getAttribute(\"style\")?.match(/\\bheight\\s*:\\s*([^;]+)/i)?.[1] ||\n null;\n const styleViewportHeight = styleHeightValue\n ? parseViewportHeightCss(styleHeightValue)\n : null;\n\n if (styleViewportHeight) {\n return styleViewportHeight;\n }\n\n return extractViewportHeightFromTailwindClass(\n element.getAttribute(\"class\") || \"\"\n );\n};\n\nconst isFullViewportHeightCss = (value: string | null) =>\n value === \"100vh\" ||\n value === \"100dvh\" ||\n value === \"100svh\" ||\n value === \"100lvh\";\n\nconst inspectSandboxPrimaryHeight = (root: ParentNode) => {\n const inspectableElements = getInspectableSandboxElementChain(root);\n let viewportHeightCss: string | null = null;\n let hasFullViewportHeight = false;\n\n inspectableElements.forEach((element) => {\n const elementViewportHeight = extractViewportHeightFromElement(element);\n\n if (!viewportHeightCss && elementViewportHeight) {\n viewportHeightCss = elementViewportHeight;\n }\n\n if (isFullViewportHeightCss(elementViewportHeight)) {\n hasFullViewportHeight = true;\n }\n });\n\n return {\n viewportHeightCss,\n hasFullViewportHeight,\n };\n};\n\nconst inspectRootHeightFromHtmlString = (html: string) => {\n const normalized = html.trim();\n\n if (!normalized) {\n return {\n viewportHeightCss: null,\n hasFullViewportHeight: false,\n };\n }\n\n const rootMatch = normalized.match(/^<([a-zA-Z][\\w:-]*)(\\s[^>]*?)?>/);\n const attrs = rootMatch?.[2] || \"\";\n const heightAttrValue = attrs.match(/\\bheight\\s*=\\s*[\"']([^\"']+)[\"']/i)?.[1];\n const styleAttrValue = attrs.match(/\\bstyle\\s*=\\s*[\"']([^\"']+)[\"']/i)?.[1];\n const styleHeightValue = styleAttrValue?.match(\n /\\bheight\\s*:\\s*([^;]+)/i\n )?.[1];\n const classAttrValue = attrs.match(/\\bclass\\s*=\\s*[\"']([^\"']+)[\"']/i)?.[1];\n const viewportHeightCss =\n (heightAttrValue ? parseViewportHeightCss(heightAttrValue) : null) ||\n (styleHeightValue ? parseViewportHeightCss(styleHeightValue) : null) ||\n (classAttrValue\n ? extractViewportHeightFromTailwindClass(classAttrValue)\n : null);\n\n return {\n viewportHeightCss,\n hasFullViewportHeight: isFullViewportHeightCss(viewportHeightCss),\n };\n};\n\nconst inspectSandboxPrimaryHeightFromHtml = (html: string) => {\n const normalized = html.trim();\n\n if (!normalized) {\n return {\n viewportHeightCss: null,\n hasFullViewportHeight: false,\n };\n }\n\n if (typeof document === \"undefined\") {\n return inspectRootHeightFromHtmlString(normalized);\n }\n\n const template = document.createElement(\"template\");\n template.innerHTML = normalized;\n\n return inspectSandboxPrimaryHeight(template.content);\n};\n\nconst replaceRootScreenHeightToken = (className: string) =>\n className\n .split(/\\s+/)\n .filter(Boolean)\n .map((token) => {\n const segments = token.split(\":\");\n if (\n segments[segments.length - 1] !== \"h-screen\" &&\n segments[segments.length - 1] !== \"min-h-screen\"\n ) {\n return token;\n }\n segments[segments.length - 1] = \"h-full\";\n return segments.join(\":\");\n })\n .join(\" \");\n\nconst replaceRootScreenHeightWithFullClass = (\n html: string,\n enabled: boolean\n) => {\n if (!enabled || !html.trim()) {\n return html;\n }\n\n return html.replace(\n /^(\\s*<[a-zA-Z][\\w:-]*)(\\s[^>]*?)?>/,\n (match, tagStart: string, attrs = \"\") => {\n const classMatch = attrs.match(/\\bclass\\s*=\\s*([\"'])([^\"']*)\\1/i);\n\n if (!classMatch) {\n return match;\n }\n\n const nextClassName = replaceRootScreenHeightToken(classMatch[2]);\n\n if (nextClassName === classMatch[2]) {\n return match;\n }\n\n return `${tagStart}${attrs.replace(\n classMatch[0],\n `class=${classMatch[1]}${nextClassName}${classMatch[1]}`\n )}>`;\n }\n );\n};\n\nconst IframeSandbox: React.FC<IframeSandboxProps> = ({\n content,\n type,\n className,\n loadingText,\n styleLoadingText,\n scriptLoadingText,\n fullScreenButtonText,\n hideFullScreen = false,\n mode = \"content\",\n replaceRootScreenHeightWithFull = false,\n}) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const iframeRef = useRef<HTMLIFrameElement>(null);\n const rootRef = useRef<Root | null>(null);\n const docRef = useRef<Document | null>(null);\n const updateHeightRef = useRef<() => void>(() => {});\n const [height, setHeight] = useState(480);\n const lastSandboxInteractionTimeRef = useRef(0);\n const [resetToken, setResetToken] = useState(0);\n const [isFullscreen, setIsFullscreen] = useState(false);\n const [, setIsSandboxVendorReady] = useState(true);\n const shouldInjectSandboxVendor = type === \"sandbox\";\n\n const isBlackboardMode = mode === \"blackboard\";\n const prevHtmlRef = useRef<string>(\"\");\n const htmlContent = React.useMemo(() => {\n const segments = splitContentSegments(content);\n // console.log('segments=====', segments);\n const sandboxSegments = segments.filter((seg) => seg.type === \"sandbox\");\n const sandboxContent =\n mode === \"blackboard\"\n ? sandboxSegments[sandboxSegments.length - 1]?.value || \"\"\n : sandboxSegments.map((seg) => seg.value).join(\"\\n\");\n return sandboxContent || \"\";\n }, [content, mode]);\n const normalizedHtmlContent = React.useMemo(\n () =>\n replaceRootScreenHeightWithFullClass(\n htmlContent,\n replaceRootScreenHeightWithFull\n ),\n [htmlContent, replaceRootScreenHeightWithFull]\n );\n const htmlHeightMeta = React.useMemo(\n () => inspectSandboxPrimaryHeightFromHtml(htmlContent),\n [htmlContent]\n );\n const shouldStretchRootHeight = React.useMemo(\n () =>\n replaceRootScreenHeightWithFull && htmlHeightMeta.hasFullViewportHeight,\n [htmlHeightMeta.hasFullViewportHeight, replaceRootScreenHeightWithFull]\n );\n const [renderHtmlContent, setRenderHtmlContent] = useState(\n normalizedHtmlContent\n );\n const prevIncomingHtmlRef = useRef(normalizedHtmlContent);\n const pendingHtmlRef = useRef(normalizedHtmlContent);\n const deferRenderTimerRef = useRef<number | null>(null);\n const initialPaintFrameRef = useRef<number | null>(null);\n\n const emitSandboxInteraction = useCallback((eventType: string) => {\n if (typeof window === \"undefined\") {\n return;\n }\n const now = Date.now();\n if (\n now - lastSandboxInteractionTimeRef.current <\n SANDBOX_INTERACTION_THROTTLE_MS\n ) {\n return;\n }\n lastSandboxInteractionTimeRef.current = now;\n window.postMessage(\n {\n source: SANDBOX_INTERACTION_MESSAGE_SOURCE,\n type: SANDBOX_INTERACTION_MESSAGE_TYPE,\n eventType,\n },\n window.location.origin\n );\n }, []);\n\n const clearDeferredRenderTimer = () => {\n if (deferRenderTimerRef.current === null) return;\n window.clearTimeout(deferRenderTimerRef.current);\n deferRenderTimerRef.current = null;\n };\n\n const clearInitialPaintFrames = () => {\n if (initialPaintFrameRef.current !== null) {\n window.cancelAnimationFrame(initialPaintFrameRef.current);\n initialPaintFrameRef.current = null;\n }\n };\n\n useEffect(\n () => () => {\n clearDeferredRenderTimer();\n clearInitialPaintFrames();\n },\n []\n );\n\n useEffect(() => {\n const prevIncomingHtml = prevIncomingHtmlRef.current;\n prevIncomingHtmlRef.current = normalizedHtmlContent;\n\n const isAppendOnlyStream =\n !!prevIncomingHtml &&\n normalizedHtmlContent.length > prevIncomingHtml.length &&\n normalizedHtmlContent.startsWith(prevIncomingHtml);\n const containsCompleteImage = COMPLETE_IMAGE_TAG_PATTERN.test(\n normalizedHtmlContent\n );\n const shouldDeferRender = isAppendOnlyStream && containsCompleteImage;\n\n pendingHtmlRef.current = normalizedHtmlContent;\n clearDeferredRenderTimer();\n\n if (!shouldDeferRender) {\n setRenderHtmlContent(normalizedHtmlContent);\n return;\n }\n\n deferRenderTimerRef.current = window.setTimeout(() => {\n setRenderHtmlContent(pendingHtmlRef.current);\n deferRenderTimerRef.current = null;\n }, POST_IMAGE_STREAM_DEBOUNCE_MS);\n }, [normalizedHtmlContent]);\n\n const rootViewportHeightCss = React.useMemo(\n () =>\n inspectSandboxPrimaryHeightFromHtml(renderHtmlContent).viewportHeightCss,\n [renderHtmlContent]\n );\n const hasRootVhHeight = Boolean(rootViewportHeightCss);\n const sandboxViewportHeight =\n isBlackboardMode && type === \"sandbox\"\n ? shouldStretchRootHeight\n ? \"100%\"\n : (rootViewportHeightCss ?? `${height}px`)\n : undefined;\n const shouldShowHtmlFallbackWhilePreparingSandbox = false;\n useEffect(() => {\n if (mode !== \"blackboard\") {\n prevHtmlRef.current = normalizedHtmlContent;\n return;\n }\n const prev = prevHtmlRef.current;\n const isContinuation = prev && normalizedHtmlContent.startsWith(prev);\n if (!isContinuation && prev) {\n setResetToken((token) => token + 1);\n }\n prevHtmlRef.current = normalizedHtmlContent;\n }, [mode, normalizedHtmlContent]);\n\n useEffect(() => {\n const iframe = iframeRef.current;\n if (!iframe) return undefined;\n\n const doc = iframe.contentDocument;\n if (!doc) return undefined;\n\n doc.open();\n doc.write(`<!DOCTYPE html>\n<html${mode === \"blackboard\" ? ' style=\"height: 100%;\"' : \"\"}>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <style>\n :root { color-scheme: light; }\n html, body, #root { width: 100%; height: 100%; }\n html, body { margin: 0; padding: 0; overflow: auto; }\n *, *::before, *::after { box-sizing: border-box; }\n </style>\n </head>\n <body>\n <div id=\"root\"></div>\n </body>\n</html>`);\n doc.close();\n\n // Force iframe theme to stay in light mode regardless of host OS preference.\n doc.documentElement.setAttribute(\"data-theme\", \"light\");\n doc.documentElement.style.colorScheme = \"light\";\n doc.body?.style.setProperty(\"color-scheme\", \"light\");\n\n docRef.current = doc;\n\n const shouldBridgeSandboxInteraction =\n isBlackboardMode && type === \"sandbox\";\n const handleSandboxPointerDown = () =>\n emitSandboxInteraction(\"pointerdown\");\n const handleSandboxMouseDown = () => emitSandboxInteraction(\"mousedown\");\n const handleSandboxTouchStart = () => emitSandboxInteraction(\"touchstart\");\n\n if (shouldBridgeSandboxInteraction) {\n doc.addEventListener(\"pointerdown\", handleSandboxPointerDown, true);\n doc.addEventListener(\"mousedown\", handleSandboxMouseDown, true);\n doc.addEventListener(\"touchstart\", handleSandboxTouchStart, true);\n }\n\n const rootEl = doc.getElementById(\"root\");\n if (!rootEl) return undefined;\n\n const root = createRoot(rootEl);\n rootRef.current = root;\n let isDestroyed = false;\n\n const parseExplicitHeight = (\n value: string,\n parentViewportHeight: number\n ) => {\n const normalized = value.trim().toLowerCase();\n if (!normalized) return null;\n const numeric = Number.parseFloat(normalized);\n if (Number.isNaN(numeric)) return null;\n if (/(dvh|svh|lvh|vh)$/i.test(normalized)) {\n return (numeric / 100) * parentViewportHeight;\n }\n if (normalized.endsWith(\"px\") || /^[0-9.]+$/.test(normalized)) {\n return numeric;\n }\n return null;\n };\n const parseTailwindHeightClass = (\n className: string,\n parentViewportHeight: number\n ) => {\n if (!className.trim()) return null;\n const viewportHeightCss =\n extractViewportHeightFromTailwindClass(className);\n if (viewportHeightCss) {\n return parseExplicitHeight(viewportHeightCss, parentViewportHeight);\n }\n const normalizedTokens = normalizeTailwindHeightTokens(className);\n const arbitraryToken = normalizedTokens.find((token) =>\n /^h-\\[[0-9.]+px\\]$/i.test(token)\n );\n if (!arbitraryToken) return null;\n const matched = arbitraryToken.match(/^h-\\[([0-9.]+)px\\]$/i);\n if (!matched) return null;\n const numeric = Number.parseFloat(matched[1]);\n if (Number.isNaN(numeric)) return null;\n return numeric;\n };\n\n const resolveExplicitHeight = () => {\n if (!iframeRef.current || !doc.body) return null;\n const parentViewportHeight =\n iframeRef.current.ownerDocument?.documentElement?.clientHeight ||\n window.innerHeight;\n const { viewportHeightCss } = inspectSandboxPrimaryHeight(doc.body);\n const parsed = viewportHeightCss\n ? parseExplicitHeight(viewportHeightCss, parentViewportHeight)\n : null;\n\n if (parsed !== null) {\n return Math.ceil(parsed);\n }\n\n const wrapper = doc.body.querySelector(\n \".sandbox-wrapper\"\n ) as HTMLElement | null;\n const target = wrapper?.querySelector(\n \".sandbox-container > *\"\n ) as HTMLElement | null;\n\n if (!target) return null;\n\n const heightValue = target.style.height || target.getAttribute(\"height\");\n const explicitPixelHeight = heightValue\n ? parseExplicitHeight(heightValue, parentViewportHeight)\n : null;\n\n if (explicitPixelHeight !== null) {\n return Math.ceil(explicitPixelHeight);\n }\n\n const classHeight = parseTailwindHeightClass(\n target.getAttribute(\"class\") || \"\",\n parentViewportHeight\n );\n\n return classHeight !== null ? Math.ceil(classHeight) : null;\n };\n\n const updateHeight = () => {\n if (!iframeRef.current || !doc.body) return;\n const bodyRect = doc.body.getBoundingClientRect();\n const htmlRect = doc.documentElement?.getBoundingClientRect();\n const bodyHeight = bodyRect.height;\n const htmlHeight = htmlRect?.height || 0;\n const contentHeight = Math.max(bodyHeight, htmlHeight);\n const explicitHeight = resolveExplicitHeight();\n const nextHeight = Math.max(\n 200,\n explicitHeight ?? Math.ceil(contentHeight)\n );\n setHeight(nextHeight);\n };\n const scheduleHeightUpdate = () => {\n requestAnimationFrame(() => {\n if (isDestroyed) return;\n updateHeight();\n });\n };\n updateHeightRef.current = scheduleHeightUpdate;\n\n updateHeight();\n scheduleHeightUpdate();\n\n if (!shouldInjectSandboxVendor) {\n setIsSandboxVendorReady(true);\n } else {\n // Inject Tailwind/DaisyUI/GSAP before rendering sandbox content to avoid FOUC.\n loadBlackboardVendorOnDemandWithMetrics()\n .then((inject) => {\n if (isDestroyed) return;\n inject(doc);\n requestAnimationFrame(() => {\n if (isDestroyed) return;\n setIsSandboxVendorReady(true);\n scheduleHeightUpdate();\n });\n })\n .catch(() => {\n if (isDestroyed) return;\n setIsSandboxVendorReady(true);\n scheduleHeightUpdate();\n });\n }\n\n const resizeObserver = new ResizeObserver(() => updateHeight());\n resizeObserver.observe(doc.body);\n if (rootEl) {\n resizeObserver.observe(rootEl);\n }\n\n return () => {\n isDestroyed = true;\n resizeObserver.disconnect();\n if (shouldBridgeSandboxInteraction) {\n doc.removeEventListener(\"pointerdown\", handleSandboxPointerDown, true);\n doc.removeEventListener(\"mousedown\", handleSandboxMouseDown, true);\n doc.removeEventListener(\"touchstart\", handleSandboxTouchStart, true);\n }\n // Defer unmount to avoid React warning when parent is mid-render\n setTimeout(() => {\n root.unmount();\n rootRef.current = null;\n docRef.current = null;\n updateHeightRef.current = () => {};\n }, 0);\n };\n }, []);\n\n useEffect(() => {\n const onFullscreenChange = () => {\n setIsFullscreen(Boolean(document.fullscreenElement));\n };\n document.addEventListener(\"fullscreenchange\", onFullscreenChange);\n return () =>\n document.removeEventListener(\"fullscreenchange\", onFullscreenChange);\n }, []);\n\n const toggleFullscreen = () => {\n const target = containerRef.current || iframeRef.current;\n if (!target) return;\n if (document.fullscreenElement) {\n document.exitFullscreen().catch(() => {});\n return;\n }\n if (target.requestFullscreen) {\n target.requestFullscreen().catch(() => {});\n }\n };\n\n useEffect(() => {\n const root = rootRef.current;\n if (!root) return;\n\n root.render(\n <SandboxApp\n html={renderHtmlContent}\n loadingText={loadingText}\n styleLoadingText={styleLoadingText}\n scriptLoadingText={scriptLoadingText}\n fullScreenButtonText={fullScreenButtonText}\n hideFullScreen={hideFullScreen}\n resetToken={resetToken}\n hasRootVhHeight={hasRootVhHeight}\n mode={mode}\n stretchRootHeight={shouldStretchRootHeight}\n />\n );\n\n initialPaintFrameRef.current = window.requestAnimationFrame(() => {\n updateHeightRef.current?.();\n initialPaintFrameRef.current = null;\n });\n }, [\n renderHtmlContent,\n loadingText,\n styleLoadingText,\n scriptLoadingText,\n fullScreenButtonText,\n resetToken,\n mode,\n ]);\n const containerClassName = [\n \"w-full relative content-render-iframe-sandbox\",\n isBlackboardMode\n ? \"h-full overflow-auto flex flex-col\"\n : \"aspect-[16/9] overflow-hidden flex items-center justify-center\",\n ]\n .filter(Boolean)\n .join(\" \");\n\n const shouldShowSandboxLoading = false;\n\n return (\n <div\n ref={containerRef}\n data-root-vh={hasRootVhHeight ? \"true\" : \"false\"}\n className={containerClassName}\n style={\n sandboxViewportHeight\n ? {\n height: sandboxViewportHeight,\n minHeight: sandboxViewportHeight,\n }\n : undefined\n }\n >\n {!hideFullScreen && (\n <button\n type=\"button\"\n onClick={toggleFullscreen}\n className={\n \"absolute top-2 right-2 z-50 p-1.5 bg-black/75 text-white rounded-md cursor-pointer\"\n }\n >\n {isFullscreen ? \"退出全屏\" : fullScreenButtonText || \"全屏浏览\"}\n </button>\n )}\n {mode === \"blackboard\" && type === \"markdown\" ? (\n <div\n onMouseDown={() => emitSandboxInteraction(\"mousedown\")}\n onPointerDown={() => emitSandboxInteraction(\"pointerdown\")}\n onTouchStart={() => emitSandboxInteraction(\"touchstart\")}\n >\n <ContentRender content={content} />\n </div>\n ) : (\n <>\n {shouldShowHtmlFallbackWhilePreparingSandbox ? (\n <div\n aria-hidden\n className=\"absolute inset-0 z-10 overflow-hidden\"\n style={{\n height: sandboxViewportHeight ?? \"100%\",\n minHeight: sandboxViewportHeight,\n }}\n >\n <div\n className=\"h-full w-full\"\n dangerouslySetInnerHTML={{ __html: renderHtmlContent }}\n />\n </div>\n ) : null}\n <iframe\n ref={iframeRef}\n sandbox=\"allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox\"\n allow=\"fullscreen\"\n allowFullScreen\n className={[className, \"w-full h-full mx-auto my-auto block\"]\n .filter(Boolean)\n .join(\" \")}\n style={{\n height: sandboxViewportHeight ?? \"100%\",\n minHeight: sandboxViewportHeight,\n margin: \"auto\",\n visibility: \"visible\",\n }}\n />\n {shouldShowSandboxLoading ? (\n <div className=\"pointer-events-none absolute inset-0 z-20 flex items-center justify-center\">\n <Loader2\n aria-label={loadingText || \"Preparing sandbox styles\"}\n className=\"text-primary h-7 w-7 animate-spin\"\n />\n </div>\n ) : null}\n </>\n )}\n </div>\n );\n};\n\nexport default IframeSandbox;\n"],"names":["blackboardVendorPromise","loadBlackboardVendor","m","loadBlackboardVendorOnDemandWithMetrics","loadStart","startedAt","inject","error","COMPLETE_IMAGE_TAG_PATTERN","POST_IMAGE_STREAM_DEBOUNCE_MS","SANDBOX_INTERACTION_THROTTLE_MS","normalizeTailwindHeightTokens","className","token","parseViewportHeightCss","value","normalized","matched","extractViewportHeightFromTailwindClass","normalizedTokens","arbitraryToken","SANDBOX_IGNORED_TAG_NAMES","isSandboxRenderableElement","element","getFirstRenderableElementChild","root","node","getInspectableSandboxElementChain","chain","current","childElements","extractViewportHeightFromElement","heightAttrValue","attrViewportHeight","styleHeightValue","styleViewportHeight","isFullViewportHeightCss","inspectSandboxPrimaryHeight","inspectableElements","viewportHeightCss","hasFullViewportHeight","elementViewportHeight","inspectRootHeightFromHtmlString","html","attrs","classAttrValue","inspectSandboxPrimaryHeightFromHtml","template","replaceRootScreenHeightToken","segments","replaceRootScreenHeightWithFullClass","enabled","match","tagStart","classMatch","nextClassName","IframeSandbox","content","type","loadingText","styleLoadingText","scriptLoadingText","fullScreenButtonText","hideFullScreen","mode","replaceRootScreenHeightWithFull","containerRef","useRef","iframeRef","rootRef","docRef","updateHeightRef","height","setHeight","useState","lastSandboxInteractionTimeRef","resetToken","setResetToken","isFullscreen","setIsFullscreen","setIsSandboxVendorReady","shouldInjectSandboxVendor","isBlackboardMode","prevHtmlRef","htmlContent","React","sandboxSegments","splitContentSegments","seg","normalizedHtmlContent","htmlHeightMeta","shouldStretchRootHeight","renderHtmlContent","setRenderHtmlContent","prevIncomingHtmlRef","pendingHtmlRef","deferRenderTimerRef","initialPaintFrameRef","emitSandboxInteraction","useCallback","eventType","now","SANDBOX_INTERACTION_MESSAGE_SOURCE","SANDBOX_INTERACTION_MESSAGE_TYPE","clearDeferredRenderTimer","clearInitialPaintFrames","useEffect","prevIncomingHtml","isAppendOnlyStream","containsCompleteImage","shouldDeferRender","rootViewportHeightCss","hasRootVhHeight","sandboxViewportHeight","prev","iframe","doc","shouldBridgeSandboxInteraction","handleSandboxPointerDown","handleSandboxMouseDown","handleSandboxTouchStart","rootEl","createRoot","isDestroyed","parseExplicitHeight","parentViewportHeight","numeric","parseTailwindHeightClass","resolveExplicitHeight","parsed","target","heightValue","explicitPixelHeight","classHeight","updateHeight","bodyRect","htmlRect","bodyHeight","htmlHeight","contentHeight","explicitHeight","nextHeight","scheduleHeightUpdate","resizeObserver","onFullscreenChange","toggleFullscreen","jsx","SandboxApp","containerClassName","jsxs","ContentRender","Fragment"],"mappings":";;;;;;;AAeA,IAAIA,IAAqE;AAEzE,MAAMC,KAAuB,OACtBD,MACHA,IAA0B,OAAO,2BAAqB,EAAE;AAAA,EACtD,CAACE,MAAMA,EAAE;AAAA,IAINF,IAGHG,KAA0C,MAAM;AACpD,QAAMC,IAAY,YAAY,IAAA,GACxBC,KAAY,oBAAI,KAAA,GAAO,YAAA;AAC7B,iBAAQ,IAAI,sCAAsC,EAAE,WAAAA,EAAA,CAAW,GAExDJ,GAAA,EACJ,KAAK,CAACK,OACL,QAAQ,IAAI,qCAAqC;AAAA,IAC/C,WAAAD;AAAA,IACA,UAAS,oBAAI,KAAA,GAAO,YAAA;AAAA,IACpB,YAAY,QAAQ,YAAY,IAAA,IAAQD,GAAW,QAAQ,CAAC,CAAC;AAAA,EAAA,CAC9D,GACME,EACR,EACA,MAAM,CAACC,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A,gBACL,QAAQqG,KAAyB;AAAA,gBACjC,WAAWA;AAAA,gBACX,QAAQ;AAAA,gBACR,YAAY;AAAA,cAAA;AAAA,YACd;AAAA,UAAA;AAAA,UASE;AAAA,QAAA,EAAA,CACN;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAIR;"}
@@ -1,11 +1,11 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("../../_virtual/jsx-runtime.cjs.js"),t=require("react"),J=require("../../Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/loader-circle.cjs.js"),X=["src","srcset","sizes","alt","class","width","height","style","loading","decoding","crossorigin","referrerpolicy"],F=a=>X.map(r=>`${r}:${a.getAttribute(r)||""}`).join("|"),Y=a=>{const r=new Map;return a.querySelectorAll("img").forEach(l=>{const c=l,n=F(c),f=r.get(n)||[];f.push(c),r.set(n,f)}),r},Z=(a,r)=>{const l=Array.from(a.attributes),c=new Set(l.map(n=>n.name));Array.from(r.attributes).forEach(n=>{c.has(n.name)||r.removeAttribute(n.name)}),l.forEach(n=>{r.setAttribute(n.name,n.value)})},ee=(a,r)=>{r.size&&a.querySelectorAll("img").forEach(l=>{const c=l,n=F(c),f=r.get(n),h=f?.shift();h&&(Z(c,h),c.replaceWith(h),f&&f.length===0&&r.delete(n))})},te=({html:a,styleLoadingText:r,scriptLoadingText:l,resetToken:c=0,mode:n="content",hasRootVhHeight:f=!1})=>{const h=t.useRef(null),w=t.useRef(null),[,T]=t.useState(!0),[H,A]=t.useState(!1),[O,C]=t.useState(!1),I=t.useRef([]),j=t.useRef([]),k=t.useRef(0),q=t.useRef(0),g=t.useRef(null),x=t.useRef(null),b=t.useRef(!1),R=t.useRef(!1),N=t.useRef(!1),L=t.useRef(c),U=200,d=s=>{s.current&&(clearTimeout(s.current),s.current=null)},_=(s,i,u,M)=>{const S=performance.now()-u.current,p=Math.max(0,U-S);d(i),i.current=window.setTimeout(()=>{s(!1),M?.(),i.current=null},p)};t.useEffect(()=>{const s=w.current?.ownerDocument;if(!s)return;const i="sandbox-spinner-style";let u=s.getElementById(i);u||(u=s.createElement("style"),u.id=i,s.head?.appendChild(u)),u.textContent=`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const A=require("../../_virtual/jsx-runtime.cjs.js"),t=require("react"),Y=require("../../Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/loader-circle.cjs.js"),Z=["src","srcset","sizes","alt","class","width","height","style","loading","decoding","crossorigin","referrerpolicy","fetchpriority"],O=a=>Z.map(r=>`${r}:${a.getAttribute(r)||""}`).join("|"),ee=a=>{const r=new Map;return a.querySelectorAll("img").forEach(l=>{const c=l,s=O(c),f=r.get(s)||[];f.push(c),r.set(s,f)}),r},te=(a,r)=>{const l=Array.from(a.attributes),c=new Set(l.map(s=>s.name));Array.from(r.attributes).forEach(s=>{c.has(s.name)||r.removeAttribute(s.name)}),l.forEach(s=>{r.setAttribute(s.name,s.value)})},re=(a,r)=>{r.size&&a.querySelectorAll("img").forEach(l=>{const c=l,s=O(c),f=r.get(s),y=f?.shift();if(!y)return;const g=y.cloneNode(!0);te(c,g),c.replaceWith(g),f&&f.length===0&&r.delete(s)})},se=({html:a,styleLoadingText:r,scriptLoadingText:l,resetToken:c=0,mode:s="content",hasRootVhHeight:f=!1,stretchRootHeight:y=!1})=>{const g=t.useRef(null),C=t.useRef(null),[,_]=t.useState(!0),[U,I]=t.useState(!1),[V,j]=t.useState(!1),N=t.useRef([]),M=t.useRef([]),B=t.useRef(0),D=t.useRef(0),x=t.useRef(null),b=t.useRef(null),R=t.useRef(!1),S=t.useRef(!1),T=t.useRef(!1),G=t.useRef(c),$=200,d=n=>{n.current&&(clearTimeout(n.current),n.current=null)},L=(n,i,u,q)=>{const w=performance.now()-u.current,p=Math.max(0,$-w);d(i),i.current=window.setTimeout(()=>{n(!1),q?.(),i.current=null},p)};t.useEffect(()=>{const n=C.current?.ownerDocument;if(!n)return;const i="sandbox-spinner-style";let u=n.getElementById(i);u||(u=n.createElement("style"),u.id=i,n.head?.appendChild(u)),u.textContent=`
2
2
  @keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }
3
3
  .sandbox-wrapper { align-items: center; }
4
- .sandbox-container { width: 100%; }
4
+ .sandbox-container { position: relative; width: 100%; }
5
5
  .sandbox-container svg,
6
6
  .sandbox-container img { display: block; margin-left: auto; margin-right: auto; }
7
7
  .justify-\\[safe_center\\]{
8
8
  justify-content: safe center;
9
9
  }
10
- `},[]),t.useEffect(()=>{c!==L.current&&(N.current=!1,L.current=c),d(g),d(x),b.current=!1,R.current=!1;const s=w.current;if(!s)return;const i=s.ownerDocument,u=i?.body;if(!u)return;const M=Y(s);I.current.forEach(e=>e.remove()),I.current=[],j.current.forEach(e=>e.remove()),j.current=[];const S=N.current;T(!S),A(!1),C(!1);const p=i.createElement("div");p.innerHTML=a;const D=(a.match(/<script[\s>]/gi)||[]).length,K=(a.match(/<\/script>/gi)||[]).length,P=D>0&&D===K,y=[];Array.from(p.querySelectorAll("style, script")).forEach(e=>{if(e.tagName.toLowerCase()==="style"){const o=i.createElement("style");o.textContent=e.textContent||"",Array.from(e.attributes).forEach(m=>{o.setAttribute(m.name,m.value)}),y.push(o)}else{const o=i.createElement("script");Array.from(e.attributes).forEach(m=>{o.setAttribute(m.name,m.value)}),o.textContent=e.textContent||"",y.push(o)}e.remove()}),ee(p,M);const G=y.some(e=>e.tagName.toLowerCase()==="style"),z=y.some(e=>e.tagName.toLowerCase()==="script");G&&(b.current=!0,k.current=performance.now(),d(g),A(!0)),z&&(R.current=!0,q.current=performance.now(),d(x),C(!0));const W=!!p.firstElementChild;T(!W&&!S),W&&(N.current=!0),s.innerHTML="";const Q=Array.from(p.childNodes);s.append(...Q),y.forEach(e=>{if(e.tagName.toLowerCase()==="style"){i.head?.appendChild(e),I.current.push(e);return}if(P){const o=e,m=o.textContent||"";if(!o.src)try{new Function(m)}catch{o.remove();return}try{u.appendChild(o),j.current.push(o)}catch{o.remove()}}else e.remove()}),requestAnimationFrame(()=>{G&&_(A,g,k,()=>{b.current=!1}),z&&_(C,x,q,()=>{R.current=!1})})},[a,c]),t.useEffect(()=>()=>{d(g),d(x)},[]);const E=O||R.current?l||"Building scripts cache...":H||b.current?r||"Building styles...":null,B=n==="blackboard",V={position:"relative",width:"100%",height:"100%",display:"flex",flexDirection:"column",justifyContent:B?"space-around":"flex-start"},$={pointerEvents:E?"none":void 0,margin:B?void 0:"auto 0",width:"100%"};return v.jsxRuntimeExports.jsxs("div",{ref:h,"data-root-vh":f?"true":"false",className:"sandbox-wrapper",style:V,"aria-busy":!!E,children:[v.jsxRuntimeExports.jsx("div",{ref:w,className:"sandbox-container",style:$}),E&&v.jsxRuntimeExports.jsxs("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(51, 51, 51, 0.80)",color:"#ffffff",fontSize:16,fontWeight:700,gap:10,pointerEvents:"auto",zIndex:20},children:[v.jsxRuntimeExports.jsx(J.default,{"aria-hidden":!0,size:20,style:{animation:"sandbox-spin 1s linear infinite"}}),E]})]})};exports.default=te;
10
+ `},[]),t.useEffect(()=>{c!==G.current&&(T.current=!1,G.current=c),d(x),d(b),R.current=!1,S.current=!1;const n=C.current;if(!n)return;const i=n.ownerDocument,u=i?.body;if(!u)return;const q=ee(n);N.current.forEach(e=>e.remove()),N.current=[],M.current.forEach(e=>e.remove()),M.current=[];const w=T.current;_(!w),I(!1),j(!1);const p=i.createElement("div");p.innerHTML=a;const z=(a.match(/<script[\s>]/gi)||[]).length,Q=(a.match(/<\/script>/gi)||[]).length,J=z>0&&z===Q,h=[];Array.from(p.querySelectorAll("style, script")).forEach(e=>{if(e.tagName.toLowerCase()==="style"){const o=i.createElement("style");o.textContent=e.textContent||"",Array.from(e.attributes).forEach(m=>{o.setAttribute(m.name,m.value)}),h.push(o)}else{const o=i.createElement("script");Array.from(e.attributes).forEach(m=>{o.setAttribute(m.name,m.value)}),o.textContent=e.textContent||"",h.push(o)}e.remove()}),re(p,q);const W=h.some(e=>e.tagName.toLowerCase()==="style"),F=h.some(e=>e.tagName.toLowerCase()==="script");W&&(R.current=!0,B.current=performance.now(),d(x),I(!0)),F&&(S.current=!0,D.current=performance.now(),d(b),j(!0));const H=!!p.firstElementChild;_(!H&&!w),H&&(T.current=!0);const X=Array.from(p.childNodes);n.replaceChildren(...X),h.forEach(e=>{if(e.tagName.toLowerCase()==="style"){i.head?.appendChild(e),N.current.push(e);return}if(J){const o=e,m=o.textContent||"";if(!o.src)try{new Function(m)}catch{o.remove();return}try{u.appendChild(o),M.current.push(o)}catch{o.remove()}}else e.remove()}),requestAnimationFrame(()=>{W&&L(I,x,B,()=>{R.current=!1}),F&&L(j,b,D,()=>{S.current=!1})})},[a,c]),t.useEffect(()=>()=>{d(x),d(b)},[]);const E=V||S.current?l||"Building scripts cache...":U||R.current?r||"Building styles...":null,k=s==="blackboard",v=k&&y,K={position:"relative",width:"100%",height:"100%",display:"flex",flexDirection:"column",justifyContent:v?"flex-start":k?"space-around":"flex-start"},P={pointerEvents:E?"none":void 0,margin:k?void 0:"auto 0",width:"100%",height:v?"100%":void 0,minHeight:v?0:void 0,flex:v?"1 1 auto":void 0};return A.jsxRuntimeExports.jsxs("div",{ref:g,"data-root-vh":f?"true":"false",className:"sandbox-wrapper",style:K,"aria-busy":!!E,children:[A.jsxRuntimeExports.jsx("div",{ref:C,className:"sandbox-container",style:P}),E&&A.jsxRuntimeExports.jsxs("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(51, 51, 51, 0.80)",color:"#ffffff",fontSize:16,fontWeight:700,gap:10,pointerEvents:"auto",zIndex:20},children:[A.jsxRuntimeExports.jsx(Y.default,{"aria-hidden":!0,size:20,style:{animation:"sandbox-spin 1s linear infinite"}}),E]})]})};exports.default=se;
11
11
  //# sourceMappingURL=SandboxApp.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SandboxApp.cjs.js","sources":["../../../src/components/ContentRender/SandboxApp.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport { Loader2 } from \"lucide-react\";\n\nexport interface SandboxAppProps {\n html: string;\n styleLoadingText?: string;\n scriptLoadingText?: string;\n resetToken?: number;\n mode?: \"content\" | \"blackboard\";\n hasRootVhHeight?: boolean;\n}\n\nconst IMAGE_REUSE_ATTRIBUTES = [\n \"src\",\n \"srcset\",\n \"sizes\",\n \"alt\",\n \"class\",\n \"width\",\n \"height\",\n \"style\",\n \"loading\",\n \"decoding\",\n \"crossorigin\",\n \"referrerpolicy\",\n];\n\nconst getImageReuseKey = (image: HTMLImageElement) =>\n IMAGE_REUSE_ATTRIBUTES.map(\n (attribute) => `${attribute}:${image.getAttribute(attribute) || \"\"}`\n ).join(\"|\");\n\nconst collectReusableImages = (root: ParentNode) => {\n const imageMap = new Map<string, HTMLImageElement[]>();\n root.querySelectorAll(\"img\").forEach((node) => {\n const image = node as HTMLImageElement;\n const key = getImageReuseKey(image);\n const bucket = imageMap.get(key) || [];\n bucket.push(image);\n imageMap.set(key, bucket);\n });\n return imageMap;\n};\n\nconst syncImageAttributes = (\n sourceImage: HTMLImageElement,\n targetImage: HTMLImageElement\n) => {\n const sourceAttributes = Array.from(sourceImage.attributes);\n const sourceAttributeNames = new Set(\n sourceAttributes.map((attribute) => attribute.name)\n );\n\n Array.from(targetImage.attributes).forEach((attribute) => {\n if (!sourceAttributeNames.has(attribute.name)) {\n targetImage.removeAttribute(attribute.name);\n }\n });\n\n sourceAttributes.forEach((attribute) => {\n targetImage.setAttribute(attribute.name, attribute.value);\n });\n};\n\nconst reuseRenderedImages = (\n root: ParentNode,\n imageMap: Map<string, HTMLImageElement[]>\n) => {\n if (!imageMap.size) return;\n\n root.querySelectorAll(\"img\").forEach((node) => {\n const nextImage = node as HTMLImageElement;\n const key = getImageReuseKey(nextImage);\n const bucket = imageMap.get(key);\n const preservedImage = bucket?.shift();\n if (!preservedImage) return;\n\n syncImageAttributes(nextImage, preservedImage);\n nextImage.replaceWith(preservedImage);\n\n if (bucket && bucket.length === 0) {\n imageMap.delete(key);\n }\n });\n};\n\nconst SandboxApp: React.FC<SandboxAppProps> = ({\n html,\n styleLoadingText,\n scriptLoadingText,\n resetToken = 0,\n mode = \"content\",\n hasRootVhHeight = false,\n}) => {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const [, setIsWaitingFirstDiv] = useState(true);\n const [isGeneratingStyles, setIsGeneratingStyles] = useState(false);\n const [isGeneratingScripts, setIsGeneratingScripts] = useState(false);\n const appendedStylesRef = useRef<HTMLStyleElement[]>([]);\n const appendedScriptsRef = useRef<HTMLScriptElement[]>([]);\n const styleStartRef = useRef(0);\n const scriptStartRef = useRef(0);\n const styleTimerRef = useRef<number | null>(null);\n const scriptTimerRef = useRef<number | null>(null);\n const hasStylesRef = useRef(false);\n const hasScriptsRef = useRef(false);\n const hasRenderedContentRef = useRef(false);\n const prevResetTokenRef = useRef(resetToken);\n const MIN_LOADING_MS = 200;\n\n const clearTimer = (timerRef: React.MutableRefObject<number | null>) => {\n if (timerRef.current) {\n clearTimeout(timerRef.current);\n timerRef.current = null;\n }\n };\n\n const settleStateWithMinimumDelay = (\n setter: React.Dispatch<React.SetStateAction<boolean>>,\n timerRef: React.MutableRefObject<number | null>,\n startRef: React.MutableRefObject<number>,\n onDone?: () => void\n ) => {\n const elapsed = performance.now() - startRef.current;\n const delay = Math.max(0, MIN_LOADING_MS - elapsed);\n clearTimer(timerRef);\n timerRef.current = window.setTimeout(() => {\n setter(false);\n onDone?.();\n timerRef.current = null;\n }, delay);\n };\n\n useEffect(() => {\n const doc = containerRef.current?.ownerDocument;\n if (!doc) return;\n const styleId = \"sandbox-spinner-style\";\n let styleEl = doc.getElementById(styleId) as HTMLStyleElement | null;\n if (!styleEl) {\n styleEl = doc.createElement(\"style\");\n styleEl.id = styleId;\n doc.head?.appendChild(styleEl);\n }\n styleEl.textContent = `\n @keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }\n .sandbox-wrapper { align-items: center; }\n .sandbox-container { width: 100%; }\n .sandbox-container svg,\n .sandbox-container img { display: block; margin-left: auto; margin-right: auto; }\n .justify-\\\\[safe_center\\\\]{\n justify-content: safe center;\n }\n `;\n }, []);\n\n useEffect(() => {\n if (resetToken !== prevResetTokenRef.current) {\n hasRenderedContentRef.current = false;\n prevResetTokenRef.current = resetToken;\n }\n clearTimer(styleTimerRef);\n clearTimer(scriptTimerRef);\n hasStylesRef.current = false;\n hasScriptsRef.current = false;\n\n const container = containerRef.current;\n if (!container) return;\n const doc = container.ownerDocument;\n const body = doc?.body;\n if (!body) return;\n const reusableImages = collectReusableImages(container);\n\n appendedStylesRef.current.forEach((node) => node.remove());\n appendedStylesRef.current = [];\n appendedScriptsRef.current.forEach((node) => node.remove());\n appendedScriptsRef.current = [];\n\n const hasRenderedBefore = hasRenderedContentRef.current;\n setIsWaitingFirstDiv(!hasRenderedBefore);\n setIsGeneratingStyles(false);\n setIsGeneratingScripts(false);\n const wrapper = doc.createElement(\"div\");\n wrapper.innerHTML = html;\n\n const openScriptCount = (html.match(/<script[\\s>]/gi) || []).length;\n const closeScriptCount = (html.match(/<\\/script>/gi) || []).length;\n const shouldExecuteScripts =\n openScriptCount > 0 && openScriptCount === closeScriptCount;\n\n const resourceQueue: HTMLElement[] = [];\n\n Array.from(wrapper.querySelectorAll(\"style, script\")).forEach((node) => {\n if (node.tagName.toLowerCase() === \"style\") {\n const cloned = doc.createElement(\"style\");\n cloned.textContent = node.textContent || \"\";\n Array.from(node.attributes).forEach((attr) => {\n cloned.setAttribute(attr.name, attr.value);\n });\n resourceQueue.push(cloned);\n } else {\n const replacement = doc.createElement(\"script\");\n Array.from(node.attributes).forEach((attr) => {\n replacement.setAttribute(attr.name, attr.value);\n });\n replacement.textContent = node.textContent || \"\";\n resourceQueue.push(replacement);\n }\n node.remove();\n });\n reuseRenderedImages(wrapper, reusableImages);\n\n const hasStyles = resourceQueue.some(\n (node) => node.tagName.toLowerCase() === \"style\"\n );\n const hasScripts = resourceQueue.some(\n (node) => node.tagName.toLowerCase() === \"script\"\n );\n if (hasStyles) {\n hasStylesRef.current = true;\n styleStartRef.current = performance.now();\n clearTimer(styleTimerRef);\n setIsGeneratingStyles(true);\n }\n if (hasScripts) {\n hasScriptsRef.current = true;\n scriptStartRef.current = performance.now();\n clearTimer(scriptTimerRef);\n setIsGeneratingScripts(true);\n }\n\n const hasFirstElement = !!wrapper.firstElementChild;\n setIsWaitingFirstDiv(!hasFirstElement && !hasRenderedBefore);\n if (hasFirstElement) {\n hasRenderedContentRef.current = true;\n }\n\n container.innerHTML = \"\";\n const contentNodes = Array.from(wrapper.childNodes);\n container.append(...contentNodes);\n\n resourceQueue.forEach((node) => {\n if (node.tagName.toLowerCase() === \"style\") {\n doc.head?.appendChild(node);\n appendedStylesRef.current.push(node as HTMLStyleElement);\n return;\n }\n\n if (shouldExecuteScripts) {\n const scriptNode = node as HTMLScriptElement;\n const scriptText = scriptNode.textContent || \"\";\n const shouldValidate = !scriptNode.src;\n\n if (shouldValidate) {\n try {\n // Validate script is syntactically complete before executing\n\n new Function(scriptText);\n } catch {\n scriptNode.remove();\n return;\n }\n }\n\n try {\n body.appendChild(scriptNode);\n appendedScriptsRef.current.push(scriptNode);\n } catch {\n scriptNode.remove();\n }\n } else {\n // Defer execution until all script tags are fully received\n node.remove();\n }\n });\n requestAnimationFrame(() => {\n if (hasStyles) {\n settleStateWithMinimumDelay(\n setIsGeneratingStyles,\n styleTimerRef,\n styleStartRef,\n () => {\n hasStylesRef.current = false;\n }\n );\n }\n if (hasScripts) {\n settleStateWithMinimumDelay(\n setIsGeneratingScripts,\n scriptTimerRef,\n scriptStartRef,\n () => {\n hasScriptsRef.current = false;\n }\n );\n }\n });\n }, [html, resetToken]);\n\n useEffect(\n () => () => {\n clearTimer(styleTimerRef);\n clearTimer(scriptTimerRef);\n },\n []\n );\n\n const overlayMessage = (() => {\n if (isGeneratingScripts || hasScriptsRef.current)\n return scriptLoadingText || \"Building scripts cache...\";\n if (isGeneratingStyles || hasStylesRef.current)\n return styleLoadingText || \"Building styles...\";\n return null;\n })();\n\n const isBlackboard = mode === \"blackboard\";\n const sandboxWrapperStyle: React.CSSProperties = {\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n flexDirection: \"column\",\n // Keep blackboard scroll behavior while centering content in non-blackboard mode\n justifyContent: isBlackboard ? \"space-around\" : \"flex-start\",\n };\n const sandboxContainerStyle: React.CSSProperties = {\n pointerEvents: overlayMessage ? \"none\" : undefined,\n margin: isBlackboard ? undefined : \"auto 0\",\n width: \"100%\",\n };\n\n return (\n <div\n ref={wrapperRef}\n data-root-vh={hasRootVhHeight ? \"true\" : \"false\"}\n className=\"sandbox-wrapper\"\n style={sandboxWrapperStyle}\n aria-busy={!!overlayMessage}\n >\n <div\n ref={containerRef}\n className=\"sandbox-container\"\n style={sandboxContainerStyle}\n />\n {overlayMessage && (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n background: \"rgba(51, 51, 51, 0.80)\",\n color: \"#ffffff\",\n fontSize: 16,\n fontWeight: 700,\n gap: 10,\n pointerEvents: \"auto\",\n zIndex: 20,\n }}\n >\n <Loader2\n aria-hidden\n size={20}\n style={{ animation: \"sandbox-spin 1s linear infinite\" }}\n />\n {overlayMessage}\n </div>\n )}\n </div>\n );\n};\n\nexport default SandboxApp;\n"],"names":["IMAGE_REUSE_ATTRIBUTES","getImageReuseKey","image","attribute","collectReusableImages","root","imageMap","node","key","bucket","syncImageAttributes","sourceImage","targetImage","sourceAttributes","sourceAttributeNames","reuseRenderedImages","nextImage","preservedImage","SandboxApp","html","styleLoadingText","scriptLoadingText","resetToken","mode","hasRootVhHeight","wrapperRef","useRef","containerRef","setIsWaitingFirstDiv","useState","isGeneratingStyles","setIsGeneratingStyles","isGeneratingScripts","setIsGeneratingScripts","appendedStylesRef","appendedScriptsRef","styleStartRef","scriptStartRef","styleTimerRef","scriptTimerRef","hasStylesRef","hasScriptsRef","hasRenderedContentRef","prevResetTokenRef","MIN_LOADING_MS","clearTimer","timerRef","settleStateWithMinimumDelay","setter","startRef","onDone","elapsed","delay","useEffect","doc","styleId","styleEl","container","body","reusableImages","hasRenderedBefore","wrapper","openScriptCount","closeScriptCount","shouldExecuteScripts","resourceQueue","cloned","attr","replacement","hasStyles","hasScripts","hasFirstElement","contentNodes","scriptNode","scriptText","overlayMessage","isBlackboard","sandboxWrapperStyle","sandboxContainerStyle","jsxs","jsx","Loader2"],"mappings":"8VAYMA,EAAyB,CAC7B,MACA,SACA,QACA,MACA,QACA,QACA,SACA,QACA,UACA,WACA,cACA,gBACF,EAEMC,EAAoBC,GACxBF,EAAuB,IACpBG,GAAc,GAAGA,CAAS,IAAID,EAAM,aAAaC,CAAS,GAAK,EAAE,EACpE,EAAE,KAAK,GAAG,EAENC,EAAyBC,GAAqB,CAClD,MAAMC,MAAe,IACrB,OAAAD,EAAK,iBAAiB,KAAK,EAAE,QAASE,GAAS,CAC7C,MAAML,EAAQK,EACRC,EAAMP,EAAiBC,CAAK,EAC5BO,EAASH,EAAS,IAAIE,CAAG,GAAK,CAAA,EACpCC,EAAO,KAAKP,CAAK,EACjBI,EAAS,IAAIE,EAAKC,CAAM,CAC1B,CAAC,EACMH,CACT,EAEMI,EAAsB,CAC1BC,EACAC,IACG,CACH,MAAMC,EAAmB,MAAM,KAAKF,EAAY,UAAU,EACpDG,EAAuB,IAAI,IAC/BD,EAAiB,IAAKV,GAAcA,EAAU,IAAI,CAAA,EAGpD,MAAM,KAAKS,EAAY,UAAU,EAAE,QAAST,GAAc,CACnDW,EAAqB,IAAIX,EAAU,IAAI,GAC1CS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f,eAAgBD,EAAe,eAAiB,YAAA,EAE5CE,EAA6C,CACjD,cAAeH,EAAiB,OAAS,OACzC,OAAQC,EAAe,OAAY,SACnC,MAAO,MAAA,EAGT,OACEG,EAAAA,kBAAAA,KAAC,MAAA,CACC,IAAKtD,EACL,eAAcD,EAAkB,OAAS,QACzC,UAAU,kBACV,MAAOqD,EACP,YAAW,CAAC,CAACF,EAEb,SAAA,CAAAK,EAAAA,kBAAAA,IAAC,MAAA,CACC,IAAKrD,EACL,UAAU,oBACV,MAAOmD,CAAA,CAAA,EAERH,GACCI,EAAAA,kBAAAA,KAAC,MAAA,CACC,MAAO,CACL,SAAU,WACV,MAAO,EACP,QAAS,OACT,WAAY,SACZ,eAAgB,SAChB,WAAY,yBACZ,MAAO,UACP,SAAU,GACV,WAAY,IACZ,IAAK,GACL,cAAe,OACf,OAAQ,EAAA,EAGV,SAAA,CAAAC,EAAAA,kBAAAA,IAACC,EAAAA,QAAA,CACC,cAAW,GACX,KAAM,GACN,MAAO,CAAE,UAAW,iCAAA,CAAkC,CAAA,EAEvDN,CAAA,CAAA,CAAA,CACH,CAAA,CAAA,CAIR"}
1
+ {"version":3,"file":"SandboxApp.cjs.js","sources":["../../../src/components/ContentRender/SandboxApp.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport { Loader2 } from \"lucide-react\";\n\nexport interface SandboxAppProps {\n html: string;\n loadingText?: string;\n styleLoadingText?: string;\n scriptLoadingText?: string;\n fullScreenButtonText?: string;\n hideFullScreen?: boolean;\n resetToken?: number;\n mode?: \"content\" | \"blackboard\";\n hasRootVhHeight?: boolean;\n stretchRootHeight?: boolean;\n}\n\nconst IMAGE_REUSE_ATTRIBUTES = [\n \"src\",\n \"srcset\",\n \"sizes\",\n \"alt\",\n \"class\",\n \"width\",\n \"height\",\n \"style\",\n \"loading\",\n \"decoding\",\n \"crossorigin\",\n \"referrerpolicy\",\n \"fetchpriority\",\n];\n\nconst getImageReuseKey = (image: HTMLImageElement) =>\n IMAGE_REUSE_ATTRIBUTES.map(\n (attribute) => `${attribute}:${image.getAttribute(attribute) || \"\"}`\n ).join(\"|\");\n\nconst collectReusableImages = (root: ParentNode) => {\n const imageMap = new Map<string, HTMLImageElement[]>();\n root.querySelectorAll(\"img\").forEach((node) => {\n const image = node as HTMLImageElement;\n const key = getImageReuseKey(image);\n const bucket = imageMap.get(key) || [];\n bucket.push(image);\n imageMap.set(key, bucket);\n });\n return imageMap;\n};\n\nconst syncImageAttributes = (\n sourceImage: HTMLImageElement,\n targetImage: HTMLImageElement\n) => {\n const sourceAttributes = Array.from(sourceImage.attributes);\n const sourceAttributeNames = new Set(\n sourceAttributes.map((attribute) => attribute.name)\n );\n\n Array.from(targetImage.attributes).forEach((attribute) => {\n if (!sourceAttributeNames.has(attribute.name)) {\n targetImage.removeAttribute(attribute.name);\n }\n });\n\n sourceAttributes.forEach((attribute) => {\n targetImage.setAttribute(attribute.name, attribute.value);\n });\n};\n\nconst reuseRenderedImages = (\n root: ParentNode,\n imageMap: Map<string, HTMLImageElement[]>\n) => {\n if (!imageMap.size) return;\n\n root.querySelectorAll(\"img\").forEach((node) => {\n const nextImage = node as HTMLImageElement;\n const key = getImageReuseKey(nextImage);\n const bucket = imageMap.get(key);\n const preservedImage = bucket?.shift();\n if (!preservedImage) return;\n\n // Clone the already-rendered image instead of moving the live node out of\n // the visible tree before the next DOM commit.\n const clonedImage = preservedImage.cloneNode(true) as HTMLImageElement;\n syncImageAttributes(nextImage, clonedImage);\n nextImage.replaceWith(clonedImage);\n\n if (bucket && bucket.length === 0) {\n imageMap.delete(key);\n }\n });\n};\n\nconst SandboxApp: React.FC<SandboxAppProps> = ({\n html,\n styleLoadingText,\n scriptLoadingText,\n resetToken = 0,\n mode = \"content\",\n hasRootVhHeight = false,\n stretchRootHeight = false,\n}) => {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const [, setIsWaitingFirstDiv] = useState(true);\n const [isGeneratingStyles, setIsGeneratingStyles] = useState(false);\n const [isGeneratingScripts, setIsGeneratingScripts] = useState(false);\n const appendedStylesRef = useRef<HTMLStyleElement[]>([]);\n const appendedScriptsRef = useRef<HTMLScriptElement[]>([]);\n const styleStartRef = useRef(0);\n const scriptStartRef = useRef(0);\n const styleTimerRef = useRef<number | null>(null);\n const scriptTimerRef = useRef<number | null>(null);\n const hasStylesRef = useRef(false);\n const hasScriptsRef = useRef(false);\n const hasRenderedContentRef = useRef(false);\n const prevResetTokenRef = useRef(resetToken);\n const MIN_LOADING_MS = 200;\n\n const clearTimer = (timerRef: React.MutableRefObject<number | null>) => {\n if (timerRef.current) {\n clearTimeout(timerRef.current);\n timerRef.current = null;\n }\n };\n\n const settleStateWithMinimumDelay = (\n setter: React.Dispatch<React.SetStateAction<boolean>>,\n timerRef: React.MutableRefObject<number | null>,\n startRef: React.MutableRefObject<number>,\n onDone?: () => void\n ) => {\n const elapsed = performance.now() - startRef.current;\n const delay = Math.max(0, MIN_LOADING_MS - elapsed);\n clearTimer(timerRef);\n timerRef.current = window.setTimeout(() => {\n setter(false);\n onDone?.();\n timerRef.current = null;\n }, delay);\n };\n\n useEffect(() => {\n const doc = containerRef.current?.ownerDocument;\n if (!doc) return;\n const styleId = \"sandbox-spinner-style\";\n let styleEl = doc.getElementById(styleId) as HTMLStyleElement | null;\n if (!styleEl) {\n styleEl = doc.createElement(\"style\");\n styleEl.id = styleId;\n doc.head?.appendChild(styleEl);\n }\n styleEl.textContent = `\n @keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }\n .sandbox-wrapper { align-items: center; }\n .sandbox-container { position: relative; width: 100%; }\n .sandbox-container svg,\n .sandbox-container img { display: block; margin-left: auto; margin-right: auto; }\n .justify-\\\\[safe_center\\\\]{\n justify-content: safe center;\n }\n `;\n }, []);\n\n useEffect(() => {\n if (resetToken !== prevResetTokenRef.current) {\n hasRenderedContentRef.current = false;\n prevResetTokenRef.current = resetToken;\n }\n clearTimer(styleTimerRef);\n clearTimer(scriptTimerRef);\n hasStylesRef.current = false;\n hasScriptsRef.current = false;\n\n const container = containerRef.current;\n if (!container) return;\n const doc = container.ownerDocument;\n const body = doc?.body;\n if (!body) return;\n const reusableImages = collectReusableImages(container);\n\n appendedStylesRef.current.forEach((node) => node.remove());\n appendedStylesRef.current = [];\n appendedScriptsRef.current.forEach((node) => node.remove());\n appendedScriptsRef.current = [];\n\n const hasRenderedBefore = hasRenderedContentRef.current;\n setIsWaitingFirstDiv(!hasRenderedBefore);\n setIsGeneratingStyles(false);\n setIsGeneratingScripts(false);\n const wrapper = doc.createElement(\"div\");\n wrapper.innerHTML = html;\n\n const openScriptCount = (html.match(/<script[\\s>]/gi) || []).length;\n const closeScriptCount = (html.match(/<\\/script>/gi) || []).length;\n const shouldExecuteScripts =\n openScriptCount > 0 && openScriptCount === closeScriptCount;\n\n const resourceQueue: HTMLElement[] = [];\n\n Array.from(wrapper.querySelectorAll(\"style, script\")).forEach((node) => {\n if (node.tagName.toLowerCase() === \"style\") {\n const cloned = doc.createElement(\"style\");\n cloned.textContent = node.textContent || \"\";\n Array.from(node.attributes).forEach((attr) => {\n cloned.setAttribute(attr.name, attr.value);\n });\n resourceQueue.push(cloned);\n } else {\n const replacement = doc.createElement(\"script\");\n Array.from(node.attributes).forEach((attr) => {\n replacement.setAttribute(attr.name, attr.value);\n });\n replacement.textContent = node.textContent || \"\";\n resourceQueue.push(replacement);\n }\n node.remove();\n });\n reuseRenderedImages(wrapper, reusableImages);\n\n const hasStyles = resourceQueue.some(\n (node) => node.tagName.toLowerCase() === \"style\"\n );\n const hasScripts = resourceQueue.some(\n (node) => node.tagName.toLowerCase() === \"script\"\n );\n if (hasStyles) {\n hasStylesRef.current = true;\n styleStartRef.current = performance.now();\n clearTimer(styleTimerRef);\n setIsGeneratingStyles(true);\n }\n if (hasScripts) {\n hasScriptsRef.current = true;\n scriptStartRef.current = performance.now();\n clearTimer(scriptTimerRef);\n setIsGeneratingScripts(true);\n }\n\n const hasFirstElement = !!wrapper.firstElementChild;\n setIsWaitingFirstDiv(!hasFirstElement && !hasRenderedBefore);\n if (hasFirstElement) {\n hasRenderedContentRef.current = true;\n }\n\n const contentNodes = Array.from(wrapper.childNodes);\n container.replaceChildren(...contentNodes);\n\n resourceQueue.forEach((node) => {\n if (node.tagName.toLowerCase() === \"style\") {\n doc.head?.appendChild(node);\n appendedStylesRef.current.push(node as HTMLStyleElement);\n return;\n }\n\n if (shouldExecuteScripts) {\n const scriptNode = node as HTMLScriptElement;\n const scriptText = scriptNode.textContent || \"\";\n const shouldValidate = !scriptNode.src;\n\n if (shouldValidate) {\n try {\n // Validate script is syntactically complete before executing\n\n new Function(scriptText);\n } catch {\n scriptNode.remove();\n return;\n }\n }\n\n try {\n body.appendChild(scriptNode);\n appendedScriptsRef.current.push(scriptNode);\n } catch {\n scriptNode.remove();\n }\n } else {\n // Defer execution until all script tags are fully received\n node.remove();\n }\n });\n requestAnimationFrame(() => {\n if (hasStyles) {\n settleStateWithMinimumDelay(\n setIsGeneratingStyles,\n styleTimerRef,\n styleStartRef,\n () => {\n hasStylesRef.current = false;\n }\n );\n }\n if (hasScripts) {\n settleStateWithMinimumDelay(\n setIsGeneratingScripts,\n scriptTimerRef,\n scriptStartRef,\n () => {\n hasScriptsRef.current = false;\n }\n );\n }\n });\n }, [html, resetToken]);\n\n useEffect(\n () => () => {\n clearTimer(styleTimerRef);\n clearTimer(scriptTimerRef);\n },\n []\n );\n\n const overlayMessage = (() => {\n if (isGeneratingScripts || hasScriptsRef.current)\n return scriptLoadingText || \"Building scripts cache...\";\n if (isGeneratingStyles || hasStylesRef.current)\n return styleLoadingText || \"Building styles...\";\n return null;\n })();\n\n const isBlackboard = mode === \"blackboard\";\n const shouldStretchRootHeight = isBlackboard && stretchRootHeight;\n const sandboxWrapperStyle: React.CSSProperties = {\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n flexDirection: \"column\",\n // Keep blackboard scroll behavior while centering content in non-blackboard mode\n justifyContent: shouldStretchRootHeight\n ? \"flex-start\"\n : isBlackboard\n ? \"space-around\"\n : \"flex-start\",\n };\n const sandboxContainerStyle: React.CSSProperties = {\n pointerEvents: overlayMessage ? \"none\" : undefined,\n margin: isBlackboard ? undefined : \"auto 0\",\n width: \"100%\",\n height: shouldStretchRootHeight ? \"100%\" : undefined,\n minHeight: shouldStretchRootHeight ? 0 : undefined,\n flex: shouldStretchRootHeight ? \"1 1 auto\" : undefined,\n };\n\n return (\n <div\n ref={wrapperRef}\n data-root-vh={hasRootVhHeight ? \"true\" : \"false\"}\n className=\"sandbox-wrapper\"\n style={sandboxWrapperStyle}\n aria-busy={!!overlayMessage}\n >\n <div\n ref={containerRef}\n className=\"sandbox-container\"\n style={sandboxContainerStyle}\n />\n {overlayMessage && (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n background: \"rgba(51, 51, 51, 0.80)\",\n color: \"#ffffff\",\n fontSize: 16,\n fontWeight: 700,\n gap: 10,\n pointerEvents: \"auto\",\n zIndex: 20,\n }}\n >\n <Loader2\n aria-hidden\n size={20}\n style={{ animation: \"sandbox-spin 1s linear infinite\" }}\n />\n {overlayMessage}\n </div>\n )}\n </div>\n );\n};\n\nexport default SandboxApp;\n"],"names":["IMAGE_REUSE_ATTRIBUTES","getImageReuseKey","image","attribute","collectReusableImages","root","imageMap","node","key","bucket","syncImageAttributes","sourceImage","targetImage","sourceAttributes","sourceAttributeNames","reuseRenderedImages","nextImage","preservedImage","clonedImage","SandboxApp","html","styleLoadingText","scriptLoadingText","resetToken","mode","hasRootVhHeight","stretchRootHeight","wrapperRef","useRef","containerRef","setIsWaitingFirstDiv","useState","isGeneratingStyles","setIsGeneratingStyles","isGeneratingScripts","setIsGeneratingScripts","appendedStylesRef","appendedScriptsRef","styleStartRef","scriptStartRef","styleTimerRef","scriptTimerRef","hasStylesRef","hasScriptsRef","hasRenderedContentRef","prevResetTokenRef","MIN_LOADING_MS","clearTimer","timerRef","settleStateWithMinimumDelay","setter","startRef","onDone","elapsed","delay","useEffect","doc","styleId","styleEl","container","body","reusableImages","hasRenderedBefore","wrapper","openScriptCount","closeScriptCount","shouldExecuteScripts","resourceQueue","cloned","attr","replacement","hasStyles","hasScripts","hasFirstElement","contentNodes","scriptNode","scriptText","overlayMessage","isBlackboard","shouldStretchRootHeight","sandboxWrapperStyle","sandboxContainerStyle","jsxs","jsx","Loader2"],"mappings":"8VAgBMA,EAAyB,CAC7B,MACA,SACA,QACA,MACA,QACA,QACA,SACA,QACA,UACA,WACA,cACA,iBACA,eACF,EAEMC,EAAoBC,GACxBF,EAAuB,IACpBG,GAAc,GAAGA,CAAS,IAAID,EAAM,aAAaC,CAAS,GAAK,EAAE,EACpE,EAAE,KAAK,GAAG,EAENC,GAAyBC,GAAqB,CAClD,MAAMC,MAAe,IACrB,OAAAD,EAAK,iBAAiB,KAAK,EAAE,QAASE,GAAS,CAC7C,MAAML,EAAQK,EACRC,EAAMP,EAAiBC,CAAK,EAC5BO,EAASH,EAAS,IAAIE,CAAG,GAAK,CAAA,EACpCC,EAAO,KAAKP,CAAK,EACjBI,EAAS,IAAIE,EAAKC,CAAM,CAC1B,CAAC,EACMH,CACT,EAEMI,GAAsB,CAC1BC,EACAC,IACG,CACH,MAAMC,EAAmB,MAAM,KAAKF,EAAY,UAAU,EACpDG,EAAuB,IAAI,IAC/BD,EAAiB,IAAKV,GAAcA,EAAU,IAAI,CAAA,EAGpD,MAAM,KAAKS,EAAY,UAAU,EAAE,QAAST,GAAc,CACnDW,EAAqB,IAAIX,EAAU,IAAI,GAC1CS,EAAY,gBAAgBT,EAAU,IAAI,CAE9C,CAAC,EAEDU,EAAiB,QAASV,GAAc,CACtCS,EAAY,aAAaT,EAAU,KAAMA,EAAU,KAAK,CAC1D,CAAC,CACH,EAEMY,GAAsB,CAC1BV,EACAC,IACG,CACEA,EAAS,MAEdD,EAAK,iBAAiB,KAAK,EAAE,QAASE,GA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,EAA0B,OAAS,OAC3C,UAAWA,EAA0B,EAAI,OACzC,KAAMA,EAA0B,WAAa,MAAA,EAG/C,OACEG,EAAAA,kBAAAA,KAAC,MAAA,CACC,IAAKvD,EACL,eAAcF,EAAkB,OAAS,QACzC,UAAU,kBACV,MAAOuD,EACP,YAAW,CAAC,CAACH,EAEb,SAAA,CAAAM,EAAAA,kBAAAA,IAAC,MAAA,CACC,IAAKtD,EACL,UAAU,oBACV,MAAOoD,CAAA,CAAA,EAERJ,GACCK,EAAAA,kBAAAA,KAAC,MAAA,CACC,MAAO,CACL,SAAU,WACV,MAAO,EACP,QAAS,OACT,WAAY,SACZ,eAAgB,SAChB,WAAY,yBACZ,MAAO,UACP,SAAU,GACV,WAAY,IACZ,IAAK,GACL,cAAe,OACf,OAAQ,EAAA,EAGV,SAAA,CAAAC,EAAAA,kBAAAA,IAACC,EAAAA,QAAA,CACC,cAAW,GACX,KAAM,GACN,MAAO,CAAE,UAAW,iCAAA,CAAkC,CAAA,EAEvDP,CAAA,CAAA,CAAA,CACH,CAAA,CAAA,CAIR"}
@@ -1,11 +1,15 @@
1
1
  import { default as React } from 'react';
2
2
  export interface SandboxAppProps {
3
3
  html: string;
4
+ loadingText?: string;
4
5
  styleLoadingText?: string;
5
6
  scriptLoadingText?: string;
7
+ fullScreenButtonText?: string;
8
+ hideFullScreen?: boolean;
6
9
  resetToken?: number;
7
10
  mode?: "content" | "blackboard";
8
11
  hasRootVhHeight?: boolean;
12
+ stretchRootHeight?: boolean;
9
13
  }
10
14
  declare const SandboxApp: React.FC<SandboxAppProps>;
11
15
  export default SandboxApp;
@@ -1,7 +1,7 @@
1
- import { j as w } from "../../_virtual/jsx-runtime.es.js";
2
- import { useRef as i, useState as L, useEffect as M } from "react";
3
- import Y from "../../Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/loader-circle.es.js";
4
- const Z = [
1
+ import { j as C } from "../../_virtual/jsx-runtime.es.js";
2
+ import { useRef as i, useState as B, useEffect as D } from "react";
3
+ import ee from "../../Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/loader-circle.es.js";
4
+ const te = [
5
5
  "src",
6
6
  "srcset",
7
7
  "sizes",
@@ -13,102 +13,106 @@ const Z = [
13
13
  "loading",
14
14
  "decoding",
15
15
  "crossorigin",
16
- "referrerpolicy"
17
- ], U = (c) => Z.map(
16
+ "referrerpolicy",
17
+ "fetchpriority"
18
+ ], $ = (c) => te.map(
18
19
  (t) => `${t}:${c.getAttribute(t) || ""}`
19
- ).join("|"), ee = (c) => {
20
+ ).join("|"), re = (c) => {
20
21
  const t = /* @__PURE__ */ new Map();
21
22
  return c.querySelectorAll("img").forEach((u) => {
22
- const o = u, n = U(o), f = t.get(n) || [];
23
- f.push(o), t.set(n, f);
23
+ const o = u, r = $(o), f = t.get(r) || [];
24
+ f.push(o), t.set(r, f);
24
25
  }), t;
25
- }, te = (c, t) => {
26
+ }, ne = (c, t) => {
26
27
  const u = Array.from(c.attributes), o = new Set(
27
- u.map((n) => n.name)
28
+ u.map((r) => r.name)
28
29
  );
29
- Array.from(t.attributes).forEach((n) => {
30
- o.has(n.name) || t.removeAttribute(n.name);
31
- }), u.forEach((n) => {
32
- t.setAttribute(n.name, n.value);
30
+ Array.from(t.attributes).forEach((r) => {
31
+ o.has(r.name) || t.removeAttribute(r.name);
32
+ }), u.forEach((r) => {
33
+ t.setAttribute(r.name, r.value);
33
34
  });
34
- }, re = (c, t) => {
35
+ }, se = (c, t) => {
35
36
  t.size && c.querySelectorAll("img").forEach((u) => {
36
- const o = u, n = U(o), f = t.get(n), h = f?.shift();
37
- h && (te(o, h), o.replaceWith(h), f && f.length === 0 && t.delete(n));
37
+ const o = u, r = $(o), f = t.get(r), y = f?.shift();
38
+ if (!y) return;
39
+ const g = y.cloneNode(!0);
40
+ ne(o, g), o.replaceWith(g), f && f.length === 0 && t.delete(r);
38
41
  });
39
- }, ae = ({
42
+ }, le = ({
40
43
  html: c,
41
44
  styleLoadingText: t,
42
45
  scriptLoadingText: u,
43
46
  resetToken: o = 0,
44
- mode: n = "content",
45
- hasRootVhHeight: f = !1
47
+ mode: r = "content",
48
+ hasRootVhHeight: f = !1,
49
+ stretchRootHeight: y = !1
46
50
  }) => {
47
- const h = i(null), A = i(null), [, k] = L(!0), [V, C] = L(!1), [$, R] = L(!1), I = i([]), N = i([]), B = i(0), D = i(0), g = i(null), b = i(null), x = i(!1), S = i(!1), j = i(!1), G = i(o), K = 200, d = (r) => {
48
- r.current && (clearTimeout(r.current), r.current = null);
49
- }, z = (r, a, l, T) => {
50
- const v = performance.now() - l.current, p = Math.max(0, K - v);
51
+ const g = i(null), R = i(null), [, G] = B(!0), [K, I] = B(!1), [O, N] = B(!1), j = i([]), T = i([]), z = i(0), W = i(0), x = i(null), b = i(null), v = i(!1), S = i(!1), k = i(!1), _ = i(o), Q = 200, d = (n) => {
52
+ n.current && (clearTimeout(n.current), n.current = null);
53
+ }, q = (n, a, l, M) => {
54
+ const A = performance.now() - l.current, p = Math.max(0, Q - A);
51
55
  d(a), a.current = window.setTimeout(() => {
52
- r(!1), T?.(), a.current = null;
56
+ n(!1), M?.(), a.current = null;
53
57
  }, p);
54
58
  };
55
- M(() => {
56
- const r = A.current?.ownerDocument;
57
- if (!r) return;
59
+ D(() => {
60
+ const n = R.current?.ownerDocument;
61
+ if (!n) return;
58
62
  const a = "sandbox-spinner-style";
59
- let l = r.getElementById(a);
60
- l || (l = r.createElement("style"), l.id = a, r.head?.appendChild(l)), l.textContent = `
63
+ let l = n.getElementById(a);
64
+ l || (l = n.createElement("style"), l.id = a, n.head?.appendChild(l)), l.textContent = `
61
65
  @keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }
62
66
  .sandbox-wrapper { align-items: center; }
63
- .sandbox-container { width: 100%; }
67
+ .sandbox-container { position: relative; width: 100%; }
64
68
  .sandbox-container svg,
65
69
  .sandbox-container img { display: block; margin-left: auto; margin-right: auto; }
66
70
  .justify-\\[safe_center\\]{
67
71
  justify-content: safe center;
68
72
  }
69
73
  `;
70
- }, []), M(() => {
71
- o !== G.current && (j.current = !1, G.current = o), d(g), d(b), x.current = !1, S.current = !1;
72
- const r = A.current;
73
- if (!r) return;
74
- const a = r.ownerDocument, l = a?.body;
74
+ }, []), D(() => {
75
+ o !== _.current && (k.current = !1, _.current = o), d(x), d(b), v.current = !1, S.current = !1;
76
+ const n = R.current;
77
+ if (!n) return;
78
+ const a = n.ownerDocument, l = a?.body;
75
79
  if (!l) return;
76
- const T = ee(r);
77
- I.current.forEach((e) => e.remove()), I.current = [], N.current.forEach((e) => e.remove()), N.current = [];
78
- const v = j.current;
79
- k(!v), C(!1), R(!1);
80
+ const M = re(n);
81
+ j.current.forEach((e) => e.remove()), j.current = [], T.current.forEach((e) => e.remove()), T.current = [];
82
+ const A = k.current;
83
+ G(!A), I(!1), N(!1);
80
84
  const p = a.createElement("div");
81
85
  p.innerHTML = c;
82
- const _ = (c.match(/<script[\s>]/gi) || []).length, J = (c.match(/<\/script>/gi) || []).length, P = _ > 0 && _ === J, y = [];
86
+ const F = (c.match(/<script[\s>]/gi) || []).length, X = (c.match(/<\/script>/gi) || []).length, Y = F > 0 && F === X, h = [];
83
87
  Array.from(p.querySelectorAll("style, script")).forEach((e) => {
84
88
  if (e.tagName.toLowerCase() === "style") {
85
89
  const s = a.createElement("style");
86
90
  s.textContent = e.textContent || "", Array.from(e.attributes).forEach((m) => {
87
91
  s.setAttribute(m.name, m.value);
88
- }), y.push(s);
92
+ }), h.push(s);
89
93
  } else {
90
94
  const s = a.createElement("script");
91
95
  Array.from(e.attributes).forEach((m) => {
92
96
  s.setAttribute(m.name, m.value);
93
- }), s.textContent = e.textContent || "", y.push(s);
97
+ }), s.textContent = e.textContent || "", h.push(s);
94
98
  }
95
99
  e.remove();
96
- }), re(p, T);
97
- const q = y.some(
100
+ }), se(p, M);
101
+ const H = h.some(
98
102
  (e) => e.tagName.toLowerCase() === "style"
99
- ), F = y.some(
103
+ ), U = h.some(
100
104
  (e) => e.tagName.toLowerCase() === "script"
101
105
  );
102
- q && (x.current = !0, B.current = performance.now(), d(g), C(!0)), F && (S.current = !0, D.current = performance.now(), d(b), R(!0));
103
- const H = !!p.firstElementChild;
104
- k(!H && !v), H && (j.current = !0), r.innerHTML = "";
105
- const X = Array.from(p.childNodes);
106
- r.append(...X), y.forEach((e) => {
106
+ H && (v.current = !0, z.current = performance.now(), d(x), I(!0)), U && (S.current = !0, W.current = performance.now(), d(b), N(!0));
107
+ const V = !!p.firstElementChild;
108
+ G(!V && !A), V && (k.current = !0);
109
+ const Z = Array.from(p.childNodes);
110
+ n.replaceChildren(...Z), h.forEach((e) => {
107
111
  if (e.tagName.toLowerCase() === "style") {
108
- a.head?.appendChild(e), I.current.push(e);
112
+ a.head?.appendChild(e), j.current.push(e);
109
113
  return;
110
114
  }
111
- if (P) {
115
+ if (Y) {
112
116
  const s = e, m = s.textContent || "";
113
117
  if (!s.src)
114
118
  try {
@@ -118,66 +122,69 @@ const Z = [
118
122
  return;
119
123
  }
120
124
  try {
121
- l.appendChild(s), N.current.push(s);
125
+ l.appendChild(s), T.current.push(s);
122
126
  } catch {
123
127
  s.remove();
124
128
  }
125
129
  } else
126
130
  e.remove();
127
131
  }), requestAnimationFrame(() => {
128
- q && z(
129
- C,
130
- g,
131
- B,
132
+ H && q(
133
+ I,
134
+ x,
135
+ z,
132
136
  () => {
133
- x.current = !1;
137
+ v.current = !1;
134
138
  }
135
- ), F && z(
136
- R,
139
+ ), U && q(
140
+ N,
137
141
  b,
138
- D,
142
+ W,
139
143
  () => {
140
144
  S.current = !1;
141
145
  }
142
146
  );
143
147
  });
144
- }, [c, o]), M(
148
+ }, [c, o]), D(
145
149
  () => () => {
146
- d(g), d(b);
150
+ d(x), d(b);
147
151
  },
148
152
  []
149
153
  );
150
- const E = $ || S.current ? u || "Building scripts cache..." : V || x.current ? t || "Building styles..." : null, W = n === "blackboard", O = {
154
+ const E = O || S.current ? u || "Building scripts cache..." : K || v.current ? t || "Building styles..." : null, L = r === "blackboard", w = L && y, J = {
151
155
  position: "relative",
152
156
  width: "100%",
153
157
  height: "100%",
154
158
  display: "flex",
155
159
  flexDirection: "column",
156
160
  // Keep blackboard scroll behavior while centering content in non-blackboard mode
157
- justifyContent: W ? "space-around" : "flex-start"
158
- }, Q = {
161
+ justifyContent: w ? "flex-start" : L ? "space-around" : "flex-start"
162
+ }, P = {
159
163
  pointerEvents: E ? "none" : void 0,
160
- margin: W ? void 0 : "auto 0",
161
- width: "100%"
164
+ margin: L ? void 0 : "auto 0",
165
+ width: "100%",
166
+ height: w ? "100%" : void 0,
167
+ minHeight: w ? 0 : void 0,
168
+ flex: w ? "1 1 auto" : void 0
162
169
  };
163
- return /* @__PURE__ */ w.jsxs(
170
+ return /* @__PURE__ */ C.jsxs(
164
171
  "div",
165
172
  {
166
- ref: h,
173
+ ref: g,
167
174
  "data-root-vh": f ? "true" : "false",
168
175
  className: "sandbox-wrapper",
169
- style: O,
176
+ style: J,
170
177
  "aria-busy": !!E,
171
178
  children: [
172
- /* @__PURE__ */ w.jsx(
179
+ /* @__PURE__ */ C.jsx(
173
180
  "div",
174
181
  {
175
- ref: A,
182
+ ref: R,
176
183
  className: "sandbox-container",
177
- style: Q
184
+ style: P
178
185
  }
179
186
  ),
180
- E && /* @__PURE__ */ w.jsxs(
187
+ E && /* @__PURE__ */ C.jsxs(
181
188
  "div",
182
189
  {
183
190
  style: {
@@ -195,8 +202,8 @@ const Z = [
195
202
  zIndex: 20
196
203
  },
197
204
  children: [
198
- /* @__PURE__ */ w.jsx(
199
- Y,
205
+ /* @__PURE__ */ C.jsx(
206
+ ee,
200
207
  {
201
208
  "aria-hidden": !0,
202
209
  size: 20,
@@ -212,6 +219,6 @@ const Z = [
212
219
  );
213
220
  };
214
221
  export {
215
- ae as default
222
+ le as default
216
223
  };
217
224
  //# sourceMappingURL=SandboxApp.es.js.map