Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
refactor: extract shared festive-preset injector, add it to the Forge
fudjia285ec7f10ad0
diff --git a/pages/forge.html b/pages/forge.htmlindex fdd8588b6..ffd1ef048 100644--- a/pages/forge.html+++ b/pages/forge.html@@ -1195,6 +1195,23 @@border-color: var(--accent);background: var(--accent-soft);}+ /* Independence Day presets (July 1–5) — soft red/white/blue edge so+ they read as seasonal alongside the library chips. Injected by+ forge.js only within the window; pinned across "More ideas". */+ .chip--festive {+ border-color: color-mix(in srgb, #6f8cff 55%, var(--stroke));+ background: linear-gradient(+ 90deg,+ color-mix(in srgb, #ff5a5f 10%, var(--surface-1)),+ color-mix(in srgb, #6f8cff 10%, var(--surface-1))+ );+ }+ .chip--festive::before {+ content: '🎆 ';+ }+ .chip--festive:hover {+ border-color: #ff5a5f;+ }/* Workspace / states ------------------------------------------ */.stage {diff --git a/src/create-prompt.js b/src/create-prompt.jsindex 3e678e97d..71530c98b 100644--- a/src/create-prompt.js+++ b/src/create-prompt.js@@ -15,6 +15,7 @@*/import { log } from './shared/log.js';+import { injectFestivePresets } from './shared/festive-presets.js';const SUBMIT_ENDPOINT = '/api/avatars/reconstruct';const STATUS_ENDPOINT = '/api/avatars/regenerate-status';@@ -79,30 +80,18 @@ promptEl.addEventListener('keydown', (e) => {});// Independence Day (July 1–5, viewer's local time): prepend a set of themed-// "Made in America" presets so the seasonal moment reaches the create flow, not-// just the homepage. They self-retire outside the window — no dead copy ships-// out of season — and are wired through the same generic handler below.-(() => {- const now = new Date();- if (now.getMonth() !== 6 || now.getDate() > 5) return;- const container = document.querySelector('.examples');- if (!container) return;- const FESTIVE = [+// "Made in America" avatar presets so the seasonal moment reaches the create+// flow, not just the homepage. They self-retire outside the window and are+// wired through the same generic handler below (fill the composer — no submit).+injectFestivePresets({+ container: document.querySelector('.examples'),+ prompts: ['Uncle Sam in a star-spangled top hat and tailcoat, confident stance','A bald eagle mascot in a blue bomber jacket, wings folded, proud pose','Lady Liberty reimagined as a hero, flowing robe, torch raised high','A firework sparkler sprite, glowing red-white-and-blue trails, cheerful',- ];- const frag = document.createDocumentFragment();- for (const text of FESTIVE) {- const btn = document.createElement('button');- btn.className = 'example example--festive';- btn.type = 'button';- btn.textContent = text;- frag.appendChild(btn);- }- container.prepend(frag);-})();+ ],+});for (const chip of document.querySelectorAll('.example')) {chip.addEventListener('click', () => {diff --git a/src/forge-prompt-studio.js b/src/forge-prompt-studio.jsindex 8f818fd6d..c974ccd67 100644--- a/src/forge-prompt-studio.js+++ b/src/forge-prompt-studio.js@@ -233,7 +233,9 @@ function surprise() {function shuffleChips() {if (!els.examples) return;- const chips = [...els.examples.querySelectorAll('.chip')];+ // Seasonal presets (.chip--festive) are pinned — "More ideas" only rotates+ // the regular library chips, never overwrites the festive prompts.+ const chips = [...els.examples.querySelectorAll('.chip:not(.chip--festive)')];if (!chips.length) return;const current = new Set(chips.map((c) => c.textContent.trim()));const fresh = pickDistinct(chips.length, current);diff --git a/src/forge.js b/src/forge.jsindex a7a405cbe..eda3e721b 100644--- a/src/forge.js+++ b/src/forge.js@@ -10,6 +10,7 @@ import {onGate,trackUpgradeConverted,} from './three-access.js';+import { injectFestivePresets } from './shared/festive-presets.js';import { renderLock, lockStateFromAccess } from './three-lock.js';import { payForHighGeneration } from './forge-pay.js';import { initWalletButton, getConnectedWalletAddress } from './wallet.js';@@ -2321,6 +2322,23 @@ els.examples.addEventListener('click', (e) => {submit();});+// Independence Day (July 1–5): a few festive single-object prompts so the+// seasonal moment reaches the Forge too. They carry the `.chip` class, so the+// delegation above generates them one-click; the `.chip--festive` modifier both+// styles them and keeps "More ideas" from shuffling their text away+// (forge-prompt-studio.js excludes it). Self-retires out of season.+injectFestivePresets({+ container: els.examples,+ chipClass: 'chip',+ festiveClass: 'chip--festive',+ prompts: [+ 'a bald eagle statue, wings spread, patriotic pose',+ 'a rippling American flag on a golden pole',+ 'a cracked liberty bell, aged bronze, wooden yoke',+ 'a glossy firework rocket, red white and blue',+ ],+});+// Quality tier + engine + BYOK key wiring.els.tier?.addEventListener('click', (e) => {const btn = e.target.closest('button[data-tier]');diff --git a/src/shared/festive-presets.js b/src/shared/festive-presets.jsnew file mode 100644index 000000000..a42152923--- /dev/null+++ b/src/shared/festive-presets.js@@ -0,0 +1,72 @@+/**+ * Seasonal preset injector — shared across the creation surfaces so the+ * Independence Day (July 1–5, viewer's local time) moment is consistent and+ * self-retiring. Outside the window this injects nothing, so the themed presets+ * never ship as dead copy and the callers need no seasonal branching of their+ * own.+ *+ * The helper only builds and inserts the preset buttons; each surface keeps its+ * own click idiom. Two surfaces already delegate clicks from the container+ * (`/create/prompt` fills the composer, `/forge` fills + generates), so simply+ * prepending buttons with the surface's chip class wires them for free. Callers+ * that wire per-element can use the returned button list.+ *+ * @example+ * import { injectFestivePresets } from './shared/festive-presets.js';+ * injectFestivePresets({+ * container: document.querySelector('.examples'),+ * prompts: ['Uncle Sam in a star-spangled top hat…'],+ * });+ */++/**+ * True during the Independence Day decoration window (July 1–5 inclusive) in+ * the given date's local time. Matches the gate used by public/seasonal.js so+ * every seasonal surface appears and retires together.+ * @param {Date} [date]+ * @returns {boolean}+ */+export function isIndependenceDayWindow(date = new Date()) {+ return date.getMonth() === 6 && date.getDate() <= 5;+}++/**+ * Prepend festive preset buttons to a container when in season.+ *+ * @param {object} opts+ * @param {Element|null} opts.container Where the presets are inserted.+ * @param {string[]} opts.prompts Preset prompt strings (button text).+ * @param {string} [opts.chipClass='example'] Base class the surface's click+ * handler/delegation matches on.+ * @param {string} [opts.festiveClass='example--festive'] Seasonal modifier class+ * for styling and shuffle-exclusion.+ * @param {Date} [opts.now] Injectable clock (for tests).+ * @returns {HTMLButtonElement[]} The inserted buttons (empty out of season, or+ * if the container is missing / already injected).+ */+export function injectFestivePresets({+ container,+ prompts,+ chipClass = 'example',+ festiveClass = 'example--festive',+ now = new Date(),+} = {}) {+ if (!isIndependenceDayWindow(now)) return [];+ if (!container || !Array.isArray(prompts) || prompts.length === 0) return [];+ // Idempotent: never double-inject if a surface re-runs its init.+ if (container.dataset.festiveInjected === '1') return [];+ container.dataset.festiveInjected = '1';++ const frag = document.createDocumentFragment();+ const made = /** @type {HTMLButtonElement[]} */ ([]);+ for (const text of prompts) {+ const btn = document.createElement('button');+ btn.type = 'button';+ btn.className = `${chipClass} ${festiveClass}`;+ btn.textContent = text;+ frag.appendChild(btn);+ made.push(btn);+ }+ container.prepend(frag);+ return made;+}diff --git a/tests/festive-presets.test.js b/tests/festive-presets.test.jsnew file mode 100644index 000000000..7abb952ea--- /dev/null+++ b/tests/festive-presets.test.js@@ -0,0 +1,86 @@+// @vitest-environment jsdom+//+// The shared Independence Day preset injector feeds the create + forge flows.+// A wrong date gate would show July 4 chips in December (or hide them on the+// day), and a broken prepend/idempotency guard would duplicate or misorder the+// presets on every surface — so the window edges and DOM effects are pinned.++import { describe, expect, it, beforeEach } from 'vitest';+import { injectFestivePresets, isIndependenceDayWindow } from '../src/shared/festive-presets.js';++const JULY = (day) => new Date(2026, 6, day); // month 6 === July+const PROMPTS = ['Uncle Sam', 'A bald eagle', 'Lady Liberty'];++describe('isIndependenceDayWindow', () => {+ it('is true across July 1–5', () => {+ for (const d of [1, 2, 3, 4, 5]) expect(isIndependenceDayWindow(JULY(d))).toBe(true);+ });++ it('is false on July 6 and later', () => {+ expect(isIndependenceDayWindow(JULY(6))).toBe(false);+ expect(isIndependenceDayWindow(JULY(20))).toBe(false);+ });++ it('is false in other months (June 30, Dec 25)', () => {+ expect(isIndependenceDayWindow(new Date(2026, 5, 30))).toBe(false);+ expect(isIndependenceDayWindow(new Date(2026, 11, 25))).toBe(false);+ });+});++describe('injectFestivePresets', () => {+ let container;+ beforeEach(() => {+ document.body.innerHTML = '';+ container = document.createElement('div');+ const existing = document.createElement('button');+ existing.className = 'example';+ existing.textContent = 'Existing chip';+ container.appendChild(existing);+ document.body.appendChild(container);+ });++ it('prepends one button per prompt, ahead of existing chips', () => {+ const made = injectFestivePresets({ container, prompts: PROMPTS, now: JULY(4) });+ expect(made).toHaveLength(3);+ const buttons = [...container.querySelectorAll('button')];+ expect(buttons).toHaveLength(4); // 3 festive + 1 existing+ // festive come first, in order, existing last+ expect(buttons.map((b) => b.textContent)).toEqual([...PROMPTS, 'Existing chip']);+ });++ it('applies the base + festive classes and type=button', () => {+ const [btn] = injectFestivePresets({ container, prompts: PROMPTS, now: JULY(4) });+ expect(btn.classList.contains('example')).toBe(true);+ expect(btn.classList.contains('example--festive')).toBe(true);+ expect(btn.type).toBe('button');+ });++ it('honors custom chip/festive class names', () => {+ const [btn] = injectFestivePresets({+ container,+ prompts: PROMPTS,+ chipClass: 'chip',+ festiveClass: 'chip--festive',+ now: JULY(4),+ });+ expect(btn.className).toBe('chip chip--festive');+ });++ it('injects nothing outside the window', () => {+ const made = injectFestivePresets({ container, prompts: PROMPTS, now: new Date(2026, 11, 25) });+ expect(made).toEqual([]);+ expect(container.querySelectorAll('button')).toHaveLength(1);+ });++ it('is idempotent — a second call does not duplicate', () => {+ injectFestivePresets({ container, prompts: PROMPTS, now: JULY(4) });+ const second = injectFestivePresets({ container, prompts: PROMPTS, now: JULY(4) });+ expect(second).toEqual([]);+ expect(container.querySelectorAll('.example--festive')).toHaveLength(3);+ });++ it('returns [] for a missing container or empty prompts', () => {+ expect(injectFestivePresets({ container: null, prompts: PROMPTS, now: JULY(4) })).toEqual([]);+ expect(injectFestivePresets({ container, prompts: [], now: JULY(4) })).toEqual([]);+ });+});