diff --git a/CHANGELOG.md b/CHANGELOG.md
index 50137ef..a6865d0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]
+### Changed
+
+- **Share shows the workout image first, with a transparent background and Copy.** Share on the Workout Complete sheet opens a preview, and nothing leaves the app until you tap Share. Transparent drops the background, to put the card over a photo in a story, and Copy puts the image on the clipboard to paste it there (in a browser, over HTTPS).
+
### Security
- **Tokens, keys and passwords saved in Settings are stored encrypted, and the ones only the server uses never reach the app** (from [cooktrace#92](https://github.com/TraceApps/cooktrace/issues/92), thanks @stupleb). The NutriTrace link token, the ntfy and Gotify tokens and the music server's sign-in stay on the server: Settings shows a saved one as dots, saving the dots keeps it, and typing a new one replaces it. The AI key, ExerciseDB key and music server password still go to your own signed-in app, which uses them itself. All of them are stored encrypted with `TOKEN_ENC_KEY`, so the database, a backup or an export never holds them in plain text; ones saved before are encrypted when the server starts. Changing `TOKEN_ENC_KEY`, or `JWT_SECRET` when it isn't set, means entering them again.
diff --git a/src/components/diary/WorkoutSummary.svelte b/src/components/diary/WorkoutSummary.svelte
index ea63950..29f1cce 100644
--- a/src/components/diary/WorkoutSummary.svelte
+++ b/src/components/diary/WorkoutSummary.svelte
@@ -5,10 +5,10 @@
import { weightUnit, caloriesBurnedEnabled, heightCm, currentWeightKg } from '../../stores/settings.js';
import { currentUser } from '../../stores/auth.js';
import { DB } from '../../lib/db.js';
- import { shareWorkoutCard } from '../../lib/workoutCard.js';
+ import { renderWorkoutCard, shareWorkoutCard, canCopyImage, copyWorkoutCard } from '../../lib/workoutCard.js';
import { exportWorkoutCsv } from '../../lib/workoutCsv.js';
import { LtApi } from '../../lib/api.js';
- import { showError } from '../../stores/toast.js';
+ import { showError, showSuccess } from '../../stores/toast.js';
import { estimateWorkoutCalories, toKg, ageFromDob, exerciseVolume, fmtSetLabel, distanceUnitOf } from '../../lib/workout.js';
import { timerState, timerMs } from '../../stores/workoutTimer.js';
@@ -60,14 +60,49 @@
);
})();
+ // Share shows the image first and sends it only on a second tap; the blob
+ // shown is the one shared or copied. The background can be dropped, to
+ // paste the card over a photo.
let sharing = false;
- async function handleShare() {
+ let previewBlob = null;
+ let cardUrl = '';
+ let previewTransparent = false;
+ const canCopy = canCopyImage();
+ async function renderPreview(transparent) {
if (!workout || sharing) return;
sharing = true;
- try { await shareWorkoutCard({ ...workout, duration_min: effectiveDurationMin }, $weightUnit); }
+ try {
+ const blob = await renderWorkoutCard({ ...workout, duration_min: effectiveDurationMin }, $weightUnit, { transparent });
+ if (cardUrl) URL.revokeObjectURL(cardUrl);
+ previewBlob = blob;
+ cardUrl = blob ? URL.createObjectURL(blob) : '';
+ previewTransparent = transparent;
+ }
catch (e) { showError(e.message || 'Share failed'); }
sharing = false;
}
+ function handleShare() { return renderPreview(false); }
+ function closePreview() {
+ if (cardUrl) URL.revokeObjectURL(cardUrl);
+ cardUrl = '';
+ previewBlob = null;
+ }
+ async function copyPreview() {
+ if (!previewBlob || sharing) return;
+ try { await copyWorkoutCard(previewBlob); showSuccess($_('workout_summary.image_copied')); }
+ catch (e) { showError(e.message || 'Copy failed'); }
+ }
+ async function confirmShare() {
+ if (!previewBlob || sharing) return;
+ sharing = true;
+ try {
+ // false = the share sheet was dismissed: stay on the preview.
+ if (await shareWorkoutCard({ ...workout, duration_min: effectiveDurationMin }, $weightUnit, previewBlob)) closePreview();
+ }
+ catch (e) { showError(e.message || 'Share failed'); }
+ sharing = false;
+ }
+ $: if (!open) closePreview();
let exportingCsv = false;
async function handleExportCsv() {
@@ -175,6 +210,31 @@
close
+ {#if cardUrl}
+
+
{$_('workout_summary.share_title')}
+
+
+
+
+
+
+
+ {:else}
@@ -302,6 +362,7 @@
+ {/if}
{/if}
@@ -546,4 +607,22 @@
}
.ws-icon-btn .material-symbols-rounded { font-size: 20px; }
.ws-done-btn { flex: 1; }
+
+ /* Share preview: the image at its own 4:5, as tall as the sheet allows. */
+ .ws-preview { padding: 20px 20px 4px; text-align: center; }
+ .ws-bg-row { display: flex; justify-content: center; gap: 8px; margin-top: 12px; }
+ .ws-bg-btn { height: 34px; padding: 0 14px; font-size: 13px; }
+ .ws-bg-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
+ .ws-preview-img {
+ display: block; margin: 12px auto 0;
+ aspect-ratio: 4 / 5;
+ height: min(48dvh, 450px); width: auto; max-width: 100%;
+ border-radius: var(--radius-lg);
+ border: 1px solid var(--border);
+ }
+ /* No background: a checkerboard behind the image says so. */
+ .ws-preview-img.transparent {
+ background: repeating-conic-gradient(#8a8f9a 0% 25%, #5d626d 0% 50%) 50% / 24px 24px;
+ }
+ .ws-preview + .ws-footer .ws-share-btn { justify-content: center; }
diff --git a/src/i18n/en.json b/src/i18n/en.json
index 217033a..e84d609 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -851,7 +851,15 @@
"exercises": "Exercises",
"duration": "Duration",
"custom": "Custom",
- "done": "Done"
+ "done": "Done",
+ "share": "Share",
+ "share_title": "Share Workout",
+ "share_preview_alt": "Preview of the image to share",
+ "share_background": "Background",
+ "share_bg_solid": "Solid",
+ "share_bg_transparent": "Transparent",
+ "copy": "Copy",
+ "image_copied": "Image copied"
},
"exercise_detail": {
"deleted": "Exercise deleted",
diff --git a/src/lib/workoutCard.js b/src/lib/workoutCard.js
index 89ca670..312215d 100644
--- a/src/lib/workoutCard.js
+++ b/src/lib/workoutCard.js
@@ -6,6 +6,10 @@
//
// Pulls the current accent color from the CSS custom property so the card
// matches the user's theme.
+//
+// With { transparent: true } the card has no background, to paste over a
+// photo: lighter greys, see-through tiles and a soft shadow keep it readable
+// on whatever ends up behind it.
// workout.js is pure (no stores), so importing it keeps this renderer self-contained.
import { isRepSet, setKind, setAmount, fmtSetLabel, distanceUnitOf, setReps } from './workout.js';
@@ -76,9 +80,10 @@ function _computeStats(workout) {
/**
* @param {object} workout { name, date, duration_min, exercises: [...] }
* @param {string} unit weight unit label ('lbs' or 'kg')
+ * @param {{ transparent?: boolean }} [opts]
* @returns {Promise} PNG blob
*/
-export async function renderWorkoutCard(workout, unit = 'lbs') {
+export async function renderWorkoutCard(workout, unit = 'lbs', { transparent = false } = {}) {
const canvas = document.createElement('canvas');
canvas.width = W;
canvas.height = H;
@@ -88,21 +93,27 @@ export async function renderWorkoutCard(workout, unit = 'lbs') {
const accent = _cssVar('--accent', '#FF7433');
const accent2 = _cssVar('--accent-2', accent);
const bg = '#0A0B0F';
- const surface = '#16181E';
+ const surface = transparent ? 'rgba(0, 0, 0, 0.38)' : '#16181E';
const text1 = '#F5F6F8';
- const text2 = '#A8AFBD';
- const text3 = '#6B7280';
+ const text2 = transparent ? 'rgba(255, 255, 255, 0.88)' : '#A8AFBD';
+ const text3 = transparent ? 'rgba(255, 255, 255, 0.72)' : '#6B7280';
+ const line = transparent ? 'rgba(255, 255, 255, 0.28)' : '#23262E';
- // ── Background ───────────────────────────────────────────────────────
- ctx.fillStyle = bg;
- ctx.fillRect(0, 0, W, H);
+ if (transparent) {
+ ctx.shadowColor = 'rgba(0, 0, 0, 0.55)';
+ ctx.shadowBlur = 10;
+ } else {
+ // ── Background ─────────────────────────────────────────────────────
+ ctx.fillStyle = bg;
+ ctx.fillRect(0, 0, W, H);
- // Soft accent glow in the top-right corner
- const grad = ctx.createRadialGradient(W - 100, -100, 50, W - 100, -100, 700);
- grad.addColorStop(0, accent + '55'); // add ~33% alpha
- grad.addColorStop(1, accent + '00');
- ctx.fillStyle = grad;
- ctx.fillRect(0, 0, W, H);
+ // Soft accent glow in the top-right corner
+ const grad = ctx.createRadialGradient(W - 100, -100, 50, W - 100, -100, 700);
+ grad.addColorStop(0, accent + '55'); // add ~33% alpha
+ grad.addColorStop(1, accent + '00');
+ ctx.fillStyle = grad;
+ ctx.fillRect(0, 0, W, H);
+ }
// ── Header: LIFTTRACE wordmark ──────────────────────────────────────
ctx.font = '700 32px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif';
@@ -248,7 +259,7 @@ export async function renderWorkoutCard(workout, unit = 'lbs') {
ctx.fillStyle = accent;
ctx.fillRect(64, blockTop, 4, blockBottom - blockTop);
// Bottom thin divider for the block.
- ctx.strokeStyle = '#23262E';
+ ctx.strokeStyle = line;
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(64, y - rowGap + 22);
@@ -259,7 +270,7 @@ export async function renderWorkoutCard(workout, unit = 'lbs') {
const yBefore = y;
y = _renderRow(g.exercise, y, 0);
rendered++;
- ctx.strokeStyle = '#23262E';
+ ctx.strokeStyle = line;
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(64, yBefore + 18);
@@ -298,9 +309,10 @@ function _roundRect(ctx, x, y, w, h, r) {
/**
* Share a workout card using Web Share API if available (with file),
* otherwise trigger a download. Returns true if shared/downloaded.
+ * Pass the blob already rendered for a preview to share that exact image.
*/
-export async function shareWorkoutCard(workout, unit = 'lbs') {
- const blob = await renderWorkoutCard(workout, unit);
+export async function shareWorkoutCard(workout, unit = 'lbs', rendered = null) {
+ const blob = rendered || await renderWorkoutCard(workout, unit);
if (!blob) return false;
const filename = `lifttrace-${(workout.name || 'workout').replace(/\s+/g, '-').toLowerCase()}-${workout.date || 'today'}.png`;
@@ -330,3 +342,13 @@ export async function shareWorkoutCard(workout, unit = 'lbs') {
setTimeout(() => URL.revokeObjectURL(url), 1000);
return true;
}
+
+/** Whether this browser can put an image on the clipboard (needs HTTPS or localhost). */
+export function canCopyImage() {
+ return typeof ClipboardItem !== 'undefined' && !!navigator.clipboard?.write;
+}
+
+/** Put a rendered card on the clipboard, to paste into a story or a chat. */
+export async function copyWorkoutCard(blob) {
+ await navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]);
+}