{
  "version": 3,
  "sources": ["/cdn/shop/t/1064/assets/nb-edit.js?nc=26963"],
  "sourcesContent": ["/*\n  NB-edit.js \u2014 shared AI Edit engine for the members-portal AI surfaces.\n\n  WHY THIS FILE EXISTS\n  ai-chat-sandbox.js's Edit affordance (runEdit) gates on, and calls,\n  window.nbEditRequest \u2014 which is defined GLOBALLY only in\n  bySize_popular.js, and that file loads only on the by-size PDP. The two\n  members-portal AI surfaces don't load it:\n    \u2022 Portal Design Studio  (/pages/free-design-tools, design-tool-widget.liquid):\n      v0-script.js defines an equivalent nbEditRequest but scope-locally\n      (inside its $(document).ready()), never on window.\n    \u2022 Portal AI Image Generator (/pages/ai-image-generator, ai-image-creator.liquid):\n      no copy at all.\n  So the capability gate (typeof window.nbEditRequest === 'function') stays\n  off on both, and Edit can't run there.\n\n  This tiny asset exposes window.nbEditRequest (+ the daily-cap gate\n  window.canUseAiRequest) on those two portal surfaces. It is loaded via script_tag\n  from design-tool-widget.liquid + ai-image-creator.liquid \u2014 the same two sections\n  that eager-load ai-create.css. Neither section renders on the by-size PDP,\n  theme.liquid, or the header, so this NEVER loads on the PDP's anonymous path:\n  on the PDP, window.nbEditRequest keeps coming solely from bySize_popular.js.\n\n  PROVENANCE: nbEditRequest posts to the bg-removal proxy Lambda\n  (model 'gram-edit'), which calls Gram's edit-lite API server-side and\n  returns a persistent imgix URL. The cap cluster (AI_DAILY_LIMIT / getLocalDayKey /\n  getAiUsage / canUseAiRequest) is copied verbatim from bySize_popular.js, keyed\n  on the same localStorage key nbUsage (per-origin; a legacy 'nanoBananaUsage'\n  value is still read as a one-release fallback for continuity) \u2014 so the 50/day\n  gate is consistent across every AI surface.\n\n  \u26A0 Deliberately NO consumeAiRequest here: the create-with-AI edit path gates on\n  canUseAiRequest but does NOT increment (matching bySize_popular.js's existing\n  behavior \u2014 the counter is bumped by the legacy edit-modal flow, not by runEdit).\n  This asset is a consistent GATE, not a shared decrement. Changing that is out of scope.\n\n  Wrapped in an IIFE + guarded window assignment so it can never clobber an\n  already-present global or collide with another file's top-level declarations.\n*/\n(function () {\n  var aiJobAbortController = null;\n  var aiJobCancelled = false;\n\n  // \u2500\u2500 nbEditRequest \u2014 Gram edit-lite via the bg-removal proxy Lambda \u2500\u2500\n  async function nbEditRequest(imageUrl, promptText) {\n    aiJobCancelled = false;\n    console.log ( 'promptText', promptText );\n    aiJobAbortController = new AbortController();\n\n    const resp = await fetch('https://ruhg140mmf.execute-api.us-east-1.amazonaws.com/', {\n      method: 'POST',\n      headers: { 'Content-Type': 'application/json' },\n      body: JSON.stringify({\n        model: 'gram-edit-45g',\n        imageUrl: imageUrl,\n        prompt: promptText,\n        transparency: 'AUTO'\n      }),\n      signal: aiJobAbortController.signal\n    });\n\n    if (!resp.ok) {\n      const txt = await resp.text().catch(() => '');\n      throw new Error('AI edit request failed (' + resp.status + '): ' + txt.slice(0, 200));\n    }\n\n    if (aiJobCancelled) {\n      throw new Error(\"AI request cancelled by user\");\n    }\n\n    const data = await resp.json();\n    if (!data || !data.url) throw new Error('AI edit response missing url');\n    return data.url;\n  }\n\n  // \u2500\u2500 daily-cap GATE \u2014 VERBATIM cluster from bySize_popular.js (keyed on nbUsage) \u2500\u2500\n  const AI_DAILY_LIMIT = 50;\n\n  function getLocalDayKey() {\n    // YYYY-MM-DD in USER'S local timezone\n    const d = new Date();\n    const year  = d.getFullYear();\n    const month = String(d.getMonth() + 1).padStart(2, '0');\n    const day   = String(d.getDate()).padStart(2, '0');\n    return `${year}-${month}-${day}`;\n  }\n\n  function getAiUsage() {\n    const day = getLocalDayKey();\n    const raw = (localStorage.getItem('nbUsage') || localStorage.getItem('nanoBananaUsage'));\n    let obj = {};\n    try { obj = raw ? JSON.parse(raw) : {}; } catch (e) { obj = {}; }\n\n    if (!obj || obj.day !== day) obj = { day, count: 0 };\n    return obj;\n  }\n\n  function canUseAiRequest() {\n    const usage = getAiUsage();\n    return usage.count < AI_DAILY_LIMIT;\n  }\n\n  // Expose on window \u2014 guarded so we never clobber an already-present global\n  // (e.g. bySize_popular.js's on the PDP, though this asset never loads there).\n  if (typeof window.nbEditRequest !== 'function') {\n    window.nbEditRequest = nbEditRequest;\n  }\n  if (typeof window.canUseAiRequest !== 'function') {\n    window.canUseAiRequest = canUseAiRequest;\n  }\n})();\n"],
  "mappings": "CAuCC,UAAY,CACX,IAAI,qBAAuB,KACvB,eAAiB,GAGrB,eAAe,cAAc,SAAU,WAAY,CACjD,eAAiB,GACjB,QAAQ,IAAM,aAAc,UAAW,EACvC,qBAAuB,IAAI,gBAE3B,MAAM,KAAO,MAAM,MAAM,0DAA2D,CAClF,OAAQ,OACR,QAAS,CAAE,eAAgB,kBAAmB,EAC9C,KAAM,KAAK,UAAU,CACnB,MAAO,gBACP,SACA,OAAQ,WACR,aAAc,MAChB,CAAC,EACD,OAAQ,qBAAqB,MAC/B,CAAC,EAED,GAAI,CAAC,KAAK,GAAI,CACZ,MAAM,IAAM,MAAM,KAAK,KAAK,EAAE,MAAM,IAAM,EAAE,EAC5C,MAAM,IAAI,MAAM,2BAA6B,KAAK,OAAS,MAAQ,IAAI,MAAM,EAAG,GAAG,CAAC,CACtF,CAEA,GAAI,eACF,MAAM,IAAI,MAAM,8BAA8B,EAGhD,MAAM,KAAO,MAAM,KAAK,KAAK,EAC7B,GAAI,CAAC,MAAQ,CAAC,KAAK,IAAK,MAAM,IAAI,MAAM,8BAA8B,EACtE,OAAO,KAAK,GACd,CAGA,MAAM,eAAiB,GAEvB,SAAS,gBAAiB,CAExB,MAAM,EAAI,IAAI,KACR,KAAQ,EAAE,YAAY,EACtB,MAAQ,OAAO,EAAE,SAAS,EAAI,CAAC,EAAE,SAAS,EAAG,GAAG,EAChD,IAAQ,OAAO,EAAE,QAAQ,CAAC,EAAE,SAAS,EAAG,GAAG,EACjD,MAAO,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,EAChC,CAEA,SAAS,YAAa,CACpB,MAAM,IAAM,eAAe,EACrB,IAAO,aAAa,QAAQ,SAAS,GAAK,aAAa,QAAQ,iBAAiB,EACtF,IAAI,IAAM,CAAC,EACX,GAAI,CAAE,IAAM,IAAM,KAAK,MAAM,GAAG,EAAI,CAAC,CAAG,MAAY,CAAE,IAAM,CAAC,CAAG,CAEhE,OAAI,CAAC,KAAO,IAAI,MAAQ,OAAK,IAAM,CAAE,IAAK,MAAO,CAAE,GAC5C,GACT,CAEA,SAAS,iBAAkB,CAEzB,OADc,WAAW,EACZ,MAAQ,cACvB,CAII,OAAO,OAAO,eAAkB,aAClC,OAAO,cAAgB,eAErB,OAAO,OAAO,iBAAoB,aACpC,OAAO,gBAAkB,gBAE7B,GAAG",
  "names": []
}
