Skip to content

Commit 6fae75d

Browse files
committed
better text shadow button
1 parent f2a1d19 commit 6fae75d

3 files changed

Lines changed: 67 additions & 34 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<script lang="ts">
2+
import { tooltip } from "$lib/tooltip";
3+
import IconShadow from "~icons/tabler/shadow";
4+
5+
interface Props {
6+
/** DOM element of the label wrapper */
7+
labelElement: HTMLLabelElement | undefined;
8+
/** hex color */
9+
hex: string | null;
10+
/** input label */
11+
label: string;
12+
/** input name, useful in a native form */
13+
name?: string | undefined;
14+
/** directionality left to right, or right to left*/
15+
dir: "ltr" | "rtl";
16+
small?: boolean;
17+
}
18+
19+
let {
20+
labelElement = $bindable(),
21+
hex,
22+
label,
23+
name = undefined,
24+
dir,
25+
small,
26+
}: Props = $props();
27+
</script>
28+
29+
<label bind:this={labelElement} {dir}>
30+
<button
31+
aria-label="Shadow Color"
32+
{@attach tooltip}
33+
class="p-1 {small
34+
? 'text-sm'
35+
: 'text-lg'} rounded-md bg-zinc-800 font-medium hover:bg-white/3">
36+
<IconShadow />
37+
</button>
38+
</label>

src/lib/components/text/TextStyleButtons.svelte

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { colorMap, defaultColorLUT } from "$lib/text/utils";
2+
import { colorMap } from "$lib/text/utils";
33
import { tooltip } from "$lib/tooltip";
44
import type { Editor } from "@tiptap/core";
55
import ColorPicker from "svelte-awesome-color-picker";
@@ -9,10 +9,13 @@
99
import IconShadow from "~icons/tabler/shadow";
1010
import IconStrikethrough from "~icons/tabler/strikethrough";
1111
import IconUnderline from "~icons/tabler/underline";
12+
import ShadowColorButton from "./ShadowColorButton.svelte";
1213
1314
const { editor, small = false }: { editor: Editor; small?: boolean } =
1415
$props();
1516
let shadowColorValue = $state("#ffffff");
17+
let shouldIgnoreInitInput = true;
18+
let isColorPickerOpen = $state(false);
1619
</script>
1720

1821
<button
@@ -80,42 +83,36 @@
8083
: ''}">
8184
<IconObfuscate />
8285
</button>
83-
<div class="mx-2 h-5 w-px bg-zinc-600"></div>
84-
{#if editor.isActive("shadowColor")}
85-
<button
86-
aria-label="Shadow Color"
87-
name="shadow_color"
88-
{@attach tooltip}
89-
class="p-1 {small
90-
? 'text-sm'
91-
: 'text-lg'} rounded-md bg-zinc-800 font-medium hover:bg-white/3"
92-
onclick={() => editor.chain().focus().unsetShadowColor().run()}>
93-
<IconShadow />
94-
</button>
86+
87+
{#if !editor.isActive("shadowColor") || isColorPickerOpen}
88+
<ColorPicker
89+
isAlpha={false}
90+
bind:hex={shadowColorValue}
91+
bind:isOpen={isColorPickerOpen}
92+
--cp-bg-color="#18181b"
93+
--cp-text-color="white"
94+
--cp-input-color="#0C0C0E"
95+
--cp-button-hover-color="#18181b"
96+
textInputModes={["hex"]}
97+
onInput={(c) => {
98+
if (isColorPickerOpen) {
99+
c.hex && editor.chain().focus().setShadowColor(c.hex).run();
100+
}
101+
}}
102+
swatches={Object.values(colorMap).map((c) => c.value)}
103+
components={{ input: ShadowColorButton }} />
95104
{:else}
96105
<button
97-
aria-label="Shadow Color"
98-
name="shadow_color"
106+
aria-label="Unset Shadow Color"
99107
{@attach tooltip}
108+
onclick={() => {
109+
shouldIgnoreInitInput = true;
110+
shadowColorValue = "#ffffff";
111+
editor.chain().focus().unsetShadowColor().run();
112+
}}
100113
class="p-1 {small
101114
? 'text-sm'
102-
: 'text-lg'} rounded-md font-medium hover:bg-white/3"
103-
onclick={() => {
104-
editor.chain().focus().setShadowColor(shadowColorValue).run();
105-
}}>
115+
: 'text-lg'} rounded-md bg-zinc-800 font-medium hover:bg-white/3">
106116
<IconShadow />
107117
</button>
108118
{/if}
109-
<!-- isAlpha is off because ARGB != RGBA and i want to get the update out -->
110-
<ColorPicker
111-
isAlpha={false}
112-
bind:hex={shadowColorValue}
113-
--cp-bg-color="#18181b"
114-
--cp-text-color="white"
115-
--cp-input-color="#0C0C0E"
116-
--cp-button-hover-color="#18181b"
117-
--input-size="20px"
118-
textInputModes={["hex"]}
119-
swatches={Object.values(colorMap).map((c) => c.value)}
120-
label="" />
121-
<div class="mx-2 h-5 w-px bg-zinc-600"></div>

src/lib/text/nbt/optimiser.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,10 @@ function mergeTextComponents(output: StringyMCText[]) {
232232
// Find shared style/interactivity properties between consecutive objects
233233
if (typeof current === "object" && typeof next === "object") {
234234
const sharedProperties = getSharedStyleProps(current, next);
235-
console.log("Shared Properties:", sharedProperties);
236235

237236
if (Object.keys(sharedProperties).length > 0) {
238237
let group = [current];
239238
collectAllFromIndex(i, group, output, sharedProperties);
240-
console.log("Group Collected:", group);
241239

242240
if (group.length < 1) {
243241
continue;

0 commit comments

Comments
 (0)