commit 6b415e9530c2533438f2600e8f480b5c65eeb96c
parent 718236d95e799dfe3f5fc841005f18ca7fd292e6
Author: Hunter
Date: Tue, 6 Aug 2024 19:03:47 -0400
implement theme switching (F2); theme saving
Diffstat:
| A | OFL.txt | | | 94 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | index.html | | | 85 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------- |
| A | medieval_sharp.ttf | | | 0 | |
| M | readme.md | | | 62 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- |
4 files changed, 224 insertions(+), 17 deletions(-)
diff --git a/OFL.txt b/OFL.txt
@@ -0,0 +1,94 @@
+Copyright (c) 2011, wmk69 (wmk69@o2.pl),
+with Reserved Font Name MedievalSharp.
+
+This Font Software is licensed under the SIL Open Font License, Version 1.1.
+This license is copied below, and is also available with a FAQ at:
+https://openfontlicense.org
+
+
+-----------------------------------------------------------
+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
+-----------------------------------------------------------
+
+PREAMBLE
+The goals of the Open Font License (OFL) are to stimulate worldwide
+development of collaborative font projects, to support the font creation
+efforts of academic and linguistic communities, and to provide a free and
+open framework in which fonts may be shared and improved in partnership
+with others.
+
+The OFL allows the licensed fonts to be used, studied, modified and
+redistributed freely as long as they are not sold by themselves. The
+fonts, including any derivative works, can be bundled, embedded,
+redistributed and/or sold with any software provided that any reserved
+names are not used by derivative works. The fonts and derivatives,
+however, cannot be released under any other type of license. The
+requirement for fonts to remain under this license does not apply
+to any document created using the fonts or their derivatives.
+
+DEFINITIONS
+"Font Software" refers to the set of files released by the Copyright
+Holder(s) under this license and clearly marked as such. This may
+include source files, build scripts and documentation.
+
+"Reserved Font Name" refers to any names specified as such after the
+copyright statement(s).
+
+"Original Version" refers to the collection of Font Software components as
+distributed by the Copyright Holder(s).
+
+"Modified Version" refers to any derivative made by adding to, deleting,
+or substituting -- in part or in whole -- any of the components of the
+Original Version, by changing formats or by porting the Font Software to a
+new environment.
+
+"Author" refers to any designer, engineer, programmer, technical
+writer or other person who contributed to the Font Software.
+
+PERMISSION & CONDITIONS
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of the Font Software, to use, study, copy, merge, embed, modify,
+redistribute, and sell modified and unmodified copies of the Font
+Software, subject to the following conditions:
+
+1) Neither the Font Software nor any of its individual components,
+in Original or Modified Versions, may be sold by itself.
+
+2) Original or Modified Versions of the Font Software may be bundled,
+redistributed and/or sold with any software, provided that each copy
+contains the above copyright notice and this license. These can be
+included either as stand-alone text files, human-readable headers or
+in the appropriate machine-readable metadata fields within text or
+binary files as long as those fields can be easily viewed by the user.
+
+3) No Modified Version of the Font Software may use the Reserved Font
+Name(s) unless explicit written permission is granted by the corresponding
+Copyright Holder. This restriction only applies to the primary font name as
+presented to the users.
+
+4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
+Software shall not be used to promote, endorse or advertise any
+Modified Version, except to acknowledge the contribution(s) of the
+Copyright Holder(s) and the Author(s) or with their explicit written
+permission.
+
+5) The Font Software, modified or unmodified, in part or in whole,
+must be distributed entirely under this license, and must not be
+distributed under any other license. The requirement for fonts to
+remain under this license does not apply to any document created
+using the Font Software.
+
+TERMINATION
+This license becomes null and void if any of the above conditions are
+not met.
+
+DISCLAIMER
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
+OTHER DEALINGS IN THE FONT SOFTWARE.
diff --git a/index.html b/index.html
@@ -1,9 +1,9 @@
<!DOCTYPE html>
-<html lang="en" data-theme="medieval"> <!-- update to change theme -->
+<html lang="en" data-theme="gak"> <!-- update to change default theme -->
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
-
+
<!-- favicon -->
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🪆</text></svg>">
@@ -30,13 +30,13 @@
--chlorophyll: #5aa83b;
--terracotta: #b15c2e;
- --wheat: #D2C3A3;
- --earth: #4A3C31;
+ --wheat: #d2c3a3;
+ --earth: #4a3c31;
--pumpkin: #cb7c52;
- --tobacco: #7D6C55;
+ --tobacco: #7d6c55;
- --forest: #20302f;
- --goat-milk:#d8d3c9;
+ --moss: #20302f;
+ --goat-milk: #d8d3c9;
--burl: #231f20;
--flame: #c63728;
@@ -72,8 +72,8 @@
--accent: var(--tobacco);
}
- [data-theme="medieval"] {
- --background: var(--forest);
+ :root[data-theme="medieval"] {
+ --background: var(--moss);
--text: var(--goat-milk);
--highlight: var(--burl);
--accent: var(--flame);
@@ -202,20 +202,23 @@
});
document.addEventListener('DOMContentLoaded', function() {
const appContainer = document.getElementById('app-container');
- let rootTask = loadFromLocalStorage();
+ let rootTask = loadTasksFromLocalStorage();
let currentTask = rootTask;
let taskPath = [currentTask];
let lastSubtaskDownArrowReleased = false;
let saveTimer = null;
+ let currentThemeIndex = 0;
+ let isF2Pressed = false;
+ let themes = [];
function scheduleSave() {
if (saveTimer) {
clearTimeout(saveTimer);
}
- saveTimer = setTimeout(saveToLocalStorage, 1000);
+ saveTimer = setTimeout(saveTasksToLocalStorage, 1000);
}
- function saveToLocalStorage() {
+ function saveTasksToLocalStorage() {
const serializedTasks = serializeTaskTree(taskPath[0]);
localStorage.setItem('taskTree', serializedTasks);
saveTimer = null;
@@ -233,7 +236,7 @@
return serialized;
}
- function loadFromLocalStorage() {
+ function loadTasksFromLocalStorage() {
const savedTasks = localStorage.getItem('taskTree');
if (savedTasks) {
return deserializeTaskTree(savedTasks);
@@ -472,7 +475,7 @@
selectAndFocusTask(task);
scheduleSave();
} else {
- // Animate the checkbox
+ // disallow unchecking and play a 'shake' animation
const checkbox = document.querySelector(`.task-container[data-id="${task.id}"] .checkbox-label`);
if (checkbox) {
checkbox.classList.add('shake');
@@ -865,6 +868,60 @@
return parentTask.subtasks[parentTask.subtasks.length - 1].id === task.id;
}
+ function getThemesFromCSS() {
+ const styleElement = document.querySelector('style');
+ if (styleElement && styleElement.textContent) {
+ const cssText = styleElement.textContent;
+ const themeRegex = /:root\[data-theme="([^"]+)"\]/g;
+ let match;
+ while ((match = themeRegex.exec(cssText)) !== null) {
+ themes.push(match[1]);
+ }
+ }
+ }
+
+ function cycleTheme() {
+ currentThemeIndex = (currentThemeIndex + 1) % themes.length;
+ const newTheme = themes[currentThemeIndex];
+ document.documentElement.setAttribute('data-theme', newTheme);
+ saveThemeToLocalStorage(newTheme);
+ }
+
+ function saveThemeToLocalStorage(theme) {
+ localStorage.setItem('currentTheme', theme);
+ }
+
+ function setInitialTheme() {
+ const savedTheme = localStorage.getItem('currentTheme');
+ const defaultTheme = document.documentElement.getAttribute('data-theme');
+
+ if (savedTheme && themes.includes(savedTheme)) {
+ currentThemeIndex = themes.indexOf(savedTheme);
+ } else if (themes.includes(defaultTheme)) {
+ currentThemeIndex = themes.indexOf(defaultTheme);
+ } else {
+ currentThemeIndex = 0;
+ }
+
+ document.documentElement.setAttribute('data-theme', themes[currentThemeIndex]);
+ }
+
+ document.addEventListener('keydown', function(event) {
+ if (event.key === 'F2' && !isF2Pressed) {
+ event.preventDefault();
+ isF2Pressed = true;
+ cycleTheme();
+ }
+ });
+
+ document.addEventListener('keyup', function(event) {
+ if (event.key === 'F2') {
+ isF2Pressed = false;
+ }
+ });
+
+ getThemesFromCSS();
+ setInitialTheme();
renderCurrentView();
selectFirstSubtask();
});
diff --git a/medieval_sharp.ttf b/medieval_sharp.ttf
Binary files differ.
diff --git a/readme.md b/readme.md
@@ -40,6 +40,60 @@ a nested task manager that breaks complex tasks into manageable subtasks.
- `Command/Ctrl + Z` undo text edit
- `Command/Ctrl + Shift + Z` redo text edit
+## themes
+Press `F2` to cycle through available themes.
+
+To create a new theme, add a CSS rule set with the following form to the `<style>` tag in index.html:
+
+```css
+:root[data-theme="sunflower"] {
+ --background: var(--pollen);
+ --text: var(--loam);
+ --highlight: var(--chlorophyll);
+ --accent: var(--terracotta);
+}
+```
+
+You can also use themes to set custom fonts, etc:
+
+``` css
+:root[data-theme="medieval"] {
+ --background: var(--moss);
+ --text: var(--goat-milk);
+ --highlight: var(--burl);
+ --accent: var(--flame);
+ & input[type="text"] {
+ font-family: 'MedievalSharp';
+ src: url('MedievalSharp-Regular.ttf') format('truetype');
+ }
+}
+```
+
+You can add named colors to the `:root` selector at the top of the `<style>` tag:
+
+```css
+:root {
+ --pollen: #f4a127;
+ --loam: #5a352b;
+ --chlorophyll: #5aa83b;
+ --terracotta: #b15c2e;
+
+ --wheat: #d2c3a3;
+ --earth: #4a3c31;
+ --pumpkin: #cb7c52;
+ --tobacco: #7d6c55;
+
+ --moss: #20302f;
+ --goat-milk: #d8d3c9;
+ --burl: #231f20;
+ --flame: #c63728;
+
+ .
+ .
+ .
+}
+```
+
## data persistence
your task tree is automatically saved to your browser's local storage. this ensures your tasks will persist even if you close the browser or refresh the page. note that clearing your browser data may erase your saved tasks.
@@ -49,5 +103,7 @@ this application is designed to run on modern web browsers with javascript enabl
## privacy
all data is stored locally on your machine. no data is sent to or stored on any external servers.
-## license
-this project is licensed under the <a href="https://github.com/hunterirving/matryoshka/blob/main/LICENSE">GNU general public license v3.0</a>.
-\ No newline at end of file
+## licenses
+this project is licensed under the <a href="https://github.com/hunterirving/matryoshka/blob/main/LICENSE">GNU General Public License v3.0</a>.
+
+the Medieval Sharp font by <a href="http://www.identifont.com/show?3DQU">Wojciech Kalinowski</a> is licensed under the <a href="https://github.com/hunterirving/matryoshka/blob/main/OFL.txt">SIL Open Font License, version 1.1</a>.
+\ No newline at end of file