feat: inital implementation
This commit is contained in:
commit
cdc144ef93
30 files changed
+6110
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
.git
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
*.log
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
APP_PORT=8080
|
||||||
|
|
||||||
|
# Host directory mounted read-only as /overlays in the nginx container.
|
||||||
|
# Edit its images and overlays.json without rebuilding the application image.
|
||||||
|
OVERLAYS_DIR=./public/overlays
|
||||||
|
|
||||||
|
# Public frontend configuration only. VITE_* values are compiled into the browser.
|
||||||
|
VITE_APP_NAME=Image Editor
|
||||||
|
VITE_OVERLAYS_CONFIG=/overlays/overlays.json
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
*.log
|
||||||
|
.DS_Store
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
FROM node:22-alpine AS build
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
FROM nginx:1.27-alpine
|
||||||
|
|
||||||
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
COPY --from=build /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
# Local Image Editor
|
||||||
|
|
||||||
|
A fast, privacy-friendly image overlay editor. Add a predefined overlay or any custom PNG, JPEG, WebP, or SVG image to a local image, then download the result at its original resolution.
|
||||||
|
|
||||||
|
Transparent PNG and SVG files retain their alpha channel while editing and when downloading a PNG. JPEG downloads are flattened because JPEG does not support transparency.
|
||||||
|
|
||||||
|
All image processing occurs in the browser. This project has no backend, database, image upload endpoint, or credentials.
|
||||||
|
|
||||||
|
The interface supports English and Portuguese. It uses the browser language by default, and the header language selector remembers the user's choice locally.
|
||||||
|
|
||||||
|
## Run locally
|
||||||
|
|
||||||
|
Requirements: Node.js 22 or newer and npm.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Open the URL printed by Vite. To create a production build:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker
|
||||||
|
|
||||||
|
Create an optional local `.env` from the public example and set a host port if needed:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cp .env.example .env
|
||||||
|
docker compose up --build
|
||||||
|
```
|
||||||
|
|
||||||
|
The application is served at `http://localhost:8080` unless `APP_PORT` is set. The production image uses nginx and can sit behind a standard reverse proxy.
|
||||||
|
|
||||||
|
Compose mounts `OVERLAYS_DIR` read-only at `/usr/share/nginx/html/overlays` in the container. It defaults to `./public/overlays`, but a deployment can point it at any host directory:
|
||||||
|
|
||||||
|
```env
|
||||||
|
OVERLAYS_DIR=/srv/local-image-editor/overlays
|
||||||
|
```
|
||||||
|
|
||||||
|
Add or replace images and edit `overlays.json` in that mounted directory without rebuilding or restarting the application container. Reload the browser after changing `overlays.json`; it is served without browser caching.
|
||||||
|
|
||||||
|
## Overlay library
|
||||||
|
|
||||||
|
Predefined overlays are loaded at runtime from `public/overlays/overlays.json`. In Docker deployments, this is the directory configured by `OVERLAYS_DIR`. To add one, place the image there and add its identifier, label, and filename to `overlays.json`. No Vue source changes or image rebuild are needed.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "example-badge",
|
||||||
|
"name": "Example badge",
|
||||||
|
"file": "example-badge.png"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration and security
|
||||||
|
|
||||||
|
`.env` is deliberately ignored by Git and Docker builds. `.env.example` contains only public values. Any variable prefixed `VITE_` is embedded into browser JavaScript and must never contain a secret.
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
services:
|
||||||
|
image-editor:
|
||||||
|
build: .
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "${APP_PORT:-8080}:80"
|
||||||
|
volumes:
|
||||||
|
# Overlay assets and their runtime configuration can change without rebuilding the image.
|
||||||
|
- "${OVERLAYS_DIR:-./public/overlays}:/usr/share/nginx/html/overlays:ro"
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<meta
|
||||||
|
name="description"
|
||||||
|
content="Create image overlays locally in your browser."
|
||||||
|
/>
|
||||||
|
<title>Local Image Editor</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script type="module" src="/src/main.ts"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
listen [::]:80;
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
# The overlay picker loads this at runtime, so changes must not be browser-cached.
|
||||||
|
location = /overlays/overlays.json {
|
||||||
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||||
|
try_files $uri =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~* \.(?:css|js|mjs|svg|png|jpe?g|webp|json|woff2?)$ {
|
||||||
|
expires 7d;
|
||||||
|
add_header Cache-Control "public";
|
||||||
|
try_files $uri =404;
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+3116
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "local-image-editor",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.1.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "vue-tsc -b && vite build",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"type-check": "vue-tsc -b"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"fabric": "^6.5.4",
|
||||||
|
"vue": "^3.5.13"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^22.10.2",
|
||||||
|
"@vitejs/plugin-vue": "^5.2.1",
|
||||||
|
"typescript": "~5.7.2",
|
||||||
|
"vite": "^6.0.5",
|
||||||
|
"vue-tsc": "^2.2.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 60 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 9.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 144 KiB |
@@ -0,0 +1,17 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "crr-logo-white-bc",
|
||||||
|
"name": "Logo CRR com fundo branco",
|
||||||
|
"file": "crr-logo-white-backgroud.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "crr-logo-sem-interior",
|
||||||
|
"name": "Logo CRR Sem Interior",
|
||||||
|
"file": "crr-logo-sem-interior.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "crr-logo-extenso",
|
||||||
|
"name": "Logo CRR Nome Completo",
|
||||||
|
"file": "crr-logo-extenso.png"
|
||||||
|
}
|
||||||
|
]
|
||||||
+111
@@ -0,0 +1,111 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
import BackgroundUpload from '@/components/BackgroundUpload.vue'
|
||||||
|
import ExportControls from '@/components/ExportControls.vue'
|
||||||
|
import ImageEditor from '@/components/ImageEditor.vue'
|
||||||
|
import OverlayControls from '@/components/OverlayControls.vue'
|
||||||
|
import OverlayPicker from '@/components/OverlayPicker.vue'
|
||||||
|
import { useLocale, type TranslationKey } from '@/composables/useLocale'
|
||||||
|
import type {
|
||||||
|
EditorHandle,
|
||||||
|
ImageDimensions,
|
||||||
|
OverlayCorner,
|
||||||
|
SelectedOverlay,
|
||||||
|
} from '@/types/editor'
|
||||||
|
|
||||||
|
const editor = ref<EditorHandle | null>(null)
|
||||||
|
const backgroundDimensions = ref<ImageDimensions | null>(null)
|
||||||
|
const selectedOverlay = ref<SelectedOverlay | null>(null)
|
||||||
|
const errorMessage = ref('')
|
||||||
|
const { locale, setLocale, t } = useLocale()
|
||||||
|
const localizedErrorKeys: Record<string, TranslationKey> = {
|
||||||
|
'unsupported-background': 'unsupportedBackground',
|
||||||
|
'unsupported-overlay': 'unsupportedOverlay',
|
||||||
|
'overlay-config-failed': 'overlayConfigFailed',
|
||||||
|
}
|
||||||
|
|
||||||
|
const imageDimensionsLabel = computed(() => {
|
||||||
|
const dimensions = backgroundDimensions.value
|
||||||
|
return dimensions ? t('imageDimensions', dimensions) : ''
|
||||||
|
})
|
||||||
|
|
||||||
|
function showError(message: string): void {
|
||||||
|
errorMessage.value = localizedErrorKeys[message] ? t(localizedErrorKeys[message]) : message
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadBackground(file: File): void {
|
||||||
|
errorMessage.value = ''
|
||||||
|
void editor.value?.loadBackground(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
function addOverlay(source: string, name: string): void {
|
||||||
|
errorMessage.value = ''
|
||||||
|
void editor.value?.addOverlay(source, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
function addCustomOverlay(file: File): void {
|
||||||
|
errorMessage.value = ''
|
||||||
|
void editor.value?.addCustomOverlay(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateOverlay(changes: Partial<Pick<SelectedOverlay, 'x' | 'y' | 'width'>>): void {
|
||||||
|
editor.value?.updateSelected(changes)
|
||||||
|
}
|
||||||
|
|
||||||
|
function positionOverlay(corner: OverlayCorner): void {
|
||||||
|
editor.value?.positionSelected(corner)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<main class="app-shell">
|
||||||
|
<header class="site-header">
|
||||||
|
<h1 class="brand">
|
||||||
|
<a href="/" :aria-label="t('homeLabel')">
|
||||||
|
<span class="brand-mark" aria-hidden="true"><i></i><i></i><i></i></span>
|
||||||
|
<span>{{ t('appName') }}</span>
|
||||||
|
</a>
|
||||||
|
</h1>
|
||||||
|
<div class="header-tools">
|
||||||
|
<label class="language-picker">
|
||||||
|
<span class="sr-only">{{ t('languageLabel') }}</span>
|
||||||
|
<select :value="locale" :aria-label="t('languageLabel')" @change="setLocale(($event.target as HTMLSelectElement).value as 'en' | 'pt')">
|
||||||
|
<option value="en">{{ t('english') }}</option>
|
||||||
|
<option value="pt">{{ t('portuguese') }}</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<p class="privacy-notice">{{ t('privacyNotice') }}</p>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<p v-if="errorMessage" class="error-notice" role="alert">
|
||||||
|
{{ errorMessage }}
|
||||||
|
<button type="button" :aria-label="t('dismissError')" @click="errorMessage = ''">x</button>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="workspace">
|
||||||
|
<aside class="control-column">
|
||||||
|
<BackgroundUpload :t="t" @select="loadBackground" @error="showError" />
|
||||||
|
<p v-if="imageDimensionsLabel" class="image-dimensions">{{ imageDimensionsLabel }}</p>
|
||||||
|
<OverlayPicker :t="t" @add="addOverlay" @custom="addCustomOverlay" @error="showError" />
|
||||||
|
<OverlayControls
|
||||||
|
:selected="selectedOverlay"
|
||||||
|
:t="t"
|
||||||
|
@update="updateOverlay"
|
||||||
|
@position="positionOverlay"
|
||||||
|
@remove="editor?.removeSelected()"
|
||||||
|
/>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<ImageEditor
|
||||||
|
ref="editor"
|
||||||
|
:t="t"
|
||||||
|
@background-change="backgroundDimensions = $event"
|
||||||
|
@selection-change="selectedOverlay = $event"
|
||||||
|
@error="showError"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ExportControls :enabled="Boolean(backgroundDimensions)" :t="t" @export="editor?.exportImage($event)" />
|
||||||
|
</main>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import type { Translate } from '@/composables/useLocale'
|
||||||
|
|
||||||
|
defineProps<{ t: Translate }>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
select: [file: File]
|
||||||
|
error: [message: string]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const isDragging = ref(false)
|
||||||
|
const acceptedTypes = new Set(['image/png', 'image/jpeg', 'image/webp', 'image/svg+xml'])
|
||||||
|
|
||||||
|
function emitFile(file: File | undefined): void {
|
||||||
|
if (!file) return
|
||||||
|
if (!acceptedTypes.has(file.type)) {
|
||||||
|
emit('error', 'unsupported-background')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
emit('select', file)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onInput(event: Event): void {
|
||||||
|
emitFile((event.target as HTMLInputElement).files?.[0])
|
||||||
|
;(event.target as HTMLInputElement).value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDrop(event: DragEvent): void {
|
||||||
|
isDragging.value = false
|
||||||
|
emitFile(event.dataTransfer?.files[0])
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="panel upload-panel" aria-labelledby="background-title">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<span class="step-number">01</span>
|
||||||
|
<div>
|
||||||
|
<p class="eyebrow">{{ t('baseLayer') }}</p>
|
||||||
|
<h2 id="background-title">{{ t('chooseImage') }}</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<label
|
||||||
|
class="dropzone"
|
||||||
|
:class="{ 'dropzone--active': isDragging }"
|
||||||
|
@dragenter.prevent="isDragging = true"
|
||||||
|
@dragover.prevent="isDragging = true"
|
||||||
|
@dragleave.prevent="isDragging = false"
|
||||||
|
@drop.prevent="onDrop"
|
||||||
|
>
|
||||||
|
<input type="file" accept="image/png,image/jpeg,image/webp,image/svg+xml,.svg" @change="onInput" />
|
||||||
|
<span class="dropzone-icon" aria-hidden="true">↑</span>
|
||||||
|
<span><strong>{{ t('uploadImage') }}</strong> {{ t('dropImage') }}</span>
|
||||||
|
<small>{{ t('supportedFormats') }}</small>
|
||||||
|
</label>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { Translate } from '@/composables/useLocale'
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
enabled: boolean
|
||||||
|
t: Translate
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
export: [format: 'png' | 'jpeg']
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="export-panel" :aria-label="t('downloadImage')">
|
||||||
|
<div>
|
||||||
|
<p class="eyebrow">{{ t('readyWhenYouAre') }}</p>
|
||||||
|
<h2>{{ t('downloadImage') }}</h2>
|
||||||
|
<p>{{ t('originalDimensions') }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="export-actions">
|
||||||
|
<button class="button button--primary" type="button" :disabled="!enabled" @click="emit('export', 'png')">{{ t('downloadPng') }}</button>
|
||||||
|
<button class="button button--dark" type="button" :disabled="!enabled" @click="emit('export', 'jpeg')">{{ t('downloadJpeg') }}</button>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { nextTick, onMounted, onUnmounted, ref } from 'vue'
|
||||||
|
import { useFabricEditor } from '@/composables/useFabricEditor'
|
||||||
|
import type { Translate } from '@/composables/useLocale'
|
||||||
|
import type { EditorHandle, ImageDimensions, SelectedOverlay } from '@/types/editor'
|
||||||
|
|
||||||
|
defineProps<{ t: Translate }>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
backgroundChange: [dimensions: ImageDimensions | null]
|
||||||
|
selectionChange: [overlay: SelectedOverlay | null]
|
||||||
|
error: [message: string]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const canvasElement = ref<HTMLCanvasElement | null>(null)
|
||||||
|
const canvasShell = ref<HTMLElement | null>(null)
|
||||||
|
const displayWidth = ref(0)
|
||||||
|
const displayHeight = ref(0)
|
||||||
|
const dimensions = ref<ImageDimensions | null>(null)
|
||||||
|
|
||||||
|
function updateDisplaySize(): void {
|
||||||
|
if (!canvasShell.value || !dimensions.value) {
|
||||||
|
displayWidth.value = 0
|
||||||
|
displayHeight.value = 0
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const availableWidth = canvasShell.value.clientWidth
|
||||||
|
const scale = Math.min(1, availableWidth / dimensions.value.width)
|
||||||
|
displayWidth.value = Math.floor(dimensions.value.width * scale)
|
||||||
|
displayHeight.value = Math.floor(dimensions.value.height * scale)
|
||||||
|
editor.resizeDisplay(displayWidth.value, displayHeight.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const editor = useFabricEditor({
|
||||||
|
canvasElement: () => canvasElement.value,
|
||||||
|
onBackgroundChange: (nextDimensions) => {
|
||||||
|
dimensions.value = nextDimensions
|
||||||
|
nextTick(updateDisplaySize)
|
||||||
|
emit('backgroundChange', nextDimensions)
|
||||||
|
},
|
||||||
|
onSelectionChange: (overlay) => emit('selectionChange', overlay),
|
||||||
|
onError: (message) => emit('error', message),
|
||||||
|
})
|
||||||
|
|
||||||
|
function onResize(): void {
|
||||||
|
updateDisplaySize()
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
window.addEventListener('resize', onResize)
|
||||||
|
updateDisplaySize()
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
window.removeEventListener('resize', onResize)
|
||||||
|
})
|
||||||
|
|
||||||
|
defineExpose<EditorHandle>(editor)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="editor-region" :aria-label="t('imageEditor')">
|
||||||
|
<div ref="canvasShell" class="canvas-shell" :class="{ 'canvas-shell--empty': !dimensions }">
|
||||||
|
<div v-if="!dimensions" class="editor-empty">
|
||||||
|
<span class="empty-mark" aria-hidden="true">+</span>
|
||||||
|
<p>{{ t('imageAppearsHere') }}</p>
|
||||||
|
<small>{{ t('uploadToBegin') }}</small>
|
||||||
|
</div>
|
||||||
|
<canvas
|
||||||
|
ref="canvasElement"
|
||||||
|
class="editor-canvas"
|
||||||
|
:style="dimensions ? { width: `${displayWidth}px`, height: `${displayHeight}px` } : undefined"
|
||||||
|
:aria-label="t('canvasLabel')"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { OverlayCorner, SelectedOverlay } from '@/types/editor'
|
||||||
|
import type { Translate } from '@/composables/useLocale'
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
selected: SelectedOverlay | null
|
||||||
|
t: Translate
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
update: [changes: Partial<Pick<SelectedOverlay, 'x' | 'y' | 'width'>>]
|
||||||
|
position: [corner: OverlayCorner]
|
||||||
|
remove: []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
function updateNumber(field: 'x' | 'y' | 'width', event: Event): void {
|
||||||
|
const input = event.target as HTMLInputElement
|
||||||
|
const value = Number(input.value)
|
||||||
|
if (input.value.trim() && Number.isFinite(value)) emit('update', { [field]: value })
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="panel controls-panel" aria-labelledby="controls-title">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<span class="step-number">03</span>
|
||||||
|
<div>
|
||||||
|
<p class="eyebrow">{{ t('fineTune') }}</p>
|
||||||
|
<h2 id="controls-title">{{ t('selectedElement') }}</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<template v-if="selected">
|
||||||
|
<p class="selected-name">{{ selected.name }}</p>
|
||||||
|
<div class="coordinate-grid">
|
||||||
|
<label>
|
||||||
|
<span>{{ t('xPosition') }}</span>
|
||||||
|
<span class="number-input"><input type="number" step="1" :value="selected.x" @input="updateNumber('x', $event)" /><em>px</em></span>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>{{ t('yPosition') }}</span>
|
||||||
|
<span class="number-input"><input type="number" step="1" :value="selected.y" @input="updateNumber('y', $event)" /><em>px</em></span>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>{{ t('width') }}</span>
|
||||||
|
<span class="number-input"><input type="number" min="12" step="1" :value="selected.width" @input="updateNumber('width', $event)" /><em>px</em></span>
|
||||||
|
</label>
|
||||||
|
<div class="calculated-size" aria-label="Calculated overlay height">
|
||||||
|
<span>{{ t('height') }}</span>
|
||||||
|
<strong>{{ selected.height }} px</strong>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="quick-position" aria-label="Quick position">
|
||||||
|
<span>{{ t('quickPosition') }}</span>
|
||||||
|
<div class="corner-buttons">
|
||||||
|
<button type="button" :aria-label="t('topLeft')" :title="t('topLeft')" @click="emit('position', 'top-left')">TL</button>
|
||||||
|
<button type="button" :aria-label="t('topRight')" :title="t('topRight')" @click="emit('position', 'top-right')">TR</button>
|
||||||
|
<button type="button" :aria-label="t('bottomLeft')" :title="t('bottomLeft')" @click="emit('position', 'bottom-left')">BL</button>
|
||||||
|
<button type="button" :aria-label="t('bottomRight')" :title="t('bottomRight')" @click="emit('position', 'bottom-right')">BR</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button class="button button--danger" type="button" @click="emit('remove')">{{ t('removeElement') }}</button>
|
||||||
|
</template>
|
||||||
|
<p v-else class="control-empty">{{ t('selectOverlay') }}</p>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, onMounted, ref } from 'vue'
|
||||||
|
import type { Translate } from '@/composables/useLocale'
|
||||||
|
import type { OverlayLibraryItem } from '@/types/editor'
|
||||||
|
|
||||||
|
defineProps<{ t: Translate }>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
add: [source: string, name: string]
|
||||||
|
custom: [file: File]
|
||||||
|
error: [message: string]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const items = ref<OverlayLibraryItem[]>([])
|
||||||
|
const selectedId = ref('')
|
||||||
|
const isLoading = ref(true)
|
||||||
|
const configPath = import.meta.env.VITE_OVERLAYS_CONFIG || '/overlays/overlays.json'
|
||||||
|
const selectedItem = computed(() => items.value.find((item) => item.id === selectedId.value))
|
||||||
|
const acceptedTypes = new Set(['image/png', 'image/jpeg', 'image/webp', 'image/svg+xml'])
|
||||||
|
|
||||||
|
function isValidItem(value: unknown): value is OverlayLibraryItem {
|
||||||
|
if (!value || typeof value !== 'object') return false
|
||||||
|
const item = value as Record<string, unknown>
|
||||||
|
return typeof item.id === 'string' && typeof item.name === 'string' && typeof item.file === 'string'
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadItems(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const response = await fetch(configPath)
|
||||||
|
if (!response.ok) throw new Error()
|
||||||
|
const config: unknown = await response.json()
|
||||||
|
if (!Array.isArray(config) || !config.every(isValidItem)) throw new Error()
|
||||||
|
items.value = config
|
||||||
|
selectedId.value = config[0]?.id ?? ''
|
||||||
|
} catch {
|
||||||
|
emit('error', 'overlay-config-failed')
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addSelected(): void {
|
||||||
|
const item = selectedItem.value
|
||||||
|
if (!item) return
|
||||||
|
const basePath = configPath.slice(0, configPath.lastIndexOf('/') + 1)
|
||||||
|
const source = `${basePath}${item.file}`
|
||||||
|
emit('add', source, item.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onCustomInput(event: Event): void {
|
||||||
|
const input = event.target as HTMLInputElement
|
||||||
|
const file = input.files?.[0]
|
||||||
|
input.value = ''
|
||||||
|
if (!file) return
|
||||||
|
if (!acceptedTypes.has(file.type)) {
|
||||||
|
emit('error', 'unsupported-overlay')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
emit('custom', file)
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(loadItems)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="panel" aria-labelledby="overlay-title">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<span class="step-number">02</span>
|
||||||
|
<div>
|
||||||
|
<p class="eyebrow">{{ t('topLayer') }}</p>
|
||||||
|
<h2 id="overlay-title">{{ t('addOverlay') }}</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field-group">
|
||||||
|
<label for="library-overlay">{{ t('overlayLibrary') }}</label>
|
||||||
|
<select id="library-overlay" v-model="selectedId" :disabled="isLoading || !items.length">
|
||||||
|
<option v-if="!items.length" value="">{{ t('noOverlays') }}</option>
|
||||||
|
<option v-for="item in items" :key="item.id" :value="item.id">{{ item.name }}</option>
|
||||||
|
</select>
|
||||||
|
<button class="button button--secondary" type="button" :disabled="!selectedItem" @click="addSelected">
|
||||||
|
{{ t('addSelectedOverlay') }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="panel-divider"><span>{{ t('or') }}</span></div>
|
||||||
|
<label class="button button--outline upload-button">
|
||||||
|
<input type="file" accept="image/png,image/jpeg,image/webp,image/svg+xml,.svg" @change="onCustomInput" />
|
||||||
|
{{ t('uploadCustomImage') }}
|
||||||
|
</label>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,379 @@
|
|||||||
|
import { Canvas, FabricImage, type FabricObject } from 'fabric'
|
||||||
|
import { nextTick, onBeforeUnmount, ref, shallowRef } from 'vue'
|
||||||
|
import { useLocale } from '@/composables/useLocale'
|
||||||
|
import type {
|
||||||
|
EditorHandle,
|
||||||
|
ImageDimensions,
|
||||||
|
OverlayCorner,
|
||||||
|
SelectedOverlay,
|
||||||
|
} from '@/types/editor'
|
||||||
|
|
||||||
|
const ACCEPTED_IMAGE_TYPES = new Set(['image/png', 'image/jpeg', 'image/webp', 'image/svg+xml'])
|
||||||
|
const MIN_OVERLAY_WIDTH = 12
|
||||||
|
|
||||||
|
type OverlayFabricObject = FabricImage & {
|
||||||
|
overlayId: string
|
||||||
|
overlayName: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface UseFabricEditorOptions {
|
||||||
|
canvasElement: () => HTMLCanvasElement | null
|
||||||
|
onBackgroundChange: (dimensions: ImageDimensions | null) => void
|
||||||
|
onSelectionChange: (overlay: SelectedOverlay | null) => void
|
||||||
|
onError: (message: string) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
function rounded(value: number): number {
|
||||||
|
return Math.round(Number.isFinite(value) ? value : 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
function isSupportedImage(file: File): boolean {
|
||||||
|
return ACCEPTED_IMAGE_TYPES.has(file.type)
|
||||||
|
}
|
||||||
|
|
||||||
|
function isOverlay(object: FabricObject | null | undefined): object is OverlayFabricObject {
|
||||||
|
return Boolean(object && 'overlayId' in object && 'overlayName' in object)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useFabricEditor(options: UseFabricEditorOptions): EditorHandle {
|
||||||
|
const { t } = useLocale()
|
||||||
|
const canvas = shallowRef<Canvas | null>(null)
|
||||||
|
const backgroundDimensions = ref<ImageDimensions | null>(null)
|
||||||
|
let selectedOverlay: OverlayFabricObject | null = null
|
||||||
|
|
||||||
|
function reportError(message: string): void {
|
||||||
|
options.onError(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCanvas(): Canvas | null {
|
||||||
|
if (!canvas.value) {
|
||||||
|
reportError(t('editorLoading'))
|
||||||
|
}
|
||||||
|
|
||||||
|
return canvas.value
|
||||||
|
}
|
||||||
|
|
||||||
|
function getScaledWidth(object: FabricObject): number {
|
||||||
|
return object.getScaledWidth()
|
||||||
|
}
|
||||||
|
|
||||||
|
function getScaledHeight(object: FabricObject): number {
|
||||||
|
return object.getScaledHeight()
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectedDetails(object: OverlayFabricObject): SelectedOverlay {
|
||||||
|
return {
|
||||||
|
id: object.overlayId,
|
||||||
|
name: object.overlayName,
|
||||||
|
x: rounded(object.left ?? 0),
|
||||||
|
y: rounded(object.top ?? 0),
|
||||||
|
width: rounded(getScaledWidth(object)),
|
||||||
|
height: rounded(getScaledHeight(object)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function publishSelection(object: FabricObject | undefined | null): void {
|
||||||
|
if (!isOverlay(object)) {
|
||||||
|
selectedOverlay = null
|
||||||
|
options.onSelectionChange(null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedOverlay = object
|
||||||
|
options.onSelectionChange(selectedDetails(object))
|
||||||
|
}
|
||||||
|
|
||||||
|
function clampOverlay(object: OverlayFabricObject): void {
|
||||||
|
const dimensions = backgroundDimensions.value
|
||||||
|
if (!dimensions || !object.width || !object.height) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overlays cannot exceed the image, and scaling is always uniform.
|
||||||
|
const maximumScale = Math.min(
|
||||||
|
dimensions.width / object.width,
|
||||||
|
dimensions.height / object.height,
|
||||||
|
)
|
||||||
|
const minimumScale = Math.min(MIN_OVERLAY_WIDTH / object.width, maximumScale)
|
||||||
|
const requestedScale = Math.max(object.scaleX ?? 1, object.scaleY ?? 1, minimumScale)
|
||||||
|
const scale = Math.min(requestedScale, maximumScale)
|
||||||
|
|
||||||
|
object.set({ scaleX: scale, scaleY: scale })
|
||||||
|
object.setCoords()
|
||||||
|
|
||||||
|
const width = getScaledWidth(object)
|
||||||
|
const height = getScaledHeight(object)
|
||||||
|
object.set({
|
||||||
|
left: Math.min(Math.max(object.left ?? 0, 0), Math.max(0, dimensions.width - width)),
|
||||||
|
top: Math.min(Math.max(object.top ?? 0, 0), Math.max(0, dimensions.height - height)),
|
||||||
|
})
|
||||||
|
object.setCoords()
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateAfterTransform(target: FabricObject): void {
|
||||||
|
if (!isOverlay(target)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
clampOverlay(target)
|
||||||
|
publishSelection(target)
|
||||||
|
canvas.value?.requestRenderAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
function initializeCanvas(): void {
|
||||||
|
const element = options.canvasElement()
|
||||||
|
if (!element || canvas.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const fabricCanvas = new Canvas(element, {
|
||||||
|
preserveObjectStacking: true,
|
||||||
|
selection: false,
|
||||||
|
uniformScaling: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
fabricCanvas.on('selection:created', ({ selected }) => publishSelection(selected[0]))
|
||||||
|
fabricCanvas.on('selection:updated', ({ selected }) => publishSelection(selected[0]))
|
||||||
|
fabricCanvas.on('selection:cleared', () => publishSelection(null))
|
||||||
|
fabricCanvas.on('object:moving', ({ target }) => {
|
||||||
|
if (target) updateAfterTransform(target)
|
||||||
|
})
|
||||||
|
fabricCanvas.on('object:scaling', ({ target }) => {
|
||||||
|
if (target) updateAfterTransform(target)
|
||||||
|
})
|
||||||
|
fabricCanvas.on('object:modified', ({ target }) => {
|
||||||
|
if (target) updateAfterTransform(target)
|
||||||
|
})
|
||||||
|
|
||||||
|
canvas.value = fabricCanvas
|
||||||
|
}
|
||||||
|
|
||||||
|
function resizeDisplay(width: number, height: number): void {
|
||||||
|
if (!canvas.value || !width || !height) return
|
||||||
|
canvas.value.setDimensions({ width, height }, { cssOnly: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadImage(source: string): Promise<FabricImage> {
|
||||||
|
try {
|
||||||
|
return await FabricImage.fromURL(source)
|
||||||
|
} catch {
|
||||||
|
throw new Error(t('decodeImage'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function verifyHostedOverlay(source: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
const response = await fetch(source)
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error()
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
throw new Error(t('predefinedOverlayFailed'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadBackground(file: File): Promise<void> {
|
||||||
|
if (!isSupportedImage(file)) {
|
||||||
|
reportError(t('unsupportedBackground'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const fabricCanvas = getCanvas()
|
||||||
|
if (!fabricCanvas) return
|
||||||
|
|
||||||
|
const source = URL.createObjectURL(file)
|
||||||
|
try {
|
||||||
|
const image = await loadImage(source)
|
||||||
|
const width = image.width ?? 0
|
||||||
|
const height = image.height ?? 0
|
||||||
|
if (!width || !height) {
|
||||||
|
throw new Error(t('invalidBackgroundDimensions'))
|
||||||
|
}
|
||||||
|
|
||||||
|
fabricCanvas.clear()
|
||||||
|
fabricCanvas.setDimensions({ width, height })
|
||||||
|
fabricCanvas.backgroundImage = image
|
||||||
|
image.set({
|
||||||
|
left: 0,
|
||||||
|
top: 0,
|
||||||
|
originX: 'left',
|
||||||
|
originY: 'top',
|
||||||
|
scaleX: 1,
|
||||||
|
scaleY: 1,
|
||||||
|
selectable: false,
|
||||||
|
evented: false,
|
||||||
|
})
|
||||||
|
image.setCoords()
|
||||||
|
|
||||||
|
backgroundDimensions.value = { width, height }
|
||||||
|
selectedOverlay = null
|
||||||
|
fabricCanvas.requestRenderAll()
|
||||||
|
options.onBackgroundChange(backgroundDimensions.value)
|
||||||
|
options.onSelectionChange(null)
|
||||||
|
} catch (error) {
|
||||||
|
reportError(error instanceof Error ? error.message : t('backgroundLoadFailed'))
|
||||||
|
} finally {
|
||||||
|
URL.revokeObjectURL(source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addOverlay(source: string, name: string): Promise<void> {
|
||||||
|
const fabricCanvas = getCanvas()
|
||||||
|
const dimensions = backgroundDimensions.value
|
||||||
|
if (!fabricCanvas || !dimensions) {
|
||||||
|
reportError(t('uploadBackgroundFirst'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!source.startsWith('blob:')) {
|
||||||
|
await verifyHostedOverlay(source)
|
||||||
|
}
|
||||||
|
const overlay = (await loadImage(source)) as OverlayFabricObject
|
||||||
|
if (!overlay.width || !overlay.height) {
|
||||||
|
throw new Error(t('invalidOverlayDimensions'))
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetWidth = Math.min(dimensions.width * 0.22, dimensions.width)
|
||||||
|
const scale = targetWidth / overlay.width
|
||||||
|
const id = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random()}`
|
||||||
|
Object.assign(overlay, { overlayId: id, overlayName: name })
|
||||||
|
overlay.set({
|
||||||
|
left: dimensions.width - targetWidth - dimensions.width * 0.025,
|
||||||
|
top: dimensions.width * 0.025,
|
||||||
|
originX: 'left',
|
||||||
|
originY: 'top',
|
||||||
|
scaleX: scale,
|
||||||
|
scaleY: scale,
|
||||||
|
selectable: true,
|
||||||
|
evented: true,
|
||||||
|
lockRotation: true,
|
||||||
|
lockUniScaling: true,
|
||||||
|
lockScalingFlip: true,
|
||||||
|
lockSkewingX: true,
|
||||||
|
lockSkewingY: true,
|
||||||
|
})
|
||||||
|
overlay.setControlsVisibility({
|
||||||
|
mtr: false,
|
||||||
|
ml: false,
|
||||||
|
mr: false,
|
||||||
|
mt: false,
|
||||||
|
mb: false,
|
||||||
|
})
|
||||||
|
clampOverlay(overlay)
|
||||||
|
fabricCanvas.add(overlay)
|
||||||
|
fabricCanvas.setActiveObject(overlay)
|
||||||
|
updateAfterTransform(overlay)
|
||||||
|
} catch (error) {
|
||||||
|
reportError(error instanceof Error ? error.message : t('overlayLoadFailed'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addCustomOverlay(file: File): Promise<void> {
|
||||||
|
if (!isSupportedImage(file)) {
|
||||||
|
reportError(t('unsupportedOverlay'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const source = URL.createObjectURL(file)
|
||||||
|
try {
|
||||||
|
await addOverlay(source, file.name)
|
||||||
|
} finally {
|
||||||
|
URL.revokeObjectURL(source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateSelected(changes: Partial<Pick<SelectedOverlay, 'x' | 'y' | 'width'>>): void {
|
||||||
|
if (!selectedOverlay || !backgroundDimensions.value) return
|
||||||
|
|
||||||
|
const object = selectedOverlay
|
||||||
|
const updates: Partial<OverlayFabricObject> = {}
|
||||||
|
if (typeof changes.x === 'number' && Number.isFinite(changes.x)) {
|
||||||
|
updates.left = rounded(changes.x)
|
||||||
|
}
|
||||||
|
if (typeof changes.y === 'number' && Number.isFinite(changes.y)) {
|
||||||
|
updates.top = rounded(changes.y)
|
||||||
|
}
|
||||||
|
if (typeof changes.width === 'number' && Number.isFinite(changes.width) && object.width) {
|
||||||
|
const width = Math.max(MIN_OVERLAY_WIDTH, rounded(changes.width))
|
||||||
|
const scale = width / object.width
|
||||||
|
updates.scaleX = scale
|
||||||
|
updates.scaleY = scale
|
||||||
|
}
|
||||||
|
|
||||||
|
object.set(updates)
|
||||||
|
updateAfterTransform(object)
|
||||||
|
}
|
||||||
|
|
||||||
|
function positionSelected(corner: OverlayCorner): void {
|
||||||
|
const dimensions = backgroundDimensions.value
|
||||||
|
if (!selectedOverlay || !dimensions) return
|
||||||
|
|
||||||
|
const margin = dimensions.width * 0.025
|
||||||
|
const width = getScaledWidth(selectedOverlay)
|
||||||
|
const height = getScaledHeight(selectedOverlay)
|
||||||
|
const isRight = corner === 'top-right' || corner === 'bottom-right'
|
||||||
|
const isBottom = corner === 'bottom-left' || corner === 'bottom-right'
|
||||||
|
|
||||||
|
selectedOverlay.set({
|
||||||
|
left: isRight ? dimensions.width - width - margin : margin,
|
||||||
|
top: isBottom ? dimensions.height - height - margin : margin,
|
||||||
|
})
|
||||||
|
updateAfterTransform(selectedOverlay)
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeSelected(): void {
|
||||||
|
if (!selectedOverlay || !canvas.value) return
|
||||||
|
|
||||||
|
canvas.value.remove(selectedOverlay)
|
||||||
|
selectedOverlay = null
|
||||||
|
options.onSelectionChange(null)
|
||||||
|
canvas.value.requestRenderAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
function exportImage(format: 'png' | 'jpeg'): void {
|
||||||
|
const fabricCanvas = getCanvas()
|
||||||
|
if (!fabricCanvas || !backgroundDimensions.value) {
|
||||||
|
reportError(t('uploadBackgroundBeforeExport'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const activeObject = fabricCanvas.getActiveObject()
|
||||||
|
fabricCanvas.discardActiveObject()
|
||||||
|
fabricCanvas.requestRenderAll()
|
||||||
|
|
||||||
|
const dataUrl = fabricCanvas.toDataURL({
|
||||||
|
format,
|
||||||
|
quality: format === 'jpeg' ? 0.95 : 1,
|
||||||
|
multiplier: 1,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (activeObject) {
|
||||||
|
fabricCanvas.setActiveObject(activeObject)
|
||||||
|
}
|
||||||
|
fabricCanvas.requestRenderAll()
|
||||||
|
|
||||||
|
const link = document.createElement('a')
|
||||||
|
link.href = dataUrl
|
||||||
|
link.download = `${t('downloadFilename')}-${new Date().toISOString().slice(0, 10)}.${format === 'jpeg' ? 'jpg' : 'png'}`
|
||||||
|
link.click()
|
||||||
|
}
|
||||||
|
|
||||||
|
void nextTick(initializeCanvas)
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
canvas.value?.dispose()
|
||||||
|
canvas.value = null
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
resizeDisplay,
|
||||||
|
loadBackground,
|
||||||
|
addOverlay,
|
||||||
|
addCustomOverlay,
|
||||||
|
updateSelected,
|
||||||
|
positionSelected,
|
||||||
|
removeSelected,
|
||||||
|
exportImage,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
import { ref, watch } from 'vue'
|
||||||
|
|
||||||
|
export type Locale = 'en' | 'pt'
|
||||||
|
|
||||||
|
export type TranslationKey = keyof typeof translations.en
|
||||||
|
export type Translate = (key: TranslationKey, values?: Record<string, string | number>) => string
|
||||||
|
|
||||||
|
const translations = {
|
||||||
|
en: {
|
||||||
|
appName: 'Local Image Editor',
|
||||||
|
homeLabel: 'Local Image Editor home',
|
||||||
|
privacyNotice: 'Images are processed locally in your browser and are not uploaded to the server.',
|
||||||
|
languageLabel: 'Language',
|
||||||
|
english: 'English',
|
||||||
|
portuguese: 'Portuguese',
|
||||||
|
dismissError: 'Dismiss error',
|
||||||
|
imageDimensions: 'Image: {width} x {height} px',
|
||||||
|
baseLayer: 'Base layer',
|
||||||
|
chooseImage: 'Choose your image',
|
||||||
|
uploadImage: 'Upload an image',
|
||||||
|
dropImage: 'or drop it here',
|
||||||
|
supportedFormats: 'PNG, JPEG, WebP, or SVG',
|
||||||
|
topLayer: 'Top layer',
|
||||||
|
addOverlay: 'Add an overlay',
|
||||||
|
overlayLibrary: 'Overlay library',
|
||||||
|
noOverlays: 'No overlays available',
|
||||||
|
addSelectedOverlay: 'Add selected overlay',
|
||||||
|
or: 'or',
|
||||||
|
uploadCustomImage: 'Upload custom image',
|
||||||
|
fineTune: 'Fine tune',
|
||||||
|
selectedElement: 'Selected element',
|
||||||
|
xPosition: 'X position',
|
||||||
|
yPosition: 'Y position',
|
||||||
|
width: 'Width',
|
||||||
|
height: 'Height',
|
||||||
|
quickPosition: 'Quick position',
|
||||||
|
topLeft: 'Position top left',
|
||||||
|
topRight: 'Position top right',
|
||||||
|
bottomLeft: 'Position bottom left',
|
||||||
|
bottomRight: 'Position bottom right',
|
||||||
|
removeElement: 'Remove element',
|
||||||
|
selectOverlay: 'Select an overlay on the canvas to adjust its position and size.',
|
||||||
|
imageEditor: 'Image editor',
|
||||||
|
canvasLabel: 'Canvas for positioning image overlays',
|
||||||
|
imageAppearsHere: 'Your image will appear here.',
|
||||||
|
uploadToBegin: 'Upload a PNG, JPEG, WebP, or SVG to begin.',
|
||||||
|
readyWhenYouAre: 'Ready when you are',
|
||||||
|
downloadImage: 'Download your image',
|
||||||
|
originalDimensions: "Exports retain your source image's original dimensions.",
|
||||||
|
downloadPng: 'Download PNG',
|
||||||
|
downloadJpeg: 'Download JPEG',
|
||||||
|
editorLoading: 'The editor is still loading. Please try again.',
|
||||||
|
decodeImage: 'The image could not be decoded. Choose a valid PNG, JPEG, WebP, or SVG image.',
|
||||||
|
predefinedOverlayFailed: 'This predefined overlay could not be loaded. Check that its filename in overlays.json exactly matches the file in public/overlays/.',
|
||||||
|
unsupportedBackground: 'Choose a PNG, JPEG, WebP, or SVG image for the background.',
|
||||||
|
invalidBackgroundDimensions: 'The background image has invalid dimensions.',
|
||||||
|
backgroundLoadFailed: 'The background could not be loaded.',
|
||||||
|
uploadBackgroundFirst: 'Upload a background image before adding an overlay.',
|
||||||
|
invalidOverlayDimensions: 'The overlay image has invalid dimensions.',
|
||||||
|
overlayLoadFailed: 'The overlay could not be loaded.',
|
||||||
|
unsupportedOverlay: 'Choose a PNG, JPEG, WebP, or SVG image for the overlay.',
|
||||||
|
uploadBackgroundBeforeExport: 'Upload a background image before exporting.',
|
||||||
|
overlayConfigFailed: 'The predefined overlay library could not be loaded. You can still upload a custom overlay.',
|
||||||
|
downloadFilename: 'local-image',
|
||||||
|
},
|
||||||
|
pt: {
|
||||||
|
appName: 'Editor de Imagens Local',
|
||||||
|
homeLabel: 'Pagina inicial do Editor de Imagens Local',
|
||||||
|
privacyNotice: 'As imagens são processadas localmente no seu navegador e não são enviadas para o servidor.',
|
||||||
|
languageLabel: 'Idioma',
|
||||||
|
english: 'Inglês',
|
||||||
|
portuguese: 'Português',
|
||||||
|
dismissError: 'Fechar erro',
|
||||||
|
imageDimensions: 'Imagem: {width} x {height} px',
|
||||||
|
baseLayer: 'Camada de base',
|
||||||
|
chooseImage: 'Escolha a sua imagem',
|
||||||
|
uploadImage: 'Carregar imagem',
|
||||||
|
dropImage: 'ou largue-a aqui',
|
||||||
|
supportedFormats: 'PNG, JPEG, WebP ou SVG',
|
||||||
|
topLayer: 'Camada superior',
|
||||||
|
addOverlay: 'Adicionar sobreposicao',
|
||||||
|
overlayLibrary: 'Biblioteca de sobreposicoes',
|
||||||
|
noOverlays: 'Não há sobreposições disponíveis',
|
||||||
|
addSelectedOverlay: 'Adicionar sobreposição selecionada',
|
||||||
|
or: 'ou',
|
||||||
|
uploadCustomImage: 'Carregar imagem personalizada',
|
||||||
|
fineTune: 'Ajuste preciso',
|
||||||
|
selectedElement: 'Elemento selecionado',
|
||||||
|
xPosition: 'Posição X',
|
||||||
|
yPosition: 'Posição Y',
|
||||||
|
width: 'Largura',
|
||||||
|
height: 'Altura',
|
||||||
|
quickPosition: 'Posição rápida',
|
||||||
|
topLeft: 'Posicionar no canto superior esquerdo',
|
||||||
|
topRight: 'Posicionar no canto superior direito',
|
||||||
|
bottomLeft: 'Posicionar no canto inferior esquerdo',
|
||||||
|
bottomRight: 'Posicionar no canto inferior direito',
|
||||||
|
removeElement: 'Remover elemento',
|
||||||
|
selectOverlay: 'Selecione uma sobreposição na tela para ajustar a posição e o tamanho.',
|
||||||
|
imageEditor: 'Editor de imagens',
|
||||||
|
canvasLabel: 'Área para posicionar sobreposições de imagem',
|
||||||
|
imageAppearsHere: 'A sua imagem aparecerá aqui.',
|
||||||
|
uploadToBegin: 'Carregue um PNG, JPEG, WebP ou SVG para começar.',
|
||||||
|
readyWhenYouAre: 'Quando estiver pronto',
|
||||||
|
downloadImage: 'Descarregue a sua imagem',
|
||||||
|
originalDimensions: 'As exportações mantêm as dimensões originais da imagem.',
|
||||||
|
downloadPng: 'Descarregar PNG',
|
||||||
|
downloadJpeg: 'Descarregar JPEG',
|
||||||
|
editorLoading: 'O editor ainda está a carregar. Tente novamente.',
|
||||||
|
decodeImage: 'Não foi possível descodificar a imagem. Escolha um PNG, JPEG, WebP ou SVG válido.',
|
||||||
|
predefinedOverlayFailed: 'Não foi possível carregar esta sobreposição predefinida. Confirme que o nome em overlays.json corresponde exatamente ao ficheiro em public/overlays/.',
|
||||||
|
unsupportedBackground: 'Escolha um PNG, JPEG, WebP ou SVG para a imagem de fundo.',
|
||||||
|
invalidBackgroundDimensions: 'A imagem de fundo tem dimensões inválidas.',
|
||||||
|
backgroundLoadFailed: 'Não foi possível carregar a imagem de fundo.',
|
||||||
|
uploadBackgroundFirst: 'Carregue uma imagem de fundo antes de adicionar uma sobreposição.',
|
||||||
|
invalidOverlayDimensions: 'A sobreposição tem dimensões inválidas.',
|
||||||
|
overlayLoadFailed: 'Não foi possível carregar a sobreposição.',
|
||||||
|
unsupportedOverlay: 'Escolha um PNG, JPEG, WebP ou SVG para a sobreposição.',
|
||||||
|
uploadBackgroundBeforeExport: 'Carregue uma imagem de fundo antes de exportar.',
|
||||||
|
overlayConfigFailed: 'Não foi possível carregar a biblioteca de sobreposições predefinidas. Ainda pode carregar uma imagem personalizada.',
|
||||||
|
downloadFilename: 'imagem-local',
|
||||||
|
},
|
||||||
|
} as const
|
||||||
|
|
||||||
|
function initialLocale(): Locale {
|
||||||
|
const savedLocale = localStorage.getItem('local-image-editor-locale')
|
||||||
|
if (savedLocale === 'en' || savedLocale === 'pt') return savedLocale
|
||||||
|
return navigator.language.toLowerCase().startsWith('pt') ? 'pt' : 'en'
|
||||||
|
}
|
||||||
|
|
||||||
|
const locale = ref<Locale>(initialLocale())
|
||||||
|
|
||||||
|
const t: Translate = (key, values = {}) => {
|
||||||
|
let message: string = translations[locale.value][key]
|
||||||
|
for (const [name, value] of Object.entries(values)) {
|
||||||
|
message = message.replace(`{${name}}`, String(value))
|
||||||
|
}
|
||||||
|
return message
|
||||||
|
}
|
||||||
|
|
||||||
|
function setLocale(nextLocale: Locale): void {
|
||||||
|
locale.value = nextLocale
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(locale, (nextLocale) => {
|
||||||
|
localStorage.setItem('local-image-editor-locale', nextLocale)
|
||||||
|
document.documentElement.lang = nextLocale === 'pt' ? 'pt-PT' : 'en'
|
||||||
|
document.title = translations[nextLocale].appName
|
||||||
|
}, { immediate: true })
|
||||||
|
|
||||||
|
export function useLocale() {
|
||||||
|
return { locale, setLocale, t }
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { createApp } from 'vue'
|
||||||
|
import App from './App.vue'
|
||||||
|
import './styles/main.css'
|
||||||
|
|
||||||
|
createApp(App).mount('#app')
|
||||||
@@ -0,0 +1,613 @@
|
|||||||
|
:root {
|
||||||
|
color: #15373a;
|
||||||
|
background: #f4f2eb;
|
||||||
|
font-family: 'Avenir Next', 'Helvetica Neue', Arial, sans-serif;
|
||||||
|
font-synthesis: none;
|
||||||
|
text-rendering: optimizeLegibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
min-width: 320px;
|
||||||
|
min-height: 100vh;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
button,
|
||||||
|
input,
|
||||||
|
select {
|
||||||
|
font: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
button,
|
||||||
|
label,
|
||||||
|
select {
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:disabled {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.44;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:focus-visible,
|
||||||
|
input:focus-visible,
|
||||||
|
select:focus-visible,
|
||||||
|
.dropzone:focus-within {
|
||||||
|
outline: 3px solid #ee815e;
|
||||||
|
outline-offset: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-shell {
|
||||||
|
width: min(1480px, calc(100% - 48px));
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 26px 0 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.site-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 24px;
|
||||||
|
margin-bottom: 48px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-tools {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 17px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.language-picker select {
|
||||||
|
width: auto;
|
||||||
|
height: 31px;
|
||||||
|
padding: 0 7px;
|
||||||
|
border-color: #c7cec6;
|
||||||
|
background: transparent;
|
||||||
|
color: #53645d;
|
||||||
|
font-family: 'DM Mono', monospace;
|
||||||
|
font-size: 9px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sr-only {
|
||||||
|
position: absolute;
|
||||||
|
width: 1px;
|
||||||
|
height: 1px;
|
||||||
|
overflow: hidden;
|
||||||
|
clip: rect(0 0 0 0);
|
||||||
|
white-space: nowrap;
|
||||||
|
clip-path: inset(50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand {
|
||||||
|
margin: 0;
|
||||||
|
color: #15373a;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 800;
|
||||||
|
letter-spacing: -0.04em;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand a {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 11px;
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-mark {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
gap: 3px;
|
||||||
|
width: 30px;
|
||||||
|
height: 30px;
|
||||||
|
padding: 7px 6px;
|
||||||
|
background: #ee815e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-mark i {
|
||||||
|
display: block;
|
||||||
|
width: 4px;
|
||||||
|
background: #15373a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-mark i:first-child { height: 8px; }
|
||||||
|
.brand-mark i:nth-child(2) { height: 15px; }
|
||||||
|
.brand-mark i:last-child { height: 11px; }
|
||||||
|
|
||||||
|
.privacy-notice {
|
||||||
|
margin: 0;
|
||||||
|
max-width: 450px;
|
||||||
|
color: #6c7771;
|
||||||
|
font-family: 'DM Mono', monospace;
|
||||||
|
font-size: 10px;
|
||||||
|
line-height: 1.45;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.eyebrow {
|
||||||
|
margin: 0 0 9px;
|
||||||
|
color: #d56043;
|
||||||
|
font-family: 'DM Mono', monospace;
|
||||||
|
font-size: 10px;
|
||||||
|
font-weight: 500;
|
||||||
|
letter-spacing: 0.11em;
|
||||||
|
line-height: 1.2;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2,
|
||||||
|
p {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-notice {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
max-width: 900px;
|
||||||
|
margin: 0 0 28px;
|
||||||
|
padding: 14px 16px;
|
||||||
|
border: 1px solid #e29982;
|
||||||
|
background: #fff0e9;
|
||||||
|
color: #90381e;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.45;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-notice button {
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
color: inherit;
|
||||||
|
font-family: 'DM Mono', monospace;
|
||||||
|
font-size: 17px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.workspace {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(280px, 342px) minmax(0, 1fr);
|
||||||
|
align-items: start;
|
||||||
|
gap: clamp(25px, 4vw, 68px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-column {
|
||||||
|
display: grid;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel {
|
||||||
|
padding: 23px;
|
||||||
|
border: 1px solid #d6d6cc;
|
||||||
|
background: #fbfaf6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-heading {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 13px;
|
||||||
|
margin-bottom: 21px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-heading .eyebrow {
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.step-number {
|
||||||
|
display: grid;
|
||||||
|
flex: 0 0 26px;
|
||||||
|
width: 26px;
|
||||||
|
height: 26px;
|
||||||
|
place-items: center;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #15373a;
|
||||||
|
color: #f7f5ee;
|
||||||
|
font-family: 'DM Mono', monospace;
|
||||||
|
font-size: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
margin-bottom: 0;
|
||||||
|
color: #15373a;
|
||||||
|
font-size: 17px;
|
||||||
|
font-weight: 800;
|
||||||
|
letter-spacing: -0.045em;
|
||||||
|
line-height: 1.15;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropzone {
|
||||||
|
display: flex;
|
||||||
|
min-height: 148px;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 7px;
|
||||||
|
border: 1px dashed #9fa9a2;
|
||||||
|
background: #f4f2eb;
|
||||||
|
color: #52635d;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 12px;
|
||||||
|
text-align: center;
|
||||||
|
transition: background 150ms ease, border-color 150ms ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropzone:hover,
|
||||||
|
.dropzone--active {
|
||||||
|
border-color: #ee815e;
|
||||||
|
background: #fff2e8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropzone input,
|
||||||
|
.upload-button input {
|
||||||
|
position: absolute;
|
||||||
|
width: 1px;
|
||||||
|
height: 1px;
|
||||||
|
overflow: hidden;
|
||||||
|
clip: rect(0 0 0 0);
|
||||||
|
white-space: nowrap;
|
||||||
|
clip-path: inset(50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropzone strong {
|
||||||
|
color: #15373a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropzone small {
|
||||||
|
color: #8c9690;
|
||||||
|
font-family: 'DM Mono', monospace;
|
||||||
|
font-size: 9px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropzone-icon {
|
||||||
|
display: grid;
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
place-items: center;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #dce6dd;
|
||||||
|
color: #15373a;
|
||||||
|
font-size: 17px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-dimensions {
|
||||||
|
margin: -5px 0 1px;
|
||||||
|
color: #718079;
|
||||||
|
font-family: 'DM Mono', monospace;
|
||||||
|
font-size: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-group {
|
||||||
|
display: grid;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-group > label,
|
||||||
|
.coordinate-grid label,
|
||||||
|
.quick-position > span,
|
||||||
|
.calculated-size > span {
|
||||||
|
color: #64736d;
|
||||||
|
font-family: 'DM Mono', monospace;
|
||||||
|
font-size: 10px;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
select,
|
||||||
|
.number-input {
|
||||||
|
min-width: 0;
|
||||||
|
height: 42px;
|
||||||
|
border: 1px solid #cfd2c9;
|
||||||
|
border-radius: 0;
|
||||||
|
background: #fffefb;
|
||||||
|
color: #15373a;
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0 12px;
|
||||||
|
appearance: auto;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
display: inline-flex;
|
||||||
|
min-height: 42px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: 0;
|
||||||
|
padding: 10px 14px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: -0.01em;
|
||||||
|
line-height: 1.2;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button--secondary {
|
||||||
|
margin-top: 4px;
|
||||||
|
background: #dce6dd;
|
||||||
|
color: #15373a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button--secondary:hover:not(:disabled) { background: #c9daca; }
|
||||||
|
|
||||||
|
.panel-divider {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
margin: 18px 0;
|
||||||
|
color: #9aa39d;
|
||||||
|
font-family: 'DM Mono', monospace;
|
||||||
|
font-size: 9px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-divider::before,
|
||||||
|
.panel-divider::after {
|
||||||
|
height: 1px;
|
||||||
|
flex: 1;
|
||||||
|
background: #deded5;
|
||||||
|
content: '';
|
||||||
|
}
|
||||||
|
|
||||||
|
.button--outline {
|
||||||
|
width: 100%;
|
||||||
|
border-color: #15373a;
|
||||||
|
background: transparent;
|
||||||
|
color: #15373a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button--outline:hover { background: #15373a; color: #fff; }
|
||||||
|
|
||||||
|
.upload-button { cursor: pointer; }
|
||||||
|
|
||||||
|
.controls-panel { min-height: 230px; }
|
||||||
|
|
||||||
|
.selected-name {
|
||||||
|
overflow: hidden;
|
||||||
|
margin: -6px 0 19px;
|
||||||
|
color: #15373a;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 700;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coordinate-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 14px 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coordinate-grid label {
|
||||||
|
display: grid;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.number-input {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.number-input input {
|
||||||
|
min-width: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
padding: 0 6px 0 10px;
|
||||||
|
color: #15373a;
|
||||||
|
font-family: 'DM Mono', monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.number-input input:focus-visible { outline: 0; }
|
||||||
|
|
||||||
|
.number-input em {
|
||||||
|
padding-right: 9px;
|
||||||
|
color: #97a099;
|
||||||
|
font-family: 'DM Mono', monospace;
|
||||||
|
font-size: 9px;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.calculated-size {
|
||||||
|
display: grid;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.calculated-size strong {
|
||||||
|
display: flex;
|
||||||
|
height: 42px;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0 10px;
|
||||||
|
border: 1px solid #e0e1d9;
|
||||||
|
color: #60706b;
|
||||||
|
font-family: 'DM Mono', monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.quick-position {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr auto;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
margin: 20px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.corner-buttons {
|
||||||
|
display: flex;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.corner-buttons button {
|
||||||
|
display: grid;
|
||||||
|
width: 31px;
|
||||||
|
height: 31px;
|
||||||
|
place-items: center;
|
||||||
|
border: 1px solid #cfd2c9;
|
||||||
|
background: #fffefb;
|
||||||
|
color: #15373a;
|
||||||
|
font-family: 'DM Mono', monospace;
|
||||||
|
font-size: 9px;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.corner-buttons button:hover { background: #dce6dd; }
|
||||||
|
|
||||||
|
.button--danger {
|
||||||
|
width: 100%;
|
||||||
|
border-color: #d56143;
|
||||||
|
background: transparent;
|
||||||
|
color: #b94b31;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button--danger:hover { background: #fff0ea; }
|
||||||
|
|
||||||
|
.control-empty {
|
||||||
|
margin: 0;
|
||||||
|
color: #829089;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.65;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor-region {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-shell {
|
||||||
|
display: grid;
|
||||||
|
min-height: 430px;
|
||||||
|
place-items: center;
|
||||||
|
overflow: hidden;
|
||||||
|
border: 1px solid #d6d6cc;
|
||||||
|
background-color: #d8ddd5;
|
||||||
|
background-image: linear-gradient(45deg, #cfd5cc 25%, transparent 25%), linear-gradient(-45deg, #cfd5cc 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #cfd5cc 75%), linear-gradient(-45deg, transparent 75%, #cfd5cc 75%);
|
||||||
|
background-position: 0 0, 0 10px, 10px -10px, -10px 0;
|
||||||
|
background-size: 20px 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor-empty {
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
color: #6d7972;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor-empty p {
|
||||||
|
margin: 12px 0 5px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor-empty small {
|
||||||
|
font-family: 'DM Mono', monospace;
|
||||||
|
font-size: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-mark {
|
||||||
|
display: grid;
|
||||||
|
width: 44px;
|
||||||
|
height: 44px;
|
||||||
|
place-items: center;
|
||||||
|
border: 1px solid #91a098;
|
||||||
|
border-radius: 50%;
|
||||||
|
color: #60716a;
|
||||||
|
font-size: 26px;
|
||||||
|
font-weight: 300;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor-canvas {
|
||||||
|
display: block;
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-shell--empty .canvas-container {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.export-panel {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 28px;
|
||||||
|
margin-top: clamp(28px, 4vw, 55px);
|
||||||
|
padding: 26px 29px;
|
||||||
|
background: #e5b35e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.export-panel .eyebrow { color: #79551b; }
|
||||||
|
.export-panel h2 { color: #15373a; }
|
||||||
|
|
||||||
|
.export-panel p:last-child {
|
||||||
|
max-width: 420px;
|
||||||
|
margin: 8px 0 0;
|
||||||
|
color: #5e532e;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.export-actions {
|
||||||
|
display: flex;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
gap: 9px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button--primary { background: #15373a; color: #fff; }
|
||||||
|
.button--primary:hover:not(:disabled) { background: #0a2528; }
|
||||||
|
.button--dark { border-color: #15373a; background: transparent; color: #15373a; }
|
||||||
|
.button--dark:hover:not(:disabled) { background: #f5dc9d; }
|
||||||
|
|
||||||
|
@media (max-width: 860px) {
|
||||||
|
.workspace {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-column {
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls-panel,
|
||||||
|
.image-dimensions {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor-region { grid-row: 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 590px) {
|
||||||
|
.app-shell {
|
||||||
|
width: min(100% - 30px, 1480px);
|
||||||
|
padding-top: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.site-header { margin-bottom: 30px; }
|
||||||
|
|
||||||
|
.site-header { align-items: flex-start; }
|
||||||
|
.header-tools { align-items: flex-end; flex-direction: column-reverse; gap: 6px; }
|
||||||
|
.privacy-notice { max-width: 185px; font-size: 8px; }
|
||||||
|
.intro { padding: 58px 0 38px; }
|
||||||
|
.intro-copy { font-size: 14px; }
|
||||||
|
.control-column { grid-template-columns: 1fr; }
|
||||||
|
.controls-panel,
|
||||||
|
.image-dimensions { grid-column: auto; }
|
||||||
|
.canvas-shell { min-height: 280px; }
|
||||||
|
.export-panel { align-items: flex-start; flex-direction: column; padding: 23px; }
|
||||||
|
.export-actions { width: 100%; }
|
||||||
|
.export-actions .button { flex: 1; padding-right: 8px; padding-left: 8px; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
export interface ImageDimensions {
|
||||||
|
width: number
|
||||||
|
height: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OverlayLibraryItem {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
file: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SelectedOverlay {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
x: number
|
||||||
|
y: number
|
||||||
|
width: number
|
||||||
|
height: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type OverlayCorner = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
|
||||||
|
|
||||||
|
export interface EditorHandle {
|
||||||
|
resizeDisplay: (width: number, height: number) => void
|
||||||
|
loadBackground: (file: File) => Promise<void>
|
||||||
|
addOverlay: (source: string, name: string) => Promise<void>
|
||||||
|
addCustomOverlay: (file: File) => Promise<void>
|
||||||
|
updateSelected: (changes: Partial<Pick<SelectedOverlay, 'x' | 'y' | 'width'>>) => void
|
||||||
|
positionSelected: (corner: OverlayCorner) => void
|
||||||
|
removeSelected: () => void
|
||||||
|
exportImage: (format: 'png' | 'jpeg') => void
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
|
||||||
|
"exclude": ["src/**/__tests__/*"],
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||||
|
"composite": true,
|
||||||
|
"target": "ES2022",
|
||||||
|
"useDefineForClassFields": true,
|
||||||
|
"module": "ESNext",
|
||||||
|
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"moduleResolution": "Bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
"jsx": "preserve",
|
||||||
|
"types": ["vite/client"],
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["./src/*"]
|
||||||
|
},
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"noFallthroughCasesInSwitch": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{ "path": "./tsconfig.app.json" },
|
||||||
|
{ "path": "./tsconfig.node.json" }
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"include": ["vite.config.ts"],
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||||
|
"composite": true,
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "Bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { fileURLToPath, URL } from 'node:url'
|
||||||
|
import { defineConfig } from 'vite'
|
||||||
|
import vue from '@vitejs/plugin-vue'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [vue()],
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
Reference in new issue
Block a user