@stll/folio-vue 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- 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"),ee=require("@stll/folio-core/prosemirror/extensions/ExtensionManager"),v=require("@stll/folio-core/prosemirror/extensions/features/ParagraphChangeTrackerExtension"),te=require("@stll/folio-core/prosemirror/extensions/StarterKit"),ne=require("@stll/folio-core/prosemirror/plugins/templatePreviewValues"),re=require("@stll/folio-core/prosemirror/plugins/templateSlashMenu"),y=require("@stll/folio-core/utils/findVerticalScrollParent"),b=require("@stll/folio-core/prosemirror/tableResize"),x=require("@stll/folio-core/prosemirror/utils/extractTrackedChanges");var ie=24,ae=32,oe=96,se=250,ce=[];function le(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 S(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 ue(e){let t=e?.package.document;if(!t)return;let n=t.sections;if(n&&n.length>0)return n.map(e=>S(e.properties));let r=t.finalSectionProperties;if(r)return[S(r)]}var C={hf:null,rId:null};function de(e,t){let n=e?.package;if(!n||!t)return{header:C,footer:C,firstHeader:C,firstFooter:C};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 w(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 fe(e,t,n,r,i){if(!e||e.size===0)return;let a=new Map;for(let[o,s]of e){let e=w(s,o,t,n,r,i);e&&a.set(o,e)}return a.size>0?a:void 0}function pe(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 T=new Set([`black`,`blue`,`cyan`,`darkBlue`,`darkCyan`,`darkGray`,`darkGreen`,`darkMagenta`,`darkRed`,`darkYellow`,`green`,`lightGray`,`magenta`,`none`,`red`,`white`,`yellow`]);function me(e){let t=[],n=(e,r)=>{for(let[n,i]of e.marks.entries())i.type.name===`highlight`&&!T.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 he(){return typeof document>`u`||!(`fonts`in document)?!0:document.fonts.status===`loaded`}function ge(f){let{hiddenContainer:p,pagesContainer:y,readOnly:b=!1,pageGap:x=ie,documentKey:S,editorMode:C,author:T,externalPlugins:ge=[],onAnonymizationMatchesChange:_e,showTemplateDirectives:ve,onSlashMenuChange:ye,onSlashMenuKeyAction:be,onChange:xe,onError:E,onSelectionUpdate:D,onEditorViewReady:O,onReadOnlyEditAttempt:k,featureFlags:A,onSelectiveSaveTripwire:j}=f,M=(0,e.shallowRef)(null),N=(0,e.shallowRef)(null),P=(0,e.shallowRef)(null),F=(0,e.shallowRef)(null),I=(0,e.shallowRef)([]),L=(0,e.shallowRef)([]),R=(0,e.ref)(!1),z=(0,e.ref)(null),B=(0,e.ref)(!1),V=new ee.ExtensionManager((0,te.createStarterKit)());V.buildSchema(),V.initializeRuntime();let Se=(0,i.createSuggestionModePlugin)(!1),Ce=(0,n.createAnonymizationDecorationsPlugin)({onMatchesChange:e=>_e?.(e)}),H=(0,r.createTemplateDirectivesPlugin)(),U=(0,re.templateSlashMenuPlugin)({onChange:e=>ye?.(e),onKeyAction:e=>be?.(e)??!1}),W=(0,ne.createTemplatePreviewValuesPlugin)(),G=()=>(0,e.toValue)(ve)===!0;function K(){return[Se,...ge,Ce,...G()?[H,U]:[],W]}let q=(0,o.createFolioEditorEmitter)(),J=new h.LayoutSelectionGate,we=(0,u.createLayoutSession)(),Te=new m.LayoutPainter({pageGap:x,showShadow:!0});function Ee(e){e.layout&&(F.value=e.layout),e.blocks&&(I.value=e.blocks),e.measures&&(L.value=e.measures),e.blockLookup&&Te.setBlockLookup(e.blockLookup),e.layout&&q.emit(`layoutComplete`,e.layout)}function Y(e,n={}){let r=y.value,i=r instanceof HTMLDivElement?r:null,a=M.value,o=a?.package.document,s=o?.sections?.[0]?.properties??o?.finalSectionProperties??null,l=(0,t.getPageSize)(s),u=(0,t.getMargins)(s),d=le(s),f=l.w-u.left-u.right,p=a?.package.styles??null,m=a?.package.theme??null,h=a?.package.settings?.defaultTabStop,g=de(a,s);try{Ee((0,c.runLayoutPipeline)({contentWidth:f,columns:d,pageSize:l,margins:u,pageGap:x,syncCoordinator:J,headerContent:g.header.hf,footerContent:g.footer.hf,firstPageHeaderContent:g.firstHeader.hf,firstPageFooterContent:g.firstFooter.hf,headerContentRId:g.header.rId,footerContentRId:g.footer.rId,firstPageHeaderContentRId:g.firstHeader.rId,firstPageFooterContentRId:g.firstFooter.rId,sectionHeaderFooterRefs:ue(a),theme:m,sectionProperties:s,document:a,defaultTabStop:h,styles:p,layout:F.value,hfPMs:null,painter:Te,pagesContainer:i,session:we,renderHfFromContentOrPm:w,renderHeaderFooterContentByRId:fe,documentFontsAreLoaded:he,buildFootnoteRenderItems:pe,describeInvalidHighlightMarks:me,emptyTemplatePreviewEntries:ce},e,n))}catch(e){let t=e instanceof Error?e:Error(String(e));E?.(t)}}let X=(0,l.createLayoutScheduler)({runLayout:(e,t)=>Y(e,t),debounceMs:ae,maxDelayMs:oe,clock:l.browserClock}),Z=null;function De(){Z!==null&&(window.clearTimeout(Z),Z=null);let e=N.value,t=M.value;if(!(!e||!t))try{let n=(0,_.fromProseDoc)(e.state.doc,t);M.value=n,xe?.(n),q.emit(`docChange`,n)}catch(e){E?.(e instanceof Error?e:Error(String(e)))}}function Oe(){Z!==null&&window.clearTimeout(Z),Z=window.setTimeout(()=>{Z=null,De()},se)}let Q=(0,s.createHiddenEditorManager)({getHost:()=>p.value,getDocument:()=>M.value,getStyles:()=>M.value?.package.styles??null,getExtensionManager:()=>V,getExternalPlugins:K,getCollaboration:()=>void 0,getCollaborationModules:()=>null,getPrecomputedInitialState:()=>null,getReadOnly:()=>(0,e.toValue)(b),getDocumentKey:()=>(0,e.toValue)(S),getDocumentContext:()=>M.value,onTransaction:ke,onSelectionChange:e=>{P.value=e,D?.(e),q.emit(`selectionChange`,{from:e.selection.from,to:e.selection.to})},onKeyDown:()=>!1,onReadOnlyEditAttempt:()=>k?.(),onEditorViewReady:Ae,onEditorViewDestroy:()=>{N.value=null,R.value=!1,O?.(null)},onRemoteSelectionsChange:()=>{}});function ke(e,t){P.value=t,e.docChanged&&(B.value=!0,J.incrementStateSeq(),X.schedule(t,(0,g.getTransactionDirtyRange)(e)),Oe()),J.requestRender()}function Ae(t){N.value=t,P.value=t.state,R.value=!0,Y(t.state,{reason:`initial`}),J.requestRender(),Me(t),O?.(t),(0,e.toValue)(b)||requestAnimationFrame(()=>{N.value===t&&t.focus()})}let je=(0,a.createFolioEditor)({getEditorApi:()=>Q.api,getLayout:()=>F.value,runLayout:(e,t)=>Y(e,t),emitter:q});function Me(t){(0,i.setSuggestionMode)((0,e.toValue)(C)===`suggesting`,t.state,t.dispatch,(0,e.toValue)(T))}(0,e.watch)([()=>(0,e.toValue)(C),()=>(0,e.toValue)(T)],()=>{let e=N.value;e&&Me(e)}),(0,e.watch)(()=>(0,e.toValue)(b),()=>Q.syncEditable());function Ne(e){let t=G();if(t===e.state.plugins.includes(H))return;let n=e.state.plugins.filter(e=>e!==H&&e!==U);if(t){let e=n.indexOf(W),t=e===-1?n.length:e;n.splice(t,0,H,U)}e.updateState(e.state.reconfigure({plugins:n}))}(0,e.watch)(()=>G(),()=>{let e=N.value;e&&Ne(e)});function Pe(){Q.ensureView()}function Fe(){B.value=!1,X.dispose(),Q.destroyView(),Q.ensureView(),Q.getView()||Ie()}function Ie(){let e=M.value;if(e)try{let t=(0,s.createHiddenEditorState)({document:e,styles:e.package.styles??null,manager:V,externalPlugins:K(),collaborationModules:null,reason:`mount`});P.value=t,Y(t,{reason:`initial`})}catch(e){E?.(e instanceof Error?e:Error(String(e)))}}(0,e.watch)([p,y],()=>{p.value&&M.value&&!Q.getView()&&Pe()},{flush:`post`});async function Le(e){z.value=null,R.value=!1;try{M.value=await(0,d.parseDocx)(e),Fe()}catch(e){let t=e instanceof Error?e:Error(String(e));z.value=t.message,E?.(t)}}function Re(e){z.value=null,M.value=e,Fe()}async function ze(t){let n=N.value,r=M.value;if(!n||!r)return null;let i=n.state,{resolveSelectiveSaveFlags:a}=await import(`@stll/folio-core/docx/selectiveSaveFlags`),o=a((0,e.toValue)(A)),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,v.getChangedParagraphIds)(i),structuralChange:(0,v.hasStructuralChanges)(i),hasUntrackedChanges:(0,v.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&&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 Be(){return M.value}function Ve(e){M.value=e}function He(){return V.getCommands()}function Ue(){N.value?.focus()}function We(){let e=N.value;e&&Y(e.state,{reason:`manual`})}function $(){X.dispose(),Z!==null&&(window.clearTimeout(Z),Z=null),Q.destroyView(),V.destroy(),P.value=null,F.value=null,M.value=null,R.value=!1}return(0,e.onScopeDispose)($),{editor:je,editorView:N,editorState:P,isReady:R,isDirty:B,parseError:z,layout:F,blocks:I,measures:L,loadBuffer:Le,loadDocument:Re,save:ze,getDocument:Be,setDocument:Ve,getCommands:He,focus:Ue,reLayout:We,destroy:$}}function _e(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 ve({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,y.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=_e(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 ye(){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),be(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),xe(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),E(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*b.TWIPS_PER_PIXEL),a=e.origWidths.left+i,o=e.origWidths.right-i;a>=b.MIN_CELL_WIDTH_TWIPS&&o>=b.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*b.TWIPS_PER_PIXEL),a=t.origHeight+i;a>=b.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*b.TWIPS_PER_PIXEL),a=n.origWidth+i;a>=b.MIN_CELL_WIDTH_TWIPS&&(n.origWidth=a)}}function s(i){if(e.active){e.active=!1,e.handle?.classList.remove(`dragging`),r&&(0,b.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,b.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,b.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 be(e,t){let n=(0,b.readColumnWidths)(e,t.tablePmStart,t.columnIndex);n&&(t.origWidths=n)}function xe(e,t,n){let r=(0,b.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*b.TWIPS_PER_PIXEL)}function E(e,t){let n=(0,b.readColumnWidthAt)(e,t.tablePmStart,t.columnIndex);n!=null&&(t.origWidth=n)}function D(t,n){return(0,e.computed)(()=>(n.value,(0,x.extractTrackedChanges)(t.value?.state??null)))}var O=.5,k=2,A=.1,j=[.5,.75,1,1.25,1.5,2];function M(t=1){let n=(0,e.ref)(Math.max(O,Math.min(k,t))),r=(0,e.computed)(()=>Math.round(n.value*100)),i=(0,e.computed)(()=>n.value<=O),a=(0,e.computed)(()=>n.value>=k);function o(e){n.value=Math.max(O,Math.min(k,Math.round(e*100)/100))}function s(){o(n.value+A)}function c(){o(n.value-A)}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 ge}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return M}});