change layout: add tool menu
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Simon Vieille 2024-04-14 19:39:47 +02:00
parent e34262f494
commit 47a2365c60
Signed by: deblan
GPG key ID: 579388D585F70417
2 changed files with 343 additions and 269 deletions

View file

@ -1,7 +1,7 @@
<template> <template>
<div class=""> <div class="">
<TopMenu /> <TopMenu />
<main class="py-6 grid grid-cols-1 gap-y-8 lg:py-12 lg:grid-cols-[1fr_2fr] lg:gap-x-20"> <main class="pt-5 grid grid-cols-1 lg:grid-cols-[1fr_2fr] lg:gap-x-20">
<RouterView /> <RouterView />
</main> </main>
</div> </div>

View file

@ -1,7 +1,40 @@
<template> <template>
<div class="md:grid md:grid-cols-12 md:col-span-12"> <div class="md:grid md:grid-cols-12 md:col-span-12">
<div class="col-span-3 flex flex-col gap-4 lg:gap-6"> <div
<div class="drop-shadow-md rounded-md md:border border-zinc-300 p-5"> class="col-span-3 lg:mr-4 tools"
ref="tools"
>
<div class="mb-2">
<button
class="p-3 mr-2 rounded"
:class="{'bg-slate-300': this.tool == 'heading'}"
@click="this.tool = 'heading'"
>Heading</button>
<button
class="p-3 mr-2 rounded"
:class="{'bg-slate-300': this.tool == 'author'}"
@click="this.tool = 'author'"
>Author</button>
<button
class="p-3 mr-2 rounded"
:class="{'bg-slate-300': this.tool == 'background'}"
@click="this.tool = 'background'"
>Background</button>
<button
class="p-3 rounded"
:class="{'bg-slate-300': this.tool == 'size'}"
@click="this.tool = 'size'"
>Size</button>
</div>
<div
:class="{hidden: this.tool !== 'heading'}"
class="drop-shadow-md rounded-md md:border border-zinc-300 tool"
>
<div class="p-5">
<div> <div>
<TextareaForm <TextareaForm
id="heading" id="heading"
@ -12,7 +45,7 @@
id="heading-size" id="heading-size"
v-model="headingSize" v-model="headingSize"
min="1" min="1"
max="10" max="20"
step="0.1" step="0.1"
/> />
</div> </div>
@ -27,7 +60,7 @@
id="subheading-size" id="subheading-size"
v-model="subheadingSize" v-model="subheadingSize"
min="1" min="1"
max="10" max="20"
step="0.1" step="0.1"
/> />
</div> </div>
@ -45,7 +78,7 @@
id="content-padding" id="content-padding"
v-model="contentPadding" v-model="contentPadding"
min="0" min="0"
max="50" max="300"
step="0.05" step="0.05"
label="Padding" label="Padding"
/> />
@ -75,8 +108,13 @@
</div> </div>
</div> </div>
</div> </div>
</div>
<div class="drop-shadow-md rounded-md md:border border-zinc-300 p-5"> <div
:class="{hidden: this.tool !== 'author'}"
class="drop-shadow-md rounded-md md:border border-zinc-300 tool"
>
<div class="p-5">
<div> <div>
<InputForm <InputForm
id="author" id="author"
@ -151,9 +189,13 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col-span-3 md:px-10 flex flex-col gap-4 lg:gap-6">
<div class="drop-shadow-md rounded-md md:border border-zinc-300 p-5"> <div
<div class="py-6"> :class="{hidden: this.tool !== 'background'}"
class="drop-shadow-md rounded-md md:border border-zinc-300 tool"
>
<div class="p-5">
<div class="pb-6">
<FileForm <FileForm
id="background" id="background"
v-model="background" v-model="background"
@ -177,12 +219,17 @@
/> />
</div> </div>
</div> </div>
<div class="drop-shadow-md rounded-md md:border border-zinc-300 p-5"> </div>
<div
:class="{hidden: this.tool !== 'size'}"
class="drop-shadow-md rounded-md md:border border-zinc-300 tool"
>
<div class="p-5">
<div> <div>
<label <label
class="block text-sm font-medium text-gray-700" class="block text-sm font-medium text-gray-700"
for="width" for="width"
>Size and quality</label> >Size</label>
<div class="grid grid-cols-2 gap-x-4"> <div class="grid grid-cols-2 gap-x-4">
<InputForm <InputForm
@ -196,21 +243,15 @@
type="number" type="number"
/> />
</div> </div>
</div>
<RangeForm
id="quality"
v-model="quality"
min="0"
max="1"
step="0.05"
/>
</div> </div>
</div> </div>
</div> </div>
<div <div
ref="ogwrapper" ref="ogwrapper"
class="col-span-6 space-y-6" class="og-wrapper col-span-9 lg:pl-10"
> >
<div class="og-wrapper-content">
<div <div
ref="og" ref="og"
class="og" class="og"
@ -218,6 +259,7 @@
> >
<div <div
class="og-image" class="og-image"
ref="ogimage"
:style="ogImageStyle()" :style="ogImageStyle()"
> >
<div <div
@ -280,8 +322,9 @@
</div> </div>
</div> </div>
</div> </div>
</div>
<div class="text-center"> <div class="text-center mt-3">
<DownloadButton <DownloadButton
class="rounded-l-md" class="rounded-l-md"
label="PNG" label="PNG"
@ -294,6 +337,8 @@
/> />
</div> </div>
</div> </div>
<div id="bottom"></div>
</div> </div>
</template> </template>
@ -322,6 +367,7 @@ export default {
}, },
data() { data() {
return { return {
tool: localStorage.getItem('tool') ?? 'heading',
author: localStorage.getItem('author'), author: localStorage.getItem('author'),
authorPadding: localStorage.getItem('authorPadding') ?? 0, authorPadding: localStorage.getItem('authorPadding') ?? 0,
authorAlign: localStorage.getItem('authorAlign') ?? 'left', authorAlign: localStorage.getItem('authorAlign') ?? 'left',
@ -343,7 +389,6 @@ export default {
subheadingSize: localStorage.getItem('subheadingSize') ?? 2, subheadingSize: localStorage.getItem('subheadingSize') ?? 2,
width: localStorage.getItem('width') ?? 1920, width: localStorage.getItem('width') ?? 1920,
height: localStorage.getItem('height') ?? 1080, height: localStorage.getItem('height') ?? 1080,
quality: localStorage.getItem('quality') ?? 0.9,
contentPadding: localStorage.getItem('contentPadding') ?? 2.5, contentPadding: localStorage.getItem('contentPadding') ?? 2.5,
allowHtml: localStorage.getItem('allowHtml'), allowHtml: localStorage.getItem('allowHtml'),
ogMaxWidth: 100, ogMaxWidth: 100,
@ -363,6 +408,9 @@ export default {
} }
}, },
watch: { watch: {
tool(value) {
localStorage.setItem('tool', value)
},
author(value) { author(value) {
localStorage.setItem('author', value) localStorage.setItem('author', value)
}, },
@ -423,9 +471,6 @@ export default {
height(value) { height(value) {
localStorage.setItem('height', value) localStorage.setItem('height', value)
}, },
quality(value) {
localStorage.setItem('quality', value)
},
contentPadding(value) { contentPadding(value) {
localStorage.setItem('contentPadding', value) localStorage.setItem('contentPadding', value)
}, },
@ -444,18 +489,25 @@ export default {
ogStyle() { ogStyle() {
return { return {
color: this.textColor, color: this.textColor,
width: `${this.width}px`,
maxWidth: `${this.ogMaxWidth}px`,
fontFamily: this.font, fontFamily: this.font,
maxHeight: `${this.ogMaxHeight}px`,
maxWidth: `${this.ogMaxWidth}px !important`,
aspectRatio: `${this.width}/${this.height}`,
} }
}, },
ogImageStyle() { ogImageStyle() {
let value = {
maxHeight: `${this.ogMaxHeight}px`,
maxWidth: `${this.ogMaxWidth}px`,
aspectRatio: `${this.width}/${this.height}`,
}
if (this.background) { if (this.background) {
return { value.background = `url(${this.background}) center`
background: `url(${this.background}) center`, value.backgroundSize = 'cover'
backgroundSize: 'cover',
}
} }
return value
}, },
ogHeadingStyle() { ogHeadingStyle() {
return { return {
@ -513,7 +565,9 @@ export default {
return { return {
background, background,
aspectRatio: `${this.width}/${this.height}` aspectRatio: `${this.width}/${this.height}`,
maxHeight: `${this.ogMaxHeight}px`,
maxWidth: `${this.ogMaxWidth}px`,
} }
}, },
ogContentStyle() { ogContentStyle() {
@ -530,12 +584,12 @@ export default {
return this.download(toJpeg, 'image.jpg') return this.download(toJpeg, 'image.jpg')
}, },
download(callback, filename) { download(callback, filename) {
const element = this.$refs.og const element = this.$refs.ogimage
callback(this.$refs.og, { callback(element, {
canvasWidth: this.width, canvasWidth: this.width,
canvasHeight: this.height, canvasHeight: this.height,
quality: this.quality, quality: 1,
}) })
.then((dataUrl) => { .then((dataUrl) => {
const link = document.createElement('a') const link = document.createElement('a')
@ -552,7 +606,8 @@ export default {
}, },
updateOgMaxWidth() { updateOgMaxWidth() {
this.$refs.og.style.display = 'none' this.$refs.og.style.display = 'none'
this.ogMaxWidth = this.$refs.ogwrapper.offsetWidth this.ogMaxWidth = this.$refs.ogwrapper.offsetWidth - 30
this.ogMaxHeight = this.$refs.tools.offsetHeight - 50
this.$refs.og.style.display = 'block' this.$refs.og.style.display = 'block'
}, },
} }
@ -560,12 +615,31 @@ export default {
</script> </script>
<style> <style>
#bottom {
position: fixed;
bottom: 0;
}
.tool {
max-height: calc(100vh - 250px);
overflow: auto;
}
.tools {
height: calc(100vh - 250px);
}
.og { .og {
background: #cecece;
max-width: 10px;
margin: auto; margin: auto;
} }
.og-wrapper-content {
background-color: #c1c1c1;
background-image: linear-gradient(45deg, #646464 25%, transparent 25%, transparent 75%, #646464 75%), linear-gradient(45deg, #646464 25%, transparent 25%, transparent 75%, #646464 75%);
background-size: 20px 20px;
background-position: 0 0, 10px 10px;
}
.og-heading { .og-heading {
font-size: 5em; font-size: 5em;
} }