@stll/folio-vue
Advanced tools
| let e=require("vue"),t=require("@stll/folio-core/paged-layout/sectionGeometry"),n=require("@stll/folio-core/prosemirror/plugins/anonymizationDecorations"),r=require("@stll/folio-core/prosemirror/plugins/templateDirectives"),i=require("@stll/folio-core/prosemirror/plugins/suggestionMode"),a=require("@stll/folio-core/controller/folioEditor"),o=require("@stll/folio-core/controller/folioEditorEvents"),s=require("@stll/folio-core/controller/hiddenEditorManager"),c=require("@stll/folio-core/controller/layoutPipeline"),l=require("@stll/folio-core/controller/layoutScheduler"),u=require("@stll/folio-core/controller/layoutSession"),d=require("@stll/folio-core/docx/parser"),f=require("@stll/folio-core/docx/footnoteParser"),p=require("@stll/folio-core/layout-bridge/convert/headerFooterLayout"),m=require("@stll/folio-core/layout-engine"),h=require("@stll/folio-core/layout-painter"),g=require("@stll/folio-core/paged-layout/LayoutSelectionGate"),_=require("@stll/folio-core/paged-layout/transactionDirtyRange"),v=require("@stll/folio-core/prosemirror/conversion/fromProseDoc"),y=require("@stll/folio-core/prosemirror/extensions/ExtensionManager"),b=require("@stll/folio-core/prosemirror/extensions/features/ParagraphChangeTrackerExtension"),ee=require("@stll/folio-core/prosemirror/extensions/StarterKit"),te=require("@stll/folio-core/prosemirror/plugins/templatePreviewValues"),ne=require("@stll/folio-core/prosemirror/plugins/templateSlashMenu"),x=require("@stll/folio-core/utils/findVerticalScrollParent"),S=require("@stll/folio-core/prosemirror/tableResize"),C=require("@stll/folio-core/prosemirror/utils/extractTrackedChanges"),w=require("@stll/folio-core/utils/zoom");var re=24,ie=32,ae=96,oe=250,se=[];function ce(e){let n=e?.columnCount??1;if(n<=1)return;let r={count:n,gap:(0,t.twipsToPixels)(e?.columnSpace??720),equalWidth:e?.equalWidth??!0};return e?.separator!==void 0&&(r.separator=e.separator),r}var T={hf:null,rId:null};function le(e,t){let n=e?.package;if(!n||!t)return{header:T,footer:T,firstHeader:T,firstFooter:T};let r=n.headers,i=n.footers,a=e=>e?r?.get(e)??null:null,o=e=>e?i?.get(e)??null:null,s=null,c=null;for(let e of t.headerReferences??[])e.type==="default"?s=e.rId:e.type===`first`&&(c=e.rId);let l=null,u=null;for(let e of t.footerReferences??[])e.type==="default"?l=e.rId:e.type===`first`&&(u=e.rId);return{header:{hf:a(s),rId:s},footer:{hf:o(l),rId:l},firstHeader:{hf:a(c),rId:c},firstFooter:{hf:o(u),rId:u}}}function ue(e,t,n,r,i,a){if(!e)return;let o=t?{...a,rId:t}:a,s=t?n?.getView(t):null;return s?(0,p.convertHeaderFooterPmDocToContent)(s.state.doc,r,i,o):(0,p.convertHeaderFooterToContent)(e,r,i,o)}function de(e,t,n,r,i){if(!e||e.size===0)return;let a=new Map;for(let[o,s]of e){let e=ue(s,o,t,n,r,i);e&&a.set(o,e)}return a.size>0?a:void 0}function fe(e,t,n){let r=new Map;if(!n||!n.package.footnotes)return r;let i=new Map;for(let e of n.package.footnotes)e.noteType&&e.noteType!==`normal`||i.set(e.id,e);for(let[n,a]of e){let e=[];for(let n of a){let r=i.get(n);if(!r)continue;let a=t.get(n),o=a?.displayNumber??0;e.push({displayNumber:String(o),text:(0,f.getFootnoteText)(r),...a?{content:{blocks:a.blocks,measures:a.measures,height:a.height}}:{}})}e.length>0&&r.set(n,e)}return r}var E=new Set([`black`,`blue`,`cyan`,`darkBlue`,`darkCyan`,`darkGray`,`darkGreen`,`darkMagenta`,`darkRed`,`darkYellow`,`green`,`lightGray`,`magenta`,`none`,`red`,`white`,`yellow`]);function pe(e){let t=[],n=(e,r)=>{for(let[n,i]of e.marks.entries())i.type.name===`highlight`&&!E.has(String(i.attrs.color))&&t.push(`${r}.marks[${n}]=${JSON.stringify(i.attrs)}`);e.forEach((e,t,i)=>{n(e,`${r}.content[${i}]`)})};return n(e,`doc`),t.join(`; `)}function me(){return typeof document>`u`||!(`fonts`in document)||document.fonts.status===`loaded`}function D(f){let{hiddenContainer:p,pagesContainer:x,readOnly:S=!1,pageGap:C=re,documentKey:w,password:T,editorMode:E,author:D,externalPlugins:he=[],onAnonymizationMatchesChange:ge,showTemplateDirectives:_e,onSlashMenuChange:ve,onSlashMenuKeyAction:ye,onChange:be,onError:O,onSelectionUpdate:k,onEditorViewReady:A,onReadOnlyEditAttempt:j,featureFlags:M,onSelectiveSaveTripwire:N}=f,P=(0,e.shallowRef)(null),F=(0,e.shallowRef)(null),I=(0,e.shallowRef)(null),L=(0,e.shallowRef)(null),R=(0,e.shallowRef)([]),z=(0,e.shallowRef)([]),B=(0,e.ref)(!1),V=(0,e.ref)(null),H=(0,e.ref)(!1),U=new y.ExtensionManager((0,ee.createStarterKit)());U.buildSchema(),U.initializeRuntime();let xe=(0,i.createSuggestionModePlugin)(!1),Se=(0,n.createAnonymizationDecorationsPlugin)({onMatchesChange:e=>ge?.(e)}),W=(0,r.createTemplateDirectivesPlugin)(),G=(0,ne.templateSlashMenuPlugin)({onChange:e=>ve?.(e),onKeyAction:e=>ye?.(e)??!1}),Ce=(0,te.createTemplatePreviewValuesPlugin)(),K=()=>(0,e.toValue)(_e)===!0;function we(){return[xe,...he,Se,...K()?[W,G]:[],Ce]}let q=(0,o.createFolioEditorEmitter)(),J=new g.LayoutSelectionGate,Te=(0,u.createLayoutSession)(),Ee=new h.LayoutPainter({pageGap:C,showShadow:!0});function De(e){e.layout&&(L.value=e.layout),e.blocks&&(R.value=e.blocks),e.measures&&(z.value=e.measures),e.blockLookup&&Ee.setBlockLookup(e.blockLookup),e.layout&&q.emit(`layoutComplete`,e.layout)}function Y(e,n={}){let r=x.value,i=r instanceof HTMLDivElement?r:null,a=P.value,o=a?.package.document,s=o?.sections?.[0]?.properties??o?.finalSectionProperties??null,l=(0,t.getPageSize)(s),u=(0,t.getMargins)(s),d=ce(s),f=l.w-u.left-u.right,p=a?.package.styles??null,h=a?.package.theme??null,g=a?.package.settings?.defaultTabStop,_=a?.package.settings,v=_!==void 0&&`mirrorMargins`in _&&_.mirrorMargins===!0,y=le(a,s);try{De((0,c.runLayoutPipeline)({contentWidth:f,columns:d,pageSize:l,margins:u,pageGap:C,syncCoordinator:J,headerContent:y.header.hf,footerContent:y.footer.hf,firstPageHeaderContent:y.firstHeader.hf,firstPageFooterContent:y.firstFooter.hf,headerContentRId:y.header.rId,footerContentRId:y.footer.rId,firstPageHeaderContentRId:y.firstHeader.rId,firstPageFooterContentRId:y.firstFooter.rId,sectionHeaderFooterRefs:(0,m.resolveSectionHeaderFooterRefs)(a),theme:h,sectionProperties:s,document:a,defaultTabStop:g,mirrorMargins:v,styles:p,layout:L.value,hfPMs:null,painter:Ee,pagesContainer:i,session:Te,renderHfFromContentOrPm:ue,renderHeaderFooterContentByRId:de,documentFontsAreLoaded:me,buildFootnoteRenderItems:fe,describeInvalidHighlightMarks:pe,emptyTemplatePreviewEntries:se},e,n))}catch(e){let t=e instanceof Error?e:Error(String(e));O?.(t)}}let X=(0,l.createLayoutScheduler)({runLayout:(e,t)=>Y(e,t),debounceMs:ie,maxDelayMs:ae,clock:l.browserClock}),Z=null;function Oe(){Z!==null&&(window.clearTimeout(Z),Z=null);let e=F.value,t=P.value;if(!(!e||!t))try{let n=(0,v.fromProseDoc)(e.state.doc,t);P.value=n,be?.(n),q.emit(`docChange`,n)}catch(e){O?.(e instanceof Error?e:Error(String(e)))}}function ke(){Z!==null&&window.clearTimeout(Z),Z=window.setTimeout(()=>{Z=null,Oe()},oe)}let Q=(0,s.createHiddenEditorManager)({getHost:()=>p.value,getDocument:()=>P.value,getStyles:()=>P.value?.package.styles??null,getExtensionManager:()=>U,getExternalPlugins:we,getCollaboration:()=>void 0,getCollaborationModules:()=>null,getPrecomputedInitialState:()=>null,getReadOnly:()=>(0,e.toValue)(S),getDocumentKey:()=>(0,e.toValue)(w),getDocumentContext:()=>P.value,onTransaction:Ae,onSelectionChange:e=>{I.value=e,k?.(e),q.emit(`selectionChange`,{from:e.selection.from,to:e.selection.to})},onKeyDown:()=>!1,onReadOnlyEditAttempt:()=>j?.(),onEditorViewReady:je,onEditorViewDestroy:()=>{F.value=null,B.value=!1,A?.(null)},onRemoteSelectionsChange:()=>{}});function Ae(e,t){I.value=t,e.docChanged&&(H.value=!0,J.incrementStateSeq(),X.schedule(t,(0,_.getTransactionDirtyRange)(e)),ke()),J.requestRender()}function je(t){F.value=t,I.value=t.state,B.value=!0,Y(t.state,{reason:`initial`}),J.requestRender(),Ne(t),A?.(t),(0,e.toValue)(S)||requestAnimationFrame(()=>{F.value===t&&t.focus()})}let Me=(0,a.createFolioEditor)({getEditorApi:()=>Q.api,getLayout:()=>L.value,runLayout:(e,t)=>Y(e,t),emitter:q});function Ne(t){(0,i.setSuggestionMode)((0,e.toValue)(E)===`suggesting`,t.state,t.dispatch,(0,e.toValue)(D))}(0,e.watch)([()=>(0,e.toValue)(E),()=>(0,e.toValue)(D)],()=>{let e=F.value;e&&Ne(e)}),(0,e.watch)(()=>(0,e.toValue)(S),()=>Q.syncEditable());function Pe(e){let t=K();if(t===e.state.plugins.includes(W))return;let n=e.state.plugins.filter(e=>e!==W&&e!==G);if(t){let e=n.indexOf(Ce),t=e===-1?n.length:e;n.splice(t,0,W,G)}e.updateState(e.state.reconfigure({plugins:n}))}(0,e.watch)(()=>K(),()=>{let e=F.value;e&&Pe(e)});function Fe(){Q.ensureView()}function Ie(){H.value=!1,X.dispose(),Q.destroyView(),Q.ensureView(),Q.getView()||Le()}function Le(){let e=P.value;if(e)try{let t=(0,s.createHiddenEditorState)({document:e,styles:e.package.styles??null,manager:U,externalPlugins:we(),collaborationModules:null,reason:`mount`});I.value=t,Y(t,{reason:`initial`})}catch(e){O?.(e instanceof Error?e:Error(String(e)))}}(0,e.watch)([p,x],()=>{p.value&&P.value&&!Q.getView()&&Fe()},{flush:`post`});async function Re(t){V.value=null,B.value=!1;try{let n=await(0,d.parseDocx)(t,{password:(0,e.toValue)(T)});P.value=n,Ie()}catch(e){let t=e instanceof Error?e:Error(String(e));V.value=t.message,O?.(t)}}function ze(e){V.value=null,P.value=e,Ie()}async function Be(t){let n=F.value,r=P.value;if(!n||!r)return null;let i=n.state,{resolveSelectiveSaveFlags:a}=await import(`@stll/folio-core/docx/selectiveSaveFlags`),o=a((0,e.toValue)(M)),s=(0,v.fromProseDoc)(i.doc,r),c=s.originalBuffer??null,l=o.selectiveSave&&t?.selective!==!1,u=l||o.selectiveSaveTripwire,{repackDocx:d,createDocx:f}=await import(`@stll/folio-core/docx/rezip`),p=null;if(u&&c){let{attemptSelectiveSave:e}=await import(`@stll/folio-core/docx/selectiveSave`);p=await e(s,c,{changedParaIds:(0,b.getChangedParagraphIds)(i),structuralChange:(0,b.hasStructuralChanges)(i),hasUntrackedChanges:(0,b.hasUntrackedChanges)(i),maxBytes:o.selectiveSaveMaxBytes})}let m=l?p:null,h=null;if(!m)h=c?await d(s):await f(s),m=h;else if(o.selectiveSaveTripwire)try{h=await d(s)}catch{}if(o.selectiveSaveTripwire&&h&&N)try{let{compareSelectiveVsFull:e}=await import(`@stll/folio-core/docx/selectiveSaveTripwire`);N(await e(p,h))}catch{}return H.value=!1,new Blob([m],{type:`application/vnd.openxmlformats-officedocument.wordprocessingml.document`})}function Ve(){return P.value}function He(e){P.value=e}function Ue(){return U.getCommands()}function We(){F.value?.focus()}function Ge(){let e=F.value;e&&Y(e.state,{reason:`manual`})}function $(){X.dispose(),Z!==null&&(window.clearTimeout(Z),Z=null),Q.destroyView(),U.destroy(),I.value=null,L.value=null,P.value=null,B.value=!1}return(0,e.onScopeDispose)($),{editor:Me,editorView:F,editorState:I,isReady:B,isDirty:H,parseError:V,layout:L,blocks:R,measures:z,loadBuffer:Re,loadDocument:ze,save:Be,getDocument:Ve,setDocument:He,getCommands:Ue,focus:We,reLayout:Ge,destroy:$}}function he(e,t){if(t<e.top+40){let n=Math.max(0,e.top+40-t);return-Math.min(12,n/40*12)}if(t>e.bottom-40){let n=Math.max(0,t-(e.bottom-40));return Math.min(12,n/40*12)}return 0}function ge({pagesContainer:t,onScrollExtendSelection:n}){let r=null,i=0,a=0,o=!1,s=null;function c(){if(s)return s;let e=t.value;return e?(s=(0,x.findVerticalScrollParent)(e),s):null}function l(){o=!1,r!==null&&(cancelAnimationFrame(r),r=null)}function u(){if(!o)return;let e=c();if(!e)return;let t=he(e.getBoundingClientRect(),a);t!==0&&(e.scrollTop+=t,n(i,a)),r=requestAnimationFrame(u)}function d(){o||(o=!0,r=requestAnimationFrame(u))}function f(e,t){if(i=e,a=t,!o){let e=c();if(!e)return;let n=e.getBoundingClientRect();(t<n.top+40||t>n.bottom-40)&&d()}}return(0,e.onScopeDispose)(()=>l()),{updateMousePosition:f,stopAutoScroll:l}}function _e(){let e={active:!1,startX:0,handle:null,columnIndex:0,tablePmStart:0,origWidths:{left:0,right:0}},t={active:!1,startY:0,handle:null,rowIndex:0,isEdge:!1,tablePmStart:0,origHeight:0},n={active:!1,startX:0,handle:null,columnIndex:0,tablePmStart:0,origWidth:0},r=null;function i(){return e.active||t.active||n.active}function a(i,a){let o=i.target;return o instanceof HTMLElement?o.classList.contains(`layout-table-resize-handle`)?(i.preventDefault(),i.stopPropagation(),r=a,e.active=!0,e.startX=i.clientX,e.handle=o,o.classList.add(`dragging`),e.columnIndex=parseInt(o.dataset.columnIndex??`0`,10),e.tablePmStart=parseInt(o.dataset.tablePmStart??`0`,10),ve(a,e),!0):o.classList.contains(`layout-table-row-resize-handle`)||o.classList.contains(`layout-table-edge-handle-bottom`)?(i.preventDefault(),i.stopPropagation(),r=a,t.active=!0,t.startY=i.clientY,t.handle=o,t.isEdge=o.dataset.isEdge===`bottom`,o.classList.add(`dragging`),t.rowIndex=parseInt(o.dataset.rowIndex??`0`,10),t.tablePmStart=parseInt(o.dataset.tablePmStart??`0`,10),ye(a,t,o),!0):o.classList.contains(`layout-table-edge-handle-right`)?(i.preventDefault(),i.stopPropagation(),r=a,n.active=!0,n.startX=i.clientX,n.handle=o,o.classList.add(`dragging`),n.columnIndex=parseInt(o.dataset.columnIndex??`0`,10),n.tablePmStart=parseInt(o.dataset.tablePmStart??`0`,10),be(a,n),!0):!1:!1}function o(r){if(e.active&&e.handle){r.preventDefault();let t=r.clientX-e.startX,n=parseFloat(e.handle.style.left);e.handle.style.left=`${n+t}px`,e.startX=r.clientX;let i=Math.round(t*S.TWIPS_PER_PIXEL),a=e.origWidths.left+i,o=e.origWidths.right-i;a>=S.MIN_CELL_WIDTH_TWIPS&&o>=S.MIN_CELL_WIDTH_TWIPS&&(e.origWidths={left:a,right:o});return}if(t.active&&t.handle){r.preventDefault();let e=r.clientY-t.startY,n=parseFloat(t.handle.style.top);t.handle.style.top=`${n+e}px`,t.startY=r.clientY;let i=Math.round(e*S.TWIPS_PER_PIXEL),a=t.origHeight+i;a>=S.MIN_ROW_HEIGHT_TWIPS&&(t.origHeight=a);return}if(n.active&&n.handle){r.preventDefault();let e=r.clientX-n.startX,t=parseFloat(n.handle.style.left);n.handle.style.left=`${t+e}px`,n.startX=r.clientX;let i=Math.round(e*S.TWIPS_PER_PIXEL),a=n.origWidth+i;a>=S.MIN_CELL_WIDTH_TWIPS&&(n.origWidth=a)}}function s(i){if(e.active){e.active=!1,e.handle?.classList.remove(`dragging`),r&&(0,S.commitColumnResize)(r,{pmStart:e.tablePmStart,colIdx:e.columnIndex,newLeft:e.origWidths.left,newRight:e.origWidths.right}),e.handle=null;return}if(t.active){t.active=!1,t.handle?.classList.remove(`dragging`),r&&(0,S.commitRowResize)(r,{pmStart:t.tablePmStart,rowIdx:t.rowIndex,newHeight:t.origHeight}),t.handle=null;return}n.active&&(n.active=!1,n.handle?.classList.remove(`dragging`),r&&(0,S.commitRightEdgeResize)(r,{pmStart:n.tablePmStart,colIdx:n.columnIndex,newWidth:n.origWidth}),n.handle=null)}function c(){return document.addEventListener(`mousemove`,o),document.addEventListener(`mouseup`,s),()=>{document.removeEventListener(`mousemove`,o),document.removeEventListener(`mouseup`,s)}}return{tryStartResize:a,install:c,isResizing:i}}function ve(e,t){let n=(0,S.readColumnWidths)(e,t.tablePmStart,t.columnIndex);n&&(t.origWidths=n)}function ye(e,t,n){let r=(0,S.readRowHeight)(e,t.tablePmStart,t.rowIndex);if(r!=null){t.origHeight=r;return}let i=n.closest(`.layout-table`)?.querySelector(`[data-row-index="${t.rowIndex}"]`),a=i?i.getBoundingClientRect().height:30;t.origHeight=Math.round(a*S.TWIPS_PER_PIXEL)}function be(e,t){let n=(0,S.readColumnWidthAt)(e,t.tablePmStart,t.columnIndex);n!=null&&(t.origWidth=n)}function O(t,n){return(0,e.computed)(()=>(n.value,(0,C.extractTrackedChanges)(t.value?.state??null)))}var k=w.ZOOM_MIN,A=w.ZOOM_MAX,j=[.5,.75,1,1.25,1.5,2];function M(t=1){let n=(0,e.ref)(Math.max(k,Math.min(A,t))),r=(0,e.computed)(()=>Math.round(n.value*100)),i=(0,e.computed)(()=>n.value<=k),a=(0,e.computed)(()=>n.value>=A);function o(e){n.value=Math.max(k,Math.min(A,Math.round(e*100)/100))}function s(){o(n.value+w.ZOOM_STEP)}function c(){o(n.value-w.ZOOM_STEP)}function l(){o(1)}function u(e){(e.ctrlKey||e.metaKey)&&(e.preventDefault(),e.deltaY<0?s():c())}function d(e){(e.ctrlKey||e.metaKey)&&(e.shiftKey||e.altKey||(e.key===`=`||e.key===`+`?(e.preventDefault(),s()):e.key===`-`?(e.preventDefault(),c()):e.key===`0`&&(e.preventDefault(),l())))}function f(){(0,e.onMounted)(()=>document.addEventListener(`keydown`,d)),(0,e.onBeforeUnmount)(()=>document.removeEventListener(`keydown`,d))}return{zoom:n,zoomPercent:r,isMinZoom:i,isMaxZoom:a,setZoom:o,zoomIn:s,zoomOut:c,resetZoom:l,handleWheel:u,handleKeyDown:d,installShortcuts:f,ZOOM_PRESETS:j}}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return _e}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return M}}); |
| import { computed as e, onBeforeUnmount as t, onMounted as n, onScopeDispose as r, ref as i, shallowRef as a, toValue as o, watch as s } from "vue"; | ||
| import { getMargins as c, getPageSize as l, twipsToPixels as u } from "@stll/folio-core/paged-layout/sectionGeometry"; | ||
| import { createAnonymizationDecorationsPlugin as d } from "@stll/folio-core/prosemirror/plugins/anonymizationDecorations"; | ||
| import { createTemplateDirectivesPlugin as f } from "@stll/folio-core/prosemirror/plugins/templateDirectives"; | ||
| import { createSuggestionModePlugin as p, setSuggestionMode as m } from "@stll/folio-core/prosemirror/plugins/suggestionMode"; | ||
| import { createFolioEditor as h } from "@stll/folio-core/controller/folioEditor"; | ||
| import { createFolioEditorEmitter as ee } from "@stll/folio-core/controller/folioEditorEvents"; | ||
| import { createHiddenEditorManager as g, createHiddenEditorState as _ } from "@stll/folio-core/controller/hiddenEditorManager"; | ||
| import { runLayoutPipeline as te } from "@stll/folio-core/controller/layoutPipeline"; | ||
| import { browserClock as v, createLayoutScheduler as ne } from "@stll/folio-core/controller/layoutScheduler"; | ||
| import { createLayoutSession as re } from "@stll/folio-core/controller/layoutSession"; | ||
| import { parseDocx as ie } from "@stll/folio-core/docx/parser"; | ||
| import { getFootnoteText as y } from "@stll/folio-core/docx/footnoteParser"; | ||
| import { convertHeaderFooterPmDocToContent as b, convertHeaderFooterToContent as x } from "@stll/folio-core/layout-bridge/convert/headerFooterLayout"; | ||
| import { resolveSectionHeaderFooterRefs as ae } from "@stll/folio-core/layout-engine"; | ||
| import { LayoutPainter as oe } from "@stll/folio-core/layout-painter"; | ||
| import { LayoutSelectionGate as se } from "@stll/folio-core/paged-layout/LayoutSelectionGate"; | ||
| import { getTransactionDirtyRange as ce } from "@stll/folio-core/paged-layout/transactionDirtyRange"; | ||
| import { fromProseDoc as le } from "@stll/folio-core/prosemirror/conversion/fromProseDoc"; | ||
| import { ExtensionManager as ue } from "@stll/folio-core/prosemirror/extensions/ExtensionManager"; | ||
| import { getChangedParagraphIds as de, hasStructuralChanges as fe, hasUntrackedChanges as pe } from "@stll/folio-core/prosemirror/extensions/features/ParagraphChangeTrackerExtension"; | ||
| import { createStarterKit as me } from "@stll/folio-core/prosemirror/extensions/StarterKit"; | ||
| import { createTemplatePreviewValuesPlugin as he } from "@stll/folio-core/prosemirror/plugins/templatePreviewValues"; | ||
| import { templateSlashMenuPlugin as ge } from "@stll/folio-core/prosemirror/plugins/templateSlashMenu"; | ||
| import { findVerticalScrollParent as S } from "@stll/folio-core/utils/findVerticalScrollParent"; | ||
| import { MIN_CELL_WIDTH_TWIPS as C, MIN_ROW_HEIGHT_TWIPS as _e, TWIPS_PER_PIXEL as w, commitColumnResize as T, commitRightEdgeResize as E, commitRowResize as D, readColumnWidthAt as ve, readColumnWidths as O, readRowHeight as ye } from "@stll/folio-core/prosemirror/tableResize"; | ||
| import { extractTrackedChanges as k } from "@stll/folio-core/prosemirror/utils/extractTrackedChanges"; | ||
| import { ZOOM_MAX as be, ZOOM_MIN as xe, ZOOM_STEP as A } from "@stll/folio-core/utils/zoom"; | ||
| //#region src/composables/useDocxEditor.ts | ||
| var Se = 24, Ce = 32, we = 96, Te = 250, Ee = []; | ||
| function De(e) { | ||
| let t = e?.columnCount ?? 1; | ||
| if (t <= 1) return; | ||
| let n = { | ||
| count: t, | ||
| gap: u(e?.columnSpace ?? 720), | ||
| equalWidth: e?.equalWidth ?? !0 | ||
| }; | ||
| return e?.separator !== void 0 && (n.separator = e.separator), n; | ||
| } | ||
| var j = { | ||
| hf: null, | ||
| rId: null | ||
| }; | ||
| function Oe(e, t) { | ||
| let n = e?.package; | ||
| if (!n || !t) return { | ||
| header: j, | ||
| footer: j, | ||
| firstHeader: j, | ||
| firstFooter: j | ||
| }; | ||
| let r = n.headers, i = n.footers, a = (e) => e ? r?.get(e) ?? null : null, o = (e) => e ? i?.get(e) ?? null : null, s = null, c = null; | ||
| for (let e of t.headerReferences ?? []) e.type === "default" ? s = e.rId : e.type === "first" && (c = e.rId); | ||
| let l = null, u = null; | ||
| for (let e of t.footerReferences ?? []) e.type === "default" ? l = e.rId : e.type === "first" && (u = e.rId); | ||
| return { | ||
| header: { | ||
| hf: a(s), | ||
| rId: s | ||
| }, | ||
| footer: { | ||
| hf: o(l), | ||
| rId: l | ||
| }, | ||
| firstHeader: { | ||
| hf: a(c), | ||
| rId: c | ||
| }, | ||
| firstFooter: { | ||
| hf: o(u), | ||
| rId: u | ||
| } | ||
| }; | ||
| } | ||
| function M(e, t, n, r, i, a) { | ||
| if (!e) return; | ||
| let o = t ? { | ||
| ...a, | ||
| rId: t | ||
| } : a, s = t ? n?.getView(t) : null; | ||
| return s ? b(s.state.doc, r, i, o) : x(e, r, i, o); | ||
| } | ||
| function ke(e, t, n, r, i) { | ||
| if (!e || e.size === 0) return; | ||
| let a = /* @__PURE__ */ new Map(); | ||
| for (let [o, s] of e) { | ||
| let e = M(s, o, t, n, r, i); | ||
| e && a.set(o, e); | ||
| } | ||
| return a.size > 0 ? a : void 0; | ||
| } | ||
| function Ae(e, t, n) { | ||
| let r = /* @__PURE__ */ new Map(); | ||
| if (!n || !n.package.footnotes) return r; | ||
| let i = /* @__PURE__ */ new Map(); | ||
| for (let e of n.package.footnotes) e.noteType && e.noteType !== "normal" || i.set(e.id, e); | ||
| for (let [n, a] of e) { | ||
| let e = []; | ||
| for (let n of a) { | ||
| let r = i.get(n); | ||
| if (!r) continue; | ||
| let a = t.get(n), o = a?.displayNumber ?? 0; | ||
| e.push({ | ||
| displayNumber: String(o), | ||
| text: y(r), | ||
| ...a ? { content: { | ||
| blocks: a.blocks, | ||
| measures: a.measures, | ||
| height: a.height | ||
| } } : {} | ||
| }); | ||
| } | ||
| e.length > 0 && r.set(n, e); | ||
| } | ||
| return r; | ||
| } | ||
| var N = /* @__PURE__ */ new Set([ | ||
| "black", | ||
| "blue", | ||
| "cyan", | ||
| "darkBlue", | ||
| "darkCyan", | ||
| "darkGray", | ||
| "darkGreen", | ||
| "darkMagenta", | ||
| "darkRed", | ||
| "darkYellow", | ||
| "green", | ||
| "lightGray", | ||
| "magenta", | ||
| "none", | ||
| "red", | ||
| "white", | ||
| "yellow" | ||
| ]); | ||
| function je(e) { | ||
| let t = [], n = (e, r) => { | ||
| for (let [n, i] of e.marks.entries()) i.type.name === "highlight" && !N.has(String(i.attrs.color)) && t.push(`${r}.marks[${n}]=${JSON.stringify(i.attrs)}`); | ||
| e.forEach((e, t, i) => { | ||
| n(e, `${r}.content[${i}]`); | ||
| }); | ||
| }; | ||
| return n(e, "doc"), t.join("; "); | ||
| } | ||
| function Me() { | ||
| return typeof document > "u" || !("fonts" in document) || document.fonts.status === "loaded"; | ||
| } | ||
| function P(e) { | ||
| let { hiddenContainer: t, pagesContainer: n, readOnly: u = !1, pageGap: y = Se, documentKey: b, password: x, editorMode: S, author: C, externalPlugins: _e = [], onAnonymizationMatchesChange: w, showTemplateDirectives: T, onSlashMenuChange: E, onSlashMenuKeyAction: D, onChange: ve, onError: O, onSelectionUpdate: ye, onEditorViewReady: k, onReadOnlyEditAttempt: be, featureFlags: xe, onSelectiveSaveTripwire: A } = e, j = a(null), N = a(null), P = a(null), F = a(null), I = a([]), L = a([]), R = i(!1), z = i(null), B = i(!1), V = new ue(me()); | ||
| V.buildSchema(), V.initializeRuntime(); | ||
| let H = p(!1), U = d({ onMatchesChange: (e) => w?.(e) }), W = f(), G = ge({ | ||
| onChange: (e) => E?.(e), | ||
| onKeyAction: (e) => D?.(e) ?? !1 | ||
| }), Ne = he(), K = () => o(T) === !0; | ||
| function Pe() { | ||
| return [ | ||
| H, | ||
| ..._e, | ||
| U, | ||
| ...K() ? [W, G] : [], | ||
| Ne | ||
| ]; | ||
| } | ||
| let q = ee(), J = new se(), Fe = re(), Y = new oe({ | ||
| pageGap: y, | ||
| showShadow: !0 | ||
| }); | ||
| function Ie(e) { | ||
| e.layout && (F.value = e.layout), e.blocks && (I.value = e.blocks), e.measures && (L.value = e.measures), e.blockLookup && Y.setBlockLookup(e.blockLookup), e.layout && q.emit("layoutComplete", e.layout); | ||
| } | ||
| function X(e, t = {}) { | ||
| let r = n.value, i = r instanceof HTMLDivElement ? r : null, a = j.value, o = a?.package.document, s = o?.sections?.[0]?.properties ?? o?.finalSectionProperties ?? null, u = l(s), d = c(s), f = De(s), p = u.w - d.left - d.right, m = a?.package.styles ?? null, h = a?.package.theme ?? null, ee = a?.package.settings?.defaultTabStop, g = a?.package.settings, _ = g !== void 0 && "mirrorMargins" in g && g.mirrorMargins === !0, v = Oe(a, s); | ||
| try { | ||
| Ie(te({ | ||
| contentWidth: p, | ||
| columns: f, | ||
| pageSize: u, | ||
| margins: d, | ||
| pageGap: y, | ||
| syncCoordinator: J, | ||
| headerContent: v.header.hf, | ||
| footerContent: v.footer.hf, | ||
| firstPageHeaderContent: v.firstHeader.hf, | ||
| firstPageFooterContent: v.firstFooter.hf, | ||
| headerContentRId: v.header.rId, | ||
| footerContentRId: v.footer.rId, | ||
| firstPageHeaderContentRId: v.firstHeader.rId, | ||
| firstPageFooterContentRId: v.firstFooter.rId, | ||
| sectionHeaderFooterRefs: ae(a), | ||
| theme: h, | ||
| sectionProperties: s, | ||
| document: a, | ||
| defaultTabStop: ee, | ||
| mirrorMargins: _, | ||
| styles: m, | ||
| layout: F.value, | ||
| hfPMs: null, | ||
| painter: Y, | ||
| pagesContainer: i, | ||
| session: Fe, | ||
| renderHfFromContentOrPm: M, | ||
| renderHeaderFooterContentByRId: ke, | ||
| documentFontsAreLoaded: Me, | ||
| buildFootnoteRenderItems: Ae, | ||
| describeInvalidHighlightMarks: je, | ||
| emptyTemplatePreviewEntries: Ee | ||
| }, e, t)); | ||
| } catch (e) { | ||
| let t = e instanceof Error ? e : Error(String(e)); | ||
| O?.(t); | ||
| } | ||
| } | ||
| let Z = ne({ | ||
| runLayout: (e, t) => X(e, t), | ||
| debounceMs: Ce, | ||
| maxDelayMs: we, | ||
| clock: v | ||
| }), Q = null; | ||
| function Le() { | ||
| Q !== null && (window.clearTimeout(Q), Q = null); | ||
| let e = N.value, t = j.value; | ||
| if (!(!e || !t)) try { | ||
| let n = le(e.state.doc, t); | ||
| j.value = n, ve?.(n), q.emit("docChange", n); | ||
| } catch (e) { | ||
| O?.(e instanceof Error ? e : Error(String(e))); | ||
| } | ||
| } | ||
| function Re() { | ||
| Q !== null && window.clearTimeout(Q), Q = window.setTimeout(() => { | ||
| Q = null, Le(); | ||
| }, Te); | ||
| } | ||
| let $ = g({ | ||
| getHost: () => t.value, | ||
| getDocument: () => j.value, | ||
| getStyles: () => j.value?.package.styles ?? null, | ||
| getExtensionManager: () => V, | ||
| getExternalPlugins: Pe, | ||
| getCollaboration: () => void 0, | ||
| getCollaborationModules: () => null, | ||
| getPrecomputedInitialState: () => null, | ||
| getReadOnly: () => o(u), | ||
| getDocumentKey: () => o(b), | ||
| getDocumentContext: () => j.value, | ||
| onTransaction: ze, | ||
| onSelectionChange: (e) => { | ||
| P.value = e, ye?.(e), q.emit("selectionChange", { | ||
| from: e.selection.from, | ||
| to: e.selection.to | ||
| }); | ||
| }, | ||
| onKeyDown: () => !1, | ||
| onReadOnlyEditAttempt: () => be?.(), | ||
| onEditorViewReady: Be, | ||
| onEditorViewDestroy: () => { | ||
| N.value = null, R.value = !1, k?.(null); | ||
| }, | ||
| onRemoteSelectionsChange: () => {} | ||
| }); | ||
| function ze(e, t) { | ||
| P.value = t, e.docChanged && (B.value = !0, J.incrementStateSeq(), Z.schedule(t, ce(e)), Re()), J.requestRender(); | ||
| } | ||
| function Be(e) { | ||
| N.value = e, P.value = e.state, R.value = !0, X(e.state, { reason: "initial" }), J.requestRender(), He(e), k?.(e), o(u) || requestAnimationFrame(() => { | ||
| N.value === e && e.focus(); | ||
| }); | ||
| } | ||
| let Ve = h({ | ||
| getEditorApi: () => $.api, | ||
| getLayout: () => F.value, | ||
| runLayout: (e, t) => X(e, t), | ||
| emitter: q | ||
| }); | ||
| function He(e) { | ||
| m(o(S) === "suggesting", e.state, e.dispatch, o(C)); | ||
| } | ||
| s([() => o(S), () => o(C)], () => { | ||
| let e = N.value; | ||
| e && He(e); | ||
| }), s(() => o(u), () => $.syncEditable()); | ||
| function Ue(e) { | ||
| let t = K(); | ||
| if (t === e.state.plugins.includes(W)) return; | ||
| let n = e.state.plugins.filter((e) => e !== W && e !== G); | ||
| if (t) { | ||
| let e = n.indexOf(Ne), t = e === -1 ? n.length : e; | ||
| n.splice(t, 0, W, G); | ||
| } | ||
| e.updateState(e.state.reconfigure({ plugins: n })); | ||
| } | ||
| s(() => K(), () => { | ||
| let e = N.value; | ||
| e && Ue(e); | ||
| }); | ||
| function We() { | ||
| $.ensureView(); | ||
| } | ||
| function Ge() { | ||
| B.value = !1, Z.dispose(), $.destroyView(), $.ensureView(), $.getView() || Ke(); | ||
| } | ||
| function Ke() { | ||
| let e = j.value; | ||
| if (e) try { | ||
| let t = _({ | ||
| document: e, | ||
| styles: e.package.styles ?? null, | ||
| manager: V, | ||
| externalPlugins: Pe(), | ||
| collaborationModules: null, | ||
| reason: "mount" | ||
| }); | ||
| P.value = t, X(t, { reason: "initial" }); | ||
| } catch (e) { | ||
| O?.(e instanceof Error ? e : Error(String(e))); | ||
| } | ||
| } | ||
| s([t, n], () => { | ||
| t.value && j.value && !$.getView() && We(); | ||
| }, { flush: "post" }); | ||
| async function qe(e) { | ||
| z.value = null, R.value = !1; | ||
| try { | ||
| let t = await ie(e, { password: o(x) }); | ||
| j.value = t, Ge(); | ||
| } catch (e) { | ||
| let t = e instanceof Error ? e : Error(String(e)); | ||
| z.value = t.message, O?.(t); | ||
| } | ||
| } | ||
| function Je(e) { | ||
| z.value = null, j.value = e, Ge(); | ||
| } | ||
| async function Ye(e) { | ||
| let t = N.value, n = j.value; | ||
| if (!t || !n) return null; | ||
| let r = t.state, { resolveSelectiveSaveFlags: i } = await import("@stll/folio-core/docx/selectiveSaveFlags"), a = i(o(xe)), s = le(r.doc, n), c = s.originalBuffer ?? null, l = a.selectiveSave && e?.selective !== !1, u = l || a.selectiveSaveTripwire, { repackDocx: d, createDocx: f } = await import("@stll/folio-core/docx/rezip"), p = null; | ||
| if (u && c) { | ||
| let { attemptSelectiveSave: e } = await import("@stll/folio-core/docx/selectiveSave"); | ||
| p = await e(s, c, { | ||
| changedParaIds: de(r), | ||
| structuralChange: fe(r), | ||
| hasUntrackedChanges: pe(r), | ||
| maxBytes: a.selectiveSaveMaxBytes | ||
| }); | ||
| } | ||
| let m = l ? p : null, h = null; | ||
| if (!m) h = c ? await d(s) : await f(s), m = h; | ||
| else if (a.selectiveSaveTripwire) try { | ||
| h = await d(s); | ||
| } catch {} | ||
| if (a.selectiveSaveTripwire && h && A) try { | ||
| let { compareSelectiveVsFull: e } = await import("@stll/folio-core/docx/selectiveSaveTripwire"); | ||
| A(await e(p, h)); | ||
| } catch {} | ||
| return B.value = !1, new Blob([m], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" }); | ||
| } | ||
| function Xe() { | ||
| return j.value; | ||
| } | ||
| function Ze(e) { | ||
| j.value = e; | ||
| } | ||
| function Qe() { | ||
| return V.getCommands(); | ||
| } | ||
| function $e() { | ||
| N.value?.focus(); | ||
| } | ||
| function et() { | ||
| let e = N.value; | ||
| e && X(e.state, { reason: "manual" }); | ||
| } | ||
| function tt() { | ||
| Z.dispose(), Q !== null && (window.clearTimeout(Q), Q = null), $.destroyView(), V.destroy(), P.value = null, F.value = null, j.value = null, R.value = !1; | ||
| } | ||
| return r(tt), { | ||
| editor: Ve, | ||
| editorView: N, | ||
| editorState: P, | ||
| isReady: R, | ||
| isDirty: B, | ||
| parseError: z, | ||
| layout: F, | ||
| blocks: I, | ||
| measures: L, | ||
| loadBuffer: qe, | ||
| loadDocument: Je, | ||
| save: Ye, | ||
| getDocument: Xe, | ||
| setDocument: Ze, | ||
| getCommands: Qe, | ||
| focus: $e, | ||
| reLayout: et, | ||
| destroy: tt | ||
| }; | ||
| } | ||
| function F(e, t) { | ||
| if (t < e.top + 40) { | ||
| let n = Math.max(0, e.top + 40 - t); | ||
| return -Math.min(12, n / 40 * 12); | ||
| } | ||
| if (t > e.bottom - 40) { | ||
| let n = Math.max(0, t - (e.bottom - 40)); | ||
| return Math.min(12, n / 40 * 12); | ||
| } | ||
| return 0; | ||
| } | ||
| //#endregion | ||
| //#region src/composables/useDragAutoScroll.ts | ||
| function I({ pagesContainer: e, onScrollExtendSelection: t }) { | ||
| let n = null, i = 0, a = 0, o = !1, s = null; | ||
| function c() { | ||
| if (s) return s; | ||
| let t = e.value; | ||
| return t ? (s = S(t), s) : null; | ||
| } | ||
| function l() { | ||
| o = !1, n !== null && (cancelAnimationFrame(n), n = null); | ||
| } | ||
| function u() { | ||
| if (!o) return; | ||
| let e = c(); | ||
| if (!e) return; | ||
| let r = F(e.getBoundingClientRect(), a); | ||
| r !== 0 && (e.scrollTop += r, t(i, a)), n = requestAnimationFrame(u); | ||
| } | ||
| function d() { | ||
| o || (o = !0, n = requestAnimationFrame(u)); | ||
| } | ||
| function f(e, t) { | ||
| if (i = e, a = t, !o) { | ||
| let e = c(); | ||
| if (!e) return; | ||
| let n = e.getBoundingClientRect(); | ||
| (t < n.top + 40 || t > n.bottom - 40) && d(); | ||
| } | ||
| } | ||
| return r(() => l()), { | ||
| updateMousePosition: f, | ||
| stopAutoScroll: l | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/composables/useTableResize.ts | ||
| function L() { | ||
| let e = { | ||
| active: !1, | ||
| startX: 0, | ||
| handle: null, | ||
| columnIndex: 0, | ||
| tablePmStart: 0, | ||
| origWidths: { | ||
| left: 0, | ||
| right: 0 | ||
| } | ||
| }, t = { | ||
| active: !1, | ||
| startY: 0, | ||
| handle: null, | ||
| rowIndex: 0, | ||
| isEdge: !1, | ||
| tablePmStart: 0, | ||
| origHeight: 0 | ||
| }, n = { | ||
| active: !1, | ||
| startX: 0, | ||
| handle: null, | ||
| columnIndex: 0, | ||
| tablePmStart: 0, | ||
| origWidth: 0 | ||
| }, r = null; | ||
| function i() { | ||
| return e.active || t.active || n.active; | ||
| } | ||
| function a(i, a) { | ||
| let o = i.target; | ||
| return o instanceof HTMLElement ? o.classList.contains("layout-table-resize-handle") ? (i.preventDefault(), i.stopPropagation(), r = a, e.active = !0, e.startX = i.clientX, e.handle = o, o.classList.add("dragging"), e.columnIndex = parseInt(o.dataset.columnIndex ?? "0", 10), e.tablePmStart = parseInt(o.dataset.tablePmStart ?? "0", 10), R(a, e), !0) : o.classList.contains("layout-table-row-resize-handle") || o.classList.contains("layout-table-edge-handle-bottom") ? (i.preventDefault(), i.stopPropagation(), r = a, t.active = !0, t.startY = i.clientY, t.handle = o, t.isEdge = o.dataset.isEdge === "bottom", o.classList.add("dragging"), t.rowIndex = parseInt(o.dataset.rowIndex ?? "0", 10), t.tablePmStart = parseInt(o.dataset.tablePmStart ?? "0", 10), z(a, t, o), !0) : o.classList.contains("layout-table-edge-handle-right") ? (i.preventDefault(), i.stopPropagation(), r = a, n.active = !0, n.startX = i.clientX, n.handle = o, o.classList.add("dragging"), n.columnIndex = parseInt(o.dataset.columnIndex ?? "0", 10), n.tablePmStart = parseInt(o.dataset.tablePmStart ?? "0", 10), B(a, n), !0) : !1 : !1; | ||
| } | ||
| function o(r) { | ||
| if (e.active && e.handle) { | ||
| r.preventDefault(); | ||
| let t = r.clientX - e.startX, n = parseFloat(e.handle.style.left); | ||
| e.handle.style.left = `${n + t}px`, e.startX = r.clientX; | ||
| let i = Math.round(t * w), a = e.origWidths.left + i, o = e.origWidths.right - i; | ||
| a >= C && o >= C && (e.origWidths = { | ||
| left: a, | ||
| right: o | ||
| }); | ||
| return; | ||
| } | ||
| if (t.active && t.handle) { | ||
| r.preventDefault(); | ||
| let e = r.clientY - t.startY, n = parseFloat(t.handle.style.top); | ||
| t.handle.style.top = `${n + e}px`, t.startY = r.clientY; | ||
| let i = Math.round(e * w), a = t.origHeight + i; | ||
| a >= _e && (t.origHeight = a); | ||
| return; | ||
| } | ||
| if (n.active && n.handle) { | ||
| r.preventDefault(); | ||
| let e = r.clientX - n.startX, t = parseFloat(n.handle.style.left); | ||
| n.handle.style.left = `${t + e}px`, n.startX = r.clientX; | ||
| let i = Math.round(e * w), a = n.origWidth + i; | ||
| a >= C && (n.origWidth = a); | ||
| } | ||
| } | ||
| function s(i) { | ||
| if (e.active) { | ||
| e.active = !1, e.handle?.classList.remove("dragging"), r && T(r, { | ||
| pmStart: e.tablePmStart, | ||
| colIdx: e.columnIndex, | ||
| newLeft: e.origWidths.left, | ||
| newRight: e.origWidths.right | ||
| }), e.handle = null; | ||
| return; | ||
| } | ||
| if (t.active) { | ||
| t.active = !1, t.handle?.classList.remove("dragging"), r && D(r, { | ||
| pmStart: t.tablePmStart, | ||
| rowIdx: t.rowIndex, | ||
| newHeight: t.origHeight | ||
| }), t.handle = null; | ||
| return; | ||
| } | ||
| n.active && (n.active = !1, n.handle?.classList.remove("dragging"), r && E(r, { | ||
| pmStart: n.tablePmStart, | ||
| colIdx: n.columnIndex, | ||
| newWidth: n.origWidth | ||
| }), n.handle = null); | ||
| } | ||
| function c() { | ||
| return document.addEventListener("mousemove", o), document.addEventListener("mouseup", s), () => { | ||
| document.removeEventListener("mousemove", o), document.removeEventListener("mouseup", s); | ||
| }; | ||
| } | ||
| return { | ||
| tryStartResize: a, | ||
| install: c, | ||
| isResizing: i | ||
| }; | ||
| } | ||
| function R(e, t) { | ||
| let n = O(e, t.tablePmStart, t.columnIndex); | ||
| n && (t.origWidths = n); | ||
| } | ||
| function z(e, t, n) { | ||
| let r = ye(e, t.tablePmStart, t.rowIndex); | ||
| if (r != null) { | ||
| t.origHeight = r; | ||
| return; | ||
| } | ||
| let i = n.closest(".layout-table")?.querySelector(`[data-row-index="${t.rowIndex}"]`), a = i ? i.getBoundingClientRect().height : 30; | ||
| t.origHeight = Math.round(a * w); | ||
| } | ||
| function B(e, t) { | ||
| let n = ve(e, t.tablePmStart, t.columnIndex); | ||
| n != null && (t.origWidth = n); | ||
| } | ||
| //#endregion | ||
| //#region src/composables/useTrackedChanges.ts | ||
| function V(t, n) { | ||
| return e(() => (n.value, k(t.value?.state ?? null))); | ||
| } | ||
| //#endregion | ||
| //#region src/composables/useZoom.ts | ||
| var H = xe, U = be, W = [ | ||
| .5, | ||
| .75, | ||
| 1, | ||
| 1.25, | ||
| 1.5, | ||
| 2 | ||
| ]; | ||
| function G(r = 1) { | ||
| let a = i(Math.max(H, Math.min(U, r))), o = e(() => Math.round(a.value * 100)), s = e(() => a.value <= H), c = e(() => a.value >= U); | ||
| function l(e) { | ||
| a.value = Math.max(H, Math.min(U, Math.round(e * 100) / 100)); | ||
| } | ||
| function u() { | ||
| l(a.value + A); | ||
| } | ||
| function d() { | ||
| l(a.value - A); | ||
| } | ||
| function f() { | ||
| l(1); | ||
| } | ||
| function p(e) { | ||
| (e.ctrlKey || e.metaKey) && (e.preventDefault(), e.deltaY < 0 ? u() : d()); | ||
| } | ||
| function m(e) { | ||
| (e.ctrlKey || e.metaKey) && (e.shiftKey || e.altKey || (e.key === "=" || e.key === "+" ? (e.preventDefault(), u()) : e.key === "-" ? (e.preventDefault(), d()) : e.key === "0" && (e.preventDefault(), f()))); | ||
| } | ||
| function h() { | ||
| n(() => document.addEventListener("keydown", m)), t(() => document.removeEventListener("keydown", m)); | ||
| } | ||
| return { | ||
| zoom: a, | ||
| zoomPercent: o, | ||
| isMinZoom: s, | ||
| isMaxZoom: c, | ||
| setZoom: l, | ||
| zoomIn: u, | ||
| zoomOut: d, | ||
| resetZoom: f, | ||
| handleWheel: p, | ||
| handleKeyDown: m, | ||
| installShortcuts: h, | ||
| ZOOM_PRESETS: W | ||
| }; | ||
| } | ||
| //#endregion | ||
| export { I as a, L as i, k as n, P as o, V as r, G as t }; |
@@ -5,3 +5,3 @@ import { CSSProperties, VNodeChild } from 'vue'; | ||
| import { XmlFragment } from 'yjs'; | ||
| import { FolioAIEditApplyMode, FolioAIEditApplyResult, FolioAIEditOperation, FolioAIEditSnapshot, FolioCommentAnchor, FolioDocumentOperationBatch, FolioDocumentOperationResult, FolioDocumentOperationUndoHandle, FolioDocumentOperationUndoResult, FolioReviewChange } from '@stll/folio-core/ai-edits'; | ||
| import { FolioAIEditApplyMode, FolioAIEditApplyResult, FolioAIEditOperation, FolioAIEditSnapshot, FolioCommentAnchor, FolioDocumentNavigationTarget, FolioDocumentOperationBatch, FolioDocumentOperationResult, FolioDocumentOperationUndoHandle, FolioDocumentOperationUndoResult, FolioReviewChange } from '@stll/folio-core/ai-edits'; | ||
| import { ContentControlFilter, SetContentControlContentInput, SetContentControlValueInput } from '@stll/folio-core/content-controls'; | ||
@@ -415,2 +415,4 @@ import { FolioEditor } from '@stll/folio-core/controller/folioEditor'; | ||
| scrollToBlock: (blockId: string, snapshot?: FolioAIEditSnapshot) => boolean; | ||
| /** Resolve a stable block or text-range target and reveal it in the editor. */ | ||
| showInDocument: (target: FolioDocumentNavigationTarget, snapshot?: FolioAIEditSnapshot) => boolean; | ||
| /** | ||
@@ -438,2 +440,4 @@ * The tracked changes (insertions and deletions) present in the live | ||
| getPageText: (page: number) => string | null; | ||
| /** Resolve a stable block or text range to its real 1-based rendered page. */ | ||
| getTargetPage: (target: FolioDocumentNavigationTarget, snapshot?: FolioAIEditSnapshot) => number | null; | ||
| /** | ||
@@ -440,0 +444,0 @@ * List every block-level content control in the live document, filtered by |
@@ -1,2 +0,2 @@ | ||
| Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./useZoom-BB6hSMvM.cjs");let t=require("vue"),n=require("prosemirror-history"),r=require("@stll/folio-core/utils/clipboard"),i=require("@stll/folio-core/managers/ClipboardManager"),a=require("@stll/folio-core/managers/TableSelectionManager"),o=require("@stll/folio-core/prosemirror/utils/visualLineNavigation"),s=require("@stll/folio-core/prosemirror/utils/extractTrackedChanges");function c(e={}){let{onCopy:n,onCut:i,onPaste:a,cleanWordFormatting:o=!0,editable:s=!0,onError:c}=e,l=(0,t.ref)(!1),u=(0,t.ref)(null),d=c?{onError:c}:{};async function f(e){if(l.value)return!1;l.value=!0;try{let t=await(0,r.copyRuns)(e.runs,d);return t&&n?.(e),t}finally{l.value=!1}}async function p(e){if(l.value||!s)return!1;l.value=!0;try{let t=await(0,r.copyRuns)(e.runs,d);return t&&i?.(e),t}finally{l.value=!1}}async function m(e=!1){if(l.value||!s)return null;l.value=!0;try{if(navigator.clipboard&&navigator.clipboard.read){let t=await navigator.clipboard.read(),n=``,i=``;for(let e of t)e.types.includes(`text/html`)&&(n=await(await e.getType(`text/html`)).text()),e.types.includes(`text/plain`)&&(i=await(await e.getType(`text/plain`)).text());e&&(n=``);let s=(0,r.parseClipboardHtml)(n,i,o);return u.value=s,a?.(s,e),s}return null}catch(e){return c?.(e instanceof Error?e:Error(String(e))),null}finally{l.value=!1}}return{copy:f,cut:p,paste:m,isProcessing:l,lastPastedContent:u}}function l({isOpen:e,onClose:n,align:r=`left`}){let i=(0,t.ref)(null),a=(0,t.ref)(null),o=(0,t.ref)({position:`fixed`,top:`0px`,left:`0px`,zIndex:1e4});function s(e,t){o.value={position:`fixed`,top:e+`px`,left:t+`px`,zIndex:1e4}}function c(e){let t=e.target;t instanceof Node&&i.value&&!i.value.contains(t)&&a.value&&!a.value.contains(t)&&n()}function l(e){e.key===`Escape`&&n()}function u(e){let t=e.target;t instanceof Node&&a.value&&a.value.contains(t)||n()}function d(){document.addEventListener(`mousedown`,c),document.addEventListener(`keydown`,l),window.addEventListener(`scroll`,u,!0)}function f(){document.removeEventListener(`mousedown`,c),document.removeEventListener(`keydown`,l),window.removeEventListener(`scroll`,u,!0)}(0,t.watch)(e,e=>{if(!e){f();return}let t=i.value;if(!t)return;let n=t.getBoundingClientRect();r===`right`?requestAnimationFrame(()=>{let e=a.value;if(e){let t=e.getBoundingClientRect();s(n.bottom+4,n.right-t.width)}else s(n.bottom+4,n.left)}):s(n.bottom+4,n.left),d()}),(0,t.onScopeDispose)(f);function p(e){e.preventDefault(),e.stopPropagation()}return{containerRef:i,dropdownRef:a,dropdownStyle:o,handleMouseDown:p}}function u(e,r){let i=(0,t.computed)(()=>{r.value;let t=e.value;return t?(0,n.undoDepth)(t.state)>0:!1}),a=(0,t.computed)(()=>{r.value;let t=e.value;return t?(0,n.redoDepth)(t.state)>0:!1});function o(){let t=e.value;return t?(0,n.undo)(t.state,t.dispatch):!1}function s(){let t=e.value;return t?(0,n.redo)(t.state,t.dispatch):!1}return{canUndo:i,canRedo:a,undo:o,redo:s}}var d={backgroundColor:`rgba(26, 115, 232, 0.3)`,borderRadius:0,zIndex:0,opacity:1,mixBlendMode:`multiply`};function f(e){let t=window.getSelection();if(!t||t.rangeCount===0||t.isCollapsed)return[];let n=t.getRangeAt(0);if(e&&!e.contains(n.commonAncestorContainer))return[];let r=0,i=0;if(e){let t=e.getBoundingClientRect();r=t.left+e.scrollLeft,i=t.top+e.scrollTop}let a=[];for(let e of n.getClientRects())e.width===0&&e.height===0||a.push({left:e.left-r,top:e.top-i,width:e.width,height:e.height});return a}function p(e,t=2){if(e.length<=1)return e;let n=[...e].sort((e,n)=>Math.abs(e.top-n.top)<t?e.left-n.left:e.top-n.top),r=n[0];if(!r)return e;let i=[],a={...r};for(let e=1;e<n.length;e++){let r=n[e];if(!r)continue;let o=Math.abs(r.top-a.top)<t,s=r.left<=a.left+a.width+t;if(o&&s){let e=Math.max(a.left+a.width,r.left+r.width);a.width=e-a.left,a.height=Math.max(a.height,r.height)}else i.push(a),a={...r}}return i.push(a),i}function m(e){return p(f(e))}function h(){let e=window.getSelection();return e!==null&&!e.isCollapsed&&e.rangeCount>0}function g(e){let t=window.getSelection();return!t||t.rangeCount===0?!1:e.contains(t.getRangeAt(0).commonAncestorContainer)}var _=`docx-selection-styles`,v=null;function y(){v&&=(v.remove(),null),document.getElementById(_)?.remove()}function b(e=d){y();let t=` | ||
| Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./useZoom-C7jhL696.cjs");let t=require("vue"),n=require("prosemirror-history"),r=require("@stll/folio-core/utils/clipboard"),i=require("@stll/folio-core/managers/ClipboardManager"),a=require("@stll/folio-core/managers/TableSelectionManager"),o=require("@stll/folio-core/prosemirror/utils/visualLineNavigation"),s=require("@stll/folio-core/prosemirror/utils/extractTrackedChanges");function c(e={}){let{onCopy:n,onCut:i,onPaste:a,cleanWordFormatting:o=!0,editable:s=!0,onError:c}=e,l=(0,t.ref)(!1),u=(0,t.ref)(null),d=c?{onError:c}:{};async function f(e){if(l.value)return!1;l.value=!0;try{let t=await(0,r.copyRuns)(e.runs,d);return t&&n?.(e),t}finally{l.value=!1}}async function p(e){if(l.value||!s)return!1;l.value=!0;try{let t=await(0,r.copyRuns)(e.runs,d);return t&&i?.(e),t}finally{l.value=!1}}async function m(e=!1){if(l.value||!s)return null;l.value=!0;try{if(navigator.clipboard&&navigator.clipboard.read){let t=await navigator.clipboard.read(),n=``,i=``;for(let e of t)e.types.includes(`text/html`)&&(n=await(await e.getType(`text/html`)).text()),e.types.includes(`text/plain`)&&(i=await(await e.getType(`text/plain`)).text());e&&(n=``);let s=(0,r.parseClipboardHtml)(n,i,o);return u.value=s,a?.(s,e),s}return null}catch(e){return c?.(e instanceof Error?e:Error(String(e))),null}finally{l.value=!1}}return{copy:f,cut:p,paste:m,isProcessing:l,lastPastedContent:u}}function l({isOpen:e,onClose:n,align:r=`left`}){let i=(0,t.ref)(null),a=(0,t.ref)(null),o=(0,t.ref)({position:`fixed`,top:`0px`,left:`0px`,zIndex:1e4});function s(e,t){o.value={position:`fixed`,top:e+`px`,left:t+`px`,zIndex:1e4}}function c(e){let t=e.target;t instanceof Node&&i.value&&!i.value.contains(t)&&a.value&&!a.value.contains(t)&&n()}function l(e){e.key===`Escape`&&n()}function u(e){let t=e.target;t instanceof Node&&a.value&&a.value.contains(t)||n()}function d(){document.addEventListener(`mousedown`,c),document.addEventListener(`keydown`,l),window.addEventListener(`scroll`,u,!0)}function f(){document.removeEventListener(`mousedown`,c),document.removeEventListener(`keydown`,l),window.removeEventListener(`scroll`,u,!0)}(0,t.watch)(e,e=>{if(!e){f();return}let t=i.value;if(!t)return;let n=t.getBoundingClientRect();r===`right`?requestAnimationFrame(()=>{let e=a.value;if(e){let t=e.getBoundingClientRect();s(n.bottom+4,n.right-t.width)}else s(n.bottom+4,n.left)}):s(n.bottom+4,n.left),d()}),(0,t.onScopeDispose)(f);function p(e){e.preventDefault(),e.stopPropagation()}return{containerRef:i,dropdownRef:a,dropdownStyle:o,handleMouseDown:p}}function u(e,r){let i=(0,t.computed)(()=>{r.value;let t=e.value;return t?(0,n.undoDepth)(t.state)>0:!1}),a=(0,t.computed)(()=>{r.value;let t=e.value;return t?(0,n.redoDepth)(t.state)>0:!1});function o(){let t=e.value;return t?(0,n.undo)(t.state,t.dispatch):!1}function s(){let t=e.value;return t?(0,n.redo)(t.state,t.dispatch):!1}return{canUndo:i,canRedo:a,undo:o,redo:s}}var d={backgroundColor:`rgba(26, 115, 232, 0.3)`,borderRadius:0,zIndex:0,opacity:1,mixBlendMode:`multiply`};function f(e){let t=window.getSelection();if(!t||t.rangeCount===0||t.isCollapsed)return[];let n=t.getRangeAt(0);if(e&&!e.contains(n.commonAncestorContainer))return[];let r=0,i=0;if(e){let t=e.getBoundingClientRect();r=t.left+e.scrollLeft,i=t.top+e.scrollTop}let a=[];for(let e of n.getClientRects())e.width===0&&e.height===0||a.push({left:e.left-r,top:e.top-i,width:e.width,height:e.height});return a}function p(e,t=2){if(e.length<=1)return e;let n=[...e].sort((e,n)=>Math.abs(e.top-n.top)<t?e.left-n.left:e.top-n.top),r=n[0];if(!r)return e;let i=[],a={...r};for(let e=1;e<n.length;e++){let r=n[e];if(!r)continue;let o=Math.abs(r.top-a.top)<t,s=r.left<=a.left+a.width+t;if(o&&s){let e=Math.max(a.left+a.width,r.left+r.width);a.width=e-a.left,a.height=Math.max(a.height,r.height)}else i.push(a),a={...r}}return i.push(a),i}function m(e){return p(f(e))}function h(){let e=window.getSelection();return e!==null&&!e.isCollapsed&&e.rangeCount>0}function g(e){let t=window.getSelection();return!t||t.rangeCount===0?!1:e.contains(t.getRangeAt(0).commonAncestorContainer)}var _=`docx-selection-styles`,v=null;function y(){v&&=(v.remove(),null),document.getElementById(_)?.remove()}function b(e=d){y();let t=` | ||
| /* DOCX Editor Selection Highlighting */ | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
| import { a as e, i as t, n, o as r, r as i, t as a } from "./useZoom-BxDANpqb.js"; | ||
| import { a as e, i as t, n, o as r, r as i, t as a } from "./useZoom-zJvuJlUd.js"; | ||
| import { computed as o, onBeforeUnmount as s, onMounted as c, onScopeDispose as l, ref as u, watch as d } from "vue"; | ||
@@ -3,0 +3,0 @@ import { redo as f, redoDepth as p, undo as m, undoDepth as h } from "prosemirror-history"; |
+1
-1
| { | ||
| "name": "@stll/folio-vue", | ||
| "version": "0.6.1", | ||
| "version": "0.7.0", | ||
| "description": "Vue 3 editor for folio: a Word-document (.docx) editor for the browser, built on @stll/folio-core and ProseMirror.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
| let e=require("vue"),t=require("@stll/folio-core/paged-layout/sectionGeometry"),n=require("@stll/folio-core/prosemirror/plugins/anonymizationDecorations"),r=require("@stll/folio-core/prosemirror/plugins/templateDirectives"),i=require("@stll/folio-core/prosemirror/plugins/suggestionMode"),a=require("@stll/folio-core/controller/folioEditor"),o=require("@stll/folio-core/controller/folioEditorEvents"),s=require("@stll/folio-core/controller/hiddenEditorManager"),c=require("@stll/folio-core/controller/layoutPipeline"),l=require("@stll/folio-core/controller/layoutScheduler"),u=require("@stll/folio-core/controller/layoutSession"),d=require("@stll/folio-core/docx/parser"),f=require("@stll/folio-core/docx/footnoteParser"),p=require("@stll/folio-core/layout-bridge/convert/headerFooterLayout"),m=require("@stll/folio-core/layout-painter"),h=require("@stll/folio-core/paged-layout/LayoutSelectionGate"),g=require("@stll/folio-core/paged-layout/transactionDirtyRange"),_=require("@stll/folio-core/prosemirror/conversion/fromProseDoc"),v=require("@stll/folio-core/prosemirror/extensions/ExtensionManager"),y=require("@stll/folio-core/prosemirror/extensions/features/ParagraphChangeTrackerExtension"),ee=require("@stll/folio-core/prosemirror/extensions/StarterKit"),te=require("@stll/folio-core/prosemirror/plugins/templatePreviewValues"),ne=require("@stll/folio-core/prosemirror/plugins/templateSlashMenu"),b=require("@stll/folio-core/utils/findVerticalScrollParent"),x=require("@stll/folio-core/prosemirror/tableResize"),S=require("@stll/folio-core/prosemirror/utils/extractTrackedChanges"),C=require("@stll/folio-core/utils/zoom");var re=24,ie=32,ae=96,oe=250,se=[];function ce(e){let n=e?.columnCount??1;if(n<=1)return;let r={count:n,gap:(0,t.twipsToPixels)(e?.columnSpace??720),equalWidth:e?.equalWidth??!0};return e?.separator!==void 0&&(r.separator=e.separator),r}function w(e){let t={};e.titlePg!==void 0&&(t.titlePg=e.titlePg);for(let n of e.headerReferences??[])n.type==="default"?t.headerDefault=n.rId:n.type===`first`?t.headerFirst=n.rId:t.headerEven=n.rId;for(let n of e.footerReferences??[])n.type==="default"?t.footerDefault=n.rId:n.type===`first`?t.footerFirst=n.rId:t.footerEven=n.rId;return t}function le(e){let t=e?.package.document;if(!t)return;let n=t.sections;if(n&&n.length>0)return n.map(e=>w(e.properties));let r=t.finalSectionProperties;if(r)return[w(r)]}var T={hf:null,rId:null};function ue(e,t){let n=e?.package;if(!n||!t)return{header:T,footer:T,firstHeader:T,firstFooter:T};let r=n.headers,i=n.footers,a=e=>e?r?.get(e)??null:null,o=e=>e?i?.get(e)??null:null,s=null,c=null;for(let e of t.headerReferences??[])e.type==="default"?s=e.rId:e.type===`first`&&(c=e.rId);let l=null,u=null;for(let e of t.footerReferences??[])e.type==="default"?l=e.rId:e.type===`first`&&(u=e.rId);return{header:{hf:a(s),rId:s},footer:{hf:o(l),rId:l},firstHeader:{hf:a(c),rId:c},firstFooter:{hf:o(u),rId:u}}}function E(e,t,n,r,i,a){if(!e)return;let o=t?{...a,rId:t}:a,s=t?n?.getView(t):null;return s?(0,p.convertHeaderFooterPmDocToContent)(s.state.doc,r,i,o):(0,p.convertHeaderFooterToContent)(e,r,i,o)}function de(e,t,n,r,i){if(!e||e.size===0)return;let a=new Map;for(let[o,s]of e){let e=E(s,o,t,n,r,i);e&&a.set(o,e)}return a.size>0?a:void 0}function fe(e,t,n){let r=new Map;if(!n||!n.package.footnotes)return r;let i=new Map;for(let e of n.package.footnotes)e.noteType&&e.noteType!==`normal`||i.set(e.id,e);for(let[n,a]of e){let e=[];for(let n of a){let r=i.get(n);if(!r)continue;let a=t.get(n),o=a?.displayNumber??0;e.push({displayNumber:String(o),text:(0,f.getFootnoteText)(r),...a?{content:{blocks:a.blocks,measures:a.measures,height:a.height}}:{}})}e.length>0&&r.set(n,e)}return r}var D=new Set([`black`,`blue`,`cyan`,`darkBlue`,`darkCyan`,`darkGray`,`darkGreen`,`darkMagenta`,`darkRed`,`darkYellow`,`green`,`lightGray`,`magenta`,`none`,`red`,`white`,`yellow`]);function pe(e){let t=[],n=(e,r)=>{for(let[n,i]of e.marks.entries())i.type.name===`highlight`&&!D.has(String(i.attrs.color))&&t.push(`${r}.marks[${n}]=${JSON.stringify(i.attrs)}`);e.forEach((e,t,i)=>{n(e,`${r}.content[${i}]`)})};return n(e,`doc`),t.join(`; `)}function me(){return typeof document>`u`||!(`fonts`in document)||document.fonts.status===`loaded`}function he(f){let{hiddenContainer:p,pagesContainer:b,readOnly:x=!1,pageGap:S=re,documentKey:C,password:w,editorMode:T,author:D,externalPlugins:he=[],onAnonymizationMatchesChange:ge,showTemplateDirectives:_e,onSlashMenuChange:ve,onSlashMenuKeyAction:O,onChange:k,onError:A,onSelectionUpdate:j,onEditorViewReady:M,onReadOnlyEditAttempt:N,featureFlags:P,onSelectiveSaveTripwire:F}=f,I=(0,e.shallowRef)(null),L=(0,e.shallowRef)(null),R=(0,e.shallowRef)(null),z=(0,e.shallowRef)(null),B=(0,e.shallowRef)([]),ye=(0,e.shallowRef)([]),V=(0,e.ref)(!1),H=(0,e.ref)(null),U=(0,e.ref)(!1),W=new v.ExtensionManager((0,ee.createStarterKit)());W.buildSchema(),W.initializeRuntime();let be=(0,i.createSuggestionModePlugin)(!1),xe=(0,n.createAnonymizationDecorationsPlugin)({onMatchesChange:e=>ge?.(e)}),G=(0,r.createTemplateDirectivesPlugin)(),K=(0,ne.templateSlashMenuPlugin)({onChange:e=>ve?.(e),onKeyAction:e=>O?.(e)??!1}),Se=(0,te.createTemplatePreviewValuesPlugin)(),q=()=>(0,e.toValue)(_e)===!0;function Ce(){return[be,...he,xe,...q()?[G,K]:[],Se]}let J=(0,o.createFolioEditorEmitter)(),Y=new h.LayoutSelectionGate,we=(0,u.createLayoutSession)(),Te=new m.LayoutPainter({pageGap:S,showShadow:!0});function Ee(e){e.layout&&(z.value=e.layout),e.blocks&&(B.value=e.blocks),e.measures&&(ye.value=e.measures),e.blockLookup&&Te.setBlockLookup(e.blockLookup),e.layout&&J.emit(`layoutComplete`,e.layout)}function X(e,n={}){let r=b.value,i=r instanceof HTMLDivElement?r:null,a=I.value,o=a?.package.document,s=o?.sections?.[0]?.properties??o?.finalSectionProperties??null,l=(0,t.getPageSize)(s),u=(0,t.getMargins)(s),d=ce(s),f=l.w-u.left-u.right,p=a?.package.styles??null,m=a?.package.theme??null,h=a?.package.settings?.defaultTabStop,g=a?.package.settings,_=g!==void 0&&`mirrorMargins`in g&&g.mirrorMargins===!0,v=ue(a,s);try{Ee((0,c.runLayoutPipeline)({contentWidth:f,columns:d,pageSize:l,margins:u,pageGap:S,syncCoordinator:Y,headerContent:v.header.hf,footerContent:v.footer.hf,firstPageHeaderContent:v.firstHeader.hf,firstPageFooterContent:v.firstFooter.hf,headerContentRId:v.header.rId,footerContentRId:v.footer.rId,firstPageHeaderContentRId:v.firstHeader.rId,firstPageFooterContentRId:v.firstFooter.rId,sectionHeaderFooterRefs:le(a),theme:m,sectionProperties:s,document:a,defaultTabStop:h,mirrorMargins:_,styles:p,layout:z.value,hfPMs:null,painter:Te,pagesContainer:i,session:we,renderHfFromContentOrPm:E,renderHeaderFooterContentByRId:de,documentFontsAreLoaded:me,buildFootnoteRenderItems:fe,describeInvalidHighlightMarks:pe,emptyTemplatePreviewEntries:se},e,n))}catch(e){let t=e instanceof Error?e:Error(String(e));A?.(t)}}let Z=(0,l.createLayoutScheduler)({runLayout:(e,t)=>X(e,t),debounceMs:ie,maxDelayMs:ae,clock:l.browserClock}),Q=null;function De(){Q!==null&&(window.clearTimeout(Q),Q=null);let e=L.value,t=I.value;if(!(!e||!t))try{let n=(0,_.fromProseDoc)(e.state.doc,t);I.value=n,k?.(n),J.emit(`docChange`,n)}catch(e){A?.(e instanceof Error?e:Error(String(e)))}}function Oe(){Q!==null&&window.clearTimeout(Q),Q=window.setTimeout(()=>{Q=null,De()},oe)}let $=(0,s.createHiddenEditorManager)({getHost:()=>p.value,getDocument:()=>I.value,getStyles:()=>I.value?.package.styles??null,getExtensionManager:()=>W,getExternalPlugins:Ce,getCollaboration:()=>void 0,getCollaborationModules:()=>null,getPrecomputedInitialState:()=>null,getReadOnly:()=>(0,e.toValue)(x),getDocumentKey:()=>(0,e.toValue)(C),getDocumentContext:()=>I.value,onTransaction:ke,onSelectionChange:e=>{R.value=e,j?.(e),J.emit(`selectionChange`,{from:e.selection.from,to:e.selection.to})},onKeyDown:()=>!1,onReadOnlyEditAttempt:()=>N?.(),onEditorViewReady:Ae,onEditorViewDestroy:()=>{L.value=null,V.value=!1,M?.(null)},onRemoteSelectionsChange:()=>{}});function ke(e,t){R.value=t,e.docChanged&&(U.value=!0,Y.incrementStateSeq(),Z.schedule(t,(0,g.getTransactionDirtyRange)(e)),Oe()),Y.requestRender()}function Ae(t){L.value=t,R.value=t.state,V.value=!0,X(t.state,{reason:`initial`}),Y.requestRender(),Me(t),M?.(t),(0,e.toValue)(x)||requestAnimationFrame(()=>{L.value===t&&t.focus()})}let je=(0,a.createFolioEditor)({getEditorApi:()=>$.api,getLayout:()=>z.value,runLayout:(e,t)=>X(e,t),emitter:J});function Me(t){(0,i.setSuggestionMode)((0,e.toValue)(T)===`suggesting`,t.state,t.dispatch,(0,e.toValue)(D))}(0,e.watch)([()=>(0,e.toValue)(T),()=>(0,e.toValue)(D)],()=>{let e=L.value;e&&Me(e)}),(0,e.watch)(()=>(0,e.toValue)(x),()=>$.syncEditable());function Ne(e){let t=q();if(t===e.state.plugins.includes(G))return;let n=e.state.plugins.filter(e=>e!==G&&e!==K);if(t){let e=n.indexOf(Se),t=e===-1?n.length:e;n.splice(t,0,G,K)}e.updateState(e.state.reconfigure({plugins:n}))}(0,e.watch)(()=>q(),()=>{let e=L.value;e&&Ne(e)});function Pe(){$.ensureView()}function Fe(){U.value=!1,Z.dispose(),$.destroyView(),$.ensureView(),$.getView()||Ie()}function Ie(){let e=I.value;if(e)try{let t=(0,s.createHiddenEditorState)({document:e,styles:e.package.styles??null,manager:W,externalPlugins:Ce(),collaborationModules:null,reason:`mount`});R.value=t,X(t,{reason:`initial`})}catch(e){A?.(e instanceof Error?e:Error(String(e)))}}(0,e.watch)([p,b],()=>{p.value&&I.value&&!$.getView()&&Pe()},{flush:`post`});async function Le(t){H.value=null,V.value=!1;try{let n=await(0,d.parseDocx)(t,{password:(0,e.toValue)(w)});I.value=n,Fe()}catch(e){let t=e instanceof Error?e:Error(String(e));H.value=t.message,A?.(t)}}function Re(e){H.value=null,I.value=e,Fe()}async function ze(t){let n=L.value,r=I.value;if(!n||!r)return null;let i=n.state,{resolveSelectiveSaveFlags:a}=await import(`@stll/folio-core/docx/selectiveSaveFlags`),o=a((0,e.toValue)(P)),s=(0,_.fromProseDoc)(i.doc,r),c=s.originalBuffer??null,l=o.selectiveSave&&t?.selective!==!1,u=l||o.selectiveSaveTripwire,{repackDocx:d,createDocx:f}=await import(`@stll/folio-core/docx/rezip`),p=null;if(u&&c){let{attemptSelectiveSave:e}=await import(`@stll/folio-core/docx/selectiveSave`);p=await e(s,c,{changedParaIds:(0,y.getChangedParagraphIds)(i),structuralChange:(0,y.hasStructuralChanges)(i),hasUntrackedChanges:(0,y.hasUntrackedChanges)(i),maxBytes:o.selectiveSaveMaxBytes})}let m=l?p:null,h=null;if(!m)h=c?await d(s):await f(s),m=h;else if(o.selectiveSaveTripwire)try{h=await d(s)}catch{}if(o.selectiveSaveTripwire&&h&&F)try{let{compareSelectiveVsFull:e}=await import(`@stll/folio-core/docx/selectiveSaveTripwire`);F(await e(p,h))}catch{}return U.value=!1,new Blob([m],{type:`application/vnd.openxmlformats-officedocument.wordprocessingml.document`})}function Be(){return I.value}function Ve(e){I.value=e}function He(){return W.getCommands()}function Ue(){L.value?.focus()}function We(){let e=L.value;e&&X(e.state,{reason:`manual`})}function Ge(){Z.dispose(),Q!==null&&(window.clearTimeout(Q),Q=null),$.destroyView(),W.destroy(),R.value=null,z.value=null,I.value=null,V.value=!1}return(0,e.onScopeDispose)(Ge),{editor:je,editorView:L,editorState:R,isReady:V,isDirty:U,parseError:H,layout:z,blocks:B,measures:ye,loadBuffer:Le,loadDocument:Re,save:ze,getDocument:Be,setDocument:Ve,getCommands:He,focus:Ue,reLayout:We,destroy:Ge}}function ge(e,t){if(t<e.top+40){let n=Math.max(0,e.top+40-t);return-Math.min(12,n/40*12)}if(t>e.bottom-40){let n=Math.max(0,t-(e.bottom-40));return Math.min(12,n/40*12)}return 0}function _e({pagesContainer:t,onScrollExtendSelection:n}){let r=null,i=0,a=0,o=!1,s=null;function c(){if(s)return s;let e=t.value;return e?(s=(0,b.findVerticalScrollParent)(e),s):null}function l(){o=!1,r!==null&&(cancelAnimationFrame(r),r=null)}function u(){if(!o)return;let e=c();if(!e)return;let t=ge(e.getBoundingClientRect(),a);t!==0&&(e.scrollTop+=t,n(i,a)),r=requestAnimationFrame(u)}function d(){o||(o=!0,r=requestAnimationFrame(u))}function f(e,t){if(i=e,a=t,!o){let e=c();if(!e)return;let n=e.getBoundingClientRect();(t<n.top+40||t>n.bottom-40)&&d()}}return(0,e.onScopeDispose)(()=>l()),{updateMousePosition:f,stopAutoScroll:l}}function ve(){let e={active:!1,startX:0,handle:null,columnIndex:0,tablePmStart:0,origWidths:{left:0,right:0}},t={active:!1,startY:0,handle:null,rowIndex:0,isEdge:!1,tablePmStart:0,origHeight:0},n={active:!1,startX:0,handle:null,columnIndex:0,tablePmStart:0,origWidth:0},r=null;function i(){return e.active||t.active||n.active}function a(i,a){let o=i.target;return o instanceof HTMLElement?o.classList.contains(`layout-table-resize-handle`)?(i.preventDefault(),i.stopPropagation(),r=a,e.active=!0,e.startX=i.clientX,e.handle=o,o.classList.add(`dragging`),e.columnIndex=parseInt(o.dataset.columnIndex??`0`,10),e.tablePmStart=parseInt(o.dataset.tablePmStart??`0`,10),O(a,e),!0):o.classList.contains(`layout-table-row-resize-handle`)||o.classList.contains(`layout-table-edge-handle-bottom`)?(i.preventDefault(),i.stopPropagation(),r=a,t.active=!0,t.startY=i.clientY,t.handle=o,t.isEdge=o.dataset.isEdge===`bottom`,o.classList.add(`dragging`),t.rowIndex=parseInt(o.dataset.rowIndex??`0`,10),t.tablePmStart=parseInt(o.dataset.tablePmStart??`0`,10),k(a,t,o),!0):o.classList.contains(`layout-table-edge-handle-right`)?(i.preventDefault(),i.stopPropagation(),r=a,n.active=!0,n.startX=i.clientX,n.handle=o,o.classList.add(`dragging`),n.columnIndex=parseInt(o.dataset.columnIndex??`0`,10),n.tablePmStart=parseInt(o.dataset.tablePmStart??`0`,10),A(a,n),!0):!1:!1}function o(r){if(e.active&&e.handle){r.preventDefault();let t=r.clientX-e.startX,n=parseFloat(e.handle.style.left);e.handle.style.left=`${n+t}px`,e.startX=r.clientX;let i=Math.round(t*x.TWIPS_PER_PIXEL),a=e.origWidths.left+i,o=e.origWidths.right-i;a>=x.MIN_CELL_WIDTH_TWIPS&&o>=x.MIN_CELL_WIDTH_TWIPS&&(e.origWidths={left:a,right:o});return}if(t.active&&t.handle){r.preventDefault();let e=r.clientY-t.startY,n=parseFloat(t.handle.style.top);t.handle.style.top=`${n+e}px`,t.startY=r.clientY;let i=Math.round(e*x.TWIPS_PER_PIXEL),a=t.origHeight+i;a>=x.MIN_ROW_HEIGHT_TWIPS&&(t.origHeight=a);return}if(n.active&&n.handle){r.preventDefault();let e=r.clientX-n.startX,t=parseFloat(n.handle.style.left);n.handle.style.left=`${t+e}px`,n.startX=r.clientX;let i=Math.round(e*x.TWIPS_PER_PIXEL),a=n.origWidth+i;a>=x.MIN_CELL_WIDTH_TWIPS&&(n.origWidth=a)}}function s(i){if(e.active){e.active=!1,e.handle?.classList.remove(`dragging`),r&&(0,x.commitColumnResize)(r,{pmStart:e.tablePmStart,colIdx:e.columnIndex,newLeft:e.origWidths.left,newRight:e.origWidths.right}),e.handle=null;return}if(t.active){t.active=!1,t.handle?.classList.remove(`dragging`),r&&(0,x.commitRowResize)(r,{pmStart:t.tablePmStart,rowIdx:t.rowIndex,newHeight:t.origHeight}),t.handle=null;return}n.active&&(n.active=!1,n.handle?.classList.remove(`dragging`),r&&(0,x.commitRightEdgeResize)(r,{pmStart:n.tablePmStart,colIdx:n.columnIndex,newWidth:n.origWidth}),n.handle=null)}function c(){return document.addEventListener(`mousemove`,o),document.addEventListener(`mouseup`,s),()=>{document.removeEventListener(`mousemove`,o),document.removeEventListener(`mouseup`,s)}}return{tryStartResize:a,install:c,isResizing:i}}function O(e,t){let n=(0,x.readColumnWidths)(e,t.tablePmStart,t.columnIndex);n&&(t.origWidths=n)}function k(e,t,n){let r=(0,x.readRowHeight)(e,t.tablePmStart,t.rowIndex);if(r!=null){t.origHeight=r;return}let i=n.closest(`.layout-table`)?.querySelector(`[data-row-index="${t.rowIndex}"]`),a=i?i.getBoundingClientRect().height:30;t.origHeight=Math.round(a*x.TWIPS_PER_PIXEL)}function A(e,t){let n=(0,x.readColumnWidthAt)(e,t.tablePmStart,t.columnIndex);n!=null&&(t.origWidth=n)}function j(t,n){return(0,e.computed)(()=>(n.value,(0,S.extractTrackedChanges)(t.value?.state??null)))}var M=C.ZOOM_MIN,N=C.ZOOM_MAX,P=[.5,.75,1,1.25,1.5,2];function F(t=1){let n=(0,e.ref)(Math.max(M,Math.min(N,t))),r=(0,e.computed)(()=>Math.round(n.value*100)),i=(0,e.computed)(()=>n.value<=M),a=(0,e.computed)(()=>n.value>=N);function o(e){n.value=Math.max(M,Math.min(N,Math.round(e*100)/100))}function s(){o(n.value+C.ZOOM_STEP)}function c(){o(n.value-C.ZOOM_STEP)}function l(){o(1)}function u(e){(e.ctrlKey||e.metaKey)&&(e.preventDefault(),e.deltaY<0?s():c())}function d(e){(e.ctrlKey||e.metaKey)&&(e.shiftKey||e.altKey||(e.key===`=`||e.key===`+`?(e.preventDefault(),s()):e.key===`-`?(e.preventDefault(),c()):e.key===`0`&&(e.preventDefault(),l())))}function f(){(0,e.onMounted)(()=>document.addEventListener(`keydown`,d)),(0,e.onBeforeUnmount)(()=>document.removeEventListener(`keydown`,d))}return{zoom:n,zoomPercent:r,isMinZoom:i,isMaxZoom:a,setZoom:o,zoomIn:s,zoomOut:c,resetZoom:l,handleWheel:u,handleKeyDown:d,installShortcuts:f,ZOOM_PRESETS:P}}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return _e}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return F}}); |
| import { computed as e, onBeforeUnmount as t, onMounted as n, onScopeDispose as r, ref as i, shallowRef as a, toValue as o, watch as s } from "vue"; | ||
| import { getMargins as c, getPageSize as l, twipsToPixels as u } from "@stll/folio-core/paged-layout/sectionGeometry"; | ||
| import { createAnonymizationDecorationsPlugin as d } from "@stll/folio-core/prosemirror/plugins/anonymizationDecorations"; | ||
| import { createTemplateDirectivesPlugin as f } from "@stll/folio-core/prosemirror/plugins/templateDirectives"; | ||
| import { createSuggestionModePlugin as p, setSuggestionMode as m } from "@stll/folio-core/prosemirror/plugins/suggestionMode"; | ||
| import { createFolioEditor as h } from "@stll/folio-core/controller/folioEditor"; | ||
| import { createFolioEditorEmitter as ee } from "@stll/folio-core/controller/folioEditorEvents"; | ||
| import { createHiddenEditorManager as g, createHiddenEditorState as _ } from "@stll/folio-core/controller/hiddenEditorManager"; | ||
| import { runLayoutPipeline as te } from "@stll/folio-core/controller/layoutPipeline"; | ||
| import { browserClock as v, createLayoutScheduler as ne } from "@stll/folio-core/controller/layoutScheduler"; | ||
| import { createLayoutSession as re } from "@stll/folio-core/controller/layoutSession"; | ||
| import { parseDocx as ie } from "@stll/folio-core/docx/parser"; | ||
| import { getFootnoteText as y } from "@stll/folio-core/docx/footnoteParser"; | ||
| import { convertHeaderFooterPmDocToContent as ae, convertHeaderFooterToContent as b } from "@stll/folio-core/layout-bridge/convert/headerFooterLayout"; | ||
| import { LayoutPainter as oe } from "@stll/folio-core/layout-painter"; | ||
| import { LayoutSelectionGate as se } from "@stll/folio-core/paged-layout/LayoutSelectionGate"; | ||
| import { getTransactionDirtyRange as ce } from "@stll/folio-core/paged-layout/transactionDirtyRange"; | ||
| import { fromProseDoc as x } from "@stll/folio-core/prosemirror/conversion/fromProseDoc"; | ||
| import { ExtensionManager as le } from "@stll/folio-core/prosemirror/extensions/ExtensionManager"; | ||
| import { getChangedParagraphIds as ue, hasStructuralChanges as de, hasUntrackedChanges as fe } from "@stll/folio-core/prosemirror/extensions/features/ParagraphChangeTrackerExtension"; | ||
| import { createStarterKit as pe } from "@stll/folio-core/prosemirror/extensions/StarterKit"; | ||
| import { createTemplatePreviewValuesPlugin as me } from "@stll/folio-core/prosemirror/plugins/templatePreviewValues"; | ||
| import { templateSlashMenuPlugin as he } from "@stll/folio-core/prosemirror/plugins/templateSlashMenu"; | ||
| import { findVerticalScrollParent as S } from "@stll/folio-core/utils/findVerticalScrollParent"; | ||
| import { MIN_CELL_WIDTH_TWIPS as C, MIN_ROW_HEIGHT_TWIPS as w, TWIPS_PER_PIXEL as T, commitColumnResize as E, commitRightEdgeResize as ge, commitRowResize as _e, readColumnWidthAt as ve, readColumnWidths as D, readRowHeight as ye } from "@stll/folio-core/prosemirror/tableResize"; | ||
| import { extractTrackedChanges as O } from "@stll/folio-core/prosemirror/utils/extractTrackedChanges"; | ||
| import { ZOOM_MAX as k, ZOOM_MIN as A, ZOOM_STEP as j } from "@stll/folio-core/utils/zoom"; | ||
| //#region src/composables/useDocxEditor.ts | ||
| var be = 24, xe = 32, Se = 96, Ce = 250, we = []; | ||
| function Te(e) { | ||
| let t = e?.columnCount ?? 1; | ||
| if (t <= 1) return; | ||
| let n = { | ||
| count: t, | ||
| gap: u(e?.columnSpace ?? 720), | ||
| equalWidth: e?.equalWidth ?? !0 | ||
| }; | ||
| return e?.separator !== void 0 && (n.separator = e.separator), n; | ||
| } | ||
| function M(e) { | ||
| let t = {}; | ||
| e.titlePg !== void 0 && (t.titlePg = e.titlePg); | ||
| for (let n of e.headerReferences ?? []) n.type === "default" ? t.headerDefault = n.rId : n.type === "first" ? t.headerFirst = n.rId : t.headerEven = n.rId; | ||
| for (let n of e.footerReferences ?? []) n.type === "default" ? t.footerDefault = n.rId : n.type === "first" ? t.footerFirst = n.rId : t.footerEven = n.rId; | ||
| return t; | ||
| } | ||
| function Ee(e) { | ||
| let t = e?.package.document; | ||
| if (!t) return; | ||
| let n = t.sections; | ||
| if (n && n.length > 0) return n.map((e) => M(e.properties)); | ||
| let r = t.finalSectionProperties; | ||
| if (r) return [M(r)]; | ||
| } | ||
| var N = { | ||
| hf: null, | ||
| rId: null | ||
| }; | ||
| function De(e, t) { | ||
| let n = e?.package; | ||
| if (!n || !t) return { | ||
| header: N, | ||
| footer: N, | ||
| firstHeader: N, | ||
| firstFooter: N | ||
| }; | ||
| let r = n.headers, i = n.footers, a = (e) => e ? r?.get(e) ?? null : null, o = (e) => e ? i?.get(e) ?? null : null, s = null, c = null; | ||
| for (let e of t.headerReferences ?? []) e.type === "default" ? s = e.rId : e.type === "first" && (c = e.rId); | ||
| let l = null, u = null; | ||
| for (let e of t.footerReferences ?? []) e.type === "default" ? l = e.rId : e.type === "first" && (u = e.rId); | ||
| return { | ||
| header: { | ||
| hf: a(s), | ||
| rId: s | ||
| }, | ||
| footer: { | ||
| hf: o(l), | ||
| rId: l | ||
| }, | ||
| firstHeader: { | ||
| hf: a(c), | ||
| rId: c | ||
| }, | ||
| firstFooter: { | ||
| hf: o(u), | ||
| rId: u | ||
| } | ||
| }; | ||
| } | ||
| function Oe(e, t, n, r, i, a) { | ||
| if (!e) return; | ||
| let o = t ? { | ||
| ...a, | ||
| rId: t | ||
| } : a, s = t ? n?.getView(t) : null; | ||
| return s ? ae(s.state.doc, r, i, o) : b(e, r, i, o); | ||
| } | ||
| function ke(e, t, n, r, i) { | ||
| if (!e || e.size === 0) return; | ||
| let a = /* @__PURE__ */ new Map(); | ||
| for (let [o, s] of e) { | ||
| let e = Oe(s, o, t, n, r, i); | ||
| e && a.set(o, e); | ||
| } | ||
| return a.size > 0 ? a : void 0; | ||
| } | ||
| function Ae(e, t, n) { | ||
| let r = /* @__PURE__ */ new Map(); | ||
| if (!n || !n.package.footnotes) return r; | ||
| let i = /* @__PURE__ */ new Map(); | ||
| for (let e of n.package.footnotes) e.noteType && e.noteType !== "normal" || i.set(e.id, e); | ||
| for (let [n, a] of e) { | ||
| let e = []; | ||
| for (let n of a) { | ||
| let r = i.get(n); | ||
| if (!r) continue; | ||
| let a = t.get(n), o = a?.displayNumber ?? 0; | ||
| e.push({ | ||
| displayNumber: String(o), | ||
| text: y(r), | ||
| ...a ? { content: { | ||
| blocks: a.blocks, | ||
| measures: a.measures, | ||
| height: a.height | ||
| } } : {} | ||
| }); | ||
| } | ||
| e.length > 0 && r.set(n, e); | ||
| } | ||
| return r; | ||
| } | ||
| var P = /* @__PURE__ */ new Set([ | ||
| "black", | ||
| "blue", | ||
| "cyan", | ||
| "darkBlue", | ||
| "darkCyan", | ||
| "darkGray", | ||
| "darkGreen", | ||
| "darkMagenta", | ||
| "darkRed", | ||
| "darkYellow", | ||
| "green", | ||
| "lightGray", | ||
| "magenta", | ||
| "none", | ||
| "red", | ||
| "white", | ||
| "yellow" | ||
| ]); | ||
| function je(e) { | ||
| let t = [], n = (e, r) => { | ||
| for (let [n, i] of e.marks.entries()) i.type.name === "highlight" && !P.has(String(i.attrs.color)) && t.push(`${r}.marks[${n}]=${JSON.stringify(i.attrs)}`); | ||
| e.forEach((e, t, i) => { | ||
| n(e, `${r}.content[${i}]`); | ||
| }); | ||
| }; | ||
| return n(e, "doc"), t.join("; "); | ||
| } | ||
| function Me() { | ||
| return typeof document > "u" || !("fonts" in document) || document.fonts.status === "loaded"; | ||
| } | ||
| function F(e) { | ||
| let { hiddenContainer: t, pagesContainer: n, readOnly: u = !1, pageGap: y = be, documentKey: ae, password: b, editorMode: S, author: C, externalPlugins: w = [], onAnonymizationMatchesChange: T, showTemplateDirectives: E, onSlashMenuChange: ge, onSlashMenuKeyAction: _e, onChange: ve, onError: D, onSelectionUpdate: ye, onEditorViewReady: O, onReadOnlyEditAttempt: k, featureFlags: A, onSelectiveSaveTripwire: j } = e, M = a(null), N = a(null), P = a(null), F = a(null), I = a([]), L = a([]), R = i(!1), z = i(null), B = i(!1), V = new le(pe()); | ||
| V.buildSchema(), V.initializeRuntime(); | ||
| let H = p(!1), U = d({ onMatchesChange: (e) => T?.(e) }), W = f(), G = he({ | ||
| onChange: (e) => ge?.(e), | ||
| onKeyAction: (e) => _e?.(e) ?? !1 | ||
| }), K = me(), q = () => o(E) === !0; | ||
| function Ne() { | ||
| return [ | ||
| H, | ||
| ...w, | ||
| U, | ||
| ...q() ? [W, G] : [], | ||
| K | ||
| ]; | ||
| } | ||
| let J = ee(), Y = new se(), Pe = re(), Fe = new oe({ | ||
| pageGap: y, | ||
| showShadow: !0 | ||
| }); | ||
| function Ie(e) { | ||
| e.layout && (F.value = e.layout), e.blocks && (I.value = e.blocks), e.measures && (L.value = e.measures), e.blockLookup && Fe.setBlockLookup(e.blockLookup), e.layout && J.emit("layoutComplete", e.layout); | ||
| } | ||
| function X(e, t = {}) { | ||
| let r = n.value, i = r instanceof HTMLDivElement ? r : null, a = M.value, o = a?.package.document, s = o?.sections?.[0]?.properties ?? o?.finalSectionProperties ?? null, u = l(s), d = c(s), f = Te(s), p = u.w - d.left - d.right, m = a?.package.styles ?? null, h = a?.package.theme ?? null, ee = a?.package.settings?.defaultTabStop, g = a?.package.settings, _ = g !== void 0 && "mirrorMargins" in g && g.mirrorMargins === !0, v = De(a, s); | ||
| try { | ||
| Ie(te({ | ||
| contentWidth: p, | ||
| columns: f, | ||
| pageSize: u, | ||
| margins: d, | ||
| pageGap: y, | ||
| syncCoordinator: Y, | ||
| headerContent: v.header.hf, | ||
| footerContent: v.footer.hf, | ||
| firstPageHeaderContent: v.firstHeader.hf, | ||
| firstPageFooterContent: v.firstFooter.hf, | ||
| headerContentRId: v.header.rId, | ||
| footerContentRId: v.footer.rId, | ||
| firstPageHeaderContentRId: v.firstHeader.rId, | ||
| firstPageFooterContentRId: v.firstFooter.rId, | ||
| sectionHeaderFooterRefs: Ee(a), | ||
| theme: h, | ||
| sectionProperties: s, | ||
| document: a, | ||
| defaultTabStop: ee, | ||
| mirrorMargins: _, | ||
| styles: m, | ||
| layout: F.value, | ||
| hfPMs: null, | ||
| painter: Fe, | ||
| pagesContainer: i, | ||
| session: Pe, | ||
| renderHfFromContentOrPm: Oe, | ||
| renderHeaderFooterContentByRId: ke, | ||
| documentFontsAreLoaded: Me, | ||
| buildFootnoteRenderItems: Ae, | ||
| describeInvalidHighlightMarks: je, | ||
| emptyTemplatePreviewEntries: we | ||
| }, e, t)); | ||
| } catch (e) { | ||
| let t = e instanceof Error ? e : Error(String(e)); | ||
| D?.(t); | ||
| } | ||
| } | ||
| let Z = ne({ | ||
| runLayout: (e, t) => X(e, t), | ||
| debounceMs: xe, | ||
| maxDelayMs: Se, | ||
| clock: v | ||
| }), Q = null; | ||
| function Le() { | ||
| Q !== null && (window.clearTimeout(Q), Q = null); | ||
| let e = N.value, t = M.value; | ||
| if (!(!e || !t)) try { | ||
| let n = x(e.state.doc, t); | ||
| M.value = n, ve?.(n), J.emit("docChange", n); | ||
| } catch (e) { | ||
| D?.(e instanceof Error ? e : Error(String(e))); | ||
| } | ||
| } | ||
| function Re() { | ||
| Q !== null && window.clearTimeout(Q), Q = window.setTimeout(() => { | ||
| Q = null, Le(); | ||
| }, Ce); | ||
| } | ||
| let $ = g({ | ||
| getHost: () => t.value, | ||
| getDocument: () => M.value, | ||
| getStyles: () => M.value?.package.styles ?? null, | ||
| getExtensionManager: () => V, | ||
| getExternalPlugins: Ne, | ||
| getCollaboration: () => void 0, | ||
| getCollaborationModules: () => null, | ||
| getPrecomputedInitialState: () => null, | ||
| getReadOnly: () => o(u), | ||
| getDocumentKey: () => o(ae), | ||
| getDocumentContext: () => M.value, | ||
| onTransaction: ze, | ||
| onSelectionChange: (e) => { | ||
| P.value = e, ye?.(e), J.emit("selectionChange", { | ||
| from: e.selection.from, | ||
| to: e.selection.to | ||
| }); | ||
| }, | ||
| onKeyDown: () => !1, | ||
| onReadOnlyEditAttempt: () => k?.(), | ||
| onEditorViewReady: Be, | ||
| onEditorViewDestroy: () => { | ||
| N.value = null, R.value = !1, O?.(null); | ||
| }, | ||
| onRemoteSelectionsChange: () => {} | ||
| }); | ||
| function ze(e, t) { | ||
| P.value = t, e.docChanged && (B.value = !0, Y.incrementStateSeq(), Z.schedule(t, ce(e)), Re()), Y.requestRender(); | ||
| } | ||
| function Be(e) { | ||
| N.value = e, P.value = e.state, R.value = !0, X(e.state, { reason: "initial" }), Y.requestRender(), He(e), O?.(e), o(u) || requestAnimationFrame(() => { | ||
| N.value === e && e.focus(); | ||
| }); | ||
| } | ||
| let Ve = h({ | ||
| getEditorApi: () => $.api, | ||
| getLayout: () => F.value, | ||
| runLayout: (e, t) => X(e, t), | ||
| emitter: J | ||
| }); | ||
| function He(e) { | ||
| m(o(S) === "suggesting", e.state, e.dispatch, o(C)); | ||
| } | ||
| s([() => o(S), () => o(C)], () => { | ||
| let e = N.value; | ||
| e && He(e); | ||
| }), s(() => o(u), () => $.syncEditable()); | ||
| function Ue(e) { | ||
| let t = q(); | ||
| if (t === e.state.plugins.includes(W)) return; | ||
| let n = e.state.plugins.filter((e) => e !== W && e !== G); | ||
| if (t) { | ||
| let e = n.indexOf(K), t = e === -1 ? n.length : e; | ||
| n.splice(t, 0, W, G); | ||
| } | ||
| e.updateState(e.state.reconfigure({ plugins: n })); | ||
| } | ||
| s(() => q(), () => { | ||
| let e = N.value; | ||
| e && Ue(e); | ||
| }); | ||
| function We() { | ||
| $.ensureView(); | ||
| } | ||
| function Ge() { | ||
| B.value = !1, Z.dispose(), $.destroyView(), $.ensureView(), $.getView() || Ke(); | ||
| } | ||
| function Ke() { | ||
| let e = M.value; | ||
| if (e) try { | ||
| let t = _({ | ||
| document: e, | ||
| styles: e.package.styles ?? null, | ||
| manager: V, | ||
| externalPlugins: Ne(), | ||
| collaborationModules: null, | ||
| reason: "mount" | ||
| }); | ||
| P.value = t, X(t, { reason: "initial" }); | ||
| } catch (e) { | ||
| D?.(e instanceof Error ? e : Error(String(e))); | ||
| } | ||
| } | ||
| s([t, n], () => { | ||
| t.value && M.value && !$.getView() && We(); | ||
| }, { flush: "post" }); | ||
| async function qe(e) { | ||
| z.value = null, R.value = !1; | ||
| try { | ||
| let t = await ie(e, { password: o(b) }); | ||
| M.value = t, Ge(); | ||
| } catch (e) { | ||
| let t = e instanceof Error ? e : Error(String(e)); | ||
| z.value = t.message, D?.(t); | ||
| } | ||
| } | ||
| function Je(e) { | ||
| z.value = null, M.value = e, Ge(); | ||
| } | ||
| async function Ye(e) { | ||
| let t = N.value, n = M.value; | ||
| if (!t || !n) return null; | ||
| let r = t.state, { resolveSelectiveSaveFlags: i } = await import("@stll/folio-core/docx/selectiveSaveFlags"), a = i(o(A)), s = x(r.doc, n), c = s.originalBuffer ?? null, l = a.selectiveSave && e?.selective !== !1, u = l || a.selectiveSaveTripwire, { repackDocx: d, createDocx: f } = await import("@stll/folio-core/docx/rezip"), p = null; | ||
| if (u && c) { | ||
| let { attemptSelectiveSave: e } = await import("@stll/folio-core/docx/selectiveSave"); | ||
| p = await e(s, c, { | ||
| changedParaIds: ue(r), | ||
| structuralChange: de(r), | ||
| hasUntrackedChanges: fe(r), | ||
| maxBytes: a.selectiveSaveMaxBytes | ||
| }); | ||
| } | ||
| let m = l ? p : null, h = null; | ||
| if (!m) h = c ? await d(s) : await f(s), m = h; | ||
| else if (a.selectiveSaveTripwire) try { | ||
| h = await d(s); | ||
| } catch {} | ||
| if (a.selectiveSaveTripwire && h && j) try { | ||
| let { compareSelectiveVsFull: e } = await import("@stll/folio-core/docx/selectiveSaveTripwire"); | ||
| j(await e(p, h)); | ||
| } catch {} | ||
| return B.value = !1, new Blob([m], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" }); | ||
| } | ||
| function Xe() { | ||
| return M.value; | ||
| } | ||
| function Ze(e) { | ||
| M.value = e; | ||
| } | ||
| function Qe() { | ||
| return V.getCommands(); | ||
| } | ||
| function $e() { | ||
| N.value?.focus(); | ||
| } | ||
| function et() { | ||
| let e = N.value; | ||
| e && X(e.state, { reason: "manual" }); | ||
| } | ||
| function tt() { | ||
| Z.dispose(), Q !== null && (window.clearTimeout(Q), Q = null), $.destroyView(), V.destroy(), P.value = null, F.value = null, M.value = null, R.value = !1; | ||
| } | ||
| return r(tt), { | ||
| editor: Ve, | ||
| editorView: N, | ||
| editorState: P, | ||
| isReady: R, | ||
| isDirty: B, | ||
| parseError: z, | ||
| layout: F, | ||
| blocks: I, | ||
| measures: L, | ||
| loadBuffer: qe, | ||
| loadDocument: Je, | ||
| save: Ye, | ||
| getDocument: Xe, | ||
| setDocument: Ze, | ||
| getCommands: Qe, | ||
| focus: $e, | ||
| reLayout: et, | ||
| destroy: tt | ||
| }; | ||
| } | ||
| function I(e, t) { | ||
| if (t < e.top + 40) { | ||
| let n = Math.max(0, e.top + 40 - t); | ||
| return -Math.min(12, n / 40 * 12); | ||
| } | ||
| if (t > e.bottom - 40) { | ||
| let n = Math.max(0, t - (e.bottom - 40)); | ||
| return Math.min(12, n / 40 * 12); | ||
| } | ||
| return 0; | ||
| } | ||
| //#endregion | ||
| //#region src/composables/useDragAutoScroll.ts | ||
| function L({ pagesContainer: e, onScrollExtendSelection: t }) { | ||
| let n = null, i = 0, a = 0, o = !1, s = null; | ||
| function c() { | ||
| if (s) return s; | ||
| let t = e.value; | ||
| return t ? (s = S(t), s) : null; | ||
| } | ||
| function l() { | ||
| o = !1, n !== null && (cancelAnimationFrame(n), n = null); | ||
| } | ||
| function u() { | ||
| if (!o) return; | ||
| let e = c(); | ||
| if (!e) return; | ||
| let r = I(e.getBoundingClientRect(), a); | ||
| r !== 0 && (e.scrollTop += r, t(i, a)), n = requestAnimationFrame(u); | ||
| } | ||
| function d() { | ||
| o || (o = !0, n = requestAnimationFrame(u)); | ||
| } | ||
| function f(e, t) { | ||
| if (i = e, a = t, !o) { | ||
| let e = c(); | ||
| if (!e) return; | ||
| let n = e.getBoundingClientRect(); | ||
| (t < n.top + 40 || t > n.bottom - 40) && d(); | ||
| } | ||
| } | ||
| return r(() => l()), { | ||
| updateMousePosition: f, | ||
| stopAutoScroll: l | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/composables/useTableResize.ts | ||
| function R() { | ||
| let e = { | ||
| active: !1, | ||
| startX: 0, | ||
| handle: null, | ||
| columnIndex: 0, | ||
| tablePmStart: 0, | ||
| origWidths: { | ||
| left: 0, | ||
| right: 0 | ||
| } | ||
| }, t = { | ||
| active: !1, | ||
| startY: 0, | ||
| handle: null, | ||
| rowIndex: 0, | ||
| isEdge: !1, | ||
| tablePmStart: 0, | ||
| origHeight: 0 | ||
| }, n = { | ||
| active: !1, | ||
| startX: 0, | ||
| handle: null, | ||
| columnIndex: 0, | ||
| tablePmStart: 0, | ||
| origWidth: 0 | ||
| }, r = null; | ||
| function i() { | ||
| return e.active || t.active || n.active; | ||
| } | ||
| function a(i, a) { | ||
| let o = i.target; | ||
| return o instanceof HTMLElement ? o.classList.contains("layout-table-resize-handle") ? (i.preventDefault(), i.stopPropagation(), r = a, e.active = !0, e.startX = i.clientX, e.handle = o, o.classList.add("dragging"), e.columnIndex = parseInt(o.dataset.columnIndex ?? "0", 10), e.tablePmStart = parseInt(o.dataset.tablePmStart ?? "0", 10), z(a, e), !0) : o.classList.contains("layout-table-row-resize-handle") || o.classList.contains("layout-table-edge-handle-bottom") ? (i.preventDefault(), i.stopPropagation(), r = a, t.active = !0, t.startY = i.clientY, t.handle = o, t.isEdge = o.dataset.isEdge === "bottom", o.classList.add("dragging"), t.rowIndex = parseInt(o.dataset.rowIndex ?? "0", 10), t.tablePmStart = parseInt(o.dataset.tablePmStart ?? "0", 10), B(a, t, o), !0) : o.classList.contains("layout-table-edge-handle-right") ? (i.preventDefault(), i.stopPropagation(), r = a, n.active = !0, n.startX = i.clientX, n.handle = o, o.classList.add("dragging"), n.columnIndex = parseInt(o.dataset.columnIndex ?? "0", 10), n.tablePmStart = parseInt(o.dataset.tablePmStart ?? "0", 10), V(a, n), !0) : !1 : !1; | ||
| } | ||
| function o(r) { | ||
| if (e.active && e.handle) { | ||
| r.preventDefault(); | ||
| let t = r.clientX - e.startX, n = parseFloat(e.handle.style.left); | ||
| e.handle.style.left = `${n + t}px`, e.startX = r.clientX; | ||
| let i = Math.round(t * T), a = e.origWidths.left + i, o = e.origWidths.right - i; | ||
| a >= C && o >= C && (e.origWidths = { | ||
| left: a, | ||
| right: o | ||
| }); | ||
| return; | ||
| } | ||
| if (t.active && t.handle) { | ||
| r.preventDefault(); | ||
| let e = r.clientY - t.startY, n = parseFloat(t.handle.style.top); | ||
| t.handle.style.top = `${n + e}px`, t.startY = r.clientY; | ||
| let i = Math.round(e * T), a = t.origHeight + i; | ||
| a >= w && (t.origHeight = a); | ||
| return; | ||
| } | ||
| if (n.active && n.handle) { | ||
| r.preventDefault(); | ||
| let e = r.clientX - n.startX, t = parseFloat(n.handle.style.left); | ||
| n.handle.style.left = `${t + e}px`, n.startX = r.clientX; | ||
| let i = Math.round(e * T), a = n.origWidth + i; | ||
| a >= C && (n.origWidth = a); | ||
| } | ||
| } | ||
| function s(i) { | ||
| if (e.active) { | ||
| e.active = !1, e.handle?.classList.remove("dragging"), r && E(r, { | ||
| pmStart: e.tablePmStart, | ||
| colIdx: e.columnIndex, | ||
| newLeft: e.origWidths.left, | ||
| newRight: e.origWidths.right | ||
| }), e.handle = null; | ||
| return; | ||
| } | ||
| if (t.active) { | ||
| t.active = !1, t.handle?.classList.remove("dragging"), r && _e(r, { | ||
| pmStart: t.tablePmStart, | ||
| rowIdx: t.rowIndex, | ||
| newHeight: t.origHeight | ||
| }), t.handle = null; | ||
| return; | ||
| } | ||
| n.active && (n.active = !1, n.handle?.classList.remove("dragging"), r && ge(r, { | ||
| pmStart: n.tablePmStart, | ||
| colIdx: n.columnIndex, | ||
| newWidth: n.origWidth | ||
| }), n.handle = null); | ||
| } | ||
| function c() { | ||
| return document.addEventListener("mousemove", o), document.addEventListener("mouseup", s), () => { | ||
| document.removeEventListener("mousemove", o), document.removeEventListener("mouseup", s); | ||
| }; | ||
| } | ||
| return { | ||
| tryStartResize: a, | ||
| install: c, | ||
| isResizing: i | ||
| }; | ||
| } | ||
| function z(e, t) { | ||
| let n = D(e, t.tablePmStart, t.columnIndex); | ||
| n && (t.origWidths = n); | ||
| } | ||
| function B(e, t, n) { | ||
| let r = ye(e, t.tablePmStart, t.rowIndex); | ||
| if (r != null) { | ||
| t.origHeight = r; | ||
| return; | ||
| } | ||
| let i = n.closest(".layout-table")?.querySelector(`[data-row-index="${t.rowIndex}"]`), a = i ? i.getBoundingClientRect().height : 30; | ||
| t.origHeight = Math.round(a * T); | ||
| } | ||
| function V(e, t) { | ||
| let n = ve(e, t.tablePmStart, t.columnIndex); | ||
| n != null && (t.origWidth = n); | ||
| } | ||
| //#endregion | ||
| //#region src/composables/useTrackedChanges.ts | ||
| function H(t, n) { | ||
| return e(() => (n.value, O(t.value?.state ?? null))); | ||
| } | ||
| //#endregion | ||
| //#region src/composables/useZoom.ts | ||
| var U = A, W = k, G = [ | ||
| .5, | ||
| .75, | ||
| 1, | ||
| 1.25, | ||
| 1.5, | ||
| 2 | ||
| ]; | ||
| function K(r = 1) { | ||
| let a = i(Math.max(U, Math.min(W, r))), o = e(() => Math.round(a.value * 100)), s = e(() => a.value <= U), c = e(() => a.value >= W); | ||
| function l(e) { | ||
| a.value = Math.max(U, Math.min(W, Math.round(e * 100) / 100)); | ||
| } | ||
| function u() { | ||
| l(a.value + j); | ||
| } | ||
| function d() { | ||
| l(a.value - j); | ||
| } | ||
| function f() { | ||
| l(1); | ||
| } | ||
| function p(e) { | ||
| (e.ctrlKey || e.metaKey) && (e.preventDefault(), e.deltaY < 0 ? u() : d()); | ||
| } | ||
| function m(e) { | ||
| (e.ctrlKey || e.metaKey) && (e.shiftKey || e.altKey || (e.key === "=" || e.key === "+" ? (e.preventDefault(), u()) : e.key === "-" ? (e.preventDefault(), d()) : e.key === "0" && (e.preventDefault(), f()))); | ||
| } | ||
| function h() { | ||
| n(() => document.addEventListener("keydown", m)), t(() => document.removeEventListener("keydown", m)); | ||
| } | ||
| return { | ||
| zoom: a, | ||
| zoomPercent: o, | ||
| isMinZoom: s, | ||
| isMaxZoom: c, | ||
| setZoom: l, | ||
| zoomIn: u, | ||
| zoomOut: d, | ||
| resetZoom: f, | ||
| handleWheel: p, | ||
| handleKeyDown: m, | ||
| installShortcuts: h, | ||
| ZOOM_PRESETS: G | ||
| }; | ||
| } | ||
| //#endregion | ||
| export { L as a, R as i, O as n, F as o, H as r, K as t }; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
1186722
-0.04%20081
-0.04%8
14.29%