Skip to content

Commit

Permalink
v0.1.0-beta.16
Browse files Browse the repository at this point in the history
  • Loading branch information
jgerigmeyer committed Dec 14, 2022
1 parent c151211 commit 5f35e75
Show file tree
Hide file tree
Showing 6 changed files with 886 additions and 3,180 deletions.
6 changes: 3 additions & 3 deletions .sassdocrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ herman:
- name: 'OddBird'
url: 'https://www.oddbird.net/'
sass:
implementation: sass
includepaths:
- 'sass/'
sassOptions:
loadPaths:
- 'sass/'
use:
- 'tools'
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changelog

## UNRELEASED
## 0.1.0-beta.16 - 2022/12/14

- 🏠 INTERNAL: Remove documentation from npm package
- 🏠 INTERNAL: Upgrade dependencies

## 0.1.0-beta.15 - 2020/10/20

Expand Down
8 changes: 4 additions & 4 deletions css/ccs.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 18 additions & 37 deletions dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
value: true
});
_exports.default = _default;

function _default() {
// root elements
const root = document.querySelector('[data-ccs="root"]');
Expand All @@ -26,122 +25,112 @@
const modeLight = document.querySelector('[data-ccs-input="light-mode"]');
const modeDark = document.querySelector('[data-ccs-input="dark-mode"]');
const modeAuto = document.querySelector('[data-ccs-input="auto-mode"]');
const unsetBtn = document.querySelector('[data-ccs-input="unset"]'); // controls
const unsetBtn = document.querySelector('[data-ccs-input="unset"]');

// controls
const controls = {
theme: document.querySelector('[data-ccs-input~="theme"]'),
hue: document.querySelector('[data-ccs-input="hue"]'),
sat: document.querySelector('[data-ccs-input="saturation"]'),
light: document.querySelector('[data-ccs-input="lightness"]'),
contrast: document.querySelector('[data-ccs-input="contrast"]')
};

const showUnsetBtn = (show = true) => {
if (unsetBtn) {
show ? unsetBtn.removeAttribute("hidden") : unsetBtn.setAttribute("hidden", "");
}
}; // attributes

};

// attributes
const attrs = {
theme: "data-ccs-theme"
}; // properties
};

// properties
const props = {
hue: "--ccs-prime--user",
sat: "--ccs-s--user",
light: "--ccs-l--user",
contrast: "--ccs-contrast--user",
mode: "--ccs-mode--user"
}; // local storage
};

// local storage
const store = {
theme: "ccsTheme",
mode: "ccsMode",
hue: "ccsHue",
sat: "ccsSat",
light: "ccsLight",
contrast: "ccsContrast"
}; // set a value
};

// set a value
const setValue = (type, to, toStore = true) => {
if (to) {
if (attrs[type]) {
root.setAttribute(attrs[type], to);
} else if (props[type]) {
root.style.setProperty(props[type], to);
}

if (toStore && store[type]) {
localStorage.setItem(store[type], to);
showUnsetBtn();
}
}
};

const clearProps = (sub = null) => Object.keys(props).forEach(prop => {
if (!sub || sub.includes(prop)) {
root.style.removeProperty(props[prop]);
}
});

const clearStore = (sub = null) => Object.keys(store).forEach(type => {
if (!sub || sub.includes(type)) {
localStorage.removeItem(store[type]);
}
});

const resetControls = (sub = null) => Object.keys(controls).forEach(type => {
if (!sub || sub.includes(type)) {
const el = controls[type];

if (el) {
el.value = el.getAttribute("data-default");
}
}
});

const subTheme = ["hue", "sat", "light", "contrast"];

const setSelection = (type, selection) => {
const unsetTheme = controls.theme && controls.theme.dataset.ccsInput && controls.theme.dataset.ccsInput.includes("unset-values");

if (type === "theme" && unsetTheme) {
clearProps(subTheme);
clearStore(subTheme);
resetControls(subTheme);
}

setValue(type, selection);
}; // clear all settings on reset

};

// clear all settings on reset
const unset = () => {
if (controls.theme) {
setValue("theme", controls.theme.getAttribute("data-default"), false);
}

clearStore();
clearProps();
resetControls();
showUnsetBtn(false);

if (modeAuto) {
modeAuto.checked = true;
}
}; // modes

};

// modes
const getMode = () => parseInt(getComputedStyle(root).getPropertyValue("--ccs-mode").trim(), 10);

const changeMode = scheme => {
const schemeDict = {
light: 1,
dark: -1,
auto: 0
};
const setting = schemeDict[scheme];

if (setting) {
setValue("mode", setting);
} else {
Expand All @@ -150,7 +139,6 @@
clearProps(["mode"]);
}
};

const toggleMode = () => {
const modeDict = {
1: modeLight,
Expand All @@ -159,55 +147,48 @@
const mode = getMode();
setValue("mode", mode * -1);
const modeBtn = modeDict[mode * -1];

if (modeBtn) {
modeBtn.checked = true;
}
}; // initialize everything

};

// initialize everything
const initMenu = () => {
if (themeMenu) {
themeMenu.removeAttribute("hidden");
}
};

const initMode = () => {
let to = localStorage.getItem(store.mode);

if (to) {
const modeDict = {
1: modeLight,
[-1]: modeDark
};
const modeBtn = modeDict[to];
setValue("mode", to);

if (modeBtn) {
modeBtn.checked = true;
}
} else if (modeAuto) {
modeAuto.checked = true;
}
};

const initValue = type => {
controls[type].setAttribute("data-default", controls[type].value);
const to = localStorage.getItem(store[type]);

if (to) {
setValue(type, to, false);
controls[type].value = to;
showUnsetBtn();
}
};
/* init defaults */


/* init defaults */
window.onload = initMenu();
window.onload = initMode();
/* attach event listeners */

/* attach event listeners */
invertBtn && invertBtn.addEventListener("click", toggleMode);
modeLight && modeLight.addEventListener("change", () => changeMode("light"));
modeDark && modeDark.addEventListener("change", () => changeMode("dark"));
Expand Down
20 changes: 7 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cascading-color-systems",
"version": "0.1.0-beta.15",
"version": "0.1.0-beta.16",
"description": "generate dynamic color palettes with custom properties",
"title": "Cascading Colors",
"main": "dist.js",
Expand All @@ -16,19 +16,13 @@
],
"license": "SEE LICENSE IN LICENSE.md",
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/plugin-transform-modules-umd": "^7.12.1",
"@babel/cli": "^7.19.3",
"@babel/core": "^7.20.5",
"@babel/plugin-transform-modules-umd": "^7.18.6",
"cssremedy": "^0.1.0-beta.2",
"sass": "^1.27.0",
"sassdoc": "^2.7.3",
"sassdoc-theme-herman": "^3.2.0"
},
"resolutions": {
"marked": "^0.7.0",
"sassdoc-theme-herman/nunjucks/chokidar": ">=3.0.0",
"sassdoc-theme-herman/nunjucks/yargs": "^13.2",
"sassdoc-theme-herman/typogr/mkdirp": "^0.5.5"
"sass": "^1.56.2",
"sassdoc": "^2.7.4",
"sassdoc-theme-herman": "^5.0.0"
},
"scripts": {
"build-sass": "sass sass/_output.scss css/ccs.css",
Expand Down
Loading

0 comments on commit 5f35e75

Please sign in to comment.