commerce-kit 0.51.0 → 0.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,18 @@
1
1
  /**
2
2
  * Sandbox Inspectors — side-effect entry.
3
3
  *
4
- * Auto-mounts the design-mode + comment-mode inspectors inside per-store
5
- * storefronts running under the AI Builder sandbox dev server. Communicates
6
- * with the parent /design iframe via postMessage.
4
+ * Runs inside per-store storefronts under the AI Builder sandbox dev server.
5
+ * Two responsibilities:
6
+ * 1. Report uncaught runtime errors to the parent /design iframe.
7
+ * 2. Load the builder-annotations UI (blue annotation pins, popovers, creation
8
+ * composer) from the central yns-toolbar CDN when embedded in the /design
9
+ * iframe. The UI lives there — not here — so fixes ship by pushing the
10
+ * toolbar repo instead of publishing commerce-kit + bumping every store.
7
11
  *
8
- * Always-on: inspectors are passive postMessage listeners and don't affect the
9
- * page until the AI Builder iframe sends a `*-mode-toggle` message. Gating on
10
- * NODE_ENV is wrong (always "production" on Vercel) and any build-time gate
11
- * gets folded out by the commerce-kit bundle, leaving an empty file.
12
+ * Always-on: both parts are gated at runtime on being embedded in a parent
13
+ * frame. Gating on NODE_ENV is wrong (always "production" on Vercel) and any
14
+ * build-time gate gets folded out by the commerce-kit bundle, leaving an empty
15
+ * file.
12
16
  */
13
17
  /**
14
18
  * Exported so `browser.tsx` can `export { startSandboxInspectors }` — the
@@ -1,2 +1,2 @@
1
- function E(){typeof window>"u"||(console.log("[YNS Sandbox Inspectors] module evaluated"),k(),S(),x())}E();function x(){if(window.parent===window)return;let o=5e3,i=10,e=2e3,t=0,n="",c=0;function f(d,l){let m=Date.now();c>=i||d===n&&m-t<o||(t=m,n=d,c+=1,window.parent.postMessage({type:"runtime-error",message:d,stack:l?l.slice(0,e):void 0,pagePath:window.location.pathname},"*"))}window.addEventListener("error",d=>{let l=d.error,m=l instanceof Error?l.message:d.message||"Unknown error",y=l instanceof Error?l.stack:void 0;f(m,y)}),window.addEventListener("unhandledrejection",d=>{let l=d.reason,m=l instanceof Error?l.message:String(l??"Unhandled rejection"),y=l instanceof Error?l.stack:void 0;f(m,y)})}var C=new Set(["HEAD","SCRIPT","STYLE","NOSCRIPT","HTML"]);function L(o){if(o.id)return`${o.tagName.toLowerCase()}#${CSS.escape(o.id)}`;let i=[],e=o;for(;e&&e!==document.body&&e!==document.documentElement;){let t=e.tagName.toLowerCase();if(e.id){i.unshift(`${t}#${CSS.escape(e.id)}`);break}let n=Array.from(e.classList).filter(d=>!d.startsWith("data-yns-"));n.length>0&&(t+=`.${n.map(d=>CSS.escape(d)).join(".")}`);let c=e.parentElement,f=e.tagName;if(c&&Array.from(c.children).filter(l=>l.tagName===f&&(n.length===0||n.every(m=>l.classList.contains(m)))).length>1){let l=Array.from(c.children).indexOf(e)+1;t+=`:nth-child(${l})`}i.unshift(t),e=e.parentElement}return i.join(" > ")}function w(o,i){let e=o.getBoundingClientRect(),t=window.getComputedStyle(o),n=(o.textContent??"").trim();return{tag:o.tagName.toLowerCase(),id:o.id||void 0,classes:Array.from(o.classList).filter(c=>!c.startsWith("data-yns-")),textContent:n.length>i?`${n.slice(0,i)}\u2026`:n,cssSelector:L(o),boundingRect:{top:e.top,left:e.left,width:e.width,height:e.height},computedStyles:{color:t.color,backgroundColor:t.backgroundColor,fontSize:t.fontSize,fontFamily:t.fontFamily,padding:t.padding,margin:t.margin}}}function v(o,i){if(!o?.tagName||C.has(o.tagName))return!0;for(let e of i)if(o.hasAttribute?.(e))return!0;return!1}function k(){let o=!1,i=null,e=null,t=document.createElement("div");t.setAttribute("data-yns-design-overlay","hover"),t.style.cssText=["position: fixed","pointer-events: none","z-index: 2147483646","border: 2px solid #3b82f6","background: rgba(59, 130, 246, 0.08)","border-radius: 3px","display: none","transition: top 0.05s, left 0.05s, width 0.05s, height 0.05s"].join(";");let n=document.createElement("div");n.setAttribute("data-yns-design-overlay","label"),n.style.cssText=["position: fixed","pointer-events: none","z-index: 2147483647","background: #3b82f6","color: #fff","font-size: 11px","font-family: ui-monospace, monospace","padding: 2px 6px","border-radius: 3px","white-space: nowrap","display: none"].join(";"),document.documentElement.appendChild(t),document.documentElement.appendChild(n);let c=document.createElement("style");c.setAttribute("data-yns-design-overlay","style"),c.textContent="[data-yns-selected] { outline: 2px solid #3b82f6 !important; outline-offset: 1px; }",document.head.appendChild(c);function f(u){let r=u.getBoundingClientRect();t.style.top=`${r.top}px`,t.style.left=`${r.left}px`,t.style.width=`${r.width}px`,t.style.height=`${r.height}px`,t.style.display="block";let a=Array.from(u.classList).filter(p=>!p.startsWith("data-yns-")),s=u.tagName.toLowerCase()+(a.length?`.${a[0]}`:"");n.textContent=s,n.style.left=`${r.left}px`,n.style.top=`${Math.max(0,r.top-22)}px`,n.style.display="block"}let d=u=>{let r=document.elementFromPoint(u.clientX,u.clientY);if(v(r,["data-yns-design-overlay"])){t.style.display="none",n.style.display="none",i=null;return}i=r,requestAnimationFrame(()=>{i===r&&o&&r&&f(r)})},l=()=>{t.style.display="none",n.style.display="none",i=null},m=u=>{if(!o||!i)return;u.preventDefault(),u.stopPropagation(),u.stopImmediatePropagation();let r=i;if(v(r,["data-yns-design-overlay"]))return;let a=w(r,120),s=a.cssSelector;e&&e.el.removeAttribute("data-yns-selected"),e&&e.cssSelector===s?(e=null,window.parent.postMessage({type:"element-deselected",data:a},"*")):(e={el:r,cssSelector:s},r.setAttribute("data-yns-selected",""),window.parent.postMessage({type:"element-selected",data:a},"*"))},y=u=>{u.key==="Escape"&&o&&(h(),window.parent.postMessage({type:"design-mode-cleared"},"*"))};function b(){o=!0,document.addEventListener("mousemove",d,!0),document.addEventListener("mouseleave",l),document.addEventListener("click",m,!0),document.addEventListener("keydown",y,!0)}function h(){o=!1,document.removeEventListener("mousemove",d,!0),document.removeEventListener("mouseleave",l),document.removeEventListener("click",m,!0),document.removeEventListener("keydown",y,!0),t.style.display="none",n.style.display="none",i=null,e&&(e.el.removeAttribute("data-yns-selected"),e=null)}window.addEventListener("message",u=>{let r=u.data;!r||typeof r!="object"||(r.type==="design-mode-toggle"&&(r.enabled?b():(h(),window.parent.postMessage({type:"design-mode-cleared"},"*"))),r.type==="design-mode-deselect"&&e&&(e.el.removeAttribute("data-yns-selected"),e=null))})}function S(){let o=!1,i=null,e=[],t=document.createElement("div");t.setAttribute("data-yns-comment-overlay","hover"),t.style.cssText=["position: fixed","pointer-events: none","z-index: 2147483644","border: 2px dashed #10b981","background: rgba(16, 185, 129, 0.06)","border-radius: 3px","display: none","transition: top 0.05s, left 0.05s, width 0.05s, height 0.05s"].join(";");let n=document.createElement("div");n.setAttribute("data-yns-comment-overlay","cursor-label"),n.textContent="Click to comment",n.style.cssText=["position: fixed","pointer-events: none","z-index: 2147483645","background: #059669","color: #fff","font-size: 11px","font-family: ui-sans-serif, system-ui, sans-serif","padding: 3px 8px","border-radius: 4px","white-space: nowrap","display: none","box-shadow: 0 2px 6px rgba(0,0,0,0.15)"].join(";");let c=document.createElement("div");c.setAttribute("data-yns-comment-overlay","pins"),c.style.cssText="position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2147483643;",document.documentElement.appendChild(t),document.documentElement.appendChild(n),document.documentElement.appendChild(c);function f(){c.innerHTML="";for(let a of e){let s=null;try{s=document.querySelector(a.selector)}catch{s=null}if(!s)continue;let p=s.getBoundingClientRect(),g=document.createElement("div");g.style.cssText=["position: fixed",`top: ${p.top-12}px`,`left: ${p.left+p.width/2-12}px`,"width: 24px","height: 24px","border-radius: 50%","background: #059669","color: #fff","display: flex","align-items: center","justify-content: center","font-size: 12px","font-weight: 600","font-family: ui-sans-serif, system-ui, sans-serif","box-shadow: 0 2px 8px rgba(0,0,0,0.2)","pointer-events: none"].join(";"),g.textContent=String(a.number),c.appendChild(g)}}let d=a=>{let s=document.elementFromPoint(a.clientX,a.clientY);if(v(s,["data-yns-comment-overlay","data-yns-design-overlay"])){t.style.display="none",n.style.display="none",i=null;return}i=s,requestAnimationFrame(()=>{if(i===s&&o&&s){let p=s.getBoundingClientRect();t.style.top=`${p.top}px`,t.style.left=`${p.left}px`,t.style.width=`${p.width}px`,t.style.height=`${p.height}px`,t.style.display="block",n.style.left=`${a.clientX+14}px`,n.style.top=`${a.clientY+14}px`,n.style.display="block"}})},l=()=>{t.style.display="none",n.style.display="none",i=null},m=a=>{if(!o||!i)return;a.preventDefault(),a.stopPropagation(),a.stopImmediatePropagation();let s=i;if(v(s,["data-yns-comment-overlay","data-yns-design-overlay"]))return;let p=w(s,200),g=s.getBoundingClientRect();window.parent.postMessage({type:"comment-click",data:{element:p,clickPosition:{x:a.clientX,y:a.clientY},elementRect:{top:g.top,left:g.left,width:g.width,height:g.height},pagePath:window.location.pathname}},"*")},y=a=>{a.key==="Escape"&&o&&(h(),window.parent.postMessage({type:"comment-mode-cleared"},"*"))};function b(){o=!0,document.body.style.cursor="crosshair",document.addEventListener("mousemove",d,!0),document.addEventListener("mouseleave",l),document.addEventListener("click",m,!0),document.addEventListener("keydown",y,!0)}function h(){o=!1,document.body.style.cursor="",document.removeEventListener("mousemove",d,!0),document.removeEventListener("mouseleave",l),document.removeEventListener("click",m,!0),document.removeEventListener("keydown",y,!0),t.style.display="none",n.style.display="none",i=null}let u=!1,r=()=>{u||(u=!0,requestAnimationFrame(()=>{u=!1,f()}))};window.addEventListener("scroll",r,{passive:!0}),window.addEventListener("resize",r,{passive:!0}),window.addEventListener("message",a=>{let s=a.data;!s||typeof s!="object"||(s.type==="comment-mode-toggle"&&(s.enabled?b():h()),s.type==="comment-pins-update"&&(e=s.pins??[],f()),s.type==="comment-pin-remove"&&(e=e.filter(p=>p.id!==s.pinId),f()))})}export{E as startSandboxInspectors};
1
+ function w(){typeof window>"u"||(console.log("[YNS Sandbox Inspectors] module evaluated"),p(),f())}w();function f(){if(window.parent===window)return;let r="yns-builder-annotations-script";if(document.getElementById(r))return;let s=process.env.NEXT_PUBLIC_YNS_TOOLBAR_BASE||"https://toolbar.yns.cx",t=document.createElement("script");t.id=r,t.async=!0,t.src=`${s}/annotations.js`,document.head.appendChild(t)}function p(){if(window.parent===window)return;let r=5e3,s=10,t=2e3,a=0,c="",d=0;function u(e,n){let o=Date.now();d>=s||e===c&&o-a<r||(a=o,c=e,d+=1,window.parent.postMessage({type:"runtime-error",message:e,stack:n?n.slice(0,t):void 0,pagePath:window.location.pathname},"*"))}window.addEventListener("error",e=>{let n=e.error,o=n instanceof Error?n.message:e.message||"Unknown error",i=n instanceof Error?n.stack:void 0;u(o,i)}),window.addEventListener("unhandledrejection",e=>{let n=e.reason,o=n instanceof Error?n.message:String(n??"Unhandled rejection"),i=n instanceof Error?n.stack:void 0;u(o,i)})}export{w as startSandboxInspectors};
2
2
  //# sourceMappingURL=sandbox-inspectors.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sandbox-inspectors.ts"],"sourcesContent":["/**\n * Sandbox Inspectors — side-effect entry.\n *\n * Auto-mounts the design-mode + comment-mode inspectors inside per-store\n * storefronts running under the AI Builder sandbox dev server. Communicates\n * with the parent /design iframe via postMessage.\n *\n * Always-on: inspectors are passive postMessage listeners and don't affect the\n * page until the AI Builder iframe sends a `*-mode-toggle` message. Gating on\n * NODE_ENV is wrong (always \"production\" on Vercel) and any build-time gate\n * gets folded out by the commerce-kit bundle, leaving an empty file.\n */\n\n/**\n * Exported so `browser.tsx` can `export { startSandboxInspectors }` — the\n * named binding anchors this module against esbuild tree-shaking when\n * commerce-kit is bundled. Without it, an `export * from \"./sandbox-inspectors\"`\n * re-exports an empty binding set and esbuild DCEs the whole file.\n */\nexport function startSandboxInspectors(): void {\n\tif (typeof window === \"undefined\") return;\n\tconsole.log(\"[YNS Sandbox Inspectors] module evaluated\");\n\tinitDesignModeInspector();\n\tinitCommentModeInspector();\n\tinitRuntimeErrorReporter();\n}\n\n// Auto-start on import.\nstartSandboxInspectors();\n\n/**\n * Reports uncaught runtime errors (e.g. React's \"Maximum update depth\n * exceeded\" from an infinite render loop) to the parent /design iframe so the\n * AI Builder can surface a crash overlay instead of a silently frozen preview.\n *\n * Unlike the inspectors, this posts unsolicited messages — so it only attaches\n * when actually embedded in a parent frame. Render loops fire the same error\n * continuously; rate-limit hard so the parent isn't flooded.\n */\nfunction initRuntimeErrorReporter() {\n\tif (window.parent === window) return;\n\n\tconst MIN_INTERVAL_MS = 5_000;\n\tconst MAX_REPORTS_PER_LOAD = 10;\n\tconst MAX_STACK_LENGTH = 2_000;\n\n\tlet lastSentAt = 0;\n\tlet lastMessage = \"\";\n\tlet sentCount = 0;\n\n\tfunction report(message: string, stack: string | undefined) {\n\t\tconst now = Date.now();\n\t\tif (sentCount >= MAX_REPORTS_PER_LOAD) return;\n\t\tif (message === lastMessage && now - lastSentAt < MIN_INTERVAL_MS) return;\n\t\tlastSentAt = now;\n\t\tlastMessage = message;\n\t\tsentCount += 1;\n\t\twindow.parent.postMessage(\n\t\t\t{\n\t\t\t\ttype: \"runtime-error\",\n\t\t\t\tmessage,\n\t\t\t\tstack: stack ? stack.slice(0, MAX_STACK_LENGTH) : undefined,\n\t\t\t\tpagePath: window.location.pathname,\n\t\t\t},\n\t\t\t\"*\",\n\t\t);\n\t}\n\n\twindow.addEventListener(\"error\", (event) => {\n\t\tconst error: unknown = event.error;\n\t\tconst message = error instanceof Error ? error.message : event.message || \"Unknown error\";\n\t\tconst stack = error instanceof Error ? error.stack : undefined;\n\t\treport(message, stack);\n\t});\n\n\twindow.addEventListener(\"unhandledrejection\", (event) => {\n\t\tconst reason: unknown = event.reason;\n\t\tconst message = reason instanceof Error ? reason.message : String(reason ?? \"Unhandled rejection\");\n\t\tconst stack = reason instanceof Error ? reason.stack : undefined;\n\t\treport(message, stack);\n\t});\n}\n\ninterface ElementInfo {\n\ttag: string;\n\tid: string | undefined;\n\tclasses: string[];\n\ttextContent: string;\n\tcssSelector: string;\n\tboundingRect: { top: number; left: number; width: number; height: number };\n\tcomputedStyles: Partial<{\n\t\tcolor: string;\n\t\tbackgroundColor: string;\n\t\tfontSize: string;\n\t\tfontFamily: string;\n\t\tpadding: string;\n\t\tmargin: string;\n\t}>;\n}\n\nconst IGNORED_TAGS = new Set([\"HEAD\", \"SCRIPT\", \"STYLE\", \"NOSCRIPT\", \"HTML\"]);\n\nfunction generateCssSelector(el: Element): string {\n\tif (el.id) return `${el.tagName.toLowerCase()}#${CSS.escape(el.id)}`;\n\n\tconst parts: string[] = [];\n\tlet current: Element | null = el;\n\twhile (current && current !== document.body && current !== document.documentElement) {\n\t\tlet selector = current.tagName.toLowerCase();\n\n\t\tif (current.id) {\n\t\t\tparts.unshift(`${selector}#${CSS.escape(current.id)}`);\n\t\t\tbreak;\n\t\t}\n\n\t\tconst classes = Array.from(current.classList).filter((c) => !c.startsWith(\"data-yns-\"));\n\t\tif (classes.length > 0) {\n\t\t\tselector += `.${classes.map((c) => CSS.escape(c)).join(\".\")}`;\n\t\t}\n\n\t\tconst parent: Element | null = current.parentElement;\n\t\tconst tag = current.tagName;\n\t\tif (parent) {\n\t\t\tconst siblings = Array.from(parent.children).filter(\n\t\t\t\t(s) => s.tagName === tag && (classes.length === 0 || classes.every((c) => s.classList.contains(c))),\n\t\t\t);\n\t\t\tif (siblings.length > 1) {\n\t\t\t\tconst index = Array.from(parent.children).indexOf(current) + 1;\n\t\t\t\tselector += `:nth-child(${index})`;\n\t\t\t}\n\t\t}\n\n\t\tparts.unshift(selector);\n\t\tcurrent = current.parentElement;\n\t}\n\treturn parts.join(\" > \");\n}\n\nfunction buildElementInfo(el: Element, textLimit: number): ElementInfo {\n\tconst rect = el.getBoundingClientRect();\n\tconst computed = window.getComputedStyle(el);\n\tconst text = (el.textContent ?? \"\").trim();\n\treturn {\n\t\ttag: el.tagName.toLowerCase(),\n\t\tid: el.id || undefined,\n\t\tclasses: Array.from(el.classList).filter((c) => !c.startsWith(\"data-yns-\")),\n\t\ttextContent: text.length > textLimit ? `${text.slice(0, textLimit)}…` : text,\n\t\tcssSelector: generateCssSelector(el),\n\t\tboundingRect: { top: rect.top, left: rect.left, width: rect.width, height: rect.height },\n\t\tcomputedStyles: {\n\t\t\tcolor: computed.color,\n\t\t\tbackgroundColor: computed.backgroundColor,\n\t\t\tfontSize: computed.fontSize,\n\t\t\tfontFamily: computed.fontFamily,\n\t\t\tpadding: computed.padding,\n\t\t\tmargin: computed.margin,\n\t\t},\n\t};\n}\n\nfunction shouldIgnore(el: Element | null, overlayAttrs: string[]): el is null {\n\tif (!el?.tagName) return true;\n\tif (IGNORED_TAGS.has(el.tagName)) return true;\n\tfor (const attr of overlayAttrs) {\n\t\tif (el.hasAttribute?.(attr)) return true;\n\t}\n\treturn false;\n}\n\nfunction initDesignModeInspector() {\n\tlet enabled = false;\n\tlet hoveredElement: Element | null = null;\n\tlet selectedElement: { el: Element; cssSelector: string } | null = null;\n\n\tconst overlay = document.createElement(\"div\");\n\toverlay.setAttribute(\"data-yns-design-overlay\", \"hover\");\n\toverlay.style.cssText = [\n\t\t\"position: fixed\",\n\t\t\"pointer-events: none\",\n\t\t\"z-index: 2147483646\",\n\t\t\"border: 2px solid #3b82f6\",\n\t\t\"background: rgba(59, 130, 246, 0.08)\",\n\t\t\"border-radius: 3px\",\n\t\t\"display: none\",\n\t\t\"transition: top 0.05s, left 0.05s, width 0.05s, height 0.05s\",\n\t].join(\";\");\n\n\tconst label = document.createElement(\"div\");\n\tlabel.setAttribute(\"data-yns-design-overlay\", \"label\");\n\tlabel.style.cssText = [\n\t\t\"position: fixed\",\n\t\t\"pointer-events: none\",\n\t\t\"z-index: 2147483647\",\n\t\t\"background: #3b82f6\",\n\t\t\"color: #fff\",\n\t\t\"font-size: 11px\",\n\t\t\"font-family: ui-monospace, monospace\",\n\t\t\"padding: 2px 6px\",\n\t\t\"border-radius: 3px\",\n\t\t\"white-space: nowrap\",\n\t\t\"display: none\",\n\t].join(\";\");\n\n\tdocument.documentElement.appendChild(overlay);\n\tdocument.documentElement.appendChild(label);\n\n\tconst style = document.createElement(\"style\");\n\tstyle.setAttribute(\"data-yns-design-overlay\", \"style\");\n\tstyle.textContent = \"[data-yns-selected] { outline: 2px solid #3b82f6 !important; outline-offset: 1px; }\";\n\tdocument.head.appendChild(style);\n\n\tfunction positionOverlay(el: Element) {\n\t\tconst rect = el.getBoundingClientRect();\n\t\toverlay.style.top = `${rect.top}px`;\n\t\toverlay.style.left = `${rect.left}px`;\n\t\toverlay.style.width = `${rect.width}px`;\n\t\toverlay.style.height = `${rect.height}px`;\n\t\toverlay.style.display = \"block\";\n\n\t\tconst classes = Array.from(el.classList).filter((c) => !c.startsWith(\"data-yns-\"));\n\t\tconst labelText = el.tagName.toLowerCase() + (classes.length ? `.${classes[0]}` : \"\");\n\t\tlabel.textContent = labelText;\n\t\tlabel.style.left = `${rect.left}px`;\n\t\tlabel.style.top = `${Math.max(0, rect.top - 22)}px`;\n\t\tlabel.style.display = \"block\";\n\t}\n\n\tconst handleMouseMove = (e: MouseEvent) => {\n\t\tconst el = document.elementFromPoint(e.clientX, e.clientY);\n\t\tif (shouldIgnore(el, [\"data-yns-design-overlay\"])) {\n\t\t\toverlay.style.display = \"none\";\n\t\t\tlabel.style.display = \"none\";\n\t\t\thoveredElement = null;\n\t\t\treturn;\n\t\t}\n\t\thoveredElement = el;\n\t\trequestAnimationFrame(() => {\n\t\t\tif (hoveredElement === el && enabled && el) {\n\t\t\t\tpositionOverlay(el);\n\t\t\t}\n\t\t});\n\t};\n\n\tconst handleMouseLeave = () => {\n\t\toverlay.style.display = \"none\";\n\t\tlabel.style.display = \"none\";\n\t\thoveredElement = null;\n\t};\n\n\tconst handleClick = (e: MouseEvent) => {\n\t\tif (!enabled || !hoveredElement) return;\n\t\te.preventDefault();\n\t\te.stopPropagation();\n\t\te.stopImmediatePropagation();\n\n\t\tconst el = hoveredElement;\n\t\tif (shouldIgnore(el, [\"data-yns-design-overlay\"])) return;\n\n\t\tconst info = buildElementInfo(el, 120);\n\t\tconst selector = info.cssSelector;\n\n\t\tif (selectedElement) {\n\t\t\tselectedElement.el.removeAttribute(\"data-yns-selected\");\n\t\t}\n\n\t\tif (selectedElement && selectedElement.cssSelector === selector) {\n\t\t\tselectedElement = null;\n\t\t\twindow.parent.postMessage({ type: \"element-deselected\", data: info }, \"*\");\n\t\t} else {\n\t\t\tselectedElement = { el, cssSelector: selector };\n\t\t\tel.setAttribute(\"data-yns-selected\", \"\");\n\t\t\twindow.parent.postMessage({ type: \"element-selected\", data: info }, \"*\");\n\t\t}\n\t};\n\n\tconst handleKeyDown = (e: KeyboardEvent) => {\n\t\tif (e.key === \"Escape\" && enabled) {\n\t\t\tdisableDesignMode();\n\t\t\twindow.parent.postMessage({ type: \"design-mode-cleared\" }, \"*\");\n\t\t}\n\t};\n\n\tfunction enableDesignMode() {\n\t\tenabled = true;\n\t\tdocument.addEventListener(\"mousemove\", handleMouseMove, true);\n\t\tdocument.addEventListener(\"mouseleave\", handleMouseLeave);\n\t\tdocument.addEventListener(\"click\", handleClick, true);\n\t\tdocument.addEventListener(\"keydown\", handleKeyDown, true);\n\t}\n\n\tfunction disableDesignMode() {\n\t\tenabled = false;\n\t\tdocument.removeEventListener(\"mousemove\", handleMouseMove, true);\n\t\tdocument.removeEventListener(\"mouseleave\", handleMouseLeave);\n\t\tdocument.removeEventListener(\"click\", handleClick, true);\n\t\tdocument.removeEventListener(\"keydown\", handleKeyDown, true);\n\n\t\toverlay.style.display = \"none\";\n\t\tlabel.style.display = \"none\";\n\t\thoveredElement = null;\n\n\t\tif (selectedElement) {\n\t\t\tselectedElement.el.removeAttribute(\"data-yns-selected\");\n\t\t\tselectedElement = null;\n\t\t}\n\t}\n\n\twindow.addEventListener(\"message\", (event) => {\n\t\tconst msg = event.data;\n\t\tif (!msg || typeof msg !== \"object\") return;\n\n\t\tif (msg.type === \"design-mode-toggle\") {\n\t\t\tif (msg.enabled) {\n\t\t\t\tenableDesignMode();\n\t\t\t} else {\n\t\t\t\tdisableDesignMode();\n\t\t\t\twindow.parent.postMessage({ type: \"design-mode-cleared\" }, \"*\");\n\t\t\t}\n\t\t}\n\n\t\tif (msg.type === \"design-mode-deselect\") {\n\t\t\tif (selectedElement) {\n\t\t\t\tselectedElement.el.removeAttribute(\"data-yns-selected\");\n\t\t\t\tselectedElement = null;\n\t\t\t}\n\t\t}\n\t});\n}\n\nfunction initCommentModeInspector() {\n\tlet enabled = false;\n\tlet hoveredElement: Element | null = null;\n\tlet pins: Array<{ id: string; selector: string; number: number }> = [];\n\n\tconst overlay = document.createElement(\"div\");\n\toverlay.setAttribute(\"data-yns-comment-overlay\", \"hover\");\n\toverlay.style.cssText = [\n\t\t\"position: fixed\",\n\t\t\"pointer-events: none\",\n\t\t\"z-index: 2147483644\",\n\t\t\"border: 2px dashed #10b981\",\n\t\t\"background: rgba(16, 185, 129, 0.06)\",\n\t\t\"border-radius: 3px\",\n\t\t\"display: none\",\n\t\t\"transition: top 0.05s, left 0.05s, width 0.05s, height 0.05s\",\n\t].join(\";\");\n\n\tconst cursorLabel = document.createElement(\"div\");\n\tcursorLabel.setAttribute(\"data-yns-comment-overlay\", \"cursor-label\");\n\tcursorLabel.textContent = \"Click to comment\";\n\tcursorLabel.style.cssText = [\n\t\t\"position: fixed\",\n\t\t\"pointer-events: none\",\n\t\t\"z-index: 2147483645\",\n\t\t\"background: #059669\",\n\t\t\"color: #fff\",\n\t\t\"font-size: 11px\",\n\t\t\"font-family: ui-sans-serif, system-ui, sans-serif\",\n\t\t\"padding: 3px 8px\",\n\t\t\"border-radius: 4px\",\n\t\t\"white-space: nowrap\",\n\t\t\"display: none\",\n\t\t\"box-shadow: 0 2px 6px rgba(0,0,0,0.15)\",\n\t].join(\";\");\n\n\tconst pinContainer = document.createElement(\"div\");\n\tpinContainer.setAttribute(\"data-yns-comment-overlay\", \"pins\");\n\tpinContainer.style.cssText =\n\t\t\"position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2147483643;\";\n\n\tdocument.documentElement.appendChild(overlay);\n\tdocument.documentElement.appendChild(cursorLabel);\n\tdocument.documentElement.appendChild(pinContainer);\n\n\tfunction renderPins() {\n\t\tpinContainer.innerHTML = \"\";\n\t\tfor (const pin of pins) {\n\t\t\tlet el: Element | null = null;\n\t\t\ttry {\n\t\t\t\tel = document.querySelector(pin.selector);\n\t\t\t} catch {\n\t\t\t\tel = null;\n\t\t\t}\n\t\t\tif (!el) continue;\n\n\t\t\tconst r = el.getBoundingClientRect();\n\t\t\tconst pinEl = document.createElement(\"div\");\n\t\t\tpinEl.style.cssText = [\n\t\t\t\t\"position: fixed\",\n\t\t\t\t`top: ${r.top - 12}px`,\n\t\t\t\t`left: ${r.left + r.width / 2 - 12}px`,\n\t\t\t\t\"width: 24px\",\n\t\t\t\t\"height: 24px\",\n\t\t\t\t\"border-radius: 50%\",\n\t\t\t\t\"background: #059669\",\n\t\t\t\t\"color: #fff\",\n\t\t\t\t\"display: flex\",\n\t\t\t\t\"align-items: center\",\n\t\t\t\t\"justify-content: center\",\n\t\t\t\t\"font-size: 12px\",\n\t\t\t\t\"font-weight: 600\",\n\t\t\t\t\"font-family: ui-sans-serif, system-ui, sans-serif\",\n\t\t\t\t\"box-shadow: 0 2px 8px rgba(0,0,0,0.2)\",\n\t\t\t\t\"pointer-events: none\",\n\t\t\t].join(\";\");\n\t\t\tpinEl.textContent = String(pin.number);\n\t\t\tpinContainer.appendChild(pinEl);\n\t\t}\n\t}\n\n\tconst handleMouseMove = (e: MouseEvent) => {\n\t\tconst el = document.elementFromPoint(e.clientX, e.clientY);\n\t\tif (shouldIgnore(el, [\"data-yns-comment-overlay\", \"data-yns-design-overlay\"])) {\n\t\t\toverlay.style.display = \"none\";\n\t\t\tcursorLabel.style.display = \"none\";\n\t\t\thoveredElement = null;\n\t\t\treturn;\n\t\t}\n\t\thoveredElement = el;\n\t\trequestAnimationFrame(() => {\n\t\t\tif (hoveredElement === el && enabled && el) {\n\t\t\t\tconst rect = el.getBoundingClientRect();\n\t\t\t\toverlay.style.top = `${rect.top}px`;\n\t\t\t\toverlay.style.left = `${rect.left}px`;\n\t\t\t\toverlay.style.width = `${rect.width}px`;\n\t\t\t\toverlay.style.height = `${rect.height}px`;\n\t\t\t\toverlay.style.display = \"block\";\n\n\t\t\t\tcursorLabel.style.left = `${e.clientX + 14}px`;\n\t\t\t\tcursorLabel.style.top = `${e.clientY + 14}px`;\n\t\t\t\tcursorLabel.style.display = \"block\";\n\t\t\t}\n\t\t});\n\t};\n\n\tconst handleMouseLeave = () => {\n\t\toverlay.style.display = \"none\";\n\t\tcursorLabel.style.display = \"none\";\n\t\thoveredElement = null;\n\t};\n\n\tconst handleClick = (e: MouseEvent) => {\n\t\tif (!enabled || !hoveredElement) return;\n\t\te.preventDefault();\n\t\te.stopPropagation();\n\t\te.stopImmediatePropagation();\n\n\t\tconst el = hoveredElement;\n\t\tif (shouldIgnore(el, [\"data-yns-comment-overlay\", \"data-yns-design-overlay\"])) return;\n\n\t\tconst info = buildElementInfo(el, 200);\n\t\tconst rect = el.getBoundingClientRect();\n\n\t\twindow.parent.postMessage(\n\t\t\t{\n\t\t\t\ttype: \"comment-click\",\n\t\t\t\tdata: {\n\t\t\t\t\telement: info,\n\t\t\t\t\tclickPosition: { x: e.clientX, y: e.clientY },\n\t\t\t\t\telementRect: { top: rect.top, left: rect.left, width: rect.width, height: rect.height },\n\t\t\t\t\tpagePath: window.location.pathname,\n\t\t\t\t},\n\t\t\t},\n\t\t\t\"*\",\n\t\t);\n\t};\n\n\tconst handleKeyDown = (e: KeyboardEvent) => {\n\t\tif (e.key === \"Escape\" && enabled) {\n\t\t\tdisableCommentMode();\n\t\t\twindow.parent.postMessage({ type: \"comment-mode-cleared\" }, \"*\");\n\t\t}\n\t};\n\n\tfunction enableCommentMode() {\n\t\tenabled = true;\n\t\tdocument.body.style.cursor = \"crosshair\";\n\t\tdocument.addEventListener(\"mousemove\", handleMouseMove, true);\n\t\tdocument.addEventListener(\"mouseleave\", handleMouseLeave);\n\t\tdocument.addEventListener(\"click\", handleClick, true);\n\t\tdocument.addEventListener(\"keydown\", handleKeyDown, true);\n\t}\n\n\tfunction disableCommentMode() {\n\t\tenabled = false;\n\t\tdocument.body.style.cursor = \"\";\n\t\tdocument.removeEventListener(\"mousemove\", handleMouseMove, true);\n\t\tdocument.removeEventListener(\"mouseleave\", handleMouseLeave);\n\t\tdocument.removeEventListener(\"click\", handleClick, true);\n\t\tdocument.removeEventListener(\"keydown\", handleKeyDown, true);\n\n\t\toverlay.style.display = \"none\";\n\t\tcursorLabel.style.display = \"none\";\n\t\thoveredElement = null;\n\t}\n\n\tlet rafPending = false;\n\tconst scheduleRender = () => {\n\t\tif (rafPending) return;\n\t\trafPending = true;\n\t\trequestAnimationFrame(() => {\n\t\t\trafPending = false;\n\t\t\trenderPins();\n\t\t});\n\t};\n\twindow.addEventListener(\"scroll\", scheduleRender, { passive: true });\n\twindow.addEventListener(\"resize\", scheduleRender, { passive: true });\n\n\twindow.addEventListener(\"message\", (event) => {\n\t\tconst msg = event.data;\n\t\tif (!msg || typeof msg !== \"object\") return;\n\n\t\tif (msg.type === \"comment-mode-toggle\") {\n\t\t\tif (msg.enabled) enableCommentMode();\n\t\t\telse disableCommentMode();\n\t\t}\n\n\t\tif (msg.type === \"comment-pins-update\") {\n\t\t\tpins = msg.pins ?? [];\n\t\t\trenderPins();\n\t\t}\n\n\t\tif (msg.type === \"comment-pin-remove\") {\n\t\t\tpins = pins.filter((p) => p.id !== msg.pinId);\n\t\t\trenderPins();\n\t\t}\n\t});\n}\n"],"mappings":"AAmBO,SAASA,GAA+B,CAC1C,OAAO,OAAW,MACtB,QAAQ,IAAI,2CAA2C,EACvDC,EAAwB,EACxBC,EAAyB,EACzBC,EAAyB,EAC1B,CAGAH,EAAuB,EAWvB,SAASG,GAA2B,CACnC,GAAI,OAAO,SAAW,OAAQ,OAE9B,IAAMC,EAAkB,IAClBC,EAAuB,GACvBC,EAAmB,IAErBC,EAAa,EACbC,EAAc,GACdC,EAAY,EAEhB,SAASC,EAAOC,EAAiBC,EAA2B,CAC3D,IAAMC,EAAM,KAAK,IAAI,EACjBJ,GAAaJ,GACbM,IAAYH,GAAeK,EAAMN,EAAaH,IA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D,SAAS,iBAAiB,QAASC,EAAa,EAAI,EACpD,SAAS,iBAAiB,UAAWE,EAAe,EAAI,CACzD,CAEA,SAASW,GAAqB,CAC7BxB,EAAU,GACV,SAAS,KAAK,MAAM,OAAS,GAC7B,SAAS,oBAAoB,YAAaQ,EAAiB,EAAI,EAC/D,SAAS,oBAAoB,aAAcE,CAAgB,EAC3D,SAAS,oBAAoB,QAASC,EAAa,EAAI,EACvD,SAAS,oBAAoB,UAAWE,EAAe,EAAI,EAE3DV,EAAQ,MAAM,QAAU,OACxBe,EAAY,MAAM,QAAU,OAC5BjB,EAAiB,IAClB,CAEA,IAAIyB,EAAa,GACXC,EAAiB,IAAM,CACxBD,IACJA,EAAa,GACb,sBAAsB,IAAM,CAC3BA,EAAa,GACbN,EAAW,CACZ,CAAC,EACF,EACA,OAAO,iBAAiB,SAAUO,EAAgB,CAAE,QAAS,EAAK,CAAC,EACnE,OAAO,iBAAiB,SAAUA,EAAgB,CAAE,QAAS,EAAK,CAAC,EAEnE,OAAO,iBAAiB,UAAYlD,GAAU,CAC7C,IAAMuC,EAAMvC,EAAM,KACd,CAACuC,GAAO,OAAOA,GAAQ,WAEvBA,EAAI,OAAS,wBACZA,EAAI,QAASS,EAAkB,EAC9BD,EAAmB,GAGrBR,EAAI,OAAS,wBAChBC,EAAOD,EAAI,MAAQ,CAAC,EACpBI,EAAW,GAGRJ,EAAI,OAAS,uBAChBC,EAAOA,EAAK,OAAQ,GAAM,EAAE,KAAOD,EAAI,KAAK,EAC5CI,EAAW,GAEb,CAAC,CACF","names":["startSandboxInspectors","initDesignModeInspector","initCommentModeInspector","initRuntimeErrorReporter","MIN_INTERVAL_MS","MAX_REPORTS_PER_LOAD","MAX_STACK_LENGTH","lastSentAt","lastMessage","sentCount","report","message","stack","now","event","error","reason","IGNORED_TAGS","generateCssSelector","el","parts","current","selector","classes","c","parent","tag","s","index","buildElementInfo","textLimit","rect","computed","text","shouldIgnore","overlayAttrs","attr","enabled","hoveredElement","selectedElement","overlay","label","style","positionOverlay","labelText","handleMouseMove","e","handleMouseLeave","handleClick","info","handleKeyDown","disableDesignMode","enableDesignMode","msg","pins","cursorLabel","pinContainer","renderPins","pin","r","pinEl","disableCommentMode","enableCommentMode","rafPending","scheduleRender"]}
1
+ {"version":3,"sources":["../src/sandbox-inspectors.ts"],"sourcesContent":["/**\n * Sandbox Inspectors — side-effect entry.\n *\n * Runs inside per-store storefronts under the AI Builder sandbox dev server.\n * Two responsibilities:\n * 1. Report uncaught runtime errors to the parent /design iframe.\n * 2. Load the builder-annotations UI (blue annotation pins, popovers, creation\n * composer) from the central yns-toolbar CDN when embedded in the /design\n * iframe. The UI lives there — not here — so fixes ship by pushing the\n * toolbar repo instead of publishing commerce-kit + bumping every store.\n *\n * Always-on: both parts are gated at runtime on being embedded in a parent\n * frame. Gating on NODE_ENV is wrong (always \"production\" on Vercel) and any\n * build-time gate gets folded out by the commerce-kit bundle, leaving an empty\n * file.\n */\n\n/**\n * Exported so `browser.tsx` can `export { startSandboxInspectors }` — the\n * named binding anchors this module against esbuild tree-shaking when\n * commerce-kit is bundled. Without it, an `export * from \"./sandbox-inspectors\"`\n * re-exports an empty binding set and esbuild DCEs the whole file.\n */\nexport function startSandboxInspectors(): void {\n\tif (typeof window === \"undefined\") return;\n\tconsole.log(\"[YNS Sandbox Inspectors] module evaluated\");\n\tinitRuntimeErrorReporter();\n\tinitBuilderAnnotationsLoader();\n}\n\n// Auto-start on import.\nstartSandboxInspectors();\n\n/**\n * Injects the builder-annotations bundle from the yns-toolbar CDN. The bundle\n * self-gates on being framed too, so this is belt-and-braces; loading only when\n * framed keeps direct sandbox-URL visits (and feedback preview deploys, which\n * import this module top-level) free of the extra script.\n */\nfunction initBuilderAnnotationsLoader() {\n\tif (window.parent === window) return;\n\n\tconst SCRIPT_ID = \"yns-builder-annotations-script\";\n\tif (document.getElementById(SCRIPT_ID)) return;\n\n\tconst base = process.env.NEXT_PUBLIC_YNS_TOOLBAR_BASE || \"https://toolbar.yns.cx\";\n\tconst script = document.createElement(\"script\");\n\tscript.id = SCRIPT_ID;\n\tscript.async = true;\n\tscript.src = `${base}/annotations.js`;\n\tdocument.head.appendChild(script);\n}\n\n/**\n * Reports uncaught runtime errors (e.g. React's \"Maximum update depth\n * exceeded\" from an infinite render loop) to the parent /design iframe so the\n * AI Builder can surface a crash overlay instead of a silently frozen preview.\n *\n * Unlike the annotations UI, this posts unsolicited messages — so it only\n * attaches when actually embedded in a parent frame. Render loops fire the same\n * error continuously; rate-limit hard so the parent isn't flooded.\n */\nfunction initRuntimeErrorReporter() {\n\tif (window.parent === window) return;\n\n\tconst MIN_INTERVAL_MS = 5_000;\n\tconst MAX_REPORTS_PER_LOAD = 10;\n\tconst MAX_STACK_LENGTH = 2_000;\n\n\tlet lastSentAt = 0;\n\tlet lastMessage = \"\";\n\tlet sentCount = 0;\n\n\tfunction report(message: string, stack: string | undefined) {\n\t\tconst now = Date.now();\n\t\tif (sentCount >= MAX_REPORTS_PER_LOAD) return;\n\t\tif (message === lastMessage && now - lastSentAt < MIN_INTERVAL_MS) return;\n\t\tlastSentAt = now;\n\t\tlastMessage = message;\n\t\tsentCount += 1;\n\t\twindow.parent.postMessage(\n\t\t\t{\n\t\t\t\ttype: \"runtime-error\",\n\t\t\t\tmessage,\n\t\t\t\tstack: stack ? stack.slice(0, MAX_STACK_LENGTH) : undefined,\n\t\t\t\tpagePath: window.location.pathname,\n\t\t\t},\n\t\t\t\"*\",\n\t\t);\n\t}\n\n\twindow.addEventListener(\"error\", (event) => {\n\t\tconst error: unknown = event.error;\n\t\tconst message = error instanceof Error ? error.message : event.message || \"Unknown error\";\n\t\tconst stack = error instanceof Error ? error.stack : undefined;\n\t\treport(message, stack);\n\t});\n\n\twindow.addEventListener(\"unhandledrejection\", (event) => {\n\t\tconst reason: unknown = event.reason;\n\t\tconst message = reason instanceof Error ? reason.message : String(reason ?? \"Unhandled rejection\");\n\t\tconst stack = reason instanceof Error ? reason.stack : undefined;\n\t\treport(message, stack);\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EAAO,MAAQ,OACvDN,EAAOC,EAASC,CAAK,CACtB,CAAC,CACF","names":["startSandboxInspectors","initRuntimeErrorReporter","initBuilderAnnotationsLoader","SCRIPT_ID","base","script","MIN_INTERVAL_MS","MAX_REPORTS_PER_LOAD","MAX_STACK_LENGTH","lastSentAt","lastMessage","sentCount","report","message","stack","now","event","error","reason"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "commerce-kit",
4
- "version": "0.51.0",
4
+ "version": "0.53.0",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",
7
7
  "keywords": [