aboutsummaryrefslogtreecommitdiff
path: root/themes/hugo-theme-stack/assets/ts/color.ts
diff options
context:
space:
mode:
authorAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-11-16 19:32:18 +0300
committerAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-11-17 01:28:57 +0300
commit239d68f94c6250276850fbe95eaa6cdd5c38fb26 (patch)
treec576da169afc442f51eae6213ad0ff749ed86589 /themes/hugo-theme-stack/assets/ts/color.ts
parent8e79098193fd0a8b65305dd8054cf7c424c60bc5 (diff)
Своя тема, полностью всё переделал
Diffstat (limited to 'themes/hugo-theme-stack/assets/ts/color.ts')
-rw-r--r--themes/hugo-theme-stack/assets/ts/color.ts63
1 files changed, 0 insertions, 63 deletions
diff --git a/themes/hugo-theme-stack/assets/ts/color.ts b/themes/hugo-theme-stack/assets/ts/color.ts
deleted file mode 100644
index 50581d1..0000000
--- a/themes/hugo-theme-stack/assets/ts/color.ts
+++ /dev/null
@@ -1,63 +0,0 @@
-interface colorScheme {
- hash: string, /// Regenerate color scheme when the image hash is changed
- DarkMuted: {
- hex: string,
- rgb: Number[],
- bodyTextColor: string
- },
- Vibrant: {
- hex: string,
- rgb: Number[],
- bodyTextColor: string
- }
-}
-
-let colorsCache: { [key: string]: colorScheme } = {};
-
-if (localStorage.hasOwnProperty('StackColorsCache')) {
- try {
- colorsCache = JSON.parse(localStorage.getItem('StackColorsCache'));
- }
- catch (e) {
- colorsCache = {};
- }
-}
-
-async function getColor(key: string, hash: string, imageURL: string) {
- if (!key) {
- /**
- * If no key is provided, do not cache the result
- */
- return await Vibrant.from(imageURL).getPalette();
- }
-
- if (!colorsCache.hasOwnProperty(key) || colorsCache[key].hash !== hash) {
- /**
- * If key is provided, but not found in cache, or the hash mismatches => Regenerate color scheme
- */
- const palette = await Vibrant.from(imageURL).getPalette();
-
- colorsCache[key] = {
- hash: hash,
- Vibrant: {
- hex: palette.Vibrant.hex,
- rgb: palette.Vibrant.rgb,
- bodyTextColor: palette.Vibrant.bodyTextColor
- },
- DarkMuted: {
- hex: palette.DarkMuted.hex,
- rgb: palette.DarkMuted.rgb,
- bodyTextColor: palette.DarkMuted.bodyTextColor
- }
- }
-
- /* Save the result in localStorage */
- localStorage.setItem('StackColorsCache', JSON.stringify(colorsCache));
- }
-
- return colorsCache[key];
-}
-
-export {
- getColor
-} \ No newline at end of file