//#region src/canvas/api/CanvasAPI.ts
/**
* Programmatic API/SDK for canvas operations.
*/
var CanvasAPI = class {
	constructor(canvas) {
		this.canvas = canvas;
	}
	/**
	* Register an existing element for canvas management.
	* @param element - The HTML element to register
	* @param id - Optional custom ID, otherwise auto-generated
	* @returns The element ID
	*/
	registerElement(element, id) {
		return this.canvas.registerElement(element, id);
	}
	/**
	* Unregister an element from canvas management.
	* @param id - Element ID or element itself
	*/
	unregisterElement(id) {
		this.canvas.unregisterElement(id);
	}
	/**
	* Update element position/transform in canvas coordinates.
	* @param id - Element ID
	* @param updates - Partial element data to update
	*/
	updateElement(id, updates) {
		const current = this.getElement(id);
		if (!current) throw new Error(`Element ${id} not found`);
		if (updates.x !== void 0 || updates.y !== void 0) {
			const x = updates.x !== void 0 ? updates.x : current.x;
			const y = updates.y !== void 0 ? updates.y : current.y;
			this.canvas.updateElementPosition(id, x, y);
		}
		if (updates.width !== void 0 || updates.height !== void 0) {
			const element = current.element;
			const width = updates.width !== void 0 ? updates.width : current.width;
			const height = updates.height !== void 0 ? updates.height : current.height;
			element.style.width = `${width}px`;
			element.style.height = `${height}px`;
		}
		if (updates.rotation !== void 0) {
			const element = current.element;
			element.style.transform = `rotate(${updates.rotation}deg)`;
		}
	}
	/**
	* Get element data by ID.
	* @param id - Element ID
	* @returns Element data or null if not found
	*/
	getElement(id) {
		return this.canvas.getElementData(id);
	}
	/**
	* Get all registered elements.
	* @returns Array of all element data
	*/
	getAllElements() {
		return this.canvas.getAllElementsData();
	}
	/**
	* Get the number of registered elements.
	* @returns The count of registered elements
	*/
	get elementCount() {
		return this.getAllElements().length;
	}
	/**
	* Get all registered elements (getter alias for getAllElements).
	* @returns Array of all element data
	*/
	get elements() {
		return this.getAllElements();
	}
	/**
	* Convert screen coordinates to canvas coordinates.
	* @param screenX - X coordinate in screen space
	* @param screenY - Y coordinate in screen space
	* @returns Canvas coordinates
	*/
	screenToCanvas(screenX, screenY) {
		return this.canvas.screenToCanvasCoords(screenX, screenY);
	}
	/**
	* Convert canvas coordinates to screen coordinates.
	* @param canvasX - X coordinate in canvas space
	* @param canvasY - Y coordinate in canvas space
	* @returns Screen coordinates
	*/
	canvasToScreen(canvasX, canvasY) {
		return this.canvas.canvasToScreenCoords(canvasX, canvasY);
	}
	/**
	* Select an element.
	* @param id - Element ID
	*/
	select(id) {
		this.canvas.selectionController.getModel().select(id);
	}
	/**
	* Select multiple elements.
	* @param ids - Array of element IDs
	*/
	selectMultiple(ids) {
		this.canvas.selectionController.getModel().selectMultiple(ids);
	}
	/**
	* Deselect an element.
	* @param id - Element ID
	*/
	deselect(id) {
		this.canvas.selectionController.getModel().deselect(id);
	}
	/**
	* Get currently selected element IDs.
	* @returns Set of selected IDs
	*/
	getSelectedIds() {
		const controller = this.canvas.selectionController;
		return Array.from(controller.getModel().selectedIds);
	}
	/**
	* Create a group from element IDs.
	* @param ids - Array of element IDs to group
	* @returns Group ID
	*/
	group(ids) {
		return this.canvas.selectionController.getModel().createGroup(ids);
	}
	/**
	* Ungroup a group.
	* @param groupId - Group ID
	*/
	ungroup(groupId) {
		this.canvas.selectionController.getModel().ungroup(groupId);
	}
	/**
	* Export canvas data.
	* @returns Canvas data structure
	*/
	export() {
		const model = this.canvas.selectionController.getModel();
		const groups = [];
		const processedGroups = /* @__PURE__ */ new Set();
		for (const elementId of this.getAllElements().map((e) => e.id)) {
			const groupId = model.getGroupId(elementId);
			if (groupId && !processedGroups.has(groupId)) {
				processedGroups.add(groupId);
				groups.push({
					id: groupId,
					elementIds: model.getGroupElements(groupId)
				});
			}
		}
		return {
			elements: this.getAllElements(),
			groups
		};
	}
	/**
	* Import canvas data.
	* @param data - Canvas data structure
	*/
	import(data) {
		for (const element of this.getAllElements()) this.unregisterElement(element.id);
		for (const elementData of data.elements) {
			const element = elementData.element;
			this.registerElement(element, elementData.id);
			this.updateElement(elementData.id, elementData);
		}
		const controller = this.canvas.selectionController;
		for (const group of data.groups) controller.getModel().createGroup(group.elementIds);
	}
};

//#endregion
export { CanvasAPI };
//# sourceMappingURL=CanvasAPI.js.map