@mdgate/office-common 0.5.0 → 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 +2 -2
- package/dist/officeart.d.ts +3 -3
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{relTargetBytes as o}from"@mdgate/containers";
|
|
2
|
-
`)})}this.kind=void 0,this.quoteBlocks=[],this.codeLines=[]}}import{ConvertError as
|
|
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};
|
package/dist/officeart.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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.5.
|
|
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.5.
|
|
26
|
-
"@mdgate/core": "0.5.
|
|
27
|
-
"@mdgate/document": "0.5.
|
|
28
|
-
"@mdgate/utils": "0.5.
|
|
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"
|