"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImageSpecs = exports.imageType = exports.imageToMarkdown = exports.imageNodeName = exports.ImageAttr = void 0;
const schema_1 = require("../../../../utils/schema.js");
const const_1 = require("./const.js");
const utils_1 = require("./utils.js");
var const_2 = require("./const.js");
Object.defineProperty(exports, "ImageAttr", { enumerable: true, get: function () { return const_2.ImageAttr; } });
Object.defineProperty(exports, "imageNodeName", { enumerable: true, get: function () { return const_2.imageNodeName; } });
var utils_2 = require("./utils.js");
Object.defineProperty(exports, "imageToMarkdown", { enumerable: true, get: function () { return utils_2.imageToMarkdown; } });
exports.imageType = (0, schema_1.nodeTypeFactory)(const_1.imageNodeName);
const ImageSpecs = (builder) => {
    builder.addNode(const_1.imageNodeName, () => ({
        spec: {
            inline: true,
            attrs: {
                [const_1.ImageAttr.Src]: {},
                [const_1.ImageAttr.Alt]: { default: null },
                [const_1.ImageAttr.Title]: { default: null },
                [const_1.ImageAttr.Loading]: { default: null },
            },
            group: 'inline',
            draggable: true,
            parseDOM: [
                {
                    tag: 'img[src]',
                    getAttrs(dom) {
                        return {
                            [const_1.ImageAttr.Src]: dom.getAttribute(const_1.ImageAttr.Src),
                            [const_1.ImageAttr.Alt]: dom.getAttribute(const_1.ImageAttr.Alt),
                            [const_1.ImageAttr.Title]: dom.getAttribute(const_1.ImageAttr.Title),
                            [const_1.ImageAttr.Loading]: dom.getAttribute(const_1.ImageAttr.Loading),
                        };
                    },
                },
            ],
            toDOM(node) {
                return ['img', node.attrs];
            },
        },
        fromMd: {
            tokenSpec: {
                name: const_1.imageNodeName,
                type: 'node',
                getAttrs: (tok) => ({
                    [const_1.ImageAttr.Src]: tok.attrGet('src'),
                    [const_1.ImageAttr.Title]: tok.attrGet('title') || null,
                    [const_1.ImageAttr.Loading]: tok.attrGet(const_1.ImageAttr.Loading) || null,
                    [const_1.ImageAttr.Alt]: tok.children?.[0]?.content || null,
                }),
            },
        },
        toMd: (0, utils_1.imageToMarkdown)(),
    }));
};
exports.ImageSpecs = ImageSpecs;
//# sourceMappingURL=index.js.map
