Skip to content

Commit

Permalink
fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
SlicedSilver committed May 2, 2024
1 parent bf4b57d commit 337849e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 32 deletions.
9 changes: 5 additions & 4 deletions examples/offscreen/bouncing-ball-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ export class BouncingBallModel {
y: 5,
};

// eslint-disable-next-line max-params
public constructor(
canvas: Canvas,
color: string,
size: Size,
mediaSize: Size
mediaSize: Size,
) {
this._canvas = canvas;
this._color = color;
Expand All @@ -40,7 +41,7 @@ export class BouncingBallModel {
public updateSize(
size: Size,
mediaSize: Size,
isOffscreen?: boolean
isOffscreen?: boolean,
): void {
this._size = size;
this._mediaSize = mediaSize;
Expand Down Expand Up @@ -68,14 +69,14 @@ export class BouncingBallModel {
this._velocity.x *= -1;
newPos.x = Math.min(
Math.max(10, newPos.x),
this._mediaSize.width - 10
this._mediaSize.width - 10,
);
}
if (newPos.y <= 10 || newPos.y >= this._mediaSize.height - 10) {
this._velocity.y *= -1;
newPos.y = Math.min(
Math.max(10, newPos.y),
this._mediaSize.height - 10
this._mediaSize.height - 10,
);
}
const target = createCanvasRenderingTarget2D({
Expand Down
6 changes: 3 additions & 3 deletions examples/offscreen/bouncing-ball-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ export class BouncingBallRenderer {
0,
0,
scope.mediaSize.width,
scope.mediaSize.height
scope.mediaSize.height,
);
scope.context.beginPath();
scope.context.arc(
this._position?.x ?? 0,
this._position?.y ?? 0,
10,
0,
2 * Math.PI
2 * Math.PI,
);
scope.context.fillStyle = this._color;
scope.context.fill();
}
},
);
}
}
22 changes: 12 additions & 10 deletions examples/offscreen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ class BouncingBall<T extends boolean> {
private _model: BouncingBallModel | undefined = undefined;
private _workerThread: Worker | undefined;

// eslint-disable-next-line max-params
public constructor(
container: HTMLCanvasElement,
color: string,
offscreen: T,
worker: boolean
worker: boolean,
) {
this._canvasHTMLElement = container;
this._color = color;
Expand All @@ -48,7 +49,8 @@ class BouncingBall<T extends boolean> {
for (const entry of entries) {
const { width } = entry.contentRect;
this._binding.resizeCanvasElement({
height: 150, // fixed height
// fixed height
height: 150,
width,
});
}
Expand Down Expand Up @@ -84,15 +86,15 @@ class BouncingBall<T extends boolean> {
this._binding.canvas,
this._color,
this._binding.bitmapSize,
this._binding.canvasElementClientSize
this._binding.canvasElementClientSize,
);
this._binding.subscribeBitmapSizeChanged(
(_oldSize: Size, newSize: Size) => {
this._model?.updateSize(
newSize,
this._binding.canvasElementClientSize
this._binding.canvasElementClientSize,
);
}
},
);
}

Expand All @@ -111,7 +113,7 @@ class BouncingBall<T extends boolean> {
this._binding.canvasElementClientSize,
} satisfies CreateWorkerMessageData,
},
[offscreenCanvas]
[offscreenCanvas],
);
}
}
Expand All @@ -131,13 +133,13 @@ class BouncingBall<T extends boolean> {
}

const disabledCanvas = document.querySelector<HTMLCanvasElement>(
'#offscreen-canvas-disabled'
'#offscreen-canvas-disabled',
);
const mainCanvas = document.querySelector<HTMLCanvasElement>(
'#offscreen-canvas-main'
'#offscreen-canvas-main',
);
const workerCanvas = document.querySelector<HTMLCanvasElement>(
'#offscreen-canvas-worker'
'#offscreen-canvas-worker',
);
const startButton = document.querySelector<HTMLButtonElement>('#start-button');
const pauseButton = document.querySelector<HTMLButtonElement>('#pause-button');
Expand All @@ -155,7 +157,7 @@ if (
disabledCanvas,
'#F23645',
false,
false
false,
);
const mainBall = new BouncingBall(mainCanvas, '#2962ff', true, false);
const workerBall = new BouncingBall(workerCanvas, '#089981', true, true);
Expand Down
31 changes: 16 additions & 15 deletions examples/offscreen/worker-thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ export class WorkerHandler {
const { type, data } = e.data;

switch (type) {
case 'create-canvas':
this._create(data);
break;
case 'adjust-canvas-size':
this._adjustSize(data);
break;
case 'start':
this._start();
break;
case 'pause':
this._pause();
break;
default:
console.warn(`Unknown message type: ${type}`);
case 'create-canvas':
this._create(data);
break;
case 'adjust-canvas-size':
this._adjustSize(data);
break;
case 'start':
this._start();
break;
case 'pause':
this._pause();
break;
default:
console.warn(`Unknown message type: ${type}`);
}
}

Expand All @@ -34,7 +34,7 @@ export class WorkerHandler {
data.canvas,
data.color,
data.bitmapSize,
data.canvasElementClientSize
data.canvasElementClientSize,
);
self.postMessage('created');
}
Expand Down Expand Up @@ -65,4 +65,5 @@ export interface AdjustCanvasSizeMessage {
}

// self-start
// eslint-disable-next-line no-new
new WorkerHandler();
1 change: 1 addition & 0 deletions src/canvas-element-bitmap-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class DevicePixelContentBoxBinding<OffscreenAllowed extends boolean> implements
private _offscreenCanvasSize: Size | null = null;
private _setOffscreenCanvasSize: SetOffscreenBitmapSize | null = null;

// eslint-disable-next-line max-params
public constructor(
canvasElement: HTMLCanvasElement,
transformBitmapSize?: BitmapSizeTransformer,
Expand Down

0 comments on commit 337849e

Please sign in to comment.