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
readonlysourcePartName: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
| Parameter | Type |
|---|---|
type | string |
target | string |
targetMode? | "Internal" | "External" |
Returns
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
| Parameter | Type |
|---|---|
id | string |
type | string |
target | string |
targetMode? | "Internal" | "External" |
Returns
byType()
byType(
type):Relationship[]
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
get()
get(
id):Relationship|undefined
Parameters
| Parameter | Type |
|---|---|
id | string |
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
| Parameter | Type |
|---|---|
id | string |
Returns
boolean
resolveTarget()
resolveTarget(
id):string
Resolve an internal relationship's target to an absolute partname.
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
string
serialize()
serialize():
string
Returns
string
empty()
staticempty(sourcePartName):Relationships
Empty relationship set (for parts that have no .rels).
Parameters
| Parameter | Type |
|---|---|
sourcePartName | string |
Returns
Relationships
parse()
staticparse(xml,sourcePartName):Relationships
Parameters
| Parameter | Type | Description |
|---|---|---|
xml | string | body of the .rels part |
sourcePartName | string | partname of the owning part ('/' for /_rels/.rels) |
Returns
Relationships