UNPKG

@curvenote/schema

Version:

Schema and markdown parser for @curvenote/editor

54 lines 1.25 kB
/* eslint-disable max-classes-per-file */ import { createId } from '../../utils'; export class Text { constructor(text) { this.kind = 'text'; this.id = createId(); this.text = text; } } export class Node { constructor(tag, name = 'unknown') { this.kind = 'node'; this.id = 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; } } export class Fragment { constructor() { this.children = []; } appendChild(child) { this.children.push(child); } } export 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; } //# sourceMappingURL=document.js.map