diff --git a/color-module/src/schemes/q_style/color_set.rs b/color-module/src/schemes/q_style/color_set.rs index 2a1a33a..b729eba 100644 --- a/color-module/src/schemes/q_style/color_set.rs +++ b/color-module/src/schemes/q_style/color_set.rs @@ -25,28 +25,37 @@ pub struct ColorSet { fn fit_to_wacg(reference: &Oklch, neutral_swatch: &NeutralSwatch, ratio: f32) -> Oklch { let reference_luma = map_oklch_to_luma(reference); let mut new_target = neutral_swatch.get(reference.l); - let quick_factor: f32 = if reference.l <= 0.5 { 0.05 } else { -0.05 }; - let fine_factor: f32 = if reference.l <= 0.5 { 0.01 } else { -0.01 }; + let factor: f32 = if reference.l <= 0.5 { 0.01 } else { -0.01 }; let match_wacg = |original: &Oklch, reference: &Luma| { let luma = map_oklch_to_luma(original); luma.relative_contrast(*reference) }; - while match_wacg(&new_target, &reference_luma) < ratio { - new_target.l = new_target.l * (1.0 + quick_factor); - if new_target.l > 1.0 { - new_target.l = 1.0; + let mut last_contrast_ratio = 0.0; + let mut repeat_count = 0; + let mut target_ratio = ratio; + loop { + let contrast_ratio = match_wacg(&new_target, &reference_luma); + if contrast_ratio >= target_ratio { break; } - } - while match_wacg(&new_target, &reference_luma) < ratio { - new_target.l = new_target.l * (1.0 + fine_factor); - if new_target.l > 1.0 { - new_target.l = 1.0; - break; + if (contrast_ratio - last_contrast_ratio).abs() / last_contrast_ratio < 0.001 { + repeat_count += 1; + if repeat_count > 20 { + target_ratio *= 1.0 - 0.01; + repeat_count = 0; + } + } else { + repeat_count = 0; } + last_contrast_ratio = contrast_ratio; + new_target = Oklch { + l: new_target.l * (1.0 + factor), + ..new_target + }; } + new_target } diff --git a/src/color_functions/color_module.d.ts b/src/color_functions/color_module.d.ts index 7fa0a0e..f719dca 100644 --- a/src/color_functions/color_module.d.ts +++ b/src/color_functions/color_module.d.ts @@ -14,20 +14,20 @@ export function relative_differ_in_oklch(color: string, other: string): OklchDif export function tint_scale(basic_color: string, mixed_color: string): MixReversing; export function shade_scale(basic_color: string, mixed_color: string): MixReversing; export function shift_hue(color: string, degree: number): string; -export function analogous_30(color: string): (string)[]; -export function analogous_60(color: string): (string)[]; +export function analogous_30(color: string): string[]; +export function analogous_60(color: string): string[]; export function complementary(color: string): string; -export function split_complementary(color: string): (string)[]; -export function tetradic(color: string): (string)[]; -export function triadic(color: string): (string)[]; -export function generate_palette_from_color(reference_color: string, swatch_amount: number, minimum_lightness: number, maximum_lightness: number, use_reference_color?: boolean, reference_color_bias?: number): (string)[]; +export function split_complementary(color: string): string[]; +export function tetradic(color: string): string[]; +export function triadic(color: string): string[]; +export function generate_palette_from_color(reference_color: string, swatch_amount: number, minimum_lightness: number, maximum_lightness: number, use_reference_color?: boolean | null, reference_color_bias?: number | null): string[]; export function color_categories(): any; -export function search_color_cards(tag: string, category?: string): any; +export function search_color_cards(tag: string, category?: string | null): any; export function generate_material_design_3_scheme(source_color: string, error_color: string, custom_colors: any): any; export function generate_material_design_2_scheme(primary_color: string, secondary_color: string, error_color: string, custom_colors: any): any; export function generate_q_scheme_automatically(primary_color: string, danger_color: string, success_color: string, warning_color: string, info_color: string, fg_color: string, bg_color: string, setting: SchemeSetting): any; -export function generate_q_scheme_manually(primary_color: string, secondary_color: string | undefined, tertiary_color: string | undefined, accent_color: string | undefined, danger_color: string, success_color: string, warning_color: string, info_color: string, fg_color: string, bg_color: string, setting: SchemeSetting): any; -export function generate_swatch_scheme(colors: (SwatchEntry)[], setting: SwatchSchemeSetting): any; +export function generate_q_scheme_manually(primary_color: string, secondary_color: string | null | undefined, tertiary_color: string | null | undefined, accent_color: string | null | undefined, danger_color: string, success_color: string, warning_color: string, info_color: string, fg_color: string, bg_color: string, setting: SchemeSetting): any; +export function generate_swatch_scheme(colors: SwatchEntry[], setting: SwatchSchemeSetting): any; export function lighten(color: string, percent: number): string; export function lighten_absolute(color: string, value: number): string; export function darken(color: string, percent: number): string; @@ -35,9 +35,9 @@ export function darken_absolute(color: string, value: number): string; export function mix(color1: string, color2: string, percent: number): string; export function tint(color: string, percent: number): string; export function shade(color: string, percent: number): string; -export function series(color: string, expand_amount: number, step: number): (string)[]; -export function tonal_lighten_series(color: string, expand_amount: number, step: number): (string)[]; -export function tonal_darken_series(color: string, expand_amount: number, step: number): (string)[]; +export function series(color: string, expand_amount: number, step: number): string[]; +export function tonal_lighten_series(color: string, expand_amount: number, step: number): string[]; +export function tonal_darken_series(color: string, expand_amount: number, step: number): string[]; export function represent_rgb(color: string): Uint8Array; export function rgb_to_hex(r: number, g: number, b: number): string; export function represent_hsl(color: string): Float32Array; @@ -220,13 +220,13 @@ export interface InitOutput { readonly __wbg_set_mixreversing_b_factor: (a: number, b: number) => void; readonly __wbg_get_mixreversing_average: (a: number) => number; readonly __wbg_set_mixreversing_average: (a: number, b: number) => void; - readonly __wbg_hsldifference_free: (a: number, b: number) => void; - readonly __wbg_get_hsldifference_hue: (a: number) => number; - readonly __wbg_set_hsldifference_hue: (a: number, b: number) => void; - readonly __wbg_get_hsldifference_saturation: (a: number) => number; - readonly __wbg_set_hsldifference_saturation: (a: number, b: number) => void; - readonly __wbg_get_hsldifference_lightness: (a: number) => number; - readonly __wbg_set_hsldifference_lightness: (a: number, b: number) => void; + readonly __wbg_rgbdifference_free: (a: number, b: number) => void; + readonly __wbg_get_rgbdifference_r: (a: number) => number; + readonly __wbg_set_rgbdifference_r: (a: number, b: number) => void; + readonly __wbg_get_rgbdifference_g: (a: number) => number; + readonly __wbg_set_rgbdifference_g: (a: number, b: number) => void; + readonly __wbg_get_rgbdifference_b: (a: number) => number; + readonly __wbg_set_rgbdifference_b: (a: number, b: number) => void; readonly __wbg_swatchentry_free: (a: number, b: number) => void; readonly __wbg_get_swatchentry_name: (a: number) => [number, number]; readonly __wbg_set_swatchentry_name: (a: number, b: number, c: number) => void; @@ -253,13 +253,13 @@ export interface InitOutput { readonly represent_hct: (a: number, b: number) => [number, number, number, number]; readonly hct_to_hex: (a: number, b: number, c: number) => [number, number, number, number]; readonly wacg_relative_contrast: (a: number, b: number, c: number, d: number) => [number, number, number]; - readonly __wbg_rgbdifference_free: (a: number, b: number) => void; - readonly __wbg_get_rgbdifference_r: (a: number) => number; - readonly __wbg_set_rgbdifference_r: (a: number, b: number) => void; - readonly __wbg_get_rgbdifference_g: (a: number) => number; - readonly __wbg_set_rgbdifference_g: (a: number, b: number) => void; - readonly __wbg_get_rgbdifference_b: (a: number) => number; - readonly __wbg_set_rgbdifference_b: (a: number, b: number) => void; + readonly __wbg_hsldifference_free: (a: number, b: number) => void; + readonly __wbg_get_hsldifference_hue: (a: number) => number; + readonly __wbg_set_hsldifference_hue: (a: number, b: number) => void; + readonly __wbg_get_hsldifference_saturation: (a: number) => number; + readonly __wbg_set_hsldifference_saturation: (a: number, b: number) => void; + readonly __wbg_get_hsldifference_lightness: (a: number) => number; + readonly __wbg_set_hsldifference_lightness: (a: number, b: number) => void; readonly __wbg_swatchschemesetting_free: (a: number, b: number) => void; readonly __wbg_get_swatchschemesetting_amount: (a: number) => number; readonly __wbg_set_swatchschemesetting_amount: (a: number, b: number) => void; diff --git a/src/color_functions/color_module.js b/src/color_functions/color_module.js index 0f408ba..5d9f690 100644 --- a/src/color_functions/color_module.js +++ b/src/color_functions/color_module.js @@ -410,7 +410,7 @@ function getArrayJsValueFromWasm0(ptr, len) { } /** * @param {string} color - * @returns {(string)[]} + * @returns {string[]} */ export function analogous_30(color) { const ptr0 = passStringToWasm0(color, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); @@ -426,7 +426,7 @@ export function analogous_30(color) { /** * @param {string} color - * @returns {(string)[]} + * @returns {string[]} */ export function analogous_60(color) { const ptr0 = passStringToWasm0(color, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); @@ -467,7 +467,7 @@ export function complementary(color) { /** * @param {string} color - * @returns {(string)[]} + * @returns {string[]} */ export function split_complementary(color) { const ptr0 = passStringToWasm0(color, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); @@ -483,7 +483,7 @@ export function split_complementary(color) { /** * @param {string} color - * @returns {(string)[]} + * @returns {string[]} */ export function tetradic(color) { const ptr0 = passStringToWasm0(color, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); @@ -499,7 +499,7 @@ export function tetradic(color) { /** * @param {string} color - * @returns {(string)[]} + * @returns {string[]} */ export function triadic(color) { const ptr0 = passStringToWasm0(color, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); @@ -523,9 +523,9 @@ function _assertClass(instance, klass) { * @param {number} swatch_amount * @param {number} minimum_lightness * @param {number} maximum_lightness - * @param {boolean | undefined} [use_reference_color] - * @param {number | undefined} [reference_color_bias] - * @returns {(string)[]} + * @param {boolean | null} [use_reference_color] + * @param {number | null} [reference_color_bias] + * @returns {string[]} */ export function generate_palette_from_color(reference_color, swatch_amount, minimum_lightness, maximum_lightness, use_reference_color, reference_color_bias) { const ptr0 = passStringToWasm0(reference_color, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); @@ -552,7 +552,7 @@ export function color_categories() { /** * @param {string} tag - * @param {string | undefined} [category] + * @param {string | null} [category] * @returns {any} */ export function search_color_cards(tag, category) { @@ -643,9 +643,9 @@ export function generate_q_scheme_automatically(primary_color, danger_color, suc /** * @param {string} primary_color - * @param {string | undefined} secondary_color - * @param {string | undefined} tertiary_color - * @param {string | undefined} accent_color + * @param {string | null | undefined} secondary_color + * @param {string | null | undefined} tertiary_color + * @param {string | null | undefined} accent_color * @param {string} danger_color * @param {string} success_color * @param {string} warning_color @@ -687,15 +687,15 @@ export function generate_q_scheme_manually(primary_color, secondary_color, terti function passArrayJsValueToWasm0(array, malloc) { const ptr = malloc(array.length * 4, 4) >>> 0; - const mem = getDataViewMemory0(); for (let i = 0; i < array.length; i++) { - mem.setUint32(ptr + 4 * i, addToExternrefTable0(array[i]), true); + const add = addToExternrefTable0(array[i]); + getDataViewMemory0().setUint32(ptr + 4 * i, add, true); } WASM_VECTOR_LEN = array.length; return ptr; } /** - * @param {(SwatchEntry)[]} colors + * @param {SwatchEntry[]} colors * @param {SwatchSchemeSetting} setting * @returns {any} */ @@ -900,7 +900,7 @@ export function shade(color, percent) { * @param {string} color * @param {number} expand_amount * @param {number} step - * @returns {(string)[]} + * @returns {string[]} */ export function series(color, expand_amount, step) { const ptr0 = passStringToWasm0(color, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); @@ -918,7 +918,7 @@ export function series(color, expand_amount, step) { * @param {string} color * @param {number} expand_amount * @param {number} step - * @returns {(string)[]} + * @returns {string[]} */ export function tonal_lighten_series(color, expand_amount, step) { const ptr0 = passStringToWasm0(color, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); @@ -936,7 +936,7 @@ export function tonal_lighten_series(color, expand_amount, step) { * @param {string} color * @param {number} expand_amount * @param {number} step - * @returns {(string)[]} + * @returns {string[]} */ export function tonal_darken_series(color, expand_amount, step) { const ptr0 = passStringToWasm0(color, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); @@ -2045,31 +2045,31 @@ function __wbg_get_imports() { getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); }; - imports.wbg.__wbg_buffer_61b7ce01341d7f88 = function(arg0) { + imports.wbg.__wbg_buffer_609cc3eee51ed158 = function(arg0) { const ret = arg0.buffer; return ret; }; - imports.wbg.__wbg_call_b0d8e36992d9900d = function() { return handleError(function (arg0, arg1) { + imports.wbg.__wbg_call_672a4d21634d4a24 = function() { return handleError(function (arg0, arg1) { const ret = arg0.call(arg1); return ret; }, arguments) }; - imports.wbg.__wbg_done_f22c1561fa919baa = function(arg0) { + imports.wbg.__wbg_done_769e5ede4b31c67b = function(arg0) { const ret = arg0.done; return ret; }; - imports.wbg.__wbg_entries_4f2bb9b0d701c0f6 = function(arg0) { + imports.wbg.__wbg_entries_3265d4158b33e5dc = function(arg0) { const ret = Object.entries(arg0); return ret; }; - imports.wbg.__wbg_get_9aa3dff3f0266054 = function(arg0, arg1) { - const ret = arg0[arg1 >>> 0]; - return ret; - }; - imports.wbg.__wbg_get_bbccf8970793c087 = function() { return handleError(function (arg0, arg1) { + imports.wbg.__wbg_get_67b2ba62fc30de12 = function() { return handleError(function (arg0, arg1) { const ret = Reflect.get(arg0, arg1); return ret; }, arguments) }; - imports.wbg.__wbg_instanceof_ArrayBuffer_670ddde44cdb2602 = function(arg0) { + imports.wbg.__wbg_get_b9b93047fe3cf45b = function(arg0, arg1) { + const ret = arg0[arg1 >>> 0]; + return ret; + }; + imports.wbg.__wbg_instanceof_ArrayBuffer_e14585432e3737fc = function(arg0) { let result; try { result = arg0 instanceof ArrayBuffer; @@ -2079,7 +2079,7 @@ function __wbg_get_imports() { const ret = result; return ret; }; - imports.wbg.__wbg_instanceof_Uint8Array_28af5bc19d6acad8 = function(arg0) { + imports.wbg.__wbg_instanceof_Uint8Array_17156bcf118086a9 = function(arg0) { let result; try { result = arg0 instanceof Uint8Array; @@ -2089,52 +2089,52 @@ function __wbg_get_imports() { const ret = result; return ret; }; - imports.wbg.__wbg_iterator_23604bb983791576 = function() { + imports.wbg.__wbg_iterator_9a24c88df860dc65 = function() { const ret = Symbol.iterator; return ret; }; - imports.wbg.__wbg_length_65d1cd11729ced11 = function(arg0) { + imports.wbg.__wbg_length_a446193dc22c12f8 = function(arg0) { const ret = arg0.length; return ret; }; - imports.wbg.__wbg_length_d65cf0786bfc5739 = function(arg0) { + imports.wbg.__wbg_length_e2d2a49132c1b256 = function(arg0) { const ret = arg0.length; return ret; }; - imports.wbg.__wbg_new_254fa9eac11932ae = function() { - const ret = new Array(); - return ret; - }; - imports.wbg.__wbg_new_3ff5b33b1ce712df = function(arg0) { - const ret = new Uint8Array(arg0); - return ret; - }; - imports.wbg.__wbg_new_688846f374351c92 = function() { + imports.wbg.__wbg_new_405e22f390576ce2 = function() { const ret = new Object(); return ret; }; - imports.wbg.__wbg_new_bc96c6a1c0786643 = function() { + imports.wbg.__wbg_new_5e0be73521bc8c17 = function() { const ret = new Map(); return ret; }; - imports.wbg.__wbg_next_01dd9234a5bf6d05 = function() { return handleError(function (arg0) { - const ret = arg0.next(); + imports.wbg.__wbg_new_78feb108b6472713 = function() { + const ret = new Array(); return ret; - }, arguments) }; - imports.wbg.__wbg_next_137428deb98342b0 = function(arg0) { + }; + imports.wbg.__wbg_new_a12002a7f91c75be = function(arg0) { + const ret = new Uint8Array(arg0); + return ret; + }; + imports.wbg.__wbg_next_25feadfc0913fea9 = function(arg0) { const ret = arg0.next; return ret; }; - imports.wbg.__wbg_set_1d80752d0d5f0b21 = function(arg0, arg1, arg2) { + imports.wbg.__wbg_next_6574e1a8a62d1055 = function() { return handleError(function (arg0) { + const ret = arg0.next(); + return ret; + }, arguments) }; + imports.wbg.__wbg_set_37837023f3d740e8 = function(arg0, arg1, arg2) { arg0[arg1 >>> 0] = arg2; }; - imports.wbg.__wbg_set_23d69db4e5c66a6e = function(arg0, arg1, arg2) { - arg0.set(arg1, arg2 >>> 0); - }; imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) { arg0[arg1] = arg2; }; - imports.wbg.__wbg_set_76818dc3c59a63d5 = function(arg0, arg1, arg2) { + imports.wbg.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) { + arg0.set(arg1, arg2 >>> 0); + }; + imports.wbg.__wbg_set_8fc6bf8a5b1071d1 = function(arg0, arg1, arg2) { const ret = arg0.set(arg1, arg2); return ret; }; @@ -2142,7 +2142,7 @@ function __wbg_get_imports() { const ret = SwatchEntry.__unwrap(arg0); return ret; }; - imports.wbg.__wbg_value_4c32fd138a88eee2 = function(arg0) { + imports.wbg.__wbg_value_cd1ffa7b1ab794f1 = function(arg0) { const ret = arg0.value; return ret; }; diff --git a/src/color_functions/color_module_bg.wasm b/src/color_functions/color_module_bg.wasm index 28dc56b..d571489 100644 Binary files a/src/color_functions/color_module_bg.wasm and b/src/color_functions/color_module_bg.wasm differ diff --git a/src/color_functions/color_module_bg.wasm.d.ts b/src/color_functions/color_module_bg.wasm.d.ts index 22688f0..314b6de 100644 --- a/src/color_functions/color_module_bg.wasm.d.ts +++ b/src/color_functions/color_module_bg.wasm.d.ts @@ -79,13 +79,13 @@ export const __wbg_get_mixreversing_b_factor: (a: number) => number; export const __wbg_set_mixreversing_b_factor: (a: number, b: number) => void; export const __wbg_get_mixreversing_average: (a: number) => number; export const __wbg_set_mixreversing_average: (a: number, b: number) => void; -export const __wbg_hsldifference_free: (a: number, b: number) => void; -export const __wbg_get_hsldifference_hue: (a: number) => number; -export const __wbg_set_hsldifference_hue: (a: number, b: number) => void; -export const __wbg_get_hsldifference_saturation: (a: number) => number; -export const __wbg_set_hsldifference_saturation: (a: number, b: number) => void; -export const __wbg_get_hsldifference_lightness: (a: number) => number; -export const __wbg_set_hsldifference_lightness: (a: number, b: number) => void; +export const __wbg_rgbdifference_free: (a: number, b: number) => void; +export const __wbg_get_rgbdifference_r: (a: number) => number; +export const __wbg_set_rgbdifference_r: (a: number, b: number) => void; +export const __wbg_get_rgbdifference_g: (a: number) => number; +export const __wbg_set_rgbdifference_g: (a: number, b: number) => void; +export const __wbg_get_rgbdifference_b: (a: number) => number; +export const __wbg_set_rgbdifference_b: (a: number, b: number) => void; export const __wbg_swatchentry_free: (a: number, b: number) => void; export const __wbg_get_swatchentry_name: (a: number) => [number, number]; export const __wbg_set_swatchentry_name: (a: number, b: number, c: number) => void; @@ -112,13 +112,13 @@ export const oklch_to_hex: (a: number, b: number, c: number) => [number, number, export const represent_hct: (a: number, b: number) => [number, number, number, number]; export const hct_to_hex: (a: number, b: number, c: number) => [number, number, number, number]; export const wacg_relative_contrast: (a: number, b: number, c: number, d: number) => [number, number, number]; -export const __wbg_rgbdifference_free: (a: number, b: number) => void; -export const __wbg_get_rgbdifference_r: (a: number) => number; -export const __wbg_set_rgbdifference_r: (a: number, b: number) => void; -export const __wbg_get_rgbdifference_g: (a: number) => number; -export const __wbg_set_rgbdifference_g: (a: number, b: number) => void; -export const __wbg_get_rgbdifference_b: (a: number) => number; -export const __wbg_set_rgbdifference_b: (a: number, b: number) => void; +export const __wbg_hsldifference_free: (a: number, b: number) => void; +export const __wbg_get_hsldifference_hue: (a: number) => number; +export const __wbg_set_hsldifference_hue: (a: number, b: number) => void; +export const __wbg_get_hsldifference_saturation: (a: number) => number; +export const __wbg_set_hsldifference_saturation: (a: number, b: number) => void; +export const __wbg_get_hsldifference_lightness: (a: number) => number; +export const __wbg_set_hsldifference_lightness: (a: number, b: number) => void; export const __wbg_swatchschemesetting_free: (a: number, b: number) => void; export const __wbg_get_swatchschemesetting_amount: (a: number) => number; export const __wbg_set_swatchschemesetting_amount: (a: number, b: number) => void;