@mdgate/office-common 0.1.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.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @mdgate/office-common
2
+
3
+ Semantics shared by the office-format converters: Word field codes, list numbering, style deltas, border-grid tables, DrawingML and OfficeArt graphics.
4
+
5
+ Internal shared library for the mdgate converters. Install a converter
6
+ package (for example `@mdgate/docx`) or the `@mdgate/converters` bundle
7
+ instead of depending on this directly.
@@ -0,0 +1,16 @@
1
+ import type { Package } from '@mdgate/containers';
2
+ import { type Relationships } from '@mdgate/containers';
3
+ import type { Asset, AssetId, ImageSource } from '@mdgate/document';
4
+ export declare class AssetSink {
5
+ assets: Asset[];
6
+ private readonly byPart;
7
+ total: number;
8
+ add(mediaType: string, originPart: string, bytes: Uint8Array): AssetId;
9
+ }
10
+ /**
11
+ * Resolve an image relationship to its source. Failures degrade to
12
+ * `undefined`; fatal errors propagate.
13
+ */
14
+ export declare function relImageSource(pkg: Package, rels: Relationships, basePart: string, assets: AssetSink, relId: string): ImageSource | undefined;
15
+ /** MIME type from a part path's extension. */
16
+ export declare function mediaTypeFor(part: string): string;
@@ -0,0 +1,14 @@
1
+ import { type Block, type Inline } from '@mdgate/document';
2
+ /** The block container a paragraph style designates. */
3
+ export type BlockStyle = 'quote' | 'code';
4
+ /** The container a paragraph style name designates. ODF encodes spaces as `_20_`. */
5
+ export declare function fromStyleName(name: string): BlockStyle | undefined;
6
+ /** Consecutive paragraphs sharing one styled container. */
7
+ export declare class StyledRun {
8
+ private kind;
9
+ private quoteBlocks;
10
+ private codeLines;
11
+ style(): BlockStyle | undefined;
12
+ push(style: BlockStyle, inlines: Inline[], out: Block[]): void;
13
+ flush(out: Block[]): void;
14
+ }
@@ -0,0 +1,10 @@
1
+ /** Style id -> (definition, parent style id). */
2
+ export declare class StyleChains<D> {
3
+ private readonly raw;
4
+ insert(id: string, def: D, parent: string | undefined): void;
5
+ definition(id: string): D | undefined;
6
+ /**
7
+ * Walk a chain child-to-root. Unknown ids end the walk; a cycle hard-fails.
8
+ */
9
+ walk<T>(id: string, visit: (def: D) => T | undefined): T | undefined;
10
+ }
@@ -0,0 +1,20 @@
1
+ import { type Inline, type Style } from '@mdgate/document';
2
+ /** Tri-state style delta used during cascade resolution. */
3
+ export interface StyleDelta {
4
+ bold: boolean | undefined;
5
+ italic: boolean | undefined;
6
+ strike: boolean | undefined;
7
+ code: boolean | undefined;
8
+ }
9
+ export declare function emptyDelta(): StyleDelta;
10
+ /** Overlay `child` on `base`: an explicit child value wins; unset inherits. */
11
+ export declare function mergeDelta(base: StyleDelta, child: StyleDelta): StyleDelta;
12
+ export declare function applyDelta(delta: StyleDelta, base: Style): Style;
13
+ export declare function resolveDelta(delta: StyleDelta): Style;
14
+ export declare function deltasEqual(a: StyleDelta, b: StyleDelta): boolean;
15
+ /**
16
+ * Drop from every run the emphasis `base` already carries. A heading style
17
+ * defines its own typography, so its runs should carry only what they add
18
+ * beyond it.
19
+ */
20
+ export declare function rebaseEmphasis(inlines: Inline[], base: Style): void;
@@ -0,0 +1,8 @@
1
+ import { type Element } from '@mdgate/containers';
2
+ import { type Block } from '@mdgate/document';
3
+ /** A chart part as blocks: bold title paragraph plus a categories × series table. */
4
+ export declare function chartBlocks(root: Element): Block[];
5
+ /** A SmartArt data part as a bullet list of its text points in order. */
6
+ export declare function diagramBlocks(root: Element): Block[];
7
+ /** Text runs inside DrawingML rich text (`a:p`/`a:r`/`a:t`), joined. */
8
+ export declare function drawingText(elem: Element): string;
@@ -0,0 +1,14 @@
1
+ import { type Inline, type LinkTarget } from '@mdgate/document';
2
+ /** Field accumulator: instruction text before the separator, result after. */
3
+ export interface FieldFrame {
4
+ instr: string;
5
+ inResult: boolean;
6
+ inlines: Inline[];
7
+ }
8
+ export declare function emptyFieldFrame(): FieldFrame;
9
+ /** Finish a field: wrap the result in a link when the instruction is a hyperlink. */
10
+ export declare function fieldResult(instr: string, content: Inline[]): Inline[];
11
+ /** Interpret a HYPERLINK field instruction as a link target. */
12
+ export declare function hyperlinkTarget(instr: string): LinkTarget | undefined;
13
+ /** Classify an OPC relationship target as a link target. */
14
+ export declare function classifyRelTarget(external: boolean, target: string): LinkTarget;
package/dist/grid.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { type Block, type Cell } from '@mdgate/document';
2
+ /** Merge/boundary properties of one cell. */
3
+ export interface CellProp {
4
+ mergeFirst: boolean;
5
+ mergeCont: boolean;
6
+ vmergeFirst: boolean;
7
+ vmergeCont: boolean;
8
+ /** Right boundary in twips. */
9
+ right: number;
10
+ }
11
+ export declare function emptyCellProp(): CellProp;
12
+ /** One logical row: its cells with their properties, and whether it is a header. */
13
+ export interface GridRow {
14
+ cells: Array<[Block[], CellProp]>;
15
+ header: boolean;
16
+ }
17
+ /** Assemble logical rows into the canonical grid. */
18
+ export declare function buildEdgeTable(rowsIn: GridRow[]): Block | undefined;
19
+ export type { Cell };
@@ -0,0 +1,11 @@
1
+ export { AssetSink, mediaTypeFor, relImageSource } from './assets.js';
2
+ export { type BlockStyle, fromStyleName, StyledRun } from './blockstyle.js';
3
+ export { StyleChains } from './chain.js';
4
+ export { applyDelta, deltasEqual, emptyDelta, mergeDelta, rebaseEmphasis, resolveDelta, type StyleDelta, } from './delta.js';
5
+ export { chartBlocks, diagramBlocks, drawingText } from './drawingml.js';
6
+ export { classifyRelTarget, emptyFieldFrame, type FieldFrame, fieldResult, hyperlinkTarget, } from './fields.js';
7
+ export { buildEdgeTable, type CellProp, emptyCellProp, type GridRow, } from './grid.js';
8
+ export { flushList, type ListEntry, type ListKey, listKeysEqual, } from './list.js';
9
+ export { alternateBranch } from './mc.js';
10
+ export { compositeLabel, emptyNumberPattern, type NumberPattern, type NumberText, parsePercentPattern, } from './numbering.js';
11
+ export { type Blip, decodeBlip, fbseBlip, firstBlip, recordAt } from './officeart.js';
package/dist/index.js ADDED
@@ -0,0 +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(`
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/dist/list.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { type Block, type MarkerKind } from '@mdgate/document';
2
+ export type { MarkerKind };
3
+ /** Identity of a resolved list at one level. */
4
+ export interface ListKey {
5
+ instance: number;
6
+ marker: MarkerKind;
7
+ }
8
+ export declare function listKeysEqual(a: ListKey, b: ListKey): boolean;
9
+ /** One flat, fully resolved list paragraph. */
10
+ export interface ListEntry {
11
+ level: number;
12
+ key: ListKey;
13
+ /** Effective item number at this entry (ignored for bullets). */
14
+ number: number;
15
+ label: string | undefined;
16
+ blocks: Block[];
17
+ }
18
+ /** Pop the accumulated run of list paragraphs into list blocks. */
19
+ export declare function flushList(blocks: Block[], run: ListEntry[]): void;
package/dist/mc.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { type Element } from '@mdgate/containers';
2
+ /**
3
+ * Pick the branch of an `mc:AlternateContent`: the first `mc:Choice` whose
4
+ * `Requires` namespaces are all supported, else the `mc:Fallback`.
5
+ */
6
+ export declare function alternateBranch(alt: Element, supported: readonly string[]): Element | undefined;
@@ -0,0 +1,22 @@
1
+ import { type MarkerKind } from '@mdgate/document';
2
+ /** One piece of a level's number text. */
3
+ export type NumberText = {
4
+ type: 'literal';
5
+ text: string;
6
+ } | {
7
+ type: 'level';
8
+ level: number;
9
+ };
10
+ /** A level's resolved number pattern. */
11
+ export interface NumberPattern {
12
+ text: NumberText[];
13
+ legal: boolean;
14
+ }
15
+ export declare function emptyNumberPattern(): NumberPattern;
16
+ /** Parse WordprocessingML-style percent patterns (`%1`–`%9`). */
17
+ export declare function parsePercentPattern(text: string): NumberText[];
18
+ /**
19
+ * Render a pattern against the current sequence values. `undefined` when the
20
+ * result matches the default label produced from the own level's marker and value.
21
+ */
22
+ export declare function compositeLabel(pattern: NumberPattern, ownMarker: MarkerKind, ownValue: number, levelMarker: (level: number) => MarkerKind, levelValue: (level: number) => number): string | undefined;
@@ -0,0 +1,16 @@
1
+ /** (verAndInstance, recType, body) of the OfficeArt record at `off`. */
2
+ export declare function recordAt(data: Uint8Array, off: number): [number, number, Uint8Array] | undefined;
3
+ export interface Blip {
4
+ mediaType: string;
5
+ extension: string;
6
+ bytes: Uint8Array;
7
+ }
8
+ /** Decode one blip record (`recType` 0xF01A–0xF01F). */
9
+ export declare function decodeBlip(verInst: number, recType: number, body: Uint8Array, maxBytes: number): Blip | undefined;
10
+ /**
11
+ * Find and decode the first blip in a run of OfficeArt records, descending
12
+ * into containers.
13
+ */
14
+ export declare function firstBlip(data: Uint8Array, maxBytes: number): Blip | undefined;
15
+ /** Decode the blip embedded in an FBSE (0xF007) record body, if present. */
16
+ export declare function fbseBlip(body: Uint8Array, maxBytes: number): Blip | undefined;
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@mdgate/office-common",
3
+ "version": "0.1.0",
4
+ "description": "mdgate shared office-format semantics: fields, numbering, styles, DrawingML",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "files": [
17
+ "dist/**/*.js",
18
+ "dist/**/*.d.ts"
19
+ ],
20
+ "scripts": {
21
+ "build": "bun ../../scripts/build-package.ts",
22
+ "prepublishOnly": "bun run build"
23
+ },
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"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "engines": {
34
+ "node": ">=20"
35
+ },
36
+ "keywords": [
37
+ "mdgate",
38
+ "office"
39
+ ]
40
+ }