feat: load background file

This commit is contained in:
2026-06-24 06:48:13 +05:00
parent 680dad30bf
commit 3b49c9f3c2
7 changed files with 242 additions and 3 deletions
+19
View File
@@ -1,6 +1,14 @@
const LABELS = ['TL', 'TR', 'BR', 'BL'];
const ns = 'http://www.w3.org/2000/svg';
const OBJECT_FIT_MAP = {
contain: 'xMidYMid meet',
cover: 'xMidYMid slice',
fill: 'none',
none: 'xMinYMin meet',
'scale-down': 'xMidYMid meet'
};
function gridInterval(maxDim) {
if (maxDim <= 500) return 50;
if (maxDim <= 1000) return 100;
@@ -26,6 +34,17 @@ export function renderSVG(svg, state) {
});
svg.appendChild(rect);
if (state.bgImage) {
const img = document.createElementNS(ns, 'image');
setAttrs(img, {
href: state.bgImage,
width: state.fieldW,
height: state.fieldH,
preserveAspectRatio: OBJECT_FIT_MAP[state.objectFit] || 'xMidYMid meet'
});
svg.appendChild(img);
}
const step = gridInterval(Math.max(state.fieldW, state.fieldH));
const gridG = document.createElementNS(ns, 'g');
for (let x = step; x < state.fieldW; x += step) {