diff --git a/.env.example b/.env.example index 7bd9b32..408844a 100644 --- a/.env.example +++ b/.env.example @@ -4,8 +4,11 @@ # secrets, API keys or tokens in this file. PokeGuru needs no API keys. # Canonical public origin, with no trailing slash, e.g. https://pokeguru.example.com -# Used for canonical links, Open Graph URLs, robots.txt and sitemap.xml. -# Leave empty to derive URLs from the address the app is served from. +# Used for canonical links, Open Graph URLs, robots.txt, sitemap.xml AND the QR +# code on the printable 5 x 7 in flyer. +# Leave empty to derive URLs from the address the app is served from; the flyer +# then refuses to generate a QR code unless that address is a real production +# origin (never localhost, preview or sandbox hosts). VITE_PUBLIC_SITE_URL= # "Buy Me a Pack" support destination (a real, verified payment/support page). diff --git a/README.md b/README.md index 6c471ca..3f79f21 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,13 @@ and keeps a private collection vault in the browser. or estimated, shows the modelled tier odds with sources, and keeps simulated pulls in their own store (`pokeguru_pack_sim_v1`) so they can never leak into your real collection or its valuation. -- **Offline-tolerant PWA** — app shell cached, clearly labelled cached data, and - a safe update prompt that never traps you on an old version. +- **Printable 5 × 7 in flyer** — one-click, vector, print-ready PDF + (`PokeGuru-5x7-QR-Flyer.pdf`) with a QR code that always points at the live + production site, plus a Print option that opens your print dialogue. Linked + from the footer, the homepage “Share PokeGuru” panel and the About page. +- **Offline-tolerant PWA** — app shell cached, clearly labelled cached data, a + safe update prompt that never traps you on an old version, and an optional + install invitation (“Take PokeGuru with you!”). --- @@ -111,7 +116,7 @@ so never put secrets in them. | Variable | Required | Purpose | | --- | --- | --- | -| `VITE_PUBLIC_SITE_URL` | no | Canonical origin used for canonical/OG tags, `sitemap.xml` and absolute `robots.txt` entries, e.g. `https://pokeguru.example.com` (no trailing slash). Empty = derive from the browser and skip the sitemap. When set, the build asks TCGdex for the live set list so every `/set/:id` page is listed (static routes only if the API is unreachable). | +| `VITE_PUBLIC_SITE_URL` | **yes for the flyer** | Canonical origin used for canonical/OG tags, `sitemap.xml`, absolute `robots.txt` entries **and the QR code on the printable flyer**, e.g. `https://pokeguru.example.com` (no trailing slash). Empty = derive from the browser and skip the sitemap; for the flyer the served origin is used only when it looks like a real production address (see below). When set, the build asks TCGdex for the live set list so every `/set/:id` page is listed (static routes only if the API is unreachable). | | `VITE_BUY_ME_A_PACK_URL` | no | A real support/payment page for “Buy Me a Pack”. When empty the call-to-action renders in a clearly labelled *not configured* state — no fabricated link is ever shown. | | `DEPLOY_TARGET` | no | `github-pages` builds with the `/PokeGuru/` base path. Leave unset for Vercel and other root-hosted deployments. | @@ -120,6 +125,42 @@ so never put secrets in them. --- +## 🎴 Printable flyer + +Every page footer, the homepage “Share PokeGuru” panel and the About page offer +**🎴 Download PokeGuru Flyer** (and **Print flyer**). + +- **File:** `PokeGuru-5x7-QR-Flyer.pdf` — exactly one page, exactly **5 × 7 in + portrait (127 × 177.8 mm = 360 × 504 pt)**. The PDF is generated in the browser + on demand, so it is never a stale checked-in binary: one current design, one + download, no server work. +- **Everything is vector** — text uses the standard Helvetica faces, the artwork + is native PDF paths and the QR code is one rectangle per module, so it stays + sharp at any print resolution. +- **The QR code is verified.** `tests/flyer.test.ts` decodes the generated + matrix with the independent `jsqr` decoder and asserts the payload is the + production URL, and also re-opens the produced PDF to assert the page count + and page box. +- **The production address is enforced.** `src/services/flyer/qr.ts` accepts + `VITE_PUBLIC_SITE_URL` (or, if unset, the origin the app is served from) only + when it is `https`, has no path/query/hash, and is not `localhost`, `127.x`, + `*.local`, a sandbox preview (`*.e2b.app`) or a Vercel preview/branch + deployment. If nothing passes, the buttons show a **configuration warning** + instead of generating a QR code that would not work once printed — no dummy + URLs, ever. +- **Printing:** choose 100% / “Actual size” (never “Fit to page”). The design is + full-bleed dark, so a slightly heavier paper stock keeps it crisp. +- **Wording:** the flyer advertises only shipped features (search, set archive, + collection, real market prices, free virtual packs) and carries an unofficial + fan-project disclaimer. No official artwork, logos, character images or + partnership claims are used. + +To point the flyer at your own domain, set `VITE_PUBLIC_SITE_URL` (for example +in the Vercel project’s environment variables) and redeploy; Google Fonts, the +sitemap, canonical tags and the printed QR code all follow that one value. + +--- + ## 🎁 Pack Opening Simulator | Piece | Where | @@ -215,6 +256,14 @@ card. - Cached/offline data is labelled in the UI. - Updates are non-blocking: a prompt appears, and `SKIP_WAITING` swaps versions on your next action instead of pinning an old build. +- **Install invitation** (`src/components/UI/InstallPrompt.tsx`): a branded + “Take PokeGuru with you!” card appears ~7 s after load, only when the browser + can actually install the app (`beforeinstallprompt` has fired) or on iOS, + where it explains the Safari “Add to Home Screen” route instead of pretending + a one-tap prompt exists. The browser’s own install dialogue is opened **only** + after the visitor chooses *Install PokeGuru*; *Maybe later* or a dismissal is + remembered in `localStorage` for 60 days, and the card never appears when the + app is already installed (standalone display mode). --- diff --git a/package-lock.json b/package-lock.json index 74256dd..dfd461c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,20 @@ { "name": "pokeguru", - "version": "1.6.0", + "version": "1.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pokeguru", - "version": "1.6.0", + "version": "1.7.0", "license": "MIT", "dependencies": { "@fontsource-variable/inter": "^5.3.0", "@fontsource-variable/space-grotesk": "^5.3.0", "clsx": "2.1.1", "lucide-react": "^1.18.0", + "pdf-lib": "^1.17.1", + "qrcode-generator": "^2.0.4", "react": "19.2.6", "react-dom": "19.2.6", "react-router-dom": "^7.17.0", @@ -33,6 +35,7 @@ "gh-pages": "^6.3.0", "globals": "^17.14.0", "jsdom": "^31.0.1", + "jsqr": "^1.4.0", "sharp": "^0.35.5", "tailwindcss": "4.1.17", "typescript": "5.9.3", @@ -1267,6 +1270,24 @@ "url": "https://github.com/sponsors/oxc-project" } }, + "node_modules/@pdf-lib/standard-fonts": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@pdf-lib/standard-fonts/-/standard-fonts-1.0.0.tgz", + "integrity": "sha512-hU30BK9IUN/su0Mn9VdlVKsWBS6GyhVfqjwl1FjZN4TxP6cCw0jP2w7V3Hf5uX7M0AZJ16vey9yE0ny7Sa59ZA==", + "license": "MIT", + "dependencies": { + "pako": "^1.0.6" + } + }, + "node_modules/@pdf-lib/upng": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@pdf-lib/upng/-/upng-1.0.1.tgz", + "integrity": "sha512-dQK2FUMQtowVP00mtIksrlZhdFXQZPC+taih1q4CvPZ5vqdxR/LKBaFg0oAfzd1GlHZXXSPdQfzQnt+ViGvEIQ==", + "license": "MIT", + "dependencies": { + "pako": "^1.0.10" + } + }, "node_modules/@rolldown/binding-android-arm-eabi": { "version": "1.2.19", "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.19.tgz", @@ -3724,6 +3745,13 @@ "graceful-fs": "^4.1.6" } }, + "node_modules/jsqr": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/jsqr/-/jsqr-1.4.0.tgz", + "integrity": "sha512-dxLob7q65Xg2DvstYkRpkYtmKm2sPJ9oFhrhmudT1dZvNFFTlroai3AWSpLey/w5vMcLBXRgOJsbXpdN9HzU/A==", + "dev": true, + "license": "Apache-2.0" + }, "node_modules/keyv": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/keyv/-/keyv-5.6.0.tgz", @@ -4272,6 +4300,12 @@ "node": ">=6" } }, + "node_modules/pako": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", + "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==", + "license": "(MIT AND Zlib)" + }, "node_modules/parse5": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/parse5/-/parse5-8.1.1.tgz", @@ -4328,6 +4362,24 @@ "node": ">=8" } }, + "node_modules/pdf-lib": { + "version": "1.17.1", + "resolved": "https://registry.npmjs.org/pdf-lib/-/pdf-lib-1.17.1.tgz", + "integrity": "sha512-V/mpyJAoTsN4cnP31vc0wfNA1+p20evqqnap0KLoRUN0Yk/p3wN52DOEsL4oBFcLdb76hlpKPtzJIgo67j/XLw==", + "license": "MIT", + "dependencies": { + "@pdf-lib/standard-fonts": "^1.0.0", + "@pdf-lib/upng": "^1.0.1", + "pako": "^1.0.11", + "tslib": "^1.11.1" + } + }, + "node_modules/pdf-lib/node_modules/tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "license": "0BSD" + }, "node_modules/picocolors": { "version": "1.1.1", "dev": true, @@ -4443,6 +4495,12 @@ "dev": true, "license": "MIT" }, + "node_modules/qrcode-generator": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/qrcode-generator/-/qrcode-generator-2.0.4.tgz", + "integrity": "sha512-mZSiP6RnbHl4xL2Ap5HfkjLnmxfKcPWpWe/c+5XxCuetEenqmNFf1FH/ftXPCtFG5/TDobjsjz6sSNL0Sr8Z9g==", + "license": "MIT" + }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", diff --git a/package.json b/package.json index f854a94..120874d 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,8 @@ "@fontsource-variable/space-grotesk": "^5.3.0", "clsx": "2.1.1", "lucide-react": "^1.18.0", + "pdf-lib": "^1.17.1", + "qrcode-generator": "^2.0.4", "react": "19.2.6", "react-dom": "19.2.6", "react-router-dom": "^7.17.0", @@ -49,6 +51,7 @@ "gh-pages": "^6.3.0", "globals": "^17.14.0", "jsdom": "^31.0.1", + "jsqr": "^1.4.0", "sharp": "^0.35.5", "tailwindcss": "4.1.17", "typescript": "5.9.3", diff --git a/src/components/Flyer/FlyerActions.tsx b/src/components/Flyer/FlyerActions.tsx new file mode 100644 index 0000000..84efbae --- /dev/null +++ b/src/components/Flyer/FlyerActions.tsx @@ -0,0 +1,154 @@ +import { useMemo, useState } from "react"; +import { AlertTriangle, Check, Download, Loader2, Printer } from "lucide-react"; +import { cn } from "../../utils/cn"; +import { FlyerConfigurationError, downloadFlyer, printFlyer, resolveFlyerOrigin } from "../../services/flyer"; + +type Status = { tone: "ok" | "warn" | "error"; text: string } | null; + +interface FlyerActionsProps { + variant?: "full" | "compact"; + className?: string; + /** Show the printer button (kept on for every surface by default). */ + showPrint?: boolean; +} + +/** + * Download / print controls for the 5 × 7 in promotional flyer. + * + * The PDF is generated in the browser on demand, so the button always hands + * out the current design with a QR code for the live production address — there + * is no stale static file to forget about, and no server work. + */ +export default function FlyerActions({ variant = "full", className, showPrint = true }: FlyerActionsProps) { + const [busy, setBusy] = useState<"download" | "print" | null>(null); + const [status, setStatus] = useState(null); + + const origin = useMemo(() => resolveFlyerOrigin(), []); + const compact = variant === "compact"; + + const handleDownload = async () => { + if (busy) return; + setBusy("download"); + setStatus(null); + try { + const file = await downloadFlyer(); + setStatus({ + tone: "ok", + text: `Saved ${file.fileName} — ${file.millimetres.width} × ${file.millimetres.height} mm, print at 100%.`, + }); + } catch (error) { + setStatus({ + tone: error instanceof FlyerConfigurationError ? "warn" : "error", + text: + error instanceof FlyerConfigurationError + ? error.message + : "The flyer could not be generated in this browser. Please try again.", + }); + } finally { + setBusy(null); + } + }; + + const handlePrint = async () => { + if (busy) return; + setBusy("print"); + setStatus(null); + try { + const { printed } = await printFlyer(); + setStatus({ + tone: "ok", + text: printed + ? "Opened the PDF in a new tab — in the print dialogue choose 100% / Actual size." + : "Your browser blocked the new tab, so the flyer was downloaded instead. Print it at 100%.", + }); + } catch (error) { + setStatus({ + tone: error instanceof FlyerConfigurationError ? "warn" : "error", + text: + error instanceof FlyerConfigurationError + ? error.message + : "The flyer could not be generated in this browser. Please try again.", + }); + } finally { + setBusy(null); + } + }; + + return ( +
+
+ + + {showPrint && ( + + )} +
+ + {compact ? ( +

+ 5 × 7 in print-ready PDF · QR links to{" "} + {origin.origin ? origin.host : "the live site once configured"} +

+ ) : ( +

+ One-page, print-ready PDF · exactly 5 × 7 in (127 × 177.8 mm) · the QR code links to{" "} + {origin.origin ? origin.host : "the live site once configured"}. Free to + download, print and share — no account needed. +

+ )} + +
+ {status && ( +

+ {status.tone === "ok" ? ( +

+ )} +
+ + {!origin.origin && ( +

+

+ )} + + {!compact && ( +

+ Wrapper artwork and logo are original PokeGuru designs. Promotional flyer for an unofficial fan-made companion — no physical + cards are supplied and there is no affiliation with The Pokémon Company. +

+ )} +
+ ); +} diff --git a/src/components/Flyer/FlyerPreview.tsx b/src/components/Flyer/FlyerPreview.tsx new file mode 100644 index 0000000..6bda959 --- /dev/null +++ b/src/components/Flyer/FlyerPreview.tsx @@ -0,0 +1,54 @@ +import { useEffect, useState } from "react"; +import { cn } from "../../utils/cn"; +import { buildFlyerSvg, resolveFlyerOrigin } from "../../services/flyer"; + +interface FlyerPreviewProps { + className?: string; + /** Alt text for the rasterised preview. */ + label?: string; +} + +/** + * Live vector preview of the printable flyer, rendered from exactly the same + * scene as the PDF so what visitors see is what the printer gets. + */ +export default function FlyerPreview({ className, label = "Preview of the printable PokeGuru 5 × 7 in flyer" }: FlyerPreviewProps) { + const [src, setSrc] = useState(null); + const [failed, setFailed] = useState(false); + + useEffect(() => { + let cancelled = false; + if (!resolveFlyerOrigin().origin) { + setFailed(true); + return; + } + buildFlyerSvg() + .then((svg) => { + if (cancelled) return; + setSrc(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`); + }) + .catch(() => { + if (!cancelled) setFailed(true); + }); + return () => { + cancelled = true; + }; + }, []); + + return ( +
+ {src ? ( + {label} + ) : ( +
+ {failed ? "Flyer preview needs a live site address (VITE_PUBLIC_SITE_URL)." : "Rendering flyer preview…"} +
+ )} +
+ ); +} diff --git a/src/components/Layout/Footer.tsx b/src/components/Layout/Footer.tsx index 8e2a1d4..62aa782 100644 --- a/src/components/Layout/Footer.tsx +++ b/src/components/Layout/Footer.tsx @@ -1,6 +1,7 @@ import { ExternalLink, Info } from "lucide-react"; import { Link } from "react-router-dom"; import { BuyMeAPackPanel } from "../UI/BuyMeAPack"; +import FlyerActions from "../Flyer/FlyerActions"; import Brand from "./Brand"; const LINKS = [ @@ -53,6 +54,11 @@ export default function Footer() { Source on GitHub + +
+

Share PokeGuru

+ +