Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/build-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ jobs:
- name: Install dependencies
run: bun install

- name: Build
- name: Build Core package
run: |
cd packages/core
bun run build

- name: Build 3D package
run: |
cd packages/3d
bun run build

- name: Run tests
run: |
cd packages/core
Expand Down
138 changes: 77 additions & 61 deletions bun.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"packages/*"
],
"scripts": {
"build": "cd packages/core && bun run build && cd ../solid && bun run build && cd ../react && bun run build",
"build": "cd packages/core && bun run build && cd ../3d && bun run build && cd ../solid && bun run build && cd ../react && bun run build",
"build:go": "cd packages/go && go build ./...",
"pre-publish": "bun scripts/pre-publish.ts",
"publish": "bun run pre-publish && bun run publish:core && bun run publish:react && bun run publish:solid",
"publish": "bun run pre-publish && bun run publish:core && bun run publish:3d && bun run publish:react && bun run publish:solid",
"publish:3d": "cd packages/3d && bun run publish",
"publish:core": "cd packages/core && bun run publish",
"publish:react": "cd packages/react && bun run publish",
"publish:solid": "cd packages/solid && bun run publish",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bun

import { createCliRenderer, RGBA, TextRenderable, BoxRenderable, FrameBufferRenderable } from "../index"
import { ThreeCliRenderer } from "../3d/WGPURenderer"
import { TextureUtils } from "../3d/TextureUtils"
import { createCliRenderer, RGBA, TextRenderable, BoxRenderable, FrameBufferRenderable } from "@opentui/core"
import { ThreeCliRenderer, TextureUtils } from "../src"
import type { Mesh, MeshPhongMaterial as MeshPhongMaterialType } from "three"
import {
Scene as ThreeScene,
Mesh as ThreeMesh,
Expand All @@ -26,9 +26,9 @@ import { mkdir } from "node:fs/promises"
type MemorySnapshot = { heapUsed: number; heapTotal: number; arrayBuffers: number }

// @ts-ignore
import cratePath from "../examples/assets/crate.png" with { type: "image/png" }
import cratePath from "@opentui/core/src/examples/assets/crate.png" with { type: "image/png" }
// @ts-ignore
import crateEmissivePath from "../examples/assets/crate_emissive.png" with { type: "image/png" }
import crateEmissivePath from "@opentui/core/src/examples/assets/crate_emissive.png" with { type: "image/png" }

// Setup command line options
const program = new Command()
Expand Down Expand Up @@ -205,7 +205,7 @@ let benchmarkStartTime = 0
let benchmarkActive = true
const results: ScenarioResult[] = []
let currentMemorySnapshots: MemorySnapshot[] = []
let cubeMeshNodes: ThreeMesh[] = []
let cubeMeshNodes: Mesh[] = []
const RADIUS = 1
const MULTIPLE_CUBES_COUNT = 8

Expand All @@ -228,7 +228,7 @@ const singleCubeMaterial = new MeshPhongMaterial({

const cullingCubeMaterial = new MeshPhongMaterial({ color: 0x555555, shininess: 10 })
let texturedMaterial: MeshPhongNodeMaterial | null = null
let multiCubeMaterials: MeshPhongMaterial[] = []
let multiCubeMaterials: MeshPhongMaterialType[] = []
for (let i = 0; i < MULTIPLE_CUBES_COUNT; i++) {
const baseColor = new Color()
const hue = i / MULTIPLE_CUBES_COUNT
Expand Down
41 changes: 41 additions & 0 deletions packages/3d/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@opentui/3d",
"version": "0.1.60",
"description": "3D rendering module for OpenTUI",
"repository": {
"type": "git",
"url": "https://github.com/sst/opentui",
"directory": "packages/3d"
},
"module": "src/index.ts",
"type": "module",
"main": "src/index.ts",
"license": "MIT",
"scripts": {
"build": "bun scripts/build.ts",
"publish": "bun scripts/publish.ts"
},
"devDependencies": {
"@types/bun": "latest",
"@types/three": "0.177.0",
"typescript": "^5"
},
"dependencies": {
"@opentui/core": "workspace:*"
},
"optionalDependencies": {
"@dimforge/rapier2d-simd-compat": "^0.17.3",
"bun-webgpu": "0.1.4",
"planck": "^1.4.2",
"three": "0.177.0"
},
"exports": {
".": {
"types": "./src/index.ts",
"import": "./src/index.ts"
}
},
"engines": {
"bun": ">=1.2.0"
}
}
126 changes: 126 additions & 0 deletions packages/3d/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { spawnSync, type SpawnSyncReturns } from "node:child_process"
import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs"
import { dirname, join, resolve } from "path"
import { fileURLToPath } from "url"
import process from "process"

interface PackageJson {
name: string
version: string
license?: string
repository?: any
description?: string
homepage?: string
author?: string
bugs?: any
keywords?: string[]
module?: string
main?: string
types?: string
type?: string
exports?: any
dependencies?: Record<string, string>
devDependencies?: Record<string, string>
peerDependencies?: Record<string, string>
optionalDependencies?: Record<string, string>
engines?: Record<string, string>
}

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const rootDir = resolve(__dirname, "..")
const projectRootDir = resolve(rootDir, "../..")
const licensePath = join(projectRootDir, "LICENSE")
const packageJson: PackageJson = JSON.parse(readFileSync(join(rootDir, "package.json"), "utf8"))

const args = process.argv.slice(2)
const isCi = args.includes("--ci")

console.log("Building @opentui/3d library...")

const distDir = join(rootDir, "dist")
rmSync(distDir, { recursive: true, force: true })
mkdirSync(distDir, { recursive: true })

if (!packageJson.module) {
console.error("Error: 'module' field not found in package.json")
process.exit(1)
}

console.log("Building main entry point...")
const mainBuildResult = await Bun.build({
entrypoints: [join(rootDir, packageJson.module)],
target: "bun",
outdir: distDir,
packages: "external",
splitting: true,
})

if (!mainBuildResult.success) {
console.error("Build failed:", mainBuildResult.logs)
process.exit(1)
}

console.log("Generating TypeScript declarations...")
const tsconfigBuildPath = join(rootDir, "tsconfig.build.json")
const tscResult: SpawnSyncReturns<Buffer> = spawnSync("bunx", ["tsc", "-p", tsconfigBuildPath], {
cwd: rootDir,
stdio: "inherit",
})

if (tscResult.status !== 0) {
if (isCi) {
console.error("Error: TypeScript declaration generation failed")
process.exit(1)
}
console.warn("Warning: TypeScript declaration generation failed")
} else {
console.log("TypeScript declarations generated")
}

const exports = {
".": {
types: "./src/index.d.ts",
import: "./index.js",
require: "./index.js",
},
}

const processedDependencies = { ...packageJson.dependencies }
if (processedDependencies["@opentui/core"] === "workspace:*") {
processedDependencies["@opentui/core"] = packageJson.version
}

writeFileSync(
join(distDir, "package.json"),
JSON.stringify(
{
name: packageJson.name,
version: packageJson.version,
description: packageJson.description,
repository: packageJson.repository,
module: "index.js",
main: "index.js",
types: "src/index.d.ts",
type: packageJson.type,
license: packageJson.license,
exports,
dependencies: processedDependencies,
optionalDependencies: packageJson.optionalDependencies,
engines: packageJson.engines,
},
null,
2,
),
)

const readmePath = join(rootDir, "README.md")
if (existsSync(readmePath)) {
copyFileSync(readmePath, join(distDir, "README.md"))
}

if (existsSync(licensePath)) {
copyFileSync(licensePath, join(distDir, "LICENSE"))
}

console.log("Library built at:", distDir)
44 changes: 44 additions & 0 deletions packages/3d/scripts/publish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { spawnSync, type SpawnSyncReturns } from "node:child_process"
import { readFileSync } from "node:fs"
import { dirname, join, resolve } from "node:path"
import process from "node:process"
import { fileURLToPath } from "node:url"

interface PackageJson {
name: string
version: string
dependencies?: Record<string, string>
}

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const rootDir = resolve(__dirname, "..")

const packageJson: PackageJson = JSON.parse(readFileSync(join(rootDir, "package.json"), "utf8"))

console.log(`Publishing @opentui/3d@${packageJson.version}...`)
console.log("Make sure you've run the pre-publish validation script first!")

const distDir = join(rootDir, "dist")

console.log(`\nPublishing ${packageJson.name}@${packageJson.version}...`)

const isSnapshot = packageJson.version.includes("-snapshot") || /^0\.0\.0-\d{8}-[a-f0-9]{8}$/.test(packageJson.version)
const publishArgs = ["publish", "--access=public"]

if (isSnapshot) {
publishArgs.push("--tag", "snapshot")
console.log(` Publishing as snapshot (--tag snapshot)`)
}

const publish: SpawnSyncReturns<Buffer> = spawnSync("npm", publishArgs, {
cwd: distDir,
stdio: "inherit",
})

if (publish.status !== 0) {
console.error(`Failed to publish '${packageJson.name}@${packageJson.version}'.`)
process.exit(1)
}

console.log(`Successfully published '${packageJson.name}@${packageJson.version}'`)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { PerspectiveCamera, OrthographicCamera, Color, NoToneMapping, LinearSRGBColorSpace, Scene } from "three"
import { WebGPURenderer } from "three/webgpu"
import type { OptimizedBuffer } from "../buffer"
import { RGBA } from "../lib/RGBA"
import { RGBA, CliRenderEvents, type CliRenderer, type OptimizedBuffer } from "@opentui/core"
import { createWebGPUDevice, setupGlobals } from "bun-webgpu"
import { CLICanvas, SuperSampleAlgorithm } from "./canvas"
import { CliRenderEvents, type CliRenderer } from "../renderer"

export enum SuperSampleType {
NONE = "none",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { GPUCanvasContextMock } from "bun-webgpu"
import { RGBA } from "../lib/RGBA"
import { RGBA, type OptimizedBuffer } from "@opentui/core"
import { SuperSampleType } from "./WGPURenderer"
import type { OptimizedBuffer } from "../buffer"
import { toArrayBuffer } from "bun:ffi"
import { Jimp } from "jimp"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * as THREE from "three"
export * from "./WGPURenderer"
export * from "./TextureUtils"
export * from "./canvas"
Expand Down
21 changes: 21 additions & 0 deletions packages/3d/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "./dist",
"noEmit": false,
"rootDir": ".",
"types": ["bun"],
"skipLibCheck": true,
"moduleResolution": "bundler",
"baseUrl": ".",
"paths": {
"@opentui/core": ["../core/dist"],
"@opentui/core/*": ["../core/dist/*"]
}
},
"include": ["src/**/*"],
"exclude": ["**/*.test.ts", "**/*.spec.ts", "scripts/**/*", "node_modules/**/*", "../core/**/*"]
}
28 changes: 28 additions & 0 deletions packages/3d/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
},
"exclude": ["dist"]
}
10 changes: 1 addition & 9 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
},
"license": "MIT",
"devDependencies": {
"@opentui/3d": "workspace:*",
"@types/bun": "latest",
"@types/node": "^24.0.0",
"@types/three": "0.177.0",
"commander": "^13.1.0",
"typescript": "^5",
"web-tree-sitter": "0.25.10"
Expand All @@ -43,10 +43,6 @@
"web-tree-sitter": "0.25.10"
},
"optionalDependencies": {
"@dimforge/rapier2d-simd-compat": "^0.17.3",
"bun-webgpu": "0.1.4",
"planck": "^1.4.2",
"three": "0.177.0",
"@opentui/core-darwin-x64": "0.1.63",
"@opentui/core-darwin-arm64": "0.1.63",
"@opentui/core-linux-x64": "0.1.63",
Expand All @@ -59,10 +55,6 @@
"types": "./src/index.ts",
"import": "./src/index.ts"
},
"./3d": {
"types": "./src/3d.ts",
"import": "./src/3d.ts"
},
"./testing": {
"types": "./src/testing.ts",
"import": "./src/testing.ts"
Expand Down
Loading
Loading