@fluxlay/react 0.1.6

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.txt ADDED
@@ -0,0 +1,4 @@
1
+ Copyright (c) Fluxlay. All rights reserved.
2
+
3
+ This software is provided under the Fluxlay Terms of Service.
4
+ Full terms: https://fluxlay.com/legal/terms
package/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # @fluxlay/react
2
+
3
+ SDK for building [Fluxlay](https://fluxlay.com) wallpapers with React.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install @fluxlay/react
9
+ # or
10
+ pnpm add @fluxlay/react
11
+ ```
12
+
13
+ Also import the stylesheet in your entry file:
14
+
15
+ ```ts
16
+ import "@fluxlay/react/dist/sdk.css";
17
+ ```
18
+
19
+ ## API
20
+
21
+ ### `useBackendMouse()`
22
+
23
+ Subscribes to the global mouse position streamed from the Fluxlay backend. The Y axis is inverted so that positive values point upward (standard mathematical coordinates).
24
+
25
+ ```tsx
26
+ import { useBackendMouse } from "@fluxlay/react";
27
+
28
+ function Wallpaper() {
29
+ const { x, y } = useBackendMouse();
30
+ return <div style={{ transform: `translate(${x}px, ${y}px)` }} />;
31
+ }
32
+ ```
33
+
34
+ ### `useShell(commandId, options?)`
35
+
36
+ Executes a shell command declared in `fluxlay.yaml` and optionally renders its output into a terminal.
37
+
38
+ ```tsx
39
+ import { useShell } from "@fluxlay/react";
40
+
41
+ function Wallpaper() {
42
+ const { result, isRunning } = useShell("my-command", {
43
+ refreshInterval: 5000, // re-run every 5 seconds
44
+ });
45
+ return <pre>{result?.stdout}</pre>;
46
+ }
47
+ ```
48
+
49
+ | Option | Type | Default | Description |
50
+ |--------|------|---------|-------------|
51
+ | `refreshInterval` | `number` | `30000` | Auto-refresh interval in ms. `0` to disable. |
52
+ | `showStdout` | `boolean` | `true` | Write stdout to the linked terminal. |
53
+ | `showStderr` | `boolean` | `false` | Write stderr to the linked terminal. |
54
+ | `terminal` | `TerminalInstance` | — | Terminal instance from `useTerminal`. |
55
+ | `columns` | `number` | — | Pseudo-terminal column width. |
56
+ | `lines` | `number` | — | Pseudo-terminal row height. |
57
+
58
+ Returns `{ execute, isRunning, error, result }`.
59
+
60
+ ### `useTerminal(options?)`
61
+
62
+ Creates a read-only xterm terminal. Attach `terminalRef` to a `<div>` container.
63
+
64
+ ```tsx
65
+ import { useTerminal, useShell, TerminalThemes } from "@fluxlay/react";
66
+
67
+ function Wallpaper() {
68
+ const { terminalRef, instance } = useTerminal({
69
+ fontSize: 13,
70
+ theme: TerminalThemes.tokyoNight,
71
+ });
72
+ useShell("my-command", { terminal: instance });
73
+ return <div ref={terminalRef} />;
74
+ }
75
+ ```
76
+
77
+ | Option | Type | Default | Description |
78
+ |--------|------|---------|-------------|
79
+ | `fontSize` | `number` | `12` | Font size in pixels. |
80
+ | `fontFamily` | `string` | system monospace | CSS font-family string. |
81
+ | `theme` | `ITheme` | `TerminalThemes.dark.default` | xterm color theme. |
82
+
83
+ Returns `{ terminalRef, instance }`.
84
+
85
+ ### `runShell(commandId, options?)`
86
+
87
+ Low-level function to run a shell command imperatively.
88
+
89
+ ```ts
90
+ import { runShell } from "@fluxlay/react";
91
+
92
+ const result = await runShell("my-command", { columns: 80, lines: 24 });
93
+ console.log(result.stdout);
94
+ ```
95
+
96
+ ### `TerminalThemes`
97
+
98
+ Pre-built xterm color themes to pass to `useTerminal`.
99
+
100
+ | Key | Variants |
101
+ |-----|----------|
102
+ | `dark` | `default`, `modern` |
103
+ | `light` | `default`, `modern` |
104
+ | `nord` | — |
105
+ | `dracula` | — |
106
+ | `gruvbox` | `dark`, `light` |
107
+ | `solarized` | `dark`, `light` |
108
+ | `oneDark` | — |
109
+ | `catppuccin` | `latte`, `frappe`, `macchiato`, `mocha` |
110
+ | `monokaiPro` | — |
111
+ | `tokyoNight` | — |
112
+ | `nightOwl` | — |
113
+ | `everforest` | `dark`, `light` |
@@ -0,0 +1,226 @@
1
+ import { FitAddon } from '@xterm/addon-fit';
2
+ import { ITheme } from '@xterm/xterm';
3
+ import { RefObject } from 'react';
4
+ import { Terminal } from '@xterm/xterm';
5
+
6
+ /**
7
+ * Runs a pre-declared shell command from fluxlay.yaml.
8
+ *
9
+ * @param commandId The ID of the command declared in the manifest's `shell` section.
10
+ * @param options Options for command execution.
11
+ * @returns The standard output and error of the command.
12
+ * @throws An error if the command fails or the ID is invalid.
13
+ */
14
+ export declare function runShell(commandId: string, options?: ShellOptions): Promise<ShellResult>;
15
+
16
+ /** Options that control how a shell command is executed. */
17
+ export declare interface ShellOptions {
18
+ /** Number of columns (character width) of the pseudo-terminal. */
19
+ columns?: number;
20
+ /** Number of rows (line height) of the pseudo-terminal. */
21
+ lines?: number;
22
+ }
23
+
24
+ /** The result returned after executing a shell command. */
25
+ export declare interface ShellResult {
26
+ /** Standard output produced by the command. */
27
+ stdout: string;
28
+ /** Standard error produced by the command. */
29
+ stderr: string;
30
+ /** Exit status code of the process, or `null` if the process was terminated by a signal. */
31
+ statusCode: number | null;
32
+ /** Whether the command exited successfully (status code 0). */
33
+ success: boolean;
34
+ /** Signal number that terminated the process, or `null` if it exited normally. */
35
+ signal: number | null;
36
+ }
37
+
38
+ /** Holds the xterm {@link Terminal} and its associated {@link FitAddon}. */
39
+ export declare interface TerminalInstance {
40
+ /** The underlying xterm Terminal instance. */
41
+ terminal: Terminal;
42
+ /** The FitAddon used to resize the terminal to match its container element. */
43
+ fitAddon: FitAddon;
44
+ }
45
+
46
+ /**
47
+ * Collection of pre-built xterm color themes.
48
+ *
49
+ * Pass any of these values to the `theme` option of {@link useTerminal}.
50
+ *
51
+ * @example
52
+ * ```tsx
53
+ * const { terminalRef, instance } = useTerminal({
54
+ * theme: TerminalThemes.dracula,
55
+ * });
56
+ * ```
57
+ */
58
+ export declare const TerminalThemes: {
59
+ /** Dark themes with a transparent background. */
60
+ readonly dark: {
61
+ /** Default dark theme using Tailwind color palette. */
62
+ readonly default: ITheme;
63
+ /** Modern dark theme using Slate/Rose color palette. */
64
+ readonly modern: ITheme;
65
+ };
66
+ /** Light themes. */
67
+ readonly light: {
68
+ /** Default light theme. */
69
+ readonly default: ITheme;
70
+ /** Modern light theme. */
71
+ readonly modern: ITheme;
72
+ };
73
+ /** Nord theme — an arctic, north-bluish color palette. */
74
+ readonly nord: ITheme;
75
+ /** Dracula theme — a dark theme with vivid accent colors. */
76
+ readonly dracula: ITheme;
77
+ /** Gruvbox themes — a retro groove color scheme. */
78
+ readonly gruvbox: {
79
+ /** Gruvbox dark variant. */
80
+ readonly dark: ITheme;
81
+ /** Gruvbox light variant. */
82
+ readonly light: ITheme;
83
+ };
84
+ /** Solarized themes — a precision color scheme with reduced brightness. */
85
+ readonly solarized: {
86
+ /** Solarized dark variant. */
87
+ readonly dark: ITheme;
88
+ /** Solarized light variant. */
89
+ readonly light: ITheme;
90
+ };
91
+ /** One Dark theme — based on Atom's One Dark syntax theme. */
92
+ readonly oneDark: ITheme;
93
+ /** Catppuccin themes — a soothing pastel color scheme. */
94
+ readonly catppuccin: {
95
+ /** Catppuccin Latte — the light variant. */
96
+ readonly latte: ITheme;
97
+ /** Catppuccin Frappé — a cool medium-dark variant. */
98
+ readonly frappe: ITheme;
99
+ /** Catppuccin Macchiato — a warm medium-dark variant. */
100
+ readonly macchiato: ITheme;
101
+ /** Catppuccin Mocha — the darkest variant. */
102
+ readonly mocha: ITheme;
103
+ };
104
+ /** Monokai Pro theme — a refined dark theme inspired by Monokai. */
105
+ readonly monokaiPro: ITheme;
106
+ /** Tokyo Night theme — a dark theme inspired by Tokyo city lights. */
107
+ readonly tokyoNight: ITheme;
108
+ /** Night Owl theme — optimized for late-night coding with low brightness. */
109
+ readonly nightOwl: ITheme;
110
+ /** Everforest themes — a green-tinted theme inspired by forests. */
111
+ readonly everforest: {
112
+ /** Everforest dark variant. */
113
+ readonly dark: ITheme;
114
+ /** Everforest light variant. */
115
+ readonly light: ITheme;
116
+ };
117
+ };
118
+
119
+ /**
120
+ * React hook that subscribes to global mouse position events streamed from
121
+ * the Fluxlay backend.
122
+ *
123
+ * The Y axis is inverted so that positive values point upward, matching a
124
+ * standard mathematical coordinate system rather than the screen coordinate
125
+ * system where Y grows downward.
126
+ *
127
+ * The subscription is scoped to the window identified by the `window_label`
128
+ * query parameter of the current URL, defaulting to `"main"`.
129
+ *
130
+ * @returns The current mouse position as `{ x, y }`.
131
+ */
132
+ export declare function useBackendMouse(): {
133
+ x: number;
134
+ y: number;
135
+ };
136
+
137
+ /**
138
+ * React hook that executes a pre-declared Fluxlay shell command and
139
+ * optionally renders its output into an xterm terminal.
140
+ *
141
+ * The command runs once on mount and is re-executed whenever `commandId`
142
+ * changes or the `refreshInterval` elapses.
143
+ *
144
+ * @param commandId The ID of the command declared in `fluxlay.yaml`.
145
+ * @param options Configuration options for execution and display behaviour.
146
+ * @returns An object containing:
147
+ * - `execute` – manually triggers the command.
148
+ * - `isRunning` – `true` while the command is in progress.
149
+ * - `error` – error message string when the last execution failed, otherwise `null`.
150
+ * - `result` – the {@link ShellResult} of the last completed execution, or `null`.
151
+ */
152
+ export declare function useShell(commandId: string, options?: UseShellOptions): {
153
+ execute: () => Promise<void>;
154
+ isRunning: boolean;
155
+ error: string | null;
156
+ result: ShellResult | null;
157
+ };
158
+
159
+ /** Options for the {@link useShell} hook. */
160
+ export declare interface UseShellOptions extends ShellOptions {
161
+ /**
162
+ * Interval in milliseconds at which the command is automatically re-executed.
163
+ * Set to `0` to disable auto-refresh.
164
+ * @defaultValue 30000
165
+ */
166
+ refreshInterval?: number;
167
+ /**
168
+ * Whether to write the command's stdout to the linked terminal.
169
+ * @defaultValue true
170
+ */
171
+ showStdout?: boolean;
172
+ /**
173
+ * Whether to write the command's stderr to the linked terminal.
174
+ * @defaultValue false
175
+ */
176
+ showStderr?: boolean;
177
+ /**
178
+ * Optional terminal instance returned by {@link useTerminal}.
179
+ * When provided, command output is rendered directly into the terminal and
180
+ * the terminal dimensions are used as the pseudo-terminal size.
181
+ */
182
+ terminal?: TerminalInstance | null;
183
+ }
184
+
185
+ /**
186
+ * React hook that creates and manages a read-only xterm terminal rendered
187
+ * inside a `<div>` element.
188
+ *
189
+ * The terminal is configured for display-only use: stdin is disabled, the
190
+ * cursor is hidden, and the scrollback buffer is removed. Custom CSS overrides
191
+ * are injected into `document.head` to make the terminal behave as an inline
192
+ * block that expands to fill its container width.
193
+ *
194
+ * The terminal is disposed and the injected styles are removed when the
195
+ * component unmounts or when `fontSize` / `fontFamily` change.
196
+ *
197
+ * @param options Display configuration for the terminal.
198
+ * @returns An object containing:
199
+ * - `terminalRef` – a React ref that must be attached to the container `<div>`.
200
+ * - `instance` – the {@link TerminalInstance} once the terminal is mounted, or `null`.
201
+ */
202
+ export declare function useTerminal(options?: UseTerminalOptions): {
203
+ terminalRef: RefObject<HTMLDivElement | null>;
204
+ instance: TerminalInstance | null;
205
+ };
206
+
207
+ /** Options for the {@link useTerminal} hook. */
208
+ export declare interface UseTerminalOptions {
209
+ /**
210
+ * Font size in pixels used by the terminal.
211
+ * @defaultValue 12
212
+ */
213
+ fontSize?: number;
214
+ /**
215
+ * CSS font-family string applied to the terminal.
216
+ * Defaults to a system monospace font stack.
217
+ */
218
+ fontFamily?: string;
219
+ /**
220
+ * Color theme applied to the terminal.
221
+ * @defaultValue {@link TerminalThemes.dark.default}
222
+ */
223
+ theme?: ITheme;
224
+ }
225
+
226
+ export { }