@stll/folio-vue 0.6.1 → 0.8.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"),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}});