-
Notifications
You must be signed in to change notification settings - Fork 2
Documentation
Here's a list of submodules of attheme-js
you can use.
- attheme-js/lib/
Submodules in the tools
directory are not used by attheme-js
and are
intended to simplify some work you may face.
Other files are not intended to be external and you should not use them.
If you ever need to use some of interfaces attheme-js
defines, you may import
attheme-js/lib/types
. It exports Color
, ColorSignature
and
VariableIterator
.
import Attheme from "attheme-js";
Constructs a new Attheme
instance.
If contents
is a string, the constructor will parse them and add the variables
(and wallpaper, if present) to the theme.
If contents
is a VariableIterator
(an iterator over [string, Color]
),
then its yielded values are collected to the constructed theme.
Returns the wallpaper of the theme. If it's not present, it returns null
.
Sets newWallpaper
as the theme's wallpaper.
Returns a boolean whether the theme has a wallpaper.
Deletes the wallpaper from the theme.
Important note: the methods above don't work with
chat_wallpaper
. In .attheme files, the image wallpaper is stored separately from the color value ofchat_wallpaper
.
Returns a copy of the value of variable
. If it's defined in the theme, then
null
is returned.
Sets a copy of value
as the value of variable
.
Returns a boolean whether the theme has variable
.
Deletes the variable
in the theme.
Returns the amount of variables defined in the theme.
Returns an array of names of variables defined in the theme.
Sorts the theme's variables in place.
Fallbacks this theme to another theme:
- Every variable which is present in
other
but not inthis
, is copied tothis
. - If
this
doesn't have a wallpaper, the wallpaper is copied fromother
.
const other = new Attheme([
[`checkbox`, { red: 0, green: 0, blue: 0, alpha: 255 }],
[`checkboxCheck`, { red: 255, green: 0, blue: 0, alpha: 255 }],
]);
other.setWallpaper(`wallpaper`);
const theme = new Attheme([
[`checkbox`, { red: 255, green: 255, blue: 255, alpha: 255 }],
]);
theme.fallbackToOther(other);
console.log(theme.get(`checkbox`)); // { red: 255, green: 255, blue: 255, alpha: 255 }
console.log(theme.get(`checkboxCheck`)); // { red: 255, green: 0, blue: 0, alpha: 255 }
console.log(theme.getWallpaper()); // wallpaper
Fallbacks variables to other existing variables according to the map.
const theme = new Attheme([[`foo`, { red: 0, green: 0, blue: 0, alpha: 0 }]]);
theme.fallbackToSelf(new Map([[`bar`, `foo`], [`spam`, `eggs`]]));
console.log(theme.get(`bar`)); // { red: 0, green: 0, blue: 0, alpha: 0 }
console.log(theme.get(`spam`)); // null
This is a generator that yields all the theme's variables as a tuple
[string, Color]
. The first element in the tuple is the variable name and the
second one is a copy of the value of the variable.
This is how you iterate over a theme:
const theme = new Attheme(/* ... */);
for (const [variable, color] of theme) {
console.log(variable, `has the value`, color);
}
You may copy all the variables from the theme this way:
const theme = new Attheme(/* ... */);
const variablesCopy = new Map(theme);
console.log(variabliesCopy.entries().next()); // [variable name, its value]
Serializes the theme.
const theme = new Attheme(/* ... */);
fs.writeFile(`theme.attheme`, String(theme));
const theme = new Attheme(/* ... */);
fs.writeFile(`theme.attheme`, theme.toString(`hex`)); // Uses HEX
import VARIABLES from "attheme-js/lib/variables";
A list of all variable names.
import FALLBACKS from "attheme-js/lib/fallbacks";
A fallback map used by Telegram.
import defaultTheme from "attheme-js/lib/defaultThemes/default";
A function that generates the default theme. Note that it does not have all
variables, use the VARIABLES
constant from the [variables
] file.
import mono from "attheme-js/lib/defaultThemes/mono";
A function that generates a Mono theme with the accent color provided as the first argument.
import dark from "attheme-js/lib/defaultThemes/dark";
A function that generates a Dark theme with the accent color provided as the first argument.
import arctic from "attheme-js/lib/defaultThemes/arctic";
A function that generates an Arctic theme with the accent color provided as the first arguments.
import graphite from "attheme-js/lib/defaultThemes/graphite";
A function that generates the Graphite theme. Note that this theme is only available in debug builds, so, if the theme is removed never reaching production builds, this file may be removed without a major version bump.
import themeToObject from "attheme-js/lib/tools/themeToObject";
const IMAGE_KEY = Symbol.for(`image`);
interface ObjectTheme {
[key: string]: Color;
[IMAGE_KEY]?: string;
}
Converts a new theme into an old one. This is useful for working with code that only knows the old API.
const newTheme = new Attheme(/* ... */);
const oldTheme = themeToObject(newTheme);
await toTDesktopTheme(oldTheme); // Does something like this exist?
import fromFile from "attheme-js/lib/tools/node/fromFile";
Asynchroniously reads the theme from the file at path
. Note that the path is
given to fs.readFile
as it is, which reads the file relatively to
process.cwd()
.
This function will read the theme at the given path correctly so the wallpaper won't spoil.
const themePath = process.argv[2];
fromFile(themePath).then(theme => {
// ...
});
import fromFile from "attheme-js/lib/tools/node/fromFile";
Asynchronously writes the theme to the file at path
.
const theme = new Attheme(null, {
defaultValues
});
toFile(theme, `The best most coolest theme.attheme`).then(() =>
console.log(`Saved the theme!`);
);
import fromFile from "attheme-js/lib/tools/browser/fromFile";
Reads the theme from the file opened by the user, e.g. via <input type="file">
or Drag'n'Drop.
This function will read the theme at the given path correctly so the wallpaper won't spoil, which is a common mistake.
const input = document.querySelector(`[name="theme"]`);
input.addEventListener(`change`, async () => {
for (const file of input.files) {
const theme = await fromTheme(file);
// ...
}
});
import toBlob from "attheme-js/lib/tools/browser/toBlob";
Serializes the theme and generates a Blob
which you can use to download the
theme.
const theme = new Attheme(null, {
defaultValues,
});
const link = document.createElement(`a`);
link.href = toBlob(theme, `The best theme ever`);
link.click();
link.remove();