feat: client-side export — toSvgString / toPng / downloadChart / copyToClipboard (#123)#131
Merged
Merged
Conversation
…ToClipboard (#123) Browser-side rasterisation and download helpers, plus an `svgRef` prop on `<Surface>` so consumers can grab the inner `<svg>` cleanly. - new src/render/clientExport.ts: toSvgString, toPng, downloadChart, copyToClipboard, chartSvgFrom (container helper), svgPixelSize - Surface accepts `svgRef?: Ref<SVGSVGElement>` and threads it to the inner <svg> - exported from goldenchart main entry; no new deps; tree-shakeable - no font embedding (matches what the user sees; for fully standalone SVGs use goldenchart/server's renderToSVGString) - pure helpers unit-tested (project convention: no jsdom — see InteractiveChart.test.ts) Bundle 50 KB gzipped (budget 75 KB). All 412 existing tests pass plus 10 new.
This was referenced May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/render/clientExport.tswith browser-side helpers:toSvgString,toPng,downloadChart,copyToClipboard, pluschartSvgFrom(find the inner<svg>from a container ref) andsvgPixelSize/extensionFor/mimeForutilities.<Surface>accepts ansvgRef?: Ref<SVGSVGElement>prop and threads it to the inner<svg>— gives consumers a clean handle without restructuring chart APIs.goldenchartentry. Tree-shakeable: no canvas/clipboard work unless the relevant helper is imported.goldenchart/serverrenderToSVGStringpath embeds@font-face.src/interactive/InteractiveChart.test.ts). The DOM-dependent paths (toPng,downloadChart,copyToClipboard) are integration-only.Verification
npm run typecheckcleannpm test— 412 existing tests pass + 10 newnpm run build && npm run check:bundle— browser entry 50 KB gzipped (budget 75 KB, up 2 KB from clientExport)Test plan
Closes #123.