-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(settings): setup caret style and animation store
TODO: functionalities of caret style and animation
- Loading branch information
1 parent
e134eab
commit 802e953
Showing
17 changed files
with
276 additions
and
78 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<script lang="ts"> | ||
import throttle from 'lodash.throttle'; | ||
import debounce from 'lodash.debounce'; | ||
import { position as getCaretPosition } from 'caret-pos'; | ||
import { settings } from '@/store/store'; | ||
import type Quill from 'quill'; | ||
interface Props { | ||
quill: Quill; | ||
editorContainer: HTMLElement; | ||
} | ||
let { quill, editorContainer }: Props = $props(); | ||
let caret = $state({ top: 10, left: 8, height: 24 }); | ||
let fakeCaretElement: HTMLSpanElement = $state(null!); | ||
const resumeFakeCaretBlink = debounce(function () { | ||
if (fakeCaretElement) fakeCaretElement.classList.add('animate-caret-blink'); | ||
}, 1000); | ||
export const updateCaretPosition = throttle(() => { | ||
if (!quill) return; | ||
// console.count('Update caret position'); | ||
requestAnimationFrame(async () => { | ||
if (fakeCaretElement) fakeCaretElement.classList.remove('animate-caret-blink'); | ||
if (!quill) return; | ||
if (editorContainer) { | ||
try { | ||
const { top, left, height } = getCaretPosition(quill.root); | ||
// Adjust for the scroll position | ||
caret = { | ||
top: top - editorContainer.scrollTop, | ||
left: left - editorContainer.scrollLeft, | ||
height: height | ||
}; | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
resumeFakeCaretBlink(); | ||
}); | ||
}); | ||
</script> | ||
|
||
<span | ||
class="fake-caret absolute z-0 w-0.5 animate-caret-blink | ||
rounded-[.06em] bg-primary" | ||
bind:this={fakeCaretElement} | ||
style="top: {caret.top}px; | ||
left: {caret.left}px; | ||
height: {caret.height}px; | ||
width: {$settings.zoom * 2}px" | ||
spellcheck="false" | ||
></span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.