[Editor] Avoid to darken the current editor when opening the alt-text dialog
This commit is contained in:
parent
a7894a4d7b
commit
6545551e76
@ -54,6 +54,7 @@ import {
|
|||||||
version,
|
version,
|
||||||
} from "./display/api.js";
|
} from "./display/api.js";
|
||||||
import {
|
import {
|
||||||
|
DOMSVGFactory,
|
||||||
getFilenameFromUrl,
|
getFilenameFromUrl,
|
||||||
getPdfFilenameFromUrl,
|
getPdfFilenameFromUrl,
|
||||||
getXfaPageViewport,
|
getXfaPageViewport,
|
||||||
@ -90,6 +91,7 @@ export {
|
|||||||
build,
|
build,
|
||||||
CMapCompressionType,
|
CMapCompressionType,
|
||||||
createValidAbsoluteUrl,
|
createValidAbsoluteUrl,
|
||||||
|
DOMSVGFactory,
|
||||||
FeatureTest,
|
FeatureTest,
|
||||||
getDocument,
|
getDocument,
|
||||||
getFilenameFromUrl,
|
getFilenameFromUrl,
|
||||||
|
@ -43,6 +43,7 @@ import {
|
|||||||
version,
|
version,
|
||||||
} from "../../src/display/api.js";
|
} from "../../src/display/api.js";
|
||||||
import {
|
import {
|
||||||
|
DOMSVGFactory,
|
||||||
getFilenameFromUrl,
|
getFilenameFromUrl,
|
||||||
getPdfFilenameFromUrl,
|
getPdfFilenameFromUrl,
|
||||||
getXfaPageViewport,
|
getXfaPageViewport,
|
||||||
@ -86,6 +87,7 @@ describe("pdfjs_api", function () {
|
|||||||
build,
|
build,
|
||||||
CMapCompressionType,
|
CMapCompressionType,
|
||||||
createValidAbsoluteUrl,
|
createValidAbsoluteUrl,
|
||||||
|
DOMSVGFactory,
|
||||||
FeatureTest,
|
FeatureTest,
|
||||||
getDocument,
|
getDocument,
|
||||||
getFilenameFromUrl,
|
getFilenameFromUrl,
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { shadow } from "pdfjs-lib";
|
import { DOMSVGFactory, shadow } from "pdfjs-lib";
|
||||||
|
|
||||||
class AltTextManager {
|
class AltTextManager {
|
||||||
#boundUpdateUIState = this.#updateUIState.bind(this);
|
#boundUpdateUIState = this.#updateUIState.bind(this);
|
||||||
@ -46,6 +46,10 @@ class AltTextManager {
|
|||||||
|
|
||||||
#previousAltText = null;
|
#previousAltText = null;
|
||||||
|
|
||||||
|
#svgElement = null;
|
||||||
|
|
||||||
|
#rectElement = null;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
{
|
{
|
||||||
dialog,
|
dialog,
|
||||||
@ -87,11 +91,46 @@ class AltTextManager {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#createSVGElement() {
|
||||||
|
if (this.#svgElement) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We create a mask to add to the dialog backdrop: the idea is to have a
|
||||||
|
// darken background everywhere except on the editor to clearly see the
|
||||||
|
// picture to describe.
|
||||||
|
|
||||||
|
const svgFactory = new DOMSVGFactory();
|
||||||
|
const svg = (this.#svgElement = svgFactory.createElement("svg"));
|
||||||
|
svg.setAttribute("width", "0");
|
||||||
|
svg.setAttribute("height", "0");
|
||||||
|
const defs = svgFactory.createElement("defs");
|
||||||
|
svg.append(defs);
|
||||||
|
const mask = svgFactory.createElement("mask");
|
||||||
|
defs.append(mask);
|
||||||
|
mask.setAttribute("id", "alttext-manager-mask");
|
||||||
|
mask.setAttribute("maskContentUnits", "objectBoundingBox");
|
||||||
|
let rect = svgFactory.createElement("rect");
|
||||||
|
mask.append(rect);
|
||||||
|
rect.setAttribute("fill", "white");
|
||||||
|
rect.setAttribute("width", "1");
|
||||||
|
rect.setAttribute("height", "1");
|
||||||
|
rect.setAttribute("x", "0");
|
||||||
|
rect.setAttribute("y", "0");
|
||||||
|
|
||||||
|
rect = this.#rectElement = svgFactory.createElement("rect");
|
||||||
|
mask.append(rect);
|
||||||
|
rect.setAttribute("fill", "black");
|
||||||
|
this.#dialog.append(svg);
|
||||||
|
}
|
||||||
|
|
||||||
async editAltText(uiManager, editor) {
|
async editAltText(uiManager, editor) {
|
||||||
if (this.#currentEditor || !editor) {
|
if (this.#currentEditor || !editor) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.#createSVGElement();
|
||||||
|
|
||||||
this.#hasUsedPointer = false;
|
this.#hasUsedPointer = false;
|
||||||
for (const element of this._elements) {
|
for (const element of this._elements) {
|
||||||
element.addEventListener("pointerdown", this.#boundPointerDown);
|
element.addEventListener("pointerdown", this.#boundPointerDown);
|
||||||
@ -134,6 +173,11 @@ class AltTextManager {
|
|||||||
const MARGIN = 10;
|
const MARGIN = 10;
|
||||||
const isLTR = this.#uiManager.direction === "ltr";
|
const isLTR = this.#uiManager.direction === "ltr";
|
||||||
|
|
||||||
|
this.#rectElement.setAttribute("width", `${width / windowW}`);
|
||||||
|
this.#rectElement.setAttribute("height", `${height / windowH}`);
|
||||||
|
this.#rectElement.setAttribute("x", `${x / windowW}`);
|
||||||
|
this.#rectElement.setAttribute("y", `${y / windowH}`);
|
||||||
|
|
||||||
let left = null;
|
let left = null;
|
||||||
let top = y;
|
let top = y;
|
||||||
top += Math.min(windowH - (top + dialogH), 0);
|
top += Math.min(windowH - (top + dialogH), 0);
|
||||||
@ -254,6 +298,8 @@ class AltTextManager {
|
|||||||
this.#currentEditor = null;
|
this.#currentEditor = null;
|
||||||
this.#uiManager = null;
|
this.#uiManager = null;
|
||||||
this.#finish();
|
this.#finish();
|
||||||
|
this.#svgElement?.remove();
|
||||||
|
this.#svgElement = this.#rectElement = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -688,7 +688,7 @@
|
|||||||
|
|
||||||
&::backdrop {
|
&::backdrop {
|
||||||
/* This is needed to avoid to darken the image the user want to describe. */
|
/* This is needed to avoid to darken the image the user want to describe. */
|
||||||
display: none;
|
mask: url(#alttext-manager-mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
&.positioned {
|
&.positioned {
|
||||||
|
Loading…
Reference in New Issue
Block a user