react-x11 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/README.md +330 -81
  2. package/package.json +132 -14
  3. package/src/ClickToComponent.js +9 -2
  4. package/src/DevToolsIntegration.js +440 -32
  5. package/src/Reconciler.js +463 -165
  6. package/src/a11y.js +1299 -0
  7. package/src/acceleratorhooks.js +86 -0
  8. package/src/accelerators.js +128 -0
  9. package/src/activate.js +168 -0
  10. package/src/anchor.js +360 -0
  11. package/src/appcontext.js +161 -0
  12. package/src/appearance.js +748 -0
  13. package/src/appearancehooks.js +96 -0
  14. package/src/apphooks.js +73 -0
  15. package/src/application.js +748 -0
  16. package/src/atspi.js +1953 -0
  17. package/src/bus.js +545 -0
  18. package/src/bushooks.js +136 -0
  19. package/src/clientmessage.js +140 -0
  20. package/src/clipboard.js +121 -0
  21. package/src/components/Button.js +148 -33
  22. package/src/components/Checkbox.js +66 -32
  23. package/src/components/Dialog.js +96 -29
  24. package/src/components/FileDialog.js +491 -0
  25. package/src/components/Icon.js +329 -0
  26. package/src/components/Menu.js +797 -133
  27. package/src/components/PasswordInput.js +434 -0
  28. package/src/components/ProgressBar.js +91 -12
  29. package/src/components/Radio.js +78 -35
  30. package/src/components/Select.js +255 -65
  31. package/src/components/Slider.js +102 -41
  32. package/src/components/SplitPane.js +206 -0
  33. package/src/components/Switch.js +100 -22
  34. package/src/components/Table.js +529 -0
  35. package/src/components/Tabs.js +211 -0
  36. package/src/components/Tooltip.js +528 -54
  37. package/src/components/anchor.js +154 -107
  38. package/src/components/change.js +34 -0
  39. package/src/components/dnd.js +103 -0
  40. package/src/components/index.js +16 -3
  41. package/src/components/keys.js +17 -20
  42. package/src/components/scribble.js +247 -0
  43. package/src/components/theme.js +350 -42
  44. package/src/components/typeahead.js +12 -2
  45. package/src/compose.js +868 -0
  46. package/src/compositing.js +224 -0
  47. package/src/dbusmenu.js +384 -0
  48. package/src/debug.d.ts +63 -0
  49. package/src/debug.js +642 -0
  50. package/src/decorations.js +486 -0
  51. package/src/desktopsettings.js +209 -0
  52. package/src/desktopsettingshooks.js +62 -0
  53. package/src/dnd.js +1725 -0
  54. package/src/editmenu.js +272 -0
  55. package/src/errors.js +98 -0
  56. package/src/events.js +1406 -162
  57. package/src/extensions.js +45 -0
  58. package/src/filedialog.js +375 -0
  59. package/src/filedialoghooks.js +132 -0
  60. package/src/fonthooks.js +64 -0
  61. package/src/fonts.js +301 -0
  62. package/src/foreignnodes.js +519 -0
  63. package/src/frame/child.js +33 -0
  64. package/src/frame/childmain.js +274 -0
  65. package/src/frame/env.js +140 -0
  66. package/src/frame/index.js +444 -0
  67. package/src/frame/lifecycle.js +67 -0
  68. package/src/frame/protocol.js +179 -0
  69. package/src/frames.js +73 -0
  70. package/src/glbackend.js +114 -0
  71. package/src/glnodes.js +125 -67
  72. package/src/globalmenu.js +683 -0
  73. package/src/host.d.ts +88 -0
  74. package/src/host.js +42 -0
  75. package/src/idle.js +490 -0
  76. package/src/idlehooks.js +100 -0
  77. package/src/imagesource.js +349 -0
  78. package/src/index.d.ts +475 -0
  79. package/src/index.js +83 -9
  80. package/src/inputtime.js +206 -0
  81. package/src/jsx-dev-runtime.d.ts +21 -0
  82. package/src/jsx-dev-runtime.js +2 -0
  83. package/src/jsx-runtime.d.ts +39 -0
  84. package/src/jsx-runtime.js +6 -0
  85. package/src/keyboard.js +256 -0
  86. package/src/keyboardstate.js +278 -0
  87. package/src/keyboardstatehooks.js +58 -0
  88. package/src/keysyms.d.ts +149 -0
  89. package/src/keysyms.js +270 -0
  90. package/src/locale.js +170 -0
  91. package/src/localehooks.js +47 -0
  92. package/src/menuitem.js +223 -0
  93. package/src/node.d.ts +597 -0
  94. package/src/node.js +44 -0
  95. package/src/nodes.js +9546 -690
  96. package/src/ntk.d.ts +44 -0
  97. package/src/ntk.js +25 -0
  98. package/src/paintcache.js +366 -0
  99. package/src/palette.js +380 -0
  100. package/src/pastestate.js +66 -0
  101. package/src/portal.js +461 -0
  102. package/src/priority.js +26 -0
  103. package/src/refresh/index.d.ts +40 -0
  104. package/src/refresh/index.js +122 -0
  105. package/src/refresh/loader.d.ts +37 -0
  106. package/src/refresh/loader.js +401 -0
  107. package/src/refresh/register.d.ts +5 -0
  108. package/src/refresh/register.js +13 -0
  109. package/src/registry.js +232 -0
  110. package/src/scale.js +626 -0
  111. package/src/scalehooks.js +27 -0
  112. package/src/screencolor.js +640 -0
  113. package/src/screencolorhooks.js +101 -0
  114. package/src/screens.js +754 -0
  115. package/src/screenshooks.js +137 -0
  116. package/src/startup.js +302 -0
  117. package/src/style.d.ts +126 -0
  118. package/src/style.js +33 -0
  119. package/src/styles.js +1482 -6
  120. package/src/svgnodes.js +306 -0
  121. package/src/testing/a11y.js +484 -0
  122. package/src/testing/components.js +414 -0
  123. package/src/testing/events.js +407 -0
  124. package/src/testing/harness.js +455 -0
  125. package/src/testing/index.d.ts +558 -0
  126. package/src/testing/index.js +85 -0
  127. package/src/testing/mock-app.js +463 -0
  128. package/src/testing/pixels.js +152 -0
  129. package/src/testing/queries.js +224 -0
  130. package/src/textrange.js +83 -0
  131. package/src/textselection.js +439 -0
  132. package/src/trace-registry.js +63 -0
  133. package/src/transfer.js +93 -0
  134. package/src/types/appearance.d.ts +84 -0
  135. package/src/types/application.d.ts +173 -0
  136. package/src/types/components.d.ts +820 -0
  137. package/src/types/dbus.d.ts +177 -0
  138. package/src/types/elements.d.ts +897 -0
  139. package/src/types/events.d.ts +549 -0
  140. package/src/types/filedialog.d.ts +260 -0
  141. package/src/types/fonts.d.ts +124 -0
  142. package/src/types/frame.d.ts +146 -0
  143. package/src/types/globalmenu.d.ts +42 -0
  144. package/src/types/nodes.d.ts +199 -0
  145. package/src/types/screencolor.d.ts +84 -0
  146. package/src/types/style.d.ts +434 -0
  147. package/src/types/system.d.ts +287 -0
  148. package/src/windowid.js +151 -0
  149. package/src/windowstate.js +393 -0
  150. package/src/xsettings.js +336 -0
  151. package/src/yoga.d.ts +55 -0
  152. package/src/yoga.js +135 -0
  153. package/src/components/Canvas3D.js +0 -28
  154. package/src/geometry3d.js +0 -223
  155. package/src/pointer3d.js +0 -158
  156. package/src/raycast3d.js +0 -146
  157. package/src/richnodes.js +0 -436
  158. package/src/scene3d.js +0 -683
@@ -0,0 +1,199 @@
1
+ /**
2
+ * What a `ref` gives you. Drawn elements hand back their retained node;
3
+ * `<window>` and `<popup>` hand back the live ntk `Window`, so the whole
4
+ * ntk API is available from a ref.
5
+ */
6
+
7
+ /** A rectangle within the owning window, valid after layout. */
8
+ export interface Rect {
9
+ x: number;
10
+ y: number;
11
+ width: number;
12
+ height: number;
13
+ }
14
+
15
+ /** The retained node behind a drawn element. */
16
+ export interface DrawnNode {
17
+ /** Element name — `'box'`, `'text'`, and the name a registered element
18
+ * was registered under. What queries and paint order match on:
19
+ * `screen.all((n) => n.kind === 'gauge')`. */
20
+ readonly kind: string;
21
+ /** Position and size within the owning window, valid after layout. */
22
+ readonly abs: Rect;
23
+ readonly parent: DrawnNode | null;
24
+ readonly children: readonly DrawnNode[];
25
+ /** Take the keyboard focus, if this node is focusable. Returns the node,
26
+ * so a component can hand it straight out of an imperative handle. */
27
+ focus(): this;
28
+ blur(): this;
29
+ /** Whether this node has the owning window's focus. */
30
+ readonly focused: boolean;
31
+ /** Whether focus is on this node or inside it — CSS `:focus-within`. */
32
+ readonly focusWithin: boolean;
33
+ /**
34
+ * Which way this node reads, resolved — `'ltr'` or `'rtl'`, never
35
+ * `'inherit'`. The `direction` style property here or on the nearest
36
+ * element above, and the palette's under all of them.
37
+ *
38
+ * What a widget measuring a pointer against a laid-out box has to ask: a
39
+ * coordinate means the opposite thing in the two directions, so a drag
40
+ * reads this rather than the theme.
41
+ */
42
+ readonly direction: 'ltr' | 'rtl';
43
+ /** Whether `node` is this node or a descendant of it (DOM `contains`). */
44
+ contains(node: DrawnNode | null): boolean;
45
+ getClientRects(): Rect[];
46
+
47
+ // --- text geometry (docs/elements.md, "Selection") ------------------------
48
+ //
49
+ // Every drawn node answers these; an element with no text answers `null`,
50
+ // `0` and `[]`. Indices are **code points** and rectangles are in the
51
+ // owning window's coordinates — the same space as `abs` and a mouse
52
+ // event's `x`/`y`.
53
+
54
+ /** This element's text, or null when it has none. */
55
+ textContent(): string | null;
56
+ /** The character boundary nearest a point. Clamps to the ends. */
57
+ textIndexAt(x: number, y: number): number;
58
+ /** Where a caret at this index stands — a zero-width rect. */
59
+ textCaretRect(index: number): Rect | null;
60
+ /** The bands a highlight over `[start, end)` fills: one per line, and one
61
+ * per direction run within a line. */
62
+ textRangeRects(start: number, end: number): Rect[];
63
+ /** The part of this element's text the document selection covers. */
64
+ readonly selectionRange: { start: number; end: number } | null;
65
+ /** What to fill `textRangeRects` with while `selectionRange` is set. */
66
+ readonly selectionColor: string | null;
67
+
68
+ // --- being a selection surface (`selectable`) -----------------------------
69
+
70
+ /** The selection this element owns, or null when it is not `selectable`.
71
+ * A snapshot: read it again after a change. */
72
+ readonly textSelection: TextSelectionSnapshot | null;
73
+ /** Select everything in this surface, and take PRIMARY with it. */
74
+ selectAll(): this;
75
+ /** Drop the selection. PRIMARY is left where it is. */
76
+ clearSelection(): this;
77
+ /** What a copy would put on the clipboard. */
78
+ selectedText(): string;
79
+ /** Set both ends by hand. `setSelection(null)` clears. */
80
+ setSelection(anchor: TextPosition | null, focus?: TextPosition | null): this;
81
+ }
82
+
83
+ /** One end of a selection: a code-point index into an element's text. */
84
+ export interface TextPosition {
85
+ node: DrawnNode;
86
+ index: number;
87
+ }
88
+
89
+ /** What `node.selection` answers with. */
90
+ export interface TextSelectionSnapshot {
91
+ isCollapsed: boolean;
92
+ /** The assembled text, with the separators a copy would use. */
93
+ text: string;
94
+ /** Every element the selection reaches, in document order. */
95
+ ranges: readonly (TextPosition & { start: number; end: number })[];
96
+ }
97
+
98
+ export interface ScrollTarget {
99
+ x?: number;
100
+ y?: number;
101
+ }
102
+
103
+ /**
104
+ * What a `<box>` ref is: a drawn node that also scrolls. The scrolling half
105
+ * is live only while the node's style says `overflow: 'scroll'` — before
106
+ * that `scrollTo` has nowhere to go and the offsets stay 0.
107
+ */
108
+ export interface ScrollableNode extends DrawnNode {
109
+ readonly scrollX: number;
110
+ readonly scrollY: number;
111
+ readonly contentWidth: number;
112
+ readonly contentHeight: number;
113
+ /** A number scrolls the vertical axis; an object moves either or both. */
114
+ scrollTo(to: number | ScrollTarget): void;
115
+ scrollBy(by: number | ScrollTarget): void;
116
+ /**
117
+ * Is there room to move on the axis a delta names? What the wheel's
118
+ * default action asks before it scrolls this node instead of the next one
119
+ * out — see [extending.md](../../docs/extending.md).
120
+ */
121
+ canScroll(dx: number, dy: number): boolean;
122
+ /**
123
+ * Scroll the minimum amount on both axes that makes a descendant fully
124
+ * visible. Safe to call right after that node mounts — the request is
125
+ * resolved on the next layout pass, when it has geometry.
126
+ */
127
+ scrollIntoView(node: DrawnNode): void;
128
+ }
129
+
130
+ /** `<textinput>` / `<textarea>`. */
131
+ export interface TextInputNode extends DrawnNode {
132
+ /**
133
+ * The control's current text. Inside an `onChange` handler this is the
134
+ * value the edit produced, even in controlled mode — which is what makes
135
+ * `ev.target.value` mean what a DOM form library expects it to.
136
+ *
137
+ * Writable, as a DOM input's `value` is: assigning sets the text without
138
+ * firing `onChange`, and on a controlled input the next render puts
139
+ * `props.value` back. react-hook-form's `register()` resets a field this
140
+ * way.
141
+ */
142
+ value: string;
143
+ /** The `name` prop, for form libraries that key fields by it. */
144
+ readonly name?: string;
145
+ /**
146
+ * Step back one edit, as Ctrl+Z does. False when there is nothing to
147
+ * undo. Controlled inputs report the restored value through `onChange`,
148
+ * so the display follows the same round trip typing does.
149
+ */
150
+ undo(): boolean;
151
+ /** Step forward one undone edit, as Ctrl+Shift+Z does. */
152
+ redo(): boolean;
153
+ readonly canUndo: boolean;
154
+ readonly canRedo: boolean;
155
+ }
156
+
157
+ /**
158
+ * ntk's `Window`, as handed back by a `<window>` or `<popup>` ref. This
159
+ * covers what a react-x11 program usually reaches for; ntk has more (see
160
+ * its docs/window.md), and the index signature keeps the rest reachable
161
+ * without pretending this is a full description of the class.
162
+ */
163
+ export interface NtkWindow {
164
+ readonly id: number;
165
+ width: number;
166
+ height: number;
167
+ x: number;
168
+ y: number;
169
+ map(): void;
170
+ unmap(): void;
171
+ raise(): NtkWindow;
172
+ lower(): NtkWindow;
173
+ move(x: number, y: number): void;
174
+ resize(width: number, height: number): void;
175
+ moveResize(x: number, y: number, width: number, height: number): void;
176
+ setTitle(title: string): NtkWindow;
177
+ setCursor(name: string | null): NtkWindow;
178
+ focus(revertTo?: number): NtkWindow;
179
+ getContext(name: '2d' | 'opengl' | 'x11', ...args: unknown[]): unknown;
180
+ requestAnimationFrame(cb: (time: number) => void): number;
181
+ cancelAnimationFrame(id: number): void;
182
+ destroy(): void;
183
+ on(event: string, handler: (...args: any[]) => void): unknown;
184
+ off?(event: string, handler: (...args: any[]) => void): unknown;
185
+ [key: string]: any;
186
+ }
187
+
188
+ /**
189
+ * An ntk `App` — the X connection. `createRoot()` makes one for you; pass
190
+ * your own to render into an existing connection.
191
+ */
192
+ export interface NtkApp {
193
+ readonly X: any;
194
+ readonly display: any;
195
+ createWindow(args?: Record<string, unknown>): NtkWindow;
196
+ rootWindow(screen?: number): NtkWindow;
197
+ close(): Promise<void>;
198
+ [key: string]: any;
199
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Sampling a colour from the screen — the eyedropper. See docs/eyedropper.md.
3
+ */
4
+
5
+ import type { AbortSignalLike, WindowTarget } from './filedialog.js';
6
+ import type { NtkApp } from './nodes.js';
7
+
8
+ /** Which rung of the ladder answered — or would. */
9
+ export type ScreenColorBackend = 'portal' | 'x11';
10
+
11
+ export interface PickScreenColorOptions {
12
+ /**
13
+ * The window the picker belongs to — `parent_window` for the portal, and
14
+ * (when it points at a mounted node) the connection the X11 rung grabs on.
15
+ * `useEyedropper()` infers it from the tree.
16
+ */
17
+ parentWindow?: WindowTarget;
18
+ /** Abort the pick. Closes the portal request, or releases the X11 grab —
19
+ * the grab is released **before** the rejection is reported. */
20
+ signal?: AbortSignalLike;
21
+ /** Force a rung, for kiosks and for tests. */
22
+ backend?: ScreenColorBackend;
23
+ /**
24
+ * The connection the X11 rung grabs and reads on. Required for that rung
25
+ * when `parentWindow` does not resolve to a mounted node — the hook passes
26
+ * the tree's own.
27
+ */
28
+ app?: NtkApp;
29
+ }
30
+
31
+ /**
32
+ * Nothing here can sample the screen, and nothing can be drawn instead. A
33
+ * **typed** rejection — the `NoFileDialogError` rule — so a caller hides its
34
+ * eyedropper button rather than crashing; `useEyedropper().supported` is
35
+ * that branch made render state.
36
+ */
37
+ export declare class NoScreenColorError extends Error {
38
+ readonly name: 'NoScreenColorError';
39
+ readonly cause?: unknown;
40
+ }
41
+
42
+ /**
43
+ * Sample one pixel from the screen: the desktop's own picker
44
+ * (`org.freedesktop.portal.Screenshot.PickColor`, Screenshot interface
45
+ * version 2) where there is one, a crosshair pointer grab on plain X11
46
+ * everywhere else.
47
+ *
48
+ * Resolves to `'#rrggbb'`, or `null` when the user cancelled — Escape on the
49
+ * X11 rung, the dialog's own cancel on the portal. Rejects with
50
+ * {@link NoScreenColorError} when neither rung is reachable.
51
+ */
52
+ export declare function pickScreenColor(
53
+ options?: PickScreenColorOptions,
54
+ ): Promise<string | null>;
55
+
56
+ /**
57
+ * Which rung this machine lands on, without grabbing anything. `'x11'` needs
58
+ * a connection to answer with — pass `app`, or a `parentWindow` pointing at
59
+ * a mounted node — and `null` means {@link pickScreenColor} would reject.
60
+ */
61
+ export declare function screenColorBackend(
62
+ options?: Pick<PickScreenColorOptions, 'app' | 'backend' | 'parentWindow'>,
63
+ ): Promise<ScreenColorBackend | null>;
64
+
65
+ export interface Eyedropper {
66
+ /**
67
+ * Start a pick. `'#rrggbb'`, or `null` when cancelled. While one is in
68
+ * flight, another call returns the **same promise** rather than queueing a
69
+ * second grab.
70
+ */
71
+ pick(options?: Omit<PickScreenColorOptions, 'app'>): Promise<string | null>;
72
+ /** `screenColorBackend()` resolved, for hiding or disabling the button. */
73
+ supported: boolean;
74
+ /** A pick is in flight — the button's pressed state. */
75
+ picking: boolean;
76
+ }
77
+
78
+ /**
79
+ * The eyedropper for a component: the tree's connection and owner window
80
+ * bound once, `picking` and `supported` as render state.
81
+ */
82
+ export declare function useEyedropper(
83
+ defaults?: Omit<PickScreenColorOptions, 'app'>,
84
+ ): Eyedropper;