Skip to content

Class: OpcPackage ​

An OPC package loaded from .pptx bytes.

Fidelity contract: parts that are never mutated (Part.markDirty()) are written back byte-identically by save(). Whole-zip byte-identity is not promised — zip metadata and compression may differ — but part bodies, the part-name set, and part order are preserved.

Properties ​

contentTypes ​

readonly contentTypes: ContentTypes

Content-type resolution + registration overlay.

Accessors ​

parts ​

Get Signature ​

get parts(): ReadonlyMap<string, Part>

All parts, keyed by partname, in zip/add order.

Returns ​

ReadonlyMap<string, Part>

Methods ​

addPart() ​

addPart(partName, contentType, bytes): Part

Add a new part and register its content type (ensureRegistered), so the package stays consistent. Throws if the partname is already taken.

Parameters ​

ParameterType
partNamestring
contentTypestring
bytesUint8Array

Returns ​

Part


part() ​

part(partName): Part | undefined

Parameters ​

ParameterType
partNamestring

Returns ​

Part | undefined


partsByContentType() ​

partsByContentType(contentType): Part[]

Parameters ​

ParameterType
contentTypestring

Returns ​

Part[]


relationshipsFor() ​

relationshipsFor(sourcePartName?): Relationships

Relationships owned by a part ('/' for the package-level /_rels/.rels). Parts without a .rels part get an empty set.

Parameters ​

ParameterTypeDefault value
sourcePartNamestring'/'

Returns ​

Relationships


removePart() ​

removePart(partName): boolean

Remove a part and return whether it existed. Its .rels part goes with it, along with its Override content-type registration and any cached relationship set it owned, so a later save() neither re-emits it nor flushes a stale .rels for it. A relationship set belongs to its part: one left behind would come back as the relationships of the next part added under the same name. Low-level: it does not touch references to this part (dangling rels are the caller's concern) nor cascade to parts this one referenced — see Presentation.removeSlide for the slide-aware variant that unwires the presentation and prunes orphans.

Parameters ​

ParameterType
partNamestring

Returns ​

boolean


reserveMediaPartName() ​

reserveMediaPartName(extension, base?): string

Reserve an unused media partname /ppt/media/<base><n>.<ext> (n one past the highest existing index for that base). Does not create the part.

Parameters ​

ParameterTypeDefault value
extensionstringundefined
basestring'image'

Returns ​

string


reservePartNameLike() ​

reservePartNameLike(templatePartName, taken?): string

Reserve an unused partname in the same directory and naming family as templatePartName, with a fresh index one past the highest existing one. The template's filename is split into a base (its stem minus any trailing digits) and an extension, e.g. /ppt/slideLayouts/slideLayout1.xml → /ppt/slideLayouts/slideLayout<n>.xml, /ppt/media/image1.png → /ppt/media/image<n>.png. Used when copying a part in from another package. Does not create the part.

taken names partnames to count as existing although the package does not hold them yet: an import plan's names for the parts it would add, so the names it predicts are the ones the copy itself is then given.

Parameters ​

ParameterType
templatePartNamestring
taken?ReadonlySet<string>

Returns ​

string


save() ​

save(): Promise<Uint8Array<ArrayBufferLike>>

Re-emit the package. Clean parts are written from their original bytes; dirty parts from their DOM. Dirty relationship sets and content types are flushed first. Part order is preserved from load; added parts append.

Returns ​

Promise<Uint8Array<ArrayBufferLike>>


load() ​

static load(input): Promise<OpcPackage>

Parameters ​

ParameterType
inputOpcInput

Returns ​

Promise<OpcPackage>