From 6e4d7d31923ac19523ec9cc5fd8ea89d4289b4d9 Mon Sep 17 00:00:00 2001 From: Andrew Michael McNutt Date: Sun, 20 Oct 2024 18:33:18 -0600 Subject: [PATCH] Share pal --- apps/color-buddy/src/App.svelte | 38 ++++++++++++++ .../src/components/SharePal.svelte | 52 +++++++++++++++++++ .../color-buddy/src/components/Tooltip.svelte | 2 +- yarn.lock | 5 -- 4 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 apps/color-buddy/src/components/SharePal.svelte diff --git a/apps/color-buddy/src/App.svelte b/apps/color-buddy/src/App.svelte index 775380e..7d4a8fe 100644 --- a/apps/color-buddy/src/App.svelte +++ b/apps/color-buddy/src/App.svelte @@ -15,6 +15,40 @@ {}, $configStore.userName ); + + // check if there's a palette specified in the url + const url = new URL(window.location.href); + const colors = url.searchParams.get("colors"); + const background = url.searchParams.get("background") || "#ffffff"; + const palName = url.searchParams.get("palName"); + const space = url.searchParams.get("space"); + if (colors) { + console.log(colors, background, palName, space); + let parsedColors = []; + try { + parsedColors = JSON.parse(colors || "[]"); + } catch (e) { + console.error(e); + } + const newPal = makePalFromString(parsedColors, background); + if (palName) { + newPal.name = palName; + } + if (space) { + newPal.colorSpace = space as any; + } + if (parsedColors.length > 0) { + console.log("here", newPal); + colorStore.createNewPal(newPal); + } + + // remove the palette from the url + url.searchParams.delete("colors"); + url.searchParams.delete("background"); + url.searchParams.delete("palName"); + url.searchParams.delete("space"); + window.history.replaceState({}, "", url.toString()); + } }); // make sure no focused colors are out of bounds @@ -43,12 +77,15 @@ import TourProvider from "./content-modules/TourProvider.svelte"; import Config from "./controls/Config.svelte"; import Title from "./controls/Title.svelte"; + import SharePal from "./components/SharePal.svelte"; import { lint } from "./lib/api-calls"; import { debounce } from "vega"; import { buttonStyle } from "./lib/styles"; + import { makePalFromString } from "color-buddy-palette"; + $: route = $configStore.route; $: evalRoute = $configStore.evalDisplayMode; const bindStr = "!!"; @@ -114,6 +151,7 @@ Redo + diff --git a/apps/color-buddy/src/components/SharePal.svelte b/apps/color-buddy/src/components/SharePal.svelte new file mode 100644 index 0000000..7c08076 --- /dev/null +++ b/apps/color-buddy/src/components/SharePal.svelte @@ -0,0 +1,52 @@ + + +
+ +
+
Share via url
+
{open && generateWebUrl()}
+
+ + {#if copyState === "copied"} +
Copied!
+ {/if} +
+
+ + +
+
diff --git a/apps/color-buddy/src/components/Tooltip.svelte b/apps/color-buddy/src/components/Tooltip.svelte index 234102d..2c45718 100644 --- a/apps/color-buddy/src/components/Tooltip.svelte +++ b/apps/color-buddy/src/components/Tooltip.svelte @@ -129,7 +129,7 @@ }} > {/if} - + diff --git a/yarn.lock b/yarn.lock index b4d8eda..d7f827f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2314,11 +2314,6 @@ resolved "https://registry.npmjs.org/@types/color-namer/-/color-namer-1.3.3.tgz" integrity sha512-DJ0MHHqazwb94dUBRhahK49nXhRGk2DIRNrVNVR3U3uQjYWY4uNhEjHXO+TbFQGpZcwli1pCj6xm3S3KsB/+3A== -"@types/color-thief-node@^1.0.4": - version "1.0.4" - resolved "https://registry.yarnpkg.com/@types/color-thief-node/-/color-thief-node-1.0.4.tgz#33b250895de87ed7090dce44bee2b19a419acbb6" - integrity sha512-9mHoSyLAojvDQsZWxu3FHhiwUsQC7Lfuxrii6rnYc11uJ7GH2ODaM82gyDCXnR/5eXqlOymauUXU5eCEYAHS4A== - "@types/d3-array@*": version "3.2.1" resolved "https://registry.npmjs.org/@types/d3-array/-/d3-array-3.2.1.tgz"