var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
import { AcSvgRenderer } from '@mlightcad/svg-renderer';
import { AcApDocManager } from '../app';
/**
 * Utility class for converting CAD drawings to SVG format.
 *
 * This class provides functionality to export the current CAD drawing
 * to SVG format and download it as a file. It iterates through all
 * entities in the model space and renders them using the SVG renderer.
 *
 * The conversion process:
 * 1. Gets all entities from the current document's model space
 * 2. Uses the SVG renderer to convert each entity to SVG markup
 * 3. Exports the complete SVG content
 * 4. Creates a downloadable file for the user
 *
 * @example
 * ```typescript
 * const converter = new AcApSvgConvertor();
 *
 * // Convert and download current drawing as SVG
 * converter.convert();
 * ```
 */
var AcApSvgConvertor = /** @class */ (function () {
    function AcApSvgConvertor() {
    }
    /**
     * Converts the current CAD drawing to SVG format and initiates download.
     *
     * This method:
     * - Retrieves all entities from the current document's model space
     * - Renders each entity using the SVG renderer
     * - Exports the complete SVG markup
     * - Automatically downloads the SVG file as 'example.svg'
     *
     * @example
     * ```typescript
     * const converter = new AcApSvgConvertor();
     * converter.convert(); // Downloads the drawing as SVG
     * ```
     */
    AcApSvgConvertor.prototype.convert = function () {
        var e_1, _a;
        var entities = AcApDocManager.instance.curDocument.database.tables.blockTable.modelSpace.newIterator();
        var renderer = new AcSvgRenderer();
        try {
            for (var entities_1 = __values(entities), entities_1_1 = entities_1.next(); !entities_1_1.done; entities_1_1 = entities_1.next()) {
                var entity = entities_1_1.value;
                entity.worldDraw(renderer);
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1);
            }
            finally { if (e_1) throw e_1.error; }
        }
        this.createFileAndDownloadIt(renderer.export());
    };
    /**
     * Creates a downloadable SVG file and triggers the download.
     *
     * This method:
     * - Creates a Blob from the SVG content with proper MIME type
     * - Generates a temporary download URL
     * - Creates and triggers a download link
     * - Cleans up the temporary elements
     *
     * @param svgContent - The SVG markup content to download
     * @private
     */
    AcApSvgConvertor.prototype.createFileAndDownloadIt = function (svgContent) {
        // Convert the SVG content into a Blob
        var svgBlob = new Blob([svgContent], {
            type: 'image/svg+xml;charset=utf-8'
        });
        // Create a URL for the Blob
        var url = URL.createObjectURL(svgBlob);
        // Create a download link and trigger the download
        var downloadLink = document.createElement('a');
        downloadLink.href = url;
        downloadLink.download = 'example.svg';
        // Append the link to the body (it needs to be in the DOM to work in some browsers)
        document.body.appendChild(downloadLink);
        // Trigger the download
        downloadLink.click();
    };
    return AcApSvgConvertor;
}());
export { AcApSvgConvertor };
//# sourceMappingURL=AcApSvgConvertor.js.map