From 06d1780fd82905bbb1ed0a73b8d943968bb6ca46 Mon Sep 17 00:00:00 2001 From: Martin Ziegler Date: Sun, 30 Nov 2025 16:53:05 +0100 Subject: [PATCH] Minor bugfixes --- frontend/src/components/TimelapseViewer.tsx | 11 +++++++++++ .../assets/{index-0UQnyYo8.js => index-C2974G18.js} | 2 +- static/index.html | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) rename static/assets/{index-0UQnyYo8.js => index-C2974G18.js} (99%) diff --git a/frontend/src/components/TimelapseViewer.tsx b/frontend/src/components/TimelapseViewer.tsx index 2c9572972..2d665e135 100644 --- a/frontend/src/components/TimelapseViewer.tsx +++ b/frontend/src/components/TimelapseViewer.tsx @@ -25,6 +25,17 @@ export function TimelapseViewer({ src, title, downloadFilename, onClose }: Timel } }, [playbackRate]); + // Close on Escape key + useEffect(() => { + const handleKeyDown = (e: KeyboardEvent) => { + if (e.key === 'Escape') { + onClose(); + } + }; + window.addEventListener('keydown', handleKeyDown); + return () => window.removeEventListener('keydown', handleKeyDown); + }, [onClose]); + useEffect(() => { const video = videoRef.current; if (!video) return; diff --git a/static/assets/index-0UQnyYo8.js b/static/assets/index-C2974G18.js similarity index 99% rename from static/assets/index-0UQnyYo8.js rename to static/assets/index-C2974G18.js index e355e5863..df124f36f 100644 --- a/static/assets/index-0UQnyYo8.js +++ b/static/assets/index-C2974G18.js @@ -8547,7 +8547,7 @@ ${m.slice(c+2)}`,f+=1;else break}e.push({indent:c,number:parseInt(o,10),content: `):"",markdownTokenizer:{name:"orderedList",level:"block",start:t=>{const e=t.match(/^(\s*)(\d+)\.\s+/),n=e?.index;return n!==void 0?n:-1},tokenize:(t,e,n)=>{var i;const r=t.split(` `),[a,s]=PMe(r);if(a.length===0)return;const o=D7(a,0,n);return o.length===0?void 0:{type:"list",ordered:!0,start:((i=a[0])==null?void 0:i.number)||1,items:o,raw:r.slice(0,s).join(` `)}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleOrderedList:()=>({commands:t,chain:e})=>this.options.keepAttributes?e().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(OMe,this.editor.getAttributes(a5)).run():t.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addInputRules(){let t=Vp({find:s5,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:(e,n)=>n.childCount+n.attrs.start===+e[1]});return(this.options.keepMarks||this.options.keepAttributes)&&(t=Vp({find:s5,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(a5)}),joinPredicate:(e,n)=>n.childCount+n.attrs.start===+e[1],editor:this.editor})),[t]}}),kMe=/^\s*(\[([( |x])?\])\s$/,LMe=Fa.create({name:"taskItem",addOptions(){return{nested:!1,HTMLAttributes:{},taskListTypeName:"taskList",a11y:void 0}},content(){return this.options.nested?"paragraph block*":"paragraph+"},defining:!0,addAttributes(){return{checked:{default:!1,keepOnSplit:!1,parseHTML:t=>{const e=t.getAttribute("data-checked");return e===""||e==="true"},renderHTML:t=>({"data-checked":t.checked})}}},parseHTML(){return[{tag:`li[data-type="${this.name}"]`,priority:51}]},renderHTML({node:t,HTMLAttributes:e}){return["li",wi(this.options.HTMLAttributes,e,{"data-type":this.name}),["label",["input",{type:"checkbox",checked:t.attrs.checked?"checked":null}],["span"]],["div",0]]},parseMarkdown:(t,e)=>{const n=[];if(t.tokens&&t.tokens.length>0?n.push(e.createNode("paragraph",{},e.parseInline(t.tokens))):t.text?n.push(e.createNode("paragraph",{},[e.createNode("text",{text:t.text})])):n.push(e.createNode("paragraph",{},[])),t.nestedTokens&&t.nestedTokens.length>0){const i=e.parseChildren(t.nestedTokens);n.push(...i)}return e.createNode("taskItem",{checked:t.checked||!1},n)},renderMarkdown:(t,e)=>{var n;const r=`- [${(n=t.attrs)!=null&&n.checked?"x":" "}] `;return JP(t,e,r)},addKeyboardShortcuts(){const t={Enter:()=>this.editor.commands.splitListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)};return this.options.nested?{...t,Tab:()=>this.editor.commands.sinkListItem(this.name)}:t},addNodeView(){return({node:t,HTMLAttributes:e,getPos:n,editor:i})=>{const r=document.createElement("li"),a=document.createElement("label"),s=document.createElement("span"),o=document.createElement("input"),l=document.createElement("div"),c=d=>{var f,p;o.ariaLabel=((p=(f=this.options.a11y)==null?void 0:f.checkboxLabel)==null?void 0:p.call(f,d,o.checked))||`Task item checkbox for ${d.textContent||"empty task item"}`};return c(t),a.contentEditable="false",o.type="checkbox",o.addEventListener("mousedown",d=>d.preventDefault()),o.addEventListener("change",d=>{if(!i.isEditable&&!this.options.onReadOnlyChecked){o.checked=!o.checked;return}const{checked:f}=d.target;i.isEditable&&typeof n=="function"&&i.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:p})=>{const m=n();if(typeof m!="number")return!1;const _=p.doc.nodeAt(m);return p.setNodeMarkup(m,void 0,{..._?.attrs,checked:f}),!0}).run(),!i.isEditable&&this.options.onReadOnlyChecked&&(this.options.onReadOnlyChecked(t,f)||(o.checked=!o.checked))}),Object.entries(this.options.HTMLAttributes).forEach(([d,f])=>{r.setAttribute(d,f)}),r.dataset.checked=t.attrs.checked,o.checked=t.attrs.checked,a.append(o,s),r.append(a,l),Object.entries(e).forEach(([d,f])=>{r.setAttribute(d,f)}),{dom:r,contentDOM:l,update:d=>d.type!==this.type?!1:(r.dataset.checked=d.attrs.checked,o.checked=d.attrs.checked,c(d),!0)}}},addInputRules(){return[Vp({find:kMe,type:this.type,getAttributes:t=>({checked:t[t.length-1]==="x"})})]}}),IMe=Fa.create({name:"taskList",addOptions(){return{itemTypeName:"taskItem",HTMLAttributes:{}}},group:"block list",content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul[data-type="${this.name}"]`,priority:51}]},renderHTML({HTMLAttributes:t}){return["ul",wi(this.options.HTMLAttributes,t,{"data-type":this.name}),0]},parseMarkdown:(t,e)=>e.createNode("taskList",{},e.parseChildren(t.items||[])),renderMarkdown:(t,e)=>t.content?e.renderChildren(t.content,` -`):"",markdownTokenizer:{name:"taskList",level:"block",start(t){var e;const n=(e=t.match(/^\s*[-+*]\s+\[([ xX])\]\s+/))==null?void 0:e.index;return n!==void 0?n:-1},tokenize(t,e,n){const i=a=>{const s=pR(a,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:o=>({indentLevel:o[1].length,mainContent:o[4],checked:o[3].toLowerCase()==="x"}),createToken:(o,l)=>({type:"taskItem",raw:"",mainContent:o.mainContent,indentLevel:o.indentLevel,checked:o.checked,text:o.mainContent,tokens:n.inlineTokens(o.mainContent),nestedTokens:l}),customNestedParser:i},n);return s?[{type:"taskList",raw:s.raw,items:s.items}]:n.blockTokens(a)},r=pR(t,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:a=>({indentLevel:a[1].length,mainContent:a[4],checked:a[3].toLowerCase()==="x"}),createToken:(a,s)=>({type:"taskItem",raw:"",mainContent:a.mainContent,indentLevel:a.indentLevel,checked:a.checked,text:a.mainContent,tokens:n.inlineTokens(a.mainContent),nestedTokens:s}),customNestedParser:i},n);if(r)return{type:"taskList",raw:r.raw,items:r.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:t})=>t.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});Gn.create({name:"listKit",addExtensions(){const t=[];return this.options.bulletList!==!1&&t.push(M7.configure(this.options.bulletList)),this.options.listItem!==!1&&t.push(E7.configure(this.options.listItem)),this.options.listKeymap!==!1&&t.push(P7.configure(this.options.listKeymap)),this.options.orderedList!==!1&&t.push(O7.configure(this.options.orderedList)),this.options.taskItem!==!1&&t.push(LMe.configure(this.options.taskItem)),this.options.taskList!==!1&&t.push(IMe.configure(this.options.taskList)),t}});var UMe=Fa.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:t}){return["p",wi(this.options.HTMLAttributes,t),0]},parseMarkdown:(t,e)=>{const n=t.tokens||[];return n.length===1&&n[0].type==="image"?e.parseChildren([n[0]]):e.createNode("paragraph",void 0,e.parseInline(n))},renderMarkdown:(t,e)=>!t||!Array.isArray(t.content)?"":e.renderChildren(t.content),addCommands(){return{setParagraph:()=>({commands:t})=>t.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),FMe=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,zMe=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,jMe=Ju.create({name:"strike",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",consuming:!1,getAttrs:t=>t.includes("line-through")?{}:!1}]},renderHTML({HTMLAttributes:t}){return["s",wi(this.options.HTMLAttributes,t),0]},markdownTokenName:"del",parseMarkdown:(t,e)=>e.applyMark("strike",e.parseInline(t.tokens||[])),renderMarkdown:(t,e)=>`~~${e.renderChildren(t)}~~`,addCommands(){return{setStrike:()=>({commands:t})=>t.setMark(this.name),toggleStrike:()=>({commands:t})=>t.toggleMark(this.name),unsetStrike:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[Hp({find:FMe,type:this.type})]},addPasteRules(){return[Ef({find:zMe,type:this.type})]}}),BMe=Fa.create({name:"text",group:"inline",parseMarkdown:t=>({type:"text",text:t.text||""}),renderMarkdown:t=>t.text||""}),k7=Ju.create({name:"underline",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:t=>t.includes("underline")?{}:!1}]},renderHTML({HTMLAttributes:t}){return["u",wi(this.options.HTMLAttributes,t),0]},parseMarkdown(t,e){return e.applyMark(this.name||"underline",e.parseInline(t.tokens||[]))},renderMarkdown(t,e){return`++${e.renderChildren(t)}++`},markdownTokenizer:{name:"underline",level:"inline",start(t){return t.indexOf("++")},tokenize(t,e,n){const r=/^(\+\+)([\s\S]+?)(\+\+)/.exec(t);if(!r)return;const a=r[2].trim();return{type:"underline",raw:r[0],text:a,tokens:n.inlineTokens(a)}}},addCommands(){return{setUnderline:()=>({commands:t})=>t.setMark(this.name),toggleUnderline:()=>({commands:t})=>t.toggleMark(this.name),unsetUnderline:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),HMe=k7;function VMe(t={}){return new mi({view(e){return new GMe(e,t)}})}class GMe{constructor(e,n){var i;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=(i=n.width)!==null&&i!==void 0?i:1,this.color=n.color===!1?void 0:n.color||"black",this.class=n.class,this.handlers=["dragover","dragend","drop","dragleave"].map(r=>{let a=s=>{this[r](s)};return e.dom.addEventListener(r,a),{name:r,handler:a}})}destroy(){this.handlers.forEach(({name:e,handler:n})=>this.editorView.dom.removeEventListener(e,n))}update(e,n){this.cursorPos!=null&&n.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),n=!e.parent.inlineContent,i,r=this.editorView.dom,a=r.getBoundingClientRect(),s=a.width/r.offsetWidth,o=a.height/r.offsetHeight;if(n){let f=e.nodeBefore,p=e.nodeAfter;if(f||p){let m=this.editorView.nodeDOM(this.cursorPos-(f?f.nodeSize:0));if(m){let _=m.getBoundingClientRect(),b=f?_.bottom:_.top;f&&p&&(b=(b+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let y=this.width/2*o;i={left:_.left,right:_.right,top:b-y,bottom:b+y}}}}if(!i){let f=this.editorView.coordsAtPos(this.cursorPos),p=this.width/2*s;i={left:f.left-p,right:f.left+p,top:f.top,bottom:f.bottom}}let l=this.editorView.dom.offsetParent;this.element||(this.element=l.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",n),this.element.classList.toggle("prosemirror-dropcursor-inline",!n);let c,d;if(!l||l==document.body&&getComputedStyle(l).position=="static")c=-pageXOffset,d=-pageYOffset;else{let f=l.getBoundingClientRect(),p=f.width/l.offsetWidth,m=f.height/l.offsetHeight;c=f.left-l.scrollLeft*p,d=f.top-l.scrollTop*m}this.element.style.left=(i.left-c)/s+"px",this.element.style.top=(i.top-d)/o+"px",this.element.style.width=(i.right-i.left)/s+"px",this.element.style.height=(i.bottom-i.top)/o+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let n=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),i=n&&n.inside>=0&&this.editorView.state.doc.nodeAt(n.inside),r=i&&i.type.spec.disableDropCursor,a=typeof r=="function"?r(this.editorView,n,e):r;if(n&&!a){let s=n.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let o=O9(this.editorView.state.doc,s,this.editorView.dragging.slice);o!=null&&(s=o)}this.setCursor(s),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}class Si extends tn{constructor(e){super(e,e)}map(e,n){let i=e.resolve(n.map(this.head));return Si.valid(i)?new Si(i):tn.near(i)}content(){return wt.empty}eq(e){return e instanceof Si&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new Si(e.resolve(n.pos))}getBookmark(){return new uD(this.anchor)}static valid(e){let n=e.parent;if(n.isTextblock||!$Me(e)||!WMe(e))return!1;let i=n.type.spec.allowGapCursor;if(i!=null)return i;let r=n.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(e,n,i=!1){e:for(;;){if(!i&&Si.valid(e))return e;let r=e.pos,a=null;for(let s=e.depth;;s--){let o=e.node(s);if(n>0?e.indexAfter(s)0){a=o.child(n>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;r+=n;let l=e.doc.resolve(r);if(Si.valid(l))return l}for(;;){let s=n>0?a.firstChild:a.lastChild;if(!s){if(a.isAtom&&!a.isText&&!Ut.isSelectable(a)){e=e.doc.resolve(r+a.nodeSize*n),i=!1;continue e}break}a=s,r+=n;let o=e.doc.resolve(r);if(Si.valid(o))return o}return null}}}Si.prototype.visible=!1;Si.findFrom=Si.findGapCursorFrom;tn.jsonID("gapcursor",Si);class uD{constructor(e){this.pos=e}map(e){return new uD(e.map(this.pos))}resolve(e){let n=e.resolve(this.pos);return Si.valid(n)?new Si(n):tn.near(n)}}function L7(t){return t.isAtom||t.spec.isolating||t.spec.createGapCursor}function $Me(t){for(let e=t.depth;e>=0;e--){let n=t.index(e),i=t.node(e);if(n==0){if(i.type.spec.isolating)return!0;continue}for(let r=i.child(n-1);;r=r.lastChild){if(r.childCount==0&&!r.inlineContent||L7(r.type))return!0;if(r.inlineContent)return!1}}return!0}function WMe(t){for(let e=t.depth;e>=0;e--){let n=t.indexAfter(e),i=t.node(e);if(n==i.childCount){if(i.type.spec.isolating)return!0;continue}for(let r=i.child(n);;r=r.firstChild){if(r.childCount==0&&!r.inlineContent||L7(r.type))return!0;if(r.inlineContent)return!1}}return!0}function qMe(){return new mi({props:{decorations:ZMe,createSelectionBetween(t,e,n){return e.pos==n.pos&&Si.valid(n)?new Si(n):null},handleClick:KMe,handleKeyDown:XMe,handleDOMEvents:{beforeinput:YMe}}})}const XMe=OW({ArrowLeft:mb("horiz",-1),ArrowRight:mb("horiz",1),ArrowUp:mb("vert",-1),ArrowDown:mb("vert",1)});function mb(t,e){const n=t=="vert"?e>0?"down":"up":e>0?"right":"left";return function(i,r,a){let s=i.selection,o=e>0?s.$to:s.$from,l=s.empty;if(s instanceof jt){if(!a.endOfTextblock(n)||o.depth==0)return!1;l=!1,o=i.doc.resolve(e>0?o.after():o.before())}let c=Si.findGapCursorFrom(o,e,l);return c?(r&&r(i.tr.setSelection(new Si(c))),!0):!1}}function KMe(t,e,n){if(!t||!t.editable)return!1;let i=t.state.doc.resolve(e);if(!Si.valid(i))return!1;let r=t.posAtCoords({left:n.clientX,top:n.clientY});return r&&r.inside>-1&&Ut.isSelectable(t.state.doc.nodeAt(r.inside))?!1:(t.dispatch(t.state.tr.setSelection(new Si(i))),!0)}function YMe(t,e){if(e.inputType!="insertCompositionText"||!(t.state.selection instanceof Si))return!1;let{$from:n}=t.state.selection,i=n.parent.contentMatchAt(n.index()).findWrapping(t.state.schema.nodes.text);if(!i)return!1;let r=ut.empty;for(let s=i.length-1;s>=0;s--)r=ut.from(i[s].createAndFill(null,r));let a=t.state.tr.replace(n.pos,n.pos,new wt(r,0,0));return a.setSelection(jt.near(a.doc.resolve(n.pos+1))),t.dispatch(a),!1}function ZMe(t){if(!(t.selection instanceof Si))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",fi.create(t.doc,[da.widget(t.selection.head,e,{key:"gapcursor"})])}var p1=200,Er=function(){};Er.prototype.append=function(e){return e.length?(e=Er.from(e),!this.length&&e||e.length=n?Er.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,n))};Er.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};Er.prototype.forEach=function(e,n,i){n===void 0&&(n=0),i===void 0&&(i=this.length),n<=i?this.forEachInner(e,n,i,0):this.forEachInvertedInner(e,n,i,0)};Er.prototype.map=function(e,n,i){n===void 0&&(n=0),i===void 0&&(i=this.length);var r=[];return this.forEach(function(a,s){return r.push(e(a,s))},n,i),r};Er.from=function(e){return e instanceof Er?e:e&&e.length?new I7(e):Er.empty};var I7=(function(t){function e(i){t.call(this),this.values=i}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var n={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(r,a){return r==0&&a==this.length?this:new e(this.values.slice(r,a))},e.prototype.getInner=function(r){return this.values[r]},e.prototype.forEachInner=function(r,a,s,o){for(var l=a;l=s;l--)if(r(this.values[l],o+l)===!1)return!1},e.prototype.leafAppend=function(r){if(this.length+r.length<=p1)return new e(this.values.concat(r.flatten()))},e.prototype.leafPrepend=function(r){if(this.length+r.length<=p1)return new e(r.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(e.prototype,n),e})(Er);Er.empty=new I7([]);var QMe=(function(t){function e(n,i){t.call(this),this.left=n,this.right=i,this.length=n.length+i.length,this.depth=Math.max(n.depth,i.depth)+1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(i){return io&&this.right.forEachInner(i,Math.max(r-o,0),Math.min(this.length,a)-o,s+o)===!1)return!1},e.prototype.forEachInvertedInner=function(i,r,a,s){var o=this.left.length;if(r>o&&this.right.forEachInvertedInner(i,r-o,Math.max(a,o)-o,s+o)===!1||a=a?this.right.slice(i-a,r-a):this.left.slice(i,a).append(this.right.slice(0,r-a))},e.prototype.leafAppend=function(i){var r=this.right.leafAppend(i);if(r)return new e(this.left,r)},e.prototype.leafPrepend=function(i){var r=this.left.leafPrepend(i);if(r)return new e(r,this.right)},e.prototype.appendInner=function(i){return this.left.depth>=Math.max(this.right.depth,i.depth)+1?new e(this.left,new e(this.right,i)):new e(this,i)},e})(Er);const JMe=500;class so{constructor(e,n){this.items=e,this.eventCount=n}popEvent(e,n){if(this.eventCount==0)return null;let i=this.items.length;for(;;i--)if(this.items.get(i-1).selection){--i;break}let r,a;n&&(r=this.remapping(i,this.items.length),a=r.maps.length);let s=e.tr,o,l,c=[],d=[];return this.items.forEach((f,p)=>{if(!f.step){r||(r=this.remapping(i,p+1),a=r.maps.length),a--,d.push(f);return}if(r){d.push(new Do(f.map));let m=f.step.map(r.slice(a)),_;m&&s.maybeStep(m).doc&&(_=s.mapping.maps[s.mapping.maps.length-1],c.push(new Do(_,void 0,void 0,c.length+d.length))),a--,_&&r.appendMap(_,a)}else s.maybeStep(f.step);if(f.selection)return o=r?f.selection.map(r.slice(a)):f.selection,l=new so(this.items.slice(0,i).append(d.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:l,transform:s,selection:o}}addTransform(e,n,i,r){let a=[],s=this.eventCount,o=this.items,l=!r&&o.length?o.get(o.length-1):null;for(let d=0;dtEe&&(o=eEe(o,c),s-=c),new so(o.append(a),s)}remapping(e,n){let i=new D0;return this.items.forEach((r,a)=>{let s=r.mirrorOffset!=null&&a-r.mirrorOffset>=e?i.maps.length-r.mirrorOffset:void 0;i.appendMap(r.map,s)},e,n),i}addMaps(e){return this.eventCount==0?this:new so(this.items.append(e.map(n=>new Do(n))),this.eventCount)}rebased(e,n){if(!this.eventCount)return this;let i=[],r=Math.max(0,this.items.length-n),a=e.mapping,s=e.steps.length,o=this.eventCount;this.items.forEach(p=>{p.selection&&o--},r);let l=n;this.items.forEach(p=>{let m=a.getMirror(--l);if(m==null)return;s=Math.min(s,m);let _=a.maps[m];if(p.step){let b=e.steps[m].invert(e.docs[m]),y=p.selection&&p.selection.map(a.slice(l+1,m));y&&o++,i.push(new Do(_,b,y))}else i.push(new Do(_))},r);let c=[];for(let p=n;pJMe&&(f=f.compress(this.items.length-i.length)),f}emptyItemCount(){let e=0;return this.items.forEach(n=>{n.step||e++}),e}compress(e=this.items.length){let n=this.remapping(0,e),i=n.maps.length,r=[],a=0;return this.items.forEach((s,o)=>{if(o>=e)r.push(s),s.selection&&a++;else if(s.step){let l=s.step.map(n.slice(i)),c=l&&l.getMap();if(i--,c&&n.appendMap(c,i),l){let d=s.selection&&s.selection.map(n.slice(i));d&&a++;let f=new Do(c.invert(),l,d),p,m=r.length-1;(p=r.length&&r[m].merge(f))?r[m]=p:r.push(f)}}else s.map&&i--},this.items.length,0),new so(Er.from(r.reverse()),a)}}so.empty=new so(Er.empty,0);function eEe(t,e){let n;return t.forEach((i,r)=>{if(i.selection&&e--==0)return n=r,!1}),t.slice(n)}class Do{constructor(e,n,i,r){this.map=e,this.step=n,this.selection=i,this.mirrorOffset=r}merge(e){if(this.step&&e.step&&!e.selection){let n=e.step.merge(this.step);if(n)return new Do(n.getMap().invert(),n,this.selection)}}}class du{constructor(e,n,i,r,a){this.done=e,this.undone=n,this.prevRanges=i,this.prevTime=r,this.prevComposition=a}}const tEe=20;function nEe(t,e,n,i){let r=n.getMeta(af),a;if(r)return r.historyState;n.getMeta(aEe)&&(t=new du(t.done,t.undone,null,0,-1));let s=n.getMeta("appendedTransaction");if(n.steps.length==0)return t;if(s&&s.getMeta(af))return s.getMeta(af).redo?new du(t.done.addTransform(n,void 0,i,Qb(e)),t.undone,o5(n.mapping.maps),t.prevTime,t.prevComposition):new du(t.done,t.undone.addTransform(n,void 0,i,Qb(e)),null,t.prevTime,t.prevComposition);if(n.getMeta("addToHistory")!==!1&&!(s&&s.getMeta("addToHistory")===!1)){let o=n.getMeta("composition"),l=t.prevTime==0||!s&&t.prevComposition!=o&&(t.prevTime<(n.time||0)-i.newGroupDelay||!iEe(n,t.prevRanges)),c=s?$T(t.prevRanges,n.mapping):o5(n.mapping.maps);return new du(t.done.addTransform(n,l?e.selection.getBookmark():void 0,i,Qb(e)),so.empty,c,n.time,o??t.prevComposition)}else return(a=n.getMeta("rebased"))?new du(t.done.rebased(n,a),t.undone.rebased(n,a),$T(t.prevRanges,n.mapping),t.prevTime,t.prevComposition):new du(t.done.addMaps(n.mapping.maps),t.undone.addMaps(n.mapping.maps),$T(t.prevRanges,n.mapping),t.prevTime,t.prevComposition)}function iEe(t,e){if(!e)return!1;if(!t.docChanged)return!0;let n=!1;return t.mapping.maps[0].forEach((i,r)=>{for(let a=0;a=e[a]&&(n=!0)}),n}function o5(t){let e=[];for(let n=t.length-1;n>=0&&e.length==0;n--)t[n].forEach((i,r,a,s)=>e.push(a,s));return e}function $T(t,e){if(!t)return null;let n=[];for(let i=0;i{let r=af.getState(n);if(!r||(t?r.undone:r.done).eventCount==0)return!1;if(i){let a=rEe(r,n,t);a&&i(e?a.scrollIntoView():a)}return!0}}const F7=U7(!1,!0),z7=U7(!0,!0);Gn.create({name:"characterCount",addOptions(){return{limit:null,mode:"textSize",textCounter:t=>t.length,wordCounter:t=>t.split(" ").filter(e=>e!=="").length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=t=>{const e=t?.node||this.editor.state.doc;if((t?.mode||this.options.mode)==="textSize"){const i=e.textBetween(0,e.content.size,void 0," ");return this.options.textCounter(i)}return e.nodeSize},this.storage.words=t=>{const e=t?.node||this.editor.state.doc,n=e.textBetween(0,e.content.size," "," ");return this.options.wordCounter(n)}},addProseMirrorPlugins(){let t=!1;return[new mi({key:new sr("characterCount"),appendTransaction:(e,n,i)=>{if(t)return;const r=this.options.limit;if(r==null||r===0){t=!0;return}const a=this.storage.characters({node:i.doc});if(a>r){const s=a-r,o=0,l=s;console.warn(`[CharacterCount] Initial content exceeded limit of ${r} characters. Content was automatically trimmed.`);const c=i.tr.deleteRange(o,l);return t=!0,c}t=!0},filterTransaction:(e,n)=>{const i=this.options.limit;if(!e.docChanged||i===0||i===null||i===void 0)return!0;const r=this.storage.characters({node:n.doc}),a=this.storage.characters({node:e.doc});if(a<=i||r>i&&a>i&&a<=r)return!0;if(r>i&&a>i&&a>r||!e.getMeta("paste"))return!1;const o=e.selection.$head.pos,l=a-i,c=o-l,d=o;return e.deleteRange(c,d),!(this.storage.characters({node:e.doc})>i)}})]}});var oEe=Gn.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[VMe(this.options)]}});Gn.create({name:"focus",addOptions(){return{className:"has-focus",mode:"all"}},addProseMirrorPlugins(){return[new mi({key:new sr("focus"),props:{decorations:({doc:t,selection:e})=>{const{isEditable:n,isFocused:i}=this.editor,{anchor:r}=e,a=[];if(!n||!i)return fi.create(t,[]);let s=0;this.options.mode==="deepest"&&t.descendants((l,c)=>{if(l.isText)return;if(!(r>=c&&r<=c+l.nodeSize-1))return!1;s+=1});let o=0;return t.descendants((l,c)=>{if(l.isText||!(r>=c&&r<=c+l.nodeSize-1))return!1;if(o+=1,this.options.mode==="deepest"&&s-o>0||this.options.mode==="shallowest"&&o>1)return this.options.mode==="deepest";a.push(da.node(c,c+l.nodeSize,{class:this.options.className}))}),fi.create(t,a)}}})]}});var lEe=Gn.create({name:"gapCursor",addProseMirrorPlugins(){return[qMe()]},extendNodeSchema(t){var e;const n={name:t.name,options:t.options,storage:t.storage};return{allowGapCursor:(e=Dn(It(t,"allowGapCursor",n)))!=null?e:null}}});Gn.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new mi({key:new sr("placeholder"),props:{decorations:({doc:t,selection:e})=>{const n=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:i}=e,r=[];if(!n)return null;const a=this.editor.isEmpty;return t.descendants((s,o)=>{const l=i>=o&&i<=o+s.nodeSize,c=!s.isLeaf&&jS(s);if((l||!this.options.showOnlyCurrent)&&c){const d=[this.options.emptyNodeClass];a&&d.push(this.options.emptyEditorClass);const f=da.node(o,o+s.nodeSize,{class:d.join(" "),"data-placeholder":typeof this.options.placeholder=="function"?this.options.placeholder({editor:this.editor,node:s,pos:o,hasAnchor:l}):this.options.placeholder});r.push(f)}return this.options.includeChildren}),fi.create(t,r)}}})]}});Gn.create({name:"selection",addOptions(){return{className:"selection"}},addProseMirrorPlugins(){const{editor:t,options:e}=this;return[new mi({key:new sr("selection"),props:{decorations(n){return n.selection.empty||t.isFocused||!t.isEditable||KW(n.selection)||t.view.dragging?null:fi.create(n.doc,[da.inline(n.selection.from,n.selection.to,{class:e.className})])}}})]}});function c5({types:t,node:e}){return e&&Array.isArray(t)&&t.includes(e.type)||e?.type===t}var cEe=Gn.create({name:"trailingNode",addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){var t;const e=new sr(this.name),n=this.options.node||((t=this.editor.schema.topNodeType.contentMatch.defaultType)==null?void 0:t.name)||"paragraph",i=Object.entries(this.editor.schema.nodes).map(([,r])=>r).filter(r=>(this.options.notAfter||[]).concat(n).includes(r.name));return[new mi({key:e,appendTransaction:(r,a,s)=>{const{doc:o,tr:l,schema:c}=s,d=e.getState(s),f=o.content.size,p=c.nodes[n];if(d)return l.insert(f,p.create())},state:{init:(r,a)=>{const s=a.tr.doc.lastChild;return!c5({node:s,types:i})},apply:(r,a)=>{if(!r.docChanged||r.getMeta("__uniqueIDTransaction"))return a;const s=r.doc.lastChild;return!c5({node:s,types:i})}}})]}}),uEe=Gn.create({name:"undoRedo",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:t,dispatch:e})=>F7(t,e),redo:()=>({state:t,dispatch:e})=>z7(t,e)}},addProseMirrorPlugins(){return[sEe(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),dEe=Gn.create({name:"starterKit",addExtensions(){var t,e,n,i;const r=[];return this.options.bold!==!1&&r.push(Fwe.configure(this.options.bold)),this.options.blockquote!==!1&&r.push(Owe.configure(this.options.blockquote)),this.options.bulletList!==!1&&r.push(M7.configure(this.options.bulletList)),this.options.code!==!1&&r.push(Bwe.configure(this.options.code)),this.options.codeBlock!==!1&&r.push(Gwe.configure(this.options.codeBlock)),this.options.document!==!1&&r.push($we.configure(this.options.document)),this.options.dropcursor!==!1&&r.push(oEe.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&r.push(lEe.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&r.push(Wwe.configure(this.options.hardBreak)),this.options.heading!==!1&&r.push(qwe.configure(this.options.heading)),this.options.undoRedo!==!1&&r.push(uEe.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&r.push(Xwe.configure(this.options.horizontalRule)),this.options.italic!==!1&&r.push(Jwe.configure(this.options.italic)),this.options.listItem!==!1&&r.push(E7.configure(this.options.listItem)),this.options.listKeymap!==!1&&r.push(P7.configure((t=this.options)==null?void 0:t.listKeymap)),this.options.link!==!1&&r.push(w7.configure((e=this.options)==null?void 0:e.link)),this.options.orderedList!==!1&&r.push(O7.configure(this.options.orderedList)),this.options.paragraph!==!1&&r.push(UMe.configure(this.options.paragraph)),this.options.strike!==!1&&r.push(jMe.configure(this.options.strike)),this.options.text!==!1&&r.push(BMe.configure(this.options.text)),this.options.underline!==!1&&r.push(k7.configure((n=this.options)==null?void 0:n.underline)),this.options.trailingNode!==!1&&r.push(cEe.configure((i=this.options)==null?void 0:i.trailingNode)),r}}),fEe=dEe,hEe=Gn.create({name:"textAlign",addOptions(){return{types:[],alignments:["left","center","right","justify"],defaultAlignment:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:t=>{const e=t.style.textAlign;return this.options.alignments.includes(e)?e:this.options.defaultAlignment},renderHTML:t=>t.textAlign?{style:`text-align: ${t.textAlign}`}:{}}}}]},addCommands(){return{setTextAlign:t=>({commands:e})=>this.options.alignments.includes(t)?this.options.types.map(n=>e.updateAttributes(n,{textAlign:t})).some(n=>n):!1,unsetTextAlign:()=>({commands:t})=>this.options.types.map(e=>t.resetAttributes(e,"textAlign")).some(e=>e),toggleTextAlign:t=>({editor:e,commands:n})=>this.options.alignments.includes(t)?e.isActive({textAlign:t})?n.unsetTextAlign():n.setTextAlign(t):!1}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign("left"),"Mod-Shift-e":()=>this.editor.commands.setTextAlign("center"),"Mod-Shift-r":()=>this.editor.commands.setTextAlign("right"),"Mod-Shift-j":()=>this.editor.commands.setTextAlign("justify")}}}),pEe=hEe,mEe=20,j7=(t,e=0)=>{const n=[];return!t.children.length||e>mEe||Array.from(t.children).forEach(i=>{i.tagName==="SPAN"?n.push(i):i.children.length&&n.push(...j7(i,e+1))}),n},gEe=t=>{if(!t.children.length)return;const e=j7(t);e&&e.forEach(n=>{var i,r;const a=n.getAttribute("style"),s=(r=(i=n.parentElement)==null?void 0:i.closest("span"))==null?void 0:r.getAttribute("style");n.setAttribute("style",`${s};${a}`)})},B7=Ju.create({name:"textStyle",priority:101,addOptions(){return{HTMLAttributes:{},mergeNestedSpanStyles:!0}},parseHTML(){return[{tag:"span",consuming:!1,getAttrs:t=>t.hasAttribute("style")?(this.options.mergeNestedSpanStyles&&gEe(t),{}):!1}]},renderHTML({HTMLAttributes:t}){return["span",wi(this.options.HTMLAttributes,t),0]},addCommands(){return{toggleTextStyle:t=>({commands:e})=>e.toggleMark(this.name,t),removeEmptyTextStyle:()=>({tr:t})=>{const{selection:e}=t;return t.doc.nodesBetween(e.from,e.to,(n,i)=>{if(n.isTextblock)return!0;n.marks.filter(r=>r.type===this.type).some(r=>Object.values(r.attrs).some(a=>!!a))||t.removeMark(i,i+n.nodeSize,this.type)}),!0}}}}),xEe=Gn.create({name:"backgroundColor",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{backgroundColor:{default:null,parseHTML:t=>{var e;const n=t.getAttribute("style");if(n){const i=n.split(";").map(r=>r.trim()).filter(Boolean);for(let r=i.length-1;r>=0;r-=1){const a=i[r].split(":");if(a.length>=2){const s=a[0].trim().toLowerCase(),o=a.slice(1).join(":").trim();if(s==="background-color")return o.replace(/['"]+/g,"")}}}return(e=t.style.backgroundColor)==null?void 0:e.replace(/['"]+/g,"")},renderHTML:t=>t.backgroundColor?{style:`background-color: ${t.backgroundColor}`}:{}}}}]},addCommands(){return{setBackgroundColor:t=>({chain:e})=>e().setMark("textStyle",{backgroundColor:t}).run(),unsetBackgroundColor:()=>({chain:t})=>t().setMark("textStyle",{backgroundColor:null}).removeEmptyTextStyle().run()}}}),H7=Gn.create({name:"color",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{color:{default:null,parseHTML:t=>{var e;const n=t.getAttribute("style");if(n){const i=n.split(";").map(r=>r.trim()).filter(Boolean);for(let r=i.length-1;r>=0;r-=1){const a=i[r].split(":");if(a.length>=2){const s=a[0].trim().toLowerCase(),o=a.slice(1).join(":").trim();if(s==="color")return o.replace(/['"]+/g,"")}}}return(e=t.style.color)==null?void 0:e.replace(/['"]+/g,"")},renderHTML:t=>t.color?{style:`color: ${t.color}`}:{}}}}]},addCommands(){return{setColor:t=>({chain:e})=>e().setMark("textStyle",{color:t}).run(),unsetColor:()=>({chain:t})=>t().setMark("textStyle",{color:null}).removeEmptyTextStyle().run()}}}),vEe=Gn.create({name:"fontFamily",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontFamily:{default:null,parseHTML:t=>t.style.fontFamily,renderHTML:t=>t.fontFamily?{style:`font-family: ${t.fontFamily}`}:{}}}}]},addCommands(){return{setFontFamily:t=>({chain:e})=>e().setMark("textStyle",{fontFamily:t}).run(),unsetFontFamily:()=>({chain:t})=>t().setMark("textStyle",{fontFamily:null}).removeEmptyTextStyle().run()}}}),yEe=Gn.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:t=>t.style.fontSize,renderHTML:t=>t.fontSize?{style:`font-size: ${t.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:t=>({chain:e})=>e().setMark("textStyle",{fontSize:t}).run(),unsetFontSize:()=>({chain:t})=>t().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),bEe=Gn.create({name:"lineHeight",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{lineHeight:{default:null,parseHTML:t=>t.style.lineHeight,renderHTML:t=>t.lineHeight?{style:`line-height: ${t.lineHeight}`}:{}}}}]},addCommands(){return{setLineHeight:t=>({chain:e})=>e().setMark("textStyle",{lineHeight:t}).run(),unsetLineHeight:()=>({chain:t})=>t().setMark("textStyle",{lineHeight:null}).removeEmptyTextStyle().run()}}});Gn.create({name:"textStyleKit",addExtensions(){const t=[];return this.options.backgroundColor!==!1&&t.push(xEe.configure(this.options.backgroundColor)),this.options.color!==!1&&t.push(H7.configure(this.options.color)),this.options.fontFamily!==!1&&t.push(vEe.configure(this.options.fontFamily)),this.options.fontSize!==!1&&t.push(yEe.configure(this.options.fontSize)),this.options.lineHeight!==!1&&t.push(bEe.configure(this.options.lineHeight)),this.options.textStyle!==!1&&t.push(B7.configure(this.options.textStyle)),t}});var _Ee=H7,SEe=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,wEe=Fa.create({name:"image",addOptions(){return{inline:!1,allowBase64:!1,HTMLAttributes:{},resize:!1}},inline(){return this.options.inline},group(){return this.options.inline?"inline":"block"},draggable:!0,addAttributes(){return{src:{default:null},alt:{default:null},title:{default:null},width:{default:null},height:{default:null}}},parseHTML(){return[{tag:this.options.allowBase64?"img[src]":'img[src]:not([src^="data:"])'}]},renderHTML({HTMLAttributes:t}){return["img",wi(this.options.HTMLAttributes,t)]},parseMarkdown:(t,e)=>e.createNode("image",{src:t.href,title:t.title,alt:t.text}),renderMarkdown:t=>{var e,n,i,r,a,s;const o=(n=(e=t.attrs)==null?void 0:e.src)!=null?n:"",l=(r=(i=t.attrs)==null?void 0:i.alt)!=null?r:"",c=(s=(a=t.attrs)==null?void 0:a.title)!=null?s:"";return c?`![${l}](${o} "${c}")`:`![${l}](${o})`},addNodeView(){if(!this.options.resize||!this.options.resize.enabled||typeof document>"u"||!this.editor.isEditable)return null;const{directions:t,minWidth:e,minHeight:n,alwaysPreserveAspectRatio:i}=this.options.resize;return({node:r,getPos:a,HTMLAttributes:s})=>{const o=document.createElement("img");Object.entries(s).forEach(([d,f])=>{if(f!=null)switch(d){case"width":case"height":break;default:o.setAttribute(d,f);break}}),o.src=s.src;const l=new nwe({element:o,node:r,getPos:a,onResize:(d,f)=>{o.style.width=`${d}px`,o.style.height=`${f}px`},onCommit:(d,f)=>{const p=a();p!==void 0&&this.editor.chain().setNodeSelection(p).updateAttributes(this.name,{width:d,height:f}).run()},onUpdate:(d,f,p)=>d.type===r.type,options:{directions:t,min:{width:e,height:n},preserveAspectRatio:i===!0}}),c=l.dom;return c.style.visibility="hidden",c.style.pointerEvents="none",o.onload=()=>{c.style.visibility="",c.style.pointerEvents=""},l}},addCommands(){return{setImage:t=>({commands:e})=>e.insertContent({type:this.name,attrs:t})}},addInputRules(){return[u7({find:SEe,type:this.type,getAttributes:t=>{const[,,e,n,i]=t;return{src:n,alt:e,title:i}}})]}}),MEe=wEe;function u5({content:t,onChange:e,placeholder:n}){const i=Cwe({extensions:[fEe.configure({heading:!1,codeBlock:!1,code:!1}),HMe,MMe.configure({openOnClick:!1,HTMLAttributes:{target:"_blank",rel:"noopener noreferrer"}}),pEe.configure({types:["paragraph"]}),B7,_Ee,MEe.configure({HTMLAttributes:{style:"max-width: 100%; height: auto;"}})],content:t,onUpdate:({editor:s})=>{e(s.getHTML())},editorProps:{attributes:{class:"prose prose-invert prose-sm max-w-none focus:outline-none min-h-[120px] px-3 py-2",placeholder:n||""}}});if(!i)return null;const r=({onClick:s,isActive:o=!1,children:l,title:c})=>x.jsx("button",{type:"button",onClick:s,title:c,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary transition-colors ${o?"bg-bambu-dark-tertiary text-bambu-green":"text-bambu-gray"}`,children:l}),a=()=>{const s=window.prompt("Enter URL:");s&&i.chain().focus().setLink({href:s}).run()};return x.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden bg-bambu-dark",children:[x.jsxs("div",{className:"flex items-center gap-0.5 p-1.5 border-b border-bambu-dark-tertiary bg-bambu-dark-secondary",children:[x.jsx(r,{onClick:()=>i.chain().focus().toggleBold().run(),isActive:i.isActive("bold"),title:"Bold",children:x.jsx(tie,{className:"w-4 h-4"})}),x.jsx(r,{onClick:()=>i.chain().focus().toggleItalic().run(),isActive:i.isActive("italic"),title:"Italic",children:x.jsx(ire,{className:"w-4 h-4"})}),x.jsx(r,{onClick:()=>i.chain().focus().toggleUnderline().run(),isActive:i.isActive("underline"),title:"Underline",children:x.jsx(yae,{className:"w-4 h-4"})}),x.jsx("div",{className:"w-px h-5 bg-bambu-dark-tertiary mx-1"}),x.jsx(r,{onClick:()=>i.chain().focus().toggleBulletList().run(),isActive:i.isActive("bulletList"),title:"Bullet List",children:x.jsx(RG,{className:"w-4 h-4"})}),x.jsx(r,{onClick:()=>i.chain().focus().toggleOrderedList().run(),isActive:i.isActive("orderedList"),title:"Numbered List",children:x.jsx(hre,{className:"w-4 h-4"})}),x.jsx("div",{className:"w-px h-5 bg-bambu-dark-tertiary mx-1"}),x.jsx(r,{onClick:()=>i.chain().focus().setTextAlign("left").run(),isActive:i.isActive({textAlign:"left"}),title:"Align Left",children:x.jsx(pae,{className:"w-4 h-4"})}),x.jsx(r,{onClick:()=>i.chain().focus().setTextAlign("center").run(),isActive:i.isActive({textAlign:"center"}),title:"Align Center",children:x.jsx(uae,{className:"w-4 h-4"})}),x.jsx(r,{onClick:()=>i.chain().focus().setTextAlign("right").run(),isActive:i.isActive({textAlign:"right"}),title:"Align Right",children:x.jsx(fae,{className:"w-4 h-4"})}),x.jsx("div",{className:"w-px h-5 bg-bambu-dark-tertiary mx-1"}),x.jsx(r,{onClick:a,isActive:i.isActive("link"),title:"Add Link",children:x.jsx(dre,{className:"w-4 h-4"})}),i.isActive("link")&&x.jsx(r,{onClick:()=>i.chain().focus().unsetLink().run(),title:"Remove Link",children:x.jsx(_ae,{className:"w-4 h-4"})})]}),x.jsx(_we,{editor:i})]})}function EEe({archiveId:t,archiveName:e,onClose:n}){const i=Mi(),[r,a]=T.useState(!1),[s,o]=T.useState(null),[l,c]=T.useState({}),{data:d,isLoading:f,error:p}=un({queryKey:["archive-project-page",t],queryFn:()=>lt.getArchiveProjectPage(t)}),m=Xt({mutationFn:E=>lt.updateArchiveProjectPage(t,E),onSuccess:()=>{i.invalidateQueries({queryKey:["archive-project-page",t]}),a(!1),c({})}});T.useEffect(()=>{const E=P=>{P.key==="Escape"&&(s!==null?o(null):r?g():n())};return document.addEventListener("keydown",E),()=>document.removeEventListener("keydown",E)},[s,r,n]);const _=[...d?.model_pictures||[],...d?.profile_pictures||[]],b=()=>{c({title:d?.title||"",description:d?.description||"",designer:d?.designer||"",license:d?.license||"",profile_title:d?.profile_title||"",profile_description:d?.profile_description||""}),a(!0)},y=()=>{m.mutate(l)},g=()=>{a(!1),c({})},M=E=>{const P=["p","br","b","strong","i","em","u","a","ul","ol","li","figure","img"],N=new DOMParser().parseFromString(E,"text/html"),F=R=>{if(R.nodeType===Node.TEXT_NODE)return R.textContent||"";if(R.nodeType===Node.ELEMENT_NODE){const O=R,B=O.tagName.toLowerCase();if(!P.includes(B))return Array.from(O.childNodes).map(F).join("");let I="";if(B==="a"&&O.getAttribute("href")){const L=O.getAttribute("href");L?.toLowerCase().startsWith("http")&&(I=` href="${L}" target="_blank" rel="noopener noreferrer"`)}if(B==="img"){const L=O.getAttribute("src");if(!L?.toLowerCase().startsWith("http"))return"";I=` src="${L}" style="max-width: 100%; height: auto;"`}const G=Array.from(O.childNodes).map(F).join("");return["br","img"].includes(B)?`<${B}${I} />`:`<${B}${I}>${G}`}return""};return Array.from(N.body.childNodes).map(F).join("")},w=d&&(d.title||d.description||d.designer||d.profile_title||_.length>0),A=E=>{E.target===E.currentTarget&&n()};return x.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:A,children:[x.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl max-w-4xl w-full max-h-[90vh] overflow-hidden flex flex-col",children:[x.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[x.jsxs("div",{className:"flex items-center gap-3",children:[x.jsx(sp,{className:"w-5 h-5 text-bambu-green"}),x.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Project Page",e&&x.jsxs("span",{className:"text-bambu-gray ml-2",children:["- ",e]})]})]}),x.jsxs("div",{className:"flex items-center gap-2",children:[!r&&w&&x.jsxs(dt,{variant:"ghost",size:"sm",onClick:b,children:[x.jsx(Cre,{className:"w-4 h-4 mr-1"}),"Edit"]}),r&&x.jsxs(x.Fragment,{children:[x.jsx(dt,{variant:"ghost",size:"sm",onClick:g,children:"Cancel"}),x.jsxs(dt,{variant:"primary",size:"sm",onClick:y,disabled:m.isPending,children:[x.jsx(cx,{className:"w-4 h-4 mr-1"}),"Save"]})]}),x.jsx("button",{onClick:n,className:"p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:x.jsx(kn,{className:"w-5 h-5 text-bambu-gray"})})]})]}),x.jsxs("div",{className:"flex-1 overflow-y-auto p-6",children:[f&&x.jsx("div",{className:"flex items-center justify-center py-12",children:x.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-2 border-bambu-green border-t-transparent"})}),p&&x.jsx("div",{className:"text-red-400 text-center py-12",children:"Failed to load project page data"}),d&&!w&&x.jsxs("div",{className:"text-bambu-gray text-center py-12",children:[x.jsx(sp,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),x.jsx("p",{children:"No project page data found in this 3MF file."}),x.jsx("p",{className:"text-sm mt-2",children:"Project pages are typically included in files downloaded from MakerWorld."})]}),d&&w&&x.jsxs("div",{className:"space-y-6",children:[x.jsxs("div",{className:"space-y-4",children:[r?x.jsx("input",{type:"text",value:l.title||"",onChange:E=>c({...l,title:E.target.value}),placeholder:"Title",className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-lg px-4 py-2 text-white text-xl font-semibold"}):d.title&&x.jsx("h3",{className:"text-xl font-semibold text-white",children:d.title}),x.jsxs("div",{className:"flex flex-wrap gap-4 text-sm",children:[r?x.jsxs("div",{className:"flex items-center gap-2",children:[x.jsx(L4,{className:"w-4 h-4 text-bambu-gray"}),x.jsx("input",{type:"text",value:l.designer||"",onChange:E=>c({...l,designer:E.target.value}),placeholder:"Designer",className:"bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-white"})]}):d.designer&&x.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[x.jsx(L4,{className:"w-4 h-4"}),x.jsx("span",{children:d.designer}),d.designer_user_id&&x.jsx("a",{href:`https://makerworld.com/en/@${d.designer_user_id}`,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-green hover:underline",children:x.jsx(Lu,{className:"w-3 h-3"})})]}),d.creation_date&&x.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[x.jsx(Ho,{className:"w-4 h-4"}),x.jsx("span",{children:d.creation_date})]}),r?x.jsxs("div",{className:"flex items-center gap-2",children:[x.jsx(sp,{className:"w-4 h-4 text-bambu-gray"}),x.jsx("input",{type:"text",value:l.license||"",onChange:E=>c({...l,license:E.target.value}),placeholder:"License",className:"bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-white"})]}):d.license&&x.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[x.jsx(sp,{className:"w-4 h-4"}),x.jsx("span",{children:d.license})]}),d.origin&&x.jsx("span",{className:"px-2 py-0.5 bg-bambu-dark rounded text-bambu-gray",children:d.origin})]})]}),(d.description||r)&&x.jsxs("div",{className:"space-y-2",children:[x.jsx("h4",{className:"text-sm font-medium text-bambu-gray uppercase tracking-wide",children:"Description"}),r?x.jsx(u5,{content:l.description||"",onChange:E=>c({...l,description:E}),placeholder:"Enter description..."}):x.jsx("div",{className:"prose prose-invert prose-sm max-w-none text-bambu-gray-light",dangerouslySetInnerHTML:{__html:M(d.description||"")}})]}),(d.profile_title||d.profile_description||r)&&x.jsxs("div",{className:"space-y-2 p-4 bg-bambu-dark rounded-lg",children:[x.jsx("h4",{className:"text-sm font-medium text-bambu-gray uppercase tracking-wide",children:"Print Profile"}),r?x.jsxs("div",{className:"space-y-2",children:[x.jsx("input",{type:"text",value:l.profile_title||"",onChange:E=>c({...l,profile_title:E.target.value}),placeholder:"Profile Title",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-white"}),x.jsx(u5,{content:l.profile_description||"",onChange:E=>c({...l,profile_description:E}),placeholder:"Profile description..."})]}):x.jsxs(x.Fragment,{children:[d.profile_title&&x.jsx("p",{className:"text-white font-medium",children:d.profile_title}),d.profile_description&&x.jsx("div",{className:"prose prose-invert prose-sm max-w-none text-bambu-gray-light",dangerouslySetInnerHTML:{__html:M(d.profile_description)}}),d.profile_user_name&&x.jsxs("p",{className:"text-sm text-bambu-gray",children:["by ",d.profile_user_name]})]})]}),_.length>0&&x.jsxs("div",{className:"space-y-2",children:[x.jsxs("h4",{className:"text-sm font-medium text-bambu-gray uppercase tracking-wide flex items-center gap-2",children:[x.jsx(mS,{className:"w-4 h-4"}),"Images (",_.length,")"]}),x.jsx("div",{className:"grid grid-cols-3 sm:grid-cols-4 md:grid-cols-5 gap-2",children:_.map((E,P)=>x.jsx("button",{onClick:()=>o(P),className:"aspect-square rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors",children:x.jsx("img",{src:E.url,alt:E.name,className:"w-full h-full object-cover"})},E.path))})]}),d.design_model_id&&x.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:x.jsxs("a",{href:`https://makerworld.com/en/models/${d.design_model_id}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 text-bambu-green hover:underline",children:[x.jsx(Lu,{className:"w-4 h-4"}),"View on MakerWorld"]})})]})]})]}),s!==null&&_[s]&&x.jsxs("div",{className:"fixed inset-0 bg-black/90 flex items-center justify-center z-60",onClick:()=>o(null),children:[x.jsx("button",{onClick:E=>{E.stopPropagation(),o(Math.max(0,s-1))},disabled:s===0,className:"absolute left-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary disabled:opacity-30",children:x.jsx(hf,{className:"w-6 h-6 text-white"})}),x.jsx("img",{src:_[s].url,alt:_[s].name,className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:E=>E.stopPropagation()}),x.jsx("button",{onClick:E=>{E.stopPropagation(),o(Math.min(_.length-1,s+1))},disabled:s===_.length-1,className:"absolute right-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary disabled:opacity-30",children:x.jsx(Of,{className:"w-6 h-6 text-white"})}),x.jsx("button",{onClick:()=>o(null),className:"absolute top-4 right-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary",children:x.jsx(kn,{className:"w-6 h-6 text-white"})}),x.jsxs("div",{className:"absolute bottom-4 text-white text-sm",children:[s+1," / ",_.length]})]})]})}const AEe=[.25,.5,.75,1,1.5,2,3,4];function TEe({src:t,title:e,downloadFilename:n,onClose:i}){const r=T.useRef(null),[a,s]=T.useState(!0),[o,l]=T.useState(.5),[c,d]=T.useState(0),[f,p]=T.useState(0);T.useEffect(()=>{const w=r.current;w&&(w.playbackRate=o)},[o]),T.useEffect(()=>{const w=r.current;if(!w)return;const A=()=>d(w.currentTime),E=()=>p(w.duration),P=()=>s(!0),N=()=>s(!1);return w.addEventListener("timeupdate",A),w.addEventListener("durationchange",E),w.addEventListener("play",P),w.addEventListener("pause",N),()=>{w.removeEventListener("timeupdate",A),w.removeEventListener("durationchange",E),w.removeEventListener("play",P),w.removeEventListener("pause",N)}},[]);const m=()=>{const w=r.current;w&&(a?w.pause():w.play())},_=w=>{const A=r.current;A&&(A.currentTime=parseFloat(w.target.value))},b=()=>{const w=r.current;w&&(w.currentTime=Math.max(0,w.currentTime-5))},y=()=>{const w=r.current;w&&(w.currentTime=Math.min(f,w.currentTime+5))},g=w=>{const A=Math.floor(w/60),E=Math.floor(w%60);return`${A}:${E.toString().padStart(2,"0")}`},M=()=>{const w=document.createElement("a");w.href=t,w.download=n,w.click()};return x.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",children:x.jsxs("div",{className:"relative bg-bambu-dark-secondary rounded-xl max-w-4xl w-full mx-4 overflow-hidden",children:[x.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[x.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[x.jsx(hp,{className:"w-5 h-5 text-bambu-green"}),e]}),x.jsxs("div",{className:"flex items-center gap-2",children:[x.jsxs(dt,{variant:"secondary",size:"sm",onClick:M,children:[x.jsx(pf,{className:"w-4 h-4"}),"Download"]}),x.jsx("button",{onClick:i,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",children:x.jsx(kn,{className:"w-5 h-5 text-bambu-gray"})})]})]}),x.jsxs("div",{className:"p-4",children:[x.jsx("video",{ref:r,src:t,autoPlay:!0,className:"w-full rounded-lg",onClick:m}),x.jsxs("div",{className:"mt-4 space-y-3",children:[x.jsxs("div",{className:"flex items-center gap-3",children:[x.jsx("span",{className:"text-xs text-bambu-gray w-12 text-right",children:g(c)}),x.jsx("input",{type:"range",min:0,max:f||100,value:c,onChange:_,className:`flex-1 h-1 bg-bambu-dark-tertiary rounded-lg appearance-none cursor-pointer +`):"",markdownTokenizer:{name:"taskList",level:"block",start(t){var e;const n=(e=t.match(/^\s*[-+*]\s+\[([ xX])\]\s+/))==null?void 0:e.index;return n!==void 0?n:-1},tokenize(t,e,n){const i=a=>{const s=pR(a,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:o=>({indentLevel:o[1].length,mainContent:o[4],checked:o[3].toLowerCase()==="x"}),createToken:(o,l)=>({type:"taskItem",raw:"",mainContent:o.mainContent,indentLevel:o.indentLevel,checked:o.checked,text:o.mainContent,tokens:n.inlineTokens(o.mainContent),nestedTokens:l}),customNestedParser:i},n);return s?[{type:"taskList",raw:s.raw,items:s.items}]:n.blockTokens(a)},r=pR(t,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:a=>({indentLevel:a[1].length,mainContent:a[4],checked:a[3].toLowerCase()==="x"}),createToken:(a,s)=>({type:"taskItem",raw:"",mainContent:a.mainContent,indentLevel:a.indentLevel,checked:a.checked,text:a.mainContent,tokens:n.inlineTokens(a.mainContent),nestedTokens:s}),customNestedParser:i},n);if(r)return{type:"taskList",raw:r.raw,items:r.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:t})=>t.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});Gn.create({name:"listKit",addExtensions(){const t=[];return this.options.bulletList!==!1&&t.push(M7.configure(this.options.bulletList)),this.options.listItem!==!1&&t.push(E7.configure(this.options.listItem)),this.options.listKeymap!==!1&&t.push(P7.configure(this.options.listKeymap)),this.options.orderedList!==!1&&t.push(O7.configure(this.options.orderedList)),this.options.taskItem!==!1&&t.push(LMe.configure(this.options.taskItem)),this.options.taskList!==!1&&t.push(IMe.configure(this.options.taskList)),t}});var UMe=Fa.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:t}){return["p",wi(this.options.HTMLAttributes,t),0]},parseMarkdown:(t,e)=>{const n=t.tokens||[];return n.length===1&&n[0].type==="image"?e.parseChildren([n[0]]):e.createNode("paragraph",void 0,e.parseInline(n))},renderMarkdown:(t,e)=>!t||!Array.isArray(t.content)?"":e.renderChildren(t.content),addCommands(){return{setParagraph:()=>({commands:t})=>t.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),FMe=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,zMe=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,jMe=Ju.create({name:"strike",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",consuming:!1,getAttrs:t=>t.includes("line-through")?{}:!1}]},renderHTML({HTMLAttributes:t}){return["s",wi(this.options.HTMLAttributes,t),0]},markdownTokenName:"del",parseMarkdown:(t,e)=>e.applyMark("strike",e.parseInline(t.tokens||[])),renderMarkdown:(t,e)=>`~~${e.renderChildren(t)}~~`,addCommands(){return{setStrike:()=>({commands:t})=>t.setMark(this.name),toggleStrike:()=>({commands:t})=>t.toggleMark(this.name),unsetStrike:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[Hp({find:FMe,type:this.type})]},addPasteRules(){return[Ef({find:zMe,type:this.type})]}}),BMe=Fa.create({name:"text",group:"inline",parseMarkdown:t=>({type:"text",text:t.text||""}),renderMarkdown:t=>t.text||""}),k7=Ju.create({name:"underline",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:t=>t.includes("underline")?{}:!1}]},renderHTML({HTMLAttributes:t}){return["u",wi(this.options.HTMLAttributes,t),0]},parseMarkdown(t,e){return e.applyMark(this.name||"underline",e.parseInline(t.tokens||[]))},renderMarkdown(t,e){return`++${e.renderChildren(t)}++`},markdownTokenizer:{name:"underline",level:"inline",start(t){return t.indexOf("++")},tokenize(t,e,n){const r=/^(\+\+)([\s\S]+?)(\+\+)/.exec(t);if(!r)return;const a=r[2].trim();return{type:"underline",raw:r[0],text:a,tokens:n.inlineTokens(a)}}},addCommands(){return{setUnderline:()=>({commands:t})=>t.setMark(this.name),toggleUnderline:()=>({commands:t})=>t.toggleMark(this.name),unsetUnderline:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),HMe=k7;function VMe(t={}){return new mi({view(e){return new GMe(e,t)}})}class GMe{constructor(e,n){var i;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=(i=n.width)!==null&&i!==void 0?i:1,this.color=n.color===!1?void 0:n.color||"black",this.class=n.class,this.handlers=["dragover","dragend","drop","dragleave"].map(r=>{let a=s=>{this[r](s)};return e.dom.addEventListener(r,a),{name:r,handler:a}})}destroy(){this.handlers.forEach(({name:e,handler:n})=>this.editorView.dom.removeEventListener(e,n))}update(e,n){this.cursorPos!=null&&n.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),n=!e.parent.inlineContent,i,r=this.editorView.dom,a=r.getBoundingClientRect(),s=a.width/r.offsetWidth,o=a.height/r.offsetHeight;if(n){let f=e.nodeBefore,p=e.nodeAfter;if(f||p){let m=this.editorView.nodeDOM(this.cursorPos-(f?f.nodeSize:0));if(m){let _=m.getBoundingClientRect(),b=f?_.bottom:_.top;f&&p&&(b=(b+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let y=this.width/2*o;i={left:_.left,right:_.right,top:b-y,bottom:b+y}}}}if(!i){let f=this.editorView.coordsAtPos(this.cursorPos),p=this.width/2*s;i={left:f.left-p,right:f.left+p,top:f.top,bottom:f.bottom}}let l=this.editorView.dom.offsetParent;this.element||(this.element=l.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",n),this.element.classList.toggle("prosemirror-dropcursor-inline",!n);let c,d;if(!l||l==document.body&&getComputedStyle(l).position=="static")c=-pageXOffset,d=-pageYOffset;else{let f=l.getBoundingClientRect(),p=f.width/l.offsetWidth,m=f.height/l.offsetHeight;c=f.left-l.scrollLeft*p,d=f.top-l.scrollTop*m}this.element.style.left=(i.left-c)/s+"px",this.element.style.top=(i.top-d)/o+"px",this.element.style.width=(i.right-i.left)/s+"px",this.element.style.height=(i.bottom-i.top)/o+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let n=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),i=n&&n.inside>=0&&this.editorView.state.doc.nodeAt(n.inside),r=i&&i.type.spec.disableDropCursor,a=typeof r=="function"?r(this.editorView,n,e):r;if(n&&!a){let s=n.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let o=O9(this.editorView.state.doc,s,this.editorView.dragging.slice);o!=null&&(s=o)}this.setCursor(s),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}class Si extends tn{constructor(e){super(e,e)}map(e,n){let i=e.resolve(n.map(this.head));return Si.valid(i)?new Si(i):tn.near(i)}content(){return wt.empty}eq(e){return e instanceof Si&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new Si(e.resolve(n.pos))}getBookmark(){return new uD(this.anchor)}static valid(e){let n=e.parent;if(n.isTextblock||!$Me(e)||!WMe(e))return!1;let i=n.type.spec.allowGapCursor;if(i!=null)return i;let r=n.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(e,n,i=!1){e:for(;;){if(!i&&Si.valid(e))return e;let r=e.pos,a=null;for(let s=e.depth;;s--){let o=e.node(s);if(n>0?e.indexAfter(s)0){a=o.child(n>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;r+=n;let l=e.doc.resolve(r);if(Si.valid(l))return l}for(;;){let s=n>0?a.firstChild:a.lastChild;if(!s){if(a.isAtom&&!a.isText&&!Ut.isSelectable(a)){e=e.doc.resolve(r+a.nodeSize*n),i=!1;continue e}break}a=s,r+=n;let o=e.doc.resolve(r);if(Si.valid(o))return o}return null}}}Si.prototype.visible=!1;Si.findFrom=Si.findGapCursorFrom;tn.jsonID("gapcursor",Si);class uD{constructor(e){this.pos=e}map(e){return new uD(e.map(this.pos))}resolve(e){let n=e.resolve(this.pos);return Si.valid(n)?new Si(n):tn.near(n)}}function L7(t){return t.isAtom||t.spec.isolating||t.spec.createGapCursor}function $Me(t){for(let e=t.depth;e>=0;e--){let n=t.index(e),i=t.node(e);if(n==0){if(i.type.spec.isolating)return!0;continue}for(let r=i.child(n-1);;r=r.lastChild){if(r.childCount==0&&!r.inlineContent||L7(r.type))return!0;if(r.inlineContent)return!1}}return!0}function WMe(t){for(let e=t.depth;e>=0;e--){let n=t.indexAfter(e),i=t.node(e);if(n==i.childCount){if(i.type.spec.isolating)return!0;continue}for(let r=i.child(n);;r=r.firstChild){if(r.childCount==0&&!r.inlineContent||L7(r.type))return!0;if(r.inlineContent)return!1}}return!0}function qMe(){return new mi({props:{decorations:ZMe,createSelectionBetween(t,e,n){return e.pos==n.pos&&Si.valid(n)?new Si(n):null},handleClick:KMe,handleKeyDown:XMe,handleDOMEvents:{beforeinput:YMe}}})}const XMe=OW({ArrowLeft:mb("horiz",-1),ArrowRight:mb("horiz",1),ArrowUp:mb("vert",-1),ArrowDown:mb("vert",1)});function mb(t,e){const n=t=="vert"?e>0?"down":"up":e>0?"right":"left";return function(i,r,a){let s=i.selection,o=e>0?s.$to:s.$from,l=s.empty;if(s instanceof jt){if(!a.endOfTextblock(n)||o.depth==0)return!1;l=!1,o=i.doc.resolve(e>0?o.after():o.before())}let c=Si.findGapCursorFrom(o,e,l);return c?(r&&r(i.tr.setSelection(new Si(c))),!0):!1}}function KMe(t,e,n){if(!t||!t.editable)return!1;let i=t.state.doc.resolve(e);if(!Si.valid(i))return!1;let r=t.posAtCoords({left:n.clientX,top:n.clientY});return r&&r.inside>-1&&Ut.isSelectable(t.state.doc.nodeAt(r.inside))?!1:(t.dispatch(t.state.tr.setSelection(new Si(i))),!0)}function YMe(t,e){if(e.inputType!="insertCompositionText"||!(t.state.selection instanceof Si))return!1;let{$from:n}=t.state.selection,i=n.parent.contentMatchAt(n.index()).findWrapping(t.state.schema.nodes.text);if(!i)return!1;let r=ut.empty;for(let s=i.length-1;s>=0;s--)r=ut.from(i[s].createAndFill(null,r));let a=t.state.tr.replace(n.pos,n.pos,new wt(r,0,0));return a.setSelection(jt.near(a.doc.resolve(n.pos+1))),t.dispatch(a),!1}function ZMe(t){if(!(t.selection instanceof Si))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",fi.create(t.doc,[da.widget(t.selection.head,e,{key:"gapcursor"})])}var p1=200,Er=function(){};Er.prototype.append=function(e){return e.length?(e=Er.from(e),!this.length&&e||e.length=n?Er.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,n))};Er.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};Er.prototype.forEach=function(e,n,i){n===void 0&&(n=0),i===void 0&&(i=this.length),n<=i?this.forEachInner(e,n,i,0):this.forEachInvertedInner(e,n,i,0)};Er.prototype.map=function(e,n,i){n===void 0&&(n=0),i===void 0&&(i=this.length);var r=[];return this.forEach(function(a,s){return r.push(e(a,s))},n,i),r};Er.from=function(e){return e instanceof Er?e:e&&e.length?new I7(e):Er.empty};var I7=(function(t){function e(i){t.call(this),this.values=i}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var n={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(r,a){return r==0&&a==this.length?this:new e(this.values.slice(r,a))},e.prototype.getInner=function(r){return this.values[r]},e.prototype.forEachInner=function(r,a,s,o){for(var l=a;l=s;l--)if(r(this.values[l],o+l)===!1)return!1},e.prototype.leafAppend=function(r){if(this.length+r.length<=p1)return new e(this.values.concat(r.flatten()))},e.prototype.leafPrepend=function(r){if(this.length+r.length<=p1)return new e(r.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(e.prototype,n),e})(Er);Er.empty=new I7([]);var QMe=(function(t){function e(n,i){t.call(this),this.left=n,this.right=i,this.length=n.length+i.length,this.depth=Math.max(n.depth,i.depth)+1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(i){return io&&this.right.forEachInner(i,Math.max(r-o,0),Math.min(this.length,a)-o,s+o)===!1)return!1},e.prototype.forEachInvertedInner=function(i,r,a,s){var o=this.left.length;if(r>o&&this.right.forEachInvertedInner(i,r-o,Math.max(a,o)-o,s+o)===!1||a=a?this.right.slice(i-a,r-a):this.left.slice(i,a).append(this.right.slice(0,r-a))},e.prototype.leafAppend=function(i){var r=this.right.leafAppend(i);if(r)return new e(this.left,r)},e.prototype.leafPrepend=function(i){var r=this.left.leafPrepend(i);if(r)return new e(r,this.right)},e.prototype.appendInner=function(i){return this.left.depth>=Math.max(this.right.depth,i.depth)+1?new e(this.left,new e(this.right,i)):new e(this,i)},e})(Er);const JMe=500;class so{constructor(e,n){this.items=e,this.eventCount=n}popEvent(e,n){if(this.eventCount==0)return null;let i=this.items.length;for(;;i--)if(this.items.get(i-1).selection){--i;break}let r,a;n&&(r=this.remapping(i,this.items.length),a=r.maps.length);let s=e.tr,o,l,c=[],d=[];return this.items.forEach((f,p)=>{if(!f.step){r||(r=this.remapping(i,p+1),a=r.maps.length),a--,d.push(f);return}if(r){d.push(new Do(f.map));let m=f.step.map(r.slice(a)),_;m&&s.maybeStep(m).doc&&(_=s.mapping.maps[s.mapping.maps.length-1],c.push(new Do(_,void 0,void 0,c.length+d.length))),a--,_&&r.appendMap(_,a)}else s.maybeStep(f.step);if(f.selection)return o=r?f.selection.map(r.slice(a)):f.selection,l=new so(this.items.slice(0,i).append(d.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:l,transform:s,selection:o}}addTransform(e,n,i,r){let a=[],s=this.eventCount,o=this.items,l=!r&&o.length?o.get(o.length-1):null;for(let d=0;dtEe&&(o=eEe(o,c),s-=c),new so(o.append(a),s)}remapping(e,n){let i=new D0;return this.items.forEach((r,a)=>{let s=r.mirrorOffset!=null&&a-r.mirrorOffset>=e?i.maps.length-r.mirrorOffset:void 0;i.appendMap(r.map,s)},e,n),i}addMaps(e){return this.eventCount==0?this:new so(this.items.append(e.map(n=>new Do(n))),this.eventCount)}rebased(e,n){if(!this.eventCount)return this;let i=[],r=Math.max(0,this.items.length-n),a=e.mapping,s=e.steps.length,o=this.eventCount;this.items.forEach(p=>{p.selection&&o--},r);let l=n;this.items.forEach(p=>{let m=a.getMirror(--l);if(m==null)return;s=Math.min(s,m);let _=a.maps[m];if(p.step){let b=e.steps[m].invert(e.docs[m]),y=p.selection&&p.selection.map(a.slice(l+1,m));y&&o++,i.push(new Do(_,b,y))}else i.push(new Do(_))},r);let c=[];for(let p=n;pJMe&&(f=f.compress(this.items.length-i.length)),f}emptyItemCount(){let e=0;return this.items.forEach(n=>{n.step||e++}),e}compress(e=this.items.length){let n=this.remapping(0,e),i=n.maps.length,r=[],a=0;return this.items.forEach((s,o)=>{if(o>=e)r.push(s),s.selection&&a++;else if(s.step){let l=s.step.map(n.slice(i)),c=l&&l.getMap();if(i--,c&&n.appendMap(c,i),l){let d=s.selection&&s.selection.map(n.slice(i));d&&a++;let f=new Do(c.invert(),l,d),p,m=r.length-1;(p=r.length&&r[m].merge(f))?r[m]=p:r.push(f)}}else s.map&&i--},this.items.length,0),new so(Er.from(r.reverse()),a)}}so.empty=new so(Er.empty,0);function eEe(t,e){let n;return t.forEach((i,r)=>{if(i.selection&&e--==0)return n=r,!1}),t.slice(n)}class Do{constructor(e,n,i,r){this.map=e,this.step=n,this.selection=i,this.mirrorOffset=r}merge(e){if(this.step&&e.step&&!e.selection){let n=e.step.merge(this.step);if(n)return new Do(n.getMap().invert(),n,this.selection)}}}class du{constructor(e,n,i,r,a){this.done=e,this.undone=n,this.prevRanges=i,this.prevTime=r,this.prevComposition=a}}const tEe=20;function nEe(t,e,n,i){let r=n.getMeta(af),a;if(r)return r.historyState;n.getMeta(aEe)&&(t=new du(t.done,t.undone,null,0,-1));let s=n.getMeta("appendedTransaction");if(n.steps.length==0)return t;if(s&&s.getMeta(af))return s.getMeta(af).redo?new du(t.done.addTransform(n,void 0,i,Qb(e)),t.undone,o5(n.mapping.maps),t.prevTime,t.prevComposition):new du(t.done,t.undone.addTransform(n,void 0,i,Qb(e)),null,t.prevTime,t.prevComposition);if(n.getMeta("addToHistory")!==!1&&!(s&&s.getMeta("addToHistory")===!1)){let o=n.getMeta("composition"),l=t.prevTime==0||!s&&t.prevComposition!=o&&(t.prevTime<(n.time||0)-i.newGroupDelay||!iEe(n,t.prevRanges)),c=s?$T(t.prevRanges,n.mapping):o5(n.mapping.maps);return new du(t.done.addTransform(n,l?e.selection.getBookmark():void 0,i,Qb(e)),so.empty,c,n.time,o??t.prevComposition)}else return(a=n.getMeta("rebased"))?new du(t.done.rebased(n,a),t.undone.rebased(n,a),$T(t.prevRanges,n.mapping),t.prevTime,t.prevComposition):new du(t.done.addMaps(n.mapping.maps),t.undone.addMaps(n.mapping.maps),$T(t.prevRanges,n.mapping),t.prevTime,t.prevComposition)}function iEe(t,e){if(!e)return!1;if(!t.docChanged)return!0;let n=!1;return t.mapping.maps[0].forEach((i,r)=>{for(let a=0;a=e[a]&&(n=!0)}),n}function o5(t){let e=[];for(let n=t.length-1;n>=0&&e.length==0;n--)t[n].forEach((i,r,a,s)=>e.push(a,s));return e}function $T(t,e){if(!t)return null;let n=[];for(let i=0;i{let r=af.getState(n);if(!r||(t?r.undone:r.done).eventCount==0)return!1;if(i){let a=rEe(r,n,t);a&&i(e?a.scrollIntoView():a)}return!0}}const F7=U7(!1,!0),z7=U7(!0,!0);Gn.create({name:"characterCount",addOptions(){return{limit:null,mode:"textSize",textCounter:t=>t.length,wordCounter:t=>t.split(" ").filter(e=>e!=="").length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=t=>{const e=t?.node||this.editor.state.doc;if((t?.mode||this.options.mode)==="textSize"){const i=e.textBetween(0,e.content.size,void 0," ");return this.options.textCounter(i)}return e.nodeSize},this.storage.words=t=>{const e=t?.node||this.editor.state.doc,n=e.textBetween(0,e.content.size," "," ");return this.options.wordCounter(n)}},addProseMirrorPlugins(){let t=!1;return[new mi({key:new sr("characterCount"),appendTransaction:(e,n,i)=>{if(t)return;const r=this.options.limit;if(r==null||r===0){t=!0;return}const a=this.storage.characters({node:i.doc});if(a>r){const s=a-r,o=0,l=s;console.warn(`[CharacterCount] Initial content exceeded limit of ${r} characters. Content was automatically trimmed.`);const c=i.tr.deleteRange(o,l);return t=!0,c}t=!0},filterTransaction:(e,n)=>{const i=this.options.limit;if(!e.docChanged||i===0||i===null||i===void 0)return!0;const r=this.storage.characters({node:n.doc}),a=this.storage.characters({node:e.doc});if(a<=i||r>i&&a>i&&a<=r)return!0;if(r>i&&a>i&&a>r||!e.getMeta("paste"))return!1;const o=e.selection.$head.pos,l=a-i,c=o-l,d=o;return e.deleteRange(c,d),!(this.storage.characters({node:e.doc})>i)}})]}});var oEe=Gn.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[VMe(this.options)]}});Gn.create({name:"focus",addOptions(){return{className:"has-focus",mode:"all"}},addProseMirrorPlugins(){return[new mi({key:new sr("focus"),props:{decorations:({doc:t,selection:e})=>{const{isEditable:n,isFocused:i}=this.editor,{anchor:r}=e,a=[];if(!n||!i)return fi.create(t,[]);let s=0;this.options.mode==="deepest"&&t.descendants((l,c)=>{if(l.isText)return;if(!(r>=c&&r<=c+l.nodeSize-1))return!1;s+=1});let o=0;return t.descendants((l,c)=>{if(l.isText||!(r>=c&&r<=c+l.nodeSize-1))return!1;if(o+=1,this.options.mode==="deepest"&&s-o>0||this.options.mode==="shallowest"&&o>1)return this.options.mode==="deepest";a.push(da.node(c,c+l.nodeSize,{class:this.options.className}))}),fi.create(t,a)}}})]}});var lEe=Gn.create({name:"gapCursor",addProseMirrorPlugins(){return[qMe()]},extendNodeSchema(t){var e;const n={name:t.name,options:t.options,storage:t.storage};return{allowGapCursor:(e=Dn(It(t,"allowGapCursor",n)))!=null?e:null}}});Gn.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new mi({key:new sr("placeholder"),props:{decorations:({doc:t,selection:e})=>{const n=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:i}=e,r=[];if(!n)return null;const a=this.editor.isEmpty;return t.descendants((s,o)=>{const l=i>=o&&i<=o+s.nodeSize,c=!s.isLeaf&&jS(s);if((l||!this.options.showOnlyCurrent)&&c){const d=[this.options.emptyNodeClass];a&&d.push(this.options.emptyEditorClass);const f=da.node(o,o+s.nodeSize,{class:d.join(" "),"data-placeholder":typeof this.options.placeholder=="function"?this.options.placeholder({editor:this.editor,node:s,pos:o,hasAnchor:l}):this.options.placeholder});r.push(f)}return this.options.includeChildren}),fi.create(t,r)}}})]}});Gn.create({name:"selection",addOptions(){return{className:"selection"}},addProseMirrorPlugins(){const{editor:t,options:e}=this;return[new mi({key:new sr("selection"),props:{decorations(n){return n.selection.empty||t.isFocused||!t.isEditable||KW(n.selection)||t.view.dragging?null:fi.create(n.doc,[da.inline(n.selection.from,n.selection.to,{class:e.className})])}}})]}});function c5({types:t,node:e}){return e&&Array.isArray(t)&&t.includes(e.type)||e?.type===t}var cEe=Gn.create({name:"trailingNode",addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){var t;const e=new sr(this.name),n=this.options.node||((t=this.editor.schema.topNodeType.contentMatch.defaultType)==null?void 0:t.name)||"paragraph",i=Object.entries(this.editor.schema.nodes).map(([,r])=>r).filter(r=>(this.options.notAfter||[]).concat(n).includes(r.name));return[new mi({key:e,appendTransaction:(r,a,s)=>{const{doc:o,tr:l,schema:c}=s,d=e.getState(s),f=o.content.size,p=c.nodes[n];if(d)return l.insert(f,p.create())},state:{init:(r,a)=>{const s=a.tr.doc.lastChild;return!c5({node:s,types:i})},apply:(r,a)=>{if(!r.docChanged||r.getMeta("__uniqueIDTransaction"))return a;const s=r.doc.lastChild;return!c5({node:s,types:i})}}})]}}),uEe=Gn.create({name:"undoRedo",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:t,dispatch:e})=>F7(t,e),redo:()=>({state:t,dispatch:e})=>z7(t,e)}},addProseMirrorPlugins(){return[sEe(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),dEe=Gn.create({name:"starterKit",addExtensions(){var t,e,n,i;const r=[];return this.options.bold!==!1&&r.push(Fwe.configure(this.options.bold)),this.options.blockquote!==!1&&r.push(Owe.configure(this.options.blockquote)),this.options.bulletList!==!1&&r.push(M7.configure(this.options.bulletList)),this.options.code!==!1&&r.push(Bwe.configure(this.options.code)),this.options.codeBlock!==!1&&r.push(Gwe.configure(this.options.codeBlock)),this.options.document!==!1&&r.push($we.configure(this.options.document)),this.options.dropcursor!==!1&&r.push(oEe.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&r.push(lEe.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&r.push(Wwe.configure(this.options.hardBreak)),this.options.heading!==!1&&r.push(qwe.configure(this.options.heading)),this.options.undoRedo!==!1&&r.push(uEe.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&r.push(Xwe.configure(this.options.horizontalRule)),this.options.italic!==!1&&r.push(Jwe.configure(this.options.italic)),this.options.listItem!==!1&&r.push(E7.configure(this.options.listItem)),this.options.listKeymap!==!1&&r.push(P7.configure((t=this.options)==null?void 0:t.listKeymap)),this.options.link!==!1&&r.push(w7.configure((e=this.options)==null?void 0:e.link)),this.options.orderedList!==!1&&r.push(O7.configure(this.options.orderedList)),this.options.paragraph!==!1&&r.push(UMe.configure(this.options.paragraph)),this.options.strike!==!1&&r.push(jMe.configure(this.options.strike)),this.options.text!==!1&&r.push(BMe.configure(this.options.text)),this.options.underline!==!1&&r.push(k7.configure((n=this.options)==null?void 0:n.underline)),this.options.trailingNode!==!1&&r.push(cEe.configure((i=this.options)==null?void 0:i.trailingNode)),r}}),fEe=dEe,hEe=Gn.create({name:"textAlign",addOptions(){return{types:[],alignments:["left","center","right","justify"],defaultAlignment:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:t=>{const e=t.style.textAlign;return this.options.alignments.includes(e)?e:this.options.defaultAlignment},renderHTML:t=>t.textAlign?{style:`text-align: ${t.textAlign}`}:{}}}}]},addCommands(){return{setTextAlign:t=>({commands:e})=>this.options.alignments.includes(t)?this.options.types.map(n=>e.updateAttributes(n,{textAlign:t})).some(n=>n):!1,unsetTextAlign:()=>({commands:t})=>this.options.types.map(e=>t.resetAttributes(e,"textAlign")).some(e=>e),toggleTextAlign:t=>({editor:e,commands:n})=>this.options.alignments.includes(t)?e.isActive({textAlign:t})?n.unsetTextAlign():n.setTextAlign(t):!1}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign("left"),"Mod-Shift-e":()=>this.editor.commands.setTextAlign("center"),"Mod-Shift-r":()=>this.editor.commands.setTextAlign("right"),"Mod-Shift-j":()=>this.editor.commands.setTextAlign("justify")}}}),pEe=hEe,mEe=20,j7=(t,e=0)=>{const n=[];return!t.children.length||e>mEe||Array.from(t.children).forEach(i=>{i.tagName==="SPAN"?n.push(i):i.children.length&&n.push(...j7(i,e+1))}),n},gEe=t=>{if(!t.children.length)return;const e=j7(t);e&&e.forEach(n=>{var i,r;const a=n.getAttribute("style"),s=(r=(i=n.parentElement)==null?void 0:i.closest("span"))==null?void 0:r.getAttribute("style");n.setAttribute("style",`${s};${a}`)})},B7=Ju.create({name:"textStyle",priority:101,addOptions(){return{HTMLAttributes:{},mergeNestedSpanStyles:!0}},parseHTML(){return[{tag:"span",consuming:!1,getAttrs:t=>t.hasAttribute("style")?(this.options.mergeNestedSpanStyles&&gEe(t),{}):!1}]},renderHTML({HTMLAttributes:t}){return["span",wi(this.options.HTMLAttributes,t),0]},addCommands(){return{toggleTextStyle:t=>({commands:e})=>e.toggleMark(this.name,t),removeEmptyTextStyle:()=>({tr:t})=>{const{selection:e}=t;return t.doc.nodesBetween(e.from,e.to,(n,i)=>{if(n.isTextblock)return!0;n.marks.filter(r=>r.type===this.type).some(r=>Object.values(r.attrs).some(a=>!!a))||t.removeMark(i,i+n.nodeSize,this.type)}),!0}}}}),xEe=Gn.create({name:"backgroundColor",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{backgroundColor:{default:null,parseHTML:t=>{var e;const n=t.getAttribute("style");if(n){const i=n.split(";").map(r=>r.trim()).filter(Boolean);for(let r=i.length-1;r>=0;r-=1){const a=i[r].split(":");if(a.length>=2){const s=a[0].trim().toLowerCase(),o=a.slice(1).join(":").trim();if(s==="background-color")return o.replace(/['"]+/g,"")}}}return(e=t.style.backgroundColor)==null?void 0:e.replace(/['"]+/g,"")},renderHTML:t=>t.backgroundColor?{style:`background-color: ${t.backgroundColor}`}:{}}}}]},addCommands(){return{setBackgroundColor:t=>({chain:e})=>e().setMark("textStyle",{backgroundColor:t}).run(),unsetBackgroundColor:()=>({chain:t})=>t().setMark("textStyle",{backgroundColor:null}).removeEmptyTextStyle().run()}}}),H7=Gn.create({name:"color",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{color:{default:null,parseHTML:t=>{var e;const n=t.getAttribute("style");if(n){const i=n.split(";").map(r=>r.trim()).filter(Boolean);for(let r=i.length-1;r>=0;r-=1){const a=i[r].split(":");if(a.length>=2){const s=a[0].trim().toLowerCase(),o=a.slice(1).join(":").trim();if(s==="color")return o.replace(/['"]+/g,"")}}}return(e=t.style.color)==null?void 0:e.replace(/['"]+/g,"")},renderHTML:t=>t.color?{style:`color: ${t.color}`}:{}}}}]},addCommands(){return{setColor:t=>({chain:e})=>e().setMark("textStyle",{color:t}).run(),unsetColor:()=>({chain:t})=>t().setMark("textStyle",{color:null}).removeEmptyTextStyle().run()}}}),vEe=Gn.create({name:"fontFamily",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontFamily:{default:null,parseHTML:t=>t.style.fontFamily,renderHTML:t=>t.fontFamily?{style:`font-family: ${t.fontFamily}`}:{}}}}]},addCommands(){return{setFontFamily:t=>({chain:e})=>e().setMark("textStyle",{fontFamily:t}).run(),unsetFontFamily:()=>({chain:t})=>t().setMark("textStyle",{fontFamily:null}).removeEmptyTextStyle().run()}}}),yEe=Gn.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:t=>t.style.fontSize,renderHTML:t=>t.fontSize?{style:`font-size: ${t.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:t=>({chain:e})=>e().setMark("textStyle",{fontSize:t}).run(),unsetFontSize:()=>({chain:t})=>t().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),bEe=Gn.create({name:"lineHeight",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{lineHeight:{default:null,parseHTML:t=>t.style.lineHeight,renderHTML:t=>t.lineHeight?{style:`line-height: ${t.lineHeight}`}:{}}}}]},addCommands(){return{setLineHeight:t=>({chain:e})=>e().setMark("textStyle",{lineHeight:t}).run(),unsetLineHeight:()=>({chain:t})=>t().setMark("textStyle",{lineHeight:null}).removeEmptyTextStyle().run()}}});Gn.create({name:"textStyleKit",addExtensions(){const t=[];return this.options.backgroundColor!==!1&&t.push(xEe.configure(this.options.backgroundColor)),this.options.color!==!1&&t.push(H7.configure(this.options.color)),this.options.fontFamily!==!1&&t.push(vEe.configure(this.options.fontFamily)),this.options.fontSize!==!1&&t.push(yEe.configure(this.options.fontSize)),this.options.lineHeight!==!1&&t.push(bEe.configure(this.options.lineHeight)),this.options.textStyle!==!1&&t.push(B7.configure(this.options.textStyle)),t}});var _Ee=H7,SEe=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,wEe=Fa.create({name:"image",addOptions(){return{inline:!1,allowBase64:!1,HTMLAttributes:{},resize:!1}},inline(){return this.options.inline},group(){return this.options.inline?"inline":"block"},draggable:!0,addAttributes(){return{src:{default:null},alt:{default:null},title:{default:null},width:{default:null},height:{default:null}}},parseHTML(){return[{tag:this.options.allowBase64?"img[src]":'img[src]:not([src^="data:"])'}]},renderHTML({HTMLAttributes:t}){return["img",wi(this.options.HTMLAttributes,t)]},parseMarkdown:(t,e)=>e.createNode("image",{src:t.href,title:t.title,alt:t.text}),renderMarkdown:t=>{var e,n,i,r,a,s;const o=(n=(e=t.attrs)==null?void 0:e.src)!=null?n:"",l=(r=(i=t.attrs)==null?void 0:i.alt)!=null?r:"",c=(s=(a=t.attrs)==null?void 0:a.title)!=null?s:"";return c?`![${l}](${o} "${c}")`:`![${l}](${o})`},addNodeView(){if(!this.options.resize||!this.options.resize.enabled||typeof document>"u"||!this.editor.isEditable)return null;const{directions:t,minWidth:e,minHeight:n,alwaysPreserveAspectRatio:i}=this.options.resize;return({node:r,getPos:a,HTMLAttributes:s})=>{const o=document.createElement("img");Object.entries(s).forEach(([d,f])=>{if(f!=null)switch(d){case"width":case"height":break;default:o.setAttribute(d,f);break}}),o.src=s.src;const l=new nwe({element:o,node:r,getPos:a,onResize:(d,f)=>{o.style.width=`${d}px`,o.style.height=`${f}px`},onCommit:(d,f)=>{const p=a();p!==void 0&&this.editor.chain().setNodeSelection(p).updateAttributes(this.name,{width:d,height:f}).run()},onUpdate:(d,f,p)=>d.type===r.type,options:{directions:t,min:{width:e,height:n},preserveAspectRatio:i===!0}}),c=l.dom;return c.style.visibility="hidden",c.style.pointerEvents="none",o.onload=()=>{c.style.visibility="",c.style.pointerEvents=""},l}},addCommands(){return{setImage:t=>({commands:e})=>e.insertContent({type:this.name,attrs:t})}},addInputRules(){return[u7({find:SEe,type:this.type,getAttributes:t=>{const[,,e,n,i]=t;return{src:n,alt:e,title:i}}})]}}),MEe=wEe;function u5({content:t,onChange:e,placeholder:n}){const i=Cwe({extensions:[fEe.configure({heading:!1,codeBlock:!1,code:!1}),HMe,MMe.configure({openOnClick:!1,HTMLAttributes:{target:"_blank",rel:"noopener noreferrer"}}),pEe.configure({types:["paragraph"]}),B7,_Ee,MEe.configure({HTMLAttributes:{style:"max-width: 100%; height: auto;"}})],content:t,onUpdate:({editor:s})=>{e(s.getHTML())},editorProps:{attributes:{class:"prose prose-invert prose-sm max-w-none focus:outline-none min-h-[120px] px-3 py-2",placeholder:n||""}}});if(!i)return null;const r=({onClick:s,isActive:o=!1,children:l,title:c})=>x.jsx("button",{type:"button",onClick:s,title:c,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary transition-colors ${o?"bg-bambu-dark-tertiary text-bambu-green":"text-bambu-gray"}`,children:l}),a=()=>{const s=window.prompt("Enter URL:");s&&i.chain().focus().setLink({href:s}).run()};return x.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden bg-bambu-dark",children:[x.jsxs("div",{className:"flex items-center gap-0.5 p-1.5 border-b border-bambu-dark-tertiary bg-bambu-dark-secondary",children:[x.jsx(r,{onClick:()=>i.chain().focus().toggleBold().run(),isActive:i.isActive("bold"),title:"Bold",children:x.jsx(tie,{className:"w-4 h-4"})}),x.jsx(r,{onClick:()=>i.chain().focus().toggleItalic().run(),isActive:i.isActive("italic"),title:"Italic",children:x.jsx(ire,{className:"w-4 h-4"})}),x.jsx(r,{onClick:()=>i.chain().focus().toggleUnderline().run(),isActive:i.isActive("underline"),title:"Underline",children:x.jsx(yae,{className:"w-4 h-4"})}),x.jsx("div",{className:"w-px h-5 bg-bambu-dark-tertiary mx-1"}),x.jsx(r,{onClick:()=>i.chain().focus().toggleBulletList().run(),isActive:i.isActive("bulletList"),title:"Bullet List",children:x.jsx(RG,{className:"w-4 h-4"})}),x.jsx(r,{onClick:()=>i.chain().focus().toggleOrderedList().run(),isActive:i.isActive("orderedList"),title:"Numbered List",children:x.jsx(hre,{className:"w-4 h-4"})}),x.jsx("div",{className:"w-px h-5 bg-bambu-dark-tertiary mx-1"}),x.jsx(r,{onClick:()=>i.chain().focus().setTextAlign("left").run(),isActive:i.isActive({textAlign:"left"}),title:"Align Left",children:x.jsx(pae,{className:"w-4 h-4"})}),x.jsx(r,{onClick:()=>i.chain().focus().setTextAlign("center").run(),isActive:i.isActive({textAlign:"center"}),title:"Align Center",children:x.jsx(uae,{className:"w-4 h-4"})}),x.jsx(r,{onClick:()=>i.chain().focus().setTextAlign("right").run(),isActive:i.isActive({textAlign:"right"}),title:"Align Right",children:x.jsx(fae,{className:"w-4 h-4"})}),x.jsx("div",{className:"w-px h-5 bg-bambu-dark-tertiary mx-1"}),x.jsx(r,{onClick:a,isActive:i.isActive("link"),title:"Add Link",children:x.jsx(dre,{className:"w-4 h-4"})}),i.isActive("link")&&x.jsx(r,{onClick:()=>i.chain().focus().unsetLink().run(),title:"Remove Link",children:x.jsx(_ae,{className:"w-4 h-4"})})]}),x.jsx(_we,{editor:i})]})}function EEe({archiveId:t,archiveName:e,onClose:n}){const i=Mi(),[r,a]=T.useState(!1),[s,o]=T.useState(null),[l,c]=T.useState({}),{data:d,isLoading:f,error:p}=un({queryKey:["archive-project-page",t],queryFn:()=>lt.getArchiveProjectPage(t)}),m=Xt({mutationFn:E=>lt.updateArchiveProjectPage(t,E),onSuccess:()=>{i.invalidateQueries({queryKey:["archive-project-page",t]}),a(!1),c({})}});T.useEffect(()=>{const E=P=>{P.key==="Escape"&&(s!==null?o(null):r?g():n())};return document.addEventListener("keydown",E),()=>document.removeEventListener("keydown",E)},[s,r,n]);const _=[...d?.model_pictures||[],...d?.profile_pictures||[]],b=()=>{c({title:d?.title||"",description:d?.description||"",designer:d?.designer||"",license:d?.license||"",profile_title:d?.profile_title||"",profile_description:d?.profile_description||""}),a(!0)},y=()=>{m.mutate(l)},g=()=>{a(!1),c({})},M=E=>{const P=["p","br","b","strong","i","em","u","a","ul","ol","li","figure","img"],N=new DOMParser().parseFromString(E,"text/html"),F=R=>{if(R.nodeType===Node.TEXT_NODE)return R.textContent||"";if(R.nodeType===Node.ELEMENT_NODE){const O=R,B=O.tagName.toLowerCase();if(!P.includes(B))return Array.from(O.childNodes).map(F).join("");let I="";if(B==="a"&&O.getAttribute("href")){const L=O.getAttribute("href");L?.toLowerCase().startsWith("http")&&(I=` href="${L}" target="_blank" rel="noopener noreferrer"`)}if(B==="img"){const L=O.getAttribute("src");if(!L?.toLowerCase().startsWith("http"))return"";I=` src="${L}" style="max-width: 100%; height: auto;"`}const G=Array.from(O.childNodes).map(F).join("");return["br","img"].includes(B)?`<${B}${I} />`:`<${B}${I}>${G}`}return""};return Array.from(N.body.childNodes).map(F).join("")},w=d&&(d.title||d.description||d.designer||d.profile_title||_.length>0),A=E=>{E.target===E.currentTarget&&n()};return x.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:A,children:[x.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl max-w-4xl w-full max-h-[90vh] overflow-hidden flex flex-col",children:[x.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[x.jsxs("div",{className:"flex items-center gap-3",children:[x.jsx(sp,{className:"w-5 h-5 text-bambu-green"}),x.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Project Page",e&&x.jsxs("span",{className:"text-bambu-gray ml-2",children:["- ",e]})]})]}),x.jsxs("div",{className:"flex items-center gap-2",children:[!r&&w&&x.jsxs(dt,{variant:"ghost",size:"sm",onClick:b,children:[x.jsx(Cre,{className:"w-4 h-4 mr-1"}),"Edit"]}),r&&x.jsxs(x.Fragment,{children:[x.jsx(dt,{variant:"ghost",size:"sm",onClick:g,children:"Cancel"}),x.jsxs(dt,{variant:"primary",size:"sm",onClick:y,disabled:m.isPending,children:[x.jsx(cx,{className:"w-4 h-4 mr-1"}),"Save"]})]}),x.jsx("button",{onClick:n,className:"p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:x.jsx(kn,{className:"w-5 h-5 text-bambu-gray"})})]})]}),x.jsxs("div",{className:"flex-1 overflow-y-auto p-6",children:[f&&x.jsx("div",{className:"flex items-center justify-center py-12",children:x.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-2 border-bambu-green border-t-transparent"})}),p&&x.jsx("div",{className:"text-red-400 text-center py-12",children:"Failed to load project page data"}),d&&!w&&x.jsxs("div",{className:"text-bambu-gray text-center py-12",children:[x.jsx(sp,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),x.jsx("p",{children:"No project page data found in this 3MF file."}),x.jsx("p",{className:"text-sm mt-2",children:"Project pages are typically included in files downloaded from MakerWorld."})]}),d&&w&&x.jsxs("div",{className:"space-y-6",children:[x.jsxs("div",{className:"space-y-4",children:[r?x.jsx("input",{type:"text",value:l.title||"",onChange:E=>c({...l,title:E.target.value}),placeholder:"Title",className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-lg px-4 py-2 text-white text-xl font-semibold"}):d.title&&x.jsx("h3",{className:"text-xl font-semibold text-white",children:d.title}),x.jsxs("div",{className:"flex flex-wrap gap-4 text-sm",children:[r?x.jsxs("div",{className:"flex items-center gap-2",children:[x.jsx(L4,{className:"w-4 h-4 text-bambu-gray"}),x.jsx("input",{type:"text",value:l.designer||"",onChange:E=>c({...l,designer:E.target.value}),placeholder:"Designer",className:"bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-white"})]}):d.designer&&x.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[x.jsx(L4,{className:"w-4 h-4"}),x.jsx("span",{children:d.designer}),d.designer_user_id&&x.jsx("a",{href:`https://makerworld.com/en/@${d.designer_user_id}`,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-green hover:underline",children:x.jsx(Lu,{className:"w-3 h-3"})})]}),d.creation_date&&x.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[x.jsx(Ho,{className:"w-4 h-4"}),x.jsx("span",{children:d.creation_date})]}),r?x.jsxs("div",{className:"flex items-center gap-2",children:[x.jsx(sp,{className:"w-4 h-4 text-bambu-gray"}),x.jsx("input",{type:"text",value:l.license||"",onChange:E=>c({...l,license:E.target.value}),placeholder:"License",className:"bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-white"})]}):d.license&&x.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[x.jsx(sp,{className:"w-4 h-4"}),x.jsx("span",{children:d.license})]}),d.origin&&x.jsx("span",{className:"px-2 py-0.5 bg-bambu-dark rounded text-bambu-gray",children:d.origin})]})]}),(d.description||r)&&x.jsxs("div",{className:"space-y-2",children:[x.jsx("h4",{className:"text-sm font-medium text-bambu-gray uppercase tracking-wide",children:"Description"}),r?x.jsx(u5,{content:l.description||"",onChange:E=>c({...l,description:E}),placeholder:"Enter description..."}):x.jsx("div",{className:"prose prose-invert prose-sm max-w-none text-bambu-gray-light",dangerouslySetInnerHTML:{__html:M(d.description||"")}})]}),(d.profile_title||d.profile_description||r)&&x.jsxs("div",{className:"space-y-2 p-4 bg-bambu-dark rounded-lg",children:[x.jsx("h4",{className:"text-sm font-medium text-bambu-gray uppercase tracking-wide",children:"Print Profile"}),r?x.jsxs("div",{className:"space-y-2",children:[x.jsx("input",{type:"text",value:l.profile_title||"",onChange:E=>c({...l,profile_title:E.target.value}),placeholder:"Profile Title",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-white"}),x.jsx(u5,{content:l.profile_description||"",onChange:E=>c({...l,profile_description:E}),placeholder:"Profile description..."})]}):x.jsxs(x.Fragment,{children:[d.profile_title&&x.jsx("p",{className:"text-white font-medium",children:d.profile_title}),d.profile_description&&x.jsx("div",{className:"prose prose-invert prose-sm max-w-none text-bambu-gray-light",dangerouslySetInnerHTML:{__html:M(d.profile_description)}}),d.profile_user_name&&x.jsxs("p",{className:"text-sm text-bambu-gray",children:["by ",d.profile_user_name]})]})]}),_.length>0&&x.jsxs("div",{className:"space-y-2",children:[x.jsxs("h4",{className:"text-sm font-medium text-bambu-gray uppercase tracking-wide flex items-center gap-2",children:[x.jsx(mS,{className:"w-4 h-4"}),"Images (",_.length,")"]}),x.jsx("div",{className:"grid grid-cols-3 sm:grid-cols-4 md:grid-cols-5 gap-2",children:_.map((E,P)=>x.jsx("button",{onClick:()=>o(P),className:"aspect-square rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors",children:x.jsx("img",{src:E.url,alt:E.name,className:"w-full h-full object-cover"})},E.path))})]}),d.design_model_id&&x.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:x.jsxs("a",{href:`https://makerworld.com/en/models/${d.design_model_id}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 text-bambu-green hover:underline",children:[x.jsx(Lu,{className:"w-4 h-4"}),"View on MakerWorld"]})})]})]})]}),s!==null&&_[s]&&x.jsxs("div",{className:"fixed inset-0 bg-black/90 flex items-center justify-center z-60",onClick:()=>o(null),children:[x.jsx("button",{onClick:E=>{E.stopPropagation(),o(Math.max(0,s-1))},disabled:s===0,className:"absolute left-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary disabled:opacity-30",children:x.jsx(hf,{className:"w-6 h-6 text-white"})}),x.jsx("img",{src:_[s].url,alt:_[s].name,className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:E=>E.stopPropagation()}),x.jsx("button",{onClick:E=>{E.stopPropagation(),o(Math.min(_.length-1,s+1))},disabled:s===_.length-1,className:"absolute right-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary disabled:opacity-30",children:x.jsx(Of,{className:"w-6 h-6 text-white"})}),x.jsx("button",{onClick:()=>o(null),className:"absolute top-4 right-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary",children:x.jsx(kn,{className:"w-6 h-6 text-white"})}),x.jsxs("div",{className:"absolute bottom-4 text-white text-sm",children:[s+1," / ",_.length]})]})]})}const AEe=[.25,.5,.75,1,1.5,2,3,4];function TEe({src:t,title:e,downloadFilename:n,onClose:i}){const r=T.useRef(null),[a,s]=T.useState(!0),[o,l]=T.useState(.5),[c,d]=T.useState(0),[f,p]=T.useState(0);T.useEffect(()=>{const w=r.current;w&&(w.playbackRate=o)},[o]),T.useEffect(()=>{const w=A=>{A.key==="Escape"&&i()};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[i]),T.useEffect(()=>{const w=r.current;if(!w)return;const A=()=>d(w.currentTime),E=()=>p(w.duration),P=()=>s(!0),N=()=>s(!1);return w.addEventListener("timeupdate",A),w.addEventListener("durationchange",E),w.addEventListener("play",P),w.addEventListener("pause",N),()=>{w.removeEventListener("timeupdate",A),w.removeEventListener("durationchange",E),w.removeEventListener("play",P),w.removeEventListener("pause",N)}},[]);const m=()=>{const w=r.current;w&&(a?w.pause():w.play())},_=w=>{const A=r.current;A&&(A.currentTime=parseFloat(w.target.value))},b=()=>{const w=r.current;w&&(w.currentTime=Math.max(0,w.currentTime-5))},y=()=>{const w=r.current;w&&(w.currentTime=Math.min(f,w.currentTime+5))},g=w=>{const A=Math.floor(w/60),E=Math.floor(w%60);return`${A}:${E.toString().padStart(2,"0")}`},M=()=>{const w=document.createElement("a");w.href=t,w.download=n,w.click()};return x.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",children:x.jsxs("div",{className:"relative bg-bambu-dark-secondary rounded-xl max-w-4xl w-full mx-4 overflow-hidden",children:[x.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[x.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[x.jsx(hp,{className:"w-5 h-5 text-bambu-green"}),e]}),x.jsxs("div",{className:"flex items-center gap-2",children:[x.jsxs(dt,{variant:"secondary",size:"sm",onClick:M,children:[x.jsx(pf,{className:"w-4 h-4"}),"Download"]}),x.jsx("button",{onClick:i,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",children:x.jsx(kn,{className:"w-5 h-5 text-bambu-gray"})})]})]}),x.jsxs("div",{className:"p-4",children:[x.jsx("video",{ref:r,src:t,autoPlay:!0,className:"w-full rounded-lg",onClick:m}),x.jsxs("div",{className:"mt-4 space-y-3",children:[x.jsxs("div",{className:"flex items-center gap-3",children:[x.jsx("span",{className:"text-xs text-bambu-gray w-12 text-right",children:g(c)}),x.jsx("input",{type:"range",min:0,max:f||100,value:c,onChange:_,className:`flex-1 h-1 bg-bambu-dark-tertiary rounded-lg appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-3 [&::-webkit-slider-thumb]:h-3 [&::-webkit-slider-thumb]:bg-bambu-green [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:cursor-pointer`}),x.jsx("span",{className:"text-xs text-bambu-gray w-12",children:g(f)})]}),x.jsxs("div",{className:"flex items-center justify-between",children:[x.jsxs("div",{className:"flex items-center gap-2",children:[x.jsx("button",{onClick:b,className:"p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors",title:"Skip back 5s",children:x.jsx(Yre,{className:"w-5 h-5 text-bambu-gray"})}),x.jsx("button",{onClick:m,className:"p-2 bg-bambu-green hover:bg-bambu-green-dark rounded-lg transition-colors",children:a?x.jsx(Are,{className:"w-5 h-5 text-white"}):x.jsx(gS,{className:"w-5 h-5 text-white"})}),x.jsx("button",{onClick:y,className:"p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors",title:"Skip forward 5s",children:x.jsx(kG,{className:"w-5 h-5 text-bambu-gray"})})]}),x.jsxs("div",{className:"flex items-center gap-2",children:[x.jsx("span",{className:"text-sm text-bambu-gray",children:"Speed:"}),x.jsx("div",{className:"flex gap-1",children:AEe.map(w=>x.jsxs("button",{onClick:()=>l(w),className:`px-2 py-1 text-xs rounded transition-colors ${o===w?"bg-bambu-green text-white":"bg-bambu-dark-tertiary text-bambu-gray hover:bg-bambu-dark-tertiary/80"}`,children:[w,"x"]},w))})]})]})]})]})]})})}function CEe({archiveId:t,archiveName:e,onClose:n}){const i=Mi(),{showToast:r}=Jo(),[a,s]=T.useState(null),[o,l]=T.useState("asap"),[c,d]=T.useState(""),[f,p]=T.useState(!1),[m,_]=T.useState(!1),{data:b}=un({queryKey:["printers"],queryFn:()=>lt.getPrinters()});T.useEffect(()=>{b?.length===1&&!a&&s(b[0].id)},[b,a]),T.useEffect(()=>{const w=A=>{A.key==="Escape"&&n()};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[n]);const y=Xt({mutationFn:w=>lt.addToQueue(w),onSuccess:()=>{i.invalidateQueries({queryKey:["queue"]}),r("Added to print queue"),n()},onError:w=>{r(w.message||"Failed to add to queue","error")}}),g=w=>{if(w.preventDefault(),!a){r("Please select a printer","error");return}const A={printer_id:a,archive_id:t,require_previous_success:f,auto_off_after:m};o==="scheduled"&&c&&(A.scheduled_time=new Date(c).toISOString()),y.mutate(A)},M=()=>{const w=new Date;return w.setMinutes(w.getMinutes()+1),w.toISOString().slice(0,16)};return x.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:n,children:x.jsx(vn,{className:"w-full max-w-md",onClick:w=>w.stopPropagation(),children:x.jsxs(Sn,{className:"p-0",children:[x.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[x.jsxs("div",{className:"flex items-center gap-2",children:[x.jsx(Ho,{className:"w-5 h-5 text-bambu-green"}),x.jsx("h2",{className:"text-xl font-semibold text-white",children:"Schedule Print"})]}),x.jsx("button",{onClick:n,className:"text-bambu-gray hover:text-white transition-colors",children:x.jsx(kn,{className:"w-5 h-5"})})]}),x.jsxs("form",{onSubmit:g,className:"p-4 space-y-4",children:[x.jsxs("div",{children:[x.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Print Job"}),x.jsx("p",{className:"text-white font-medium truncate",children:e})]}),x.jsxs("div",{children:[x.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer"}),b?.length===0?x.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm",children:[x.jsx(Ku,{className:"w-4 h-4"}),"No printers configured"]}):x.jsxs("select",{className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:a||"",onChange:w=>s(w.target.value?Number(w.target.value):null),required:!0,children:[x.jsx("option",{value:"",children:"Select printer..."}),b?.map(w=>x.jsx("option",{value:w.id,children:w.name},w.id))]})]}),x.jsxs("div",{children:[x.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"When to print"}),x.jsxs("div",{className:"flex gap-2",children:[x.jsxs("button",{type:"button",className:`flex-1 px-3 py-2 rounded-lg border text-sm flex items-center justify-center gap-2 transition-colors ${o==="asap"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>l("asap"),children:[x.jsx(yo,{className:"w-4 h-4"}),"ASAP (when idle)"]}),x.jsxs("button",{type:"button",className:`flex-1 px-3 py-2 rounded-lg border text-sm flex items-center justify-center gap-2 transition-colors ${o==="scheduled"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>l("scheduled"),children:[x.jsx(Ho,{className:"w-4 h-4"}),"Scheduled"]})]})]}),o==="scheduled"&&x.jsxs("div",{children:[x.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date & Time"}),x.jsx("input",{type:"datetime-local",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:c,onChange:w=>d(w.target.value),min:M(),required:!0})]}),x.jsxs("div",{className:"flex items-center gap-2",children:[x.jsx("input",{type:"checkbox",id:"requirePrevious",checked:f,onChange:w=>p(w.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),x.jsx("label",{htmlFor:"requirePrevious",className:"text-sm text-bambu-gray",children:"Only start if previous print succeeded"})]}),x.jsxs("div",{className:"flex items-center gap-2",children:[x.jsx("input",{type:"checkbox",id:"autoOffAfter",checked:m,onChange:w=>_(w.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),x.jsxs("label",{htmlFor:"autoOffAfter",className:"text-sm text-bambu-gray flex items-center gap-1",children:[x.jsx(xS,{className:"w-3.5 h-3.5"}),"Power off printer when done"]})]}),x.jsx("p",{className:"text-xs text-bambu-gray",children:o==="asap"?"Print will start as soon as the printer is idle.":"Print will start at the scheduled time if the printer is idle. If busy, it will wait until the printer becomes available."}),x.jsxs("div",{className:"flex gap-3 pt-2",children:[x.jsx(dt,{type:"button",variant:"secondary",onClick:n,className:"flex-1",children:"Cancel"}),x.jsx(dt,{type:"submit",className:"flex-1",disabled:y.isPending||!a||b?.length===0,children:y.isPending?"Adding...":"Add to Queue"})]})]})]})})})}function AR(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function Rg(t){const e=Math.floor(t/3600),n=Math.floor(t%3600/60);return e>0?`${e}h ${n}m`:`${n}m`}function d5(t){return new Date(t).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function NEe({archive:t,printerName:e,isSelected:n,onSelect:i,selectionMode:r}){const a=Mi(),{showToast:s}=Jo(),[o,l]=T.useState(!1),[c,d]=T.useState(!1),[f,p]=T.useState(!1),[m,_]=T.useState(!1),[b,y]=T.useState(!1),[g,M]=T.useState(!1),[w,A]=T.useState([]),[E,P]=T.useState(!1),[N,F]=T.useState(!1),[R,O]=T.useState(!1),[B,I]=T.useState(!1),[G,L]=T.useState(null),H=Xt({mutationFn:()=>lt.scanArchiveTimelapse(t.id),onSuccess:j=>{j.status==="attached"?(a.invalidateQueries({queryKey:["archives"]}),s(`Timelapse attached: ${j.filename}`)):j.status==="exists"?s("Timelapse already attached"):j.status==="not_found"&&j.available_files&&j.available_files.length>0?(A(j.available_files),M(!0)):s(j.message||"No matching timelapse found","warning")},onError:j=>{s(j.message||"Failed to scan for timelapse","error")}}),q=Xt({mutationFn:j=>lt.selectArchiveTimelapse(t.id,j),onSuccess:j=>{a.invalidateQueries({queryKey:["archives"]}),s(`Timelapse attached: ${j.filename}`),M(!1),A([])},onError:j=>{s(j.message||"Failed to attach timelapse","error")}}),W=Xt({mutationFn:()=>lt.deleteArchive(t.id),onSuccess:()=>{a.invalidateQueries({queryKey:["archives"]}),s("Archive deleted")},onError:()=>{s("Failed to delete archive","error")}}),K=Xt({mutationFn:()=>lt.toggleFavorite(t.id),onSuccess:j=>{a.invalidateQueries({queryKey:["archives"]}),s(j.is_favorite?"Added to favorites":"Removed from favorites")}}),J=j=>{j.preventDefault(),L({x:j.clientX,y:j.clientY})},se=[{label:"Print",icon:x.jsx(ic,{className:"w-4 h-4"}),onClick:()=>d(!0)},{label:"Schedule",icon:x.jsx(Ho,{className:"w-4 h-4"}),onClick:()=>I(!0)},{label:"Open in Bambu Studio",icon:x.jsx(Lu,{className:"w-4 h-4"}),onClick:()=>{const j=t.print_name||t.filename||"model",X=`${window.location.origin}${lt.getArchiveForSlicer(t.id,j)}`;window.location.href=`bambustudioopen://${encodeURIComponent(X)}`}},{label:"View on MakerWorld",icon:x.jsx(HC,{className:"w-4 h-4"}),onClick:()=>t.makerworld_url&&window.open(t.makerworld_url,"_blank"),disabled:!t.makerworld_url},{label:"",divider:!0,onClick:()=>{}},{label:"3D Preview",icon:x.jsx(x0,{className:"w-4 h-4"}),onClick:()=>l(!0)},{label:"View Timelapse",icon:x.jsx(hp,{className:"w-4 h-4"}),onClick:()=>y(!0),disabled:!t.timelapse_path},{label:"Scan for Timelapse",icon:x.jsx(Vre,{className:"w-4 h-4"}),onClick:()=>H.mutate(),disabled:!t.printer_id||!!t.timelapse_path||H.isPending},{label:"Download",icon:x.jsx(pf,{className:"w-4 h-4"}),onClick:()=>{const j=document.createElement("a");j.href=lt.getArchiveDownload(t.id),j.download=`${t.print_name||t.filename}.3mf`,j.click()}},{label:"Copy Download Link",icon:x.jsx(BC,{className:"w-4 h-4"}),onClick:()=>{const j=`${window.location.origin}${lt.getArchiveDownload(t.id)}`;navigator.clipboard.writeText(j).then(()=>{s("Link copied to clipboard")}).catch(()=>{s("Failed to copy link","error")})}},{label:"QR Code",icon:x.jsx(Fre,{className:"w-4 h-4"}),onClick:()=>P(!0)},{label:`View Photos${t.photos?.length?` (${t.photos.length})`:""}`,icon:x.jsx(jC,{className:"w-4 h-4"}),onClick:()=>F(!0),disabled:!t.photos?.length},{label:"Project Page",icon:x.jsx(sp,{className:"w-4 h-4"}),onClick:()=>O(!0)},{label:"",divider:!0,onClick:()=>{}},{label:t.is_favorite?"Remove from Favorites":"Add to Favorites",icon:x.jsx(v0,{className:`w-4 h-4 ${t.is_favorite?"fill-yellow-400 text-yellow-400":""}`}),onClick:()=>K.mutate()},{label:"Edit",icon:x.jsx(O4,{className:"w-4 h-4"}),onClick:()=>_(!0)},{label:n?"Deselect":"Select",icon:n?x.jsx(d_,{className:"w-4 h-4"}):x.jsx(f_,{className:"w-4 h-4"}),onClick:()=>i(t.id)},{label:"",divider:!0,onClick:()=>{}},{label:"Delete",icon:x.jsx(Pa,{className:"w-4 h-4"}),onClick:()=>p(!0),danger:!0}];return x.jsxs(vn,{className:`relative flex flex-col ${n?"ring-2 ring-bambu-green":""} ${r?"cursor-pointer":""}`,onContextMenu:J,onClick:r?()=>i(t.id):void 0,children:[r&&x.jsx("button",{className:"absolute top-2 left-2 z-10 p-1 rounded bg-black/50 hover:bg-black/70 transition-colors",onClick:j=>{j.stopPropagation(),i(t.id)},children:n?x.jsx(d_,{className:"w-5 h-5 text-bambu-green"}):x.jsx(f_,{className:"w-5 h-5 text-white"})}),x.jsxs("div",{className:"aspect-video bg-bambu-dark relative flex-shrink-0 overflow-hidden rounded-t-xl",children:[t.thumbnail_path?x.jsx("img",{src:lt.getArchiveThumbnail(t.id),alt:t.print_name||t.filename,className:"w-full h-full object-cover"}):x.jsx("div",{className:"w-full h-full flex items-center justify-center",children:x.jsx(mS,{className:"w-12 h-12 text-bambu-dark-tertiary"})}),x.jsx("button",{className:"absolute top-2 right-2 p-1 rounded bg-black/50 hover:bg-black/70 transition-colors",onClick:j=>{j.stopPropagation(),K.mutate()},title:t.is_favorite?"Remove from favorites":"Add to favorites",children:x.jsx(v0,{className:`w-5 h-5 ${t.is_favorite?"text-yellow-400 fill-yellow-400":"text-white"}`})}),t.status==="failed"&&x.jsx("div",{className:"absolute top-2 left-12 px-2 py-1 rounded text-xs bg-red-500/80 text-white",children:"failed"}),t.duplicate_count>0&&x.jsxs("div",{className:"absolute top-2 right-2 px-2 py-1 rounded text-xs bg-purple-500/80 text-white flex items-center gap-1",title:"This model has been printed before",children:[x.jsx(BC,{className:"w-3 h-3"}),"duplicate"]}),t.timelapse_path&&x.jsx("button",{className:"absolute bottom-2 right-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors",onClick:j=>{j.stopPropagation(),y(!0)},title:"View timelapse",children:x.jsx(hp,{className:"w-4 h-4 text-bambu-green"})}),t.photos&&t.photos.length>0&&x.jsxs("button",{className:`absolute bottom-2 ${t.timelapse_path?"right-12":"right-2"} p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:j=>{j.stopPropagation(),F(!0)},title:`View ${t.photos.length} photo${t.photos.length>1?"s":""}`,children:[x.jsx(jC,{className:"w-4 h-4 text-blue-400"}),t.photos.length>1&&x.jsx("span",{className:"absolute -top-1 -right-1 w-4 h-4 bg-blue-500 rounded-full text-[10px] text-white flex items-center justify-center",children:t.photos.length})]})]}),x.jsxs(Sn,{className:"p-4 flex-1 flex flex-col",children:[x.jsx("h3",{className:"font-medium text-white mb-1 truncate",children:t.print_name||t.filename}),x.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:e}),x.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs mb-4 min-h-[48px]",children:[(t.print_time_seconds||t.actual_time_seconds)&&x.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",title:t.time_accuracy?`Estimated: ${Rg(t.print_time_seconds||0)} diff --git a/static/index.html b/static/index.html index b58c1fdb3..fb18da694 100644 --- a/static/index.html +++ b/static/index.html @@ -7,7 +7,7 @@ - +