oficina / mapa Public

Columns: the rebuilt editor bundle

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev e740753819d39e38e839f5106e0cb6f70d854f54 parent 51dc9df
1 file changed, +1 −1
  • internal/mapa/static/{editor.ca5ef847c9df9e7d.js => editor.bad1b29c273b6a86.js} +1 −1

CI failed — run details

CI log
=== editor ===
cd editor && npm ci --no-audit --no-fund --loglevel=error

added 16 packages in 417ms
cd editor && node build-bundles.mjs
wrote internal/mapa/static/editor.bad1b29c273b6a86.js (364471 bytes, 114.4KB gzipped; L12 budget 120KB)
cd editor && node --test
✔ a badge is named for what it does, starting with its visible word (1.119316ms)
✔ first words stop at five words or forty characters (0.183811ms)
✔ the field keeps one trimmed line, without brackets (0.269249ms)
✔ the field holds at most MaxAlt bytes, cut at a character (0.945774ms)
✔ a block becomes column 1 of two, and undo gives it back (12.443931ms)
✔ a selection over blocks moves them all into column 1 (2.456026ms)
✔ no layout is made inside a layout (0.61947ms)
✔ Add a column, Remove this column and Undo columns (5.599235ms)
✔ Undo columns puts the blocks in reading order (0.673209ms)
✔ Backspace in an empty column takes the column away (0.973416ms)
✔ ⌥⌘→ and ⌥⌘← move between columns (0.456918ms)
✔ typing a fence line in a column never closes it (D16) (7.046049ms)
✔ a selection holding a layout makes no nested layout (H1) (2.549279ms)
✔ a fence typed after a break in a column stays in the column (H2) (5.476798ms)
✔ code holding a fence line and ::: stays code in its column (H2) (3.612801ms)
✔ Backspace after a layout and Delete before one join nothing (M4) (0.96544ms)
✔ deleting across columns keeps every column (M3) (2.995616ms)
✔ a layout pasted into a column arrives as its blocks (M1) (3.701325ms)
✔ copying inside one column puts no fence on the clipboard (M2) (0.315215ms)
✔ typing goes on in the column after a structural reparse (round 2) (5.22406ms)
✔ a structural reparse in a column leaves code as it was (round 2) (2.101768ms)
✔ days and weeks move across months and years (1.289401ms)
✔ a month keeps the day, or takes the month's last (0.263989ms)
✔ the grid is six weeks from Monday, as the month calendar draws it (1.921024ms)
✔ the grid starts the week where the locale does (0.65231ms)
✔ the keys move a day, a week, a month and a year (0.323901ms)
✔ the picked day is the chip [[ makes for a date (16.765547ms)
✔ Insert → Today's date still puts today in at once (1.938765ms)
✔ / offers Date, the picker, and Today's date beside it (0.367341ms)
✔ after a ! the chip goes in after a space, never as an embed (4.591416ms)
✔ where the Markdown would read the chip differently, it is refused (4.332546ms)
✔ over a selection the chip goes after it and the words stay (2.574665ms)
✔ today is the day in the viewer's zone (17.617847ms)
✔ every offered locale has cases (1.124145ms)
✔ dates.mjs writes every date Go writes, byte for byte (5.673563ms)
✔ a chip, the month and the week, in three locales (0.583152ms)
✔ dates.json is what ICU gives, byte for byte (533.804937ms)
✔ L1: mounting then serialising gives cleanBody(body), byte for byte (102.246957ms)
ℹ 901 bodies
✔ L1: mounting a stored body adds nothing, and saving it writes nothing new (96.608389ms)
✔ L2: one edited block changes only that block's bytes; undo gives the body back (154.008614ms)
ℹ 888 single-block edits
✔ L2: inserting or deleting a block changes bytes only at the new seams, by Join (166.401219ms)
ℹ 896 inserts, 837 deletes
✔ L3: seeded edits keep the document and its Markdown saying the same thing (5993.190204ms)
ℹ 21624 edits over 901 bodies
✔ L3: Link to a page makes exactly one chip, and changes nothing else (1347.153883ms)
ℹ 4710 links over 901 bodies; refused: {"A page link can’t hold another link or a line break. Select plain words.":945,"A page link can’t show [ or ]]. Select words without them.":404,"Select some words to link them to a page.":174,"Linked here, the Markdown around these words would read differently: a ! before them makes an embed, and a stray ` or * pairs up. Select other words.":18}
✔ L3: a picked date is one more date chip, or refused where a letter would be too (1410.249616ms)
ℹ over 901 bodies: {"inserted":5338,"spaced":23,"refused":45,"unstable":9}
✔ linear: trailing spaces (44.547625ms)
✔ linear: trailing whitespace (64.38945ms)
✔ linear: unclosed web links (23.335533ms)
✔ linear: web links with no address (31.237488ms)
✔ linear: unclosed wiki links (20.640524ms)
✔ linear: unclosed embeds (22.650241ms)
✔ linear: closes only (6.517689ms)
✔ the selected words become the chip's shown text (14.549265ms)
✔ words that are the title make a plain [[Title]] (6.478215ms)
✔ spaces at the selection's edges stay outside the chip (1.528265ms)
✔ a date makes a date link, in a heading, an item and a quote (9.147867ms)
✔ bold words lose their bold: a chip carries no marks in Mapa's Markdown (1.583186ms)
✔ only the linked block's bytes change, and undo gives the body back (3.478742ms)
✔ a selection across blocks, over a chip or a break, or of brackets is refused (1.850282ms)
✔ a target the words cannot be linked to as typed is refused (0.339199ms)
✔ ⌘L: over a selection it opens Page link; with none it types [[; in code it does nothing (2.712942ms)
✔ web-linked words are refused: the address would be lost (review M4) (1.703359ms)
✔ words whose Markdown would read otherwise are refused (review M3) (2.454413ms)
✔ ⌘A then ⌘L says why, instead of doing nothing (review low 1) (1.82199ms)
✔ linkCheck says why it refuses (review low 2) (1.646453ms)
✔ golden file has bodies (1.103867ms)
✔ markup.mjs parses every body into Go's blocks, byte offsets and all (43.415877ms)
✔ markup.mjs strips and spans every block as Go does (46.138236ms)
✔ the schema's toDOM draws every body as Go renders it (76.614153ms)
✔ emphasis draws the four pinned outputs (19.048331ms)
✔ a body ends in the editor's empty paragraph (0.238041ms)
✔ the editor labels date chips as Go does, in every locale L4 holds (12.491548ms)
✔ a POST that never answers is aborted after the timeout (22.343333ms)
✔ a keepalive POST carries no signal, and an answer clears the timer (5.368647ms)
✔ autosave sends only what differs, and the tab owns the draft it wrote (13.186868ms)
✔ an offered draft never commits by itself; Save commits it (2.088323ms)
✔ reload, then close: sessionStorage says the draft is this tab's own (0.705178ms)
✔ closing carries text not yet sent, and the cap leaves it out (47.213341ms)
✔ clean rebase: applied, the caret survives, the base moves by the rebase POST (3.912096ms)
✔ the block under the caret is the teammate's too, and undo brings back yours (7.13267ms)
✔ typing mid-flight: the merge is not applied and the base does not move (1.623732ms)
✔ a merge the editor cannot represent stops after three tries (6.05502ms)
✔ a conflict is shown, locks the editor's own commits, and Resolve settles it (1.462122ms)
✔ leaving: a conflict stays with the choice; a failed flush offers Leave anyway; a stored draft leaves (2.139468ms)
✔ a stale tab shows the newer draft, offered, and never overwrites it (1.377475ms)
✔ the first scratch commit: empty creates nothing, then one page, then drafts on it (2.043139ms)
✔ noBase and gone lead to the existing choices (0.974468ms)
✔ a commit that merged is applied when nothing was typed since (1.163778ms)
✔ back from the cache: nothing unsaved reloads, unsaved text autosaves at once (10.361579ms)
✔ an own draft committed meanwhile goes on as a new draft (1.858718ms)
✔ a reload keeps a stored draft; unsent text still commits (0.740043ms)
✔ a page deleted mid-edit: what is typed is still stored as the draft, and nothing commits (H1) (1.499351ms)
✔ an offered draft committed in another tab: typing goes on as a new draft (H1) (2.761261ms)
✔ a commit reply without a revision is not a commit; an emptied day starts afresh (H2) (1.356947ms)
✔ Resolve stores what was typed first, and takes no typing until its answer is applied (M1) (4.462427ms)
✔ closing with a choice open, or commits held, still writes the text, never commits (M2) (1.357047ms)
✔ closing inside the settling window sends the loaded version with settling=1 (M3) (0.550851ms)
✔ a clean merge not applied because of typing still ends the choice on show (M4) (1.129856ms)
✔ settling finds the draft committed with a teammate's text: a close still writes (M-A) (0.562764ms)
✔ settling finds another tab's newer draft: the tab shows it before any typing (0.811195ms)
✔ a page deleted before the first autosave: the text is offered as a scratch page, and a close makes one (M-B) (0.717511ms)
✔ an autosave that never answered but landed: its 409 keeps the typing since (L3) (0.75491ms)
✔ marks: em outside strong, bold reopened around italics, edges outside (5.84996ms)
✔ marks close before code, links and atoms, and reopen after (0.442411ms)
✔ untouched blocks and atoms re-emit their source; edited atoms are written from attributes (10.177357ms)
✔ empty blocks are written as nothing (2.079616ms)
✔ an unclosed fence that is no longer last gets its closing fence (2.030436ms)
✔ the structure check puts Join's seam where a kept one would merge two blocks (1.695766ms)
✔ prepareSave adopts the parse when no seam or rewrite can save the document (2.194952ms)
✔ reparse: typed emphasis becomes a mark, "- " after a break becomes an item (2.575827ms)
✔ a trailing hard break stays on screen and is written as nothing (0.610361ms)
✔ the reparse waits while an IME is composing (0.833617ms)
✔ copied blocks paste with their bytes and seams; a cut and paste gives the body back (4.127336ms)
✔ a forged x-mapa slice is refused, and text from outside is read as Markdown (0.787871ms)
✔ rebuild changes origins only, outside undo history (2.993813ms)
✔ applyBody takes a teammate's block, keeps the caret, and ends untouched (1.311593ms)
✔ a block whose context changed is written again: a task toggled, a bullet, a quote (2.201824ms)
✔ a duplicate ^id typed above its holder never takes the id from it (1.332672ms)
✔ a copy-dragged block is reparsed, and says what its Markdown says (1.81733ms)
✔ a history command that throws is refused, never thrown (9.512315ms)
✔ an image re-emits its source, and an edited alt changes only its span (1.411988ms)
✔ a paste whose image copy is refused says why and pastes nothing (15.741547ms)
✔ a line of image openers reads in linear time (118.145985ms)
✔ a line of shared link address reads in linear time (15.884444ms)
✔ a line of shared web address reads in linear time (59.087584ms)
✔ one rename at a time, from either field (2.200682ms)
✔ an empty or unchanged title sends nothing (0.215499ms)
✔ a refusal keeps what was typed, and the title (0.488686ms)
✔ the pending state holds for the busy rule (7.933656ms)
✔ a failed POST says so and keeps the title (1.420676ms)
✔ Update links posts the confirm page's POST (0.30735ms)
✔ clean is CleanTitle's whitespace rule (0.357623ms)
✔ the saver's base follows a rename made over it, and only that (0.326124ms)
✔ closing sends the rename as one keepalive POST (2.989455ms)
✔ the port answers every shared case as typeddate.go does (8.115903ms)
✔ numbers follow the locale: 12/11 is November in en-IE, December in en-US (1.376383ms)
✔ M6: several files land in the order they were chosen (47.433749ms)
✔ M5: one Backspace before the box keeps the image where the box is (13.308534ms)
✔ M5: undoing text typed just before the box keeps the upload (14.366627ms)
✔ L12: a failed upload an undo takes away does not stall the next (14.22777ms)
✔ M4: Replace… keeps the old image until the new one is in, and its alt (15.169165ms)
✔ M3 and N1: text wins, except over a picture copied from a page (2.082432ms)
✔ N2: a JPEG over 10 MB is scaled before its size is checked (6.616392ms)
✔ a drag whose anchor the document no longer reaches selects to its end (6.165716ms)
ℹ tests 143
ℹ suites 0
ℹ pass 143
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 9447.774537
=== vet ===
go vet ./...
go vet -tags browser ./internal/mapatest/
=== fmt ===
=== code ===
go tool rastrillo budget code
The base has no .rastrillo/code.txt: skipping the check that records only go down.
budget code: within the limits.
=== test ===
CGO_ENABLED=0 go test ./...
?   	amadan.net/oficina/mapa/cmd/mapa	[no test files]
ok  	amadan.net/oficina/mapa/internal/mapa	3.611s
ok  	amadan.net/oficina/mapa/internal/mapa/emoji	(cached)
?   	amadan.net/oficina/mapa/internal/mapa/icons	[no test files]
ok  	amadan.net/oficina/mapa/internal/mapa/imagefile	(cached)
ok  	amadan.net/oficina/mapa/internal/mapa/locale	(cached)
ok  	amadan.net/oficina/mapa/internal/mapa/markup	(cached)
ok  	amadan.net/oficina/mapa/internal/mapa/notionmd	(cached)
ok  	amadan.net/oficina/mapa/internal/mapa/seal	(cached)
ok  	amadan.net/oficina/mapa/internal/mapatest	14.897s
?   	amadan.net/oficina/mapa/scripts/mutate	[no test files]
?   	amadan.net/oficina/mapa/scripts/preview	[no test files]
=== migration-check ===
go tool rastrillo migration check
rastrillo migration check: models and migrations agree
=== credits-check ===
python3 scripts/credits.py --check
the Colophon's JavaScript inventory is stale; run make credits
make: *** [Makefile:171: credits-check] Error 1

amadan: step credits-check failed: exit status 2

amadan: job failed at step credits-check — its output is above, not at the tail of this log
diff --git a/internal/mapa/static/editor.ca5ef847c9df9e7d.js b/internal/mapa/static/editor.bad1b29c273b6a86.js
similarity index 99%
rename from internal/mapa/static/editor.ca5ef847c9df9e7d.js
rename to internal/mapa/static/editor.bad1b29c273b6a86.js
index 0f63087..ccffeff 100644
--- a/internal/mapa/static/editor.ca5ef847c9df9e7d.js
+++ b/internal/mapa/static/editor.bad1b29c273b6a86.js
@@ -36,7 +36,7 @@ function H(n){this.content=n}H.prototype={constructor:H,find:function(n){for(var
`+o,em:i("em"),strong:i("strong")})}else e.push({kind:"atom",text:Pm(r)})});let t="";for(let r=0;r<e.length;){let i=e[r];if(i.kind==="text"){let o=r;for(;o<e.length&&e[o].kind==="text";)o++;t+=Nm(e.slice(r,o)),r=o;continue}i.kind==="code"?t+="`"+i.text+"`":i.kind==="link"?t+=Em(i):t+=i.text,r++}return yt(t)}function Em({text:n,mark:e}){return e.attrs.bare&&n===e.attrs.href?n:`[${n}](${e.attrs.href})`}function Nm(n){return Nc(n,"em",e=>vm(e),"*")}function vm(n){return Nc(n,"strong",e=>e.map(t=>t.text).join(""),"**")}function Nc(n,e,t,r){let i="";for(let o=0;o<n.length;){let s=o;for(;s<n.length&&n[s][e]===n[o][e];)s++;let l=t(n.slice(o,s));i+=n[o][e]?Im(l,r):l,o=s}return i}function Im(n,e){let t=/^([\t\n\f\r ]*)([^]*?)([\t\n\f\r ]*)$/u.exec(n);return t[2]===""?n:t[1]+e+t[2]+e+t[3]}function Pm(n){let e=n.attrs;return e.source!=null&&Rm(n,e.source)?e.source:n.type.name==="embed"?`![[${e.ref}]]`:n.type.name==="image"?`![${e.alt??""}](${X}${e.id})`:`[[${n.type.name==="datelink"?e.date:e.target}${e.anchor?"#^"+e.anchor:""}${e.shown?"|"+e.shown:""}]]`}function Rm(n,e){let t=ze(e);if(t.length!==1||t[0].source!==e)return!1;let r=t[0];if(n.type.name==="embed")return r.kind===pn&&r.text.slice(3,-2)===n.attrs.ref;if(n.type.name==="image")return r.kind===Ze&&r.target===n.attrs.id&&r.text===(n.attrs.alt??"");if(r.kind!==gt)return!1;let i=n.type.name==="datelink";return W(r.target)===i&&r.target===(i?n.attrs.date:n.attrs.target)&&r.anchor===(n.attrs.anchor??"")&&r.text===(n.attrs.shown??"")}function P(n,e,t={}){let r=t.fresh??new Set,i=t.joins??new Set,o=ke(n),s=new Set;for(let f of o){let d=Kr(f);f.origin=d,f.first=d!=null&&!s.has(d),d!=null&&s.add(d),f.entry=f.first?e?.get(d):void 0,f.untouched=!r.has(f.index)&&Cm(f,f.entry),f.text=f.untouched?f.entry.source:Wr(f)}let l=-1;o.forEach((f,d)=>{f.text!==""&&(l=d)});for(let f of o.slice(0,Math.max(l,0)))f.kind===ie&&(f.untouched&&Ec(f.text)||(f.untouched=!1,f.text=Wr(f,{last:!1})));let a=o.filter(f=>f.text!==""),c="";a.forEach((f,d)=>{d===0?t.edges!==!1&&f.entry?.leading!=null&&(c+=f.entry.leading):(f.seam=Lm(a[d-1],f,i.has(f.index)),c+=f.seam),c+=f.text});let u=a[a.length-1];return t.edges!==!1&&u?.entry?.trailing!=null&&(c+=u.entry.trailing),{body:t.raw?yt(c):ge(c),blocks:o,emitted:a}}function Fn(n,e,t){return P(n,e,t).body}function Lm(n,e,t){if(!t&&n.first&&e.first){if(n.entry&&n.entry.next===e.origin&&n.entry.after!=null)return n.entry.after;if(e.entry&&e.entry.prev===n.origin&&e.entry.before!=null)return e.entry.before}return Bm(n.kind,e.kind)}function Bm(n,e){return n===Oe||n===R&&e===R?`
`:`
-`}function Vo(n){let e=new Set;return n.map(t=>{if(t.kind===Be)return`${Be}:${Math.min(Math.max(t.node.attrs.level,1),6)}`;if(t.kind!==R)return t.kind;let r=!e.has(t.listPos);return e.add(t.listPos),`${R}:${t.list}:${t.depth}:${r}`})}function zm(n,e){let t=ke(Qt(n,ee(e),{trailing:!1}));return Vo(t.filter(r=>!(r.kind===hn&&r.column>0&&r.node.childCount===0)))}function vc(n){return Vo(n)}function $m(n,e){let t=Math.min(n.length,e.length);for(let r=0;r<t;r++)if(n[r]!==e[r])return r;return n.length===e.length?-1:t}function jr(n,e){let t=n.type.schema,r=l=>{let a=P(n,e,l);return a.shapes=Vo(a.emitted),a.mismatch=$m(a.shapes,zm(t,a.body)),a},i=new Set,o=new Set,s=r({});for(let l=0;s.mismatch>=0&&l<4;l++){let a=[-1,0,1,2].map(c=>s.emitted[s.mismatch+c]);for(let c of a)c&&(o.add(c.index),l>=2&&i.add(c.index));s=r({fresh:i,joins:o})}if(s.mismatch>=0){let l=new Set(s.blocks.map(a=>a.index));s=r({fresh:l,joins:l})}return{ok:s.mismatch<0,body:s.body,shapes:s.shapes,fixed:o.size>0}}var Jr=class{constructor(){this.issued=0,this.table=new Map}mint(){return++this.issued}get(e){return this.table.get(e)}record(e,t){if(this.table.has(e))throw new Error(`origin ${e} is already recorded`);this.table.set(e,Object.freeze(t))}},st=new N("mapa-fidelity");function tn(n,e,t,r={}){let i=yt(t),o=ee(i),s=o.map(()=>e.mint()),l=Qt(n,o,{origin:f=>s[f],...r}),a=new Map(ke(l).map(f=>[Kr(f),f])),c=s.map(f=>a.get(f)),u=r.edges!==!1;return o.forEach((f,d)=>{let h=o[d-1],p=o[d+1];e.record(s[d],{node:c[d].node,source:f.source,context:xe(c[d]),prev:h?s[d-1]:null,next:p?s[d+1]:null,before:h?i.slice(h.to,f.from):null,after:p?i.slice(f.to,p.from):null,leading:u&&!h?i.slice(0,f.from):null,trailing:u&&!p?i.slice(f.to):null})}),{doc:l,nodes:c,origins:s}}function qo(n,e){let t=new Jr,{doc:r}=tn(n,t,e);return{doc:r,fidelity:t}}function Fm(n,e){return ye(n.kind)||ye(e.kind)?n.kind===e.kind&&xe(n)===xe(e):xe(n)===xe(e)&&Fo(Nt(n),e.node)}function Pc(n,e,t){let r=0;for(;r<n.length&&r<e.length&&t(n[r],e[r]);)r++;let i=0;for(;i<n.length-r&&i<e.length-r&&t(n[n.length-1-i],e[e.length-1-i]);)i++;let o=Vm(n.slice(r,n.length-i),e.slice(r,e.length-i),t);return[...Array.from({length:r},(s,l)=>[l,l]),...o.map(([s,l])=>[s+r,l+r]),...Array.from({length:i},(s,l)=>[n.length-i+l,e.length-i+l])]}function Vm(n,e,t){let r=n.length,i=e.length,o=Array.from({length:r+1},()=>new Int32Array(i+1));for(let l=r-1;l>=0;l--)for(let a=i-1;a>=0;a--)o[l][a]=t(n[l],e[a])?o[l+1][a+1]+1:Math.max(o[l+1][a],o[l][a+1]);let s=[];for(let l=0,a=0;l<r&&a<i;)t(n[l],e[a])?(s.push([l,a]),l++,a++):o[l+1][a]>=o[l][a+1]?l++:a++;return s}function Rc(n,e,t){let r=n.state,{nodes:i,origins:o}=tn(r.schema,e,t),s=i.slice(0,o.length),l=P(r.doc,e).emitted,a=r.tr;for(let[c,u]of Pc(l,s,Fm))a.setNodeAttribute(l[c].pos,$o(l[c]),o[u]);return a.setMeta("addToHistory",!1).setMeta(st,{rebuilt:!0}),n.dispatch(a),{ok:Fn(n.state.doc,e)===ge(t)}}function Wo(n,e){let t=e.topNodeType.create(null,n),{emitted:r}=P(t,null,{raw:!0}),i=vc(r);return JSON.stringify(r.map((o,s)=>[i[s],o.text]))}function Ko(n,e,t,r=null){let i=n.doc.type.schema,o=r?r.node:n.doc,s=r?r.start:0,{doc:l}=tn(i,e,t,r?{trailing:!1,edges:!1}:{}),a=[];o.forEach((m,g)=>{let y=Wo(m,i);y!=="[]"&&a.push({node:m,offset:g+s,key:y})});let c=[];l.forEach(m=>{let g=Wo(m,i);g!=="[]"&&c.push({node:m,key:g})});let u=Pc(a,c,(m,g)=>m.key===g.key),f=[],d=[-1,-1];for(let m of[...u,[a.length,c.length]]){let[g,y]=[d[0]+1,d[1]+1];if(m[0]>g||m[1]>y){let C=g<a.length?a[g].offset:a[a.length-1]?a[a.length-1].offset+a[a.length-1].node.nodeSize:s,O=m[0]>g?a[m[0]-1].offset+a[m[0]-1].node.nodeSize:C;f.push({from:C,to:O,nodes:c.slice(y,m[1]).map($=>$.node)})}d=m}let h=n.selection.head,p=null;for(let m of f.reverse()){p===null&&h>=m.from&&h<=m.to&&(p={left:Wm(n.doc,h,m.to),gap:m});let g=[];n.doc.nodesBetween(m.from,m.to,(y,C)=>(C>=m.from&&Wo(y,i)==="[]"&&g.push(y),!1)),n.replaceWith(m.from,m.to,b.from([...m.nodes,...g])),m.size=[...m.nodes,...g].reduce((y,C)=>y+C.nodeSize,0)}if(p){let m=n.mapping.map(p.gap.from,-1),g=qm(n.doc,m,m+p.gap.size,p.left);n.setSelection(k.near(n.doc.resolve(g),-1))}return n}function Wm(n,e,t){let r=0;return n.nodesBetween(e,t,(i,o)=>{i.isText?r+=Math.min(o+i.nodeSize,t)-Math.max(o,e):i.isInline&&(r+=1)}),r}function qm(n,e,t,r){let i=null,o=[];n.nodesBetween(e,t,(s,l)=>{if(s.isTextblock)return o.push({node:s,pos:l}),!1});for(let{node:s,pos:l}of o.reverse()){let a=s.content.size;if(r<=a){i=l+1+a-r;break}r-=a}return i===null&&(i=o.length?o[o.length-1].pos+1:e),Math.min(Math.max(i,0),n.content.size)}function Hr(n,e,t){let r=Ko(n.state.tr,e,t).setMeta("mapa-applied",!0);return r.docChanged&&n.dispatch(r.scrollIntoView()),Rc(n,e,t)}function jo(n,e){let t=jr(n.state.doc,e);if(t.ok)return{body:t.body,shapes:t.shapes,adopted:!1};Hr(n,e,t.body);let r=jr(n.state.doc,e);return{body:r.body,shapes:r.shapes,adopted:!0}}var Km={paragraph:["marker"],heading:["level","marker"],code_block:["fence","info","closed","close"],list_item:["indent","bullet","number","delim","task","checked","marker"],blockquote:["prefix","marker"]};function Ic(n){return n.kind===R||n.kind===oe?n.holder:n.node}function jm(n,e){if(n.kind===Ce||ye(n.kind))return null;let t=Wr(n);if(t==="")return null;let r=ee(t);if(r.length!==1||r[0].kind!==n.kind)return"structural";let i=ke(Qt(e,r,{trailing:!1}))[0];if(n.kind===R&&i.list!==n.list)return"structural";let o=Ic(n),s=Ic(i),l=[];for(let d of Km[o.type.name]??[])JSON.stringify(o.attrs[d])!==JSON.stringify(s.attrs[d])&&l.push([d,s.attrs[d]]);let a=Nt(n).content,c=i.node.content,u=a.findDiffStart(c);if(u===null&&l.length===0)return null;let f=null;if(u!==null){let{a:d,b:h}=a.findDiffEnd(c),p=u-Math.min(d,h);p>0&&(d+=p,h+=p),f={from:u,to:d,content:c.cut(u,h)}}return{block:n,attrs:l,diff:f,text:t,node:i.node}}function Jm(n,{block:e,attrs:t,diff:r},i){if(r){let s=e.pos+1;n.replaceWith(s+r.from,s+r.to,r.content)}let o=e.kind===R||e.kind===oe?e.holderPos:e.pos;for(let[s,l]of t)n.setNodeAttribute(o,s,l);n.setNodeAttribute(e.pos,"origin",i)}function Hm(n,e,t=null){let r=n.tr;return Lc(r,e,t),r.docChanged?r:null}function Um(n,e){let t=n.blocks.filter(i=>!i.untouched);if(!e)return t;let r=new Map(ke(e).map(i=>[i.node,xe(i)]));return t.filter(i=>!i.first||r.get(i.node)!==xe(i))}function Lc(n,e,t){let r=n.doc.type.schema,i=P(n.doc,e),o=[];for(let f of Um(i,t)){let d=jm(f,r);if(d==="structural"){f.column>0?eg(n,e,f):Ko(n,e,i.body);return}d&&o.push(d)}if(o.length===0)return;let s=new Map(o.map(f=>[f.block,e.mint()])),l=f=>s.get(f)??(f.first?f.origin:null),{emitted:a}=i,c=o.map(({block:f,text:d,node:h})=>{let p=a.indexOf(f),m=a[p-1],g=a[p+1],y=s.get(f);return{origin:y,source:d,node:h.type.create({...h.attrs,origin:y},h.content,h.marks),prev:m?l(m):null,next:g?l(g):null,before:m?f.seam:null,after:g?g.seam:null,leading:p===0?f.entry?.leading??null:null,trailing:p>=0&&!g?f.entry?.trailing??null:null}});for(let f of[...o].reverse())Jm(n,f,s.get(f.block));let u=new Map(ke(n.doc).map(f=>[Kr(f),f]));for(let{origin:f,...d}of c)e.record(f,{...d,context:xe(u.get(f))})}function _m(n,e){let t=s=>{let l=new Map;for(let a of ke(s)){let c=a.holder.attrs.marker;c&&l.set(c,(l.get(c)??0)+1)}return l},r=e?t(e):new Map,i=new Set(e?ke(e).map(s=>s.holder):[]),o=ke(n.doc);for(let[s,l]of t(n.doc)){let a=l-Math.max(r.get(s)??0,1);if(a<=0)continue;let c=o.filter(h=>h.holder.attrs.marker===s),u=c.find(h=>i.has(h.holder))??c[0],f=c.filter(h=>h!==u),d=[...f.filter(h=>!i.has(h.holder)).reverse(),...f.filter(h=>i.has(h.holder)).reverse()];for(let h of d.slice(0,a))n.setNodeAttribute(h.holderPos,"marker",null)}}function Ym(n){return Math.floor(String(n??"").replaceAll(" "," ").length/2)}function Gm(n,e){let t=-1;for(let o of P(n.doc,e).emitted){if(o.kind!==R){t=-1;continue}let s=Ym(o.holder.attrs.indent),l=" ".repeat(o.depth);Math.min(s,t+1)!==o.depth&&o.depth<=t+1&&o.holder.attrs.indent!==l&&n.setNodeAttribute(o.holderPos,"indent",l),t=o.depth}let r=[],i=(o,s)=>{let l=s,a=null;o.forEach(c=>{a&&a.type===c.type&&(c.type.name==="bullet_list"||c.type.name==="ordered_list")&&r.push(l),a=c,l+=c.nodeSize})};i(n.doc,0),n.doc.descendants((o,s)=>{if(o.isTextblock)return!1;i(o,s+1)});for(let o of r.sort((s,l)=>l-s))n.join(o)}function Xm(n,e){let t=P(n.doc,e),r=t.emitted.filter(s=>ye(s.kind)).map(s=>s.kind),i=ee(t.body).filter(s=>ye(s.kind)).map(s=>s.kind);if(r.join()===i.join())return;let o=[];n.doc.descendants((s,l)=>s.isTextblock?(s.type.name!=="code_block"&&Zm(s,l,o),!1):!0);for(let s of o.reverse())n.insertText("\u200B",s)}function Zm(n,e,t){let r="",i=e+1,o=i,s=()=>{Li(r)&&t.push(o+r.indexOf(":"))};n.forEach((l,a)=>{l.type.name==="hard_break"?(s(),r="",o=i+a+l.nodeSize):l.isText?r+=l.text:r+="\uFFFC"}),s()}function Qm(n){let e=n.doc.lastChild;(!e||e.type.name!=="paragraph")&&n.insert(n.doc.content.size,n.doc.type.schema.nodes.paragraph.create())}function Bc(n,e,t=null){let r=n.tr;for(let i=0;i<4;i++){let o=r.doc;if(Lc(r,e,t),Xm(r,e),_m(r,t),Gm(r,e),Qm(r),r.doc===o)break}return r.docChanged?r:null}function Jo(n,e={}){let t=null,r=null,i=()=>e.composing?e.composing():t?.composing??!1;return new S({key:st,state:{init:()=>n,apply:(o,s)=>s},view(o){return t=o,{destroy(){t=null}}},props:{handleDOMEvents:{compositionend(o){return setTimeout(()=>{t===o&&r&&o.dispatch(o.state.tr.setMeta(st,{composed:!0}))},50),!1}}},appendTransaction(o,s,l){if(!o.some(f=>f.docChanged&&!f.getMeta(st)?.rebuilt)&&!r)return null;if(i())return r=r??s.doc,null;let c=r??s.doc;r=null;let u=Bc(l,n,c);return u?u.setMeta(st,{settled:!0}):null}})}function eg(n,e,t){let r=n.doc.resolve(t.pos),i=r.depth;for(;i>0&&r.node(i).type.name!=="column";)i--;if(i===0)return;let o=r.node(i),s=r.before(i)+1,l=s+o.content.size,a=n.doc.type.schema,c=a.topNodeType.create(null,o.content),u=tg(P(c,e,{edges:!1,raw:!0}).body);Ko(n,e,u,{node:o,start:s});let f=n.doc.nodeAt(s-1);f&&f.type.name==="column"&&f.childCount===0&&n.insert(s,a.nodes.paragraph.create())}function tg(n){let e=null;return n.split(`
+`}function Vo(n){let e=new Set;return n.map(t=>{if(t.kind===Be)return`${Be}:${Math.min(Math.max(t.node.attrs.level,1),6)}`;if(t.kind!==R)return t.kind;let r=!e.has(t.listPos);return e.add(t.listPos),`${R}:${t.list}:${t.depth}:${r}`})}function zm(n,e){let t=ke(Qt(n,ee(e),{trailing:!1}));return Vo(t.filter(r=>!(r.kind===hn&&r.column>0&&r.node.childCount===0)))}function vc(n){return Vo(n)}function $m(n,e){let t=Math.min(n.length,e.length);for(let r=0;r<t;r++)if(n[r]!==e[r])return r;return n.length===e.length?-1:t}function jr(n,e){let t=n.type.schema,r=l=>{let a=P(n,e,l);return a.shapes=Vo(a.emitted),a.mismatch=$m(a.shapes,zm(t,a.body)),a},i=new Set,o=new Set,s=r({});for(let l=0;s.mismatch>=0&&l<4;l++){let a=[-1,0,1,2].map(c=>s.emitted[s.mismatch+c]);for(let c of a)c&&(o.add(c.index),l>=2&&i.add(c.index));s=r({fresh:i,joins:o})}if(s.mismatch>=0){let l=new Set(s.blocks.map(a=>a.index));s=r({fresh:l,joins:l})}return{ok:s.mismatch<0,body:s.body,shapes:s.shapes,fixed:o.size>0}}var Jr=class{constructor(){this.issued=0,this.table=new Map}mint(){return++this.issued}get(e){return this.table.get(e)}record(e,t){if(this.table.has(e))throw new Error(`origin ${e} is already recorded`);this.table.set(e,Object.freeze(t))}},st=new N("mapa-fidelity");function tn(n,e,t,r={}){let i=yt(t),o=ee(i),s=o.map(()=>e.mint()),l=Qt(n,o,{origin:f=>s[f],...r}),a=new Map(ke(l).map(f=>[Kr(f),f])),c=s.map(f=>a.get(f)),u=r.edges!==!1;return o.forEach((f,d)=>{let h=o[d-1],p=o[d+1];e.record(s[d],{node:c[d].node,source:f.source,context:xe(c[d]),prev:h?s[d-1]:null,next:p?s[d+1]:null,before:h?i.slice(h.to,f.from):null,after:p?i.slice(f.to,p.from):null,leading:u&&!h?i.slice(0,f.from):null,trailing:u&&!p?i.slice(f.to):null})}),{doc:l,nodes:c,origins:s}}function qo(n,e){let t=new Jr,{doc:r}=tn(n,t,e);return{doc:r,fidelity:t}}function Fm(n,e){return ye(n.kind)||ye(e.kind)?n.kind===e.kind&&xe(n)===xe(e):xe(n)===xe(e)&&Fo(Nt(n),e.node)}function Pc(n,e,t){let r=0;for(;r<n.length&&r<e.length&&t(n[r],e[r]);)r++;let i=0;for(;i<n.length-r&&i<e.length-r&&t(n[n.length-1-i],e[e.length-1-i]);)i++;let o=Vm(n.slice(r,n.length-i),e.slice(r,e.length-i),t);return[...Array.from({length:r},(s,l)=>[l,l]),...o.map(([s,l])=>[s+r,l+r]),...Array.from({length:i},(s,l)=>[n.length-i+l,e.length-i+l])]}function Vm(n,e,t){let r=n.length,i=e.length,o=Array.from({length:r+1},()=>new Int32Array(i+1));for(let l=r-1;l>=0;l--)for(let a=i-1;a>=0;a--)o[l][a]=t(n[l],e[a])?o[l+1][a+1]+1:Math.max(o[l+1][a],o[l][a+1]);let s=[];for(let l=0,a=0;l<r&&a<i;)t(n[l],e[a])?(s.push([l,a]),l++,a++):o[l+1][a]>=o[l][a+1]?l++:a++;return s}function Rc(n,e,t){let r=n.state,{nodes:i,origins:o}=tn(r.schema,e,t),s=i.slice(0,o.length),l=P(r.doc,e).emitted,a=r.tr;for(let[c,u]of Pc(l,s,Fm))a.setNodeAttribute(l[c].pos,$o(l[c]),o[u]);return a.setMeta("addToHistory",!1).setMeta(st,{rebuilt:!0}),n.dispatch(a),{ok:Fn(n.state.doc,e)===ge(t)}}function Wo(n,e){let t=e.topNodeType.create(null,n),{emitted:r}=P(t,null,{raw:!0}),i=vc(r);return JSON.stringify(r.map((o,s)=>[i[s],o.text]))}function Ko(n,e,t,r=null){let i=n.doc.type.schema,o=r?r.node:n.doc,s=r?r.start:0,{doc:l}=tn(i,e,t,r?{trailing:!1,edges:!1}:{}),a=[];o.forEach((m,g)=>{let y=Wo(m,i);y!=="[]"&&a.push({node:m,offset:g+s,key:y})});let c=[];l.forEach(m=>{let g=Wo(m,i);g!=="[]"&&c.push({node:m,key:g})});let u=Pc(a,c,(m,g)=>m.key===g.key),f=[],d=[-1,-1];for(let m of[...u,[a.length,c.length]]){let[g,y]=[d[0]+1,d[1]+1];if(m[0]>g||m[1]>y){let C=g<a.length?a[g].offset:a[a.length-1]?a[a.length-1].offset+a[a.length-1].node.nodeSize:s,O=m[0]>g?a[m[0]-1].offset+a[m[0]-1].node.nodeSize:C;f.push({from:C,to:O,nodes:c.slice(y,m[1]).map($=>$.node)})}d=m}let h=n.selection.head,p=null;for(let m of f.reverse()){p===null&&h>=m.from&&h<=m.to&&(p={left:Wm(n.doc,h,m.to),gap:m});let g=[];n.doc.nodesBetween(m.from,m.to,(y,C)=>(C>=m.from&&Wo(y,i)==="[]"&&g.push(y),!1)),n.replaceWith(m.from,m.to,b.from([...m.nodes,...g])),m.size=[...m.nodes,...g].reduce((y,C)=>y+C.nodeSize,0)}if(p){let m=n.mapping.map(p.gap.from,-1),g=qm(n.doc,m,m+p.gap.size,p.left);n.setSelection(k.near(n.doc.resolve(g),-1))}return n}function Wm(n,e,t){let r=0;return n.nodesBetween(e,t,(i,o)=>{i.isText?r+=Math.min(o+i.nodeSize,t)-Math.max(o,e):i.isInline&&(r+=1)}),r}function qm(n,e,t,r){let i=null,o=[];n.nodesBetween(e,t,(s,l)=>{if(s.isTextblock)return o.push({node:s,pos:l}),!1});for(let{node:s,pos:l}of o.reverse()){let a=s.content.size;if(r<=a){i=l+1+a-r;break}r-=a}return i===null&&(i=o.length?o[o.length-1].pos+1:e),Math.min(Math.max(i,0),n.content.size)}function Hr(n,e,t){let r=Ko(n.state.tr,e,t).setMeta("mapa-applied",!0);return r.docChanged&&n.dispatch(r.scrollIntoView()),Rc(n,e,t)}function jo(n,e){let t=jr(n.state.doc,e);if(t.ok)return{body:t.body,shapes:t.shapes,adopted:!1};Hr(n,e,t.body);let r=jr(n.state.doc,e);return{body:r.body,shapes:r.shapes,adopted:!0}}var Km={paragraph:["marker"],heading:["level","marker"],code_block:["fence","info","closed","close"],list_item:["indent","bullet","number","delim","task","checked","marker"],blockquote:["prefix","marker"]};function Ic(n){return n.kind===R||n.kind===oe?n.holder:n.node}function jm(n,e){if(n.kind===Ce||ye(n.kind))return null;let t=Wr(n);if(t==="")return null;let r=ee(t);if(r.length!==1||r[0].kind!==n.kind)return"structural";let i=ke(Qt(e,r,{trailing:!1}))[0];if(n.kind===R&&i.list!==n.list)return"structural";let o=Ic(n),s=Ic(i),l=[];for(let d of Km[o.type.name]??[])JSON.stringify(o.attrs[d])!==JSON.stringify(s.attrs[d])&&l.push([d,s.attrs[d]]);let a=Nt(n).content,c=i.node.content,u=a.findDiffStart(c);if(u===null&&l.length===0)return null;let f=null;if(u!==null){let{a:d,b:h}=a.findDiffEnd(c),p=u-Math.min(d,h);p>0&&(d+=p,h+=p),f={from:u,to:d,content:c.cut(u,h)}}return{block:n,attrs:l,diff:f,text:t,node:i.node}}function Jm(n,{block:e,attrs:t,diff:r},i){if(r){let s=e.pos+1;n.replaceWith(s+r.from,s+r.to,r.content)}let o=e.kind===R||e.kind===oe?e.holderPos:e.pos;for(let[s,l]of t)n.setNodeAttribute(o,s,l);n.setNodeAttribute(e.pos,"origin",i)}function Hm(n,e,t=null){let r=n.tr;return Lc(r,e,t),r.docChanged?r:null}function Um(n,e){let t=n.blocks.filter(i=>!i.untouched);if(!e)return t;let r=new Map(ke(e).map(i=>[i.node,xe(i)]));return t.filter(i=>!i.first||r.get(i.node)!==xe(i))}function Lc(n,e,t){let r=n.doc.type.schema,i=P(n.doc,e),o=[];for(let f of Um(i,t)){let d=jm(f,r);if(d==="structural"){f.column>0?eg(n,e,f):Ko(n,e,i.body);return}d&&o.push(d)}if(o.length===0)return;let s=new Map(o.map(f=>[f.block,e.mint()])),l=f=>s.get(f)??(f.first?f.origin:null),{emitted:a}=i,c=o.map(({block:f,text:d,node:h})=>{let p=a.indexOf(f),m=a[p-1],g=a[p+1],y=s.get(f);return{origin:y,source:d,node:h.type.create({...h.attrs,origin:y},h.content,h.marks),prev:m?l(m):null,next:g?l(g):null,before:m?f.seam:null,after:g?g.seam:null,leading:p===0?f.entry?.leading??null:null,trailing:p>=0&&!g?f.entry?.trailing??null:null}});for(let f of[...o].reverse())Jm(n,f,s.get(f.block));let u=new Map(ke(n.doc).map(f=>[Kr(f),f]));for(let{origin:f,...d}of c)e.record(f,{...d,context:xe(u.get(f))})}function _m(n,e){let t=s=>{let l=new Map;for(let a of ke(s)){let c=a.holder.attrs.marker;c&&l.set(c,(l.get(c)??0)+1)}return l},r=e?t(e):new Map,i=new Set(e?ke(e).map(s=>s.holder):[]),o=ke(n.doc);for(let[s,l]of t(n.doc)){let a=l-Math.max(r.get(s)??0,1);if(a<=0)continue;let c=o.filter(h=>h.holder.attrs.marker===s),u=c.find(h=>i.has(h.holder))??c[0],f=c.filter(h=>h!==u),d=[...f.filter(h=>!i.has(h.holder)).reverse(),...f.filter(h=>i.has(h.holder)).reverse()];for(let h of d.slice(0,a))n.setNodeAttribute(h.holderPos,"marker",null)}}function Ym(n){return Math.floor(String(n??"").replaceAll(" "," ").length/2)}function Gm(n,e){let t=-1;for(let o of P(n.doc,e).emitted){if(o.kind!==R){t=-1;continue}let s=Ym(o.holder.attrs.indent),l=" ".repeat(o.depth);Math.min(s,t+1)!==o.depth&&o.depth<=t+1&&o.holder.attrs.indent!==l&&n.setNodeAttribute(o.holderPos,"indent",l),t=o.depth}let r=[],i=(o,s)=>{let l=s,a=null;o.forEach(c=>{a&&a.type===c.type&&(c.type.name==="bullet_list"||c.type.name==="ordered_list")&&r.push(l),a=c,l+=c.nodeSize})};i(n.doc,0),n.doc.descendants((o,s)=>{if(o.isTextblock)return!1;i(o,s+1)});for(let o of r.sort((s,l)=>l-s))n.join(o)}function Xm(n,e){let t=P(n.doc,e),r=t.emitted.filter(s=>ye(s.kind)).map(s=>s.kind),i=ee(t.body).filter(s=>ye(s.kind)).map(s=>s.kind);if(r.join()===i.join())return;let o=[];n.doc.descendants((s,l)=>s.isTextblock?(s.type.name!=="code_block"&&Zm(s,l,o),!1):!0);for(let s of o.reverse())n.insertText("\u200B",s)}function Zm(n,e,t){let r="",i=e+1,o=i,s=()=>{Li(r)&&t.push(o+r.indexOf(":"))};n.forEach((l,a)=>{l.type.name==="hard_break"?(s(),r="",o=i+a+l.nodeSize):l.isText?r+=l.text:r+="\uFFFC"}),s()}function Qm(n){let e=n.doc.lastChild;(!e||e.type.name!=="paragraph")&&n.insert(n.doc.content.size,n.doc.type.schema.nodes.paragraph.create())}function Bc(n,e,t=null){let r=n.tr;for(let i=0;i<4;i++){let o=r.doc;if(Lc(r,e,t),Xm(r,e),_m(r,t),Gm(r,e),Qm(r),r.doc===o)break}return r.docChanged?r:null}function Jo(n,e={}){let t=null,r=null,i=()=>e.composing?e.composing():t?.composing??!1;return new S({key:st,state:{init:()=>n,apply:(o,s)=>s},view(o){return t=o,{destroy(){t=null}}},props:{handleDOMEvents:{compositionend(o){return setTimeout(()=>{t===o&&r&&o.dispatch(o.state.tr.setMeta(st,{composed:!0}))},50),!1}}},appendTransaction(o,s,l){if(!o.some(f=>f.docChanged&&!f.getMeta(st)?.rebuilt)&&!r)return null;if(i())return r=r??s.doc,null;let c=r??s.doc;r=null;let u=Bc(l,n,c);return u?u.setMeta(st,{settled:!0}):null}})}function eg(n,e,t){let r=n.doc.resolve(t.pos),i=r.depth;for(;i>0&&r.node(i).type.name!=="column";)i--;if(i===0)return;let o=r.node(i),s=r.before(i)+1,l=n.doc.type.schema,a=l.topNodeType.create(null,o.content),c=tg(P(a,e,{edges:!1,raw:!0}).body);Ko(n,e,c,{node:o,start:s});let u=n.doc.nodeAt(s-1);u&&u.type.name==="column"&&u.childCount===0&&n.insert(s,l.nodes.paragraph.create())}function tg(n){let e=null;return n.split(`
`).map(t=>{if(e)return Qe(t,e)&&(e=null),t;let r=Ft(t);return r?(e=r,t):Li(t)?t.replace(/^([ \t]*):::/u,"$1\u200B:::"):t}).join(`
`)}var Ur=200,J=function(){};J.prototype.append=function(e){return e.length?(e=J.from(e),!this.length&&e||e.length<Ur&&this.leafAppend(e)||this.length<Ur&&e.leafPrepend(this)||this.appendInner(e)):this};J.prototype.prepend=function(e){return e.length?J.from(e).append(this):this};J.prototype.appendInner=function(e){return new ng(this,e)};J.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?J.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};J.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};J.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};J.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(o,s){return i.push(e(o,s))},t,r),i};J.from=function(e){return e instanceof J?e:e&&e.length?new zc(e):J.empty};var zc=(function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,o){return i==0&&o==this.length?this:new e(this.values.slice(i,o))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,o,s,l){for(var a=o;a<s;a++)if(i(this.values[a],l+a)===!1)return!1},e.prototype.forEachInvertedInner=function(i,o,s,l){for(var a=o-1;a>=s;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=Ur)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=Ur)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e})(J);J.empty=new zc([]);var ng=(function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return r<this.left.length?this.left.get(r):this.right.get(r-this.left.length)},e.prototype.forEachInner=function(r,i,o,s){var l=this.left.length;if(i<l&&this.left.forEachInner(r,i,Math.min(o,l),s)===!1||o>l&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,o)-l,s+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,o,s){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(o,l)-l,s+l)===!1||o<l&&this.left.forEachInvertedInner(r,Math.min(i,l),o,s)===!1)return!1},e.prototype.sliceInner=function(r,i){if(r==0&&i==this.length)return this;var o=this.left.length;return i<=o?this.left.slice(r,i):r>=o?this.right.slice(r-o,i-o):this.left.slice(r,o).append(this.right.slice(0,i-o))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e})(J),Ho=J;var rg=500,It=class n{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,o;t&&(i=this.remapping(r,this.items.length),o=i.maps.length);let s=e.tr,l,a,c=[],u=[];return this.items.forEach((f,d)=>{if(!f.step){i||(i=this.remapping(r,d+1),o=i.maps.length),o--,u.push(f);return}if(i){u.push(new Ae(f.map));let h=f.step.map(i.slice(o)),p;h&&s.maybeStep(h).doc&&(p=s.mapping.maps[s.mapping.maps.length-1],c.push(new Ae(p,void 0,void 0,c.length+u.length))),o--,p&&i.appendMap(p,o)}else s.maybeStep(f.step);if(f.selection)return l=i?f.selection.map(i.slice(o)):f.selection,a=new n(this.items.slice(0,r).append(u.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:s,selection:l}}addTransform(e,t,r,i){let o=[],s=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let u=0;u<e.steps.length;u++){let f=e.steps[u].invert(e.docs[u]),d=new Ae(e.mapping.maps[u],f,t),h;(h=a&&a.merge(d))&&(d=h,u?o.pop():l=l.slice(0,l.length-1)),o.push(d),t&&(s++,t=void 0),i||(a=d)}let c=s-r.depth;return c>og&&(l=ig(l,c),s-=c),new n(l.append(o),s)}remapping(e,t){let r=new wn;return this.items.forEach((i,o)=>{let s=i.mirrorOffset!=null&&o-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,s)},e,t),r}addMaps(e){return this.eventCount==0?this:new n(this.items.append(e.map(t=>new Ae(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;t=Math.min(this.items.length,t);let r=[],i=this.items.length-t,o=e.mapping,s=e.steps.length,l=this.eventCount;this.items.forEach(d=>{d.selection&&l--},i);let a=t;this.items.forEach(d=>{let h=o.getMirror(--a);if(h==null)return;s=Math.min(s,h);let p=o.maps[h];if(d.step){let m=e.steps[h].invert(e.docs[h]),g=d.selection&&d.selection.map(o.slice(a+1,h));g&&l++,r.push(new Ae(p,m,g))}else r.push(new Ae(p))},i);let c=[];for(let d=t;d<s;d++)c.push(new Ae(o.maps[d]));let u=this.items.slice(0,i).append(c).append(r),f=new n(u,l);return f.emptyItemCount()>rg&&(f=f.compress(this.items.length-r.length)),f}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,i=[],o=0;return this.items.forEach((s,l)=>{if(l>=e)i.push(s),s.selection&&o++;else if(s.step){let a=s.step.map(t.slice(r)),c=a&&a.getMap();if(r--,c&&t.appendMap(c,r),a){let u=s.selection&&s.selection.map(t.slice(r));u&&o++;let f=new Ae(c.invert(),a,u),d,h=i.length-1;(d=i.length&&i[h].merge(f))?i[h]=d:i.push(f)}}else s.map&&r--},this.items.length,0),new n(Ho.from(i.reverse()),o)}};It.empty=new It(Ho.empty,0);function ig(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}var Ae=class n{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new n(t.getMap().invert(),t,this.selection)}}},Ee=class{constructor(e,t,r,i,o){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=o}},og=20;function sg(n,e,t,r){let i=t.getMeta(vt),o;if(i)return i.historyState;t.getMeta(Vc)&&(n=new Ee(n.done,n.undone,null,0,-1));let s=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(s&&s.getMeta(vt))return s.getMeta(vt).redo?new Ee(n.done.addTransform(t,void 0,r,_r(e)),n.undone,$c(t.mapping.maps),n.prevTime,n.prevComposition):new Ee(n.done,n.undone.addTransform(t,void 0,r,_r(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(s&&s.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=n.prevTime==0||!s&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-r.newGroupDelay||!lg(t,n.prevRanges)),c=s?Uo(n.prevRanges,t.mapping):$c(t.mapping.maps);return new Ee(n.done.addTransform(t,a?e.selection.getBookmark():void 0,r,_r(e)),It.empty,c,t.time,l??n.prevComposition)}else return(o=t.getMeta("rebased"))?new Ee(n.done.rebased(t,o),n.undone.rebased(t,o),Uo(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new Ee(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),Uo(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function lg(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((r,i)=>{for(let o=0;o<e.length;o+=2)r<=e[o+1]&&i>=e[o]&&(t=!0)}),t}function $c(n){let e=[];for(let t=n.length-1;t>=0&&e.length==0;t--)n[t].forEach((r,i,o,s)=>e.push(o,s));return e}function Uo(n,e){if(!n)return null;let t=[];for(let r=0;r<n.length;r+=2){let i=e.map(n[r],1),o=e.map(n[r+1],-1);i<=o&&t.push(i,o)}return t}function ag(n,e,t){let r=_r(e),i=vt.get(e).spec.config,o=(t?n.undone:n.done).popEvent(e,r);if(!o)return null;let s=o.selection.resolve(o.transform.doc),l=(t?n.done:n.undone).addTransform(o.transform,e.selection.getBookmark(),i,r),a=new Ee(t?l:o.remaining,t?o.remaining:l,null,0,-1);return o.transform.setSelection(s).setMeta(vt,{redo:t,historyState:a})}var _o=!1,Fc=null;function _r(n){let e=n.plugins;if(Fc!=e){_o=!1,Fc=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){_o=!0;break}}return _o}function Yo(n){return n.setMeta(Vc,!0)}var vt=new N("history"),Vc=new N("closeHistory");function Wc(n={}){return n={depth:n.depth||100,newGroupDelay:n.newGroupDelay||500},new S({key:vt,state:{init(){return new Ee(It.empty,It.empty,null,0,-1)},apply(e,t,r){return sg(t,r,e,n)}},config:n,props:{handleDOMEvents:{beforeinput(e,t){let r=t.inputType,i=r=="historyUndo"?Go:r=="historyRedo"?Xo:null;return!i||!e.editable?!1:(t.preventDefault(),i(e.state,e.dispatch))}}}})}function Yr(n,e){return(t,r)=>{let i=vt.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let o=ag(i,t,n);o&&r(e?o.scrollIntoView():o)}return!0}}var Go=Yr(!1,!0),Xo=Yr(!0,!0),tx=Yr(!1,!1),nx=Yr(!0,!1);function qc(n,e){let t={remote:!1},r=()=>n.view,i=o=>{let s=t.remote;t.remote=!0;try{return o()}finally{t.remote=s}};return t.current=()=>Fn(r().state.doc,e),t.prepare=()=>i(()=>jo(r(),e).body),t.apply=o=>i(()=>{r().dispatch(Yo(r().state.tr));let s=Hr(r(),e,o);return r().dispatch(Yo(r().state.tr)),s}),t}function Ne(n){for(let e=n.depth;e>0;e--)if(n.node(e).type.name==="column")return{layout:n.node(e-1),layoutPos:n.before(e-1),column:n.node(e),columnPos:n.before(e),index:n.index(e-1)};return null}function Kc(n){return n.nodes.column.create(null,n.nodes.paragraph.create())}function cg(n){let{$from:e,$to:t}=n.selection;return e.depth<1?null:{from:e.before(1),to:t.after(1)}}function Zo(n){return(e,t)=>{let r=e.schema;if(Ne(e.selection.$from)||Ne(e.selection.$to))return!1;let i=cg(e);if(!i)return!1;if(t){let o=Gr(e.doc.slice(i.from,i.to).content),s=o.textBetween(0,o.size,"","\uFFFC").trim()!=="",l=r.nodes.column.createChecked(null,o.size?o:r.nodes.paragraph.create()),a=[l];for(let d=1;d<n;d++)a.push(Kc(r));let c=r.nodes.columns.createChecked(null,a),u=e.tr.replaceWith(i.from,i.to,c),f=s?i.from+1+l.nodeSize+1:i.from+2;u.setSelection(k.near(u.doc.resolve(f))),t(u.scrollIntoView())}return!0}}function ug(n,e){let t=Ne(n.selection.$head);if(!t||t.layout.childCount>=4)return!1;if(e){let r=t.columnPos+t.column.nodeSize,i=n.tr.insert(r,Kc(n.schema));i.setSelection(k.near(i.doc.resolve(r+2))),e(i.scrollIntoView())}return!0}function jc(n,e){let t=Ne(n.selection.$head);if(!t)return!1;if(t.layout.childCount<=2)return Jc(n,e);if(e){let r=Hc(t.column.content),i=n.tr.delete(t.columnPos,t.columnPos+t.column.nodeSize),o=t.index>0?t.index-1:0,s=t.layoutPos+1;for(let c=0;c<o;c++)s+=i.doc.nodeAt(t.layoutPos).child(c).nodeSize;let l=i.doc.nodeAt(s),a=t.index>0?s+l.nodeSize-1:s+1;r.size&&i.insert(a,r),i.setSelection(k.near(i.doc.resolve(a))),e(i.scrollIntoView())}return!0}function Jc(n,e){let t=Ne(n.selection.$head);if(!t)return!1;if(e){let r=[];t.layout.forEach(s=>s.forEach(l=>r.push(l)));let i=Hc(b.from(r)),o=n.tr.replaceWith(t.layoutPos,t.layoutPos+t.layout.nodeSize,i.size?i:n.schema.nodes.paragraph.create());o.setSelection(k.near(o.doc.resolve(t.layoutPos+1))),e(o.scrollIntoView())}return!0}function Hc(n){let e=[];return n.forEach(t=>{t.type.name==="paragraph"&&t.content.size===0||e.push(t)}),b.from(e)}function Uc(n,e){let{$head:t,empty:r}=n.selection,i=Ne(t);return!r||!i||!(i.column.childCount===1&&i.column.firstChild.type.name==="paragraph"&&i.column.firstChild.content.size===0)?!1:jc(n,e)}function Qo(n){return(e,t)=>{let r=Ne(e.selection.$head);if(!r)return!1;let i=r.index+n;if(i<0||i>=r.layout.childCount)return!1;if(t){let o=r.layoutPos+1;for(let s=0;s<i;s++)o+=r.layout.child(s).nodeSize;t(e.tr.setSelection(k.near(e.doc.resolve(o+1))).scrollIntoView())}return!0}}function _c(){return{"insert-columns-2":Zo(2),"insert-columns-3":Zo(3),"insert-columns-4":Zo(4),"add-column":ug,"remove-column":jc,"undo-columns":Jc}}function Gr(n){let e=[];return n.forEach(t=>{t.type.name==="columns"?t.forEach(r=>r.forEach(i=>e.push(i))):e.push(t)}),b.from(e)}function es(n){return Ne(n)!==null}function Vn(n){let{$from:e,$to:t,empty:r}=n.selection;if(r)return!1;let i=Ne(e),o=Ne(t);return!i&&!o?!1:!i||!o||i.columnPos!==o.columnPos}function Pt(n,e){if(!Vn(n))return!1;if(e){let{from:t,to:r}=n.selection,i=[];n.doc.nodesBetween(t,r,(s,l,a)=>{if(s.type.name==="columns")return!0;if(s.type.name==="column"){let c=Math.max(t,l+1),u=Math.min(r,l+s.nodeSize-1);return u>c&&i.push({from:c,to:u,column:l}),!1}if(a===n.doc){let c=Math.max(t,l),u=Math.min(r,l+s.nodeSize);u>c&&i.push({from:c,to:u})}return!1});let o=n.tr;for(let s of i.reverse())if(o.delete(o.mapping.map(s.from),o.mapping.map(s.to)),s.column!==void 0){let l=o.mapping.map(s.column),a=o.doc.nodeAt(l);a&&a.content.size===0&&o.insert(l+1,n.schema.nodes.paragraph.create())}o.setSelection(k.near(o.doc.resolve(o.mapping.map(t)))),e(o.scrollIntoView())}return!0}function ts(n){return(e,t)=>{let{$cursor:r}=e.selection;if(!r||r.depth<1||!(n?r.parentOffset===0:r.parentOffset===r.parent.content.size))return!1;let o=r.depth,s=r.index(o-1),a=r.node(o-1).maybeChild(n?s-1:s+1);if(!a||a.type.name!=="columns")return!1;if(t){let c=n?r.before(o)-1:r.after(o)+1,u=n?k.near(e.doc.resolve(c),-1):k.near(e.doc.resolve(c),1);t(e.tr.setSelection(u).scrollIntoView())}return!0}}function Yc(){return new S({props:{handleTextInput(n,e,t,r){return Vn(n.state)?(Pt(n.state,n.dispatch),n.dispatch(n.state.tr.insertText(r).scrollIntoView()),!0):!1},handlePaste(n){return Vn(n.state)&&Pt(n.state,n.dispatch),!1}}})}var ns="application/x-mapa";function rs(n,e,t=n.selection.from,r=n.selection.to,i=""){let s=n.doc.slice(t,r,!0).content,l=s.firstChild;s.childCount===1&&l.type.name==="columns"&&l.childCount===1&&(s=l.firstChild.content);let a=n.schema.topNodeType.create(null,s),{body:c,emitted:u}=P(a,e,{edges:!1,raw:!0}),f=JSON.stringify({v:1,sources:u.map(d=>d.text),seams:u.slice(1).map(d=>d.seam),page:i});return{text:c,mapa:f}}function fg(n){let e;try{e=JSON.parse(n)}catch{return null}if(e?.v!==1||!Array.isArray(e.sources))return null;let t=new Set;for(let r of e.sources){if(typeof r!="string")return null;for(let i of ee(r))if(i.kind!==ie)for(let o of ze(i.source))o.kind===Ze&&t.add(o.target)}return{payload:e,ids:[...t],page:typeof e.page=="string"?e.page:""}}function dg(n,e){let t=n.sources.map(r=>{if(ee(r)[0]?.kind===ie)return r;let i="";for(let o of ze(r)){let s=o.kind===Ze?e[o.target]:null;i+=s?`![${o.text}](${X}${s.id})`:o.source}return i});return JSON.stringify({...n,sources:t})}function hg(n){if(!/<img/iu.test(n))return n;let e=new DOMParser().parseFromString(n,"text/html");for(let t of[...e.querySelectorAll("img")]){let r=t.getAttribute("src")??"";if(!r.startsWith(X))if(Re(r)){let i=e.createElement("a");i.setAttribute("href",r),i.textContent=t.getAttribute("alt")||r,t.replaceWith(i)}else t.remove()}return e.body.innerHTML}function pg(n){let e;try{e=JSON.parse(n)}catch{return null}let{sources:t,seams:r}=e??{};if(e?.v!==1||!Array.isArray(t)||!Array.isArray(r)||t.length===0||r.length!==t.length-1||![...t,...r].every(s=>typeof s=="string")||!r.every(s=>/^\n(?:[^\n]*\n)*$/u.test(s)))return null;let i=t.map((s,l)=>(l?r[l-1]:"")+s).join(""),o=ee(i);return o.length!==t.length||o.some((s,l)=>s.source!==t[l])?null:i}function mg(n,e){let{from:t,to:r}=n.selection,i=new Set;for(let o of P(n.doc,e).emitted){let s=o.holder.attrs.marker,l=o.holderPos>=t&&o.holderPos+o.holder.nodeSize<=r;s&&!l&&i.add(s)}return i}function Gc(n,e){let t=[];return n.forEach(r=>{let i=r;!r.isTextblock&&!r.isLeaf&&(i=r.copy(Gc(r.content,e))),i.attrs.marker&&e.has(i.attrs.marker)&&(i=i.type.create({...i.attrs,marker:null},i.content,i.marks)),t.push(i)}),b.from(t)}function Xc(n,e,t){let r=mg(e,t);return r.size===0?n:new x(Gc(n.content,r),n.openStart,n.openEnd)}function is(n,e,t){let r=pg(t);if(r===null)return null;let{doc:i}=tn(n.schema,e,r,{trailing:!1,edges:!1}),o=es(n.selection.$from)?Gr(i.content):i.content,s=Xc(x.maxOpen(o),n,e),{$from:l,empty:a}=n.selection;if(a&&l.depth===1&&l.parent.type.name==="paragraph"&&l.parent.content.size===0){let c=n.tr.replaceWith(l.before(),l.after(),s.content),u=l.before()+s.content.size;return c.setSelection(k.near(c.doc.resolve(u),-1))}return n.tr.replaceSelection(s)}function Zc(n,e){let t=$n(n,e,{trailing:!1});return t.childCount?x.maxOpen(t.content):x.empty}function gg(n,e){let t=e.content,r=t.firstChild;if(!r)return"";r.isInline?t=b.from(n.nodes.paragraph.create(null,t)):r.type.name==="list_item"&&(t=b.from(n.nodes.bullet_list.create(null,t)));try{return P(n.topNodeType.create(null,t),null,{edges:!1,raw:!0}).body}catch{return e.content.textBetween(0,e.content.size,`