summaryrefslogtreecommitdiff
path: root/apps/web/src/services/renderer/nodes/sticker-node.ts
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2026-03-25 16:47:22 +0100
committerMaze Winther <mazewinther@gmail.com>2026-03-29 15:48:22 +0200
commit8db3bead13441a5882d8689dfc6a9f09c82375d9 (patch)
treee9d0cafa93904ffcbec3188c37961bcc16c6422d /apps/web/src/services/renderer/nodes/sticker-node.ts
parent39ea298a9ccba3104c549c0ca079c231981811f5 (diff)
downloadopencut-8db3bead13441a5882d8689dfc6a9f09c82375d9.tar.gz
feat: masks, properties refactor, shaders, storage migrations, and more
Diffstat (limited to 'apps/web/src/services/renderer/nodes/sticker-node.ts')
-rw-r--r--apps/web/src/services/renderer/nodes/sticker-node.ts20
1 files changed, 14 insertions, 6 deletions
diff --git a/apps/web/src/services/renderer/nodes/sticker-node.ts b/apps/web/src/services/renderer/nodes/sticker-node.ts
index da271685..71cb37b5 100644
--- a/apps/web/src/services/renderer/nodes/sticker-node.ts
+++ b/apps/web/src/services/renderer/nodes/sticker-node.ts
@@ -4,6 +4,8 @@ import { VisualNode, type VisualNodeParams } from "./visual-node";
export interface StickerNodeParams extends VisualNodeParams {
stickerId: string;
+ intrinsicWidth?: number;
+ intrinsicHeight?: number;
}
interface CachedStickerSource {
@@ -14,7 +16,7 @@ interface CachedStickerSource {
const stickerSourceCache = new Map<string, Promise<CachedStickerSource>>();
-function loadStickerSource(stickerId: string): Promise<CachedStickerSource> {
+function loadStickerSource({ stickerId }: { stickerId: string }): Promise<CachedStickerSource> {
const cached = stickerSourceCache.get(stickerId);
if (cached) return cached;
@@ -33,7 +35,7 @@ function loadStickerSource(stickerId: string): Promise<CachedStickerSource> {
image.src = url;
});
- return { source: image, width: 200, height: 200 };
+ return { source: image, width: image.naturalWidth, height: image.naturalHeight };
})();
stickerSourceCache.set(stickerId, promise);
@@ -45,7 +47,7 @@ export class StickerNode extends VisualNode<StickerNodeParams> {
constructor(params: StickerNodeParams) {
super(params);
- this.cachedSource = loadStickerSource(params.stickerId);
+ this.cachedSource = loadStickerSource({ stickerId: params.stickerId });
}
async render({ renderer, time }: { renderer: CanvasRenderer; time: number }) {
@@ -55,13 +57,19 @@ export class StickerNode extends VisualNode<StickerNodeParams> {
return;
}
- const { source, width, height } = await this.cachedSource;
+ const { source, width: loadedWidth, height: loadedHeight } =
+ await this.cachedSource;
+
+ // Prefer element-stored intrinsic dimensions as the geometry authority.
+ // The loaded image is only the drawable source.
+ const sourceWidth = this.params.intrinsicWidth ?? loadedWidth;
+ const sourceHeight = this.params.intrinsicHeight ?? loadedHeight;
this.renderVisual({
renderer,
source,
- sourceWidth: width,
- sourceHeight: height,
+ sourceWidth,
+ sourceHeight,
timelineTime: time,
});
}