modern-openxml
Version:
OpenXML for JavaScript
578 lines (523 loc) • 21.4 kB
TypeScript
import { EffectDeclaration, FillDeclaration, TextureFillDeclaration, OutlineDeclaration, BackgroundDeclaration, StyleDeclaration, ElementDeclaration, StyleProperty, GeometryDeclaration, DocumentDeclaration, TextDeclaration } from 'modern-idoc';
import { Unzipped } from 'fflate';
type OOXMLValueType = 'boolean' | 'degree' | 'ST_Angle' | 'ST_PositiveFixedAngle' | 'positiveFixedAngle' | 'fontSize' | 'int' | 'unsignedInt' | 'number' | 'SByteValue' | 'ST_TLTimeNodeID' | 'ST_ShapeID' | 'string' | 'HexBinaryValue' | 'StringValue' | '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;
declare function stringifyCoreProperties(): 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>): 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): EffectDeclaration | undefined;
declare const fillXPath: string;
declare function parseFill(fill?: OOXMLNode, ctx?: Record<string, any>): FillDeclaration | undefined;
declare function parseBlipFill(fill?: OOXMLNode, ctx?: Record<string, any>): TextureFillDeclaration | undefined;
declare function stringifyFill(fill?: FillDeclaration, isPic?: boolean): 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 LineEnd {
headEnd?: LineEndType;
tailEnd?: LineEndType;
}
declare enum LineEndType {
NONE = "none",
OVAL = "oval",
STEALTH = "stealth",
TRIANGLE = "triangle",
ARROW = "arrow",
DIAMOND = "diamond"
}
declare enum DashType {
SOLID = "solid",
SYS_DOT = "sysDot",
SYS_DASH = "sysDash",
DASH = "dash",
DASH_DOT = "dashDot",
LG_DASH = "lgDash",
LG_DASH_DOT = "lgDashDot",
LG_DASH_DOT_DOT = "lgDashDotDot"
}
declare function parseOutline(node?: OOXMLNode, ctx?: any): OutlineDeclaration | undefined;
declare function stringifyOutline(ln?: OutlineDeclaration): string | undefined;
declare function parseBackground(bg?: OOXMLNode, ctx?: any): BackgroundDeclaration | undefined;
declare function stringifyBackground(bg?: BackgroundDeclaration): 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: Partial<StyleDeclaration>;
}
declare function parseNonVisualDrawingProperties(cNvPr?: OOXMLNode): NonVisualDrawingProperties | undefined;
declare function stringifyNonVisualDrawingProperties(cNvPr: NonVisualDrawingProperties): string;
type ConnectionShapeMeta = NonVisualDrawingProperties['meta'] & {
type: 'connection-shape';
placeholderType?: string;
placeholderIndex?: string;
};
interface ConnectionShape extends ElementDeclaration {
style: StyleProperty;
meta: ConnectionShapeMeta;
}
declare function parseConnectionShape(node?: OOXMLNode, ctx?: any): ConnectionShape | undefined;
declare function parseGeometry(geom?: OOXMLNode, ctx?: Record<string, any>): GeometryDeclaration | undefined;
declare function stringifyGeometry(geometry?: GeometryDeclaration): string | undefined;
type GroupShapeMeta = NonVisualDrawingProperties['meta'] & {
type: 'group-shape';
placeholderType?: string;
placeholderIndex?: string;
};
interface GroupShape extends ElementDeclaration {
style: StyleProperty;
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'] & {
type: 'picture';
placeholderType?: string;
placeholderIndex?: string;
};
interface Picture extends ElementDeclaration {
style: StyleProperty;
meta: PictureMeta;
}
declare function parsePicture(node?: OOXMLNode, ctx?: any): Picture | undefined;
declare function stringifyPicture(pic: Picture): string;
type ShapeMeta = NonVisualDrawingProperties['meta'] & {
type: 'shape';
placeholderType?: string;
placeholderIndex?: string;
};
interface Shape extends ElementDeclaration {
style: StyleProperty;
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 {
id: string;
layoutId: string;
masterId: string;
}
interface Slide extends Transition, Timing, ElementDeclaration {
children: SlideElement[];
meta: SlideMeta;
}
declare function parseElement(node: OOXMLNode, ctx: any): SlideElement | undefined;
declare function parseSlide(slide: OOXMLNode, id: string, ctx: any): Slide;
declare function stringifySlide(slide: Slide): string;
type GraphicFrameMeta = NonVisualDrawingProperties['meta'] & {
type: 'graphic-frame';
placeholderType?: string;
placeholderIndex?: string;
};
interface GraphicFrame extends ElementDeclaration {
style: StyleProperty;
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 {
audio?: any;
video?: any;
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 {
cover?: string;
themes: Theme[];
slides: Slide[];
slideLayouts: SlideLayout[];
slideMasters: SlideMaster[];
}
interface PPTXStyle {
width: number;
height: number;
}
interface PPTXDeclaration extends DocumentDeclaration {
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: PPTXDeclaration, 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 {
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 {
geometry?: GeometryDeclaration;
fill?: FillDeclaration;
outline?: OutlineDeclaration;
effect?: EffectDeclaration;
}
declare function parseShapeProperties(spPr?: OOXMLNode, ctx?: any): ShapeProperties | undefined;
declare function stringifyShapeProperties(spPr: ShapeProperties, isPic?: boolean): string;
interface SlideLayout extends ElementDeclaration {
children: SlideElement[];
meta: {
id: string;
masterId: string;
colorMap?: ColorMap;
};
}
declare function parseSlideLayout(slide: OOXMLNode, id: string, ctx: any): SlideLayout;
declare function stringifySlideLayout(): string;
interface SlideMaster extends ElementDeclaration {
children: SlideElement[];
meta: {
id: string;
colorMap?: ColorMap;
themeId?: string;
themeIndex?: number;
};
}
declare function parseSlideMaster(slide: OOXMLNode, id: string, ctx: any): SlideMaster;
declare function stringifySlideMaster(): string;
declare function stringifyTableStyles(): string;
interface TextBody {
style: Partial<StyleDeclaration>;
text?: TextDeclaration;
}
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?: FillDeclaration[];
outlineStyleList?: OutlineDeclaration[];
effectStyleList?: EffectDeclaration[];
backgroundFillStyleList?: FillDeclaration[];
}
declare function parseTheme(theme?: OOXMLNode): Theme | undefined;
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;
};
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 const IN_BROWSER: boolean;
declare const SUPPORTS_CRYPTO: boolean;
declare const SUPPORTS_CRYPTO_SUBTLE: boolean;
declare function hashBlob(blob: Blob, algorithm?: 'sha1' | 'sha256' | 'sha384' | 'sha512'): Promise<string>;
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 encodeForMap<T extends Record<string, any>>(value: any | undefined, map: T): keyof T | undefined;
declare function decodeForMap<T extends Record<string, any>>(value: string | undefined, map: T): T[keyof T] | undefined;
declare const Alignment: {
map: {
ctr: string;
dist: string;
just: string;
justLow: string;
l: string;
r: string;
thaiDist: string;
};
encode(value?: string): "ctr" | "dist" | "just" | "justLow" | "l" | "r" | "thaiDist" | undefined;
decode(value?: string): string | undefined;
};
declare function clearUndef<T>(obj: T): T;
declare function idocToPPTX(source: PPTX): Promise<Uint8Array>;
declare class IDocToPPTXConverter {
encode(pptx: PPTX): Promise<Uint8Array>;
}
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;
}
interface ParseSlideElementContext {
parent?: SlideElement;
}
declare class IDocToSVGStringConverter {
xmlRenderer: XMLRenderer;
genUUID(): number;
parseColor(val: string, ctx: {
defs: XMLNode;
uuid: number;
colorMap: Map<string, string>;
}): string;
parseFill(fill: FillDeclaration, ctx: {
key: string;
attrs?: Record<string, any>;
width: number;
height: number;
defs: XMLNode;
uuid: number;
colorMap: Map<string, string>;
geometryPaths?: XMLNode[];
}): XMLNode[];
parseSlideElement(el: SlideElement, ctx?: ParseSlideElementContext): XMLNode;
parse(pptx: PPTXDeclaration): XMLNode;
convertSlideElement(element: SlideElement, ctx?: ParseSlideElementContext): string;
convert(pptx: PPTXDeclaration): string;
}
interface PPTXUploadOptions {
upload?: (input: string, file: {
src: string;
}, source: PPTXDeclaration | 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?: PPTXDeclaration;
protected _resolveSource(source: PPTXSource): Promise<Uint8Array>;
protected _resolvePath(path: string): string;
protected _readFile(path?: string, type?: 'text' | 'base64'): any | undefined;
decode(source: PPTXSource, options?: PPTXDecodeOptions): Promise<PPTXDeclaration>;
static mimeTypes: {
[key: string]: string;
};
getMimeType(filePath: string): string | undefined;
upload(options?: PPTXUploadOptions, pptx?: PPTXDeclaration | undefined): Promise<PPTXDeclaration>;
convert(source: PPTXSource, options?: PPTXConvertOptions): Promise<PPTXDeclaration>;
}
declare function pptxToIDoc(source: PPTXSource, options?: PPTXConvertOptions): Promise<PPTXDeclaration>;
declare function pptxToSVG(source: PPTXSource, options?: PPTXConvertOptions): Promise<SVGSVGElement>;
declare function pptxToSVGString(source: PPTXSource, options?: PPTXConvertOptions): Promise<string>;
export { Alignment, DashType, EXT_TO_MIMES, IDocToPPTXConverter, IDocToSVGStringConverter, IN_BROWSER, LineEndType, MINES_TO_EXT, OOXMLNode, OOXMLValue, PPTXToIDocConverter, SUPPORTS_CRYPTO, SUPPORTS_CRYPTO_SUBTLE, XMLRenderer, XML_HEADER, clearUndef, colorXPath, compressXml, decodeForMap, encodeForMap, fillXPath, hashBlob, idocToPPTX, namespaces, parseBackground, parseBlipFill, parseColor, parseColorMap, parseColorScheme, parseConnectionShape, parseEffectList, parseElement, parseFill, parseFontScheme, parseGeometry, parseGraphicFrame, parseGroupShape, parseNonVisualDrawingProperties, parseNonVisualProperties, parseOutline, parsePicture, parsePlaceholder, parsePresentation, parseRelationships, parseShape, parseShapeProperties, parseSlide, parseSlideLayout, parseSlideMaster, parseTextBody, parseTheme, parseTiming, parseTransform2d, parseTransition, parseTypes, pathToContentType, pptxToIDoc, pptxToSVG, pptxToSVGString, stringifyAudio, stringifyBackground, stringifyBldList, stringifyColor, stringifyCoreProperties, stringifyFill, stringifyGeometry, stringifyGroupShape, stringifyMainSeq, stringifyNonVisualDrawingProperties, stringifyNonVisualProperties, stringifyNotesMaster, stringifyNotesSlide, stringifyOutline, stringifyPicture, stringifyPresentation, stringifyPresentationProperties, stringifyProperties, stringifyRelationships, stringifyShape, stringifyShapeProperties, stringifySlide, stringifySlideLayout, stringifySlideMaster, stringifyTableStyles, stringifyTextBody, stringifyTheme, stringifyTiming, stringifyTransform2d, stringifyTransition, stringifyTypes, stringifyViewProperties, withAttr, withAttrs, withChildren, withIndents, withXmlHeader };
export type { AnimationEffectNode, AnimationNode, AnimationRotateNode, AnimationScaleNode, AudioNode, ColorMap, ColorScheme, CommandNode, CommonTimeNode, ConnectionShape, ConnectionShapeMeta, Font, FontScheme, GraphicFrame, GraphicFrameMeta, GroupShape, GroupShapeMeta, HSL, LineEnd, NonVisualDrawingProperties, NonVisualDrawingPropertiesMeta, NonVisualProperties, OOXMLQueryType, OOXMLValueType, PPTX, PPTXConvertOptions, PPTXDeclaration, PPTXDecodeOptions, PPTXMeta, PPTXSource, PPTXStyle, PPTXUploadOptions, ParseSlideElementContext, Picture, PictureMeta, Placeholder, Presentation, RGB, RGBA, RawTransform2d, Relationships, SetNode, Shape, ShapeMeta, ShapeProperties, Slide, SlideElement, SlideLayout, SlideMaster, SlideMeta, TextBody, Theme, Timing, TimingNode, TimingPartNode, Transform2d, Transform2dStyle, Transition, XMLNode, XMLNodeAttrs, XMLNodeChild };