"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmojiSpecs = exports.EmojiConsts = void 0;
const tslib_1 = require("tslib");
const bare_1 = tslib_1.__importDefault(require("markdown-it-emoji/bare"));
const const_1 = require("./const.js");
var const_2 = require("./const.js");
Object.defineProperty(exports, "EmojiConsts", { enumerable: true, get: function () { return const_2.EmojiConsts; } });
const EmojiSpecsExtension = (builder, opts) => {
    builder.configureMd((md) => md.use(bare_1.default, opts));
    builder.addNode(const_1.EmojiConsts.NodeName, () => ({
        spec: {
            attrs: { [const_1.EmojiConsts.NodeAttrs.Markup]: {} },
            atom: true,
            inline: true,
            content: 'text*',
            group: 'inline',
            selectable: false,
            parseDOM: [
                {
                    tag: `span[${const_1.markupDataAttribute}]`,
                    priority: 100,
                    getAttrs: (node) => {
                        if (node instanceof HTMLElement) {
                            const markup = node.getAttribute(const_1.markupDataAttribute);
                            if (markup) {
                                return { [const_1.EmojiConsts.NodeAttrs.Markup]: markup };
                            }
                        }
                        return false;
                    },
                },
            ],
            toDOM: (node) => {
                const markup = node.attrs[const_1.EmojiConsts.NodeAttrs.Markup];
                return ['span', { contentEditable: false, [const_1.markupDataAttribute]: markup }, 0];
            },
        },
        fromMd: {
            tokenName: const_1.emojiTokenName,
            tokenSpec: {
                name: const_1.EmojiConsts.NodeName,
                type: 'block',
                noCloseToken: true,
                getAttrs: (token) => ({
                    [const_1.EmojiConsts.NodeAttrs.Markup]: token.markup,
                }),
            },
        },
        toMd: (state, node) => {
            state.text(`:${node.attrs[const_1.EmojiConsts.NodeAttrs.Markup]}:`, false);
        },
    }));
};
exports.EmojiSpecs = Object.assign(EmojiSpecsExtension, const_1.EmojiConsts);
//# sourceMappingURL=EmojiSpecs.js.map
