@curvenote/schema
Version:
Schema and markdown parser for @curvenote/editor
61 lines • 1.52 kB
JavaScript
/* eslint-disable max-classes-per-file */
Object.defineProperty(exports, "__esModule", { value: true });
exports.createDocument = exports.Fragment = exports.Node = exports.Text = void 0;
const utils_1 = require("../../utils");
class Text {
constructor(text) {
this.kind = 'text';
this.id = (0, utils_1.createId)();
this.text = text;
}
}
exports.Text = Text;
class Node {
constructor(tag, name = 'unknown') {
this.kind = 'node';
this.id = (0, utils_1.createId)();
this.tag = tag;
this.name = name;
this.children = [];
this.attrs = {};
}
appendChild(child) {
this.children.push(child);
}
setAttribute(name, value) {
this.attrs[name] = value;
}
setAttributeNS(_, name, value) {
this.attrs[name] = value;
}
}
exports.Node = Node;
class Fragment {
constructor() {
this.children = [];
}
appendChild(child) {
this.children.push(child);
}
}
exports.Fragment = Fragment;
function createDocument() {
const document = {
createTextNode(text) {
return new Text(text);
},
createElementNS(name, tag) {
return new Node(tag, name);
},
createElement(tag) {
return new Node(tag);
},
createDocumentFragment() {
return new Fragment();
},
};
return document;
}
exports.createDocument = createDocument;
//# sourceMappingURL=document.js.map
;