@newtonedev/colors 0.0.1 → 1.0.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 +22 -23
- package/dist/__tests__/key-color.test.d.ts +2 -0
- package/dist/__tests__/key-color.test.d.ts.map +1 -0
- package/dist/config.d.ts +23 -11
- package/dist/config.d.ts.map +1 -1
- package/dist/contrast/apca.d.ts +16 -0
- package/dist/contrast/apca.d.ts.map +1 -1
- package/dist/gamut/max-chroma.d.ts +8 -3
- package/dist/gamut/max-chroma.d.ts.map +1 -1
- package/dist/index.cjs +74 -77
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +66 -70
- package/dist/index.js.map +1 -1
- package/dist/scale/generate.d.ts +44 -34
- package/dist/scale/generate.d.ts.map +1 -1
- package/dist/scale/hue-grade.d.ts +36 -29
- package/dist/scale/hue-grade.d.ts.map +1 -1
- package/dist/scale/key-color.d.ts +31 -27
- package/dist/scale/key-color.d.ts.map +1 -1
- package/dist/scale/resolve-color.d.ts +6 -26
- package/dist/scale/resolve-color.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,53 +1,57 @@
|
|
|
1
|
-
import type { Hex, Oklch
|
|
2
|
-
import { type ResolvedColor } from "./resolve-color.js";
|
|
1
|
+
import type { Hex, Oklch } from "../types.js";
|
|
3
2
|
/**
|
|
4
3
|
* The result of deriving scale parameters from a key color.
|
|
5
4
|
*
|
|
6
|
-
* Spread `hue` and `chroma` directly into ScaleOptions, then
|
|
7
|
-
* `
|
|
5
|
+
* Spread `hue` and `chroma` directly into ScaleOptions, then use
|
|
6
|
+
* `stepIndex` to locate the key color's position in the generated scale.
|
|
8
7
|
*/
|
|
9
8
|
export interface KeyColorResult {
|
|
10
9
|
/** Derived hue angle — use directly as ScaleOptions.hue. */
|
|
11
10
|
readonly hue: number;
|
|
12
11
|
/**
|
|
13
12
|
* Derived chroma shape — use directly as ScaleOptions.chroma.
|
|
14
|
-
* - `
|
|
15
|
-
* - `
|
|
13
|
+
* - `amount`: how saturated the scale is (0–1, relative to gamut boundary).
|
|
14
|
+
* - `balance`: where in the scale the key color's lightness falls (0 = lightest, 1 = darkest).
|
|
16
15
|
*/
|
|
17
16
|
readonly chroma: {
|
|
18
|
-
readonly
|
|
19
|
-
readonly
|
|
17
|
+
readonly amount: number;
|
|
18
|
+
readonly balance: number;
|
|
20
19
|
};
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
readonly
|
|
20
|
+
/** The step index in a scale of `steps` length where this color lands. */
|
|
21
|
+
readonly stepIndex: number;
|
|
22
|
+
/** Hex representation of the resolved color (sRGB-clamped if necessary). */
|
|
23
|
+
readonly hex: Hex;
|
|
24
|
+
/** The final OKLCH color, guaranteed in-gamut for the target gamut. */
|
|
25
|
+
readonly oklch: Oklch;
|
|
26
|
+
/** Whether the input was outside the target gamut and was remapped. */
|
|
27
|
+
readonly wasRemapped: boolean;
|
|
28
|
+
/** The original OKLCH before gamut mapping (identical to oklch if in-gamut). */
|
|
29
|
+
readonly original: Oklch;
|
|
31
30
|
}
|
|
32
31
|
/**
|
|
33
|
-
* Derive scale parameters from a
|
|
32
|
+
* Derive scale parameters from a known color.
|
|
34
33
|
*
|
|
35
34
|
* Given a hex or OKLCH color, returns the `hue` and `chroma` values
|
|
36
|
-
* ready to spread into ScaleOptions. The chroma
|
|
35
|
+
* ready to spread into ScaleOptions. The chroma balance is derived from
|
|
37
36
|
* where the color's lightness falls within the scale's lightness range,
|
|
38
|
-
* so the
|
|
37
|
+
* so the chroma distribution is centered around the key color's position.
|
|
39
38
|
*
|
|
40
39
|
* @param color A hex string (#RGB or #RRGGBB) or an OKLCH color object.
|
|
41
40
|
* @param options Scale context — must match the ScaleOptions you will use.
|
|
41
|
+
* `contrast` values are slider values (0–1), same as ScaleOptions.contrast.
|
|
42
|
+
* `steps` is the number of steps in the scale (default: 26).
|
|
42
43
|
*
|
|
43
44
|
* @example
|
|
44
|
-
* const key = keyColor('#3B82F6'
|
|
45
|
-
* const scale = generateScale({
|
|
46
|
-
* const
|
|
45
|
+
* const key = keyColor('#3B82F6');
|
|
46
|
+
* const scale = generateScale({ hue: key.hue, chroma: key.chroma });
|
|
47
|
+
* const matchedHex = oklchToHex(scale[key.stepIndex]);
|
|
47
48
|
*/
|
|
48
49
|
export declare function keyColor(color: Hex | Oklch, options?: {
|
|
49
|
-
readonly
|
|
50
|
-
readonly
|
|
51
|
-
|
|
50
|
+
readonly isP3?: boolean;
|
|
51
|
+
readonly contrast?: {
|
|
52
|
+
readonly light?: number;
|
|
53
|
+
readonly dark?: number;
|
|
54
|
+
};
|
|
55
|
+
readonly steps?: number;
|
|
52
56
|
}): KeyColorResult;
|
|
53
57
|
//# sourceMappingURL=key-color.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-color.d.ts","sourceRoot":"","sources":["../../src/scale/key-color.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"key-color.d.ts","sourceRoot":"","sources":["../../src/scale/key-color.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAK9C;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,4DAA4D;IAC5D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACvE,0EAA0E;IAC1E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,4EAA4E;IAC5E,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,uEAAuE;IACvE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,uEAAuE;IACvE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,GAAG,GAAG,KAAK,EAClB,OAAO,CAAC,EAAE;IACR,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACxE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB,GACA,cAAc,CAiBhB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Hex, Oklch
|
|
1
|
+
import type { Hex, Oklch } from "../types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Result of resolving a color into scale-ready parameters.
|
|
4
4
|
*/
|
|
@@ -13,9 +13,9 @@ export interface ResolvedColor {
|
|
|
13
13
|
readonly original: Oklch;
|
|
14
14
|
/** Chroma lost during gamut mapping (0 if in-gamut). */
|
|
15
15
|
readonly chromaShift: number;
|
|
16
|
-
/** Hue from the resolved color
|
|
16
|
+
/** Hue from the resolved color. */
|
|
17
17
|
readonly hue: number;
|
|
18
|
-
/** Chroma as a fraction of the gamut boundary at this L/h (0–1)
|
|
18
|
+
/** Chroma as a fraction of the gamut boundary at this L/h (0–1). */
|
|
19
19
|
readonly chromaRatio: number;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
@@ -23,33 +23,13 @@ export interface ResolvedColor {
|
|
|
23
23
|
*
|
|
24
24
|
* If the color is outside the target gamut, it is perceptually mapped to the
|
|
25
25
|
* nearest in-gamut color (chroma reduction at fixed L and h). The result
|
|
26
|
-
* includes the derived hue and chromaRatio
|
|
26
|
+
* includes the derived hue and chromaRatio.
|
|
27
27
|
*
|
|
28
28
|
* Hex input is always valid sRGB, so `wasRemapped` will be false for hex
|
|
29
29
|
* with gamut="srgb". OKLCH input may be out of gamut and will be mapped.
|
|
30
30
|
*
|
|
31
31
|
* @param input A hex string (#RGB, #RRGGBB) or an OKLCH color.
|
|
32
|
-
* @param
|
|
32
|
+
* @param isP3 Use Display P3 gamut instead of sRGB (default: false).
|
|
33
33
|
*/
|
|
34
|
-
export declare function resolveColor(input: Hex | Oklch,
|
|
35
|
-
/**
|
|
36
|
-
* Result of finding the nearest color in a scale.
|
|
37
|
-
*/
|
|
38
|
-
export interface NearestMatch {
|
|
39
|
-
/** Index of the nearest step in the scale (0-based). */
|
|
40
|
-
readonly index: number;
|
|
41
|
-
/** The nearest OKLCH color from the scale. */
|
|
42
|
-
readonly color: Oklch;
|
|
43
|
-
/** Perceptual distance (deltaEOK) between the target and nearest step. */
|
|
44
|
-
readonly distance: number;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Find the step in a scale perceptually closest to a target color.
|
|
48
|
-
*
|
|
49
|
-
* Uses deltaEOK (Euclidean distance in OKLAB) for comparison.
|
|
50
|
-
*
|
|
51
|
-
* @param target The color to match against.
|
|
52
|
-
* @param scale An array of OKLCH colors (e.g. from generateScale).
|
|
53
|
-
*/
|
|
54
|
-
export declare function findNearest(target: Oklch, scale: readonly Oklch[]): NearestMatch;
|
|
34
|
+
export declare function resolveColor(input: Hex | Oklch, isP3?: boolean): ResolvedColor;
|
|
55
35
|
//# sourceMappingURL=resolve-color.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-color.d.ts","sourceRoot":"","sources":["../../src/scale/resolve-color.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"resolve-color.d.ts","sourceRoot":"","sources":["../../src/scale/resolve-color.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAS,MAAM,aAAa,CAAC;AAWrD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,uEAAuE;IACvE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,4EAA4E;IAC5E,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,uEAAuE;IACvE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC;IACzB,wDAAwD;IACxD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,mCAAmC;IACnC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,oEAAoE;IACpE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,GAAG,GAAG,KAAK,EAClB,IAAI,GAAE,OAAe,GACpB,aAAa,CA+Bf"}
|