bahaghari/lib/tinted-theming: update formatting and comments

This commit is contained in:
Gabriel Arazas 2024-03-15 17:30:15 +08:00
parent 2b5b7cf50a
commit ef69085e0d
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360

View File

@ -13,6 +13,42 @@ let
(lib.count (name: lib.elem name schemeNames) paletteNames) == i; (lib.count (name: lib.elem name schemeNames) paletteNames) == i;
in in
rec { rec {
/* Imports a Base16 scheme. This also handles converting the legacy Base16
schema into the new one if it's detected. Take note, every single token
that is not part of the legacy proper is assumed to be part of the
`palette` of the new schema.
:::{.note}
This is the main entrypoint of the Bahaghari library Tinted Theming
subset. It is expected that most users will use this.
:::
Type: importScheme :: Path -> Attrs
Example:
importScheme ./legacy-base16-scheme.yml
=> {
system = "base16";
name = "Scheme name";
author = "Scheme author";
palette = {
# All legacy token that are not included in the old standard proper
# are placed here. This is typically something like `background`,
# `foreground`, and whatnot that are added for enriching the palette
# or just for semantics for the theme designers.
};
}
*/
importScheme = yamlpath:
let
scheme = self.importYAML yamlpath;
in
assert lib.assertMsg (isValidScheme scheme || isLegacyScheme scheme)
"bahaghariLib.tinted-theming.importScheme: given data is not a valid Tinted Theming scheme";
if isLegacyScheme scheme
then modernizeLegacyScheme scheme
else scheme;
# TODO: Return a Nix object to generate a Tinted Theming color scheme from an # TODO: Return a Nix object to generate a Tinted Theming color scheme from an
# image. # image.
generateScheme = image: { }; generateScheme = image: { };
@ -24,10 +60,10 @@ rec {
Type: isBase16 :: Attrs -> Bool Type: isBase16 :: Attrs -> Bool
Example: Example:
isBase16 (bahaghariLib.tinted-theming.importScheme ./base16.yml) isBase16 (bahaghariLib.tinted-theming.importScheme ./base16.yml).palette
=> true => true
isBase16 (bahaghariLib.tinted-theming.importScheme ./base16-scheme-with-missing-base0F.yml) isBase16 (bahaghariLib.tinted-theming.importScheme ./base16-scheme-with-missing-base0F.yml).palette
=> false => false
*/ */
isBase16 = isBaseX 16; isBase16 = isBaseX 16;
@ -38,10 +74,10 @@ rec {
Type: isBase24 :: Attrs -> Bool Type: isBase24 :: Attrs -> Bool
Example: Example:
isBase24 (bahaghariLib.tinted-theming.importScheme ./base24.yml) isBase24 (bahaghariLib.tinted-theming.importScheme ./base24.yml).palette
=> true => true
isBase24 (bahaghariLib.tinted-theming.importScheme ./base24-scheme-with-missing-base0F.yml) isBase24 (bahaghariLib.tinted-theming.importScheme ./base24-scheme-with-missing-base0F.yml).palette
=> false => false
*/ */
isBase24 = isBaseX 24; isBase24 = isBaseX 24;
@ -52,10 +88,10 @@ rec {
Type: isValidScheme :: Attrs -> Bool Type: isValidScheme :: Attrs -> Bool
Example: Example:
isValidScheme (bahaghariLib.importYAML ./base24.yml).palette isValidScheme (bahaghariLib.tinted-theming.importScheme ./base24.yml)
=> true => true
isValidScheme (bahaghariLib.importYAML ./base16.yml).palette isValidScheme (bahaghariLib.tinted-theming.importScheme ./base16.yml)
=> true => true
*/ */
isValidScheme = scheme: isValidScheme = scheme:
@ -66,14 +102,10 @@ rec {
Type: isLegacyBase16 :: Attrs -> Bool Type: isLegacyBase16 :: Attrs -> Bool
Example: Example:
isLegacyBase16 { isLegacyBase16 (bahaghariLib.tinted-theming.importScheme ./legacy-base16-scheme.yml)
# Some old-ass scheme...
}
=> true => true
isLegacyBase16 { isLegacyBase16 (bahaghariLib.tinted-theming.importScheme ./modern-base16-scheme.yml)
# Some new-ass scheme such as from the updated schemes repo...
}
=> false => false
*/ */
isLegacyScheme = scheme: isLegacyScheme = scheme:
@ -115,35 +147,4 @@ rec {
} }
// lib.optionalAttrs (scheme?description) { inherit (scheme) description; } // lib.optionalAttrs (scheme?description) { inherit (scheme) description; }
// lib.optionalAttrs (system != null) { inherit system; }; // lib.optionalAttrs (system != null) { inherit system; };
/* Imports a Base16 scheme. This also handles converting the legacy Base16
schema into the new one if it's detected. Take note, every single token
that is not part of the legacy proper is assumed to be part of the
`palette` of the new schema.
Type: importBase16Scheme :: Path -> Attrs
Example:
importScheme ./legacy-base16-scheme.yml
=> {
system = "base16";
name = "Scheme name";
author = "Scheme author";
palette = {
# All legacy token that are not included in the old standard proper
# are placed here. This is typically something like `background`,
# `foreground`, and whatnot that are added for enriching the palette
# or just for semantics for the theme designers.
};
}
*/
importScheme = yamlpath:
let
scheme = self.importYAML yamlpath;
in
assert lib.assertMsg (isValidScheme scheme || isLegacyScheme scheme)
"bahaghariLib.tinted-theming.importScheme: given data is not a valid Tinted Theming scheme";
if isLegacyScheme scheme
then modernizeLegacyScheme scheme
else scheme;
} }