UNPKG

@tldraw/editor

Version:

A tiny little drawing app (editor).

27 lines (26 loc) 931 B
import { getSchema } from "@tiptap/core"; import { Node } from "@tiptap/pm/model"; import { assert } from "@tldraw/utils"; function getFontsFromRichText(editor, richText, initialState) { const { tipTapConfig, addFontsFromNode } = editor.getTextOptions(); assert(tipTapConfig, "textOptions.tipTapConfig must be set to use rich text"); assert(addFontsFromNode, "textOptions.addFontsFromNode must be set to use rich text"); const schema = getSchema(tipTapConfig.extensions ?? []); const rootNode = Node.fromJSON(schema, richText); const fonts = /* @__PURE__ */ new Set(); function addFont(font) { fonts.add(font); } function visit(node, state) { state = addFontsFromNode(node, state, addFont); for (const child of node.children) { visit(child, state); } } visit(rootNode, initialState); return Array.from(fonts); } export { getFontsFromRichText }; //# sourceMappingURL=richText.mjs.map