@gtkx/animated 2.0.0-beta.12 → 2.0.0-beta.13
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/dist/bootstrap.d.ts +1 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +1 -0
- package/dist/bootstrap.js.map +1 -1
- package/dist/loop-guard.d.ts +2 -0
- package/dist/loop-guard.d.ts.map +1 -0
- package/dist/loop-guard.js +45 -0
- package/dist/loop-guard.js.map +1 -0
- package/dist/reduced-motion.d.ts +2 -1
- package/dist/reduced-motion.d.ts.map +1 -1
- package/dist/reduced-motion.js +9 -4
- package/dist/reduced-motion.js.map +1 -1
- package/package.json +10 -8
- package/src/bootstrap.ts +1 -0
- package/src/loop-guard.ts +71 -0
- package/src/reduced-motion.ts +11 -5
package/dist/bootstrap.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import "./loop-guard.js";
|
|
2
2
|
//# sourceMappingURL=bootstrap.d.ts.map
|
package/dist/bootstrap.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAGA,OAAO,iBAAiB,CAAC"}
|
package/dist/bootstrap.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Globals } from "@react-spring/core";
|
|
2
2
|
import { colors, createStringInterpolator } from "@react-spring/shared";
|
|
3
3
|
import { trackReducedMotion } from "./reduced-motion.js";
|
|
4
|
+
import "./loop-guard.js";
|
|
4
5
|
import { requestFrame } from "./request-frame.js";
|
|
5
6
|
Globals.assign({
|
|
6
7
|
colors,
|
package/dist/bootstrap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,CAAC,MAAM,CAAC;IACX,MAAM;IACN,wBAAwB;IACxB,qBAAqB,EAAE,YAAY;CACtC,CAAC,CAAC;AAEH,kBAAkB,EAAE,CAAC","sourcesContent":["import { Globals } from \"@react-spring/core\";\nimport { colors, createStringInterpolator } from \"@react-spring/shared\";\nimport { trackReducedMotion } from \"./reduced-motion.js\";\nimport { requestFrame } from \"./request-frame.js\";\n\nGlobals.assign({\n colors,\n createStringInterpolator,\n requestAnimationFrame: requestFrame,\n});\n\ntrackReducedMotion();\n"]}
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,CAAC,MAAM,CAAC;IACX,MAAM;IACN,wBAAwB;IACxB,qBAAqB,EAAE,YAAY;CACtC,CAAC,CAAC;AAEH,kBAAkB,EAAE,CAAC","sourcesContent":["import { Globals } from \"@react-spring/core\";\nimport { colors, createStringInterpolator } from \"@react-spring/shared\";\nimport { trackReducedMotion } from \"./reduced-motion.js\";\nimport \"./loop-guard.js\";\nimport { requestFrame } from \"./request-frame.js\";\n\nGlobals.assign({\n colors,\n createStringInterpolator,\n requestAnimationFrame: requestFrame,\n});\n\ntrackReducedMotion();\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop-guard.d.ts","sourceRoot":"","sources":["../src/loop-guard.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Controller, Globals, SpringValue, } from "@react-spring/core";
|
|
2
|
+
import { is } from "@react-spring/shared";
|
|
3
|
+
const isLoopFunction = (loop) => typeof loop === "function";
|
|
4
|
+
const resolveLoop = (loop) => (isLoopFunction(loop) ? loop() : loop);
|
|
5
|
+
const guardLoop = (update) => {
|
|
6
|
+
const { loop } = update;
|
|
7
|
+
if (!loop) {
|
|
8
|
+
return update;
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
...update,
|
|
12
|
+
loop: () => {
|
|
13
|
+
if (Globals.skipAnimation) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const resolved = resolveLoop(loop);
|
|
17
|
+
return typeof resolved === "object" ? guardLoop(resolved) : resolved;
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/* TODO: End each `loop` at the pass that finds animations skipped until React Spring stops restarting loops
|
|
22
|
+
* synchronously under `skipAnimation`, which GTKX derives from `gtk-enable-animations`.
|
|
23
|
+
* https://github.com/pmndrs/react-spring/issues/2409
|
|
24
|
+
*/
|
|
25
|
+
/* eslint-disable @typescript-eslint/unbound-method -- the overrides call the originals on their own instance */
|
|
26
|
+
const startController = Controller.prototype.start;
|
|
27
|
+
const startSpringValue = SpringValue.prototype.start;
|
|
28
|
+
/* eslint-enable @typescript-eslint/unbound-method */
|
|
29
|
+
Controller.prototype.start = function start(props) {
|
|
30
|
+
if (!props) {
|
|
31
|
+
this.queue = this.queue.map(guardLoop);
|
|
32
|
+
return startController.call(this);
|
|
33
|
+
}
|
|
34
|
+
return startController.call(this, is.arr(props) ? props.map(guardLoop) : guardLoop(props));
|
|
35
|
+
};
|
|
36
|
+
SpringValue.prototype.start = function start(to, props) {
|
|
37
|
+
if (to === undefined) {
|
|
38
|
+
if (this.queue) {
|
|
39
|
+
this.queue = this.queue.map(guardLoop);
|
|
40
|
+
}
|
|
41
|
+
return startSpringValue.call(this);
|
|
42
|
+
}
|
|
43
|
+
return startSpringValue.call(this, guardLoop(is.obj(to) ? to : { ...props, to }));
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=loop-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop-guard.js","sourceRoot":"","sources":["../src/loop-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,UAAU,EAEV,OAAO,EAGP,WAAW,GACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAM1C,MAAM,cAAc,GAAG,CAAC,IAAU,EAAwB,EAAE,CAAC,OAAO,IAAI,KAAK,UAAU,CAAC;AAExF,MAAM,WAAW,GAAG,CAAC,IAAU,EAA2B,EAAE,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAEpG,MAAM,SAAS,GAAG,CAA0B,MAAS,EAAK,EAAE;IACxD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IAExB,IAAI,CAAC,IAAI,EAAE,CAAC;QACR,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,OAAO;QACH,GAAG,MAAM;QACT,IAAI,EAAE,GAAG,EAAE;YACP,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;gBACxB,OAAO,KAAK,CAAC;YACjB,CAAC;YAED,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;YAEnC,OAAO,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;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yncResult,\n Controller,\n type ControllerUpdate,\n Globals,\n type SpringProps,\n type SpringUpdate,\n SpringValue,\n} from \"@react-spring/core\";\nimport { is } from \"@react-spring/shared\";\n\ntype LoopingUpdate = { loop?: Loop | undefined };\ntype LoopFunction = () => boolean | LoopingUpdate;\ntype Loop = boolean | LoopingUpdate | LoopFunction;\n\nconst isLoopFunction = (loop: Loop): loop is LoopFunction => typeof loop === \"function\";\n\nconst resolveLoop = (loop: Loop): boolean | LoopingUpdate => (isLoopFunction(loop) ? loop() : loop);\n\nconst guardLoop = <T extends LoopingUpdate>(update: T): T => {\n const { loop } = update;\n\n if (!loop) {\n return update;\n }\n\n return {\n ...update,\n loop: () => {\n if (Globals.skipAnimation) {\n return false;\n }\n\n const resolved = resolveLoop(loop);\n\n return typeof resolved === \"object\" ? guardLoop(resolved) : resolved;\n },\n };\n};\n\n/* TODO: End each `loop` at the pass that finds animations skipped until React Spring stops restarting loops\n * synchronously under `skipAnimation`, which GTKX derives from `gtk-enable-animations`.\n * https://github.com/pmndrs/react-spring/issues/2409\n */\n/* eslint-disable @typescript-eslint/unbound-method -- the overrides call the originals on their own instance */\nconst startController = Controller.prototype.start;\nconst startSpringValue: (this: SpringValue, props?: SpringUpdate) => AsyncResult<SpringValue> =\n SpringValue.prototype.start;\n/* eslint-enable @typescript-eslint/unbound-method */\n\nController.prototype.start = function start(this: Controller, props?: ControllerUpdate | ControllerUpdate[] | null) {\n if (!props) {\n this.queue = this.queue.map(guardLoop);\n\n return startController.call(this);\n }\n\n return startController.call(this, is.arr(props) ? props.map(guardLoop) : guardLoop(props));\n};\n\nSpringValue.prototype.start = function start(this: SpringValue, to?: unknown, props?: SpringProps) {\n if (to === undefined) {\n if (this.queue) {\n this.queue = this.queue.map(guardLoop);\n }\n\n return startSpringValue.call(this);\n }\n\n return startSpringValue.call(this, guardLoop(is.obj(to) ? to : { ...props, to }));\n};\n"]}
|
package/dist/reduced-motion.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ declare const trackReducedMotion: () => boolean | null;
|
|
|
6
6
|
* `false` otherwise, or `null` before a display opens.
|
|
7
7
|
*
|
|
8
8
|
* @remarks
|
|
9
|
-
* `gtk-enable-animations: false` makes springs jump to their targets.
|
|
9
|
+
* `gtk-enable-animations: false` makes springs jump to their targets. GTKX sets React Spring's
|
|
10
|
+
* `Globals.skipAnimation` only when that setting changes, so an application can set it for its own preference.
|
|
10
11
|
* `gtk-interface-reduced-motion` leaves springs running for components to adapt;
|
|
11
12
|
* it also drives GTK's `prefers-reduced-motion` media query.
|
|
12
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reduced-motion.d.ts","sourceRoot":"","sources":["../src/reduced-motion.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reduced-motion.d.ts","sourceRoot":"","sources":["../src/reduced-motion.ts"],"names":[],"mappings":"AAqDA,QAAA,MAAM,kBAAkB,QAAO,OAAO,GAAG,IAYxC,CAAC;AAUF;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,gBAAgB,QAAO,OAAO,GAAG,IAA2D,CAAC;AAEnG,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,CAAC"}
|
package/dist/reduced-motion.js
CHANGED
|
@@ -2,7 +2,7 @@ import * as Gtk from "@gtkx/gi/gtk";
|
|
|
2
2
|
import { Globals } from "@react-spring/core";
|
|
3
3
|
import { useSyncExternalStore } from "react";
|
|
4
4
|
const REDUCED_MOTION_MINOR = 22;
|
|
5
|
-
const tracker = { settings: null, isReduced: null };
|
|
5
|
+
const tracker = { settings: null, isReduced: null, areAnimationsEnabled: true };
|
|
6
6
|
const listeners = new Set();
|
|
7
7
|
const hasReducedMotionSetting = () => Gtk.checkVersion(4, REDUCED_MOTION_MINOR, 0) === null;
|
|
8
8
|
const isReduceMotionPreferred = (settings) => hasReducedMotionSetting() && settings.gtkInterfaceReducedMotion === Gtk.ReducedMotion.REDUCE;
|
|
@@ -11,8 +11,12 @@ const sync = () => {
|
|
|
11
11
|
if (settings === null) {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const areAnimationsEnabled = settings.gtkEnableAnimations;
|
|
15
|
+
const isReduced = !areAnimationsEnabled || isReduceMotionPreferred(settings);
|
|
16
|
+
if (areAnimationsEnabled !== tracker.areAnimationsEnabled) {
|
|
17
|
+
tracker.areAnimationsEnabled = areAnimationsEnabled;
|
|
18
|
+
Globals.assign({ skipAnimation: !areAnimationsEnabled });
|
|
19
|
+
}
|
|
16
20
|
if (isReduced === tracker.isReduced) {
|
|
17
21
|
return;
|
|
18
22
|
}
|
|
@@ -52,7 +56,8 @@ const subscribe = (listener) => {
|
|
|
52
56
|
* `false` otherwise, or `null` before a display opens.
|
|
53
57
|
*
|
|
54
58
|
* @remarks
|
|
55
|
-
* `gtk-enable-animations: false` makes springs jump to their targets.
|
|
59
|
+
* `gtk-enable-animations: false` makes springs jump to their targets. GTKX sets React Spring's
|
|
60
|
+
* `Globals.skipAnimation` only when that setting changes, so an application can set it for its own preference.
|
|
56
61
|
* `gtk-interface-reduced-motion` leaves springs running for components to adapt;
|
|
57
62
|
* it also drives GTK's `prefers-reduced-motion` media query.
|
|
58
63
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reduced-motion.js","sourceRoot":"","sources":["../src/reduced-motion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAK7C,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,OAAO,GAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"reduced-motion.js","sourceRoot":"","sources":["../src/reduced-motion.ts"],"names":[],"mappings":"AAAA,OAAO,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ntype Tracker = { settings: Gtk.Settings | null; isReduced: boolean | null; areAnimationsEnabled: boolean };\n\nconst REDUCED_MOTION_MINOR = 22;\nconst tracker: Tracker = { settings: null, isReduced: null, areAnimationsEnabled: true };\nconst listeners: Set<Listener> = new Set();\n\nconst hasReducedMotionSetting = (): boolean => Gtk.checkVersion(4, REDUCED_MOTION_MINOR, 0) === null;\n\nconst isReduceMotionPreferred = (settings: Gtk.Settings): boolean =>\n hasReducedMotionSetting() && settings.gtkInterfaceReducedMotion === Gtk.ReducedMotion.REDUCE;\n\nconst sync = (): void => {\n const { settings } = tracker;\n\n if (settings === null) {\n return;\n }\n\n const areAnimationsEnabled = settings.gtkEnableAnimations;\n const isReduced = !areAnimationsEnabled || isReduceMotionPreferred(settings);\n\n if (areAnimationsEnabled !== tracker.areAnimationsEnabled) {\n tracker.areAnimationsEnabled = areAnimationsEnabled;\n Globals.assign({ skipAnimation: !areAnimationsEnabled });\n }\n\n if (isReduced === tracker.isReduced) {\n return;\n }\n\n tracker.isReduced = isReduced;\n\n for (const listener of listeners) {\n listener();\n }\n};\n\nconst watch = (settings: Gtk.Settings): void => {\n tracker.settings = settings;\n settings.on(\"notify::gtk-enable-animations\", sync);\n\n if (hasReducedMotionSetting()) {\n settings.on(\"notify::gtk-interface-reduced-motion\", sync);\n }\n\n sync();\n};\n\nconst trackReducedMotion = (): boolean | null => {\n if (tracker.settings === null) {\n const settings = Gtk.Settings.getDefault();\n\n if (settings === null) {\n return null;\n }\n\n watch(settings);\n }\n\n return tracker.isReduced;\n};\n\nconst subscribe = (listener: Listener): (() => void) => {\n listeners.add(listener);\n\n return () => {\n listeners.delete(listener);\n };\n};\n\n/**\n * Tracks GTK's motion preferences and updates when they change.\n *\n * @returns `true` when animations are disabled or GTK 4.22+ requests reduced motion,\n * `false` otherwise, or `null` before a display opens.\n *\n * @remarks\n * `gtk-enable-animations: false` makes springs jump to their targets. GTKX sets React Spring's\n * `Globals.skipAnimation` only when that setting changes, so an application can set it for its own preference.\n * `gtk-interface-reduced-motion` leaves springs running for components to adapt;\n * it also drives GTK's `prefers-reduced-motion` media query.\n */\nconst useReducedMotion = (): boolean | null => useSyncExternalStore(subscribe, trackReducedMotion);\n\nexport { trackReducedMotion, useReducedMotion };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/animated",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.13",
|
|
4
4
|
"description": "Spring animations for GTKX widgets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gtkx",
|
|
@@ -40,7 +40,9 @@
|
|
|
40
40
|
"./src/index.ts",
|
|
41
41
|
"./dist/index.js",
|
|
42
42
|
"./src/bootstrap.ts",
|
|
43
|
-
"./dist/bootstrap.js"
|
|
43
|
+
"./dist/bootstrap.js",
|
|
44
|
+
"./src/loop-guard.ts",
|
|
45
|
+
"./dist/loop-guard.js"
|
|
44
46
|
],
|
|
45
47
|
"files": [
|
|
46
48
|
"dist",
|
|
@@ -50,8 +52,8 @@
|
|
|
50
52
|
"node": ">=26.7.0"
|
|
51
53
|
},
|
|
52
54
|
"dependencies": {
|
|
53
|
-
"@gtkx/react": "2.0.0-beta.
|
|
54
|
-
"@gtkx/runtime": "2.0.0-beta.
|
|
55
|
+
"@gtkx/react": "^2.0.0-beta.13",
|
|
56
|
+
"@gtkx/runtime": "^2.0.0-beta.13",
|
|
55
57
|
"@react-spring/core": "^10.1.2",
|
|
56
58
|
"@react-spring/shared": "^10.1.2",
|
|
57
59
|
"@react-spring/types": "^10.1.2"
|
|
@@ -61,11 +63,11 @@
|
|
|
61
63
|
"react": "^19.3"
|
|
62
64
|
},
|
|
63
65
|
"devDependencies": {
|
|
64
|
-
"@gtkx/config": "2.0.0-beta.
|
|
65
|
-
"@gtkx/testing": "2.0.0-beta.
|
|
66
|
-
"@gtkx/vitest": "2.0.0-beta.
|
|
66
|
+
"@gtkx/config": "2.0.0-beta.13",
|
|
67
|
+
"@gtkx/testing": "2.0.0-beta.13",
|
|
68
|
+
"@gtkx/vitest": "2.0.0-beta.13",
|
|
67
69
|
"@types/react": "^19.3.0",
|
|
68
|
-
"vitest": "5.0
|
|
70
|
+
"vitest": "5.1.0"
|
|
69
71
|
},
|
|
70
72
|
"scripts": {
|
|
71
73
|
"release": "node ../../scripts/release/publish-package.ts"
|
package/src/bootstrap.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Globals } from "@react-spring/core";
|
|
2
2
|
import { colors, createStringInterpolator } from "@react-spring/shared";
|
|
3
3
|
import { trackReducedMotion } from "./reduced-motion.js";
|
|
4
|
+
import "./loop-guard.js";
|
|
4
5
|
import { requestFrame } from "./request-frame.js";
|
|
5
6
|
|
|
6
7
|
Globals.assign({
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AsyncResult,
|
|
3
|
+
Controller,
|
|
4
|
+
type ControllerUpdate,
|
|
5
|
+
Globals,
|
|
6
|
+
type SpringProps,
|
|
7
|
+
type SpringUpdate,
|
|
8
|
+
SpringValue,
|
|
9
|
+
} from "@react-spring/core";
|
|
10
|
+
import { is } from "@react-spring/shared";
|
|
11
|
+
|
|
12
|
+
type LoopingUpdate = { loop?: Loop | undefined };
|
|
13
|
+
type LoopFunction = () => boolean | LoopingUpdate;
|
|
14
|
+
type Loop = boolean | LoopingUpdate | LoopFunction;
|
|
15
|
+
|
|
16
|
+
const isLoopFunction = (loop: Loop): loop is LoopFunction => typeof loop === "function";
|
|
17
|
+
|
|
18
|
+
const resolveLoop = (loop: Loop): boolean | LoopingUpdate => (isLoopFunction(loop) ? loop() : loop);
|
|
19
|
+
|
|
20
|
+
const guardLoop = <T extends LoopingUpdate>(update: T): T => {
|
|
21
|
+
const { loop } = update;
|
|
22
|
+
|
|
23
|
+
if (!loop) {
|
|
24
|
+
return update;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
...update,
|
|
29
|
+
loop: () => {
|
|
30
|
+
if (Globals.skipAnimation) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const resolved = resolveLoop(loop);
|
|
35
|
+
|
|
36
|
+
return typeof resolved === "object" ? guardLoop(resolved) : resolved;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/* TODO: End each `loop` at the pass that finds animations skipped until React Spring stops restarting loops
|
|
42
|
+
* synchronously under `skipAnimation`, which GTKX derives from `gtk-enable-animations`.
|
|
43
|
+
* https://github.com/pmndrs/react-spring/issues/2409
|
|
44
|
+
*/
|
|
45
|
+
/* eslint-disable @typescript-eslint/unbound-method -- the overrides call the originals on their own instance */
|
|
46
|
+
const startController = Controller.prototype.start;
|
|
47
|
+
const startSpringValue: (this: SpringValue, props?: SpringUpdate) => AsyncResult<SpringValue> =
|
|
48
|
+
SpringValue.prototype.start;
|
|
49
|
+
/* eslint-enable @typescript-eslint/unbound-method */
|
|
50
|
+
|
|
51
|
+
Controller.prototype.start = function start(this: Controller, props?: ControllerUpdate | ControllerUpdate[] | null) {
|
|
52
|
+
if (!props) {
|
|
53
|
+
this.queue = this.queue.map(guardLoop);
|
|
54
|
+
|
|
55
|
+
return startController.call(this);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return startController.call(this, is.arr(props) ? props.map(guardLoop) : guardLoop(props));
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
SpringValue.prototype.start = function start(this: SpringValue, to?: unknown, props?: SpringProps) {
|
|
62
|
+
if (to === undefined) {
|
|
63
|
+
if (this.queue) {
|
|
64
|
+
this.queue = this.queue.map(guardLoop);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return startSpringValue.call(this);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return startSpringValue.call(this, guardLoop(is.obj(to) ? to : { ...props, to }));
|
|
71
|
+
};
|
package/src/reduced-motion.ts
CHANGED
|
@@ -3,10 +3,10 @@ import { Globals } from "@react-spring/core";
|
|
|
3
3
|
import { useSyncExternalStore } from "react";
|
|
4
4
|
|
|
5
5
|
type Listener = () => void;
|
|
6
|
-
type Tracker = { settings: Gtk.Settings | null; isReduced: boolean | null };
|
|
6
|
+
type Tracker = { settings: Gtk.Settings | null; isReduced: boolean | null; areAnimationsEnabled: boolean };
|
|
7
7
|
|
|
8
8
|
const REDUCED_MOTION_MINOR = 22;
|
|
9
|
-
const tracker: Tracker = { settings: null, isReduced: null };
|
|
9
|
+
const tracker: Tracker = { settings: null, isReduced: null, areAnimationsEnabled: true };
|
|
10
10
|
const listeners: Set<Listener> = new Set();
|
|
11
11
|
|
|
12
12
|
const hasReducedMotionSetting = (): boolean => Gtk.checkVersion(4, REDUCED_MOTION_MINOR, 0) === null;
|
|
@@ -21,8 +21,13 @@ const sync = (): void => {
|
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const
|
|
25
|
-
|
|
24
|
+
const areAnimationsEnabled = settings.gtkEnableAnimations;
|
|
25
|
+
const isReduced = !areAnimationsEnabled || isReduceMotionPreferred(settings);
|
|
26
|
+
|
|
27
|
+
if (areAnimationsEnabled !== tracker.areAnimationsEnabled) {
|
|
28
|
+
tracker.areAnimationsEnabled = areAnimationsEnabled;
|
|
29
|
+
Globals.assign({ skipAnimation: !areAnimationsEnabled });
|
|
30
|
+
}
|
|
26
31
|
|
|
27
32
|
if (isReduced === tracker.isReduced) {
|
|
28
33
|
return;
|
|
@@ -75,7 +80,8 @@ const subscribe = (listener: Listener): (() => void) => {
|
|
|
75
80
|
* `false` otherwise, or `null` before a display opens.
|
|
76
81
|
*
|
|
77
82
|
* @remarks
|
|
78
|
-
* `gtk-enable-animations: false` makes springs jump to their targets.
|
|
83
|
+
* `gtk-enable-animations: false` makes springs jump to their targets. GTKX sets React Spring's
|
|
84
|
+
* `Globals.skipAnimation` only when that setting changes, so an application can set it for its own preference.
|
|
79
85
|
* `gtk-interface-reduced-motion` leaves springs running for components to adapt;
|
|
80
86
|
* it also drives GTK's `prefers-reduced-motion` media query.
|
|
81
87
|
*/
|