export default {
template: `
`,
data() {
return {
viewBox: "0 0 0 0",
loaded_image_width: 0,
loaded_image_height: 0,
x: 100,
y: 100,
showCross: false,
computed_src: undefined,
waiting_source: undefined,
loading: false,
DOMPurify: null,
};
},
mounted() {
if (this.sanitize) {
import("dompurify").then(({ default: DOMPurify }) => {
this.DOMPurify = DOMPurify;
this.renderContent();
});
} else {
this.renderContent();
}
setTimeout(() => this.compute_src(), 0); // NOTE: wait for window.path_prefix to be set in app.mounted()
const handle_completion = () => {
if (this.waiting_source) {
this.computed_src = this.waiting_source;
this.waiting_source = undefined;
} else {
this.loading = false;
}
};
this.$refs.img.addEventListener("load", handle_completion);
this.$refs.img.addEventListener("error", handle_completion);
for (const event of [
"pointermove",
"pointerdown",
"pointerup",
"pointerover",
"pointerout",
"pointerenter",
"pointerleave",
"pointercancel",
]) {
this.$refs.svg.addEventListener(event, (e) => this.onPointerEvent(event, e));
}
},
updated() {
this.renderContent();
this.compute_src();
},
methods: {
renderContent() {
const content = this.content || "";
if (this.sanitize) {
if (!this.DOMPurify) return;
const sanitized = this.DOMPurify.sanitize(``, {
USE_PROFILES: { svg: true, svgFilters: true },
});
const match = sanitized.match(/^