The <svelte:document> element allows you to listen for events that fire on document. This is useful with events like selectionchange, which doesn't fire on window.
Add the selectionchange handler to the <svelte:document> tag:
App.svelte
<svelte:document on:selectionchange={handleSelectionChange} />Avoid
mouseenterandmouseleavehandlers on this element, as these events are not fired ondocumentin all browsers. Use<svelte:body>instead.