@eigenpal/docx-editor-vue 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/DocxEditor/types.d.ts +19 -0
- package/dist/composables/usePagesPointer.d.ts +2 -2
- package/dist/composables.cjs +1 -1
- package/dist/composables.js +1 -1
- package/dist/docx-editor-vue.css +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.js +746 -560
- package/dist/{useTableResize-BbyKMoa9.js → useTableResize-BcBdSaOE.js} +193 -187
- package/dist/useTableResize-DTag4SY0.cjs +1 -0
- package/package.json +4 -4
- package/dist/useTableResize-CIV2YW70.cjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e=require(`vue`),t=require(`prosemirror-state`),n=require(`@eigenpal/docx-editor-core/layout-bridge`),r=require(`@eigenpal/docx-editor-core/layout-painter`),i=require(`@eigenpal/docx-editor-core/prosemirror/conversion`),a=require(`@eigenpal/docx-editor-core/prosemirror`),o=require(`prosemirror-view`),s=require(`@eigenpal/docx-editor-core/docx/parser`),c=require(`@eigenpal/docx-editor-core/prosemirror/conversion/fromProseDoc`),l=require(`@eigenpal/docx-editor-core/prosemirror/schema`),u=require(`@eigenpal/docx-editor-core/prosemirror/plugins`),d=require(`@eigenpal/docx-editor-core/prosemirror/extensions`),f=require(`@eigenpal/docx-editor-core/layout-bridge/toFlowBlocks`),p=require(`@eigenpal/docx-editor-core/layout-bridge/measuring`),m=require(`@eigenpal/docx-editor-core/layout-engine`),h=require(`@eigenpal/docx-editor-core/layout-painter/renderPage`);require(`prosemirror-view/style/prosemirror.css`),require(`@eigenpal/docx-editor-core/prosemirror/editor.css`);var g=24;function _(e,t,r,i){switch(e.kind){case`paragraph`:return(0,p.measureParagraph)(e,t,{floatingZones:r,paragraphYOffset:i??0});case`table`:return(0,n.measureTableBlock)(e,t,_);case`image`:{let t=e;return{kind:`image`,width:t.width??100,height:t.height??100}}case`textBox`:{let t=e,n=t.margins??m.DEFAULT_TEXTBOX_MARGINS,r=(t.width??m.DEFAULT_TEXTBOX_WIDTH)-n.left-n.right,i=t.content.map(e=>(0,p.measureParagraph)(e,r)),a=i.reduce((e,t)=>e+t.totalHeight,0),o=t.height??a+n.top+n.bottom;return{kind:`textBox`,width:t.width??m.DEFAULT_TEXTBOX_WIDTH,height:o,innerMeasures:i}}case`pageBreak`:return{kind:`pageBreak`};case`columnBreak`:return{kind:`columnBreak`};case`sectionBreak`:return{kind:`sectionBreak`};default:(0,m.assertExhaustiveFlowBlock)(e,`vue useDocxEditor measureBlock`)}}function v(e,t){return(0,p.measureBlocksWithFloats)(e,t,_)}function y(p){let{hiddenContainer:_,pagesContainer:y,readOnly:b=!1,pageGap:x=g,onChange:S,onError:C,onSelectionUpdate:w,externalPlugins:T=[],syncCoordinator:E,editorMode:D,author:O}=p,k=(0,e.shallowRef)(null),A=(0,e.shallowRef)(null),j=(0,e.shallowRef)(null),M=(0,e.ref)(!1),N=(0,e.ref)(null),P=(0,e.shallowRef)(null),F=l.singletonManager;function I(e){let t=y.value;if(!t||!k.value)return;let i=E?.getStateSeq()??0;E?.onLayoutStart();let a=k.value.package?.document,o=a?.sections?.[0]?.properties??a?.finalSectionProperties??null,s=a?.finalSectionProperties??o,c=(0,n.getPageSize)(o),l=(0,n.getMargins)(o),u=(0,n.getPageSize)(s),d=(0,n.getMargins)(s),p=c.w-l.left-l.right,g=c.h-l.top-l.bottom,_=k.value.package?.theme??null,b=k.value.package?.styles??null;try{let i=(0,f.toFlowBlocks)(e.doc,{theme:_,pageContentHeight:g}),a=v(i,p),{header:s,footer:y,firstHeader:S,firstFooter:C}=(0,n.resolveHeaderFooter)(k.value,o),w={section:`header`,pageSize:c,margins:l},T={section:`footer`,pageSize:c,margins:l},E=e.doc.attrs?.defaultTabStopTwips,D={styles:b,theme:_,measureBlocks:v,defaultTabStopTwips:E},O=(e,t)=>{if(!e)return;let r=W(e);return r?(0,n.convertHeaderFooterPmDocToContent)(r.state.doc,p,t,D):(0,n.convertHeaderFooterToContent)(e,p,t,D)},A=O(s,w),j=O(y,T),M=o?.titlePg===!0,N=M?O(S,w):void 0,F=M?O(C,T):void 0,I=l.header??48,L=l.footer??48,R=l.top-I,z=l.bottom-L,B=e=>e?e.visualBottom??e.height:0,V=e=>e?Math.max((e.visualBottom??e.height)-(e.visualTop??0),e.height):0,H=Math.max(B(A),B(N)),U=Math.max(V(j),V(F)),G=H>R,K=U>z;if(G||K){let e=e=>{let t={...e};return G&&(t.top=Math.max(e.top,I+H)),K&&(t.bottom=Math.max(e.bottom,L+U)),t};l=e(l),d=e(d);for(let t of i){if(t.kind!==`sectionBreak`)continue;let n=t;n.margins&&=e(n.margins)}}let q={pageSize:c,margins:l,finalPageSize:u,finalMargins:d,pageGap:x},J=(0,n.collectFootnoteRefs)(i),Y=J.length>0&&!!k.value.package?.footnotes,X=(0,m.layoutDocument)(i,a,q),Z=new Map,Q=new Map;if(Y){Q=(0,n.buildFootnoteContentMap)(k.value.package.footnotes,J,p,{styles:b,theme:_,measureBlocks:v,defaultTabStopTwips:E});let e=(0,n.stabilizeFootnoteLayout)({blocks:i,measures:a,layoutOpts:q,footnoteRefs:J,footnoteContentMap:Q,initialLayout:X});X=e.layout,Z=e.pageFootnoteMap}P.value=X;let $=new Map;for(let e=0;e<i.length;e++){let t=i[e],n=a[e];t&&n&&$.set(String(t.id),{block:t,measure:n})}let ee=Y?(0,n.buildFootnoteRenderItems)(Z,Q,k.value):void 0;(0,h.renderPages)(X.pages,t,{pageGap:x,showShadow:!0,pageBackground:`#fff`,blockLookup:$,theme:_,headerContent:A,footerContent:j,firstPageHeaderContent:N,firstPageFooterContent:F,titlePage:M,footnotesByPage:ee}),t.style.overflowY=`auto`,t.style.minHeight=`0`;for(let e of Array.from(t.children))e.style.flexShrink=`0`;(0,r.applySdtFocus)(t,(0,r.enclosingSdtGroupIds)(e.doc,e.selection.from,e.selection.to))}catch(e){console.error(`[useDocxEditor] Layout pipeline error:`,e),C?.(e instanceof Error?e:Error(String(e)))}finally{E?.onLayoutComplete(i)}}function L(){let n=_.value;if(!n)return;let a=k.value?.package?.styles,s=k.value?(0,i.toProseDoc)(k.value,{styles:a??void 0}):(0,i.createEmptyDoc)(),l=(0,u.createSuggestionModePlugin)(!1),d=(0,u.createDocumentStylesPlugin)(a),f=[l,...T,...F.getPlugins()??[],d],p=t.EditorState.create({doc:s,schema:F.getSchema(),plugins:f});j.value=p;let m=new o.EditorView(n,{state:p,editable:()=>!(0,e.unref)(b),dispatchTransaction(e){if(!m)return;let t=m.state.apply(e);if(m.updateState(t),j.value=t,e.docChanged){E?.incrementStateSeq(),I(t);try{if(k.value){let e=(0,c.fromProseDoc)(t.doc,k.value);k.value=e,S?.(e)}}catch(e){console.error(`[useDocxEditor] fromProseDoc error:`,e)}}if(E?.requestRender(),w?.(),!e.docChanged){let e=y.value;e&&(0,r.applySdtFocus)(e,(0,r.enclosingSdtGroupIds)(t.doc,t.selection.from,t.selection.to))}}});A.value=m,M.value=!0,I(p),E?.requestRender()}(0,e.watch)([()=>(0,e.unref)(D),()=>(0,e.unref)(O),A],([e,t,n])=>{n&&(0,u.setSuggestionMode)(e===`suggesting`,n.state,n.dispatch,t)},{immediate:!0});function R(){A.value&&=(A.value.destroy(),null),j.value=null,M.value=!1}let z={current:null},B=new Map,V=new Map;function H(){if(z.current&&z.current.isConnected)return z.current;let e=window.document.createElement(`div`);return e.dataset.hfHost=`true`,e.style.cssText=`position: fixed; left: -9999px; top: 0; opacity: 0; z-index: -1; pointer-events: none;`,window.document.body.appendChild(e),z.current=e,e}function U(e){let t=k.value?.package;if(!t)return null;if(t.headers){for(let[n,r]of t.headers)if(r===e)return n}if(t.footers){for(let[n,r]of t.footers)if(r===e)return n}return null}function W(e){let t=U(e);return t?B.get(t)??null:null}function G(){let e=k.value?.package,n=H(),r=new Set;if(e?.headers)for(let t of e.headers.keys())r.add(t);if(e?.footers)for(let t of e.footers.keys())r.add(t);for(let[e,t]of B)r.has(e)||(t.destroy(),t.dom.parentElement?.remove(),V.get(e)?.destroy(),V.delete(e),B.delete(e));if(!e)return;let s=e.styles??null,c=e.theme??null,l=e.settings?.defaultTabStop??null;for(let f of r){if(B.has(f))continue;let r=e.headers?.get(f)??e.footers?.get(f);if(!r)continue;let p=e.headers?.has(f)?`header`:`footer`,m=new d.ExtensionManager((0,d.createStarterKit)());m.buildSchema(),m.initializeRuntime(),V.set(f,m);let h=window.document.createElement(`div`);h.dataset.hfRId=f,h.dataset.hfKind=p,n.appendChild(h);let g=(0,i.headerFooterToProseDoc)(r.content,{styles:s??void 0,theme:c,defaultTabStopTwips:l}),_=(0,u.createDocumentStylesPlugin)(s),v=t.EditorState.create({doc:g,schema:a.schema,plugins:[...m.getPlugins(),_]}),y=p,b=new o.EditorView(h,{state:v,dispatchTransaction(e){let t=b.state.apply(e);if(b.updateState(t),e.docChanged){let e=k.value?.package,n=(y===`header`?e?.headers:e?.footers)?.get(f);n&&(n.content=(0,i.proseDocToBlocks)(t.doc))}e.docChanged&&j.value&&I(j.value),q.value?.(f,b,e.docChanged)}});B.set(f,b)}}function K(){for(let e of B.values())e.destroy(),e.dom.parentElement?.remove();B.clear();for(let e of V.values())e.destroy();V.clear(),z.current&&=(z.current.remove(),null)}let q={value:null};function J(e){q.value=e}async function Y(e){N.value=null,M.value=!1;try{let t;t=e instanceof Blob||e instanceof File?await e.arrayBuffer():e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,k.value=await(0,s.parseDocx)(t),R(),K(),L(),G()}catch(e){let t=e instanceof Error?e:Error(String(e));N.value=t.message,C?.(t)}}function X(e){N.value=null,k.value=e,R(),K(),L(),G()}async function Z(){if(!A.value||!k.value)return null;let{repackDocx:e,createDocx:t}=await import(`@eigenpal/docx-editor-core/docx/rezip`),{injectReplyRangeMarkers:n,injectTCReplyRangeMarkers:r}=await import(`@eigenpal/docx-editor-core/docx`),i=(0,c.fromProseDoc)(A.value.state.doc,k.value),a=i.package.document?.comments??[];i.package.document?.content&&a.length>0&&(n(i.package.document.content,a),r(i.package.document.content,a));let o;return o=i.originalBuffer?await e(i):await t(i),new Blob([o],{type:`application/vnd.openxmlformats-officedocument.wordprocessingml.document`})}function Q(){A.value?.focus()}function $(){R(),K(),k.value=null}function ee(){return k.value}(0,e.onBeforeUnmount)(()=>{$()});function te(){return F.getCommands()}return{editorView:A,editorState:j,isReady:M,parseError:N,layout:P,loadBuffer:Y,loadDocument:X,save:Z,focus:Q,destroy:$,getDocument:ee,getCommands:te,reLayout(){A.value&&I(A.value.state)},getHfPmView:W,syncHfPMs:G,setHfTransactionListener:J,setDocument(e){k.value=e}}}var b=.25,x=4,S=.1,C=[.25,.5,.75,1,1.25,1.5,2,3,4];function w(t=1){let n=(0,e.ref)(Math.max(b,Math.min(x,t))),r=(0,e.computed)(()=>Math.round(n.value*100)),i=(0,e.computed)(()=>n.value<=b),a=(0,e.computed)(()=>n.value>=x);function o(e){n.value=Math.max(b,Math.min(x,Math.round(e*100)/100))}function s(){o(n.value+S)}function c(){o(n.value-S)}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:C}}var T=15,E=300,D=200,O=15;function k(){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?.classList?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),A(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),j(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),M(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>=E&&o>=E&&(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>=D&&(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>=E&&(n.origWidth=a)}}function s(i){if(e.active){e.active=!1,e.handle?.classList.remove(`dragging`),r&&N(r,e),e.handle=null;return}if(t.active){t.active=!1,t.handle?.classList.remove(`dragging`),r&&P(r,t),t.handle=null;return}n.active&&(n.active=!1,n.handle?.classList.remove(`dragging`),r&&F(r,n),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 A(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let e=n.depth;e>=0;e--){let r=n.node(e);if(r.type.name===`table`){let e=r.attrs.columnWidths;e&&e[t.columnIndex]!==void 0&&e[t.columnIndex+1]!==void 0&&(t.origWidths={left:e[t.columnIndex],right:e[t.columnIndex+1]});return}}}function j(e,t,n){let r=e.state.doc.resolve(t.tablePmStart+1);for(let e=r.depth;e>=0;e--){let i=r.node(e);if(i.type.name===`table`){let e=null,r=0;if(i.forEach(n=>{r===t.rowIndex&&(e=n),r++}),e){let r=e.attrs.height;if(r)t.origHeight=r;else{let e=n.closest(`.layout-table`)?.querySelector(`[data-row-index="${t.rowIndex}"]`),r=e?e.getBoundingClientRect().height:30;t.origHeight=Math.round(r*O)}}return}}}function M(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let e=n.depth;e>=0;e--){let r=n.node(e);if(r.type.name===`table`){let e=r.attrs.columnWidths;e&&e[t.columnIndex]!==void 0&&(t.origWidth=e[t.columnIndex]);return}}}function N(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let r=n.depth;r>=0;r--){let i=n.node(r);if(i.type.name!==`table`)continue;let a=n.before(r),o=e.state.tr,s=[...i.attrs.columnWidths||[]];s[t.columnIndex]=t.origWidths.left,s[t.columnIndex+1]=t.origWidths.right,o.setNodeMarkup(a,void 0,{...i.attrs,columnWidths:s});let c=a+1;i.forEach(e=>{let n=c+1,r=0;e.forEach(e=>{let i=e.attrs.colspan||1;if(r===t.columnIndex||r===t.columnIndex+1){let i=r===t.columnIndex?t.origWidths.left:t.origWidths.right;o.setNodeMarkup(o.mapping.map(n),void 0,{...e.attrs,width:i,widthType:`dxa`,colwidth:null})}n+=e.nodeSize,r+=i}),c+=e.nodeSize}),e.dispatch(o);return}}function P(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let r=n.depth;r>=0;r--){let i=n.node(r);if(i.type.name!==`table`)continue;let a=n.before(r),o=e.state.tr,s=a+1,c=0;i.forEach(e=>{c===t.rowIndex&&o.setNodeMarkup(o.mapping.map(s),void 0,{...e.attrs,height:t.origHeight,heightRule:`atLeast`}),s+=e.nodeSize,c++}),e.dispatch(o);return}}function F(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let r=n.depth;r>=0;r--){let i=n.node(r);if(i.type.name!==`table`)continue;let a=n.before(r),o=e.state.tr,s=[...i.attrs.columnWidths||[]];s[t.columnIndex]=t.origWidth,o.setNodeMarkup(a,void 0,{...i.attrs,columnWidths:s});let c=a+1;i.forEach(e=>{let n=c+1,r=0;e.forEach(e=>{let i=e.attrs.colspan||1;r===t.columnIndex&&o.setNodeMarkup(o.mapping.map(n),void 0,{...e.attrs,width:t.origWidth,widthType:`dxa`,colwidth:null}),n+=e.nodeSize,r+=i}),c+=e.nodeSize}),e.dispatch(o);return}}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return k}});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eigenpal/docx-editor-vue",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Vue 3 DOCX editor adapter for @eigenpal/docx-editor-core.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -83,9 +83,9 @@
|
|
|
83
83
|
"vue": "^3.3.0"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@eigenpal/docx-editor-agents": "^1.1
|
|
87
|
-
"@eigenpal/docx-editor-core": "^1.1
|
|
88
|
-
"@eigenpal/docx-editor-i18n": "^1.1
|
|
86
|
+
"@eigenpal/docx-editor-agents": "^1.2.1",
|
|
87
|
+
"@eigenpal/docx-editor-core": "^1.2.1",
|
|
88
|
+
"@eigenpal/docx-editor-i18n": "^1.2.1"
|
|
89
89
|
},
|
|
90
90
|
"keywords": [
|
|
91
91
|
"docx",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
let e=require(`vue`),t=require(`prosemirror-state`),n=require(`@eigenpal/docx-editor-core/layout-bridge`),r=require(`@eigenpal/docx-editor-core/prosemirror/conversion`),i=require(`@eigenpal/docx-editor-core/prosemirror`),a=require(`prosemirror-view`),o=require(`@eigenpal/docx-editor-core/docx/parser`),s=require(`@eigenpal/docx-editor-core/prosemirror/conversion/fromProseDoc`),c=require(`@eigenpal/docx-editor-core/prosemirror/schema`),l=require(`@eigenpal/docx-editor-core/prosemirror/plugins`),u=require(`@eigenpal/docx-editor-core/prosemirror/extensions`),d=require(`@eigenpal/docx-editor-core/layout-bridge/toFlowBlocks`),f=require(`@eigenpal/docx-editor-core/layout-bridge/measuring`),p=require(`@eigenpal/docx-editor-core/layout-engine`),m=require(`@eigenpal/docx-editor-core/layout-painter/renderPage`);require(`prosemirror-view/style/prosemirror.css`),require(`@eigenpal/docx-editor-core/prosemirror/editor.css`);var h=24;function g(e,t,r,i){switch(e.kind){case`paragraph`:return(0,f.measureParagraph)(e,t,{floatingZones:r,paragraphYOffset:i??0});case`table`:return(0,n.measureTableBlock)(e,t,g);case`image`:{let t=e;return{kind:`image`,width:t.width??100,height:t.height??100}}case`textBox`:{let t=e,n=t.margins??p.DEFAULT_TEXTBOX_MARGINS,r=(t.width??p.DEFAULT_TEXTBOX_WIDTH)-n.left-n.right,i=t.content.map(e=>(0,f.measureParagraph)(e,r)),a=i.reduce((e,t)=>e+t.totalHeight,0),o=t.height??a+n.top+n.bottom;return{kind:`textBox`,width:t.width??p.DEFAULT_TEXTBOX_WIDTH,height:o,innerMeasures:i}}case`pageBreak`:return{kind:`pageBreak`};case`columnBreak`:return{kind:`columnBreak`};case`sectionBreak`:return{kind:`sectionBreak`};default:(0,p.assertExhaustiveFlowBlock)(e,`vue useDocxEditor measureBlock`)}}function _(e,t){return(0,f.measureBlocksWithFloats)(e,t,g)}function v(f){let{hiddenContainer:g,pagesContainer:v,readOnly:y=!1,pageGap:b=h,onChange:x,onError:S,onSelectionUpdate:C,externalPlugins:w=[],syncCoordinator:T,editorMode:E,author:D}=f,O=(0,e.shallowRef)(null),k=(0,e.shallowRef)(null),A=(0,e.shallowRef)(null),j=(0,e.ref)(!1),M=(0,e.ref)(null),N=(0,e.shallowRef)(null),P=c.singletonManager;function F(e){let t=v.value;if(!t||!O.value)return;let r=T?.getStateSeq()??0;T?.onLayoutStart();let i=O.value.package?.document,a=i?.sections?.[0]?.properties??i?.finalSectionProperties??null,o=i?.finalSectionProperties??a,s=(0,n.getPageSize)(a),c=(0,n.getMargins)(a),l=(0,n.getPageSize)(o),u=(0,n.getMargins)(o),f=s.w-c.left-c.right,h=s.h-c.top-c.bottom,g=O.value.package?.theme??null,y=O.value.package?.styles??null;try{let r=(0,d.toFlowBlocks)(e.doc,{theme:g,pageContentHeight:h}),i=_(r,f),{header:o,footer:v,firstHeader:x,firstFooter:S}=(0,n.resolveHeaderFooter)(O.value,a),C={section:`header`,pageSize:s,margins:c},w={section:`footer`,pageSize:s,margins:c},T=e.doc.attrs?.defaultTabStopTwips,E={styles:y,theme:g,measureBlocks:_,defaultTabStopTwips:T},D=(e,t)=>{if(!e)return;let r=U(e);return r?(0,n.convertHeaderFooterPmDocToContent)(r.state.doc,f,t,E):(0,n.convertHeaderFooterToContent)(e,f,t,E)},k=D(o,C),A=D(v,w),j=a?.titlePg===!0,M=j?D(x,C):void 0,P=j?D(S,w):void 0,F=c.header??48,I=c.footer??48,L=c.top-F,R=c.bottom-I,z=e=>e?e.visualBottom??e.height:0,B=e=>e?Math.max((e.visualBottom??e.height)-(e.visualTop??0),e.height):0,V=Math.max(z(k),z(M)),H=Math.max(B(A),B(P)),W=V>L,G=H>R;if(W||G){let e=e=>{let t={...e};return W&&(t.top=Math.max(e.top,F+V)),G&&(t.bottom=Math.max(e.bottom,I+H)),t};c=e(c),u=e(u);for(let t of r){if(t.kind!==`sectionBreak`)continue;let n=t;n.margins&&=e(n.margins)}}let K={pageSize:s,margins:c,finalPageSize:l,finalMargins:u,pageGap:b},q=(0,n.collectFootnoteRefs)(r),J=q.length>0&&!!O.value.package?.footnotes,Y=(0,p.layoutDocument)(r,i,K),X=new Map,Z=new Map;if(J){Z=(0,n.buildFootnoteContentMap)(O.value.package.footnotes,q,f,{styles:y,theme:g,measureBlocks:_,defaultTabStopTwips:T});let e=(0,n.stabilizeFootnoteLayout)({blocks:r,measures:i,layoutOpts:K,footnoteRefs:q,footnoteContentMap:Z,initialLayout:Y});Y=e.layout,X=e.pageFootnoteMap}N.value=Y;let Q=new Map;for(let e=0;e<r.length;e++){let t=r[e],n=i[e];t&&n&&Q.set(String(t.id),{block:t,measure:n})}let $=J?(0,n.buildFootnoteRenderItems)(X,Z,O.value):void 0;(0,m.renderPages)(Y.pages,t,{pageGap:b,showShadow:!0,pageBackground:`#fff`,blockLookup:Q,theme:g,headerContent:k,footerContent:A,firstPageHeaderContent:M,firstPageFooterContent:P,titlePage:j,footnotesByPage:$}),t.style.overflowY=`auto`,t.style.minHeight=`0`;for(let e of Array.from(t.children))e.style.flexShrink=`0`}catch(e){console.error(`[useDocxEditor] Layout pipeline error:`,e),S?.(e instanceof Error?e:Error(String(e)))}finally{T?.onLayoutComplete(r)}}function I(){let n=g.value;if(!n)return;let i=O.value?(0,r.toProseDoc)(O.value,{styles:O.value.package?.styles??void 0}):(0,r.createEmptyDoc)(),o=[(0,l.createSuggestionModePlugin)(!1),...w,...P.getPlugins()??[]],c=t.EditorState.create({doc:i,schema:P.getSchema(),plugins:o});A.value=c;let u=new a.EditorView(n,{state:c,editable:()=>!(0,e.unref)(y),dispatchTransaction(e){if(!u)return;let t=u.state.apply(e);if(u.updateState(t),A.value=t,e.docChanged){T?.incrementStateSeq(),F(t);try{if(O.value){let e=(0,s.fromProseDoc)(t.doc,O.value);O.value=e,x?.(e)}}catch(e){console.error(`[useDocxEditor] fromProseDoc error:`,e)}}T?.requestRender(),C?.()}});k.value=u,j.value=!0,F(c),T?.requestRender()}(0,e.watch)([()=>(0,e.unref)(E),()=>(0,e.unref)(D),k],([e,t,n])=>{n&&(0,l.setSuggestionMode)(e===`suggesting`,n.state,n.dispatch,t)},{immediate:!0});function L(){k.value&&=(k.value.destroy(),null),A.value=null,j.value=!1}let R={current:null},z=new Map,B=new Map;function V(){if(R.current&&R.current.isConnected)return R.current;let e=window.document.createElement(`div`);return e.dataset.hfHost=`true`,e.style.cssText=`position: fixed; left: -9999px; top: 0; opacity: 0; z-index: -1; pointer-events: none;`,window.document.body.appendChild(e),R.current=e,e}function H(e){let t=O.value?.package;if(!t)return null;if(t.headers){for(let[n,r]of t.headers)if(r===e)return n}if(t.footers){for(let[n,r]of t.footers)if(r===e)return n}return null}function U(e){let t=H(e);return t?z.get(t)??null:null}function W(){let e=O.value?.package,n=V(),o=new Set;if(e?.headers)for(let t of e.headers.keys())o.add(t);if(e?.footers)for(let t of e.footers.keys())o.add(t);for(let[e,t]of z)o.has(e)||(t.destroy(),t.dom.parentElement?.remove(),B.get(e)?.destroy(),B.delete(e),z.delete(e));if(!e)return;let s=e.styles??null,c=e.theme??null,l=e.settings?.defaultTabStop??null;for(let d of o){if(z.has(d))continue;let o=e.headers?.get(d)??e.footers?.get(d);if(!o)continue;let f=e.headers?.has(d)?`header`:`footer`,p=new u.ExtensionManager((0,u.createStarterKit)());p.buildSchema(),p.initializeRuntime(),B.set(d,p);let m=window.document.createElement(`div`);m.dataset.hfRId=d,m.dataset.hfKind=f,n.appendChild(m);let h=(0,r.headerFooterToProseDoc)(o.content,{styles:s??void 0,theme:c,defaultTabStopTwips:l}),g=t.EditorState.create({doc:h,schema:i.schema,plugins:p.getPlugins()}),_=f,v=new a.EditorView(m,{state:g,dispatchTransaction(e){let t=v.state.apply(e);if(v.updateState(t),e.docChanged){let e=O.value?.package,n=(_===`header`?e?.headers:e?.footers)?.get(d);n&&(n.content=(0,r.proseDocToBlocks)(t.doc))}e.docChanged&&A.value&&F(A.value),K.value?.(d,v,e.docChanged)}});z.set(d,v)}}function G(){for(let e of z.values())e.destroy(),e.dom.parentElement?.remove();z.clear();for(let e of B.values())e.destroy();B.clear(),R.current&&=(R.current.remove(),null)}let K={value:null};function q(e){K.value=e}async function J(e){M.value=null,j.value=!1;try{let t;t=e instanceof Blob||e instanceof File?await e.arrayBuffer():e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,O.value=await(0,o.parseDocx)(t),L(),G(),I(),W()}catch(e){let t=e instanceof Error?e:Error(String(e));M.value=t.message,S?.(t)}}function Y(e){M.value=null,O.value=e,L(),G(),I(),W()}async function X(){if(!k.value||!O.value)return null;let{repackDocx:e,createDocx:t}=await import(`@eigenpal/docx-editor-core/docx/rezip`),{injectReplyRangeMarkers:n,injectTCReplyRangeMarkers:r}=await import(`@eigenpal/docx-editor-core/docx`),i=(0,s.fromProseDoc)(k.value.state.doc,O.value),a=i.package.document?.comments??[];i.package.document?.content&&a.length>0&&(n(i.package.document.content,a),r(i.package.document.content,a));let o;return o=i.originalBuffer?await e(i):await t(i),new Blob([o],{type:`application/vnd.openxmlformats-officedocument.wordprocessingml.document`})}function Z(){k.value?.focus()}function Q(){L(),G(),O.value=null}function $(){return O.value}(0,e.onBeforeUnmount)(()=>{Q()});function ee(){return P.getCommands()}return{editorView:k,editorState:A,isReady:j,parseError:M,layout:N,loadBuffer:J,loadDocument:Y,save:X,focus:Z,destroy:Q,getDocument:$,getCommands:ee,reLayout(){k.value&&F(k.value.state)},getHfPmView:U,syncHfPMs:W,setHfTransactionListener:q,setDocument(e){O.value=e}}}var y=.25,b=4,x=.1,S=[.25,.5,.75,1,1.25,1.5,2,3,4];function C(t=1){let n=(0,e.ref)(Math.max(y,Math.min(b,t))),r=(0,e.computed)(()=>Math.round(n.value*100)),i=(0,e.computed)(()=>n.value<=y),a=(0,e.computed)(()=>n.value>=b);function o(e){n.value=Math.max(y,Math.min(b,Math.round(e*100)/100))}function s(){o(n.value+x)}function c(){o(n.value-x)}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:S}}var w=15,T=300,E=200,D=15;function O(){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?.classList?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),k(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),A(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),j(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>=T&&o>=T&&(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>=T&&(n.origWidth=a)}}function s(i){if(e.active){e.active=!1,e.handle?.classList.remove(`dragging`),r&&M(r,e),e.handle=null;return}if(t.active){t.active=!1,t.handle?.classList.remove(`dragging`),r&&N(r,t),t.handle=null;return}n.active&&(n.active=!1,n.handle?.classList.remove(`dragging`),r&&P(r,n),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 k(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let e=n.depth;e>=0;e--){let r=n.node(e);if(r.type.name===`table`){let e=r.attrs.columnWidths;e&&e[t.columnIndex]!==void 0&&e[t.columnIndex+1]!==void 0&&(t.origWidths={left:e[t.columnIndex],right:e[t.columnIndex+1]});return}}}function A(e,t,n){let r=e.state.doc.resolve(t.tablePmStart+1);for(let e=r.depth;e>=0;e--){let i=r.node(e);if(i.type.name===`table`){let e=null,r=0;if(i.forEach(n=>{r===t.rowIndex&&(e=n),r++}),e){let r=e.attrs.height;if(r)t.origHeight=r;else{let e=n.closest(`.layout-table`)?.querySelector(`[data-row-index="${t.rowIndex}"]`),r=e?e.getBoundingClientRect().height:30;t.origHeight=Math.round(r*D)}}return}}}function j(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let e=n.depth;e>=0;e--){let r=n.node(e);if(r.type.name===`table`){let e=r.attrs.columnWidths;e&&e[t.columnIndex]!==void 0&&(t.origWidth=e[t.columnIndex]);return}}}function M(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let r=n.depth;r>=0;r--){let i=n.node(r);if(i.type.name!==`table`)continue;let a=n.before(r),o=e.state.tr,s=[...i.attrs.columnWidths||[]];s[t.columnIndex]=t.origWidths.left,s[t.columnIndex+1]=t.origWidths.right,o.setNodeMarkup(a,void 0,{...i.attrs,columnWidths:s});let c=a+1;i.forEach(e=>{let n=c+1,r=0;e.forEach(e=>{let i=e.attrs.colspan||1;if(r===t.columnIndex||r===t.columnIndex+1){let i=r===t.columnIndex?t.origWidths.left:t.origWidths.right;o.setNodeMarkup(o.mapping.map(n),void 0,{...e.attrs,width:i,widthType:`dxa`,colwidth:null})}n+=e.nodeSize,r+=i}),c+=e.nodeSize}),e.dispatch(o);return}}function N(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let r=n.depth;r>=0;r--){let i=n.node(r);if(i.type.name!==`table`)continue;let a=n.before(r),o=e.state.tr,s=a+1,c=0;i.forEach(e=>{c===t.rowIndex&&o.setNodeMarkup(o.mapping.map(s),void 0,{...e.attrs,height:t.origHeight,heightRule:`atLeast`}),s+=e.nodeSize,c++}),e.dispatch(o);return}}function P(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let r=n.depth;r>=0;r--){let i=n.node(r);if(i.type.name!==`table`)continue;let a=n.before(r),o=e.state.tr,s=[...i.attrs.columnWidths||[]];s[t.columnIndex]=t.origWidth,o.setNodeMarkup(a,void 0,{...i.attrs,columnWidths:s});let c=a+1;i.forEach(e=>{let n=c+1,r=0;e.forEach(e=>{let i=e.attrs.colspan||1;r===t.columnIndex&&o.setNodeMarkup(o.mapping.map(n),void 0,{...e.attrs,width:t.origWidth,widthType:`dxa`,colwidth:null}),n+=e.nodeSize,r+=i}),c+=e.nodeSize}),e.dispatch(o);return}}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return O}});
|