Skip to content

Commit

Permalink
crud works
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew committed Mar 1, 2024
1 parent cefc0c0 commit 0b2cab3
Show file tree
Hide file tree
Showing 10 changed files with 349 additions and 54 deletions.
15 changes: 0 additions & 15 deletions src/content-modules/Browse.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import type { LintResult } from "../lib/ColorLint";
import MiniPalPreview from "../components/MiniPalPreview.svelte";
import LintCustomizationModal from "../linting/LintCustomizationModal.svelte";
import { lint } from "../lib/api-calls";
import Tooltip from "../components/Tooltip.svelte";
import { buttonStyle } from "../lib/styles";
Expand Down Expand Up @@ -266,17 +265,3 @@
{/each}
</div>
</div>

{#if $lintStore.focusedLint !== false}
<LintCustomizationModal
onClose={() => {
setTimeout(() => {
// loadLints()
// .then(() => lint(currentPal))
// .then((res) => {
// checks = res;
// });
}, 100);
}}
/>
{/if}
18 changes: 9 additions & 9 deletions src/lib/ColorLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import type { Palette, PalType, Affect, Context } from "../types";

export type LintLevel = "error" | "warning";
export interface LintResult {
name: string;
passes: boolean;
message: string;
level: LintLevel;
group: string;
description: string;
isCustom: false | string;
taskTypes: PalType[];
affectTypes: Affect[];
contextTypes: Context[];
subscribedFix: string;
description: string;
group: string;
isCustom: false | string;
level: LintLevel;
message: string;
name: string;
naturalLanguageProgram: string;
passes: boolean;
subscribedFix: string;
taskTypes: PalType[];
}

export class ColorLint<CheckData, ParamType> {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/CustomLint.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ColorLint } from "./ColorLint";
import type { PalType, Affect, Context } from "../types";
import type { PalType, Affect, Context, Palette } from "../types";
import {
LLEval,
prettyPrintLL,
Expand All @@ -20,6 +20,8 @@ export interface CustomLint {
program: string;
subscribedFix?: string;
taskTypes: PalType[];
expectedPassingTests: Palette[];
expectedFailingTests: Palette[];
}

export function CreateCustomLint(props: CustomLint) {
Expand Down
8 changes: 8 additions & 0 deletions src/lib/lints/affects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const lint1: CustomLint = {
failMessage: `This palette does not have at least one light blue, beige, or gray, which may not be appropriate for a playful palette. In particular {{blame}} may be problematic.`,
id: `light-blues-beiges-grays-playful-built-in`,
blameMode: "single",
expectedPassingTests: [],
expectedFailingTests: [],
};
lints.push(lint1);

Expand Down Expand Up @@ -88,6 +90,8 @@ const lint2: CustomLint = {
failMessage: `This palette has dark reds or browns, which may not be appropriate for a positive palette. In particular {{blame}} may be problematic.`,
id: `dark-reds-browns-positive-built-in`,
blameMode: "single",
expectedPassingTests: [],
expectedFailingTests: [],
};
lints.push(lint2);

Expand Down Expand Up @@ -118,6 +122,8 @@ const lint3: CustomLint = {
failMessage: `This palette has light colors, particularly greens, which may not be appropriate for a negative palette. In particular {{blame}} may be problematic.`,
id: `light-colors-greens-negative-built-in`,
blameMode: "single",
expectedPassingTests: [],
expectedFailingTests: [],
};
lints.push(lint3);

Expand Down Expand Up @@ -150,6 +156,8 @@ lints.push(lint3);
// failMessage: `This palette does not have two thematic strategies (blue-gray, green-gray) bridged by a common color (yellow), which may not be appropriate for a trustworthy palette.`,
// id: `trustworthy-thematic-strategies-yellow-built-in`,
// blameMode: "single",
// expectedPassingTests: [],
// expectedFailingTests: [],
// };
// lints.push(lint4);

Expand Down
13 changes: 12 additions & 1 deletion src/lib/lints/avoid-extremes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JSONToPrettyString } from "../utils";
import { JSONToPrettyString, makePalFromString } from "../utils";
import type { CustomLint } from "../CustomLint";

// https://www.sciencedirect.com/science/article/pii/S0167947308005549?casa_token=s8jmZqboaYgAAAAA:7lsAu7YUHVBTQA_eaKJ_3FFGv309684j_NTisGO9mIr3UZNIJ6hlAlxPQo04xzsowG7-dH0vzm4
Expand Down Expand Up @@ -29,5 +29,16 @@ const lint: CustomLint = {
failMessage: `Colors at either end of the lightness spectrum {{blame}} are hard to discriminate in some contexts, and are sometimes advised against`,
id: "extreme-colors-built-in",
blameMode: "single",
expectedPassingTests: [makePalFromString(["#ff7e0e"])],
expectedFailingTests: [
makePalFromString([
"#000000",
"#ffffff",
"#ff7e0e",
"#00ff00",
"#0084a9",
"#0000ff",
]),
],
};
export default lint;
2 changes: 2 additions & 0 deletions src/lib/lints/discriminative-power.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ const lint: CustomLint = {
failMessage: ``,
id: "discrim-power-built-in",
blameMode: "single",
expectedPassingTests: [],
expectedFailingTests: [],
};
export default lint;
8 changes: 7 additions & 1 deletion src/lib/lints/ugly-colors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JSONToPrettyString } from "../utils";
import { JSONToPrettyString, makePalFromString } from "../utils";
import type { CustomLint } from "../CustomLint";

const lint: CustomLint = {
Expand Down Expand Up @@ -31,5 +31,11 @@ const lint: CustomLint = {
group: "design",
id: "ugly-colors-built-in",
blameMode: "single",
expectedPassingTests: [
makePalFromString(["#000000", "#FFFFFF", "#FF0000", "#00FF00", "#0000FF"]),
],
expectedFailingTests: [
makePalFromString(["#000000", "#0010FF", "#6A7E25", "#00FF00", "#0000FF"]),
],
};
export default lint;
111 changes: 111 additions & 0 deletions src/linting/LintCustomizationPreview.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<script lang="ts">
import ColorChannelPicker from "../components/ColorChannelPicker.svelte";
import Tooltip from "../components/Tooltip.svelte";
import { Color } from "../lib/Color";
import Background from "../components/Background.svelte";
import type { Palette } from "../types";
import { buttonStyle } from "../lib/styles";
export let pal: Palette;
export let blamedSet: Set<number> = new Set();
export let updatePal: (newPal: Palette) => void;
export let removeCase: () => void;
</script>

<div
class="flex flex-wrap rounded p-2 grow"
style="background-color: {pal.background.toDisplay()};"
>
{#each pal.colors as color, idx}
<Tooltip top={"75px"} allowDrag={true}>
<div slot="content" class="flex flex-col">
<input
class="mb-2"
value={color.toHex()}
on:change={(e) => {
// @ts-ignore
const val = e.target.value;
const newColors = [...pal.colors];
newColors[idx] = Color.colorFromString(val, pal.colorSpace);
updatePal({ ...pal, colors: newColors });
}}
/>
<ColorChannelPicker
onSpaceChange={(newSpace) => {
updatePal({
...pal,
// @ts-ignore
colors: pal.colors.map((x) => x.toColorSpace(newSpace)),
// @ts-ignore
colorSpace: newSpace,
});
}}
colorMode={pal.colorSpace}
{color}
onColorChange={(newColor) => {
const newColors = [...pal.colors];
newColors[idx] = newColor;
updatePal({ ...pal, colors: newColors });
}}
/>
<button
class="w-6 h-6 mx-2 rounded-full transition-all"
on:click={() => {
const newColors = [...pal.colors].filter((_, i) => i !== idx);
updatePal({ ...pal, colors: newColors });
}}
>
Remove
</button>
</div>
<button
let:toggle
slot="target"
on:click|stopPropagation|preventDefault={(e) => {
toggle();
}}
class={"w-6 h-6 mx-2 rounded-full transition-all"}
class:border-4={blamedSet.has(idx)}
class:border-dashed={blamedSet.has(idx)}
class:border-black={blamedSet.has(idx) && color.luminance() > 0.5}
class:border-white={blamedSet.has(idx) && color.luminance() <= 0.5}
style="background-color: {color.toDisplay()}"
></button>
</Tooltip>
{/each}
<Tooltip>
<div slot="content" class="flex flex-col items-start">
<button
class={buttonStyle}
on:click={() => {
const newColors = [...pal.colors, Color.colorFromString("steelblue")];
updatePal({ ...pal, colors: newColors });
}}
>
Add Color
</button>
<button
class={buttonStyle}
on:click={() => {
removeCase();
}}
>
Remove Test Case
</button>
<Background
onChange={(newColor) => updatePal({ ...pal, background: newColor })}
bg={pal.background}
colorSpace={pal.colorSpace}
onSpaceChange={(newSpace) => {
updatePal({
...pal,
// @ts-ignore
colors: pal.colors.map((x) => x.toColorSpace(newSpace)),
// @ts-ignore
colorSpace: newSpace,
});
}}
/>
</div>
<button slot="target" let:toggle on:click={toggle}>⚙</button>
</Tooltip>
</div>
Loading

0 comments on commit 0b2cab3

Please sign in to comment.