From 070300da8650dd0ca1ddb662c88b0be8d47c5448 Mon Sep 17 00:00:00 2001 From: Karl-HeinzSchneider <56960197+Karl-HeinzSchneider@users.noreply.github.com> Date: Mon, 1 Apr 2024 05:05:51 +0200 Subject: [PATCH] checkered url workaround --- src/app/components/canvas/canvas.component.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/app/components/canvas/canvas.component.ts b/src/app/components/canvas/canvas.component.ts index 4b62480..11151f0 100644 --- a/src/app/components/canvas/canvas.component.ts +++ b/src/app/components/canvas/canvas.component.ts @@ -1,5 +1,5 @@ import { CommonModule } from '@angular/common'; -import { AfterViewInit, Component, ElementRef, HostListener, Input, OnChanges, OnDestroy, SimpleChanges, ViewChild } from '@angular/core'; +import { AfterViewInit, Component, ElementRef, HostListener, Input, OnChanges, OnDestroy, SimpleChanges, ViewChild, isDevMode } from '@angular/core'; import { getActiveEntity } from '@ngneat/elf-entities'; import Konva from 'konva'; import { Layer } from 'konva/lib/Layer'; @@ -361,11 +361,18 @@ export class CanvasComponent implements OnChanges, AfterViewInit, OnDestroy { }) layer.add(rect) + // WORKAROUND: import.meta.url not using correct url -> "forgets" /ImageCutter/ when creating asset url //const url = '../../../../assets/img/checkered.png' - const url = '../assets/img/checkered.png' - - const fixedUrl = new URL(url, import.meta.url); - console.log(url, fixedUrl); + let url: string = ''; + if (isDevMode()) { + console.log('DEVMODE'); + url = '../assets/img/checkered.png'; + url = new URL(url, import.meta.url).href; + } + else { + console.log('NO DEVMODE'); + url = 'https://karl-heinzschneider.github.io/ImageCutter/assets/img/checkered.png' + } const loadImage = (url: string) => { return new Promise((resolve, reject) => { @@ -377,7 +384,7 @@ export class CanvasComponent implements OnChanges, AfterViewInit, OnDestroy { }) } - const checkered = await loadImage(fixedUrl.href); + const checkered = await loadImage(url); for (let i = 0; i < amountX; i++) { for (let j = 0; j < amountY; j++) {