'use strict';

var jsxRuntime = require('react/jsx-runtime');
var index = require('../packages/ui/dist/index.js');
var VectorEditor_module = require('./VectorEditor.module.css.js');
var vectorEditorTypes = require('./vectorEditorTypes.js');
var VectorEditorShapeRenderer = require('./VectorEditorShapeRenderer.js');
var useVectorEditor = require('./useVectorEditor.js');
var VectorEditorMenuBar = require('./VectorEditorMenuBar.js');
var VectorEditorRightPanel = require('./VectorEditorRightPanel.js');
var VectorEditorStatusBar = require('./VectorEditorStatusBar.js');

const NiceVectorEditor = ({ width: artW = 512, height: artH = 512, className, onSaveToLibrary, }) => {
    const api = useVectorEditor.useVectorEditor({ artW, artH, onSaveToLibrary });
    const { shapes, selId, tool, zoom, px, py, dlgSvg, svgText, gridSize, boxRef, fInp, onDown, onMove, onUp, onWheel, onDblClick, openFile, switchTool, importSVGString, setDlgSvg, setSvgText, } = api;
    return (jsxRuntime.jsxs("div", { className: `${VectorEditor_module.root} ${className || ""}`, children: [jsxRuntime.jsx("input", { ref: fInp, type: "file", accept: ".svg", style: { display: "none" }, onChange: (e) => {
                    var _a;
                    const f = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
                    if (f)
                        openFile(f);
                    e.target.value = "";
                } }), jsxRuntime.jsx(VectorEditorMenuBar, { api: api, hasOnSaveToLibrary: !!onSaveToLibrary }), jsxRuntime.jsxs("div", { className: VectorEditor_module.mainArea, children: [jsxRuntime.jsx("div", { className: VectorEditor_module.toolbar, children: vectorEditorTypes.TOOLS.map((t) => (jsxRuntime.jsx(index.NiceButton, { className: `${VectorEditor_module.toolBtn} ${tool === t.id ? VectorEditor_module.toolBtnActive : ""}`, onClick: () => switchTool(t.id), "aria-label": `${t.label} (${t.key})`, variant: tool === t.id ? "primary" : "ghost", size: "sm", children: t.icon }, t.id))) }), jsxRuntime.jsx("div", { ref: boxRef, className: VectorEditor_module.canvasContainer, children: jsxRuntime.jsxs("svg", { viewBox: `0 0 ${artW} ${artH}`, onMouseDown: onDown, onMouseMove: onMove, onMouseUp: onUp, onMouseLeave: () => {
                                /* handled internally via refs */
                            }, onDoubleClick: onDblClick, onWheel: onWheel, onContextMenu: (e) => e.preventDefault(), style: {
                                transform: `translate(${px}px, ${py}px) scale(${zoom})`,
                                transformOrigin: "center center",
                                cursor: tool === "pointer" ? "default" : "crosshair",
                            }, children: [jsxRuntime.jsx("rect", { x: 0, y: 0, width: artW, height: artH, fill: "#222" }), zoom >= 2 && (jsxRuntime.jsxs("g", { opacity: 0.08, children: [Array.from({ length: Math.floor(artW / gridSize) + 1 }, (_, i) => (jsxRuntime.jsx("line", { x1: i * gridSize, y1: 0, x2: i * gridSize, y2: artH, stroke: "#fff", strokeWidth: 1 / zoom }, `gx${i}`))), Array.from({ length: Math.floor(artH / gridSize) + 1 }, (_, i) => (jsxRuntime.jsx("line", { x1: 0, y1: i * gridSize, x2: artW, y2: i * gridSize, stroke: "#fff", strokeWidth: 1 / zoom }, `gy${i}`)))] })), shapes.map((s) => (jsxRuntime.jsx(VectorEditorShapeRenderer.ShapeRenderer, { shape: s, selected: s.id === selId, zoom: zoom }, s.id)))] }) }), jsxRuntime.jsx(VectorEditorRightPanel, { api: api })] }), jsxRuntime.jsx(VectorEditorStatusBar, { api: api, artW: artW, artH: artH }), jsxRuntime.jsxs(index.NiceModal, { open: dlgSvg, onClose: () => setDlgSvg(false), title: "Paste SVG", children: [jsxRuntime.jsx("label", { children: "Paste SVG source code below:" }), jsxRuntime.jsx(index.NiceTextArea, { value: svgText, onChange: (val) => setSvgText(val), placeholder: '<svg xmlns="http://www.w3.org/2000/svg" ...>' }), jsxRuntime.jsxs("div", { className: VectorEditor_module.dialogActions, children: [jsxRuntime.jsx(index.NiceButton, { variant: "ghost", onClick: () => setDlgSvg(false), children: "Cancel" }), jsxRuntime.jsx(index.NiceButton, { variant: "primary", onClick: () => importSVGString(svgText), children: "Import" })] })] })] }));
};
/** @deprecated Use NiceVectorEditor */
const VectorEditor = NiceVectorEditor;

exports.NiceVectorEditor = NiceVectorEditor;
exports.VectorEditor = VectorEditor;
//# sourceMappingURL=VectorEditor.js.map
