laymur 0.2.6 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1997,12 +1997,22 @@ class UISolverWrapper {
1997
1997
  const description = { variable, priority, value };
1998
1998
  this._private_variables.set(index, description);
1999
1999
  description.constraint = this._private_buildConstraint(new UIExpression(0, [[index, 1]]), new UIExpression(value), UIRelation.EQUAL, priority);
2000
- this._private_solver.addConstraint(description.constraint);
2000
+ try {
2001
+ this._private_solver?.addConstraint(description.constraint);
2002
+ }
2003
+ catch {
2004
+ this._private_solver = undefined;
2005
+ }
2001
2006
  }
2002
2007
  else {
2003
2008
  this._private_variables.set(index, { variable, priority, value });
2004
- this._private_solver.addEditVariable(variable, convertPriority(priority));
2005
- this._private_solver.suggestValue(variable, value);
2009
+ try {
2010
+ this._private_solver?.addEditVariable(variable, convertPriority(priority));
2011
+ this._private_solver?.suggestValue(variable, value);
2012
+ }
2013
+ catch {
2014
+ this._private_solver = undefined;
2015
+ }
2006
2016
  }
2007
2017
  this._private_recalculationRequired = true;
2008
2018
  return index;
@@ -2017,9 +2027,14 @@ class UISolverWrapper {
2017
2027
  throw new Error(`Variable ${index} is used in constraint`);
2018
2028
  }
2019
2029
  }
2020
- description.constraint
2021
- ? this._private_solver.removeConstraint(description.constraint)
2022
- : this._private_solver.removeEditVariable(description.variable);
2030
+ try {
2031
+ description.constraint
2032
+ ? this._private_solver?.removeConstraint(description.constraint)
2033
+ : this._private_solver?.removeEditVariable(description.variable);
2034
+ }
2035
+ catch {
2036
+ this._private_solver = undefined;
2037
+ }
2023
2038
  this._private_variables.delete(index);
2024
2039
  this._private_recalculationRequired = true;
2025
2040
  }
@@ -2031,10 +2046,10 @@ class UISolverWrapper {
2031
2046
  if (description.value !== value) {
2032
2047
  description.value = value;
2033
2048
  if (description.constraint) {
2034
- description.constraint = this._private_rebuildRawConstraint(description.constraint, new UIExpression().plus(index, 1), new UIExpression(description.value), UIRelation.EQUAL, description.priority);
2049
+ description.constraint = this._private_rebuildConstraint(description.constraint, new UIExpression().plus(index, 1), new UIExpression(description.value), UIRelation.EQUAL, description.priority);
2035
2050
  }
2036
2051
  else {
2037
- this._private_solver.suggestValue(description.variable, value);
2052
+ this._private_solver?.suggestValue(description.variable, value);
2038
2053
  }
2039
2054
  this._private_recalculationRequired = true;
2040
2055
  }
@@ -2046,10 +2061,27 @@ class UISolverWrapper {
2046
2061
  }
2047
2062
  if (priority !== description.priority) {
2048
2063
  description.priority = priority;
2049
- if (description.constraint) {
2050
- description.constraint = this._private_rebuildRawConstraint(description.constraint, new UIExpression().plus(index, 1), new UIExpression(description.value), UIRelation.EQUAL, description.priority);
2064
+ if (description.priority === UIPriority.P0) {
2065
+ const lhs = new UIExpression().plus(index, 1);
2066
+ const rhs = new UIExpression(description.value);
2067
+ description.constraint = this._private_buildConstraint(lhs, rhs, UIRelation.EQUAL, description.priority);
2068
+ try {
2069
+ this._private_solver?.addConstraint(description.constraint);
2070
+ }
2071
+ catch {
2072
+ this._private_solver = undefined;
2073
+ }
2051
2074
  }
2052
2075
  else {
2076
+ if (description.constraint) {
2077
+ try {
2078
+ this._private_solver?.removeConstraint(description.constraint);
2079
+ }
2080
+ catch {
2081
+ this._private_solver = undefined;
2082
+ }
2083
+ }
2084
+ description.constraint = undefined;
2053
2085
  this._private_rebuildVariable(index, description);
2054
2086
  }
2055
2087
  this._private_recalculationRequired = true;
@@ -2060,8 +2092,11 @@ class UISolverWrapper {
2060
2092
  if (description === undefined) {
2061
2093
  throw new Error(`Variable ${index} does not exist`);
2062
2094
  }
2095
+ if (this._private_solver === undefined) {
2096
+ this._private_rebuildSolver();
2097
+ }
2063
2098
  if (this._private_recalculationRequired) {
2064
- this._private_solver.updateVariables();
2099
+ this._private_solver?.updateVariables();
2065
2100
  this._private_recalculationRequired = false;
2066
2101
  }
2067
2102
  return description.variable.value();
@@ -2078,7 +2113,12 @@ class UISolverWrapper {
2078
2113
  enabled,
2079
2114
  });
2080
2115
  if (enabled) {
2081
- this._private_solver.addConstraint(constraint);
2116
+ try {
2117
+ this._private_solver?.addConstraint(constraint);
2118
+ }
2119
+ catch {
2120
+ this._private_solver = undefined;
2121
+ }
2082
2122
  this._private_recalculationRequired = true;
2083
2123
  }
2084
2124
  return index;
@@ -2088,7 +2128,14 @@ class UISolverWrapper {
2088
2128
  if (description === undefined) {
2089
2129
  throw new Error(`Constraint ${index} does not exist`);
2090
2130
  }
2091
- this._private_solver.removeConstraint(description.constraint);
2131
+ if (description.enabled) {
2132
+ try {
2133
+ this._private_solver?.removeConstraint(description.constraint);
2134
+ }
2135
+ catch {
2136
+ this._private_solver = undefined;
2137
+ }
2138
+ }
2092
2139
  this._private_constraints.delete(index);
2093
2140
  this._private_recalculationRequired = true;
2094
2141
  }
@@ -2137,99 +2184,96 @@ class UISolverWrapper {
2137
2184
  description.enabled = enabled;
2138
2185
  try {
2139
2186
  description.enabled
2140
- ? this._private_solver.addConstraint(description.constraint)
2141
- : this._private_solver.removeConstraint(description.constraint);
2187
+ ? this._private_solver?.addConstraint(description.constraint)
2188
+ : this._private_solver?.removeConstraint(description.constraint);
2142
2189
  }
2143
2190
  catch {
2144
- this._private_rebuildSolver();
2191
+ this._private_solver = undefined;
2145
2192
  }
2146
2193
  this._private_recalculationRequired = true;
2147
2194
  }
2148
2195
  }
2149
- _private_convertExpression(expression) {
2150
- return new Expression(...expression["prepareTermsInternal"]().map(([variableIndex, coefficient]) => {
2151
- const variable = this._private_variables.get(variableIndex);
2152
- if (variable === undefined) {
2153
- throw new Error(`Variable ${variableIndex} does not exist`);
2154
- }
2155
- return [coefficient, variable.variable];
2156
- }), expression.constant);
2157
- }
2158
2196
  _private_rebuildVariable(index, description) {
2159
- let rebuildRequired = false;
2160
2197
  const dependConstraints = [];
2161
2198
  for (const cDescription of this._private_constraints.values()) {
2162
2199
  if (cDescription.lhs.hasTerm(index) || cDescription.rhs.hasTerm(index)) {
2163
- if (!rebuildRequired) {
2164
- try {
2165
- this._private_solver.removeConstraint(cDescription.constraint);
2166
- }
2167
- catch {
2168
- rebuildRequired = true;
2169
- }
2200
+ try {
2201
+ this._private_solver?.removeConstraint(cDescription.constraint);
2202
+ }
2203
+ catch {
2204
+ this._private_solver = undefined;
2170
2205
  }
2171
2206
  dependConstraints.push(cDescription);
2172
2207
  }
2173
2208
  }
2174
- this._private_solver.removeEditVariable(description.variable);
2175
- this._private_solver.addEditVariable(description.variable, convertPriority(description.priority));
2209
+ this._private_solver?.removeEditVariable(description.variable);
2210
+ this._private_solver?.addEditVariable(description.variable, convertPriority(description.priority));
2176
2211
  for (const cDescription of dependConstraints) {
2177
- cDescription.constraint = new Constraint(this._private_convertExpression(cDescription.lhs), convertRelation(cDescription.relation), this._private_convertExpression(cDescription.rhs), convertPriority(cDescription.priority));
2212
+ cDescription.constraint = this._private_buildConstraint(cDescription.lhs, cDescription.rhs, cDescription.relation, cDescription.priority);
2178
2213
  }
2179
- if (!rebuildRequired) {
2180
- for (const cDescription of dependConstraints) {
2181
- try {
2182
- this._private_solver.addConstraint(cDescription.constraint);
2183
- }
2184
- catch {
2185
- rebuildRequired = true;
2186
- break;
2187
- }
2214
+ for (const cDescription of dependConstraints) {
2215
+ try {
2216
+ this._private_solver?.addConstraint(cDescription.constraint);
2217
+ }
2218
+ catch {
2219
+ this._private_solver = undefined;
2220
+ break;
2188
2221
  }
2189
- }
2190
- if (rebuildRequired) {
2191
- this._private_rebuildSolver();
2192
2222
  }
2193
2223
  }
2194
2224
  _private_rebuildConstraintByDescription(description) {
2195
2225
  description.constraint = description.enabled
2196
- ? this._private_rebuildRawConstraint(description.constraint, description.lhs, description.rhs, description.relation, description.priority)
2226
+ ? this._private_rebuildConstraint(description.constraint, description.lhs, description.rhs, description.relation, description.priority)
2197
2227
  : this._private_buildConstraint(description.lhs, description.rhs, description.relation, description.priority);
2198
2228
  }
2199
- _private_rebuildRawConstraint(oldConstraint, lhs, rhs, relation, priority) {
2200
- let isSolverCrashed = false;
2229
+ _private_rebuildConstraint(oldConstraint, lhs, rhs, relation, priority) {
2201
2230
  try {
2202
- this._private_solver.removeConstraint(oldConstraint);
2231
+ this._private_solver?.removeConstraint(oldConstraint);
2203
2232
  }
2204
2233
  catch {
2205
- isSolverCrashed = true;
2234
+ this._private_solver = undefined;
2206
2235
  }
2207
2236
  const constraint = this._private_buildConstraint(lhs, rhs, relation, priority);
2208
- if (!isSolverCrashed) {
2209
- try {
2210
- this._private_solver.addConstraint(constraint);
2211
- }
2212
- catch {
2213
- isSolverCrashed = true;
2214
- }
2237
+ try {
2238
+ this._private_solver?.addConstraint(constraint);
2215
2239
  }
2216
- if (isSolverCrashed) {
2217
- this._private_rebuildSolver();
2240
+ catch {
2241
+ this._private_solver = undefined;
2218
2242
  }
2219
2243
  return constraint;
2220
2244
  }
2221
2245
  _private_buildConstraint(lhs, rhs, relation, priority) {
2222
2246
  return new Constraint(this._private_convertExpression(lhs), convertRelation(relation), this._private_convertExpression(rhs), convertPriority(priority));
2223
2247
  }
2248
+ _private_convertExpression(expression) {
2249
+ return new Expression(...expression["prepareTermsInternal"]().map(([variableIndex, coefficient]) => {
2250
+ const description = this._private_variables.get(variableIndex);
2251
+ if (description === undefined) {
2252
+ throw new Error(`Variable ${variableIndex} does not exist`);
2253
+ }
2254
+ return [coefficient, description.variable];
2255
+ }), expression.constant);
2256
+ }
2224
2257
  _private_rebuildSolver() {
2258
+ if (this._private_solver) {
2259
+ throw new Error("Solver already exists");
2260
+ }
2225
2261
  this._private_solver = new Solver();
2226
2262
  for (const description of this._private_variables.values()) {
2227
- this._private_solver.addEditVariable(description.variable, description.priority);
2228
- this._private_solver.suggestValue(description.variable, description.value);
2263
+ if (description.constraint) {
2264
+ this._private_solver.addConstraint(description.constraint);
2265
+ }
2266
+ else {
2267
+ this._private_solver.addEditVariable(description.variable, convertPriority(description.priority));
2268
+ this._private_solver.suggestValue(description.variable, description.value);
2269
+ }
2229
2270
  }
2230
2271
  for (const description of this._private_constraints.values()) {
2231
- this._private_solver.addConstraint(description.constraint);
2272
+ if (description.enabled) {
2273
+ this._private_solver.addConstraint(description.constraint);
2274
+ }
2232
2275
  }
2276
+ this._private_recalculationRequired = true;
2233
2277
  }
2234
2278
  }
2235
2279
 
@@ -4068,7 +4112,7 @@ class UIMaterial extends ShaderMaterial {
4068
4112
  setTransparency(value) {
4069
4113
  if (this.transparent !== value) {
4070
4114
  this.transparent = value;
4071
- this.uniforms.alphaTest.value = value ? DEFAULT_ALPHA_TEST$1 : 0;
4115
+ this.uniforms.alphaTest.value = !value ? DEFAULT_ALPHA_TEST$1 : 0;
4072
4116
  this.needsUpdate = true;
4073
4117
  this.uniformsNeedUpdate = true;
4074
4118
  }