Skip to content

Commit

Permalink
chore: Replace prettier with biome (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt authored Jul 21, 2024
1 parent 7c9bda1 commit 04b4a11
Show file tree
Hide file tree
Showing 34 changed files with 611 additions and 516 deletions.
34 changes: 34 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
"organizeImports": {
"enabled": true
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 120
},
"linter": {
"enabled": false,
"rules": {
"recommended": true,
"style": {
"useConst": "off",
"noParameterAssign": "off"
},
"suspicious": {
"noShadowRestrictedNames": "off"
}
}
},
"files": {
"ignore": ["python"]
},
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
}
}
22 changes: 11 additions & 11 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import * as vizarr from './src/index';
import debounce from 'just-debounce-it';
import debounce from "just-debounce-it";
import * as vizarr from "./src/index";

function initStandaloneApp(viewer: vizarr.VizarrViewer) {
const url = new URL(window.location.href);

if (!url.searchParams.has('source')) {
if (!url.searchParams.has("source")) {
return;
}

// see if we have initial viewState
if (url.searchParams.has('viewState')) {
const viewState = JSON.parse(url.searchParams.get('viewState')!);
if (url.searchParams.has("viewState")) {
const viewState = JSON.parse(url.searchParams.get("viewState")!);
viewer.setViewState(viewState);
}

// Add event listener to sync viewState as query param.
// Debounce to limit how quickly we are pushing to browser history
viewer.on(
'viewStateChange',
"viewStateChange",
debounce((update: vizarr.ViewState) => {
const url = new URL(window.location.href);
url.searchParams.set('viewState', JSON.stringify(update));
window.history.pushState({}, '', decodeURIComponent(url.href));
}, 200)
url.searchParams.set("viewState", JSON.stringify(update));
window.history.pushState({}, "", decodeURIComponent(url.href));
}, 200),
);

// parse image config
Expand All @@ -39,13 +39,13 @@ function initStandaloneApp(viewer: vizarr.VizarrViewer) {

// Only update history if the new loacation is different from the current
if (window.location.href !== newLocation) {
window.history.pushState(null, '', newLocation);
window.history.pushState(null, "", newLocation);
}
}

async function main() {
console.log(`vizarr v${vizarr.version}: https://github.com/hms-dbmi/vizarr`);
const viewer = await vizarr.createViewer(document.querySelector('#root')!);
const viewer = await vizarr.createViewer(document.querySelector("#root")!);
initStandaloneApp(viewer);
}

Expand Down
16 changes: 4 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"build": "npm run check && vite build",
"preview": "vite preview",
"export": "npm run check && npm run build",
"format": "prettier --write \"{src,types}/**/*.{js,jsx,ts,tsx}\" vite.config.js main.ts",
"lint": "prettier --check \"{src,types}/**/*.{js,jsx,ts,tsx}\" vite.config.js main.ts",
"lint": "biome ci",
"fix": "biome check --write",
"check": "tsc"
},
"dependencies": {
"@hms-dbmi/viv": "^0.16.0",
"@hms-dbmi/vizarr": "link:",
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"@material-ui/styles": "^4.11.5",
Expand All @@ -29,19 +27,13 @@
"react-dom": "^18.2.0",
"zarrita": "^0.4.0-next.14"
},
"prettier": {
"trailingComma": "es5",
"printWidth": 120,
"semi": true,
"singleQuote": true
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@danmarshall/deckgl-typings": "^4.3.10",
"@types/node": "^20.14.11",
"@types/react": "^18.2.51",
"@types/react-dom": "^18.2.18",
"@vitejs/plugin-react": "^4.3.1",
"prettier": "^3.3.3",
"typescript": "^5.5.3",
"vite": "^5.3.3"
},
Expand Down
104 changes: 91 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 13 additions & 16 deletions src/ZarrPixelSource.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import * as zarr from 'zarrita';
import * as zarr from "zarrita";

import type * as viv from '@vivjs/types';
import type { Readable } from '@zarrita/storage';
import type * as viv from "@vivjs/types";
import type { Readable } from "@zarrita/storage";

import { assert } from './utils';
import { getImageSize } from '@hms-dbmi/viv';
import { getImageSize } from "@hms-dbmi/viv";
import { assert } from "./utils";

// TODO: Export from top-level zarrita
type Slice = ReturnType<typeof zarr.slice>;

const X_AXIS_NAME = 'x';
const Y_AXIS_NAME = 'y';
const RGBA_CHANNEL_AXIS_NAME = '_c';
const SUPPORTED_DTYPES = ['Uint8', 'Uint16', 'Uint32', 'Float32', 'Int8', 'Int16', 'Int32', 'Float64'] as const;
const X_AXIS_NAME = "x";
const Y_AXIS_NAME = "y";
const RGBA_CHANNEL_AXIS_NAME = "_c";
const SUPPORTED_DTYPES = ["Uint8", "Uint16", "Uint32", "Float32", "Int8", "Int16", "Int32", "Float64"] as const;

export class ZarrPixelSource<S extends Array<string> = Array<string>> implements viv.PixelSource<S> {
#arr: zarr.Array<zarr.DataType, Readable>;
Expand All @@ -25,7 +25,7 @@ export class ZarrPixelSource<S extends Array<string> = Array<string>> implements
options: {
labels: viv.Labels<S>;
tileSize: number;
}
},
) {
this.#arr = arr;
this.labels = options.labels;
Expand Down Expand Up @@ -64,10 +64,10 @@ export class ZarrPixelSource<S extends Array<string> = Array<string>> implements
// a BoundsCheckError which is picked up in `ZarrPixelSource.onTileError`
// and ignored by deck.gl.
if (xStart === xStop || yStart === yStop) {
throw new BoundsCheckError('Tile slice is zero-sized.');
throw new BoundsCheckError("Tile slice is zero-sized.");
}
if (xStart < 0 || yStart < 0 || xStop > width || yStop > height) {
throw new BoundsCheckError('Tile slice is out of bounds.');
throw new BoundsCheckError("Tile slice is out of bounds.");
}

sel[this.labels.indexOf(X_AXIS_NAME)] = zarr.slice(xStart, xStop);
Expand Down Expand Up @@ -126,8 +126,5 @@ function isSupportedDtype(dtype: string): dtype is viv.SupportedDtype {
}

class BoundsCheckError extends Error {
name = 'BoundsCheckError';
constructor(message?: string) {
super(message);
}
name = "BoundsCheckError";
}
8 changes: 4 additions & 4 deletions src/codecs/jpeg2k.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
// `deno bundle` since the pdf.js dist does not include ESM source code (only UMD or CJS).

// @ts-ignore
import { JpxImage } from 'https://cdn.jsdelivr.net/gh/mozilla/pdf.js@30bd5f0/src/core/jpx.js';
import { JpxImage } from "https://cdn.jsdelivr.net/gh/mozilla/pdf.js@30bd5f0/src/core/jpx.js";

export default class Jpeg2k {
kind = 'bytes_to_bytes' as const;
static codecId = 'jpeg2k';
kind = "bytes_to_bytes" as const;
static codecId = "jpeg2k";
static fromConfig(): Jpeg2k {
return new Jpeg2k();
}
encode(_: Uint8Array): never {
throw new Error('encode not implemented');
throw new Error("encode not implemented");
}
async decode(data: Uint8Array): Promise<Uint8Array> {
const img = new JpxImage();
Expand Down
4 changes: 2 additions & 2 deletions src/codecs/register.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { registry } from 'zarrita';
registry.set('jpeg2k', () => import('./jpeg2k').then((m) => m.default));
import { registry } from "zarrita";
registry.set("jpeg2k", () => import("./jpeg2k").then((m) => m.default));
Loading

0 comments on commit 04b4a11

Please sign in to comment.