[api-minor] Add a new method, in OptionalContentConfig
, to detect the initial Optional Content visibility state
This will allow us to improve the `PDFThumbnailView.setImage` handling in the viewer, and thanks to the added caching this should be reasonbly efficient.
This commit is contained in:
parent
f3d76b42b3
commit
ceb4f8a6ab
@ -44,8 +44,12 @@ class OptionalContentGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class OptionalContentConfig {
|
class OptionalContentConfig {
|
||||||
|
#cachedHasInitialVisibility = true;
|
||||||
|
|
||||||
#groups = new Map();
|
#groups = new Map();
|
||||||
|
|
||||||
|
#initialVisibility = null;
|
||||||
|
|
||||||
#order = null;
|
#order = null;
|
||||||
|
|
||||||
constructor(data) {
|
constructor(data) {
|
||||||
@ -78,6 +82,12 @@ class OptionalContentConfig {
|
|||||||
for (const off of data.off) {
|
for (const off of data.off) {
|
||||||
this.#groups.get(off)._setVisible(INTERNAL, false);
|
this.#groups.get(off)._setVisible(INTERNAL, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The following code must always run *last* in the constructor.
|
||||||
|
this.#initialVisibility = new Map();
|
||||||
|
for (const [id, group] of this.#groups) {
|
||||||
|
this.#initialVisibility.set(id, group.visible);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#evaluateVisibilityExpression(array) {
|
#evaluateVisibilityExpression(array) {
|
||||||
@ -195,6 +205,21 @@ class OptionalContentConfig {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.#groups.get(id)._setVisible(INTERNAL, !!visible);
|
this.#groups.get(id)._setVisible(INTERNAL, !!visible);
|
||||||
|
|
||||||
|
this.#cachedHasInitialVisibility = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
get hasInitialVisibility() {
|
||||||
|
if (this.#cachedHasInitialVisibility !== null) {
|
||||||
|
return this.#cachedHasInitialVisibility;
|
||||||
|
}
|
||||||
|
for (const [id, group] of this.#groups) {
|
||||||
|
const visible = this.#initialVisibility.get(id);
|
||||||
|
if (group.visible !== visible) {
|
||||||
|
return (this.#cachedHasInitialVisibility = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (this.#cachedHasInitialVisibility = true);
|
||||||
}
|
}
|
||||||
|
|
||||||
getOrder() {
|
getOrder() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user