"use strict"; // Pure math and canvas utilities shared across modules. const TLUtils = (() => { const clamp = (x, a, b) => Math.max(a, Math.min(b, x)); const fmt = (x, d = 3) => Number.isFinite(x) ? x.toFixed(d) : "NaN"; const sign = (x) => (x > 0) - (x < 0); function getDPR() { return Math.max(1, Math.floor(window.devicePixelRatio || 1)); } // Scale canvas internal buffer to match CSS size × device pixel ratio, // returning a logical-pixel coordinate system via ctx.setTransform. function resizeCanvasToCSS(canvas) { const dpr = getDPR(); const cssW = canvas.clientWidth; const cssH = Math.round(cssW * (canvas.height / canvas.width)); canvas.width = Math.round(cssW * dpr); canvas.height = Math.round(cssH * dpr); const ctx = canvas.getContext("2d"); ctx.setTransform(dpr, 0, 0, dpr, 0, 0); return { ctx, w: cssW, h: cssH, dpr }; } return { clamp, fmt, sign, getDPR, resizeCanvasToCSS }; })();