efficient-office 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Documents-4L3242LJ.js +1 -0
- package/dist/chunk-7B4B25DB.js +1 -0
- package/dist/{chunk-HNNYUGDU.js → chunk-JI56OCIU.js} +1 -1
- package/dist/{chunk-O35VT6BD.js → chunk-LGY776XE.js} +1 -1
- package/dist/{chunk-EC6D54MM.js → chunk-SDLOT5Z5.js} +1 -1
- package/dist/chunk-VMUUFEWS.js +1 -0
- package/dist/documents/documents.css +43 -1
- package/dist/documents/index.d.ts +154 -2
- package/dist/documents/index.js +1 -1
- package/dist/{docxPdf-S4RXU4L2.js → docxPdf-LO2VPZSJ.js} +1 -1
- package/dist/importDocument-C5L275FU.js +1 -0
- package/package.json +1 -1
- package/dist/Documents-2ZU5D3ZI.js +0 -1
- package/dist/chunk-POH6OTTR.js +0 -1
- package/dist/chunk-YKQ5UKYZ.js +0 -1
- package/dist/importDocument-34WALCTG.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{countWords as e,documentText as t,findInNodes as n,pageBlocks as r,pageDocument as o,pageStarts as a,pageStyles as i,replaceSpots as l,sanitizeHtml as s}from"./chunk-SDLOT5Z5.js";import{DocumentsConflict as c,useDocumentsHost as d,useDocumentsWords as u}from"./chunk-JI56OCIU.js";import"./chunk-VMUUFEWS.js";import{FileList as m}from"./chunk-PMGQ5GUH.js";import"./chunk-B32ASXHM.js";import{importDocumentFile as f}from"./chunk-LGY776XE.js";import{fingerprintOf as p,headerKindFor as h,marginTextOfHtml as g,readDocx as w,readParts as b,stampFingerprints as y,tocEntryHtml as v}from"./chunk-7B4B25DB.js";import{BUILTIN_STYLES as x,CHECK_BULLETS as k,HIGHLIGHTS as C,MARGIN_PRESETS as S,PAPER_SIZES as N,REL as A,WEB_FONTS as $,WORD_NS as L,addContentDefault as T,addContentOverride as P,addRel as M,blankDocxParts as E,child as R,escapeXml as z,marginsOf as F,paperOf as O,paraCss as I,parseParaProps as D,parseRunProps as H,parseTabsAttr as j,parseXml as B,partText as U,readRels as W,resolveTarget as q,runCss as K,setPartText as V,tabCss as _,tabsAttr as G,webFontSheetUrl as X,withMargins as J,withPaper as Z,writeZip as Q}from"./chunk-D3JKD7KW.js";import{hasExtension as Y,placeCopy as ee}from"./chunk-XYVQTQ6N.js";import{useEffect as te,useRef as ne,useState as re}from"react";import{WindowTitle as oe,useWindowDirty as ae}from"efficient-shell";import{Button as ie,EmptyState as le,Input as se,LoadingSpinner as ce,confirmDestructive as de,toast as ue}from"efficient-shell/ui";import{useCallback as me,useEffect as fe,useId as pe,useMemo as he,useRef as ge,useState as we}from"react";import{saveIndicator as be,useAutosave as ye}from"efficient-easel/autosave";import{useEaselStrings as ve}from"efficient-easel/strings";import{Icon as xe}from"efficient-shell/icons";import{Button as ke,ColorPickerPanel as Ce,ContextMenu as Se,DropdownMenu as Ne,IconButton as Ae,Popover as $e,PopupMenu as Le,PopupMenuDivider as Te,PopupMenuItem as Pe,PopupMenuLabel as Me,prompt as Ee,registerModalEscapeInterceptor as Re,toast as ze,useShellLocale as Fe}from"efficient-shell/ui";import{SettingsColour as Oe}from"efficient-easel/panel";import{useEaselStrings as Ie}from"efficient-easel/strings";import{Button as De,Select as He}from"efficient-shell/ui";import{jsx as je,jsxs as Be}from"react/jsx-runtime";function Ue({page:e,onPage:t,onMorePageSetup:n,colour:r,onColour:o,outline:a,onHeading:i}){const l=u(),s=Ie(),c=O(e),d=F(e),m={a4:"A4",a3:"A3",a5:"A5",letter:l.paperLetter,legal:l.paperLegal},f={normal:l.marginsNormal,narrow:l.marginsNarrow,moderate:l.marginsModerate,wide:l.marginsWide},p={value:"custom",label:l.custom};return Be("aside",{className:"docs-panel",children:[je("h3",{children:l.documentPanel}),Be("div",{className:"docs-panel-section",children:[je("p",{className:"docs-panel-label",children:l.pagePanel}),je(He,{"aria-label":l.paperSize,value:c??"custom",onChange:n=>{"custom"!==n&&t(Z(e,n))},options:[...c?[]:[p],...Object.keys(N).map(e=>({value:e,label:m[e]}))]}),je(He,{"aria-label":l.margins,value:d??"custom",onChange:n=>{"custom"!==n&&t(J(e,n))},options:[...d?[]:[p],...Object.keys(S).map(e=>({value:e,label:f[e]}))]}),je(De,{variant:"secondary",block:!0,onClick:n,children:l.morePageSetup})]}),je("div",{className:"docs-panel-section",children:je(Oe,{label:l.textColor,value:r,onChange:o,words:s.colourRow})}),Be("div",{className:"docs-panel-section",children:[je("p",{className:"docs-panel-label",children:l.outline}),0===a.length?je("p",{className:"docs-panel-empty",children:l.outlineEmpty}):je("ul",{className:"docs-outline",children:a.map((e,t)=>je("li",{style:{paddingLeft:10*(e.level-1)+"px"},children:je("button",{type:"button",onClick:()=>i(t),children:e.text})},t))})]})]})}import{EaselIconButton as We,EaselTopBar as qe,SaveState as Ke,TopBarCluster as Ve,TopBarDivider as _e}from"efficient-easel/chrome";import"efficient-easel/shell.css";import"efficient-easel/chrome.css";import"efficient-easel/panel.css";import"efficient-easel/fields.css";import{Icon as Ge}from"efficient-shell/icons";import{DropdownMenu as Xe}from"efficient-shell/ui";import{jsx as Je,jsxs as Ze}from"react/jsx-runtime";function Qe({onClose:e,fileMenu:t,name:n,saveState:r,canUndo:o,canRedo:a,onUndo:i,onRedo:l,exportControl:s,extra:c}){const d=u();return Ze(qe,{children:[Ze(Ve,{children:[e&&Je(We,{label:d.backToFiles,onClick:e,children:Je(Ge,{name:"chevron-left",size:16})}),t.length>0&&Je(Xe,{trigger:d.menuFile,items:t,align:"start",triggerClassName:"docs-menu-trigger"}),n,Je(Ke,{...r}),Je(_e,{}),Ze("span",{className:"docs-history",onMouseDown:e=>e.preventDefault(),children:[Je(We,{label:d.undo,disabled:!o,onClick:i,children:Je(Ge,{name:"undo",size:16})}),Je(We,{label:d.redo,disabled:!a,onClick:l,children:Je(Ge,{name:"redo",size:16})})]})]}),Ze(Ve,{kind:"right",children:[c,s]})]})}var Ye=/^[0-7][0-9A-F]{7}$/;function et(){return(Math.floor(2147483647*Math.random())+1).toString(16).toUpperCase().padStart(8,"0")}function tt(e){const t=new Set;let n=!1;for(const r of Array.from(e.querySelectorAll("p,h1,h2,h3,h4,h5,h6,li"))){if(r.closest("[data-toc]"))continue;const e=r.getAttribute("data-pid");if(e&&Ye.test(e)&&!t.has(e)){t.add(e);continue}let o=et();for(;t.has(o);)o=et();r.setAttribute("data-pid",o),t.add(o),n=!0}return n}function nt(e){const t=e.getAttribute("data-pid");if(t)return t;const n=e.querySelector("[data-pid]");return n?`${e.tagName}:${n.getAttribute("data-pid")}`:null}var rt=["data-docx","data-r","data-raw","data-num-id","data-new"];function ot(e){const t=e.cloneNode(!0);for(const e of[t,...Array.from(t.querySelectorAll("*"))]){for(const t of rt)e.removeAttribute(t);"IMG"===e.tagName&&e.removeAttribute("src")}return t.outerHTML}function at(e){const t=[],n=new Map;for(const r of Array.from(e.children)){const e=nt(r);e&&!n.has(e)&&(t.push(e),n.set(e,ot(r)))}return{order:t,blocks:n}}function it(e,t,n,r){const o=new Map;for(const t of Array.from(e.children)){const e=nt(t);e&&!o.has(e)&&o.set(e,t)}const a=new Map;for(const e of Array.from(t.children)){const t=nt(e);t&&!a.has(t)&&a.set(t,e)}const i=[];let l=!1;const s=[],c=new Set,d=Array.from(o.keys()),u=new Map;d.forEach((e,t)=>{if(a.has(e))return;let r=t>0?d[t-1]:null;const o=n.order.indexOf(e);if(o>=0){r=null;for(let e=o-1;e>=0;e--)if(a.has(n.order[e])){r=n.order[e];break}}u.set(r,[...u.get(r)??[],e])});const m=e=>{if(c.has(e))return;c.add(e);const t=(e=>{const t=o.get(e),s=a.get(e),c=n.blocks.get(e),d=t?void 0===c||ot(t)!==c:void 0!==c,u=s?void 0===c||ot(s)!==c:void 0!==c;return t&&s?u?(d&&ot(t)!==ot(s)&&i.push({key:e,mine:t.outerHTML}),r(s)):(d&&(l=!0),t):t&&!s?void 0===c||d?(l=!0,t):null:!t&&s?void 0===c||u?r(s):(l=!0,null):null})(e);t&&s.push(t);for(const t of u.get(e)??[])m(t)};for(const e of u.get(null)??[])m(e);for(const e of a.keys())m(e);return e.replaceChildren(...s),s.length||(e.innerHTML="<p><br></p>"),{overwritten:i,ahead:l}}function lt(e,t,n){const r=1===t.nodeType?t:t.parentElement,o=r?.closest("[data-pid]");if(!o||!e.contains(o))return null;const a=document.createRange();a.setStart(o,0);try{a.setEnd(t,n)}catch{return null}return{block:o.getAttribute("data-pid"),offset:a.toString().length}}function st(e,t){const n=e.querySelector(`[data-pid="${t.block.replace(/[^0-9A-F]/g,"")}"]`);if(!n)return null;const r=document.createTreeWalker(n,NodeFilter.SHOW_TEXT);let o=t.offset,a=null;for(let e=r.nextNode();e;e=r.nextNode())if(e.parentElement?.closest("[data-pid]")===n){if(o<=e.length)return{node:e,offset:o};o-=e.length,a=e}return a?{node:a,offset:a.length}:{node:n,offset:0}}var ct=["#1d9e75","#d85a30","#378add","#d4537e","#ba7517","#639922","#7f77dd","#993c1d"];function dt(e){let t=0;for(const n of e)t=31*t+n.charCodeAt(0)>>>0;return ct[t%ct.length]}import{useRef as ut,useState as mt}from"react";import{Icon as ft}from"efficient-shell/icons";import{Button as pt,Checkbox as ht,IconButton as gt,Textarea as wt,toast as bt}from"efficient-shell/ui";import{jsx as yt,jsxs as vt}from"react/jsx-runtime";var xt=e=>e.split(/\s+/).filter(Boolean).slice(0,2).map(e=>e[0].toUpperCase()).join("")||"?",kt=e=>e?new Date(e).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"}):"";function Ct({label:e,placeholder:t,people:n,onPost:r,assignable:o,autoFocus:a}){const i=u(),[l,s]=mt(""),[c,d]=mt([]),[m,f]=mt(!1),p=ut(new Map),h=ut(null),g=/@([\p{L}\p{N} .'-]{0,30})$/u,w=()=>[...p.current].filter(([,e])=>l.includes(`@${e}`)),b=()=>{const e=l.trim();if(!e)return;const t=w().map(([e])=>e);r(e,t,m&&t.length?t[0]:null).then(()=>{s(""),f(!1),p.current.clear()},()=>bt.error(i.commentFailed))},y=w()[0];return vt("div",{className:"docs-composer",children:[yt(wt,{ref:h,rows:2,"aria-label":e,placeholder:t,autoFocus:a,value:l,onChange:e=>{s(e.target.value),(e=>{const t=e.match(g)?.[1];if(void 0===t||!n)return d([]);n(t.trim()).then(e=>d(e.slice(0,6)),()=>d([]))})(e.target.value)},onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&b()}}),c.length>0&&yt("ul",{className:"docs-mentions",role:"listbox","aria-label":e,children:c.map(e=>yt("li",{role:"option","aria-selected":!1,onMouseDown:t=>{var n;t.preventDefault(),n=e,p.current.set(n.id,n.name),s(e=>e.replace(g,`@${n.name} `)),d([]),h.current?.focus()},children:e.name},e.id))}),o&&y&&yt(ht,{checked:m,onChange:f,label:i.assignTo(y[1])}),yt("div",{className:"docs-composer-actions",children:yt(pt,{size:"sm",disabled:!l.trim(),onClick:b,children:e})})]})}function St({comment:e,mine:t,onSave:n,onDelete:r}){const o=u(),[a,i]=mt(!1),[l,s]=mt(e.body);return vt("div",{className:"docs-comment",children:[vt("div",{className:"docs-comment-head",children:[yt("span",{className:"docs-avatar","aria-hidden":"true",children:xt(e.author_name)}),yt("span",{className:"docs-comment-author",children:e.author_name}),yt("time",{className:"docs-comment-time",dateTime:e.created_at,children:kt(e.created_at)}),t&&!a&&yt(gt,{size:"sm",variant:"ghost","aria-label":o.editComment,title:o.editComment,onClick:()=>i(!0),children:yt(ft,{name:"edit",size:14})}),r&&!a&&yt(gt,{size:"sm",variant:"ghost","aria-label":o.deleteComment,title:o.deleteComment,onClick:r,children:yt(ft,{name:"trash",size:14})})]}),a?vt("div",{className:"docs-composer",children:[yt(wt,{rows:2,"aria-label":o.editComment,value:l,onChange:e=>s(e.target.value)}),vt("div",{className:"docs-composer-actions",children:[yt(pt,{size:"sm",variant:"ghost",onClick:()=>{i(!1),s(e.body)},children:o.cancel}),yt(pt,{size:"sm",disabled:!l.trim(),onClick:()=>{n(l.trim()),i(!1)},children:o.save})]})]}):yt("p",{className:"docs-comment-body",children:e.body})]})}function Nt(e){const t=u(),{comments:n,blockOrder:r,suggestions:o,me:a,canComment:i,canEdit:l,people:s,draft:c,activeId:d}=e,[m,f]=mt(!1),p=n.filter(e=>!e.parent),h=e=>{const t=r.indexOf(e.block_id);return t<0?Number.MAX_SAFE_INTEGER:t},g=p.filter(e=>!e.resolved_at).sort((e,t)=>h(e)-h(t)||e.created_at.localeCompare(t.created_at)),w=p.filter(e=>e.resolved_at),b=e=>"insert"===e.kind?t.suggestionInsert(e.added):"delete"===e.kind?t.suggestionDelete(e.removed):t.suggestionReplace(e.removed,e.added),y=r=>{return vt("article",{className:`docs-thread${r.id===d?" docs-thread-active":""}${r.resolved_at?" docs-thread-resolved":""}`,onClick:()=>e.onFocus(r),children:[r.quote&&yt("blockquote",{className:"docs-thread-quote",children:r.quote}),yt(St,{comment:r,mine:!!a&&r.author===a.id,onSave:t=>e.onEdit(r.id,t),onDelete:a&&r.author===a.id?()=>e.onDelete(r.id):void 0}),r.assignee_name&&vt("p",{className:"docs-thread-assignee",children:[yt(ft,{name:"account",size:12})," ",t.assignedTo(r.assignee_name)]}),(o=r.id,n.filter(e=>e.parent===o)).map(t=>yt(St,{comment:t,mine:!!a&&t.author===a.id,onSave:n=>e.onEdit(t.id,n),onDelete:a&&t.author===a.id?()=>e.onDelete(t.id):void 0},t.id)),yt("div",{className:"docs-thread-actions",onClick:e=>e.stopPropagation(),children:(l||a&&r.author===a.id)&&yt(pt,{size:"sm",variant:"ghost",onClick:()=>e.onResolve(r.id,!r.resolved_at),children:r.resolved_at?t.reopen:t.resolve})}),i&&!r.resolved_at&&r.id===d&&yt("div",{onClick:e=>e.stopPropagation(),children:yt(Ct,{label:t.reply,placeholder:t.commentPlaceholder,people:s,onPost:(t,n)=>e.onReply(r.id,t,n)})})]},r.id);var o};return vt("aside",{className:"docs-panel docs-comments","aria-label":t.comments,children:[yt("h3",{children:t.comments}),c&&vt("section",{className:"docs-thread docs-thread-active",children:[yt("blockquote",{className:"docs-thread-quote",children:c.quote}),yt(Ct,{label:t.comment,placeholder:t.commentPlaceholder,people:s,assignable:!0,autoFocus:!0,onPost:e.onAdd}),yt("div",{className:"docs-composer-actions",children:yt(pt,{size:"sm",variant:"ghost",onClick:e.onCancelDraft,children:t.cancel})})]}),o.length>0&&vt("section",{className:"docs-panel-section",children:[yt("p",{className:"docs-panel-label",children:t.suggestions}),o.map((n,r)=>vt("article",{className:"docs-thread docs-suggestion",onClick:()=>e.onShowSuggestion(n),children:[vt("div",{className:"docs-comment-head",children:[yt("span",{className:"docs-avatar","aria-hidden":"true",children:xt(n.author)}),yt("span",{className:"docs-comment-author",children:n.author||t.untitled}),yt("time",{className:"docs-comment-time",dateTime:n.date,children:kt(n.date)})]}),yt("p",{className:"docs-comment-body",children:b(n)}),l&&vt("div",{className:"docs-thread-actions",onClick:e=>e.stopPropagation(),children:[vt(pt,{size:"sm",variant:"secondary",onClick:()=>e.onSuggestion(n,!0),children:[yt(ft,{name:"check",size:14}),t.accept]}),vt(pt,{size:"sm",variant:"ghost",onClick:()=>e.onSuggestion(n,!1),children:[yt(ft,{name:"close",size:14}),t.reject]})]})]},`${n.els[0].getAttribute("data-tid")??r}-${r}`))]}),!c&&0===g.length&&0===o.length&&yt("p",{className:"docs-panel-empty docs-comments-empty",children:i?t.noComments:t.noCommentsView}),g.map(y),w.length>0&&vt("div",{className:"docs-panel-section",children:[yt(pt,{size:"sm",variant:"ghost",onClick:()=>f(e=>!e),children:t.resolvedCount(w.length)}),m&&w.map(y)]})]})}import{useCallback as At,useEffect as $t,useState as Lt}from"react";import{Button as Tt,confirm as Pt,prompt as Mt,toast as Et}from"efficient-shell/ui";import{jsx as Rt,jsxs as zt}from"react/jsx-runtime";var Ft=e=>new Date(e).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"});function Ot({documentId:e,versions:t,canEdit:n,previewing:r,onPreview:o,onRestore:a,refreshKey:i}){const l=u(),[s,c]=Lt(null),d=At(()=>{t.list(e).then(c,()=>{c([]),Et.error(l.versionsFailed)})},[e,l.versionsFailed,t]);$t(()=>{d()},[d,i]);return zt("aside",{className:"docs-panel docs-history-panel","aria-label":l.versionHistory,children:[Rt("h3",{children:l.versionHistory}),n&&Rt("div",{className:"docs-panel-section",children:Rt(Tt,{variant:"secondary",block:!0,onClick:()=>{(async()=>{const n=await Mt({title:l.nameVersion,message:l.versionName,confirmLabel:l.ok,cancelLabel:l.cancel});if(n?.trim())try{await t.snapshot(e,n.trim()),d()}catch{Et.error(l.versionsFailed)}})()},children:l.nameCurrentVersion})}),null===s?Rt("p",{className:"docs-panel-empty docs-comments-empty",children:l.loading}):0===s.length?Rt("p",{className:"docs-panel-empty docs-comments-empty",children:l.noVersions}):Rt("ul",{className:"docs-versions",children:s.map((i,c)=>zt("li",{className:i.id===r?"docs-version-on":"",children:[zt("button",{type:"button",className:"docs-version",onClick:()=>o(i.id===r?null:i,s[c+1]??null),children:[zt("span",{className:"docs-version-title",children:[i.name||Ft(i.created_at),0===c?` · ${l.currentVersion}`:""]}),i.name&&Rt("span",{className:"docs-version-when",children:Ft(i.created_at)}),Rt("span",{className:"docs-version-who",children:i.editor_names.join(", ")})]}),i.id===r&&n&&zt("div",{className:"docs-thread-actions",children:[Rt(Tt,{size:"sm",variant:"ghost",onClick:()=>{(async n=>{const r=await Mt({title:l.nameVersion,message:l.versionName,defaultValue:n.name,confirmLabel:l.ok,cancelLabel:l.cancel,allowEmpty:!0});if(null!==r)try{await t.rename(e,n.id,r.trim()),d()}catch{Et.error(l.versionsFailed)}})(i)},children:i.name?l.renameVersion:l.nameVersion}),c>0&&Rt(Tt,{size:"sm",variant:"secondary",onClick:()=>{(async e=>{if(await Pt({title:l.restoreVersion,message:l.restoreConfirm(e.name||Ft(e.created_at)),confirmLabel:l.restoreVersion,cancelLabel:l.cancel}))try{await a(e),d()}catch{Et.error(l.restoreFailed)}})(i)},children:l.restoreVersion})]})]},i.id))})]})}var It=(e,t)=>!!e&&e.getAttribute("data-author")===t.name;function Dt(e,t,n){let r=e;for(;r&&r!==t;){if(1===r.nodeType&&r.tagName===n)return r;r=r.parentNode}return null}function Ht(e,t){const n=document.createElement(e);return n.setAttribute("data-author",t.name),n.setAttribute("data-date",t.date()),n}function jt(e,t,n){const r=function(e){const t=[],n=e.commonAncestorContainer;if(3===n.nodeType)return t.push({node:n,start:e.startOffset,end:e.endOffset}),t;const r=document.createTreeWalker(n,NodeFilter.SHOW_TEXT);for(let n=r.nextNode();n;n=r.nextNode()){if(!e.intersectsNode(n))continue;const r=n===e.startContainer?e.startOffset:0,o=n===e.endContainer?e.endOffset:n.length;o>r&&t.push({node:n,start:r,end:o})}return t}(t);let o=null;for(const{node:t,start:a,end:i}of r){if(t.parentElement?.closest('[contenteditable="false"]'))continue;if(Dt(t,e,"DEL")){o??={node:t,offset:a};continue}const r=Dt(t,e,"INS");if(r&&It(r,n)){if(t.deleteData(a,i-a),o??={node:t,offset:a},!r.textContent){const e=r.parentNode,t=Array.prototype.indexOf.call(e.childNodes,r);r.remove(),o={node:e,offset:t}}continue}let l=t;a>0&&(l=l.splitText(a)),i-a<l.length&&l.splitText(i-a);const s=l.previousSibling;if(s&&1===s.nodeType&&"DEL"===s.tagName&&It(s,n))s.appendChild(l);else{const e=Ht("del",n);l.replaceWith(e),e.appendChild(l)}o??={node:l,offset:0}}return o}function Bt(e,t){"INS"===e.tagName===t?e.replaceWith(...Array.from(e.childNodes)):e.remove()}var Ut=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),Wt=e=>e.match(/\s+|[^\s]+/g)??[];function qt(e,t){const n=Wt(e),r=Wt(t),o=function(e,t){const n=e.length,r=t.length;if(n*r>4e5)return[];const o=Array.from({length:n+1},()=>new Uint32Array(r+1));for(let a=n-1;a>=0;a--)for(let n=r-1;n>=0;n--)o[a][n]=e[a]===t[n]?o[a+1][n+1]+1:Math.max(o[a+1][n],o[a][n+1]);const a=[];let i=0,l=0;for(;i<n&&l<r;)e[i]===t[l]?(a.push([i,l]),i++,l++):o[i+1][l]>=o[i][l+1]?i++:l++;return a}(n,r);let a=0,i=0,l="";const s=(e,t)=>{const o=n.slice(a,e).join(""),s=r.slice(i,t).join("");o.trim()?l+=`<span class="docs-diff-del">${Ut(o)}</span>`:l+=Ut(o),s.trim()?l+=`<span class="docs-diff-ins">${Ut(s)}</span>`:o||(l+=Ut(s))};for(const[e,t]of o)s(e,t),l+=Ut(n[e]),a=e+1,i=t+1;return s(n.length,r.length),l}function Kt(e,t){const n=document.createElement("div");if(n.innerHTML=e,null===t)return n.innerHTML;const r=document.createElement("div");r.innerHTML=t;const o=new Map(Array.from(r.querySelectorAll("[data-pid]")).map(e=>[e.getAttribute("data-pid"),e]));for(const e of Array.from(n.querySelectorAll("[data-pid]"))){const t=o.get(e.getAttribute("data-pid")),n=e.textContent??"";if(!t){n.trim()&&e.classList.add("docs-diff-new");continue}const r=t.textContent??"";r===n||e.querySelector("[data-raw],img,table,ins,del")||t.querySelector("ins,del")?r!==n&&e.classList.add("docs-diff-new"):e.innerHTML=qt(r,n)}return n.innerHTML}var Vt=["w:rStyle","w:rFonts","w:b","w:bCs","w:i","w:iCs","w:caps","w:smallCaps","w:strike","w:dstrike","w:outline","w:shadow","w:emboss","w:imprint","w:noProof","w:snapToGrid","w:vanish","w:webHidden","w:color","w:spacing","w:w","w:kern","w:position","w:sz","w:szCs","w:highlight","w:u","w:effect","w:bdr","w:shd","w:fitText","w:vertAlign","w:rtl","w:cs","w:em","w:lang","w:eastAsianLayout","w:specVanish","w:oMath","w:rPrChange"],_t=["w:pStyle","w:keepNext","w:keepLines","w:pageBreakBefore","w:framePr","w:widowControl","w:numPr","w:suppressLineNumbers","w:pBdr","w:shd","w:tabs","w:suppressAutoHyphens","w:kinsoku","w:wordWrap","w:overflowPunct","w:topLinePunct","w:autoSpaceDE","w:autoSpaceDN","w:bidi","w:adjustRightInd","w:snapToGrid","w:spacing","w:ind","w:contextualSpacing","w:mirrorIndents","w:suppressOverlap","w:jc","w:textDirection","w:textAlignment","w:textboxTightWrap","w:outlineLvl","w:divId","w:cnfStyle","w:rPr","w:sectPr","w:pPrChange"],Gt=["w:cnfStyle","w:tcW","w:gridSpan","w:hMerge","w:vMerge","w:tcBorders","w:shd","w:noWrap","w:tcMar","w:textDirection","w:tcFitText","w:vAlign","w:hideMark","w:headers","w:cellIns","w:cellDel","w:cellMerge","w:tcPrChange"],Xt=["w:headerReference","w:footerReference","w:footnotePr","w:endnotePr","w:type","w:pgSz","w:pgMar","w:paperSrc","w:pgBorders","w:lnNumType","w:pgNumType","w:cols","w:formProt","w:vAlign","w:noEndnote","w:titlePg","w:textDirection","w:bidi","w:rtlGutter","w:docGrid","w:printerSettings","w:sectPrChange"];function Jt(e){if(!e)return[];return B(e).children.map(t=>({name:t.name,xml:e.slice(t.start,t.end)}))}function Zt(e,t){const n=e=>{const n=t.indexOf(e);return n<0?t.length:n};return e.map((e,t)=>({p:e,i:t})).sort((e,t)=>n(e.p.name)-n(t.p.name)||e.i-t.i).map(e=>e.p.xml).join("")}function Qt(e){const t=new Map;for(const n of(e.getAttribute("style")??"").split(";")){const e=n.indexOf(":");e>0&&t.set(n.slice(0,e).trim().toLowerCase(),n.slice(e+1).trim())}return t}var Yt={black:"#000000",white:"#ffffff",red:"#ff0000",blue:"#0000ff",green:"#008000",yellow:"#ffff00"};function en(e){if(!e)return;const t=e.trim().toLowerCase();if("transparent"===t||"inherit"===t||"initial"===t||"auto"===t)return;if(Yt[t])return Yt[t];if(/^#[0-9a-f]{6}$/.test(t))return t;if(/^#[0-9a-f]{3}$/.test(t))return`#${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}`;const n=/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:[\s,/]+([\d.]+))?\s*\)$/.exec(t);return!n||void 0!==n[4]&&0===Number(n[4])?void 0:`#${[n[1],n[2],n[3]].map(e=>Math.round(Number(e)).toString(16).padStart(2,"0")).join("")}`}function tn(e){if(!e)return;const t=/^(-?[\d.]+)(pt|px|in|cm|mm|em)?$/.exec(e.trim());if(!t)return;const n=Number(t[1]);switch(t[2]){case"pt":return n;case"px":return.75*n;case"in":return 72*n;case"cm":return 72*n/2.54;case"mm":return 72*n/25.4;default:return"0"===t[1]?0:void 0}}var nn=[10,13,16,18,24,32,48].map(e=>.75*e);var rn=(e,t)=>void 0===e||void 0===t?e===t:Math.abs(e-t)<.02,on=e=>Math.round(20*e);function an(e,t,n){return ln(n?e.runs.get(n):void 0,t,e)}function ln(e,t,n){const r=e?B(e):void 0,o=H(r,n.theme);let a=Jt(e);const i=(e,t)=>{a=a.filter(t=>!e.includes(t.name)),a.push(...t)},l=(e,t)=>void 0===t?[]:[{name:e,xml:t?`<${e}/>`:`<${e} w:val="0"/>`}];if(t.b!==o.b&&i(["w:b","w:bCs"],[...l("w:b",t.b),...l("w:bCs",t.b)]),t.i!==o.i&&i(["w:i","w:iCs"],[...l("w:i",t.i),...l("w:iCs",t.i)]),!!t.u!=!!o.u&&i(["w:u"],t.u?[{name:"w:u",xml:'<w:u w:val="single"/>'}]:o.u?[{name:"w:u",xml:'<w:u w:val="none"/>'}]:[]),t.strike!==o.strike&&!!t.strike!=!!o.strike&&i(["w:strike"],l("w:strike",t.strike)),t.vert!==o.vert&&i(["w:vertAlign"],t.vert?[{name:"w:vertAlign",xml:`<w:vertAlign w:val="${"sub"===t.vert?"subscript":"superscript"}"/>`}]:[]),t.font!==o.font){const e=z(t.font??"");i(["w:rFonts"],t.font?[{name:"w:rFonts",xml:`<w:rFonts w:ascii="${e}" w:hAnsi="${e}" w:eastAsia="${e}" w:cs="${e}"/>`}]:[])}if(t.size!==o.size){const e=t.size?Math.round(2*t.size):0;i(["w:sz","w:szCs"],e?[{name:"w:sz",xml:`<w:sz w:val="${e}"/>`},{name:"w:szCs",xml:`<w:szCs w:val="${e}"/>`}]:[])}if(t.color!==o.color&&i(["w:color"],t.color?[{name:"w:color",xml:`<w:color w:val="${t.color.slice(1).toUpperCase()}"/>`}]:[]),t.hl!==o.hl){const e=t.hl?Object.entries(C).find(([,e])=>e===t.hl)?.[0]:void 0;i(["w:highlight","w:shd"],t.hl?e?[{name:"w:highlight",xml:`<w:highlight w:val="${e}"/>`}]:[{name:"w:shd",xml:`<w:shd w:val="clear" w:color="auto" w:fill="${t.hl.slice(1).toUpperCase()}"/>`}]:[])}const s=Zt(a,Vt);return s?`<w:rPr>${s}</w:rPr>`:""}var sn={FootnoteText:'<w:style w:type="paragraph" w:styleId="FootnoteText"><w:name w:val="footnote text"/><w:basedOn w:val="Normal"/><w:uiPriority w:val="99"/><w:unhideWhenUsed/><w:pPr><w:spacing w:after="0" w:line="240" w:lineRule="auto"/></w:pPr><w:rPr><w:sz w:val="20"/><w:szCs w:val="20"/></w:rPr></w:style>',FootnoteReference:'<w:style w:type="character" w:styleId="FootnoteReference"><w:name w:val="footnote reference"/><w:uiPriority w:val="99"/><w:unhideWhenUsed/><w:rPr><w:vertAlign w:val="superscript"/></w:rPr></w:style>',TOCHeading:'<w:style w:type="paragraph" w:styleId="TOCHeading"><w:name w:val="TOC Heading"/><w:basedOn w:val="Heading1"/><w:next w:val="Normal"/><w:uiPriority w:val="39"/><w:unhideWhenUsed/></w:style>',...Object.fromEntries([1,2,3,4,5,6].map(e=>[`TOC${e}`,`<w:style w:type="paragraph" w:styleId="TOC${e}"><w:name w:val="toc ${e}"/><w:basedOn w:val="Normal"/><w:next w:val="Normal"/><w:uiPriority w:val="39"/><w:unhideWhenUsed/><w:pPr><w:spacing w:after="100"/><w:ind w:left="${220*(e-1)}"/></w:pPr></w:style>`]))};function cn(e){const t=W(e.parts,e.doc.docPath).find(e=>e.type===A.styles);return t?q(e.doc.docPath,t.target):void 0}function dn(e,t){const n=cn(e);if(!n)return;const r=U(e.parts,n);if(!r||new RegExp(`w:styleId="${t}"`).test(r))return;const o=x[t]?.xml??sn[t];o&&V(e.parts,n,r.replace("</w:styles>",`${o}</w:styles>`))}var un=["w:name","w:aliases","w:basedOn","w:next","w:link","w:autoRedefine","w:hidden","w:uiPriority","w:semiHidden","w:unhideWhenUsed","w:qFormat","w:locked","w:personal","w:personalCompose","w:personalReply","w:rsid","w:pPr","w:rPr","w:tblPr","w:trPr","w:tcPr","w:tblStylePr"];function mn(e,t){let n=Jt(e);const r=(e,t)=>{n=n.filter(t=>t.name!==e),t&&n.push({name:e,xml:t})};t.align&&r("w:jc",`<w:jc w:val="${"justify"===t.align?"both":t.align}"/>`);const o=[];void 0!==t.indentLeft&&o.push(`w:left="${on(t.indentLeft)}"`),void 0!==t.indentRight&&o.push(`w:right="${on(t.indentRight)}"`),void 0!==t.firstLine&&o.push(t.firstLine<0?`w:hanging="${on(-t.firstLine)}"`:`w:firstLine="${on(t.firstLine)}"`),o.length&&r("w:ind",`<w:ind ${o.join(" ")}/>`);const a=[];void 0!==t.before&&a.push(`w:before="${on(t.before)}"`),void 0!==t.after&&a.push(`w:after="${on(t.after)}"`),void 0!==t.lineMultiple&&a.push(`w:line="${Math.round(240*t.lineMultiple)}" w:lineRule="auto"`),void 0!==t.linePoints&&a.push(`w:line="${on(t.linePoints)}" w:lineRule="exact"`),a.length&&r("w:spacing",`<w:spacing ${a.join(" ")}/>`);const i=Zt(n,_t);return i?`<w:pPr>${i}</w:pPr>`:""}function fn(e,t){const n=W(e.parts,e.doc.docPath).find(e=>e.type===A.styles),r=n?U(e.parts,q(e.doc.docPath,n.target)):void 0;if(r)for(const e of B(r).children)if("w:style"===e.name&&R(e,"w:name")?.attrs["w:val"]?.toLowerCase()===t)return e.attrs["w:styleId"];return Object.entries(x).find(([,e])=>e.name===t)?.[0]??null}var pn=["•","o","▪"],hn=["decimal","lowerLetter","lowerRoman"];function gn(e){const t=W(e.parts,e.doc.docPath).find(e=>e.type===A.numbering);if(t){const n=q(e.doc.docPath,t.target);return{path:n,text:U(e.parts,n)??`<w:numbering ${L}></w:numbering>`}}const n="word/numbering.xml";return M(e.parts,e.doc.docPath,A.numbering,"numbering.xml"),P(e.parts,n,"application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"),{path:n,text:`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<w:numbering ${L}></w:numbering>`}}function wn(e,t,n){const{path:r,text:o}=gn(e),a=B(o),i=a.children.filter(e=>"w:abstractNum"===e.name).map(e=>Number(e.attrs["w:abstractNumId"])),l=String((i.length?Math.max(...i):-1)+1);let s="";for(let e=0;e<9;e++){s+=`<w:lvl w:ilvl="${e}"><w:start w:val="1"/><w:numFmt w:val="${t?hn[e%3]:"bullet"}"/><w:lvlText w:val="${t?`%${e+1}.`:n??pn[e%3]}"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="${720*(e+1)}" w:hanging="360"/></w:pPr></w:lvl>`}const c=`<w:abstractNum w:abstractNumId="${l}"><w:multiLevelType w:val="hybridMultilevel"/>${s}</w:abstractNum>`,d=a.children.find(e=>"w:num"===e.name),u=d?d.start:a.innerEnd>a.innerStart||o.includes("</w:numbering>")?o.lastIndexOf("</w:numbering>"):-1,m=u>=0?o.slice(0,u)+c+o.slice(u):o.replace(/\/>\s*$/,`>${c}</w:numbering>`);return V(e.parts,r,m),l}function bn(e,t,n){const{path:r,text:o}=gn(e),a=B(o),i=a.children.filter(e=>"w:num"===e.name).map(e=>Number(e.attrs["w:numId"])),l=String((i.length?Math.max(...i):0)+1),s=`<w:num w:numId="${l}"><w:abstractNumId w:val="${t}"/>${n?'<w:lvlOverride w:ilvl="0"><w:startOverride w:val="1"/></w:lvlOverride>':""}</w:num>`,c=[...a.children].reverse().find(e=>"w:num"===e.name),d=c?c.end:o.lastIndexOf("</w:numbering>");return V(e.parts,r,o.slice(0,d)+s+o.slice(d)),l}var yn={"image/png":"png","image/jpeg":"jpeg","image/gif":"gif","image/bmp":"bmp","image/webp":"webp","image/svg+xml":"svg"};function vn(e,t){const n=t.getAttribute("data-raw"),r=function(e,t){const n=Qt(t),r=tn(n.get("width")),o=tn(n.get("height")),a=t.naturalWidth?.75*t.naturalWidth:0,i=t.naturalHeight?.75*t.naturalHeight:0,l=a&&i?i/a:o&&r?o/r:.75;let s=r??(a||e.contentWidth);return s>2*e.contentWidth&&(s=e.contentWidth),{width:s,height:o??s*l}}(e,t),o=Math.round(12700*r.width),a=Math.round(12700*r.height),i=n?e.doc.raw.get(n):void 0;if(i)return i.replace(/(<wp:extent\b[^>]*?\bcx=")\d+("[^>]*?\bcy=")\d+/,`$1${o}$2${a}`).replace(/(<a:xfrm\b[^>]*>\s*<a:off\b[^>]*\/>\s*<a:ext\b[^>]*?\bcx=")\d+("[^>]*?\bcy=")\d+/,`$1${o}$2${a}`);const l=t.getAttribute("src")??"",s=`${e.part}\n${l}`;let c=e.mediaBySrc.get(s);if(!c){const t=e.images.get(l)??function(e){const t=/^data:([^;,]+);base64,(.*)$/s.exec(e);if(!t)return null;const n=atob(t[2]),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return{bytes:r,mime:t[1]}}(l);if(!t)return"";const n=yn[t.mime]??"png";T(e.parts,n,t.mime);let r=1;const o=[...e.parts.keys()].find(r=>r.startsWith("word/media/inserted")&&r.endsWith(`.${n}`)&&function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(e.parts.get(r),t.bytes));if(o)r=Number(/inserted(\d+)\./.exec(o)[1]);else{for(;e.parts.has(`word/media/inserted${r}.${n}`);)r++;e.parts.set(`word/media/inserted${r}.${n}`,t.bytes)}c=M(e.parts,e.part,A.image,function(e,t){const n=e.split("/").slice(0,-1),r=t.split("/");let o=0;for(;o<n.length&&o<r.length-1&&n[o]===r[o];)o++;return[...n.slice(o).map(()=>".."),...r.slice(o)].join("/")}(e.part,`word/media/inserted${r}.${n}`)),e.mediaBySrc.set(s,c)}const d=++e.drawingId;return`<w:r><w:drawing><wp:inline xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" distT="0" distB="0" distL="0" distR="0"><wp:extent cx="${o}" cy="${a}"/><wp:docPr id="${d}" name="Picture ${d}"/><a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:nvPicPr><pic:cNvPr id="${d}" name="Picture ${d}"/><pic:cNvPicPr/></pic:nvPicPr><pic:blipFill><a:blip r:embed="${c}"/><a:stretch><a:fillRect/></a:stretch></pic:blipFill><pic:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="${o}" cy="${a}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic></wp:inline></w:drawing></w:r>`}function xn(e,t,n,r={}){let o="",a=null;const i=()=>{a?.body&&(o+=`<w:r>${an(e.doc,a.format,a.runId)}${a.body}</w:r>`),a=null},l=(e,t,n)=>{n&&(a&&a.runId===t&&JSON.stringify(a.format)===JSON.stringify(e)?a.body+=n:(i(),a={format:e,runId:t,body:n}))},s=(t,r,a)=>{if(3===t.nodeType)return void l(r,a,function(e){let t="",n="";const r=()=>{n&&(t+=`<w:t xml:space="preserve">${z(n)}</w:t>`),n=""};for(const o of e)"\t"===o?(r(),t+="<w:tab/>"):"\n"===o?(r(),t+="<w:br/>"):"‑"===o?(r(),t+="<w:noBreakHyphen/>"):""===o?(r(),t+="<w:softHyphen/>"):""!==o&&"\ufeff"!==o&&(n+=o);return r(),t}(t.nodeValue??""));if(1!==t.nodeType)return;const c=t,d=c.tagName;if("IMG"===d)return i(),void(o+=vn(e,c));const u=c.getAttribute("data-raw");if(u){const t=e.doc.raw.get(u);if(t){i(),o+=t;const n=c.getAttribute("data-note");null!==n&&e.notesUsed.add(n)}return}if(c.hasAttribute("data-page-break"))return void l(r,a,'<w:br w:type="page"/>');const m=c.getAttribute("data-note");if(null!==m)return i(),e.notesUsed.add(m),dn(e,"FootnoteReference"),void(o+=`<w:r><w:rPr><w:rStyle w:val="FootnoteReference"/></w:rPr><w:footnoteReference w:id="${z(m)}"/></w:r>`);const f=c.getAttribute("data-bookmark");if(null!==f){i();const t=++e.bookmarkId;return void(o+=`<w:bookmarkStart w:id="${t}" w:name="${z(f)}"/><w:bookmarkEnd w:id="${t}"/>`)}const p=c.getAttribute("data-field");if("page"===p||"pages"===p)return i(),void(o+=`<w:fldSimple w:instr=" ${"page"===p?"PAGE":"NUMPAGES"} "><w:r>${an(e.doc,r,a)}<w:t>1</w:t></w:r></w:fldSimple>`);if("BR"===d)return void(function(e,t){let n=e;for(;n!==t;){let e=n.nextSibling;for(;e&&3===e.nodeType&&!e.nodeValue;)e=e.nextSibling;if(e)return!1;if(!n.parentNode)return!0;n=n.parentNode}return!0}(c,n)||l(r,a,"<w:br/>"));if("A"===d)return i(),void(o+=function(e,t,n,r){const o=t.getAttribute("data-anchor"),a=t.getAttribute("href")??"";let i=t.getAttribute("data-rel");const l=W(e.parts,e.part),s=i?l.find(e=>e.id===i):void 0;a&&!a.startsWith("#")&&s?.target!==a&&(i=l.find(e=>e.external&&e.target===a)?.id??M(e.parts,e.part,A.hyperlink,a,!0),t.setAttribute("data-rel",i));const c=t.querySelector("[data-r]")?n:{color:"#0563c1",u:!0,...n},d=xn(e,Array.from(t.childNodes),r,c);return`<w:hyperlink${o?` w:anchor="${z(o)}"`:i?` r:id="${z(i)}"`:a.startsWith("#")?` w:anchor="${z(a.slice(1))}"`:""} w:history="1">${d}</w:hyperlink>`}(e,c,r,n));if("INS"===d||"DEL"===d)return i(),void(o+=function(e,t,n,r){let o=t.getAttribute("data-tid");o&&/^\d+$/.test(o)||(o=String(e.trackId++),t.setAttribute("data-tid",o));const a=t.getAttribute("data-author")||"Unknown",i=t.getAttribute("data-date")||(new Date).toISOString().replace(/\.\d+Z$/,"Z");t.getAttribute("data-date")||t.setAttribute("data-date",i);let l=xn(e,Array.from(t.childNodes),r,n);const s="INS"===t.tagName?"ins":"del";"del"===s&&(l=l.replace(/<w:t(\s|>)/g,"<w:delText$1").replace(/<\/w:t>/g,"</w:delText>").replace(/<w:instrText(\s|>)/g,"<w:delInstrText$1").replace(/<\/w:instrText>/g,"</w:delInstrText>"));return l?`<w:${s} w:id="${z(o)}" w:author="${z(a)}" w:date="${z(i)}">${l}</w:${s}>`:""}(e,c,r,n));const h=c.getAttribute("data-comment");h&&e.firstComment.get(h)===c&&(i(),o+=`<w:commentRangeStart w:id="${z(h)}"/>`);const g=c.getAttribute("data-r"),w=function(e,t){const n={...t},r=e.tagName;if("B"!==r&&"STRONG"!==r||(n.b=!0),"I"!==r&&"EM"!==r||(n.i=!0),"U"===r&&(n.u=!0),"S"!==r&&"STRIKE"!==r||(n.strike=!0),"SUB"===r&&(n.vert="sub"),"SUP"===r&&(n.vert="super"),"FONT"===r){const t=en(e.getAttribute("color")??void 0);t&&(n.color=t);const r=e.getAttribute("face");r&&(n.font=r.split(",")[0].replace(/["']/g,"").trim());const o=Number(e.getAttribute("size"));o>=1&&o<=7&&(n.size=nn[o-1])}const o=Qt(e),a=o.get("font-weight");a&&(n.b="bold"===a||"bolder"===a||Number(a)>=600);const i=o.get("font-style");i&&(n.i="italic"===i||"oblique"===i);const l=o.get("text-decoration-line")??o.get("text-decoration");l&&(/none/.test(l)?(n.u=!1,n.strike=!1):(/underline/.test(l)&&(n.u=!0),/line-through/.test(l)&&(n.strike=!0)));const s=o.get("font-family");s&&(n.font=s.split(",")[0].replace(/["']|"/g,"").trim());const c=tn(o.get("font-size"));if(c&&(n.size=Math.round(2*c)/2),o.has("color")){const e=en(o.get("color"));e?n.color=e:delete n.color}const d=o.get("background-color")??o.get("background");if(void 0!==d){const e=en(d);e?n.hl=e:delete n.hl}return n}(c,r);for(const e of Array.from(c.childNodes))s(e,w,g??a);h&&e.lastComment.get(h)===c&&(i(),o+=`<w:commentRangeEnd w:id="${z(h)}"/><w:r><w:commentReference w:id="${z(h)}"/></w:r>`)};for(const e of t)s(e,r,null);return i(),o}function kn(e,t,n,r,o){const a=n?B(n):void 0,i=D(a),l=function(e){const t=Qt(e),n={},r=t.get("text-align")??e.getAttribute("align")??void 0;"left"===r||"start"===r?n.align="left":"center"!==r&&"right"!==r&&"justify"!==r||(n.align=r);const o=tn(t.get("margin-left"));void 0!==o&&(n.indentLeft=o);const a=tn(t.get("margin-right"));void 0!==a&&(n.indentRight=a),e.hasAttribute("data-tabs")&&(n.tabs=j(e.getAttribute("data-tabs")));const i=tn(t.get("text-indent"));void 0!==i&&(n.firstLine=i);const l=tn(t.get("margin-top"));void 0!==l&&(n.before=l);const s=tn(t.get("margin-bottom"));void 0!==s&&(n.after=s);const c=t.get("line-height");if(c){const e=tn(c);e?n.linePoints=e:Number(c)&&(n.lineMultiple=Number(c))}return n}(t);let s=Jt(n);const c=(e,t)=>{s=s.filter(t=>t.name!==e),t&&s.push({name:e,xml:t})};if(c("w:pStyle",r?`<w:pStyle w:val="${z(r)}"/>`:null),c("w:numPr",o?`<w:numPr><w:ilvl w:val="${o.ilvl}"/><w:numId w:val="${z(o.numId)}"/></w:numPr>`:null),l.align!==i.align&&c("w:jc",l.align?`<w:jc w:val="${"justify"===l.align?"both":l.align}"/>`:null),!(o||rn(l.indentLeft,i.indentLeft)&&rn(l.firstLine,i.firstLine)&&rn(l.indentRight,i.indentRight))){const e=[];void 0!==l.indentLeft&&e.push(`w:left="${on(l.indentLeft)}"`),void 0!==l.indentRight&&e.push(`w:right="${on(l.indentRight)}"`),void 0!==l.firstLine&&e.push(l.firstLine<0?`w:hanging="${on(-l.firstLine)}"`:`w:firstLine="${on(l.firstLine)}"`),c("w:ind",e.length?`<w:ind ${e.join(" ")}/>`:null)}if(!(rn(l.before,i.before)&&rn(l.after,i.after)&&rn(l.lineMultiple,i.lineMultiple)&&rn(l.linePoints,i.linePoints))){const e=[];void 0!==l.before&&e.push(`w:before="${on(l.before)}"`),void 0!==l.after&&e.push(`w:after="${on(l.after)}"`),void 0!==l.lineMultiple&&e.push(`w:line="${Math.round(240*l.lineMultiple)}" w:lineRule="auto"`),void 0!==l.linePoints&&e.push(`w:line="${on(l.linePoints)}" w:lineRule="exact"`),c("w:spacing",e.length?`<w:spacing ${e.join(" ")}/>`:null)}if(t.hasAttribute("data-tabs")&&!Cn(l.tabs??[],i.tabs??[])){const e=(l.tabs??[]).map(e=>`<w:tab w:val="${e.align}" w:pos="${on(e.pos)}"/>`),t=(i.tabs??[]).filter(e=>!(l.tabs??[]).some(t=>rn(t.pos,e.pos))).map(e=>`<w:tab w:val="clear" w:pos="${on(e.pos)}"/>`);c("w:tabs",e.length||t.length?`<w:tabs>${[...e,...t].join("")}</w:tabs>`:null)}c("w:sectPr",e.sections.get(t)??null);const d=Zt(s,_t);return d?`<w:pPr>${d}</w:pPr>`:""}var Cn=(e,t)=>e.length===t.length&&e.every((e,n)=>rn(e.pos,t[n].pos)&&e.align===t[n].align);function Sn(e,t,n,r){const o=t.getAttribute("data-docx"),a=o?e.doc.blocks.get(o):void 0,i=t.getAttribute("data-pid"),l=i&&/^[0-7][0-9A-F]{7}$/.test(i)?i:null;if(a?.xml&&a.xml.startsWith("<w:p")&&(a.fingerprint===p(t)||t.hasAttribute("data-locked"))&&!e.sections.has(t)&&(t.hasAttribute("data-locked")||(a.numId??null)===(r?.numId??null)&&(a.ilvl??null)===(r?.ilvl??null))){for(const t of a.xml.matchAll(/<w:footnoteReference\b[^>]*w:id="([^"]+)"/g))e.notesUsed.add(t[1]);return l&&!/^<w:p\b[^>]*w14:paraId=/.test(a.xml)?a.xml.replace(/^<w:p\b/,`<w:p w14:paraId="${l}"`):a.xml}const s=kn(e,t,a?.props,function(e,t){let n=t.getAttribute("data-pstyle");if(!n){const r=/^H([1-6])$/.exec(t.tagName);r?n=fn(e,`heading ${r[1]}`)??`Heading${r[1]}`:"BLOCKQUOTE"===t.tagName&&(n=fn(e,"quote"))}return n&&dn(e,n),n}(e,t),r);let c=xn(e,n,t);const d=t.getAttribute("data-bm");if(d&&/^[A-Za-z0-9_]+$/.test(d)&&!c.includes(`w:name="${d}"`)){const t=++e.bookmarkId;c=`<w:bookmarkStart w:id="${t}" w:name="${d}"/>${c}<w:bookmarkEnd w:id="${t}"/>`}return`<w:p${l?` w14:paraId="${l}"`:""}>${s}${c}</w:p>`}var Nn=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","UL","OL","TABLE","LI","HR","SECTION","ARTICLE"]);function An(e,t,n,r){if(t.hasAttribute("data-checklist")){const n=function(e){if(e.checkNums)return e.checkNums;const{path:t,text:n}=gn(e),r=B(n),o={},a=new Map;for(const e of r.children.filter(e=>"w:abstractNum"===e.name)){const t=e.children.find(e=>"w:lvl"===e.name&&"0"===e.attrs["w:ilvl"]),n=R(t,"w:lvlText")?.attrs["w:val"];n===k.open&&a.set(e.attrs["w:abstractNumId"],"open"),n===k.done&&a.set(e.attrs["w:abstractNumId"],"done")}for(const e of r.children.filter(e=>"w:num"===e.name)){const t=a.get(R(e,"w:abstractNumId")?.attrs["w:val"]??"");t&&!o[t]&&(o[t]=e.attrs["w:numId"])}const i=t=>{const n=wn(e,!1,t);return bn(e,n,!1)};return e.checkNums={open:o.open??i(k.open),done:o.done??i(k.done)},e.checkNums}(e),o=t.getAttribute("data-ilvl"),a=null!==o&&Number(o)>r?Number(o):r+1;let i="";for(const r of Array.from(t.children)){if("UL"===r.tagName||"OL"===r.tagName){i+=An(e,r,null,a);continue}if("LI"!==r.tagName)continue;const t=Array.from(r.children).filter(e=>"UL"===e.tagName||"OL"===e.tagName);i+=Sn(e,r,Array.from(r.childNodes).filter(e=>!t.includes(e)),{numId:r.hasAttribute("data-checked")?n.done:n.open,ilvl:a});for(const n of t)i+=An(e,n,null,a)}return i}const o=function(e,t,n){const r=t.getAttribute("data-num-id");if(r)return r;if(n)return t.setAttribute("data-num-id",n),n;let o;return"OL"===t.tagName?(e.orderedAbstract??=wn(e,!0),o=bn(e,e.orderedAbstract,!0)):(e.bulletNum??=bn(e,wn(e,!1),!1),o=e.bulletNum),t.setAttribute("data-num-id",o),o}(e,t,n),a=t.getAttribute("data-ilvl"),i=null!==a&&Number(a)>r?Number(a):r+1;let l="";for(const n of Array.from(t.children)){if("UL"===n.tagName||"OL"===n.tagName){l+=An(e,n,o,i);continue}if("LI"!==n.tagName)continue;const t=Array.from(n.children).filter(e=>"UL"===e.tagName||"OL"===e.tagName);l+=Sn(e,n,Array.from(n.childNodes).filter(e=>!t.includes(e)),{numId:o,ilvl:i});for(const n of t)l+=An(e,n,o,i)}return l}function $n(e){return Array.from(e.children).some(e=>Nn.has(e.tagName))}function Ln(e,t){let n="",r=[];const o=()=>{r.some(e=>1===e.nodeType||(e.nodeValue??"").trim())&&(n+=`<w:p>${xn(e,r,t)}</w:p>`),r=[]};for(const a of Array.from(t.childNodes)){const t=a;if(1!==a.nodeType||!Nn.has(t.tagName)){r.push(a);continue}o();const i=t.getAttribute("data-docx"),l=i?e.doc.blocks.get(i):void 0;"UL"===t.tagName||"OL"===t.tagName?n+=An(e,t,null,-1):"TABLE"===t.tagName?n+=Tn(e,t):t.hasAttribute("data-toc")?n+=En(e,t,l?.fingerprint===p(t)?l.xml:void 0):t.hasAttribute("data-locked")&&l?.xml?n+=l.xml:"HR"===t.tagName?n+='<w:p><w:pPr><w:pBdr><w:bottom w:val="single" w:sz="6" w:space="1" w:color="auto"/></w:pBdr></w:pPr></w:p>':$n(t)?n+=Ln(e,t):n+=Sn(e,t,Array.from(t.childNodes),null)}return o(),n}function Tn(e,t){const n=t.getAttribute("data-docx"),r=n?e.doc.blocks.get(n):void 0;if(r?.xml&&(t.hasAttribute("data-locked")||r.fingerprint===p(t)))return r.xml;const o=Array.from(t.querySelectorAll(":scope > tbody > tr, :scope > tr, :scope > thead > tr, :scope > tfoot > tr")),a=[];let i=0;const l=o.map(t=>{const n=[];let r=0;const o=()=>{for(;a[r]?.left>0;){const e=a[r];e.left--,n.push({continuation:!0,span:e.span,col:r,props:e.props}),r+=e.span}};for(const i of Array.from(t.children).filter(e=>"TD"===e.tagName||"TH"===e.tagName)){o();const t=Math.max(1,Number(i.getAttribute("colspan")??1)),l=Math.max(1,Number(i.getAttribute("rowspan")??1));n.push({cell:i,span:t,col:r}),l>1&&(a[r]={left:l-1,span:t,props:e.doc.blocks.get(i.getAttribute("data-docx")??"")?.props}),r+=t}return o(),i=Math.max(i,r),n}),s=Array.from(t.querySelectorAll(":scope > colgroup > col")),c=[];for(let t=0;t<i;t++){const n=s[t]?tn(Qt(s[t]).get("width")):void 0;c.push(void 0!==n&&s.length===i?on(n):Math.round(20*e.contentWidth/Math.max(i,1)))}return`<w:tbl>${r?.props??'<w:tblPr><w:tblW w:w="5000" w:type="pct"/><w:tblBorders><w:top w:val="single" w:sz="4" w:space="0" w:color="auto"/><w:left w:val="single" w:sz="4" w:space="0" w:color="auto"/><w:bottom w:val="single" w:sz="4" w:space="0" w:color="auto"/><w:right w:val="single" w:sz="4" w:space="0" w:color="auto"/><w:insideH w:val="single" w:sz="4" w:space="0" w:color="auto"/><w:insideV w:val="single" w:sz="4" w:space="0" w:color="auto"/></w:tblBorders><w:tblLook w:val="04A0"/></w:tblPr>'}${`<w:tblGrid>${c.map(e=>`<w:gridCol w:w="${e}"/>`).join("")}</w:tblGrid>`}${o.map((t,n)=>`<w:tr>${e.doc.blocks.get(t.getAttribute("data-docx")??"")?.props??""}${l[n].map(t=>{const n=t.span,r=c.slice(t.col,t.col+n).reduce((e,t)=>e+t,0);if("continuation"in t)return`<w:tc><w:tcPr>${Pn(t.props,r,n,"continue",void 0)}</w:tcPr><w:p/></w:tc>`;const o=e.doc.blocks.get(t.cell.getAttribute("data-docx")??""),a=Number(t.cell.getAttribute("rowspan")??1),i=en(Qt(t.cell).get("background-color"));let l=Ln(e,t.cell);return l.endsWith("</w:p>")||l.endsWith("<w:p/>")||(l+="<w:p/>"),`<w:tc><w:tcPr>${Pn(o?.props,r,n,a>1?"restart":null,i)}</w:tcPr>${l}</w:tc>`}).join("")}</w:tr>`).join("")}</w:tbl>`}function Pn(e,t,n,r,o){const a=e?B(e):void 0;let i=Jt(e).filter(e=>!["w:tcW","w:gridSpan","w:vMerge"].includes(e.name));i.push({name:"w:tcW",xml:`<w:tcW w:w="${t}" w:type="dxa"/>`}),n>1&&i.push({name:"w:gridSpan",xml:`<w:gridSpan w:val="${n}"/>`}),r&&i.push({name:"w:vMerge",xml:"restart"===r?'<w:vMerge w:val="restart"/>':"<w:vMerge/>"});const l=R(a,"w:shd")?.attrs["w:fill"]?.toLowerCase();return"continue"!==r&&(o?.slice(1)??void 0)!==(l&&/^[0-9a-f]{6}$/.test(l)?l:void 0)&&(i=i.filter(e=>"w:shd"!==e.name),o&&i.push({name:"w:shd",xml:`<w:shd w:val="clear" w:color="auto" w:fill="${o.slice(1).toUpperCase()}"/>`})),Zt(i,Gt)}function Mn(e){let t=0;for(const n of e.matchAll(/<w:(?:ins|del|moveFrom|moveTo)\b[^>]*\bw:id="(\d+)"/g))t=Math.max(t,Number(n[1]));return Math.max(t+1,1e3)}function En(e,t,n){if(n)return n;const r=Math.round(20*e.contentWidth),o='<w:r><w:fldChar w:fldCharType="begin"/></w:r><w:r><w:instrText xml:space="preserve"> TOC \\o "1-3" \\h \\z \\u </w:instrText></w:r><w:r><w:fldChar w:fldCharType="separate"/></w:r>',a=Array.from(t.querySelectorAll("[data-toc-level]")).map((t,n)=>{const a=Math.min(Math.max(Number(t.getAttribute("data-toc-level"))||1,1),6);dn(e,`TOC${a}`);const i=t.querySelector("a"),l=i?.getAttribute("data-anchor")??"",s=t.querySelector("[data-toc-page]")?.textContent??"",c=(i??t).cloneNode(!0);c.querySelectorAll("[data-toc-page]").forEach(e=>e.remove());const d=`<w:r><w:t xml:space="preserve">${z(c.textContent??"")}</w:t></w:r><w:r><w:tab/></w:r><w:r><w:t>${z(s)}</w:t></w:r>`,u=/^[A-Za-z0-9_]+$/.test(l)?`<w:hyperlink w:anchor="${l}" w:history="1">${d}</w:hyperlink>`:d;return`<w:p><w:pPr><w:pStyle w:val="TOC${a}"/><w:tabs><w:tab w:val="right" w:leader="dot" w:pos="${r}"/></w:tabs></w:pPr>${0===n?o:""}${u}</w:p>`});return a.length||a.push(`<w:p>${o}</w:p>`),`<w:sdt><w:sdtPr><w:docPartObj><w:docPartGallery w:val="Table of Contents"/><w:docPartUnique/></w:docPartObj></w:sdtPr><w:sdtContent>${a.join("")}<w:p><w:r><w:fldChar w:fldCharType="end"/></w:r></w:p></w:sdtContent></w:sdt>`}function Rn(e,t){return`<w:footnote w:id="${z(e)}"><w:p><w:pPr><w:pStyle w:val="FootnoteText"/></w:pPr><w:r><w:rPr><w:rStyle w:val="FootnoteReference"/></w:rPr><w:footnoteRef/></w:r><w:r><w:t xml:space="preserve"> ${z(t)}</w:t></w:r></w:p></w:footnote>`}var zn=["w:writeProtection","w:view","w:zoom","w:removePersonalInformation","w:removeDateAndTime","w:doNotDisplayPageBoundaries","w:displayBackgroundShape","w:printPostScriptOverText","w:printFractionalCharacterWidth","w:printFormsData","w:embedTrueTypeFonts","w:embedSystemFonts","w:saveSubsetFonts","w:saveFormsData","w:mirrorMargins","w:alignBordersAndEdges","w:bordersDoNotSurroundHeader","w:bordersDoNotSurroundFooter","w:gutterAtTop","w:hideSpellingErrors","w:hideGrammaticalErrors","w:activeWritingStyle","w:proofState","w:formsDesign","w:attachedTemplate","w:linkStyles","w:stylePaneFormatFilter","w:stylePaneSortMethod","w:documentType","w:mailMerge","w:revisionView","w:trackRevisions","w:doNotTrackMoves","w:doNotTrackFormatting","w:documentProtection","w:autoFormatOverride","w:styleLockTheme","w:styleLockQFSet","w:defaultTabStop","w:autoHyphenation","w:consecutiveHyphenLimit","w:hyphenationZone","w:doNotHyphenateCaps","w:showEnvelope","w:summaryLength","w:clickAndTypeStyle","w:defaultTableStyle","w:evenAndOddHeaders","w:bookFoldRevPrinting","w:bookFoldPrinting","w:bookFoldPrintingSheets","w:drawingGridHorizontalSpacing","w:drawingGridVerticalSpacing","w:displayHorizontalDrawingGridEvery","w:displayVerticalDrawingGridEvery","w:doNotUseMarginsForDrawingGridOrigin","w:drawingGridHorizontalOrigin","w:drawingGridVerticalOrigin","w:doNotShadeFormData","w:noPunctuationKerning","w:characterSpacingControl","w:printTwoOnOne","w:strictFirstAndLastChars","w:noLineBreaksAfter","w:noLineBreaksBefore","w:savePreviewPicture","w:doNotValidateAgainstSchema","w:saveInvalidXml","w:ignoreMixedContent","w:alwaysShowPlaceholderText","w:doNotDemarcateInvalidXml","w:saveXmlDataOnly","w:useXSLTWhenSaving","w:saveThroughXslt","w:showXMLTags","w:alwaysMergeEmptyNamespace","w:updateFields","w:hdrShapeDefaults","w:footnotePr","w:endnotePr","w:compat","w:docVars","w:rsids","m:mathPr","w:attachedSchema","w:themeFontLang","w:clrSchemeMapping","w:doNotIncludeSubdocsInStats","w:doNotAutoCompressPictures","w:forceUpgrade","w:captions","w:readModeInkLockDown","w:smartTagType","sl:schemaLibrary","w:shapeDefaults","w:doNotEmbedSmartTags","w:decimalSymbol","w:listSeparator"];function Fn(e,t,n){const{path:r,text:o}=function(e){const t=W(e.parts,e.doc.docPath).find(e=>e.type===A.settings);if(t){const n=q(e.doc.docPath,t.target);return{path:n,text:U(e.parts,n)??`<w:settings ${L}></w:settings>`}}const n="word/settings.xml";return M(e.parts,e.doc.docPath,A.settings,"settings.xml"),P(e.parts,n,"application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"),{path:n,text:`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<w:settings ${L}></w:settings>`}}(e),a=B(o),i=a.children.find(e=>e.name===t);let l=o;if(i)l=o.slice(0,i.start)+(n??"")+o.slice(i.end);else if(n){const e=zn.indexOf(t),r=a.children.find(t=>zn.indexOf(t.name)>e);l=r?o.slice(0,r.start)+n+o.slice(r.start):/<\/w:settings>\s*$/.test(o)?o.replace(/<\/w:settings>\s*$/,`${n}</w:settings>`):o.replace(/\/>\s*$/,`>${n}</w:settings>`)}l!==o&&V(e.parts,r,l)}function On(e,t,n){const r=/^<w:sectPr\b([^>]*?)\/?>/.exec(e)?.[1]??"";let o=Jt(`<x>${/^<w:sectPr\b[^>]*\/>$/.test(e)?"":e.replace(/^<w:sectPr\b[^>]*>/,"").replace(/<\/w:sectPr>$/,"")}</x>`).filter(e=>e.name!==t);return n&&(o=[...o,{name:t,xml:n}]),`<w:sectPr${r}>${Zt(o,Xt)}</w:sectPr>`}var In=e=>e>1?`<w:cols w:num="${e}" w:space="720"/>`:null;var Dn=`${L} xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"`;function Hn(e,t,n,r){const o=document.createElement("div");o.innerHTML=n;const a=e.part;let i;e.part=r;try{i=Ln(e,o)}finally{e.part=a}/<\/w:p>\s*$|<w:p\/>\s*$/.test(i)||(i+="<w:p/>");const l=U(e.parts,r);return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n${(l?new RegExp(`<w:${t}\\b[^>]*>`).exec(l)?.[0]:void 0)??`<w:${t} ${Dn}>`}${i}</w:${t}>`}async function jn(e,t,n){const r=new Map(e.parts),o=U(r,e.docPath);if(!o)throw new Error("Not a Word document");const a=B(o),i=R(a,"w:body"),l=R(i,"w:sectPr"),s={doc:e,parts:r,images:n.images??new Map,firstComment:new Map,lastComment:new Map,drawingId:9e4,mediaBySrc:e.insertedMedia??=new Map,contentWidth:(n.page.width-n.page.left-n.page.right)/20,bulletNum:null,orderedAbstract:null,part:e.docPath,checkNums:null,bookmarkId:8e4,sections:new Map,notesUsed:new Set,trackId:Mn(o)};t.querySelectorAll("[data-comment]").forEach(e=>{const t=e.getAttribute("data-comment");s.firstComment.has(t)||s.firstComment.set(t,e),s.lastComment.set(t,e)});const c=l?o.slice(l.start,l.end):void 0,d=function(e,t,n){const r=Array.from(t.children).filter(e=>e.hasAttribute("data-section")),o=(n??"<w:sectPr/>").replace(/<w:(header|footer)Reference\b[^>]*\/>/g,"").replace(/<w:titlePg\b[^>]*\/>/g,"").replace(/<w:type\b[^>]*\/>/g,"");r.forEach((t,n)=>{const a=e.doc.blocks.get(t.getAttribute("data-docx")??""),i=a?.props?/<w:sectPr\b[\s\S]*?(?:<\/w:sectPr>|\/>)/.exec(a.props)?.[0]:void 0;let l=i??o;const s=0===n?null:r[n-1].getAttribute("data-section");l=0===n&&i?l:On(l,"w:type",s&&"nextPage"!==s?`<w:type w:val="${z(s)}"/>`:null),l=On(l,"w:cols",In(Number(t.getAttribute("data-cols")??1))),e.sections.set(t,l)});const a=r[r.length-1]?.getAttribute("data-section");return r.length?a??"nextPage":null}(s,t,c);let u=Ln(s,t);/<\/w:p>\s*$|<w:p\/>\s*$/.test(u)||(u+="<w:p/>"),u=function(e){const t=new Set,n=e.replace(/<w:commentRangeStart\b[^>]*w:id="([^"]+)"[^>]*\/>/g,(e,n)=>t.has(n)?"":(t.add(n),e)),r=new Set,o=[],a=n.split(/(<w:commentRangeEnd\b[^>]*\/>|<w:r>(?:<w:rPr>(?:(?!<\/w:rPr>).)*<\/w:rPr>)?<w:commentReference\b[^>]*\/><\/w:r>)/s);for(let e=a.length-1;e>=0;e--){const t=a[e],n=/^<w:commentRangeEnd\b[^>]*w:id="([^"]+)"/.exec(t)??/^<w:r>.*<w:commentReference\b[^>]*w:id="([^"]+)"/s.exec(t);if(n&&e%2==1){const e=`${t.includes("commentRangeEnd")?"e":"r"}${n[1]}`;if(r.has(e))continue;r.add(e)}o.push(t)}return o.reverse().join("")}(u);const m=function(e,t,n,r){let o=t??"<w:sectPr/>";const a=n.page,i=e.doc.page;if(Object.keys(a).some(e=>a[e]!==i[e])||!t){const e=a.width>a.height,n=t?B(t):void 0,r=R(n,"w:pgMar")?.attrs["w:gutter"]??"0";o=On(o,"w:pgSz",`<w:pgSz w:w="${a.width}" w:h="${a.height}"${e?' w:orient="landscape"':""}/>`),o=On(o,"w:pgMar",`<w:pgMar w:top="${a.top}" w:right="${a.right}" w:bottom="${a.bottom}" w:left="${a.left}" w:header="${a.header}" w:footer="${a.footer}" w:gutter="${r}"/>`)}const l=n.columns??e.doc.columns;l!==e.doc.columns&&(o=On(o,"w:cols",In(l))),null!==r&&(o=On(o,"w:type","nextPage"!==r?`<w:type w:val="${z(r)}"/>`:null));const s=n.titlePage??e.doc.titlePage;s!==e.doc.titlePage&&(o=On(o,"w:titlePg",s?"<w:titlePg/>":null));const c=n.evenOdd??e.doc.evenOdd;c!==e.doc.evenOdd&&Fn(e,"w:evenAndOddHeaders",c?"<w:evenAndOddHeaders/>":null);const d=[],u=(t,n)=>{const r="headers"===t?"header":"footer";for(const o of["default","first","even"]){const a=e.doc[t][o],i=n?.[o];if(void 0===i||!a.editable||i===a.html)continue;if(!a.part&&!i.replace(/<br>|<p>|<\/p>|\s/g,""))continue;let l=a.part;if(!l){let n=1;for(;e.parts.has(`word/${r}${n}.xml`);)n++;l=`word/${r}${n}.xml`,V(e.parts,l,""),P(e.parts,l,`application/vnd.openxmlformats-officedocument.wordprocessingml.${r}+xml`);const i=M(e.parts,e.doc.docPath,"headers"===t?A.header:A.footer,`${r}${n}.xml`);d.push(`<w:${r}Reference w:type="${o}" r:id="${i}"/>`),a.part=l}V(e.parts,l,Hn(e,"headers"===t?"hdr":"ftr",i,l))}};if(u("headers",n.headers),u("footers",n.footers),d.length){const e=/^<w:sectPr\b([^>]*?)\/?>/.exec(o)?.[1]??"",t=/^<w:sectPr\b[^>]*\/>$/.test(o)?"":o.replace(/^<w:sectPr\b[^>]*>/,"").replace(/<\/w:sectPr>$/,"");o=`<w:sectPr${e}>${Zt([...Jt(`<x>${t}</x>`),...d.map(e=>({name:/^<(w:\w+)/.exec(e)[1],xml:e}))],Xt)}</w:sectPr>`}return o}(s,c,n,d);!function(e){const t=[...e.notesUsed].filter(t=>{const n=e.doc.footnotes.get(t);return n&&n.editable&&(!n.xml||n.text!==e.doc.footnotesRead?.get(t))});if(!t.length)return;dn(e,"FootnoteText"),dn(e,"FootnoteReference");const n=W(e.parts,e.doc.docPath).find(e=>e.type===A.footnotes);let r,o;n?(r=q(e.doc.docPath,n.target),o=U(e.parts,r)??""):(r="word/footnotes.xml",M(e.parts,e.doc.docPath,A.footnotes,"footnotes.xml"),P(e.parts,r,"application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml"),o=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<w:footnotes ${L}><w:footnote w:type="separator" w:id="-1"><w:p><w:pPr><w:spacing w:after="0" w:line="240" w:lineRule="auto"/></w:pPr><w:r><w:separator/></w:r></w:p></w:footnote><w:footnote w:type="continuationSeparator" w:id="0"><w:p><w:pPr><w:spacing w:after="0" w:line="240" w:lineRule="auto"/></w:pPr><w:r><w:continuationSeparator/></w:r></w:p></w:footnote></w:footnotes>`,Fn(e,"w:footnotePr",'<w:footnotePr><w:footnote w:id="-1"/><w:footnote w:id="0"/></w:footnotePr>'));const a=B(o),i=new Map(a.children.filter(e=>"w:footnote"===e.name).map(e=>[e.attrs["w:id"],e]));let l=o;const s=[],c=[];for(const n of t){const t=Rn(n,e.doc.footnotes.get(n).text),r=i.get(n);r?c.push({start:r.start,end:r.end,xml:t}):s.push(t)}for(const e of c.sort((e,t)=>t.start-e.start))l=l.slice(0,e.start)+e.xml+l.slice(e.end);s.length&&(l=l.replace(/<\/w:footnotes>\s*$/,`${s.join("")}</w:footnotes>`)),V(e.parts,r,l)}(s),n.styleEdits?.size&&function(e,t){for(const n of t.keys())dn(e,n);const n=cn(e),r=n?U(e.parts,n):void 0;if(!n||!r)return;let o=r;const a=B(r).children.filter(e=>"w:style"===e.name&&t.has(e.attrs["w:styleId"])).reverse();for(const n of a){const a=t.get(n.attrs["w:styleId"]),i=r.slice(n.start,n.end),l=B(i),s=R(l,"w:rPr"),c=R(l,"w:pPr"),d=s?i.slice(s.start,s.end):void 0,u=c?i.slice(c.start,c.end):void 0,m=ln(d,{...H(s,e.doc.theme),...a.run},e.doc),f=mn(u,a.para);let p=l.children.filter(e=>"w:rPr"!==e.name&&"w:pPr"!==e.name).map(e=>({name:e.name,xml:i.slice(e.start,e.end)}));f&&p.push({name:"w:pPr",xml:f}),m&&p.push({name:"w:rPr",xml:m}),p=p.filter(Boolean);const h=`${/^<w:style\b[^>]*?(?=\/?>)/.exec(i)[0]}>${Zt(p,un)}</w:style>`;o=o.slice(0,n.start)+h+o.slice(n.end)}V(e.parts,n,o)}(s,n.styleEdits);const f=o.slice(a.start,a.innerStart),p=/\bw14:paraId=/.test(u),h=[!/\bxmlns:r=/.test(f)&&/\br:(id|embed)=/.test(u+m)?' xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"':"",p&&!/\bxmlns:w14=/.test(f)?' xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"':"",p&&!/\bxmlns:mc=/.test(f)?' xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"':""].join("");let g=o.slice(0,a.innerStart-1)+h;if(p){const e=/\bmc:Ignorable="([^"]*)"/.exec(g);e?e[1].split(/\s+/).includes("w14")||(g=g.replace(/\bmc:Ignorable="([^"]*)"/,(e,t)=>`mc:Ignorable="${`${t} w14`.trim()}"`)):g+=' mc:Ignorable="w14"'}const w=`${g}>`+o.slice(a.innerStart,i.innerStart)+u+m+o.slice(i.innerEnd);V(r,e.docPath,w),e.parts=r,e.page={...n.page};for(const t of["headers","footers"]){const r=n[t];for(const n of["default","first","even"]){const o=r?.[n];void 0!==o&&e[t][n].editable&&(e[t][n]={...e[t][n],html:o})}}return e.titlePage=n.titlePage??e.titlePage,e.evenOdd=n.evenOdd??e.evenOdd,e.columns=n.columns??e.columns,e.footnotesRead=new Map([...e.footnotes].map(([e,t])=>[e,t.text])),Q(r)}import{useRef as Bn,useState as Un}from"react";import{Icon as Wn}from"efficient-shell/icons";import{Button as qn,Checkbox as Kn,Dialog as Vn,IconButton as _n}from"efficient-shell/ui";import{Fragment as Gn,jsx as Xn,jsxs as Jn}from"react/jsx-runtime";function Zn({label:e,html:t,locked:n,scope:r,onRef:o}){const a=u(),i=Bn(null),l=(e,t)=>{document.activeElement!==i.current&&i.current?.focus(),document.execCommand(e,!1,t)},s=e=>{const t=i.current,n=document.getSelection();if(!t||!n)return;if(!n.rangeCount||!t.contains(n.anchorNode)){t.focus();const e=document.createRange();e.selectNodeContents(t.lastElementChild??t),e.collapse(!1),n.removeAllRanges(),n.addRange(e)}const r=n.getRangeAt(0);r.deleteContents();const o=document.createElement("div");o.innerHTML=(e=>`<span data-kind="field" data-field="${e}" contenteditable="false">1</span>`)(e);const a=o.firstChild;r.insertNode(a);const l=a.nextSibling;l&&"BR"===l.nodeName&&!l.nextSibling&&l.remove();const s=document.createTextNode("");a.after(s),n.collapse(s,1)};return Jn("div",{className:"docs-hf-region",children:[Jn("div",{className:"docs-hf-tools",onMouseDown:e=>e.preventDefault(),children:[Xn("span",{className:"docs-hf-label",children:e}),!n&&Jn(Gn,{children:[Xn(_n,{size:"sm",variant:"ghost","aria-label":a.bold,title:a.bold,onClick:()=>l("bold"),children:Xn(Wn,{name:"bold",size:14})}),Xn(_n,{size:"sm",variant:"ghost","aria-label":a.italic,title:a.italic,onClick:()=>l("italic"),children:Xn(Wn,{name:"italic",size:14})}),Xn(_n,{size:"sm",variant:"ghost","aria-label":a.underline,title:a.underline,onClick:()=>l("underline"),children:Xn(Wn,{name:"underline",size:14})}),Xn(_n,{size:"sm",variant:"ghost","aria-label":a.alignLeft,title:a.alignLeft,onClick:()=>l("justifyLeft"),children:Xn(Wn,{name:"align-left",size:14})}),Xn(_n,{size:"sm",variant:"ghost","aria-label":a.alignCenter,title:a.alignCenter,onClick:()=>l("justifyCenter"),children:Xn(Wn,{name:"align-center",size:14})}),Xn(_n,{size:"sm",variant:"ghost","aria-label":a.alignRight,title:a.alignRight,onClick:()=>l("justifyRight"),children:Xn(Wn,{name:"align-right",size:14})}),Xn(qn,{size:"sm",variant:"ghost",onClick:()=>s("page"),children:a.pageNumber}),Xn(qn,{size:"sm",variant:"ghost",onClick:()=>s("pages"),children:a.pageCount})]})]}),Xn("div",{ref:e=>{i.current=e,o(e),e&&!e.dataset.ready&&(e.innerHTML=t||"<p><br></p>",e.dataset.ready="1")},className:"docs-page docs-hf-edit","data-doc":r,role:"textbox","aria-label":e,"aria-multiline":"true",contentEditable:!n,suppressContentEditableWarning:!0}),n&&Xn("p",{className:"docs-hf-note",children:a.headerFooterLocked})]})}function Qn({value:e,locked:t,scope:n,onApply:r,onClose:o}){const a=u(),[i,l]=Un(e.titlePage),[s,c]=Un(e.evenOdd),d=Bn({}),m=[...i?["first"]:[],"default",...s?["even"]:[]],f={first:a.headerFirst,default:s?a.headerOdd:a.headerDefault,even:a.headerEven};return Xn(Vn,{open:!0,onClose:o,title:a.headersFooters,size:"lg",footer:Jn(Gn,{children:[Xn(qn,{variant:"secondary",onClick:o,children:a.cancel}),Xn(qn,{variant:"primary",onClick:()=>{const t=(t,n)=>{const r=d.current[`${t}:${n}`];if(!r)return e[t][n];const o=r.innerHTML;return"<p><br></p>"!==o||e[t][n]?o:""},n=e=>({default:t(e,"default"),first:t(e,"first"),even:t(e,"even")});r({headers:n("headers"),footers:n("footers"),titlePage:i,evenOdd:s})},children:a.ok})]}),children:Jn("div",{className:"docs-hf",children:[Jn("div",{className:"docs-hf-options",children:[Xn(Kn,{checked:i,onChange:l,label:a.differentFirst}),Xn(Kn,{checked:s,onChange:c,label:a.differentOddEven})]}),m.map(r=>Jn("section",{className:"docs-hf-kind",children:[Xn("h4",{children:f[r]}),Xn(Zn,{label:`${a.header} · ${f[r]}`,html:e.headers[r],locked:t.headers[r],scope:n,onRef:e=>{d.current[`headers:${r}`]=e}}),Xn(Zn,{label:`${a.footer} · ${f[r]}`,html:e.footers[r],locked:t.footers[r],scope:n,onRef:e=>{d.current[`footers:${r}`]=e}})]},r))]})})}import{useState as Yn}from"react";import{Button as er,Dialog as tr,FormField as nr,Input as rr,Select as or}from"efficient-shell/ui";import{Fragment as ar,jsx as ir,jsxs as lr}from"react/jsx-runtime";var sr=e=>{const t=Number(e.replace(",","."));return""!==e.trim()&&Number.isFinite(t)?t:void 0},cr=e=>void 0===e?"":String(Math.round(100*e)/100);function dr({value:e,onApply:t,onClose:n}){const r=u(),[o,a]=Yn(cr(e.lineMultiple??1.15)),[i,l]=Yn(cr(e.before??0)),[s,c]=Yn(cr(e.after??0)),[d,m]=Yn(cr(e.indentLeft??0)),[f,p]=Yn(cr(e.indentRight??0)),[h,g]=Yn(void 0===e.firstLine||0===e.firstLine?"none":e.firstLine>0?"first":"hanging"),[w,b]=Yn(cr(void 0===e.firstLine?36:Math.abs(e.firstLine)||36)),[y,v]=Yn(""),x=e=>t=>{e(t.target.value),v("")};return lr(tr,{open:!0,onClose:n,title:r.customSpacing,size:"sm",footer:lr(ar,{children:[ir(er,{variant:"secondary",onClick:n,children:r.cancel}),ir(er,{variant:"primary",onClick:()=>{if([o,i,s,d,f,..."none"===h?[]:[w]].some(e=>void 0===sr(e)||sr(e)<0)||sr(o)<=0||sr(o)>10)return void v(r.spacingInvalid);const e=sr(w);t({lineMultiple:sr(o),before:sr(i),after:sr(s),indentLeft:sr(d),indentRight:sr(f),firstLine:"none"===h?0:"first"===h?e:-e})},children:r.ok})]}),children:[lr("div",{className:"docs-para-grid",children:[ir(nr,{label:r.lineSpacingCustom,children:ir(rr,{inputMode:"decimal",value:o,onChange:x(a)})}),ir(nr,{label:r.spacingBefore,children:ir(rr,{inputMode:"decimal",value:i,onChange:x(l)})}),ir(nr,{label:r.spacingAfter,children:ir(rr,{inputMode:"decimal",value:s,onChange:x(c)})}),ir(nr,{label:r.indentLeft,children:ir(rr,{inputMode:"decimal",value:d,onChange:x(m)})}),ir(nr,{label:r.indentRight,children:ir(rr,{inputMode:"decimal",value:f,onChange:x(p)})}),ir(nr,{label:r.indentSpecial,children:ir(or,{value:h,onChange:e=>{g(String(e)),v("")},options:[{value:"none",label:r.indentNone},{value:"first",label:r.indentFirstLine},{value:"hanging",label:r.indentHanging}]})}),"none"!==h&&ir(nr,{label:r.indentBy,children:ir(rr,{inputMode:"decimal",value:w,onChange:x(b)})})]}),y&&ir("p",{className:"docs-para-error",role:"alert",children:y})]})}import{useRef as ur}from"react";import{Fragment as mr,jsx as fr,jsxs as pr}from"react/jsx-runtime";var hr=4/3,gr={left:"center",center:"right",right:"left"};function wr({pageWidth:e,marginLeft:t,marginRight:n,zoom:r,value:o,onChange:a}){const i=u(),l=ur(null),s=r/100*hr,c=e-t-n,d=e=>(t+e)*s+"px",m=e=>{const n=l.current.getBoundingClientRect();return r=(e-n.left)/s-t,4.5*Math.round(r/4.5);var r},f=(e,t,n)=>{e.preventDefault(),e.stopPropagation();const r=e.currentTarget;r.setPointerCapture(e.pointerId);const o=l.current.getBoundingClientRect().bottom,i=e=>{const n=t(m(e.clientX),e.clientY>o+12);n&&a(n)},s=e=>{r.removeEventListener("pointermove",i),r.removeEventListener("pointerup",s);const t=n?.(m(e.clientX),e.clientY>o+12);t&&a(t)};r.addEventListener("pointermove",i),r.addEventListener("pointerup",s)},p=(e,t,n)=>Math.min(Math.max(e,t),n),h=o;return pr("div",{className:"docs-ruler",style:{width:e*s+"px"},"aria-label":i.ruler,title:h?i.tabStopHint:void 0,ref:l,onPointerDown:e=>{if(!h||0!==e.button)return;const t=m(e.clientX);t<=0||t>=c||a({...h,tabs:[...h.tabs.filter(e=>Math.abs(e.pos-t)>1),{pos:t,align:"left"}].sort((e,t)=>e.pos-t.pos)})},children:[fr("div",{className:"docs-ruler-margin",style:{left:0,width:d(0)}}),fr("div",{className:"docs-ruler-margin",style:{right:0,width:n*s+"px"}}),Array.from({length:Math.floor(c/36)+1},(e,t)=>fr("span",{className:"docs-ruler-tick",style:{left:d(36*t)},children:t?t/2:""},t)),h&&pr(mr,{children:[fr("button",{type:"button",className:"docs-ruler-first","aria-label":i.indentFirstLine,style:{left:d(h.indentLeft+h.firstLine)},onPointerDown:e=>f(e,e=>({...h,firstLine:p(e,0,c-18)-h.indentLeft}))}),fr("button",{type:"button",className:"docs-ruler-left","aria-label":i.indentLeft,style:{left:d(h.indentLeft)},onPointerDown:e=>f(e,e=>{const t=p(e,0,c-h.indentRight-18);return{...h,indentLeft:t}})}),fr("button",{type:"button",className:"docs-ruler-right","aria-label":i.indentRight,style:{left:d(c-h.indentRight)},onPointerDown:e=>f(e,e=>({...h,indentRight:p(c-e,0,c-h.indentLeft-18)}))}),h.tabs.map((e,t)=>fr("button",{type:"button",className:`docs-ruler-tab docs-ruler-tab-${e.align}`,"aria-label":`${i.tabStop} ${Math.round(e.pos)}pt`,style:{left:d(e.pos)},onDoubleClick:e=>{e.stopPropagation(),a({...h,tabs:h.tabs.map((e,n)=>n===t?{...e,align:gr[e.align]}:e)})},onPointerDown:e=>f(e,e=>({...h,tabs:h.tabs.map((n,r)=>r===t?{...n,pos:p(e,0,c)}:n)}),(e,n)=>({...h,tabs:n?h.tabs.filter((e,n)=>n!==t):h.tabs.map((n,r)=>r===t?{...n,pos:p(e,0,c)}:n).sort((e,t)=>e.pos-t.pos)}))},`${e.pos}-${t}`))]})]})}function br(e,t,n){const r=new Blob([e],{type:n}),o=URL.createObjectURL(r),a=document.createElement("a");a.href=o,a.download=t,a.click(),setTimeout(()=>URL.revokeObjectURL(o),1e4)}import{useEffect as yr,useRef as vr}from"react";import{Icon as xr}from"efficient-shell/icons";import{Button as kr,Checkbox as Cr,IconButton as Sr,Input as Nr}from"efficient-shell/ui";import{jsx as Ar,jsxs as $r}from"react/jsx-runtime";function Lr({query:e,replacement:t,matchCase:n,current:r,total:o,onQuery:a,onReplacement:i,onMatchCase:l,onStep:s,onReplace:c,onReplaceAll:d,onClose:m}){const f=u(),p=vr(null);return yr(()=>{p.current?.focus(),p.current?.select()},[]),$r("div",{className:"flex shrink-0 flex-wrap items-center gap-1 border-b border-line bg-surface-sunken px-2 py-1",children:[Ar("div",{className:"w-40",children:Ar(Nr,{ref:p,size:"sm","aria-label":f.find,placeholder:f.find,value:e,onChange:e=>a(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),s(!e.shiftKey))}})}),Ar("span",{className:"min-w-14 text-xs text-ink-muted","aria-live":"polite",children:e?o?f.matchCount(r+1,o):f.noMatches:""}),Ar(Sr,{size:"sm",variant:"ghost","aria-label":f.previousMatch,title:f.previousMatch,onClick:()=>s(!1),children:Ar(xr,{name:"chevron-up",size:16})}),Ar(Sr,{size:"sm",variant:"ghost","aria-label":f.nextMatch,title:f.nextMatch,onClick:()=>s(!0),children:Ar(xr,{name:"chevron-down",size:16})}),Ar("div",{className:"ml-1 w-40",children:Ar(Nr,{size:"sm","aria-label":f.replaceWith,placeholder:f.replaceWith,value:t,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),c())}})}),Ar(kr,{size:"sm",variant:"secondary",onClick:c,children:f.replace}),Ar(kr,{size:"sm",variant:"secondary",onClick:d,children:f.replaceAll}),$r("label",{className:"ml-1 flex items-center gap-1 text-xs text-ink-muted",children:[Ar(Cr,{checked:n,onChange:l,"aria-label":f.matchCase}),f.matchCase]}),Ar(Sr,{className:"ml-auto",size:"sm",variant:"ghost","aria-label":f.closeFind,title:f.closeFind,onClick:m,children:Ar(xr,{name:"close",size:16})})]})}var Tr=class{past=[];future=[];get canUndo(){return this.past.length>0}get canRedo(){return this.future.length>0}record(e){if(this.past[this.past.length-1]?.html===e.html)return;this.past.push(e),this.future=[];let t=this.past.reduce((e,t)=>e+t.html.length,0);for(;this.past.length>1&&(this.past.length>200||t>67108864);)t-=this.past.shift().html.length}undo(e){const t=this.past.pop();return t?(this.future.push(e),t):null}redo(e){const t=this.future.pop();return t?(this.past.push(e),t):null}};function Pr(e,t,n){const r=[];let o=t;for(;o&&o!==e;){const e=o.parentNode;if(!e)return null;r.unshift(Array.prototype.indexOf.call(e.childNodes,o)),o=e}return o===e?{path:r,offset:n}:null}function Mr(e,t){let n=e;for(const e of t.path){const t=n.childNodes[e];if(!t)return null;n=t}const r=3===n.nodeType?(n.nodeValue??"").length:n.childNodes.length;return{node:n,offset:Math.min(t.offset,r)}}function Er(e){return Array.from(e.querySelectorAll("h1,h2,h3,h4,h5,h6")).filter(e=>!e.closest("[data-hidden]")&&""!==(e.textContent??"").trim())}var Rr=["#000000","#404040","#7f7f7f","#c00000","#ff0000","#ffc000","#00b050","#0070c0","#002060","#7030a0"],zr=["#ffff00","#00ff00","#00ffff","#ff00ff","#ff0000","#c0c0c0"],Fr=["#d9e2f3","#e2efd9","#fff2cc","#fbe4d5","#ededed","#bfbfbf"];function Or(e){if(/^#[0-9a-f]{6}$/i.test(e))return e.toLowerCase();const t=/^rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)/i.exec(e);return t?`#${[t[1],t[2],t[3]].map(e=>Number(e).toString(16).padStart(2,"0")).join("")}`:""}import{useState as Ir}from"react";import{Button as Dr,Dialog as Hr,FormField as jr,Select as Br}from"efficient-shell/ui";import{Fragment as Ur,jsx as Wr,jsxs as qr}from"react/jsx-runtime";function Kr({value:e,onApply:t,onClose:n}){const r=u(),[o,a]=Ir(e.page),i=o.width>o.height,l=O(o),s=F(o),c={a4:"A4",a3:"A3",a5:"A5",letter:r.paperLetter,legal:r.paperLegal},d={normal:r.marginsNormal,narrow:r.marginsNarrow,moderate:r.marginsModerate,wide:r.marginsWide},m={value:"custom",label:r.custom};return Wr(Hr,{open:!0,onClose:n,title:r.pageSetup,size:"sm",footer:qr(Ur,{children:[Wr(Dr,{variant:"secondary",onClick:n,children:r.cancel}),Wr(Dr,{variant:"primary",onClick:()=>t({page:o}),children:r.ok})]}),children:qr("div",{className:"space-y-3",children:[Wr(jr,{label:r.paperSize,children:Wr(Br,{value:l??"custom",onChange:e=>{"custom"!==e&&a(t=>Z(t,e))},options:[...l?[]:[m],...Object.keys(N).map(e=>({value:e,label:c[e]}))]})}),Wr(jr,{label:r.orientation,children:Wr(Br,{value:i?"landscape":"portrait",onChange:e=>{"landscape"===e!==i&&a(e=>({...e,width:e.height,height:e.width}))},options:[{value:"portrait",label:r.portrait},{value:"landscape",label:r.landscape}]})}),Wr(jr,{label:r.margins,children:Wr(Br,{value:s??"custom",onChange:e=>{"custom"!==e&&a(t=>J(t,e))},options:[...s?[]:[m],...Object.keys(S).map(e=>({value:e,label:d[e]}))]})})]})})}var Vr=e=>e.querySelectorAll("ul,ol").forEach(e=>e.removeAttribute("data-ilvl"));function _r(e){const t=e.previousElementSibling,n=e.parentElement;if(!t||"LI"!==t.tagName||!n)return!1;const r=t.lastElementChild;let o;var a;return a=r,"UL"===a?.tagName||"OL"===a?.tagName?o=r:(o=e.ownerDocument.createElement(n.tagName),t.appendChild(o)),o.appendChild(e),Vr(e),!0}function Gr(e){const t=e.parentElement,n=t?.parentElement;if(!t||"LI"!==n?.tagName)return!1;const r=[];for(let t=e.nextElementSibling;t;t=t.nextElementSibling)r.push(t);if(r.length){const n=e.ownerDocument.createElement(t.tagName),o=t.getAttribute("data-num-id");o&&n.setAttribute("data-num-id",o),r.forEach(e=>n.appendChild(e)),e.appendChild(n)}return n.parentElement.insertBefore(e,n.nextSibling),Vr(e),t.children.length||t.remove(),!0}var Xr=e=>Array.from(e.querySelectorAll(":scope > tbody > tr, :scope > tr, :scope > thead > tr, :scope > tfoot > tr")),Jr=(e,t)=>Math.max(1,Number(e.getAttribute(t)??1));function Zr(e){const t=Xr(e),n=t.map(()=>[]);return t.forEach((e,r)=>{let o=0;for(const a of(e=>Array.from(e.children).filter(e=>"TD"===e.tagName||"TH"===e.tagName))(e)){for(;n[r][o];)o++;const e=Jr(a,"colspan"),i=Jr(a,"rowspan");for(let l=r;l<Math.min(r+i,t.length);l++)for(let t=o;t<o+e;t++)n[l][t]=a;o+=e}}),{table:e,slots:n,cols:Math.max(0,...n.map(e=>e.length))}}function Qr(e,t){for(let n=0;n<e.slots.length;n++){const r=e.slots[n].indexOf(t);if(r>=0)return{row:n,col:r}}return null}function Yr(e){const t=e.createElement("td");return t.innerHTML="<p><br></p>",t}function eo(e,t,n){const r=Zr(e),o=Qr(r,t);if(!o)return;const a=Xr(e),i=Jr(t,"rowspan"),l=n?o.row+i:o.row,s=e.ownerDocument.createElement("tr"),c=new Set;for(let t=0;t<r.cols;t++){const n=l>0?r.slots[l-1]?.[t]:void 0,o=r.slots[l]?.[t];n&&n===o?c.has(n)||(c.add(n),n.setAttribute("rowspan",String(Jr(n,"rowspan")+1))):s.appendChild(Yr(e.ownerDocument))}const d=a[l];d?d.parentNode.insertBefore(s,d):a[a.length-1].parentNode.appendChild(s)}function to(e,t,n){const r=Zr(e),o=Qr(r,t);if(!o)return;const a=n?o.col+Jr(t,"colspan"):o.col,i=new Set;r.slots.forEach((t,n)=>{const r=a>0?t[a-1]:void 0,o=t[a];if(r&&r===o)return void(i.has(r)||(i.add(r),r.setAttribute("colspan",String(Jr(r,"colspan")+1))));if(o&&o.parentElement!==Xr(e)[n])return;const l=Xr(e)[n],s=t.slice(a).find(e=>e.parentElement===l);l.insertBefore(Yr(e.ownerDocument),s??null)}),no(e,r.cols+1,a,null)}function no(e,t,n,r){const o=e.querySelector(":scope > colgroup");if(!o)return;const a=Array.from(o.children);if(null!==r&&a[r]?.remove(),null!==n){const t=e.ownerDocument.createElement("col"),r=a[Math.min(n,a.length-1)];r?.getAttribute("style")&&t.setAttribute("style",r.getAttribute("style")),o.insertBefore(t,a[n]??null)}o.children.length!==t&&o.remove()}import{Fragment as ro,jsx as oo,jsxs as ao}from"react/jsx-runtime";var io=["Calibri","Arial","Cambria","Courier New","Georgia","Tahoma","Times New Roman","Verdana"],lo=[8,9,10,10.5,11,12,14,16,18,20,22,24,28,32,36,48,72],so=[1,1.15,1.5,2,2.5,3],co=/^[A-Za-z][A-Za-z0-9_]{0,39}$/,uo="data-docs-fonts",mo=["default","first","even"];function fo(e){const t=[...new Set(e)].filter(e=>$.includes(e));if(!t.length||"undefined"==typeof document)return;const n=document.head.querySelector(`link[${uo}]`),r=n?.getAttribute(uo)?.split("|").filter(Boolean)??[],o=[...new Set([...r,...t])].sort();if(n&&o.length===r.length)return;const a=document.createElement("link");a.rel="stylesheet",a.href=X(o),a.setAttribute(uo,o.join("|")),document.head.appendChild(a),n?.remove()}function po(e,t,n){if(!e)return"";const r=document.createElement("div");return r.innerHTML=e,r.querySelectorAll('[data-field="page"]').forEach(e=>{e.textContent=String(t)}),r.querySelectorAll('[data-field="pages"]').forEach(e=>{e.textContent=String(n)}),r.innerHTML}var ho=e=>Math.round(.75*(parseFloat(e)||0)*100)/100,go=()=>(new Date).toISOString().replace(/\.\d+Z$/,"Z"),wo=[50,75,90,100,110,125,150,200],bo="p,h1,h2,h3,h4,h5,h6,li,blockquote,pre",yo=/^(https?:|mailto:|tel:)/i,vo={bold:!1,italic:!1,underline:!1,strike:!1,sub:!1,sup:!1,ul:!1,ol:!1,align:"left",font:"",size:null,styleId:null,color:""};function xo({sessionKey:m,doc:f,filename:p,images:b,fileEntries:y,title:x,startsDirty:k,dirty:C,onDirty:S,onOpenFile:N,onNewImageUrl:A,onClose:L,stored:T,onReload:P}){const M=u(),E=Fe(),R=pe().replace(/[^a-zA-Z0-9]/g,""),z=ge(null),F=ge(null),D=ge(null),H=ge(new Tr),B=ge(null),U=ge(null),W=ge(null),q=ge(!!k),V=ge(0),X=ge(()=>{}),J=ge(null),Z=ge(0),Q=ge(T?.version??""),Y=ge(null),[ee,te]=we({page:f.page}),[ne,re]=we(()=>({headers:{default:f.headers.default.html,first:f.headers.first.html,even:f.headers.even.html},footers:{default:f.footers.default.html,first:f.footers.first.html,even:f.footers.even.html},titlePage:f.titlePage,evenOdd:f.evenOdd})),[oe,ae]=we(!1),[ie,le]=we(f.columns),[se,ce]=we(!1),de=ge(new Map),[ue,Oe]=we(""),[Ie,De]=we(null),[He,je]=we(null),Be=ge(null),We=ge(null),[qe,Ke]=we(!1),[Ve,_e]=we([]),[,Ge]=we(0),Xe=ge(null),[Je,Ze]=we(null),Ye=d(),et=T?.id??null,rt=Ye.currentUser,[ot,ct]=we("edit"),[ut,mt]=we("editing"),ft=ge(ut);ft.current=ut;const[pt,ht]=we("document"),[gt,wt]=we([]),[bt,yt]=we(null),[vt,xt]=we(null),[kt,Ct]=we([]),[St,At]=we([]),[$t,Lt]=we(()=>new Map),[Tt,Pt]=we([]),[Mt,Et]=we([]),[Rt,zt]=we(null),[Ft,Ut]=we(0),Wt=ge(null),qt=ge(null),Vt=ge(null),_t=ge(null),Gt=ge(null),Xt=ge(""),Jt=ge(0),Zt=ge(null),Qt="edit"===ot,Yt="view"!==ot,en=me(()=>({name:rt?.name??M.untitled,date:go}),[rt?.name,M.untitled]),tn=ge(()=>{}),nn=ge(()=>{}),rn=ge(()=>{}),on=ge(()=>{}),[an,ln]=we(vo),[sn,cn]=we({undo:!1,redo:!1}),[dn,un]=we({words:0,pageNow:1}),[mn,fn]=we([0]),[pn,hn]=we([]),[gn,wn]=we(!1),[bn,yn]=we(100),[vn,xn]=we(!1),[kn,Cn]=we(!0),[Sn,Nn]=we(!1),[An,$n]=we({rows:0,cols:0}),[Ln,Tn]=we(null),[Pn,Mn]=we(null),[En,Rn]=we(!1),[zn,Fn]=we(""),[On,In]=we(""),[Dn,Hn]=we(!1),[Bn,Un]=we(0),[Wn,qn]=we(0),Kn=ge([]),Vn=(ee.page.width-ee.page.left-ee.page.right)/20,_n=e=>!!e&&!!F.current?.contains(e),Gn=me(()=>{const e=F.current,t=document.getSelection();if(!(e&&t?.anchorNode&&t.focusNode&&_n(t.anchorNode))){const t=B.current;if(!e||!t)return null;const n=Pr(e,t.startContainer,t.startOffset),r=Pr(e,t.endContainer,t.endOffset);return n&&r?{anchor:n,focus:r}:null}const n=Pr(e,t.anchorNode,t.anchorOffset),r=Pr(e,t.focusNode,t.focusOffset);return n&&r?{anchor:n,focus:r}:null},[]),Xn=me(e=>{const t=F.current,n=document.getSelection();if(!t||!n||!e)return;const r=Mr(t,e.anchor),o=Mr(t,e.focus);r&&o&&n.setBaseAndExtent(r.node,r.offset,o.node,o.offset)},[]),Jn=me(e=>{const t=F.current;if(!t)return;const n=document.getSelection(),r=!e&&!!n&&_n(n.anchorNode);if(document.activeElement!==t&&t.focus({preventScroll:!0}),r&&n?.rangeCount)return void(B.current=n.getRangeAt(0).cloneRange());const o=e??B.current;n&&o&&(n.removeAllRanges(),n.addRange(o),B.current=o.cloneRange())},[]),Zn=me(()=>{const e=F.current,t=B.current;if(!e||!t)return[];const n=Array.from(e.querySelectorAll(bo)).filter(e=>!e.closest("[data-locked]"));var r;return(t.collapsed?[(r=t.startContainer,(1===r.nodeType?r:r.parentElement)?.closest(bo))].filter(Boolean):n.filter(e=>t.intersectsNode(e))).filter(e=>_n(e)&&!e.closest("[data-locked]"))},[]),Yn=me(()=>{cancelAnimationFrame(V.current),V.current=requestAnimationFrame(()=>{const n=F.current;if(!n)return;const o=n.getBoundingClientRect().height/(n.offsetHeight||1)||1,i=n.getBoundingClientRect().top+ee.page.top/20*(4/3)*o,l=(ee.page.height-ee.page.top-ee.page.bottom)/20*(4/3),s=a(r(n,i,o),l);fn(e=>e.length===s.length&&e.every((e,t)=>e===s[t])?e:s);const c=document.getSelection();let d=1;if(c?.rangeCount&&_n(c.anchorNode)){const e=c.getRangeAt(0).getClientRects()[0]??c.anchorNode?.getBoundingClientRect?.();if(e){const t=(e.top-i)/o;for(let e=0;e<s.length;e++)s[e]<=t+1&&(d=e+1)}}un({words:e(t(n)),pageNow:d});const u=[...new Set(Array.from(n.querySelectorAll("[data-note]")).map(e=>e.getAttribute("data-note")))];_e(e=>e.length===u.length&&e.every((e,t)=>e===u[t])?e:u),ce(!!n.querySelector(":scope > [data-section]")),Ct(function(e){const t=Array.from(e.querySelectorAll("ins,del")).filter(e=>!e.parentElement?.closest("ins,del")),n=[];for(let e=0;e<t.length;e++){const r=t[e],o=t[e+1],a=r.getAttribute("data-author")??"";"DEL"!==r.tagName||"INS"!==o?.tagName||o.getAttribute("data-author")!==a||r.nextSibling!==o?n.push({els:[r],author:a,date:r.getAttribute("data-date")??"",kind:"INS"===r.tagName?"insert":"delete",removed:"DEL"===r.tagName?r.textContent??"":"",added:"INS"===r.tagName?r.textContent??"":""}):(n.push({els:[r,o],author:a,date:r.getAttribute("data-date")??"",kind:"replace",removed:r.textContent??"",added:o.textContent??""}),e++)}return n}(n));const m=Array.from(n.querySelectorAll("[data-pid]")).map(e=>e.getAttribute("data-pid"));At(e=>e.length===m.length&&e.every((e,t)=>e===m[t])?e:m),tn.current();const f=function(e){return Er(e).map(e=>({level:Number(e.tagName[1]),text:(e.textContent??"").trim().replace(/\s+/g," ")}))}(n);hn(e=>{return n=f,(t=e).length===n.length&&t.every((e,t)=>e.level===n[t].level&&e.text===n[t].text)?e:f;var t,n})})},[ee.page]),er=me(()=>{const e=document.getSelection();if(!e?.anchorNode||!_n(e.anchorNode))return;const t=1===e.anchorNode.nodeType?e.anchorNode:e.anchorNode.parentElement;if(!t)return;const n=getComputedStyle(t),r=t.closest(bo),o=e=>{try{return document.queryCommandState(e)}catch{return!1}},a=n.textAlign,i=.75*parseFloat(n.fontSize);if(ln({bold:o("bold"),italic:o("italic"),underline:o("underline"),strike:o("strikeThrough"),sub:o("subscript"),sup:o("superscript"),ul:o("insertUnorderedList"),ol:o("insertOrderedList"),align:"center"===a||"right"===a||"justify"===a?a:"left",font:n.fontFamily.split(",")[0].replace(/["']/g,"").trim(),size:i?Math.round(2*i)/2:null,styleId:r?.getAttribute("data-pstyle")??null,color:Or(n.color)}),r&&!r.closest("[data-locked]")){const e=getComputedStyle(r),t="LI"===r.tagName;je({indentLeft:t?0:ho(e.marginLeft),indentRight:ho(e.marginRight),firstLine:t?0:ho(e.textIndent),tabs:j(r.getAttribute("data-tabs"))})}else je(null)},[]),tr=async()=>{const e=J.current;if(!e)throw new Error("No page");if(!q.current&&ee.page===f.page&&f.source)return f.source;const t=Z.current,n=await jn(f,e,{page:ee.page,headers:ne.headers,footers:ne.footers,titlePage:ne.titlePage,evenOdd:ne.evenOdd,columns:ie,styleEdits:de.current,images:b});return q.current&&Z.current===t&&(f.source=n,q.current=!1,te(e=>({...e,page:f.page}))),n},nr=ve(),rr=ye({debounceMs:1500,maxWaitMs:4e3,save:async()=>{if(!T)return;const e=F.current?at(F.current):null;try{Q.current=await T.store.save(T.id,await tr(),Q.current)}catch(e){if(!(e instanceof c))throw e;await vr(!1),Q.current=await T.store.save(T.id,await tr(),Q.current)}F.current&&(Wt.current=at(F.current)??e),Ut(e=>e+1)},onFailure:(e,t)=>{e instanceof c?(rr.stop(),wn(!0)):0===t&&ze.error(M.saveFailed)}}),{push:or,flush:ar}=rr,ir=!!T,lr=rr.state.pending;fe(()=>{ir&&S(lr||gn)},[gn,ir,S,lr]),fe(()=>()=>{ar()},[ar]);const sr=me(()=>{q.current=!0,Z.current+=1,S(!0),ir&&or(Z.current),Yn(),cn({undo:H.current.canUndo,redo:H.current.canRedo})},[ir,Yn,S,or]),cr=me(()=>({html:F.current?.innerHTML??"",caret:Gn()}),[Gn]),ur=()=>{U.current&&clearTimeout(U.current),U.current=null},mr=me(e=>{e&&F.current&&(F.current.innerHTML=e.html,F.current.focus({preventScroll:!0}),Xn(e.caret),ur(),sr(),er())},[Xn,sr,er]),fr=me(()=>mr(H.current.undo(cr())),[mr,cr]),pr=me(()=>mr(H.current.redo(cr())),[mr,cr]),hr=me(e=>{Jn(),ur(),H.current.record(cr()),e(),sr(),er()},[sr,er,Jn,cr]),gr=me((e,t)=>{"editing"===ft.current&&hr(()=>{document.execCommand(e,!1,t)})},[hr]),yr=e=>hr(()=>{document.execCommand(e);const t=F.current;if(!t)return;const n=document.getSelection(),r=n?.anchorNode??null,o=n?.anchorOffset??0;let a=!1;t.querySelectorAll("p > ul, p > ol").forEach(e=>{const t=e.parentElement;Array.from(t.childNodes).some(t=>t!==e&&(1===t.nodeType||(t.nodeValue??"").trim()))||(t.replaceWith(e),a=!0)}),a&&r&&n?.collapse(r,o)});fe(()=>{const e=F.current;if(!e)return;J.current=e,e.innerHTML=f.html,fo($.filter(e=>f.html.includes(e)||f.css.includes(e)||f.defaultFont===e));const t=tt(e);Wt.current=at(e);try{document.execCommand("defaultParagraphSeparator",!1,"p"),document.execCommand("styleWithCSS",!1,"true")}catch{}e.focus({preventScroll:!0});const n=e.querySelector(bo);n&&document.getSelection()?.collapse(n,0),Yn(),t&&T&&(q.current=!0,Z.current+=1,or(Z.current));const r=t=>"historyUndo"===t.inputType?(t.preventDefault(),void fr()):"historyRedo"===t.inputType?(t.preventDefault(),void pr()):void("viewing"!==ft.current?"suggesting"!==ft.current?(U.current?clearTimeout(U.current):H.current.record({html:e.innerHTML,caret:Gn()}),U.current=setTimeout(()=>{U.current=null},600)):on.current(t):t.preventDefault()),o=()=>{tt(e),(()=>{const t=W.current;e.querySelectorAll('font[size="7"]').forEach(e=>{const n=document.createElement("span");for(n.setAttribute("style",`font-size:${t??11}pt`);e.firstChild;)n.appendChild(e.firstChild);e.replaceWith(n),3===n.lastChild?.nodeType&&document.getSelection()?.collapse(n.lastChild,(n.lastChild.nodeValue??"").length)})})(),sr(),er()},a=()=>{const e=document.getSelection();e?.rangeCount&&_n(e.anchorNode)&&(B.current=e.getRangeAt(0).cloneRange(),er(),Yn(),nn.current(),rn.current())};e.addEventListener("beforeinput",r),e.addEventListener("input",o),document.addEventListener("selectionchange",a);const i=new ResizeObserver(()=>Yn());return i.observe(e),()=>{e.removeEventListener("beforeinput",r),e.removeEventListener("input",o),document.removeEventListener("selectionchange",a),i.disconnect(),cancelAnimationFrame(V.current),ur(),Y.current&&clearTimeout(Y.current)}},[]),fe(()=>{Yn()},[Yn]),fe(()=>{const e=Xe.current;e&&Ve.includes(e)&&(Xe.current=null,z.current?.querySelector(`input[data-note-input="${e}"]`)?.focus())},[Ve]),fe(()=>{k&&S(!0)},[]);const vr=me(async(e=!0)=>{if(Vt.current)return Vt.current;const t=(async()=>{const t=F.current;if(!T||!t)return;const n=await T.store.get(T.id);if(!n.bytes||n.version===Q.current)return;const r=await w(n.bytes),o=document.createElement("div");o.innerHTML=r.html;const a=document.getSelection(),i=a?.anchorNode&&t.contains(a.anchorNode)?lt(t,a.anchorNode,a.anchorOffset):null,l=Wt.current??at(o),s=(e=>t=>{const n=t.cloneNode(!0),r=(e,t,n,r)=>{const o=e.getAttribute(t);if(!o||!n.has(o))return;const a="m"+ ++Jt.current;r.set(a,n.get(o)),e.setAttribute(t,a)};for(const t of[n,...Array.from(n.querySelectorAll("*"))])r(t,"data-docx",e.blocks,f.blocks),r(t,"data-r",e.runs,f.runs),r(t,"data-raw",e.raw,f.raw);return n})(r),c=new Set(Array.from(o.children).map(nt)),d=it(t,o,l,s);for(const e of Array.from(t.children))"UL"!==e.tagName&&"OL"!==e.tagName||c.has(nt(e))||e.querySelectorAll("[data-num-id]").forEach(e=>e.removeAttribute("data-num-id")),"UL"!==e.tagName&&"OL"!==e.tagName||c.has(nt(e))||e.removeAttribute("data-num-id");f.parts=r.parts,f.source=null,f.insertedMedia=new Map,f.css=r.css,f.styles=r.styles;for(const[e,t]of r.footnotes){void 0!==f.footnotes.get(e)?.text&&f.footnotes.get(e)?.text!==f.footnotesRead?.get(e)||f.footnotes.set(e,t)}f.footnotesRead=r.footnotesRead;const u=e=>{const t=document.createElement("div");return t.innerHTML=e,t.replaceChildren(...Array.from(t.children).map(s)),t.innerHTML};re(e=>{if(!(mo.every(t=>e.headers[t]===f.headers[t].html&&e.footers[t]===f.footers[t].html)&&e.titlePage===f.titlePage&&e.evenOdd===f.evenOdd))return e;for(const e of mo)f.headers[e]={...r.headers[e],html:u(r.headers[e].html)},f.footers[e]={...r.footers[e],html:u(r.footers[e].html)};return f.titlePage=r.titlePage,f.evenOdd=r.evenOdd,{headers:{default:f.headers.default.html,first:f.headers.first.html,even:f.headers.even.html},footers:{default:f.footers.default.html,first:f.footers.first.html,even:f.footers.even.html},titlePage:r.titlePage,evenOdd:r.evenOdd}}),te(e=>e.page===f.page?{page:r.page}:e),ee.page===f.page&&(f.page=r.page),le(e=>e===f.columns?r.columns:e),Q.current=n.version,Wt.current=at(o),H.current=new Tr,cn({undo:!1,redo:!1}),tt(t);const m=i?st(t,i):null;m&&document.activeElement===t&&document.getSelection()?.collapse(m.node,m.offset),d.overwritten.length&&Et(e=>[...e,...d.overwritten.map(e=>({...e,by:Xt.current}))]),wn(!1),Ut(e=>e+1),e&&d.ahead&&(q.current=!0,Z.current+=1,or(Z.current)),Yn()})();Vt.current=t;try{await t}finally{Vt.current=null}},[T,f,Yn,ee.page]),xr=me(()=>{_t.current&&clearTimeout(_t.current),_t.current=setTimeout(()=>{_t.current=null,rr.state.saving||Vt.current?xr():vr().catch(()=>ze.error(M.openFailed))},300)},[vr]);fe(()=>{if(!et||!Ye.access)return;let e=!0;return Ye.access(et).then(t=>{e&&(ct(t),mt("edit"===t?"editing":"comment"===t?"suggesting":"viewing"))},()=>{}),()=>{e=!1}},[et,Ye]);const kr=me(()=>{et&&Ye.comments&&Ye.comments.list(et).then(wt,()=>{})},[et,Ye.comments]);fe(()=>{kr()},[kr]),fe(()=>{if(!et||!Ye.live)return;const e=Ye.live(et,e=>{if("hello"===e.event||"presence"===e.event){const{user:t,key:n,block:r,offset:o}=e.payload;Lt(e=>new Map(e).set(n,{key:n,user:t,block:r,offset:o,color:dt(t.id)})),"hello"===e.event&&nn.current()}else if("bye"===e.event)Lt(t=>{const n=new Map(t);return n.delete(e.payload.key),n});else if("saved"===e.event){if(e.payload.by===rt?.id||e.payload.version===Q.current)return;Xt.current=[...Cr.current.values()].find(t=>t.user.id===e.payload.by)?.user.name??"",xr()}else"comments"===e.event&&e.payload.by!==rt?.id&&kr()});qt.current=e;const t=Sr();return e.send({type:"hello",block:t?.block??null,offset:t?.offset??null}),()=>{qt.current=null,e.close()}},[et,Ye.live]);const Cr=ge($t);Cr.current=$t;const Sr=()=>{const e=F.current,t=document.getSelection();return e&&t?.anchorNode&&e.contains(t.anchorNode)?lt(e,t.focusNode??t.anchorNode,t.focusOffset):null};nn.current=()=>{qt.current&&!Gt.current&&(Gt.current=setTimeout(()=>{Gt.current=null;const e=Sr();qt.current?.send({type:"presence",block:e?.block??null,offset:e?.offset??null})},250))},tn.current=()=>{const e=F.current,t=Zt.current;if(!e||!t)return;const n=bn/100,r=t.getBoundingClientRect(),o=[];for(const t of Cr.current.values()){if(!t.block||null===t.offset)continue;const a=st(e,{block:t.block,offset:t.offset});if(!a)continue;const i=document.createRange();try{i.setStart(a.node,a.offset)}catch{continue}i.collapse(!0);const l=i.getClientRects()[0]??(1===a.node.nodeType?a.node.getBoundingClientRect():a.node.parentElement?.getBoundingClientRect());l&&o.push({key:t.key,name:t.user.name,color:t.color,x:(l.left-r.left)/n,y:(l.top-r.top)/n,h:(l.height||16)/n})}Pt(e=>JSON.stringify(e)===JSON.stringify(o)?e:o)},fe(()=>{tn.current()},[$t,bn]),on.current=e=>{const t=F.current,n=document.getSelection();if(!t||!n?.rangeCount)return;const r=e.inputType;if("insertParagraph"===r||"insertLineBreak"===r||"insertCompositionText"===r)return;e.preventDefault();const o=en();if(H.current.record(cr()),r.startsWith("insert")){const r=e.data??e.dataTransfer?.getData("text/plain")??"";if(!r)return;let a={node:n.anchorNode,offset:n.anchorOffset};if(!n.isCollapsed){const e=jt(t,n.getRangeAt(0),o),r=e?1===e.node.nodeType?e.node:e.node.parentElement:null;let i=r?.closest("del");for(;"DEL"===i?.nextElementSibling?.tagName&&i.nextSibling===i.nextElementSibling;)i=i.nextElementSibling;i?a={node:i.parentNode,offset:Array.prototype.indexOf.call(i.parentNode.childNodes,i)+1}:e&&(a=e)}const i=function(e,t,n,r){let{node:o,offset:a}=t;const i=Dt(o,e,"INS");if(i&&It(i,r)&&3===o.nodeType)return o.insertData(a,n),{node:o,offset:a+n.length};const l=Dt(o,e,"DEL");l&&(o=l.parentNode,a=Array.prototype.indexOf.call(o.childNodes,l)+1);const s=Ht("ins",r),c=document.createTextNode(n);if(s.appendChild(c),3===o.nodeType){const e=o.splitText(a);e.parentNode.insertBefore(s,e)}else o.insertBefore(s,o.childNodes[a]??null);return{node:c,offset:n.length}}(t,a,r,o);n.collapse(i.node,i.offset)}else if(r.startsWith("delete")){const e=r.includes("Backward");if(n.isCollapsed){const t=r.includes("Word")?"word":r.includes("Line")||r.includes("Soft")?"lineboundary":"character";n.modify("extend",e?"backward":"forward",t)}if(n.isCollapsed)return;const a=n.getRangeAt(0),i=a.endContainer,l=a.endOffset,s=jt(t,a,o);e&&s?n.collapse(s.node,s.offset):i.isConnected&&n.collapse(i,Math.min(l,3===i.nodeType?i.length:i.childNodes.length))}sr()};const Nr=(e,t)=>{et&&Ye.comments&&Ye.comments.update(et,e,t).then(t=>wt(n=>n.map(n=>n.id===e?t:n)),()=>ze.error(M.commentFailed))},Ar=me(()=>{const e=F.current;if(!e)return[];const t=[];for(const r of gt){if(r.parent||r.resolved_at||!r.quote)continue;const o=e.querySelector(`[data-pid="${r.block_id.replace(/[^0-9A-F]/g,"")}"]`),a=o?n(o,r.quote,!0)[0]:void 0;if(!a)continue;const i=document.createRange();i.setStart(a[0].node,a[0].start),i.setEnd(a[a.length-1].node,a[a.length-1].end),t.push({id:r.id,range:i})}return t},[gt]);fe(()=>{const e=globalThis.CSS?.highlights,t=globalThis.Highlight;if(!e||!t)return;const n=Ar();return e.set("docs-comment",new t(...n.map(e=>e.range))),e.set("docs-comment-active",new t(...n.filter(e=>e.id===vt).map(e=>e.range))),()=>{e.delete("docs-comment"),e.delete("docs-comment-active")}},[Ar,vt,St,dn.words]),rn.current=()=>{const e=document.getSelection();if(!e?.isCollapsed||!e.anchorNode)return;const t=Ar().find(t=>t.range.isPointInRange(e.anchorNode,e.anchorOffset));t&&(xt(t.id),Ye.comments&&ht("comments"))};const $r=e=>hr(()=>{const t=Gn(),n=e?/^heading ([1-6])$/i.exec(f.styles.find(t=>t.id===e)?.name??"")?.[1]:void 0,r=n?`H${n}`:"P";for(const t of Zn()){if("LI"===t.tagName){e?t.setAttribute("data-pstyle",e):t.removeAttribute("data-pstyle");continue}let n=t;if(t.tagName!==r){n=document.createElement(r);for(const e of Array.from(t.attributes))n.setAttribute(e.name,e.value);for(;t.firstChild;)n.appendChild(t.firstChild);t.replaceWith(n)}e?n.setAttribute("data-pstyle",e):n.removeAttribute("data-pstyle")}Xn(t)}),Ir=(e,t)=>hr(()=>{for(const n of Zn())n.style["before"===e?"marginTop":"marginBottom"]=t?"10pt":"0pt"}),Dr=()=>{const e=Zn()[0];if(!e)return{};const t=getComputedStyle(e),n=parseFloat(t.fontSize)||14.67,r=parseFloat(t.lineHeight);return{before:ho(t.marginTop),after:ho(t.marginBottom),lineMultiple:Number.isFinite(r)?Math.round(r/n*100)/100:1.15,indentLeft:"LI"===e.tagName?void 0:ho(t.marginLeft),indentRight:ho(t.marginRight),firstLine:"LI"===e.tagName?void 0:ho(t.textIndent)}},Hr=()=>{const e=We.current,t=document.getSelection();e&&t&&!t.isCollapsed&&_n(t.anchorNode)&&(We.current=null,Ke(!1),B.current=t.getRangeAt(0).cloneRange(),hr(()=>{const t=(e,t)=>{!!t!==(e=>{try{return document.queryCommandState(e)}catch{return!1}})(e)&&document.execCommand(e)};t("bold",e.run.b),t("italic",e.run.i),t("underline",e.run.u),t("strikeThrough",e.run.strike),e.run.font&&document.execCommand("fontName",!1,e.run.font),e.run.color&&document.execCommand("foreColor",!1,e.run.color),document.execCommand("hiliteColor",!1,e.run.hl||"transparent"),e.run.size&&(document.execCommand("styleWithCSS",!1,"false"),document.execCommand("fontSize",!1,"7"),document.execCommand("styleWithCSS",!1,"true"),F.current?.querySelectorAll('font[size="7"]').forEach(t=>{const n=document.createElement("span");for(n.setAttribute("style",`font-size:${e.run.size}pt`);t.firstChild;)n.appendChild(t.firstChild);t.replaceWith(n)}));for(const t of Zn())"LI"!==t.tagName&&(e.styleId?t.setAttribute("data-pstyle",e.styleId):t.removeAttribute("data-pstyle"))}))},jr=e=>{fo([e]),gr("fontName",e)},Br=e=>hr(()=>{const t=F.current,n=Zn()[0];if(!t||!n)return;const r=Array.from(t.children).find(e=>e.contains(n));if(!r)return;r.setAttribute("data-section",e);const o=document.createElement("p");o.innerHTML="<br>",r.after(o),document.getSelection()?.collapse(o,0)}),Ur=e=>{let t=e.getAttribute("data-bm");return t||(t=`_Toc${Math.floor(1e8+899999999*Math.random())}`,e.setAttribute("data-bm",t)),t},Wr=()=>{const e=F.current;if(!e)return"";const t=e.getBoundingClientRect().height/(e.offsetHeight||1)||1,n=e.getBoundingClientRect().top+ee.page.top/20*(4/3)*t;return Er(e).filter(e=>Number(e.tagName[1])<=3&&!e.closest("[data-toc]")).map(e=>{const r=(e.getBoundingClientRect().top-n)/t;let o=1;for(let e=0;e<mn.length;e++)mn[e]<=r+1&&(o=e+1);return v(Number(e.tagName[1]),Ur(e),(e.textContent??"").trim(),String(o))}).join("")},qr=()=>{const e=[...f.footnotes.keys(),...Ve].map(Number).filter(Number.isFinite),t=String(Math.max(0,...e)+1);f.footnotes.set(t,{text:"",editable:!0}),Xe.current=t,gr("insertHTML",`<span data-kind="note" data-note="${t}" contenteditable="false"></span>`)},Vr=()=>Array.from(F.current?.querySelectorAll("[data-bookmark]")??[]).map(e=>e.getAttribute("data-bookmark")),uo=(e,t)=>{Jn();const n=B.current;if(n&&!n.collapsed)gr("createLink",`#${e}`);else{const n=document.createElement("a");n.href=`#${e}`,n.textContent=t,gr("insertHTML",n.outerHTML)}},xo=e=>{const t=F.current;return t&&/^[A-Za-z0-9_]+$/.test(e)?t.querySelector(`[data-bm="${e}"],[data-bookmark="${e}"],[data-toc-anchor="${e}"]`):null},Co=e=>hr(()=>{const t=Zn(),n=t.filter(e=>"LI"===e.tagName);if(n.length){const t=document.getSelection(),r=t?.anchorNode??null,o=t?.anchorOffset??0;for(const t of e?n:[...n].reverse())e?_r(t):Gr(t);return void(r&&t?.collapse(r,o))}for(const n of t){const t=parseFloat(n.style.marginLeft)||0,r=Math.max(0,t+(e?36:-36));n.style.marginLeft=r?`${r}pt`:""}}),So=e=>gr({left:"justifyLeft",center:"justifyCenter",right:"justifyRight",justify:"justifyFull"}[e]),No=async e=>{for(const t of e){if(!t.type.startsWith("image/"))continue;const e=new Uint8Array(await t.arrayBuffer()),n=URL.createObjectURL(new Blob([e],{type:t.type}));A(n),b.set(n,{bytes:e,mime:t.type});const r=new Image;r.src=n,await r.decode().catch(()=>{});const o=.75*r.naturalWidth,a=Math.min(o||Vn,Vn),i=o?a*(r.naturalHeight/r.naturalWidth):0;gr("insertHTML",`<img src="${n}" alt="" style="width:${Math.round(100*a)/100}pt${i?`;height:${Math.round(100*i)/100}pt`:""}">`)}},Ao=async()=>{Jn();const e=B.current?.cloneRange()??null,t=e?.startContainer?1===e.startContainer.nodeType?e.startContainer:e.startContainer.parentElement:null,n=t?.closest("a")??null,r=await Ee({title:M.link,message:M.linkPrompt,placeholder:"https://example.com",defaultValue:n?.getAttribute("href")??"",confirmLabel:M.ok,cancelLabel:M.cancel,allowEmpty:!0});if(await new Promise(e=>setTimeout(e,0)),Jn(e),null===r)return;const o=r.trim();if(!o)return void(n&&gr("unlink"));const a=/^[a-z][a-z0-9+.-]*:/i.test(o)?o:`https://${o}`;if(yo.test(a))if(n)hr(()=>{n.setAttribute("href",a)});else if(e?.collapsed){const e=document.createElement("a");e.href=a,e.textContent=o,gr("insertHTML",e.outerHTML)}else gr("createLink",a);else ze.error(M.linkInvalid)},$o=()=>gr("insertHTML",'<span data-page-break="" contenteditable="false"></span>'),Lo=(e,t)=>{Nn(!1);const n=function(e,t,n,r){const o=e.createElement("table"),a=e.createElement("colgroup");for(let t=0;t<n;t++){const t=e.createElement("col");t.setAttribute("style",`width:${Math.round(r/n*100)/100}pt`),a.appendChild(t)}o.appendChild(a);const i=e.createElement("tbody");for(let r=0;r<t;r++){const t=e.createElement("tr");for(let r=0;r<n;r++)t.appendChild(Yr(e));i.appendChild(t)}return o.appendChild(i),o}(document,e,t,Vn);n.setAttribute("data-new",""),gr("insertHTML",`${n.outerHTML}<p><br></p>`);const r=F.current?.querySelector("table[data-new]");if(r){r.removeAttribute("data-new");const e=r.querySelector("td p");e&&document.getSelection()?.collapse(e,0)}};X.current=e=>{No(e)};const To=e=>{if(!Ln)return;const t=Ln.el;hr(()=>{const n=.75*t.naturalWidth,r=null===e?n:Vn*e,o=t.naturalWidth?t.naturalHeight/t.naturalWidth:.75;t.removeAttribute("width"),t.removeAttribute("height"),t.style.width=Math.round(100*r)/100+"pt",t.style.height=Math.round(r*o*100)/100+"pt"}),Tn(null)},Po=me((e,t)=>{const n=Kn.current,r=e=>{const t=document.createRange();return t.setStart(e[0].node,e[0].start),t.setEnd(e[e.length-1].node,e[e.length-1].end),t},o=globalThis.CSS?.highlights,a=globalThis.Highlight;o&&a&&(o.set("docs-find",new a(...n.map(r))),o.set("docs-find-current",new a(...n[e]?[r(n[e])]:[]))),t&&n[e]&&n[e][0].node.parentElement?.scrollIntoView({block:"center"})},[]),Mo=()=>{const e=globalThis.CSS?.highlights;e?.delete("docs-find"),e?.delete("docs-find-current")},Eo=me((e,t,r)=>{const o=F.current,a=o?n(o,e,t):[];Kn.current=a,qn(a.length);const i=a.length?Math.min(r,a.length-1):0;Un(i),Po(i,!0)},[Po]),Ro=me(()=>{const e=Kn.current[Bn];Rn(!1),Mo();const t=F.current;t?.focus({preventScroll:!0}),e&&document.getSelection()?.setBaseAndExtent(e[0].node,e[0].start,e[e.length-1].node,e[e.length-1].end),Kn.current=[]},[Bn]),zo=()=>{const e=document.getSelection(),t=e&&_n(e.anchorNode)?e.toString():"";Rn(!0);const n=t&&!t.includes("\n")?t:zn;Fn(n),setTimeout(()=>Eo(n,Dn,0),0)},Fo=ge(Ro);Fo.current=Ro;const Oo=ge(En);Oo.current=En,fe(()=>Re(()=>!(!Oo.current||!z.current?.contains(document.activeElement))&&(Fo.current(),!0)),[]),fe(()=>()=>Mo(),[]),fe(()=>{const e=e=>{const{key:t,files:n}=e.detail;t===m&&X.current(n)};return window.addEventListener("docs-insert-images",e),()=>window.removeEventListener("docs-insert-images",e)},[m]);const Io=T?p:(e=>e.replace(/\.[^.]+$/,"")||e)(p),Do=`${Io}.docx`,Ho=async()=>{try{const e=Z.current;br(await tr(),Do,"application/vnd.openxmlformats-officedocument.wordprocessingml.document"),T||Z.current!==e||S(!1)}catch{ze.error(M.saveFailed)}},jo=e=>o({title:Io,html:e,doc:{css:`${f.css}\n${ue}`},scope:R,page:ee.page,header:g(ne.headers.default),footer:g(ne.footers.default)}),Bo=()=>{const e=document.createElement("iframe");e.setAttribute("aria-hidden","true"),e.style.cssText="position:fixed;width:0;height:0;border:0;left:-10px;top:-10px",document.body.appendChild(e);const t=e.contentWindow;if(!t)return void e.remove();t.document.open(),t.document.write(jo(F.current?.innerHTML??"")),t.document.close();const n=()=>{t.focus(),t.print(),setTimeout(()=>e.remove(),6e4)},r=Array.from(t.document.images).filter(e=>!e.complete);r.length?Promise.all(r.map(e=>e.decode().catch(()=>{}))).then(n):n()},Uo=y.length?[...y,{type:"divider",key:"d1"},{key:"save",label:oo(ko,{label:M.saveDocx,hint:"⌘S"}),onSelect:()=>{Ho()}}]:[],Wo=[{key:"docx",label:M.saveAsWord,onSelect:()=>{Ho()}},{key:"pdf",label:M.saveAsPdf,onSelect:Bo},{key:"html",label:M.saveAsWeb,onSelect:()=>{(async()=>{const e=document.createElement("div");e.innerHTML=F.current?.innerHTML??"";for(const t of Array.from(e.querySelectorAll("img"))){const e=b.get(t.getAttribute("src")??"");if(!e)continue;let n="";for(let t=0;t<e.bytes.length;t+=32768)n+=String.fromCharCode(...e.bytes.subarray(t,t+32768));t.setAttribute("src",`data:${e.mime};base64,${btoa(n)}`)}e.querySelectorAll("[data-hidden]").forEach(e=>e.remove()),br(jo(e.innerHTML),`${Io}.html`,"text/html")})()}},{key:"txt",label:M.saveAsText,onSelect:()=>{br(t(F.current),`${Io}.txt`,"text/plain")}}],qo=F.current?Vr():[],Ko=[{key:"table",label:M.table,onSelect:()=>Nn(!0)},{key:"image",label:M.image,onSelect:()=>D.current?.click()},{key:"link",label:oo(ko,{label:M.link,hint:"⌘K"}),onSelect:()=>{Ao()}},{type:"submenu",key:"linkHeading",label:M.linkToHeading,items:pn.length?pn.map((e,t)=>({key:`h${t}`,label:oo("span",{style:{paddingLeft:8*(e.level-1)},children:e.text}),onSelect:()=>(e=>{const t=F.current,n=t?Er(t)[e]:void 0;if(!n)return;Jn();const r=B.current?.cloneRange()??null;H.current.record(cr());const o=Ur(n);Jn(r),uo(o,(n.textContent??"").trim())})(t)})):[{type:"label",key:"none",label:M.noHeadings}]},{type:"submenu",key:"linkBookmark",label:M.linkToBookmark,items:qo.length?qo.map(e=>({key:e,label:e,onSelect:()=>uo(e,e)})):[{type:"label",key:"none",label:M.noBookmarks}]},{type:"divider",key:"d1"},{key:"toc",label:M.tableOfContents,onSelect:()=>{Jn();const e=Wr();gr("insertHTML",`<div data-toc="" contenteditable="false">${e}</div><p><br></p>`)}},{key:"footnote",label:oo(ko,{label:M.footnote,hint:"⌘⌥F"}),onSelect:qr},{key:"bookmark",label:M.bookmark,onSelect:()=>{(async()=>{Jn();const e=B.current?.cloneRange()??null,t=await Ee({title:M.bookmark,message:M.bookmarkPrompt,placeholder:"Clause_4",confirmLabel:M.ok,cancelLabel:M.cancel});if(await new Promise(e=>setTimeout(e,0)),Jn(e),null===t)return;const n=t.trim();co.test(n)?Vr().includes(n)?ze.error(M.bookmarkTaken):gr("insertHTML",`<span data-kind="mark" data-bookmark="${n}" contenteditable="false"></span>`):ze.error(M.bookmarkInvalid)})()}},{type:"submenu",key:"breaks",label:M.breakMenu,items:[{key:"page",label:oo(ko,{label:M.pageBreak,hint:"⌘↵"}),onSelect:$o},{key:"next",label:M.sectionBreakNext,onSelect:()=>Br("nextPage")},{key:"cont",label:M.sectionBreakContinuous,onSelect:()=>Br("continuous")}]},{key:"number",label:M.pageNumber,onSelect:()=>ae(!0)},{key:"line",label:M.horizontalLine,onSelect:()=>gr("insertHorizontalRule")}],Vo=(()=>{const e=F.current,t=B.current?1===B.current.startContainer.nodeType?B.current.startContainer:B.current.startContainer.parentElement:null;return e&&t?Array.from(e.children).find(e=>e.contains(t))??null:null})(),_o=[{key:"setup",label:M.pageSetup,onSelect:()=>xn(!0)},{key:"hf",label:M.headersFooters,onSelect:()=>ae(!0)},{type:"submenu",key:"cols",label:M.columns,items:[1,2,3].map(e=>({key:String(e),label:M.columnsCount(e),onSelect:()=>(e=>{const t=F.current,n=Zn()[0];if(!t)return;let r=n?Array.from(t.children).find(e=>e.contains(n))??null:null;for(;r&&!r.hasAttribute("data-section");)r=r.nextElementSibling;r?hr(()=>{e>1?r.setAttribute("data-cols",String(e)):r.removeAttribute("data-cols")}):(le(e),sr())})(e)}))},...Vo?.hasAttribute("data-section")?[{key:"unsection",label:M.removeSectionBreak,onSelect:()=>{return e=Vo,hr(()=>{e.removeAttribute("data-section"),e.removeAttribute("data-cols")});var e}}]:[]],Go={Title:M.styleTitle,"heading 1":M.styleHeading1,"heading 2":M.styleHeading2,"heading 3":M.styleHeading3,"heading 4":M.styleHeading4,"heading 5":M.styleHeading5,"heading 6":M.styleHeading6,Quote:M.styleQuote},Xo=[{key:"normal",label:M.styleNormal,onSelect:()=>$r(null)},...f.styles.map(e=>{const t=Go[e.name]??e.name;return{type:"submenu",key:e.id,label:t,items:[{key:"apply",label:M.applyStyle(t),onSelect:()=>$r(e.id)},{key:"update",label:M.updateStyle(t),onSelect:()=>((e,t)=>hr(()=>{const n=Zn()[0];if(!n)return;const r=Array.from(n.querySelectorAll("*")).find(e=>(e.textContent??"").trim()&&!e.querySelector("*"))??n,o=getComputedStyle(r),a=getComputedStyle(n),i=parseFloat(o.fontSize)||14.67,l=parseFloat(a.lineHeight),s={b:Number(o.fontWeight)>=600,i:"italic"===o.fontStyle,u:/underline/.test(o.textDecorationLine),strike:/line-through/.test(o.textDecorationLine),font:o.fontFamily.split(",")[0].replace(/["']/g,"").trim(),size:Math.round(.75*i*2)/2,color:Or(o.color)||void 0},c=a.textAlign,d={align:"center"===c||"right"===c||"justify"===c?c:"left",before:ho(a.marginTop),after:ho(a.marginBottom),...Number.isFinite(l)?{lineMultiple:Math.round(l/(parseFloat(a.fontSize)||i)*100)/100}:{}};de.current.set(e,{run:s,para:d});const u=n.style.tabSize;n.removeAttribute("style"),u&&(n.style.tabSize=u),n.querySelectorAll("[style]").forEach(e=>{for(const t of["font-family","font-size","font-weight","font-style","color","text-decoration","text-decoration-line"])e.style.removeProperty(t)}),Oe([...de.current].map(([e,t])=>`.docs-page [data-pstyle="${e.replace(/["\\]/g,"")}"]{${[K(t.run),I(t.para)].filter(Boolean).join(";")}}`).join("\n")),fo(s.font?[s.font]:[]),ze.success(M.styleUpdated(t))}))(e.id,t)}]}})],Jo=he(()=>Array.from(new Set([...f.defaultFont?[f.defaultFont]:[],...io])),[f.defaultFont]),Zo=[{type:"label",key:"word",label:M.wordFonts},...Jo.map(e=>({key:e,label:oo("span",{style:{fontFamily:`"${e}"`},children:e}),onSelect:()=>jr(e)})),{type:"label",key:"web",label:M.webFonts},...$.filter(e=>!Jo.includes(e)).map(e=>({key:e,label:oo("span",{style:{fontFamily:`"${e}"`},children:e}),onSelect:()=>jr(e)}))],Qo=lo.map(e=>({key:String(e),label:String(e),onSelect:()=>(e=>hr(()=>{W.current=e,document.execCommand("styleWithCSS",!1,"false"),document.execCommand("fontSize",!1,"7"),document.execCommand("styleWithCSS",!1,"true");const t=F.current,n=[];if(t.querySelectorAll('font[size="7"]').forEach(t=>{const r=document.createElement("span");for(r.setAttribute("style",`font-size:${e}pt`);t.firstChild;)r.appendChild(t.firstChild);t.replaceWith(r),n.push(r)}),n.length){const e=document.getSelection();e?.setBaseAndExtent(n[0],0,n[n.length-1],n[n.length-1].childNodes.length)}}))(e)})),Yo=F.current&&B.current?Dr():{},ea=[...so.map(e=>({key:String(e),label:e.toFixed(1.15===e?2:1),onSelect:()=>{return t=e,hr(()=>{for(const e of Zn())e.style.lineHeight=String(t)});var t}})),{type:"divider",key:"d1"},(Yo.before??0)>0?{key:"before",label:M.removeSpaceBefore,onSelect:()=>Ir("before",!1)}:{key:"before",label:M.addSpaceBefore,onSelect:()=>Ir("before",!0)},(Yo.after??0)>0?{key:"after",label:M.removeSpaceAfter,onSelect:()=>Ir("after",!1)}:{key:"after",label:M.addSpaceAfter,onSelect:()=>Ir("after",!0)},{type:"divider",key:"d2"},{key:"custom",label:M.customSpacing,onSelect:()=>{Jn(),De(Dr())}}],ta=e=>e.preventDefault(),na="rounded px-2 py-0.5 text-xs text-ink-muted hover:bg-line-subtle hover:text-ink",ra="inline-flex h-7 items-center gap-1 rounded px-2 text-xs text-ink-muted hover:bg-line-subtle hover:text-ink",oa=oo("div",{className:"mx-1 h-4 w-px bg-line"}),aa=(e,t,n,r={})=>oo(Ae,{"aria-label":e,title:e,size:"sm",variant:"ghost",onMouseDown:ta,onClick:n,disabled:r.disabled,...void 0!==r.pressed?{"aria-pressed":r.pressed}:{},children:t}),ia=(e,t,n,r="")=>oo(Ne,{"aria-label":e,align:"start",items:n,triggerClassName:ra,trigger:ao("span",{title:e,className:`flex items-center justify-between gap-1 ${r}`,children:[oo("span",{className:"truncate",children:t}),oo(xe,{name:"chevron-down",size:12})]})}),la=(e,t,n,r,o)=>oo($e,{triggerLabel:e,align:"start",triggerClassName:"inline-flex h-7 w-7 flex-col items-center justify-center rounded text-ink-muted hover:bg-line-subtle hover:text-ink",trigger:ao(ro,{children:[t,oo("span",{className:"h-0.5 w-4 rounded-sm",style:{background:n}})]}),children:({close:t})=>oo(Ce,{label:e,value:"",presets:r,clearable:!0,dragWrites:"end",onChange:e=>{"hiliteColor"===o?gr("hiliteColor",e||"transparent"):gr("foreColor",e||Rr[0]),ca(t=>({...t,[o]:e||("hiliteColor"===o?"var(--line)":"var(--ink)")})),t()}})}),[sa,ca]=we({foreColor:"var(--ink)",hiliteColor:"var(--line)"}),da=O(ee.page),ua=da?{a4:"A4",a3:"A3",a5:"A5",letter:M.paperLetter,legal:M.paperLegal}[da]:M.custom,ma=he(()=>{if(!f.lang)return"";try{return new Intl.DisplayNames(E?[E]:void 0,{type:"language"}).of(f.lang)??f.lang}catch{return f.lang}},[f.lang,E]),fa=ee.page.width/20,pa=ee.page.top/20,ha=mn.length,ga=ne.headers[h(1,ne.titlePage,ne.evenOdd)],wa=ne.footers[h(ha,ne.titlePage,ne.evenOdd)],ba=[`.docs-page [data-section="nextPage"]::after{content:${JSON.stringify(M.sectionBreakNext)}}`,`.docs-page [data-section="continuous"]::after{content:${JSON.stringify(M.sectionBreakContinuous)}}`,...[2,3].map(e=>`.docs-page [data-section][data-cols="${e}"]::after{content:${JSON.stringify(`${M.sectionBreakNext} · ${M.columnsCount(e)}`)}}`),`.docs-page [data-section="continuous"][data-cols]::after{content:${JSON.stringify(M.sectionBreakContinuous)}}`,`.docs-page [data-toc]:empty::before{content:${JSON.stringify(M.noHeadings)}}`,ue].join("\n").replaceAll(".docs-page",`.docs-page[data-doc="${R}"]`),ya=f.notices,va=[ya.comments&&M.noticeComments(ya.comments),ya.tracked&&M.noticeTracked(ya.tracked),ya.objects&&M.noticeObjects(ya.objects),ya.footnotes&&M.noticeFootnotes(ya.footnotes)].filter(Boolean);return ao("div",{ref:z,className:"es-editor docs-frame",onKeyDown:e=>{const t=e.metaKey||e.ctrlKey,n=e.key.toLowerCase(),r=_n(e.target),o=()=>{e.preventDefault(),e.stopPropagation()};if(t&&!e.altKey){if("s"===n)return o(),void(T?ar():Ho());if("o"===n)return o(),void N();if("p"===n)return o(),void Bo();if("f"===n)return o(),void zo();if("k"===n)return o(),void Ao()}if(t&&e.altKey&&("f"===n||"KeyF"===e.code)&&r)return o(),void qr();if(t&&!e.altKey&&r){if("z"===n&&!e.shiftKey)return o(),void fr();if("z"===n&&e.shiftKey||"y"===n)return o(),void pr();if("b"===n)return o(),void gr("bold");if("i"===n)return o(),void gr("italic");if("u"===n)return o(),void gr("underline");if("Enter"===e.key)return o(),void $o()}if(r&&"Tab"===e.key&&!t&&!e.altKey){const t=document.getSelection(),n=t?.anchorNode?1===t.anchorNode.nodeType?t.anchorNode:t.anchorNode.parentElement:null,r=n?.closest("td,th");if(r)return o(),void((e,t)=>{const n=Array.from(e.closest("table").querySelectorAll("td,th")),r=n[n.indexOf(e)+(t?1:-1)];if(r){const e=document.createRange();e.selectNodeContents(r);const t=document.getSelection();t?.removeAllRanges(),t?.addRange(e)}else t&&hr(()=>eo(e.closest("table"),e,!0))})(r,!e.shiftKey);if(n?.closest("li"))return o(),void Co(!e.shiftKey);if(!e.shiftKey)return o(),void gr("insertText","\t")}},children:[ao("style",{children:[i(f,R),ba]}),oo("input",{ref:D,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:e=>{e.target.files?.length&&No(Array.from(e.target.files)),e.target.value=""}}),oo(Qe,{onClose:L,fileMenu:Uo,name:x,saveState:T?be(rr.state,nr.save):{tone:C?"off-unsaved":"off",label:C?M.noStoreEdited:M.noStoreClean},canUndo:sn.undo,canRedo:sn.redo,onUndo:fr,onRedo:pr,extra:ao(ro,{children:[$t.size>0&&oo("span",{className:"docs-visitors",title:M.editors(new Set([...$t.values()].map(e=>e.user.id)).size),children:[...new Map([...$t.values()].map(e=>[e.user.id,e])).values()].slice(0,5).map(e=>oo("span",{className:"docs-visitor",style:{background:e.color},title:e.user.name,children:e.user.name.split(/\s+/).map(e=>e[0]).slice(0,2).join("").toUpperCase()},e.user.id))}),T&&oo(Ne,{"aria-label":M.mode,align:"end",triggerClassName:"docs-mode-trigger",trigger:ao(ro,{children:[oo(xe,{name:"viewing"===ut?"eye":"pen",size:14}),{editing:M.modeEditing,suggesting:M.modeSuggesting,viewing:M.modeViewing}[ut],oo(xe,{name:"chevron-down",size:12})]}),items:[...Qt?[{key:"editing",label:oo(ko,{label:M.modeEditing,hint:M.modeEditingHint}),onSelect:()=>mt("editing")}]:[],...Yt?[{key:"suggesting",label:oo(ko,{label:M.modeSuggesting,hint:M.modeSuggestingHint}),onSelect:()=>mt("suggesting")}]:[],{key:"viewing",label:oo(ko,{label:M.modeViewing,hint:M.modeViewingHint}),onSelect:()=>mt("viewing")}]}),Ye.comments&&Yt&&oo(Ae,{size:"sm",variant:"ghost","aria-label":M.comment,title:M.comment,onMouseDown:e=>e.preventDefault(),onClick:()=>{Jn();const e=F.current,t=B.current;if(!e||!t||t.collapsed)return void ze.info(M.commentNeedsSelection);const n=1===t.startContainer.nodeType?t.startContainer:t.startContainer.parentElement,r=n?.closest("[data-pid]");r?(yt({blockId:r.getAttribute("data-pid"),quote:t.toString().replace(/\s+/g," ").trim().slice(0,500)}),ht("comments")):ze.info(M.commentNeedsSelection)},children:oo(xe,{name:"chat",size:16})}),Ye.comments&&oo(Ae,{size:"sm",variant:"ghost","aria-label":M.comments,title:M.comments,"aria-pressed":"comments"===pt,onClick:()=>ht(e=>"comments"===e?"document":"comments"),children:oo(xe,{name:"chat-bubble-left-right",size:16})}),Ye.versions&&T&&oo(Ae,{size:"sm",variant:"ghost","aria-label":M.versionHistory,title:M.versionHistory,"aria-pressed":"history"===pt,onClick:()=>{ht(e=>"history"===e?"document":"history"),zt(null)},children:oo(xe,{name:"clock",size:16})})]}),exportControl:oo(Ne,{"aria-label":M.export,align:"end",items:Wo,triggerClassName:"docs-export-trigger",trigger:ao(ro,{children:[oo(xe,{name:"download",size:16}),M.export]})})}),gn&&ao("div",{className:"docs-conflict",role:"alert",children:[oo("span",{children:M.conflict}),oo(ke,{variant:"secondary",onClick:P,children:M.reload})]}),Mt.map((e,t)=>ao("div",{className:"docs-conflict",role:"status",children:[oo("span",{children:e.by?M.overwrote(e.by):M.overwroteSomeone}),ao("span",{className:"flex gap-2",children:[oo(ke,{variant:"secondary",onClick:()=>(e=>{Et(t=>t.filter(t=>t!==e));const t=F.current;if(!t)return;const n=Array.from(t.children).find(t=>nt(t)===e.key);hr(()=>{const r=document.createElement("div");r.innerHTML=e.mine;const o=r.firstElementChild;o&&(n?n.replaceWith(o):t.appendChild(o))})})(e),children:M.putMineBack}),oo(Ae,{size:"sm",variant:"ghost","aria-label":M.dismiss,title:M.dismiss,onClick:()=>Et(t=>t.filter(t=>t!==e)),children:oo(xe,{name:"close",size:14})})]})]},`${e.key}-${t}`)),Rt&&ao("div",{className:"docs-conflict",role:"status",children:[oo("span",{children:M.previewing(Rt.label)}),oo(ke,{variant:"secondary",onClick:()=>zt(null),children:M.backToDocument})]}),ao("div",{className:"flex shrink-0 flex-wrap items-center gap-0.5 border-b border-line bg-surface-sunken px-2 py-1"+("editing"!==ut?" docs-toolbar-off":""),inert:"editing"!==ut||void 0,children:[oo(Ne,{trigger:M.menuInsert,items:Ko,align:"start",triggerClassName:na}),oo($e,{open:Sn,onOpenChange:Nn,align:"start",triggerLabel:M.table,triggerClassName:"h-5 w-0 overflow-hidden",trigger:oo("span",{}),children:ao("div",{className:"p-1",children:[oo("div",{className:"mb-1 text-xs text-ink-muted",children:An.rows?M.tableSize(An.cols,An.rows):M.table}),oo("div",{className:"grid gap-0.5",style:{gridTemplateColumns:"repeat(8, 1fr)"},onMouseLeave:()=>$n({rows:0,cols:0}),children:Array.from({length:48},(e,t)=>{const n=Math.floor(t/8)+1,r=t%8+1,o=n<=An.rows&&r<=An.cols;return oo("button",{type:"button","aria-label":M.tableSize(r,n),onMouseEnter:()=>$n({rows:n,cols:r}),onFocus:()=>$n({rows:n,cols:r}),onClick:()=>Lo(n,r),className:"h-4 w-4 rounded-sm border "+(o?"border-accent-fill bg-accent-tint-strong":"border-line bg-surface")},t)})})]})}),oo(Ne,{trigger:M.menuLayout,items:_o,align:"start",triggerClassName:na}),oa,aa(M.print,oo(xe,{name:"print",size:16}),Bo),aa(M.find,oo(xe,{name:"search",size:16}),()=>En?Ro():zo(),{pressed:En}),oa,ia(M.paragraphStyle,(e=>{if(!e)return M.styleNormal;const t=f.styles.find(t=>t.id===e);return t?Go[t.name]??t.name:e})(an.styleId),Xo,"w-20"),ia(M.font,an.font||f.defaultFont||"Calibri",Zo,"w-20"),ia(M.fontSize,an.size??f.defaultSize??11,Qo),oa,aa(M.bold,oo(xe,{name:"bold",size:16}),()=>gr("bold"),{pressed:an.bold}),aa(M.italic,oo(xe,{name:"italic",size:16}),()=>gr("italic"),{pressed:an.italic}),aa(M.underline,oo(xe,{name:"underline",size:16}),()=>gr("underline"),{pressed:an.underline}),aa(M.strikethrough,oo(xe,{name:"strike",size:16}),()=>gr("strikeThrough"),{pressed:an.strike}),aa(M.superscript,oo(xe,{name:"superscript",size:16}),()=>gr("superscript"),{pressed:an.sup}),aa(M.subscript,oo(xe,{name:"subscript",size:16}),()=>gr("subscript"),{pressed:an.sub}),la(M.textColor,oo(xe,{name:"text-color",size:14}),sa.foreColor,Rr,"foreColor"),la(M.highlight,oo(xe,{name:"palette",size:14}),sa.hiliteColor,zr,"hiliteColor"),aa(M.paintFormat,oo(xe,{name:"paint-brush",size:16}),()=>{if(We.current)return We.current=null,void Ke(!1);Jn(),We.current=(()=>{const e=document.getSelection();if(!e?.anchorNode||!_n(e.anchorNode))return null;const t=1===e.anchorNode.nodeType?e.anchorNode:e.anchorNode.parentElement,n=getComputedStyle(t),r=t.closest(bo),o=e=>{try{return document.queryCommandState(e)}catch{return!1}};return{run:{b:o("bold"),i:o("italic"),u:o("underline"),strike:o("strikeThrough"),font:n.fontFamily.split(",")[0].replace(/["']/g,"").trim(),size:Math.round(.75*parseFloat(n.fontSize)*2)/2,color:Or(n.color),hl:Or(n.backgroundColor)||void 0},styleId:r?.getAttribute("data-pstyle")??null,tag:r?.tagName??"P"}})(),Ke(!!We.current),We.current&&ze.info(M.paintFormatHint)},{pressed:qe}),aa(M.clearFormatting,oo(xe,{name:"clear-marks",size:16}),()=>hr(()=>{document.execCommand("removeFormat");for(const e of Zn())e.style.removeProperty("text-align"),e.style.removeProperty("line-height"),e.style.removeProperty("margin-left")})),oa,aa(M.bulletedList,oo(xe,{name:"list",size:16}),()=>yr("insertUnorderedList"),{pressed:an.ul}),aa(M.numberedList,oo(xe,{name:"numbered-list",size:16}),()=>yr("insertOrderedList"),{pressed:an.ol}),aa(M.checklist,oo(xe,{name:"checkbox",size:16}),()=>hr(()=>{const e=F.current;if(!e)return;const t=Zn(),n=t.length>0&&t.every(e=>e.closest("ul[data-checklist]")),r=document.getSelection(),o=r?.anchorNode??null,a=r?.anchorOffset??0;if(n)document.execCommand("insertUnorderedList");else{const n=new Set(t.map(e=>e.closest("ul,ol")).filter(Boolean));n.size&&![...n].some(e=>"UL"!==e.tagName)||document.execCommand("insertUnorderedList");const r=(document.getSelection()?.anchorNode?.parentElement??o?.parentElement)?.closest("ul");e.querySelectorAll("p > ul").forEach(e=>{const t=e.parentElement;Array.from(t.childNodes).some(t=>t!==e&&(1===t.nodeType||(t.nodeValue??"").trim()))||t.replaceWith(e)});for(const e of[r,...n])e&&"UL"===e.tagName&&(e.setAttribute("data-checklist",""),e.removeAttribute("data-num-id"))}o&&o.isConnected&&r?.collapse(o,Math.min(a,3===o.nodeType?(o.nodeValue??"").length:o.childNodes.length))})),aa(M.decreaseIndent,oo(xe,{name:"chevron-double-left",size:16}),()=>Co(!1)),aa(M.increaseIndent,oo(xe,{name:"chevron-double-right",size:16}),()=>Co(!0)),oa,aa(M.alignLeft,oo(xe,{name:"align-left",size:16}),()=>So("left"),{pressed:"left"===an.align}),aa(M.alignCenter,oo(xe,{name:"align-center",size:16}),()=>So("center"),{pressed:"center"===an.align}),aa(M.alignRight,oo(xe,{name:"align-right",size:16}),()=>So("right"),{pressed:"right"===an.align}),aa(M.justify,oo(xe,{name:"align-justify",size:16}),()=>So("justify"),{pressed:"justify"===an.align}),oo(Ne,{"aria-label":M.paragraphSpacing,align:"start",items:ea,triggerClassName:ra,trigger:ao("span",{title:M.paragraphSpacing,className:"flex items-center gap-0.5",children:[oo(xe,{name:"line-spacing",size:16}),oo(xe,{name:"chevron-down",size:12})]})})]}),kn&&va.length>0&&ao("div",{role:"status",className:"flex shrink-0 items-center gap-2 border-b border-status-warning-line bg-status-warning-soft px-3 py-1 text-xs text-status-warning-soft-ink",children:[oo(xe,{name:"info",size:14}),oo("span",{className:"min-w-0 flex-1",children:M.noticeLead(va)}),oo(Ae,{size:"sm",variant:"ghost",ink:"inherit","aria-label":M.dismiss,title:M.dismiss,onClick:()=>Cn(!1),children:oo(xe,{name:"close",size:14})})]}),En&&oo(Lr,{query:zn,replacement:On,matchCase:Dn,current:Bn,total:Wn,onQuery:e=>{Fn(e),Eo(e,Dn,0)},onReplacement:In,onMatchCase:e=>{Hn(e),Eo(zn,e,0)},onStep:e=>{const t=Kn.current.length;if(!t)return;const n=(Bn+(e?1:-1)+t)%t;Un(n),Po(n,!0)},onReplace:()=>{const e=Kn.current[Bn];e&&(H.current.record(cr()),l(e,On),sr(),Eo(zn,Dn,Bn))},onReplaceAll:()=>{const e=Kn.current;if(e.length){H.current.record(cr());for(let t=e.length-1;t>=0;t--)l(e[t],On);sr(),ze.success(M.replacedCount(e.length)),Eo(zn,Dn,0)}},onClose:Ro}),ao("div",{className:"docs-body",children:[ao("div",{className:"docs-centre",children:[ao("div",{className:"min-h-0 flex-1 overflow-auto bg-surface-sunken px-6 pb-6",children:[oo("div",{className:"docs-ruler-row",children:oo(wr,{pageWidth:fa,marginLeft:ee.page.left/20,marginRight:ee.page.right/20,zoom:bn,value:He,onChange:e=>{je(e),Jn(),Be.current?clearTimeout(Be.current):H.current.record(cr()),Be.current=setTimeout(()=>{Be.current=null},500);for(const t of Zn()){"LI"!==t.tagName&&(t.style.marginLeft=e.indentLeft?`${e.indentLeft}pt`:"",t.style.textIndent=e.firstLine?`${e.firstLine}pt`:""),t.style.marginRight=e.indentRight?`${e.indentRight}pt`:"",e.tabs.length?t.setAttribute("data-tabs",G(e.tabs)):t.hasAttribute("data-tabs")&&t.setAttribute("data-tabs","");const n=_({indentLeft:e.indentLeft,tabs:e.tabs});t.style.tabSize=n?n.split(":")[1]:""}sr()}})}),ao("div",{ref:Zt,className:"docs-sheet relative mx-auto shadow",style:{width:`${fa}pt`,zoom:bn/100,minHeight:ee.page.height/20+"pt"},children:[Rt&&oo("div",{className:"docs-page docs-preview","data-doc":R,"aria-readonly":"true",style:{paddingTop:`${pa}pt`,paddingRight:ee.page.right/20+"pt",paddingBottom:ee.page.bottom/20+"pt",paddingLeft:ee.page.left/20+"pt",minHeight:ee.page.height/20+"pt"},dangerouslySetInnerHTML:{__html:Rt.html}}),oo("div",{ref:F,contentEditable:"viewing"!==ut,suppressContentEditableWarning:!0,spellCheck:!0,lang:f.lang,role:"textbox","aria-multiline":"true","aria-label":p,"data-doc":R,onPaste:e=>{(async e=>{if("editing"!==ft.current){e.preventDefault();const t=e.clipboardData?.getData("text/plain")??"";return void("suggesting"===ft.current&&t&&on.current(new InputEvent("beforeinput",{inputType:"insertFromPaste",data:t})))}const t=Array.from(e.clipboardData?.items??[]).filter(e=>"file"===e.kind&&e.type.startsWith("image/")).map(e=>e.getAsFile()).filter(e=>!!e),n=e.clipboardData?.getData("text/html");if(n){e.preventDefault();const t=document.createElement("div");t.innerHTML=s(n);for(const e of Array.from(t.querySelectorAll("img"))){const t=e.getAttribute("src")??"";if(t.startsWith("blob:")&&!b.has(t))try{const e=await(await fetch(t)).blob();b.set(t,{bytes:new Uint8Array(await e.arrayBuffer()),mime:e.type})}catch{e.remove()}}return void gr("insertHTML",t.innerHTML)}t.length&&(e.preventDefault(),No(t))})(e)},onMouseUp:Hr,onKeyUp:e=>{e.shiftKey&&Hr()},onClick:e=>{const t=e.target,n=t.closest("[data-toc]");if(n&&_n(n)){const r=t.closest("a"),o=r&&(e.metaKey||e.ctrlKey)?xo(r.getAttribute("data-anchor")??(r.getAttribute("href")??"").slice(1)):null;return o?void o.scrollIntoView({block:"start"}):void Ze({x:e.clientX,y:e.clientY,el:n})}if("LI"===t.tagName&&t.parentElement?.hasAttribute("data-checklist")&&e.nativeEvent.offsetX<0)return void hr(()=>{t.toggleAttribute("data-checked")});if("IMG"===t.tagName&&null===t.closest('[contenteditable="false"]')&&!t.getAttribute("contenteditable"))return e.preventDefault(),void Tn({x:e.clientX,y:e.clientY,el:t});const r=t.closest("a");if(r&&(e.metaKey||e.ctrlKey)){const e=r.getAttribute("href")??"";e.startsWith("#")?xo(e.slice(1))?.scrollIntoView({block:"start"}):yo.test(e)&&window.open(e,"_blank","noopener,noreferrer")}},onContextMenu:e=>{const t=e.target.closest?.("td,th");t&&!e.shiftKey&&!t.closest("[data-locked]")&&_n(t)&&(e.preventDefault(),Mn({x:e.clientX,y:e.clientY,cell:t}))},className:"docs-page","data-mode":ut,hidden:!!Rt,style:{paddingTop:`${pa}pt`,paddingRight:ee.page.right/20+"pt",paddingBottom:ee.page.bottom/20+"pt",paddingLeft:ee.page.left/20+"pt",minHeight:ee.page.height/20+"pt",boxSizing:"border-box",...ie>1&&!se?{columnCount:ie,columnGap:"36pt"}:{},...qe?{cursor:"copy"}:{}}}),!Rt&&Tt.map(e=>oo("span",{className:"docs-remote-caret","aria-hidden":"true",style:{left:e.x,top:e.y,height:e.h,background:e.color},children:oo("span",{style:{background:e.color},children:e.name})},e.key)),oo("button",{type:"button",className:"docs-hf-preview docs-page","data-doc":R,title:M.headersFootersHint,"aria-label":M.headersFooters,onClick:()=>ae(!0),"data-hint":M.headersFootersHint,style:{top:ee.page.header/20+"pt",left:ee.page.left/20+"pt",right:ee.page.right/20+"pt",minHeight:Math.max(ee.page.top-ee.page.header-120,240)/20+"pt",maxHeight:Math.max(ee.page.top-ee.page.header,240)/20+"pt"},dangerouslySetInnerHTML:{__html:po(ga,1,ha)}}),Ve.length>0&&oo("section",{className:"docs-footnotes","aria-label":M.footnotes,style:{marginLeft:ee.page.left/20+"pt",marginRight:ee.page.right/20+"pt",marginBottom:ee.page.bottom/20+"pt"},children:Ve.map((e,t)=>{const n=f.footnotes.get(e);return ao("div",{className:"docs-footnote",children:[oo("sup",{children:t+1}),!1===n?.editable?oo("span",{title:M.footnoteLocked,children:n.text}):oo("input",{"data-note-input":e,value:n?.text??"",placeholder:M.footnotePlaceholder,"aria-label":`${M.footnote} ${t+1}`,onChange:t=>((e,t)=>{const n=f.footnotes.get(e);n?.editable&&(f.footnotes.set(e,{...n,text:t}),Ge(e=>e+1),sr())})(e,t.target.value)})]},e)})}),mn.slice(1).map((e,t)=>oo("div",{className:"docs-sheet-line pointer-events-none absolute left-0 right-0 border-t border-dashed","aria-hidden":"true",style:{top:`calc(${pa}pt + ${e}px)`},children:oo("span",{className:"docs-sheet absolute right-1 -top-2 px-1 text-2xs",children:M.pageLabel(t+2)})},e)),oo("button",{type:"button",className:"docs-hf-preview docs-page","data-doc":R,title:M.headersFootersHint,"aria-label":M.headersFooters,onClick:()=>ae(!0),"data-hint":M.headersFootersHint,style:{bottom:ee.page.footer/20+"pt",left:ee.page.left/20+"pt",right:ee.page.right/20+"pt",minHeight:Math.max(ee.page.bottom-ee.page.footer-120,240)/20+"pt",maxHeight:Math.max(ee.page.bottom-ee.page.footer,240)/20+"pt"},dangerouslySetInnerHTML:{__html:po(wa,ha,ha)}})]})]}),ao("div",{className:"flex shrink-0 items-center gap-2 border-t border-line bg-surface-sunken px-3 py-1 text-xs text-ink-muted",children:[oo("span",{children:M.pageOf(Math.min(dn.pageNow,mn.length),mn.length)}),oo("span",{children:M.wordCount(dn.words)}),oo("span",{children:ua}),ma&&oo("span",{children:ma}),ao("span",{className:"ml-auto flex items-center gap-1",children:[oo(ke,{size:"sm",variant:"ghost","aria-label":M.zoomOut,onClick:()=>yn(e=>[...wo].reverse().find(t=>t<e)??e),children:"−"}),ao("span",{className:"w-9 text-center tabular-nums",children:[bn,"%"]}),oo(ke,{size:"sm",variant:"ghost","aria-label":M.zoomIn,onClick:()=>yn(e=>wo.find(t=>t>e)??e),children:"+"})]})]})]}),"comments"===pt&&Ye.comments?oo(Nt,{comments:gt,blockOrder:St,suggestions:kt,me:rt,canComment:Yt,canEdit:Qt,people:Ye.people,draft:bt,activeId:vt,onCancelDraft:()=>yt(null),onAdd:async(e,t,n)=>{if(!et||!Ye.comments||!bt)return;const r=await Ye.comments.add(et,{body:e,block_id:bt.blockId,quote:bt.quote,mentions:t,assignee:n});wt(e=>[...e,r]),yt(null),xt(r.id)},onReply:async(e,t,n)=>{if(!et||!Ye.comments)return;const r=await Ye.comments.add(et,{body:t,parent:e,mentions:n});wt(t=>[...t.map(t=>t.id===e?{...t,resolved_at:null}:t),r])},onResolve:(e,t)=>Nr(e,{resolved:t}),onEdit:(e,t)=>Nr(e,{body:t}),onDelete:e=>{et&&Ye.comments&&Ye.comments.remove(et,e).then(()=>wt(t=>t.filter(t=>t.id!==e&&t.parent!==e)),()=>ze.error(M.commentFailed))},onFocus:e=>{xt(e.id);const t=F.current;t?.querySelector(`[data-pid="${e.block_id.replace(/[^0-9A-F]/g,"")}"]`)?.scrollIntoView({block:"center"})},onSuggestion:(e,t)=>hr(()=>{for(const n of e.els)n.isConnected&&Bt(n,t)}),onShowSuggestion:e=>e.els[0]?.scrollIntoView({block:"center"})}):"history"===pt&&Ye.versions&&et?oo(Ot,{documentId:et,versions:Ye.versions,canEdit:Qt,previewing:Rt?.id??null,onPreview:(e,t)=>{(async(e,t)=>{if(e&&et&&Ye.versions)try{const[n,r]=await Promise.all([Ye.versions.content(et,e.id).then(e=>w(e)),t?Ye.versions.content(et,t.id).then(e=>w(e)).catch(()=>null):Promise.resolve(null)]),o=dt(e.editor_names[0]??"");zt({id:e.id,html:`<div style="--docs-diff:${o}">${Kt(n.html,r?.html??null)}</div>`,label:e.name||new Date(e.created_at).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})})}catch{ze.error(M.versionsFailed)}else zt(null)})(e,t)},onRestore:async e=>{if(!et||!Ye.versions||!T)return;await ar();const t=await Ye.versions.content(et,e.id);Q.current=await T.store.save(T.id,t,Q.current),zt(null),P?.()},refreshKey:Ft}):oo(Ue,{page:ee.page,onPage:e=>{te(t=>({...t,page:e})),sr()},onMorePageSetup:()=>xn(!0),colour:an.color,onColour:e=>{ln(t=>({...t,color:e})),ca(t=>({...t,foreColor:e})),Y.current&&clearTimeout(Y.current),Y.current=setTimeout(()=>{Y.current=null,gr("foreColor",e)},150)},outline:pn,onHeading:e=>{const t=F.current;t&&Er(t)[e]?.scrollIntoView({block:"start"})}})]}),vn&&oo(Kr,{value:ee,onClose:()=>xn(!1),onApply:e=>{te(e),xn(!1),sr()}}),oe&&oo(Qn,{value:ne,scope:R,locked:{headers:Object.fromEntries(mo.map(e=>[e,!f.headers[e].editable])),footers:Object.fromEntries(mo.map(e=>[e,!f.footers[e].editable]))},onClose:()=>ae(!1),onApply:e=>{re(e),ae(!1),sr()}}),Ie&&oo(dr,{value:Ie,onClose:()=>De(null),onApply:e=>{var t;De(null),t=e,hr(()=>{for(const e of Zn())void 0!==t.lineMultiple&&(e.style.lineHeight=String(t.lineMultiple)),void 0!==t.before&&(e.style.marginTop=`${t.before}pt`),void 0!==t.after&&(e.style.marginBottom=`${t.after}pt`),void 0!==t.indentRight&&(e.style.marginRight=t.indentRight?`${t.indentRight}pt`:""),"LI"!==e.tagName&&(void 0!==t.indentLeft&&(e.style.marginLeft=t.indentLeft?`${t.indentLeft}pt`:""),void 0!==t.firstLine&&(e.style.textIndent=t.firstLine?`${t.firstLine}pt`:""))})}}),Je&&ao(Le,{minWidth:180,portal:!0,style:{position:"fixed",left:Je.x,top:Je.y},onClose:()=>Ze(null),children:[oo(Pe,{onClick:()=>{var e;e=Je.el,hr(()=>{e.innerHTML=Wr()}),Ze(null)},children:M.tocRefresh}),oo(Te,{}),oo(Pe,{danger:!0,onClick:()=>{const e=Je.el;hr(()=>{e.remove()}),Ze(null)},children:M.tocDelete})]}),Ln&&ao(Le,{minWidth:150,portal:!0,style:{position:"fixed",left:Ln.x,top:Ln.y},onClose:()=>Tn(null),children:[oo(Me,{children:M.imageWidth}),oo(Pe,{onClick:()=>To(.25),children:"25%"}),oo(Pe,{onClick:()=>To(.5),children:"50%"}),oo(Pe,{onClick:()=>To(.75),children:"75%"}),oo(Pe,{onClick:()=>To(1),children:"100%"}),oo(Pe,{onClick:()=>To(null),children:M.imageOriginalSize}),oo(Te,{}),oo(Pe,{danger:!0,onClick:()=>{if(!Ln)return;const e=Ln.el;hr(()=>{e.remove()}),Tn(null)},children:M.imageRemove})]}),Pn&&oo(Se,{at:{x:Pn.x,y:Pn.y},owner:Pn.cell,onClose:()=>Mn(null),items:(e=>{const t=e.closest("table"),n=(e,t,n,r={})=>({key:e,label:t,onSelect:()=>hr(n),...r}),r=(e=>{const t=B.current;return t?Array.from(e.querySelectorAll("td,th")).filter(n=>n.closest("table")===e&&t.intersectsNode(n)):[]})(t);return[n("above",M.rowAbove,()=>eo(t,e,!1)),n("below",M.rowBelow,()=>eo(t,e,!0)),n("left",M.columnLeft,()=>to(t,e,!1)),n("right",M.columnRight,()=>to(t,e,!0)),{type:"divider",key:"d1"},n("merge",M.mergeCells,()=>{(function(e,t){if(t.length<2)return!1;const n=Zr(e);let r=1/0,o=1/0,a=-1,i=-1;for(const e of t){const t=Qr(n,e);if(!t)return!1;r=Math.min(r,t.row),o=Math.min(o,t.col),a=Math.max(a,t.row+Jr(e,"rowspan")-1),i=Math.max(i,t.col+Jr(e,"colspan")-1)}const l=new Set;for(let e=r;e<=a;e++)for(let t=o;t<=i;t++){const r=n.slots[e]?.[t];r&&l.add(r)}for(const e of l){const t=Qr(n,e);if(t.row<r||t.col<o||t.row+Jr(e,"rowspan")-1>a||t.col+Jr(e,"colspan")-1>i)return!1}const s=n.slots[r][o];for(const e of l)if(e!==s){if((e.textContent??"").trim())for(;e.firstChild;)s.appendChild(e.firstChild);e.remove()}return s.setAttribute("colspan",String(i-o+1)),s.setAttribute("rowspan",String(a-r+1)),i===o&&s.removeAttribute("colspan"),a===r&&s.removeAttribute("rowspan"),!0})(t,r)||ze.error(M.mergeFailed)},{disabled:r.length<2}),{type:"submenu",key:"shade",label:M.cellShading,items:[...Fr.map(t=>({key:t,label:ao("span",{className:"flex items-center gap-2",children:[oo("span",{className:"h-3 w-5 rounded-sm border border-line",style:{background:t}}),t.toUpperCase()]}),onSelect:()=>hr(()=>{for(const n of r.length?r:[e])n.style.backgroundColor=t})})),{key:"none",label:M.noColor,onSelect:()=>hr(()=>{for(const t of r.length?r:[e])t.style.removeProperty("background-color")})}]},{type:"divider",key:"d2"},n("delRow",M.deleteRow,()=>{!function(e,t){const n=Zr(e),r=Qr(n,t);if(!r)return!1;const o=Xr(e);if(1===o.length)return e.remove(),!1;const a=new Set;for(let e=0;e<n.cols;e++){const t=n.slots[r.row][e];if(!t||a.has(t))continue;a.add(t);const i=Jr(t,"rowspan");if(1!==i)if(t.parentElement===o[r.row]){const a=o[r.row+1],l=n.slots[r.row+1].slice(e+Jr(t,"colspan")).find(e=>e.parentElement===a);t.setAttribute("rowspan",String(i-1)),a.insertBefore(t,l??null)}else t.setAttribute("rowspan",String(i-1))}o[r.row].remove()}(t,e)}),n("delCol",M.deleteColumn,()=>{!function(e,t){const n=Zr(e),r=Qr(n,t);if(!r)return!1;if(1===n.cols)return e.remove(),!1;const o=new Set;for(const e of n.slots){const t=e[r.col];if(!t||o.has(t))continue;o.add(t);const n=Jr(t,"colspan");n>1?t.setAttribute("colspan",String(n-1)):t.remove()}no(e,n.cols-1,null,r.col)}(t,e)}),n("delTable",M.deleteTable,()=>{t.remove()},{danger:!0})]})(Pn.cell)})]})}function ko({label:e,hint:t}){return ao("span",{className:"flex w-full items-center justify-between gap-4",children:[oo("span",{children:e}),oo("span",{className:"text-2xs text-ink-faint",children:t})]})}import{useEffect as Co,useRef as So,useState as No}from"react";import{Icon as Ao}from"efficient-shell/icons";import{Button as $o,IconButton as Lo,registerModalEscapeInterceptor as To,toast as Po}from"efficient-shell/ui";var Mo={LF:"\n",CRLF:"\r\n",CR:"\r"};function Eo(e,t){let n=1,r=-1;for(let o=e.indexOf("\n");o>=0&&o<t;o=e.indexOf("\n",o+1))n++,r=o;return{line:n,col:t-r}}function Ro(e){let t=1;for(let n=e.indexOf("\n");n>=0;n=e.indexOf("\n",n+1))t++;return t}import{jsx as zo,jsxs as Fo}from"react/jsx-runtime";function Oo({filename:e,decoded:t,bytes:n,fileEntries:r,title:o,dirty:a,onDirty:i,onOpenFile:l,onClose:s}){const c=u(),d=So(null),m=So(null),f=So(t.text),p=So(!1),[h,g]=No(!0),[w,b]=No(!1),[y,v]=No({line:1,col:1,lines:Ro(t.text)}),[x,k]=No(!1),[C,S]=No(""),[N,A]=No(""),[$,L]=No(!1),[T,P]=No(0),[M,E]=No([]),R=()=>m.current?.value??"",z=So(null),[F,O]=No(0),I=()=>{z.current&&m.current&&(z.current.scrollTop=m.current.scrollTop,z.current.scrollLeft=m.current.scrollLeft)};Co(()=>{const e=z.current?.querySelector("[data-current]"),t=m.current;if(!e||!t)return;const n=e.offsetTop-t.clientHeight/3;(e.offsetTop<t.scrollTop||e.offsetTop>t.scrollTop+t.clientHeight-42)&&(t.scrollTop=Math.max(0,n)),h||(t.scrollLeft=Math.max(0,e.offsetLeft-t.clientWidth/2)),I()},[F,T,M,h]);const D=()=>{const e=m.current;e&&v({...Eo(e.value,e.selectionStart),lines:Ro(e.value)})},H=(e=C,t=$)=>{const n=function(e,t,n){if(!t)return[];const r=n?e:e.toLowerCase(),o=n?t:t.toLowerCase(),a=r.length===e.length?r:e,i=[];for(let e=a.indexOf(o);e>=0;e=a.indexOf(o,e+Math.max(o.length,1)))i.push(e);return i}(R(),e,t);return E(n),n},j=(e,t,n=C)=>{const r=m.current;if(!r||!e.length)return;const o=(t%e.length+e.length)%e.length;P(o),r.setSelectionRange(e[o],e[o]+n.length),O(e=>e+1)},B=()=>{br(p.current?function(e,t,n){const r=e.replace(/\n/g,Mo[n]);if("utf-16le"===t||"utf-16be"===t){const e=new Uint8Array(2+2*r.length),n=new DataView(e.buffer),o="utf-16le"===t;n.setUint16(0,65279,o);for(let e=0;e<r.length;e++)n.setUint16(2+2*e,r.charCodeAt(e),o);return e}const o=(new TextEncoder).encode(r);if("utf-8-bom"!==t)return o;const a=new Uint8Array(o.length+3);return a.set([239,187,191]),a.set(o,3),a}(R(),t.encoding,t.eol):n,e,"text/plain"),p.current&&"windows-1252"===t.encoding&&Po.info(c.savedAsUtf8),f.current=R(),i(!1)},U=()=>{p.current=!0,b(!0),i(R()!==f.current),D(),x&&H()},W=e=>{document.execCommand("insertText",!1,e)||m.current?.setRangeText(e,m.current.selectionStart,m.current.selectionEnd,"end"),U()},q=e=>{m.current?.focus(),document.execCommand(e)},K=()=>{k(!1),m.current?.focus()};Co(()=>{m.current?.focus(),m.current?.setSelectionRange(0,0)},[]);const V=So(x);V.current=x,Co(()=>To(()=>!(!V.current||!d.current?.contains(document.activeElement))&&(K(),!0)),[]);const _=[...r,{type:"divider",key:"d1"},{key:"save",label:c.saveKeepType,onSelect:B}],G=a?c.noStoreEdited:c.noStoreClean;return Fo("div",{ref:d,className:"es-editor docs-frame",onKeyDown:e=>{const t=e.metaKey||e.ctrlKey,n=e.key.toLowerCase();if(t&&"s"===n)e.preventDefault(),B();else if(t&&"o"===n)e.preventDefault(),l();else if(t&&"f"===n){e.preventDefault(),k(!0);const t=m.current,n=t?t.value.slice(t.selectionStart,t.selectionEnd):"";n&&!n.includes("\n")&&(S(n),H(n))}else"Tab"!==e.key||t||e.shiftKey||e.target!==m.current||(e.preventDefault(),W("\t"))},children:[zo(Qe,{onClose:s,fileMenu:_,name:o,saveState:{tone:a?"off-unsaved":"off",label:G},canUndo:w,canRedo:w,onUndo:()=>q("undo"),onRedo:()=>q("redo"),exportControl:zo($o,{variant:"secondary",leftIcon:zo(Ao,{name:"download",size:16}),onClick:B,children:c.export})}),Fo("div",{className:"flex shrink-0 flex-wrap items-center gap-0.5 border-b border-line bg-surface-sunken px-2 py-1",children:[zo(Lo,{size:"sm",variant:"ghost","aria-label":c.find,title:c.find,"aria-pressed":x,onClick:()=>k(e=>!e),children:zo(Ao,{name:"search",size:16})}),zo(Lo,{size:"sm",variant:"ghost","aria-label":c.wrapLines,title:c.wrapLines,"aria-pressed":h,onClick:()=>g(e=>!e),children:zo(Ao,{name:"wrap",size:16})})]}),x&&zo(Lr,{query:C,replacement:N,matchCase:$,current:T,total:M.length,onQuery:e=>{S(e);const t=H(e);P(0),j(t,0,e)},onReplacement:A,onMatchCase:e=>{L(e);const t=H(C,e);P(0),j(t,0)},onStep:e=>j(M,T+(e?1:-1)),onReplace:()=>{const e=m.current;if(!e||!M.length)return;e.focus(),e.setSelectionRange(M[T],M[T]+C.length),W(N);const t=H();j(t,T)},onReplaceAll:()=>{const e=m.current;if(!e||!M.length)return;const t=M.length;e.focus();for(let t=M.length-1;t>=0;t--)e.setSelectionRange(M[t],M[t]+C.length),W(N);H(),P(0),Po.success(c.replacedCount(t))},onClose:K}),Fo("div",{className:"relative min-h-0 flex-1 bg-surface",children:[x&&C&&M.length>0&&M.length<=2e3&&zo("div",{ref:z,"aria-hidden":"true",style:{lineHeight:"21px",scrollbarGutter:"stable"},className:"pointer-events-none absolute inset-0 overflow-hidden p-4 font-mono text-sm text-transparent "+(h?"whitespace-pre-wrap break-words":"whitespace-pre"),children:(()=>{const e=R(),t=[];let n=0;return M.forEach((r,o)=>{t.push(e.slice(n,r)),n=r+C.length,t.push(zo("mark",{...o===T?{"data-current":""}:{},className:"rounded-sm text-transparent "+(o===T?"bg-status-warning-line":"bg-status-warning-soft"),children:e.slice(r,n)},r))}),t.push(e.slice(n)),t})()}),zo("textarea",{ref:m,defaultValue:t.text,"aria-label":e,spellCheck:!1,wrap:h?"soft":"off",onInput:U,onSelect:D,onKeyUp:D,onClick:D,onScroll:I,style:{lineHeight:"21px",scrollbarGutter:"stable"},className:"absolute inset-0 h-full w-full resize-none bg-transparent p-4 font-mono text-sm text-ink outline-none "+(h?"whitespace-pre-wrap break-words":"overflow-x-auto whitespace-pre")})]}),Fo("div",{className:"flex shrink-0 items-center gap-2 border-t border-line bg-surface-sunken px-3 py-1 text-xs text-ink-muted",children:[zo("span",{children:e}),zo("span",{children:c.lineColumn(y.line,y.col)}),zo("span",{children:c.lineCount(y.lines)}),zo("span",{children:t.eol})]})]})}import{jsx as Io,jsxs as Do}from"react/jsx-runtime";var Ho=new Set(["txt","md","markdown","csv","tsv","log","json","xml","html","htm","css","js","jsx","ts","tsx","py","rb","go","rs","java","c","h","cpp","hpp","sh","bash","yml","yaml","toml","ini","conf","env","sql"]),jo=["docx"],Bo=`${Array.from(Ho,e=>`.${e}`).join(",")},.docx,text/*`,Uo=/^<!doctype html><meta charset="utf-8"><title>[^<]*<\/title>(?!<body style="font-family:ui-monospace)/,Wo=()=>"undefined"!=typeof navigator&&navigator.language||"en-AU";function qo({value:e,onRename:t}){const n=u(),[r,o]=re(e);return te(()=>o(e),[e]),Io("div",{className:"docs-title",children:Io(se,{"aria-label":n.documentName,value:r,onChange:e=>o(e.target.value),onKeyDown:e=>{"Enter"===e.key&&e.currentTarget.blur()},onBlur:()=>{const n=r.trim();o(n||e),n&&n!==e&&t(n)}})})}function Ko({documentId:e,onClose:t}){const n=u(),{store:r,canCreate:o=!0,canDelete:a=!0,chooseFile:i}=d(),[l,s]=re(null),[c,p]=re(null);if(!r||e)return Io(Vo,{documentId:e,onClose:t});if(l)return Io(Vo,{documentId:l.id,initialFile:l.file,onClose:()=>s(null)},l.key);return Io(m,{words:{windowTitle:n.filesHeading,heading:n.filesHeading,newFile:n.newFile,emptyTitle:n.filesEmptyTitle,emptyBody:n.filesEmptyBody,deleteConfirm:n.deleteConfirm,createFailed:n.createFailed,deleteFailed:n.deleteFailed},files:n.files,list:r.list,create:()=>r.create(n.untitled),rename:r.rename,remove:r.remove,canCreate:o,canDelete:a,accept:Bo,choose:i&&{run:i,request:{title:n.files.choosing(n.fileKind,n.filesHeading),extensions:jo}},onOpen:e=>s({key:Date.now(),id:e}),onOpenFile:(e,t)=>{Y(e.name,jo)?c||(p(n.files.opening(e.name)),f(r,e).then(async r=>{const o=await ee(t,r.id);ue.success(n.files.savedCopy(r.title,e.name,o?t?.location:void 0)),s({key:Date.now(),id:r.id})}).catch(()=>ue.error(n.files.openFailed(e.name))).finally(()=>p(null))):s({key:Date.now(),file:e})},busy:c})}function Vo({documentId:e,onClose:t,initialFile:n}){const r=u(),{store:o}=d(),a=o&&e?e:null,i=ne([]),l=ne(0),c=ne(null),m={textBox:r.objectTextBox,chart:r.objectChart,diagram:r.objectDiagram,equation:r.objectEquation,picture:r.objectPicture,object:r.objectOther,contents:r.objectField},f=e=>({labels:m,imageUrl:(t,n)=>{const r=URL.createObjectURL(new Blob([t],{type:n}));return i.current.push(r),e.set(r,{bytes:t,mime:n}),r}}),p=e=>{const t=new Map;return{key:++l.current,kind:"rich",filename:e,images:t,doc:b(E(Wo()),null,f(t))}},[h,g]=re(()=>a?null:p(r.untitled)),[v,x]=re(!1),[k,C]=re(0),[S,N]=re(!1),[A,$]=re(!1),[L,T]=re(!1);ae(L),te(()=>()=>{i.current.forEach(e=>URL.revokeObjectURL(e))},[]),te(()=>{if(!o||!a)return;let e=!0;return x(!1),(async()=>{const t=await o.get(a),n=new Map,r=t.bytes?.length?await w(t.bytes,f(n)):b(E(Wo()),null,f(n));e&&P({key:++l.current,kind:"rich",doc:r,images:n,filename:t.title,stored:{id:t.id,version:t.version}})})().catch(()=>{e&&x(!0)}),()=>{e=!1}},[o,a,k]);const P=e=>{const t=i.current;if(i.current=[],"rich"===e.kind)for(const t of e.images.keys())i.current.push(t);g(e),T(!1),setTimeout(()=>t.filter(e=>!i.current.includes(e)).forEach(e=>URL.revokeObjectURL(e)),0)},M=async()=>!L||de({title:r.discardTitle(h?.filename??""),message:r.discardMessage,confirmLabel:r.discard,cancelLabel:r.keepEditing}),R=async e=>{if(!await M())return;const t=(e.name.split(".").pop()||"").toLowerCase();N(!0);try{if("docx"===t){const t=new Map,n=new Uint8Array(await e.arrayBuffer());try{const r=await w(n,f(t));P({key:++l.current,kind:"rich",doc:r,filename:e.name,images:t})}catch{ue.error(r.cannotRead(e.name))}}else if("doc"===t)ue.error(r.legacyDoc);else if(Ho.has(t)||e.type.startsWith("text/")){const n=new Uint8Array(await e.arrayBuffer()),o=function(e){let t,n="utf-8";if(239===e[0]&&187===e[1]&&191===e[2])n="utf-8-bom",t=new TextDecoder("utf-8").decode(e.subarray(3));else if(255===e[0]&&254===e[1])n="utf-16le",t=new TextDecoder("utf-16le").decode(e.subarray(2));else if(254===e[0]&&255===e[1])n="utf-16be",t=new TextDecoder("utf-16be").decode(e.subarray(2));else try{t=new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch{n="windows-1252",t=new TextDecoder("windows-1252").decode(e)}const r=t.match(/\r\n/g)?.length??0,o=(t.match(/\n/g)?.length??0)-r,a=(t.match(/\r/g)?.length??0)-r,i=r>o&&r>=a?"CRLF":a>o?"CR":"LF";return{text:t.replace(/\r\n?/g,"\n"),encoding:n,eol:i}}(n);if("html"!==t&&"htm"!==t||!Uo.test(o.text))P({key:++l.current,kind:"text",decoded:o,bytes:n,filename:e.name});else{const t=new Map,n=b(E(Wo()),null,f(t));n.html=s(o.text)||n.html,y(n),P({key:++l.current,kind:"rich",doc:n,images:t,filename:e.name.replace(/\.[^.]+$/,".docx"),imported:!0}),ue.info(r.openedOldSave)}}else ue.error(r.unsupported(t))}finally{N(!1)}};te(()=>{n&&R(n)},[]);const z=async()=>{await M()&&(T(!1),c.current?.click())},F="rich"===h?.kind&&!!h.stored,O=()=>ue.info(r.openFromFiles),I=[{key:"new",label:r.newDocument,onSelect:()=>{(async()=>{await M()&&P(p(r.untitled))})()}},{key:"open",label:Do("span",{className:"flex w-full items-center justify-between gap-4",children:[Io("span",{children:r.open}),Io("span",{className:"text-2xs text-ink-faint",children:"⌘O"})]}),onSelect:()=>{z()}}],D=h&&Io(qo,{value:h.filename,onRename:e=>{const t=h?.filename??e;g(t=>t?{...t,filename:e}:t),o&&"rich"===h?.kind&&h.stored&&o.rename(h.stored.id,e).catch(()=>{ue.error(r.renameFailed),g(e=>e?{...e,filename:t}:e)})}});return Do("div",{className:"relative flex h-full flex-col bg-surface text-ink",onDragOver:e=>{e.dataTransfer.types.includes("Files")&&(e.preventDefault(),A||$(!0))},onDragLeave:e=>{e.currentTarget===e.target&&$(!1)},onDrop:e=>{if(!e.dataTransfer.types.includes("Files"))return;e.preventDefault(),$(!1);const t=Array.from(e.dataTransfer.files??[]);"rich"===h?.kind&&t.length&&t.every(e=>e.type.startsWith("image/"))?window.dispatchEvent(new CustomEvent("docs-insert-images",{detail:{key:h.key,files:t}})):t[0]&&F?O():t[0]&&R(t[0])},children:[h&&Io(oe,{title:`${H=h.filename,H.length>24?`${H.slice(0,23)}…`:H}${L?" •":""} - Documents`}),Io("input",{ref:c,type:"file",accept:Bo,className:"hidden",onChange:e=>{const t=e.target.files?.[0];t&&R(t),e.target.value=""}}),v?Io("div",{className:"docs-open-failed",children:Io(le,{title:r.openFailed,children:t&&Io(ie,{onClick:t,children:r.backToFiles})})}):S||!h?Io(ce,{size:"sm",padding:"",className:"h-full",label:r.loading}):"rich"===h.kind?Io(xo,{sessionKey:h.key,doc:h.doc,filename:h.filename,images:h.images,fileEntries:F?[]:I,title:D,startsDirty:h.imported,dirty:L,onDirty:T,onOpenFile:()=>{F?O():z()},onNewImageUrl:e=>{i.current.push(e)},onClose:t,stored:o&&h.stored?{store:o,...h.stored}:void 0,onReload:()=>{T(!1),g(null),C(e=>e+1)}},h.key):Io(Oo,{filename:h.filename,decoded:h.decoded,bytes:h.bytes,fileEntries:I,title:D,dirty:L,onDirty:T,onOpenFile:()=>{z()},onClose:t},h.key),A&&Io("div",{className:"pointer-events-none absolute inset-0 z-20 flex items-center justify-center border-4 border-dashed border-accent-fill bg-accent-tint",children:Io("div",{className:"rounded-md bg-accent-fill px-4 py-2 text-sm font-medium text-on-accent",children:r.dropHint})})]});var H}function _o({id:e,onClose:t}){return Io(Ko,{documentId:e,onClose:t})}export{_o as OpenDocument,Ko as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{BUILTIN_STYLES as t,CHECK_BULLETS as e,DEFAULT_PAGE as a,REL as n,child as r,childrenOf as o,descendants as s,paraCss as c,parseParaProps as l,parseRunProps as d,parseXml as i,partText as w,readRels as m,readThemeFonts as p,readZip as f,resolveTarget as u,runCss as h,tabCss as b,tabsAttr as g}from"./chunk-D3JKD7KW.js";import{escapeHtml as $}from"efficient-shell/ui";var v={textBox:"Text box",chart:"Chart",diagram:"Diagram",equation:"Equation",picture:"Picture",object:"Object",contents:"Field"},x={text:"",html:"",editable:!0},k=()=>({default:{...x},first:{...x},even:{...x}}),y=new Set(["w:ins","w:del","w:moveFrom","w:moveTo","w:rPrChange","w:pPrChange","w:tcPrChange","w:trPrChange","w:tblPrChange","w:sectPrChange","w:cellIns","w:cellDel"]),P=new Set(["w:ins","w:del","w:moveFrom","w:moveTo"]),S=new Set([...y].filter(t=>"w:ins"!==t&&"w:del"!==t)),j={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",bmp:"image/bmp",webp:"image/webp",svg:"image/svg+xml"},C=/^(https?:|mailto:|tel:)/i,I=t=>$(t);function M(t,e){let a="";for(let e=0;e<t.length;e+=32768)a+=String.fromCharCode(...t.subarray(e,e+32768));return`data:${e};base64,${btoa(a)}`}var T=(t,e)=>`${e}${++t.nextId}`,N=(t,e)=>t.src.slice(e.start,e.end),A=(t,e)=>e?N(t,e):void 0;function E(t,e){const a=[],n=new Set;let o=e;for(;o&&!n.has(o);){n.add(o);const e=t.styles.get(o);if(!e)break;a.unshift(e),o=r(e,"w:basedOn")?.attrs["w:val"]}return a}var O=t=>`"${t.replace(/["\\\n\r]/g,"")}"`;function B(t){return"w:t"===t.name||"w:delText"===t.name?t.text:"w:tab"===t.name?"\t":"w:instrText"===t.name||"w:instrDelText"===t.name?"":t.children.map(B).join("")}function L(t,e,a,n,r=""){const o=T(t,"x");return t.doc.raw.set(o,e),`<span data-raw="${o}" data-kind="${a}" contenteditable="false"${r}>${$(n)}</span>`}function R(t,e){const a=T(t,"x");return t.doc.raw.set(a,e),`<span data-raw="${a}" data-kind="mark"></span>`}function F(t,e,a){const n=a(N(t,e)),o=t=>s(e,new Set([t])).length>0,c=r(e,"wp:inline"),l=s(e,new Set(["a:blip"]))[0],d=l&&t.rels.get(l.attrs["r:embed"]),i=d&&!d.external?u(t.doc.docPath,d.target):void 0,w=i?.split(".").pop()?.toLowerCase()??"",m=i?t.doc.parts.get(i):void 0;if(m&&j[w]&&!o("wps:txbx")){const a=T(t,"x");t.doc.raw.set(a,n);const o=r(c??r(e,"wp:anchor"),"wp:extent"),s=Number(o?.attrs.cx)/12700,l=Number(o?.attrs.cy)/12700,d=s&&l?` style="width:${Math.round(100*s)/100}pt;height:${Math.round(100*l)/100}pt"`:"",i=c?"":' contenteditable="false"';return c||t.doc.notices.objects++,`<img data-raw="${a}" src="${I(t.imageUrl(m,j[w]))}"${d}${i} alt="">`}return t.doc.notices.objects++,o("wps:txbx")||o("w:txbxContent")?L(t,n,"object",`${t.labels.textBox}: ${B(e).slice(0,80)}`):o("c:chart")?L(t,n,"object",t.labels.chart):o("dgm:relIds")?L(t,n,"object",t.labels.diagram):L(t,n,"object",l?t.labels.picture:t.labels.object)}function D(t,e){const a=r(e,"w:rPr"),n=d(a,t.theme),o=A(t,a)??"",c=t=>`<w:r>${o}${t}</w:r>`;let l="";for(const a of e.children)switch(a.name){case"w:rPr":case"w:lastRenderedPageBreak":case"w:commentReference":case"w:fldChar":case"w:instrText":case"w:delInstrText":break;case"w:t":case"w:delText":l+=$(a.text);break;case"w:tab":l+="\t";break;case"w:noBreakHyphen":l+="‑";break;case"w:softHyphen":l+="";break;case"w:br":case"w:cr":"page"===a.attrs["w:type"]?l+='<span data-page-break contenteditable="false"></span>':"column"===a.attrs["w:type"]?l+=L(t,c(N(t,a)),"mark",""):l+="<br>";break;case"w:drawing":l+=F(t,a,c);break;case"mc:AlternateContent":case"w:pict":case"w:object":t.doc.notices.objects++,l+=L(t,c(N(t,a)),"object",s(a,new Set(["wps:txbx","w:txbxContent","v:textbox"])).length?`${t.labels.textBox}: ${B(s(a,new Set(["wps:txbx","w:txbxContent","v:textbox"]))[0]).slice(0,80)}`:t.labels.object);break;case"w:footnoteReference":{const e=a.attrs["w:id"],n=T(t,"x");t.doc.raw.set(n,c(N(t,a))),l+=`<span data-raw="${n}" data-kind="note" data-note="${I(e)}" contenteditable="false"></span>`;break}case"w:endnoteReference":{const e=++t.footnoteCount;t.doc.notices.footnotes++;const n=t.footnotes.get(a.attrs["w:id"]);l+=L(t,c(N(t,a)),"endnote",String(e),n?` title="${I(n)}"`:"");break}default:l+=L(t,c(N(t,a)),"mark","")}if(!l)return"";if(n.vert&&(l=`<${"sub"===n.vert?"sub":"sup"}>${l}</${"sub"===n.vert?"sub":"sup"}>`),a){const e=T(t,"r");t.doc.runs.set(e,o);const s=h(n),c=r(a,"w:rStyle")?.attrs["w:val"];l=`<span data-r="${e}"${c?` data-rstyle="${I(c)}"`:""}${s?` style="${I(s)}"`:""}>${l}</span>`}for(const e of t.openComments)l=`<span data-comment="${I(e)}" title="${I(t.comments.get(e)??"")}">${l}</span>`;return l}function q(t,e){let a="",n=0,r=-1,s=-1,c="",l="",d=!1;const i=()=>{if(r>=0){const e=Q(l);a+=L(t,t.src.slice(r,s),"field",c||t.labels.contents,e?` data-field="${e}"`:"")}l="",r=-1,c="",d=!1};for(const w of e){if("w:r"===w.name){const e=o(w,"w:fldChar");if(e.length||n>0){if(0===n&&(r=w.start,d=!1),d)c+=B(w);else for(const t of o(w,"w:instrText"))l+=t.text;for(const t of e){const e=t.attrs["w:fldCharType"];"begin"===e?n++:"separate"===e&&1===n?d=!0:"end"===e&&n--}s=w.end,0===n&&i();continue}a+=D(t,w);continue}if(n>0)s=w.end;else switch(w.name){case"w:pPr":case"w:proofErr":break;case"w:commentRangeStart":t.openComments.add(w.attrs["w:id"]);break;case"w:commentRangeEnd":t.openComments.delete(w.attrs["w:id"]);break;case"w:hyperlink":{const e=w.attrs["r:id"]?t.rels.get(w.attrs["r:id"]):void 0,n=w.attrs["w:anchor"],r=e?.target??(n?`#${n}`:""),o=C.test(r)||r.startsWith("#"),s=`${e?` data-rel="${I(w.attrs["r:id"])}"`:""}${n?` data-anchor="${I(n)}"`:""}`;a+=`<a${o?` href="${I(r)}"`:""}${s}>${q(t,w.children)}</a>`;break}case"w:ins":case"w:moveTo":a+=`<ins${H(w)}>${q(t,w.children)}</ins>`;break;case"w:del":case"w:moveFrom":a+=`<del${H(w)}>${q(t,w.children)}</del>`;break;case"w:bookmarkStart":{const e=w.attrs["w:name"]??"",n=T(t,"x");t.doc.raw.set(n,N(t,w)),a+=e&&!e.startsWith("_")?`<span data-raw="${n}" data-kind="mark" data-bookmark="${I(e)}" contenteditable="false"></span>`:`<span data-raw="${n}" data-kind="mark"${e.startsWith("_Toc")?` data-toc-anchor="${I(e)}"`:""}></span>`;break}case"w:bookmarkEnd":case"w:permStart":case"w:permEnd":default:a+=R(t,N(t,w));break;case"m:oMath":case"m:oMathPara":t.doc.notices.objects++,a+=L(t,N(t,w),"object",t.labels.equation);break;case"w:fldSimple":case"w:sdt":case"w:smartTag":case"w:customXml":{const e="w:fldSimple"===w.name?Q(w.attrs["w:instr"]??""):"";a+=L(t,N(t,w),"field",B(w)||t.labels.contents,e?` data-field="${e}"`:"");break}}}return n>0&&(a+=$(c)),a}function W(t){return s(t,S).length>0}function H(t){const e=t.attrs;return`${e["w:id"]?` data-tid="${I(e["w:id"])}"`:""}${e["w:author"]?` data-author="${I(e["w:author"])}"`:""}${e["w:date"]?` data-date="${I(e["w:date"])}"`:""}`}function z(t,e){const a=r(e,"w:pPr"),n=r(a,"w:pStyle")?.attrs["w:val"],o=r(a,"w:numPr")??function(t,e){let a;for(const n of E(t,e))a=r(r(n,"w:pPr"),"w:numPr")??a;return a}(t,n),s=r(o,"w:numId")?.attrs["w:val"];if(!s||"0"===s)return null;const c=Number(r(o,"w:ilvl")?.attrs["w:val"]??0),l=t.numbering.get(s)?.get(c);return{numId:s,ilvl:c,ordered:l?.ordered??!1,marker:l?.marker??"",check:l?.check}}function G(t){const e=[],a=r(t,"w:pBdr");for(const t of["top","bottom","left","right"]){const n=r(a,`w:${t}`);if(!n||"nil"===n.attrs["w:val"]||"none"===n.attrs["w:val"])continue;const o=/^[0-9a-fA-F]{6}$/.test(n.attrs["w:color"]??"")?`#${n.attrs["w:color"]}`:"currentcolor";e.push(`border-${t}:${(Number(n.attrs["w:sz"])||4)/8}pt solid ${o}`)}const n=r(t,"w:shd")?.attrs["w:fill"];return n&&/^[0-9a-fA-F]{6}$/.test(n)&&e.push(`background-color:#${n}`),e.join(";")}function U(t,e,a){const n=r(e,"w:pPr"),o=r(n,"w:pStyle")?.attrs["w:val"],d=t.fieldOpen,i=function(t){let e=0;for(const a of s(t,new Set(["w:fldChar"]))){const t=a.attrs["w:fldCharType"];"begin"===t?e++:"end"===t&&e--}return e}(e),w=W(e)||d||0!==i;i>0&&(t.fieldOpen=!0),d&&i<0&&(t.fieldOpen=!1);const m=T(t,"p");t.doc.blocks.set(m,{xml:N(t,e),fingerprint:"",props:A(t,n),numId:a?.numId,ilvl:a?.ilvl});const p=a?0:function(t,e){if(!e)return 0;const a=r(t.styles.get(e),"w:name")?.attrs["w:val"]??"",n=/^heading ([1-6])$/i.exec(a);return n?Number(n[1]):0}(t,o),f=a?"li":p?`h${p}`:"p",u=l(n);a&&delete u.indentLeft,a&&delete u.firstLine;const h=[c(u),b(u),G(n)].filter(Boolean).join(";");let $=w?_(t,e):q(t,e.children);$&&!/<br>(<\/[^>]+>)*$/.test($)||($+="<br>");const v=r(n,"w:pageBreakBefore")?" data-break-before":"",x=u.tabs?` data-tabs="${g(u.tabs)}"`:"",k=e.attrs["w14:paraId"]?` data-pid="${I(e.attrs["w14:paraId"])}"`:"",y=r(n,"w:sectPr");let P="";if(y){const e=t.sectionTypes[++t.sectionIndex]??"nextPage",a=Number(r(y,"w:cols")?.attrs["w:num"]??1);P=` data-section="${I(e)}"${a>1?` data-cols="${a}"`:""}`}const S=/<span data-raw="[^"]+" data-kind="mark" data-toc-anchor="([^"]+)"/.exec($)?.[1];return`<${f} data-docx="${m}"${k}${v}${P}${p&&S?` data-bm="${S}"`:""}${o?` data-pstyle="${I(o)}"`:""}${x}${h?` style="${I(h)}"`:""}${w?' data-locked contenteditable="false"':""}>${$}</${f}>`}function _(t,e){let a="";for(const n of e.children)"w:pPr"!==n.name&&"w:rPr"!==n.name&&"w:instrText"!==n.name&&"w:delInstrText"!==n.name&&("w:ins"===n.name||"w:moveTo"===n.name?a+=`<ins>${_(t,n)}</ins>`:"w:del"===n.name||"w:moveFrom"===n.name?a+=`<del>${_(t,n)}</del>`:"w:commentRangeStart"===n.name?t.openComments.add(n.attrs["w:id"]):"w:commentRangeEnd"===n.name?t.openComments.delete(n.attrs["w:id"]):"w:t"===n.name||"w:delText"===n.name?a+=$(n.text):"w:tab"===n.name?a+="\t":"w:br"===n.name?a+="<br>":"w:drawing"===n.name||"mc:AlternateContent"===n.name||"w:pict"===n.name?a+=`<span data-kind="object">${$(t.labels.object)}</span>`:a+=_(t,n));return a}function K(t,e){const a=T(t,"t"),n=r(e,"w:tblPr"),s=r(e,"w:tblGrid"),c=o(e,"w:tr"),l=c.some(t=>r(r(t,"w:trPr"),"w:gridBefore")||r(r(t,"w:trPr"),"w:gridAfter")),d=W(e)||l;l&&t.doc.notices.objects++,t.doc.blocks.set(a,{xml:N(t,e),fingerprint:"",props:A(t,n),tblGrid:A(t,s)});const i=r(n,"w:tblStyle")?.attrs["w:val"],w=o(s,"w:gridCol").map(t=>Number(t.attrs["w:w"])/20),m=new Map,p=c.map(t=>{const e=[];let a=0;for(const n of o(t,"w:tc")){const t=r(n,"w:tcPr"),o=Number(r(t,"w:gridSpan")?.attrs["w:val"]??1),s=r(t,"w:vMerge");if(s&&"restart"!==s.attrs["w:val"]&&m.has(a))m.get(a).rowSpan++;else{const t={node:n,rowSpan:1,col:a,span:o};e.push(t),s?m.set(a,t):m.delete(a)}a+=o}return e}),f=function(t,e,a){let n=r(e,"w:tblBorders");if(!n)for(const e of E(t,a))n=r(r(e,"w:tblPr"),"w:tblBorders")??n;return!!n&&n.children.some(t=>!["nil","none"].includes(t.attrs["w:val"]))}(t,n,i),u=c.map((e,a)=>{const n=T(t,"t");t.doc.blocks.set(n,{xml:"",fingerprint:"",props:A(t,r(e,"w:trPr"))});return`<tr data-docx="${n}">${p[a].map(e=>{const a=T(t,"t"),n=r(e.node,"w:tcPr");t.doc.blocks.set(a,{xml:"",fingerprint:"",props:A(t,n)});const o=r(n,"w:shd")?.attrs["w:fill"],s=[];o&&/^[0-9a-fA-F]{6}$/.test(o)&&s.push(`background-color:#${o.toLowerCase()}`);const c=r(n,"w:vAlign")?.attrs["w:val"];return"center"===c&&s.push("vertical-align:middle"),"bottom"===c&&s.push("vertical-align:bottom"),`<td data-docx="${a}"${e.span>1?` colspan="${e.span}"`:""}${e.rowSpan>1?` rowspan="${e.rowSpan}"`:""}${s.length?` style="${s.join(";")}"`:""}>${Z(t,e.node.children)}</td>`}).join("")}</tr>`}).join(""),h=w.length?`<colgroup>${w.map(t=>`<col style="width:${Math.round(100*t)/100}pt">`).join("")}</colgroup>`:"";return`<table data-docx="${a}"${i?` data-tstyle="${I(i)}"`:""}${f?"":" data-no-borders"}${d?' data-locked contenteditable="false"':""}>${h}<tbody>${u}</tbody></table>`}function Z(t,e){const a=[],n=[],c=t=>{for(;n.length>t;){const t=n.pop();a.push(`</li></${t.tag}>`)}};for(const l of e){const e="w:p"===l.name?z(t,l):null;if(e){for(;n.length&&n[n.length-1].ilvl>e.ilvl;)c(n.length-1);const r=n[n.length-1],o=r&&(!(!r.check||!e.check)||r.numId===e.numId&&r.tag===(e.ordered?"ol":"ul"));r&&r.ilvl===e.ilvl&&!o&&c(n.length-1);const s=`${e.numId}:${e.ilvl}`,d=t.listCounters.get(s)??0;t.listCounters.set(s,d+1);let i=U(t,l,e);"done"===e.check&&(i=i.replace(/^<li /,"<li data-checked "));const w=n[n.length-1];if(w&&w.ilvl===e.ilvl)a.push(`</li>${i.slice(0,i.lastIndexOf("</li>"))}`);else{const t=e.ordered?"ol":"ul",r=e.marker?` style="list-style-type:${e.marker}"`:"",o=e.ordered&&d?` start="${d+1}"`:"",s=e.check?" data-checklist":` data-num-id="${I(e.numId)}"`;a.push(`<${t}${s} data-ilvl="${e.ilvl}"${o}${r}>${i.slice(0,i.lastIndexOf("</li>"))}`),n.push({tag:t,numId:e.numId,ilvl:e.ilvl,check:!!e.check})}continue}if("w:tcPr"!==l.name&&"w:sectPr"!==l.name)if(c(0),"w:p"===l.name)a.push(U(t,l,null));else if("w:tbl"===l.name)a.push(K(t,l));else if("w:sdt"===l.name&&J(l)){const e=T(t,"p");t.doc.blocks.set(e,{xml:N(t,l),fingerprint:""});const n=o(r(l,"w:sdtContent"),"w:p").map(t=>{const e=Number(/(\d)$/.exec(r(r(t,"w:pPr"),"w:pStyle")?.attrs["w:val"]??"")?.[1]??1),a=s(t,new Set(["w:hyperlink"]))[0]?.attrs["w:anchor"]??"",n=B(t).replace(/\s+/g," ").trim();return X(e,a,n.replace(/\t?\s*\d+$/,""),/(\d+)$/.exec(n)?.[1]??"")}).join("");a.push(`<div data-docx="${e}" data-toc contenteditable="false">${n}</div>`)}else if("w:sdt"===l.name){const e=T(t,"p");t.doc.blocks.set(e,{xml:N(t,l),fingerprint:""}),t.doc.notices.objects++;const n=Z(t,o(r(l,"w:sdtContent"),"w:p"));a.push(`<div data-docx="${e}" data-locked contenteditable="false">${n}</div>`)}else{const e=T(t,"p");t.doc.blocks.set(e,{xml:N(t,l),fingerprint:""}),a.push(`<div data-docx="${e}" data-locked data-hidden contenteditable="false"></div>`)}}return c(0),a.join("")}function J(t){const e=r(r(r(t,"w:sdtPr"),"w:docPartObj"),"w:docPartGallery")?.attrs["w:val"]??"";return/table of contents/i.test(e)}function X(t,e,a,n){const r=/^[A-Za-z0-9_]+$/.test(e)?e:"";return`<p data-toc-level="${Math.min(Math.max(t,1),9)}">${r?`<a href="#${r}" data-anchor="${r}">${$(a)}</a>`:$(a)}<span data-toc-page>${$(n)}</span></p>`}function Q(t){const e=t.trim().split(/\s+/)[0]?.toUpperCase();return"PAGE"===e?"page":"NUMPAGES"===e||"SECTIONPAGES"===e?"pages":""}function V(t){if("LI"!==t.tagName&&!t.hasAttribute("data-pid"))return t.outerHTML;const e=t.cloneNode(!0);return e.removeAttribute("data-pid"),"LI"===t.tagName&&Array.from(e.children).forEach(t=>{"UL"!==t.tagName&&"OL"!==t.tagName||t.remove()}),e.outerHTML}function Y(t,e=t.html){const a=document.createElement("div");a.innerHTML=e,a.querySelectorAll("[data-docx]").forEach(e=>{const a=t.blocks.get(e.getAttribute("data-docx"));a&&(a.fingerprint=V(e))})}function tt(t,e){const a=e?w(t.doc.parts,e):void 0;if(!e||!a)return{text:"",html:"",editable:!0};const n=i(a),r=0===s(n,new Set(["w:sdt","mc:AlternateContent","w:pict","w:txbxContent"])).length,o={src:t.src,rels:t.rels,notices:{...t.doc.notices}};t.src=a,t.rels=new Map(m(t.doc.parts,e).map(t=>[t.id,t]));let c="";try{c=Z(t,n.children)}finally{t.src=o.src,t.rels=o.rels,t.doc.notices=o.notices}return{text:et(n),html:r?c:`<div data-locked contenteditable="false">${c}</div>`,editable:r,part:e}}function et(t){return t.children.filter(t=>"w:p"===t.name).map(t=>{let e="",a="",n=!1;const r=t=>{for(const o of t.children)if("w:t"===o.name)n||(e+=o.text);else if("w:tab"===o.name)n||(e+=" | ");else if("w:instrText"===o.name)a+=o.text;else if("w:fldChar"===o.name){const t=o.attrs["w:fldCharType"];"separate"!==t&&"end"!==t||(a&&(e+=at(a),a=""),n="separate"===t)}else"w:fldSimple"===o.name?e+=at(o.attrs["w:instr"]??"")||o.children.map(B).join(""):"w:pPr"!==o.name&&"w:rPr"!==o.name&&r(o)};return r(t),e}).filter(Boolean).join(" ")}function at(t){const e=Q(t);return e?`{${e}}`:""}function nt(t,e,a){return 1===t&&e?"first":t%2==0&&a?"even":"default"}function rt(t){const e=document.createElement("div");e.innerHTML=t,e.querySelectorAll('[data-field="page"]').forEach(t=>t.replaceWith("{page}")),e.querySelectorAll('[data-field="pages"]').forEach(t=>t.replaceWith("{pages}")),e.querySelectorAll('img,[data-kind="object"],[data-hidden]').forEach(t=>t.remove());const a=Array.from(e.querySelectorAll("p,h1,h2,h3,h4,h5,h6,li")).map(t=>(t.textContent??"").replace(/\t/g," | ").trim()).filter(Boolean);return a.length?a.join(" "):(e.textContent??"").trim()}async function ot(t,e={}){return st(await f(t),t,e)}function st(f,b,g={}){const $=m(f,"").find(t=>t.type.endsWith("/officeDocument")),x=$?u("",$.target):"word/document.xml",y=w(f,x);if(!y)throw new Error("Not a Word document");const S=i(y),j=r(S,"w:body");if(!j)throw new Error("Not a Word document");const C=m(f,x),I=t=>{const e=(t=>C.find(e=>e.type===t))(t);return e?u(x,e.target):void 0},T=p(I(n.theme)?w(f,I(n.theme)):void 0),N={parts:f,docPath:x,source:b,html:"",css:"",page:{...a},headers:k(),footers:k(),titlePage:!1,evenOdd:!1,columns:1,footnotes:new Map,blocks:new Map,runs:new Map,raw:new Map,notices:{comments:0,tracked:0,objects:0,footnotes:0},styles:[],theme:T},A={src:y,doc:N,labels:g.labels??v,rels:new Map(C.map(t=>[t.id,t])),theme:T,imageUrl:g.imageUrl??M,styles:new Map,numbering:new Map,listCounters:new Map,comments:new Map,footnotes:new Map,nextId:0,footnoteCount:0,openComments:new Set,fieldOpen:!1,sectionTypes:[],sectionIndex:0},L=I(n.styles),R=L?w(f,L):void 0,F=R?i(R):void 0;for(const t of o(F,"w:style"))A.styles.set(t.attrs["w:styleId"],t);const D=new Set(A.styles.keys());for(const[e,a]of Object.entries(t))D.has(e)||A.styles.set(e,i(a.xml));const q=r(F,"w:docDefaults");N.lang=r(r(r(q,"w:rPrDefault"),"w:rPr"),"w:lang")?.attrs["w:val"],N.css=function(t,e){const a=[],n=d(r(r(e,"w:rPrDefault"),"w:rPr"),t.theme),o=l(r(r(e,"w:pPrDefault"),"w:pPr"));t.doc.defaultFont=n.font,t.doc.defaultSize=n.size;let s=n,i=o;for(const[e,w]of t.styles){const m=w.attrs["w:type"];if("paragraph"!==m&&"character"!==m&&"table"!==m)continue;let p={},f={};for(const a of E(t,e))p={...p,...d(r(a,"w:rPr"),t.theme)},f={...f,...l(r(a,"w:pPr"))};if("paragraph"===m)a.push(`.docs-page [data-pstyle=${O(e)}]{${[h(p),c(f)].filter(Boolean).join(";")}}`),"1"===w.attrs["w:default"]&&(s={...n,...p},i={...o,...f});else if("character"===m)a.push(`.docs-page [data-rstyle=${O(e)}]{${h(p)}}`);else{const t=c(f);t&&a.push(`.docs-page table[data-tstyle=${O(e)}] p{${t}}`)}}return a.unshift(`.docs-page{${h(s)}}`,`.docs-page p,.docs-page h1,.docs-page h2,.docs-page h3,.docs-page h4,.docs-page h5,.docs-page h6,.docs-page li{${c(i)}}`),a.join("\n")}(A,q);const W=new Set(Object.keys(t));N.styles=[...A.styles.values()].filter(t=>"paragraph"===t.attrs["w:type"]&&"1"!==t.attrs["w:default"]&&(W.has(t.attrs["w:styleId"])||r(t,"w:qFormat"))&&!r(t,"w:hidden")&&!r(t,"w:semiHidden")).map(t=>({id:t.attrs["w:styleId"],name:r(t,"w:name")?.attrs["w:val"]??t.attrs["w:styleId"]}));const H=I(n.numbering),z=H?w(f,H):void 0;z&&function(t,a){const n=new Map;for(const t of o(a,"w:abstractNum")){const a=new Map;for(const n of o(t,"w:lvl")){const t=r(n,"w:numFmt")?.attrs["w:val"]??"decimal",o=r(n,"w:lvlText")?.attrs["w:val"],s="bullet"===t&&o===e.open?"open":"bullet"===t&&o===e.done?"done":void 0;a.set(Number(n.attrs["w:ilvl"]),{ordered:"bullet"!==t&&"none"!==t,marker:ct[t]??"",check:s})}n.set(t.attrs["w:abstractNumId"],a)}for(const e of o(a,"w:num")){const a=n.get(r(e,"w:abstractNumId")?.attrs["w:val"]??"");a&&t.numbering.set(e.attrs["w:numId"],a)}}(A,i(z));const G=I(n.comments),U=G?w(f,G):void 0;if(U){for(const t of o(i(U),"w:comment"))A.comments.set(t.attrs["w:id"],`${t.attrs["w:author"]??""}: ${B(t)}`);N.notices.comments=A.comments.size}const _=I(n.footnotes),K=_?w(f,_):void 0;if(K)for(const t of o(i(K),"w:footnote")){const e=t.attrs["w:id"];if(A.footnotes.set(e,B(t)),t.attrs["w:type"]&&"normal"!==t.attrs["w:type"])continue;const a=0===s(t,new Set(["w:tbl","w:drawing","w:pict","mc:AlternateContent","w:sdt","m:oMath"])).length;N.footnotes.set(e,{text:B(t).trim(),xml:K.slice(t.start,t.end),editable:a})}N.notices.tracked=s(j,P).length;const J=r(j,"w:sectPr"),X=[...s(j,new Set(["w:sectPr"])).filter(t=>t!==J),...J?[J]:[]];A.sectionTypes=X.map(t=>r(t,"w:type")?.attrs["w:val"]??"nextPage"),A.sectionIndex=0,N.columns=Math.max(1,Number(r(J,"w:cols")?.attrs["w:num"]??1)||1),N.titlePage=!!r(J,"w:titlePg")&&"0"!==r(J,"w:titlePg")?.attrs["w:val"];const Q=I(n.settings),V=Q?w(f,Q):void 0;N.evenOdd=!!V&&/<w:evenAndOddHeaders(?![^>]*w:val="(?:0|false)")[^>]*\/?>/.test(V);const et=r(J,"w:pgSz"),at=r(J,"w:pgMar"),nt=(t,e,a)=>{const n=Number(t?.attrs[e]);return Number.isFinite(n)&&void 0!==t?.attrs[e]?n:a};N.page={width:nt(et,"w:w",a.width),height:nt(et,"w:h",a.height),top:Math.abs(nt(at,"w:top",a.top)),right:nt(at,"w:right",a.right),bottom:Math.abs(nt(at,"w:bottom",a.bottom)),left:nt(at,"w:left",a.left),header:nt(at,"w:header",a.header),footer:nt(at,"w:footer",a.footer)};const rt=(t,e)=>{const a=o(J,t).find(t=>(t.attrs["w:type"]??"default")===e),n=a&&A.rels.get(a.attrs["r:id"]);return n?u(x,n.target):void 0};N.html=Z(A,j.children);for(const t of["default","first","even"])N.headers[t]=tt(A,rt("w:headerReference",t)),N.footers[t]=tt(A,rt("w:footerReference",t));N.html||(N.html="<p><br></p>"),Y(N),N.footnotesRead=new Map([...N.footnotes].map(([t,e])=>[t,e.text]));for(const t of[N.headers,N.footers])for(const e of Object.values(t))e.html&&Y(N,e.html);return N}var ct={lowerLetter:"lower-alpha",upperLetter:"upper-alpha",lowerRoman:"lower-roman",upperRoman:"upper-roman",decimalZero:"decimal-leading-zero"};export{X as tocEntryHtml,V as fingerprintOf,Y as stampFingerprints,nt as headerKindFor,rt as marginTextOfHtml,ot as readDocx,st as readParts};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ENGLISH_WORDS as r}from"./chunk-
|
|
1
|
+
import{ENGLISH_WORDS as r}from"./chunk-VMUUFEWS.js";import{createContext as e,useContext as o}from"react";import{jsx as t}from"react/jsx-runtime";var n=e(r);function a({words:r,children:e}){return t(n.Provider,{value:r,children:e})}var i=()=>o(n);import{createContext as s,useContext as c}from"react";import{jsx as d}from"react/jsx-runtime";var m=class extends Error{},u=s({});function l({value:r,children:e}){return d(u.Provider,{value:r,children:r.words?d(a,{words:r.words,children:e}):e})}var v=()=>c(u);export{a as DocumentsWordsProvider,i as useDocumentsWords,m as DocumentsConflict,l as DocumentsProvider,v as useDocumentsHost};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readDocx as t}from"./chunk-
|
|
1
|
+
import{readDocx as t}from"./chunk-7B4B25DB.js";import{titleOf as a}from"./chunk-XYVQTQ6N.js";async function r(r,i){const e=new Uint8Array(await i.arrayBuffer());await t(e);const n=a(i.name),c=await r.create(n);try{await r.save(c.id,e,c.version)}catch(t){throw await r.remove(c.id).catch(()=>{}),t}return{id:c.id,title:n}}export{r as importDocumentFile};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","LI","TR","TABLE","UL","OL","TBODY"]);function t(t){let o="";const a=t=>{for(const n of Array.from(t.childNodes)){if(3===n.nodeType){o+=(n.nodeValue??"").replace(//g,"");continue}if(1!==n.nodeType)continue;const t=n;if("BR"===t.tagName){o+="\n";continue}if("DEL"===t.tagName||t.hasAttribute("data-hidden"))continue;if("object"===t.getAttribute("data-kind")||"mark"===t.getAttribute("data-kind"))continue;if("TD"===t.tagName||"TH"===t.tagName){a(t),o=`${o.replace(/\n+$/,"")}\t`;continue}const r=e.has(t.tagName);a(t),r&&!o.endsWith("\n")&&(o+="\n")}};return a(t),o.replace(/\t\n/g,"\n").replace(/\n+$/,"\n")}function o(e){return(e.match(/[-ヿ㐀-鿿豈-]/g)?.length??0)+(e.replace(/[-ヿ㐀-鿿豈-]/g," ").match(/\S+/g)?.length??0)}function a(t,o,a){if(!o)return[];const n=function(e){const t=[],o=e=>{for(const a of Array.from(e.childNodes))if(3===a.nodeType)t.push(a);else if(1===a.nodeType){const e=a;if("false"===e.getAttribute("contenteditable")||e.hasAttribute("data-raw"))continue;o(e)}};return o(e),t}(t),r=o=>{let a=o.parentNode;for(;a&&a!==t&&!e.has(a.tagName)&&"TD"!==a.tagName;)a=a.parentNode;return a},d=[];let c=0;for(;c<n.length;){const e=r(n[c]);let t=c;const i=[];for(;t<n.length&&r(n[t])===e;)i.push(n[t++]);const s=i.map(e=>e.nodeValue??"").join(""),l=a?s:s.toLowerCase(),p=a?o:o.toLowerCase(),g=l.length===s.length?l:s;for(let e=g.indexOf(p);e>=0;e=g.indexOf(p,e+p.length)){const t=[];let o=0;for(const a of i){const n=(a.nodeValue??"").length,r=Math.max(e,o),d=Math.min(e+p.length,o+n);r<d&&t.push({node:a,start:r-o,end:d-o}),o+=n}d.push(t)}c=t}return d}function n(e,t){e.forEach((e,o)=>{const a=e.node.nodeValue??"";e.node.nodeValue=a.slice(0,e.start)+(0===o?t:"")+a.slice(e.end)})}function r(e,t){const o=[0];if(t<=0)return o;let a=0;for(const n of e)if(n.breakBefore&&n.top>a&&(a=n.top,o.push(a)),!(n.top+n.height-a<=t))if(n.height<=t)n.top>a&&(a=n.top,o.push(a));else for(;n.top+n.height-a>t;)a+=t,o.push(a);return o}function d(e,t,o=1){const a=[],n=e=>{const n=e.getBoundingClientRect();a.push({top:(n.top-t)/o,height:n.height/o,breakBefore:e.hasAttribute("data-break-before")})};for(const r of Array.from(e.children))"TABLE"===r.tagName?r.querySelectorAll("tr").forEach(n):"UL"===r.tagName||"OL"===r.tagName?r.querySelectorAll("li").forEach(n):n(r),r.querySelectorAll("[data-page-break]").forEach(e=>{const n=e.getBoundingClientRect();a.push({top:(n.bottom-t)/o,height:0,breakBefore:!0})});return a}var c=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","UL","OL","LI","TABLE","THEAD","TBODY","TFOOT","TR","TD","TH","COLGROUP","COL","B","STRONG","I","EM","U","S","STRIKE","SUB","SUP","SPAN","FONT","A","BR","IMG","PRE","HR"]),i=new Set(["SCRIPT","STYLE","TITLE","META","LINK","OBJECT","EMBED","IFRAME","NOSCRIPT","TEMPLATE","SVG","MATH","FORM","INPUT","BUTTON","SELECT","TEXTAREA","VIDEO","AUDIO","CANVAS"]),s=new Set(["color","background-color","font-weight","font-style","text-decoration-line","text-decoration","font-family","font-size","text-align","margin-left","line-height","width","height","list-style-type"]),l=/^(https?:|mailto:|tel:|#)/i,p=/^(data:image\/(png|jpe?g|gif|webp|bmp);base64,|blob:)/i;function g(e){const t=document.implementation.createHTMLDocument("");t.body.innerHTML=e;const o=(e,t,a)=>{for(const n of Array.from(e.childNodes)){if(3===n.nodeType){t.appendChild(a.createTextNode(n.nodeValue??""));continue}if(1!==n.nodeType)continue;const e=n,r=e.tagName.toUpperCase();if(i.has(r))continue;if(!c.has(r)){o(e,t,a);continue}if("IMG"===r&&!p.test(e.getAttribute("src")??""))continue;const d=a.createElement(r),g=(e.getAttribute("style")??"").split(";").map(e=>{const t=e.indexOf(":");if(t<0)return"";const o=e.slice(0,t).trim().toLowerCase(),a=e.slice(t+1).trim();return s.has(o)&&!/url\(|expression|mso-/i.test(a)?`${o}:${a}`:""}).filter(Boolean).join(";");g&&d.setAttribute("style",g),"A"===r&&l.test(e.getAttribute("href")??"")&&d.setAttribute("href",e.getAttribute("href")),"IMG"===r&&d.setAttribute("src",e.getAttribute("src"));for(const t of["colspan","rowspan","start","color","face","size"]){const o=e.getAttribute(t);null!==o&&d.setAttribute(t,o)}o(e,d,a),t.appendChild(d)}},a=document.createElement("div");return o(t.body,a,document),a.innerHTML}import{escapeHtml as f}from"efficient-shell/ui";var u='\nhtml,body{margin:0;background:#fff}\n.docs-page [data-comment]{background:none;border:0}\n.docs-page [data-locked]{background:none;box-shadow:none}\n.docs-page [data-page-break]{break-after:page;border:0;margin:0}\n.docs-page [data-section]::after{display:none}\n.docs-page [data-section="nextPage"]{break-after:page}\n.docs-page [data-bookmark]{display:none}\n.docs-page [data-break-before]{break-before:page}\n.docs-page tr,.docs-page img{break-inside:avoid}\n';function h(e,t){return`\n.docs-sheet{background:#fff;color:#777}\n.docs-sheet-line{border-color:#aaa}\n\n${`\n.docs-page{color:#000;background:#fff;white-space:pre-wrap;overflow-wrap:break-word;outline:none;line-height:1.08;tab-size:36pt;font-family:Calibri,Carlito,Arial,sans-serif;font-size:11pt}\n.docs-page p,.docs-page h1,.docs-page h2,.docs-page h3,.docs-page h4,.docs-page h5,.docs-page h6{margin:0;font:inherit;font-weight:400}\n.docs-page ul,.docs-page ol{margin:0;padding-left:24pt}\n.docs-page ul{list-style-type:disc}.docs-page ol{list-style-type:decimal}\n.docs-page ul ul{list-style-type:circle}.docs-page ul ul ul{list-style-type:square}\n.docs-page a{color:#0563c1;text-decoration:underline}\n.docs-page sub,.docs-page sup{font-size:.66em}\n.docs-page img{max-width:100%}\n.docs-page table{border-collapse:collapse;table-layout:fixed;width:100%}\n.docs-page td,.docs-page th{border:.5pt solid #000;padding:0 5.4pt;vertical-align:top}\n.docs-page table[data-no-borders] td,.docs-page table[data-no-borders] th{border:.5pt dotted #bbb}\n.docs-page td p{margin-bottom:0}\n.docs-page blockquote{margin:0 0 8pt 24pt;font-style:italic}\n.docs-page hr{border:0;border-top:.75pt solid #000;margin:6pt 0}\n.docs-page [data-hidden]{display:none}\n.docs-page [data-page-break]{display:block;height:0;border-top:1pt dashed #999;margin:6pt 0;user-select:none}\n.docs-page [data-comment]{background:#fff2cc;border-bottom:1.5pt solid #e0b000}\n.docs-page [data-locked]{background:#f4f4f4;box-shadow:-5pt 0 0 #bbb;cursor:not-allowed}\n.docs-page ins{color:#c00000;text-decoration:underline}\n.docs-page del{color:#c00000;text-decoration:line-through}\n.docs-page [data-kind="object"]{display:inline-block;background:#f4f4f4;border:.75pt dashed #999;color:#555;padding:1pt 5pt;cursor:not-allowed;white-space:normal}\n.docs-page [data-kind="field"]{background:#ededed}\n.docs-page{counter-reset:docs-note}\n.docs-page [data-kind="note"]{vertical-align:super;font-size:.66em}\n.docs-page [data-note]{counter-increment:docs-note;color:#0563c1;padding:0 1pt}\n.docs-page [data-note]::after{content:counter(docs-note)}\n.docs-page [data-kind="endnote"]{vertical-align:super;font-size:.66em}\n.docs-page ul[data-checklist]{list-style:none;padding-left:20pt}\n.docs-page ul[data-checklist]>li{position:relative}\n.docs-page ul[data-checklist]>li::before{content:"\\2610";position:absolute;left:-17pt;width:14pt;text-align:center;cursor:pointer}\n.docs-page ul[data-checklist]>li[data-checked]::before{content:"\\2611"}\n.docs-page ul[data-checklist]>li[data-checked]{text-decoration:line-through;color:#777}\n.docs-page [data-bookmark]{display:inline-block;width:7pt;height:9pt;margin:0 1pt;vertical-align:-1pt;background:#1a73e8;clip-path:polygon(0 0,100% 0,100% 100%,50% 70%,0 100%);cursor:default}\n.docs-page [data-toc]{margin:6pt 0;padding:4pt 0;border-top:.5pt solid #ddd;border-bottom:.5pt solid #ddd;cursor:pointer}\n.docs-page [data-toc] p{display:flex;gap:6pt;margin:0 0 3pt}\n.docs-page [data-toc] p::after{content:"";order:1;flex:1;border-bottom:1pt dotted #999;margin-bottom:3pt}\n.docs-page [data-toc] [data-toc-page]{order:2}\n.docs-page [data-toc] [data-toc-level="2"]{padding-left:11pt}\n.docs-page [data-toc] [data-toc-level="3"]{padding-left:22pt}\n.docs-page [data-toc]:empty::before{color:#777;font-style:italic}\n.docs-page [data-section]::after{display:block;margin:6pt 0;border-top:2pt double #aaa;color:#888;font-size:8pt;text-align:center;line-height:1.6;user-select:none}\n.docs-page ::highlight(docs-find){background:#ffe680}\n.docs-page ::highlight(docs-find-current){background:#ff9f1a}\n\n${e.css}`.replaceAll(".docs-page",`.docs-page[data-doc="${t}"]`)}`}var b=e=>u.replaceAll(".docs-page",`.docs-page[data-doc="${e}"]`);function m(e,t,o){const a=e=>(e??"").replaceAll("{page}",String(t)).replaceAll("{pages}",String(o)),[n,r]=e.split(/\s*\|\s*/);return[a(n),a(r)]}function k(e,t){const[o,a]=function(e){return e.split(/\s*\|\s*/).map(e=>e.split(/(\{page\}|\{pages\})/).map(e=>"{page}"===e?"counter(page)":"{pages}"===e?"counter(pages)":e?`"${e.replace(/["\\\n\r]/g,"")}"`:"").filter(Boolean).join(" "))}(t),n="font:9pt Calibri,Carlito,Arial,sans-serif;color:#555";return`${o?`@${e}-left{content:${o};${n}}`:""}${a?`@${e}-right{content:${a};${n}}`:""}`}function y({title:e,html:t,doc:o,scope:a,page:n,header:r,footer:d}){const c=e=>Math.round(e)/20+"pt",i=`@page{size:${c(n.width)} ${c(n.height)};margin:${c(n.top)} ${c(n.right)} ${c(n.bottom)} ${c(n.left)};${k("top",r)}${k("bottom",d)}}`;return`<!doctype html><html><head><meta charset="utf-8"><meta name="generator" content="efficient-shell Documents"><title>${f(e)}</title><style>${h(o,a)}\n${b(a)}\n${i}</style></head><body><div class="docs-page" data-doc="${a}">${t}</div></body></html>`}export{t as documentText,o as countWords,a as findInNodes,n as replaceSpots,r as pageStarts,d as pageBlocks,g as sanitizeHtml,h as pageStyles,b as printStyles,m as marginText,y as pageDocument};
|
|
1
|
+
var e=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","LI","TR","TABLE","UL","OL","TBODY"]);function t(t){let o="";const a=t=>{for(const n of Array.from(t.childNodes)){if(3===n.nodeType){o+=(n.nodeValue??"").replace(//g,"");continue}if(1!==n.nodeType)continue;const t=n;if("BR"===t.tagName){o+="\n";continue}if("DEL"===t.tagName||t.hasAttribute("data-hidden"))continue;if("object"===t.getAttribute("data-kind")||"mark"===t.getAttribute("data-kind"))continue;if("TD"===t.tagName||"TH"===t.tagName){a(t),o=`${o.replace(/\n+$/,"")}\t`;continue}const d=e.has(t.tagName);a(t),d&&!o.endsWith("\n")&&(o+="\n")}};return a(t),o.replace(/\t\n/g,"\n").replace(/\n+$/,"\n")}function o(e){return(e.match(/[-ヿ㐀-鿿豈-]/g)?.length??0)+(e.replace(/[-ヿ㐀-鿿豈-]/g," ").match(/\S+/g)?.length??0)}function a(t,o,a){if(!o)return[];const n=function(e){const t=[],o=e=>{for(const a of Array.from(e.childNodes))if(3===a.nodeType)t.push(a);else if(1===a.nodeType){const e=a;if("false"===e.getAttribute("contenteditable")||e.hasAttribute("data-raw"))continue;o(e)}};return o(e),t}(t),d=o=>{let a=o.parentNode;for(;a&&a!==t&&!e.has(a.tagName)&&"TD"!==a.tagName;)a=a.parentNode;return a},c=[];let r=0;for(;r<n.length;){const e=d(n[r]);let t=r;const i=[];for(;t<n.length&&d(n[t])===e;)i.push(n[t++]);const s=i.map(e=>e.nodeValue??"").join(""),l=a?s:s.toLowerCase(),p=a?o:o.toLowerCase(),g=l.length===s.length?l:s;for(let e=g.indexOf(p);e>=0;e=g.indexOf(p,e+p.length)){const t=[];let o=0;for(const a of i){const n=(a.nodeValue??"").length,d=Math.max(e,o),c=Math.min(e+p.length,o+n);d<c&&t.push({node:a,start:d-o,end:c-o}),o+=n}c.push(t)}r=t}return c}function n(e,t){e.forEach((e,o)=>{const a=e.node.nodeValue??"";e.node.nodeValue=a.slice(0,e.start)+(0===o?t:"")+a.slice(e.end)})}function d(e,t){const o=[0];if(t<=0)return o;let a=0;for(const n of e)if(n.breakBefore&&n.top>a&&(a=n.top,o.push(a)),!(n.top+n.height-a<=t))if(n.height<=t)n.top>a&&(a=n.top,o.push(a));else for(;n.top+n.height-a>t;)a+=t,o.push(a);return o}function c(e,t,o=1){const a=[],n=e=>{const n=e.getBoundingClientRect();a.push({top:(n.top-t)/o,height:n.height/o,breakBefore:e.hasAttribute("data-break-before")})};for(const d of Array.from(e.children))"TABLE"===d.tagName?d.querySelectorAll("tr").forEach(n):"UL"===d.tagName||"OL"===d.tagName?d.querySelectorAll("li").forEach(n):n(d),d.querySelectorAll("[data-page-break]").forEach(e=>{const n=e.getBoundingClientRect();a.push({top:(n.bottom-t)/o,height:0,breakBefore:!0})});return a}var r=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","UL","OL","LI","TABLE","THEAD","TBODY","TFOOT","TR","TD","TH","COLGROUP","COL","B","STRONG","I","EM","U","S","STRIKE","SUB","SUP","SPAN","FONT","A","BR","IMG","PRE","HR"]),i=new Set(["SCRIPT","STYLE","TITLE","META","LINK","OBJECT","EMBED","IFRAME","NOSCRIPT","TEMPLATE","SVG","MATH","FORM","INPUT","BUTTON","SELECT","TEXTAREA","VIDEO","AUDIO","CANVAS"]),s=new Set(["color","background-color","font-weight","font-style","text-decoration-line","text-decoration","font-family","font-size","text-align","margin-left","line-height","width","height","list-style-type"]),l=/^(https?:|mailto:|tel:|#)/i,p=/^(data:image\/(png|jpe?g|gif|webp|bmp);base64,|blob:)/i;function g(e){const t=document.implementation.createHTMLDocument("");t.body.innerHTML=e;const o=(e,t,a)=>{for(const n of Array.from(e.childNodes)){if(3===n.nodeType){t.appendChild(a.createTextNode(n.nodeValue??""));continue}if(1!==n.nodeType)continue;const e=n,d=e.tagName.toUpperCase();if(i.has(d))continue;if(!r.has(d)){o(e,t,a);continue}if("IMG"===d&&!p.test(e.getAttribute("src")??""))continue;const c=a.createElement(d),g=(e.getAttribute("style")??"").split(";").map(e=>{const t=e.indexOf(":");if(t<0)return"";const o=e.slice(0,t).trim().toLowerCase(),a=e.slice(t+1).trim();return s.has(o)&&!/url\(|expression|mso-/i.test(a)?`${o}:${a}`:""}).filter(Boolean).join(";");g&&c.setAttribute("style",g),"A"===d&&l.test(e.getAttribute("href")??"")&&c.setAttribute("href",e.getAttribute("href")),"IMG"===d&&c.setAttribute("src",e.getAttribute("src"));for(const t of["colspan","rowspan","start","color","face","size"]){const o=e.getAttribute(t);null!==o&&c.setAttribute(t,o)}o(e,c,a),t.appendChild(c)}},a=document.createElement("div");return o(t.body,a,document),a.innerHTML}import{escapeHtml as f}from"efficient-shell/ui";var u='\nhtml,body{margin:0;background:#fff}\n.docs-page [data-comment]{background:none;border:0}\n.docs-page [data-locked]{background:none;box-shadow:none}\n.docs-page [data-page-break]{break-after:page;border:0;margin:0}\n.docs-page [data-section]::after{display:none}\n.docs-page [data-section="nextPage"]{break-after:page}\n.docs-page [data-bookmark]{display:none}\n.docs-page [data-break-before]{break-before:page}\n.docs-page tr,.docs-page img{break-inside:avoid}\n';function h(e,t){return`\n.docs-sheet{background:#fff;color:#777}\n.docs-sheet-line{border-color:#aaa}\n\n${`\n.docs-page{color:#000;background:#fff;white-space:pre-wrap;overflow-wrap:break-word;outline:none;line-height:1.08;tab-size:36pt;font-family:Calibri,Carlito,Arial,sans-serif;font-size:11pt}\n.docs-page p,.docs-page h1,.docs-page h2,.docs-page h3,.docs-page h4,.docs-page h5,.docs-page h6{margin:0;font:inherit;font-weight:400}\n.docs-page ul,.docs-page ol{margin:0;padding-left:24pt}\n.docs-page ul{list-style-type:disc}.docs-page ol{list-style-type:decimal}\n.docs-page ul ul{list-style-type:circle}.docs-page ul ul ul{list-style-type:square}\n.docs-page a{color:#0563c1;text-decoration:underline}\n.docs-page sub,.docs-page sup{font-size:.66em}\n.docs-page img{max-width:100%}\n.docs-page table{border-collapse:collapse;table-layout:fixed;width:100%}\n.docs-page td,.docs-page th{border:.5pt solid #000;padding:0 5.4pt;vertical-align:top}\n.docs-page table[data-no-borders] td,.docs-page table[data-no-borders] th{border:.5pt dotted #bbb}\n.docs-page td p{margin-bottom:0}\n.docs-page blockquote{margin:0 0 8pt 24pt;font-style:italic}\n.docs-page hr{border:0;border-top:.75pt solid #000;margin:6pt 0}\n.docs-page [data-hidden]{display:none}\n.docs-page [data-page-break]{display:block;height:0;border-top:1pt dashed #999;margin:6pt 0;user-select:none}\n.docs-page [data-comment]{background:#fff2cc;border-bottom:1.5pt solid #e0b000}\n.docs-page [data-locked]{background:#f4f4f4;box-shadow:-5pt 0 0 #bbb;cursor:not-allowed}\n.docs-page ins{color:#c00000;text-decoration:underline}\n.docs-page del{color:#c00000;text-decoration:line-through}\n.docs-page [data-kind="object"]{display:inline-block;background:#f4f4f4;border:.75pt dashed #999;color:#555;padding:1pt 5pt;cursor:not-allowed;white-space:normal}\n.docs-page [data-kind="field"]{background:#ededed}\n.docs-page{counter-reset:docs-note}\n.docs-page [data-kind="note"]{vertical-align:super;font-size:.66em}\n.docs-page [data-note]{counter-increment:docs-note;color:#0563c1;padding:0 1pt}\n.docs-page [data-note]::after{content:counter(docs-note)}\n.docs-page [data-kind="endnote"]{vertical-align:super;font-size:.66em}\n.docs-page ul[data-checklist]{list-style:none;padding-left:20pt}\n.docs-page ul[data-checklist]>li{position:relative}\n.docs-page ul[data-checklist]>li::before{content:"\\2610";position:absolute;left:-17pt;width:14pt;text-align:center;cursor:pointer}\n.docs-page ul[data-checklist]>li[data-checked]::before{content:"\\2611"}\n.docs-page ul[data-checklist]>li[data-checked]{text-decoration:line-through;color:#777}\n.docs-page [data-bookmark]{display:inline-block;width:7pt;height:9pt;margin:0 1pt;vertical-align:-1pt;background:#1a73e8;clip-path:polygon(0 0,100% 0,100% 100%,50% 70%,0 100%);cursor:default}\n.docs-page [data-toc]{margin:6pt 0;padding:4pt 0;border-top:.5pt solid #ddd;border-bottom:.5pt solid #ddd;cursor:pointer}\n.docs-page [data-toc] p{display:flex;gap:6pt;margin:0 0 3pt}\n.docs-page [data-toc] p::after{content:"";order:1;flex:1;border-bottom:1pt dotted #999;margin-bottom:3pt}\n.docs-page [data-toc] [data-toc-page]{order:2}\n.docs-page [data-toc] [data-toc-level="2"]{padding-left:11pt}\n.docs-page [data-toc] [data-toc-level="3"]{padding-left:22pt}\n.docs-page [data-toc]:empty::before{color:#777;font-style:italic}\n.docs-page [data-section]::after{display:block;margin:6pt 0;border-top:2pt double #aaa;color:#888;font-size:8pt;text-align:center;line-height:1.6;user-select:none}\n.docs-page ::highlight(docs-comment){background:#fde9a9}\n.docs-page ::highlight(docs-comment-active){background:#fbd25f}\n.docs-page ::highlight(docs-find){background:#ffe680}\n.docs-page[data-mode="viewing"] del{display:none}\n.docs-page[data-mode="viewing"] ins{color:inherit;text-decoration:none}\n.docs-page ins[data-author],.docs-page del[data-author]{color:#1a7f5a}\n.docs-page .docs-diff-ins{color:var(--docs-diff,#1a7f5a);text-decoration:underline;text-decoration-color:var(--docs-diff,#1a7f5a)}\n.docs-page .docs-diff-del{color:var(--docs-diff,#1a7f5a);text-decoration:line-through;opacity:.7}\n.docs-page .docs-diff-new{box-shadow:-4pt 0 0 var(--docs-diff,#1a7f5a)}\n.docs-page ::highlight(docs-find-current){background:#ff9f1a}\n\n${e.css}`.replaceAll(".docs-page",`.docs-page[data-doc="${t}"]`)}`}var b=e=>u.replaceAll(".docs-page",`.docs-page[data-doc="${e}"]`);function m(e,t,o){const a=e=>(e??"").replaceAll("{page}",String(t)).replaceAll("{pages}",String(o)),[n,d]=e.split(/\s*\|\s*/);return[a(n),a(d)]}function k(e,t){const[o,a]=function(e){return e.split(/\s*\|\s*/).map(e=>e.split(/(\{page\}|\{pages\})/).map(e=>"{page}"===e?"counter(page)":"{pages}"===e?"counter(pages)":e?`"${e.replace(/["\\\n\r]/g,"")}"`:"").filter(Boolean).join(" "))}(t),n="font:9pt Calibri,Carlito,Arial,sans-serif;color:#555";return`${o?`@${e}-left{content:${o};${n}}`:""}${a?`@${e}-right{content:${a};${n}}`:""}`}function y({title:e,html:t,doc:o,scope:a,page:n,header:d,footer:c}){const r=e=>Math.round(e)/20+"pt",i=`@page{size:${r(n.width)} ${r(n.height)};margin:${r(n.top)} ${r(n.right)} ${r(n.bottom)} ${r(n.left)};${k("top",d)}${k("bottom",c)}}`;return`<!doctype html><html><head><meta charset="utf-8"><meta name="generator" content="efficient-shell Documents"><title>${f(e)}</title><style>${h(o,a)}\n${b(a)}\n${i}</style></head><body><div class="docs-page" data-doc="${a}">${t}</div></body></html>`}export{t as documentText,o as countWords,a as findInNodes,n as replaceSpots,d as pageStarts,c as pageBlocks,g as sanitizeHtml,h as pageStyles,b as printStyles,m as marginText,y as pageDocument};
|