@gtkx/animated 1.6.0 → 2.0.0-beta.10
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 +47 -44
- package/dist/animated.d.ts +4 -13
- package/dist/animated.d.ts.map +1 -1
- package/dist/animated.js +2 -38
- package/dist/animated.js.map +1 -1
- package/dist/apply-animated-values.d.ts.map +1 -1
- package/dist/apply-animated-values.js +2 -5
- package/dist/apply-animated-values.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +5 -17
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/with-animated.d.ts.map +1 -1
- package/dist/with-animated.js +1 -7
- package/dist/with-animated.js.map +1 -1
- package/package.json +14 -16
- package/src/animated.ts +5 -53
- package/src/apply-animated-values.ts +2 -7
- package/src/index.ts +0 -2
- package/src/types.ts +7 -27
- package/src/with-animated.tsx +1 -10
- package/dist/internal.d.ts +0 -3
- package/dist/internal.d.ts.map +0 -1
- package/dist/internal.js +0 -3
- package/dist/internal.js.map +0 -1
- package/src/internal.ts +0 -3
package/README.md
CHANGED
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
<h1 align="center">GTKX</h1>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
-
The React framework for Linux
|
|
9
|
-
Write native
|
|
10
|
-
Real
|
|
8
|
+
The React framework for Linux.<br />
|
|
9
|
+
Write native GNOME applications with React and TypeScript.
|
|
10
|
+
Real Adwaita and GTK4 widgets with standard web tooling.
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
13
|
<p align="center">
|
|
14
14
|
<a href="https://www.npmjs.com/package/create-gtkx"><img src="https://img.shields.io/npm/v/create-gtkx?color=cb3837&logo=npm&label=create-gtkx" alt="npm version" /></a>
|
|
15
15
|
<a href="https://www.npmjs.com/package/create-gtkx"><img src="https://img.shields.io/npm/dm/create-gtkx?color=cb3837&logo=npm&label=downloads" alt="npm downloads" /></a>
|
|
16
|
-
<img src="https://img.shields.io/badge/node-%E2%89%
|
|
16
|
+
<img src="https://img.shields.io/badge/node-%E2%89%A526.7-339933?logo=node.js&logoColor=white" alt="Node >= 26.7" />
|
|
17
17
|
<a href="https://github.com/gtkx-org/gtkx/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MPL--2.0-blue.svg" alt="License: MPL-2.0" /></a>
|
|
18
18
|
<a href="https://github.com/gtkx-org/gtkx/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/gtkx-org/gtkx/ci.yml?branch=main&logo=github&label=CI" alt="CI status" /></a>
|
|
19
19
|
<img src="https://img.shields.io/badge/TypeScript-strict-3178c6?logo=typescript&logoColor=white" alt="TypeScript" />
|
|
@@ -38,11 +38,12 @@
|
|
|
38
38
|
|
|
39
39
|
## Demo
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
This app starts with an Adwaita application shell, renders native GTK4 widgets inside it, and uses ordinary React hooks and events:
|
|
42
42
|
|
|
43
43
|
```tsx
|
|
44
44
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
45
|
-
import {
|
|
45
|
+
import { AdwApplication, AdwApplicationWindow, AdwHeaderBar, AdwToolbarView } from "@gtkx/jsx/adw";
|
|
46
|
+
import { GtkBox, GtkButton, GtkLabel } from "@gtkx/jsx/gtk";
|
|
46
47
|
import { createRoot, quit } from "@gtkx/react";
|
|
47
48
|
import { useState } from "react";
|
|
48
49
|
|
|
@@ -50,38 +51,40 @@ const Counter = () => {
|
|
|
50
51
|
const [count, setCount] = useState(0);
|
|
51
52
|
|
|
52
53
|
return (
|
|
53
|
-
<
|
|
54
|
+
<AdwApplicationWindow
|
|
54
55
|
title="Hello GTKX"
|
|
55
56
|
defaultWidth={400}
|
|
56
57
|
defaultHeight={300}
|
|
57
58
|
onCloseRequest={quit}
|
|
58
59
|
>
|
|
59
|
-
<
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
60
|
+
<AdwToolbarView topBar={<AdwHeaderBar />}>
|
|
61
|
+
<GtkBox
|
|
62
|
+
orientation={Gtk.Orientation.VERTICAL}
|
|
63
|
+
spacing={20}
|
|
64
|
+
marginTop={40}
|
|
65
|
+
marginBottom={40}
|
|
66
|
+
marginStart={40}
|
|
67
|
+
marginEnd={40}
|
|
68
|
+
valign={Gtk.Align.CENTER}
|
|
69
|
+
halign={Gtk.Align.CENTER}
|
|
70
|
+
>
|
|
71
|
+
<GtkLabel cssClasses={["title-1"]}>Welcome to GTKX!</GtkLabel>
|
|
72
|
+
<GtkLabel cssClasses={["title-2"]}>{`Count: ${String(count)}`}</GtkLabel>
|
|
73
|
+
<GtkButton
|
|
74
|
+
label="Increment"
|
|
75
|
+
onClicked={() => setCount((c) => c + 1)}
|
|
76
|
+
cssClasses={["suggested-action", "pill"]}
|
|
77
|
+
/>
|
|
78
|
+
</GtkBox>
|
|
79
|
+
</AdwToolbarView>
|
|
80
|
+
</AdwApplicationWindow>
|
|
78
81
|
);
|
|
79
82
|
};
|
|
80
83
|
|
|
81
84
|
const App = () => (
|
|
82
|
-
<
|
|
85
|
+
<AdwApplication>
|
|
83
86
|
<Counter />
|
|
84
|
-
</
|
|
87
|
+
</AdwApplication>
|
|
85
88
|
);
|
|
86
89
|
|
|
87
90
|
createRoot().render(<App />);
|
|
@@ -91,9 +94,9 @@ This is the [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/
|
|
|
91
94
|
|
|
92
95
|
## Why GTKX
|
|
93
96
|
|
|
94
|
-
###
|
|
97
|
+
### Adwaita-first application development
|
|
95
98
|
|
|
96
|
-
|
|
99
|
+
GTKX uses Adwaita as the foundation for applications, windows, navigation, dialogs, and adaptive layouts, with the complete GTK4 toolkit underneath. It adds a declarative React layer and an integrated TypeScript toolchain to the GNOME platform:
|
|
97
100
|
|
|
98
101
|
- a React reconciler that exposes every GObject as a JSX element,
|
|
99
102
|
- a CLI for scaffolding, development, and production builds,
|
|
@@ -102,29 +105,29 @@ GTK4 is mature, and GtkBuilder XML can lay out a static interface, but nothing r
|
|
|
102
105
|
- a Testing Library-style API for querying and driving your widgets in tests,
|
|
103
106
|
- and a Model Context Protocol (MCP) server that exposes your live app to AI agents.
|
|
104
107
|
|
|
105
|
-
###
|
|
108
|
+
### Native GNOME widgets, without a compatibility layer
|
|
106
109
|
|
|
107
|
-
React Native and similar frameworks hide the native toolkit so one API can run everywhere. GTKX
|
|
110
|
+
React Native and similar frameworks hide the native toolkit so one API can run everywhere. GTKX renders real Adwaita and GTK4 widgets and exposes any other GObject-Introspection library on your system. It is GNOME-native and Linux-only by design.
|
|
108
111
|
|
|
109
112
|
### Why Node.js, and why generated bindings
|
|
110
113
|
|
|
111
114
|
GTKX runs on Node.js, which puts native modules, the npm ecosystem, and the tooling built for Node.js APIs within reach. GJS is GNOME's own runtime, built on SpiderMonkey rather than V8; node-gtk runs on Node.js but is lightly maintained, on the older nan/V8 ABI rather than N-API, and still centered on GTK3. The [Why GTKX guide](https://gtkx.dev/guide/why-gtkx) covers what running on Node.js means day to day.
|
|
112
115
|
|
|
113
|
-
GTKX generates the TypeScript types and
|
|
116
|
+
GTKX generates the TypeScript types and native FFI calls from the same GObject-Introspection data, so the types cannot drift from the calls they back. `Adw-1` is the sole default GIR root; its GIR include pulls in `Gtk-4.0`, so codegen covers both complete API surfaces. Neither belongs in a GTKX 2 `libraries` list.
|
|
114
117
|
|
|
115
|
-
At runtime, the native Rust core calls straight into the system
|
|
118
|
+
At runtime, the native Rust core calls straight into the system Adwaita, GTK4, and GLib libraries through libffi, without loading libgirepository at all.
|
|
116
119
|
|
|
117
120
|
## Quick start
|
|
118
121
|
|
|
119
|
-
GTKX is Linux-only and needs Node.js
|
|
122
|
+
GTKX is Linux-only and needs Node.js 26.7 or later. See [Requirements](#requirements).
|
|
120
123
|
|
|
121
124
|
Scaffold a new app with the `create-gtkx` initializer:
|
|
122
125
|
|
|
123
126
|
```sh
|
|
124
|
-
npm create gtkx
|
|
127
|
+
npm create gtkx@beta
|
|
125
128
|
```
|
|
126
129
|
|
|
127
|
-
The same command works with other package managers: `pnpm create gtkx` or `yarn create gtkx`.
|
|
130
|
+
The same command works with other package managers: `pnpm create gtkx@beta` or `yarn create gtkx@beta`.
|
|
128
131
|
|
|
129
132
|
Then run your new app:
|
|
130
133
|
|
|
@@ -145,8 +148,8 @@ The documentation at **[gtkx.dev](https://gtkx.dev)** includes a step-by-step tu
|
|
|
145
148
|
|
|
146
149
|
GTKX is Linux-only. You need:
|
|
147
150
|
|
|
148
|
-
- Linux with the
|
|
149
|
-
- Node.js
|
|
151
|
+
- Linux with the Adwaita (1.8 or later), GTK4 (4.20 or later), and GLib development libraries
|
|
152
|
+
- Node.js 26.7 or later
|
|
150
153
|
|
|
151
154
|
The `@gtkx/native` addon ships prebuilt for x64 and arm64 glibc Linux; other targets need to build it from the GTKX repository, which requires a Rust toolchain.
|
|
152
155
|
|
|
@@ -154,10 +157,10 @@ The `@gtkx/native` addon ships prebuilt for x64 and arm64 glibc Linux; other tar
|
|
|
154
157
|
|
|
155
158
|
Explore the [example apps](https://github.com/gtkx-org/gtkx/tree/main/examples):
|
|
156
159
|
|
|
157
|
-
- [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/hello-world): the counter above.
|
|
158
|
-
- [`gtk-demo`](https://github.com/gtkx-org/gtkx/tree/main/examples/gtk-demo):
|
|
159
|
-
- [`browser`](https://github.com/gtkx-org/gtkx/tree/main/examples/browser):
|
|
160
|
-
- [`animations`](https://github.com/gtkx-org/gtkx/tree/main/examples/animations):
|
|
160
|
+
- [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/hello-world): the Adwaita counter above.
|
|
161
|
+
- [`gtk-demo`](https://github.com/gtkx-org/gtkx/tree/main/examples/gtk-demo): the official GTK4 widget showcase in an Adwaita application shell, covering lists, dialogs, gestures, CSS, and OpenGL.
|
|
162
|
+
- [`browser`](https://github.com/gtkx-org/gtkx/tree/main/examples/browser): an Adwaita browser built around `WebKitWebView`.
|
|
163
|
+
- [`animations`](https://github.com/gtkx-org/gtkx/tree/main/examples/animations): an Adwaita showcase for `@gtkx/animated`, with React Spring animations driven by the GTK frame clock.
|
|
161
164
|
- [`navigation`](https://github.com/gtkx-org/gtkx/tree/main/examples/navigation): a tour of `@gtkx/navigation`, React Navigation's stack, tab, and drawer navigators rendered with libadwaita.
|
|
162
165
|
- [`tutorial`](https://github.com/gtkx-org/gtkx/tree/main/examples/tutorial): the Tasks app the documentation builds.
|
|
163
166
|
|
|
@@ -167,7 +170,7 @@ GTKX is stable and ready for production use.
|
|
|
167
170
|
|
|
168
171
|
## Contributing
|
|
169
172
|
|
|
170
|
-
Contributions are welcome. See [CONTRIBUTING.md](https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md), the [Code of Conduct](https://github.com/gtkx-org/gtkx/blob/main/CODE_OF_CONDUCT.md), and the [security policy](https://github.com/gtkx-org/gtkx/blob/main/SECURITY.md). Building the repo needs Node.js
|
|
173
|
+
Contributions are welcome. See [CONTRIBUTING.md](https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md), the [Code of Conduct](https://github.com/gtkx-org/gtkx/blob/main/CODE_OF_CONDUCT.md), and the [security policy](https://github.com/gtkx-org/gtkx/blob/main/SECURITY.md). Building the repo needs Node.js 26.7 or later, pnpm, and a Rust toolchain.
|
|
171
174
|
|
|
172
175
|
## License
|
|
173
176
|
|
package/dist/animated.d.ts
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
import type { ElementType } from "react";
|
|
2
|
-
import type { AnimatedComponent
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
* component as a property, so `animated.GtkLabel` is the animated form of `GtkLabel`.
|
|
6
|
-
*/
|
|
7
|
-
type Animated = (<T extends Exclude<ElementType, string>>(component: T) => AnimatedComponent<T>) & AnimatedElementMap;
|
|
2
|
+
import type { AnimatedComponent } from "./types.js";
|
|
3
|
+
/** Callable entrypoint that wraps a component with animated props. */
|
|
4
|
+
type Animated = <T extends Exclude<ElementType, string>>(component: T) => AnimatedComponent<T>;
|
|
8
5
|
/**
|
|
9
6
|
* Wraps a component so that its props accept springs and interpolations: `animated(GtkLabel)` is
|
|
10
7
|
* `GtkLabel` with every prop also taking a `SpringValue` or an `Interpolation`. Animated values are
|
|
11
8
|
* written to the widget on each frame without a React render. The wrapper of a given component is
|
|
12
|
-
* created once and reused
|
|
13
|
-
*
|
|
14
|
-
* Every widget component of the generated `@gtkx/jsx` store is also available as a property:
|
|
15
|
-
* `animated.GtkLabel` is `animated(GtkLabel)` without the import. **Deprecated: property access is
|
|
16
|
-
* removed in GTKX 2.0**, where `animated` is only callable; import the component and call
|
|
17
|
-
* `animated(GtkLabel)` instead, which also lets a production bundle drop the widgets an
|
|
18
|
-
* application never animates.
|
|
9
|
+
* created once and reused.
|
|
19
10
|
*/
|
|
20
11
|
declare const animated: Animated;
|
|
21
12
|
export { animated, type Animated };
|
package/dist/animated.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"animated.d.ts","sourceRoot":"","sources":["../src/animated.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"animated.d.ts","sourceRoot":"","sources":["../src/animated.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGpD,sEAAsE;AACtE,KAAK,QAAQ,GAAG,CAAC,CAAC,SAAS,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,KAAK,iBAAiB,CAAC,CAAC,CAAC,CAAC;AAE/F;;;;;GAKG;AACH,QAAA,MAAM,QAAQ,EAAE,QAAuB,CAAC;AAExC,OAAO,EAAE,QAAQ,EAAE,KAAK,QAAQ,EAAE,CAAC"}
|
package/dist/animated.js
CHANGED
|
@@ -1,46 +1,10 @@
|
|
|
1
|
-
import * as elements from "@gtkx/jsx";
|
|
2
1
|
import { withAnimated } from "./with-animated.js";
|
|
3
2
|
/**
|
|
4
3
|
* Wraps a component so that its props accept springs and interpolations: `animated(GtkLabel)` is
|
|
5
4
|
* `GtkLabel` with every prop also taking a `SpringValue` or an `Interpolation`. Animated values are
|
|
6
5
|
* written to the widget on each frame without a React render. The wrapper of a given component is
|
|
7
|
-
* created once and reused
|
|
8
|
-
*
|
|
9
|
-
* Every widget component of the generated `@gtkx/jsx` store is also available as a property:
|
|
10
|
-
* `animated.GtkLabel` is `animated(GtkLabel)` without the import. **Deprecated: property access is
|
|
11
|
-
* removed in GTKX 2.0**, where `animated` is only callable; import the component and call
|
|
12
|
-
* `animated(GtkLabel)` instead, which also lets a production bundle drop the widgets an
|
|
13
|
-
* application never animates.
|
|
6
|
+
* created once and reused.
|
|
14
7
|
*/
|
|
15
|
-
const animated =
|
|
16
|
-
get(target, property, receiver) {
|
|
17
|
-
const component = componentFor(property);
|
|
18
|
-
return component === null ? Reflect.get(target, property, receiver) : withAnimated(component);
|
|
19
|
-
},
|
|
20
|
-
getOwnPropertyDescriptor(target, property) {
|
|
21
|
-
const component = componentFor(property);
|
|
22
|
-
if (component === null) {
|
|
23
|
-
return Reflect.getOwnPropertyDescriptor(target, property);
|
|
24
|
-
}
|
|
25
|
-
return { configurable: true, enumerable: true, writable: false, value: withAnimated(component) };
|
|
26
|
-
},
|
|
27
|
-
has(target, property) {
|
|
28
|
-
return componentFor(property) !== null || Reflect.has(target, property);
|
|
29
|
-
},
|
|
30
|
-
ownKeys(target) {
|
|
31
|
-
const names = Object.keys(elements).filter((name) => componentFor(name) !== null);
|
|
32
|
-
return [...new Set([...Reflect.ownKeys(target), ...names])];
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
function componentFor(property) {
|
|
36
|
-
const value = Reflect.get(elements, property);
|
|
37
|
-
return isComponent(value) ? value : null;
|
|
38
|
-
}
|
|
39
|
-
function isComponent(value) {
|
|
40
|
-
return typeof value === "function";
|
|
41
|
-
}
|
|
42
|
-
function wrapComponent(component) {
|
|
43
|
-
return withAnimated(component);
|
|
44
|
-
}
|
|
8
|
+
const animated = withAnimated;
|
|
45
9
|
export { animated };
|
|
46
10
|
//# sourceMappingURL=animated.js.map
|
package/dist/animated.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"animated.js","sourceRoot":"","sources":["../src/animated.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"animated.js","sourceRoot":"","sources":["../src/animated.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKlD;;;;;GAKG;AACH,MAAM,QAAQ,GAAa,YAAY,CAAC;AAExC,OAAO,EAAE,QAAQ,EAAiB,CAAC","sourcesContent":["import type { ElementType } from \"react\";\nimport type { AnimatedComponent } from \"./types.js\";\nimport { withAnimated } from \"./with-animated.js\";\n\n/** Callable entrypoint that wraps a component with animated props. */\ntype Animated = <T extends Exclude<ElementType, string>>(component: T) => AnimatedComponent<T>;\n\n/**\n * Wraps a component so that its props accept springs and interpolations: `animated(GtkLabel)` is\n * `GtkLabel` with every prop also taking a `SpringValue` or an `Interpolation`. Animated values are\n * written to the widget on each frame without a React render. The wrapper of a given component is\n * created once and reused.\n */\nconst animated: Animated = withAnimated;\n\nexport { animated, type Animated };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-animated-values.d.ts","sourceRoot":"","sources":["../src/apply-animated-values.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"apply-animated-values.d.ts","sourceRoot":"","sources":["../src/apply-animated-values.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAmGlD,QAAA,MAAM,sBAAsB,GAAI,UAAU,MAAM,EAAE,QAAQ,MAAM,KAAG,OAUlE,CAAC;AAEF,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -17,11 +17,8 @@ const hasSetter = (instance, name) => {
|
|
|
17
17
|
if (prototype === null) {
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
known = new Map();
|
|
23
|
-
setterCache.set(prototype, known);
|
|
24
|
-
}
|
|
20
|
+
const known = setterCache.get(prototype) ?? new Map();
|
|
21
|
+
setterCache.set(prototype, known);
|
|
25
22
|
let isWritable = known.get(name);
|
|
26
23
|
if (isWritable === undefined) {
|
|
27
24
|
isWritable = hasSetterInChain(prototype, name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-animated-values.js","sourceRoot":"","sources":["../src/apply-animated-values.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,MAAM,UAAU,GAAG,OAAO,CAAC;AAC3B,MAAM,WAAW,GAA0C,IAAI,OAAO,EAAE,CAAC;AAEzE,MAAM,gBAAgB,GAAG,CAAC,SAAwB,EAAE,IAAY,EAAW,EAAE;IACzE,KAAK,IAAI,OAAO,GAAG,SAAS,EAAE,OAAO,KAAK,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAkB,EAAE,CAAC;QACxG,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC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CAAC,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,QAAgB,EAAE,MAAc,EAAW,EAAE;IACzE,IAAI,SAAS,GAAG,IAAI,CAAC;IAErB,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;QACxB,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;YAC/C,SAAS,GAAG,KAAK,CAAC;QACtB,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC;AAEF,OAAO,EAAE,sBAAsB,EAAE,CAAC","sourcesContent":["import type { Lookup } from \"@react-spring/types\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { applyStyle, applyWrite } from \"@gtkx/react/internal\";\nimport { coerceObjectProperty } from \"@gtkx/runtime\";\n\nconst LABEL_PROP = \"label\";\nconst setterCache: WeakMap<object, Map<string, boolean>> = new WeakMap();\n\nconst hasSetterInChain = (prototype: object | null, name: string): boolean => {\n for (let current = prototype; current !== null; current = Object.getPrototypeOf(current) as object | null) {\n const descriptor = Object.getOwnPropertyDescriptor(current, name);\n\n if (descriptor !== undefined) {\n return descriptor.set !== undefined;\n }\n }\n\n return false;\n};\n\nconst hasSetter = (instance: object, name: string): boolean => {\n const prototype = Object.getPrototypeOf(instance) as object | null;\n\n if (prototype === null) {\n return false;\n }\n\n const known = setterCache.get(prototype) ?? new Map<string, boolean>();\n setterCache.set(prototype, known);\n let isWritable = known.get(name);\n\n if (isWritable === undefined) {\n isWritable = hasSetterInChain(prototype, name);\n known.set(name, isWritable);\n }\n\n return isWritable;\n};\n\nconst isText = (value: unknown): value is string | number => typeof value === \"string\" || typeof value === \"number\";\n\nconst getText = (value: unknown): string | null => {\n if (isText(value)) {\n return String(value);\n }\n\n if (!Array.isArray(value)) {\n return null;\n }\n\n const texts = value.map((item) => getText(item));\n\n return texts.every((item) => item !== null) ? texts.join(\"\") : null;\n};\n\nconst didApplyText = (instance: object, value: unknown): boolean => {\n const text = getText(value);\n\n if (text === null || !(instance instanceof Gtk.Label)) {\n return false;\n }\n\n applyWrite(LABEL_PROP, () => {\n instance.setLabel(text);\n });\n\n return true;\n};\n\nconst didApplyStyle = (instance: object, value: unknown): boolean => {\n if (!(instance instanceof Gtk.Widget)) {\n return false;\n }\n\n applyStyle(instance, value);\n\n return true;\n};\n\nconst didApplyValue = (instance: object, name: string, value: unknown): boolean => {\n if (name === \"children\") {\n return didApplyText(instance, value);\n }\n\n if (name === \"style\") {\n return didApplyStyle(instance, value);\n }\n\n if (!hasSetter(instance, name)) {\n return false;\n }\n\n applyWrite(name, () => {\n Reflect.set(instance, name, coerceObjectProperty(instance, name, value));\n });\n\n return true;\n};\n\nconst didApplyAnimatedValues = (instance: object, values: Lookup): boolean => {\n let isApplied = true;\n\n for (const name in values) {\n if (!didApplyValue(instance, name, values[name])) {\n isApplied = false;\n }\n }\n\n return isApplied;\n};\n\nexport { didApplyAnimatedValues };\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "./bootstrap.js";
|
|
2
2
|
export { animated, type Animated } from "./animated.js";
|
|
3
3
|
export { useReducedMotion } from "./reduced-motion.js";
|
|
4
|
-
export type { AnimatedComponent, AnimatedElementMap,
|
|
4
|
+
export type { AnimatedComponent, AnimatedElementMap, AnimatedItems, AnimatedProp, AnimatedProps, AnimatedStyle, } from "./types.js";
|
|
5
5
|
export { BailSignal, config, Controller, createInterpolator, easings, FrameValue, Globals, inferTo, Interpolation, Spring, SpringContext, SpringRef, SpringValue, to, Trail, Transition, update, useChain, useSpring, useSpringRef, useSprings, useSpringValue, useTrail, useTransition, } from "@react-spring/core";
|
|
6
6
|
export type { AnimationConfig, AnimationProps, AnimationResult, AsyncResult, Change, ControllerFlushFn, ControllerProps, ControllerUpdate, EventProp, ForwardProps, GoalProp, GoalValue, GoalValues, InferTo, InlineToProps, Interpolated, Interpolator, ItemKeys, LoopProp, MatchProp, OnChange, OnPause, OnProps, OnResolve, OnRest, OnResume, OnStart, PickAnimated, ReservedEventProps, ReservedProps, SpringChain, SpringComponentProps, SpringConfig, SpringProps, SpringsUpdate, SpringTo, SpringToFn, SpringUpdate, SpringUpdateFn, SpringValues, Springify, ToProps, ToValues, TrailComponentProps, TransitionComponentProps, TransitionFn, TransitionFrom, TransitionKey, TransitionRenderFn, TransitionState, TransitionTo, TransitionValues, UseSpringProps, UseSpringsProps, UseTrailProps, UseTransitionProps, VelocityProp, } from "@react-spring/core";
|
|
7
7
|
export type { FluidValue } from "@react-spring/shared";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,YAAY,EACR,iBAAiB,EACjB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,YAAY,EACR,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,aAAa,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EACH,UAAU,EACV,MAAM,EACN,UAAU,EACV,kBAAkB,EAClB,OAAO,EACP,UAAU,EACV,OAAO,EACP,OAAO,EACP,aAAa,EACb,MAAM,EACN,aAAa,EACb,SAAS,EACT,WAAW,EACX,EAAE,EACF,KAAK,EACL,UAAU,EACV,MAAM,EACN,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,UAAU,EACV,cAAc,EACd,QAAQ,EACR,aAAa,GAChB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACR,eAAe,EACf,cAAc,EACd,eAAe,EACf,WAAW,EACX,MAAM,EACN,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,UAAU,EACV,OAAO,EACP,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,OAAO,EACP,OAAO,EACP,SAAS,EACT,MAAM,EACN,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,YAAY,EACZ,WAAW,EACX,aAAa,EACb,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,SAAS,EACT,OAAO,EACP,QAAQ,EACR,mBAAmB,EACnB,wBAAwB,EACxB,YAAY,EACZ,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,YAAY,GACf,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,EACR,UAAU,EACV,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,MAAM,EACN,SAAS,EACT,YAAY,GACf,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAiB,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAiB,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AASvD,OAAO,EACH,UAAU,EACV,MAAM,EACN,UAAU,EACV,kBAAkB,EAClB,OAAO,EACP,UAAU,EACV,OAAO,EACP,OAAO,EACP,aAAa,EACb,MAAM,EACN,aAAa,EACb,SAAS,EACT,WAAW,EACX,EAAE,EACF,KAAK,EACL,UAAU,EACV,MAAM,EACN,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,UAAU,EACV,cAAc,EACd,QAAQ,EACR,aAAa,GAChB,MAAM,oBAAoB,CAAC","sourcesContent":["import \"./bootstrap.js\";\n\nexport { animated, type Animated } from \"./animated.js\";\nexport { useReducedMotion } from \"./reduced-motion.js\";\nexport type {\n AnimatedComponent,\n AnimatedElementMap,\n AnimatedItems,\n AnimatedProp,\n AnimatedProps,\n AnimatedStyle,\n} from \"./types.js\";\nexport {\n BailSignal,\n config,\n Controller,\n createInterpolator,\n easings,\n FrameValue,\n Globals,\n inferTo,\n Interpolation,\n Spring,\n SpringContext,\n SpringRef,\n SpringValue,\n to,\n Trail,\n Transition,\n update,\n useChain,\n useSpring,\n useSpringRef,\n useSprings,\n useSpringValue,\n useTrail,\n useTransition,\n} from \"@react-spring/core\";\nexport type {\n AnimationConfig,\n AnimationProps,\n AnimationResult,\n AsyncResult,\n Change,\n ControllerFlushFn,\n ControllerProps,\n ControllerUpdate,\n EventProp,\n ForwardProps,\n GoalProp,\n GoalValue,\n GoalValues,\n InferTo,\n InlineToProps,\n Interpolated,\n Interpolator,\n ItemKeys,\n LoopProp,\n MatchProp,\n OnChange,\n OnPause,\n OnProps,\n OnResolve,\n OnRest,\n OnResume,\n OnStart,\n PickAnimated,\n ReservedEventProps,\n ReservedProps,\n SpringChain,\n SpringComponentProps,\n SpringConfig,\n SpringProps,\n SpringsUpdate,\n SpringTo,\n SpringToFn,\n SpringUpdate,\n SpringUpdateFn,\n SpringValues,\n Springify,\n ToProps,\n ToValues,\n TrailComponentProps,\n TransitionComponentProps,\n TransitionFn,\n TransitionFrom,\n TransitionKey,\n TransitionRenderFn,\n TransitionState,\n TransitionTo,\n TransitionValues,\n UseSpringProps,\n UseSpringsProps,\n UseTrailProps,\n UseTransitionProps,\n VelocityProp,\n} from \"@react-spring/core\";\nexport type { FluidValue } from \"@react-spring/shared\";\nexport type {\n Animatable,\n EasingFunction,\n ExtrapolateType,\n InterpolatorArgs,\n InterpolatorConfig,\n InterpolatorFactory,\n InterpolatorFn,\n Lookup,\n OneOrMore,\n UnknownProps,\n} from \"@react-spring/types\";\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
-
import type * as elements from "@gtkx/jsx";
|
|
3
1
|
import type { FluidValue } from "@react-spring/shared";
|
|
4
|
-
import type { ComponentPropsWithRef, ElementType, FunctionComponent,
|
|
2
|
+
import type { ComponentPropsWithRef, ElementType, FunctionComponent, JSX } from "react";
|
|
5
3
|
/** An array-valued prop whose items may each be a spring or an interpolation, such as mixed text children. */
|
|
6
4
|
type AnimatedItems<T> = [Exclude<Extract<T, Iterable<unknown>>, string>] extends [never] ? never : Exclude<Extract<T, Iterable<unknown>>, string> extends Iterable<infer Item> ? Iterable<AnimatedProp<Item>> : never;
|
|
7
5
|
/** A prop value that an animated component also accepts as a spring or an interpolation. */
|
|
@@ -24,21 +22,11 @@ type AnimatedProps<Props extends object> = {
|
|
|
24
22
|
/** A component returned by {@link animated}: the wrapped component with animated props. */
|
|
25
23
|
type AnimatedComponent<T extends Exclude<ElementType, string>> = FunctionComponent<AnimatedProps<ComponentPropsWithRef<T>>>;
|
|
26
24
|
/**
|
|
27
|
-
* The
|
|
28
|
-
*
|
|
29
|
-
* included, so `animated.GtkLabel` is available while non-widget elements such as `GtkAdjustment`
|
|
30
|
-
* are wrapped explicitly through the `animated(...)` call instead.
|
|
25
|
+
* The generated JSX intrinsic elements, keyed by element name, as components accepting animated props.
|
|
26
|
+
* Only elements whose `ref` exposes a `Gtk.Widget` subclass are included.
|
|
31
27
|
*/
|
|
32
28
|
type AnimatedElementMap = {
|
|
33
|
-
readonly [K in keyof
|
|
34
|
-
ref?: Ref<infer Instance> | undefined;
|
|
35
|
-
} ? [NonNullable<Instance>] extends [never] ? never : NonNullable<Instance> extends Gtk.Widget ? K : never : never : never]: (typeof elements)[K] extends Exclude<ElementType, string> ? AnimatedComponent<(typeof elements)[K]> : never;
|
|
29
|
+
readonly [K in keyof JSX.IntrinsicElements as "cssClasses" extends keyof JSX.IntrinsicElements[K] ? K : never]: JSX.IntrinsicElements[K] extends object ? FunctionComponent<AnimatedProps<JSX.IntrinsicElements[K]>> : never;
|
|
36
30
|
};
|
|
37
|
-
|
|
38
|
-
* The widget components of the generated `@gtkx/jsx` store, exposed as properties of `animated`.
|
|
39
|
-
*
|
|
40
|
-
* @deprecated Since 1.6. Use `AnimatedElementMap` instead. Removed in v2.
|
|
41
|
-
*/
|
|
42
|
-
type AnimatedElements = AnimatedElementMap;
|
|
43
|
-
export type { AnimatedComponent, AnimatedElementMap, AnimatedElements, AnimatedItems, AnimatedProp, AnimatedProps, AnimatedStyle, };
|
|
31
|
+
export type { AnimatedComponent, AnimatedElementMap, AnimatedItems, AnimatedProp, AnimatedProps, AnimatedStyle, };
|
|
44
32
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d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KAAK,CAAC,CAAC,CAAC,GACR,CAAC,SAAS,OAAO,GACb,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAC7D,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;CACnC,CAAC;AAEF,2FAA2F;AAC3F,KAAK,iBAAiB,CAAC,CAAC,SAAS,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,iBAAiB,CAC9E,aAAa,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAC1C,CAAC;AAEF;;;GAGG;AACH,KAAK,kBAAkB,GAAG;IACtB,QAAQ,EAAE,CAAC,IAAI,MAAM,GAAG,CAAC,iBAAiB,IAAI,YAAY,SAAS,MAAM,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAC3F,CAAC,GACD,KAAK,GAAG,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,SAAS,MAAM,GAC/C,iBAAiB,CAAC,aAAa,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,GAC1D,KAAK;CACd,CAAC;AAEF,YAAY,EACR,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,aAAa,GAChB,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { FluidValue } from \"@react-spring/shared\";\nimport type { ComponentPropsWithRef, ElementType, FunctionComponent, JSX } from \"react\";\n\n/** An array-valued prop whose items may each be a spring or an interpolation, such as mixed text children. */\ntype AnimatedItems<T> = [Exclude<Extract<T, Iterable<unknown>>, string>] extends [never]\n ? never\n : Exclude<Extract<T, Iterable<unknown>>, string> extends Iterable<infer Item>\n ? Iterable<AnimatedProp<Item>>\n : never;\n\n/** A prop value that an animated component also accepts as a spring or an interpolation. */\ntype AnimatedProp<T> = T | FluidValue<Exclude<T, undefined>> | AnimatedItems<Exclude<T, undefined>>;\n\n/**\n * A `style` object whose declarations may each be a spring or an interpolation, nested blocks\n * included, so the object a spring hook returns can be handed to `style` as it is.\n */\ntype AnimatedStyle<T> = {\n [K in keyof T]: T[K] extends string | number | undefined | null\n ? AnimatedProp<T[K]>\n : AnimatedProp<T[K]> | AnimatedStyle<NonNullable<T[K]>>;\n};\n\n/**\n * The props of an animated component: every prop of the wrapped component, each also accepting a\n * {@link FluidValue} such as a `SpringValue` or an `Interpolation`, while `ref` and `key` keep\n * their original types.\n */\ntype AnimatedProps<Props extends object> = {\n [P in keyof Props]: P extends \"key\" | \"ref\"\n ? Props[P]\n : P extends \"style\"\n ? AnimatedProp<Props[P]> | AnimatedStyle<NonNullable<Props[P]>>\n : AnimatedProp<Props[P]>;\n};\n\n/** A component returned by {@link animated}: the wrapped component with animated props. */\ntype AnimatedComponent<T extends Exclude<ElementType, string>> = FunctionComponent<\n AnimatedProps<ComponentPropsWithRef<T>>\n>;\n\n/**\n * The generated JSX intrinsic elements, keyed by element name, as components accepting animated props.\n * Only elements whose `ref` exposes a `Gtk.Widget` subclass are included.\n */\ntype AnimatedElementMap = {\n readonly [K in keyof JSX.IntrinsicElements as \"cssClasses\" extends keyof JSX.IntrinsicElements[K]\n ? K\n : never]: JSX.IntrinsicElements[K] extends object\n ? FunctionComponent<AnimatedProps<JSX.IntrinsicElements[K]>>\n : never;\n};\n\nexport type {\n AnimatedComponent,\n AnimatedElementMap,\n AnimatedItems,\n AnimatedProp,\n AnimatedProps,\n AnimatedStyle,\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-animated.d.ts","sourceRoot":"","sources":["../src/with-animated.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,WAAW,EAAqE,MAAM,OAAO,CAAC;AAC5G,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAKpD,KAAK,SAAS,GAAG,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"with-animated.d.ts","sourceRoot":"","sources":["../src/with-animated.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,WAAW,EAAqE,MAAM,OAAO,CAAC;AAC5G,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAKpD,KAAK,SAAS,GAAG,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;AAsM9C,iBAAS,YAAY,CAAC,CAAC,SAAS,SAAS,EAAE,SAAS,EAAE,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAS7E;AAmBD,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
package/dist/with-animated.js
CHANGED
|
@@ -97,16 +97,10 @@ const unobserve = (observer) => {
|
|
|
97
97
|
raf.cancel(observer.update);
|
|
98
98
|
};
|
|
99
99
|
const useObserver = (observer) => {
|
|
100
|
-
const observerRef = useRef(null);
|
|
101
100
|
useLayoutEffect(() => {
|
|
102
|
-
observerRef.current = observer;
|
|
103
101
|
observe(observer);
|
|
104
102
|
return () => {
|
|
105
|
-
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
unobserve(observerRef.current);
|
|
109
|
-
observerRef.current = null;
|
|
103
|
+
unobserve(observer);
|
|
110
104
|
};
|
|
111
105
|
});
|
|
112
106
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-animated.js","sourceRoot":"","sources":["../src/with-animated.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EACH,gBAAgB,EAGhB,aAAa,EACb,aAAa,EACb,GAAG,EACH,mBAAmB,EACnB,cAAc,GACjB,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AY,CAAsB,SAAY;IACnD,IAAI,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAElC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,GAAG,uBAAuB,CAAC,SAAS,CAAC,CAAC;QAC5C,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,MAA8B,CAAC;AAC1C,CAAC;AAED,MAAM,aAAa;IACN,MAAM,CAAa;IAEnB,YAAY,CAAkB;IAEvC,YAAY,MAAkB,EAAE,YAA6B;QACzD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;IAED,aAAa,CAAC,KAAiB;QAC3B,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC1B,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC;IACL,CAAC;CACJ;AAED,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import type { Lookup } from \"@react-spring/types\";\nimport { useMergedRef } from \"@gtkx/react/internal\";\nimport {\n addFluidObserver,\n type FluidEvent,\n type FluidValue,\n getFluidValue,\n hasFluidValue,\n raf,\n removeFluidObserver,\n useForceUpdate,\n} from \"@react-spring/shared\";\nimport { type ElementType, type ReactNode, type Ref, type RefObject, useLayoutEffect, useRef } from \"react\";\nimport type { AnimatedComponent } from \"./types.js\";\nimport { didApplyAnimatedValues } from \"./apply-animated-values.js\";\nimport { trackReducedMotion } from \"./reduced-motion.js\";\n\ntype AnimatedInput = { ref?: Ref<object> | undefined; [key: string]: unknown };\ntype Wrappable = Exclude<ElementType, string>;\ntype ObserverRef = { current: PropsObserver | null };\n\nconst STYLE_PROP = \"style\";\nconst cache: WeakMap<object, AnimatedComponent<Wrappable>> = new WeakMap();\n\nconst getDisplayName = (component: Wrappable): string => {\n const { displayName, name } = component as { displayName?: unknown; name?: unknown };\n\n if (typeof displayName === \"string\" && displayName !== \"\") {\n return displayName;\n }\n\n return typeof name === \"string\" && name !== \"\" ? name : \"Anonymous\";\n};\n\nconst isFluidProp = (value: unknown): boolean => hasFluidValue(value) || isFluidArray(value);\n\nconst isBlock = (value: unknown): value is Lookup =>\n typeof value === \"object\" && value !== null && Object.getPrototypeOf(value) === Object.prototype;\n\nfunction isFluidArray(value: unknown): value is unknown[] {\n return Array.isArray(value) && value.some((item) => isFluidProp(item));\n}\n\nfunction isFluidStyle(value: unknown): value is Lookup {\n return isBlock(value) && Object.values(value).some((item) => hasFluidValue(item) || isFluidStyle(item));\n}\n\nfunction resolveStyle(style: Lookup): Lookup {\n const resolved: Lookup = {};\n\n for (const name in style) {\n const value: unknown = style[name];\n const next: unknown = isFluidStyle(value) ? resolveStyle(value) : getFluidValue(value);\n resolved[name] = next;\n }\n\n return resolved;\n}\n\nfunction resolveValue(value: unknown): unknown {\n return isFluidArray(value) ? value.map((item) => resolveValue(item)) : getFluidValue(value);\n}\n\nconst isFluidNamed = (name: string, value: unknown): boolean =>\n isFluidProp(value) || (name === STYLE_PROP && isFluidStyle(value));\n\nconst resolveNamed = (name: string, value: unknown): unknown =>\n name === STYLE_PROP && isFluidStyle(value) ? resolveStyle(value) : resolveValue(value);\n\nconst resolveProps = (props: Lookup, isAnimatedOnly: boolean): Lookup => {\n const resolved: Lookup = {};\n\n for (const name in props) {\n const value: unknown = props[name];\n\n if (isFluidNamed(name, value)) {\n resolved[name] = resolveNamed(name, value);\n } else if (!isAnimatedOnly) {\n resolved[name] = value;\n }\n }\n\n return resolved;\n};\n\nfunction collectEach(items: unknown[], dependencies: Set<FluidValue>): void {\n for (const item of items) {\n collectDependencies(item, dependencies);\n }\n}\n\nfunction collectDependencies(value: unknown, dependencies: Set<FluidValue>): void {\n if (hasFluidValue(value)) {\n dependencies.add(value);\n } else if (isFluidArray(value)) {\n collectEach(value, dependencies);\n } else if (isFluidStyle(value)) {\n collectEach(Object.values(value), dependencies);\n }\n}\n\nconst collectNamed = (name: string, value: unknown, dependencies: Set<FluidValue>): void => {\n if (isFluidNamed(name, value)) {\n collectDependencies(value, dependencies);\n }\n};\n\nconst getDependencies = (props: Lookup): Set<FluidValue> => {\n const dependencies: Set<FluidValue> = new Set();\n\n for (const name in props) {\n collectNamed(name, props[name], dependencies);\n }\n\n return dependencies;\n};\n\nconst getFluidNames = (props: Lookup): Set<string> => {\n const names: Set<string> = new Set();\n\n for (const name in props) {\n if (isFluidNamed(name, props[name])) {\n names.add(name);\n }\n }\n\n return names;\n};\n\nconst observe = (observer: PropsObserver): void => {\n for (const dependency of observer.dependencies) {\n addFluidObserver(dependency, observer);\n }\n};\n\nconst unobserve = (observer: PropsObserver): void => {\n for (const dependency of observer.dependencies) {\n removeFluidObserver(dependency, observer);\n }\n\n raf.cancel(observer.update);\n};\n\nconst useObserver = (observer: PropsObserver): void => {\n const observerRef: ObserverRef = useRef<PropsObserver | null>(null);\n\n useLayoutEffect(() => {\n observerRef.current = observer;\n observe(observer);\n\n return () => {\n if (observerRef.current === null) {\n return;\n }\n\n unobserve(observerRef.current);\n observerRef.current = null;\n };\n });\n};\n\nconst collectStaticReplacements = (\n props: Lookup,\n previous: Set<string>,\n current: Set<string>,\n values: Lookup,\n): void => {\n for (const name of previous) {\n const value: unknown = props[name];\n\n if (value !== undefined && !current.has(name)) {\n values[name] = value;\n }\n }\n};\n\nconst useCommitSync = (instanceRef: RefObject<object | null>, props: Lookup): void => {\n const fluidNamesRef = useRef<Set<string>>(new Set());\n\n useLayoutEffect(() => {\n const previous = fluidNamesRef.current;\n const current = getFluidNames(props);\n fluidNamesRef.current = current;\n trackReducedMotion();\n const instance = instanceRef.current;\n\n if (instance === null) {\n return;\n }\n\n const values = resolveProps(props, true);\n collectStaticReplacements(props, previous, current, values);\n didApplyAnimatedValues(instance, values);\n });\n};\n\nconst useAnimatedUpdate = (instanceRef: RefObject<object | null>, props: Lookup): (() => void) => {\n const forceUpdate = useForceUpdate();\n\n return () => {\n const instance = instanceRef.current;\n const isApplied = instance !== null && didApplyAnimatedValues(instance, resolveProps(props, true));\n\n if (!isApplied) {\n forceUpdate();\n }\n };\n};\n\nconst createAnimatedComponent = (Component: Wrappable): AnimatedComponent<Wrappable> => {\n const Animated = ({ ref: givenRef, ...props }: AnimatedInput): ReactNode => {\n const instanceRef = useRef<object | null>(null);\n const ref = useMergedRef(givenRef, instanceRef);\n const update = useAnimatedUpdate(instanceRef, props);\n useObserver(new PropsObserver(update, getDependencies(props)));\n useCommitSync(instanceRef, props);\n\n return <Component {...resolveProps(props, false)} ref={ref} />;\n };\n\n Animated.displayName = `Animated(${getDisplayName(Component)})`;\n\n return Animated as AnimatedComponent<Wrappable>;\n};\n\nfunction withAnimated<T extends Wrappable>(component: T): AnimatedComponent<T> {\n let cached = cache.get(component);\n\n if (cached === undefined) {\n cached = createAnimatedComponent(component);\n cache.set(component, cached);\n }\n\n return cached as AnimatedComponent<T>;\n}\n\nclass PropsObserver {\n readonly update: () => void;\n\n readonly dependencies: Set<FluidValue>;\n\n constructor(update: () => void, dependencies: Set<FluidValue>) {\n this.update = update;\n this.dependencies = dependencies;\n }\n\n eventObserved(event: FluidEvent): void {\n if (event.type === \"change\") {\n raf.write(this.update);\n }\n }\n}\n\nexport { withAnimated };\n"]}
|
|
1
|
+
{"version":3,"file":"with-animated.js","sourceRoot":"","sources":["../src/with-animated.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EACH,gBAAgB,EAGhB,aAAa,EACb,aAAa,EACb,GAAG,EACH,mBAAmB,EACnB,cAAc,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAA8D,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE5G,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;A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,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;IAED,aAAa,CAAC,KAAiB;QAC3B,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC1B,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC;IACL,CAAC;CACJ;AAED,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import type { Lookup } from \"@react-spring/types\";\nimport { useMergedRef } from \"@gtkx/react/internal\";\nimport {\n addFluidObserver,\n type FluidEvent,\n type FluidValue,\n getFluidValue,\n hasFluidValue,\n raf,\n removeFluidObserver,\n useForceUpdate,\n} from \"@react-spring/shared\";\nimport { type ElementType, type ReactNode, type Ref, type RefObject, useLayoutEffect, useRef } from \"react\";\nimport type { AnimatedComponent } from \"./types.js\";\nimport { didApplyAnimatedValues } from \"./apply-animated-values.js\";\nimport { trackReducedMotion } from \"./reduced-motion.js\";\n\ntype AnimatedInput = { ref?: Ref<object> | undefined; [key: string]: unknown };\ntype Wrappable = Exclude<ElementType, string>;\n\nconst STYLE_PROP = \"style\";\nconst cache: WeakMap<object, AnimatedComponent<Wrappable>> = new WeakMap();\n\nconst getDisplayName = (component: Wrappable): string => {\n const { displayName, name } = component as { displayName?: unknown; name?: unknown };\n\n if (typeof displayName === \"string\" && displayName !== \"\") {\n return displayName;\n }\n\n return typeof name === \"string\" && name !== \"\" ? name : \"Anonymous\";\n};\n\nconst isFluidProp = (value: unknown): boolean => hasFluidValue(value) || isFluidArray(value);\n\nconst isBlock = (value: unknown): value is Lookup =>\n typeof value === \"object\" && value !== null && Object.getPrototypeOf(value) === Object.prototype;\n\nfunction isFluidArray(value: unknown): value is unknown[] {\n return Array.isArray(value) && value.some((item) => isFluidProp(item));\n}\n\nfunction isFluidStyle(value: unknown): value is Lookup {\n return isBlock(value) && Object.values(value).some((item) => hasFluidValue(item) || isFluidStyle(item));\n}\n\nfunction resolveStyle(style: Lookup): Lookup {\n const resolved: Lookup = {};\n\n for (const name in style) {\n const value: unknown = style[name];\n const next: unknown = isFluidStyle(value) ? resolveStyle(value) : getFluidValue(value);\n resolved[name] = next;\n }\n\n return resolved;\n}\n\nfunction resolveValue(value: unknown): unknown {\n return isFluidArray(value) ? value.map((item) => resolveValue(item)) : getFluidValue(value);\n}\n\nconst isFluidNamed = (name: string, value: unknown): boolean =>\n isFluidProp(value) || (name === STYLE_PROP && isFluidStyle(value));\n\nconst resolveNamed = (name: string, value: unknown): unknown =>\n name === STYLE_PROP && isFluidStyle(value) ? resolveStyle(value) : resolveValue(value);\n\nconst resolveProps = (props: Lookup, isAnimatedOnly: boolean): Lookup => {\n const resolved: Lookup = {};\n\n for (const name in props) {\n const value: unknown = props[name];\n\n if (isFluidNamed(name, value)) {\n resolved[name] = resolveNamed(name, value);\n } else if (!isAnimatedOnly) {\n resolved[name] = value;\n }\n }\n\n return resolved;\n};\n\nfunction collectEach(items: unknown[], dependencies: Set<FluidValue>): void {\n for (const item of items) {\n collectDependencies(item, dependencies);\n }\n}\n\nfunction collectDependencies(value: unknown, dependencies: Set<FluidValue>): void {\n if (hasFluidValue(value)) {\n dependencies.add(value);\n } else if (isFluidArray(value)) {\n collectEach(value, dependencies);\n } else if (isFluidStyle(value)) {\n collectEach(Object.values(value), dependencies);\n }\n}\n\nconst collectNamed = (name: string, value: unknown, dependencies: Set<FluidValue>): void => {\n if (isFluidNamed(name, value)) {\n collectDependencies(value, dependencies);\n }\n};\n\nconst getDependencies = (props: Lookup): Set<FluidValue> => {\n const dependencies: Set<FluidValue> = new Set();\n\n for (const name in props) {\n collectNamed(name, props[name], dependencies);\n }\n\n return dependencies;\n};\n\nconst getFluidNames = (props: Lookup): Set<string> => {\n const names: Set<string> = new Set();\n\n for (const name in props) {\n if (isFluidNamed(name, props[name])) {\n names.add(name);\n }\n }\n\n return names;\n};\n\nconst observe = (observer: PropsObserver): void => {\n for (const dependency of observer.dependencies) {\n addFluidObserver(dependency, observer);\n }\n};\n\nconst unobserve = (observer: PropsObserver): void => {\n for (const dependency of observer.dependencies) {\n removeFluidObserver(dependency, observer);\n }\n\n raf.cancel(observer.update);\n};\n\nconst useObserver = (observer: PropsObserver): void => {\n useLayoutEffect(() => {\n observe(observer);\n\n return () => {\n unobserve(observer);\n };\n });\n};\n\nconst collectStaticReplacements = (\n props: Lookup,\n previous: Set<string>,\n current: Set<string>,\n values: Lookup,\n): void => {\n for (const name of previous) {\n const value: unknown = props[name];\n\n if (value !== undefined && !current.has(name)) {\n values[name] = value;\n }\n }\n};\n\nconst useCommitSync = (instanceRef: RefObject<object | null>, props: Lookup): void => {\n const fluidNamesRef = useRef<Set<string>>(new Set());\n\n useLayoutEffect(() => {\n const previous = fluidNamesRef.current;\n const current = getFluidNames(props);\n fluidNamesRef.current = current;\n trackReducedMotion();\n const instance = instanceRef.current;\n\n if (instance === null) {\n return;\n }\n\n const values = resolveProps(props, true);\n collectStaticReplacements(props, previous, current, values);\n didApplyAnimatedValues(instance, values);\n });\n};\n\nconst useAnimatedUpdate = (instanceRef: RefObject<object | null>, props: Lookup): (() => void) => {\n const forceUpdate = useForceUpdate();\n\n return () => {\n const instance = instanceRef.current;\n const isApplied = instance !== null && didApplyAnimatedValues(instance, resolveProps(props, true));\n\n if (!isApplied) {\n forceUpdate();\n }\n };\n};\n\nconst createAnimatedComponent = (Component: Wrappable): AnimatedComponent<Wrappable> => {\n const Animated = ({ ref: givenRef, ...props }: AnimatedInput): ReactNode => {\n const instanceRef = useRef<object | null>(null);\n const ref = useMergedRef(givenRef, instanceRef);\n const update = useAnimatedUpdate(instanceRef, props);\n useObserver(new PropsObserver(update, getDependencies(props)));\n useCommitSync(instanceRef, props);\n\n return <Component {...resolveProps(props, false)} ref={ref} />;\n };\n\n Animated.displayName = `Animated(${getDisplayName(Component)})`;\n\n return Animated as AnimatedComponent<Wrappable>;\n};\n\nfunction withAnimated<T extends Wrappable>(component: T): AnimatedComponent<T> {\n let cached = cache.get(component);\n\n if (cached === undefined) {\n cached = createAnimatedComponent(component);\n cache.set(component, cached);\n }\n\n return cached as AnimatedComponent<T>;\n}\n\nclass PropsObserver {\n readonly update: () => void;\n\n readonly dependencies: Set<FluidValue>;\n\n constructor(update: () => void, dependencies: Set<FluidValue>) {\n this.update = update;\n this.dependencies = dependencies;\n }\n\n eventObserved(event: FluidEvent): void {\n if (event.type === \"change\") {\n raf.write(this.update);\n }\n }\n}\n\nexport { withAnimated };\n"]}
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/animated",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Spring animations for GTK widgets
|
|
3
|
+
"version": "2.0.0-beta.10",
|
|
4
|
+
"description": "Spring animations for Adwaita and GTK widgets on the GTK4 frame clock.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gtkx",
|
|
7
7
|
"gtk",
|
|
8
8
|
"gtk4",
|
|
9
|
+
"adwaita",
|
|
10
|
+
"gnome",
|
|
9
11
|
"react",
|
|
10
12
|
"react-spring",
|
|
11
13
|
"animation",
|
|
@@ -29,18 +31,14 @@
|
|
|
29
31
|
"./package.json": "./package.json",
|
|
30
32
|
".": {
|
|
31
33
|
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"require": null,
|
|
32
36
|
"default": "./dist/index.js"
|
|
33
|
-
},
|
|
34
|
-
"./internal": {
|
|
35
|
-
"types": "./dist/internal.d.ts",
|
|
36
|
-
"default": "./dist/internal.js"
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"sideEffects": [
|
|
40
40
|
"./src/index.ts",
|
|
41
41
|
"./dist/index.js",
|
|
42
|
-
"./src/internal.ts",
|
|
43
|
-
"./dist/internal.js",
|
|
44
42
|
"./src/bootstrap.ts",
|
|
45
43
|
"./dist/bootstrap.js"
|
|
46
44
|
],
|
|
@@ -59,23 +57,23 @@
|
|
|
59
57
|
}
|
|
60
58
|
},
|
|
61
59
|
"engines": {
|
|
62
|
-
"node": ">=
|
|
60
|
+
"node": ">=26.7.0"
|
|
63
61
|
},
|
|
64
62
|
"dependencies": {
|
|
63
|
+
"@gtkx/react": "2.0.0-beta.10",
|
|
64
|
+
"@gtkx/runtime": "2.0.0-beta.10",
|
|
65
65
|
"@react-spring/core": "^10.1.2",
|
|
66
66
|
"@react-spring/shared": "^10.1.2",
|
|
67
|
-
"@react-spring/types": "^10.1.2"
|
|
68
|
-
"@gtkx/react": "1.6.0",
|
|
69
|
-
"@gtkx/runtime": "1.6.0"
|
|
67
|
+
"@react-spring/types": "^10.1.2"
|
|
70
68
|
},
|
|
71
69
|
"peerDependencies": {
|
|
72
70
|
"react": "^19.2"
|
|
73
71
|
},
|
|
74
72
|
"devDependencies": {
|
|
75
|
-
"
|
|
76
|
-
"@gtkx/
|
|
77
|
-
"@gtkx/vitest": "
|
|
78
|
-
"
|
|
73
|
+
"@gtkx/config": "2.0.0-beta.10",
|
|
74
|
+
"@gtkx/testing": "2.0.0-beta.10",
|
|
75
|
+
"@gtkx/vitest": "2.0.0-beta.10",
|
|
76
|
+
"vitest": "^5.0.0"
|
|
79
77
|
},
|
|
80
78
|
"scripts": {
|
|
81
79
|
"release": "tsx ../../scripts/release-package.ts"
|
package/src/animated.ts
CHANGED
|
@@ -1,64 +1,16 @@
|
|
|
1
1
|
import type { ElementType } from "react";
|
|
2
|
-
import
|
|
3
|
-
import type { AnimatedComponent, AnimatedElementMap } from "./types.js";
|
|
2
|
+
import type { AnimatedComponent } from "./types.js";
|
|
4
3
|
import { withAnimated } from "./with-animated.js";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* The `animated` entrypoint: callable to wrap any component, and exposing every generated widget
|
|
9
|
-
* component as a property, so `animated.GtkLabel` is the animated form of `GtkLabel`.
|
|
10
|
-
*/
|
|
11
|
-
type Animated = (<T extends Exclude<ElementType, string>>(component: T) => AnimatedComponent<T>) & AnimatedElementMap;
|
|
5
|
+
/** Callable entrypoint that wraps a component with animated props. */
|
|
6
|
+
type Animated = <T extends Exclude<ElementType, string>>(component: T) => AnimatedComponent<T>;
|
|
12
7
|
|
|
13
8
|
/**
|
|
14
9
|
* Wraps a component so that its props accept springs and interpolations: `animated(GtkLabel)` is
|
|
15
10
|
* `GtkLabel` with every prop also taking a `SpringValue` or an `Interpolation`. Animated values are
|
|
16
11
|
* written to the widget on each frame without a React render. The wrapper of a given component is
|
|
17
|
-
* created once and reused
|
|
18
|
-
*
|
|
19
|
-
* Every widget component of the generated `@gtkx/jsx` store is also available as a property:
|
|
20
|
-
* `animated.GtkLabel` is `animated(GtkLabel)` without the import. **Deprecated: property access is
|
|
21
|
-
* removed in GTKX 2.0**, where `animated` is only callable; import the component and call
|
|
22
|
-
* `animated(GtkLabel)` instead, which also lets a production bundle drop the widgets an
|
|
23
|
-
* application never animates.
|
|
12
|
+
* created once and reused.
|
|
24
13
|
*/
|
|
25
|
-
const animated: Animated =
|
|
26
|
-
get(target, property, receiver): unknown {
|
|
27
|
-
const component = componentFor(property);
|
|
28
|
-
|
|
29
|
-
return component === null ? Reflect.get(target, property, receiver) : withAnimated(component);
|
|
30
|
-
},
|
|
31
|
-
getOwnPropertyDescriptor(target, property): PropertyDescriptor | undefined {
|
|
32
|
-
const component = componentFor(property);
|
|
33
|
-
|
|
34
|
-
if (component === null) {
|
|
35
|
-
return Reflect.getOwnPropertyDescriptor(target, property);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return { configurable: true, enumerable: true, writable: false, value: withAnimated(component) };
|
|
39
|
-
},
|
|
40
|
-
has(target, property): boolean {
|
|
41
|
-
return componentFor(property) !== null || Reflect.has(target, property);
|
|
42
|
-
},
|
|
43
|
-
ownKeys(target): (string | symbol)[] {
|
|
44
|
-
const names = Object.keys(elements).filter((name) => componentFor(name) !== null);
|
|
45
|
-
|
|
46
|
-
return [...new Set([...Reflect.ownKeys(target), ...names])];
|
|
47
|
-
},
|
|
48
|
-
}) as Animated;
|
|
49
|
-
|
|
50
|
-
function componentFor(property: string | symbol): Wrappable | null {
|
|
51
|
-
const value: unknown = Reflect.get(elements, property);
|
|
52
|
-
|
|
53
|
-
return isComponent(value) ? value : null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function isComponent(value: unknown): value is Wrappable {
|
|
57
|
-
return typeof value === "function";
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function wrapComponent<T extends Wrappable>(component: T): AnimatedComponent<T> {
|
|
61
|
-
return withAnimated(component);
|
|
62
|
-
}
|
|
14
|
+
const animated: Animated = withAnimated;
|
|
63
15
|
|
|
64
16
|
export { animated, type Animated };
|
|
@@ -25,13 +25,8 @@ const hasSetter = (instance: object, name: string): boolean => {
|
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (known === undefined) {
|
|
31
|
-
known = new Map();
|
|
32
|
-
setterCache.set(prototype, known);
|
|
33
|
-
}
|
|
34
|
-
|
|
28
|
+
const known = setterCache.get(prototype) ?? new Map<string, boolean>();
|
|
29
|
+
setterCache.set(prototype, known);
|
|
35
30
|
let isWritable = known.get(name);
|
|
36
31
|
|
|
37
32
|
if (isWritable === undefined) {
|
package/src/index.ts
CHANGED
|
@@ -5,8 +5,6 @@ export { useReducedMotion } from "./reduced-motion.js";
|
|
|
5
5
|
export type {
|
|
6
6
|
AnimatedComponent,
|
|
7
7
|
AnimatedElementMap,
|
|
8
|
-
/* eslint-disable-next-line @typescript-eslint/no-deprecated -- exported until 2.0 removes it */
|
|
9
|
-
AnimatedElements,
|
|
10
8
|
AnimatedItems,
|
|
11
9
|
AnimatedProp,
|
|
12
10
|
AnimatedProps,
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
-
import type * as elements from "@gtkx/jsx";
|
|
3
1
|
import type { FluidValue } from "@react-spring/shared";
|
|
4
|
-
import type { ComponentPropsWithRef, ElementType, FunctionComponent,
|
|
2
|
+
import type { ComponentPropsWithRef, ElementType, FunctionComponent, JSX } from "react";
|
|
5
3
|
|
|
6
4
|
/** An array-valued prop whose items may each be a spring or an interpolation, such as mixed text children. */
|
|
7
5
|
type AnimatedItems<T> = [Exclude<Extract<T, Iterable<unknown>>, string>] extends [never]
|
|
@@ -42,38 +40,20 @@ type AnimatedComponent<T extends Exclude<ElementType, string>> = FunctionCompone
|
|
|
42
40
|
>;
|
|
43
41
|
|
|
44
42
|
/**
|
|
45
|
-
* The
|
|
46
|
-
*
|
|
47
|
-
* included, so `animated.GtkLabel` is available while non-widget elements such as `GtkAdjustment`
|
|
48
|
-
* are wrapped explicitly through the `animated(...)` call instead.
|
|
43
|
+
* The generated JSX intrinsic elements, keyed by element name, as components accepting animated props.
|
|
44
|
+
* Only elements whose `ref` exposes a `Gtk.Widget` subclass are included.
|
|
49
45
|
*/
|
|
50
46
|
type AnimatedElementMap = {
|
|
51
|
-
readonly [K in keyof
|
|
52
|
-
?
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
: NonNullable<Instance> extends Gtk.Widget
|
|
56
|
-
? K
|
|
57
|
-
: never
|
|
58
|
-
: never
|
|
59
|
-
: never]: (typeof elements)[K] extends Exclude<ElementType, string>
|
|
60
|
-
? AnimatedComponent<(typeof elements)[K]>
|
|
47
|
+
readonly [K in keyof JSX.IntrinsicElements as "cssClasses" extends keyof JSX.IntrinsicElements[K]
|
|
48
|
+
? K
|
|
49
|
+
: never]: JSX.IntrinsicElements[K] extends object
|
|
50
|
+
? FunctionComponent<AnimatedProps<JSX.IntrinsicElements[K]>>
|
|
61
51
|
: never;
|
|
62
52
|
};
|
|
63
53
|
|
|
64
|
-
/**
|
|
65
|
-
* The widget components of the generated `@gtkx/jsx` store, exposed as properties of `animated`.
|
|
66
|
-
*
|
|
67
|
-
* @deprecated Since 1.6. Use `AnimatedElementMap` instead. Removed in v2.
|
|
68
|
-
*/
|
|
69
|
-
/* eslint-disable-next-line sonarjs/redundant-type-aliases -- deprecated alias kept until 2.0 removes it */
|
|
70
|
-
type AnimatedElements = AnimatedElementMap;
|
|
71
|
-
|
|
72
54
|
export type {
|
|
73
55
|
AnimatedComponent,
|
|
74
56
|
AnimatedElementMap,
|
|
75
|
-
/* eslint-disable-next-line @typescript-eslint/no-deprecated -- exported until 2.0 removes it */
|
|
76
|
-
AnimatedElements,
|
|
77
57
|
AnimatedItems,
|
|
78
58
|
AnimatedProp,
|
|
79
59
|
AnimatedProps,
|
package/src/with-animated.tsx
CHANGED
|
@@ -17,7 +17,6 @@ import { trackReducedMotion } from "./reduced-motion.js";
|
|
|
17
17
|
|
|
18
18
|
type AnimatedInput = { ref?: Ref<object> | undefined; [key: string]: unknown };
|
|
19
19
|
type Wrappable = Exclude<ElementType, string>;
|
|
20
|
-
type ObserverRef = { current: PropsObserver | null };
|
|
21
20
|
|
|
22
21
|
const STYLE_PROP = "style";
|
|
23
22
|
const cache: WeakMap<object, AnimatedComponent<Wrappable>> = new WeakMap();
|
|
@@ -142,19 +141,11 @@ const unobserve = (observer: PropsObserver): void => {
|
|
|
142
141
|
};
|
|
143
142
|
|
|
144
143
|
const useObserver = (observer: PropsObserver): void => {
|
|
145
|
-
const observerRef: ObserverRef = useRef<PropsObserver | null>(null);
|
|
146
|
-
|
|
147
144
|
useLayoutEffect(() => {
|
|
148
|
-
observerRef.current = observer;
|
|
149
145
|
observe(observer);
|
|
150
146
|
|
|
151
147
|
return () => {
|
|
152
|
-
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
unobserve(observerRef.current);
|
|
157
|
-
observerRef.current = null;
|
|
148
|
+
unobserve(observer);
|
|
158
149
|
};
|
|
159
150
|
});
|
|
160
151
|
};
|
package/dist/internal.d.ts
DELETED
package/dist/internal.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/internal.js
DELETED
package/dist/internal.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["import \"./bootstrap.js\";\n\nexport { withAnimated } from \"./with-animated.js\";\n"]}
|
package/src/internal.ts
DELETED