@gtkx/react 0.18.0 → 0.18.2
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/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +1 -0
- package/dist/errors.js.map +1 -0
- package/dist/factory.d.ts +1 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +1 -0
- package/dist/factory.js.map +1 -0
- package/dist/fiber-root.d.ts +1 -0
- package/dist/fiber-root.d.ts.map +1 -0
- package/dist/fiber-root.js +1 -0
- package/dist/fiber-root.js.map +1 -0
- package/dist/generated/internal.d.ts +1 -0
- package/dist/generated/internal.d.ts.map +1 -0
- package/dist/generated/internal.js +1 -0
- package/dist/generated/internal.js.map +1 -0
- package/dist/generated/jsx.d.ts +1 -0
- package/dist/generated/jsx.d.ts.map +1 -0
- package/dist/generated/jsx.js +1 -0
- package/dist/generated/jsx.js.map +1 -0
- package/dist/generated/registry.d.ts +1 -0
- package/dist/generated/registry.d.ts.map +1 -0
- package/dist/generated/registry.js +1 -0
- package/dist/generated/registry.js.map +1 -0
- package/dist/host-config.d.ts +1 -0
- package/dist/host-config.d.ts.map +1 -0
- package/dist/host-config.js +1 -0
- package/dist/host-config.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx.d.ts +1 -0
- package/dist/jsx.d.ts.map +1 -0
- package/dist/jsx.js +1 -0
- package/dist/jsx.js.map +1 -0
- package/dist/metadata.d.ts +1 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +1 -0
- package/dist/metadata.js.map +1 -0
- package/dist/node.d.ts +1 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +1 -0
- package/dist/node.js.map +1 -0
- package/dist/nodes/adjustable.d.ts +1 -0
- package/dist/nodes/adjustable.d.ts.map +1 -0
- package/dist/nodes/adjustable.js +1 -0
- package/dist/nodes/adjustable.js.map +1 -0
- package/dist/nodes/alert-dialog-response.d.ts +1 -0
- package/dist/nodes/alert-dialog-response.d.ts.map +1 -0
- package/dist/nodes/alert-dialog-response.js +1 -0
- package/dist/nodes/alert-dialog-response.js.map +1 -0
- package/dist/nodes/animation.d.ts +1 -0
- package/dist/nodes/animation.d.ts.map +1 -0
- package/dist/nodes/animation.js +1 -0
- package/dist/nodes/animation.js.map +1 -0
- package/dist/nodes/application.d.ts +1 -0
- package/dist/nodes/application.d.ts.map +1 -0
- package/dist/nodes/application.js +1 -0
- package/dist/nodes/application.js.map +1 -0
- package/dist/nodes/calendar.d.ts +1 -0
- package/dist/nodes/calendar.d.ts.map +1 -0
- package/dist/nodes/calendar.js +1 -0
- package/dist/nodes/calendar.js.map +1 -0
- package/dist/nodes/color-dialog-button.d.ts +1 -0
- package/dist/nodes/color-dialog-button.d.ts.map +1 -0
- package/dist/nodes/color-dialog-button.js +1 -0
- package/dist/nodes/color-dialog-button.js.map +1 -0
- package/dist/nodes/column-view-column.d.ts +1 -0
- package/dist/nodes/column-view-column.d.ts.map +1 -0
- package/dist/nodes/column-view-column.js +1 -0
- package/dist/nodes/column-view-column.js.map +1 -0
- package/dist/nodes/column-view.d.ts +1 -0
- package/dist/nodes/column-view.d.ts.map +1 -0
- package/dist/nodes/column-view.js +1 -0
- package/dist/nodes/column-view.js.map +1 -0
- package/dist/nodes/container-slot.d.ts +1 -0
- package/dist/nodes/container-slot.d.ts.map +1 -0
- package/dist/nodes/container-slot.js +1 -0
- package/dist/nodes/container-slot.js.map +1 -0
- package/dist/nodes/dialog.d.ts +1 -0
- package/dist/nodes/dialog.d.ts.map +1 -0
- package/dist/nodes/dialog.js +1 -0
- package/dist/nodes/dialog.js.map +1 -0
- package/dist/nodes/drawing-area.d.ts +1 -0
- package/dist/nodes/drawing-area.d.ts.map +1 -0
- package/dist/nodes/drawing-area.js +1 -0
- package/dist/nodes/drawing-area.js.map +1 -0
- package/dist/nodes/drop-down.d.ts +1 -0
- package/dist/nodes/drop-down.d.ts.map +1 -0
- package/dist/nodes/drop-down.js +1 -0
- package/dist/nodes/drop-down.js.map +1 -0
- package/dist/nodes/event-controller.d.ts +1 -0
- package/dist/nodes/event-controller.d.ts.map +1 -0
- package/dist/nodes/event-controller.js +1 -0
- package/dist/nodes/event-controller.js.map +1 -0
- package/dist/nodes/fixed-child.d.ts +1 -0
- package/dist/nodes/fixed-child.d.ts.map +1 -0
- package/dist/nodes/fixed-child.js +1 -0
- package/dist/nodes/fixed-child.js.map +1 -0
- package/dist/nodes/font-dialog-button.d.ts +1 -0
- package/dist/nodes/font-dialog-button.d.ts.map +1 -0
- package/dist/nodes/font-dialog-button.js +1 -0
- package/dist/nodes/font-dialog-button.js.map +1 -0
- package/dist/nodes/grid-child.d.ts +1 -0
- package/dist/nodes/grid-child.d.ts.map +1 -0
- package/dist/nodes/grid-child.js +1 -0
- package/dist/nodes/grid-child.js.map +1 -0
- package/dist/nodes/grid-view.d.ts +1 -0
- package/dist/nodes/grid-view.d.ts.map +1 -0
- package/dist/nodes/grid-view.js +1 -0
- package/dist/nodes/grid-view.js.map +1 -0
- package/dist/nodes/internal/base-item-renderer.d.ts +1 -0
- package/dist/nodes/internal/base-item-renderer.d.ts.map +1 -0
- package/dist/nodes/internal/base-item-renderer.js +1 -0
- package/dist/nodes/internal/base-item-renderer.js.map +1 -0
- package/dist/nodes/internal/grid-item-renderer.d.ts +1 -0
- package/dist/nodes/internal/grid-item-renderer.d.ts.map +1 -0
- package/dist/nodes/internal/grid-item-renderer.js +1 -0
- package/dist/nodes/internal/grid-item-renderer.js.map +1 -0
- package/dist/nodes/internal/list-item-renderer.d.ts +1 -0
- package/dist/nodes/internal/list-item-renderer.d.ts.map +1 -0
- package/dist/nodes/internal/list-item-renderer.js +1 -0
- package/dist/nodes/internal/list-item-renderer.js.map +1 -0
- package/dist/nodes/internal/list-store.d.ts +1 -0
- package/dist/nodes/internal/list-store.d.ts.map +1 -0
- package/dist/nodes/internal/list-store.js +1 -0
- package/dist/nodes/internal/list-store.js.map +1 -0
- package/dist/nodes/internal/predicates.d.ts +1 -0
- package/dist/nodes/internal/predicates.d.ts.map +1 -0
- package/dist/nodes/internal/predicates.js +1 -0
- package/dist/nodes/internal/predicates.js.map +1 -0
- package/dist/nodes/internal/props.d.ts +1 -0
- package/dist/nodes/internal/props.d.ts.map +1 -0
- package/dist/nodes/internal/props.js +1 -0
- package/dist/nodes/internal/props.js.map +1 -0
- package/dist/nodes/internal/selection-model-controller.d.ts +1 -0
- package/dist/nodes/internal/selection-model-controller.d.ts.map +1 -0
- package/dist/nodes/internal/selection-model-controller.js +1 -0
- package/dist/nodes/internal/selection-model-controller.js.map +1 -0
- package/dist/nodes/internal/signal-store.d.ts +1 -0
- package/dist/nodes/internal/signal-store.d.ts.map +1 -0
- package/dist/nodes/internal/signal-store.js +1 -0
- package/dist/nodes/internal/signal-store.js.map +1 -0
- package/dist/nodes/internal/simple-list-store.d.ts +1 -0
- package/dist/nodes/internal/simple-list-store.d.ts.map +1 -0
- package/dist/nodes/internal/simple-list-store.js +1 -0
- package/dist/nodes/internal/simple-list-store.js.map +1 -0
- package/dist/nodes/internal/text-buffer-controller.d.ts +1 -0
- package/dist/nodes/internal/text-buffer-controller.d.ts.map +1 -0
- package/dist/nodes/internal/text-buffer-controller.js +1 -0
- package/dist/nodes/internal/text-buffer-controller.js.map +1 -0
- package/dist/nodes/internal/tree-store.d.ts +1 -0
- package/dist/nodes/internal/tree-store.d.ts.map +1 -0
- package/dist/nodes/internal/tree-store.js +1 -0
- package/dist/nodes/internal/tree-store.js.map +1 -0
- package/dist/nodes/internal/widget.d.ts +1 -0
- package/dist/nodes/internal/widget.d.ts.map +1 -0
- package/dist/nodes/internal/widget.js +1 -0
- package/dist/nodes/internal/widget.js.map +1 -0
- package/dist/nodes/level-bar.d.ts +1 -0
- package/dist/nodes/level-bar.d.ts.map +1 -0
- package/dist/nodes/level-bar.js +1 -0
- package/dist/nodes/level-bar.js.map +1 -0
- package/dist/nodes/list-item.d.ts +1 -0
- package/dist/nodes/list-item.d.ts.map +1 -0
- package/dist/nodes/list-item.js +1 -0
- package/dist/nodes/list-item.js.map +1 -0
- package/dist/nodes/list-view.d.ts +1 -0
- package/dist/nodes/list-view.d.ts.map +1 -0
- package/dist/nodes/list-view.js +1 -0
- package/dist/nodes/list-view.js.map +1 -0
- package/dist/nodes/menu.d.ts +1 -0
- package/dist/nodes/menu.d.ts.map +1 -0
- package/dist/nodes/menu.js +1 -0
- package/dist/nodes/menu.js.map +1 -0
- package/dist/nodes/models/grid.d.ts +1 -0
- package/dist/nodes/models/grid.d.ts.map +1 -0
- package/dist/nodes/models/grid.js +1 -0
- package/dist/nodes/models/grid.js.map +1 -0
- package/dist/nodes/models/list.d.ts +1 -0
- package/dist/nodes/models/list.d.ts.map +1 -0
- package/dist/nodes/models/list.js +1 -0
- package/dist/nodes/models/list.js.map +1 -0
- package/dist/nodes/models/menu.d.ts +1 -0
- package/dist/nodes/models/menu.d.ts.map +1 -0
- package/dist/nodes/models/menu.js +1 -0
- package/dist/nodes/models/menu.js.map +1 -0
- package/dist/nodes/navigation-page.d.ts +1 -0
- package/dist/nodes/navigation-page.d.ts.map +1 -0
- package/dist/nodes/navigation-page.js +1 -0
- package/dist/nodes/navigation-page.js.map +1 -0
- package/dist/nodes/navigation-view.d.ts +1 -0
- package/dist/nodes/navigation-view.d.ts.map +1 -0
- package/dist/nodes/navigation-view.js +1 -0
- package/dist/nodes/navigation-view.js.map +1 -0
- package/dist/nodes/notebook-page-tab.d.ts +1 -0
- package/dist/nodes/notebook-page-tab.d.ts.map +1 -0
- package/dist/nodes/notebook-page-tab.js +1 -0
- package/dist/nodes/notebook-page-tab.js.map +1 -0
- package/dist/nodes/notebook-page.d.ts +1 -0
- package/dist/nodes/notebook-page.d.ts.map +1 -0
- package/dist/nodes/notebook-page.js +1 -0
- package/dist/nodes/notebook-page.js.map +1 -0
- package/dist/nodes/notebook.d.ts +1 -0
- package/dist/nodes/notebook.d.ts.map +1 -0
- package/dist/nodes/notebook.js +1 -0
- package/dist/nodes/notebook.js.map +1 -0
- package/dist/nodes/overlay-child.d.ts +1 -0
- package/dist/nodes/overlay-child.d.ts.map +1 -0
- package/dist/nodes/overlay-child.js +1 -0
- package/dist/nodes/overlay-child.js.map +1 -0
- package/dist/nodes/popover-menu.d.ts +1 -0
- package/dist/nodes/popover-menu.d.ts.map +1 -0
- package/dist/nodes/popover-menu.js +1 -0
- package/dist/nodes/popover-menu.js.map +1 -0
- package/dist/nodes/scale.d.ts +1 -0
- package/dist/nodes/scale.d.ts.map +1 -0
- package/dist/nodes/scale.js +1 -0
- package/dist/nodes/scale.js.map +1 -0
- package/dist/nodes/scrolled-window.d.ts +1 -0
- package/dist/nodes/scrolled-window.d.ts.map +1 -0
- package/dist/nodes/scrolled-window.js +1 -0
- package/dist/nodes/scrolled-window.js.map +1 -0
- package/dist/nodes/search-bar.d.ts +1 -0
- package/dist/nodes/search-bar.d.ts.map +1 -0
- package/dist/nodes/search-bar.js +1 -0
- package/dist/nodes/search-bar.js.map +1 -0
- package/dist/nodes/shortcut-controller.d.ts +1 -0
- package/dist/nodes/shortcut-controller.d.ts.map +1 -0
- package/dist/nodes/shortcut-controller.js +1 -0
- package/dist/nodes/shortcut-controller.js.map +1 -0
- package/dist/nodes/shortcut.d.ts +1 -0
- package/dist/nodes/shortcut.d.ts.map +1 -0
- package/dist/nodes/shortcut.js +1 -0
- package/dist/nodes/shortcut.js.map +1 -0
- package/dist/nodes/slot.d.ts +1 -0
- package/dist/nodes/slot.d.ts.map +1 -0
- package/dist/nodes/slot.js +1 -0
- package/dist/nodes/slot.js.map +1 -0
- package/dist/nodes/source-view.d.ts +1 -0
- package/dist/nodes/source-view.d.ts.map +1 -0
- package/dist/nodes/source-view.js +1 -0
- package/dist/nodes/source-view.js.map +1 -0
- package/dist/nodes/stack-page.d.ts +1 -0
- package/dist/nodes/stack-page.d.ts.map +1 -0
- package/dist/nodes/stack-page.js +1 -0
- package/dist/nodes/stack-page.js.map +1 -0
- package/dist/nodes/stack.d.ts +1 -0
- package/dist/nodes/stack.d.ts.map +1 -0
- package/dist/nodes/stack.js +1 -0
- package/dist/nodes/stack.js.map +1 -0
- package/dist/nodes/text-anchor.d.ts +1 -0
- package/dist/nodes/text-anchor.d.ts.map +1 -0
- package/dist/nodes/text-anchor.js +1 -0
- package/dist/nodes/text-anchor.js.map +1 -0
- package/dist/nodes/text-content.d.ts +1 -0
- package/dist/nodes/text-content.d.ts.map +1 -0
- package/dist/nodes/text-content.js +1 -0
- package/dist/nodes/text-content.js.map +1 -0
- package/dist/nodes/text-paintable.d.ts +1 -0
- package/dist/nodes/text-paintable.d.ts.map +1 -0
- package/dist/nodes/text-paintable.js +1 -0
- package/dist/nodes/text-paintable.js.map +1 -0
- package/dist/nodes/text-segment.d.ts +1 -0
- package/dist/nodes/text-segment.d.ts.map +1 -0
- package/dist/nodes/text-segment.js +1 -0
- package/dist/nodes/text-segment.js.map +1 -0
- package/dist/nodes/text-tag.d.ts +1 -0
- package/dist/nodes/text-tag.d.ts.map +1 -0
- package/dist/nodes/text-tag.js +1 -0
- package/dist/nodes/text-tag.js.map +1 -0
- package/dist/nodes/text-view.d.ts +1 -0
- package/dist/nodes/text-view.d.ts.map +1 -0
- package/dist/nodes/text-view.js +1 -0
- package/dist/nodes/text-view.js.map +1 -0
- package/dist/nodes/toggle-group.d.ts +1 -0
- package/dist/nodes/toggle-group.d.ts.map +1 -0
- package/dist/nodes/toggle-group.js +1 -0
- package/dist/nodes/toggle-group.js.map +1 -0
- package/dist/nodes/toggle.d.ts +1 -0
- package/dist/nodes/toggle.d.ts.map +1 -0
- package/dist/nodes/toggle.js +1 -0
- package/dist/nodes/toggle.js.map +1 -0
- package/dist/nodes/virtual.d.ts +1 -0
- package/dist/nodes/virtual.d.ts.map +1 -0
- package/dist/nodes/virtual.js +1 -0
- package/dist/nodes/virtual.js.map +1 -0
- package/dist/nodes/web-view.d.ts +1 -0
- package/dist/nodes/web-view.d.ts.map +1 -0
- package/dist/nodes/web-view.js +1 -0
- package/dist/nodes/web-view.js.map +1 -0
- package/dist/nodes/widget.d.ts +1 -0
- package/dist/nodes/widget.d.ts.map +1 -0
- package/dist/nodes/widget.js +1 -0
- package/dist/nodes/widget.js.map +1 -0
- package/dist/nodes/window.d.ts +1 -0
- package/dist/nodes/window.d.ts.map +1 -0
- package/dist/nodes/window.js +1 -0
- package/dist/nodes/window.js.map +1 -0
- package/dist/portal.d.ts +1 -0
- package/dist/portal.d.ts.map +1 -0
- package/dist/portal.js +1 -0
- package/dist/portal.js.map +1 -0
- package/dist/reconciler.d.ts +1 -0
- package/dist/reconciler.d.ts.map +1 -0
- package/dist/reconciler.js +1 -0
- package/dist/reconciler.js.map +1 -0
- package/dist/registry.d.ts +1 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +1 -0
- package/dist/registry.js.map +1 -0
- package/dist/render.d.ts +1 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +1 -0
- package/dist/render.js.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/package.json +6 -4
- package/src/errors.ts +52 -0
- package/src/factory.ts +62 -0
- package/src/fiber-root.ts +20 -0
- package/src/generated/internal.ts +2134 -0
- package/src/generated/jsx.ts +20068 -0
- package/src/generated/registry.ts +16 -0
- package/src/host-config.ts +186 -0
- package/src/index.ts +11 -0
- package/src/jsx.ts +1294 -0
- package/src/metadata.ts +36 -0
- package/src/node.ts +109 -0
- package/src/nodes/adjustable.ts +68 -0
- package/src/nodes/alert-dialog-response.ts +78 -0
- package/src/nodes/animation.ts +402 -0
- package/src/nodes/application.ts +56 -0
- package/src/nodes/calendar.ts +38 -0
- package/src/nodes/color-dialog-button.ts +69 -0
- package/src/nodes/column-view-column.ts +84 -0
- package/src/nodes/column-view.ts +192 -0
- package/src/nodes/container-slot.ts +87 -0
- package/src/nodes/dialog.ts +25 -0
- package/src/nodes/drawing-area.ts +51 -0
- package/src/nodes/drop-down.ts +92 -0
- package/src/nodes/event-controller.ts +100 -0
- package/src/nodes/fixed-child.ts +108 -0
- package/src/nodes/font-dialog-button.ts +97 -0
- package/src/nodes/grid-child.ts +103 -0
- package/src/nodes/grid-view.ts +96 -0
- package/src/nodes/internal/base-item-renderer.ts +108 -0
- package/src/nodes/internal/grid-item-renderer.ts +71 -0
- package/src/nodes/internal/list-item-renderer.ts +155 -0
- package/src/nodes/internal/list-store.ts +105 -0
- package/src/nodes/internal/predicates.ts +80 -0
- package/src/nodes/internal/props.ts +51 -0
- package/src/nodes/internal/selection-model-controller.ts +115 -0
- package/src/nodes/internal/signal-store.ts +141 -0
- package/src/nodes/internal/simple-list-store.ts +99 -0
- package/src/nodes/internal/text-buffer-controller.ts +374 -0
- package/src/nodes/internal/tree-store.ts +237 -0
- package/src/nodes/internal/widget.ts +78 -0
- package/src/nodes/level-bar.ts +36 -0
- package/src/nodes/list-item.ts +107 -0
- package/src/nodes/list-view.ts +97 -0
- package/src/nodes/menu.ts +27 -0
- package/src/nodes/models/grid.ts +105 -0
- package/src/nodes/models/list.ts +140 -0
- package/src/nodes/models/menu.ts +310 -0
- package/src/nodes/navigation-page.ts +154 -0
- package/src/nodes/navigation-view.ts +58 -0
- package/src/nodes/notebook-page-tab.ts +55 -0
- package/src/nodes/notebook-page.ts +185 -0
- package/src/nodes/notebook.ts +28 -0
- package/src/nodes/overlay-child.ts +109 -0
- package/src/nodes/popover-menu.ts +59 -0
- package/src/nodes/scale.ts +28 -0
- package/src/nodes/scrolled-window.ts +23 -0
- package/src/nodes/search-bar.ts +27 -0
- package/src/nodes/shortcut-controller.ts +27 -0
- package/src/nodes/shortcut.ts +69 -0
- package/src/nodes/slot.ts +138 -0
- package/src/nodes/source-view.ts +130 -0
- package/src/nodes/stack-page.ts +170 -0
- package/src/nodes/stack.ts +35 -0
- package/src/nodes/text-anchor.ts +74 -0
- package/src/nodes/text-content.ts +14 -0
- package/src/nodes/text-paintable.ts +51 -0
- package/src/nodes/text-segment.ts +55 -0
- package/src/nodes/text-tag.ts +287 -0
- package/src/nodes/text-view.ts +93 -0
- package/src/nodes/toggle-group.ts +27 -0
- package/src/nodes/toggle.ts +72 -0
- package/src/nodes/virtual.ts +16 -0
- package/src/nodes/web-view.ts +22 -0
- package/src/nodes/widget.ts +398 -0
- package/src/nodes/window.ts +159 -0
- package/src/portal.ts +37 -0
- package/src/reconciler.ts +52 -0
- package/src/registry.ts +123 -0
- package/src/render.tsx +192 -0
- package/src/types.ts +7 -0
package/src/metadata.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { NativeClass } from "@gtkx/ffi";
|
|
2
|
+
import { PROPS, SIGNALS } from "./generated/internal.js";
|
|
3
|
+
import type { Container } from "./types.js";
|
|
4
|
+
|
|
5
|
+
const walkPrototypeChain = <T>(instance: Container, lookup: (typeName: string) => T | null): T | null => {
|
|
6
|
+
// biome-ignore lint/complexity/noBannedTypes: Walking prototype chain requires Function type
|
|
7
|
+
let current: Function | null = instance.constructor;
|
|
8
|
+
|
|
9
|
+
while (current) {
|
|
10
|
+
const typeName = (current as NativeClass).glibTypeName;
|
|
11
|
+
|
|
12
|
+
if (typeName) {
|
|
13
|
+
const result = lookup(typeName);
|
|
14
|
+
if (result !== null) {
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const prototype = Object.getPrototypeOf(current.prototype);
|
|
20
|
+
current = prototype?.constructor ?? null;
|
|
21
|
+
|
|
22
|
+
if (current === Object || current === Function) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return null;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const resolvePropMeta = (instance: Container, key: string): [string | null, string] | null =>
|
|
31
|
+
walkPrototypeChain(instance, (typeName) => PROPS[typeName]?.[key] ?? null);
|
|
32
|
+
|
|
33
|
+
export const resolveSignal = (instance: Container, propName: string): string | null => {
|
|
34
|
+
if (propName === "onNotify") return "notify";
|
|
35
|
+
return walkPrototypeChain(instance, (typeName) => SIGNALS[typeName]?.[propName] ?? null);
|
|
36
|
+
};
|
package/src/node.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { getSignalStore, type SignalStore } from "./nodes/internal/signal-store.js";
|
|
2
|
+
import type { Container, ContainerClass, Props } from "./types.js";
|
|
3
|
+
|
|
4
|
+
// biome-ignore lint/suspicious/noExplicitAny: Self-referential type bounds require any
|
|
5
|
+
export class Node<TContainer = any, TProps = any, TParent extends Node = any, TChild extends Node = any> {
|
|
6
|
+
public static createContainer(_props: Props, _containerClass: ContainerClass, _rootContainer?: Container): unknown {
|
|
7
|
+
throw new Error("Cannot create container: unsupported node type");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
container: TContainer;
|
|
11
|
+
props: TProps;
|
|
12
|
+
typeName: string;
|
|
13
|
+
signalStore: SignalStore;
|
|
14
|
+
rootContainer: Container;
|
|
15
|
+
parent: TParent | null = null;
|
|
16
|
+
children: TChild[] = [];
|
|
17
|
+
private childIndices = new Map<TChild, number>();
|
|
18
|
+
|
|
19
|
+
constructor(typeName: string, props: TProps, container: TContainer, rootContainer: Container) {
|
|
20
|
+
this.typeName = typeName;
|
|
21
|
+
this.props = props;
|
|
22
|
+
this.container = container;
|
|
23
|
+
this.rootContainer = rootContainer;
|
|
24
|
+
this.signalStore = getSignalStore(rootContainer);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public isValidChild(_child: Node): boolean {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public isValidParent(_parent: Node): boolean {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public setParent(parent: TParent | null): void {
|
|
36
|
+
if (parent !== null && !this.isValidParent(parent)) {
|
|
37
|
+
throw new Error(`Cannot add '${this.typeName}' to '${parent.typeName}'`);
|
|
38
|
+
}
|
|
39
|
+
this.parent = parent;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public appendInitialChild(child: TChild): void {
|
|
43
|
+
this.appendChild(child);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public appendChild(child: TChild): void {
|
|
47
|
+
if (!this.isValidChild(child)) {
|
|
48
|
+
throw new Error(`Cannot append '${child.typeName}' to '${this.typeName}'`);
|
|
49
|
+
}
|
|
50
|
+
this.childIndices.set(child, this.children.length);
|
|
51
|
+
this.children.push(child);
|
|
52
|
+
child.setParent(this);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public removeChild(child: TChild): void {
|
|
56
|
+
const index = this.childIndices.get(child);
|
|
57
|
+
if (index !== undefined) {
|
|
58
|
+
child.setParent(null);
|
|
59
|
+
this.children.splice(index, 1);
|
|
60
|
+
this.childIndices.delete(child);
|
|
61
|
+
this.rebuildChildIndices(index);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public insertBefore(child: TChild, before: TChild): void {
|
|
66
|
+
const beforeIndex = this.childIndices.get(before);
|
|
67
|
+
if (beforeIndex === undefined) {
|
|
68
|
+
throw new Error(`Cannot find 'before' child '${before.typeName}' in '${this.typeName}'`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const existingIndex = this.childIndices.get(child);
|
|
72
|
+
if (existingIndex !== undefined) {
|
|
73
|
+
this.children.splice(existingIndex, 1);
|
|
74
|
+
const adjustedIndex = existingIndex < beforeIndex ? beforeIndex - 1 : beforeIndex;
|
|
75
|
+
this.children.splice(adjustedIndex, 0, child);
|
|
76
|
+
this.rebuildChildIndices(Math.min(existingIndex, adjustedIndex));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!this.isValidChild(child)) {
|
|
81
|
+
throw new Error(`Cannot insert '${child.typeName}' into '${this.typeName}'`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.children.splice(beforeIndex, 0, child);
|
|
85
|
+
this.rebuildChildIndices(beforeIndex);
|
|
86
|
+
child.setParent(this);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private rebuildChildIndices(fromIndex: number): void {
|
|
90
|
+
for (let i = fromIndex; i < this.children.length; i++) {
|
|
91
|
+
this.childIndices.set(this.children[i] as TChild, i);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public finalizeInitialChildren(props: TProps): boolean {
|
|
96
|
+
this.commitUpdate(null, props);
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public commitUpdate(_oldProps: TProps | null, newProps: TProps): void {
|
|
101
|
+
this.props = newProps;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public commitMount(): void {}
|
|
105
|
+
|
|
106
|
+
public detachDeletedInstance(): void {
|
|
107
|
+
this.signalStore.clear(this);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
+
import type { AdjustableProps } from "../jsx.js";
|
|
3
|
+
import type { AdjustableWidget } from "../registry.js";
|
|
4
|
+
import { filterProps, hasChanged } from "./internal/props.js";
|
|
5
|
+
import { WidgetNode } from "./widget.js";
|
|
6
|
+
|
|
7
|
+
const OWN_PROPS = ["value", "lower", "upper", "stepIncrement", "pageIncrement", "pageSize", "onValueChanged"] as const;
|
|
8
|
+
|
|
9
|
+
export class AdjustableNode<T extends AdjustableWidget = AdjustableWidget> extends WidgetNode<T, AdjustableProps> {
|
|
10
|
+
private adjustment: Gtk.Adjustment | null = null;
|
|
11
|
+
|
|
12
|
+
public override commitUpdate(oldProps: AdjustableProps | null, newProps: AdjustableProps): void {
|
|
13
|
+
super.commitUpdate(oldProps ? filterProps(oldProps, OWN_PROPS) : null, filterProps(newProps, OWN_PROPS));
|
|
14
|
+
this.applyOwnProps(oldProps, newProps);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
protected ensureAdjustment(props: AdjustableProps): Gtk.Adjustment {
|
|
18
|
+
if (!this.adjustment) {
|
|
19
|
+
this.adjustment = new Gtk.Adjustment(
|
|
20
|
+
props.value ?? 0,
|
|
21
|
+
props.lower ?? 0,
|
|
22
|
+
props.upper ?? 100,
|
|
23
|
+
props.stepIncrement ?? 1,
|
|
24
|
+
props.pageIncrement ?? 10,
|
|
25
|
+
props.pageSize ?? 0,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
this.container.setAdjustment(this.adjustment);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return this.adjustment;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected applyOwnProps(oldProps: AdjustableProps | null, newProps: AdjustableProps): void {
|
|
35
|
+
const adjustment = this.ensureAdjustment(newProps);
|
|
36
|
+
|
|
37
|
+
if (hasChanged(oldProps, newProps, "onValueChanged")) {
|
|
38
|
+
const { onValueChanged } = newProps;
|
|
39
|
+
this.signalStore.set(
|
|
40
|
+
this,
|
|
41
|
+
this.container,
|
|
42
|
+
"value-changed",
|
|
43
|
+
onValueChanged ? (self: T) => onValueChanged(self.getValue(), self) : undefined,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!oldProps) return;
|
|
48
|
+
|
|
49
|
+
if (hasChanged(oldProps, newProps, "lower")) {
|
|
50
|
+
adjustment.setLower(newProps.lower ?? 0);
|
|
51
|
+
}
|
|
52
|
+
if (hasChanged(oldProps, newProps, "upper")) {
|
|
53
|
+
adjustment.setUpper(newProps.upper ?? 100);
|
|
54
|
+
}
|
|
55
|
+
if (hasChanged(oldProps, newProps, "stepIncrement")) {
|
|
56
|
+
adjustment.setStepIncrement(newProps.stepIncrement ?? 1);
|
|
57
|
+
}
|
|
58
|
+
if (hasChanged(oldProps, newProps, "pageIncrement")) {
|
|
59
|
+
adjustment.setPageIncrement(newProps.pageIncrement ?? 10);
|
|
60
|
+
}
|
|
61
|
+
if (hasChanged(oldProps, newProps, "pageSize")) {
|
|
62
|
+
adjustment.setPageSize(newProps.pageSize ?? 0);
|
|
63
|
+
}
|
|
64
|
+
if (hasChanged(oldProps, newProps, "value") && newProps.value !== undefined) {
|
|
65
|
+
adjustment.setValue(newProps.value);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as Adw from "@gtkx/ffi/adw";
|
|
2
|
+
import type { AlertDialogResponseProps } from "../jsx.js";
|
|
3
|
+
import type { Node } from "../node.js";
|
|
4
|
+
import { hasChanged } from "./internal/props.js";
|
|
5
|
+
import { VirtualNode } from "./virtual.js";
|
|
6
|
+
import { WidgetNode } from "./widget.js";
|
|
7
|
+
|
|
8
|
+
export class AlertDialogResponseNode extends VirtualNode<AlertDialogResponseProps, WidgetNode<Adw.AlertDialog>> {
|
|
9
|
+
private responseId: string | null = null;
|
|
10
|
+
|
|
11
|
+
public override isValidParent(parent: Node): boolean {
|
|
12
|
+
return parent instanceof WidgetNode && parent.container instanceof Adw.AlertDialog;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public override setParent(parent: WidgetNode<Adw.AlertDialog> | null): void {
|
|
16
|
+
if (!parent && this.parent) {
|
|
17
|
+
this.removeFromDialog();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
super.setParent(parent);
|
|
21
|
+
|
|
22
|
+
if (parent && !this.responseId) {
|
|
23
|
+
this.responseId = this.props.id;
|
|
24
|
+
parent.container.addResponse(this.responseId, this.props.label);
|
|
25
|
+
this.applyOwnProps(null, this.props);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public override commitUpdate(oldProps: AlertDialogResponseProps | null, newProps: AlertDialogResponseProps): void {
|
|
30
|
+
super.commitUpdate(oldProps, newProps);
|
|
31
|
+
|
|
32
|
+
if (!this.parent || !this.responseId) return;
|
|
33
|
+
|
|
34
|
+
if (hasChanged(oldProps, newProps, "id")) {
|
|
35
|
+
const oldId = this.responseId;
|
|
36
|
+
const newId = newProps.id;
|
|
37
|
+
const label = newProps.label;
|
|
38
|
+
|
|
39
|
+
this.parent.container.removeResponse(oldId);
|
|
40
|
+
this.responseId = newId;
|
|
41
|
+
this.parent.container.addResponse(newId, label);
|
|
42
|
+
this.applyOwnProps(null, newProps);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (hasChanged(oldProps, newProps, "label")) {
|
|
47
|
+
this.parent.container.setResponseLabel(this.responseId, newProps.label);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this.applyOwnProps(oldProps, newProps);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public override detachDeletedInstance(): void {
|
|
54
|
+
this.removeFromDialog();
|
|
55
|
+
super.detachDeletedInstance();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private removeFromDialog(): void {
|
|
59
|
+
if (!this.parent || !this.responseId) return;
|
|
60
|
+
|
|
61
|
+
this.parent.container.removeResponse(this.responseId);
|
|
62
|
+
this.responseId = null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private applyOwnProps(oldProps: AlertDialogResponseProps | null, newProps: AlertDialogResponseProps): void {
|
|
66
|
+
if (!this.parent || !this.responseId) return;
|
|
67
|
+
|
|
68
|
+
if (hasChanged(oldProps, newProps, "appearance")) {
|
|
69
|
+
this.parent.container.setResponseAppearance(
|
|
70
|
+
this.responseId,
|
|
71
|
+
newProps.appearance ?? Adw.ResponseAppearance.DEFAULT,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
if (hasChanged(oldProps, newProps, "enabled")) {
|
|
75
|
+
this.parent.container.setResponseEnabled(this.responseId, newProps.enabled ?? true);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import * as Adw from "@gtkx/ffi/adw";
|
|
2
|
+
import * as Gdk from "@gtkx/ffi/gdk";
|
|
3
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
4
|
+
import type { AnimatableProperties, AnimationProps, SpringTransition, TimedTransition } from "../jsx.js";
|
|
5
|
+
import type { Node } from "../node.js";
|
|
6
|
+
import type { Container } from "../types.js";
|
|
7
|
+
import { attachChild, detachChild, isAttachedTo } from "./internal/widget.js";
|
|
8
|
+
import { VirtualNode } from "./virtual.js";
|
|
9
|
+
import { WidgetNode } from "./widget.js";
|
|
10
|
+
|
|
11
|
+
let animationCounter = 0;
|
|
12
|
+
|
|
13
|
+
const DEFAULT_TIMED_DURATION = 300;
|
|
14
|
+
const DEFAULT_SPRING_DAMPING = 1;
|
|
15
|
+
const DEFAULT_SPRING_MASS = 1;
|
|
16
|
+
const DEFAULT_SPRING_STIFFNESS = 100;
|
|
17
|
+
|
|
18
|
+
export class AnimationNode extends VirtualNode<AnimationProps, WidgetNode, WidgetNode> {
|
|
19
|
+
private className: string;
|
|
20
|
+
private provider: Gtk.CssProvider | null = null;
|
|
21
|
+
private display: Gdk.Display | null = null;
|
|
22
|
+
private currentAnimation: Adw.Animation | null = null;
|
|
23
|
+
private currentValues: AnimatableProperties = {};
|
|
24
|
+
private isExiting = false;
|
|
25
|
+
private detachedParentWidget: Gtk.Widget | null = null;
|
|
26
|
+
|
|
27
|
+
constructor(typeName: string, props: AnimationProps, container: undefined, rootContainer: Container) {
|
|
28
|
+
super(typeName, props, container, rootContainer);
|
|
29
|
+
this.className = `gtkx-anim-${animationCounter++}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public override isValidChild(child: Node): boolean {
|
|
33
|
+
return child instanceof WidgetNode;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public override isValidParent(parent: Node): boolean {
|
|
37
|
+
return parent instanceof WidgetNode;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public override setParent(parent: WidgetNode | null): void {
|
|
41
|
+
if (!parent && this.parent) {
|
|
42
|
+
this.detachedParentWidget = this.parent.container;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
super.setParent(parent);
|
|
46
|
+
|
|
47
|
+
if (parent && this.children[0]) {
|
|
48
|
+
this.onChildChange(null);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public override appendChild(child: WidgetNode): void {
|
|
53
|
+
const oldChildWidget = this.children[0]?.container ?? null;
|
|
54
|
+
|
|
55
|
+
super.appendChild(child);
|
|
56
|
+
|
|
57
|
+
if (this.parent) {
|
|
58
|
+
this.onChildChange(oldChildWidget);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public override removeChild(child: WidgetNode): void {
|
|
63
|
+
const oldChildWidget = child.container;
|
|
64
|
+
|
|
65
|
+
super.removeChild(child);
|
|
66
|
+
|
|
67
|
+
if (this.parent && oldChildWidget) {
|
|
68
|
+
this.onChildChange(oldChildWidget);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public override finalizeInitialChildren(props: AnimationProps): boolean {
|
|
73
|
+
this.commitUpdate(null, props);
|
|
74
|
+
return !!props.animateOnMount;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public override commitMount(): void {
|
|
78
|
+
const animate = this.props.animate;
|
|
79
|
+
|
|
80
|
+
if (this.props.animateOnMount && animate) {
|
|
81
|
+
this.animateTo(animate);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public override commitUpdate(oldProps: AnimationProps | null, newProps: AnimationProps): void {
|
|
86
|
+
super.commitUpdate(oldProps, newProps);
|
|
87
|
+
|
|
88
|
+
if (this.isExiting) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (oldProps && newProps.animate && !this.areAnimatedPropsEqual(oldProps.animate, newProps.animate)) {
|
|
93
|
+
const target = newProps.animate;
|
|
94
|
+
if (this.children[0] && !this.isExiting) {
|
|
95
|
+
this.animateTo(target);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public override detachDeletedInstance(): void {
|
|
101
|
+
if (this.isExiting) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (this.props.exit && this.children[0]) {
|
|
106
|
+
this.isExiting = true;
|
|
107
|
+
|
|
108
|
+
this.animateTo(this.props.exit, () => {
|
|
109
|
+
this.detachChildFromParentWidget();
|
|
110
|
+
this.cleanup();
|
|
111
|
+
super.detachDeletedInstance();
|
|
112
|
+
});
|
|
113
|
+
} else {
|
|
114
|
+
this.detachChildFromParentWidget();
|
|
115
|
+
this.cleanup();
|
|
116
|
+
super.detachDeletedInstance();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private onChildChange(oldChild: Gtk.Widget | null): void {
|
|
121
|
+
const parentWidget = this.parent?.container ?? null;
|
|
122
|
+
const childWidget = this.children[0]?.container ?? null;
|
|
123
|
+
|
|
124
|
+
if (oldChild && this.provider) {
|
|
125
|
+
oldChild.removeCssClass(this.className);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (oldChild && parentWidget && isAttachedTo(oldChild, parentWidget)) {
|
|
129
|
+
detachChild(oldChild, parentWidget);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (childWidget && parentWidget) {
|
|
133
|
+
attachChild(childWidget, parentWidget);
|
|
134
|
+
|
|
135
|
+
this.setupCssProvider();
|
|
136
|
+
childWidget.addCssClass(this.className);
|
|
137
|
+
|
|
138
|
+
const initial = this.props.initial;
|
|
139
|
+
const animate = this.props.animate;
|
|
140
|
+
|
|
141
|
+
if (initial === false || !this.props.animateOnMount) {
|
|
142
|
+
if (animate) {
|
|
143
|
+
this.currentValues = { ...animate };
|
|
144
|
+
this.applyValues(this.currentValues);
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
const initialValues = initial ?? animate ?? {};
|
|
148
|
+
this.currentValues = { ...initialValues };
|
|
149
|
+
this.applyValues(this.currentValues);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private detachChildFromParentWidget(): void {
|
|
155
|
+
const parentWidget = this.parent?.container ?? this.detachedParentWidget;
|
|
156
|
+
const childWidget = this.children[0]?.container ?? null;
|
|
157
|
+
|
|
158
|
+
if (childWidget && parentWidget && isAttachedTo(childWidget, parentWidget)) {
|
|
159
|
+
detachChild(childWidget, parentWidget);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private setupCssProvider(): void {
|
|
164
|
+
const childWidget = this.children[0]?.container ?? null;
|
|
165
|
+
if (this.provider || !childWidget) return;
|
|
166
|
+
|
|
167
|
+
this.provider = new Gtk.CssProvider();
|
|
168
|
+
this.display = Gdk.DisplayManager.get().getDefaultDisplay();
|
|
169
|
+
|
|
170
|
+
if (this.display) {
|
|
171
|
+
Gtk.StyleContext.addProviderForDisplay(
|
|
172
|
+
this.display,
|
|
173
|
+
this.provider,
|
|
174
|
+
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION,
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private cleanup(): void {
|
|
180
|
+
const childWidget = this.children[0]?.container ?? null;
|
|
181
|
+
|
|
182
|
+
if (this.currentAnimation) {
|
|
183
|
+
this.currentAnimation.skip();
|
|
184
|
+
this.currentAnimation = null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (this.provider && this.display) {
|
|
188
|
+
Gtk.StyleContext.removeProviderForDisplay(this.display, this.provider);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (childWidget) {
|
|
192
|
+
childWidget.removeCssClass(this.className);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
this.provider = null;
|
|
196
|
+
this.display = null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
private animateTo(target: AnimatableProperties, onComplete?: () => void): void {
|
|
200
|
+
const childWidget = this.children[0]?.container ?? null;
|
|
201
|
+
if (!childWidget) return;
|
|
202
|
+
|
|
203
|
+
if (this.currentAnimation) {
|
|
204
|
+
this.currentAnimation.skip();
|
|
205
|
+
this.currentAnimation = null;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const from = { ...this.currentValues };
|
|
209
|
+
const to = { ...target };
|
|
210
|
+
|
|
211
|
+
this.props.onAnimationStart?.();
|
|
212
|
+
|
|
213
|
+
const callback = new Adw.CallbackAnimationTarget((progress: number) => {
|
|
214
|
+
const interpolated = this.interpolate(from, to, progress);
|
|
215
|
+
this.currentValues = interpolated;
|
|
216
|
+
this.applyValues(interpolated);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const animation = this.createAnimation(childWidget, callback);
|
|
220
|
+
|
|
221
|
+
animation.connect("done", () => {
|
|
222
|
+
this.currentValues = { ...to };
|
|
223
|
+
this.currentAnimation = null;
|
|
224
|
+
this.props.onAnimationComplete?.();
|
|
225
|
+
onComplete?.();
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
this.currentAnimation = animation;
|
|
229
|
+
|
|
230
|
+
const transition = this.props.transition;
|
|
231
|
+
const delay = transition?.delay ?? 0;
|
|
232
|
+
|
|
233
|
+
if (delay > 0) {
|
|
234
|
+
setTimeout(() => {
|
|
235
|
+
if (this.currentAnimation === animation) {
|
|
236
|
+
animation.play();
|
|
237
|
+
}
|
|
238
|
+
}, delay);
|
|
239
|
+
} else {
|
|
240
|
+
animation.play();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
private createAnimation(widget: Gtk.Widget, target: Adw.CallbackAnimationTarget): Adw.Animation {
|
|
245
|
+
const transition = this.props.transition;
|
|
246
|
+
|
|
247
|
+
if (transition?.mode === "spring") {
|
|
248
|
+
return this.createSpringAnimation(widget, target, transition);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return this.createTimedAnimation(widget, target, transition);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private createTimedAnimation(
|
|
255
|
+
widget: Gtk.Widget,
|
|
256
|
+
target: Adw.CallbackAnimationTarget,
|
|
257
|
+
transition: TimedTransition | undefined,
|
|
258
|
+
): Adw.TimedAnimation {
|
|
259
|
+
const duration = transition?.duration ?? DEFAULT_TIMED_DURATION;
|
|
260
|
+
|
|
261
|
+
const animation = new Adw.TimedAnimation(widget, 0, 1, duration, target);
|
|
262
|
+
|
|
263
|
+
if (transition?.easing !== undefined) {
|
|
264
|
+
animation.setEasing(transition.easing);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (transition?.repeat !== undefined) {
|
|
268
|
+
animation.setRepeatCount(transition.repeat);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (transition?.reverse !== undefined) {
|
|
272
|
+
animation.setReverse(transition.reverse);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (transition?.alternate !== undefined) {
|
|
276
|
+
animation.setAlternate(transition.alternate);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return animation;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private createSpringAnimation(
|
|
283
|
+
widget: Gtk.Widget,
|
|
284
|
+
target: Adw.CallbackAnimationTarget,
|
|
285
|
+
transition: SpringTransition,
|
|
286
|
+
): Adw.SpringAnimation {
|
|
287
|
+
const damping = transition.damping ?? DEFAULT_SPRING_DAMPING;
|
|
288
|
+
const mass = transition.mass ?? DEFAULT_SPRING_MASS;
|
|
289
|
+
const stiffness = transition.stiffness ?? DEFAULT_SPRING_STIFFNESS;
|
|
290
|
+
|
|
291
|
+
const springParams = new Adw.SpringParams(damping, mass, stiffness);
|
|
292
|
+
const animation = new Adw.SpringAnimation(widget, 0, 1, springParams, target);
|
|
293
|
+
|
|
294
|
+
if (transition.initialVelocity !== undefined) {
|
|
295
|
+
animation.setInitialVelocity(transition.initialVelocity);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (transition.clamp !== undefined) {
|
|
299
|
+
animation.setClamp(transition.clamp);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return animation;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
private applyValues(values: AnimatableProperties): void {
|
|
306
|
+
if (!this.provider) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const childWidget = this.children[0]?.container ?? null;
|
|
311
|
+
if (childWidget && !childWidget.getCssClasses()?.includes(this.className)) {
|
|
312
|
+
childWidget.addCssClass(this.className);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const css = this.buildCss(this.className, values);
|
|
316
|
+
if (css) {
|
|
317
|
+
this.provider.loadFromString(css);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
private getDefaultValue(property: keyof AnimatableProperties): number {
|
|
322
|
+
switch (property) {
|
|
323
|
+
case "opacity":
|
|
324
|
+
case "scale":
|
|
325
|
+
case "scaleX":
|
|
326
|
+
case "scaleY":
|
|
327
|
+
return 1;
|
|
328
|
+
default:
|
|
329
|
+
return 0;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
private interpolate(from: AnimatableProperties, to: AnimatableProperties, progress: number): AnimatableProperties {
|
|
334
|
+
const result: AnimatableProperties = {};
|
|
335
|
+
|
|
336
|
+
const allKeys = new Set([...Object.keys(from), ...Object.keys(to)]) as Set<keyof AnimatableProperties>;
|
|
337
|
+
|
|
338
|
+
for (const key of allKeys) {
|
|
339
|
+
const fromVal = from[key] ?? this.getDefaultValue(key);
|
|
340
|
+
const toVal = to[key] ?? this.getDefaultValue(key);
|
|
341
|
+
result[key] = fromVal + (toVal - fromVal) * progress;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return result;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
private buildCss(className: string, props: AnimatableProperties): string {
|
|
348
|
+
const parts: string[] = [];
|
|
349
|
+
const transforms: string[] = [];
|
|
350
|
+
|
|
351
|
+
if (props.opacity !== undefined) {
|
|
352
|
+
parts.push(`opacity: ${props.opacity}`);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (props.translateX !== undefined || props.translateY !== undefined) {
|
|
356
|
+
transforms.push(`translate(${props.translateX ?? 0}px, ${props.translateY ?? 0}px)`);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (props.scale !== undefined) {
|
|
360
|
+
transforms.push(`scale(${props.scale})`);
|
|
361
|
+
} else if (props.scaleX !== undefined || props.scaleY !== undefined) {
|
|
362
|
+
transforms.push(`scale(${props.scaleX ?? 1}, ${props.scaleY ?? 1})`);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (props.rotate !== undefined) {
|
|
366
|
+
transforms.push(`rotate(${props.rotate}deg)`);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (props.skewX !== undefined) {
|
|
370
|
+
transforms.push(`skewX(${props.skewX}deg)`);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (props.skewY !== undefined) {
|
|
374
|
+
transforms.push(`skewY(${props.skewY}deg)`);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (transforms.length > 0) {
|
|
378
|
+
parts.push(`transform: ${transforms.join(" ")}`);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (parts.length === 0) {
|
|
382
|
+
return "";
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return `.${className} { ${parts.join("; ")}; }`;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
private areAnimatedPropsEqual<T extends Record<string, unknown>>(a?: T, b?: T): boolean {
|
|
389
|
+
if (a === b) return true;
|
|
390
|
+
if (!a || !b) return false;
|
|
391
|
+
|
|
392
|
+
const keysA = Object.keys(a);
|
|
393
|
+
const keysB = Object.keys(b);
|
|
394
|
+
if (keysA.length !== keysB.length) return false;
|
|
395
|
+
|
|
396
|
+
for (const key of keysA) {
|
|
397
|
+
if (a[key] !== b[key]) return false;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
}
|