feat: Suppression de html2canvas
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-05-03 17:20:25 +02:00
parent 5b52cee3fe
commit c85fdc8d27
3 changed files with 24 additions and 113 deletions

View File

@ -9,8 +9,7 @@ import { Splide, SplideSlide } from "@splidejs/vue-splide";
import Question from "./Question.vue";
import "@splidejs/splide/dist/css/splide.min.css";
import ScoreHeader from "./ScoreHeader.vue";
import html2canvas from "html2canvas";
import { toPng } from 'html-to-image';
import { toPng } from "html-to-image";
const props = defineProps({
id: {
@ -114,41 +113,37 @@ function nextQuestion() {
}, 100);
}
const saveAs = (blob, fileName) =>{
var elem = window.document.createElement('a');
elem.href = blob
const saveAs = (blob, fileName) => {
var elem = window.document.createElement("a");
elem.href = blob;
elem.download = fileName;
elem.style = 'display:none;';
elem.style = "display:none;";
(document.body || document.documentElement).appendChild(elem);
if (typeof elem.click === 'function') {
if (typeof elem.click === "function") {
elem.click();
} else {
elem.target = '_blank';
elem.dispatchEvent(new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true
}));
elem.target = "_blank";
elem.dispatchEvent(
new MouseEvent("click", {
view: window,
bubbles: true,
cancelable: true,
})
);
}
URL.revokeObjectURL(elem.href);
elem.remove()
}
elem.remove();
};
const sharing = ref(false);
async function share() {
sharing.value = true
// const canvas = await html2canvas(document.querySelector("html"));
// let anchor = document.createElement("a");
// anchor.download = "download.png";
// anchor.href = canvas.toDataURL("image/png");
// anchor.click();
// anchor.remove();
const body = document.querySelector("body")
body.classList.add("print")
const dataUrl = await toPng(body)
body.classList.remove("print")
saveAs(dataUrl, 'my-node.png')
sharing.value = false
sharing.value = true;
const body = document.querySelector("body");
body.classList.add("print");
const dataUrl = await toPng(body);
body.classList.remove("print");
saveAs(dataUrl, "my-node.png");
sharing.value = false;
}
</script>
@ -227,7 +222,7 @@ async function share() {
</svg>
</button>
<button class="btn spin no-print" v-if="sharing">
<img src="/spin.svg">
<img src="/spin.svg" />
</button>
</div>
</template>