@rokkit/app 1.0.0-next.132 → 1.0.0-next.134
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +111 -0
- package/package.json +9 -5
- package/src/components/ThemeSwitcherToggle.svelte +1 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jerry Thomas
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @rokkit/app
|
|
2
|
+
|
|
3
|
+
App-level controls for Rokkit applications — color mode management and theme switching.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @rokkit/app
|
|
9
|
+
# or
|
|
10
|
+
bun add @rokkit/app
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
`@rokkit/app` provides the application-level plumbing for Rokkit projects:
|
|
16
|
+
|
|
17
|
+
- **`ColorModeManager`** — reactive class that tracks `system` / `light` / `dark` mode, resolves `system` to the actual OS preference, and syncs to the active theme target
|
|
18
|
+
- **`ThemeSwitcherToggle`** — Svelte component for a three-way light/dark/system toggle
|
|
19
|
+
- **`resolveMode`** — utility to resolve `'system'` to `'light'` or `'dark'` via `matchMedia`
|
|
20
|
+
|
|
21
|
+
Works directly with `@rokkit/unocss` dark mode: `ColorModeManager` sets `data-mode` on the `<html>` element, which the UnoCSS preset uses as its dark mode selector.
|
|
22
|
+
|
|
23
|
+
Requires Svelte 5.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### ColorModeManager
|
|
28
|
+
|
|
29
|
+
`ColorModeManager` is a Svelte 5 reactive class (`$state` internals). Instantiate it with a theme target — typically the `vibe` singleton from `@rokkit/states`.
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import { ColorModeManager } from '@rokkit/app'
|
|
33
|
+
import { vibe } from '@rokkit/states'
|
|
34
|
+
|
|
35
|
+
const modeManager = new ColorModeManager(vibe)
|
|
36
|
+
|
|
37
|
+
// Read current mode
|
|
38
|
+
console.log(modeManager.mode) // 'system' | 'light' | 'dark'
|
|
39
|
+
console.log(modeManager.resolved) // 'light' | 'dark'
|
|
40
|
+
|
|
41
|
+
// Change mode
|
|
42
|
+
modeManager.mode = 'dark'
|
|
43
|
+
modeManager.mode = 'system' // will re-resolve from OS preference
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Listening for OS preference changes
|
|
47
|
+
|
|
48
|
+
Call `listen()` inside `onMount` or a `$effect.root`. It returns a cleanup function.
|
|
49
|
+
|
|
50
|
+
```svelte
|
|
51
|
+
<script>
|
|
52
|
+
import { onMount } from 'svelte'
|
|
53
|
+
import { ColorModeManager } from '@rokkit/app'
|
|
54
|
+
import { vibe } from '@rokkit/states'
|
|
55
|
+
|
|
56
|
+
const modeManager = new ColorModeManager(vibe)
|
|
57
|
+
|
|
58
|
+
onMount(() => {
|
|
59
|
+
return modeManager.listen() // returns cleanup fn, called on destroy
|
|
60
|
+
})
|
|
61
|
+
</script>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
When `mode` is `'system'`, the manager automatically updates `resolved` whenever the OS preference changes.
|
|
65
|
+
|
|
66
|
+
### ThemeSwitcherToggle
|
|
67
|
+
|
|
68
|
+
Drop-in Svelte component that renders a three-way toggle (light / dark / system). Pass the `ColorModeManager` instance as a prop.
|
|
69
|
+
|
|
70
|
+
```svelte
|
|
71
|
+
<script>
|
|
72
|
+
import { ThemeSwitcherToggle, ColorModeManager } from '@rokkit/app'
|
|
73
|
+
import { vibe } from '@rokkit/states'
|
|
74
|
+
|
|
75
|
+
const modeManager = new ColorModeManager(vibe)
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<ThemeSwitcherToggle {modeManager} />
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### resolveMode utility
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
import { resolveMode } from '@rokkit/app'
|
|
85
|
+
|
|
86
|
+
resolveMode('system') // 'light' or 'dark' based on OS preference
|
|
87
|
+
resolveMode('dark') // 'dark'
|
|
88
|
+
resolveMode('light') // 'light'
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## API
|
|
92
|
+
|
|
93
|
+
| Export | Description |
|
|
94
|
+
| --------------------- | ----------------------------------------------------- |
|
|
95
|
+
| `ColorModeManager` | Reactive class for tracking and resolving color mode |
|
|
96
|
+
| `ThemeSwitcherToggle` | Svelte component — three-way light/dark/system toggle |
|
|
97
|
+
| `resolveMode(mode)` | Resolve `'system'` to actual `'light'` \| `'dark'` |
|
|
98
|
+
| `ColorMode` | Type: `'system' \| 'light' \| 'dark'` |
|
|
99
|
+
| `ResolvedMode` | Type: `'light' \| 'dark'` |
|
|
100
|
+
|
|
101
|
+
### ColorModeManager members
|
|
102
|
+
|
|
103
|
+
| Member | Type | Description |
|
|
104
|
+
| ---------- | --------------------- | ------------------------------------------------ |
|
|
105
|
+
| `mode` | `ColorMode` (get/set) | Current three-way mode selection |
|
|
106
|
+
| `resolved` | `ResolvedMode` (get) | Actual light or dark value |
|
|
107
|
+
| `listen()` | `() => () => void` | Start OS preference listener; returns cleanup fn |
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
Part of [Rokkit](https://github.com/jerrythomas/rokkit) — a Svelte 5 component library and design system.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rokkit/app",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.134",
|
|
4
4
|
"description": "App-level controls for Rokkit applications - theme management and UI chrome",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,18 +20,22 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
|
-
"src"
|
|
23
|
+
"src",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
24
26
|
],
|
|
25
27
|
"scripts": {
|
|
28
|
+
"prepublishOnly": "cp ../../LICENSE .",
|
|
29
|
+
"postpublish": "rm -f LICENSE",
|
|
26
30
|
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
27
31
|
"test": "vitest run",
|
|
28
32
|
"test:watch": "vitest",
|
|
29
33
|
"build": "echo 'No build step needed for source-only package'"
|
|
30
34
|
},
|
|
31
35
|
"dependencies": {
|
|
32
|
-
"@rokkit/core": "1.0.0-next.
|
|
33
|
-
"@rokkit/states": "1.0.0-next.
|
|
34
|
-
"@rokkit/ui": "1.0.0-next.
|
|
36
|
+
"@rokkit/core": "1.0.0-next.134",
|
|
37
|
+
"@rokkit/states": "1.0.0-next.134",
|
|
38
|
+
"@rokkit/ui": "1.0.0-next.134"
|
|
35
39
|
},
|
|
36
40
|
"peerDependencies": {
|
|
37
41
|
"svelte": "^5.0.0"
|
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
import { vibe } from '@rokkit/states'
|
|
4
4
|
import { Toggle } from '@rokkit/ui'
|
|
5
5
|
import type { ThemeSwitcherToggleProps } from '../types/theme-switcher.js'
|
|
6
|
-
import {
|
|
7
|
-
defaultThemeSwitcherIcons,
|
|
8
|
-
buildThemeSwitcherOptions
|
|
9
|
-
} from '../types/theme-switcher.js'
|
|
6
|
+
import { defaultThemeSwitcherIcons, buildThemeSwitcherOptions } from '../types/theme-switcher.js'
|
|
10
7
|
import { ColorModeManager, type ColorMode } from '../utils/color-mode.svelte.js'
|
|
11
8
|
|
|
12
9
|
let {
|