Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.6.1-beta01</Version>
<Version>9.6.1-beta02</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions src/BootstrapBlazor/wwwroot/modules/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,16 @@ export function setMemorialMode(memorial) {
}
}

export function drawImage(canvas, image, offsetWidth, offsetHeight) {
canvas.width = offsetWidth * devicePixelRatio;
canvas.height = offsetHeight * devicePixelRatio;
canvas.style.width = `${offsetWidth}px`;
canvas.style.height = `${offsetHeight}px`;
const context = canvas.getContext('2d');
Copy link

Copilot AI May 2, 2025

Choose a reason for hiding this comment

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

Consider verifying that canvas.getContext('2d') returns a valid context object before applying transformations and drawing the image.

Suggested change
const context = canvas.getContext('2d');
const context = canvas.getContext('2d');
if (!context) {
console.error("Failed to get 2D context from canvas.");
return;
}

Copilot uses AI. Check for mistakes.
context.scale(devicePixelRatio, devicePixelRatio);
Comment on lines +880 to +885
Copy link

Copilot AI May 2, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider assigning window.devicePixelRatio to a local variable if used multiple times for improved clarity and potential performance benefits.

Suggested change
canvas.width = offsetWidth * devicePixelRatio;
canvas.height = offsetHeight * devicePixelRatio;
canvas.style.width = `${offsetWidth}px`;
canvas.style.height = `${offsetHeight}px`;
const context = canvas.getContext('2d');
context.scale(devicePixelRatio, devicePixelRatio);
const pixelRatio = window.devicePixelRatio;
canvas.width = offsetWidth * pixelRatio;
canvas.height = offsetHeight * pixelRatio;
canvas.style.width = `${offsetWidth}px`;
canvas.style.height = `${offsetHeight}px`;
const context = canvas.getContext('2d');
context.scale(pixelRatio, pixelRatio);

Copilot uses AI. Check for mistakes.
context.drawImage(image, 0, 0, offsetWidth, offsetHeight);
Comment on lines +884 to +886
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Handle potential null from getContext('2d').

Verify canvas.getContext('2d') returns a non-null context before scaling or drawing the image.

Suggested change
const context = canvas.getContext('2d');
context.scale(devicePixelRatio, devicePixelRatio);
context.drawImage(image, 0, 0, offsetWidth, offsetHeight);
const context = canvas.getContext('2d');
if (context) {
context.scale(devicePixelRatio, devicePixelRatio);
context.drawImage(image, 0, 0, offsetWidth, offsetHeight);
} else {
console.error('2D context not available on canvas.');
}

}

export {
autoAdd,
autoRemove,
Expand Down