@tspro/ts-utils-lib 1.20.0 → 1.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/index.d.mts +406 -70
- package/dist/index.d.ts +406 -70
- package/dist/index.js +617 -74
- package/dist/index.mjs +615 -74
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* TsUtilsLib v1.
|
|
1
|
+
/* TsUtilsLib v1.21.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -23,6 +23,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
23
23
|
// src/index.ts
|
|
24
24
|
var index_exports = {};
|
|
25
25
|
__export(index_exports, {
|
|
26
|
+
AnchoredRect: () => AnchoredRect,
|
|
26
27
|
Assert: () => assert_exports,
|
|
27
28
|
BaseContainer: () => BaseContainer,
|
|
28
29
|
BiMap: () => BiMap,
|
|
@@ -40,6 +41,7 @@ __export(index_exports, {
|
|
|
40
41
|
Map2: () => Map2,
|
|
41
42
|
Map3: () => Map3,
|
|
42
43
|
MultiContainer: () => MultiContainer,
|
|
44
|
+
Rect: () => Rect,
|
|
43
45
|
Set1: () => Set1,
|
|
44
46
|
SetBase: () => SetBase,
|
|
45
47
|
SignedIndexArray: () => SignedIndexArray,
|
|
@@ -1659,8 +1661,179 @@ var Vec = class _Vec extends BaseContainer {
|
|
|
1659
1661
|
}
|
|
1660
1662
|
};
|
|
1661
1663
|
|
|
1662
|
-
// src/core/
|
|
1663
|
-
var
|
|
1664
|
+
// src/core/rect.ts
|
|
1665
|
+
var Rect = class _Rect {
|
|
1666
|
+
constructor(...args) {
|
|
1667
|
+
__publicField(this, "x");
|
|
1668
|
+
__publicField(this, "y");
|
|
1669
|
+
__publicField(this, "width");
|
|
1670
|
+
__publicField(this, "height");
|
|
1671
|
+
if (args.length === 0) {
|
|
1672
|
+
this.x = this.y = this.width = this.height = 0;
|
|
1673
|
+
} else if (args.length === 2) {
|
|
1674
|
+
this.x = this.y = 0;
|
|
1675
|
+
this.width = args[0];
|
|
1676
|
+
this.height = args[1];
|
|
1677
|
+
} else {
|
|
1678
|
+
this.x = args[0];
|
|
1679
|
+
this.y = args[1];
|
|
1680
|
+
this.width = args[2];
|
|
1681
|
+
this.height = args[3];
|
|
1682
|
+
}
|
|
1683
|
+
if (this.width < 0 || this.height < 0)
|
|
1684
|
+
throw new Error("Rect width and height must be non-negative.");
|
|
1685
|
+
}
|
|
1686
|
+
set(...args) {
|
|
1687
|
+
if (args.length === 0) {
|
|
1688
|
+
this.x = this.y = this.width = this.height = 0;
|
|
1689
|
+
} else if (args.length === 2) {
|
|
1690
|
+
this.x = this.y = 0;
|
|
1691
|
+
this.width = args[0];
|
|
1692
|
+
this.height = args[1];
|
|
1693
|
+
} else {
|
|
1694
|
+
this.x = args[0];
|
|
1695
|
+
this.y = args[1];
|
|
1696
|
+
this.width = args[2];
|
|
1697
|
+
this.height = args[3];
|
|
1698
|
+
}
|
|
1699
|
+
if (this.width < 0 || this.height < 0)
|
|
1700
|
+
throw new Error("Rect width and height must be non-negative.");
|
|
1701
|
+
return this;
|
|
1702
|
+
}
|
|
1703
|
+
// --- Static Constructors ---
|
|
1704
|
+
static fromPoints(p1, p2) {
|
|
1705
|
+
const x = Math.min(p1.x, p2.x);
|
|
1706
|
+
const y = Math.min(p1.y, p2.y);
|
|
1707
|
+
const w = Math.abs(p1.x - p2.x);
|
|
1708
|
+
const h = Math.abs(p1.y - p2.y);
|
|
1709
|
+
return new _Rect(x, y, w, h);
|
|
1710
|
+
}
|
|
1711
|
+
static fromCenter(cx, cy, width, height) {
|
|
1712
|
+
return new _Rect(cx - width / 2, cy - height / 2, width, height);
|
|
1713
|
+
}
|
|
1714
|
+
// --- Derived Properties ---
|
|
1715
|
+
get left() {
|
|
1716
|
+
return this.x;
|
|
1717
|
+
}
|
|
1718
|
+
get top() {
|
|
1719
|
+
return this.y;
|
|
1720
|
+
}
|
|
1721
|
+
get right() {
|
|
1722
|
+
return this.x + this.width;
|
|
1723
|
+
}
|
|
1724
|
+
get bottom() {
|
|
1725
|
+
return this.y + this.height;
|
|
1726
|
+
}
|
|
1727
|
+
get centerX() {
|
|
1728
|
+
return this.x + this.width / 2;
|
|
1729
|
+
}
|
|
1730
|
+
get centerY() {
|
|
1731
|
+
return this.y + this.height / 2;
|
|
1732
|
+
}
|
|
1733
|
+
get center() {
|
|
1734
|
+
return { x: this.centerX, y: this.centerY };
|
|
1735
|
+
}
|
|
1736
|
+
get area() {
|
|
1737
|
+
return this.width * this.height;
|
|
1738
|
+
}
|
|
1739
|
+
get isEmpty() {
|
|
1740
|
+
return this.width <= 0 || this.height <= 0;
|
|
1741
|
+
}
|
|
1742
|
+
// --- Geometric Tests ---
|
|
1743
|
+
containsPoint(px, py) {
|
|
1744
|
+
return px >= this.left && px <= this.right && py >= this.top && py <= this.bottom;
|
|
1745
|
+
}
|
|
1746
|
+
containsRect(other) {
|
|
1747
|
+
return other.left >= this.left && other.right <= this.right && other.top >= this.top && other.bottom <= this.bottom;
|
|
1748
|
+
}
|
|
1749
|
+
intersects(other) {
|
|
1750
|
+
return !(other.right < this.left || other.left > this.right || other.bottom < this.top || other.top > this.bottom);
|
|
1751
|
+
}
|
|
1752
|
+
// --- Operations ---
|
|
1753
|
+
intersectionCopy(other) {
|
|
1754
|
+
const x1 = Math.max(this.left, other.left);
|
|
1755
|
+
const y1 = Math.max(this.top, other.top);
|
|
1756
|
+
const x2 = Math.min(this.right, other.right);
|
|
1757
|
+
const y2 = Math.min(this.bottom, other.bottom);
|
|
1758
|
+
if (x2 <= x1 || y2 <= y1) return new _Rect();
|
|
1759
|
+
return new _Rect(x1, y1, x2 - x1, y2 - y1);
|
|
1760
|
+
}
|
|
1761
|
+
unionCopy(other) {
|
|
1762
|
+
const x1 = Math.min(this.left, other.left);
|
|
1763
|
+
const y1 = Math.min(this.top, other.top);
|
|
1764
|
+
const x2 = Math.max(this.right, other.right);
|
|
1765
|
+
const y2 = Math.max(this.bottom, other.bottom);
|
|
1766
|
+
return new _Rect(x1, y1, x2 - x1, y2 - y1);
|
|
1767
|
+
}
|
|
1768
|
+
insetCopy(dx, dy) {
|
|
1769
|
+
return new _Rect(this.x + dx, this.y + dy, this.width - 2 * dx, this.height - 2 * dy);
|
|
1770
|
+
}
|
|
1771
|
+
inflateCopy(dx, dy) {
|
|
1772
|
+
return new _Rect(this.x - dx, this.y - dy, this.width + 2 * dx, this.height + 2 * dy);
|
|
1773
|
+
}
|
|
1774
|
+
offsetInPlace(dx, dy) {
|
|
1775
|
+
this.x += dx;
|
|
1776
|
+
this.y += dy;
|
|
1777
|
+
return this;
|
|
1778
|
+
}
|
|
1779
|
+
offsetCopy(dx, dy) {
|
|
1780
|
+
return new _Rect(this.x + dx, this.y + dy, this.width, this.height);
|
|
1781
|
+
}
|
|
1782
|
+
scaleInPlace(scaleX, scaleY = scaleX) {
|
|
1783
|
+
this.x = this.centerX - this.width * scaleX / 2;
|
|
1784
|
+
this.width *= scaleX;
|
|
1785
|
+
this.y = this.centerY - this.height * scaleY / 2;
|
|
1786
|
+
this.height *= scaleY;
|
|
1787
|
+
return this;
|
|
1788
|
+
}
|
|
1789
|
+
scaleCopy(scaleX, scaleY = scaleX) {
|
|
1790
|
+
return this.clone().scaleInPlace(scaleX, scaleY);
|
|
1791
|
+
}
|
|
1792
|
+
roundCopy() {
|
|
1793
|
+
const left = Math.round(this.left);
|
|
1794
|
+
const top = Math.round(this.top);
|
|
1795
|
+
const right = Math.round(this.right);
|
|
1796
|
+
const bottom = Math.round(this.bottom);
|
|
1797
|
+
return new _Rect(left, top, right - left, bottom - top);
|
|
1798
|
+
}
|
|
1799
|
+
floorCopy() {
|
|
1800
|
+
const left = Math.floor(this.left);
|
|
1801
|
+
const top = Math.floor(this.top);
|
|
1802
|
+
const right = Math.floor(this.right);
|
|
1803
|
+
const bottom = Math.floor(this.bottom);
|
|
1804
|
+
return new _Rect(left, top, right - left, bottom - top);
|
|
1805
|
+
}
|
|
1806
|
+
ceilCopy() {
|
|
1807
|
+
const left = Math.ceil(this.left);
|
|
1808
|
+
const top = Math.ceil(this.top);
|
|
1809
|
+
const right = Math.ceil(this.right);
|
|
1810
|
+
const bottom = Math.ceil(this.bottom);
|
|
1811
|
+
return new _Rect(left, top, right - left, bottom - top);
|
|
1812
|
+
}
|
|
1813
|
+
expandCopy(px, py) {
|
|
1814
|
+
const left = Math.min(this.left, px);
|
|
1815
|
+
const top = Math.min(this.top, py);
|
|
1816
|
+
const right = Math.max(this.right, px);
|
|
1817
|
+
const bottom = Math.max(this.bottom, py);
|
|
1818
|
+
return new _Rect(left, top, right - left, bottom - top);
|
|
1819
|
+
}
|
|
1820
|
+
// --- Utilities ---
|
|
1821
|
+
equals(other) {
|
|
1822
|
+
return this.x === other.x && this.y === other.y && this.width === other.width && this.height === other.height;
|
|
1823
|
+
}
|
|
1824
|
+
clone() {
|
|
1825
|
+
return new _Rect(this.x, this.y, this.width, this.height);
|
|
1826
|
+
}
|
|
1827
|
+
toString() {
|
|
1828
|
+
return `Rect(x=${this.x}, y=${this.y}, w=${this.width}, h=${this.height})`;
|
|
1829
|
+
}
|
|
1830
|
+
toAnchoredRect() {
|
|
1831
|
+
return new AnchoredRect(this.left, this.right, this.top, this.bottom);
|
|
1832
|
+
}
|
|
1833
|
+
};
|
|
1834
|
+
|
|
1835
|
+
// src/core/anchor-rect.ts
|
|
1836
|
+
var AnchoredRect = class _AnchoredRect {
|
|
1664
1837
|
constructor(...args) {
|
|
1665
1838
|
__publicField(this, "left");
|
|
1666
1839
|
__publicField(this, "anchorX");
|
|
@@ -1686,8 +1859,31 @@ var DivRect = class _DivRect {
|
|
|
1686
1859
|
this.left = this.anchorX = this.right = 0;
|
|
1687
1860
|
this.top = this.anchorY = this.bottom = 0;
|
|
1688
1861
|
} else {
|
|
1689
|
-
throw new TypeError(`Invalid
|
|
1862
|
+
throw new TypeError(`Invalid AnchoredRect args: ${args}`);
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
set(...args) {
|
|
1866
|
+
if (args.length === 6) {
|
|
1867
|
+
this.left = args[0];
|
|
1868
|
+
this.anchorX = args[1];
|
|
1869
|
+
this.right = args[2];
|
|
1870
|
+
this.top = args[3];
|
|
1871
|
+
this.anchorY = args[4];
|
|
1872
|
+
this.bottom = args[5];
|
|
1873
|
+
} else if (args.length === 4) {
|
|
1874
|
+
this.left = args[0];
|
|
1875
|
+
this.right = args[1];
|
|
1876
|
+
this.anchorX = (this.left + this.right) / 2;
|
|
1877
|
+
this.top = args[2];
|
|
1878
|
+
this.bottom = args[3];
|
|
1879
|
+
this.anchorY = (this.top + this.bottom) / 2;
|
|
1880
|
+
} else if (args.length === 0) {
|
|
1881
|
+
this.left = this.anchorX = this.right = 0;
|
|
1882
|
+
this.top = this.anchorY = this.bottom = 0;
|
|
1883
|
+
} else {
|
|
1884
|
+
throw new TypeError(`Invalid AnchoredRect args: ${args}`);
|
|
1690
1885
|
}
|
|
1886
|
+
return this;
|
|
1691
1887
|
}
|
|
1692
1888
|
/**
|
|
1693
1889
|
* Create rect from basic left, top, width and height arguments.
|
|
@@ -1696,10 +1892,10 @@ var DivRect = class _DivRect {
|
|
|
1696
1892
|
* @param top - Top coordinate.
|
|
1697
1893
|
* @param width - Width.
|
|
1698
1894
|
* @param height - Height.
|
|
1699
|
-
* @returns -
|
|
1895
|
+
* @returns - AnchoredRect.
|
|
1700
1896
|
*/
|
|
1701
1897
|
static create(left, top, width, height) {
|
|
1702
|
-
return new
|
|
1898
|
+
return new _AnchoredRect(left, left + width, top, top + height);
|
|
1703
1899
|
}
|
|
1704
1900
|
/**
|
|
1705
1901
|
* Create rect from anchorX, anchorY, width, height arguments.
|
|
@@ -1708,10 +1904,10 @@ var DivRect = class _DivRect {
|
|
|
1708
1904
|
* @param centerY - Center y-coordinate.
|
|
1709
1905
|
* @param width - Width.
|
|
1710
1906
|
* @param height - Height.
|
|
1711
|
-
* @returns -
|
|
1907
|
+
* @returns - AnchoredRect.
|
|
1712
1908
|
*/
|
|
1713
1909
|
static createCentered(centerX, centerY, width, height) {
|
|
1714
|
-
return new
|
|
1910
|
+
return new _AnchoredRect(
|
|
1715
1911
|
centerX - width / 2,
|
|
1716
1912
|
centerX,
|
|
1717
1913
|
centerX + width / 2,
|
|
@@ -1727,38 +1923,22 @@ var DivRect = class _DivRect {
|
|
|
1727
1923
|
* @param rightw - Right section width.
|
|
1728
1924
|
* @param toph - Top section height.
|
|
1729
1925
|
* @param bottomh - Bottomsection height.
|
|
1730
|
-
* @returns -
|
|
1926
|
+
* @returns - AnchoredRect.
|
|
1731
1927
|
*/
|
|
1732
1928
|
static createSections(leftw, rightw, toph, bottomh) {
|
|
1733
|
-
return new
|
|
1929
|
+
return new _AnchoredRect(-leftw, 0, rightw, -toph, 0, bottomh);
|
|
1734
1930
|
}
|
|
1735
1931
|
/**
|
|
1736
|
-
*
|
|
1737
|
-
|
|
1738
|
-
* */
|
|
1932
|
+
* Get center x-coordinate.
|
|
1933
|
+
*/
|
|
1739
1934
|
get centerX() {
|
|
1740
|
-
return this.
|
|
1741
|
-
}
|
|
1742
|
-
/**
|
|
1743
|
-
* @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
|
|
1744
|
-
* @private
|
|
1745
|
-
* */
|
|
1746
|
-
set centerX(x) {
|
|
1747
|
-
this.anchorX = x;
|
|
1935
|
+
return this.left + this.width / 2;
|
|
1748
1936
|
}
|
|
1749
1937
|
/**
|
|
1750
|
-
*
|
|
1751
|
-
|
|
1752
|
-
* */
|
|
1938
|
+
* Get center ycoordinate.
|
|
1939
|
+
*/
|
|
1753
1940
|
get centerY() {
|
|
1754
|
-
return this.
|
|
1755
|
-
}
|
|
1756
|
-
/**
|
|
1757
|
-
* @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
|
|
1758
|
-
* @private
|
|
1759
|
-
* */
|
|
1760
|
-
set centerY(y) {
|
|
1761
|
-
this.anchorY = y;
|
|
1941
|
+
return this.top + this.height / 2;
|
|
1762
1942
|
}
|
|
1763
1943
|
/**
|
|
1764
1944
|
* Width getter.
|
|
@@ -1809,8 +1989,8 @@ var DivRect = class _DivRect {
|
|
|
1809
1989
|
/**
|
|
1810
1990
|
* Do a and b rects overlap?
|
|
1811
1991
|
*
|
|
1812
|
-
* @param a -
|
|
1813
|
-
* @param b -
|
|
1992
|
+
* @param a - AnchoredRect a.
|
|
1993
|
+
* @param b - AnchoredRect b.
|
|
1814
1994
|
* @returns - True/false.
|
|
1815
1995
|
*/
|
|
1816
1996
|
static overlap(a, b) {
|
|
@@ -1819,8 +1999,8 @@ var DivRect = class _DivRect {
|
|
|
1819
1999
|
/**
|
|
1820
2000
|
* Do horizontal measures of a and b rects overlap?
|
|
1821
2001
|
*
|
|
1822
|
-
* @param a -
|
|
1823
|
-
* @param b -
|
|
2002
|
+
* @param a - AnchoredRect a.
|
|
2003
|
+
* @param b - AnchoredRect b.
|
|
1824
2004
|
* @returns - True/false.
|
|
1825
2005
|
*/
|
|
1826
2006
|
static overlapX(a, b) {
|
|
@@ -1828,8 +2008,8 @@ var DivRect = class _DivRect {
|
|
|
1828
2008
|
}
|
|
1829
2009
|
/**
|
|
1830
2010
|
* Check if given rects are equal.
|
|
1831
|
-
* @param a -
|
|
1832
|
-
* @param b -
|
|
2011
|
+
* @param a - AnchoredRect a.
|
|
2012
|
+
* @param b - AnchoredRect b.
|
|
1833
2013
|
* @returns - True/false.
|
|
1834
2014
|
*/
|
|
1835
2015
|
static equals(a, b) {
|
|
@@ -1847,13 +2027,13 @@ var DivRect = class _DivRect {
|
|
|
1847
2027
|
* @returns - True/false.
|
|
1848
2028
|
*/
|
|
1849
2029
|
equals(other) {
|
|
1850
|
-
return
|
|
2030
|
+
return _AnchoredRect.equals(this, other);
|
|
1851
2031
|
}
|
|
1852
2032
|
/**
|
|
1853
2033
|
* Check if edges of given rects are equal, ignoring anchorX and anchorY.
|
|
1854
2034
|
*
|
|
1855
|
-
* @param a -
|
|
1856
|
-
* @param b -
|
|
2035
|
+
* @param a - AnchoredRect a.
|
|
2036
|
+
* @param b - AnchoredRect b.
|
|
1857
2037
|
* @returns - True/false.
|
|
1858
2038
|
*/
|
|
1859
2039
|
static equalsEdges(a, b) {
|
|
@@ -1868,33 +2048,25 @@ var DivRect = class _DivRect {
|
|
|
1868
2048
|
/**
|
|
1869
2049
|
* Check if edges of this Rect equals with given Rect, ignoring anchorX and anchorY.
|
|
1870
2050
|
*
|
|
1871
|
-
* @param other - The other
|
|
2051
|
+
* @param other - The other AnchoredRect.
|
|
1872
2052
|
* @returns - True/false.
|
|
1873
2053
|
*/
|
|
1874
2054
|
equalsEdges(other) {
|
|
1875
|
-
return
|
|
1876
|
-
}
|
|
1877
|
-
/**
|
|
1878
|
-
* @deprecated - Use `DivRect.equalsEdges()` instead. Will be removed in v2.0.0.
|
|
1879
|
-
* @private
|
|
1880
|
-
*/
|
|
1881
|
-
static equalsFrame(a, b) {
|
|
1882
|
-
return _DivRect.equalsEdges(a, b);
|
|
2055
|
+
return _AnchoredRect.equalsEdges(this, other);
|
|
1883
2056
|
}
|
|
1884
2057
|
/**
|
|
1885
2058
|
* Created duplicate of this Rect.
|
|
1886
|
-
*
|
|
1887
2059
|
* @returns - Duplicate.
|
|
1888
2060
|
*/
|
|
1889
|
-
|
|
1890
|
-
return new
|
|
2061
|
+
clone() {
|
|
2062
|
+
return new _AnchoredRect(this.left, this.anchorX, this.right, this.top, this.anchorY, this.bottom);
|
|
1891
2063
|
}
|
|
1892
2064
|
/**
|
|
1893
2065
|
* Move this rect by (dx, dy). Modifies this Rect.
|
|
1894
2066
|
*
|
|
1895
2067
|
* @param dx - Offset amount in x-direction.
|
|
1896
2068
|
* @param dy - Offset amount in y-direction.
|
|
1897
|
-
* @returns - This
|
|
2069
|
+
* @returns - This AnchoredRect instance.
|
|
1898
2070
|
*/
|
|
1899
2071
|
offsetInPlace(dx, dy) {
|
|
1900
2072
|
this.left += dx;
|
|
@@ -1910,16 +2082,16 @@ var DivRect = class _DivRect {
|
|
|
1910
2082
|
*
|
|
1911
2083
|
* @param dx - Offset amount in x-direction.
|
|
1912
2084
|
* @param dy - Offset amount in y-direction.
|
|
1913
|
-
* @returns -
|
|
2085
|
+
* @returns - AnchoredRect copy with applied offset.
|
|
1914
2086
|
*/
|
|
1915
2087
|
offsetCopy(dx, dy) {
|
|
1916
|
-
return this.
|
|
2088
|
+
return this.clone().offsetInPlace(dx, dy);
|
|
1917
2089
|
}
|
|
1918
2090
|
/**
|
|
1919
2091
|
* Expand this Rect by given Rect. Modifies this Rect.
|
|
1920
2092
|
*
|
|
1921
|
-
* @param rect -
|
|
1922
|
-
* @returns - This
|
|
2093
|
+
* @param rect - AnchoredRect to expand this instance with.
|
|
2094
|
+
* @returns - This AnchoredRect instance.
|
|
1923
2095
|
*/
|
|
1924
2096
|
expandInPlace(rect) {
|
|
1925
2097
|
this.left = Math.min(this.left, rect.left);
|
|
@@ -1931,17 +2103,17 @@ var DivRect = class _DivRect {
|
|
|
1931
2103
|
/**
|
|
1932
2104
|
* Expand this Rect by given Rect. Immutable, returns modified copy.
|
|
1933
2105
|
*
|
|
1934
|
-
* @param rect -
|
|
1935
|
-
* @returns - Expanded copy of this
|
|
2106
|
+
* @param rect - AnchoredRect to expand this instance with.
|
|
2107
|
+
* @returns - Expanded copy of this AnchoredRect.
|
|
1936
2108
|
*/
|
|
1937
2109
|
expandCopy(rect) {
|
|
1938
|
-
return this.
|
|
2110
|
+
return this.clone().expandInPlace(rect);
|
|
1939
2111
|
}
|
|
1940
2112
|
/**
|
|
1941
2113
|
* Clip this Rect by given Rect. Mmodifies this Rect.
|
|
1942
2114
|
*
|
|
1943
|
-
* @param clipRect -
|
|
1944
|
-
* @returns - This
|
|
2115
|
+
* @param clipRect - AnchoredRect to clip this instance with.
|
|
2116
|
+
* @returns - This AnchoredRect instance.
|
|
1945
2117
|
*/
|
|
1946
2118
|
clipInPlace(clipRect) {
|
|
1947
2119
|
this.left = Math.max(this.left, clipRect.left);
|
|
@@ -1955,21 +2127,20 @@ var DivRect = class _DivRect {
|
|
|
1955
2127
|
/**
|
|
1956
2128
|
* Clip this Rect by given Rect. Immutable, return modified copy.
|
|
1957
2129
|
*
|
|
1958
|
-
* @param clipRect -
|
|
1959
|
-
* @returns - Clipped
|
|
2130
|
+
* @param clipRect - AnchoredRecto to clip this instance with.
|
|
2131
|
+
* @returns - Clipped AnchoredRect copy.
|
|
1960
2132
|
*/
|
|
1961
2133
|
clipCopy(clipRect) {
|
|
1962
|
-
return this.
|
|
2134
|
+
return this.clone().clipInPlace(clipRect);
|
|
1963
2135
|
}
|
|
1964
2136
|
/**
|
|
1965
2137
|
* Scale Rect. Anchor pos is (anchorX, anchorY). Modifies this Rect.
|
|
1966
2138
|
*
|
|
1967
2139
|
* @param scaleX - Scale x-amount.
|
|
1968
2140
|
* @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
|
|
1969
|
-
* @returns This
|
|
2141
|
+
* @returns This AnchoredRect instance.
|
|
1970
2142
|
*/
|
|
1971
|
-
scaleInPlace(scaleX, scaleY) {
|
|
1972
|
-
scaleY = scaleY ?? scaleX;
|
|
2143
|
+
scaleInPlace(scaleX, scaleY = scaleX) {
|
|
1973
2144
|
this.left = this.anchorX - this.leftw * scaleX;
|
|
1974
2145
|
this.right = this.anchorX + this.rightw * scaleX;
|
|
1975
2146
|
this.top = this.anchorY - this.toph * scaleY;
|
|
@@ -1981,18 +2152,21 @@ var DivRect = class _DivRect {
|
|
|
1981
2152
|
*
|
|
1982
2153
|
* @param scaleX - Scale x-amount.
|
|
1983
2154
|
* @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
|
|
1984
|
-
* @returns Scaled copy of this
|
|
2155
|
+
* @returns Scaled copy of this AnchoredRect.
|
|
1985
2156
|
*/
|
|
1986
|
-
scaleCopy(scaleX, scaleY) {
|
|
1987
|
-
return this.
|
|
2157
|
+
scaleCopy(scaleX, scaleY = scaleX) {
|
|
2158
|
+
return this.clone().scaleInPlace(scaleX, scaleY);
|
|
1988
2159
|
}
|
|
1989
2160
|
/**
|
|
1990
|
-
* Get this
|
|
1991
|
-
* @returns - This
|
|
2161
|
+
* Get this AnchoredRect instance.
|
|
2162
|
+
* @returns - This AnchoredRect instance.
|
|
1992
2163
|
*/
|
|
1993
2164
|
getRect() {
|
|
1994
2165
|
return this;
|
|
1995
2166
|
}
|
|
2167
|
+
toRect() {
|
|
2168
|
+
return new Rect(this.left, this.right, this.width, this.height);
|
|
2169
|
+
}
|
|
1996
2170
|
};
|
|
1997
2171
|
|
|
1998
2172
|
// src/core/LRU-cache.ts
|
|
@@ -4901,8 +5075,376 @@ var DeepSet = class _DeepSet extends SetBase {
|
|
|
4901
5075
|
return isDeepEqual2(a, b);
|
|
4902
5076
|
}
|
|
4903
5077
|
};
|
|
5078
|
+
|
|
5079
|
+
// src/deprecated/div-rect.ts
|
|
5080
|
+
var DivRect = class _DivRect {
|
|
5081
|
+
constructor(...args) {
|
|
5082
|
+
__publicField(this, "left");
|
|
5083
|
+
__publicField(this, "anchorX");
|
|
5084
|
+
__publicField(this, "right");
|
|
5085
|
+
__publicField(this, "top");
|
|
5086
|
+
__publicField(this, "anchorY");
|
|
5087
|
+
__publicField(this, "bottom");
|
|
5088
|
+
if (args.length === 6) {
|
|
5089
|
+
this.left = args[0];
|
|
5090
|
+
this.anchorX = args[1];
|
|
5091
|
+
this.right = args[2];
|
|
5092
|
+
this.top = args[3];
|
|
5093
|
+
this.anchorY = args[4];
|
|
5094
|
+
this.bottom = args[5];
|
|
5095
|
+
} else if (args.length === 4) {
|
|
5096
|
+
this.left = args[0];
|
|
5097
|
+
this.right = args[1];
|
|
5098
|
+
this.anchorX = (this.left + this.right) / 2;
|
|
5099
|
+
this.top = args[2];
|
|
5100
|
+
this.bottom = args[3];
|
|
5101
|
+
this.anchorY = (this.top + this.bottom) / 2;
|
|
5102
|
+
} else if (args.length === 0) {
|
|
5103
|
+
this.left = this.anchorX = this.right = 0;
|
|
5104
|
+
this.top = this.anchorY = this.bottom = 0;
|
|
5105
|
+
} else {
|
|
5106
|
+
throw new TypeError(`Invalid DivRect args: ${args}`);
|
|
5107
|
+
}
|
|
5108
|
+
}
|
|
5109
|
+
set(...args) {
|
|
5110
|
+
if (args.length === 6) {
|
|
5111
|
+
this.left = args[0];
|
|
5112
|
+
this.anchorX = args[1];
|
|
5113
|
+
this.right = args[2];
|
|
5114
|
+
this.top = args[3];
|
|
5115
|
+
this.anchorY = args[4];
|
|
5116
|
+
this.bottom = args[5];
|
|
5117
|
+
} else if (args.length === 4) {
|
|
5118
|
+
this.left = args[0];
|
|
5119
|
+
this.right = args[1];
|
|
5120
|
+
this.anchorX = (this.left + this.right) / 2;
|
|
5121
|
+
this.top = args[2];
|
|
5122
|
+
this.bottom = args[3];
|
|
5123
|
+
this.anchorY = (this.top + this.bottom) / 2;
|
|
5124
|
+
} else if (args.length === 0) {
|
|
5125
|
+
this.left = this.anchorX = this.right = 0;
|
|
5126
|
+
this.top = this.anchorY = this.bottom = 0;
|
|
5127
|
+
} else {
|
|
5128
|
+
throw new TypeError(`Invalid DivRect args: ${args}`);
|
|
5129
|
+
}
|
|
5130
|
+
return this;
|
|
5131
|
+
}
|
|
5132
|
+
/**
|
|
5133
|
+
* Create rect from basic left, top, width and height arguments.
|
|
5134
|
+
*
|
|
5135
|
+
* @param left - Left coordinate.
|
|
5136
|
+
* @param top - Top coordinate.
|
|
5137
|
+
* @param width - Width.
|
|
5138
|
+
* @param height - Height.
|
|
5139
|
+
* @returns - DivRect.
|
|
5140
|
+
*/
|
|
5141
|
+
static create(left, top, width, height) {
|
|
5142
|
+
return new _DivRect(left, left + width, top, top + height);
|
|
5143
|
+
}
|
|
5144
|
+
/**
|
|
5145
|
+
* Create rect from anchorX, anchorY, width, height arguments.
|
|
5146
|
+
*
|
|
5147
|
+
* @param centerX - Center x-coordinate.
|
|
5148
|
+
* @param centerY - Center y-coordinate.
|
|
5149
|
+
* @param width - Width.
|
|
5150
|
+
* @param height - Height.
|
|
5151
|
+
* @returns - DivRect.
|
|
5152
|
+
*/
|
|
5153
|
+
static createCentered(centerX, centerY, width, height) {
|
|
5154
|
+
return new _DivRect(
|
|
5155
|
+
centerX - width / 2,
|
|
5156
|
+
centerX,
|
|
5157
|
+
centerX + width / 2,
|
|
5158
|
+
centerY - height / 2,
|
|
5159
|
+
centerY,
|
|
5160
|
+
centerY + height / 2
|
|
5161
|
+
);
|
|
5162
|
+
}
|
|
5163
|
+
/**
|
|
5164
|
+
* Create rect from sections.
|
|
5165
|
+
*
|
|
5166
|
+
* @param leftw - Left section width.
|
|
5167
|
+
* @param rightw - Right section width.
|
|
5168
|
+
* @param toph - Top section height.
|
|
5169
|
+
* @param bottomh - Bottomsection height.
|
|
5170
|
+
* @returns - DivRect.
|
|
5171
|
+
*/
|
|
5172
|
+
static createSections(leftw, rightw, toph, bottomh) {
|
|
5173
|
+
return new _DivRect(-leftw, 0, rightw, -toph, 0, bottomh);
|
|
5174
|
+
}
|
|
5175
|
+
/**
|
|
5176
|
+
* @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
|
|
5177
|
+
* @private
|
|
5178
|
+
* */
|
|
5179
|
+
get centerX() {
|
|
5180
|
+
return this.anchorX;
|
|
5181
|
+
}
|
|
5182
|
+
/**
|
|
5183
|
+
* @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
|
|
5184
|
+
* @private
|
|
5185
|
+
* */
|
|
5186
|
+
set centerX(x) {
|
|
5187
|
+
this.anchorX = x;
|
|
5188
|
+
}
|
|
5189
|
+
/**
|
|
5190
|
+
* @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
|
|
5191
|
+
* @private
|
|
5192
|
+
* */
|
|
5193
|
+
get centerY() {
|
|
5194
|
+
return this.anchorY;
|
|
5195
|
+
}
|
|
5196
|
+
/**
|
|
5197
|
+
* @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
|
|
5198
|
+
* @private
|
|
5199
|
+
* */
|
|
5200
|
+
set centerY(y) {
|
|
5201
|
+
this.anchorY = y;
|
|
5202
|
+
}
|
|
5203
|
+
/**
|
|
5204
|
+
* Width getter.
|
|
5205
|
+
*/
|
|
5206
|
+
get width() {
|
|
5207
|
+
return this.right - this.left;
|
|
5208
|
+
}
|
|
5209
|
+
/**
|
|
5210
|
+
* Height getter.
|
|
5211
|
+
*/
|
|
5212
|
+
get height() {
|
|
5213
|
+
return this.bottom - this.top;
|
|
5214
|
+
}
|
|
5215
|
+
/**
|
|
5216
|
+
* Left section width getter.
|
|
5217
|
+
*/
|
|
5218
|
+
get leftw() {
|
|
5219
|
+
return this.anchorX - this.left;
|
|
5220
|
+
}
|
|
5221
|
+
/**
|
|
5222
|
+
* Right section width getter.
|
|
5223
|
+
*/
|
|
5224
|
+
get rightw() {
|
|
5225
|
+
return this.right - this.anchorX;
|
|
5226
|
+
}
|
|
5227
|
+
/**
|
|
5228
|
+
* Top section height getter.
|
|
5229
|
+
*/
|
|
5230
|
+
get toph() {
|
|
5231
|
+
return this.anchorY - this.top;
|
|
5232
|
+
}
|
|
5233
|
+
/**
|
|
5234
|
+
* Bottom section height getter.
|
|
5235
|
+
*/
|
|
5236
|
+
get bottomh() {
|
|
5237
|
+
return this.bottom - this.anchorY;
|
|
5238
|
+
}
|
|
5239
|
+
/**
|
|
5240
|
+
* Does this Rect contain given (x, y)-point?
|
|
5241
|
+
*
|
|
5242
|
+
* @param x - X-coordinate.
|
|
5243
|
+
* @param y - Y-coordinate.
|
|
5244
|
+
* @returns - True/false.
|
|
5245
|
+
*/
|
|
5246
|
+
contains(x, y) {
|
|
5247
|
+
return x >= this.left && x <= this.right && y >= this.top && y <= this.bottom;
|
|
5248
|
+
}
|
|
5249
|
+
/**
|
|
5250
|
+
* Do a and b rects overlap?
|
|
5251
|
+
*
|
|
5252
|
+
* @param a - DivRect a.
|
|
5253
|
+
* @param b - DivRect b.
|
|
5254
|
+
* @returns - True/false.
|
|
5255
|
+
*/
|
|
5256
|
+
static overlap(a, b) {
|
|
5257
|
+
return a.right > b.left && a.left < b.right && a.bottom > b.top && a.top < b.bottom;
|
|
5258
|
+
}
|
|
5259
|
+
/**
|
|
5260
|
+
* Do horizontal measures of a and b rects overlap?
|
|
5261
|
+
*
|
|
5262
|
+
* @param a - DivRect a.
|
|
5263
|
+
* @param b - DivRect b.
|
|
5264
|
+
* @returns - True/false.
|
|
5265
|
+
*/
|
|
5266
|
+
static overlapX(a, b) {
|
|
5267
|
+
return a.right > b.left && a.left < b.right;
|
|
5268
|
+
}
|
|
5269
|
+
/**
|
|
5270
|
+
* Check if given rects are equal.
|
|
5271
|
+
* @param a - DivRect a.
|
|
5272
|
+
* @param b - DivRect b.
|
|
5273
|
+
* @returns - True/false.
|
|
5274
|
+
*/
|
|
5275
|
+
static equals(a, b) {
|
|
5276
|
+
if (a == null && b == null) {
|
|
5277
|
+
return true;
|
|
5278
|
+
} else if (a == null || b == null) {
|
|
5279
|
+
return false;
|
|
5280
|
+
} else {
|
|
5281
|
+
return a === b || a.left === b.left && a.anchorX === b.anchorX && a.right === b.right && a.top === b.top && a.anchorY === b.anchorY && a.bottom === b.bottom;
|
|
5282
|
+
}
|
|
5283
|
+
}
|
|
5284
|
+
/**
|
|
5285
|
+
* Check if this rect equals with another rect.
|
|
5286
|
+
* @param other - The other rect.
|
|
5287
|
+
* @returns - True/false.
|
|
5288
|
+
*/
|
|
5289
|
+
equals(other) {
|
|
5290
|
+
return _DivRect.equals(this, other);
|
|
5291
|
+
}
|
|
5292
|
+
/**
|
|
5293
|
+
* Check if edges of given rects are equal, ignoring anchorX and anchorY.
|
|
5294
|
+
*
|
|
5295
|
+
* @param a - DivRect a.
|
|
5296
|
+
* @param b - DivRect b.
|
|
5297
|
+
* @returns - True/false.
|
|
5298
|
+
*/
|
|
5299
|
+
static equalsEdges(a, b) {
|
|
5300
|
+
if (a == null && b == null) {
|
|
5301
|
+
return true;
|
|
5302
|
+
} else if (a == null || b == null) {
|
|
5303
|
+
return false;
|
|
5304
|
+
} else {
|
|
5305
|
+
return a === b || a.left === b.left && a.right === b.right && a.top === b.top && a.bottom === b.bottom;
|
|
5306
|
+
}
|
|
5307
|
+
}
|
|
5308
|
+
/**
|
|
5309
|
+
* Check if edges of this Rect equals with given Rect, ignoring anchorX and anchorY.
|
|
5310
|
+
*
|
|
5311
|
+
* @param other - The other DivRect.
|
|
5312
|
+
* @returns - True/false.
|
|
5313
|
+
*/
|
|
5314
|
+
equalsEdges(other) {
|
|
5315
|
+
return _DivRect.equalsEdges(this, other);
|
|
5316
|
+
}
|
|
5317
|
+
/**
|
|
5318
|
+
* @deprecated - Use {@link equalsEdges()} instead. Will be removed in v2.0.0.
|
|
5319
|
+
* @private
|
|
5320
|
+
*/
|
|
5321
|
+
static equalsFrame(a, b) {
|
|
5322
|
+
return _DivRect.equalsEdges(a, b);
|
|
5323
|
+
}
|
|
5324
|
+
/**
|
|
5325
|
+
* @deprecated - Use {@link clone()} instead. Will be removed in v2.0.0.
|
|
5326
|
+
* @private
|
|
5327
|
+
*/
|
|
5328
|
+
copy() {
|
|
5329
|
+
return new _DivRect(this.left, this.anchorX, this.right, this.top, this.anchorY, this.bottom);
|
|
5330
|
+
}
|
|
5331
|
+
/**
|
|
5332
|
+
* Created duplicate of this Rect.
|
|
5333
|
+
* @returns - Duplicate.
|
|
5334
|
+
*/
|
|
5335
|
+
clone() {
|
|
5336
|
+
return new _DivRect(this.left, this.anchorX, this.right, this.top, this.anchorY, this.bottom);
|
|
5337
|
+
}
|
|
5338
|
+
/**
|
|
5339
|
+
* Move this rect by (dx, dy). Modifies this Rect.
|
|
5340
|
+
*
|
|
5341
|
+
* @param dx - Offset amount in x-direction.
|
|
5342
|
+
* @param dy - Offset amount in y-direction.
|
|
5343
|
+
* @returns - This DivRect instance.
|
|
5344
|
+
*/
|
|
5345
|
+
offsetInPlace(dx, dy) {
|
|
5346
|
+
this.left += dx;
|
|
5347
|
+
this.anchorX += dx;
|
|
5348
|
+
this.right += dx;
|
|
5349
|
+
this.top += dy;
|
|
5350
|
+
this.anchorY += dy;
|
|
5351
|
+
this.bottom += dy;
|
|
5352
|
+
return this;
|
|
5353
|
+
}
|
|
5354
|
+
/**
|
|
5355
|
+
* Move this rect by (dx, dy). Immutable, returns modified copy.
|
|
5356
|
+
*
|
|
5357
|
+
* @param dx - Offset amount in x-direction.
|
|
5358
|
+
* @param dy - Offset amount in y-direction.
|
|
5359
|
+
* @returns - DivRect copy with applied offset.
|
|
5360
|
+
*/
|
|
5361
|
+
offsetCopy(dx, dy) {
|
|
5362
|
+
return this.clone().offsetInPlace(dx, dy);
|
|
5363
|
+
}
|
|
5364
|
+
/**
|
|
5365
|
+
* Expand this Rect by given Rect. Modifies this Rect.
|
|
5366
|
+
*
|
|
5367
|
+
* @param rect - DivRect to expand this instance with.
|
|
5368
|
+
* @returns - This DivRect instance.
|
|
5369
|
+
*/
|
|
5370
|
+
expandInPlace(rect) {
|
|
5371
|
+
this.left = Math.min(this.left, rect.left);
|
|
5372
|
+
this.right = Math.max(this.right, rect.right);
|
|
5373
|
+
this.top = Math.min(this.top, rect.top);
|
|
5374
|
+
this.bottom = Math.max(this.bottom, rect.bottom);
|
|
5375
|
+
return this;
|
|
5376
|
+
}
|
|
5377
|
+
/**
|
|
5378
|
+
* Expand this Rect by given Rect. Immutable, returns modified copy.
|
|
5379
|
+
*
|
|
5380
|
+
* @param rect - DivRect to expand this instance with.
|
|
5381
|
+
* @returns - Expanded copy of this DivRect.
|
|
5382
|
+
*/
|
|
5383
|
+
expandCopy(rect) {
|
|
5384
|
+
return this.clone().expandInPlace(rect);
|
|
5385
|
+
}
|
|
5386
|
+
/**
|
|
5387
|
+
* Clip this Rect by given Rect. Mmodifies this Rect.
|
|
5388
|
+
*
|
|
5389
|
+
* @param clipRect - DivRect to clip this instance with.
|
|
5390
|
+
* @returns - This DivRect instance.
|
|
5391
|
+
*/
|
|
5392
|
+
clipInPlace(clipRect) {
|
|
5393
|
+
this.left = Math.max(this.left, clipRect.left);
|
|
5394
|
+
this.right = Math.min(this.right, clipRect.right);
|
|
5395
|
+
this.anchorX = clamp(this.anchorX, this.left, this.right);
|
|
5396
|
+
this.top = Math.max(this.top, clipRect.top);
|
|
5397
|
+
this.bottom = Math.min(this.bottom, clipRect.bottom);
|
|
5398
|
+
this.anchorY = clamp(this.anchorY, this.top, this.bottom);
|
|
5399
|
+
return this;
|
|
5400
|
+
}
|
|
5401
|
+
/**
|
|
5402
|
+
* Clip this Rect by given Rect. Immutable, return modified copy.
|
|
5403
|
+
*
|
|
5404
|
+
* @param clipRect - DivRecto to clip this instance with.
|
|
5405
|
+
* @returns - Clipped DivRect copy.
|
|
5406
|
+
*/
|
|
5407
|
+
clipCopy(clipRect) {
|
|
5408
|
+
return this.clone().clipInPlace(clipRect);
|
|
5409
|
+
}
|
|
5410
|
+
/**
|
|
5411
|
+
* Scale Rect. Anchor pos is (anchorX, anchorY). Modifies this Rect.
|
|
5412
|
+
*
|
|
5413
|
+
* @param scaleX - Scale x-amount.
|
|
5414
|
+
* @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
|
|
5415
|
+
* @returns This DivRect instance.
|
|
5416
|
+
*/
|
|
5417
|
+
scaleInPlace(scaleX, scaleY = scaleX) {
|
|
5418
|
+
this.left = this.anchorX - this.leftw * scaleX;
|
|
5419
|
+
this.right = this.anchorX + this.rightw * scaleX;
|
|
5420
|
+
this.top = this.anchorY - this.toph * scaleY;
|
|
5421
|
+
this.bottom = this.anchorY + this.bottomh * scaleY;
|
|
5422
|
+
return this;
|
|
5423
|
+
}
|
|
5424
|
+
/**
|
|
5425
|
+
* Scale Rect. Anchor pos is (anchorX, anchorY). Immutable, returns modified copy.
|
|
5426
|
+
*
|
|
5427
|
+
* @param scaleX - Scale x-amount.
|
|
5428
|
+
* @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
|
|
5429
|
+
* @returns Scaled copy of this DivRect.
|
|
5430
|
+
*/
|
|
5431
|
+
scaleCopy(scaleX, scaleY = scaleX) {
|
|
5432
|
+
return this.clone().scaleInPlace(scaleX, scaleY);
|
|
5433
|
+
}
|
|
5434
|
+
/**
|
|
5435
|
+
* Get this DivRect instance.
|
|
5436
|
+
* @returns - This DivRect instance.
|
|
5437
|
+
*/
|
|
5438
|
+
getRect() {
|
|
5439
|
+
return this;
|
|
5440
|
+
}
|
|
5441
|
+
toRect() {
|
|
5442
|
+
return new Rect(this.left, this.right, this.width, this.height);
|
|
5443
|
+
}
|
|
5444
|
+
};
|
|
4904
5445
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4905
5446
|
0 && (module.exports = {
|
|
5447
|
+
AnchoredRect,
|
|
4906
5448
|
Assert,
|
|
4907
5449
|
BaseContainer,
|
|
4908
5450
|
BiMap,
|
|
@@ -4920,6 +5462,7 @@ var DeepSet = class _DeepSet extends SetBase {
|
|
|
4920
5462
|
Map2,
|
|
4921
5463
|
Map3,
|
|
4922
5464
|
MultiContainer,
|
|
5465
|
+
Rect,
|
|
4923
5466
|
Set1,
|
|
4924
5467
|
SetBase,
|
|
4925
5468
|
SignedIndexArray,
|