UNPKG

modern-openxml

Version:
620 lines (564 loc) 23.6 kB
import { NormalizedEffect, NormalizedFill, NormalizedImageFill, NormalizedGradientFill, ShapePath, NormalizedShape, NormalizedOutline, NormalizedBackground, 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 parseGradientFill(gradFill?: OoxmlNode, ctx?: any): NormalizedGradientFill | undefined; declare function stringifyFill(fill?: NormalizedFill, isPic?: boolean): 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; 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'] & { inPptIs: 'ConnectionShape'; placeholderType?: string; placeholderIndex?: string; }; interface ConnectionShape extends NormalizedElement { style: NormalizedStyle; meta: ConnectionShapeMeta; } declare function parseConnectionShape(node?: OoxmlNode, ctx?: any): ConnectionShape | undefined; type GroupShapeMeta = NonVisualDrawingProperties['meta'] & { 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'] & { 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'] & { 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 { inPptIs: 'Slide'; pptPath: string; pptLayoutPath: string; pptMasterPath: string; pptThemePath: 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'] & { 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; 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 stringifyNotesSlide(): 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 { width: number; height: number; slides: { id: string; rId: string; }[]; slideMasters: { id: string; rId: string; }[]; } declare function parsePresentation(node?: OoxmlNode): Presentation | undefined; declare function stringifyPresentation(props: NormalizedPptx, slides: string[], slideMasters: 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: { 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: { 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 namespaces: { asvg: string; p: string; r: string; a: 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; 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; 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; declare class IdocToPptxConverter { encode(pptx: Pptx): 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 PptxToIdocConverter { 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 CustomDomParser = (string: string, type: DOMParserSupportedType) => Document; declare function useCustomDomParser(parser: CustomDomParser): void; declare function parseDomFromString(string: string, type: DOMParserSupportedType): Document; declare function idocToPptx(source: Pptx): 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 pptxToIdoc(source: PptxSource, options?: PptxConvertOptions): Promise<NormalizedPptx>; 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, EXT_TO_MIMES, IdocToPptxConverter, MINES_TO_EXT, OoxmlNode, OoxmlValue, PptxToIdocConverter, XML_HEADER, XmlRenderer, clearUndef, colorXPath, compressXml, fillXPath, idocToPptx, namespaces, normalizePath, parseAdjustHandleList, parseAdjustValue, parseAdjustValueList, parseBackground, parseBlipFill, parseColor, parseColorMap, parseColorScheme, parseConnectionShape, parseCoreProperties, parseDomFromString, parseEffectList, parseElement, parseFill, parseFontScheme, parseGeometry, parseGradientFill, parseGraphicFrame, parseGroupShape, parseNonVisualDrawingProperties, parseNonVisualProperties, parseOutline, parsePaths, parsePicture, parsePlaceholder, parsePresentation, parsePresetShapeDefinition, parsePresetShapeDefinitions, parsePresetTextWarpDefinitions, parseRectangle, parseRelationships, parseShape, parseShapeGuide, parseShapeGuideFmla, parseShapeGuideList, parseShapeGuideValue, parseShapeProperties, parseSlide, parseSlideLayout, parseSlideMaster, parseTextBody, parseTheme, parseTiming, parseTransform2d, parseTransition, parseTypes, pathJoin, pathToContentType, pptxToIdoc, stringifyAudio, stringifyBackground, stringifyBldList, stringifyColor, stringifyCoreProperties, stringifyFill, stringifyGeometry, stringifyGradientFill, stringifyGroupShape, stringifyMainSeq, stringifyNonVisualDrawingProperties, stringifyNonVisualProperties, stringifyNotesMaster, stringifyNotesSlide, stringifyOutline, stringifyPicture, stringifyPresentation, stringifyPresentationProperties, stringifyProperties, stringifyRelationships, stringifyShape, stringifyShapeProperties, stringifySlide, stringifySlideLayout, stringifySlideMaster, stringifySolidFill, stringifyTableStyles, stringifyTextBody, stringifyTheme, stringifyTiming, stringifyTransform2d, stringifyTransition, stringifyTypes, stringifyViewProperties, useCustomDomParser, withAttr, withAttrs, withChildren, withIndents, withXmlHeader }; export type { AdjustHandle, AdjustValue, AnimationEffectNode, AnimationNode, AnimationRotateNode, AnimationScaleNode, AudioNode, ColorMap, ColorScheme, CommandNode, CommonTimeNode, ConnectionShape, ConnectionShapeMeta, CoreProperties, CustomDomParser, Font, FontScheme, GeneratedAdjustHandle, GraphicFrame, GraphicFrameMeta, GroupShape, GroupShapeMeta, HSL, NonVisualDrawingProperties, NonVisualDrawingPropertiesMeta, NonVisualProperties, NormalizedPptx, OOXMLQueryType, OoxmlValueType, ParsedPresetShapeDefinition, ParsedPresetTextWarpDefinition, Picture, PictureMeta, Placeholder, Pptx, PptxConvertOptions, PptxDecodeOptions, PptxMeta, PptxSource, PptxStyle, PptxUploadOptions, Presentation, PrstDashType, RGB, RGBA, RawTransform2d, Rectangle, Relationships, SetNode, Shape, ShapeGuide, ShapeGuideContext, ShapeMeta, ShapeProperties, Slide, SlideElement, SlideLayout, SlideMaster, SlideMeta, TextBody, Theme, Timing, TimingNode, TimingPartNode, Transform2d, Transform2dStyle, Transition, XmlNode, XmlNodeAttrs, XmlNodeChild };