laymur 0.11.4 → 0.11.5

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.
Files changed (40) hide show
  1. package/dist/constraints/{UIAspectConstraint.Internal.d.ts → UIAspectConstraint/UIAspectConstraint.Internal.d.ts} +1 -1
  2. package/dist/constraints/{UIAspectConstraint.d.ts → UIAspectConstraint/UIAspectConstraint.d.ts} +2 -2
  3. package/dist/constraints/{UIHeightConstraint.Internal.d.ts → UIHeightConstraint/UIHeightConstraint.Internal.d.ts} +1 -1
  4. package/dist/constraints/{UIHeightConstraint.d.ts → UIHeightConstraint/UIHeightConstraint.d.ts} +2 -2
  5. package/dist/constraints/{UIHorizontalDistanceConstraint.Internal.d.ts → UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.Internal.d.ts} +1 -1
  6. package/dist/constraints/{UIHorizontalDistanceConstraint.d.ts → UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.d.ts} +2 -2
  7. package/dist/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.Internal.d.ts +14 -0
  8. package/dist/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.d.ts +44 -0
  9. package/dist/constraints/{UIHorizontalProportionConstraint.Internal.d.ts → UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.Internal.d.ts} +1 -1
  10. package/dist/constraints/{UIHorizontalProportionConstraint.d.ts → UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.d.ts} +2 -2
  11. package/dist/constraints/{UIVerticalDistanceConstraint.Internal.d.ts → UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.Internal.d.ts} +1 -1
  12. package/dist/constraints/{UIVerticalDistanceConstraint.d.ts → UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.d.ts} +2 -2
  13. package/dist/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.Internal.d.ts +14 -0
  14. package/dist/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.d.ts +44 -0
  15. package/dist/constraints/{UIVerticalProportionConstraint.Internal.d.ts → UIVerticalProportionConstraint/UIVerticalProportionConstraint.Internal.d.ts} +1 -1
  16. package/dist/constraints/{UIVerticalProportionConstraint.d.ts → UIVerticalProportionConstraint/UIVerticalProportionConstraint.d.ts} +2 -2
  17. package/dist/constraints/{UIWidthConstraint.Internal.d.ts → UIWidthConstraint/UIWidthConstraint.Internal.d.ts} +1 -1
  18. package/dist/constraints/{UIWidthConstraint.d.ts → UIWidthConstraint/UIWidthConstraint.d.ts} +2 -2
  19. package/dist/constraints/builders/UIConstraint2DBuilder.Internal.d.ts +21 -2
  20. package/dist/constraints/builders/UIConstraint2DBuilder.d.ts +19 -8
  21. package/dist/constraints/builders/UICoverConstraintBuilder.d.ts +6 -6
  22. package/dist/constraints/builders/UIFitConstraintBuilder.d.ts +6 -6
  23. package/dist/elements/UIAnchor/UIAnchor.d.ts +1 -1
  24. package/dist/elements/UIGraphics/UIGraphics.Internal.d.ts +0 -2
  25. package/dist/elements/UIGraphics/UIGraphics.d.ts +1 -1
  26. package/dist/elements/UIImage/UIImage.Internal.d.ts +0 -2
  27. package/dist/elements/UIImage/UIImage.d.ts +1 -1
  28. package/dist/elements/UIInputDummy/UIInputDummy.d.ts +1 -1
  29. package/dist/elements/UIProgress/UIProgress.Internal.d.ts +0 -2
  30. package/dist/elements/UIProgress/UIProgress.d.ts +2 -2
  31. package/dist/index.d.ts +9 -7
  32. package/dist/index.js +667 -180
  33. package/dist/index.js.map +1 -1
  34. package/dist/index.min.js +1 -1
  35. package/dist/index.min.js.map +1 -1
  36. package/dist/layers/UILayer.d.ts +1 -1
  37. package/dist/miscellaneous/asserts.d.ts +21 -54
  38. package/dist/miscellaneous/color/UIColor.d.ts +1 -0
  39. package/dist/miscellaneous/shared.d.ts +46 -0
  40. package/package.json +6 -3
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { Color, Vector4, Texture, Vector2, Vector3, Matrix3, Matrix4, PlaneGeometry, InstancedBufferGeometry, ShaderMaterial, InstancedBufferAttribute, Mesh, Scene, OrthographicCamera, Quaternion, MathUtils, CanvasTexture, SRGBColorSpace, LinearFilter, WebGLRenderTarget, UnsignedByteType, RGBAFormat, PerspectiveCamera, Ray } from 'three';
1
+ import { Color, MathUtils, Vector4, Texture, Vector2, Vector3, Matrix3, Matrix4, PlaneGeometry, InstancedBufferGeometry, ShaderMaterial, InstancedBufferAttribute, Mesh, Scene, OrthographicCamera, Quaternion, CanvasTexture, SRGBColorSpace, LinearFilter, WebGLRenderTarget, UnsignedByteType, RGBAFormat, PerspectiveCamera, Ray } from 'three';
2
2
 
3
- 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);}}}}
3
+ 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;o.length>t;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(10>e||o[0].M===o[n].M)for(let t=1;n>t;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(;n>=e;){const i=e+n>>>1;t>o[i].M?e=i+1:n=i-1;}const c=e;for(n=o.length-1;n>=e;){const i=e+n>>>1;o[i].M>t?n=i-1:e=i+1;}const h=n;for(let t=c;h>=t;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;s.length>t;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;n.length>t;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||i>=t[t.length-1].M)return void t.push(c);if(t[0].M>=i)return void t.unshift(c);{let r=0,s=t.length;for(;s>r;){const o=r+s>>>1;i>t[o].M?r=o+1:s=o;}t.splice(r,0,c);}}}}
4
4
 
5
5
  /** Visibility and interactivity state */
6
6
  var UIMode;
@@ -2021,6 +2021,8 @@ class UIColor {
2021
2021
  }
2022
2022
  /** Red component (0 to 1) */
2023
2023
  set r(value) {
2024
+ assertValidNumber(value, "UIColor.r");
2025
+ value = MathUtils.clamp(value, 0, 1);
2024
2026
  this._private_ensureRGBUpdatedFromHSL();
2025
2027
  if (value !== this._private_rInternal) {
2026
2028
  this._private_rInternal = value;
@@ -2030,6 +2032,8 @@ class UIColor {
2030
2032
  }
2031
2033
  /** Green component (0 to 1) */
2032
2034
  set g(value) {
2035
+ assertValidNumber(value, "UIColor.g");
2036
+ value = MathUtils.clamp(value, 0, 1);
2033
2037
  this._private_ensureRGBUpdatedFromHSL();
2034
2038
  if (value !== this._private_gInternal) {
2035
2039
  this._private_gInternal = value;
@@ -2039,6 +2043,8 @@ class UIColor {
2039
2043
  }
2040
2044
  /** Blue component (0 to 1) */
2041
2045
  set b(value) {
2046
+ assertValidNumber(value, "UIColor.b");
2047
+ value = MathUtils.clamp(value, 0, 1);
2042
2048
  this._private_ensureRGBUpdatedFromHSL();
2043
2049
  if (value !== this._private_bInternal) {
2044
2050
  this._private_bInternal = value;
@@ -2048,6 +2054,8 @@ class UIColor {
2048
2054
  }
2049
2055
  /** Alpha component (0 to 1) */
2050
2056
  set a(value) {
2057
+ assertValidNumber(value, "UIColor.a");
2058
+ value = MathUtils.clamp(value, 0, 1);
2051
2059
  if (value !== this._private_aInternal) {
2052
2060
  this._private_aInternal = value;
2053
2061
  this._private_dirtyInternal = true;
@@ -2055,6 +2063,8 @@ class UIColor {
2055
2063
  }
2056
2064
  /** Hue component (0 to 360) */
2057
2065
  set hue(value) {
2066
+ assertValidNumber(value, "UIColor.hue");
2067
+ value = MathUtils.clamp(value, 0, 360);
2058
2068
  this._private_ensureHSLUpdatedFromRGB();
2059
2069
  if (value !== this._private_hInternal) {
2060
2070
  this._private_hInternal = value;
@@ -2064,6 +2074,8 @@ class UIColor {
2064
2074
  }
2065
2075
  /** Saturation component (0 to 1) */
2066
2076
  set saturation(value) {
2077
+ assertValidNumber(value, "UIColor.saturation");
2078
+ value = MathUtils.clamp(value, 0, 1);
2067
2079
  this._private_ensureHSLUpdatedFromRGB();
2068
2080
  if (value !== this._private_sInternal) {
2069
2081
  this._private_sInternal = value;
@@ -2073,6 +2085,8 @@ class UIColor {
2073
2085
  }
2074
2086
  /** Lightness component (0 to 1) */
2075
2087
  set lightness(value) {
2088
+ assertValidNumber(value, "UIColor.lightness");
2089
+ value = MathUtils.clamp(value, 0, 1);
2076
2090
  this._private_ensureHSLUpdatedFromRGB();
2077
2091
  if (value !== this._private_lInternal) {
2078
2092
  this._private_lInternal = value;
@@ -2086,6 +2100,14 @@ class UIColor {
2086
2100
  }
2087
2101
  /** Sets RGB(A) components */
2088
2102
  set(r, g, b, a = this._private_aInternal) {
2103
+ assertValidNumber(r, "UIColor.set.r");
2104
+ assertValidNumber(g, "UIColor.set.g");
2105
+ assertValidNumber(b, "UIColor.set.b");
2106
+ assertValidNumber(a, "UIColor.set.a");
2107
+ r = MathUtils.clamp(r, 0, 1);
2108
+ g = MathUtils.clamp(g, 0, 1);
2109
+ b = MathUtils.clamp(b, 0, 1);
2110
+ a = MathUtils.clamp(a, 0, 1);
2089
2111
  this._private_ensureRGBUpdatedFromHSL();
2090
2112
  if (r !== this._private_rInternal ||
2091
2113
  g !== this._private_gInternal ||
@@ -2127,6 +2149,7 @@ class UIColor {
2127
2149
  }
2128
2150
  /** Sets from 32-bit hex RGBA (RRGGBBAA) */
2129
2151
  setHexRGBA(hex) {
2152
+ assertValidNumber(hex, "UIColor.setHexRGBA.hex");
2130
2153
  this._private_ensureRGBUpdatedFromHSL();
2131
2154
  const r = ((hex >> 16) & 0xff) / 255;
2132
2155
  const g = ((hex >> 8) & 0xff) / 255;
@@ -2147,6 +2170,9 @@ class UIColor {
2147
2170
  }
2148
2171
  /** Sets from 24-bit hex RGB (RRGGBB) */
2149
2172
  setHexRGB(hex, a = this._private_aInternal) {
2173
+ assertValidNumber(hex, "UIColor.setHexRGB.hex");
2174
+ assertValidNumber(a, "UIColor.setHexRGB.a");
2175
+ a = MathUtils.clamp(a, 0, 1);
2150
2176
  this._private_ensureRGBUpdatedFromHSL();
2151
2177
  const r = ((hex >> 16) & 0xff) / 255;
2152
2178
  const g = ((hex >> 8) & 0xff) / 255;
@@ -2195,6 +2221,14 @@ class UIColor {
2195
2221
  }
2196
2222
  /** Sets from HSL values */
2197
2223
  setHSL(h, s, l, a = this._private_aInternal) {
2224
+ assertValidNumber(h, "UIColor.setHSL.h");
2225
+ assertValidNumber(s, "UIColor.setHSL.s");
2226
+ assertValidNumber(l, "UIColor.setHSL.l");
2227
+ assertValidNumber(a, "UIColor.setHSL.a");
2228
+ h = MathUtils.clamp(h, 0, 360);
2229
+ s = MathUtils.clamp(s, 0, 1);
2230
+ l = MathUtils.clamp(l, 0, 1);
2231
+ a = MathUtils.clamp(a, 0, 1);
2198
2232
  this._private_ensureHSLUpdatedFromRGB();
2199
2233
  if (h !== this._private_hInternal ||
2200
2234
  s !== this._private_sInternal ||
@@ -2215,6 +2249,8 @@ class UIColor {
2215
2249
  * @throws If color name unknown
2216
2250
  */
2217
2251
  setColorName(colorName, a = this._private_aInternal) {
2252
+ assertValidNumber(a, "UIColor.setColorName.a");
2253
+ a = MathUtils.clamp(a, 0, 1);
2218
2254
  const normalizedName = colorName.toLowerCase().trim();
2219
2255
  const hex = COLORS[normalizedName];
2220
2256
  if (hex === undefined) {
@@ -2224,6 +2260,11 @@ class UIColor {
2224
2260
  }
2225
2261
  /** Sets from linear (GLSL) color space */
2226
2262
  setGLSLColor(r, g, b, a = this._private_aInternal) {
2263
+ assertValidNumber(r, "UIColor.setGLSLColor.r");
2264
+ assertValidNumber(g, "UIColor.setGLSLColor.g");
2265
+ assertValidNumber(b, "UIColor.setGLSLColor.b");
2266
+ assertValidNumber(a, "UIColor.setGLSLColor.a");
2267
+ a = MathUtils.clamp(a, 0, 1);
2227
2268
  this._private_ensureRGBUpdatedFromHSL();
2228
2269
  const sRGBR = LinearToSRGB(r);
2229
2270
  const sRGBG = LinearToSRGB(g);
@@ -2243,6 +2284,8 @@ class UIColor {
2243
2284
  }
2244
2285
  /** Sets from Three.js Color */
2245
2286
  setThreeColor(threeColor, a = this._private_aInternal) {
2287
+ assertValidNumber(a, "UIColor.setThreeColor.a");
2288
+ a = MathUtils.clamp(a, 0, 1);
2246
2289
  this._private_ensureRGBUpdatedFromHSL();
2247
2290
  if (threeColor.r !== this._private_rInternal ||
2248
2291
  threeColor.g !== this._private_gInternal ||
@@ -2345,7 +2388,6 @@ class UIColor {
2345
2388
  this._private_rgbDirty = false;
2346
2389
  }
2347
2390
  }
2348
- /** @internal */
2349
2391
  _private_ensureHSLUpdatedFromRGB() {
2350
2392
  if (this._private_hslDirty) {
2351
2393
  const { _private_rInternal: r, _private_gInternal: g, _private_bInternal: b } = this;
@@ -3287,8 +3329,14 @@ class UIExpression {
3287
3329
  * @param terms Variable-coefficient pairs
3288
3330
  */
3289
3331
  constructor(constant = 0, terms) {
3332
+ assertValidNumber(constant, "UIExpression.constructor.constant");
3290
3333
  this.constant = constant;
3291
3334
  this._private_terms = terms ? new Map(terms) : new Map();
3335
+ if (terms) {
3336
+ for (let i = 0; i < terms.length; i++) {
3337
+ assertValidNumber(terms[i][1], `UIExpression.constructor.terms[${i}][1]`);
3338
+ }
3339
+ }
3292
3340
  }
3293
3341
  /**
3294
3342
  * Creates expression representing a + b.
@@ -3323,6 +3371,7 @@ class UIExpression {
3323
3371
  * @returns This instance for chaining
3324
3372
  */
3325
3373
  plus(variableIndex, coefficient) {
3374
+ assertValidNumber(coefficient, "UIExpression.plus.coefficient");
3326
3375
  this._private_terms.set(variableIndex, (this._private_terms.get(variableIndex) ?? 0) + coefficient);
3327
3376
  return this;
3328
3377
  }
@@ -3341,6 +3390,7 @@ class UIExpression {
3341
3390
  * @returns This instance for chaining
3342
3391
  */
3343
3392
  multiply(value) {
3393
+ assertValidNumber(value, "UIExpression.multiply.value");
3344
3394
  this.constant *= value;
3345
3395
  for (const [variableIndex, coefficient] of this._private_terms) {
3346
3396
  this._private_terms.set(variableIndex, coefficient * value);
@@ -3353,6 +3403,10 @@ class UIExpression {
3353
3403
  * @returns This instance for chaining
3354
3404
  */
3355
3405
  divide(value) {
3406
+ assertValidNumber(value, "UIExpression.divide.value");
3407
+ if (value === 0) {
3408
+ throw new Error("UIExpression.divide.value: cannot divide by zero");
3409
+ }
3356
3410
  return this.multiply(1 / value);
3357
3411
  }
3358
3412
  /**
@@ -4027,7 +4081,6 @@ class UILayer extends i {
4027
4081
  }
4028
4082
  }
4029
4083
 
4030
- const EPSILON = 1e-6;
4031
4084
  /**
4032
4085
  * Checks if object implements UILayerElement.
4033
4086
  * @param obj Object to check
@@ -4073,37 +4126,8 @@ function isUIPlaneElement(obj) {
4073
4126
  "height" in obj &&
4074
4127
  typeof obj.height === "number");
4075
4128
  }
4076
- /**
4077
- * Validates constraint subjects are from same layer.
4078
- * @param a First constraint subject
4079
- * @param b Second constraint subject
4080
- * @param subject Constraint name for error messages
4081
- * @returns Common layer for both subjects
4082
- * @throws If subjects are invalid or from different layers
4083
- */
4084
- function assertValidConstraintSubjects(a, b, subject) {
4085
- if (a instanceof UILayer && b instanceof UILayer) {
4086
- throw new Error(`${subject}: layer cannot be snapped to another layer`);
4087
- }
4088
- let layerA;
4089
- let layerB;
4090
- if (a instanceof UILayer || isUILayerElement(a)) {
4091
- layerA = a instanceof UILayer ? a : a.layer;
4092
- }
4093
- else {
4094
- throw new Error(`${subject}: A must be a UILayer or a UIPointElement`);
4095
- }
4096
- if (b instanceof UILayer || isUILayerElement(b)) {
4097
- layerB = b instanceof UILayer ? b : b.layer;
4098
- }
4099
- else {
4100
- throw new Error(`${subject}: B must be a UILayer or a UIPointElement`);
4101
- }
4102
- if (layerA !== layerB) {
4103
- throw new Error(`${subject}: elements must be on the same layer`);
4104
- }
4105
- return layerA;
4106
- }
4129
+
4130
+ const EPSILON = 1e-6;
4107
4131
  /**
4108
4132
  * Validates value is finite number within safe range.
4109
4133
  * @param value Number to validate
@@ -4148,6 +4172,119 @@ function assertValidNonNegativeNumber(value, subject) {
4148
4172
  }
4149
4173
  }
4150
4174
  }
4175
+ /**
4176
+ * Validates constraint arguments are from same layer.
4177
+ * @param a First constraint subject
4178
+ * @param b Second constraint subject
4179
+ * @param subject Constraint name for error messages
4180
+ * @returns Common layer for both subjects
4181
+ * @throws If subjects are invalid or from different layers
4182
+ */
4183
+ function assertValidConstraintArguments(a, b, subject) {
4184
+ if ("development" !== "production") {
4185
+ if (a instanceof UILayer && b instanceof UILayer) {
4186
+ throw new Error(`${subject}: layer cannot be snapped to another layer`);
4187
+ }
4188
+ let layerA;
4189
+ let layerB;
4190
+ if (a instanceof UILayer) {
4191
+ layerA = a;
4192
+ }
4193
+ else if (isUILayerElement(a)) {
4194
+ layerA = a.layer;
4195
+ }
4196
+ else {
4197
+ throw new Error(`${subject}: A must be a UILayer or a UILayerElement`);
4198
+ }
4199
+ if (b instanceof UILayer) {
4200
+ layerB = b;
4201
+ }
4202
+ else if (isUILayerElement(b)) {
4203
+ layerB = b.layer;
4204
+ }
4205
+ else {
4206
+ throw new Error(`${subject}: B must be a UILayer or a UILayerElement`);
4207
+ }
4208
+ if (layerA !== layerB) {
4209
+ throw new Error(`${subject}: elements must be on the same layer`);
4210
+ }
4211
+ return layerA;
4212
+ }
4213
+ if (a instanceof UILayer) {
4214
+ return a;
4215
+ }
4216
+ if (isUILayerElement(a)) {
4217
+ return a.layer;
4218
+ }
4219
+ if (b instanceof UILayer) {
4220
+ return b;
4221
+ }
4222
+ if (isUILayerElement(b)) {
4223
+ return b.layer;
4224
+ }
4225
+ throw new Error(`${subject}: no valid subjects found`);
4226
+ }
4227
+ /**
4228
+ * Validates interpolation constraint subjects.
4229
+ * @param subject Constraint name for error messages
4230
+ * @param a First element
4231
+ * @param b Second element
4232
+ * @param c Element to interpolate
4233
+ * @param anchorA Anchor on element A
4234
+ * @param anchorB Anchor on element B
4235
+ * @returns Common layer for all subjects
4236
+ * @throws If subjects violate interpolation constraints
4237
+ */
4238
+ function assertValidInterpolationConstraintArguments(subject, a, b, c, anchorA, anchorB) {
4239
+ if ("development" !== "production") {
4240
+ if (c instanceof UILayer) {
4241
+ throw new Error(`${subject}: C cannot be a layer`);
4242
+ }
4243
+ if (!isUILayerElement(c)) {
4244
+ throw new Error(`${subject}: C must be a UILayerElement`);
4245
+ }
4246
+ let layerA;
4247
+ let layerB;
4248
+ if (a instanceof UILayer || isUILayerElement(a)) {
4249
+ layerA = a instanceof UILayer ? a : a.layer;
4250
+ }
4251
+ else {
4252
+ throw new Error(`${subject}: A must be UILayer or UILayerElement`);
4253
+ }
4254
+ if (b instanceof UILayer || isUILayerElement(b)) {
4255
+ layerB = b instanceof UILayer ? b : b.layer;
4256
+ }
4257
+ else {
4258
+ throw new Error(`${subject}: B must be UILayer or UILayerElement`);
4259
+ }
4260
+ const layerC = c.layer;
4261
+ if (layerA !== layerB || layerA !== layerC) {
4262
+ throw new Error(`${subject}: all elements must be on the same layer`);
4263
+ }
4264
+ if (c === a || c === b) {
4265
+ throw new Error(`${subject}: C cannot be equal to A or B`);
4266
+ }
4267
+ if (a === b) {
4268
+ if (Math.abs(anchorA - anchorB) <= EPSILON) {
4269
+ throw new Error(`${subject}: when A and B are the same, anchorA and anchorB must differ by more than ${EPSILON}`);
4270
+ }
4271
+ }
4272
+ return layerA;
4273
+ }
4274
+ if (a instanceof UILayer) {
4275
+ return a;
4276
+ }
4277
+ if (isUILayerElement(a)) {
4278
+ return a.layer;
4279
+ }
4280
+ if (b instanceof UILayer) {
4281
+ return b;
4282
+ }
4283
+ if (isUILayerElement(b)) {
4284
+ return b.layer;
4285
+ }
4286
+ throw new Error(`${subject}: no valid subjects found`);
4287
+ }
4151
4288
 
4152
4289
  /** Base class for layout constraints */
4153
4290
  class UIConstraint {
@@ -4232,11 +4369,11 @@ class UIHeightConstraint extends UISingleParameterConstraint {
4232
4369
  * @param options Height configuration. Defaults to element's current height.
4233
4370
  */
4234
4371
  constructor(_private_element, options = {}) {
4235
- super(_private_element.layer, options);
4236
- this._private_element = _private_element;
4237
4372
  if (options.height !== undefined) {
4238
4373
  assertValidPositiveNumber(options.height, "UIHeightConstraint.constructor.options.height");
4239
4374
  }
4375
+ super(_private_element.layer, options);
4376
+ this._private_element = _private_element;
4240
4377
  this._private_heightInternal = options.height ?? _private_element.height;
4241
4378
  this.constraint = this.solverWrapper.createConstraint(new UIExpression(0, [[this._private_element.hVariable, 1]]), new UIExpression(this._private_heightInternal), this.relation, this.priority, this.isConstraintEnabled());
4242
4379
  }
@@ -4254,7 +4391,7 @@ class UIHeightConstraint extends UISingleParameterConstraint {
4254
4391
  }
4255
4392
  }
4256
4393
 
4257
- const DEFAULT_ANCHOR$2 = 0.5;
4394
+ const DEFAULT_ANCHOR$4 = 0.5;
4258
4395
 
4259
4396
  /** Maintains horizontal distance between elements with configurable anchors */
4260
4397
  class UIHorizontalDistanceConstraint extends UISingleParameterConstraint {
@@ -4264,9 +4401,6 @@ class UIHorizontalDistanceConstraint extends UISingleParameterConstraint {
4264
4401
  * @param options Distance configuration
4265
4402
  */
4266
4403
  constructor(_private_a, _private_b, options = {}) {
4267
- super(assertValidConstraintSubjects(_private_a, _private_b, "UIHorizontalDistanceConstraint"), options);
4268
- this._private_a = _private_a;
4269
- this._private_b = _private_b;
4270
4404
  if (options.anchorA !== undefined) {
4271
4405
  assertValidNumber(options.anchorA, "UIHorizontalDistanceConstraint.constructor.options.anchorA");
4272
4406
  }
@@ -4276,8 +4410,11 @@ class UIHorizontalDistanceConstraint extends UISingleParameterConstraint {
4276
4410
  if (options.distance !== undefined) {
4277
4411
  assertValidNumber(options.distance, "UIHorizontalDistanceConstraint.constructor.options.distance");
4278
4412
  }
4279
- this._private_anchorAInternal = options.anchorA ?? DEFAULT_ANCHOR$2;
4280
- this._private_anchorBInternal = options.anchorB ?? DEFAULT_ANCHOR$2;
4413
+ super(assertValidConstraintArguments(_private_a, _private_b, "UIHorizontalDistanceConstraint.constructor"), options);
4414
+ this._private_a = _private_a;
4415
+ this._private_b = _private_b;
4416
+ this._private_anchorAInternal = options.anchorA ?? DEFAULT_ANCHOR$4;
4417
+ this._private_anchorBInternal = options.anchorB ?? DEFAULT_ANCHOR$4;
4281
4418
  this._private_distanceInternal = options.distance ?? 0;
4282
4419
  this.constraint = this.solverWrapper.createConstraint(this._private_buildLHS(), new UIExpression(this._private_distanceInternal), this.relation, this.priority, this.isConstraintEnabled());
4283
4420
  }
@@ -4349,6 +4486,138 @@ class UIHorizontalDistanceConstraint extends UISingleParameterConstraint {
4349
4486
  }
4350
4487
  }
4351
4488
 
4489
+ const DEFAULT_ANCHOR$3 = 0.5;
4490
+ const DEFAULT_T$1 = 0.5;
4491
+
4492
+ /** Positions element C horizontally between A and B based on interpolation factor */
4493
+ class UIHorizontalInterpolationConstraint extends UISingleParameterConstraint {
4494
+ /**
4495
+ * @param a First element
4496
+ * @param b Second element
4497
+ * @param c Element to position between A and B
4498
+ * @param options Interpolation configuration
4499
+ */
4500
+ constructor(_private_a, _private_b, _private_c, options = {}) {
4501
+ if (options.anchorA !== undefined) {
4502
+ assertValidNumber(options.anchorA, "UIHorizontalInterpolationConstraint.constructor.options.anchorA");
4503
+ }
4504
+ if (options.anchorB !== undefined) {
4505
+ assertValidNumber(options.anchorB, "UIHorizontalInterpolationConstraint.constructor.options.anchorB");
4506
+ }
4507
+ if (options.anchorC !== undefined) {
4508
+ assertValidNumber(options.anchorC, "UIHorizontalInterpolationConstraint.constructor.options.anchorC");
4509
+ }
4510
+ if (options.t !== undefined) {
4511
+ assertValidNumber(options.t, "UIHorizontalInterpolationConstraint.constructor.options.t");
4512
+ }
4513
+ const anchorA = options.anchorA ?? DEFAULT_ANCHOR$3;
4514
+ const anchorB = options.anchorB ?? DEFAULT_ANCHOR$3;
4515
+ super(assertValidInterpolationConstraintArguments("UIHorizontalInterpolationConstraint.constructor", _private_a, _private_b, _private_c, anchorA, anchorB), options);
4516
+ this._private_a = _private_a;
4517
+ this._private_b = _private_b;
4518
+ this._private_c = _private_c;
4519
+ this._private_anchorAInternal = anchorA;
4520
+ this._private_anchorBInternal = anchorA;
4521
+ this._private_anchorCInternal = options.anchorC ?? DEFAULT_ANCHOR$3;
4522
+ this._private_tInternal = options.t ?? DEFAULT_T$1;
4523
+ this.constraint = this.solverWrapper.createConstraint(this._private_buildLHS(), new UIExpression(0), this.relation, this.priority, this.isConstraintEnabled());
4524
+ }
4525
+ /** Interpolation factor (0 = A position, 1 = B position) */
4526
+ get t() {
4527
+ return this._private_tInternal;
4528
+ }
4529
+ /** Anchor on element A (0 = left, 0.5 = center, 1 = right) */
4530
+ get anchorA() {
4531
+ return this._private_anchorAInternal;
4532
+ }
4533
+ /** Anchor on element B (0 = left, 0.5 = center, 1 = right) */
4534
+ get anchorB() {
4535
+ return this._private_anchorBInternal;
4536
+ }
4537
+ /** Anchor on element C (0 = left, 0.5 = center, 1 = right) */
4538
+ get anchorC() {
4539
+ return this._private_anchorCInternal;
4540
+ }
4541
+ /** Updates interpolation factor */
4542
+ set t(value) {
4543
+ assertValidNumber(value, "UIHorizontalInterpolationConstraint.t");
4544
+ if (this._private_tInternal !== value) {
4545
+ this._private_tInternal = value;
4546
+ this.solverWrapper.setConstraintLHS(this.constraint, this._private_buildLHS());
4547
+ }
4548
+ }
4549
+ /** Updates anchor on element A */
4550
+ set anchorA(value) {
4551
+ assertValidNumber(value, "UIHorizontalInterpolationConstraint.anchorA");
4552
+ if (this._private_anchorAInternal !== value) {
4553
+ this._private_anchorAInternal = value;
4554
+ this.solverWrapper.setConstraintLHS(this.constraint, this._private_buildLHS());
4555
+ }
4556
+ }
4557
+ /** Updates anchor on element B */
4558
+ set anchorB(value) {
4559
+ assertValidNumber(value, "UIHorizontalInterpolationConstraint.anchorB");
4560
+ if (this._private_anchorBInternal !== value) {
4561
+ this._private_anchorBInternal = value;
4562
+ this.solverWrapper.setConstraintLHS(this.constraint, this._private_buildLHS());
4563
+ }
4564
+ }
4565
+ /** Updates anchor on element C */
4566
+ set anchorC(value) {
4567
+ assertValidNumber(value, "UIHorizontalInterpolationConstraint.anchorC");
4568
+ if (this._private_anchorCInternal !== value) {
4569
+ this._private_anchorCInternal = value;
4570
+ this.solverWrapper.setConstraintLHS(this.constraint, this._private_buildLHS());
4571
+ }
4572
+ }
4573
+ /** Builds constraint expression: C - A*(1-t) - B*t = 0 */
4574
+ _private_buildLHS() {
4575
+ let aExpression;
4576
+ let bExpression;
4577
+ let cExpression;
4578
+ if (isUIPlaneElement(this._private_a)) {
4579
+ aExpression = new UIExpression(0, [
4580
+ [this._private_a.xVariable, 1],
4581
+ [this._private_a.wVariable, this._private_anchorAInternal],
4582
+ ]);
4583
+ }
4584
+ else if (isUIPointElement(this._private_a)) {
4585
+ aExpression = new UIExpression().plus(this._private_a.xVariable, 1);
4586
+ }
4587
+ else {
4588
+ throw new Error("UIHorizontalInterpolationConstraint.buildLHS.a: invalid element type");
4589
+ }
4590
+ if (isUIPlaneElement(this._private_b)) {
4591
+ bExpression = new UIExpression(0, [
4592
+ [this._private_b.xVariable, 1],
4593
+ [this._private_b.wVariable, this._private_anchorBInternal],
4594
+ ]);
4595
+ }
4596
+ else if (isUIPointElement(this._private_b)) {
4597
+ bExpression = new UIExpression().plus(this._private_b.xVariable, 1);
4598
+ }
4599
+ else {
4600
+ throw new Error("UIHorizontalInterpolationConstraint.buildLHS.b: invalid element type");
4601
+ }
4602
+ if (isUIPlaneElement(this._private_c)) {
4603
+ cExpression = new UIExpression(0, [
4604
+ [this._private_c.xVariable, 1],
4605
+ [this._private_c.wVariable, this._private_anchorCInternal],
4606
+ ]);
4607
+ }
4608
+ else if (isUIPointElement(this._private_c)) {
4609
+ cExpression = new UIExpression().plus(this._private_c.xVariable, 1);
4610
+ }
4611
+ else {
4612
+ throw new Error("UIHorizontalInterpolationConstraint.buildLHS.c: invalid element type");
4613
+ }
4614
+ // C - A*(1-t) - B*t = 0
4615
+ const aScaled = aExpression.clone().multiply(1 - this._private_tInternal);
4616
+ const bScaled = bExpression.clone().multiply(this._private_tInternal);
4617
+ return UIExpression.minus(UIExpression.minus(cExpression, aScaled), bScaled);
4618
+ }
4619
+ }
4620
+
4352
4621
  /** Maintains proportional width relationship (A.width * proportion = B.width) */
4353
4622
  class UIHorizontalProportionConstraint extends UISingleParameterConstraint {
4354
4623
  /**
@@ -4357,12 +4626,12 @@ class UIHorizontalProportionConstraint extends UISingleParameterConstraint {
4357
4626
  * @param options Proportion configuration
4358
4627
  */
4359
4628
  constructor(_private_a, _private_b, options = {}) {
4360
- super(assertValidConstraintSubjects(_private_a, _private_b, "UIHorizontalProportionConstraint"), options);
4361
- this._private_a = _private_a;
4362
- this._private_b = _private_b;
4363
4629
  if (options.proportion !== undefined) {
4364
4630
  assertValidPositiveNumber(options.proportion, "UIHorizontalProportionConstraint.constructor.options.proportion");
4365
4631
  }
4632
+ super(assertValidConstraintArguments(_private_a, _private_b, "UIHorizontalProportionConstraint.constructor"), options);
4633
+ this._private_a = _private_a;
4634
+ this._private_b = _private_b;
4366
4635
  this._private_proportionInternal = options.proportion ?? 1;
4367
4636
  this.constraint = this.solverWrapper.createConstraint(new UIExpression(0), this._private_buildRHS(), this.relation, this.priority, this.isConstraintEnabled());
4368
4637
  }
@@ -4384,7 +4653,7 @@ class UIHorizontalProportionConstraint extends UISingleParameterConstraint {
4384
4653
  }
4385
4654
  }
4386
4655
 
4387
- const DEFAULT_ANCHOR$1 = 0.5;
4656
+ const DEFAULT_ANCHOR$2 = 0.5;
4388
4657
 
4389
4658
  /** Maintains vertical distance between elements with configurable anchors */
4390
4659
  class UIVerticalDistanceConstraint extends UISingleParameterConstraint {
@@ -4394,9 +4663,6 @@ class UIVerticalDistanceConstraint extends UISingleParameterConstraint {
4394
4663
  * @param options Distance configuration
4395
4664
  */
4396
4665
  constructor(_private_a, _private_b, options = {}) {
4397
- super(assertValidConstraintSubjects(_private_a, _private_b, "UIVerticalDistanceConstraint"), options);
4398
- this._private_a = _private_a;
4399
- this._private_b = _private_b;
4400
4666
  if (options.anchorA !== undefined) {
4401
4667
  assertValidNumber(options.anchorA, "UIVerticalDistanceConstraint.constructor.options.anchorA");
4402
4668
  }
@@ -4406,8 +4672,11 @@ class UIVerticalDistanceConstraint extends UISingleParameterConstraint {
4406
4672
  if (options.distance !== undefined) {
4407
4673
  assertValidNumber(options.distance, "UIVerticalDistanceConstraint.constructor.options.distance");
4408
4674
  }
4409
- this._private_anchorAInternal = options.anchorA ?? DEFAULT_ANCHOR$1;
4410
- this._private_anchorBInternal = options.anchorB ?? DEFAULT_ANCHOR$1;
4675
+ super(assertValidConstraintArguments(_private_a, _private_b, "UIVerticalDistanceConstraint.constructor"), options);
4676
+ this._private_a = _private_a;
4677
+ this._private_b = _private_b;
4678
+ this._private_anchorAInternal = options.anchorA ?? DEFAULT_ANCHOR$2;
4679
+ this._private_anchorBInternal = options.anchorB ?? DEFAULT_ANCHOR$2;
4411
4680
  this._private_distanceInternal = options.distance ?? 0;
4412
4681
  this.constraint = this.solverWrapper.createConstraint(this._private_buildLHS(), new UIExpression(this._private_distanceInternal), this.relation, this.priority, this.isConstraintEnabled());
4413
4682
  }
@@ -4479,6 +4748,138 @@ class UIVerticalDistanceConstraint extends UISingleParameterConstraint {
4479
4748
  }
4480
4749
  }
4481
4750
 
4751
+ const DEFAULT_ANCHOR$1 = 0.5;
4752
+ const DEFAULT_T = 0.5;
4753
+
4754
+ /** Positions element C vertically between A and B based on interpolation factor */
4755
+ class UIVerticalInterpolationConstraint extends UISingleParameterConstraint {
4756
+ /**
4757
+ * @param a First element
4758
+ * @param b Second element
4759
+ * @param c Element to position between A and B
4760
+ * @param options Interpolation configuration
4761
+ */
4762
+ constructor(_private_a, _private_b, _private_c, options = {}) {
4763
+ if (options.anchorA !== undefined) {
4764
+ assertValidNumber(options.anchorA, "UIVerticalInterpolationConstraint.constructor.options.anchorA");
4765
+ }
4766
+ if (options.anchorB !== undefined) {
4767
+ assertValidNumber(options.anchorB, "UIVerticalInterpolationConstraint.constructor.options.anchorB");
4768
+ }
4769
+ if (options.anchorC !== undefined) {
4770
+ assertValidNumber(options.anchorC, "UIVerticalInterpolationConstraint.constructor.options.anchorC");
4771
+ }
4772
+ if (options.t !== undefined) {
4773
+ assertValidNumber(options.t, "UIVerticalInterpolationConstraint.constructor.options.t");
4774
+ }
4775
+ const anchorA = options.anchorA ?? DEFAULT_ANCHOR$1;
4776
+ const anchorB = options.anchorB ?? DEFAULT_ANCHOR$1;
4777
+ super(assertValidInterpolationConstraintArguments("UIVerticalInterpolationConstraint.constructor", _private_a, _private_b, _private_c, anchorA, anchorB), options);
4778
+ this._private_a = _private_a;
4779
+ this._private_b = _private_b;
4780
+ this._private_c = _private_c;
4781
+ this._private_anchorAInternal = anchorA;
4782
+ this._private_anchorBInternal = anchorA;
4783
+ this._private_anchorCInternal = options.anchorC ?? DEFAULT_ANCHOR$1;
4784
+ this._private_tInternal = options.t ?? DEFAULT_T;
4785
+ this.constraint = this.solverWrapper.createConstraint(this._private_buildLHS(), new UIExpression(0), this.relation, this.priority, this.isConstraintEnabled());
4786
+ }
4787
+ /** Interpolation factor (0 = A position, 1 = B position) */
4788
+ get t() {
4789
+ return this._private_tInternal;
4790
+ }
4791
+ /** Anchor on element A (0 = bottom, 0.5 = center, 1 = top) */
4792
+ get anchorA() {
4793
+ return this._private_anchorAInternal;
4794
+ }
4795
+ /** Anchor on element B (0 = bottom, 0.5 = center, 1 = top) */
4796
+ get anchorB() {
4797
+ return this._private_anchorBInternal;
4798
+ }
4799
+ /** Anchor on element C (0 = bottom, 0.5 = center, 1 = top) */
4800
+ get anchorC() {
4801
+ return this._private_anchorCInternal;
4802
+ }
4803
+ /** Updates interpolation factor */
4804
+ set t(value) {
4805
+ assertValidNumber(value, "UIVerticalInterpolationConstraint.t");
4806
+ if (this._private_tInternal !== value) {
4807
+ this._private_tInternal = value;
4808
+ this.solverWrapper.setConstraintLHS(this.constraint, this._private_buildLHS());
4809
+ }
4810
+ }
4811
+ /** Updates anchor on element A */
4812
+ set anchorA(value) {
4813
+ assertValidNumber(value, "UIVerticalInterpolationConstraint.anchorA");
4814
+ if (this._private_anchorAInternal !== value) {
4815
+ this._private_anchorAInternal = value;
4816
+ this.solverWrapper.setConstraintLHS(this.constraint, this._private_buildLHS());
4817
+ }
4818
+ }
4819
+ /** Updates anchor on element B */
4820
+ set anchorB(value) {
4821
+ assertValidNumber(value, "UIVerticalInterpolationConstraint.anchorB");
4822
+ if (this._private_anchorBInternal !== value) {
4823
+ this._private_anchorBInternal = value;
4824
+ this.solverWrapper.setConstraintLHS(this.constraint, this._private_buildLHS());
4825
+ }
4826
+ }
4827
+ /** Updates anchor on element C */
4828
+ set anchorC(value) {
4829
+ assertValidNumber(value, "UIVerticalInterpolationConstraint.anchorC");
4830
+ if (this._private_anchorCInternal !== value) {
4831
+ this._private_anchorCInternal = value;
4832
+ this.solverWrapper.setConstraintLHS(this.constraint, this._private_buildLHS());
4833
+ }
4834
+ }
4835
+ /** Builds constraint expression: C - A*(1-t) - B*t = 0 */
4836
+ _private_buildLHS() {
4837
+ let aExpression;
4838
+ let bExpression;
4839
+ let cExpression;
4840
+ if (isUIPlaneElement(this._private_a)) {
4841
+ aExpression = new UIExpression(0, [
4842
+ [this._private_a.yVariable, 1],
4843
+ [this._private_a.hVariable, this._private_anchorAInternal],
4844
+ ]);
4845
+ }
4846
+ else if (isUIPointElement(this._private_a)) {
4847
+ aExpression = new UIExpression().plus(this._private_a.yVariable, 1);
4848
+ }
4849
+ else {
4850
+ throw new Error("UIVerticalInterpolationConstraint.buildLHS.a: invalid element type");
4851
+ }
4852
+ if (isUIPlaneElement(this._private_b)) {
4853
+ bExpression = new UIExpression(0, [
4854
+ [this._private_b.yVariable, 1],
4855
+ [this._private_b.hVariable, this._private_anchorBInternal],
4856
+ ]);
4857
+ }
4858
+ else if (isUIPointElement(this._private_b)) {
4859
+ bExpression = new UIExpression().plus(this._private_b.yVariable, 1);
4860
+ }
4861
+ else {
4862
+ throw new Error("UIVerticalInterpolationConstraint.buildLHS.b: invalid element type");
4863
+ }
4864
+ if (isUIPlaneElement(this._private_c)) {
4865
+ cExpression = new UIExpression(0, [
4866
+ [this._private_c.yVariable, 1],
4867
+ [this._private_c.hVariable, this._private_anchorCInternal],
4868
+ ]);
4869
+ }
4870
+ else if (isUIPointElement(this._private_c)) {
4871
+ cExpression = new UIExpression().plus(this._private_c.yVariable, 1);
4872
+ }
4873
+ else {
4874
+ throw new Error("UIVerticalInterpolationConstraint.buildLHS.c: invalid element type");
4875
+ }
4876
+ // C - A*(1-t) - B*t = 0
4877
+ const aScaled = aExpression.clone().multiply(1 - this._private_tInternal);
4878
+ const bScaled = bExpression.clone().multiply(this._private_tInternal);
4879
+ return UIExpression.minus(UIExpression.minus(cExpression, aScaled), bScaled);
4880
+ }
4881
+ }
4882
+
4482
4883
  /** Maintains proportional height relationship (A.height * proportion = B.height) */
4483
4884
  class UIVerticalProportionConstraint extends UISingleParameterConstraint {
4484
4885
  /**
@@ -4487,12 +4888,12 @@ class UIVerticalProportionConstraint extends UISingleParameterConstraint {
4487
4888
  * @param options Proportion configuration
4488
4889
  */
4489
4890
  constructor(_private_a, _private_b, options = {}) {
4490
- super(assertValidConstraintSubjects(_private_a, _private_b, "UIVerticalProportionConstraint"), options);
4491
- this._private_a = _private_a;
4492
- this._private_b = _private_b;
4493
4891
  if (options.proportion !== undefined) {
4494
4892
  assertValidPositiveNumber(options.proportion, "UIVerticalProportionConstraint.constructor.options.proportion");
4495
4893
  }
4894
+ super(assertValidConstraintArguments(_private_a, _private_b, "UIVerticalProportionConstraint.constructor"), options);
4895
+ this._private_a = _private_a;
4896
+ this._private_b = _private_b;
4496
4897
  this._private_proportionInternal = options.proportion ?? 1;
4497
4898
  this.constraint = this.solverWrapper.createConstraint(new UIExpression(0), this._private_buildRHS(), this.relation, this.priority, this.isConstraintEnabled());
4498
4899
  }
@@ -4521,11 +4922,11 @@ class UIWidthConstraint extends UISingleParameterConstraint {
4521
4922
  * @param options Width configuration. Defaults to element's current width.
4522
4923
  */
4523
4924
  constructor(_private_element, options = {}) {
4524
- super(_private_element.layer, options);
4525
- this._private_element = _private_element;
4526
4925
  if (options.width !== undefined) {
4527
4926
  assertValidPositiveNumber(options.width, "UIWidthConstraint.constructor.options.width");
4528
4927
  }
4928
+ super(_private_element.layer, options);
4929
+ this._private_element = _private_element;
4529
4930
  this._private_widthInternal = options.width ?? _private_element.width;
4530
4931
  this.constraint = this.solverWrapper.createConstraint(new UIExpression(0, [[this._private_element.wVariable, 1]]), new UIExpression(this._private_widthInternal), this.relation, this.priority, this.isConstraintEnabled());
4531
4932
  }
@@ -4543,6 +4944,26 @@ class UIWidthConstraint extends UISingleParameterConstraint {
4543
4944
  }
4544
4945
  }
4545
4946
 
4947
+ /**
4948
+ * Normalizes UIType2D input to object form.
4949
+ * @param value Object, tuple, or single value
4950
+ * @returns Normalized object with h and v properties
4951
+ */
4952
+ function normalizeUIType2D(value) {
4953
+ if (value === undefined) {
4954
+ return {};
4955
+ }
4956
+ if (Array.isArray(value)) {
4957
+ return { h: value[0], v: value[1] };
4958
+ }
4959
+ if (typeof value === "object" &&
4960
+ value !== null &&
4961
+ ("h" in value || "v" in value)) {
4962
+ return value;
4963
+ }
4964
+ return { h: value, v: value };
4965
+ }
4966
+
4546
4967
  /** Builder for paired horizontal and vertical constraints */
4547
4968
  class UIConstraint2DBuilder {
4548
4969
  /**
@@ -4552,18 +4973,22 @@ class UIConstraint2DBuilder {
4552
4973
  * @returns Width and height constraints
4553
4974
  */
4554
4975
  static size(element, options = {}) {
4976
+ const size = normalizeUIType2D(options.size);
4977
+ const priority = normalizeUIType2D(options.priority);
4978
+ const relation = normalizeUIType2D(options.relation);
4979
+ const orientation = normalizeUIType2D(options.orientation);
4555
4980
  return {
4556
4981
  h: new UIWidthConstraint(element, {
4557
- width: options.size?.h,
4558
- priority: options.priority?.h,
4559
- relation: options.relation?.h,
4560
- orientation: options.orientation?.h,
4982
+ width: size.h,
4983
+ priority: priority.h,
4984
+ relation: relation.h,
4985
+ orientation: orientation.h,
4561
4986
  }),
4562
4987
  v: new UIHeightConstraint(element, {
4563
- height: options.size?.v,
4564
- priority: options.priority?.v,
4565
- relation: options.relation?.v,
4566
- orientation: options.orientation?.v,
4988
+ height: size.v,
4989
+ priority: priority.v,
4990
+ relation: relation.v,
4991
+ orientation: orientation.v,
4567
4992
  }),
4568
4993
  };
4569
4994
  }
@@ -4575,22 +5000,28 @@ class UIConstraint2DBuilder {
4575
5000
  * @returns Horizontal and vertical distance constraints
4576
5001
  */
4577
5002
  static distance(a, b, options = {}) {
5003
+ const anchorA = normalizeUIType2D(options.anchorA);
5004
+ const anchorB = normalizeUIType2D(options.anchorB);
5005
+ const distance = normalizeUIType2D(options.distance);
5006
+ const priority = normalizeUIType2D(options.priority);
5007
+ const relation = normalizeUIType2D(options.relation);
5008
+ const orientation = normalizeUIType2D(options.orientation);
4578
5009
  return {
4579
5010
  h: new UIHorizontalDistanceConstraint(a, b, {
4580
- anchorA: options.anchorA?.h,
4581
- anchorB: options.anchorB?.h,
4582
- distance: options.distance?.h,
4583
- priority: options.priority?.h,
4584
- relation: options.relation?.h,
4585
- orientation: options.orientation?.h,
5011
+ anchorA: anchorA.h,
5012
+ anchorB: anchorB.h,
5013
+ distance: distance.h,
5014
+ priority: priority.h,
5015
+ relation: relation.h,
5016
+ orientation: orientation.h,
4586
5017
  }),
4587
5018
  v: new UIVerticalDistanceConstraint(a, b, {
4588
- anchorA: options.anchorA?.v,
4589
- anchorB: options.anchorB?.v,
4590
- distance: options.distance?.v,
4591
- priority: options.priority?.v,
4592
- relation: options.relation?.v,
4593
- orientation: options.orientation?.v,
5019
+ anchorA: anchorA.v,
5020
+ anchorB: anchorB.v,
5021
+ distance: distance.v,
5022
+ priority: priority.v,
5023
+ relation: relation.v,
5024
+ orientation: orientation.v,
4594
5025
  }),
4595
5026
  };
4596
5027
  }
@@ -4602,18 +5033,59 @@ class UIConstraint2DBuilder {
4602
5033
  * @returns Horizontal and vertical proportion constraints
4603
5034
  */
4604
5035
  static proportion(a, b, options = {}) {
5036
+ const proportion = normalizeUIType2D(options.proportion);
5037
+ const priority = normalizeUIType2D(options.priority);
5038
+ const relation = normalizeUIType2D(options.relation);
5039
+ const orientation = normalizeUIType2D(options.orientation);
4605
5040
  return {
4606
5041
  h: new UIHorizontalProportionConstraint(a, b, {
4607
- proportion: options.proportion?.h,
4608
- priority: options.priority?.h,
4609
- relation: options.relation?.h,
4610
- orientation: options.orientation?.h,
5042
+ proportion: proportion.h,
5043
+ priority: priority.h,
5044
+ relation: relation.h,
5045
+ orientation: orientation.h,
4611
5046
  }),
4612
5047
  v: new UIVerticalProportionConstraint(a, b, {
4613
- proportion: options.proportion?.v,
4614
- priority: options.priority?.v,
4615
- relation: options.relation?.v,
4616
- orientation: options.orientation?.v,
5048
+ proportion: proportion.v,
5049
+ priority: priority.v,
5050
+ relation: relation.v,
5051
+ orientation: orientation.v,
5052
+ }),
5053
+ };
5054
+ }
5055
+ /**
5056
+ * Creates horizontal and vertical interpolation constraints.
5057
+ * @param a First element
5058
+ * @param b Second element
5059
+ * @param c Element to position between A and B
5060
+ * @param options Interpolation configuration for both axes
5061
+ * @returns Horizontal and vertical interpolation constraints
5062
+ */
5063
+ static interpolation(a, b, c, options = {}) {
5064
+ const anchorA = normalizeUIType2D(options.anchorA);
5065
+ const anchorB = normalizeUIType2D(options.anchorB);
5066
+ const anchorC = normalizeUIType2D(options.anchorC);
5067
+ const t = normalizeUIType2D(options.t);
5068
+ const priority = normalizeUIType2D(options.priority);
5069
+ const relation = normalizeUIType2D(options.relation);
5070
+ const orientation = normalizeUIType2D(options.orientation);
5071
+ return {
5072
+ h: new UIHorizontalInterpolationConstraint(a, b, c, {
5073
+ anchorA: anchorA.h,
5074
+ anchorB: anchorB.h,
5075
+ anchorC: anchorC.h,
5076
+ t: t.h,
5077
+ priority: priority.h,
5078
+ relation: relation.h,
5079
+ orientation: orientation.h,
5080
+ }),
5081
+ v: new UIVerticalInterpolationConstraint(a, b, c, {
5082
+ anchorA: anchorA.v,
5083
+ anchorB: anchorB.v,
5084
+ anchorC: anchorC.v,
5085
+ t: t.v,
5086
+ priority: priority.v,
5087
+ relation: relation.v,
5088
+ orientation: orientation.v,
4617
5089
  }),
4618
5090
  };
4619
5091
  }
@@ -4626,11 +5098,11 @@ class UIAspectConstraint extends UISingleParameterConstraint {
4626
5098
  * @param options Aspect configuration. Defaults to element's current ratio.
4627
5099
  */
4628
5100
  constructor(_private_element, options = {}) {
4629
- super(_private_element.layer, options);
4630
- this._private_element = _private_element;
4631
5101
  if (options.aspect !== undefined) {
4632
5102
  assertValidPositiveNumber(options.aspect, "UIAspectConstraint.constructor.options.aspect");
4633
5103
  }
5104
+ super(_private_element.layer, options);
5105
+ this._private_element = _private_element;
4634
5106
  this._private_aspectInternal = options.aspect ?? _private_element.width / _private_element.height;
4635
5107
  this.constraint = this.solverWrapper.createConstraint(this._private_buildLHS(), new UIExpression(0), this.relation, this.priority, this.isConstraintEnabled());
4636
5108
  }
@@ -5006,12 +5478,12 @@ class UITextureView extends i {
5006
5478
  }
5007
5479
  /** Transparent padding around visible content */
5008
5480
  get trim() {
5009
- const s = this._private_scaleInternal;
5481
+ const scale = this._private_scaleInternal;
5010
5482
  return {
5011
- left: this._private_trimLeft / s,
5012
- right: this._private_trimRight / s,
5013
- top: this._private_trimTop / s,
5014
- bottom: this._private_trimBottom / s,
5483
+ left: this._private_trimLeft / scale,
5484
+ right: this._private_trimRight / scale,
5485
+ top: this._private_trimTop / scale,
5486
+ bottom: this._private_trimBottom / scale,
5015
5487
  };
5016
5488
  }
5017
5489
  get textureDirty() {
@@ -5121,6 +5593,19 @@ class UITextureView extends i {
5121
5593
  }
5122
5594
  }
5123
5595
  _private_setFromAtlasConfig(config) {
5596
+ assertValidPositiveNumber(config.sourceSize.w, "UITextureView.setFromAtlasConfig.config.sourceSize.w");
5597
+ assertValidPositiveNumber(config.sourceSize.h, "UITextureView.setFromAtlasConfig.config.sourceSize.h");
5598
+ assertValidNonNegativeNumber(config.frame.x, "UITextureView.setFromAtlasConfig.config.frame.x");
5599
+ assertValidNonNegativeNumber(config.frame.y, "UITextureView.setFromAtlasConfig.config.frame.y");
5600
+ assertValidPositiveNumber(config.frame.w, "UITextureView.setFromAtlasConfig.config.frame.w");
5601
+ assertValidPositiveNumber(config.frame.h, "UITextureView.setFromAtlasConfig.config.frame.h");
5602
+ assertValidNonNegativeNumber(config.spriteSourceSize.x, "UITextureView.setFromAtlasConfig.config.spriteSourceSize.x");
5603
+ assertValidNonNegativeNumber(config.spriteSourceSize.y, "UITextureView.setFromAtlasConfig.config.spriteSourceSize.y");
5604
+ assertValidPositiveNumber(config.spriteSourceSize.w, "UITextureView.setFromAtlasConfig.config.spriteSourceSize.w");
5605
+ assertValidPositiveNumber(config.spriteSourceSize.h, "UITextureView.setFromAtlasConfig.config.spriteSourceSize.h");
5606
+ if (config.scale !== undefined) {
5607
+ assertValidPositiveNumber(config.scale, "UITextureView.setFromAtlasConfig.config.scale");
5608
+ }
5124
5609
  this._private_sourceWidth = config.sourceSize.w;
5125
5610
  this._private_sourceHeight = config.sourceSize.h;
5126
5611
  if (this.texture !== config.texture) {
@@ -5359,9 +5844,15 @@ class UIAreaRectangle extends UIArea {
5359
5844
  this.y = y;
5360
5845
  this.width = width;
5361
5846
  this.height = height;
5847
+ assertValidNonNegativeNumber(x, "UIAreaRectangle.constructor.x");
5848
+ assertValidNonNegativeNumber(y, "UIAreaRectangle.constructor.y");
5849
+ assertValidNonNegativeNumber(width, "UIAreaRectangle.constructor.width");
5850
+ assertValidNonNegativeNumber(height, "UIAreaRectangle.constructor.height");
5362
5851
  }
5363
5852
  /** @internal */
5364
5853
  contains(pointX, pointY) {
5854
+ assertValidNumber(pointX, "UIAreaRectangle.contains.pointX");
5855
+ assertValidNumber(pointY, "UIAreaRectangle.contains.pointY");
5365
5856
  return (pointX >= this.x &&
5366
5857
  pointX <= this.x + this.width &&
5367
5858
  pointY >= this.y &&
@@ -5751,30 +6242,38 @@ class UIAnimatedImage extends UIElement {
5751
6242
  super.onWillRender(renderer, deltaTime);
5752
6243
  }
5753
6244
  setPlaneTransform() {
5754
- const frame = this._private_sequenceInternal[this._private_sequenceFrameIndex];
5755
- if (this.color.dirty || this._private_currentFrameIndexDirty) {
5756
- this.sceneWrapper.setProperties(this.planeHandler, {
5757
- texture: frame.texture,
5758
- textureTransform: frame.calculateUVTransform(this._private_textureTransform),
5759
- color: this.color,
5760
- });
6245
+ let properties;
6246
+ if (this.color.dirty) {
6247
+ properties ?? (properties = {});
6248
+ properties["color"] = this.color;
5761
6249
  this.color.setDirtyFalse();
5762
6250
  }
5763
- if (this._private_currentFrameIndexDirty ||
5764
- frame.textureDirty ||
5765
- frame.uvTransformDirty ||
5766
- frame.trimDirty ||
6251
+ const frame = this._private_sequenceInternal[this._private_sequenceFrameIndex];
6252
+ if (frame.textureDirty || this._private_currentFrameIndexDirty) {
6253
+ properties ?? (properties = {});
6254
+ properties["texture"] = frame.texture;
6255
+ frame.setTextureDirtyFalse();
6256
+ }
6257
+ if (frame.uvTransformDirty || this._private_currentFrameIndexDirty) {
6258
+ properties ?? (properties = {});
6259
+ properties["textureTransform"] = frame.calculateUVTransform(this._private_textureTransform);
6260
+ frame.setUVTransformDirtyFalse();
6261
+ }
6262
+ if (properties) {
6263
+ this.sceneWrapper.setProperties(this.planeHandler, properties);
6264
+ }
6265
+ const isTransformDirty = this._private_currentFrameIndexDirty ||
5767
6266
  this.micro.dirty ||
6267
+ frame.trimDirty ||
5768
6268
  this.inputWrapper.dirty ||
5769
- this.solverWrapper.dirty) {
6269
+ this.solverWrapper.dirty;
6270
+ if (isTransformDirty) {
5770
6271
  const micro = this.micro;
5771
6272
  const textureTrim = frame.trim;
5772
6273
  this.sceneWrapper.setTransform(this.planeHandler, computeTrimmedTransformMatrix(this.x, this.y, this.width, this.height, this.zIndex, micro.x, micro.y, micro.anchorX, micro.anchorY, micro.scaleX, micro.scaleY, micro.rotation, micro.anchorMode, textureTrim.left, textureTrim.right, textureTrim.top, textureTrim.bottom));
6274
+ this._private_currentFrameIndexDirty = false;
5773
6275
  this.micro.setDirtyFalse();
5774
- frame.setTextureDirtyFalse();
5775
- frame.setUVTransformDirtyFalse();
5776
6276
  frame.setTrimDirtyFalse();
5777
- this._private_currentFrameIndexDirty = false;
5778
6277
  }
5779
6278
  }
5780
6279
  _private_subscribeSequenceEvents() {
@@ -5789,8 +6288,6 @@ class UIAnimatedImage extends UIElement {
5789
6288
  }
5790
6289
  }
5791
6290
 
5792
- const GRAPHICS_TEMP_PROPERTIES = {};
5793
-
5794
6291
  /** Canvas-based 2D drawing element */
5795
6292
  class UIGraphics extends UIElement {
5796
6293
  /**
@@ -5895,19 +6392,13 @@ class UIGraphics extends UIElement {
5895
6392
  }
5896
6393
  onWillRender(renderer, deltaTime) {
5897
6394
  if (this.color.dirty) {
5898
- GRAPHICS_TEMP_PROPERTIES["color"] = this.color;
6395
+ this.sceneWrapper.setProperties(this.planeHandler, { color: this.color });
5899
6396
  this.color.setDirtyFalse();
5900
6397
  }
5901
- else {
5902
- delete GRAPHICS_TEMP_PROPERTIES["color"];
5903
- }
5904
- this.sceneWrapper.setProperties(this.planeHandler, GRAPHICS_TEMP_PROPERTIES);
5905
6398
  super.onWillRender(renderer, deltaTime);
5906
6399
  }
5907
6400
  }
5908
6401
 
5909
- const IMAGE_TEMP_PROPERTIES = {};
5910
-
5911
6402
  /** Textured image element */
5912
6403
  class UIImage extends UIElement {
5913
6404
  /**
@@ -5945,29 +6436,25 @@ class UIImage extends UIElement {
5945
6436
  super.destroy();
5946
6437
  }
5947
6438
  setPlaneTransform() {
6439
+ let properties;
5948
6440
  if (this.color.dirty) {
5949
- IMAGE_TEMP_PROPERTIES["color"] = this.color;
6441
+ properties ?? (properties = {});
6442
+ properties["color"] = this.color;
5950
6443
  this.color.setDirtyFalse();
5951
6444
  }
5952
- else {
5953
- delete IMAGE_TEMP_PROPERTIES["color"];
5954
- }
5955
6445
  if (this.texture.textureDirty) {
5956
- IMAGE_TEMP_PROPERTIES["texture"] = this.texture.texture;
6446
+ properties ?? (properties = {});
6447
+ properties["texture"] = this.texture.texture;
5957
6448
  this.texture.setTextureDirtyFalse();
5958
6449
  }
5959
- else {
5960
- delete IMAGE_TEMP_PROPERTIES["texture"];
5961
- }
5962
6450
  if (this.texture.uvTransformDirty) {
5963
- IMAGE_TEMP_PROPERTIES["textureTransform"] =
5964
- this.texture.calculateUVTransform(this._private_textureTransform);
6451
+ properties ?? (properties = {});
6452
+ properties["textureTransform"] = this.texture.calculateUVTransform(this._private_textureTransform);
5965
6453
  this.texture.setUVTransformDirtyFalse();
5966
6454
  }
5967
- else {
5968
- delete IMAGE_TEMP_PROPERTIES["textureTransform"];
6455
+ if (properties) {
6456
+ this.sceneWrapper.setProperties(this.planeHandler, properties);
5969
6457
  }
5970
- this.sceneWrapper.setProperties(this.planeHandler, IMAGE_TEMP_PROPERTIES);
5971
6458
  const isTransformDirty = this.micro.dirty ||
5972
6459
  this.texture.trimDirty ||
5973
6460
  this.inputWrapper.dirty ||
@@ -6372,15 +6859,6 @@ class UIProgressMaskFunctionDirectional extends UIProgressMaskFunction {
6372
6859
  var source$1 = "vec4 draw(){vec2 transformedUV=(p_textureTransform*vec3(p_uv,1.0)).xy;vec4 diffuseColor=texture2D(p_texture,transformedUV)*p_color;diffuseColor.a*=calculateMask();return diffuseColor;}";
6373
6860
 
6374
6861
  const PROGRESS_DEFAULT_VALUE = 1;
6375
- const PROGRESS_TEMP_PROPERTIES = {};
6376
- function simplifyGLSLSource(source) {
6377
- return source
6378
- .replace(/\/\*[\s\S]*?\*\//g, "")
6379
- .replace(/\/\/[^\n]*/g, "")
6380
- .replace(/\s*([{}(),=;+\-*/<>])\s*/g, "$1")
6381
- .replace(/\s+/g, " ")
6382
- .trim();
6383
- }
6384
6862
 
6385
6863
  /** Progress bar with customizable fill direction */
6386
6864
  class UIProgress extends UIElement {
@@ -6394,16 +6872,18 @@ class UIProgress extends UIElement {
6394
6872
  * @param options - Configuration options
6395
6873
  */
6396
6874
  constructor(layer, texture, options = {}) {
6875
+ if (options.progress !== undefined) {
6876
+ assertValidNumber(options.progress, "UIProgress.constructor.options.progress");
6877
+ }
6397
6878
  const color = new UIColor(options.color);
6398
6879
  const textureView = new UITextureView(texture);
6399
6880
  const textureTransform = textureView.calculateUVTransform();
6400
6881
  const textureResolution = textureView.getResolution();
6401
6882
  options.width = options.width ?? textureView.width;
6402
6883
  options.height = options.height ?? textureView.height;
6403
- const progress = options.progress ?? PROGRESS_DEFAULT_VALUE;
6884
+ const progress = MathUtils.clamp(options.progress ?? PROGRESS_DEFAULT_VALUE, 0, 1);
6404
6885
  const maskFunction = options.maskFunction ?? new UIProgressMaskFunctionDirectional();
6405
- const simplifiedSource = simplifyGLSLSource(maskFunction.source + source$1);
6406
- super(layer, simplifiedSource, {
6886
+ super(layer, maskFunction.source + source$1, {
6407
6887
  texture: textureView.texture,
6408
6888
  textureTransform,
6409
6889
  textureResolution,
@@ -6432,64 +6912,53 @@ class UIProgress extends UIElement {
6432
6912
  get progress() {
6433
6913
  return this._private_progressInternal;
6434
6914
  }
6435
- /** Progress from 0 (empty) to 1 (full). Clamped by shader. */
6915
+ /** Progress from 0 (empty) to 1 (full). Clamped. */
6436
6916
  set progress(value) {
6917
+ assertValidNumber(value, "UIProgress.progress");
6918
+ value = MathUtils.clamp(value, 0, 1);
6437
6919
  if (this._private_progressInternal !== value) {
6438
6920
  this._private_progressInternal = value;
6439
6921
  this._private_progressDirty = true;
6440
6922
  }
6441
6923
  }
6442
6924
  setPlaneTransform() {
6925
+ let properties;
6443
6926
  if (this.color.dirty) {
6444
- PROGRESS_TEMP_PROPERTIES["color"] = this.color;
6927
+ properties ?? (properties = {});
6928
+ properties["color"] = this.color;
6445
6929
  this.color.setDirtyFalse();
6446
6930
  }
6447
- else {
6448
- delete PROGRESS_TEMP_PROPERTIES["color"];
6449
- }
6450
6931
  if (this.texture.textureDirty) {
6451
- PROGRESS_TEMP_PROPERTIES["texture"] = this.texture.texture;
6932
+ properties ?? (properties = {});
6933
+ properties["texture"] = this.texture.texture;
6452
6934
  this.texture.setTextureDirtyFalse();
6453
6935
  }
6454
- else {
6455
- delete PROGRESS_TEMP_PROPERTIES["texture"];
6456
- }
6457
6936
  if (this.texture.uvTransformDirty) {
6458
- PROGRESS_TEMP_PROPERTIES["textureTransform"] =
6459
- this.texture.calculateUVTransform(this._private_textureTransform);
6937
+ properties ?? (properties = {});
6938
+ properties["textureTransform"] = this.texture.calculateUVTransform(this._private_textureTransform);
6460
6939
  this.texture.setUVTransformDirtyFalse();
6461
6940
  }
6462
- else {
6463
- delete PROGRESS_TEMP_PROPERTIES["textureTransform"];
6464
- }
6465
- if (this.texture.uvTransformDirty) {
6466
- PROGRESS_TEMP_PROPERTIES["progress"] = this._private_progressInternal;
6941
+ if (this._private_progressDirty) {
6942
+ properties ?? (properties = {});
6943
+ properties["progress"] = this._private_progressInternal;
6467
6944
  this._private_progressDirty = false;
6468
6945
  }
6469
- else {
6470
- delete PROGRESS_TEMP_PROPERTIES["progress"];
6471
- }
6472
6946
  if (this._private_textureResolutionDirty) {
6473
- PROGRESS_TEMP_PROPERTIES["textureResolution"] =
6474
- this.texture.getResolution(this._private_textureResolution);
6947
+ properties ?? (properties = {});
6948
+ properties["textureResolution"] = this.texture.getResolution(this._private_textureResolution);
6475
6949
  this._private_textureResolutionDirty = false;
6476
6950
  }
6477
- else {
6478
- delete PROGRESS_TEMP_PROPERTIES["textureResolution"];
6479
- }
6480
6951
  if (this.maskFunction.dirty) {
6481
- const properties = this.maskFunction.enumerateProperties();
6482
- for (const key in properties) {
6483
- PROGRESS_TEMP_PROPERTIES[key] = properties[key];
6952
+ properties ?? (properties = {});
6953
+ const maskProperties = this.maskFunction.enumerateProperties();
6954
+ for (const key in maskProperties) {
6955
+ properties[key] = maskProperties[key];
6484
6956
  }
6485
6957
  this.maskFunction.setDirtyFalse();
6486
6958
  }
6487
- else {
6488
- for (const key in this.maskFunction.enumerateProperties()) {
6489
- delete PROGRESS_TEMP_PROPERTIES[key];
6490
- }
6959
+ if (properties) {
6960
+ this.sceneWrapper.setProperties(this.planeHandler, properties);
6491
6961
  }
6492
- this.sceneWrapper.setProperties(this.planeHandler, PROGRESS_TEMP_PROPERTIES);
6493
6962
  const isTransformDirty = this.micro.dirty ||
6494
6963
  this.texture.trimDirty ||
6495
6964
  this.inputWrapper.dirty ||
@@ -6538,11 +7007,10 @@ class UIScene extends UIElement {
6538
7007
  * @throws If resolutionFactor outside range 0.1 to 2.0
6539
7008
  */
6540
7009
  constructor(layer, options = {}) {
6541
- const resolutionFactor = options.resolutionFactor ?? SCENE_DEFAULT_RESOLUTION_FACTOR;
6542
- if (resolutionFactor < SCENE_MIN_RESOLUTION_FACTOR ||
6543
- resolutionFactor > SCENE_MAX_RESOLUTION_FACTOR) {
6544
- throw new Error(`UIScene.constructor.resolutionFactor: must be between ${SCENE_MIN_RESOLUTION_FACTOR} and ${SCENE_MAX_RESOLUTION_FACTOR}.`);
7010
+ if (options.resolutionFactor !== undefined) {
7011
+ assertValidPositiveNumber(options.resolutionFactor, "UIScene.constructor.resolutionFactor");
6545
7012
  }
7013
+ const resolutionFactor = MathUtils.clamp(options.resolutionFactor ?? SCENE_DEFAULT_RESOLUTION_FACTOR, SCENE_MIN_RESOLUTION_FACTOR, SCENE_MAX_RESOLUTION_FACTOR);
6546
7014
  const w = options.width ?? DUMMY_DEFAULT_WIDTH;
6547
7015
  const h = options.height ?? DUMMY_DEFAULT_HEIGHT;
6548
7016
  const renderTarget = new WebGLRenderTarget(w * resolutionFactor, h * resolutionFactor, {
@@ -6613,6 +7081,8 @@ class UIScene extends UIElement {
6613
7081
  }
6614
7082
  /** Render target resolution multiplier. Range 0.1 to 2.0. */
6615
7083
  set resolutionFactor(value) {
7084
+ assertValidPositiveNumber(value, "UIScene.resolutionFactor");
7085
+ value = MathUtils.clamp(value, SCENE_MIN_RESOLUTION_FACTOR, SCENE_MAX_RESOLUTION_FACTOR);
6616
7086
  if (this._private_resolutionFactorInternal !== value) {
6617
7087
  this._private_resolutionFactorInternal = value;
6618
7088
  this._private_resolutionFactorDirty = true;
@@ -6629,14 +7099,15 @@ class UIScene extends UIElement {
6629
7099
  }
6630
7100
  onWillRender(renderer, deltaTime) {
6631
7101
  this._private_evenFrame = !this._private_evenFrame;
6632
- if (this._private_updateRequired ||
7102
+ const isFramebufferDirty = this._private_updateRequired ||
6633
7103
  this._private_updateModeInternal === UISceneUpdateMode.EACH_FRAME ||
6634
7104
  (this._private_updateModeInternal === UISceneUpdateMode.EVERY_SECOND_FRAME && this._private_evenFrame) ||
6635
7105
  (this._private_updateModeInternal === UISceneUpdateMode.ON_PROPERTIES_CHANGE && this._private_propertyDirty) ||
6636
7106
  this.color.dirty ||
6637
7107
  this.clearColor.dirty ||
6638
7108
  (this._private_updateModeInternal === UISceneUpdateMode.ON_DIMENSIONS_CHANGE &&
6639
- (this._private_resolutionFactorDirty || this.solverWrapper.dirty))) {
7109
+ (this._private_resolutionFactorDirty || this.solverWrapper.dirty));
7110
+ if (isFramebufferDirty) {
6640
7111
  if (this._private_resolutionFactorDirty || this.solverWrapper.dirty) {
6641
7112
  this._private_renderTarget.setSize(this.width * this._private_resolutionFactorInternal, this.height * this._private_resolutionFactorInternal);
6642
7113
  this._private_resolutionFactorDirty = false;
@@ -7685,9 +8156,14 @@ class UIAreaCircle extends UIArea {
7685
8156
  this.centerX = centerX;
7686
8157
  this.centerY = centerY;
7687
8158
  this.radius = radius;
8159
+ assertValidNonNegativeNumber(centerX, "UIAreaCircle.constructor.centerX");
8160
+ assertValidNonNegativeNumber(centerY, "UIAreaCircle.constructor.centerY");
8161
+ assertValidNonNegativeNumber(radius, "UIAreaCircle.constructor.radius");
7688
8162
  }
7689
8163
  /** @internal */
7690
8164
  contains(pointX, pointY) {
8165
+ assertValidNumber(pointX, "UIAreaCircle.contains.pointX");
8166
+ assertValidNumber(pointY, "UIAreaCircle.contains.pointY");
7691
8167
  const deltaX = pointX - this.centerX;
7692
8168
  const deltaY = pointY - this.centerY;
7693
8169
  return deltaX * deltaX + deltaY * deltaY <= this.radius * this.radius;
@@ -7707,6 +8183,8 @@ class UIAreaPolygon extends UIArea {
7707
8183
  }
7708
8184
  /** @internal */
7709
8185
  contains(pointX, pointY) {
8186
+ assertValidNumber(pointX, "UIAreaPolygon.contains.pointX");
8187
+ assertValidNumber(pointY, "UIAreaPolygon.contains.pointY");
7710
8188
  const vertexCount = this.vertices.length;
7711
8189
  if (vertexCount < 3) {
7712
8190
  return false;
@@ -7751,10 +8229,17 @@ class UIAreaRoundedRectangle extends UIArea {
7751
8229
  this.width = width;
7752
8230
  this.height = height;
7753
8231
  this.radius = radius;
8232
+ assertValidNonNegativeNumber(x, "UIAreaRoundedRectangle.constructor.x");
8233
+ assertValidNonNegativeNumber(y, "UIAreaRoundedRectangle.constructor.y");
8234
+ assertValidNonNegativeNumber(width, "UIAreaRoundedRectangle.constructor.width");
8235
+ assertValidNonNegativeNumber(height, "UIAreaRoundedRectangle.constructor.height");
8236
+ assertValidNonNegativeNumber(radius, "UIAreaRoundedRectangle.constructor.radius");
7754
8237
  this.radius = Math.min(radius, Math.min(width, height) / 2);
7755
8238
  }
7756
8239
  /** @internal */
7757
8240
  contains(pointX, pointY) {
8241
+ assertValidNumber(pointX, "UIAreaRoundedRectangle.contains.pointX");
8242
+ assertValidNumber(pointY, "UIAreaRoundedRectangle.contains.pointY");
7758
8243
  const left = this.x;
7759
8244
  const right = this.x + this.width;
7760
8245
  const top = this.y;
@@ -7803,6 +8288,7 @@ class UIProgressMaskFunctionCircular extends UIProgressMaskFunction {
7803
8288
  * @param inverseDirection - Whether to fill counter-clockwise
7804
8289
  */
7805
8290
  constructor(startAngle = 0, inverseDirection = false) {
8291
+ assertValidNumber(startAngle, "UIProgressMaskFunctionCircular.constructor.startAngle");
7806
8292
  super(source);
7807
8293
  this._private_startAngleInternal = startAngle;
7808
8294
  this._private_inverseDirectionInternal = inverseDirection;
@@ -7817,6 +8303,7 @@ class UIProgressMaskFunctionCircular extends UIProgressMaskFunction {
7817
8303
  }
7818
8304
  /** Starting angle in radians */
7819
8305
  set startAngle(value) {
8306
+ assertValidNumber(value, "UIProgressMaskFunctionCircular.startAngle");
7820
8307
  if (this._private_startAngleInternal !== value) {
7821
8308
  this._private_startAngleInternal = value;
7822
8309
  this.dirtyInternal = true;
@@ -8122,5 +8609,5 @@ class UIResizePolicyFixedWidth extends UIResizePolicy {
8122
8609
  }
8123
8610
  }
8124
8611
 
8125
- export { UIAnchor, UIAnimatedImage, UIAreaCircle, UIAreaPolygon, UIAreaRectangle, UIAreaRoundedRectangle, UIAspectConstraint, UIColor, UIConstraint2DBuilder, UICoverConstraintBuilder, UICustomConstraint, UIExpression, UIFitConstraintBuilder, UIFullscreenLayer, UIGraphics, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalProportionConstraint, UIImage, UIInputDummy, UIInputEvent, UIMicro, UIMicroAnchorMode, UIMode, UINineSlice, UINineSliceRegionMode, UIOrientation, UIPriority, UIProgress, UIProgressMaskFunctionCircular, UIProgressMaskFunctionDirectional, UIRelation, UIResizePolicyCover, UIResizePolicyCross, UIResizePolicyCrossInverted, UIResizePolicyFit, UIResizePolicyFixedHeight, UIResizePolicyFixedWidth, UIResizePolicyNone, UIScene, UISceneUpdateMode, UISingleParameterConstraint, UIText, UITextResizeMode, UITransparencyMode, UIVerticalDistanceConstraint, UIVerticalProportionConstraint, UIWidthConstraint };
8612
+ export { UIAnchor, UIAnimatedImage, UIAreaCircle, UIAreaPolygon, UIAreaRectangle, UIAreaRoundedRectangle, UIAspectConstraint, UIColor, UIConstraint2DBuilder, UICoverConstraintBuilder, UICustomConstraint, UIExpression, UIFitConstraintBuilder, UIFullscreenLayer, UIGraphics, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalInterpolationConstraint, UIHorizontalProportionConstraint, UIImage, UIInputDummy, UIInputEvent, UIMicro, UIMicroAnchorMode, UIMode, UINineSlice, UINineSliceRegionMode, UIOrientation, UIPriority, UIProgress, UIProgressMaskFunctionCircular, UIProgressMaskFunctionDirectional, UIRelation, UIResizePolicyCover, UIResizePolicyCross, UIResizePolicyCrossInverted, UIResizePolicyFit, UIResizePolicyFixedHeight, UIResizePolicyFixedWidth, UIResizePolicyNone, UIScene, UISceneUpdateMode, UISingleParameterConstraint, UIText, UITextResizeMode, UITransparencyMode, UIVerticalDistanceConstraint, UIVerticalInterpolationConstraint, UIVerticalProportionConstraint, UIWidthConstraint };
8126
8613
  //# sourceMappingURL=index.js.map