Release package version 0.0.04
All checks were successful
CI / build (push) Successful in 23s

Support for render ImageBitmap
This commit is contained in:
Andrey Kernichniy 2026-03-14 18:16:22 +07:00
parent 3c3b13e22f
commit c0150f85fa
5 changed files with 40 additions and 19 deletions

View file

@ -167,6 +167,18 @@ export class Artist {
this._context.restore(); this._context.restore();
} }
drawImage2(source: ImageBitmap, position: IPoint, size: ISize) {
this._context.save();
const scaleY = size.height / source.height;
const scaleX = size.width / source.width;
this._context.translate(position.x + size.width / 2, position.y + size.height / 2);
this._context.scale(scaleY, scaleX);
this._context.drawImage(source, -source.width / 2, -source.height / 2);
this._context.restore();
}
drawPath(path: string) { drawPath(path: string) {
const path2d = new Path2D(path); const path2d = new Path2D(path);
this._context.stroke(path2d); this._context.stroke(path2d);

View file

@ -92,11 +92,20 @@ export class Canvas2DRenderer implements IRenderer {
this._context.globalCompositeOperation = dn.blendMode as GlobalCompositeOperation; this._context.globalCompositeOperation = dn.blendMode as GlobalCompositeOperation;
this._artist.setTransform(dn.transform); this._artist.setTransform(dn.transform);
this._artist.drawImage( if (dn.source instanceof HTMLImageElement) {
dn.source, this._artist.drawImage(
{ x: dn.rectangle.x, y: dn.rectangle.y }, dn.source,
{ width: dn.rectangle.width, height: dn.rectangle.height }, { x: dn.rectangle.x, y: dn.rectangle.y },
); { width: dn.rectangle.width, height: dn.rectangle.height },
);
} else if (dn.source instanceof ImageBitmap) {
this._artist.drawImage2(
dn.source,
{ x: dn.rectangle.x, y: dn.rectangle.y },
{ width: dn.rectangle.width, height: dn.rectangle.height },
);
}
this._context.restore(); this._context.restore();
} }
if (isRectangleDrawObject(leaf)) { if (isRectangleDrawObject(leaf)) {

View file

@ -1,6 +1,6 @@
{ {
"name": "@gxc-solutions/renderer-canvas-2d", "name": "@gxc-solutions/renderer-canvas-2d",
"version": "0.0.3", "version": "0.0.4",
"main": "index.js", "main": "index.js",
"author": "GXC Solutions", "author": "GXC Solutions",
"publishConfig": { "publishConfig": {
@ -8,7 +8,7 @@
"registry": "https://npm.gxc-solutions.ru" "registry": "https://npm.gxc-solutions.ru"
}, },
"peerDependencies": { "peerDependencies": {
"@gxc-solutions/math": "^0.0.1", "@gxc-solutions/math": "^0.0.2",
"@gxc-solutions/renderer-base": "^0.0.9" "@gxc-solutions/renderer-base": "^0.0.10"
} }
} }

18
package-lock.json generated
View file

@ -9,8 +9,8 @@
"version": "0.0.0", "version": "0.0.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@gxc-solutions/math": "^0.0.1", "@gxc-solutions/math": "^0.0.2",
"@gxc-solutions/renderer-base": "^0.0.9" "@gxc-solutions/renderer-base": "^0.0.10"
}, },
"devDependencies": { "devDependencies": {
"@eslint/eslintrc": "^3.3.4", "@eslint/eslintrc": "^3.3.4",
@ -696,16 +696,16 @@
} }
}, },
"node_modules/@gxc-solutions/math": { "node_modules/@gxc-solutions/math": {
"version": "0.0.1", "version": "0.0.2",
"resolved": "https://npm.gxc-solutions.ru/@gxc-solutions/math/-/math-0.0.1.tgz", "resolved": "https://npm.gxc-solutions.ru/@gxc-solutions/math/-/math-0.0.2.tgz",
"integrity": "sha512-m6lxTkjXkyaUoI3+cJKpgt/AQlyApLSJ2p9D2EJ9+XzHCSjOWs29GzczPLgopYdLEWYN/YPr77V4CScGpR7qxw==" "integrity": "sha512-R6zYvbspis+XoHZ7lwyVLAUGZkJwivbeo94VtN7cSZzOA86AgVev+UQeHt9S1Ua4d1FwgxYVasck1/l5WXR7CQ=="
}, },
"node_modules/@gxc-solutions/renderer-base": { "node_modules/@gxc-solutions/renderer-base": {
"version": "0.0.9", "version": "0.0.10",
"resolved": "https://npm.gxc-solutions.ru/@gxc-solutions/renderer-base/-/renderer-base-0.0.9.tgz", "resolved": "https://npm.gxc-solutions.ru/@gxc-solutions/renderer-base/-/renderer-base-0.0.10.tgz",
"integrity": "sha512-aLu3eTyzDcGQw+FsYt25MNg/6gNORXa8FynUX5rtEFinmdFEDdqxOr08dhFViw1FIT3ZdYtJbY9aegFK3V/OcA==", "integrity": "sha512-DaGo2ii+Vqz5Mk20zXwNXMpxMCoF7fE8EbC+V37qEu+b/YVLtk7/N//1PyMl43hIIMlGNRps81dfJhPkCgSbdQ==",
"peerDependencies": { "peerDependencies": {
"@gxc-solutions/math": "^0.0.1" "@gxc-solutions/math": "^0.0.2"
} }
}, },
"node_modules/@humanfs/core": { "node_modules/@humanfs/core": {

View file

@ -31,7 +31,7 @@
"vite": "^7.3.1" "vite": "^7.3.1"
}, },
"dependencies": { "dependencies": {
"@gxc-solutions/math": "^0.0.1", "@gxc-solutions/math": "^0.0.2",
"@gxc-solutions/renderer-base": "^0.0.9" "@gxc-solutions/renderer-base": "^0.0.10"
} }
} }