One Vue 3 Component Handles Solid Colors, Gradients, and Canvas Eyedropper Picking
Design tools, low-code builders, and data visualization dashboards frequently need color picking beyond the native input, and this library collapses three separate libraries and their state management into one coherent package. Its screenshot-based eyedropper and multi-user history isolation solve real integration pain points that Western developers building similar web apps often hit.
The library, @you-want/color-picker-lib, ships three components: ColorPicker for solid and gradient palettes, EyeDropper for screenshot-based canvas sampling, and SliderColorSetting for gradient stop editing. It avoids the browser's native EyeDropper API by using snapdom to capture the target area and sample through Canvas, making it work wherever Canvas is available.
The package separates overall transparency from per-stop alpha to prevent data pollution, always writes back new array references for gradient stops to satisfy canvas redraw triggers like Konva, and provides a session-commit event that fires only once per edit session. It supports themeing via five CSS variables, requires only Vue 3.5+ and Element Plus 2.6+, and comes with 196 automated tests covering parsing, coordinates, SSR, and keyboard interaction.
The build is 71.81 kB JS (20.92 kB gzip) plus 12.80 kB CSS (3.62 kB gzip), excluding Element Plus. Known gaps include no support for var(), calc(), radial gradients, or CSS Color 4 spaces, and real-browser verification is currently Chrome-centric.
The screenshot-based eyedropper is a deliberate workaround for native API availability, trading a dependency on snapdom for broader reach across browsers and environments.
Separating raw color from effective color prevents a common bug where users accidentally multiply alpha twice and end up with faded colors in design tools.
The library's decision to force new array references for gradient stops is a pragmatic fix for canvas redraw mechanisms, but it imposes a specific update pattern on host code.
By requiring Element Plus as a peer dependency, the library leverages existing UI infrastructure but limits adoption in projects that don't already use Element Plus.
The explicit list of unsupported color formats (var(), calc(), radial gradients) is a refreshingly honest contract; it prevents silent misinterpretation of CSS values.