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