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" ;
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
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 >
0 commit comments