@mdgate/office-common 0.4.1 → 0.5.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/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{relTargetBytes as o}from"@mdgate/containers";import{ConvertError as n}from"@mdgate/core";import{MAX_ASSET_TOTAL_BYTES as i}from"@mdgate/document";class T{assets=[];byPart=new Map;total=0;add(G,N,J){let K=this.byPart.get(N);if(K!==void 0)return K;if(this.total+=J.length,this.total>i)throw n.resourceLimit("max_asset_total_bytes","embedded assets exceed the retained-bytes cap");let $=this.assets.length;return this.byPart.set(N,$),this.assets.push({id:$,mediaType:G,originPart:N,bytes:J.slice()}),$}}function s(G,N,J,K,$){let Q=N.get($);if(Q===void 0)return;if(Q.mode==="external")return Q.target.length>0?{type:"external",url:Q.target}:void 0;let j=o(G,N,J,$);if(j===void 0)return;let[Z,U]=j;return{type:"asset",id:K.add(v(Z),Z,U)}}function v(G){let N=G.lastIndexOf(".");switch((N>=0?G.slice(N+1):"").toLowerCase()){case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"bmp":return"image/bmp";case"tif":case"tiff":return"image/tiff";case"svg":return"image/svg+xml";case"emf":return"image/emf";case"wmf":return"image/wmf";case"webp":return"image/webp";case"heic":case"heif":return"image/heic";default:return"application/octet-stream"}}import{inlinesAreEmpty as a,inlinesToPlainText as r}from"@mdgate/document";import{trim as k}from"@mdgate/utils";function t(G){let N=G.replace(/_20_/g," ");switch(k(N).toLowerCase()){case"quote":case"intense quote":case"block text":case"quotations":return"quote";case"html preformatted":case"source code":case"preformatted text":return"code";default:return}}class w{kind;quoteBlocks=[];codeLines=[];style(){return this.kind}push(G,N,J){if(this.kind!==G)this.flush(J),this.kind=G,this.quoteBlocks=[],this.codeLines=[];if(this.kind==="code")this.codeLines.push(r(N));else if(this.kind==="quote"){if(!a(N))this.quoteBlocks.push({type:"paragraph",inlines:N})}}flush(G){if(this.kind==="quote"){if(this.quoteBlocks.length>0)G.push({type:"blockQuote",blocks:this.quoteBlocks})}else if(this.kind==="code"){let N=-1,J=-1;for(let K=0;K<this.codeLines.length;K+=1)if(k(this.codeLines[K]).length>0){if(N<0)N=K;J=K}if(N>=0&&J>=0)G.push({type:"codeBlock",lang:void 0,text:this.codeLines.slice(N,J+1).join(`
2
- `)})}this.kind=void 0,this.quoteBlocks=[],this.codeLines=[]}}import{ConvertError as e}from"@mdgate/core";class m{raw=new Map;insert(G,N,J){this.raw.set(G,{def:N,parent:J})}definition(G){return this.raw.get(G)?.def}walk(G,N){let J=new Set,K=this.raw.has(G)?G:void 0;while(K!==void 0){if(J.has(K))throw e.malformed(`style inheritance cycle at ${JSON.stringify(K)}`);J.add(K);let $=this.raw.get(K),Q=N($.def);if(Q!==void 0)return Q;let j=$.parent;K=j!==void 0&&this.raw.has(j)?j:void 0}return}}import{PLAIN as NN}from"@mdgate/document";function GN(){return{bold:void 0,italic:void 0,strike:void 0,code:void 0}}function JN(G,N){return{bold:N.bold??G.bold,italic:N.italic??G.italic,strike:N.strike??G.strike,code:N.code??G.code}}function g(G,N){return{bold:G.bold??N.bold,italic:G.italic??N.italic,strike:G.strike??N.strike,code:G.code??N.code}}function KN(G){return g(G,NN)}function QN(G,N){return G.bold===N.bold&&G.italic===N.italic&&G.strike===N.strike&&G.code===N.code}function f(G,N){if(!N.bold&&!N.italic&&!N.strike&&!N.code)return;for(let J of G)if(J.type==="text")J.style.bold=J.style.bold&&!N.bold,J.style.italic=J.style.italic&&!N.italic,J.style.strike=J.style.strike&&!N.strike;else if(J.type==="link")f(J.content,N)}import{ns as _}from"@mdgate/containers";import{cellFromInlines as C,plain as S,tableFromRows as ZN}from"@mdgate/document";import{cleanText as R,trim as M}from"@mdgate/utils";function $N(G){let N=[],J=G.firstDescendant(_.CHART,"title"),K=J!==void 0?R(P(J)):"";if(M(K).length>0)N.push({type:"paragraph",inlines:[{type:"text",text:K,style:{bold:!0,italic:!1,strike:!1,code:!1}}]});let $=[],Q=[];for(let j of G.descendants(_.CHART,"ser")){let Z=j.find(_.CHART,"tx")?.firstDescendant(_.CHART,"v")!==void 0?R(j.find(_.CHART,"tx").firstDescendant(_.CHART,"v").text()):"",U=j.find(_.CHART,"cat"),F=U!==void 0?[...U.descendants(_.CHART,"v")].map((H)=>R(H.text())):[];if($.length===0)$=F;let W=j.find(_.CHART,"val"),q=W!==void 0?[...W.descendants(_.CHART,"v")].map((H)=>R(H.text())):[];Q.push({name:Z,values:q})}if(Q.length>0&&$.length>0){let Z=G.firstDescendant(_.CHART,"catAx")?.find(_.CHART,"title"),U=Z!==void 0?R(P(Z)):"",F=[C([S(U)])];for(let q of Q)F.push(C([S(q.name)]));let W=[F];for(let q=0;q<$.length;q+=1){let H=[C([S($[q])])];for(let X of Q)H.push(C([S(X.values[q]??"")]));W.push(H)}N.push({type:"table",table:ZN(W,1,"data")})}return N}function jN(G){let N=[];for(let J of G.descendants(_.DGM,"pt")){let K=J.find(_.DGM,"t");if(K===void 0)continue;let $=R(K.text());if(M($).length===0)continue;N.push({blocks:[{type:"paragraph",inlines:[S($)]}],checked:void 0,markerLabel:void 0})}if(N.length===0)return[];return[{type:"list",list:{marker:"bullet",start:1,items:N}}]}function P(G){let N=[];for(let J of G.descendants(_.A,"p")){let K=J.text();if(M(K).length>0)N.push(K)}return N.length===0?G.text():N.join(" ")}import{inlinesAreEmpty as HN}from"@mdgate/document";import{isAbsoluteUri as XN,isWhitespace as y}from"@mdgate/utils";function YN(){return{instr:"",inResult:!1,inlines:[]}}function UN(G,N){let J=h(G);if(J!==void 0&&!HN(N))return[{type:"link",content:N,target:J}];return N}function qN(G){let N=[],J=[...G],K=0;while(K<J.length){let $=J[K];if(y($))K+=1;else if($==='"'){K+=1;let Q="";while(K<J.length){let j=J[K];if(K+=1,j==='"')break;if(j==="\\"){let Z=J[K];if(Z==='"'||Z==="\\")Q+=Z,K+=1;else if(Z===void 0)break;else Q+="\\",Q+=Z,K+=1}else Q+=j}N.push({type:"word",word:Q})}else if($==="\\"){K+=1;let Q=J[K];if(Q!==void 0)K+=1,N.push({type:"switch",ch:Q.toLowerCase()})}else{let Q="";while(K<J.length){let j=J[K];if(y(j))break;Q+=j,K+=1}N.push({type:"word",word:Q})}}return N}function zN(G){return G==="l"||G==="o"||G==="t"}function h(G){let N=qN(G),J=0,K=N[J];if(J+=1,K===void 0||K.type!=="word"||K.word.toLowerCase()!=="hyperlink")return;let $,Q;while(J<N.length){let j=N[J];if(J+=1,j.type==="word"){if($===void 0&&j.word.trim().length>0)$=j.word.trim()}else{let Z;if(zN(j.ch)&&N[J]?.type==="word"){let U=N[J];if(J+=1,U.type==="word")Z=U.word}if(j.ch==="l"&&Z!==void 0&&Z.trim().length>0)Q=Z.trim()}}if($!==void 0&&Q!==void 0)return B(`${$}#${Q}`);if($!==void 0)return B($);if(Q!==void 0)return{type:"anchor",id:Q};return}function WN(G,N){return G?B(N):{type:"relative",url:N}}function B(G){if(G.startsWith("#"))return{type:"anchor",id:G.slice(1)};if(XN(G))return{type:"external",url:G};return{type:"relative",url:G}}import{cellSpanning as _N,GridBuilder as FN,resolveHeaderRows as VN}from"@mdgate/document";function DN(){return{mergeFirst:!1,mergeCont:!1,vmergeFirst:!1,vmergeCont:!1,right:0}}function RN(G){let J=SN(G,(H)=>H.header),K=G.map((H)=>{let X=Number.NEGATIVE_INFINITY;return H.cells.map(([z,Y])=>{let V={...Y};if(V.right<=X)V.right=X+1;return X=V.right,[z,V]})}),$=[];for(let H of K)for(let[,X]of H)$.push(X.right);$.sort((H,X)=>H-X);let Q=[];for(let H of $){let X=Q[Q.length-1];if(X===void 0||H-X>10)Q.push(H)}let j=(H)=>{let X=0,z=Q.length;while(X<z){let Y=X+z>>1;if(Q[Y]<H-10)X=Y+1;else z=Y}return X},Z=[];for(let H of K){let X=[],z=0,Y=0;while(Y<H.length){let[V,D]=H[Y];Y+=1;let L=V,I=D.right;if(D.mergeFirst)while(Y<H.length&&H[Y][1].mergeCont){let[d,l]=H[Y];Y+=1,L=L.concat(d),I=l.right}let x=Math.max(j(I)+1,z+1);X.push({blocks:L,colL:z,colR:x,rowSpan:1,vmergeFirst:D.vmergeFirst,covered:D.vmergeCont}),z=x}Z.push(X)}let U=(H,X)=>`${H},${X}`,F=new Map;for(let H=0;H<Z.length;H+=1){let X=new Map;for(let z=0;z<Z[H].length;z+=1){let Y=Z[H][z],V=U(Y.colL,Y.colR);if(Y.covered){let D=F.get(V);if(D!==void 0){Z[D[0]][D[1]].rowSpan+=1,X.set(V,D);continue}Y.covered=!1}if(Y.vmergeFirst)X.set(V,[H,z])}F=X}let W=new FN;for(let H of Z){W.nextRow();for(let X of H){let z=X.colR-X.colL;if(X.covered)for(let Y=0;Y<z;Y+=1)W.covered();else W.place(_N(X.blocks,z,X.rowSpan))}}let q=W.finish("data");if(q.grid.length===0)return;return q.headerRows=VN(q,J),{type:"table",table:q}}function SN(G,N){let J=0;for(let K of G){if(!N(K))break;J+=1}return J}import{markerIsOrdered as p}from"@mdgate/document";function b(G,N){return G.instance===N.instance&&G.marker===N.marker}function CN(G,N){let J=N.splice(0,N.length);if(J.length===0)return;G.push(...u(J))}function u(G){if(G.length===0)return[];let N=G[0].level;for(let j of G)if(j.level<N)N=j.level;let J=[],K,$=()=>{if(K!==void 0&&K.list.items.length>0)J.push({type:"list",list:K.list});K=void 0},Q=0;while(Q<G.length)if(G[Q].level<=N){let Z=G[Q];if(Q+=1,K===void 0||!b(K.key,Z.key)||p(Z.key.marker)&&K.lastNumber+1!==Z.number)$(),K={list:{marker:Z.key.marker,start:p(Z.key.marker)?Z.number:1,items:[]},key:Z.key,lastNumber:Z.number};K.list.items.push({blocks:Z.blocks,checked:void 0,markerLabel:Z.label}),K.lastNumber=Z.number}else{let Z=[];while(Q<G.length&&G[Q].level>N)Z.push(G[Q]),Q+=1;let U=u(Z);if(U.length===0)continue;if(K===void 0)K={list:{marker:"bullet",start:1,items:[]},key:{instance:Number.MAX_SAFE_INTEGER,marker:"bullet"},lastNumber:0};if(K.list.items.length===0)K.list.items.push({blocks:[],checked:void 0,markerLabel:void 0});K.list.items[K.list.items.length-1].blocks.push(...U)}return $(),J}import{ns as O}from"@mdgate/containers";function LN(G,N){for(let J of G.findAll(O.MC,"Choice"))if(PN(J,N))return J;return G.find(O.MC,"Fallback")}function PN(G,N){let J=G.attr(O.MC,"Requires");if(J===void 0)return!0;for(let K of J.split(/\s+/)){if(K.length===0)continue;if(!N.includes(K))return!1}return!0}import{markerLabel as MN,markerOrdinal as BN}from"@mdgate/document";function ON(){return{text:[],legal:!1}}function EN(G){let N=[],J=[...G];for(let K=0;K<J.length;K+=1){let $=J[K];if($==="%"){let j=J[K+1],Z=j!==void 0?j.charCodeAt(0)-48:-1;if(Z>=1&&Z<=9){K+=1,N.push({type:"level",level:Z-1});continue}}let Q=N[N.length-1];if(Q?.type==="literal")Q.text+=$;else N.push({type:"literal",text:$})}return N}function AN(G,N,J,K,$){if(G.text.length===0)return;let Q="";for(let j of G.text)if(j.type==="literal")Q+=j.text;else{let Z=G.legal?"decimal":K(j.level);Q+=BN(Z,$(j.level))}return Q===MN(N,J)?void 0:Q}import{inflateRaw as IN}from"@mdgate/utils";function E(G,N){if(N<0||N+8>G.length)return;let J=G[N]|G[N+1]<<8,K=G[N+2]|G[N+3]<<8,$=(G[N+4]|G[N+5]<<8|G[N+6]<<16|G[N+7]<<24)>>>0;if(N+8+$>G.length)return;return[J,K,G.subarray(N+8,N+8+$)]}function A(G,N,J,K){let $=G>>>4;if(N===61469||N===61470){let j=($===1131||$===1763||$===1761?32:16)+1;if(j>J.length)return;let Z=J.subarray(j);return N===61469?{mediaType:"image/jpeg",extension:"jpg",bytes:Z}:{mediaType:"image/png",extension:"png",bytes:Z}}if(N===61466||N===61467){let j=$===981||$===535?32:16;if(j+34>J.length)return;let Z=J.subarray(j),U=(Z[0]|Z[1]<<8|Z[2]<<16|Z[3]<<24)>>>0,F=Z[32],W=Z.subarray(34),q=N===61466?{mediaType:"image/emf",extension:"emf"}:{mediaType:"image/wmf",extension:"wmf"};if(F===0){let H=Math.min(U,K),X=vN(W,H);if(X===void 0)return;return{...q,bytes:X}}return{...q,bytes:W}}return}function xN(G,N){let J=[[0,G.length]],K=0;for(;;){let $=J[J.length-1];if($===void 0)return;let[Q,j]=$;if(Q>=j){J.pop();continue}let Z=E(G.subarray(0,j),Q);if(Z===void 0){J.pop();continue}let[U,F,W]=Z,q=Q+8,H=q+W.length;if($[0]=H,K+=1,K>1e4||J.length>16)return;let X=A(U,F,W,N);if(X!==void 0)return X;if(F===61447){let z=q+(c(W)??W.length);if(z<H)J.push([z,H]);continue}if((U&15)===15)J.push([q,H])}}function c(G){if(G.length<=33)return;return 36+G[33]}function TN(G,N){let J=c(G);if(J===void 0)return;let K=E(G,J);if(K===void 0)return;return A(K[0],K[1],K[2],N)}function vN(G,N){try{return IN(G,N)}catch{return}}export{KN as resolveDelta,s as relImageSource,E as recordAt,f as rebaseEmphasis,EN as parsePercentPattern,JN as mergeDelta,v as mediaTypeFor,b as listKeysEqual,h as hyperlinkTarget,t as fromStyleName,CN as flushList,xN as firstBlip,UN as fieldResult,TN as fbseBlip,ON as emptyNumberPattern,YN as emptyFieldFrame,GN as emptyDelta,DN as emptyCellProp,P as drawingText,jN as diagramBlocks,QN as deltasEqual,A as decodeBlip,AN as compositeLabel,WN as classifyRelTarget,$N as chartBlocks,RN as buildEdgeTable,g as applyDelta,LN as alternateBranch,w as StyledRun,m as StyleChains,T as AssetSink};
1
+ import{relTargetBytes as o}from"@mdgate/containers";class T{assets=[];byPart=new Map;total=0;add(G,N,J){let K=this.byPart.get(N);if(K!==void 0)return K;this.total+=J.length;let Y=this.assets.length;return this.byPart.set(N,Y),this.assets.push({id:Y,mediaType:G,originPart:N,bytes:J.slice()}),Y}}function n(G,N,J,K,Y){let X=N.get(Y);if(X===void 0)return;if(X.mode==="external")return X.target.length>0?{type:"external",url:X.target}:void 0;let Z=o(G,N,J,Y);if(Z===void 0)return;let[Q,U]=Z;return{type:"asset",id:K.add(v(Q),Q,U)}}function v(G){let N=G.lastIndexOf(".");switch((N>=0?G.slice(N+1):"").toLowerCase()){case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"bmp":return"image/bmp";case"tif":case"tiff":return"image/tiff";case"svg":return"image/svg+xml";case"emf":return"image/emf";case"wmf":return"image/wmf";case"webp":return"image/webp";case"heic":case"heif":return"image/heic";default:return"application/octet-stream"}}import{inlinesAreEmpty as i,inlinesToPlainText as s}from"@mdgate/document";import{trim as k}from"@mdgate/utils";function a(G){let N=G.replace(/_20_/g," ");switch(k(N).toLowerCase()){case"quote":case"intense quote":case"block text":case"quotations":return"quote";case"html preformatted":case"source code":case"preformatted text":return"code";default:return}}class w{kind;quoteBlocks=[];codeLines=[];style(){return this.kind}push(G,N,J){if(this.kind!==G)this.flush(J),this.kind=G,this.quoteBlocks=[],this.codeLines=[];if(this.kind==="code")this.codeLines.push(s(N));else if(this.kind==="quote"){if(!i(N))this.quoteBlocks.push({type:"paragraph",inlines:N})}}flush(G){if(this.kind==="quote"){if(this.quoteBlocks.length>0)G.push({type:"blockQuote",blocks:this.quoteBlocks})}else if(this.kind==="code"){let N=-1,J=-1;for(let K=0;K<this.codeLines.length;K+=1)if(k(this.codeLines[K]).length>0){if(N<0)N=K;J=K}if(N>=0&&J>=0)G.push({type:"codeBlock",lang:void 0,text:this.codeLines.slice(N,J+1).join(`
2
+ `)})}this.kind=void 0,this.quoteBlocks=[],this.codeLines=[]}}import{ConvertError as r}from"@mdgate/core";class m{raw=new Map;insert(G,N,J){this.raw.set(G,{def:N,parent:J})}definition(G){return this.raw.get(G)?.def}walk(G,N){let J=new Set,K=this.raw.has(G)?G:void 0;while(K!==void 0){if(J.has(K))throw r.malformed(`style inheritance cycle at ${JSON.stringify(K)}`);J.add(K);let Y=this.raw.get(K),X=N(Y.def);if(X!==void 0)return X;let Z=Y.parent;K=Z!==void 0&&this.raw.has(Z)?Z:void 0}return}}import{PLAIN as t}from"@mdgate/document";function e(){return{bold:void 0,italic:void 0,strike:void 0,code:void 0}}function NN(G,N){return{bold:N.bold??G.bold,italic:N.italic??G.italic,strike:N.strike??G.strike,code:N.code??G.code}}function g(G,N){return{bold:G.bold??N.bold,italic:G.italic??N.italic,strike:G.strike??N.strike,code:G.code??N.code}}function GN(G){return g(G,t)}function JN(G,N){return G.bold===N.bold&&G.italic===N.italic&&G.strike===N.strike&&G.code===N.code}function f(G,N){if(!N.bold&&!N.italic&&!N.strike&&!N.code)return;for(let J of G)if(J.type==="text")J.style.bold=J.style.bold&&!N.bold,J.style.italic=J.style.italic&&!N.italic,J.style.strike=J.style.strike&&!N.strike;else if(J.type==="link")f(J.content,N)}import{ns as W}from"@mdgate/containers";import{cellFromInlines as C,plain as R,tableFromRows as KN}from"@mdgate/document";import{cleanText as D,trim as P}from"@mdgate/utils";function QN(G){let N=[],J=G.firstDescendant(W.CHART,"title"),K=J!==void 0?D(M(J)):"";if(P(K).length>0)N.push({type:"paragraph",inlines:[{type:"text",text:K,style:{bold:!0,italic:!1,strike:!1,code:!1}}]});let Y=[],X=[];for(let Z of G.descendants(W.CHART,"ser")){let Q=Z.find(W.CHART,"tx")?.firstDescendant(W.CHART,"v")!==void 0?D(Z.find(W.CHART,"tx").firstDescendant(W.CHART,"v").text()):"",U=Z.find(W.CHART,"cat"),S=U!==void 0?[...U.descendants(W.CHART,"v")].map((_)=>D(_.text())):[];if(Y.length===0)Y=S;let q=Z.find(W.CHART,"val"),H=q!==void 0?[...q.descendants(W.CHART,"v")].map((_)=>D(_.text())):[];X.push({name:Q,values:H})}if(X.length>0&&Y.length>0){let Q=G.firstDescendant(W.CHART,"catAx")?.find(W.CHART,"title"),U=Q!==void 0?D(M(Q)):"",S=[C([R(U)])];for(let H of X)S.push(C([R(H.name)]));let q=[S];for(let H=0;H<Y.length;H+=1){let _=[C([R(Y[H])])];for(let $ of X)_.push(C([R($.values[H]??"")]));q.push(_)}N.push({type:"table",table:KN(q,1,"data")})}return N}function XN(G){let N=[];for(let J of G.descendants(W.DGM,"pt")){let K=J.find(W.DGM,"t");if(K===void 0)continue;let Y=D(K.text());if(P(Y).length===0)continue;N.push({blocks:[{type:"paragraph",inlines:[R(Y)]}],checked:void 0,markerLabel:void 0})}if(N.length===0)return[];return[{type:"list",list:{marker:"bullet",start:1,items:N}}]}function M(G){let N=[];for(let J of G.descendants(W.A,"p")){let K=J.text();if(P(K).length>0)N.push(K)}return N.length===0?G.text():N.join(" ")}import{inlinesAreEmpty as YN}from"@mdgate/document";import{isAbsoluteUri as ZN,isWhitespace as y}from"@mdgate/utils";function _N(){return{instr:"",inResult:!1,inlines:[]}}function $N(G,N){let J=h(G);if(J!==void 0&&!YN(N))return[{type:"link",content:N,target:J}];return N}function jN(G){let N=[],J=[...G],K=0;while(K<J.length){let Y=J[K];if(y(Y))K+=1;else if(Y==='"'){K+=1;let X="";while(K<J.length){let Z=J[K];if(K+=1,Z==='"')break;if(Z==="\\"){let Q=J[K];if(Q==='"'||Q==="\\")X+=Q,K+=1;else if(Q===void 0)break;else X+="\\",X+=Q,K+=1}else X+=Z}N.push({type:"word",word:X})}else if(Y==="\\"){K+=1;let X=J[K];if(X!==void 0)K+=1,N.push({type:"switch",ch:X.toLowerCase()})}else{let X="";while(K<J.length){let Z=J[K];if(y(Z))break;X+=Z,K+=1}N.push({type:"word",word:X})}}return N}function HN(G){return G==="l"||G==="o"||G==="t"}function h(G){let N=jN(G),J=0,K=N[J];if(J+=1,K===void 0||K.type!=="word"||K.word.toLowerCase()!=="hyperlink")return;let Y,X;while(J<N.length){let Z=N[J];if(J+=1,Z.type==="word"){if(Y===void 0&&Z.word.trim().length>0)Y=Z.word.trim()}else{let Q;if(HN(Z.ch)&&N[J]?.type==="word"){let U=N[J];if(J+=1,U.type==="word")Q=U.word}if(Z.ch==="l"&&Q!==void 0&&Q.trim().length>0)X=Q.trim()}}if(Y!==void 0&&X!==void 0)return B(`${Y}#${X}`);if(Y!==void 0)return B(Y);if(X!==void 0)return{type:"anchor",id:X};return}function UN(G,N){return G?B(N):{type:"relative",url:N}}function B(G){if(G.startsWith("#"))return{type:"anchor",id:G.slice(1)};if(ZN(G))return{type:"external",url:G};return{type:"relative",url:G}}import{cellSpanning as qN,GridBuilder as zN,resolveHeaderRows as SN}from"@mdgate/document";function WN(){return{mergeFirst:!1,mergeCont:!1,vmergeFirst:!1,vmergeCont:!1,right:0}}function FN(G){let J=VN(G,(_)=>_.header),K=G.map((_)=>{let $=Number.NEGATIVE_INFINITY;return _.cells.map(([z,j])=>{let F={...j};if(F.right<=$)F.right=$+1;return $=F.right,[z,F]})}),Y=[];for(let _ of K)for(let[,$]of _)Y.push($.right);Y.sort((_,$)=>_-$);let X=[];for(let _ of Y){let $=X[X.length-1];if($===void 0||_-$>10)X.push(_)}let Z=(_)=>{let $=0,z=X.length;while($<z){let j=$+z>>1;if(X[j]<_-10)$=j+1;else z=j}return $},Q=[];for(let _ of K){let $=[],z=0,j=0;while(j<_.length){let[F,V]=_[j];j+=1;let L=F,I=V.right;if(V.mergeFirst)while(j<_.length&&_[j][1].mergeCont){let[d,l]=_[j];j+=1,L=L.concat(d),I=l.right}let x=Math.max(Z(I)+1,z+1);$.push({blocks:L,colL:z,colR:x,rowSpan:1,vmergeFirst:V.vmergeFirst,covered:V.vmergeCont}),z=x}Q.push($)}let U=(_,$)=>`${_},${$}`,S=new Map;for(let _=0;_<Q.length;_+=1){let $=new Map;for(let z=0;z<Q[_].length;z+=1){let j=Q[_][z],F=U(j.colL,j.colR);if(j.covered){let V=S.get(F);if(V!==void 0){Q[V[0]][V[1]].rowSpan+=1,$.set(F,V);continue}j.covered=!1}if(j.vmergeFirst)$.set(F,[_,z])}S=$}let q=new zN;for(let _ of Q){q.nextRow();for(let $ of _){let z=$.colR-$.colL;if($.covered)for(let j=0;j<z;j+=1)q.covered();else q.place(qN($.blocks,z,$.rowSpan))}}let H=q.finish("data");if(H.grid.length===0)return;return H.headerRows=SN(H,J),{type:"table",table:H}}function VN(G,N){let J=0;for(let K of G){if(!N(K))break;J+=1}return J}import{markerIsOrdered as p}from"@mdgate/document";function b(G,N){return G.instance===N.instance&&G.marker===N.marker}function DN(G,N){let J=N.splice(0,N.length);if(J.length===0)return;G.push(...u(J))}function u(G){if(G.length===0)return[];let N=G[0].level;for(let Z of G)if(Z.level<N)N=Z.level;let J=[],K,Y=()=>{if(K!==void 0&&K.list.items.length>0)J.push({type:"list",list:K.list});K=void 0},X=0;while(X<G.length)if(G[X].level<=N){let Q=G[X];if(X+=1,K===void 0||!b(K.key,Q.key)||p(Q.key.marker)&&K.lastNumber+1!==Q.number)Y(),K={list:{marker:Q.key.marker,start:p(Q.key.marker)?Q.number:1,items:[]},key:Q.key,lastNumber:Q.number};K.list.items.push({blocks:Q.blocks,checked:void 0,markerLabel:Q.label}),K.lastNumber=Q.number}else{let Q=[];while(X<G.length&&G[X].level>N)Q.push(G[X]),X+=1;let U=u(Q);if(U.length===0)continue;if(K===void 0)K={list:{marker:"bullet",start:1,items:[]},key:{instance:Number.MAX_SAFE_INTEGER,marker:"bullet"},lastNumber:0};if(K.list.items.length===0)K.list.items.push({blocks:[],checked:void 0,markerLabel:void 0});K.list.items[K.list.items.length-1].blocks.push(...U)}return Y(),J}import{ns as O}from"@mdgate/containers";function RN(G,N){for(let J of G.findAll(O.MC,"Choice"))if(CN(J,N))return J;return G.find(O.MC,"Fallback")}function CN(G,N){let J=G.attr(O.MC,"Requires");if(J===void 0)return!0;for(let K of J.split(/\s+/)){if(K.length===0)continue;if(!N.includes(K))return!1}return!0}import{markerLabel as LN,markerOrdinal as MN}from"@mdgate/document";function PN(){return{text:[],legal:!1}}function BN(G){let N=[],J=[...G];for(let K=0;K<J.length;K+=1){let Y=J[K];if(Y==="%"){let Z=J[K+1],Q=Z!==void 0?Z.charCodeAt(0)-48:-1;if(Q>=1&&Q<=9){K+=1,N.push({type:"level",level:Q-1});continue}}let X=N[N.length-1];if(X?.type==="literal")X.text+=Y;else N.push({type:"literal",text:Y})}return N}function ON(G,N,J,K,Y){if(G.text.length===0)return;let X="";for(let Z of G.text)if(Z.type==="literal")X+=Z.text;else{let Q=G.legal?"decimal":K(Z.level);X+=MN(Q,Y(Z.level))}return X===LN(N,J)?void 0:X}import{inflateRaw as EN}from"@mdgate/utils";function E(G,N){if(N<0||N+8>G.length)return;let J=G[N]|G[N+1]<<8,K=G[N+2]|G[N+3]<<8,Y=(G[N+4]|G[N+5]<<8|G[N+6]<<16|G[N+7]<<24)>>>0;if(N+8+Y>G.length)return;return[J,K,G.subarray(N+8,N+8+Y)]}function A(G,N,J,K=Number.MAX_SAFE_INTEGER){let Y=G>>>4;if(N===61469||N===61470){let Z=(Y===1131||Y===1763||Y===1761?32:16)+1;if(Z>J.length)return;let Q=J.subarray(Z);return N===61469?{mediaType:"image/jpeg",extension:"jpg",bytes:Q}:{mediaType:"image/png",extension:"png",bytes:Q}}if(N===61466||N===61467){let Z=Y===981||Y===535?32:16;if(Z+34>J.length)return;let Q=J.subarray(Z),U=(Q[0]|Q[1]<<8|Q[2]<<16|Q[3]<<24)>>>0,S=Q[32],q=Q.subarray(34),H=N===61466?{mediaType:"image/emf",extension:"emf"}:{mediaType:"image/wmf",extension:"wmf"};if(S===0){let _=Math.min(U,K),$=xN(q,_);if($===void 0)return;return{...H,bytes:$}}return{...H,bytes:q}}return}function AN(G,N=Number.MAX_SAFE_INTEGER){let J=[[0,G.length]];for(;;){let K=J[J.length-1];if(K===void 0)return;let[Y,X]=K;if(Y>=X){J.pop();continue}let Z=E(G.subarray(0,X),Y);if(Z===void 0){J.pop();continue}let[Q,U,S]=Z,q=Y+8,H=q+S.length;K[0]=H;let _=A(Q,U,S,N);if(_!==void 0)return _;if(U===61447){let $=q+(c(S)??S.length);if($<H)J.push([$,H]);continue}if((Q&15)===15)J.push([q,H])}}function c(G){if(G.length<=33)return;return 36+G[33]}function IN(G,N=Number.MAX_SAFE_INTEGER){let J=c(G);if(J===void 0)return;let K=E(G,J);if(K===void 0)return;return A(K[0],K[1],K[2],N)}function xN(G,N){try{return EN(G,N)}catch{return}}export{GN as resolveDelta,n as relImageSource,E as recordAt,f as rebaseEmphasis,BN as parsePercentPattern,NN as mergeDelta,v as mediaTypeFor,b as listKeysEqual,h as hyperlinkTarget,a as fromStyleName,DN as flushList,AN as firstBlip,$N as fieldResult,IN as fbseBlip,PN as emptyNumberPattern,_N as emptyFieldFrame,e as emptyDelta,WN as emptyCellProp,M as drawingText,XN as diagramBlocks,JN as deltasEqual,A as decodeBlip,ON as compositeLabel,UN as classifyRelTarget,QN as chartBlocks,FN as buildEdgeTable,g as applyDelta,RN as alternateBranch,w as StyledRun,m as StyleChains,T as AssetSink};
@@ -6,11 +6,11 @@ export interface Blip {
6
6
  bytes: Uint8Array;
7
7
  }
8
8
  /** Decode one blip record (`recType` 0xF01A–0xF01F). */
9
- export declare function decodeBlip(verInst: number, recType: number, body: Uint8Array, maxBytes: number): Blip | undefined;
9
+ export declare function decodeBlip(verInst: number, recType: number, body: Uint8Array, maxBytes?: number): Blip | undefined;
10
10
  /**
11
11
  * Find and decode the first blip in a run of OfficeArt records, descending
12
12
  * into containers.
13
13
  */
14
- export declare function firstBlip(data: Uint8Array, maxBytes: number): Blip | undefined;
14
+ export declare function firstBlip(data: Uint8Array, maxBytes?: number): Blip | undefined;
15
15
  /** Decode the blip embedded in an FBSE (0xF007) record body, if present. */
16
- export declare function fbseBlip(body: Uint8Array, maxBytes: number): Blip | undefined;
16
+ export declare function fbseBlip(body: Uint8Array, maxBytes?: number): Blip | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdgate/office-common",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "mdgate shared office-format semantics: fields, numbering, styles, DrawingML",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -22,10 +22,10 @@
22
22
  "prepublishOnly": "bun run build"
23
23
  },
24
24
  "dependencies": {
25
- "@mdgate/containers": "0.4.1",
26
- "@mdgate/core": "0.4.1",
27
- "@mdgate/document": "0.4.1",
28
- "@mdgate/utils": "0.4.1"
25
+ "@mdgate/containers": "0.5.1",
26
+ "@mdgate/core": "0.5.1",
27
+ "@mdgate/document": "0.5.1",
28
+ "@mdgate/utils": "0.5.1"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"