Skip to content

Commit

Permalink
Add exhaustive web case (to match C++)
Browse files Browse the repository at this point in the history
  • Loading branch information
louix committed Jan 17, 2024
1 parent 4c45ea1 commit 7e747d6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions package/src/skia/web/JsiSkColor.ts
@@ -1,4 +1,4 @@
import type { SkColor, Color as InputColor } from "../types";
import type { Color as InputColor, SkColor } from "../types";

const alphaf = (c: number) => ((c >> 24) & 255) / 255;
const red = (c: number) => (c >> 16) & 255;
Expand Down Expand Up @@ -329,12 +329,17 @@ export const Color = (color: InputColor): SkColor => {
rgba[2] / 255,
rgba[3]
);
} else {
} else if (typeof color === "number") {
return Float32Array.of(
red(color) / 255,
green(color) / 255,
blue(color) / 255,
alphaf(color)
);
} else {
// Exhaustive case (though not possible on the type level, could be possible at runtime)
throw new Error(
`Skia.Color expected number, Float32Array, number[], or string and got: ${color}`
);
}
};

0 comments on commit 7e747d6

Please sign in to comment.