@forgecart/designer-runtime 1.202608221935.0 → 1.202609190800.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.
@@ -0,0 +1 @@
1
+ "use strict";var ForgeCartDesignerRuntime=(()=>{var y=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var q=(s,e,t)=>e in s?y(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var Y=(s,e)=>{for(var t in e)y(s,t,{get:e[t],enumerable:!0})},$=(s,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of z(e))!j.call(s,n)&&n!==t&&y(s,n,{get:()=>e[n],enumerable:!(i=W(e,n))||i.enumerable});return s};var X=s=>$(y({},"__esModule",{value:!0}),s);var a=(s,e,t)=>q(s,typeof e!="symbol"?e+"":e,t);var Te={};Y(Te,{installDesignerRuntime:()=>Se});var m="fc-designer";var _="fc-designer:nonce",w="data-fc-source",c="data-fc-ref",R="data-fc-designer-overlay";var Z=new Set(["INVALID_MESSAGE","NOT_ACTIVE","REGION_TOO_LARGE","UNKNOWN_REF","INTERNAL"]),b=class{constructor(){a(this,"hostValidators",new Map([["HELLO",e=>this.isNonEmptyString(e.nonce)&&this.isFiniteNumber(e.protocolVersion)],["ACTIVATE",()=>!0],["DEACTIVATE",()=>!0],["PING",()=>!0],["REGION_SELECT",e=>this.isNonEmptyString(e.requestId)&&this.isPointArray(e.stroke)&&this.isPositiveNumber(e.radius)&&this.isOptionalPositiveNumber(e.maxElements)],["HIGHLIGHT_SET",e=>this.isStringArray(e.refIds)],["HIGHLIGHT_CLEAR",()=>!0],["ELEMENT_BOUNDS_QUERY",e=>this.isNonEmptyString(e.requestId)&&this.isStringArray(e.refIds)],["VIEW_MODE",e=>typeof e.board=="boolean"]]));a(this,"guestValidators",new Map([["READY",()=>!0],["HELLO_ACK",e=>this.isCapabilities(e.capabilities)&&this.isString(e.url)&&this.isViewport(e.viewport)],["ACTIVATED",()=>!0],["DEACTIVATED",()=>!0],["PONG",e=>this.isString(e.url)&&this.isPoint(e.scroll)],["REGION_RESOLVED",e=>this.isNonEmptyString(e.requestId)&&this.isElementDescriptorArray(e.elements)&&this.isRect(e.regionBounds)&&typeof e.truncated=="boolean"],["ELEMENT_BOUNDS",e=>this.isNonEmptyString(e.requestId)&&this.isBoundsEntryArray(e.entries)],["SCROLL",e=>this.isPoint(e.scroll)],["RESIZE",e=>this.isViewport(e.viewport)],["NAVIGATED",e=>this.isString(e.url)],["WHEEL_ZOOM",e=>this.isFiniteNumber(e.deltaY)&&this.isPoint(e.point)],["DOUBLE_CLICK",()=>!0],["SPACE",e=>typeof e.down=="boolean"],["ZOOM_KEY",e=>typeof e.down=="boolean"&&typeof e.alt=="boolean"],["DRAW_PROGRESS",e=>this.isPointArray(e.points)],["DRAW_COMMIT",e=>this.isPointArray(e.points)&&this.isPoint(e.scroll)],["DRAW_CANCEL",()=>!0],["ERROR",e=>this.isString(e.code)&&Z.has(e.code)&&this.isStringOrNull(e.requestId)&&this.isStringOrNull(e.detail)]]))}parseHostMessage(e){return this.isHostMessage(e)?e:null}parseGuestMessage(e){return this.isGuestMessage(e)?e:null}hasProtocolNamespace(e){return this.isRecord(e)&&e.ns===m}isHostMessage(e){return this.isEnvelopedRecord(e)?this.hostValidators.get(e.type)?.(e)??!1:!1}isGuestMessage(e){return this.isEnvelopedRecord(e)?this.guestValidators.get(e.type)?.(e)??!1:!1}isEnvelopedRecord(e){return!this.isRecord(e)||e.ns!==m||e.v!==1?!1:this.isNonEmptyString(e.type)}isRecord(e){return typeof e=="object"&&e!==null}isString(e){return typeof e=="string"}isStringOrNull(e){return e===null||typeof e=="string"}isNonEmptyString(e){return typeof e=="string"&&e.length>0}isFiniteNumber(e){return typeof e=="number"&&Number.isFinite(e)}isPositiveNumber(e){return this.isFiniteNumber(e)&&e>0}isOptionalPositiveNumber(e){return e===void 0||this.isPositiveNumber(e)}isStringArray(e){return Array.isArray(e)&&e.every(t=>this.isString(t))}isPoint(e){return this.isRecord(e)&&this.isFiniteNumber(e.x)&&this.isFiniteNumber(e.y)}isPointArray(e){return Array.isArray(e)&&e.every(t=>this.isPoint(t))}isViewport(e){return this.isRecord(e)&&this.isFiniteNumber(e.width)&&this.isFiniteNumber(e.height)}isRect(e){return this.isRecord(e)?this.isFiniteNumber(e.x)&&this.isFiniteNumber(e.y)&&this.isFiniteNumber(e.width)&&this.isFiniteNumber(e.height):!1}isCapabilities(e){return this.isRecord(e)&&typeof e.stamping=="boolean"&&typeof e.highlight=="boolean"}isBoundsEntryArray(e){return Array.isArray(e)&&e.every(t=>this.isBoundsEntry(t))}isBoundsEntry(e){return this.isRecord(e)?this.isNonEmptyString(e.refId)&&(e.bounds===null||this.isRect(e.bounds)):!1}isElementDescriptorArray(e){return Array.isArray(e)&&e.every(t=>this.isElementDescriptor(t))}isElementDescriptor(e){return this.isRecord(e)?this.hasDescriptorIdentity(e)&&this.hasDescriptorContent(e)&&this.hasDescriptorGeometry(e):!1}hasDescriptorIdentity(e){return this.isNonEmptyString(e.refId)&&this.isNonEmptyString(e.tagName)&&this.isStringOrNull(e.id)&&this.isStringArray(e.classList)}hasDescriptorContent(e){return this.isDomPath(e.domPath)&&this.isSourceRefOrNull(e.source)&&this.isStringOrNull(e.text)&&this.isStringOrNull(e.role)&&this.isStringRecord(e.attributes)}hasDescriptorGeometry(e){return this.isRect(e.bounds)&&this.isFiniteNumber(e.coverage)&&this.isFiniteNumber(e.childCount)}isDomPath(e){return Array.isArray(e)&&e.every(t=>this.isDomPathSegment(t))}isDomPathSegment(e){return this.isRecord(e)?this.isNonEmptyString(e.tag)&&this.isFiniteNumber(e.nthOfType):!1}isSourceRefOrNull(e){return e===null?!0:this.isRecord(e)?this.isNonEmptyString(e.file)&&this.isFiniteNumber(e.line)&&this.isFiniteNumber(e.column)&&this.isStringOrNull(e.componentName):!1}isStringRecord(e){return this.isRecord(e)&&Object.values(e).every(t=>this.isString(t))}};var Q=3,J=14,ee=6,te=7,ie={tag:"\u2026",nthOfType:0},H=120,ne=10,re=["href","src","alt","type","name","placeholder","aria-label","data-testid"],se=new Map([["button","button"],["textarea","textbox"],["select","combobox"],["img","img"],["nav","navigation"],["main","main"],["header","banner"],["footer","contentinfo"],["h1","heading"],["h2","heading"],["h3","heading"],["h4","heading"],["h5","heading"],["h6","heading"],["ul","list"],["ol","list"],["li","listitem"]]),S=class{constructor(e){this.win=e}extract(e,t,i){return{refId:t,tagName:e.tagName.toLowerCase(),id:e.id.length>0?e.id:null,classList:Array.from(e.classList).slice(0,ne),domPath:this.buildDomPath(e),source:this.resolveSource(e),text:this.extractText(e),role:this.resolveRole(e),attributes:this.collectAttributes(e),bounds:this.toRect(e.getBoundingClientRect()),coverage:i,childCount:e.childElementCount}}resolveSource(e){let t=e;for(let i=0;i<=Q&&t!==null;i++){let n=t.getAttribute(w);if(n!==null)return this.parseSource(n);t=t.parentElement}return null}parseSource(e){let t=e.split(":");if(t.length<4)return null;let i=t[t.length-1],n=this.parsePosition(t[t.length-2]),r=this.parsePosition(t[t.length-3]),o=t.slice(0,t.length-3).join(":");return r===null||n===null||o.length===0?null:{file:o,line:r,column:n,componentName:i.length>0?i:null}}parsePosition(e){if(!/^\d+$/.test(e))return null;let t=Number(e);return Number.isSafeInteger(t)?t:null}buildDomPath(e){let t=[],i=e;for(;i!==null&&i!==this.win.document.documentElement&&(t.unshift({tag:i.tagName.toLowerCase(),nthOfType:this.nthOfType(i)}),i!==this.win.document.body);)i=i.parentElement;return t.length<=J?t:[...t.slice(0,ee),ie,...t.slice(t.length-te)]}nthOfType(e){let t=1,i=e.previousElementSibling;for(;i!==null;)i.tagName===e.tagName&&t++,i=i.previousElementSibling;return t}extractText(e){let t=e.textContent.replace(/\s+/g," ").trim();return t.length===0?null:t.length<=H?t:`${t.slice(0,H)}\u2026`}resolveRole(e){let t=e.getAttribute("role");if(t!==null&&t.length>0)return t;let i=e.tagName.toLowerCase();return i==="a"?e.hasAttribute("href")?"link":null:i==="input"?this.inputRole(e):se.get(i)??null}inputRole(e){let t=e.getAttribute("type");return t==="submit"||t==="button"?"button":"textbox"}collectAttributes(e){let t={};for(let i of re){let n=e.getAttribute(i);n!==null&&(t[i]=n)}return t}toRect(e){return{x:e.x,y:e.y,width:e.width,height:e.height}}};var oe=200,ae=16,le=4,A=class{constructor(e,t,i,n,r,o){this.win=e;this.codec=t;this.gate=i;this.messenger=n;this.resolver=r;this.overlay=o;a(this,"state","dormant");a(this,"messageListener",null);a(this,"armed",null);a(this,"scrollFrame",null);a(this,"resizeFrame",null);a(this,"drawFrame",null);a(this,"draw",null);a(this,"boardMode",!1);a(this,"spaceHeld",!1);a(this,"zoomKeyHeld",!1);a(this,"zoomAltHeld",!1);a(this,"nativeHistory",null)}install(){this.messageListener===null&&(this.messageListener=e=>{this.onMessage(e)},this.win.addEventListener("message",this.messageListener),this.messenger.postReady())}dispose(){this.teardownActivation(),this.messageListener!==null&&(this.win.removeEventListener("message",this.messageListener),this.messageListener=null),this.state="dormant"}onMessage(e){try{this.routeMessage(e)}catch(t){this.messenger.post({type:"ERROR",code:"INTERNAL",requestId:this.extractRequestId(e.data),detail:t instanceof Error?t.message:null})}}routeMessage(e){let t=this.codec.parseHostMessage(e.data);if(t===null){this.handleUnparseable(e);return}if(t.type==="HELLO"){this.handleHello(e,t);return}this.state==="dormant"||!this.isTrustedHostEvent(e)||this.dispatch(t)}handleUnparseable(e){this.codec.hasProtocolNamespace(e.data)&&(this.state==="dormant"||!this.isTrustedHostEvent(e)||this.messenger.post({type:"ERROR",code:"INVALID_MESSAGE",requestId:this.extractRequestId(e.data),detail:"message failed protocol validation"}))}handleHello(e,t){if(!this.gate.acceptHello(e,t))return;let i=this.gate.getPinnedOrigin();i!==null&&(this.messenger.pinOrigin(i),this.state==="dormant"&&(this.state="handshaken"),this.messenger.post({type:"HELLO_ACK",capabilities:{stamping:this.win.document.querySelector(`[${w}]`)!==null,highlight:!0},url:this.win.location.href,viewport:this.getViewport()}))}dispatch(e){switch(e.type){case"ACTIVATE":this.handleActivate();return;case"DEACTIVATE":this.handleDeactivate();return;case"PING":this.handlePing();return;case"REGION_SELECT":this.handleRegionSelect(e);return;case"HIGHLIGHT_SET":this.handleHighlightSet(e);return;case"HIGHLIGHT_CLEAR":this.overlay.clear();return;case"ELEMENT_BOUNDS_QUERY":this.handleElementBoundsQuery(e);return;case"VIEW_MODE":this.handleViewMode(e);return}}handleViewMode(e){this.boardMode=e.board,!e.board&&(this.spaceHeld&&(this.spaceHeld=!1,this.messenger.post({type:"SPACE",down:!1})),this.zoomKeyHeld&&(this.zoomKeyHeld=!1,this.messenger.post({type:"ZOOM_KEY",down:!1,alt:!1})),this.zoomAltHeld=!1)}handleActivate(){this.state!=="active"&&(this.armEmitters(),this.state="active"),this.messenger.post({type:"ACTIVATED"})}handleDeactivate(){this.teardownActivation(),this.state="handshaken",this.messenger.post({type:"DEACTIVATED"})}handlePing(){this.messenger.post({type:"PONG",url:this.win.location.href,scroll:this.getScroll()})}handleRegionSelect(e){if(this.state!=="active"){this.postError("NOT_ACTIVE",e.requestId);return}let t=this.resolver.resolve(e.stroke,e.radius,e.maxElements);if(t.kind==="too-large"){this.postError("REGION_TOO_LARGE",e.requestId);return}this.messenger.post({type:"REGION_RESOLVED",requestId:e.requestId,elements:t.elements,regionBounds:t.regionBounds,truncated:t.truncated})}handleHighlightSet(e){let t=[];for(let i of e.refIds){let n=this.findByRef(i);n!==null&&t.push(n)}if(t.length===0&&e.refIds.length>0){this.postError("UNKNOWN_REF",null);return}this.overlay.show(t)}handleElementBoundsQuery(e){let t=e.refIds.map(i=>{let n=this.findByRef(i);return{refId:i,bounds:n===null?null:this.toRect(n.getBoundingClientRect())}});this.messenger.post({type:"ELEMENT_BOUNDS",requestId:e.requestId,entries:t})}armEmitters(){this.armed===null&&(this.armed={scroll:()=>{this.scheduleFrame("scrollFrame",()=>{this.emitScroll()})},resize:()=>{this.scheduleFrame("resizeFrame",()=>{this.emitResize()})},popstate:()=>{this.emitNavigated()},hashchange:()=>{this.emitNavigated()},wheel:e=>{this.emitWheelZoom(e)},dblclick:()=>{this.emitDoubleClick()},keydown:e=>{this.onKeyDown(e)},keyup:e=>{this.onKeyUp(e)},pointerdown:e=>{this.onPointerDown(e)},pointermove:e=>{this.onPointerMove(e)},pointerup:e=>{this.onPointerUp(e)},pointercancel:e=>{this.onPointerCancel(e)},touchmove:e=>{this.draw?.activated===!0&&e.preventDefault()},selectstart:e=>{(this.draw!==null||this.spaceHeld)&&e.preventDefault()},dragstart:e=>{(this.draw!==null||this.spaceHeld)&&e.preventDefault()}},this.win.addEventListener("scroll",this.armed.scroll,{passive:!0}),this.win.addEventListener("resize",this.armed.resize),this.win.addEventListener("popstate",this.armed.popstate),this.win.addEventListener("hashchange",this.armed.hashchange),this.win.addEventListener("wheel",this.armed.wheel,{passive:!1}),this.win.addEventListener("dblclick",this.armed.dblclick),this.win.addEventListener("keydown",this.armed.keydown),this.win.addEventListener("keyup",this.armed.keyup),this.win.addEventListener("pointerdown",this.armed.pointerdown),this.win.addEventListener("pointermove",this.armed.pointermove),this.win.addEventListener("pointerup",this.armed.pointerup),this.win.addEventListener("pointercancel",this.armed.pointercancel),this.win.addEventListener("touchmove",this.armed.touchmove,{passive:!1}),this.win.addEventListener("selectstart",this.armed.selectstart),this.win.addEventListener("dragstart",this.armed.dragstart),this.patchHistoryEmitters())}patchHistoryEmitters(){if(this.nativeHistory!==null)return;let e=this.win.history,t=Reflect.get(e,"pushState"),i=Reflect.get(e,"replaceState");this.nativeHistory={pushState:t,replaceState:i},e.pushState=(...n)=>{t.apply(e,n),this.emitNavigated()},e.replaceState=(...n)=>{i.apply(e,n),this.emitNavigated()}}restoreHistoryEmitters(){this.nativeHistory!==null&&(this.win.history.pushState=this.nativeHistory.pushState,this.win.history.replaceState=this.nativeHistory.replaceState,this.nativeHistory=null)}disarmEmitters(){this.armed!==null&&(this.win.removeEventListener("scroll",this.armed.scroll),this.win.removeEventListener("resize",this.armed.resize),this.win.removeEventListener("popstate",this.armed.popstate),this.win.removeEventListener("hashchange",this.armed.hashchange),this.win.removeEventListener("wheel",this.armed.wheel),this.win.removeEventListener("dblclick",this.armed.dblclick),this.win.removeEventListener("keydown",this.armed.keydown),this.win.removeEventListener("keyup",this.armed.keyup),this.win.removeEventListener("pointerdown",this.armed.pointerdown),this.win.removeEventListener("pointermove",this.armed.pointermove),this.win.removeEventListener("pointerup",this.armed.pointerup),this.win.removeEventListener("pointercancel",this.armed.pointercancel),this.win.removeEventListener("touchmove",this.armed.touchmove),this.win.removeEventListener("selectstart",this.armed.selectstart),this.win.removeEventListener("dragstart",this.armed.dragstart),this.restoreHistoryEmitters(),this.armed=null,this.spaceHeld=!1,this.zoomKeyHeld=!1,this.zoomAltHeld=!1,this.cancelDraw(),this.cancelFrames())}scheduleFrame(e,t){this[e]===null&&(this[e]=this.win.requestAnimationFrame(()=>{this[e]=null,this.overlay.refresh(),t()}))}cancelFrames(){this.scrollFrame!==null&&(this.win.cancelAnimationFrame(this.scrollFrame),this.scrollFrame=null),this.resizeFrame!==null&&(this.win.cancelAnimationFrame(this.resizeFrame),this.resizeFrame=null),this.cancelDrawFrame()}emitScroll(){this.messenger.post({type:"SCROLL",scroll:this.getScroll()})}emitResize(){this.messenger.post({type:"RESIZE",viewport:this.getViewport()})}emitNavigated(){this.messenger.post({type:"NAVIGATED",url:this.win.location.href})}emitWheelZoom(e){!e.ctrlKey&&!e.metaKey||(e.preventDefault(),this.messenger.post({type:"WHEEL_ZOOM",deltaY:e.deltaY,point:{x:e.clientX,y:e.clientY}}))}emitDoubleClick(){this.messenger.post({type:"DOUBLE_CLICK"})}onKeyDown(e){this.trackZoomKey(e,!0),!(!this.boardMode||!this.isSpace(e)||this.isTypingTarget(e.target))&&(e.preventDefault(),!this.spaceHeld&&(this.spaceHeld=!0,this.messenger.post({type:"SPACE",down:!0})))}onKeyUp(e){this.trackZoomKey(e,!1),!(!this.isSpace(e)||!this.spaceHeld)&&(this.spaceHeld=!1,this.messenger.post({type:"SPACE",down:!1}))}trackZoomKey(e,t){let i=!1;if(e.key==="Alt"&&this.zoomAltHeld!==t&&(this.zoomAltHeld=t,i=!0),this.isZoomKey(e)){let n=t&&this.boardMode&&!this.isTypingTarget(e.target);this.zoomKeyHeld!==n&&(this.zoomKeyHeld=n,i=!0)}!i||!this.boardMode||this.messenger.post({type:"ZOOM_KEY",down:this.zoomKeyHeld,alt:this.zoomAltHeld})}isZoomKey(e){return e.code==="KeyZ"||e.key.toLowerCase()==="z"}isSpace(e){return e.key===" "||e.code==="Space"}isTypingTarget(e){return e instanceof HTMLElement?e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e.isContentEditable:!1}onPointerDown(e){if(this.draw!==null||!e.isPrimary||e.button!==0)return;let t=e.pointerType==="touch";this.draw={pointerId:e.pointerId,points:[{x:e.clientX,y:e.clientY}],activated:!1,holdTimer:t?this.win.setTimeout(()=>{this.activateDraw()},oe):null}}onPointerMove(e){let t=this.draw;if(e.pointerId!==t?.pointerId)return;let i={x:e.clientX,y:e.clientY};if(!t.activated){let[r]=t.points;if(Math.hypot(i.x-r.x,i.y-r.y)<=ae)return;if(t.holdTimer!==null){this.clearHoldTimer(t),this.draw=null;return}this.activateDraw()}let n=t.points[t.points.length-1];Math.hypot(i.x-n.x,i.y-n.y)<le||(t.points.push(i),this.scheduleDrawFrame())}onPointerUp(e){let t=this.draw;if(e.pointerId===t?.pointerId){if(this.clearHoldTimer(t),!t.activated){this.draw=null;return}this.cancelDrawFrame(),this.releaseCapture(t.pointerId),this.messenger.post({type:"DRAW_COMMIT",points:t.points,scroll:this.getScroll()}),this.draw=null}}onPointerCancel(e){let t=this.draw;e.pointerId===t?.pointerId&&(this.clearHoldTimer(t),this.cancelDrawFrame(),this.releaseCapture(t.pointerId),t.activated&&this.messenger.post({type:"DRAW_CANCEL"}),this.draw=null)}activateDraw(){let e=this.draw;e!==null&&(e.holdTimer=null,e.activated=!0,this.capturePointer(e.pointerId),this.messenger.post({type:"DRAW_PROGRESS",points:e.points}))}scheduleDrawFrame(){this.drawFrame===null&&(this.drawFrame=this.win.requestAnimationFrame(()=>{this.drawFrame=null,this.draw?.activated===!0&&this.messenger.post({type:"DRAW_PROGRESS",points:this.draw.points})}))}cancelDrawFrame(){this.drawFrame!==null&&(this.win.cancelAnimationFrame(this.drawFrame),this.drawFrame=null)}clearHoldTimer(e){e.holdTimer!==null&&(this.win.clearTimeout(e.holdTimer),e.holdTimer=null)}cancelDraw(){this.draw!==null&&(this.clearHoldTimer(this.draw),this.releaseCapture(this.draw.pointerId),this.draw=null)}capturePointer(e){let t=this.win.document.documentElement;typeof t.setPointerCapture=="function"&&t.setPointerCapture(e)}releaseCapture(e){let t=this.win.document.documentElement;typeof t.hasPointerCapture=="function"&&t.hasPointerCapture(e)&&t.releasePointerCapture(e)}postError(e,t){this.messenger.post({type:"ERROR",code:e,requestId:t,detail:null})}teardownActivation(){this.overlay.dispose(),this.stripRefStamps(),this.disarmEmitters()}stripRefStamps(){for(let e of this.win.document.querySelectorAll(`[${c}]`))e.removeAttribute(c)}findByRef(e){let t=e.replace(/[\\"]/g,"\\$&");return this.win.document.querySelector(`[${c}="${t}"]`)}isTrustedHostEvent(e){let t=this.gate.getPinnedOrigin();return t!==null&&e.origin===t&&e.source===this.win.parent}extractRequestId(e){return typeof e!="object"||e===null||!("requestId"in e)?null:typeof e.requestId=="string"?e.requestId:null}getViewport(){return{width:this.win.innerWidth,height:this.win.innerHeight}}getScroll(){return{x:this.win.scrollX,y:this.win.scrollY}}toRect(e){return{x:e.x,y:e.y,width:e.width,height:e.height}}};var T=class{constructor(e){this.targetWindow=e;a(this,"pinnedOrigin",null)}postReady(){this.targetWindow.postMessage({ns:m,v:1,type:"READY"},"*")}pinOrigin(e){this.pinnedOrigin=e}getPinnedOrigin(){return this.pinnedOrigin}post(e){this.pinnedOrigin!==null&&this.targetWindow.postMessage({ns:m,v:1,...e},this.pinnedOrigin)}};var O=class{constructor(e){this.win=e;a(this,"nonce");a(this,"pinnedOrigin",null);this.nonce=this.captureNonce()}get hasNonce(){return this.nonce!==null}acceptHello(e,t){return this.nonce===null||e.source!==this.win.parent||!e.origin||e.origin==="null"||t.nonce!==this.nonce||t.protocolVersion!==1||this.pinnedOrigin!==null&&e.origin!==this.pinnedOrigin?!1:(this.pinnedOrigin=e.origin,!0)}getPinnedOrigin(){return this.pinnedOrigin}captureNonce(){let e=this.extractFragmentNonce();return e===null?this.win.sessionStorage.getItem(_):(this.win.sessionStorage.setItem(_,e),this.stripFragmentKey(),e)}extractFragmentNonce(){let e=this.win.location.hash;if(!e.startsWith("#"))return null;let t=new URLSearchParams(e.slice(1)).get("fcd");return t===null||t.length===0?null:t}stripFragmentKey(){let{location:e,history:t}=this.win,i=new URLSearchParams(e.hash.slice(1));i.delete("fcd");let n=i.toString(),r=n.length>0?`#${n}`:"";t.replaceState(t.state,"",`${e.pathname}${e.search}${r}`)}};var he="2147483646",de="2px solid rgba(99, 102, 241, 0.95)",pe="rgba(99, 102, 241, 0.12)",M=class{constructor(e){this.doc=e;a(this,"container",null);a(this,"shown",[])}show(e){this.shown=[...e],this.renderBoxes()}refresh(){this.shown.length!==0&&this.renderBoxes()}clear(){this.shown=[],this.container?.replaceChildren()}dispose(){this.shown=[],this.container?.remove(),this.container=null}renderBoxes(){let e=this.ensureContainer();e.replaceChildren();for(let t of this.shown){let i=t.getBoundingClientRect();i.width<=0||i.height<=0||e.appendChild(this.createBox(i))}}ensureContainer(){if(this.container!==null)return this.container;let e=this.doc.createElement("div");return e.setAttribute(R,""),e.style.position="fixed",e.style.inset="0",e.style.pointerEvents="none",e.style.zIndex=he,this.doc.body.appendChild(e),this.container=e,e}createBox(e){let t=this.doc.createElement("div");return t.style.position="absolute",t.style.left=`${String(e.left)}px`,t.style.top=`${String(e.top)}px`,t.style.width=`${String(e.width)}px`,t.style.height=`${String(e.height)}px`,t.style.boxSizing="border-box",t.style.border=de,t.style.backgroundColor=pe,t.style.borderRadius="2px",t}};var B="http://www.w3.org/2000/svg",C=class{constructor(e){this.doc=e}elementsAt(e){let t=this.doc.elementsFromPoint(e.x,e.y),i=new Set,n=[];for(let r of t){if(r.closest(`[${R}]`)!==null)continue;let o=this.resolveSvgOwner(r);i.has(o)||(i.add(o),n.push(o))}return n}resolveSvgOwner(e){if(e.namespaceURI!==B)return e;let t=e;for(;t.parentElement!==null&&t.parentElement.namespaceURI===B;)t=t.parentElement;return t}};var ue=new Set(["html","body","script","style","template","noscript","link","meta","nextjs-portal"]),ce=.85,me=.6,ge=1,ve=.9,fe=12,Ee=25,P=class{constructor(e){this.win=e}isMeaningful(e,t){if(ue.has(e.tagName.toLowerCase())||this.isNextDevChrome(e)||this.isInvisible(e))return!1;let i=e.getBoundingClientRect();if(i.width<=0||i.height<=0)return!1;let n=t.width*t.height;return!(n>0&&i.width*i.height>ce*n)}dedupeAncestors(e){let t=[...e].sort((n,r)=>this.domDepth(n.element)-this.domDepth(r.element)),i=new Set;for(let n of t){if(i.has(n))continue;let r=t.filter(o=>o!==n&&!i.has(o)&&n.element.contains(o.element));r.length!==0&&this.resolveOverlap(n,r,i)}return t.filter(n=>!i.has(n))}rankAndCap(e,t){let i=Math.min(t??fe,Ee),n=[...e].sort((r,o)=>o.coverage-r.coverage||this.rectArea(r.bounds)-this.rectArea(o.bounds));return{candidates:n.slice(0,i),truncated:n.length>i}}resolveOverlap(e,t,i){if(e.coverage>=me&&t.length>=2){for(let n of t)i.add(n);return}if(this.exclusiveCellCount(e,t)<=ge){i.add(e);return}this.isPureWrapper(e,t)&&i.add(e)}exclusiveCellCount(e,t){let i=0;for(let n of e.hitCells)t.some(r=>r.hitCells.has(n))||i++;return i}isPureWrapper(e,t){let i=this.rectArea(e.bounds);return t.filter(r=>this.rectArea(r.bounds)>=ve*i).length===1}isInvisible(e){let t=this.win.getComputedStyle(e);return t.visibility==="hidden"||t.display==="none"?!0:t.opacity.length>0&&Number(t.opacity)===0}isNextDevChrome(e){return e.getAttributeNames().some(t=>t.startsWith("data-nextjs-"))}domDepth(e){let t=0,i=e.parentElement;for(;i!==null;)t++,i=i.parentElement;return t}rectArea(e){return e.width*e.height}};function x(s){if(s.length===0)return{left:0,top:0,right:0,bottom:0,width:0,height:0};let e=s[0].x,t=s[0].x,i=s[0].y,n=s[0].y;for(let r=1;r<s.length;r++){let o=s[r];o.x<e&&(e=o.x),o.x>t&&(t=o.x),o.y<i&&(i=o.y),o.y>n&&(n=o.y)}return{left:e,top:i,right:t,bottom:n,width:t-e,height:n-i}}function N(s,e,t=0,i=0){let n=s.left-e,r=s.right+e,o=s.top-e,l=s.bottom+e,h=t-(r-n);h>0&&(n-=h/2,r+=h/2);let d=i-(l-o);return d>0&&(o-=d/2,l+=d/2),{left:n,top:o,right:r,bottom:l,width:r-n,height:l-o}}function D(s,e){let t=s.x-e.x,i=s.y-e.y;return Math.sqrt(t*t+i*i)}function F(s,e){let t=Math.max(0,Math.floor(s.left)),i=Math.max(0,Math.floor(s.top)),n=Math.min(e.width,Math.ceil(s.right)),r=Math.min(e.height,Math.ceil(s.bottom));return{x:t,y:i,width:Math.max(1,n-t),height:Math.max(1,r-i)}}var ye=600,we=4,Re=16,I=class{sample(e,t,i){let n=N(x(e),t),r=i.width*i.height;if(n.width*n.height>we*r)return{kind:"too-large"};let o=this.walkPolyline(e,Math.min(t,Re)),l=Math.max(8,t/2);for(;;){let h=this.rasterize(n,l,o,t,i);if(h.length<=ye)return{kind:"ok",cellCenters:h,cellSize:l};l*=2}}walkPolyline(e,t){if(e.length===0)return[];let i=[e[0]];for(let n=1;n<e.length;n++){let r=e[n-1],o=e[n],l=Math.max(1,Math.ceil(D(r,o)/t));for(let h=1;h<=l;h++){let d=h/l;i.push({x:r.x+(o.x-r.x)*d,y:r.y+(o.y-r.y)*d})}}return i}rasterize(e,t,i,n,r){let o=Math.max(1,Math.ceil(e.width/t)),l=Math.max(1,Math.ceil(e.height/t)),h=new Set;for(let p of i){let u=this.clampIndex(Math.floor((p.x-n-e.left)/t),o),V=this.clampIndex(Math.floor((p.x+n-e.left)/t),o),G=this.clampIndex(Math.floor((p.y-n-e.top)/t),l),K=this.clampIndex(Math.floor((p.y+n-e.top)/t),l);for(let f=G;f<=K;f++)for(let E=u;E<=V;E++){let U=this.cellCenter(e,t,E,f);D(U,p)<=n&&h.add(f*o+E)}}let d=[];for(let p of h){let u=this.cellCenter(e,t,p%o,Math.floor(p/o));this.isInsideViewport(u,r)&&d.push(u)}return d}cellCenter(e,t,i,n){return{x:e.left+(i+.5)*t,y:e.top+(n+.5)*t}}clampIndex(e,t){return e<0?0:e>t-1?t-1:e}isInsideViewport(e,t){return e.x>=0&&e.x<=t.width&&e.y>=0&&e.y<=t.height}};var L=class{constructor(e,t,i,n,r){this.sampler=e;this.hitTester=t;this.filter=i;this.extractor=n;this.doc=r;a(this,"refCounter",0)}resolve(e,t,i){let n=this.getViewport(),r=this.sampler.sample(e,t,n);if(r.kind==="too-large")return{kind:"too-large"};let o=this.collectHits(r.cellCenters),l=this.toCandidates(o,r.cellCenters,n),h=this.filter.dedupeAncestors(l),d=this.filter.rankAndCap(h,i);return{kind:"ok",elements:d.candidates.map(u=>this.extractor.extract(u.element,this.stampRef(u.element),u.coverage)),regionBounds:F(N(x(e),t),n),truncated:d.truncated}}collectHits(e){let t=new Map;for(let i=0;i<e.length;i++)for(let n of this.hitTester.elementsAt(e[i])){let r=t.get(n);if(r===void 0){t.set(n,new Set([i]));continue}r.add(i)}return t}toCandidates(e,t,i){let n=[];for(let[r,o]of e){if(!this.filter.isMeaningful(r,i))continue;let l=this.toRect(r.getBoundingClientRect()),h=this.countCentersInside(t,l);n.push({element:r,bounds:l,hitCells:o,coverage:o.size/Math.max(1,h)})}return n}countCentersInside(e,t){let i=0;for(let n of e)n.x>=t.x&&n.x<=t.x+t.width&&n.y>=t.y&&n.y<=t.y+t.height&&i++;return i}stampRef(e){let t=e.getAttribute(c);if(t!==null&&t.length>0)return t;this.refCounter++;let i=`fcd-${String(this.refCounter)}`;return e.setAttribute(c,i),i}getViewport(){let e=this.doc.documentElement;return{width:e.clientWidth,height:e.clientHeight}}toRect(e){return{x:e.x,y:e.y,width:e.width,height:e.height}}};var v=null,be=()=>{};function Se(){if(typeof window>"u"||window.parent===window)return be;if(v!==null)return v;let s=Ae(window);s.install();let e=()=>{v===e&&(v=null,s.dispose())};return v=e,e}function Ae(s){let e=s.document;return new A(s,new b,new O(s),new T(s.parent),new L(new I,new C(e),new P(s),new S(s),e),new M(e))}return X(Te);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgecart/designer-runtime",
3
- "version": "1.202608221935.0",
3
+ "version": "1.202609190800.0",
4
4
  "type": "module",
5
5
  "description": "ForgeCart visual-editor guest runtime for tenant storefronts: dormant iframe protocol endpoint, spray-region element resolution, and the Turbopack data-fc-source stamping loader",
6
6
  "sideEffects": false,