laymur 0.3.19 → 0.3.21

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
@@ -6639,13 +6639,17 @@ class UIText extends UIElement {
6639
6639
  }
6640
6640
  }
6641
6641
 
6642
+ var UIResizePolicyEvent;
6643
+ (function (UIResizePolicyEvent) {
6644
+ UIResizePolicyEvent[UIResizePolicyEvent["CHANGE"] = 0] = "CHANGE";
6645
+ })(UIResizePolicyEvent || (UIResizePolicyEvent = {}));
6642
6646
  /**
6643
6647
  * Base class for UI resize policies.
6644
6648
  *
6645
6649
  * Calculates scale factors based on viewport dimensions. Different policies
6646
6650
  * implement different scaling strategies.
6647
6651
  */
6648
- class UIResizePolicy {
6652
+ class UIResizePolicy extends i {
6649
6653
  }
6650
6654
  /**
6651
6655
  * No scaling applied, always returns 1:1 scale.
@@ -6667,15 +6671,35 @@ class UIResizePolicyFixedWidth extends UIResizePolicy {
6667
6671
  */
6668
6672
  constructor(fixedWidthLandscape, fixedWidthPortrait) {
6669
6673
  super();
6670
- this.fixedWidthLandscape = fixedWidthLandscape;
6671
- this.fixedWidthPortrait = fixedWidthPortrait;
6672
6674
  assertValidPositiveNumber(fixedWidthLandscape, "UIResizePolicyFixedWidth.fixedWidthLandscape");
6673
6675
  assertValidPositiveNumber(fixedWidthPortrait, "UIResizePolicyFixedWidth.fixedWidthPortrait");
6676
+ this._private_fixedWidthLandscapeInternal = fixedWidthLandscape;
6677
+ this._private_fixedWidthPortraitInternal = fixedWidthPortrait;
6678
+ }
6679
+ get fixedWidthLandscape() {
6680
+ return this._private_fixedWidthLandscapeInternal;
6681
+ }
6682
+ get fixedWidthPortrait() {
6683
+ return this._private_fixedWidthPortraitInternal;
6684
+ }
6685
+ set fixedWidthLandscape(value) {
6686
+ assertValidPositiveNumber(value, "UIResizePolicyFixedWidth.fixedWidthLandscape");
6687
+ if (value !== this._private_fixedWidthLandscapeInternal) {
6688
+ this._private_fixedWidthLandscapeInternal = value;
6689
+ this.emit(UIResizePolicyEvent.CHANGE);
6690
+ }
6691
+ }
6692
+ set fixedWidthPortrait(value) {
6693
+ assertValidPositiveNumber(value, "UIResizePolicyFixedWidth.fixedWidthPortrait");
6694
+ if (value !== this._private_fixedWidthPortraitInternal) {
6695
+ this._private_fixedWidthPortraitInternal = value;
6696
+ this.emit(UIResizePolicyEvent.CHANGE);
6697
+ }
6674
6698
  }
6675
6699
  calculateScaleInternal(width, height) {
6676
6700
  return width > height
6677
- ? this.fixedWidthLandscape / width
6678
- : this.fixedWidthPortrait / width;
6701
+ ? this._private_fixedWidthLandscapeInternal / width
6702
+ : this._private_fixedWidthPortraitInternal / width;
6679
6703
  }
6680
6704
  }
6681
6705
  /**
@@ -6690,15 +6714,35 @@ class UIResizePolicyFixedHeight extends UIResizePolicy {
6690
6714
  */
6691
6715
  constructor(fixedHeightLandscape, fixedHeightPortrait) {
6692
6716
  super();
6693
- this.fixedHeightLandscape = fixedHeightLandscape;
6694
- this.fixedHeightPortrait = fixedHeightPortrait;
6695
6717
  assertValidPositiveNumber(fixedHeightLandscape, "UIResizePolicyFixedHeight.fixedHeightLandscape");
6696
6718
  assertValidPositiveNumber(fixedHeightPortrait, "UIResizePolicyFixedHeight.fixedHeightPortrait");
6719
+ this._private_fixedHeightLandscapeInternal = fixedHeightLandscape;
6720
+ this._private_fixedHeightPortraitInternal = fixedHeightPortrait;
6721
+ }
6722
+ get fixedHeightLandscape() {
6723
+ return this._private_fixedHeightLandscapeInternal;
6724
+ }
6725
+ get fixedHeightPortrait() {
6726
+ return this._private_fixedHeightPortraitInternal;
6727
+ }
6728
+ set fixedHeightLandscape(value) {
6729
+ assertValidPositiveNumber(value, "UIResizePolicyFixedHeight.fixedHeightLandscape");
6730
+ if (value !== this._private_fixedHeightLandscapeInternal) {
6731
+ this._private_fixedHeightLandscapeInternal = value;
6732
+ this.emit(UIResizePolicyEvent.CHANGE);
6733
+ }
6734
+ }
6735
+ set fixedHeightPortrait(value) {
6736
+ assertValidPositiveNumber(value, "UIResizePolicyFixedHeight.fixedHeightPortrait");
6737
+ if (value !== this._private_fixedHeightPortraitInternal) {
6738
+ this._private_fixedHeightPortraitInternal = value;
6739
+ this.emit(UIResizePolicyEvent.CHANGE);
6740
+ }
6697
6741
  }
6698
6742
  calculateScaleInternal(width, height) {
6699
6743
  return width > height
6700
- ? this.fixedHeightLandscape / height
6701
- : this.fixedHeightPortrait / height;
6744
+ ? this._private_fixedHeightLandscapeInternal / height
6745
+ : this._private_fixedHeightPortraitInternal / height;
6702
6746
  }
6703
6747
  }
6704
6748
  /**
@@ -6711,15 +6755,35 @@ class UIResizePolicyCross extends UIResizePolicy {
6711
6755
  */
6712
6756
  constructor(fixedWidthLandscape, fixedHeightPortrait) {
6713
6757
  super();
6714
- this.fixedWidthLandscape = fixedWidthLandscape;
6715
- this.fixedHeightPortrait = fixedHeightPortrait;
6716
6758
  assertValidPositiveNumber(fixedWidthLandscape, "UIResizePolicyCross.fixedWidthLandscape");
6717
6759
  assertValidPositiveNumber(fixedHeightPortrait, "UIResizePolicyCross.fixedHeightPortrait");
6760
+ this._private_fixedWidthLandscapeInternal = fixedWidthLandscape;
6761
+ this._private_fixedHeightPortraitInternal = fixedHeightPortrait;
6762
+ }
6763
+ get fixedWidthLandscape() {
6764
+ return this._private_fixedWidthLandscapeInternal;
6765
+ }
6766
+ get fixedHeightPortrait() {
6767
+ return this._private_fixedHeightPortraitInternal;
6768
+ }
6769
+ set fixedWidthLandscape(value) {
6770
+ assertValidPositiveNumber(value, "UIResizePolicyCross.fixedWidthLandscape");
6771
+ if (value !== this._private_fixedWidthLandscapeInternal) {
6772
+ this._private_fixedWidthLandscapeInternal = value;
6773
+ this.emit(UIResizePolicyEvent.CHANGE);
6774
+ }
6775
+ }
6776
+ set fixedHeightPortrait(value) {
6777
+ assertValidPositiveNumber(value, "UIResizePolicyCross.fixedHeightPortrait");
6778
+ if (value !== this._private_fixedHeightPortraitInternal) {
6779
+ this._private_fixedHeightPortraitInternal = value;
6780
+ this.emit(UIResizePolicyEvent.CHANGE);
6781
+ }
6718
6782
  }
6719
6783
  calculateScaleInternal(width, height) {
6720
6784
  return width > height
6721
- ? this.fixedWidthLandscape / width
6722
- : this.fixedHeightPortrait / height;
6785
+ ? this._private_fixedWidthLandscapeInternal / width
6786
+ : this._private_fixedHeightPortraitInternal / height;
6723
6787
  }
6724
6788
  }
6725
6789
  /**
@@ -6732,15 +6796,35 @@ class UIResizePolicyCrossInverted extends UIResizePolicy {
6732
6796
  */
6733
6797
  constructor(fixedHeightLandscape, fixedWidthPortrait) {
6734
6798
  super();
6735
- this.fixedHeightLandscape = fixedHeightLandscape;
6736
- this.fixedWidthPortrait = fixedWidthPortrait;
6737
6799
  assertValidPositiveNumber(fixedHeightLandscape, "UIResizePolicyCrossInverted.fixedHeightLandscape");
6738
6800
  assertValidPositiveNumber(fixedWidthPortrait, "UIResizePolicyCrossInverted.fixedWidthPortrait");
6801
+ this._private_fixedHeightLandscapeInternal = fixedHeightLandscape;
6802
+ this._private_fixedWidthPortraitInternal = fixedWidthPortrait;
6803
+ }
6804
+ get fixedHeightLandscape() {
6805
+ return this._private_fixedHeightLandscapeInternal;
6806
+ }
6807
+ get fixedWidthPortrait() {
6808
+ return this._private_fixedWidthPortraitInternal;
6809
+ }
6810
+ set fixedHeightLandscape(value) {
6811
+ assertValidPositiveNumber(value, "UIResizePolicyCrossInverted.fixedHeightLandscape");
6812
+ if (value !== this._private_fixedHeightLandscapeInternal) {
6813
+ this._private_fixedHeightLandscapeInternal = value;
6814
+ this.emit(UIResizePolicyEvent.CHANGE);
6815
+ }
6816
+ }
6817
+ set fixedWidthPortrait(value) {
6818
+ assertValidPositiveNumber(value, "UIResizePolicyCrossInverted.fixedWidthPortrait");
6819
+ if (value !== this._private_fixedWidthPortraitInternal) {
6820
+ this._private_fixedWidthPortraitInternal = value;
6821
+ this.emit(UIResizePolicyEvent.CHANGE);
6822
+ }
6739
6823
  }
6740
6824
  calculateScaleInternal(width, height) {
6741
6825
  return width > height
6742
- ? this.fixedHeightLandscape / height
6743
- : this.fixedWidthPortrait / width;
6826
+ ? this._private_fixedHeightLandscapeInternal / height
6827
+ : this._private_fixedWidthPortraitInternal / width;
6744
6828
  }
6745
6829
  }
6746
6830
 
@@ -6757,14 +6841,13 @@ class UIFullscreenLayer extends UILayer {
6757
6841
  /**
6758
6842
  * Creates a fullscreen layer and sets up window event listeners.
6759
6843
  */
6760
- constructor() {
6844
+ constructor(resizePolicy = new UIResizePolicyNone()) {
6761
6845
  super(window.innerWidth, window.innerHeight);
6762
- this.resizePolicy = new UIResizePolicyNone();
6763
6846
  /**
6764
6847
  * Handles window resize. Updates layer dimensions according to resize policy.
6765
6848
  */
6766
6849
  this._private_onResize = () => {
6767
- const scale = this.resizePolicy.calculateScaleInternal(window.innerWidth, window.innerHeight);
6850
+ const scale = this._private_resizePolicyInternal.calculateScaleInternal(window.innerWidth, window.innerHeight);
6768
6851
  this.resizeInternal(window.innerWidth * scale, window.innerHeight * scale);
6769
6852
  };
6770
6853
  /**
@@ -6781,19 +6864,39 @@ class UIFullscreenLayer extends UILayer {
6781
6864
  const y = rect
6782
6865
  ? rect.bottom - event.clientY
6783
6866
  : window.innerHeight - event.clientY;
6784
- const scale = this.resizePolicy.calculateScaleInternal(window.innerWidth, window.innerHeight);
6867
+ const scale = this._private_resizePolicyInternal.calculateScaleInternal(window.innerWidth, window.innerHeight);
6785
6868
  this.pointerClickInternal(x * scale, y * scale);
6786
6869
  };
6787
6870
  window.addEventListener("resize", this._private_onResize);
6788
6871
  window.addEventListener("pointerdown", this._private_onClick);
6872
+ this._private_resizePolicyInternal = resizePolicy;
6873
+ this._private_resizePolicyInternal.on(UIResizePolicyEvent.CHANGE, this._private_onResize);
6789
6874
  this._private_onResize();
6790
6875
  }
6876
+ /**
6877
+ * Gets the current resize policy.
6878
+ */
6879
+ get resizePolicy() {
6880
+ return this._private_resizePolicyInternal;
6881
+ }
6882
+ /**
6883
+ * Sets a new resize policy. Unsubscribes from old policy and subscribes to new one.
6884
+ */
6885
+ set resizePolicy(value) {
6886
+ if (this._private_resizePolicyInternal !== value) {
6887
+ this._private_resizePolicyInternal.off(UIResizePolicyEvent.CHANGE, this._private_onResize);
6888
+ this._private_resizePolicyInternal = value;
6889
+ this._private_resizePolicyInternal.on(UIResizePolicyEvent.CHANGE, this._private_onResize);
6890
+ this._private_onResize();
6891
+ }
6892
+ }
6791
6893
  /**
6792
6894
  * Removes window event listeners. The layer should not be used after this.
6793
6895
  */
6794
6896
  destroy() {
6795
6897
  window.removeEventListener("resize", this._private_onResize);
6796
6898
  window.removeEventListener("pointerdown", this._private_onClick);
6899
+ this._private_resizePolicyInternal.off(UIResizePolicyEvent.CHANGE, this._private_onResize);
6797
6900
  }
6798
6901
  /**
6799
6902
  * Renders the layer.
@@ -7222,5 +7325,5 @@ function isUITextSpan(obj) {
7222
7325
  (!("style" in obj) || isUITextStyle(obj.style)));
7223
7326
  }
7224
7327
 
7225
- export { UIAnchor, UIAnimatedImage, UIAnimatedImageEvent, UIAspectConstraint, UIColor, UIColorEvent, UIConstraint, UIConstraint2DBuilder, UICoverConstraintBuilder, UICustomConstraint, UIDummy, UIElement, UIExpression, UIFitConstraintBuilder, UIFullscreenLayer, UIGenericInstancedPlane, UIGraphics, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalProportionConstraint, UIImage, UIInputEvent, UILayer, UILayerEvent, UIMicro, UIMicroAnchorMode, UIMicroEvent, UIMode, UINineSlice, UIOrientation, UIPriority, UIProgress, UIProgressMaskFunction, UIRelation, UIResizePolicy, UIResizePolicyCross, UIResizePolicyCrossInverted, UIResizePolicyFixedHeight, UIResizePolicyFixedWidth, UIResizePolicyNone, UIScene, UISceneUpdateMode, UISingleParameterConstraint, UIText, UITransparencyMode, UIVerticalDistanceConstraint, UIVerticalProportionConstraint, UIWidthConstraint, convertPriority, convertRelation, isUITextSpan, isUITextStyle, resolveOrientation, resolvePriority, resolveRelation, resolveTextPadding, resolveTextStyle };
7328
+ export { UIAnchor, UIAnimatedImage, UIAnimatedImageEvent, UIAspectConstraint, UIColor, UIColorEvent, UIConstraint, UIConstraint2DBuilder, UICoverConstraintBuilder, UICustomConstraint, UIDummy, UIElement, UIExpression, UIFitConstraintBuilder, UIFullscreenLayer, UIGenericInstancedPlane, UIGraphics, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalProportionConstraint, UIImage, UIInputEvent, UILayer, UILayerEvent, UIMicro, UIMicroAnchorMode, UIMicroEvent, UIMode, UINineSlice, UIOrientation, UIPriority, UIProgress, UIProgressMaskFunction, UIRelation, UIResizePolicy, UIResizePolicyCross, UIResizePolicyCrossInverted, UIResizePolicyEvent, UIResizePolicyFixedHeight, UIResizePolicyFixedWidth, UIResizePolicyNone, UIScene, UISceneUpdateMode, UISingleParameterConstraint, UIText, UITransparencyMode, UIVerticalDistanceConstraint, UIVerticalProportionConstraint, UIWidthConstraint, convertPriority, convertRelation, isUITextSpan, isUITextStyle, resolveOrientation, resolvePriority, resolveRelation, resolveTextPadding, resolveTextStyle };
7226
7329
  //# sourceMappingURL=index.js.map