@glissade/react 0.1.0 → 0.3.0
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/README.md +24 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.js +14 -1
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @glissade/react
|
|
2
|
+
|
|
3
|
+
Thin React adapters over the signal graph via `useSyncExternalStore` — components re-render only when a value actually changes. Includes the v2 machine hooks, typed structurally so this package never depends on `@glissade/interact`.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm i @glissade/react
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { useSignalValue, usePlayhead, useMachineState, useInput } from '@glissade/react';
|
|
11
|
+
|
|
12
|
+
const t = usePlayhead(player);
|
|
13
|
+
const state = useMachineState(machine); // 'idle' | 'hover' | ...
|
|
14
|
+
const [hovered, setHovered] = useInput(machine, 'hovered');
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Part of glissade
|
|
18
|
+
|
|
19
|
+
*(glide & slide)* — programmatic motion graphics for TypeScript: realtime-first in any web page, deterministic headless video export from the same code, a visual studio over the same document. No generator functions.
|
|
20
|
+
|
|
21
|
+
- [Repository & full README](https://github.com/tyevco/glissade)
|
|
22
|
+
- [Getting started](https://github.com/tyevco/glissade/blob/main/docs/getting-started.md) · [Concepts](https://github.com/tyevco/glissade/blob/main/docs/concepts.md) · [Interactivity](https://github.com/tyevco/glissade/blob/main/docs/interactivity.md)
|
|
23
|
+
|
|
24
|
+
Apache-2.0.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReadonlySignal } from "@glissade/core";
|
|
1
|
+
import { ReadonlySignal, Signal } from "@glissade/core";
|
|
2
2
|
import { Player } from "@glissade/player";
|
|
3
3
|
|
|
4
4
|
//#region src/index.d.ts
|
|
@@ -13,5 +13,17 @@ declare function usePlayerState(player: Player): {
|
|
|
13
13
|
time: number;
|
|
14
14
|
duration: number;
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Machine hooks (v2 §C.6): the machine's active state and inputs are signals,
|
|
18
|
+
* so the §4.3 contract already covers them. Typed structurally — react never
|
|
19
|
+
* imports @glissade/interact; any object with this shape works.
|
|
20
|
+
*/
|
|
21
|
+
declare function useMachineState(machine: {
|
|
22
|
+
current: ReadonlySignal<string>;
|
|
23
|
+
}): string;
|
|
24
|
+
/** A machine input as React state: [value, set]. */
|
|
25
|
+
declare function useInput<T extends boolean | number>(machine: {
|
|
26
|
+
input(name: string): Signal<T>;
|
|
27
|
+
}, name: string): [T, (value: T) => void];
|
|
16
28
|
//#endregion
|
|
17
|
-
export { usePlayerState, usePlayhead, useSignalValue };
|
|
29
|
+
export { useInput, useMachineState, usePlayerState, usePlayhead, useSignalValue };
|
package/dist/index.js
CHANGED
|
@@ -26,5 +26,18 @@ function usePlayerState(player) {
|
|
|
26
26
|
duration: player.duration
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Machine hooks (v2 §C.6): the machine's active state and inputs are signals,
|
|
31
|
+
* so the §4.3 contract already covers them. Typed structurally — react never
|
|
32
|
+
* imports @glissade/interact; any object with this shape works.
|
|
33
|
+
*/
|
|
34
|
+
function useMachineState(machine) {
|
|
35
|
+
return useSignalValue(machine.current);
|
|
36
|
+
}
|
|
37
|
+
/** A machine input as React state: [value, set]. */
|
|
38
|
+
function useInput(machine, name) {
|
|
39
|
+
const sig = machine.input(name);
|
|
40
|
+
return [useSignalValue(sig), useCallback((v) => sig.set(v), [sig])];
|
|
41
|
+
}
|
|
29
42
|
//#endregion
|
|
30
|
-
export { usePlayerState, usePlayhead, useSignalValue };
|
|
43
|
+
export { useInput, useMachineState, usePlayerState, usePlayhead, useSignalValue };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glissade/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "glissade React bindings: signals via useSyncExternalStore, player hooks.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@glissade/core": "0.
|
|
19
|
-
"@glissade/player": "0.
|
|
18
|
+
"@glissade/core": "0.3.0",
|
|
19
|
+
"@glissade/player": "0.3.0"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"react": ">=18"
|