UNPKG

on-codemerge

Version:

A WYSIWYG editor for on-codemerge is a user-friendly interface that allows users to edit and view their code in real time, exactly as it will appear in the final product

77 lines (76 loc) 2.47 kB
/*! on-codemerge v1.3.1 @author Pavel Kuzmin @license MIT @homepage https://s00d.github.io/on-codemerge/ @repository git+https://github.com/s00d/on-codemerge.git Copyright (c) 2026 Pavel Kuzmin - Built on 2026-07-02T13:39:17.947Z */ var u = Object.defineProperty; var a = (r, e, t) => e in r ? u(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t; var s = (r, e, t) => a(r, typeof e != "symbol" ? e + "" : e, t); import { buildDomTree as l, serializeSelection as d, nodeToRef as h, publishFormatDebugMap as c } from "./FormatDebugMap.mjs"; let p = 0; class b { constructor() { s(this, "enabled", !1); s(this, "current", null); s(this, "lastMap", null); } isEnabled() { return this.enabled; } setEnabled(e) { this.enabled = e; } getLastMap() { return this.lastMap; } begin(e, t, n) { if (!this.enabled) return; l(t); const i = n.rangeCount > 0 ? n.getRangeAt(0) : null; this.current = { id: `trace-${++p}`, command: e, htmlBefore: t.innerHTML, selection: i ? d(n, t) : { collapsed: !0, text: "", start: { path: "", offset: 0, nodeType: "none" }, end: { path: "", offset: 0, nodeType: "none" }, commonAncestorPath: "" }, domTree: l(t), pipeline: [], nodesToModify: [], action: "noop" }; } step(e, t, n, i) { if (!this.enabled || !this.current) return; const o = { step: e }; i !== void 0 && (o.input = i), t !== void 0 && (o.output = t), n && (o.decision = n), this.current.pipeline.push(o); } setNodesToModify(e, t) { !this.enabled || !this.current || (this.current.nodesToModify = e.map((n) => h(n, t))); } setAction(e) { !this.enabled || !this.current || (this.current.action = e); } end(e) { if (!this.enabled || !this.current) return null; l(e); const t = { id: this.current.id, command: this.current.command, htmlBefore: this.current.htmlBefore, htmlAfter: e.innerHTML, selection: this.current.selection, domTree: l(e), pipeline: this.current.pipeline ?? [], nodesToModify: this.current.nodesToModify ?? [], action: this.current.action ?? "noop" }; return this.lastMap = t, this.current = null, c(t), t; } logToConsole(e, t) { this.enabled && (typeof process < "u" && process.env.JEST_WORKER_ID || console.info(t(e))); } } export { b as FormatDebugTracer };