···3030export { Textarea } from '$lib/components/base/textarea';
3131export { Tooltip } from '$lib/components/base/tooltip';
32323333+// colors components
3434+export { default as ColorGradientPicker } from '$lib/components/colors/color-gradient-picker/ColorGradientPicker.svelte';
3535+export { ColorPicker, PopoverColorPicker } from '$lib/components/colors/color-picker';
3636+export { ColorSelect } from '$lib/components/colors/color-select';
3737+3338// extra components
3434-export { default as ColorGradientPicker } from '$lib/components/extra/color-gradient-picker/ColorGradientPicker.svelte';
3535-export { ColorPicker, PopoverColorPicker } from '$lib/components/extra/color-picker/';
3639export { default as Excalidraw } from '$lib/components/extra/excalidraw/Excalidraw.svelte';
3740export { default as Undraw } from '$lib/components/extra/undraw/Undraw.svelte';
3838-export { ColorSelect } from '$lib/components/extra/color-select';
3941export { default as Stopwatch } from '$lib/components/extra/stopwatch/Stopwatch.svelte';
4042export { default as Timer } from '$lib/components/extra/timer/Timer.svelte';
4143export { StopwatchState } from '$lib/components/extra/stopwatch/StopwatchState.svelte';
···11+export { default as ColorPicker } from './base/ColorPicker.svelte';
22+export { default as PopoverColorPicker } from './popover/PopoverColorPicker.svelte';
···11-export { default as ColorPicker } from './base/ColorPicker.svelte';
22-export { default as PopoverColorPicker } from './popover/PopoverColorPicker.svelte';
···11+// adapted from https://github.com/CaptainCodeman/svelte-color-select
22+33+export { default } from './ColorPicker.svelte';
44+export { default as ColorPicker } from './ColorPicker.svelte';
55+export type { RGB, OKlab, OKhsv } from './color';
···11-// adapted from https://github.com/CaptainCodeman/svelte-color-select
22-33-export { default } from './ColorPicker.svelte';
44-export { default as ColorPicker } from './ColorPicker.svelte';
55-export type { RGB, OKlab, OKhsv } from './color';
···11+// Copyright(c) 2021 Björn Ottosson
22+//
33+// Permission is hereby granted, free of charge, to any person obtaining a copy of
44+// this softwareand associated documentation files(the "Software"), to deal in
55+// the Software without restriction, including without limitation the rights to
66+// use, copy, modify, merge, publish, distribute, sublicense, and /or sell copies
77+// of the Software, and to permit persons to whom the Software is furnished to do
88+// so, subject to the following conditions :
99+// The above copyright noticeand this permission notice shall be included in all
1010+// copies or substantial portions of the Software.
1111+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1212+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1313+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
1414+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1515+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1616+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1717+// SOFTWARE.
1818+1919+precision mediump float;
2020+#define M_PI 3.1415926536
2121+2222+float cbrt(float x) {
2323+ return sign(x)*pow(abs(x), 1.0 / 3.0);
2424+}
2525+2626+float srgb_transfer_function(float a) {
2727+ return .0031308 >= a ? 12.92 * a : 1.055 * pow(a, .4166666666666667) - .055;
2828+}
2929+3030+vec3 oklab_to_linear_srgb(vec3 c) {
3131+ float l_ = c.x + 0.3963377774 * c.y + 0.2158037573 * c.z;
3232+ float m_ = c.x - 0.1055613458 * c.y - 0.0638541728 * c.z;
3333+ float s_ = c.x - 0.0894841775 * c.y - 1.2914855480 * c.z;
3434+3535+ float l = l_ * l_ * l_;
3636+ float m = m_ * m_ * m_;
3737+ float s = s_ * s_ * s_;
3838+3939+ return vec3(
4040+ +4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
4141+ -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
4242+ -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s
4343+ );
4444+}
4545+4646+// Finds the maximum saturation possible for a given hue that fits in sRGB
4747+// Saturation here is defined as S = C/L
4848+// a and b must be normalized so a^2 + b^2 == 1
4949+float compute_max_saturation(float a, float b) {
5050+ // Max saturation will be when one of r, g or b goes below zero.
5151+5252+ // Select different coefficients depending on which component goes below zero first
5353+ float k0, k1, k2, k3, k4, wl, wm, ws;
5454+5555+ if (-1.88170328 * a - 0.80936493 * b > 1.0)
5656+ {
5757+ // Red component
5858+ k0 = +1.19086277; k1 = +1.76576728; k2 = +0.59662641; k3 = +0.75515197; k4 = +0.56771245;
5959+ wl = +4.0767416621; wm = -3.3077115913; ws = +0.2309699292;
6060+ }
6161+ else if (1.81444104 * a - 1.19445276 * b > 1.0)
6262+ {
6363+ // Green component
6464+ k0 = +0.73956515; k1 = -0.45954404; k2 = +0.08285427; k3 = +0.12541070; k4 = +0.14503204;
6565+ wl = -1.2684380046; wm = +2.6097574011; ws = -0.3413193965;
6666+ }
6767+ else
6868+ {
6969+ // Blue component
7070+ k0 = +1.35733652; k1 = -0.00915799; k2 = -1.15130210; k3 = -0.50559606; k4 = +0.00692167;
7171+ wl = -0.0041960863; wm = -0.7034186147; ws = +1.7076147010;
7272+ }
7373+7474+ // Approximate max saturation using a polynomial:
7575+ float S = k0 + k1 * a + k2 * b + k3 * a * a + k4 * a * b;
7676+7777+ // Do one step Halley's method to get closer
7878+ // this gives an error less than 10e6, except for some blue hues where the dS/dh is close to infinite
7979+ // this should be sufficient for most applications, otherwise do two/three steps
8080+8181+ float k_l = +0.3963377774 * a + 0.2158037573 * b;
8282+ float k_m = -0.1055613458 * a - 0.0638541728 * b;
8383+ float k_s = -0.0894841775 * a - 1.2914855480 * b;
8484+8585+ {
8686+ float l_ = 1.0 + S * k_l;
8787+ float m_ = 1.0 + S * k_m;
8888+ float s_ = 1.0 + S * k_s;
8989+9090+ float l = l_ * l_ * l_;
9191+ float m = m_ * m_ * m_;
9292+ float s = s_ * s_ * s_;
9393+9494+ float l_dS = 3.0 * k_l * l_ * l_;
9595+ float m_dS = 3.0 * k_m * m_ * m_;
9696+ float s_dS = 3.0 * k_s * s_ * s_;
9797+9898+ float l_dS2 = 6.0 * k_l * k_l * l_;
9999+ float m_dS2 = 6.0 * k_m * k_m * m_;
100100+ float s_dS2 = 6.0 * k_s * k_s * s_;
101101+102102+ float f = wl * l + wm * m + ws * s;
103103+ float f1 = wl * l_dS + wm * m_dS + ws * s_dS;
104104+ float f2 = wl * l_dS2 + wm * m_dS2 + ws * s_dS2;
105105+106106+ S = S - f * f1 / (f1 * f1 - 0.5 * f * f2);
107107+ }
108108+109109+ return S;
110110+}
111111+112112+// finds L_cusp and C_cusp for a given hue
113113+// a and b must be normalized so a^2 + b^2 == 1
114114+vec2 find_cusp(float a, float b) {
115115+ // First, find the maximum saturation (saturation S = C/L)
116116+ float S_cusp = compute_max_saturation(a, b);
117117+118118+ // Convert to linear sRGB to find the first point where at least one of r,g or b >= 1:
119119+ vec3 rgb_at_max = oklab_to_linear_srgb(vec3( 1, S_cusp * a, S_cusp * b ));
120120+ float L_cusp = cbrt(1.0 / max(max(rgb_at_max.r, rgb_at_max.g), rgb_at_max.b));
121121+ float C_cusp = L_cusp * S_cusp;
122122+123123+ return vec2( L_cusp , C_cusp );
124124+}
125125+126126+float toe_inv(float x) {
127127+ float k_1 = 0.206;
128128+ float k_2 = 0.03;
129129+ float k_3 = (1.0 + k_1) / (1.0 + k_2);
130130+ return (x * x + k_1 * x) / (k_3 * (x + k_2));
131131+}
132132+133133+vec2 to_ST(vec2 cusp) {
134134+ float L = cusp.x;
135135+ float C = cusp.y;
136136+ return vec2( C / L, C / (1.0 - L) );
137137+}
138138+139139+vec3 okhsv_to_srgb(vec3 hsv) {
140140+ float h = hsv.x;
141141+ float s = hsv.y;
142142+ float v = hsv.z;
143143+144144+ float a_ = cos(2.0 * M_PI * h);
145145+ float b_ = sin(2.0 * M_PI * h);
146146+147147+ vec2 cusp = find_cusp(a_, b_);
148148+ vec2 ST_max = to_ST(cusp);
149149+ float S_max = ST_max.x;
150150+ float T_max = ST_max.y;
151151+ float S_0 = 0.5;
152152+ float k = 1.0- S_0 / S_max;
153153+154154+ // first we compute L and V as if the gamut is a perfect triangle:
155155+156156+ // L, C when v==1:
157157+ float L_v = 1.0 - s * S_0 / (S_0 + T_max - T_max * k * s);
158158+ float C_v = s * T_max * S_0 / (S_0 + T_max - T_max * k * s);
159159+160160+ float L = v * L_v;
161161+ float C = v * C_v;
162162+163163+ // then we compensate for both toe and the curved top part of the triangle:
164164+ float L_vt = toe_inv(L_v);
165165+ float C_vt = C_v * L_vt / L_v;
166166+167167+ float L_new = toe_inv(L);
168168+ C = C * L_new / L;
169169+ L = L_new;
170170+171171+ vec3 rgb_scale = oklab_to_linear_srgb(vec3( L_vt, a_ * C_vt, b_ * C_vt ));
172172+ float scale_L = cbrt(1.0 / max(max(rgb_scale.r, rgb_scale.g), max(rgb_scale.b, 0.0)));
173173+174174+ L = L * scale_L;
175175+ C = C * scale_L;
176176+177177+ vec3 rgb = oklab_to_linear_srgb(vec3( L, C * a_, C * b_ ));
178178+ return vec3(
179179+ srgb_transfer_function(rgb.r),
180180+ srgb_transfer_function(rgb.g),
181181+ srgb_transfer_function(rgb.b)
182182+ );
183183+}
···11+shaders adapted from https://github.com/dokozero/okcolor
22+the source in this folder is minified and included in a ts file to enable svelte-package to be used
···11-// Copyright(c) 2021 Björn Ottosson
22-//
33-// Permission is hereby granted, free of charge, to any person obtaining a copy of
44-// this softwareand associated documentation files(the "Software"), to deal in
55-// the Software without restriction, including without limitation the rights to
66-// use, copy, modify, merge, publish, distribute, sublicense, and /or sell copies
77-// of the Software, and to permit persons to whom the Software is furnished to do
88-// so, subject to the following conditions :
99-// The above copyright noticeand this permission notice shall be included in all
1010-// copies or substantial portions of the Software.
1111-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1212-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1313-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
1414-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1515-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1616-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1717-// SOFTWARE.
1818-1919-precision mediump float;
2020-#define M_PI 3.1415926536
2121-2222-float cbrt(float x) {
2323- return sign(x)*pow(abs(x), 1.0 / 3.0);
2424-}
2525-2626-float srgb_transfer_function(float a) {
2727- return .0031308 >= a ? 12.92 * a : 1.055 * pow(a, .4166666666666667) - .055;
2828-}
2929-3030-vec3 oklab_to_linear_srgb(vec3 c) {
3131- float l_ = c.x + 0.3963377774 * c.y + 0.2158037573 * c.z;
3232- float m_ = c.x - 0.1055613458 * c.y - 0.0638541728 * c.z;
3333- float s_ = c.x - 0.0894841775 * c.y - 1.2914855480 * c.z;
3434-3535- float l = l_ * l_ * l_;
3636- float m = m_ * m_ * m_;
3737- float s = s_ * s_ * s_;
3838-3939- return vec3(
4040- +4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
4141- -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
4242- -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s
4343- );
4444-}
4545-4646-// Finds the maximum saturation possible for a given hue that fits in sRGB
4747-// Saturation here is defined as S = C/L
4848-// a and b must be normalized so a^2 + b^2 == 1
4949-float compute_max_saturation(float a, float b) {
5050- // Max saturation will be when one of r, g or b goes below zero.
5151-5252- // Select different coefficients depending on which component goes below zero first
5353- float k0, k1, k2, k3, k4, wl, wm, ws;
5454-5555- if (-1.88170328 * a - 0.80936493 * b > 1.0)
5656- {
5757- // Red component
5858- k0 = +1.19086277; k1 = +1.76576728; k2 = +0.59662641; k3 = +0.75515197; k4 = +0.56771245;
5959- wl = +4.0767416621; wm = -3.3077115913; ws = +0.2309699292;
6060- }
6161- else if (1.81444104 * a - 1.19445276 * b > 1.0)
6262- {
6363- // Green component
6464- k0 = +0.73956515; k1 = -0.45954404; k2 = +0.08285427; k3 = +0.12541070; k4 = +0.14503204;
6565- wl = -1.2684380046; wm = +2.6097574011; ws = -0.3413193965;
6666- }
6767- else
6868- {
6969- // Blue component
7070- k0 = +1.35733652; k1 = -0.00915799; k2 = -1.15130210; k3 = -0.50559606; k4 = +0.00692167;
7171- wl = -0.0041960863; wm = -0.7034186147; ws = +1.7076147010;
7272- }
7373-7474- // Approximate max saturation using a polynomial:
7575- float S = k0 + k1 * a + k2 * b + k3 * a * a + k4 * a * b;
7676-7777- // Do one step Halley's method to get closer
7878- // this gives an error less than 10e6, except for some blue hues where the dS/dh is close to infinite
7979- // this should be sufficient for most applications, otherwise do two/three steps
8080-8181- float k_l = +0.3963377774 * a + 0.2158037573 * b;
8282- float k_m = -0.1055613458 * a - 0.0638541728 * b;
8383- float k_s = -0.0894841775 * a - 1.2914855480 * b;
8484-8585- {
8686- float l_ = 1.0 + S * k_l;
8787- float m_ = 1.0 + S * k_m;
8888- float s_ = 1.0 + S * k_s;
8989-9090- float l = l_ * l_ * l_;
9191- float m = m_ * m_ * m_;
9292- float s = s_ * s_ * s_;
9393-9494- float l_dS = 3.0 * k_l * l_ * l_;
9595- float m_dS = 3.0 * k_m * m_ * m_;
9696- float s_dS = 3.0 * k_s * s_ * s_;
9797-9898- float l_dS2 = 6.0 * k_l * k_l * l_;
9999- float m_dS2 = 6.0 * k_m * k_m * m_;
100100- float s_dS2 = 6.0 * k_s * k_s * s_;
101101-102102- float f = wl * l + wm * m + ws * s;
103103- float f1 = wl * l_dS + wm * m_dS + ws * s_dS;
104104- float f2 = wl * l_dS2 + wm * m_dS2 + ws * s_dS2;
105105-106106- S = S - f * f1 / (f1 * f1 - 0.5 * f * f2);
107107- }
108108-109109- return S;
110110-}
111111-112112-// finds L_cusp and C_cusp for a given hue
113113-// a and b must be normalized so a^2 + b^2 == 1
114114-vec2 find_cusp(float a, float b) {
115115- // First, find the maximum saturation (saturation S = C/L)
116116- float S_cusp = compute_max_saturation(a, b);
117117-118118- // Convert to linear sRGB to find the first point where at least one of r,g or b >= 1:
119119- vec3 rgb_at_max = oklab_to_linear_srgb(vec3( 1, S_cusp * a, S_cusp * b ));
120120- float L_cusp = cbrt(1.0 / max(max(rgb_at_max.r, rgb_at_max.g), rgb_at_max.b));
121121- float C_cusp = L_cusp * S_cusp;
122122-123123- return vec2( L_cusp , C_cusp );
124124-}
125125-126126-float toe_inv(float x) {
127127- float k_1 = 0.206;
128128- float k_2 = 0.03;
129129- float k_3 = (1.0 + k_1) / (1.0 + k_2);
130130- return (x * x + k_1 * x) / (k_3 * (x + k_2));
131131-}
132132-133133-vec2 to_ST(vec2 cusp) {
134134- float L = cusp.x;
135135- float C = cusp.y;
136136- return vec2( C / L, C / (1.0 - L) );
137137-}
138138-139139-vec3 okhsv_to_srgb(vec3 hsv) {
140140- float h = hsv.x;
141141- float s = hsv.y;
142142- float v = hsv.z;
143143-144144- float a_ = cos(2.0 * M_PI * h);
145145- float b_ = sin(2.0 * M_PI * h);
146146-147147- vec2 cusp = find_cusp(a_, b_);
148148- vec2 ST_max = to_ST(cusp);
149149- float S_max = ST_max.x;
150150- float T_max = ST_max.y;
151151- float S_0 = 0.5;
152152- float k = 1.0- S_0 / S_max;
153153-154154- // first we compute L and V as if the gamut is a perfect triangle:
155155-156156- // L, C when v==1:
157157- float L_v = 1.0 - s * S_0 / (S_0 + T_max - T_max * k * s);
158158- float C_v = s * T_max * S_0 / (S_0 + T_max - T_max * k * s);
159159-160160- float L = v * L_v;
161161- float C = v * C_v;
162162-163163- // then we compensate for both toe and the curved top part of the triangle:
164164- float L_vt = toe_inv(L_v);
165165- float C_vt = C_v * L_vt / L_v;
166166-167167- float L_new = toe_inv(L);
168168- C = C * L_new / L;
169169- L = L_new;
170170-171171- vec3 rgb_scale = oklab_to_linear_srgb(vec3( L_vt, a_ * C_vt, b_ * C_vt ));
172172- float scale_L = cbrt(1.0 / max(max(rgb_scale.r, rgb_scale.g), max(rgb_scale.b, 0.0)));
173173-174174- L = L * scale_L;
175175- C = C * scale_L;
176176-177177- vec3 rgb = oklab_to_linear_srgb(vec3( L, C * a_, C * b_ ));
178178- return vec3(
179179- srgb_transfer_function(rgb.r),
180180- srgb_transfer_function(rgb.g),
181181- srgb_transfer_function(rgb.b)
182182- );
183183-}
···11-shaders adapted from https://github.com/dokozero/okcolor
22-the source in this folder is minified and included in a ts file to enable svelte-package to be used