Simple TypeScript + React utility that detects the computed character color (the CSS color
property) in an element, checking for mouse and focus events across all parents.
This is useful for icons that adapt to light and dark themes.
import { ColorObserver } from "@hydroper/colorobserver"; import { useEffect, useRef } from "react"; import Color from "color"; const myRef = useRef(null); useEffect(() => { const colorObserver = new ColorObserver(myRef.current, (color: Color) => { console.log("light =", color.isLight()); }); return () => { colorObserver.cleanup(); }; });
Add Package
deno add jsr:@hydroper/colorobserver
Import symbol
import * as colorobserver from "@hydroper/colorobserver";
---- OR ----
Import directly with a jsr specifier
import * as colorobserver from "jsr:@hydroper/colorobserver";
Add Package
npx jsr add @hydroper/colorobserver
Import symbol
import * as colorobserver from "@hydroper/colorobserver";
Add Package
yarn dlx jsr add @hydroper/colorobserver
Import symbol
import * as colorobserver from "@hydroper/colorobserver";
Add Package
pnpm dlx jsr add @hydroper/colorobserver
Import symbol
import * as colorobserver from "@hydroper/colorobserver";
Add Package
bunx jsr add @hydroper/colorobserver
Import symbol
import * as colorobserver from "@hydroper/colorobserver";