Skip to content

Commit 3987ecd

Browse files
Update calls
1 parent 40fd56e commit 3987ecd

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

public/ui.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ const matterLab = {
261261
};
262262

263263
function createDotsPattern(size, color, ctx) {
264-
const canvas = new OffscreenCanvas(size, size);
264+
const canvas = createScratchCanvas(size, size);
265265
const c = canvas.getContext("2d");
266266
c.fillStyle = color;
267267
c.beginPath();
@@ -271,7 +271,7 @@ function createDotsPattern(size, color, ctx) {
271271
}
272272

273273
function createCrosshatchPattern(size, color, ctx) {
274-
const canvas = new OffscreenCanvas(size, size);
274+
const canvas = createScratchCanvas(size, size);
275275
const c = canvas.getContext("2d");
276276
c.strokeStyle = color;
277277
c.lineWidth = Math.max(1, size / 8);
@@ -287,7 +287,7 @@ function createCrosshatchPattern(size, color, ctx) {
287287
}
288288

289289
function createNoisePattern(size, color, ctx) {
290-
const canvas = new OffscreenCanvas(size, size);
290+
const canvas = createScratchCanvas(size, size);
291291
const c = canvas.getContext("2d");
292292
const imageData = c.createImageData(size, size);
293293
const data = imageData.data;
@@ -376,6 +376,21 @@ function mulberry32(seed) {
376376
};
377377
}
378378

379+
function assetUrl(path) {
380+
const script = document.querySelector('script[src$="ui.js"]');
381+
return new URL(path, script?.src || location.href);
382+
}
383+
384+
function createScratchCanvas(width, height) {
385+
if (typeof OffscreenCanvas === "function") {
386+
return new OffscreenCanvas(width, height);
387+
}
388+
const canvas = document.createElement("canvas");
389+
canvas.width = width;
390+
canvas.height = height;
391+
return canvas;
392+
}
393+
379394
function interpolateColor(a, b, t) {
380395
const progressScaled = Math.round(t * 1000);
381396
return a.map((value, index) => interpolateComponent(value, b[index], progressScaled));
@@ -405,7 +420,7 @@ function obtenirDimensionsRendu() {
405420
async function loadWasm() {
406421
const status = document.getElementById("wasm-status");
407422
try {
408-
const response = await fetch("cellcosmos.wasm");
423+
const response = await fetch(assetUrl("cellcosmos.wasm"));
409424
if (!response.ok) {
410425
throw new Error(`Fichier WASM indisponible (${response.status}).`);
411426
}
@@ -1435,7 +1450,7 @@ function renderToCanvas(canvas, ruleNumber, rows, cols, cellSize) {
14351450

14361451
couches.forEach((couche) => {
14371452
// Create offscreen canvas for this layer
1438-
const offscreen = new OffscreenCanvas(canvasWidth, canvasHeight);
1453+
const offscreen = createScratchCanvas(canvasWidth, canvasHeight);
14391454
const offscreenCtx = offscreen.getContext("2d");
14401455

14411456
const gradient = generateGradient(couche.couleurs, rows);
@@ -2719,7 +2734,7 @@ async function loadGalleryFragment() {
27192734
if (galleryLoading) return galleryLoading;
27202735
const grid = document.getElementById("gallery-grid");
27212736
grid.innerHTML = '<p class="muted">Chargement de la galerie...</p>';
2722-
galleryLoading = fetch("gallery-fragment.html")
2737+
galleryLoading = fetch(assetUrl("gallery-fragment.html"))
27232738
.then((response) => {
27242739
if (!response.ok) {
27252740
throw new Error(`Fragment galerie indisponible (${response.status}).`);

0 commit comments

Comments
 (0)