@basiclines/rampa-sdk 1.6.0 → 1.7.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 +72 -21
- package/dist/index.js +56 -0
- package/package.json +1 -1
- package/dist/builder.d.ts +0 -38
- package/dist/color-result.d.ts +0 -21
- package/dist/cube-color-space.d.ts +0 -48
- package/dist/formatters/css.d.ts +0 -2
- package/dist/formatters/json.d.ts +0 -2
- package/dist/index.d.ts +0 -38
- package/dist/linear-color-space.d.ts +0 -43
- package/dist/read-only.d.ts +0 -8
- package/dist/types.d.ts +0 -107
package/README.md
CHANGED
|
@@ -345,7 +345,11 @@ rampa('#3b82f6').size(5).lightness(10, 90).add('complementary').toJSON();
|
|
|
345
345
|
|
|
346
346
|
## Color Spaces
|
|
347
347
|
|
|
348
|
-
Color spaces let you create structured palettes from a set of anchor colors and query them semantically.
|
|
348
|
+
Color spaces let you create structured palettes from a set of anchor colors and query them semantically. Three geometric primitives are available:
|
|
349
|
+
|
|
350
|
+
- **LinearColorSpace** — 1D interpolated ramp
|
|
351
|
+
- **PlaneColorSpace** — 2D saturation×lightness plane
|
|
352
|
+
- **CubeColorSpace** — 3D trilinear interpolation cube
|
|
349
353
|
|
|
350
354
|
### `LinearColorSpace`
|
|
351
355
|
|
|
@@ -355,11 +359,9 @@ Interpolates between two colors to produce an evenly-spaced ramp.
|
|
|
355
359
|
import { LinearColorSpace } from '@basiclines/rampa-sdk';
|
|
356
360
|
|
|
357
361
|
const neutral = new LinearColorSpace('#ffffff', '#000000').size(24);
|
|
358
|
-
neutral(1) // →
|
|
359
|
-
neutral(12) // →
|
|
360
|
-
neutral(
|
|
361
|
-
neutral(12).hex // → '#666666'
|
|
362
|
-
neutral(12).format('hsl') // → 'hsl(0, 0%, 40%)'
|
|
362
|
+
neutral(1) // → '#ffffff' (lightest, returns string directly)
|
|
363
|
+
neutral(12) // → '#666666' (mid gray)
|
|
364
|
+
neutral(12).hsl() // → 'hsl(0, 0%, 40%)'
|
|
363
365
|
neutral.palette // → string[24]
|
|
364
366
|
```
|
|
365
367
|
|
|
@@ -377,6 +379,44 @@ base(1) // → '#45475a' (exact, no interpolation)
|
|
|
377
379
|
base(3) // → '#a6e3a1'
|
|
378
380
|
```
|
|
379
381
|
|
|
382
|
+
### `PlaneColorSpace`
|
|
383
|
+
|
|
384
|
+
Creates a 2D color plane for a single hue, anchored to shared dark/light values. Create one plane per hue.
|
|
385
|
+
|
|
386
|
+
```
|
|
387
|
+
Y(lightness)
|
|
388
|
+
1 │ light ─────────── hue
|
|
389
|
+
│ │ │
|
|
390
|
+
│ │ interpolated │
|
|
391
|
+
│ │ │
|
|
392
|
+
0 │ dark ─────────── dark
|
|
393
|
+
└──────────────────────── X(saturation)
|
|
394
|
+
0 1
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
At Y=0 the entire row converges to the dark anchor.
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
import { PlaneColorSpace } from '@basiclines/rampa-sdk';
|
|
401
|
+
|
|
402
|
+
// One plane per hue, reuse dark/light anchors
|
|
403
|
+
const red = new PlaneColorSpace('#1e1e2e', '#cdd6f4', '#f38ba8').size(6);
|
|
404
|
+
const blue = new PlaneColorSpace('#1e1e2e', '#cdd6f4', '#89b4fa').size(6);
|
|
405
|
+
|
|
406
|
+
red(3, 5) // → ColorAccessor (saturation=3, lightness=5)
|
|
407
|
+
red(0, 3) // → achromatic at lightness 3 (no hue influence)
|
|
408
|
+
red(5, 5) // → full hue color
|
|
409
|
+
red(0, 0) // → dark anchor
|
|
410
|
+
red.palette // → string[36] (6²)
|
|
411
|
+
|
|
412
|
+
// Template literals and concatenation work directly
|
|
413
|
+
`background: ${red(3, 5)};` // → 'background: #ab34cd;'
|
|
414
|
+
|
|
415
|
+
// Format conversion
|
|
416
|
+
red(3, 5).hsl() // → 'hsl(280, 60%, 50%)'
|
|
417
|
+
red(3, 5).oklch() // → 'oklch(52.3% 0.198 310)'
|
|
418
|
+
```
|
|
419
|
+
|
|
380
420
|
### `CubeColorSpace`
|
|
381
421
|
|
|
382
422
|
Creates a 3D color cube from 8 corner colors via trilinear interpolation. The constructor keys become alias names for semantic lookups.
|
|
@@ -384,7 +424,7 @@ Creates a 3D color cube from 8 corner colors via trilinear interpolation. The co
|
|
|
384
424
|
```typescript
|
|
385
425
|
import { CubeColorSpace } from '@basiclines/rampa-sdk';
|
|
386
426
|
|
|
387
|
-
const tint = new CubeColorSpace({
|
|
427
|
+
const { r, b, tint } = new CubeColorSpace({
|
|
388
428
|
k: '#1e1e2e', // origin (0,0,0)
|
|
389
429
|
r: '#f38ba8', // x axis
|
|
390
430
|
g: '#a6e3a1', // y axis
|
|
@@ -395,11 +435,9 @@ const tint = new CubeColorSpace({
|
|
|
395
435
|
w: '#cdd6f4', // x+y+z
|
|
396
436
|
}).size(6);
|
|
397
437
|
|
|
398
|
-
|
|
438
|
+
r(4) // → strong red
|
|
399
439
|
tint({ r: 4, b: 2 }) // → red-blue blend
|
|
400
440
|
tint({ w: 3 }) // → mid-white (all axes at 3)
|
|
401
|
-
tint({ r: 5, w: 2 }) // → pastel red (white raises base)
|
|
402
|
-
tint.palette // → string[216] (6³)
|
|
403
441
|
```
|
|
404
442
|
|
|
405
443
|
#### Custom vocabulary
|
|
@@ -440,7 +478,7 @@ When you call `tint({ r: 4, b: 2 })`, each alias's mask is multiplied by its int
|
|
|
440
478
|
|
|
441
479
|
### Interpolation modes
|
|
442
480
|
|
|
443
|
-
|
|
481
|
+
`LinearColorSpace`, `PlaneColorSpace`, and `CubeColorSpace` all support configurable interpolation:
|
|
444
482
|
|
|
445
483
|
| Mode | Description |
|
|
446
484
|
|------|-------------|
|
|
@@ -453,24 +491,37 @@ Both `LinearColorSpace` and `CubeColorSpace` support configurable interpolation:
|
|
|
453
491
|
// LinearColorSpace
|
|
454
492
|
new LinearColorSpace('#ff0000', '#0000ff').interpolation('oklch').size(10)
|
|
455
493
|
new LinearColorSpace('#ff0000', '#0000ff').interpolation('lab').size(10)
|
|
456
|
-
new LinearColorSpace('#ff0000', '#0000ff').interpolation('rgb').size(10)
|
|
457
494
|
new LinearColorSpace('#f00', '#0f0', '#00f').interpolation(false).size(3)
|
|
458
495
|
|
|
496
|
+
// PlaneColorSpace
|
|
497
|
+
new PlaneColorSpace('#000', '#fff', '#f00').interpolation('oklch').size(6)
|
|
498
|
+
new PlaneColorSpace('#000', '#fff', '#f00').interpolation('lab').size(6)
|
|
499
|
+
|
|
459
500
|
// CubeColorSpace
|
|
460
|
-
new CubeColorSpace({ ... }
|
|
501
|
+
new CubeColorSpace({ ... }).interpolation('lab').size(6)
|
|
461
502
|
```
|
|
462
503
|
|
|
463
|
-
### Color
|
|
504
|
+
### Color accessor
|
|
505
|
+
|
|
506
|
+
All color space lookups return a `ColorAccessor` — a string that works directly in template literals and concatenation, with conversion methods:
|
|
507
|
+
|
|
508
|
+
```typescript
|
|
509
|
+
const c = red(3, 5);
|
|
510
|
+
`${c}` // → '#ab34cd' (string coercion)
|
|
511
|
+
'bg: ' + c // → 'bg: #ab34cd' (concatenation)
|
|
512
|
+
c.hex() // → '#ab34cd'
|
|
513
|
+
c.hsl() // → 'hsl(280, 60%, 50%)'
|
|
514
|
+
c.rgb() // → 'rgb(171, 52, 205)'
|
|
515
|
+
c.oklch() // → 'oklch(52.3% 0.198 310)'
|
|
516
|
+
c.luminance // → 0.52 (perceptual, 0–1)
|
|
517
|
+
```
|
|
464
518
|
|
|
465
|
-
|
|
519
|
+
Use `.format()` on the color space to change the default output format:
|
|
466
520
|
|
|
467
521
|
```typescript
|
|
468
|
-
const
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
color.format('rgb') // → 'rgb(171, 52, 205)'
|
|
472
|
-
color.format('oklch') // → 'oklch(52.3% 0.198 310)'
|
|
473
|
-
color.toString() // → '#ab34cd'
|
|
522
|
+
const rgbSpace = new PlaneColorSpace('#000', '#fff', '#f00').format('rgb').size(6);
|
|
523
|
+
`${rgbSpace(3, 5)}` // → 'rgb(255, 128, 128)'
|
|
524
|
+
rgbSpace(3, 5).hex() // → '#ff8080' (still available)
|
|
474
525
|
```
|
|
475
526
|
|
|
476
527
|
## Development
|
package/dist/index.js
CHANGED
|
@@ -7939,6 +7939,21 @@ function generateCubeSpace(corners, stepsPerAxis, mode = "oklch") {
|
|
|
7939
7939
|
}
|
|
7940
7940
|
return colors;
|
|
7941
7941
|
}
|
|
7942
|
+
function generatePlaneSpace(dark, light, hue3, stepsPerAxis, mode = "oklch") {
|
|
7943
|
+
const mix = (a, b, t) => mixWithMode(a, b, t, mode);
|
|
7944
|
+
const max11 = stepsPerAxis - 1;
|
|
7945
|
+
const colors = [];
|
|
7946
|
+
for (let xi = 0;xi < stepsPerAxis; xi++) {
|
|
7947
|
+
const tx = max11 === 0 ? 0 : xi / max11;
|
|
7948
|
+
const bottom = dark;
|
|
7949
|
+
const top = mix(light, hue3, tx);
|
|
7950
|
+
for (let yi = 0;yi < stepsPerAxis; yi++) {
|
|
7951
|
+
const ty = max11 === 0 ? 0 : yi / max11;
|
|
7952
|
+
colors.push(mix(bottom, top, ty));
|
|
7953
|
+
}
|
|
7954
|
+
}
|
|
7955
|
+
return colors;
|
|
7956
|
+
}
|
|
7942
7957
|
|
|
7943
7958
|
// src/color-result.ts
|
|
7944
7959
|
function detectColorFormat(color) {
|
|
@@ -8147,6 +8162,46 @@ class CubeColorSpace {
|
|
|
8147
8162
|
}
|
|
8148
8163
|
}
|
|
8149
8164
|
|
|
8165
|
+
// src/plane-color-space.ts
|
|
8166
|
+
class PlaneColorSpace {
|
|
8167
|
+
_dark;
|
|
8168
|
+
_light;
|
|
8169
|
+
_hue;
|
|
8170
|
+
_interpolation;
|
|
8171
|
+
_format = "hex";
|
|
8172
|
+
constructor(dark, light, hue3) {
|
|
8173
|
+
validateSameFormat([dark, light, hue3]);
|
|
8174
|
+
this._dark = chroma_js_default(dark).hex();
|
|
8175
|
+
this._light = chroma_js_default(light).hex();
|
|
8176
|
+
this._hue = chroma_js_default(hue3).hex();
|
|
8177
|
+
this._interpolation = "oklch";
|
|
8178
|
+
}
|
|
8179
|
+
interpolation(mode) {
|
|
8180
|
+
this._interpolation = mode;
|
|
8181
|
+
return this;
|
|
8182
|
+
}
|
|
8183
|
+
format(fmt) {
|
|
8184
|
+
this._format = fmt;
|
|
8185
|
+
return this;
|
|
8186
|
+
}
|
|
8187
|
+
size(stepsPerAxis) {
|
|
8188
|
+
const palette = generatePlaneSpace(this._dark, this._light, this._hue, stepsPerAxis, this._interpolation);
|
|
8189
|
+
const fmt = this._format;
|
|
8190
|
+
const lookup = (saturation, lightness) => {
|
|
8191
|
+
const sx = Math.max(0, Math.min(stepsPerAxis - 1, saturation));
|
|
8192
|
+
const ly = Math.max(0, Math.min(stepsPerAxis - 1, lightness));
|
|
8193
|
+
const idx = sx * stepsPerAxis + ly;
|
|
8194
|
+
return createColorAccessor(palette[idx], fmt);
|
|
8195
|
+
};
|
|
8196
|
+
const result = lookup;
|
|
8197
|
+
Object.defineProperties(result, {
|
|
8198
|
+
palette: { value: palette, enumerable: true },
|
|
8199
|
+
size: { value: stepsPerAxis, enumerable: true }
|
|
8200
|
+
});
|
|
8201
|
+
return result;
|
|
8202
|
+
}
|
|
8203
|
+
}
|
|
8204
|
+
|
|
8150
8205
|
// ../src/usecases/MixColors.ts
|
|
8151
8206
|
function mixColors(color1, color2, t) {
|
|
8152
8207
|
const oklch1 = convertToOklch(color1);
|
|
@@ -8200,6 +8255,7 @@ export {
|
|
|
8200
8255
|
color,
|
|
8201
8256
|
ReadOnlyBuilder,
|
|
8202
8257
|
RampaBuilder,
|
|
8258
|
+
PlaneColorSpace,
|
|
8203
8259
|
LinearColorSpace,
|
|
8204
8260
|
CubeColorSpace
|
|
8205
8261
|
};
|
package/package.json
CHANGED
package/dist/builder.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { ColorFormat, ScaleType, BlendMode, HarmonyType, RampaResult } from './types';
|
|
2
|
-
export declare class RampaBuilder {
|
|
3
|
-
private _baseColor;
|
|
4
|
-
private _size;
|
|
5
|
-
private _format;
|
|
6
|
-
private _lightnessStart;
|
|
7
|
-
private _lightnessEnd;
|
|
8
|
-
private _saturationStart;
|
|
9
|
-
private _saturationEnd;
|
|
10
|
-
private _hueStart;
|
|
11
|
-
private _hueEnd;
|
|
12
|
-
private _lightnessScale;
|
|
13
|
-
private _saturationScale;
|
|
14
|
-
private _hueScale;
|
|
15
|
-
private _tintColor?;
|
|
16
|
-
private _tintOpacity;
|
|
17
|
-
private _tintBlend;
|
|
18
|
-
private _harmonies;
|
|
19
|
-
constructor(baseColor: string);
|
|
20
|
-
size(steps: number): this;
|
|
21
|
-
format(fmt: ColorFormat): this;
|
|
22
|
-
lightness(start: number, end: number): this;
|
|
23
|
-
saturation(start: number, end: number): this;
|
|
24
|
-
hue(start: number, end: number): this;
|
|
25
|
-
lightnessScale(scale: ScaleType): this;
|
|
26
|
-
saturationScale(scale: ScaleType): this;
|
|
27
|
-
hueScale(scale: ScaleType): this;
|
|
28
|
-
tint(color: string, opacity: number, blend?: BlendMode): this;
|
|
29
|
-
add(type: HarmonyType): this;
|
|
30
|
-
add(type: 'shift', degrees: number): this;
|
|
31
|
-
private buildConfig;
|
|
32
|
-
private formatColor;
|
|
33
|
-
private getHarmonyColors;
|
|
34
|
-
private buildRamps;
|
|
35
|
-
generate(): RampaResult;
|
|
36
|
-
toCSS(): string;
|
|
37
|
-
toJSON(): string;
|
|
38
|
-
}
|
package/dist/color-result.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { ColorFormat, ColorResult, ColorAccessor } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Detect the format of a color string.
|
|
4
|
-
*/
|
|
5
|
-
export declare function detectColorFormat(color: string): ColorFormat;
|
|
6
|
-
/**
|
|
7
|
-
* Validate that all colors in an array share the same format.
|
|
8
|
-
* Returns the detected format.
|
|
9
|
-
*/
|
|
10
|
-
export declare function validateSameFormat(colors: string[]): ColorFormat;
|
|
11
|
-
/**
|
|
12
|
-
* Create a ColorAccessor from a hex string with a given output format.
|
|
13
|
-
* Returns a String object with conversion methods so it acts as a string
|
|
14
|
-
* in template literals, comparisons, and concatenation.
|
|
15
|
-
*/
|
|
16
|
-
export declare function createColorAccessor(hex: string, outputFormat: ColorFormat): ColorAccessor;
|
|
17
|
-
/**
|
|
18
|
-
* Create a ColorResult from a hex string.
|
|
19
|
-
* Acts as a string (hex) by default, supports .format() for conversions.
|
|
20
|
-
*/
|
|
21
|
-
export declare function createColorResult(hex: string): ColorResult;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { ColorFormat, InterpolationMode, CubeColorSpaceResult } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Create a 3D color cube from 8 named corner colors.
|
|
4
|
-
*
|
|
5
|
-
* The constructor keys become shortcut function names and tint() aliases.
|
|
6
|
-
* Key order determines cube position (see CORNER_MASKS above).
|
|
7
|
-
* All input colors must use the same format.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* const space = new CubeColorSpace({
|
|
12
|
-
* k: '#1e1e2e', r: '#f38ba8', g: '#a6e3a1', b: '#89b4fa',
|
|
13
|
-
* y: '#f9e2af', m: '#cba6f7', c: '#94e2d5', w: '#cdd6f4',
|
|
14
|
-
* }).size(6);
|
|
15
|
-
*
|
|
16
|
-
* // With different interpolation or output format:
|
|
17
|
-
* const space2 = new CubeColorSpace({ ... }).interpolation('lab').format('rgb').size(6);
|
|
18
|
-
*
|
|
19
|
-
* space.r(4) // → "f38ba8" (string in output format)
|
|
20
|
-
* space.r(4).hsl() // → "hsl(...)" (convert to another format)
|
|
21
|
-
* space.tint({ r: 3, b: 2 }) // → string in output format
|
|
22
|
-
* space.cube(3, 0, 2) // → string in output format
|
|
23
|
-
* space.palette // → string[216]
|
|
24
|
-
*
|
|
25
|
-
* // Destructure for convenience:
|
|
26
|
-
* const { r, w, tint, cube } = space;
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export declare class CubeColorSpace {
|
|
30
|
-
private _corners;
|
|
31
|
-
private _interpolation;
|
|
32
|
-
private _format;
|
|
33
|
-
constructor(corners: Record<string, string>, options?: {
|
|
34
|
-
interpolation?: InterpolationMode;
|
|
35
|
-
});
|
|
36
|
-
/**
|
|
37
|
-
* Set the interpolation mode.
|
|
38
|
-
*/
|
|
39
|
-
interpolation(mode: InterpolationMode): this;
|
|
40
|
-
/**
|
|
41
|
-
* Set the output color format (default: 'hex').
|
|
42
|
-
*/
|
|
43
|
-
format(fmt: ColorFormat): this;
|
|
44
|
-
/**
|
|
45
|
-
* Set the steps per axis and return the color space accessor object.
|
|
46
|
-
*/
|
|
47
|
-
size(stepsPerAxis: number): CubeColorSpaceResult;
|
|
48
|
-
}
|
package/dist/formatters/css.d.ts
DELETED
package/dist/index.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { RampaBuilder } from './builder';
|
|
2
|
-
import { ReadOnlyBuilder } from './read-only';
|
|
3
|
-
import { LinearColorSpace } from './linear-color-space';
|
|
4
|
-
import { CubeColorSpace } from './cube-color-space';
|
|
5
|
-
import type { ColorFormat, ScaleType, BlendMode, HarmonyType, RampResult, RampaResult, ColorInfo, InterpolationMode, ColorResult, ColorAccessor, RgbComponents, LinearColorSpaceFn, CubeColorSpaceResult, ColorSpaceOptions } from './types';
|
|
6
|
-
/**
|
|
7
|
-
* Create a new color ramp builder from a base color.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { rampa } from '@basiclines/rampa-sdk';
|
|
12
|
-
*
|
|
13
|
-
* const result = rampa('#3b82f6').size(10).generate();
|
|
14
|
-
* const css = rampa('#3b82f6').add('complementary').toCSS();
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export declare function rampa(baseColor: string): RampaBuilder;
|
|
18
|
-
export declare namespace rampa {
|
|
19
|
-
var convert: (color: string, format: ColorFormat) => string;
|
|
20
|
-
var readOnly: (color: string) => ReadOnlyBuilder;
|
|
21
|
-
var mix: (color1: string, color2: string, t: number) => string;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Create a ColorResult from any hex color string.
|
|
25
|
-
* Provides .hex, .rgb, .luminance, .format() for color inspection.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* import { color } from '@basiclines/rampa-sdk';
|
|
30
|
-
* const c = color('#ff0000');
|
|
31
|
-
* c.rgb // { r: 255, g: 0, b: 0 }
|
|
32
|
-
* c.luminance // 0.627 (OKLCH perceptual lightness)
|
|
33
|
-
* c.format('hsl') // 'hsl(0, 100%, 50%)'
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare function color(hex: string): ColorResult;
|
|
37
|
-
export { RampaBuilder, ReadOnlyBuilder, LinearColorSpace, CubeColorSpace };
|
|
38
|
-
export type { ColorFormat, ScaleType, BlendMode, HarmonyType, RampResult, RampaResult, ColorInfo, InterpolationMode, ColorResult, ColorAccessor, RgbComponents, LinearColorSpaceFn, CubeColorSpaceResult, ColorSpaceOptions, };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { ColorFormat, InterpolationMode, LinearColorSpaceFn } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Create a linear color space.
|
|
4
|
-
* All input colors must use the same format.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* // Interpolated (default: oklch)
|
|
9
|
-
* const neutral = new LinearColorSpace('#ffffff', '#000000').size(24);
|
|
10
|
-
* neutral(12) // → "#808080" (string in output format)
|
|
11
|
-
* neutral(12).hsl() // → "hsl(...)" (convert to another format)
|
|
12
|
-
*
|
|
13
|
-
* // Different interpolation and output format:
|
|
14
|
-
* const ramp = new LinearColorSpace('#ff0000', '#0000ff').interpolation('lab').format('rgb').size(10);
|
|
15
|
-
* ramp(5) // → "rgb(128, 0, 128)"
|
|
16
|
-
*
|
|
17
|
-
* // Lookup table — no interpolation, just a plain color array
|
|
18
|
-
* const base = new LinearColorSpace('#000', '#f00', '#0f0', '#ff0', '#00f', '#f0f', '#0ff', '#fff')
|
|
19
|
-
* .interpolation(false)
|
|
20
|
-
* .size(8);
|
|
21
|
-
* base(1) // → first color
|
|
22
|
-
* base(3) // → third color
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export declare class LinearColorSpace {
|
|
26
|
-
private _colors;
|
|
27
|
-
private _interpolation;
|
|
28
|
-
private _format;
|
|
29
|
-
constructor(...colors: string[]);
|
|
30
|
-
/**
|
|
31
|
-
* Set the interpolation mode.
|
|
32
|
-
* Pass false for a plain lookup table (no interpolation).
|
|
33
|
-
*/
|
|
34
|
-
interpolation(mode: InterpolationMode | false): this;
|
|
35
|
-
/**
|
|
36
|
-
* Set the output color format (default: 'hex').
|
|
37
|
-
*/
|
|
38
|
-
format(fmt: ColorFormat): this;
|
|
39
|
-
/**
|
|
40
|
-
* Set the number of color steps and return the color accessor function.
|
|
41
|
-
*/
|
|
42
|
-
size(steps: number): LinearColorSpaceFn;
|
|
43
|
-
}
|
package/dist/read-only.d.ts
DELETED
package/dist/types.d.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
export type ColorFormat = 'hex' | 'hsl' | 'rgb' | 'oklch';
|
|
2
|
-
export type ScaleType = 'linear' | 'geometric' | 'fibonacci' | 'golden-ratio' | 'logarithmic' | 'powers-of-2' | 'musical-ratio' | 'cielab-uniform' | 'ease-in' | 'ease-out' | 'ease-in-out';
|
|
3
|
-
export type BlendMode = 'normal' | 'darken' | 'multiply' | 'plus-darker' | 'color-burn' | 'lighten' | 'screen' | 'plus-lighter' | 'color-dodge' | 'overlay' | 'soft-light' | 'hard-light' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity';
|
|
4
|
-
export type HarmonyType = 'complementary' | 'triadic' | 'analogous' | 'split-complementary' | 'square' | 'compound';
|
|
5
|
-
export interface RampResult {
|
|
6
|
-
name: string;
|
|
7
|
-
baseColor: string;
|
|
8
|
-
colors: string[];
|
|
9
|
-
}
|
|
10
|
-
export interface RampaResult {
|
|
11
|
-
ramps: RampResult[];
|
|
12
|
-
}
|
|
13
|
-
export interface ColorInfo {
|
|
14
|
-
hex: string;
|
|
15
|
-
rgb: {
|
|
16
|
-
r: number;
|
|
17
|
-
g: number;
|
|
18
|
-
b: number;
|
|
19
|
-
};
|
|
20
|
-
hsl: {
|
|
21
|
-
h: number;
|
|
22
|
-
s: number;
|
|
23
|
-
l: number;
|
|
24
|
-
};
|
|
25
|
-
oklch: {
|
|
26
|
-
l: number;
|
|
27
|
-
c: number;
|
|
28
|
-
h: number;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
export type InterpolationMode = 'oklch' | 'lab' | 'rgb';
|
|
32
|
-
export interface ColorSpaceOptions {
|
|
33
|
-
interpolation?: InterpolationMode;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* RGB components (0-255).
|
|
37
|
-
*/
|
|
38
|
-
export interface RgbComponents {
|
|
39
|
-
r: number;
|
|
40
|
-
g: number;
|
|
41
|
-
b: number;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* A color result that acts as a hex string but supports format chaining.
|
|
45
|
-
*/
|
|
46
|
-
export interface ColorResult {
|
|
47
|
-
/** Hex color string */
|
|
48
|
-
hex: string;
|
|
49
|
-
/** RGB components (0-255) */
|
|
50
|
-
rgb: RgbComponents;
|
|
51
|
-
/** Perceptual luminance (0-1) using OKLCH lightness */
|
|
52
|
-
luminance: number;
|
|
53
|
-
/** Format the color as hsl, rgb, oklch, or hex */
|
|
54
|
-
format(fmt: ColorFormat): string;
|
|
55
|
-
/** String coercion returns hex */
|
|
56
|
-
toString(): string;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* A color accessor returned by color space functions.
|
|
60
|
-
* Acts as a string via toString()/valueOf() in the color space's output format.
|
|
61
|
-
* Has .hex(), .hsl(), .rgb(), .oklch() methods for format conversion.
|
|
62
|
-
*/
|
|
63
|
-
export interface ColorAccessor {
|
|
64
|
-
/** Convert to hex string */
|
|
65
|
-
hex(): string;
|
|
66
|
-
/** Convert to hsl string */
|
|
67
|
-
hsl(): string;
|
|
68
|
-
/** Convert to rgb string */
|
|
69
|
-
rgb(): string;
|
|
70
|
-
/** Convert to oklch string */
|
|
71
|
-
oklch(): string;
|
|
72
|
-
/** Perceptual luminance (0-1) using OKLCH lightness */
|
|
73
|
-
luminance: number;
|
|
74
|
-
/** String coercion returns color in the space's output format */
|
|
75
|
-
toString(): string;
|
|
76
|
-
/** Primitive coercion returns the formatted string */
|
|
77
|
-
valueOf(): string;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* The function signature returned by LinearColorSpace.
|
|
81
|
-
* Call it with a 1-based index to get a color.
|
|
82
|
-
*/
|
|
83
|
-
export interface LinearColorSpaceFn {
|
|
84
|
-
(index: number): ColorAccessor;
|
|
85
|
-
palette: string[];
|
|
86
|
-
size: number;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* The result object returned by CubeColorSpace.size().
|
|
90
|
-
* Provides multiple ways to access colors:
|
|
91
|
-
* - Per-corner shortcut functions (e.g. r(3), w(5))
|
|
92
|
-
* - tint() for multi-axis lookups
|
|
93
|
-
* - cube() for raw 3D coordinate access
|
|
94
|
-
* - palette for the full color array
|
|
95
|
-
*/
|
|
96
|
-
export interface CubeColorSpaceResult {
|
|
97
|
-
/** Multi-axis lookup: tint({ r: 3, b: 2 }) */
|
|
98
|
-
tint(query: Record<string, number>): ColorAccessor;
|
|
99
|
-
/** Raw 3D coordinate lookup: cube(x, y, z) */
|
|
100
|
-
cube(x: number, y: number, z: number): ColorAccessor;
|
|
101
|
-
/** Full palette array */
|
|
102
|
-
palette: string[];
|
|
103
|
-
/** Steps per axis */
|
|
104
|
-
size: number;
|
|
105
|
-
/** Per-corner shortcut functions, keyed by constructor key names */
|
|
106
|
-
[key: string]: ((index: number) => ColorAccessor) | string[] | number | ((query: Record<string, number>) => ColorAccessor) | ((x: number, y: number, z: number) => ColorAccessor);
|
|
107
|
-
}
|