UNPKG

modern-openxml

Version:
1,013 lines (929 loc) 37.7 kB
import { NormalizedEffect, NormalizedImageFill, NormalizedFilter, NormalizedFill, NormalizedGradientFill, NormalizedShape, ShapePath, NormalizedOutline, NormalizedBackground, NormalizedChart, NormalizedStyle, NormalizedElement, NormalizedDocument, NormalizedText } from 'modern-idoc'; import { Unzipped } from 'fflate'; import { Path2DStyle } from 'modern-path2d'; type OoxmlValueType = 'boolean' | 'degree' | 'ST_Angle' | 'ST_PositiveFixedAngle' | 'positiveFixedAngle' | 'fontSize' | 'int' | 'unsignedInt' | 'number' | 'SByteValue' | 'ST_TLTimeNodeID' | 'ST_ShapeID' | 'string' | 'HexBinaryValue' | 'StringValue' | 'ST_LineEndLength' | 'ST_LineEndWidth' | 'emu' | 'ST_PositiveCoordinate' | 'ST_LineWidth' | 'ST_Coordinate32' | 'ST_AdjCoordinate' | 'dxa' | 'percentage' | 'ST_Percentage' | 'ST_PositivePercentage' | 'CT_PositiveFixedPercentage' | 'ST_PositiveFixedPercentage' | 'positiveFixedPercentage' | 'rate' | 'ST_TextSpacingPercentOrPercentString' | 'ST_TextSpacingPoint' | 'lineHeight'; declare class OoxmlValue { static DPI: number; static encode(value: any, type: OoxmlValueType): string; static decode(value: any, type: OoxmlValueType): any; } type OOXMLQueryType = 'node' | 'nodes' | OoxmlValueType; declare class OoxmlNode { dom: Node; namespaces: Record<string, any>; doc: Document; resolver: XPathNSResolver; get name(): string; constructor(dom: Node, namespaces: Record<string, any>); static fromXML(xml?: string, userNamespaces?: Record<string, any>): OoxmlNode; getDOM<T = Node>(): T; evaluate(xpath: string, type?: number): XPathResult; query(xpath: string, type?: OOXMLQueryType): any; get(xpath: string): OoxmlNode[]; find(xpath: string): OoxmlNode | undefined; attr<T = string>(xpath: string, type?: OoxmlValueType): T | undefined; } declare function stringifyProperties(slides: number): string; interface CoreProperties { title?: string; subject?: string; creator?: string; lastModifiedBy?: string; revision?: string; modified?: string; } declare function parseCoreProperties(node: OoxmlNode): CoreProperties; declare function stringifyCoreProperties(props: CoreProperties): string; interface RGBA { r: number; g: number; b: number; a: number; } type RGB = Omit<RGBA, 'a'>; interface HSL { h: number; l: number; s: number; } declare const colorXPath: string; declare function parseColor(node?: OoxmlNode, ctx?: Record<string, any>): { color: string; } | undefined; declare function stringifyColor(color: string): string; type ColorScheme = Record<string, any>; declare function parseColorScheme(clrScheme?: OoxmlNode): ColorScheme | undefined; declare function parseEffectList(effectLst?: OoxmlNode, ctx?: any): NormalizedEffect | undefined; declare const fillXPath: string; declare function parseFill(fill?: OoxmlNode, ctx?: Record<string, any>): NormalizedFill | undefined; declare function parseBlipFill(fill?: OoxmlNode, ctx?: Record<string, any>): NormalizedImageFill | undefined; declare function parseBlipFilter(blipFill?: OoxmlNode, ctx?: Record<string, any>): NormalizedFilter | undefined; declare function parseGradientFill(gradFill?: OoxmlNode, ctx?: any): NormalizedGradientFill | undefined; declare function stringifyFill(fill?: NormalizedFill, isPic?: boolean, filter?: NormalizedFilter): string | undefined; declare function stringifySolidFill(color: string): string; declare function stringifyGradientFill(fill: NormalizedGradientFill): string | undefined; interface Font { complexScript?: string; eastasian?: string; latin?: string; symbol?: string; } type FontScheme = Record<string, Font>; declare function parseFontScheme(fontScheme?: OoxmlNode): FontScheme | undefined; interface Rectangle { left?: string; top?: string; right?: string; bottom?: string; } interface ShapeGuide { name: string; fmla: string; } interface AdjustValue { name: string; value: number; } interface AdjustHandle { gdRefX?: string; gdRefY?: string; minX?: string; maxX?: string; minY?: string; maxY?: string; posX: string; posY: string; } interface ShapeGuideContext { width: number; height: number; variables: Record<string, number>; } declare function parseRectangle(rect?: OoxmlNode): Rectangle | undefined; declare function parseAdjustValueList(avLst: OoxmlNode): AdjustValue[]; declare function parseShapeGuideList(gdLst: OoxmlNode): ShapeGuide[]; declare function parseAdjustValue(gd: OoxmlNode): AdjustValue; declare function parseShapeGuide(gd: OoxmlNode): ShapeGuide; declare function parseAdjustHandleList(ahLst: OoxmlNode): AdjustHandle[]; declare function parseShapeGuideValue(value: string, ctx: ShapeGuideContext, parent?: OoxmlNode): number; declare function parseShapeGuideFmla(fmla: string, ctx: ShapeGuideContext, parent?: OoxmlNode): number; declare function parsePaths(pathLst: OoxmlNode | undefined, ctx: ShapeGuideContext): ShapePath[]; declare function parseGeometry(geom?: OoxmlNode, ctx?: Record<string, any>): NormalizedShape | undefined; declare function stringifyGeometry(shape?: NormalizedShape): string; type PrstDashType = 'solid' | 'sysDot' | 'sysDash' | 'dash' | 'dashDot' | 'lgDash' | 'lgDashDot' | 'lgDashDotDot'; declare function parseOutline(node?: OoxmlNode, ctx?: any): NormalizedOutline | undefined; declare function stringifyOutline(ln?: NormalizedOutline): string | undefined; declare function parseBackground(bg?: OoxmlNode, ctx?: any): NormalizedBackground | undefined; declare function stringifyBackground(bg?: NormalizedBackground): string | undefined; declare function parseChart(node: OoxmlNode | undefined, ctx?: any): NormalizedChart | undefined; declare function stringifyChart(chart: NormalizedChart): string; type ColorMap = Record<string, string>; declare function parseColorMap(clrMap?: OoxmlNode): ColorMap | undefined; interface NonVisualDrawingPropertiesMeta { id?: string; desc?: string; click?: string; } interface NonVisualDrawingProperties { name?: string; meta: NonVisualDrawingPropertiesMeta; style: NormalizedStyle; } declare function parseNonVisualDrawingProperties(cNvPr?: OoxmlNode): NonVisualDrawingProperties | undefined; declare function stringifyNonVisualDrawingProperties(cNvPr: NonVisualDrawingProperties): string; type ConnectionShapeMeta = NonVisualDrawingProperties['meta'] & { inCanvasIs: 'Element2D'; inPptIs: 'ConnectionShape'; placeholderType?: string; placeholderIndex?: string; }; interface ConnectionShape extends NormalizedElement { style: NormalizedStyle; meta: ConnectionShapeMeta; } declare function parseConnectionShape(node?: OoxmlNode, ctx?: any): ConnectionShape | undefined; declare function stringifyConnectionShape(sp: ConnectionShape): string; type GroupShapeMeta = NonVisualDrawingProperties['meta'] & { inCanvasIs: 'Element2D'; inPptIs: 'GroupShape'; placeholderType?: string; placeholderIndex?: string; }; interface GroupShape extends NormalizedElement { style: NormalizedStyle; children: SlideElement[]; meta: GroupShapeMeta; } declare function parseGroupShape(node: OoxmlNode, ctx: any, parseElement: any): GroupShape; declare function stringifyGroupShape(grpSp: GroupShape, stringifyElement: any): string; type PictureMeta = NonVisualDrawingProperties['meta'] & { inCanvasIs: 'Element2D'; inPptIs: 'Picture'; placeholderType?: string; placeholderIndex?: string; }; interface Picture extends NormalizedElement { style: NormalizedStyle; meta: PictureMeta; } declare function parsePicture(node?: OoxmlNode, ctx?: any): Picture | undefined; declare function stringifyPicture(pic: Picture): string; type ShapeMeta = NonVisualDrawingProperties['meta'] & { inCanvasIs: 'Element2D'; inPptIs: 'Shape'; placeholderType?: string; placeholderIndex?: string; }; interface Shape extends NormalizedElement { style: NormalizedStyle; meta: ShapeMeta; } declare function parseShape(node?: OoxmlNode, ctx?: any): Shape | undefined; declare function stringifyShape(sp: Shape): string; interface CommonTimeNode { type: 'common-time-node'; nodeType?: string; mode?: string; preset?: { id?: string; subtype?: string; groupId?: string; }; delay?: string; children: TimingNode[]; } interface Props { attribute?: string | null; duration: number; delay?: string; fill?: string; additive?: string; id?: string; mode?: string; } interface SetNode extends Props { type: 'set'; value?: string; } interface AnimationNode extends Props { type: 'animation'; calcmode?: string; valueType?: string; value: { time?: string; value?: string; floatValue?: string; fmla?: string; }[]; } interface AnimationScaleNode extends Props { type: 'animation-scale'; x: number; y: number; } interface AnimationEffectNode extends Props { type: 'animation-effect'; filter?: string; transition?: string; } interface AnimationRotateNode extends Props { type: 'animation-rotate'; rotate: number; } interface AudioNode extends Props { type: 'audio'; crossSlides: number; showWhenStopped: boolean; repeatCount: number; fill: string; display: boolean; shapeId: string; } interface CommandNode extends Props { type: 'command'; cmd: string; cmdType: string; } type TimingPartNode = SetNode | AnimationNode | AnimationScaleNode | AnimationEffectNode | AnimationRotateNode | CommandNode; type TimingNode = CommonTimeNode | TimingPartNode | AudioNode; interface Timing { mainSequence?: TimingNode[]; interactiveSequence?: TimingNode[]; bgmSequnces?: AudioNode[]; } declare function parseTiming(node: OoxmlNode | undefined): Timing | undefined; declare function stringifyMainSeq(timing: Timing): string; declare function stringifyAudio(timing: Timing): string; declare function stringifyBldList(): string; declare function stringifyTiming(timing: Timing): string; interface Transition { transition?: { name?: string; speed?: 'slow' | 'med' | 'fast'; duration?: number; attrs: Record<string, string>; }; } declare function parseTransition(node: OoxmlNode | undefined): Transition | undefined; declare function stringifyTransition(transition: Transition['transition']): string; type SlideElement = Picture | Shape | ConnectionShape | GroupShape | GraphicFrame; interface SlideMeta { inCanvasIs: 'Element2D'; inPptIs: 'Slide'; pptPath: string; pptLayoutPath: string; pptMasterPath: string; pptThemePath: string; /** 演讲者备注(纯文本,段落以换行分隔) */ notes?: string; } interface Slide extends Transition, Timing, NormalizedElement { children: SlideElement[]; meta: SlideMeta; } declare function parseElement(node: OoxmlNode, ctx: any): SlideElement | undefined; declare function parseSlide(slide: OoxmlNode, path: string, ctx: any): Slide; declare function stringifySlide(slide: Slide): string; type GraphicFrameMeta = NonVisualDrawingProperties['meta'] & { inCanvasIs: 'Element2D'; inPptIs: 'GraphicFrame'; placeholderType?: string; placeholderIndex?: string; }; interface GraphicFrame extends NormalizedElement { style: NormalizedStyle; meta: GraphicFrameMeta; children: SlideElement[]; } declare function parseGraphicFrame(node?: OoxmlNode, ctx?: any): GraphicFrame | undefined; declare function stringifyGraphicFrame(node: GraphicFrame): string | undefined; interface Placeholder { type?: string; index?: string; node?: OoxmlNode; } declare function parsePlaceholder(ph?: OoxmlNode, ctx?: any): Placeholder | undefined; interface NonVisualProperties { placeholder?: Placeholder; } declare function parseNonVisualProperties(nvPr?: OoxmlNode, ctx?: any): NonVisualProperties | undefined; declare function stringifyNonVisualProperties(_nvPr: NonVisualProperties): string; declare function stringifyNotesMaster(): string; declare function parseNotesSlide(node?: OoxmlNode): string | undefined; declare function stringifyNotesSlide(notes?: string): string; type PptxSource = string | number[] | Uint8Array | ArrayBuffer | Blob | NodeJS.ReadableStream; interface PptxMeta extends CoreProperties { cover?: string; themes: Theme[]; slides: Slide[]; slideLayouts: SlideLayout[]; slideMasters: SlideMaster[]; } interface PptxStyle { width: number; height: number; } interface NormalizedPptx extends NormalizedDocument { style: PptxStyle; children: Slide[]; meta: PptxMeta; } interface Pptx { style?: Partial<PptxStyle>; children?: Slide[]; meta?: Partial<PptxMeta>; } interface Presentation { slideWidth: number; slideHeight: number; slides: { id: string; rId: string; }[]; slideMasters: { id: string; rId: string; }[]; } declare function parsePresentation(node?: OoxmlNode): Presentation | undefined; declare function stringifyPresentation(pptx: NormalizedPptx, slides: string[], slideMasters: string[], notesMasterId?: string): string; declare function stringifyPresentationProperties(): string; interface Transform2d { style?: Transform2dStyle; rawTransform2d?: RawTransform2d; } interface Transform2dStyle { left?: number; top?: number; width?: number; height?: number; rotate?: number; scaleX?: number; scaleY?: number; } interface RawTransform2d { absoluteX?: number; absoluteY?: number; offsetX?: number; offsetY?: number; extentsCx?: number; extentsCy?: number; childOffsetX?: number; childOffsetY?: number; childExtentsCx?: number; childExtentsCy?: number; } declare function parseTransform2d(xfrm?: OoxmlNode, ctx?: any): Transform2d | undefined; declare function stringifyTransform2d(xfrm: Transform2d, isGroup?: boolean): string; interface ShapeProperties extends Transform2d { shape?: NormalizedShape; fill?: NormalizedFill; outline?: NormalizedOutline; effect?: NormalizedEffect; } declare function parseShapeProperties(spPr?: OoxmlNode, ctx?: any): ShapeProperties | undefined; declare function stringifyShapeProperties(spPr: ShapeProperties, isPic?: boolean): string; interface SlideLayout extends NormalizedElement { children: SlideElement[]; meta: { inCanvasIs: 'Element2D'; inPptIs: 'SlideLayout'; pptPath: string; pptMasterPath: string; pptThemePath: string; colorMap?: ColorMap; }; } declare function parseSlideLayout(slide: OoxmlNode, path: string, ctx: any): SlideLayout; declare function stringifySlideLayout(): string; interface SlideMaster extends NormalizedElement { children: SlideElement[]; meta: { inCanvasIs: 'Element2D'; inPptIs: 'SlideMaster'; pptPath: string; pptThemePath?: string; colorMap?: ColorMap; }; } declare function parseSlideMaster(slide: OoxmlNode, pptPath: string, ctx: any): SlideMaster; declare function stringifySlideMaster(): string; declare function stringifyTableStyles(): string; interface TextBody { style: NormalizedStyle; text?: NormalizedText; } declare function parseTextBody(txBody?: OoxmlNode, ctx?: Record<string, any>): TextBody; declare function stringifyTextBody(txBody?: TextBody): string | undefined; declare function stringifyViewProperties(): string; interface Theme { colorScheme?: ColorScheme; extraColorMap?: ColorMap; extraColorScheme?: ColorScheme; fontScheme?: FontScheme; fillStyleList?: NormalizedFill[]; outlineStyleList?: NormalizedOutline[]; effectStyleList?: NormalizedEffect[]; backgroundFillStyleList?: NormalizedFill[]; meta: { pptPath: string; }; } declare function parseTheme(theme: OoxmlNode, pptPath: string): Theme; declare function stringifyTheme(): string; declare const RELATIONSHIP_NS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"; declare const namespaces: { asvg: string; p: string; r: string; a: string; c: string; w: string; a14: string; dgm: string; dsp: string; mc: string; p14: string; p15: string; p159: string; cp: string; dc: string; dcterms: string; dcmitype: string; xsi: string; }; declare function parseTypes(node: OoxmlNode): { type: string; ext?: string; path?: string; }[]; declare function stringifyTypes(paths: string[]): string; type Relationships = ({ id: string | undefined; type: string | undefined; path: string; })[]; declare function parseRelationships(node: OoxmlNode | undefined, relsPath: string, contentTypes: { type: string; ext?: string; path?: string; }[]): Relationships; declare function stringifyRelationships(targets?: string[]): string; /** 0-based 列号转字母,例如 0 -> "A", 26 -> "AA" */ declare function colToLetter(col: number): string; /** 字母转 0-based 列号,例如 "A" -> 0, "AA" -> 26 */ declare function letterToCol(letters: string): number; /** 解析 A1 引用,返回 { row(1-based), col(0-based) } */ declare function parseCellRef(ref: string): { row: number; col: number; }; /** 由 row(1-based) 与 col(0-based) 生成 A1 引用 */ declare function toCellRef(row: number, col: number): string; interface XlsxFont { bold?: boolean; italic?: boolean; underline?: boolean; /** 字号(磅) */ size?: number; /** ARGB,如 "FFFF0000" */ color?: string; name?: string; } interface XlsxFill { /** 'none' | 'gray125' | 'solid' | ... */ patternType?: string; /** 前景色 ARGB(solid 时即填充色) */ fgColor?: string; bgColor?: string; } interface XlsxBorderEdge { /** 'thin' | 'medium' | 'thick' | 'dashed' | ... */ style?: string; color?: string; } interface XlsxBorder { left?: XlsxBorderEdge; right?: XlsxBorderEdge; top?: XlsxBorderEdge; bottom?: XlsxBorderEdge; } interface XlsxAlignment { horizontal?: string; vertical?: string; wrapText?: boolean; } interface CellXf { numFmtId?: number; fontId?: number; fillId?: number; borderId?: number; xfId?: number; applyNumberFormat?: boolean; applyFont?: boolean; applyFill?: boolean; applyBorder?: boolean; applyAlignment?: boolean; alignment?: XlsxAlignment; } interface Styles { numFmts: { id: number; formatCode: string; }[]; fonts: XlsxFont[]; fills: XlsxFill[]; borders: XlsxBorder[]; cellXfs: CellXf[]; } interface ResolvedCellStyle { font?: XlsxFont; fill?: XlsxFill; border?: XlsxBorder; alignment?: XlsxAlignment; /** 数字格式代码(内置或自定义) */ formatCode?: string; } declare function parseStyles(node?: OoxmlNode): Styles | undefined; /** 按单元格 styleId 解析出有效样式 */ declare function resolveCellStyle(styles: Styles | undefined, styleId?: number): ResolvedCellStyle | undefined; declare function stringifyStyles(styles: Styles): string; type CellValue = string | number | boolean | null; type CellType = 'string' | 'number' | 'boolean'; interface Cell { /** A1 风格引用,例如 "A1" */ ref: string; /** 行号,1-based(对应 OOXML 的 row@r) */ row: number; /** 列号,0-based 数值列(便于计算,A=0) */ col: number; /** 单元格值(公式单元格为缓存结果) */ value: CellValue; /** 值类型 */ type: CellType; /** 公式文本(不含前导 "="),例如 "SUM(A1:A2)" */ formula?: string; /** 样式索引(c@s -> styles.cellXfs[styleId]) */ styleId?: number; } interface Row { /** 行号,1-based */ index: number; cells: Cell[]; /** 行高(磅 / point,OOXML row@ht 原值) */ height?: number; } /** 列定义(对应 <col min max width>),width 为 OOXML 字符宽度原值 */ interface Column { /** 起始列,1-based(含) */ min: number; /** 结束列,1-based(含) */ max: number; width: number; } interface Worksheet { name: string; rows: Row[]; /** 列宽定义 */ columns?: Column[]; /** 合并区,A1 风格,例如 "A1:B2" */ merges?: string[]; } interface Workbook { sheets: Worksheet[]; /** 样式表(xl/styles.xml) */ styles?: Styles; } interface XlsxMeta { /** 原始 Workbook 模型,docToXlsx 据此无损回写 */ workbook: Workbook; [key: string]: any; } interface NormalizedXlsx extends NormalizedDocument { meta: XlsxMeta; } /** * 把 idoc 文档逆向投影为 Workbook 数据模型(toDoc/workbookToDoc 的逆)。 * 每个含 table 的元素还原为一个工作表;元素 meta.name 作为表名。 * 用于 docToXlsx 在缺少 meta.workbook 时的有损降级导出。 */ declare function idocToWorkbookModel(doc: NormalizedDocument): Workbook; declare function parseSharedStrings(node?: OoxmlNode): string[]; /** * 编码时收集字符串并去重,返回索引。 */ declare class SharedStrings { private readonly indexes; readonly list: string[]; index(value: string): number; get count(): number; } declare function stringifySharedStrings(strings: string[]): string; /** * 把 Workbook 投影为 idoc 文档:每个工作表是一个带 table 的元素(idoc 的 * NormalizedTable 原语:真实列宽/行高几何 + 单元格内容,合并用 rowSpan/colSpan)。 * 原始 Workbook 放进 meta.workbook 以便 docToXlsx 无损回写。 */ declare function workbookToDoc(workbook: Workbook): NormalizedXlsx; declare const SPREADSHEET_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main"; interface WorkbookSheetRef { name: string; sheetId: number; /** 指向 xl/_rels/workbook.xml.rels 中对应 worksheet 的关系 id */ rId: string; } declare function parseWorkbook(node?: OoxmlNode): WorkbookSheetRef[]; /** * 生成 workbook.xml。sheet 的 r:id 取 rId1..N,与 workbook.xml.rels 中 * worksheet 关系按相同顺序排列一致。 */ declare function stringifyWorkbook(sheetNames: string[]): string; declare function parseWorksheet(node: OoxmlNode | undefined, name: string, sharedStrings: string[]): Worksheet; declare function stringifyWorksheet(sheet: Worksheet, sharedStrings: SharedStrings): string; declare class BiMap<K, V> { forward: Map<K, V>; reverse: Map<V, K>; constructor(source: Record<any, any>); set(key: K, value: V): void; getValue(key: K): V | undefined; getKey(value: V): K | undefined; deleteByKey(key: K): void; deleteByValue(value: V): void; } declare const XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"; declare function withXmlHeader(str: string): string; declare function compressXml(str: string): string; declare function withAttr(name: string, value?: string | number): string; declare function withAttrs(attrs: (string | boolean | undefined)[]): string; declare function withIndents(str: string | (string | boolean | undefined)[] | undefined, deep?: number, ignoreFirstLine?: boolean): string; declare function withChildren(tagName: string, content?: string | null): string; /** * 转义 XML 文本内容中的特殊字符。 * * 注意:转义 `"` 为 `&quot;` 还能让 compressXml 折叠属性空格的正则失效, * 从而避免文本中形如 `a="b"` 的内容被破坏。 */ declare function escapeXml(value: string): string; declare function pathToContentType(path: string): [string, string | null] | undefined; declare const EXT_TO_MIMES: { readonly jpeg: "image/jpeg"; readonly jpg: "image/jpeg"; readonly png: "image/png"; readonly webp: "image/webp"; readonly svg: "image/svg+xml"; readonly mp3: "audio/mpeg"; readonly mp4: "video/mp4"; readonly mov: "video/quicktime"; }; declare const MINES_TO_EXT: { [k: string]: string; }; declare function clearUndef<T>(obj: T): T; declare function pathJoin(...segments: string[]): string; declare function normalizePath(path: string): string; interface Run { text: string; bold?: boolean; italic?: boolean; underline?: boolean; /** 字号(磅 / point;OOXML 中以半磅存储) */ fontSize?: number; /** 颜色 hex,例如 "FF0000" */ color?: string; } type ParagraphAlign = 'left' | 'center' | 'right' | 'both' | 'justify' | (string & {}); interface Paragraph { runs: Run[]; /** 段落样式 id(w:pStyle),例如 "Heading1" */ style?: string; /** 对齐(w:jc) */ align?: ParagraphAlign; } /** 单元格边框(w:tcBorders 的某一边),保留 OOXML 原值以便无损回写 */ interface TableBorder { /** w:val,如 single/double/dashed/nil */ val?: string; /** w:sz,八分之一磅 */ size?: number; /** w:color,RRGGBB(或 auto) */ color?: string; } interface TableCellBorders { top?: TableBorder; left?: TableBorder; bottom?: TableBorder; right?: TableBorder; } interface TableCell { paragraphs: Paragraph[]; /** 横向合并列数(w:gridSpan) */ colSpan?: number; /** 纵向合并(w:vMerge);restart 为合并起点,continue 为被并入上方 */ vMerge?: 'restart' | 'continue'; /** 底纹填充色(w:shd@fill,RRGGBB) */ shading?: string; /** 垂直对齐(w:vAlign) */ vAlign?: 'top' | 'center' | 'bottom'; /** 边框(w:tcBorders) */ borders?: TableCellBorders; } interface TableRow { cells: TableCell[]; /** 行高(twips,w:trHeight 原值) */ height?: number; } interface Table { /** 各网格列宽(twips,w:tblGrid/w:gridCol) */ columns: number[]; rows: TableRow[]; } /** 文档正文块:段落或表格(保留出现顺序) */ type Block = Paragraph | Table; /** 块是否为表格 */ declare function isTable(block: Block): block is Table; interface Docx { blocks: Block[]; } interface DocxMeta { /** 原始 Docx 模型,docToDocx 据此无损回写 */ docx: Docx; [key: string]: any; } interface NormalizedDocx extends NormalizedDocument { meta: DocxMeta; } declare function parseDocument(node?: OoxmlNode): Block[]; declare function stringifyDocument(blocks: Block[]): string; /** * 把 idoc 文档逆向投影为 Docx 数据模型(toDoc/docxModelToDoc 的逆)。 * 按 children 顺序:含 table 的元素 -> 表格块,其余含文本的元素 -> 段落块。 * 用于 docToDocx 在缺少 meta.docx 时的有损降级导出。 */ declare function idocToDocxModel(doc: NormalizedDocument): Docx; /** * 把 Docx 数据模型投影为 idoc 文档(用于统一渲染),并把原始 Docx 模型放进 * meta.docx 以便 docToDocx 无损回写。 * * 正文按块顺序投影:连续段落归到一个文本元素,表格走 idoc 的 NormalizedTable。 */ declare function docxModelToDoc(docx: Docx): NormalizedDocx; declare const WORD_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"; declare class DocToPptx { encode(pptx: Pptx): Promise<Uint8Array>; } type OpcSource = string | number[] | Uint8Array | ArrayBuffer | Blob | NodeJS.ReadableStream; /** * OPC(Open Packaging Conventions)读取基类。 * * 封装与具体 OOXML 格式无关的能力:把各种来源解成 Uint8Array、解压 zip、 * 按部件路径读取文本/字节、定位 `_rels` 路径、构造 OoxmlNode。 * pptx / xlsx 等具体解码器继承它即可复用。 */ declare class OpcReader { unzipped?: Unzipped; protected _resolveSource(source: OpcSource): Promise<Uint8Array>; protected _open(source: OpcSource): Promise<void>; protected _resolvePath(path: string): string; protected _readFile(path?: string, type?: 'text' | 'base64'): any | undefined; protected _createNode(xml?: string): OoxmlNode; protected _readNode(path?: string): OoxmlNode; protected _getRelsPath(path?: string): string; } type DocxSource = OpcSource; /** * 解码 docx(OPC 包)为 Docx 数据模型。 * * 流程对照 XlsxToJson.decode: * [Content_Types].xml → _rels/.rels → 定位 word/document.xml → 解析段落。 * MVP 只取正文段落与 run 文本/基础格式,不解析样式定义、表格、图片等。 */ declare class DocxToJson extends OpcReader { decode(source: DocxSource): Promise<Docx>; } /** * 把 Docx 数据模型编码为 docx(OPC 包)字节。流程对照 JsonToXlsx.encode。 */ declare class JsonToDocx { encode(docx: Docx): Promise<Uint8Array>; } /** * 把 Workbook 数据模型编码为 xlsx(OPC 包)字节。 * * 流程对照 DocToPptx.encode:逐个 add() 各部件,先序列化 worksheet 以收集 * 共享字符串,再写 sharedStrings.xml,最后写关系与 [Content_Types].xml 并打包。 */ declare class JsonToXlsx { encode(workbook: Workbook): Promise<Uint8Array>; } interface PptxUploadOptions { upload?: (input: string, file: NormalizedImageFill, source: NormalizedPptx | Slide | SlideLayout | SlideMaster | SlideElement) => any | Promise<any>; progress?: (progress: number, total: number, cached: boolean) => void; } interface PptxDecodeOptions { presetShapeDefinitions?: string; } interface PptxConvertOptions extends PptxDecodeOptions, PptxUploadOptions { } declare class PptxToDoc { unzipped?: Unzipped; pptx?: NormalizedPptx; protected _resolveSource(source: PptxSource): Promise<Uint8Array>; protected _resolvePath(path: string): string; protected _readFile(path?: string, type?: 'text' | 'base64'): any | undefined; protected _createNode(xml?: string): OoxmlNode; protected _readNode(path?: string): OoxmlNode; protected _getRelsPath(path?: string): string; decode(source: PptxSource, options?: PptxDecodeOptions): Promise<NormalizedPptx>; static mimeTypes: { [key: string]: string; }; static getMimeType(filePath: string): string | undefined; upload(options?: PptxUploadOptions, pptx?: NormalizedPptx | undefined): Promise<NormalizedPptx>; convert(source: PptxSource, options?: PptxConvertOptions): Promise<NormalizedPptx>; } type XlsxSource = OpcSource; /** * 解码 xlsx(OPC 包)为 Workbook 数据模型。 * * 流程对照 PptxToDoc.decode: * [Content_Types].xml → _rels/.rels → 定位 workbook → * 解析 workbook.xml 拿到 sheet 清单 → 读 workbook.xml.rels 把 rId 映射到部件 → * 解析 sharedStrings → 逐个 worksheet 解析。 */ declare class XlsxToJson extends OpcReader { decode(source: XlsxSource): Promise<Workbook>; } type CustomDomParser = (string: string, type: DOMParserSupportedType) => Document; declare function useCustomDomParser(parser: CustomDomParser): void; declare function parseDomFromString(string: string, type: DOMParserSupportedType): Document; /** * 把 idoc 文档编码回 docx。优先用 meta.docx(由 docxToDoc 写入)无损回写; * 若缺失则像 docToPptx 那样从 idoc 模型重建导出(有损,但保留文本/表格结构)。 */ declare function docToDocx(doc: NormalizedDocument): Promise<Uint8Array>; declare function docToPptx(source: Pptx): Promise<Uint8Array>; /** * 把 idoc 文档编码回 xlsx。优先用 meta.workbook(由 xlsxToDoc 写入)无损回写; * 若缺失则像 docToPptx 那样从 idoc 模型重建网格导出(有损:丢失公式/数字格式/样式, * 但保留单元格值、网格几何与合并)。 */ declare function docToXlsx(doc: NormalizedDocument): Promise<Uint8Array>; /** * 解码 docx 为 idoc 文档(NormalizedDocx)。原始 Docx 模型保留在 meta.docx, * 可用 docToDocx 无损回写。 */ declare function docxToDoc(source: DocxSource): Promise<NormalizedDocx>; declare function docxToJson(source: DocxSource): Promise<Docx>; declare function jsonToDocx(docx: Docx): Promise<Uint8Array>; declare function jsonToXlsx(workbook: Workbook): Promise<Uint8Array>; interface GeneratedAdjustHandle { refX: string; refY: string; refXDefault?: number; refYDefault?: number; minX?: number; minY?: number; maxX?: number; maxY?: number; posX: number; posY: number; } interface ParsedPresetShapeDefinition { name: string; attrs?: Record<string, any>; rect?: Rectangle; adjustValues?: AdjustValue[]; adjustHandles?: AdjustHandle[]; shapeGuides?: ShapeGuide[]; generatePaths: (options: Partial<ShapeGuideContext>) => ShapePath[]; generateAdjustHandles: (options: Partial<ShapeGuideContext>) => GeneratedAdjustHandle[] | undefined; generateSvgString: (options: Partial<ShapeGuideContext & Path2DStyle>) => string; } declare function parsePresetShapeDefinitions(presetShapeDefinitions: string): ParsedPresetShapeDefinition[]; declare function parsePresetShapeDefinition(node: OoxmlNode): ParsedPresetShapeDefinition; interface ParsedPresetTextWarpDefinition extends ParsedPresetShapeDefinition { } declare function parsePresetTextWarpDefinitions(presetTextWarpDefinitions: string): ParsedPresetTextWarpDefinition[]; declare function pptxToDoc(source: PptxSource, options?: PptxConvertOptions): Promise<NormalizedPptx>; /** * 解码 xlsx 为 idoc 文档(NormalizedXlsx)。原始 Workbook 模型保留在 * meta.workbook,可用 docToXlsx 无损回写。 */ declare function xlsxToDoc(source: XlsxSource): Promise<NormalizedXlsx>; declare function xlsxToJson(source: XlsxSource): Promise<Workbook>; type XmlNodeChild = XmlNode | string | undefined | boolean; type XmlNodeAttrs = Record<string, any>; interface XmlNode { tag: string; attrs?: XmlNodeAttrs; children?: XmlNodeChild[]; } declare class XmlRenderer { htmlEntities: Record<string, string>; encodeHtmlCustom(str: string): string; renderAttrs(attrs?: XmlNodeAttrs): string; renderChildren(children?: XmlNodeChild[]): string; render(node: XmlNode): string; } export { BiMap, DocToPptx, DocxToJson, EXT_TO_MIMES, JsonToDocx, JsonToXlsx, MINES_TO_EXT, OoxmlNode, OoxmlValue, OpcReader, PptxToDoc, RELATIONSHIP_NS, SPREADSHEET_NS, SharedStrings, WORD_NS, XML_HEADER, XlsxToJson, XmlRenderer, clearUndef, colToLetter, colorXPath, compressXml, docToDocx, docToPptx, docToXlsx, docxModelToDoc, docxToDoc, docxToJson, escapeXml, fillXPath, idocToDocxModel, idocToWorkbookModel, isTable, jsonToDocx, jsonToXlsx, letterToCol, namespaces, normalizePath, parseAdjustHandleList, parseAdjustValue, parseAdjustValueList, parseBackground, parseBlipFill, parseBlipFilter, parseCellRef, parseChart, parseColor, parseColorMap, parseColorScheme, parseConnectionShape, parseCoreProperties, parseDocument, parseDomFromString, parseEffectList, parseElement, parseFill, parseFontScheme, parseGeometry, parseGradientFill, parseGraphicFrame, parseGroupShape, parseNonVisualDrawingProperties, parseNonVisualProperties, parseNotesSlide, parseOutline, parsePaths, parsePicture, parsePlaceholder, parsePresentation, parsePresetShapeDefinition, parsePresetShapeDefinitions, parsePresetTextWarpDefinitions, parseRectangle, parseRelationships, parseShape, parseShapeGuide, parseShapeGuideFmla, parseShapeGuideList, parseShapeGuideValue, parseShapeProperties, parseSharedStrings, parseSlide, parseSlideLayout, parseSlideMaster, parseStyles, parseTextBody, parseTheme, parseTiming, parseTransform2d, parseTransition, parseTypes, parseWorkbook, parseWorksheet, pathJoin, pathToContentType, pptxToDoc, resolveCellStyle, stringifyAudio, stringifyBackground, stringifyBldList, stringifyChart, stringifyColor, stringifyConnectionShape, stringifyCoreProperties, stringifyDocument, stringifyFill, stringifyGeometry, stringifyGradientFill, stringifyGraphicFrame, stringifyGroupShape, stringifyMainSeq, stringifyNonVisualDrawingProperties, stringifyNonVisualProperties, stringifyNotesMaster, stringifyNotesSlide, stringifyOutline, stringifyPicture, stringifyPresentation, stringifyPresentationProperties, stringifyProperties, stringifyRelationships, stringifyShape, stringifyShapeProperties, stringifySharedStrings, stringifySlide, stringifySlideLayout, stringifySlideMaster, stringifySolidFill, stringifyStyles, stringifyTableStyles, stringifyTextBody, stringifyTheme, stringifyTiming, stringifyTransform2d, stringifyTransition, stringifyTypes, stringifyViewProperties, stringifyWorkbook, stringifyWorksheet, toCellRef, useCustomDomParser, withAttr, withAttrs, withChildren, withIndents, withXmlHeader, workbookToDoc, xlsxToDoc, xlsxToJson }; export type { AdjustHandle, AdjustValue, AnimationEffectNode, AnimationNode, AnimationRotateNode, AnimationScaleNode, AudioNode, Block, Cell, CellType, CellValue, CellXf, ColorMap, ColorScheme, Column, CommandNode, CommonTimeNode, ConnectionShape, ConnectionShapeMeta, CoreProperties, CustomDomParser, Docx, DocxMeta, DocxSource, Font, FontScheme, GeneratedAdjustHandle, GraphicFrame, GraphicFrameMeta, GroupShape, GroupShapeMeta, HSL, NonVisualDrawingProperties, NonVisualDrawingPropertiesMeta, NonVisualProperties, NormalizedDocx, NormalizedPptx, NormalizedXlsx, OOXMLQueryType, OoxmlValueType, OpcSource, Paragraph, ParagraphAlign, ParsedPresetShapeDefinition, ParsedPresetTextWarpDefinition, Picture, PictureMeta, Placeholder, Pptx, PptxConvertOptions, PptxDecodeOptions, PptxMeta, PptxSource, PptxStyle, PptxUploadOptions, Presentation, PrstDashType, RGB, RGBA, RawTransform2d, Rectangle, Relationships, ResolvedCellStyle, Row, Run, SetNode, Shape, ShapeGuide, ShapeGuideContext, ShapeMeta, ShapeProperties, Slide, SlideElement, SlideLayout, SlideMaster, SlideMeta, Styles, Table, TableBorder, TableCell, TableCellBorders, TableRow, TextBody, Theme, Timing, TimingNode, TimingPartNode, Transform2d, Transform2dStyle, Transition, Workbook, WorkbookSheetRef, Worksheet, XlsxAlignment, XlsxBorder, XlsxBorderEdge, XlsxFill, XlsxFont, XlsxMeta, XlsxSource, XmlNode, XmlNodeAttrs, XmlNodeChild };