nixos-config/subprojects/bahaghari/lib/tinted-theming.nix

46 lines
1.3 KiB
Nix
Raw Normal View History

{ pkgs, lib }:
2024-02-23 12:37:06 +00:00
let
isBaseX = i: palette:
let
paletteNames = pkgs.lib.attrNames palette;
maxDigitLength = pkgs.lib.lists.length (pkgs.lib.toBaseDigits 10 i);
mkBaseAttr = hex: "base${lib.hex.pad maxDigitLength hex}";
schemeNames = builtins.map mkBaseAttr (lib.hex.range 0 (i - 1));
2024-02-23 12:37:06 +00:00
in
2024-02-25 10:20:13 +00:00
(pkgs.lib.count (name: pkgs.lib.elem name schemeNames) paletteNames) == i;
2024-02-23 12:37:06 +00:00
in
{
# TODO: Return a Nix object to generate a Tinted Theming color scheme from an
# image.
generateScheme = image: { };
/* A very naive implementation of checking whether the given palette is a
valid Base16 palette. It simply checks if `base00` to `base0F` is present.
Type: isBase16 :: Attrs -> Bool
Example:
isBase16 (bahaghariLib.importYAML ./base16.yml).palette
=> true
isBase16 (bahaghariLib.importYAML ./base16-scheme-with-missing-base0F.yml).palette
=> false
*/
2024-02-23 12:37:06 +00:00
isBase16 = isBaseX 16;
/* Similar to `isBase16` but for Base24 schemes. It considers the scheme as
valid if `base00` to `base17` from the palette are present.
Type: isBase24 :: Attrs -> Bool
Example:
isBase24 (bahaghariLib.importYAML ./base24.yml).palette
=> true
isBase24 (bahaghariLib.importYAML ./base24-scheme-with-missing-base0F.yml).palette
=> false
*/
2024-02-23 12:37:06 +00:00
isBase24 = isBaseX 24;
}