react-x11 2.11.0 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +278 -129
- package/package.json +10 -3
- package/src/Reconciler.js +15 -17
- package/src/a11y.js +2 -2
- package/src/anchor.js +7 -5
- package/src/bootstrap.js +14 -0
- package/src/clientmessage.js +1 -1
- package/src/cocoa/app.js +292 -49
- package/src/cocoa/bezels.js +175 -30
- package/src/cocoa/dnd.js +27 -13
- package/src/cocoa/fonts.js +3 -3
- package/src/cocoa/glarea.js +20 -3
- package/src/cocoa/main.d.ts +8 -0
- package/src/cocoa/main.js +43 -0
- package/src/cocoa/panehost.js +15 -5
- package/src/cocoa/presenter.js +13 -9
- package/src/cocoa/promotion.js +4 -7
- package/src/cocoa/relaunch.js +207 -0
- package/src/cocoa/threaded.js +246 -0
- package/src/cocoa/window.js +256 -42
- package/src/components/Select.js +2 -2
- package/src/components/anchor.js +3 -3
- package/src/components/native.js +12 -7
- package/src/components/theme.js +2 -2
- package/src/debug.js +1 -1
- package/src/decorations.js +1 -1
- package/src/editmenu.js +2 -2
- package/src/errors.js +46 -0
- package/src/events.js +6 -6
- package/src/foreignnodes.js +3 -2
- package/src/frames.js +2 -2
- package/src/glnodes.js +1 -1
- package/src/grid.js +1653 -0
- package/src/host.d.ts +230 -0
- package/src/host.js +11 -3
- package/src/imagesource.js +1 -1
- package/src/index.d.ts +21 -4
- package/src/index.js +9 -1
- package/src/layouts.js +721 -0
- package/src/node.d.ts +4 -2
- package/src/node.js +19 -21
- package/src/nodes/animation.js +644 -0
- package/src/nodes/box.js +21 -0
- package/src/nodes/boxpaint.js +473 -0
- package/src/nodes/canvas.js +269 -0
- package/src/nodes/cascade.js +600 -0
- package/src/nodes/damage.js +183 -0
- package/src/nodes/edithistory.js +124 -0
- package/src/nodes/editmenupopup.js +260 -0
- package/src/nodes/hittest.js +185 -0
- package/src/nodes/image.js +266 -0
- package/src/nodes/install.js +75 -0
- package/src/nodes/invalidate.js +465 -0
- package/src/nodes/kinds.js +31 -0
- package/src/nodes/layout.js +439 -0
- package/src/nodes/layouthost.js +949 -0
- package/src/nodes/node.js +868 -0
- package/src/nodes/paint.js +466 -0
- package/src/nodes/position.js +366 -0
- package/src/nodes/preedit.js +127 -0
- package/src/nodes/queries.js +330 -0
- package/src/nodes/rects.js +102 -0
- package/src/nodes/scrollable.js +891 -0
- package/src/nodes/scrollbars.js +138 -0
- package/src/nodes/scrollblit.js +1034 -0
- package/src/nodes/selectable.js +142 -0
- package/src/nodes/styling.js +225 -0
- package/src/nodes/text.js +649 -0
- package/src/nodes/textarea.js +391 -0
- package/src/nodes/textinput.js +1146 -0
- package/src/nodes/util.js +17 -0
- package/src/nodes/window/anchoring.js +161 -0
- package/src/nodes/window/capabilities.js +190 -0
- package/src/nodes/window/debugpaint.js +83 -0
- package/src/nodes/window/droptarget.js +145 -0
- package/src/nodes/window/floors.js +577 -0
- package/src/nodes/window/flush.js +334 -0
- package/src/nodes/window/hints.js +482 -0
- package/src/nodes/window/listeners.js +222 -0
- package/src/nodes/window/popup.js +71 -0
- package/src/nodes/window/size.js +591 -0
- package/src/nodes/window/window.js +945 -0
- package/src/palette.js +1 -1
- package/src/registry.js +7 -3
- package/src/styles.js +137 -15
- package/src/svgnodes.js +2 -1
- package/src/testing/harness.js +2 -2
- package/src/textselection.js +5 -3
- package/src/trace-registry.js +1 -1
- package/src/types/components.d.ts +38 -6
- package/src/types/elements.d.ts +11 -1
- package/src/types/nodes.d.ts +17 -2
- package/src/types/style.d.ts +94 -3
- package/src/windowstate.js +1 -1
- package/src/yoga.js +1 -1
- package/src/nodes.js +0 -13120
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// Scrollbar geometry: the track, the thumb, the hit test and the thumb's
|
|
2
|
+
// paint — shared by the Scrollable mixin, <textarea>'s own bar and the
|
|
3
|
+
// window's scroll blit.
|
|
4
|
+
|
|
5
|
+
import { insetRect } from './rects.js';
|
|
6
|
+
|
|
7
|
+
/** The full track strip a scrollbar occupies (thumb travel included), with
|
|
8
|
+
* a pixel of slop for the thumb's antialiased corners. */
|
|
9
|
+
export function scrollbarTrackRect(bar) {
|
|
10
|
+
const width = SCROLLBAR_WIDTH * (bar.scale ?? 1);
|
|
11
|
+
const rect =
|
|
12
|
+
bar.axis === 'x'
|
|
13
|
+
? {
|
|
14
|
+
x: bar.trackStart,
|
|
15
|
+
y: bar.crossStart,
|
|
16
|
+
width: bar.trackLength,
|
|
17
|
+
height: width,
|
|
18
|
+
}
|
|
19
|
+
: {
|
|
20
|
+
x: bar.crossStart,
|
|
21
|
+
y: bar.trackStart,
|
|
22
|
+
width,
|
|
23
|
+
height: bar.trackLength,
|
|
24
|
+
};
|
|
25
|
+
return insetRect(rect, -1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const SCROLLBAR_WIDTH = 6;
|
|
29
|
+
const SCROLLBAR_MIN_THUMB = 20;
|
|
30
|
+
// the visible bar is thin; the pointer target is not
|
|
31
|
+
const SCROLLBAR_SLOP = 4;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Geometry of a scrollbar on either axis, or null when there is nothing to
|
|
35
|
+
* scroll along it. Shared by scrolling boxes and `<textarea>` so what is
|
|
36
|
+
* painted and what the pointer hits cannot drift apart — and written once
|
|
37
|
+
* for both axes so the two cannot drift from each other either.
|
|
38
|
+
*
|
|
39
|
+
* `viewport`/`content`/`scroll` are along the axis; `across`/`crossSize`
|
|
40
|
+
* place the bar on the other one. `shorten` keeps the two bars out of each
|
|
41
|
+
* other's corner when both are showing.
|
|
42
|
+
*
|
|
43
|
+
* `direction` mirrors both of those. A vertical bar sits on the **left** in
|
|
44
|
+
* an RTL viewport — every desktop does this, and it is not decoration: the
|
|
45
|
+
* bar belongs on the edge the eye finishes a line at. And a horizontal bar's
|
|
46
|
+
* thumb starts at the right, because `scroll` is measured from the start of
|
|
47
|
+
* the content and the start of RTL content is its right-hand edge.
|
|
48
|
+
*/
|
|
49
|
+
export function scrollbarGeometry({
|
|
50
|
+
axis = 'y',
|
|
51
|
+
start,
|
|
52
|
+
viewport,
|
|
53
|
+
content,
|
|
54
|
+
across: crossStart0,
|
|
55
|
+
crossSize,
|
|
56
|
+
scroll,
|
|
57
|
+
inset = 0,
|
|
58
|
+
shorten = 0,
|
|
59
|
+
direction = 'ltr',
|
|
60
|
+
scale = 1,
|
|
61
|
+
}) {
|
|
62
|
+
const length = viewport - shorten;
|
|
63
|
+
if (length <= 0 || !(content > viewport)) return null;
|
|
64
|
+
// The strip's own dimensions are logical constants; everything the caller
|
|
65
|
+
// passed — rects, content extents, offsets — is already device. The bar
|
|
66
|
+
// carries `scale` so the track, the hit slop and the thumb's corner
|
|
67
|
+
// radius downstream draw from the same number.
|
|
68
|
+
const barWidth = SCROLLBAR_WIDTH * scale;
|
|
69
|
+
const rtl = direction === 'rtl';
|
|
70
|
+
const thumbLength = Math.max(
|
|
71
|
+
SCROLLBAR_MIN_THUMB * scale,
|
|
72
|
+
(length * length) / content,
|
|
73
|
+
);
|
|
74
|
+
const range = content - viewport;
|
|
75
|
+
const travel = Math.max(0, length - thumbLength);
|
|
76
|
+
const offset = range > 0 ? (scroll / range) * travel : 0;
|
|
77
|
+
// a vertical bar always fills from the top; only the horizontal one runs
|
|
78
|
+
// the way the text does
|
|
79
|
+
const thumbStart =
|
|
80
|
+
rtl && axis === 'x' ? start + travel - offset : start + offset;
|
|
81
|
+
const crossStart =
|
|
82
|
+
rtl && axis === 'y'
|
|
83
|
+
? crossStart0 + inset
|
|
84
|
+
: crossStart0 + crossSize - barWidth - inset;
|
|
85
|
+
return {
|
|
86
|
+
axis,
|
|
87
|
+
scale,
|
|
88
|
+
trackStart: start,
|
|
89
|
+
trackLength: length,
|
|
90
|
+
thumbStart,
|
|
91
|
+
thumbLength,
|
|
92
|
+
crossStart,
|
|
93
|
+
range,
|
|
94
|
+
travel,
|
|
95
|
+
// does a larger `scroll` move the thumb *towards* trackStart? The one
|
|
96
|
+
// place the mirroring is written down, so the drag and the track-page
|
|
97
|
+
// below read it rather than asking about the direction again
|
|
98
|
+
reversed: rtl && axis === 'x',
|
|
99
|
+
// the thumb as a rect, for painting
|
|
100
|
+
x: axis === 'x' ? thumbStart : crossStart,
|
|
101
|
+
y: axis === 'x' ? crossStart : thumbStart,
|
|
102
|
+
width: axis === 'x' ? thumbLength : barWidth,
|
|
103
|
+
height: axis === 'x' ? barWidth : thumbLength,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The coordinate along a bar's own axis, and across it. */
|
|
108
|
+
export const along = (bar, x, y) => (bar.axis === 'x' ? x : y);
|
|
109
|
+
const across = (bar, x, y) => (bar.axis === 'x' ? y : x);
|
|
110
|
+
|
|
111
|
+
/** Is this point on the bar (with slop), and if so, on the thumb? */
|
|
112
|
+
export function scrollbarHit(bar, x, y) {
|
|
113
|
+
if (!bar) return null;
|
|
114
|
+
const c = across(bar, x, y);
|
|
115
|
+
const s = bar.scale ?? 1;
|
|
116
|
+
if (
|
|
117
|
+
c < bar.crossStart - SCROLLBAR_SLOP * s ||
|
|
118
|
+
c > bar.crossStart + (SCROLLBAR_WIDTH + SCROLLBAR_SLOP) * s
|
|
119
|
+
) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
const a = along(bar, x, y);
|
|
123
|
+
if (a < bar.trackStart || a > bar.trackStart + bar.trackLength) return null;
|
|
124
|
+
return a >= bar.thumbStart && a <= bar.thumbStart + bar.thumbLength
|
|
125
|
+
? 'thumb'
|
|
126
|
+
: 'track';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function paintScrollbarThumb(ctx, bar, color) {
|
|
130
|
+
ctx.fillStyle = color || 'rgba(0, 0, 0, 0.25)';
|
|
131
|
+
ctx.beginPath();
|
|
132
|
+
if (typeof ctx.roundRect === 'function') {
|
|
133
|
+
ctx.roundRect(bar.x, bar.y, bar.width, bar.height, 3 * (bar.scale ?? 1));
|
|
134
|
+
} else {
|
|
135
|
+
ctx.rect(bar.x, bar.y, bar.width, bar.height);
|
|
136
|
+
}
|
|
137
|
+
ctx.fill();
|
|
138
|
+
}
|