增加WASM的调用错误防御。
This commit is contained in:
parent
22755fa60a
commit
05bceaeb06
|
@ -62,27 +62,32 @@ export function ColorStand({ title, color }: ColorStandProps) {
|
||||||
if (isNil(color)) {
|
if (isNil(color)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
switch (viewColor) {
|
try {
|
||||||
case 'hex':
|
switch (viewColor) {
|
||||||
return color;
|
case 'hex':
|
||||||
case 'rgb': {
|
return color;
|
||||||
const rgb = colorFn?.represent_rgb(color);
|
case 'rgb': {
|
||||||
return `rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`;
|
const rgb = colorFn?.represent_rgb(color);
|
||||||
|
return `rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`;
|
||||||
|
}
|
||||||
|
case 'hsl': {
|
||||||
|
const hsl = colorFn?.represent_hsl(color);
|
||||||
|
return `hsl(${hsl[0]}, ${hsl[1]}%, ${hsl[2]}%)`;
|
||||||
|
}
|
||||||
|
case 'lab': {
|
||||||
|
const lab = colorFn?.represent_lab(color);
|
||||||
|
return `lab(${lab[0]}, ${lab[1]}, ${lab[2]})`;
|
||||||
|
}
|
||||||
|
case 'oklch': {
|
||||||
|
const oklch = colorFn?.represent_oklch(color);
|
||||||
|
return `oklch(${oklch[0]}%, ${oklch[1]}, ${oklch[2]})`;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
case 'hsl': {
|
} catch (e) {
|
||||||
const hsl = colorFn?.represent_hsl(color);
|
console.error('[ColorStand Convert]', e);
|
||||||
return `hsl(${hsl[0]}, ${hsl[1]}%, ${hsl[2]}%)`;
|
return null;
|
||||||
}
|
|
||||||
case 'lab': {
|
|
||||||
const lab = colorFn?.represent_lab(color);
|
|
||||||
return `lab(${lab[0]}, ${lab[1]}, ${lab[2]})`;
|
|
||||||
}
|
|
||||||
case 'oklch': {
|
|
||||||
const oklch = colorFn?.represent_oklch(color);
|
|
||||||
return `oklch(${oklch[0]}%, ${oklch[1]}, ${oklch[2]})`;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}, [viewColor, color]);
|
}, [viewColor, color]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user