dishui 0.0.83 → 0.0.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Demo/index.js +2 -2
- package/dist/components/Demo/index.js.map +1 -1
- package/dist/components/Input/index.js +52 -62
- package/dist/components/Input/index.js.map +1 -1
- package/dist/components/LayoutSuite/index.d.ts +10 -0
- package/dist/components/LayoutSuite/index.js +27 -18
- package/dist/components/LayoutSuite/index.js.map +1 -1
- package/dist/components/Markdown/markdownComponents.js +1 -0
- package/dist/components/Markdown/markdownComponents.js.map +1 -1
- package/dist/components/Markdown/useMarkdownSource.js +46 -31
- package/dist/components/Markdown/useMarkdownSource.js.map +1 -1
- package/dist/components/Markdown/useMarkmapRenderer.js +44 -31
- package/dist/components/Markdown/useMarkmapRenderer.js.map +1 -1
- package/dist/components/Markdown/useMermaidRenderer.js +49 -31
- package/dist/components/Markdown/useMermaidRenderer.js.map +1 -1
- package/dist/components/Page/index.d.ts +18 -4
- package/dist/components/Page/index.js +47 -35
- package/dist/components/Page/index.js.map +1 -1
- package/dist/components/ProtectedRoute/index.d.ts +2 -1
- package/dist/components/ProtectedRoute/index.js +16 -6
- package/dist/components/ProtectedRoute/index.js.map +1 -1
- package/dist/components/Select/index.d.ts +6 -0
- package/dist/components/Select/index.js +166 -136
- package/dist/components/Select/index.js.map +1 -1
- package/dist/components/Tabs/index.d.ts +12 -1
- package/dist/components/Tabs/index.js +42 -17
- package/dist/components/Tabs/index.js.map +1 -1
- package/dist/components/Text/index.d.ts +1 -1
- package/dist/components/Text/index.js +2 -2
- package/dist/components/Text/index.js.map +1 -1
- package/dist/components/pro/ArticleContextMenu/index.js +7 -7
- package/dist/components/pro/CodeEditor/editors/CodeEditor.js +200 -189
- package/dist/components/pro/CodeEditor/editors/CodeEditor.js.map +1 -1
- package/dist/components/pro/CodeEditor/types.d.ts +3 -0
- package/dist/components/pro/DataTable/DataTable.d.ts +1 -1
- package/dist/components/pro/DataTable/DataTable.js +98 -240
- package/dist/components/pro/DataTable/DataTable.js.map +1 -1
- package/dist/components/pro/DataTable/components/TableBody.js +14 -16
- package/dist/components/pro/DataTable/components/TableBody.js.map +1 -1
- package/dist/components/pro/DataTable/components/TablePagination.d.ts +3 -9
- package/dist/components/pro/DataTable/components/TablePagination.js +29 -25
- package/dist/components/pro/DataTable/components/TablePagination.js.map +1 -1
- package/dist/components/pro/DataTable/tanstack-table.d.ts +2 -2
- package/dist/components/pro/DataTable/tanstack-table.js +29 -21
- package/dist/components/pro/DataTable/tanstack-table.js.map +1 -1
- package/dist/components/pro/DataTable/treeDataUtils.d.ts +2 -0
- package/dist/components/pro/DataTable/treeDataUtils.js +18 -19
- package/dist/components/pro/DataTable/treeDataUtils.js.map +1 -1
- package/dist/components/pro/DataTable/types.d.ts +24 -0
- package/dist/components/pro/DataTable/useDataTableModel.d.ts +16 -0
- package/dist/components/pro/DataTable/useDataTableModel.js +148 -0
- package/dist/components/pro/DataTable/useDataTableModel.js.map +1 -0
- package/dist/components/pro/FileExplorer/Breadcrumb.js +12 -12
- package/dist/components/pro/Flow/nodes/DataNodeView.js +87 -82
- package/dist/components/pro/Flow/nodes/DataNodeView.js.map +1 -1
- package/dist/components/pro/Flow/nodes/MediaContent.js +1 -1
- package/dist/components/pro/Flow/nodes/MediaContent.js.map +1 -1
- package/dist/components/pro/Flow/nodes/MediaOverlay.js +1 -1
- package/dist/components/pro/Flow/nodes/MediaOverlay.js.map +1 -1
- package/dist/components/pro/Flow/nodes/Model3DView.js +69 -63
- package/dist/components/pro/Flow/nodes/Model3DView.js.map +1 -1
- package/dist/components/pro/Flow/nodes/chartGeometryBudget.d.ts +14 -0
- package/dist/components/pro/Flow/nodes/chartGeometryBudget.js +76 -0
- package/dist/components/pro/Flow/nodes/chartGeometryBudget.js.map +1 -0
- package/dist/components/pro/Flow/nodes/demandRender.d.ts +11 -0
- package/dist/components/pro/Flow/nodes/demandRender.js +26 -0
- package/dist/components/pro/Flow/nodes/demandRender.js.map +1 -0
- package/dist/components/pro/RichTextEditor/SlashMenu.js +68 -58
- package/dist/components/pro/RichTextEditor/SlashMenu.js.map +1 -1
- package/dist/contexts/AppContext.d.ts +1 -0
- package/dist/contexts/AppContext.js +144 -145
- package/dist/contexts/AppContext.js.map +1 -1
- package/dist/contexts/authentication.d.ts +7 -0
- package/dist/contexts/authentication.js +22 -0
- package/dist/contexts/authentication.js.map +1 -0
- package/dist/dishui.css +1 -1
- package/dist/hooks/useControllableState.d.ts +6 -14
- package/dist/hooks/useControllableState.js +21 -15
- package/dist/hooks/useControllableState.js.map +1 -1
- package/dist/hooks/useTableColumns.d.ts +3 -3
- package/dist/hooks/useTableColumns.js +2 -2
- package/dist/hooks/useTableColumns.js.map +1 -1
- package/dist/hooks/useTableData.d.ts +11 -4
- package/dist/hooks/useTableData.js +44 -26
- package/dist/hooks/useTableData.js.map +1 -1
- package/dist/index-nostyled.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +97 -97
- package/dist/layouts/Sidebar.d.ts +3 -1
- package/dist/layouts/Sidebar.js +131 -122
- package/dist/layouts/Sidebar.js.map +1 -1
- package/dist/utils/i18n.js +1 -1
- package/dist/utils/i18n.js.map +1 -1
- package/dist/utils/routerBuilder.d.ts +7 -5
- package/dist/utils/routerBuilder.js +11 -15
- package/dist/utils/routerBuilder.js.map +1 -1
- package/dist/utils/safeStorage.d.ts +8 -0
- package/dist/utils/safeStorage.js +45 -0
- package/dist/utils/safeStorage.js.map +1 -0
- package/package.json +22 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MediaContent.js","names":[],"sources":["../../../../../src/components/pro/Flow/nodes/MediaContent.tsx"],"sourcesContent":["import React, { useEffect, useMemo, useRef, useState } from 'react';\nimport katex from 'katex';\nimport mermaid from 'mermaid';\nimport Markdown from '../../../Markdown';\nimport type { FlowNode, FlowAIConfig } from '../types';\nimport { streamAIChat, type AIChatMessage } from './aiClient';\nimport { resolveThemeColorCss, resolveThemeColor } from '../utils/themeColor';\nimport 'katex/dist/katex.min.css';\nimport { Model3DView } from './Model3DView';\n\n// Data-node view pulls in DataTable + Chart; lazy-load so it only enters the\n// bundle when a data node actually renders.\nconst DataNodeView = React.lazy(() =>\n import('./DataNodeView').then((m) => ({ default: m.DataNodeView })),\n);\n\nlet mermaidReady = false;\nfunction ensureMermaid() {\n if (mermaidReady) return;\n mermaid.initialize({ startOnLoad: false, theme: 'default', securityLevel: 'loose', fontFamily: 'inherit' });\n mermaidReady = true;\n}\n\n/** Renders a Mermaid diagram from source into an inline SVG. */\nfunction MermaidView({ content, color }: { content: string; color?: string }) {\n const [svg, setSvg] = useState('');\n const [error, setError] = useState<string | null>(null);\n const idRef = useRef(`flow-mermaid-${Math.random().toString(36).slice(2)}`);\n\n useEffect(() => {\n let cancelled = false;\n ensureMermaid();\n const src = content.trim();\n if (!src) { setSvg(''); setError(null); return; }\n mermaid\n .render(idRef.current, src)\n .then(({ svg }) => { if (!cancelled) { setSvg(svg); setError(null); } })\n .catch((e) => { if (!cancelled) setError(e?.message ?? 'Mermaid error'); });\n return () => { cancelled = true; };\n }, [content]);\n\n if (error) return <div className=\"flow-media-error\">{error}</div>;\n return <div className=\"flow-media-mermaid\" style={{ color }} dangerouslySetInnerHTML={{ __html: svg }} />;\n}\n\n/** Renders a LaTeX formula (display mode) via KaTeX. */\nfunction MathView({ content, color, fontSize }: { content: string; color?: string; fontSize?: number }) {\n const html = useMemo(() => {\n try {\n return katex.renderToString(content.trim() || '\\\\;', { displayMode: true, throwOnError: false });\n } catch (e: any) {\n return `<span class=\"flow-media-error\">${e?.message ?? 'KaTeX error'}</span>`;\n }\n }, [content]);\n return <div className=\"flow-media-math\" style={{ color, fontSize }} dangerouslySetInnerHTML={{ __html: html }} />;\n}\n\n/** Renders raw HTML in a sandboxed iframe (isolated from the host document).\n * A base stylesheet is injected so the fragment inherits the node's themed\n * text color / font size and a transparent background, keeping it readable on\n * any theme without the author having to set colors. */\nfunction HtmlView({ content, interactive, color, fontSize }: { content: string; interactive: boolean; color?: string; fontSize?: number }) {\n const srcDoc = useMemo(() => {\n const base = `<!doctype html><html><head><meta charset=\"utf-8\"><style>\n :root { color-scheme: light dark; }\n html, body { margin: 0; background: transparent; }\n body {\n color: ${color ?? '#111827'};\n font-size: ${fontSize ?? 13}px;\n font-family: system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif;\n line-height: 1.5;\n padding: 0;\n }\n a { color: inherit; }\n </style></head><body>${content}</body></html>`;\n return base;\n }, [content, color, fontSize]);\n return (\n <iframe\n title=\"html-media\"\n className=\"flow-media-iframe\"\n style={{ pointerEvents: interactive ? 'auto' : 'none' }}\n sandbox=\"allow-scripts allow-same-origin allow-popups allow-forms\"\n srcDoc={srcDoc}\n />\n );\n}\n\nfunction ImageView({ content }: { content: string }) {\n const src = content.trim();\n if (!src) {\n return <div className=\"flow-media-image-empty\">输入图片链接,或直接粘贴图片</div>;\n }\n return (\n <img\n className=\"flow-media-image\"\n src={src}\n alt=\"\"\n draggable={false}\n referrerPolicy=\"no-referrer\"\n />\n );\n}\n\n/** Interactive AI chat backed by an OpenAI/Anthropic-compatible endpoint. */\nfunction AIView({ node, config, interactive, color }: { node: FlowNode; config?: FlowAIConfig; interactive: boolean; color?: string }) {\n const [messages, setMessages] = useState<AIChatMessage[]>([]);\n const [input, setInput] = useState('');\n const [streaming, setStreaming] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const abortRef = useRef<AbortController | null>(null);\n const scrollRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n scrollRef.current?.scrollTo({ top: scrollRef.current.scrollHeight });\n }, [messages, streaming]);\n\n useEffect(() => () => abortRef.current?.abort(), []);\n\n const canSend = !!config?.gateway && !!config?.model && !streaming;\n\n const send = async () => {\n const text = input.trim();\n if (!text || !config?.gateway) return;\n setError(null);\n // Only keep non-empty assistant messages in history; an aborted/errored\n // request can leave an empty assistant placeholder behind, which the API\n // then rejects (\"assistant message must not be empty\").\n const history = messages.filter(\n (m) => !(m.role === 'assistant' && m.content.trim() === ''),\n );\n const next: AIChatMessage[] = [...history, { role: 'user', content: text }];\n setMessages(next);\n setInput('');\n setStreaming(true);\n const ac = new AbortController();\n abortRef.current = ac;\n let acc = '';\n setMessages((m) => [...m, { role: 'assistant', content: '' }]);\n try {\n for await (const delta of streamAIChat(config, next, ac.signal)) {\n acc += delta;\n setMessages((m) => {\n const copy = m.slice();\n copy[copy.length - 1] = { role: 'assistant', content: acc };\n return copy;\n });\n }\n } catch (e: any) {\n if (e?.name !== 'AbortError') setError(e?.message ?? 'Request failed');\n } finally {\n // Drop the trailing assistant placeholder if nothing streamed in.\n setMessages((m) => {\n const last = m[m.length - 1];\n if (last && last.role === 'assistant' && last.content.trim() === '') {\n return m.slice(0, -1);\n }\n return m;\n });\n setStreaming(false);\n abortRef.current = null;\n }\n };\n\n return (\n <div className=\"flow-media-ai\" style={{ color }}>\n <div className=\"flow-media-ai-header\">\n {config?.model ? `AI · ${config.model}` : (node.data.label || 'AI')}\n </div>\n <div className=\"flow-media-ai-log\" ref={scrollRef}>\n {messages.length === 0 && (\n <div className=\"flow-media-ai-empty\">\n {config?.gateway ? '开始对话…' : '请在属性面板配置 AI 接口'}\n </div>\n )}\n {messages.map((m, i) => (\n <div key={i} className={`flow-media-ai-msg flow-media-ai-msg--${m.role}`}>\n {m.role === 'assistant'\n ? <Markdown content={m.content || '…'} enableMermaid={false} enableMarkmap={false} />\n : <span>{m.content}</span>}\n </div>\n ))}\n {error && <div className=\"flow-media-error\">{error}</div>}\n </div>\n <div className=\"flow-media-ai-input\" style={{ pointerEvents: interactive ? 'auto' : 'none' }}>\n <textarea\n value={input}\n placeholder=\"输入消息,Enter 发送\"\n onChange={(e) => setInput(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); if (canSend) send(); }\n }}\n onPointerDown={(e) => e.stopPropagation()}\n />\n {streaming ? (\n <button type=\"button\" onClick={() => abortRef.current?.abort()}>停止</button>\n ) : (\n <button type=\"button\" disabled={!canSend || !input.trim()} onClick={send}>发送</button>\n )}\n </div>\n </div>\n );\n}\n\n/** Dispatches to the correct renderer for the node's media kind. */\nexport function MediaContent({ node, interactive }: { node: FlowNode; interactive: boolean }) {\n const kind = node.data.mediaKind ?? 'markdown';\n const content = node.data.mediaContent ?? '';\n const textColor = resolveThemeColorCss(node.data.labelColor ?? node.data.color, '#111827');\n\n switch (kind) {\n case 'markdown':\n return (\n <div className=\"flow-media-markdown\" style={{ color: textColor, fontSize: node.data.fontSize }}>\n <Markdown content={content} />\n </div>\n );\n case 'html':\n // The iframe is an isolated document with no access to the parent's CSS\n // variables, so pass a concrete resolved color instead of a var().\n return (\n <HtmlView\n content={content}\n interactive={interactive}\n color={resolveThemeColor(node.data.labelColor ?? node.data.color, '#111827')}\n fontSize={node.data.fontSize}\n />\n );\n case 'mermaid':\n return <MermaidView content={content} color={textColor} />;\n case 'math':\n return <MathView content={content} color={textColor} fontSize={node.data.fontSize} />;\n case 'image':\n return <ImageView content={content} />;\n case 'model3d':\n return (\n <Model3DView\n content={content}\n format={node.data.modelFormat ?? 'stl'}\n interactive={interactive}\n />\n );\n case 'ai':\n return <AIView node={node} config={node.data.aiConfig} interactive={interactive} color={textColor} />;\n case 'data':\n return (\n <div className=\"flow-media-data\" style={{ pointerEvents: interactive ? 'auto' : 'none' }}>\n <DataNodeView\n config={node.data.dataConfig ?? { columns: [], rows: [], view: 'table' }}\n surfaceColor={node.data.fill === 'transparent' ? undefined : resolveThemeColorCss(node.data.fill, '')}\n textColor={textColor}\n primaryColor={resolveThemeColorCss(node.data.color, '')}\n />\n </div>\n );\n default:\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;AAYA,IAAM,IAAe,EAAM,WACzB,OAAO,oBAAiB,CAAC,MAAM,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,CACpE,GAEI,IAAe;AACnB,SAAS,IAAgB;CACnB,AAEJ,OADA,EAAQ,WAAW;EAAE,aA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rB,CAAA;EAEL,KAAK,WACH,OAAO,kBAAC,GAAD;GAAsB;GAAS,OAAO;EAAY,CAAA;EAC3D,KAAK,QACH,OAAO,kBAAC,GAAD;GAAmB;GAAS,OAAO;GAAW,UAAU,EAAK,KAAK;EAAW,CAAA;EACtF,KAAK,SACH,OAAO,kBAAC,GAAD,EAAoB,WAAU,CAAA;EACvC,KAAK,WACH,OACE,kBAAC,GAAD;GACW;GACT,QAAQ,EAAK,KAAK,eAAe;GACpB;EACd,CAAA;EAEL,KAAK,MACH,OAAO,kBAAC,GAAD;GAAc;GAAM,QAAQ,EAAK,KAAK;GAAuB;GAAa,OAAO;EAAY,CAAA;EACtG,KAAK,QACH,OACE,kBAAC,OAAD;GAAK,WAAU;GAAkB,OAAO,EAAE,eAAe,IAAc,SAAS,OAAO;GACrF,UAAA,kBAAC,GAAD;IACE,QAAQ,EAAK,KAAK,cAAc;KAAE,SAAS,CAAC;KAAG,MAAM,CAAC;KAAG,MAAM;IAAQ;IACvE,cAAc,EAAK,KAAK,SAAS,gBAAgB,KAAA,IAAY,EAAqB,EAAK,KAAK,MAAM,EAAE;IACzF;IACX,cAAc,EAAqB,EAAK,KAAK,OAAO,EAAE;GACvD,CAAA;EACE,CAAA;EAET,SACE,OAAO;CACX;AACF"}
|
|
1
|
+
{"version":3,"file":"MediaContent.js","names":[],"sources":["../../../../../src/components/pro/Flow/nodes/MediaContent.tsx"],"sourcesContent":["import React, { useEffect, useMemo, useRef, useState } from 'react';\nimport katex from 'katex';\nimport mermaid from 'mermaid';\nimport Markdown from '../../../Markdown';\nimport type { FlowNode, FlowAIConfig } from '../types';\nimport { streamAIChat, type AIChatMessage } from './aiClient';\nimport { resolveThemeColorCss, resolveThemeColor } from '../utils/themeColor';\nimport 'katex/dist/katex.min.css';\nimport { Model3DView } from './Model3DView';\n\n// Data-node view pulls in DataTable + Chart; lazy-load so it only enters the\n// bundle when a data node actually renders.\nconst DataNodeView = React.lazy(() =>\n import('./DataNodeView').then((m) => ({ default: m.DataNodeView })),\n);\n\nlet mermaidReady = false;\nfunction ensureMermaid() {\n if (mermaidReady) return;\n mermaid.initialize({ startOnLoad: false, theme: 'default', securityLevel: 'loose', fontFamily: 'inherit' });\n mermaidReady = true;\n}\n\n/** Renders a Mermaid diagram from source into an inline SVG. */\nfunction MermaidView({ content, color }: { content: string; color?: string }) {\n const [svg, setSvg] = useState('');\n const [error, setError] = useState<string | null>(null);\n const idRef = useRef(`flow-mermaid-${Math.random().toString(36).slice(2)}`);\n\n useEffect(() => {\n let cancelled = false;\n ensureMermaid();\n const src = content.trim();\n if (!src) { setSvg(''); setError(null); return; }\n mermaid\n .render(idRef.current, src)\n .then(({ svg }) => { if (!cancelled) { setSvg(svg); setError(null); } })\n .catch((e) => { if (!cancelled) setError(e?.message ?? 'Mermaid error'); });\n return () => { cancelled = true; };\n }, [content]);\n\n if (error) return <div className=\"flow-media-error\">{error}</div>;\n return <div className=\"flow-media-mermaid\" style={{ color }} dangerouslySetInnerHTML={{ __html: svg }} />;\n}\n\n/** Renders a LaTeX formula (display mode) via KaTeX. */\nfunction MathView({ content, color, fontSize }: { content: string; color?: string; fontSize?: number }) {\n const html = useMemo(() => {\n try {\n return katex.renderToString(content.trim() || '\\\\;', { displayMode: true, throwOnError: false });\n } catch (e: any) {\n return `<span class=\"flow-media-error\">${e?.message ?? 'KaTeX error'}</span>`;\n }\n }, [content]);\n return <div className=\"flow-media-math\" style={{ color, fontSize }} dangerouslySetInnerHTML={{ __html: html }} />;\n}\n\n/** Renders raw HTML in a sandboxed iframe (isolated from the host document).\n * A base stylesheet is injected so the fragment inherits the node's themed\n * text color / font size and a transparent background, keeping it readable on\n * any theme without the author having to set colors.\n * Content is always untrusted: scripts can drive the preview, but the opaque\n * sandbox origin prevents host DOM/storage access. Do not add allow-same-origin\n * alongside allow-scripts; interactive only controls pointer input. */\nfunction HtmlView({ content, interactive, color, fontSize }: { content: string; interactive: boolean; color?: string; fontSize?: number }) {\n const srcDoc = useMemo(() => {\n const base = `<!doctype html><html><head><meta charset=\"utf-8\"><style>\n :root { color-scheme: light dark; }\n html, body { margin: 0; background: transparent; }\n body {\n color: ${color ?? '#111827'};\n font-size: ${fontSize ?? 13}px;\n font-family: system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif;\n line-height: 1.5;\n padding: 0;\n }\n a { color: inherit; }\n </style></head><body>${content}</body></html>`;\n return base;\n }, [content, color, fontSize]);\n return (\n <iframe\n title=\"html-media\"\n className=\"flow-media-iframe\"\n style={{ pointerEvents: interactive ? 'auto' : 'none' }}\n sandbox=\"allow-scripts\"\n srcDoc={srcDoc}\n />\n );\n}\n\nfunction ImageView({ content }: { content: string }) {\n const src = content.trim();\n if (!src) {\n return <div className=\"flow-media-image-empty\">输入图片链接,或直接粘贴图片</div>;\n }\n return (\n <img\n className=\"flow-media-image\"\n src={src}\n alt=\"\"\n draggable={false}\n referrerPolicy=\"no-referrer\"\n />\n );\n}\n\n/** Interactive AI chat backed by an OpenAI/Anthropic-compatible endpoint. */\nfunction AIView({ node, config, interactive, color }: { node: FlowNode; config?: FlowAIConfig; interactive: boolean; color?: string }) {\n const [messages, setMessages] = useState<AIChatMessage[]>([]);\n const [input, setInput] = useState('');\n const [streaming, setStreaming] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const abortRef = useRef<AbortController | null>(null);\n const scrollRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n scrollRef.current?.scrollTo({ top: scrollRef.current.scrollHeight });\n }, [messages, streaming]);\n\n useEffect(() => () => abortRef.current?.abort(), []);\n\n const canSend = !!config?.gateway && !!config?.model && !streaming;\n\n const send = async () => {\n const text = input.trim();\n if (!text || !config?.gateway) return;\n setError(null);\n // Only keep non-empty assistant messages in history; an aborted/errored\n // request can leave an empty assistant placeholder behind, which the API\n // then rejects (\"assistant message must not be empty\").\n const history = messages.filter(\n (m) => !(m.role === 'assistant' && m.content.trim() === ''),\n );\n const next: AIChatMessage[] = [...history, { role: 'user', content: text }];\n setMessages(next);\n setInput('');\n setStreaming(true);\n const ac = new AbortController();\n abortRef.current = ac;\n let acc = '';\n setMessages((m) => [...m, { role: 'assistant', content: '' }]);\n try {\n for await (const delta of streamAIChat(config, next, ac.signal)) {\n acc += delta;\n setMessages((m) => {\n const copy = m.slice();\n copy[copy.length - 1] = { role: 'assistant', content: acc };\n return copy;\n });\n }\n } catch (e: any) {\n if (e?.name !== 'AbortError') setError(e?.message ?? 'Request failed');\n } finally {\n // Drop the trailing assistant placeholder if nothing streamed in.\n setMessages((m) => {\n const last = m[m.length - 1];\n if (last && last.role === 'assistant' && last.content.trim() === '') {\n return m.slice(0, -1);\n }\n return m;\n });\n setStreaming(false);\n abortRef.current = null;\n }\n };\n\n return (\n <div className=\"flow-media-ai\" style={{ color }}>\n <div className=\"flow-media-ai-header\">\n {config?.model ? `AI · ${config.model}` : (node.data.label || 'AI')}\n </div>\n <div className=\"flow-media-ai-log\" ref={scrollRef}>\n {messages.length === 0 && (\n <div className=\"flow-media-ai-empty\">\n {config?.gateway ? '开始对话…' : '请在属性面板配置 AI 接口'}\n </div>\n )}\n {messages.map((m, i) => (\n <div key={i} className={`flow-media-ai-msg flow-media-ai-msg--${m.role}`}>\n {m.role === 'assistant'\n ? <Markdown content={m.content || '…'} enableMermaid={false} enableMarkmap={false} />\n : <span>{m.content}</span>}\n </div>\n ))}\n {error && <div className=\"flow-media-error\">{error}</div>}\n </div>\n <div className=\"flow-media-ai-input\" style={{ pointerEvents: interactive ? 'auto' : 'none' }}>\n <textarea\n value={input}\n placeholder=\"输入消息,Enter 发送\"\n onChange={(e) => setInput(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); if (canSend) send(); }\n }}\n onPointerDown={(e) => e.stopPropagation()}\n />\n {streaming ? (\n <button type=\"button\" onClick={() => abortRef.current?.abort()}>停止</button>\n ) : (\n <button type=\"button\" disabled={!canSend || !input.trim()} onClick={send}>发送</button>\n )}\n </div>\n </div>\n );\n}\n\n/** Dispatches to the correct renderer for the node's media kind. */\nexport function MediaContent({ node, interactive }: { node: FlowNode; interactive: boolean }) {\n const kind = node.data.mediaKind ?? 'markdown';\n const content = node.data.mediaContent ?? '';\n const textColor = resolveThemeColorCss(node.data.labelColor ?? node.data.color, '#111827');\n\n switch (kind) {\n case 'markdown':\n return (\n <div className=\"flow-media-markdown\" style={{ color: textColor, fontSize: node.data.fontSize }}>\n <Markdown content={content} />\n </div>\n );\n case 'html':\n // The iframe is an isolated document with no access to the parent's CSS\n // variables, so pass a concrete resolved color instead of a var().\n return (\n <HtmlView\n content={content}\n interactive={interactive}\n color={resolveThemeColor(node.data.labelColor ?? node.data.color, '#111827')}\n fontSize={node.data.fontSize}\n />\n );\n case 'mermaid':\n return <MermaidView content={content} color={textColor} />;\n case 'math':\n return <MathView content={content} color={textColor} fontSize={node.data.fontSize} />;\n case 'image':\n return <ImageView content={content} />;\n case 'model3d':\n return (\n <Model3DView\n content={content}\n format={node.data.modelFormat ?? 'stl'}\n interactive={interactive}\n />\n );\n case 'ai':\n return <AIView node={node} config={node.data.aiConfig} interactive={interactive} color={textColor} />;\n case 'data':\n return (\n <div className=\"flow-media-data\" style={{ pointerEvents: interactive ? 'auto' : 'none' }}>\n <DataNodeView\n config={node.data.dataConfig ?? { columns: [], rows: [], view: 'table' }}\n surfaceColor={node.data.fill === 'transparent' ? undefined : resolveThemeColorCss(node.data.fill, '')}\n textColor={textColor}\n primaryColor={resolveThemeColorCss(node.data.color, '')}\n />\n </div>\n );\n default:\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;AAYA,IAAM,IAAe,EAAM,WACzB,OAAO,oBAAiB,CAAC,MAAM,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,CACpE,GAEI,IAAe;AACnB,SAAS,IAAgB;CACnB,AAEJ,OADA,EAAQ,WAAW;EAAE,aAAa;EAAO,OAAO;EAAW,eAAe;EAAS,YAAY;CAAU,CAAC,GAC3F;AACjB;AAGA,SAAS,EAAY,EAAE,YAA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,OAAO,kBAAC,GAAD;GAAmB;GAAS,OAAO;GAAW,UAAU,EAAK,KAAK;EAAW,CAAA;EACtF,KAAK,SACH,OAAO,kBAAC,GAAD,EAAoB,WAAU,CAAA;EACvC,KAAK,WACH,OACE,kBAAC,GAAD;GACW;GACT,QAAQ,EAAK,KAAK,eAAe;GACpB;EACd,CAAA;EAEL,KAAK,MACH,OAAO,kBAAC,GAAD;GAAc;GAAM,QAAQ,EAAK,KAAK;GAAuB;GAAa,OAAO;EAAY,CAAA;EACtG,KAAK,QACH,OACE,kBAAC,OAAD;GAAK,WAAU;GAAkB,OAAO,EAAE,eAAe,IAAc,SAAS,OAAO;GACrF,UAAA,kBAAC,GAAD;IACE,QAAQ,EAAK,KAAK,cAAc;KAAE,SAAS,CAAC;KAAG,MAAM,CAAC;KAAG,MAAM;IAAQ;IACvE,cAAc,EAAK,KAAK,SAAS,gBAAgB,KAAA,IAAY,EAAqB,EAAK,KAAK,MAAM,EAAE;IACzF;IACX,cAAc,EAAqB,EAAK,KAAK,OAAO,EAAE;GACvD,CAAA;EACE,CAAA;EAET,SACE,OAAO;CACX;AACF"}
|
|
@@ -4,7 +4,7 @@ import { resolveThemeColorCss as n } from "../utils/themeColor.js";
|
|
|
4
4
|
import r, { Suspense as i, useMemo as a } from "react";
|
|
5
5
|
import { jsx as o } from "react/jsx-runtime";
|
|
6
6
|
//#region src/components/pro/Flow/nodes/MediaOverlay.tsx
|
|
7
|
-
var s = r.lazy(() => import("./MediaContent.js").then((e) => ({ default: e.MediaContent }))), c = class extends r.Component {
|
|
7
|
+
var s = r.memo(r.lazy(() => import("./MediaContent.js").then((e) => ({ default: e.MediaContent })))), c = class extends r.Component {
|
|
8
8
|
constructor(e) {
|
|
9
9
|
super(e), this.state = { error: null };
|
|
10
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MediaOverlay.js","names":[],"sources":["../../../../../src/components/pro/Flow/nodes/MediaOverlay.tsx"],"sourcesContent":["import React, { useMemo, Suspense } from 'react';\nimport { useFlowContext } from '../context/FlowContext';\nimport { useFlowUI } from '../context/FlowUIContext';\nimport { resolveThemeColorCss } from '../utils/themeColor';\n\n// Lazy-load the media renderers so the heavy optional deps they pull in\n// (react-markdown, mermaid, katex, markmap, …) are only fetched when a media\n// node actually needs to render. This keeps the base `dishui/flow` bundle\n// lightweight and avoids loading that stack for diagrams without media nodes.\nconst MediaContent = React.lazy(() =>\n import('./MediaContent').then((m) => ({ default: m.MediaContent })),\n);\n\n/** Isolates media render/load failures so one bad node never blanks the editor. */\nclass MediaErrorBoundary extends React.Component<\n { children: React.ReactNode },\n { error: Error | null }\n> {\n constructor(props: { children: React.ReactNode }) {\n super(props);\n this.state = { error: null };\n }\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n render() {\n if (this.state.error) {\n return <div className=\"flow-media-error\">{this.state.error.message}</div>;\n }\n return this.props.children;\n }\n}\n\n/**\n * DOM overlay for media nodes. PixiJS draws the frame; this layer renders the\n * live content (markdown/html/mermaid/math/AI) on top, synced to the viewport\n * so it pans and zooms with the canvas.\n *\n * Event model: a media surface is `pointer-events: none` by default so the\n * canvas underneath can be clicked to select/drag the node's frame. The\n * surface only becomes interactive while its node is selected (so AI chat can\n * be typed into, HTML can be scrolled). This also stops an always-interactive\n * iframe/AI box from swallowing pointer gestures and leaving the drag stuck.\n */\nexport function MediaOverlay() {\n const { currentCanvas, selection } = useFlowContext();\n const { viewport, isNodeDragging } = useFlowUI();\n\n const mediaNodes = useMemo(\n () => currentCanvas.nodes.filter((n) => n.type === 'mediaNode'),\n [currentCanvas.nodes],\n );\n\n if (mediaNodes.length === 0) return null;\n\n const { x: vx, y: vy, zoom } = viewport;\n\n return (\n <div className=\"flow-media-layer\">\n {mediaNodes.map((node) => {\n // World → screen (CSS px, matching ViewportManager.worldToScreen).\n const left = node.position.x * zoom + vx;\n const top = node.position.y * zoom + vy;\n // Interactive only while selected, so the canvas stays draggable.\n // Suppress entirely during a drag: an interactive iframe would swallow\n // the pointer and the canvas would never receive pointerup (stuck drag).\n const interactive = selection.nodeIds.has(node.id) && !isNodeDragging;\n // Drive the overlay's background / text from the node's own color data.\n // Theme tokens (`theme:*`) resolve to CSS variables so the media content\n // follows theme switches natively; literal colors are used as-is. This\n // keeps html / ai / data (which render opaque content) in sync with the\n // fill/color chosen in the inspector, matching the PixiJS frame drawn\n // underneath. The border is owned by the Pixi frame (also what PNG/PDF\n // export captures), so we don't redraw it here.\n const fillCss = node.data.fill === 'transparent'\n ? 'transparent'\n : resolveThemeColorCss(node.data.fill, 'transparent');\n const textColor = resolveThemeColorCss(node.data.labelColor ?? node.data.color, '#111827');\n return (\n <div\n key={node.id}\n className=\"flow-media-node\"\n data-media-node={node.id}\n style={{\n position: 'absolute',\n left,\n top,\n width: node.width,\n height: node.height,\n // Scale the fixed-size content box to match zoom without\n // reflowing text on every zoom step.\n transform: `scale(${zoom})`,\n transformOrigin: 'top left',\n // Below the frame's selection outline but above the canvas.\n pointerEvents: 'none',\n }}\n >\n <div\n className=\"flow-media-surface\"\n onWheel={(e) => e.stopPropagation()}\n style={{\n background: fillCss,\n color: textColor,\n }}\n >\n <Suspense fallback={<div className=\"flow-media-loading\">…</div>}>\n <MediaErrorBoundary>\n <MediaContent node={node} interactive={interactive} />\n </MediaErrorBoundary>\n </Suspense>\n </div>\n </div>\n );\n })}\n </div>\n );\n}\n"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"MediaOverlay.js","names":[],"sources":["../../../../../src/components/pro/Flow/nodes/MediaOverlay.tsx"],"sourcesContent":["import React, { useMemo, Suspense } from 'react';\nimport { useFlowContext } from '../context/FlowContext';\nimport { useFlowUI } from '../context/FlowUIContext';\nimport { resolveThemeColorCss } from '../utils/themeColor';\n\n// Lazy-load the media renderers so the heavy optional deps they pull in\n// (react-markdown, mermaid, katex, markmap, …) are only fetched when a media\n// node actually needs to render. This keeps the base `dishui/flow` bundle\n// lightweight and avoids loading that stack for diagrams without media nodes.\n// Viewport-only updates move the outer box, not the live media subtree. Keep\n// nodes mounted offscreen so iframe/AI state and model camera state survive.\nconst MediaContent = React.memo(React.lazy(() =>\n import('./MediaContent').then((m) => ({ default: m.MediaContent })),\n));\n\n/** Isolates media render/load failures so one bad node never blanks the editor. */\nclass MediaErrorBoundary extends React.Component<\n { children: React.ReactNode },\n { error: Error | null }\n> {\n constructor(props: { children: React.ReactNode }) {\n super(props);\n this.state = { error: null };\n }\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n render() {\n if (this.state.error) {\n return <div className=\"flow-media-error\">{this.state.error.message}</div>;\n }\n return this.props.children;\n }\n}\n\n/**\n * DOM overlay for media nodes. PixiJS draws the frame; this layer renders the\n * live content (markdown/html/mermaid/math/AI) on top, synced to the viewport\n * so it pans and zooms with the canvas.\n *\n * Event model: a media surface is `pointer-events: none` by default so the\n * canvas underneath can be clicked to select/drag the node's frame. The\n * surface only becomes interactive while its node is selected (so AI chat can\n * be typed into, HTML can be scrolled). This also stops an always-interactive\n * iframe/AI box from swallowing pointer gestures and leaving the drag stuck.\n */\nexport function MediaOverlay() {\n const { currentCanvas, selection } = useFlowContext();\n const { viewport, isNodeDragging } = useFlowUI();\n\n const mediaNodes = useMemo(\n () => currentCanvas.nodes.filter((n) => n.type === 'mediaNode'),\n [currentCanvas.nodes],\n );\n\n if (mediaNodes.length === 0) return null;\n\n const { x: vx, y: vy, zoom } = viewport;\n\n return (\n <div className=\"flow-media-layer\">\n {mediaNodes.map((node) => {\n // World → screen (CSS px, matching ViewportManager.worldToScreen).\n const left = node.position.x * zoom + vx;\n const top = node.position.y * zoom + vy;\n // Interactive only while selected, so the canvas stays draggable.\n // Suppress entirely during a drag: an interactive iframe would swallow\n // the pointer and the canvas would never receive pointerup (stuck drag).\n const interactive = selection.nodeIds.has(node.id) && !isNodeDragging;\n // Drive the overlay's background / text from the node's own color data.\n // Theme tokens (`theme:*`) resolve to CSS variables so the media content\n // follows theme switches natively; literal colors are used as-is. This\n // keeps html / ai / data (which render opaque content) in sync with the\n // fill/color chosen in the inspector, matching the PixiJS frame drawn\n // underneath. The border is owned by the Pixi frame (also what PNG/PDF\n // export captures), so we don't redraw it here.\n const fillCss = node.data.fill === 'transparent'\n ? 'transparent'\n : resolveThemeColorCss(node.data.fill, 'transparent');\n const textColor = resolveThemeColorCss(node.data.labelColor ?? node.data.color, '#111827');\n return (\n <div\n key={node.id}\n className=\"flow-media-node\"\n data-media-node={node.id}\n style={{\n position: 'absolute',\n left,\n top,\n width: node.width,\n height: node.height,\n // Scale the fixed-size content box to match zoom without\n // reflowing text on every zoom step.\n transform: `scale(${zoom})`,\n transformOrigin: 'top left',\n // Below the frame's selection outline but above the canvas.\n pointerEvents: 'none',\n }}\n >\n <div\n className=\"flow-media-surface\"\n onWheel={(e) => e.stopPropagation()}\n style={{\n background: fillCss,\n color: textColor,\n }}\n >\n <Suspense fallback={<div className=\"flow-media-loading\">…</div>}>\n <MediaErrorBoundary>\n <MediaContent node={node} interactive={interactive} />\n </MediaErrorBoundary>\n </Suspense>\n </div>\n </div>\n );\n })}\n </div>\n );\n}\n"],"mappings":";;;;;;AAWA,IAAM,IAAe,EAAM,KAAK,EAAM,WACpC,OAAO,oBAAiB,CAAC,MAAM,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,CACpE,CAAC,GAGK,IAAN,cAAiC,EAAM,UAGrC;CACA,YAAY,GAAsC;EAEhD,AADA,MAAM,CAAK,GACX,KAAK,QAAQ,EAAE,OAAO,KAAK;CAC7B;CACA,OAAO,yBAAyB,GAAc;EAC5C,OAAO,EAAE,SAAM;CACjB;CACA,SAAS;EAIP,OAHI,KAAK,MAAM,QACN,kBAAC,OAAD;GAAK,WAAU;GAAoB,UAAA,KAAK,MAAM,MAAM;EAAa,CAAA,IAEnE,KAAK,MAAM;CACpB;AACF;AAaA,SAAgB,IAAe;CAC7B,IAAM,EAAE,kBAAe,iBAAc,EAAe,GAC9C,EAAE,aAAU,sBAAmB,EAAU,GAEzC,IAAa,QACX,EAAc,MAAM,QAAQ,MAAM,EAAE,SAAS,WAAW,GAC9D,CAAC,EAAc,KAAK,CACtB;CAEA,IAAI,EAAW,WAAW,GAAG,OAAO;CAEpC,IAAM,EAAE,GAAG,GAAI,GAAG,GAAI,YAAS;CAE/B,OACE,kBAAC,OAAD;EAAK,WAAU;EACZ,UAAA,EAAW,KAAK,MAAS;GAExB,IAAM,IAAO,EAAK,SAAS,IAAI,IAAO,GAChC,IAAM,EAAK,SAAS,IAAI,IAAO,GAI/B,IAAc,EAAU,QAAQ,IAAI,EAAK,EAAE,KAAK,CAAC,GAQjD,IAAU,EAAK,KAAK,SAAS,gBAC/B,gBACA,EAAqB,EAAK,KAAK,MAAM,aAAa,GAChD,IAAY,EAAqB,EAAK,KAAK,cAAc,EAAK,KAAK,OAAO,SAAS;GACzF,OACE,kBAAC,OAAD;IAEE,WAAU;IACV,mBAAiB,EAAK;IACtB,OAAO;KACL,UAAU;KACV;KACA;KACA,OAAO,EAAK;KACZ,QAAQ,EAAK;KAGb,WAAW,SAAS,EAAK;KACzB,iBAAiB;KAEjB,eAAe;IACjB;IAEA,UAAA,kBAAC,OAAD;KACE,WAAU;KACV,UAAU,MAAM,EAAE,gBAAgB;KAClC,OAAO;MACL,YAAY;MACZ,OAAO;KACT;KAEA,UAAA,kBAAC,GAAD;MAAU,UAAU,kBAAC,OAAD;OAAK,WAAU;OAAqB,UAAA;MAAM,CAAA;MAC5D,UAAA,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD;OAAoB;OAAmB;MAAc,CAAA,EACnC,CAAA;KACZ,CAAA;IACP,CAAA;GACF,GA/BE,EAAK,EA+BP;EAET,CAAC;CACE,CAAA;AAET"}
|
|
@@ -1,116 +1,122 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { createDemandRender as e } from "./demandRender.js";
|
|
2
|
+
import { useEffect as t, useRef as n, useState as r } from "react";
|
|
3
|
+
import { jsx as i, jsxs as a } from "react/jsx-runtime";
|
|
4
|
+
import * as o from "three";
|
|
5
|
+
import { OrbitControls as s } from "three/addons/controls/OrbitControls.js";
|
|
6
|
+
import { ThreeMFLoader as c } from "three/addons/loaders/3MFLoader.js";
|
|
7
|
+
import { OBJLoader as l } from "three/addons/loaders/OBJLoader.js";
|
|
8
|
+
import { STLLoader as u } from "three/addons/loaders/STLLoader.js";
|
|
8
9
|
//#region src/components/pro/Flow/nodes/Model3DView.tsx
|
|
9
|
-
function
|
|
10
|
+
function d(e) {
|
|
10
11
|
let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
|
|
11
12
|
e.traverse((e) => {
|
|
12
|
-
if (!(e instanceof
|
|
13
|
+
if (!(e instanceof o.Mesh)) return;
|
|
13
14
|
e.geometry?.dispose();
|
|
14
15
|
let r = Array.isArray(e.material) ? e.material : [e.material];
|
|
15
16
|
for (let e of r) if (e && !t.has(e)) {
|
|
16
17
|
t.add(e);
|
|
17
|
-
for (let t of Object.values(e)) t instanceof
|
|
18
|
+
for (let t of Object.values(e)) t instanceof o.Texture && n.add(t);
|
|
18
19
|
}
|
|
19
20
|
});
|
|
20
21
|
for (let e of n) e.dispose();
|
|
21
22
|
for (let e of t) e.dispose();
|
|
22
23
|
}
|
|
23
|
-
function
|
|
24
|
+
function f(e, t) {
|
|
24
25
|
if (e === "stl") {
|
|
25
|
-
let e = new
|
|
26
|
-
return e.getAttribute("normal") || e.computeVertexNormals(), new
|
|
26
|
+
let e = new u().parse(t);
|
|
27
|
+
return e.getAttribute("normal") || e.computeVertexNormals(), new o.Mesh(e, new o.MeshStandardMaterial({
|
|
27
28
|
color: 12108492,
|
|
28
29
|
metalness: .05,
|
|
29
30
|
roughness: .72,
|
|
30
|
-
side:
|
|
31
|
+
side: o.DoubleSide
|
|
31
32
|
}));
|
|
32
33
|
}
|
|
33
|
-
return e === "obj" ? new
|
|
34
|
+
return e === "obj" ? new l().parse(new TextDecoder().decode(t)) : new c().parse(t);
|
|
34
35
|
}
|
|
35
|
-
function
|
|
36
|
-
let
|
|
37
|
-
return
|
|
38
|
-
|
|
39
|
-
}, [
|
|
40
|
-
let
|
|
41
|
-
if (!
|
|
42
|
-
let
|
|
36
|
+
function p({ content: c, format: l, interactive: u }) {
|
|
37
|
+
let p = n(null), m = n(null), h = n(u), [g, _] = r(null), [v, y] = r(!1);
|
|
38
|
+
return t(() => {
|
|
39
|
+
h.current = u, m.current && (m.current.enabled = u);
|
|
40
|
+
}, [u]), t(() => {
|
|
41
|
+
let t = p.current, n = c.trim();
|
|
42
|
+
if (!t || !n) return;
|
|
43
|
+
let r = !1, i = null, a = new AbortController(), u = new o.Scene(), g = new o.PerspectiveCamera(45, 1, .01, 1e4), v = new o.WebGLRenderer({
|
|
43
44
|
antialias: !0,
|
|
44
45
|
alpha: !0
|
|
45
46
|
});
|
|
46
|
-
|
|
47
|
-
let b = new
|
|
48
|
-
b.position.set(3, 5, 4),
|
|
49
|
-
let x = new
|
|
50
|
-
x.enableDamping = !0, x.enabled =
|
|
51
|
-
let S = (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
S
|
|
56
|
-
let C =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
v.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2)), v.outputColorSpace = o.SRGBColorSpace, v.setClearColor(0, 0), t.appendChild(v.domElement), u.add(new o.HemisphereLight(16777215, 4477030, 2));
|
|
48
|
+
let b = new o.DirectionalLight(16777215, 2.4);
|
|
49
|
+
b.position.set(3, 5, 4), u.add(b);
|
|
50
|
+
let x = new s(g, v.domElement);
|
|
51
|
+
x.enableDamping = !0, x.enabled = h.current, m.current = x;
|
|
52
|
+
let S = e({
|
|
53
|
+
update: () => x.update(),
|
|
54
|
+
render: () => v.render(u, g)
|
|
55
|
+
});
|
|
56
|
+
x.addEventListener("change", S.invalidate);
|
|
57
|
+
let C = typeof IntersectionObserver > "u", w = () => S.setActive(C && !document.hidden), T = typeof IntersectionObserver > "u" ? null : new IntersectionObserver((e) => {
|
|
58
|
+
C = e.some((e) => e.isIntersecting && e.intersectionRect.width > 0 && e.intersectionRect.height > 0), w();
|
|
59
|
+
});
|
|
60
|
+
T?.observe(t), document.addEventListener("visibilitychange", w), w();
|
|
61
|
+
let E = () => {
|
|
62
|
+
let e = Math.max(1, t.clientWidth), n = Math.max(1, t.clientHeight);
|
|
63
|
+
v.setSize(e, n, !1), g.aspect = e / n, g.updateProjectionMatrix(), S.invalidate();
|
|
60
64
|
};
|
|
61
|
-
|
|
65
|
+
E();
|
|
66
|
+
let D = new ResizeObserver(E);
|
|
67
|
+
return D.observe(t), y(!0), _(null), fetch(n, { signal: a.signal }).then((e) => {
|
|
62
68
|
if (!e.ok) throw Error(`模型加载失败:HTTP ${e.status}`);
|
|
63
69
|
return e.arrayBuffer();
|
|
64
70
|
}).then((e) => {
|
|
65
71
|
if (e.byteLength > 52428800) throw Error("模型超过 50 MiB,无法加载");
|
|
66
|
-
let t =
|
|
67
|
-
if (
|
|
68
|
-
|
|
72
|
+
let t = f(l, e);
|
|
73
|
+
if (r) {
|
|
74
|
+
d(t);
|
|
69
75
|
return;
|
|
70
76
|
}
|
|
71
77
|
i = t, t.updateMatrixWorld(!0);
|
|
72
|
-
let
|
|
73
|
-
if (
|
|
74
|
-
let
|
|
75
|
-
t.position.sub(
|
|
76
|
-
let s = new
|
|
78
|
+
let n = new o.Box3().setFromObject(t);
|
|
79
|
+
if (n.isEmpty()) throw Error("模型不包含可显示的几何体");
|
|
80
|
+
let a = n.getCenter(new o.Vector3());
|
|
81
|
+
t.position.sub(a), t.updateMatrixWorld(!0);
|
|
82
|
+
let s = new o.Box3().setFromObject(t).getBoundingSphere(new o.Sphere());
|
|
77
83
|
if (!Number.isFinite(s.radius) || s.radius <= 0) throw Error("模型尺寸无效");
|
|
78
|
-
|
|
79
|
-
let
|
|
80
|
-
|
|
84
|
+
u.add(t);
|
|
85
|
+
let c = o.MathUtils.degToRad(g.fov / 2), p = Math.atan(Math.tan(c) * g.aspect), m = s.radius / Math.sin(Math.min(p, c)) * 1.15;
|
|
86
|
+
g.position.copy(new o.Vector3(1, .75, 1).normalize().multiplyScalar(m)), g.near = Math.max(s.radius / 1e3, .001), g.far = Math.max(m + s.radius * 10, s.radius * 1e3), g.updateProjectionMatrix(), x.target.set(0, 0, 0), x.minDistance = s.radius * .05, x.maxDistance = s.radius * 100, S.invalidate();
|
|
81
87
|
}).catch((e) => {
|
|
82
|
-
!
|
|
88
|
+
!r && e?.name !== "AbortError" && _(e?.message ?? "模型加载失败");
|
|
83
89
|
}).finally(() => {
|
|
84
|
-
|
|
90
|
+
r || y(!1);
|
|
85
91
|
}), () => {
|
|
86
|
-
|
|
92
|
+
r = !0, a.abort(), S.dispose(), D.disconnect(), T?.disconnect(), document.removeEventListener("visibilitychange", w), x.removeEventListener("change", S.invalidate), x.dispose(), m.current = null, i && d(i), u.clear(), v.renderLists.dispose(), v.dispose(), v.forceContextLoss(), v.domElement.remove();
|
|
87
93
|
};
|
|
88
|
-
}, [
|
|
89
|
-
ref:
|
|
94
|
+
}, [c, l]), c.trim() ? /* @__PURE__ */ a("div", {
|
|
95
|
+
ref: p,
|
|
90
96
|
className: "flow-media-model3d",
|
|
91
97
|
style: {
|
|
92
|
-
pointerEvents:
|
|
93
|
-
touchAction:
|
|
98
|
+
pointerEvents: u ? "auto" : "none",
|
|
99
|
+
touchAction: u ? "none" : "auto"
|
|
94
100
|
},
|
|
95
101
|
onPointerDown: (e) => {
|
|
96
|
-
|
|
102
|
+
u && e.stopPropagation();
|
|
97
103
|
},
|
|
98
104
|
onWheel: (e) => {
|
|
99
|
-
|
|
105
|
+
u && e.stopPropagation();
|
|
100
106
|
},
|
|
101
|
-
children: [
|
|
107
|
+
children: [v && /* @__PURE__ */ i("div", {
|
|
102
108
|
className: "flow-media-loading flow-media-model3d-status",
|
|
103
109
|
children: "加载模型…"
|
|
104
|
-
}),
|
|
110
|
+
}), g && /* @__PURE__ */ i("div", {
|
|
105
111
|
className: "flow-media-error flow-media-model3d-status",
|
|
106
|
-
children:
|
|
112
|
+
children: g
|
|
107
113
|
})]
|
|
108
|
-
}) : /* @__PURE__ */
|
|
114
|
+
}) : /* @__PURE__ */ i("div", {
|
|
109
115
|
className: "flow-media-image-empty",
|
|
110
116
|
children: "输入 STL、OBJ 或 3MF 模型链接"
|
|
111
117
|
});
|
|
112
118
|
}
|
|
113
119
|
//#endregion
|
|
114
|
-
export {
|
|
120
|
+
export { p as Model3DView };
|
|
115
121
|
|
|
116
122
|
//# sourceMappingURL=Model3DView.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Model3DView.js","names":[],"sources":["../../../../../src/components/pro/Flow/nodes/Model3DView.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport * as THREE from 'three';\nimport { OrbitControls } from 'three/addons/controls/OrbitControls.js';\nimport { ThreeMFLoader } from 'three/addons/loaders/3MFLoader.js';\nimport { OBJLoader } from 'three/addons/loaders/OBJLoader.js';\nimport { STLLoader } from 'three/addons/loaders/STLLoader.js';\nimport type { FlowModelFormat } from '../types';\n\nfunction disposeObject(root: any) {\n const materials = new Set<any>();\n const textures = new Set<any>();\n root.traverse((object: any) => {\n if (!(object instanceof THREE.Mesh)) return;\n object.geometry?.dispose();\n const list = Array.isArray(object.material) ? object.material : [object.material];\n for (const material of list) {\n if (!material || materials.has(material)) continue;\n materials.add(material);\n for (const value of Object.values(material)) {\n if (value instanceof THREE.Texture) textures.add(value);\n }\n }\n });\n for (const texture of textures) texture.dispose();\n for (const material of materials) material.dispose();\n}\n\nfunction parseModel(format: FlowModelFormat, data: ArrayBuffer): any {\n if (format === 'stl') {\n const geometry = new STLLoader().parse(data);\n if (!geometry.getAttribute('normal')) geometry.computeVertexNormals();\n return new THREE.Mesh(\n geometry,\n new THREE.MeshStandardMaterial({\n color: 0xb8c2cc,\n metalness: 0.05,\n roughness: 0.72,\n side: THREE.DoubleSide,\n }),\n );\n }\n if (format === 'obj') {\n return new OBJLoader().parse(new TextDecoder().decode(data));\n }\n return new ThreeMFLoader().parse(data);\n}\n\nexport function Model3DView({\n content,\n format,\n interactive,\n}: {\n content: string;\n format: FlowModelFormat;\n interactive: boolean;\n}) {\n const hostRef = useRef<HTMLDivElement>(null);\n const controlsRef = useRef<any>(null);\n const [error, setError] = useState<string | null>(null);\n const [loading, setLoading] = useState(false);\n\n useEffect(() => {\n if (controlsRef.current) controlsRef.current.enabled = interactive;\n }, [interactive]);\n\n useEffect(() => {\n const host = hostRef.current;\n const source = content.trim();\n if (!host || !source) return;\n\n let cancelled = false;\n let frame = 0;\n let model: any = null;\n const abort = new AbortController();\n const scene = new THREE.Scene();\n const camera = new THREE.PerspectiveCamera(45, 1, 0.01, 10000);\n const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });\n renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));\n renderer.outputColorSpace = THREE.SRGBColorSpace;\n renderer.setClearColor(0x000000, 0);\n host.appendChild(renderer.domElement);\n\n scene.add(new THREE.HemisphereLight(0xffffff, 0x445066, 2));\n const directional = new THREE.DirectionalLight(0xffffff, 2.4);\n directional.position.set(3, 5, 4);\n scene.add(directional);\n\n const controls = new OrbitControls(camera, renderer.domElement);\n controls.enableDamping = true;\n controls.enabled = interactive;\n controlsRef.current = controls;\n\n const resize = () => {\n const width = Math.max(1, host.clientWidth);\n const height = Math.max(1, host.clientHeight);\n renderer.setSize(width, height, false);\n camera.aspect = width / height;\n camera.updateProjectionMatrix();\n };\n resize();\n const observer = new ResizeObserver(resize);\n observer.observe(host);\n\n const animate = () => {\n controls.update();\n renderer.render(scene, camera);\n frame = requestAnimationFrame(animate);\n };\n animate();\n\n setLoading(true);\n setError(null);\n fetch(source, { signal: abort.signal })\n .then(response => {\n if (!response.ok) throw new Error(`模型加载失败:HTTP ${response.status}`);\n return response.arrayBuffer();\n })\n .then(data => {\n if (data.byteLength > 50 * 1024 * 1024) throw new Error('模型超过 50 MiB,无法加载');\n const root = parseModel(format, data);\n if (cancelled) {\n disposeObject(root);\n return;\n }\n model = root;\n root.updateMatrixWorld(true);\n const box = new THREE.Box3().setFromObject(root);\n if (box.isEmpty()) throw new Error('模型不包含可显示的几何体');\n const center = box.getCenter(new THREE.Vector3());\n root.position.sub(center);\n root.updateMatrixWorld(true);\n const sphere = new THREE.Box3().setFromObject(root).getBoundingSphere(new THREE.Sphere());\n if (!Number.isFinite(sphere.radius) || sphere.radius <= 0) throw new Error('模型尺寸无效');\n scene.add(root);\n\n const halfFovY = THREE.MathUtils.degToRad(camera.fov / 2);\n const halfFovX = Math.atan(Math.tan(halfFovY) * camera.aspect);\n const distance = (sphere.radius / Math.sin(Math.min(halfFovX, halfFovY))) * 1.15;\n camera.position.copy(new THREE.Vector3(1, 0.75, 1).normalize().multiplyScalar(distance));\n camera.near = Math.max(sphere.radius / 1000, 0.001);\n camera.far = Math.max(distance + sphere.radius * 10, sphere.radius * 1000);\n camera.updateProjectionMatrix();\n controls.target.set(0, 0, 0);\n controls.minDistance = sphere.radius * 0.05;\n controls.maxDistance = sphere.radius * 100;\n controls.update();\n })\n .catch(nextError => {\n if (!cancelled && nextError?.name !== 'AbortError') setError(nextError?.message ?? '模型加载失败');\n })\n .finally(() => {\n if (!cancelled) setLoading(false);\n });\n\n return () => {\n cancelled = true;\n abort.abort();\n cancelAnimationFrame(frame);\n observer.disconnect();\n controls.dispose();\n controlsRef.current = null;\n if (model) disposeObject(model);\n scene.clear();\n renderer.renderLists.dispose();\n renderer.dispose();\n renderer.forceContextLoss();\n renderer.domElement.remove();\n };\n }, [content, format]);\n\n if (!content.trim()) {\n return <div className=\"flow-media-image-empty\">输入 STL、OBJ 或 3MF 模型链接</div>;\n }\n\n return (\n <div\n ref={hostRef}\n className=\"flow-media-model3d\"\n style={{ pointerEvents: interactive ? 'auto' : 'none', touchAction: interactive ? 'none' : 'auto' }}\n onPointerDown={event => { if (interactive) event.stopPropagation(); }}\n onWheel={event => { if (interactive) event.stopPropagation(); }}\n >\n {loading && <div className=\"flow-media-loading flow-media-model3d-status\">加载模型…</div>}\n {error && <div className=\"flow-media-error flow-media-model3d-status\">{error}</div>}\n </div>\n );\n}\n"],"mappings":";;;;;;;;AAQA,SAAS,EAAc,GAAW;CAChC,IAAM,oBAAY,IAAI,IAAS,GACzB,oBAAW,IAAI,IAAS;CAC9B,EAAK,UAAU,MAAgB;EAC7B,IAAI,EAAE,aAAkB,EAAM,OAAO;EACrC,EAAO,UAAU,QAAQ;EACzB,IAAM,IAAO,MAAM,QAAQ,EAAO,QAAQ,IAAI,EAAO,WAAW,CAAC,EAAO,QAAQ;EAChF,KAAK,IAAM,KAAY,GACjB,IAAC,KAAY,GAAU,IAAI,CAAQ,GACvC;KAAU,IAAI,CAAQ;GACtB,KAAK,IAAM,KAAS,OAAO,OAAO,CAAQ,GACxC,AAAI,aAAiB,EAAM,WAAS,EAAS,IAAI,CAAK;EAFlC;CAK1B,CAAC;CACD,KAAK,IAAM,KAAW,GAAU,EAAQ,QAAQ;CAChD,KAAK,IAAM,KAAY,GAAW,EAAS,QAAQ;AACrD;AAEA,SAAS,EAAW,GAAyB,GAAwB;CACnE,IAAI,MAAW,OAAO;EACpB,IAAM,IAAW,IAAI,EAAU,CAAC,CAAC,MAAM,CAAI;EAE3C,OADK,EAAS,aAAa,QAAQ,KAAG,EAAS,qBAAqB,GAC7D,IAAI,EAAM,KACf,GACA,IAAI,EAAM,qBAAqB;GAC7B,OAAO;GACP,WAAW;GACX,WAAW;GACX,MAAM,EAAM;EACd,CAAC,CACH;CACF;CAIA,OAHI,MAAW,QACN,IAAI,EAAU,CAAC,CAAC,MAAM,IAAI,YAAY,CAAC,CAAC,OAAO,CAAI,CAAC,IAEtD,IAAI,EAAc,CAAC,CAAC,MAAM,CAAI;AACvC;AAEA,SAAgB,EAAY,EAC1B,YACA,WACA,kBAKC;CACD,IAAM,IAAU,EAAuB,IAA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AD;EAAK,WAAU;EAAyB,UAAA;CAA0B,CAAA;AAe7E"}
|
|
1
|
+
{"version":3,"file":"Model3DView.js","names":[],"sources":["../../../../../src/components/pro/Flow/nodes/Model3DView.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport * as THREE from 'three';\nimport { OrbitControls } from 'three/addons/controls/OrbitControls.js';\nimport { ThreeMFLoader } from 'three/addons/loaders/3MFLoader.js';\nimport { OBJLoader } from 'three/addons/loaders/OBJLoader.js';\nimport { STLLoader } from 'three/addons/loaders/STLLoader.js';\nimport type { FlowModelFormat } from '../types';\nimport { createDemandRender } from './demandRender';\n\nfunction disposeObject(root: any) {\n const materials = new Set<any>();\n const textures = new Set<any>();\n root.traverse((object: any) => {\n if (!(object instanceof THREE.Mesh)) return;\n object.geometry?.dispose();\n const list = Array.isArray(object.material) ? object.material : [object.material];\n for (const material of list) {\n if (!material || materials.has(material)) continue;\n materials.add(material);\n for (const value of Object.values(material)) {\n if (value instanceof THREE.Texture) textures.add(value);\n }\n }\n });\n for (const texture of textures) texture.dispose();\n for (const material of materials) material.dispose();\n}\n\nfunction parseModel(format: FlowModelFormat, data: ArrayBuffer): any {\n if (format === 'stl') {\n const geometry = new STLLoader().parse(data);\n if (!geometry.getAttribute('normal')) geometry.computeVertexNormals();\n return new THREE.Mesh(\n geometry,\n new THREE.MeshStandardMaterial({\n color: 0xb8c2cc,\n metalness: 0.05,\n roughness: 0.72,\n side: THREE.DoubleSide,\n }),\n );\n }\n if (format === 'obj') {\n return new OBJLoader().parse(new TextDecoder().decode(data));\n }\n return new ThreeMFLoader().parse(data);\n}\n\nexport function Model3DView({\n content,\n format,\n interactive,\n}: {\n content: string;\n format: FlowModelFormat;\n interactive: boolean;\n}) {\n const hostRef = useRef<HTMLDivElement>(null);\n const controlsRef = useRef<OrbitControls | null>(null);\n const interactiveRef = useRef(interactive);\n const [error, setError] = useState<string | null>(null);\n const [loading, setLoading] = useState(false);\n\n useEffect(() => {\n interactiveRef.current = interactive;\n if (controlsRef.current) controlsRef.current.enabled = interactive;\n }, [interactive]);\n\n useEffect(() => {\n const host = hostRef.current;\n const source = content.trim();\n if (!host || !source) return;\n\n let cancelled = false;\n let model: any = null;\n const abort = new AbortController();\n const scene = new THREE.Scene();\n const camera = new THREE.PerspectiveCamera(45, 1, 0.01, 10000);\n const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });\n renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));\n renderer.outputColorSpace = THREE.SRGBColorSpace;\n renderer.setClearColor(0x000000, 0);\n host.appendChild(renderer.domElement);\n\n scene.add(new THREE.HemisphereLight(0xffffff, 0x445066, 2));\n const directional = new THREE.DirectionalLight(0xffffff, 2.4);\n directional.position.set(3, 5, 4);\n scene.add(directional);\n\n const controls = new OrbitControls(camera, renderer.domElement);\n controls.enableDamping = true;\n controls.enabled = interactiveRef.current;\n controlsRef.current = controls;\n\n const drawing = createDemandRender({\n update: () => controls.update(),\n render: () => renderer.render(scene, camera),\n });\n controls.addEventListener('change', drawing.invalidate);\n // Observe the actual DOM box, including overlay transforms and clipping.\n // Pausing keeps the loaded model, camera and WebGL context intact.\n let intersecting = typeof IntersectionObserver === 'undefined';\n const updateVisibility = () => drawing.setActive(intersecting && !document.hidden);\n const visibilityObserver = typeof IntersectionObserver === 'undefined' ? null : new IntersectionObserver(entries => {\n intersecting = entries.some(entry => entry.isIntersecting && entry.intersectionRect.width > 0 && entry.intersectionRect.height > 0);\n updateVisibility();\n });\n visibilityObserver?.observe(host);\n document.addEventListener('visibilitychange', updateVisibility);\n updateVisibility();\n\n const resize = () => {\n const width = Math.max(1, host.clientWidth);\n const height = Math.max(1, host.clientHeight);\n renderer.setSize(width, height, false);\n camera.aspect = width / height;\n camera.updateProjectionMatrix();\n drawing.invalidate();\n };\n resize();\n const observer = new ResizeObserver(resize);\n observer.observe(host);\n\n setLoading(true);\n setError(null);\n fetch(source, { signal: abort.signal })\n .then(response => {\n if (!response.ok) throw new Error(`模型加载失败:HTTP ${response.status}`);\n return response.arrayBuffer();\n })\n .then(data => {\n if (data.byteLength > 50 * 1024 * 1024) throw new Error('模型超过 50 MiB,无法加载');\n const root = parseModel(format, data);\n if (cancelled) {\n disposeObject(root);\n return;\n }\n model = root;\n root.updateMatrixWorld(true);\n const box = new THREE.Box3().setFromObject(root);\n if (box.isEmpty()) throw new Error('模型不包含可显示的几何体');\n const center = box.getCenter(new THREE.Vector3());\n root.position.sub(center);\n root.updateMatrixWorld(true);\n const sphere = new THREE.Box3().setFromObject(root).getBoundingSphere(new THREE.Sphere());\n if (!Number.isFinite(sphere.radius) || sphere.radius <= 0) throw new Error('模型尺寸无效');\n scene.add(root);\n\n const halfFovY = THREE.MathUtils.degToRad(camera.fov / 2);\n const halfFovX = Math.atan(Math.tan(halfFovY) * camera.aspect);\n const distance = (sphere.radius / Math.sin(Math.min(halfFovX, halfFovY))) * 1.15;\n camera.position.copy(new THREE.Vector3(1, 0.75, 1).normalize().multiplyScalar(distance));\n camera.near = Math.max(sphere.radius / 1000, 0.001);\n camera.far = Math.max(distance + sphere.radius * 10, sphere.radius * 1000);\n camera.updateProjectionMatrix();\n controls.target.set(0, 0, 0);\n controls.minDistance = sphere.radius * 0.05;\n controls.maxDistance = sphere.radius * 100;\n drawing.invalidate();\n })\n .catch(nextError => {\n if (!cancelled && nextError?.name !== 'AbortError') setError(nextError?.message ?? '模型加载失败');\n })\n .finally(() => {\n if (!cancelled) setLoading(false);\n });\n\n return () => {\n cancelled = true;\n abort.abort();\n drawing.dispose();\n observer.disconnect();\n visibilityObserver?.disconnect();\n document.removeEventListener('visibilitychange', updateVisibility);\n controls.removeEventListener('change', drawing.invalidate);\n controls.dispose();\n controlsRef.current = null;\n if (model) disposeObject(model);\n scene.clear();\n renderer.renderLists.dispose();\n renderer.dispose();\n renderer.forceContextLoss();\n renderer.domElement.remove();\n };\n }, [content, format]);\n\n if (!content.trim()) {\n return <div className=\"flow-media-image-empty\">输入 STL、OBJ 或 3MF 模型链接</div>;\n }\n\n return (\n <div\n ref={hostRef}\n className=\"flow-media-model3d\"\n style={{ pointerEvents: interactive ? 'auto' : 'none', touchAction: interactive ? 'none' : 'auto' }}\n onPointerDown={event => { if (interactive) event.stopPropagation(); }}\n onWheel={event => { if (interactive) event.stopPropagation(); }}\n >\n {loading && <div className=\"flow-media-loading flow-media-model3d-status\">加载模型…</div>}\n {error && <div className=\"flow-media-error flow-media-model3d-status\">{error}</div>}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AASA,SAAS,EAAc,GAAW;CAChC,IAAM,oBAAY,IAAI,IAAS,GACzB,oBAAW,IAAI,IAAS;CAC9B,EAAK,UAAU,MAAgB;EAC7B,IAAI,EAAE,aAAkB,EAAM,OAAO;EACrC,EAAO,UAAU,QAAQ;EACzB,IAAM,IAAO,MAAM,QAAQ,EAAO,QAAQ,IAAI,EAAO,WAAW,CAAC,EAAO,QAAQ;EAChF,KAAK,IAAM,KAAY,GACjB,IAAC,KAAY,GAAU,IAAI,CAAQ,GACvC;KAAU,IAAI,CAAQ;GACtB,KAAK,IAAM,KAAS,OAAO,OAAO,CAAQ,GACxC,AAAI,aAAiB,EAAM,WAAS,EAAS,IAAI,CAAK;EAFlC;CAK1B,CAAC;CACD,KAAK,IAAM,KAAW,GAAU,EAAQ,QAAQ;CAChD,KAAK,IAAM,KAAY,GAAW,EAAS,QAAQ;AACrD;AAEA,SAAS,EAAW,GAAyB,GAAwB;CACnE,IAAI,MAAW,OAAO;EACpB,IAAM,IAAW,IAAI,EAAU,CAAC,CAAC,MAAM,CAAI;EAE3C,OADK,EAAS,aAAa,QAAQ,KAAG,EAAS,qBAAqB,GAC7D,IAAI,EAAM,KACf,GACA,IAAI,EAAM,qBAAqB;GAC7B,OAAO;GACP,WAAW;GACX,WAAW;GACX,MAAM,EAAM;EACd,CAAC,CACH;CACF;CAIA,OAHI,MAAW,QACN,IAAI,EAAU,CAAC,CAAC,MAAM,IAAI,YAAY,CAAC,CAAC,OAAO,CAAI,CA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B,GACjE,EAAS,oBAAoB,UAAU,EAAQ,UAAU,GACzD,EAAS,QAAQ,GACjB,EAAY,UAAU,MAClB,KAAO,EAAc,CAAK,GAC9B,EAAM,MAAM,GACZ,EAAS,YAAY,QAAQ,GAC7B,EAAS,QAAQ,GACjB,EAAS,iBAAiB,GAC1B,EAAS,WAAW,OAAO;EAC7B;CACF,GAAG,CAAC,GAAS,CAAM,CAAC,GAEf,EAAQ,KAAK,IAKhB,kBAAC,OAAD;EACE,KAAK;EACL,WAAU;EACV,OAAO;GAAE,eAAe,IAAc,SAAS;GAAQ,aAAa,IAAc,SAAS;EAAO;EAClG,gBAAe,MAAS;GAAE,AAAI,KAAa,EAAM,gBAAgB;EAAG;EACpE,UAAS,MAAS;GAAE,AAAI,KAAa,EAAM,gBAAgB;EAAG;EALhE,UAAA,CAOG,KAAW,kBAAC,OAAD;GAAK,WAAU;GAA+C,UAAA;EAAU,CAAA,GACnF,KAAS,kBAAC,OAAD;GAAK,WAAU;GAA8C,UAAA;EAAW,CAAA,CAC/E;MAbE,kBAAC,OAAD;EAAK,WAAU;EAAyB,UAAA;CAA0B,CAAA;AAe7E"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ChartMark, SceneNode } from '@tanstack/charts';
|
|
2
|
+
type Position = readonly [number, number];
|
|
3
|
+
/** Keep sparse charts' dots, but not overlapping dots in dense/multi-series lines. */
|
|
4
|
+
export declare function showLinePoints(rowCount: number, seriesCount: number, width: number): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* First/min/max/last per two CSS plot pixels (at most ~2 vertices/pixel).
|
|
7
|
+
* Keep source order and extrema. Repeated/non-monotonic category positions are
|
|
8
|
+
* deliberately left alone: bucketing them can change backtracking geometry.
|
|
9
|
+
*/
|
|
10
|
+
export declare function budgetPolyline(points: readonly Position[]): readonly Position[];
|
|
11
|
+
export declare function budgetChartNode(node: SceneNode): SceneNode;
|
|
12
|
+
/** Budget only display geometry, after full-data domains and tooltip points exist. */
|
|
13
|
+
export declare function withChartGeometryBudget<T extends ChartMark<any, any, any, any, any, any, any>>(mark: T): T;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
//#region src/components/pro/Flow/nodes/chartGeometryBudget.ts
|
|
2
|
+
function e(e, t, n) {
|
|
3
|
+
return e * t <= Math.min(200, Math.floor(Math.max(0, n) / 6));
|
|
4
|
+
}
|
|
5
|
+
function t(e) {
|
|
6
|
+
if (e.length < 3) return e;
|
|
7
|
+
let t = -Infinity;
|
|
8
|
+
for (let [n, r] of e) {
|
|
9
|
+
if (!Number.isFinite(n) || !Number.isFinite(r) || n <= t) return e;
|
|
10
|
+
t = n;
|
|
11
|
+
}
|
|
12
|
+
let n = [];
|
|
13
|
+
for (let t = 0; t < e.length;) {
|
|
14
|
+
let r = Math.floor(e[t][0] / 2), i = t + 1, a = t, o = t;
|
|
15
|
+
for (; i < e.length && Math.floor(e[i][0] / 2) === r;) e[i][1] < e[a][1] && (a = i), e[i][1] > e[o][1] && (o = i), i++;
|
|
16
|
+
let s = [
|
|
17
|
+
t,
|
|
18
|
+
Math.min(a, o),
|
|
19
|
+
Math.max(a, o),
|
|
20
|
+
i - 1
|
|
21
|
+
];
|
|
22
|
+
for (let t = 0; t < s.length; t++) (t === 0 || s[t] !== s[t - 1]) && n.push(e[s[t]]);
|
|
23
|
+
t = i;
|
|
24
|
+
}
|
|
25
|
+
return n.length < e.length ? n : e;
|
|
26
|
+
}
|
|
27
|
+
function n(e) {
|
|
28
|
+
if (e.kind === "group") return {
|
|
29
|
+
...e,
|
|
30
|
+
children: e.children.map(n)
|
|
31
|
+
};
|
|
32
|
+
if (e.kind === "polyline" && !e.path) {
|
|
33
|
+
let n = t(e.points);
|
|
34
|
+
return n === e.points ? e : {
|
|
35
|
+
...e,
|
|
36
|
+
points: n
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (e.kind === "area" && !e.path && !e.polygons) {
|
|
40
|
+
let n = e.interaction?.points?.length;
|
|
41
|
+
if (n && e.points.length === n * 2) {
|
|
42
|
+
let r = e.points.slice(0, n), i = Array.from({ length: n }, (t, n) => e.points[e.points.length - 1 - n]), a = t(r), o = t(i);
|
|
43
|
+
if (a !== r || o !== i) {
|
|
44
|
+
let t = [...a];
|
|
45
|
+
for (let e = o.length - 1; e >= 0; e--) t.push(o[e]);
|
|
46
|
+
return {
|
|
47
|
+
...e,
|
|
48
|
+
points: t
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return e;
|
|
54
|
+
}
|
|
55
|
+
function r(e) {
|
|
56
|
+
return {
|
|
57
|
+
...e,
|
|
58
|
+
initialize(t) {
|
|
59
|
+
let r = e.initialize(t);
|
|
60
|
+
return {
|
|
61
|
+
...r,
|
|
62
|
+
render(e) {
|
|
63
|
+
let t = r.render(e);
|
|
64
|
+
return {
|
|
65
|
+
...t,
|
|
66
|
+
nodes: t.nodes.map(n)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { n as budgetChartNode, t as budgetPolyline, e as showLinePoints, r as withChartGeometryBudget };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=chartGeometryBudget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chartGeometryBudget.js","names":[],"sources":["../../../../../src/components/pro/Flow/nodes/chartGeometryBudget.ts"],"sourcesContent":["import type { ChartMark, SceneNode } from '@tanstack/charts';\n\ntype Position = readonly [number, number];\n\n/** Keep sparse charts' dots, but not overlapping dots in dense/multi-series lines. */\nexport function showLinePoints(rowCount: number, seriesCount: number, width: number) {\n return rowCount * seriesCount <= Math.min(200, Math.floor(Math.max(0, width) / 6));\n}\n\n/**\n * First/min/max/last per two CSS plot pixels (at most ~2 vertices/pixel).\n * Keep source order and extrema. Repeated/non-monotonic category positions are\n * deliberately left alone: bucketing them can change backtracking geometry.\n */\nexport function budgetPolyline(points: readonly Position[]): readonly Position[] {\n if (points.length < 3) return points;\n let previousX = -Infinity;\n for (const [x, y] of points) {\n if (!Number.isFinite(x) || !Number.isFinite(y) || x <= previousX) return points;\n previousX = x;\n }\n const result: Position[] = [];\n for (let start = 0; start < points.length;) {\n const bucket = Math.floor(points[start][0] / 2);\n let end = start + 1, min = start, max = start;\n while (end < points.length && Math.floor(points[end][0] / 2) === bucket) {\n if (points[end][1] < points[min][1]) min = end;\n if (points[end][1] > points[max][1]) max = end;\n end++;\n }\n const indices = [start, Math.min(min, max), Math.max(min, max), end - 1];\n for (let i = 0; i < indices.length; i++) {\n if (i === 0 || indices[i] !== indices[i - 1]) result.push(points[indices[i]]);\n }\n start = end;\n }\n return result.length < points.length ? result : points;\n}\n\nexport function budgetChartNode(node: SceneNode): SceneNode {\n if (node.kind === 'group') return { ...node, children: node.children.map(budgetChartNode) };\n // Never rewrite precomputed curves or arbitrary polygons. Interaction points\n // remain the full-resolution source data, separate from the painted vertices.\n if (node.kind === 'polyline' && !node.path) {\n const points = budgetPolyline(node.points);\n return points === node.points ? node : { ...node, points };\n }\n if (node.kind === 'area' && !node.path && !node.polygons) {\n const count = node.interaction?.points?.length;\n // areaY emits the upper edge then the reversed lower edge for each gap-\n // separated segment. Check this shape before applying the budget.\n if (count && node.points.length === count * 2) {\n const top = node.points.slice(0, count);\n const bottom = Array.from({ length: count }, (_, i) => node.points[node.points.length - 1 - i]);\n const upper = budgetPolyline(top), lower = budgetPolyline(bottom);\n if (upper !== top || lower !== bottom) {\n const points = [...upper];\n for (let i = lower.length - 1; i >= 0; i--) points.push(lower[i]);\n return { ...node, points };\n }\n }\n }\n return node;\n}\n\n/** Budget only display geometry, after full-data domains and tooltip points exist. */\nexport function withChartGeometryBudget<T extends ChartMark<any, any, any, any, any, any, any>>(mark: T): T {\n return {\n ...mark,\n initialize(context) {\n const initialized = mark.initialize(context);\n return {\n ...initialized,\n render(renderContext) {\n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E,GAAG;EAAM,UAAU,EAAK,SAAS,IAAI,CAAe;CAAE;CAG1F,IAAI,EAAK,SAAS,cAAc,CAAC,EAAK,MAAM;EAC1C,IAAM,IAAS,EAAe,EAAK,MAAM;EACzC,OAAO,MAAW,EAAK,SAAS,IAAO;GAAE,GAAG;GAAM;EAAO;CAC3D;CACA,IAAI,EAAK,SAAS,UAAU,CAAC,EAAK,QAAQ,CAAC,EAAK,UAAU;EACxD,IAAM,IAAQ,EAAK,aAAa,QAAQ;EAGxC,IAAI,KAAS,EAAK,OAAO,WAAW,IAAQ,GAAG;GAC7C,IAAM,IAAM,EAAK,OAAO,MAAM,GAAG,CAAK,GAChC,IAAS,MAAM,KAAK,EAAE,QAAQ,EAAM,IAAI,GAAG,MAAM,EAAK,OAAO,EAAK,OAAO,SAAS,IAAI,EAAE,GACxF,IAAQ,EAAe,CAAG,GAAG,IAAQ,EAAe,CAAM;GAChE,IAAI,MAAU,KAAO,MAAU,GAAQ;IACrC,IAAM,IAAS,CAAC,GAAG,CAAK;IACxB,KAAK,IAAI,IAAI,EAAM,SAAS,GAAG,KAAK,GAAG,KAAK,EAAO,KAAK,EAAM,EAAE;IAChE,OAAO;KAAE,GAAG;KAAM;IAAO;GAC3B;EACF;CACF;CACA,OAAO;AACT;AAGA,SAAgB,EAAgF,GAAY;CAC1G,OAAO;EACL,GAAG;EACH,WAAW,GAAS;GAClB,IAAM,IAAc,EAAK,WAAW,CAAO;GAC3C,OAAO;IACL,GAAG;IACH,OAAO,GAAe;KACpB,IAAM,IAAQ,EAAY,OAAO,CAAa;KAC9C,OAAO;MAAE,GAAG;MAAO,OAAO,EAAM,MAAM,IAAI,CAAe;KAAE;IAC7D;GACF;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** One pending frame at most; OrbitControls.update() reports when damping settles. */
|
|
2
|
+
export declare function createDemandRender({ update, render, request, cancel, }: {
|
|
3
|
+
update: () => boolean;
|
|
4
|
+
render: () => void;
|
|
5
|
+
request?: (callback: FrameRequestCallback) => number;
|
|
6
|
+
cancel?: (id: number) => void;
|
|
7
|
+
}): {
|
|
8
|
+
invalidate: () => void;
|
|
9
|
+
setActive(next: boolean): void;
|
|
10
|
+
dispose(): void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/components/pro/Flow/nodes/demandRender.ts
|
|
2
|
+
function e({ update: e, render: t, request: n = requestAnimationFrame, cancel: r = cancelAnimationFrame }) {
|
|
3
|
+
let i = null, a = !1, o = !1, s = !1, c = !0, l = () => {
|
|
4
|
+
a && !o && i === null && (i = n(u));
|
|
5
|
+
}, u = () => {
|
|
6
|
+
if (i = null, !a || o) return;
|
|
7
|
+
s = !0;
|
|
8
|
+
let n = e();
|
|
9
|
+
s = !1, (c || n) && t(), c = !1, n && l();
|
|
10
|
+
}, d = () => {
|
|
11
|
+
s || o || (c = !0, l());
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
invalidate: d,
|
|
15
|
+
setActive(e) {
|
|
16
|
+
a === e || o || (a = e, a ? d() : i !== null && (r(i), i = null));
|
|
17
|
+
},
|
|
18
|
+
dispose() {
|
|
19
|
+
o = !0, i !== null && r(i), i = null;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { e as createDemandRender };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=demandRender.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"demandRender.js","names":[],"sources":["../../../../../src/components/pro/Flow/nodes/demandRender.ts"],"sourcesContent":["/** One pending frame at most; OrbitControls.update() reports when damping settles. */\nexport function createDemandRender({\n update,\n render,\n request = requestAnimationFrame,\n cancel = cancelAnimationFrame,\n}: {\n update: () => boolean;\n render: () => void;\n request?: (callback: FrameRequestCallback) => number;\n cancel?: (id: number) => void;\n}) {\n let frame: number | null = null;\n let active = false;\n let disposed = false;\n let updating = false;\n let dirty = true;\n\n const schedule = () => {\n if (active && !disposed && frame === null) frame = request(tick);\n };\n const tick = () => {\n frame = null;\n if (!active || disposed) return;\n updating = true;\n const changed = update();\n updating = false;\n if (dirty || changed) render();\n dirty = false;\n if (changed) schedule();\n };\n const invalidate = () => {\n // update() emits change synchronously; its boolean result already accounts\n // for that change. Scheduling here would leave an extra perpetual RAF.\n if (updating || disposed) return;\n dirty = true;\n schedule();\n };\n return {\n invalidate,\n setActive(next: boolean) {\n if (active === next || disposed) return;\n active = next;\n if (active) invalidate();\n else if (frame !== null) {\n cancel(frame);\n frame = null;\n }\n },\n dispose() {\n disposed = true;\n if (frame !== null) cancel(frame);\n frame = null;\n },\n };\n}\n"],"mappings":";AACA,SAAgB,EAAmB,EACjC,WACA,WACA,aAAU,uBACV,YAAS,wBAMR;CACD,IAAI,IAAuB,MACvB,IAAS,IACT,IAAW,IACX,IAAW,IACX,IAAQ,IAEN,UAAiB;EACrB,AAAI,KAAU,CAAC,KAAY,MAAU,SAAM,IAAQ,EAAQ,CAAI;CACjE,GACM,UAAa;EAEjB,IADA,IAAQ,MACJ,CAAC,KAAU,GAAU;EACzB,IAAW;EACX,IAAM,IAAU,EAAO;EAIvB,AAHA,IAAW,KACP,KAAS,MAAS,EAAO,GAC7B,IAAQ,IACJ,KAAS,EAAS;CACxB,GACM,UAAmB;EAGnB,KAAY,MAChB,IAAQ,IACR,EAAS;CACX;CACA,OAAO;EACL;EACA,UAAU,GAAe;GACnB,MAAW,KAAQ,MACvB,IAAS,GACL,IAAQ,EAAW,IACd,MAAU,SACjB,EAAO,CAAK,GACZ,IAAQ;EAEZ;EACA,UAAU;GAGR,AAFA,IAAW,IACP,MAAU,QAAM,EAAO,CAAK,GAChC,IAAQ;EACV;CACF;AACF"}
|