kandown 0.15.1 → 0.15.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/kandown.js +31 -1
- package/bin/tui.js +40 -9
- package/dist/index.html +2 -2
- package/package.json +1 -1
package/bin/kandown.js
CHANGED
|
@@ -71,11 +71,32 @@ const PKG_ROOT = resolve(__dirname, '..');
|
|
|
71
71
|
// 📖 Default localhost range for the zero-config `kandown` web UI server.
|
|
72
72
|
// 📖 Single source of truth for the daemon port range. Each kandown project
|
|
73
73
|
// gets its own daemon on the first free port in this range, so multiple
|
|
74
|
-
// projects can run in parallel (A=2048, B=
|
|
74
|
+
// projects can run in parallel (A=2048, B=2050, C=2051, ...).
|
|
75
75
|
const START_PORT_RANGE = 2048;
|
|
76
76
|
const END_PORT_RANGE = 2150;
|
|
77
77
|
const DAEMON_FILE = 'daemon.json';
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* 📖 Ports that Chromium/Firefox/Safari refuse to load (net::ERR_UNSAFE_PORT).
|
|
81
|
+
* These are reserved for well-known services (NFS, ssh, smtp, X11, ...).
|
|
82
|
+
* Browsers block navigation to them with no recourse, so a daemon listening
|
|
83
|
+
* on one of these appears dead in the browser even though it serves fine via
|
|
84
|
+
* curl. We MUST skip them when allocating ports. The most common victim in
|
|
85
|
+
* our 2048+ range is 2049 (NFS), which silently broke the 2nd concurrent
|
|
86
|
+
* kandown project. Sourced from Chromium's net/base/port_util.cc restricted
|
|
87
|
+
* ports list (stable, updated rarely).
|
|
88
|
+
*/
|
|
89
|
+
const BROWSER_UNSAFE_PORTS = new Set([
|
|
90
|
+
1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42, 43, 53, 69, 77,
|
|
91
|
+
79, 87, 95, 101, 102, 103, 104, 109, 110, 111, 113, 115, 117, 119, 123,
|
|
92
|
+
135, 139, 143, 179, 389, 427, 465, 512, 513, 514, 515, 526, 530, 531, 532,
|
|
93
|
+
540, 548, 554, 556, 563, 587, 601, 636, 993, 995, 1720, 1723, 2049, 3659,
|
|
94
|
+
4045, 5060, 5061, 6000, 6566, 6665, 6666, 6667, 6668, 6669, 6697, 10080,
|
|
95
|
+
]);
|
|
96
|
+
function isBrowserUnsafePort(port) {
|
|
97
|
+
return BROWSER_UNSAFE_PORTS.has(port);
|
|
98
|
+
}
|
|
99
|
+
|
|
79
100
|
// 📖 Get current CLI version from package.json at PKG_ROOT
|
|
80
101
|
function getCurrentVersion() {
|
|
81
102
|
try {
|
|
@@ -1902,6 +1923,11 @@ async function listenOnAvailablePort(kandownDir, preferredPort) {
|
|
|
1902
1923
|
|
|
1903
1924
|
// If user specified a specific port, only try that one
|
|
1904
1925
|
if (isSinglePort) {
|
|
1926
|
+
if (isBrowserUnsafePort(port)) {
|
|
1927
|
+
err(`Port ${c.bold}${port}${c.reset} is reserved for a well-known service and ${c.bold}blocked by all browsers${c.reset} (net::ERR_UNSAFE_PORT).`);
|
|
1928
|
+
log(` Pick another port with ${c.cyan}--port${c.reset}.`);
|
|
1929
|
+
process.exit(1);
|
|
1930
|
+
}
|
|
1905
1931
|
const server = createServeServer(kandownDir);
|
|
1906
1932
|
try {
|
|
1907
1933
|
await listen(server, port);
|
|
@@ -1917,6 +1943,10 @@ async function listenOnAvailablePort(kandownDir, preferredPort) {
|
|
|
1917
1943
|
|
|
1918
1944
|
// 📖 Scan range — try ports until one works
|
|
1919
1945
|
for (let p = START_PORT_RANGE; p <= END_PORT_RANGE; p++) {
|
|
1946
|
+
// 📖 Skip browser-blocked ports (e.g. 2049 = NFS). A daemon here would
|
|
1947
|
+
// start fine and answer curl, but the browser refuses with
|
|
1948
|
+
// net::ERR_UNSAFE_PORT, so the web UI looks dead. Move to the next port.
|
|
1949
|
+
if (isBrowserUnsafePort(p)) continue;
|
|
1920
1950
|
// Skip port if occupied by a stale kandown from a DIFFERENT project
|
|
1921
1951
|
const stale = detectStaleKandown(p, kandownDir);
|
|
1922
1952
|
if (stale && !stale.reason) {
|
package/bin/tui.js
CHANGED
|
@@ -54651,6 +54651,7 @@ function moveTaskToColumn(kandownDir, taskId, targetColumn) {
|
|
|
54651
54651
|
import { existsSync as existsSync4, readFileSync as readFileSync4, unlinkSync } from "fs";
|
|
54652
54652
|
import { dirname as dirname2, join as join3 } from "path";
|
|
54653
54653
|
import { spawn } from "child_process";
|
|
54654
|
+
import { createConnection } from "net";
|
|
54654
54655
|
function metadataPath(kandownDir) {
|
|
54655
54656
|
return join3(kandownDir, "daemon.json");
|
|
54656
54657
|
}
|
|
@@ -54708,6 +54709,20 @@ async function fetchDaemonInfo(port) {
|
|
|
54708
54709
|
return null;
|
|
54709
54710
|
}
|
|
54710
54711
|
}
|
|
54712
|
+
function isPortListening(port, timeoutMs = 400) {
|
|
54713
|
+
return new Promise((resolve3) => {
|
|
54714
|
+
const socket = createConnection({ port, host: "127.0.0.1" }, () => {
|
|
54715
|
+
socket.destroy();
|
|
54716
|
+
resolve3(true);
|
|
54717
|
+
});
|
|
54718
|
+
socket.on("error", () => resolve3(false));
|
|
54719
|
+
socket.setTimeout(timeoutMs);
|
|
54720
|
+
socket.on("timeout", () => {
|
|
54721
|
+
socket.destroy();
|
|
54722
|
+
resolve3(false);
|
|
54723
|
+
});
|
|
54724
|
+
});
|
|
54725
|
+
}
|
|
54711
54726
|
async function getDaemonStatus(kandownDir) {
|
|
54712
54727
|
const metadata = readDaemonMetadata(kandownDir);
|
|
54713
54728
|
if (!metadata) return { running: false, metadata: null };
|
|
@@ -54716,18 +54731,23 @@ async function getDaemonStatus(kandownDir) {
|
|
|
54716
54731
|
return { running: false, metadata: null };
|
|
54717
54732
|
}
|
|
54718
54733
|
const remote = await fetchDaemonInfo(metadata.port);
|
|
54719
|
-
if (!remote
|
|
54734
|
+
if (!remote) {
|
|
54735
|
+
return { running: false, metadata: null };
|
|
54736
|
+
}
|
|
54737
|
+
if (remote.pid !== metadata.pid || remote.kandownDir !== kandownDir) {
|
|
54720
54738
|
removeDaemonMetadata(kandownDir);
|
|
54721
54739
|
return { running: false, metadata: null };
|
|
54722
54740
|
}
|
|
54723
54741
|
return { running: true, metadata };
|
|
54724
54742
|
}
|
|
54725
|
-
async function waitForDaemon(kandownDir, timeoutMs =
|
|
54743
|
+
async function waitForDaemon(kandownDir, timeoutMs = 8e3) {
|
|
54726
54744
|
const started = Date.now();
|
|
54727
54745
|
while (Date.now() - started < timeoutMs) {
|
|
54728
|
-
const
|
|
54729
|
-
if (
|
|
54730
|
-
|
|
54746
|
+
const metadata = readDaemonMetadata(kandownDir);
|
|
54747
|
+
if (metadata && isProcessAlive(metadata.pid) && await isPortListening(metadata.port)) {
|
|
54748
|
+
return { running: true, metadata };
|
|
54749
|
+
}
|
|
54750
|
+
await new Promise((resolve3) => setTimeout(resolve3, 120));
|
|
54731
54751
|
}
|
|
54732
54752
|
return { running: false, metadata: null };
|
|
54733
54753
|
}
|
|
@@ -57082,8 +57102,15 @@ var MENU_HEIGHT = 2;
|
|
|
57082
57102
|
var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
|
|
57083
57103
|
var TASKS_START_Y = 5;
|
|
57084
57104
|
function truncate(str, maxLen) {
|
|
57105
|
+
if (maxLen <= 0) return "";
|
|
57085
57106
|
if (str.length <= maxLen) return str;
|
|
57086
|
-
return str.slice(0, maxLen - 1) + "\u2026";
|
|
57107
|
+
return str.slice(0, Math.max(0, maxLen - 1)) + "\u2026";
|
|
57108
|
+
}
|
|
57109
|
+
function terminalHyperlink(label, url) {
|
|
57110
|
+
return `\x1B]8;;${url}\x07${label}\x1B]8;;\x07`;
|
|
57111
|
+
}
|
|
57112
|
+
function webLinkLabel(url) {
|
|
57113
|
+
return `\u2197 ${url.replace(/^https?:\/\//, "")}`;
|
|
57087
57114
|
}
|
|
57088
57115
|
function pad(str, len) {
|
|
57089
57116
|
const t = truncate(str, len);
|
|
@@ -57258,11 +57285,15 @@ function BoardHeader({ title, inTmux, modeHint, version, daemonStatus, daemonBus
|
|
|
57258
57285
|
const rightWidth = Math.max(0, width - leftWidth - daemonWidth);
|
|
57259
57286
|
const left = pad(` \u25C6 KANDOWN${tmuxHint}${versionTag} ${title}`, leftWidth);
|
|
57260
57287
|
const daemon = pad(daemonLabel, daemonWidth);
|
|
57261
|
-
const
|
|
57288
|
+
const webUrl = daemonStatus.running ? daemonStatus.metadata?.url : null;
|
|
57289
|
+
const rightPlain = webUrl ? truncate(webLinkLabel(webUrl), rightWidth) : truncate(hint, rightWidth);
|
|
57290
|
+
const right = rightPlain.padStart(rightWidth, " ");
|
|
57291
|
+
const rightPadding = right.slice(0, Math.max(0, right.length - rightPlain.length));
|
|
57292
|
+
const rightContent = webUrl ? `${rightPadding}${terminalHyperlink(rightPlain, webUrl)}` : right;
|
|
57262
57293
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Box_default, { marginBottom: 1, children: [
|
|
57263
57294
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { bold: true, color: "cyan", children: left }),
|
|
57264
57295
|
daemonWidth > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: daemonStatus.running ? "green" : "yellow", bold: true, children: daemon }),
|
|
57265
|
-
rightWidth > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: "gray", dimColor:
|
|
57296
|
+
rightWidth > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: webUrl ? "blue" : "gray", dimColor: !webUrl, underline: !!webUrl, children: rightContent })
|
|
57266
57297
|
] });
|
|
57267
57298
|
}
|
|
57268
57299
|
function StatusBar({ message, task, daemonStatus }) {
|
|
@@ -58006,7 +58037,7 @@ function Board({ kandownDir, version }) {
|
|
|
58006
58037
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Box_default, { flexDirection: "column", children: [
|
|
58007
58038
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Box_default, { marginBottom: 1, justifyContent: "space-between", children: [
|
|
58008
58039
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: "gray", children: "Esc back \xB7 a agent \xB7 j/k scroll" }),
|
|
58009
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: "gray", dimColor: true, children: [
|
|
58040
|
+
daemonStatus.running && daemonStatus.metadata ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: "blue", underline: true, children: terminalHyperlink(webLinkLabel(daemonStatus.metadata.url), daemonStatus.metadata.url) }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: "gray", dimColor: true, children: [
|
|
58010
58041
|
"KANDOWN ",
|
|
58011
58042
|
board.title
|
|
58012
58043
|
] })
|
package/dist/index.html
CHANGED
|
@@ -113,7 +113,7 @@ Error generating stack: `+y.message+`
|
|
|
113
113
|
|
|
114
114
|
## Subtasks
|
|
115
115
|
|
|
116
|
-
`}}async function Hz(t,e){try{return await(await(await(await t.getDirectoryHandle("archive",{create:!1})).getFileHandle(`${e}.md`)).getFile()).text()}catch{return null}}async function Yoe(t,e){try{return await(await t.getDirectoryHandle("archive",{create:!1})).getFileHandle(`${e}.md`),!0}catch{return!1}}async function Bz(t,e){try{return await t.getDirectoryHandle("archive",{create:e})}catch{return null}}async function Xoe(t){if(Kt())return Q4();const e=new Set;for await(const n of t.values())n.kind==="file"&&n.name.endsWith(".md")&&e.add(n.name.slice(0,-3));try{const n=await t.getDirectoryHandle("archive",{create:!1});for await(const a of n.values())a.kind==="file"&&a.name.endsWith(".md")&&e.add(a.name.slice(0,-3))}catch{}return[...e].sort((n,a)=>n.localeCompare(a,void 0,{numeric:!0}))}async function Es(t,e){if(Kt())try{const i=await J4(e);return Ig(i)}catch{return hj(e)}const a=await(async i=>{try{return await(await(await i.getFileHandle(`${e}.md`)).getFile()).text()}catch{return null}})(t)??await Hz(t,e);return a!==null?Ig(a):hj(e)}async function Qoe(t,e){if(Kt())try{const a=await J4(e);return{ok:!0,task:Ig(a)}}catch(a){return a.name==="NotFoundError"?{ok:!1,reason:"not-found"}:{ok:!1,reason:"unknown",error:a}}let n=null;try{n=await(await(await t.getFileHandle(`${e}.md`)).getFile()).text()}catch{}if(n===null)try{n=await Hz(t,e)}catch(a){return{ok:!1,reason:"unknown",error:a}}if(n===null)return{ok:!1,reason:"not-found"};if(n.trim()==="")return{ok:!1,reason:"corrupted",error:new Error(`Task file ${e}.md is empty`)};try{return{ok:!0,task:Ig(n)}}catch(a){return{ok:!1,reason:"corrupted",error:a}}}async function au(t,e,n,a){const i=Y4(n,a);if(Kt())return Boe(e,i);try{const o=await(await(await Yoe(t,e)?await Bz(t,!0):t).getFileHandle(`${e}.md`,{create:!0})).createWritable();try{await o.write(i)}finally{await o.close()}}catch(r){throw ek(r,`${e}.md`)}}async function bj(t,e){if(Kt())return qoe(e);try{await t.removeEntry(`${e}.md`)}catch{}try{await(await t.getDirectoryHandle("archive",{create:!1})).removeEntry(`${e}.md`)}catch{}}async function Joe(t,e){await hs(`/api/tasks/${encodeURIComponent(t)}/archive`,{method:"POST",body:e,headers:{"Content-Type":"text/plain"}})}async function ece(t,e){await hs(`/api/tasks/${encodeURIComponent(t)}/unarchive`,{method:"POST",body:e,headers:{"Content-Type":"text/plain"}})}async function tce(t,e,n,a){const i=Y4(n,a);if(Kt())return Joe(e,i);try{const o=await(await(await Bz(t,!0)).getFileHandle(`${e}.md`,{create:!0})).createWritable();try{await o.write(i)}finally{await o.close()}try{await t.removeEntry(`${e}.md`)}catch{}}catch(r){throw ek(r,`archive/${e}.md`)}}async function nce(t,e,n,a){const i=Y4(n,a);if(Kt())return ece(e,i);try{const s=await(await t.getFileHandle(`${e}.md`,{create:!0})).createWritable();try{await s.write(i)}finally{await s.close()}try{await(await t.getDirectoryHandle("archive",{create:!1})).removeEntry(`${e}.md`)}catch{}}catch(r){throw ek(r,`${e}.md`)}}const ace="kanban-md",ice=1,ap="recentProjects";function eS(){return new Promise((t,e)=>{const n=indexedDB.open(ace,ice);n.onerror=()=>e(n.error),n.onsuccess=()=>t(n.result),n.onupgradeneeded=()=>{const a=n.result;a.objectStoreNames.contains(ap)||a.createObjectStore(ap,{keyPath:"id"})}})}async function E2(t){const e=await eS();return new Promise((n,a)=>{const i=e.transaction(ap,"readwrite");i.objectStore(ap).put(t),i.oncomplete=()=>n(),i.onerror=()=>a(i.error)})}async function Ly(){const t=await eS();return new Promise((e,n)=>{const i=t.transaction(ap,"readonly").objectStore(ap).getAll();i.onsuccess=()=>{const r=i.result||[];r.sort((s,o)=>o.lastOpened-s.lastOpened),e(r.slice(0,10))},i.onerror=()=>n(i.error)})}async function rce(t){const e=await eS();return new Promise((n,a)=>{const i=e.transaction(ap,"readwrite");i.objectStore(ap).delete(t),i.oncomplete=()=>n(),i.onerror=()=>a(i.error)})}async function vj(t,e=!0){const n={mode:e?"readwrite":"read"};try{return await t.queryPermission(n)==="granted"||await t.requestPermission(n)==="granted"}catch(a){return console.warn("[FS] verifyPermission: handle is no longer valid:",a),!1}}function qz(t=Ci){const e=t.board.columns;return e[e.length-1]??"Done"}function sce(t,e=Ci){return t===qz(e)||t.toLowerCase()==="archived"}class oce{dirHandle=null;tasksDirHandle=null;intervalId=null;configHash=null;taskHashes=new Map;knownTaskIds=new Set;listeners=new Map;debounceTimers=new Map;debounceDelay=150;consecutiveErrors=0;maxConsecutiveErrors=5;disabled=!1;start(e,n){this.dirHandle=e,this.tasksDirHandle=n,this.consecutiveErrors=0,this.disabled=!1,this.initHashes(),this.intervalId=setInterval(()=>void this.tick(),300)}stop(){this.intervalId&&(clearInterval(this.intervalId),this.intervalId=null),this.configHash=null,this.taskHashes.clear(),this.knownTaskIds.clear(),this.listeners.clear(),this.debounceTimers.forEach(e=>clearTimeout(e)),this.debounceTimers.clear(),this.consecutiveErrors=0,this.disabled=!1}isDisabled(){return this.disabled}on(e,n){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(n),()=>{this.listeners.get(e)?.delete(n)}}getKnownTaskIds(){return Array.from(this.knownTaskIds)}async initHashes(){if(!(!this.dirHandle||!this.tasksDirHandle))try{const e=await yj(this.dirHandle);e!==null&&(this.configHash=await this.hash(e)),await this.syncTaskDir(!1)}catch(e){console.warn("[Watcher] initHashes error:",e)}}async tick(){if(!(!this.dirHandle||!this.tasksDirHandle)&&!this.disabled)try{const e=await yj(this.dirHandle);if(e!==null){const n=await this.hash(e);this.configHash!==null&&n!==this.configHash&&(this.configHash=n,this.debouncedEmit("configChanged"))}for(const n of[...this.knownTaskIds])try{const a=await _j(this.tasksDirHandle,n);if(a!==null){const i=await this.hash(a),r=this.taskHashes.get(n);r!==void 0&&i!==r&&(this.taskHashes.set(n,i),this.debouncedEmit("taskChanged",n))}}catch(a){console.warn(`[Watcher] Error reading task ${n}:`,a)}await this.syncTaskDir(!0),this.consecutiveErrors=0}catch(e){this.consecutiveErrors++,console.error(`[Watcher] Tick failed (${this.consecutiveErrors}/${this.maxConsecutiveErrors}):`,e),this.consecutiveErrors>=this.maxConsecutiveErrors&&this.disable(`File watcher stopped after ${this.maxConsecutiveErrors} consecutive errors: ${e.message}`)}}disable(e){this.intervalId&&(clearInterval(this.intervalId),this.intervalId=null),this.disabled=!0,this.emit("watcherError",e)}debouncedEmit(e,...n){const a=e+JSON.stringify(n),i=this.debounceTimers.get(a);i&&clearTimeout(i);const r=setTimeout(()=>{this.debounceTimers.delete(a),this.emit(e,...n)},this.debounceDelay);this.debounceTimers.set(a,r)}async syncTaskDir(e){if(!this.tasksDirHandle)return;let n;try{n=this.tasksDirHandle.values()}catch(a){throw a}for await(const a of n){if(a.kind!=="file"||!a.name.endsWith(".md"))continue;const i=a.name.replace(".md","");if(!this.knownTaskIds.has(i))try{this.knownTaskIds.add(i);const r=await _j(this.tasksDirHandle,i);r!==null&&(this.taskHashes.set(i,await this.hash(r)),e&&this.debouncedEmit("newTaskDetected",i))}catch(r){console.warn(`[Watcher] syncTaskDir: failed to read ${i}:`,r)}}}async hash(e){const a=new TextEncoder().encode(e),i=await crypto.subtle.digest("SHA-256",a);return Array.from(new Uint8Array(i)).map(s=>s.toString(16).padStart(2,"0")).join("")}emit(e,...n){this.listeners.get(e)?.forEach(i=>{if(e==="configChanged"){i();return}if(e==="taskChanged"){const[s]=n;i(s);return}if(e==="newTaskDetected"){const[s]=n;i(s);return}const[r]=n;i(r)})}}async function yj(t){try{return await(await(await t.getFileHandle("kandown.json")).getFile()).text()}catch{return null}}async function _j(t,e){try{return await(await(await t.getFileHandle(`${e}.md`)).getFile()).text()}catch{return null}}const al=new oce,cce={soft:[{frequency:520,durationMs:90,delayMs:0,type:"sine"},{frequency:720,durationMs:120,delayMs:95,type:"sine"}],chime:[{frequency:660,durationMs:120,delayMs:0,type:"triangle"},{frequency:880,durationMs:160,delayMs:125,type:"triangle"}],ping:[{frequency:920,durationMs:110,delayMs:0,type:"sine"}],pop:[{frequency:260,durationMs:55,delayMs:0,type:"square"},{frequency:520,durationMs:80,delayMs:60,type:"square"}]};let kj=null;function Uz(){return"Notification"in window?Notification.permission:"unsupported"}async function pce(){return"Notification"in window?await Notification.requestPermission():"unsupported"}function P2({title:t,body:e,config:n}){if(n.notifications.sound&&lce(n.notifications.soundId),!(!n.notifications.browser||Uz()!=="granted"))try{new Notification(t,{body:e})}catch{}}function lce(t){const e=cce[t],n=window.AudioContext??window.webkitAudioContext;if(!(!n||e.length===0))try{kj??=new n;const a=kj;a.state==="suspended"&&a.resume();const i=a.currentTime+.01;e.forEach(r=>{const s=a.createOscillator(),o=a.createGain(),c=i+r.delayMs/1e3,p=c+r.durationMs/1e3;s.type=r.type??"sine",s.frequency.setValueAtTime(r.frequency,c),o.gain.setValueAtTime(1e-4,c),o.gain.exponentialRampToValueAtTime(.08,c+.01),o.gain.exponentialRampToValueAtTime(1e-4,p),s.connect(o),o.connect(a.destination),s.start(c),s.stop(p+.02)})}catch{}}async function Tf(t,e={}){const{maxAttempts:n=3,baseDelayMs:a=500,retryableCheck:i=Foe}=e;let r;for(let s=1;s<=n;s++)try{return await t()}catch(o){if(r=o,!i(o))throw o;if(s<n){const c=a*Math.pow(2,s-1);await new Promise(p=>setTimeout(p,c))}}throw r}function dce(t){let e=-1;for(const n of t)for(const a of n.tasks){const i=a.id.match(/^t(\d+)$/);if(i){const r=parseInt(i[1],10);r>e&&(e=r)}}return"t"+(e+1)}async function uce(){const t=await Q4();return await Promise.all(t.map(async n=>{const{frontmatter:a,body:i}=await zz(n),r={...a,id:a.id||n,status:a.status||"Backlog"},{subtasks:s,bodyWithoutSubtasks:o}=Ds(i);return{id:n,frontmatter:r,body:o,subtasks:s}}))}async function mce(t){const e=await Xoe(t),n=await Promise.all(e.map(async r=>{const s=await Qoe(t,r);return{id:r,result:s}})),a=[],i=[];for(const{id:r,result:s}of n)if(s.ok){const o={...s.task.frontmatter,id:s.task.frontmatter.id||r,status:s.task.frontmatter.status||"Backlog"},{subtasks:c,bodyWithoutSubtasks:p}=Ds(s.task.body);a.push({id:r,frontmatter:o,body:p,subtasks:c})}else{if(s.reason==="not-found")continue;i.push(r)}return{tasks:a,failedIds:i}}async function wj(t,e,n){const a=[];for(const s of e){const o=s.name;s.tasks.forEach((c,p)=>{const d=(async()=>{const{frontmatter:m,body:f}=await Es(t,c.id);await au(t,c.id,{...m,id:c.id,status:o,order:p},f)})();a.push({id:c.id,promise:d})})}const i=await Promise.allSettled(a.map(s=>s.promise)),r=[];return i.forEach((s,o)=>{s.status==="rejected"&&r.push(a[o].id)}),{failedIds:r}}function rl(t){Roe(t.ui.theme,t.ui.skin,t.ui.font,t.ui.background)}function h3(t){return{title:t.frontmatter.title||t.id,status:t.frontmatter.status||"Backlog",body:t.body,subtasks:t.subtasks}}function T2(t){mu.clear(),t.forEach(e=>{mu.set(e.id,h3(e))})}function fce(t){const e=t.split(/[\\/]+/).filter(Boolean),n=e[e.length-1];return n===".kandown"?e[e.length-2]??"Project":n??"Project"}function gce(t,e){return e.reduce((n,a,i)=>{const r=t[i]?.done??!1;return n+(a.done&&!r?1:0)},0)}function hce(t,e){const n=t.subtasks.map(i=>({text:i.text,description:i.description??"",report:i.report??""})),a=e.subtasks.map(i=>({text:i.text,description:i.description??"",report:i.report??""}));return t.title!==e.title||t.body!==e.body||JSON.stringify(n)!==JSON.stringify(a)}let bce=0;const mu=new Map,Mf=new Map;let M2=null;const ue=$oe((t,e)=>({isOpen:!1,loading:!1,dirHandle:null,projectName:null,tasksDirHandle:null,boardTitle:"Project Kanban",columns:[],archivedTasks:[],showArchives:!1,showMetadata:!0,taskContents:new Map,searchMatches:new Map,viewMode:localStorage.getItem("kandown:view")||"board",density:localStorage.getItem("kandown:density")||"comfortable",filters:{search:"",priority:null,tag:null,assignee:null,ownerType:null},commandOpen:!1,cheatsheetOpen:!1,drawerTaskId:null,drawerData:null,currentPage:"board",config:Ci,recentProjects:[],toasts:[],agentHook:null,isReloading:!1,lastReloadError:null,failedTaskIds:[],watcherError:null,hasUnsavedDrawerEdits:!1,lastSaveError:null,drawerRecoveryData:new Map,drawerBaseVersion:null,conflictState:null,showConflictModal:!1,openFolder:async()=>{if(!Oz()){const c=navigator.userAgent||"this browser";e().toast(new Ooe(c).message,"error",8e3);return}let n;try{n=await Goe()}catch(c){c instanceof X4?e().toast("Permission denied — please grant access to the project folder","error"):e().toast("Failed to open folder: "+c.message,"error");return}if(!n)return;const{projectHandle:a,kandownHandle:i,tasksHandle:r}=n,s=a.name;t({dirHandle:i,tasksDirHandle:r,projectName:s}),window.history.pushState({},"",`?p=${encodeURIComponent(s)}`);const o=Kt()?$2():null;try{await E2({id:a.name,name:a.name,handle:a,lastOpened:Date.now(),...o?{kandownDir:o}:{}})}catch(c){console.warn("[Store] Failed to save recent project:",c)}await e().loadConfig(),await e().reloadBoard();try{const c=await Ly();t({recentProjects:c})}catch(c){console.warn("[Store] Failed to load recent projects:",c)}e().setupWatcher()},openRecentProject:async n=>{const a={dirHandle:e().dirHandle,tasksDirHandle:e().tasksDirHandle,projectName:e().projectName};if(!await vj(n.handle,!0)){let r=!1;try{await My(n.handle),r=!0}catch{r=!1}if(!r){e().toast(`"${n.name}" is no longer accessible. Removed from recent projects.`,"warning",8e3);try{await rce(n.id);const s=await Ly();t({recentProjects:s})}catch{}return}e().toast("Permission denied — please grant access to the folder","error");return}try{const r=await My(n.handle),s=await g3(n.handle),o=n.handle.name;t({dirHandle:r,tasksDirHandle:s,projectName:o}),window.history.pushState({},"",`?p=${encodeURIComponent(o)}`);try{await E2({...n,lastOpened:Date.now()})}catch(c){console.warn("[Store] Failed to update recent project:",c)}await e().loadConfig(),await e().reloadBoard(),e().setupWatcher()}catch(r){t(a),e().toast(`Failed to open project: ${r.message}`,"error")}},openServerProject:async()=>{t({loading:!0});try{const n=$2();if(!n)throw new Error("No server root");await gj();const a=fce(n),i=await Fz();rl(i);const r=await Q4(),s=await Promise.all(r.map(async f=>{const{frontmatter:h,body:b}=await zz(f),k={...h,id:h.id||f,status:h.status||"Backlog"},{subtasks:w,bodyWithoutSubtasks:A}=Ds(b);return{id:f,frontmatter:k,body:A,subtasks:w}}));T2(s);const o=s.map(f=>({frontmatter:f.frontmatter,body:qd(f.body,f.subtasks)})),c=N2(o,i.board.columns),p=S2(o),d=c.reduce((f,h)=>f+h.tasks.length,0),m=new Map;if(d<=10)for(const f of s)m.set(f.frontmatter.id,{frontmatter:f.frontmatter,subtasks:f.subtasks,body:f.body});t({loading:!1,isOpen:!0,config:i,columns:c,archivedTasks:p,boardTitle:"Project Kanban",projectName:a,taskContents:m,searchMatches:new Map}),window.history.pushState({},"",`?p=${encodeURIComponent(a)}`),e().setupWatcher(),e().refreshAgentHook()}catch{t({loading:!1,isOpen:!1}),e().toast("Impossible de charger le projet. Relancez `kandown`.","error")}},tryAutoOpenServerProject:async()=>{if(!Kt())return;const n=$2();if(!n)return;await gj();const a=await Ly(),i=a.find(p=>p.kandownDir===n);if(!i){await e().openServerProject();return}if(!await vj(i.handle,!0)){await e().openServerProject();return}const s=await My(i.handle),o=await g3(i.handle),c=i.handle.name;t({dirHandle:s,tasksDirHandle:o,projectName:c,recentProjects:a,isOpen:!0}),window.history.pushState({},"",`?p=${encodeURIComponent(c)}`),await E2({...i,lastOpened:Date.now()}),await e().loadConfig(),await e().reloadBoard(),e().setupWatcher()},loadConfig:async()=>{const{dirHandle:n}=e();if(!(!n&&!Kt()))try{const a=await Woe(n);if(a.ok){t({config:a.config}),rl(a.config);return}if(a.reason==="corrupted"){if(a.rawContent&&n)try{const r=await(await n.getFileHandle("kandown.json.backup",{create:!0})).createWritable();try{await r.write(a.rawContent)}finally{await r.close()}}catch{}e().toast("kandown.json is corrupted — using default settings. A backup was saved as kandown.json.backup.","warning",1e4)}t({config:Ci}),rl(Ci)}catch{t({config:Ci}),rl(Ci)}},updateConfig:async n=>{const{dirHandle:a,config:i}=e();if(!a&&!Kt())return;const r=n(i);t({config:r}),rl(r);try{await Koe(a,r)}catch(s){const o=s;o instanceof $o?e().toast("Disk is full — settings were not saved.","error",8e3):e().toast("Failed to save config: "+o.message,"error")}},reloadBoard:async()=>{const{tasksDirHandle:n,config:a}=e();t({isReloading:!0,lastReloadError:null});try{if(Kt()){const i=await uce();T2(i);const r=i.map(d=>({frontmatter:d.frontmatter,body:qd(d.body,d.subtasks)})),s=N2(r,a.board.columns),o=S2(r);t({boardTitle:"Project Kanban",columns:s,archivedTasks:o});const c=s.reduce((d,m)=>d+m.tasks.length,0),p=new Map;if(c<=10)for(const d of i)p.set(d.frontmatter.id,{frontmatter:d.frontmatter,subtasks:d.subtasks,body:d.body});t({taskContents:p,searchMatches:new Map,failedTaskIds:[],isReloading:!1})}else if(n){const{tasks:i,failedIds:r}=await mce(n);T2(i);const s=i.map(m=>({frontmatter:m.frontmatter,body:qd(m.body,m.subtasks)})),o=N2(s,a.board.columns),c=S2(s);t({boardTitle:"Project Kanban",columns:o,archivedTasks:c});const p=o.reduce((m,f)=>m+f.tasks.length,0),d=new Map;if(p<=10)for(const m of i)d.set(m.frontmatter.id,{frontmatter:m.frontmatter,subtasks:m.subtasks,body:m.body});if(r.length>0){const m=r.length===1?`Task ${r[0]} could not be loaded`:`${r.length} tasks could not be loaded`;e().toast(m,"warning",8e3)}t({taskContents:d,searchMatches:new Map,failedTaskIds:r,isReloading:!1})}else t({isReloading:!1})}catch(i){const r=i.message||String(i);t({isReloading:!1,lastReloadError:`Failed to reload board: ${r}`}),e().toast(`Board reload failed — showing last loaded state (${r})`,"warning",8e3)}},moveTask:async(n,a,i,r)=>{const{columns:s,config:o,taskContents:c,searchMatches:p}=e(),d=Kt();if(!d&&!e().tasksDirHandle)return;const m=s.find(E=>E.name===a),f=s.find(E=>E.name===i);if(!m||!f)return;const h=m.tasks.findIndex(E=>E.id===n);if(h===-1)return;const b=m.tasks[h];if(!b)return;if(sce(i,o)){const E=new Map,P=qz(o).toLowerCase();for(const j of s)for(const z of j.tasks){const H=z.frontmatter&&(z.frontmatter.archived===!0||z.frontmatter.archived==="true");E.set(z.id,{exists:!0,resolved:H||z.id===n||j.name.toLowerCase()===P})}const M=[];for(const j of b.dependsOn){if(typeof j!="string"||!j.trim()||j===n)continue;const z=E.get(j);(!z||!z.resolved)&&M.push(j)}if(M.length>0){const j=M.length===1?M[0]:`${M.slice(0,-1).join(", ")} and ${M[M.length-1]}`;e().toast(`Cannot move ${n} to ${i}: blocked by ${j}`,"error");return}}const k=s.map(E=>({...E,tasks:[...E.tasks]})),w=k.find(E=>E.name===a),A=k.find(E=>E.name===i),[S]=w.tasks.splice(h,1);/done|termin|closed|complet/i.test(i)?S.checked=!0:S.checked=!1,r!==void 0?A.tasks.splice(r,0,S):A.tasks.push(S),t({columns:k});try{const{tasksDirHandle:E}=e();if(!E&&!d)return;const P=a===i?k.filter(j=>j.name===i):k.filter(j=>j.name===a||j.name===i),{failedIds:M}=await Tf(()=>wj(E??null,P,o.board.columns),{maxAttempts:3});if(M.length>0){const j=M.length===1?`Could not save move for ${M[0]}`:`${M.length} tasks could not be moved`;e().toast(j,"warning",8e3),await e().reloadBoard()}}catch(E){const P=E;P instanceof $o?e().toast("Disk is full — move was not saved. Free up space and try again.","error",8e3):e().toast("Failed to save: "+P.message,"error"),t({columns:s,taskContents:c,searchMatches:p})}},reorderInColumn:async(n,a,i)=>{const{columns:r,tasksDirHandle:s,config:o,taskContents:c,searchMatches:p}=e();if(!s&&!Kt())return;const d=r.map(h=>({...h,tasks:[...h.tasks]})),m=d.find(h=>h.name===n);if(!m)return;const[f]=m.tasks.splice(a,1);m.tasks.splice(i,0,f),t({columns:d});try{const{tasksDirHandle:h}=e(),b=Kt();if(!h&&!b)return;const{failedIds:k}=await Tf(()=>wj(h??null,[m],o.board.columns),{maxAttempts:3});k.length>0&&(e().toast(`Could not save reorder for ${k.length} task(s)`,"warning",8e3),await e().reloadBoard())}catch(h){const b=h;b instanceof $o?e().toast("Disk is full — reorder was not saved.","error",8e3):e().toast("Failed to save: "+b.message,"error"),t({columns:r,taskContents:c,searchMatches:p})}},addColumn:async n=>{const a=n.trim();if(!a)return;const{config:i}=e();i.board.columns.some(r=>r.toLowerCase()===a.toLowerCase())||(await e().updateConfig(r=>({...r,board:{...r.board,columns:[...r.board.columns,a]}})),await e().reloadBoard())},renameColumn:async(n,a)=>{const i=a.trim(),{columns:r,tasksDirHandle:s,config:o}=e();if(!s||!i||i.toLowerCase()===n.toLowerCase())return;if(r.some(d=>d.name.toLowerCase()===i.toLowerCase())){e().toast("Column already exists","error");return}const c=r,p=r.map(d=>d.name===n?{...d,name:i}:d);t({columns:p});try{const d=c.find(m=>m.name===n);if(d){const f=(await Promise.allSettled(d.tasks.map(async(h,b)=>{const{frontmatter:k,body:w}=await Es(s,h.id);await au(s,h.id,{...k,id:h.id,status:i,order:b},w)}))).filter(h=>h.status==="rejected").length;f>0&&e().toast(`${f} task(s) could not be renamed`,"warning",8e3)}await e().updateConfig(m=>{const f={...m.board.columnColors??{}},h=f[n.toLowerCase()];h&&(f[i.toLowerCase()]=h,delete f[n.toLowerCase()]);const b=m.board.columns.some(k=>k.toLowerCase()===n.toLowerCase())?m.board.columns:[...m.board.columns,n];return{...m,board:{...m.board,columns:b.map(k=>k.toLowerCase()===n.toLowerCase()?i:k),columnColors:f}}}),await e().reloadBoard()}catch(d){e().toast("Failed to rename column: "+d.message,"error"),t({columns:c})}},deleteColumn:async n=>{const{columns:a,tasksDirHandle:i}=e();if(!i&&!Kt())return;const r=a.find(o=>o.name===n);if(!r)return;const s=a;t({columns:a.filter(o=>o.name!==n)});try{const c=(await Promise.allSettled(r.tasks.map(p=>bj(i,p.id)))).filter(p=>p.status==="rejected").length;c>0&&e().toast(`${c} task(s) could not be deleted`,"warning",8e3),await e().updateConfig(p=>{const d={...p.board.columnColors??{}};return delete d[n.toLowerCase()],{...p,board:{...p.board,columns:p.board.columns.filter(m=>m.toLowerCase()!==n.toLowerCase()),columnColors:d}}}),await e().reloadBoard(),e().toast("Column deleted")}catch(o){e().toast("Failed to delete column: "+o.message,"error"),t({columns:s})}},createTask:async n=>{const{columns:a,tasksDirHandle:i,config:r,taskContents:s,searchMatches:o}=e();if(!i&&!Kt()||!a.length)return null;const c=n||r.board.columns[0]||a[0].name,p=dce(a),d=a.find(w=>w.name===c)?.tasks.length??0,m={id:p,title:"",checked:!1,dependsOn:[],tags:[],assignee:null,priority:r.fields.priority?r.board.defaultPriority:null,ownerType:r.fields.ownerType?r.board.defaultOwnerType:"",progress:null,frontmatter:{}},f=a.map(w=>w.name===c?{...w,tasks:[...w.tasks,m]}:w),h=new Map(s),b={id:p,title:"",status:c,order:d,priority:r.fields.priority?r.board.defaultPriority:"",tags:[],assignee:"",created:new Date().toISOString().slice(0,10),ownerType:r.fields.ownerType?r.board.defaultOwnerType:"",tools:""},k="";h.set(p,{frontmatter:b,subtasks:[],body:k}),t({columns:f,taskContents:h});try{const w=i||null;return await Tf(()=>au(w,p,b,k),{maxAttempts:3}),e().toast(`Created ${p.replace(/^t/,"")}`),await e().openDrawer(p),p}catch(w){const A=w;return A instanceof $o?e().toast("Disk is full — task was not created.","error",8e3):e().toast("Failed to create: "+A.message,"error"),t({columns:a,taskContents:s,searchMatches:o}),null}},deleteTask:async n=>{const{columns:a,tasksDirHandle:i,taskContents:r,searchMatches:s}=e();if(!i&&!Kt())return;const o=a.map(d=>({...d,tasks:d.tasks.filter(m=>m.id!==n)}));t({columns:o});const c=new Map(r);c.delete(n);const p=new Map(s);p.delete(n),t({taskContents:c,searchMatches:p});try{await bj(i||null,n),e().toast("Deleted")}catch(d){const m=d;e().toast("Failed to delete: "+m.message,"error"),t({columns:a,taskContents:r,searchMatches:s})}},archiveTask:async n=>{const{tasksDirHandle:a}=e();if(!(!a&&!Kt()))try{const{frontmatter:i,body:r}=await Es(a||null,n);await tce(a||null,n,{...i,archived:!0},r),e().drawerTaskId===n&&e().closeDrawer(),await e().reloadBoard(),e().toast("Archived")}catch(i){const r=i;r instanceof $o?e().toast("Disk is full — task was not archived.","error",8e3):e().toast("Failed to archive: "+r.message,"error")}},unarchiveTask:async n=>{const{tasksDirHandle:a}=e();if(!(!a&&!Kt()))try{const{frontmatter:i,body:r}=await Es(a||null,n),s={...i};delete s.archived,await nce(a||null,n,s,r),await e().reloadBoard(),e().toast("Restored")}catch(i){const r=i;r instanceof $o?e().toast("Disk is full — task was not restored.","error",8e3):e().toast("Failed to restore: "+r.message,"error")}},setShowArchives:n=>t({showArchives:n}),setShowMetadata:n=>t({showMetadata:n}),openDrawer:async n=>{const{tasksDirHandle:a}=e();if(!(!a&&!Kt()))try{const{frontmatter:i,body:r}=await Es(a,n),{subtasks:s,bodyWithoutSubtasks:o}=Ds(r),c={frontmatter:i,subtasks:s,body:o,savedAt:Date.now()},p=e().drawerRecoveryData.get(n),d=p?{frontmatter:p.frontmatter,subtasks:p.subtasks,body:p.body}:{frontmatter:i,subtasks:s,body:o},m=new Map(e().drawerRecoveryData);m.delete(n),t({drawerTaskId:n,drawerData:d,drawerBaseVersion:c,conflictState:null,showConflictModal:!1,hasUnsavedDrawerEdits:!!p,lastSaveError:null,drawerRecoveryData:m}),p&&e().toast("Restored your unsaved edits for this task","info")}catch(i){e().toast("Failed to open: "+i.message,"error")}},closeDrawer:()=>t({drawerTaskId:null,drawerData:null,drawerBaseVersion:null,conflictState:null,showConflictModal:!1,hasUnsavedDrawerEdits:!1,lastSaveError:null}),markDrawerDirty:()=>t({hasUnsavedDrawerEdits:!0}),forceCloseDrawer:()=>{const{drawerTaskId:n,drawerData:a}=e();if(n&&a){const i=new Map(e().drawerRecoveryData);i.set(n,{frontmatter:a.frontmatter,subtasks:a.subtasks,body:a.body}),t({drawerRecoveryData:i})}e().closeDrawer()},updateDrawerData:n=>{const{drawerData:a}=e();a&&t({drawerData:n(a)})},saveDrawer:async()=>{const{drawerTaskId:n,drawerData:a,tasksDirHandle:i,taskContents:r}=e();if(!n||!a)return;const s=qd(a.body,a.subtasks),o={...a.frontmatter,id:n};try{await Tf(()=>au(i||null,n,o,s),{maxAttempts:3}),e().toast("Saved");const c=new Map(e().drawerRecoveryData);c.delete(n),t({drawerTaskId:null,drawerData:null,hasUnsavedDrawerEdits:!1,lastSaveError:null,drawerRecoveryData:c});const p=new Map(r);p.set(n,{frontmatter:o,subtasks:a.subtasks,body:a.body}),t({taskContents:p}),await e().reloadBoard()}catch(c){const p=c,d=p instanceof $o?"Disk is full — your edits are kept. Free up space and retry.":"Failed to save: "+p.message;e().toast(d,"error",8e3),t({lastSaveError:d})}},saveDrawerMetadata:async()=>{const{drawerTaskId:n,drawerData:a,tasksDirHandle:i,taskContents:r}=e();if(!(!n||!a))try{const s=qd(a.body,a.subtasks),o={...a.frontmatter,id:n};await Tf(()=>au(i||null,n,o,s),{maxAttempts:3});const c=new Map(r);c.set(n,{frontmatter:o,subtasks:a.subtasks,body:a.body}),t({taskContents:c,hasUnsavedDrawerEdits:!1,lastSaveError:null}),await e().reloadBoard()}catch(s){const o=s,c=o instanceof $o?"Disk is full — your edits are kept.":"Failed to save: "+o.message;t({hasUnsavedDrawerEdits:!0,lastSaveError:c})}},setViewMode:n=>{localStorage.setItem("kandown:view",n),t({viewMode:n})},setDensity:n=>{localStorage.setItem("kandown:density",n),t({density:n})},setFilter:(n,a)=>{if(t(i=>({filters:{...i.filters,[n]:a}})),n==="search"){const{columns:i,tasksDirHandle:r,taskContents:s}=e(),o=a,c=i.flatMap(p=>p.tasks.map(d=>d.id));if(r){const p=c.filter(d=>!s.has(d));p.length>0?e().loadTaskContents(p).then(()=>{e().computeSearchMatches(o)}):e().computeSearchMatches(o)}}},clearFilters:()=>t({filters:{search:"",priority:null,tag:null,assignee:null,ownerType:null},searchMatches:new Map}),setCommandOpen:n=>t({commandOpen:n}),setCheatsheetOpen:n=>t({cheatsheetOpen:n}),refreshAgentHook:async()=>{if(!Kt()){t({agentHook:null});return}const n=await Uoe();t({agentHook:n?.agentHook??null})},sendTaskToAgent:async n=>{const a=e().agentHook;if(!a){e().toast("Agent hook not configured","error");return}e().toast(`Sending to ${a.label}…`);const i=await Voe(n);if(i===null){e().toast("Could not reach the daemon","error");return}i.ok?e().toast(`Sent to ${a.label}`):e().toast(i.error||"Agent hook failed","error")},setCurrentPage:n=>t({currentPage:n}),loadTaskContents:async n=>{const{tasksDirHandle:a}=e();if(!a)return;const i=new Map(e().taskContents);await Promise.all(n.map(async r=>{if(!i.has(r))try{const{frontmatter:s,body:o}=await Es(a,r),{subtasks:c,bodyWithoutSubtasks:p}=Ds(o);i.set(r,{frontmatter:s,subtasks:c,body:p})}catch{}})),t({taskContents:i})},computeSearchMatches:n=>{if(!n.trim()){t({searchMatches:new Map});return}const{taskContents:a}=e(),i=new Map,r=n.toLowerCase();for(const[s,o]of a){const c=Rz(o,r);c.length>0&&i.set(s,c)}t({searchMatches:i})},toast:(n,a="success",i)=>{const r=++bce,s=i??(a==="error"||a==="warning"?6e3:2500);t(o=>({toasts:[...o.toasts,{id:r,message:n,type:a}]})),setTimeout(()=>{t(o=>({toasts:o.toasts.filter(c=>c.id!==r)}))},s)},dismissToast:n=>t(a=>({toasts:a.toasts.filter(i=>i.id!==n)})),resolveConflict:async n=>{const{conflictState:a,drawerData:i,tasksDirHandle:r,drawerTaskId:s,drawerBaseVersion:o}=e();if(!(!a||!r||!s))if(n==="reload"){const{frontmatter:c,body:p}=await Es(r,s),{subtasks:d,bodyWithoutSubtasks:m}=Ds(p);t({drawerData:{frontmatter:c,subtasks:d,body:m},drawerBaseVersion:{frontmatter:c,subtasks:d,body:m,savedAt:Date.now()},conflictState:null,showConflictModal:!1}),e().toast("Reloaded from disk")}else if(n==="overwrite"){if(i&&s&&o){const c=qd(i.body,i.subtasks),p={...i.frontmatter,id:s};try{await au(r,s,p,c),t({drawerBaseVersion:{...i,savedAt:Date.now()},conflictState:null,showConflictModal:!1}),e().toast("Overwritten remote changes")}catch(d){e().toast("Failed to overwrite: "+d.message,"error")}}}else t({conflictState:null,showConflictModal:!1})},setupWatcher:()=>{if(Kt()){M2&&clearInterval(M2),M2=setInterval(()=>{e().reloadBoard()},2e3);return}const{dirHandle:n,tasksDirHandle:a}=e();if(!n||!a)return;al.stop(),Mf.forEach(s=>clearTimeout(s)),Mf.clear(),al.start(n,a);const i=(s,o)=>{const c=Mf.get(s);c&&clearTimeout(c);const p=Math.max(2e3,e().config.notifications.editDebounceMs),d=setTimeout(()=>{Mf.delete(s);const m=e().config;m.notifications.taskEdits&&P2({title:"Task edited",body:`${o} changed on disk.`,config:m})},p);Mf.set(s,d)},r=async s=>{const{tasksDirHandle:o,config:c}=e();if(!o)return;let p,d;try{({frontmatter:p,body:d}=await Es(o,s))}catch(A){console.warn(`[Watcher] notifyTaskChange: failed to read ${s}:`,A);return}const{subtasks:m,bodyWithoutSubtasks:f}=Ds(d),h={id:s,frontmatter:{...p,id:p.id||s,status:p.status||"Backlog"},body:f,subtasks:m},b=h3(h),k=mu.get(s);if(!k){mu.set(s,b);return}c.notifications.statusChanges&&k.status!==b.status&&P2({title:"Task status changed",body:`${b.title}: ${k.status} → ${b.status}`,config:c});const w=gce(k.subtasks,b.subtasks);c.notifications.subtaskCompletions&&w>0&&P2({title:"Subtask completed",body:w===1?`${b.title}: 1 subtask completed.`:`${b.title}: ${w} subtasks completed.`,config:c}),hce(k,b)&&i(s,b.title),mu.set(s,b)};al.on("configChanged",()=>{try{e().loadConfig(),e().toast("Settings updated externally","info")}catch(s){console.error("[Watcher] configChanged handler error:",s)}}),al.on("taskChanged",async s=>{try{const{drawerTaskId:o,drawerBaseVersion:c,tasksDirHandle:p}=e();if(await r(s),o===s&&c&&p){let d,m;try{({frontmatter:d,body:m}=await Es(p,s))}catch(E){console.warn(`[Watcher] taskChanged: failed to re-read ${s}:`,E);return}const{subtasks:f,bodyWithoutSubtasks:h}=Ds(m),b=c,k=JSON.stringify(b.frontmatter)!==JSON.stringify(d),w=b.body!==h,A=JSON.stringify(b.subtasks)!==JSON.stringify(f);if(!k&&!w&&!A)return;let S="none";k&&(w||A)?S="full":k?S="metadata-only":(w||A)&&(S="body-only"),t({conflictState:{taskId:s,type:S,local:b,remote:{frontmatter:d,body:h,subtasks:f}},showConflictModal:S==="full"})}else await e().reloadBoard()}catch(o){console.error(`[Watcher] taskChanged handler error for ${s}:`,o)}}),al.on("newTaskDetected",async s=>{try{const{tasksDirHandle:o}=e();if(o){let c,p;try{({frontmatter:c,body:p}=await Es(o,s))}catch(f){console.warn(`[Watcher] newTaskDetected: failed to read ${s}:`,f),e().toast(`New task ${s} detected but could not be loaded`,"warning");return}const{subtasks:d,bodyWithoutSubtasks:m}=Ds(p);mu.set(s,h3({id:s,frontmatter:{...c,id:c.id||s,status:c.status||"Backlog"},body:m,subtasks:d}))}await e().reloadBoard()}catch(o){console.error(`[Watcher] newTaskDetected handler error for ${s}:`,o)}}),al.on("watcherError",s=>{t({watcherError:s}),e().toast(s,"warning",1e4)})},restartWatcher:()=>{const{dirHandle:n,tasksDirHandle:a}=e();!n||!a||(t({watcherError:null}),e().setupWatcher(),e().toast("File watcher restarted"))}}));Ly().then(t=>{ue.setState({recentProjects:t})}).catch(t=>{console.warn("[Store] Failed to hydrate recent projects:",t)});rl(Ci);window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",()=>{rl(ue.getState().config)});const vce=Object.freeze(Object.defineProperty({__proto__:null,useStore:ue},Symbol.toStringTag,{value:"Module"}));function yce(){const t=ue(o=>o.config),e=ue(o=>o.updateConfig),[n,a]=$.useState(!1);if($.useEffect(()=>{a(!0)},[]),!n)return null;const i=t.ui.theme==="auto"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t.ui.theme,r=i==="dark",s=()=>{const o=r?"light":"dark";e(c=>({...c,ui:{...c.ui,theme:o}}))};return _.jsx(lt.button,{onClick:s,className:m3("relative inline-flex items-center rounded-full transition-all duration-300","border border-black/[0.08] dark:border-white/[0.12]","bg-black/[0.05] dark:bg-white/[0.08]","h-8 w-[52px] px-1"),title:r?"Switch to light mode":"Switch to dark mode",children:_.jsx(lt.div,{className:m3("inline-flex items-center justify-center rounded-full shadow-md",r?"bg-[#1e293b] border border-white/[0.15]":"bg-black border border-black/20","h-[26px] w-[26px]"),animate:{x:r?22:0},transition:{type:"spring",stiffness:500,damping:30},children:_.jsx(lt.div,{initial:{rotate:-90,scale:.5,opacity:0},animate:{rotate:0,scale:1,opacity:1},transition:{duration:.25,ease:"easeOut"},children:r?_.jsx(Zn.Moon,{size:13,className:"text-sky-300"}):_.jsx(Zn.Sun,{size:13,className:"text-amber-400"})},i)})})}function _ce(t){const e=xse(t,{stiffness:180,damping:22,mass:.8});return $.useEffect(()=>{e.set(t)},[t,e]),bz(e,a=>Math.round(a).toString())}const b3="0.15.1",kce=({className:t})=>_.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 150 150",className:t,fill:"currentColor",children:[_.jsx("path",{d:"m57.6 64.6 0.1-0.1v-31.3c-0.1-3.5-2.7-5.6-5.7-5.6h-16.3v59.6c0.2-1.3 0.9-2.6 1.7-3.2l20.2-19.4z"}),_.jsx("path",{d:"m87.6 43.8c-3.4 0.1-7.1 1.3-9.9 3.7l-38.5 38.7c-2.1 2.1-3.4 4.8-3.5 7.5v26.7l77.5-76.4v-0.2h-25.6z"}),_.jsx("path",{d:"m108.1 96.4-6 5-22.4-20.8-14.6 14.2 21.1 21.4-5 4.1c-0.6 0.5-0.3 0.9 0.2 0.9h27.6c0.4 0 0.7-0.4 0.7-0.6v-24.8c0-0.7-1.1-0.3-1.6 0.3v0.3z"})]});function wce(){const{t}=Cn(),e=ue(I=>I.dirHandle),n=ue(I=>I.isOpen),a=ue(I=>I.projectName),i=ue(I=>I.archivedTasks.length),r=ue(I=>I.showArchives),s=ue(I=>I.setShowArchives),o=ue(I=>I.columns),c=ue(I=>I.openFolder),p=ue(I=>I.reloadBoard),d=ue(I=>I.createTask),m=ue(I=>I.setCommandOpen),f=ue(I=>I.viewMode),h=ue(I=>I.setViewMode),b=ue(I=>I.density),k=ue(I=>I.setDensity),w=ue(I=>I.setCurrentPage),A=ue(I=>I.recentProjects),S=ue(I=>I.openRecentProject),E=ue(I=>I.filters),P=ue(I=>I.setFilter),M=ue(I=>I.clearFilters),j=ue(I=>I.config.fields),z=ue(I=>I.lastReloadError),H=ue(I=>I.watcherError),O=ue(I=>I.restartWatcher),[L,W]=$.useState(!1),[X,te]=$.useState(!0),Z=$.useRef(null),Q=$.useRef(null),q=o.reduce((I,J)=>I+J.tasks.length,0),V=_ce(q),B=[];j.priority&&E.priority&&B.push({type:"priority",label:E.priority,value:E.priority}),j.tags&&E.tag&&B.push({type:"tag",label:"#"+E.tag,value:E.tag}),j.assignee&&E.assignee&&B.push({type:"assignee",label:"@"+E.assignee,value:E.assignee});const ne=[{label:t("filterBar.ownerAll"),value:""},{label:t("filterBar.ownerHuman"),value:"human"},{label:t("filterBar.ownerAI"),value:"ai"}],D=B.length>0||E.search||j.ownerType&&E.ownerType;return $.useEffect(()=>{if(!L)return;const I=J=>{Z.current&&!Z.current.contains(J.target)&&W(!1)};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[L]),$.useEffect(()=>{const I=setTimeout(()=>te(!1),5e3);return()=>clearTimeout(I)},[]),$.useEffect(()=>{document.title=a?`${a} · Kandown`:"Kandown"},[a]),_.jsxs(_.Fragment,{children:[(z||H)&&_.jsxs("div",{className:"flex items-center gap-2 px-5 py-1.5 bg-amber-500/10 border-b border-amber-500/30 text-[12px] text-amber-700 dark:text-amber-300",children:[_.jsx("span",{className:"flex-1 truncate",children:H?`⚠ ${H}`:`⚠ ${z}`}),H&&_.jsx("button",{type:"button",onClick:O,className:"px-2 py-0.5 rounded bg-amber-500/20 hover:bg-amber-500/30 text-[11.5px] font-medium",children:"Restart watcher"}),_.jsx("button",{type:"button",onClick:p,className:"px-2 py-0.5 rounded bg-amber-500/20 hover:bg-amber-500/30 text-[11.5px] font-medium",children:"Reload"})]}),_.jsxs("header",{className:"flex items-center justify-between px-5 h-[64px] border-b border-border bg-card/80 backdrop-blur-xl relative z-10",children:[_.jsxs("div",{className:"flex items-center gap-4 min-w-0",children:[_.jsx("div",{className:"flex items-center gap-2.5 flex-shrink-0",children:_.jsxs("button",{onClick:()=>window.history.pushState({},"",window.location.pathname),className:"flex items-center gap-2 cursor-pointer",children:[_.jsx(kce,{className:"w-[34px] h-[34px] dark:text-white text-black"}),_.jsx(Sr,{mode:"wait",initial:!1,children:X?_.jsxs(lt.span,{className:"flex items-center gap-2",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.45},children:[_.jsx("span",{className:"text-[15px] font-semibold tracking-tight text-fg",children:"kandown"}),_.jsxs("span",{className:"inline-flex items-center h-5 px-1.5 text-[10.5px] font-semibold text-red-600 bg-red-50 dark:text-red-400 dark:bg-red-500/15 rounded-md",children:["v",b3]})]},"boot"):a?_.jsx(lt.span,{className:"text-[15px] font-semibold tracking-tight text-fg truncate max-w-[240px]",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.45},children:a},"project"):null})]})}),e&&_.jsxs(_.Fragment,{children:[_.jsx("div",{className:"w-px h-[20px] bg-black/[0.08] dark:bg-white/[0.08] flex-shrink-0"}),_.jsxs("div",{className:"flex items-center gap-2 px-3 h-9 bg-secondary/60 border border-border rounded-xl min-w-[200px] max-w-[280px] focus-within:border-border-focus focus-within:bg-secondary transition-all",children:[_.jsx(Zn.Search,{size:14,className:"text-fg-muted/60 flex-shrink-0"}),_.jsx("input",{ref:Q,type:"text",placeholder:t("filterBar.searchPlaceholder"),value:E.search,onChange:I=>P("search",I.target.value),className:"bg-transparent border-none outline-none text-fg text-[13px] w-full placeholder:text-fg-muted/60"}),E.search?_.jsx("button",{onClick:()=>P("search",""),className:"text-fg-muted/60 hover:text-fg flex-shrink-0",children:_.jsx(Zn.X,{size:14})}):_.jsx("kbd",{className:"inline-flex items-center h-5 px-1.5 text-[10px] font-medium text-fg-muted/50 bg-black/[0.04] dark:bg-white/[0.08] rounded border border-black/[0.06] dark:border-white/[0.1]",children:"⌘K"})]}),_.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap overflow-hidden",children:[_.jsx(Sr,{children:B.map(I=>_.jsxs(lt.button,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},transition:{duration:.15},onClick:()=>P(I.type,null),className:"inline-flex items-center gap-1 h-6 px-2.5 text-[12px] text-fg bg-black/[0.05] dark:bg-white/[0.1] border border-black/[0.08] dark:border-white/[0.12] rounded-lg hover:bg-black/[0.08] dark:hover:bg-white/[0.15] transition-colors",children:[I.label,_.jsx(Zn.X,{size:10,className:"text-fg-muted/60"})]},I.type+I.value))}),j.ownerType&&_.jsx("div",{className:"flex items-center h-6 border border-black/[0.06] dark:border-white/[0.1] rounded-lg overflow-hidden",children:ne.map(I=>_.jsx("button",{onClick:()=>P("ownerType",I.value),className:`h-full px-2.5 text-[12px] transition-colors ${E.ownerType===I.value?"bg-black/[0.06] dark:bg-white/[0.12] text-fg":"text-fg-muted/70 hover:text-fg"}`,children:I.label},I.value))}),D&&_.jsx("button",{onClick:M,className:"text-[12px] text-fg-muted/60 hover:text-fg transition-colors",children:t("filterBar.clearAll")})]})]}),e&&_.jsxs(_.Fragment,{children:[_.jsx("div",{className:"w-px h-[20px] bg-black/[0.08] dark:bg-white/[0.08] flex-shrink-0"}),_.jsxs("div",{className:"relative flex-shrink-0",ref:Z,children:[_.jsxs("button",{onClick:()=>W(I=>!I),className:"flex items-center gap-1.5 px-2.5 py-1.5 text-[13px] text-fg-muted hover:text-fg hover:bg-black/[0.04] dark:hover:bg-white/[0.06] rounded-lg transition-colors border border-transparent hover:border-black/[0.06] dark:hover:border-white/[0.1]",children:[_.jsx(Zn.Folder,{size:13,className:"text-fg-muted/70"}),_.jsxs("span",{className:"font-medium",children:[".",e.name]}),_.jsx(Zn.ChevronDown,{size:11,className:"opacity-50"})]}),_.jsx(Sr,{children:L&&_.jsx(lt.div,{initial:{opacity:0,y:-4,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.98},transition:{duration:.12},className:"absolute top-full left-0 mt-2 min-w-[240px] glass rounded-xl shadow-[0_16px_48px_rgba(0,0,0,0.5)] overflow-hidden z-50",children:_.jsxs("div",{className:"py-1.5",children:[A.length>0&&_.jsxs(_.Fragment,{children:[_.jsx("div",{className:"px-3 py-1.5 text-[11px] font-semibold uppercase tracking-wider text-fg-muted/60",children:t("header.recentProjects")}),A.map(I=>_.jsxs("button",{onClick:()=>{W(!1),S(I)},className:"w-full flex items-center gap-2 px-3 py-2 text-[13.5px] text-left hover:bg-black/[0.04] dark:hover:bg-white/[0.06] transition-colors",children:[_.jsx(Zn.Folder,{size:12,className:"text-fg-muted/60"}),_.jsx("span",{className:"truncate",children:I.name}),I.id===e.name&&_.jsx(Zn.Check,{size:12,className:"ml-auto text-emerald-500"})]},I.id)),_.jsx("div",{className:"h-px bg-black/[0.06] dark:bg-white/[0.08] my-1.5 mx-2"})]}),_.jsxs("button",{onClick:()=>{W(!1),c()},className:"w-full flex items-center gap-2 px-3 py-2 text-[13.5px] text-left hover:bg-black/[0.04] dark:hover:bg-white/[0.06] transition-colors",children:[_.jsx(Zn.Plus,{size:12,className:"text-fg-muted/60"}),_.jsx("span",{children:t("header.openFolder...")})]})]})})})]})]})]}),_.jsx("div",{className:"flex items-center gap-2 flex-shrink-0",children:n||e?_.jsxs(_.Fragment,{children:[_.jsxs("div",{className:"flex items-center gap-2 mr-2 text-[12.5px] text-fg-muted/70",children:[_.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-emerald-500"}),_.jsx(lt.span,{className:"tabular-nums font-medium",children:V}),_.jsx("span",{children:t("header.tasks")})]}),_.jsxs("div",{className:"flex items-center bg-black/[0.04] dark:bg-white/[0.06] border border-black/[0.06] dark:border-white/[0.1] rounded-xl p-0.5 h-10",children:[_.jsx("button",{onClick:()=>h("board"),className:`w-9 h-9 inline-flex items-center justify-center rounded-lg transition-all ${f==="board"?"bg-card text-fg shadow-sm":"text-fg-muted/70 hover:text-fg"}`,title:t("common.board"),children:_.jsx(Zn.LayoutBoard,{size:18})}),_.jsx("button",{onClick:()=>h("list"),className:`w-9 h-9 inline-flex items-center justify-center rounded-lg transition-all ${f==="list"?"bg-card text-fg shadow-sm":"text-fg-muted/70 hover:text-fg"}`,title:t("common.list"),children:_.jsx(Zn.LayoutList,{size:18})})]}),_.jsx(na,{variant:"icon",icon:"Archive",onClick:()=>s(!r),title:r?t("header.backToBoard"):`${t("header.archives")} (${i})`,className:r?"text-accent":""}),_.jsx(na,{variant:"icon",icon:"Density",onClick:()=>k(b==="compact"?"comfortable":"compact"),title:`Density: ${b}`}),_.jsx(na,{variant:"icon",icon:"Settings",onClick:()=>w("settings"),title:t("common.settings")}),_.jsx(yce,{}),_.jsx("div",{className:"w-px h-5 bg-black/[0.08] dark:bg-white/[0.08] mx-1"}),_.jsx(na,{variant:"secondary",icon:"Search",label:t("common.search"),shortcut:"⌘K",onClick:()=>m(!0),title:"Command palette (⌘K)"}),_.jsx(na,{variant:"icon",icon:"Refresh",onClick:p,title:`${t("common.reload")} (R)`}),_.jsx(na,{variant:"primary",icon:"Plus",label:t("common.newTask"),shortcut:"N",onClick:()=>d()})]}):_.jsx(na,{variant:"primary",label:t("common.openFolder"),onClick:c})})]})]})}/**
|
|
116
|
+
`}}async function Hz(t,e){try{return await(await(await(await t.getDirectoryHandle("archive",{create:!1})).getFileHandle(`${e}.md`)).getFile()).text()}catch{return null}}async function Yoe(t,e){try{return await(await t.getDirectoryHandle("archive",{create:!1})).getFileHandle(`${e}.md`),!0}catch{return!1}}async function Bz(t,e){try{return await t.getDirectoryHandle("archive",{create:e})}catch{return null}}async function Xoe(t){if(Kt())return Q4();const e=new Set;for await(const n of t.values())n.kind==="file"&&n.name.endsWith(".md")&&e.add(n.name.slice(0,-3));try{const n=await t.getDirectoryHandle("archive",{create:!1});for await(const a of n.values())a.kind==="file"&&a.name.endsWith(".md")&&e.add(a.name.slice(0,-3))}catch{}return[...e].sort((n,a)=>n.localeCompare(a,void 0,{numeric:!0}))}async function Es(t,e){if(Kt())try{const i=await J4(e);return Ig(i)}catch{return hj(e)}const a=await(async i=>{try{return await(await(await i.getFileHandle(`${e}.md`)).getFile()).text()}catch{return null}})(t)??await Hz(t,e);return a!==null?Ig(a):hj(e)}async function Qoe(t,e){if(Kt())try{const a=await J4(e);return{ok:!0,task:Ig(a)}}catch(a){return a.name==="NotFoundError"?{ok:!1,reason:"not-found"}:{ok:!1,reason:"unknown",error:a}}let n=null;try{n=await(await(await t.getFileHandle(`${e}.md`)).getFile()).text()}catch{}if(n===null)try{n=await Hz(t,e)}catch(a){return{ok:!1,reason:"unknown",error:a}}if(n===null)return{ok:!1,reason:"not-found"};if(n.trim()==="")return{ok:!1,reason:"corrupted",error:new Error(`Task file ${e}.md is empty`)};try{return{ok:!0,task:Ig(n)}}catch(a){return{ok:!1,reason:"corrupted",error:a}}}async function au(t,e,n,a){const i=Y4(n,a);if(Kt())return Boe(e,i);try{const o=await(await(await Yoe(t,e)?await Bz(t,!0):t).getFileHandle(`${e}.md`,{create:!0})).createWritable();try{await o.write(i)}finally{await o.close()}}catch(r){throw ek(r,`${e}.md`)}}async function bj(t,e){if(Kt())return qoe(e);try{await t.removeEntry(`${e}.md`)}catch{}try{await(await t.getDirectoryHandle("archive",{create:!1})).removeEntry(`${e}.md`)}catch{}}async function Joe(t,e){await hs(`/api/tasks/${encodeURIComponent(t)}/archive`,{method:"POST",body:e,headers:{"Content-Type":"text/plain"}})}async function ece(t,e){await hs(`/api/tasks/${encodeURIComponent(t)}/unarchive`,{method:"POST",body:e,headers:{"Content-Type":"text/plain"}})}async function tce(t,e,n,a){const i=Y4(n,a);if(Kt())return Joe(e,i);try{const o=await(await(await Bz(t,!0)).getFileHandle(`${e}.md`,{create:!0})).createWritable();try{await o.write(i)}finally{await o.close()}try{await t.removeEntry(`${e}.md`)}catch{}}catch(r){throw ek(r,`archive/${e}.md`)}}async function nce(t,e,n,a){const i=Y4(n,a);if(Kt())return ece(e,i);try{const s=await(await t.getFileHandle(`${e}.md`,{create:!0})).createWritable();try{await s.write(i)}finally{await s.close()}try{await(await t.getDirectoryHandle("archive",{create:!1})).removeEntry(`${e}.md`)}catch{}}catch(r){throw ek(r,`${e}.md`)}}const ace="kanban-md",ice=1,ap="recentProjects";function eS(){return new Promise((t,e)=>{const n=indexedDB.open(ace,ice);n.onerror=()=>e(n.error),n.onsuccess=()=>t(n.result),n.onupgradeneeded=()=>{const a=n.result;a.objectStoreNames.contains(ap)||a.createObjectStore(ap,{keyPath:"id"})}})}async function E2(t){const e=await eS();return new Promise((n,a)=>{const i=e.transaction(ap,"readwrite");i.objectStore(ap).put(t),i.oncomplete=()=>n(),i.onerror=()=>a(i.error)})}async function Ly(){const t=await eS();return new Promise((e,n)=>{const i=t.transaction(ap,"readonly").objectStore(ap).getAll();i.onsuccess=()=>{const r=i.result||[];r.sort((s,o)=>o.lastOpened-s.lastOpened),e(r.slice(0,10))},i.onerror=()=>n(i.error)})}async function rce(t){const e=await eS();return new Promise((n,a)=>{const i=e.transaction(ap,"readwrite");i.objectStore(ap).delete(t),i.oncomplete=()=>n(),i.onerror=()=>a(i.error)})}async function vj(t,e=!0){const n={mode:e?"readwrite":"read"};try{return await t.queryPermission(n)==="granted"||await t.requestPermission(n)==="granted"}catch(a){return console.warn("[FS] verifyPermission: handle is no longer valid:",a),!1}}function qz(t=Ci){const e=t.board.columns;return e[e.length-1]??"Done"}function sce(t,e=Ci){return t===qz(e)||t.toLowerCase()==="archived"}class oce{dirHandle=null;tasksDirHandle=null;intervalId=null;configHash=null;taskHashes=new Map;knownTaskIds=new Set;listeners=new Map;debounceTimers=new Map;debounceDelay=150;consecutiveErrors=0;maxConsecutiveErrors=5;disabled=!1;start(e,n){this.dirHandle=e,this.tasksDirHandle=n,this.consecutiveErrors=0,this.disabled=!1,this.initHashes(),this.intervalId=setInterval(()=>void this.tick(),300)}stop(){this.intervalId&&(clearInterval(this.intervalId),this.intervalId=null),this.configHash=null,this.taskHashes.clear(),this.knownTaskIds.clear(),this.listeners.clear(),this.debounceTimers.forEach(e=>clearTimeout(e)),this.debounceTimers.clear(),this.consecutiveErrors=0,this.disabled=!1}isDisabled(){return this.disabled}on(e,n){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(n),()=>{this.listeners.get(e)?.delete(n)}}getKnownTaskIds(){return Array.from(this.knownTaskIds)}async initHashes(){if(!(!this.dirHandle||!this.tasksDirHandle))try{const e=await yj(this.dirHandle);e!==null&&(this.configHash=await this.hash(e)),await this.syncTaskDir(!1)}catch(e){console.warn("[Watcher] initHashes error:",e)}}async tick(){if(!(!this.dirHandle||!this.tasksDirHandle)&&!this.disabled)try{const e=await yj(this.dirHandle);if(e!==null){const n=await this.hash(e);this.configHash!==null&&n!==this.configHash&&(this.configHash=n,this.debouncedEmit("configChanged"))}for(const n of[...this.knownTaskIds])try{const a=await _j(this.tasksDirHandle,n);if(a!==null){const i=await this.hash(a),r=this.taskHashes.get(n);r!==void 0&&i!==r&&(this.taskHashes.set(n,i),this.debouncedEmit("taskChanged",n))}}catch(a){console.warn(`[Watcher] Error reading task ${n}:`,a)}await this.syncTaskDir(!0),this.consecutiveErrors=0}catch(e){this.consecutiveErrors++,console.error(`[Watcher] Tick failed (${this.consecutiveErrors}/${this.maxConsecutiveErrors}):`,e),this.consecutiveErrors>=this.maxConsecutiveErrors&&this.disable(`File watcher stopped after ${this.maxConsecutiveErrors} consecutive errors: ${e.message}`)}}disable(e){this.intervalId&&(clearInterval(this.intervalId),this.intervalId=null),this.disabled=!0,this.emit("watcherError",e)}debouncedEmit(e,...n){const a=e+JSON.stringify(n),i=this.debounceTimers.get(a);i&&clearTimeout(i);const r=setTimeout(()=>{this.debounceTimers.delete(a),this.emit(e,...n)},this.debounceDelay);this.debounceTimers.set(a,r)}async syncTaskDir(e){if(!this.tasksDirHandle)return;let n;try{n=this.tasksDirHandle.values()}catch(a){throw a}for await(const a of n){if(a.kind!=="file"||!a.name.endsWith(".md"))continue;const i=a.name.replace(".md","");if(!this.knownTaskIds.has(i))try{this.knownTaskIds.add(i);const r=await _j(this.tasksDirHandle,i);r!==null&&(this.taskHashes.set(i,await this.hash(r)),e&&this.debouncedEmit("newTaskDetected",i))}catch(r){console.warn(`[Watcher] syncTaskDir: failed to read ${i}:`,r)}}}async hash(e){const a=new TextEncoder().encode(e),i=await crypto.subtle.digest("SHA-256",a);return Array.from(new Uint8Array(i)).map(s=>s.toString(16).padStart(2,"0")).join("")}emit(e,...n){this.listeners.get(e)?.forEach(i=>{if(e==="configChanged"){i();return}if(e==="taskChanged"){const[s]=n;i(s);return}if(e==="newTaskDetected"){const[s]=n;i(s);return}const[r]=n;i(r)})}}async function yj(t){try{return await(await(await t.getFileHandle("kandown.json")).getFile()).text()}catch{return null}}async function _j(t,e){try{return await(await(await t.getFileHandle(`${e}.md`)).getFile()).text()}catch{return null}}const al=new oce,cce={soft:[{frequency:520,durationMs:90,delayMs:0,type:"sine"},{frequency:720,durationMs:120,delayMs:95,type:"sine"}],chime:[{frequency:660,durationMs:120,delayMs:0,type:"triangle"},{frequency:880,durationMs:160,delayMs:125,type:"triangle"}],ping:[{frequency:920,durationMs:110,delayMs:0,type:"sine"}],pop:[{frequency:260,durationMs:55,delayMs:0,type:"square"},{frequency:520,durationMs:80,delayMs:60,type:"square"}]};let kj=null;function Uz(){return"Notification"in window?Notification.permission:"unsupported"}async function pce(){return"Notification"in window?await Notification.requestPermission():"unsupported"}function P2({title:t,body:e,config:n}){if(n.notifications.sound&&lce(n.notifications.soundId),!(!n.notifications.browser||Uz()!=="granted"))try{new Notification(t,{body:e})}catch{}}function lce(t){const e=cce[t],n=window.AudioContext??window.webkitAudioContext;if(!(!n||e.length===0))try{kj??=new n;const a=kj;a.state==="suspended"&&a.resume();const i=a.currentTime+.01;e.forEach(r=>{const s=a.createOscillator(),o=a.createGain(),c=i+r.delayMs/1e3,p=c+r.durationMs/1e3;s.type=r.type??"sine",s.frequency.setValueAtTime(r.frequency,c),o.gain.setValueAtTime(1e-4,c),o.gain.exponentialRampToValueAtTime(.08,c+.01),o.gain.exponentialRampToValueAtTime(1e-4,p),s.connect(o),o.connect(a.destination),s.start(c),s.stop(p+.02)})}catch{}}async function Tf(t,e={}){const{maxAttempts:n=3,baseDelayMs:a=500,retryableCheck:i=Foe}=e;let r;for(let s=1;s<=n;s++)try{return await t()}catch(o){if(r=o,!i(o))throw o;if(s<n){const c=a*Math.pow(2,s-1);await new Promise(p=>setTimeout(p,c))}}throw r}function dce(t){let e=-1;for(const n of t)for(const a of n.tasks){const i=a.id.match(/^t(\d+)$/);if(i){const r=parseInt(i[1],10);r>e&&(e=r)}}return"t"+(e+1)}async function uce(){const t=await Q4();return await Promise.all(t.map(async n=>{const{frontmatter:a,body:i}=await zz(n),r={...a,id:a.id||n,status:a.status||"Backlog"},{subtasks:s,bodyWithoutSubtasks:o}=Ds(i);return{id:n,frontmatter:r,body:o,subtasks:s}}))}async function mce(t){const e=await Xoe(t),n=await Promise.all(e.map(async r=>{const s=await Qoe(t,r);return{id:r,result:s}})),a=[],i=[];for(const{id:r,result:s}of n)if(s.ok){const o={...s.task.frontmatter,id:s.task.frontmatter.id||r,status:s.task.frontmatter.status||"Backlog"},{subtasks:c,bodyWithoutSubtasks:p}=Ds(s.task.body);a.push({id:r,frontmatter:o,body:p,subtasks:c})}else{if(s.reason==="not-found")continue;i.push(r)}return{tasks:a,failedIds:i}}async function wj(t,e,n){const a=[];for(const s of e){const o=s.name;s.tasks.forEach((c,p)=>{const d=(async()=>{const{frontmatter:m,body:f}=await Es(t,c.id);await au(t,c.id,{...m,id:c.id,status:o,order:p},f)})();a.push({id:c.id,promise:d})})}const i=await Promise.allSettled(a.map(s=>s.promise)),r=[];return i.forEach((s,o)=>{s.status==="rejected"&&r.push(a[o].id)}),{failedIds:r}}function rl(t){Roe(t.ui.theme,t.ui.skin,t.ui.font,t.ui.background)}function h3(t){return{title:t.frontmatter.title||t.id,status:t.frontmatter.status||"Backlog",body:t.body,subtasks:t.subtasks}}function T2(t){mu.clear(),t.forEach(e=>{mu.set(e.id,h3(e))})}function fce(t){const e=t.split(/[\\/]+/).filter(Boolean),n=e[e.length-1];return n===".kandown"?e[e.length-2]??"Project":n??"Project"}function gce(t,e){return e.reduce((n,a,i)=>{const r=t[i]?.done??!1;return n+(a.done&&!r?1:0)},0)}function hce(t,e){const n=t.subtasks.map(i=>({text:i.text,description:i.description??"",report:i.report??""})),a=e.subtasks.map(i=>({text:i.text,description:i.description??"",report:i.report??""}));return t.title!==e.title||t.body!==e.body||JSON.stringify(n)!==JSON.stringify(a)}let bce=0;const mu=new Map,Mf=new Map;let M2=null;const ue=$oe((t,e)=>({isOpen:!1,loading:!1,dirHandle:null,projectName:null,tasksDirHandle:null,boardTitle:"Project Kanban",columns:[],archivedTasks:[],showArchives:!1,showMetadata:!0,taskContents:new Map,searchMatches:new Map,viewMode:localStorage.getItem("kandown:view")||"board",density:localStorage.getItem("kandown:density")||"comfortable",filters:{search:"",priority:null,tag:null,assignee:null,ownerType:null},commandOpen:!1,cheatsheetOpen:!1,drawerTaskId:null,drawerData:null,currentPage:"board",config:Ci,recentProjects:[],toasts:[],agentHook:null,isReloading:!1,lastReloadError:null,failedTaskIds:[],watcherError:null,hasUnsavedDrawerEdits:!1,lastSaveError:null,drawerRecoveryData:new Map,drawerBaseVersion:null,conflictState:null,showConflictModal:!1,openFolder:async()=>{if(!Oz()){const c=navigator.userAgent||"this browser";e().toast(new Ooe(c).message,"error",8e3);return}let n;try{n=await Goe()}catch(c){c instanceof X4?e().toast("Permission denied — please grant access to the project folder","error"):e().toast("Failed to open folder: "+c.message,"error");return}if(!n)return;const{projectHandle:a,kandownHandle:i,tasksHandle:r}=n,s=a.name;t({dirHandle:i,tasksDirHandle:r,projectName:s}),window.history.pushState({},"",`?p=${encodeURIComponent(s)}`);const o=Kt()?$2():null;try{await E2({id:a.name,name:a.name,handle:a,lastOpened:Date.now(),...o?{kandownDir:o}:{}})}catch(c){console.warn("[Store] Failed to save recent project:",c)}await e().loadConfig(),await e().reloadBoard();try{const c=await Ly();t({recentProjects:c})}catch(c){console.warn("[Store] Failed to load recent projects:",c)}e().setupWatcher()},openRecentProject:async n=>{const a={dirHandle:e().dirHandle,tasksDirHandle:e().tasksDirHandle,projectName:e().projectName};if(!await vj(n.handle,!0)){let r=!1;try{await My(n.handle),r=!0}catch{r=!1}if(!r){e().toast(`"${n.name}" is no longer accessible. Removed from recent projects.`,"warning",8e3);try{await rce(n.id);const s=await Ly();t({recentProjects:s})}catch{}return}e().toast("Permission denied — please grant access to the folder","error");return}try{const r=await My(n.handle),s=await g3(n.handle),o=n.handle.name;t({dirHandle:r,tasksDirHandle:s,projectName:o}),window.history.pushState({},"",`?p=${encodeURIComponent(o)}`);try{await E2({...n,lastOpened:Date.now()})}catch(c){console.warn("[Store] Failed to update recent project:",c)}await e().loadConfig(),await e().reloadBoard(),e().setupWatcher()}catch(r){t(a),e().toast(`Failed to open project: ${r.message}`,"error")}},openServerProject:async()=>{t({loading:!0});try{const n=$2();if(!n)throw new Error("No server root");await gj();const a=fce(n),i=await Fz();rl(i);const r=await Q4(),s=await Promise.all(r.map(async f=>{const{frontmatter:h,body:b}=await zz(f),k={...h,id:h.id||f,status:h.status||"Backlog"},{subtasks:w,bodyWithoutSubtasks:A}=Ds(b);return{id:f,frontmatter:k,body:A,subtasks:w}}));T2(s);const o=s.map(f=>({frontmatter:f.frontmatter,body:qd(f.body,f.subtasks)})),c=N2(o,i.board.columns),p=S2(o),d=c.reduce((f,h)=>f+h.tasks.length,0),m=new Map;if(d<=10)for(const f of s)m.set(f.frontmatter.id,{frontmatter:f.frontmatter,subtasks:f.subtasks,body:f.body});t({loading:!1,isOpen:!0,config:i,columns:c,archivedTasks:p,boardTitle:"Project Kanban",projectName:a,taskContents:m,searchMatches:new Map}),window.history.pushState({},"",`?p=${encodeURIComponent(a)}`),e().setupWatcher(),e().refreshAgentHook()}catch{t({loading:!1,isOpen:!1}),e().toast("Impossible de charger le projet. Relancez `kandown`.","error")}},tryAutoOpenServerProject:async()=>{if(!Kt())return;const n=$2();if(!n)return;await gj();const a=await Ly(),i=a.find(p=>p.kandownDir===n);if(!i){await e().openServerProject();return}if(!await vj(i.handle,!0)){await e().openServerProject();return}const s=await My(i.handle),o=await g3(i.handle),c=i.handle.name;t({dirHandle:s,tasksDirHandle:o,projectName:c,recentProjects:a,isOpen:!0}),window.history.pushState({},"",`?p=${encodeURIComponent(c)}`),await E2({...i,lastOpened:Date.now()}),await e().loadConfig(),await e().reloadBoard(),e().setupWatcher()},loadConfig:async()=>{const{dirHandle:n}=e();if(!(!n&&!Kt()))try{const a=await Woe(n);if(a.ok){t({config:a.config}),rl(a.config);return}if(a.reason==="corrupted"){if(a.rawContent&&n)try{const r=await(await n.getFileHandle("kandown.json.backup",{create:!0})).createWritable();try{await r.write(a.rawContent)}finally{await r.close()}}catch{}e().toast("kandown.json is corrupted — using default settings. A backup was saved as kandown.json.backup.","warning",1e4)}t({config:Ci}),rl(Ci)}catch{t({config:Ci}),rl(Ci)}},updateConfig:async n=>{const{dirHandle:a,config:i}=e();if(!a&&!Kt())return;const r=n(i);t({config:r}),rl(r);try{await Koe(a,r)}catch(s){const o=s;o instanceof $o?e().toast("Disk is full — settings were not saved.","error",8e3):e().toast("Failed to save config: "+o.message,"error")}},reloadBoard:async()=>{const{tasksDirHandle:n,config:a}=e();t({isReloading:!0,lastReloadError:null});try{if(Kt()){const i=await uce();T2(i);const r=i.map(d=>({frontmatter:d.frontmatter,body:qd(d.body,d.subtasks)})),s=N2(r,a.board.columns),o=S2(r);t({boardTitle:"Project Kanban",columns:s,archivedTasks:o});const c=s.reduce((d,m)=>d+m.tasks.length,0),p=new Map;if(c<=10)for(const d of i)p.set(d.frontmatter.id,{frontmatter:d.frontmatter,subtasks:d.subtasks,body:d.body});t({taskContents:p,searchMatches:new Map,failedTaskIds:[],isReloading:!1})}else if(n){const{tasks:i,failedIds:r}=await mce(n);T2(i);const s=i.map(m=>({frontmatter:m.frontmatter,body:qd(m.body,m.subtasks)})),o=N2(s,a.board.columns),c=S2(s);t({boardTitle:"Project Kanban",columns:o,archivedTasks:c});const p=o.reduce((m,f)=>m+f.tasks.length,0),d=new Map;if(p<=10)for(const m of i)d.set(m.frontmatter.id,{frontmatter:m.frontmatter,subtasks:m.subtasks,body:m.body});if(r.length>0){const m=r.length===1?`Task ${r[0]} could not be loaded`:`${r.length} tasks could not be loaded`;e().toast(m,"warning",8e3)}t({taskContents:d,searchMatches:new Map,failedTaskIds:r,isReloading:!1})}else t({isReloading:!1})}catch(i){const r=i.message||String(i);t({isReloading:!1,lastReloadError:`Failed to reload board: ${r}`}),e().toast(`Board reload failed — showing last loaded state (${r})`,"warning",8e3)}},moveTask:async(n,a,i,r)=>{const{columns:s,config:o,taskContents:c,searchMatches:p}=e(),d=Kt();if(!d&&!e().tasksDirHandle)return;const m=s.find(E=>E.name===a),f=s.find(E=>E.name===i);if(!m||!f)return;const h=m.tasks.findIndex(E=>E.id===n);if(h===-1)return;const b=m.tasks[h];if(!b)return;if(sce(i,o)){const E=new Map,P=qz(o).toLowerCase();for(const j of s)for(const z of j.tasks){const H=z.frontmatter&&(z.frontmatter.archived===!0||z.frontmatter.archived==="true");E.set(z.id,{exists:!0,resolved:H||z.id===n||j.name.toLowerCase()===P})}const M=[];for(const j of b.dependsOn){if(typeof j!="string"||!j.trim()||j===n)continue;const z=E.get(j);(!z||!z.resolved)&&M.push(j)}if(M.length>0){const j=M.length===1?M[0]:`${M.slice(0,-1).join(", ")} and ${M[M.length-1]}`;e().toast(`Cannot move ${n} to ${i}: blocked by ${j}`,"error");return}}const k=s.map(E=>({...E,tasks:[...E.tasks]})),w=k.find(E=>E.name===a),A=k.find(E=>E.name===i),[S]=w.tasks.splice(h,1);/done|termin|closed|complet/i.test(i)?S.checked=!0:S.checked=!1,r!==void 0?A.tasks.splice(r,0,S):A.tasks.push(S),t({columns:k});try{const{tasksDirHandle:E}=e();if(!E&&!d)return;const P=a===i?k.filter(j=>j.name===i):k.filter(j=>j.name===a||j.name===i),{failedIds:M}=await Tf(()=>wj(E??null,P,o.board.columns),{maxAttempts:3});if(M.length>0){const j=M.length===1?`Could not save move for ${M[0]}`:`${M.length} tasks could not be moved`;e().toast(j,"warning",8e3),await e().reloadBoard()}}catch(E){const P=E;P instanceof $o?e().toast("Disk is full — move was not saved. Free up space and try again.","error",8e3):e().toast("Failed to save: "+P.message,"error"),t({columns:s,taskContents:c,searchMatches:p})}},reorderInColumn:async(n,a,i)=>{const{columns:r,tasksDirHandle:s,config:o,taskContents:c,searchMatches:p}=e();if(!s&&!Kt())return;const d=r.map(h=>({...h,tasks:[...h.tasks]})),m=d.find(h=>h.name===n);if(!m)return;const[f]=m.tasks.splice(a,1);m.tasks.splice(i,0,f),t({columns:d});try{const{tasksDirHandle:h}=e(),b=Kt();if(!h&&!b)return;const{failedIds:k}=await Tf(()=>wj(h??null,[m],o.board.columns),{maxAttempts:3});k.length>0&&(e().toast(`Could not save reorder for ${k.length} task(s)`,"warning",8e3),await e().reloadBoard())}catch(h){const b=h;b instanceof $o?e().toast("Disk is full — reorder was not saved.","error",8e3):e().toast("Failed to save: "+b.message,"error"),t({columns:r,taskContents:c,searchMatches:p})}},addColumn:async n=>{const a=n.trim();if(!a)return;const{config:i}=e();i.board.columns.some(r=>r.toLowerCase()===a.toLowerCase())||(await e().updateConfig(r=>({...r,board:{...r.board,columns:[...r.board.columns,a]}})),await e().reloadBoard())},renameColumn:async(n,a)=>{const i=a.trim(),{columns:r,tasksDirHandle:s,config:o}=e();if(!s||!i||i.toLowerCase()===n.toLowerCase())return;if(r.some(d=>d.name.toLowerCase()===i.toLowerCase())){e().toast("Column already exists","error");return}const c=r,p=r.map(d=>d.name===n?{...d,name:i}:d);t({columns:p});try{const d=c.find(m=>m.name===n);if(d){const f=(await Promise.allSettled(d.tasks.map(async(h,b)=>{const{frontmatter:k,body:w}=await Es(s,h.id);await au(s,h.id,{...k,id:h.id,status:i,order:b},w)}))).filter(h=>h.status==="rejected").length;f>0&&e().toast(`${f} task(s) could not be renamed`,"warning",8e3)}await e().updateConfig(m=>{const f={...m.board.columnColors??{}},h=f[n.toLowerCase()];h&&(f[i.toLowerCase()]=h,delete f[n.toLowerCase()]);const b=m.board.columns.some(k=>k.toLowerCase()===n.toLowerCase())?m.board.columns:[...m.board.columns,n];return{...m,board:{...m.board,columns:b.map(k=>k.toLowerCase()===n.toLowerCase()?i:k),columnColors:f}}}),await e().reloadBoard()}catch(d){e().toast("Failed to rename column: "+d.message,"error"),t({columns:c})}},deleteColumn:async n=>{const{columns:a,tasksDirHandle:i}=e();if(!i&&!Kt())return;const r=a.find(o=>o.name===n);if(!r)return;const s=a;t({columns:a.filter(o=>o.name!==n)});try{const c=(await Promise.allSettled(r.tasks.map(p=>bj(i,p.id)))).filter(p=>p.status==="rejected").length;c>0&&e().toast(`${c} task(s) could not be deleted`,"warning",8e3),await e().updateConfig(p=>{const d={...p.board.columnColors??{}};return delete d[n.toLowerCase()],{...p,board:{...p.board,columns:p.board.columns.filter(m=>m.toLowerCase()!==n.toLowerCase()),columnColors:d}}}),await e().reloadBoard(),e().toast("Column deleted")}catch(o){e().toast("Failed to delete column: "+o.message,"error"),t({columns:s})}},createTask:async n=>{const{columns:a,tasksDirHandle:i,config:r,taskContents:s,searchMatches:o}=e();if(!i&&!Kt()||!a.length)return null;const c=n||r.board.columns[0]||a[0].name,p=dce(a),d=a.find(w=>w.name===c)?.tasks.length??0,m={id:p,title:"",checked:!1,dependsOn:[],tags:[],assignee:null,priority:r.fields.priority?r.board.defaultPriority:null,ownerType:r.fields.ownerType?r.board.defaultOwnerType:"",progress:null,frontmatter:{}},f=a.map(w=>w.name===c?{...w,tasks:[...w.tasks,m]}:w),h=new Map(s),b={id:p,title:"",status:c,order:d,priority:r.fields.priority?r.board.defaultPriority:"",tags:[],assignee:"",created:new Date().toISOString().slice(0,10),ownerType:r.fields.ownerType?r.board.defaultOwnerType:"",tools:""},k="";h.set(p,{frontmatter:b,subtasks:[],body:k}),t({columns:f,taskContents:h});try{const w=i||null;return await Tf(()=>au(w,p,b,k),{maxAttempts:3}),e().toast(`Created ${p.replace(/^t/,"")}`),await e().openDrawer(p),p}catch(w){const A=w;return A instanceof $o?e().toast("Disk is full — task was not created.","error",8e3):e().toast("Failed to create: "+A.message,"error"),t({columns:a,taskContents:s,searchMatches:o}),null}},deleteTask:async n=>{const{columns:a,tasksDirHandle:i,taskContents:r,searchMatches:s}=e();if(!i&&!Kt())return;const o=a.map(d=>({...d,tasks:d.tasks.filter(m=>m.id!==n)}));t({columns:o});const c=new Map(r);c.delete(n);const p=new Map(s);p.delete(n),t({taskContents:c,searchMatches:p});try{await bj(i||null,n),e().toast("Deleted")}catch(d){const m=d;e().toast("Failed to delete: "+m.message,"error"),t({columns:a,taskContents:r,searchMatches:s})}},archiveTask:async n=>{const{tasksDirHandle:a}=e();if(!(!a&&!Kt()))try{const{frontmatter:i,body:r}=await Es(a||null,n);await tce(a||null,n,{...i,archived:!0},r),e().drawerTaskId===n&&e().closeDrawer(),await e().reloadBoard(),e().toast("Archived")}catch(i){const r=i;r instanceof $o?e().toast("Disk is full — task was not archived.","error",8e3):e().toast("Failed to archive: "+r.message,"error")}},unarchiveTask:async n=>{const{tasksDirHandle:a}=e();if(!(!a&&!Kt()))try{const{frontmatter:i,body:r}=await Es(a||null,n),s={...i};delete s.archived,await nce(a||null,n,s,r),await e().reloadBoard(),e().toast("Restored")}catch(i){const r=i;r instanceof $o?e().toast("Disk is full — task was not restored.","error",8e3):e().toast("Failed to restore: "+r.message,"error")}},setShowArchives:n=>t({showArchives:n}),setShowMetadata:n=>t({showMetadata:n}),openDrawer:async n=>{const{tasksDirHandle:a}=e();if(!(!a&&!Kt()))try{const{frontmatter:i,body:r}=await Es(a,n),{subtasks:s,bodyWithoutSubtasks:o}=Ds(r),c={frontmatter:i,subtasks:s,body:o,savedAt:Date.now()},p=e().drawerRecoveryData.get(n),d=p?{frontmatter:p.frontmatter,subtasks:p.subtasks,body:p.body}:{frontmatter:i,subtasks:s,body:o},m=new Map(e().drawerRecoveryData);m.delete(n),t({drawerTaskId:n,drawerData:d,drawerBaseVersion:c,conflictState:null,showConflictModal:!1,hasUnsavedDrawerEdits:!!p,lastSaveError:null,drawerRecoveryData:m}),p&&e().toast("Restored your unsaved edits for this task","info")}catch(i){e().toast("Failed to open: "+i.message,"error")}},closeDrawer:()=>t({drawerTaskId:null,drawerData:null,drawerBaseVersion:null,conflictState:null,showConflictModal:!1,hasUnsavedDrawerEdits:!1,lastSaveError:null}),markDrawerDirty:()=>t({hasUnsavedDrawerEdits:!0}),forceCloseDrawer:()=>{const{drawerTaskId:n,drawerData:a}=e();if(n&&a){const i=new Map(e().drawerRecoveryData);i.set(n,{frontmatter:a.frontmatter,subtasks:a.subtasks,body:a.body}),t({drawerRecoveryData:i})}e().closeDrawer()},updateDrawerData:n=>{const{drawerData:a}=e();a&&t({drawerData:n(a)})},saveDrawer:async()=>{const{drawerTaskId:n,drawerData:a,tasksDirHandle:i,taskContents:r}=e();if(!n||!a)return;const s=qd(a.body,a.subtasks),o={...a.frontmatter,id:n};try{await Tf(()=>au(i||null,n,o,s),{maxAttempts:3}),e().toast("Saved");const c=new Map(e().drawerRecoveryData);c.delete(n),t({drawerTaskId:null,drawerData:null,hasUnsavedDrawerEdits:!1,lastSaveError:null,drawerRecoveryData:c});const p=new Map(r);p.set(n,{frontmatter:o,subtasks:a.subtasks,body:a.body}),t({taskContents:p}),await e().reloadBoard()}catch(c){const p=c,d=p instanceof $o?"Disk is full — your edits are kept. Free up space and retry.":"Failed to save: "+p.message;e().toast(d,"error",8e3),t({lastSaveError:d})}},saveDrawerMetadata:async()=>{const{drawerTaskId:n,drawerData:a,tasksDirHandle:i,taskContents:r}=e();if(!(!n||!a))try{const s=qd(a.body,a.subtasks),o={...a.frontmatter,id:n};await Tf(()=>au(i||null,n,o,s),{maxAttempts:3});const c=new Map(r);c.set(n,{frontmatter:o,subtasks:a.subtasks,body:a.body}),t({taskContents:c,hasUnsavedDrawerEdits:!1,lastSaveError:null}),await e().reloadBoard()}catch(s){const o=s,c=o instanceof $o?"Disk is full — your edits are kept.":"Failed to save: "+o.message;t({hasUnsavedDrawerEdits:!0,lastSaveError:c})}},setViewMode:n=>{localStorage.setItem("kandown:view",n),t({viewMode:n})},setDensity:n=>{localStorage.setItem("kandown:density",n),t({density:n})},setFilter:(n,a)=>{if(t(i=>({filters:{...i.filters,[n]:a}})),n==="search"){const{columns:i,tasksDirHandle:r,taskContents:s}=e(),o=a,c=i.flatMap(p=>p.tasks.map(d=>d.id));if(r){const p=c.filter(d=>!s.has(d));p.length>0?e().loadTaskContents(p).then(()=>{e().computeSearchMatches(o)}):e().computeSearchMatches(o)}}},clearFilters:()=>t({filters:{search:"",priority:null,tag:null,assignee:null,ownerType:null},searchMatches:new Map}),setCommandOpen:n=>t({commandOpen:n}),setCheatsheetOpen:n=>t({cheatsheetOpen:n}),refreshAgentHook:async()=>{if(!Kt()){t({agentHook:null});return}const n=await Uoe();t({agentHook:n?.agentHook??null})},sendTaskToAgent:async n=>{const a=e().agentHook;if(!a){e().toast("Agent hook not configured","error");return}e().toast(`Sending to ${a.label}…`);const i=await Voe(n);if(i===null){e().toast("Could not reach the daemon","error");return}i.ok?e().toast(`Sent to ${a.label}`):e().toast(i.error||"Agent hook failed","error")},setCurrentPage:n=>t({currentPage:n}),loadTaskContents:async n=>{const{tasksDirHandle:a}=e();if(!a)return;const i=new Map(e().taskContents);await Promise.all(n.map(async r=>{if(!i.has(r))try{const{frontmatter:s,body:o}=await Es(a,r),{subtasks:c,bodyWithoutSubtasks:p}=Ds(o);i.set(r,{frontmatter:s,subtasks:c,body:p})}catch{}})),t({taskContents:i})},computeSearchMatches:n=>{if(!n.trim()){t({searchMatches:new Map});return}const{taskContents:a}=e(),i=new Map,r=n.toLowerCase();for(const[s,o]of a){const c=Rz(o,r);c.length>0&&i.set(s,c)}t({searchMatches:i})},toast:(n,a="success",i)=>{const r=++bce,s=i??(a==="error"||a==="warning"?6e3:2500);t(o=>({toasts:[...o.toasts,{id:r,message:n,type:a}]})),setTimeout(()=>{t(o=>({toasts:o.toasts.filter(c=>c.id!==r)}))},s)},dismissToast:n=>t(a=>({toasts:a.toasts.filter(i=>i.id!==n)})),resolveConflict:async n=>{const{conflictState:a,drawerData:i,tasksDirHandle:r,drawerTaskId:s,drawerBaseVersion:o}=e();if(!(!a||!r||!s))if(n==="reload"){const{frontmatter:c,body:p}=await Es(r,s),{subtasks:d,bodyWithoutSubtasks:m}=Ds(p);t({drawerData:{frontmatter:c,subtasks:d,body:m},drawerBaseVersion:{frontmatter:c,subtasks:d,body:m,savedAt:Date.now()},conflictState:null,showConflictModal:!1}),e().toast("Reloaded from disk")}else if(n==="overwrite"){if(i&&s&&o){const c=qd(i.body,i.subtasks),p={...i.frontmatter,id:s};try{await au(r,s,p,c),t({drawerBaseVersion:{...i,savedAt:Date.now()},conflictState:null,showConflictModal:!1}),e().toast("Overwritten remote changes")}catch(d){e().toast("Failed to overwrite: "+d.message,"error")}}}else t({conflictState:null,showConflictModal:!1})},setupWatcher:()=>{if(Kt()){M2&&clearInterval(M2),M2=setInterval(()=>{e().reloadBoard()},2e3);return}const{dirHandle:n,tasksDirHandle:a}=e();if(!n||!a)return;al.stop(),Mf.forEach(s=>clearTimeout(s)),Mf.clear(),al.start(n,a);const i=(s,o)=>{const c=Mf.get(s);c&&clearTimeout(c);const p=Math.max(2e3,e().config.notifications.editDebounceMs),d=setTimeout(()=>{Mf.delete(s);const m=e().config;m.notifications.taskEdits&&P2({title:"Task edited",body:`${o} changed on disk.`,config:m})},p);Mf.set(s,d)},r=async s=>{const{tasksDirHandle:o,config:c}=e();if(!o)return;let p,d;try{({frontmatter:p,body:d}=await Es(o,s))}catch(A){console.warn(`[Watcher] notifyTaskChange: failed to read ${s}:`,A);return}const{subtasks:m,bodyWithoutSubtasks:f}=Ds(d),h={id:s,frontmatter:{...p,id:p.id||s,status:p.status||"Backlog"},body:f,subtasks:m},b=h3(h),k=mu.get(s);if(!k){mu.set(s,b);return}c.notifications.statusChanges&&k.status!==b.status&&P2({title:"Task status changed",body:`${b.title}: ${k.status} → ${b.status}`,config:c});const w=gce(k.subtasks,b.subtasks);c.notifications.subtaskCompletions&&w>0&&P2({title:"Subtask completed",body:w===1?`${b.title}: 1 subtask completed.`:`${b.title}: ${w} subtasks completed.`,config:c}),hce(k,b)&&i(s,b.title),mu.set(s,b)};al.on("configChanged",()=>{try{e().loadConfig(),e().toast("Settings updated externally","info")}catch(s){console.error("[Watcher] configChanged handler error:",s)}}),al.on("taskChanged",async s=>{try{const{drawerTaskId:o,drawerBaseVersion:c,tasksDirHandle:p}=e();if(await r(s),o===s&&c&&p){let d,m;try{({frontmatter:d,body:m}=await Es(p,s))}catch(E){console.warn(`[Watcher] taskChanged: failed to re-read ${s}:`,E);return}const{subtasks:f,bodyWithoutSubtasks:h}=Ds(m),b=c,k=JSON.stringify(b.frontmatter)!==JSON.stringify(d),w=b.body!==h,A=JSON.stringify(b.subtasks)!==JSON.stringify(f);if(!k&&!w&&!A)return;let S="none";k&&(w||A)?S="full":k?S="metadata-only":(w||A)&&(S="body-only"),t({conflictState:{taskId:s,type:S,local:b,remote:{frontmatter:d,body:h,subtasks:f}},showConflictModal:S==="full"})}else await e().reloadBoard()}catch(o){console.error(`[Watcher] taskChanged handler error for ${s}:`,o)}}),al.on("newTaskDetected",async s=>{try{const{tasksDirHandle:o}=e();if(o){let c,p;try{({frontmatter:c,body:p}=await Es(o,s))}catch(f){console.warn(`[Watcher] newTaskDetected: failed to read ${s}:`,f),e().toast(`New task ${s} detected but could not be loaded`,"warning");return}const{subtasks:d,bodyWithoutSubtasks:m}=Ds(p);mu.set(s,h3({id:s,frontmatter:{...c,id:c.id||s,status:c.status||"Backlog"},body:m,subtasks:d}))}await e().reloadBoard()}catch(o){console.error(`[Watcher] newTaskDetected handler error for ${s}:`,o)}}),al.on("watcherError",s=>{t({watcherError:s}),e().toast(s,"warning",1e4)})},restartWatcher:()=>{const{dirHandle:n,tasksDirHandle:a}=e();!n||!a||(t({watcherError:null}),e().setupWatcher(),e().toast("File watcher restarted"))}}));Ly().then(t=>{ue.setState({recentProjects:t})}).catch(t=>{console.warn("[Store] Failed to hydrate recent projects:",t)});rl(Ci);window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",()=>{rl(ue.getState().config)});const vce=Object.freeze(Object.defineProperty({__proto__:null,useStore:ue},Symbol.toStringTag,{value:"Module"}));function yce(){const t=ue(o=>o.config),e=ue(o=>o.updateConfig),[n,a]=$.useState(!1);if($.useEffect(()=>{a(!0)},[]),!n)return null;const i=t.ui.theme==="auto"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t.ui.theme,r=i==="dark",s=()=>{const o=r?"light":"dark";e(c=>({...c,ui:{...c.ui,theme:o}}))};return _.jsx(lt.button,{onClick:s,className:m3("relative inline-flex items-center rounded-full transition-all duration-300","border border-black/[0.08] dark:border-white/[0.12]","bg-black/[0.05] dark:bg-white/[0.08]","h-8 w-[52px] px-1"),title:r?"Switch to light mode":"Switch to dark mode",children:_.jsx(lt.div,{className:m3("inline-flex items-center justify-center rounded-full shadow-md",r?"bg-[#1e293b] border border-white/[0.15]":"bg-black border border-black/20","h-[26px] w-[26px]"),animate:{x:r?22:0},transition:{type:"spring",stiffness:500,damping:30},children:_.jsx(lt.div,{initial:{rotate:-90,scale:.5,opacity:0},animate:{rotate:0,scale:1,opacity:1},transition:{duration:.25,ease:"easeOut"},children:r?_.jsx(Zn.Moon,{size:13,className:"text-sky-300"}):_.jsx(Zn.Sun,{size:13,className:"text-amber-400"})},i)})})}function _ce(t){const e=xse(t,{stiffness:180,damping:22,mass:.8});return $.useEffect(()=>{e.set(t)},[t,e]),bz(e,a=>Math.round(a).toString())}const b3="0.15.3",kce=({className:t})=>_.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 150 150",className:t,fill:"currentColor",children:[_.jsx("path",{d:"m57.6 64.6 0.1-0.1v-31.3c-0.1-3.5-2.7-5.6-5.7-5.6h-16.3v59.6c0.2-1.3 0.9-2.6 1.7-3.2l20.2-19.4z"}),_.jsx("path",{d:"m87.6 43.8c-3.4 0.1-7.1 1.3-9.9 3.7l-38.5 38.7c-2.1 2.1-3.4 4.8-3.5 7.5v26.7l77.5-76.4v-0.2h-25.6z"}),_.jsx("path",{d:"m108.1 96.4-6 5-22.4-20.8-14.6 14.2 21.1 21.4-5 4.1c-0.6 0.5-0.3 0.9 0.2 0.9h27.6c0.4 0 0.7-0.4 0.7-0.6v-24.8c0-0.7-1.1-0.3-1.6 0.3v0.3z"})]});function wce(){const{t}=Cn(),e=ue(I=>I.dirHandle),n=ue(I=>I.isOpen),a=ue(I=>I.projectName),i=ue(I=>I.archivedTasks.length),r=ue(I=>I.showArchives),s=ue(I=>I.setShowArchives),o=ue(I=>I.columns),c=ue(I=>I.openFolder),p=ue(I=>I.reloadBoard),d=ue(I=>I.createTask),m=ue(I=>I.setCommandOpen),f=ue(I=>I.viewMode),h=ue(I=>I.setViewMode),b=ue(I=>I.density),k=ue(I=>I.setDensity),w=ue(I=>I.setCurrentPage),A=ue(I=>I.recentProjects),S=ue(I=>I.openRecentProject),E=ue(I=>I.filters),P=ue(I=>I.setFilter),M=ue(I=>I.clearFilters),j=ue(I=>I.config.fields),z=ue(I=>I.lastReloadError),H=ue(I=>I.watcherError),O=ue(I=>I.restartWatcher),[L,W]=$.useState(!1),[X,te]=$.useState(!0),Z=$.useRef(null),Q=$.useRef(null),q=o.reduce((I,J)=>I+J.tasks.length,0),V=_ce(q),B=[];j.priority&&E.priority&&B.push({type:"priority",label:E.priority,value:E.priority}),j.tags&&E.tag&&B.push({type:"tag",label:"#"+E.tag,value:E.tag}),j.assignee&&E.assignee&&B.push({type:"assignee",label:"@"+E.assignee,value:E.assignee});const ne=[{label:t("filterBar.ownerAll"),value:""},{label:t("filterBar.ownerHuman"),value:"human"},{label:t("filterBar.ownerAI"),value:"ai"}],D=B.length>0||E.search||j.ownerType&&E.ownerType;return $.useEffect(()=>{if(!L)return;const I=J=>{Z.current&&!Z.current.contains(J.target)&&W(!1)};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[L]),$.useEffect(()=>{const I=setTimeout(()=>te(!1),5e3);return()=>clearTimeout(I)},[]),$.useEffect(()=>{document.title=a?`${a} · Kandown`:"Kandown"},[a]),_.jsxs(_.Fragment,{children:[(z||H)&&_.jsxs("div",{className:"flex items-center gap-2 px-5 py-1.5 bg-amber-500/10 border-b border-amber-500/30 text-[12px] text-amber-700 dark:text-amber-300",children:[_.jsx("span",{className:"flex-1 truncate",children:H?`⚠ ${H}`:`⚠ ${z}`}),H&&_.jsx("button",{type:"button",onClick:O,className:"px-2 py-0.5 rounded bg-amber-500/20 hover:bg-amber-500/30 text-[11.5px] font-medium",children:"Restart watcher"}),_.jsx("button",{type:"button",onClick:p,className:"px-2 py-0.5 rounded bg-amber-500/20 hover:bg-amber-500/30 text-[11.5px] font-medium",children:"Reload"})]}),_.jsxs("header",{className:"flex items-center justify-between px-5 h-[64px] border-b border-border bg-card/80 backdrop-blur-xl relative z-10",children:[_.jsxs("div",{className:"flex items-center gap-4 min-w-0",children:[_.jsx("div",{className:"flex items-center gap-2.5 flex-shrink-0",children:_.jsxs("button",{onClick:()=>window.history.pushState({},"",window.location.pathname),className:"flex items-center gap-2 cursor-pointer",children:[_.jsx(kce,{className:"w-[34px] h-[34px] dark:text-white text-black"}),_.jsx(Sr,{mode:"wait",initial:!1,children:X?_.jsxs(lt.span,{className:"flex items-center gap-2",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.45},children:[_.jsx("span",{className:"text-[15px] font-semibold tracking-tight text-fg",children:"kandown"}),_.jsxs("span",{className:"inline-flex items-center h-5 px-1.5 text-[10.5px] font-semibold text-red-600 bg-red-50 dark:text-red-400 dark:bg-red-500/15 rounded-md",children:["v",b3]})]},"boot"):a?_.jsx(lt.span,{className:"text-[15px] font-semibold tracking-tight text-fg truncate max-w-[240px]",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.45},children:a},"project"):null})]})}),e&&_.jsxs(_.Fragment,{children:[_.jsx("div",{className:"w-px h-[20px] bg-black/[0.08] dark:bg-white/[0.08] flex-shrink-0"}),_.jsxs("div",{className:"flex items-center gap-2 px-3 h-9 bg-secondary/60 border border-border rounded-xl min-w-[200px] max-w-[280px] focus-within:border-border-focus focus-within:bg-secondary transition-all",children:[_.jsx(Zn.Search,{size:14,className:"text-fg-muted/60 flex-shrink-0"}),_.jsx("input",{ref:Q,type:"text",placeholder:t("filterBar.searchPlaceholder"),value:E.search,onChange:I=>P("search",I.target.value),className:"bg-transparent border-none outline-none text-fg text-[13px] w-full placeholder:text-fg-muted/60"}),E.search?_.jsx("button",{onClick:()=>P("search",""),className:"text-fg-muted/60 hover:text-fg flex-shrink-0",children:_.jsx(Zn.X,{size:14})}):_.jsx("kbd",{className:"inline-flex items-center h-5 px-1.5 text-[10px] font-medium text-fg-muted/50 bg-black/[0.04] dark:bg-white/[0.08] rounded border border-black/[0.06] dark:border-white/[0.1]",children:"⌘K"})]}),_.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap overflow-hidden",children:[_.jsx(Sr,{children:B.map(I=>_.jsxs(lt.button,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},transition:{duration:.15},onClick:()=>P(I.type,null),className:"inline-flex items-center gap-1 h-6 px-2.5 text-[12px] text-fg bg-black/[0.05] dark:bg-white/[0.1] border border-black/[0.08] dark:border-white/[0.12] rounded-lg hover:bg-black/[0.08] dark:hover:bg-white/[0.15] transition-colors",children:[I.label,_.jsx(Zn.X,{size:10,className:"text-fg-muted/60"})]},I.type+I.value))}),j.ownerType&&_.jsx("div",{className:"flex items-center h-6 border border-black/[0.06] dark:border-white/[0.1] rounded-lg overflow-hidden",children:ne.map(I=>_.jsx("button",{onClick:()=>P("ownerType",I.value),className:`h-full px-2.5 text-[12px] transition-colors ${E.ownerType===I.value?"bg-black/[0.06] dark:bg-white/[0.12] text-fg":"text-fg-muted/70 hover:text-fg"}`,children:I.label},I.value))}),D&&_.jsx("button",{onClick:M,className:"text-[12px] text-fg-muted/60 hover:text-fg transition-colors",children:t("filterBar.clearAll")})]})]}),e&&_.jsxs(_.Fragment,{children:[_.jsx("div",{className:"w-px h-[20px] bg-black/[0.08] dark:bg-white/[0.08] flex-shrink-0"}),_.jsxs("div",{className:"relative flex-shrink-0",ref:Z,children:[_.jsxs("button",{onClick:()=>W(I=>!I),className:"flex items-center gap-1.5 px-2.5 py-1.5 text-[13px] text-fg-muted hover:text-fg hover:bg-black/[0.04] dark:hover:bg-white/[0.06] rounded-lg transition-colors border border-transparent hover:border-black/[0.06] dark:hover:border-white/[0.1]",children:[_.jsx(Zn.Folder,{size:13,className:"text-fg-muted/70"}),_.jsxs("span",{className:"font-medium",children:[".",e.name]}),_.jsx(Zn.ChevronDown,{size:11,className:"opacity-50"})]}),_.jsx(Sr,{children:L&&_.jsx(lt.div,{initial:{opacity:0,y:-4,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.98},transition:{duration:.12},className:"absolute top-full left-0 mt-2 min-w-[240px] glass rounded-xl shadow-[0_16px_48px_rgba(0,0,0,0.5)] overflow-hidden z-50",children:_.jsxs("div",{className:"py-1.5",children:[A.length>0&&_.jsxs(_.Fragment,{children:[_.jsx("div",{className:"px-3 py-1.5 text-[11px] font-semibold uppercase tracking-wider text-fg-muted/60",children:t("header.recentProjects")}),A.map(I=>_.jsxs("button",{onClick:()=>{W(!1),S(I)},className:"w-full flex items-center gap-2 px-3 py-2 text-[13.5px] text-left hover:bg-black/[0.04] dark:hover:bg-white/[0.06] transition-colors",children:[_.jsx(Zn.Folder,{size:12,className:"text-fg-muted/60"}),_.jsx("span",{className:"truncate",children:I.name}),I.id===e.name&&_.jsx(Zn.Check,{size:12,className:"ml-auto text-emerald-500"})]},I.id)),_.jsx("div",{className:"h-px bg-black/[0.06] dark:bg-white/[0.08] my-1.5 mx-2"})]}),_.jsxs("button",{onClick:()=>{W(!1),c()},className:"w-full flex items-center gap-2 px-3 py-2 text-[13.5px] text-left hover:bg-black/[0.04] dark:hover:bg-white/[0.06] transition-colors",children:[_.jsx(Zn.Plus,{size:12,className:"text-fg-muted/60"}),_.jsx("span",{children:t("header.openFolder...")})]})]})})})]})]})]}),_.jsx("div",{className:"flex items-center gap-2 flex-shrink-0",children:n||e?_.jsxs(_.Fragment,{children:[_.jsxs("div",{className:"flex items-center gap-2 mr-2 text-[12.5px] text-fg-muted/70",children:[_.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-emerald-500"}),_.jsx(lt.span,{className:"tabular-nums font-medium",children:V}),_.jsx("span",{children:t("header.tasks")})]}),_.jsxs("div",{className:"flex items-center bg-black/[0.04] dark:bg-white/[0.06] border border-black/[0.06] dark:border-white/[0.1] rounded-xl p-0.5 h-10",children:[_.jsx("button",{onClick:()=>h("board"),className:`w-9 h-9 inline-flex items-center justify-center rounded-lg transition-all ${f==="board"?"bg-card text-fg shadow-sm":"text-fg-muted/70 hover:text-fg"}`,title:t("common.board"),children:_.jsx(Zn.LayoutBoard,{size:18})}),_.jsx("button",{onClick:()=>h("list"),className:`w-9 h-9 inline-flex items-center justify-center rounded-lg transition-all ${f==="list"?"bg-card text-fg shadow-sm":"text-fg-muted/70 hover:text-fg"}`,title:t("common.list"),children:_.jsx(Zn.LayoutList,{size:18})})]}),_.jsx(na,{variant:"icon",icon:"Archive",onClick:()=>s(!r),title:r?t("header.backToBoard"):`${t("header.archives")} (${i})`,className:r?"text-accent":""}),_.jsx(na,{variant:"icon",icon:"Density",onClick:()=>k(b==="compact"?"comfortable":"compact"),title:`Density: ${b}`}),_.jsx(na,{variant:"icon",icon:"Settings",onClick:()=>w("settings"),title:t("common.settings")}),_.jsx(yce,{}),_.jsx("div",{className:"w-px h-5 bg-black/[0.08] dark:bg-white/[0.08] mx-1"}),_.jsx(na,{variant:"secondary",icon:"Search",label:t("common.search"),shortcut:"⌘K",onClick:()=>m(!0),title:"Command palette (⌘K)"}),_.jsx(na,{variant:"icon",icon:"Refresh",onClick:p,title:`${t("common.reload")} (R)`}),_.jsx(na,{variant:"primary",icon:"Plus",label:t("common.newTask"),shortcut:"N",onClick:()=>d()})]}):_.jsx(na,{variant:"primary",label:t("common.openFolder"),onClick:c})})]})]})}/**
|
|
117
117
|
* @license @tabler/icons-react v3.41.1 - MIT
|
|
118
118
|
*
|
|
119
119
|
* This source code is licensed under the MIT license.
|
|
@@ -228,7 +228,7 @@ Error generating stack: `+y.message+`
|
|
|
228
228
|
*
|
|
229
229
|
* This source code is licensed under the MIT license.
|
|
230
230
|
* See the LICENSE file in the root directory of this source tree.
|
|
231
|
-
*/const ape=[["path",{d:"M4 7l16 0",key:"svg-0"}],["path",{d:"M10 11l0 6",key:"svg-1"}],["path",{d:"M14 11l0 6",key:"svg-2"}],["path",{d:"M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12",key:"svg-3"}],["path",{d:"M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3",key:"svg-4"}]],ipe=On("outline","trash","Trash",ape),rpe={priority:"Priority",assignee:"Assignee",tags:"Tags",due:"Due",ownerType:"Owner",tools:"Tools"},spe=new Set(["report"]);function ope(t){return rpe[t]??t.charAt(0).toUpperCase()+t.slice(1).replace(/_/g," ")}function cpe(t){if(!/^\d{4}-\d{2}-\d{2}/.test(t))return!1;const e=new Date(t);return!isNaN(e.getTime())}function ppe(t,e){if(e==null)return null;if(Array.isArray(e))return _.jsx("span",{className:"flex flex-wrap gap-1",children:e.map((n,a)=>_.jsx("span",{className:"inline-flex items-center h-[18px] px-1.5 rounded bg-black/[0.04] dark:bg-white/[0.08] border border-border/60 text-fg-dim",children:String(n)},a))});if(typeof e=="string"){if(t==="due"||cpe(e)){const n=new Date(e);if(!isNaN(n.getTime()))return _.jsx("span",{className:"text-fg-dim",children:n.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})})}return _.jsx("span",{className:"text-fg-dim break-words",children:e})}return typeof e=="boolean"?_.jsx("span",{className:"text-fg-dim",children:e?"yes":"no"}):typeof e=="number"?_.jsx("span",{className:"text-fg-dim",children:e}):_.jsx("span",{className:"text-fg-dim",children:String(e)})}function lpe({frontmatter:t,hidden:e}){if(e)return null;const n=Object.entries(t).filter(([a,i])=>!(spe.has(a)||i==null||i===""||Array.isArray(i)&&i.length===0));return n.length===0?null:_.jsx("div",{className:"mt-2.5 pt-2 border-t border-border/60 space-y-1",children:n.map(([a,i])=>_.jsxs("div",{className:"flex items-start gap-2 text-[11.5px] leading-snug",children:[_.jsx("span",{className:"text-fg-muted/80 font-medium flex-shrink-0 min-w-[64px]",children:ope(a)}),_.jsx("span",{className:"flex-1 min-w-0",children:ppe(a,i)})]},a))})}function dpe({text:t,keyword:e}){if(!e)return _.jsx(_.Fragment,{children:t});const n=t.split(new RegExp(`(${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})`,"gi"));return _.jsx(_.Fragment,{children:n.map((a,i)=>a.toLowerCase()===e.toLowerCase()?_.jsx("mark",{className:"bg-yellow-200/60 text-fg rounded px-0.5 font-semibold",children:a},i):_.jsx("span",{children:a},i))})}function Gz({task:t,searchMatches:e=[],density:n,onDragStart:a,onDragEnd:i,columnName:r,doneTags:s}){const{t:o}=Cn(),c=ue(O=>O.openDrawer),p=ue(O=>O.deleteTask),d=ue(O=>O.showMetadata),[m,f]=$.useState(!1),[h,b]=$.useState(!1),k=$.useRef(!0),w=n==="compact",A=t.progress&&t.progress.total>0?Math.round(t.progress.done/t.progress.total*100):0,S=t.progress&&t.progress.done===t.progress.total,E={onDragStart:a,onDragEnd:i},P=t.title.match(/^\[([^\]]+)\]\s*/),M=P?`[${P[1]}]`:"",j=P?t.title.slice(P[0].length):t.title,z=e.length>0&&!w;$.useEffect(()=>()=>{k.current=!1},[]),$.useEffect(()=>{if(!m)return;const O=window.setTimeout(()=>f(!1),2400);return()=>window.clearTimeout(O)},[m]);const H=async O=>{if(O.stopPropagation(),O.preventDefault(),!h){if(!m){f(!0);return}b(!0),await p(t.id),k.current&&(b(!1),f(!1))}};return _.jsxs(lt.div,{layout:!0,layoutId:t.id,transition:{type:"spring",stiffness:500,damping:40,mass:.8},initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,scale:.95,transition:{duration:.12}},whileHover:{y:-1},whileTap:{scale:.99},draggable:!0,...E,onClick:()=>c(t.id),onMouseLeave:()=>f(!1),"data-task-id":t.id,"data-col":r,className:`group relative cursor-pointer rounded-lg border border-border bg-card shadow-[0_1px_2px_rgba(0,0,0,0.04)] transition-all duration-150 hover:border-border-strong hover:shadow-[0_2px_8px_rgba(0,0,0,0.06)] ${t.checked?"opacity-70":""}`,children:[_.jsx("div",{className:"absolute left-1.5 top-1/2 -translate-y-1/2 opacity-0 group-hover:opacity-40 transition-opacity cursor-grab active:cursor-grabbing",children:_.jsxs("svg",{width:"10",height:"16",viewBox:"0 0 10 16",fill:"currentColor",className:"text-fg-muted",children:[_.jsx("circle",{cx:"3",cy:"2",r:"1.5"}),_.jsx("circle",{cx:"7",cy:"2",r:"1.5"}),_.jsx("circle",{cx:"3",cy:"8",r:"1.5"}),_.jsx("circle",{cx:"7",cy:"8",r:"1.5"}),_.jsx("circle",{cx:"3",cy:"14",r:"1.5"}),_.jsx("circle",{cx:"7",cy:"14",r:"1.5"})]})}),_.jsx("button",{type:"button",draggable:!1,"aria-label":o(m?"card.confirmDelete":"card.delete"),title:o(m?"card.confirmDelete":"card.delete"),disabled:h,onClick:H,onPointerDown:O=>O.stopPropagation(),onBlur:()=>f(!1),className:`absolute right-2 top-2 z-10 inline-flex h-6 w-6 items-center justify-center rounded-md border transition-all ${m?"border-red-500 bg-red-500 text-white opacity-100 shadow-sm":"border-border bg-card/80 text-fg-muted opacity-0 hover:border-red-500/60 hover:bg-card hover:text-red-500 group-hover:opacity-100"} ${h?"pointer-events-none opacity-60":""}`,children:m?_.jsx(npe,{size:14,stroke:1.9}):_.jsx(ipe,{size:14,stroke:1.8})}),_.jsxs("div",{className:"px-3.5 pt-3 pb-1.5",children:[_.jsx("span",{className:"font-mono text-[11.5px] font-medium text-fg-faint tabular-nums",children:t.id.replace(/^t/,"#")}),t.dependsOn&&t.dependsOn.length>0&&_.jsxs("span",{className:"ml-1.5 inline-flex items-center gap-0.5 px-1.5 h-[16px] rounded text-[10.5px] font-semibold text-amber-700 dark:text-amber-300 bg-amber-500/10 border border-amber-500/20",title:o("card.blockedBy",{ids:t.dependsOn.join(", ")}),"aria-label":o("card.blockedBy",{ids:t.dependsOn.join(", ")}),children:["↪",t.dependsOn.length]})]}),_.jsxs("div",{className:"px-3.5 pb-1.5",children:[_.jsx("div",{className:`text-[13.5px] leading-snug font-medium ${t.checked?"line-through text-fg-muted":"text-fg"} ${w?"line-clamp-1":"line-clamp-2"}`,children:j}),M&&_.jsx("div",{className:"mt-1.5",children:_.jsx("span",{className:"inline-flex items-center h-[18px] px-1.5 text-[10.5px] font-semibold tracking-wide text-fg-muted uppercase rounded bg-black/[0.04] dark:bg-white/10",children:M})}),z&&_.jsx("div",{className:"mt-2.5 space-y-1",children:e.slice(0,2).map((O,L)=>_.jsxs("div",{className:"text-[12px] text-fg-dim bg-black/[0.03] dark:bg-white/[0.04] rounded-lg px-2.5 py-1.5 border border-black/[0.05] dark:border-white/[0.08]",children:[_.jsx("span",{className:"text-[10px] font-semibold text-fg-muted uppercase tracking-wide mr-1.5",children:o(`sectionLabels.${O.section}`)||O.section}),_.jsx(dpe,{text:O.snippet,keyword:O.keyword})]},L))}),!w&&t.progress&&t.progress.total>0&&_.jsxs("div",{className:"mt-2.5 flex items-center gap-2 ",children:[_.jsx("div",{className:"flex-1 h-[3px] bg-black/[0.06] dark:bg-white/[0.1] rounded-full overflow-hidden",children:_.jsx(lt.div,{className:"h-full rounded-full",style:{backgroundColor:S?"#22c55e":"#737078"},initial:!1,animate:{width:`${A}%`},transition:{type:"spring",stiffness:160,damping:22}})}),_.jsxs("span",{className:"font-mono text-[11px] text-fg-muted tabular-nums",children:[t.progress.done,"/",t.progress.total]})]}),_.jsx(lpe,{frontmatter:t.frontmatter,hidden:d})]})]})}function upe({group:t,searchMatches:e,density:n,columnName:a,onCardDragStart:i,onCardDragEnd:r,defaultExpanded:s=!1,doneTags:o}){const{t:c}=Cn(),[p,d]=$.useState(s);$.useEffect(()=>{d(s)},[s]);const m=t.tasks.length,f=t.tasks[0],h=f.title.replace(/^\[([^\]]+)\]\s*/,"").replace(/#\w+\s*/,"").trim()||f.title;return p?_.jsxs(lt.div,{layout:!0,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,scale:.95,transition:{duration:.12}},className:"flex flex-col gap-2",children:[_.jsxs("button",{type:"button",onClick:()=>d(!1),className:"flex items-center gap-1.5 px-2 py-1 rounded-md text-[11px] font-semibold text-fg-muted/70 uppercase tracking-wide hover:bg-black/[0.04] dark:hover:bg-white/[0.06] transition-colors w-fit",children:[_.jsx(Lce,{size:13,stroke:2}),_.jsx("span",{children:t.displayKey}),_.jsx("span",{className:"font-normal text-fg-muted/40",children:m})]}),_.jsx(Sr,{mode:"popLayout",children:t.tasks.map(b=>_.jsx(Gz,{task:b,searchMatches:e.get(b.id)||[],density:n,columnName:a,doneTags:o,onDragStart:()=>i(b.id,a),onDragEnd:r},b.id))})]}):_.jsxs(lt.div,{layout:!0,initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,scale:.95,transition:{duration:.12}},transition:{type:"spring",stiffness:500,damping:40,mass:.8},onClick:()=>d(!0),className:"relative cursor-pointer pb-3",children:[m>2&&_.jsx("div",{className:"absolute inset-0 rounded-lg border border-border bg-card/40 pointer-events-none",style:{transform:"translateY(8px) scale(0.94)",zIndex:0}}),_.jsx("div",{className:"absolute inset-0 rounded-lg border border-border bg-card/60 pointer-events-none",style:{transform:"translateY(4px) scale(0.97)",zIndex:1}}),_.jsx(lt.div,{whileHover:{y:-1},whileTap:{scale:.99},className:"relative z-10 rounded-lg border border-border bg-card shadow-[0_1px_2px_rgba(0,0,0,0.04)] transition-all hover:border-border-strong hover:shadow-[0_2px_8px_rgba(0,0,0,0.06)]",children:_.jsxs("div",{className:"px-3.5 pt-3 pb-2.5",children:[_.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[_.jsxs("div",{className:"flex items-center gap-1.5",children:[_.jsx(Qce,{size:12,stroke:1.8,className:"text-fg-muted/60"}),_.jsx("span",{className:"text-[11px] font-semibold tracking-wide text-fg-muted uppercase",children:t.displayKey})]}),_.jsxs("div",{className:"flex items-center gap-1.5",children:[_.jsx("span",{className:"inline-flex items-center h-[18px] px-1.5 text-[10.5px] font-medium rounded-md text-fg-muted tabular-nums",children:m}),_.jsx(Ece,{size:12,stroke:2,className:"text-fg-muted/50"})]})]}),_.jsxs("div",{className:"text-[13.5px] leading-snug font-medium text-fg line-clamp-1",children:[h,m>1&&_.jsxs("span",{className:"text-fg-muted/50 ml-1.5",children:["+",m-1]})]})]})})]})}const mpe=/^\[([^\]]+)\]\s*/,fpe=/#(\w+)/;function Wz(t){const e=t.match(mpe);if(e)return`[${e[1].toLowerCase()}]`;const n=t.match(fpe);return n?`#${n[1].toLowerCase()}`:null}function gpe(t){return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function hpe(t){const e=new Map,n=new Map;for(const r of t){const s=Wz(r.title);e.set(r.id,s),s&&n.set(s,(n.get(s)??0)+1)}const a=[],i=new Map;for(const r of t){const s=e.get(r.id)??null;if(!s||(n.get(s)??0)<2){a.push({type:"single",task:r});continue}const o=i.get(s);if(o)o.tasks.push(r);else{const c={type:"stack",groupKey:s,displayKey:gpe(s),tasks:[r]};i.set(s,c),a.push(c)}}return a}const bpe={backlog:xj,icebox:xj,todo:j2,"to do":j2,ready:j2,doing:Mv,progress:Mv,"in progress":Mv,active:Mv,review:D2,qa:D2,verify:D2,done:L2,complete:L2,completed:L2};function vpe(t){const e=t.trim().toLowerCase();return bpe[e]??qce}const Aj={red:"rgba(239,68,68,0.06)",orange:"rgba(249,115,22,0.06)",amber:"rgba(245,158,11,0.06)",yellow:"rgba(234,179,8,0.06)",lime:"rgba(132,204,22,0.06)",green:"rgba(34,197,94,0.06)",emerald:"rgba(16,185,129,0.06)",teal:"rgba(20,184,166,0.06)",cyan:"rgba(6,182,212,0.06)",sky:"rgba(14,165,233,0.06)",blue:"rgba(59,130,246,0.06)",indigo:"rgba(99,102,241,0.06)",violet:"rgba(139,92,246,0.06)",purple:"rgba(168,85,247,0.06)",fuchsia:"rgba(217,70,239,0.06)",pink:"rgba(236,72,153,0.06)",rose:"rgba(244,63,94,0.06)",slate:"rgba(100,116,139,0.05)",gray:"rgba(255,255,255,0.025)",zinc:"rgba(113,113,122,0.05)",black:"rgba(0,0,0,0.24)",blackTransparent:"rgba(0,0,0,0.1)"},ype=[{key:"red",label:"Red",color:"rgba(239,68,68,0.9)"},{key:"orange",label:"Orange",color:"rgba(249,115,22,0.9)"},{key:"amber",label:"Amber",color:"rgba(245,158,11,0.9)"},{key:"yellow",label:"Yellow",color:"rgba(234,179,8,0.9)"},{key:"lime",label:"Lime",color:"rgba(132,204,22,0.9)"},{key:"green",label:"Green",color:"rgba(34,197,94,0.9)"},{key:"emerald",label:"Emerald",color:"rgba(16,185,129,0.9)"},{key:"teal",label:"Teal",color:"rgba(20,184,166,0.9)"},{key:"cyan",label:"Cyan",color:"rgba(6,182,212,0.9)"},{key:"sky",label:"Sky",color:"rgba(14,165,233,0.9)"},{key:"blue",label:"Blue",color:"rgba(59,130,246,0.9)"},{key:"indigo",label:"Indigo",color:"rgba(99,102,241,0.9)"},{key:"violet",label:"Violet",color:"rgba(139,92,246,0.9)"},{key:"purple",label:"Purple",color:"rgba(168,85,247,0.9)"},{key:"fuchsia",label:"Fuchsia",color:"rgba(217,70,239,0.9)"},{key:"pink",label:"Pink",color:"rgba(236,72,153,0.9)"},{key:"rose",label:"Rose",color:"rgba(244,63,94,0.9)"},{key:"slate",label:"Slate",color:"rgba(100,116,139,0.9)"},{key:"gray",label:"Gray",color:"rgba(156,163,175,0.9)"},{key:"zinc",label:"Zinc",color:"rgba(113,113,122,0.9)"},{key:"black",label:"Black",color:"rgba(0,0,0,0.9)"},{key:"blackTransparent",label:"Black 50%",color:"rgba(0,0,0,0.5)"}];function _pe({columnName:t,currentColor:e,onSelect:n}){const{t:a}=Cn(),[i,r]=$.useState(!1),s=$.useRef(null);return $.useEffect(()=>{if(!i)return;const o=c=>{s.current&&!s.current.contains(c.target)&&r(!1)};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[i]),_.jsxs("div",{ref:s,className:"relative",children:[_.jsx("button",{onClick:o=>{o.stopPropagation(),r(c=>!c)},className:"w-5 h-5 inline-flex items-center justify-center text-fg-muted hover:bg-bg-3 hover:text-fg rounded-[4px] transition-colors",title:a("column.columnColor"),children:_.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-60",children:[_.jsx("circle",{cx:"3",cy:"2",r:"1.2",fill:"currentColor"}),_.jsx("circle",{cx:"9",cy:"2",r:"1.2",fill:"currentColor"}),_.jsx("circle",{cx:"3",cy:"6",r:"1.2",fill:"currentColor"}),_.jsx("circle",{cx:"9",cy:"6",r:"1.2",fill:"currentColor"}),_.jsx("circle",{cx:"3",cy:"10",r:"1.2",fill:"currentColor"}),_.jsx("circle",{cx:"9",cy:"10",r:"1.2",fill:"currentColor"})]})}),_.jsx(Sr,{children:i&&_.jsxs(lt.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},transition:{duration:.12},className:"absolute right-0 top-full mt-1 bg-bg-2 border border-border rounded-[6px] shadow-lg p-1.5 z-50 min-w-[152px]",style:{transformOrigin:"top right"},children:[_.jsx("div",{className:"text-[11px] text-fg-muted px-1.5 pb-1.5 font-medium",children:a("column.color")}),_.jsx("div",{className:"grid grid-cols-5 gap-1",children:ype.map(({key:o,label:c,color:p})=>_.jsx("button",{onClick:d=>{d.stopPropagation(),n(o),r(!1)},title:c,className:`w-6 h-6 rounded-[4px] flex items-center justify-center transition-all ${e===o?"ring-2 ring-offset-1 ring-offset-bg-2 ring-fg":"hover:scale-110"}`,style:{backgroundColor:p},children:e===o&&_.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",className:"text-white",children:_.jsx("path",{d:"M2 5l2.5 2.5L8 3",stroke:"white",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})})},o))})]})})]})}function kpe({column:t,filteredTasks:e,searchMatches:n,density:a,draggedTaskId:i,draggedFromCol:r,onCardDragStart:s,onCardDragEnd:o,onDrop:c}){const{t:p}=Cn(),[d,m]=$.useState(!1),f=ue(q=>q.createTask),h=ue(q=>q.addColumn),b=ue(q=>q.renameColumn),k=ue(q=>q.deleteColumn),w=ue(q=>q.updateConfig),A=ue(q=>q.config),S=ue(q=>q.filters),E=A.board.columns.some(q=>q.toLowerCase()===t.name.toLowerCase()),P=$.useMemo(()=>hpe(e),[e]),M=$.useMemo(()=>{const q=new Map;for(const B of ue.getState().columns)for(const ne of B.tasks){const D=Wz(ne.title);D&&(q.has(D)||q.set(D,[]),q.get(D).push(ne))}const V=new Set;for(const[B,ne]of q)ne.every(D=>D.checked)&&V.add(B);return V},[]),j=A.board.columnColors?.[t.name.toLowerCase()]??"gray",z=Aj[j]??Aj.gray,H=q=>{w(V=>({...V,board:{...V.board,columnColors:{...V.board.columnColors??{},[t.name.toLowerCase()]:q}}}))},O=q=>{i&&(q.preventDefault(),q.dataTransfer.dropEffect="move",m(!0))},L=q=>{const V=q.relatedTarget;V&&q.currentTarget.contains(V)||m(!1)},W=q=>{q.preventDefault(),m(!1),i&&r!==t.name&&c(t.name)},X=e.length!==t.tasks.length,te=vpe(t.name),Z=()=>{const q=window.prompt(p("column.renamePrompt"),t.name)?.trim();!q||q===t.name||b(t.name,q)},Q=()=>{const q=p("column.deleteConfirm",{name:t.name,count:t.tasks.length});window.confirm(q)&&k(t.name)};return _.jsxs(lt.div,{layout:!0,initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.3,ease:[.32,.72,.35,1]},onDragOver:O,onDragLeave:L,onDrop:W,"data-column":t.name,className:"group flex flex-col flex-none w-[320px] h-full rounded-xl border border-border transition-colors duration-150",style:{backgroundColor:d?"rgba(255,255,255,0.04)":z},children:[_.jsxs("div",{className:"flex items-center justify-between px-3.5 pt-3 pb-2",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(te,{"aria-hidden":"true",size:14,stroke:1.8,className:"flex-none text-fg-muted"}),_.jsx("span",{className:"text-[12.5px] font-semibold tracking-tight text-fg",children:t.name}),_.jsxs("span",{className:"inline-flex items-center justify-center min-w-[20px] h-[18px] px-1.5 text-[10.5px] font-medium text-fg-muted rounded-md tabular-nums",children:[e.length,X&&_.jsxs("span",{className:"text-fg-faint",children:["/",t.tasks.length]})]})]}),_.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[!E&&_.jsx("button",{onClick:()=>h(t.name),className:"h-6 rounded-md px-2 text-[11px] font-medium text-fg-muted transition-colors hover:bg-black/[0.05] dark:hover:bg-white/[0.1] hover:text-fg",title:p("column.addToSettings"),children:p("column.addColumn")}),_.jsx("button",{onClick:()=>f(t.name),className:"w-6 h-6 inline-flex items-center justify-center text-fg-muted hover:bg-black/[0.05] dark:hover:bg-white/[0.1] hover:text-fg rounded-md transition-colors",title:p("column.addTask"),children:_.jsx(Zn.Plus,{size:14})}),_.jsx(_pe,{columnName:t.name.toLowerCase(),currentColor:j,onSelect:H}),_.jsx("button",{onClick:Z,className:"w-6 h-6 inline-flex items-center justify-center text-fg-muted hover:bg-black/[0.05] dark:hover:bg-white/[0.1] hover:text-fg rounded-md transition-colors",title:p("column.renameColumn"),children:_.jsx("span",{className:"text-[11px] leading-none",children:"✎"})}),_.jsx("button",{onClick:Q,className:"w-6 h-6 inline-flex items-center justify-center text-fg-muted hover:bg-red-500/10 hover:text-red-500 rounded-md transition-colors",title:p("column.deleteColumn"),children:_.jsx("span",{className:"text-[13px] leading-none",children:"×"})})]})]}),_.jsx("div",{className:"flex-1 min-h-0 px-2.5 scrollbar-always",style:{overflowY:"scroll"},children:_.jsx("div",{className:"flex flex-col gap-2 py-1",children:_.jsx(Sr,{mode:"popLayout",children:P.length===0?_.jsxs(lt.div,{initial:{opacity:0},animate:{opacity:1},className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[_.jsx("div",{className:"w-10 h-10 rounded-xl bg-black/[0.04] dark:bg-white/[0.08] flex items-center justify-center mb-3",children:_.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-muted/50",children:[_.jsx("path",{d:"M9 11l3 3L22 4"}),_.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})}),_.jsx("p",{className:"text-[13px] font-medium text-fg-muted/70",children:"No tasks yet"}),_.jsx("p",{className:"text-[12px] text-fg-muted/50 mt-0.5",children:"Drag tasks here to get started."})]}):P.map(q=>q.type==="single"?_.jsx(Gz,{task:q.task,searchMatches:n.get(q.task.id)||[],density:a,columnName:t.name,doneTags:M,onDragStart:()=>s(q.task.id,t.name),onDragEnd:o},q.task.id):_.jsx(upe,{group:q,searchMatches:n,density:a,columnName:t.name,doneTags:M,onCardDragStart:s,onCardDragEnd:o,defaultExpanded:A.board.stackDefaultState==="expanded"||!!S.search},`stack-${q.groupKey}`))})})}),_.jsx("div",{className:"flex-none px-2.5 pb-2.5 pt-1",children:_.jsx(na,{variant:"ghost",icon:"Plus",label:p("column.addTask"),onClick:()=>f(t.name),className:"w-full justify-start px-2.5 py-1.5 h-auto text-[12.5px] text-fg-muted hover:text-fg rounded-lg hover:bg-black/[0.04] dark:hover:bg-white/[0.06]"})})]})}function wpe(){const{t}=Cn(),e=ue(A=>A.columns),n=ue(A=>A.density),a=ue(A=>A.filters),i=ue(A=>A.moveTask),r=ue(A=>A.addColumn),s=ue(A=>A.searchMatches),o=ue(A=>A.config),[c,p]=$.useState(null),[d,m]=$.useState(null),f=$.useMemo(()=>e.map(A=>{const S=A.tasks.filter(E=>{if(a.search){const P=a.search.toLowerCase(),M=E.title.toLowerCase().includes(P)||E.id.toLowerCase().includes(P),j=s.has(E.id);if(!M&&!j)return!1}return!(o.fields.priority&&a.priority&&E.priority!==a.priority||o.fields.tags&&a.tag&&!(E.tags||[]).includes(a.tag)||o.fields.assignee&&a.assignee&&E.assignee!==a.assignee||o.fields.ownerType&&a.ownerType&&E.ownerType!==a.ownerType)});return{column:A,filtered:S}}),[e,o.fields,a,s]),h=(A,S)=>{p(A),m(S)},b=()=>{p(null),m(null)},k=A=>{c&&d&&i(c,d,A),p(null),m(null)},w=()=>{const A=window.prompt(t("column.createPrompt"))?.trim();A&&r(A)};return _.jsxs(lt.div,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.25},className:`flex-1 min-h-0 flex gap-5 p-5 pb-6 overflow-x-auto overflow-y-hidden relative ${o.ui.background==="solid"?"board-bg":""}`,children:[f.map(({column:A,filtered:S},E)=>_.jsx(lt.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:E*.04,duration:.35,ease:[.32,.72,.35,1]},className:"h-full",children:_.jsx(kpe,{column:A,filteredTasks:S,searchMatches:a.search?s:new Map,density:n,draggedTaskId:c,draggedFromCol:d,onCardDragStart:h,onCardDragEnd:b,onDrop:k})},A.name)),_.jsx("button",{type:"button",onClick:w,className:"flex h-[120px] w-[220px] flex-none items-center justify-center rounded-[8px] border border-dashed border-border bg-bg/45 px-4 text-[13px] font-medium text-fg-muted transition-colors hover:border-border-strong hover:bg-bg-2 hover:text-fg",children:t("column.createColumn")})]})}function xpe(){const{t}=Cn(),e=ue(r=>r.archivedTasks),n=ue(r=>r.unarchiveTask),a=ue(r=>r.setShowArchives),i=ue(r=>r.openDrawer);return _.jsxs("div",{className:"flex flex-col h-full overflow-y-auto px-[5vw] py-6",children:[_.jsxs("div",{className:"flex items-center justify-between mb-5 max-w-5xl w-full",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(Zn.Archive,{size:18,className:"text-fg-muted"}),_.jsx("h2",{className:"text-[18px] font-semibold tracking-tight",children:t("header.archives")}),_.jsx("span",{className:"text-[13px] text-fg-muted tabular-nums",children:e.length})]}),_.jsx(na,{variant:"secondary",icon:"ArrowLeft",label:t("header.backToBoard"),onClick:()=>a(!1)})]}),e.length===0?_.jsx("div",{className:"text-fg-muted text-[14px] italic px-2 py-8",children:t("archive.empty")}):_.jsx("div",{className:"flex flex-col gap-1 max-w-3xl",children:e.map(r=>_.jsxs("div",{className:"group flex items-center gap-3 px-3 py-2 rounded-[6px] hover:bg-bg-3/80 dark:hover:bg-bg-1/60 transition-colors",children:[_.jsx("button",{onClick:()=>{a(!1),i(r.id)},className:"flex-1 text-left min-w-0",children:_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx("span",{className:"font-mono text-[11.5px] text-fg-muted flex-shrink-0",children:r.id.toUpperCase()}),_.jsx("span",{className:"text-[14px] text-fg truncate",children:r.title})]})}),_.jsx(na,{variant:"ghost",icon:"ArchiveRestore",label:t("drawer.restore"),onClick:()=>void n(r.id)})]},r.id))})]})}const Ape={P1:"#e5484d",P2:"#e9a23b",P3:"#3e63dd",P4:"#6e6e6e"};function Cpe({text:t,keyword:e}){if(!e)return _.jsx(_.Fragment,{children:t});const n=t.split(new RegExp(`(${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})`,"gi"));return _.jsx(_.Fragment,{children:n.map((a,i)=>a.toLowerCase()===e.toLowerCase()?_.jsx("mark",{className:"bg-yellow-200/60 text-fg rounded px-0.5 font-semibold",children:a},i):_.jsx("span",{children:a},i))})}function Npe(){const{t}=Cn(),e=ue(p=>p.columns),n=ue(p=>p.filters),a=ue(p=>p.openDrawer),i=ue(p=>p.searchMatches),r=ue(p=>p.config.fields),s=$.useMemo(()=>{const p=[];for(const d of e)for(const m of d.tasks){if(n.search){const f=n.search.toLowerCase(),h=m.title.toLowerCase().includes(f)||m.id.toLowerCase().includes(f),b=i.has(m.id);if(!h&&!b)continue}r.priority&&n.priority&&m.priority!==n.priority||r.tags&&n.tag&&!(m.tags||[]).includes(n.tag)||r.assignee&&n.assignee&&m.assignee!==n.assignee||r.ownerType&&n.ownerType&&m.ownerType!==n.ownerType||p.push({task:m,column:d.name})}return p},[e,r,n,i]),c={gridTemplateColumns:["80px",r.priority?"40px":null,"1fr","140px",r.tags?"120px":null,r.assignee?"120px":null,"80px"].filter(Boolean).join("_").replaceAll("_"," ")};return _.jsx(lt.div,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.2},className:"flex-1 overflow-y-auto",children:_.jsxs("div",{className:"max-w-[1200px] mx-auto",children:[_.jsxs("div",{className:"grid grid-cols-[80px_40px_1fr_140px_120px_120px_80px] gap-3 px-6 py-2 text-[11.5px] font-semibold uppercase tracking-wider text-fg-faint border-b border-border sticky top-0 bg-bg z-10",children:[_.jsx("div",{children:t("listView.id")}),_.jsx("div",{}),_.jsx("div",{children:t("listView.title")}),_.jsx("div",{children:t("listView.status")}),_.jsx("div",{children:t("listView.tags")}),_.jsx("div",{children:t("listView.assignee")}),_.jsx("div",{children:t("listView.progress")})]}),_.jsx(Sr,{children:s.map(({task:p,column:d},m)=>{const f=n.search?i.get(p.id)||[]:[],h=f.length>0;return _.jsxs("div",{children:[_.jsxs(lt.button,{layout:!0,initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0},transition:{delay:Math.min(m*.012,.2),duration:.2},onClick:()=>a(p.id),className:"w-full grid gap-3 px-6 py-2.5 text-[13.5px] border-b border-border hover:bg-bg-1 transition-colors text-left items-center",style:c,children:[_.jsx("span",{className:"font-mono text-[13px] font-bold text-fg-muted",children:p.id.replace(/^t/,"")}),r.priority&&_.jsx("span",{className:"flex items-center gap-1.5",children:p.priority&&_.jsx("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:Ape[p.priority]},title:p.priority})}),_.jsx("span",{className:`truncate ${p.checked?"line-through text-fg-muted":"text-fg"}`,children:p.title}),_.jsx("span",{className:"text-fg-dim text-[12.5px]",children:d}),r.tags&&_.jsx("span",{className:"flex flex-wrap gap-1",children:p.tags.slice(0,2).map(b=>_.jsx("span",{className:"text-[11.5px] px-1.5 py-0.5 rounded-[3px] bg-bg-2 border border-border text-fg-dim",children:b},b))}),r.assignee&&_.jsx("span",{className:"text-[12.5px] text-fg-dim",children:p.assignee?`@${p.assignee}`:""}),_.jsx("span",{className:"text-[12px] font-mono text-fg-muted tabular-nums",children:p.progress?`${p.progress.done}/${p.progress.total}`:""})]}),h&&_.jsx(lt.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"px-6 pb-2 grid gap-3",style:c,children:_.jsx("div",{className:`${r.priority?"col-start-3":"col-start-2"} flex flex-col gap-1`,children:f.slice(0,2).map((b,k)=>_.jsxs("div",{className:"text-[12px] text-fg-dim bg-bg rounded px-2 py-1 border border-border",children:[_.jsx("span",{className:"text-[10.5px] font-medium text-fg-muted uppercase tracking-wide mr-1.5",children:t(`sectionLabels.${b.section}`)||b.section}),_.jsx(Cpe,{text:b.snippet,keyword:b.keyword})]},k))})})]},p.id)})}),s.length===0&&_.jsx("div",{className:"py-20 text-center text-[13.5px] text-fg-muted",children:t("listView.noMatchingTasks")})]})})}const Spe=({className:t})=>_.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 150 150",className:t,fill:"currentColor",children:[_.jsx("path",{d:"m57.6 64.6 0.1-0.1v-31.3c-0.1-3.5-2.7-5.6-5.7-5.6h-16.3v59.6c0.2-1.3 0.9-2.6 1.7-3.2l20.2-19.4z"}),_.jsx("path",{d:"m87.6 43.8c-3.4 0.1-7.1 1.3-9.9 3.7l-38.5 38.7c-2.1 2.1-3.4 4.8-3.5 7.5v26.7l77.5-76.4v-0.2h-25.6z"}),_.jsx("path",{d:"m108.1 96.4-6 5-22.4-20.8-14.6 14.2 21.1 21.4-5 4.1c-0.6 0.5-0.3 0.9 0.2 0.9h27.6c0.4 0 0.7-0.4 0.7-0.6v-24.8c0-0.7-1.1-0.3-1.6 0.3v0.3z"})]});function $pe(){const{t}=Cn(),e=ue(s=>s.openFolder);ue(s=>s.openServerProject);const n=ue(s=>s.loading),a=ue(s=>s.recentProjects),i=ue(s=>s.openRecentProject);if(ue(s=>s.tryAutoOpenServerProject),!Oz())return _.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 px-10 text-center",children:[_.jsx("div",{className:"text-[22px] font-semibold tracking-tight text-fg",children:t("emptyState.unsupportedBrowser")}),_.jsx("div",{className:"text-[14px] text-fg-dim max-w-[440px] leading-relaxed",dangerouslySetInnerHTML:{__html:t("emptyState.unsupportedBrowserDesc")}})]});const r=Kt();return r&&n?_.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 px-10 text-center",children:[_.jsx("div",{className:"text-[22px] font-semibold tracking-tight text-fg",children:"Chargement…"}),_.jsx("div",{className:"text-[14px] text-fg-dim max-w-[440px] leading-relaxed",children:t("emptyState.serverModeLoadingDesc")??"Connexion au serveur…"})]}):_.jsxs(lt.div,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.3},className:"flex-1 flex flex-col items-center justify-start pt-32 gap-5 px-10 text-center board-bg relative",children:[_.jsx(lt.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.05},children:_.jsx(Spe,{className:"w-40 h-40 dark:text-white text-black"})}),_.jsx(lt.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.05},className:"text-[26px] font-semibold tracking-tight text-fg",children:t("app.name")}),r?_.jsx(_.Fragment,{children:_.jsx(lt.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.1},className:"text-[14.5px] text-fg-dim max-w-[480px] leading-relaxed",children:t("emptyState.serverModeDesc")??"Kandown est lancé en mode serveur. Le projet va se charger automatiquement."})}):_.jsxs(_.Fragment,{children:[_.jsx(lt.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.1},className:"text-[14.5px] text-fg-dim max-w-[480px] leading-relaxed",children:t("app.tagline")}),_.jsx(lt.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.1},className:"text-[14.5px] text-fg-dim max-w-[480px] leading-relaxed",dangerouslySetInnerHTML:{__html:t("emptyState.selectFolderDesc")}}),_.jsx(lt.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{delay:.15},children:_.jsx(na,{variant:"primary",label:t("common.selectFolder"),onClick:e,className:"h-10 px-6 text-[16px]",iconSize:20,icon:"Folder"})})]}),a.length>0&&_.jsxs(lt.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:.25},className:"mt-4 flex flex-col items-center gap-2",children:[_.jsx("div",{className:"text-[11.5px] font-semibold uppercase tracking-wider text-fg-faint",children:t("common.recent")}),_.jsx("div",{className:"flex flex-col gap-1 min-w-[220px]",children:a.slice(0,5).map(s=>_.jsx("button",{onClick:()=>i(s),className:"px-3 py-1.5 text-[13.5px] text-fg-dim hover:text-fg hover:bg-bg-2 rounded-[6px] transition-colors",children:s.name},s.id))})]})]})}const yu=new WeakMap,jy=new WeakMap,x_={current:[]};let I2=!1;const Lv=new Set,Cj=new Map;function Kz(t){const e=Array.from(t).sort((n,a)=>n instanceof _u&&n.options.deps.includes(a)?1:a instanceof _u&&a.options.deps.includes(n)?-1:0);for(const n of e){if(x_.current.includes(n))continue;x_.current.push(n),n.recompute();const a=jy.get(n);if(a)for(const i of a){const r=yu.get(i);r&&Kz(r)}}}function Epe(t){const e={prevVal:t.prevState,currentVal:t.state};for(const n of t.listeners)n(e)}function Ppe(t){const e={prevVal:t.prevState,currentVal:t.state};for(const n of t.listeners)n(e)}function Tpe(t){if(Lv.add(t),!I2)try{for(I2=!0;Lv.size>0;){const e=Array.from(Lv);Lv.clear();for(const n of e){const a=Cj.get(n)??n.prevState;n.prevState=a,Epe(n)}for(const n of e){const a=yu.get(n);a&&(x_.current.push(n),Kz(a))}for(const n of e){const a=yu.get(n);if(a)for(const i of a)Ppe(i)}}}finally{I2=!1,x_.current=[],Cj.clear()}}function Mpe(t){return typeof t=="function"}class v3{constructor(e,n){this.listeners=new Set,this.subscribe=a=>{var i,r;this.listeners.add(a);const s=(r=(i=this.options)==null?void 0:i.onSubscribe)==null?void 0:r.call(i,a,this);return()=>{this.listeners.delete(a),s?.()}},this.prevState=e,this.state=e,this.options=n}setState(e){var n,a,i;this.prevState=this.state,(n=this.options)!=null&&n.updateFn?this.state=this.options.updateFn(this.prevState)(e):Mpe(e)?this.state=e(this.prevState):this.state=e,(i=(a=this.options)==null?void 0:a.onUpdate)==null||i.call(a),Tpe(this)}}class _u{constructor(e){this.listeners=new Set,this._subscriptions=[],this.lastSeenDepValues=[],this.getDepVals=()=>{const n=this.options.deps.length,a=new Array(n),i=new Array(n);for(let r=0;r<n;r++){const s=this.options.deps[r];a[r]=s.prevState,i[r]=s.state}return this.lastSeenDepValues=i,{prevDepVals:a,currDepVals:i,prevVal:this.prevState??void 0}},this.recompute=()=>{var n,a;this.prevState=this.state;const i=this.getDepVals();this.state=this.options.fn(i),(a=(n=this.options).onUpdate)==null||a.call(n)},this.checkIfRecalculationNeededDeeply=()=>{for(const r of this.options.deps)r instanceof _u&&r.checkIfRecalculationNeededDeeply();let n=!1;const a=this.lastSeenDepValues,{currDepVals:i}=this.getDepVals();for(let r=0;r<i.length;r++)if(i[r]!==a[r]){n=!0;break}n&&this.recompute()},this.mount=()=>(this.registerOnGraph(),this.checkIfRecalculationNeededDeeply(),()=>{this.unregisterFromGraph();for(const n of this._subscriptions)n()}),this.subscribe=n=>{var a,i;this.listeners.add(n);const r=(i=(a=this.options).onSubscribe)==null?void 0:i.call(a,n,this);return()=>{this.listeners.delete(n),r?.()}},this.options=e,this.state=e.fn({prevDepVals:void 0,prevVal:void 0,currDepVals:this.getDepVals().currDepVals})}registerOnGraph(e=this.options.deps){for(const n of e)if(n instanceof _u)n.registerOnGraph(),this.registerOnGraph(n.options.deps);else if(n instanceof v3){let a=yu.get(n);a||(a=new Set,yu.set(n,a)),a.add(this);let i=jy.get(this);i||(i=new Set,jy.set(this,i)),i.add(n)}}unregisterFromGraph(e=this.options.deps){for(const n of e)if(n instanceof _u)this.unregisterFromGraph(n.options.deps);else if(n instanceof v3){const a=yu.get(n);a&&a.delete(this);const i=jy.get(this);i&&i.delete(n)}}}var y3=Symbol("originalFactory");function Mt(t){if(typeof t=="object"&&"key"in t)return function e(){return t[y3]=e,t};if(typeof t!="function")throw Error("factory must be a function");return function e(n){return a=>{let i=t({editor:a.editor,options:n});return i[y3]=e,i}}}function vp(t,e){return new v3(t,e)}function Ca(t){this.content=t}Ca.prototype={constructor:Ca,find:function(t){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===t)return e;return-1},get:function(t){var e=this.find(t);return e==-1?void 0:this.content[e+1]},update:function(t,e,n){var a=n&&n!=t?this.remove(n):this,i=a.find(t),r=a.content.slice();return i==-1?r.push(n||t,e):(r[i+1]=e,n&&(r[i]=n)),new Ca(r)},remove:function(t){var e=this.find(t);if(e==-1)return this;var n=this.content.slice();return n.splice(e,2),new Ca(n)},addToStart:function(t,e){return new Ca([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var n=this.remove(t).content.slice();return n.push(t,e),new Ca(n)},addBefore:function(t,e,n){var a=this.remove(e),i=a.content.slice(),r=a.find(t);return i.splice(r==-1?i.length:r,0,e,n),new Ca(i)},forEach:function(t){for(var e=0;e<this.content.length;e+=2)t(this.content[e],this.content[e+1])},prepend:function(t){return t=Ca.from(t),t.size?new Ca(t.content.concat(this.subtract(t).content)):this},append:function(t){return t=Ca.from(t),t.size?new Ca(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var e=this;t=Ca.from(t);for(var n=0;n<t.content.length;n+=2)e=e.remove(t.content[n]);return e},toObject:function(){var t={};return this.forEach(function(e,n){t[e]=n}),t},get size(){return this.content.length>>1}};Ca.from=function(t){if(t instanceof Ca)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new Ca(e)};function Yz(t,e,n){for(let a=0;;a++){if(a==t.childCount||a==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(a),r=e.child(a);if(i==r){n+=i.nodeSize;continue}if(!i.sameMarkup(r))return n;if(i.isText&&i.text!=r.text){for(let s=0;i.text[s]==r.text[s];s++)n++;return n}if(i.content.size||r.content.size){let s=Yz(i.content,r.content,n+1);if(s!=null)return s}n+=i.nodeSize}}function Xz(t,e,n,a){for(let i=t.childCount,r=e.childCount;;){if(i==0||r==0)return i==r?null:{a:n,b:a};let s=t.child(--i),o=e.child(--r),c=s.nodeSize;if(s==o){n-=c,a-=c;continue}if(!s.sameMarkup(o))return{a:n,b:a};if(s.isText&&s.text!=o.text){let p=0,d=Math.min(s.text.length,o.text.length);for(;p<d&&s.text[s.text.length-p-1]==o.text[o.text.length-p-1];)p++,n--,a--;return{a:n,b:a}}if(s.content.size||o.content.size){let p=Xz(s.content,o.content,n-1,a-1);if(p)return p}n-=c,a-=c}}class le{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let a=0;a<e.length;a++)this.size+=e[a].nodeSize}nodesBetween(e,n,a,i=0,r){for(let s=0,o=0;o<n;s++){let c=this.content[s],p=o+c.nodeSize;if(p>e&&a(c,i+o,r||null,s)!==!1&&c.content.size){let d=o+1;c.nodesBetween(Math.max(0,e-d),Math.min(c.content.size,n-d),a,i+d)}o=p}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,a,i){let r="",s=!0;return this.nodesBetween(e,n,(o,c)=>{let p=o.isText?o.text.slice(Math.max(e,c)-c,n-c):o.isLeaf?i?typeof i=="function"?i(o):i:o.type.spec.leafText?o.type.spec.leafText(o):"":"";o.isBlock&&(o.isLeaf&&p||o.isTextblock)&&a&&(s?s=!1:r+=a),r+=p},0),r}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,a=e.firstChild,i=this.content.slice(),r=0;for(n.isText&&n.sameMarkup(a)&&(i[i.length-1]=n.withText(n.text+a.text),r=1);r<e.content.length;r++)i.push(e.content[r]);return new le(i,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let a=[],i=0;if(n>e)for(let r=0,s=0;s<n;r++){let o=this.content[r],c=s+o.nodeSize;c>e&&((s<e||c>n)&&(o.isText?o=o.cut(Math.max(0,e-s),Math.min(o.text.length,n-s)):o=o.cut(Math.max(0,e-s-1),Math.min(o.content.size,n-s-1))),a.push(o),i+=o.nodeSize),s=c}return new le(a,i)}cutByIndex(e,n){return e==n?le.empty:e==0&&n==this.content.length?this:new le(this.content.slice(e,n))}replaceChild(e,n){let a=this.content[e];if(a==n)return this;let i=this.content.slice(),r=this.size+n.nodeSize-a.nodeSize;return i[e]=n,new le(i,r)}addToStart(e){return new le([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new le(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(e.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let n=this.content[e];if(!n)throw new RangeError("Index "+e+" out of range for "+this);return n}maybeChild(e){return this.content[e]||null}forEach(e){for(let n=0,a=0;n<this.content.length;n++){let i=this.content[n];e(i,a,n),a+=i.nodeSize}}findDiffStart(e,n=0){return Yz(this,e,n)}findDiffEnd(e,n=this.size,a=e.size){return Xz(this,e,n,a)}findIndex(e){if(e==0)return jv(0,e);if(e==this.size)return jv(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,a=0;;n++){let i=this.child(n),r=a+i.nodeSize;if(r>=e)return r==e?jv(n+1,r):jv(n,a);a=r}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return le.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new le(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return le.empty;let n,a=0;for(let i=0;i<e.length;i++){let r=e[i];a+=r.nodeSize,i&&r.isText&&e[i-1].sameMarkup(r)?(n||(n=e.slice(0,i)),n[n.length-1]=r.withText(n[n.length-1].text+r.text)):n&&n.push(r)}return new le(n||e,a)}static from(e){if(!e)return le.empty;if(e instanceof le)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new le([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}le.empty=new le([],0);const R2={index:0,offset:0};function jv(t,e){return R2.index=t,R2.offset=e,R2}function A_(t,e){if(t===e)return!0;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let a=0;a<t.length;a++)if(!A_(t[a],e[a]))return!1}else{for(let a in t)if(!(a in e)||!A_(t[a],e[a]))return!1;for(let a in e)if(!(a in t))return!1}return!0}let en=class _3{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,a=!1;for(let i=0;i<e.length;i++){let r=e[i];if(this.eq(r))return e;if(this.type.excludes(r.type))n||(n=e.slice(0,i));else{if(r.type.excludes(this.type))return e;!a&&r.type.rank>this.type.rank&&(n||(n=e.slice(0,i)),n.push(this),a=!0),n&&n.push(r)}}return n||(n=e.slice()),a||n.push(this),n}removeFromSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return e.slice(0,n).concat(e.slice(n+1));return e}isInSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return!0;return!1}eq(e){return this==e||this.type==e.type&&A_(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let a=e.marks[n.type];if(!a)throw new RangeError(`There is no mark type ${n.type} in this schema`);let i=a.create(n.attrs);return a.checkAttrs(i.attrs),i}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let a=0;a<e.length;a++)if(!e[a].eq(n[a]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return _3.none;if(e instanceof _3)return[e];let n=e.slice();return n.sort((a,i)=>a.type.rank-i.type.rank),n}};en.none=[];class C_ extends Error{}class Ae{constructor(e,n,a){this.content=e,this.openStart=n,this.openEnd=a}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let a=Jz(this.content,e+this.openStart,n);return a&&new Ae(a,this.openStart,this.openEnd)}removeBetween(e,n){return new Ae(Qz(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return Ae.empty;let a=n.openStart||0,i=n.openEnd||0;if(typeof a!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new Ae(le.fromJSON(e,n.content),a,i)}static maxOpen(e,n=!0){let a=0,i=0;for(let r=e.firstChild;r&&!r.isLeaf&&(n||!r.type.spec.isolating);r=r.firstChild)a++;for(let r=e.lastChild;r&&!r.isLeaf&&(n||!r.type.spec.isolating);r=r.lastChild)i++;return new Ae(e,a,i)}}Ae.empty=new Ae(le.empty,0,0);function Qz(t,e,n){let{index:a,offset:i}=t.findIndex(e),r=t.maybeChild(a),{index:s,offset:o}=t.findIndex(n);if(i==e||r.isText){if(o!=n&&!t.child(s).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(a!=s)throw new RangeError("Removing non-flat range");return t.replaceChild(a,r.copy(Qz(r.content,e-i-1,n-i-1)))}function Jz(t,e,n,a){let{index:i,offset:r}=t.findIndex(e),s=t.maybeChild(i);if(r==e||s.isText)return a&&!a.canReplace(i,i,n)?null:t.cut(0,e).append(n).append(t.cut(e));let o=Jz(s.content,e-r-1,n,s);return o&&t.replaceChild(i,s.copy(o))}function Lpe(t,e,n){if(n.openStart>t.depth)throw new C_("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new C_("Inconsistent open depths");return eH(t,e,n,0)}function eH(t,e,n,a){let i=t.index(a),r=t.node(a);if(i==e.index(a)&&a<t.depth-n.openStart){let s=eH(t,e,n,a+1);return r.copy(r.content.replaceChild(i,s))}else if(n.content.size)if(!n.openStart&&!n.openEnd&&t.depth==a&&e.depth==a){let s=t.parent,o=s.content;return _l(s,o.cut(0,t.parentOffset).append(n.content).append(o.cut(e.parentOffset)))}else{let{start:s,end:o}=jpe(n,t);return _l(r,nH(t,s,o,e,a))}else return _l(r,N_(t,e,a))}function tH(t,e){if(!e.type.compatibleContent(t.type))throw new C_("Cannot join "+e.type.name+" onto "+t.type.name)}function k3(t,e,n){let a=t.node(n);return tH(a,e.node(n)),a}function yl(t,e){let n=e.length-1;n>=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function pg(t,e,n,a){let i=(e||t).node(n),r=0,s=e?e.index(n):i.childCount;t&&(r=t.index(n),t.depth>n?r++:t.textOffset&&(yl(t.nodeAfter,a),r++));for(let o=r;o<s;o++)yl(i.child(o),a);e&&e.depth==n&&e.textOffset&&yl(e.nodeBefore,a)}function _l(t,e){return t.type.checkContent(e),t.copy(e)}function nH(t,e,n,a,i){let r=t.depth>i&&k3(t,e,i+1),s=a.depth>i&&k3(n,a,i+1),o=[];return pg(null,t,i,o),r&&s&&e.index(i)==n.index(i)?(tH(r,s),yl(_l(r,nH(t,e,n,a,i+1)),o)):(r&&yl(_l(r,N_(t,e,i+1)),o),pg(e,n,i,o),s&&yl(_l(s,N_(n,a,i+1)),o)),pg(a,null,i,o),new le(o)}function N_(t,e,n){let a=[];if(pg(null,t,n,a),t.depth>n){let i=k3(t,e,n+1);yl(_l(i,N_(t,e,n+1)),a)}return pg(e,null,n,a),new le(a)}function jpe(t,e){let n=e.depth-t.openStart,i=e.node(n).copy(t.content);for(let r=n-1;r>=0;r--)i=e.node(r).copy(le.from(i));return{start:i.resolveNoCache(t.openStart+n),end:i.resolveNoCache(i.content.size-t.openEnd-n)}}class Og{constructor(e,n,a){this.pos=e,this.path=n,this.parentOffset=a,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let a=this.pos-this.path[this.path.length-1],i=e.child(n);return a?e.child(n).cut(a):i}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let a=this.path[n*3],i=n==0?0:this.path[n*3-1]+1;for(let r=0;r<e;r++)i+=a.child(r).nodeSize;return i}marks(){let e=this.parent,n=this.index();if(e.content.size==0)return en.none;if(this.textOffset)return e.child(n).marks;let a=e.maybeChild(n-1),i=e.maybeChild(n);if(!a){let o=a;a=i,i=o}let r=a.marks;for(var s=0;s<r.length;s++)r[s].type.spec.inclusive===!1&&(!i||!r[s].isInSet(i.marks))&&(r=r[s--].removeFromSet(r));return r}marksAcross(e){let n=this.parent.maybeChild(this.index());if(!n||!n.isInline)return null;let a=n.marks,i=e.parent.maybeChild(e.index());for(var r=0;r<a.length;r++)a[r].type.spec.inclusive===!1&&(!i||!a[r].isInSet(i.marks))&&(a=a[r--].removeFromSet(a));return a}sharedDepth(e){for(let n=this.depth;n>0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos<this.pos)return e.blockRange(this);for(let a=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);a>=0;a--)if(e.pos<=this.end(a)&&(!n||n(this.node(a))))return new Fg(this,e,a);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let n=1;n<=this.depth;n++)e+=(e?"/":"")+this.node(n).type.name+"_"+this.index(n-1);return e+":"+this.parentOffset}static resolve(e,n){if(!(n>=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let a=[],i=0,r=n;for(let s=e;;){let{index:o,offset:c}=s.content.findIndex(r),p=r-c;if(a.push(s,o,i+c),!p||(s=s.child(o),s.isText))break;r=p-1,i+=c+1}return new Og(n,a,r)}static resolveCached(e,n){let a=Nj.get(e);if(a)for(let r=0;r<a.elts.length;r++){let s=a.elts[r];if(s.pos==n)return s}else Nj.set(e,a=new Dpe);let i=a.elts[a.i]=Og.resolve(e,n);return a.i=(a.i+1)%Ipe,i}}class Dpe{constructor(){this.elts=[],this.i=0}}const Ipe=12,Nj=new WeakMap;class Fg{constructor(e,n,a){this.$from=e,this.$to=n,this.depth=a}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const Rpe=Object.create(null);let Oo=class w3{constructor(e,n,a,i=en.none){this.type=e,this.attrs=n,this.marks=i,this.content=a||le.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,n,a,i=0){this.content.nodesBetween(e,n,a,i,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,n,a,i){return this.content.textBetween(e,n,a,i)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,n,a){return this.type==e&&A_(this.attrs,n||e.defaultAttrs||Rpe)&&en.sameSet(this.marks,a||en.none)}copy(e=null){return e==this.content?this:new w3(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new w3(this.type,this.attrs,this.content,e)}cut(e,n=this.content.size){return e==0&&n==this.content.size?this:this.copy(this.content.cut(e,n))}slice(e,n=this.content.size,a=!1){if(e==n)return Ae.empty;let i=this.resolve(e),r=this.resolve(n),s=a?0:i.sharedDepth(n),o=i.start(s),p=i.node(s).content.cut(i.pos-o,r.pos-o);return new Ae(p,i.depth-s,r.depth-s)}replace(e,n,a){return Lpe(this.resolve(e),this.resolve(n),a)}nodeAt(e){for(let n=this;;){let{index:a,offset:i}=n.content.findIndex(e);if(n=n.maybeChild(a),!n)return null;if(i==e||n.isText)return n;e-=i+1}}childAfter(e){let{index:n,offset:a}=this.content.findIndex(e);return{node:this.content.maybeChild(n),index:n,offset:a}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:n,offset:a}=this.content.findIndex(e);if(a<e)return{node:this.content.child(n),index:n,offset:a};let i=this.content.child(n-1);return{node:i,index:n-1,offset:a-i.nodeSize}}resolve(e){return Og.resolveCached(this,e)}resolveNoCache(e){return Og.resolve(this,e)}rangeHasMark(e,n,a){let i=!1;return n>e&&this.nodesBetween(e,n,r=>(a.isInSet(r.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),aH(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,a=le.empty,i=0,r=a.childCount){let s=this.contentMatchAt(e).matchFragment(a,i,r),o=s&&s.matchFragment(this.content,n);if(!o||!o.validEnd)return!1;for(let c=i;c<r;c++)if(!this.type.allowsMarks(a.child(c).marks))return!1;return!0}canReplaceWith(e,n,a,i){if(i&&!this.type.allowsMarks(i))return!1;let r=this.contentMatchAt(e).matchType(a),s=r&&r.matchFragment(this.content,n);return s?s.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=en.none;for(let n=0;n<this.marks.length;n++){let a=this.marks[n];a.type.checkAttrs(a.attrs),e=a.addToSet(e)}if(!en.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(n=>n.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let a;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");a=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,a)}let i=le.fromJSON(e,n.content),r=e.nodeType(n.type).create(n.attrs,i,a);return r.type.checkAttrs(r.attrs),r}};Oo.prototype.text=void 0;class S_ extends Oo{constructor(e,n,a,i){if(super(e,n,null,i),!a)throw new RangeError("Empty text nodes are not allowed");this.text=a}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):aH(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new S_(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new S_(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function aH(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class El{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let a=new Ope(e,n);if(a.next==null)return El.empty;let i=iH(a);a.next&&a.err("Unexpected trailing text");let r=Vpe(Upe(i));return Zpe(r,a),r}matchType(e){for(let n=0;n<this.next.length;n++)if(this.next[n].type==e)return this.next[n].next;return null}matchFragment(e,n=0,a=e.childCount){let i=this;for(let r=n;i&&r<a;r++)i=i.matchType(e.child(r).type);return i}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:n}=this.next[e];if(!(n.isText||n.hasRequiredAttrs()))return n}return null}compatible(e){for(let n=0;n<this.next.length;n++)for(let a=0;a<e.next.length;a++)if(this.next[n].type==e.next[a].type)return!0;return!1}fillBefore(e,n=!1,a=0){let i=[this];function r(s,o){let c=s.matchFragment(e,a);if(c&&(!n||c.validEnd))return le.from(o.map(p=>p.createAndFill()));for(let p=0;p<s.next.length;p++){let{type:d,next:m}=s.next[p];if(!(d.isText||d.hasRequiredAttrs())&&i.indexOf(m)==-1){i.push(m);let f=r(m,o.concat(d));if(f)return f}}return null}return r(this,[])}findWrapping(e){for(let a=0;a<this.wrapCache.length;a+=2)if(this.wrapCache[a]==e)return this.wrapCache[a+1];let n=this.computeWrapping(e);return this.wrapCache.push(e,n),n}computeWrapping(e){let n=Object.create(null),a=[{match:this,type:null,via:null}];for(;a.length;){let i=a.shift(),r=i.match;if(r.matchType(e)){let s=[];for(let o=i;o.type;o=o.via)s.push(o.type);return s.reverse()}for(let s=0;s<r.next.length;s++){let{type:o,next:c}=r.next[s];!o.isLeaf&&!o.hasRequiredAttrs()&&!(o.name in n)&&(!i.type||c.validEnd)&&(a.push({match:o.contentMatch,type:o,via:i}),n[o.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(a){e.push(a);for(let i=0;i<a.next.length;i++)e.indexOf(a.next[i].next)==-1&&n(a.next[i].next)}return n(this),e.map((a,i)=>{let r=i+(a.validEnd?"*":" ")+" ";for(let s=0;s<a.next.length;s++)r+=(s?", ":"")+a.next[s].type.name+"->"+e.indexOf(a.next[s].next);return r}).join(`
|
|
231
|
+
*/const ape=[["path",{d:"M4 7l16 0",key:"svg-0"}],["path",{d:"M10 11l0 6",key:"svg-1"}],["path",{d:"M14 11l0 6",key:"svg-2"}],["path",{d:"M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12",key:"svg-3"}],["path",{d:"M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3",key:"svg-4"}]],ipe=On("outline","trash","Trash",ape),rpe={priority:"Priority",assignee:"Assignee",tags:"Tags",due:"Due",ownerType:"Owner",tools:"Tools"},spe=new Set(["report"]);function ope(t){return rpe[t]??t.charAt(0).toUpperCase()+t.slice(1).replace(/_/g," ")}function cpe(t){if(!/^\d{4}-\d{2}-\d{2}/.test(t))return!1;const e=new Date(t);return!isNaN(e.getTime())}function ppe(t,e){if(e==null)return null;if(Array.isArray(e))return _.jsx("span",{className:"flex flex-wrap gap-1",children:e.map((n,a)=>_.jsx("span",{className:"inline-flex items-center h-[18px] px-1.5 rounded bg-black/[0.04] dark:bg-white/[0.08] border border-border/60 text-fg-dim",children:String(n)},a))});if(typeof e=="string"){if(t==="due"||cpe(e)){const n=new Date(e);if(!isNaN(n.getTime()))return _.jsx("span",{className:"text-fg-dim",children:n.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})})}return _.jsx("span",{className:"text-fg-dim break-words",children:e})}return typeof e=="boolean"?_.jsx("span",{className:"text-fg-dim",children:e?"yes":"no"}):typeof e=="number"?_.jsx("span",{className:"text-fg-dim",children:e}):_.jsx("span",{className:"text-fg-dim",children:String(e)})}function lpe({frontmatter:t,hidden:e}){if(e)return null;const n=Object.entries(t).filter(([a,i])=>!(spe.has(a)||i==null||i===""||Array.isArray(i)&&i.length===0));return n.length===0?null:_.jsx("div",{className:"mt-2.5 pt-2 border-t border-border/60 space-y-1",children:n.map(([a,i])=>_.jsxs("div",{className:"flex items-start gap-2 text-[11.5px] leading-snug",children:[_.jsx("span",{className:"text-fg-muted/80 font-medium flex-shrink-0 min-w-[64px]",children:ope(a)}),_.jsx("span",{className:"flex-1 min-w-0",children:ppe(a,i)})]},a))})}function dpe({text:t,keyword:e}){if(!e)return _.jsx(_.Fragment,{children:t});const n=t.split(new RegExp(`(${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})`,"gi"));return _.jsx(_.Fragment,{children:n.map((a,i)=>a.toLowerCase()===e.toLowerCase()?_.jsx("mark",{className:"bg-yellow-200/60 text-fg rounded px-0.5 font-semibold",children:a},i):_.jsx("span",{children:a},i))})}function Gz({task:t,searchMatches:e=[],density:n,onDragStart:a,onDragEnd:i,columnName:r,doneTags:s}){const{t:o}=Cn(),c=ue(O=>O.openDrawer),p=ue(O=>O.deleteTask),d=ue(O=>O.showMetadata),[m,f]=$.useState(!1),[h,b]=$.useState(!1),k=$.useRef(!0),w=n==="compact",A=t.progress&&t.progress.total>0?Math.round(t.progress.done/t.progress.total*100):0,S=t.progress&&t.progress.done===t.progress.total,E={onDragStart:a,onDragEnd:i},P=t.title.match(/^\[([^\]]+)\]\s*/),M=P?`[${P[1]}]`:"",j=P?t.title.slice(P[0].length):t.title,z=e.length>0&&!w;$.useEffect(()=>()=>{k.current=!1},[]),$.useEffect(()=>{if(!m)return;const O=window.setTimeout(()=>f(!1),2400);return()=>window.clearTimeout(O)},[m]);const H=async O=>{if(O.stopPropagation(),O.preventDefault(),!h){if(!m){f(!0);return}b(!0),await p(t.id),k.current&&(b(!1),f(!1))}};return _.jsxs(lt.div,{layout:!0,layoutId:t.id,transition:{type:"spring",stiffness:500,damping:40,mass:.8},initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,scale:.95,transition:{duration:.12}},whileHover:{y:-1},whileTap:{scale:.99},draggable:!0,...E,onClick:()=>c(t.id),onMouseLeave:()=>f(!1),"data-task-id":t.id,"data-col":r,className:`group relative cursor-pointer rounded-lg border border-border bg-card shadow-[0_1px_2px_rgba(0,0,0,0.04)] transition-all duration-150 hover:border-border-strong hover:shadow-[0_2px_8px_rgba(0,0,0,0.06)] ${t.checked?"opacity-70":""}`,children:[_.jsx("div",{className:"absolute left-1.5 top-1/2 -translate-y-1/2 opacity-0 group-hover:opacity-40 transition-opacity cursor-grab active:cursor-grabbing",children:_.jsxs("svg",{width:"10",height:"16",viewBox:"0 0 10 16",fill:"currentColor",className:"text-fg-muted",children:[_.jsx("circle",{cx:"3",cy:"2",r:"1.5"}),_.jsx("circle",{cx:"7",cy:"2",r:"1.5"}),_.jsx("circle",{cx:"3",cy:"8",r:"1.5"}),_.jsx("circle",{cx:"7",cy:"8",r:"1.5"}),_.jsx("circle",{cx:"3",cy:"14",r:"1.5"}),_.jsx("circle",{cx:"7",cy:"14",r:"1.5"})]})}),_.jsx("button",{type:"button",draggable:!1,"aria-label":o(m?"card.confirmDelete":"card.delete"),title:o(m?"card.confirmDelete":"card.delete"),disabled:h,onClick:H,onPointerDown:O=>O.stopPropagation(),onBlur:()=>f(!1),className:`absolute right-2 top-2 z-10 inline-flex h-6 w-6 items-center justify-center rounded-md border transition-all ${m?"border-red-500 bg-red-500 text-white opacity-100 shadow-sm":"border-border bg-card/80 text-fg-muted opacity-0 hover:border-red-500/60 hover:bg-card hover:text-red-500 group-hover:opacity-100"} ${h?"pointer-events-none opacity-60":""}`,children:m?_.jsx(npe,{size:14,stroke:1.9}):_.jsx(ipe,{size:14,stroke:1.8})}),_.jsxs("div",{className:"px-3.5 pt-3 pb-1.5 flex items-center gap-1.5 flex-wrap",children:[_.jsx("span",{className:"font-mono text-[11.5px] font-medium text-fg-faint tabular-nums",children:t.id.replace(/^t/,"#")}),M&&_.jsx("span",{className:"inline-flex items-center h-[16px] px-1.5 text-[10px] font-semibold tracking-wide text-fg-muted uppercase rounded bg-black/[0.04] dark:bg-white/10",children:M}),t.dependsOn&&t.dependsOn.length>0&&_.jsxs("span",{className:"ml-auto inline-flex items-center gap-0.5 px-1.5 h-[16px] rounded text-[10.5px] font-semibold text-amber-700 dark:text-amber-300 bg-amber-500/10 border border-amber-500/20",title:o("card.blockedBy",{ids:t.dependsOn.join(", ")}),"aria-label":o("card.blockedBy",{ids:t.dependsOn.join(", ")}),children:["↪",t.dependsOn.length]})]}),_.jsxs("div",{className:"px-3.5 pb-1.5",children:[_.jsx("div",{className:`text-[13.5px] leading-snug font-medium ${t.checked?"line-through text-fg-muted":"text-fg"} ${w?"line-clamp-1":"line-clamp-2"}`,children:j}),z&&_.jsx("div",{className:"mt-2.5 space-y-1",children:e.slice(0,2).map((O,L)=>_.jsxs("div",{className:"text-[12px] text-fg-dim bg-black/[0.03] dark:bg-white/[0.04] rounded-lg px-2.5 py-1.5 border border-black/[0.05] dark:border-white/[0.08]",children:[_.jsx("span",{className:"text-[10px] font-semibold text-fg-muted uppercase tracking-wide mr-1.5",children:o(`sectionLabels.${O.section}`)||O.section}),_.jsx(dpe,{text:O.snippet,keyword:O.keyword})]},L))}),!w&&t.progress&&t.progress.total>0&&_.jsxs("div",{className:"mt-2.5 flex items-center gap-2 ",children:[_.jsx("div",{className:"flex-1 h-[3px] bg-black/[0.06] dark:bg-white/[0.1] rounded-full overflow-hidden",children:_.jsx(lt.div,{className:"h-full rounded-full",style:{backgroundColor:S?"#22c55e":"#737078"},initial:!1,animate:{width:`${A}%`},transition:{type:"spring",stiffness:160,damping:22}})}),_.jsxs("span",{className:"font-mono text-[11px] text-fg-muted tabular-nums",children:[t.progress.done,"/",t.progress.total]})]}),_.jsx(lpe,{frontmatter:t.frontmatter,hidden:d})]})]})}function upe({group:t,searchMatches:e,density:n,columnName:a,onCardDragStart:i,onCardDragEnd:r,defaultExpanded:s=!1,doneTags:o}){const{t:c}=Cn(),[p,d]=$.useState(s);$.useEffect(()=>{d(s)},[s]);const m=t.tasks.length,f=t.tasks[0],h=f.title.replace(/^\[([^\]]+)\]\s*/,"").replace(/#\w+\s*/,"").trim()||f.title;return p?_.jsxs(lt.div,{layout:!0,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,scale:.95,transition:{duration:.12}},className:"flex flex-col gap-2",children:[_.jsxs("button",{type:"button",onClick:()=>d(!1),className:"flex items-center gap-1.5 px-2 py-1 rounded-md text-[11px] font-semibold text-fg-muted/70 uppercase tracking-wide hover:bg-black/[0.04] dark:hover:bg-white/[0.06] transition-colors w-fit",children:[_.jsx(Lce,{size:13,stroke:2}),_.jsx("span",{children:t.displayKey}),_.jsx("span",{className:"font-normal text-fg-muted/40",children:m})]}),_.jsx(Sr,{mode:"popLayout",children:t.tasks.map(b=>_.jsx(Gz,{task:b,searchMatches:e.get(b.id)||[],density:n,columnName:a,doneTags:o,onDragStart:()=>i(b.id,a),onDragEnd:r},b.id))})]}):_.jsxs(lt.div,{layout:!0,initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,scale:.95,transition:{duration:.12}},transition:{type:"spring",stiffness:500,damping:40,mass:.8},onClick:()=>d(!0),className:"relative cursor-pointer pb-3",children:[m>2&&_.jsx("div",{className:"absolute inset-0 rounded-lg border border-border bg-card/40 pointer-events-none",style:{transform:"translateY(8px) scale(0.94)",zIndex:0}}),_.jsx("div",{className:"absolute inset-0 rounded-lg border border-border bg-card/60 pointer-events-none",style:{transform:"translateY(4px) scale(0.97)",zIndex:1}}),_.jsx(lt.div,{whileHover:{y:-1},whileTap:{scale:.99},className:"relative z-10 rounded-lg border border-border bg-card shadow-[0_1px_2px_rgba(0,0,0,0.04)] transition-all hover:border-border-strong hover:shadow-[0_2px_8px_rgba(0,0,0,0.06)]",children:_.jsxs("div",{className:"px-3.5 pt-3 pb-2.5",children:[_.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[_.jsxs("div",{className:"flex items-center gap-1.5",children:[_.jsx(Qce,{size:12,stroke:1.8,className:"text-fg-muted/60"}),_.jsx("span",{className:"text-[11px] font-semibold tracking-wide text-fg-muted uppercase",children:t.displayKey})]}),_.jsxs("div",{className:"flex items-center gap-1.5",children:[_.jsx("span",{className:"inline-flex items-center h-[18px] px-1.5 text-[10.5px] font-medium rounded-md text-fg-muted tabular-nums",children:m}),_.jsx(Ece,{size:12,stroke:2,className:"text-fg-muted/50"})]})]}),_.jsxs("div",{className:"text-[13.5px] leading-snug font-medium text-fg line-clamp-1",children:[h,m>1&&_.jsxs("span",{className:"text-fg-muted/50 ml-1.5",children:["+",m-1]})]})]})})]})}const mpe=/^\[([^\]]+)\]\s*/,fpe=/#(\w+)/;function Wz(t){const e=t.match(mpe);if(e)return`[${e[1].toLowerCase()}]`;const n=t.match(fpe);return n?`#${n[1].toLowerCase()}`:null}function gpe(t){return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function hpe(t){const e=new Map,n=new Map;for(const r of t){const s=Wz(r.title);e.set(r.id,s),s&&n.set(s,(n.get(s)??0)+1)}const a=[],i=new Map;for(const r of t){const s=e.get(r.id)??null;if(!s||(n.get(s)??0)<2){a.push({type:"single",task:r});continue}const o=i.get(s);if(o)o.tasks.push(r);else{const c={type:"stack",groupKey:s,displayKey:gpe(s),tasks:[r]};i.set(s,c),a.push(c)}}return a}const bpe={backlog:xj,icebox:xj,todo:j2,"to do":j2,ready:j2,doing:Mv,progress:Mv,"in progress":Mv,active:Mv,review:D2,qa:D2,verify:D2,done:L2,complete:L2,completed:L2};function vpe(t){const e=t.trim().toLowerCase();return bpe[e]??qce}const Aj={red:"rgba(239,68,68,0.06)",orange:"rgba(249,115,22,0.06)",amber:"rgba(245,158,11,0.06)",yellow:"rgba(234,179,8,0.06)",lime:"rgba(132,204,22,0.06)",green:"rgba(34,197,94,0.06)",emerald:"rgba(16,185,129,0.06)",teal:"rgba(20,184,166,0.06)",cyan:"rgba(6,182,212,0.06)",sky:"rgba(14,165,233,0.06)",blue:"rgba(59,130,246,0.06)",indigo:"rgba(99,102,241,0.06)",violet:"rgba(139,92,246,0.06)",purple:"rgba(168,85,247,0.06)",fuchsia:"rgba(217,70,239,0.06)",pink:"rgba(236,72,153,0.06)",rose:"rgba(244,63,94,0.06)",slate:"rgba(100,116,139,0.05)",gray:"rgba(255,255,255,0.025)",zinc:"rgba(113,113,122,0.05)",black:"rgba(0,0,0,0.24)",blackTransparent:"rgba(0,0,0,0.1)"},ype=[{key:"red",label:"Red",color:"rgba(239,68,68,0.9)"},{key:"orange",label:"Orange",color:"rgba(249,115,22,0.9)"},{key:"amber",label:"Amber",color:"rgba(245,158,11,0.9)"},{key:"yellow",label:"Yellow",color:"rgba(234,179,8,0.9)"},{key:"lime",label:"Lime",color:"rgba(132,204,22,0.9)"},{key:"green",label:"Green",color:"rgba(34,197,94,0.9)"},{key:"emerald",label:"Emerald",color:"rgba(16,185,129,0.9)"},{key:"teal",label:"Teal",color:"rgba(20,184,166,0.9)"},{key:"cyan",label:"Cyan",color:"rgba(6,182,212,0.9)"},{key:"sky",label:"Sky",color:"rgba(14,165,233,0.9)"},{key:"blue",label:"Blue",color:"rgba(59,130,246,0.9)"},{key:"indigo",label:"Indigo",color:"rgba(99,102,241,0.9)"},{key:"violet",label:"Violet",color:"rgba(139,92,246,0.9)"},{key:"purple",label:"Purple",color:"rgba(168,85,247,0.9)"},{key:"fuchsia",label:"Fuchsia",color:"rgba(217,70,239,0.9)"},{key:"pink",label:"Pink",color:"rgba(236,72,153,0.9)"},{key:"rose",label:"Rose",color:"rgba(244,63,94,0.9)"},{key:"slate",label:"Slate",color:"rgba(100,116,139,0.9)"},{key:"gray",label:"Gray",color:"rgba(156,163,175,0.9)"},{key:"zinc",label:"Zinc",color:"rgba(113,113,122,0.9)"},{key:"black",label:"Black",color:"rgba(0,0,0,0.9)"},{key:"blackTransparent",label:"Black 50%",color:"rgba(0,0,0,0.5)"}];function _pe({columnName:t,currentColor:e,onSelect:n}){const{t:a}=Cn(),[i,r]=$.useState(!1),s=$.useRef(null);return $.useEffect(()=>{if(!i)return;const o=c=>{s.current&&!s.current.contains(c.target)&&r(!1)};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[i]),_.jsxs("div",{ref:s,className:"relative",children:[_.jsx("button",{onClick:o=>{o.stopPropagation(),r(c=>!c)},className:"w-5 h-5 inline-flex items-center justify-center text-fg-muted hover:bg-bg-3 hover:text-fg rounded-[4px] transition-colors",title:a("column.columnColor"),children:_.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-60",children:[_.jsx("circle",{cx:"3",cy:"2",r:"1.2",fill:"currentColor"}),_.jsx("circle",{cx:"9",cy:"2",r:"1.2",fill:"currentColor"}),_.jsx("circle",{cx:"3",cy:"6",r:"1.2",fill:"currentColor"}),_.jsx("circle",{cx:"9",cy:"6",r:"1.2",fill:"currentColor"}),_.jsx("circle",{cx:"3",cy:"10",r:"1.2",fill:"currentColor"}),_.jsx("circle",{cx:"9",cy:"10",r:"1.2",fill:"currentColor"})]})}),_.jsx(Sr,{children:i&&_.jsxs(lt.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},transition:{duration:.12},className:"absolute right-0 top-full mt-1 bg-bg-2 border border-border rounded-[6px] shadow-lg p-1.5 z-50 min-w-[152px]",style:{transformOrigin:"top right"},children:[_.jsx("div",{className:"text-[11px] text-fg-muted px-1.5 pb-1.5 font-medium",children:a("column.color")}),_.jsx("div",{className:"grid grid-cols-5 gap-1",children:ype.map(({key:o,label:c,color:p})=>_.jsx("button",{onClick:d=>{d.stopPropagation(),n(o),r(!1)},title:c,className:`w-6 h-6 rounded-[4px] flex items-center justify-center transition-all ${e===o?"ring-2 ring-offset-1 ring-offset-bg-2 ring-fg":"hover:scale-110"}`,style:{backgroundColor:p},children:e===o&&_.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",className:"text-white",children:_.jsx("path",{d:"M2 5l2.5 2.5L8 3",stroke:"white",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})})},o))})]})})]})}function kpe({column:t,filteredTasks:e,searchMatches:n,density:a,draggedTaskId:i,draggedFromCol:r,onCardDragStart:s,onCardDragEnd:o,onDrop:c}){const{t:p}=Cn(),[d,m]=$.useState(!1),f=ue(q=>q.createTask),h=ue(q=>q.addColumn),b=ue(q=>q.renameColumn),k=ue(q=>q.deleteColumn),w=ue(q=>q.updateConfig),A=ue(q=>q.config),S=ue(q=>q.filters),E=A.board.columns.some(q=>q.toLowerCase()===t.name.toLowerCase()),P=$.useMemo(()=>hpe(e),[e]),M=$.useMemo(()=>{const q=new Map;for(const B of ue.getState().columns)for(const ne of B.tasks){const D=Wz(ne.title);D&&(q.has(D)||q.set(D,[]),q.get(D).push(ne))}const V=new Set;for(const[B,ne]of q)ne.every(D=>D.checked)&&V.add(B);return V},[]),j=A.board.columnColors?.[t.name.toLowerCase()]??"gray",z=Aj[j]??Aj.gray,H=q=>{w(V=>({...V,board:{...V.board,columnColors:{...V.board.columnColors??{},[t.name.toLowerCase()]:q}}}))},O=q=>{i&&(q.preventDefault(),q.dataTransfer.dropEffect="move",m(!0))},L=q=>{const V=q.relatedTarget;V&&q.currentTarget.contains(V)||m(!1)},W=q=>{q.preventDefault(),m(!1),i&&r!==t.name&&c(t.name)},X=e.length!==t.tasks.length,te=vpe(t.name),Z=()=>{const q=window.prompt(p("column.renamePrompt"),t.name)?.trim();!q||q===t.name||b(t.name,q)},Q=()=>{const q=p("column.deleteConfirm",{name:t.name,count:t.tasks.length});window.confirm(q)&&k(t.name)};return _.jsxs(lt.div,{layout:!0,initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.3,ease:[.32,.72,.35,1]},onDragOver:O,onDragLeave:L,onDrop:W,"data-column":t.name,className:"group flex flex-col flex-none w-[320px] h-full rounded-xl border border-border transition-colors duration-150",style:{backgroundColor:d?"rgba(255,255,255,0.04)":z},children:[_.jsxs("div",{className:"flex items-center justify-between px-3.5 pt-3 pb-2",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(te,{"aria-hidden":"true",size:14,stroke:1.8,className:"flex-none text-fg-muted"}),_.jsx("span",{className:"text-[12.5px] font-semibold tracking-tight text-fg",children:t.name}),_.jsxs("span",{className:"inline-flex items-center justify-center min-w-[20px] h-[18px] px-1.5 text-[10.5px] font-medium text-fg-muted rounded-md tabular-nums",children:[e.length,X&&_.jsxs("span",{className:"text-fg-faint",children:["/",t.tasks.length]})]})]}),_.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[!E&&_.jsx("button",{onClick:()=>h(t.name),className:"h-6 rounded-md px-2 text-[11px] font-medium text-fg-muted transition-colors hover:bg-black/[0.05] dark:hover:bg-white/[0.1] hover:text-fg",title:p("column.addToSettings"),children:p("column.addColumn")}),_.jsx("button",{onClick:()=>f(t.name),className:"w-6 h-6 inline-flex items-center justify-center text-fg-muted hover:bg-black/[0.05] dark:hover:bg-white/[0.1] hover:text-fg rounded-md transition-colors",title:p("column.addTask"),children:_.jsx(Zn.Plus,{size:14})}),_.jsx(_pe,{columnName:t.name.toLowerCase(),currentColor:j,onSelect:H}),_.jsx("button",{onClick:Z,className:"w-6 h-6 inline-flex items-center justify-center text-fg-muted hover:bg-black/[0.05] dark:hover:bg-white/[0.1] hover:text-fg rounded-md transition-colors",title:p("column.renameColumn"),children:_.jsx("span",{className:"text-[11px] leading-none",children:"✎"})}),_.jsx("button",{onClick:Q,className:"w-6 h-6 inline-flex items-center justify-center text-fg-muted hover:bg-red-500/10 hover:text-red-500 rounded-md transition-colors",title:p("column.deleteColumn"),children:_.jsx("span",{className:"text-[13px] leading-none",children:"×"})})]})]}),_.jsx("div",{className:"flex-1 min-h-0 px-2.5 scrollbar-always",style:{overflowY:"scroll"},children:_.jsx("div",{className:"flex flex-col gap-2 py-1",children:_.jsx(Sr,{mode:"popLayout",children:P.length===0?_.jsxs(lt.div,{initial:{opacity:0},animate:{opacity:1},className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[_.jsx("div",{className:"w-10 h-10 rounded-xl bg-black/[0.04] dark:bg-white/[0.08] flex items-center justify-center mb-3",children:_.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-muted/50",children:[_.jsx("path",{d:"M9 11l3 3L22 4"}),_.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})}),_.jsx("p",{className:"text-[13px] font-medium text-fg-muted/70",children:"No tasks yet"}),_.jsx("p",{className:"text-[12px] text-fg-muted/50 mt-0.5",children:"Drag tasks here to get started."})]}):P.map(q=>q.type==="single"?_.jsx(Gz,{task:q.task,searchMatches:n.get(q.task.id)||[],density:a,columnName:t.name,doneTags:M,onDragStart:()=>s(q.task.id,t.name),onDragEnd:o},q.task.id):_.jsx(upe,{group:q,searchMatches:n,density:a,columnName:t.name,doneTags:M,onCardDragStart:s,onCardDragEnd:o,defaultExpanded:A.board.stackDefaultState==="expanded"||!!S.search},`stack-${q.groupKey}`))})})}),_.jsx("div",{className:"flex-none px-2.5 pb-2.5 pt-1",children:_.jsx(na,{variant:"ghost",icon:"Plus",label:p("column.addTask"),onClick:()=>f(t.name),className:"w-full justify-start px-2.5 py-1.5 h-auto text-[12.5px] text-fg-muted hover:text-fg rounded-lg hover:bg-black/[0.04] dark:hover:bg-white/[0.06]"})})]})}function wpe(){const{t}=Cn(),e=ue(A=>A.columns),n=ue(A=>A.density),a=ue(A=>A.filters),i=ue(A=>A.moveTask),r=ue(A=>A.addColumn),s=ue(A=>A.searchMatches),o=ue(A=>A.config),[c,p]=$.useState(null),[d,m]=$.useState(null),f=$.useMemo(()=>e.map(A=>{const S=A.tasks.filter(E=>{if(a.search){const P=a.search.toLowerCase(),M=E.title.toLowerCase().includes(P)||E.id.toLowerCase().includes(P),j=s.has(E.id);if(!M&&!j)return!1}return!(o.fields.priority&&a.priority&&E.priority!==a.priority||o.fields.tags&&a.tag&&!(E.tags||[]).includes(a.tag)||o.fields.assignee&&a.assignee&&E.assignee!==a.assignee||o.fields.ownerType&&a.ownerType&&E.ownerType!==a.ownerType)});return{column:A,filtered:S}}),[e,o.fields,a,s]),h=(A,S)=>{p(A),m(S)},b=()=>{p(null),m(null)},k=A=>{c&&d&&i(c,d,A),p(null),m(null)},w=()=>{const A=window.prompt(t("column.createPrompt"))?.trim();A&&r(A)};return _.jsxs(lt.div,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.25},className:`flex-1 min-h-0 flex gap-5 p-5 pb-6 overflow-x-auto overflow-y-hidden relative ${o.ui.background==="solid"?"board-bg":""}`,children:[f.map(({column:A,filtered:S},E)=>_.jsx(lt.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:E*.04,duration:.35,ease:[.32,.72,.35,1]},className:"h-full",children:_.jsx(kpe,{column:A,filteredTasks:S,searchMatches:a.search?s:new Map,density:n,draggedTaskId:c,draggedFromCol:d,onCardDragStart:h,onCardDragEnd:b,onDrop:k})},A.name)),_.jsx("button",{type:"button",onClick:w,className:"flex h-[120px] w-[220px] flex-none items-center justify-center rounded-[8px] border border-dashed border-border bg-bg/45 px-4 text-[13px] font-medium text-fg-muted transition-colors hover:border-border-strong hover:bg-bg-2 hover:text-fg",children:t("column.createColumn")})]})}function xpe(){const{t}=Cn(),e=ue(r=>r.archivedTasks),n=ue(r=>r.unarchiveTask),a=ue(r=>r.setShowArchives),i=ue(r=>r.openDrawer);return _.jsxs("div",{className:"flex flex-col h-full overflow-y-auto px-[5vw] py-6",children:[_.jsxs("div",{className:"flex items-center justify-between mb-5 max-w-5xl w-full",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(Zn.Archive,{size:18,className:"text-fg-muted"}),_.jsx("h2",{className:"text-[18px] font-semibold tracking-tight",children:t("header.archives")}),_.jsx("span",{className:"text-[13px] text-fg-muted tabular-nums",children:e.length})]}),_.jsx(na,{variant:"secondary",icon:"ArrowLeft",label:t("header.backToBoard"),onClick:()=>a(!1)})]}),e.length===0?_.jsx("div",{className:"text-fg-muted text-[14px] italic px-2 py-8",children:t("archive.empty")}):_.jsx("div",{className:"flex flex-col gap-1 max-w-3xl",children:e.map(r=>_.jsxs("div",{className:"group flex items-center gap-3 px-3 py-2 rounded-[6px] hover:bg-bg-3/80 dark:hover:bg-bg-1/60 transition-colors",children:[_.jsx("button",{onClick:()=>{a(!1),i(r.id)},className:"flex-1 text-left min-w-0",children:_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx("span",{className:"font-mono text-[11.5px] text-fg-muted flex-shrink-0",children:r.id.toUpperCase()}),_.jsx("span",{className:"text-[14px] text-fg truncate",children:r.title})]})}),_.jsx(na,{variant:"ghost",icon:"ArchiveRestore",label:t("drawer.restore"),onClick:()=>void n(r.id)})]},r.id))})]})}const Ape={P1:"#e5484d",P2:"#e9a23b",P3:"#3e63dd",P4:"#6e6e6e"};function Cpe({text:t,keyword:e}){if(!e)return _.jsx(_.Fragment,{children:t});const n=t.split(new RegExp(`(${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})`,"gi"));return _.jsx(_.Fragment,{children:n.map((a,i)=>a.toLowerCase()===e.toLowerCase()?_.jsx("mark",{className:"bg-yellow-200/60 text-fg rounded px-0.5 font-semibold",children:a},i):_.jsx("span",{children:a},i))})}function Npe(){const{t}=Cn(),e=ue(p=>p.columns),n=ue(p=>p.filters),a=ue(p=>p.openDrawer),i=ue(p=>p.searchMatches),r=ue(p=>p.config.fields),s=$.useMemo(()=>{const p=[];for(const d of e)for(const m of d.tasks){if(n.search){const f=n.search.toLowerCase(),h=m.title.toLowerCase().includes(f)||m.id.toLowerCase().includes(f),b=i.has(m.id);if(!h&&!b)continue}r.priority&&n.priority&&m.priority!==n.priority||r.tags&&n.tag&&!(m.tags||[]).includes(n.tag)||r.assignee&&n.assignee&&m.assignee!==n.assignee||r.ownerType&&n.ownerType&&m.ownerType!==n.ownerType||p.push({task:m,column:d.name})}return p},[e,r,n,i]),c={gridTemplateColumns:["80px",r.priority?"40px":null,"1fr","140px",r.tags?"120px":null,r.assignee?"120px":null,"80px"].filter(Boolean).join("_").replaceAll("_"," ")};return _.jsx(lt.div,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.2},className:"flex-1 overflow-y-auto",children:_.jsxs("div",{className:"max-w-[1200px] mx-auto",children:[_.jsxs("div",{className:"grid grid-cols-[80px_40px_1fr_140px_120px_120px_80px] gap-3 px-6 py-2 text-[11.5px] font-semibold uppercase tracking-wider text-fg-faint border-b border-border sticky top-0 bg-bg z-10",children:[_.jsx("div",{children:t("listView.id")}),_.jsx("div",{}),_.jsx("div",{children:t("listView.title")}),_.jsx("div",{children:t("listView.status")}),_.jsx("div",{children:t("listView.tags")}),_.jsx("div",{children:t("listView.assignee")}),_.jsx("div",{children:t("listView.progress")})]}),_.jsx(Sr,{children:s.map(({task:p,column:d},m)=>{const f=n.search?i.get(p.id)||[]:[],h=f.length>0;return _.jsxs("div",{children:[_.jsxs(lt.button,{layout:!0,initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0},transition:{delay:Math.min(m*.012,.2),duration:.2},onClick:()=>a(p.id),className:"w-full grid gap-3 px-6 py-2.5 text-[13.5px] border-b border-border hover:bg-bg-1 transition-colors text-left items-center",style:c,children:[_.jsx("span",{className:"font-mono text-[13px] font-bold text-fg-muted",children:p.id.replace(/^t/,"")}),r.priority&&_.jsx("span",{className:"flex items-center gap-1.5",children:p.priority&&_.jsx("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:Ape[p.priority]},title:p.priority})}),_.jsx("span",{className:`truncate ${p.checked?"line-through text-fg-muted":"text-fg"}`,children:p.title}),_.jsx("span",{className:"text-fg-dim text-[12.5px]",children:d}),r.tags&&_.jsx("span",{className:"flex flex-wrap gap-1",children:p.tags.slice(0,2).map(b=>_.jsx("span",{className:"text-[11.5px] px-1.5 py-0.5 rounded-[3px] bg-bg-2 border border-border text-fg-dim",children:b},b))}),r.assignee&&_.jsx("span",{className:"text-[12.5px] text-fg-dim",children:p.assignee?`@${p.assignee}`:""}),_.jsx("span",{className:"text-[12px] font-mono text-fg-muted tabular-nums",children:p.progress?`${p.progress.done}/${p.progress.total}`:""})]}),h&&_.jsx(lt.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"px-6 pb-2 grid gap-3",style:c,children:_.jsx("div",{className:`${r.priority?"col-start-3":"col-start-2"} flex flex-col gap-1`,children:f.slice(0,2).map((b,k)=>_.jsxs("div",{className:"text-[12px] text-fg-dim bg-bg rounded px-2 py-1 border border-border",children:[_.jsx("span",{className:"text-[10.5px] font-medium text-fg-muted uppercase tracking-wide mr-1.5",children:t(`sectionLabels.${b.section}`)||b.section}),_.jsx(Cpe,{text:b.snippet,keyword:b.keyword})]},k))})})]},p.id)})}),s.length===0&&_.jsx("div",{className:"py-20 text-center text-[13.5px] text-fg-muted",children:t("listView.noMatchingTasks")})]})})}const Spe=({className:t})=>_.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 150 150",className:t,fill:"currentColor",children:[_.jsx("path",{d:"m57.6 64.6 0.1-0.1v-31.3c-0.1-3.5-2.7-5.6-5.7-5.6h-16.3v59.6c0.2-1.3 0.9-2.6 1.7-3.2l20.2-19.4z"}),_.jsx("path",{d:"m87.6 43.8c-3.4 0.1-7.1 1.3-9.9 3.7l-38.5 38.7c-2.1 2.1-3.4 4.8-3.5 7.5v26.7l77.5-76.4v-0.2h-25.6z"}),_.jsx("path",{d:"m108.1 96.4-6 5-22.4-20.8-14.6 14.2 21.1 21.4-5 4.1c-0.6 0.5-0.3 0.9 0.2 0.9h27.6c0.4 0 0.7-0.4 0.7-0.6v-24.8c0-0.7-1.1-0.3-1.6 0.3v0.3z"})]});function $pe(){const{t}=Cn(),e=ue(s=>s.openFolder);ue(s=>s.openServerProject);const n=ue(s=>s.loading),a=ue(s=>s.recentProjects),i=ue(s=>s.openRecentProject);if(ue(s=>s.tryAutoOpenServerProject),!Oz())return _.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 px-10 text-center",children:[_.jsx("div",{className:"text-[22px] font-semibold tracking-tight text-fg",children:t("emptyState.unsupportedBrowser")}),_.jsx("div",{className:"text-[14px] text-fg-dim max-w-[440px] leading-relaxed",dangerouslySetInnerHTML:{__html:t("emptyState.unsupportedBrowserDesc")}})]});const r=Kt();return r&&n?_.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 px-10 text-center",children:[_.jsx("div",{className:"text-[22px] font-semibold tracking-tight text-fg",children:"Chargement…"}),_.jsx("div",{className:"text-[14px] text-fg-dim max-w-[440px] leading-relaxed",children:t("emptyState.serverModeLoadingDesc")??"Connexion au serveur…"})]}):_.jsxs(lt.div,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.3},className:"flex-1 flex flex-col items-center justify-start pt-32 gap-5 px-10 text-center board-bg relative",children:[_.jsx(lt.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.05},children:_.jsx(Spe,{className:"w-40 h-40 dark:text-white text-black"})}),_.jsx(lt.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.05},className:"text-[26px] font-semibold tracking-tight text-fg",children:t("app.name")}),r?_.jsx(_.Fragment,{children:_.jsx(lt.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.1},className:"text-[14.5px] text-fg-dim max-w-[480px] leading-relaxed",children:t("emptyState.serverModeDesc")??"Kandown est lancé en mode serveur. Le projet va se charger automatiquement."})}):_.jsxs(_.Fragment,{children:[_.jsx(lt.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.1},className:"text-[14.5px] text-fg-dim max-w-[480px] leading-relaxed",children:t("app.tagline")}),_.jsx(lt.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.1},className:"text-[14.5px] text-fg-dim max-w-[480px] leading-relaxed",dangerouslySetInnerHTML:{__html:t("emptyState.selectFolderDesc")}}),_.jsx(lt.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{delay:.15},children:_.jsx(na,{variant:"primary",label:t("common.selectFolder"),onClick:e,className:"h-10 px-6 text-[16px]",iconSize:20,icon:"Folder"})})]}),a.length>0&&_.jsxs(lt.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:.25},className:"mt-4 flex flex-col items-center gap-2",children:[_.jsx("div",{className:"text-[11.5px] font-semibold uppercase tracking-wider text-fg-faint",children:t("common.recent")}),_.jsx("div",{className:"flex flex-col gap-1 min-w-[220px]",children:a.slice(0,5).map(s=>_.jsx("button",{onClick:()=>i(s),className:"px-3 py-1.5 text-[13.5px] text-fg-dim hover:text-fg hover:bg-bg-2 rounded-[6px] transition-colors",children:s.name},s.id))})]})]})}const yu=new WeakMap,jy=new WeakMap,x_={current:[]};let I2=!1;const Lv=new Set,Cj=new Map;function Kz(t){const e=Array.from(t).sort((n,a)=>n instanceof _u&&n.options.deps.includes(a)?1:a instanceof _u&&a.options.deps.includes(n)?-1:0);for(const n of e){if(x_.current.includes(n))continue;x_.current.push(n),n.recompute();const a=jy.get(n);if(a)for(const i of a){const r=yu.get(i);r&&Kz(r)}}}function Epe(t){const e={prevVal:t.prevState,currentVal:t.state};for(const n of t.listeners)n(e)}function Ppe(t){const e={prevVal:t.prevState,currentVal:t.state};for(const n of t.listeners)n(e)}function Tpe(t){if(Lv.add(t),!I2)try{for(I2=!0;Lv.size>0;){const e=Array.from(Lv);Lv.clear();for(const n of e){const a=Cj.get(n)??n.prevState;n.prevState=a,Epe(n)}for(const n of e){const a=yu.get(n);a&&(x_.current.push(n),Kz(a))}for(const n of e){const a=yu.get(n);if(a)for(const i of a)Ppe(i)}}}finally{I2=!1,x_.current=[],Cj.clear()}}function Mpe(t){return typeof t=="function"}class v3{constructor(e,n){this.listeners=new Set,this.subscribe=a=>{var i,r;this.listeners.add(a);const s=(r=(i=this.options)==null?void 0:i.onSubscribe)==null?void 0:r.call(i,a,this);return()=>{this.listeners.delete(a),s?.()}},this.prevState=e,this.state=e,this.options=n}setState(e){var n,a,i;this.prevState=this.state,(n=this.options)!=null&&n.updateFn?this.state=this.options.updateFn(this.prevState)(e):Mpe(e)?this.state=e(this.prevState):this.state=e,(i=(a=this.options)==null?void 0:a.onUpdate)==null||i.call(a),Tpe(this)}}class _u{constructor(e){this.listeners=new Set,this._subscriptions=[],this.lastSeenDepValues=[],this.getDepVals=()=>{const n=this.options.deps.length,a=new Array(n),i=new Array(n);for(let r=0;r<n;r++){const s=this.options.deps[r];a[r]=s.prevState,i[r]=s.state}return this.lastSeenDepValues=i,{prevDepVals:a,currDepVals:i,prevVal:this.prevState??void 0}},this.recompute=()=>{var n,a;this.prevState=this.state;const i=this.getDepVals();this.state=this.options.fn(i),(a=(n=this.options).onUpdate)==null||a.call(n)},this.checkIfRecalculationNeededDeeply=()=>{for(const r of this.options.deps)r instanceof _u&&r.checkIfRecalculationNeededDeeply();let n=!1;const a=this.lastSeenDepValues,{currDepVals:i}=this.getDepVals();for(let r=0;r<i.length;r++)if(i[r]!==a[r]){n=!0;break}n&&this.recompute()},this.mount=()=>(this.registerOnGraph(),this.checkIfRecalculationNeededDeeply(),()=>{this.unregisterFromGraph();for(const n of this._subscriptions)n()}),this.subscribe=n=>{var a,i;this.listeners.add(n);const r=(i=(a=this.options).onSubscribe)==null?void 0:i.call(a,n,this);return()=>{this.listeners.delete(n),r?.()}},this.options=e,this.state=e.fn({prevDepVals:void 0,prevVal:void 0,currDepVals:this.getDepVals().currDepVals})}registerOnGraph(e=this.options.deps){for(const n of e)if(n instanceof _u)n.registerOnGraph(),this.registerOnGraph(n.options.deps);else if(n instanceof v3){let a=yu.get(n);a||(a=new Set,yu.set(n,a)),a.add(this);let i=jy.get(this);i||(i=new Set,jy.set(this,i)),i.add(n)}}unregisterFromGraph(e=this.options.deps){for(const n of e)if(n instanceof _u)this.unregisterFromGraph(n.options.deps);else if(n instanceof v3){const a=yu.get(n);a&&a.delete(this);const i=jy.get(this);i&&i.delete(n)}}}var y3=Symbol("originalFactory");function Mt(t){if(typeof t=="object"&&"key"in t)return function e(){return t[y3]=e,t};if(typeof t!="function")throw Error("factory must be a function");return function e(n){return a=>{let i=t({editor:a.editor,options:n});return i[y3]=e,i}}}function vp(t,e){return new v3(t,e)}function Ca(t){this.content=t}Ca.prototype={constructor:Ca,find:function(t){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===t)return e;return-1},get:function(t){var e=this.find(t);return e==-1?void 0:this.content[e+1]},update:function(t,e,n){var a=n&&n!=t?this.remove(n):this,i=a.find(t),r=a.content.slice();return i==-1?r.push(n||t,e):(r[i+1]=e,n&&(r[i]=n)),new Ca(r)},remove:function(t){var e=this.find(t);if(e==-1)return this;var n=this.content.slice();return n.splice(e,2),new Ca(n)},addToStart:function(t,e){return new Ca([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var n=this.remove(t).content.slice();return n.push(t,e),new Ca(n)},addBefore:function(t,e,n){var a=this.remove(e),i=a.content.slice(),r=a.find(t);return i.splice(r==-1?i.length:r,0,e,n),new Ca(i)},forEach:function(t){for(var e=0;e<this.content.length;e+=2)t(this.content[e],this.content[e+1])},prepend:function(t){return t=Ca.from(t),t.size?new Ca(t.content.concat(this.subtract(t).content)):this},append:function(t){return t=Ca.from(t),t.size?new Ca(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var e=this;t=Ca.from(t);for(var n=0;n<t.content.length;n+=2)e=e.remove(t.content[n]);return e},toObject:function(){var t={};return this.forEach(function(e,n){t[e]=n}),t},get size(){return this.content.length>>1}};Ca.from=function(t){if(t instanceof Ca)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new Ca(e)};function Yz(t,e,n){for(let a=0;;a++){if(a==t.childCount||a==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(a),r=e.child(a);if(i==r){n+=i.nodeSize;continue}if(!i.sameMarkup(r))return n;if(i.isText&&i.text!=r.text){for(let s=0;i.text[s]==r.text[s];s++)n++;return n}if(i.content.size||r.content.size){let s=Yz(i.content,r.content,n+1);if(s!=null)return s}n+=i.nodeSize}}function Xz(t,e,n,a){for(let i=t.childCount,r=e.childCount;;){if(i==0||r==0)return i==r?null:{a:n,b:a};let s=t.child(--i),o=e.child(--r),c=s.nodeSize;if(s==o){n-=c,a-=c;continue}if(!s.sameMarkup(o))return{a:n,b:a};if(s.isText&&s.text!=o.text){let p=0,d=Math.min(s.text.length,o.text.length);for(;p<d&&s.text[s.text.length-p-1]==o.text[o.text.length-p-1];)p++,n--,a--;return{a:n,b:a}}if(s.content.size||o.content.size){let p=Xz(s.content,o.content,n-1,a-1);if(p)return p}n-=c,a-=c}}class le{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let a=0;a<e.length;a++)this.size+=e[a].nodeSize}nodesBetween(e,n,a,i=0,r){for(let s=0,o=0;o<n;s++){let c=this.content[s],p=o+c.nodeSize;if(p>e&&a(c,i+o,r||null,s)!==!1&&c.content.size){let d=o+1;c.nodesBetween(Math.max(0,e-d),Math.min(c.content.size,n-d),a,i+d)}o=p}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,a,i){let r="",s=!0;return this.nodesBetween(e,n,(o,c)=>{let p=o.isText?o.text.slice(Math.max(e,c)-c,n-c):o.isLeaf?i?typeof i=="function"?i(o):i:o.type.spec.leafText?o.type.spec.leafText(o):"":"";o.isBlock&&(o.isLeaf&&p||o.isTextblock)&&a&&(s?s=!1:r+=a),r+=p},0),r}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,a=e.firstChild,i=this.content.slice(),r=0;for(n.isText&&n.sameMarkup(a)&&(i[i.length-1]=n.withText(n.text+a.text),r=1);r<e.content.length;r++)i.push(e.content[r]);return new le(i,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let a=[],i=0;if(n>e)for(let r=0,s=0;s<n;r++){let o=this.content[r],c=s+o.nodeSize;c>e&&((s<e||c>n)&&(o.isText?o=o.cut(Math.max(0,e-s),Math.min(o.text.length,n-s)):o=o.cut(Math.max(0,e-s-1),Math.min(o.content.size,n-s-1))),a.push(o),i+=o.nodeSize),s=c}return new le(a,i)}cutByIndex(e,n){return e==n?le.empty:e==0&&n==this.content.length?this:new le(this.content.slice(e,n))}replaceChild(e,n){let a=this.content[e];if(a==n)return this;let i=this.content.slice(),r=this.size+n.nodeSize-a.nodeSize;return i[e]=n,new le(i,r)}addToStart(e){return new le([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new le(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(e.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let n=this.content[e];if(!n)throw new RangeError("Index "+e+" out of range for "+this);return n}maybeChild(e){return this.content[e]||null}forEach(e){for(let n=0,a=0;n<this.content.length;n++){let i=this.content[n];e(i,a,n),a+=i.nodeSize}}findDiffStart(e,n=0){return Yz(this,e,n)}findDiffEnd(e,n=this.size,a=e.size){return Xz(this,e,n,a)}findIndex(e){if(e==0)return jv(0,e);if(e==this.size)return jv(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,a=0;;n++){let i=this.child(n),r=a+i.nodeSize;if(r>=e)return r==e?jv(n+1,r):jv(n,a);a=r}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return le.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new le(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return le.empty;let n,a=0;for(let i=0;i<e.length;i++){let r=e[i];a+=r.nodeSize,i&&r.isText&&e[i-1].sameMarkup(r)?(n||(n=e.slice(0,i)),n[n.length-1]=r.withText(n[n.length-1].text+r.text)):n&&n.push(r)}return new le(n||e,a)}static from(e){if(!e)return le.empty;if(e instanceof le)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new le([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}le.empty=new le([],0);const R2={index:0,offset:0};function jv(t,e){return R2.index=t,R2.offset=e,R2}function A_(t,e){if(t===e)return!0;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let a=0;a<t.length;a++)if(!A_(t[a],e[a]))return!1}else{for(let a in t)if(!(a in e)||!A_(t[a],e[a]))return!1;for(let a in e)if(!(a in t))return!1}return!0}let en=class _3{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,a=!1;for(let i=0;i<e.length;i++){let r=e[i];if(this.eq(r))return e;if(this.type.excludes(r.type))n||(n=e.slice(0,i));else{if(r.type.excludes(this.type))return e;!a&&r.type.rank>this.type.rank&&(n||(n=e.slice(0,i)),n.push(this),a=!0),n&&n.push(r)}}return n||(n=e.slice()),a||n.push(this),n}removeFromSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return e.slice(0,n).concat(e.slice(n+1));return e}isInSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return!0;return!1}eq(e){return this==e||this.type==e.type&&A_(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let a=e.marks[n.type];if(!a)throw new RangeError(`There is no mark type ${n.type} in this schema`);let i=a.create(n.attrs);return a.checkAttrs(i.attrs),i}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let a=0;a<e.length;a++)if(!e[a].eq(n[a]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return _3.none;if(e instanceof _3)return[e];let n=e.slice();return n.sort((a,i)=>a.type.rank-i.type.rank),n}};en.none=[];class C_ extends Error{}class Ae{constructor(e,n,a){this.content=e,this.openStart=n,this.openEnd=a}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let a=Jz(this.content,e+this.openStart,n);return a&&new Ae(a,this.openStart,this.openEnd)}removeBetween(e,n){return new Ae(Qz(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return Ae.empty;let a=n.openStart||0,i=n.openEnd||0;if(typeof a!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new Ae(le.fromJSON(e,n.content),a,i)}static maxOpen(e,n=!0){let a=0,i=0;for(let r=e.firstChild;r&&!r.isLeaf&&(n||!r.type.spec.isolating);r=r.firstChild)a++;for(let r=e.lastChild;r&&!r.isLeaf&&(n||!r.type.spec.isolating);r=r.lastChild)i++;return new Ae(e,a,i)}}Ae.empty=new Ae(le.empty,0,0);function Qz(t,e,n){let{index:a,offset:i}=t.findIndex(e),r=t.maybeChild(a),{index:s,offset:o}=t.findIndex(n);if(i==e||r.isText){if(o!=n&&!t.child(s).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(a!=s)throw new RangeError("Removing non-flat range");return t.replaceChild(a,r.copy(Qz(r.content,e-i-1,n-i-1)))}function Jz(t,e,n,a){let{index:i,offset:r}=t.findIndex(e),s=t.maybeChild(i);if(r==e||s.isText)return a&&!a.canReplace(i,i,n)?null:t.cut(0,e).append(n).append(t.cut(e));let o=Jz(s.content,e-r-1,n,s);return o&&t.replaceChild(i,s.copy(o))}function Lpe(t,e,n){if(n.openStart>t.depth)throw new C_("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new C_("Inconsistent open depths");return eH(t,e,n,0)}function eH(t,e,n,a){let i=t.index(a),r=t.node(a);if(i==e.index(a)&&a<t.depth-n.openStart){let s=eH(t,e,n,a+1);return r.copy(r.content.replaceChild(i,s))}else if(n.content.size)if(!n.openStart&&!n.openEnd&&t.depth==a&&e.depth==a){let s=t.parent,o=s.content;return _l(s,o.cut(0,t.parentOffset).append(n.content).append(o.cut(e.parentOffset)))}else{let{start:s,end:o}=jpe(n,t);return _l(r,nH(t,s,o,e,a))}else return _l(r,N_(t,e,a))}function tH(t,e){if(!e.type.compatibleContent(t.type))throw new C_("Cannot join "+e.type.name+" onto "+t.type.name)}function k3(t,e,n){let a=t.node(n);return tH(a,e.node(n)),a}function yl(t,e){let n=e.length-1;n>=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function pg(t,e,n,a){let i=(e||t).node(n),r=0,s=e?e.index(n):i.childCount;t&&(r=t.index(n),t.depth>n?r++:t.textOffset&&(yl(t.nodeAfter,a),r++));for(let o=r;o<s;o++)yl(i.child(o),a);e&&e.depth==n&&e.textOffset&&yl(e.nodeBefore,a)}function _l(t,e){return t.type.checkContent(e),t.copy(e)}function nH(t,e,n,a,i){let r=t.depth>i&&k3(t,e,i+1),s=a.depth>i&&k3(n,a,i+1),o=[];return pg(null,t,i,o),r&&s&&e.index(i)==n.index(i)?(tH(r,s),yl(_l(r,nH(t,e,n,a,i+1)),o)):(r&&yl(_l(r,N_(t,e,i+1)),o),pg(e,n,i,o),s&&yl(_l(s,N_(n,a,i+1)),o)),pg(a,null,i,o),new le(o)}function N_(t,e,n){let a=[];if(pg(null,t,n,a),t.depth>n){let i=k3(t,e,n+1);yl(_l(i,N_(t,e,n+1)),a)}return pg(e,null,n,a),new le(a)}function jpe(t,e){let n=e.depth-t.openStart,i=e.node(n).copy(t.content);for(let r=n-1;r>=0;r--)i=e.node(r).copy(le.from(i));return{start:i.resolveNoCache(t.openStart+n),end:i.resolveNoCache(i.content.size-t.openEnd-n)}}class Og{constructor(e,n,a){this.pos=e,this.path=n,this.parentOffset=a,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let a=this.pos-this.path[this.path.length-1],i=e.child(n);return a?e.child(n).cut(a):i}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let a=this.path[n*3],i=n==0?0:this.path[n*3-1]+1;for(let r=0;r<e;r++)i+=a.child(r).nodeSize;return i}marks(){let e=this.parent,n=this.index();if(e.content.size==0)return en.none;if(this.textOffset)return e.child(n).marks;let a=e.maybeChild(n-1),i=e.maybeChild(n);if(!a){let o=a;a=i,i=o}let r=a.marks;for(var s=0;s<r.length;s++)r[s].type.spec.inclusive===!1&&(!i||!r[s].isInSet(i.marks))&&(r=r[s--].removeFromSet(r));return r}marksAcross(e){let n=this.parent.maybeChild(this.index());if(!n||!n.isInline)return null;let a=n.marks,i=e.parent.maybeChild(e.index());for(var r=0;r<a.length;r++)a[r].type.spec.inclusive===!1&&(!i||!a[r].isInSet(i.marks))&&(a=a[r--].removeFromSet(a));return a}sharedDepth(e){for(let n=this.depth;n>0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos<this.pos)return e.blockRange(this);for(let a=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);a>=0;a--)if(e.pos<=this.end(a)&&(!n||n(this.node(a))))return new Fg(this,e,a);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let n=1;n<=this.depth;n++)e+=(e?"/":"")+this.node(n).type.name+"_"+this.index(n-1);return e+":"+this.parentOffset}static resolve(e,n){if(!(n>=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let a=[],i=0,r=n;for(let s=e;;){let{index:o,offset:c}=s.content.findIndex(r),p=r-c;if(a.push(s,o,i+c),!p||(s=s.child(o),s.isText))break;r=p-1,i+=c+1}return new Og(n,a,r)}static resolveCached(e,n){let a=Nj.get(e);if(a)for(let r=0;r<a.elts.length;r++){let s=a.elts[r];if(s.pos==n)return s}else Nj.set(e,a=new Dpe);let i=a.elts[a.i]=Og.resolve(e,n);return a.i=(a.i+1)%Ipe,i}}class Dpe{constructor(){this.elts=[],this.i=0}}const Ipe=12,Nj=new WeakMap;class Fg{constructor(e,n,a){this.$from=e,this.$to=n,this.depth=a}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const Rpe=Object.create(null);let Oo=class w3{constructor(e,n,a,i=en.none){this.type=e,this.attrs=n,this.marks=i,this.content=a||le.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,n,a,i=0){this.content.nodesBetween(e,n,a,i,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,n,a,i){return this.content.textBetween(e,n,a,i)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,n,a){return this.type==e&&A_(this.attrs,n||e.defaultAttrs||Rpe)&&en.sameSet(this.marks,a||en.none)}copy(e=null){return e==this.content?this:new w3(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new w3(this.type,this.attrs,this.content,e)}cut(e,n=this.content.size){return e==0&&n==this.content.size?this:this.copy(this.content.cut(e,n))}slice(e,n=this.content.size,a=!1){if(e==n)return Ae.empty;let i=this.resolve(e),r=this.resolve(n),s=a?0:i.sharedDepth(n),o=i.start(s),p=i.node(s).content.cut(i.pos-o,r.pos-o);return new Ae(p,i.depth-s,r.depth-s)}replace(e,n,a){return Lpe(this.resolve(e),this.resolve(n),a)}nodeAt(e){for(let n=this;;){let{index:a,offset:i}=n.content.findIndex(e);if(n=n.maybeChild(a),!n)return null;if(i==e||n.isText)return n;e-=i+1}}childAfter(e){let{index:n,offset:a}=this.content.findIndex(e);return{node:this.content.maybeChild(n),index:n,offset:a}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:n,offset:a}=this.content.findIndex(e);if(a<e)return{node:this.content.child(n),index:n,offset:a};let i=this.content.child(n-1);return{node:i,index:n-1,offset:a-i.nodeSize}}resolve(e){return Og.resolveCached(this,e)}resolveNoCache(e){return Og.resolve(this,e)}rangeHasMark(e,n,a){let i=!1;return n>e&&this.nodesBetween(e,n,r=>(a.isInSet(r.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),aH(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,a=le.empty,i=0,r=a.childCount){let s=this.contentMatchAt(e).matchFragment(a,i,r),o=s&&s.matchFragment(this.content,n);if(!o||!o.validEnd)return!1;for(let c=i;c<r;c++)if(!this.type.allowsMarks(a.child(c).marks))return!1;return!0}canReplaceWith(e,n,a,i){if(i&&!this.type.allowsMarks(i))return!1;let r=this.contentMatchAt(e).matchType(a),s=r&&r.matchFragment(this.content,n);return s?s.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=en.none;for(let n=0;n<this.marks.length;n++){let a=this.marks[n];a.type.checkAttrs(a.attrs),e=a.addToSet(e)}if(!en.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(n=>n.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let a;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");a=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,a)}let i=le.fromJSON(e,n.content),r=e.nodeType(n.type).create(n.attrs,i,a);return r.type.checkAttrs(r.attrs),r}};Oo.prototype.text=void 0;class S_ extends Oo{constructor(e,n,a,i){if(super(e,n,null,i),!a)throw new RangeError("Empty text nodes are not allowed");this.text=a}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):aH(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new S_(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new S_(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function aH(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class El{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let a=new Ope(e,n);if(a.next==null)return El.empty;let i=iH(a);a.next&&a.err("Unexpected trailing text");let r=Vpe(Upe(i));return Zpe(r,a),r}matchType(e){for(let n=0;n<this.next.length;n++)if(this.next[n].type==e)return this.next[n].next;return null}matchFragment(e,n=0,a=e.childCount){let i=this;for(let r=n;i&&r<a;r++)i=i.matchType(e.child(r).type);return i}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:n}=this.next[e];if(!(n.isText||n.hasRequiredAttrs()))return n}return null}compatible(e){for(let n=0;n<this.next.length;n++)for(let a=0;a<e.next.length;a++)if(this.next[n].type==e.next[a].type)return!0;return!1}fillBefore(e,n=!1,a=0){let i=[this];function r(s,o){let c=s.matchFragment(e,a);if(c&&(!n||c.validEnd))return le.from(o.map(p=>p.createAndFill()));for(let p=0;p<s.next.length;p++){let{type:d,next:m}=s.next[p];if(!(d.isText||d.hasRequiredAttrs())&&i.indexOf(m)==-1){i.push(m);let f=r(m,o.concat(d));if(f)return f}}return null}return r(this,[])}findWrapping(e){for(let a=0;a<this.wrapCache.length;a+=2)if(this.wrapCache[a]==e)return this.wrapCache[a+1];let n=this.computeWrapping(e);return this.wrapCache.push(e,n),n}computeWrapping(e){let n=Object.create(null),a=[{match:this,type:null,via:null}];for(;a.length;){let i=a.shift(),r=i.match;if(r.matchType(e)){let s=[];for(let o=i;o.type;o=o.via)s.push(o.type);return s.reverse()}for(let s=0;s<r.next.length;s++){let{type:o,next:c}=r.next[s];!o.isLeaf&&!o.hasRequiredAttrs()&&!(o.name in n)&&(!i.type||c.validEnd)&&(a.push({match:o.contentMatch,type:o,via:i}),n[o.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(a){e.push(a);for(let i=0;i<a.next.length;i++)e.indexOf(a.next[i].next)==-1&&n(a.next[i].next)}return n(this),e.map((a,i)=>{let r=i+(a.validEnd?"*":" ")+" ";for(let s=0;s<a.next.length;s++)r+=(s?", ":"")+a.next[s].type.name+"->"+e.indexOf(a.next[s].next);return r}).join(`
|
|
232
232
|
`)}}El.empty=new El(!0);class Ope{constructor(e,n){this.string=e,this.nodeTypes=n,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function iH(t){let e=[];do e.push(Fpe(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function Fpe(t){let e=[];do e.push(zpe(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function zpe(t){let e=qpe(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=Hpe(t,e);else break;return e}function Sj(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function Hpe(t,e){let n=Sj(t),a=n;return t.eat(",")&&(t.next!="}"?a=Sj(t):a=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:a,expr:e}}function Bpe(t,e){let n=t.nodeTypes,a=n[e];if(a)return[a];let i=[];for(let r in n){let s=n[r];s.isInGroup(e)&&i.push(s)}return i.length==0&&t.err("No node type or group '"+e+"' found"),i}function qpe(t){if(t.eat("(")){let e=iH(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=Bpe(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Upe(t){let e=[[]];return i(r(t,0),n()),e;function n(){return e.push([])-1}function a(s,o,c){let p={term:c,to:o};return e[s].push(p),p}function i(s,o){s.forEach(c=>c.to=o)}function r(s,o){if(s.type=="choice")return s.exprs.reduce((c,p)=>c.concat(r(p,o)),[]);if(s.type=="seq")for(let c=0;;c++){let p=r(s.exprs[c],o);if(c==s.exprs.length-1)return p;i(p,o=n())}else if(s.type=="star"){let c=n();return a(o,c),i(r(s.expr,c),c),[a(c)]}else if(s.type=="plus"){let c=n();return i(r(s.expr,o),c),i(r(s.expr,c),c),[a(c)]}else{if(s.type=="opt")return[a(o)].concat(r(s.expr,o));if(s.type=="range"){let c=o;for(let p=0;p<s.min;p++){let d=n();i(r(s.expr,c),d),c=d}if(s.max==-1)i(r(s.expr,c),c);else for(let p=s.min;p<s.max;p++){let d=n();a(c,d),i(r(s.expr,c),d),c=d}return[a(c)]}else{if(s.type=="name")return[a(o,void 0,s.value)];throw new Error("Unknown expr type")}}}}function rH(t,e){return e-t}function $j(t,e){let n=[];return a(e),n.sort(rH);function a(i){let r=t[i];if(r.length==1&&!r[0].term)return a(r[0].to);n.push(i);for(let s=0;s<r.length;s++){let{term:o,to:c}=r[s];!o&&n.indexOf(c)==-1&&a(c)}}}function Vpe(t){let e=Object.create(null);return n($j(t,0));function n(a){let i=[];a.forEach(s=>{t[s].forEach(({term:o,to:c})=>{if(!o)return;let p;for(let d=0;d<i.length;d++)i[d][0]==o&&(p=i[d][1]);$j(t,c).forEach(d=>{p||i.push([o,p=[]]),p.indexOf(d)==-1&&p.push(d)})})});let r=e[a.join(",")]=new El(a.indexOf(t.length-1)>-1);for(let s=0;s<i.length;s++){let o=i[s][1].sort(rH);r.next.push({type:i[s][0],next:e[o.join(",")]||n(o)})}return r}}function Zpe(t,e){for(let n=0,a=[t];n<a.length;n++){let i=a[n],r=!i.validEnd,s=[];for(let o=0;o<i.next.length;o++){let{type:c,next:p}=i.next[o];s.push(c.name),r&&!(c.isText||c.hasRequiredAttrs())&&(r=!1),a.indexOf(p)==-1&&a.push(p)}r&&e.err("Only non-generatable nodes ("+s.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function sH(t){let e=Object.create(null);for(let n in t){let a=t[n];if(!a.hasDefault)return null;e[n]=a.default}return e}function oH(t,e){let n=Object.create(null);for(let a in t){let i=e&&e[a];if(i===void 0){let r=t[a];if(r.hasDefault)i=r.default;else throw new RangeError("No value supplied for attribute "+a)}n[a]=i}return n}function cH(t,e,n,a){for(let i in e)if(!(i in t))throw new RangeError(`Unsupported attribute ${i} for ${n} of type ${i}`);for(let i in t){let r=t[i];r.validate&&r.validate(e[i])}}function pH(t,e){let n=Object.create(null);if(e)for(let a in e)n[a]=new Wpe(t,a,e[a]);return n}let Ej=class lH{constructor(e,n,a){this.name=e,this.schema=n,this.spec=a,this.markSet=null,this.groups=a.group?a.group.split(" "):[],this.attrs=pH(e,a.attrs),this.defaultAttrs=sH(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(a.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==El.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:oH(this.attrs,e)}create(e=null,n,a){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Oo(this,this.computeAttrs(e),le.from(n),en.setFrom(a))}createChecked(e=null,n,a){return n=le.from(n),this.checkContent(n),new Oo(this,this.computeAttrs(e),n,en.setFrom(a))}createAndFill(e=null,n,a){if(e=this.computeAttrs(e),n=le.from(n),n.size){let s=this.contentMatch.fillBefore(n);if(!s)return null;n=s.append(n)}let i=this.contentMatch.matchFragment(n),r=i&&i.fillBefore(le.empty,!0);return r?new Oo(this,e,n.append(r),en.setFrom(a)):null}validContent(e){let n=this.contentMatch.matchFragment(e);if(!n||!n.validEnd)return!1;for(let a=0;a<e.childCount;a++)if(!this.allowsMarks(e.child(a).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){cH(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;n<e.length;n++)if(!this.allowsMarkType(e[n].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let n;for(let a=0;a<e.length;a++)this.allowsMarkType(e[a].type)?n&&n.push(e[a]):n||(n=e.slice(0,a));return n?n.length?n:en.none:e}static compile(e,n){let a=Object.create(null);e.forEach((r,s)=>a[r]=new lH(r,n,s));let i=n.spec.topNode||"doc";if(!a[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!a.text)throw new RangeError("Every schema needs a 'text' type");for(let r in a.text.attrs)throw new RangeError("The text node type should not have attributes");return a}};function Gpe(t,e,n){let a=n.split("|");return i=>{let r=i===null?"null":typeof i;if(a.indexOf(r)<0)throw new RangeError(`Expected value of type ${a} for attribute ${e} on type ${t}, got ${r}`)}}class Wpe{constructor(e,n,a){this.hasDefault=Object.prototype.hasOwnProperty.call(a,"default"),this.default=a.default,this.validate=typeof a.validate=="string"?Gpe(e,n,a.validate):a.validate}get isRequired(){return!this.hasDefault}}class tk{constructor(e,n,a,i){this.name=e,this.rank=n,this.schema=a,this.spec=i,this.attrs=pH(e,i.attrs),this.excluded=null;let r=sH(this.attrs);this.instance=r?new en(this,r):null}create(e=null){return!e&&this.instance?this.instance:new en(this,oH(this.attrs,e))}static compile(e,n){let a=Object.create(null),i=0;return e.forEach((r,s)=>a[r]=new tk(r,i++,n,s)),a}removeFromSet(e){for(var n=0;n<e.length;n++)e[n].type==this&&(e=e.slice(0,n).concat(e.slice(n+1)),n--);return e}isInSet(e){for(let n=0;n<e.length;n++)if(e[n].type==this)return e[n]}checkAttrs(e){cH(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}let dH=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let i in e)n[i]=e[i];n.nodes=Ca.from(e.nodes),n.marks=Ca.from(e.marks||{}),this.nodes=Ej.compile(this.spec.nodes,this),this.marks=tk.compile(this.spec.marks,this);let a=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let r=this.nodes[i],s=r.spec.content||"",o=r.spec.marks;if(r.contentMatch=a[s]||(a[s]=El.parse(s,this.nodes)),r.inlineContent=r.contentMatch.inlineContent,r.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!r.isInline||!r.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=r}r.markSet=o=="_"?null:o?Pj(this,o.split(" ")):o==""||!r.inlineContent?[]:null}for(let i in this.marks){let r=this.marks[i],s=r.spec.excludes;r.excluded=s==null?[r]:s==""?[]:Pj(this,s.split(" "))}this.nodeFromJSON=i=>Oo.fromJSON(this,i),this.markFromJSON=i=>en.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,a,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Ej){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(n,a,i)}text(e,n){let a=this.nodes.text;return new S_(a,a.defaultAttrs,e,en.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}};function Pj(t,e){let n=[];for(let a=0;a<e.length;a++){let i=e[a],r=t.marks[i],s=r;if(r)n.push(r);else for(let o in t.marks){let c=t.marks[o];(i=="_"||c.spec.group&&c.spec.group.split(" ").indexOf(i)>-1)&&n.push(s=c)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[a]+"'")}return n}function Kpe(t){return t.tag!=null}function Ype(t){return t.style!=null}let $r=class x3{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[];let a=this.matchedStyles=[];n.forEach(i=>{if(Kpe(i))this.tags.push(i);else if(Ype(i)){let r=/[^=]*/.exec(i.style)[0];a.indexOf(r)<0&&a.push(r),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let r=e.nodes[i.node];return r.contentMatch.matchType(r)})}parse(e,n={}){let a=new Mj(this,n,!1);return a.addAll(e,en.none,n.from,n.to),a.finish()}parseSlice(e,n={}){let a=new Mj(this,n,!0);return a.addAll(e,en.none,n.from,n.to),Ae.maxOpen(a.finish())}matchTag(e,n,a){for(let i=a?this.tags.indexOf(a)+1:0;i<this.tags.length;i++){let r=this.tags[i];if(Jpe(e,r.tag)&&(r.namespace===void 0||e.namespaceURI==r.namespace)&&(!r.context||n.matchesContext(r.context))){if(r.getAttrs){let s=r.getAttrs(e);if(s===!1)continue;r.attrs=s||void 0}return r}}}matchStyle(e,n,a,i){for(let r=i?this.styles.indexOf(i)+1:0;r<this.styles.length;r++){let s=this.styles[r],o=s.style;if(!(o.indexOf(e)!=0||s.context&&!a.matchesContext(s.context)||o.length>e.length&&(o.charCodeAt(e.length)!=61||o.slice(e.length+1)!=n))){if(s.getAttrs){let c=s.getAttrs(n);if(c===!1)continue;s.attrs=c||void 0}return s}}}static schemaRules(e){let n=[];function a(i){let r=i.priority==null?50:i.priority,s=0;for(;s<n.length;s++){let o=n[s];if((o.priority==null?50:o.priority)<r)break}n.splice(s,0,i)}for(let i in e.marks){let r=e.marks[i].spec.parseDOM;r&&r.forEach(s=>{a(s=Lj(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let r=e.nodes[i].spec.parseDOM;r&&r.forEach(s=>{a(s=Lj(s)),s.node||s.ignore||s.mark||(s.node=i)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new x3(e,x3.schemaRules(e)))}};const uH={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Xpe={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},mH={ol:!0,ul:!0},zg=1,A3=2,lg=4;function Tj(t,e,n){return e!=null?(e?zg:0)|(e==="full"?A3:0):t&&t.whitespace=="pre"?zg|A3:n&~lg}class Dv{constructor(e,n,a,i,r,s){this.type=e,this.attrs=n,this.marks=a,this.solid=i,this.options=s,this.content=[],this.activeMarks=en.none,this.match=r||(s&lg?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(le.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let a=this.type.contentMatch,i;return(i=a.findWrapping(e.type))?(this.match=a,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&zg)){let a=this.content[this.content.length-1],i;if(a&&a.isText&&(i=/[ \t\r\n\u000c]+$/.exec(a.text))){let r=a;a.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=r.withText(r.text.slice(0,r.text.length-i[0].length))}}let n=le.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(le.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!uH.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class Mj{constructor(e,n,a){this.parser=e,this.options=n,this.isOpen=a,this.open=0,this.localPreserveWS=!1;let i=n.topNode,r,s=Tj(null,n.preserveWhitespace,0)|(a?lg:0);i?r=new Dv(i.type,i.attrs,en.none,!0,n.topMatch||i.type.contentMatch,s):a?r=new Dv(null,null,en.none,!0,null,s):r=new Dv(e.schema.topNodeType,null,en.none,!0,null,s),this.nodes=[r],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,n){e.nodeType==3?this.addTextNode(e,n):e.nodeType==1&&this.addElement(e,n)}addTextNode(e,n){let a=e.nodeValue,i=this.top,r=i.options&A3?"full":this.localPreserveWS||(i.options&zg)>0,{schema:s}=this.parser;if(r==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(a)){if(r)if(r==="full")a=a.replace(/\r\n?/g,`
|
|
233
233
|
`);else if(s.linebreakReplacement&&/[\r\n]/.test(a)&&this.top.findWrapping(s.linebreakReplacement.create())){let o=a.split(/\r?\n|\r/);for(let c=0;c<o.length;c++)c&&this.insertNode(s.linebreakReplacement.create(),n,!0),o[c]&&this.insertNode(s.text(o[c]),n,!/\S/.test(o[c]));a=""}else a=a.replace(/\r?\n|\r/g," ");else if(a=a.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(a)&&this.open==this.nodes.length-1){let o=i.content[i.content.length-1],c=e.previousSibling;(!o||c&&c.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(a=a.slice(1))}a&&this.insertNode(s.text(a),n,!/\S/.test(a)),this.findInText(e)}else this.findInside(e)}addElement(e,n,a){let i=this.localPreserveWS,r=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let s=e.nodeName.toLowerCase(),o;mH.hasOwnProperty(s)&&this.parser.normalizeLists&&Qpe(e);let c=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,a));e:if(c?c.ignore:Xpe.hasOwnProperty(s))this.findInside(e),this.ignoreFallback(e,n);else if(!c||c.skip||c.closeParent){c&&c.closeParent?this.open=Math.max(0,this.open-1):c&&c.skip.nodeType&&(e=c.skip);let p,d=this.needsBlock;if(uH.hasOwnProperty(s))r.content.length&&r.content[0].isInline&&this.open&&(this.open--,r=this.top),p=!0,r.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,n);break e}let m=c&&c.skip?n:this.readStyles(e,n);m&&this.addAll(e,m),p&&this.sync(r),this.needsBlock=d}else{let p=this.readStyles(e,n);p&&this.addElementByRule(e,c,p,c.consuming===!1?o:void 0)}this.localPreserveWS=i}leafFallback(e,n){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
|
|
234
234
|
`),n)}ignoreFallback(e,n){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),n,!0)}readStyles(e,n){let a=e.style;if(a&&a.length)for(let i=0;i<this.parser.matchedStyles.length;i++){let r=this.parser.matchedStyles[i],s=a.getPropertyValue(r);if(s)for(let o=void 0;;){let c=this.parser.matchStyle(r,s,this,o);if(!c)break;if(c.ignore)return null;if(c.clearMark?n=n.filter(p=>!c.clearMark(p)):n=n.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)o=c;else break}}return n}addElementByRule(e,n,a,i){let r,s;if(n.node)if(s=this.parser.schema.nodes[n.node],s.isLeaf)this.insertNode(s.create(n.attrs),a,e.nodeName=="BR")||this.leafFallback(e,a);else{let c=this.enter(s,n.attrs||null,a,n.preserveWhitespace);c&&(r=!0,a=c)}else{let c=this.parser.schema.marks[n.mark];a=a.concat(c.create(n.attrs))}let o=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,a,i);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,a,!1));else{let c=e;typeof n.contentElement=="string"?c=e.querySelector(n.contentElement):typeof n.contentElement=="function"?c=n.contentElement(e):n.contentElement&&(c=n.contentElement),this.findAround(e,c,!0),this.addAll(c,a),this.findAround(e,c,!1)}r&&this.sync(o)&&this.open--}addAll(e,n,a,i){let r=a||0;for(let s=a?e.childNodes[a]:e.firstChild,o=i==null?null:e.childNodes[i];s!=o;s=s.nextSibling,++r)this.findAtPoint(e,r),this.addDOM(s,n);this.findAtPoint(e,r)}findPlace(e,n,a){let i,r;for(let s=this.open,o=0;s>=0;s--){let c=this.nodes[s],p=c.findWrapping(e);if(p&&(!i||i.length>p.length+o)&&(i=p,r=c,!p.length))break;if(c.solid){if(a)break;o+=2}}if(!i)return null;this.sync(r);for(let s=0;s<i.length;s++)n=this.enterInner(i[s],null,n,!1);return n}insertNode(e,n,a){if(e.isInline&&this.needsBlock&&!this.top.type){let r=this.textblockFromContext();r&&(n=this.enterInner(r,null,n))}let i=this.findPlace(e,n,a);if(i){this.closeExtra();let r=this.top;r.match&&(r.match=r.match.matchType(e.type));let s=en.none;for(let o of i.concat(e.marks))(r.type?r.type.allowsMarkType(o.type):jj(o.type,e.type))&&(s=o.addToSet(s));return r.content.push(e.mark(s)),!0}return!1}enter(e,n,a,i){let r=this.findPlace(e.create(n),a,!1);return r&&(r=this.enterInner(e,n,a,!0,i)),r}enterInner(e,n,a,i=!1,r){this.closeExtra();let s=this.top;s.match=s.match&&s.match.matchType(e);let o=Tj(e,r,s.options);s.options&lg&&s.content.length==0&&(o|=lg);let c=en.none;return a=a.filter(p=>(s.type?s.type.allowsMarkType(p.type):jj(p.type,e))?(c=p.addToSet(c),!1):!0),this.nodes.push(new Dv(e,n,c,i,null,o)),this.open++,a}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let n=this.open;n>=0;n--){if(this.nodes[n]==e)return this.open=n,!0;this.localPreserveWS&&(this.nodes[n].options|=zg)}return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let a=this.nodes[n].content;for(let i=a.length-1;i>=0;i--)e+=a[i].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let a=0;a<this.find.length;a++)this.find[a].node==e&&this.find[a].offset==n&&(this.find[a].pos=this.currentPos)}findInside(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&e.nodeType==1&&e.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(e,n,a){if(e!=n&&this.find)for(let i=0;i<this.find.length;i++)this.find[i].pos==null&&e.nodeType==1&&e.contains(this.find[i].node)&&n.compareDocumentPosition(this.find[i].node)&(a?2:4)&&(this.find[i].pos=this.currentPos)}findInText(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&(this.find[n].pos=this.currentPos-(e.nodeValue.length-this.find[n].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),a=this.options.context,i=!this.isOpen&&(!a||a.parent.type==this.nodes[0].type),r=-(a?a.depth+1:0)+(i?0:1),s=(o,c)=>{for(;o>=0;o--){let p=n[o];if(p==""){if(o==n.length-1||o==0)continue;for(;c>=r;c--)if(s(o-1,c))return!0;return!1}else{let d=c>0||c==0&&i?this.nodes[c].type:a&&c>=r?a.node(c-r).type:null;if(!d||d.name!=p&&!d.isInGroup(p))return!1;c--}}return!0};return s(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let a=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(a&&a.isTextblock&&a.defaultAttrs)return a}for(let n in this.parser.schema.nodes){let a=this.parser.schema.nodes[n];if(a.isTextblock&&a.defaultAttrs)return a}}}function Qpe(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let a=e.nodeType==1?e.nodeName.toLowerCase():null;a&&mH.hasOwnProperty(a)&&n?(n.appendChild(e),e=n):a=="li"?n=e:a&&(n=null)}}function Jpe(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function Lj(t){let e={};for(let n in t)e[n]=t[n];return e}function jj(t,e){let n=e.schema.nodes;for(let a in n){let i=n[a];if(!i.allowsMarkType(t))continue;let r=[],s=o=>{r.push(o);for(let c=0;c<o.edgeCount;c++){let{type:p,next:d}=o.edge(c);if(p==e||r.indexOf(d)<0&&s(d))return!0}};if(s(i.contentMatch))return!0}}class Ji{constructor(e,n){this.nodes=e,this.marks=n}serializeFragment(e,n={},a){a||(a=O2(n).createDocumentFragment());let i=a,r=[];return e.forEach(s=>{if(r.length||s.marks.length){let o=0,c=0;for(;o<r.length&&c<s.marks.length;){let p=s.marks[c];if(!this.marks[p.type.name]){c++;continue}if(!p.eq(r[o][0])||p.type.spec.spanning===!1)break;o++,c++}for(;o<r.length;)i=r.pop()[1];for(;c<s.marks.length;){let p=s.marks[c++],d=this.serializeMark(p,s.isInline,n);d&&(r.push([p,i]),i.appendChild(d.dom),i=d.contentDOM||d.dom)}}i.appendChild(this.serializeNodeInner(s,n))}),a}serializeNodeInner(e,n){let{dom:a,contentDOM:i}=Dy(O2(n),this.nodes[e.type.name](e),null,e.attrs);if(i){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,n,i)}return a}serializeNode(e,n={}){let a=this.serializeNodeInner(e,n);for(let i=e.marks.length-1;i>=0;i--){let r=this.serializeMark(e.marks[i],e.isInline,n);r&&((r.contentDOM||r.dom).appendChild(a),a=r.dom)}return a}serializeMark(e,n,a={}){let i=this.marks[e.type.name];return i&&Dy(O2(a),i(e,n),null,e.attrs)}static renderSpec(e,n,a=null,i){return Dy(e,n,a,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new Ji(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=Dj(e.nodes);return n.text||(n.text=a=>a.text),n}static marksFromSchema(e){return Dj(e.marks)}}function Dj(t){let e={};for(let n in t){let a=t[n].spec.toDOM;a&&(e[n]=a)}return e}function O2(t){return t.document||window.document}const Ij=new WeakMap;function ele(t){let e=Ij.get(t);return e===void 0&&Ij.set(t,e=tle(t)),e}function tle(t){let e=null;function n(a){if(a&&typeof a=="object")if(Array.isArray(a))if(typeof a[0]=="string")e||(e=[]),e.push(a);else for(let i=0;i<a.length;i++)n(a[i]);else for(let i in a)n(a[i])}return n(t),e}function Dy(t,e,n,a){if(typeof e=="string")return{dom:t.createTextNode(e)};if(e.nodeType!=null)return{dom:e};if(e.dom&&e.dom.nodeType!=null)return e;let i=e[0],r;if(typeof i!="string")throw new RangeError("Invalid array passed to renderSpec");if(a&&(r=ele(a))&&r.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(n=i.slice(0,s),i=i.slice(s+1));let o,c=n?t.createElementNS(n,i):t.createElement(i),p=e[1],d=1;if(p&&typeof p=="object"&&p.nodeType==null&&!Array.isArray(p)){d=2;for(let m in p)if(p[m]!=null){let f=m.indexOf(" ");f>0?c.setAttributeNS(m.slice(0,f),m.slice(f+1),p[m]):m=="style"&&c.style?c.style.cssText=p[m]:c.setAttribute(m,p[m])}}for(let m=d;m<e.length;m++){let f=e[m];if(f===0){if(m<e.length-1||m>d)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:h,contentDOM:b}=Dy(t,f,n,a);if(c.appendChild(h),b){if(o)throw new RangeError("Multiple content holes");o=b}}}return{dom:c,contentDOM:o}}const fH=65535,gH=Math.pow(2,16);function nle(t,e){return t+e*gH}function Rj(t){return t&fH}function ale(t){return(t-(t&fH))/gH}const hH=1,bH=2,Iy=4,vH=8;class C3{constructor(e,n,a){this.pos=e,this.delInfo=n,this.recover=a}get deleted(){return(this.delInfo&vH)>0}get deletedBefore(){return(this.delInfo&(hH|Iy))>0}get deletedAfter(){return(this.delInfo&(bH|Iy))>0}get deletedAcross(){return(this.delInfo&Iy)>0}}class Wi{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&Wi.empty)return Wi.empty}recover(e){let n=0,a=Rj(e);if(!this.inverted)for(let i=0;i<a;i++)n+=this.ranges[i*3+2]-this.ranges[i*3+1];return this.ranges[a*3]+n+ale(e)}mapResult(e,n=1){return this._map(e,n,!1)}map(e,n=1){return this._map(e,n,!0)}_map(e,n,a){let i=0,r=this.inverted?2:1,s=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let c=this.ranges[o]-(this.inverted?i:0);if(c>e)break;let p=this.ranges[o+r],d=this.ranges[o+s],m=c+p;if(e<=m){let f=p?e==c?-1:e==m?1:n:n,h=c+i+(f<0?0:d);if(a)return h;let b=e==(n<0?c:m)?null:nle(o/3,e-c),k=e==c?bH:e==m?hH:Iy;return(n<0?e!=c:e!=m)&&(k|=vH),new C3(h,k,b)}i+=d-p}return a?e+i:new C3(e+i,0,null)}touches(e,n){let a=0,i=Rj(n),r=this.inverted?2:1,s=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let c=this.ranges[o]-(this.inverted?a:0);if(c>e)break;let p=this.ranges[o+r],d=c+p;if(e<=d&&o==i*3)return!0;a+=this.ranges[o+s]-p}return!1}forEach(e){let n=this.inverted?2:1,a=this.inverted?1:2;for(let i=0,r=0;i<this.ranges.length;i+=3){let s=this.ranges[i],o=s-(this.inverted?r:0),c=s+(this.inverted?0:r),p=this.ranges[i+n],d=this.ranges[i+a];e(o,o+p,c,c+d),r+=d-p}}invert(){return new Wi(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?Wi.empty:new Wi(e<0?[0,-e,0]:[0,0,e])}}Wi.empty=new Wi([]);class Du{constructor(e,n,a=0,i=e?e.length:0){this.mirror=n,this.from=a,this.to=i,this._maps=e||[],this.ownData=!(e||n)}get maps(){return this._maps}slice(e=0,n=this.maps.length){return new Du(this._maps,this.mirror,e,n)}appendMap(e,n){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),n!=null&&this.setMirror(this._maps.length-1,n)}appendMapping(e){for(let n=0,a=this._maps.length;n<e._maps.length;n++){let i=e.getMirror(n);this.appendMap(e._maps[n],i!=null&&i<n?a+i:void 0)}}getMirror(e){if(this.mirror){for(let n=0;n<this.mirror.length;n++)if(this.mirror[n]==e)return this.mirror[n+(n%2?-1:1)]}}setMirror(e,n){this.mirror||(this.mirror=[]),this.mirror.push(e,n)}appendMappingInverted(e){for(let n=e.maps.length-1,a=this._maps.length+e._maps.length;n>=0;n--){let i=e.getMirror(n);this.appendMap(e._maps[n].invert(),i!=null&&i>n?a-i-1:void 0)}}invert(){let e=new Du;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let a=this.from;a<this.to;a++)e=this._maps[a].map(e,n);return e}mapResult(e,n=1){return this._map(e,n,!1)}_map(e,n,a){let i=0;for(let r=this.from;r<this.to;r++){let s=this._maps[r],o=s.mapResult(e,n);if(o.recover!=null){let c=this.getMirror(r);if(c!=null&&c>r&&c<this.to){r=c,e=this._maps[c].recover(o.recover);continue}}i|=o.delInfo,e=o.pos}return a?e:new C3(e,i,null)}}const F2=Object.create(null);class Ka{getMap(){return Wi.empty}merge(e){return null}static fromJSON(e,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let a=F2[n.stepType];if(!a)throw new RangeError(`No step type ${n.stepType} defined`);return a.fromJSON(e,n)}static jsonID(e,n){if(e in F2)throw new RangeError("Duplicate use of step JSON ID "+e);return F2[e]=n,n.prototype.jsonID=e,n}}class Gn{constructor(e,n){this.doc=e,this.failed=n}static ok(e){return new Gn(e,null)}static fail(e){return new Gn(null,e)}static fromReplace(e,n,a,i){try{return Gn.ok(e.replace(n,a,i))}catch(r){if(r instanceof C_)return Gn.fail(r.message);throw r}}}function tS(t,e,n){let a=[];for(let i=0;i<t.childCount;i++){let r=t.child(i);r.content.size&&(r=r.copy(tS(r.content,e,r))),r.isInline&&(r=e(r,n,i)),a.push(r)}return le.fromArray(a)}class qc extends Ka{constructor(e,n,a){super(),this.from=e,this.to=n,this.mark=a}apply(e){let n=e.slice(this.from,this.to),a=e.resolve(this.from),i=a.node(a.sharedDepth(this.to)),r=new Ae(tS(n.content,(s,o)=>!s.isAtom||!o.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),n.openStart,n.openEnd);return Gn.fromReplace(e,this.from,this.to,r)}invert(){return new Qr(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),a=e.mapResult(this.to,-1);return n.deleted&&a.deleted||n.pos>=a.pos?null:new qc(n.pos,a.pos,this.mark)}merge(e){return e instanceof qc&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new qc(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new qc(n.from,n.to,e.markFromJSON(n.mark))}}Ka.jsonID("addMark",qc);class Qr extends Ka{constructor(e,n,a){super(),this.from=e,this.to=n,this.mark=a}apply(e){let n=e.slice(this.from,this.to),a=new Ae(tS(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return Gn.fromReplace(e,this.from,this.to,a)}invert(){return new qc(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),a=e.mapResult(this.to,-1);return n.deleted&&a.deleted||n.pos>=a.pos?null:new Qr(n.pos,a.pos,this.mark)}merge(e){return e instanceof Qr&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Qr(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Qr(n.from,n.to,e.markFromJSON(n.mark))}}Ka.jsonID("removeMark",Qr);class Uc extends Ka{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return Gn.fail("No node at mark step's position");let a=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return Gn.fromReplace(e,this.pos,this.pos+1,new Ae(le.from(a),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let a=this.mark.addToSet(n.marks);if(a.length==n.marks.length){for(let i=0;i<n.marks.length;i++)if(!n.marks[i].isInSet(a))return new Uc(this.pos,n.marks[i]);return new Uc(this.pos,this.mark)}}return new Pl(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Uc(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Uc(n.pos,e.markFromJSON(n.mark))}}Ka.jsonID("addNodeMark",Uc);class Pl extends Ka{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return Gn.fail("No node at mark step's position");let a=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return Gn.fromReplace(e,this.pos,this.pos+1,new Ae(le.from(a),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new Uc(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Pl(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Pl(n.pos,e.markFromJSON(n.mark))}}Ka.jsonID("removeNodeMark",Pl);class Pn extends Ka{constructor(e,n,a,i=!1){super(),this.from=e,this.to=n,this.slice=a,this.structure=i}apply(e){return this.structure&&N3(e,this.from,this.to)?Gn.fail("Structure replace would overwrite content"):Gn.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Wi([this.from,this.to-this.from,this.slice.size])}invert(e){return new Pn(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let n=e.mapResult(this.to,-1),a=this.from==this.to&&Pn.MAP_BIAS<0?n:e.mapResult(this.from,1);return a.deletedAcross&&n.deletedAcross?null:new Pn(a.pos,Math.max(a.pos,n.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Pn)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let n=this.slice.size+e.slice.size==0?Ae.empty:new Ae(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Pn(this.from,this.to+(e.to-e.from),n,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let n=this.slice.size+e.slice.size==0?Ae.empty:new Ae(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Pn(e.from,this.to,n,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Pn(n.from,n.to,Ae.fromJSON(e,n.slice),!!n.structure)}}Pn.MAP_BIAS=1;Ka.jsonID("replace",Pn);class Mn extends Ka{constructor(e,n,a,i,r,s,o=!1){super(),this.from=e,this.to=n,this.gapFrom=a,this.gapTo=i,this.slice=r,this.insert=s,this.structure=o}apply(e){if(this.structure&&(N3(e,this.from,this.gapFrom)||N3(e,this.gapTo,this.to)))return Gn.fail("Structure gap-replace would overwrite content");let n=e.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return Gn.fail("Gap is not a flat range");let a=this.slice.insertAt(this.insert,n.content);return a?Gn.fromReplace(e,this.from,this.to,a):Gn.fail("Content does not fit in gap")}getMap(){return new Wi([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let n=this.gapTo-this.gapFrom;return new Mn(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let n=e.mapResult(this.from,1),a=e.mapResult(this.to,-1),i=this.from==this.gapFrom?n.pos:e.map(this.gapFrom,-1),r=this.to==this.gapTo?a.pos:e.map(this.gapTo,1);return n.deletedAcross&&a.deletedAcross||i<n.pos||r>a.pos?null:new Mn(n.pos,a.pos,i,r,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Mn(n.from,n.to,n.gapFrom,n.gapTo,Ae.fromJSON(e,n.slice),n.insert,!!n.structure)}}Ka.jsonID("replaceAround",Mn);function N3(t,e,n){let a=t.resolve(e),i=n-e,r=a.depth;for(;i>0&&r>0&&a.indexAfter(r)==a.node(r).childCount;)r--,i--;if(i>0){let s=a.node(r).maybeChild(a.indexAfter(r));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function ile(t,e,n,a){let i=[],r=[],s,o;t.doc.nodesBetween(e,n,(c,p,d)=>{if(!c.isInline)return;let m=c.marks;if(!a.isInSet(m)&&d.type.allowsMarkType(a.type)){let f=Math.max(p,e),h=Math.min(p+c.nodeSize,n),b=a.addToSet(m);for(let k=0;k<m.length;k++)m[k].isInSet(b)||(s&&s.to==f&&s.mark.eq(m[k])?s.to=h:i.push(s=new Qr(f,h,m[k])));o&&o.to==f?o.to=h:r.push(o=new qc(f,h,a))}}),i.forEach(c=>t.step(c)),r.forEach(c=>t.step(c))}function rle(t,e,n,a){let i=[],r=0;t.doc.nodesBetween(e,n,(s,o)=>{if(!s.isInline)return;r++;let c=null;if(a instanceof tk){let p=s.marks,d;for(;d=a.isInSet(p);)(c||(c=[])).push(d),p=d.removeFromSet(p)}else a?a.isInSet(s.marks)&&(c=[a]):c=s.marks;if(c&&c.length){let p=Math.min(o+s.nodeSize,n);for(let d=0;d<c.length;d++){let m=c[d],f;for(let h=0;h<i.length;h++){let b=i[h];b.step==r-1&&m.eq(i[h].style)&&(f=b)}f?(f.to=p,f.step=r):i.push({style:m,from:Math.max(o,e),to:p,step:r})}}}),i.forEach(s=>t.step(new Qr(s.from,s.to,s.style)))}function nS(t,e,n,a=n.contentMatch,i=!0){let r=t.doc.nodeAt(e),s=[],o=e+1;for(let c=0;c<r.childCount;c++){let p=r.child(c),d=o+p.nodeSize,m=a.matchType(p.type);if(!m)s.push(new Pn(o,d,Ae.empty));else{a=m;for(let f=0;f<p.marks.length;f++)n.allowsMarkType(p.marks[f].type)||t.step(new Qr(o,d,p.marks[f]));if(i&&p.isText&&n.whitespace!="pre"){let f,h=/\r?\n|\r/g,b;for(;f=h.exec(p.text);)b||(b=new Ae(le.from(n.schema.text(" ",n.allowedMarks(p.marks))),0,0)),s.push(new Pn(o+f.index,o+f.index+f[0].length,b))}}o=d}if(!a.validEnd){let c=a.fillBefore(le.empty,!0);t.replace(o,o,new Ae(c,0,0))}for(let c=s.length-1;c>=0;c--)t.step(s[c])}function sle(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function Kl(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let a=t.depth,i=0,r=0;;--a){let s=t.$from.node(a),o=t.$from.index(a)+i,c=t.$to.indexAfter(a)-r;if(a<t.depth&&s.canReplace(o,c,n))return a;if(a==0||s.type.spec.isolating||!sle(s,o,c))break;o&&(i=1),c<s.childCount&&(r=1)}return null}function ole(t,e,n){let{$from:a,$to:i,depth:r}=e,s=a.before(r+1),o=i.after(r+1),c=s,p=o,d=le.empty,m=0;for(let b=r,k=!1;b>n;b--)k||a.index(b)>0?(k=!0,d=le.from(a.node(b).copy(d)),m++):c--;let f=le.empty,h=0;for(let b=r,k=!1;b>n;b--)k||i.after(b+1)<i.end(b)?(k=!0,f=le.from(i.node(b).copy(f)),h++):p++;t.step(new Mn(c,p,s,o,new Ae(d.append(f),m,h),d.size-m,!0))}function yH(t,e,n=null,a=t){let i=cle(t,e),r=i&&ple(a,e);return r?i.map(Oj).concat({type:e,attrs:n}).concat(r.map(Oj)):null}function Oj(t){return{type:t,attrs:null}}function cle(t,e){let{parent:n,startIndex:a,endIndex:i}=t,r=n.contentMatchAt(a).findWrapping(e);if(!r)return null;let s=r.length?r[0]:e;return n.canReplaceWith(a,i,s)?r:null}function ple(t,e){let{parent:n,startIndex:a,endIndex:i}=t,r=n.child(a),s=e.contentMatch.findWrapping(r.type);if(!s)return null;let c=(s.length?s[s.length-1]:e).contentMatch;for(let p=a;c&&p<i;p++)c=c.matchType(n.child(p).type);return!c||!c.validEnd?null:s}function lle(t,e,n){let a=le.empty;for(let s=n.length-1;s>=0;s--){if(a.size){let o=n[s].type.contentMatch.matchFragment(a);if(!o||!o.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}a=le.from(n[s].type.create(n[s].attrs,a))}let i=e.start,r=e.end;t.step(new Mn(i,r,i,r,new Ae(a,0,0),n.length,!0))}function dle(t,e,n,a,i){if(!a.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let r=t.steps.length;t.doc.nodesBetween(e,n,(s,o)=>{let c=typeof i=="function"?i(s):i;if(s.isTextblock&&!s.hasMarkup(a,c)&&ule(t.doc,t.mapping.slice(r).map(o),a)){let p=null;if(a.schema.linebreakReplacement){let h=a.whitespace=="pre",b=!!a.contentMatch.matchType(a.schema.linebreakReplacement);h&&!b?p=!1:!h&&b&&(p=!0)}p===!1&&kH(t,s,o,r),nS(t,t.mapping.slice(r).map(o,1),a,void 0,p===null);let d=t.mapping.slice(r),m=d.map(o,1),f=d.map(o+s.nodeSize,1);return t.step(new Mn(m,f,m+1,f-1,new Ae(le.from(a.create(c,null,s.marks)),0,0),1,!0)),p===!0&&_H(t,s,o,r),!1}})}function _H(t,e,n,a){e.forEach((i,r)=>{if(i.isText){let s,o=/\r?\n|\r/g;for(;s=o.exec(i.text);){let c=t.mapping.slice(a).map(n+1+r+s.index);t.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function kH(t,e,n,a){e.forEach((i,r)=>{if(i.type==i.type.schema.linebreakReplacement){let s=t.mapping.slice(a).map(n+1+r);t.replaceWith(s,s+1,e.type.schema.text(`
|