dsh-tidy-display 0.1.0
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/CHANGELOG.md +270 -0
- package/DESIGN.md +72 -0
- package/LICENSE +24 -0
- package/README.en.md +118 -0
- package/README.md +118 -0
- package/THIRD_PARTY_NOTICES.md +65 -0
- package/compat/harness-rc2.json +99 -0
- package/cordis.patch.yml +5 -0
- package/cordis.yml +4 -0
- package/docs/official-rendering-bridge.md +65 -0
- package/docs/plans/2026-09-28-merge/checklist.md +21 -0
- package/docs/plans/2026-09-28-merge/findings.md +24 -0
- package/docs/plans/2026-09-28-merge/spec.md +61 -0
- package/docs/plans/2026-09-28-merge/tasks.md +34 -0
- package/dshx.yml +5 -0
- package/lib/client.js +50207 -0
- package/lib/client.js.map +1 -0
- package/lib/dsh-tidy-display.js +254 -0
- package/lib/types/client/Blocks.d.ts +49 -0
- package/lib/types/client/Blocks.d.ts.map +1 -0
- package/lib/types/client/Blocks.js +143 -0
- package/lib/types/client/Blocks.js.map +1 -0
- package/lib/types/client/ChoreographedFlow.d.ts +22 -0
- package/lib/types/client/ChoreographedFlow.d.ts.map +1 -0
- package/lib/types/client/ChoreographedFlow.js +218 -0
- package/lib/types/client/ChoreographedFlow.js.map +1 -0
- package/lib/types/client/ClosedProcessSummary.d.ts +9 -0
- package/lib/types/client/ClosedProcessSummary.d.ts.map +1 -0
- package/lib/types/client/ClosedProcessSummary.js +16 -0
- package/lib/types/client/ClosedProcessSummary.js.map +1 -0
- package/lib/types/client/DiffPanel.d.ts +13 -0
- package/lib/types/client/DiffPanel.d.ts.map +1 -0
- package/lib/types/client/DiffPanel.js +115 -0
- package/lib/types/client/DiffPanel.js.map +1 -0
- package/lib/types/client/LiveFold.d.ts +10 -0
- package/lib/types/client/LiveFold.d.ts.map +1 -0
- package/lib/types/client/LiveFold.js +39 -0
- package/lib/types/client/LiveFold.js.map +1 -0
- package/lib/types/client/McpAppFrame.d.ts +32 -0
- package/lib/types/client/McpAppFrame.d.ts.map +1 -0
- package/lib/types/client/McpAppFrame.js +193 -0
- package/lib/types/client/McpAppFrame.js.map +1 -0
- package/lib/types/client/OfficialContent.d.ts +25 -0
- package/lib/types/client/OfficialContent.d.ts.map +1 -0
- package/lib/types/client/OfficialContent.js +53 -0
- package/lib/types/client/OfficialContent.js.map +1 -0
- package/lib/types/client/Reader.d.ts +3 -0
- package/lib/types/client/Reader.d.ts.map +1 -0
- package/lib/types/client/Reader.js +508 -0
- package/lib/types/client/Reader.js.map +1 -0
- package/lib/types/client/ReasoningCard.d.ts +11 -0
- package/lib/types/client/ReasoningCard.d.ts.map +1 -0
- package/lib/types/client/ReasoningCard.js +322 -0
- package/lib/types/client/ReasoningCard.js.map +1 -0
- package/lib/types/client/SettingsSection.d.ts +59 -0
- package/lib/types/client/SettingsSection.d.ts.map +1 -0
- package/lib/types/client/SettingsSection.js +93 -0
- package/lib/types/client/SettingsSection.js.map +1 -0
- package/lib/types/client/StickyLane.d.ts +8 -0
- package/lib/types/client/StickyLane.d.ts.map +1 -0
- package/lib/types/client/StickyLane.js +39 -0
- package/lib/types/client/StickyLane.js.map +1 -0
- package/lib/types/client/TimelineRail.d.ts +10 -0
- package/lib/types/client/TimelineRail.d.ts.map +1 -0
- package/lib/types/client/TimelineRail.js +168 -0
- package/lib/types/client/TimelineRail.js.map +1 -0
- package/lib/types/client/ToolActivity.d.ts +17 -0
- package/lib/types/client/ToolActivity.d.ts.map +1 -0
- package/lib/types/client/ToolActivity.js +244 -0
- package/lib/types/client/ToolActivity.js.map +1 -0
- package/lib/types/client/TurnMetrics.d.ts +11 -0
- package/lib/types/client/TurnMetrics.d.ts.map +1 -0
- package/lib/types/client/TurnMetrics.js +44 -0
- package/lib/types/client/TurnMetrics.js.map +1 -0
- package/lib/types/client/WaitClock.d.ts +16 -0
- package/lib/types/client/WaitClock.d.ts.map +1 -0
- package/lib/types/client/WaitClock.js +29 -0
- package/lib/types/client/WaitClock.js.map +1 -0
- package/lib/types/client/WaitingClock.d.ts +15 -0
- package/lib/types/client/WaitingClock.d.ts.map +1 -0
- package/lib/types/client/WaitingClock.js +30 -0
- package/lib/types/client/WaitingClock.js.map +1 -0
- package/lib/types/client/WaitingStatus.d.ts +6 -0
- package/lib/types/client/WaitingStatus.d.ts.map +1 -0
- package/lib/types/client/WaitingStatus.js +9 -0
- package/lib/types/client/WaitingStatus.js.map +1 -0
- package/lib/types/client/conversation-scroll.d.ts +19 -0
- package/lib/types/client/conversation-scroll.d.ts.map +1 -0
- package/lib/types/client/conversation-scroll.js +25 -0
- package/lib/types/client/conversation-scroll.js.map +1 -0
- package/lib/types/client/deliverables.d.ts +24 -0
- package/lib/types/client/deliverables.d.ts.map +1 -0
- package/lib/types/client/deliverables.js +104 -0
- package/lib/types/client/deliverables.js.map +1 -0
- package/lib/types/client/entry-policy.d.ts +10 -0
- package/lib/types/client/entry-policy.d.ts.map +1 -0
- package/lib/types/client/entry-policy.js +24 -0
- package/lib/types/client/entry-policy.js.map +1 -0
- package/lib/types/client/entry.d.ts +4 -0
- package/lib/types/client/entry.d.ts.map +1 -0
- package/lib/types/client/entry.js +34 -0
- package/lib/types/client/entry.js.map +1 -0
- package/lib/types/client/fold-choreography.d.ts +40 -0
- package/lib/types/client/fold-choreography.d.ts.map +1 -0
- package/lib/types/client/fold-choreography.js +48 -0
- package/lib/types/client/fold-choreography.js.map +1 -0
- package/lib/types/client/fold-intensity.d.ts +11 -0
- package/lib/types/client/fold-intensity.d.ts.map +1 -0
- package/lib/types/client/fold-intensity.js +32 -0
- package/lib/types/client/fold-intensity.js.map +1 -0
- package/lib/types/client/index.d.ts +7 -0
- package/lib/types/client/index.d.ts.map +1 -0
- package/lib/types/client/index.js +234 -0
- package/lib/types/client/index.js.map +1 -0
- package/lib/types/client/live-turn.d.ts +58 -0
- package/lib/types/client/live-turn.d.ts.map +1 -0
- package/lib/types/client/live-turn.js +144 -0
- package/lib/types/client/live-turn.js.map +1 -0
- package/lib/types/client/markdown/MarkdownText.d.ts +41 -0
- package/lib/types/client/markdown/MarkdownText.d.ts.map +1 -0
- package/lib/types/client/markdown/MarkdownText.js +178 -0
- package/lib/types/client/markdown/MarkdownText.js.map +1 -0
- package/lib/types/client/markdown/cjkFriendlyStrong.d.ts +9 -0
- package/lib/types/client/markdown/cjkFriendlyStrong.d.ts.map +1 -0
- package/lib/types/client/markdown/cjkFriendlyStrong.js +73 -0
- package/lib/types/client/markdown/cjkFriendlyStrong.js.map +1 -0
- package/lib/types/client/markdown/incremental.d.ts +69 -0
- package/lib/types/client/markdown/incremental.d.ts.map +1 -0
- package/lib/types/client/markdown/incremental.js +108 -0
- package/lib/types/client/markdown/incremental.js.map +1 -0
- package/lib/types/client/markdown/katex.d.ts +27 -0
- package/lib/types/client/markdown/katex.d.ts.map +1 -0
- package/lib/types/client/markdown/katex.js +88 -0
- package/lib/types/client/markdown/katex.js.map +1 -0
- package/lib/types/client/markdown/mathCompatibility.d.ts +11 -0
- package/lib/types/client/markdown/mathCompatibility.d.ts.map +1 -0
- package/lib/types/client/markdown/mathCompatibility.js +295 -0
- package/lib/types/client/markdown/mathCompatibility.js.map +1 -0
- package/lib/types/client/markdown/parse.d.ts +25 -0
- package/lib/types/client/markdown/parse.d.ts.map +1 -0
- package/lib/types/client/markdown/parse.js +42 -0
- package/lib/types/client/markdown/parse.js.map +1 -0
- package/lib/types/client/markdown/render.d.ts +121 -0
- package/lib/types/client/markdown/render.d.ts.map +1 -0
- package/lib/types/client/markdown/render.js +452 -0
- package/lib/types/client/markdown/render.js.map +1 -0
- package/lib/types/client/mcp-app.d.ts +50 -0
- package/lib/types/client/mcp-app.d.ts.map +1 -0
- package/lib/types/client/mcp-app.js +328 -0
- package/lib/types/client/mcp-app.js.map +1 -0
- package/lib/types/client/message-chrome.d.ts +19 -0
- package/lib/types/client/message-chrome.d.ts.map +1 -0
- package/lib/types/client/message-chrome.js +42 -0
- package/lib/types/client/message-chrome.js.map +1 -0
- package/lib/types/client/motion.d.ts +38 -0
- package/lib/types/client/motion.d.ts.map +1 -0
- package/lib/types/client/motion.js +453 -0
- package/lib/types/client/motion.js.map +1 -0
- package/lib/types/client/native/ContextBody.d.ts +130 -0
- package/lib/types/client/native/ContextBody.d.ts.map +1 -0
- package/lib/types/client/native/ContextBody.js +398 -0
- package/lib/types/client/native/ContextBody.js.map +1 -0
- package/lib/types/client/native/ContextInjectionRow.d.ts +35 -0
- package/lib/types/client/native/ContextInjectionRow.d.ts.map +1 -0
- package/lib/types/client/native/ContextInjectionRow.js +42 -0
- package/lib/types/client/native/ContextInjectionRow.js.map +1 -0
- package/lib/types/client/native/ReferenceIcon.d.ts +16 -0
- package/lib/types/client/native/ReferenceIcon.d.ts.map +1 -0
- package/lib/types/client/native/ReferenceIcon.js +16 -0
- package/lib/types/client/native/ReferenceIcon.js.map +1 -0
- package/lib/types/client/native/tool-call-model.d.ts +58 -0
- package/lib/types/client/native/tool-call-model.d.ts.map +1 -0
- package/lib/types/client/native/tool-call-model.js +219 -0
- package/lib/types/client/native/tool-call-model.js.map +1 -0
- package/lib/types/client/native/tool-update.d.ts +23 -0
- package/lib/types/client/native/tool-update.d.ts.map +1 -0
- package/lib/types/client/native/tool-update.js +22 -0
- package/lib/types/client/native/tool-update.js.map +1 -0
- package/lib/types/client/official-slots.d.ts +71 -0
- package/lib/types/client/official-slots.d.ts.map +1 -0
- package/lib/types/client/official-slots.js +183 -0
- package/lib/types/client/official-slots.js.map +1 -0
- package/lib/types/client/open-file.d.ts +29 -0
- package/lib/types/client/open-file.d.ts.map +1 -0
- package/lib/types/client/open-file.js +71 -0
- package/lib/types/client/open-file.js.map +1 -0
- package/lib/types/client/pending-submission.d.ts +28 -0
- package/lib/types/client/pending-submission.d.ts.map +1 -0
- package/lib/types/client/pending-submission.js +28 -0
- package/lib/types/client/pending-submission.js.map +1 -0
- package/lib/types/client/platform-media.d.ts +6 -0
- package/lib/types/client/platform-media.d.ts.map +1 -0
- package/lib/types/client/platform-media.js +18 -0
- package/lib/types/client/platform-media.js.map +1 -0
- package/lib/types/client/primitive-labels.d.ts +10 -0
- package/lib/types/client/primitive-labels.d.ts.map +1 -0
- package/lib/types/client/primitive-labels.js +38 -0
- package/lib/types/client/primitive-labels.js.map +1 -0
- package/lib/types/client/projection.d.ts +41 -0
- package/lib/types/client/projection.d.ts.map +1 -0
- package/lib/types/client/projection.js +112 -0
- package/lib/types/client/projection.js.map +1 -0
- package/lib/types/client/rail/RailView.d.ts +24 -0
- package/lib/types/client/rail/RailView.d.ts.map +1 -0
- package/lib/types/client/rail/RailView.js +540 -0
- package/lib/types/client/rail/RailView.js.map +1 -0
- package/lib/types/client/rail/colors.d.ts +43 -0
- package/lib/types/client/rail/colors.d.ts.map +1 -0
- package/lib/types/client/rail/colors.js +223 -0
- package/lib/types/client/rail/colors.js.map +1 -0
- package/lib/types/client/reasoning-follow.d.ts +10 -0
- package/lib/types/client/reasoning-follow.d.ts.map +1 -0
- package/lib/types/client/reasoning-follow.js +21 -0
- package/lib/types/client/reasoning-follow.js.map +1 -0
- package/lib/types/client/resource-address.d.ts +3 -0
- package/lib/types/client/resource-address.d.ts.map +1 -0
- package/lib/types/client/resource-address.js +33 -0
- package/lib/types/client/resource-address.js.map +1 -0
- package/lib/types/client/settings-copy.d.ts +7 -0
- package/lib/types/client/settings-copy.d.ts.map +1 -0
- package/lib/types/client/settings-copy.js +85 -0
- package/lib/types/client/settings-copy.js.map +1 -0
- package/lib/types/client/settings-slots.d.ts +34 -0
- package/lib/types/client/settings-slots.d.ts.map +1 -0
- package/lib/types/client/settings-slots.js +2 -0
- package/lib/types/client/settings-slots.js.map +1 -0
- package/lib/types/client/settings.d.ts +4 -0
- package/lib/types/client/settings.d.ts.map +1 -0
- package/lib/types/client/settings.js +60 -0
- package/lib/types/client/settings.js.map +1 -0
- package/lib/types/client/skill-status.d.ts +25 -0
- package/lib/types/client/skill-status.d.ts.map +1 -0
- package/lib/types/client/skill-status.js +44 -0
- package/lib/types/client/skill-status.js.map +1 -0
- package/lib/types/client/store.d.ts +66 -0
- package/lib/types/client/store.d.ts.map +1 -0
- package/lib/types/client/store.js +61 -0
- package/lib/types/client/store.js.map +1 -0
- package/lib/types/client/stream-buffer.d.ts +37 -0
- package/lib/types/client/stream-buffer.d.ts.map +1 -0
- package/lib/types/client/stream-buffer.js +150 -0
- package/lib/types/client/stream-buffer.js.map +1 -0
- package/lib/types/client/streaming.d.ts +18 -0
- package/lib/types/client/streaming.d.ts.map +1 -0
- package/lib/types/client/streaming.js +84 -0
- package/lib/types/client/streaming.js.map +1 -0
- package/lib/types/client/timeline.d.ts +26 -0
- package/lib/types/client/timeline.d.ts.map +1 -0
- package/lib/types/client/timeline.js +48 -0
- package/lib/types/client/timeline.js.map +1 -0
- package/lib/types/client/tool-activity.d.ts +98 -0
- package/lib/types/client/tool-activity.d.ts.map +1 -0
- package/lib/types/client/tool-activity.js +301 -0
- package/lib/types/client/tool-activity.js.map +1 -0
- package/lib/types/client/types.d.ts +91 -0
- package/lib/types/client/types.d.ts.map +1 -0
- package/lib/types/client/types.js +2 -0
- package/lib/types/client/types.js.map +1 -0
- package/lib/types/client/waiting-clock.d.ts +49 -0
- package/lib/types/client/waiting-clock.d.ts.map +1 -0
- package/lib/types/client/waiting-clock.js +80 -0
- package/lib/types/client/waiting-clock.js.map +1 -0
- package/lib/types/client/word-motion.d.ts +16 -0
- package/lib/types/client/word-motion.d.ts.map +1 -0
- package/lib/types/client/word-motion.js +90 -0
- package/lib/types/client/word-motion.js.map +1 -0
- package/lib/types/client/word-timeline.d.ts +32 -0
- package/lib/types/client/word-timeline.d.ts.map +1 -0
- package/lib/types/client/word-timeline.js +119 -0
- package/lib/types/client/word-timeline.js.map +1 -0
- package/lib/types/dsh-tidy-display.d.ts +17 -0
- package/lib/types/dsh-tidy-display.d.ts.map +1 -0
- package/lib/types/dsh-tidy-display.js +97 -0
- package/lib/types/dsh-tidy-display.js.map +1 -0
- package/lib/types/skill-roots.d.ts +22 -0
- package/lib/types/skill-roots.d.ts.map +1 -0
- package/lib/types/skill-roots.js +126 -0
- package/lib/types/skill-roots.js.map +1 -0
- package/lib/types/skill-status.d.ts +36 -0
- package/lib/types/skill-status.d.ts.map +1 -0
- package/lib/types/skill-status.js +51 -0
- package/lib/types/skill-status.js.map +1 -0
- package/package.json +141 -0
- package/scripts/build-motion-fixture.mjs +26 -0
- package/scripts/check-harness-compat.mjs +75 -0
- package/scripts/link-harness-dependencies.mjs +54 -0
- package/scripts/verify-auto-fold.mjs +114 -0
- package/scripts/verify-official-bridge.mjs +121 -0
- package/scripts/verify-tool-shimmer.mjs +62 -0
- package/skills/generative-mcpapps/SKILL.md +47 -0
- package/skills/generative-mcpapps/examples/interactive_quiz.html +153 -0
- package/skills/generative-mcpapps/references/html_boilerplate.md +122 -0
- package/skills/generative-mcpapps/references/sep1865_protocol.md +54 -0
- package/src/client/Blocks.tsx +213 -0
- package/src/client/ChoreographedFlow.tsx +232 -0
- package/src/client/ClosedProcessSummary.tsx +23 -0
- package/src/client/DiffPanel.tsx +124 -0
- package/src/client/LiveFold.tsx +43 -0
- package/src/client/McpAppFrame.module.css +210 -0
- package/src/client/McpAppFrame.tsx +317 -0
- package/src/client/OfficialContent.tsx +69 -0
- package/src/client/Reader.module.css +714 -0
- package/src/client/Reader.tsx +783 -0
- package/src/client/ReasoningCard.tsx +306 -0
- package/src/client/SettingsSection.module.css +184 -0
- package/src/client/SettingsSection.tsx +391 -0
- package/src/client/StickyLane.tsx +34 -0
- package/src/client/ToolActivity.tsx +274 -0
- package/src/client/TurnMetrics.module.css +139 -0
- package/src/client/TurnMetrics.tsx +160 -0
- package/src/client/WaitClock.tsx +33 -0
- package/src/client/WaitingStatus.tsx +13 -0
- package/src/client/conversation-scroll.ts +28 -0
- package/src/client/deliverables.ts +122 -0
- package/src/client/entry-policy.ts +20 -0
- package/src/client/entry.tsx +40 -0
- package/src/client/fold-choreography.ts +55 -0
- package/src/client/fold-intensity.ts +36 -0
- package/src/client/index.tsx +268 -0
- package/src/client/live-turn.ts +155 -0
- package/src/client/markdown/MarkdownText.module.css +304 -0
- package/src/client/markdown/MarkdownText.tsx +195 -0
- package/src/client/markdown/cjkFriendlyStrong.ts +84 -0
- package/src/client/markdown/incremental.ts +131 -0
- package/src/client/markdown/katex.tsx +91 -0
- package/src/client/markdown/mathCompatibility.ts +352 -0
- package/src/client/markdown/parse.ts +45 -0
- package/src/client/markdown/render.tsx +647 -0
- package/src/client/markdown/upstream.json +14 -0
- package/src/client/mcp-app.ts +323 -0
- package/src/client/message-chrome.ts +47 -0
- package/src/client/motion.tsx +410 -0
- package/src/client/native/ContextBody.module.css +161 -0
- package/src/client/native/ContextBody.tsx +591 -0
- package/src/client/native/ContextInjectionRow.module.css +66 -0
- package/src/client/native/ContextInjectionRow.tsx +106 -0
- package/src/client/native/ReferenceIcon.tsx +35 -0
- package/src/client/native/tool-call-model.ts +248 -0
- package/src/client/native/tool-update.ts +32 -0
- package/src/client/native/upstream.json +41 -0
- package/src/client/official-slots.tsx +211 -0
- package/src/client/open-file.ts +94 -0
- package/src/client/pending-submission.ts +49 -0
- package/src/client/platform-media.ts +17 -0
- package/src/client/primitive-labels.ts +54 -0
- package/src/client/projection.ts +118 -0
- package/src/client/rail/RailView.tsx +508 -0
- package/src/client/rail/colors.ts +212 -0
- package/src/client/reasoning-follow.ts +28 -0
- package/src/client/settings-copy.ts +128 -0
- package/src/client/settings-slots.ts +27 -0
- package/src/client/settings.tsx +73 -0
- package/src/client/skill-status.ts +78 -0
- package/src/client/store.ts +130 -0
- package/src/client/stream-buffer.ts +136 -0
- package/src/client/streaming.tsx +70 -0
- package/src/client/style.d.ts +4 -0
- package/src/client/timeline.ts +75 -0
- package/src/client/tool-activity.ts +298 -0
- package/src/client/types.ts +89 -0
- package/src/client/waiting-clock.ts +83 -0
- package/src/client/word-motion.tsx +92 -0
- package/src/client/word-timeline.ts +113 -0
- package/src/dsh-tidy-display.ts +112 -0
- package/src/skill-roots.ts +138 -0
- package/src/skill-status.ts +81 -0
- package/tests/browser-auto-fold.tsx +64 -0
- package/tests/browser-closed-gap.tsx +20 -0
- package/tests/browser-motion.tsx +65 -0
- package/tests/browser-official-bridge.tsx +152 -0
- package/tests/browser-sticky-lanes.tsx +22 -0
- package/tests/browser-waiting-clock.tsx +14 -0
- package/tests/chat-flow-hook.test.ts +66 -0
- package/tests/cloud-gate.test.ts +34 -0
- package/tests/context-tool-update.test.ts +33 -0
- package/tests/conversation-scroll.test.ts +47 -0
- package/tests/deliverables.test.ts +128 -0
- package/tests/entry.test.ts +42 -0
- package/tests/fixtures/maid-composer-hide.html +31 -0
- package/tests/fold-choreography.test.ts +54 -0
- package/tests/fold-intensity.test.ts +93 -0
- package/tests/footer-precedence.test.ts +129 -0
- package/tests/history-word-regression.test.ts +16 -0
- package/tests/live-turn.test.ts +218 -0
- package/tests/mcp-apps.test.ts +157 -0
- package/tests/message-chrome.test.ts +29 -0
- package/tests/official-slots.test.ts +112 -0
- package/tests/open-file.test.ts +114 -0
- package/tests/pending-submission.test.ts +45 -0
- package/tests/platform-media.test.ts +23 -0
- package/tests/projection.test.ts +184 -0
- package/tests/reasoning-follow.test.ts +34 -0
- package/tests/settings-copy.test.ts +63 -0
- package/tests/skill-status.test.ts +140 -0
- package/tests/stock-install.test.ts +58 -0
- package/tests/stream-buffer.test.ts +102 -0
- package/tests/timeline.test.ts +59 -0
- package/tests/tool-diff.test.ts +57 -0
- package/tests/waiting-clock.test.ts +83 -0
- package/tests/word-timeline.test.ts +146 -0
- package/tsconfig.json +11 -0
- package/tsdown.config.ts +51 -0
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Canvas message rail, ported from dsh-tidychat (release/0.1.7, white-sheen
|
|
5
|
+
* ring edition). DOM single source of truth: identity/count/order come from
|
|
6
|
+
* conversation rows carrying the host anchor contract (data-chat-anchor-key +
|
|
7
|
+
* data-chat-flow-kind, present on native ChatView rows and on reader rows
|
|
8
|
+
* since the anchor-contract fix). Port adjustments vs the tidychat original:
|
|
9
|
+
* - config comes in as props from the reader store (no settings namespace)
|
|
10
|
+
* - "load earlier" goes through the reader's own loadOlder (no button sniffing)
|
|
11
|
+
* - summaries use the row-text fallback only (the event-source enhancement is
|
|
12
|
+
* a tidychat-side refinement, deferred); time is omitted until then.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export type RailSide = 'left' | 'right';
|
|
16
|
+
export type RailStyle = 'bar' | 'dot';
|
|
17
|
+
|
|
18
|
+
const NAV_RAIL_WIDTH = 48;
|
|
19
|
+
const NAV_RAIL_BAR_H = 3;
|
|
20
|
+
const NAV_RAIL_BAR_LEN = 14;
|
|
21
|
+
const NAV_RAIL_BAR_LEN_NEAR = 26;
|
|
22
|
+
const NAV_RAIL_BAR_LEN_CURRENT = 22;
|
|
23
|
+
const NAV_RAIL_FISH_EYE_RADIUS = 4;
|
|
24
|
+
const NAV_RAIL_FISH_EYE_BOOST = 0.5;
|
|
25
|
+
const NAV_RAIL_TURN_SPACING = 12;
|
|
26
|
+
const NAV_RAIL_MIN_HEIGHT = 48;
|
|
27
|
+
const NAV_RAIL_CAP_H = 16;
|
|
28
|
+
const NAV_RAIL_CAP_INDEX = -1;
|
|
29
|
+
const HEADER_OFFSET = 64;
|
|
30
|
+
const NAV_RAIL_RING_OFFSET = 2;
|
|
31
|
+
const NAV_RAIL_RING_BLUR = 4;
|
|
32
|
+
const NAV_RAIL_RING_ALPHA_CURRENT = 0.4;
|
|
33
|
+
const NAV_RAIL_RING_ALPHA_HOVER = 0.22;
|
|
34
|
+
|
|
35
|
+
let cssInjected = false;
|
|
36
|
+
function ensureRailCss(): void {
|
|
37
|
+
if (cssInjected || typeof document === 'undefined') return;
|
|
38
|
+
cssInjected = true;
|
|
39
|
+
const style = document.createElement('style');
|
|
40
|
+
style.textContent = `
|
|
41
|
+
.tidychat-nav-rail { position: fixed; z-index: 40; display: flex; flex-direction: column; align-items: flex-start; padding: 6px 2px; }
|
|
42
|
+
.tidychat-nav-canvas { display: block; cursor: pointer; touch-action: none; }
|
|
43
|
+
.tidychat-nav-tip.tidychat-nav-tip {
|
|
44
|
+
position: fixed; z-index: 41; pointer-events: none; max-width: 300px;
|
|
45
|
+
background: var(--dsw-alias-bg-layer-3, #fff);
|
|
46
|
+
border: 1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.3));
|
|
47
|
+
border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,0.16); padding: 6px 10px;
|
|
48
|
+
font-size: 12px; line-height: 1.5;
|
|
49
|
+
color: var(--tidychat-nav-tip-text, var(--dsw-alias-label-primary, #222)) !important;
|
|
50
|
+
overflow-wrap: anywhere;
|
|
51
|
+
}
|
|
52
|
+
.tidychat-nav-tip-head { color: var(--tidychat-nav-tip-head, var(--dsw-alias-label-secondary, #666)) !important; font-size: 11px; margin-bottom: 2px; }
|
|
53
|
+
/* 接管官方消息轨:官方 TurnNavigator 的类名是 CSS Module 产物(hash 随构建变化),
|
|
54
|
+
双重锚定保证跨 hash 稳定;隐藏而非卸载(宿主 React 会还原被删节点)。 */
|
|
55
|
+
html[data-tidychat-hide-official-nav] [class*="_slot"]:has(> nav[class*="_frame"]),
|
|
56
|
+
html[data-tidychat-hide-official-nav] nav[class*="_frame"]:has([style*="--turn-natural-position"]) {
|
|
57
|
+
display: none !important;
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
60
|
+
document.head.appendChild(style);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const findScrollContainer = (): Element | null => document.querySelector('[data-conversation-scroll]')
|
|
64
|
+
|
|
65
|
+
const scopedRows = (selector: string): Element[] => {
|
|
66
|
+
const container = findScrollContainer()
|
|
67
|
+
return Array.from((container ?? document).querySelectorAll<Element>(selector))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// DOM 侧用户行:'user' + 'steering' 同视(宿主原生行与阅读视图行同契约)。
|
|
71
|
+
// data-reader-key 回退:渲染器替换者丢失原生锚点时的兜底,键公式只做白名单分类。
|
|
72
|
+
const railRows = (): Element[] => {
|
|
73
|
+
const native = scopedRows('[data-chat-anchor-key]').filter((r) => {
|
|
74
|
+
const k = r.getAttribute('data-chat-flow-kind')
|
|
75
|
+
return k === 'user' || k === 'steering'
|
|
76
|
+
})
|
|
77
|
+
if (native.length > 0) return native
|
|
78
|
+
return scopedRows('[data-reader-key]').filter((r) => {
|
|
79
|
+
const key = r.getAttribute('data-reader-key') || ''
|
|
80
|
+
const m = /^(\d+):/.exec(key)
|
|
81
|
+
if (m === null) return false
|
|
82
|
+
const kind = key.slice(m[1].length + 1, m[1].length + 1 + Number(m[1]))
|
|
83
|
+
return kind === 'user' || kind === 'steering'
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const fallbackSummary = (el: Element): string => {
|
|
88
|
+
try {
|
|
89
|
+
const t = (el as HTMLElement).innerText ?? ''
|
|
90
|
+
return t.replace(/\s+/g, ' ').trim().slice(0, 120)
|
|
91
|
+
} catch { return String(el.textContent ?? '').trim().slice(0, 120) }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const hhmm = (ms: number): string => {
|
|
95
|
+
const d = new Date(ms)
|
|
96
|
+
const pad = (n: number) => (n < 10 ? '0' + n : String(n))
|
|
97
|
+
return (d.getMonth() + 1) + '月' + d.getDate() + '日 ' + pad(d.getHours()) + ':' + pad(d.getMinutes())
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const railHeight = (n: number): number => Math.min(Math.min(window.innerHeight * 0.7, 660), Math.max(NAV_RAIL_MIN_HEIGHT, n * NAV_RAIL_TURN_SPACING))
|
|
101
|
+
|
|
102
|
+
const roundRectPath = (c: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, r: number): void => {
|
|
103
|
+
const rr = Math.max(0, Math.min(r, w / 2, h / 2))
|
|
104
|
+
c.beginPath()
|
|
105
|
+
c.moveTo(x + rr, y)
|
|
106
|
+
c.arcTo(x + w, y, x + w, y + h, rr)
|
|
107
|
+
c.arcTo(x + w, y + h, x, y + h, rr)
|
|
108
|
+
c.arcTo(x, y + h, x, y, rr)
|
|
109
|
+
c.arcTo(x, y, x + w, y, rr)
|
|
110
|
+
c.closePath()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const measurePos = (side: RailSide): { left: number; top: number; gutter: number } | null => {
|
|
114
|
+
const host = document.querySelector('[data-conversation-scroll]')
|
|
115
|
+
if (host === null) return null
|
|
116
|
+
const r = host.getBoundingClientRect()
|
|
117
|
+
if (r.width < 10 || r.height < 10) return null
|
|
118
|
+
const composer = scopedRows('[data-composer-card]')[0]
|
|
119
|
+
const chatRows = scopedRows('[data-chat-anchor-key]')
|
|
120
|
+
const candidates = [composer, chatRows[0], chatRows[chatRows.length - 1]].filter((x): x is Element => x !== null && x !== undefined)
|
|
121
|
+
const rects = candidates.map((el) => el.getBoundingClientRect())
|
|
122
|
+
if (side === 'right') {
|
|
123
|
+
const maxRight = rects.length > 0 ? Math.max(...rects.map((e) => e.right)) : r.right
|
|
124
|
+
const gutter = Math.max(0, r.right - maxRight)
|
|
125
|
+
return { left: r.right - (NAV_RAIL_WIDTH - 4), top: r.top + r.height * 0.5, gutter }
|
|
126
|
+
}
|
|
127
|
+
const minLeft = rects.length > 0 ? Math.min(...rects.map((e) => e.left)) : r.left
|
|
128
|
+
const gutterL = Math.max(0, minLeft - r.left)
|
|
129
|
+
return { left: r.left, top: r.top + r.height * 0.5, gutter: gutterL }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function RailView({ enabled, side, style: railStyle, ring, hideOfficialNav, hasMore, loadOlder }: {
|
|
133
|
+
enabled: boolean; side: RailSide; style: RailStyle; ring: boolean; hideOfficialNav: boolean;
|
|
134
|
+
hasMore: boolean; loadOlder: () => void | Promise<void>;
|
|
135
|
+
}): React.ReactElement | null {
|
|
136
|
+
ensureRailCss()
|
|
137
|
+
// 接管官方消息轨:切根元素属性,官方轨 CSS 隐藏(隐藏≠卸载,宿主 React 仍挂载它)。
|
|
138
|
+
React.useEffect(() => {
|
|
139
|
+
if (hideOfficialNav) document.documentElement.setAttribute('data-tidychat-hide-official-nav', '')
|
|
140
|
+
else document.documentElement.removeAttribute('data-tidychat-hide-official-nav')
|
|
141
|
+
return () => { document.documentElement.removeAttribute('data-tidychat-hide-official-nav') }
|
|
142
|
+
}, [hideOfficialNav])
|
|
143
|
+
const [pos, setPos] = React.useState<{ left: number; top: number; gutter: number } | null>(null)
|
|
144
|
+
const [tip, setTip] = React.useState<{ x: number; y: number; head?: string | null; num: number | null; time: string; text: string; mirror: boolean } | null>(null)
|
|
145
|
+
const [hover, setHover] = React.useState<number | null>(null)
|
|
146
|
+
const [current, setCurrent] = React.useState<number | null>(null)
|
|
147
|
+
const canvasRef = React.useRef<HTMLCanvasElement | null>(null)
|
|
148
|
+
const moveRafRef = React.useRef(0)
|
|
149
|
+
const moveLastRef = React.useRef<{ x: number; y: number } | null>(null)
|
|
150
|
+
const rowCacheRef = React.useRef<{ rows: Element[]; tops: number[]; count: number; scrollH: number }>({ rows: [], tops: [], count: -1, scrollH: -1 })
|
|
151
|
+
const scrollAnimRef = React.useRef(0)
|
|
152
|
+
const cancelScrollAnim = (): void => {
|
|
153
|
+
if (scrollAnimRef.current !== 0) { cancelAnimationFrame(scrollAnimRef.current); scrollAnimRef.current = 0 }
|
|
154
|
+
}
|
|
155
|
+
const smoothScrollTo = (container: Element, top: number): void => {
|
|
156
|
+
cancelScrollAnim()
|
|
157
|
+
const el = container as HTMLElement
|
|
158
|
+
const maxTop = Math.max(0, el.scrollHeight - el.clientHeight)
|
|
159
|
+
const target = Math.max(0, Math.min(maxTop, top))
|
|
160
|
+
const start = el.scrollTop
|
|
161
|
+
const delta = target - start
|
|
162
|
+
if (Math.abs(delta) < 1) return
|
|
163
|
+
let reduce = false
|
|
164
|
+
try { reduce = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches } catch { /* ignore */ }
|
|
165
|
+
if (reduce) { el.scrollTop = target; return }
|
|
166
|
+
const duration = Math.min(700, Math.max(260, Math.abs(delta) * 0.45))
|
|
167
|
+
const t0 = performance.now()
|
|
168
|
+
const ease = (p: number): number => (p < 0.5 ? 4 * p * p * p : 1 - Math.pow(-2 * p + 2, 3) / 2)
|
|
169
|
+
const step = (now: number): void => {
|
|
170
|
+
const p = Math.min(1, (now - t0) / duration)
|
|
171
|
+
el.scrollTop = start + delta * ease(p)
|
|
172
|
+
scrollAnimRef.current = p < 1 ? requestAnimationFrame(step) : 0
|
|
173
|
+
}
|
|
174
|
+
scrollAnimRef.current = requestAnimationFrame(step)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const turns: Array<{ el: Element; summary: string; time: number | null }> = railRows().map((el) => ({ el, summary: fallbackSummary(el), time: null }))
|
|
178
|
+
const capOffset = hasMore ? NAV_RAIL_CAP_H : 0
|
|
179
|
+
|
|
180
|
+
const rebuildRowCache = (count: number, scrollH: number): void => {
|
|
181
|
+
const rows = railRows()
|
|
182
|
+
const container = findScrollContainer()
|
|
183
|
+
if (container === null) { rowCacheRef.current = { rows: [], tops: [], count, scrollH }; return }
|
|
184
|
+
const cRect = container.getBoundingClientRect()
|
|
185
|
+
const tops = rows.map((r) => r.getBoundingClientRect().top - cRect.top + container.scrollTop)
|
|
186
|
+
rowCacheRef.current = { rows, tops, count, scrollH }
|
|
187
|
+
}
|
|
188
|
+
const detectCurrent = (): void => {
|
|
189
|
+
const container = findScrollContainer()
|
|
190
|
+
const tops = rowCacheRef.current.tops
|
|
191
|
+
if (container === null || tops.length === 0) return
|
|
192
|
+
const target = container.scrollTop + HEADER_OFFSET
|
|
193
|
+
let lo = 0; let hi = tops.length - 1; let ans = -1
|
|
194
|
+
while (lo <= hi) {
|
|
195
|
+
const mid = (lo + hi) >> 1
|
|
196
|
+
if (tops[mid] <= target) { ans = mid; lo = mid + 1 } else hi = mid - 1
|
|
197
|
+
}
|
|
198
|
+
const cur = ans === -1 ? 0 : ans
|
|
199
|
+
setCurrent((p) => (p === cur ? p : cur))
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const layoutPositions = (n: number, hoverIdx: number | null, H: number): number[] => {
|
|
203
|
+
const weights: number[] = []
|
|
204
|
+
for (let i = 0; i < n; i++) {
|
|
205
|
+
let w = 1
|
|
206
|
+
if (hoverIdx !== null) {
|
|
207
|
+
const d = Math.abs(i - hoverIdx)
|
|
208
|
+
if (d <= NAV_RAIL_FISH_EYE_RADIUS) w = 1 + (NAV_RAIL_FISH_EYE_RADIUS - d + 1) * NAV_RAIL_FISH_EYE_BOOST
|
|
209
|
+
}
|
|
210
|
+
weights.push(w)
|
|
211
|
+
}
|
|
212
|
+
const total = weights.reduce((a, b) => a + b, 0)
|
|
213
|
+
const usable = Math.max(H - NAV_RAIL_BAR_H, 1)
|
|
214
|
+
const pos: number[] = []
|
|
215
|
+
let acc = 0
|
|
216
|
+
for (let i = 0; i < n; i++) {
|
|
217
|
+
acc += weights[i]
|
|
218
|
+
pos.push(((acc - weights[i] / 2) / total) * usable + NAV_RAIL_BAR_H / 2)
|
|
219
|
+
}
|
|
220
|
+
return pos
|
|
221
|
+
}
|
|
222
|
+
const indexFromY = (y: number, positions: number[]): number => {
|
|
223
|
+
if (positions.length === 0) return 0
|
|
224
|
+
let lo = 0; let hi = positions.length - 1
|
|
225
|
+
while (lo < hi) {
|
|
226
|
+
const mid = (lo + hi) >> 1
|
|
227
|
+
if (positions[mid] < y) lo = mid + 1
|
|
228
|
+
else hi = mid
|
|
229
|
+
}
|
|
230
|
+
const cur = positions[lo]
|
|
231
|
+
const prev = lo > 0 ? positions[lo - 1] : -Infinity
|
|
232
|
+
const candidate = Math.abs(cur - y) <= Math.abs(prev - y) ? lo : lo - 1
|
|
233
|
+
return Math.max(0, Math.min(positions.length - 1, candidate))
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const marksHeight = (): number => (turns.length === 0 ? 0 : railHeight(turns.length))
|
|
237
|
+
const positionsAt = (hv: number | null): number[] =>
|
|
238
|
+
layoutPositions(turns.length, hv, marksHeight()).map((y) => y + capOffset)
|
|
239
|
+
|
|
240
|
+
// 每轮渲染后:行数或内容高度变化(加载/懒加载)→ 重建行缓存 → 检测当前 turn → 重绘
|
|
241
|
+
React.useEffect(() => {
|
|
242
|
+
const container = findScrollContainer()
|
|
243
|
+
const scrollH = container !== null ? container.scrollHeight : 0
|
|
244
|
+
if (rowCacheRef.current.count !== turns.length || rowCacheRef.current.scrollH !== scrollH) {
|
|
245
|
+
rebuildRowCache(turns.length, scrollH)
|
|
246
|
+
}
|
|
247
|
+
detectCurrent()
|
|
248
|
+
redraw()
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
const jumpTo = (index: number): void => {
|
|
252
|
+
const t = turns[index]
|
|
253
|
+
if (t === undefined) return
|
|
254
|
+
const container = findScrollContainer()
|
|
255
|
+
if (container === null) return
|
|
256
|
+
const cRect = container.getBoundingClientRect()
|
|
257
|
+
const tRect = t.el.getBoundingClientRect()
|
|
258
|
+
smoothScrollTo(container, (tRect.top - cRect.top) + container.scrollTop - HEADER_OFFSET)
|
|
259
|
+
}
|
|
260
|
+
const inCap = (localY: number): boolean => capOffset > 0 && localY < capOffset
|
|
261
|
+
const markY = (i: number, hv: number | null): number => positionsAt(hv)[i] ?? 0
|
|
262
|
+
const indexAt = (localY: number): number => {
|
|
263
|
+
let idx = indexFromY(localY, positionsAt(null))
|
|
264
|
+
let prev = -1
|
|
265
|
+
for (let k = 0; k < 4; k++) {
|
|
266
|
+
const next = indexFromY(localY, positionsAt(idx))
|
|
267
|
+
if (next === idx) return idx
|
|
268
|
+
if (next === prev) {
|
|
269
|
+
return Math.abs(markY(idx, idx) - localY) <= Math.abs(markY(next, next) - localY) ? idx : next
|
|
270
|
+
}
|
|
271
|
+
prev = idx
|
|
272
|
+
idx = next
|
|
273
|
+
}
|
|
274
|
+
return idx
|
|
275
|
+
}
|
|
276
|
+
const handlePointerMove = (ev: React.PointerEvent<HTMLCanvasElement>): void => {
|
|
277
|
+
moveLastRef.current = { x: ev.clientX, y: ev.clientY }
|
|
278
|
+
if (moveRafRef.current !== 0) return
|
|
279
|
+
moveRafRef.current = requestAnimationFrame(() => {
|
|
280
|
+
moveRafRef.current = 0
|
|
281
|
+
const p = moveLastRef.current
|
|
282
|
+
moveLastRef.current = null
|
|
283
|
+
if (p === null || canvasRef.current === null) return
|
|
284
|
+
const canvas = canvasRef.current
|
|
285
|
+
const rect = canvas.getBoundingClientRect()
|
|
286
|
+
const localY = p.y - rect.top
|
|
287
|
+
const mirror = side === 'right'
|
|
288
|
+
if (inCap(localY)) {
|
|
289
|
+
if (hover !== NAV_RAIL_CAP_INDEX) setHover(NAV_RAIL_CAP_INDEX)
|
|
290
|
+
setTip({
|
|
291
|
+
x: mirror ? p.x - 18 : p.x + 18,
|
|
292
|
+
y: p.y - 8,
|
|
293
|
+
head: '更早历史未加载',
|
|
294
|
+
num: null,
|
|
295
|
+
time: '',
|
|
296
|
+
text: `点击加载更早记录 · 当前轨道仅覆盖已加载的 ${turns.length} 轮`,
|
|
297
|
+
mirror,
|
|
298
|
+
})
|
|
299
|
+
return
|
|
300
|
+
}
|
|
301
|
+
const idx = indexAt(localY)
|
|
302
|
+
if (idx !== hover) setHover(idx)
|
|
303
|
+
const u = turns[idx]
|
|
304
|
+
if (u === undefined) { setTip(null); return }
|
|
305
|
+
setTip({ x: mirror ? p.x - 18 : p.x + 18, y: p.y - 8, num: idx + 1, time: u.time !== null ? hhmm(u.time) : '', text: u.summary, mirror })
|
|
306
|
+
})
|
|
307
|
+
}
|
|
308
|
+
const handlePointerLeave = (): void => {
|
|
309
|
+
if (moveRafRef.current !== 0) { cancelAnimationFrame(moveRafRef.current); moveRafRef.current = 0 }
|
|
310
|
+
moveLastRef.current = null
|
|
311
|
+
setHover(null); setTip(null)
|
|
312
|
+
}
|
|
313
|
+
const handlePointerDown = (ev: React.PointerEvent<HTMLCanvasElement>): void => {
|
|
314
|
+
try { ev.currentTarget.setPointerCapture(ev.pointerId) } catch { /* ignore */ }
|
|
315
|
+
}
|
|
316
|
+
const handlePointerUp = (ev: React.PointerEvent<HTMLCanvasElement>): void => {
|
|
317
|
+
const canvas = canvasRef.current
|
|
318
|
+
if (canvas !== null) {
|
|
319
|
+
const rect = canvas.getBoundingClientRect()
|
|
320
|
+
const localY = ev.clientY - rect.top
|
|
321
|
+
if (inCap(localY)) void loadOlder()
|
|
322
|
+
else jumpTo(indexAt(localY))
|
|
323
|
+
}
|
|
324
|
+
try { ev.currentTarget.releasePointerCapture(ev.pointerId) } catch { /* ignore */ }
|
|
325
|
+
setHover(null)
|
|
326
|
+
setTip(null)
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const redraw = (): void => {
|
|
330
|
+
const canvas = canvasRef.current
|
|
331
|
+
if (canvas === null) return
|
|
332
|
+
const n = turns.length
|
|
333
|
+
if (n === 0 && capOffset === 0) return
|
|
334
|
+
const H = marksHeight() + capOffset
|
|
335
|
+
const W = NAV_RAIL_WIDTH - 8
|
|
336
|
+
const dpr = window.devicePixelRatio || 1
|
|
337
|
+
if (canvas.width !== Math.round(W * dpr) || canvas.height !== Math.round(H * dpr)) {
|
|
338
|
+
canvas.width = Math.round(W * dpr)
|
|
339
|
+
canvas.height = Math.round(H * dpr)
|
|
340
|
+
canvas.style.width = W + 'px'
|
|
341
|
+
canvas.style.height = H + 'px'
|
|
342
|
+
}
|
|
343
|
+
const ctx = canvas.getContext('2d')
|
|
344
|
+
if (ctx === null) return
|
|
345
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0)
|
|
346
|
+
ctx.clearRect(0, 0, W, H)
|
|
347
|
+
const cs = getComputedStyle(document.documentElement)
|
|
348
|
+
// 配色由 colors.ts 的 applyNavColors 统一写入变量(auto/调色盘解析都在那里),这里只读
|
|
349
|
+
const barColor = cs.getPropertyValue('--tidychat-nav-color').trim() || cs.getPropertyValue('--dsw-alias-label-caption').trim() || 'rgba(127,127,127,0.5)'
|
|
350
|
+
const hotColor = cs.getPropertyValue('--tidychat-nav-color-hot').trim() || cs.getPropertyValue('--dsw-alias-state-business-primary').trim() || '#3b82f6'
|
|
351
|
+
const mirror = side === 'right'
|
|
352
|
+
const dot = railStyle === 'dot'
|
|
353
|
+
const dir = mirror ? -1 : 1
|
|
354
|
+
const positions = positionsAt(hover)
|
|
355
|
+
const nearest = (i: number): boolean => hover !== null && hover >= 0 && Math.abs(i - hover) <= 2
|
|
356
|
+
const boxOf = (i: number, y: number, isCurrent: boolean, isHover: boolean): { x: number; y: number; w: number; h: number; dot: boolean } => {
|
|
357
|
+
if (dot) {
|
|
358
|
+
const rad = isCurrent || isHover ? 4 : (nearest(i) ? 3.2 : 2.5)
|
|
359
|
+
const cx = mirror ? W - NAV_RAIL_BAR_LEN / 2 : NAV_RAIL_BAR_LEN / 2
|
|
360
|
+
return { x: cx - rad, y: y - rad, w: rad * 2, h: rad * 2, dot: true }
|
|
361
|
+
}
|
|
362
|
+
const len = isHover ? NAV_RAIL_BAR_LEN_NEAR : (isCurrent ? NAV_RAIL_BAR_LEN_CURRENT : (nearest(i) ? NAV_RAIL_BAR_LEN + 4 : NAV_RAIL_BAR_LEN))
|
|
363
|
+
return { x: mirror ? W - len : 0, y: y - NAV_RAIL_BAR_H / 2, w: len, h: NAV_RAIL_BAR_H, dot: false }
|
|
364
|
+
}
|
|
365
|
+
// 外圈(navRing):白色柔光垫底,先光晕后标记
|
|
366
|
+
if (ring) {
|
|
367
|
+
ctx.save()
|
|
368
|
+
ctx.fillStyle = 'rgba(255,255,255,1)'
|
|
369
|
+
ctx.shadowColor = 'rgba(255,255,255,.9)'
|
|
370
|
+
ctx.shadowBlur = NAV_RAIL_RING_BLUR
|
|
371
|
+
for (let i = 0; i < n; i++) {
|
|
372
|
+
const isCurrent = current === i
|
|
373
|
+
const isHover = hover === i
|
|
374
|
+
if (!isCurrent && !isHover) continue
|
|
375
|
+
ctx.globalAlpha = isCurrent ? NAV_RAIL_RING_ALPHA_CURRENT : NAV_RAIL_RING_ALPHA_HOVER
|
|
376
|
+
const b = boxOf(i, positions[i], isCurrent, isHover)
|
|
377
|
+
if (b.dot) {
|
|
378
|
+
ctx.beginPath()
|
|
379
|
+
ctx.arc(b.x + b.w / 2, b.y + b.h / 2, b.w / 2 + NAV_RAIL_RING_OFFSET, 0, Math.PI * 2)
|
|
380
|
+
ctx.fill()
|
|
381
|
+
} else {
|
|
382
|
+
roundRectPath(ctx, b.x - NAV_RAIL_RING_OFFSET, b.y - NAV_RAIL_RING_OFFSET, b.w + NAV_RAIL_RING_OFFSET * 2, b.h + NAV_RAIL_RING_OFFSET * 2, b.h / 2 + NAV_RAIL_RING_OFFSET)
|
|
383
|
+
ctx.fill()
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
ctx.restore()
|
|
387
|
+
}
|
|
388
|
+
for (let i = 0; i < n; i++) {
|
|
389
|
+
const y = positions[i]
|
|
390
|
+
const isCurrent = current === i
|
|
391
|
+
const isHover = hover === i
|
|
392
|
+
const color = isCurrent || isHover ? hotColor : barColor
|
|
393
|
+
ctx.fillStyle = color
|
|
394
|
+
if (dot) {
|
|
395
|
+
const rad = isCurrent || isHover ? 4 : (nearest(i) ? 3.2 : 2.5)
|
|
396
|
+
const cx = mirror ? W - NAV_RAIL_BAR_LEN / 2 : NAV_RAIL_BAR_LEN / 2
|
|
397
|
+
ctx.beginPath()
|
|
398
|
+
ctx.arc(cx, y, rad, 0, Math.PI * 2)
|
|
399
|
+
ctx.fill()
|
|
400
|
+
} else {
|
|
401
|
+
const len = isHover ? NAV_RAIL_BAR_LEN_NEAR : (isCurrent ? NAV_RAIL_BAR_LEN_CURRENT : (nearest(i) ? NAV_RAIL_BAR_LEN + 4 : NAV_RAIL_BAR_LEN))
|
|
402
|
+
ctx.fillRect(mirror ? W - len : 0, y - NAV_RAIL_BAR_H / 2, len, NAV_RAIL_BAR_H)
|
|
403
|
+
if (isCurrent) {
|
|
404
|
+
const headX = mirror ? W - len - 2 : len + 2
|
|
405
|
+
ctx.beginPath()
|
|
406
|
+
ctx.moveTo(headX, y)
|
|
407
|
+
ctx.lineTo(headX + dir * 4, y - 3)
|
|
408
|
+
ctx.lineTo(headX + dir * 4, y + 3)
|
|
409
|
+
ctx.closePath()
|
|
410
|
+
ctx.fill()
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
// 顶部「更早历史未加载」提示带
|
|
415
|
+
if (capOffset > 0) {
|
|
416
|
+
const capColor = hover === NAV_RAIL_CAP_INDEX ? hotColor : barColor
|
|
417
|
+
const cx = mirror ? W - NAV_RAIL_BAR_LEN / 2 : NAV_RAIL_BAR_LEN / 2
|
|
418
|
+
const cy = NAV_RAIL_CAP_H / 2
|
|
419
|
+
ctx.strokeStyle = capColor
|
|
420
|
+
ctx.fillStyle = capColor
|
|
421
|
+
ctx.lineWidth = 1.5
|
|
422
|
+
ctx.lineCap = 'round'
|
|
423
|
+
ctx.beginPath()
|
|
424
|
+
ctx.moveTo(cx - 3.5, cy + 1.5)
|
|
425
|
+
ctx.lineTo(cx, cy - 2)
|
|
426
|
+
ctx.lineTo(cx + 3.5, cy + 1.5)
|
|
427
|
+
ctx.stroke()
|
|
428
|
+
ctx.lineWidth = 1
|
|
429
|
+
ctx.setLineDash([2, 3])
|
|
430
|
+
ctx.beginPath()
|
|
431
|
+
ctx.moveTo(cx, cy + 4)
|
|
432
|
+
if (positions.length > 0) ctx.lineTo(cx, Math.max(cy + 4, positions[0]! - 4))
|
|
433
|
+
ctx.stroke()
|
|
434
|
+
ctx.setLineDash([])
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// 度量 + 重排:侧别/开关/样式变化、窗口与容器尺寸变化、滚动
|
|
439
|
+
React.useEffect(() => {
|
|
440
|
+
const refresh = (): void => { setPos(measurePos(side)) }
|
|
441
|
+
refresh()
|
|
442
|
+
let resizeObs: ResizeObserver | null = null
|
|
443
|
+
const container = findScrollContainer()
|
|
444
|
+
if (container !== null && typeof ResizeObserver !== 'undefined') {
|
|
445
|
+
resizeObs = new ResizeObserver(() => { refresh() })
|
|
446
|
+
resizeObs.observe(container)
|
|
447
|
+
}
|
|
448
|
+
window.addEventListener('resize', refresh)
|
|
449
|
+
let scrollRaf = 0
|
|
450
|
+
const onScroll = (): void => {
|
|
451
|
+
if (scrollRaf !== 0) return
|
|
452
|
+
scrollRaf = requestAnimationFrame(() => {
|
|
453
|
+
scrollRaf = 0
|
|
454
|
+
const c = findScrollContainer()
|
|
455
|
+
if (c !== null && c.scrollHeight !== rowCacheRef.current.scrollH) rebuildRowCache(turns.length, c.scrollHeight)
|
|
456
|
+
detectCurrent()
|
|
457
|
+
})
|
|
458
|
+
}
|
|
459
|
+
if (container !== null) container.addEventListener('scroll', onScroll, { passive: true })
|
|
460
|
+
const onUserTakeOver = (): void => cancelScrollAnim()
|
|
461
|
+
if (container !== null) {
|
|
462
|
+
container.addEventListener('wheel', onUserTakeOver, { passive: true })
|
|
463
|
+
container.addEventListener('touchstart', onUserTakeOver, { passive: true })
|
|
464
|
+
}
|
|
465
|
+
window.addEventListener('keydown', onUserTakeOver)
|
|
466
|
+
return () => {
|
|
467
|
+
resizeObs?.disconnect()
|
|
468
|
+
window.removeEventListener('resize', refresh)
|
|
469
|
+
if (container !== null) {
|
|
470
|
+
container.removeEventListener('scroll', onScroll)
|
|
471
|
+
container.removeEventListener('wheel', onUserTakeOver)
|
|
472
|
+
container.removeEventListener('touchstart', onUserTakeOver)
|
|
473
|
+
}
|
|
474
|
+
window.removeEventListener('keydown', onUserTakeOver)
|
|
475
|
+
cancelScrollAnim()
|
|
476
|
+
if (scrollRaf !== 0) cancelAnimationFrame(scrollRaf)
|
|
477
|
+
if (moveRafRef.current !== 0) cancelAnimationFrame(moveRafRef.current)
|
|
478
|
+
}
|
|
479
|
+
}, [side])
|
|
480
|
+
|
|
481
|
+
if (!enabled) return null
|
|
482
|
+
if (pos === null) return null
|
|
483
|
+
if (pos.gutter < NAV_RAIL_WIDTH) return null
|
|
484
|
+
if (turns.length === 0 && !hasMore) return null
|
|
485
|
+
const railEl = React.createElement('div', {
|
|
486
|
+
className: 'tidychat-nav-rail',
|
|
487
|
+
style: { transform: 'translateY(-50%)', left: pos.left + 'px', top: pos.top + 'px' },
|
|
488
|
+
'aria-label': '用户消息定位',
|
|
489
|
+
}, React.createElement('canvas', {
|
|
490
|
+
ref: canvasRef,
|
|
491
|
+
className: 'tidychat-nav-canvas',
|
|
492
|
+
onPointerMove: handlePointerMove,
|
|
493
|
+
onPointerLeave: handlePointerLeave,
|
|
494
|
+
onPointerDown: handlePointerDown,
|
|
495
|
+
onPointerUp: handlePointerUp,
|
|
496
|
+
}))
|
|
497
|
+
const tipEl = tip === null ? null : React.createElement('div', {
|
|
498
|
+
className: 'tidychat-nav-tip',
|
|
499
|
+
style: tip.mirror
|
|
500
|
+
? { right: Math.max(0, window.innerWidth - tip.x) + 'px', top: tip.y + 'px' }
|
|
501
|
+
: { left: tip.x + 'px', top: tip.y + 'px' },
|
|
502
|
+
},
|
|
503
|
+
React.createElement('div', { className: 'tidychat-nav-tip-head' },
|
|
504
|
+
tip.head !== undefined && tip.head !== null ? tip.head : '#' + (tip.num ?? '?') + (tip.time !== '' ? ' · ' + tip.time : '')),
|
|
505
|
+
React.createElement('div', null, tip.text),
|
|
506
|
+
)
|
|
507
|
+
return React.createElement(React.Fragment, null, railEl, tipEl)
|
|
508
|
+
}
|