laymur 0.1.72 → 0.2.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 +16 -0
- package/dist/Passes/UIPass.d.ts +2 -2
- package/dist/{Builders → builders}/UIConstraint2DBuilder.d.ts +14 -14
- package/dist/{Builders → builders}/UIConstraintContainerBuilder.d.ts +5 -5
- package/dist/{Builders → builders}/UIConstraintStackBuilder.d.ts +7 -7
- package/dist/{Constraints → constraints}/UIAspectConstraint.d.ts +5 -5
- package/dist/{Constraints → constraints}/UIConstraint.d.ts +3 -3
- package/dist/{Constraints → constraints}/UIConstraintRule.d.ts +1 -1
- package/dist/{Constraints → constraints}/UICoverConstraint.d.ts +6 -6
- package/dist/{Constraints → constraints}/UIFitConstraint.d.ts +6 -6
- package/dist/{Constraints → constraints}/UIHeightConstraint.d.ts +2 -2
- package/dist/{Constraints → constraints}/UIHorizontalDistanceConstraint.d.ts +7 -7
- package/dist/{Constraints → constraints}/UIHorizontalProportionConstraint.d.ts +6 -6
- package/dist/{Constraints → constraints}/UIVerticalDistanceConstraint.d.ts +7 -7
- package/dist/{Constraints → constraints}/UIVerticalProportionConstraint.d.ts +6 -6
- package/dist/{Constraints → constraints}/UIWidthConstraint.d.ts +2 -2
- package/dist/{Elements → elements}/UIAnchor.d.ts +5 -6
- package/dist/{Elements → elements}/UIDummy.d.ts +1 -1
- package/dist/{Elements → elements}/UIElement.d.ts +9 -10
- package/dist/{Elements → elements}/UIImage.d.ts +2 -2
- package/dist/{Elements → elements}/UIProgress.d.ts +1 -1
- package/dist/{Elements → elements}/UIScene.d.ts +1 -1
- package/dist/{Elements → elements}/UIText.d.ts +4 -4
- package/dist/index.d.ts +28 -29
- package/dist/index.js +871 -978
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/{Layers → layers}/UILayer.d.ts +20 -21
- package/dist/{Materials → materials}/UIMaterial.d.ts +1 -1
- package/dist/{Miscellaneous → miscellaneous}/UIMicro.d.ts +1 -1
- package/dist/{Miscellaneous → miscellaneous}/asserts.d.ts +3 -3
- package/package.json +16 -12
- package/dist/Miscellaneous/symbols.d.ts +0 -1
- /package/dist/{Constraints → constraints}/UIConstraintPower.d.ts +0 -0
- /package/dist/{Layers → layers}/UIFullScreenLayer.d.ts +0 -0
- /package/dist/{Materials → materials}/UIProgressMaterial.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/UIBlending.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/UIMode.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/UIOrientation.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/UITextInterfaces.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/math.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/microTransformationTools.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/textTools.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/threeInstances.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,57 +1,48 @@
|
|
|
1
|
-
import { MathUtils, Vector2, Box2, Matrix3,
|
|
1
|
+
import { MathUtils, Vector2, Box2, Matrix3, Vector3, ShaderMaterial, Color, AddEquation, SrcAlphaFactor, OneMinusSrcAlphaFactor, NormalBlending, CustomBlending, OneMinusDstColorFactor, OneFactor, MultiplyBlending, SubtractiveBlending, AdditiveBlending, PlaneGeometry, Scene, Mesh, OrthographicCamera, WebGLRenderTarget, UnsignedByteType, LinearFilter, RGBAFormat, NoBlending, Object3D, UniformsUtils, PerspectiveCamera, CanvasTexture } from 'three';
|
|
2
2
|
|
|
3
|
-
/*-----------------------------------------------------------------------------
|
|
4
|
-
| Copyright (c) 2014, Nucleic Development Team.
|
|
5
|
-
|
|
|
6
|
-
| Distributed under the terms of the Modified BSD License.
|
|
7
|
-
|
|
|
8
|
-
| The full license is in the file COPYING.txt, distributed with this software.
|
|
9
|
-
|----------------------------------------------------------------------------*/
|
|
10
3
|
function createMap() {
|
|
11
4
|
return new IndexedMap();
|
|
12
5
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.array = [];
|
|
17
|
-
}
|
|
6
|
+
class IndexedMap {
|
|
7
|
+
index = {};
|
|
8
|
+
array = [];
|
|
18
9
|
/**
|
|
19
10
|
* Returns the number of items in the array.
|
|
20
11
|
*/
|
|
21
|
-
|
|
12
|
+
size() {
|
|
22
13
|
return this.array.length;
|
|
23
|
-
}
|
|
14
|
+
}
|
|
24
15
|
/**
|
|
25
16
|
* Returns true if the array is empty.
|
|
26
17
|
*/
|
|
27
|
-
|
|
18
|
+
empty() {
|
|
28
19
|
return this.array.length === 0;
|
|
29
|
-
}
|
|
20
|
+
}
|
|
30
21
|
/**
|
|
31
22
|
* Returns the item at the given array index.
|
|
32
23
|
*
|
|
33
24
|
* @param index The integer index of the desired item.
|
|
34
25
|
*/
|
|
35
|
-
|
|
26
|
+
itemAt(index) {
|
|
36
27
|
return this.array[index];
|
|
37
|
-
}
|
|
28
|
+
}
|
|
38
29
|
/**
|
|
39
30
|
* Returns true if the key is in the array, false otherwise.
|
|
40
31
|
*
|
|
41
32
|
* @param key The key to locate in the array.
|
|
42
33
|
*/
|
|
43
|
-
|
|
34
|
+
contains(key) {
|
|
44
35
|
return this.index[key.id()] !== undefined;
|
|
45
|
-
}
|
|
36
|
+
}
|
|
46
37
|
/**
|
|
47
38
|
* Returns the pair associated with the given key, or undefined.
|
|
48
39
|
*
|
|
49
40
|
* @param key The key to locate in the array.
|
|
50
41
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
find(key) {
|
|
43
|
+
const i = this.index[key.id()];
|
|
53
44
|
return i === undefined ? undefined : this.array[i];
|
|
54
|
-
}
|
|
45
|
+
}
|
|
55
46
|
/**
|
|
56
47
|
* Returns the pair associated with the key if it exists.
|
|
57
48
|
*
|
|
@@ -61,10 +52,10 @@ var IndexedMap = /** @class */ (function () {
|
|
|
61
52
|
* @param key The key to locate in the array.
|
|
62
53
|
* @param factory The function which creates the default value.
|
|
63
54
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
setDefault(key, factory) {
|
|
56
|
+
const i = this.index[key.id()];
|
|
66
57
|
if (i === undefined) {
|
|
67
|
-
|
|
58
|
+
const pair = new Pair(key, factory());
|
|
68
59
|
this.index[key.id()] = this.array.length;
|
|
69
60
|
this.array.push(pair);
|
|
70
61
|
return pair;
|
|
@@ -72,7 +63,7 @@ var IndexedMap = /** @class */ (function () {
|
|
|
72
63
|
else {
|
|
73
64
|
return this.array[i];
|
|
74
65
|
}
|
|
75
|
-
}
|
|
66
|
+
}
|
|
76
67
|
/**
|
|
77
68
|
* Insert the pair into the array and return the pair.
|
|
78
69
|
*
|
|
@@ -81,9 +72,9 @@ var IndexedMap = /** @class */ (function () {
|
|
|
81
72
|
* @param key The key portion of the pair.
|
|
82
73
|
* @param value The value portion of the pair.
|
|
83
74
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
75
|
+
insert(key, value) {
|
|
76
|
+
const pair = new Pair(key, value);
|
|
77
|
+
const i = this.index[key.id()];
|
|
87
78
|
if (i === undefined) {
|
|
88
79
|
this.index[key.id()] = this.array.length;
|
|
89
80
|
this.array.push(pair);
|
|
@@ -92,136 +83,127 @@ var IndexedMap = /** @class */ (function () {
|
|
|
92
83
|
this.array[i] = pair;
|
|
93
84
|
}
|
|
94
85
|
return pair;
|
|
95
|
-
}
|
|
86
|
+
}
|
|
96
87
|
/**
|
|
97
88
|
* Removes and returns the pair for the given key, or undefined.
|
|
98
89
|
*
|
|
99
90
|
* @param key The key to remove from the map.
|
|
100
91
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
92
|
+
erase(key) {
|
|
93
|
+
const i = this.index[key.id()];
|
|
103
94
|
if (i === undefined) {
|
|
104
95
|
return undefined;
|
|
105
96
|
}
|
|
106
97
|
this.index[key.id()] = undefined;
|
|
107
|
-
|
|
108
|
-
|
|
98
|
+
const pair = this.array[i];
|
|
99
|
+
const last = this.array.pop();
|
|
109
100
|
if (pair !== last) {
|
|
110
101
|
this.array[i] = last;
|
|
111
102
|
this.index[last.first.id()] = i;
|
|
112
103
|
}
|
|
113
104
|
return pair;
|
|
114
|
-
}
|
|
105
|
+
}
|
|
115
106
|
/**
|
|
116
107
|
* Create a copy of this associative array.
|
|
117
108
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
for (
|
|
121
|
-
|
|
109
|
+
copy() {
|
|
110
|
+
const copy = new IndexedMap();
|
|
111
|
+
for (let i = 0; i < this.array.length; i++) {
|
|
112
|
+
const pair = this.array[i].copy();
|
|
122
113
|
copy.array[i] = pair;
|
|
123
114
|
copy.index[pair.first.id()] = i;
|
|
124
115
|
}
|
|
125
116
|
return copy;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
}());
|
|
117
|
+
}
|
|
118
|
+
}
|
|
129
119
|
/**
|
|
130
120
|
* A class which defines a generic pair object.
|
|
131
121
|
* @private
|
|
132
122
|
*/
|
|
133
123
|
// tslint:disable: max-classes-per-file
|
|
134
|
-
|
|
124
|
+
class Pair {
|
|
125
|
+
first;
|
|
126
|
+
second;
|
|
135
127
|
/**
|
|
136
128
|
* Construct a new Pair object.
|
|
137
129
|
*
|
|
138
130
|
* @param first The first item of the pair.
|
|
139
131
|
* @param second The second item of the pair.
|
|
140
132
|
*/
|
|
141
|
-
|
|
133
|
+
constructor(first, second) {
|
|
142
134
|
this.first = first;
|
|
143
135
|
this.second = second;
|
|
144
136
|
}
|
|
145
137
|
/**
|
|
146
138
|
* Create a copy of the pair.
|
|
147
139
|
*/
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
140
|
+
copy() {
|
|
141
|
+
return new Pair(this.first, this.second);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
151
144
|
|
|
152
|
-
/*-----------------------------------------------------------------------------
|
|
153
|
-
| Copyright (c) 2014, Nucleic Development Team.
|
|
154
|
-
|
|
|
155
|
-
| Distributed under the terms of the Modified BSD License.
|
|
156
|
-
|
|
|
157
|
-
| The full license is in the file COPYING.txt, distributed with this software.
|
|
158
|
-
|----------------------------------------------------------------------------*/
|
|
159
145
|
/**
|
|
160
146
|
* The primary user constraint variable.
|
|
161
147
|
*
|
|
162
148
|
* @class
|
|
163
149
|
* @param {String} [name=""] The name to associated with the variable.
|
|
164
150
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (name === void 0) { name = ""; }
|
|
168
|
-
this._value = 0.0;
|
|
169
|
-
this._context = null;
|
|
170
|
-
this._id = VarId++;
|
|
151
|
+
class Variable {
|
|
152
|
+
constructor(name = '') {
|
|
171
153
|
this._name = name;
|
|
172
154
|
}
|
|
173
155
|
/**
|
|
174
156
|
* Returns the unique id number of the variable.
|
|
175
157
|
* @private
|
|
176
158
|
*/
|
|
177
|
-
|
|
159
|
+
id() {
|
|
178
160
|
return this._id;
|
|
179
|
-
}
|
|
161
|
+
}
|
|
180
162
|
/**
|
|
181
163
|
* Returns the name of the variable.
|
|
182
164
|
*
|
|
183
165
|
* @return {String} name of the variable
|
|
184
166
|
*/
|
|
185
|
-
|
|
167
|
+
name() {
|
|
186
168
|
return this._name;
|
|
187
|
-
}
|
|
169
|
+
}
|
|
188
170
|
/**
|
|
189
171
|
* Set the name of the variable.
|
|
190
172
|
*
|
|
191
173
|
* @param {String} name Name of the variable
|
|
192
174
|
*/
|
|
193
|
-
|
|
175
|
+
setName(name) {
|
|
194
176
|
this._name = name;
|
|
195
|
-
}
|
|
177
|
+
}
|
|
196
178
|
/**
|
|
197
179
|
* Returns the user context object of the variable.
|
|
198
180
|
* @private
|
|
199
181
|
*/
|
|
200
|
-
|
|
182
|
+
context() {
|
|
201
183
|
return this._context;
|
|
202
|
-
}
|
|
184
|
+
}
|
|
203
185
|
/**
|
|
204
186
|
* Set the user context object of the variable.
|
|
205
187
|
* @private
|
|
206
188
|
*/
|
|
207
|
-
|
|
189
|
+
setContext(context) {
|
|
208
190
|
this._context = context;
|
|
209
|
-
}
|
|
191
|
+
}
|
|
210
192
|
/**
|
|
211
193
|
* Returns the value of the variable.
|
|
212
194
|
*
|
|
213
195
|
* @return {Number} Calculated value
|
|
214
196
|
*/
|
|
215
|
-
|
|
197
|
+
value() {
|
|
216
198
|
return this._value;
|
|
217
|
-
}
|
|
199
|
+
}
|
|
218
200
|
/**
|
|
219
201
|
* Set the value of the variable.
|
|
220
202
|
* @private
|
|
221
203
|
*/
|
|
222
|
-
|
|
204
|
+
setValue(value) {
|
|
223
205
|
this._value = value;
|
|
224
|
-
}
|
|
206
|
+
}
|
|
225
207
|
/**
|
|
226
208
|
* Creates a new Expression by adding a number, variable or expression
|
|
227
209
|
* to the variable.
|
|
@@ -229,9 +211,9 @@ var Variable = /** @class */ (function () {
|
|
|
229
211
|
* @param {Number|Variable|Expression} value Value to add.
|
|
230
212
|
* @return {Expression} expression
|
|
231
213
|
*/
|
|
232
|
-
|
|
214
|
+
plus(value) {
|
|
233
215
|
return new Expression(this, value);
|
|
234
|
-
}
|
|
216
|
+
}
|
|
235
217
|
/**
|
|
236
218
|
* Creates a new Expression by substracting a number, variable or expression
|
|
237
219
|
* from the variable.
|
|
@@ -239,55 +221,51 @@ var Variable = /** @class */ (function () {
|
|
|
239
221
|
* @param {Number|Variable|Expression} value Value to substract.
|
|
240
222
|
* @return {Expression} expression
|
|
241
223
|
*/
|
|
242
|
-
|
|
243
|
-
return new Expression(this, typeof value ===
|
|
244
|
-
}
|
|
224
|
+
minus(value) {
|
|
225
|
+
return new Expression(this, typeof value === 'number' ? -value : [-1, value]);
|
|
226
|
+
}
|
|
245
227
|
/**
|
|
246
228
|
* Creates a new Expression by multiplying with a fixed number.
|
|
247
229
|
*
|
|
248
230
|
* @param {Number} coefficient Coefficient to multiply with.
|
|
249
231
|
* @return {Expression} expression
|
|
250
232
|
*/
|
|
251
|
-
|
|
233
|
+
multiply(coefficient) {
|
|
252
234
|
return new Expression([coefficient, this]);
|
|
253
|
-
}
|
|
235
|
+
}
|
|
254
236
|
/**
|
|
255
237
|
* Creates a new Expression by dividing with a fixed number.
|
|
256
238
|
*
|
|
257
239
|
* @param {Number} coefficient Coefficient to divide by.
|
|
258
240
|
* @return {Expression} expression
|
|
259
241
|
*/
|
|
260
|
-
|
|
242
|
+
divide(coefficient) {
|
|
261
243
|
return new Expression([1 / coefficient, this]);
|
|
262
|
-
}
|
|
244
|
+
}
|
|
263
245
|
/**
|
|
264
246
|
* Returns the JSON representation of the variable.
|
|
265
247
|
* @private
|
|
266
248
|
*/
|
|
267
|
-
|
|
249
|
+
toJSON() {
|
|
268
250
|
return {
|
|
269
251
|
name: this._name,
|
|
270
252
|
value: this._value,
|
|
271
253
|
};
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return this._context +
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
254
|
+
}
|
|
255
|
+
toString() {
|
|
256
|
+
return this._context + '[' + this._name + ':' + this._value + ']';
|
|
257
|
+
}
|
|
258
|
+
_name;
|
|
259
|
+
_value = 0.0;
|
|
260
|
+
_context = null;
|
|
261
|
+
_id = VarId++;
|
|
262
|
+
}
|
|
278
263
|
/**
|
|
279
264
|
* The internal variable id counter.
|
|
280
265
|
* @private
|
|
281
266
|
*/
|
|
282
|
-
|
|
267
|
+
let VarId = 0;
|
|
283
268
|
|
|
284
|
-
/*-----------------------------------------------------------------------------
|
|
285
|
-
| Copyright (c) 2014, Nucleic Development Team.
|
|
286
|
-
|
|
|
287
|
-
| Distributed under the terms of the Modified BSD License.
|
|
288
|
-
|
|
|
289
|
-
| The full license is in the file COPYING.txt, distributed with this software.
|
|
290
|
-
|----------------------------------------------------------------------------*/
|
|
291
269
|
/**
|
|
292
270
|
* An expression of variable terms and a constant.
|
|
293
271
|
*
|
|
@@ -303,9 +281,9 @@ var VarId = 0;
|
|
|
303
281
|
* @class
|
|
304
282
|
* @param {...(number|Variable|Expression|Array)} args
|
|
305
283
|
*/
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
284
|
+
class Expression {
|
|
285
|
+
constructor() {
|
|
286
|
+
let parsed = parseArgs(arguments);
|
|
309
287
|
this._terms = parsed.terms;
|
|
310
288
|
this._constant = parsed.constant;
|
|
311
289
|
}
|
|
@@ -315,30 +293,30 @@ var Expression = /** @class */ (function () {
|
|
|
315
293
|
* This *must* be treated as const.
|
|
316
294
|
* @private
|
|
317
295
|
*/
|
|
318
|
-
|
|
296
|
+
terms() {
|
|
319
297
|
return this._terms;
|
|
320
|
-
}
|
|
298
|
+
}
|
|
321
299
|
/**
|
|
322
300
|
* Returns the constant of the expression.
|
|
323
301
|
* @private
|
|
324
302
|
*/
|
|
325
|
-
|
|
303
|
+
constant() {
|
|
326
304
|
return this._constant;
|
|
327
|
-
}
|
|
305
|
+
}
|
|
328
306
|
/**
|
|
329
307
|
* Returns the computed value of the expression.
|
|
330
308
|
*
|
|
331
309
|
* @private
|
|
332
310
|
* @return {Number} computed value of the expression
|
|
333
311
|
*/
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
for (
|
|
337
|
-
|
|
312
|
+
value() {
|
|
313
|
+
let result = this._constant;
|
|
314
|
+
for (let i = 0, n = this._terms.size(); i < n; i++) {
|
|
315
|
+
let pair = this._terms.itemAt(i);
|
|
338
316
|
result += pair.first.value() * pair.second;
|
|
339
317
|
}
|
|
340
318
|
return result;
|
|
341
|
-
}
|
|
319
|
+
}
|
|
342
320
|
/**
|
|
343
321
|
* Creates a new Expression by adding a number, variable or expression
|
|
344
322
|
* to the expression.
|
|
@@ -346,9 +324,9 @@ var Expression = /** @class */ (function () {
|
|
|
346
324
|
* @param {Number|Variable|Expression} value Value to add.
|
|
347
325
|
* @return {Expression} expression
|
|
348
326
|
*/
|
|
349
|
-
|
|
327
|
+
plus(value) {
|
|
350
328
|
return new Expression(this, value);
|
|
351
|
-
}
|
|
329
|
+
}
|
|
352
330
|
/**
|
|
353
331
|
* Creates a new Expression by substracting a number, variable or expression
|
|
354
332
|
* from the expression.
|
|
@@ -356,53 +334,56 @@ var Expression = /** @class */ (function () {
|
|
|
356
334
|
* @param {Number|Variable|Expression} value Value to substract.
|
|
357
335
|
* @return {Expression} expression
|
|
358
336
|
*/
|
|
359
|
-
|
|
360
|
-
return new Expression(this, typeof value ===
|
|
361
|
-
}
|
|
337
|
+
minus(value) {
|
|
338
|
+
return new Expression(this, typeof value === 'number' ? -value : [-1, value]);
|
|
339
|
+
}
|
|
362
340
|
/**
|
|
363
341
|
* Creates a new Expression by multiplying with a fixed number.
|
|
364
342
|
*
|
|
365
343
|
* @param {Number} coefficient Coefficient to multiply with.
|
|
366
344
|
* @return {Expression} expression
|
|
367
345
|
*/
|
|
368
|
-
|
|
346
|
+
multiply(coefficient) {
|
|
369
347
|
return new Expression([coefficient, this]);
|
|
370
|
-
}
|
|
348
|
+
}
|
|
371
349
|
/**
|
|
372
350
|
* Creates a new Expression by dividing with a fixed number.
|
|
373
351
|
*
|
|
374
352
|
* @param {Number} coefficient Coefficient to divide by.
|
|
375
353
|
* @return {Expression} expression
|
|
376
354
|
*/
|
|
377
|
-
|
|
355
|
+
divide(coefficient) {
|
|
378
356
|
return new Expression([1 / coefficient, this]);
|
|
379
|
-
}
|
|
380
|
-
|
|
357
|
+
}
|
|
358
|
+
isConstant() {
|
|
381
359
|
return this._terms.size() == 0;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
360
|
+
}
|
|
361
|
+
toString() {
|
|
362
|
+
let result = this._terms.array
|
|
363
|
+
.map(function (pair) {
|
|
364
|
+
return pair.second + '*' + pair.first.toString();
|
|
365
|
+
})
|
|
366
|
+
.join(' + ');
|
|
387
367
|
if (!this.isConstant() && this._constant !== 0) {
|
|
388
|
-
result +=
|
|
368
|
+
result += ' + ';
|
|
389
369
|
}
|
|
390
370
|
result += this._constant;
|
|
391
371
|
return result;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
|
|
372
|
+
}
|
|
373
|
+
_terms;
|
|
374
|
+
_constant;
|
|
375
|
+
}
|
|
395
376
|
/**
|
|
396
377
|
* An internal argument parsing function.
|
|
397
378
|
* @private
|
|
398
379
|
*/
|
|
399
380
|
function parseArgs(args) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
for (
|
|
404
|
-
|
|
405
|
-
if (typeof item ===
|
|
381
|
+
let constant = 0.0;
|
|
382
|
+
let factory = () => 0.0;
|
|
383
|
+
let terms = createMap();
|
|
384
|
+
for (let i = 0, n = args.length; i < n; ++i) {
|
|
385
|
+
let item = args[i];
|
|
386
|
+
if (typeof item === 'number') {
|
|
406
387
|
constant += item;
|
|
407
388
|
}
|
|
408
389
|
else if (item instanceof Variable) {
|
|
@@ -410,56 +391,47 @@ function parseArgs(args) {
|
|
|
410
391
|
}
|
|
411
392
|
else if (item instanceof Expression) {
|
|
412
393
|
constant += item.constant();
|
|
413
|
-
|
|
414
|
-
for (
|
|
415
|
-
|
|
394
|
+
let terms2 = item.terms();
|
|
395
|
+
for (let j = 0, k = terms2.size(); j < k; j++) {
|
|
396
|
+
let termPair = terms2.itemAt(j);
|
|
416
397
|
terms.setDefault(termPair.first, factory).second += termPair.second;
|
|
417
398
|
}
|
|
418
399
|
}
|
|
419
400
|
else if (item instanceof Array) {
|
|
420
401
|
if (item.length !== 2) {
|
|
421
|
-
throw new Error(
|
|
402
|
+
throw new Error('array must have length 2');
|
|
422
403
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
if (typeof value !==
|
|
426
|
-
throw new Error(
|
|
404
|
+
let value = item[0];
|
|
405
|
+
let value2 = item[1];
|
|
406
|
+
if (typeof value !== 'number') {
|
|
407
|
+
throw new Error('array item 0 must be a number');
|
|
427
408
|
}
|
|
428
409
|
if (value2 instanceof Variable) {
|
|
429
410
|
terms.setDefault(value2, factory).second += value;
|
|
430
411
|
}
|
|
431
412
|
else if (value2 instanceof Expression) {
|
|
432
|
-
constant +=
|
|
433
|
-
|
|
434
|
-
for (
|
|
435
|
-
|
|
436
|
-
terms.setDefault(termPair.first, factory).second +=
|
|
413
|
+
constant += value2.constant() * value;
|
|
414
|
+
let terms2 = value2.terms();
|
|
415
|
+
for (let j = 0, k = terms2.size(); j < k; j++) {
|
|
416
|
+
let termPair = terms2.itemAt(j);
|
|
417
|
+
terms.setDefault(termPair.first, factory).second += termPair.second * value;
|
|
437
418
|
}
|
|
438
419
|
}
|
|
439
420
|
else {
|
|
440
|
-
throw new Error(
|
|
421
|
+
throw new Error('array item 1 must be a variable or expression');
|
|
441
422
|
}
|
|
442
423
|
}
|
|
443
424
|
else {
|
|
444
|
-
throw new Error(
|
|
425
|
+
throw new Error('invalid Expression argument: ' + item);
|
|
445
426
|
}
|
|
446
427
|
}
|
|
447
|
-
return { terms
|
|
428
|
+
return { terms, constant };
|
|
448
429
|
}
|
|
449
430
|
|
|
450
|
-
/*-----------------------------------------------------------------------------
|
|
451
|
-
| Copyright (c) 2014, Nucleic Development Team.
|
|
452
|
-
|
|
|
453
|
-
| Distributed under the terms of the Modified BSD License.
|
|
454
|
-
|
|
|
455
|
-
| The full license is in the file COPYING.txt, distributed with this software.
|
|
456
|
-
|----------------------------------------------------------------------------*/
|
|
457
431
|
/**
|
|
458
432
|
* @class Strength
|
|
459
433
|
*/
|
|
460
|
-
|
|
461
|
-
function Strength() {
|
|
462
|
-
}
|
|
434
|
+
class Strength {
|
|
463
435
|
/**
|
|
464
436
|
* Create a new symbolic strength.
|
|
465
437
|
*
|
|
@@ -468,48 +440,39 @@ var Strength = /** @class */ (function () {
|
|
|
468
440
|
* @param c weak
|
|
469
441
|
* @param [w] weight
|
|
470
442
|
* @return strength
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
var result = 0.0;
|
|
443
|
+
*/
|
|
444
|
+
static create(a, b, c, w = 1.0) {
|
|
445
|
+
let result = 0.0;
|
|
475
446
|
result += Math.max(0.0, Math.min(1000.0, a * w)) * 1000000.0;
|
|
476
447
|
result += Math.max(0.0, Math.min(1000.0, b * w)) * 1000.0;
|
|
477
448
|
result += Math.max(0.0, Math.min(1000.0, c * w));
|
|
478
449
|
return result;
|
|
479
|
-
}
|
|
480
|
-
/**
|
|
481
|
-
* Clip a symbolic strength to the allowed min and max.
|
|
482
|
-
* @private
|
|
483
|
-
*/
|
|
484
|
-
Strength.clip = function (value) {
|
|
485
|
-
return Math.max(0.0, Math.min(Strength.required, value));
|
|
486
|
-
};
|
|
450
|
+
}
|
|
487
451
|
/**
|
|
488
452
|
* The 'required' symbolic strength.
|
|
489
453
|
*/
|
|
490
|
-
|
|
454
|
+
static required = Strength.create(1000.0, 1000.0, 1000.0);
|
|
491
455
|
/**
|
|
492
456
|
* The 'strong' symbolic strength.
|
|
493
457
|
*/
|
|
494
|
-
|
|
458
|
+
static strong = Strength.create(1.0, 0.0, 0.0);
|
|
495
459
|
/**
|
|
496
460
|
* The 'medium' symbolic strength.
|
|
497
461
|
*/
|
|
498
|
-
|
|
462
|
+
static medium = Strength.create(0.0, 1.0, 0.0);
|
|
499
463
|
/**
|
|
500
464
|
* The 'weak' symbolic strength.
|
|
501
465
|
*/
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
466
|
+
static weak = Strength.create(0.0, 0.0, 1.0);
|
|
467
|
+
/**
|
|
468
|
+
* Clip a symbolic strength to the allowed min and max.
|
|
469
|
+
* @private
|
|
470
|
+
*/
|
|
471
|
+
static clip(value) {
|
|
472
|
+
return Math.max(0.0, Math.min(Strength.required, value));
|
|
473
|
+
}
|
|
474
|
+
}
|
|
505
475
|
|
|
506
|
-
/*-----------------------------------------------------------------------------
|
|
507
|
-
| Copyright (c) 2014, Nucleic Development Team.
|
|
508
|
-
|
|
|
509
|
-
| Distributed under the terms of the Modified BSD License.
|
|
510
|
-
|
|
|
511
|
-
| The full license is in the file COPYING.txt, distributed with this software.
|
|
512
|
-
|----------------------------------------------------------------------------*/
|
|
513
476
|
/**
|
|
514
477
|
* An enum defining the linear constraint operators.
|
|
515
478
|
*
|
|
@@ -539,13 +502,11 @@ var Operator;
|
|
|
539
502
|
* @param {Expression} [rhs] Right hand side of the expression.
|
|
540
503
|
* @param {Number} [strength=Strength.required] The strength of the constraint.
|
|
541
504
|
*/
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
if (strength === void 0) { strength = Strength.required; }
|
|
545
|
-
this._id = CnId++;
|
|
505
|
+
class Constraint {
|
|
506
|
+
constructor(expression, operator, rhs, strength = Strength.required) {
|
|
546
507
|
this._operator = operator;
|
|
547
508
|
this._strength = Strength.clip(strength);
|
|
548
|
-
if (
|
|
509
|
+
if (rhs === undefined && expression instanceof Expression) {
|
|
549
510
|
this._expression = expression;
|
|
550
511
|
}
|
|
551
512
|
else {
|
|
@@ -556,70 +517,62 @@ var Constraint = /** @class */ (function () {
|
|
|
556
517
|
* Returns the unique id number of the constraint.
|
|
557
518
|
* @private
|
|
558
519
|
*/
|
|
559
|
-
|
|
520
|
+
id() {
|
|
560
521
|
return this._id;
|
|
561
|
-
}
|
|
522
|
+
}
|
|
562
523
|
/**
|
|
563
524
|
* Returns the expression of the constraint.
|
|
564
525
|
*
|
|
565
526
|
* @return {Expression} expression
|
|
566
527
|
*/
|
|
567
|
-
|
|
528
|
+
expression() {
|
|
568
529
|
return this._expression;
|
|
569
|
-
}
|
|
530
|
+
}
|
|
570
531
|
/**
|
|
571
532
|
* Returns the relational operator of the constraint.
|
|
572
533
|
*
|
|
573
534
|
* @return {Operator} linear constraint operator
|
|
574
535
|
*/
|
|
575
|
-
|
|
536
|
+
op() {
|
|
576
537
|
return this._operator;
|
|
577
|
-
}
|
|
538
|
+
}
|
|
578
539
|
/**
|
|
579
540
|
* Returns the strength of the constraint.
|
|
580
541
|
*
|
|
581
542
|
* @return {Number} strength
|
|
582
543
|
*/
|
|
583
|
-
|
|
544
|
+
strength() {
|
|
584
545
|
return this._strength;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
return this._expression.toString() +
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
|
|
546
|
+
}
|
|
547
|
+
toString() {
|
|
548
|
+
return (this._expression.toString() + ' ' + ['<=', '>=', '='][this._operator] + ' 0 (' + this._strength.toString() + ')');
|
|
549
|
+
}
|
|
550
|
+
_expression;
|
|
551
|
+
_operator;
|
|
552
|
+
_strength;
|
|
553
|
+
_id = CnId++;
|
|
554
|
+
}
|
|
591
555
|
/**
|
|
592
556
|
* The internal constraint id counter.
|
|
593
557
|
* @private
|
|
594
558
|
*/
|
|
595
|
-
|
|
559
|
+
let CnId = 0;
|
|
596
560
|
|
|
597
|
-
/*-----------------------------------------------------------------------------
|
|
598
|
-
| Copyright (c) 2014, Nucleic Development Team.
|
|
599
|
-
|
|
|
600
|
-
| Distributed under the terms of the Modified BSD License.
|
|
601
|
-
|
|
|
602
|
-
| The full license is in the file COPYING.txt, distributed with this software.
|
|
603
|
-
|----------------------------------------------------------------------------*/
|
|
604
561
|
/**
|
|
605
562
|
* The constraint solver class.
|
|
606
563
|
*
|
|
607
564
|
* @class
|
|
608
565
|
*/
|
|
609
|
-
|
|
566
|
+
class Solver {
|
|
567
|
+
/**
|
|
568
|
+
* @type {number} - The max number of solver iterations before an error
|
|
569
|
+
* is thrown, in order to prevent infinite iteration. Default: `10,000`.
|
|
570
|
+
*/
|
|
571
|
+
maxIterations = 1000;
|
|
610
572
|
/**
|
|
611
573
|
* Construct a new Solver.
|
|
612
574
|
*/
|
|
613
|
-
|
|
614
|
-
this._cnMap = createCnMap();
|
|
615
|
-
this._rowMap = createRowMap();
|
|
616
|
-
this._varMap = createVarMap();
|
|
617
|
-
this._editMap = createEditMap();
|
|
618
|
-
this._infeasibleRows = [];
|
|
619
|
-
this._objective = new Row();
|
|
620
|
-
this._artificial = null;
|
|
621
|
-
this._idTick = 0;
|
|
622
|
-
}
|
|
575
|
+
constructor() { }
|
|
623
576
|
/**
|
|
624
577
|
* Creates and add a constraint to the solver.
|
|
625
578
|
*
|
|
@@ -628,21 +581,20 @@ var Solver = /** @class */ (function () {
|
|
|
628
581
|
* @param {Expression|Variable|Number} rhs Right hand side of the expression
|
|
629
582
|
* @param {Number} [strength=Strength.required] Strength
|
|
630
583
|
*/
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
var cn = new Constraint(lhs, operator, rhs, strength);
|
|
584
|
+
createConstraint(lhs, operator, rhs, strength = Strength.required) {
|
|
585
|
+
let cn = new Constraint(lhs, operator, rhs, strength);
|
|
634
586
|
this.addConstraint(cn);
|
|
635
587
|
return cn;
|
|
636
|
-
}
|
|
588
|
+
}
|
|
637
589
|
/**
|
|
638
590
|
* Add a constraint to the solver.
|
|
639
591
|
*
|
|
640
592
|
* @param {Constraint} constraint Constraint to add to the solver
|
|
641
593
|
*/
|
|
642
|
-
|
|
643
|
-
|
|
594
|
+
addConstraint(constraint) {
|
|
595
|
+
let cnPair = this._cnMap.find(constraint);
|
|
644
596
|
if (cnPair !== undefined) {
|
|
645
|
-
throw new Error(
|
|
597
|
+
throw new Error('duplicate constraint');
|
|
646
598
|
}
|
|
647
599
|
// Creating a row causes symbols to be reserved for the variables
|
|
648
600
|
// in the constraint. If this method exits with an exception,
|
|
@@ -650,10 +602,10 @@ var Solver = /** @class */ (function () {
|
|
|
650
602
|
// Since its likely that those variables will be used in other
|
|
651
603
|
// constraints and since exceptional conditions are uncommon,
|
|
652
604
|
// i'm not too worried about aggressive cleanup of the var map.
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
605
|
+
let data = this._createRow(constraint);
|
|
606
|
+
let row = data.row;
|
|
607
|
+
let tag = data.tag;
|
|
608
|
+
let subject = this._chooseSubject(row, tag);
|
|
657
609
|
// If chooseSubject couldnt find a valid entering symbol, one
|
|
658
610
|
// last option is available if the entire row is composed of
|
|
659
611
|
// dummy variables. If the constant of the row is zero, then
|
|
@@ -662,7 +614,7 @@ var Solver = /** @class */ (function () {
|
|
|
662
614
|
// then it represents an unsatisfiable constraint.
|
|
663
615
|
if (subject.type() === SymbolType.Invalid && row.allDummies()) {
|
|
664
616
|
if (!nearZero(row.constant())) {
|
|
665
|
-
throw new Error(
|
|
617
|
+
throw new Error('unsatisfiable constraint');
|
|
666
618
|
}
|
|
667
619
|
else {
|
|
668
620
|
subject = tag.marker;
|
|
@@ -673,7 +625,7 @@ var Solver = /** @class */ (function () {
|
|
|
673
625
|
// the row represents an unsatisfiable constraint.
|
|
674
626
|
if (subject.type() === SymbolType.Invalid) {
|
|
675
627
|
if (!this._addWithArtificialVariable(row)) {
|
|
676
|
-
throw new Error(
|
|
628
|
+
throw new Error('unsatisfiable constraint');
|
|
677
629
|
}
|
|
678
630
|
}
|
|
679
631
|
else {
|
|
@@ -686,16 +638,16 @@ var Solver = /** @class */ (function () {
|
|
|
686
638
|
// aggregate work due to a smaller average system size. It
|
|
687
639
|
// also ensures the solver remains in a consistent state.
|
|
688
640
|
this._optimize(this._objective);
|
|
689
|
-
}
|
|
641
|
+
}
|
|
690
642
|
/**
|
|
691
643
|
* Remove a constraint from the solver.
|
|
692
644
|
*
|
|
693
645
|
* @param {Constraint} constraint Constraint to remove from the solver
|
|
694
646
|
*/
|
|
695
|
-
|
|
696
|
-
|
|
647
|
+
removeConstraint(constraint) {
|
|
648
|
+
let cnPair = this._cnMap.erase(constraint);
|
|
697
649
|
if (cnPair === undefined) {
|
|
698
|
-
throw new Error(
|
|
650
|
+
throw new Error('unknown constraint');
|
|
699
651
|
}
|
|
700
652
|
// Remove the error effects from the objective function
|
|
701
653
|
// *before* pivoting, or substitutions into the objective
|
|
@@ -703,12 +655,12 @@ var Solver = /** @class */ (function () {
|
|
|
703
655
|
this._removeConstraintEffects(constraint, cnPair.second);
|
|
704
656
|
// If the marker is basic, simply drop the row. Otherwise,
|
|
705
657
|
// pivot the marker into the basis and then drop the row.
|
|
706
|
-
|
|
707
|
-
|
|
658
|
+
let marker = cnPair.second.marker;
|
|
659
|
+
let rowPair = this._rowMap.erase(marker);
|
|
708
660
|
if (rowPair === undefined) {
|
|
709
|
-
|
|
661
|
+
let leaving = this._getMarkerLeavingSymbol(marker);
|
|
710
662
|
if (leaving.type() === SymbolType.Invalid) {
|
|
711
|
-
throw new Error(
|
|
663
|
+
throw new Error('failed to find leaving row');
|
|
712
664
|
}
|
|
713
665
|
rowPair = this._rowMap.erase(leaving);
|
|
714
666
|
rowPair.second.solveForEx(leaving, marker);
|
|
@@ -718,77 +670,85 @@ var Solver = /** @class */ (function () {
|
|
|
718
670
|
// solver remains consistent. It makes the solver api easier to
|
|
719
671
|
// use at a small tradeoff for speed.
|
|
720
672
|
this._optimize(this._objective);
|
|
721
|
-
}
|
|
673
|
+
}
|
|
722
674
|
/**
|
|
723
675
|
* Test whether the solver contains the constraint.
|
|
724
676
|
*
|
|
725
677
|
* @param {Constraint} constraint Constraint to test for
|
|
726
678
|
* @return {Bool} true or false
|
|
727
679
|
*/
|
|
728
|
-
|
|
680
|
+
hasConstraint(constraint) {
|
|
729
681
|
return this._cnMap.contains(constraint);
|
|
730
|
-
}
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Get an array of the current constraints.
|
|
685
|
+
*
|
|
686
|
+
* @return {Constraint[]}
|
|
687
|
+
*/
|
|
688
|
+
getConstraints() {
|
|
689
|
+
return this._cnMap.array.map(({ first }) => first);
|
|
690
|
+
}
|
|
731
691
|
/**
|
|
732
692
|
* Add an edit variable to the solver.
|
|
733
693
|
*
|
|
734
694
|
* @param {Variable} variable Edit variable to add to the solver
|
|
735
695
|
* @param {Number} strength Strength, should be less than `Strength.required`
|
|
736
696
|
*/
|
|
737
|
-
|
|
738
|
-
|
|
697
|
+
addEditVariable(variable, strength) {
|
|
698
|
+
let editPair = this._editMap.find(variable);
|
|
739
699
|
if (editPair !== undefined) {
|
|
740
|
-
throw new Error(
|
|
700
|
+
throw new Error('duplicate edit variable');
|
|
741
701
|
}
|
|
742
702
|
strength = Strength.clip(strength);
|
|
743
703
|
if (strength === Strength.required) {
|
|
744
|
-
throw new Error(
|
|
704
|
+
throw new Error('bad required strength');
|
|
745
705
|
}
|
|
746
|
-
|
|
747
|
-
|
|
706
|
+
let expr = new Expression(variable);
|
|
707
|
+
let cn = new Constraint(expr, Operator.Eq, undefined, strength);
|
|
748
708
|
this.addConstraint(cn);
|
|
749
|
-
|
|
750
|
-
|
|
709
|
+
let tag = this._cnMap.find(cn).second;
|
|
710
|
+
let info = { tag, constraint: cn, constant: 0.0 };
|
|
751
711
|
this._editMap.insert(variable, info);
|
|
752
|
-
}
|
|
712
|
+
}
|
|
753
713
|
/**
|
|
754
714
|
* Remove an edit variable from the solver.
|
|
755
715
|
*
|
|
756
716
|
* @param {Variable} variable Edit variable to remove from the solver
|
|
757
717
|
*/
|
|
758
|
-
|
|
759
|
-
|
|
718
|
+
removeEditVariable(variable) {
|
|
719
|
+
let editPair = this._editMap.erase(variable);
|
|
760
720
|
if (editPair === undefined) {
|
|
761
|
-
throw new Error(
|
|
721
|
+
throw new Error('unknown edit variable');
|
|
762
722
|
}
|
|
763
723
|
this.removeConstraint(editPair.second.constraint);
|
|
764
|
-
}
|
|
724
|
+
}
|
|
765
725
|
/**
|
|
766
726
|
* Test whether the solver contains the edit variable.
|
|
767
727
|
*
|
|
768
728
|
* @param {Variable} variable Edit variable to test for
|
|
769
729
|
* @return {Bool} true or false
|
|
770
730
|
*/
|
|
771
|
-
|
|
731
|
+
hasEditVariable(variable) {
|
|
772
732
|
return this._editMap.contains(variable);
|
|
773
|
-
}
|
|
733
|
+
}
|
|
774
734
|
/**
|
|
775
735
|
* Suggest the value of an edit variable.
|
|
776
736
|
*
|
|
777
737
|
* @param {Variable} variable Edit variable to suggest a value for
|
|
778
738
|
* @param {Number} value Suggested value
|
|
779
739
|
*/
|
|
780
|
-
|
|
781
|
-
|
|
740
|
+
suggestValue(variable, value) {
|
|
741
|
+
let editPair = this._editMap.find(variable);
|
|
782
742
|
if (editPair === undefined) {
|
|
783
|
-
throw new Error(
|
|
743
|
+
throw new Error('unknown edit variable');
|
|
784
744
|
}
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
745
|
+
let rows = this._rowMap;
|
|
746
|
+
let info = editPair.second;
|
|
747
|
+
let delta = value - info.constant;
|
|
788
748
|
info.constant = value;
|
|
789
749
|
// Check first if the positive error variable is basic.
|
|
790
|
-
|
|
791
|
-
|
|
750
|
+
let marker = info.tag.marker;
|
|
751
|
+
let rowPair = rows.find(marker);
|
|
792
752
|
if (rowPair !== undefined) {
|
|
793
753
|
if (rowPair.second.add(-delta) < 0.0) {
|
|
794
754
|
this._infeasibleRows.push(marker);
|
|
@@ -797,7 +757,7 @@ var Solver = /** @class */ (function () {
|
|
|
797
757
|
return;
|
|
798
758
|
}
|
|
799
759
|
// Check next if the negative error variable is basic.
|
|
800
|
-
|
|
760
|
+
let other = info.tag.other;
|
|
801
761
|
rowPair = rows.find(other);
|
|
802
762
|
if (rowPair !== undefined) {
|
|
803
763
|
if (rowPair.second.add(delta) < 0.0) {
|
|
@@ -807,26 +767,25 @@ var Solver = /** @class */ (function () {
|
|
|
807
767
|
return;
|
|
808
768
|
}
|
|
809
769
|
// Otherwise update each row where the error variables exist.
|
|
810
|
-
for (
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
if (coeff !== 0.0 && row.add(delta * coeff) < 0.0 &&
|
|
815
|
-
|
|
816
|
-
this._infeasibleRows.push(rowPair_1.first);
|
|
770
|
+
for (let i = 0, n = rows.size(); i < n; ++i) {
|
|
771
|
+
let rowPair = rows.itemAt(i);
|
|
772
|
+
let row = rowPair.second;
|
|
773
|
+
let coeff = row.coefficientFor(marker);
|
|
774
|
+
if (coeff !== 0.0 && row.add(delta * coeff) < 0.0 && rowPair.first.type() !== SymbolType.External) {
|
|
775
|
+
this._infeasibleRows.push(rowPair.first);
|
|
817
776
|
}
|
|
818
777
|
}
|
|
819
778
|
this._dualOptimize();
|
|
820
|
-
}
|
|
779
|
+
}
|
|
821
780
|
/**
|
|
822
781
|
* Update the values of the variables.
|
|
823
782
|
*/
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
for (
|
|
828
|
-
|
|
829
|
-
|
|
783
|
+
updateVariables() {
|
|
784
|
+
let vars = this._varMap;
|
|
785
|
+
let rows = this._rowMap;
|
|
786
|
+
for (let i = 0, n = vars.size(); i < n; ++i) {
|
|
787
|
+
let pair = vars.itemAt(i);
|
|
788
|
+
let rowPair = rows.find(pair.second);
|
|
830
789
|
if (rowPair !== undefined) {
|
|
831
790
|
pair.first.setValue(rowPair.second.constant());
|
|
832
791
|
}
|
|
@@ -834,18 +793,17 @@ var Solver = /** @class */ (function () {
|
|
|
834
793
|
pair.first.setValue(0.0);
|
|
835
794
|
}
|
|
836
795
|
}
|
|
837
|
-
}
|
|
796
|
+
}
|
|
838
797
|
/**
|
|
839
798
|
* Get the symbol for the given variable.
|
|
840
799
|
*
|
|
841
800
|
* If a symbol does not exist for the variable, one will be created.
|
|
842
801
|
* @private
|
|
843
802
|
*/
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
var factory = function () { return _this._makeSymbol(SymbolType.External); };
|
|
803
|
+
_getVarSymbol(variable) {
|
|
804
|
+
let factory = () => this._makeSymbol(SymbolType.External);
|
|
847
805
|
return this._varMap.setDefault(variable, factory).second;
|
|
848
|
-
}
|
|
806
|
+
}
|
|
849
807
|
/**
|
|
850
808
|
* Create a new Row object for the given constraint.
|
|
851
809
|
*
|
|
@@ -863,16 +821,16 @@ var Solver = /** @class */ (function () {
|
|
|
863
821
|
* Returns the created Row and the tag for tracking the constraint.
|
|
864
822
|
* @private
|
|
865
823
|
*/
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
824
|
+
_createRow(constraint) {
|
|
825
|
+
let expr = constraint.expression();
|
|
826
|
+
let row = new Row(expr.constant());
|
|
869
827
|
// Substitute the current basic variables into the row.
|
|
870
|
-
|
|
871
|
-
for (
|
|
872
|
-
|
|
828
|
+
let terms = expr.terms();
|
|
829
|
+
for (let i = 0, n = terms.size(); i < n; ++i) {
|
|
830
|
+
let termPair = terms.itemAt(i);
|
|
873
831
|
if (!nearZero(termPair.second)) {
|
|
874
|
-
|
|
875
|
-
|
|
832
|
+
let symbol = this._getVarSymbol(termPair.first);
|
|
833
|
+
let basicPair = this._rowMap.find(symbol);
|
|
876
834
|
if (basicPair !== undefined) {
|
|
877
835
|
row.insertRow(basicPair.second, termPair.second);
|
|
878
836
|
}
|
|
@@ -882,51 +840,49 @@ var Solver = /** @class */ (function () {
|
|
|
882
840
|
}
|
|
883
841
|
}
|
|
884
842
|
// Add the necessary slack, error, and dummy variables.
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
843
|
+
let objective = this._objective;
|
|
844
|
+
let strength = constraint.strength();
|
|
845
|
+
let tag = { marker: INVALID_SYMBOL, other: INVALID_SYMBOL };
|
|
888
846
|
switch (constraint.op()) {
|
|
889
847
|
case Operator.Le:
|
|
890
|
-
case Operator.Ge:
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
objective.insertSymbol(error, strength);
|
|
901
|
-
}
|
|
902
|
-
break;
|
|
848
|
+
case Operator.Ge: {
|
|
849
|
+
let coeff = constraint.op() === Operator.Le ? 1.0 : -1;
|
|
850
|
+
let slack = this._makeSymbol(SymbolType.Slack);
|
|
851
|
+
tag.marker = slack;
|
|
852
|
+
row.insertSymbol(slack, coeff);
|
|
853
|
+
if (strength < Strength.required) {
|
|
854
|
+
let error = this._makeSymbol(SymbolType.Error);
|
|
855
|
+
tag.other = error;
|
|
856
|
+
row.insertSymbol(error, -coeff);
|
|
857
|
+
objective.insertSymbol(error, strength);
|
|
903
858
|
}
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
break;
|
|
859
|
+
break;
|
|
860
|
+
}
|
|
861
|
+
case Operator.Eq: {
|
|
862
|
+
if (strength < Strength.required) {
|
|
863
|
+
let errplus = this._makeSymbol(SymbolType.Error);
|
|
864
|
+
let errminus = this._makeSymbol(SymbolType.Error);
|
|
865
|
+
tag.marker = errplus;
|
|
866
|
+
tag.other = errminus;
|
|
867
|
+
row.insertSymbol(errplus, -1); // v = eplus - eminus
|
|
868
|
+
row.insertSymbol(errminus, 1.0); // v - eplus + eminus = 0
|
|
869
|
+
objective.insertSymbol(errplus, strength);
|
|
870
|
+
objective.insertSymbol(errminus, strength);
|
|
871
|
+
}
|
|
872
|
+
else {
|
|
873
|
+
let dummy = this._makeSymbol(SymbolType.Dummy);
|
|
874
|
+
tag.marker = dummy;
|
|
875
|
+
row.insertSymbol(dummy);
|
|
922
876
|
}
|
|
877
|
+
break;
|
|
878
|
+
}
|
|
923
879
|
}
|
|
924
880
|
// Ensure the row has a positive constant.
|
|
925
881
|
if (row.constant() < 0.0) {
|
|
926
882
|
row.reverseSign();
|
|
927
883
|
}
|
|
928
|
-
return { row
|
|
929
|
-
}
|
|
884
|
+
return { row, tag };
|
|
885
|
+
}
|
|
930
886
|
/**
|
|
931
887
|
* Choose the subject for solving for the row.
|
|
932
888
|
*
|
|
@@ -943,15 +899,15 @@ var Solver = /** @class */ (function () {
|
|
|
943
899
|
*
|
|
944
900
|
* @private
|
|
945
901
|
*/
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
for (
|
|
949
|
-
|
|
902
|
+
_chooseSubject(row, tag) {
|
|
903
|
+
let cells = row.cells();
|
|
904
|
+
for (let i = 0, n = cells.size(); i < n; ++i) {
|
|
905
|
+
let pair = cells.itemAt(i);
|
|
950
906
|
if (pair.first.type() === SymbolType.External) {
|
|
951
907
|
return pair.first;
|
|
952
908
|
}
|
|
953
909
|
}
|
|
954
|
-
|
|
910
|
+
let type = tag.marker.type();
|
|
955
911
|
if (type === SymbolType.Slack || type === SymbolType.Error) {
|
|
956
912
|
if (row.coefficientFor(tag.marker) < 0.0) {
|
|
957
913
|
return tag.marker;
|
|
@@ -964,7 +920,7 @@ var Solver = /** @class */ (function () {
|
|
|
964
920
|
}
|
|
965
921
|
}
|
|
966
922
|
return INVALID_SYMBOL;
|
|
967
|
-
}
|
|
923
|
+
}
|
|
968
924
|
/**
|
|
969
925
|
* Add the row to the tableau using an artificial variable.
|
|
970
926
|
*
|
|
@@ -972,25 +928,25 @@ var Solver = /** @class */ (function () {
|
|
|
972
928
|
*
|
|
973
929
|
* @private
|
|
974
930
|
*/
|
|
975
|
-
|
|
931
|
+
_addWithArtificialVariable(row) {
|
|
976
932
|
// Create and add the artificial variable to the tableau.
|
|
977
|
-
|
|
933
|
+
let art = this._makeSymbol(SymbolType.Slack);
|
|
978
934
|
this._rowMap.insert(art, row.copy());
|
|
979
935
|
this._artificial = row.copy();
|
|
980
936
|
// Optimize the artificial objective. This is successful
|
|
981
937
|
// only if the artificial objective is optimized to zero.
|
|
982
938
|
this._optimize(this._artificial);
|
|
983
|
-
|
|
939
|
+
let success = nearZero(this._artificial.constant());
|
|
984
940
|
this._artificial = null;
|
|
985
941
|
// If the artificial variable is basic, pivot the row so that
|
|
986
942
|
// it becomes non-basic. If the row is constant, exit early.
|
|
987
|
-
|
|
943
|
+
let pair = this._rowMap.erase(art);
|
|
988
944
|
if (pair !== undefined) {
|
|
989
|
-
|
|
945
|
+
let basicRow = pair.second;
|
|
990
946
|
if (basicRow.isConstant()) {
|
|
991
947
|
return success;
|
|
992
948
|
}
|
|
993
|
-
|
|
949
|
+
let entering = this._anyPivotableSymbol(basicRow);
|
|
994
950
|
if (entering.type() === SymbolType.Invalid) {
|
|
995
951
|
return false; // unsatisfiable (will this ever happen?)
|
|
996
952
|
}
|
|
@@ -999,13 +955,13 @@ var Solver = /** @class */ (function () {
|
|
|
999
955
|
this._rowMap.insert(entering, basicRow);
|
|
1000
956
|
}
|
|
1001
957
|
// Remove the artificial variable from the tableau.
|
|
1002
|
-
|
|
1003
|
-
for (
|
|
958
|
+
let rows = this._rowMap;
|
|
959
|
+
for (let i = 0, n = rows.size(); i < n; ++i) {
|
|
1004
960
|
rows.itemAt(i).second.removeSymbol(art);
|
|
1005
961
|
}
|
|
1006
962
|
this._objective.removeSymbol(art);
|
|
1007
963
|
return success;
|
|
1008
|
-
}
|
|
964
|
+
}
|
|
1009
965
|
/**
|
|
1010
966
|
* Substitute the parametric symbol with the given row.
|
|
1011
967
|
*
|
|
@@ -1014,13 +970,12 @@ var Solver = /** @class */ (function () {
|
|
|
1014
970
|
*
|
|
1015
971
|
* @private
|
|
1016
972
|
*/
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
for (
|
|
1020
|
-
|
|
973
|
+
_substitute(symbol, row) {
|
|
974
|
+
let rows = this._rowMap;
|
|
975
|
+
for (let i = 0, n = rows.size(); i < n; ++i) {
|
|
976
|
+
let pair = rows.itemAt(i);
|
|
1021
977
|
pair.second.substitute(symbol, row);
|
|
1022
|
-
if (pair.second.constant() < 0.0 &&
|
|
1023
|
-
pair.first.type() !== SymbolType.External) {
|
|
978
|
+
if (pair.second.constant() < 0.0 && pair.first.type() !== SymbolType.External) {
|
|
1024
979
|
this._infeasibleRows.push(pair.first);
|
|
1025
980
|
}
|
|
1026
981
|
}
|
|
@@ -1028,7 +983,7 @@ var Solver = /** @class */ (function () {
|
|
|
1028
983
|
if (this._artificial) {
|
|
1029
984
|
this._artificial.substitute(symbol, row);
|
|
1030
985
|
}
|
|
1031
|
-
}
|
|
986
|
+
}
|
|
1032
987
|
/**
|
|
1033
988
|
* Optimize the system for the given objective function.
|
|
1034
989
|
*
|
|
@@ -1037,23 +992,26 @@ var Solver = /** @class */ (function () {
|
|
|
1037
992
|
*
|
|
1038
993
|
* @private
|
|
1039
994
|
*/
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
995
|
+
_optimize(objective) {
|
|
996
|
+
let iterations = 0;
|
|
997
|
+
while (iterations < this.maxIterations) {
|
|
998
|
+
let entering = this._getEnteringSymbol(objective);
|
|
1043
999
|
if (entering.type() === SymbolType.Invalid) {
|
|
1044
1000
|
return;
|
|
1045
1001
|
}
|
|
1046
|
-
|
|
1002
|
+
let leaving = this._getLeavingSymbol(entering);
|
|
1047
1003
|
if (leaving.type() === SymbolType.Invalid) {
|
|
1048
|
-
throw new Error(
|
|
1004
|
+
throw new Error('the objective is unbounded');
|
|
1049
1005
|
}
|
|
1050
1006
|
// pivot the entering symbol into the basis
|
|
1051
|
-
|
|
1007
|
+
let row = this._rowMap.erase(leaving).second;
|
|
1052
1008
|
row.solveForEx(leaving, entering);
|
|
1053
1009
|
this._substitute(entering, row);
|
|
1054
1010
|
this._rowMap.insert(entering, row);
|
|
1011
|
+
iterations++;
|
|
1055
1012
|
}
|
|
1056
|
-
|
|
1013
|
+
throw new Error('solver iterations exceeded');
|
|
1014
|
+
}
|
|
1057
1015
|
/**
|
|
1058
1016
|
* Optimize the system using the dual of the simplex method.
|
|
1059
1017
|
*
|
|
@@ -1064,26 +1022,26 @@ var Solver = /** @class */ (function () {
|
|
|
1064
1022
|
*
|
|
1065
1023
|
* @private
|
|
1066
1024
|
*/
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1025
|
+
_dualOptimize() {
|
|
1026
|
+
let rows = this._rowMap;
|
|
1027
|
+
let infeasible = this._infeasibleRows;
|
|
1070
1028
|
while (infeasible.length !== 0) {
|
|
1071
|
-
|
|
1072
|
-
|
|
1029
|
+
let leaving = infeasible.pop();
|
|
1030
|
+
let pair = rows.find(leaving);
|
|
1073
1031
|
if (pair !== undefined && pair.second.constant() < 0.0) {
|
|
1074
|
-
|
|
1032
|
+
let entering = this._getDualEnteringSymbol(pair.second);
|
|
1075
1033
|
if (entering.type() === SymbolType.Invalid) {
|
|
1076
|
-
throw new Error(
|
|
1034
|
+
throw new Error('dual optimize failed');
|
|
1077
1035
|
}
|
|
1078
1036
|
// pivot the entering symbol into the basis
|
|
1079
|
-
|
|
1037
|
+
let row = pair.second;
|
|
1080
1038
|
rows.erase(leaving);
|
|
1081
1039
|
row.solveForEx(leaving, entering);
|
|
1082
1040
|
this._substitute(entering, row);
|
|
1083
1041
|
rows.insert(entering, row);
|
|
1084
1042
|
}
|
|
1085
1043
|
}
|
|
1086
|
-
}
|
|
1044
|
+
}
|
|
1087
1045
|
/**
|
|
1088
1046
|
* Compute the entering variable for a pivot operation.
|
|
1089
1047
|
*
|
|
@@ -1094,17 +1052,17 @@ var Solver = /** @class */ (function () {
|
|
|
1094
1052
|
*
|
|
1095
1053
|
* @private
|
|
1096
1054
|
*/
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
for (
|
|
1100
|
-
|
|
1101
|
-
|
|
1055
|
+
_getEnteringSymbol(objective) {
|
|
1056
|
+
let cells = objective.cells();
|
|
1057
|
+
for (let i = 0, n = cells.size(); i < n; ++i) {
|
|
1058
|
+
let pair = cells.itemAt(i);
|
|
1059
|
+
let symbol = pair.first;
|
|
1102
1060
|
if (pair.second < 0.0 && symbol.type() !== SymbolType.Dummy) {
|
|
1103
1061
|
return symbol;
|
|
1104
1062
|
}
|
|
1105
1063
|
}
|
|
1106
1064
|
return INVALID_SYMBOL;
|
|
1107
|
-
}
|
|
1065
|
+
}
|
|
1108
1066
|
/**
|
|
1109
1067
|
* Compute the entering symbol for the dual optimize operation.
|
|
1110
1068
|
*
|
|
@@ -1116,17 +1074,17 @@ var Solver = /** @class */ (function () {
|
|
|
1116
1074
|
*
|
|
1117
1075
|
* @private
|
|
1118
1076
|
*/
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
for (
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1077
|
+
_getDualEnteringSymbol(row) {
|
|
1078
|
+
let ratio = Number.MAX_VALUE;
|
|
1079
|
+
let entering = INVALID_SYMBOL;
|
|
1080
|
+
let cells = row.cells();
|
|
1081
|
+
for (let i = 0, n = cells.size(); i < n; ++i) {
|
|
1082
|
+
let pair = cells.itemAt(i);
|
|
1083
|
+
let symbol = pair.first;
|
|
1084
|
+
let c = pair.second;
|
|
1127
1085
|
if (c > 0.0 && symbol.type() !== SymbolType.Dummy) {
|
|
1128
|
-
|
|
1129
|
-
|
|
1086
|
+
let coeff = this._objective.coefficientFor(symbol);
|
|
1087
|
+
let r = coeff / c;
|
|
1130
1088
|
if (r < ratio) {
|
|
1131
1089
|
ratio = r;
|
|
1132
1090
|
entering = symbol;
|
|
@@ -1134,7 +1092,7 @@ var Solver = /** @class */ (function () {
|
|
|
1134
1092
|
}
|
|
1135
1093
|
}
|
|
1136
1094
|
return entering;
|
|
1137
|
-
}
|
|
1095
|
+
}
|
|
1138
1096
|
/**
|
|
1139
1097
|
* Compute the symbol for pivot exit row.
|
|
1140
1098
|
*
|
|
@@ -1145,18 +1103,18 @@ var Solver = /** @class */ (function () {
|
|
|
1145
1103
|
*
|
|
1146
1104
|
* @private
|
|
1147
1105
|
*/
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
for (
|
|
1153
|
-
|
|
1154
|
-
|
|
1106
|
+
_getLeavingSymbol(entering) {
|
|
1107
|
+
let ratio = Number.MAX_VALUE;
|
|
1108
|
+
let found = INVALID_SYMBOL;
|
|
1109
|
+
let rows = this._rowMap;
|
|
1110
|
+
for (let i = 0, n = rows.size(); i < n; ++i) {
|
|
1111
|
+
let pair = rows.itemAt(i);
|
|
1112
|
+
let symbol = pair.first;
|
|
1155
1113
|
if (symbol.type() !== SymbolType.External) {
|
|
1156
|
-
|
|
1157
|
-
|
|
1114
|
+
let row = pair.second;
|
|
1115
|
+
let temp = row.coefficientFor(entering);
|
|
1158
1116
|
if (temp < 0.0) {
|
|
1159
|
-
|
|
1117
|
+
let temp_ratio = -row.constant() / temp;
|
|
1160
1118
|
if (temp_ratio < ratio) {
|
|
1161
1119
|
ratio = temp_ratio;
|
|
1162
1120
|
found = symbol;
|
|
@@ -1165,7 +1123,7 @@ var Solver = /** @class */ (function () {
|
|
|
1165
1123
|
}
|
|
1166
1124
|
}
|
|
1167
1125
|
return found;
|
|
1168
|
-
}
|
|
1126
|
+
}
|
|
1169
1127
|
/**
|
|
1170
1128
|
* Compute the leaving symbol for a marker variable.
|
|
1171
1129
|
*
|
|
@@ -1187,35 +1145,35 @@ var Solver = /** @class */ (function () {
|
|
|
1187
1145
|
*
|
|
1188
1146
|
* @private
|
|
1189
1147
|
*/
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
for (
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1148
|
+
_getMarkerLeavingSymbol(marker) {
|
|
1149
|
+
let dmax = Number.MAX_VALUE;
|
|
1150
|
+
let r1 = dmax;
|
|
1151
|
+
let r2 = dmax;
|
|
1152
|
+
let invalid = INVALID_SYMBOL;
|
|
1153
|
+
let first = invalid;
|
|
1154
|
+
let second = invalid;
|
|
1155
|
+
let third = invalid;
|
|
1156
|
+
let rows = this._rowMap;
|
|
1157
|
+
for (let i = 0, n = rows.size(); i < n; ++i) {
|
|
1158
|
+
let pair = rows.itemAt(i);
|
|
1159
|
+
let row = pair.second;
|
|
1160
|
+
let c = row.coefficientFor(marker);
|
|
1203
1161
|
if (c === 0.0) {
|
|
1204
1162
|
continue;
|
|
1205
1163
|
}
|
|
1206
|
-
|
|
1164
|
+
let symbol = pair.first;
|
|
1207
1165
|
if (symbol.type() === SymbolType.External) {
|
|
1208
1166
|
third = symbol;
|
|
1209
1167
|
}
|
|
1210
1168
|
else if (c < 0.0) {
|
|
1211
|
-
|
|
1169
|
+
let r = -row.constant() / c;
|
|
1212
1170
|
if (r < r1) {
|
|
1213
1171
|
r1 = r;
|
|
1214
1172
|
first = symbol;
|
|
1215
1173
|
}
|
|
1216
1174
|
}
|
|
1217
1175
|
else {
|
|
1218
|
-
|
|
1176
|
+
let r = row.constant() / c;
|
|
1219
1177
|
if (r < r2) {
|
|
1220
1178
|
r2 = r;
|
|
1221
1179
|
second = symbol;
|
|
@@ -1229,34 +1187,34 @@ var Solver = /** @class */ (function () {
|
|
|
1229
1187
|
return second;
|
|
1230
1188
|
}
|
|
1231
1189
|
return third;
|
|
1232
|
-
}
|
|
1190
|
+
}
|
|
1233
1191
|
/**
|
|
1234
1192
|
* Remove the effects of a constraint on the objective function.
|
|
1235
1193
|
*
|
|
1236
1194
|
* @private
|
|
1237
1195
|
*/
|
|
1238
|
-
|
|
1196
|
+
_removeConstraintEffects(cn, tag) {
|
|
1239
1197
|
if (tag.marker.type() === SymbolType.Error) {
|
|
1240
1198
|
this._removeMarkerEffects(tag.marker, cn.strength());
|
|
1241
1199
|
}
|
|
1242
1200
|
if (tag.other.type() === SymbolType.Error) {
|
|
1243
1201
|
this._removeMarkerEffects(tag.other, cn.strength());
|
|
1244
1202
|
}
|
|
1245
|
-
}
|
|
1203
|
+
}
|
|
1246
1204
|
/**
|
|
1247
1205
|
* Remove the effects of an error marker on the objective function.
|
|
1248
1206
|
*
|
|
1249
1207
|
* @private
|
|
1250
1208
|
*/
|
|
1251
|
-
|
|
1252
|
-
|
|
1209
|
+
_removeMarkerEffects(marker, strength) {
|
|
1210
|
+
let pair = this._rowMap.find(marker);
|
|
1253
1211
|
if (pair !== undefined) {
|
|
1254
1212
|
this._objective.insertRow(pair.second, -strength);
|
|
1255
1213
|
}
|
|
1256
1214
|
else {
|
|
1257
1215
|
this._objective.insertSymbol(marker, -strength);
|
|
1258
1216
|
}
|
|
1259
|
-
}
|
|
1217
|
+
}
|
|
1260
1218
|
/**
|
|
1261
1219
|
* Get the first Slack or Error symbol in the row.
|
|
1262
1220
|
*
|
|
@@ -1264,33 +1222,40 @@ var Solver = /** @class */ (function () {
|
|
|
1264
1222
|
*
|
|
1265
1223
|
* @private
|
|
1266
1224
|
*/
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
for (
|
|
1270
|
-
|
|
1271
|
-
|
|
1225
|
+
_anyPivotableSymbol(row) {
|
|
1226
|
+
let cells = row.cells();
|
|
1227
|
+
for (let i = 0, n = cells.size(); i < n; ++i) {
|
|
1228
|
+
let pair = cells.itemAt(i);
|
|
1229
|
+
let type = pair.first.type();
|
|
1272
1230
|
if (type === SymbolType.Slack || type === SymbolType.Error) {
|
|
1273
1231
|
return pair.first;
|
|
1274
1232
|
}
|
|
1275
1233
|
}
|
|
1276
1234
|
return INVALID_SYMBOL;
|
|
1277
|
-
}
|
|
1235
|
+
}
|
|
1278
1236
|
/**
|
|
1279
1237
|
* Returns a new Symbol of the given type.
|
|
1280
1238
|
*
|
|
1281
1239
|
* @private
|
|
1282
1240
|
*/
|
|
1283
|
-
|
|
1284
|
-
return new Symbol
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
|
|
1241
|
+
_makeSymbol(type) {
|
|
1242
|
+
return new Symbol(type, this._idTick++);
|
|
1243
|
+
}
|
|
1244
|
+
_cnMap = createCnMap();
|
|
1245
|
+
_rowMap = createRowMap();
|
|
1246
|
+
_varMap = createVarMap();
|
|
1247
|
+
_editMap = createEditMap();
|
|
1248
|
+
_infeasibleRows = [];
|
|
1249
|
+
_objective = new Row();
|
|
1250
|
+
_artificial = null;
|
|
1251
|
+
_idTick = 0;
|
|
1252
|
+
}
|
|
1288
1253
|
/**
|
|
1289
1254
|
* Test whether a value is approximately zero.
|
|
1290
1255
|
* @private
|
|
1291
1256
|
*/
|
|
1292
1257
|
function nearZero(value) {
|
|
1293
|
-
|
|
1258
|
+
let eps = 1.0e-8;
|
|
1294
1259
|
return value < 0.0 ? -value < eps : value < eps;
|
|
1295
1260
|
}
|
|
1296
1261
|
/**
|
|
@@ -1337,96 +1302,95 @@ var SymbolType;
|
|
|
1337
1302
|
* An internal class representing a symbol in the solver.
|
|
1338
1303
|
* @private
|
|
1339
1304
|
*/
|
|
1340
|
-
|
|
1305
|
+
class Symbol {
|
|
1341
1306
|
/**
|
|
1342
1307
|
* Construct a new Symbol
|
|
1343
1308
|
*
|
|
1344
1309
|
* @param [type] The type of the symbol.
|
|
1345
1310
|
* @param [id] The unique id number of the symbol.
|
|
1346
1311
|
*/
|
|
1347
|
-
|
|
1312
|
+
constructor(type, id) {
|
|
1348
1313
|
this._id = id;
|
|
1349
1314
|
this._type = type;
|
|
1350
1315
|
}
|
|
1351
1316
|
/**
|
|
1352
1317
|
* Returns the unique id number of the symbol.
|
|
1353
1318
|
*/
|
|
1354
|
-
|
|
1319
|
+
id() {
|
|
1355
1320
|
return this._id;
|
|
1356
|
-
}
|
|
1321
|
+
}
|
|
1357
1322
|
/**
|
|
1358
1323
|
* Returns the type of the symbol.
|
|
1359
1324
|
*/
|
|
1360
|
-
|
|
1325
|
+
type() {
|
|
1361
1326
|
return this._type;
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1327
|
+
}
|
|
1328
|
+
_id;
|
|
1329
|
+
_type;
|
|
1330
|
+
}
|
|
1365
1331
|
/**
|
|
1366
1332
|
* A static invalid symbol
|
|
1367
1333
|
* @private
|
|
1368
1334
|
*/
|
|
1369
|
-
|
|
1335
|
+
let INVALID_SYMBOL = new Symbol(SymbolType.Invalid, -1);
|
|
1370
1336
|
/**
|
|
1371
1337
|
* An internal row class used by the solver.
|
|
1372
1338
|
* @private
|
|
1373
1339
|
*/
|
|
1374
|
-
|
|
1340
|
+
class Row {
|
|
1375
1341
|
/**
|
|
1376
1342
|
* Construct a new Row.
|
|
1377
1343
|
*/
|
|
1378
|
-
|
|
1379
|
-
if (constant === void 0) { constant = 0.0; }
|
|
1380
|
-
this._cellMap = createMap();
|
|
1344
|
+
constructor(constant = 0.0) {
|
|
1381
1345
|
this._constant = constant;
|
|
1382
1346
|
}
|
|
1383
1347
|
/**
|
|
1384
1348
|
* Returns the mapping of symbols to coefficients.
|
|
1385
1349
|
*/
|
|
1386
|
-
|
|
1350
|
+
cells() {
|
|
1387
1351
|
return this._cellMap;
|
|
1388
|
-
}
|
|
1352
|
+
}
|
|
1389
1353
|
/**
|
|
1390
1354
|
* Returns the constant for the row.
|
|
1391
1355
|
*/
|
|
1392
|
-
|
|
1356
|
+
constant() {
|
|
1393
1357
|
return this._constant;
|
|
1394
|
-
}
|
|
1358
|
+
}
|
|
1395
1359
|
/**
|
|
1396
1360
|
* Returns true if the row is a constant value.
|
|
1397
1361
|
*/
|
|
1398
|
-
|
|
1362
|
+
isConstant() {
|
|
1399
1363
|
return this._cellMap.empty();
|
|
1400
|
-
}
|
|
1364
|
+
}
|
|
1401
1365
|
/**
|
|
1402
1366
|
* Returns true if the Row has all dummy symbols.
|
|
1403
1367
|
*/
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
for (
|
|
1407
|
-
|
|
1368
|
+
allDummies() {
|
|
1369
|
+
let cells = this._cellMap;
|
|
1370
|
+
for (let i = 0, n = cells.size(); i < n; ++i) {
|
|
1371
|
+
let pair = cells.itemAt(i);
|
|
1408
1372
|
if (pair.first.type() !== SymbolType.Dummy) {
|
|
1409
1373
|
return false;
|
|
1410
1374
|
}
|
|
1411
1375
|
}
|
|
1412
1376
|
return true;
|
|
1413
|
-
}
|
|
1377
|
+
}
|
|
1414
1378
|
/**
|
|
1415
1379
|
* Create a copy of the row.
|
|
1416
1380
|
*/
|
|
1417
|
-
|
|
1418
|
-
|
|
1381
|
+
copy() {
|
|
1382
|
+
let theCopy = new Row(this._constant);
|
|
1419
1383
|
theCopy._cellMap = this._cellMap.copy();
|
|
1420
1384
|
return theCopy;
|
|
1421
|
-
}
|
|
1385
|
+
}
|
|
1422
1386
|
/**
|
|
1423
1387
|
* Add a constant value to the row constant.
|
|
1424
1388
|
*
|
|
1425
1389
|
* Returns the new value of the constant.
|
|
1426
1390
|
*/
|
|
1427
|
-
|
|
1428
|
-
return this._constant += value;
|
|
1429
|
-
}
|
|
1391
|
+
add(value) {
|
|
1392
|
+
return (this._constant += value);
|
|
1393
|
+
}
|
|
1430
1394
|
/**
|
|
1431
1395
|
* Insert the symbol into the row with the given coefficient.
|
|
1432
1396
|
*
|
|
@@ -1434,13 +1398,12 @@ var Row = /** @class */ (function () {
|
|
|
1434
1398
|
* will be added to the existing coefficient. If the resulting
|
|
1435
1399
|
* coefficient is zero, the symbol will be removed from the row.
|
|
1436
1400
|
*/
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
if (nearZero(pair.second += coefficient)) {
|
|
1401
|
+
insertSymbol(symbol, coefficient = 1.0) {
|
|
1402
|
+
let pair = this._cellMap.setDefault(symbol, () => 0.0);
|
|
1403
|
+
if (nearZero((pair.second += coefficient))) {
|
|
1441
1404
|
this._cellMap.erase(symbol);
|
|
1442
1405
|
}
|
|
1443
|
-
}
|
|
1406
|
+
}
|
|
1444
1407
|
/**
|
|
1445
1408
|
* Insert a row into this row with a given coefficient.
|
|
1446
1409
|
*
|
|
@@ -1449,32 +1412,31 @@ var Row = /** @class */ (function () {
|
|
|
1449
1412
|
* cell with a resulting coefficient of zero will be removed
|
|
1450
1413
|
* from the row.
|
|
1451
1414
|
*/
|
|
1452
|
-
|
|
1453
|
-
if (coefficient === void 0) { coefficient = 1.0; }
|
|
1415
|
+
insertRow(other, coefficient = 1.0) {
|
|
1454
1416
|
this._constant += other._constant * coefficient;
|
|
1455
|
-
|
|
1456
|
-
for (
|
|
1457
|
-
|
|
1417
|
+
let cells = other._cellMap;
|
|
1418
|
+
for (let i = 0, n = cells.size(); i < n; ++i) {
|
|
1419
|
+
let pair = cells.itemAt(i);
|
|
1458
1420
|
this.insertSymbol(pair.first, pair.second * coefficient);
|
|
1459
1421
|
}
|
|
1460
|
-
}
|
|
1422
|
+
}
|
|
1461
1423
|
/**
|
|
1462
1424
|
* Remove a symbol from the row.
|
|
1463
1425
|
*/
|
|
1464
|
-
|
|
1426
|
+
removeSymbol(symbol) {
|
|
1465
1427
|
this._cellMap.erase(symbol);
|
|
1466
|
-
}
|
|
1428
|
+
}
|
|
1467
1429
|
/**
|
|
1468
1430
|
* Reverse the sign of the constant and cells in the row.
|
|
1469
1431
|
*/
|
|
1470
|
-
|
|
1432
|
+
reverseSign() {
|
|
1471
1433
|
this._constant = -this._constant;
|
|
1472
|
-
|
|
1473
|
-
for (
|
|
1474
|
-
|
|
1434
|
+
let cells = this._cellMap;
|
|
1435
|
+
for (let i = 0, n = cells.size(); i < n; ++i) {
|
|
1436
|
+
let pair = cells.itemAt(i);
|
|
1475
1437
|
pair.second = -pair.second;
|
|
1476
1438
|
}
|
|
1477
|
-
}
|
|
1439
|
+
}
|
|
1478
1440
|
/**
|
|
1479
1441
|
* Solve the row for the given symbol.
|
|
1480
1442
|
*
|
|
@@ -1487,15 +1449,15 @@ var Row = /** @class */ (function () {
|
|
|
1487
1449
|
*
|
|
1488
1450
|
* The given symbol *must* exist in the row.
|
|
1489
1451
|
*/
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1452
|
+
solveFor(symbol) {
|
|
1453
|
+
let cells = this._cellMap;
|
|
1454
|
+
let pair = cells.erase(symbol);
|
|
1455
|
+
let coeff = -1 / pair.second;
|
|
1494
1456
|
this._constant *= coeff;
|
|
1495
|
-
for (
|
|
1457
|
+
for (let i = 0, n = cells.size(); i < n; ++i) {
|
|
1496
1458
|
cells.itemAt(i).second *= coeff;
|
|
1497
1459
|
}
|
|
1498
|
-
}
|
|
1460
|
+
}
|
|
1499
1461
|
/**
|
|
1500
1462
|
* Solve the row for the given symbols.
|
|
1501
1463
|
*
|
|
@@ -1508,17 +1470,17 @@ var Row = /** @class */ (function () {
|
|
|
1508
1470
|
* The lhs symbol *must not* exist in the row, and the rhs
|
|
1509
1471
|
* symbol must* exist in the row.
|
|
1510
1472
|
*/
|
|
1511
|
-
|
|
1473
|
+
solveForEx(lhs, rhs) {
|
|
1512
1474
|
this.insertSymbol(lhs, -1);
|
|
1513
1475
|
this.solveFor(rhs);
|
|
1514
|
-
}
|
|
1476
|
+
}
|
|
1515
1477
|
/**
|
|
1516
1478
|
* Returns the coefficient for the given symbol.
|
|
1517
1479
|
*/
|
|
1518
|
-
|
|
1519
|
-
|
|
1480
|
+
coefficientFor(symbol) {
|
|
1481
|
+
let pair = this._cellMap.find(symbol);
|
|
1520
1482
|
return pair !== undefined ? pair.second : 0.0;
|
|
1521
|
-
}
|
|
1483
|
+
}
|
|
1522
1484
|
/**
|
|
1523
1485
|
* Substitute a symbol with the data from another row.
|
|
1524
1486
|
*
|
|
@@ -1528,53 +1490,15 @@ var Row = /** @class */ (function () {
|
|
|
1528
1490
|
*
|
|
1529
1491
|
* If the symbol does not exist in the row, this is a no-op.
|
|
1530
1492
|
*/
|
|
1531
|
-
|
|
1532
|
-
|
|
1493
|
+
substitute(symbol, row) {
|
|
1494
|
+
let pair = this._cellMap.erase(symbol);
|
|
1533
1495
|
if (pair !== undefined) {
|
|
1534
1496
|
this.insertRow(row, pair.second);
|
|
1535
1497
|
}
|
|
1536
|
-
}
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
/** @internal */
|
|
1541
|
-
const xSymbol = Symbol("xSymbol");
|
|
1542
|
-
/** @internal */
|
|
1543
|
-
const ySymbol = Symbol("ySymbol");
|
|
1544
|
-
/** @internal */
|
|
1545
|
-
const widthSymbol = Symbol("widthSymbol");
|
|
1546
|
-
/** @internal */
|
|
1547
|
-
const heightSymbol = Symbol("heightSymbol");
|
|
1548
|
-
/** @internal */
|
|
1549
|
-
const addUIElementSymbol = Symbol("addUIElementSymbol");
|
|
1550
|
-
/** @internal */
|
|
1551
|
-
const removeUIElementSymbol = Symbol("removeUIElementSymbol");
|
|
1552
|
-
/** @internal */
|
|
1553
|
-
const addUIConstraintSymbol = Symbol("addConstraintSymbol");
|
|
1554
|
-
/** @internal */
|
|
1555
|
-
const removeUIConstraintSymbol = Symbol("removeUIConstraintSymbol");
|
|
1556
|
-
/** @internal */
|
|
1557
|
-
const addConstraintSymbol = Symbol("addConstraintSymbol");
|
|
1558
|
-
/** @internal */
|
|
1559
|
-
const removeConstraintSymbol = Symbol("removeConstraintSymbol");
|
|
1560
|
-
/** @internal */
|
|
1561
|
-
const addVariableSymbol = Symbol("addVariableSymbol");
|
|
1562
|
-
/** @internal */
|
|
1563
|
-
const removeVariableSymbol = Symbol("removeVariableSymbol");
|
|
1564
|
-
/** @internal */
|
|
1565
|
-
const suggestVariableSymbol = Symbol("suggestVariableSymbol");
|
|
1566
|
-
/** @internal */
|
|
1567
|
-
const disableConstraintSymbol = Symbol("disableConstraintSymbol");
|
|
1568
|
-
/** @internal */
|
|
1569
|
-
const enableConstraintSymbol = Symbol("enableConstraintSymbol");
|
|
1570
|
-
/** @internal */
|
|
1571
|
-
const needsRecalculation = Symbol("needsRecalculation");
|
|
1572
|
-
/** @internal */
|
|
1573
|
-
const renderSymbol = Symbol("renderSymbol");
|
|
1574
|
-
/** @internal */
|
|
1575
|
-
const clickSymbol = Symbol("clickSymbol");
|
|
1576
|
-
/** @internal */
|
|
1577
|
-
const sortSymbol = Symbol("sortSymbol");
|
|
1498
|
+
}
|
|
1499
|
+
_cellMap = createMap();
|
|
1500
|
+
_constant;
|
|
1501
|
+
}
|
|
1578
1502
|
|
|
1579
1503
|
/**
|
|
1580
1504
|
* Defines the screen orientation states for UI constraints.
|
|
@@ -1616,7 +1540,7 @@ function isUIOrientation(obj) {
|
|
|
1616
1540
|
* @returns The provided orientation, or ALWAYS if none was provided
|
|
1617
1541
|
*/
|
|
1618
1542
|
function resolveOrientation(orientation) {
|
|
1619
|
-
return orientation
|
|
1543
|
+
return orientation ?? UIOrientation.ALWAYS;
|
|
1620
1544
|
}
|
|
1621
1545
|
|
|
1622
1546
|
/**
|
|
@@ -1642,14 +1566,14 @@ class UIConstraint {
|
|
|
1642
1566
|
* Useful for debugging and identifying constraints.
|
|
1643
1567
|
*/
|
|
1644
1568
|
this.name = "";
|
|
1645
|
-
this.layer[
|
|
1569
|
+
this.layer["addUIConstraintInternal"](this, elements);
|
|
1646
1570
|
}
|
|
1647
1571
|
/**
|
|
1648
1572
|
* Destroys the constraint, removing it from the layer and solver.
|
|
1649
1573
|
* This should be called when the constraint is no longer needed.
|
|
1650
1574
|
*/
|
|
1651
1575
|
destroy() {
|
|
1652
|
-
this.layer[
|
|
1576
|
+
this.layer["removeUIConstraintInternal"](this);
|
|
1653
1577
|
}
|
|
1654
1578
|
}
|
|
1655
1579
|
|
|
@@ -1711,7 +1635,7 @@ function isUIConstraintPower(obj) {
|
|
|
1711
1635
|
* @returns The provided power level, or P0 (highest) if none was provided
|
|
1712
1636
|
*/
|
|
1713
1637
|
function resolvePower(power) {
|
|
1714
|
-
return power
|
|
1638
|
+
return power ?? UIConstraintPower.P0;
|
|
1715
1639
|
}
|
|
1716
1640
|
/**
|
|
1717
1641
|
* Converts a UIConstraintPower enum value to a Kiwi.js strength value.
|
|
@@ -1790,7 +1714,7 @@ function isUIConstraintRule(obj) {
|
|
|
1790
1714
|
* @returns The provided rule, or EQUAL if none was provided
|
|
1791
1715
|
*/
|
|
1792
1716
|
function resolveRule(rule) {
|
|
1793
|
-
return rule
|
|
1717
|
+
return rule ?? UIConstraintRule.EQUAL;
|
|
1794
1718
|
}
|
|
1795
1719
|
/**
|
|
1796
1720
|
* Converts a UIConstraintRule to the corresponding Kiwi.js Operator.
|
|
@@ -1825,15 +1749,14 @@ class UIHeightConstraint extends UIConstraint {
|
|
|
1825
1749
|
* @param element - The UI element to constrain
|
|
1826
1750
|
* @param options - Configuration options
|
|
1827
1751
|
*/
|
|
1828
|
-
constructor(_private_element, options) {
|
|
1829
|
-
var _a;
|
|
1752
|
+
constructor(_private_element, options = {}) {
|
|
1830
1753
|
super(_private_element.layer, new Set([_private_element]));
|
|
1831
1754
|
this._private_element = _private_element;
|
|
1832
1755
|
this._private_options = {
|
|
1833
|
-
height:
|
|
1834
|
-
power: resolvePower(options
|
|
1835
|
-
rule: resolveRule(options
|
|
1836
|
-
orientation: resolveOrientation(options
|
|
1756
|
+
height: options.height ?? _private_element.height,
|
|
1757
|
+
power: resolvePower(options.power),
|
|
1758
|
+
rule: resolveRule(options.rule),
|
|
1759
|
+
orientation: resolveOrientation(options.orientation),
|
|
1837
1760
|
};
|
|
1838
1761
|
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
1839
1762
|
this._private_options.orientation === this.layer.orientation) {
|
|
@@ -1853,9 +1776,9 @@ class UIHeightConstraint extends UIConstraint {
|
|
|
1853
1776
|
* @param orientation - The new screen orientation
|
|
1854
1777
|
* @internal
|
|
1855
1778
|
*/
|
|
1856
|
-
[
|
|
1779
|
+
["disableConstraintInternal"](newOrientation) {
|
|
1857
1780
|
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
1858
|
-
|
|
1781
|
+
newOrientation !== this._private_options.orientation) {
|
|
1859
1782
|
this.destroyConstraints();
|
|
1860
1783
|
}
|
|
1861
1784
|
}
|
|
@@ -1865,9 +1788,9 @@ class UIHeightConstraint extends UIConstraint {
|
|
|
1865
1788
|
* @param orientation - The new screen orientation
|
|
1866
1789
|
* @internal
|
|
1867
1790
|
*/
|
|
1868
|
-
[
|
|
1791
|
+
["enableConstraintInternal"](newOrientation) {
|
|
1869
1792
|
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
1870
|
-
|
|
1793
|
+
newOrientation === this._private_options.orientation) {
|
|
1871
1794
|
this.buildConstraints();
|
|
1872
1795
|
}
|
|
1873
1796
|
}
|
|
@@ -1879,8 +1802,8 @@ class UIHeightConstraint extends UIConstraint {
|
|
|
1879
1802
|
*
|
|
1880
1803
|
*/
|
|
1881
1804
|
buildConstraints() {
|
|
1882
|
-
this._private_constraint = new Constraint(new Expression(this._private_element[
|
|
1883
|
-
this.layer[
|
|
1805
|
+
this._private_constraint = new Constraint(new Expression(this._private_element["heightInternal"]), convertRuleToOperator(this._private_options.rule), this._private_options.height, convertPowerToStrength(this._private_options.power));
|
|
1806
|
+
this.layer["addConstraintInternal"](this, this._private_constraint);
|
|
1884
1807
|
}
|
|
1885
1808
|
/**
|
|
1886
1809
|
* Removes the height constraint from the constraint solver.
|
|
@@ -1888,7 +1811,7 @@ class UIHeightConstraint extends UIConstraint {
|
|
|
1888
1811
|
*/
|
|
1889
1812
|
destroyConstraints() {
|
|
1890
1813
|
if (this._private_constraint) {
|
|
1891
|
-
this.layer[
|
|
1814
|
+
this.layer["removeConstraintInternal"](this, this._private_constraint);
|
|
1892
1815
|
this._private_constraint = undefined;
|
|
1893
1816
|
}
|
|
1894
1817
|
}
|
|
@@ -1896,7 +1819,6 @@ class UIHeightConstraint extends UIConstraint {
|
|
|
1896
1819
|
|
|
1897
1820
|
class t{constructor(t,i,r=0){this.t=new WeakMap,this.i=new Map,void 0!==t&&(void 0===i?this.i.set(t,r):this.t.set(i,new Map([[t,r]])));}insert(t,i,r=0){if(void 0===i){if(this.i.has(t))return;return void this.i.set(t,r)}const s=this.t.get(i);void 0===s?this.t.set(i,new Map([[t,r]])):s.has(t)||s.set(t,r);}remove(t,i){if(void 0===i)return void this.i.delete(t);const r=this.t.get(i);void 0!==r&&(r.delete(t),0===r.size&&this.t.delete(i));}has(t,i){if(void 0===i)return this.i.has(t);const r=this.t.get(i);return void 0!==r&&r.has(t)}getPriority(t,i){if(void 0===i)return this.i.get(t);const r=this.t.get(i);return void 0!==r?r.get(t):void 0}}class i{constructor(){this.o=new Map;}on(t,i,r,s=0){return this.h(t,false,s,i,r),this}once(t,i,r,s=0){return this.h(t,true,s,i,r),this}off(t,i,r){const s=this.o.get(t);if(void 0===s)return this;s.u&&(s.u=false,s.v=s.v.slice());const o=s.v;if(0===o.length)return this.o.delete(t),this;if(void 0===i){this.o.delete(t);for(let t=0;t<o.length;t++){const i=o[t];s.l.remove(i._,i.p);}return this}{const e=o.length;if(o[0]._===i&&o[0].p===r)return 1===e?this.o.delete(t):o.shift(),this;const n=e-1;if(o[n]._===i&&o[n].p===r)return o.pop(),this;if(e<10||o[0].M===o[n].M)for(let t=1;t<n;t++){const s=o[t];if(s._===i&&s.p===r)return o.splice(t,1),this}else {const t=s.l.getPriority(i,r);if(void 0===t)return this;let e=0,n=o.length-1;for(;e<=n;){const i=e+n>>>1;o[i].M<t?e=i+1:n=i-1;}const c=e;for(n=o.length-1;e<=n;){const i=e+n>>>1;o[i].M<=t?e=i+1:n=i-1;}const h=n;for(let t=c;t<=h;t++)if(o[t]._===i&&o[t].p===r)return o.splice(t,1),this}}return this}emit(t,...i){const r=this.o.get(t);if(void 0===r)return false;if(0===r.v.length)return false;r.u?r.v=r.v.slice():r.u=true;const s=r.v;let o=false;for(let t=0;t<s.length;t++){const r=s[t];r._.apply(r.p,i),r.k&&(o=true,r.m=true);}const e=this.o.get(t);if(void 0===e)return true;e.v===s&&(e.u=false);const n=e.v;if(o){let i=0;for(let t=0;t<n.length;t++){const r=n[t];r.m?e.l.remove(r._,r.p):n[i++]=r;}0===i?this.o.delete(t):n.length=i;}return true}h(i,r,s,o,e){let n=this.o.get(i);if(void 0===n)return void this.o.set(i,{v:[{_:o,p:e,M:s,k:r,m:false}],u:false,l:new t(o,e,s)});if(n.l.has(o,e))throw Error("Event listener already exists");n.l.insert(o,e,s);const c={_:o,p:e,M:s,k:r,m:false};n.u&&(n.u=false,n.v=n.v.slice());{const t=n.v,i=c.M;if(0===t.length||t[t.length-1].M<=i)return void t.push(c);if(t[0].M>=i)return void t.unshift(c);{let r=0,s=t.length;for(;r<s;){const o=r+s>>>1;t[o].M<i?r=o+1:s=o;}t.splice(r,0,c);}}}}
|
|
1898
1821
|
|
|
1899
|
-
var _a$2, _b$2, _c$2;
|
|
1900
1822
|
class UIAnchor extends i {
|
|
1901
1823
|
/**
|
|
1902
1824
|
* Creates a new UI element.
|
|
@@ -1910,54 +1832,53 @@ class UIAnchor extends i {
|
|
|
1910
1832
|
this.layer = layer;
|
|
1911
1833
|
this.object = object;
|
|
1912
1834
|
/** X position variable for constraint system */
|
|
1913
|
-
this[
|
|
1835
|
+
this["xInternal"] = new Variable("x");
|
|
1914
1836
|
/** Y position variable for constraint system */
|
|
1915
|
-
this[
|
|
1837
|
+
this["yInternal"] = new Variable("y");
|
|
1916
1838
|
/** Flag indicating whether the element needs recalculation */
|
|
1917
|
-
this[
|
|
1839
|
+
this["needsRecalculationInternal"] = false;
|
|
1918
1840
|
/** Unique identifier for the element */
|
|
1919
1841
|
this.name = MathUtils.generateUUID();
|
|
1920
1842
|
if (this.object) {
|
|
1921
1843
|
this.object.matrixAutoUpdate = false;
|
|
1922
1844
|
}
|
|
1923
|
-
this.layer[
|
|
1924
|
-
this.layer[
|
|
1925
|
-
this.layer[
|
|
1926
|
-
this[
|
|
1927
|
-
this[
|
|
1928
|
-
this.layer[
|
|
1929
|
-
this.layer[
|
|
1845
|
+
this.layer["addUIElementInternal"](this, object);
|
|
1846
|
+
this.layer["addVariableInternal"](this, this["xInternal"], convertPowerToStrength(UIConstraintPower.P7));
|
|
1847
|
+
this.layer["addVariableInternal"](this, this["yInternal"], convertPowerToStrength(UIConstraintPower.P7));
|
|
1848
|
+
this["xInternal"].setValue(x);
|
|
1849
|
+
this["yInternal"].setValue(y);
|
|
1850
|
+
this.layer["suggestVariableInternal"](this, this["xInternal"], x);
|
|
1851
|
+
this.layer["suggestVariableInternal"](this, this["yInternal"], y);
|
|
1930
1852
|
}
|
|
1931
1853
|
/** Gets the current x position of the anchor */
|
|
1932
1854
|
get x() {
|
|
1933
|
-
return this[
|
|
1855
|
+
return this["xInternal"].value();
|
|
1934
1856
|
}
|
|
1935
1857
|
/** Gets the current y position of the anchor */
|
|
1936
1858
|
get y() {
|
|
1937
|
-
return this[
|
|
1859
|
+
return this["yInternal"].value();
|
|
1938
1860
|
}
|
|
1939
1861
|
/** Gets the current z-index (depth) of the element */
|
|
1940
1862
|
get zIndex() {
|
|
1941
|
-
|
|
1942
|
-
return (_e = (_d = this.object) === null || _d === void 0 ? void 0 : _d.position.z) !== null && _e !== void 0 ? _e : 0;
|
|
1863
|
+
return this.object?.position.z ?? 0;
|
|
1943
1864
|
}
|
|
1944
1865
|
/** Gets whether the element needs recalculation */
|
|
1945
1866
|
get needsRecalculation() {
|
|
1946
|
-
return this[
|
|
1867
|
+
return this["needsRecalculationInternal"];
|
|
1947
1868
|
}
|
|
1948
1869
|
/**
|
|
1949
1870
|
* Sets the x position of the element
|
|
1950
1871
|
* @param value - New x position
|
|
1951
1872
|
*/
|
|
1952
1873
|
set x(value) {
|
|
1953
|
-
this.layer[
|
|
1874
|
+
this.layer["suggestVariableInternal"](this, this["xInternal"], value);
|
|
1954
1875
|
}
|
|
1955
1876
|
/**
|
|
1956
1877
|
* Sets the y position of the element
|
|
1957
1878
|
* @param value - New y position
|
|
1958
1879
|
*/
|
|
1959
1880
|
set y(value) {
|
|
1960
|
-
this.layer[
|
|
1881
|
+
this.layer["suggestVariableInternal"](this, this["yInternal"], value);
|
|
1961
1882
|
}
|
|
1962
1883
|
/**
|
|
1963
1884
|
* Sets the z-index (depth) of the element
|
|
@@ -1967,7 +1888,7 @@ class UIAnchor extends i {
|
|
|
1967
1888
|
if (this.object && this.object.renderOrder !== value) {
|
|
1968
1889
|
this.object.position.z = value;
|
|
1969
1890
|
this.object.renderOrder = value;
|
|
1970
|
-
this.layer[
|
|
1891
|
+
this.layer["sortInternal"]();
|
|
1971
1892
|
this.object.updateMatrix();
|
|
1972
1893
|
}
|
|
1973
1894
|
}
|
|
@@ -1976,9 +1897,9 @@ class UIAnchor extends i {
|
|
|
1976
1897
|
* This should be called when the anchor is no longer needed.
|
|
1977
1898
|
*/
|
|
1978
1899
|
destroy() {
|
|
1979
|
-
this.layer[
|
|
1980
|
-
this.layer[
|
|
1981
|
-
this.layer[
|
|
1900
|
+
this.layer["removeVariableInternal"](this, this["yInternal"]);
|
|
1901
|
+
this.layer["removeVariableInternal"](this, this["xInternal"]);
|
|
1902
|
+
this.layer["removeUIElementInternal"](this);
|
|
1982
1903
|
}
|
|
1983
1904
|
/**
|
|
1984
1905
|
* Internal method called by the rendering system to render this element.
|
|
@@ -1987,7 +1908,7 @@ class UIAnchor extends i {
|
|
|
1987
1908
|
* @param deltaTime - Time elapsed since the last frame
|
|
1988
1909
|
* @internal
|
|
1989
1910
|
*/
|
|
1990
|
-
[
|
|
1911
|
+
["renderInternal"](renderer, deltaTime) {
|
|
1991
1912
|
this.render(renderer, deltaTime);
|
|
1992
1913
|
}
|
|
1993
1914
|
/**
|
|
@@ -1995,11 +1916,11 @@ class UIAnchor extends i {
|
|
|
1995
1916
|
* This is called when the element's position, size, or other properties change.
|
|
1996
1917
|
*/
|
|
1997
1918
|
applyTransformations() {
|
|
1998
|
-
if (this[
|
|
1919
|
+
if (this["needsRecalculationInternal"]) {
|
|
1999
1920
|
if (this.object) {
|
|
2000
1921
|
this.object.updateMatrix();
|
|
2001
1922
|
}
|
|
2002
|
-
this[
|
|
1923
|
+
this["needsRecalculationInternal"] = false;
|
|
2003
1924
|
}
|
|
2004
1925
|
}
|
|
2005
1926
|
}
|
|
@@ -2018,31 +1939,30 @@ const tempMatrixB = new Matrix3();
|
|
|
2018
1939
|
const tempMatrixC = new Matrix3();
|
|
2019
1940
|
const tempMatrixD = new Matrix3();
|
|
2020
1941
|
const tempMatrixE = new Matrix3();
|
|
2021
|
-
const
|
|
2022
|
-
const tempMatrixG = new Matrix4();
|
|
1942
|
+
const tempVectorA = new Vector3();
|
|
2023
1943
|
function applyMicroTransformations(object, micro, x, y, width, height, padding) {
|
|
2024
|
-
const
|
|
2025
|
-
const
|
|
2026
|
-
const
|
|
2027
|
-
const
|
|
2028
|
-
const
|
|
2029
|
-
const
|
|
2030
|
-
const
|
|
2031
|
-
const
|
|
2032
|
-
const
|
|
2033
|
-
const
|
|
2034
|
-
const
|
|
2035
|
-
const
|
|
2036
|
-
|
|
2037
|
-
.
|
|
2038
|
-
.
|
|
2039
|
-
.
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
object.
|
|
1944
|
+
const realX = x - padding;
|
|
1945
|
+
const realY = y - padding;
|
|
1946
|
+
const realWidth = width + padding * 2;
|
|
1947
|
+
const realHeight = height + padding * 2;
|
|
1948
|
+
const anchorOffsetX = realWidth * micro.anchorX;
|
|
1949
|
+
const anchorOffsetY = realHeight * micro.anchorY;
|
|
1950
|
+
const centerX = realX + anchorOffsetX;
|
|
1951
|
+
const centerY = realY + anchorOffsetY;
|
|
1952
|
+
const translateToCenter = tempMatrixA.set(1, 0, -centerX, 0, 1, -centerY, 0, 0, 1);
|
|
1953
|
+
const scale = tempMatrixB.set(micro.scaleX, 0, 0, 0, micro.scaleY, 0, 0, 0, 1);
|
|
1954
|
+
const rotation = tempMatrixC.set(Math.cos(micro.rotation), -Math.sin(micro.rotation), 0, Math.sin(micro.rotation), Math.cos(micro.rotation), 0, 0, 0, 1);
|
|
1955
|
+
const translateFinal = tempMatrixD.set(1, 0, micro.x + centerX, 0, 1, micro.y + centerY, 0, 0, 1);
|
|
1956
|
+
const finalMatrix = tempMatrixE
|
|
1957
|
+
.multiplyMatrices(translateFinal, rotation)
|
|
1958
|
+
.multiply(scale)
|
|
1959
|
+
.multiply(translateToCenter);
|
|
1960
|
+
const point = tempVectorA.set(realX, realY, 1).applyMatrix3(finalMatrix);
|
|
1961
|
+
object.position.x = point.x;
|
|
1962
|
+
object.position.y = point.y;
|
|
1963
|
+
object.rotation.z = micro.rotation;
|
|
1964
|
+
object.scale.x = realWidth * micro.scaleX;
|
|
1965
|
+
object.scale.y = realHeight * micro.scaleY;
|
|
2046
1966
|
}
|
|
2047
1967
|
|
|
2048
1968
|
/**
|
|
@@ -2557,7 +2477,7 @@ class UIComposerInternal {
|
|
|
2557
2477
|
this._private_paddingHasChangedInternal = false;
|
|
2558
2478
|
/** Current padding value in pixels */
|
|
2559
2479
|
this._private_paddingInternal = 0;
|
|
2560
|
-
const
|
|
2480
|
+
const options = {
|
|
2561
2481
|
format: RGBAFormat,
|
|
2562
2482
|
minFilter: LinearFilter,
|
|
2563
2483
|
magFilter: LinearFilter,
|
|
@@ -2565,8 +2485,8 @@ class UIComposerInternal {
|
|
|
2565
2485
|
depthBuffer: false,
|
|
2566
2486
|
stencilBuffer: false,
|
|
2567
2487
|
};
|
|
2568
|
-
this._private_fromRenderTarget = new WebGLRenderTarget(1, 1,
|
|
2569
|
-
this._private_toRenderTarget = new WebGLRenderTarget(1, 1,
|
|
2488
|
+
this._private_fromRenderTarget = new WebGLRenderTarget(1, 1, options);
|
|
2489
|
+
this._private_toRenderTarget = new WebGLRenderTarget(1, 1, options);
|
|
2570
2490
|
this._private_fromRenderTarget.texture.generateMipmaps = false;
|
|
2571
2491
|
this._private_toRenderTarget.texture.generateMipmaps = false;
|
|
2572
2492
|
}
|
|
@@ -2638,13 +2558,12 @@ class UIComposerInternal {
|
|
|
2638
2558
|
this._private_screen.render(renderer, material);
|
|
2639
2559
|
material.blending = originalBlending;
|
|
2640
2560
|
const options = { width, height, padding };
|
|
2641
|
-
for (
|
|
2642
|
-
const pass = this.passes[i];
|
|
2561
|
+
for (const pass of this.passes) {
|
|
2643
2562
|
if (pass.needsUpdate || pass.isValuable) {
|
|
2644
2563
|
this._private_reverseRenderTargets();
|
|
2645
2564
|
renderer.setRenderTarget(this._private_toRenderTarget);
|
|
2646
2565
|
renderer.clear(true, false, false);
|
|
2647
|
-
|
|
2566
|
+
pass.render(renderer, this._private_fromRenderTarget.texture, options);
|
|
2648
2567
|
}
|
|
2649
2568
|
}
|
|
2650
2569
|
this._private_needsUpdateInternal = false;
|
|
@@ -2723,7 +2642,6 @@ class UIComposer {
|
|
|
2723
2642
|
}
|
|
2724
2643
|
}
|
|
2725
2644
|
|
|
2726
|
-
var _a$1, _b$1, _c$1, _d$1, _e;
|
|
2727
2645
|
/**
|
|
2728
2646
|
* Events that can be emitted by UI elements.
|
|
2729
2647
|
*/
|
|
@@ -2759,15 +2677,15 @@ class UIElement extends i {
|
|
|
2759
2677
|
this.layer = layer;
|
|
2760
2678
|
this.object = object;
|
|
2761
2679
|
/** X position variable for constraint system */
|
|
2762
|
-
this[
|
|
2680
|
+
this["xInternal"] = new Variable("x");
|
|
2763
2681
|
/** Y position variable for constraint system */
|
|
2764
|
-
this[
|
|
2682
|
+
this["yInternal"] = new Variable("y");
|
|
2765
2683
|
/** Width variable for constraint system */
|
|
2766
|
-
this[
|
|
2684
|
+
this["widthInternal"] = new Variable("width");
|
|
2767
2685
|
/** Height variable for constraint system */
|
|
2768
|
-
this[
|
|
2686
|
+
this["heightInternal"] = new Variable("height");
|
|
2769
2687
|
/** Flag indicating whether the element needs recalculation */
|
|
2770
|
-
this[
|
|
2688
|
+
this["needsRecalculationInternal"] = false;
|
|
2771
2689
|
/** Unique identifier for the element */
|
|
2772
2690
|
this.name = MathUtils.generateUUID();
|
|
2773
2691
|
/** Internal micro transformation implementation */
|
|
@@ -2779,35 +2697,35 @@ class UIElement extends i {
|
|
|
2779
2697
|
this.micro = new UIMicro(this.microInternal, this);
|
|
2780
2698
|
this.composer = new UIComposer(this.composerInternal);
|
|
2781
2699
|
this.object.matrixAutoUpdate = false;
|
|
2782
|
-
this.layer[
|
|
2783
|
-
this.layer[
|
|
2784
|
-
this.layer[
|
|
2785
|
-
this.layer[
|
|
2786
|
-
this.layer[
|
|
2787
|
-
this[
|
|
2788
|
-
this[
|
|
2789
|
-
this[
|
|
2790
|
-
this[
|
|
2791
|
-
this.layer[
|
|
2792
|
-
this.layer[
|
|
2793
|
-
this.layer[
|
|
2794
|
-
this.layer[
|
|
2700
|
+
this.layer["addUIElementInternal"](this, this.object);
|
|
2701
|
+
this.layer["addVariableInternal"](this, this["xInternal"], convertPowerToStrength(UIConstraintPower.P7));
|
|
2702
|
+
this.layer["addVariableInternal"](this, this["yInternal"], convertPowerToStrength(UIConstraintPower.P7));
|
|
2703
|
+
this.layer["addVariableInternal"](this, this["widthInternal"], convertPowerToStrength(UIConstraintPower.P5));
|
|
2704
|
+
this.layer["addVariableInternal"](this, this["heightInternal"], convertPowerToStrength(UIConstraintPower.P5));
|
|
2705
|
+
this["xInternal"].setValue(x);
|
|
2706
|
+
this["yInternal"].setValue(y);
|
|
2707
|
+
this["widthInternal"].setValue(width);
|
|
2708
|
+
this["heightInternal"].setValue(height);
|
|
2709
|
+
this.layer["suggestVariableInternal"](this, this["xInternal"], x);
|
|
2710
|
+
this.layer["suggestVariableInternal"](this, this["yInternal"], y);
|
|
2711
|
+
this.layer["suggestVariableInternal"](this, this["widthInternal"], width);
|
|
2712
|
+
this.layer["suggestVariableInternal"](this, this["heightInternal"], height);
|
|
2795
2713
|
}
|
|
2796
2714
|
/** Gets the current x position of the element */
|
|
2797
2715
|
get x() {
|
|
2798
|
-
return this[
|
|
2716
|
+
return this["xInternal"].value();
|
|
2799
2717
|
}
|
|
2800
2718
|
/** Gets the current y position of the element */
|
|
2801
2719
|
get y() {
|
|
2802
|
-
return this[
|
|
2720
|
+
return this["yInternal"].value();
|
|
2803
2721
|
}
|
|
2804
2722
|
/** Gets the current width of the element */
|
|
2805
2723
|
get width() {
|
|
2806
|
-
return this[
|
|
2724
|
+
return this["widthInternal"].value();
|
|
2807
2725
|
}
|
|
2808
2726
|
/** Gets the current height of the element */
|
|
2809
2727
|
get height() {
|
|
2810
|
-
return this[
|
|
2728
|
+
return this["heightInternal"].value();
|
|
2811
2729
|
}
|
|
2812
2730
|
/** Gets the current z-index (depth) of the element */
|
|
2813
2731
|
get zIndex() {
|
|
@@ -2819,35 +2737,35 @@ class UIElement extends i {
|
|
|
2819
2737
|
}
|
|
2820
2738
|
/** Gets whether the element needs recalculation */
|
|
2821
2739
|
get needsRecalculation() {
|
|
2822
|
-
return this[
|
|
2740
|
+
return this["needsRecalculationInternal"];
|
|
2823
2741
|
}
|
|
2824
2742
|
/**
|
|
2825
2743
|
* Sets the x position of the element
|
|
2826
2744
|
* @param value - New x position
|
|
2827
2745
|
*/
|
|
2828
2746
|
set x(value) {
|
|
2829
|
-
this.layer[
|
|
2747
|
+
this.layer["suggestVariableInternal"](this, this["xInternal"], value);
|
|
2830
2748
|
}
|
|
2831
2749
|
/**
|
|
2832
2750
|
* Sets the y position of the element
|
|
2833
2751
|
* @param value - New y position
|
|
2834
2752
|
*/
|
|
2835
2753
|
set y(value) {
|
|
2836
|
-
this.layer[
|
|
2754
|
+
this.layer["suggestVariableInternal"](this, this["yInternal"], value);
|
|
2837
2755
|
}
|
|
2838
2756
|
/**
|
|
2839
2757
|
* Sets the width of the element
|
|
2840
2758
|
* @param value - New width
|
|
2841
2759
|
*/
|
|
2842
2760
|
set width(value) {
|
|
2843
|
-
this.layer[
|
|
2761
|
+
this.layer["suggestVariableInternal"](this, this["widthInternal"], value);
|
|
2844
2762
|
}
|
|
2845
2763
|
/**
|
|
2846
2764
|
* Sets the height of the element
|
|
2847
2765
|
* @param value - New height
|
|
2848
2766
|
*/
|
|
2849
2767
|
set height(value) {
|
|
2850
|
-
this.layer[
|
|
2768
|
+
this.layer["suggestVariableInternal"](this, this["heightInternal"], value);
|
|
2851
2769
|
}
|
|
2852
2770
|
/**
|
|
2853
2771
|
* Sets the z-index (depth) of the element
|
|
@@ -2857,7 +2775,7 @@ class UIElement extends i {
|
|
|
2857
2775
|
if (this.object.renderOrder !== value) {
|
|
2858
2776
|
this.object.position.z = value;
|
|
2859
2777
|
this.object.renderOrder = value;
|
|
2860
|
-
this.layer[
|
|
2778
|
+
this.layer["sortInternal"]();
|
|
2861
2779
|
this.object.updateMatrix();
|
|
2862
2780
|
}
|
|
2863
2781
|
}
|
|
@@ -2875,11 +2793,11 @@ class UIElement extends i {
|
|
|
2875
2793
|
*/
|
|
2876
2794
|
destroy() {
|
|
2877
2795
|
this.composerInternal.destroy();
|
|
2878
|
-
this.layer[
|
|
2879
|
-
this.layer[
|
|
2880
|
-
this.layer[
|
|
2881
|
-
this.layer[
|
|
2882
|
-
this.layer[
|
|
2796
|
+
this.layer["removeVariableInternal"](this, this["heightInternal"]);
|
|
2797
|
+
this.layer["removeVariableInternal"](this, this["widthInternal"]);
|
|
2798
|
+
this.layer["removeVariableInternal"](this, this["yInternal"]);
|
|
2799
|
+
this.layer["removeVariableInternal"](this, this["xInternal"]);
|
|
2800
|
+
this.layer["removeUIElementInternal"](this);
|
|
2883
2801
|
}
|
|
2884
2802
|
/**
|
|
2885
2803
|
* Internal method called by the rendering system to render this element.
|
|
@@ -2888,7 +2806,7 @@ class UIElement extends i {
|
|
|
2888
2806
|
* @param deltaTime - Time elapsed since the last frame
|
|
2889
2807
|
* @internal
|
|
2890
2808
|
*/
|
|
2891
|
-
[
|
|
2809
|
+
["renderInternal"](renderer, deltaTime) {
|
|
2892
2810
|
this.render(renderer, deltaTime);
|
|
2893
2811
|
}
|
|
2894
2812
|
/**
|
|
@@ -2899,7 +2817,7 @@ class UIElement extends i {
|
|
|
2899
2817
|
* @returns Whether the click was handled by this element
|
|
2900
2818
|
* @internal
|
|
2901
2819
|
*/
|
|
2902
|
-
[
|
|
2820
|
+
["clickInternal"](x, y) {
|
|
2903
2821
|
return this.click(x, y);
|
|
2904
2822
|
}
|
|
2905
2823
|
/**
|
|
@@ -2907,12 +2825,12 @@ class UIElement extends i {
|
|
|
2907
2825
|
* This is called when the element's position, size, or other properties change.
|
|
2908
2826
|
*/
|
|
2909
2827
|
applyTransformations() {
|
|
2910
|
-
if (this[
|
|
2828
|
+
if (this["needsRecalculationInternal"] ||
|
|
2911
2829
|
this.microInternal.needsRecalculation ||
|
|
2912
2830
|
this.composerInternal.paddingHasChanged) {
|
|
2913
2831
|
applyMicroTransformations(this.object, this.microInternal, this.x, this.y, this.width, this.height, this.composerInternal.padding);
|
|
2914
2832
|
this.object.updateMatrix();
|
|
2915
|
-
this[
|
|
2833
|
+
this["needsRecalculationInternal"] = false;
|
|
2916
2834
|
this.microInternal.needsRecalculation = false;
|
|
2917
2835
|
}
|
|
2918
2836
|
}
|
|
@@ -2936,7 +2854,6 @@ class UIElement extends i {
|
|
|
2936
2854
|
}
|
|
2937
2855
|
}
|
|
2938
2856
|
|
|
2939
|
-
var _a, _b, _c, _d;
|
|
2940
2857
|
const clearColor = new Color(0x000000);
|
|
2941
2858
|
var UILayerEvent;
|
|
2942
2859
|
(function (UILayerEvent) {
|
|
@@ -2947,10 +2864,10 @@ class UILayer extends i {
|
|
|
2947
2864
|
constructor() {
|
|
2948
2865
|
super(...arguments);
|
|
2949
2866
|
this.mode = UIMode.VISIBLE;
|
|
2950
|
-
this[
|
|
2951
|
-
this[
|
|
2952
|
-
this[
|
|
2953
|
-
this[
|
|
2867
|
+
this["xInternal"] = new Variable();
|
|
2868
|
+
this["yInternal"] = new Variable();
|
|
2869
|
+
this["widthInternal"] = new Variable();
|
|
2870
|
+
this["heightInternal"] = new Variable();
|
|
2954
2871
|
this.scene = new Scene();
|
|
2955
2872
|
this.camera = new OrthographicCamera();
|
|
2956
2873
|
this.solver = new Solver();
|
|
@@ -2963,10 +2880,10 @@ class UILayer extends i {
|
|
|
2963
2880
|
return this.orientationPrivate;
|
|
2964
2881
|
}
|
|
2965
2882
|
get width() {
|
|
2966
|
-
return this[
|
|
2883
|
+
return this["widthInternal"].value();
|
|
2967
2884
|
}
|
|
2968
2885
|
get height() {
|
|
2969
|
-
return this[
|
|
2886
|
+
return this["heightInternal"].value();
|
|
2970
2887
|
}
|
|
2971
2888
|
destroy() {
|
|
2972
2889
|
this.solver = undefined;
|
|
@@ -2977,7 +2894,7 @@ class UILayer extends i {
|
|
|
2977
2894
|
element.destroy();
|
|
2978
2895
|
}
|
|
2979
2896
|
}
|
|
2980
|
-
[
|
|
2897
|
+
["addUIElementInternal"](element, object, renderOrder) {
|
|
2981
2898
|
if (this.elements.has(element)) {
|
|
2982
2899
|
throw new Error("Element already added");
|
|
2983
2900
|
}
|
|
@@ -2987,14 +2904,14 @@ class UILayer extends i {
|
|
|
2987
2904
|
constraints: new Set(),
|
|
2988
2905
|
});
|
|
2989
2906
|
if (object) {
|
|
2990
|
-
const zIndex = renderOrder
|
|
2907
|
+
const zIndex = renderOrder ?? this.scene.children.length;
|
|
2991
2908
|
object.position.z = zIndex;
|
|
2992
2909
|
object.renderOrder = zIndex;
|
|
2993
2910
|
this.scene.add(object);
|
|
2994
|
-
this[
|
|
2911
|
+
this["sortInternal"]();
|
|
2995
2912
|
}
|
|
2996
2913
|
}
|
|
2997
|
-
[
|
|
2914
|
+
["removeUIElementInternal"](element) {
|
|
2998
2915
|
const dependencies = this.elements.get(element);
|
|
2999
2916
|
if (dependencies === undefined) {
|
|
3000
2917
|
throw new Error("Element not found");
|
|
@@ -3010,7 +2927,7 @@ class UILayer extends i {
|
|
|
3010
2927
|
this.scene.remove(dependencies.object);
|
|
3011
2928
|
}
|
|
3012
2929
|
}
|
|
3013
|
-
[
|
|
2930
|
+
["addUIConstraintInternal"](constraint, elements) {
|
|
3014
2931
|
if (this.constraints.has(constraint)) {
|
|
3015
2932
|
throw new Error("Constraint already added");
|
|
3016
2933
|
}
|
|
@@ -3030,7 +2947,7 @@ class UILayer extends i {
|
|
|
3030
2947
|
constraints: new Set(),
|
|
3031
2948
|
});
|
|
3032
2949
|
}
|
|
3033
|
-
[
|
|
2950
|
+
["removeUIConstraintInternal"](constraint) {
|
|
3034
2951
|
const dependencies = this.constraints.get(constraint);
|
|
3035
2952
|
if (dependencies === undefined) {
|
|
3036
2953
|
throw new Error("Constraint not found");
|
|
@@ -3053,8 +2970,7 @@ class UILayer extends i {
|
|
|
3053
2970
|
}
|
|
3054
2971
|
this.constraints.delete(constraint);
|
|
3055
2972
|
}
|
|
3056
|
-
[
|
|
3057
|
-
var _e;
|
|
2973
|
+
["addConstraintInternal"](owner, constraint) {
|
|
3058
2974
|
const dependencies = this.constraints.get(owner);
|
|
3059
2975
|
if (dependencies === undefined) {
|
|
3060
2976
|
throw new Error("Before adding constraint you need to add it's owner");
|
|
@@ -3064,15 +2980,14 @@ class UILayer extends i {
|
|
|
3064
2980
|
}
|
|
3065
2981
|
dependencies.constraints.add(constraint);
|
|
3066
2982
|
try {
|
|
3067
|
-
|
|
2983
|
+
this.solver?.addConstraint(constraint);
|
|
3068
2984
|
}
|
|
3069
|
-
catch
|
|
2985
|
+
catch {
|
|
3070
2986
|
this._private_rebuildSolver();
|
|
3071
2987
|
}
|
|
3072
2988
|
this.needsRecalculation = true;
|
|
3073
2989
|
}
|
|
3074
|
-
[
|
|
3075
|
-
var _e;
|
|
2990
|
+
["removeConstraintInternal"](owner, constraint) {
|
|
3076
2991
|
const dependencies = this.constraints.get(owner);
|
|
3077
2992
|
if (dependencies === undefined) {
|
|
3078
2993
|
throw new Error("Before removing constraint you need to add it's owner");
|
|
@@ -3082,15 +2997,14 @@ class UILayer extends i {
|
|
|
3082
2997
|
}
|
|
3083
2998
|
dependencies.constraints.delete(constraint);
|
|
3084
2999
|
try {
|
|
3085
|
-
|
|
3000
|
+
this.solver?.removeConstraint(constraint);
|
|
3086
3001
|
}
|
|
3087
|
-
catch
|
|
3002
|
+
catch {
|
|
3088
3003
|
this._private_rebuildSolver();
|
|
3089
3004
|
}
|
|
3090
3005
|
this.needsRecalculation = true;
|
|
3091
3006
|
}
|
|
3092
|
-
[
|
|
3093
|
-
var _e;
|
|
3007
|
+
["addVariableInternal"](owner, variable, strength) {
|
|
3094
3008
|
const dependencies = owner instanceof UIElement || owner instanceof UIAnchor
|
|
3095
3009
|
? this.elements.get(owner)
|
|
3096
3010
|
: this.constraints.get(owner);
|
|
@@ -3105,15 +3019,14 @@ class UILayer extends i {
|
|
|
3105
3019
|
suggestedValue: variable.value(),
|
|
3106
3020
|
});
|
|
3107
3021
|
try {
|
|
3108
|
-
|
|
3022
|
+
this.solver?.addEditVariable(variable, strength);
|
|
3109
3023
|
}
|
|
3110
|
-
catch
|
|
3024
|
+
catch {
|
|
3111
3025
|
this._private_rebuildSolver();
|
|
3112
3026
|
}
|
|
3113
3027
|
this.needsRecalculation = true;
|
|
3114
3028
|
}
|
|
3115
|
-
[
|
|
3116
|
-
var _e;
|
|
3029
|
+
["removeVariableInternal"](owner, variable) {
|
|
3117
3030
|
const dependencies = owner instanceof UIElement || owner instanceof UIAnchor
|
|
3118
3031
|
? this.elements.get(owner)
|
|
3119
3032
|
: this.constraints.get(owner);
|
|
@@ -3125,15 +3038,14 @@ class UILayer extends i {
|
|
|
3125
3038
|
}
|
|
3126
3039
|
dependencies.variables.delete(variable);
|
|
3127
3040
|
try {
|
|
3128
|
-
|
|
3041
|
+
this.solver?.removeEditVariable(variable);
|
|
3129
3042
|
}
|
|
3130
|
-
catch
|
|
3043
|
+
catch {
|
|
3131
3044
|
this._private_rebuildSolver();
|
|
3132
3045
|
}
|
|
3133
3046
|
this.needsRecalculation = true;
|
|
3134
3047
|
}
|
|
3135
|
-
[
|
|
3136
|
-
var _e;
|
|
3048
|
+
["suggestVariableInternal"](owner, variable, value) {
|
|
3137
3049
|
const dependencies = owner instanceof UIElement || owner instanceof UIAnchor
|
|
3138
3050
|
? this.elements.get(owner)
|
|
3139
3051
|
: this.constraints.get(owner);
|
|
@@ -3147,15 +3059,15 @@ class UILayer extends i {
|
|
|
3147
3059
|
if (description.suggestedValue !== value) {
|
|
3148
3060
|
description.suggestedValue = value;
|
|
3149
3061
|
try {
|
|
3150
|
-
|
|
3062
|
+
this.solver?.suggestValue(variable, value);
|
|
3151
3063
|
}
|
|
3152
|
-
catch
|
|
3064
|
+
catch {
|
|
3153
3065
|
this._private_rebuildSolver();
|
|
3154
3066
|
}
|
|
3155
3067
|
this.needsRecalculation = true;
|
|
3156
3068
|
}
|
|
3157
3069
|
}
|
|
3158
|
-
[
|
|
3070
|
+
["sortInternal"]() {
|
|
3159
3071
|
this.scene.children.sort((a, b) => a.position.z - b.position.z);
|
|
3160
3072
|
for (let i = 0; i < this.scene.children.length; i++) {
|
|
3161
3073
|
const child = this.scene.children[i];
|
|
@@ -3170,7 +3082,6 @@ class UILayer extends i {
|
|
|
3170
3082
|
this.camera.updateMatrix();
|
|
3171
3083
|
}
|
|
3172
3084
|
render(renderer, deltaTime) {
|
|
3173
|
-
var _e;
|
|
3174
3085
|
if (this.mode === UIMode.HIDDEN) {
|
|
3175
3086
|
return;
|
|
3176
3087
|
}
|
|
@@ -3179,13 +3090,13 @@ class UILayer extends i {
|
|
|
3179
3090
|
const originalClearAlpha = renderer.getClearAlpha();
|
|
3180
3091
|
if (this.needsRecalculation) {
|
|
3181
3092
|
this.needsRecalculation = false;
|
|
3182
|
-
|
|
3093
|
+
this.solver?.updateVariables();
|
|
3183
3094
|
for (const element of this.elements.keys()) {
|
|
3184
|
-
element[
|
|
3095
|
+
element["needsRecalculationInternal"] = true;
|
|
3185
3096
|
}
|
|
3186
3097
|
}
|
|
3187
3098
|
for (const element of this.elements.keys()) {
|
|
3188
|
-
element[
|
|
3099
|
+
element["renderInternal"](renderer, deltaTime);
|
|
3189
3100
|
}
|
|
3190
3101
|
renderer.setRenderTarget(originalRenderTarget);
|
|
3191
3102
|
renderer.setClearColor(originalClearColor);
|
|
@@ -3202,7 +3113,7 @@ class UILayer extends i {
|
|
|
3202
3113
|
.filter((e) => e.mode === UIMode.INTERACTIVE)
|
|
3203
3114
|
.sort((a, b) => a.zIndex - b.zIndex);
|
|
3204
3115
|
for (const element of elements) {
|
|
3205
|
-
if (element[
|
|
3116
|
+
if (element["clickInternal"](x, y)) {
|
|
3206
3117
|
break;
|
|
3207
3118
|
}
|
|
3208
3119
|
}
|
|
@@ -3221,31 +3132,30 @@ class UILayer extends i {
|
|
|
3221
3132
|
this.camera.updateProjectionMatrix();
|
|
3222
3133
|
}
|
|
3223
3134
|
rebuildLayerConstraints(width, height) {
|
|
3224
|
-
var _e, _f, _g, _h, _j, _k, _l, _m;
|
|
3225
3135
|
if (this.constraintX) {
|
|
3226
|
-
|
|
3136
|
+
this.solver?.removeConstraint(this.constraintX);
|
|
3227
3137
|
this.constraintX = undefined;
|
|
3228
3138
|
}
|
|
3229
3139
|
if (this.constraintY) {
|
|
3230
|
-
|
|
3140
|
+
this.solver?.removeConstraint(this.constraintY);
|
|
3231
3141
|
this.constraintY = undefined;
|
|
3232
3142
|
}
|
|
3233
3143
|
if (this.constraintW) {
|
|
3234
|
-
|
|
3144
|
+
this.solver?.removeConstraint(this.constraintW);
|
|
3235
3145
|
this.constraintW = undefined;
|
|
3236
3146
|
}
|
|
3237
3147
|
if (this.constraintH) {
|
|
3238
|
-
|
|
3148
|
+
this.solver?.removeConstraint(this.constraintH);
|
|
3239
3149
|
this.constraintH = undefined;
|
|
3240
3150
|
}
|
|
3241
|
-
this.constraintX = new Constraint(new Expression(this[
|
|
3242
|
-
this.constraintY = new Constraint(new Expression(this[
|
|
3243
|
-
this.constraintW = new Constraint(new Expression(this[
|
|
3244
|
-
this.constraintH = new Constraint(new Expression(this[
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3151
|
+
this.constraintX = new Constraint(new Expression(this["xInternal"]), Operator.Eq, 0, Strength.required);
|
|
3152
|
+
this.constraintY = new Constraint(new Expression(this["yInternal"]), Operator.Eq, 0, Strength.required);
|
|
3153
|
+
this.constraintW = new Constraint(new Expression(this["widthInternal"]), Operator.Eq, width, Strength.required);
|
|
3154
|
+
this.constraintH = new Constraint(new Expression(this["heightInternal"]), Operator.Eq, height, Strength.required);
|
|
3155
|
+
this.solver?.addConstraint(this.constraintX);
|
|
3156
|
+
this.solver?.addConstraint(this.constraintY);
|
|
3157
|
+
this.solver?.addConstraint(this.constraintW);
|
|
3158
|
+
this.solver?.addConstraint(this.constraintH);
|
|
3249
3159
|
}
|
|
3250
3160
|
updateOrientation(width, height) {
|
|
3251
3161
|
const lastOrientation = this.orientationPrivate;
|
|
@@ -3254,10 +3164,10 @@ class UILayer extends i {
|
|
|
3254
3164
|
if (lastOrientation !== this.orientationPrivate) {
|
|
3255
3165
|
this.solver = undefined;
|
|
3256
3166
|
for (const constraint of this.constraints.keys()) {
|
|
3257
|
-
constraint[
|
|
3167
|
+
constraint["enableConstraintInternal"](this.orientationPrivate);
|
|
3258
3168
|
}
|
|
3259
3169
|
for (const constraint of this.constraints.keys()) {
|
|
3260
|
-
constraint[
|
|
3170
|
+
constraint["disableConstraintInternal"](this.orientationPrivate);
|
|
3261
3171
|
}
|
|
3262
3172
|
this.solver = new Solver();
|
|
3263
3173
|
const descriptions = [
|
|
@@ -3336,7 +3246,8 @@ function assertSameLayer(elementOne, elementTwo, message) {
|
|
|
3336
3246
|
}
|
|
3337
3247
|
function assertSize(width, height, message) {
|
|
3338
3248
|
if (width <= 0 || height <= 0) {
|
|
3339
|
-
throw new Error(message
|
|
3249
|
+
throw new Error(message ??
|
|
3250
|
+
`Invalid dimensions: width (${width}) and height (${height}) must both be positive numbers greater than 0`);
|
|
3340
3251
|
}
|
|
3341
3252
|
}
|
|
3342
3253
|
|
|
@@ -3356,26 +3267,25 @@ class UIHorizontalDistanceConstraint extends UIConstraint {
|
|
|
3356
3267
|
*
|
|
3357
3268
|
* @param elementOne - The first element or layer
|
|
3358
3269
|
* @param elementTwo - The second element
|
|
3359
|
-
* @param
|
|
3270
|
+
* @param options - Configuration options
|
|
3360
3271
|
*/
|
|
3361
|
-
constructor(_private_elementOne, _private_elementTwo,
|
|
3362
|
-
var _a, _b, _c;
|
|
3272
|
+
constructor(_private_elementOne, _private_elementTwo, options = {}) {
|
|
3363
3273
|
assertSameLayer(_private_elementOne, _private_elementTwo);
|
|
3364
3274
|
super(_private_elementTwo.layer, new Set(_private_elementOne instanceof UIElement || _private_elementOne instanceof UIAnchor
|
|
3365
3275
|
? [_private_elementOne, _private_elementTwo]
|
|
3366
3276
|
: [_private_elementTwo]));
|
|
3367
3277
|
this._private_elementOne = _private_elementOne;
|
|
3368
3278
|
this._private_elementTwo = _private_elementTwo;
|
|
3369
|
-
this.
|
|
3370
|
-
anchorOne:
|
|
3371
|
-
anchorTwo:
|
|
3372
|
-
distance:
|
|
3373
|
-
power: resolvePower(
|
|
3374
|
-
rule: resolveRule(
|
|
3375
|
-
orientation: resolveOrientation(
|
|
3279
|
+
this._private_options = {
|
|
3280
|
+
anchorOne: options.anchorOne ?? DEFAULT_ANCHOR$3,
|
|
3281
|
+
anchorTwo: options.anchorTwo ?? DEFAULT_ANCHOR$3,
|
|
3282
|
+
distance: options.distance ?? 0,
|
|
3283
|
+
power: resolvePower(options.power),
|
|
3284
|
+
rule: resolveRule(options.rule),
|
|
3285
|
+
orientation: resolveOrientation(options.orientation),
|
|
3376
3286
|
};
|
|
3377
|
-
if (this.
|
|
3378
|
-
this.
|
|
3287
|
+
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
3288
|
+
this._private_options.orientation === this.layer.orientation) {
|
|
3379
3289
|
this.buildConstraints();
|
|
3380
3290
|
}
|
|
3381
3291
|
}
|
|
@@ -3392,9 +3302,9 @@ class UIHorizontalDistanceConstraint extends UIConstraint {
|
|
|
3392
3302
|
* @param orientation - The new screen orientation
|
|
3393
3303
|
* @internal
|
|
3394
3304
|
*/
|
|
3395
|
-
[
|
|
3396
|
-
if (this.
|
|
3397
|
-
orientation !== this.
|
|
3305
|
+
["disableConstraintInternal"](orientation) {
|
|
3306
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3307
|
+
orientation !== this._private_options.orientation) {
|
|
3398
3308
|
this.destroyConstraints();
|
|
3399
3309
|
}
|
|
3400
3310
|
}
|
|
@@ -3404,9 +3314,9 @@ class UIHorizontalDistanceConstraint extends UIConstraint {
|
|
|
3404
3314
|
* @param orientation - The new screen orientation
|
|
3405
3315
|
* @internal
|
|
3406
3316
|
*/
|
|
3407
|
-
[
|
|
3408
|
-
if (this.
|
|
3409
|
-
orientation === this.
|
|
3317
|
+
["enableConstraintInternal"](orientation) {
|
|
3318
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3319
|
+
orientation === this._private_options.orientation) {
|
|
3410
3320
|
this.buildConstraints();
|
|
3411
3321
|
}
|
|
3412
3322
|
}
|
|
@@ -3419,13 +3329,13 @@ class UIHorizontalDistanceConstraint extends UIConstraint {
|
|
|
3419
3329
|
*/
|
|
3420
3330
|
buildConstraints() {
|
|
3421
3331
|
const expressionOne = this._private_elementOne instanceof UIElement || this._private_elementOne instanceof UILayer
|
|
3422
|
-
? new Expression(this._private_elementOne[
|
|
3423
|
-
: new Expression(this._private_elementOne[
|
|
3332
|
+
? new Expression(this._private_elementOne["xInternal"]).plus(new Expression(this._private_elementOne["widthInternal"]).multiply(this._private_options.anchorOne))
|
|
3333
|
+
: new Expression(this._private_elementOne["xInternal"]);
|
|
3424
3334
|
const expressionTwo = this._private_elementTwo instanceof UIElement
|
|
3425
|
-
? new Expression(this._private_elementTwo[
|
|
3426
|
-
: new Expression(this._private_elementTwo[
|
|
3427
|
-
this._private_constraint = new Constraint(expressionTwo.minus(expressionOne), convertRuleToOperator(this.
|
|
3428
|
-
this.layer[
|
|
3335
|
+
? new Expression(this._private_elementTwo["xInternal"]).plus(new Expression(this._private_elementTwo["widthInternal"]).multiply(this._private_options.anchorTwo))
|
|
3336
|
+
: new Expression(this._private_elementTwo["xInternal"]);
|
|
3337
|
+
this._private_constraint = new Constraint(expressionTwo.minus(expressionOne), convertRuleToOperator(this._private_options.rule), this._private_options.distance, convertPowerToStrength(this._private_options.power));
|
|
3338
|
+
this.layer["addConstraintInternal"](this, this._private_constraint);
|
|
3429
3339
|
}
|
|
3430
3340
|
/**
|
|
3431
3341
|
* Removes the horizontal distance constraint from the constraint solver.
|
|
@@ -3433,7 +3343,7 @@ class UIHorizontalDistanceConstraint extends UIConstraint {
|
|
|
3433
3343
|
*/
|
|
3434
3344
|
destroyConstraints() {
|
|
3435
3345
|
if (this._private_constraint) {
|
|
3436
|
-
this.layer[
|
|
3346
|
+
this.layer["removeConstraintInternal"](this, this._private_constraint);
|
|
3437
3347
|
this._private_constraint = undefined;
|
|
3438
3348
|
}
|
|
3439
3349
|
}
|
|
@@ -3451,24 +3361,23 @@ class UIHorizontalProportionConstraint extends UIConstraint {
|
|
|
3451
3361
|
*
|
|
3452
3362
|
* @param elementOne - The reference element or layer
|
|
3453
3363
|
* @param elementTwo - The element to constrain proportionally
|
|
3454
|
-
* @param
|
|
3364
|
+
* @param options - Configuration options
|
|
3455
3365
|
*/
|
|
3456
|
-
constructor(_private_elementOne, _private_elementTwo,
|
|
3457
|
-
var _a;
|
|
3366
|
+
constructor(_private_elementOne, _private_elementTwo, options = {}) {
|
|
3458
3367
|
assertSameLayer(_private_elementOne, _private_elementTwo);
|
|
3459
3368
|
super(_private_elementTwo.layer, new Set(_private_elementOne instanceof UIElement
|
|
3460
3369
|
? [_private_elementOne, _private_elementTwo]
|
|
3461
3370
|
: [_private_elementTwo]));
|
|
3462
3371
|
this._private_elementOne = _private_elementOne;
|
|
3463
3372
|
this._private_elementTwo = _private_elementTwo;
|
|
3464
|
-
this.
|
|
3465
|
-
proportion:
|
|
3466
|
-
power: resolvePower(
|
|
3467
|
-
rule: resolveRule(
|
|
3468
|
-
orientation: resolveOrientation(
|
|
3373
|
+
this._private_options = {
|
|
3374
|
+
proportion: options.proportion ?? 1,
|
|
3375
|
+
power: resolvePower(options.power),
|
|
3376
|
+
rule: resolveRule(options.rule),
|
|
3377
|
+
orientation: resolveOrientation(options.orientation),
|
|
3469
3378
|
};
|
|
3470
|
-
if (this.
|
|
3471
|
-
this.
|
|
3379
|
+
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
3380
|
+
this._private_options.orientation === this.layer.orientation) {
|
|
3472
3381
|
this.buildConstraints();
|
|
3473
3382
|
}
|
|
3474
3383
|
}
|
|
@@ -3485,9 +3394,9 @@ class UIHorizontalProportionConstraint extends UIConstraint {
|
|
|
3485
3394
|
* @param orientation - The new screen orientation
|
|
3486
3395
|
* @internal
|
|
3487
3396
|
*/
|
|
3488
|
-
[
|
|
3489
|
-
if (this.
|
|
3490
|
-
orientation !== this.
|
|
3397
|
+
["disableConstraintInternal"](orientation) {
|
|
3398
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3399
|
+
orientation !== this._private_options.orientation) {
|
|
3491
3400
|
this.destroyConstraints();
|
|
3492
3401
|
}
|
|
3493
3402
|
}
|
|
@@ -3497,9 +3406,9 @@ class UIHorizontalProportionConstraint extends UIConstraint {
|
|
|
3497
3406
|
* @param orientation - The new screen orientation
|
|
3498
3407
|
* @internal
|
|
3499
3408
|
*/
|
|
3500
|
-
[
|
|
3501
|
-
if (this.
|
|
3502
|
-
orientation === this.
|
|
3409
|
+
["enableConstraintInternal"](orientation) {
|
|
3410
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3411
|
+
orientation === this._private_options.orientation) {
|
|
3503
3412
|
this.buildConstraints();
|
|
3504
3413
|
}
|
|
3505
3414
|
}
|
|
@@ -3511,10 +3420,10 @@ class UIHorizontalProportionConstraint extends UIConstraint {
|
|
|
3511
3420
|
*
|
|
3512
3421
|
*/
|
|
3513
3422
|
buildConstraints() {
|
|
3514
|
-
const expressionOne = new Expression(this._private_elementOne[
|
|
3515
|
-
const expressionTwo = new Expression(this._private_elementTwo[
|
|
3516
|
-
this._private_constraint = new Constraint(expressionOne.minus(expressionTwo), convertRuleToOperator(this.
|
|
3517
|
-
this.layer[
|
|
3423
|
+
const expressionOne = new Expression(this._private_elementOne["widthInternal"]).multiply(this._private_options.proportion);
|
|
3424
|
+
const expressionTwo = new Expression(this._private_elementTwo["widthInternal"]);
|
|
3425
|
+
this._private_constraint = new Constraint(expressionOne.minus(expressionTwo), convertRuleToOperator(this._private_options.rule), 0, convertPowerToStrength(this._private_options.power));
|
|
3426
|
+
this.layer["addConstraintInternal"](this, this._private_constraint);
|
|
3518
3427
|
}
|
|
3519
3428
|
/**
|
|
3520
3429
|
* Removes the horizontal proportion constraint from the constraint solver.
|
|
@@ -3522,7 +3431,7 @@ class UIHorizontalProportionConstraint extends UIConstraint {
|
|
|
3522
3431
|
*/
|
|
3523
3432
|
destroyConstraints() {
|
|
3524
3433
|
if (this._private_constraint) {
|
|
3525
|
-
this.layer[
|
|
3434
|
+
this.layer["removeConstraintInternal"](this, this._private_constraint);
|
|
3526
3435
|
this._private_constraint = undefined;
|
|
3527
3436
|
}
|
|
3528
3437
|
}
|
|
@@ -3544,26 +3453,25 @@ class UIVerticalDistanceConstraint extends UIConstraint {
|
|
|
3544
3453
|
*
|
|
3545
3454
|
* @param elementOne - The first element or layer
|
|
3546
3455
|
* @param elementTwo - The second element
|
|
3547
|
-
* @param
|
|
3456
|
+
* @param options - Configuration options
|
|
3548
3457
|
*/
|
|
3549
|
-
constructor(_private_elementOne, _private_elementTwo,
|
|
3550
|
-
var _a, _b, _c;
|
|
3458
|
+
constructor(_private_elementOne, _private_elementTwo, options = {}) {
|
|
3551
3459
|
assertSameLayer(_private_elementOne, _private_elementTwo);
|
|
3552
3460
|
super(_private_elementTwo.layer, new Set(_private_elementOne instanceof UIElement || _private_elementOne instanceof UIAnchor
|
|
3553
3461
|
? [_private_elementOne, _private_elementTwo]
|
|
3554
3462
|
: [_private_elementTwo]));
|
|
3555
3463
|
this._private_elementOne = _private_elementOne;
|
|
3556
3464
|
this._private_elementTwo = _private_elementTwo;
|
|
3557
|
-
this.
|
|
3558
|
-
anchorOne:
|
|
3559
|
-
anchorTwo:
|
|
3560
|
-
distance:
|
|
3561
|
-
power: resolvePower(
|
|
3562
|
-
rule: resolveRule(
|
|
3563
|
-
orientation: resolveOrientation(
|
|
3465
|
+
this._private_options = {
|
|
3466
|
+
anchorOne: options.anchorOne ?? DEFAULT_ANCHOR$2,
|
|
3467
|
+
anchorTwo: options.anchorTwo ?? DEFAULT_ANCHOR$2,
|
|
3468
|
+
distance: options.distance ?? 0,
|
|
3469
|
+
power: resolvePower(options.power),
|
|
3470
|
+
rule: resolveRule(options.rule),
|
|
3471
|
+
orientation: resolveOrientation(options.orientation),
|
|
3564
3472
|
};
|
|
3565
|
-
if (this.
|
|
3566
|
-
this.
|
|
3473
|
+
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
3474
|
+
this._private_options.orientation === this.layer.orientation) {
|
|
3567
3475
|
this.buildConstraints();
|
|
3568
3476
|
}
|
|
3569
3477
|
}
|
|
@@ -3580,9 +3488,9 @@ class UIVerticalDistanceConstraint extends UIConstraint {
|
|
|
3580
3488
|
* @param orientation - The new screen orientation
|
|
3581
3489
|
* @internal
|
|
3582
3490
|
*/
|
|
3583
|
-
[
|
|
3584
|
-
if (this.
|
|
3585
|
-
orientation !== this.
|
|
3491
|
+
["disableConstraintInternal"](orientation) {
|
|
3492
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3493
|
+
orientation !== this._private_options.orientation) {
|
|
3586
3494
|
this.destroyConstraints();
|
|
3587
3495
|
}
|
|
3588
3496
|
}
|
|
@@ -3592,9 +3500,9 @@ class UIVerticalDistanceConstraint extends UIConstraint {
|
|
|
3592
3500
|
* @param orientation - The new screen orientation
|
|
3593
3501
|
* @internal
|
|
3594
3502
|
*/
|
|
3595
|
-
[
|
|
3596
|
-
if (this.
|
|
3597
|
-
orientation === this.
|
|
3503
|
+
["enableConstraintInternal"](orientation) {
|
|
3504
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3505
|
+
orientation === this._private_options.orientation) {
|
|
3598
3506
|
this.buildConstraints();
|
|
3599
3507
|
}
|
|
3600
3508
|
}
|
|
@@ -3607,13 +3515,13 @@ class UIVerticalDistanceConstraint extends UIConstraint {
|
|
|
3607
3515
|
*/
|
|
3608
3516
|
buildConstraints() {
|
|
3609
3517
|
const expressionOne = this._private_elementOne instanceof UIElement || this._private_elementOne instanceof UILayer
|
|
3610
|
-
? new Expression(this._private_elementOne[
|
|
3611
|
-
: new Expression(this._private_elementOne[
|
|
3518
|
+
? new Expression(this._private_elementOne["yInternal"]).plus(new Expression(this._private_elementOne["heightInternal"]).multiply(this._private_options.anchorOne))
|
|
3519
|
+
: new Expression(this._private_elementOne["yInternal"]);
|
|
3612
3520
|
const expressionTwo = this._private_elementTwo instanceof UIElement
|
|
3613
|
-
? new Expression(this._private_elementTwo[
|
|
3614
|
-
: new Expression(this._private_elementTwo[
|
|
3615
|
-
this._private_constraint = new Constraint(expressionTwo.minus(expressionOne), convertRuleToOperator(this.
|
|
3616
|
-
this.layer[
|
|
3521
|
+
? new Expression(this._private_elementTwo["yInternal"]).plus(new Expression(this._private_elementTwo["heightInternal"]).multiply(this._private_options.anchorTwo))
|
|
3522
|
+
: new Expression(this._private_elementTwo["yInternal"]);
|
|
3523
|
+
this._private_constraint = new Constraint(expressionTwo.minus(expressionOne), convertRuleToOperator(this._private_options.rule), this._private_options.distance, convertPowerToStrength(this._private_options.power));
|
|
3524
|
+
this.layer["addConstraintInternal"](this, this._private_constraint);
|
|
3617
3525
|
}
|
|
3618
3526
|
/**
|
|
3619
3527
|
* Removes the vertical distance constraint from the constraint solver.
|
|
@@ -3621,7 +3529,7 @@ class UIVerticalDistanceConstraint extends UIConstraint {
|
|
|
3621
3529
|
*/
|
|
3622
3530
|
destroyConstraints() {
|
|
3623
3531
|
if (this._private_constraint) {
|
|
3624
|
-
this.layer[
|
|
3532
|
+
this.layer["removeConstraintInternal"](this, this._private_constraint);
|
|
3625
3533
|
this._private_constraint = undefined;
|
|
3626
3534
|
}
|
|
3627
3535
|
}
|
|
@@ -3639,24 +3547,23 @@ class UIVerticalProportionConstraint extends UIConstraint {
|
|
|
3639
3547
|
*
|
|
3640
3548
|
* @param elementOne - The reference element or layer
|
|
3641
3549
|
* @param elementTwo - The element to constrain proportionally
|
|
3642
|
-
* @param
|
|
3550
|
+
* @param options - Configuration options
|
|
3643
3551
|
*/
|
|
3644
|
-
constructor(_private_elementOne, _private_elementTwo,
|
|
3645
|
-
var _a;
|
|
3552
|
+
constructor(_private_elementOne, _private_elementTwo, options = {}) {
|
|
3646
3553
|
assertSameLayer(_private_elementOne, _private_elementTwo);
|
|
3647
3554
|
super(_private_elementTwo.layer, new Set(_private_elementOne instanceof UIElement
|
|
3648
3555
|
? [_private_elementOne, _private_elementTwo]
|
|
3649
3556
|
: [_private_elementTwo]));
|
|
3650
3557
|
this._private_elementOne = _private_elementOne;
|
|
3651
3558
|
this._private_elementTwo = _private_elementTwo;
|
|
3652
|
-
this.
|
|
3653
|
-
proportion:
|
|
3654
|
-
power: resolvePower(
|
|
3655
|
-
rule: resolveRule(
|
|
3656
|
-
orientation: resolveOrientation(
|
|
3559
|
+
this._private_options = {
|
|
3560
|
+
proportion: options.proportion ?? 1,
|
|
3561
|
+
power: resolvePower(options.power),
|
|
3562
|
+
rule: resolveRule(options.rule),
|
|
3563
|
+
orientation: resolveOrientation(options.orientation),
|
|
3657
3564
|
};
|
|
3658
|
-
if (this.
|
|
3659
|
-
this.
|
|
3565
|
+
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
3566
|
+
this._private_options.orientation === this.layer.orientation) {
|
|
3660
3567
|
this.buildConstraints();
|
|
3661
3568
|
}
|
|
3662
3569
|
}
|
|
@@ -3673,9 +3580,9 @@ class UIVerticalProportionConstraint extends UIConstraint {
|
|
|
3673
3580
|
* @param orientation - The new screen orientation
|
|
3674
3581
|
* @internal
|
|
3675
3582
|
*/
|
|
3676
|
-
[
|
|
3677
|
-
if (this.
|
|
3678
|
-
orientation !== this.
|
|
3583
|
+
["disableConstraintInternal"](orientation) {
|
|
3584
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3585
|
+
orientation !== this._private_options.orientation) {
|
|
3679
3586
|
this.destroyConstraints();
|
|
3680
3587
|
}
|
|
3681
3588
|
}
|
|
@@ -3685,9 +3592,9 @@ class UIVerticalProportionConstraint extends UIConstraint {
|
|
|
3685
3592
|
* @param orientation - The new screen orientation
|
|
3686
3593
|
* @internal
|
|
3687
3594
|
*/
|
|
3688
|
-
[
|
|
3689
|
-
if (this.
|
|
3690
|
-
orientation === this.
|
|
3595
|
+
["enableConstraintInternal"](orientation) {
|
|
3596
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3597
|
+
orientation === this._private_options.orientation) {
|
|
3691
3598
|
this.buildConstraints();
|
|
3692
3599
|
}
|
|
3693
3600
|
}
|
|
@@ -3699,10 +3606,10 @@ class UIVerticalProportionConstraint extends UIConstraint {
|
|
|
3699
3606
|
*
|
|
3700
3607
|
*/
|
|
3701
3608
|
buildConstraints() {
|
|
3702
|
-
const expressionOne = new Expression(this._private_elementOne[
|
|
3703
|
-
const expressionTwo = new Expression(this._private_elementTwo[
|
|
3704
|
-
this._private_constraint = new Constraint(expressionOne.minus(expressionTwo), convertRuleToOperator(this.
|
|
3705
|
-
this.layer[
|
|
3609
|
+
const expressionOne = new Expression(this._private_elementOne["heightInternal"]).multiply(this._private_options.proportion);
|
|
3610
|
+
const expressionTwo = new Expression(this._private_elementTwo["heightInternal"]);
|
|
3611
|
+
this._private_constraint = new Constraint(expressionOne.minus(expressionTwo), convertRuleToOperator(this._private_options.rule), 0, convertPowerToStrength(this._private_options.power));
|
|
3612
|
+
this.layer["addConstraintInternal"](this, this._private_constraint);
|
|
3706
3613
|
}
|
|
3707
3614
|
/**
|
|
3708
3615
|
* Removes the vertical proportion constraint from the constraint solver.
|
|
@@ -3710,7 +3617,7 @@ class UIVerticalProportionConstraint extends UIConstraint {
|
|
|
3710
3617
|
*/
|
|
3711
3618
|
destroyConstraints() {
|
|
3712
3619
|
if (this._private_constraint) {
|
|
3713
|
-
this.layer[
|
|
3620
|
+
this.layer["removeConstraintInternal"](this, this._private_constraint);
|
|
3714
3621
|
this._private_constraint = undefined;
|
|
3715
3622
|
}
|
|
3716
3623
|
}
|
|
@@ -3729,15 +3636,14 @@ class UIWidthConstraint extends UIConstraint {
|
|
|
3729
3636
|
* @param element - The UI element to constrain
|
|
3730
3637
|
* @param options - Configuration options
|
|
3731
3638
|
*/
|
|
3732
|
-
constructor(_private_element, options) {
|
|
3733
|
-
var _a;
|
|
3639
|
+
constructor(_private_element, options = {}) {
|
|
3734
3640
|
super(_private_element.layer, new Set([_private_element]));
|
|
3735
3641
|
this._private_element = _private_element;
|
|
3736
3642
|
this._private_options = {
|
|
3737
|
-
width:
|
|
3738
|
-
power: resolvePower(options
|
|
3739
|
-
rule: resolveRule(options
|
|
3740
|
-
orientation: resolveOrientation(options
|
|
3643
|
+
width: options.width ?? _private_element.width,
|
|
3644
|
+
power: resolvePower(options.power),
|
|
3645
|
+
rule: resolveRule(options.rule),
|
|
3646
|
+
orientation: resolveOrientation(options.orientation),
|
|
3741
3647
|
};
|
|
3742
3648
|
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
3743
3649
|
this._private_options.orientation === this.layer.orientation) {
|
|
@@ -3757,9 +3663,9 @@ class UIWidthConstraint extends UIConstraint {
|
|
|
3757
3663
|
* @param orientation - The new screen orientation
|
|
3758
3664
|
* @internal
|
|
3759
3665
|
*/
|
|
3760
|
-
[
|
|
3666
|
+
["disableConstraintInternal"](newOrientation) {
|
|
3761
3667
|
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3762
|
-
|
|
3668
|
+
newOrientation !== this._private_options.orientation) {
|
|
3763
3669
|
this.destroyConstraints();
|
|
3764
3670
|
}
|
|
3765
3671
|
}
|
|
@@ -3769,9 +3675,9 @@ class UIWidthConstraint extends UIConstraint {
|
|
|
3769
3675
|
* @param orientation - The new screen orientation
|
|
3770
3676
|
* @internal
|
|
3771
3677
|
*/
|
|
3772
|
-
[
|
|
3678
|
+
["enableConstraintInternal"](newOrientation) {
|
|
3773
3679
|
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3774
|
-
|
|
3680
|
+
newOrientation === this._private_options.orientation) {
|
|
3775
3681
|
this.buildConstraints();
|
|
3776
3682
|
}
|
|
3777
3683
|
}
|
|
@@ -3783,8 +3689,8 @@ class UIWidthConstraint extends UIConstraint {
|
|
|
3783
3689
|
*
|
|
3784
3690
|
*/
|
|
3785
3691
|
buildConstraints() {
|
|
3786
|
-
this._private_constraint = new Constraint(new Expression(this._private_element[
|
|
3787
|
-
this.layer[
|
|
3692
|
+
this._private_constraint = new Constraint(new Expression(this._private_element["widthInternal"]), convertRuleToOperator(this._private_options.rule), this._private_options.width, convertPowerToStrength(this._private_options.power));
|
|
3693
|
+
this.layer["addConstraintInternal"](this, this._private_constraint);
|
|
3788
3694
|
}
|
|
3789
3695
|
/**
|
|
3790
3696
|
* Removes the width constraint from the constraint solver.
|
|
@@ -3792,7 +3698,7 @@ class UIWidthConstraint extends UIConstraint {
|
|
|
3792
3698
|
*/
|
|
3793
3699
|
destroyConstraints() {
|
|
3794
3700
|
if (this._private_constraint) {
|
|
3795
|
-
this.layer[
|
|
3701
|
+
this.layer["removeConstraintInternal"](this, this._private_constraint);
|
|
3796
3702
|
this._private_constraint = undefined;
|
|
3797
3703
|
}
|
|
3798
3704
|
}
|
|
@@ -3800,57 +3706,54 @@ class UIWidthConstraint extends UIConstraint {
|
|
|
3800
3706
|
|
|
3801
3707
|
class UIConstraint2DBuilder {
|
|
3802
3708
|
static size(element, options = {}) {
|
|
3803
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3804
3709
|
return {
|
|
3805
3710
|
x: new UIWidthConstraint(element, {
|
|
3806
|
-
width:
|
|
3807
|
-
power:
|
|
3808
|
-
rule:
|
|
3809
|
-
orientation:
|
|
3711
|
+
width: options.size?.h,
|
|
3712
|
+
power: options.power?.h,
|
|
3713
|
+
rule: options.rule?.h,
|
|
3714
|
+
orientation: options.orientation?.h,
|
|
3810
3715
|
}),
|
|
3811
3716
|
y: new UIHeightConstraint(element, {
|
|
3812
|
-
height:
|
|
3813
|
-
power:
|
|
3814
|
-
rule:
|
|
3815
|
-
orientation:
|
|
3717
|
+
height: options.size?.v,
|
|
3718
|
+
power: options.power?.v,
|
|
3719
|
+
rule: options.rule?.v,
|
|
3720
|
+
orientation: options.orientation?.v,
|
|
3816
3721
|
}),
|
|
3817
3722
|
};
|
|
3818
3723
|
}
|
|
3819
3724
|
static distance(elementOne, elementTwo, options = {}) {
|
|
3820
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
3821
3725
|
return {
|
|
3822
3726
|
x: new UIHorizontalDistanceConstraint(elementOne, elementTwo, {
|
|
3823
|
-
anchorOne:
|
|
3824
|
-
anchorTwo:
|
|
3825
|
-
distance:
|
|
3826
|
-
power:
|
|
3827
|
-
rule:
|
|
3828
|
-
orientation:
|
|
3727
|
+
anchorOne: options.anchorOne?.h,
|
|
3728
|
+
anchorTwo: options.anchorTwo?.h,
|
|
3729
|
+
distance: options.distance?.h,
|
|
3730
|
+
power: options.power?.h,
|
|
3731
|
+
rule: options.rule?.h,
|
|
3732
|
+
orientation: options.orientation?.h,
|
|
3829
3733
|
}),
|
|
3830
3734
|
y: new UIVerticalDistanceConstraint(elementOne, elementTwo, {
|
|
3831
|
-
anchorOne:
|
|
3832
|
-
anchorTwo:
|
|
3833
|
-
distance:
|
|
3834
|
-
power:
|
|
3835
|
-
rule:
|
|
3836
|
-
orientation:
|
|
3735
|
+
anchorOne: options.anchorOne?.v,
|
|
3736
|
+
anchorTwo: options.anchorTwo?.v,
|
|
3737
|
+
distance: options.distance?.v,
|
|
3738
|
+
power: options.power?.v,
|
|
3739
|
+
rule: options.rule?.v,
|
|
3740
|
+
orientation: options.orientation?.v,
|
|
3837
3741
|
}),
|
|
3838
3742
|
};
|
|
3839
3743
|
}
|
|
3840
3744
|
static proportion(elementOne, elementTwo, options = {}) {
|
|
3841
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3842
3745
|
return {
|
|
3843
3746
|
x: new UIHorizontalProportionConstraint(elementOne, elementTwo, {
|
|
3844
|
-
proportion:
|
|
3845
|
-
power:
|
|
3846
|
-
rule:
|
|
3847
|
-
orientation:
|
|
3747
|
+
proportion: options.proportion?.h,
|
|
3748
|
+
power: options.power?.h,
|
|
3749
|
+
rule: options.rule?.h,
|
|
3750
|
+
orientation: options.orientation?.h,
|
|
3848
3751
|
}),
|
|
3849
3752
|
y: new UIVerticalProportionConstraint(elementOne, elementTwo, {
|
|
3850
|
-
proportion:
|
|
3851
|
-
power:
|
|
3852
|
-
rule:
|
|
3853
|
-
orientation:
|
|
3753
|
+
proportion: options.proportion?.v,
|
|
3754
|
+
power: options.power?.v,
|
|
3755
|
+
rule: options.rule?.v,
|
|
3756
|
+
orientation: options.orientation?.v,
|
|
3854
3757
|
}),
|
|
3855
3758
|
};
|
|
3856
3759
|
}
|
|
@@ -3863,8 +3766,7 @@ var UIConstraintContainerDirection;
|
|
|
3863
3766
|
})(UIConstraintContainerDirection || (UIConstraintContainerDirection = {}));
|
|
3864
3767
|
class UIConstraintContainerBuilder {
|
|
3865
3768
|
static build(container, elementOne, elementTwo, options = {}) {
|
|
3866
|
-
|
|
3867
|
-
const direction = (_a = options.direction) !== null && _a !== void 0 ? _a : UIConstraintContainerDirection.FROM_LEFT_TOP;
|
|
3769
|
+
const direction = options.direction ?? UIConstraintContainerDirection.FROM_LEFT_TOP;
|
|
3868
3770
|
const horizontalDistances = [];
|
|
3869
3771
|
const verticalDistances = [];
|
|
3870
3772
|
horizontalDistances.push(new UIHorizontalDistanceConstraint(container, elementOne, {
|
|
@@ -3966,20 +3868,19 @@ class UIAspectConstraint extends UIConstraint {
|
|
|
3966
3868
|
* Creates a new aspect ratio constraint.
|
|
3967
3869
|
*
|
|
3968
3870
|
* @param element - The UI element to constrain
|
|
3969
|
-
* @param
|
|
3871
|
+
* @param options - Configuration options
|
|
3970
3872
|
*/
|
|
3971
|
-
constructor(_private_element,
|
|
3972
|
-
var _a;
|
|
3873
|
+
constructor(_private_element, options = {}) {
|
|
3973
3874
|
super(_private_element.layer, new Set([_private_element]));
|
|
3974
3875
|
this._private_element = _private_element;
|
|
3975
|
-
this.
|
|
3976
|
-
aspect:
|
|
3977
|
-
power: resolvePower(
|
|
3978
|
-
rule: resolveRule(
|
|
3979
|
-
orientation: resolveOrientation(
|
|
3876
|
+
this._private_options = {
|
|
3877
|
+
aspect: options.aspect ?? this._private_element.width / this._private_element.height,
|
|
3878
|
+
power: resolvePower(options.power),
|
|
3879
|
+
rule: resolveRule(options.rule),
|
|
3880
|
+
orientation: resolveOrientation(options.orientation),
|
|
3980
3881
|
};
|
|
3981
|
-
if (this.
|
|
3982
|
-
this.
|
|
3882
|
+
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
3883
|
+
this._private_options.orientation === this.layer.orientation) {
|
|
3983
3884
|
this.buildConstraints();
|
|
3984
3885
|
}
|
|
3985
3886
|
}
|
|
@@ -3996,9 +3897,9 @@ class UIAspectConstraint extends UIConstraint {
|
|
|
3996
3897
|
* @param newOrientation - The new screen orientation
|
|
3997
3898
|
* @internal
|
|
3998
3899
|
*/
|
|
3999
|
-
[
|
|
4000
|
-
if (this.
|
|
4001
|
-
newOrientation !== this.
|
|
3900
|
+
["disableConstraintInternal"](newOrientation) {
|
|
3901
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3902
|
+
newOrientation !== this._private_options.orientation) {
|
|
4002
3903
|
this.destroyConstraints();
|
|
4003
3904
|
}
|
|
4004
3905
|
}
|
|
@@ -4008,9 +3909,9 @@ class UIAspectConstraint extends UIConstraint {
|
|
|
4008
3909
|
* @param newOrientation - The new screen orientation
|
|
4009
3910
|
* @internal
|
|
4010
3911
|
*/
|
|
4011
|
-
[
|
|
4012
|
-
if (this.
|
|
4013
|
-
newOrientation === this.
|
|
3912
|
+
["enableConstraintInternal"](newOrientation) {
|
|
3913
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3914
|
+
newOrientation === this._private_options.orientation) {
|
|
4014
3915
|
this.buildConstraints();
|
|
4015
3916
|
}
|
|
4016
3917
|
}
|
|
@@ -4022,9 +3923,9 @@ class UIAspectConstraint extends UIConstraint {
|
|
|
4022
3923
|
*
|
|
4023
3924
|
*/
|
|
4024
3925
|
buildConstraints() {
|
|
4025
|
-
const expression = new Expression(this._private_element[
|
|
4026
|
-
this._private_constraint = new Constraint(expression, convertRuleToOperator(this.
|
|
4027
|
-
this.layer[
|
|
3926
|
+
const expression = new Expression(this._private_element["widthInternal"]).plus(new Expression(this._private_element["heightInternal"]).multiply(-this._private_options.aspect));
|
|
3927
|
+
this._private_constraint = new Constraint(expression, convertRuleToOperator(this._private_options.rule), 0, convertPowerToStrength(this._private_options.power));
|
|
3928
|
+
this.layer["addConstraintInternal"](this, this._private_constraint);
|
|
4028
3929
|
}
|
|
4029
3930
|
/**
|
|
4030
3931
|
* Removes the aspect ratio constraint from the constraint solver.
|
|
@@ -4032,7 +3933,7 @@ class UIAspectConstraint extends UIConstraint {
|
|
|
4032
3933
|
*/
|
|
4033
3934
|
destroyConstraints() {
|
|
4034
3935
|
if (this._private_constraint) {
|
|
4035
|
-
this.layer[
|
|
3936
|
+
this.layer["removeConstraintInternal"](this, this._private_constraint);
|
|
4036
3937
|
this._private_constraint = undefined;
|
|
4037
3938
|
}
|
|
4038
3939
|
}
|
|
@@ -4058,24 +3959,23 @@ class UICoverConstraint extends UIConstraint {
|
|
|
4058
3959
|
*
|
|
4059
3960
|
* @param elementOne - The element or layer to be covered (the reference)
|
|
4060
3961
|
* @param elementTwo - The element that will cover the reference
|
|
4061
|
-
* @param
|
|
3962
|
+
* @param options - Configuration options
|
|
4062
3963
|
*/
|
|
4063
|
-
constructor(_private_elementOne, _private_elementTwo,
|
|
4064
|
-
var _a, _b, _c;
|
|
3964
|
+
constructor(_private_elementOne, _private_elementTwo, options = {}) {
|
|
4065
3965
|
assertSameLayer(_private_elementOne, _private_elementTwo);
|
|
4066
3966
|
super(_private_elementTwo.layer, new Set(_private_elementOne instanceof UIElement
|
|
4067
3967
|
? [_private_elementOne, _private_elementTwo]
|
|
4068
3968
|
: [_private_elementTwo]));
|
|
4069
3969
|
this._private_elementOne = _private_elementOne;
|
|
4070
3970
|
this._private_elementTwo = _private_elementTwo;
|
|
4071
|
-
this.
|
|
4072
|
-
isStrict:
|
|
4073
|
-
horizontalAnchor:
|
|
4074
|
-
verticalAnchor:
|
|
4075
|
-
orientation: resolveOrientation(
|
|
3971
|
+
this._private_options = {
|
|
3972
|
+
isStrict: options.isStrict ?? true,
|
|
3973
|
+
horizontalAnchor: options.horizontalAnchor ?? DEFAULT_ANCHOR$1,
|
|
3974
|
+
verticalAnchor: options.verticalAnchor ?? DEFAULT_ANCHOR$1,
|
|
3975
|
+
orientation: resolveOrientation(options.orientation),
|
|
4076
3976
|
};
|
|
4077
|
-
if (this.
|
|
4078
|
-
this.
|
|
3977
|
+
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
3978
|
+
this._private_options.orientation === this.layer.orientation) {
|
|
4079
3979
|
this.buildConstraints();
|
|
4080
3980
|
}
|
|
4081
3981
|
}
|
|
@@ -4092,9 +3992,9 @@ class UICoverConstraint extends UIConstraint {
|
|
|
4092
3992
|
* @param orientation - The new screen orientation
|
|
4093
3993
|
* @internal
|
|
4094
3994
|
*/
|
|
4095
|
-
[
|
|
4096
|
-
if (this.
|
|
4097
|
-
orientation !== this.
|
|
3995
|
+
["disableConstraintInternal"](orientation) {
|
|
3996
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3997
|
+
orientation !== this._private_options.orientation) {
|
|
4098
3998
|
this.destroyConstraints();
|
|
4099
3999
|
}
|
|
4100
4000
|
}
|
|
@@ -4104,9 +4004,9 @@ class UICoverConstraint extends UIConstraint {
|
|
|
4104
4004
|
* @param orientation - The new screen orientation
|
|
4105
4005
|
* @internal
|
|
4106
4006
|
*/
|
|
4107
|
-
[
|
|
4108
|
-
if (this.
|
|
4109
|
-
orientation === this.
|
|
4007
|
+
["enableConstraintInternal"](orientation) {
|
|
4008
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
4009
|
+
orientation === this._private_options.orientation) {
|
|
4110
4010
|
this.buildConstraints();
|
|
4111
4011
|
}
|
|
4112
4012
|
}
|
|
@@ -4122,17 +4022,17 @@ class UICoverConstraint extends UIConstraint {
|
|
|
4122
4022
|
*
|
|
4123
4023
|
*/
|
|
4124
4024
|
buildConstraints() {
|
|
4125
|
-
this._private_constraintX = new Constraint(new Expression(this._private_elementOne[
|
|
4126
|
-
this._private_constraintY = new Constraint(new Expression(this._private_elementOne[
|
|
4127
|
-
this._private_constraintW = new Constraint(new Expression(this._private_elementOne[
|
|
4128
|
-
this._private_constraintH = new Constraint(new Expression(this._private_elementOne[
|
|
4129
|
-
this.layer[
|
|
4130
|
-
this.layer[
|
|
4131
|
-
this.layer[
|
|
4132
|
-
this.layer[
|
|
4133
|
-
if (!this.
|
|
4134
|
-
this._private_constraintStrict = new Constraint(new Expression(this._private_elementOne[
|
|
4135
|
-
this.layer[
|
|
4025
|
+
this._private_constraintX = new Constraint(new Expression(this._private_elementOne["xInternal"]).plus(new Expression(this._private_elementOne["widthInternal"]).multiply(this._private_options.horizontalAnchor)), Operator.Eq, new Expression(this._private_elementTwo["xInternal"]).plus(new Expression(this._private_elementTwo["widthInternal"]).multiply(this._private_options.horizontalAnchor)));
|
|
4026
|
+
this._private_constraintY = new Constraint(new Expression(this._private_elementOne["yInternal"]).plus(new Expression(this._private_elementOne["heightInternal"]).multiply(this._private_options.verticalAnchor)), Operator.Eq, new Expression(this._private_elementTwo["yInternal"]).plus(new Expression(this._private_elementTwo["heightInternal"]).multiply(this._private_options.verticalAnchor)));
|
|
4027
|
+
this._private_constraintW = new Constraint(new Expression(this._private_elementOne["widthInternal"]), Operator.Eq, new Expression(this._private_elementTwo["widthInternal"]));
|
|
4028
|
+
this._private_constraintH = new Constraint(new Expression(this._private_elementOne["heightInternal"]), Operator.Eq, new Expression(this._private_elementTwo["heightInternal"]));
|
|
4029
|
+
this.layer["addConstraintInternal"](this, this._private_constraintX);
|
|
4030
|
+
this.layer["addConstraintInternal"](this, this._private_constraintY);
|
|
4031
|
+
this.layer["addConstraintInternal"](this, this._private_constraintW);
|
|
4032
|
+
this.layer["addConstraintInternal"](this, this._private_constraintH);
|
|
4033
|
+
if (!this._private_options.isStrict) {
|
|
4034
|
+
this._private_constraintStrict = new Constraint(new Expression(this._private_elementOne["heightInternal"]), Operator.Eq, new Expression(this._private_elementTwo["heightInternal"]));
|
|
4035
|
+
this.layer["addConstraintInternal"](this, this._private_constraintStrict);
|
|
4136
4036
|
}
|
|
4137
4037
|
}
|
|
4138
4038
|
/**
|
|
@@ -4141,23 +4041,23 @@ class UICoverConstraint extends UIConstraint {
|
|
|
4141
4041
|
*/
|
|
4142
4042
|
destroyConstraints() {
|
|
4143
4043
|
if (this._private_constraintX) {
|
|
4144
|
-
this.layer[
|
|
4044
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintX);
|
|
4145
4045
|
this._private_constraintX = undefined;
|
|
4146
4046
|
}
|
|
4147
4047
|
if (this._private_constraintY) {
|
|
4148
|
-
this.layer[
|
|
4048
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintY);
|
|
4149
4049
|
this._private_constraintY = undefined;
|
|
4150
4050
|
}
|
|
4151
4051
|
if (this._private_constraintW) {
|
|
4152
|
-
this.layer[
|
|
4052
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintW);
|
|
4153
4053
|
this._private_constraintW = undefined;
|
|
4154
4054
|
}
|
|
4155
4055
|
if (this._private_constraintH) {
|
|
4156
|
-
this.layer[
|
|
4056
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintH);
|
|
4157
4057
|
this._private_constraintH = undefined;
|
|
4158
4058
|
}
|
|
4159
4059
|
if (this._private_constraintStrict) {
|
|
4160
|
-
this.layer[
|
|
4060
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintStrict);
|
|
4161
4061
|
this._private_constraintStrict = undefined;
|
|
4162
4062
|
}
|
|
4163
4063
|
}
|
|
@@ -4183,24 +4083,23 @@ class UIFitConstraint extends UIConstraint {
|
|
|
4183
4083
|
*
|
|
4184
4084
|
* @param elementOne - The element or layer that contains the fitting element (the container)
|
|
4185
4085
|
* @param elementTwo - The element that will fit within the container
|
|
4186
|
-
* @param
|
|
4086
|
+
* @param options - Configuration options
|
|
4187
4087
|
*/
|
|
4188
|
-
constructor(_private_elementOne, _private_elementTwo,
|
|
4189
|
-
var _a, _b, _c;
|
|
4088
|
+
constructor(_private_elementOne, _private_elementTwo, options = {}) {
|
|
4190
4089
|
super(_private_elementTwo.layer, new Set(_private_elementOne instanceof UIElement
|
|
4191
4090
|
? [_private_elementOne, _private_elementTwo]
|
|
4192
4091
|
: [_private_elementTwo]));
|
|
4193
4092
|
this._private_elementOne = _private_elementOne;
|
|
4194
4093
|
this._private_elementTwo = _private_elementTwo;
|
|
4195
4094
|
assertSameLayer(_private_elementOne, _private_elementTwo);
|
|
4196
|
-
this.
|
|
4197
|
-
isStrict:
|
|
4198
|
-
horizontalAnchor:
|
|
4199
|
-
verticalAnchor:
|
|
4200
|
-
orientation: resolveOrientation(
|
|
4095
|
+
this._private_options = {
|
|
4096
|
+
isStrict: options.isStrict ?? true,
|
|
4097
|
+
horizontalAnchor: options.horizontalAnchor ?? DEFAULT_ANCHOR,
|
|
4098
|
+
verticalAnchor: options.verticalAnchor ?? DEFAULT_ANCHOR,
|
|
4099
|
+
orientation: resolveOrientation(options.orientation),
|
|
4201
4100
|
};
|
|
4202
|
-
if (this.
|
|
4203
|
-
this.
|
|
4101
|
+
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
4102
|
+
this._private_options.orientation === this.layer.orientation) {
|
|
4204
4103
|
this.buildConstraints();
|
|
4205
4104
|
}
|
|
4206
4105
|
}
|
|
@@ -4217,9 +4116,9 @@ class UIFitConstraint extends UIConstraint {
|
|
|
4217
4116
|
* @param orientation - The new screen orientation
|
|
4218
4117
|
* @internal
|
|
4219
4118
|
*/
|
|
4220
|
-
[
|
|
4221
|
-
if (this.
|
|
4222
|
-
orientation !== this.
|
|
4119
|
+
["disableConstraintInternal"](orientation) {
|
|
4120
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
4121
|
+
orientation !== this._private_options.orientation) {
|
|
4223
4122
|
this.destroyConstraints();
|
|
4224
4123
|
}
|
|
4225
4124
|
}
|
|
@@ -4229,9 +4128,9 @@ class UIFitConstraint extends UIConstraint {
|
|
|
4229
4128
|
* @param orientation - The new screen orientation
|
|
4230
4129
|
* @internal
|
|
4231
4130
|
*/
|
|
4232
|
-
[
|
|
4233
|
-
if (this.
|
|
4234
|
-
orientation === this.
|
|
4131
|
+
["enableConstraintInternal"](orientation) {
|
|
4132
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
4133
|
+
orientation === this._private_options.orientation) {
|
|
4235
4134
|
this.buildConstraints();
|
|
4236
4135
|
}
|
|
4237
4136
|
}
|
|
@@ -4247,17 +4146,17 @@ class UIFitConstraint extends UIConstraint {
|
|
|
4247
4146
|
*
|
|
4248
4147
|
*/
|
|
4249
4148
|
buildConstraints() {
|
|
4250
|
-
this._private_constraintX = new Constraint(new Expression(this._private_elementOne[
|
|
4251
|
-
this._private_constraintY = new Constraint(new Expression(this._private_elementOne[
|
|
4252
|
-
this._private_constraintW = new Constraint(new Expression(this._private_elementOne[
|
|
4253
|
-
this._private_constraintH = new Constraint(new Expression(this._private_elementOne[
|
|
4254
|
-
this.layer[
|
|
4255
|
-
this.layer[
|
|
4256
|
-
this.layer[
|
|
4257
|
-
this.layer[
|
|
4258
|
-
if (this.
|
|
4259
|
-
this._private_constraintStrict = new Constraint(new Expression(this._private_elementOne[
|
|
4260
|
-
this.layer[
|
|
4149
|
+
this._private_constraintX = new Constraint(new Expression(this._private_elementOne["xInternal"]).plus(new Expression(this._private_elementOne["widthInternal"]).multiply(this._private_options.horizontalAnchor)), Operator.Eq, new Expression(this._private_elementTwo["xInternal"]).plus(new Expression(this._private_elementTwo["widthInternal"]).multiply(this._private_options.horizontalAnchor)));
|
|
4150
|
+
this._private_constraintY = new Constraint(new Expression(this._private_elementOne["yInternal"]).plus(new Expression(this._private_elementOne["heightInternal"]).multiply(this._private_options.verticalAnchor)), Operator.Eq, new Expression(this._private_elementTwo["yInternal"]).plus(new Expression(this._private_elementTwo["heightInternal"]).multiply(this._private_options.verticalAnchor)));
|
|
4151
|
+
this._private_constraintW = new Constraint(new Expression(this._private_elementOne["widthInternal"]), Operator.Ge, new Expression(this._private_elementTwo["widthInternal"]));
|
|
4152
|
+
this._private_constraintH = new Constraint(new Expression(this._private_elementOne["heightInternal"]), Operator.Ge, new Expression(this._private_elementTwo["heightInternal"]));
|
|
4153
|
+
this.layer["addConstraintInternal"](this, this._private_constraintX);
|
|
4154
|
+
this.layer["addConstraintInternal"](this, this._private_constraintY);
|
|
4155
|
+
this.layer["addConstraintInternal"](this, this._private_constraintW);
|
|
4156
|
+
this.layer["addConstraintInternal"](this, this._private_constraintH);
|
|
4157
|
+
if (this._private_options.isStrict) {
|
|
4158
|
+
this._private_constraintStrict = new Constraint(new Expression(this._private_elementOne["heightInternal"]), Operator.Eq, new Expression(this._private_elementTwo["heightInternal"]), Strength.strong);
|
|
4159
|
+
this.layer["addConstraintInternal"](this, this._private_constraintStrict);
|
|
4261
4160
|
}
|
|
4262
4161
|
}
|
|
4263
4162
|
/**
|
|
@@ -4266,23 +4165,23 @@ class UIFitConstraint extends UIConstraint {
|
|
|
4266
4165
|
*/
|
|
4267
4166
|
destroyConstraints() {
|
|
4268
4167
|
if (this._private_constraintX) {
|
|
4269
|
-
this.layer[
|
|
4168
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintX);
|
|
4270
4169
|
this._private_constraintX = undefined;
|
|
4271
4170
|
}
|
|
4272
4171
|
if (this._private_constraintY) {
|
|
4273
|
-
this.layer[
|
|
4172
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintY);
|
|
4274
4173
|
this._private_constraintY = undefined;
|
|
4275
4174
|
}
|
|
4276
4175
|
if (this._private_constraintW) {
|
|
4277
|
-
this.layer[
|
|
4176
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintW);
|
|
4278
4177
|
this._private_constraintW = undefined;
|
|
4279
4178
|
}
|
|
4280
4179
|
if (this._private_constraintH) {
|
|
4281
|
-
this.layer[
|
|
4180
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintH);
|
|
4282
4181
|
this._private_constraintH = undefined;
|
|
4283
4182
|
}
|
|
4284
4183
|
if (this._private_constraintStrict) {
|
|
4285
|
-
this.layer[
|
|
4184
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintStrict);
|
|
4286
4185
|
this._private_constraintStrict = undefined;
|
|
4287
4186
|
}
|
|
4288
4187
|
}
|
|
@@ -4330,9 +4229,8 @@ class UIImage extends UIElement {
|
|
|
4330
4229
|
* @throws Error if the texture has invalid dimensions
|
|
4331
4230
|
*/
|
|
4332
4231
|
constructor(layer, texture) {
|
|
4333
|
-
|
|
4334
|
-
const
|
|
4335
|
-
const height = (_b = texture.image) === null || _b === void 0 ? void 0 : _b.height;
|
|
4232
|
+
const width = texture.image?.width;
|
|
4233
|
+
const height = texture.image?.height;
|
|
4336
4234
|
assertSize(width, height, `Invalid image dimensions - texture "${texture.name || "unnamed"}" has invalid width (${width}) or height (${height}). Image dimensions must be non-zero positive numbers.`);
|
|
4337
4235
|
const material = new UIMaterial(texture);
|
|
4338
4236
|
const object = new Mesh(geometry, material);
|
|
@@ -4564,12 +4462,11 @@ class UIProgress extends UIElement {
|
|
|
4564
4462
|
* @throws Error if either texture has invalid dimensions
|
|
4565
4463
|
*/
|
|
4566
4464
|
constructor(layer, textureForeground, options = {}) {
|
|
4567
|
-
|
|
4568
|
-
const
|
|
4569
|
-
const foregroundHeight = (_b = textureForeground.image) === null || _b === void 0 ? void 0 : _b.height;
|
|
4465
|
+
const foregroundWidth = textureForeground.image?.width;
|
|
4466
|
+
const foregroundHeight = textureForeground.image?.height;
|
|
4570
4467
|
assertSize(foregroundWidth, foregroundHeight, `Invalid image dimensions - texture "${textureForeground.name || "unnamed"}" has invalid width (${foregroundWidth}) or height (${foregroundHeight}). Image dimensions must be non-zero positive numbers.`);
|
|
4571
|
-
const backgroundWidth =
|
|
4572
|
-
const backgroundHeight =
|
|
4468
|
+
const backgroundWidth = options.textureBackground?.image?.width;
|
|
4469
|
+
const backgroundHeight = options.textureBackground?.image?.height;
|
|
4573
4470
|
if (options.textureBackground) {
|
|
4574
4471
|
assertSize(backgroundWidth, backgroundHeight, `Invalid image dimensions - texture "${options.textureBackground.name || "unnamed"}" has invalid width (${backgroundWidth}) or height (${backgroundHeight}). Image dimensions must be non-zero positive numbers.`);
|
|
4575
4472
|
}
|
|
@@ -4602,8 +4499,8 @@ class UIProgress extends UIElement {
|
|
|
4602
4499
|
if (options.foregroundOpacity) {
|
|
4603
4500
|
material.setForegroundOpacity(options.foregroundOpacity);
|
|
4604
4501
|
}
|
|
4605
|
-
const imageWidth = backgroundWidth
|
|
4606
|
-
const imageHeight = foregroundHeight
|
|
4502
|
+
const imageWidth = backgroundWidth ?? foregroundWidth;
|
|
4503
|
+
const imageHeight = foregroundHeight ?? backgroundHeight;
|
|
4607
4504
|
super(layer, object, 0, 0, imageWidth, imageHeight);
|
|
4608
4505
|
this._private_material = material;
|
|
4609
4506
|
this._private_imageWidth = imageWidth;
|
|
@@ -4796,21 +4693,20 @@ class UIScene extends UIElement {
|
|
|
4796
4693
|
* @throws Error if resolution factor is out of valid range or dimensions are invalid
|
|
4797
4694
|
*/
|
|
4798
4695
|
constructor(layer, options = {}) {
|
|
4799
|
-
|
|
4800
|
-
const resolutionFactor = (_a = options.resolutionFactor) !== null && _a !== void 0 ? _a : DEFAULT_RESOLUTION_FACTOR;
|
|
4696
|
+
const resolutionFactor = options.resolutionFactor ?? DEFAULT_RESOLUTION_FACTOR;
|
|
4801
4697
|
if (resolutionFactor < MIN_RESOLUTION_FACTOR ||
|
|
4802
4698
|
resolutionFactor > MAX_RESOLUTION_FACTOR) {
|
|
4803
4699
|
throw new Error(`Invalid resolution factor: ${resolutionFactor}. Must be between ${MIN_RESOLUTION_FACTOR} and ${MAX_RESOLUTION_FACTOR}.`);
|
|
4804
4700
|
}
|
|
4805
|
-
const width =
|
|
4806
|
-
const height =
|
|
4701
|
+
const width = options.width ?? DEFAULT_WIDTH;
|
|
4702
|
+
const height = options.height ?? DEFAULT_HEIGHT;
|
|
4807
4703
|
assertSize(width, height, `Invalid width or height: ${width}x${height}. Must be positive.`);
|
|
4808
4704
|
const renderTarget = new WebGLRenderTarget(width * resolutionFactor, height * resolutionFactor, {
|
|
4809
4705
|
format: RGBAFormat,
|
|
4810
4706
|
minFilter: LinearFilter,
|
|
4811
4707
|
magFilter: LinearFilter,
|
|
4812
4708
|
type: UnsignedByteType,
|
|
4813
|
-
depthBuffer:
|
|
4709
|
+
depthBuffer: options.useDepth ?? DEFAULT_USE_DEPTH,
|
|
4814
4710
|
stencilBuffer: false,
|
|
4815
4711
|
});
|
|
4816
4712
|
const material = new UIMaterial(renderTarget.texture);
|
|
@@ -4818,16 +4714,17 @@ class UIScene extends UIElement {
|
|
|
4818
4714
|
super(layer, object, 0, 0, width, height);
|
|
4819
4715
|
/** Whether the scene needs to be re-rendered on the next frame */
|
|
4820
4716
|
this._private_needsRenderInternal = false;
|
|
4821
|
-
this._private_sceneInternal =
|
|
4717
|
+
this._private_sceneInternal = options.scene ?? new Scene();
|
|
4822
4718
|
this._private_cameraInternal =
|
|
4823
|
-
|
|
4719
|
+
options.camera ??
|
|
4720
|
+
new PerspectiveCamera(DEFAULT_FOV, width / height, DEFAULT_NEAR, DEFAULT_FAR);
|
|
4824
4721
|
this._private_resolutionFactorInternal = resolutionFactor;
|
|
4825
|
-
this._private_updateModeInternal =
|
|
4826
|
-
if (
|
|
4722
|
+
this._private_updateModeInternal = options.updateBehavior ?? DEFAULT_UPDATE_MODE;
|
|
4723
|
+
if (options.renderedByDefault ?? DEFAULT_RENDERED_BY_DEFAULT) {
|
|
4827
4724
|
this._private_needsRenderInternal = true;
|
|
4828
4725
|
}
|
|
4829
|
-
this._private_clearColorInternal =
|
|
4830
|
-
this._private_clearAlphaInternal =
|
|
4726
|
+
this._private_clearColorInternal = options.clearColor ?? DEFAULT_CLEAR_COLOR;
|
|
4727
|
+
this._private_clearAlphaInternal = options.clearAlpha ?? DEFAULT_CLEAR_ALPHA;
|
|
4831
4728
|
this._private_renderTarget = renderTarget;
|
|
4832
4729
|
this._private_material = material;
|
|
4833
4730
|
this.applyTransformations();
|
|
@@ -4981,7 +4878,6 @@ class UIScene extends UIElement {
|
|
|
4981
4878
|
}
|
|
4982
4879
|
|
|
4983
4880
|
function resolvePadding(padding) {
|
|
4984
|
-
var _a, _b, _c, _d;
|
|
4985
4881
|
if (typeof padding === "number") {
|
|
4986
4882
|
return {
|
|
4987
4883
|
left: padding,
|
|
@@ -4991,37 +4887,36 @@ function resolvePadding(padding) {
|
|
|
4991
4887
|
};
|
|
4992
4888
|
}
|
|
4993
4889
|
return {
|
|
4994
|
-
left: Math.max(
|
|
4995
|
-
right: Math.max(
|
|
4996
|
-
top: Math.max(
|
|
4997
|
-
bottom: Math.max(
|
|
4890
|
+
left: Math.max(padding?.left ?? 0, 0),
|
|
4891
|
+
right: Math.max(padding?.right ?? 0, 0),
|
|
4892
|
+
top: Math.max(padding?.top ?? 0, 0),
|
|
4893
|
+
bottom: Math.max(padding?.bottom ?? 0, 0),
|
|
4998
4894
|
};
|
|
4999
4895
|
}
|
|
5000
4896
|
function resolveTextStyle(currentStyle, baseStyle) {
|
|
5001
|
-
|
|
5002
|
-
const
|
|
5003
|
-
const
|
|
5004
|
-
const
|
|
5005
|
-
const strokeWidth = Math.max((_h = (_g = currentStyle === null || currentStyle === void 0 ? void 0 : currentStyle.strokeWidth) !== null && _g !== void 0 ? _g : baseStyle === null || baseStyle === void 0 ? void 0 : baseStyle.strokeWidth) !== null && _h !== void 0 ? _h : 0, 0);
|
|
4897
|
+
const fontSize = Math.max(currentStyle?.fontSize ?? baseStyle?.fontSize ?? 16, 1);
|
|
4898
|
+
const lineHeight = currentStyle?.lineHeight ?? baseStyle?.lineHeight ?? fontSize * 1.2;
|
|
4899
|
+
const shadowBlur = Math.max(currentStyle?.shadowBlur ?? baseStyle?.shadowBlur ?? 0, 0);
|
|
4900
|
+
const strokeWidth = Math.max(currentStyle?.strokeWidth ?? baseStyle?.strokeWidth ?? 0, 0);
|
|
5006
4901
|
return {
|
|
5007
|
-
color:
|
|
5008
|
-
fontFamily:
|
|
4902
|
+
color: currentStyle?.color ?? baseStyle?.color ?? "#000000",
|
|
4903
|
+
fontFamily: currentStyle?.fontFamily ?? baseStyle?.fontFamily ?? "Arial",
|
|
5009
4904
|
fontSize,
|
|
5010
|
-
fontStyle:
|
|
5011
|
-
fontWeight:
|
|
4905
|
+
fontStyle: currentStyle?.fontStyle ?? baseStyle?.fontStyle ?? "normal",
|
|
4906
|
+
fontWeight: currentStyle?.fontWeight ?? baseStyle?.fontWeight ?? "normal",
|
|
5012
4907
|
lineHeight,
|
|
5013
|
-
enableShadow:
|
|
5014
|
-
shadowOffsetX:
|
|
5015
|
-
shadowOffsetY:
|
|
4908
|
+
enableShadow: currentStyle?.enableShadow ?? baseStyle?.enableShadow ?? false,
|
|
4909
|
+
shadowOffsetX: currentStyle?.shadowOffsetX ?? baseStyle?.shadowOffsetX ?? 0,
|
|
4910
|
+
shadowOffsetY: currentStyle?.shadowOffsetY ?? baseStyle?.shadowOffsetY ?? 0,
|
|
5016
4911
|
shadowBlur,
|
|
5017
|
-
shadowColor:
|
|
5018
|
-
enableStroke:
|
|
5019
|
-
strokeColor:
|
|
4912
|
+
shadowColor: currentStyle?.shadowColor ?? baseStyle?.shadowColor ?? "transparent",
|
|
4913
|
+
enableStroke: currentStyle?.enableStroke ?? baseStyle?.enableStroke ?? false,
|
|
4914
|
+
strokeColor: currentStyle?.strokeColor ?? baseStyle?.strokeColor ?? "transparent",
|
|
5020
4915
|
strokeWidth,
|
|
5021
4916
|
};
|
|
5022
4917
|
}
|
|
5023
4918
|
function splitText(text) {
|
|
5024
|
-
return text.match(/\S+|\s|\n/g)
|
|
4919
|
+
return text.match(/\S+|\s|\n/g) ?? [];
|
|
5025
4920
|
}
|
|
5026
4921
|
function measureTextChunk(context, chunk, style) {
|
|
5027
4922
|
context.font = `${style.fontStyle} ${style.fontWeight} ${style.fontSize}px ${style.fontFamily}`;
|
|
@@ -5166,11 +5061,10 @@ class UIText extends UIElement {
|
|
|
5166
5061
|
*
|
|
5167
5062
|
* @param layer - The UI layer that contains this element
|
|
5168
5063
|
* @param spans - Text content to display, either as a string, text span, or array of text spans/strings
|
|
5169
|
-
* @param
|
|
5064
|
+
* @param options - Options to customize the text rendering
|
|
5170
5065
|
* @throws Error if canvas context creation fails
|
|
5171
5066
|
*/
|
|
5172
|
-
constructor(layer, spans,
|
|
5173
|
-
var _a;
|
|
5067
|
+
constructor(layer, spans, options = {}) {
|
|
5174
5068
|
const canvas = document.createElement("canvas");
|
|
5175
5069
|
const context = canvas.getContext("2d");
|
|
5176
5070
|
if (!context) {
|
|
@@ -5181,15 +5075,15 @@ class UIText extends UIElement {
|
|
|
5181
5075
|
for (const span of processedSpans) {
|
|
5182
5076
|
const isSpanString = typeof span === "string";
|
|
5183
5077
|
const spanText = isSpanString ? span : span.text;
|
|
5184
|
-
const style = resolveTextStyle(isSpanString ? undefined : span.style,
|
|
5078
|
+
const style = resolveTextStyle(isSpanString ? undefined : span.style, options.defaultStyle);
|
|
5185
5079
|
for (const text of splitText(spanText)) {
|
|
5186
5080
|
const metrics = measureTextChunk(context, text, style);
|
|
5187
5081
|
chunks.push({ text, style, metrics });
|
|
5188
5082
|
}
|
|
5189
5083
|
}
|
|
5190
|
-
const wrappedLines = wrapTextLines(
|
|
5084
|
+
const wrappedLines = wrapTextLines(options.maxWidth ?? DEFAULT_LINE_SIZE, chunks);
|
|
5191
5085
|
const textBlockSize = calculateTextBlockSize(wrappedLines);
|
|
5192
|
-
const padding = resolvePadding(
|
|
5086
|
+
const padding = resolvePadding(options.padding);
|
|
5193
5087
|
canvas.width = textBlockSize.width + padding.left + padding.right;
|
|
5194
5088
|
canvas.height = textBlockSize.height + padding.top + padding.bottom;
|
|
5195
5089
|
const texture = new CanvasTexture(canvas);
|
|
@@ -5313,8 +5207,7 @@ class UIFullScreenLayer extends UILayer {
|
|
|
5313
5207
|
super.render(renderer, deltaTime);
|
|
5314
5208
|
}
|
|
5315
5209
|
_private_calculateScale() {
|
|
5316
|
-
|
|
5317
|
-
const targetHeight = (_a = this.tergetScreenHeight) !== null && _a !== void 0 ? _a : window.innerHeight;
|
|
5210
|
+
const targetHeight = this.tergetScreenHeight ?? window.innerHeight;
|
|
5318
5211
|
return targetHeight / window.innerHeight;
|
|
5319
5212
|
}
|
|
5320
5213
|
}
|
|
@@ -5335,5 +5228,5 @@ function isUITextSpan(obj) {
|
|
|
5335
5228
|
class UIPass {
|
|
5336
5229
|
}
|
|
5337
5230
|
|
|
5338
|
-
export { UIAnchor, UIAspectConstraint, UIBlending, UIConstraint, UIConstraint2DBuilder, UIConstraintContainerBuilder, UIConstraintContainerDirection, UIConstraintPower, UIConstraintRule, UIConstraintStackBuilder, UICoverConstraint, UIDummy, UIElement, UIElementEvent, UIFitConstraint, UIFullScreenLayer, UIFullScreenQuad, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalProportionConstraint, UIImage, UILayer, UILayerEvent, UIMode, UIOrientation, UIPass, UIProgress, UIScene, UISceneUpdateMode, UIText, UIVerticalDistanceConstraint, UIVerticalProportionConstraint, UIWidthConstraint,
|
|
5231
|
+
export { UIAnchor, UIAspectConstraint, UIBlending, UIConstraint, UIConstraint2DBuilder, UIConstraintContainerBuilder, UIConstraintContainerDirection, UIConstraintPower, UIConstraintRule, UIConstraintStackBuilder, UICoverConstraint, UIDummy, UIElement, UIElementEvent, UIFitConstraint, UIFullScreenLayer, UIFullScreenQuad, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalProportionConstraint, UIImage, UILayer, UILayerEvent, UIMode, UIOrientation, UIPass, UIProgress, UIScene, UISceneUpdateMode, UIText, UIVerticalDistanceConstraint, UIVerticalProportionConstraint, UIWidthConstraint, convertPowerToStrength, convertRuleToOperator, isUIConstraintPower, isUIConstraintRule, isUIOrientation, isUITextSpan, resolveOrientation, resolvePower, resolveRule };
|
|
5339
5232
|
//# sourceMappingURL=index.js.map
|