Skip to content

Commit

Permalink
testing html2canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
marwan committed Mar 29, 2024
1 parent 8fa6833 commit 552a71f
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 10 deletions.
20 changes: 20 additions & 0 deletions public/assets/js/html2canvas.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
<link href="/assets/images/apple-touch-icon.png" rel="apple-touch-icon" />
<link rel="stylesheet" href="/assets/css/global.css" />
<link rel="stylesheet" href="/assets/css/mushaf.css" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.8.1/flowbite.min.css" rel="stylesheet" />
<script src="https://cdn.tailwindcss.com"></script>
<script defer src="/build/bundle.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.8.1/flowbite.min.css" rel="stylesheet" />
<script defer src="/assets/js/html2canvas.min.js"></script>
<!-- <script src="/preline.js"></script> -->

<!-- tailwind config -->
Expand Down
5 changes: 2 additions & 3 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@
</script>

<Router>
<div class="max-w-screen-lg mx-auto py-16 select-none {$currentPageStore === 'page' ? 'px-0 md:px-4' : 'px-4'}">
<div class="max-w-screen-lg mx-auto pt-16 pb-24 select-none {$currentPageStore === 'page' ? 'px-0 md:px-4' : 'px-4'}">
<!-- include the UI elements -->
<Navbar />
<Drawer />
<InitialSetupModal />
<AudioModal />
<BottomNavbar />
<TajweedRulingModal />
<!-- <BottomPlayer /> -->
<BottomNavbar />

<!-- components will be rendered in this div -->
<div>
Expand Down
4 changes: 3 additions & 1 deletion src/components/verses/VersesButtons.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { showAudioModal } from "$utils/audioController";
import { currentPageStore, userSettingsStore, audioSettingsStore } from "$utils/stores";
import { updateSettings } from "$utils/updateSettings";
import { disabledElement } from "$utils/commonStyles";
import { downloadVerseImage } from "$utils/downloadVerseImage";
// icons
import Bookmark from "$svgs/Bookmark.svelte";
Expand Down Expand Up @@ -45,6 +45,8 @@
<svelte:component this={$audioSettingsStore.isPlaying === true && $audioSettingsStore.playingKey === key ? Pause : Play} />
</button>

<button on:click={() => downloadVerseImage(key)}> Pic </button>

<!-- verses option dropdown -->
<!-- <div class="relative inline-block text-left">
<button data-dropdown-toggle="dropdown" class={buttonClasses} on:click={() => verseDropdownToggle()}>
Expand Down
20 changes: 20 additions & 0 deletions src/lib/html2canvas.min.js

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions src/utils/downloadVerseImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export function downloadVerseImage(key) {
html2canvas(document.getElementById(key), {
letterRendering: 1,
allowTaint: true,
useCORS: true,
})
.then(function (canvas) {
download(canvas, key);
})
.catch((e) => {
alert(e);
});
}

function download(canvas, key) {
let downloadLink = document.createElement("a");
downloadLink.setAttribute("download", `Verse ${key} - ${Date.now()}.png`);
canvas.toBlob(function (blob) {
let url = URL.createObjectURL(blob);
downloadLink.setAttribute("href", url);
downloadLink.click();
});
}
9 changes: 4 additions & 5 deletions src/views/Page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import { Link } from "svelte-routing";
import VersesWords from "$verses/VersesWords.svelte";
import Spinner from "$svgs/Spinner.svelte";
import { websiteURL } from "$data/websiteSettings";
import { currentPageStore, wordTypeStore } from "$utils/stores";
import { updateSettings } from "$utils/updateSettings";
import { quranMetaData } from "$data/quranMeta";
import { tabPillElement } from "$utils/commonStyles";
import { tabPillElement, disabledElement } from "$utils/commonStyles";
import BismillahMushaf from "$svgs/BismillahMushaf.svelte";
updateSettings({ type: "displayType", value: 4 });
Expand Down Expand Up @@ -87,15 +86,15 @@
<PageMeta title={`Page ${page}`} />

<div class="flex flex-row space-x-8 my-8 justify-center">
<Link to="/page/{+page - 1}" class={tabPillElement}>{@html "&#x2190;"} Previous Page</Link>
<Link to="/page/{+page + 1}" class={tabPillElement}>Next Page {@html "&#x2192;"}</Link>
<Link to="/page/{+page - 1}" class="{tabPillElement} {+page === 1 && disabledElement}">{@html "&#x2190;"} Previous Page</Link>
<Link to="/page/{+page + 1}" class="{tabPillElement} {+page === 604 && disabledElement}">Next Page {@html "&#x2192;"}</Link>
</div>

<div class="text-center mt-8 text-xl">
{#await fetchData}
<Spinner />
{:then}
<div class="max-w-2xl space-y-2 pb-2 mx-auto">
<div class="max-w-3xl space-y-2 pb-2 mx-auto">
{#each Array.from(Array(endingLine + 1).keys()).slice(startingLine) as line}
<!-- if it's the first verse of a chapter -->
{#if chapters.length > 1 && lines.includes(line) && verses[lines.indexOf(line)] === 1}
Expand Down

0 comments on commit 552a71f

Please sign in to comment.