textmode.js 0.1.4-beta.4 → 0.1.4-beta.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.
package/dist/textmode.esm.js
CHANGED
|
@@ -341,9 +341,9 @@ class gA {
|
|
|
341
341
|
this.vertexBuffer = A.createBuffer(), A.bindBuffer(A.ARRAY_BUFFER, this.vertexBuffer), A.bufferData(A.ARRAY_BUFFER, rA, A.STATIC_DRAW);
|
|
342
342
|
return;
|
|
343
343
|
}
|
|
344
|
-
const d = l / c, m = -(Q / c), D = d, C = s / 2, p = e + m * C, F = t + D * C, v = e - m * C,
|
|
344
|
+
const d = l / c, m = -(Q / c), D = d, C = s / 2, p = e + m * C, F = t + D * C, v = e - m * C, _ = t - D * C, R = r + m * C, T = i + D * C, j = r - m * C, X = i - D * C, Z = p / g * 2 - 1, q = v / g * 2 - 1, AA = R / g * 2 - 1, eA = j / g * 2 - 1;
|
|
345
345
|
let G, M, U, Y;
|
|
346
|
-
E ? (G = F / B * 2 - 1, M =
|
|
346
|
+
E ? (G = F / B * 2 - 1, M = _ / B * 2 - 1, U = T / B * 2 - 1, Y = X / B * 2 - 1) : (G = 1 - F / B * 2, M = 1 - _ / B * 2, U = 1 - T / B * 2, Y = 1 - X / B * 2);
|
|
347
347
|
const tA = this.generateLineVertices(
|
|
348
348
|
Z,
|
|
349
349
|
G,
|
|
@@ -465,7 +465,7 @@ class BA extends K {
|
|
|
465
465
|
new gA(this.gl, this.x, this.y, this.x2, this.y2, e).render();
|
|
466
466
|
}
|
|
467
467
|
}
|
|
468
|
-
class
|
|
468
|
+
class I {
|
|
469
469
|
constructor(A, e, t) {
|
|
470
470
|
a(this, "gl");
|
|
471
471
|
a(this, "program");
|
|
@@ -612,7 +612,7 @@ class w {
|
|
|
612
612
|
this.textureUnitCounter = 0;
|
|
613
613
|
}
|
|
614
614
|
}
|
|
615
|
-
var
|
|
615
|
+
var w = "attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;uniform float u_rotation;uniform vec2 u_center;uniform float u_aspectRatio;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){v_uv=a_texCoord;vec2 pos=a_position;pos-=u_center;pos.x*=u_aspectRatio;pos=rotate2D(-u_rotation)*pos;pos.x/=u_aspectRatio;pos+=u_center;gl_Position=vec4(pos,0.0,1.0);}", EA = "precision lowp float;uniform sampler2D u_texture;varying vec2 v_uv;void main(){gl_FragColor=texture2D(u_texture,v_uv);}", lA = "precision lowp float;uniform vec4 u_color;void main(){gl_FragColor=u_color;}";
|
|
616
616
|
class QA {
|
|
617
617
|
constructor(A) {
|
|
618
618
|
a(this, "gl");
|
|
@@ -631,7 +631,7 @@ class QA {
|
|
|
631
631
|
// in degrees
|
|
632
632
|
// State stack for push/pop functionality
|
|
633
633
|
a(this, "stateStack", []);
|
|
634
|
-
this.gl = A, this.imageShader = new
|
|
634
|
+
this.gl = A, this.imageShader = new I(this.gl, w, EA), this.solidColorShader = new I(this.gl, w, lA), this.gl.enable(this.gl.BLEND), this.gl.blendEquation(this.gl.FUNC_ADD), this.gl.blendFunc(this.gl.ONE, this.gl.ONE_MINUS_SRC_ALPHA);
|
|
635
635
|
}
|
|
636
636
|
/**
|
|
637
637
|
* Set the current shader
|
|
@@ -732,7 +732,10 @@ class QA {
|
|
|
732
732
|
this.currentShader = null, this.stateStack = [], this.currentRotation = 0, this.fillMode = !0, this.strokeMode = !0, this.currentFillColor = [1, 1, 1, 1], this.currentStrokeColor = [0, 0, 0, 1], this.currentStrokeWeight = 1;
|
|
733
733
|
}
|
|
734
734
|
createShader(A, e) {
|
|
735
|
-
return new
|
|
735
|
+
return new I(this.gl, A, e);
|
|
736
|
+
}
|
|
737
|
+
createFilterShader(A) {
|
|
738
|
+
return new I(this.gl, w, A);
|
|
736
739
|
}
|
|
737
740
|
/**
|
|
738
741
|
* Set a uniform value for the current shader
|
|
@@ -770,8 +773,8 @@ class QA {
|
|
|
770
773
|
const i = new BA(this.gl, A, e, t, r);
|
|
771
774
|
if (this.currentShader !== null) {
|
|
772
775
|
if (this.currentRotation !== 0) {
|
|
773
|
-
const u = (A + t) / 2, m = (e + r) / 2, D = Math.abs(t - A), C = Math.abs(r - e), { centerX: p, centerY: F, radians: v, aspectRatio:
|
|
774
|
-
this.setUniform("u_rotation", v), this.setUniform("u_center", [p, F]), this.setUniform("u_aspectRatio",
|
|
776
|
+
const u = (A + t) / 2, m = (e + r) / 2, D = Math.abs(t - A), C = Math.abs(r - e), { centerX: p, centerY: F, radians: v, aspectRatio: _ } = this.calculateRotationParams(u - D / 2, m - C / 2, D, C);
|
|
777
|
+
this.setUniform("u_rotation", v), this.setUniform("u_center", [p, F]), this.setUniform("u_aspectRatio", _);
|
|
775
778
|
} else
|
|
776
779
|
this.setUniform("u_rotation", 0), this.setUniform("u_center", [0, 0]), this.setUniform("u_aspectRatio", 1);
|
|
777
780
|
i.renderStroke(this.currentStrokeWeight), this.currentShader = null;
|
|
@@ -2088,10 +2091,10 @@ class O extends z {
|
|
|
2088
2091
|
a(this, "transformFillShader");
|
|
2089
2092
|
a(this, "rotationFillShader");
|
|
2090
2093
|
a(this, "sampleFramebuffer");
|
|
2091
|
-
this.sampleShader = new
|
|
2094
|
+
this.sampleShader = new I(e.context, w, pA), this.colorFillShader = new I(e.context, w, IA), this.transformFillShader = new I(e.context, w, wA), this.rotationFillShader = new I(e.context, w, _A), this.charMappingShader = new I(e.context, w, vA), this.sampleFramebuffer = this.renderer.createFramebuffer(this.grid.cols, this.grid.rows);
|
|
2092
2095
|
}
|
|
2093
2096
|
convert(e) {
|
|
2094
|
-
this.sampleFramebuffer.begin(), this.renderer.clear(), this.renderer.shader(this.sampleShader), this.renderer.setUniform("u_sketchTexture", e), this.renderer.setUniform("u_gridCellDimensions", [this.grid.cols, this.grid.rows]), this.renderer.setUniform("u_brightnessRange", this._options.brightnessRange), this.renderer.rect(0, 0, this.grid.cols, this.grid.rows), this.sampleFramebuffer.end(), this._primaryColorFramebuffer.begin(), this.renderer.clear(), this.renderer.shader(this.colorFillShader), this.renderer.setUniform("u_sampleTexture", this.sampleFramebuffer.texture), this.renderer.setUniform("u_fillColor", this._options.characterColor), this.renderer.setUniform("u_useFixedColor", this._options.characterColorMode === "fixed"), this.renderer.rect(0, 0, this.grid.cols, this.grid.rows), this._primaryColorFramebuffer.end(), this._secondaryColorFramebuffer.begin(), this.renderer.clear(), this.renderer.shader(this.colorFillShader), this.renderer.setUniform("u_sampleTexture", this.sampleFramebuffer.texture), this.renderer.setUniform("u_fillColor", this._options.cellColor), this.renderer.setUniform("u_useFixedColor", this._options.cellColorMode === "fixed"), this.renderer.rect(0, 0, this.grid.cols, this.grid.rows), this._secondaryColorFramebuffer.end(), this._transformFramebuffer.begin(), this.renderer.clear(), this.renderer.shader(this.transformFillShader), this.renderer.setUniform("u_sampleTexture", this.sampleFramebuffer.texture), this.renderer.setUniform("u_invert", this._options.invert), this.renderer.setUniform("u_flipHorizontally", this._options.flipHorizontally), this.renderer.setUniform("u_flipVertically", this._options.flipVertically), this.renderer.rect(0, 0, this.grid.cols, this.grid.rows), this._transformFramebuffer.end(), this._rotationFramebuffer.begin(), this.renderer.clear(), this.renderer.shader(this.rotationFillShader), this.renderer.setUniform("u_sampleTexture", this.sampleFramebuffer.texture), this.renderer.setUniform("u_rotationColor", this._options.rotation), this.renderer.rect(0, 0, this.grid.cols, this.grid.rows), this._rotationFramebuffer.end(), this._characterFramebuffer.begin(), this.renderer.clear(0, 0, 0, 0), this.renderer.shader(this.charMappingShader), this.renderer.setUniform("u_colorSampleFramebuffer", this.sampleFramebuffer.texture), this.renderer.setUniform("u_charPaletteTexture", this.palette.texture), this.renderer.setUniform("u_charPaletteSize", [this.palette.colors.length, 1]), this.renderer.setUniform("u_brightnessRange", this._options.brightnessRange), this.renderer.rect(0, 0, this.grid.cols, this.grid.rows), this._characterFramebuffer.end();
|
|
2097
|
+
this.sampleFramebuffer.begin(), this.renderer.clear(), this.renderer.shader(this.sampleShader), this.renderer.setUniform("u_sketchTexture", e), this.renderer.setUniform("u_gridCellDimensions", [this.grid.cols, this.grid.rows]), this.renderer.setUniform("u_brightnessRange", this._options.brightnessRange), this.renderer.rect(0, 0, this.grid.cols, this.grid.rows), this.sampleFramebuffer.end(), console.log("this.options.characterColor:", this._options.characterColor), this._primaryColorFramebuffer.begin(), this.renderer.clear(), this.renderer.shader(this.colorFillShader), this.renderer.setUniform("u_sampleTexture", this.sampleFramebuffer.texture), this.renderer.setUniform("u_fillColor", this._options.characterColor), this.renderer.setUniform("u_useFixedColor", this._options.characterColorMode === "fixed"), this.renderer.rect(0, 0, this.grid.cols, this.grid.rows), this._primaryColorFramebuffer.end(), this._secondaryColorFramebuffer.begin(), this.renderer.clear(), this.renderer.shader(this.colorFillShader), this.renderer.setUniform("u_sampleTexture", this.sampleFramebuffer.texture), this.renderer.setUniform("u_fillColor", this._options.cellColor), this.renderer.setUniform("u_useFixedColor", this._options.cellColorMode === "fixed"), this.renderer.rect(0, 0, this.grid.cols, this.grid.rows), this._secondaryColorFramebuffer.end(), this._transformFramebuffer.begin(), this.renderer.clear(), this.renderer.shader(this.transformFillShader), this.renderer.setUniform("u_sampleTexture", this.sampleFramebuffer.texture), this.renderer.setUniform("u_invert", this._options.invert), this.renderer.setUniform("u_flipHorizontally", this._options.flipHorizontally), this.renderer.setUniform("u_flipVertically", this._options.flipVertically), this.renderer.rect(0, 0, this.grid.cols, this.grid.rows), this._transformFramebuffer.end(), this._rotationFramebuffer.begin(), this.renderer.clear(), this.renderer.shader(this.rotationFillShader), this.renderer.setUniform("u_sampleTexture", this.sampleFramebuffer.texture), this.renderer.setUniform("u_rotationColor", this._options.rotation), this.renderer.rect(0, 0, this.grid.cols, this.grid.rows), this._rotationFramebuffer.end(), this._characterFramebuffer.begin(), this.renderer.clear(0, 0, 0, 0), this.renderer.shader(this.charMappingShader), this.renderer.setUniform("u_colorSampleFramebuffer", this.sampleFramebuffer.texture), this.renderer.setUniform("u_charPaletteTexture", this.palette.texture), this.renderer.setUniform("u_charPaletteSize", [this.palette.colors.length, 1]), this.renderer.setUniform("u_brightnessRange", this._options.brightnessRange), this.renderer.rect(0, 0, this.grid.cols, this.grid.rows), this._characterFramebuffer.end();
|
|
2095
2098
|
}
|
|
2096
2099
|
resize() {
|
|
2097
2100
|
super.resize(), this.sampleFramebuffer.resize(this.grid.cols, this.grid.rows);
|
|
@@ -2138,7 +2141,7 @@ class FA {
|
|
|
2138
2141
|
a(this, "_secondaryColorFramebuffer");
|
|
2139
2142
|
a(this, "_rotationFramebuffer");
|
|
2140
2143
|
a(this, "_transformFramebuffer");
|
|
2141
|
-
this.renderer = A, this.font = e, this.grid = t, this._asciiShader = this.renderer.createShader(
|
|
2144
|
+
this.renderer = A, this.font = e, this.grid = t, this._asciiShader = this.renderer.createShader(w, bA), this.converters = [
|
|
2142
2145
|
{ name: "brightness", converter: new O(A, e, t) },
|
|
2143
2146
|
{ name: "custom", converter: new b(A, e, t) }
|
|
2144
2147
|
], this._characterFramebuffer = this.renderer.createFramebuffer(t.cols, t.rows), this._primaryColorFramebuffer = this.renderer.createFramebuffer(t.cols, t.rows), this._secondaryColorFramebuffer = this.renderer.createFramebuffer(t.cols, t.rows), this._rotationFramebuffer = this.renderer.createFramebuffer(t.cols, t.rows), this._transformFramebuffer = this.renderer.createFramebuffer(t.cols, t.rows), this._resultFramebuffer = this.renderer.createFramebuffer(this.grid.width, this.grid.height);
|
|
@@ -2555,10 +2558,10 @@ class TA {
|
|
|
2555
2558
|
const D = e + i[u] * r, C = t - s[u] * r;
|
|
2556
2559
|
let p = u + 1 > Q ? E : u + 1;
|
|
2557
2560
|
if ((g[p] & 1) !== 0) {
|
|
2558
|
-
const v = e + i[p] * r,
|
|
2559
|
-
B += `Q${D.toFixed(2)},${C.toFixed(2)} ${v.toFixed(2)},${
|
|
2561
|
+
const v = e + i[p] * r, _ = t - s[p] * r;
|
|
2562
|
+
B += `Q${D.toFixed(2)},${C.toFixed(2)} ${v.toFixed(2)},${_.toFixed(2)}`, u = p + 1;
|
|
2560
2563
|
} else {
|
|
2561
|
-
const v = e + i[p] * r,
|
|
2564
|
+
const v = e + i[p] * r, _ = t - s[p] * r, R = (D + v) / 2, T = (C + _) / 2;
|
|
2562
2565
|
B += `Q${D.toFixed(2)},${C.toFixed(2)} ${R.toFixed(2)},${T.toFixed(2)}`, u = p;
|
|
2563
2566
|
}
|
|
2564
2567
|
}
|
|
@@ -4172,6 +4175,14 @@ class S {
|
|
|
4172
4175
|
createShader(A, e) {
|
|
4173
4176
|
return this._renderer.createShader(A, e);
|
|
4174
4177
|
}
|
|
4178
|
+
/**
|
|
4179
|
+
* Create a filter shader program from a fragment source code.
|
|
4180
|
+
* @param fragmentSource The GLSL source code for the fragment shader.
|
|
4181
|
+
* @returns The created filter shader program for use in `textmode.js`.
|
|
4182
|
+
*/
|
|
4183
|
+
createFilterShader(A) {
|
|
4184
|
+
return this._renderer.createFilterShader(A);
|
|
4185
|
+
}
|
|
4175
4186
|
/**
|
|
4176
4187
|
* Set the current shader for rendering.
|
|
4177
4188
|
* @param shader The shader program to use for rendering.
|
|
@@ -4345,7 +4356,7 @@ class N {
|
|
|
4345
4356
|
* ```
|
|
4346
4357
|
*/
|
|
4347
4358
|
static get version() {
|
|
4348
|
-
return "0.1.4-beta.
|
|
4359
|
+
return "0.1.4-beta.5";
|
|
4349
4360
|
}
|
|
4350
4361
|
constructor() {
|
|
4351
4362
|
throw new Error("Textmode is a static class and cannot be instantiated.");
|