|
|
|
@@ -4,9 +4,7 @@ import { Fireworks } from 'fireworks-js';
|
|
|
|
import { usePuzzleStore } from '@/stores/puzzle';
|
|
|
|
import { usePuzzleStore } from '@/stores/puzzle';
|
|
|
|
import { useI18n } from '@/composables/useI18n';
|
|
|
|
import { useI18n } from '@/composables/useI18n';
|
|
|
|
import { useTimer } from '@/composables/useTimer';
|
|
|
|
import { useTimer } from '@/composables/useTimer';
|
|
|
|
import xIcon from '@/assets/brands/x.svg';
|
|
|
|
import { Download } from 'lucide-vue-next';
|
|
|
|
import facebookIcon from '@/assets/brands/facebook.svg';
|
|
|
|
|
|
|
|
import whatsappIcon from '@/assets/brands/whatsapp.svg';
|
|
|
|
|
|
|
|
import { calculateDifficulty } from '@/utils/puzzleUtils';
|
|
|
|
import { calculateDifficulty } from '@/utils/puzzleUtils';
|
|
|
|
|
|
|
|
|
|
|
|
const store = usePuzzleStore();
|
|
|
|
const store = usePuzzleStore();
|
|
|
|
@@ -177,7 +175,11 @@ const buildShareCanvas = () => {
|
|
|
|
if (store.guideUsageCount > 0) {
|
|
|
|
if (store.guideUsageCount > 0) {
|
|
|
|
ctx.fillStyle = '#ff4d4d';
|
|
|
|
ctx.fillStyle = '#ff4d4d';
|
|
|
|
ctx.font = '600 14px "Segoe UI", sans-serif';
|
|
|
|
ctx.font = '600 14px "Segoe UI", sans-serif';
|
|
|
|
const guideText = t('win.usedGuide', { count: store.guideUsageCount });
|
|
|
|
|
|
|
|
|
|
|
|
const totalCells = store.size * store.size;
|
|
|
|
|
|
|
|
const percent = Math.min(100, Math.round((store.guideUsageCount / totalCells) * 100));
|
|
|
|
|
|
|
|
const guideText = t('win.usedGuide', { count: store.guideUsageCount, percent });
|
|
|
|
|
|
|
|
|
|
|
|
ctx.fillText(`⚠️ ${guideText}`, padding, height - padding - footerHeight + 10);
|
|
|
|
ctx.fillText(`⚠️ ${guideText}`, padding, height - padding - footerHeight + 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -212,7 +214,7 @@ const buildShareUrl = (target, text, url) => {
|
|
|
|
const encodedText = encodeURIComponent(text);
|
|
|
|
const encodedText = encodeURIComponent(text);
|
|
|
|
const encodedUrl = encodeURIComponent(url);
|
|
|
|
const encodedUrl = encodeURIComponent(url);
|
|
|
|
if (target === 'x') {
|
|
|
|
if (target === 'x') {
|
|
|
|
return `https://twitter.com/intent/tweet?text=${encodedText}&url=${encodedUrl}`;
|
|
|
|
return `https://x.com/intent/tweet?text=${encodedText}&url=${encodedUrl}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (target === 'facebook') {
|
|
|
|
if (target === 'facebook') {
|
|
|
|
return `https://www.facebook.com/sharer/sharer.php?u=${encodedUrl}"e=${encodedText}`;
|
|
|
|
return `https://www.facebook.com/sharer/sharer.php?u=${encodedUrl}"e=${encodedText}`;
|
|
|
|
@@ -226,29 +228,48 @@ const buildShareUrl = (target, text, url) => {
|
|
|
|
const shareTo = async (target) => {
|
|
|
|
const shareTo = async (target) => {
|
|
|
|
if (shareInProgress.value) return;
|
|
|
|
if (shareInProgress.value) return;
|
|
|
|
shareInProgress.value = true;
|
|
|
|
shareInProgress.value = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const text = shareText.value;
|
|
|
|
|
|
|
|
const url = window.location.href;
|
|
|
|
|
|
|
|
const shareUrl = buildShareUrl(target, text, url);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const blob = await createShareBlob();
|
|
|
|
// Try native share first if available (supports images)
|
|
|
|
if (!blob) return;
|
|
|
|
if (navigator.share && navigator.canShare) {
|
|
|
|
const file = new File([blob], `nonogram-${store.size}x${store.size}.png`, { type: 'image/png' });
|
|
|
|
const blob = await createShareBlob();
|
|
|
|
const text = shareText.value;
|
|
|
|
if (blob) {
|
|
|
|
const url = window.location.href;
|
|
|
|
const file = new File([blob], `nonogram-${store.size}x${store.size}.png`, { type: 'image/png' });
|
|
|
|
if (navigator.share && navigator.canShare && navigator.canShare({ files: [file] })) {
|
|
|
|
if (navigator.canShare({ files: [file] })) {
|
|
|
|
await navigator.share({
|
|
|
|
await navigator.share({
|
|
|
|
files: [file],
|
|
|
|
files: [file],
|
|
|
|
text,
|
|
|
|
text,
|
|
|
|
title: t('app.title'),
|
|
|
|
title: t('app.title'),
|
|
|
|
url
|
|
|
|
url
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await downloadShareImage();
|
|
|
|
} catch (error) {
|
|
|
|
const shareUrl = buildShareUrl(target, text, url);
|
|
|
|
if (error.name === 'AbortError') {
|
|
|
|
if (shareUrl) {
|
|
|
|
return; // User cancelled native share, do nothing
|
|
|
|
window.open(shareUrl, '_blank', 'noopener');
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Other errors -> fall through to fallback
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
shareInProgress.value = false;
|
|
|
|
shareInProgress.value = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fallback: Direct Link + Download
|
|
|
|
|
|
|
|
// Open window immediately if possible (though we awaited above, so it might be blocked,
|
|
|
|
|
|
|
|
// but we can't do much about it if we want to try native share first).
|
|
|
|
|
|
|
|
// Ideally, for Desktop, navigator.share is undefined so we skip the await above.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (shareUrl) {
|
|
|
|
|
|
|
|
window.open(shareUrl, '_blank', 'noopener');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Trigger download as "screenshot support"
|
|
|
|
|
|
|
|
downloadShareImage();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
onMounted(() => {
|
|
|
|
@@ -308,19 +329,23 @@ onUnmounted(() => {
|
|
|
|
<div class="share">
|
|
|
|
<div class="share">
|
|
|
|
<div class="share-title">{{ t('win.shareTitle') }}</div>
|
|
|
|
<div class="share-title">{{ t('win.shareTitle') }}</div>
|
|
|
|
<div class="share-buttons">
|
|
|
|
<div class="share-buttons">
|
|
|
|
|
|
|
|
<!-- X (Twitter) -->
|
|
|
|
<button class="btn-neon secondary share-btn" :disabled="shareInProgress" :aria-label="t('win.shareX')" @click="shareTo('x')">
|
|
|
|
<button class="btn-neon secondary share-btn" :disabled="shareInProgress" :aria-label="t('win.shareX')" @click="shareTo('x')">
|
|
|
|
<img :src="xIcon" alt="" class="share-icon" />
|
|
|
|
<svg viewBox="0 0 24 24" fill="currentColor" class="share-icon"><path d="M18.901 3H22l-7.21 8.26L23 21h-6.66L11.13 14.76 5.66 21H2.56l7.73-8.83L1 3h6.8l4.63 5.56L18.9 3h.001zm-1.2 15.9h1.77L6.44 5.1H4.44l13.26 13.8z"/></svg>
|
|
|
|
</button>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<!-- Facebook -->
|
|
|
|
<button class="btn-neon secondary share-btn" :disabled="shareInProgress" :aria-label="t('win.shareFacebook')" @click="shareTo('facebook')">
|
|
|
|
<button class="btn-neon secondary share-btn" :disabled="shareInProgress" :aria-label="t('win.shareFacebook')" @click="shareTo('facebook')">
|
|
|
|
<img :src="facebookIcon" alt="" class="share-icon" />
|
|
|
|
<svg viewBox="0 0 24 24" fill="currentColor" class="share-icon"><path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.791-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"/></svg>
|
|
|
|
</button>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<!-- WhatsApp -->
|
|
|
|
<button class="btn-neon secondary share-btn" :disabled="shareInProgress" :aria-label="t('win.shareWhatsapp')" @click="shareTo('whatsapp')">
|
|
|
|
<button class="btn-neon secondary share-btn" :disabled="shareInProgress" :aria-label="t('win.shareWhatsapp')" @click="shareTo('whatsapp')">
|
|
|
|
<img :src="whatsappIcon" alt="" class="share-icon" />
|
|
|
|
<svg viewBox="0 0 24 24" fill="currentColor" class="share-icon"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.008-.57-.008-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413Z"/></svg>
|
|
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<!-- Download Screenshot (Compact) -->
|
|
|
|
|
|
|
|
<button class="btn-neon secondary share-btn" :disabled="shareInProgress" :aria-label="t('win.shareDownload')" @click="downloadShareImage">
|
|
|
|
|
|
|
|
<Download :size="20" />
|
|
|
|
</button>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<button class="btn-neon secondary share-download" :disabled="shareInProgress" @click="downloadShareImage">
|
|
|
|
|
|
|
|
{{ t('win.shareDownload') }}
|
|
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="actions">
|
|
|
|
<div class="actions">
|
|
|
|
|