Spaces:
Running
Running
hugApi for the agent API; README
Browse filesFiles changed (2)
- README.md+10
- src/main.ts+51-13
46 unmodified lines47484946 unmodified lines- `src/hands.ts` keeps the right hand near home (small snap to the nearest edge) and letsthe left hand pick the best grip point on the logo's far edges.- `src/main.ts` wires the scene, interaction and export.46 unmodified lines4748495051525354555657585946 unmodified lines- `src/hands.ts` keeps the right hand near home (small snap to the nearest edge) and letsthe left hand pick the best grip point on the logo's far edges.- `src/main.ts` wires the scene, interaction and export.## Agent API (MCP)Agents can hug a logo without the UI: the private Space[Chunte/hugging-space-mcp](https://huggingface.co/spaces/Chunte/hugging-space-mcp) runs this appheadlessly (Playwright) behind Gradio with an MCP server. Tools: `hug_logo` → transparent PNG(default), `hug_logo_svg` → SVG; inputs `svg` (markup or URL), `size`, `rotation`. MCP URL:`https://chunte-hugging-space-mcp.hf.space/gradio_api/mcp/sse` (send an HF token while private).Code in `agent/`, deployed with `tools/deploy-agent.sh`. The app side is `window.hugApi.hug()`in `src/main.ts`.
1422 unmodified lines14231424142514261427142814291430143114321433143414351436143714381439144014411442144314441422 unmodified linesdownload(new Blob([text], { type: 'image/svg+xml' }), `${baseName()}.svg`);});$<HTMLButtonElement>('exportPng').addEventListener('click', async () => {const { text, width, height } = exportSvgText();const scale = 2;const img = new Image();const url = URL.createObjectURL(new Blob([text], { type: 'image/svg+xml' }));img.onload = () => {const canvas = document.createElement('canvas');canvas.width = Math.round(width * scale);canvas.height = Math.round(height * scale);canvas.getContext('2d')!.drawImage(img, 0, 0, canvas.width, canvas.height);URL.revokeObjectURL(url);canvas.toBlob((blob) => blob && download(blob, `${baseName()}.png`), 'image/png');};img.src = url;});// ---------------------------------------------------------------------------------------------// Debug/test hook (used for tuning against the Figma references).1422 unmodified lines1423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821422 unmodified linesdownload(new Blob([text], { type: 'image/svg+xml' }), `${baseName()}.svg`);});/** Render the current scene to a transparent PNG at `scale` × its size. */function exportPngBlob(scale = 2): Promise<Blob> {const { text, width, height } = exportSvgText();return new Promise((resolve, reject) => {const img = new Image();const url = URL.createObjectURL(new Blob([text], { type: 'image/svg+xml' }));img.onload = () => {const canvas = document.createElement('canvas');canvas.width = Math.round(width * scale);canvas.height = Math.round(height * scale);canvas.getContext('2d')!.drawImage(img, 0, 0, canvas.width, canvas.height);URL.revokeObjectURL(url);canvas.toBlob((blob) => (blob ? resolve(blob) : reject(new Error('PNG export failed'))), 'image/png');};img.onerror = () => reject(new Error('PNG export failed'));img.src = url;});}$<HTMLButtonElement>('exportPng').addEventListener('click', async () => {download(await exportPngBlob(2), `${baseName()}.png`);});// ---------------------------------------------------------------------------------------------// Agent API: load an SVG logo, let the hug settle, return the default export. Used by the// agent Space (headless browser) so tools / agents get the same result as the Export buttons.(window as unknown as { hugApi: unknown }).hugApi = {/*** @param svg the partner logo (SVG source)* @param size logo size (longest side, 140–1000; default 600)* @param rotation logo rotation in degrees (−180–180; default 0)* @param format 'png' (default) or 'svg'* @param scale PNG scale (default 2)*/async hug(opts: { svg: string; name?: string; size?: number; rotation?: number; format?: 'png' | 'svg'; scale?: number }) {if (typeof opts?.svg !== 'string' || !/<svg[\s>]/i.test(opts.svg)) throw new Error('Expected SVG source (an <svg> element).');markSample(null);await useLogo(opts.svg, opts.name || 'partner');if (!logo) throw new Error(el.status.textContent || 'Could not read that SVG.');if (typeof opts.size === 'number') setSize(opts.size);if (typeof opts.rotation === 'number') setRotation(opts.rotation, false);for (let i = 0; i < 240; i++) frame(1 / 60); // settle: hug, swell, squish, handsconst { text, width, height } = exportSvgText();if (opts.format === 'svg') return { format: 'svg', svg: text, width, height };const blob = await exportPngBlob(opts.scale ?? 2);const png = await new Promise<string>((resolve) => {const r = new FileReader();r.onload = () => resolve(String(r.result));r.readAsDataURL(blob);});return { format: 'png', png, width: Math.round(width * (opts.scale ?? 2)), height: Math.round(height * (opts.scale ?? 2)) };},};// ---------------------------------------------------------------------------------------------// Debug/test hook (used for tuning against the Figma references).
README.md+10
src/main.ts+51-13