markdown-flow-ui 0.1.81-beta.16 → 0.1.81-beta.18

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 (43) hide show
  1. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/c4Diagram-YG6GDRKO.js +1 -1
  2. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/chunk-S3R3BYOJ.js +1 -1
  3. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/chunk-TZMSLE5B.js +1 -1
  4. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/ganttDiagram-LVOFAZNH.js +1 -1
  5. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/sequenceDiagram-WL72ISMW.js +1 -1
  6. 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.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/ResizableTextArea.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/TextArea.js +1 -1
  9. 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.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/index.js +1 -1
  11. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/style-to-object@1.0.11/node_modules/style-to-object/cjs/index.js +1 -1
  12. package/dist/_virtual/index2.js +2 -5
  13. package/dist/_virtual/index2.js.map +1 -1
  14. package/dist/_virtual/index3.js +5 -2
  15. package/dist/_virtual/index3.js.map +1 -1
  16. package/dist/_virtual/index7.js +3 -2
  17. package/dist/_virtual/index7.js.map +1 -1
  18. package/dist/_virtual/index9.js +2 -3
  19. package/dist/_virtual/index9.js.map +1 -1
  20. package/dist/components/ContentRender/ContentRender.d.ts +5 -0
  21. package/dist/components/ContentRender/ContentRender.js +139 -141
  22. package/dist/components/ContentRender/ContentRender.js.map +1 -1
  23. package/dist/components/ContentRender/ContentRender.stories.d.ts +1 -0
  24. package/dist/components/ContentRender/IframeSandbox.d.ts +5 -0
  25. package/dist/components/ContentRender/IframeSandbox.js +71 -32
  26. package/dist/components/ContentRender/IframeSandbox.js.map +1 -1
  27. package/dist/components/ContentRender/SandboxApp.d.ts +5 -0
  28. package/dist/components/ContentRender/SandboxApp.js +194 -16
  29. package/dist/components/ContentRender/SandboxApp.js.map +1 -1
  30. package/dist/components/ContentRender/index.d.ts +5 -0
  31. package/dist/components/ContentRender/index.js +2 -1
  32. package/dist/components/ContentRender/index.js.map +1 -1
  33. package/dist/components/ContentRender/utils/split-content.d.ts +8 -0
  34. package/dist/components/ContentRender/utils/split-content.js +18 -0
  35. package/dist/components/ContentRender/utils/split-content.js.map +1 -0
  36. package/dist/components/MarkdownFlow/MarkdownFlow.js +4 -3
  37. package/dist/components/MarkdownFlow/MarkdownFlow.js.map +1 -1
  38. package/dist/components/ui/inputGroup/textarea.js +1 -1
  39. package/dist/index.js +9 -8
  40. package/dist/index.js.map +1 -1
  41. package/dist/renderer.js +5 -4
  42. package/dist/renderer.js.map +1 -1
  43. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"ContentRender.js","sources":["../../../src/components/ContentRender/ContentRender.tsx"],"sourcesContent":["import \"highlight.js/styles/github.css\";\nimport \"katex/dist/katex.min.css\";\nimport React, { useEffect, useMemo, useRef } from \"react\";\nimport ReactMarkdown from \"react-markdown\";\nimport rehypeHighlight from \"rehype-highlight\";\nimport rehypeKatex from \"rehype-katex\";\nimport rehypeRaw from \"rehype-raw\";\nimport remarkBreaks from \"remark-breaks\";\nimport remarkFlow from \"remark-flow\";\nimport remarkGfm from \"remark-gfm\";\nimport remarkMath from \"remark-math\";\nimport { CustomRenderBarProps, OnSendContentParams } from \"../types\";\nimport \"./contentRender.css\";\nimport \"./github-markdown-light.css\";\nimport CodeBlock from \"./CodeBlock\";\nimport CustomButtonInputVariable, {\n ComponentsWithCustomVariable,\n} from \"./plugins/CustomVariable\";\nimport MermaidChart from \"./plugins/MermaidChart\";\nimport useTypewriterStateMachine from \"./useTypewriterStateMachine\";\nimport {\n preserveCustomVariableProperties,\n restoreCustomVariableProperties,\n} from \"./utils/custom-variable-props\";\nimport {\n highlightLanguages,\n subsetLanguages,\n} from \"./utils/highlight-languages\";\n// import { processMarkdownText } from \"./utils/process-markdown\";\nimport {\n parseMarkdownSegments,\n mermaidBlockIsComplete,\n} from \"./utils/mermaid-parse\";\nimport { normalizeInlineHtml } from \"./utils/normalize-inline-html\";\nimport IframeSandbox from \"./IframeSandbox\";\n\ntype RenderSegment =\n | { type: \"markdown\"; value: string }\n | { type: \"sandbox\"; value: string };\n\nconst splitContentSegments = (raw: string): RenderSegment[] => {\n const startPattern =\n /<(script|style|link|iframe|html|head|body|meta|title|base|template|div|section|article|main)[\\s>]/i;\n\n const startIndex = raw.search(startPattern);\n if (startIndex === -1) {\n return [{ type: \"markdown\", value: raw }];\n }\n\n // Find the end of the HTML block: stop at the first closing tag whose\n // following line does not start with another HTML tag.\n const closingBoundary = /<\\/[a-z][^>]*>\\s*\\n(?=[^\\s<])/gi;\n let blockEnd = raw.length;\n let match: RegExpExecArray | null;\n\n while ((match = closingBoundary.exec(raw))) {\n if (match.index <= startIndex) continue;\n blockEnd = match.index + match[0].length - 1; // end before the newline\n break;\n }\n\n const segments: RenderSegment[] = [];\n const before = raw.slice(0, startIndex);\n const htmlBlock = raw.slice(startIndex, blockEnd);\n const after = raw.slice(blockEnd);\n\n if (before.trim()) {\n segments.push({ type: \"markdown\", value: before });\n }\n\n segments.push({ type: \"sandbox\", value: htmlBlock });\n\n if (after.trim()) {\n segments.push(...splitContentSegments(after));\n }\n\n return segments;\n};\n// Define component Props type\nexport interface ContentRenderProps {\n content: string;\n /**\n+ * Callback invoked when the custom button after content is clicked.\n+ * This button is rendered via the `<custom-button-after-content>` tag in markdown content.\n+ * @example\n+ * ```tsx\n+ * <ContentRender\n+ * content=\"Hello <custom-button-after-content>Ask</custom-button-after-content>\"\n+ * onClickCustomButtonAfterContent={() => console.log('Button clicked')}\n+ * />\n+ * ```\n+ */\n customRenderBar?: CustomRenderBarProps;\n onClickCustomButtonAfterContent?: () => void;\n onSend?: (content: OnSendContentParams) => void;\n typingSpeed?: number;\n enableTypewriter?: boolean;\n defaultButtonText?: string;\n defaultInputText?: string; // Text input by user\n defaultSelectedValues?: string[]; // Default selected values for multi-select\n readonly?: boolean;\n onTypeFinished?: () => void;\n // Multi-select confirm button text (i18n support)\n confirmButtonText?: string;\n // Copy button text (i18n support)\n copyButtonText?: string;\n // Copied state text (i18n support)\n copiedButtonText?: string;\n // Dynamic interaction format for multi-select support\n dynamicInteractionFormat?: string;\n beforeSend?: (param: OnSendContentParams) => boolean;\n // tooltipMinLength?: number; // Control minimum character length for tooltip display, default 10\n}\n\n// Render svg string via Shadow DOM to avoid markdown wrapping\nconst SvgBlockInShadow: React.FC<{ svg: string }> = ({ svg }) => {\n const hostRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const host = hostRef.current;\n if (!host) return;\n const shadowRoot = host.shadowRoot ?? host.attachShadow({ mode: \"open\" });\n const styleId = \"content-render-svg-style\";\n let styleEl = shadowRoot.getElementById(styleId) as HTMLStyleElement | null;\n\n if (!styleEl) {\n styleEl = document.createElement(\"style\");\n styleEl.id = styleId;\n styleEl.textContent = `\n :host { display: block; width: 100%; max-width: 100%; text-align: center; }\n svg { max-width: 100%; height: auto; display: inline-block; }\n `;\n shadowRoot.appendChild(styleEl);\n }\n\n const nodesToRemove = Array.from(shadowRoot.childNodes).filter(\n (node) => node !== styleEl\n );\n nodesToRemove.forEach((node) => shadowRoot.removeChild(node));\n\n const template = document.createElement(\"template\");\n template.innerHTML = svg;\n shadowRoot.append(template.content.cloneNode(true));\n\n shadowRoot.querySelectorAll(\"svg\").forEach((svgEl) => {\n // Derive responsive sizing from viewBox so pure viewBox SVGs stay visible and fluid\n const viewBox = svgEl.getAttribute(\"viewBox\");\n if (!viewBox) return;\n\n const dimensions = viewBox\n .trim()\n .split(/[\\s,]+/)\n .map((value) => Number(value));\n\n if (dimensions.length !== 4 || dimensions.some(Number.isNaN)) return;\n\n const [, , viewBoxWidth, viewBoxHeight] = dimensions;\n const widthAttr = svgEl.getAttribute(\"width\");\n const heightAttr = svgEl.getAttribute(\"height\");\n const hasWidth = !!widthAttr && widthAttr !== \"0\";\n const hasHeight = !!heightAttr && heightAttr !== \"0\";\n const shouldUseResponsiveSize = !hasWidth && !hasHeight;\n\n if (shouldUseResponsiveSize) {\n svgEl.style.width = \"100%\";\n svgEl.style.height = \"auto\";\n if (!svgEl.style.aspectRatio && viewBoxHeight > 0) {\n svgEl.style.aspectRatio = `${viewBoxWidth} / ${viewBoxHeight}`;\n }\n return;\n }\n\n if (!hasWidth && viewBoxWidth > 0) {\n svgEl.setAttribute(\"width\", `${viewBoxWidth}`);\n }\n if (!hasHeight && viewBoxHeight > 0) {\n svgEl.setAttribute(\"height\", `${viewBoxHeight}`);\n }\n });\n }, [svg]);\n\n return (\n <div className=\"content-render-svg-scroll\">\n <div className=\"content-render-svg\" ref={hostRef} />\n </div>\n );\n};\n\n// Extended component interface\ntype CustomComponents = ComponentsWithCustomVariable & {\n \"custom-button-after-content\"?: React.ComponentType<{\n children: React.ReactNode;\n }>;\n};\n\nconst remarkPlugins = [remarkGfm, remarkMath, remarkFlow, remarkBreaks];\n\nconst rehypePlugins = [\n preserveCustomVariableProperties,\n rehypeRaw,\n restoreCustomVariableProperties,\n [rehypeHighlight, { languages: highlightLanguages, subset: subsetLanguages }],\n rehypeKatex,\n];\n\nconst MarkdownRenderer: React.FC<{\n content: string;\n components: CustomComponents;\n}> = ({ content: markdownContent, components }) => (\n <div className=\"markdown-body\">\n <ReactMarkdown\n remarkPlugins={remarkPlugins}\n rehypePlugins={rehypePlugins}\n components={components}\n >\n {markdownContent}\n </ReactMarkdown>\n </div>\n);\n\nconst ContentRender: React.FC<ContentRenderProps> = ({\n content,\n customRenderBar,\n onSend,\n typingSpeed = 30,\n enableTypewriter = false,\n defaultButtonText,\n defaultInputText,\n defaultSelectedValues,\n readonly = false,\n onTypeFinished,\n confirmButtonText,\n copyButtonText,\n copiedButtonText,\n onClickCustomButtonAfterContent,\n beforeSend,\n // tooltipMinLength,\n}) => {\n const normalizedContent = useMemo(\n () => normalizeInlineHtml(content),\n [content]\n );\n\n // Use custom Hook to handle typewriter effect\n const components: CustomComponents = {\n \"custom-button-after-content\": ({\n children,\n }: {\n children: React.ReactNode;\n }) => {\n return (\n <button\n className=\"content-render-custom-button-after-content\"\n onClick={onClickCustomButtonAfterContent}\n >\n <span className=\"content-render-custom-button-after-content-inner\">\n {children}\n </span>\n </button>\n );\n },\n \"custom-variable\": (props) => (\n <CustomButtonInputVariable\n {...props}\n readonly={readonly}\n defaultButtonText={defaultButtonText}\n defaultInputText={defaultInputText}\n defaultSelectedValues={defaultSelectedValues}\n onSend={onSend}\n beforeSend={beforeSend}\n confirmButtonText={confirmButtonText}\n // tooltipMinLength={tooltipMinLength}\n />\n ),\n code: (props) => {\n const { className, children, ...rest } = props as {\n className?: string;\n children?: React.ReactNode;\n };\n const match = /language-(\\w+)/.exec(className || \"\");\n const language = match?.[1];\n if (language === \"mermaid\") {\n const chartContent = children?.toString().replace(/\\n$/, \"\") || \"\";\n const frozen = mermaidBlockIsComplete(content, chartContent);\n return <MermaidChart chart={chartContent} frozen={frozen} />;\n }\n\n return (\n <code className={className} {...rest}>\n {children}\n </code>\n );\n },\n table: ({ ...props }) => (\n <div className=\"content-render-table-container\">\n <table className=\"content-render-table\" {...props} />\n </div>\n ),\n th: ({ ...props }) => <th className=\"content-render-th\" {...props} />,\n td: ({ ...props }) => <td className=\"content-render-td\" {...props} />,\n tr: ({ ...props }) => <tr className=\"content-render-tr\" {...props} />,\n li: ({ node, ...props }) => {\n const className = node?.properties?.className;\n const hasTaskListItem =\n (typeof className === \"string\" &&\n className.includes(\"task-list-item\")) ||\n (Array.isArray(className) && className.includes(\"task-list-item\"));\n if (hasTaskListItem) {\n return <li className=\"content-render-task-list-item\" {...props} />;\n }\n return <li {...props} />;\n },\n ol: ({ ...props }) => <ol className=\"content-render-ol\" {...props} />,\n ul: ({ ...props }) => <ul className=\"content-render-ul\" {...props} />,\n input: ({ ...props }) => {\n if (props.type === \"checkbox\") {\n return (\n <input\n type=\"checkbox\"\n className=\"content-render-checkbox\"\n disabled\n {...props}\n />\n );\n }\n return <input {...props} />;\n },\n a: ({ children, ...props }) => (\n <a target=\"_blank\" rel=\"noopener noreferrer\" {...props}>\n {children}\n </a>\n ),\n pre: (props) => (\n <CodeBlock\n {...props}\n copyButtonText={copyButtonText}\n copiedButtonText={copiedButtonText}\n />\n ),\n };\n\n const { displayContent, isComplete } = useTypewriterStateMachine({\n // processMarkdownText will let code block printf(\"You win!\\n\") become printf(\"You win!<br/>\");\n // content: processMarkdownText(content),\n content: normalizedContent,\n typingSpeed,\n disabled: !enableTypewriter,\n });\n\n const renderSegments = useMemo(\n () => splitContentSegments(content),\n [content]\n );\n const hasSandbox = renderSegments.some(\n (segment) => segment.type === \"sandbox\"\n );\n\n const segments = useMemo(\n () => parseMarkdownSegments(displayContent),\n [displayContent]\n );\n\n const hasCompleted = useRef(false);\n\n useEffect(() => {\n if (hasSandbox) return;\n if (isComplete && !hasCompleted.current) {\n hasCompleted.current = true; // Mark as completed\n onTypeFinished?.(); // Call the passed callback\n }\n }, [hasSandbox, isComplete, onTypeFinished]);\n\n useEffect(() => {\n if (hasSandbox) return;\n hasCompleted.current = false; // Reset completion status when content changes\n }, [hasSandbox, content]);\n\n if (hasSandbox) {\n return (\n <div className=\"content-render\">\n {renderSegments.map((segment, idx) =>\n segment.type === \"sandbox\" ? (\n <IframeSandbox\n key={`sandbox-${idx}`}\n content={segment.value}\n className=\"content-render-iframe\"\n />\n ) : (\n <MarkdownRenderer\n key={`md-${idx}`}\n components={components}\n content={normalizeInlineHtml(segment.value)}\n />\n )\n )}\n </div>\n );\n }\n\n return (\n <div className=\"content-render\">\n {segments.map((seg, index) => {\n if (seg.type === \"text\") {\n return (\n <MarkdownRenderer\n key={index}\n components={components}\n content={seg.value}\n />\n );\n }\n\n if (seg.type === \"mermaid\") {\n return (\n <MermaidChart\n key={index}\n chart={seg.value}\n frozen={!seg.complete}\n />\n );\n }\n\n if (seg.type === \"svg\") {\n return <SvgBlockInShadow key={index} svg={seg.value} />;\n }\n })}\n\n {customRenderBar && (\n <div className=\"content-render-custom-bar\">\n {React.createElement(customRenderBar, {\n content,\n displayContent,\n onSend,\n })}\n </div>\n )}\n </div>\n );\n};\n\nexport default ContentRender;\n"],"names":["splitContentSegments","raw","startPattern","startIndex","closingBoundary","blockEnd","match","segments","before","htmlBlock","after","SvgBlockInShadow","svg","hostRef","useRef","useEffect","host","shadowRoot","styleId","styleEl","node","template","svgEl","viewBox","dimensions","value","viewBoxWidth","viewBoxHeight","widthAttr","heightAttr","hasWidth","hasHeight","jsx","remarkPlugins","remarkGfm","remarkMath","remarkFlow","remarkBreaks","rehypePlugins","preserveCustomVariableProperties","rehypeRaw","restoreCustomVariableProperties","rehypeHighlight","highlightLanguages","subsetLanguages","rehypeKatex","MarkdownRenderer","markdownContent","components","ReactMarkdown","ContentRender","content","customRenderBar","onSend","typingSpeed","enableTypewriter","defaultButtonText","defaultInputText","defaultSelectedValues","readonly","onTypeFinished","confirmButtonText","copyButtonText","copiedButtonText","onClickCustomButtonAfterContent","beforeSend","normalizedContent","useMemo","normalizeInlineHtml","children","props","CustomButtonInputVariable","className","rest","chartContent","frozen","mermaidBlockIsComplete","MermaidChart","CodeBlock","displayContent","isComplete","useTypewriterStateMachine","renderSegments","hasSandbox","segment","parseMarkdownSegments","hasCompleted","idx","IframeSandbox","jsxs","seg","index","React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAMA,IAAuB,CAACC,MAAiC;AAC7D,QAAMC,IACJ,sGAEIC,IAAaF,EAAI,OAAOC,CAAY;AAC1C,MAAIC,MAAe;AACjB,WAAO,CAAC,EAAE,MAAM,YAAY,OAAOF,GAAK;AAK1C,QAAMG,IAAkB;AACxB,MAAIC,IAAWJ,EAAI,QACfK;AAEJ,SAAQA,IAAQF,EAAgB,KAAKH,CAAG;AACtC,QAAI,EAAAK,EAAM,SAASH,IACnB;AAAA,MAAAE,IAAWC,EAAM,QAAQA,EAAM,CAAC,EAAE,SAAS;AAC3C;AAAA;AAGF,QAAMC,IAA4B,CAAA,GAC5BC,IAASP,EAAI,MAAM,GAAGE,CAAU,GAChCM,IAAYR,EAAI,MAAME,GAAYE,CAAQ,GAC1CK,IAAQT,EAAI,MAAMI,CAAQ;AAEhC,SAAIG,EAAO,UACTD,EAAS,KAAK,EAAE,MAAM,YAAY,OAAOC,GAAQ,GAGnDD,EAAS,KAAK,EAAE,MAAM,WAAW,OAAOE,GAAW,GAE/CC,EAAM,UACRH,EAAS,KAAK,GAAGP,EAAqBU,CAAK,CAAC,GAGvCH;AACT,GAsCMI,KAA8C,CAAC,EAAE,KAAAC,QAAU;AAC/D,QAAMC,IAAUC,EAAuB,IAAI;AAE3C,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAOH,EAAQ;AACrB,QAAI,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A,EAAI,WAAU,kBACZ,UAAA;AAAA,IAAAlF,EAAS,IAAI,CAACmF,GAAKC,MAAU;AAC5B,UAAID,EAAI,SAAS;AACf,eACE1D,gBAAAA,EAAAA;AAAAA,UAACc;AAAA,UAAA;AAAA,YAEC,YAAAE;AAAA,YACA,SAAS0C,EAAI;AAAA,UAAA;AAAA,UAFRC;AAAA,QAAA;AAOX,UAAID,EAAI,SAAS;AACf,eACE1D,gBAAAA,EAAAA;AAAAA,UAAC6C;AAAA,UAAA;AAAA,YAEC,OAAOa,EAAI;AAAA,YACX,QAAQ,CAACA,EAAI;AAAA,UAAA;AAAA,UAFRC;AAAA,QAAA;AAOX,UAAID,EAAI,SAAS;AACf,eAAO1D,gBAAAA,EAAAA,IAACrB,IAAA,EAA6B,KAAK+E,EAAI,SAAhBC,CAAuB;AAAA,IAEzD,CAAC;AAAA,IAEAvC,KACCpB,gBAAAA,EAAAA,IAAC,OAAA,EAAI,WAAU,6BACZ,UAAA4D,EAAM,cAAcxC,GAAiB;AAAA,MACpC,SAAAD;AAAA,MACA,gBAAA4B;AAAA,MACA,QAAA1B;AAAA,IAAA,CACD,EAAA,CACH;AAAA,EAAA,GAEJ;AAEJ;"}
1
+ {"version":3,"file":"ContentRender.js","sources":["../../../src/components/ContentRender/ContentRender.tsx"],"sourcesContent":["import \"highlight.js/styles/github.css\";\nimport \"katex/dist/katex.min.css\";\nimport React, { useEffect, useMemo, useRef } from \"react\";\nimport ReactMarkdown from \"react-markdown\";\nimport rehypeHighlight from \"rehype-highlight\";\nimport rehypeKatex from \"rehype-katex\";\nimport rehypeRaw from \"rehype-raw\";\nimport remarkBreaks from \"remark-breaks\";\nimport remarkFlow from \"remark-flow\";\nimport remarkGfm from \"remark-gfm\";\nimport remarkMath from \"remark-math\";\nimport { CustomRenderBarProps, OnSendContentParams } from \"../types\";\nimport \"./contentRender.css\";\nimport \"./github-markdown-light.css\";\nimport CodeBlock from \"./CodeBlock\";\nimport CustomButtonInputVariable, {\n ComponentsWithCustomVariable,\n} from \"./plugins/CustomVariable\";\nimport MermaidChart from \"./plugins/MermaidChart\";\nimport useTypewriterStateMachine from \"./useTypewriterStateMachine\";\nimport {\n preserveCustomVariableProperties,\n restoreCustomVariableProperties,\n} from \"./utils/custom-variable-props\";\nimport {\n highlightLanguages,\n subsetLanguages,\n} from \"./utils/highlight-languages\";\n// import { processMarkdownText } from \"./utils/process-markdown\";\nimport {\n parseMarkdownSegments,\n mermaidBlockIsComplete,\n} from \"./utils/mermaid-parse\";\nimport { normalizeInlineHtml } from \"./utils/normalize-inline-html\";\nimport IframeSandbox from \"./IframeSandbox\";\nimport { splitContentSegments } from \"./utils/split-content\";\n// Define component Props type\nexport interface ContentRenderProps {\n content: string;\n /**\n+ * Callback invoked when the custom button after content is clicked.\n+ * This button is rendered via the `<custom-button-after-content>` tag in markdown content.\n+ * @example\n+ * ```tsx\n+ * <ContentRender\n+ * content=\"Hello <custom-button-after-content>Ask</custom-button-after-content>\"\n+ * onClickCustomButtonAfterContent={() => console.log('Button clicked')}\n+ * />\n+ * ```\n+ */\n customRenderBar?: CustomRenderBarProps;\n onClickCustomButtonAfterContent?: () => void;\n onSend?: (content: OnSendContentParams) => void;\n typingSpeed?: number;\n enableTypewriter?: boolean;\n defaultButtonText?: string;\n defaultInputText?: string; // Text input by user\n defaultSelectedValues?: string[]; // Default selected values for multi-select\n readonly?: boolean;\n onTypeFinished?: () => void;\n // Multi-select confirm button text (i18n support)\n confirmButtonText?: string;\n // Copy button text (i18n support)\n copyButtonText?: string;\n // Copied state text (i18n support)\n copiedButtonText?: string;\n // Dynamic interaction format for multi-select support\n dynamicInteractionFormat?: string;\n // Loading text before first HTML block renders inside iframe (i18n support)\n sandboxLoadingText?: string;\n // Loading text while styles are being generated inside iframe\n sandboxStyleLoadingText?: string;\n // Loading text while scripts are being cached/executed inside iframe\n sandboxScriptLoadingText?: string;\n // Fullscreen button text for iframe sandbox\n sandboxFullscreenButtonText?: string;\n // Sandbox render mode\n sandboxMode?: \"content\" | \"blackboard\";\n beforeSend?: (param: OnSendContentParams) => boolean;\n // tooltipMinLength?: number; // Control minimum character length for tooltip display, default 10\n}\n\n// Render svg string via Shadow DOM to avoid markdown wrapping\nconst SvgBlockInShadow: React.FC<{ svg: string }> = ({ svg }) => {\n const hostRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const host = hostRef.current;\n if (!host) return;\n const shadowRoot = host.shadowRoot ?? host.attachShadow({ mode: \"open\" });\n const styleId = \"content-render-svg-style\";\n let styleEl = shadowRoot.getElementById(styleId) as HTMLStyleElement | null;\n\n if (!styleEl) {\n styleEl = document.createElement(\"style\");\n styleEl.id = styleId;\n styleEl.textContent = `\n :host { display: block; width: 100%; max-width: 100%; text-align: center; }\n svg { max-width: 100%; height: auto; display: inline-block; }\n `;\n shadowRoot.appendChild(styleEl);\n }\n\n const nodesToRemove = Array.from(shadowRoot.childNodes).filter(\n (node) => node !== styleEl\n );\n nodesToRemove.forEach((node) => shadowRoot.removeChild(node));\n\n const template = document.createElement(\"template\");\n template.innerHTML = svg;\n shadowRoot.append(template.content.cloneNode(true));\n\n shadowRoot.querySelectorAll(\"svg\").forEach((svgEl) => {\n // Derive responsive sizing from viewBox so pure viewBox SVGs stay visible and fluid\n const viewBox = svgEl.getAttribute(\"viewBox\");\n if (!viewBox) return;\n\n const dimensions = viewBox\n .trim()\n .split(/[\\s,]+/)\n .map((value) => Number(value));\n\n if (dimensions.length !== 4 || dimensions.some(Number.isNaN)) return;\n\n const [, , viewBoxWidth, viewBoxHeight] = dimensions;\n const widthAttr = svgEl.getAttribute(\"width\");\n const heightAttr = svgEl.getAttribute(\"height\");\n const hasWidth = !!widthAttr && widthAttr !== \"0\";\n const hasHeight = !!heightAttr && heightAttr !== \"0\";\n const shouldUseResponsiveSize = !hasWidth && !hasHeight;\n\n if (shouldUseResponsiveSize) {\n svgEl.style.width = \"100%\";\n svgEl.style.height = \"auto\";\n if (!svgEl.style.aspectRatio && viewBoxHeight > 0) {\n svgEl.style.aspectRatio = `${viewBoxWidth} / ${viewBoxHeight}`;\n }\n return;\n }\n\n if (!hasWidth && viewBoxWidth > 0) {\n svgEl.setAttribute(\"width\", `${viewBoxWidth}`);\n }\n if (!hasHeight && viewBoxHeight > 0) {\n svgEl.setAttribute(\"height\", `${viewBoxHeight}`);\n }\n });\n }, [svg]);\n\n return (\n <div className=\"content-render-svg-scroll\">\n <div className=\"content-render-svg\" ref={hostRef} />\n </div>\n );\n};\n\n// Extended component interface\ntype CustomComponents = ComponentsWithCustomVariable & {\n \"custom-button-after-content\"?: React.ComponentType<{\n children: React.ReactNode;\n }>;\n};\n\nconst remarkPlugins = [remarkGfm, remarkMath, remarkFlow, remarkBreaks];\n\nconst rehypePlugins = [\n preserveCustomVariableProperties,\n rehypeRaw,\n restoreCustomVariableProperties,\n [rehypeHighlight, { languages: highlightLanguages, subset: subsetLanguages }],\n rehypeKatex,\n];\n\nconst MarkdownRenderer: React.FC<{\n content: string;\n components: CustomComponents;\n}> = ({ content: markdownContent, components }) => (\n <div className=\"markdown-body\">\n <ReactMarkdown\n remarkPlugins={remarkPlugins}\n rehypePlugins={rehypePlugins}\n components={components}\n >\n {markdownContent}\n </ReactMarkdown>\n </div>\n);\n\nconst ContentRender: React.FC<ContentRenderProps> = ({\n content,\n customRenderBar,\n onSend,\n typingSpeed = 30,\n enableTypewriter = false,\n defaultButtonText,\n defaultInputText,\n defaultSelectedValues,\n readonly = false,\n onTypeFinished,\n confirmButtonText,\n copyButtonText,\n copiedButtonText,\n sandboxLoadingText,\n sandboxStyleLoadingText,\n sandboxScriptLoadingText,\n sandboxFullscreenButtonText,\n sandboxMode = \"content\",\n onClickCustomButtonAfterContent,\n beforeSend,\n // tooltipMinLength,\n}) => {\n const normalizedContent = useMemo(\n () => normalizeInlineHtml(content),\n [content]\n );\n\n // Use custom Hook to handle typewriter effect\n const components: CustomComponents = {\n \"custom-button-after-content\": ({\n children,\n }: {\n children: React.ReactNode;\n }) => {\n return (\n <button\n className=\"content-render-custom-button-after-content\"\n onClick={onClickCustomButtonAfterContent}\n >\n <span className=\"content-render-custom-button-after-content-inner\">\n {children}\n </span>\n </button>\n );\n },\n \"custom-variable\": (props) => (\n <CustomButtonInputVariable\n {...props}\n readonly={readonly}\n defaultButtonText={defaultButtonText}\n defaultInputText={defaultInputText}\n defaultSelectedValues={defaultSelectedValues}\n onSend={onSend}\n beforeSend={beforeSend}\n confirmButtonText={confirmButtonText}\n // tooltipMinLength={tooltipMinLength}\n />\n ),\n code: (props) => {\n const { className, children, ...rest } = props as {\n className?: string;\n children?: React.ReactNode;\n };\n const match = /language-(\\w+)/.exec(className || \"\");\n const language = match?.[1];\n if (language === \"mermaid\") {\n const chartContent = children?.toString().replace(/\\n$/, \"\") || \"\";\n const frozen = mermaidBlockIsComplete(content, chartContent);\n return <MermaidChart chart={chartContent} frozen={frozen} />;\n }\n\n return (\n <code className={className} {...rest}>\n {children}\n </code>\n );\n },\n table: ({ ...props }) => (\n <div className=\"content-render-table-container\">\n <table className=\"content-render-table\" {...props} />\n </div>\n ),\n th: ({ ...props }) => <th className=\"content-render-th\" {...props} />,\n td: ({ ...props }) => <td className=\"content-render-td\" {...props} />,\n tr: ({ ...props }) => <tr className=\"content-render-tr\" {...props} />,\n li: ({ node, ...props }) => {\n const className = node?.properties?.className;\n const hasTaskListItem =\n (typeof className === \"string\" &&\n className.includes(\"task-list-item\")) ||\n (Array.isArray(className) && className.includes(\"task-list-item\"));\n if (hasTaskListItem) {\n return <li className=\"content-render-task-list-item\" {...props} />;\n }\n return <li {...props} />;\n },\n ol: ({ ...props }) => <ol className=\"content-render-ol\" {...props} />,\n ul: ({ ...props }) => <ul className=\"content-render-ul\" {...props} />,\n input: ({ ...props }) => {\n if (props.type === \"checkbox\") {\n return (\n <input\n type=\"checkbox\"\n className=\"content-render-checkbox\"\n disabled\n {...props}\n />\n );\n }\n return <input {...props} />;\n },\n a: ({ children, ...props }) => (\n <a target=\"_blank\" rel=\"noopener noreferrer\" {...props}>\n {children}\n </a>\n ),\n pre: (props) => (\n <CodeBlock\n {...props}\n copyButtonText={copyButtonText}\n copiedButtonText={copiedButtonText}\n />\n ),\n };\n\n const { displayContent, isComplete } = useTypewriterStateMachine({\n // processMarkdownText will let code block printf(\"You win!\\n\") become printf(\"You win!<br/>\");\n // content: processMarkdownText(content),\n content: normalizedContent,\n typingSpeed,\n disabled: !enableTypewriter,\n });\n\n const renderSegments = useMemo(\n () => splitContentSegments(content),\n [content]\n );\n const hasSandbox = renderSegments.some(\n (segment) => segment.type === \"sandbox\"\n );\n\n const segments = useMemo(\n () => parseMarkdownSegments(displayContent),\n [displayContent]\n );\n\n const hasCompleted = useRef(false);\n\n useEffect(() => {\n if (hasSandbox) return;\n if (isComplete && !hasCompleted.current) {\n hasCompleted.current = true; // Mark as completed\n onTypeFinished?.(); // Call the passed callback\n }\n }, [hasSandbox, isComplete, onTypeFinished]);\n\n useEffect(() => {\n if (hasSandbox) return;\n hasCompleted.current = false; // Reset completion status when content changes\n }, [hasSandbox, content]);\n\n if (hasSandbox) {\n return (\n <div className=\"content-render\">\n {renderSegments.map((segment, idx) =>\n segment.type === \"sandbox\" ? (\n <IframeSandbox\n key={`sandbox-${idx}`}\n content={segment.value}\n className=\"content-render-iframe\"\n loadingText={sandboxLoadingText}\n styleLoadingText={sandboxStyleLoadingText}\n scriptLoadingText={sandboxScriptLoadingText}\n fullScreenButtonText={sandboxFullscreenButtonText}\n mode={sandboxMode}\n />\n ) : (\n <MarkdownRenderer\n key={`md-${idx}`}\n components={components}\n content={normalizeInlineHtml(segment.value)}\n />\n )\n )}\n </div>\n );\n }\n\n return (\n <div className=\"content-render\">\n {segments.map((seg, index) => {\n if (seg.type === \"text\") {\n return (\n <MarkdownRenderer\n key={index}\n components={components}\n content={seg.value}\n />\n );\n }\n\n if (seg.type === \"mermaid\") {\n return (\n <MermaidChart\n key={index}\n chart={seg.value}\n frozen={!seg.complete}\n />\n );\n }\n\n if (seg.type === \"svg\") {\n return <SvgBlockInShadow key={index} svg={seg.value} />;\n }\n })}\n\n {customRenderBar && (\n <div className=\"content-render-custom-bar\">\n {React.createElement(customRenderBar, {\n content,\n displayContent,\n onSend,\n })}\n </div>\n )}\n </div>\n );\n};\n\nexport default ContentRender;\n"],"names":["SvgBlockInShadow","svg","hostRef","useRef","useEffect","host","shadowRoot","styleId","styleEl","node","template","svgEl","viewBox","dimensions","value","viewBoxWidth","viewBoxHeight","widthAttr","heightAttr","hasWidth","hasHeight","jsx","remarkPlugins","remarkGfm","remarkMath","remarkFlow","remarkBreaks","rehypePlugins","preserveCustomVariableProperties","rehypeRaw","restoreCustomVariableProperties","rehypeHighlight","highlightLanguages","subsetLanguages","rehypeKatex","MarkdownRenderer","markdownContent","components","ReactMarkdown","ContentRender","content","customRenderBar","onSend","typingSpeed","enableTypewriter","defaultButtonText","defaultInputText","defaultSelectedValues","readonly","onTypeFinished","confirmButtonText","copyButtonText","copiedButtonText","sandboxLoadingText","sandboxStyleLoadingText","sandboxScriptLoadingText","sandboxFullscreenButtonText","sandboxMode","onClickCustomButtonAfterContent","beforeSend","normalizedContent","useMemo","normalizeInlineHtml","children","props","CustomButtonInputVariable","className","rest","chartContent","frozen","mermaidBlockIsComplete","MermaidChart","CodeBlock","displayContent","isComplete","useTypewriterStateMachine","renderSegments","splitContentSegments","hasSandbox","segment","segments","parseMarkdownSegments","hasCompleted","idx","IframeSandbox","jsxs","seg","index","React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmFA,MAAMA,KAA8C,CAAC,EAAE,KAAAC,QAAU;AAC/D,QAAMC,IAAUC,EAAuB,IAAI;AAE3C,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAOH,EAAQ;AACrB,QAAI,CAACG,EAAM;AACX,UAAMC,IAAaD,EAAK,cAAcA,EAAK,aAAa,EAAE,MAAM,QAAQ,GAClEE,IAAU;AAChB,QAAIC,IAAUF,EAAW,eAAeC,CAAO;AAE/C,IAAKC,MACHA,IAAU,SAAS,cAAc,OAAO,GAC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,GAGN,IAKFE,gBAAAA,EAAAA,KAAC,OAAA,EAAI,WAAU,kBACZ,UAAA;AAAA,IAAAL,EAAS,IAAI,CAACM,GAAKC,MAAU;AAC5B,UAAID,EAAI,SAAS;AACf,eACEjE,gBAAAA,EAAAA;AAAAA,UAACc;AAAA,UAAA;AAAA,YAEC,YAAAE;AAAA,YACA,SAASiD,EAAI;AAAA,UAAA;AAAA,UAFRC;AAAA,QAAA;AAOX,UAAID,EAAI,SAAS;AACf,eACEjE,gBAAAA,EAAAA;AAAAA,UAACkD;AAAA,UAAA;AAAA,YAEC,OAAOe,EAAI;AAAA,YACX,QAAQ,CAACA,EAAI;AAAA,UAAA;AAAA,UAFRC;AAAA,QAAA;AAOX,UAAID,EAAI,SAAS;AACf,eAAOjE,gBAAAA,EAAAA,IAACrB,IAAA,EAA6B,KAAKsF,EAAI,SAAhBC,CAAuB;AAAA,IAEzD,CAAC;AAAA,IAEA9C,KACCpB,gBAAAA,EAAAA,IAAC,OAAA,EAAI,WAAU,6BACZ,UAAAmE,EAAM,cAAc/C,GAAiB;AAAA,MACpC,SAAAD;AAAA,MACA,gBAAAiC;AAAA,MACA,QAAA/B;AAAA,IAAA,CACD,EAAA,CACH;AAAA,EAAA,GAEJ;AAEJ;"}
@@ -34,3 +34,4 @@ export declare const CodeBlockShowcase: Story;
34
34
  export declare const EnglishChineseTypographyPreview: Story;
35
35
  export declare const SVGDemo: Story;
36
36
  export declare const HTMLDemo: Story;
37
+ export declare const HTMLDemoIframeOnly: Story;
@@ -2,6 +2,11 @@ import { default as React } from 'react';
2
2
  export interface IframeSandboxProps {
3
3
  content: string;
4
4
  className?: string;
5
+ loadingText?: string;
6
+ styleLoadingText?: string;
7
+ scriptLoadingText?: string;
8
+ fullScreenButtonText?: string;
9
+ mode?: "content" | "blackboard";
5
10
  }
6
11
  declare const IframeSandbox: React.FC<IframeSandboxProps>;
7
12
  export default IframeSandbox;
@@ -1,15 +1,32 @@
1
- import { j as a } from "../../_virtual/jsx-runtime.js";
2
- import { useRef as r, useState as E, useEffect as h } from "react";
3
- import { createRoot as w } from "react-dom/client";
4
- import j from "./SandboxApp.js";
5
- const O = ({
6
- content: d,
7
- className: f
1
+ import { j as y } from "../../_virtual/jsx-runtime.js";
2
+ import B, { useRef as s, useState as C, useEffect as f } from "react";
3
+ import { createRoot as D } from "react-dom/client";
4
+ import F from "./SandboxApp.js";
5
+ import { splitContentSegments as I } from "./utils/split-content.js";
6
+ const $ = ({
7
+ content: i,
8
+ className: H,
9
+ loadingText: b,
10
+ styleLoadingText: g,
11
+ scriptLoadingText: p,
12
+ fullScreenButtonText: R,
13
+ mode: c = "content"
8
14
  }) => {
9
- const n = r(null), i = r(null), l = r(null), c = r(() => {
10
- }), [g, b] = E(480);
11
- return h(() => {
12
- const e = n.current;
15
+ const u = s(null), a = s(null), x = s(null), l = s(() => {
16
+ }), [w, E] = C(480), [v, S] = C(0), m = s(""), o = B.useMemo(() => {
17
+ const t = I(i).filter((r) => r.type === "sandbox");
18
+ return (c === "blackboard" ? t[t.length - 1]?.value || "" : t.map((r) => r.value).join(`
19
+ `)) || "";
20
+ }, [i, c]);
21
+ return f(() => {
22
+ if (c !== "blackboard") {
23
+ m.current = o;
24
+ return;
25
+ }
26
+ const e = m.current;
27
+ !(e && o.startsWith(e)) && e && S((n) => n + 1), m.current = o;
28
+ }, [o, c]), f(() => {
29
+ const e = u.current;
13
30
  if (!e) return;
14
31
  const t = e.contentDocument;
15
32
  if (!t) return;
@@ -24,34 +41,56 @@ const O = ({
24
41
  <body>
25
42
  <div id="root"></div>
26
43
  </body>
27
- </html>`), t.close(), l.current = t;
28
- const o = t.getElementById("root");
29
- if (!o) return;
30
- const m = w(o);
31
- i.current = m;
32
- const s = () => {
33
- if (!n.current || !t.body) return;
34
- const p = t.body.getBoundingClientRect(), x = t.documentElement?.getBoundingClientRect(), y = p.height, R = x?.height || 0, v = Math.max(y, R), H = Math.max(200, Math.ceil(v));
35
- b(H);
44
+ </html>`), t.close(), x.current = t;
45
+ const n = t.getElementById("root");
46
+ if (!n) return;
47
+ const r = D(n);
48
+ a.current = r;
49
+ const d = () => {
50
+ if (!u.current || !t.body) return;
51
+ const j = t.body.getBoundingClientRect(), M = t.documentElement?.getBoundingClientRect(), k = j.height, O = M?.height || 0, z = Math.max(k, O), A = Math.max(200, Math.ceil(z));
52
+ E(A);
36
53
  };
37
- c.current = s, s();
38
- const u = new ResizeObserver(() => s());
39
- return u.observe(t.body), o && u.observe(o), () => {
40
- u.disconnect(), m.unmount(), i.current = null, l.current = null, c.current = () => {
54
+ l.current = d, d();
55
+ const h = new ResizeObserver(() => d());
56
+ return h.observe(t.body), n && h.observe(n), () => {
57
+ h.disconnect(), r.unmount(), a.current = null, x.current = null, l.current = () => {
41
58
  };
42
59
  };
43
- }, []), h(() => {
44
- const e = i.current;
45
- e && (e.render(/* @__PURE__ */ a.jsx(j, { html: d })), requestAnimationFrame(() => c.current?.()));
46
- }, [d]), /* @__PURE__ */ a.jsx(
60
+ }, []), f(() => {
61
+ const e = a.current;
62
+ e && (e.render(
63
+ /* @__PURE__ */ y.jsx(
64
+ F,
65
+ {
66
+ html: o,
67
+ loadingText: b,
68
+ styleLoadingText: g,
69
+ scriptLoadingText: p,
70
+ fullScreenButtonText: R,
71
+ resetToken: v
72
+ }
73
+ )
74
+ ), requestAnimationFrame(() => l.current?.()));
75
+ }, [
76
+ i,
77
+ o,
78
+ b,
79
+ g,
80
+ p,
81
+ R,
82
+ v
83
+ ]), /* @__PURE__ */ y.jsx(
47
84
  "iframe",
48
85
  {
49
- ref: n,
86
+ ref: u,
50
87
  sandbox: "allow-scripts allow-same-origin",
51
- className: f,
88
+ allow: "fullscreen",
89
+ allowFullScreen: !0,
90
+ className: H,
52
91
  style: {
53
92
  width: "100%",
54
- height: `${g}px`,
93
+ height: `${w}px`,
55
94
  margin: "16px 0"
56
95
  },
57
96
  title: "HTML Sandbox"
@@ -59,6 +98,6 @@ const O = ({
59
98
  );
60
99
  };
61
100
  export {
62
- O as default
101
+ $ as default
63
102
  };
64
103
  //# sourceMappingURL=IframeSandbox.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"IframeSandbox.js","sources":["../../../src/components/ContentRender/IframeSandbox.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport SandboxApp from \"./SandboxApp\";\n\nexport interface IframeSandboxProps {\n content: string;\n className?: string;\n}\n\nconst IframeSandbox: React.FC<IframeSandboxProps> = ({\n content,\n className,\n}) => {\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\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>\n <head>\n <meta charset=\"utf-8\" />\n <style>\n html, body { margin: 0; padding: 0; }\n </style>\n </head>\n <body>\n <div id=\"root\"></div>\n </body>\n</html>`);\n doc.close();\n docRef.current = doc;\n\n const rootEl = doc.getElementById(\"root\");\n if (!rootEl) return undefined;\n\n const root = createRoot(rootEl);\n rootRef.current = root;\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 nextHeight = Math.max(200, Math.ceil(contentHeight));\n setHeight(nextHeight);\n };\n updateHeightRef.current = updateHeight;\n\n updateHeight();\n\n const resizeObserver = new ResizeObserver(() => updateHeight());\n resizeObserver.observe(doc.body);\n if (rootEl) {\n resizeObserver.observe(rootEl);\n }\n\n return () => {\n resizeObserver.disconnect();\n root.unmount();\n rootRef.current = null;\n docRef.current = null;\n updateHeightRef.current = () => {};\n };\n }, []);\n\n useEffect(() => {\n const root = rootRef.current;\n if (!root) return;\n\n root.render(<SandboxApp html={content} />);\n requestAnimationFrame(() => updateHeightRef.current?.());\n }, [content]);\n\n return (\n <iframe\n ref={iframeRef}\n sandbox=\"allow-scripts allow-same-origin\"\n className={className}\n style={{\n width: \"100%\",\n height: `${height}px`,\n margin: \"16px 0\",\n }}\n title=\"HTML Sandbox\"\n />\n );\n};\n\nexport default IframeSandbox;\n"],"names":["IframeSandbox","content","className","iframeRef","useRef","rootRef","docRef","updateHeightRef","height","setHeight","useState","useEffect","iframe","doc","rootEl","root","createRoot","updateHeight","bodyRect","htmlRect","bodyHeight","htmlHeight","contentHeight","nextHeight","resizeObserver","jsx","SandboxApp"],"mappings":";;;;AASA,MAAMA,IAA8C,CAAC;AAAA,EACnD,SAAAC;AAAA,EACA,WAAAC;AACF,MAAM;AACJ,QAAMC,IAAYC,EAA0B,IAAI,GAC1CC,IAAUD,EAAoB,IAAI,GAClCE,IAASF,EAAwB,IAAI,GACrCG,IAAkBH,EAAmB,MAAM;AAAA,EAAC,CAAC,GAC7C,CAACI,GAAQC,CAAS,IAAIC,EAAS,GAAG;AAExC,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAST,EAAU;AACzB,QAAI,CAACS,EAAQ;AAEb,UAAMC,IAAMD,EAAO;AACnB,QAAI,CAACC,EAAK;AAEV,IAAAA,EAAI,KAAA,GACJA,EAAI,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAWN,GACJA,EAAI,MAAA,GACJP,EAAO,UAAUO;AAEjB,UAAMC,IAASD,EAAI,eAAe,MAAM;AACxC,QAAI,CAACC,EAAQ;AAEb,UAAMC,IAAOC,EAAWF,CAAM;AAC9B,IAAAT,EAAQ,UAAUU;AAElB,UAAME,IAAe,MAAM;AACzB,UAAI,CAACd,EAAU,WAAW,CAACU,EAAI,KAAM;AACrC,YAAMK,IAAWL,EAAI,KAAK,sBAAA,GACpBM,IAAWN,EAAI,iBAAiB,sBAAA,GAChCO,IAAaF,EAAS,QACtBG,IAAaF,GAAU,UAAU,GACjCG,IAAgB,KAAK,IAAIF,GAAYC,CAAU,GAC/CE,IAAa,KAAK,IAAI,KAAK,KAAK,KAAKD,CAAa,CAAC;AACzD,MAAAb,EAAUc,CAAU;AAAA,IACtB;AACA,IAAAhB,EAAgB,UAAUU,GAE1BA,EAAA;AAEA,UAAMO,IAAiB,IAAI,eAAe,MAAMP,GAAc;AAC9D,WAAAO,EAAe,QAAQX,EAAI,IAAI,GAC3BC,KACFU,EAAe,QAAQV,CAAM,GAGxB,MAAM;AACX,MAAAU,EAAe,WAAA,GACfT,EAAK,QAAA,GACLV,EAAQ,UAAU,MAClBC,EAAO,UAAU,MACjBC,EAAgB,UAAU,MAAM;AAAA,MAAC;AAAA,IACnC;AAAA,EACF,GAAG,CAAA,CAAE,GAELI,EAAU,MAAM;AACd,UAAMI,IAAOV,EAAQ;AACrB,IAAKU,MAELA,EAAK,OAAOU,gBAAAA,MAACC,GAAA,EAAW,MAAMzB,GAAS,CAAE,GACzC,sBAAsB,MAAMM,EAAgB,WAAW;AAAA,EACzD,GAAG,CAACN,CAAO,CAAC,GAGVwB,gBAAAA,EAAAA;AAAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAKtB;AAAA,MACL,SAAQ;AAAA,MACR,WAAAD;AAAA,MACA,OAAO;AAAA,QACL,OAAO;AAAA,QACP,QAAQ,GAAGM,CAAM;AAAA,QACjB,QAAQ;AAAA,MAAA;AAAA,MAEV,OAAM;AAAA,IAAA;AAAA,EAAA;AAGZ;"}
1
+ {"version":3,"file":"IframeSandbox.js","sources":["../../../src/components/ContentRender/IframeSandbox.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport SandboxApp from \"./SandboxApp\";\nimport { splitContentSegments } from \"./utils/split-content\";\n\nexport interface IframeSandboxProps {\n content: string;\n className?: string;\n loadingText?: string;\n styleLoadingText?: string;\n scriptLoadingText?: string;\n fullScreenButtonText?: string;\n mode?: \"content\" | \"blackboard\";\n}\n\nconst IframeSandbox: React.FC<IframeSandboxProps> = ({\n content,\n className,\n loadingText,\n styleLoadingText,\n scriptLoadingText,\n fullScreenButtonText,\n mode = \"content\",\n}) => {\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 [resetToken, setResetToken] = useState(0);\n const prevHtmlRef = useRef<string>(\"\");\n const htmlContent = React.useMemo(() => {\n const segments = splitContentSegments(content);\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\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>\n <head>\n <meta charset=\"utf-8\" />\n <style>\n html, body { margin: 0; padding: 0; }\n </style>\n </head>\n <body>\n <div id=\"root\"></div>\n </body>\n</html>`);\n doc.close();\n docRef.current = doc;\n\n const rootEl = doc.getElementById(\"root\");\n if (!rootEl) return undefined;\n\n const root = createRoot(rootEl);\n rootRef.current = root;\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 nextHeight = Math.max(200, Math.ceil(contentHeight));\n setHeight(nextHeight);\n };\n updateHeightRef.current = updateHeight;\n\n updateHeight();\n\n const resizeObserver = new ResizeObserver(() => updateHeight());\n resizeObserver.observe(doc.body);\n if (rootEl) {\n resizeObserver.observe(rootEl);\n }\n\n return () => {\n resizeObserver.disconnect();\n root.unmount();\n rootRef.current = null;\n docRef.current = null;\n updateHeightRef.current = () => {};\n };\n }, []);\n\n useEffect(() => {\n const root = rootRef.current;\n if (!root) return;\n\n root.render(\n <SandboxApp\n html={htmlContent}\n loadingText={loadingText}\n styleLoadingText={styleLoadingText}\n scriptLoadingText={scriptLoadingText}\n fullScreenButtonText={fullScreenButtonText}\n resetToken={resetToken}\n />\n );\n requestAnimationFrame(() => updateHeightRef.current?.());\n }, [\n content,\n htmlContent,\n loadingText,\n styleLoadingText,\n scriptLoadingText,\n fullScreenButtonText,\n resetToken,\n ]);\n\n return (\n <iframe\n ref={iframeRef}\n sandbox=\"allow-scripts allow-same-origin\"\n allow=\"fullscreen\"\n allowFullScreen\n className={className}\n style={{\n width: \"100%\",\n height: `${height}px`,\n margin: \"16px 0\",\n }}\n title=\"HTML Sandbox\"\n />\n );\n};\n\nexport default IframeSandbox;\n"],"names":["IframeSandbox","content","className","loadingText","styleLoadingText","scriptLoadingText","fullScreenButtonText","mode","iframeRef","useRef","rootRef","docRef","updateHeightRef","height","setHeight","useState","resetToken","setResetToken","prevHtmlRef","htmlContent","React","sandboxSegments","splitContentSegments","seg","useEffect","prev","token","iframe","doc","rootEl","root","createRoot","updateHeight","bodyRect","htmlRect","bodyHeight","htmlHeight","contentHeight","nextHeight","resizeObserver","jsx","SandboxApp"],"mappings":";;;;;AAeA,MAAMA,IAA8C,CAAC;AAAA,EACnD,SAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,k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AAC;AAAA,IAAA;AAAA,MACC,KAAKhC;AAAA,MACL,SAAQ;AAAA,MACR,OAAM;AAAA,MACN,iBAAe;AAAA,MACf,WAAAN;AAAA,MACA,OAAO;AAAA,QACL,OAAO;AAAA,QACP,QAAQ,GAAGW,CAAM;AAAA,QACjB,QAAQ;AAAA,MAAA;AAAA,MAEV,OAAM;AAAA,IAAA;AAAA,EAAA;AAGZ;"}
@@ -1,6 +1,11 @@
1
1
  import { default as React } from 'react';
2
2
  export interface SandboxAppProps {
3
3
  html: string;
4
+ loadingText?: string;
5
+ styleLoadingText?: string;
6
+ scriptLoadingText?: string;
7
+ fullScreenButtonText?: string;
8
+ resetToken?: number;
4
9
  }
5
10
  declare const SandboxApp: React.FC<SandboxAppProps>;
6
11
  export default SandboxApp;
@@ -1,21 +1,199 @@
1
- import { j as s } from "../../_virtual/jsx-runtime.js";
2
- import { useRef as i, useEffect as u } from "react";
3
- const p = ({ html: o }) => {
4
- const c = i(null);
5
- return u(() => {
6
- const e = c.current;
1
+ import { j as u } from "../../_virtual/jsx-runtime.js";
2
+ import { useRef as n, useState as b, useEffect as v } 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.js";
4
+ const re = ({
5
+ html: f,
6
+ loadingText: q,
7
+ styleLoadingText: B,
8
+ scriptLoadingText: H,
9
+ fullScreenButtonText: L,
10
+ resetToken: p = 0
11
+ }) => {
12
+ const A = n(null), S = n(null), [k, N] = b(!0), [V, C] = b(!1), [_, w] = b(!1), [O, Q] = b(!1), R = n([]), F = n([]), j = n(0), M = n(0), d = n(null), m = n(null), h = n(!1), y = n(!1), I = n(!1), D = n(p), J = 200, o = (e) => {
13
+ e.current && (clearTimeout(e.current), e.current = null);
14
+ }, T = (e, s, c, x) => {
15
+ const a = performance.now() - c.current, E = Math.max(0, J - a);
16
+ o(s), s.current = window.setTimeout(() => {
17
+ e(!1), x?.(), s.current = null;
18
+ }, E);
19
+ };
20
+ v(() => {
21
+ const e = () => {
22
+ Q(!!document.fullscreenElement);
23
+ };
24
+ return document.addEventListener("fullscreenchange", e), () => {
25
+ document.removeEventListener("fullscreenchange", e);
26
+ };
27
+ }, []), v(() => {
28
+ const e = S.current?.ownerDocument;
7
29
  if (!e) return;
8
- e.innerHTML = "";
9
- const t = document.createElement("div");
10
- t.innerHTML = o, t.querySelectorAll("script").forEach((r) => {
11
- const n = document.createElement("script");
12
- Array.from(r.attributes).forEach((a) => {
13
- n.setAttribute(a.name, a.value);
14
- }), n.textContent = r.textContent, r.replaceWith(n);
15
- }), e.append(...Array.from(t.childNodes));
16
- }, [o]), /* @__PURE__ */ s.jsx("div", { ref: c });
30
+ const s = "sandbox-spinner-style";
31
+ let c = e.getElementById(s);
32
+ c || (c = e.createElement("style"), c.id = s, c.textContent = "@keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }", e.head?.appendChild(c));
33
+ }, []), v(() => {
34
+ p !== D.current && (I.current = !1, D.current = p), o(d), o(m), h.current = !1, y.current = !1;
35
+ const e = S.current;
36
+ if (!e) return;
37
+ const s = e.ownerDocument, c = s?.body;
38
+ if (!c) return;
39
+ R.current.forEach((t) => t.remove()), R.current = [], F.current.forEach((t) => t.remove()), F.current = [];
40
+ const x = I.current;
41
+ N(!x), C(!1), w(!1), e.innerHTML = "";
42
+ const a = document.createElement("div");
43
+ a.innerHTML = f;
44
+ const E = (f.match(/<script[\s>]/gi) || []).length, P = (f.match(/<\/script>/gi) || []).length, U = E > 0 && E === P, l = [];
45
+ Array.from(a.querySelectorAll("style, script")).forEach((t) => {
46
+ if (t.tagName.toLowerCase() === "style") {
47
+ const r = s.createElement("style");
48
+ r.textContent = t.textContent || "", Array.from(t.attributes).forEach((i) => {
49
+ r.setAttribute(i.name, i.value);
50
+ }), l.push(r);
51
+ } else {
52
+ const r = s.createElement("script");
53
+ Array.from(t.attributes).forEach((i) => {
54
+ r.setAttribute(i.name, i.value);
55
+ }), r.textContent = t.textContent || "", l.push(r);
56
+ }
57
+ t.remove();
58
+ });
59
+ const z = l.some(
60
+ (t) => t.tagName.toLowerCase() === "style"
61
+ ), G = l.some(
62
+ (t) => t.tagName.toLowerCase() === "script"
63
+ );
64
+ z && (h.current = !0, j.current = performance.now(), o(d), C(!0)), G && (y.current = !0, M.current = performance.now(), o(m), w(!0));
65
+ const W = !!a.firstElementChild;
66
+ N(!W && !x), W && (I.current = !0);
67
+ const X = Array.from(a.childNodes);
68
+ e.append(...X), l.forEach((t) => {
69
+ if (t.tagName.toLowerCase() === "style") {
70
+ s.head?.appendChild(t), R.current.push(t);
71
+ return;
72
+ }
73
+ if (U) {
74
+ const r = t, i = r.textContent || "";
75
+ if (!r.src)
76
+ try {
77
+ new Function(i);
78
+ } catch {
79
+ r.remove();
80
+ return;
81
+ }
82
+ try {
83
+ c.appendChild(r), F.current.push(r);
84
+ } catch {
85
+ r.remove();
86
+ }
87
+ } else
88
+ t.remove();
89
+ }), requestAnimationFrame(() => {
90
+ z && T(
91
+ C,
92
+ d,
93
+ j,
94
+ () => {
95
+ h.current = !1;
96
+ }
97
+ ), G && T(
98
+ w,
99
+ m,
100
+ M,
101
+ () => {
102
+ y.current = !1;
103
+ }
104
+ );
105
+ });
106
+ }, [f, p]), v(
107
+ () => () => {
108
+ o(d), o(m);
109
+ },
110
+ []
111
+ );
112
+ const g = _ || y.current ? H || "Building scripts cache..." : V || h.current ? B || "Building styles..." : k ? q || "Loading..." : null, K = () => {
113
+ const e = A.current;
114
+ if (e) {
115
+ if (!document.fullscreenElement) {
116
+ e.requestFullscreen?.().catch(() => {
117
+ });
118
+ return;
119
+ }
120
+ document.exitFullscreen?.();
121
+ }
122
+ };
123
+ return /* @__PURE__ */ u.jsxs(
124
+ "div",
125
+ {
126
+ ref: A,
127
+ style: { position: "relative", minHeight: 120 },
128
+ "aria-busy": !!g,
129
+ children: [
130
+ /* @__PURE__ */ u.jsx(
131
+ "div",
132
+ {
133
+ ref: S,
134
+ style: {
135
+ pointerEvents: g ? "none" : void 0
136
+ }
137
+ }
138
+ ),
139
+ /* @__PURE__ */ u.jsx(
140
+ "button",
141
+ {
142
+ type: "button",
143
+ onClick: K,
144
+ style: {
145
+ position: "absolute",
146
+ top: 8,
147
+ right: 8,
148
+ zIndex: 30,
149
+ padding: "6px 10px",
150
+ borderRadius: 6,
151
+ border: "1px solid #cbd5e1",
152
+ background: "#ffffffcc",
153
+ color: "#0f172a",
154
+ fontSize: 12,
155
+ fontWeight: 600,
156
+ cursor: "pointer",
157
+ boxShadow: "0 4px 10px rgba(15, 23, 42, 0.08)"
158
+ },
159
+ children: O ? L || "Exit Fullscreen" : L || "Fullscreen"
160
+ }
161
+ ),
162
+ g && /* @__PURE__ */ u.jsxs(
163
+ "div",
164
+ {
165
+ style: {
166
+ position: "absolute",
167
+ inset: 0,
168
+ display: "flex",
169
+ alignItems: "center",
170
+ justifyContent: "center",
171
+ background: "rgba(51, 51, 51, 0.80)",
172
+ color: "#ffffff",
173
+ fontSize: 16,
174
+ fontWeight: 700,
175
+ gap: 10,
176
+ pointerEvents: "auto",
177
+ zIndex: 20
178
+ },
179
+ children: [
180
+ /* @__PURE__ */ u.jsx(
181
+ Y,
182
+ {
183
+ "aria-hidden": !0,
184
+ size: 20,
185
+ style: { animation: "sandbox-spin 1s linear infinite" }
186
+ }
187
+ ),
188
+ g
189
+ ]
190
+ }
191
+ )
192
+ ]
193
+ }
194
+ );
17
195
  };
18
196
  export {
19
- p as default
197
+ re as default
20
198
  };
21
199
  //# sourceMappingURL=SandboxApp.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SandboxApp.js","sources":["../../../src/components/ContentRender/SandboxApp.tsx"],"sourcesContent":["import React, { useEffect, useRef } from \"react\";\n\nexport interface SandboxAppProps {\n html: string;\n}\n\nconst SandboxApp: React.FC<SandboxAppProps> = ({ html }) => {\n const containerRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const container = containerRef.current;\n if (!container) return;\n\n container.innerHTML = \"\";\n const wrapper = document.createElement(\"div\");\n wrapper.innerHTML = html;\n\n // Ensure inline scripts execute by recreating them after injection\n wrapper.querySelectorAll(\"script\").forEach((script) => {\n const replacement = document.createElement(\"script\");\n Array.from(script.attributes).forEach((attr) => {\n replacement.setAttribute(attr.name, attr.value);\n });\n replacement.textContent = script.textContent;\n script.replaceWith(replacement);\n });\n\n container.append(...Array.from(wrapper.childNodes));\n }, [html]);\n\n return <div ref={containerRef} />;\n};\n\nexport default SandboxApp;\n"],"names":["SandboxApp","html","containerRef","useRef","useEffect","container","wrapper","script","replacement","attr","jsx"],"mappings":";;AAMA,MAAMA,IAAwC,CAAC,EAAE,MAAAC,QAAW;AAC1D,QAAMC,IAAeC,EAAuB,IAAI;AAEhD,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAYH,EAAa;AAC/B,QAAI,CAACG,EAAW;AAEhB,IAAAA,EAAU,YAAY;AACtB,UAAMC,IAAU,SAAS,cAAc,KAAK;AAC5C,IAAAA,EAAQ,YAAYL,GAGpBK,EAAQ,iBAAiB,QAAQ,EAAE,QAAQ,CAACC,MAAW;AACrD,YAAMC,IAAc,SAAS,cAAc,QAAQ;AACnD,YAAM,KAAKD,EAAO,UAAU,EAAE,QAAQ,CAACE,MAAS;AAC9C,QAAAD,EAAY,aAAaC,EAAK,MAAMA,EAAK,KAAK;AAAA,MAChD,CAAC,GACDD,EAAY,cAAcD,EAAO,aACjCA,EAAO,YAAYC,CAAW;AAAA,IAChC,CAAC,GAEDH,EAAU,OAAO,GAAG,MAAM,KAAKC,EAAQ,UAAU,CAAC;AAAA,EACpD,GAAG,CAACL,CAAI,CAAC,GAEFS,gBAAAA,EAAAA,IAAC,OAAA,EAAI,KAAKR,EAAA,CAAc;AACjC;"}
1
+ {"version":3,"file":"SandboxApp.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 resetToken?: number;\n}\n\nconst SandboxApp: React.FC<SandboxAppProps> = ({\n html,\n loadingText,\n styleLoadingText,\n scriptLoadingText,\n fullScreenButtonText,\n resetToken = 0,\n}) => {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const [isWaitingFirstDiv, setIsWaitingFirstDiv] = useState(true);\n const [isGeneratingStyles, setIsGeneratingStyles] = useState(false);\n const [isGeneratingScripts, setIsGeneratingScripts] = useState(false);\n const [isFullscreen, setIsFullscreen] = 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 onFullscreenChange = () => {\n setIsFullscreen(!!document.fullscreenElement);\n };\n document.addEventListener(\"fullscreenchange\", onFullscreenChange);\n return () => {\n document.removeEventListener(\"fullscreenchange\", onFullscreenChange);\n };\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 styleEl.textContent =\n \"@keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }\";\n doc.head?.appendChild(styleEl);\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\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 container.innerHTML = \"\";\n const wrapper = document.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\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.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 if (isWaitingFirstDiv) return loadingText || \"Loading...\";\n return null;\n })();\n\n const handleToggleFullscreen = () => {\n const wrapper = wrapperRef.current;\n if (!wrapper) return;\n if (!document.fullscreenElement) {\n wrapper.requestFullscreen?.().catch(() => {});\n return;\n }\n document.exitFullscreen?.();\n };\n\n return (\n <div\n ref={wrapperRef}\n style={{ position: \"relative\", minHeight: 120 }}\n aria-busy={!!overlayMessage}\n >\n <div\n ref={containerRef}\n style={{\n pointerEvents: overlayMessage ? \"none\" : undefined,\n }}\n />\n <button\n type=\"button\"\n onClick={handleToggleFullscreen}\n style={{\n position: \"absolute\",\n top: 8,\n right: 8,\n zIndex: 30,\n padding: \"6px 10px\",\n borderRadius: 6,\n border: \"1px solid #cbd5e1\",\n background: \"#ffffffcc\",\n color: \"#0f172a\",\n fontSize: 12,\n fontWeight: 600,\n cursor: \"pointer\",\n boxShadow: \"0 4px 10px rgba(15, 23, 42, 0.08)\",\n }}\n >\n {isFullscreen\n ? fullScreenButtonText || \"Exit Fullscreen\"\n : fullScreenButtonText || \"Fullscreen\"}\n </button>\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":["SandboxApp","html","loadingText","styleLoadingText","scriptLoadingText","fullScreenButtonText","resetToken","wrapperRef","useRef","containerRef","isWaitingFirstDiv","setIsWaitingFirstDiv","useState","isGeneratingStyles","setIsGeneratingStyles","isGeneratingScripts","setIsGeneratingScripts","isFullscreen","setIsFullscreen","appendedStylesRef","appendedScriptsRef","styleStartRef","scriptStartRef","styleTimerRef","scriptTimerRef","hasStylesRef","hasScriptsRef","hasRenderedContentRef","prevResetTokenRef","MIN_LOADING_MS","clearTimer","timerRef","settleStateWithMinimumDelay","setter","startRef","onDone","elapsed","delay","useEffect","onFullscreenChange","doc","styleId","styleEl","container","body","node","hasRenderedBefore","wrapper","openScriptCount","closeScriptCount","shouldExecuteScripts","resourceQueue","cloned","attr","replacement","hasStyles","hasScripts","hasFirstElement","contentNodes","scriptNode","scriptText","overlayMessage","handleToggleFullscreen","jsxs","jsx","Loader2"],"mappings":";;;AAYA,MAAMA,KAAwC,CAAC;AAAA,EAC7C,MAAAC;AAAA,EACA,aAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,sBAAAC;AAAA,EACA,YAAAC,IAAa;AACf,MAAM;AACJ,QAAMC,IAAaC,EAAuB,IAAI,GACxCC,IAAeD,EAAuB,IAAI,GAC1C,CAACE,GAAmBC,CAAoB,IAAIC,EAAS,EAAI,GACzD,CAACC,GAAoBC,CAAqB,IAAIF,EAAS,EAAK,GAC5D,CAACG,GAAqBC,CAAsB,IAAIJ,EAAS,EAAK,GAC9D,CAACK,GAAcC,CAAe,IAAIN,EAAS,EAAK,GAChDO,IAAoBX,EAA2B,EAAE,GACjDY,IAAqBZ,EAA4B,EAAE,GACnDa,IAAgBb,EAAO,CAAC,GACxBc,IAAiBd,EAAO,CAAC,GACzBe,IAAgBf,EAAsB,IAAI,GAC1CgB,IAAiBhB,EAAsB,IAAI,GAC3CiB,IAAejB,EAAO,EAAK,GAC3BkB,IAAgBlB,EAAO,EAAK,GAC5BmB,IAAwBnB,EAAO,EAAK,GACpCoB,IAAoBpB,EAAOF,CAAU,GACrCuB,IAAiB,KAEjBC,IAAa,CAACC,MAAoD;AACtE,IAAIA,EAAS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ACZ,QAAQ;AAAA,cACR,WAAW;AAAA,YAAA;AAAA,YAGZ,UAAA7C,IACGZ,KAAwB,oBACxBA,KAAwB;AAAA,UAAA;AAAA,QAAA;AAAA,QAE7BwD,KACCE,gBAAAA,EAAAA;AAAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAO;AAAA,cACL,UAAU;AAAA,cACV,OAAO;AAAA,cACP,SAAS;AAAA,cACT,YAAY;AAAA,cACZ,gBAAgB;AAAA,cAChB,YAAY;AAAA,cACZ,OAAO;AAAA,cACP,UAAU;AAAA,cACV,YAAY;AAAA,cACZ,KAAK;AAAA,cACL,eAAe;AAAA,cACf,QAAQ;AAAA,YAAA;AAAA,YAGV,UAAA;AAAA,cAAAC,gBAAAA,EAAAA;AAAAA,gBAACC;AAAAA,gBAAA;AAAA,kBACC,eAAW;AAAA,kBACX,MAAM;AAAA,kBACN,OAAO,EAAE,WAAW,kCAAA;AAAA,gBAAkC;AAAA,cAAA;AAAA,cAEvDJ;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAAA;AAIR;"}
@@ -1,5 +1,10 @@
1
1
  import { default as ContentRender } from './ContentRender';
2
2
  export default ContentRender;
3
+ export { default as IframeSandbox } from './IframeSandbox';
4
+ export type { IframeSandboxProps } from './IframeSandbox';
5
+ export type { SandboxAppProps } from './SandboxApp';
6
+ export type { RenderSegment } from './utils/split-content';
7
+ export { splitContentSegments } from './utils/split-content';
3
8
  export { default as ContentRender } from './ContentRender';
4
9
  export { default as MarkdownFlowInput } from './MarkdownFlowInput';
5
10
  export { default as useTypewriter } from './useTypewriter';
@@ -1,7 +1,8 @@
1
1
  import o from "./ContentRender.js";
2
2
  import "../../_virtual/jsx-runtime.js";
3
- import "../ui/inputGroup/input-group.js";
4
3
  import "react";
4
+ import "react-dom/client";
5
+ import "../ui/inputGroup/input-group.js";
5
6
  export {
6
7
  o as ContentRender,
7
8
  o as default
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -0,0 +1,8 @@
1
+ export type RenderSegment = {
2
+ type: "markdown";
3
+ value: string;
4
+ } | {
5
+ type: "sandbox";
6
+ value: string;
7
+ };
8
+ export declare const splitContentSegments: (raw: string) => RenderSegment[];
@@ -0,0 +1,18 @@
1
+ const m = (t) => {
2
+ const o = /<(script|style|link|iframe|html|head|body|meta|title|base|template|div|section|article|main)[\s>]/i, e = t.search(o);
3
+ if (e === -1)
4
+ return [{ type: "markdown", value: t }];
5
+ const a = /<\/[a-z][^>]*>\s*\n(?=[^\s<])/gi;
6
+ let i = t.length, n;
7
+ for (; n = a.exec(t); )
8
+ if (!(n.index <= e)) {
9
+ i = n.index + n[0].length - 1;
10
+ break;
11
+ }
12
+ const s = [], l = t.slice(0, e), r = t.slice(e, i), c = t.slice(i);
13
+ return l.trim() && s.push({ type: "markdown", value: l }), s.push({ type: "sandbox", value: r }), c.trim() && s.push(...m(c)), s;
14
+ };
15
+ export {
16
+ m as splitContentSegments
17
+ };
18
+ //# sourceMappingURL=split-content.js.map