@mkbabb/value.js 0.5.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -56
- package/dist/easing.d.ts +49 -0
- package/dist/index.d.ts +19 -8
- package/dist/math.d.ts +1 -1
- package/dist/parsing/animation-shorthand.d.ts +19 -0
- package/dist/parsing/color.d.ts +10 -3
- package/dist/parsing/extract.d.ts +48 -0
- package/dist/parsing/index.d.ts +5 -20
- package/dist/parsing/serialize.d.ts +24 -0
- package/dist/parsing/stylesheet.d.ts +44 -0
- package/dist/parsing/units.d.ts +24 -6
- package/dist/parsing/utils.d.ts +5 -0
- package/dist/postcss-CRluLK2m.js +6400 -0
- package/dist/quantize/cluster.d.ts +45 -0
- package/dist/quantize/index.d.ts +14 -0
- package/dist/quantize/types.d.ts +39 -0
- package/dist/standalone-Ck3UyY5I.js +3458 -0
- package/dist/units/color/constants.d.ts +21 -0
- package/dist/units/color/contrast.d.ts +35 -0
- package/dist/units/color/conversions/cylindrical.d.ts +13 -0
- package/dist/units/color/conversions/direct.d.ts +41 -0
- package/dist/units/color/conversions/hex.d.ts +3 -0
- package/dist/units/color/conversions/index.d.ts +17 -0
- package/dist/units/color/conversions/kelvin.d.ts +5 -0
- package/dist/units/color/conversions/lab.d.ts +8 -0
- package/dist/units/color/conversions/oklab.d.ts +11 -0
- package/dist/units/color/conversions/transfer.d.ts +22 -0
- package/dist/units/color/conversions/xyz-extended.d.ts +13 -0
- package/dist/units/color/dispatch.d.ts +26 -0
- package/dist/units/color/gamut.d.ts +6 -0
- package/dist/units/color/index.d.ts +220 -116
- package/dist/units/color/mix.d.ts +16 -0
- package/dist/units/color/normalize.d.ts +3 -3
- package/dist/units/index.d.ts +39 -1
- package/dist/units/interpolate.d.ts +47 -0
- package/dist/units/normalize.d.ts +47 -7
- package/dist/units/utils.d.ts +1 -1
- package/dist/utils.d.ts +3 -2
- package/dist/value.js +4229 -5229
- package/package.json +62 -30
- package/scripts/migrate-keyframes-js-lerp.mjs +257 -0
- package/dist/units/color/utils.d.ts +0 -77
- package/dist/value.cjs +0 -20
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { rawOklabToOklch, oklabToRgb255 } from '../units/color/gamut';
|
|
2
|
+
export { rawOklabToOklch, oklabToRgb255 };
|
|
3
|
+
/** Chroma-weighted squared distance in OKLab */
|
|
4
|
+
export declare function chromaDistSq(L1: number, a1: number, b1: number, L2: number, a2: number, b2: number, kC: number): number;
|
|
5
|
+
/** Format OKLCH as CSS string */
|
|
6
|
+
export declare function oklchToCss(L: number, C: number, H: number): string;
|
|
7
|
+
/**
|
|
8
|
+
* Median-cut quantization in OKLab space.
|
|
9
|
+
*
|
|
10
|
+
* Iteratively splits pixel buckets along the axis of greatest range
|
|
11
|
+
* until `targetBuckets` clusters are reached. Returns each bucket's
|
|
12
|
+
* centroid (mean L, a, b) and population count.
|
|
13
|
+
*/
|
|
14
|
+
export declare function medianCutOKLab(allPixels: Float64Array, pixelCount: number, targetBuckets: number): {
|
|
15
|
+
centroid: [number, number, number];
|
|
16
|
+
population: number;
|
|
17
|
+
}[];
|
|
18
|
+
/**
|
|
19
|
+
* Select k seed centroids from MMCQ output using D²-weighted sampling
|
|
20
|
+
* (Arthur & Vassilvitskii, 2007). The first seed is the most populated
|
|
21
|
+
* MMCQ bucket; subsequent seeds are chosen with probability proportional
|
|
22
|
+
* to chroma-weighted squared distance × population.
|
|
23
|
+
*/
|
|
24
|
+
export declare function kmeansPlusPlusInit(centroids: {
|
|
25
|
+
centroid: [number, number, number];
|
|
26
|
+
population: number;
|
|
27
|
+
}[], k: number, kC: number): [number, number, number][];
|
|
28
|
+
/**
|
|
29
|
+
* Standard Lloyd's algorithm with chroma-weighted distance.
|
|
30
|
+
* Runs until centroids converge (shift < 1e-10) or `maxIterations` is reached.
|
|
31
|
+
* Returns final centroids and per-cluster pixel populations.
|
|
32
|
+
*/
|
|
33
|
+
export declare function kmeansIterate(pixels: Float64Array, pixelCount: number, seeds: [number, number, number][], maxIterations: number, kC: number): {
|
|
34
|
+
centroids: [number, number, number][];
|
|
35
|
+
populations: number[];
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Merge centroids whose deltaE_OK falls below `threshold` (the JND).
|
|
39
|
+
* Merged centroids are population-weighted averages. This collapses
|
|
40
|
+
* clusters that k-means settled into the same perceptual neighborhood.
|
|
41
|
+
*/
|
|
42
|
+
export declare function deduplicateCentroids(centroids: [number, number, number][], populations: number[], threshold: number): {
|
|
43
|
+
centroids: [number, number, number][];
|
|
44
|
+
populations: number[];
|
|
45
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { QuantizeOptions, QuantizedColor } from './types';
|
|
2
|
+
export type { QuantizeOptions, QuantizedColor } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Quantize image pixels to a palette of K colors in OKLab space.
|
|
5
|
+
*
|
|
6
|
+
* Pipeline: downsample → sRGB→OKLab → MMCQ seed → k-means++ init →
|
|
7
|
+
* k-means refine → dedupe → perceptual sort
|
|
8
|
+
*/
|
|
9
|
+
export declare function quantizePixels(pixels: Uint8ClampedArray, width: number, height: number, options?: Partial<QuantizeOptions>): QuantizedColor[];
|
|
10
|
+
/**
|
|
11
|
+
* Extract the single dominant color from an image.
|
|
12
|
+
* Runs k=5 quantization and returns the centroid with highest OKLCH chroma.
|
|
13
|
+
*/
|
|
14
|
+
export declare function dominantColor(pixels: Uint8ClampedArray, width: number, height: number): QuantizedColor | null;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types and defaults for OKLab-native color quantization.
|
|
3
|
+
*
|
|
4
|
+
* The quantizer operates entirely in OKLab for perceptual uniformity,
|
|
5
|
+
* then converts results to OKLCH, sRGB, and CSS on output.
|
|
6
|
+
*/
|
|
7
|
+
export interface QuantizeOptions {
|
|
8
|
+
/** Number of palette colors to extract (default 5, clamped to [1, 16]). */
|
|
9
|
+
k: number;
|
|
10
|
+
/** Maximum k-means refinement iterations before convergence cutoff (default 10). */
|
|
11
|
+
maxIterations: number;
|
|
12
|
+
/** Downsample target: images are subsampled to approximately this many pixels (default 20,000). */
|
|
13
|
+
targetPixels: number;
|
|
14
|
+
/**
|
|
15
|
+
* Chroma weight (kC) for the distance metric.
|
|
16
|
+
* Scales the chromatic (a, b) axes relative to lightness:
|
|
17
|
+
* d² = ΔL² + (1 + kC·C)·(Δa² + Δb²)
|
|
18
|
+
* Higher values bias clustering toward hue/chroma distinctions (default 0.5).
|
|
19
|
+
*/
|
|
20
|
+
chromaWeight: number;
|
|
21
|
+
/**
|
|
22
|
+
* Minimum deltaE_OK between centroids; pairs below this threshold are
|
|
23
|
+
* merged as perceptually indistinguishable. Defaults to the JND (~0.02).
|
|
24
|
+
*/
|
|
25
|
+
dedupeThreshold: number;
|
|
26
|
+
}
|
|
27
|
+
export interface QuantizedColor {
|
|
28
|
+
/** OKLab triplet [L, a, b]. L ∈ [0, 1]; a, b ∈ approx [-0.4, 0.4]. */
|
|
29
|
+
oklab: [number, number, number];
|
|
30
|
+
/** OKLCH triplet [L, C, H]. L ∈ [0, 1]; C ≥ 0; H ∈ [0, 360). */
|
|
31
|
+
oklch: [number, number, number];
|
|
32
|
+
/** Gamma-encoded sRGB triplet, each channel ∈ [0, 255]. */
|
|
33
|
+
rgb: [number, number, number];
|
|
34
|
+
/** CSS `oklch()` string, ready for stylesheet injection. */
|
|
35
|
+
css: string;
|
|
36
|
+
/** Pixel count assigned to this cluster (after downsampling). */
|
|
37
|
+
population: number;
|
|
38
|
+
}
|
|
39
|
+
export declare const DEFAULTS: QuantizeOptions;
|