import { hexToRGBA, setPixel } from './pixelEditorUtils.js';

/**
 * pixelEditorTypes — shared types, constants & helpers for PixelEditor.
 */
/* ─────────────── constants ─────────────── */
const TOOLS = [
    { id: "pencil", icon: "✏", label: "Pencil", key: "B" },
    { id: "eraser", icon: "⌫", label: "Eraser", key: "E" },
    { id: "fill", icon: "🪣", label: "Bucket Fill", key: "G" },
    { id: "line", icon: "╱", label: "Line", key: "L" },
    { id: "rect", icon: "▢", label: "Rectangle", key: "U" },
    { id: "ellipse", icon: "◯", label: "Ellipse", key: "O" },
    { id: "eyedropper", icon: "💧", label: "Eyedropper", key: "I" },
    { id: "select", icon: "⬚", label: "Select", key: "M" },
    { id: "move", icon: "✥", label: "Move", key: "V" },
    { id: "gradient", icon: "▧", label: "Gradient", key: "H" },
    { id: "dither", icon: "▦", label: "Dither", key: "D" },
];
const BLEND_MODES = ["normal", "multiply", "screen", "overlay", "darken", "lighten"];
const BRUSH_SHAPES = [
    { id: "square", label: "Square", icon: "▪" },
    { id: "circle", label: "Circle", icon: "●" },
    { id: "diamond", label: "Diamond", icon: "◆" },
    { id: "spray", label: "Spray", icon: "░" },
];
const SYMMETRY_MODES = [
    { id: "none", label: "Off" },
    { id: "h", label: "↔ H" },
    { id: "v", label: "↕ V" },
    { id: "both", label: "✦ Both" },
    { id: "radial4", label: "✿ Radial" },
];
const DEFAULT_PALETTE = [
    "#000000", "#1d2b53", "#7e2553", "#008751",
    "#ab5236", "#5f574f", "#c2c3c7", "#fff1e8",
    "#ff004d", "#ffa300", "#ffec27", "#00e436",
    "#29adff", "#83769c", "#ff77a8", "#ffccaa",
    "#291814", "#111d35", "#422136", "#125359",
    "#742f29", "#49333b", "#a28879", "#f3ef7d",
    "#be1250", "#ff6c24", "#a8e72e", "#00b543",
    "#065ab5", "#754665", "#ff6e59", "#ff9768",
];
let _layerSeq = 0;
const lid = () => `l${++_layerSeq}`;
/* ─────────────── helpers ─────────────── */
const celKey = (f, l) => `${f}:${l}`;
const inB = (x, y, w, h) => x >= 0 && y >= 0 && x < w && y < h;
const downloadBlob = (blob, name) => {
    const a = document.createElement("a");
    const url = URL.createObjectURL(blob);
    a.href = url;
    a.download = name;
    a.click();
    setTimeout(() => URL.revokeObjectURL(url), 3000);
};
/** Hex → RGBA tuple. */
const hex2t = (hex) => hexToRGBA(hex);
/** Draw ellipse outline using parametric approach. */
const plotEllipse = (data, cx, cy, rx, ry, color, w, h, filled = false) => {
    if (rx <= 0 && ry <= 0) {
        if (inB(Math.round(cx), Math.round(cy), w, h))
            setPixel(data, Math.round(cx), Math.round(cy), color);
        return;
    }
    if (filled) {
        // filled ellipse
        for (let py = Math.ceil(cy - ry); py <= Math.floor(cy + ry); py++) {
            const t = ry > 0 ? (py - cy) / ry : 0;
            const halfW = rx * Math.sqrt(Math.max(0, 1 - t * t));
            for (let px = Math.ceil(cx - halfW); px <= Math.floor(cx + halfW); px++) {
                if (inB(px, py, w, h))
                    setPixel(data, px, py, color);
            }
        }
    }
    else {
        const steps = Math.max(Math.ceil(Math.PI * 2 * Math.max(rx, ry)), 16);
        for (let i = 0; i < steps; i++) {
            const a = (2 * Math.PI * i) / steps;
            const px = Math.round(cx + rx * Math.cos(a));
            const py = Math.round(cy + ry * Math.sin(a));
            if (inB(px, py, w, h))
                setPixel(data, px, py, color);
        }
    }
};

export { BLEND_MODES, BRUSH_SHAPES, DEFAULT_PALETTE, SYMMETRY_MODES, TOOLS, celKey, downloadBlob, hex2t, inB, lid, plotEllipse };
//# sourceMappingURL=pixelEditorTypes.js.map
