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ACG,IAEU,qBAAQ,KAAI,CAAEH,EAAM,KAAMgB,IAACL,EAAMhB,CAAM,GAAIqB,GAAG,SAASW,EAAMC,CAAI,GAAIE,GACnF,QAAC,CACA,aAAaD,CAAK,CACnB,CACD,CAGgB,SAAAG,GAAU,CACzBrB,EAAAhB,CAAM,GAAE,YAAW,CACpB,UAGgBsC,EAAYC,EAAoB,GAC/CvC,CAAM,GAAE,YAAYuC,CAAI,CACzB,0EAGKtC,CAAK,EAAAuC,GAAA,CACT,IAAAC,EAAAC,EAAA,IAAAD,EAAAE,GAAA/B,EACWd,YAAM,UADjB8C,EAAAH,EAAA,EAAAI,EAAA,CAEQ,gBAAiBjD,KAAe,aAAa,qBAFrDkD,EAAAL,EAAA,aAGY7C,EAAW,EAAG,yBAA2B,UAAU,IAH/DmD,EAAAP,EAAAC,CAAA,eAHM","names":["interactive","showRuler","canvas","$.state","engine","build","reducedMotion","markReady","markFailed","ready","res","rej","SNAPSHOT_TIMEOUT_MS","onMount","mq","onMq","$.set","cancelled","start","SculptStageEngine","$.get","sanitizeAnySculpt","$.snapshot","$$props","b","e","rebuilding","rebuild","tick","onLost","onShow","host","$.user_effect","p","onDestroy","snapshot","type","opts","timer","timeout","_","reframe","viewInkSpot","spot","$$anchor","canvas_1","root_1","$$value","$.set_class","$.clsx","$.set_attribute","$.append"],"sources":["../../../../../../src/lib/components/sculpt/SculptStage.svelte"],"sourcesContent":["<script lang=\"ts\">\n\t// 3D sculpt editor / viewer canvas. three.js + the stage engine load lazily in the browser only.\n\t// The canvas fills its parent; the parent sets the size and any HUD on top.\n\timport { onDestroy, onMount, tick } from 'svelte';\n\timport { sanitizeAnySculpt, type VulvaInkSpot } from '$lib/sculpt/vulva-params';\n\timport type { PublicSculptParams } from '$lib/sculpt/public-params';\n\timport type { SculptStageEngine, SnapshotOptions } from '$lib/sculpt/render/stage';\n\n\tinterface Props {\n\t\t/** Someone else's sculpt comes without her duet settings (public-params.ts): the stage\n\t\t *  sanitizes, which fills in the defaults here, in the browser only. */\n\t\tparams: PublicSculptParams;\n\t\tunits: 'cm' | 'in';\n\t\twobble: boolean;\n\t\tinteractive?: boolean;\n\t\tshowRuler?: boolean;\n\t\tonbusy?: (busy: boolean) => void;\n\t\t/** Shown as \"@handle\" under the in-scene watermark. */\n\t\twatermarkHandle?: string;\n\t}\n\n\tlet {\n\t\tparams,\n\t\tunits,\n\t\twobble,\n\t\tinteractive = true,\n\t\tshowRuler = true,\n\t\tonbusy,\n\t\twatermarkHandle\n\t}: Props = $props();\n\n\tlet canvas = $state<HTMLCanvasElement>();\n\tlet engine = $state<SculptStageEngine | null>(null);\n\t/** a new canvas (and context) for each build: a lost context is never drawn on again */\n\tlet build = $state(0);\n\tlet reducedMotion = $state(false);\n\tlet markReady: (e: SculptStageEngine) => void = () => {};\n\tlet markFailed: (e: unknown) => void = () => {};\n\tconst ready = new Promise<SculptStageEngine>((res, rej) => {\n\t\tmarkReady = res;\n\t\tmarkFailed = rej;\n\t});\n\t// snapshot() reports the failure to its caller; nobody else awaits this\n\tready.catch(() => {});\n\t/** A snapshot that has not landed by then is given up (the editor then saves without a poster). */\n\tconst SNAPSHOT_TIMEOUT_MS = 8000;\n\n\tonMount(() => {\n\t\tconst mq = window.matchMedia('(prefers-reduced-motion: reduce)');\n\t\treducedMotion = mq.matches;\n\t\tconst onMq = () => (reducedMotion = mq.matches);\n\t\tmq.addEventListener('change', onMq);\n\t\tlet cancelled = false;\n\t\tconst start = () =>\n\t\t\timport('$lib/sculpt/render/stage')\n\t\t\t\t.then(({ SculptStageEngine }) => {\n\t\t\t\t\tif (cancelled || !canvas) return;\n\t\t\t\t\tengine = new SculptStageEngine(canvas, sanitizeAnySculpt($state.snapshot(params)), {\n\t\t\t\t\t\tinteractive,\n\t\t\t\t\t\tshowRuler,\n\t\t\t\t\t\tunits,\n\t\t\t\t\t\twobble,\n\t\t\t\t\t\treducedMotion,\n\t\t\t\t\t\tonbusy: (b) => onbusy?.(b),\n\t\t\t\t\t\twatermarkHandle\n\t\t\t\t\t});\n\t\t\t\t\tmarkReady(engine);\n\t\t\t\t})\n\t\t\t\t.catch((e) => {\n\t\t\t\t\t// no WebGL (iOS Lockdown Mode, a lost context) or a stale chunk after a deploy\n\t\t\t\t\tconsole.error('[SculptStage] 3D failed to start', e);\n\t\t\t\t\tmarkFailed(e);\n\t\t\t\t});\n\t\tvoid start();\n\n\t\t// iOS drops the context under memory pressure (a duet just played, the tab in the background)\n\t\t// and rarely gives it back: the model froze and took no drag. Lost: the engine goes and a new\n\t\t// one builds on a new canvas. A page back from the bfcache gets a fresh one too.\n\t\tlet rebuilding = false;\n\t\tconst rebuild = async () => {\n\t\t\tif (cancelled || rebuilding) return;\n\t\t\trebuilding = true;\n\t\t\tengine?.dispose();\n\t\t\tengine = null;\n\t\t\tbuild++;\n\t\t\tawait tick();\n\t\t\trebuilding = false;\n\t\t\tvoid start();\n\t\t};\n\t\tconst onLost = (e: Event) => {\n\t\t\t// the old canvas's own loss (dispose forces it) is not this one's\n\t\t\tif (e.target !== canvas) return;\n\t\t\te.preventDefault();\n\t\t\tvoid rebuild();\n\t\t};\n\t\tconst onShow = (e: PageTransitionEvent) => {\n\t\t\tif (e.persisted) void rebuild();\n\t\t};\n\t\tconst host = canvas?.parentElement;\n\t\thost?.addEventListener('webglcontextlost', onLost, true);\n\t\twindow.addEventListener('pageshow', onShow);\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t\tmq.removeEventListener('change', onMq);\n\t\t\thost?.removeEventListener('webglcontextlost', onLost, true);\n\t\t\twindow.removeEventListener('pageshow', onShow);\n\t\t};\n\t});\n\n\t// every param read here, so any change (even deep in a $state object) re-runs\n\t$effect(() => {\n\t\tconst p = sanitizeAnySculpt($state.snapshot(params));\n\t\tengine?.setParams(p);\n\t});\n\t$effect(() => engine?.setUnits(units));\n\t$effect(() => engine?.setWobble(wobble));\n\t$effect(() => engine?.setInteractive(interactive));\n\t$effect(() => engine?.setShowRuler(showRuler));\n\t$effect(() => engine?.setReducedMotion(reducedMotion));\n\t$effect(() => engine?.setWatermarkHandle(watermarkHandle));\n\n\tonDestroy(() => {\n\t\t// onDestroy also runs during SSR; the engine only ever exists in the browser\n\t\tengine?.dispose();\n\t\tengine = null;\n\t});\n\n\t/**\n\t * One still from a fixed hero camera. Waits for the FINE mesh. Carries the in-scene watermark by\n\t * default; pass `{ watermark: false, poster: true }` for the stored profile poster (the server\n\t * marks share/OG images). `handle` overrides `watermarkHandle` for this one image.\n\t */\n\texport async function snapshot(type = 'image/webp', opts: SnapshotOptions = {}): Promise<Blob> {\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tconst timeout = new Promise<never>((_, rej) => {\n\t\t\ttimer = setTimeout(() => rej(new Error('snapshot timed out')), SNAPSHOT_TIMEOUT_MS);\n\t\t});\n\t\ttry {\n\t\t\t// the engine now (a rebuild after a lost context replaces the first one)\n\t\t\treturn await Promise.race([ready.then((e) => (engine ?? e).snapshot(type, opts)), timeout]);\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t}\n\n\t/** Re-centre the camera on the model. */\n\texport function reframe() {\n\t\tengine?.frameCamera();\n\t}\n\n\t/** Turn the camera to where her tattoo sits (the editor's Ink tab, on a pick). */\n\texport function viewInkSpot(spot: VulvaInkSpot) {\n\t\tengine?.viewInkSpot(spot);\n\t}\n</script>\n\n{#key build}\n\t<canvas\n\t\tbind:this={canvas}\n\t\tclass={['sculpt-canvas', interactive && 'interactive']}\n\t\taria-label={interactive ? '3D model, drag to spin' : '3D model'}\n\t></canvas>\n{/key}\n\n<style>\n\t.sculpt-canvas {\n\t\tdisplay: block;\n\t\twidth: 100%;\n\t\theight: 100%;\n\t}\n\t.sculpt-canvas.interactive {\n\t\ttouch-action: none;\n\t}\n</style>\n"],"version":3}