@mdgate/office-common 0.1.0 → 0.4.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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +5 -5
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";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(`
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
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdgate/office-common",
3
- "version": "0.1.0",
3
+ "version": "0.4.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.1.0",
26
- "@mdgate/core": "0.1.3",
27
- "@mdgate/document": "0.1.0",
28
- "@mdgate/utils": "0.1.2"
25
+ "@mdgate/containers": "0.4.1",
26
+ "@mdgate/core": "0.4.1",
27
+ "@mdgate/document": "0.4.1",
28
+ "@mdgate/utils": "0.4.1"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"