@opentui/core 0.1.75 → 0.1.77

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.
@@ -0,0 +1,40 @@
1
+ import { OrthographicCamera, PerspectiveCamera, Scene } from "three";
2
+ import { OptimizedBuffer } from "../buffer";
3
+ import { Renderable, type RenderableOptions } from "../Renderable";
4
+ import type { RenderContext } from "../types";
5
+ import { ThreeCliRenderer, type ThreeCliRendererOptions } from "./WGPURenderer";
6
+ export interface ThreeRenderableOptions extends RenderableOptions<ThreeRenderable> {
7
+ scene?: Scene | null;
8
+ camera?: PerspectiveCamera | OrthographicCamera;
9
+ renderer?: Omit<ThreeCliRendererOptions, "width" | "height" | "autoResize">;
10
+ autoAspect?: boolean;
11
+ }
12
+ export declare class ThreeRenderable extends Renderable {
13
+ private engine;
14
+ private scene;
15
+ private autoAspect;
16
+ private initPromise;
17
+ private initFailed;
18
+ private drawInFlight;
19
+ private frameCallback;
20
+ private frameCallbackRegistered;
21
+ private cliRenderer;
22
+ private clearColor;
23
+ constructor(ctx: RenderContext, options: ThreeRenderableOptions);
24
+ get aspectRatio(): number;
25
+ get renderer(): ThreeCliRenderer;
26
+ getScene(): Scene | null;
27
+ setScene(scene: Scene | null): void;
28
+ getActiveCamera(): PerspectiveCamera | OrthographicCamera;
29
+ setActiveCamera(camera: PerspectiveCamera | OrthographicCamera): void;
30
+ setAutoAspect(autoAspect: boolean): void;
31
+ protected onResize(width: number, height: number): void;
32
+ protected renderSelf(buffer: OptimizedBuffer, deltaTime: number): void;
33
+ protected destroySelf(): void;
34
+ private registerFrameCallback;
35
+ private renderToBuffer;
36
+ private ensureInitialized;
37
+ private updateCameraAspect;
38
+ private getAspectRatio;
39
+ private getRenderSize;
40
+ }
package/3d/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./WGPURenderer";
2
+ export * from "./ThreeRenderable";
2
3
  export * from "./TextureUtils";
3
4
  export * from "./canvas";
4
5
  export * from "./SpriteUtils";
package/3d.js CHANGED
@@ -1,11 +1,12 @@
1
1
  // @bun
2
2
  import {
3
3
  RGBA,
4
+ Renderable,
4
5
  __commonJS,
5
6
  __export,
6
7
  __require,
7
8
  __toESM
8
- } from "./index-s0q9547t.js";
9
+ } from "./index-h3dbfsf6.js";
9
10
 
10
11
  // ../../node_modules/.bun/omggif@1.0.10/node_modules/omggif/omggif.js
11
12
  var require_omggif = __commonJS((exports) => {
@@ -32013,6 +32014,167 @@ class ThreeCliRenderer {
32013
32014
  this.renderMethod = () => Promise.resolve();
32014
32015
  }
32015
32016
  }
32017
+ // src/3d/ThreeRenderable.ts
32018
+ import { PerspectiveCamera as PerspectiveCamera2 } from "three";
32019
+ class ThreeRenderable extends Renderable {
32020
+ engine;
32021
+ scene;
32022
+ autoAspect;
32023
+ initPromise = null;
32024
+ initFailed = false;
32025
+ drawInFlight = false;
32026
+ frameCallback = null;
32027
+ frameCallbackRegistered = false;
32028
+ cliRenderer;
32029
+ clearColor;
32030
+ constructor(ctx, options) {
32031
+ const { scene = null, camera, renderer, autoAspect = true, ...renderableOptions } = options;
32032
+ super(ctx, { ...renderableOptions, buffered: true, live: options.live ?? true });
32033
+ const cliRenderer = ctx;
32034
+ if (typeof cliRenderer.setFrameCallback !== "function" || typeof cliRenderer.removeFrameCallback !== "function") {
32035
+ throw new Error("ThreeRenderable requires a CliRenderer context");
32036
+ }
32037
+ this.cliRenderer = cliRenderer;
32038
+ this.scene = scene;
32039
+ this.autoAspect = autoAspect;
32040
+ this.clearColor = renderer?.backgroundColor ?? RGBA.fromValues(0, 0, 0, 1);
32041
+ const { width, height } = this.getRenderSize();
32042
+ this.engine = new ThreeCliRenderer(cliRenderer, {
32043
+ width,
32044
+ height,
32045
+ autoResize: false,
32046
+ ...renderer
32047
+ });
32048
+ if (camera) {
32049
+ this.engine.setActiveCamera(camera);
32050
+ }
32051
+ this.updateCameraAspect(width, height);
32052
+ this.registerFrameCallback();
32053
+ }
32054
+ get aspectRatio() {
32055
+ return this.getAspectRatio(this.width, this.height);
32056
+ }
32057
+ get renderer() {
32058
+ return this.engine;
32059
+ }
32060
+ getScene() {
32061
+ return this.scene;
32062
+ }
32063
+ setScene(scene) {
32064
+ this.scene = scene;
32065
+ this.requestRender();
32066
+ }
32067
+ getActiveCamera() {
32068
+ return this.engine.getActiveCamera();
32069
+ }
32070
+ setActiveCamera(camera) {
32071
+ this.engine.setActiveCamera(camera);
32072
+ this.updateCameraAspect(this.width, this.height);
32073
+ this.requestRender();
32074
+ }
32075
+ setAutoAspect(autoAspect) {
32076
+ if (this.autoAspect === autoAspect)
32077
+ return;
32078
+ this.autoAspect = autoAspect;
32079
+ if (autoAspect) {
32080
+ this.updateCameraAspect(this.width, this.height);
32081
+ }
32082
+ }
32083
+ onResize(width, height) {
32084
+ if (width > 0 && height > 0) {
32085
+ this.engine.setSize(width, height, true);
32086
+ this.updateCameraAspect(width, height);
32087
+ }
32088
+ super.onResize(width, height);
32089
+ }
32090
+ renderSelf(buffer, deltaTime) {
32091
+ if (!this.visible || this.isDestroyed)
32092
+ return;
32093
+ if (this.frameCallbackRegistered)
32094
+ return;
32095
+ if (this.buffered && !this.frameBuffer)
32096
+ return;
32097
+ this.renderToBuffer(buffer, deltaTime / 1000);
32098
+ }
32099
+ destroySelf() {
32100
+ if (this.frameCallback && this.frameCallbackRegistered) {
32101
+ this.cliRenderer.removeFrameCallback(this.frameCallback);
32102
+ this.frameCallbackRegistered = false;
32103
+ this.frameCallback = null;
32104
+ }
32105
+ this.engine.destroy();
32106
+ super.destroySelf();
32107
+ }
32108
+ registerFrameCallback() {
32109
+ if (this.frameCallbackRegistered)
32110
+ return;
32111
+ this.frameCallback = async (deltaTime) => {
32112
+ if (this.isDestroyed || !this.visible || !this.parent)
32113
+ return;
32114
+ if (!this.scene || !this.frameBuffer)
32115
+ return;
32116
+ await this.renderToBuffer(this.frameBuffer, deltaTime / 1000);
32117
+ };
32118
+ this.cliRenderer.setFrameCallback(this.frameCallback);
32119
+ this.frameCallbackRegistered = true;
32120
+ }
32121
+ async renderToBuffer(buffer, deltaTime) {
32122
+ if (!this.scene || this.isDestroyed || this.drawInFlight)
32123
+ return;
32124
+ this.drawInFlight = true;
32125
+ try {
32126
+ const initialized = await this.ensureInitialized();
32127
+ if (!initialized || !this.scene)
32128
+ return;
32129
+ if (buffer === this.frameBuffer) {
32130
+ buffer.clear(this.clearColor);
32131
+ }
32132
+ await this.engine.drawScene(this.scene, buffer, deltaTime);
32133
+ } finally {
32134
+ this.drawInFlight = false;
32135
+ }
32136
+ }
32137
+ async ensureInitialized() {
32138
+ if (this.initFailed)
32139
+ return false;
32140
+ if (!this.initPromise) {
32141
+ this.initPromise = this.engine.init().then(() => true).catch((error) => {
32142
+ this.initFailed = true;
32143
+ console.error("ThreeRenderable init failed:", error);
32144
+ return false;
32145
+ });
32146
+ }
32147
+ return this.initPromise;
32148
+ }
32149
+ updateCameraAspect(width, height) {
32150
+ if (!this.autoAspect || width <= 0 || height <= 0)
32151
+ return;
32152
+ const camera = this.engine.getActiveCamera();
32153
+ if (camera instanceof PerspectiveCamera2) {
32154
+ camera.aspect = this.getAspectRatio(width, height);
32155
+ camera.updateProjectionMatrix();
32156
+ }
32157
+ }
32158
+ getAspectRatio(width, height) {
32159
+ if (width <= 0 || height <= 0)
32160
+ return 1;
32161
+ const resolution = this.cliRenderer.resolution;
32162
+ if (resolution && this.cliRenderer.terminalWidth > 0 && this.cliRenderer.terminalHeight > 0) {
32163
+ const cellWidth = resolution.width / this.cliRenderer.terminalWidth;
32164
+ const cellHeight = resolution.height / this.cliRenderer.terminalHeight;
32165
+ if (cellHeight > 0) {
32166
+ return width * cellWidth / (height * cellHeight);
32167
+ }
32168
+ }
32169
+ return width / (height * 2);
32170
+ }
32171
+ getRenderSize() {
32172
+ return {
32173
+ width: Math.max(1, this.width),
32174
+ height: Math.max(1, this.height)
32175
+ };
32176
+ }
32177
+ }
32016
32178
  // src/3d/TextureUtils.ts
32017
32179
  import { Color as Color2, DataTexture, NearestFilter, ClampToEdgeWrapping, RGBAFormat, UnsignedByteType } from "three";
32018
32180
  class TextureUtils {
@@ -33848,6 +34010,7 @@ class SpriteResourceManager {
33848
34010
  import * as THREE6 from "three";
33849
34011
  export {
33850
34012
  TiledSprite,
34013
+ ThreeRenderable,
33851
34014
  ThreeCliRenderer,
33852
34015
  TextureUtils,
33853
34016
  THREE6 as THREE,
@@ -33874,5 +34037,5 @@ export {
33874
34037
  CLICanvas
33875
34038
  };
33876
34039
 
33877
- //# debugId=D1F311FB11168D3664756E2164756E21
34040
+ //# debugId=A658FFDC4E7D1D3B64756E2164756E21
33878
34041
  //# sourceMappingURL=3d.js.map