Skip to content

Class: Relationships ​

Overlay over one .rels part, keyed by relationship id. While clean, the .rels bytes pass through verbatim on save (byte-identical); once add() (or another mutation) marks it dirty, OpcPackage.save() writes serialize() into the owning .rels part instead.

Properties ​

sourcePartName ​

readonly sourcePartName: string

Partname of the part owning these relationships ('/' for package-level).

Accessors ​

isDirty ​

Get Signature ​

get isDirty(): boolean

True once a relationship was added/changed; serialize() is then authoritative.

Returns ​

boolean


size ​

Get Signature ​

get size(): number

Returns ​

number

Methods ​

[iterator]() ​

[iterator](): IterableIterator<Relationship>

Returns ​

IterableIterator<Relationship>


add() ​

add(type, target, targetMode?): Relationship

Add a relationship and return it. Allocates an id rId<n> with n one past the highest existing numeric id. target is relative to the source part's directory for internal targets (e.g. ../media/image1.png), or an absolute URI for external ones. Marks this set dirty.

Parameters ​

ParameterType
typestring
targetstring
targetMode?"Internal" | "External"

Returns ​

Relationship


addWithId() ​

addWithId(id, type, target, targetMode?): Relationship

Add a relationship under a caller-chosen id and return it. Used when rebuilding a copied part's relationships across a package boundary: keeping each source id lets the copied part body's r:id/r:embed references stay valid without rewriting the body. Throws if the id is already present. Marks this set dirty.

Parameters ​

ParameterType
idstring
typestring
targetstring
targetMode?"Internal" | "External"

Returns ​

Relationship


byType() ​

byType(type): Relationship[]

Parameters ​

ParameterType
typestring

Returns ​

Relationship[]


get() ​

get(id): Relationship | undefined

Parameters ​

ParameterType
idstring

Returns ​

Relationship | undefined


remove() ​

remove(id): boolean

Remove the relationship with id and return whether one was present. Used when a referenced part is deleted (e.g. removing a slide drops the presentation→slide relationship). Marks this set dirty when it removes one.

Parameters ​

ParameterType
idstring

Returns ​

boolean


resolveTarget() ​

resolveTarget(id): string

Resolve an internal relationship's target to an absolute partname.

Parameters ​

ParameterType
idstring

Returns ​

string


serialize() ​

serialize(): string

Returns ​

string


empty() ​

static empty(sourcePartName): Relationships

Empty relationship set (for parts that have no .rels).

Parameters ​

ParameterType
sourcePartNamestring

Returns ​

Relationships


parse() ​

static parse(xml, sourcePartName): Relationships

Parameters ​

ParameterTypeDescription
xmlstringbody of the .rels part
sourcePartNamestringpartname of the owning part ('/' for /_rels/.rels)

Returns ​

Relationships