textmode.js 0.3.2-beta.3 → 0.4.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.
@@ -2566,57 +2566,53 @@ class Qt {
2566
2566
  h(this, "rh", /* @__PURE__ */ new Map());
2567
2567
  this.th = t;
2568
2568
  }
2569
- async installMany(t) {
2570
- for (const e of t) await this.use(e);
2571
- }
2572
- async use(t) {
2573
- if (this.sh.has(t.name)) return void console.warn(`[textmode.js] Plugin "${t.name}" is already installed.`);
2574
- const e = this.nh(t.name);
2575
- try {
2576
- await t.install(this.th, e);
2577
- } catch (i) {
2578
- throw this.oh(t.name), i;
2569
+ async nh(t) {
2570
+ for (const e of t) {
2571
+ if (this.sh.has(e.name)) return void console.warn(`[textmode.js] Plugin "${e.name}" is already installed.`);
2572
+ const i = this.oh(e.name);
2573
+ try {
2574
+ await e.install(this.th, i);
2575
+ } catch (s) {
2576
+ throw this.hh(e.name), s;
2577
+ }
2578
+ this.sh.set(e.name, e), this.eh.push(e.name);
2579
2579
  }
2580
- this.sh.set(t.name, t), this.eh.push(t.name);
2581
2580
  }
2582
- async unuse(t) {
2581
+ async ah(t) {
2583
2582
  const e = this.sh.get(t);
2584
2583
  if (!e) return;
2585
- const i = this.nh(t);
2584
+ const i = this.oh(t);
2586
2585
  if (e.uninstall) try {
2587
2586
  await e.uninstall(this.th, i);
2588
2587
  } catch (s) {
2589
2588
  console.error(`[textmode.js] Error while uninstalling plugin "${t}":`, s);
2590
2589
  }
2591
- this.sh.delete(t), this.eh.splice(this.eh.indexOf(t), 1), this.oh(t);
2592
- }
2593
- has(t) {
2594
- return this.sh.has(t);
2590
+ this.sh.delete(t), this.eh.splice(this.eh.indexOf(t), 1), this.hh(t);
2595
2591
  }
2596
2592
  runPreDrawHooks() {
2597
- this.hh(this.ih, "preDraw");
2593
+ this.uh(this.ih, "preDraw");
2598
2594
  }
2599
2595
  runPostDrawHooks() {
2600
- this.hh(this.rh, "postDraw");
2596
+ this.uh(this.rh, "postDraw");
2601
2597
  }
2602
- async disposeAll() {
2598
+ async fh() {
2603
2599
  const t = [...this.sh.keys()];
2604
- for (const e of t) await this.unuse(e);
2600
+ for (const e of t) await this.ah(e);
2605
2601
  }
2606
- nh(t) {
2607
- return { ...this.th.ah(), registerPreDrawHook: (e) => this.uh(this.ih, t, e), registerPostDrawHook: (e) => this.uh(this.rh, t, e) };
2602
+ oh(t) {
2603
+ return { ...this.th.dh(), registerPreDrawHook: (e) => this._h(this.ih, t, e), registerPostDrawHook: (e) => this._h(this.rh, t, e) };
2608
2604
  }
2609
- uh(t, e, i) {
2605
+ _h(t, e, i) {
2610
2606
  const s = t.get(e) ?? /* @__PURE__ */ new Set();
2611
2607
  return s.add(i), t.set(e, s), () => {
2612
2608
  const r = t.get(e);
2613
2609
  r && (r.delete(i), r.size === 0 && t.delete(e));
2614
2610
  };
2615
2611
  }
2616
- oh(t) {
2612
+ hh(t) {
2617
2613
  this.ih.delete(t), this.rh.delete(t);
2618
2614
  }
2619
- hh(t, e) {
2615
+ uh(t, e) {
2620
2616
  for (const i of this.eh) {
2621
2617
  const s = t.get(i);
2622
2618
  if (s) for (const r of s) try {
@@ -2637,11 +2633,11 @@ class te {
2637
2633
  h(this, "In");
2638
2634
  h(this, "Jo");
2639
2635
  h(this, "Qo");
2640
- h(this, "fh");
2641
- h(this, "Vo");
2642
- h(this, "dh");
2643
- h(this, "_h");
2644
2636
  h(this, "ph");
2637
+ h(this, "Vo");
2638
+ h(this, "mh");
2639
+ h(this, "gh");
2640
+ h(this, "yh");
2645
2641
  }
2646
2642
  Zo() {
2647
2643
  }
@@ -2650,78 +2646,66 @@ class ee extends function(e, ...i) {
2650
2646
  return i.reduce((s, r) => r(s), e);
2651
2647
  }(te, $t, Kt, qt, jt, Jt, Zt) {
2652
2648
  constructor(e = {}) {
2653
- var i;
2654
2649
  super();
2655
- h(this, "mh");
2656
- h(this, "gh");
2657
- h(this, "yh", !1);
2658
- h(this, "Ch", !1);
2659
- h(this, "wh", () => {
2660
- });
2650
+ h(this, "Ch");
2651
+ h(this, "wh", !1);
2661
2652
  h(this, "bh", () => {
2662
2653
  });
2663
2654
  h(this, "$h", () => {
2664
2655
  });
2665
- h(this, "xh");
2656
+ h(this, "xh", () => {
2657
+ });
2658
+ h(this, "Mh");
2666
2659
  h(this, "lr");
2667
2660
  h(this, "cr", !1);
2668
- h(this, "Mh");
2669
- this.mh = new Qt(this), this.gh = ((i = e.plugins) == null ? void 0 : i.slice()) ?? [], this.cr = e.overlay ?? !1, this.er = new Wt(e), this.xt = new _t(this.er.gr()), this.ki = new Nt(this.xt, e.fontSize ?? 16), this.qo = new Xt(e.frameRate ?? 60), this.In = new rt(this.er), this.Jo = new ot(this.er, this.In), this.Qo = new nt(), this.fh = this.xt.At(), this.dh = this.xt.rs(), this.Rh(e);
2661
+ h(this, "Rh");
2662
+ this.Ch = new Qt(this), this.cr = e.overlay ?? !1, this.er = new Wt(e), this.xt = new _t(this.er.gr()), this.ki = new Nt(this.xt, e.fontSize ?? 16), this.qo = new Xt(e.frameRate ?? 60), this.In = new rt(this.er), this.Jo = new ot(this.er, this.In), this.Qo = new nt(), this.ph = this.xt.At(), this.mh = this.xt.rs(), this.Fh(e);
2670
2663
  }
2671
- async Rh(e) {
2664
+ async Fh(e) {
2672
2665
  await this.ki.Ni(e.fontSource);
2673
2666
  const i = this.ki.maxGlyphDimensions;
2674
- this.Gr = new zt(this.er.canvas, i.width, i.height), this.In.Ni(this.Gr), this.Jo.Ni(this.Gr), this.Vo = this.xt.Ye(this.Gr.cols, this.Gr.rows, 5), this._h = this.xt.Ye(this.Gr.width, this.Gr.height, 1), this.cr && (this.Mh = N.Fr(this.xt, this.er.targetCanvas, (s) => this.ki.zi(s))), this.ph = this.xt.cs(st, "precision mediump float;uniform sampler2D Ua;uniform vec2 Ub;uniform vec2 Uc;uniform vec2 Ud;void main(){vec2 A=gl_FragCoord.xy-Uc;vec2 B=A*(Ub/Ud);vec2 C=(floor(B)+0.5)/Ub;gl_FragColor=texture2D(Ua,C);}"), this.Fh(), await this.mh.installMany(this.gh), this.gh = [], this.yh = !0, this.wh(), this.qo.start(() => this.Zo());
2675
- }
2676
- async use(e) {
2677
- return this.yh ? await this.mh.use(e) : this.gh.push(e), this;
2667
+ this.Gr = new zt(this.er.canvas, i.width, i.height), this.In.Ni(this.Gr), this.Jo.Ni(this.Gr), this.Vo = this.xt.Ye(this.Gr.cols, this.Gr.rows, 5), this.gh = this.xt.Ye(this.Gr.width, this.Gr.height, 1), this.cr && (this.Rh = N.Fr(this.xt, this.er.targetCanvas, (s) => this.ki.zi(s))), this.yh = this.xt.cs(st, "precision mediump float;uniform sampler2D Ua;uniform vec2 Ub;uniform vec2 Uc;uniform vec2 Ud;void main(){vec2 A=gl_FragCoord.xy-Uc;vec2 B=A*(Ub/Ud);vec2 C=(floor(B)+0.5)/Ub;gl_FragColor=texture2D(Ua,C);}"), this.Sh(), await this.Ch.nh(e.plugins ?? []), this.bh(), this.qo.start(() => this.Zo());
2678
2668
  }
2679
- async unuse(e) {
2680
- return this.yh ? (await this.mh.unuse(e), this) : (this.gh = this.gh.filter((i) => i.name !== e), this);
2681
- }
2682
- hasPlugin(e) {
2683
- return this.yh ? this.mh.has(e) : this.gh.some((i) => i.name === e);
2684
- }
2685
- ah() {
2686
- return { renderer: this.xt, font: this.ki, grid: this.Gr, canvas: this.er, drawFramebuffer: this.Vo, asciiFramebuffer: this._h, flushDrawCommands: () => {
2687
- this.xt.zt(this.fh);
2669
+ dh() {
2670
+ return { renderer: this.xt, font: this.ki, grid: this.Gr, canvas: this.er, drawFramebuffer: this.Vo, asciiFramebuffer: this.gh, flushDrawCommands: () => {
2671
+ this.xt.zt(this.ph);
2688
2672
  } };
2689
2673
  }
2690
- Fh() {
2691
- this.xh = () => {
2692
- this.cr && this.resizeCanvas(this.er.targetCanvas.width, this.er.targetCanvas.height), this.$h();
2693
- }, window.addEventListener("resize", this.xh), this.In.an(), this.Jo.an(), this.Qo.an(), window.addEventListener("blur", () => {
2674
+ Sh() {
2675
+ this.Mh = () => {
2676
+ this.cr && this.resizeCanvas(this.er.targetCanvas.width, this.er.targetCanvas.height), this.xh();
2677
+ }, window.addEventListener("resize", this.Mh), this.In.an(), this.Jo.an(), this.Qo.an(), window.addEventListener("blur", () => {
2694
2678
  this.Qo.Gn();
2695
2679
  }), window.ResizeObserver && this.cr && (this.lr = new ResizeObserver(() => {
2696
2680
  this.resizeCanvas(this.er.targetCanvas.width, this.er.targetCanvas.height);
2697
2681
  }), this.lr.observe(this.er.targetCanvas));
2698
2682
  }
2699
2683
  Zo() {
2700
- if (this.qo.measureFrameRate(), this.qo.incrementFrame(), this.Ch) return;
2684
+ if (this.qo.measureFrameRate(), this.qo.incrementFrame(), this.wh) return;
2701
2685
  if (this.cr) {
2702
2686
  const i = this.xt.context;
2703
- i.bindTexture(i.TEXTURE_2D, this.Mh.texture), i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL, 1), i.texImage2D(i.TEXTURE_2D, 0, i.RGBA, i.RGBA, i.UNSIGNED_BYTE, this.er.targetCanvas), i.bindTexture(i.TEXTURE_2D, null);
2687
+ i.bindTexture(i.TEXTURE_2D, this.Rh.texture), i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL, 1), i.texImage2D(i.TEXTURE_2D, 0, i.RGBA, i.RGBA, i.UNSIGNED_BYTE, this.er.targetCanvas), i.bindTexture(i.TEXTURE_2D, null);
2704
2688
  }
2705
- this.mh.runPreDrawHooks(), this.Vo.begin(), this.xt.Le(this.fh), this.bh(), this.xt.zt(this.fh), this.Vo.end(), this._h.begin(), this.xt.Le(this.dh), this.dh.Xt({ U0: this.ki.fontFramebuffer, U1: [this.ki.textureColumns, this.ki.textureRows], U2: this.Vo.textures[0], U3: this.Vo.textures[1], U4: this.Vo.textures[2], U5: this.Vo.textures[4], U6: this.Vo.textures[3], U7: [this.Gr.cols, this.Gr.rows], U8: [this._h.width, this._h.height], U9: this._h.width / this._h.height }), this.xt.We(0, 0, this.er.width, this.er.height), this._h.end();
2689
+ this.Ch.runPreDrawHooks(), this.Vo.begin(), this.xt.Le(this.ph), this.$h(), this.xt.zt(this.ph), this.Vo.end(), this.gh.begin(), this.xt.Le(this.mh), this.mh.Xt({ U0: this.ki.fontFramebuffer, U1: [this.ki.textureColumns, this.ki.textureRows], U2: this.Vo.textures[0], U3: this.Vo.textures[1], U4: this.Vo.textures[2], U5: this.Vo.textures[4], U6: this.Vo.textures[3], U7: [this.Gr.cols, this.Gr.rows], U8: [this.gh.width, this.gh.height], U9: this.gh.width / this.gh.height }), this.xt.We(0, 0, this.er.width, this.er.height), this.gh.end();
2706
2690
  const e = this.xt.state.canvasBackgroundColor;
2707
- this.xt.Ys(e[0], e[1], e[2], e[3]), this.xt.Le(this.ph), this.ph.Xt({ Ua: this._h.textures[0], Ub: [this._h.width, this._h.height], Uc: [this.Gr.offsetX, this.Gr.offsetY], Ud: [this.Gr.width, this.Gr.height] }), this.xt.We(this.Gr.offsetX, this.Gr.offsetY, this.Gr.width, this.Gr.height), this.mh.runPostDrawHooks();
2691
+ this.xt.Ys(e[0], e[1], e[2], e[3]), this.xt.Le(this.yh), this.yh.Xt({ Ua: this.gh.textures[0], Ub: [this.gh.width, this.gh.height], Uc: [this.Gr.offsetX, this.Gr.offsetY], Ud: [this.Gr.width, this.Gr.height] }), this.xt.We(this.Gr.offsetX, this.Gr.offsetY, this.Gr.width, this.Gr.height), this.Ch.runPostDrawHooks();
2708
2692
  }
2709
2693
  setup(e) {
2710
- this.wh = e;
2694
+ this.bh = e;
2711
2695
  }
2712
2696
  draw(e) {
2713
- this.bh = e;
2697
+ this.$h = e;
2714
2698
  }
2715
2699
  windowResized(e) {
2716
- this.$h = e;
2700
+ this.xh = e;
2717
2701
  }
2718
2702
  resizeCanvas(e, i) {
2719
- this.er.vr(e, i), this.Gr.nr(), this.Vo.resize(this.Gr.cols, this.Gr.rows), this._h.resize(this.Gr.width, this.Gr.height), this.xt.Ze(), this.In.hn(), this.Jo.wo(), this.Zo();
2703
+ this.er.vr(e, i), this.Gr.nr(), this.Vo.resize(this.Gr.cols, this.Gr.rows), this.gh.resize(this.Gr.width, this.Gr.height), this.xt.Ze(), this.In.hn(), this.Jo.wo(), this.Zo();
2720
2704
  }
2721
2705
  destroy() {
2722
- this.Ch || (this.qo.stop(), this.mh.disposeAll().catch((e) => {
2706
+ this.wh || (this.qo.stop(), this.Ch.fh().catch((e) => {
2723
2707
  console.error("[textmode.js] Error while disposing plugins:", e);
2724
- }), window.removeEventListener("resize", this.xh), this.In.pn(), this.Jo.pn(), this.Qo.pn(), this.ki.Pt(), this.xt.Pt(), this._h.Pt(), this.ph.Pt(), this.Mh && this.Mh.Pt(), this.Ch = !0);
2708
+ }), window.removeEventListener("resize", this.Mh), this.In.pn(), this.Jo.pn(), this.Qo.pn(), this.ki.Pt(), this.xt.Pt(), this.gh.Pt(), this.yh.Pt(), this.Rh && this.Rh.Pt(), this.wh = !0);
2725
2709
  }
2726
2710
  get grid() {
2727
2711
  return this.Gr;
@@ -2742,10 +2726,10 @@ class ee extends function(e, ...i) {
2742
2726
  return this.Vo;
2743
2727
  }
2744
2728
  get isDisposed() {
2745
- return this.Ch;
2729
+ return this.wh;
2746
2730
  }
2747
2731
  get overlay() {
2748
- return this.Mh;
2732
+ return this.Rh;
2749
2733
  }
2750
2734
  }
2751
2735
  class J {
@@ -2758,12 +2742,11 @@ class J {
2758
2742
  k.C(t);
2759
2743
  }
2760
2744
  static get version() {
2761
- return "0.3.2-beta.3";
2745
+ return "0.4.0";
2762
2746
  }
2763
2747
  }
2764
- const se = Object.freeze(Object.defineProperty({ __proto__: null }, Symbol.toStringTag, { value: "Module" })), re = Object.freeze(Object.defineProperty({ __proto__: null, keyboard: Ht, mouse: Yt, touch: Vt }, Symbol.toStringTag, { value: "Module" })), ne = J.create, oe = J.setErrorLevel, he = J.version;
2748
+ const se = Object.freeze(Object.defineProperty({ __proto__: null, keyboard: Ht, mouse: Yt, touch: Vt }, Symbol.toStringTag, { value: "Module" })), re = J.create, ne = J.setErrorLevel, oe = J.version;
2765
2749
  export {
2766
- Qt as PluginManager,
2767
2750
  Wt as TextmodeCanvas,
2768
2751
  ct as TextmodeErrorLevel,
2769
2752
  Nt as TextmodeFont,
@@ -2771,10 +2754,9 @@ export {
2771
2754
  zt as TextmodeGrid,
2772
2755
  N as TextmodeImage,
2773
2756
  ee as Textmodifier,
2774
- ne as create,
2775
- se as export,
2776
- re as input,
2777
- oe as setErrorLevel,
2757
+ re as create,
2758
+ se as input,
2759
+ ne as setErrorLevel,
2778
2760
  J as textmode,
2779
- he as version
2761
+ oe as version
2780
2762
  };