Repository navigation
Conversation
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.
Motivation
Ondine's SVG reads every color, the stroke width, the radius, and the font from CSS custom properties, and chart series mix colors with
color-mix(). Renderers without CSS variables draw such an SVG black or not at all: resvg, librsvg, the SVG parsers of native apps, and email clients. Each host now flattens the SVG with its own string pass.Changes
themerender option: an object of--ondine-*values in camel case (bg,fg,surfaceAlt,series1,radius, and so on). An empty object writes the defaults.crates/compiler/src/svg/resolve.rs, a final pass that replaces eachvar()in attributes with the host value, the root alias, or its fallback, and drops custom-property declarations. Text content is not changed.color-mix(in srgb, …)to#rrggbbor#rrggbbaa(premultiplied, CSS Color 5 percentage rules). A mix reads hex,transparent, the 148 CSS named colors (sorted table, binary search), andrgb()orrgba()with comma or space syntax and an optional alpha.hsl()oroklch(),renderthrows aRenderErrorwith the new codeunsupportedthat names the key. Unmixed values, such asborder: 'hsl(…)', are written as given.themeCargo feature oncompiler, forwarded bywasm. Onlyall.fast.generated.wasm(ondine/compiler, the CLI, andondine/compiler/wasm/all.fast.wasm) and native builds enable it. The size-optimized per-type andallmodules leave it out and returnunsupportedfortheme.allmodule and its own flattening, since it must fit beside resvg under the 3 MB Worker limit. A later change can move it tothemeif that budget allows.rxattribute whenthemeis set. Withouttheme, the output is byte-identical.unsupportedcode on therender,create, andRenderErrorAPI pages and in the theming guide.Example
Validation
cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warnings(also wasm32 withflowchartonly andall,theme),cargo test --workspace,pnpm build:wasm,pnpm vp test --run --project node(808 passed),pnpm check, andpnpm check:types. On this machine both builds use the stable toolchain (the pinned nightly has norust-src). Against the base commit, per-type modules are 14 to 46 B smaller raw and 6 to 150 B larger gzip (flowchart +30 B, pie +35 B). They are not byte-identical, because of theunsupportederror path.all.fast.wasmgrows 27,341 B raw and 10,365 B gzip (1,265,581 to 1,275,946 B).