Gelato / index.html
Unmid's picture
Rename little-chick-nest-demo.html to index.html
1eb8aba verified
Raw History Blame Contribute Delete
37.9 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Little Chick Nest β€” Demo Store</title>
<!--
=====================================================================
LITTLE CHICK NEST β€” DEMO STOREFRONT (single HTML file)
=====================================================================
SAFETY:
- 100% MOCK DATA. No Gelato API key anywhere in this file.
- No API key is stored in this file. To see real products, tap
"Connect Gelato" and type the key on your device; it stays in your
browser only.
- Only GET (read) calls to Gelato. A guard below blocks any
POST / PUT / PATCH / DELETE to Gelato.
- "Add to Cart" only shows a demo popup. No checkout, no payment,
no order is ever sent anywhere.
=====================================================================
-->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Fredoka:wght@500;600&family=Nunito:wght@400;600;700&display=swap" rel="stylesheet">
<style>
:root{
--cream:#FFF8EC; --cream-2:#FCEFD9; --yellow:#FFE7A3; --yellow-2:#FFD66B;
--accent:#E9A92C; --ink:#4A3B2A; --ink-soft:#7B6A55; --white:#FFFFFF;
--line:#EFE2CC; --radius:18px; --shadow:0 8px 28px rgba(122,92,40,.10);
}
*{box-sizing:border-box;margin:0;padding:0}
html{scroll-behavior:smooth}
body{font-family:Nunito,system-ui,-apple-system,Segoe UI,sans-serif;background:var(--cream);color:var(--ink);line-height:1.5}
h1,h2,h3,.logo{font-family:Fredoka,Nunito,sans-serif;font-weight:600}
button{font:inherit;cursor:pointer}
img{display:block;max-width:100%}
/* Demo banner */
.demo-bar{background:var(--ink);color:var(--yellow);text-align:center;font-size:13px;font-weight:700;padding:8px 12px;letter-spacing:.3px}
/* Header */
header{position:sticky;top:0;z-index:20;background:rgba(255,248,236,.94);backdrop-filter:blur(8px);border-bottom:1px solid var(--line)}
.nav{max-width:1180px;margin:auto;display:flex;align-items:center;justify-content:space-between;padding:14px 20px;gap:16px}
.logo{display:flex;align-items:center;gap:10px;font-size:22px;color:var(--ink);text-decoration:none}
.logo-mark{width:38px;height:38px}
.nav-links{display:flex;gap:26px;list-style:none;font-weight:700;font-size:15px}
.nav-links a{color:var(--ink-soft);text-decoration:none}
.nav-links a:hover{color:var(--ink)}
.cart-btn{position:relative;background:var(--white);border:1px solid var(--line);border-radius:999px;padding:8px 14px;font-weight:700;color:var(--ink);display:flex;gap:8px;align-items:center}
.cart-count{background:var(--yellow-2);border-radius:999px;font-size:12px;min-width:22px;height:22px;display:grid;place-items:center;padding:0 6px}
/* Hero */
.hero{max-width:1180px;margin:auto;padding:48px 20px 24px;display:grid;grid-template-columns:1.1fr .9fr;gap:30px;align-items:center}
.hero h1{font-size:clamp(32px,5vw,52px);line-height:1.1}
.hero h1 span{background:linear-gradient(transparent 60%,var(--yellow) 60%)}
.hero p{color:var(--ink-soft);font-size:18px;margin:16px 0 24px;max-width:480px}
.btn{display:inline-block;background:var(--ink);color:var(--cream);border:none;border-radius:999px;padding:14px 28px;font-weight:700;text-decoration:none;transition:transform .15s}
.btn:hover{transform:translateY(-2px)}
.hero-art{background:var(--yellow);border-radius:40% 60% 55% 45%/50% 45% 55% 50%;aspect-ratio:1;display:grid;place-items:center;box-shadow:var(--shadow)}
.hero-art svg{width:62%}
/* Section */
section{max-width:1180px;margin:auto;padding:36px 20px}
.section-head{display:flex;justify-content:space-between;align-items:end;margin-bottom:22px;gap:12px;flex-wrap:wrap}
.section-head h2{font-size:30px}
.section-head p{color:var(--ink-soft)}
/* Product grid */
.grid{display:grid;grid-template-columns:repeat(3,1fr);gap:22px}
.card{background:var(--white);border-radius:var(--radius);overflow:hidden;box-shadow:var(--shadow);transition:transform .2s;cursor:pointer;border:1px solid var(--line)}
.card:hover{transform:translateY(-4px)}
.card-img{aspect-ratio:1;background:var(--cream-2)}
.card-img img{width:100%;height:100%;object-fit:cover;transition:opacity .2s}
.card-body{padding:16px 18px 20px}
.card-body h3{font-size:18px}
.price{font-weight:700;color:var(--ink);margin:4px 0 10px}
.mini-swatches{display:flex;gap:8px}
/* Swatches */
.swatch{width:26px;height:26px;border-radius:50%;border:2px solid var(--white);box-shadow:0 0 0 1px #d9cbb2;transition:box-shadow .15s,transform .15s}
.swatch:hover{transform:scale(1.1)}
.swatch.active{box-shadow:0 0 0 2px var(--ink)}
.swatch-lg{width:38px;height:38px}
/* Product detail */
.pdp{display:grid;grid-template-columns:1.05fr 1fr;gap:40px;background:var(--white);border-radius:28px;padding:28px;box-shadow:var(--shadow);border:1px solid var(--line)}
.gallery-main{aspect-ratio:1;border-radius:var(--radius);overflow:hidden;background:var(--cream-2);position:relative}
.gallery-main img{width:100%;height:100%;object-fit:cover;transition:opacity .25s}
.gallery-main img.fade{opacity:0}
.color-tag{position:absolute;top:14px;left:14px;background:rgba(255,255,255,.9);border-radius:999px;padding:6px 12px;font-size:13px;font-weight:700}
.thumbs{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin-top:12px}
.thumb{border:2px solid transparent;border-radius:14px;overflow:hidden;padding:0;background:var(--cream-2);aspect-ratio:1}
.thumb.active{border-color:var(--ink)}
.thumb img{width:100%;height:100%;object-fit:cover}
.pdp-info h2{font-size:32px;line-height:1.15}
.pdp-price{font-size:24px;font-weight:700;margin:8px 0 6px}
.pdp-desc{color:var(--ink-soft);margin-bottom:20px}
.opt-label{font-weight:700;margin:18px 0 10px;display:flex;gap:6px}
.opt-label span{font-weight:400;color:var(--ink-soft)}
.swatch-row{display:flex;gap:12px;flex-wrap:wrap}
.size-row{display:flex;gap:10px;flex-wrap:wrap}
.size{min-width:54px;padding:10px 14px;border-radius:12px;border:1.5px solid var(--line);background:var(--white);font-weight:700;color:var(--ink)}
.size.active{background:var(--ink);color:var(--cream);border-color:var(--ink)}
.buy-row{display:flex;gap:12px;margin-top:24px;flex-wrap:wrap}
.qty{display:flex;align-items:center;border:1.5px solid var(--line);border-radius:999px;overflow:hidden}
.qty button{width:44px;height:50px;border:none;background:var(--white);font-size:20px;color:var(--ink)}
.qty input{width:44px;text-align:center;border:none;font:inherit;font-weight:700;color:var(--ink);background:transparent}
.add-btn{flex:1;min-width:200px;background:var(--yellow-2);color:var(--ink);border:none;border-radius:999px;font-weight:700;font-size:16px;padding:0 24px;height:52px;transition:background .15s}
.add-btn:hover{background:var(--accent)}
.perks{margin-top:22px;display:grid;gap:8px;font-size:14px;color:var(--ink-soft)}
.debug{margin-top:20px;background:var(--cream);border:1px dashed #E2CFA8;border-radius:12px;padding:10px 12px;font-size:12px;font-family:ui-monospace,Menlo,monospace;color:var(--ink-soft);word-break:break-all}
/* Modal */
.modal-bg{position:fixed;inset:0;background:rgba(74,59,42,.45);display:none;place-items:center;z-index:50;padding:20px}
.modal-bg.show{display:grid}
.modal{background:var(--white);border-radius:24px;padding:28px;max-width:400px;width:100%;text-align:center;box-shadow:0 20px 60px rgba(0,0,0,.2)}
.modal h3{font-size:22px;margin:10px 0 6px}
.modal p{color:var(--ink-soft);font-size:15px}
.modal .summary{background:var(--cream);border-radius:12px;padding:12px;margin:16px 0;font-size:14px;text-align:left}
.modal svg{width:64px;margin:auto}
.field{width:100%;padding:12px 14px;border:1.5px solid var(--line);border-radius:12px;font:inherit;color:var(--ink);background:var(--cream)}
.field:focus{outline:2px solid var(--yellow-2);border-color:transparent}
#connectModal .opt-label{margin:14px 0 6px}
footer{text-align:center;padding:40px 20px;color:var(--ink-soft);font-size:14px;border-top:1px solid var(--line);margin-top:30px}
/* Responsive */
@media (max-width:900px){
.grid{grid-template-columns:repeat(2,1fr)}
.pdp{grid-template-columns:1fr;padding:18px;gap:24px}
.hero{grid-template-columns:1fr;text-align:center}
.hero p{margin-left:auto;margin-right:auto}
.hero-art{max-width:300px;margin:auto}
.nav-links{display:none}
}
@media (max-width:560px){
.grid{grid-template-columns:1fr}
.pdp-info h2{font-size:26px}
section{padding:28px 14px}
}
</style>
</head>
<body>
<div class="demo-bar" id="modeBar">🐣 DEMO PREVIEW β€” mock data only Β· not connected to Gelato Β· no real orders</div>
<header>
<nav class="nav">
<a href="#" class="logo">
<svg class="logo-mark" viewBox="0 0 64 64"><ellipse cx="32" cy="50" rx="26" ry="9" fill="#C9A26A"/><circle cx="32" cy="32" r="18" fill="#FFD66B"/><circle cx="38" cy="28" r="2.6" fill="#4A3B2A"/><path d="M48 32 L56 35 L48 38 Z" fill="#E9A92C"/><path d="M22 34 q6 6 12 0" fill="none" stroke="#E9A92C" stroke-width="2.5" stroke-linecap="round"/></svg>
Little Chick Nest
</a>
<ul class="nav-links">
<li><a href="#shop">Shop</a></li>
<li><a href="#product">New In</a></li>
<li><a href="#">About</a></li>
</ul>
<div style="display:flex;gap:8px">
<button class="cart-btn" id="connectBtn">πŸ”— <span id="connectLabel">Connect Gelato</span></button>
<button class="cart-btn" id="cartBtn">πŸ›’ <span class="cart-count" id="cartCount">0</span></button>
</div>
</nav>
</header>
<div class="hero">
<div>
<h1>Soft clothes for your <span>little chicks</span></h1>
<p>Cozy hoodies, tees and bodysuits made for tiny adventures. Printed on demand, gentle on skin.</p>
<a class="btn" href="#shop">Shop the collection</a>
</div>
<div class="hero-art" id="heroArt"></div>
</div>
<section id="shop">
<div class="section-head">
<div><h2>The Collection</h2><p>Hover a color dot to preview it</p></div>
</div>
<div class="grid" id="grid"></div>
</section>
<section id="product">
<div class="pdp">
<div>
<div class="gallery-main">
<img id="mainImg" alt="Product mockup">
<div class="color-tag" id="colorTag"></div>
</div>
<div class="thumbs" id="thumbs"></div>
</div>
<div class="pdp-info">
<h2 id="pTitle"></h2>
<div class="pdp-price" id="pPrice"></div>
<p class="pdp-desc" id="pDesc"></p>
<div class="opt-label">Color: <span id="colorName"></span></div>
<div class="swatch-row" id="swatches"></div>
<div class="opt-label">Size: <span id="sizeName"></span></div>
<div class="size-row" id="sizes"></div>
<div class="buy-row">
<div class="qty">
<button id="qtyMinus" aria-label="Decrease">βˆ’</button>
<input id="qty" type="text" inputmode="numeric" value="1" aria-label="Quantity">
<button id="qtyPlus" aria-label="Increase">+</button>
</div>
<button class="add-btn" id="addBtn">Add to Cart</button>
</div>
<div class="perks">
<div>🌱 Soft, breathable cotton blend</div>
<div>πŸ“¦ Printed on demand, shipped worldwide</div>
<div>πŸ’› Easy 30-day returns</div>
</div>
<div class="debug" id="debug"></div>
</div>
</div>
</section>
<footer>Β© Little Chick Nest Β· Demo storefront Β· Mock data only β€” nothing here talks to Gelato</footer>
<div class="modal-bg" id="connectModal">
<div class="modal" style="text-align:left">
<h3>Connect Gelato (read-only)</h3>
<p>Shows your real products. This page only reads β€” it cannot create, change or order anything.</p>
<label class="opt-label" for="inKey">API key</label>
<input id="inKey" class="field" type="password" autocomplete="off" placeholder="Paste API key">
<label class="opt-label" for="inStore">Store ID</label>
<input id="inStore" class="field" type="text" autocomplete="off" placeholder="From your store page in Gelato">
<label style="display:flex;gap:8px;align-items:center;margin-top:14px;font-size:14px;color:var(--ink-soft)">
<input type="checkbox" id="inRemember"> Remember on this phone
</label>
<div id="connectMsg" style="margin-top:12px;font-size:14px;min-height:20px"></div>
<div style="display:flex;gap:10px;margin-top:14px;flex-wrap:wrap">
<button class="btn" id="doConnect">Load my products</button>
<button class="size" id="doForget">Forget key</button>
<button class="size" id="closeConnect">Close</button>
</div>
</div>
</div>
<div class="modal-bg" id="modal">
<div class="modal">
<svg viewBox="0 0 64 64"><circle cx="32" cy="32" r="30" fill="#FFE7A3"/><path d="M20 33 l8 8 l16 -18" fill="none" stroke="#4A3B2A" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/></svg>
<h3>Demo β€” No real order sent to Gelato</h3>
<p>This is a preview store. Nothing was charged, created or ordered.</p>
<div class="summary" id="summary"></div>
<button class="btn" id="closeModal">Got it</button>
</div>
</div>
<script>
/* =====================================================================
0) SAFETY GUARD β€” only GET (read) requests may go to Gelato.
Any POST / PUT / PATCH / DELETE to a Gelato address is rejected here,
so nothing on this page can create, change, delete or order anything.
===================================================================== */
(function(){
const realFetch = window.fetch ? window.fetch.bind(window) : null;
window.fetch = function(url, opts){
const u = String(url && url.url ? url.url : url);
const method = String((opts && opts.method) || (url && url.method) || "GET").toUpperCase();
if (/gelato/i.test(u) && method !== "GET") {
console.warn("[READ-ONLY GUARD] Blocked", method, "request to Gelato:", u);
return Promise.reject(new Error("Read-only: only GET requests to Gelato are allowed"));
}
return realFetch ? realFetch(url, opts) : Promise.reject(new Error("fetch unavailable"));
};
const realOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url){
if (/gelato/i.test(String(url)) && String(method).toUpperCase() !== "GET") throw new Error("Read-only: only GET to Gelato");
return realOpen.apply(this, arguments);
};
})();
/* =====================================================================
1) FAKE, READ-ONLY "GELATO-LIKE" JSON
Shaped roughly like what a backend would get from a Gelato product
GET call. IDs are made up. No API key. Nothing is fetched.
===================================================================== */
const FAKE_GELATO_RESPONSE = {
products: [
{
id: "demo-prod-hoodie-001",
key: "hoodie",
title: "Classic Kids Pullover Hoodie",
description: "Our coziest pullover with a roomy hood and front pocket. Perfect for chilly park days.",
price: { amount: 34.00, currency: "USD" },
shape: "hoodie",
colors: [
{ key: "white", name: "White", hex: "#FAFAF7" },
{ key: "pink", name: "Pink", hex: "#F6C1CF" },
{ key: "navy", name: "Navy", hex: "#2C3A5A" }
]
},
{
id: "demo-prod-tee-002",
key: "tee",
title: "Kids Classic Tee",
description: "Everyday soft tee with our little chick on the chest. Pre-shrunk and wash-friendly.",
price: { amount: 19.00, currency: "USD" },
shape: "tee",
colors: [
{ key: "white", name: "White", hex: "#FAFAF7" },
{ key: "sand", name: "Sand", hex: "#E3D1B0" },
{ key: "navy", name: "Navy", hex: "#2C3A5A" }
]
},
{
id: "demo-prod-bodysuit-003",
key: "bodysuit",
title: "Baby Bodysuit",
description: "Gentle short-sleeve bodysuit with easy snap closure. Made for wiggly little ones.",
price: { amount: 16.00, currency: "USD" },
shape: "bodysuit",
colors: [
{ key: "white", name: "White", hex: "#FAFAF7" },
{ key: "yellow", name: "Yellow", hex: "#FFDD75" }
]
}
]
};
const SIZES = ["XS", "S", "M", "L"];
/* =====================================================================
2) MOCKUP IMAGES PER COLOR
Final structure (same as the real site would use):
mockups = {
"hoodie": { "white": ["img1","img2","img3"], "pink": [...], "navy": [...] },
"tee": { "white": [...], "sand": [...], "navy": [...] },
"bodysuit": { "white": [...], "yellow": [...] }
}
For the demo, each "img" is a generated SVG placeholder tinted in
the real garment color and labeled e.g. "Mockup – Pink Β· Front",
so you can SEE the switch happen. In the real site these strings
would simply be the Gelato mockup URLs saved in your database.
===================================================================== */
const VIEWS = ["Front", "Back", "Detail"];
function shade(hex, amt){
const n = parseInt(hex.slice(1), 16);
const c = s => Math.max(0, Math.min(255, ((n >> s) & 255) + amt));
return "#" + [16, 8, 0].map(s => c(s).toString(16).padStart(2, "0")).join("");
}
function chick(x, y, s){
return `<g transform="translate(${x} ${y}) scale(${s})">
<circle r="20" fill="#FFD66B" stroke="#E9A92C" stroke-width="2"/>
<circle cx="6" cy="-4" r="2.8" fill="#4A3B2A"/>
<path d="M18 0 L27 3 L18 6 Z" fill="#E9A92C"/>
<path d="M-10 4 q6 6 12 0" fill="none" stroke="#E9A92C" stroke-width="2.5" stroke-linecap="round"/>
</g>`;
}
const SHAPES = {
tee: {
body: "M210 130 L160 145 L90 210 L130 270 L178 240 L178 480 L422 480 L422 240 L470 270 L510 210 L440 145 L390 130 Q300 185 210 130 Z",
frontExtra: (c) => `<path d="M210 130 Q300 185 390 130" fill="none" stroke="${c}" stroke-width="7"/>`,
backExtra: (c) => `<path d="M215 132 Q300 158 385 132" fill="none" stroke="${c}" stroke-width="7"/>`,
logo: [300, 245, 1.5]
},
hoodie: {
body: "M200 150 L150 170 L105 270 L85 440 L140 450 L170 310 L175 490 L425 490 L430 310 L460 450 L515 440 L495 270 L450 170 L400 150 Q300 210 200 150 Z",
frontExtra: (c, f) => `<path d="M215 155 Q300 60 385 155 Q300 215 215 155 Z" fill="${f}" stroke="${c}" stroke-width="3"/>
<path d="M245 160 Q300 105 355 160 Q300 195 245 160 Z" fill="${c}" opacity=".35"/>
<path d="M288 190 L284 250 M312 190 L316 250" stroke="${c}" stroke-width="3" stroke-linecap="round"/>
<rect x="225" y="385" width="150" height="70" rx="14" fill="none" stroke="${c}" stroke-width="3"/>`,
backExtra: (c, f) => `<path d="M212 158 Q300 40 388 158 L372 250 Q300 280 228 250 Z" fill="${f}" stroke="${c}" stroke-width="3"/>
<path d="M300 70 L300 265" stroke="${c}" stroke-width="2" opacity=".5"/>`,
logo: [300, 300, 1.5]
},
bodysuit: {
body: "M230 140 L180 160 L140 220 L180 255 L205 235 L210 395 Q250 445 270 475 L330 475 Q350 445 390 395 L395 235 L420 255 L460 220 L420 160 L370 140 Q300 185 230 140 Z",
frontExtra: (c) => `<path d="M230 140 Q300 185 370 140" fill="none" stroke="${c}" stroke-width="6"/>
<circle cx="283" cy="462" r="4.5" fill="${c}"/><circle cx="300" cy="462" r="4.5" fill="${c}"/><circle cx="317" cy="462" r="4.5" fill="${c}"/>`,
backExtra: (c) => `<path d="M235 142 Q300 165 365 142" fill="none" stroke="${c}" stroke-width="6"/>
<path d="M270 475 Q300 455 330 475" fill="none" stroke="${c}" stroke-width="3"/>`,
logo: [300, 260, 1.35]
}
};
function svgMock(shapeKey, color, view){
const S = SHAPES[shapeKey];
const fill = color.hex;
const isLight = parseInt(fill.slice(1, 3), 16) > 200;
const stroke = isLight ? "#D3C3A6" : shade(fill, -40);
const detailLine = isLight ? "#D9CBB0" : shade(fill, 30);
const label = `Mockup – ${color.name} Β· ${view}`;
let art;
if (view === "Detail") {
let knit = "";
for (let y = 120; y < 470; y += 22) {
knit += `<path d="M110 ${y} q10 10 20 0 t20 0 t20 0 t20 0 t20 0 t20 0 t20 0 t20 0 t20 0 t20 0 t20 0 t20 0 t20 0 t20 0 t20 0 t20 0 t20 0 t20 0 t20 0" fill="none" stroke="${detailLine}" stroke-width="2" opacity=".55"/>`;
}
art = `<clipPath id="cp"><circle cx="300" cy="290" r="190"/></clipPath>
<circle cx="300" cy="290" r="190" fill="${fill}" stroke="${stroke}" stroke-width="4"/>
<g clip-path="url(#cp)">${knit}</g>${chick(300, 290, 3.4)}`;
} else {
const extra = view === "Front" ? S.frontExtra(stroke, fill) : S.backExtra(stroke, fill);
art = `<ellipse cx="300" cy="510" rx="190" ry="18" fill="#000" opacity=".06"/>
<path d="${S.body}" fill="${fill}" stroke="${stroke}" stroke-width="4" stroke-linejoin="round"/>
${extra}${view === "Front" ? chick(S.logo[0], S.logo[1], S.logo[2]) : ""}`;
}
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 600">
<defs><linearGradient id="bg" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#FFF8EC"/><stop offset="1" stop-color="#FBEBCF"/></linearGradient></defs>
<rect width="600" height="600" fill="url(#bg)"/>${art}
<rect x="150" y="540" width="300" height="36" rx="18" fill="#fff" opacity=".9"/>
<text x="300" y="564" text-anchor="middle" font-family="Nunito,Arial,sans-serif" font-size="17" font-weight="700" fill="#7B6A55">${label}</text>
</svg>`;
return "data:image/svg+xml;charset=utf-8," + encodeURIComponent(svg);
}
// Build the mockups object: mockups[productKey][colorKey] = [front, back, detail]
let mockups = {};
FAKE_GELATO_RESPONSE.products.forEach(p => {
mockups[p.key] = {};
p.colors.forEach(c => { mockups[p.key][c.key] = VIEWS.map(v => svgMock(p.shape, c, v)); });
});
/* =====================================================================
3) STATE + RENDERING
===================================================================== */
let products = FAKE_GELATO_RESPONSE.products;
let MODE = "demo"; // "demo" or "live" (read-only from your Gelato store)
const viewName = i => MODE === "demo" ? VIEWS[i] : `Photo ${i + 1}`;
const state = { productKey: "hoodie", colorKey: "white", size: "S", qty: 1, imgIndex: 0, cart: 0 };
const $ = id => document.getElementById(id);
const money = p => p && typeof p.amount === "number" ? (p.currency === "USD" ? "$" : (p.currency || "$") + " ") + p.amount.toFixed(2) : "Price set in store";
const current = () => products.find(p => p.key === state.productKey);
function renderGrid(){
$("grid").innerHTML = products.map(p => `
<article class="card" data-key="${p.key}">
<div class="card-img"><img id="card-img-${p.key}" src="${mockups[p.key][p.colors[0].key][0]}" alt="${p.title}"></div>
<div class="card-body">
<h3>${p.title}</h3>
<div class="price">${money(p.price)}</div>
<div class="mini-swatches">
${p.colors.map(c => `<button class="swatch" style="background:${c.hex}" title="${c.name}"
data-key="${p.key}" data-color="${c.key}" aria-label="${c.name}"></button>`).join("")}
</div>
</div>
</article>`).join("");
$("grid").querySelectorAll(".card").forEach(card => {
card.addEventListener("click", e => {
const sw = e.target.closest(".swatch");
openProduct(card.dataset.key, sw ? sw.dataset.color : null);
});
});
// Hovering a dot on a card previews that color on the card image
$("grid").querySelectorAll(".mini-swatches .swatch").forEach(sw => {
sw.addEventListener("mouseenter", () => {
$("card-img-" + sw.dataset.key).src = mockups[sw.dataset.key][sw.dataset.color][0];
});
});
}
function openProduct(key, colorKey){
const p = products.find(x => x.key === key);
state.productKey = key;
state.colorKey = colorKey || p.colors[0].key;
state.imgIndex = 0;
renderPDP();
$("product").scrollIntoView({ behavior: "smooth" });
}
function renderPDP(){
const p = current();
$("pTitle").textContent = p.title;
$("pPrice").textContent = money(p.price);
$("pDesc").textContent = p.description;
$("swatches").innerHTML = p.colors.map(c => `
<button class="swatch swatch-lg ${c.key === state.colorKey ? "active" : ""}"
style="background:${c.hex}" data-color="${c.key}" title="${c.name}" aria-label="${c.name}"></button>`).join("");
$("swatches").querySelectorAll(".swatch").forEach(b => b.addEventListener("click", () => selectColor(b.dataset.color)));
$("sizes").innerHTML = SIZES.map(s => `<button class="size ${s === state.size ? "active" : ""}" data-size="${s}">${s}</button>`).join("");
$("sizes").querySelectorAll(".size").forEach(b => b.addEventListener("click", () => {
state.size = b.dataset.size; renderPDP();
}));
$("sizeName").textContent = state.size;
renderGallery(false);
}
/* ---- THE MAIN FEATURE: per-color mockup switching ---- */
function selectColor(colorKey){
state.colorKey = colorKey;
state.imgIndex = 0; // go back to the Front view of the new color
$("swatches").querySelectorAll(".swatch").forEach(b => b.classList.toggle("active", b.dataset.color === colorKey));
renderGallery(true);
}
function renderGallery(animate){
const p = current();
const color = p.colors.find(c => c.key === state.colorKey);
const imgs = mockups[p.key][state.colorKey]; // <- the swap: images for THIS color only
const setMain = () => { $("mainImg").src = imgs[state.imgIndex]; $("mainImg").classList.remove("fade"); };
if (animate) { $("mainImg").classList.add("fade"); setTimeout(setMain, 180); } else setMain();
$("colorTag").textContent = color.name + " Β· " + viewName(state.imgIndex);
$("colorName").textContent = color.name;
$("thumbs").innerHTML = imgs.map((src, i) => `
<button class="thumb ${i === state.imgIndex ? "active" : ""}" data-i="${i}" aria-label="${viewName(i)}">
<img src="${src}" alt="${color.name} ${viewName(i)}" loading="lazy"></button>`).join("");
$("thumbs").querySelectorAll(".thumb").forEach(t => t.addEventListener("click", () => {
state.imgIndex = +t.dataset.i; renderGallery(false);
}));
$("debug").textContent = `Demo debug β†’ mockups["${p.key}"]["${state.colorKey}"][${state.imgIndex}] Β· ` +
`${imgs.length} images for this color Β· ${MODE.toUpperCase()} Β· product: ${p.id} / ${state.colorKey} / ${state.size}`;
}
/* ---- Quantity ---- */
function setQty(n){ state.qty = Math.max(1, Math.min(99, n || 1)); $("qty").value = state.qty; }
$("qtyMinus").onclick = () => setQty(state.qty - 1);
$("qtyPlus").onclick = () => setQty(state.qty + 1);
$("qty").addEventListener("change", e => setQty(parseInt(e.target.value, 10)));
/* ---- Add to Cart: DEMO POPUP ONLY. No API call of any kind. ---- */
$("addBtn").onclick = () => {
const p = current();
const color = p.colors.find(c => c.key === state.colorKey);
state.cart += state.qty;
$("cartCount").textContent = state.cart;
$("summary").innerHTML = `<b>${p.title}</b><br>Color: ${color.name} Β· Size: ${state.size} Β· Qty: ${state.qty}<br>
${p.price ? `Total (demo): ${money({amount: p.price.amount * state.qty, currency: p.price.currency})}` : ""}`;
$("modal").classList.add("show");
};
$("cartBtn").onclick = () => {
$("summary").innerHTML = `Demo cart has <b>${state.cart}</b> item(s). Checkout is disabled in this preview.`;
$("modal").classList.add("show");
};
$("closeModal").onclick = () => $("modal").classList.remove("show");
$("modal").addEventListener("click", e => { if (e.target.id === "modal") $("modal").classList.remove("show"); });
/* ---- Hero art + init ---- */
$("heroArt").innerHTML = `<img src="${mockups.bodysuit.yellow[0]}" alt="" style="width:78%;border-radius:50%">`;
/* =====================================================================
LIVE READ-ONLY MODE
If this page is opened through the local helper (server.js), it asks
YOUR helper for products at /api/products. The helper holds the API
key and only allows GET. If the helper isn't running (e.g. you just
double-clicked the file), the page stays in demo mode.
===================================================================== */
const COLOR_HEX = { white:"#FAFAF7", black:"#222222", navy:"#2C3A5A", pink:"#F6C1CF", "light pink":"#F9D5DE",
sand:"#E3D1B0", yellow:"#FFDD75", "heather grey":"#BDBDBD", grey:"#9E9E9E", gray:"#9E9E9E", red:"#D64545",
blue:"#5B8DEF", "light blue":"#A9CBEF", green:"#5BAA6B", natural:"#F1E8D6", cream:"#F6EEDC", purple:"#9B7BC8",
lavender:"#C9B8E8", orange:"#F39A4C", mint:"#BDE6D0", brown:"#8A6446" };
function hexFor(name){
const k = name.toLowerCase().trim();
if (COLOR_HEX[k]) return COLOR_HEX[k];
const hit = Object.keys(COLOR_HEX).find(c => k.includes(c));
if (hit) return COLOR_HEX[hit];
let h = 0; for (const ch of k) h = (h * 31 + ch.charCodeAt(0)) % 360;
return `hsl(${h} 55% 72%)`;
}
const slug = s => String(s).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "default";
// Pull a color name out of a variant, whatever shape Gelato returns it in
function variantColor(v){
const opts = v.variantOptions || v.options || v.productVariantOptions || [];
const arr = Array.isArray(opts) ? opts : Object.entries(opts).map(([name, value]) => ({ name, value }));
const c = arr.find(o => /colou?r/i.test(o.name || o.key || ""));
if (c) return String(c.value || c.name);
const t = String(v.title || v.name || "");
const part = t.split(/\s*[\/|,-]\s*/).find(x => !/^(xs|s|m|l|xl|2xl|xxl|3xl|\d+.*)$/i.test(x.trim()));
return part ? part.trim() : "Default";
}
const imgUrl = x => typeof x === "string" ? x : (x && (x.fileUrl || x.url || x.src || x.previewUrl)) || null;
// Turn one Gelato store product into { product, mockupsByColor }
function normalize(gp){
const key = slug(gp.id || gp.title);
const productImgs = [gp.previewUrl, ...(gp.productImages || gp.images || []).map(imgUrl)].filter(Boolean);
const byColor = {}; const colorNames = {};
(gp.variants || []).forEach(v => {
const name = variantColor(v); const ck = slug(name);
colorNames[ck] = name;
byColor[ck] = byColor[ck] || [];
[v.previewUrl, ...(v.images || v.productImages || []).map(imgUrl)].filter(Boolean)
.forEach(u => { if (!byColor[ck].includes(u)) byColor[ck].push(u); });
});
if (!Object.keys(colorNames).length) colorNames["default"] = "Default";
// Colors with no variant-specific images: try product images whose URL mentions the color, else all product images
Object.keys(colorNames).forEach(ck => {
if (!byColor[ck] || !byColor[ck].length) {
const named = productImgs.filter(u => u.toLowerCase().includes(ck));
byColor[ck] = named.length ? named : productImgs.slice();
}
if (!byColor[ck].length) byColor[ck] = [svgMock("tee", { name: colorNames[ck], hex: "#EEE6D6" }, "Front")];
});
const priceRaw = gp.price || (gp.variants && gp.variants[0] && gp.variants[0].price);
const price = priceRaw && !isNaN(parseFloat(priceRaw.amount ?? priceRaw))
? { amount: parseFloat(priceRaw.amount ?? priceRaw), currency: priceRaw.currency || "USD" } : null;
return {
product: {
id: gp.id, key, title: gp.title || "Untitled product",
description: (gp.description || "").replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim().slice(0, 260),
price, colors: Object.entries(colorNames).map(([k, n]) => ({ key: k, name: n, hex: hexFor(n) }))
},
mockupsByColor: byColor
};
}
// getJSON(path) returns parsed JSON for "list" or a product id
async function loadLive(getJSON, label){
const list = await getJSON(null);
const items = list.products || list.data || (Array.isArray(list) ? list : []);
if (!items.length) throw new Error("No products returned");
// The list may not include full variant info, so read each product's details (GET only)
const details = await Promise.all(items.slice(0, 30).map(it =>
getJSON(it.id).catch(() => it)));
const norm = details.map(d => normalize(d.product || d));
products = norm.map(n => n.product);
mockups = {}; norm.forEach(n => { mockups[n.product.key] = n.mockupsByColor; });
MODE = "live";
state.productKey = products[0].key; state.colorKey = products[0].colors[0].key;
$("modeBar").textContent = `🟒 LIVE READ-ONLY (${label}) β€” ${products.length} real products Β· Add to Cart is still demo-only`;
$("modeBar").style.background = "#2F5D3A";
document.querySelector("#shop .section-head p").textContent = "Your real products Β· tap a color dot to see its mockups";
}
renderGrid();
renderPDP();
/* ---- Direct from the browser: GET only, key typed in by you ---- */
const GELATO_BASE = "https://ecommerce.gelatoapis.com/v1";
function directGetter(key, storeId){
return async (productId) => {
const url = `${GELATO_BASE}/stores/${encodeURIComponent(storeId)}/products` +
(productId ? "/" + encodeURIComponent(productId) : "?limit=100");
let r;
try { r = await fetch(url, { method: "GET", headers: { "X-API-KEY": key, "Accept": "application/json" } }); }
catch (e) { throw new Error("BLOCKED"); } // network/CORS failure
if (r.status === 401 || r.status === 403) throw new Error("Key rejected (" + r.status + ")");
if (r.status === 404) throw new Error("Store ID not found (404)");
if (!r.ok) throw new Error("Gelato error " + r.status);
return r.json();
};
}
const store = { get(k){ try { return localStorage.getItem(k); } catch(e){ return null; } },
set(k,v){ try { localStorage.setItem(k,v); } catch(e){} }, del(k){ try { localStorage.removeItem(k); } catch(e){} } };
async function connect(key, storeId, silent){
const msg = $("connectMsg");
msg.style.color = "var(--ink-soft)"; msg.textContent = "Loading your products…";
try {
await loadLive(directGetter(key, storeId), "direct");
renderGrid(); renderPDP();
$("connectLabel").textContent = "Connected";
$("connectModal").classList.remove("show");
} catch (err) {
msg.style.color = "#B3402F";
msg.textContent = err.message === "BLOCKED"
? "Gelato didn't let this page read from the browser (blocked request, usually CORS). Your key is fine; this needs a small proxy β€” ask Claude for the Cloudflare Worker option."
: err.message;
if (silent) $("connectModal").classList.add("show");
}
}
$("connectBtn").onclick = () => {
$("inKey").value = store.get("lcn_key") || "";
$("inStore").value = store.get("lcn_store") || "";
$("inRemember").checked = !!store.get("lcn_key");
$("connectMsg").textContent = "";
$("connectModal").classList.add("show");
};
$("closeConnect").onclick = () => $("connectModal").classList.remove("show");
$("doForget").onclick = () => { store.del("lcn_key"); store.del("lcn_store"); $("inKey").value = ""; $("connectMsg").textContent = "Key removed from this phone."; };
$("doConnect").onclick = () => {
const key = $("inKey").value.trim(), sid = $("inStore").value.trim();
if (!key || !sid) { $("connectMsg").style.color = "#B3402F"; $("connectMsg").textContent = "Enter both the API key and Store ID."; return; }
if ($("inRemember").checked) { store.set("lcn_key", key); store.set("lcn_store", sid); }
else { store.del("lcn_key"); store.del("lcn_store"); }
connect(key, sid, false);
};
// Auto-connect if you chose "Remember on this phone" earlier
if (store.get("lcn_key") && store.get("lcn_store")) connect(store.get("lcn_key"), store.get("lcn_store"), true);
/* =====================================================================
4) HOW THE REAL SITE WOULD SYNC WITH GELATO (COMMENTS ONLY β€” NOT RUN)
=====================================================================
── STEP A: Backend reads mockups from Gelato (READ-ONLY, server side) ──
File: server/sync-mockups.js (runs on your server or a cron job,
NEVER in the browser β€” the API key must never reach the frontend)
// const API_KEY = process.env.GELATO_API_KEY; // stored in .env on the server only
// const STORE_ID = process.env.GELATO_STORE_ID;
//
// // GET only β€” lists your store's products and their variants
// const res = await fetch(
// `https://ecommerce.gelatoapis.com/v1/stores/${STORE_ID}/products`,
// { method: "GET", headers: { "X-API-KEY": API_KEY } }
// );
// const { products } = await res.json();
//
// // For each product, read the variant list + preview/mockup image URLs.
// // Group the mockup URLs by color option.
── STEP B: Save to your database ──
Table: product_mockups
product_id | color | position | mockup_url
-----------+--------+----------+------------------------------
hoodie-001 | white | 0 | https://.../hoodie-white-front.png
hoodie-001 | white | 1 | https://.../hoodie-white-back.png
hoodie-001 | pink | 0 | https://.../hoodie-pink-front.png
...
// Upsert on (product_id, color, position) so re-running the sync is safe.
── STEP C: Frontend reads from YOUR database, not from Gelato ──
// const res = await fetch(`/api/products/${productId}/mockups`); // your own API
// const mockups = await res.json();
// β†’ { "white": ["url1","url2"], "pink": ["url1","url2"] }
// On swatch click: mainImg.src = mockups[colorKey][0] (exactly what
// selectColor() + renderGallery() do above with the demo data)
── STEP D: Real orders (separate backend file, never in this HTML) ──
File: server/create-order.js
// Only called AFTER the customer pays and confirms at checkout
// (e.g. a Stripe/Shopify "payment succeeded" webhook).
// That server file β€” and only that file β€” would POST the order to
// Gelato's order API with the API key from the server environment.
// This demo page contains no such code and blocks any Gelato request.
===================================================================== */
</script>
</body>
</html>