popost 4.6.8 → 4.6.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,7 +40,7 @@ img, svg image { -webkit-user-drag: none; user-drag: none; }
40
40
  `)&&(n=n.replace(/\r?\n/g,`\r
41
41
  `));let[i]=ci(t,n);return i?{start:a.start+i.start,end:a.start+i.end,text:i.text}:null}return{start:i.start,end:i.end,text:Zl(i.name,r)}}function $l(e,t,n){let r=Ni(t,n);if(!r)return null;let[i,a]=Hi(e.source,t,r);return{start:i,end:a,text:``}}function eu(e,t,n,r){let i=[n];if(r){let e=t.elements.get(n);if(e)for(let r of t.order){let a=t.elements.get(r);a&&a.id!==n&&a.start>=e.start&&a.end<=e.end&&i.push(r)}}return i.some(n=>Ua(e,n)!==Ua(t,n))}function tu(e,t,n){if([e,t].some(e=>ma(e).some(e=>e.id===n)))return[{kind:`reload`}];let r=lo(t,n);return r===``?[]:[{kind:`subtrees`,items:[{id:n,previewHTML:r}]}]}function nu(e,t,n){let r=Rl(e,t);zl(r);let i={};for(let[e,t]of Object.entries(n)){if(!ta(e))throw new Ol(`invalid-op`,`invalid CSS property name "${e}"`);if(t!==null&&!na(t))throw new Ol(`invalid-op`,`unsafe CSS value for ${e}`);i[ea(e)]=t}let a=Pi(r,`style`)??``,o=ia(a,i),s=null;return o!==a&&(s=o.trim()===``?$l(e,r,`style`):Ql(e,r,`style`,o)),{splices:s?[s]:[],attrLocal:!0,live:n=>({live:eu(e,n,t,!1)?tu(e,n,t):[{kind:`style`,id:t,props:i}]})}}var ru=/^[A-Za-z_:][A-Za-z0-9_:.-]*$/;function iu(e,t,n,r){let i=Rl(e,t);if(zl(i),!ru.test(n))throw new Ol(`invalid-op`,`invalid attribute name "${n}"`);let a=n.toLowerCase();if(a.startsWith(`on`)||a.startsWith(`data-pp-`))throw new Ol(`invalid-op`,`attribute "${n}" is not allowed`);let o=r===null?$l(e,i,n):Ql(e,i,n,r);return{splices:o?[o]:[],attrLocal:!0,live:i=>({live:eu(e,i,t,a===`class`)?tu(e,i,t):[{kind:`attr`,id:t,name:n,value:Ul(n,r)}]})}}function au(e,t){let n=Rl(e,t);if(Vl(n))throw new Ol(`unsupported`,`<${n.tag}> cannot be removed`);let[r,i]=Gl(e.source,n.start,n.end);return{splices:[{start:r,end:i,text:``}],live:()=>({live:[{kind:`remove`,id:t}]})}}function ou(e,t,n){let r=n.randomHex??Sa,i=new Set(ma(e).map(e=>Pi(e,`data-popost-page`))),a=[];for(let n of ma(e)){let o=Ni(n,`data-popost-page`);if(!o||n.start<t.start||n.end>t.end)continue;let s=xa(r);for(;i.has(s);)s=xa(r);i.add(s);let c=Bi(e.source,o);c.hasValue&&a.push({start:c.start-t.start,end:c.end-t.start,text:s})}return a.sort((e,t)=>e.start-t.start),ii(e.source.slice(t.start,t.end),a)}function su(e,t){for(let n of e.order){let r=e.elements.get(n);if(r&&!vi(r)&&r.start===t)return r}}function cu(e,t,n){let r=Rl(e,t);if(Vl(r))throw new Ol(`unsupported`,`<${r.tag}> cannot be duplicated`);let i=Kl(e.source,r,ou(e,r,n));return{splices:[{start:i.pos,end:i.pos,text:i.text}],live:e=>{let t=su(e,i.pos+i.payloadAt);if(!t)throw new Ol(`locality`,`duplicate did not produce an element`);return{createdId:t.id,live:lu(e,[t])}}}}function lu(e,t){let n=[];for(let r of[...t].reverse()){let t=r.parent===null?void 0:e.elements.get(r.parent);if(!t||Al.has(r.tag)||Al.has(t.tag))return[{kind:`reload`}];let i=lo(e,r.id);i!==``&&n.push({kind:`insert`,parentId:t.id,beforeId:Hl(e,r.id),previewHTML:i})}return n}function uu(e,t,n,r){let i=Rl(e,t);if(Vl(i))throw new Ol(`unsupported`,`<${i.tag}> cannot be moved`);zl(i);let a=Rl(e,n);if(n===t||Li(e,t,n))throw new Ol(`invalid-op`,`cannot move an element into itself`);if(r===t)return du();if(a.id===i.parent){let e=a.children;if(r===(e[e.indexOf(t)+1]??null))return du()}let o=Yl(e,n,r,e.source.slice(i.start,i.end)),[s,c]=Gl(e.source,i.start,i.end);if(o.pos>s&&o.pos<c)throw new Ol(`invalid-op`,`move target lies inside the moved range`);let l={start:s,end:c,text:``},u={start:o.pos,end:o.pos,text:o.text},d=oi([l],o.pos,1)+o.payloadAt;return{splices:[l,u].sort((e,t)=>e.start-t.start||Number(e.end>e.start)-Number(t.end>t.start)),moved:[{from:i.start,to:d,length:i.end-i.start}],live:e=>Al.has(i.tag)||Al.has(a.tag)?{live:[{kind:`reload`}]}:Wl(e,t)?{live:[{kind:`move`,id:t,parentId:n,beforeId:r}]}:{live:[]}}}function du(){return{splices:[],live:()=>({live:[]})}}function fu(e,t,n,r){let i=r.trim();if(i===``)throw new Ol(`invalid-op`,`nothing to insert`);let a=Yl(e,t,n,i),o=a.pos+a.payloadAt;return{splices:[{start:a.pos,end:a.pos,text:a.text}],live:e=>{let n=[...e.elements.values()].filter(e=>!vi(e)&&e.parent===t&&e.start>=o&&e.start<o+i.length).sort((e,t)=>e.start-t.start),r=n[0];if(!r){if(/^<[a-zA-Z]/.test(i))throw new Ol(`locality`,`inserted markup produced no element under the target`);return{live:[{kind:`reload`}]}}let a=``,s=o;for(let t of n)a+=e.source.slice(s,t.start),s=t.end;a+=e.source.slice(s,o+i.length);let c=a.trim()===``?lu(e,n):[{kind:`reload`}];return{createdId:r.id,live:c}}}}function pu(e,t,n){if(t===``||/[\u0000-\u001f]/.test(t))throw new Ol(`invalid-op`,`invalid font key`);if(/<\/style/i.test(n))throw new Ol(`invalid-op`,`css must not contain </style`);let r=e.head===null?void 0:e.elements.get(e.head);if(!r)throw new Ol(`unsupported`,`document has no <head>`);let i=[...e.elements.values()].filter(e=>e.tag===`style`&&Pi(e,`data-popost-font`)===t),a=()=>({live:[{kind:`headStyle`,key:t,css:n}]}),[o,...s]=i;if(!o){let i=Jl(e,r,`<style data-popost-font="${Vi(t)}">${n}</style>`);return{splices:[{start:i.pos,end:i.pos,text:i.text}],live:a}}let c=[],[l,u]=Bl(e,o);e.source.slice(l,u)!==n&&c.push({start:l,end:u,text:n});for(let t of s){let[n,r]=Gl(e.source,t.start,t.end);c.push({start:n,end:r,text:``})}return c.sort((e,t)=>e.start-t.start),{splices:c,live:a}}function mu(e,t){return{splices:ci(e.source,t),skipLocality:!0,live:()=>({live:[{kind:`reload`}]})}}var hu=class{undoStack=[];redoStack=[];open=null;now;mergeWindowMs;maxEntries;constructor(e={}){this.now=e.now??Date.now,this.mergeWindowMs=e.mergeWindowMs??600,this.maxEntries=e.maxEntries??300}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}get undoLabel(){return this.undoStack[this.undoStack.length-1]?.label??null}get redoLabel(){return this.redoStack[this.redoStack.length-1]?.label??null}get size(){return this.undoStack.length}push(e){let t=e.at??this.now();this.redoStack=[];let n=this.open;if(n&&e.coalesceKey!==void 0&&n.coalesceKey===e.coalesceKey&&this.undoStack[this.undoStack.length-1]===n&&t-n.at<=this.mergeWindowMs){let r=this.merge(n,e,t);this.undoStack[this.undoStack.length-1]=r,this.open=r,r.splices.length===0&&(this.undoStack.pop(),this.open=null);return}let r={...e,splices:[...e.splices],inverse:[...e.inverse],at:t};this.undoStack.push(r),this.open=r,this.undoStack.length>this.maxEntries&&this.undoStack.splice(0,this.undoStack.length-this.maxEntries)}undo(){let e=this.undoStack.pop()??null;return this.open=null,e&&this.redoStack.push(e),e}redo(){let e=this.redoStack.pop()??null;return this.open=null,e&&this.undoStack.push(e),e}breakCoalescing(){this.open=null}clear(){this.undoStack=[],this.redoStack=[],this.open=null}merge(e,t,n){let r=hi(e.splices,t.splices),i=hi(t.inverse,e.inverse);return{label:t.label,splices:r,inverse:i,coalesceKey:e.coalesceKey,at:n}}},gu=62914560,_u=new Set([`script`,`iframe`,`object`,`embed`,`base`,`form`]),vu=new Set([`href`,`src`,`xlink:href`]);function yu(e){return e.prefix?`${e.prefix}:${e.name}`:e.name}function bu(e){return _u.has(e.tagName)||e.tagName===`meta`&&e.attrs.some(e=>e.name===`http-equiv`&&e.value.toLowerCase()===`refresh`)?!0:e.attrs.some(e=>{let t=yu(e);return/^on/i.test(t)||vu.has(t)&&/^\s*javascript:/i.test(e.value)})}function xu(e){let t=ei(e,{scriptingEnabled:!1}),n=t.mode===`quirks`,r={slides:0,unsafe:!1},i=e=>{for(let t of e.childNodes){if(!Ve.isElementNode(t))continue;bu(t)&&(r.unsafe=!0);let e=(t.attrs.find(e=>e.name===`class`)?.value??``).split(/[\t\n\f\r ]+/);(e.includes(`slide`)||n&&e.some(e=>e.toLowerCase()===`slide`))&&r.slides++,i(t)}};return i(t),r.slides===0?{code:`no-slide`}:r.unsafe?{code:`unsafe`}:{slides:r.slides}}function Su(e,t=gu){return e.length>t?!0:e.length*3<=t?!1:new TextEncoder().encode(e).length>t}function Cu(e){if(e.trim()===``)return{ok:!1,code:`empty`};if(Su(e))return{ok:!1,code:`too-large`};let t=xu(e);return`code`in t?{ok:!1,code:t.code}:{ok:!0,slides:t.slides}}var wu=[`color`,`font-size`,`font-family`,`font-weight`,`font-style`,`text-decoration`,`text-decoration-line`,`text-transform`],Tu=e=>{if(!e)return!1;if(e===`bold`||e===`bolder`)return!0;let t=Number.parseInt(e,10);return Number.isFinite(t)&&t>=600},Eu=e=>(e??``).split(/\s+/).filter(e=>e!==``&&e!==`none`);function Du(e,t){return e.command===`color`||e.command===`fontSize`?`format:${e.command}:${t.join(`,`)}`:void 0}function Ou(e,t,n){let r=e=>t.map(t=>({kind:`setStyle`,id:t,props:e(t)})),i=(e,t)=>n(e,[t])[t];switch(e.command){case`bold`:{let e=!t.every(e=>Tu(i(e,`font-weight`)));return r(()=>({"font-weight":e?`700`:`400`}))}case`italic`:{let e=!t.every(e=>/^(italic|oblique)/.test(i(e,`font-style`)??``));return r(()=>({"font-style":e?`italic`:`normal`}))}case`underline`:case`strike`:{let n=e.command===`underline`?`underline`:`line-through`,a=e=>Eu(i(e,`text-decoration-line`)),o=!t.every(e=>a(e).includes(n));return r(e=>{let t=a(e).filter(e=>e!==n),r=o?[...t,n]:t;return{"text-decoration-line":r.length?r.join(` `):`none`}})}case`uppercase`:{let e=!t.every(e=>i(e,`text-transform`)===`uppercase`);return r(()=>({"text-transform":e?`uppercase`:`none`}))}case`color`:return r(()=>({color:e.value}));case`fontSize`:return r(()=>({"font-size":e.value}));case`fontFamily`:return r(()=>({"font-family":e.value}));case`clear`:return r(()=>Object.fromEntries(wu.map(e=>[e,null])))}}var ku=new Set([`script`,`noscript`,`object`,`embed`,`iframe`,`frame`,`base`]),Au=new Set([`href`,`src`,`action`,`formaction`,`xlink:href`]),ju=`default-src 'none'; img-src data: blob: https: http:; style-src 'unsafe-inline'; font-src data: https: http:`;function Mu(e){return e.prefix?`${e.prefix}:${e.name}`:e.name}function Nu(e){e.attrs=e.attrs.filter(e=>{let t=Mu(e).toLowerCase();return!t.startsWith(`on`)&&!(Au.has(t)&&/^\s*javascript:/i.test(e.value))})}function Pu(e){return e.childNodes.some(e=>Ve.isElementNode(e)&&e.tagName===`meta`&&e.attrs.some(e=>e.name===`http-equiv`&&e.value.toLowerCase()===`content-security-policy`))}function Fu(e){Ve.isElementNode(e)&&(Nu(e),Iu(`content`in e?e.content.childNodes:e.childNodes))}function Iu(e){for(let t=e.length-1;t>=0;t--){let n=e[t];Ve.isElementNode(n)&&ku.has(n.tagName)?e.splice(t,1):Fu(n)}}function Lu(e){let t=ei(e,{scriptingEnabled:!1}),n=t.childNodes.find(e=>Ve.isElementNode(e)&&e.tagName===`html`);if(!n)return e;Nu(n),Iu(n.childNodes);let r=n.childNodes.find(e=>Ve.isElementNode(e)&&e.tagName===`head`);if(r&&!Pu(r)){let e=Ve.createElement(`meta`,z.HTML,[{name:`http-equiv`,value:`Content-Security-Policy`},{name:`content`,value:ju}]),t=r.childNodes[0];t?Ve.insertBefore(r,e,t):Ve.appendChild(r,e)}return(t.childNodes.some(e=>Ve.isDocumentTypeNode(e))?`<!DOCTYPE html>
42
42
  `:``)+Kr(n)}function Ru(e){return`${(e??``).replace(/[\\/:*?"<>|\u0000-\u001f]+/g,`-`).trim().replace(/\.html?$/i,``).trim()||`index`}.html`}function zu(e,t,n=`text/html;charset=utf-8`){let r=URL.createObjectURL(new Blob([t],{type:n})),i=document.createElement(`a`);i.href=r,i.download=e,i.style.display=`none`,document.body.append(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),3e3)}var Bu=`no-pages`,Vu=e=>{typeof requestAnimationFrame==`function`?requestAnimationFrame(()=>e()):queueMicrotask(e)},Hu=e=>e instanceof Error?e.message:String(e);function Uu(e,t){let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>{let r=e[n],i=t[n];return i!==void 0&&r.x===i.x&&r.y===i.y&&r.width===i.width&&r.height===i.height})}var Wu=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]);function Gu(e,t){return e.id===t.id&&e.pageKey===t.pageKey&&e.name===t.name&&e.width===t.width&&e.height===t.height}function Ku(e){return new qu(e)}var qu=class{store;get cloud(){return this.store.cloud}frame;params;schedule;history;ids=gi();ctx;idx;savedSource=``;rev=``;snap;listeners=new Set;noticeListeners=new Set;frameListeners=new Set;iframe=null;frameOff=null;mounted=!1;mountToken=0;overflowBase=null;measureQueued=!1;savePromise=null;palette=null;disposed=!1;constructor(e){this.store=e.store,this.frame=e.frame,this.params=e.params,this.schedule=e.schedule??Vu,this.history=new hu({now:e.now}),this.ctx={newId:()=>this.ids.newId(),randomHex:e.randomHex},this.idx=Di(``,this.ids),this.snap={docState:`loading`,error:null,mode:e.store.mode,name:e.params.name??``,path:``,pages:[],currentPageId:null,selection:[],hoverId:null,editingTextId:null,textState:null,rects:{},overflow:[],saveState:`saved`,canUndo:!1,canRedo:!1,conflict:!1,sourceVersion:0}}getSnapshot=()=>this.snap;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});set(e){let t={...this.snap,...e,canUndo:this.history.canUndo,canRedo:this.history.canRedo};if(!Object.keys(t).every(e=>t[e]===this.snap[e])){this.snap=t;for(let e of[...this.listeners])e()}}notify(e,t,n){let r=n===void 0?{kind:e,key:t}:{kind:e,key:t,detail:n};for(let e of[...this.noticeListeners])e(r)}onNotice=e=>(this.noticeListeners.add(e),()=>{this.noticeListeners.delete(e)});onFrameEvent=e=>(this.frameListeners.add(e),()=>{this.frameListeners.delete(e)});index=()=>this.idx;pageSize=()=>{let e=this.snap.pages.find(e=>e.id===this.snap.currentPageId);return e?{width:e.width,height:e.height}:{...ua}};get ready(){return this.snap.docState===`ready`}dirtyState(){return this.snap.saveState===`saving`?`saving`:this.idx.source===this.savedSource?`saved`:`dirty`}async start(){this.set({docState:`loading`,error:null}),await this.loadDocument(null)}async reload(){for(this.snap.editingTextId&&this.endTextEdit(!1);this.savePromise;)await this.savePromise;let e=this.snap.pages.findIndex(e=>e.id===this.snap.currentPageId);await this.loadDocument(e<0?0:e)}externalChange=async()=>{if(this.ready){for(;this.savePromise;)await this.savePromise;this.snap.editingTextId||this.idx.source!==this.savedSource?this.set({conflict:!0}):await this.reload()}};async loadDocument(e){try{let t=await this.store.load();if(this.disposed)return;let n=Di(t.content,this.ids),r=ba(n,{ratio:this.params.ratio});if(r.length===0)throw Error(Bu);this.idx=n,this.savedSource=t.content,this.rev=t.rev,this.history.clear(),this.overflowBase=null;let i=r[Math.min(e??0,r.length-1)];this.set({docState:`ready`,error:null,name:t.name,path:t.path,pages:r,currentPageId:i.id,selection:[],hoverId:null,editingTextId:null,textState:null,rects:{},overflow:[],saveState:`saved`,conflict:!1,sourceVersion:this.snap.sourceVersion+1}),this.remount()}catch(e){if(this.disposed)return;this.set({docState:`error`,error:Hu(e)})}}attachFrame=e=>{if(e===null){this.frameOff?.(),this.frameOff=null,this.iframe=null,this.mounted=!1,this.mountToken++;return}e===this.iframe&&this.frameOff||(this.iframe=e,this.frameOff??=this.frame.on(e=>this.onFrame(e)),this.remount())};pendingTextEdit=null;remount(){let e=this.iframe;if(!e||!this.ready||this.disposed)return;let t=++this.mountToken;this.mounted=!1,this.snap.editingTextId&&this.set({editingTextId:null,textState:null});let n=this.snap.currentPageId;this.frame.mount(e,this.idx,{currentPageId:n}).then(()=>{if(t!==this.mountToken||this.disposed)return;this.mounted=!0;let e=this.snap.currentPageId;e!==null&&e!==n&&this.frame.send({type:`currentPage`,id:e});let r=this.pendingTextEdit;this.pendingTextEdit=null,r?.(),this.runMeasure()},e=>{t!==this.mountToken||this.disposed||this.set({docState:`error`,error:Hu(e)})})}onFrame(e){switch(e.type){case`ready`:case`fontsReady`:this.mounted&&this.runMeasure();break;case`rects`:this.setMeasure(e.rects,e.overflow);break;case`hover`:this.set({hoverId:e.id});break;case`textState`:if(e.id===this.snap.editingTextId){let t=this.snap.textState;t&&t.range===e.range&&[`bold`,`italic`,`underline`,`strike`].every(n=>!!t.active[n]==!!e.active[n])||this.set({textState:{range:e.range,active:e.active}})}break;case`textCommit`:e.id===this.snap.editingTextId&&(this.set({editingTextId:null,textState:null}),this.runOps([{kind:`setInnerHTML`,id:e.id,html:e.html}],`text`));break;case`textCancel`:e.id===this.snap.editingTextId&&this.set({editingTextId:null,textState:null})}for(let t of[...this.frameListeners])t(e)}setMeasure(e,t){this.set({rects:Uu(this.snap.rects,e)?this.snap.rects:e,overflow:Wu(this.snap.overflow,t)?this.snap.overflow:t})}markOverflowBase(){this.overflowBase??=this.snap.overflow}scheduleMeasure(){this.markOverflowBase(),!this.measureQueued&&(this.measureQueued=!0,this.schedule(()=>{this.measureQueued=!1,this.mounted&&!this.disposed&&this.runMeasure()}))}runMeasure(){let e;try{e=this.frame.measure(`page`)}catch{return}let t=this.overflowBase;this.overflowBase=null,this.setMeasure(e.rects,e.overflow),t&&e.overflow.some(e=>!t.includes(e)&&Wa(this.idx,e)===`text`)&&this.notify(`info`,`textOverflow`)}measure=e=>{if(!this.mounted)return;if(e===`page`){this.runMeasure();return}let t;try{t=this.frame.measure(e)}catch{return}let n=new Set(e);this.set({rects:{...this.snap.rects,...t.rects},overflow:[...this.snap.overflow.filter(e=>!n.has(e)),...t.overflow]})};styles=(e,t)=>{if(!this.mounted)return{};try{return this.frame.styles(e,t)}catch{return{}}};apply=(e,t={})=>{this.runOps([e],t.label??e.kind,t.coalesceKey)};applyBatch=(e,t,n={})=>{this.runOps(e,t,n.coalesceKey)};runOps(e,t,n){if(!this.ready||e.length===0)return!1;this.commitTextEdit();let r=this.idx,i=r,a=[],o=[],s=[],c;try{e.forEach((e,t)=>{let n=jl(i,e,this.ctx);i=n.index,a=t===0?n.splices:hi(a,n.splices),o=t===0?n.inverse:hi(n.inverse,o),s.push(...n.live),n.createdId!==void 0&&(c=n.createdId)})}catch(e){return this.notify(`error`,`editRejected`,e instanceof Ol?e.message:Hu(e)),!1}return i.source===r.source||(this.history.push({label:t,splices:a,inverse:o,coalesceKey:n}),this.install(i,s,c),!0)}undo=()=>{this.step(`undo`)};redo=()=>{this.step(`redo`)};step(e){if(!this.ready)return;this.commitTextEdit();let t=e===`undo`?this.history.undo():this.history.redo();if(!t)return;let n=Ml(this.idx,e===`undo`?t.inverse:t.splices,this.ctx);this.install(n.index,n.live)}install(e,t,n){this.idx=e;let r=this.snap,i=ba(e,{ratio:this.params.ratio}),a=i.length===r.pages.length&&i.every((e,t)=>Gu(e,r.pages[t]))?r.pages:i,o=r.currentPageId,s=!1;if(!a.some(e=>e.id===o)){let e=Math.max(0,r.pages.findIndex(e=>e.id===o));o=a[Math.min(e,a.length-1)]?.id??null,s=!0}let c=r.selection.filter(t=>e.elements.has(t));if(n!==void 0&&e.elements.has(n)){let t=ha(e,n);t!==null&&t!==n&&Ga(e,t).includes(n)&&(c=[n],t!==o&&(o=t,s=!0))}if(c.length===r.selection.length&&c.every((e,t)=>e===r.selection[t])&&(c=r.selection),this.markOverflowBase(),this.set({pages:a,currentPageId:o,selection:c,hoverId:r.hoverId!==null&&e.elements.has(r.hoverId)?r.hoverId:null,sourceVersion:r.sourceVersion+1,saveState:this.snap.saveState===`saving`?`saving`:e.source===this.savedSource?`saved`:`dirty`}),this.iframe){if(!this.mounted||t.some(e=>e.kind===`reload`)){this.remount();return}t.length&&this.frame.send({type:`live`,updates:t}),s&&o!==null&&this.frame.send({type:`currentPage`,id:o}),this.scheduleMeasure()}}select=(e,t={})=>{if(!this.ready)return;let n=new Set(ma(this.idx).map(e=>e.id)),r=[...new Set(e)].filter(e=>this.idx.elements.has(e)&&!n.has(e)),i=this.snap.selection,a,o;if(t.additive){a=[...i],o=[];for(let e of r){let t=a.indexOf(e);t>=0?a.splice(t,1):(a.push(e),o.push(e))}}else a=r,o=r;this.snap.editingTextId&&(a.length!==1||a[0]!==this.snap.editingTextId)&&this.commitTextEdit();let s=o.length?ha(this.idx,o[0]):null;s!==null&&s!==this.snap.currentPageId&&(this.switchPage(s),a=a.filter(e=>ha(this.idx,e)===s)),!Wu(a,i)&&(this.history.breakCoalescing(),this.set({selection:a}))};selectParent=()=>{let e=this.snap.selection[0],t=this.snap.currentPageId;if(!this.ready||e===void 0||t===null)return;let n=new Set(Ga(this.idx,t));for(let r=this.idx.elements.get(e)?.parent??null;r!==null&&r!==t;r=this.idx.elements.get(r)?.parent??null)if(n.has(r)){this.select([r]);return}};setCurrentPage=e=>{!this.ready||e===this.snap.currentPageId||!this.snap.pages.some(t=>t.id===e)||this.switchPage(e)};switchPage(e){this.commitTextEdit(),this.history.breakCoalescing(),this.set({currentPageId:e,selection:[],hoverId:null,rects:{},overflow:[]}),this.overflowBase=null,this.mounted&&(this.frame.send({type:`currentPage`,id:e}),this.runMeasure())}beginTextEdit=(e,t=`end`)=>{let n=typeof t==`string`?{type:`beginTextEdit`,id:e,caret:t}:{type:`beginTextEdit`,id:e,caret:`point`,x:t.x,y:t.y};if(!this.ready||!this.idx.elements.has(e))return;if(!this.mounted){this.pendingTextEdit=()=>{this.snap.selection[0]===e&&this.beginTextEdit(e,t)};return}if(this.snap.editingTextId===e)return;this.commitTextEdit();let r=ha(this.idx,e);r!==null&&r!==this.snap.currentPageId&&this.switchPage(r),this.set({selection:[e],editingTextId:e,textState:null}),this.frame.send(n)};endTextEdit=e=>{this.snap.editingTextId&&(this.mounted&&this.frame.send({type:`endTextEdit`,commit:e}),this.snap.editingTextId&&this.set({editingTextId:null,textState:null}))};commitTextEdit(){this.snap.editingTextId&&this.endTextEdit(!0)}format=e=>{if(!this.ready)return;let t=this.snap.editingTextId;if(t&&this.snap.textState?.range){this.frame.send({type:`format`,format:e});return}let n=(t?[t]:this.snap.selection).filter(e=>this.idx.elements.has(e));if(n.length===0)return;this.commitTextEdit();let r=Ou(e,n,this.styles);this.runOps(r,`format:${e.command}`,Du(e,n))};highlight=e=>{this.mounted&&this.frame.send({type:`highlight`,ids:e.filter(e=>this.idx.elements.has(e))})};livePreview=e=>{let t=e.filter(e=>e.kind!==`reload`);this.mounted&&t.length&&this.frame.send({type:`live`,updates:t})};cancelLivePreview=e=>{let t=[];for(let n of e){let e=this.idx.elements.get(n);e&&(t.push({kind:`attr`,id:n,name:`style`,value:Pi(e,`style`)}),t.push({kind:`attr`,id:n,name:`src`,value:Pi(e,`src`)}))}this.livePreview(t)};save=async(e={})=>{if(!this.ready)return;let t=e.force===!0;if(this.commitTextEdit(),this.snap.conflict&&!t)return;for(;this.savePromise;)await this.savePromise;if(!t&&this.idx.source===this.savedSource||this.snap.conflict&&!t)return;let n=this.runSave(t);this.savePromise=n;try{await n}finally{this.savePromise===n&&(this.savePromise=null)}};async runSave(e){let t=this.idx.source;if(Su(t)){this.set({saveState:`error`}),this.notify(`error`,`saveFailed`,`too-large`);return}this.set({saveState:`saving`});try{let n=await this.store.save(t,{rev:this.rev,force:e});this.rev=n.rev,this.savedSource=t,this.set({saveState:this.idx.source===t?`saved`:`dirty`,conflict:!1})}catch(e){e instanceof Ss||e?.status===409?this.set({saveState:`dirty`,conflict:!0}):(this.set({saveState:`error`}),this.notify(`error`,`saveFailed`,Hu(e)))}}resetToInitial=async()=>{if(!this.ready)return;this.commitTextEdit();let e;try{e=await this.store.initial()}catch(e){this.notify(`error`,`resetUnavailable`,Hu(e));return}if(!e.available){this.notify(`info`,`resetUnavailable`);return}this.runOps([{kind:`replaceDocument`,source:e.content}],`reset`)&&this.notify(`info`,`resetDone`)};replaceSource=e=>{if(!this.ready)return`not-ready`;let t=Cu(e);return t.ok?this.runOps([{kind:`replaceDocument`,source:e}],`code`)?null:`rejected`:t.code};uploadImage=async e=>{if(!this.store.uploadImage)throw Error(`Project asset upload unavailable`);let t=await this.store.uploadImage(e,{rev:this.rev});return this.rev=t.rev,t.image};downloadAll=async()=>{if(!this.ready)return;for(this.commitTextEdit();this.savePromise;)await this.savePromise;let e=this.idx.source;try{let t=await this.store.downloadAll(e,{rev:this.rev});this.rev=t.rev,this.store.mode===`local`&&(this.savedSource=e,this.set({saveState:this.dirtyState(),conflict:!1})),this.notify(`info`,`downloadDone`)}catch(e){this.notify(`error`,`downloadFailed`,e instanceof ws?e.message:Hu(e))}};exportHTML=()=>{if(this.ready){this.commitTextEdit();try{zu(Ru(this.snap.name),Lu(this.idx.source))}catch(e){this.notify(`error`,`downloadFailed`,Hu(e))}}};fontPalette=()=>(this.palette||=this.store.fontPalette().catch(e=>{throw this.palette=null,e}),this.palette);applyFont=async(e,t)=>{if(this.ready){this.commitTextEdit();try{let n=(await this.fontPalette()).roles,r=n.find(t=>t.id===e);if(!r)throw Error(rc);let i=t.filter(e=>this.idx.elements.has(e));if(i.length===0)return;let a=i.map(e=>zi(this.idx,e)).join(`
43
- `),o=gc(n,r.family,a),s=await this.store.fontCSS(o.needed.map(e=>e.id),{rev:this.rev});this.rev=s.rev;let c=o.needed.map(e=>{let t=s.css[e.id];if(t===void 0)throw Error(`Missing font CSS: ${e.id}`);return{kind:`upsertFontStyle`,key:e.id,css:t}});for(let e of i.filter(e=>this.idx.elements.has(e)))c.push({kind:`setStyle`,id:e,props:{"font-family":o.stack}});this.runOps(c,`font`)}catch(e){this.notify(`error`,`fontFailed`,Hu(e))}}};dispose(){this.disposed=!0,this.mountToken++,this.mounted=!1,this.frameOff?.(),this.frameOff=null,this.listeners.clear(),this.noticeListeners.clear(),this.frameListeners.clear(),this.frame.dispose()}};function Ju(e,t){let n=()=>{let n=e.getSnapshot(),r={"data-doc-state":n.docState,"data-doc-path":n.path,"data-doc-seq":String(n.sourceVersion),"data-slide-count":String(n.pages.length)};for(let[e,n]of Object.entries(r))t.getAttribute(e)!==n&&t.setAttribute(e,n)};return n(),e.subscribe(n)}var Yu=`popost-canvas:lang`,Xu=`gs9_editor_lang`,Zu=`/pages/`;function Qu(e,t,n){return t?Zu:e.store===`host`?`${n}/`:void 0}function $u(e){try{return localStorage.getItem(e)}catch{return null}}function ed(e,t){try{localStorage.setItem(e,t)}catch{}}var td=e=>e===`en`||e===`zh`?e:null;function nd(){try{return navigator.languages?.length?navigator.languages:[navigator.language]}catch{return[]}}function rd(e=nd()){return(e.find(Boolean)??``).toLowerCase().startsWith(`zh`)?`zh`:`en`}function id(e,t){let n=td(new URLSearchParams(e).get(`lang`));return n?(ed(Yu,n),n):td($u(`popost-canvas:lang`))??td($u(Xu))??rd(t)}function ad(e,t){return`${t?`• `:``}${e||`Popost`}`}function od(){let e=hs(),t=id(e),n={...gs(e),lang:t},r=xs(),i=r?vl(r):n.store===`host`?Uc(n):Bc(n),a=Qu(n,r,window.location.origin),o=Ku({store:i,frame:os({store:i,baseHref:a,imageOrigins:r?[]:_s(e,n.store)}),params:n});document.documentElement.lang=t===`en`?`en`:`zh-CN`;let s=ms(n),c=n.store===`host`&&!r?ds(Pc(n.file),()=>void o.externalChange()):()=>{},l=Ju(o,document.body),u=()=>{let e=o.getSnapshot(),t=ad(e.name,e.saveState!==`saved`);document.title!==t&&(document.title=t)};u();let d=o.subscribe(u),f=e=>{o.getSnapshot().saveState!==`saved`&&(e.preventDefault(),e.returnValue=``)};return window.addEventListener(`beforeunload`,f),o.start(),{controller:o,params:n,local:r,lang:t,baseHref:a,dispose(){window.removeEventListener(`beforeunload`,f),d(),l(),s(),c(),o.dispose()}}}var sd=()=>{let e=ys();return new URLSearchParams(hs()).get(`tools`)===`1`&&e.store===`host`&&ss()&&Pc(e.file)||null},cd=(e,t,n)=>{let r=sd();return r?Ps(r,e,{content:t},n):Promise.reject(Error(`Project host unavailable`))};function ld(e){let t=document.getElementById(`frame`)?.contentDocument;return t?t.querySelector(`[${Ya}="${e.replace(/["\\]/g,`\\$&`)}"]`):null}function ud(e){let t=ld(e);if(t?.tagName!==`IMG`)return null;let n=t;return n.naturalWidth>0&&n.naturalHeight>0?{width:n.naturalWidth,height:n.naturalHeight}:null}async function dd(e,t=8e3){let n=document.getElementById(`frame`),r=n?.contentWindow,i=n?.contentDocument;!r||!i?.fonts||await Promise.race([(async()=>{if(await new Promise(e=>r.requestAnimationFrame(()=>e())),await i.fonts?.ready,!e)return;let t=[...i.fonts].filter(t=>t.family.replace(/^["']|["']$/g,``)===e);await Promise.all(t.map(e=>e.load().catch(()=>void 0)))})().catch(()=>void 0),new Promise(e=>setTimeout(e,t))])}var fd=`#000000.#333333.#666666.#999999.#cccccc.#eeeeee.#ffffff.#d64545.#ff7a1a.#f5b700.#ffd966.#8bc34a.#2e9e6b.#00a99d.#1e88e5.#3949ab.#7e57c2.#e8369a.#8d6e63.#37474f.#b71c1c.#ffcdd2.#ffe0b2.#fff9c4.#c8e6c9.#b3e5fc.#d1c4e9.#f8bbd0`.split(`.`),pd=/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i,md=/^rgba?\(\s*(\d{1,3})(?:\s*,\s*|\s+)(\d{1,3})(?:\s*,\s*|\s+)(\d{1,3})(?:\s*(?:,|\/)\s*([\d.]+%?))?\s*\)$/i;function hd(e){if(!e||e===`transparent`)return!0;let t=md.exec(e)?.[4]??/\/\s*([\d.]+%?)\s*\)$/.exec(e)?.[1];return t!==void 0&&Number.parseFloat(t)===0}var gd=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,`0`);function _d(e){let t=(e??``).trim(),n=pd.exec(t);if(n){let e=n[1].toLowerCase();return e.length===3?`#${e[0]}${e[0]}${e[1]}${e[1]}${e[2]}${e[2]}`:e.length===8?e.slice(6)===`ff`?`#${e.slice(0,6)}`:null:`#${e}`}let r=md.exec(t);if(r){let e=r[4];return e!==void 0&&!((e.endsWith(`%`)?Number.parseFloat(e)/100:Number.parseFloat(e))>=1)?null:`#${gd(Number(r[1]))}${gd(Number(r[2]))}${gd(Number(r[3]))}`}return null}var vd=/\sstyle\s*=\s*(?:"([^"]*)"|'([^']*)')/gi,yd=/<style\b([^>]*)>([\s\S]*?)<\/style>/gi,bd=/#(?:[0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{3})(?![0-9a-z_-])|rgba?\([^)]*\)/gi,xd=/data:[^"')\s]{64,}/gi;function Sd(e,t=14){let n=new Map,r=e=>{for(let t of e.replace(xd,``).matchAll(bd)){let e=_d(t[0]);e&&n.set(e,(n.get(e)??0)+1)}};for(let t of e.matchAll(vd))r(t[1]??t[2]);for(let t of e.matchAll(yd))/data-popost-font/i.test(t[1])||r(t[2]);return[...n.entries()].map(([e,t],n)=>({hex:e,n:t,at:n})).sort((e,t)=>t.n-e.n||e.at-t.at).slice(0,t).map(e=>e.hex)}function Cd(e,t){e.apply(Ca(t),{label:`duplicate page`});let n=e.getSnapshot().pages,r=n[n.findIndex(e=>e.id===t)+1];r&&e.setCurrentPage(r.id)}function wd(e,t){let n=wa(e.index(),t);return n?(e.apply(n,{label:`delete page`}),!0):!1}function Td(e,t,n){let r=Ta(e.index(),t,n);r&&e.apply(r,{label:`move page`})}var Ed=(e,t)=>t>e?t-1:t;function Dd(e){let t=e.getSnapshot().pages,n=t[0],r=t.at(-1);if(!n||!r)return;let i=e.index().elements.get(r.id)?.parent;if(!i)return;let a=ld(n.id),o=a?.ownerDocument.defaultView?.getComputedStyle(a),s=document.createElement(`div`);s.className=`slide`;let c=xa();s.dataset.popostPage=c,s.dataset.popostWidth=String(n.width),s.dataset.popostHeight=String(n.height);let l=o?.backgroundColor;s.style.cssText=`width:${n.width}px;height:${n.height}px;position:relative;overflow:hidden;background-image:none`,s.style.backgroundColor=l&&!hd(l)?l:`#fff`;let u=e.index().elements.get(i)?.children??[];e.apply({kind:`insertHTML`,parentId:i,beforeId:u[u.indexOf(r.id)+1]??null,html:s.outerHTML},{label:`add page`});let d=e.getSnapshot().pages.find(e=>e.pageKey===c);d&&e.setCurrentPage(d.id)}var Od=[];function kd(e){return Od.push(e),()=>{let t=Od.lastIndexOf(e);t>=0&&Od.splice(t,1)}}function Ad(){let e=Od.pop();return e?(e(),!0):!1}var jd=()=>Od.length>0;function Md(e,t){let n=(0,v.useRef)(t);n.current=t,(0,v.useEffect)(()=>{if(e)return kd(()=>n.current())},[e])}function Nd(e,t,n){for(let r=e.elements.get(t)?.parent??null;r!==null;r=e.elements.get(r)?.parent??null)if(r===n)return!0;return!1}function Pd(e,t){let n=t.filter(t=>e.elements.has(t));return n.filter(t=>!n.some(n=>n!==t&&Nd(e,t,n)))}function Fd(e,t,n){let r=e.elements.get(t)?.parent;if(!r)return null;let i=e.elements.get(r)?.children??[],a=i.indexOf(t);if(a<0)return null;if(n===`up`){let e=i[a-1];return e===void 0?null:{kind:`move`,id:t,parentId:r,beforeId:e}}return a>=i.length-1?null:{kind:`move`,id:t,parentId:r,beforeId:i[a+2]??null}}var Id=[`color`,`font-family`,`font-size`,`font-weight`,`font-style`,`text-decoration-line`,`text-transform`,`text-align`,`line-height`,`letter-spacing`,`opacity`];function Ld(e){let t={};for(let n of Id){let r=e[n];r!==void 0&&r.trim()!==``&&(t[n]=r.trim())}return t}function Rd(e,t){return Object.keys(t).length===0?[]:e.map(e=>({kind:`setStyle`,id:e,props:{...t}}))}var zd=/^(-?\d*\.?\d+)(?:px)?$/,Bd=e=>{let t=zd.exec((e??``).trim());return t?Number(t[1]):null};function Vd(e){let t=(e??``).trim();if(t===``||t===`none`)return{x:0,y:0};let n=t.split(/\s+/);if(n.length>3)return null;let r=n.map(Bd);return r.some(e=>e===null)?null:{x:r[0],y:r[1]??0}}var Hd=[`position`,`left`,`top`,`translate`];function Ud(e){let t=e.position;if(t===`absolute`||t===`fixed`){let t=Bd(e.left),n=Bd(e.top);if(t!==null&&n!==null)return{mode:`abs`,left:t,top:n}}let n=Vd(e.translate)??{x:0,y:0};return{mode:`flow`,x:n.x,y:n.y}}var Wd=e=>Math.round(e),Gd=e=>`${Wd(e)}px`;function Kd(e,t,n){return e.mode===`abs`?{left:Gd(e.left+t),top:Gd(e.top+n)}:{translate:`${Gd(e.x+t)} ${Gd(e.y+n)}`}}var qd=e=>e.length===2,Jd=e=>e===`image`||e===`svg`||e===`video`;function Yd(e){let{handle:t,kind:n,start:r,dx:i,dy:a}=e,o=t.includes(`w`),s=t.startsWith(`n`),c=Math.max(1,r.width),l=Math.max(1,r.height),u=Math.max(8,c+(o?-i:i)),d=l,f={},p=null;return qd(t)?n===`text`?(p=u/c,d=l*p):d=Jd(n)?u*l/c:Math.max(8,l+(s?-a:a)):Jd(n)&&(d=u*l/c),u=Wd(u),f.width=Gd(u-e.extra.width),(Jd(n)||qd(t)&&n===`box`)&&(d=Wd(d),f.height=Gd(d-e.extra.height)),p!==null&&(f[`font-size`]=`${Math.max(4,Math.round(e.fontSize*p*2)/2)}px`),{props:f,shift:{x:o?c-u:0,y:s?l-d:0},width:u,height:Wd(d)}}function Xd(e){let{controller:t,gestures:n,zoom:r,toast:i,t:a}=e,o=()=>Pd(t.index(),t.getSnapshot().selection),s=()=>{let e=o();e.length&&t.applyBatch(e.map(e=>({kind:`duplicate`,id:e})),`duplicate`)},c=()=>{let e=o();e.length!==0&&(t.applyBatch(e.map(e=>({kind:`remove`,id:e})),`delete`),i(a(`toast.deleted`)))},l=e=>{let{selection:n}=t.getSnapshot(),r=n[0];if(n.length!==1||r===void 0)return;let i=Fd(t.index(),r,e);i&&t.apply(i,{label:`reorder`})},u=(e,n)=>{let r=o();if(r.length===0)return;let i=r.map(r=>({kind:`setStyle`,id:r,props:Kd(Ud(t.styles(r,Hd)),e,n)}));t.applyBatch(i,`nudge`,{coalesceKey:`nudge:${r.join(`,`)}`})},d=e=>{let n=o()[0];if(!n||o().length!==1)return!1;let r=Wa(t.index(),n);if(r!==`image`&&r!==`svg`&&r!==`video`)return!1;let i=t.styles(n,[`width`,`height`]),a=t.getSnapshot().rects[n],s=Number.parseFloat(i.width)||a?.width,c=Number.parseFloat(i.height)||a?.height;if(!s||!c)return!1;let l=e===1?1.1:1/1.1;return t.applyBatch([{kind:`setStyle`,id:n,props:{width:`${Math.max(8,Math.round(s*l))}px`,height:`${Math.max(8,Math.round(c*l))}px`}}],`resize`,{coalesceKey:`keyboard-resize:${n}`}),!0},f=()=>{let e=t.getSnapshot();return e.editingTextId?[e.editingTextId]:[...e.selection]},p=null,m=()=>{let e=f()[0];e!==void 0&&(p=Ld(t.styles(e,[...Id])),i(a(`toast.styleCopied`)))},h=()=>{if(!p){i(a(`toast.styleNothing`));return}let e=f();e.length!==0&&(t.applyBatch(Rd(e,p),`paste style`),i(a(`toast.stylePasted`)))},g=e=>{let{pages:n,currentPageId:r}=t.getSnapshot(),i=n[n.findIndex(e=>e.id===r)+(e===`next`?1:-1)];i&&t.setCurrentPage(i.id)},_=()=>{if(n.cancel()||Ad())return;let e=t.getSnapshot();e.editingTextId?t.endTextEdit(!0):e.selection.length&&t.select([])};return{run:e=>{let i=t.getSnapshot();switch(e.type){case`save`:return t.save(),!0;case`undo`:return n.cancel(),t.undo(),!0;case`redo`:return n.cancel(),t.redo(),!0;case`zoom`:return e.mode===`fit`?r.fit():r.step(e.mode===`in`?1:-1),!0;case`scaleSelection`:return d(e.direction);case`duplicate`:return s(),!0;case`delete`:return c(),!0;case`edit`:{let e=i.selection[0];return e===void 0||Wa(t.index(),e)!==`text`?!1:(t.beginTextEdit(e,`end`),!0)}case`escape`:return _(),!0;case`nudge`:return u(e.dx,e.dy),!0;case`reorder`:return l(e.direction),!0;case`page`:return g(e.direction),!0;case`copyStyle`:return f().length!==0&&(m(),!0);case`pasteStyle`:return f().length!==0&&(h(),!0)}},duplicateSelection:s,deleteSelection:c,reorderSelection:l,nudgeSelection:u,copyStyle:m,pasteStyle:h,changePage:g,escape:_}}var Zd=o((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),Q=o(((e,t)=>{t.exports=Zd()}))(),Qd={undo:`M6 4 3 7l3 3M3 7h6.5a3.5 3.5 0 0 1 0 7H7`,redo:`m10 4 3 3-3 3M13 7H6.5a3.5 3.5 0 0 0 0 7H9`,reset:`M3 8a5 5 0 1 0 1.6-3.7M3 2.5v3h3`,save:`M3 3h8l2 2v8H3zM5.5 3v3.5h5V3M5.5 13V9.5h5V13`,export:`M8 2v8M5 7l3 3 3-3M3 12.5h10`,download:`M8 2v7.5M5 7l3 3 3-3M2.5 13.5h11`,chevron:`m4 6 4 4 4-4`,close:`m4 4 8 8M12 4l-8 8`,prev:`m10 3-5 5 5 5`,next:`m6 3 5 5-5 5`,grip:`M6 4v.01M10 4v.01M6 8v.01M10 8v.01M6 12v.01M10 12v.01`,parent:`M3 6V3h3M13 6V3h-3M3 10v3h3M13 10v3h-3M6 6h4v4H6z`,duplicate:`M5.5 5.5h7v7h-7zM3.5 10.5v-7h7`,trash:`M3 4.5h10M6.5 4.5V3h3v1.5M4.5 4.5l.6 8.5h5.8l.6-8.5M7 7v4M9 7v4`,forward:`M8 3v8M4.5 7.5 8 11l3.5-3.5M3 13.5h10`,backward:`M8 13V5M4.5 8.5 8 5l3.5 3.5M3 2.5h10`,text:`M3.5 4V3h9v1M8 3v10M6 13h4`,block:`M3 3h10v10H3zM3 7h10`,layers:`m8 2.5 5.5 3L8 8.5l-5.5-3zM2.5 8.5 8 11.5l5.5-3M2.5 11 8 14l5.5-3`,code:`m5.5 4.5-3.5 3.5 3.5 3.5M10.5 4.5 14 8l-3.5 3.5`,warn:`M8 3 14 13H2zM8 7v3M8 11.5v.01`,alignLeft:`M3 4h10M3 7h6M3 10h10M3 13h6`,alignCenter:`M3 4h10M5 7h6M3 10h10M5 13h6`,alignRight:`M3 4h10M7 7h6M3 10h10M7 13h6`,alignJustify:`M3 4h10M3 7h10M3 10h10M3 13h10`,spacing:`M3 3v10M13 3v10M5.5 8h5M7.5 6 5.5 8l2 2M8.5 6l2 2-2 2`,eraser:`m9 3 4 4-5.5 5.5H5L3 10.5zM6 6l4 4M8 12.5h5`,opacity:`M8 2.5s4 4.2 4 7.2a4 4 0 0 1-8 0c0-3 4-7.2 4-7.2z`,image:`M2.5 3.5h11v9h-11zM2.5 11l3.5-3.5 3 3 2-2 2.5 2.5M10.5 6v.01`,compare:`M2 3h5v10H2zM9 3h5v10H9z`,crop:`M4.5 2v9.5H14M2 4.5h9.5V14`,replace:`M3 6h8.5M9 3.5 11.5 6 9 8.5M13 10H4.5M7 7.5 4.5 10 7 12.5`,pencil:`M3 10.5 10.5 3a1.8 1.8 0 0 1 2.5 2.5L5.5 13H3zM9.5 4l2.5 2.5`,brush:`M3 13c1.5 0 2.5-.5 2.5-2 0-1 .5-1.5 1.5-1.5L12.5 4a1.4 1.4 0 0 0-2-2L5 7.5c-.5.5-1 1-1 2C4 11 3 11.5 3 13z`,paste:`M5.5 3h5v2h-5zM4 4h8v9.5H4zM6.5 8h3M6.5 10.5h3`,shape:`M8 2.5 13.5 12.5h-11z`,play:`M5.5 3.5v9l7-4.5z`,minus:`M3 8h10`,gem:`M2 5.5 4.7 2.8h6.6L14 5.5 8 13.2 2 5.5zM2 5.5h12M4.7 2.8l1.2 2.7L8 13.2l2.1-7.7 1.2-2.7`,wrap:`M2 4h12M2 7.5h9a2.2 2.2 0 0 1 0 4.4H6m2-2-2 2 2 2M2 11h1`,plus:`M8 3v10M3 8h10`,cloud:`M4.5 12.5a3 3 0 0 1-.5-5.9A4.2 4.2 0 0 1 12 7a2.8 2.8 0 0 1-.2 5.5z`,upload:`M8 10V2.5M5 5.5 8 2.5l3 3M3 9v4.5h10V9`,check:`m3.5 8.5 3 3 6-7`};function $({name:e,size:t=16}){return(0,Q.jsx)(`svg`,{className:`icon`,width:t,height:t,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,Q.jsx)(`path`,{d:Qd[e]})})}var $d={"compare.open":`Compare reference`,"compare.close":`Hide comparison`,"compare.reference":`Reference`,"compare.result":`Your design`,"compare.page":`Page {n}`,"compare.empty":`No reference for this page`,"compare.emptyHint":`References follow their original page order`,"compare.loading":`Loading reference…`,"compare.failed":`Could not load references`,"compare.retry":`Retry`,"compare.readonly":`Original · Read only`,"compare.editable":`Editable canvas`,"compare.imageFailed":`Reference image unavailable`,"assets.confirm":`Confirm`,"code.disableWrap":`Turn off wrap`,"code.enableWrap":`Wrap lines`,"code.copy":`Copy`,"code.status.copied":`Full code copied`,"code.status.copyFailed":`Copy failed. Check your browser clipboard permissions.`,"export.pages":`Select pages · {n}/{total}`,"export.all":`Export all`,"export.format":`File format`,"export.resolution":`Resolution`,"export.name":`File name`,"export.editName":`Edit file name`,"export.confirmName":`Confirm file name`,"export.imageFormats":`Image formats`,"export.documentFormats":`Document formats`,"export.standard":`Standard`,"export.high":`High resolution`,"export.paid":`Paid feature`,"export.upgrade":`This feature is available with a paid plan.`,"export.pricing":`Unlock`,"export.progress":`Exporting… {percent}% ({done}/{total})`,"export.done":`ZIP exported`,"export.failed":`Export failed. Try again.`,"history.draftRestored":`Restored to the editor. Save to keep your changes.`,"history.draftFailed":`Could not restore this revision. Try again.`,"zoom.in":`Zoom in`,"zoom.out":`Zoom out`,"panel.add":`Add`,"panel.images":`Add image`,"design.size":`Size`,"design.background":`Background`,"design.cancel":`Cancel`,"design.apply":`Apply`,"add.text":`Add text`,"add.page":`Add page`,"assets.current":`This project`,"assets.history":`Asset history`,"assets.projectHistory":`Project asset history`,"assets.upload":`Upload`,"assets.empty":`No images yet`,"assets.more":`Load more`,"assets.failed":`Could not load images. Try again.`,"colors.expand":`More colors`,"colors.collapse":`Fewer colors`,"topbar.undo":`Undo (Ctrl+Z)`,"topbar.redo":`Redo (Ctrl+Shift+Z)`,"topbar.resetLayout":`Reset to initial layout`,"topbar.save":`Save`,"topbar.saveTitle":`Save (Ctrl+S)`,"topbar.export":`Export`,"topbar.exportHtml":`Save as HTML`,"topbar.downloadImages":`Download all`,"topbar.downloadImagesBusy":`Downloading…`,"save.saved":`All changes saved`,"save.dirty":`Unsaved changes`,"save.saving":`Saving…`,"save.error":`Save failed`,"cloud.save":`Save to Cloud`,"cloud.tooltip":`Manage all your assets on the Popost website`,"cloud.waiting":`Waiting for login…`,"cloud.copyLink":`Copy link`,"cloud.linkCopied":`Link copied`,"cloud.loginLink":`Login link`,"cloud.uploading":`Uploading…`,"cloud.syncing":`Syncing…`,"cloud.saved":`Saved to cloud`,"cloud.synced":`Synced`,"cloud.open":`Open`,"cloud.openTitle":`Open in popost`,"cloud.dirty":`Local changes not uploaded`,"cloud.syncNow":`Sync now`,"cloud.failed":`Upload failed`,"cloud.retry":`Retry`,"cloud.conflict":`Edited on the web`,"cloud.overwrite":`Overwrite`,"cloud.overwriteTitle":`Replace the web copy with this local version`,"cloud.error.UNAUTHORIZED":`The login expired or was already used. Save to Cloud again.`,"cloud.error.STORAGE_FULL":`Your cloud storage is full.`,"cloud.error.RATE_LIMITED":`Too many uploads. Try again in a moment.`,"cloud.error.DECK_INVALID":`The cloud could not accept this project.`,"cloud.error.NETWORK":`Could not reach popost.ai.`,"cloud.error.LOCAL_SAVE_FAILED":`Could not save local edits. Save the project before uploading.`,"cloud.error.generic":`Upload failed. Try again.`,"status.loading":`Loading…`,"status.errorTitle":`Could not open the document`,"status.retry":`Try again`,"error.no-pages":`This document has no pages. A page is a top-level element with class "slide".`,"conflict.title":`Saved elsewhere`,"conflict.body":`This document was changed somewhere else since you opened it. Reload to get the latest version (your unsaved edits are lost), or overwrite it with your version.`,"conflict.reload":`Reload`,"conflict.overwrite":`Overwrite`,"notice.saveFailed":`Save failed`,"notice.editRejected":`That change could not be applied`,"notice.resetDone":`Layout reset to the initial version. Save to keep it.`,"notice.resetUnavailable":`No initial version is available for this document`,"notice.downloadDone":`Download started`,"notice.downloadFailed":`Download failed`,"notice.fontFailed":`Could not apply the font`,"notice.imageFailed":`Could not use the image`,"notice.textOverflow":`Edited text exceeds its box`,"toast.deleted":`Deleted · Ctrl+Z to undo`,"toast.pageDeleted":`Page deleted · Ctrl+Z to undo`,"rail.label":`Panels`,"panel.text":`Text`,"panel.block":`Block`,"panel.layers":`Layers`,"panel.code":`Code`,"panel.close":`Close panel`,"pages.label":`Pages`,"pages.page":`Page {n}`,"pages.prev":`Previous page`,"pages.next":`Next page`,"pages.counter":`{n} / {total}`,"pages.overflowBadge":`Text exceeds its box on this page`,"pages.duplicate":`Duplicate page`,"pages.moveLeft":`Move left`,"pages.moveRight":`Move right`,"pages.delete":`Delete page`,"pages.overflowCount":`{n} text overflow`,"pages.overflowJump":`Jump to the next overflowing text`,"zoom.slider":`Zoom`,"zoom.fit":`Fit to window`,"pill.move":`Drag to move`,"pill.selectParent":`Select parent`,"pill.duplicate":`Duplicate (Ctrl+D)`,"pill.delete":`Delete (Delete)`,"pill.forward":`Bring forward (Alt+↓)`,"pill.backward":`Send backward (Alt+↑)`,"pill.selected":`Selected {n}`,"toolbar.label":`Format`,"toast.styleCopied":`Style copied`,"toast.stylePasted":`Style pasted`,"toast.styleNothing":`Copy a style first (Ctrl+Alt+C)`,"panel.selectHint":`Select a block on the canvas first.`,"toolbar.font":`Font`,"toolbar.fontsLoading":`Loading fonts…`,"toolbar.fontsFailed":`Font library unavailable`,"toolbar.fontMissing":`{name} (not in public library)`,"toolbar.size":`Font size (px)`,"toolbar.sizeDown":`Smaller`,"toolbar.sizeUp":`Larger`,"toolbar.bold":`Bold (Ctrl+B)`,"toolbar.italic":`Italic (Ctrl+I)`,"toolbar.underline":`Underline (Ctrl+U)`,"toolbar.strike":`Strikethrough`,"toolbar.color":`Text colour`,"toolbar.alignLeft":`Align left`,"toolbar.alignCenter":`Align centre`,"toolbar.alignRight":`Align right`,"toolbar.alignJustify":`Justify`,"toolbar.spacing":`Line height and letter spacing`,"toolbar.lineHeight":`Line height`,"toolbar.letterSpacing":`Letter spacing`,"toolbar.uppercase":`Uppercase`,"toolbar.opacity":`Opacity`,"toolbar.clear":`Clear formatting`,"toolbar.copyStyle":`Copy style (Ctrl+Alt+C)`,"toolbar.pasteStyle":`Paste style (Ctrl+Alt+V)`,"toolbar.replaceImage":`Replace image`,"toolbar.crop":`Crop & align`,"toolbar.block":`Block`,"colors.document":`Document colours`,"colors.presets":`Preset colours`,"colors.custom":`Custom colour`,"colors.none":`No colour`,"text.add":`Add text`,"text.addHeading":`Heading`,"text.addSubheading":`Subheading`,"text.addParagraph":`Paragraph`,"text.sampleHeading":`Heading`,"text.sampleSubheading":`Subheading`,"text.sampleParagraph":`Paragraph text`,"text.color":`Text colour`,"block.background":`Background`,"block.radius":`Corner radius`,"block.radius.none":`None`,"block.radius.subtle":`Subtle`,"block.radius.medium":`Medium`,"block.radius.large":`Large`,"block.radius.full":`Full`,"block.padding":`Padding`,"block.padding.none":`None`,"block.padding.narrow":`Narrow`,"block.padding.medium":`Medium`,"block.padding.wide":`Wide`,"block.margin":`Margin`,"block.margin.none":`None`,"block.margin.small":`Small`,"block.margin.medium":`Medium`,"block.margin.large":`Large`,"block.border":`Border`,"block.border.none":`None`,"block.border.solid":`Solid`,"block.border.dashed":`Dashed`,"block.border.dotted":`Dotted`,"block.borderWidth.thin":`Thin`,"block.borderWidth.medium":`Medium`,"block.borderWidth.thick":`Thick`,"block.shadow":`Shadow`,"block.shadow.none":`None`,"block.shadow.soft":`Soft`,"block.shadow.medium":`Medium`,"block.shadow.strong":`Strong`,"block.opacity":`Opacity`,"block.size":`Size`,"block.sizeHint":`Drag the handles on the canvas to resize.`,"block.resetSize":`Reset to original size`,"layers.empty":`This page has no selectable blocks.`,"layers.kind.text":`Text`,"layers.kind.image":`Image`,"layers.kind.svg":`Graphic`,"layers.kind.video":`Video`,"layers.kind.box":`Box`,"code.save":`Save code`,"code.saving":`Saving…`,"code.download":`Download HTML`,"code.status.idle":`Static HTML · editable`,"code.status.dirty":`Unsaved code changes`,"code.status.saved":`Code saved. Canvas and thumbnails updated.`,"code.status.appliedUnsaved":`Code applied to the canvas, but saving the document did not finish.`,"code.status.downloaded":`Downloaded a static HTML copy (no executable scripts)`,"code.err.empty":`Code cannot be empty`,"code.err.too-large":`Code exceeds the 60 MB limit`,"code.err.no-slide":`Keep at least one .slide block`,"code.err.unsafe":`Only static HTML is supported. Scripts, event handlers and embedded content are not allowed`,"code.err.rejected":`Could not update the canvas`,"image.upload":`Upload from computer`,"image.inDocument":`Images in this document`,"image.use":`Use this image`,"image.fromUrl":`Image URL`,"image.apply":`Apply`,"image.loading":`Loading…`,"image.err.notImage":`not an image file`,"image.err.tooLarge":`image is larger than 12 MB`,"image.err.fetch":`the address could not be loaded (it may block other sites)`,"crop.hint":`Drag to reposition the image`,"crop.fill":`Fill container`,"crop.whole":`Show whole`,"crop.done":`Done`},ef={en:$d,zh:{"compare.open":`复刻对比`,"compare.close":`收起对比`,"compare.reference":`参考图文`,"compare.result":`当前作品`,"compare.page":`第 {n} 页`,"compare.empty":`这一页暂无参考图文`,"compare.emptyHint":`参考图文按原始顺序与作品逐页对应`,"compare.loading":`正在加载参考图文…`,"compare.failed":`参考图文加载失败`,"compare.retry":`重试`,"compare.readonly":`原始参考 · 只读`,"compare.editable":`可编辑画布`,"compare.imageFailed":`参考图片暂时无法加载`,"assets.confirm":`确定`,"code.disableWrap":`取消自动换行`,"code.enableWrap":`自动换行`,"code.copy":`复制`,"code.status.copied":`已复制完整代码`,"code.status.copyFailed":`复制失败,请检查浏览器的剪贴板权限。`,"export.pages":`选择页面 · {n}/{total}`,"export.all":`导出全部`,"export.format":`文件格式`,"export.resolution":`分辨率`,"export.name":`文件名`,"export.editName":`编辑文件名`,"export.confirmName":`确认文件名`,"export.imageFormats":`图片格式`,"export.documentFormats":`文档格式`,"export.standard":`标准`,"export.high":`高分辨率`,"export.paid":`付费权益`,"export.upgrade":`该功能为付费权益,付费后可使用。`,"export.pricing":`前往解锁`,"export.progress":`正在导出… {percent}%({done}/{total})`,"export.done":`ZIP 已导出`,"export.failed":`导出失败,请重试`,"history.draftRestored":`已还原到编辑器,请保存以保留更改。`,"history.draftFailed":`此版本无法还原,请重试。`,"zoom.in":`放大`,"zoom.out":`缩小`,"panel.add":`增加`,"panel.images":`增加图片`,"design.size":`尺寸`,"design.background":`背景色`,"design.cancel":`取消`,"design.apply":`确定`,"add.text":`增加文字`,"add.page":`增加页面`,"assets.current":`本次素材`,"assets.history":`历史素材`,"assets.projectHistory":`工程素材记录`,"assets.upload":`上传`,"assets.empty":`暂无素材`,"assets.more":`加载更多`,"assets.failed":`素材加载失败,请重试`,"colors.expand":`展开色板`,"colors.collapse":`收起色板`,"topbar.undo":`撤销 (Ctrl+Z)`,"topbar.redo":`重做 (Ctrl+Shift+Z)`,"topbar.resetLayout":`还原初始布局`,"topbar.save":`保存`,"topbar.saveTitle":`保存 (Ctrl+S)`,"topbar.export":`导出`,"topbar.exportHtml":`保存为 HTML`,"topbar.downloadImages":`下载全部`,"topbar.downloadImagesBusy":`下载中…`,"save.saved":`所有更改已保存`,"save.dirty":`有未保存的更改`,"save.saving":`保存中…`,"save.error":`保存失败`,"cloud.save":`保存到云端`,"cloud.tooltip":`在popost网页端管理你的所有资产`,"cloud.waiting":`等待登录…`,"cloud.copyLink":`复制链接`,"cloud.linkCopied":`链接已复制`,"cloud.loginLink":`登录链接`,"cloud.uploading":`上传中…`,"cloud.syncing":`同步中…`,"cloud.saved":`已保存到云端`,"cloud.synced":`已同步`,"cloud.open":`打开`,"cloud.openTitle":`在 popost 打开`,"cloud.dirty":`本地改动未上传`,"cloud.syncNow":`立即同步`,"cloud.failed":`上传失败`,"cloud.retry":`重试`,"cloud.conflict":`网页端已有修改`,"cloud.overwrite":`覆盖`,"cloud.overwriteTitle":`用本地版本替换网页端的版本`,"cloud.error.UNAUTHORIZED":`登录已过期或已使用,请重新点击“保存到云端”。`,"cloud.error.STORAGE_FULL":`云端存储空间已满。`,"cloud.error.RATE_LIMITED":`上传过于频繁,请稍后再试。`,"cloud.error.DECK_INVALID":`云端无法接收这个作品。`,"cloud.error.NETWORK":`无法连接 popost.ai。`,"cloud.error.LOCAL_SAVE_FAILED":`本地改动保存失败。请先保存作品,再上传到云端。`,"cloud.error.generic":`上传失败,请重试。`,"status.loading":`加载中…`,"status.errorTitle":`无法打开文档`,"status.retry":`重试`,"error.no-pages":`文档里没有页面。页面是带 "slide" 类的顶层元素。`,"conflict.title":`已在别处保存`,"conflict.body":`打开之后,这份文档在别处被修改过。可以重新加载最新版本(未保存的修改会丢失),或用你的版本覆盖。`,"conflict.reload":`重新加载`,"conflict.overwrite":`覆盖`,"notice.saveFailed":`保存失败`,"notice.editRejected":`这个修改无法应用`,"notice.resetDone":`已还原为初始布局,记得保存。`,"notice.resetUnavailable":`这份文档没有可还原的初始版本`,"notice.downloadDone":`已开始下载`,"notice.downloadFailed":`下载失败`,"notice.fontFailed":`无法应用该字体`,"notice.imageFailed":`无法使用这张图片`,"notice.textOverflow":`编辑后的文字超出了文本框`,"toast.deleted":`已删除 · Ctrl+Z 撤销`,"toast.pageDeleted":`已删除页面 · Ctrl+Z 撤销`,"rail.label":`面板`,"panel.text":`文字`,"panel.block":`区块`,"panel.layers":`图层`,"panel.code":`代码`,"panel.close":`关闭面板`,"pages.label":`页面`,"pages.page":`第 {n} 页`,"pages.prev":`上一页`,"pages.next":`下一页`,"pages.counter":`{n} / {total}`,"pages.overflowBadge":`这一页有文字超出文本框`,"pages.duplicate":`复制页面`,"pages.moveLeft":`左移`,"pages.moveRight":`右移`,"pages.delete":`删除页面`,"pages.overflowCount":`{n} 处文字溢出`,"pages.overflowJump":`跳到下一处溢出的文字`,"zoom.slider":`缩放`,"zoom.fit":`适应窗口`,"pill.move":`拖动移动`,"pill.selectParent":`选择父级`,"pill.duplicate":`复制 (Ctrl+D)`,"pill.delete":`删除 (Delete)`,"pill.forward":`上移一层 (Alt+↓)`,"pill.backward":`下移一层 (Alt+↑)`,"pill.selected":`已选 {n} 个`,"toolbar.label":`格式`,"toast.styleCopied":`样式已复制`,"toast.stylePasted":`样式已粘贴`,"toast.styleNothing":`请先复制样式 (Ctrl+Alt+C)`,"panel.selectHint":`请先在画布上选中一个区块。`,"toolbar.font":`字体`,"toolbar.fontsLoading":`字体加载中…`,"toolbar.fontsFailed":`字体库加载失败`,"toolbar.fontMissing":`{name}(不在公共字体库)`,"toolbar.size":`字号 (px)`,"toolbar.sizeDown":`减小字号`,"toolbar.sizeUp":`增大字号`,"toolbar.bold":`加粗 (Ctrl+B)`,"toolbar.italic":`斜体 (Ctrl+I)`,"toolbar.underline":`下划线 (Ctrl+U)`,"toolbar.strike":`删除线`,"toolbar.color":`文字颜色`,"toolbar.alignLeft":`左对齐`,"toolbar.alignCenter":`居中对齐`,"toolbar.alignRight":`右对齐`,"toolbar.alignJustify":`两端对齐`,"toolbar.spacing":`行距与字距`,"toolbar.lineHeight":`行距`,"toolbar.letterSpacing":`字距`,"toolbar.uppercase":`大写`,"toolbar.opacity":`不透明度`,"toolbar.clear":`清除格式`,"toolbar.copyStyle":`复制样式 (Ctrl+Alt+C)`,"toolbar.pasteStyle":`粘贴样式 (Ctrl+Alt+V)`,"toolbar.replaceImage":`替换图片`,"toolbar.crop":`裁剪与对齐`,"toolbar.block":`区块`,"colors.document":`文档中的颜色`,"colors.presets":`预设颜色`,"colors.custom":`自定义颜色`,"colors.none":`无颜色`,"text.add":`添加文字`,"text.addHeading":`标题`,"text.addSubheading":`副标题`,"text.addParagraph":`正文`,"text.sampleHeading":`标题`,"text.sampleSubheading":`副标题`,"text.sampleParagraph":`正文文字`,"text.color":`文字颜色`,"block.background":`背景颜色`,"block.radius":`圆角`,"block.radius.none":`无`,"block.radius.subtle":`轻微`,"block.radius.medium":`中等`,"block.radius.large":`较大`,"block.radius.full":`全圆`,"block.padding":`内边距`,"block.padding.none":`无`,"block.padding.narrow":`窄`,"block.padding.medium":`中`,"block.padding.wide":`宽`,"block.margin":`外边距`,"block.margin.none":`无`,"block.margin.small":`小`,"block.margin.medium":`中`,"block.margin.large":`大`,"block.border":`边框`,"block.border.none":`无`,"block.border.solid":`实线`,"block.border.dashed":`虚线`,"block.border.dotted":`点线`,"block.borderWidth.thin":`细`,"block.borderWidth.medium":`中`,"block.borderWidth.thick":`粗`,"block.shadow":`阴影`,"block.shadow.none":`无`,"block.shadow.soft":`柔和`,"block.shadow.medium":`中等`,"block.shadow.strong":`强烈`,"block.opacity":`不透明度`,"block.size":`尺寸`,"block.sizeHint":`在画布上拖动控制点调整大小。`,"block.resetSize":`还原原始尺寸`,"layers.empty":`这一页没有可选中的区块。`,"layers.kind.text":`文字`,"layers.kind.image":`图片`,"layers.kind.svg":`图形`,"layers.kind.video":`视频`,"layers.kind.box":`容器`,"code.save":`保存代码`,"code.saving":`保存中…`,"code.download":`下载 html`,"code.status.idle":`静态 HTML · 可直接编辑`,"code.status.dirty":`有未保存的代码修改`,"code.status.saved":`代码已保存,画布与图文缩略图已更新`,"code.status.appliedUnsaved":`代码已应用到画布,但文档尚未保存成功`,"code.status.downloaded":`已下载 HTML 静态副本(不含可执行脚本)`,"code.err.empty":`代码不能为空`,"code.err.too-large":`代码超过60MB上限`,"code.err.no-slide":`请保留至少一个 .slide 图文区块`,"code.err.unsafe":`仅支持静态 HTML,不允许脚本、事件处理器或嵌入内容`,"code.err.rejected":`无法更新画布`,"image.upload":`从本地上传`,"image.inDocument":`文档中已有的图片`,"image.use":`使用这张图片`,"image.fromUrl":`图片链接`,"image.apply":`应用`,"image.loading":`加载中…`,"image.err.notImage":`不是图片文件`,"image.err.tooLarge":`图片超过 12 MB`,"image.err.fetch":`无法读取该地址(可能不允许其他网站读取)`,"crop.hint":`拖动调整图片位置`,"crop.fill":`填满容器`,"crop.whole":`完整显示`,"crop.done":`完成`}};function tf(e){let t=ef[e];return(e,n)=>{let r=t[e]??$d[e]??e;return n?r.replace(/\{(\w+)\}/g,(e,t)=>t in n?String(n[t]):e):r}}var nf=(0,v.createContext)({lang:`en`,t:tf(`en`)});function rf({lang:e,children:t}){let n=(0,v.useMemo)(()=>({lang:e,t:tf(e)}),[e]);return(0,v.createElement)(nf.Provider,{value:n},t)}var af=()=>(0,v.useContext)(nf).t,of=()=>(0,v.useContext)(nf).lang,sf={saveFailed:`notice.saveFailed`,editRejected:`notice.editRejected`,resetDone:`notice.resetDone`,resetUnavailable:`notice.resetUnavailable`,downloadDone:`notice.downloadDone`,downloadFailed:`notice.downloadFailed`,fontFailed:`notice.fontFailed`,imageFailed:`notice.imageFailed`,textOverflow:`notice.textOverflow`};function cf(e,t){let n=e(sf[t.key]);return t.detail?`${n}: ${t.detail}`:n}function lf(e,t){if(!t)return``;let n=`error.${t}`;return n in $d?e(n):t}var uf=e=>Math.max(0,Math.min(1,e)),df={left:0,top:0,center:.5,right:1,bottom:1};function ff(e){if(e===void 0)return .5;if(e in df)return df[e];if(e.endsWith(`%`)){let t=Number.parseFloat(e);if(Number.isFinite(t))return uf(t/100)}return .5}function pf(e){let t=(e??``).trim().toLowerCase().split(/\s+/).filter(Boolean);return t.length===1&&(t[0]===`top`||t[0]===`bottom`)?{x:.5,y:ff(t[0])}:{x:ff(t[0]),y:ff(t[1])}}var mf=e=>`${Math.round(e*1e3)/10}%`;function hf(e){return`${mf(e.x)} ${mf(e.y)}`}function gf(e,t,n){let r=t.width/e.width,i=t.height/e.height,a=n===`cover`?Math.max(r,i):Math.min(r,i);return{width:e.width*a,height:e.height*a}}function _f(e){let{natural:t,box:n,fit:r,start:i,dx:a,dy:o}=e;if(!(t.width>0&&t.height>0&&n.width>0&&n.height>0))return i;let s=gf(t,n,r),c=(e,t,n,r)=>{let i=n-r;return Math.abs(i)<.5?e:uf(e+t/i)};return{x:c(i.x,a,n.width,s.width),y:c(i.y,o,n.height,s.height)}}function vf(e){return e===`cover`||e===`contain`?e:null}var yf=class extends Error{reason;constructor(e){super(e),this.reason=e}};function bf(e){let t=new Set,n=[];for(let r of e.order){let i=e.elements.get(r);if(!i||i.tag.toLowerCase()!==`img`)continue;let a=Pi(i,`src`);!a||t.has(a)||(t.add(a),n.push({src:a,id:r}))}return n}function xf(e){return/^image\//i.test(e)}function Sf(e){if(!xf(e.type))throw new yf(`notImage`);if(e.size>12582912)throw new yf(`tooLarge`)}function Cf(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(new yf(`fetch`)),r.readAsDataURL(e)})}async function wf(e){return Sf(e),Cf(e)}function Tf(e){let t=e.trim();if(!t)return null;if(/^data:image\//i.test(t))return t;try{let e=new URL(/^[a-z][a-z0-9+.-]*:/i.test(t)?t:`https://${t}`);return e.protocol===`http:`||e.protocol===`https:`||e.protocol===`blob:`?e.href:null}catch{return null}}async function Ef(e,t=fetch){let n=Tf(e);if(!n)throw new yf(`fetch`);if(n.startsWith(`data:`))return n;let r;try{let e=await t(n);if(!e.ok)throw new yf(`fetch`);r=await e.blob()}catch(e){throw e instanceof yf?e:new yf(`fetch`)}return wf(r)}var Df=(0,v.createContext)(()=>void 0),Of=()=>(0,v.useContext)(Df),kf=3200;function Af({children:e}){let[t,n]=(0,v.useState)([]),r=(0,v.useRef)(1),i=(0,v.useRef)(new Set),a=(0,v.useCallback)((e,t=`info`)=>{let a=r.current++;n(n=>[...n.filter(t=>t.text!==e).slice(-3),{id:a,kind:t,text:e}]);let o=setTimeout(()=>{i.current.delete(o),n(e=>e.filter(e=>e.id!==a))},kf);i.current.add(o)},[]);(0,v.useEffect)(()=>{let e=i.current;return()=>e.forEach(clearTimeout)},[]);let o=(0,v.useMemo)(()=>a,[a]);return(0,Q.jsxs)(Df.Provider,{value:o,children:[e,(0,Q.jsx)(`div`,{className:`toasts`,role:`status`,"aria-live":`polite`,children:t.map(e=>(0,Q.jsx)(`div`,{className:`toast toast-${e.kind}`,children:e.text},e.id))})]})}var jf={notImage:`image.err.notImage`,tooLarge:`image.err.tooLarge`,fetch:`image.err.fetch`};function Mf(){let e=af(),t=Of();return(0,v.useCallback)(n=>{let r=n instanceof yf?e(jf[n.reason]):n instanceof Error?n.message:``;t(r?`${e(`notice.imageFailed`)}: ${r}`:e(`notice.imageFailed`),`error`)},[e,t])}function Nf(e,t,n){let r=e.index().elements.get(t);if(!r)return;let i=[{kind:`setAttr`,id:t,name:`src`,value:n}];Pi(r,`srcset`)!==null&&i.push({kind:`setAttr`,id:t,name:`srcset`,value:null}),e.applyBatch(i,`replace image`)}var Pf=(e,t)=>e.index().elements.get(t)?.tag.toLowerCase()===`img`;function Ff(e){let t=Mf();(0,v.useEffect)(()=>e.onFrameEvent(n=>{if(n.type!==`drop`||n.id===null||!Pf(e,n.id))return;let r=n.files.find(e=>xf(e.type));if(r){if(r.dataURL.length*3/4>12582912){t(new yf(`tooLarge`));return}Nf(e,n.id,r.dataURL),e.select([n.id])}}),[e,t])}function If({controller:e,id:t,onDone:n}){let r=af(),i=Mf(),a=(0,v.useRef)(null),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1),u=bf(e.index()),d=e.index().elements.get(t),f=d?Pi(d,`src`):null,p=async r=>{l(!0);try{Nf(e,t,await r()),n()}catch(e){i(e)}finally{l(!1)}};return(0,Q.jsxs)(`div`,{className:`image-picker`,children:[(0,Q.jsxs)(`button`,{type:`button`,id:`img-upload`,className:`btn wide`,disabled:c,onClick:()=>a.current?.click(),children:[(0,Q.jsx)($,{name:`upload`}),` `,r(`image.upload`)]}),(0,Q.jsx)(`input`,{ref:a,id:`img-file`,type:`file`,accept:`image/*`,hidden:!0,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&p(()=>wf(t))}}),u.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`swatch-title`,children:r(`image.inDocument`)}),(0,Q.jsx)(`div`,{className:`img-grid`,id:`img-doc-grid`,children:u.map(e=>(0,Q.jsx)(`button`,{type:`button`,className:`img-thumb${e.src===f?` current`:``}`,title:r(`image.use`),disabled:c||e.src===f,onClick:()=>void p(async()=>e.src),children:(0,Q.jsx)(`img`,{src:e.src,alt:``})},e.src))})]}),(0,Q.jsx)(`div`,{className:`swatch-title`,children:r(`image.fromUrl`)}),(0,Q.jsxs)(`form`,{className:`img-url`,onSubmit:e=>{e.preventDefault(),o.trim()&&p(()=>Ef(o))},children:[(0,Q.jsx)(`input`,{id:`img-url`,type:`text`,inputMode:`url`,placeholder:`https://…`,value:o,onChange:e=>s(e.target.value),"aria-label":r(`image.fromUrl`)}),(0,Q.jsx)(`button`,{type:`submit`,id:`img-url-apply`,className:`btn`,disabled:c||!o.trim(),children:r(c?`image.loading`:`image.apply`)})]})]})}function Lf({controller:e,snap:t,id:n,scale:r,onExit:i}){let a=af(),o=(0,v.useRef)(null),s=(0,v.useRef)(!1),c=t.rects[n],l=(0,v.useCallback)(()=>{s.current&&e.cancelLivePreview([n]),s.current=!1,o.current=null,i()},[e,n,i]);Md(!0,l);let u=t.selection.length===1&&t.selection[0]===n&&e.index().elements.has(n);if((0,v.useEffect)(()=>{u||i()},[u,i]),!c)return null;let d=e.styles(n,[`object-fit`,`object-position`]),f=vf(d[`object-fit`]),p={left:c.x*r,top:c.y*r,width:c.width*r,height:c.height*r},m=t=>e.apply({kind:`setStyle`,id:n,props:{"object-fit":t}},{label:`crop`}),h=e=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),e.currentTarget.setPointerCapture(e.pointerId),o.current={startX:e.clientX,startY:e.clientY,start:pf(d[`object-position`]),fit:f??`cover`,last:null})},g=t=>{let i=o.current,a=ud(n);!i||!a||(i.last=hf(_f({natural:a,box:{width:c.width,height:c.height},fit:i.fit,start:i.start,dx:(t.clientX-i.startX)/r,dy:(t.clientY-i.startY)/r})),s.current=!0,e.livePreview([{kind:`style`,id:n,props:{"object-position":i.last,"object-fit":i.fit}}]))},_=t=>{let r=o.current;o.current=null,s.current=!1,t.currentTarget.hasPointerCapture(t.pointerId)&&t.currentTarget.releasePointerCapture(t.pointerId),r?.last&&e.apply({kind:`setStyle`,id:n,props:{"object-position":r.last,"object-fit":r.fit}},{label:`crop`})},y=Math.max(4,Math.min(p.top+p.height+10,e.pageSize().height*r-44));return(0,Q.jsxs)(`div`,{className:`crop-layer`,"data-keepfocus":``,onPointerDown:e=>e.target===e.currentTarget&&l(),children:[(0,Q.jsx)(`div`,{id:`crop-box`,className:`crop-box`,style:p,onPointerDown:h,onPointerMove:g,onPointerUp:_,onPointerCancel:()=>l(),children:(0,Q.jsx)(`span`,{className:`crop-hint`,children:a(`crop.hint`)})}),(0,Q.jsxs)(`div`,{className:`crop-bar`,style:{left:p.left,top:y},role:`toolbar`,children:[(0,Q.jsx)(`button`,{type:`button`,id:`crop-fill`,className:`btn${f===`cover`?` on`:``}`,onClick:()=>m(`cover`),children:a(`crop.fill`)}),(0,Q.jsx)(`button`,{type:`button`,id:`crop-whole`,className:`btn${f===`contain`?` on`:``}`,onClick:()=>m(`contain`),children:a(`crop.whole`)}),(0,Q.jsx)(`button`,{type:`button`,id:`crop-done`,className:`btn primary`,onClick:l,children:a(`crop.done`)})]})]})}var Rf=[`font-weight`,`font-style`,`text-decoration-line`,`text-transform`,`text-align`,`font-size`,`font-family`,`color`,`line-height`,`letter-spacing`,`opacity`],zf=e=>{if(!e)return!1;if(e===`bold`||e===`bolder`)return!0;let t=Number.parseInt(e,10);return Number.isFinite(t)&&t>=600};function Bf(e,t){let n=(e[`text-decoration-line`]??``).split(/\s+/);return{bold:t?!!t.bold:zf(e[`font-weight`]),italic:t?!!t.italic:/^(italic|oblique)/.test(e[`font-style`]??``),underline:t?!!t.underline:n.includes(`underline`),strike:t?!!t.strike:n.includes(`line-through`),uppercase:e[`text-transform`]===`uppercase`}}function Vf(e){switch(e){case`center`:case`right`:case`justify`:return e;case`end`:return`right`;default:return`left`}}var Hf=e=>{let t=Number.parseFloat(e??``);return Number.isFinite(t)?t:NaN},Uf=e=>Number.isFinite(Hf(e[`font-size`]))?Hf(e[`font-size`]):0;function Wf(e){let t=e[`line-height`],n=Uf(e);if(!t||t===`normal`||n<=0)return 1.2;let r=Hf(t);return Number.isFinite(r)?t.endsWith(`px`)?Math.round(r/n*100)/100:r:1.2}function Gf(e){let t=e[`letter-spacing`],n=Uf(e);if(!t||t===`normal`||n<=0)return 0;let r=Hf(t);return Number.isFinite(r)?Math.round(r/n*1e3)/1e3:0}function Kf(e){let t=Hf(e.opacity);return Number.isFinite(t)?Math.max(0,Math.min(1,t)):1}function qf(e){return((e??``).split(`,`)[0]?.trim()??``).replace(/^["']|["']$/g,``)}var Jf=e=>Math.round(e*255).toString(16).padStart(2,`0`),Yf=e=>Math.min(1,Math.max(0,e)),Xf=(e,t,n)=>{let r=r=>{let i=(r+e/60)%6;return Jf(n-n*t*Math.max(0,Math.min(i,4-i,1)))};return`#${r(5)}${r(3)}${r(1)}`},Zf=e=>{let[t,n,r]=[1,3,5].map(t=>parseInt(e.slice(t,t+2),16)/255),i=Math.max(t,n,r),a=i-Math.min(t,n,r);return{h:((a?(i===t?(n-r)/a:i===n?2+(r-t)/a:4+(t-n)/a)*60:0)+360)%360,s:i?a/i:0,v:i}},Qf=[20,45,100,155,190,220,250,290,325,350].flatMap(e=>[.94,.7,.4,.18].map((t,n)=>Xf(e,t,[.76,.92,.99,1][n]??1)));function $f({color:e,onPick:t,disabled:n}){let r=_d(e.slice(0,7))??`#222222`,[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(null),[c,l]=(0,v.useState)(null),u=Zf(r),d=i??u.h,f=c??(e.length===9?parseInt(e.slice(7),16)/255:1),p=(e,n,r)=>t(n===1?e:`${e}${Jf(n)}`,r),m=(e,t)=>{if(n)return;let r=e.currentTarget.getBoundingClientRect();a(d),p(Xf(d,Yf((e.clientX-r.left)/r.width),1-Yf((e.clientY-r.top)/r.height)),f,t)};return(0,Q.jsxs)(`div`,{className:`color-picker`,children:[(0,Q.jsx)(`div`,{className:`color-field`,style:{backgroundColor:Xf(d,1,1)},onPointerDown:e=>{e.currentTarget.setPointerCapture(e.pointerId),m(e,`live`)},onPointerMove:e=>{e.currentTarget.hasPointerCapture(e.pointerId)&&m(e,`live`)},onPointerUp:e=>m(e,`commit`),children:(0,Q.jsx)(`i`,{style:{left:`${u.s*100}%`,top:`${(1-u.v)*100}%`,background:r}})}),(0,Q.jsx)(`input`,{className:`color-hue`,type:`range`,min:0,max:359,"aria-label":`Hue`,value:d,disabled:n,onChange:e=>{let t=Number(e.currentTarget.value);a(t),p(Xf(t,u.s||.8,u.v||1),f,`commit`)}}),(0,Q.jsx)(`input`,{className:`color-alpha`,type:`range`,min:0,max:100,"aria-label":`Opacity`,value:Math.round(f*100),disabled:n,style:{backgroundImage:`linear-gradient(90deg, transparent, ${r})`},onChange:e=>{let t=Number(e.currentTarget.value)/100;l(t),p(r,t,`commit`)}}),(0,Q.jsxs)(`div`,{className:`color-inputs`,children:[(0,Q.jsxs)(`label`,{children:[`HEX`,(0,Q.jsx)(`input`,{"aria-label":`HEX`,value:o??r.toUpperCase(),maxLength:7,disabled:n,onChange:e=>s(e.currentTarget.value),onBlur:()=>{if(o===null)return;let e=o.trim(),t=_d(e.startsWith(`#`)?e:`#${e}`);t&&(a(null),p(t,f,`commit`)),s(null)},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()}})]}),(0,Q.jsxs)(`span`,{children:[Math.round(f*100),`%`]})]})]})}function ep({docColors:e,current:t,allowNone:n,disabled:r,expanded:i=!1,onPick:a}){let o=af(),[s,c]=(0,v.useState)(i),[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(null),p=d??t??`#222222`,m=(e,t)=>{f(e),a(e,t)},h=e=>(0,Q.jsx)(`button`,{type:`button`,className:`swatch${e===`transparent`?` none`:``}${p===e?` current`:``}`,style:e===`transparent`?void 0:{background:e},title:e===`transparent`?o(`colors.none`):e,"aria-label":e===`transparent`?o(`colors.none`):e,"data-color":e,disabled:r,onClick:()=>m(e,`commit`)},e);return(0,Q.jsxs)(`div`,{className:`swatches`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`btn color-toggle`,disabled:r,"aria-expanded":s,onClick:()=>{f(null),c(!s)},children:o(`colors.custom`)}),s&&(0,Q.jsx)($f,{color:p===`transparent`?`#ffffff`:p,onPick:m,disabled:r}),e.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`swatch-title`,children:o(`colors.document`)}),(0,Q.jsx)(`div`,{className:`swatch-grid`,"data-swatches":`document`,children:e.map(h)})]}),(0,Q.jsx)(`div`,{className:`swatch-title`,children:o(`colors.presets`)}),(0,Q.jsxs)(`div`,{className:`swatch-grid`,"data-swatches":`presets`,children:[n&&h(`transparent`),fd.map(h),l&&Qf.map(h)]}),(0,Q.jsx)(`button`,{type:`button`,className:`btn color-toggle`,"aria-expanded":l,onClick:()=>u(!l),children:o(l?`colors.collapse`:`colors.expand`)})]})}function tp(e){return e.editingTextId?[e.editingTextId]:[...e.selection]}function np(e,t){return(0,v.useMemo)(()=>Sd(e.index().source),[e,t])}function rp(e,t,n){let r=tp(t)[0];return(0,v.useMemo)(()=>r===void 0?{}:e.styles(r,[...n]),[e,r,t.sourceVersion,t.rects,t.editingTextId,t.textState])}function ip(e,t,n){return(0,v.useMemo)(()=>t.map(t=>Wa(e.index(),t)),[e,t.join(`,`),n])}var ap=8;function op({open:e,anchor:t,onClose:n,id:r,className:i,children:a}){let o=(0,v.useRef)(null),[s,c]=(0,v.useState)(null);return Md(e,n),(0,v.useLayoutEffect)(()=>{if(!e){c(null);return}let n=t.current?.getBoundingClientRect(),r=o.current?.offsetWidth??0;n&&c({left:Math.max(ap,Math.min(n.left,window.innerWidth-r-ap)),top:n.bottom+6})},[e,t]),e?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`menu-scrim`,"data-keepfocus":``,onMouseDown:n}),(0,Q.jsx)(`div`,{ref:o,id:r,className:`popover pop-fixed${i?` ${i}`:``}`,style:s??{left:-9999,top:0},role:`dialog`,children:a})]}):null}function sp(e){return(0,v.useSyncExternalStore)(e.subscribe,e.getSnapshot)}var cp=[{id:`left`,icon:`alignLeft`,label:`toolbar.alignLeft`},{id:`center`,icon:`alignCenter`,label:`toolbar.alignCenter`},{id:`right`,icon:`alignRight`,label:`toolbar.alignRight`},{id:`justify`,icon:`alignJustify`,label:`toolbar.alignJustify`}],lp=`__doc-font`,up=1,dp=999;function fp({id:e,label:t,min:n,max:r,step:i,value:a,format:o,onChange:s}){return(0,Q.jsxs)(`label`,{className:`slider-row`,children:[(0,Q.jsx)(`span`,{className:`slider-label`,children:t}),(0,Q.jsx)(`input`,{id:e,type:`range`,min:n,max:r,step:i,value:a,onChange:e=>s(Number(e.target.value))}),(0,Q.jsx)(`output`,{children:o(a)})]})}function pp({controller:e,actions:t,onOpenBlock:n,crop:r}){let i=af(),a=sp(e),o=tp(a),s=a.docState===`ready`&&o.length>0,c=ip(e,o,a.sourceVersion),l=s&&(a.editingTextId!==null||c.some(e=>e===`text`||e===`box`)),u=a.docState===`ready`&&a.selection.length===1&&a.selection[0]!==void 0&&Pf(e,a.selection[0])?a.selection[0]:null,d=rp(e,a,Rf),f=Bf(d,a.editingTextId?a.textState?.active:null),p=Uf(d),m=Vf(d[`text-align`]),h=_d(d.color)??`#000000`,g=np(e,a.sourceVersion),_=a.editingTextId!==null&&a.textState?.range===!0,[y,b]=(0,v.useState)(null),x=()=>b(null),S=(0,v.useRef)(null),C=(0,v.useRef)(null),w=(0,v.useRef)(null),T=(0,v.useRef)(null),ee=o.join(`,`);(0,v.useEffect)(()=>b(null),[ee]);let[E,D]=(0,v.useState)(null),[O,te]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let t=!0;return e.fontPalette().then(e=>t&&D(e.roles),()=>t&&te(!0)),()=>{t=!1}},[e]);let k=(0,v.useMemo)(()=>E?dc(E):[],[E]),A=qf(d[`font-family`]),ne=E?.some(e=>e.family===A)??!1,re=!s||A===``?``:ne?A:lp,ie=(t,n,r)=>{let i=o.map(e=>({kind:`setStyle`,id:e,props:t}));e.applyBatch(i,n,r?{coalesceKey:`${r}:${ee}`}:void 0)},j=(t,n)=>{_&&n===`live`||(e.format({command:`color`,value:t}),n===`commit`&&x())},M=t=>{Number.isFinite(t)&&e.format({command:`fontSize`,value:`${Math.max(up,Math.min(dp,Math.round(t)))}px`})},ae=t=>{let n=a.editingTextId;ie({"text-align":t},`align`),n&&e.beginTextEdit(n,`end`)},[oe,N]=(0,v.useState)(!1),[P,F]=(0,v.useState)(null),I=P??(p>0?String(Math.round(p*10)/10):``),L=(e,t,n,r)=>(0,Q.jsx)(`button`,{ref:r.ref,type:`button`,id:e,className:`tb-btn small fmt${r.on?` on`:``}`,title:t,"aria-label":t,"aria-pressed":r.on===void 0?void 0:r.on,disabled:r.disabled??!s,onClick:r.onClick,children:n}),R=t=>()=>e.format({command:t});return(0,Q.jsxs)(`div`,{className:`fmt-row`,"data-has-target":s?`1`:`0`,children:[(0,Q.jsxs)(`select`,{id:`tb-font`,className:`fmt-font`,title:i(`toolbar.font`),"aria-label":i(`toolbar.font`),disabled:!l||!E||oe,value:re,onChange:t=>{let n=E?.find(e=>e.family===t.target.value);n&&(N(!0),e.applyFont(n.id,o).then(()=>dd(n.family)).finally(()=>N(!1)))},children:[!E&&(0,Q.jsx)(`option`,{value:``,children:i(O?`toolbar.fontsFailed`:`toolbar.fontsLoading`)}),E&&re===``&&(0,Q.jsx)(`option`,{value:``,disabled:!0,children:i(`toolbar.font`)}),E&&re===lp&&(0,Q.jsx)(`option`,{value:lp,disabled:!0,children:i(`toolbar.fontMissing`,{name:A})}),k.map(e=>(0,Q.jsx)(`optgroup`,{label:e.label,children:e.options.map(e=>(0,Q.jsx)(`option`,{value:e.value,title:e.title,"data-font-id":e.fontId,children:e.label},e.fontId))},e.label))]}),(0,Q.jsxs)(`span`,{className:`fmt-size`,children:[L(`tb-size-dec`,i(`toolbar.sizeDown`),`−`,{disabled:!l,onClick:()=>M((p||16)-1)}),(0,Q.jsx)(`input`,{id:`tb-size`,type:`number`,min:up,max:dp,step:1,inputMode:`numeric`,title:i(`toolbar.size`),"aria-label":i(`toolbar.size`),disabled:!l,value:I,onChange:e=>F(e.target.value),onBlur:()=>F(null),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),M(Number(P??I)),F(null))}}),L(`tb-size-inc`,i(`toolbar.sizeUp`),`+`,{disabled:!l,onClick:()=>M((p||16)+1)})]}),(0,Q.jsx)(`span`,{className:`tb-sep`}),L(`tb-bold`,i(`toolbar.bold`),(0,Q.jsx)(`b`,{children:`B`}),{on:f.bold,disabled:!l,onClick:R(`bold`)}),L(`tb-italic`,i(`toolbar.italic`),(0,Q.jsx)(`i`,{children:`I`}),{on:f.italic,disabled:!l,onClick:R(`italic`)}),L(`tb-underline`,i(`toolbar.underline`),(0,Q.jsx)(`u`,{children:`U`}),{on:f.underline,disabled:!l,onClick:R(`underline`)}),L(`tb-strike`,i(`toolbar.strike`),(0,Q.jsx)(`s`,{children:`S`}),{on:f.strike,disabled:!l,onClick:R(`strike`)}),L(`tb-color`,i(`toolbar.color`),(0,Q.jsxs)(`span`,{className:`color-glyph`,children:[`A`,(0,Q.jsx)(`i`,{style:{background:h}})]}),{ref:S,disabled:!l,on:y===`color`,onClick:()=>b(y===`color`?null:`color`)}),(0,Q.jsx)(op,{open:y===`color`,anchor:S,onClose:x,id:`pop-color`,className:`pop-colors`,children:(0,Q.jsx)(ep,{docColors:g,current:h,onPick:j})}),(0,Q.jsx)(`span`,{className:`tb-sep`}),cp.map(e=>(0,Q.jsx)(v.Fragment,{children:L(`tb-align-${e.id}`,i(e.label),(0,Q.jsx)($,{name:e.icon}),{on:l&&m===e.id,disabled:!l,onClick:()=>ae(e.id)})},e.id)),L(`tb-spacing`,i(`toolbar.spacing`),(0,Q.jsx)($,{name:`spacing`}),{ref:C,disabled:!l,on:y===`spacing`,onClick:()=>b(y===`spacing`?null:`spacing`)}),(0,Q.jsxs)(op,{open:y===`spacing`,anchor:C,onClose:x,id:`pop-spacing`,children:[(0,Q.jsx)(fp,{id:`tb-line-height`,label:i(`toolbar.lineHeight`),min:.8,max:3,step:.05,value:Wf(d),format:e=>e.toFixed(2),onChange:e=>ie({"line-height":String(Math.round(e*100)/100)},`line-height`,`lh`)}),(0,Q.jsx)(fp,{id:`tb-letter-spacing`,label:i(`toolbar.letterSpacing`),min:-.1,max:.5,step:.005,value:Gf(d),format:e=>`${Math.round(e*1e3)}‰`,onChange:e=>ie({"letter-spacing":`${Math.round(e*1e3)/1e3}em`},`letter-spacing`,`ls`)})]}),L(`tb-uppercase`,i(`toolbar.uppercase`),(0,Q.jsx)(`span`,{className:`aa`,children:`aA`}),{on:f.uppercase,disabled:!l,onClick:R(`uppercase`)}),L(`tb-opacity`,i(`toolbar.opacity`),(0,Q.jsx)($,{name:`opacity`}),{ref:w,on:y===`opacity`,onClick:()=>b(y===`opacity`?null:`opacity`)}),(0,Q.jsx)(op,{open:y===`opacity`,anchor:w,onClose:x,id:`pop-opacity`,children:(0,Q.jsx)(fp,{id:`tb-opacity-range`,label:i(`toolbar.opacity`),min:0,max:100,step:1,value:Math.round(Kf(d)*100),format:e=>`${e}%`,onChange:e=>ie({opacity:e>=100?null:String(e/100)},`opacity`,`opacity`)})}),L(`tb-clear`,i(`toolbar.clear`),(0,Q.jsx)($,{name:`eraser`}),{disabled:!l,onClick:R(`clear`)}),(0,Q.jsx)(`span`,{className:`tb-sep`}),L(`tb-copy-style`,i(`toolbar.copyStyle`),(0,Q.jsx)($,{name:`brush`}),{disabled:!l,onClick:t.copyStyle}),L(`tb-paste-style`,i(`toolbar.pasteStyle`),(0,Q.jsx)($,{name:`paste`}),{disabled:!l,onClick:t.pasteStyle}),u!==null&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`tb-sep`}),(0,Q.jsxs)(`button`,{ref:T,type:`button`,id:`tb-replace`,className:`tb-btn small fmt wide${y===`image`?` on`:``}`,title:i(`toolbar.replaceImage`),onClick:()=>b(y===`image`?null:`image`),children:[(0,Q.jsx)($,{name:`replace`}),` `,(0,Q.jsx)(`span`,{className:`fmt-text`,children:i(`toolbar.replaceImage`)})]}),(0,Q.jsx)(op,{open:y===`image`,anchor:T,onClose:x,id:`pop-image`,className:`pop-image`,children:(0,Q.jsx)(If,{controller:e,id:u,onDone:x})}),(0,Q.jsxs)(`button`,{type:`button`,id:`tb-crop`,className:`tb-btn small fmt wide${r.id===u?` on`:``}`,title:i(`toolbar.crop`),onClick:()=>r.setId(r.id===u?null:u),children:[(0,Q.jsx)($,{name:`crop`}),` `,(0,Q.jsx)(`span`,{className:`fmt-text`,children:i(`toolbar.crop`)})]})]}),(0,Q.jsx)(`span`,{className:`fmt-spacer`}),(0,Q.jsxs)(`button`,{type:`button`,id:`tb-block`,className:`tb-btn small fmt wide`,disabled:!s,title:i(`toolbar.block`),onClick:n,children:[(0,Q.jsx)($,{name:`block`}),` `,(0,Q.jsx)(`span`,{className:`fmt-text`,children:i(`toolbar.block`)})]})]})}var mp=112,hp=84,gp=450,_p=`${vo}
43
+ `),o=gc(n,r.family,a),s=await this.store.fontCSS(o.needed.map(e=>e.id),{rev:this.rev});this.rev=s.rev;let c=o.needed.map(e=>{let t=s.css[e.id];if(t===void 0)throw Error(`Missing font CSS: ${e.id}`);return{kind:`upsertFontStyle`,key:e.id,css:t}});for(let e of i.filter(e=>this.idx.elements.has(e)))c.push({kind:`setStyle`,id:e,props:{"font-family":o.stack}});this.runOps(c,`font`)}catch(e){this.notify(`error`,`fontFailed`,Hu(e))}}};dispose(){this.disposed=!0,this.mountToken++,this.mounted=!1,this.frameOff?.(),this.frameOff=null,this.listeners.clear(),this.noticeListeners.clear(),this.frameListeners.clear(),this.frame.dispose()}};function Ju(e,t){let n=()=>{let n=e.getSnapshot(),r={"data-doc-state":n.docState,"data-doc-path":n.path,"data-doc-seq":String(n.sourceVersion),"data-slide-count":String(n.pages.length)};for(let[e,n]of Object.entries(r))t.getAttribute(e)!==n&&t.setAttribute(e,n)};return n(),e.subscribe(n)}var Yu=`popost-canvas:lang`,Xu=`gs9_editor_lang`,Zu=`/pages/`;function Qu(e,t,n){return t?Zu:e.store===`host`?`${n}/`:void 0}function $u(e){try{return localStorage.getItem(e)}catch{return null}}function ed(e,t){try{localStorage.setItem(e,t)}catch{}}var td=e=>e===`en`||e===`zh`?e:null;function nd(){try{return navigator.languages?.length?navigator.languages:[navigator.language]}catch{return[]}}function rd(e=nd()){return(e.find(Boolean)??``).toLowerCase().startsWith(`zh`)?`zh`:`en`}function id(e,t){let n=td(new URLSearchParams(e).get(`lang`));return n?(ed(Yu,n),n):td($u(`popost-canvas:lang`))??td($u(Xu))??rd(t)}function ad(e,t){return`${t?`• `:``}${e||`Popost`}`}function od(){let e=hs(),t=id(e),n={...gs(e),lang:t},r=xs(),i=r?vl(r):n.store===`host`?Uc(n):Bc(n),a=Qu(n,r,window.location.origin),o=Ku({store:i,frame:os({store:i,baseHref:a,imageOrigins:r?[]:_s(e,n.store)}),params:n});document.documentElement.lang=t===`en`?`en`:`zh-CN`;let s=ms(n),c=n.store===`host`&&!r?ds(Pc(n.file),()=>void o.externalChange()):()=>{},l=Ju(o,document.body),u=()=>{let e=o.getSnapshot(),t=ad(e.name,e.saveState!==`saved`);document.title!==t&&(document.title=t)};u();let d=o.subscribe(u),f=e=>{o.getSnapshot().saveState!==`saved`&&(e.preventDefault(),e.returnValue=``)};return window.addEventListener(`beforeunload`,f),o.start(),{controller:o,params:n,local:r,lang:t,baseHref:a,dispose(){window.removeEventListener(`beforeunload`,f),d(),l(),s(),c(),o.dispose()}}}var sd=()=>{let e=ys();return new URLSearchParams(hs()).get(`tools`)===`1`&&e.store===`host`&&ss()&&Pc(e.file)||null},cd=(e,t,n)=>{let r=sd();return r?Ps(r,e,{content:t},n):Promise.reject(Error(`Project host unavailable`))};function ld(e){let t=document.getElementById(`frame`)?.contentDocument;return t?t.querySelector(`[${Ya}="${e.replace(/["\\]/g,`\\$&`)}"]`):null}function ud(e){let t=ld(e);if(t?.tagName!==`IMG`)return null;let n=t;return n.naturalWidth>0&&n.naturalHeight>0?{width:n.naturalWidth,height:n.naturalHeight}:null}async function dd(e,t=8e3){let n=document.getElementById(`frame`),r=n?.contentWindow,i=n?.contentDocument;!r||!i?.fonts||await Promise.race([(async()=>{if(await new Promise(e=>r.requestAnimationFrame(()=>e())),await i.fonts?.ready,!e)return;let t=[...i.fonts].filter(t=>t.family.replace(/^["']|["']$/g,``)===e);await Promise.all(t.map(e=>e.load().catch(()=>void 0)))})().catch(()=>void 0),new Promise(e=>setTimeout(e,t))])}var fd=`#000000.#333333.#666666.#999999.#cccccc.#eeeeee.#ffffff.#d64545.#ff7a1a.#f5b700.#ffd966.#8bc34a.#2e9e6b.#00a99d.#1e88e5.#3949ab.#7e57c2.#e8369a.#8d6e63.#37474f.#b71c1c.#ffcdd2.#ffe0b2.#fff9c4.#c8e6c9.#b3e5fc.#d1c4e9.#f8bbd0`.split(`.`),pd=/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i,md=/^rgba?\(\s*(\d{1,3})(?:\s*,\s*|\s+)(\d{1,3})(?:\s*,\s*|\s+)(\d{1,3})(?:\s*(?:,|\/)\s*([\d.]+%?))?\s*\)$/i;function hd(e){if(!e||e===`transparent`)return!0;let t=md.exec(e)?.[4]??/\/\s*([\d.]+%?)\s*\)$/.exec(e)?.[1];return t!==void 0&&Number.parseFloat(t)===0}var gd=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,`0`);function _d(e){let t=(e??``).trim(),n=pd.exec(t);if(n){let e=n[1].toLowerCase();return e.length===3?`#${e[0]}${e[0]}${e[1]}${e[1]}${e[2]}${e[2]}`:e.length===8?e.slice(6)===`ff`?`#${e.slice(0,6)}`:null:`#${e}`}let r=md.exec(t);if(r){let e=r[4];return e!==void 0&&!((e.endsWith(`%`)?Number.parseFloat(e)/100:Number.parseFloat(e))>=1)?null:`#${gd(Number(r[1]))}${gd(Number(r[2]))}${gd(Number(r[3]))}`}return null}var vd=/\sstyle\s*=\s*(?:"([^"]*)"|'([^']*)')/gi,yd=/<style\b([^>]*)>([\s\S]*?)<\/style>/gi,bd=/#(?:[0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{3})(?![0-9a-z_-])|rgba?\([^)]*\)/gi,xd=/data:[^"')\s]{64,}/gi;function Sd(e,t=14){let n=new Map,r=e=>{for(let t of e.replace(xd,``).matchAll(bd)){let e=_d(t[0]);e&&n.set(e,(n.get(e)??0)+1)}};for(let t of e.matchAll(vd))r(t[1]??t[2]);for(let t of e.matchAll(yd))/data-popost-font/i.test(t[1])||r(t[2]);return[...n.entries()].map(([e,t],n)=>({hex:e,n:t,at:n})).sort((e,t)=>t.n-e.n||e.at-t.at).slice(0,t).map(e=>e.hex)}function Cd(e,t){e.apply(Ca(t),{label:`duplicate page`});let n=e.getSnapshot().pages,r=n[n.findIndex(e=>e.id===t)+1];r&&e.setCurrentPage(r.id)}function wd(e,t){let n=wa(e.index(),t);return n?(e.apply(n,{label:`delete page`}),!0):!1}function Td(e,t,n){let r=Ta(e.index(),t,n);r&&e.apply(r,{label:`move page`})}var Ed=(e,t)=>t>e?t-1:t;function Dd(e){let t=e.getSnapshot().pages,n=t[0],r=t.at(-1);if(!n||!r)return;let i=e.index().elements.get(r.id)?.parent;if(!i)return;let a=ld(n.id),o=a?.ownerDocument.defaultView?.getComputedStyle(a),s=document.createElement(`div`);s.className=`slide`;let c=xa();s.dataset.popostPage=c,s.dataset.popostWidth=String(n.width),s.dataset.popostHeight=String(n.height);let l=o?.backgroundColor;s.style.cssText=`width:${n.width}px;height:${n.height}px;position:relative;overflow:hidden;background-image:none`,s.style.backgroundColor=l&&!hd(l)?l:`#fff`;let u=e.index().elements.get(i)?.children??[];e.apply({kind:`insertHTML`,parentId:i,beforeId:u[u.indexOf(r.id)+1]??null,html:s.outerHTML},{label:`add page`});let d=e.getSnapshot().pages.find(e=>e.pageKey===c);d&&e.setCurrentPage(d.id)}var Od=[];function kd(e){return Od.push(e),()=>{let t=Od.lastIndexOf(e);t>=0&&Od.splice(t,1)}}function Ad(){let e=Od.pop();return e?(e(),!0):!1}var jd=()=>Od.length>0;function Md(e,t){let n=(0,v.useRef)(t);n.current=t,(0,v.useEffect)(()=>{if(e)return kd(()=>n.current())},[e])}function Nd(e,t,n){for(let r=e.elements.get(t)?.parent??null;r!==null;r=e.elements.get(r)?.parent??null)if(r===n)return!0;return!1}function Pd(e,t){let n=t.filter(t=>e.elements.has(t));return n.filter(t=>!n.some(n=>n!==t&&Nd(e,t,n)))}function Fd(e,t,n){let r=e.elements.get(t)?.parent;if(!r)return null;let i=e.elements.get(r)?.children??[],a=i.indexOf(t);if(a<0)return null;if(n===`up`){let e=i[a-1];return e===void 0?null:{kind:`move`,id:t,parentId:r,beforeId:e}}return a>=i.length-1?null:{kind:`move`,id:t,parentId:r,beforeId:i[a+2]??null}}var Id=[`color`,`font-family`,`font-size`,`font-weight`,`font-style`,`text-decoration-line`,`text-transform`,`text-align`,`line-height`,`letter-spacing`,`opacity`];function Ld(e){let t={};for(let n of Id){let r=e[n];r!==void 0&&r.trim()!==``&&(t[n]=r.trim())}return t}function Rd(e,t){return Object.keys(t).length===0?[]:e.map(e=>({kind:`setStyle`,id:e,props:{...t}}))}var zd=/^(-?\d*\.?\d+)(?:px)?$/,Bd=e=>{let t=zd.exec((e??``).trim());return t?Number(t[1]):null};function Vd(e){let t=(e??``).trim();if(t===``||t===`none`)return{x:0,y:0};let n=t.split(/\s+/);if(n.length>3)return null;let r=n.map(Bd);return r.some(e=>e===null)?null:{x:r[0],y:r[1]??0}}var Hd=[`position`,`left`,`top`,`translate`];function Ud(e){let t=e.position;if(t===`absolute`||t===`fixed`){let t=Bd(e.left),n=Bd(e.top);if(t!==null&&n!==null)return{mode:`abs`,left:t,top:n}}let n=Vd(e.translate)??{x:0,y:0};return{mode:`flow`,x:n.x,y:n.y}}var Wd=e=>Math.round(e),Gd=e=>`${Wd(e)}px`;function Kd(e,t,n){return e.mode===`abs`?{left:Gd(e.left+t),top:Gd(e.top+n)}:{translate:`${Gd(e.x+t)} ${Gd(e.y+n)}`}}var qd=e=>e.length===2,Jd=e=>e===`image`||e===`svg`||e===`video`;function Yd(e){let{handle:t,kind:n,start:r,dx:i,dy:a}=e,o=t.includes(`w`),s=t.startsWith(`n`),c=Math.max(1,r.width),l=Math.max(1,r.height),u=Math.max(8,c+(o?-i:i)),d=l,f={},p=null;return qd(t)?n===`text`?(p=u/c,d=l*p):d=Jd(n)?u*l/c:Math.max(8,l+(s?-a:a)):Jd(n)&&(d=u*l/c),u=Wd(u),f.width=Gd(u-e.extra.width),(Jd(n)||qd(t)&&n===`box`)&&(d=Wd(d),f.height=Gd(d-e.extra.height)),p!==null&&(f[`font-size`]=`${Math.max(4,Math.round(e.fontSize*p*2)/2)}px`),{props:f,shift:{x:o?c-u:0,y:s?l-d:0},width:u,height:Wd(d)}}function Xd(e){let{controller:t,gestures:n,zoom:r,toast:i,t:a}=e,o=()=>Pd(t.index(),t.getSnapshot().selection),s=()=>{let e=o();e.length&&t.applyBatch(e.map(e=>({kind:`duplicate`,id:e})),`duplicate`)},c=()=>{let e=o();e.length!==0&&(t.applyBatch(e.map(e=>({kind:`remove`,id:e})),`delete`),i(a(`toast.deleted`)))},l=e=>{let{selection:n}=t.getSnapshot(),r=n[0];if(n.length!==1||r===void 0)return;let i=Fd(t.index(),r,e);i&&t.apply(i,{label:`reorder`})},u=(e,n)=>{let r=o();if(r.length===0)return;let i=r.map(r=>({kind:`setStyle`,id:r,props:Kd(Ud(t.styles(r,Hd)),e,n)}));t.applyBatch(i,`nudge`,{coalesceKey:`nudge:${r.join(`,`)}`})},d=e=>{let n=o()[0];if(!n||o().length!==1)return!1;let r=Wa(t.index(),n);if(r!==`image`&&r!==`svg`&&r!==`video`)return!1;let i=t.styles(n,[`width`,`height`]),a=t.getSnapshot().rects[n],s=Number.parseFloat(i.width)||a?.width,c=Number.parseFloat(i.height)||a?.height;if(!s||!c)return!1;let l=e===1?1.1:1/1.1;return t.applyBatch([{kind:`setStyle`,id:n,props:{width:`${Math.max(8,Math.round(s*l))}px`,height:`${Math.max(8,Math.round(c*l))}px`}}],`resize`,{coalesceKey:`keyboard-resize:${n}`}),!0},f=()=>{let e=t.getSnapshot();return e.editingTextId?[e.editingTextId]:[...e.selection]},p=null,m=()=>{let e=f()[0];e!==void 0&&(p=Ld(t.styles(e,[...Id])),i(a(`toast.styleCopied`)))},h=()=>{if(!p){i(a(`toast.styleNothing`));return}let e=f();e.length!==0&&(t.applyBatch(Rd(e,p),`paste style`),i(a(`toast.stylePasted`)))},g=e=>{let{pages:n,currentPageId:r}=t.getSnapshot(),i=n[n.findIndex(e=>e.id===r)+(e===`next`?1:-1)];i&&t.setCurrentPage(i.id)},_=()=>{if(n.cancel()||Ad())return;let e=t.getSnapshot();e.editingTextId?t.endTextEdit(!0):e.selection.length&&t.select([])};return{run:e=>{let i=t.getSnapshot();switch(e.type){case`save`:return t.save(),!0;case`undo`:return n.cancel(),t.undo(),!0;case`redo`:return n.cancel(),t.redo(),!0;case`zoom`:return e.mode===`fit`?r.fit():r.step(e.mode===`in`?1:-1),!0;case`scaleSelection`:return d(e.direction);case`duplicate`:return s(),!0;case`delete`:return c(),!0;case`edit`:{let e=i.selection[0];return e===void 0||Wa(t.index(),e)!==`text`?!1:(t.beginTextEdit(e,`end`),!0)}case`escape`:return _(),!0;case`nudge`:return u(e.dx,e.dy),!0;case`reorder`:return l(e.direction),!0;case`page`:return g(e.direction),!0;case`copyStyle`:return f().length!==0&&(m(),!0);case`pasteStyle`:return f().length!==0&&(h(),!0)}},duplicateSelection:s,deleteSelection:c,reorderSelection:l,nudgeSelection:u,copyStyle:m,pasteStyle:h,changePage:g,escape:_}}var Zd=o((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),Q=o(((e,t)=>{t.exports=Zd()}))(),Qd={undo:`M6 4 3 7l3 3M3 7h6.5a3.5 3.5 0 0 1 0 7H7`,redo:`m10 4 3 3-3 3M13 7H6.5a3.5 3.5 0 0 0 0 7H9`,reset:`M3 8a5 5 0 1 0 1.6-3.7M3 2.5v3h3`,save:`M3 3h8l2 2v8H3zM5.5 3v3.5h5V3M5.5 13V9.5h5V13`,export:`M8 2v8M5 7l3 3 3-3M3 12.5h10`,download:`M8 2v7.5M5 7l3 3 3-3M2.5 13.5h11`,chevron:`m4 6 4 4 4-4`,close:`m4 4 8 8M12 4l-8 8`,prev:`m10 3-5 5 5 5`,next:`m6 3 5 5-5 5`,grip:`M6 4v.01M10 4v.01M6 8v.01M10 8v.01M6 12v.01M10 12v.01`,parent:`M3 6V3h3M13 6V3h-3M3 10v3h3M13 10v3h-3M6 6h4v4H6z`,duplicate:`M5.5 5.5h7v7h-7zM3.5 10.5v-7h7`,trash:`M3 4.5h10M6.5 4.5V3h3v1.5M4.5 4.5l.6 8.5h5.8l.6-8.5M7 7v4M9 7v4`,forward:`M8 3v8M4.5 7.5 8 11l3.5-3.5M3 13.5h10`,backward:`M8 13V5M4.5 8.5 8 5l3.5 3.5M3 2.5h10`,text:`M3.5 4V3h9v1M8 3v10M6 13h4`,block:`M3 3h10v10H3zM3 7h10`,layers:`m8 2.5 5.5 3L8 8.5l-5.5-3zM2.5 8.5 8 11.5l5.5-3M2.5 11 8 14l5.5-3`,code:`m5.5 4.5-3.5 3.5 3.5 3.5M10.5 4.5 14 8l-3.5 3.5`,warn:`M8 3 14 13H2zM8 7v3M8 11.5v.01`,alignLeft:`M3 4h10M3 7h6M3 10h10M3 13h6`,alignCenter:`M3 4h10M5 7h6M3 10h10M5 13h6`,alignRight:`M3 4h10M7 7h6M3 10h10M7 13h6`,alignJustify:`M3 4h10M3 7h10M3 10h10M3 13h10`,spacing:`M3 3v10M13 3v10M5.5 8h5M7.5 6 5.5 8l2 2M8.5 6l2 2-2 2`,eraser:`m9 3 4 4-5.5 5.5H5L3 10.5zM6 6l4 4M8 12.5h5`,opacity:`M8 2.5s4 4.2 4 7.2a4 4 0 0 1-8 0c0-3 4-7.2 4-7.2z`,image:`M2.5 3.5h11v9h-11zM2.5 11l3.5-3.5 3 3 2-2 2.5 2.5M10.5 6v.01`,compare:`M2 3h5v10H2zM9 3h5v10H9z`,crop:`M4.5 2v9.5H14M2 4.5h9.5V14`,replace:`M3 6h8.5M9 3.5 11.5 6 9 8.5M13 10H4.5M7 7.5 4.5 10 7 12.5`,pencil:`M3 10.5 10.5 3a1.8 1.8 0 0 1 2.5 2.5L5.5 13H3zM9.5 4l2.5 2.5`,brush:`M3 13c1.5 0 2.5-.5 2.5-2 0-1 .5-1.5 1.5-1.5L12.5 4a1.4 1.4 0 0 0-2-2L5 7.5c-.5.5-1 1-1 2C4 11 3 11.5 3 13z`,paste:`M5.5 3h5v2h-5zM4 4h8v9.5H4zM6.5 8h3M6.5 10.5h3`,shape:`M8 2.5 13.5 12.5h-11z`,play:`M5.5 3.5v9l7-4.5z`,minus:`M3 8h10`,gem:`M2 5.5 4.7 2.8h6.6L14 5.5 8 13.2 2 5.5zM2 5.5h12M4.7 2.8l1.2 2.7L8 13.2l2.1-7.7 1.2-2.7`,wrap:`M2 4h12M2 7.5h9a2.2 2.2 0 0 1 0 4.4H6m2-2-2 2 2 2M2 11h1`,plus:`M8 3v10M3 8h10`,cloud:`M4.5 12.5a3 3 0 0 1-.5-5.9A4.2 4.2 0 0 1 12 7a2.8 2.8 0 0 1-.2 5.5z`,upload:`M8 10V2.5M5 5.5 8 2.5l3 3M3 9v4.5h10V9`,check:`m3.5 8.5 3 3 6-7`};function $({name:e,size:t=16}){return(0,Q.jsx)(`svg`,{className:`icon`,width:t,height:t,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,Q.jsx)(`path`,{d:Qd[e]})})}var $d={"compare.open":`Compare reference`,"compare.close":`Hide comparison`,"compare.openHint":`Click to compare with the reference`,"compare.closeHint":`Click to hide the comparison`,"compare.reference":`Reference`,"compare.result":`Your design`,"compare.page":`Page {n}`,"compare.empty":`No reference for this page`,"compare.emptyHint":`References follow their original page order`,"compare.loading":`Loading reference…`,"compare.failed":`Could not load references`,"compare.retry":`Retry`,"compare.readonly":`Original · Read only`,"compare.editable":`Editable canvas`,"compare.imageFailed":`Reference image unavailable`,"assets.confirm":`Confirm`,"code.disableWrap":`Turn off wrap`,"code.enableWrap":`Wrap lines`,"code.copy":`Copy`,"code.status.copied":`Full code copied`,"code.status.copyFailed":`Copy failed. Check your browser clipboard permissions.`,"export.pages":`Select pages · {n}/{total}`,"export.all":`Export all`,"export.format":`File format`,"export.resolution":`Resolution`,"export.name":`File name`,"export.editName":`Edit file name`,"export.confirmName":`Confirm file name`,"export.imageFormats":`Image formats`,"export.documentFormats":`Document formats`,"export.standard":`Standard`,"export.high":`High resolution`,"export.paid":`Paid feature`,"export.upgrade":`This feature is available with a paid plan.`,"export.pricing":`Unlock`,"export.progress":`Exporting… {percent}% ({done}/{total})`,"export.done":`ZIP exported`,"export.failed":`Export failed. Try again.`,"history.draftRestored":`Restored to the editor. Save to keep your changes.`,"history.draftFailed":`Could not restore this revision. Try again.`,"zoom.in":`Zoom in`,"zoom.out":`Zoom out`,"panel.add":`Add`,"panel.images":`Add image`,"design.size":`Size`,"design.background":`Background`,"design.cancel":`Cancel`,"design.apply":`Apply`,"add.text":`Add text`,"add.page":`Add page`,"assets.current":`This project`,"assets.history":`Asset history`,"assets.projectHistory":`Project asset history`,"assets.upload":`Upload`,"assets.empty":`No images yet`,"assets.more":`Load more`,"assets.failed":`Could not load images. Try again.`,"colors.expand":`More colors`,"colors.collapse":`Fewer colors`,"topbar.undo":`Undo (Ctrl+Z)`,"topbar.redo":`Redo (Ctrl+Shift+Z)`,"topbar.resetLayout":`Reset to initial layout`,"topbar.save":`Save`,"topbar.saveTitle":`Save (Ctrl+S)`,"topbar.export":`Export`,"topbar.exportHtml":`Save as HTML`,"topbar.downloadImages":`Download all`,"topbar.downloadImagesBusy":`Downloading…`,"save.saved":`All changes saved`,"save.dirty":`Unsaved changes`,"save.saving":`Saving…`,"save.error":`Save failed`,"cloud.save":`Save to Cloud`,"cloud.tooltip":`Manage all your assets on the Popost website`,"cloud.waiting":`Waiting for login…`,"cloud.copyLink":`Copy link`,"cloud.linkCopied":`Link copied`,"cloud.loginLink":`Login link`,"cloud.uploading":`Uploading…`,"cloud.syncing":`Syncing…`,"cloud.saved":`Saved to cloud`,"cloud.synced":`Synced`,"cloud.open":`Open`,"cloud.openTitle":`Open in popost`,"cloud.dirty":`Local changes not uploaded`,"cloud.syncNow":`Sync now`,"cloud.failed":`Upload failed`,"cloud.retry":`Retry`,"cloud.conflict":`Edited on the web`,"cloud.overwrite":`Overwrite`,"cloud.overwriteTitle":`Replace the web copy with this local version`,"cloud.error.UNAUTHORIZED":`The login expired or was already used. Save to Cloud again.`,"cloud.error.STORAGE_FULL":`Your cloud storage is full.`,"cloud.error.RATE_LIMITED":`Too many uploads. Try again in a moment.`,"cloud.error.DECK_INVALID":`The cloud could not accept this project.`,"cloud.error.NETWORK":`Could not reach popost.ai.`,"cloud.error.LOCAL_SAVE_FAILED":`Could not save local edits. Save the project before uploading.`,"cloud.error.generic":`Upload failed. Try again.`,"status.loading":`Loading…`,"status.errorTitle":`Could not open the document`,"status.retry":`Try again`,"error.no-pages":`This document has no pages. A page is a top-level element with class "slide".`,"conflict.title":`Saved elsewhere`,"conflict.body":`This document was changed somewhere else since you opened it. Reload to get the latest version (your unsaved edits are lost), or overwrite it with your version.`,"conflict.reload":`Reload`,"conflict.overwrite":`Overwrite`,"notice.saveFailed":`Save failed`,"notice.editRejected":`That change could not be applied`,"notice.resetDone":`Layout reset to the initial version. Save to keep it.`,"notice.resetUnavailable":`No initial version is available for this document`,"notice.downloadDone":`Download started`,"notice.downloadFailed":`Download failed`,"notice.fontFailed":`Could not apply the font`,"notice.imageFailed":`Could not use the image`,"notice.textOverflow":`Edited text exceeds its box`,"toast.deleted":`Deleted · Ctrl+Z to undo`,"toast.pageDeleted":`Page deleted · Ctrl+Z to undo`,"rail.label":`Panels`,"panel.text":`Text`,"panel.block":`Block`,"panel.layers":`Layers`,"panel.code":`Code`,"panel.close":`Close panel`,"pages.label":`Pages`,"pages.page":`Page {n}`,"pages.prev":`Previous page`,"pages.next":`Next page`,"pages.counter":`{n} / {total}`,"pages.overflowBadge":`Text exceeds its box on this page`,"pages.duplicate":`Duplicate page`,"pages.moveLeft":`Move left`,"pages.moveRight":`Move right`,"pages.delete":`Delete page`,"pages.overflowCount":`{n} text overflow`,"pages.overflowJump":`Jump to the next overflowing text`,"zoom.slider":`Zoom`,"zoom.fit":`Fit to window`,"pill.move":`Drag to move`,"pill.selectParent":`Select parent`,"pill.duplicate":`Duplicate (Ctrl+D)`,"pill.delete":`Delete (Delete)`,"pill.forward":`Bring forward (Alt+↓)`,"pill.backward":`Send backward (Alt+↑)`,"pill.selected":`Selected {n}`,"toolbar.label":`Format`,"toast.styleCopied":`Style copied`,"toast.stylePasted":`Style pasted`,"toast.styleNothing":`Copy a style first (Ctrl+Alt+C)`,"panel.selectHint":`Select a block on the canvas first.`,"toolbar.font":`Font`,"toolbar.fontsLoading":`Loading fonts…`,"toolbar.fontsFailed":`Font library unavailable`,"toolbar.fontMissing":`{name} (not in public library)`,"toolbar.size":`Font size (px)`,"toolbar.sizeDown":`Smaller`,"toolbar.sizeUp":`Larger`,"toolbar.bold":`Bold (Ctrl+B)`,"toolbar.italic":`Italic (Ctrl+I)`,"toolbar.underline":`Underline (Ctrl+U)`,"toolbar.strike":`Strikethrough`,"toolbar.color":`Text colour`,"toolbar.alignLeft":`Align left`,"toolbar.alignCenter":`Align centre`,"toolbar.alignRight":`Align right`,"toolbar.alignJustify":`Justify`,"toolbar.spacing":`Line height and letter spacing`,"toolbar.lineHeight":`Line height`,"toolbar.letterSpacing":`Letter spacing`,"toolbar.uppercase":`Uppercase`,"toolbar.opacity":`Opacity`,"toolbar.clear":`Clear formatting`,"toolbar.copyStyle":`Copy style (Ctrl+Alt+C)`,"toolbar.pasteStyle":`Paste style (Ctrl+Alt+V)`,"toolbar.replaceImage":`Replace image`,"toolbar.crop":`Crop & align`,"toolbar.block":`Block`,"colors.document":`Document colours`,"colors.presets":`Preset colours`,"colors.custom":`Custom colour`,"colors.none":`No colour`,"text.add":`Add text`,"text.addHeading":`Heading`,"text.addSubheading":`Subheading`,"text.addParagraph":`Paragraph`,"text.sampleHeading":`Heading`,"text.sampleSubheading":`Subheading`,"text.sampleParagraph":`Paragraph text`,"text.color":`Text colour`,"block.background":`Background`,"block.radius":`Corner radius`,"block.radius.none":`None`,"block.radius.subtle":`Subtle`,"block.radius.medium":`Medium`,"block.radius.large":`Large`,"block.radius.full":`Full`,"block.padding":`Padding`,"block.padding.none":`None`,"block.padding.narrow":`Narrow`,"block.padding.medium":`Medium`,"block.padding.wide":`Wide`,"block.margin":`Margin`,"block.margin.none":`None`,"block.margin.small":`Small`,"block.margin.medium":`Medium`,"block.margin.large":`Large`,"block.border":`Border`,"block.border.none":`None`,"block.border.solid":`Solid`,"block.border.dashed":`Dashed`,"block.border.dotted":`Dotted`,"block.borderWidth.thin":`Thin`,"block.borderWidth.medium":`Medium`,"block.borderWidth.thick":`Thick`,"block.shadow":`Shadow`,"block.shadow.none":`None`,"block.shadow.soft":`Soft`,"block.shadow.medium":`Medium`,"block.shadow.strong":`Strong`,"block.opacity":`Opacity`,"block.size":`Size`,"block.sizeHint":`Drag the handles on the canvas to resize.`,"block.resetSize":`Reset to original size`,"layers.empty":`This page has no selectable blocks.`,"layers.kind.text":`Text`,"layers.kind.image":`Image`,"layers.kind.svg":`Graphic`,"layers.kind.video":`Video`,"layers.kind.box":`Box`,"code.save":`Save code`,"code.saving":`Saving…`,"code.download":`Download HTML`,"code.status.idle":`Static HTML · editable`,"code.status.dirty":`Unsaved code changes`,"code.status.saved":`Code saved. Canvas and thumbnails updated.`,"code.status.appliedUnsaved":`Code applied to the canvas, but saving the document did not finish.`,"code.status.downloaded":`Downloaded a static HTML copy (no executable scripts)`,"code.err.empty":`Code cannot be empty`,"code.err.too-large":`Code exceeds the 60 MB limit`,"code.err.no-slide":`Keep at least one .slide block`,"code.err.unsafe":`Only static HTML is supported. Scripts, event handlers and embedded content are not allowed`,"code.err.rejected":`Could not update the canvas`,"image.upload":`Upload from computer`,"image.inDocument":`Images in this document`,"image.use":`Use this image`,"image.fromUrl":`Image URL`,"image.apply":`Apply`,"image.loading":`Loading…`,"image.err.notImage":`not an image file`,"image.err.tooLarge":`image is larger than 12 MB`,"image.err.fetch":`the address could not be loaded (it may block other sites)`,"crop.hint":`Drag to reposition the image`,"crop.fill":`Fill container`,"crop.whole":`Show whole`,"crop.done":`Done`},ef={en:$d,zh:{"compare.open":`复刻对比`,"compare.close":`收起对比`,"compare.openHint":`点击查看复刻对比`,"compare.closeHint":`点击收起复刻对比`,"compare.reference":`参考图文`,"compare.result":`当前作品`,"compare.page":`第 {n} 页`,"compare.empty":`这一页暂无参考图文`,"compare.emptyHint":`参考图文按原始顺序与作品逐页对应`,"compare.loading":`正在加载参考图文…`,"compare.failed":`参考图文加载失败`,"compare.retry":`重试`,"compare.readonly":`原始参考 · 只读`,"compare.editable":`可编辑画布`,"compare.imageFailed":`参考图片暂时无法加载`,"assets.confirm":`确定`,"code.disableWrap":`取消自动换行`,"code.enableWrap":`自动换行`,"code.copy":`复制`,"code.status.copied":`已复制完整代码`,"code.status.copyFailed":`复制失败,请检查浏览器的剪贴板权限。`,"export.pages":`选择页面 · {n}/{total}`,"export.all":`导出全部`,"export.format":`文件格式`,"export.resolution":`分辨率`,"export.name":`文件名`,"export.editName":`编辑文件名`,"export.confirmName":`确认文件名`,"export.imageFormats":`图片格式`,"export.documentFormats":`文档格式`,"export.standard":`标准`,"export.high":`高分辨率`,"export.paid":`付费权益`,"export.upgrade":`该功能为付费权益,付费后可使用。`,"export.pricing":`前往解锁`,"export.progress":`正在导出… {percent}%({done}/{total})`,"export.done":`ZIP 已导出`,"export.failed":`导出失败,请重试`,"history.draftRestored":`已还原到编辑器,请保存以保留更改。`,"history.draftFailed":`此版本无法还原,请重试。`,"zoom.in":`放大`,"zoom.out":`缩小`,"panel.add":`增加`,"panel.images":`增加图片`,"design.size":`尺寸`,"design.background":`背景色`,"design.cancel":`取消`,"design.apply":`确定`,"add.text":`增加文字`,"add.page":`增加页面`,"assets.current":`本次素材`,"assets.history":`历史素材`,"assets.projectHistory":`工程素材记录`,"assets.upload":`上传`,"assets.empty":`暂无素材`,"assets.more":`加载更多`,"assets.failed":`素材加载失败,请重试`,"colors.expand":`展开色板`,"colors.collapse":`收起色板`,"topbar.undo":`撤销 (Ctrl+Z)`,"topbar.redo":`重做 (Ctrl+Shift+Z)`,"topbar.resetLayout":`还原初始布局`,"topbar.save":`保存`,"topbar.saveTitle":`保存 (Ctrl+S)`,"topbar.export":`导出`,"topbar.exportHtml":`保存为 HTML`,"topbar.downloadImages":`下载全部`,"topbar.downloadImagesBusy":`下载中…`,"save.saved":`所有更改已保存`,"save.dirty":`有未保存的更改`,"save.saving":`保存中…`,"save.error":`保存失败`,"cloud.save":`保存到云端`,"cloud.tooltip":`在popost网页端管理你的所有资产`,"cloud.waiting":`等待登录…`,"cloud.copyLink":`复制链接`,"cloud.linkCopied":`链接已复制`,"cloud.loginLink":`登录链接`,"cloud.uploading":`上传中…`,"cloud.syncing":`同步中…`,"cloud.saved":`已保存到云端`,"cloud.synced":`已同步`,"cloud.open":`打开`,"cloud.openTitle":`在 popost 打开`,"cloud.dirty":`本地改动未上传`,"cloud.syncNow":`立即同步`,"cloud.failed":`上传失败`,"cloud.retry":`重试`,"cloud.conflict":`网页端已有修改`,"cloud.overwrite":`覆盖`,"cloud.overwriteTitle":`用本地版本替换网页端的版本`,"cloud.error.UNAUTHORIZED":`登录已过期或已使用,请重新点击“保存到云端”。`,"cloud.error.STORAGE_FULL":`云端存储空间已满。`,"cloud.error.RATE_LIMITED":`上传过于频繁,请稍后再试。`,"cloud.error.DECK_INVALID":`云端无法接收这个作品。`,"cloud.error.NETWORK":`无法连接 popost.ai。`,"cloud.error.LOCAL_SAVE_FAILED":`本地改动保存失败。请先保存作品,再上传到云端。`,"cloud.error.generic":`上传失败,请重试。`,"status.loading":`加载中…`,"status.errorTitle":`无法打开文档`,"status.retry":`重试`,"error.no-pages":`文档里没有页面。页面是带 "slide" 类的顶层元素。`,"conflict.title":`已在别处保存`,"conflict.body":`打开之后,这份文档在别处被修改过。可以重新加载最新版本(未保存的修改会丢失),或用你的版本覆盖。`,"conflict.reload":`重新加载`,"conflict.overwrite":`覆盖`,"notice.saveFailed":`保存失败`,"notice.editRejected":`这个修改无法应用`,"notice.resetDone":`已还原为初始布局,记得保存。`,"notice.resetUnavailable":`这份文档没有可还原的初始版本`,"notice.downloadDone":`已开始下载`,"notice.downloadFailed":`下载失败`,"notice.fontFailed":`无法应用该字体`,"notice.imageFailed":`无法使用这张图片`,"notice.textOverflow":`编辑后的文字超出了文本框`,"toast.deleted":`已删除 · Ctrl+Z 撤销`,"toast.pageDeleted":`已删除页面 · Ctrl+Z 撤销`,"rail.label":`面板`,"panel.text":`文字`,"panel.block":`区块`,"panel.layers":`图层`,"panel.code":`代码`,"panel.close":`关闭面板`,"pages.label":`页面`,"pages.page":`第 {n} 页`,"pages.prev":`上一页`,"pages.next":`下一页`,"pages.counter":`{n} / {total}`,"pages.overflowBadge":`这一页有文字超出文本框`,"pages.duplicate":`复制页面`,"pages.moveLeft":`左移`,"pages.moveRight":`右移`,"pages.delete":`删除页面`,"pages.overflowCount":`{n} 处文字溢出`,"pages.overflowJump":`跳到下一处溢出的文字`,"zoom.slider":`缩放`,"zoom.fit":`适应窗口`,"pill.move":`拖动移动`,"pill.selectParent":`选择父级`,"pill.duplicate":`复制 (Ctrl+D)`,"pill.delete":`删除 (Delete)`,"pill.forward":`上移一层 (Alt+↓)`,"pill.backward":`下移一层 (Alt+↑)`,"pill.selected":`已选 {n} 个`,"toolbar.label":`格式`,"toast.styleCopied":`样式已复制`,"toast.stylePasted":`样式已粘贴`,"toast.styleNothing":`请先复制样式 (Ctrl+Alt+C)`,"panel.selectHint":`请先在画布上选中一个区块。`,"toolbar.font":`字体`,"toolbar.fontsLoading":`字体加载中…`,"toolbar.fontsFailed":`字体库加载失败`,"toolbar.fontMissing":`{name}(不在公共字体库)`,"toolbar.size":`字号 (px)`,"toolbar.sizeDown":`减小字号`,"toolbar.sizeUp":`增大字号`,"toolbar.bold":`加粗 (Ctrl+B)`,"toolbar.italic":`斜体 (Ctrl+I)`,"toolbar.underline":`下划线 (Ctrl+U)`,"toolbar.strike":`删除线`,"toolbar.color":`文字颜色`,"toolbar.alignLeft":`左对齐`,"toolbar.alignCenter":`居中对齐`,"toolbar.alignRight":`右对齐`,"toolbar.alignJustify":`两端对齐`,"toolbar.spacing":`行距与字距`,"toolbar.lineHeight":`行距`,"toolbar.letterSpacing":`字距`,"toolbar.uppercase":`大写`,"toolbar.opacity":`不透明度`,"toolbar.clear":`清除格式`,"toolbar.copyStyle":`复制样式 (Ctrl+Alt+C)`,"toolbar.pasteStyle":`粘贴样式 (Ctrl+Alt+V)`,"toolbar.replaceImage":`替换图片`,"toolbar.crop":`裁剪与对齐`,"toolbar.block":`区块`,"colors.document":`文档中的颜色`,"colors.presets":`预设颜色`,"colors.custom":`自定义颜色`,"colors.none":`无颜色`,"text.add":`添加文字`,"text.addHeading":`标题`,"text.addSubheading":`副标题`,"text.addParagraph":`正文`,"text.sampleHeading":`标题`,"text.sampleSubheading":`副标题`,"text.sampleParagraph":`正文文字`,"text.color":`文字颜色`,"block.background":`背景颜色`,"block.radius":`圆角`,"block.radius.none":`无`,"block.radius.subtle":`轻微`,"block.radius.medium":`中等`,"block.radius.large":`较大`,"block.radius.full":`全圆`,"block.padding":`内边距`,"block.padding.none":`无`,"block.padding.narrow":`窄`,"block.padding.medium":`中`,"block.padding.wide":`宽`,"block.margin":`外边距`,"block.margin.none":`无`,"block.margin.small":`小`,"block.margin.medium":`中`,"block.margin.large":`大`,"block.border":`边框`,"block.border.none":`无`,"block.border.solid":`实线`,"block.border.dashed":`虚线`,"block.border.dotted":`点线`,"block.borderWidth.thin":`细`,"block.borderWidth.medium":`中`,"block.borderWidth.thick":`粗`,"block.shadow":`阴影`,"block.shadow.none":`无`,"block.shadow.soft":`柔和`,"block.shadow.medium":`中等`,"block.shadow.strong":`强烈`,"block.opacity":`不透明度`,"block.size":`尺寸`,"block.sizeHint":`在画布上拖动控制点调整大小。`,"block.resetSize":`还原原始尺寸`,"layers.empty":`这一页没有可选中的区块。`,"layers.kind.text":`文字`,"layers.kind.image":`图片`,"layers.kind.svg":`图形`,"layers.kind.video":`视频`,"layers.kind.box":`容器`,"code.save":`保存代码`,"code.saving":`保存中…`,"code.download":`下载 html`,"code.status.idle":`静态 HTML · 可直接编辑`,"code.status.dirty":`有未保存的代码修改`,"code.status.saved":`代码已保存,画布与图文缩略图已更新`,"code.status.appliedUnsaved":`代码已应用到画布,但文档尚未保存成功`,"code.status.downloaded":`已下载 HTML 静态副本(不含可执行脚本)`,"code.err.empty":`代码不能为空`,"code.err.too-large":`代码超过60MB上限`,"code.err.no-slide":`请保留至少一个 .slide 图文区块`,"code.err.unsafe":`仅支持静态 HTML,不允许脚本、事件处理器或嵌入内容`,"code.err.rejected":`无法更新画布`,"image.upload":`从本地上传`,"image.inDocument":`文档中已有的图片`,"image.use":`使用这张图片`,"image.fromUrl":`图片链接`,"image.apply":`应用`,"image.loading":`加载中…`,"image.err.notImage":`不是图片文件`,"image.err.tooLarge":`图片超过 12 MB`,"image.err.fetch":`无法读取该地址(可能不允许其他网站读取)`,"crop.hint":`拖动调整图片位置`,"crop.fill":`填满容器`,"crop.whole":`完整显示`,"crop.done":`完成`}};function tf(e){let t=ef[e];return(e,n)=>{let r=t[e]??$d[e]??e;return n?r.replace(/\{(\w+)\}/g,(e,t)=>t in n?String(n[t]):e):r}}var nf=(0,v.createContext)({lang:`en`,t:tf(`en`)});function rf({lang:e,children:t}){let n=(0,v.useMemo)(()=>({lang:e,t:tf(e)}),[e]);return(0,v.createElement)(nf.Provider,{value:n},t)}var af=()=>(0,v.useContext)(nf).t,of=()=>(0,v.useContext)(nf).lang,sf={saveFailed:`notice.saveFailed`,editRejected:`notice.editRejected`,resetDone:`notice.resetDone`,resetUnavailable:`notice.resetUnavailable`,downloadDone:`notice.downloadDone`,downloadFailed:`notice.downloadFailed`,fontFailed:`notice.fontFailed`,imageFailed:`notice.imageFailed`,textOverflow:`notice.textOverflow`};function cf(e,t){let n=e(sf[t.key]);return t.detail?`${n}: ${t.detail}`:n}function lf(e,t){if(!t)return``;let n=`error.${t}`;return n in $d?e(n):t}var uf=e=>Math.max(0,Math.min(1,e)),df={left:0,top:0,center:.5,right:1,bottom:1};function ff(e){if(e===void 0)return .5;if(e in df)return df[e];if(e.endsWith(`%`)){let t=Number.parseFloat(e);if(Number.isFinite(t))return uf(t/100)}return .5}function pf(e){let t=(e??``).trim().toLowerCase().split(/\s+/).filter(Boolean);return t.length===1&&(t[0]===`top`||t[0]===`bottom`)?{x:.5,y:ff(t[0])}:{x:ff(t[0]),y:ff(t[1])}}var mf=e=>`${Math.round(e*1e3)/10}%`;function hf(e){return`${mf(e.x)} ${mf(e.y)}`}function gf(e,t,n){let r=t.width/e.width,i=t.height/e.height,a=n===`cover`?Math.max(r,i):Math.min(r,i);return{width:e.width*a,height:e.height*a}}function _f(e){let{natural:t,box:n,fit:r,start:i,dx:a,dy:o}=e;if(!(t.width>0&&t.height>0&&n.width>0&&n.height>0))return i;let s=gf(t,n,r),c=(e,t,n,r)=>{let i=n-r;return Math.abs(i)<.5?e:uf(e+t/i)};return{x:c(i.x,a,n.width,s.width),y:c(i.y,o,n.height,s.height)}}function vf(e){return e===`cover`||e===`contain`?e:null}var yf=class extends Error{reason;constructor(e){super(e),this.reason=e}};function bf(e){let t=new Set,n=[];for(let r of e.order){let i=e.elements.get(r);if(!i||i.tag.toLowerCase()!==`img`)continue;let a=Pi(i,`src`);!a||t.has(a)||(t.add(a),n.push({src:a,id:r}))}return n}function xf(e){return/^image\//i.test(e)}function Sf(e){if(!xf(e.type))throw new yf(`notImage`);if(e.size>12582912)throw new yf(`tooLarge`)}function Cf(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(new yf(`fetch`)),r.readAsDataURL(e)})}async function wf(e){return Sf(e),Cf(e)}function Tf(e){let t=e.trim();if(!t)return null;if(/^data:image\//i.test(t))return t;try{let e=new URL(/^[a-z][a-z0-9+.-]*:/i.test(t)?t:`https://${t}`);return e.protocol===`http:`||e.protocol===`https:`||e.protocol===`blob:`?e.href:null}catch{return null}}async function Ef(e,t=fetch){let n=Tf(e);if(!n)throw new yf(`fetch`);if(n.startsWith(`data:`))return n;let r;try{let e=await t(n);if(!e.ok)throw new yf(`fetch`);r=await e.blob()}catch(e){throw e instanceof yf?e:new yf(`fetch`)}return wf(r)}var Df=(0,v.createContext)(()=>void 0),Of=()=>(0,v.useContext)(Df),kf=3200;function Af({children:e}){let[t,n]=(0,v.useState)([]),r=(0,v.useRef)(1),i=(0,v.useRef)(new Set),a=(0,v.useCallback)((e,t=`info`)=>{let a=r.current++;n(n=>[...n.filter(t=>t.text!==e).slice(-3),{id:a,kind:t,text:e}]);let o=setTimeout(()=>{i.current.delete(o),n(e=>e.filter(e=>e.id!==a))},kf);i.current.add(o)},[]);(0,v.useEffect)(()=>{let e=i.current;return()=>e.forEach(clearTimeout)},[]);let o=(0,v.useMemo)(()=>a,[a]);return(0,Q.jsxs)(Df.Provider,{value:o,children:[e,(0,Q.jsx)(`div`,{className:`toasts`,role:`status`,"aria-live":`polite`,children:t.map(e=>(0,Q.jsx)(`div`,{className:`toast toast-${e.kind}`,children:e.text},e.id))})]})}var jf={notImage:`image.err.notImage`,tooLarge:`image.err.tooLarge`,fetch:`image.err.fetch`};function Mf(){let e=af(),t=Of();return(0,v.useCallback)(n=>{let r=n instanceof yf?e(jf[n.reason]):n instanceof Error?n.message:``;t(r?`${e(`notice.imageFailed`)}: ${r}`:e(`notice.imageFailed`),`error`)},[e,t])}function Nf(e,t,n){let r=e.index().elements.get(t);if(!r)return;let i=[{kind:`setAttr`,id:t,name:`src`,value:n}];Pi(r,`srcset`)!==null&&i.push({kind:`setAttr`,id:t,name:`srcset`,value:null}),e.applyBatch(i,`replace image`)}var Pf=(e,t)=>e.index().elements.get(t)?.tag.toLowerCase()===`img`;function Ff(e){let t=Mf();(0,v.useEffect)(()=>e.onFrameEvent(n=>{if(n.type!==`drop`||n.id===null||!Pf(e,n.id))return;let r=n.files.find(e=>xf(e.type));if(r){if(r.dataURL.length*3/4>12582912){t(new yf(`tooLarge`));return}Nf(e,n.id,r.dataURL),e.select([n.id])}}),[e,t])}function If({controller:e,id:t,onDone:n}){let r=af(),i=Mf(),a=(0,v.useRef)(null),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1),u=bf(e.index()),d=e.index().elements.get(t),f=d?Pi(d,`src`):null,p=async r=>{l(!0);try{Nf(e,t,await r()),n()}catch(e){i(e)}finally{l(!1)}};return(0,Q.jsxs)(`div`,{className:`image-picker`,children:[(0,Q.jsxs)(`button`,{type:`button`,id:`img-upload`,className:`btn wide`,disabled:c,onClick:()=>a.current?.click(),children:[(0,Q.jsx)($,{name:`upload`}),` `,r(`image.upload`)]}),(0,Q.jsx)(`input`,{ref:a,id:`img-file`,type:`file`,accept:`image/*`,hidden:!0,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&p(()=>wf(t))}}),u.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`swatch-title`,children:r(`image.inDocument`)}),(0,Q.jsx)(`div`,{className:`img-grid`,id:`img-doc-grid`,children:u.map(e=>(0,Q.jsx)(`button`,{type:`button`,className:`img-thumb${e.src===f?` current`:``}`,title:r(`image.use`),disabled:c||e.src===f,onClick:()=>void p(async()=>e.src),children:(0,Q.jsx)(`img`,{src:e.src,alt:``})},e.src))})]}),(0,Q.jsx)(`div`,{className:`swatch-title`,children:r(`image.fromUrl`)}),(0,Q.jsxs)(`form`,{className:`img-url`,onSubmit:e=>{e.preventDefault(),o.trim()&&p(()=>Ef(o))},children:[(0,Q.jsx)(`input`,{id:`img-url`,type:`text`,inputMode:`url`,placeholder:`https://…`,value:o,onChange:e=>s(e.target.value),"aria-label":r(`image.fromUrl`)}),(0,Q.jsx)(`button`,{type:`submit`,id:`img-url-apply`,className:`btn`,disabled:c||!o.trim(),children:r(c?`image.loading`:`image.apply`)})]})]})}function Lf({controller:e,snap:t,id:n,scale:r,onExit:i}){let a=af(),o=(0,v.useRef)(null),s=(0,v.useRef)(!1),c=t.rects[n],l=(0,v.useCallback)(()=>{s.current&&e.cancelLivePreview([n]),s.current=!1,o.current=null,i()},[e,n,i]);Md(!0,l);let u=t.selection.length===1&&t.selection[0]===n&&e.index().elements.has(n);if((0,v.useEffect)(()=>{u||i()},[u,i]),!c)return null;let d=e.styles(n,[`object-fit`,`object-position`]),f=vf(d[`object-fit`]),p={left:c.x*r,top:c.y*r,width:c.width*r,height:c.height*r},m=t=>e.apply({kind:`setStyle`,id:n,props:{"object-fit":t}},{label:`crop`}),h=e=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),e.currentTarget.setPointerCapture(e.pointerId),o.current={startX:e.clientX,startY:e.clientY,start:pf(d[`object-position`]),fit:f??`cover`,last:null})},g=t=>{let i=o.current,a=ud(n);!i||!a||(i.last=hf(_f({natural:a,box:{width:c.width,height:c.height},fit:i.fit,start:i.start,dx:(t.clientX-i.startX)/r,dy:(t.clientY-i.startY)/r})),s.current=!0,e.livePreview([{kind:`style`,id:n,props:{"object-position":i.last,"object-fit":i.fit}}]))},_=t=>{let r=o.current;o.current=null,s.current=!1,t.currentTarget.hasPointerCapture(t.pointerId)&&t.currentTarget.releasePointerCapture(t.pointerId),r?.last&&e.apply({kind:`setStyle`,id:n,props:{"object-position":r.last,"object-fit":r.fit}},{label:`crop`})},y=Math.max(4,Math.min(p.top+p.height+10,e.pageSize().height*r-44));return(0,Q.jsxs)(`div`,{className:`crop-layer`,"data-keepfocus":``,onPointerDown:e=>e.target===e.currentTarget&&l(),children:[(0,Q.jsx)(`div`,{id:`crop-box`,className:`crop-box`,style:p,onPointerDown:h,onPointerMove:g,onPointerUp:_,onPointerCancel:()=>l(),children:(0,Q.jsx)(`span`,{className:`crop-hint`,children:a(`crop.hint`)})}),(0,Q.jsxs)(`div`,{className:`crop-bar`,style:{left:p.left,top:y},role:`toolbar`,children:[(0,Q.jsx)(`button`,{type:`button`,id:`crop-fill`,className:`btn${f===`cover`?` on`:``}`,onClick:()=>m(`cover`),children:a(`crop.fill`)}),(0,Q.jsx)(`button`,{type:`button`,id:`crop-whole`,className:`btn${f===`contain`?` on`:``}`,onClick:()=>m(`contain`),children:a(`crop.whole`)}),(0,Q.jsx)(`button`,{type:`button`,id:`crop-done`,className:`btn primary`,onClick:l,children:a(`crop.done`)})]})]})}var Rf=[`font-weight`,`font-style`,`text-decoration-line`,`text-transform`,`text-align`,`font-size`,`font-family`,`color`,`line-height`,`letter-spacing`,`opacity`],zf=e=>{if(!e)return!1;if(e===`bold`||e===`bolder`)return!0;let t=Number.parseInt(e,10);return Number.isFinite(t)&&t>=600};function Bf(e,t){let n=(e[`text-decoration-line`]??``).split(/\s+/);return{bold:t?!!t.bold:zf(e[`font-weight`]),italic:t?!!t.italic:/^(italic|oblique)/.test(e[`font-style`]??``),underline:t?!!t.underline:n.includes(`underline`),strike:t?!!t.strike:n.includes(`line-through`),uppercase:e[`text-transform`]===`uppercase`}}function Vf(e){switch(e){case`center`:case`right`:case`justify`:return e;case`end`:return`right`;default:return`left`}}var Hf=e=>{let t=Number.parseFloat(e??``);return Number.isFinite(t)?t:NaN},Uf=e=>Number.isFinite(Hf(e[`font-size`]))?Hf(e[`font-size`]):0;function Wf(e){let t=e[`line-height`],n=Uf(e);if(!t||t===`normal`||n<=0)return 1.2;let r=Hf(t);return Number.isFinite(r)?t.endsWith(`px`)?Math.round(r/n*100)/100:r:1.2}function Gf(e){let t=e[`letter-spacing`],n=Uf(e);if(!t||t===`normal`||n<=0)return 0;let r=Hf(t);return Number.isFinite(r)?Math.round(r/n*1e3)/1e3:0}function Kf(e){let t=Hf(e.opacity);return Number.isFinite(t)?Math.max(0,Math.min(1,t)):1}function qf(e){return((e??``).split(`,`)[0]?.trim()??``).replace(/^["']|["']$/g,``)}var Jf=e=>Math.round(e*255).toString(16).padStart(2,`0`),Yf=e=>Math.min(1,Math.max(0,e)),Xf=(e,t,n)=>{let r=r=>{let i=(r+e/60)%6;return Jf(n-n*t*Math.max(0,Math.min(i,4-i,1)))};return`#${r(5)}${r(3)}${r(1)}`},Zf=e=>{let[t,n,r]=[1,3,5].map(t=>parseInt(e.slice(t,t+2),16)/255),i=Math.max(t,n,r),a=i-Math.min(t,n,r);return{h:((a?(i===t?(n-r)/a:i===n?2+(r-t)/a:4+(t-n)/a)*60:0)+360)%360,s:i?a/i:0,v:i}},Qf=[20,45,100,155,190,220,250,290,325,350].flatMap(e=>[.94,.7,.4,.18].map((t,n)=>Xf(e,t,[.76,.92,.99,1][n]??1)));function $f({color:e,onPick:t,disabled:n}){let r=_d(e.slice(0,7))??`#222222`,[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(null),[c,l]=(0,v.useState)(null),u=Zf(r),d=i??u.h,f=c??(e.length===9?parseInt(e.slice(7),16)/255:1),p=(e,n,r)=>t(n===1?e:`${e}${Jf(n)}`,r),m=(e,t)=>{if(n)return;let r=e.currentTarget.getBoundingClientRect();a(d),p(Xf(d,Yf((e.clientX-r.left)/r.width),1-Yf((e.clientY-r.top)/r.height)),f,t)};return(0,Q.jsxs)(`div`,{className:`color-picker`,children:[(0,Q.jsx)(`div`,{className:`color-field`,style:{backgroundColor:Xf(d,1,1)},onPointerDown:e=>{e.currentTarget.setPointerCapture(e.pointerId),m(e,`live`)},onPointerMove:e=>{e.currentTarget.hasPointerCapture(e.pointerId)&&m(e,`live`)},onPointerUp:e=>m(e,`commit`),children:(0,Q.jsx)(`i`,{style:{left:`${u.s*100}%`,top:`${(1-u.v)*100}%`,background:r}})}),(0,Q.jsx)(`input`,{className:`color-hue`,type:`range`,min:0,max:359,"aria-label":`Hue`,value:d,disabled:n,onChange:e=>{let t=Number(e.currentTarget.value);a(t),p(Xf(t,u.s||.8,u.v||1),f,`commit`)}}),(0,Q.jsx)(`input`,{className:`color-alpha`,type:`range`,min:0,max:100,"aria-label":`Opacity`,value:Math.round(f*100),disabled:n,style:{backgroundImage:`linear-gradient(90deg, transparent, ${r})`},onChange:e=>{let t=Number(e.currentTarget.value)/100;l(t),p(r,t,`commit`)}}),(0,Q.jsxs)(`div`,{className:`color-inputs`,children:[(0,Q.jsxs)(`label`,{children:[`HEX`,(0,Q.jsx)(`input`,{"aria-label":`HEX`,value:o??r.toUpperCase(),maxLength:7,disabled:n,onChange:e=>s(e.currentTarget.value),onBlur:()=>{if(o===null)return;let e=o.trim(),t=_d(e.startsWith(`#`)?e:`#${e}`);t&&(a(null),p(t,f,`commit`)),s(null)},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()}})]}),(0,Q.jsxs)(`span`,{children:[Math.round(f*100),`%`]})]})]})}function ep({docColors:e,current:t,allowNone:n,disabled:r,expanded:i=!1,onPick:a}){let o=af(),[s,c]=(0,v.useState)(i),[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(null),p=d??t??`#222222`,m=(e,t)=>{f(e),a(e,t)},h=e=>(0,Q.jsx)(`button`,{type:`button`,className:`swatch${e===`transparent`?` none`:``}${p===e?` current`:``}`,style:e===`transparent`?void 0:{background:e},title:e===`transparent`?o(`colors.none`):e,"aria-label":e===`transparent`?o(`colors.none`):e,"data-color":e,disabled:r,onClick:()=>m(e,`commit`)},e);return(0,Q.jsxs)(`div`,{className:`swatches`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`btn color-toggle`,disabled:r,"aria-expanded":s,onClick:()=>{f(null),c(!s)},children:o(`colors.custom`)}),s&&(0,Q.jsx)($f,{color:p===`transparent`?`#ffffff`:p,onPick:m,disabled:r}),e.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`swatch-title`,children:o(`colors.document`)}),(0,Q.jsx)(`div`,{className:`swatch-grid`,"data-swatches":`document`,children:e.map(h)})]}),(0,Q.jsx)(`div`,{className:`swatch-title`,children:o(`colors.presets`)}),(0,Q.jsxs)(`div`,{className:`swatch-grid`,"data-swatches":`presets`,children:[n&&h(`transparent`),fd.map(h),l&&Qf.map(h)]}),(0,Q.jsx)(`button`,{type:`button`,className:`btn color-toggle`,"aria-expanded":l,onClick:()=>u(!l),children:o(l?`colors.collapse`:`colors.expand`)})]})}function tp(e){return e.editingTextId?[e.editingTextId]:[...e.selection]}function np(e,t){return(0,v.useMemo)(()=>Sd(e.index().source),[e,t])}function rp(e,t,n){let r=tp(t)[0];return(0,v.useMemo)(()=>r===void 0?{}:e.styles(r,[...n]),[e,r,t.sourceVersion,t.rects,t.editingTextId,t.textState])}function ip(e,t,n){return(0,v.useMemo)(()=>t.map(t=>Wa(e.index(),t)),[e,t.join(`,`),n])}var ap=8;function op({open:e,anchor:t,onClose:n,id:r,className:i,children:a}){let o=(0,v.useRef)(null),[s,c]=(0,v.useState)(null);return Md(e,n),(0,v.useLayoutEffect)(()=>{if(!e){c(null);return}let n=t.current?.getBoundingClientRect(),r=o.current?.offsetWidth??0;n&&c({left:Math.max(ap,Math.min(n.left,window.innerWidth-r-ap)),top:n.bottom+6})},[e,t]),e?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`menu-scrim`,"data-keepfocus":``,onMouseDown:n}),(0,Q.jsx)(`div`,{ref:o,id:r,className:`popover pop-fixed${i?` ${i}`:``}`,style:s??{left:-9999,top:0},role:`dialog`,children:a})]}):null}function sp(e){return(0,v.useSyncExternalStore)(e.subscribe,e.getSnapshot)}var cp=[{id:`left`,icon:`alignLeft`,label:`toolbar.alignLeft`},{id:`center`,icon:`alignCenter`,label:`toolbar.alignCenter`},{id:`right`,icon:`alignRight`,label:`toolbar.alignRight`},{id:`justify`,icon:`alignJustify`,label:`toolbar.alignJustify`}],lp=`__doc-font`,up=1,dp=999;function fp({id:e,label:t,min:n,max:r,step:i,value:a,format:o,onChange:s}){return(0,Q.jsxs)(`label`,{className:`slider-row`,children:[(0,Q.jsx)(`span`,{className:`slider-label`,children:t}),(0,Q.jsx)(`input`,{id:e,type:`range`,min:n,max:r,step:i,value:a,onChange:e=>s(Number(e.target.value))}),(0,Q.jsx)(`output`,{children:o(a)})]})}function pp({controller:e,actions:t,onOpenBlock:n,crop:r}){let i=af(),a=sp(e),o=tp(a),s=a.docState===`ready`&&o.length>0,c=ip(e,o,a.sourceVersion),l=s&&(a.editingTextId!==null||c.some(e=>e===`text`||e===`box`)),u=a.docState===`ready`&&a.selection.length===1&&a.selection[0]!==void 0&&Pf(e,a.selection[0])?a.selection[0]:null,d=rp(e,a,Rf),f=Bf(d,a.editingTextId?a.textState?.active:null),p=Uf(d),m=Vf(d[`text-align`]),h=_d(d.color)??`#000000`,g=np(e,a.sourceVersion),_=a.editingTextId!==null&&a.textState?.range===!0,[y,b]=(0,v.useState)(null),x=()=>b(null),S=(0,v.useRef)(null),C=(0,v.useRef)(null),w=(0,v.useRef)(null),T=(0,v.useRef)(null),ee=o.join(`,`);(0,v.useEffect)(()=>b(null),[ee]);let[E,D]=(0,v.useState)(null),[O,te]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let t=!0;return e.fontPalette().then(e=>t&&D(e.roles),()=>t&&te(!0)),()=>{t=!1}},[e]);let k=(0,v.useMemo)(()=>E?dc(E):[],[E]),A=qf(d[`font-family`]),ne=E?.some(e=>e.family===A)??!1,re=!s||A===``?``:ne?A:lp,ie=(t,n,r)=>{let i=o.map(e=>({kind:`setStyle`,id:e,props:t}));e.applyBatch(i,n,r?{coalesceKey:`${r}:${ee}`}:void 0)},j=(t,n)=>{_&&n===`live`||(e.format({command:`color`,value:t}),n===`commit`&&x())},M=t=>{Number.isFinite(t)&&e.format({command:`fontSize`,value:`${Math.max(up,Math.min(dp,Math.round(t)))}px`})},ae=t=>{let n=a.editingTextId;ie({"text-align":t},`align`),n&&e.beginTextEdit(n,`end`)},[oe,N]=(0,v.useState)(!1),[P,F]=(0,v.useState)(null),I=P??(p>0?String(Math.round(p*10)/10):``),L=(e,t,n,r)=>(0,Q.jsx)(`button`,{ref:r.ref,type:`button`,id:e,className:`tb-btn small fmt${r.on?` on`:``}`,title:t,"aria-label":t,"aria-pressed":r.on===void 0?void 0:r.on,disabled:r.disabled??!s,onClick:r.onClick,children:n}),R=t=>()=>e.format({command:t});return(0,Q.jsxs)(`div`,{className:`fmt-row`,"data-has-target":s?`1`:`0`,children:[(0,Q.jsxs)(`select`,{id:`tb-font`,className:`fmt-font`,title:i(`toolbar.font`),"aria-label":i(`toolbar.font`),disabled:!l||!E||oe,value:re,onChange:t=>{let n=E?.find(e=>e.family===t.target.value);n&&(N(!0),e.applyFont(n.id,o).then(()=>dd(n.family)).finally(()=>N(!1)))},children:[!E&&(0,Q.jsx)(`option`,{value:``,children:i(O?`toolbar.fontsFailed`:`toolbar.fontsLoading`)}),E&&re===``&&(0,Q.jsx)(`option`,{value:``,disabled:!0,children:i(`toolbar.font`)}),E&&re===lp&&(0,Q.jsx)(`option`,{value:lp,disabled:!0,children:i(`toolbar.fontMissing`,{name:A})}),k.map(e=>(0,Q.jsx)(`optgroup`,{label:e.label,children:e.options.map(e=>(0,Q.jsx)(`option`,{value:e.value,title:e.title,"data-font-id":e.fontId,children:e.label},e.fontId))},e.label))]}),(0,Q.jsxs)(`span`,{className:`fmt-size`,children:[L(`tb-size-dec`,i(`toolbar.sizeDown`),`−`,{disabled:!l,onClick:()=>M((p||16)-1)}),(0,Q.jsx)(`input`,{id:`tb-size`,type:`number`,min:up,max:dp,step:1,inputMode:`numeric`,title:i(`toolbar.size`),"aria-label":i(`toolbar.size`),disabled:!l,value:I,onChange:e=>F(e.target.value),onBlur:()=>F(null),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),M(Number(P??I)),F(null))}}),L(`tb-size-inc`,i(`toolbar.sizeUp`),`+`,{disabled:!l,onClick:()=>M((p||16)+1)})]}),(0,Q.jsx)(`span`,{className:`tb-sep`}),L(`tb-bold`,i(`toolbar.bold`),(0,Q.jsx)(`b`,{children:`B`}),{on:f.bold,disabled:!l,onClick:R(`bold`)}),L(`tb-italic`,i(`toolbar.italic`),(0,Q.jsx)(`i`,{children:`I`}),{on:f.italic,disabled:!l,onClick:R(`italic`)}),L(`tb-underline`,i(`toolbar.underline`),(0,Q.jsx)(`u`,{children:`U`}),{on:f.underline,disabled:!l,onClick:R(`underline`)}),L(`tb-strike`,i(`toolbar.strike`),(0,Q.jsx)(`s`,{children:`S`}),{on:f.strike,disabled:!l,onClick:R(`strike`)}),L(`tb-color`,i(`toolbar.color`),(0,Q.jsxs)(`span`,{className:`color-glyph`,children:[`A`,(0,Q.jsx)(`i`,{style:{background:h}})]}),{ref:S,disabled:!l,on:y===`color`,onClick:()=>b(y===`color`?null:`color`)}),(0,Q.jsx)(op,{open:y===`color`,anchor:S,onClose:x,id:`pop-color`,className:`pop-colors`,children:(0,Q.jsx)(ep,{docColors:g,current:h,onPick:j})}),(0,Q.jsx)(`span`,{className:`tb-sep`}),cp.map(e=>(0,Q.jsx)(v.Fragment,{children:L(`tb-align-${e.id}`,i(e.label),(0,Q.jsx)($,{name:e.icon}),{on:l&&m===e.id,disabled:!l,onClick:()=>ae(e.id)})},e.id)),L(`tb-spacing`,i(`toolbar.spacing`),(0,Q.jsx)($,{name:`spacing`}),{ref:C,disabled:!l,on:y===`spacing`,onClick:()=>b(y===`spacing`?null:`spacing`)}),(0,Q.jsxs)(op,{open:y===`spacing`,anchor:C,onClose:x,id:`pop-spacing`,children:[(0,Q.jsx)(fp,{id:`tb-line-height`,label:i(`toolbar.lineHeight`),min:.8,max:3,step:.05,value:Wf(d),format:e=>e.toFixed(2),onChange:e=>ie({"line-height":String(Math.round(e*100)/100)},`line-height`,`lh`)}),(0,Q.jsx)(fp,{id:`tb-letter-spacing`,label:i(`toolbar.letterSpacing`),min:-.1,max:.5,step:.005,value:Gf(d),format:e=>`${Math.round(e*1e3)}‰`,onChange:e=>ie({"letter-spacing":`${Math.round(e*1e3)/1e3}em`},`letter-spacing`,`ls`)})]}),L(`tb-uppercase`,i(`toolbar.uppercase`),(0,Q.jsx)(`span`,{className:`aa`,children:`aA`}),{on:f.uppercase,disabled:!l,onClick:R(`uppercase`)}),L(`tb-opacity`,i(`toolbar.opacity`),(0,Q.jsx)($,{name:`opacity`}),{ref:w,on:y===`opacity`,onClick:()=>b(y===`opacity`?null:`opacity`)}),(0,Q.jsx)(op,{open:y===`opacity`,anchor:w,onClose:x,id:`pop-opacity`,children:(0,Q.jsx)(fp,{id:`tb-opacity-range`,label:i(`toolbar.opacity`),min:0,max:100,step:1,value:Math.round(Kf(d)*100),format:e=>`${e}%`,onChange:e=>ie({opacity:e>=100?null:String(e/100)},`opacity`,`opacity`)})}),L(`tb-clear`,i(`toolbar.clear`),(0,Q.jsx)($,{name:`eraser`}),{disabled:!l,onClick:R(`clear`)}),(0,Q.jsx)(`span`,{className:`tb-sep`}),L(`tb-copy-style`,i(`toolbar.copyStyle`),(0,Q.jsx)($,{name:`brush`}),{disabled:!l,onClick:t.copyStyle}),L(`tb-paste-style`,i(`toolbar.pasteStyle`),(0,Q.jsx)($,{name:`paste`}),{disabled:!l,onClick:t.pasteStyle}),u!==null&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`tb-sep`}),(0,Q.jsxs)(`button`,{ref:T,type:`button`,id:`tb-replace`,className:`tb-btn small fmt wide${y===`image`?` on`:``}`,title:i(`toolbar.replaceImage`),onClick:()=>b(y===`image`?null:`image`),children:[(0,Q.jsx)($,{name:`replace`}),` `,(0,Q.jsx)(`span`,{className:`fmt-text`,children:i(`toolbar.replaceImage`)})]}),(0,Q.jsx)(op,{open:y===`image`,anchor:T,onClose:x,id:`pop-image`,className:`pop-image`,children:(0,Q.jsx)(If,{controller:e,id:u,onDone:x})}),(0,Q.jsxs)(`button`,{type:`button`,id:`tb-crop`,className:`tb-btn small fmt wide${r.id===u?` on`:``}`,title:i(`toolbar.crop`),onClick:()=>r.setId(r.id===u?null:u),children:[(0,Q.jsx)($,{name:`crop`}),` `,(0,Q.jsx)(`span`,{className:`fmt-text`,children:i(`toolbar.crop`)})]})]}),(0,Q.jsx)(`span`,{className:`fmt-spacer`}),(0,Q.jsxs)(`button`,{type:`button`,id:`tb-block`,className:`tb-btn small fmt wide`,disabled:!s,title:i(`toolbar.block`),onClick:n,children:[(0,Q.jsx)($,{name:`block`}),` `,(0,Q.jsx)(`span`,{className:`fmt-text`,children:i(`toolbar.block`)})]})]})}var mp=112,hp=84,gp=450,_p=`${vo}
44
44
  body .slide:not(.ed-cur) { display: none !important; }
45
45
  * { pointer-events: none !important; }`;function vp(e,t,n){let[r,i]=(0,v.useState)({}),a=(0,v.useRef)(new Map),o=(0,v.useMemo)(vs,[]),s=(0,v.useRef)(!1);return(0,v.useEffect)(()=>{if(t.docState!==`ready`)return;let r=setTimeout(()=>{let t=e.index(),r=ma(t),c=r[0],l=r[r.length-1];if(!c||!l)return;let u=t.source.slice(0,c.start)+t.source.slice(l.end),d={},f=new Set;for(let e of r){f.add(e.id);let r=t.source.slice(e.start,e.end),i=a.current.get(e.id);(!i||i.shared!==u||i.slice!==r)&&(i={shared:u,slice:r,html:co(t,{frameCSS:_p,baseHref:n,imageOrigins:o,currentPageId:e.id})},a.current.set(e.id,i)),d[e.id]=i.html}for(let e of[...a.current.keys()])f.has(e)||a.current.delete(e);s.current=!0,i(d)},s.current?gp:0);return()=>clearTimeout(r)},[e,t.docState,t.sourceVersion,n,o]),r}function yp(e){let t=e.contentDocument,n=t?.querySelector(`.ed-cur`);if(!t||!n)return;let r=n.getBoundingClientRect();(r.left!==0||r.top!==0)&&t.documentElement.style.setProperty(`translate`,`${-r.left}px ${-r.top}px`)}function bp({page:e,position:t,html:n,active:r,dropBefore:i,dropAfter:a,onOpen:o,onMenu:s,onKey:c,dragProps:l}){let u=af(),d=Math.min(mp/e.width,hp/e.height),f=u(`pages.page`,{n:t+1});return(0,Q.jsxs)(`div`,{className:`thumb${r?` active`:``}${i?` drop-before`:``}${a?` drop-after`:``}`,role:`button`,tabIndex:0,draggable:!0,title:e.name?`${t+1}. ${e.name}`:f,"aria-label":f,"aria-current":r?`page`:void 0,"data-page-id":e.id,onClick:o,onKeyDown:c,onContextMenu:e=>{e.preventDefault(),s(e.clientX,e.clientY)},...l,children:[(0,Q.jsx)(`div`,{className:`thumb-view`,style:{width:Math.round(e.width*d),height:Math.round(e.height*d)},children:n!==void 0&&(0,Q.jsx)(`iframe`,{className:`thumb-frame`,sandbox:`allow-same-origin`,srcDoc:n,tabIndex:-1,"aria-hidden":`true`,title:f,style:{width:e.width,height:e.height,transform:`scale(${d})`},onLoad:e=>yp(e.currentTarget)})}),(0,Q.jsx)(`span`,{className:`thumb-num`,children:t+1})]})}function xp({controller:e,snap:t,baseHref:n,toast:r}){let i=af(),a=vp(e,t,n),[o,s]=(0,v.useState)(null),[c,l]=(0,v.useState)(null);Md(o!==null,()=>s(null));let{pages:u}=t,d=(0,v.useRef)(null);(0,v.useEffect)(()=>{d.current?.querySelector(`.thumb.active`)?.scrollIntoView({block:`nearest`,inline:`nearest`})},[t.currentPageId]);let f=t=>{wd(e,t)&&r(i(`toast.pageDeleted`))},p=e=>u.findIndex(t=>t.id===e),m=t=>n=>{let r=p(t.id),i=n.ctrlKey||n.metaKey,a=!0;n.key===`Delete`||n.key===`Backspace`?f(t.id):i&&n.key.toLowerCase()===`d`?Cd(e,t.id):n.altKey&&n.key===`ArrowLeft`?Td(e,t.id,r-1):n.altKey&&n.key===`ArrowRight`?Td(e,t.id,r+1):n.key===`Enter`||n.key===` `?e.setCurrentPage(t.id):a=!1,a&&(n.preventDefault(),n.stopPropagation())},h=t=>({onDragStart:e=>{e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t.id),l({from:t.id,slot:null})},onDragOver:e=>{if(!c)return;e.preventDefault();let n=e.currentTarget.getBoundingClientRect(),r=p(t.id)+ +(e.clientX>n.left+n.width/2);r!==c.slot&&l({from:c.from,slot:r})},onDrop:t=>{t.preventDefault(),c&&c.slot!==null&&Td(e,c.from,Ed(p(c.from),c.slot)),l(null)},onDragEnd:()=>l(null)}),g=(0,v.useMemo)(()=>o?p(o.id):-1,[o,u]);return(0,Q.jsxs)(`div`,{className:`filmstrip-wrap`,children:[(0,Q.jsx)(`div`,{id:`filmstrip`,className:`filmstrip`,ref:d,role:`list`,"aria-label":i(`pages.label`),children:u.map((n,r)=>(0,Q.jsx)(bp,{page:n,position:r,html:a[n.id],active:n.id===t.currentPageId,dropBefore:c?.slot===r&&c.from!==n.id,dropAfter:c?.slot===u.length&&r===u.length-1,onOpen:()=>e.setCurrentPage(n.id),onMenu:(e,t)=>s({x:e,y:t,id:n.id}),onKey:m(n),dragProps:h(n)},n.id))}),o&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`menu-scrim`,onMouseDown:()=>s(null),onContextMenu:e=>{e.preventDefault(),s(null)}}),(0,Q.jsxs)(`div`,{className:`popover ctx-menu`,role:`menu`,style:{left:Math.min(o.x,window.innerWidth-180),top:Math.max(8,o.y-4-140)},children:[(0,Q.jsx)(`button`,{type:`button`,role:`menuitem`,className:`menu-item`,onClick:()=>{s(null),Cd(e,o.id)},children:i(`pages.duplicate`)}),(0,Q.jsx)(`button`,{type:`button`,role:`menuitem`,className:`menu-item`,disabled:g<=0,onClick:()=>{s(null),Td(e,o.id,g-1)},children:i(`pages.moveLeft`)}),(0,Q.jsx)(`button`,{type:`button`,role:`menuitem`,className:`menu-item`,disabled:g<0||g>=u.length-1,onClick:()=>{s(null),Td(e,o.id,g+1)},children:i(`pages.moveRight`)}),(0,Q.jsx)(`button`,{type:`button`,role:`menuitem`,className:`menu-item danger`,disabled:u.length<=1,onClick:()=>{s(null),f(o.id)},children:i(`pages.delete`)})]})]})]})}var Sp=.5,Cp=(e,t)=>[e,e+t/2,e+t];function wp(e,t,n){let r=null;for(let i of e)for(let e of t){let t=Math.abs(e-i);t<=n&&(r===null||t<r.distance)&&(r={adjust:e-i,distance:t})}return r}function Tp(e,t,n,r){let i=[{x:0,y:0,width:n.width,height:n.height},...t],a=i.flatMap(e=>Cp(e.x,e.width)),o=i.flatMap(e=>Cp(e.y,e.height)),s=wp(Cp(e.x,e.width),a,r),c=wp(Cp(e.y,e.height),o,r),l=s?.adjust??0,u=c?.adjust??0,d={...e,x:e.x+l,y:e.y+u},f=[],p=(e,t,n,r)=>{let[i,a]=e===`x`?[Math.min(n.y,r.y),Math.max(n.y+n.height,r.y+r.height)]:[Math.min(n.x,r.x),Math.max(n.x+n.width,r.x+r.width)];f.some(n=>n.axis===e&&Math.abs(n.pos-t)<Sp&&n.from===i&&n.to===a)||f.push({axis:e,pos:t,from:i,to:a})};if(s)for(let e of i)for(let t of Cp(e.x,e.width))Cp(d.x,d.width).some(e=>Math.abs(e-t)<Sp)&&p(`x`,t,d,e);if(c)for(let e of i)for(let t of Cp(e.y,e.height))Cp(d.y,d.height).some(e=>Math.abs(e-t)<Sp)&&p(`y`,t,d,e);return{dx:l,dy:u,guides:f}}function Ep(e){if(e.length===0)return null;let t=Math.min(...e.map(e=>e.x)),n=Math.min(...e.map(e=>e.y)),r=Math.max(...e.map(e=>e.x+e.width)),i=Math.max(...e.map(e=>e.y+e.height));return{x:t,y:n,width:r-t,height:i-n}}function Dp(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function Op(e,t,n,r){return{x:Math.min(e,n),y:Math.min(t,r),width:Math.abs(n-e),height:Math.abs(r-t)}}var kp={active:null,guides:[],tip:null,marquee:null},Ap=[...Hd,`font-size`,`box-sizing`,`padding-left`,`padding-right`,`padding-top`,`padding-bottom`,`border-left-width`,`border-right-width`,`border-top-width`,`border-bottom-width`],jp=e=>{let t=Number.parseFloat(e??``);return Number.isFinite(t)?t:0},Mp=class{deps;g=null;view=kp;constructor(e){this.deps=e}attach(){let e=this.deps.controller.onFrameEvent(e=>this.onFrame(e));return()=>{e(),this.cancel()}}get active(){return this.g!==null}onFrame(e){if(e.type!==`pointer`)return;let t=this.deps.controller;switch(e.action){case`down`:this.down(e);break;case`move`:this.update({x:e.x,y:e.y},e.alt);break;case`up`:this.finish();break;case`dblclick`:this.cancel(),e.id!==null&&Wa(t.index(),e.id)===`text`&&t.beginTextEdit(e.id,{x:e.x,y:e.y});break;case`contextmenu`:e.id!==null&&!t.getSnapshot().selection.includes(e.id)&&t.select([e.id])}}down(e){let t=this.deps.controller;this.g&&this.cancel();let n={x:e.x,y:e.y,scale:1},r=(e.alt||e.meta)&&e.deepId!==null?e.deepId:e.id;if(r===null){let r=e.shift?[...t.getSnapshot().selection]:[];this.g={kind:`marquee`,origin:n,base:r,additive:e.shift,box:null};return}if(e.shift){t.select([r],{additive:!0});return}let i=t.getSnapshot().selection,a=i.includes(r);a||t.select([r]),this.g={kind:`press`,origin:n,items:[...t.getSnapshot().selection],collapseTo:a&&i.length>1?r:null}}startPillMove(e,t){let n=[...this.deps.controller.getSnapshot().selection];n.length!==0&&(this.g={kind:`press`,origin:{x:e,y:t,scale:1/this.deps.getZoom()},items:n,collapseTo:null})}startResize(e,t,n){let r=this.deps.controller,i=r.getSnapshot().selection[0];if(i===void 0||r.getSnapshot().selection.length!==1)return;let a=this.rectOf(i);if(!a)return;let o=r.styles(i,Ap),s=o[`box-sizing`]===`border-box`;this.g={kind:`resize`,origin:{x:t,y:n,scale:1/this.deps.getZoom()},id:i,handle:e,start:a,place:Ud(o),fontSize:jp(o[`font-size`])||16,extra:s?{width:0,height:0}:{width:jp(o[`padding-left`])+jp(o[`padding-right`])+jp(o[`border-left-width`])+jp(o[`border-right-width`]),height:jp(o[`padding-top`])+jp(o[`padding-bottom`])+jp(o[`border-top-width`])+jp(o[`border-bottom-width`])},dx:0,dy:0,changed:!1}}overlayMove(e,t,n){this.update({x:e,y:t},n)}overlayUp(){this.finish()}rectOf(e){let t=this.deps.controller,n=t.getSnapshot().rects[e];return n||=(t.measure([e]),t.getSnapshot().rects[e]),n?{x:n.x,y:n.y,width:n.width,height:n.height}:null}setView(e){this.view=e,this.deps.onView(e)}update(e,t){let n=this.g;if(!n)return;let r=(e.x-n.origin.x)*n.origin.scale,i=(e.y-n.origin.y)*n.origin.scale,a=this.deps.getZoom(),o=Math.hypot(r,i)*a>=3;switch(n.kind){case`press`:o&&this.beginMove(n)&&this.update(e,t);break;case`move`:this.updateMove(n,r,i,t,a);break;case`resize`:this.updateResize(n,r,i);break;case`marquee`:(n.box!==null||o)&&(n.box=Op(n.origin.x,n.origin.y,e.x,e.y),this.setView({active:`marquee`,guides:[],tip:null,marquee:n.box}))}}beginMove(e){let t=this.deps.controller,n=t.index(),r=Pd(n,e.items),i=r.map(e=>this.rectOf(e));if(r.length===0||i.some(e=>e===null))return!1;let a=Ep(i);if(!a)return!1;let o=new Set(r),s=[];for(let[e,i]of Object.entries(t.getSnapshot().rects))o.has(e)||r.some(t=>Nd(n,e,t))||s.push({x:i.x,y:i.y,width:i.width,height:i.height});return this.g={kind:`move`,origin:e.origin,items:r.map(e=>({id:e,place:Ud(t.styles(e,Hd))})),start:a,others:s,dx:0,dy:0},!0}moveUpdates(e){return e.items.map(t=>({kind:`style`,id:t.id,props:Kd(t.place,e.dx,e.dy)}))}updateMove(e,t,n,r,i){let a=this.deps.controller,o=t,s=n,c=[];if(!r){let t=Tp({...e.start,x:e.start.x+o,y:e.start.y+s},e.others,a.pageSize(),6/i);o+=t.dx,s+=t.dy,c=t.guides}e.dx=Math.round(o),e.dy=Math.round(s),a.livePreview(this.moveUpdates(e)),a.measure(e.items.map(e=>e.id));let l=Math.round(e.start.x+e.dx),u=Math.round(e.start.y+e.dy);this.setView({active:`move`,guides:c,tip:{x:l,y:u+e.start.height,text:`${Math.round(e.start.width)} × ${Math.round(e.start.height)} · ${e.dx>=0?`+`:``}${e.dx}, ${e.dy>=0?`+`:``}${e.dy}`},marquee:null})}resizeProps(e,t,n){let r=Wa(this.deps.controller.index(),e.id),i=Yd({handle:e.handle,kind:r,start:e.start,dx:t,dy:n,fontSize:e.fontSize,extra:e.extra}),a={...i.props};return(i.shift.x!==0||i.shift.y!==0)&&Object.assign(a,Kd(e.place,i.shift.x,i.shift.y)),{props:a,width:i.width,height:i.height}}updateResize(e,t,n){let r=this.deps.controller;e.changed=!0,e.dx=t,e.dy=n;let{props:i}=this.resizeProps(e,t,n);r.livePreview([{kind:`style`,id:e.id,props:i}]),r.measure([e.id]);let a=r.getSnapshot().rects[e.id]??e.start;this.setView({active:`resize`,guides:[],tip:{x:a.x,y:a.y+a.height,text:`${Math.max(8,Math.round(a.width))} × ${Math.round(a.height)}`},marquee:null})}finish(){let e=this.g;if(!e)return;this.g=null;let t=this.deps.controller;switch(this.setView(kp),e.kind){case`press`:e.collapseTo!==null&&t.select([e.collapseTo]);break;case`move`:{let n=e.dx===0&&e.dy===0?[]:e.items.map(t=>({kind:`setStyle`,id:t.id,props:Kd(t.place,e.dx,e.dy)}));n.length===0?t.cancelLivePreview(e.items.map(e=>e.id)):t.applyBatch(n,`move`);break}case`resize`:if(!e.changed)break;t.applyBatch([{kind:`setStyle`,id:e.id,props:this.resizeProps(e,e.dx,e.dy).props}],`resize`);break;case`marquee`:this.finishMarquee(e)}}finishMarquee(e){let t=this.deps.controller;if(e.box===null){e.additive||t.select([]);return}let n=e.box,r=t.index(),i=Object.entries(t.getSnapshot().rects).filter(([,e])=>Dp(n,e)).map(([e])=>e),a=i.filter(e=>!i.some(t=>t!==e&&Nd(r,t,e)));t.select(e.additive?[...new Set([...e.base,...a])]:a)}cancel(){let e=this.g;return e?(this.g=null,e.kind===`move`?this.deps.controller.cancelLivePreview(e.items.map(e=>e.id)):e.kind===`resize`&&this.deps.controller.cancelLivePreview([e.id]),this.view!==kp&&this.setView(kp),!0):!1}},Np={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]};function Pp(e,t){let n=e.ctrl||e.meta,r=e.key.length===1?e.key.toLowerCase():e.key;if(n)return r===`s`?{type:`save`}:e.alt?r===`c`?{type:`copyStyle`}:r===`v`?{type:`pasteStyle`}:null:t.editing?Fp(r):r===`z`?e.shift?{type:`redo`}:{type:`undo`}:r===`y`?{type:`redo`}:r===`d`?t.selectionCount>0?{type:`duplicate`}:null:Fp(r);if(r===`Escape`)return{type:`escape`};if(t.editing)return null;if(t.selectionCount>0){if(t.selectionCount===1&&!e.alt&&(r===`+`||r===`=`||r===`-`||r===`_`))return{type:`scaleSelection`,direction:r===`+`||r===`=`?1:-1};if(r===`Delete`||r===`Backspace`)return{type:`delete`};if(r===`Enter`)return t.selectionCount===1?{type:`edit`}:null;let n=Np[r];if(n){if(e.alt)return n[0]===0?{type:`reorder`,direction:n[1]<0?`up`:`down`}:null;let t=e.shift?10:1;return{type:`nudge`,dx:n[0]*t,dy:n[1]*t}}return null}return!e.alt&&(r===`+`||r===`=`||r===`-`||r===`_`)?Fp(r):r===`ArrowLeft`||r===`PageUp`?{type:`page`,direction:`prev`}:r===`ArrowRight`||r===`PageDown`?{type:`page`,direction:`next`}:null}function Fp(e){return e===`=`||e===`+`?{type:`zoom`,mode:`in`}:e===`-`||e===`_`?{type:`zoom`,mode:`out`}:e===`0`?{type:`zoom`,mode:`fit`}:null}function Ip(e){let t=e;if(!t||typeof t.closest!=`function`)return!1;if(t.isContentEditable)return!0;let n=t.tagName;if(n===`TEXTAREA`||n===`SELECT`||t.closest(`.CodeMirror`))return!0;if(n===`INPUT`){let e=t.type;return e!==`button`&&e!==`checkbox`}return!1}function Lp({controller:e}){let t=af(),n=(0,v.useRef)(null);return(0,v.useEffect)(()=>n.current?.focus(),[]),(0,Q.jsx)(`div`,{id:`modal-conflict`,className:`modal-backdrop`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`conflict-title`,children:(0,Q.jsxs)(`div`,{className:`modal`,children:[(0,Q.jsx)(`h2`,{id:`conflict-title`,children:t(`conflict.title`)}),(0,Q.jsx)(`p`,{children:t(`conflict.body`)}),(0,Q.jsxs)(`div`,{className:`modal-actions`,children:[(0,Q.jsx)(`button`,{type:`button`,id:`conflict-reload`,className:`btn`,ref:n,onClick:()=>void e.reload(),children:t(`conflict.reload`)}),(0,Q.jsx)(`button`,{type:`button`,id:`conflict-overwrite`,className:`btn primary`,onClick:()=>void e.save({force:!0}),children:t(`conflict.overwrite`)})]})]})})}var Rp={items:[],more:!1};function zp({controller:e}){let t=af(),n=Mf(),r=sp(e),i=!!sd(),a=!!xs(),[o,s]=(0,v.useState)(`current`),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(Rp),[f,p]=(0,v.useState)(Rp),[m,h]=(0,v.useState)(1),[g,_]=(0,v.useState)(!1),[y,b]=(0,v.useState)(!1),[x,S]=(0,v.useState)(!1),[C,w]=(0,v.useState)(0),T=(0,v.useRef)(null);(0,v.useEffect)(()=>{if(!i&&!a)return;let e=!0;return _(!0),S(!1),(a?fetch(`/api/project-assets?tab=${o}&page=${m}`,{cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(`Project assets unavailable`);return await e.json()}):cd(`assets`,{tab:o,page:o===`history`?m:1})).then(t=>{e&&(o===`current`?d(t):p(e=>({items:m===1?t.items:[...e.items,...t.items],more:t.more})))}).catch(()=>{e&&S(!0)}).finally(()=>{e&&_(!1)}),()=>{e=!1}},[i,a,o,m,C]);let ee=bf(e.index()).map(({src:e},t)=>({src:e,name:`Image ${t+1}`})),E=o===`history`?f.items:[...new Map([...ee,...u.items].map(e=>[e.src,e])).values()],D=(t,n=e.getSnapshot().currentPageId)=>{let r=e.getSnapshot().pages.find(e=>e.id===n);if(!r)return;let i=document.createElement(`img`);i.setAttribute(`src`,a&&t.src.startsWith(`/assets/`)?`..`+t.src:t.src),i.alt=t.name;let o=Math.round(r.width*.46);i.style.cssText=`position:absolute;z-index:90;left:${Math.round(r.width*.1)}px;top:${Math.round(r.height*.12)}px;width:${o}px;height:auto;max-height:${Math.round(r.height*.7)}px;object-fit:contain`,e.apply({kind:`insertHTML`,parentId:r.id,beforeId:null,html:i.outerHTML},{label:`add image`})};return(0,Q.jsxs)(`div`,{className:`image-panel`,"data-panel-body":`images`,children:[(0,Q.jsxs)(`div`,{className:`panel-body`,children:[(0,Q.jsxs)(`div`,{className:`asset-tabs`,role:`tablist`,"aria-label":t(`panel.images`),children:[[`current`,`history`].map(e=>(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":o===e,disabled:e===`history`&&!i&&!a,onClick:()=>{e!==o&&l(null),e===`history`&&h(1),s(e)},children:t(a&&e===`history`?`assets.projectHistory`:`assets.${e}`)},e)),(0,Q.jsxs)(`button`,{type:`button`,className:`btn`,disabled:y||r.docState!==`ready`,onClick:()=>T.current?.click(),children:[(0,Q.jsx)($,{name:`upload`,size:13}),t(`assets.upload`)]}),(0,Q.jsx)(`input`,{ref:T,type:`file`,accept:`image/*`,hidden:!0,onChange:t=>{let r=t.currentTarget.files?.[0];if(t.currentTarget.value=``,!r)return;let o=e.getSnapshot().currentPageId;b(!0),(i?cd(`upload-asset`,r,18e4):a&&e.uploadImage?e.uploadImage(r):wf(r).then(e=>({src:e,name:r.name}))).then(e=>{D(e,o),h(1),w(e=>e+1)}).catch(n).finally(()=>b(!1))}})]}),g&&(0,Q.jsx)(`p`,{role:`status`,className:`p-hint`,children:t(`status.loading`)}),x&&(0,Q.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>w(e=>e+1),children:t(`assets.failed`)}),!g&&!x&&E.length===0&&(0,Q.jsx)(`p`,{className:`p-hint`,children:t(`assets.empty`)}),(0,Q.jsx)(`div`,{className:`asset-grid`,children:E.map(e=>(0,Q.jsx)(`button`,{type:`button`,title:e.name,"aria-pressed":c?.src===e.src,onClick:()=>l(t=>t?.src===e.src?null:e),children:(0,Q.jsx)(`img`,{src:e.src,alt:e.name,loading:`lazy`})},e.src))}),o===`history`&&f.more&&(0,Q.jsx)(`button`,{type:`button`,className:`btn`,disabled:g,onClick:()=>h(e=>e+1),children:t(`assets.more`)})]}),c&&(0,Q.jsx)(`footer`,{className:`asset-confirm`,children:(0,Q.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:r.docState!==`ready`||!r.currentPageId,onClick:()=>{D(c),l(null)},children:t(`assets.confirm`)})})]})}var Bp=[{id:`none`,px:0},{id:`subtle`,px:8},{id:`medium`,px:16},{id:`large`,px:32},{id:`full`,px:9999}],Vp=[{id:`none`,px:0},{id:`narrow`,px:12},{id:`medium`,px:24},{id:`wide`,px:48}],Hp=[{id:`none`,px:0},{id:`small`,px:12},{id:`medium`,px:24},{id:`large`,px:48}],Up=[{id:`none`,css:`none`},{id:`soft`,css:`0 4px 14px rgba(0,0,0,0.12)`},{id:`medium`,css:`0 8px 24px rgba(0,0,0,0.22)`},{id:`strong`,css:`0 14px 40px rgba(0,0,0,0.38)`}],Wp=[`none`,`solid`,`dashed`,`dotted`],Gp=[{id:`thin`,px:1},{id:`medium`,px:3},{id:`thick`,px:6}],Kp=[`top`,`right`,`bottom`,`left`],qp=[`top-left`,`top-right`,`bottom-right`,`bottom-left`];function Jp(e){let t=Number.parseFloat(e??``);return Number.isFinite(t)?t:0}function Yp(e,t){return{...Object.fromEntries(Kp.map(t=>[`${e}-${t}`,null])),[e]:`${Math.round(t)}px`}}function Xp(e){return{...Object.fromEntries(qp.map(e=>[`border-${e}-radius`,null])),"border-radius":`${Math.round(e)}px`}}function Zp(e,t){return e===`none`?{"border-style":`none`}:{"border-style":e,"border-width":`${Math.max(1,Math.round(t))}px`}}function Qp(e){return{"box-shadow":e}}function $p(e){let t=(e??``).replace(/\s+/g,``).toLowerCase();return t===``?null:Up.find(e=>e.css.replace(/\s+/g,``).toLowerCase()===t)?.id??null}function em(e){return Wp.includes(e??``)?e:`none`}var tm=[`background-color`,`border-top-left-radius`,`padding-top`,`margin-top`,`border-top-style`,`border-top-width`,`border-top-color`,`opacity`,`box-shadow`];function nm({items:e,active:t,label:n,onPick:r,prefix:i}){return(0,Q.jsx)(`div`,{className:`chips`,"data-presets":i,children:e.map(e=>(0,Q.jsx)(`button`,{type:`button`,className:`chip${t===e.id?` on`:``}`,"data-preset":e.id,onClick:()=>r(e),children:n(e.id)},e.id))})}function rm({id:e,value:t,max:n,onChange:r}){return(0,Q.jsxs)(`label`,{className:`slider-row bare`,children:[(0,Q.jsx)(`input`,{id:e,type:`range`,min:0,max:n,step:1,value:Math.min(n,Math.round(t)),onChange:e=>r(Number(e.target.value))}),(0,Q.jsx)(`output`,{children:Math.round(t)>n?`∞`:Math.round(t)})]})}function im({controller:e}){let t=af(),n=sp(e),r=tp(n),i=rp(e,n,tm),a=np(e,n.sourceVersion),o=r.join(`,`);if(r.length===0||n.docState!==`ready`)return(0,Q.jsx)(`div`,{className:`panel-body`,"data-panel-body":`block`,children:(0,Q.jsx)(`p`,{className:`p-hint`,children:t(`panel.selectHint`)})});let s=r[0],c=e.index().elements.get(s),l=r.length===1,u=l&&Pf(e,s),d=(t,n,i)=>{let a=r.map(e=>({kind:`setStyle`,id:e,props:t}));e.applyBatch(a,n,i?{coalesceKey:`${i}:${o}`}:void 0)},f=(e,t)=>t.find(t=>t.px===Math.round(e))?.id??null,p=e=>n=>t(`${e}.${n}`),m=_d(i[`background-color`]),h=(e,t)=>d({"background-color":e},`background`,t===`live`?`bg`:void 0),g=(e,t)=>d({"border-color":e},`border color`,t===`live`?`bc`:void 0),_=Jp(i[`border-top-left-radius`]),v=Jp(i[`padding-top`]),y=Jp(i[`margin-top`]),b=em(i[`border-top-style`]),x=Jp(i[`border-top-width`]),S=c?ra(Pi(c,`style`)??``,`box-shadow`):null,C=l?$p(S)??(S===null&&i[`box-shadow`]===`none`?`none`:null):null,w=(e,n,r)=>(0,Q.jsxs)(`section`,{className:`p-section`,"data-section":r,children:[(0,Q.jsx)(`h3`,{children:t(e)}),n]});return(0,Q.jsxs)(`div`,{className:`panel-body`,"data-panel-body":`block`,children:[r.length>1&&(0,Q.jsx)(`p`,{className:`p-hint`,children:t(`pill.selected`,{n:r.length})}),w(`block.background`,(0,Q.jsx)(ep,{docColors:a,current:m,allowNone:!0,onPick:h}),`background`),w(`block.radius`,(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(nm,{items:Bp,active:f(_,Bp),label:p(`block.radius`),prefix:`radius`,onPick:e=>d(Xp(e.px),`radius`)}),(0,Q.jsx)(rm,{id:`block-radius`,value:_,max:120,onChange:e=>d(Xp(e),`radius`,`radius`)})]}),`radius`),w(`block.padding`,(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(nm,{items:Vp,active:f(v,Vp),label:p(`block.padding`),prefix:`padding`,onPick:e=>d(Yp(`padding`,e.px),`padding`)}),(0,Q.jsx)(rm,{id:`block-padding`,value:v,max:120,onChange:e=>d(Yp(`padding`,e),`padding`,`padding`)})]}),`padding`),w(`block.margin`,(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(nm,{items:Hp,active:f(y,Hp),label:p(`block.margin`),prefix:`margin`,onPick:e=>d(Yp(`margin`,e.px),`margin`)}),(0,Q.jsx)(rm,{id:`block-margin`,value:y,max:120,onChange:e=>d(Yp(`margin`,e),`margin`,`margin`)})]}),`margin`),w(`block.border`,(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`chips`,"data-presets":`border-style`,children:Wp.map(e=>(0,Q.jsx)(`button`,{type:`button`,className:`chip${b===e?` on`:``}`,"data-preset":e,onClick:()=>d(Zp(e,x||2),`border`),children:t(`block.border.${e}`)},e))}),(0,Q.jsx)(`div`,{className:`chips`,"data-presets":`border-width`,children:Gp.map(e=>(0,Q.jsx)(`button`,{type:`button`,className:`chip${b!==`none`&&Math.round(x)===e.px?` on`:``}`,"data-preset":e.id,onClick:()=>d(Zp(b===`none`?`solid`:b,e.px),`border`),children:t(`block.borderWidth.${e.id}`)},e.id))}),(0,Q.jsx)(ep,{docColors:a,current:_d(i[`border-top-color`]),onPick:g})]}),`border`),w(`block.shadow`,(0,Q.jsx)(nm,{items:Up,active:C,label:p(`block.shadow`),prefix:`shadow`,onPick:e=>d(Qp(e.css),`shadow`)}),`shadow`),w(`block.opacity`,(0,Q.jsx)(rm,{id:`block-opacity`,value:Kf(i)*100,max:100,onChange:e=>d({opacity:e>=100?null:String(e/100)},`opacity`,`opacity`)}),`opacity`),u&&w(`block.size`,(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`p-hint`,children:t(`block.sizeHint`)}),(0,Q.jsx)(`button`,{type:`button`,id:`block-reset-size`,className:`btn wide`,onClick:()=>d({width:null,height:null},`reset size`),children:t(`block.resetSize`)})]}),`size`)]})}var am=o(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n||=self,n.CodeMirror=r())})(e,(function(){var e=navigator.userAgent,t=navigator.platform,n=/gecko\/\d/i.test(e),r=/MSIE \d/.test(e),i=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(e),a=/Edge\/(\d+)/.exec(e),o=r||i||a,s=o&&(r?document.documentMode||6:+(a||i)[1]),c=!a&&/WebKit\//.test(e),l=c&&/Qt\/\d+\.\d+/.test(e),u=!a&&/Chrome\/(\d+)/.exec(e),d=u&&+u[1],f=/Opera\//.test(e),p=/Apple Computer/.test(navigator.vendor),m=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(e),h=/PhantomJS/.test(e),g=p&&(/Mobile\/\w+/.test(e)||navigator.maxTouchPoints>2),_=/Android/.test(e),v=g||_||/webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(e),y=g||/Mac/.test(t),b=/\bCrOS\b/.test(e),x=/win/i.test(t),S=f&&e.match(/Version\/(\d*\.\d*)/);S&&=Number(S[1]),S&&S>=15&&(f=!1,c=!0);var C=y&&(l||f&&(S==null||S<12.11)),w=n||o&&s>=9;function T(e){return RegExp(`(^|\\s)`+e+`(?:$|\\s)\\s*`)}var ee=function(e,t){var n=e.className,r=T(t).exec(n);if(r){var i=n.slice(r.index+r[0].length);e.className=n.slice(0,r.index)+(i?r[1]+i:``)}};function E(e){for(var t=e.childNodes.length;t>0;--t)e.removeChild(e.firstChild);return e}function D(e,t){return E(e).appendChild(t)}function O(e,t,n,r){var i=document.createElement(e);if(n&&(i.className=n),r&&(i.style.cssText=r),typeof t==`string`)i.appendChild(document.createTextNode(t));else if(t)for(var a=0;a<t.length;++a)i.appendChild(t[a]);return i}function te(e,t,n,r){var i=O(e,t,n,r);return i.setAttribute(`role`,`presentation`),i}var k=document.createRange?function(e,t,n,r){var i=document.createRange();return i.setEnd(r||e,n),i.setStart(e,t),i}:function(e,t,n){var r=document.body.createTextRange();try{r.moveToElementText(e.parentNode)}catch{return r}return r.collapse(!0),r.moveEnd(`character`,n),r.moveStart(`character`,t),r};function A(e,t){if(t.nodeType==3&&(t=t.parentNode),e.contains)return e.contains(t);do if(t.nodeType==11&&(t=t.host),t==e)return!0;while(t=t.parentNode)}function ne(e){var t=e.ownerDocument||e,n;try{n=e.activeElement}catch{n=t.body||null}for(;n&&n.shadowRoot&&n.shadowRoot.activeElement;)n=n.shadowRoot.activeElement;return n}function re(e,t){var n=e.className;T(t).test(n)||(e.className+=(n?` `:``)+t)}function ie(e,t){for(var n=e.split(` `),r=0;r<n.length;r++)n[r]&&!T(n[r]).test(t)&&(t+=` `+n[r]);return t}var j=function(e){e.select()};g?j=function(e){e.selectionStart=0,e.selectionEnd=e.value.length}:o&&(j=function(e){try{e.select()}catch{}});function M(e){return e.display.wrapper.ownerDocument}function ae(e){return oe(e.display.wrapper)}function oe(e){return e.getRootNode?e.getRootNode():e.ownerDocument}function N(e){return M(e).defaultView}function P(e){var t=Array.prototype.slice.call(arguments,1);return function(){return e.apply(null,t)}}function F(e,t,n){for(var r in t||={},e)e.hasOwnProperty(r)&&(n!==!1||!t.hasOwnProperty(r))&&(t[r]=e[r]);return t}function I(e,t,n,r,i){t??(t=e.search(/[^\s\u00a0]/),t==-1&&(t=e.length));for(var a=r||0,o=i||0;;){var s=e.indexOf(` `,a);if(s<0||s>=t)return o+(t-a);o+=s-a,o+=n-o%n,a=s+1}}var L=function(){this.id=null,this.f=null,this.time=0,this.handler=P(this.onTimeout,this)};L.prototype.onTimeout=function(e){e.id=0,e.time<=+new Date?e.f():setTimeout(e.handler,e.time-+new Date)},L.prototype.set=function(e,t){this.f=t;var n=+new Date+e;(!this.id||n<this.time)&&(clearTimeout(this.id),this.id=setTimeout(this.handler,e),this.time=n)};function R(e,t){for(var n=0;n<e.length;++n)if(e[n]==t)return n;return-1}var se=50,z={toString:function(){return`CodeMirror.Pass`}},ce={scroll:!1},le={origin:`*mouse`},B={origin:`+move`};function V(e,t,n){for(var r=0,i=0;;){var a=e.indexOf(` `,r);a==-1&&(a=e.length);var o=a-r;if(a==e.length||i+o>=t)return r+Math.min(o,t-i);if(i+=a-r,i+=n-i%n,r=a+1,i>=t)return r}}var ue=[``];function de(e){for(;ue.length<=e;)ue.push(H(ue)+` `);return ue[e]}function H(e){return e[e.length-1]}function fe(e,t){for(var n=[],r=0;r<e.length;r++)n[r]=t(e[r],r);return n}function pe(e,t,n){for(var r=0,i=n(t);r<e.length&&n(e[r])<=i;)r++;e.splice(r,0,t)}function me(){}function he(e,t){var n;return Object.create?n=Object.create(e):(me.prototype=e,n=new me),t&&F(t,n),n}var U=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;function ge(e){return/\w/.test(e)||e>`€`&&(e.toUpperCase()!=e.toLowerCase()||U.test(e))}function _e(e,t){return t?t.source.indexOf(`\\w`)>-1&&ge(e)?!0:t.test(e):ge(e)}function ve(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}var ye=/[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;function W(e){return e.charCodeAt(0)>=768&&ye.test(e)}function be(e,t,n){for(;(n<0?t>0:t<e.length)&&W(e.charAt(t));)t+=n;return t}function xe(e,t,n){for(var r=t>n?-1:1;;){if(t==n)return t;var i=(t+n)/2,a=r<0?Math.ceil(i):Math.floor(i);if(a==t)return e(a)?t:n;e(a)?n=a:t=a+r}}function Se(e,t,n,r){if(!e)return r(t,n,`ltr`,0);for(var i=!1,a=0;a<e.length;++a){var o=e[a];(o.from<n&&o.to>t||t==n&&o.to==t)&&(r(Math.max(o.from,t),Math.min(o.to,n),o.level==1?`rtl`:`ltr`,a),i=!0)}i||r(t,n,`ltr`)}var Ce=null;function we(e,t,n){var r;Ce=null;for(var i=0;i<e.length;++i){var a=e[i];if(a.from<t&&a.to>t)return i;a.to==t&&(a.from!=a.to&&n==`before`?r=i:Ce=i),a.from==t&&(a.from!=a.to&&n!=`before`?r=i:Ce=i)}return r??Ce}var Te=(function(){function e(e){return e<=247?`bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN`.charAt(e):1424<=e&&e<=1524?`R`:1536<=e&&e<=1785?`nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111`.charAt(e-1536):1774<=e&&e<=2220?`r`:8192<=e&&e<=8203?`w`:e==8204?`b`:`L`}var t=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,n=/[stwN]/,r=/[LRr]/,i=/[Lb1n]/,a=/[1n]/;function o(e,t,n){this.level=e,this.from=t,this.to=n}return function(s,c){var l=c==`ltr`?`L`:`R`;if(s.length==0||c==`ltr`&&!t.test(s))return!1;for(var u=s.length,d=[],f=0;f<u;++f)d.push(e(s.charCodeAt(f)));for(var p=0,m=l;p<u;++p){var h=d[p];h==`m`?d[p]=m:m=h}for(var g=0,_=l;g<u;++g){var v=d[g];v==`1`&&_==`r`?d[g]=`n`:r.test(v)&&(_=v,v==`r`&&(d[g]=`R`))}for(var y=1,b=d[0];y<u-1;++y){var x=d[y];x==`+`&&b==`1`&&d[y+1]==`1`?d[y]=`1`:x==`,`&&b==d[y+1]&&(b==`1`||b==`n`)&&(d[y]=b),b=x}for(var S=0;S<u;++S){var C=d[S];if(C==`,`)d[S]=`N`;else if(C==`%`){var w=void 0;for(w=S+1;w<u&&d[w]==`%`;++w);for(var T=S&&d[S-1]==`!`||w<u&&d[w]==`1`?`1`:`N`,ee=S;ee<w;++ee)d[ee]=T;S=w-1}}for(var E=0,D=l;E<u;++E){var O=d[E];D==`L`&&O==`1`?d[E]=`L`:r.test(O)&&(D=O)}for(var te=0;te<u;++te)if(n.test(d[te])){var k=void 0;for(k=te+1;k<u&&n.test(d[k]);++k);for(var A=(te?d[te-1]:l)==`L`,ne=A==((k<u?d[k]:l)==`L`)?A?`L`:`R`:l,re=te;re<k;++re)d[re]=ne;te=k-1}for(var ie=[],j,M=0;M<u;)if(i.test(d[M])){var ae=M;for(++M;M<u&&i.test(d[M]);++M);ie.push(new o(0,ae,M))}else{var oe=M,N=ie.length,P=+(c==`rtl`);for(++M;M<u&&d[M]!=`L`;++M);for(var F=oe;F<M;)if(a.test(d[F])){oe<F&&(ie.splice(N,0,new o(1,oe,F)),N+=P);var I=F;for(++F;F<M&&a.test(d[F]);++F);ie.splice(N,0,new o(2,I,F)),N+=P,oe=F}else++F;oe<M&&ie.splice(N,0,new o(1,oe,M))}return c==`ltr`&&(ie[0].level==1&&(j=s.match(/^\s+/))&&(ie[0].from=j[0].length,ie.unshift(new o(0,0,j[0].length))),H(ie).level==1&&(j=s.match(/\s+$/))&&(H(ie).to-=j[0].length,ie.push(new o(0,u-j[0].length,u)))),c==`rtl`?ie.reverse():ie}})();function Ee(e,t){var n=e.order;return n??=e.order=Te(e.text,t),n}var De=[],G=function(e,t,n){if(e.addEventListener)e.addEventListener(t,n,!1);else if(e.attachEvent)e.attachEvent(`on`+t,n);else{var r=e._handlers||={};r[t]=(r[t]||De).concat(n)}};function Oe(e,t){return e._handlers&&e._handlers[t]||De}function ke(e,t,n){if(e.removeEventListener)e.removeEventListener(t,n,!1);else if(e.detachEvent)e.detachEvent(`on`+t,n);else{var r=e._handlers,i=r&&r[t];if(i){var a=R(i,n);a>-1&&(r[t]=i.slice(0,a).concat(i.slice(a+1)))}}}function Ae(e,t){var n=Oe(e,t);if(n.length)for(var r=Array.prototype.slice.call(arguments,2),i=0;i<n.length;++i)n[i].apply(null,r)}function je(e,t,n){return typeof t==`string`&&(t={type:t,preventDefault:function(){this.defaultPrevented=!0}}),Ae(e,n||t.type,e,t),Le(t)||t.codemirrorIgnore}function Me(e){var t=e._handlers&&e._handlers.cursorActivity;if(t)for(var n=e.curOp.cursorActivityHandlers||(e.curOp.cursorActivityHandlers=[]),r=0;r<t.length;++r)R(n,t[r])==-1&&n.push(t[r])}function Ne(e,t){return Oe(e,t).length>0}function Pe(e){e.prototype.on=function(e,t){G(this,e,t)},e.prototype.off=function(e,t){ke(this,e,t)}}function Fe(e){e.preventDefault?e.preventDefault():e.returnValue=!1}function Ie(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0}function Le(e){return e.defaultPrevented==null?e.returnValue==0:e.defaultPrevented}function Re(e){Fe(e),Ie(e)}function ze(e){return e.target||e.srcElement}function Be(e){var t=e.which;return t??(e.button&1?t=1:e.button&2?t=3:e.button&4&&(t=2)),y&&e.ctrlKey&&t==1&&(t=3),t}var Ve=function(){if(o&&s<9)return!1;var e=O(`div`);return`draggable`in e||`dragDrop`in e}(),He;function Ue(e){if(He==null){var t=O(`span`,`​`);D(e,O(`span`,[t,document.createTextNode(`x`)])),e.firstChild.offsetHeight!=0&&(He=t.offsetWidth<=1&&t.offsetHeight>2&&!(o&&s<8))}var n=He?O(`span`,`​`):O(`span`,`\xA0`,null,`display: inline-block; width: 1px; margin-right: -1px`);return n.setAttribute(`cm-text`,``),n}var We;function Ge(e){if(We!=null)return We;var t=D(e,document.createTextNode(`AخA`)),n=k(t,0,1).getBoundingClientRect(),r=k(t,1,2).getBoundingClientRect();return E(e),!n||n.left==n.right?!1:We=r.right-n.right<3}var Ke=`
46
46
 
@@ -69,4 +69,4 @@ b`.split(/\n/).length==3?function(e){return e.split(/\r\n?|\n/)}:function(e){for
69
69
  `}),r.startTagEnd-r.start>100&&r.attrs.length>2){let e=[...r.attrs].sort((e,t)=>e.start-t.start);for(let n=1;n<e.length;n++){let r=e[n-1].end,a=e[n].start;/^ +$/.test(t.slice(r,a))&&i.push({start:r,end:a,text:`
70
70
  `})}}r.tag===`style`&&r.endTagStart!==null&&r.startTagEnd<r.endTagStart&&(/\s/.test(t[r.startTagEnd]??``)||i.push({start:r.startTagEnd,end:r.startTagEnd,text:`
71
71
  `}),/\s/.test(t[r.endTagStart-1]??``)||i.push({start:r.endTagStart,end:r.endTagStart,text:`
72
- `}))}let a=t;for(let{start:e,end:t,text:n}of i.sort((e,t)=>t.start-e.start))a=a.slice(0,e)+n+a.slice(t);return a}var fm=/(data:[a-z0-9.+/-]*;base64,)([A-Za-z0-9+/=]{1500,})/gi,pm=/\[\[popost-data-(\d+):[^\]]*\]\]/g,mm=e=>e>=1048576?`${(e/1048576).toFixed(1)} MB`:`${Math.max(1,Math.round(e/1024))} KB`;function hm(e){let t=[];return{text:e.replace(fm,(e,n,r)=>(t.push(r),`${n}[[popost-data-${t.length}:${mm(r.length)}]]`)),restore:e=>e.replace(pm,(e,n)=>t[Number(n)-1]??e)}}var gm={empty:`code.err.empty`,"too-large":`code.err.too-large`,"no-slide":`code.err.no-slide`,unsafe:`code.err.unsafe`,rejected:`code.err.rejected`,"not-ready":`code.err.rejected`};function _m({controller:e,onClose:t}){let n=af(),r=sp(e),i=(0,v.useRef)(null),a=(0,v.useRef)(null),o=(0,v.useRef)(null),s=(0,v.useRef)(null),c=(0,v.useRef)(!1),l=(0,v.useRef)(!1),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(!0),[g,_]=(0,v.useState)({key:`code.status.idle`}),y=(0,v.useCallback)(e=>{l.current=e,d(e)},[]),b=(0,v.useCallback)(()=>{let t=o.current;if(!t)return;let n=hm(dm(e.index()));s.current=n,c.current=!0,t.setValue(n.text),c.current=!1,y(!1)},[e,y]),x=(0,v.useCallback)(async()=>{let t=o.current,n=s.current;if(!(!t||!n||!l.current||f)){p(!0);try{let r=e.replaceSource(n.restore(t.getValue()));if(r!==null){let e=gm[r];_(e?{key:e,error:!0}:{key:`code.err.rejected`,error:!0,raw:r});return}b(),await e.save();let i=e.getSnapshot();_(i.saveState===`saved`?{key:`code.status.saved`}:{key:`code.status.appliedUnsaved`,error:i.saveState===`error`})}finally{p(!1)}}},[f,e,b]),S=(0,v.useRef)(x);S.current=x,(0,v.useEffect)(()=>{let e=i.current;if(!e)return;let t=om.default.fromTextArea(e,{mode:`htmlmixed`,lineNumbers:!0,lineWrapping:!0,tabSize:2,indentUnit:2,viewportMargin:10,extraKeys:{"Ctrl-S":()=>void S.current(),"Cmd-S":()=>void S.current()}});o.current=t,t.on(`change`,()=>{c.current||(y(!0),_({key:`code.status.dirty`}))}),b();let n=a.current,r=n&&typeof ResizeObserver<`u`?new ResizeObserver(()=>t.refresh()):null;n&&r?.observe(n);let s=requestAnimationFrame(()=>t.refresh()),l=setTimeout(()=>t.refresh(),230);return()=>{cancelAnimationFrame(s),clearTimeout(l),r?.disconnect(),t.toTextArea(),o.current=null}},[b,y]);let C=(0,v.useRef)(r.sourceVersion);(0,v.useEffect)(()=>{C.current!==r.sourceVersion&&(C.current=r.sourceVersion,l.current||b())},[r.sourceVersion,b]);let w=()=>{o.current?.setOption(`lineWrapping`,!m),h(!m)},T=async()=>{let e=o.current;if(!(!e||!s.current))try{await navigator.clipboard.writeText(s.current.restore(e.getValue())),_({key:`code.status.copied`})}catch{_({key:`code.status.copyFailed`,error:!0})}},ee=g.raw?`${n(g.key)}: ${g.raw}`:n(g.key);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`panel-head`,children:[(0,Q.jsx)(`h2`,{children:n(`panel.code`)}),(0,Q.jsxs)(`div`,{className:`code-header-tools`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`tb-btn small`,onClick:w,children:[(0,Q.jsx)($,{name:`wrap`,size:14}),n(m?`code.disableWrap`:`code.enableWrap`)]}),(0,Q.jsxs)(`button`,{type:`button`,className:`tb-btn small`,disabled:r.docState!==`ready`,onClick:()=>void T(),children:[(0,Q.jsx)($,{name:`duplicate`,size:14}),n(`code.copy`)]}),(0,Q.jsx)(`button`,{type:`button`,id:`panel-close`,className:`tb-btn small`,title:n(`panel.close`),"aria-label":n(`panel.close`),onClick:t,children:(0,Q.jsx)($,{name:`close`,size:14})})]})]}),(0,Q.jsxs)(`div`,{className:`panel-body code-panel`,"data-panel-body":`code`,children:[(0,Q.jsx)(`div`,{ref:a,className:`code-host`,children:(0,Q.jsx)(`textarea`,{id:`canvas-code-source`,ref:i,defaultValue:``,spellCheck:!1})}),(0,Q.jsx)(`div`,{id:`code-status`,className:`code-status${g.error?` error`:``}`,role:`status`,children:ee}),(0,Q.jsxs)(`div`,{className:`code-actions`,children:[(0,Q.jsxs)(`button`,{type:`button`,id:`code-save`,className:`btn primary`,disabled:!u||f,onClick:()=>void x(),children:[n(f?`code.saving`:`code.save`),(0,Q.jsx)(`i`,{className:`code-unsaved-dot`,hidden:!u})]}),(0,Q.jsx)(`button`,{type:`button`,id:`code-download-html`,className:`btn`,onClick:()=>{let t=o.current,n=s.current;u&&t&&n?zu(Ru(r.name),Lu(n.restore(t.getValue()))):e.exportHTML(),_({key:`code.status.downloaded`})},children:n(`code.download`)})]})]})]})}var vm=36;function ym(e,t=vm){let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-1)}…`:n}function bm(e){if(!e||/^data:/i.test(e.trim()))return``;let t=e.split(/[?#]/)[0]?.split(`/`).filter(Boolean).at(-1)??``;try{return decodeURIComponent(t)}catch{return t}}function xm(e,t,n){let r=e.elements.get(t);return r?n===`image`?ym(Pi(r,`alt`)??``)||bm(Pi(r,`src`)):n===`text`?ym(zi(e,t)):ym(Pi(r,`data-layer-id`)??Pi(r,`aria-label`)??``)||ym(zi(e,t)):``}function Sm(e,t){if(t===null)return[];let n=Ga(e,t),r=new Set(n),i=new Map;return n.map(n=>{let a=e.elements.get(n),o=a?.parent??null;for(;o!==null&&o!==t&&!r.has(o);)o=e.elements.get(o)?.parent??null;let s=o!==null&&r.has(o)?(i.get(o)??0)+1:0;i.set(n,s);let c=Wa(e,n);return{id:n,kind:c,depth:s,tag:a?.tag.toLowerCase()??``,snippet:xm(e,n,c),parentId:a?.parent??null}})}function Cm(e,t,n,r){if(t===n)return null;let i=e.elements.get(t)?.parent;if(!i||e.elements.get(n)?.parent!==i)return null;let a=(e.elements.get(i)?.children??[]).filter(e=>e!==t),o=a.indexOf(n);if(o<0)return null;let s=a[r===`before`?o:o+1]??null,c=(e.elements.get(i)?.children??[]).indexOf(t),l=[...a];return l.splice(s===null?l.length:l.indexOf(s),0,t),l.indexOf(t)===c?null:{kind:`move`,id:t,parentId:i,beforeId:s}}function wm(e,t,n,r){let i=e.elements.get(t)?.parent;if(!i)return null;let a=(e.elements.get(i)?.children??[]).filter(e=>e!==t).indexOf(n);return a<0?null:r===`before`?a:a+1}var Tm={text:`text`,image:`image`,svg:`shape`,video:`play`,box:`block`},Em={text:`layers.kind.text`,image:`layers.kind.image`,svg:`layers.kind.svg`,video:`layers.kind.video`,box:`layers.kind.box`};function Dm({controller:e}){let t=af(),n=sp(e),r=(0,v.useMemo)(()=>Sm(e.index(),n.currentPageId),[e,n.currentPageId,n.sourceVersion]),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(null),c=(0,v.useRef)(null);(0,v.useEffect)(()=>()=>e.highlight([]),[e]);let l=n.selection.join(`,`);(0,v.useEffect)(()=>{let e=n.selection[0];e!==void 0&&c.current?.querySelector(`[data-layer-id="${e}"]`)?.scrollIntoView({block:`nearest`})},[l,n.selection]);let u=(t,n)=>e.select([n],{additive:t.shiftKey}),d=t=>!i||i===t.id?!1:e.index().elements.get(i)?.parent===t.parentId,f=(e,t)=>{if(!d(t)){s(null);return}e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=e.currentTarget.getBoundingClientRect(),r=e.clientY<n.top+n.height/2?`before`:`after`;(o?.id!==t.id||o.where!==r)&&s({id:t.id,where:r})},p=(t,n)=>{t.preventDefault();let r=i,c=o?.id===n.id?o.where:`after`;if(a(null),s(null),!r||!d(n))return;let l=e.index(),u=Cm(l,r,n.id,c);if(!u)return;let f=l.elements.get(r)?.parent,p=wm(l,r,n.id,c);if(e.apply(u,{label:`reorder layer`}),f&&p!==null){let t=e.index().elements.get(f)?.children[p];t!==void 0&&e.select([t])}};return(0,Q.jsxs)(`div`,{className:`panel-body layers`,"data-panel-body":`layers`,children:[r.length===0&&(0,Q.jsx)(`p`,{className:`p-hint`,children:t(`layers.empty`)}),(0,Q.jsx)(`div`,{ref:c,className:`layer-list`,role:`tree`,"aria-label":t(`panel.layers`),onMouseLeave:()=>e.highlight([]),children:r.map(r=>{let c=n.selection.includes(r.id),l=[`layer-row`,c?`selected`:``,i===r.id?`dragging`:``,o?.id===r.id?`drop-${o.where}`:``].filter(Boolean).join(` `);return(0,Q.jsxs)(`div`,{className:l,role:`treeitem`,"aria-selected":c,tabIndex:0,draggable:!0,"data-layer-id":r.id,"data-kind":r.kind,style:{paddingLeft:8+r.depth*14},onClick:e=>u(e,r.id),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),u(e,r.id))},onMouseEnter:()=>e.highlight([r.id]),onDragStart:e=>{a(r.id),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,r.id)},onDragOver:e=>f(e,r),onDrop:e=>p(e,r),onDragEnd:()=>{a(null),s(null)},children:[(0,Q.jsx)(`span`,{className:`layer-icon`,title:t(Em[r.kind]),children:(0,Q.jsx)($,{name:Tm[r.kind],size:14})}),(0,Q.jsx)(`span`,{className:`layer-kind`,children:t(Em[r.kind])}),(0,Q.jsx)(`span`,{className:`layer-snippet`,children:r.snippet})]},r.id)})})]})}var Om=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`),km={heading:{tag:`h1`,size:.07,weight:700,line:1.15},subheading:{tag:`h2`,size:.045,weight:600,line:1.25},paragraph:{tag:`p`,size:.03,weight:400,line:1.5}};function Am(e,t,n,r=`#222222`){let i=km[e],a=Math.round(t*.07),o=`position:absolute;z-index:100;left:${a}px;top:${a}px;max-width:${t-2*a}px;margin:0;color:${r};font-size:${Math.round(t*i.size)}px;font-weight:${i.weight};line-height:${i.line}`;return`<${i.tag} style="${o}">${Om(n)}</${i.tag}>`}var jm=[{kind:`heading`,id:`add-heading`,label:`text.addHeading`,sample:`text.sampleHeading`,icon:`H1`},{kind:`subheading`,id:`add-subheading`,label:`text.addSubheading`,sample:`text.sampleSubheading`,icon:`H2`},{kind:`paragraph`,id:`add-paragraph`,label:`text.addParagraph`,sample:`text.sampleParagraph`,icon:`P`}];function Mm({controller:e}){let t=af(),n=sp(e),r=np(e,n.sourceVersion),i=rp(e,n,[`color`]),a=tp(n),[o,s]=(0,v.useState)(`#222222`),c=n.editingTextId!==null&&n.textState?.range===!0,l=(r,i)=>{if(n.currentPageId===null)return;e.apply({kind:`insertHTML`,parentId:n.currentPageId,beforeId:null,html:Am(r,e.pageSize().width,t(i),o)},{label:`add text`});let a=e.getSnapshot().selection[0];a!==void 0&&e.index().elements.has(a)&&e.beginTextEdit(a,`all`)};return(0,Q.jsxs)(`div`,{className:`panel-body`,"data-panel-body":`text`,children:[(0,Q.jsxs)(`section`,{className:`p-section`,children:[(0,Q.jsx)(`h3`,{children:t(`text.add`)}),(0,Q.jsx)(`div`,{className:`add-list`,children:jm.map(e=>(0,Q.jsxs)(`button`,{type:`button`,id:e.id,className:`add-item add-${e.kind}`,disabled:n.docState!==`ready`,onClick:()=>l(e.kind,e.sample),children:[(0,Q.jsx)(`span`,{className:`add-icon`,children:e.icon}),(0,Q.jsx)(`span`,{children:t(e.label)})]},e.kind))})]}),(0,Q.jsxs)(`section`,{className:`p-section`,children:[(0,Q.jsx)(`h3`,{children:t(`text.color`)}),(0,Q.jsx)(ep,{docColors:r,current:_d(i.color)??_d(o),onPick:(t,n)=>{c&&n===`live`||(s(t),a.length&&e.format({command:`color`,value:t}))}})]})]})}var Nm=[{id:`layers`,icon:`layers`,label:`panel.layers`},{id:`block`,icon:`block`,label:`panel.block`},{id:`code`,icon:`code`,label:`panel.code`}];function Pm({open:e,onToggle:t,onAddPage:n}){let r=af(),[i,a]=(0,v.useState)(!1);return Md(i,()=>a(!1)),(0,Q.jsxs)(`nav`,{className:`rail`,"aria-label":r(`rail.label`),children:[Nm.map(n=>(0,Q.jsxs)(`button`,{type:`button`,className:`rail-item${e===n.id?` active`:``}`,"data-panel":n.id,"aria-pressed":e===n.id,title:r(n.label),onClick:()=>t(n.id),children:[(0,Q.jsx)($,{name:n.icon,size:18}),(0,Q.jsx)(`span`,{children:r(n.label)})]},n.id)),(0,Q.jsxs)(`div`,{className:`rail-add`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`rail-item${e===`text`||e===`images`?` active`:``}`,"aria-expanded":i,onClick:()=>a(!i),children:[(0,Q.jsx)($,{name:`plus`,size:18}),(0,Q.jsx)(`span`,{children:r(`panel.add`)})]}),i&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`menu-scrim`,onMouseDown:()=>a(!1)}),(0,Q.jsxs)(`div`,{className:`popover add-popover`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`menu-item`,onClick:()=>{a(!1),e!==`text`&&t(`text`)},children:[(0,Q.jsx)($,{name:`text`}),r(`add.text`)]}),(0,Q.jsxs)(`button`,{type:`button`,className:`menu-item`,onClick:()=>{a(!1),e!==`images`&&t(`images`)},children:[(0,Q.jsx)($,{name:`image`}),r(`panel.images`)]}),(0,Q.jsxs)(`button`,{type:`button`,className:`menu-item`,onClick:()=>{a(!1),n()},children:[(0,Q.jsx)($,{name:`plus`}),r(`add.page`)]})]})]})]})]})}function Fm({open:e,controller:t,onClose:n}){let r=af();if(!e)return(0,Q.jsx)(`aside`,{id:`panel`,className:`panel`,"aria-hidden":`true`});let i={text:(0,Q.jsx)(Mm,{controller:t}),block:(0,Q.jsx)(im,{controller:t}),layers:(0,Q.jsx)(Dm,{controller:t}),images:(0,Q.jsx)(zp,{controller:t})};return(0,Q.jsx)(`aside`,{id:`panel`,className:`panel open`,"data-open":e,"data-view":e,children:e===`code`?(0,Q.jsx)(_m,{controller:t,onClose:n}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`panel-head`,children:[(0,Q.jsx)(`h2`,{children:r(Nm.find(t=>t.id===e)?.label??(e===`images`?`panel.images`:`panel.text`))}),(0,Q.jsx)(`button`,{type:`button`,id:`panel-close`,className:`tb-btn small`,title:r(`panel.close`),"aria-label":r(`panel.close`),onClick:n,children:(0,Q.jsx)($,{name:`close`,size:14})})]}),i[e]]})})}var Im=(e,t,n)=>e.some(e=>e.pageKey!==void 0)?e.find(e=>e.pageKey===n)??null:e[t]??null;function Lm(e){let[t,n]=(0,v.useState)({images:[],status:`loading`}),[r,i]=(0,v.useState)(0);return(0,v.useEffect)(()=>{if(!e&&!sd())return;let t=!0;return(e?fetch(`/api/comparison`,{cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(`Reference images unavailable`);return(await e.json()).items}):cd(`references`,void 0,1e4)).then(e=>{t&&n({images:e.filter(e=>typeof e?.src==`string`),status:`ready`})}).catch(()=>{t&&n({images:[],status:`failed`})}),()=>{t=!1}},[r,e]),{...t,retry:()=>{n({images:[],status:`loading`}),i(e=>e+1)}}}function Rm({state:e,pageIndex:t,pageKey:n,scale:r}){let i=af(),a=Im(e.images,t,n),[o,s]=(0,v.useState)(null),c=a?.width||(o&&o.src===a?.src?o.width:0)||1080,l=a?.height||(o&&o.src===a?.src?o.height:0)||1440;return(0,Q.jsxs)(`section`,{className:`comparison-reference`,"aria-label":i(`compare.reference`),style:{width:Math.round(c*r),height:Math.round(l*r)},children:[(0,Q.jsxs)(`div`,{className:`comparison-caption`,children:[(0,Q.jsx)(`span`,{children:i(`compare.reference`)}),(0,Q.jsxs)(`span`,{children:[i(`compare.page`,{n:t+1}),` · `,i(`compare.readonly`)]})]}),a?(0,Q.jsx)(zm,{image:a,onSize:(e,t)=>s({src:a.src,width:e,height:t})},a.src):(0,Q.jsxs)(`div`,{className:`comparison-empty`,role:`status`,children:[(0,Q.jsx)($,{name:`image`,size:28}),(0,Q.jsx)(`strong`,{children:i(e.status===`loading`?`compare.loading`:e.status===`failed`?`compare.failed`:`compare.empty`)}),e.status===`failed`?(0,Q.jsx)(`button`,{type:`button`,className:`tb-btn outlined`,onClick:e.retry,children:i(`compare.retry`)}):(0,Q.jsx)(`span`,{children:i(`compare.emptyHint`)})]})]})}function zm({image:e,onSize:t}){let n=af(),[r,i]=(0,v.useState)(!1);return r?(0,Q.jsxs)(`div`,{className:`comparison-empty`,children:[(0,Q.jsx)($,{name:`image`,size:28}),(0,Q.jsx)(`span`,{children:n(`compare.imageFailed`)}),(0,Q.jsx)(`button`,{type:`button`,className:`tb-btn outlined`,onClick:()=>i(!1),children:n(`compare.retry`)})]}):(0,Q.jsx)(`img`,{className:`comparison-image`,src:e.src,alt:e.name||n(`compare.reference`),draggable:!1,onLoad:e=>t(e.currentTarget.naturalWidth,e.currentTarget.naturalHeight),onError:()=>i(!0)})}async function Bm(e,t,n){let r=e?.ownerDocument.defaultView?.getComputedStyle(e),i=/^url\(["']?(.*?)["']?\)$/.exec(r?.backgroundImage??``);if(!r||!i?.[1])return{};if(![`cover`,`contain`].includes(r.backgroundSize))return!/^[-.\d]+px$/.test(r.backgroundPositionX)||!/^[-.\d]+px$/.test(r.backgroundPositionY)?{}:{"background-position":`${parseFloat(r.backgroundPositionX)-n.x}px ${parseFloat(r.backgroundPositionY)-n.y}px`};let a=new Image;a.src=i[1];try{await a.decode()}catch{return{}}let{naturalWidth:o,naturalHeight:s}=a;if(!o||!s)return{};let c=(r.backgroundSize===`cover`?Math.max:Math.min)(t.width/o,t.height/s),l=o*c,u=s*c,d=(e,t)=>e.endsWith(`%`)?t*parseFloat(e)/100:parseFloat(e)||0;return{"background-size":`${l}px ${u}px`,"background-position":`${d(r.backgroundPositionX,t.width-l)-n.x}px ${d(r.backgroundPositionY,t.height-u)-n.y}px`}}function Vm({request:e,controller:t,scale:n,onClose:r}){let i=af(),a=t.pageSize(),o=Math.max(0,a.width-e.width),s=Math.max(0,a.height-e.height),[c,l]=(0,v.useState)({x:Math.round(o/2),y:Math.round(s/2)}),u=(0,v.useRef)(null);Md(!0,r);let d=e=>{if(!e.currentTarget.hasPointerCapture(e.pointerId)||!u.current)return;let t=u.current;l({x:Math.round(Math.max(0,Math.min(o,t.left+(e.clientX-t.x)/n))),y:Math.round(Math.max(0,Math.min(s,t.top+(e.clientY-t.y)/n)))})},[f,p]=(0,v.useState)(!1),m=async()=>{if(f)return;p(!0);let{pageId:n,width:i,height:o}=e,s=t.index().elements.get(n)?.children??[],l=c.x===0&&c.y===0?[]:s.flatMap(e=>{let t=ld(e),n=t?.ownerDocument.defaultView?.getComputedStyle(t);if(!n||n.display===`none`||t?.tagName===`STYLE`)return[];let r=n.transform===`none`?``:` ${n.transform}`;return[{kind:`setStyle`,id:e,props:{transform:`translate(${-c.x}px, ${-c.y}px)${r}`}}]}),u=await Bm(ld(n),a,c);if(t.getSnapshot().currentPageId!==n){r();return}t.applyBatch([{kind:`setAttr`,id:n,name:`data-popost-width`,value:String(i)},{kind:`setAttr`,id:n,name:`data-popost-height`,value:String(o)},{kind:`setStyle`,id:n,props:{width:`${i}px`,height:`${o}px`,overflow:`hidden`,...u}},...l],`resize page`),r()};return(0,Q.jsxs)(`div`,{className:`page-resize-layer`,children:[(0,Q.jsxs)(`div`,{className:`page-resize-actions`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`btn`,onClick:r,children:i(`design.cancel`)}),(0,Q.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:f,onClick:()=>void m(),children:i(`design.apply`)}),(0,Q.jsxs)(`span`,{children:[e.width,` × `,e.height,` px`]})]}),(0,Q.jsx)(`div`,{className:`page-resize-hit`,onPointerDown:e=>{u.current={x:e.clientX,y:e.clientY,left:c.x,top:c.y},e.currentTarget.setPointerCapture(e.pointerId)},onPointerMove:d,children:(0,Q.jsx)(`div`,{className:`page-resize-frame`,style:{width:e.width*n,height:e.height*n,left:c.x*n,top:c.y*n}})})]})}var Hm=[`nw`,`ne`,`sw`,`se`,`w`,`e`],Um={nw:[0,0],ne:[100,0],sw:[0,100],se:[100,100],w:[0,50],e:[100,50]},Wm={nw:`nwse-resize`,se:`nwse-resize`,ne:`nesw-resize`,sw:`nesw-resize`,w:`ew-resize`,e:`ew-resize`},Gm=236,Km=36,qm=(e,t)=>({left:e.x*t,top:e.y*t,width:e.width*t,height:e.height*t});function Jm({controller:e,snap:t,scale:n,width:r,gestures:i,view:a,actions:o}){let s=af(),{rects:c,selection:l,hoverId:u,editingTextId:d}=t,f=l.filter(e=>c[e]),p=Ep(f.map(e=>c[e])),m=f.length===1?f[0]:null,h=d!==null,g=a.active===`move`||a.active===`resize`,_=u!==null&&!l.includes(u)&&!h&&!g?c[u]:void 0,v=e=>({"data-keepfocus":``,onPointerDown:t=>{t.button===0&&(t.preventDefault(),t.stopPropagation(),t.currentTarget.setPointerCapture(t.pointerId),e(t))},onPointerMove:e=>{e.currentTarget.hasPointerCapture(e.pointerId)&&i.overlayMove(e.clientX,e.clientY,e.altKey)},onPointerUp:e=>{e.currentTarget.hasPointerCapture(e.pointerId)&&(e.currentTarget.releasePointerCapture(e.pointerId),i.overlayUp())},onPointerCancel:()=>{i.cancel()}}),y=p?p.y*n>=48?p.y*n-Km-8:(p.y+p.height)*n+8:0,b=p?Math.max(0,Math.min(p.x*n,r-Gm)):0,x=m?Wa(e.index(),m):null;return(0,Q.jsxs)(`div`,{className:`overlay`,"aria-hidden":!1,children:[_&&(0,Q.jsx)(`div`,{className:`ov-hover`,style:qm(_,n)}),f.map(e=>(0,Q.jsx)(`div`,{className:`ov-sel${f.length>1?` multi`:``}${h?` editing`:``}`,style:qm(c[e],n),"data-sel-id":e},e)),p&&f.length>1&&(0,Q.jsx)(`div`,{className:`ov-group`,style:qm(p,n)}),p&&m&&!h&&(0,Q.jsx)(`div`,{className:`ov-handles`,style:qm(p,n),children:Hm.map(e=>(0,Q.jsx)(`span`,{className:`ov-handle h-${e}`,"data-handle":e,style:{left:`${Um[e][0]}%`,top:`${Um[e][1]}%`,cursor:Wm[e]},...v(t=>i.startResize(e,t.clientX,t.clientY))},e))}),p&&!h&&(0,Q.jsxs)(`div`,{className:`ov-pill${g?` hidden`:``}`,style:{left:b,top:y},role:`toolbar`,"data-keepfocus":``,children:[(0,Q.jsx)(`span`,{className:`pill-grip`,title:s(`pill.move`),...v(e=>i.startPillMove(e.clientX,e.clientY)),children:(0,Q.jsx)($,{name:`grip`})}),f.length>1&&(0,Q.jsx)(`span`,{className:`pill-count`,children:s(`pill.selected`,{n:f.length})}),m&&x!==null&&(0,Q.jsx)(`button`,{type:`button`,className:`pill-btn`,"data-act":`parent`,title:s(`pill.selectParent`),onClick:()=>e.selectParent(),children:(0,Q.jsx)($,{name:`parent`})}),(0,Q.jsx)(`button`,{type:`button`,className:`pill-btn`,"data-act":`duplicate`,title:s(`pill.duplicate`),onClick:o.duplicateSelection,children:(0,Q.jsx)($,{name:`duplicate`})}),(0,Q.jsx)(`button`,{type:`button`,className:`pill-btn danger`,"data-act":`delete`,title:s(`pill.delete`),onClick:o.deleteSelection,children:(0,Q.jsx)($,{name:`trash`})}),m&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{type:`button`,className:`pill-btn`,"data-act":`forward`,title:s(`pill.forward`),onClick:()=>o.reorderSelection(`down`),children:(0,Q.jsx)($,{name:`forward`})}),(0,Q.jsx)(`button`,{type:`button`,className:`pill-btn`,"data-act":`backward`,title:s(`pill.backward`),onClick:()=>o.reorderSelection(`up`),children:(0,Q.jsx)($,{name:`backward`})})]})]}),a.guides.map((e,t)=>e.axis===`x`?(0,Q.jsx)(`div`,{className:`ov-guide v`,style:{left:e.pos*n,top:e.from*n,height:(e.to-e.from)*n}},t):(0,Q.jsx)(`div`,{className:`ov-guide h`,style:{top:e.pos*n,left:e.from*n,width:(e.to-e.from)*n}},t)),a.marquee&&(0,Q.jsx)(`div`,{className:`ov-marquee`,style:qm(a.marquee,n)}),a.tip&&(0,Q.jsx)(`div`,{className:`ov-tip`,style:{left:a.tip.x*n,top:a.tip.y*n+8},children:a.tip.text})]})}var Ym=e=>Math.min(300,Math.max(10,e));function Xm(e,t,n=32){if(t.width<=0||t.height<=0)return 100;let r=Math.max(1,e.width-n*2),i=Math.max(1,e.height-n*2);return Math.min(300,Math.max(10,Math.min(r/t.width,i/t.height)*100))}function Zm(e,t){return Ym(e*(t>0?1.12:1/1.12))}var Qm=(e,t)=>Ym(e*Math.exp(-t*.002));function $m({comparing:e,references:t,controller:n,snap:r,zoom:i,gestures:a,subscribeView:o,actions:s,cropId:c=null,onExitCrop:l,resize:u,onEndResize:d}){let f=af(),p=r.pages.findIndex(e=>e.id===r.currentPageId),{stageRef:m,wheel:h}=i,g=(0,v.useRef)(null),[_,y]=(0,v.useState)(kp),b=n.pageSize(),x=i.percent/100,S=Math.round(b.width*x),C=Math.round(b.height*x),w=(0,v.useRef)(null),T=(0,v.useCallback)(e=>{w.current=e,n.attachFrame(e)},[n]);(0,v.useEffect)(()=>o(y),[o]),(0,v.useEffect)(()=>{let e=w.current;if(!e)return;let t=null,n=()=>{t?.(),t=null;let n=e.contentWindow;if(!n)return;let r=e=>{e.key!==`Escape`||!jd()||(e.preventDefault(),e.stopPropagation(),Ad())};n.addEventListener(`keydown`,r,!0),t=()=>n.removeEventListener(`keydown`,r,!0)};return n(),e.addEventListener(`load`,n),()=>{e.removeEventListener(`load`,n),t?.()}},[]),(0,v.useEffect)(()=>{let e=g.current;if(!e)return;let t=t=>{!t.ctrlKey&&!t.metaKey||(t.preventDefault(),h(t.deltaY*(t.deltaMode===1?16:t.deltaMode===2?e.clientHeight:1)))};e.addEventListener(`wheel`,t,{passive:!1});let r=n.onFrameEvent(t=>{t.type===`wheel`&&(t.ctrl?h(t.deltaY):e.scrollBy(t.deltaX,t.deltaY))});return()=>{e.removeEventListener(`wheel`,t),r()}},[n,h]);let ee=(0,v.useCallback)(e=>{g.current=e,m(e)},[m]);return(0,Q.jsx)(`div`,{className:`stage`,ref:ee,tabIndex:-1,onMouseDown:e=>{let t=e.target;(t===e.currentTarget||t.classList.contains(`stage-pad`))&&(n.select([]),e.currentTarget.focus({preventScroll:!0}))},children:(0,Q.jsxs)(`div`,{className:`stage-pad${e?` comparing`:``}`,style:{padding:32},children:[e&&(0,Q.jsx)(Rm,{state:t,pageIndex:p,pageKey:r.pages[p]?.pageKey??null,scale:x}),(0,Q.jsxs)(`div`,{className:`canvas`,style:{width:S,height:C},children:[e&&(0,Q.jsxs)(`div`,{className:`comparison-caption result-caption`,children:[(0,Q.jsx)(`span`,{children:f(`compare.result`)}),(0,Q.jsxs)(`span`,{children:[f(`compare.page`,{n:p+1}),` · `,f(`compare.editable`)]})]}),(0,Q.jsx)(`iframe`,{id:`frame`,ref:T,title:`canvas`,style:{width:b.width,height:b.height,transform:`scale(${x})`}}),(0,Q.jsx)(Jm,{controller:n,snap:r,scale:x,width:S,gestures:a,view:_,actions:s}),u&&(0,Q.jsx)(Vm,{request:u,controller:n,scale:x,onClose:d},u.pageId),!u&&c!==null&&l&&(0,Q.jsx)(Lf,{controller:n,snap:r,id:c,scale:x,onExit:l})]})]})})}function eh({snap:e,zoom:t,actions:n}){let r=af(),i=e.pages.findIndex(t=>t.id===e.currentPageId),a=e.pages.length;return(0,Q.jsxs)(`div`,{className:`statusbar`,children:[(0,Q.jsxs)(`div`,{className:`sb-group`,children:[(0,Q.jsx)(`button`,{type:`button`,id:`btn-prev-page`,className:`tb-btn small`,disabled:i<=0,title:r(`pages.prev`),"aria-label":r(`pages.prev`),onClick:()=>n.changePage(`prev`),children:(0,Q.jsx)($,{name:`prev`,size:14})}),(0,Q.jsx)(`span`,{id:`page-counter`,className:`page-counter`,children:r(`pages.counter`,{n:i+1,total:a})}),(0,Q.jsx)(`button`,{type:`button`,id:`btn-next-page`,className:`tb-btn small`,disabled:i<0||i>=a-1,title:r(`pages.next`),"aria-label":r(`pages.next`),onClick:()=>n.changePage(`next`),children:(0,Q.jsx)($,{name:`next`,size:14})})]}),(0,Q.jsx)(`div`,{className:`sb-spacer`}),(0,Q.jsxs)(`div`,{className:`sb-group zoom-group`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`tb-btn small`,"aria-label":r(`zoom.out`),disabled:t.percent<=10,onClick:()=>t.step(-1),children:(0,Q.jsx)($,{name:`minus`,size:15})}),(0,Q.jsx)(`button`,{type:`button`,className:`tb-btn small`,"aria-label":r(`zoom.in`),disabled:t.percent>=300,onClick:()=>t.step(1),children:(0,Q.jsx)($,{name:`plus`,size:15})}),(0,Q.jsx)(`input`,{id:`zoom-slider`,type:`range`,min:10,max:300,step:1,value:Math.round(t.percent),"aria-label":r(`zoom.slider`),onChange:e=>t.set(Number(e.currentTarget.value))}),(0,Q.jsxs)(`button`,{type:`button`,id:`zoom-label`,className:`zoom-label`,title:r(`zoom.fit`),onClick:t.fit,children:[Math.round(t.percent),`%`]})]})]})}var th=2e3;function nh(e,t){let n=`cloud.error.${t??``}`;return n in ef.en?e(n):e(`cloud.error.generic`)}function rh({href:e,t}){return e?(0,Q.jsx)(`a`,{className:`cloud-link`,href:e,target:`_blank`,rel:`noopener noreferrer`,title:t(`cloud.openTitle`),children:t(`cloud.open`)}):null}function ih({mode:e,status:t,link:n,copied:r,busy:i,onStart:a,onPush:o,onRetry:s,onCopy:c}){let l=af(),u=i===`push`?`uploading`:i===`start`?`starting`:t?.state??`idle`,d=e=>(0,Q.jsx)(`span`,{className:`tb-label`,children:l(e)});if(u===`uploading`)return(0,Q.jsxs)(`span`,{className:`cloud-state`,role:`status`,children:[(0,Q.jsx)(`i`,{className:`spinner small`}),l(e===`keyed`?`cloud.syncing`:`cloud.uploading`)]});if(u===`starting`)return(0,Q.jsxs)(`span`,{className:`cloud-state`,role:`status`,children:[(0,Q.jsx)(`i`,{className:`spinner small`}),l(`cloud.waiting`)]});if(u===`waiting`)return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`span`,{className:`cloud-state`,role:`status`,children:[(0,Q.jsx)(`i`,{className:`spinner small`}),l(`cloud.waiting`)]}),(0,Q.jsx)(`button`,{type:`button`,className:`tb-btn outlined cloud-copy`,onClick:c,children:l(r?`cloud.linkCopied`:`cloud.copyLink`)}),n&&(0,Q.jsx)(`input`,{className:`cloud-link-input`,readOnly:!0,value:n,"aria-label":l(`cloud.loginLink`),onFocus:e=>e.currentTarget.select()})]});if(u===`saved`)return(0,Q.jsxs)(`span`,{className:`cloud-state`,role:`status`,children:[(0,Q.jsx)($,{name:`check`,size:14}),l(e===`keyed`?`cloud.synced`:`cloud.saved`),(0,Q.jsx)(rh,{href:t?.webUrl,t:l})]});if(u===`failed`)return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`cloud-state cloud-error`,role:`status`,title:t?.error?.message,children:nh(l,t?.error?.code)}),(0,Q.jsx)(`button`,{type:`button`,className:`tb-btn outlined`,onClick:s,children:l(`cloud.retry`)})]});if(u===`conflict`)return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`span`,{className:`cloud-state cloud-error`,role:`status`,children:[l(`cloud.conflict`),(0,Q.jsx)(rh,{href:t?.webUrl,t:l})]}),e===`keyed`?(0,Q.jsx)(`button`,{type:`button`,className:`tb-btn outlined`,title:l(`cloud.overwriteTitle`),onClick:()=>o(!0),children:l(`cloud.overwrite`)}):null]});if(e===`keyed`)return(0,Q.jsxs)(`button`,{type:`button`,className:`tb-btn outlined cloud-btn`,title:l(`cloud.syncNow`),"aria-label":l(`cloud.syncNow`),onClick:()=>o(!1),children:[(0,Q.jsx)($,{name:`cloud`}),d(`cloud.syncNow`)]});let f=!!(t?.webUrl&&t.dirty);return(0,Q.jsxs)(`button`,{type:`button`,className:`tb-btn outlined cloud-btn`,title:l(`cloud.tooltip`),"aria-label":l(`cloud.save`),onClick:a,children:[(0,Q.jsx)($,{name:`cloud`}),(0,Q.jsx)(`span`,{className:`tb-label`,children:l(f?`cloud.dirty`:`cloud.save`)})]})}var ah=e=>({code:e instanceof Error&&`status`in e?`ERROR`:`NETWORK`,message:e instanceof Error?e.message:String(e)});function oh({cloud:e,saveState:t,saveLocal:n}){let r=of(),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(!1),g=(0,v.useRef)(!0),_=(0,v.useRef)(`push`);(0,v.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]);let y=(0,v.useCallback)(async()=>{try{let t=await e.status();g.current&&a(t)}catch{}},[e]);(0,v.useEffect)(()=>void y(),[y,t]);let b=c!==null||i?.state===`waiting`||i?.state===`uploading`||e.mode===`keyed`&&i?.state===`idle`&&i.dirty;(0,v.useEffect)(()=>{if(!b)return;let e=setInterval(()=>void y(),th);return()=>clearInterval(e)},[b,y]);let x=(0,v.useCallback)(async()=>{let t=window.open(`about:blank`,`_blank`);_.current=`start`,s(void 0),h(!1),l(`start`);try{if(!await n()){t?.close(),s({code:`LOCAL_SAVE_FAILED`,message:``});return}let{authorizeUrl:i}=await e.start(r);d(i),p(!t),t&&(t.opener=null,t.location.href=i),_.current=`push`,await y()}catch(e){t?.close(),s(ah(e))}finally{l(null)}},[e,r,y,n]),S=(0,v.useCallback)(async t=>{_.current=`push`,s(void 0),l(`push`);try{if(!await n()){s({code:`LOCAL_SAVE_FAILED`,message:``});return}let i=await e.push({force:t,lang:r});if(i.ok===!1&&i.error?.code===`LOGIN_REQUIRED`){l(null),await x();return}g.current&&a(i)}catch(e){s(ah(e))}finally{l(null)}},[e,r,n,x]),C=(0,v.useCallback)(async()=>{try{await navigator.clipboard.writeText(u??``),h(!0)}catch{p(!0)}},[u]),w=i??{ok:!1,mode:e.mode,state:`idle`,dirty:!0},T=o?{...w,state:`failed`,error:o}:i,ee=e.mode===`anonymous`&&(T?.error?.code===`UNAUTHORIZED`||T?.error?.code===`LOGIN_REQUIRED`);return(0,Q.jsx)(`div`,{className:`cloud`,children:(0,Q.jsx)(ih,{mode:e.mode,status:T,link:f&&i?.state===`waiting`?u:null,copied:m,busy:c,onStart:()=>void x(),onPush:e=>void S(e),onRetry:()=>void(ee||_.current===`start`?x():S(!1)),onCopy:()=>void C()})})}var sh=h(),ch=`modulepreload`,lh=function(e,t){return new URL(e,t).href},uh={},dh=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=lh(t,n),t=s(t),t in uh)return;uh[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:ch,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},fh=[`png`,`jpg`,`svg`,`psd`,`html`,`pdf`],ph=`position:fixed;left:-20000px;top:0;width:4000px;height:4000px;border:0;`,mh=e=>[...e.querySelectorAll(`.slide`)].filter(e=>!e.parentElement?.closest(`.slide`)),hh=e=>e.replace(/[\\/:*?"<>|\u0000-\u001f]+/g,` `).trim()||`deck`,gh=(e,t)=>{let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,r.click(),setTimeout(()=>URL.revokeObjectURL(n),3e3)},_h=async(e,t=!1)=>{let n=document.createElement(`iframe`);n.setAttribute(`sandbox`,`allow-same-origin`),n.setAttribute(`aria-hidden`,`true`),n.tabIndex=-1,n.style.cssText=ph;let r=new Promise(e=>{n.onload=()=>e()});n.srcdoc=t?e.replace(/<head>/i,`<head><base href="${location.origin}/pages/"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; base-uri 'self'">`):e,document.body.append(n),await r;let i=n.contentDocument;if(!i)throw n.remove(),Error(`stage unavailable`);return await i.fonts.ready,await Promise.all([...i.images].map(e=>e.decode().catch(()=>void 0))),{frame:n,doc:i}},vh=64e6,yh=async e=>{let t=await fetch(e);if(!t.ok)throw Error(`Export resource unavailable`);let n=await t.blob();return new Promise((e,t)=>{let r=new FileReader;r.onload=()=>e(String(r.result)),r.onerror=()=>t(r.error),r.readAsDataURL(n)})},bh=async(e,t)=>{let n=t?/(?:\.\.\/|\/)(?:assets|fonts|css)\/[^"'()\s<>,]+/g:/\/(?:api\/assets|fonts)\/[^"'()\s<>]+/g,r=[...new Set(e.match(n)??[])],i=await Promise.all(r.map(async e=>[e,await yh(t?new URL(e,location.origin+`/pages/`).href:e)])),a=new Map(i);return e.replace(n,e=>a.get(e)??e)},xh=async(e,t=()=>{},n=!1)=>{let[{toCanvas:r,toSvg:i},{default:a}]=await Promise.all([dh(()=>import(`./es-C_Ha8SM2.js`),[],import.meta.url),dh(()=>import(`./jszip.min-DqfCBLrH.js`).then(e=>c(e.default,1)),[],import.meta.url)]),{frame:o,doc:s}=await _h(e.html,n);try{let o=mh(s),l=[...new Set(e.pages)].sort((e,t)=>e-t);if(!l.length||l.some(e=>!o[e]))throw Error(`Invalid export pages`);let u=hh(e.name),d=new a,f=e.format===`pdf`?await(await dh(async()=>{let{PDFDocument:e}=await import(`./es-BFnFFu6P.js`);return{PDFDocument:e}},[],import.meta.url)).PDFDocument.create():null,p=e.format===`psd`?await dh(()=>import(`./dist-CX2mxpwq.js`).then(e=>c(e.default,1)),[],import.meta.url):null;for(let[a,c]of l.entries()){let m=o[c],h=`${u}-${c+1}.${e.format}`,g=m.offsetWidth,_=m.offsetHeight;if(e.format===`html`){let e=s.documentElement.cloneNode(!0);e.querySelector(`base`)?.remove(),mh(e).forEach((e,t)=>{c!==t&&e.remove()}),d.file(h,await bh(`<!doctype html>${e.outerHTML}`,n))}else{if(!g||!_||g*_*e.scale**2>vh)throw Error(`Export dimensions exceed the browser limit`);let t={pixelRatio:e.scale,skipAutoScale:!0,cacheBust:!1,style:{margin:`0`},width:g,height:_};if(e.format===`svg`){let n=await i(m,t),r=decodeURIComponent(n.slice(n.indexOf(`,`)+1)),a=new DOMParser().parseFromString(r,`image/svg+xml`).documentElement;if(a.localName!==`svg`)throw Error(`Invalid SVG export`);a.setAttribute(`width`,String(g*e.scale)),a.setAttribute(`height`,String(_*e.scale)),a.setAttribute(`viewBox`,`0 0 ${g} ${_}`),d.file(h,new XMLSerializer().serializeToString(a))}else{let n=await r(m,e.format===`jpg`||f?{...t,backgroundColor:`#ffffff`}:t);if(n.width!==g*e.scale||n.height!==_*e.scale)throw Error(`Unexpected export resolution`);if(p){let e=n.getContext(`2d`)?.getImageData(0,0,n.width,n.height);if(!e)throw Error(`Could not read canvas pixels`);d.file(h,p.writePsd({width:n.width,height:n.height,imageData:e,children:[{name:`Artwork`,imageData:e,opacity:1}]}))}else{let t=e.format===`jpg`||f!==null,r=n.toDataURL(t?`image/jpeg`:`image/png`,.95);if(f){let e=await f.embedJpg(r),t=f.addPage([g*.75,_*.75]);t.drawImage(e,{x:0,y:0,width:t.getWidth(),height:t.getHeight()})}else d.file(h,r.slice(r.indexOf(`,`)+1),{base64:!0})}}}t(a+1,l.length,(a+1)/l.length*.9)}f&&d.file(`${u}.pdf`,await f.save()),gh(await d.generateAsync({type:`blob`},({percent:e})=>t(l.length,l.length,.9+e/1e3)),`${u}.zip`)}finally{o.remove()}},Sh=[`svg`,`psd`,`pdf`];function Ch({controller:e,snap:t,customName:n,onNameChange:r,onClose:i,local:a}){let o=af(),s=of(),c=Of(),[l,u]=(0,v.useState)([]),[d,f]=(0,v.useState)(`png`),[p,m]=(0,v.useState)(1),h=n??(t.name||`Popost`),[g,_]=(0,v.useState)(null),y=(0,v.useRef)(null),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(null),[w,T]=(0,v.useState)(null),ee=(0,v.useRef)(null),E=(0,v.useRef)(null);(0,v.useLayoutEffect)(()=>{let e=E.current,t=document.getElementById(`btn-export`);if(!e||!t)return;let n=()=>{let n=window.visualViewport,r=(n?.offsetLeft??0)+12,i=(n?.offsetTop??0)+12,a=Math.max(0,(n?.width??window.innerWidth)-24),o=Math.max(0,(n?.height??window.innerHeight)-24),s=t.getBoundingClientRect();e.style.width=`${Math.min(492,a)}px`,e.style.left=`${Math.max(r,Math.min(s.right-e.offsetWidth,r+a-e.offsetWidth))}px`;let c=Math.max(i,Math.min(s.bottom+6,i+o-Math.min(e.scrollHeight+2,o)));e.style.top=`${c}px`,e.style.maxHeight=`${Math.max(0,i+o-c)}px`};n();let r=new ResizeObserver(n);return r.observe(e),window.addEventListener(`resize`,n),window.addEventListener(`scroll`,n,!0),window.visualViewport?.addEventListener(`resize`,n),window.visualViewport?.addEventListener(`scroll`,n),()=>{r.disconnect(),window.removeEventListener(`resize`,n),window.removeEventListener(`scroll`,n,!0),window.visualViewport?.removeEventListener(`resize`,n),window.visualViewport?.removeEventListener(`scroll`,n)}},[]);let[D,O]=(0,v.useState)(!1),[te,k]=(0,v.useState)({completed:0,total:0,fraction:0}),A=t.pages.filter(e=>!l.includes(e.id)),ne=A[0],re=e.index(),ie=(0,v.useMemo)(()=>t.pages.map(e=>co(re,{frameCSS:_p,baseHref:location.origin+(a?`/pages/`:`/`),imageOrigins:vs(),currentPageId:e.id})),[re,t.pages,a]);(0,v.useEffect)(()=>{if(a){let e=!0;return fetch(`/api/export-options`,{cache:`no-store`}).then(e=>e.json()).then(t=>{e&&x(t.premium===!0)}).catch(()=>{}),()=>{e=!1}}let e=!0;cd(`export-options`).then(t=>{e&&x(t.premium)}).catch(()=>{});let t=e=>{if(!ls(e,`popost-workspace`))return;let t=e.data;t.type===`export-progress`&&t.id===sd()&&k({completed:t.completed,total:t.total,fraction:t.fraction})};return window.addEventListener(`message`,t),()=>{e=!1,window.removeEventListener(`message`,t)}},[a]);let j=(0,v.useCallback)(()=>{C(null),T(null)},[]);Md(S!==null,()=>{S?.anchor.focus(),j()}),(0,v.useLayoutEffect)(()=>{let e=ee.current,t=E.current;if(!S||!e||!t)return;let n=()=>{let n=S.anchor.getBoundingClientRect(),r=t.getBoundingClientRect();if(n.bottom<=r.top||n.top>=r.bottom){j();return}let i=Math.min(270,window.innerWidth-16),a=window.innerHeight-n.bottom-6-8,o=n.top-6-8,s=e.scrollHeight>a&&o>a;Object.assign(e.style,{width:`${i}px`,left:`${Math.max(8,Math.min(n.right-i,window.innerWidth-i-8))}px`,maxHeight:`${Math.max(0,s?o:a)}px`,top:s?`auto`:`${n.bottom+6}px`,bottom:s?`${window.innerHeight-n.top+6}px`:`auto`})};n(),t.addEventListener(`scroll`,n),window.addEventListener(`resize`,n);let r=t=>{t.target instanceof Node&&!e.contains(t.target)&&!S.anchor.contains(t.target)&&j()};return document.addEventListener(`pointerdown`,r,!0),S.focusOptions&&e.querySelector(`[aria-pressed=true]`)?.focus(),()=>{t.removeEventListener(`scroll`,n),window.removeEventListener(`resize`,n),document.removeEventListener(`pointerdown`,r,!0)}},[S,j]);let M=(e,t=!1)=>{let n=g?.trim();e&&n&&r(n),_(null),t&&requestAnimationFrame(()=>y.current?.focus())},ae=async()=>{if(!(!A.length||D)){e.endTextEdit(!0),k({completed:0,total:A.length,fraction:0}),O(!0),j();try{let n={html:Lu(e.index().source),name:g?.trim()||h,pages:t.pages.flatMap((e,t)=>l.includes(e.id)?[]:[t]),format:d,scale:d===`html`?1:p};a?await xh(n,(e,t,n)=>k({completed:e,total:t,fraction:n}),!0):await cd(`export`,n,3e5),c(o(`export.done`),`info`),i()}catch(e){c(e instanceof Error&&e.message?e.message:o(`export.failed`),`error`)}finally{O(!1)}}},oe=(e,t,n)=>{C(r=>r?.kind===e?null:{kind:e,anchor:t,focusOptions:n}),T(null)},N=(e,t)=>t&&(0,Q.jsx)(`button`,{type:`button`,className:`export-gem`,"aria-label":o(`export.paid`),"aria-expanded":w===e,onMouseEnter:()=>T(e),onFocus:()=>T(e),onClick:()=>T(e),children:(0,Q.jsx)($,{name:`gem`,size:15})}),P=(e,t,n)=>{t?T(e):(n(),S?.focusOptions&&S.anchor.focus(),j())},F=e=>w===e&&(0,Q.jsxs)(`div`,{className:`export-upgrade`,children:[(0,Q.jsx)(`span`,{children:o(`export.upgrade`)}),(0,Q.jsx)(`a`,{href:a?`https://popost.ai/${s}/pricing`:`/${s}/pricing`,target:`_blank`,rel:`noopener noreferrer`,children:o(`export.pricing`)})]});return(0,sh.createPortal)((0,Q.jsxs)(`div`,{id:`pop-export`,ref:E,className:`popover export-panel`,role:`dialog`,"aria-label":o(`topbar.export`),children:[(0,Q.jsxs)(`fieldset`,{disabled:D,children:[(0,Q.jsxs)(`section`,{className:`export-section`,children:[(0,Q.jsxs)(`div`,{className:`export-section-head`,children:[(0,Q.jsx)(`strong`,{children:o(`export.pages`,{n:A.length,total:t.pages.length})}),(0,Q.jsxs)(`label`,{children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:l.length===0,onChange:e=>u(e.currentTarget.checked?[]:t.pages.map(e=>e.id))}),o(`export.all`)]})]}),(0,Q.jsx)(`div`,{className:`export-pages`,children:t.pages.map((e,t)=>{let n=Math.min(78/e.width,78/e.height),r=!l.includes(e.id);return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":r,onClick:()=>u(t=>r?[...t,e.id]:t.filter(t=>t!==e.id)),children:[(0,Q.jsxs)(`span`,{className:`export-thumb`,children:[(0,Q.jsx)(`span`,{style:{width:e.width*n,height:e.height*n},children:(0,Q.jsx)(`iframe`,{title:e.name,"aria-hidden":`true`,tabIndex:-1,sandbox:`allow-same-origin`,onLoad:e=>yp(e.currentTarget),srcDoc:ie[t],style:{width:e.width,height:e.height,transform:`scale(${n})`}})}),r&&(0,Q.jsx)(`i`,{children:(0,Q.jsx)($,{name:`check`,size:12})})]}),(0,Q.jsx)(`b`,{children:e.name}),(0,Q.jsxs)(`small`,{children:[e.width,` × `,e.height]})]},e.id)})})]}),(0,Q.jsxs)(`section`,{className:`export-section export-settings`,children:[(0,Q.jsxs)(`div`,{className:`export-row`,children:[(0,Q.jsx)(`span`,{children:o(`export.format`)}),(0,Q.jsxs)(`button`,{className:`btn`,type:`button`,"aria-expanded":S?.kind===`format`,"aria-controls":S?.kind===`format`?`export-options`:void 0,onClick:e=>oe(`format`,e.currentTarget,e.detail===0),children:[d.toUpperCase(),` `,(0,Q.jsx)($,{name:`chevron`,size:12})]})]}),(0,Q.jsxs)(`div`,{className:`export-row`,children:[(0,Q.jsx)(`span`,{children:o(`export.resolution`)}),(0,Q.jsxs)(`button`,{className:`btn`,type:`button`,disabled:d===`html`,"aria-expanded":S?.kind===`scale`,"aria-controls":S?.kind===`scale`?`export-options`:void 0,onClick:e=>oe(`scale`,e.currentTarget,e.detail===0),children:[o(p===1||d===`html`?`export.standard`:`export.high`),` · `,d===`html`?1:p,`× `,(0,Q.jsx)($,{name:`chevron`,size:12})]})]}),(0,Q.jsxs)(`div`,{className:`export-row`,children:[(0,Q.jsx)(`span`,{children:o(`export.name`)}),g===null?(0,Q.jsxs)(`button`,{type:`button`,className:`btn export-name`,ref:y,title:o(`export.editName`),"aria-label":o(`export.editName`),onClick:()=>_(h),children:[(0,Q.jsx)(`span`,{children:h}),(0,Q.jsx)($,{name:`pencil`,size:14})]}):(0,Q.jsxs)(`form`,{className:`export-name-editor`,onSubmit:e=>{e.preventDefault(),M(!0,!0)},onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||M(!0)},onKeyDown:e=>{e.key!==`Escape`||e.nativeEvent.isComposing||(e.stopPropagation(),M(!1,!0))},children:[(0,Q.jsx)(`input`,{autoFocus:!0,maxLength:160,"aria-label":o(`export.name`),value:g,onFocus:e=>e.currentTarget.select(),onChange:e=>_(e.currentTarget.value)}),(0,Q.jsx)(`button`,{type:`submit`,className:`btn`,onPointerDown:e=>e.preventDefault(),title:o(`export.confirmName`),"aria-label":o(`export.confirmName`),children:(0,Q.jsx)($,{name:`check`,size:15})})]})]})]})]}),(0,Q.jsxs)(`button`,{type:`button`,className:`btn export-start`,disabled:D||!A.length,onClick:()=>void ae(),children:[D&&(0,Q.jsx)(`i`,{style:{width:`${Math.round(te.fraction*100)}%`}}),(0,Q.jsx)(`span`,{children:D?o(`export.progress`,{percent:Math.round(te.fraction*100),done:te.completed,total:te.total}):o(`topbar.export`)})]}),S&&(0,sh.createPortal)((0,Q.jsx)(`div`,{id:`export-options`,className:`export-select`,ref:ee,role:`group`,"aria-label":o(S.kind===`format`?`export.format`:`export.resolution`),children:S.kind===`format`?(0,Q.jsx)(Q.Fragment,{children:fh.map((e,t)=>{let n=Sh.includes(e)&&!b;return(0,Q.jsxs)(`div`,{children:[t===0||t===4?(0,Q.jsx)(`small`,{className:`export-category`,children:o(t===0?`export.imageFormats`:`export.documentFormats`)}):null,(0,Q.jsxs)(`div`,{className:`export-option`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`export-option-label`,"aria-pressed":e===d,onClick:()=>P(e,n,()=>f(e)),children:e.toUpperCase()}),N(e,n)]}),F(e)]},e)})}):(0,Q.jsx)(Q.Fragment,{children:[1,2,3,4].map(e=>{let t=e>1&&!b;return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`export-option`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`export-option-label`,"aria-pressed":e===p,onClick:()=>P(e,t,()=>m(e)),children:[o(e===1?`export.standard`:`export.high`),` · `,e,`×`,ne&&(0,Q.jsxs)(`small`,{children:[ne.width*e,` × `,ne.height*e,` px`]})]}),N(e,t)]}),F(e)]},e)})})}),document.body)]}),document.body)}var wh=[[`1:1`,1080,1080],[`3:4`,1080,1440],[`4:3`,1440,1080],[`16:9`,1920,1080],[`9:16`,1080,1920]],Th=[[`TikTok`,1080,1920],[`Instagram`,1080,1080],[`Instagram 4:5`,1080,1350],[`X`,1600,900],[`小红书`,1080,1440]],Eh=({width:e,height:t})=>[e,t].every(e=>Number.isInteger(e)&&e>=16&&e<=12e3);function Dh({value:e,onChange:t,zh:n,smart:r}){let[i,a]=(0,v.useState)(`common`),[o,s]=(0,v.useState)(null),c=o??e,l=e=>{s(null),Eh(e)&&t(e)};return(0,Q.jsxs)(`div`,{className:`pp-size-picker`,children:[(0,Q.jsxs)(`div`,{className:`pp-size-tabs`,role:`tablist`,"aria-label":n?`尺寸类别`:`Size categories`,children:[(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":i===`common`,onClick:()=>a(`common`),children:n?`常规`:`Common`}),(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":i===`social`,onClick:()=>a(`social`),children:n?`社媒`:`Social`})]}),(0,Q.jsxs)(`div`,{className:`pp-size-main`,children:[(0,Q.jsxs)(`form`,{className:`pp-size-inputs`,onSubmit:e=>{e.preventDefault(),l(c)},children:[[`width`,`height`].map(e=>(0,Q.jsxs)(`label`,{children:[e===`width`?`W`:`H`,(0,Q.jsx)(`input`,{"aria-label":e===`width`?n?`宽度`:`Width`:n?`高度`:`Height`,type:`number`,min:`16`,max:`12000`,value:c[e]||``,onChange:t=>s({...c,[e]:Number(t.currentTarget.value)})})]},e)),o&&(0,Q.jsx)(`button`,{type:`submit`,disabled:!Eh(o),children:n?`应用`:`Apply`})]}),i===`common`&&r,(0,Q.jsx)(`div`,{className:`pp-size-presets`,role:`group`,children:(i===`common`?wh:Th).map(([t,r,i])=>(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":r===e.width&&i===e.height,onClick:()=>l({width:r,height:i}),children:[(0,Q.jsx)(`i`,{style:{width:22*Math.min(1,r/i),height:22*Math.min(1,i/r)}}),(0,Q.jsxs)(`span`,{children:[t===`小红书`&&!n?`RedNote`:t,(0,Q.jsxs)(`small`,{children:[r,` × `,i]})]})]},t))})]})]})}function Oh({controller:e,snap:t,onSize:n}){let r=af(),i=of(),[a,o]=(0,v.useState)(null);Md(a!==null,()=>o(null));let s=t.pages.find(e=>e.id===t.currentPageId),c=np(e,t.sourceVersion),l=s&&ld(s.id),u=l?.ownerDocument.defaultView?.getComputedStyle(l).backgroundColor,d=hd(u);return(0,Q.jsxs)(`div`,{className:`tb-group page-design`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`tb-btn`,disabled:!s,"aria-expanded":a===`size`,"aria-label":r(`design.size`),onClick:()=>o(a===`size`?null:`size`),children:[(0,Q.jsx)($,{name:`crop`}),(0,Q.jsx)(`span`,{className:`tb-text`,children:r(`design.size`)}),(0,Q.jsx)(`span`,{className:`tb-caret`,children:(0,Q.jsx)($,{name:`chevron`,size:12})})]}),(0,Q.jsxs)(`button`,{type:`button`,className:`tb-btn`,disabled:!s,"aria-expanded":a===`color`,"aria-label":r(`design.background`),onClick:()=>o(a===`color`?null:`color`),children:[(0,Q.jsx)(`i`,{className:`background-sample`,style:{background:d?void 0:u}}),(0,Q.jsx)(`span`,{className:`tb-text`,children:r(`design.background`)})]}),a&&s&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`menu-scrim`,onMouseDown:()=>o(null)}),(0,Q.jsx)(`div`,{className:`popover page-design-pop ${a}`,children:a===`size`?(0,Q.jsx)(Dh,{value:s,zh:i===`zh`,onChange:e=>{o(null),(e.width!==s.width||e.height!==s.height)&&n({...e,pageId:s.id})}}):(0,Q.jsx)(ep,{expanded:!0,docColors:c,current:d?`transparent`:_d(u),allowNone:!0,onPick:(t,n)=>{e.apply({kind:`setStyle`,id:s.id,props:{"background-color":t}},{label:`page background`,coalesceKey:n===`live`?`page background`:void 0})}})})]})]})}var kh={saved:`save.saved`,dirty:`save.dirty`,saving:`save.saving`,error:`save.error`};function Ah({controller:e,snap:t,onSize:n,comparing:r,onCompare:i,local:a=!1,canCompare:o=!1}){let s=af(),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(null),f=a||!!sd();Md(c,()=>l(!1));let p=t.docState===`ready`,m=(0,v.useCallback)(async()=>{await e.save();let t=e.getSnapshot();return t.docState===`ready`&&t.saveState===`saved`},[e]);return(0,Q.jsxs)(`header`,{className:`topbar`,children:[(0,Q.jsxs)(`div`,{className:`tb-group`,children:[(0,Q.jsx)(`button`,{type:`button`,id:`btn-undo`,className:`tb-btn`,disabled:!t.canUndo,title:s(`topbar.undo`),"aria-label":s(`topbar.undo`),onClick:e.undo,children:(0,Q.jsx)($,{name:`undo`})}),(0,Q.jsx)(`button`,{type:`button`,id:`btn-redo`,className:`tb-btn`,disabled:!t.canRedo,title:s(`topbar.redo`),"aria-label":s(`topbar.redo`),onClick:e.redo,children:(0,Q.jsx)($,{name:`redo`})}),(0,Q.jsx)(`span`,{className:`tb-sep`}),(0,Q.jsxs)(`button`,{type:`button`,id:`btn-reset-layout`,className:`tb-btn`,disabled:!p,title:s(`topbar.resetLayout`),onClick:()=>void e.resetToInitial(),children:[(0,Q.jsx)($,{name:`reset`}),(0,Q.jsx)(`span`,{className:`tb-label`,children:s(`topbar.resetLayout`)})]})]}),(0,Q.jsx)(Oh,{controller:e,snap:t,onSize:n}),o&&(0,Q.jsxs)(`button`,{type:`button`,className:`tb-btn compare-toggle${r?` active`:``}`,disabled:!p,"aria-pressed":r,"aria-label":s(r?`compare.close`:`compare.open`),onClick:i,children:[(0,Q.jsx)($,{name:`compare`}),(0,Q.jsx)(`span`,{className:`tb-text`,children:s(r?`compare.close`:`compare.open`)})]}),(0,Q.jsx)(`div`,{className:`tb-spacer`}),(0,Q.jsxs)(`span`,{className:`save-state state-${t.saveState}`,role:`status`,children:[(0,Q.jsx)(`i`,{className:`state-dot`}),(0,Q.jsx)(`span`,{className:`save-text`,children:s(kh[t.saveState])})]}),(0,Q.jsxs)(`div`,{className:`tb-menu`,children:[(0,Q.jsxs)(`button`,{type:`button`,id:`btn-export`,className:`tb-btn outlined`,disabled:!p,"aria-haspopup":f?`dialog`:`menu`,"aria-expanded":c,title:s(`topbar.export`),onClick:()=>l(e=>!e),children:[(0,Q.jsx)($,{name:`export`}),(0,Q.jsx)(`span`,{className:`tb-label`,children:s(`topbar.export`)}),(0,Q.jsx)(`span`,{className:`tb-caret`,children:(0,Q.jsx)($,{name:`chevron`,size:12})})]}),c&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`menu-scrim`,onMouseDown:()=>l(!1)}),f?(0,Q.jsx)(Ch,{local:a,controller:e,snap:t,customName:u,onNameChange:d,onClose:()=>l(!1)}):(0,Q.jsxs)(`div`,{id:`pop-export`,className:`popover`,role:`menu`,children:[(0,Q.jsx)(`button`,{type:`button`,role:`menuitem`,className:`menu-item`,onClick:()=>{l(!1),e.downloadAll()},children:s(`topbar.downloadImages`)}),(0,Q.jsx)(`button`,{type:`button`,role:`menuitem`,className:`menu-item`,onClick:()=>{l(!1),e.exportHTML()},children:s(`topbar.exportHtml`)})]})]})]}),e.cloud&&p&&(0,Q.jsx)(oh,{cloud:e.cloud,saveState:t.saveState,saveLocal:m}),(0,Q.jsxs)(`button`,{type:`button`,id:`btn-save`,className:`btn-save`,disabled:!p||t.saveState===`saving`,title:s(`topbar.saveTitle`),onClick:()=>void e.save(),children:[t.saveState!==`saved`&&(0,Q.jsx)(`i`,{className:`save-dot`}),s(`topbar.save`)]})]})}function jh(e,t=!1){let[n,r]=(0,v.useState)(`fit`),[i,a]=(0,v.useState)({width:0,height:0}),o=(0,v.useRef)(null),s=(0,v.useCallback)(e=>{if(o.current?.disconnect(),o.current=null,!e)return;let t=()=>a(t=>t.width===e.clientWidth&&t.height===e.clientHeight?t:{width:e.clientWidth,height:e.clientHeight});t(),typeof ResizeObserver==`function`&&(o.current=new ResizeObserver(t),o.current.observe(e))},[]);(0,v.useEffect)(()=>()=>o.current?.disconnect(),[]);let c=t?{width:(i.width-64-28)/2+64,height:i.height-40}:i,l=n===`fit`?Xm(c,e):n,u=(0,v.useRef)(l),d=(0,v.useRef)(null),f=(0,v.useRef)(null);u.current=l;let p=(0,v.useCallback)(()=>{f.current!==null&&cancelAnimationFrame(f.current),f.current=null,d.current=null},[]);(0,v.useEffect)(()=>p,[p]);let m=(0,v.useCallback)(e=>{if(d.current=e,f.current!==null)return;if(window.matchMedia(`(prefers-reduced-motion: reduce)`).matches){u.current=e,d.current=null,r(e);return}let t=()=>{let e=d.current;if(e===null)return;let n=e-u.current,i=Math.abs(n)<.12?e:u.current+n*.38;u.current=i,r(i),i===e?(f.current=null,d.current=null):f.current=requestAnimationFrame(t)};f.current=requestAnimationFrame(t)},[]),h=(0,v.useCallback)(e=>{p(),r(Ym(e))},[p]),g=(0,v.useCallback)(()=>{p(),r(`fit`)},[p]),_=(0,v.useCallback)(e=>{m(Zm(d.current??u.current,e))},[m]),y=(0,v.useCallback)(e=>{m(Qm(d.current??u.current,e))},[m]),b=(0,v.useCallback)(()=>u.current,[]);return{percent:l,fitting:n===`fit`,stageRef:s,set:h,fit:g,step:_,wheel:y,get:b}}function Mh({controller:e,lang:t,baseHref:n}){return(0,Q.jsx)(rf,{lang:t,children:(0,Q.jsx)(Af,{children:(0,Q.jsx)(Ih,{controller:e,baseHref:n})})})}var Nh=900,Ph=120;function Fh(e){e.target.closest(`button, [data-keepfocus]`)&&e.preventDefault()}function Ih({controller:e,baseHref:t}){let n=af(),r=Of(),i=sp(e),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(null),d=(0,v.useMemo)(()=>({id:l,setId:u}),[l]),f=(0,v.useCallback)(()=>u(null),[]);Ff(e),(0,v.useEffect)(()=>e.onFrameEvent(t=>{t.type===`pointer`&&t.action===`dblclick`&&t.id!==null&&Pf(e,t.id)&&u(t.id)}),[e]);let p=e.pageSize(),m=xs(),h=m?.comparison===!0,[g,_]=(0,v.useState)(()=>h||new URLSearchParams(window.location.search).get(`compare`)===`1`),y=Lm(!!m),b=g,x=jh(p,b),S=()=>{_(e=>!e),x.fit()},C=(0,v.useRef)(x);C.current=x;let w=(0,v.useRef)(new Set),T=(0,v.useRef)(kp),ee=(0,v.useCallback)(e=>(w.current.add(e),e(T.current),()=>{w.current.delete(e)}),[]),E=(0,v.useMemo)(()=>new Mp({controller:e,getZoom:()=>C.current.get()/100,onView:e=>{T.current=e,w.current.forEach(t=>t(e))}}),[e]);(0,v.useEffect)(()=>E.attach(),[E]);let D=(0,v.useMemo)(()=>Xd({controller:e,gestures:E,toast:r,t:n,zoom:{step:e=>C.current.step(e),fit:()=>C.current.fit()}}),[e,E,r,n]);(0,v.useEffect)(()=>{let t=null,i=()=>{if(t===null||e.getSnapshot().docState!==`ready`)return;let i=t;t=null,e.endTextEdit(!0);let a=e.replaceSource(i);r(n(a===null?`history.draftRestored`:`history.draftFailed`),a===null?`info`:`error`)},a=e=>{!ls(e,`popost-workspace`)||e.data.id!==sd()||e.data.type!==`restore-draft`||typeof e.data.html!=`string`||(t=e.data.html,i())};window.addEventListener(`message`,a);let o=e.subscribe(i);return()=>{o(),window.removeEventListener(`message`,a)}},[e,n,r]),(0,v.useEffect)(()=>e.onNotice(e=>{e.key!==`textOverflow`&&r(cf(n,e),e.kind===`error`?`error`:`info`)}),[e,r,n]),(0,v.useEffect)(()=>{let t=(t,n)=>{let r=e.getSnapshot();if(r.docState!==`ready`||r.conflict)return!1;let i=Pp(t,{selectionCount:r.selection.length,editing:r.editingTextId!==null});return!i||n&&i.type!==`save`&&!(i.type===`escape`&&jd())?!1:D.run(i)},n=e=>{if(e.isComposing||e.keyCode===229)return;let n=e.target;if(!e.ctrlKey&&!e.metaKey&&n?.closest(`.rail, #panel`)&&n.tagName===`BUTTON`&&e.key!==`Escape`)return;let r={key:e.key,ctrl:e.ctrlKey,meta:e.metaKey,shift:e.shiftKey,alt:e.altKey};t(r,Ip(e.target))&&e.preventDefault()};window.addEventListener(`keydown`,n);let r=e.onFrameEvent(e=>{e.type===`key`&&t({key:e.key,ctrl:e.ctrl,meta:e.meta,shift:e.shift,alt:e.alt},!1)});return()=>{window.removeEventListener(`keydown`,n),r()}},[e,D]),(0,v.useEffect)(()=>{if(window.innerWidth<Nh)return;let e=setTimeout(()=>o(e=>e??`layers`),Ph);return()=>clearTimeout(e)},[]);let O=i.docState===`loading`,te=i.docState===`error`;return(0,Q.jsxs)(`div`,{className:`app`,onMouseDownCapture:Fh,children:[(0,Q.jsx)(Ah,{local:!!m,canCompare:!!m||!!sd(),controller:e,snap:i,onSize:c,comparing:g,onCompare:S}),(0,Q.jsx)(`div`,{id:`format-toolbar`,className:`format-slot`,role:`toolbar`,"aria-label":n(`toolbar.label`),children:(0,Q.jsx)(pp,{controller:e,actions:D,onOpenBlock:()=>o(`block`),crop:d})}),(0,Q.jsxs)(`div`,{className:`workspace`,children:[(0,Q.jsx)(Pm,{open:a,onAddPage:()=>Dd(e),onToggle:e=>o(t=>t===e?null:e)}),(0,Q.jsx)(Fm,{open:a,controller:e,onClose:()=>o(null)}),(0,Q.jsxs)(`div`,{className:`main`,children:[(0,Q.jsx)($m,{comparing:b,references:y,controller:e,snap:i,zoom:x,gestures:E,subscribeView:ee,actions:D,cropId:l,onExitCrop:f,resize:s?.pageId===i.currentPageId?s:null,onEndResize:()=>c(null)}),(0,Q.jsx)(eh,{snap:i,zoom:x,actions:D}),(0,Q.jsx)(xp,{controller:e,snap:i,baseHref:t,toast:r})]}),O&&(0,Q.jsxs)(`div`,{className:`state-overlay`,role:`status`,children:[(0,Q.jsx)(`span`,{className:`spinner`}),n(`status.loading`)]}),te&&(0,Q.jsxs)(`div`,{className:`state-overlay state-error`,role:`alert`,children:[(0,Q.jsx)(`strong`,{children:n(`status.errorTitle`)}),(0,Q.jsx)(`p`,{children:lf(n,i.error)}),(0,Q.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>void e.reload(),children:n(`status.retry`)})]})]}),i.conflict&&(0,Q.jsx)(Lp,{controller:e})]})}var{controller:Lh,lang:Rh,baseHref:zh}=od();(0,y.createRoot)(document.getElementById(`root`)).render((0,Q.jsx)(v.StrictMode,{children:(0,Q.jsx)(Mh,{controller:Lh,lang:Rh,baseHref:zh})}));export{l as n,c as r,o as t};
72
+ `}))}let a=t;for(let{start:e,end:t,text:n}of i.sort((e,t)=>t.start-e.start))a=a.slice(0,e)+n+a.slice(t);return a}var fm=/(data:[a-z0-9.+/-]*;base64,)([A-Za-z0-9+/=]{1500,})/gi,pm=/\[\[popost-data-(\d+):[^\]]*\]\]/g,mm=e=>e>=1048576?`${(e/1048576).toFixed(1)} MB`:`${Math.max(1,Math.round(e/1024))} KB`;function hm(e){let t=[];return{text:e.replace(fm,(e,n,r)=>(t.push(r),`${n}[[popost-data-${t.length}:${mm(r.length)}]]`)),restore:e=>e.replace(pm,(e,n)=>t[Number(n)-1]??e)}}var gm={empty:`code.err.empty`,"too-large":`code.err.too-large`,"no-slide":`code.err.no-slide`,unsafe:`code.err.unsafe`,rejected:`code.err.rejected`,"not-ready":`code.err.rejected`};function _m({controller:e,onClose:t}){let n=af(),r=sp(e),i=(0,v.useRef)(null),a=(0,v.useRef)(null),o=(0,v.useRef)(null),s=(0,v.useRef)(null),c=(0,v.useRef)(!1),l=(0,v.useRef)(!1),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(!0),[g,_]=(0,v.useState)({key:`code.status.idle`}),y=(0,v.useCallback)(e=>{l.current=e,d(e)},[]),b=(0,v.useCallback)(()=>{let t=o.current;if(!t)return;let n=hm(dm(e.index()));s.current=n,c.current=!0,t.setValue(n.text),c.current=!1,y(!1)},[e,y]),x=(0,v.useCallback)(async()=>{let t=o.current,n=s.current;if(!(!t||!n||!l.current||f)){p(!0);try{let r=e.replaceSource(n.restore(t.getValue()));if(r!==null){let e=gm[r];_(e?{key:e,error:!0}:{key:`code.err.rejected`,error:!0,raw:r});return}b(),await e.save();let i=e.getSnapshot();_(i.saveState===`saved`?{key:`code.status.saved`}:{key:`code.status.appliedUnsaved`,error:i.saveState===`error`})}finally{p(!1)}}},[f,e,b]),S=(0,v.useRef)(x);S.current=x,(0,v.useEffect)(()=>{let e=i.current;if(!e)return;let t=om.default.fromTextArea(e,{mode:`htmlmixed`,lineNumbers:!0,lineWrapping:!0,tabSize:2,indentUnit:2,viewportMargin:10,extraKeys:{"Ctrl-S":()=>void S.current(),"Cmd-S":()=>void S.current()}});o.current=t,t.on(`change`,()=>{c.current||(y(!0),_({key:`code.status.dirty`}))}),b();let n=a.current,r=n&&typeof ResizeObserver<`u`?new ResizeObserver(()=>t.refresh()):null;n&&r?.observe(n);let s=requestAnimationFrame(()=>t.refresh()),l=setTimeout(()=>t.refresh(),230);return()=>{cancelAnimationFrame(s),clearTimeout(l),r?.disconnect(),t.toTextArea(),o.current=null}},[b,y]);let C=(0,v.useRef)(r.sourceVersion);(0,v.useEffect)(()=>{C.current!==r.sourceVersion&&(C.current=r.sourceVersion,l.current||b())},[r.sourceVersion,b]);let w=()=>{o.current?.setOption(`lineWrapping`,!m),h(!m)},T=async()=>{let e=o.current;if(!(!e||!s.current))try{await navigator.clipboard.writeText(s.current.restore(e.getValue())),_({key:`code.status.copied`})}catch{_({key:`code.status.copyFailed`,error:!0})}},ee=g.raw?`${n(g.key)}: ${g.raw}`:n(g.key);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`panel-head`,children:[(0,Q.jsx)(`h2`,{children:n(`panel.code`)}),(0,Q.jsxs)(`div`,{className:`code-header-tools`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`tb-btn small`,onClick:w,children:[(0,Q.jsx)($,{name:`wrap`,size:14}),n(m?`code.disableWrap`:`code.enableWrap`)]}),(0,Q.jsxs)(`button`,{type:`button`,className:`tb-btn small`,disabled:r.docState!==`ready`,onClick:()=>void T(),children:[(0,Q.jsx)($,{name:`duplicate`,size:14}),n(`code.copy`)]}),(0,Q.jsx)(`button`,{type:`button`,id:`panel-close`,className:`tb-btn small`,title:n(`panel.close`),"aria-label":n(`panel.close`),onClick:t,children:(0,Q.jsx)($,{name:`close`,size:14})})]})]}),(0,Q.jsxs)(`div`,{className:`panel-body code-panel`,"data-panel-body":`code`,children:[(0,Q.jsx)(`div`,{ref:a,className:`code-host`,children:(0,Q.jsx)(`textarea`,{id:`canvas-code-source`,ref:i,defaultValue:``,spellCheck:!1})}),(0,Q.jsx)(`div`,{id:`code-status`,className:`code-status${g.error?` error`:``}`,role:`status`,children:ee}),(0,Q.jsxs)(`div`,{className:`code-actions`,children:[(0,Q.jsxs)(`button`,{type:`button`,id:`code-save`,className:`btn primary`,disabled:!u||f,onClick:()=>void x(),children:[n(f?`code.saving`:`code.save`),(0,Q.jsx)(`i`,{className:`code-unsaved-dot`,hidden:!u})]}),(0,Q.jsx)(`button`,{type:`button`,id:`code-download-html`,className:`btn`,onClick:()=>{let t=o.current,n=s.current;u&&t&&n?zu(Ru(r.name),Lu(n.restore(t.getValue()))):e.exportHTML(),_({key:`code.status.downloaded`})},children:n(`code.download`)})]})]})]})}var vm=36;function ym(e,t=vm){let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-1)}…`:n}function bm(e){if(!e||/^data:/i.test(e.trim()))return``;let t=e.split(/[?#]/)[0]?.split(`/`).filter(Boolean).at(-1)??``;try{return decodeURIComponent(t)}catch{return t}}function xm(e,t,n){let r=e.elements.get(t);return r?n===`image`?ym(Pi(r,`alt`)??``)||bm(Pi(r,`src`)):n===`text`?ym(zi(e,t)):ym(Pi(r,`data-layer-id`)??Pi(r,`aria-label`)??``)||ym(zi(e,t)):``}function Sm(e,t){if(t===null)return[];let n=Ga(e,t),r=new Set(n),i=new Map;return n.map(n=>{let a=e.elements.get(n),o=a?.parent??null;for(;o!==null&&o!==t&&!r.has(o);)o=e.elements.get(o)?.parent??null;let s=o!==null&&r.has(o)?(i.get(o)??0)+1:0;i.set(n,s);let c=Wa(e,n);return{id:n,kind:c,depth:s,tag:a?.tag.toLowerCase()??``,snippet:xm(e,n,c),parentId:a?.parent??null}})}function Cm(e,t,n,r){if(t===n)return null;let i=e.elements.get(t)?.parent;if(!i||e.elements.get(n)?.parent!==i)return null;let a=(e.elements.get(i)?.children??[]).filter(e=>e!==t),o=a.indexOf(n);if(o<0)return null;let s=a[r===`before`?o:o+1]??null,c=(e.elements.get(i)?.children??[]).indexOf(t),l=[...a];return l.splice(s===null?l.length:l.indexOf(s),0,t),l.indexOf(t)===c?null:{kind:`move`,id:t,parentId:i,beforeId:s}}function wm(e,t,n,r){let i=e.elements.get(t)?.parent;if(!i)return null;let a=(e.elements.get(i)?.children??[]).filter(e=>e!==t).indexOf(n);return a<0?null:r===`before`?a:a+1}var Tm={text:`text`,image:`image`,svg:`shape`,video:`play`,box:`block`},Em={text:`layers.kind.text`,image:`layers.kind.image`,svg:`layers.kind.svg`,video:`layers.kind.video`,box:`layers.kind.box`};function Dm({controller:e}){let t=af(),n=sp(e),r=(0,v.useMemo)(()=>Sm(e.index(),n.currentPageId),[e,n.currentPageId,n.sourceVersion]),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(null),c=(0,v.useRef)(null);(0,v.useEffect)(()=>()=>e.highlight([]),[e]);let l=n.selection.join(`,`);(0,v.useEffect)(()=>{let e=n.selection[0];e!==void 0&&c.current?.querySelector(`[data-layer-id="${e}"]`)?.scrollIntoView({block:`nearest`})},[l,n.selection]);let u=(t,n)=>e.select([n],{additive:t.shiftKey}),d=t=>!i||i===t.id?!1:e.index().elements.get(i)?.parent===t.parentId,f=(e,t)=>{if(!d(t)){s(null);return}e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=e.currentTarget.getBoundingClientRect(),r=e.clientY<n.top+n.height/2?`before`:`after`;(o?.id!==t.id||o.where!==r)&&s({id:t.id,where:r})},p=(t,n)=>{t.preventDefault();let r=i,c=o?.id===n.id?o.where:`after`;if(a(null),s(null),!r||!d(n))return;let l=e.index(),u=Cm(l,r,n.id,c);if(!u)return;let f=l.elements.get(r)?.parent,p=wm(l,r,n.id,c);if(e.apply(u,{label:`reorder layer`}),f&&p!==null){let t=e.index().elements.get(f)?.children[p];t!==void 0&&e.select([t])}};return(0,Q.jsxs)(`div`,{className:`panel-body layers`,"data-panel-body":`layers`,children:[r.length===0&&(0,Q.jsx)(`p`,{className:`p-hint`,children:t(`layers.empty`)}),(0,Q.jsx)(`div`,{ref:c,className:`layer-list`,role:`tree`,"aria-label":t(`panel.layers`),onMouseLeave:()=>e.highlight([]),children:r.map(r=>{let c=n.selection.includes(r.id),l=[`layer-row`,c?`selected`:``,i===r.id?`dragging`:``,o?.id===r.id?`drop-${o.where}`:``].filter(Boolean).join(` `);return(0,Q.jsxs)(`div`,{className:l,role:`treeitem`,"aria-selected":c,tabIndex:0,draggable:!0,"data-layer-id":r.id,"data-kind":r.kind,style:{paddingLeft:8+r.depth*14},onClick:e=>u(e,r.id),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),u(e,r.id))},onMouseEnter:()=>e.highlight([r.id]),onDragStart:e=>{a(r.id),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,r.id)},onDragOver:e=>f(e,r),onDrop:e=>p(e,r),onDragEnd:()=>{a(null),s(null)},children:[(0,Q.jsx)(`span`,{className:`layer-icon`,title:t(Em[r.kind]),children:(0,Q.jsx)($,{name:Tm[r.kind],size:14})}),(0,Q.jsx)(`span`,{className:`layer-kind`,children:t(Em[r.kind])}),(0,Q.jsx)(`span`,{className:`layer-snippet`,children:r.snippet})]},r.id)})})]})}var Om=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`),km={heading:{tag:`h1`,size:.07,weight:700,line:1.15},subheading:{tag:`h2`,size:.045,weight:600,line:1.25},paragraph:{tag:`p`,size:.03,weight:400,line:1.5}};function Am(e,t,n,r=`#222222`){let i=km[e],a=Math.round(t*.07),o=`position:absolute;z-index:100;left:${a}px;top:${a}px;max-width:${t-2*a}px;margin:0;color:${r};font-size:${Math.round(t*i.size)}px;font-weight:${i.weight};line-height:${i.line}`;return`<${i.tag} style="${o}">${Om(n)}</${i.tag}>`}var jm=[{kind:`heading`,id:`add-heading`,label:`text.addHeading`,sample:`text.sampleHeading`,icon:`H1`},{kind:`subheading`,id:`add-subheading`,label:`text.addSubheading`,sample:`text.sampleSubheading`,icon:`H2`},{kind:`paragraph`,id:`add-paragraph`,label:`text.addParagraph`,sample:`text.sampleParagraph`,icon:`P`}];function Mm({controller:e}){let t=af(),n=sp(e),r=np(e,n.sourceVersion),i=rp(e,n,[`color`]),a=tp(n),[o,s]=(0,v.useState)(`#222222`),c=n.editingTextId!==null&&n.textState?.range===!0,l=(r,i)=>{if(n.currentPageId===null)return;e.apply({kind:`insertHTML`,parentId:n.currentPageId,beforeId:null,html:Am(r,e.pageSize().width,t(i),o)},{label:`add text`});let a=e.getSnapshot().selection[0];a!==void 0&&e.index().elements.has(a)&&e.beginTextEdit(a,`all`)};return(0,Q.jsxs)(`div`,{className:`panel-body`,"data-panel-body":`text`,children:[(0,Q.jsxs)(`section`,{className:`p-section`,children:[(0,Q.jsx)(`h3`,{children:t(`text.add`)}),(0,Q.jsx)(`div`,{className:`add-list`,children:jm.map(e=>(0,Q.jsxs)(`button`,{type:`button`,id:e.id,className:`add-item add-${e.kind}`,disabled:n.docState!==`ready`,onClick:()=>l(e.kind,e.sample),children:[(0,Q.jsx)(`span`,{className:`add-icon`,children:e.icon}),(0,Q.jsx)(`span`,{children:t(e.label)})]},e.kind))})]}),(0,Q.jsxs)(`section`,{className:`p-section`,children:[(0,Q.jsx)(`h3`,{children:t(`text.color`)}),(0,Q.jsx)(ep,{docColors:r,current:_d(i.color)??_d(o),onPick:(t,n)=>{c&&n===`live`||(s(t),a.length&&e.format({command:`color`,value:t}))}})]})]})}var Nm=[{id:`layers`,icon:`layers`,label:`panel.layers`},{id:`block`,icon:`block`,label:`panel.block`},{id:`code`,icon:`code`,label:`panel.code`}];function Pm({open:e,onToggle:t,onAddPage:n}){let r=af(),[i,a]=(0,v.useState)(!1);return Md(i,()=>a(!1)),(0,Q.jsxs)(`nav`,{className:`rail`,"aria-label":r(`rail.label`),children:[Nm.map(n=>(0,Q.jsxs)(`button`,{type:`button`,className:`rail-item${e===n.id?` active`:``}`,"data-panel":n.id,"aria-pressed":e===n.id,title:r(n.label),onClick:()=>t(n.id),children:[(0,Q.jsx)($,{name:n.icon,size:18}),(0,Q.jsx)(`span`,{children:r(n.label)})]},n.id)),(0,Q.jsxs)(`div`,{className:`rail-add`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`rail-item${e===`text`||e===`images`?` active`:``}`,"aria-expanded":i,onClick:()=>a(!i),children:[(0,Q.jsx)($,{name:`plus`,size:18}),(0,Q.jsx)(`span`,{children:r(`panel.add`)})]}),i&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`menu-scrim`,onMouseDown:()=>a(!1)}),(0,Q.jsxs)(`div`,{className:`popover add-popover`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`menu-item`,onClick:()=>{a(!1),e!==`text`&&t(`text`)},children:[(0,Q.jsx)($,{name:`text`}),r(`add.text`)]}),(0,Q.jsxs)(`button`,{type:`button`,className:`menu-item`,onClick:()=>{a(!1),e!==`images`&&t(`images`)},children:[(0,Q.jsx)($,{name:`image`}),r(`panel.images`)]}),(0,Q.jsxs)(`button`,{type:`button`,className:`menu-item`,onClick:()=>{a(!1),n()},children:[(0,Q.jsx)($,{name:`plus`}),r(`add.page`)]})]})]})]})]})}function Fm({open:e,controller:t,onClose:n}){let r=af();if(!e)return(0,Q.jsx)(`aside`,{id:`panel`,className:`panel`,"aria-hidden":`true`});let i={text:(0,Q.jsx)(Mm,{controller:t}),block:(0,Q.jsx)(im,{controller:t}),layers:(0,Q.jsx)(Dm,{controller:t}),images:(0,Q.jsx)(zp,{controller:t})};return(0,Q.jsx)(`aside`,{id:`panel`,className:`panel open`,"data-open":e,"data-view":e,children:e===`code`?(0,Q.jsx)(_m,{controller:t,onClose:n}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`panel-head`,children:[(0,Q.jsx)(`h2`,{children:r(Nm.find(t=>t.id===e)?.label??(e===`images`?`panel.images`:`panel.text`))}),(0,Q.jsx)(`button`,{type:`button`,id:`panel-close`,className:`tb-btn small`,title:r(`panel.close`),"aria-label":r(`panel.close`),onClick:n,children:(0,Q.jsx)($,{name:`close`,size:14})})]}),i[e]]})})}var Im=(e,t,n)=>e.some(e=>e.pageKey!==void 0)?e.find(e=>e.pageKey===n)??null:e[t]??null;function Lm(e){let[t,n]=(0,v.useState)({images:[],status:`loading`}),[r,i]=(0,v.useState)(0);return(0,v.useEffect)(()=>{if(!e&&!sd())return;let t=!0;return(e?fetch(`/api/comparison`,{cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(`Reference images unavailable`);return(await e.json()).items}):cd(`references`,void 0,1e4)).then(e=>{t&&n({images:e.filter(e=>typeof e?.src==`string`),status:`ready`})}).catch(()=>{t&&n({images:[],status:`failed`})}),()=>{t=!1}},[r,e]),{...t,retry:()=>{n({images:[],status:`loading`}),i(e=>e+1)}}}function Rm({state:e,pageIndex:t,pageKey:n,scale:r}){let i=af(),a=Im(e.images,t,n),[o,s]=(0,v.useState)(null),c=a?.width||(o&&o.src===a?.src?o.width:0)||1080,l=a?.height||(o&&o.src===a?.src?o.height:0)||1440;return(0,Q.jsxs)(`section`,{className:`comparison-reference`,"aria-label":i(`compare.reference`),style:{width:Math.round(c*r),height:Math.round(l*r)},children:[(0,Q.jsxs)(`div`,{className:`comparison-caption`,children:[(0,Q.jsx)(`span`,{children:i(`compare.reference`)}),(0,Q.jsxs)(`span`,{children:[i(`compare.page`,{n:t+1}),` · `,i(`compare.readonly`)]})]}),a?(0,Q.jsx)(zm,{image:a,onSize:(e,t)=>s({src:a.src,width:e,height:t})},a.src):(0,Q.jsxs)(`div`,{className:`comparison-empty`,role:`status`,children:[(0,Q.jsx)($,{name:`image`,size:28}),(0,Q.jsx)(`strong`,{children:i(e.status===`loading`?`compare.loading`:e.status===`failed`?`compare.failed`:`compare.empty`)}),e.status===`failed`?(0,Q.jsx)(`button`,{type:`button`,className:`tb-btn outlined`,onClick:e.retry,children:i(`compare.retry`)}):(0,Q.jsx)(`span`,{children:i(`compare.emptyHint`)})]})]})}function zm({image:e,onSize:t}){let n=af(),[r,i]=(0,v.useState)(!1);return r?(0,Q.jsxs)(`div`,{className:`comparison-empty`,children:[(0,Q.jsx)($,{name:`image`,size:28}),(0,Q.jsx)(`span`,{children:n(`compare.imageFailed`)}),(0,Q.jsx)(`button`,{type:`button`,className:`tb-btn outlined`,onClick:()=>i(!1),children:n(`compare.retry`)})]}):(0,Q.jsx)(`img`,{className:`comparison-image`,src:e.src,alt:e.name||n(`compare.reference`),draggable:!1,onLoad:e=>t(e.currentTarget.naturalWidth,e.currentTarget.naturalHeight),onError:()=>i(!0)})}async function Bm(e,t,n){let r=e?.ownerDocument.defaultView?.getComputedStyle(e),i=/^url\(["']?(.*?)["']?\)$/.exec(r?.backgroundImage??``);if(!r||!i?.[1])return{};if(![`cover`,`contain`].includes(r.backgroundSize))return!/^[-.\d]+px$/.test(r.backgroundPositionX)||!/^[-.\d]+px$/.test(r.backgroundPositionY)?{}:{"background-position":`${parseFloat(r.backgroundPositionX)-n.x}px ${parseFloat(r.backgroundPositionY)-n.y}px`};let a=new Image;a.src=i[1];try{await a.decode()}catch{return{}}let{naturalWidth:o,naturalHeight:s}=a;if(!o||!s)return{};let c=(r.backgroundSize===`cover`?Math.max:Math.min)(t.width/o,t.height/s),l=o*c,u=s*c,d=(e,t)=>e.endsWith(`%`)?t*parseFloat(e)/100:parseFloat(e)||0;return{"background-size":`${l}px ${u}px`,"background-position":`${d(r.backgroundPositionX,t.width-l)-n.x}px ${d(r.backgroundPositionY,t.height-u)-n.y}px`}}function Vm({request:e,controller:t,scale:n,onClose:r}){let i=af(),a=t.pageSize(),o=Math.max(0,a.width-e.width),s=Math.max(0,a.height-e.height),[c,l]=(0,v.useState)({x:Math.round(o/2),y:Math.round(s/2)}),u=(0,v.useRef)(null);Md(!0,r);let d=e=>{if(!e.currentTarget.hasPointerCapture(e.pointerId)||!u.current)return;let t=u.current;l({x:Math.round(Math.max(0,Math.min(o,t.left+(e.clientX-t.x)/n))),y:Math.round(Math.max(0,Math.min(s,t.top+(e.clientY-t.y)/n)))})},[f,p]=(0,v.useState)(!1),m=async()=>{if(f)return;p(!0);let{pageId:n,width:i,height:o}=e,s=t.index().elements.get(n)?.children??[],l=c.x===0&&c.y===0?[]:s.flatMap(e=>{let t=ld(e),n=t?.ownerDocument.defaultView?.getComputedStyle(t);if(!n||n.display===`none`||t?.tagName===`STYLE`)return[];let r=n.transform===`none`?``:` ${n.transform}`;return[{kind:`setStyle`,id:e,props:{transform:`translate(${-c.x}px, ${-c.y}px)${r}`}}]}),u=await Bm(ld(n),a,c);if(t.getSnapshot().currentPageId!==n){r();return}t.applyBatch([{kind:`setAttr`,id:n,name:`data-popost-width`,value:String(i)},{kind:`setAttr`,id:n,name:`data-popost-height`,value:String(o)},{kind:`setStyle`,id:n,props:{width:`${i}px`,height:`${o}px`,overflow:`hidden`,...u}},...l],`resize page`),r()};return(0,Q.jsxs)(`div`,{className:`page-resize-layer`,children:[(0,Q.jsxs)(`div`,{className:`page-resize-actions`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`btn`,onClick:r,children:i(`design.cancel`)}),(0,Q.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:f,onClick:()=>void m(),children:i(`design.apply`)}),(0,Q.jsxs)(`span`,{children:[e.width,` × `,e.height,` px`]})]}),(0,Q.jsx)(`div`,{className:`page-resize-hit`,onPointerDown:e=>{u.current={x:e.clientX,y:e.clientY,left:c.x,top:c.y},e.currentTarget.setPointerCapture(e.pointerId)},onPointerMove:d,children:(0,Q.jsx)(`div`,{className:`page-resize-frame`,style:{width:e.width*n,height:e.height*n,left:c.x*n,top:c.y*n}})})]})}var Hm=[`nw`,`ne`,`sw`,`se`,`w`,`e`],Um={nw:[0,0],ne:[100,0],sw:[0,100],se:[100,100],w:[0,50],e:[100,50]},Wm={nw:`nwse-resize`,se:`nwse-resize`,ne:`nesw-resize`,sw:`nesw-resize`,w:`ew-resize`,e:`ew-resize`},Gm=236,Km=36,qm=(e,t)=>({left:e.x*t,top:e.y*t,width:e.width*t,height:e.height*t});function Jm({controller:e,snap:t,scale:n,width:r,gestures:i,view:a,actions:o}){let s=af(),{rects:c,selection:l,hoverId:u,editingTextId:d}=t,f=l.filter(e=>c[e]),p=Ep(f.map(e=>c[e])),m=f.length===1?f[0]:null,h=d!==null,g=a.active===`move`||a.active===`resize`,_=u!==null&&!l.includes(u)&&!h&&!g?c[u]:void 0,v=e=>({"data-keepfocus":``,onPointerDown:t=>{t.button===0&&(t.preventDefault(),t.stopPropagation(),t.currentTarget.setPointerCapture(t.pointerId),e(t))},onPointerMove:e=>{e.currentTarget.hasPointerCapture(e.pointerId)&&i.overlayMove(e.clientX,e.clientY,e.altKey)},onPointerUp:e=>{e.currentTarget.hasPointerCapture(e.pointerId)&&(e.currentTarget.releasePointerCapture(e.pointerId),i.overlayUp())},onPointerCancel:()=>{i.cancel()}}),y=p?p.y*n>=48?p.y*n-Km-8:(p.y+p.height)*n+8:0,b=p?Math.max(0,Math.min(p.x*n,r-Gm)):0,x=m?Wa(e.index(),m):null;return(0,Q.jsxs)(`div`,{className:`overlay`,"aria-hidden":!1,children:[_&&(0,Q.jsx)(`div`,{className:`ov-hover`,style:qm(_,n)}),f.map(e=>(0,Q.jsx)(`div`,{className:`ov-sel${f.length>1?` multi`:``}${h?` editing`:``}`,style:qm(c[e],n),"data-sel-id":e},e)),p&&f.length>1&&(0,Q.jsx)(`div`,{className:`ov-group`,style:qm(p,n)}),p&&m&&!h&&(0,Q.jsx)(`div`,{className:`ov-handles`,style:qm(p,n),children:Hm.map(e=>(0,Q.jsx)(`span`,{className:`ov-handle h-${e}`,"data-handle":e,style:{left:`${Um[e][0]}%`,top:`${Um[e][1]}%`,cursor:Wm[e]},...v(t=>i.startResize(e,t.clientX,t.clientY))},e))}),p&&!h&&(0,Q.jsxs)(`div`,{className:`ov-pill${g?` hidden`:``}`,style:{left:b,top:y},role:`toolbar`,"data-keepfocus":``,children:[(0,Q.jsx)(`span`,{className:`pill-grip`,title:s(`pill.move`),...v(e=>i.startPillMove(e.clientX,e.clientY)),children:(0,Q.jsx)($,{name:`grip`})}),f.length>1&&(0,Q.jsx)(`span`,{className:`pill-count`,children:s(`pill.selected`,{n:f.length})}),m&&x!==null&&(0,Q.jsx)(`button`,{type:`button`,className:`pill-btn`,"data-act":`parent`,title:s(`pill.selectParent`),onClick:()=>e.selectParent(),children:(0,Q.jsx)($,{name:`parent`})}),(0,Q.jsx)(`button`,{type:`button`,className:`pill-btn`,"data-act":`duplicate`,title:s(`pill.duplicate`),onClick:o.duplicateSelection,children:(0,Q.jsx)($,{name:`duplicate`})}),(0,Q.jsx)(`button`,{type:`button`,className:`pill-btn danger`,"data-act":`delete`,title:s(`pill.delete`),onClick:o.deleteSelection,children:(0,Q.jsx)($,{name:`trash`})}),m&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{type:`button`,className:`pill-btn`,"data-act":`forward`,title:s(`pill.forward`),onClick:()=>o.reorderSelection(`down`),children:(0,Q.jsx)($,{name:`forward`})}),(0,Q.jsx)(`button`,{type:`button`,className:`pill-btn`,"data-act":`backward`,title:s(`pill.backward`),onClick:()=>o.reorderSelection(`up`),children:(0,Q.jsx)($,{name:`backward`})})]})]}),a.guides.map((e,t)=>e.axis===`x`?(0,Q.jsx)(`div`,{className:`ov-guide v`,style:{left:e.pos*n,top:e.from*n,height:(e.to-e.from)*n}},t):(0,Q.jsx)(`div`,{className:`ov-guide h`,style:{top:e.pos*n,left:e.from*n,width:(e.to-e.from)*n}},t)),a.marquee&&(0,Q.jsx)(`div`,{className:`ov-marquee`,style:qm(a.marquee,n)}),a.tip&&(0,Q.jsx)(`div`,{className:`ov-tip`,style:{left:a.tip.x*n,top:a.tip.y*n+8},children:a.tip.text})]})}var Ym=e=>Math.min(300,Math.max(10,e));function Xm(e,t,n=32){if(t.width<=0||t.height<=0)return 100;let r=Math.max(1,e.width-n*2),i=Math.max(1,e.height-n*2);return Math.min(300,Math.max(10,Math.min(r/t.width,i/t.height)*100))}function Zm(e,t){return Ym(e*(t>0?1.12:1/1.12))}var Qm=(e,t)=>Ym(e*Math.exp(-t*.002));function $m({comparing:e,references:t,controller:n,snap:r,zoom:i,gestures:a,subscribeView:o,actions:s,cropId:c=null,onExitCrop:l,resize:u,onEndResize:d}){let f=af(),p=r.pages.findIndex(e=>e.id===r.currentPageId),{stageRef:m,wheel:h}=i,g=(0,v.useRef)(null),[_,y]=(0,v.useState)(kp),b=n.pageSize(),x=i.percent/100,S=Math.round(b.width*x),C=Math.round(b.height*x),w=(0,v.useRef)(null),T=(0,v.useCallback)(e=>{w.current=e,n.attachFrame(e)},[n]);(0,v.useEffect)(()=>o(y),[o]),(0,v.useEffect)(()=>{let e=w.current;if(!e)return;let t=null,n=()=>{t?.(),t=null;let n=e.contentWindow;if(!n)return;let r=e=>{e.key!==`Escape`||!jd()||(e.preventDefault(),e.stopPropagation(),Ad())};n.addEventListener(`keydown`,r,!0),t=()=>n.removeEventListener(`keydown`,r,!0)};return n(),e.addEventListener(`load`,n),()=>{e.removeEventListener(`load`,n),t?.()}},[]),(0,v.useEffect)(()=>{let e=g.current;if(!e)return;let t=t=>{!t.ctrlKey&&!t.metaKey||(t.preventDefault(),h(t.deltaY*(t.deltaMode===1?16:t.deltaMode===2?e.clientHeight:1)))};e.addEventListener(`wheel`,t,{passive:!1});let r=n.onFrameEvent(t=>{t.type===`wheel`&&(t.ctrl?h(t.deltaY):e.scrollBy(t.deltaX,t.deltaY))});return()=>{e.removeEventListener(`wheel`,t),r()}},[n,h]);let ee=(0,v.useCallback)(e=>{g.current=e,m(e)},[m]);return(0,Q.jsx)(`div`,{className:`stage`,ref:ee,tabIndex:-1,onMouseDown:e=>{let t=e.target;(t===e.currentTarget||t.classList.contains(`stage-pad`))&&(n.select([]),e.currentTarget.focus({preventScroll:!0}))},children:(0,Q.jsxs)(`div`,{className:`stage-pad${e?` comparing`:``}`,style:{padding:32},children:[e&&(0,Q.jsx)(Rm,{state:t,pageIndex:p,pageKey:r.pages[p]?.pageKey??null,scale:x}),(0,Q.jsxs)(`div`,{className:`canvas`,style:{width:S,height:C},children:[e&&(0,Q.jsxs)(`div`,{className:`comparison-caption result-caption`,children:[(0,Q.jsx)(`span`,{children:f(`compare.result`)}),(0,Q.jsxs)(`span`,{children:[f(`compare.page`,{n:p+1}),` · `,f(`compare.editable`)]})]}),(0,Q.jsx)(`iframe`,{id:`frame`,ref:T,title:`canvas`,style:{width:b.width,height:b.height,transform:`scale(${x})`}}),(0,Q.jsx)(Jm,{controller:n,snap:r,scale:x,width:S,gestures:a,view:_,actions:s}),u&&(0,Q.jsx)(Vm,{request:u,controller:n,scale:x,onClose:d},u.pageId),!u&&c!==null&&l&&(0,Q.jsx)(Lf,{controller:n,snap:r,id:c,scale:x,onExit:l})]})]})})}function eh({snap:e,zoom:t,actions:n}){let r=af(),i=e.pages.findIndex(t=>t.id===e.currentPageId),a=e.pages.length;return(0,Q.jsxs)(`div`,{className:`statusbar`,children:[(0,Q.jsxs)(`div`,{className:`sb-group`,children:[(0,Q.jsx)(`button`,{type:`button`,id:`btn-prev-page`,className:`tb-btn small`,disabled:i<=0,title:r(`pages.prev`),"aria-label":r(`pages.prev`),onClick:()=>n.changePage(`prev`),children:(0,Q.jsx)($,{name:`prev`,size:14})}),(0,Q.jsx)(`span`,{id:`page-counter`,className:`page-counter`,children:r(`pages.counter`,{n:i+1,total:a})}),(0,Q.jsx)(`button`,{type:`button`,id:`btn-next-page`,className:`tb-btn small`,disabled:i<0||i>=a-1,title:r(`pages.next`),"aria-label":r(`pages.next`),onClick:()=>n.changePage(`next`),children:(0,Q.jsx)($,{name:`next`,size:14})})]}),(0,Q.jsx)(`div`,{className:`sb-spacer`}),(0,Q.jsxs)(`div`,{className:`sb-group zoom-group`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`tb-btn small`,"aria-label":r(`zoom.out`),disabled:t.percent<=10,onClick:()=>t.step(-1),children:(0,Q.jsx)($,{name:`minus`,size:15})}),(0,Q.jsx)(`button`,{type:`button`,className:`tb-btn small`,"aria-label":r(`zoom.in`),disabled:t.percent>=300,onClick:()=>t.step(1),children:(0,Q.jsx)($,{name:`plus`,size:15})}),(0,Q.jsx)(`input`,{id:`zoom-slider`,type:`range`,min:10,max:300,step:1,value:Math.round(t.percent),"aria-label":r(`zoom.slider`),onChange:e=>t.set(Number(e.currentTarget.value))}),(0,Q.jsxs)(`button`,{type:`button`,id:`zoom-label`,className:`zoom-label`,title:r(`zoom.fit`),onClick:t.fit,children:[Math.round(t.percent),`%`]})]})]})}var th=2e3;function nh(e,t){let n=`cloud.error.${t??``}`;return n in ef.en?e(n):e(`cloud.error.generic`)}function rh({href:e,t}){return e?(0,Q.jsx)(`a`,{className:`cloud-link`,href:e,target:`_blank`,rel:`noopener noreferrer`,title:t(`cloud.openTitle`),children:t(`cloud.open`)}):null}function ih({mode:e,status:t,link:n,copied:r,busy:i,onStart:a,onPush:o,onRetry:s,onCopy:c}){let l=af(),u=i===`push`?`uploading`:i===`start`?`starting`:t?.state??`idle`,d=e=>(0,Q.jsx)(`span`,{className:`tb-label`,children:l(e)});if(u===`uploading`)return(0,Q.jsxs)(`span`,{className:`cloud-state`,role:`status`,children:[(0,Q.jsx)(`i`,{className:`spinner small`}),l(e===`keyed`?`cloud.syncing`:`cloud.uploading`)]});if(u===`starting`)return(0,Q.jsxs)(`span`,{className:`cloud-state`,role:`status`,children:[(0,Q.jsx)(`i`,{className:`spinner small`}),l(`cloud.waiting`)]});if(u===`waiting`)return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`span`,{className:`cloud-state`,role:`status`,children:[(0,Q.jsx)(`i`,{className:`spinner small`}),l(`cloud.waiting`)]}),(0,Q.jsx)(`button`,{type:`button`,className:`tb-btn outlined cloud-copy`,onClick:c,children:l(r?`cloud.linkCopied`:`cloud.copyLink`)}),n&&(0,Q.jsx)(`input`,{className:`cloud-link-input`,readOnly:!0,value:n,"aria-label":l(`cloud.loginLink`),onFocus:e=>e.currentTarget.select()})]});if(u===`saved`)return(0,Q.jsxs)(`span`,{className:`cloud-state`,role:`status`,children:[(0,Q.jsx)($,{name:`check`,size:14}),l(e===`keyed`?`cloud.synced`:`cloud.saved`),(0,Q.jsx)(rh,{href:t?.webUrl,t:l})]});if(u===`failed`)return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`cloud-state cloud-error`,role:`status`,title:t?.error?.message,children:nh(l,t?.error?.code)}),(0,Q.jsx)(`button`,{type:`button`,className:`tb-btn outlined`,onClick:s,children:l(`cloud.retry`)})]});if(u===`conflict`)return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`span`,{className:`cloud-state cloud-error`,role:`status`,children:[l(`cloud.conflict`),(0,Q.jsx)(rh,{href:t?.webUrl,t:l})]}),e===`keyed`?(0,Q.jsx)(`button`,{type:`button`,className:`tb-btn outlined`,title:l(`cloud.overwriteTitle`),onClick:()=>o(!0),children:l(`cloud.overwrite`)}):null]});if(e===`keyed`)return(0,Q.jsxs)(`button`,{type:`button`,className:`tb-btn outlined cloud-btn`,title:l(`cloud.syncNow`),"aria-label":l(`cloud.syncNow`),onClick:()=>o(!1),children:[(0,Q.jsx)($,{name:`cloud`}),d(`cloud.syncNow`)]});let f=!!(t?.webUrl&&t.dirty);return(0,Q.jsxs)(`button`,{type:`button`,className:`tb-btn outlined cloud-btn`,title:l(`cloud.tooltip`),"aria-label":l(`cloud.save`),onClick:a,children:[(0,Q.jsx)($,{name:`cloud`}),(0,Q.jsx)(`span`,{className:`tb-label`,children:l(f?`cloud.dirty`:`cloud.save`)})]})}var ah=e=>({code:e instanceof Error&&`status`in e?`ERROR`:`NETWORK`,message:e instanceof Error?e.message:String(e)});function oh({cloud:e,saveState:t,saveLocal:n}){let r=of(),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(!1),g=(0,v.useRef)(!0),_=(0,v.useRef)(`push`);(0,v.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]);let y=(0,v.useCallback)(async()=>{try{let t=await e.status();g.current&&a(t)}catch{}},[e]);(0,v.useEffect)(()=>void y(),[y,t]);let b=c!==null||i?.state===`waiting`||i?.state===`uploading`||e.mode===`keyed`&&i?.state===`idle`&&i.dirty;(0,v.useEffect)(()=>{if(!b)return;let e=setInterval(()=>void y(),th);return()=>clearInterval(e)},[b,y]);let x=(0,v.useCallback)(async()=>{let t=window.open(`about:blank`,`_blank`);_.current=`start`,s(void 0),h(!1),l(`start`);try{if(!await n()){t?.close(),s({code:`LOCAL_SAVE_FAILED`,message:``});return}let{authorizeUrl:i}=await e.start(r);d(i),p(!t),t&&(t.opener=null,t.location.href=i),_.current=`push`,await y()}catch(e){t?.close(),s(ah(e))}finally{l(null)}},[e,r,y,n]),S=(0,v.useCallback)(async t=>{_.current=`push`,s(void 0),l(`push`);try{if(!await n()){s({code:`LOCAL_SAVE_FAILED`,message:``});return}let i=await e.push({force:t,lang:r});if(i.ok===!1&&i.error?.code===`LOGIN_REQUIRED`){l(null),await x();return}g.current&&a(i)}catch(e){s(ah(e))}finally{l(null)}},[e,r,n,x]),C=(0,v.useCallback)(async()=>{try{await navigator.clipboard.writeText(u??``),h(!0)}catch{p(!0)}},[u]),w=i??{ok:!1,mode:e.mode,state:`idle`,dirty:!0},T=o?{...w,state:`failed`,error:o}:i,ee=e.mode===`anonymous`&&(T?.error?.code===`UNAUTHORIZED`||T?.error?.code===`LOGIN_REQUIRED`);return(0,Q.jsx)(`div`,{className:`cloud`,children:(0,Q.jsx)(ih,{mode:e.mode,status:T,link:f&&i?.state===`waiting`?u:null,copied:m,busy:c,onStart:()=>void x(),onPush:e=>void S(e),onRetry:()=>void(ee||_.current===`start`?x():S(!1)),onCopy:()=>void C()})})}var sh=h(),ch=`modulepreload`,lh=function(e,t){return new URL(e,t).href},uh={},dh=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=lh(t,n),t=s(t),t in uh)return;uh[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:ch,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},fh=[`png`,`jpg`,`svg`,`psd`,`html`,`pdf`],ph=`position:fixed;left:-20000px;top:0;width:4000px;height:4000px;border:0;`,mh=e=>[...e.querySelectorAll(`.slide`)].filter(e=>!e.parentElement?.closest(`.slide`)),hh=e=>e.replace(/[\\/:*?"<>|\u0000-\u001f]+/g,` `).trim()||`deck`,gh=(e,t)=>{let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,r.click(),setTimeout(()=>URL.revokeObjectURL(n),3e3)},_h=async(e,t=!1)=>{let n=document.createElement(`iframe`);n.setAttribute(`sandbox`,`allow-same-origin`),n.setAttribute(`aria-hidden`,`true`),n.tabIndex=-1,n.style.cssText=ph;let r=new Promise(e=>{n.onload=()=>e()});n.srcdoc=t?e.replace(/<head>/i,`<head><base href="${location.origin}/pages/"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; base-uri 'self'">`):e,document.body.append(n),await r;let i=n.contentDocument;if(!i)throw n.remove(),Error(`stage unavailable`);return await i.fonts.ready,await Promise.all([...i.images].map(e=>e.decode().catch(()=>void 0))),{frame:n,doc:i}},vh=64e6,yh=async e=>{let t=await fetch(e);if(!t.ok)throw Error(`Export resource unavailable`);let n=await t.blob();return new Promise((e,t)=>{let r=new FileReader;r.onload=()=>e(String(r.result)),r.onerror=()=>t(r.error),r.readAsDataURL(n)})},bh=async(e,t)=>{let n=t?/(?:\.\.\/|\/)(?:assets|fonts|css)\/[^"'()\s<>,]+/g:/\/(?:api\/assets|fonts)\/[^"'()\s<>]+/g,r=[...new Set(e.match(n)??[])],i=await Promise.all(r.map(async e=>[e,await yh(t?new URL(e,location.origin+`/pages/`).href:e)])),a=new Map(i);return e.replace(n,e=>a.get(e)??e)},xh=async(e,t=()=>{},n=!1)=>{let[{toCanvas:r,toSvg:i},{default:a}]=await Promise.all([dh(()=>import(`./es-C_Ha8SM2.js`),[],import.meta.url),dh(()=>import(`./jszip.min-Bf2BQwaC.js`).then(e=>c(e.default,1)),[],import.meta.url)]),{frame:o,doc:s}=await _h(e.html,n);try{let o=mh(s),l=[...new Set(e.pages)].sort((e,t)=>e-t);if(!l.length||l.some(e=>!o[e]))throw Error(`Invalid export pages`);let u=hh(e.name),d=new a,f=e.format===`pdf`?await(await dh(async()=>{let{PDFDocument:e}=await import(`./es-aF1SvUMY.js`);return{PDFDocument:e}},[],import.meta.url)).PDFDocument.create():null,p=e.format===`psd`?await dh(()=>import(`./dist-C40jmU-w.js`).then(e=>c(e.default,1)),[],import.meta.url):null;for(let[a,c]of l.entries()){let m=o[c],h=`${u}-${c+1}.${e.format}`,g=m.offsetWidth,_=m.offsetHeight;if(e.format===`html`){let e=s.documentElement.cloneNode(!0);e.querySelector(`base`)?.remove(),mh(e).forEach((e,t)=>{c!==t&&e.remove()}),d.file(h,await bh(`<!doctype html>${e.outerHTML}`,n))}else{if(!g||!_||g*_*e.scale**2>vh)throw Error(`Export dimensions exceed the browser limit`);let t={pixelRatio:e.scale,skipAutoScale:!0,cacheBust:!1,style:{margin:`0`},width:g,height:_};if(e.format===`svg`){let n=await i(m,t),r=decodeURIComponent(n.slice(n.indexOf(`,`)+1)),a=new DOMParser().parseFromString(r,`image/svg+xml`).documentElement;if(a.localName!==`svg`)throw Error(`Invalid SVG export`);a.setAttribute(`width`,String(g*e.scale)),a.setAttribute(`height`,String(_*e.scale)),a.setAttribute(`viewBox`,`0 0 ${g} ${_}`),d.file(h,new XMLSerializer().serializeToString(a))}else{let n=await r(m,e.format===`jpg`||f?{...t,backgroundColor:`#ffffff`}:t);if(n.width!==g*e.scale||n.height!==_*e.scale)throw Error(`Unexpected export resolution`);if(p){let e=n.getContext(`2d`)?.getImageData(0,0,n.width,n.height);if(!e)throw Error(`Could not read canvas pixels`);d.file(h,p.writePsd({width:n.width,height:n.height,imageData:e,children:[{name:`Artwork`,imageData:e,opacity:1}]}))}else{let t=e.format===`jpg`||f!==null,r=n.toDataURL(t?`image/jpeg`:`image/png`,.95);if(f){let e=await f.embedJpg(r),t=f.addPage([g*.75,_*.75]);t.drawImage(e,{x:0,y:0,width:t.getWidth(),height:t.getHeight()})}else d.file(h,r.slice(r.indexOf(`,`)+1),{base64:!0})}}}t(a+1,l.length,(a+1)/l.length*.9)}f&&d.file(`${u}.pdf`,await f.save()),gh(await d.generateAsync({type:`blob`},({percent:e})=>t(l.length,l.length,.9+e/1e3)),`${u}.zip`)}finally{o.remove()}},Sh=[`svg`,`psd`,`pdf`];function Ch({controller:e,snap:t,customName:n,onNameChange:r,onClose:i,local:a}){let o=af(),s=of(),c=Of(),[l,u]=(0,v.useState)([]),[d,f]=(0,v.useState)(`png`),[p,m]=(0,v.useState)(1),h=n??(t.name||`Popost`),[g,_]=(0,v.useState)(null),y=(0,v.useRef)(null),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(null),[w,T]=(0,v.useState)(null),ee=(0,v.useRef)(null),E=(0,v.useRef)(null);(0,v.useLayoutEffect)(()=>{let e=E.current,t=document.getElementById(`btn-export`);if(!e||!t)return;let n=()=>{let n=window.visualViewport,r=(n?.offsetLeft??0)+12,i=(n?.offsetTop??0)+12,a=Math.max(0,(n?.width??window.innerWidth)-24),o=Math.max(0,(n?.height??window.innerHeight)-24),s=t.getBoundingClientRect();e.style.width=`${Math.min(492,a)}px`,e.style.left=`${Math.max(r,Math.min(s.right-e.offsetWidth,r+a-e.offsetWidth))}px`;let c=Math.max(i,Math.min(s.bottom+6,i+o-Math.min(e.scrollHeight+2,o)));e.style.top=`${c}px`,e.style.maxHeight=`${Math.max(0,i+o-c)}px`};n();let r=new ResizeObserver(n);return r.observe(e),window.addEventListener(`resize`,n),window.addEventListener(`scroll`,n,!0),window.visualViewport?.addEventListener(`resize`,n),window.visualViewport?.addEventListener(`scroll`,n),()=>{r.disconnect(),window.removeEventListener(`resize`,n),window.removeEventListener(`scroll`,n,!0),window.visualViewport?.removeEventListener(`resize`,n),window.visualViewport?.removeEventListener(`scroll`,n)}},[]);let[D,O]=(0,v.useState)(!1),[te,k]=(0,v.useState)({completed:0,total:0,fraction:0}),A=t.pages.filter(e=>!l.includes(e.id)),ne=A[0],re=e.index(),ie=(0,v.useMemo)(()=>t.pages.map(e=>co(re,{frameCSS:_p,baseHref:location.origin+(a?`/pages/`:`/`),imageOrigins:vs(),currentPageId:e.id})),[re,t.pages,a]);(0,v.useEffect)(()=>{if(a){let e=!0;return fetch(`/api/export-options`,{cache:`no-store`}).then(e=>e.json()).then(t=>{e&&x(t.premium===!0)}).catch(()=>{}),()=>{e=!1}}let e=!0;cd(`export-options`).then(t=>{e&&x(t.premium)}).catch(()=>{});let t=e=>{if(!ls(e,`popost-workspace`))return;let t=e.data;t.type===`export-progress`&&t.id===sd()&&k({completed:t.completed,total:t.total,fraction:t.fraction})};return window.addEventListener(`message`,t),()=>{e=!1,window.removeEventListener(`message`,t)}},[a]);let j=(0,v.useCallback)(()=>{C(null),T(null)},[]);Md(S!==null,()=>{S?.anchor.focus(),j()}),(0,v.useLayoutEffect)(()=>{let e=ee.current,t=E.current;if(!S||!e||!t)return;let n=()=>{let n=S.anchor.getBoundingClientRect(),r=t.getBoundingClientRect();if(n.bottom<=r.top||n.top>=r.bottom){j();return}let i=Math.min(270,window.innerWidth-16),a=window.innerHeight-n.bottom-6-8,o=n.top-6-8,s=e.scrollHeight>a&&o>a;Object.assign(e.style,{width:`${i}px`,left:`${Math.max(8,Math.min(n.right-i,window.innerWidth-i-8))}px`,maxHeight:`${Math.max(0,s?o:a)}px`,top:s?`auto`:`${n.bottom+6}px`,bottom:s?`${window.innerHeight-n.top+6}px`:`auto`})};n(),t.addEventListener(`scroll`,n),window.addEventListener(`resize`,n);let r=t=>{t.target instanceof Node&&!e.contains(t.target)&&!S.anchor.contains(t.target)&&j()};return document.addEventListener(`pointerdown`,r,!0),S.focusOptions&&e.querySelector(`[aria-pressed=true]`)?.focus(),()=>{t.removeEventListener(`scroll`,n),window.removeEventListener(`resize`,n),document.removeEventListener(`pointerdown`,r,!0)}},[S,j]);let M=(e,t=!1)=>{let n=g?.trim();e&&n&&r(n),_(null),t&&requestAnimationFrame(()=>y.current?.focus())},ae=async()=>{if(!(!A.length||D)){e.endTextEdit(!0),k({completed:0,total:A.length,fraction:0}),O(!0),j();try{let n={html:Lu(e.index().source),name:g?.trim()||h,pages:t.pages.flatMap((e,t)=>l.includes(e.id)?[]:[t]),format:d,scale:d===`html`?1:p};a?await xh(n,(e,t,n)=>k({completed:e,total:t,fraction:n}),!0):await cd(`export`,n,3e5),c(o(`export.done`),`info`),i()}catch(e){c(e instanceof Error&&e.message?e.message:o(`export.failed`),`error`)}finally{O(!1)}}},oe=(e,t,n)=>{C(r=>r?.kind===e?null:{kind:e,anchor:t,focusOptions:n}),T(null)},N=(e,t)=>t&&(0,Q.jsx)(`button`,{type:`button`,className:`export-gem`,"aria-label":o(`export.paid`),"aria-expanded":w===e,onMouseEnter:()=>T(e),onFocus:()=>T(e),onClick:()=>T(e),children:(0,Q.jsx)($,{name:`gem`,size:15})}),P=(e,t,n)=>{t?T(e):(n(),S?.focusOptions&&S.anchor.focus(),j())},F=e=>w===e&&(0,Q.jsxs)(`div`,{className:`export-upgrade`,children:[(0,Q.jsx)(`span`,{children:o(`export.upgrade`)}),(0,Q.jsx)(`a`,{href:a?`https://popost.ai/${s}/pricing`:`/${s}/pricing`,target:`_blank`,rel:`noopener noreferrer`,children:o(`export.pricing`)})]});return(0,sh.createPortal)((0,Q.jsxs)(`div`,{id:`pop-export`,ref:E,className:`popover export-panel`,role:`dialog`,"aria-label":o(`topbar.export`),children:[(0,Q.jsxs)(`fieldset`,{disabled:D,children:[(0,Q.jsxs)(`section`,{className:`export-section`,children:[(0,Q.jsxs)(`div`,{className:`export-section-head`,children:[(0,Q.jsx)(`strong`,{children:o(`export.pages`,{n:A.length,total:t.pages.length})}),(0,Q.jsxs)(`label`,{children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:l.length===0,onChange:e=>u(e.currentTarget.checked?[]:t.pages.map(e=>e.id))}),o(`export.all`)]})]}),(0,Q.jsx)(`div`,{className:`export-pages`,children:t.pages.map((e,t)=>{let n=Math.min(78/e.width,78/e.height),r=!l.includes(e.id);return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":r,onClick:()=>u(t=>r?[...t,e.id]:t.filter(t=>t!==e.id)),children:[(0,Q.jsxs)(`span`,{className:`export-thumb`,children:[(0,Q.jsx)(`span`,{style:{width:e.width*n,height:e.height*n},children:(0,Q.jsx)(`iframe`,{title:e.name,"aria-hidden":`true`,tabIndex:-1,sandbox:`allow-same-origin`,onLoad:e=>yp(e.currentTarget),srcDoc:ie[t],style:{width:e.width,height:e.height,transform:`scale(${n})`}})}),r&&(0,Q.jsx)(`i`,{children:(0,Q.jsx)($,{name:`check`,size:12})})]}),(0,Q.jsx)(`b`,{children:e.name}),(0,Q.jsxs)(`small`,{children:[e.width,` × `,e.height]})]},e.id)})})]}),(0,Q.jsxs)(`section`,{className:`export-section export-settings`,children:[(0,Q.jsxs)(`div`,{className:`export-row`,children:[(0,Q.jsx)(`span`,{children:o(`export.format`)}),(0,Q.jsxs)(`button`,{className:`btn`,type:`button`,"aria-expanded":S?.kind===`format`,"aria-controls":S?.kind===`format`?`export-options`:void 0,onClick:e=>oe(`format`,e.currentTarget,e.detail===0),children:[d.toUpperCase(),` `,(0,Q.jsx)($,{name:`chevron`,size:12})]})]}),(0,Q.jsxs)(`div`,{className:`export-row`,children:[(0,Q.jsx)(`span`,{children:o(`export.resolution`)}),(0,Q.jsxs)(`button`,{className:`btn`,type:`button`,disabled:d===`html`,"aria-expanded":S?.kind===`scale`,"aria-controls":S?.kind===`scale`?`export-options`:void 0,onClick:e=>oe(`scale`,e.currentTarget,e.detail===0),children:[o(p===1||d===`html`?`export.standard`:`export.high`),` · `,d===`html`?1:p,`× `,(0,Q.jsx)($,{name:`chevron`,size:12})]})]}),(0,Q.jsxs)(`div`,{className:`export-row`,children:[(0,Q.jsx)(`span`,{children:o(`export.name`)}),g===null?(0,Q.jsxs)(`button`,{type:`button`,className:`btn export-name`,ref:y,title:o(`export.editName`),"aria-label":o(`export.editName`),onClick:()=>_(h),children:[(0,Q.jsx)(`span`,{children:h}),(0,Q.jsx)($,{name:`pencil`,size:14})]}):(0,Q.jsxs)(`form`,{className:`export-name-editor`,onSubmit:e=>{e.preventDefault(),M(!0,!0)},onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||M(!0)},onKeyDown:e=>{e.key!==`Escape`||e.nativeEvent.isComposing||(e.stopPropagation(),M(!1,!0))},children:[(0,Q.jsx)(`input`,{autoFocus:!0,maxLength:160,"aria-label":o(`export.name`),value:g,onFocus:e=>e.currentTarget.select(),onChange:e=>_(e.currentTarget.value)}),(0,Q.jsx)(`button`,{type:`submit`,className:`btn`,onPointerDown:e=>e.preventDefault(),title:o(`export.confirmName`),"aria-label":o(`export.confirmName`),children:(0,Q.jsx)($,{name:`check`,size:15})})]})]})]})]}),(0,Q.jsxs)(`button`,{type:`button`,className:`btn export-start`,disabled:D||!A.length,onClick:()=>void ae(),children:[D&&(0,Q.jsx)(`i`,{style:{width:`${Math.round(te.fraction*100)}%`}}),(0,Q.jsx)(`span`,{children:D?o(`export.progress`,{percent:Math.round(te.fraction*100),done:te.completed,total:te.total}):o(`topbar.export`)})]}),S&&(0,sh.createPortal)((0,Q.jsx)(`div`,{id:`export-options`,className:`export-select`,ref:ee,role:`group`,"aria-label":o(S.kind===`format`?`export.format`:`export.resolution`),children:S.kind===`format`?(0,Q.jsx)(Q.Fragment,{children:fh.map((e,t)=>{let n=Sh.includes(e)&&!b;return(0,Q.jsxs)(`div`,{children:[t===0||t===4?(0,Q.jsx)(`small`,{className:`export-category`,children:o(t===0?`export.imageFormats`:`export.documentFormats`)}):null,(0,Q.jsxs)(`div`,{className:`export-option`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`export-option-label`,"aria-pressed":e===d,onClick:()=>P(e,n,()=>f(e)),children:e.toUpperCase()}),N(e,n)]}),F(e)]},e)})}):(0,Q.jsx)(Q.Fragment,{children:[1,2,3,4].map(e=>{let t=e>1&&!b;return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`export-option`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`export-option-label`,"aria-pressed":e===p,onClick:()=>P(e,t,()=>m(e)),children:[o(e===1?`export.standard`:`export.high`),` · `,e,`×`,ne&&(0,Q.jsxs)(`small`,{children:[ne.width*e,` × `,ne.height*e,` px`]})]}),N(e,t)]}),F(e)]},e)})})}),document.body)]}),document.body)}var wh=[[`1:1`,1080,1080],[`3:4`,1080,1440],[`4:3`,1440,1080],[`16:9`,1920,1080],[`9:16`,1080,1920]],Th=[[`TikTok`,1080,1920],[`Instagram`,1080,1080],[`Instagram 4:5`,1080,1350],[`X`,1600,900],[`小红书`,1080,1440]],Eh=({width:e,height:t})=>[e,t].every(e=>Number.isInteger(e)&&e>=16&&e<=12e3);function Dh({value:e,onChange:t,zh:n,smart:r}){let[i,a]=(0,v.useState)(`common`),[o,s]=(0,v.useState)(null),c=o??e,l=e=>{s(null),Eh(e)&&t(e)};return(0,Q.jsxs)(`div`,{className:`pp-size-picker`,children:[(0,Q.jsxs)(`div`,{className:`pp-size-tabs`,role:`tablist`,"aria-label":n?`尺寸类别`:`Size categories`,children:[(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":i===`common`,onClick:()=>a(`common`),children:n?`常规`:`Common`}),(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":i===`social`,onClick:()=>a(`social`),children:n?`社媒`:`Social`})]}),(0,Q.jsxs)(`div`,{className:`pp-size-main`,children:[(0,Q.jsxs)(`form`,{className:`pp-size-inputs`,onSubmit:e=>{e.preventDefault(),l(c)},children:[[`width`,`height`].map(e=>(0,Q.jsxs)(`label`,{children:[e===`width`?`W`:`H`,(0,Q.jsx)(`input`,{"aria-label":e===`width`?n?`宽度`:`Width`:n?`高度`:`Height`,type:`number`,min:`16`,max:`12000`,value:c[e]||``,onChange:t=>s({...c,[e]:Number(t.currentTarget.value)})})]},e)),o&&(0,Q.jsx)(`button`,{type:`submit`,disabled:!Eh(o),children:n?`应用`:`Apply`})]}),i===`common`&&r,(0,Q.jsx)(`div`,{className:`pp-size-presets`,role:`group`,children:(i===`common`?wh:Th).map(([t,r,i])=>(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":r===e.width&&i===e.height,onClick:()=>l({width:r,height:i}),children:[(0,Q.jsx)(`i`,{style:{width:22*Math.min(1,r/i),height:22*Math.min(1,i/r)}}),(0,Q.jsxs)(`span`,{children:[t===`小红书`&&!n?`RedNote`:t,(0,Q.jsxs)(`small`,{children:[r,` × `,i]})]})]},t))})]})]})}function Oh({controller:e,snap:t,onSize:n}){let r=af(),i=of(),[a,o]=(0,v.useState)(null);Md(a!==null,()=>o(null));let s=t.pages.find(e=>e.id===t.currentPageId),c=np(e,t.sourceVersion),l=s&&ld(s.id),u=l?.ownerDocument.defaultView?.getComputedStyle(l).backgroundColor,d=hd(u);return(0,Q.jsxs)(`div`,{className:`tb-group page-design`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`tb-btn`,disabled:!s,"aria-expanded":a===`size`,"aria-label":r(`design.size`),onClick:()=>o(a===`size`?null:`size`),children:[(0,Q.jsx)($,{name:`crop`}),(0,Q.jsx)(`span`,{className:`tb-text`,children:r(`design.size`)}),(0,Q.jsx)(`span`,{className:`tb-caret`,children:(0,Q.jsx)($,{name:`chevron`,size:12})})]}),(0,Q.jsxs)(`button`,{type:`button`,className:`tb-btn`,disabled:!s,"aria-expanded":a===`color`,"aria-label":r(`design.background`),onClick:()=>o(a===`color`?null:`color`),children:[(0,Q.jsx)(`i`,{className:`background-sample`,style:{background:d?void 0:u}}),(0,Q.jsx)(`span`,{className:`tb-text`,children:r(`design.background`)})]}),a&&s&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`menu-scrim`,onMouseDown:()=>o(null)}),(0,Q.jsx)(`div`,{className:`popover page-design-pop ${a}`,children:a===`size`?(0,Q.jsx)(Dh,{value:s,zh:i===`zh`,onChange:e=>{o(null),(e.width!==s.width||e.height!==s.height)&&n({...e,pageId:s.id})}}):(0,Q.jsx)(ep,{expanded:!0,docColors:c,current:d?`transparent`:_d(u),allowNone:!0,onPick:(t,n)=>{e.apply({kind:`setStyle`,id:s.id,props:{"background-color":t}},{label:`page background`,coalesceKey:n===`live`?`page background`:void 0})}})})]})]})}var kh={saved:`save.saved`,dirty:`save.dirty`,saving:`save.saving`,error:`save.error`};function Ah({controller:e,snap:t,onSize:n,comparing:r,onCompare:i,local:a=!1,canCompare:o=!1}){let s=af(),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(null),f=a||!!sd();Md(c,()=>l(!1));let p=t.docState===`ready`,m=(0,v.useCallback)(async()=>{await e.save();let t=e.getSnapshot();return t.docState===`ready`&&t.saveState===`saved`},[e]);return(0,Q.jsxs)(`header`,{className:`topbar`,children:[(0,Q.jsxs)(`div`,{className:`tb-group`,children:[(0,Q.jsx)(`button`,{type:`button`,id:`btn-undo`,className:`tb-btn`,disabled:!t.canUndo,title:s(`topbar.undo`),"aria-label":s(`topbar.undo`),onClick:e.undo,children:(0,Q.jsx)($,{name:`undo`})}),(0,Q.jsx)(`button`,{type:`button`,id:`btn-redo`,className:`tb-btn`,disabled:!t.canRedo,title:s(`topbar.redo`),"aria-label":s(`topbar.redo`),onClick:e.redo,children:(0,Q.jsx)($,{name:`redo`})}),(0,Q.jsx)(`span`,{className:`tb-sep`}),(0,Q.jsxs)(`button`,{type:`button`,id:`btn-reset-layout`,className:`tb-btn`,disabled:!p,title:s(`topbar.resetLayout`),onClick:()=>void e.resetToInitial(),children:[(0,Q.jsx)($,{name:`reset`}),(0,Q.jsx)(`span`,{className:`tb-label`,children:s(`topbar.resetLayout`)})]})]}),(0,Q.jsx)(Oh,{controller:e,snap:t,onSize:n}),o&&(0,Q.jsxs)(`button`,{type:`button`,className:`tb-btn compare-toggle${r?` active`:``}`,disabled:!p,"aria-pressed":r,"aria-label":s(r?`compare.close`:`compare.open`),title:s(r?`compare.closeHint`:`compare.openHint`),onClick:i,children:[(0,Q.jsx)($,{name:`compare`}),(0,Q.jsx)(`span`,{className:`tb-text`,children:s(r?`compare.close`:`compare.open`)})]}),(0,Q.jsx)(`div`,{className:`tb-spacer`}),(0,Q.jsxs)(`span`,{className:`save-state state-${t.saveState}`,role:`status`,children:[(0,Q.jsx)(`i`,{className:`state-dot`}),(0,Q.jsx)(`span`,{className:`save-text`,children:s(kh[t.saveState])})]}),(0,Q.jsxs)(`div`,{className:`tb-menu`,children:[(0,Q.jsxs)(`button`,{type:`button`,id:`btn-export`,className:`tb-btn outlined`,disabled:!p,"aria-haspopup":f?`dialog`:`menu`,"aria-expanded":c,title:s(`topbar.export`),onClick:()=>l(e=>!e),children:[(0,Q.jsx)($,{name:`export`}),(0,Q.jsx)(`span`,{className:`tb-label`,children:s(`topbar.export`)}),(0,Q.jsx)(`span`,{className:`tb-caret`,children:(0,Q.jsx)($,{name:`chevron`,size:12})})]}),c&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`menu-scrim`,onMouseDown:()=>l(!1)}),f?(0,Q.jsx)(Ch,{local:a,controller:e,snap:t,customName:u,onNameChange:d,onClose:()=>l(!1)}):(0,Q.jsxs)(`div`,{id:`pop-export`,className:`popover`,role:`menu`,children:[(0,Q.jsx)(`button`,{type:`button`,role:`menuitem`,className:`menu-item`,onClick:()=>{l(!1),e.downloadAll()},children:s(`topbar.downloadImages`)}),(0,Q.jsx)(`button`,{type:`button`,role:`menuitem`,className:`menu-item`,onClick:()=>{l(!1),e.exportHTML()},children:s(`topbar.exportHtml`)})]})]})]}),e.cloud&&p&&(0,Q.jsx)(oh,{cloud:e.cloud,saveState:t.saveState,saveLocal:m}),(0,Q.jsxs)(`button`,{type:`button`,id:`btn-save`,className:`btn-save`,disabled:!p||t.saveState===`saving`,title:s(`topbar.saveTitle`),onClick:()=>void e.save(),children:[t.saveState!==`saved`&&(0,Q.jsx)(`i`,{className:`save-dot`}),s(`topbar.save`)]})]})}function jh(e,t=!1){let[n,r]=(0,v.useState)(`fit`),[i,a]=(0,v.useState)({width:0,height:0}),o=(0,v.useRef)(null),s=(0,v.useCallback)(e=>{if(o.current?.disconnect(),o.current=null,!e)return;let t=()=>a(t=>t.width===e.clientWidth&&t.height===e.clientHeight?t:{width:e.clientWidth,height:e.clientHeight});t(),typeof ResizeObserver==`function`&&(o.current=new ResizeObserver(t),o.current.observe(e))},[]);(0,v.useEffect)(()=>()=>o.current?.disconnect(),[]);let c=t?{width:(i.width-64-28)/2+64,height:i.height-40}:i,l=n===`fit`?Xm(c,e):n,u=(0,v.useRef)(l),d=(0,v.useRef)(null),f=(0,v.useRef)(null);u.current=l;let p=(0,v.useCallback)(()=>{f.current!==null&&cancelAnimationFrame(f.current),f.current=null,d.current=null},[]);(0,v.useEffect)(()=>p,[p]);let m=(0,v.useCallback)(e=>{if(d.current=e,f.current!==null)return;if(window.matchMedia(`(prefers-reduced-motion: reduce)`).matches){u.current=e,d.current=null,r(e);return}let t=()=>{let e=d.current;if(e===null)return;let n=e-u.current,i=Math.abs(n)<.12?e:u.current+n*.38;u.current=i,r(i),i===e?(f.current=null,d.current=null):f.current=requestAnimationFrame(t)};f.current=requestAnimationFrame(t)},[]),h=(0,v.useCallback)(e=>{p(),r(Ym(e))},[p]),g=(0,v.useCallback)(()=>{p(),r(`fit`)},[p]),_=(0,v.useCallback)(e=>{m(Zm(d.current??u.current,e))},[m]),y=(0,v.useCallback)(e=>{m(Qm(d.current??u.current,e))},[m]),b=(0,v.useCallback)(()=>u.current,[]);return{percent:l,fitting:n===`fit`,stageRef:s,set:h,fit:g,step:_,wheel:y,get:b}}function Mh({controller:e,lang:t,baseHref:n}){return(0,Q.jsx)(rf,{lang:t,children:(0,Q.jsx)(Af,{children:(0,Q.jsx)(Ih,{controller:e,baseHref:n})})})}var Nh=900,Ph=120;function Fh(e){e.target.closest(`button, [data-keepfocus]`)&&e.preventDefault()}function Ih({controller:e,baseHref:t}){let n=af(),r=Of(),i=sp(e),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(null),d=(0,v.useMemo)(()=>({id:l,setId:u}),[l]),f=(0,v.useCallback)(()=>u(null),[]);Ff(e),(0,v.useEffect)(()=>e.onFrameEvent(t=>{t.type===`pointer`&&t.action===`dblclick`&&t.id!==null&&Pf(e,t.id)&&u(t.id)}),[e]);let p=e.pageSize(),m=xs(),h=m?.comparison===!0,[g,_]=(0,v.useState)(()=>h||new URLSearchParams(window.location.search).get(`compare`)===`1`),y=Lm(!!m),b=g,x=jh(p,b),S=()=>{_(e=>!e),x.fit()},C=(0,v.useRef)(x);C.current=x;let w=(0,v.useRef)(new Set),T=(0,v.useRef)(kp),ee=(0,v.useCallback)(e=>(w.current.add(e),e(T.current),()=>{w.current.delete(e)}),[]),E=(0,v.useMemo)(()=>new Mp({controller:e,getZoom:()=>C.current.get()/100,onView:e=>{T.current=e,w.current.forEach(t=>t(e))}}),[e]);(0,v.useEffect)(()=>E.attach(),[E]);let D=(0,v.useMemo)(()=>Xd({controller:e,gestures:E,toast:r,t:n,zoom:{step:e=>C.current.step(e),fit:()=>C.current.fit()}}),[e,E,r,n]);(0,v.useEffect)(()=>{let t=null,i=()=>{if(t===null||e.getSnapshot().docState!==`ready`)return;let i=t;t=null,e.endTextEdit(!0);let a=e.replaceSource(i);r(n(a===null?`history.draftRestored`:`history.draftFailed`),a===null?`info`:`error`)},a=e=>{!ls(e,`popost-workspace`)||e.data.id!==sd()||e.data.type!==`restore-draft`||typeof e.data.html!=`string`||(t=e.data.html,i())};window.addEventListener(`message`,a);let o=e.subscribe(i);return()=>{o(),window.removeEventListener(`message`,a)}},[e,n,r]),(0,v.useEffect)(()=>e.onNotice(e=>{e.key!==`textOverflow`&&r(cf(n,e),e.kind===`error`?`error`:`info`)}),[e,r,n]),(0,v.useEffect)(()=>{let t=(t,n)=>{let r=e.getSnapshot();if(r.docState!==`ready`||r.conflict)return!1;let i=Pp(t,{selectionCount:r.selection.length,editing:r.editingTextId!==null});return!i||n&&i.type!==`save`&&!(i.type===`escape`&&jd())?!1:D.run(i)},n=e=>{if(e.isComposing||e.keyCode===229)return;let n=e.target;if(!e.ctrlKey&&!e.metaKey&&n?.closest(`.rail, #panel`)&&n.tagName===`BUTTON`&&e.key!==`Escape`)return;let r={key:e.key,ctrl:e.ctrlKey,meta:e.metaKey,shift:e.shiftKey,alt:e.altKey};t(r,Ip(e.target))&&e.preventDefault()};window.addEventListener(`keydown`,n);let r=e.onFrameEvent(e=>{e.type===`key`&&t({key:e.key,ctrl:e.ctrl,meta:e.meta,shift:e.shift,alt:e.alt},!1)});return()=>{window.removeEventListener(`keydown`,n),r()}},[e,D]),(0,v.useEffect)(()=>{if(window.innerWidth<Nh)return;let e=setTimeout(()=>o(e=>e??`layers`),Ph);return()=>clearTimeout(e)},[]);let O=i.docState===`loading`,te=i.docState===`error`;return(0,Q.jsxs)(`div`,{className:`app`,onMouseDownCapture:Fh,children:[(0,Q.jsx)(Ah,{local:!!m,canCompare:!!m||!!sd(),controller:e,snap:i,onSize:c,comparing:g,onCompare:S}),(0,Q.jsx)(`div`,{id:`format-toolbar`,className:`format-slot`,role:`toolbar`,"aria-label":n(`toolbar.label`),children:(0,Q.jsx)(pp,{controller:e,actions:D,onOpenBlock:()=>o(`block`),crop:d})}),(0,Q.jsxs)(`div`,{className:`workspace`,children:[(0,Q.jsx)(Pm,{open:a,onAddPage:()=>Dd(e),onToggle:e=>o(t=>t===e?null:e)}),(0,Q.jsx)(Fm,{open:a,controller:e,onClose:()=>o(null)}),(0,Q.jsxs)(`div`,{className:`main`,children:[(0,Q.jsx)($m,{comparing:b,references:y,controller:e,snap:i,zoom:x,gestures:E,subscribeView:ee,actions:D,cropId:l,onExitCrop:f,resize:s?.pageId===i.currentPageId?s:null,onEndResize:()=>c(null)}),(0,Q.jsx)(eh,{snap:i,zoom:x,actions:D}),(0,Q.jsx)(xp,{controller:e,snap:i,baseHref:t,toast:r})]}),O&&(0,Q.jsxs)(`div`,{className:`state-overlay`,role:`status`,children:[(0,Q.jsx)(`span`,{className:`spinner`}),n(`status.loading`)]}),te&&(0,Q.jsxs)(`div`,{className:`state-overlay state-error`,role:`alert`,children:[(0,Q.jsx)(`strong`,{children:n(`status.errorTitle`)}),(0,Q.jsx)(`p`,{children:lf(n,i.error)}),(0,Q.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>void e.reload(),children:n(`status.retry`)})]})]}),i.conflict&&(0,Q.jsx)(Lp,{controller:e})]})}var{controller:Lh,lang:Rh,baseHref:zh}=od();(0,y.createRoot)(document.getElementById(`root`)).render((0,Q.jsx)(v.StrictMode,{children:(0,Q.jsx)(Mh,{controller:Lh,lang:Rh,baseHref:zh})}));export{l as n,c as r,o as t};