@basiclines/rampa-sdk 1.7.0 → 1.7.1

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.
@@ -0,0 +1,38 @@
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
+ }
@@ -0,0 +1,21 @@
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;
@@ -0,0 +1,48 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ import type { RampResult } from '../types';
2
+ export declare function formatCssOutput(ramps: RampResult[]): string;
@@ -0,0 +1,2 @@
1
+ import type { RampResult } from '../types';
2
+ export declare function formatJsonOutput(ramps: RampResult[]): string;
@@ -0,0 +1,39 @@
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 { PlaneColorSpace } from './plane-color-space';
6
+ import type { ColorFormat, ScaleType, BlendMode, HarmonyType, RampResult, RampaResult, ColorInfo, InterpolationMode, ColorResult, ColorAccessor, RgbComponents, LinearColorSpaceFn, CubeColorSpaceResult, PlaneColorSpaceResult, ColorSpaceOptions } from './types';
7
+ /**
8
+ * Create a new color ramp builder from a base color.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { rampa } from '@basiclines/rampa-sdk';
13
+ *
14
+ * const result = rampa('#3b82f6').size(10).generate();
15
+ * const css = rampa('#3b82f6').add('complementary').toCSS();
16
+ * ```
17
+ */
18
+ export declare function rampa(baseColor: string): RampaBuilder;
19
+ export declare namespace rampa {
20
+ var convert: (color: string, format: ColorFormat) => string;
21
+ var readOnly: (color: string) => ReadOnlyBuilder;
22
+ var mix: (color1: string, color2: string, t: number) => string;
23
+ }
24
+ /**
25
+ * Create a ColorResult from any hex color string.
26
+ * Provides .hex, .rgb, .luminance, .format() for color inspection.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { color } from '@basiclines/rampa-sdk';
31
+ * const c = color('#ff0000');
32
+ * c.rgb // { r: 255, g: 0, b: 0 }
33
+ * c.luminance // 0.627 (OKLCH perceptual lightness)
34
+ * c.format('hsl') // 'hsl(0, 100%, 50%)'
35
+ * ```
36
+ */
37
+ export declare function color(hex: string): ColorResult;
38
+ export { RampaBuilder, ReadOnlyBuilder, LinearColorSpace, CubeColorSpace, PlaneColorSpace };
39
+ export type { ColorFormat, ScaleType, BlendMode, HarmonyType, RampResult, RampaResult, ColorInfo, InterpolationMode, ColorResult, ColorAccessor, RgbComponents, LinearColorSpaceFn, CubeColorSpaceResult, PlaneColorSpaceResult, ColorSpaceOptions, };
@@ -0,0 +1,43 @@
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
+ }
@@ -0,0 +1,36 @@
1
+ import type { ColorFormat, InterpolationMode, PlaneColorSpaceResult } from './types';
2
+ /**
3
+ * Create a 2D color plane from dark, light, and hue anchors.
4
+ *
5
+ * The plane interpolates between 4 corners:
6
+ * (0,0) = dark — origin (bottom-left)
7
+ * (1,0) = dark — saturation has no effect at lightness=0
8
+ * (0,1) = light — achromatic light (top-left)
9
+ * (1,1) = hue — full chromatic color (top-right)
10
+ *
11
+ * Create one plane per hue, reusing the same dark/light anchors:
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const red = new PlaneColorSpace('#1e1e2e', '#cdd6f4', '#f38ba8').size(6);
16
+ * const blue = new PlaneColorSpace('#1e1e2e', '#cdd6f4', '#89b4fa').size(6);
17
+ *
18
+ * red(3, 5) // → ColorAccessor (saturation=3, lightness=5)
19
+ * red(0, 3) // → achromatic at lightness 3
20
+ * red.palette // → string[36] (6²)
21
+ *
22
+ * // With different interpolation or output format:
23
+ * new PlaneColorSpace(dark, light, hue).interpolation('lab').format('rgb').size(8);
24
+ * ```
25
+ */
26
+ export declare class PlaneColorSpace {
27
+ private _dark;
28
+ private _light;
29
+ private _hue;
30
+ private _interpolation;
31
+ private _format;
32
+ constructor(dark: string, light: string, hue: string);
33
+ interpolation(mode: InterpolationMode): this;
34
+ format(fmt: ColorFormat): this;
35
+ size(stepsPerAxis: number): PlaneColorSpaceResult;
36
+ }
@@ -0,0 +1,8 @@
1
+ import type { ColorFormat, ColorInfo } from './types';
2
+ export declare class ReadOnlyBuilder {
3
+ private _color;
4
+ private _format?;
5
+ constructor(color: string);
6
+ format(fmt: ColorFormat): this;
7
+ generate(): ColorInfo | string;
8
+ }
@@ -0,0 +1,119 @@
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
+ }
108
+ /**
109
+ * The result returned by PlaneColorSpace.size().
110
+ * Callable with (saturation, lightness) to look up colors on the 2D plane.
111
+ */
112
+ export interface PlaneColorSpaceResult {
113
+ /** Look up a color by 2D coordinates (both 0-based, clamped to size-1) */
114
+ (saturation: number, lightness: number): ColorAccessor;
115
+ /** Full palette array (length = size²) */
116
+ palette: string[];
117
+ /** Steps per axis */
118
+ size: number;
119
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basiclines/rampa-sdk",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Programmatic JavaScript SDK for generating color palettes with rampa",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",