API
@pbroom/color-kit/plane
Define 2D color planes and query their gamut and contrast regions, boundaries and paths.
94 exports41 values53 types
@pbroom/color-kit/plane turns color questions into geometry. A plane fixes every
channel of a color model but two and maps those two to normalized x and
y. Queries against it return points and paths you can draw, hit-test or
cache. It powers the React plane hooks' overlays, but nothing in it depends
on a UI.
Domains
- Definition and mapping.
definePlaneanddefinePlaneFromColorresolve axes, ranges and fixed channels foroklch,oklab,rgb,hsl,hsv,hctordisplay-p3.planeToColorandcolorToPlaneproject between the two.planeHuereports a plane's hue in OKLCH, converting the fixed color onhsl,hsvandhctplanes. - Queries.
sensebindsgamutRegion,gamutBoundary,contrastRegion,contrastBoundary,chromaBand,fallbackPointandgradientto a plane;runPlaneQueryandrunPlaneQueriestake the same queries as data. - Output and caching.
toSvgPathandtoSvgCompoundPathwrite SVG path data;PlaneQueryCachememoizes results. - Regions.
containsPointandnearestPointOnPathtest geometry;unionRegions,intersectRegionsanddifferenceRegionscombine regions on a raster, so their edges are approximate; transforms move regions within and between planes. - Tracing.
inspectPlaneQueryreturns a result with the solver's trace.
import { parse } from '@pbroom/color-kit';
import {
colorToPlane,
containsPoint,
definePlane,
sense,
} from '@pbroom/color-kit/plane';
const plane = definePlane({ fixed: { h: 290 } }); // OKLCH lightness × chroma
const srgb = sense(plane).gamutRegion({ gamut: 'srgb' });
const brand = parse('oklch(0.62 0.24 290)');
colorToPlane(plane, brand); // → { x: 0.62, y: ≈ 0.4 }
containsPoint(srgb.visibleRegion, colorToPlane(plane, brand)); // → falseSee Planes and queries for the model.
Gamut
Mapping
- function
colorToPlaneProjects a color onto a plane, returning its normalized coordinates. - function
planeHueResolves the OKLCH hue angle a plane query runs at. - function
planeToColorConverts a normalized plane point into the color it represents. - function
usesLightnessAndChromaReturns whether a plane is an OKLCH lightness × chroma plane (axes l/c in either order). - function
projectRegionBetweenPlanesRe-expresses a region drawn on one plane in the coordinates of another. - function
rotateRegionReturns a copy of a region rotated by angleDeg degrees about origin. - function
scaleRegionReturns a copy of a region scaled by (sx, sy) about origin. - function
translateRegionReturns a copy of a region with every point shifted by (dx, dy).
Compile
- function
definePlaneDefines a 2D color plane: two channels of one color model mapped onto normalized x/y coordinates, with every other channel held fixed. - function
definePlaneFromColorDefines a plane whose fixed channels are taken from an anchor color. - function
resolvePlaneDefinitionResolves a dynamic PlaneDefinition into a fully-specified Plane. - function
createPlaneQueryKeyCreates a deterministic cache key for a plane/query pair. - class
PlaneQueryCacheLRU cache of plane query results, keyed by createPlaneQueryKey. - function
runCachedPlaneQueryReturns the cached result for a plane/query pair, or runs execute and caches what it returns. - function
toSvgCompoundPathCompiles several point lists into one compound SVG path d string. - function
toSvgPathCompiles an ordered list of plane points into an SVG path d string. - interface
PlaneQueryCacheOptionsOptions for the PlaneQueryCache constructor. - interface
SvgPathCompileOptionsFormatting options for toSvgPath and toSvgCompoundPath.
Models
- function
planeModelChannelsReturns the channels a plane model accepts on its axes and in fixed. - function
planeModelDefaultRangeReturns the default axis range definePlane() uses for a channel of a model. - const
PLANE_MODEL_CHANNELSChannel sets supported by each plane model. - const
PLANE_MODEL_DEFAULT_AXESDefault x/y axis channels for each plane model. - const
PLANE_MODEL_DEFAULT_RANGESDefault axis ranges for each model's channels.
Queries
- function
colorAtPlanePointReturns the color at a normalized point of a plane definition. - function
getPlaneChromaBandSamples a constant-intent chroma band across lightness at one hue and projects it onto the plane. - function
getPlaneContrastBoundaryTraces where colors at one hue cross a contrast threshold against a reference color, projected onto the plane. - function
getPlaneContrastRegionTraces the contour lines that bound the colors of one hue meeting a contrast threshold against a reference color, projected onto the plane. - function
getPlaneFallbackPointGamut-maps a color into the target gamut and returns where the mapped color lands on the plane. - function
getPlaneGamutBoundaryTraces the gamut's maximum-chroma edge at one hue and projects it onto the plane. - function
getPlaneGamutRegionComputes the in-gamut area of a plane: the visible region to fill and the gamut boundary lines to stroke. - function
inspectPlaneQueriesRuns several plane queries in order, returning a result and trace for each. - function
inspectPlaneQueryRuns one plane query and also returns a trace of how it was solved. - function
runPlaneQueriesRuns several plane queries against one plane, in order. - function
runPlaneQueryRuns one plane query, dispatching on query.kind. - function
samplePlaneGradientSamples a two-color gradient and projects each sample onto the plane. - function
senseBinds a plane to a set of query helpers, so queries read as sense(plane).gamutRegion(). - interface
PlaneSenseQuery helpers bound to one plane, returned by sense.
Operations
- function
containsPointReturns whether a point lies inside a region, using the even-odd fill rule. - function
differenceRegionsReturns the area of a that is not covered by b (a − b). - function
intersectRegionsReturns the area covered by both regions (a ∩ b). - function
nearestPointOnPathReturns the point on a polyline closest to point. - function
pointDistanceReturns the Euclidean distance between two plane points. - function
unionRegionsReturns the area covered by either region (a ∪ b). - interface
PlaneBooleanOptionsOptions for the raster-based region booleans (unionRegions, intersectRegions, differenceRegions).
Types
- type
PlaneResolved plane returned by definePlane; the input to every plane query and projection. - interface
PlaneAxisAxis descriptor used in definePlane() input. - interface
PlaneBoundaryPointA plane point on a gamut boundary or chroma band, with its OKLCH values. - type
PlaneChannelForChannel identifiers supported by a specific plane model. - interface
PlaneChromaBandQueryQuery for getPlaneChromaBand. - interface
PlaneChromaBandResultResult of getPlaneChromaBand. - interface
PlaneColorPointA plane point carrying the color it represents. - type
PlaneContrastBoundaryQueryQuery for getPlaneContrastBoundary. - interface
PlaneContrastBoundaryResultResult of getPlaneContrastBoundary. - type
PlaneContrastRegionQueryQuery for getPlaneContrastRegion. - interface
PlaneContrastRegionResultResult of getPlaneContrastRegion. - interface
PlaneDefinitionInput shape accepted by definePlane(). - type
PlaneDefinitionForModel-aware definePlane() input. - type
PlaneFixedInputPartial channel bag used for model-relative fixed values. - interface
PlaneFallbackPointQueryQuery for getPlaneFallbackPoint. - interface
PlaneFallbackPointResultResult of getPlaneFallbackPoint. - interface
PlaneGamutBoundaryQueryQuery for getPlaneGamutBoundary. - interface
PlaneGamutBoundaryResultResult of getPlaneGamutBoundary. - interface
PlaneGamutRegionQueryQuery for getPlaneGamutRegion. - interface
PlaneGamutRegionResultResult of getPlaneGamutRegion. - interface
PlaneGradientQueryQuery for samplePlaneGradient. - interface
PlaneGradientResultResult of samplePlaneGradient. - interface
PlaneQueryInspectionA query result paired with its solver trace, from inspectPlaneQuery. - type
PlaneModelColorResolved model-relative channel bag. - type
PlaneModelColor models supported by plane geometry. display-p3 is gamma-encoded Display P3, named after CSS color(display-p3 …). - interface
PlanePointNormalized 2D point in plane space. - type
PlaneQueryAny plane query accepted by runPlaneQuery, discriminated by kind. - type
PlaneQueryResultAny plane query result, discriminated by kind (matches the query's). - interface
PlaneRegionA filled area of a plane, as closed outlines. - interface
PlaneRegionPointA plane point on a contrast contour, with its OKLCH values. - interface
ResolvedPlaneAxisA plane axis with its range resolved. - interface
ResolvedPlaneDefinitionFully-resolved plane: model, both axes with explicit ranges, and every channel value.
Tracing
- type
PlaneGamutRegionScopeExtent of gamut-region boundary paths: 'viewport' clips them to the visible [0, 1] square; 'full' returns the whole gamut boundary, which may extend outside it. - type
PlaneContrastSolverContrast-region solver: luminance level curves traced along rays from black (see contrastRegionPaths). - type
PlaneGamutSolverStrategy a gamut-region query used, picked from the plane's model, axes and gamut: - interface
PlaneQueryTraceDiagnostic record of how a plane query was solved, returned by inspectPlaneQuery / inspectPlaneQueries and by compute requests that set trace. - interface
PlaneQueryTraceCellEventOne marching-squares cell that produced contour segments ('full' level). - type
PlaneQueryTraceLevelDetail captured by a query trace: 'summary' fills only PlaneQueryTraceSummary; 'stages' adds per-stage records with truncated paths; 'full' also adds marching-squares cell events and the sampled scalar grid. - interface
PlaneQueryTraceMarchingSquaresStageStage summarizing one marching-squares contouring pass. - interface
PlaneQueryTraceMetricsStageFinal stage: a copy of the summary counters when the query finished. - interface
PlaneQueryTraceOptionsOptions for inspectPlaneQuery / inspectPlaneQueries and compute trace requests. - interface
PlaneQueryTracePathStageStage recording a set of paths produced during a solve. - interface
PlaneQueryTraceScalarGridStageStage describing a sampled gamut scalar field (positive inside the gamut, zero on its boundary). - interface
PlaneQueryTraceSolverStageStage recording which solver a query picked. - type
PlaneQueryTraceStageAny stage record in PlaneQueryTrace.stages, discriminated by kind. - interface
PlaneQueryTraceSummaryAggregate counters and metadata for one traced plane query. - interface
PlaneQueryTraceViewportStageStage classifying the viewport against the gamut from the sampled field's extremes (positive values are in gamut). - interface
PlaneTraceBoundsAxis-aligned bounds in plane-normalized coordinates. - type
PlaneViewportRelationHow a gamut relates to the plane viewport (the [0, 1] square): 'inside' when the whole viewport is in gamut, 'outside' when none of it is, and 'intersects' when the gamut boundary crosses it.