From eb0043fd5fc1c0e659feb9ae0a18adb8a3ba8533 Mon Sep 17 00:00:00 2001 From: MattMcAdams Date: Sat, 17 Feb 2024 19:34:41 -0600 Subject: [PATCH] Restructure data, add library --- package-lock.json | 4 +- package.json | 2 +- src/app/library/page.tsx | 47 ++ src/app/page.tsx | 483 ++++++++++----- src/components/ColorRow.tsx | 39 +- src/components/LibraryRow.tsx | 47 ++ src/components/generics/input.tsx | 26 - src/components/inputs/BrightnessInput.tsx | 51 -- src/components/inputs/Configuration.tsx | 2 +- src/components/inputs/CountInput.tsx | 35 -- src/components/inputs/EasingInput.tsx | 50 +- src/components/inputs/KeyColorInput.tsx | 6 +- .../inputs/LibraryConfiguration.tsx | 62 ++ src/components/inputs/NumberInput.tsx | 46 ++ src/components/inputs/RotationInput.tsx | 51 -- src/components/inputs/SaturationInput.tsx | 51 -- src/data/defaults.tsx | 39 ++ src/data/limits.tsx | 20 + src/data/session.tsx | 564 ++++++++++-------- src/functions/ease.ts | 29 +- src/functions/getColors.ts | 10 +- src/types/configObj.ts | 25 + src/types/context.ts | 31 + src/types/easing.ts | 28 + 24 files changed, 1069 insertions(+), 679 deletions(-) create mode 100644 src/app/library/page.tsx create mode 100644 src/components/LibraryRow.tsx delete mode 100644 src/components/generics/input.tsx delete mode 100644 src/components/inputs/BrightnessInput.tsx delete mode 100644 src/components/inputs/CountInput.tsx create mode 100644 src/components/inputs/LibraryConfiguration.tsx create mode 100644 src/components/inputs/NumberInput.tsx delete mode 100644 src/components/inputs/RotationInput.tsx delete mode 100644 src/components/inputs/SaturationInput.tsx create mode 100644 src/data/defaults.tsx create mode 100644 src/data/limits.tsx create mode 100644 src/types/configObj.ts create mode 100644 src/types/context.ts create mode 100644 src/types/easing.ts diff --git a/package-lock.json b/package-lock.json index d395615..dd5bc8b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "colorful", - "version": "1.3.1", + "version": "2.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "colorful", - "version": "1.3.1", + "version": "2.0.0", "license": "GPU-3.0", "dependencies": { "color": "^3.0.0", diff --git a/package.json b/package.json index 33f3bcd..c0919d2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "colorful", - "version": "1.3.1", + "version": "2.0.0", "description": "A tool for creating and manipulating colors", "private": true, "license": "GPU-3.0", diff --git a/src/app/library/page.tsx b/src/app/library/page.tsx new file mode 100644 index 0000000..0f7f09e --- /dev/null +++ b/src/app/library/page.tsx @@ -0,0 +1,47 @@ +"use client"; + +// load data +import { useSessionContext } from "../../data/session"; +// load components +import LibraryRow from "../../components/LibraryRow"; +import LibraryConfigInput from "../../components/inputs/LibraryConfiguration"; + +const Library = () => { + const Session = useSessionContext(); + + // const check = arr.some((e) => e.name === obj.name); + + return ( +
+ {Session.providerLoaded ? ( + Session.libraryLoaded && Session.configLoaded ? ( +
+
+

Library

+ {!Session.library.some( + (config) => + JSON.stringify(config) === JSON.stringify(Session.config) + ) ? ( + + ) : null} + {Session.library.map((config, index) => ( + + ))} +
+
+ +
+
+ ) : ( + <> +

Loading Library & Configuration

+ + ) + ) : ( +

The context provider has failed to load

+ )} +
+ ); +} + +export default Library; diff --git a/src/app/page.tsx b/src/app/page.tsx index 2f49b6a..81c7d6b 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,49 +1,54 @@ "use client"; +// Load dependencies import Color from 'color'; - -import { useSessionContext } from "../data/session"; +// load types +import easingOptions from "../types/easing"; +// load functions import * as hex from "../functions/hex"; -import { getColorsList } from "../functions/getColors"; +import getColorsList from "../functions/getColors"; +// load data +import { useSessionContext } from "../data/session"; +import limits from "../data/limits"; +// load inputs +import NumberInput from "../components/inputs/NumberInput"; +import EasingInput from "../components/inputs/EasingInput"; import ColorInput from "../components/inputs/KeyColorInput"; import AdvColorInfoInput from "../components/inputs/AdvColorInfoInput"; -import CountInput from "../components/inputs/CountInput"; -import BrightnessInput from "../components/inputs/BrightnessInput"; -import RotationInput from "../components/inputs/RotationInput"; -import SaturationInput from "../components/inputs/SaturationInput"; +import CopyColorsButton from "../components/inputs/CopyColorsButton"; +import CopySvgButton from "../components/inputs/CopySvgButton"; import ConfigInput from "../components/inputs/Configuration"; +// load components import ColorRow from "../components/ColorRow"; import { ConnectedScatterplot } from "../components/Graph"; -import CopyColorsButton from "../components/inputs/CopyColorsButton"; -import CopySvgButton from "../components/inputs/CopySvgButton"; export default function Home() { const Session = useSessionContext(); - const mainColor = hex.isValid(hex.fromNumber(Session.keyColor)) ? hex.fromNumber(Session.keyColor) : "#000000"; + const mainColor = hex.isValid(hex.fromNumber(Session.config.keyColor)) ? hex.fromNumber(Session.config.keyColor) : "#000000"; const darkColors = getColorsList( - Session.darkCount, + Session.config.dark.count, "black", - Session.darkRotation, - Session.darkRotationEasing, - Session.darkSaturation, - Session.darkSaturationEasing, - Session.darkness, - Session.darknessEasing, + Session.config.dark.angle, + Session.config.dark.angleEase, + Session.config.dark.saturation, + Session.config.dark.saturationEase, + Session.config.dark.brightness, + Session.config.dark.brightnessEase, mainColor, '#FFFFFF' ).reverse(); const lightColors = getColorsList( - Session.lightCount, + Session.config.light.count, 'white', - Session.lightRotation, - Session.lightRotationEasing, - Session.lightSaturation, - Session.lightSaturationEasing, - Session.lightness, - Session.lightnessEasing, + Session.config.light.angle, + Session.config.light.angleEase, + Session.config.light.saturation, + Session.config.light.saturationEase, + Session.config.light.brightness, + Session.config.light.brightnessEase, mainColor, '#FFFFFF' ); @@ -52,127 +57,333 @@ export default function Home() { return (
- {Session.loaded ? ( - <> -
- -
-

Options

- -
- - -
-
-
- About -

Colorful v1.3.1

-

+ {Session.providerLoaded ? ( + Session.configLoaded ? ( + <> +

+
+ - Matt McAdams - {" "} - ·{" "} - - Open Source - {" "} - ·{" "} - - Donate + Library -

-
-
-
- -
-
-
- - - - +
+
+

Options

+ +
+ + +
+
+
+ + About + +

Colorful v2.0.0

+

+ + Matt McAdams + {" "} + ·{" "} + + Open Source + {" "} + ·{" "} + + Donate + +

+
-
- - - - +
+
-
-
-
- Luminance · How bright is it? -
- ({ - x: allColors.indexOf(s), - y: Color(s).luminosity(), - hex: s, - }))} - /> -
-
-
- Chroma · How colorful is it? -
- ({ - x: allColors.indexOf(s), - y: Color(s).lch().object().c, - hex: s, - }))} +
+
+ + Session.updateConfig( + "dark", + "count", + Number(e.target.value) + ) + } /> -
-
-
- Hue · What color is it? -
- ({ - x: allColors.indexOf(s), - y: Color(s).hsl().object().h, - hex: s, - }))} +
+ + Session.updateConfig( + "dark", + "brightness", + Number(e.target.value) + ) + } + /> + + Session.updateConfigEasing( + "dark", + "brightness", + e.target.value as easingOptions + ) + } + /> +
+
+ + Session.updateConfig( + "dark", + "angle", + Number(e.target.value) + ) + } + /> + + Session.updateConfigEasing( + "dark", + "angle", + e.target.value as easingOptions + ) + } + /> +
+
+ + Session.updateConfig( + "dark", + "saturation", + Number(e.target.value) + ) + } + /> + + Session.updateConfigEasing( + "dark", + "saturation", + e.target.value as easingOptions + ) + } + /> +
+
+
+ + Session.updateConfig( + "light", + "count", + Number(e.target.value) + ) + } /> - -
-
- +
+ + Session.updateConfig( + "light", + "brightness", + Number(e.target.value) + ) + } + /> + + Session.updateConfigEasing( + "light", + "brightness", + e.target.value as easingOptions + ) + } + /> +
+
+ + Session.updateConfig( + "light", + "angle", + Number(e.target.value) + ) + } + /> + + Session.updateConfigEasing( + "light", + "angle", + e.target.value as easingOptions + ) + } + /> +
+
+ + Session.updateConfig( + "light", + "saturation", + Number(e.target.value) + ) + } + /> + + Session.updateConfigEasing( + "light", + "saturation", + e.target.value as easingOptions + ) + } + /> +
+
+
+
+
+ Luminance · How bright is it? +
+ ({ + x: allColors.indexOf(s), + y: Color(s).luminosity(), + hex: s, + }))} + /> +
+
+
+ Chroma · How colorful is it? +
+ ({ + x: allColors.indexOf(s), + y: Color(s).lch().object().c, + hex: s, + }))} + /> +
+
+
+ Hue · What color is it? +
+ ({ + x: allColors.indexOf(s), + y: Color(s).hsl().object().h, + hex: s, + }))} + /> +
+
+
+ +
-
- + + ) : ( + <> +

Loading Configuration

+ + ) ) : ( - <> -

Loading Configuration

- +

The context provider has failed to load

)}
); diff --git a/src/components/ColorRow.tsx b/src/components/ColorRow.tsx index c2fee62..e51ea29 100644 --- a/src/components/ColorRow.tsx +++ b/src/components/ColorRow.tsx @@ -1,14 +1,45 @@ import React from "react"; import Swatch from "./Swatch"; +import config from "../types/configObj"; +import { getColorsList } from "../functions/getColors"; +import * as hex from "../functions/hex"; + +export const ColorRow = (props: { config: config }) => { + const mainColor = hex.isValid(hex.fromNumber(props.config.keyColor)) ? props.config.keyColor : "#000000"; + + const darkColors = getColorsList( + props.config.dark.count, + "black", + props.config.dark.angle, + props.config.dark.angleEase, + props.config.dark.saturation, + props.config.dark.saturationEase, + props.config.dark.brightness, + props.config.dark.brightnessEase, + mainColor, + "#FFFFFF" + ).reverse(); + + const lightColors = getColorsList( + props.config.light.count, + "white", + props.config.light.angle, + props.config.light.angleEase, + props.config.light.saturation, + props.config.light.saturationEase, + props.config.light.brightness, + props.config.light.brightnessEase, + mainColor, + "#FFFFFF" + ); -export const ColorRow = (props: { darkColors: string[], mainColor: string, lightColors: string[] }) => { return (
- {props.darkColors.map((color: string, index: number) => ( + {darkColors.map((color: string, index: number) => ( ))} - - {props.lightColors.map((color: string, index: number) => ( + + {lightColors.map((color: string, index: number) => ( ))}
diff --git a/src/components/LibraryRow.tsx b/src/components/LibraryRow.tsx new file mode 100644 index 0000000..e7bfd9b --- /dev/null +++ b/src/components/LibraryRow.tsx @@ -0,0 +1,47 @@ +"use client"; +import ColorRow from "./ColorRow"; +import config from "../types/configObj"; +import { useSessionContext } from "../data/session"; +import { useRouter } from "next/navigation"; +import LibraryConfigInput from "./inputs/LibraryConfiguration"; + +const LibraryRow = (props: { config: config, exists: boolean }) => { + const Session = useSessionContext(); + const router = useRouter(); + + function handleEdit() { + Session.loadConfig(JSON.stringify(props.config)); + router.push("/"); + } + + return ( +
+ +
+ {props.exists ? ( + + ) : ( + + )} + +
+
+ ); +}; + +export default LibraryRow; diff --git a/src/components/generics/input.tsx b/src/components/generics/input.tsx deleted file mode 100644 index b01b51c..0000000 --- a/src/components/generics/input.tsx +++ /dev/null @@ -1,26 +0,0 @@ -"use client"; - -const NumberInput = (props: {name: string, label: string, value: number, changeHandler: () => void}) => { - - return ( -
- - -
- ); -}; - -export default NumberInput; diff --git a/src/components/inputs/BrightnessInput.tsx b/src/components/inputs/BrightnessInput.tsx deleted file mode 100644 index b1dca6a..0000000 --- a/src/components/inputs/BrightnessInput.tsx +++ /dev/null @@ -1,51 +0,0 @@ -"use client"; - -import { ChangeEvent } from "react"; -import { useSessionContext } from "../../data/session"; -import EasingInput from "./EasingInput"; - -const DarknessInput = (props: {type: 'light' | 'dark'}) => { - const Session = useSessionContext(); - - function handleChange(e: ChangeEvent) { - let value = Number(e.target.value); - Session.updateBrightness(props.type, value); - } - - return ( -
- -
- - - % - -
- - -
- ); -}; - -export default DarknessInput; diff --git a/src/components/inputs/Configuration.tsx b/src/components/inputs/Configuration.tsx index b0fcf38..02832f8 100644 --- a/src/components/inputs/Configuration.tsx +++ b/src/components/inputs/Configuration.tsx @@ -15,7 +15,7 @@ const ConfigInput = () => { } function applyConfig() { - Session.loadConfiguration(configString); + Session.loadConfig(configString); } function loadConfig() { diff --git a/src/components/inputs/CountInput.tsx b/src/components/inputs/CountInput.tsx deleted file mode 100644 index d034b4c..0000000 --- a/src/components/inputs/CountInput.tsx +++ /dev/null @@ -1,35 +0,0 @@ -"use client"; - -import { ChangeEvent } from "react"; -import { useSessionContext } from "../../data/session"; - -const DarkCountInput = (props: {type: 'light' | 'dark'}) => { - const Session = useSessionContext(); - - function handleChange(e: ChangeEvent) { - let value = Number(e.target.value); - Session.updateCount(props.type, value); - } - - return ( -
- - -
- ); -}; - -export default DarkCountInput; diff --git a/src/components/inputs/EasingInput.tsx b/src/components/inputs/EasingInput.tsx index 4f0e6cf..821f9f4 100644 --- a/src/components/inputs/EasingInput.tsx +++ b/src/components/inputs/EasingInput.tsx @@ -1,64 +1,38 @@ "use client"; import { ChangeEvent } from "react"; -import { useSessionContext } from "../../data/session"; -import { easingOptions, easingOptionsType } from "../../functions/ease"; +import { easingOptions } from "../../types/easing"; const EasingInput = (props: { - type: "light" | "dark", - property: 'hue' | 'saturation' | 'brightness', + name: string; + label: string; + value: easingOptions; + changeHandler: (e: ChangeEvent) => void; }) => { - const Session = useSessionContext(); - - let value = ''; - if (props.type === 'light') { - if (props.property === 'hue') { - value = Session.lightRotationEasing; - } else if (props.property === 'saturation') { - value = Session.lightSaturationEasing; - } else { - value = Session.lightnessEasing; - } - } else { - if (props.property === 'hue') { - value = Session.darkRotationEasing; - } else if (props.property === 'saturation') { - value = Session.darkSaturationEasing; - } else { - value = Session.darknessEasing; - } - } - - function handleChange(e: ChangeEvent) { - let value = e.target.value as easingOptionsType; - Session.updateEasing(props.type, props.property, value); - } const easingKeys = []; for (let option in easingOptions) { - easingKeys.push( - - ); + easingKeys.push(); } return (