verstak 0.24.270 → 0.24.271
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/build/dist/source/html/El.d.ts +46 -20
- package/build/dist/source/html/El.js +170 -87
- package/build/dist/source/html/Elements.js +113 -65
- package/build/dist/source/html/Handlers.d.ts +1 -1
- package/build/dist/source/html/SplitViewMath.d.ts +15 -6
- package/build/dist/source/html/SplitViewMath.js +190 -123
- package/build/dist/source/html/api.d.ts +1 -0
- package/build/dist/source/html/api.js +1 -0
- package/build/dist/source/html/sensors/KeyboardSensor.d.ts +1 -0
- package/build/dist/source/html/sensors/KeyboardSensor.js +5 -0
- package/package.json +1 -1
|
@@ -1,31 +1,49 @@
|
|
|
1
1
|
import { ElLayoutInfo, InitialElLayoutInfo, SplitView } from "./El.js";
|
|
2
|
-
import { clamp } from "./ElUtils.js";
|
|
3
2
|
import { Drivers, isSplitViewPartition } from "./Elements.js";
|
|
3
|
+
import { clamp } from "./ElUtils.js";
|
|
4
|
+
const DEBUG = false;
|
|
5
|
+
const eps = 0.0001;
|
|
6
|
+
export function equal(a, b) {
|
|
7
|
+
return Math.abs(a - b) <= eps;
|
|
8
|
+
}
|
|
9
|
+
export function less(a, b) {
|
|
10
|
+
return b - a > eps;
|
|
11
|
+
}
|
|
12
|
+
export function greater(a, b) {
|
|
13
|
+
return a - b > eps;
|
|
14
|
+
}
|
|
4
15
|
export function relayoutUsingSplitter(splitViewNode, deltaPx, index, initialSizesPx, priorities) {
|
|
5
16
|
var _a, _b, _c, _d;
|
|
6
17
|
if (priorities === undefined) {
|
|
7
18
|
priorities = getPrioritiesForSplitter(index + 1, initialSizesPx.length);
|
|
8
19
|
}
|
|
9
20
|
const containerSizePx = splitViewNode.element.splitView === SplitView.horizontal
|
|
10
|
-
? (_b = (_a = splitViewNode.element.layoutInfo) === null || _a === void 0 ? void 0 : _a.
|
|
11
|
-
: (_d = (_c = splitViewNode.element.layoutInfo) === null || _c === void 0 ? void 0 : _c.
|
|
12
|
-
console.log(`(splitter) delta = ${deltaPx}, container = ${containerSizePx}, size = ${initialSizesPx.reduce((p, c) => p + c.sizePx, 0)}, index = ${index}`);
|
|
13
|
-
resizeUsingDelta(splitViewNode,
|
|
21
|
+
? (_b = (_a = splitViewNode.element.layoutInfo) === null || _a === void 0 ? void 0 : _a.contentSizeXpx) !== null && _b !== void 0 ? _b : 0
|
|
22
|
+
: (_d = (_c = splitViewNode.element.layoutInfo) === null || _c === void 0 ? void 0 : _c.contentSizeYpx) !== null && _d !== void 0 ? _d : 0;
|
|
23
|
+
DEBUG && console.log(`(splitter) delta = ${deltaPx}, container = ${containerSizePx}, size = ${initialSizesPx.reduce((p, c) => p + c.sizePx, 0)}, index = ${index}`);
|
|
24
|
+
resizeUsingDelta(splitViewNode, deltaPx, index + 1, priorities, initialSizesPx, true);
|
|
14
25
|
layout(splitViewNode);
|
|
15
26
|
}
|
|
16
|
-
export function relayout(splitViewNode, priorities, sizesPx) {
|
|
27
|
+
export function relayout(splitViewNode, priorities, manuallyResizablePriorities, sizesPx) {
|
|
17
28
|
var _a, _b, _c, _d;
|
|
18
29
|
const containerSizePx = splitViewNode.element.splitView === SplitView.horizontal
|
|
19
|
-
? (_b = (_a = splitViewNode.element.layoutInfo) === null || _a === void 0 ? void 0 : _a.
|
|
20
|
-
: (_d = (_c = splitViewNode.element.layoutInfo) === null || _c === void 0 ? void 0 : _c.
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
? (_b = (_a = splitViewNode.element.layoutInfo) === null || _a === void 0 ? void 0 : _a.contentSizeXpx) !== null && _b !== void 0 ? _b : 0
|
|
31
|
+
: (_d = (_c = splitViewNode.element.layoutInfo) === null || _c === void 0 ? void 0 : _c.contentSizeYpx) !== null && _d !== void 0 ? _d : 0;
|
|
32
|
+
const totalSizePx = sizesPx.reduce((p, c) => p + c.sizePx, 0);
|
|
33
|
+
let deltaPx = containerSizePx - totalSizePx;
|
|
34
|
+
DEBUG && console.log(printPriorities(priorities, manuallyResizablePriorities), "color: grey", "color:", "color: grey", "color:");
|
|
35
|
+
DEBUG && console.log(`(relayout) ∆ = ${n(deltaPx)}px, container = ${n(containerSizePx)}px, total = ${totalSizePx}`);
|
|
36
|
+
deltaPx = resizeUsingDelta(splitViewNode, deltaPx, sizesPx.length, priorities, sizesPx);
|
|
37
|
+
DEBUG && console.log(`(relayout) ~∆ = ${n(deltaPx)}, container = ${n(containerSizePx, 3)}px, total = ${n(sizesPx.reduce((p, c) => p + c.sizePx, 0), 3)}px`);
|
|
38
|
+
if (deltaPx < -(1 / devicePixelRatio)) {
|
|
39
|
+
DEBUG && console.log(`%c${deltaPx}px`, "color: lime");
|
|
40
|
+
resizeUsingDelta(splitViewNode, deltaPx, sizesPx.length, manuallyResizablePriorities, sizesPx, true);
|
|
41
|
+
}
|
|
24
42
|
layout(splitViewNode);
|
|
25
43
|
}
|
|
26
|
-
export function resizeUsingDelta(splitViewNode,
|
|
27
|
-
var _a, _b, _c, _d;
|
|
44
|
+
export function resizeUsingDelta(splitViewNode, deltaPx, index, priorities, sizesPx, force = false) {
|
|
28
45
|
const isHorizontal = splitViewNode.element.splitView === SplitView.horizontal;
|
|
46
|
+
let beforeDeltaPx = 0;
|
|
29
47
|
if (sizesPx.length > 0 && deltaPx !== 0) {
|
|
30
48
|
let minBeforeDeltaPx = 0;
|
|
31
49
|
let maxBeforeDeltaPx = 0;
|
|
@@ -45,93 +63,16 @@ export function resizeUsingDelta(splitViewNode, containerSizePx, deltaPx, index,
|
|
|
45
63
|
const minDeltaPx = Math.max(minBeforeDeltaPx, minAfterDeltaPx);
|
|
46
64
|
const maxDeltaPx = Math.min(maxBeforeDeltaPx, maxAfterDeltaPx);
|
|
47
65
|
const clampedDeltaPx = clamp(deltaPx, minDeltaPx, maxDeltaPx);
|
|
48
|
-
console.log(`%c${sizesPx.map((x, i) => {
|
|
66
|
+
DEBUG && console.log(`%c${sizesPx.map((x, i) => {
|
|
49
67
|
const size = isHorizontal ? x.node.element.widthPx : x.node.element.heightPx;
|
|
50
68
|
return `${i}: ${size.minPx}..${x.sizePx}..${size.maxPx} (px)`;
|
|
51
|
-
}).join("\n")}`, "color:
|
|
52
|
-
console.log(`[${Array.from({ length: index }).map((x, i) => i).join(",")} | ${Array.from({ length: Math.max(0, sizesPx.length - index) }).map((x, i) => index + i).join(",")}]
|
|
69
|
+
}).join("\n")}`, "color: skyblue");
|
|
70
|
+
DEBUG && console.log(`[%c${Array.from({ length: index }).map((x, i) => i).join(",")}%c | %c${Array.from({ length: Math.max(0, sizesPx.length - index) }).map((x, i) => index + i).join(",")}%c]\n∆ = ${n(minDeltaPx)}px..${n(deltaPx)}px -> %c${n(clampedDeltaPx)}px%c..${n(maxDeltaPx)}px`, "color: #00BB00", "color:", "color: orange", "color:", "color: yellow", "color:");
|
|
53
71
|
if (clampedDeltaPx !== 0) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
let beforeDeltaPx = clampedDeltaPx;
|
|
59
|
-
for (let priority = 0; priority < priorities.length; priority++) {
|
|
60
|
-
const vector = priorities[priority];
|
|
61
|
-
let fractionCount = getFractionCount(isHorizontal, sizesPx.map(x => x.node), vector, index, force);
|
|
62
|
-
do {
|
|
63
|
-
const fractionSizePx = getFractionSizePx(beforeDeltaPx, fractionCount);
|
|
64
|
-
fractionCount = 0;
|
|
65
|
-
for (const i of indexes(vector, index)) {
|
|
66
|
-
const child = sizesPx[i].node;
|
|
67
|
-
const initialSizePx = sizesPx[i].sizePx;
|
|
68
|
-
const g = isHorizontal ? ((_a = child.element.stretchingStrengthX) !== null && _a !== void 0 ? _a : 0) : ((_b = child.element.stretchingStrengthY) !== null && _b !== void 0 ? _b : 0);
|
|
69
|
-
const growth = g > 0 ? g : (force ? 1 : 0);
|
|
70
|
-
if (growth > 0)
|
|
71
|
-
lastGrowingElementIndex = i;
|
|
72
|
-
const appendagePx = growth * fractionSizePx;
|
|
73
|
-
const newSizePx = initialSizePx + appendagePx;
|
|
74
|
-
let flooredNewSizePx = Math.floor(newSizePx * devicePixelRatio) / devicePixelRatio;
|
|
75
|
-
runningReminderPx += newSizePx - flooredNewSizePx;
|
|
76
|
-
if (runningReminderPx >= res) {
|
|
77
|
-
runningReminderPx -= res;
|
|
78
|
-
flooredNewSizePx += res;
|
|
79
|
-
}
|
|
80
|
-
const size = isHorizontal ? sizesPx[i].node.element.widthPx : sizesPx[i].node.element.heightPx;
|
|
81
|
-
const sizePx = clamp(flooredNewSizePx, size.minPx, size.maxPx);
|
|
82
|
-
console.log(`[${i}]: min = ${size.minPx}, max = ${size.maxPx}, growth = ${growth}, flooredNewSizePx = ${flooredNewSizePx}, size = ${sizePx} px`);
|
|
83
|
-
beforeDeltaPx -= sizePx - initialSizePx;
|
|
84
|
-
sizesPx[i].sizePx = sizePx;
|
|
85
|
-
if (sizesPx[i].sizePx > size.minPx && sizesPx[i].sizePx < size.maxPx) {
|
|
86
|
-
fractionCount += growth;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} while (beforeDeltaPx > 0 && fractionCount > 0 && Math.abs(beforeDeltaPx) >= devicePixelRatio);
|
|
90
|
-
if (Math.abs(beforeDeltaPx) < devicePixelRatio) {
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (hasAfter) {
|
|
95
|
-
let runningReminderPx = 0;
|
|
96
|
-
let afterDeltaPx = clampedDeltaPx;
|
|
97
|
-
for (let priority = 0; priority < priorities.length; priority++) {
|
|
98
|
-
const vector = priorities[priority];
|
|
99
|
-
let fractionCount = getFractionCount(isHorizontal, sizesPx.map(x => x.node), vector, -index, force);
|
|
100
|
-
do {
|
|
101
|
-
const fractionSizePx = getFractionSizePx(afterDeltaPx, fractionCount);
|
|
102
|
-
fractionCount = 0;
|
|
103
|
-
for (const i of indexes(vector, -index)) {
|
|
104
|
-
const child = sizesPx[i].node;
|
|
105
|
-
const initialSizePx = sizesPx[i].sizePx;
|
|
106
|
-
const g = isHorizontal ? ((_c = child.element.stretchingStrengthX) !== null && _c !== void 0 ? _c : 0) : ((_d = child.element.stretchingStrengthY) !== null && _d !== void 0 ? _d : 0);
|
|
107
|
-
const growth = g > 0 ? g : (force ? 1 : 0);
|
|
108
|
-
if (growth > 0)
|
|
109
|
-
lastGrowingElementIndex = i;
|
|
110
|
-
const appendagePx = growth * fractionSizePx;
|
|
111
|
-
const newSizePx = initialSizePx - appendagePx;
|
|
112
|
-
let flooredNewSizePx = Math.floor(newSizePx * devicePixelRatio) / devicePixelRatio;
|
|
113
|
-
runningReminderPx += newSizePx - flooredNewSizePx;
|
|
114
|
-
if (runningReminderPx >= res) {
|
|
115
|
-
runningReminderPx -= res;
|
|
116
|
-
flooredNewSizePx += res;
|
|
117
|
-
}
|
|
118
|
-
const size = isHorizontal ? sizesPx[i].node.element.widthPx : sizesPx[i].node.element.heightPx;
|
|
119
|
-
const sizePx = clamp(flooredNewSizePx, size.minPx, size.maxPx);
|
|
120
|
-
afterDeltaPx += sizePx - initialSizePx;
|
|
121
|
-
sizesPx[i].sizePx = sizePx;
|
|
122
|
-
if (sizesPx[i].sizePx > size.minPx && sizesPx[i].sizePx < size.maxPx) {
|
|
123
|
-
fractionCount += growth;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
} while (afterDeltaPx > 0 && fractionCount > 0 && Math.abs(containerSizePx - sizesPx.reduce((p, c) => p + c.sizePx, 0)) >= devicePixelRatio);
|
|
127
|
-
if (Math.abs(containerSizePx - sizesPx.reduce((p, c) => p + c.sizePx, 0)) < devicePixelRatio) {
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (lastGrowingElementIndex !== undefined) {
|
|
133
|
-
}
|
|
134
|
-
}
|
|
72
|
+
if (index > 0)
|
|
73
|
+
beforeDeltaPx = distribute(1, clampedDeltaPx, index, priorities, sizesPx, isHorizontal, force);
|
|
74
|
+
if (hasAfter)
|
|
75
|
+
distribute(-1, clampedDeltaPx, index, priorities, sizesPx, isHorizontal, force);
|
|
135
76
|
}
|
|
136
77
|
}
|
|
137
78
|
for (let i = 0; i < sizesPx.length; i++) {
|
|
@@ -139,28 +80,58 @@ export function resizeUsingDelta(splitViewNode, containerSizePx, deltaPx, index,
|
|
|
139
80
|
if (el.layoutInfo === undefined)
|
|
140
81
|
el.layoutInfo = new ElLayoutInfo(InitialElLayoutInfo);
|
|
141
82
|
el.layoutInfo.effectiveSizePx = sizesPx[i].sizePx;
|
|
142
|
-
console.log(`[${i}]: set size = ${sizesPx[i].sizePx}px`);
|
|
83
|
+
DEBUG && console.log(`[${i}]: set size = ${n(sizesPx[i].sizePx)}px`);
|
|
143
84
|
}
|
|
85
|
+
return beforeDeltaPx;
|
|
144
86
|
}
|
|
145
87
|
export function layout(splitViewNode) {
|
|
146
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
88
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
147
89
|
const isHorizontal = splitViewNode.element.splitView === SplitView.horizontal;
|
|
148
90
|
let posPx = 0;
|
|
91
|
+
let shrinkBefore = false;
|
|
92
|
+
let growBefore = false;
|
|
93
|
+
let isSplitterEnabled = false;
|
|
149
94
|
const sizesPx = [];
|
|
150
|
-
const
|
|
151
|
-
const
|
|
95
|
+
const layoutInfo = splitViewNode.element.layoutInfo;
|
|
96
|
+
const offsetXpx = (_a = layoutInfo === null || layoutInfo === void 0 ? void 0 : layoutInfo.offsetXpx) !== null && _a !== void 0 ? _a : 0;
|
|
97
|
+
const offsetYpx = (_b = layoutInfo === null || layoutInfo === void 0 ? void 0 : layoutInfo.offsetYpx) !== null && _b !== void 0 ? _b : 0;
|
|
152
98
|
for (const item of splitViewNode.children.items()) {
|
|
153
99
|
const child = item.instance;
|
|
154
100
|
if (isSplitViewPartition(child.driver)) {
|
|
155
101
|
const el = child.element;
|
|
156
102
|
if (el.native !== undefined) {
|
|
157
|
-
|
|
158
|
-
|
|
103
|
+
const current = item;
|
|
104
|
+
const sizePx = isHorizontal ? el.widthPx : el.heightPx;
|
|
105
|
+
const effectiveSizePx = (_d = (_c = el.layoutInfo) === null || _c === void 0 ? void 0 : _c.effectiveSizePx) !== null && _d !== void 0 ? _d : 0;
|
|
106
|
+
posPx += effectiveSizePx;
|
|
107
|
+
sizesPx.push(effectiveSizePx);
|
|
108
|
+
el.native.setAttribute("rx-max", equal(effectiveSizePx, sizePx.maxPx) ? "true" : "false");
|
|
109
|
+
el.native.setAttribute("rx-min", equal(effectiveSizePx, sizePx.minPx) ? "true" : "false");
|
|
110
|
+
shrinkBefore || (shrinkBefore = greater(effectiveSizePx - sizePx.minPx, 0));
|
|
111
|
+
growBefore || (growBefore = greater(sizePx.maxPx - effectiveSizePx, 0));
|
|
112
|
+
let shrinkAfter = false;
|
|
113
|
+
let growAfter = false;
|
|
114
|
+
for (const item of splitViewNode.children.items(current)) {
|
|
115
|
+
const child = item.instance;
|
|
116
|
+
if (isSplitViewPartition(child.driver)) {
|
|
117
|
+
const el = child.element;
|
|
118
|
+
if (el.native !== undefined) {
|
|
119
|
+
const sizePx = isHorizontal ? el.widthPx : el.heightPx;
|
|
120
|
+
const effectiveSizePx = (_f = (_e = el.layoutInfo) === null || _e === void 0 ? void 0 : _e.effectiveSizePx) !== null && _f !== void 0 ? _f : 0;
|
|
121
|
+
shrinkAfter || (shrinkAfter = greater(effectiveSizePx - sizePx.minPx, 0));
|
|
122
|
+
growAfter || (growAfter = greater(sizePx.maxPx - effectiveSizePx, 0));
|
|
123
|
+
isSplitterEnabled = growBefore && shrinkAfter || growAfter && shrinkBefore;
|
|
124
|
+
if (isSplitterEnabled)
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
159
129
|
}
|
|
160
130
|
}
|
|
161
131
|
else if (child.driver === Drivers.splitter) {
|
|
162
132
|
const el = child.element;
|
|
163
133
|
if (el.native !== undefined) {
|
|
134
|
+
el.style.display = isSplitterEnabled ? "block" : "none";
|
|
164
135
|
if (isHorizontal)
|
|
165
136
|
el.style.left = `${offsetXpx + posPx}px`;
|
|
166
137
|
else
|
|
@@ -168,12 +139,23 @@ export function layout(splitViewNode) {
|
|
|
168
139
|
}
|
|
169
140
|
}
|
|
170
141
|
}
|
|
171
|
-
const
|
|
142
|
+
const containerSizePx = (_g = (isHorizontal ? layoutInfo === null || layoutInfo === void 0 ? void 0 : layoutInfo.contentSizeXpx : layoutInfo === null || layoutInfo === void 0 ? void 0 : layoutInfo.contentSizeYpx)) !== null && _g !== void 0 ? _g : 0;
|
|
143
|
+
const isOverflowing = greater(posPx, containerSizePx);
|
|
144
|
+
const wrapper = (_h = splitViewNode.children.firstMergedItem()) === null || _h === void 0 ? void 0 : _h.instance;
|
|
172
145
|
if (wrapper !== undefined) {
|
|
173
146
|
if (isHorizontal)
|
|
174
147
|
wrapper.element.style.gridTemplateColumns = sizesPx.map(x => `${x}px`).join(" ");
|
|
175
148
|
else
|
|
176
149
|
wrapper.element.style.gridTemplateRows = sizesPx.map(x => `${x}px`).join(" ");
|
|
150
|
+
if (isOverflowing) {
|
|
151
|
+
if (isHorizontal)
|
|
152
|
+
wrapper.element.style.overflow = "scroll hidden";
|
|
153
|
+
else
|
|
154
|
+
wrapper.element.style.overflow = "hidden scroll";
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
wrapper.element.style.overflow = "hidden";
|
|
158
|
+
}
|
|
177
159
|
}
|
|
178
160
|
}
|
|
179
161
|
export function getPrioritiesForSplitter(index, size) {
|
|
@@ -193,37 +175,56 @@ export function getPrioritiesForSplitter(index, size) {
|
|
|
193
175
|
}
|
|
194
176
|
return result;
|
|
195
177
|
}
|
|
196
|
-
export function getPrioritiesForSizeChanging(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
178
|
+
export function getPrioritiesForSizeChanging(isHorizontal, children, indexes) {
|
|
179
|
+
var _a, _b;
|
|
180
|
+
const resizable = [];
|
|
181
|
+
const manuallyResizable = [];
|
|
182
|
+
const items = Array.from(children.items()).filter(x => isSplitViewPartition(x.instance.driver));
|
|
183
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
184
|
+
const item = items[i];
|
|
185
|
+
const el = item.instance.element;
|
|
186
|
+
const strength = (_a = (isHorizontal ? el.stretchingStrengthX : el.stretchingStrengthY)) !== null && _a !== void 0 ? _a : 1;
|
|
187
|
+
if (!indexes.includes(i)) {
|
|
188
|
+
if (strength > 0)
|
|
189
|
+
resizable.push(1 << i);
|
|
204
190
|
else
|
|
205
|
-
|
|
206
|
-
i++;
|
|
191
|
+
manuallyResizable.push(1 << i);
|
|
207
192
|
}
|
|
208
193
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
194
|
+
for (const i of indexes) {
|
|
195
|
+
const item = items[i];
|
|
196
|
+
const el = item.instance.element;
|
|
197
|
+
const strength = (_b = (isHorizontal ? el.stretchingStrengthX : el.stretchingStrengthY)) !== null && _b !== void 0 ? _b : 1;
|
|
198
|
+
if (strength > 0)
|
|
199
|
+
resizable.push(1 << i);
|
|
200
|
+
else
|
|
201
|
+
manuallyResizable.push(1 << i);
|
|
202
|
+
}
|
|
203
|
+
return { resizable, manuallyResizable };
|
|
212
204
|
}
|
|
213
|
-
export function getPrioritiesForEmptySpaceDistribution(children) {
|
|
214
|
-
|
|
205
|
+
export function getPrioritiesForEmptySpaceDistribution(isHorizontal, children) {
|
|
206
|
+
var _a;
|
|
207
|
+
let r = 0;
|
|
208
|
+
let mr = 0;
|
|
215
209
|
let i = 0;
|
|
216
210
|
for (const child of children.items()) {
|
|
217
|
-
if (isSplitViewPartition(child.instance.driver))
|
|
218
|
-
|
|
211
|
+
if (isSplitViewPartition(child.instance.driver)) {
|
|
212
|
+
const el = child.instance.element;
|
|
213
|
+
const strength = (_a = (isHorizontal ? el.stretchingStrengthX : el.stretchingStrengthY)) !== null && _a !== void 0 ? _a : 1;
|
|
214
|
+
if (strength > 0)
|
|
215
|
+
r |= 1 << i;
|
|
216
|
+
else
|
|
217
|
+
mr |= 1 << i;
|
|
218
|
+
i++;
|
|
219
|
+
}
|
|
219
220
|
}
|
|
220
|
-
return [
|
|
221
|
+
return { resizable: [r], manuallyResizable: [mr] };
|
|
221
222
|
}
|
|
222
223
|
function getFractionCount(isHorizontal, children, vector, index, force = false) {
|
|
223
224
|
var _a;
|
|
224
225
|
let result = 0;
|
|
225
226
|
for (const i of indexes(vector, index)) {
|
|
226
|
-
const growth = (_a = (isHorizontal ? children[i].element.stretchingStrengthX : children[i].element.stretchingStrengthY)) !== null && _a !== void 0 ? _a :
|
|
227
|
+
const growth = (_a = (isHorizontal ? children[i].element.stretchingStrengthX : children[i].element.stretchingStrengthY)) !== null && _a !== void 0 ? _a : 1;
|
|
227
228
|
result += growth > 0 ? growth : (force ? 1 : 0);
|
|
228
229
|
}
|
|
229
230
|
return result;
|
|
@@ -254,3 +255,69 @@ function* indexes(vector, index) {
|
|
|
254
255
|
}
|
|
255
256
|
}
|
|
256
257
|
}
|
|
258
|
+
function n(value, fractionDigits = 2) {
|
|
259
|
+
return value === 0 ? "0" : value.toFixed(fractionDigits);
|
|
260
|
+
}
|
|
261
|
+
function distribute(sign, deltaPx, index, priorities, sizesPx, isHorizontal, force) {
|
|
262
|
+
var _a, _b;
|
|
263
|
+
for (let priority = 0; priority < priorities.length; priority++) {
|
|
264
|
+
const vector = priorities[priority];
|
|
265
|
+
let fractionCount = getFractionCount(isHorizontal, sizesPx.map(x => x.node), vector, sign * index, force);
|
|
266
|
+
do {
|
|
267
|
+
const fractionSizePx = getFractionSizePx(deltaPx, fractionCount);
|
|
268
|
+
fractionCount = 0;
|
|
269
|
+
for (const i of indexes(vector, sign * index)) {
|
|
270
|
+
const child = sizesPx[i].node;
|
|
271
|
+
const initialSizePx = sizesPx[i].sizePx;
|
|
272
|
+
const strength = isHorizontal ? ((_a = child.element.stretchingStrengthX) !== null && _a !== void 0 ? _a : 1) : ((_b = child.element.stretchingStrengthY) !== null && _b !== void 0 ? _b : 1);
|
|
273
|
+
const growth = strength > 0 ? strength : (force ? 1 : 0);
|
|
274
|
+
const newSizePx = initialSizePx + sign * (growth * fractionSizePx);
|
|
275
|
+
const size = isHorizontal ? sizesPx[i].node.element.widthPx : sizesPx[i].node.element.heightPx;
|
|
276
|
+
const sizePx = clamp(newSizePx, size.minPx, size.maxPx);
|
|
277
|
+
deltaPx = deltaPx - sign * (sizePx - initialSizePx);
|
|
278
|
+
sizesPx[i].sizePx = sizePx;
|
|
279
|
+
if (sizesPx[i].sizePx > size.minPx && sizesPx[i].sizePx < size.maxPx) {
|
|
280
|
+
fractionCount += growth;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
} while (Math.abs(deltaPx) > eps && fractionCount > 0);
|
|
284
|
+
if (Math.abs(deltaPx) <= eps) {
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return deltaPx;
|
|
289
|
+
}
|
|
290
|
+
function printPriorities(priorities, manuallyResizablePriorities) {
|
|
291
|
+
let text = "";
|
|
292
|
+
if (priorities.length > 0) {
|
|
293
|
+
text += `Automatically Resizable:\n%c(${priorities.map(x => `0x${x.toString(2)}`).join(", ")})%c\n`;
|
|
294
|
+
for (let i = 0; i < priorities.length; i++) {
|
|
295
|
+
let vector = priorities[i];
|
|
296
|
+
const parts = [];
|
|
297
|
+
let j = 0;
|
|
298
|
+
while (vector) {
|
|
299
|
+
if (vector & 1)
|
|
300
|
+
parts.push(j);
|
|
301
|
+
j++;
|
|
302
|
+
vector >>= 1;
|
|
303
|
+
}
|
|
304
|
+
text += `${i}: ${parts.join(", ")}\n`;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (manuallyResizablePriorities.length > 0) {
|
|
308
|
+
text += `Manually Resizable:\n%c(${manuallyResizablePriorities.map(x => `0x${x.toString(2)}`).join(", ")})%c\n`;
|
|
309
|
+
for (let i = 0; i < manuallyResizablePriorities.length; i++) {
|
|
310
|
+
let vector = manuallyResizablePriorities[i];
|
|
311
|
+
const parts = [];
|
|
312
|
+
let j = 0;
|
|
313
|
+
while (vector) {
|
|
314
|
+
if (vector & 1)
|
|
315
|
+
parts.push(j);
|
|
316
|
+
j++;
|
|
317
|
+
vector >>= 1;
|
|
318
|
+
}
|
|
319
|
+
text += `${i}: ${parts.join(", ")}\n`;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return text;
|
|
323
|
+
}
|
|
@@ -6,6 +6,7 @@ export * from "./HtmlApiExt.js";
|
|
|
6
6
|
export * from "./Elements.js";
|
|
7
7
|
export * from "./Handlers.js";
|
|
8
8
|
export * from "./Sizes.js";
|
|
9
|
+
export * from "./SplitViewMath.js";
|
|
9
10
|
export * from "./sensors/Sensor.js";
|
|
10
11
|
export * from "./sensors/PointerSensor.js";
|
|
11
12
|
export * from "./sensors/BasePointerSensor.js";
|
|
@@ -6,6 +6,7 @@ export * from "./HtmlApiExt.js";
|
|
|
6
6
|
export * from "./Elements.js";
|
|
7
7
|
export * from "./Handlers.js";
|
|
8
8
|
export * from "./Sizes.js";
|
|
9
|
+
export * from "./SplitViewMath.js";
|
|
9
10
|
export * from "./sensors/Sensor.js";
|
|
10
11
|
export * from "./sensors/PointerSensor.js";
|
|
11
12
|
export * from "./sensors/BasePointerSensor.js";
|
|
@@ -25,6 +25,7 @@ export declare class KeyboardSensor extends HtmlElementSensor {
|
|
|
25
25
|
reset(): void;
|
|
26
26
|
protected onKeyDown(e: KeyboardEvent): void;
|
|
27
27
|
protected onKeyUp(e: KeyboardEvent): void;
|
|
28
|
+
protected doWindowBlur(e: FocusEvent): void;
|
|
28
29
|
protected keyDown(e: KeyboardEvent): void;
|
|
29
30
|
protected keyUp(e: KeyboardEvent): void;
|
|
30
31
|
protected updateSensorData(e: KeyboardEvent): void;
|
|
@@ -40,10 +40,12 @@ export class KeyboardSensor extends HtmlElementSensor {
|
|
|
40
40
|
if (enabled) {
|
|
41
41
|
element.addEventListener("keydown", this.onKeyDown.bind(this), { capture: true });
|
|
42
42
|
element.addEventListener("keyup", this.onKeyUp.bind(this), { capture: true });
|
|
43
|
+
window.addEventListener("blur", this.doWindowBlur.bind(this), { capture: true });
|
|
43
44
|
}
|
|
44
45
|
else {
|
|
45
46
|
element.removeEventListener("keydown", this.onKeyDown.bind(this), { capture: true });
|
|
46
47
|
element.removeEventListener("keyup", this.onKeyUp.bind(this), { capture: true });
|
|
48
|
+
window.removeEventListener("blur", this.doWindowBlur.bind(this), { capture: true });
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
reset() {
|
|
@@ -61,6 +63,9 @@ export class KeyboardSensor extends HtmlElementSensor {
|
|
|
61
63
|
this.keyUp(e);
|
|
62
64
|
this.setPreventDefaultAndStopPropagation(e);
|
|
63
65
|
}
|
|
66
|
+
doWindowBlur(e) {
|
|
67
|
+
this.reset();
|
|
68
|
+
}
|
|
64
69
|
keyDown(e) {
|
|
65
70
|
this.updateSensorData(e);
|
|
66
71
|
this.up = "";
|