textmode.js 0.1.6-beta.1 → 0.1.6-beta.3
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/textmode.esm.js +135 -110
- package/dist/textmode.esm.min.js +97 -72
- package/dist/textmode.umd.js +5 -5
- package/dist/textmode.umd.min.js +12 -12
- package/dist/types/textmode/Canvas.d.ts +17 -0
- package/package.json +1 -1
package/dist/textmode.esm.min.js
CHANGED
|
@@ -105,7 +105,7 @@ const E = class E {
|
|
|
105
105
|
};
|
|
106
106
|
o(E, "_instance", null);
|
|
107
107
|
let $ = E;
|
|
108
|
-
const
|
|
108
|
+
const v = $.getInstance();
|
|
109
109
|
class oe {
|
|
110
110
|
constructor(e, t, r = t, i = {}) {
|
|
111
111
|
o(this, "gl");
|
|
@@ -249,8 +249,8 @@ class M {
|
|
|
249
249
|
c ? (f = r / l * 2 - 1, g = (r + s) / l * 2 - 1) : (f = 1 - r / l * 2, g = 1 - (r + s) / l * 2);
|
|
250
250
|
let _, p, b, C;
|
|
251
251
|
_ = u, b = d, p = f, C = g;
|
|
252
|
-
const
|
|
253
|
-
this.vertexBuffer = e.createBuffer(), e.bindBuffer(e.ARRAY_BUFFER, this.vertexBuffer), e.bufferData(e.ARRAY_BUFFER,
|
|
252
|
+
const x = this.generateVertices(_, p, b, C);
|
|
253
|
+
this.vertexBuffer = e.createBuffer(), e.bindBuffer(e.ARRAY_BUFFER, this.vertexBuffer), e.bufferData(e.ARRAY_BUFFER, x, e.STATIC_DRAW);
|
|
254
254
|
}
|
|
255
255
|
/**
|
|
256
256
|
* Generate vertex data for the rectangle with texture coordinates
|
|
@@ -341,7 +341,7 @@ class le {
|
|
|
341
341
|
this.vertexBuffer = e.createBuffer(), e.bindBuffer(e.ARRAY_BUFFER, this.vertexBuffer), e.bufferData(e.ARRAY_BUFFER, ie, e.STATIC_DRAW);
|
|
342
342
|
return;
|
|
343
343
|
}
|
|
344
|
-
const _ = d / g, b = -(f / g), C = _,
|
|
344
|
+
const _ = d / g, b = -(f / g), C = _, x = a / 2, w = t + b * x, A = r + C * x, R = t - b * x, S = r - C * x, P = i + b * x, D = s + C * x, Z = i - b * x, W = s - C * x, J = w / l * 2 - 1, K = R / l * 2 - 1, ee = P / l * 2 - 1, te = Z / l * 2 - 1;
|
|
345
345
|
let B, G, V, k;
|
|
346
346
|
u ? (B = A / c * 2 - 1, G = S / c * 2 - 1, V = D / c * 2 - 1, k = W / c * 2 - 1) : (B = 1 - A / c * 2, G = 1 - S / c * 2, V = 1 - D / c * 2, k = 1 - W / c * 2);
|
|
347
347
|
const re = this.generateLineVertices(
|
|
@@ -773,7 +773,7 @@ class fe {
|
|
|
773
773
|
const s = new ce(this.gl, e, t, r, i);
|
|
774
774
|
if (this.currentShader !== null) {
|
|
775
775
|
if (this.currentRotation !== 0) {
|
|
776
|
-
const p = (e + r) / 2, b = (t + i) / 2, C = Math.abs(r - e),
|
|
776
|
+
const p = (e + r) / 2, b = (t + i) / 2, C = Math.abs(r - e), x = Math.abs(i - t), { centerX: w, centerY: A, radians: R, aspectRatio: S } = this.calculateRotationParams(p - C / 2, b - x / 2, C, x);
|
|
777
777
|
this.setUniform("u_rotation", R), this.setUniform("u_center", [w, A]), this.setUniform("u_aspectRatio", S);
|
|
778
778
|
} else
|
|
779
779
|
this.setUniform("u_rotation", 0), this.setUniform("u_center", [0, 0]), this.setUniform("u_aspectRatio", 1);
|
|
@@ -1326,7 +1326,7 @@ class _e {
|
|
|
1326
1326
|
* @returns RGB color as a tuple [r, g, b], or [0, 0, 0] if not found
|
|
1327
1327
|
*/
|
|
1328
1328
|
getCharacterColor(e, t) {
|
|
1329
|
-
if (!
|
|
1329
|
+
if (!v.validate(
|
|
1330
1330
|
typeof e == "string" && e.length === 1,
|
|
1331
1331
|
"Character must be a single character string.",
|
|
1332
1332
|
{ method: "getCharacterColor", providedValue: e }
|
|
@@ -1342,14 +1342,14 @@ class _e {
|
|
|
1342
1342
|
* @returns Array of RGB colors for each character
|
|
1343
1343
|
*/
|
|
1344
1344
|
getCharacterColors(e, t) {
|
|
1345
|
-
return
|
|
1345
|
+
return v.validate(
|
|
1346
1346
|
typeof e == "string" && e.length > 0,
|
|
1347
1347
|
"Characters must be a string with at least one character.",
|
|
1348
1348
|
{ method: "getCharacterColors", providedValue: e }
|
|
1349
1349
|
) ? e.split("").map((r) => this.getCharacterColor(r, t) || [0, 0, 0]) : [[0, 0, 0]];
|
|
1350
1350
|
}
|
|
1351
1351
|
}
|
|
1352
|
-
class
|
|
1352
|
+
class ve {
|
|
1353
1353
|
/**
|
|
1354
1354
|
* Creates a new TextmodeFont instance.
|
|
1355
1355
|
* @param renderer Renderer instance for texture creation
|
|
@@ -1525,7 +1525,7 @@ class xe {
|
|
|
1525
1525
|
return this._font;
|
|
1526
1526
|
}
|
|
1527
1527
|
}
|
|
1528
|
-
class
|
|
1528
|
+
class xe {
|
|
1529
1529
|
/**
|
|
1530
1530
|
* Create a new grid instance.
|
|
1531
1531
|
* @param canvas The canvas element used to determine the grid dimensions.
|
|
@@ -1562,9 +1562,8 @@ class ve {
|
|
|
1562
1562
|
*/
|
|
1563
1563
|
reset() {
|
|
1564
1564
|
if (!this._fixedDimensions) {
|
|
1565
|
-
const e = this._canvas.
|
|
1566
|
-
|
|
1567
|
-
[this._cols, this._rows] = [Math.floor(t / this._cellWidth), Math.floor(r / this._cellHeight)];
|
|
1565
|
+
const e = this._canvas.width, t = this._canvas.height;
|
|
1566
|
+
[this._cols, this._rows] = [Math.floor(e / this._cellWidth), Math.floor(t / this._cellHeight)];
|
|
1568
1567
|
}
|
|
1569
1568
|
this._resizeGrid();
|
|
1570
1569
|
}
|
|
@@ -1572,9 +1571,8 @@ class ve {
|
|
|
1572
1571
|
* Reset the total grid width & height, and the offset to the outer canvas.
|
|
1573
1572
|
*/
|
|
1574
1573
|
_resizeGrid() {
|
|
1575
|
-
const e = this._canvas.
|
|
1576
|
-
|
|
1577
|
-
this._width = this._cols * this._cellWidth, this._height = this._rows * this._cellHeight, this._offsetX = Math.floor((t - this._width) / 2), this._offsetY = Math.floor((r - this._height) / 2);
|
|
1574
|
+
const e = this._canvas.width, t = this._canvas.height;
|
|
1575
|
+
this._width = this._cols * this._cellWidth, this._height = this._rows * this._cellHeight, this._offsetX = Math.floor((e - this._width) / 2), this._offsetY = Math.floor((t - this._height) / 2);
|
|
1578
1576
|
}
|
|
1579
1577
|
/**
|
|
1580
1578
|
* Re-assign the grid cell dimensions and `reset()` the grid.
|
|
@@ -1667,7 +1665,9 @@ class be {
|
|
|
1667
1665
|
o(this, "_canvas");
|
|
1668
1666
|
o(this, "captureSource");
|
|
1669
1667
|
o(this, "_isStandalone");
|
|
1670
|
-
this
|
|
1668
|
+
o(this, "resizeObserver");
|
|
1669
|
+
o(this, "onTransformChange");
|
|
1670
|
+
this.captureSource = e, this._isStandalone = t, this._canvas = this.createCanvas(r.width, r.height), t && this.setupTransformObserver();
|
|
1671
1671
|
}
|
|
1672
1672
|
createCanvas(e, t) {
|
|
1673
1673
|
var i;
|
|
@@ -1727,12 +1727,37 @@ class be {
|
|
|
1727
1727
|
throw new F("WebGL context could not be created. Ensure your browser supports WebGL.");
|
|
1728
1728
|
return t;
|
|
1729
1729
|
}
|
|
1730
|
+
/**
|
|
1731
|
+
* Get the effective rendering dimensions accounting for CSS transforms
|
|
1732
|
+
*/
|
|
1733
|
+
getEffectiveRenderingDimensions() {
|
|
1734
|
+
return this._canvas ? { width: this._canvas.width, height: this._canvas.height } : { width: 0, height: 0 };
|
|
1735
|
+
}
|
|
1736
|
+
/**
|
|
1737
|
+
* Check if the canvas is affected by CSS transforms
|
|
1738
|
+
*/
|
|
1739
|
+
isTransformed() {
|
|
1740
|
+
if (!this._canvas || !this._isStandalone) return !1;
|
|
1741
|
+
const e = this._canvas.getBoundingClientRect(), t = Math.round(e.width), r = Math.round(e.height);
|
|
1742
|
+
return t !== this._canvas.width || r !== this._canvas.height;
|
|
1743
|
+
}
|
|
1744
|
+
/**
|
|
1745
|
+
* Set up ResizeObserver to monitor for CSS transform changes
|
|
1746
|
+
*/
|
|
1747
|
+
setupTransformObserver() {
|
|
1748
|
+
typeof ResizeObserver > "u" || (this.resizeObserver = new ResizeObserver((e) => {
|
|
1749
|
+
for (const t of e) {
|
|
1750
|
+
const r = t.contentRect, i = Math.round(r.width), s = Math.round(r.height);
|
|
1751
|
+
this.onTransformChange && (i !== this._canvas.width || s !== this._canvas.height) && this.onTransformChange();
|
|
1752
|
+
}
|
|
1753
|
+
}), this.resizeObserver.observe(this._canvas));
|
|
1754
|
+
}
|
|
1730
1755
|
/**
|
|
1731
1756
|
* Dispose of this TextmodeCanvas and clean up all resources.
|
|
1732
1757
|
* This method is idempotent and safe to call multiple times.
|
|
1733
1758
|
*/
|
|
1734
1759
|
dispose() {
|
|
1735
|
-
if (this._canvas) {
|
|
1760
|
+
if (this.resizeObserver && (this.resizeObserver.disconnect(), this.resizeObserver = void 0), this._canvas) {
|
|
1736
1761
|
const e = this._canvas.getContext("webgl") || this._canvas.getContext("webgl2");
|
|
1737
1762
|
if (e) {
|
|
1738
1763
|
const t = e.getExtension("WEBGL_lose_context");
|
|
@@ -1886,7 +1911,7 @@ class Ce {
|
|
|
1886
1911
|
return this._framebuffer.texture;
|
|
1887
1912
|
}
|
|
1888
1913
|
}
|
|
1889
|
-
class
|
|
1914
|
+
class O extends U {
|
|
1890
1915
|
constructor(t, r, i, s = {}) {
|
|
1891
1916
|
super(t, r, i, s);
|
|
1892
1917
|
o(this, "palette");
|
|
@@ -1897,7 +1922,7 @@ class H extends U {
|
|
|
1897
1922
|
* @param characters The characters to use for mapping, usually ordered from darkest to brightest.
|
|
1898
1923
|
*/
|
|
1899
1924
|
characters(t) {
|
|
1900
|
-
|
|
1925
|
+
v.validate(
|
|
1901
1926
|
this.fontManager.hasAllCharacters(t),
|
|
1902
1927
|
"One or more characters do not exist in the current font.",
|
|
1903
1928
|
{ method: "characters", providedValue: t }
|
|
@@ -1916,7 +1941,7 @@ class H extends U {
|
|
|
1916
1941
|
if (typeof t == "string") {
|
|
1917
1942
|
const u = this.parseHexColor(t);
|
|
1918
1943
|
if (!u) {
|
|
1919
|
-
|
|
1944
|
+
v.validate(
|
|
1920
1945
|
!1,
|
|
1921
1946
|
"Invalid hex color format. Use '#FF0000', '#F00', 'FF0000', or 'F00'.",
|
|
1922
1947
|
{ method: "characterColor", providedValue: t }
|
|
@@ -1924,7 +1949,7 @@ class H extends U {
|
|
|
1924
1949
|
return;
|
|
1925
1950
|
}
|
|
1926
1951
|
[a, n, l, c] = u;
|
|
1927
|
-
} else if (a = t, n = r !== void 0 ? r : t, l = i !== void 0 ? i : t, c = s, !
|
|
1952
|
+
} else if (a = t, n = r !== void 0 ? r : t, l = i !== void 0 ? i : t, c = s, !v.validate(
|
|
1928
1953
|
[a, n, l, c].every((u) => u >= 0 && u <= 255),
|
|
1929
1954
|
"Character color values must be between 0 and 255",
|
|
1930
1955
|
{ method: "characterColor", providedValues: { r: a, g: n, b: l, a: c } }
|
|
@@ -1939,7 +1964,7 @@ class H extends U {
|
|
|
1939
1964
|
* @param mode The color mode to use for characters.
|
|
1940
1965
|
*/
|
|
1941
1966
|
characterColorMode(t) {
|
|
1942
|
-
|
|
1967
|
+
v.validate(
|
|
1943
1968
|
["sampled", "fixed"].includes(t),
|
|
1944
1969
|
"Invalid character color mode. Must be 'sampled' or 'fixed'.",
|
|
1945
1970
|
{ method: "characterColorMode", providedValue: t }
|
|
@@ -1958,7 +1983,7 @@ class H extends U {
|
|
|
1958
1983
|
if (typeof t == "string") {
|
|
1959
1984
|
const u = this.parseHexColor(t);
|
|
1960
1985
|
if (!u) {
|
|
1961
|
-
|
|
1986
|
+
v.validate(
|
|
1962
1987
|
!1,
|
|
1963
1988
|
"Invalid hex color format. Use '#FF0000', '#F00', 'FF0000', or 'F00'.",
|
|
1964
1989
|
{ method: "cellColor", providedValue: t }
|
|
@@ -1966,7 +1991,7 @@ class H extends U {
|
|
|
1966
1991
|
return;
|
|
1967
1992
|
}
|
|
1968
1993
|
[a, n, l, c] = u;
|
|
1969
|
-
} else if (a = t, n = r !== void 0 ? r : t, l = i !== void 0 ? i : t, c = s, !
|
|
1994
|
+
} else if (a = t, n = r !== void 0 ? r : t, l = i !== void 0 ? i : t, c = s, !v.validate(
|
|
1970
1995
|
[a, n, l, c].every((u) => u >= 0 && u <= 255),
|
|
1971
1996
|
"Cell color values must be between 0 and 255",
|
|
1972
1997
|
{ method: "cellColor", providedValues: { r: a, g: n, b: l, a: c } }
|
|
@@ -1981,7 +2006,7 @@ class H extends U {
|
|
|
1981
2006
|
* @param mode The color mode to use for background cells.
|
|
1982
2007
|
*/
|
|
1983
2008
|
cellColorMode(t) {
|
|
1984
|
-
|
|
2009
|
+
v.validate(
|
|
1985
2010
|
["sampled", "fixed"].includes(t),
|
|
1986
2011
|
"Invalid cell color mode. Must be 'sampled' or 'fixed'.",
|
|
1987
2012
|
{ method: "cellColorMode", providedValue: t }
|
|
@@ -1992,7 +2017,7 @@ class H extends U {
|
|
|
1992
2017
|
* @param invert If `true`, the character color becomes the cell color and vice versa.
|
|
1993
2018
|
*/
|
|
1994
2019
|
invert(t) {
|
|
1995
|
-
|
|
2020
|
+
v.validate(
|
|
1996
2021
|
typeof t == "boolean" || typeof t == "number" && Number.isInteger(t),
|
|
1997
2022
|
"Invert must be a boolean value or an integer (0 for false, any other number for true).",
|
|
1998
2023
|
{ method: "invert", providedValue: t }
|
|
@@ -2003,7 +2028,7 @@ class H extends U {
|
|
|
2003
2028
|
* @param angle The rotation angle in degrees.
|
|
2004
2029
|
*/
|
|
2005
2030
|
rotation(t) {
|
|
2006
|
-
if (!
|
|
2031
|
+
if (!v.validate(
|
|
2007
2032
|
typeof t == "number",
|
|
2008
2033
|
"Rotation angle must be a number.",
|
|
2009
2034
|
{ method: "rotation", providedValue: t }
|
|
@@ -2018,7 +2043,7 @@ class H extends U {
|
|
|
2018
2043
|
* @param flip If `true`, characters are flipped horizontally. If `false`, no flip is applied.
|
|
2019
2044
|
*/
|
|
2020
2045
|
flipHorizontally(t) {
|
|
2021
|
-
|
|
2046
|
+
v.validate(
|
|
2022
2047
|
typeof t == "boolean" || typeof t == "number" && Number.isInteger(t),
|
|
2023
2048
|
"Flip horizontally must be a boolean value or an integer (0 for false, any other number for true).",
|
|
2024
2049
|
{ method: "flipHorizontally", providedValue: t }
|
|
@@ -2029,7 +2054,7 @@ class H extends U {
|
|
|
2029
2054
|
* @param flip If `true`, characters are flipped vertically. If `false`, no flip is applied.
|
|
2030
2055
|
*/
|
|
2031
2056
|
flipVertically(t) {
|
|
2032
|
-
|
|
2057
|
+
v.validate(
|
|
2033
2058
|
typeof t == "boolean" || typeof t == "number" && Number.isInteger(t),
|
|
2034
2059
|
"Flip vertically must be a boolean value or an integer (0 for false, any other number for true).",
|
|
2035
2060
|
{ method: "flipVertically", providedValue: t }
|
|
@@ -2075,7 +2100,7 @@ const Re = {
|
|
|
2075
2100
|
/** Range of brightness values to map to ASCII characters */
|
|
2076
2101
|
brightnessRange: [0, 255]
|
|
2077
2102
|
};
|
|
2078
|
-
class L extends
|
|
2103
|
+
class L extends O {
|
|
2079
2104
|
/**
|
|
2080
2105
|
* Creates a new TextmodeBrightnessConverter instance.
|
|
2081
2106
|
* @param renderer Renderer instance for texture creation
|
|
@@ -2107,18 +2132,18 @@ class L extends H {
|
|
|
2107
2132
|
* @param range Array of two numbers `[min, max]`, where `min` is darkest and `max` is brightest.
|
|
2108
2133
|
*/
|
|
2109
2134
|
brightnessRange(t) {
|
|
2110
|
-
|
|
2135
|
+
v.validate(
|
|
2111
2136
|
Array.isArray(t) && t.length === 2 && t.every((r) => typeof r == "number" && r >= 0 && r <= 255),
|
|
2112
2137
|
"Brightness range must be an array of two numbers between 0 and 255.",
|
|
2113
2138
|
{ method: "brightnessRange", providedValue: t }
|
|
2114
2139
|
) && (this._options.brightnessRange = t);
|
|
2115
2140
|
}
|
|
2116
2141
|
}
|
|
2117
|
-
const
|
|
2142
|
+
const Oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2118
2143
|
__proto__: null,
|
|
2119
2144
|
TextmodeBrightnessConverter: L,
|
|
2120
2145
|
TextmodeConverter: U,
|
|
2121
|
-
TextmodeFeatureConverter:
|
|
2146
|
+
TextmodeFeatureConverter: O
|
|
2122
2147
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
2123
2148
|
var Ee = "precision mediump float;uniform sampler2D u_characterTexture;uniform vec2 u_charsetDimensions;uniform sampler2D u_primaryColorTexture;uniform sampler2D u_secondaryColorTexture;uniform sampler2D u_transformTexture;uniform sampler2D u_asciiCharacterTexture;uniform sampler2D u_rotationTexture;uniform sampler2D u_captureTexture;uniform vec2 u_captureDimensions;uniform int u_backgroundMode;uniform vec2 u_gridCellDimensions;uniform vec2 u_gridPixelDimensions;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){vec2 adjustedCoord=gl_FragCoord.xy/u_gridPixelDimensions;vec2 gridCoord=adjustedCoord*u_gridCellDimensions;vec2 cellCoord=floor(gridCoord);vec2 charIndexTexCoord=(cellCoord+0.5)/u_gridCellDimensions;vec4 primaryColor=texture2D(u_primaryColorTexture,charIndexTexCoord);vec4 secondaryColor=texture2D(u_secondaryColorTexture,charIndexTexCoord);vec4 transformColor=texture2D(u_transformTexture,charIndexTexCoord);bool isInverted=transformColor.r>0.5;bool flipHorizontal=transformColor.g>0.5;bool flipVertical=transformColor.b>0.5;vec4 encodedIndexVec=texture2D(u_asciiCharacterTexture,charIndexTexCoord);if(encodedIndexVec.a<0.01){gl_FragColor=(u_backgroundMode==0)? vec4(0.0):texture2D(u_captureTexture,gl_FragCoord.xy/u_captureDimensions);return;}int charIndex=int(encodedIndexVec.r*255.0+0.5)+int(encodedIndexVec.g*255.0+0.5)*256;int charCol=int(mod(float(charIndex),u_charsetDimensions.x));int charRow=charIndex/int(u_charsetDimensions.x);vec2 charCoord=vec2(charCol,charRow)/u_charsetDimensions;vec4 rotationColor=texture2D(u_rotationTexture,charIndexTexCoord);float scaledAngle=rotationColor.r*255.0+rotationColor.g;float rotationAngle=(scaledAngle*360.0/255.0)*0.017453292;vec2 fractionalPart=fract(gridCoord)-0.5;if(flipHorizontal)fractionalPart.x=-fractionalPart.x;if(flipVertical)fractionalPart.y=-fractionalPart.y;fractionalPart=rotate2D(rotationAngle)*fractionalPart+0.5;vec2 cellSize=1.0/u_charsetDimensions;vec2 texCoord=charCoord+fractionalPart*cellSize;vec2 cellMax=charCoord+cellSize;if(any(lessThan(texCoord,charCoord))||any(greaterThan(texCoord,cellMax))){gl_FragColor=isInverted ? primaryColor : secondaryColor;return;}vec4 charTexel=texture2D(u_characterTexture,texCoord);if(isInverted)charTexel.rgb=1.0-charTexel.rgb;gl_FragColor=mix(secondaryColor,primaryColor,charTexel);}";
|
|
2124
2149
|
class Ue {
|
|
@@ -2154,7 +2179,7 @@ class Ue {
|
|
|
2154
2179
|
render(e) {
|
|
2155
2180
|
for (const r of this.converters) {
|
|
2156
2181
|
const i = r.converter;
|
|
2157
|
-
i.options.enabled && i instanceof
|
|
2182
|
+
i.options.enabled && i instanceof O && i.convert(e);
|
|
2158
2183
|
}
|
|
2159
2184
|
const t = (r, i) => {
|
|
2160
2185
|
r.begin(), this.renderer.clear();
|
|
@@ -2172,14 +2197,14 @@ class Ue {
|
|
|
2172
2197
|
* @returns The requested `TextmodeConverter` instance.
|
|
2173
2198
|
*/
|
|
2174
2199
|
get(e) {
|
|
2175
|
-
if (!
|
|
2200
|
+
if (!v.validate(
|
|
2176
2201
|
typeof e == "string" && e.length > 0,
|
|
2177
2202
|
"Converter name must be a non-empty string.",
|
|
2178
2203
|
{ method: "converter", providedValue: e }
|
|
2179
2204
|
))
|
|
2180
2205
|
return;
|
|
2181
2206
|
const t = this.converters.find((i) => i.name === e), r = t == null ? void 0 : t.converter;
|
|
2182
|
-
if (
|
|
2207
|
+
if (v.validate(
|
|
2183
2208
|
r instanceof U,
|
|
2184
2209
|
`Converter "${e}" is not a valid TextmodeConverter.`,
|
|
2185
2210
|
{ method: "converter", providedValue: e, converterInstance: r }
|
|
@@ -2193,11 +2218,11 @@ class Ue {
|
|
|
2193
2218
|
* @returns The newly created {@link TextmodeConverter} instance or `void` if the addition failed.
|
|
2194
2219
|
*/
|
|
2195
2220
|
add(e, t) {
|
|
2196
|
-
if (!
|
|
2221
|
+
if (!v.validate(
|
|
2197
2222
|
typeof e == "string" && e.length > 0,
|
|
2198
2223
|
"Converter name must be a non-empty string.",
|
|
2199
2224
|
{ method: "add", providedValue: e }
|
|
2200
|
-
) || !
|
|
2225
|
+
) || !v.validate(
|
|
2201
2226
|
t === "brightness" || t === "custom",
|
|
2202
2227
|
`Converter type must be either "brightness" or "custom". Provided: ${t}`,
|
|
2203
2228
|
{ method: "add", providedValue: t }
|
|
@@ -2211,7 +2236,7 @@ class Ue {
|
|
|
2211
2236
|
* @param nameOrInstance The unique name of the converter or the converter instance to remove.
|
|
2212
2237
|
*/
|
|
2213
2238
|
remove(e) {
|
|
2214
|
-
if (!
|
|
2239
|
+
if (!v.validate(
|
|
2215
2240
|
typeof e == "string" || e instanceof U,
|
|
2216
2241
|
"Parameter must be either a string (converter name) or a TextmodeConverter instance.",
|
|
2217
2242
|
{ method: "remove", providedValue: e }
|
|
@@ -2219,7 +2244,7 @@ class Ue {
|
|
|
2219
2244
|
return;
|
|
2220
2245
|
let t = -1;
|
|
2221
2246
|
if (typeof e == "string") {
|
|
2222
|
-
if (!
|
|
2247
|
+
if (!v.validate(
|
|
2223
2248
|
e.length > 0,
|
|
2224
2249
|
"Converter name must be a non-empty string.",
|
|
2225
2250
|
{ method: "remove", providedValue: e }
|
|
@@ -2228,7 +2253,7 @@ class Ue {
|
|
|
2228
2253
|
t = this.converters.findIndex((r) => r.name === e);
|
|
2229
2254
|
} else
|
|
2230
2255
|
t = this.converters.findIndex((r) => r.converter === e);
|
|
2231
|
-
|
|
2256
|
+
v.validate(
|
|
2232
2257
|
t !== -1,
|
|
2233
2258
|
typeof e == "string" ? `Converter with name "${e}" not found in pipeline.` : "Converter instance not found in pipeline.",
|
|
2234
2259
|
{ method: "remove", providedValue: e, convertersCount: this.converters.length }
|
|
@@ -2300,7 +2325,7 @@ class Ue {
|
|
|
2300
2325
|
return this._transformFramebuffer;
|
|
2301
2326
|
}
|
|
2302
2327
|
}
|
|
2303
|
-
class
|
|
2328
|
+
class H {
|
|
2304
2329
|
/**
|
|
2305
2330
|
* Extracts pixel data from all framebuffers needed for export
|
|
2306
2331
|
* @param pipeline The conversion pipeline containing framebuffers
|
|
@@ -2342,7 +2367,7 @@ class X {
|
|
|
2342
2367
|
};
|
|
2343
2368
|
}
|
|
2344
2369
|
}
|
|
2345
|
-
class
|
|
2370
|
+
class X {
|
|
2346
2371
|
/**
|
|
2347
2372
|
* Creates a downloadable blob from content
|
|
2348
2373
|
* @param content The content to include in the blob
|
|
@@ -2399,7 +2424,7 @@ class N {
|
|
|
2399
2424
|
return `'textmode-export'-${this.generateTimestamp()}`;
|
|
2400
2425
|
}
|
|
2401
2426
|
}
|
|
2402
|
-
class Ae extends
|
|
2427
|
+
class Ae extends H {
|
|
2403
2428
|
/**
|
|
2404
2429
|
* Extracts transform data from transform pixels
|
|
2405
2430
|
* @param transformPixels Transform framebuffer pixels
|
|
@@ -2552,17 +2577,17 @@ class Me {
|
|
|
2552
2577
|
let p = u + 1;
|
|
2553
2578
|
for (; p <= f; )
|
|
2554
2579
|
if ((l[p] & 1) !== 0) {
|
|
2555
|
-
const C = t + s[p] * i,
|
|
2556
|
-
c += `L${C.toFixed(2)},${
|
|
2580
|
+
const C = t + s[p] * i, x = r - a[p] * i;
|
|
2581
|
+
c += `L${C.toFixed(2)},${x.toFixed(2)}`, p++;
|
|
2557
2582
|
} else {
|
|
2558
|
-
const C = t + s[p] * i,
|
|
2583
|
+
const C = t + s[p] * i, x = r - a[p] * i;
|
|
2559
2584
|
let w = p + 1 > f ? u : p + 1;
|
|
2560
2585
|
if ((l[w] & 1) !== 0) {
|
|
2561
2586
|
const R = t + s[w] * i, S = r - a[w] * i;
|
|
2562
|
-
c += `Q${C.toFixed(2)},${
|
|
2587
|
+
c += `Q${C.toFixed(2)},${x.toFixed(2)} ${R.toFixed(2)},${S.toFixed(2)}`, p = w + 1;
|
|
2563
2588
|
} else {
|
|
2564
|
-
const R = t + s[w] * i, S = r - a[w] * i, P = (C + R) / 2, D = (
|
|
2565
|
-
c += `Q${C.toFixed(2)},${
|
|
2589
|
+
const R = t + s[w] * i, S = r - a[w] * i, P = (C + R) / 2, D = (x + S) / 2;
|
|
2590
|
+
c += `Q${C.toFixed(2)},${x.toFixed(2)} ${P.toFixed(2)},${D.toFixed(2)}`, p = w;
|
|
2566
2591
|
}
|
|
2567
2592
|
}
|
|
2568
2593
|
c += "Z";
|
|
@@ -2766,7 +2791,7 @@ class De {
|
|
|
2766
2791
|
`).replace(/[ \t]+$/gm, "");
|
|
2767
2792
|
}
|
|
2768
2793
|
}
|
|
2769
|
-
class Ie extends
|
|
2794
|
+
class Ie extends X {
|
|
2770
2795
|
/**
|
|
2771
2796
|
* Creates a downloadable blob from SVG content
|
|
2772
2797
|
* @param svgContent The SVG content string
|
|
@@ -2848,7 +2873,7 @@ class Y {
|
|
|
2848
2873
|
}
|
|
2849
2874
|
}
|
|
2850
2875
|
}
|
|
2851
|
-
class Pe extends
|
|
2876
|
+
class Pe extends H {
|
|
2852
2877
|
/**
|
|
2853
2878
|
* Extracts character data for TXT generation
|
|
2854
2879
|
* @param framebufferData Framebuffer pixel data
|
|
@@ -2894,7 +2919,7 @@ class Be {
|
|
|
2894
2919
|
return r.join(i);
|
|
2895
2920
|
}
|
|
2896
2921
|
}
|
|
2897
|
-
class Ge extends
|
|
2922
|
+
class Ge extends X {
|
|
2898
2923
|
/**
|
|
2899
2924
|
* Saves TXT content as a downloadable file
|
|
2900
2925
|
* @param content The TXT content to save
|
|
@@ -2969,7 +2994,7 @@ class j {
|
|
|
2969
2994
|
}
|
|
2970
2995
|
}
|
|
2971
2996
|
}
|
|
2972
|
-
class Ve extends
|
|
2997
|
+
class Ve extends H {
|
|
2973
2998
|
/**
|
|
2974
2999
|
* Captures the current state of the textmode canvas as image data
|
|
2975
3000
|
* @param canvas The canvas data containing the rendered textmode graphics
|
|
@@ -3047,7 +3072,7 @@ const q = {
|
|
|
3047
3072
|
jpg: ".jpg",
|
|
3048
3073
|
webp: ".webp"
|
|
3049
3074
|
};
|
|
3050
|
-
class ze extends
|
|
3075
|
+
class ze extends X {
|
|
3051
3076
|
/**
|
|
3052
3077
|
* Saves image content as a downloadable file
|
|
3053
3078
|
* @param content The image content (data URL or blob)
|
|
@@ -3245,9 +3270,9 @@ class I {
|
|
|
3245
3270
|
const r = new I(e, t), i = r._standalone ? t : void 0;
|
|
3246
3271
|
r.textmodeCanvas = new be(r.captureSource, r._standalone, i), r._renderer = new fe(r.textmodeCanvas.getWebGLContext());
|
|
3247
3272
|
let s, a;
|
|
3248
|
-
r._standalone ? (s = t.width || 800, a = t.height || 600) : (s = r.textmodeCanvas.width || 800, a = r.textmodeCanvas.height || 600), r._canvasFramebuffer = r._renderer.createFramebuffer(s, a), r._font = new
|
|
3273
|
+
r._standalone ? (s = t.width || 800, a = t.height || 600) : (s = r.textmodeCanvas.width || 800, a = r.textmodeCanvas.height || 600), r._canvasFramebuffer = r._renderer.createFramebuffer(s, a), r._font = new ve(r._renderer, t.fontSize ?? 16), await r._font.initialize(t.fontSource);
|
|
3249
3274
|
const n = r._font.maxGlyphDimensions;
|
|
3250
|
-
return r._grid = new
|
|
3275
|
+
return r._grid = new xe(r.textmodeCanvas.canvas, n.width, n.height), r._pipeline = new Ue(r._renderer, r._font, r._grid), r.setupEventListeners(), r.startAutoRendering(), r;
|
|
3251
3276
|
}
|
|
3252
3277
|
setupEventListeners() {
|
|
3253
3278
|
this._windowResizeListener = () => {
|
|
@@ -3666,7 +3691,7 @@ class I {
|
|
|
3666
3691
|
* ```
|
|
3667
3692
|
*/
|
|
3668
3693
|
redraw(e = 1) {
|
|
3669
|
-
if (
|
|
3694
|
+
if (v.validate(
|
|
3670
3695
|
typeof e == "number" && e > 0 && Number.isInteger(e),
|
|
3671
3696
|
"Redraw count must be a positive integer.",
|
|
3672
3697
|
{ method: "redraw", providedValue: e }
|
|
@@ -3722,7 +3747,7 @@ class I {
|
|
|
3722
3747
|
* ```
|
|
3723
3748
|
*/
|
|
3724
3749
|
fontSize(e) {
|
|
3725
|
-
|
|
3750
|
+
v.validate(
|
|
3726
3751
|
typeof e == "number" && e > 0,
|
|
3727
3752
|
"Font size must be a positive number greater than 0.",
|
|
3728
3753
|
{ method: "fontSize", providedValue: e }
|
|
@@ -4314,7 +4339,7 @@ class I {
|
|
|
4314
4339
|
return this._isDisposed;
|
|
4315
4340
|
}
|
|
4316
4341
|
}
|
|
4317
|
-
class
|
|
4342
|
+
class N {
|
|
4318
4343
|
/**
|
|
4319
4344
|
* Create a {@link Textmodifier} instance for textmode rendering.
|
|
4320
4345
|
*
|
|
@@ -4393,7 +4418,7 @@ class O {
|
|
|
4393
4418
|
* ```
|
|
4394
4419
|
*/
|
|
4395
4420
|
static setErrorLevel(e) {
|
|
4396
|
-
|
|
4421
|
+
v.setGlobalLevel(e);
|
|
4397
4422
|
}
|
|
4398
4423
|
/**
|
|
4399
4424
|
* Returns the current version of the `textmode.js` library.
|
|
@@ -4404,27 +4429,27 @@ class O {
|
|
|
4404
4429
|
* ```
|
|
4405
4430
|
*/
|
|
4406
4431
|
static get version() {
|
|
4407
|
-
return "0.1.6-beta.
|
|
4432
|
+
return "0.1.6-beta.3";
|
|
4408
4433
|
}
|
|
4409
4434
|
constructor() {
|
|
4410
4435
|
throw new Error("Textmode is a static class and cannot be instantiated.");
|
|
4411
4436
|
}
|
|
4412
4437
|
}
|
|
4413
|
-
const
|
|
4438
|
+
const He = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
4414
4439
|
__proto__: null
|
|
4415
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
4440
|
+
}, Symbol.toStringTag, { value: "Module" })), Xe = N.create, Ne = N.setErrorLevel, We = N.version;
|
|
4416
4441
|
export {
|
|
4417
4442
|
be as TextmodeCanvas,
|
|
4418
4443
|
Ue as TextmodeConversionPipeline,
|
|
4419
4444
|
ne as TextmodeErrorLevel,
|
|
4420
|
-
|
|
4421
|
-
|
|
4445
|
+
ve as TextmodeFont,
|
|
4446
|
+
xe as TextmodeGrid,
|
|
4422
4447
|
I as Textmodifier,
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4448
|
+
Oe as converters,
|
|
4449
|
+
Xe as create,
|
|
4450
|
+
N as default,
|
|
4451
|
+
He as export,
|
|
4452
|
+
Ne as setErrorLevel,
|
|
4453
|
+
N as textmode,
|
|
4429
4454
|
We as version
|
|
4430
4455
|
};
|