Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/verse on image #399

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
eb7d499
Roughing out verseOnImage divs
Caleb-Parks Jul 13, 2023
f8af754
Fixed modal size (made fullscreen) and un-rounded corners
Caleb-Parks Jul 13, 2023
6d5f963
Reimplemented verse on image as a route rather than modal
Caleb-Parks Jul 13, 2023
bf71b3c
Renamed verse-on-image route to "image"
Caleb-Parks Jul 13, 2023
dbfa47d
Implemented scroll-snap functionality for editors.
Caleb-Parks Jul 24, 2023
e79b11e
Implemented render function, stylized, moved share button to navbar
Caleb-Parks Jul 27, 2023
372b998
Fixed uses of cnv_text and verses vars.
Caleb-Parks Jul 30, 2023
4df632e
Got text roughly working. Look into html-to-canvas next
Caleb-Parks Aug 10, 2023
20e98be
Imported html-to-image's toPng function to use in shareCanvas()
Caleb-Parks Aug 11, 2023
dfb65f0
Working on making voi text draggable. Fix bounds of draggable border …
Caleb-Parks Aug 12, 2023
fb00635
Implementing voi still. Fix textSize slider allowing too large of tex…
Caleb-Parks Aug 13, 2023
eb6e7f7
Editor 0 roughed in, 1 and 2 nearly finished. Modified slider.
Caleb-Parks Aug 13, 2023
37029ef
Fixed height and width values of various aspects of editor panes and …
Caleb-Parks Aug 14, 2023
2d7faaf
Fixed draggability of editor panes and renamed voi_textBox's dragging…
Caleb-Parks Aug 14, 2023
ce3f5c0
Cleaned up editorTabs div's scroll features, still not scrolling when…
Caleb-Parks Aug 14, 2023
b6dd208
Apply proper theme colors for voi
Caleb-Parks Aug 15, 2023
fd49749
Modify default, max, and min values of voi font size and line height …
Caleb-Parks Aug 15, 2023
a5b6a13
Add voi_textBoxHeight and make it track the height of the textbox.
Caleb-Parks Aug 15, 2023
1f409dd
Modify default, max, and min values of voi_textBoxWidth to match andr…
Caleb-Parks Aug 16, 2023
14e3bb1
Add scrollability for image picker pane, add shadow editor pane, add …
Caleb-Parks Aug 17, 2023
d097519
Finish brightness, contrast, saturation, and blur sliders. Replace si…
Caleb-Parks Aug 17, 2023
28575e0
Add editor tab and empty editor pane for font selector.
Caleb-Parks Aug 17, 2023
e85f7b6
ColorPicker working
Caleb-Parks Aug 21, 2023
4b53d62
Added more fonts and rebuilt
Caleb-Parks Aug 22, 2023
786a162
Fix voi color selector pane. Fix font selector implementation and fon…
Caleb-Parks Aug 22, 2023
9760837
Initialize initial and max font sizes; center text
chrisvire Aug 23, 2023
5dc2121
Fix icon for reference tab
chrisvire Aug 23, 2023
cc1a094
Merge pull request #1 from chrisvire/feature/verse-on-image
Caleb-Parks Aug 23, 2023
50d495f
Merge pull request #2 from chrisvire/fix/verse-on-image-reference-icon
Caleb-Parks Aug 23, 2023
de456ab
Start to implement choose image from camera roll feature.
Caleb-Parks Aug 24, 2023
ee9b15d
Continue working on image from camera roll feature.
Caleb-Parks Aug 24, 2023
f536807
Start on image cropping.
Caleb-Parks Aug 24, 2023
8dd1f4c
Continue working on image cropping.
Caleb-Parks Aug 28, 2023
bec6f06
10/5 1:08pm
Caleb-Parks Oct 5, 2023
04a5be5
End of call 10/5
Caleb-Parks Oct 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"proskomma-tools": "^0.0.5",
"rimraf": "^5",
"svelte": "^3",
"svelte-awesome-color-picker": "^2.4.7",
"svelte-check": "^3",
"svelte-eslint-parser": "^0.30",
"svelte-french-toast": "^1.0.3",
Expand All @@ -61,5 +62,8 @@
},
"volta": {
"node": "16.17.0"
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are using this, it should be in devDependencies.

"dependencies": {
"html-to-image": "^1.11.11"
}
}
187 changes: 187 additions & 0 deletions src/lib/components/CropImage.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
<svelte:options accessors={true} />

<!--
@component
The navbar component. We have sliders that update reactively to both font size and line height.
3 buttons to change the style from normal, sepia and dark.
-->
<script>
import Modal from './Modal.svelte';
import { modal, MODAL_FONT, s, t } from '$lib/data/stores';
import { onMount } from 'svelte';
import config from '$lib/data/config';

let modalId = 'imageCropper';
let modalThis;
export function showModal() {
modalThis.showModal();
}

export let data = {
applyCrop: undefined,
cnv: undefined,
selectedSrc: undefined
};
$: applyCrop = data.applyCrop;
$: main_canvas = data.cnv;
$: src = data.selectedSrc;

$: showD8ta(data);

function showD8ta(d8ta) {
console.log('D8=', d8ta);
}

let temp_img;
let temp_canvas;
let ctx;

// export let sourceX;
// export let sourceY;
// export let sourceWidth;
// export let sourceHeight;
// export let destX;
// export let destY;
// export let destWidth;
// export let destHeight;

$: render(src);

function render(i_src) {
/*DEBUG*/ console.log('Crop render called.');
if (!temp_canvas) return;
/*DEBUG*/ console.log('Crop temp_canvas == true.');
temp_img = new Image();
temp_img.src = i_src;
// Make sure the image is loaded first otherwise nothing will draw.
temp_img.onload = function () {
ctx = temp_canvas.getContext('2d');

ctx.drawImage(temp_img, 0, 0, main_canvas.width, temp_img.height); //TODO: make width canvas.width and height auto
/*DEBUG*/ console.log('Crop ctx=', ctx);
/*DEBUG*/ console.log('Crop w&h=', main_canvas.width, main_canvas.height);
/*DEBUG*/ console.log('Crop img=', temp_img);
};
}

//Chat-GPT:

let isDragging = false;
let dragStartX, dragStartY;
export let cropTop = 0;
export let cropLeft = 0;
export let cropWidth = 100; // Initial width of the square
export let cropHeight = 100; // Initial height of the square

function startDragging(event) {
isDragging = true;
const touch = event.touches[0];
dragStartX = touch.clientX;
dragStartY = touch.clientY;
}

function drag(event) {
if (isDragging) {
const touch = event.touches[0];
const deltaX = touch.clientX - dragStartX;
const deltaY = touch.clientY - dragStartY;

cropLeft += deltaX;
cropTop += deltaY;

dragStartX = touch.clientX;
dragStartY = touch.clientY;
}
}

function stopDragging() {
isDragging = false;
}

function pinch(event) {
if (event.touches.length >= 2) {
const touch1 = event.touches[0];
const touch2 = event.touches[1];

const distance = Math.sqrt(
(touch2.clientX - touch1.clientX) ** 2 + (touch2.clientY - touch1.clientY) ** 2
);

cropWidth = cropHeight = distance;
}
}

function cropImage() {
/*DBEUG*/ console.log('Crop triggered');
const ctx = temp_canvas.getContext('2d');
ctx.clearRect(0, 0, main_canvas.width, main_canvas.height);
ctx.drawImage(
temp_img,
cropLeft,
cropTop,
cropWidth,
cropHeight,
0,
0,
main_canvas.width,
main_canvas.height
);
const cropped_image = ctx.getImageData(0, 0, main_canvas.width, main_canvas.height);
/*DEBUG*/ console.log('Crop result = ', cropped_image);
createImageBitmap(cropped_image).then((croppedBitmap) => applyCrop(croppedBitmap));
}
</script>

<!-- Image Cropper -->
<Modal
bind:this={modalThis}
id={modalId}
useLabel={false}
addCSS="width: 100vw; padding: 0px;"
on:close={() => {
console.log('Crop modal closed.');
}}
><!--addCSS is a prop for injecting CSS into the modal-->
<svelte:fragment slot="content">
<div
id="crop_temp_canvas_container"
style="width: 100vw; height: 80vh; border: 5px soild green; background-color: yellow;"
>
<canvas
bind:this={temp_canvas}
width={main_canvas ? main_canvas.width : undefined}
height={main_canvas ? main_canvas.height : undefined}
style="background-color: grey;"
/>

<div
class="crop-box"
style="
position: absolute;
top: {cropTop}px;
left: {cropLeft}px;
width: {cropWidth}px;
height: {cropHeight}px;
border: 5px solid white;
"
on:touchstart={startDragging}
on:touchmove={isDragging ? drag : pinch}
on:touchend={stopDragging}
/>
</div>
<div class="w-full flex mt-4 justify-between">
<button
on:click={() => {
console.log('Crop cancel clicked.');
}}
class="dy-btn dy-btn-sm dy-btn-ghost">{$t['Button_Cancel']}</button
>
<button on:click={cropImage} class="dy-btn dy-btn-sm dy-btn-ghost"
>{$t['Button_OK']}</button
>
</div>
</svelte:fragment>
</Modal>

<style>
</style>
2 changes: 1 addition & 1 deletion src/lib/components/Slider.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ A simple slider component.

input[type='range'] {
-webkit-appearance: none;
margin-right: 15px;
/* margin-right: 15px; */
width: auto;
height: 7px;
background: var(--barColor);
Expand Down
9 changes: 7 additions & 2 deletions src/lib/components/TextSelectionToolbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ TODO:
import { shareText, shareImage } from '$lib/data/share';
import { base } from '$app/paths';
import { play, seekToVerse } from '$lib/data/audio';

const isAudioPlayable = config?.mainFeatures['text-select-play-audio'];
const isRepeatableAudio = config?.mainFeatures['audio-repeat-selection-button'];
const isTextOnImageEnabled = config?.mainFeatures['text-on-image'];
Expand Down Expand Up @@ -198,9 +199,13 @@ TODO:
</button>
{/if}
{#if isTextOnImageEnabled}
<button class="dy-btn-sm dy-btn-ghost">
<a
href="{base}/image"
class="dy-btn-sm dy-btn-ghost"
style="text-decoration:none; display:flex; align-items:center;"
>
<ImageIcon.Image color={barIconColor} />
</button>
</a>
{/if}
{#if isHighlightEnabled}
<button
Expand Down
Loading
Loading