Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
let yjs = require("yjs");
let y_prosemirror = require("y-prosemirror");
let _tiptap_pm_model = require("@tiptap/pm/model");
let _tiptap_core = require("@tiptap/core");
let _tiptap_starter_kit = require("@tiptap/starter-kit");

//#region packages/transformer/src/Prosemirror.ts
var Prosemirror = class {
	constructor() {
		this.defaultSchema = new _tiptap_pm_model.Schema({ nodes: {
			text: {},
			doc: { content: "text*" }
		} });
	}
	schema(schema) {
		this.defaultSchema = schema;
		return this;
	}
	fromYdoc(document, fieldName) {
		const data = {};
		if (typeof fieldName === "string") return (0, y_prosemirror.yDocToProsemirrorJSON)(document, fieldName);
		if (fieldName === void 0 || fieldName.length === 0) fieldName = Array.from(document.share.keys());
		fieldName.forEach((field) => {
			data[field] = (0, y_prosemirror.yDocToProsemirrorJSON)(document, field);
		});
		return data;
	}
	toYdoc(document, fieldName = "prosemirror", schema) {
		if (!document) throw new Error(`You’ve passed an empty or invalid document to the Transformer. Make sure to pass ProseMirror-compatible JSON. Actually passed JSON: ${document}`);
		if (typeof fieldName === "string") return (0, y_prosemirror.prosemirrorJSONToYDoc)(schema || this.defaultSchema, document, fieldName);
		const ydoc = new yjs.Doc();
		fieldName.forEach((field) => {
			(0, yjs.applyUpdate)(ydoc, (0, yjs.encodeStateAsUpdate)((0, y_prosemirror.prosemirrorJSONToYDoc)(schema || this.defaultSchema, document, field)));
		});
		return ydoc;
	}
};
const ProsemirrorTransformer = new Prosemirror();

//#endregion
//#region packages/transformer/src/Tiptap.ts
var Tiptap = class {
	constructor() {
		this.defaultExtensions = [_tiptap_starter_kit.StarterKit];
	}
	extensions(extensions) {
		this.defaultExtensions = extensions;
		return this;
	}
	fromYdoc(document, fieldName) {
		return ProsemirrorTransformer.fromYdoc(document, fieldName);
	}
	toYdoc(document, fieldName = "default", extensions) {
		return ProsemirrorTransformer.toYdoc(document, fieldName, (0, _tiptap_core.getSchema)(extensions || this.defaultExtensions));
	}
};
const TiptapTransformer = new Tiptap();

//#endregion
exports.ProsemirrorTransformer = ProsemirrorTransformer;
exports.Tiptap = Tiptap;
exports.TiptapTransformer = TiptapTransformer;
//# sourceMappingURL=hocuspocus-transformer.cjs.map