@mkbabb/value.js 0.5.1 → 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.
Files changed (42) hide show
  1. package/README.md +38 -56
  2. package/dist/easing.d.ts +49 -0
  3. package/dist/index.d.ts +19 -8
  4. package/dist/math.d.ts +1 -1
  5. package/dist/parsing/animation-shorthand.d.ts +19 -0
  6. package/dist/parsing/color.d.ts +10 -3
  7. package/dist/parsing/extract.d.ts +48 -0
  8. package/dist/parsing/index.d.ts +5 -20
  9. package/dist/parsing/serialize.d.ts +24 -0
  10. package/dist/parsing/stylesheet.d.ts +44 -0
  11. package/dist/parsing/units.d.ts +24 -6
  12. package/dist/parsing/utils.d.ts +5 -0
  13. package/dist/postcss-CRluLK2m.js +6400 -0
  14. package/dist/quantize/cluster.d.ts +45 -0
  15. package/dist/quantize/index.d.ts +14 -0
  16. package/dist/quantize/types.d.ts +39 -0
  17. package/dist/standalone-Ck3UyY5I.js +3458 -0
  18. package/dist/units/color/constants.d.ts +21 -0
  19. package/dist/units/color/contrast.d.ts +35 -0
  20. package/dist/units/color/conversions/cylindrical.d.ts +13 -0
  21. package/dist/units/color/conversions/direct.d.ts +41 -0
  22. package/dist/units/color/conversions/hex.d.ts +3 -0
  23. package/dist/units/color/conversions/index.d.ts +17 -0
  24. package/dist/units/color/conversions/kelvin.d.ts +5 -0
  25. package/dist/units/color/conversions/lab.d.ts +8 -0
  26. package/dist/units/color/conversions/oklab.d.ts +11 -0
  27. package/dist/units/color/conversions/transfer.d.ts +22 -0
  28. package/dist/units/color/conversions/xyz-extended.d.ts +13 -0
  29. package/dist/units/color/dispatch.d.ts +26 -0
  30. package/dist/units/color/gamut.d.ts +6 -0
  31. package/dist/units/color/index.d.ts +220 -116
  32. package/dist/units/color/mix.d.ts +16 -0
  33. package/dist/units/color/normalize.d.ts +3 -3
  34. package/dist/units/index.d.ts +39 -1
  35. package/dist/units/interpolate.d.ts +47 -0
  36. package/dist/units/normalize.d.ts +47 -7
  37. package/dist/units/utils.d.ts +1 -1
  38. package/dist/utils.d.ts +3 -2
  39. package/dist/value.js +4213 -4407
  40. package/package.json +63 -29
  41. package/scripts/migrate-keyframes-js-lerp.mjs +257 -0
  42. package/dist/units/color/utils.d.ts +0 -77
@@ -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;