colorsort-js 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/LICENSE +21 -0
- package/README.md +17 -0
- package/dist/colorsort.js +5412 -0
- package/dist/colorsort.js.map +1 -0
- package/dist/colorsort.umd.cjs +5 -0
- package/dist/colorsort.umd.cjs.map +1 -0
- package/dist/trained.json +1804 -0
- package/dist/types/src/auto-sort.d.ts +1 -0
- package/dist/types/src/auto.d.ts +6 -0
- package/dist/types/src/color.d.ts +42 -0
- package/dist/types/src/fft.d.ts +3 -0
- package/dist/types/src/genetic-algo.d.ts +63 -0
- package/dist/types/src/index.d.ts +23 -0
- package/dist/types/src/method-runner.d.ts +21 -0
- package/dist/types/src/metrics-extended.d.ts +27 -0
- package/dist/types/src/metrics-fft.d.ts +44 -0
- package/dist/types/src/metrics-hilbert.d.ts +9 -0
- package/dist/types/src/metrics-spectral-similarity.d.ts +21 -0
- package/dist/types/src/metrics-spectral.d.ts +55 -0
- package/dist/types/src/metrics.d.ts +8 -0
- package/dist/types/src/randomizer.d.ts +1 -0
- package/dist/types/src/resample.d.ts +6 -0
- package/dist/types/src/similarity.d.ts +8 -0
- package/dist/types/src/sorting-methods/clustering.d.ts +34 -0
- package/dist/types/src/sorting-methods/genetic.d.ts +3 -0
- package/dist/types/src/sorting-methods/graph.d.ts +14 -0
- package/dist/types/src/sorting-methods/harmonize.d.ts +22 -0
- package/dist/types/src/sorting-methods/hilbert.d.ts +14 -0
- package/dist/types/src/sorting-methods/index.d.ts +21 -0
- package/dist/types/src/sorting-methods/momentum.d.ts +12 -0
- package/dist/types/src/sorting-methods/principal.d.ts +9 -0
- package/dist/types/src/sorting-methods/radial.d.ts +17 -0
- package/dist/types/src/sorting-methods/ramp.d.ts +77 -0
- package/dist/types/src/sorting-methods/raw.d.ts +7 -0
- package/dist/types/src/sorting-methods/spectral.d.ts +26 -0
- package/dist/types/src/spectral-edit.d.ts +53 -0
- package/dist/types/src/statistics.d.ts +12 -0
- package/dist/types/src/type-detect.d.ts +16 -0
- package/dist/types/src/type-relative.d.ts +2 -0
- package/dist/types/src/type-variances.d.ts +19 -0
- package/dist/types/src/uni-neighbors.d.ts +6 -0
- package/dist/types/src/uni-tsp.d.ts +2 -0
- package/dist/types/src/vector.d.ts +15 -0
- package/package.json +61 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function auto(colors: string[], DATA: any): any;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Vector3 } from './vector.ts';
|
|
2
|
+
import { UniColor } from './method-runner.ts';
|
|
3
|
+
export declare function oklch2hex([l, c, h]: Vector3): string;
|
|
4
|
+
export declare function oklab2hex([l, a, b]: Vector3): string;
|
|
5
|
+
export declare function oklch2oklab([l_, c, h]: Vector3): Vector3;
|
|
6
|
+
export declare function oklab2oklch([l_, a, b]: Vector3): Vector3;
|
|
7
|
+
export declare function hexToRgb(hex: string): [number, number, number];
|
|
8
|
+
export declare const gl: (a: any) => any;
|
|
9
|
+
export declare const cmyk: (a: any) => any;
|
|
10
|
+
export declare const oklab: (a: any) => any;
|
|
11
|
+
export declare const okhsl: (a: any) => any;
|
|
12
|
+
export declare const okhsv: (a: any) => any;
|
|
13
|
+
export declare const oklch: (a: any) => any;
|
|
14
|
+
export declare const lch: (a: any) => any;
|
|
15
|
+
export declare const lab: (a: any) => any;
|
|
16
|
+
export declare const hsl: (a: any) => any;
|
|
17
|
+
export declare const hsv: (a: any) => any;
|
|
18
|
+
export declare function nonH(H: number): H is never;
|
|
19
|
+
export declare const luminance: (a: any) => any;
|
|
20
|
+
export declare function compareLumLCH(a: string, b: string): number;
|
|
21
|
+
export declare function flatRgb(hexes: string[]): number[];
|
|
22
|
+
export declare function deltaE(a: string, b: string, x?: number, y?: number, z?: number): number;
|
|
23
|
+
export declare function normalizeLab(a: Vector3): number[];
|
|
24
|
+
export declare function distanceOk2([L1, a1, b1]: Vector3, [L2, a2, b2]: Vector3): number;
|
|
25
|
+
export declare function convertColors(colors: string[], model: ColorType): [UniColor, string][];
|
|
26
|
+
export type ColorType = 'hex' | 'rgb' | 'gl' | 'oklab' | 'oklch' | 'okhsl' | 'okhsv' | 'lab' | 'lab_norm' | 'lab_int' | 'lch' | 'hsv' | 'hsl' | 'cmyk';
|
|
27
|
+
export declare const COLOR_TYPES: {
|
|
28
|
+
readonly rgb: "rgb";
|
|
29
|
+
readonly oklab: "oklab";
|
|
30
|
+
readonly lab: "lab";
|
|
31
|
+
readonly lab_norm: "lab_norm";
|
|
32
|
+
readonly lab_int: "lab_int";
|
|
33
|
+
readonly oklch: "oklch";
|
|
34
|
+
readonly okhsl: "okhsl";
|
|
35
|
+
readonly okhsv: "okhsv";
|
|
36
|
+
readonly hex: "hex";
|
|
37
|
+
readonly hsv: "hsv";
|
|
38
|
+
readonly hsl: "hsl";
|
|
39
|
+
readonly lch: "lch";
|
|
40
|
+
readonly gl: "gl";
|
|
41
|
+
readonly cmyk: "cmyk";
|
|
42
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple Genetic Algorithm implementation for permutation problems
|
|
3
|
+
*/
|
|
4
|
+
export interface GAConfig<T, F> {
|
|
5
|
+
populationSize?: number;
|
|
6
|
+
generations?: number;
|
|
7
|
+
maxStagnation?: number;
|
|
8
|
+
mutationRate?: number;
|
|
9
|
+
crossoverRate?: number;
|
|
10
|
+
eliteSize?: number;
|
|
11
|
+
tournamentSize?: number;
|
|
12
|
+
random?: () => number;
|
|
13
|
+
fitness: (genome: T[]) => F;
|
|
14
|
+
seed: () => T[];
|
|
15
|
+
compare?: (a: F, b: F) => number;
|
|
16
|
+
onGeneration?: (stats: GenerationStats<T, F>) => void;
|
|
17
|
+
}
|
|
18
|
+
export interface Individual<T, F> {
|
|
19
|
+
genome: T[];
|
|
20
|
+
fitness: F;
|
|
21
|
+
}
|
|
22
|
+
export interface GenerationStats<T, F> {
|
|
23
|
+
generation: number;
|
|
24
|
+
bestFitness: F;
|
|
25
|
+
bestGenome: T[];
|
|
26
|
+
averageFitness: number;
|
|
27
|
+
}
|
|
28
|
+
export interface GAResult<T, F> {
|
|
29
|
+
bestGenome: T[];
|
|
30
|
+
bestFitness: F;
|
|
31
|
+
finalPopulation: Individual<T, F>[];
|
|
32
|
+
peakGeneration: number;
|
|
33
|
+
}
|
|
34
|
+
export declare class GeneticAlgorithm<T, F> {
|
|
35
|
+
private readonly populationSize;
|
|
36
|
+
private readonly generations;
|
|
37
|
+
private readonly maxStagnation;
|
|
38
|
+
private readonly mutationRate;
|
|
39
|
+
private readonly crossoverRate;
|
|
40
|
+
private readonly eliteSize;
|
|
41
|
+
private readonly tournamentSize;
|
|
42
|
+
private readonly random;
|
|
43
|
+
private readonly fitnessFunc;
|
|
44
|
+
private readonly seedFunc;
|
|
45
|
+
private readonly fitnessCompare;
|
|
46
|
+
private readonly onGeneration?;
|
|
47
|
+
private population;
|
|
48
|
+
private currentGeneration;
|
|
49
|
+
private bestIndividual;
|
|
50
|
+
private bestFitness;
|
|
51
|
+
private peakGeneration;
|
|
52
|
+
constructor(config: GAConfig<T, F>);
|
|
53
|
+
private initializePopulation;
|
|
54
|
+
private sortPopulation;
|
|
55
|
+
private updateBest;
|
|
56
|
+
private tournamentSelect;
|
|
57
|
+
private orderCrossover;
|
|
58
|
+
private swapMutate;
|
|
59
|
+
private shiftMutate;
|
|
60
|
+
private cheatMutate;
|
|
61
|
+
private evolve;
|
|
62
|
+
run(): GAResult<T, F>;
|
|
63
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { round3 } from './statistics.ts';
|
|
2
|
+
export { SORTING_METHODS } from './sorting-methods/index.ts';
|
|
3
|
+
export type { SortingMethod } from './sorting-methods/index.ts';
|
|
4
|
+
export { metrics } from './metrics.js';
|
|
5
|
+
export { detectPaletteType } from './type-detect.ts';
|
|
6
|
+
export type { PaletteType } from './type-detect.ts';
|
|
7
|
+
export { metricsEx, getMetricsExRange, metricsExQuality, metricsExQualitySum } from './metrics-extended.ts';
|
|
8
|
+
export type { MetricsEx } from './metrics-extended.ts';
|
|
9
|
+
export { flatRgb, oklab, oklch, gl, lch, lab, normalizeLab, oklch2hex, oklab2hex, oklch2oklab } from './color.ts';
|
|
10
|
+
export { randomizer } from './randomizer.ts';
|
|
11
|
+
export { metricsFftFingerprint } from './metrics-fft.ts';
|
|
12
|
+
export { cosineSimilarity } from './similarity.ts';
|
|
13
|
+
export { featuresLab } from './metrics-spectral.ts';
|
|
14
|
+
export { compareSpectralFeatures } from './metrics-spectral-similarity.ts';
|
|
15
|
+
export type { Fingerprint } from './metrics-fft.ts';
|
|
16
|
+
export type { StatsLabEx, MagnitudesLab } from './metrics-spectral.ts';
|
|
17
|
+
export { applySpectralProcessing } from './spectral-edit.ts';
|
|
18
|
+
export { fingerprintAverage, fingerprintMedian, fingerprintAverageWithoutOutliers } from './similarity.ts';
|
|
19
|
+
export { compareColors } from './vector.ts';
|
|
20
|
+
export { getAuto } from './auto.ts';
|
|
21
|
+
export declare const MASTER_LCH: (a: any) => any;
|
|
22
|
+
export declare const MASTER_ROUND: typeof round3;
|
|
23
|
+
export { auto } from './auto-sort.ts';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ColorType } from './color.ts';
|
|
2
|
+
import { Vector3, Vector4 } from './vector.ts';
|
|
3
|
+
export type UniColor = Vector3 | Vector4 | any;
|
|
4
|
+
export type ColorHelper = {
|
|
5
|
+
toColors(vectors: UniColor[]): string[];
|
|
6
|
+
toColor(vector: UniColor): string;
|
|
7
|
+
distance: Distance<UniColor>;
|
|
8
|
+
};
|
|
9
|
+
export type ColorHelperDelta = ColorHelper & {
|
|
10
|
+
delta: Distance<UniColor>;
|
|
11
|
+
};
|
|
12
|
+
export type Distance<T> = (a: T, b: T, ...args: any[]) => number;
|
|
13
|
+
export type Distance3 = Distance<Vector3>;
|
|
14
|
+
export type Distance4 = Distance<Vector4>;
|
|
15
|
+
export type DistanceU = Distance<UniColor>;
|
|
16
|
+
export type DistanceC = Distance<string>;
|
|
17
|
+
export type DistanceOptions = {
|
|
18
|
+
fn: Distance<any>;
|
|
19
|
+
color: boolean;
|
|
20
|
+
};
|
|
21
|
+
export declare function methodRunner<T>(colors: string[], fn: (this: T, vectors: UniColor[]) => UniColor[] | void, model?: ColorType, deltaMethod_?: Distance<any> | DistanceOptions, distanceMethod_?: Distance<any> | DistanceOptions): string[];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type MetricsLch<T> = {
|
|
2
|
+
L: T;
|
|
3
|
+
C: T;
|
|
4
|
+
H: T;
|
|
5
|
+
};
|
|
6
|
+
export type MetricsEx<T> = {
|
|
7
|
+
totalDistance: T;
|
|
8
|
+
avgAngleChange: T;
|
|
9
|
+
maxAngleChange: T;
|
|
10
|
+
meanDistance: T;
|
|
11
|
+
devDistance: T;
|
|
12
|
+
totalCurveDistance: T;
|
|
13
|
+
meanCurveDistance: T;
|
|
14
|
+
devCurveDistance: T;
|
|
15
|
+
lchAvgChange: MetricsLch<T>;
|
|
16
|
+
lchMaxChange: MetricsLch<T>;
|
|
17
|
+
lchDeviation: MetricsLch<T>;
|
|
18
|
+
curveRatio: T;
|
|
19
|
+
perceptualUniformity: T;
|
|
20
|
+
curveUniformity: T;
|
|
21
|
+
harmonicScore: T;
|
|
22
|
+
harmonicCurveScore: T;
|
|
23
|
+
};
|
|
24
|
+
export declare function metricsEx(colors: string[]): MetricsEx<number>;
|
|
25
|
+
export declare function getMetricsExRange(list: MetricsEx<number>[]): MetricsEx<[number, number]>;
|
|
26
|
+
export declare function metricsExQuality(value: MetricsEx<number>, range: MetricsEx<[number, number]>): MetricsEx<number>;
|
|
27
|
+
export declare function metricsExQualitySum(value: MetricsEx<number>): number;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Vector3 } from './vector.ts';
|
|
2
|
+
export type Analysis = {
|
|
3
|
+
type: string;
|
|
4
|
+
confidence: number;
|
|
5
|
+
features: {
|
|
6
|
+
chromaticRatio?: number;
|
|
7
|
+
achromaticCount?: number;
|
|
8
|
+
hueSpread?: number;
|
|
9
|
+
chromaticCount?: number;
|
|
10
|
+
largeGaps?: number;
|
|
11
|
+
avgGap?: number;
|
|
12
|
+
maxGap?: number;
|
|
13
|
+
chromaVariance?: number;
|
|
14
|
+
hueHighFreqRatio?: number;
|
|
15
|
+
chromaHighFreqRatio?: number;
|
|
16
|
+
};
|
|
17
|
+
fingerprint?: Fingerprint;
|
|
18
|
+
spectra?: {
|
|
19
|
+
hueDeltaMags: number[];
|
|
20
|
+
chromaMags: number[];
|
|
21
|
+
lightnessMags: number[];
|
|
22
|
+
hueDeltaEnergy: number;
|
|
23
|
+
chromaEnergy: number;
|
|
24
|
+
lightnessEnergy: number;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export type Fingerprint = [number, number, number, number, number, number, number];
|
|
28
|
+
export type SpectrumData = {
|
|
29
|
+
freq: number;
|
|
30
|
+
hueDelta: number;
|
|
31
|
+
chroma: number;
|
|
32
|
+
lightness: number;
|
|
33
|
+
};
|
|
34
|
+
export declare function metricsFftFingerprint(lchColors: Vector3[]): {
|
|
35
|
+
analysis: Analysis;
|
|
36
|
+
spectrumData: SpectrumData[];
|
|
37
|
+
};
|
|
38
|
+
export declare function compareFingerprints(fp1: Fingerprint, fp2: Fingerprint): {
|
|
39
|
+
cosine: number;
|
|
40
|
+
euclidean: number;
|
|
41
|
+
manhattan: number;
|
|
42
|
+
similarity: number;
|
|
43
|
+
interpretation: string;
|
|
44
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MagnitudesLab, StatsLabEx } from './metrics-spectral.ts';
|
|
2
|
+
interface SimilarityResult {
|
|
3
|
+
overall: number;
|
|
4
|
+
structural: number;
|
|
5
|
+
perceptual: number;
|
|
6
|
+
breakdown: {
|
|
7
|
+
smoothnessSimilarity: number;
|
|
8
|
+
complexitySimilarity: number;
|
|
9
|
+
energyDistributionSimilarity: number;
|
|
10
|
+
centroidSimilarity: number;
|
|
11
|
+
rolloffSimilarity: number;
|
|
12
|
+
spectrumCorrelation: number;
|
|
13
|
+
};
|
|
14
|
+
interpretation: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Compare two palettes using their spectral features
|
|
18
|
+
* Returns similarity score from 0 (completely different) to 1 (identical)
|
|
19
|
+
*/
|
|
20
|
+
export declare function compareSpectralFeatures(features1: StatsLabEx & MagnitudesLab, features2: StatsLabEx & MagnitudesLab): SimilarityResult;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Vector3 } from './vector.ts';
|
|
2
|
+
export interface ChromaticLch {
|
|
3
|
+
chromatic: Vector3[];
|
|
4
|
+
achromatic: Vector3[];
|
|
5
|
+
}
|
|
6
|
+
export declare function chromaticLch(lchColors: Vector3[], threshold?: number): ChromaticLch;
|
|
7
|
+
export interface MagnitudesLch {
|
|
8
|
+
lightnessMags: number[];
|
|
9
|
+
chromaMags: number[];
|
|
10
|
+
hueDeltaMags: number[];
|
|
11
|
+
hues: number[];
|
|
12
|
+
hueDeltas: number[];
|
|
13
|
+
sortedHues: number[];
|
|
14
|
+
chromas: number[];
|
|
15
|
+
lightnesses: number[];
|
|
16
|
+
}
|
|
17
|
+
export declare function fftLch(lchColors: Vector3[]): MagnitudesLch;
|
|
18
|
+
export interface Stats {
|
|
19
|
+
dominantFrequencies: number[];
|
|
20
|
+
smoothness: number;
|
|
21
|
+
totalEnergy: number;
|
|
22
|
+
probabilities: number[];
|
|
23
|
+
complexity: number;
|
|
24
|
+
}
|
|
25
|
+
export declare function magnitudesStats(magnitudes: number[]): Stats;
|
|
26
|
+
export declare function featuresLch(lchColors: Vector3[]): MagnitudesLch & Stats;
|
|
27
|
+
export interface MagnitudesLab {
|
|
28
|
+
lightnessMags: number[];
|
|
29
|
+
aMags: number[];
|
|
30
|
+
bMags: number[];
|
|
31
|
+
chromaMags: number[];
|
|
32
|
+
}
|
|
33
|
+
export declare function magnitudesLab(labColors: Vector3[]): MagnitudesLab;
|
|
34
|
+
export interface StatsLab {
|
|
35
|
+
lightness: number;
|
|
36
|
+
a: number;
|
|
37
|
+
b: number;
|
|
38
|
+
chroma: number;
|
|
39
|
+
}
|
|
40
|
+
export declare function statsLab({ lightnessMags, aMags, bMags, chromaMags }: MagnitudesLab, calculate: Function): StatsLab;
|
|
41
|
+
export interface StatsLabEx {
|
|
42
|
+
spectralCentroid: StatsLab;
|
|
43
|
+
spectralSpread: StatsLab;
|
|
44
|
+
spectralRolloff: StatsLab;
|
|
45
|
+
energyRatios: {
|
|
46
|
+
lowFreq: number;
|
|
47
|
+
midFreq: number;
|
|
48
|
+
highFreq: number;
|
|
49
|
+
};
|
|
50
|
+
smoothness: number;
|
|
51
|
+
complexity: number;
|
|
52
|
+
dominantFrequencies: number[];
|
|
53
|
+
}
|
|
54
|
+
export declare function statsLabsEx(magnitudesLab: MagnitudesLab): StatsLabEx;
|
|
55
|
+
export declare function featuresLab(labColors: Vector3[]): StatsLabEx & MagnitudesLab;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function randomizer(p?: number): () => number;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Vector3 } from './vector.ts';
|
|
2
|
+
export declare function snapInterpolator(values: number[], samples: number): (sample: number) => number;
|
|
3
|
+
export declare function resamplePaletteSnap(labColors: Vector3[], samples?: number): Vector3[];
|
|
4
|
+
export declare function downsamplePalette(labColors: Vector3[], targetSize: number): Vector3[];
|
|
5
|
+
export declare function resamplePaletteLinear(labColors: Vector3[], samples?: number): Vector3[];
|
|
6
|
+
export declare function resampleLinear(values: number[], samples?: number): number[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function cosineSimilarity(a: number[], b: number[]): number;
|
|
2
|
+
export declare function manhattanDistance(fp1: number[], fp2: number[]): number;
|
|
3
|
+
export declare function euclideanDistance(a: number[], b: number[]): number;
|
|
4
|
+
export declare function gaussianSimilarity(a: number, b: number, sigma: number): number;
|
|
5
|
+
export declare function pearsonCorrelation(a: number[], b: number[]): number;
|
|
6
|
+
export declare function fingerprintAverage(fingerprints: number[][]): number[];
|
|
7
|
+
export declare function fingerprintMedian(fingerprints: number[][]): number[];
|
|
8
|
+
export declare function fingerprintAverageWithoutOutliers(fingerprints: number[][]): number[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Vector3 } from '../vector.ts';
|
|
2
|
+
export declare function sortByHierarchicalClustering(colors: Vector3[], linkage?: 'single' | 'complete' | 'average', traversal?: 'depth-first' | 'breadth-first' | 'balanced'): Vector3[];
|
|
3
|
+
/**
|
|
4
|
+
* K-means clustering followed by ordering clusters and points within clusters
|
|
5
|
+
*/
|
|
6
|
+
export declare function sortByKMeans(colors: Vector3[], k?: number, maxIterations?: number): Vector3[];
|
|
7
|
+
export declare function sortByDBSCAN(colors: Vector3[], eps?: number, minPts?: number): Vector3[];
|
|
8
|
+
export declare function cluster(colors: string[], model?: 'rgb' | 'lab', linkage?: 'single' | 'complete' | 'average', traversal?: 'depth-first' | 'breadth-first' | 'balanced'): string[];
|
|
9
|
+
export declare namespace cluster {
|
|
10
|
+
var params: {
|
|
11
|
+
name: string;
|
|
12
|
+
values: string[];
|
|
13
|
+
}[];
|
|
14
|
+
}
|
|
15
|
+
export declare function kMeans(colors: string[], model?: 'rgb' | 'lab', k?: number, iterations?: number): string[];
|
|
16
|
+
export declare namespace kMeans {
|
|
17
|
+
var params: ({
|
|
18
|
+
name: string;
|
|
19
|
+
values: string[];
|
|
20
|
+
} | {
|
|
21
|
+
name: string;
|
|
22
|
+
values: number[];
|
|
23
|
+
})[];
|
|
24
|
+
}
|
|
25
|
+
export declare function dbScan(colors: string[], model?: 'rgb' | 'lab', eps?: number, pts?: number): string[];
|
|
26
|
+
export declare namespace dbScan {
|
|
27
|
+
var params: ({
|
|
28
|
+
name: string;
|
|
29
|
+
values: string[];
|
|
30
|
+
} | {
|
|
31
|
+
name: string;
|
|
32
|
+
values: number[];
|
|
33
|
+
})[];
|
|
34
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Vector3 } from '../vector.ts';
|
|
2
|
+
import { Distance3 } from '../method-runner.ts';
|
|
3
|
+
export declare function graphDeltaE(colors: Vector3[], delta: Distance3): Vector3[];
|
|
4
|
+
export declare function graph(colors: string[], post?: 'tsp' | 'raw'): string[];
|
|
5
|
+
export declare namespace graph {
|
|
6
|
+
var params: {
|
|
7
|
+
name: string;
|
|
8
|
+
values: string[];
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
11
|
+
export declare function graphWeighted(colors: string[]): string[];
|
|
12
|
+
export declare function graphWeightedPlusPlus(colors: string[]): string[];
|
|
13
|
+
export declare function graphWeightedAdaptive1(colors: string[]): string[];
|
|
14
|
+
export declare function graphWeightedAdaptive2(colors: string[]): string[];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Vector3 } from '../vector.ts';
|
|
2
|
+
interface HarmonizeOptions {
|
|
3
|
+
selectStart: (colors: Vector3[]) => Vector3;
|
|
4
|
+
distance: (a: Vector3, b: Vector3) => number;
|
|
5
|
+
compareColors: (a: Vector3, b: Vector3) => number;
|
|
6
|
+
}
|
|
7
|
+
export declare function harmonize(colors: Vector3[], options: HarmonizeOptions): Vector3[];
|
|
8
|
+
export declare function harmonizeModel(colors: string[], model?: 'hsl' | 'hsv' | 'oklch' | 'oklab' | 'okhsl' | 'okhsv' | 'lch' | 'lab' | 'rgb' | 'cmyk', start?: 'bright' | 'dark', distance?: 'euclidean' | 'delta'): string[];
|
|
9
|
+
export declare namespace harmonizeModel {
|
|
10
|
+
var params: {
|
|
11
|
+
name: string;
|
|
12
|
+
values: string[];
|
|
13
|
+
}[];
|
|
14
|
+
}
|
|
15
|
+
export declare function harmonizeDelta(colors: string[], start?: 'bright' | 'dark'): string[];
|
|
16
|
+
export declare namespace harmonizeDelta {
|
|
17
|
+
var params: {
|
|
18
|
+
name: string;
|
|
19
|
+
values: string[];
|
|
20
|
+
}[];
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Vector3 } from '../vector.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Convert 3D (0 to 255) coordinates to Hilbert curve index
|
|
4
|
+
* This ensures spatially close points stay close in the sorted order
|
|
5
|
+
*/
|
|
6
|
+
export declare function hilbertIndex([x, y, z]: [number, number, number]): number;
|
|
7
|
+
export declare function sortByHilbertCurve(colors: Vector3[]): Vector3[];
|
|
8
|
+
export declare function hilbert(colors: string[], model?: 'rgb' | 'lab_int'): string[];
|
|
9
|
+
export declare namespace hilbert {
|
|
10
|
+
var params: {
|
|
11
|
+
name: string;
|
|
12
|
+
values: string[];
|
|
13
|
+
}[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type SortingFunction = Function & {
|
|
2
|
+
params?: {
|
|
3
|
+
name: string;
|
|
4
|
+
values: any[];
|
|
5
|
+
}[];
|
|
6
|
+
valid?: Function;
|
|
7
|
+
};
|
|
8
|
+
export type SortingMethod = {
|
|
9
|
+
name: string;
|
|
10
|
+
mid: string;
|
|
11
|
+
description?: {
|
|
12
|
+
model?: any | null;
|
|
13
|
+
method?: any | null;
|
|
14
|
+
diff?: any | null;
|
|
15
|
+
};
|
|
16
|
+
fn: SortingFunction;
|
|
17
|
+
speed?: number;
|
|
18
|
+
valid?: Function;
|
|
19
|
+
};
|
|
20
|
+
export declare const SORTING_METHODS_RAW: SortingMethod[];
|
|
21
|
+
export declare const SORTING_METHODS: SortingMethod[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function momentumClosestOklab(colors: string[]): string[];
|
|
2
|
+
export declare function momentumClosestBestOklab(colors: string[], post?: 'raw' | 'tsp'): string[];
|
|
3
|
+
export declare namespace momentumClosestBestOklab {
|
|
4
|
+
var params: {
|
|
5
|
+
name: string;
|
|
6
|
+
values: string[];
|
|
7
|
+
}[];
|
|
8
|
+
}
|
|
9
|
+
export declare function momentumClosestBestDeltaEOklab(colors: string[]): string[];
|
|
10
|
+
export declare function momentumInlinestOklab(colors: string[]): string[];
|
|
11
|
+
export declare function momentumInlinestDeltaEOklab(colors: string[]): string[];
|
|
12
|
+
export declare function momentumInlinestDeltaEPlusOklab(colors: string[]): string[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Vector3 } from '../vector.ts';
|
|
2
|
+
export declare function sortByPrincipalComponent(colors: Vector3[]): Vector3[];
|
|
3
|
+
export declare function principal(colors: string[], model: 'gl' | 'lab' | 'oklab', post?: 'raw' | 'tsp' | 'tsp-adapt'): string[];
|
|
4
|
+
export declare namespace principal {
|
|
5
|
+
var params: {
|
|
6
|
+
name: string;
|
|
7
|
+
values: string[];
|
|
8
|
+
}[];
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Vector3 } from '../vector.ts';
|
|
2
|
+
export declare function sortByHslSpiral(this: any, colors: Vector3[], model?: 'hsl' | 'hsv' | 'lch' | 'okhsl' | 'okhsv' | 'oklch', mode?: 'outward' | 'inward' | 'bottom-up' | 'top-down'): Vector3[];
|
|
3
|
+
export declare function spiral(colors: string[], model?: 'hsl' | 'hsv' | 'lch' | 'okhsl' | 'okhsv' | 'oklch', mode?: 'outward' | 'inward' | 'bottom-up' | 'top-down'): string[];
|
|
4
|
+
export declare namespace spiral {
|
|
5
|
+
var params: {
|
|
6
|
+
name: string;
|
|
7
|
+
values: string[];
|
|
8
|
+
}[];
|
|
9
|
+
}
|
|
10
|
+
export declare function sortByHslCylindrical(colors: Vector3[], model?: 'hsl' | 'hsv' | 'lch' | 'okhsl' | 'okhsv' | 'oklch', direction?: 'ascending' | 'descending'): Vector3[];
|
|
11
|
+
export declare function cylindrical(colors: string[], model?: 'hsl' | 'hsv' | 'lch' | 'okhsl' | 'okhsv' | 'oklch', direction?: 'ascending' | 'descending'): string[];
|
|
12
|
+
export declare namespace cylindrical {
|
|
13
|
+
var params: {
|
|
14
|
+
name: string;
|
|
15
|
+
values: string[];
|
|
16
|
+
}[];
|
|
17
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Vector3 } from '../vector.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Sort colors into hue-based ramps
|
|
4
|
+
* Strategy:
|
|
5
|
+
* 1. Group by hue buckets (e.g., reds, oranges, yellows, etc.)
|
|
6
|
+
* 2. Within each bucket, sort by chroma (vivid to muted) then lightness
|
|
7
|
+
* 3. Handle achromatic colors (grays) separately
|
|
8
|
+
*/
|
|
9
|
+
export declare function sortColorsIntoHueRamps(colors: Vector3[], hueBuckets?: number, // Number of hue buckets (default: 12)
|
|
10
|
+
achromaticThreshold?: number): Vector3[];
|
|
11
|
+
/**
|
|
12
|
+
* Alternative: Sort into a single smooth gradient
|
|
13
|
+
* This creates one continuous ramp through the entire hue spectrum
|
|
14
|
+
*/
|
|
15
|
+
export declare function sortIntoSmoothGradient(colors: Vector3[]): Vector3[];
|
|
16
|
+
/**
|
|
17
|
+
* Auto-detect hue clusters using gap detection algorithm
|
|
18
|
+
*/
|
|
19
|
+
export declare function detectHueClusters(colors: Vector3[], minGapDegrees?: number, // Minimum gap to split clusters
|
|
20
|
+
achromaticThreshold?: number): Vector3[][];
|
|
21
|
+
/**
|
|
22
|
+
* Sort colors using nearest-neighbor traveling salesman approach
|
|
23
|
+
* This creates smooth visual progressions
|
|
24
|
+
*/
|
|
25
|
+
export declare function sortColorsByNearestNeighbor(colors: Vector3[]): Vector3[];
|
|
26
|
+
/**
|
|
27
|
+
* Sort colors into perceptual hue-based ramps
|
|
28
|
+
*
|
|
29
|
+
* Strategy:
|
|
30
|
+
* 1. Achromatic colors (very low chroma) sorted by lightness
|
|
31
|
+
* 2. Chromatic colors sorted by composite key: Hue Zone → Chroma Stratum → Lightness
|
|
32
|
+
*
|
|
33
|
+
* This creates natural color ramps that work well for palettes of 60+ colors,
|
|
34
|
+
* organizing them into manageable visual groups while maintaining smooth gradients.
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
export declare function sortColorsByHueRamps2(colors: Vector3[], // Oklch, Vector3 is [number, number, number]
|
|
38
|
+
achromaticThreshold?: number, // Chroma below this is considered achromatic (default: 0.03)
|
|
39
|
+
hueZoneSize?: number, // Degrees per hue zone (default: 40)
|
|
40
|
+
hueRotation?: number, // Starting hue angle (default: 270)
|
|
41
|
+
chromaOrder?: 'vivid' | 'muted'): Vector3[];
|
|
42
|
+
export declare function sortMultiRampPalette2(lchColors: Vector3[], numRamps?: number): Vector3[];
|
|
43
|
+
export declare function ramp(colors: string[]): string[];
|
|
44
|
+
export declare function rampa(colors: string[], gap?: number, threshold?: number, strategy?: 'cl' | 'lc'): string[];
|
|
45
|
+
export declare namespace rampa {
|
|
46
|
+
var params: ({
|
|
47
|
+
name: string;
|
|
48
|
+
values: number[];
|
|
49
|
+
} | {
|
|
50
|
+
name: string;
|
|
51
|
+
values: string[];
|
|
52
|
+
})[];
|
|
53
|
+
}
|
|
54
|
+
export declare function rampb(colors: string[]): string[];
|
|
55
|
+
export declare function rampc(colors: string[]): string[];
|
|
56
|
+
export declare function rampd(colors: string[]): string[];
|
|
57
|
+
export declare function rampe(colors: string[]): string[];
|
|
58
|
+
export declare function rampf(colors: string[]): string[];
|
|
59
|
+
export declare function rampg(colors: string[], threshold: number, zone: number, rotation: number, order: 'vivid' | 'muted'): string[];
|
|
60
|
+
export declare namespace rampg {
|
|
61
|
+
var params: ({
|
|
62
|
+
name: string;
|
|
63
|
+
values: number[];
|
|
64
|
+
} | {
|
|
65
|
+
name: string;
|
|
66
|
+
values: string[];
|
|
67
|
+
})[];
|
|
68
|
+
}
|
|
69
|
+
export declare function ramph(colors: string[], ramps?: number): string[];
|
|
70
|
+
export declare namespace ramph {
|
|
71
|
+
var params: {
|
|
72
|
+
name: string;
|
|
73
|
+
values: number[];
|
|
74
|
+
}[];
|
|
75
|
+
var valid: (colors: Vector3[], ramps: number) => boolean;
|
|
76
|
+
}
|
|
77
|
+
export declare function rampi(colors: string[]): string[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Vector3 } from '../vector.ts';
|
|
2
|
+
import { MagnitudesLch, Stats } from '../metrics-spectral.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Strategy 1: Match the spectral smoothness of a reference palette
|
|
5
|
+
*
|
|
6
|
+
* Analyzes the reference palette's frequency distribution and sorts
|
|
7
|
+
* the target colors to create a similar smoothness profile.
|
|
8
|
+
*/
|
|
9
|
+
export declare function sortBySpectralSmoothness(colorsLch: Vector3[], referenceFeatures: MagnitudesLch & Stats, achromaticThreshold?: number): Vector3[];
|
|
10
|
+
/**
|
|
11
|
+
* Strategy 2: Match the chroma wave pattern of a reference palette
|
|
12
|
+
*
|
|
13
|
+
* Uses the chroma FFT pattern to create similar saturation rhythms.
|
|
14
|
+
*/
|
|
15
|
+
export declare function sortByChromaWave(lchColors: Vector3[], referenceFeatures: MagnitudesLch & Stats, achromaticThreshold?: number): Vector3[];
|
|
16
|
+
/**
|
|
17
|
+
* Strategy 3: Reconstruct spectral template
|
|
18
|
+
*
|
|
19
|
+
* Uses the reference palette's dominant frequencies to determine
|
|
20
|
+
* how many distinct hue groups to create.
|
|
21
|
+
*/
|
|
22
|
+
export declare function sortBySpectralTemplate(lchColors: Vector3[], referenceFeatures: MagnitudesLch & Stats, achromaticThreshold?: number): Vector3[];
|
|
23
|
+
/**
|
|
24
|
+
* Strategy 4: Hybrid approach - detect palette type and apply best strategy
|
|
25
|
+
*/
|
|
26
|
+
export declare function sortBySpectralGuidance(colors: Vector3[], referenceFeatures: MagnitudesLch & Stats, achromaticThreshold?: number): Vector3[];
|