@wailsio/runtime 3.0.0-alpha.97 → 3.0.0-alpha2.117
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/appregion.js +187 -0
- package/dist/drag.js +6 -0
- package/dist/index.js +1 -0
- package/package.json +7 -2
- package/types/appregion.d.ts +1 -0
- package/types/index.d.ts +1 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
import { invoke } from "./system.js";
|
|
11
|
+
import { whenReady } from "./utils.js";
|
|
12
|
+
import { hasDOM } from "./environment.js";
|
|
13
|
+
/*
|
|
14
|
+
--wails-non-client-region: caption; marks an area that can drag the window
|
|
15
|
+
--wails-non-client-region: minimize; marks a custom minimize button
|
|
16
|
+
--wails-non-client-region: maximize; marks a custom maximize button
|
|
17
|
+
--wails-non-client-region: close; marks a custom close button
|
|
18
|
+
*/
|
|
19
|
+
const regionProperty = "--wails-non-client-region";
|
|
20
|
+
const runtimeConfigReadyEvent = "wails:runtime-config-ready";
|
|
21
|
+
const validRegions = new Set(["caption", "minimize", "maximize", "close"]);
|
|
22
|
+
// Setup
|
|
23
|
+
if (hasDOM) {
|
|
24
|
+
window._wails = window._wails || {};
|
|
25
|
+
}
|
|
26
|
+
let updatePending = false;
|
|
27
|
+
let lastPayload = "";
|
|
28
|
+
let observedElements = new Set();
|
|
29
|
+
let resizeObserver;
|
|
30
|
+
let trackingStarted = false;
|
|
31
|
+
function normaliseRegionKind(value) {
|
|
32
|
+
const region = value.trim().toLowerCase();
|
|
33
|
+
if (validRegions.has(region)) {
|
|
34
|
+
return region;
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
function nonClientRegionForElement(element) {
|
|
39
|
+
if (!(element instanceof HTMLElement)) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const style = window.getComputedStyle(element);
|
|
43
|
+
const region = normaliseRegionKind(style.getPropertyValue(regionProperty));
|
|
44
|
+
if (!region) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
const parent = element.parentElement;
|
|
48
|
+
if (parent) {
|
|
49
|
+
const parentStyle = window.getComputedStyle(parent);
|
|
50
|
+
// The CSS property is inherited. Only report the outermost element for
|
|
51
|
+
// each contiguous region so native hit testing sees stable rectangles.
|
|
52
|
+
if (normaliseRegionKind(parentStyle.getPropertyValue(regionProperty)) === region) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return region;
|
|
57
|
+
}
|
|
58
|
+
function isVisible(element) {
|
|
59
|
+
const style = window.getComputedStyle(element);
|
|
60
|
+
return style.display !== "none" &&
|
|
61
|
+
style.visibility !== "hidden" &&
|
|
62
|
+
style.contentVisibility !== "hidden";
|
|
63
|
+
}
|
|
64
|
+
function elementRegion(element) {
|
|
65
|
+
if (!(element instanceof HTMLElement)) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
const kind = nonClientRegionForElement(element);
|
|
69
|
+
if (!kind || !isVisible(element)) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
const rect = element.getBoundingClientRect();
|
|
73
|
+
if (rect.width <= 0 || rect.height <= 0) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
// Native hit testing runs in physical pixels, while DOM geometry is in CSS pixels.
|
|
77
|
+
const scale = window.devicePixelRatio || 1;
|
|
78
|
+
const left = Math.floor(rect.left * scale);
|
|
79
|
+
const top = Math.floor(rect.top * scale);
|
|
80
|
+
const right = Math.ceil(rect.right * scale);
|
|
81
|
+
const bottom = Math.ceil(rect.bottom * scale);
|
|
82
|
+
if (right <= left || bottom <= top) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
return { kind, left, top, right, bottom };
|
|
86
|
+
}
|
|
87
|
+
function regionElements() {
|
|
88
|
+
const elements = [];
|
|
89
|
+
if (document.documentElement) {
|
|
90
|
+
elements.push(document.documentElement);
|
|
91
|
+
}
|
|
92
|
+
if (document.body) {
|
|
93
|
+
elements.push(document.body);
|
|
94
|
+
// Append via a loop: spreading a huge NodeList into push() overflows
|
|
95
|
+
// the engine's argument limit on very large documents.
|
|
96
|
+
for (const element of document.body.querySelectorAll("*")) {
|
|
97
|
+
elements.push(element);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return elements;
|
|
101
|
+
}
|
|
102
|
+
function observeRegionElements(elements) {
|
|
103
|
+
if (typeof ResizeObserver === "undefined") {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
// Track size changes only for active region elements. DOM structure and style
|
|
107
|
+
// changes are covered by MutationObserver in startNonClientRegionTracking().
|
|
108
|
+
resizeObserver !== null && resizeObserver !== void 0 ? resizeObserver : (resizeObserver = new ResizeObserver(scheduleUpdate));
|
|
109
|
+
const nextElements = new Set(elements);
|
|
110
|
+
for (const element of observedElements) {
|
|
111
|
+
if (!nextElements.has(element)) {
|
|
112
|
+
resizeObserver.unobserve(element);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
for (const element of nextElements) {
|
|
116
|
+
if (!observedElements.has(element)) {
|
|
117
|
+
resizeObserver.observe(element);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
observedElements = nextElements;
|
|
121
|
+
}
|
|
122
|
+
function updateNonClientRegions() {
|
|
123
|
+
updatePending = false;
|
|
124
|
+
const elements = regionElements();
|
|
125
|
+
const regions = [];
|
|
126
|
+
const activeElements = [];
|
|
127
|
+
for (const element of elements) {
|
|
128
|
+
const region = elementRegion(element);
|
|
129
|
+
if (region) {
|
|
130
|
+
regions.push(region);
|
|
131
|
+
activeElements.push(element);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
observeRegionElements(activeElements);
|
|
135
|
+
const payload = JSON.stringify({ version: 1, regions });
|
|
136
|
+
if (payload === lastPayload) {
|
|
137
|
+
// Avoid sending duplicate native messages during resize or style churn.
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
lastPayload = payload;
|
|
141
|
+
invoke("wails:non-client-region:" + payload);
|
|
142
|
+
}
|
|
143
|
+
function scheduleUpdate() {
|
|
144
|
+
if (updatePending) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
// Batch region updates to animation frames so layout is measured once per frame.
|
|
148
|
+
updatePending = true;
|
|
149
|
+
window.requestAnimationFrame(updateNonClientRegions);
|
|
150
|
+
}
|
|
151
|
+
function startNonClientRegionTracking() {
|
|
152
|
+
var _a, _b;
|
|
153
|
+
if (trackingStarted) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
trackingStarted = true;
|
|
157
|
+
// Send an initial empty or populated region list once the DOM is ready.
|
|
158
|
+
scheduleUpdate();
|
|
159
|
+
const mutationObserver = new MutationObserver(scheduleUpdate);
|
|
160
|
+
mutationObserver.observe(document.documentElement, {
|
|
161
|
+
attributes: true,
|
|
162
|
+
childList: true,
|
|
163
|
+
subtree: true,
|
|
164
|
+
});
|
|
165
|
+
window.addEventListener("resize", scheduleUpdate);
|
|
166
|
+
window.addEventListener("scroll", scheduleUpdate, true);
|
|
167
|
+
(_a = window.visualViewport) === null || _a === void 0 ? void 0 : _a.addEventListener("resize", scheduleUpdate);
|
|
168
|
+
(_b = window.visualViewport) === null || _b === void 0 ? void 0 : _b.addEventListener("scroll", scheduleUpdate);
|
|
169
|
+
}
|
|
170
|
+
function tryStartNonClientRegionTracking() {
|
|
171
|
+
var _a, _b;
|
|
172
|
+
const os = (_a = window._wails.environment) === null || _a === void 0 ? void 0 : _a.OS;
|
|
173
|
+
if (os === undefined) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
const enabled = (_b = window._wails.flags) === null || _b === void 0 ? void 0 : _b.nonClientRegionTracking;
|
|
177
|
+
if (os === "windows") {
|
|
178
|
+
if (enabled === true) {
|
|
179
|
+
whenReady(startNonClientRegionTracking);
|
|
180
|
+
}
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
if (hasDOM && !tryStartNonClientRegionTracking()) {
|
|
186
|
+
window.addEventListener(runtimeConfigReadyEvent, tryStartNonClientRegionTracking, { once: true });
|
|
187
|
+
}
|
package/dist/drag.js
CHANGED
|
@@ -155,6 +155,12 @@ function primaryDown(event) {
|
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
if (resizeEdge) {
|
|
158
|
+
// Do not arm edge resize from synthesized presses observed on move/up:
|
|
159
|
+
// entering the window with the primary button already held should not
|
|
160
|
+
// steal another gesture into a resize.
|
|
161
|
+
if (event.type !== 'mousedown') {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
158
164
|
// Ready to resize if the primary button was pressed for the first time.
|
|
159
165
|
canResize = true;
|
|
160
166
|
// Do not start drag operations when on resize edges.
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wailsio/runtime",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.0-
|
|
4
|
+
"version": "3.0.0-alpha2.117",
|
|
5
5
|
"description": "Wails Runtime",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -31,8 +31,13 @@
|
|
|
31
31
|
],
|
|
32
32
|
"sideEffects": [
|
|
33
33
|
"./dist/index.js",
|
|
34
|
+
"./dist/appregion.js",
|
|
34
35
|
"./dist/contextmenu.js",
|
|
35
|
-
"./dist/drag.js"
|
|
36
|
+
"./dist/drag.js",
|
|
37
|
+
"./src/index.ts",
|
|
38
|
+
"./src/appregion.ts",
|
|
39
|
+
"./src/contextmenu.ts",
|
|
40
|
+
"./src/drag.ts"
|
|
36
41
|
],
|
|
37
42
|
"scripts": {
|
|
38
43
|
"check": "npx tsc --noEmit",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|