Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e006c2f
BREAKING CHANGE : handleEventListener uses $effect + target parameter…
novaotp Feb 24, 2025
9af4572
feat(core): added cleanup function in watch/whenever + renamed option…
novaotp Mar 5, 2025
8833a22
feat(core): added options.deep in watch options
novaotp Mar 5, 2025
52947c3
fix(core): fixed which characters are detected in onStartTyping + add…
novaotp Mar 6, 2025
ca5d4a9
fix(core): fixed start/stop handling in createSpeechRecognition
novaotp Mar 6, 2025
d48992d
fix(core): removed cleanup in onSwipe, using $state.raw + added tests
novaotp Mar 6, 2025
a7c114c
BREAKING CHANGE : removed getBattery utility
novaotp Mar 4, 2025
805c7f5
test: added test for getDocumentVisibility
novaotp Feb 24, 2025
d76ed14
test: added tests for hasLeftPage utility
novaotp Mar 1, 2025
ca39148
test: added tests for isWindowFocused
novaotp Mar 4, 2025
f38e3f5
test: added tests for getActiveElement
novaotp Mar 4, 2025
61301ce
test(core): added tests for getDeviceMotion
novaotp Mar 5, 2025
94275c8
feat(core): added support for iOS in getDeviceMotion
novaotp Mar 5, 2025
5802133
feat(core): getNetwork listens to 'change' event + added tests
novaotp Mar 6, 2025
d79adac
feat(core): directly exposing values in getNetwork return
novaotp Mar 6, 2025
481f471
test(core): added tests for getDeviceOrientation
novaotp Mar 6, 2025
f8c745d
test(core): added coverage.include and coverage.exclude in vite config
novaotp Mar 6, 2025
3b2b130
test(core): added tests for getDevicePixelRatio
novaotp Mar 6, 2025
5d988a5
test(core): added tests for getLastChanged
novaotp Mar 6, 2025
df4963f
test(core): added tests to getFps
novaotp Mar 7, 2025
0428c4a
test(core): added tests for onHover
novaotp Mar 7, 2025
d949d91
fix(core): removed cleanup in createObjectUrl + added tests
novaotp Mar 10, 2025
70be654
test(core): added tests for createVibration
novaotp Mar 10, 2025
de30d22
test(core): added tests for createEyeDropper
novaotp Mar 10, 2025
0b89442
chore(docs): removed unusued import in root layout
novaotp Mar 11, 2025
a9ce308
fix(docs): fixed handleEventListener demo
novaotp Mar 11, 2025
8e1f16a
fix(docs): improved the separation between the lede and the rest of t…
novaotp Mar 11, 2025
6abe5b2
chore(docs): various docs improvements
novaotp Mar 11, 2025
e184a09
fix(core): removed $lib calls
novaotp Mar 18, 2025
88d23cf
fix(core): fixed getPermission + added tests
novaotp Mar 18, 2025
bf26db9
fix(core): removed autoCleanup notion
novaotp Mar 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions docs/content/docs/core/async-state/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,29 @@ A reactive state that handles the loading and error states of a promise.

## Usage

```svelte
<script>
import { asyncState } from '@sv-use/core';
```ts
import { asyncState } from '@sv-use/core';

const recipe = asyncState(
fetch(`https://dummyjson.com/recipes/1`)
.then((res) => res.json()),
null
);
</script>
const recipe = asyncState(() => {
const result = fetch(`https://dummyjson.com/recipes/1`);

return result.json();
}, null );
```

## Examples
### Examples

A basic example where you wait for the value to be resolved.

```svelte
<script>
import { asyncState } from '@sv-use/core';

const recipe = asyncState(
fetch(`https://dummyjson.com/recipes/1`)
.then((res) => res.json()),
null
);
const recipe = asyncState(() => {
const result = fetch(`https://dummyjson.com/recipes/1`);

return result.json();
}, null );
</script>

{#if recipe.isLoading}
Expand All @@ -52,8 +50,9 @@ Note that you have to set `immediate` to `false` if you are using a function tha

let id = $state(1);
const recipe = asyncState((id) => {
return fetch(`https://dummyjson.com/recipes/${id}`)
.then((res) => res.json());
const result = fetch(`https://dummyjson.com/recipes/${id}`);

return result.json();
}, null, { immediate: false });

$effect(() => {
Expand Down
16 changes: 7 additions & 9 deletions docs/content/docs/core/auto-reset-state/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ A state that automatically resets to the default value after a delay.

## Usage

```svelte
<script>
import { autoResetState } from '@sv-use/core';
```ts
import { autoResetState } from '@sv-use/core';

const message = autoResetState('This is the default message', 3000);
const message = autoResetState('This is the default message', 3000);

function changeMessage() {
// Changes to the default value after 3 seconds
message.current = 'This is the new message';
}
</script>
function changeMessage() {
// Changes to the default value after 3 seconds
message.current = 'This is the new message';
}
```
8 changes: 3 additions & 5 deletions docs/content/docs/core/create-eye-dropper/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ Using this tool, users can sample colors from their screens, including outside o

## Usage

```svelte
<script>
import { createEyeDropper } from '@sv-use/core';
```ts
import { createEyeDropper } from '@sv-use/core';

const eyeDropper = createEyeDropper();
</script>
const eyeDropper = createEyeDropper();
```
38 changes: 18 additions & 20 deletions docs/content/docs/core/create-file-dialog/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,30 @@ Creates a file dialog to interact with programatically.

## Usage

```svelte
<script>
import { createFileDialog } from '@sv-use/core';
```ts
import { createFileDialog } from '@sv-use/core';

const dialog = createFileDialog();
</script>
const dialog = createFileDialog();
```

### Examples

```svelte
<script>
import { createFileDialog } from '@sv-use/core';

const dialog = createFileDialog({
accept: 'image/*',
multiple: true,
onChange(files) {
console.log($state.snapshot(files));
},
onCancel() {
console.log('cancelled');
}
});
</script>
```ts
import { createFileDialog } from '@sv-use/core';

const dialog = createFileDialog({
accept: 'image/*',
multiple: true,
onChange(files) {
console.log($state.snapshot(files));
},
onCancel() {
console.log('cancelled');
}
});
```

```svelte
<button onclick={dialog.open}>
Open file dialog
</button>
Expand Down
4 changes: 2 additions & 2 deletions docs/content/docs/core/create-share/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ URLs, or files.
The available share targets depend on the device, but might include the
clipboard, contacts and email applications, websites, Bluetooth, etc.

## Usage

> [!IMPORTANT]
> To prevent abuse, it must be triggered off a UI event like a button click and
> cannot be launched at arbitrary points by a script.

## Usage

```js
import { createShare } from '@sv-use/core';

Expand Down
10 changes: 4 additions & 6 deletions docs/content/docs/core/debounce/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ Debounces the update of the value after a delay.
> [!TIP]
> If you'd rather have them combined in one variable, check out [debouncedState](/docs/core/debounced-state).

```svelte
<script>
import { debounce } from '@sv-use/core';
```ts
import { debounce } from '@sv-use/core';

let search = $state('');
const debouncedSearch = debounce(() => search);
</script>
let search = $state('');
const debouncedSearch = debounce(() => search);
```
8 changes: 3 additions & 5 deletions docs/content/docs/core/debounced-state/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ A reactive state that updates its value after a delay.
> [!TIP]
> If you'd rather have them separate, check out [debounce](/docs/core/debounce).

```svelte
<script>
import { debouncedState } from '@sv-use/core';
```ts
import { debouncedState } from '@sv-use/core';

const search = debouncedState('', { delay: 1000 });
</script>
const search = debouncedState('', { delay: 1000 });
```
14 changes: 7 additions & 7 deletions docs/content/docs/core/default-state/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ A reactive state that falls back to `defaultValue` if set to `null` or `undefine
>
> This is to ensure that you can set a nullable value when changing the state without TS complaining.

```svelte
<script>
import { defaultState } from "@sv-use/core";
```ts
import { defaultState } from "@sv-use/core";

const message = defaultState("fallback message", "initial message");
const message = defaultState("fallback message", "initial message");

message.current = "Hello, World!";
// Change the value normally
message.current = "Hello, World!";

message.current = null; // message is now "fallback message"
</script>
// Set the message to the fallback message
message.current = null;
```
8 changes: 3 additions & 5 deletions docs/content/docs/core/get-active-element/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ Gets the current active element in the DOM.

## Usage

```svelte
<script>
import { getActiveElement } from '@sv-use/core';
```ts
import { getActiveElement } from '@sv-use/core';

const activeElement = getActiveElement();
</script>
const activeElement = getActiveElement();
```
7 changes: 0 additions & 7 deletions docs/content/docs/core/get-battery/Demo.svelte

This file was deleted.

17 changes: 0 additions & 17 deletions docs/content/docs/core/get-battery/index.md

This file was deleted.

14 changes: 6 additions & 8 deletions docs/content/docs/core/get-clipboard-text/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ Provides write (and optionally read) access to the text clipboard.

Set `options.legacyCopy: true` to keep the ability to copy if the [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API) is not available. It will handle copy with [document.execCommand](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand) as the fallback.

```svelte
<script>
import { getClipboardText } from '@sv-use/core';
```ts
import { getClipboardText } from '@sv-use/core';

const clipboard = getClipboardText({
allowRead: true,
legacyCopy: true
});
</script>
const clipboard = getClipboardText({
allowRead: true,
legacyCopy: true
});
```

## Examples
Expand Down
8 changes: 3 additions & 5 deletions docs/content/docs/core/get-device-motion/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ rotation rate.

## Usage

```svelte
<script>
import { getDeviceMotion } from '@sv-use/core';
```ts
import { getDeviceMotion } from '@sv-use/core';

const deviceMotion = getDeviceMotion();
</script>
const deviceMotion = getDeviceMotion();
```
8 changes: 3 additions & 5 deletions docs/content/docs/core/get-device-orientation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ device running the web page.

## Usage

```svelte
<script>
import { getDeviceOrientation } from '@sv-use/core';
```ts
import { getDeviceOrientation } from '@sv-use/core';

const deviceOrientation = getDeviceOrientation();
</script>
const deviceOrientation = getDeviceOrientation();
```
8 changes: 3 additions & 5 deletions docs/content/docs/core/get-device-pixel-ratio/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ pixels for the current display device.

## Usage

```svelte
<script>
import { getDevicePixelRatio } from '@sv-use/core';
```ts
import { getDevicePixelRatio } from '@sv-use/core';

const devicePixelRatio = getDevicePixelRatio();
</script>
const devicePixelRatio = getDevicePixelRatio();
```
8 changes: 3 additions & 5 deletions docs/content/docs/core/get-document-visibility/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ minimized window, or is otherwise not visible to the user.

## Usage

```svelte
<script>
import { getDocumentVisibility } from '@sv-use/core';
```ts
import { getDocumentVisibility } from '@sv-use/core';

const documentVisibility = getDocumentVisibility();
</script>
const documentVisibility = getDocumentVisibility();
```
8 changes: 3 additions & 5 deletions docs/content/docs/core/get-fps/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ Get the current frames per second of the device.

## Usage

```svelte
<script>
import { getFps } from '@sv-use/core';
```ts
import { getFps } from '@sv-use/core';

const fps = getFps();
</script>
const fps = getFps();
```
13 changes: 6 additions & 7 deletions docs/content/docs/core/get-geolocation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ category: sensors
It allows the user to provide their location to web applications if they so
desire.

For privacy reasons, the user is asked for permission to report location
information.
> [!IMPORTANT]
> For privacy reasons, the user is asked for permission to report location
> information.

## Usage

```svelte
<script>
import { getGeolocation } from '@sv-use/core';
```ts
import { getGeolocation } from '@sv-use/core';

const geolocation = getGeolocation();
</script>
const geolocation = getGeolocation();
```
10 changes: 4 additions & 6 deletions docs/content/docs/core/get-last-changed/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ Get the last time the reactive value changed. It is returned as a number in mill

## Usage

```svelte
<script>
import { getLastChanged } from '@sv-use/core';
```ts
import { getLastChanged } from '@sv-use/core';

let value = $state(0);
const lastChanged = getLastChanged(() => value);
</script>
let value = $state(0);
const lastChanged = getLastChanged(() => value);
```
8 changes: 3 additions & 5 deletions docs/content/docs/core/get-mouse-pressed/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ Reactive values for mouse/touch/drag pressing state.

## Usage

```svelte
<script>
import { getMousePressed } from '@sv-use/core';
```ts
import { getMousePressed } from '@sv-use/core';

const mousePressed = getMousePressed();
</script>
const mousePressed = getMousePressed();
```
Loading