const VIEWS = new Set(["edit", "split", "preview"]); const MODES = new Set(["markdown", "text"]); export function readEditorState() { const params = new URLSearchParams(window.location.search); return { view: VIEWS.has(params.get("view")) ? params.get("view") : "split", mode: MODES.has(params.get("mode")) ? params.get("mode") : "markdown", }; } export function writeEditorState(state, { replace = false } = {}) { const url = new URL(window.location.href); url.searchParams.set("view", state.view); url.searchParams.set("mode", state.mode); const method = replace ? "replaceState" : "pushState"; window.history[method]({ ...state }, "", `${url.pathname}${url.search}${url.hash}`); window.dispatchEvent(new CustomEvent("rustpad:urlchange", { detail: { url: url.href } })); return url.href; } export function currentShareUrl(state) { const url = new URL(window.location.href); url.searchParams.set("view", state.view); url.searchParams.set("mode", state.mode); return url.href; }