colorinput

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

ColorInput v1

This package owns nb1's bounded, flat JSON color grammar described in the API v1 color contract. It accepts a bare ColorInput or an explicit {"color": ...} envelope, rejects duplicate and unknown fields, and does not read configuration, devices, environment variables, or files.

CSS names and Hex literals are parsed by github.com/b1ug/colorkit. HSV objects pass the original json.Number.String() tokens directly to colorkit.FromHSVDecimal; they never pass through floating point. The shared core validates decimal syntax and ranges, computes exact rational HSV, and rounds half up once to opaque 8-bit RGB. This package applies no Gamma, brightness adjustment, or optical calibration.

The result adapter preserves the existing schema version, contract, input_kind, canonical lowercase Hex, and css-named-2026 palette marker. The local RGB8 DTO intentionally remains an integer {r,g,b} JSON object; aliasing it to colorkit.RGB8 would change JSON to a Hex string. HTTP, CLI, MCP, and Sequence callers share this boundary rather than duplicating color conversion. String inputs remain limited to CSS names and #rgb/#rrggbb; function syntax is not part of this JSON grammar.

ValidateResult checks known schema/contract/input kinds, canonical Hex/RGB agreement, and palette rules. It does not prove which original input a remote resolver received. Wire callers must still reject unknown, duplicate, null, or missing fields. The full input remains limited to 4096 bytes and color strings to 64 decoded bytes before trimming.

testdata/css-named-2026.tsv is the unchanged independent fixture for all 148 opaque CSS names and aliases, excluding transparent, currentColor, and system colors. Its source is the W3C CSS Color 4 draft from November 3, 2026: HTML SHA-256 b66ad2af540a7550fd34e0d95f8dce3f49b9d39e255fdfed56f0ec1de9c78000, sorted TSV SHA-256 521686f82ac6c649de3f22589783ac86e2bfeb0c1858fd953f59efc4e1d2fd09. Tests compare every name, value, spelling, and alias through this package's public resolver. The 37 unchanged HSV goldens were independently generated with Python Fraction using C/X/m, covering all six sectors, 0/360 degrees, exact half values, and adjacent six-place decimals. Tests also cover strict JSON/numeric syntax, input limits, result validation, and concurrent use.

Documentation

Overview

Package colorinput resolves a bounded, versioned color grammar to raw RGB. It performs no I/O, device discovery, gamma correction or light control.

Index

Constants

View Source
const (
	Contract        = "nb1-color-input/v1"
	Palette         = "css-named-2026"
	MaxRequestBytes = 4096
)

Variables

This section is empty.

Functions

func ValidateResult

func ValidateResult(r Result) error

ValidateResult checks the versioned result's structure and canonical RGB. It is not a proof that a remote resolver received or honored an input.

Types

type RGB8

type RGB8 struct {
	R int `json:"r"`
	G int `json:"g"`
	B int `json:"b"`
}

type Result

type Result struct {
	SchemaVersion  int    `json:"schema_version"`
	ColorContract  string `json:"color_contract"`
	InputKind      string `json:"input_kind"`
	CanonicalColor string `json:"canonical_color"`
	RGB8           RGB8   `json:"rgb8"`
	Palette        string `json:"palette,omitempty"`
}

func ResolveJSON

func ResolveJSON(data []byte) (Result, error)

ResolveJSON accepts one bare ColorInput, not an HTTP envelope.

func ResolveRequestJSON

func ResolveRequestJSON(data []byte) (Result, error)

ResolveRequestJSON accepts exactly {"color": ColorInput}.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL