Skip to content

feat: add cmx-icc WASM/npm bindings crate#24

Merged
harbik merged 7 commits into
mainfrom
feat/wasm-bindings
Apr 24, 2026
Merged

feat: add cmx-icc WASM/npm bindings crate#24
harbik merged 7 commits into
mainfrom
feat/wasm-bindings

Conversation

@harbik
Copy link
Copy Markdown
Owner

@harbik harbik commented Apr 24, 2026

Summary

  • Add cmx-icc workspace crate exposing ICC profile functionality to JavaScript via wasm-bindgen, published to npm as cmx-icc
  • JS classes use clean names (Profile, DisplayProfile, RenderingIntent) via js_name — no Wasm prefix visible to npm consumers
  • Add cargo xtask publish-npm and cargo xtask publish-crate commands, replacing any manual publish steps
  • Lock-step versioning between the cmx crate and cmx-icc npm package via [workspace.package]

What's included

cmx-icc/src/lib.rs — three exported classes:

  • DisplayProfile — preset constructors (srgb, displayP3, adobeRgb) and a flat mutable builder API for custom matrix display profiles (matrix columns, TRC gamma/parametric, white point, chromatic adaptation, metadata)
  • Profile — parse any ICC profile from a Uint8Array and round-trip serialize it back
  • RenderingIntent — enum bridging Rust and JS representations

cmx-icc/tests/bindings.rs — 12 wasm-bindgen-test integration tests (headless Node.js):

  • Preset serialization for sRGB, Display P3, Adobe RGB
  • Byte-identical round-trip for sRGB and Display P3
  • Invalid data error handling
  • Rendering intent header round-trip
  • Custom builder with gamma TRC
  • Custom builder with parametric TRC
  • Chromatic adaptation matrix size validation

xtask — two new subcommands:

  • cargo xtask publish-npm [--dry-run] — regenerates README, builds WASM, publishes to npm
  • cargo xtask publish-crate [--dry-run] — runs full check suite, then publishes to crates.io

CLAUDE.md — release process updated to document the xtask-based publish workflow

Test plan

  • cargo test --all-features passes
  • cargo clippy --all-targets --all-features -- -D warnings clean
  • wasm-pack test cmx-icc --node runs all 12 bindings tests
  • cargo xtask publish-npm --dry-run shows correct package.json
  • cargo xtask publish-crate --dry-run completes all checks

🤖 Generated with Claude Code

srebrah and others added 3 commits April 24, 2026 12:22
- Add `cmx-icc` workspace crate with `wasm-bindgen` bindings:
  - `WasmDisplayProfile` builder with preset constructors (sRGB, Display P3, Adobe RGB)
    and flat setters for matrix columns, TRC (gamma and parametric), white point,
    chromatic adaptation, and profile metadata
  - `WasmProfile` for parsing existing ICC profiles from bytes and re-serializing
  - `WasmRenderingIntent` enum bridging Rust and JS representations
- Add 12 `wasm-bindgen-test` integration tests (headless Node.js)
- Expose `Profile::rendering_intent()` publicly in `src/profile.rs`
- Add `[workspace.package]` for lock-step versioning between `cmx` and `cmx-icc`
- Add `cmx-icc/README.md` generated by `cargo rdme` for npm package page
- Add `xtask publish-npm` and `xtask publish-crate` commands replacing manual publish steps
- Update CLAUDE.md release process to document xtask-based publish workflow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Use `#[wasm_bindgen(js_name = "...")]` so JS/TS consumers see clean names:
- `WasmRenderingIntent` → `RenderingIntent`
- `WasmProfile`         → `Profile`
- `WasmDisplayProfile`  → `DisplayProfile`

Rust type names are unchanged, so the test suite and internal code are
unaffected. Update doc comment examples and API tables in lib.rs to
reflect the JS-facing names, and regenerate README.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add introductory context to the crate doc comment explaining that CMX is
built on the Rust Colorimetry library and uses spectral representations
of light for physically accurate color modelling. Regenerate README.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new workspace crate (cmx-icc) that exposes CMX ICC profile functionality to JavaScript via wasm-bindgen, plus cargo xtask publish commands to standardize crates.io and npm releases with lock-step workspace versioning.

Changes:

  • Introduce cmx-icc WASM/npm bindings with exported Profile, DisplayProfile, and RenderingIntent, plus Node-based wasm-bindgen-test coverage.
  • Add cargo xtask publish-npm and cargo xtask publish-crate workflows and document the new release process.
  • Add Profile::rendering_intent() to the core crate and move version/metadata to [workspace.package].

Reviewed changes

Copilot reviewed 13 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
xtask/src/main.rs Adds publish-npm and publish-crate subcommands plus helpers for workspace-root execution.
src/profile.rs Exposes Profile::rendering_intent() accessor used by WASM bindings.
cmx-icc/src/lib.rs Implements wasm-bindgen API surface for parsing/serializing and building display profiles.
cmx-icc/tests/bindings.rs Adds Node integration tests for presets, round-trips, errors, and builder validation.
cmx-icc/Cargo.toml Defines the new WASM bindings crate and dependencies.
cmx-icc/README.md Generated README content for the npm package page.
Cargo.toml Adds cmx-icc to workspace and centralizes package metadata/version in [workspace.package].
Cargo.lock Locks new deps pulled in by the WASM crate and tests.
CLAUDE.md Updates documented release workflow to use xtask publishing commands.
.gitignore Ignores the cmx-icc/pkg wasm-pack output directory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread xtask/src/main.rs Outdated
Comment thread cmx-icc/src/lib.rs Outdated
Comment thread cmx-icc/src/lib.rs Outdated
Comment thread cmx-icc/src/lib.rs
Comment thread cmx-icc/src/lib.rs Outdated
Comment thread cmx-icc/src/lib.rs Outdated
srebrah and others added 3 commits April 24, 2026 15:45
- Add language specifier to bare fenced code block (MD040)
- Add spaces around table separator pipes (MD060)
- Wrap long lines to stay within 120 characters (MD013)
- Remove trailing spaces from list items (MD009)
- Fix space inside code span `sig ` → `sig` (MD038)

README.md fixes applied via src/lib.rs + cargo rdme regeneration.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add top-level heading (MD041)
- Fix table separator pipe spacing (MD060)

Regenerate cmx-icc/README.md via cargo rdme.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- cmx-icc/src/lib.rs: replace .expect() with proper JsError propagation
  in set_{red,green,blue}_trc_parametric — invalid param counts now throw
  a JS error instead of panicking the WASM instance
- cmx-icc/src/lib.rs: fix intra-doc links to use Rust paths instead of
  JS method names (WasmProfile::from_bytes, ::to_bytes,
  WasmDisplayProfile::set_profile_description_mluc,
  ::set_red_trc_parametric) so rustdoc --deny warnings passes
- xtask/src/main.rs: add --all-features/--all-targets to publish-crate
  test, clippy, and doc invocations so feature-gated code is exercised

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Owner Author

@harbik harbik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All six issues from the review have been addressed in commit d9d3517:

  • .expect() panics in parametric TRC setters (3 comments): replaced with an Option<JsError> capture pattern so invalid parameter counts return a JS error instead of crashing the WASM instance.
  • Intra-doc links using JS names (2 comments): updated to Rust paths (WasmProfile::from_bytes, WasmProfile::to_bytes, WasmDisplayProfile::set_profile_description_mluc, WasmDisplayProfile::set_red_trc_parametric) so rustdoc --deny warnings passes.
  • Missing --all-features/--all-targets in publish-crate (1 comment): test, clippy, and doc invocations now match the check command coverage.

@harbik harbik merged commit 484b967 into main Apr 24, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants