Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use vite and vitest #236

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 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
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"extends": ["eslint:recommended", "plugin:react/recommended", "plugin:@typescript-eslint/recommended", "prettier"],
"env": {
"browser": true,
"es6": true,
"mocha": true
"es6": true
},
"plugins": ["@typescript-eslint", "react"],
"rules": {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ jobs:
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./volumeviewer
publish_dir: ./public/volumeviewer
tag_name: ${{ steps.prepare_tag.outputs.deploy_tag_name }}
tag_message: "Deployment to gh-pages to test new viewer ${{ steps.prepare_tag.outputs.tag_name }}"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ lib
es
build
demo
public/dist
public/demo
public/volumeviewer

19,109 changes: 11,078 additions & 8,031 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
"build-docs": "node node_modules/documentation/bin/documentation.js build src/Histogram.ts src/View3d.ts src/Volume.ts src/VolumeMaker.ts src/VolumeLoader.ts -f html -o docs --shallow",
"build": "npm run transpileES && npm run build-types",
"build-types": "tsc -p tsconfig.types.json",
"build-demo": "webpack --config webpack.demo.js",
"build-demo": "vite build public/ --config vite.config.ts --outDir ./demo",
"clean": "rimraf es/",
"format": "prettier --write src/**/*.js",
"gh-build": "webpack --config webpack.dev.js",
"dev": "webpack serve --config webpack.dev.js",
"start": "webpack serve --config webpack.dev.js",
"format": "prettier --write src/**/*.ts",
"gh-build": "vite build public/ --config vite.config.ts --outDir ./volumeviewer",
"dev": "vite serve",
"start": "vite serve",
"react-example": "webpack serve --config react-example/webpack.react.js",
"lint": "eslint --config ./.eslintrc.json --ignore-path ./.eslintignore --ext .jsx --ext .js --ext .ts ./src",
"test": "cross-env NODE_OPTIONS=\"--loader ts-node/esm\" mocha --require ts-node/register --es-module-specifier-resolution=node src/**/test/*.[jt]s",
"transpileES": "babel src --out-dir es --extensions .js,.ts --ignore **/*.test.js",
"test": "vitest run",
"transpileES": "babel src --out-dir es --extensions .js,.ts --ignore **/*.test.ts",
"typeCheck": "tsc -p tsconfig.json --noEmit"
},
"author": "Daniel Toloudis",
Expand All @@ -50,16 +50,13 @@
"@babel/preset-typescript": "^7.24.7",
"@babel/register": "^7.24.6",
"@tweakpane/core": "^1.1.9",
"@types/chai": "^4.3.12",
"@types/mocha": "^9.1.1",
"@types/three": "^0.144.0",
"@typescript-eslint/eslint-plugin": "^5.30.5",
"@typescript-eslint/parser": "^5.30.5",
"acorn": "^8.7.0",
"babel-loader": "^8.2.2",
"babel-plugin-inline-import": "^3.0.0",
"babel-plugin-inline-import-data-uri": "^1.0.1",
"chai": "^5.1.0",
"clean-webpack-plugin": "^4.0.0-alpha.0",
"copy-webpack-plugin": "^9.0.1",
"cross-env": "^7.0.3",
Expand All @@ -70,9 +67,9 @@
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.3.2",
"husky": "^7.0.1",
"jsdom": "^25.0.1",
"lil-gui": "^0.19.2",
"lint-staged": "^13.2.1",
"mocha": "^10.3.0",
"prettier": "^2.3.2",
"raw-loader": "^4.0.2",
"react": "^16.14.0",
Expand All @@ -81,6 +78,8 @@
"ts-node": "^10.9.2",
"typescript": "^4.3.5",
"url-loader": "^4.1.1",
"vite": "^6.0.6",
"vitest": "^2.1.8",
"webpack": "^5.69.1",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.4"
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@
<input id="gammaMax" type="number" min="0" max="255" step="1" value="255"/>
</p>
</body>
<script type="module" src="index.ts"> </script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<script type="module" src="index.ts"> </script>
<script type="module" src="index.ts"></script>


</html>
6 changes: 3 additions & 3 deletions src/FusedChannelData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import {

import Channel from "./Channel.js";
import { renderToBufferVertShader } from "./constants/basicShaders.js";
import fuseShaderSrcUI from "./constants/shaders/fuseUI.frag";
import fuseShaderSrcF from "./constants/shaders/fuseF.frag";
import fuseShaderSrcI from "./constants/shaders/fuseI.frag";
import fuseShaderSrcUI from "./constants/shaders/fuseUI.frag?raw";
import fuseShaderSrcF from "./constants/shaders/fuseF.frag?raw";
import fuseShaderSrcI from "./constants/shaders/fuseI.frag?raw";
import type { FuseChannel, NumberType } from "./types.js";

// This is the owner of the fused RGBA volume texture atlas, and the mask texture atlas.
Expand Down
2 changes: 1 addition & 1 deletion src/constants/denoiseShader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Vector2 } from "three";

import denoiseFragmentShader from "./shaders/pathtrace_denoise.frag";
import denoiseFragmentShader from "./shaders/pathtrace_denoise.frag?raw";
export const denoiseFragmentShaderSrc = denoiseFragmentShader;

const DENOISE_WINDOW_RADIUS = 3;
Expand Down
2 changes: 1 addition & 1 deletion src/constants/pathtraceOutputShader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pathtraceOutputFragmentShader from "./shaders/pathtrace_output.frag";
import pathtraceOutputFragmentShader from "./shaders/pathtrace_output.frag?raw";
export const pathtraceOutputFragmentShaderSrc = pathtraceOutputFragmentShader;

export const pathtraceOutputShaderUniforms = () => ({
Expand Down
2 changes: 1 addition & 1 deletion src/constants/volumePTshader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Texture, Vector2, Vector3, Vector4 } from "three";
import { Light, AREA_LIGHT, SKY_LIGHT } from "../Light.js";
import pathTraceFragmentShader from "./shaders/pathtrace.frag";
import pathTraceFragmentShader from "./shaders/pathtrace.frag?raw";

export const pathTracingFragmentShaderSrc = pathTraceFragmentShader;

Expand Down
4 changes: 2 additions & 2 deletions src/constants/volumeRayMarchShader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Vector2, Vector3, Matrix4, Texture } from "three";
import rayMarchVertexShader from "./shaders/raymarch.vert";
import rayMarchFragmentShader from "./shaders/raymarch.frag";
import rayMarchVertexShader from "./shaders/raymarch.vert?raw";
import rayMarchFragmentShader from "./shaders/raymarch.frag?raw";

export const rayMarchingVertexShaderSrc = rayMarchVertexShader;
export const rayMarchingFragmentShaderSrc = rayMarchFragmentShader;
Expand Down
4 changes: 2 additions & 2 deletions src/constants/volumeSliceShader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sliceVertexShader from "./shaders/slice.vert";
import sliceFragShader from "./shaders/slice.frag";
import sliceVertexShader from "./shaders/slice.vert?raw";
import sliceFragShader from "./shaders/slice.frag?raw";
import { Vector2, Vector3, Matrix4, Texture } from "three";

export const sliceVertexShaderSrc = sliceVertexShader;
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/TiffLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class TiffLoader extends ThreadableVolumeLoader {
url: this.url,
};

const worker = new Worker(new URL("../workers/FetchTiffWorker", import.meta.url));
const worker = new Worker(new URL("../workers/FetchTiffWorker", import.meta.url), {type: "module"});
worker.onmessage = (e: MessageEvent<TiffLoadResult | { isError: true; error: ErrorObject }>) => {
if (e.data.isError) {
reject(deserializeError(e.data.error));
Expand Down
22 changes: 10 additions & 12 deletions src/test/ChunkPrefetchIterator.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { expect } from "chai";

import { TCZYX } from "../loaders/zarr_utils/types";
import ChunkPrefetchIterator from "../loaders/zarr_utils/ChunkPrefetchIterator";
import { PrefetchDirection } from "../loaders/zarr_utils/types";
Expand Down Expand Up @@ -34,13 +32,13 @@ function validate(iter: ChunkPrefetchIterator, expected: number[][]) {
}

describe("ChunkPrefetchIterator", () => {
it("iterates outward in TZYX order, negative then positive", () => {
test("iterates outward in TZYX order, negative then positive", () => {
// 3x3x3x3, with one chunk in the center
const iterator = new ChunkPrefetchIterator([[1, 0, 1, 1, 1]], [1, 1, 1, 1], [[3, 1, 3, 3, 3]]);
validate(iterator, EXPECTED_3X3X3X3);
});

it("finds the borders of a set of multiple chunks and iterates outward from them", () => {
test("finds the borders of a set of multiple chunks and iterates outward from them", () => {
// 4x4x4, with a 2x2x2 set of chunks in the center
const fetchedChunks: TCZYX<number>[] = [
[1, 0, 1, 1, 1],
Expand All @@ -67,7 +65,7 @@ describe("ChunkPrefetchIterator", () => {
validate(iterator, expected);
});

it("iterates through the same offset in all dimensions before increasing the offset", () => {
test("iterates through the same offset in all dimensions before increasing the offset", () => {
// 5x5x5, with one chunk in the center
const iterator = new ChunkPrefetchIterator([[2, 0, 2, 2, 2]], [2, 2, 2, 2], [[5, 1, 5, 5, 5]]);

Expand All @@ -80,19 +78,19 @@ describe("ChunkPrefetchIterator", () => {
validate(iterator, expected);
});

it("stops at the max offset in each dimension", () => {
test("stops at the max offset in each dimension", () => {
// 5x5x5, with one chunk in the center
const iterator = new ChunkPrefetchIterator([[2, 0, 2, 2, 2]], [1, 1, 1, 1], [[5, 1, 5, 5, 5]]);
validate(iterator, EXPECTED_5X5X5X5_1); // never reaches offset = 2, as it does above
});

it("stops at the borders of the zarr", () => {
test("stops at the borders of the zarr", () => {
// 3x3x3x3, with one chunk in the center
const iterator = new ChunkPrefetchIterator([[1, 0, 1, 1, 1]], [2, 2, 2, 2], [[3, 1, 3, 3, 3]]);
validate(iterator, EXPECTED_3X3X3X3);
});

it("does not iterate in dimensions which are entirely covered by the fetched set", () => {
test("does not iterate in dimensions which are entirely covered by the fetched set", () => {
// 3x3x3x3, with a 1x1x3x3 slice covering all of x and y
const fetchedChunks: TCZYX<number>[] = [
[1, 0, 1, 0, 0], // 0, 0
Expand All @@ -117,7 +115,7 @@ describe("ChunkPrefetchIterator", () => {
validate(iterator, expected);
});

it("does not iterate in dimensions where the max offset is 0", () => {
test("does not iterate in dimensions where the max offset is 0", () => {
// 3x3x3x3, with one chunk in the center
const iterator = new ChunkPrefetchIterator([[1, 0, 1, 1, 1]], [1, 0, 1, 0], [[3, 1, 3, 3, 3]]);

Expand All @@ -132,7 +130,7 @@ describe("ChunkPrefetchIterator", () => {
validate(iterator, expected);
});

it("yields chunks in all prioritized directions first", () => {
test("yields chunks in all prioritized directions first", () => {
// 5x5x5, with one chunk in the center
const iterator = new ChunkPrefetchIterator(
[[2, 0, 2, 2, 2]],
Expand All @@ -152,7 +150,7 @@ describe("ChunkPrefetchIterator", () => {
validate(iterator, expected);
});

it("continues iterating in other dimensions when some reach their limits", () => {
test("continues iterating in other dimensions when some reach their limits", () => {
// final boss: 4x4x6 volume with off-center fetched set
// t has a max offset of 2, but is already at its maximum of 2 and never iterates in positive direction
// z has a max offset of 2, but stops early in negative direction at 0
Expand Down Expand Up @@ -187,7 +185,7 @@ describe("ChunkPrefetchIterator", () => {
validate(iterator, expected);
});

it("correctly handles sources with differing chunk dimensions", () => {
test("correctly handles sources with differing chunk dimensions", () => {
const allChannels = (x: number, y: number, ch = [0, 1, 2, 3]): TCZYX<number>[] => ch.map((c) => [0, c, 0, y, x]);
const iterator = new ChunkPrefetchIterator(
allChannels(1, 2),
Expand Down
Loading
Loading