@seatlayer/core 0.62.0 → 0.63.1

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.
Files changed (49) hide show
  1. package/dist/{categoryInventory-EaqLUHxJ.d.ts → categoryInventory-C3RogGHF.d.ts} +1 -1
  2. package/dist/{categoryInventory-C4-bA5Nx.d.cts → categoryInventory-DEgsjxCC.d.cts} +1 -1
  3. package/dist/chunk-UL5OIGIF.js +1 -0
  4. package/dist/core/chart-ops/index.cjs +1 -1
  5. package/dist/core/chart-ops/index.d.cts +6 -4
  6. package/dist/core/chart-ops/index.d.ts +6 -4
  7. package/dist/core/chart-ops/index.js +1 -1
  8. package/dist/core/inventory/index.d.cts +4 -4
  9. package/dist/core/inventory/index.d.ts +4 -4
  10. package/dist/core/layout/index.d.cts +4 -4
  11. package/dist/core/layout/index.d.ts +4 -4
  12. package/dist/core/quality/index.d.cts +3 -3
  13. package/dist/core/quality/index.d.ts +3 -3
  14. package/dist/core/render-assets/index.cjs +1 -1
  15. package/dist/core/render-assets/index.d.cts +11 -6
  16. package/dist/core/render-assets/index.d.ts +11 -6
  17. package/dist/core/render-assets/index.js +1 -1
  18. package/dist/core/seatConfidence.d.cts +1 -1
  19. package/dist/core/seatConfidence.d.ts +1 -1
  20. package/dist/core/sections/index.d.cts +5 -5
  21. package/dist/core/sections/index.d.ts +5 -5
  22. package/dist/index.cjs +1 -1
  23. package/dist/index.d.cts +14 -10
  24. package/dist/index.d.ts +14 -10
  25. package/dist/index.js +1 -1
  26. package/dist/{labeling-Cwufmw3W.d.cts → labeling-DRFC35VK.d.cts} +1 -1
  27. package/dist/{labeling-B4i6gdAb.d.ts → labeling-DTHo03rf.d.ts} +1 -1
  28. package/dist/{layout-CVumqAiR.d.ts → layout-BXB8Rf4n.d.ts} +3 -3
  29. package/dist/{layout-CGKQ3Pi2.d.cts → layout-DRB0-NGc.d.cts} +3 -3
  30. package/dist/{renderedQuality-C86YHszi.d.ts → renderedQuality-BjSBiqkN.d.ts} +1 -1
  31. package/dist/{renderedQuality-Bvj_f4Ep.d.cts → renderedQuality-DK7IGCju.d.cts} +1 -1
  32. package/dist/{renderer-Bq6tKuUD.d.cts → renderer-BNzVBOBW.d.cts} +1 -1
  33. package/dist/{renderer-DwYiuiuC.d.ts → renderer-Bhc5CgOS.d.ts} +1 -1
  34. package/dist/{sections-hr18lj4d.d.ts → sections-BrQV1WzI.d.ts} +1 -1
  35. package/dist/{sections-CXMjxU_S.d.cts → sections-D2bxgVgg.d.cts} +1 -1
  36. package/dist/{segmentedRowModel-Cgp4cK2q.d.cts → segmentedRowModel-BQYSdf7k.d.cts} +1 -1
  37. package/dist/{segmentedRowModel-lcp9clIL.d.ts → segmentedRowModel-Cl3X8SKt.d.ts} +1 -1
  38. package/dist/{ticketRestrictions-NW94Eo3R.d.ts → ticketRestrictions-B9WkJ6YG.d.ts} +2 -2
  39. package/dist/{ticketRestrictions-BY7Nvzc-.d.cts → ticketRestrictions-QBvY3Zi7.d.cts} +2 -2
  40. package/dist/{types-D_pq-iqz.d.cts → types-DmgX-iuD.d.cts} +1 -1
  41. package/dist/{types-D_pq-iqz.d.ts → types-DmgX-iuD.d.ts} +1 -1
  42. package/dist/view3d/crossfade/panorama.d.cts +1 -1
  43. package/dist/view3d/crossfade/panorama.d.ts +1 -1
  44. package/dist/view3d/index.cjs +104 -40
  45. package/dist/view3d/index.d.cts +4 -2
  46. package/dist/view3d/index.d.ts +4 -2
  47. package/dist/view3d/index.js +106 -42
  48. package/package.json +1 -1
  49. package/dist/chunk-6CNWW47A.js +0 -1
@@ -1 +1 @@
1
- "use strict";var Zn=Object.create;var Se=Object.defineProperty;var Wn=Object.getOwnPropertyDescriptor;var eo=Object.getOwnPropertyNames;var to=Object.getPrototypeOf,no=Object.prototype.hasOwnProperty;var oo=(t,e)=>{for(var n in e)Se(t,n,{get:e[n],enumerable:!0})},St=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of eo(e))!no.call(t,i)&&i!==n&&Se(t,i,{get:()=>e[i],enumerable:!(r=Wn(e,i))||r.enumerable});return t};var ro=(t,e,n)=>(n=t!=null?Zn(to(t)):{},St(e||!t||!t.__esModule?Se(n,"default",{value:t,enumerable:!0}):n,t)),io=t=>St(Se({},"__esModule",{value:!0}),t);var na={};oo(na,{COLORBLIND_SAFE_PALETTE:()=>bt,ChartOperationError:()=>u,DEFAULT_FLOOR_HEIGHT_STEP_M:()=>ct,DEFAULT_SECTION_CORNER_SMOOTHING:()=>Ze,MAX_FLOOR_BASE_HEIGHT_M:()=>je,addArcFanRows:()=>oi,addBookableGridArray:()=>vi,addBoothArray:()=>ui,addChartCategory:()=>Cn,addChartFloor:()=>No,addChartZone:()=>$o,addGAArea:()=>li,addRowBlock:()=>ai,addTableArray:()=>di,applyPolygonHole:()=>Ir,applyReferenceScanRows:()=>Si,applySectionCornerSmoothing:()=>kr,applySectionOutlineShaping:()=>fn,applySectionRowFit:()=>xr,arcFanInputForGroup:()=>Mn,assignSectionInventoryCategory:()=>Pr,automaticPlacementCenter:()=>Wr,confirmReferenceCategoryOutputColor:()=>Gr,convertGeneratedSectionToPolygon:()=>Mr,countCoveredInventory:()=>Te,familyCategoryLabel:()=>pt,gaAreaFootprint:()=>jn,groupRowsAsSegmented:()=>fi,insertSeatingBlock:()=>br,joinGAAreas:()=>qi,mergeRows:()=>Gi,mirrorFirstFloor:()=>ge,parseSeatRefId:()=>Oi,pickColorblindSafeCategoryColor:()=>vn,previewArcFanRows:()=>mt,previewBookableGridArray:()=>Ii,previewGeneratedSectionPolygonConversion:()=>dn,previewJoinGAAreas:()=>Ji,previewPolygonHole:()=>Ne,previewRemovePolygonHole:()=>sn,previewRowCubicPath:()=>on,previewSectionRowFit:()=>rn,reassignColorblindSafeCategoryColors:()=>Dr,relabelChartRows:()=>hr,removeChartCategory:()=>Xr,removeChartFloor:()=>Ko,removeChartObjects:()=>fr,removeChartZone:()=>Bo,removePolygonHole:()=>vr,renameChartFloor:()=>Do,reorderChartCategories:()=>Tr,replaceArcFanRows:()=>ri,replaceRowBlock:()=>bi,resetSeatOverrides:()=>ji,resizeShapes:()=>ea,resolveCreationCategory:()=>Jr,seatRefId:()=>we,sectionInventorySelectionSummary:()=>ln,setRowBlockSpacing:()=>$i,splitRow:()=>Ki,straightenAndSpaceRows:()=>zi,transformSectionBoundary:()=>Ar,transformSectionBoundaryObject:()=>un,ungroupSegmentedRow:()=>gi,updateBooths:()=>dr,updateCategoryDefinitions:()=>In,updateChartFloorBaseHeight:()=>Go,updateChartTheme:()=>Qr,updateChartZones:()=>zo,updateGAAreas:()=>ur,updateRowCubicPath:()=>mr,updateRows:()=>ki,updateSeatOverrides:()=>_i,updateSectionExactPath:()=>_r,updateSectionMetadata:()=>Or,updateSegmentedRow:()=>hi,updateShapes:()=>Wi,updateStageKinds:()=>ta,updateTables:()=>lr,updateTextObjects:()=>gr,updateViewFromSeatFallback:()=>Zr});module.exports=io(na);var It=t=>Math.max(1,t.fontSize*.6+(t.letterSpacing??0));function ao(t,e){let n=t.text.split(/\r?\n/);if(!t.width)return Math.max(1,n.length);let r=Math.max(1,Math.floor(e/It(t))),i=0;for(let a of n){if(!a.length){i+=1;continue}let o=0;for(let s of a.split(/\s+/)){let c=s.length;o&&o+1+c<=r?o+=1+c:(i+=Math.max(1,Math.ceil(c/r)),o=c%r)}}return Math.max(1,i)}function vt(t){let e=t.background?.padding??0,n=t.text.split(/\r?\n/),r=Math.max(1,...n.map(s=>s.length))*It(t),i=t.width??r+e*2,a=Math.max(1,i-e*2),o=ao(t,a);return{width:i,height:o*t.fontSize*(t.lineHeight??1.2)+e*2,lineCount:o,padding:e}}var ia=Math.PI/180;function E(t,e){return Math.hypot(t.x-e.x,t.y-e.y)}function qe(t,e,n){return{x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n}}function Ct(t,e){let n=1-e,r=n*n*n,i=3*n*n*e,a=3*n*e*e,o=e*e*e;return{x:r*t.start.x+i*t.control1.x+a*t.control2.x+o*t.end.x,y:r*t.start.y+i*t.control1.y+a*t.control2.y+o*t.end.y}}function Ie(t,e,n=192){if(!Number.isInteger(e)||e<1)throw new Error("Path point count must be a positive integer");if(e===1)return[Ct(t,.5)];let r=Array.from({length:n+1},(c,l)=>Ct(t,l/n)),i=new Float64Array(r.length);for(let c=1;c<r.length;c+=1){let l=r[c].x-r[c-1].x,d=r[c].y-r[c-1].y;i[c]=i[c-1]+Math.hypot(l,d)}let a=i[i.length-1];if(a<=1e-9)return Array.from({length:e},()=>({...t.start}));let o=[],s=1;for(let c=0;c<e;c+=1){let l=a*c/(e-1);for(;s<i.length-1&&i[s]<l;)s+=1;let d=i[s-1],g=i[s],h=g===d?0:(l-d)/(g-d);o.push({x:r[s-1].x+(r[s].x-r[s-1].x)*h,y:r[s-1].y+(r[s].y-r[s-1].y)*h})}return o}function de(t){if(t.length<3)return 0;let e=0;for(let n=0,r=t.length-1;n<t.length;r=n++)e+=(t[r].x+t[n].x)*(t[r].y-t[n].y);return Math.abs(e)/2}function so(t,e,n){return Math.max(e,Math.min(n,t))}function co(t){return so(t,0,1)}function Pt(t){let e=co(t);return e*e*(3-2*e)}var oe=Math.PI*2;function re(t){return Number.isFinite(t.x)&&Number.isFinite(t.y)}function lo(t,e,n){let r=e-t;if(n){for(;r<0;)r+=oe;for(;r>=oe;)r-=oe}else{for(;r>0;)r-=oe;for(;r<=-oe;)r+=oe}return r}function ve(t){if(t.version!==1||t.closed!==!0||!re(t.start)||!Array.isArray(t.segments)||t.segments.length<2||t.segments.length>512)return!1;let e=t.start;for(let n of t.segments){if(!n||!re(n.end))return!1;if(n.kind==="line"){if(E(e,n.end)<=1e-9)return!1}else if(n.kind==="bezier"){if(!re(n.control1)||!re(n.control2)||E(e,n.end)<=1e-9)return!1}else if(n.kind==="arc"){if(!re(n.center)||!Number.isFinite(n.radius)||n.radius<=1e-6||Math.abs(E(e,n.center)-n.radius)>Math.max(1e-4,n.radius*1e-4)||Math.abs(E(n.end,n.center)-n.radius)>Math.max(1e-4,n.radius*1e-4)||E(e,n.end)<=1e-9)return!1}else return!1;e=n.end}return E(e,t.start)<=1e-4}function uo(t,e,n){let r=1-n;return{x:r**3*t.x+3*r**2*n*e.control1.x+3*r*n**2*e.control2.x+n**3*e.end.x,y:r**3*t.y+3*r**2*n*e.control1.y+3*r*n**2*e.control2.y+n**3*e.end.y}}function Ye(t,e=2){if(!ve(t))throw new Error("Section outline path is invalid");let n=Math.max(.25,e),r=[{...t.start}],i=t.start;for(let a of t.segments){if(a.kind==="line")r.push({...a.end});else if(a.kind==="arc"){let o=Math.atan2(i.y-a.center.y,i.x-a.center.x),s=Math.atan2(a.end.y-a.center.y,a.end.x-a.center.x),c=lo(o,s,a.clockwise),l=Math.max(2,Math.ceil(Math.abs(c)*a.radius/n));for(let d=1;d<=l;d+=1){let g=o+c*d/l;r.push({x:a.center.x+Math.cos(g)*a.radius,y:a.center.y+Math.sin(g)*a.radius})}}else{let o=E(i,a.control1)+E(a.control1,a.control2)+E(a.control2,a.end),s=Math.max(2,Math.ceil(o/n));for(let c=1;c<=s;c+=1)r.push(uo(i,a,c/s))}i=a.end}return E(r[r.length-1],r[0])<=1e-4&&r.pop(),r}function At(t,e,n){return Qe(t,i=>({x:i.x+e,y:i.y+n}))}function Qe(t,e,n=1,r=!1){return{...t,start:e(t.start),segments:t.segments.map(i=>i.kind==="line"?{...i,end:e(i.end)}:i.kind==="arc"?{...i,center:e(i.center),radius:i.radius*Math.abs(n),clockwise:r?!i.clockwise:i.clockwise,end:e(i.end)}:{...i,control1:e(i.control1),control2:e(i.control2),end:e(i.end)})}}var Ze=45,Xe=150,fo=60;function go(t){let e=Ze/100;if(t<=e)return Xe;let n=Math.min(1,(t-e)/(1-e));return Xe-n*(Xe-fo)}var Ot=.5523;function Mt(t,e){return Math.abs(t.x-e.x)<=1e-6&&Math.abs(t.y-e.y)<=1e-6}function ho(t){let e=[],n=[];for(t.forEach((r,i)=>{re(r)&&(e.length&&Mt(e[e.length-1],r)||(e.push({x:r.x,y:r.y}),n.push(i)))});e.length>1&&Mt(e[0],e[e.length-1]);)e.pop(),n.pop();return{points:e,sourceIndex:n}}var bo=.5,po=4/3;function mo(t,e,n){let r=e.x-t.x,i=e.y-t.y,a=Math.hypot(r,i);if(a<=1e-9)return{kind:"line",end:{...e}};let o=-i/a,s=r/a,c=n*po;return{kind:"bezier",control1:{x:t.x+r/3+o*c,y:t.y+i/3+s*c},control2:{x:t.x+r*2/3+o*c,y:t.y+i*2/3+s*c},end:{...e}}}function _t(t,e){let{points:n,sourceIndex:r}=ho(t),i=n.length;if(i<3)return null;let a=Math.min(100,Math.max(0,e.cornerSmoothing??0))/100,o=e.edgeCurvature,s=new Array(i).fill(0);if(o?.length)for(let w=0;w<i;w+=1){let S=o[r[w]];s[w]=Number.isFinite(S)?Math.min(100,Math.max(-100,S))/100:0}let c=s.some(w=>Math.abs(w)>1e-6);if(a<=0&&!c)return null;let l=e.wideAngleThresholdDeg??go(a),d=[];for(let w=0;w<i;w+=1)d[w]=E(n[w],n[(w+1)%i]);let g=new Array(i).fill(0);for(let w=0;w<i;w+=1){let S=n[(w-1+i)%i],I=n[w],M=n[(w+1)%i],D={x:S.x-I.x,y:S.y-I.y},T={x:M.x-I.x,y:M.y-I.y},U=Math.hypot(D.x,D.y),K=Math.hypot(T.x,T.y);if(U<=1e-9||K<=1e-9)continue;let O=Math.min(1,Math.max(-1,(D.x*T.x+D.y*T.y)/(U*K))),$=Math.acos(O)*180/Math.PI;if($<l)continue;let j=Pt(($-l)/(180-l));g[w]=a*j*.5*Math.min(U,K)}for(let w=0;w<i;w+=1){let S=(w+1)%i,I=g[w]+g[S];if(I>d[w]&&I>1e-9){let M=d[w]/I;g[w]*=M,g[S]*=M}}let h=new Array(i),f=new Array(i);for(let w=0;w<i;w+=1){let S=n[(w-1+i)%i],I=n[w],M=n[(w+1)%i];if(g[w]<=1e-6){h[w]={...I},f[w]={...I};continue}let D=E(I,S)||1,T=E(I,M)||1;h[w]={x:I.x+(S.x-I.x)/D*g[w],y:I.y+(S.y-I.y)/D*g[w]},f[w]={x:I.x+(M.x-I.x)/T*g[w],y:I.y+(M.y-I.y)/T*g[w]}}if(g.every(w=>w<=1e-6)&&!c)return null;let b=[],y={...f[0]},x=y,v=(w,S)=>{if(E(x,w)<=1e-9)return;let I=s[S];Math.abs(I)>1e-6?b.push(mo(x,w,I*bo*d[S])):b.push({kind:"line",end:{...w}}),x=w};for(let w=1;w<=i;w+=1){let S=w%i,I=n[S];v(h[S],(w-1)%i),g[S]>1e-6&&E(h[S],f[S])>1e-9&&(b.push({kind:"bezier",control1:qe(h[S],I,Ot),control2:qe(f[S],I,Ot),end:{...f[S]}}),x=f[S])}if(!b.length)return null;let p=b[b.length-1];E(p.end,y)>1e-9&&(p.kind==="line"?p.end={...y}:b.push({kind:"line",end:{...y}}));let m={version:1,closed:!0,start:y,segments:b};return ve(m)?m:null}var jt="ABCDEFGHIJKLMNOPQRSTUVWXYZ",yo="ABCDEFGHJKLMNPQRSTUVWXYZ",wo="abcdefghijklmnopqrstuvwxyz";function kt(t,e){let n=e.length,r=t+1,i="";for(;r>0;){r-=1;let a=r%n;i=e[a]+i,r=Math.floor(r/n)}return i}function xo(t,e){let n=e.startAt-1,r=t+n;if(e.scheme==="numbers")return String(r+1);let i=e.skipAmbiguous?yo:jt;return kt(r,i)}function We(t,e=!1){let n=e?wo:jt;return kt(Math.max(0,Math.floor(t)-1),n)}var So=[[1e3,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]];function Rt(t){if(!Number.isFinite(t)||t<=0)return String(t);let e=Math.floor(t),n="";for(let[r,i]of So)for(;e>=r;)n+=i,e-=r;return n}function Ft(t,e){let n=t.length;return t.map((r,i)=>{let a=e.reverse?n-1-i:i;return{...r,label:xo(a,e)}})}function Io(t){let e=new Array(t);return Array.from({length:t},(n,r)=>r).sort((n,r)=>Math.abs(2*n-(t-1))-Math.abs(2*r-(t-1))||n-r).forEach((n,r)=>e[n]=r),e}function et(t,e){let n=t.seatLabelStart??1,r=t.seatNumbering?.direction??"ltr",i=t.seatNumbering?.step??1,a=t.seatNumbering?.scheme??"decimal",o=t.seatNumbering?.prefix??"",s=t.seatNumbering?.endAt,c=t.seatCount;if(a==="updown"||a==="updown-descending"){let f=Math.ceil(c/2),b=a==="updown"?e<f?n+2*e:n-1+2*(c-e):e<f?n+2*(f-1-e):n+1+2*(e-f);return`${o}${b}`}let l=a==="odd"||a==="even"?2:i,d=s!=null&&Number.isFinite(s)?s-(c-1)*l:n,g=r==="center"?Io(c)[e]:r==="rtl"?c-1-e:e,h;switch(a){case"odd":{let f=d%2===1?d:d+1;h=String(f+g*2);break}case"even":{let f=d%2===0?d:d+1;h=String(f+g*2);break}case"roman":h=Rt(d+g*i);break;case"letters-upper":h=We(d+g*i,!1);break;case"letters-lower":h=We(d+g*i,!0);break;default:h=String(d+g*i);break}return`${o}${h}`}function vo(t){return{...t.canonical,seatCount:t.totalSeats,label:t.displayLabel,displayLabel:t.displayLabel}}function Lt(t,e,n){return n?.label??`${t.label}-${et(t,e)}`}function Tt(t,e,n,r){if(r?.displayLabel)return r.displayLabel;if(!n)return`${t.displayLabel??t.label}-${et(t,e)}`;let i=vo(n),a=n.displayOffset+e;return`${n.displayLabel}-${et(i,a)}`}function Dt(t){return t?t.accessibility&&t.accessibility.length?t.wheelchairSpaceType&&!t.accessibility.includes("wheelchair")?["wheelchair",...t.accessibility]:t.accessibility:t.wheelchairSpaceType?["wheelchair"]:t.accessible?["wheelchair"]:[]:[]}var Pe=Math.PI/180,Co=9,ie=16;function nt(t,e,n,r){let i=n*Pe,a=Math.cos(i),o=Math.sin(i);return{x:r.x+t*a-e*o,y:r.y+t*o+e*a}}function ue(t){let{seatCount:e,seatSpacing:n,curve:r,rotation:i,origin:a}=t,o=[];if(t.path)return Ie(t.path,e);if(e<=1)return e===1&&o.push({x:a.x,y:a.y}),o;if(r===0){for(let l=0;l<e;l++)o.push(nt(l*n,0,i,a));return o}let s=r/(e-1)*Pe,c=n/(2*Math.sin(Math.abs(s)/2));for(let l=0;l<e;l++){let d=l*s,g=c*Math.sin(d),h=-c+c*Math.cos(d);o.push(nt(g,h,i,a))}return o}function Po(t){let e=new Map;if(t.overrides)for(let n of t.overrides)e.set(n.index,n);return e}function Oo(t,e){let n=Po(t);return ue(t).map((r,i)=>{let a=n.get(i),o=Dt(a),s=Lt(t,i,a),c={...t.commercial,...a?.commercial};return{index:i,x:r.x+(a?.dx??0),y:r.y+(a?.dy??0),label:s,displayLabel:Tt(t,i,e,a),categoryKey:a?.categoryKey??t.categoryKey,skipped:!!a?.skip,accessible:o.length>0,accessibility:o,wheelchairSpaceType:a?.wheelchairSpaceType,commercial:Object.values(c).some(l=>l!==void 0&&l!==!1&&l!=="")?c:void 0,glyph:a?.glyph,viewUrl:a?.viewFromSeatUrl??t.viewFromSeatUrl,viewMeta:a?.viewFromSeatUrl?a.viewFromSeatMeta:t.viewFromSeatMeta,labelStyle:a?.labelStyle}})}function z(t){let e=[];for(let n of Oo(t))n.skipped||e.push({id:`${t.id}:${n.index}`,label:n.label,displayLabel:n.displayLabel===n.label?void 0:n.displayLabel,x:n.x,y:n.y,rowId:t.id,categoryKey:n.categoryKey,accessible:n.accessible||void 0,accessibility:n.accessibility.length?n.accessibility:void 0,wheelchairSpaceType:n.wheelchairSpaceType,commercial:n.commercial,glyph:n.glyph,viewUrl:n.viewUrl,viewMeta:n.viewMeta,labelStyle:n.labelStyle});return e}function Mo(t){if(t.seatCountsBySide)return{...t.seatCountsBySide};let e=t.sides&&t.sides.length?t.sides:["top","bottom"],n=["top","bottom","left","right"].filter(a=>e.includes(a)),r={top:0,bottom:0,left:0,right:0};if(!n.length)return r;let i=Math.max(0,Math.round(t.seatCount));for(let a=0;a<i;a++)r[n[a%n.length]]+=1;return r}function Ao(t){let e=[],n=Math.max(0,Math.round(t.seatCount));if(n===0)return e;let r=new Map((t.overrides??[]).map(d=>[d.index,d])),i=(d,g,h,f)=>{let b=r.get(d),y=Dt(b),x=b?.label??`${t.label}-${d+1}`,v=t.displayLabel??t.label;return{index:d,label:x,displayLabel:b?.displayLabel??`${v}-${d+1}`,x:g+(b?.dx??0),y:h+(b?.dy??0),categoryKey:b?.categoryKey??t.categoryKey,skipped:!!b?.skip,accessible:y.length>0,accessibility:y,wheelchairSpaceType:b?.wheelchairSpaceType,commercial:b?.commercial,glyph:b?.glyph,viewUrl:b?.viewFromSeatUrl,viewMeta:b?.viewFromSeatUrl?b.viewFromSeatMeta:void 0,labelStyle:b?.labelStyle,...f?{side:f}:{}}};if(t.shape==="round"){let d=(t.radius??40)+ie,g=t.rotation*Pe,h=Math.max(0,Math.min(360,t.seatArc??360));if(h>=360||n===1){for(let x=0;x<n;x++){let v=g+x/n*2*Math.PI;e.push(i(x,t.center.x+d*Math.cos(v),t.center.y+d*Math.sin(v)))}return e}let f=h*Pe,b=(2*Math.PI-f)/2,y=g+b;for(let x=0;x<n;x++){let v=y+x/(n-1)*f;e.push(i(x,t.center.x+d*Math.cos(v),t.center.y+d*Math.sin(v)))}return e}let a=t.width??80,o=t.height??50,s=Mo(t),c=["top","bottom","left","right"],l=0;for(let d of c){let g=s[d];for(let h=0;h<g;h++){let f,b;d==="top"?(f=-a/2+(h+.5)*a/g,b=-o/2-ie):d==="bottom"?(f=-a/2+(h+.5)*a/g,b=o/2+ie):d==="left"?(f=-a/2-ie,b=-o/2+(h+.5)*o/g):(f=a/2+ie,b=-o/2+(h+.5)*o/g);let y=nt(f,b,t.rotation,t.center);e.push(i(l++,y.x,y.y,d))}}return e}function Q(t){return Ao(t).filter(e=>!e.skipped).map(e=>({id:`${t.id}:${e.index}`,label:e.label,...e.displayLabel!==e.label?{displayLabel:e.displayLabel}:{},x:e.x,y:e.y,rowId:t.id,categoryKey:e.categoryKey,...e.accessible?{accessible:!0}:{},...e.accessibility.length?{accessibility:e.accessibility}:{},...e.wheelchairSpaceType?{wheelchairSpaceType:e.wheelchairSpaceType}:{},...e.commercial?{commercial:e.commercial}:{},...e.glyph?{glyph:e.glyph}:{},...e.viewUrl?{viewUrl:e.viewUrl}:{},...e.viewUrl&&e.viewMeta?{viewMeta:e.viewMeta}:{},...e.labelStyle?{labelStyle:e.labelStyle}:{}}))}function Gt(t){return[{id:`${t.id}:0`,label:t.label,...t.displayLabel&&t.displayLabel!==t.label?{displayLabel:t.displayLabel}:{},x:t.center.x,y:t.center.y,rowId:t.id,categoryKey:t.categoryKey,kind:"booth"}]}function Et(t,e){let n=!1;for(let r=0,i=e.length-1;r<e.length;i=r++){let a=e[r].x,o=e[r].y,s=e[i].x,c=e[i].y;o>t.y!=c>t.y&&t.x<(s-a)*(t.y-o)/(c-o)+a&&(n=!n)}return n}function _o(t,e){return e.some((n,r)=>{let i=e[(r+1)%e.length],a=(t.y-n.y)*(i.x-n.x)-(t.x-n.x)*(i.y-n.y);if(Math.abs(a)>1e-7)return!1;let o=(t.x-n.x)*(i.x-n.x)+(t.y-n.y)*(i.y-n.y),s=(i.x-n.x)**2+(i.y-n.y)**2;return o>=-1e-7&&o<=s+1e-7})}function N(t,e,n){return Et(t,e)&&!(n??[]).some(r=>Et(t,r)||_o(t,r))}function tt(t){if(!t.length)return{x:0,y:0};let e=0,n=0;for(let r of t)e+=r.x,n+=r.y;return{x:e/t.length,y:n/t.length}}function F(t){switch(t.type){case"row":{let e=z(t);if(!e.length)return{x:t.origin.x,y:t.origin.y};let n=0,r=0;for(let i of e)n+=i.x,r+=i.y;return{x:n/e.length,y:r/e.length}}case"table":case"booth":return{x:t.center.x,y:t.center.y};case"gaArea":return tt(t.points);case"section":return tt(t.outline);case"text":return{x:t.position.x,y:t.position.y};case"shape":return t.points&&t.points.length?tt(t.points):t.x!=null&&t.y!=null&&t.width!=null&&t.height!=null?{x:t.x+t.width/2,y:t.y+t.height/2}:{x:t.x??0,y:t.y??0};case"decorImage":return{x:t.x+t.width/2,y:t.y+t.height/2}}}function Nt(t,e){return t.length===e.length&&t.every((n,r)=>n.x===e[r].x&&n.y===e[r].y)}function jo(t,e){if(t.type!=="gaArea"||!Nt(t.points,e.outline))return!1;let n=t.holes??[],r=e.holes??[];return n.length===r.length&&n.every((i,a)=>Nt(i,r[a]))}function Kt(t,e){let n=t.filter(o=>o.type==="section"),r="referenceInventorySource"in e?e.referenceInventorySource?.logicalSectionId:void 0,i=F(e);return(r?n.find(o=>(o.logicalSectionId??o.id)===r&&(jo(e,o)||N(i,o.outline,o.holes))):void 0)??n.find(o=>N(i,o.outline,o.holes))}function G(t){return t.floors&&t.floors.length?t.floors:[{id:"floor-0",name:"Main",objects:t.objects,focalPoint:t.focalPoint,referenceImage:t.referenceImage,backgroundImage:t.backgroundImage}]}function H(t){return t.floors&&t.floors.length?t.floors.flatMap(e=>e.objects):t.objects}var Ce=40;function $t(t){let e=1/0,n=1/0,r=-1/0,i=-1/0,a=(o,s)=>{o<e&&(e=o),s<n&&(n=s),o>r&&(r=o),s>i&&(i=s)};for(let o of H(t))if(o.type==="row"){let s=new Map((o.overrides??[]).map(c=>[c.index,c]));ue(o).forEach((c,l)=>{let d=s.get(l);d?.skip||a(c.x+(d?.dx??0),c.y+(d?.dy??0))})}else if(o.type==="gaArea")for(let s of o.points)a(s.x,s.y);else if(o.type==="section")for(let s of o.outline)a(s.x,s.y);else if(o.type==="decorImage")a(o.x,o.y),a(o.x+o.width,o.y+o.height);else if(o.type==="shape")if(o.points&&o.points.length)for(let s of o.points)a(s.x,s.y);else o.x!=null&&o.y!=null&&o.width!=null&&o.height!=null&&(a(o.x,o.y),a(o.x+o.width,o.y+o.height));else if(o.type==="table"){let s=ie+Co,c=o.shape==="round"?(o.radius??40)+s:Math.max((o.width??80)/2,(o.height??50)/2)+s;a(o.center.x-c,o.center.y-c),a(o.center.x+c,o.center.y+c)}else if(o.type==="booth"){let s=Math.max(o.width,o.height)/2;a(o.center.x-s,o.center.y-s),a(o.center.x+s,o.center.y+s)}else if(o.type==="text"){let s=vt(o);a(o.position.x,o.position.y),a(o.position.x+s.width,o.position.y+s.height)}for(let o of[t.referenceImage,t.backgroundImage]){if(!o)continue;let{center:s,width:c}=o,l=c*3/4;a(s.x-c/2,s.y-l/2),a(s.x+c/2,s.y+l/2)}if(!isFinite(e)){let o=t.focalPoint??{x:0,y:0};return{x:o.x-200,y:o.y-200,width:400,height:400}}return{x:e-Ce,y:n-Ce,width:r-e+Ce*2,height:i-n+Ce*2}}var fe=[{key:"wheelchair",label:"Wheelchair space",short:"Wheelchair",icon:"\u267F"},{key:"companion",label:"Companion seat",short:"Companion",icon:"\u{1F9D1}\u200D\u{1F91D}\u200D\u{1F9D1}"},{key:"semi-ambulatory",label:"Semi-ambulatory (limited mobility)",short:"Limited mobility",icon:"\u{1F9AF}"},{key:"designated-aisle",label:"Designated aisle / transfer seat",short:"Aisle transfer",icon:"AS"},{key:"step-free",label:"Step-free accessible seat",short:"Step-free",icon:"SF"},{key:"hearing",label:"Assistive listening",short:"Hearing",icon:"\u{1F9BB}"},{key:"cart",label:"CART live-caption view",short:"CART captions",icon:"CC"},{key:"sign-language",label:"Sign-language view",short:"Sign language",icon:"\u{1F91F}"},{key:"low-vision",label:"Blind / low-vision viewing",short:"Low vision",icon:"LV"},{key:"sensory-friendly",label:"Quiet / sensory-friendly seating",short:"Sensory-friendly",icon:"QS"},{key:"plus-size",label:"Plus-size seat",short:"Plus-size",icon:"\u{1F4BA}"},{key:"lift-armrest",label:"Lift-up armrest",short:"Lift armrest",icon:"\u2195\uFE0F"}],xa=new Map(fe.map(t=>[t.key,t]));var ko=[{key:"obstructedView",label:"Obstructed view",short:"Obstructed",icon:"\u26D4"},{key:"restrictedView",label:"Restricted view",short:"Restricted",icon:"\u{1F441}"},{key:"premium",label:"Premium seat",short:"Premium",icon:"\u2605"}],Sa=new Map(ko.map(t=>[t.key,t]));var ot=8,rt=24,Ro=["reference-focal","bar","entrance","exit","restroom","screen","sound","concession","coat","wall","rail","suite","obstruction"],Ia=new Set(Ro);var u=class extends Error{constructor(n,r,i={}){super(r);this.code=n;this.details=i;this.name="ChartOperationError"}};function C(t,e){let n=G(t),r=e?n.find(i=>i.id===e):n[0];if(!r)throw new u("floor_not_found",`Unknown chart floor: ${e}`,{floorId:e});return{floorId:r.id,objects:r.objects}}function k(t,e){if(!t.categories.some(n=>n.key===e))throw new u("category_not_found",`Unknown chart category: ${e}. Call get_chart to list valid category keys.`,{categoryKey:e})}function _(t,e,n,r){let i=new Set([...r,...t.categories.map(a=>a.key),...t.zones?.map(a=>a.id)??[],...t.floors?.map(a=>a.id)??[],...t.floors?.length?t.floors.flatMap(a=>a.objects.map(o=>o.id)):t.objects.map(a=>a.id)]);for(let a=0;a<100;a++){let o=n(e);if(o&&!i.has(o))return r.add(o),o}throw new u("id_generation_failed",`Unable to allocate a unique ${e} id`)}function Fo(t){let e=t.slice().sort((a,o)=>a.x-o.x||a.y-o.y);if(e.length<3)return e;let n=(a,o,s)=>(o.x-a.x)*(s.y-a.y)-(o.y-a.y)*(s.x-a.x),r=[];for(let a of e){for(;r.length>=2&&n(r[r.length-2],r[r.length-1],a)<=0;)r.pop();r.push(a)}let i=[];for(let a=e.length-1;a>=0;a--){let o=e[a];for(;i.length>=2&&n(i[i.length-2],i[i.length-1],o)<=0;)i.pop();i.push(o)}return r.pop(),i.pop(),r.concat(i)}function Lo(t,e){if(!t.length)return t;let n={x:t.reduce((r,i)=>r+i.x,0)/t.length,y:t.reduce((r,i)=>r+i.y,0)/t.length};return t.map(r=>{let i=r.x-n.x,a=r.y-n.y,o=Math.hypot(i,a)||1;return{x:r.x+i/o*e,y:r.y+a/o*e}})}function Z(t){let e=[];for(let r of t)r.type==="row"?e.push(...z(r).map(i=>({x:i.x,y:i.y}))):r.type==="table"?e.push(...Q(r).map(i=>({x:i.x,y:i.y}))):r.type==="gaArea"?e.push(...r.points):r.type==="booth"&&e.push(r.center);if(e.length<3)return null;let n=Lo(Fo(e),22);return n.length>=3?n:null}function Oe(t,e){let n=C(t,e),r=G(t).find(i=>i.id===n.floorId);return{...t,objects:n.objects,floors:void 0,focalPoint:r.focalPoint,referenceImage:r.referenceImage,backgroundImage:r.backgroundImage}}var zt=24,Bt=80;function it(t,e){let n=t.normalize("NFKC").trim();if(n.length>zt)throw new u("invalid_operation",`${e} displayed type must be at most ${zt} characters`);return n}function Me(t,e){if(t.displayType===void 0)return!1;let n=it(t.displayType,e);return n?(t.displayType=n,!1):(delete t.displayType,!0)}function ae(t,e){if(t.displayLabel===void 0)return!1;let n=t.displayLabel.normalize("NFKC").trim();if(n.length>Bt)throw new u("invalid_operation",`${e} displayed label must be at most ${Bt} characters`);return n?(t.displayLabel=n,!1):(delete t.displayLabel,!0)}function L(t,e){let n=t.trim().toLowerCase();if(!/^#[0-9a-f]{6}$/.test(n))throw new u("invalid_operation",`${e} must use a six-digit hex color`);return n}function Ut(t,e){if(!Number.isFinite(t)||t<ot||t>rt)throw new u("invalid_operation",`${e} label size must be from ${ot} to ${rt}`)}function se(t,e){t.size!==void 0&&t.size!==null&&Ut(t.size,e),t.color!==void 0&&t.color!==null&&L(t.color,`${e} label color`)}function Ae(t,e){if(t?.positionPreset!==void 0&&!["start","end","both","none"].includes(t.positionPreset))throw new u("invalid_operation",`${e} label positionPreset must be one of start, end, both, none`);let n=t?.labelStyle;n&&(n.size!==void 0&&Ut(n.size,e),n.color!==void 0&&L(n.color,`${e} label color`))}function _e(t,e){let n=t?structuredClone(t):{},r=n.labelStyle?{...n.labelStyle}:{};return e.size===null?delete r.size:e.size!==void 0&&(r.size=e.size),e.color===null?delete r.color:e.color!==void 0&&(r.color=L(e.color,"Label color")),r.size===void 0&&r.color===void 0?delete n.labelStyle:n.labelStyle=r,e.visible!==void 0&&(n.visible=e.visible),Object.keys(n).length?n:void 0}function at(t,e,n){let r=e.normalize("NFKC").trim();if(!r||r.length>80)throw new u("invalid_operation","Zone labels must contain 1 to 80 characters");if((t.zones??[]).some(i=>i.id!==n&&i.label.normalize("NFKC").trim().toLocaleLowerCase("en")===r.toLocaleLowerCase("en")))throw new u("invalid_operation",`Zone label already exists: ${r}`);return r}function st(t,e){if(!Number.isFinite(t?.x)||!Number.isFinite(t?.y))throw new u("invalid_operation",`${e} must contain finite x and y values`);return{x:t.x,y:t.y}}function J(t,e,n){return(e.x-t.x)*(n.y-t.y)-(e.y-t.y)*(n.x-t.x)}var X=Math.PI/180,q=Math.PI/180;function W(t){return t.type==="row"||t.type==="table"?t.seatCount:t.type==="gaArea"?Math.max(0,Math.floor(t.capacity)):t.type==="booth"?1:0}function ge(t){if(t.floors?.length){let e=t.floors[0];t.objects=e.objects,t.focalPoint=e.focalPoint,t.referenceImage=e.referenceImage,t.backgroundImage=e.backgroundImage}return t}var To=0,je=120,ct=4;function Eo(t){if(!Number.isFinite(t)||t<To||t>je)throw new u("invalid_operation","Floor base height must be a number from 0 to 120 metres")}function No(t,e){let n=G(t);if(n.length>=5)throw new u("invalid_operation","A chart can contain at most five physical floors");let r=(e.name??String(n.length+1)).normalize("NFKC").trim();if(!r||r.length>80)throw new u("invalid_operation","Floor names must contain 1 to 80 characters");if(n.some(c=>c.name.toLocaleLowerCase("en")===r.toLocaleLowerCase("en")))throw new u("invalid_operation",`Floor name already exists: ${r}`);t.floors?.length||(t.floors=[{id:"floor-0",name:"1",objects:t.objects,baseHeightM:0,focalPoint:t.focalPoint,referenceImage:t.referenceImage,backgroundImage:t.backgroundImage}]);let a=t.floors[t.floors.length-1].baseHeightM??Math.min(je,(t.floors.length-1)*ct),o=Math.min(je,a+ct),s=_(t,"floor",e.idFactory,new Set);return t.floors.push({id:s,name:r,baseHeightM:o,objects:[],focalPoint:{...t.focalPoint}}),ge(t),{changed:!0,floorId:s,floorCount:t.floors.length,baseHeightM:o}}function Do(t,e){let n=G(t),r=n.find(o=>o.id===e.floorId);if(!r)throw new u("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});let i=e.name.normalize("NFKC").trim();if(!i||i.length>80)throw new u("invalid_operation","Floor names must contain 1 to 80 characters");if(n.some(o=>o.id!==r.id&&o.name.toLocaleLowerCase("en")===i.toLocaleLowerCase("en")))throw new u("invalid_operation",`Floor name already exists: ${i}`);let a=r.name!==i;return a&&(r.name=i),{changed:a,floorId:r.id,floorName:i}}function Go(t,e){if(!t.floors?.length)throw new u("invalid_operation","A single-floor chart has an implicit base height of 0 metres");let n=t.floors.find(i=>i.id===e.floorId);if(!n)throw new u("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});Eo(e.baseHeightM);let r=n.baseHeightM!==e.baseHeightM;return r&&(n.baseHeightM=e.baseHeightM,n.physical3dProvenance={...n.physical3dProvenance,baseHeightM:{status:"confirmed",source:"user-review",note:"Physical floor height reviewed through the shared Designer/Copilot operation."}}),{changed:r,floorId:n.id,baseHeightM:e.baseHeightM}}function Ko(t,e){if(!t.floors?.length)throw new u("invalid_operation","A single-floor chart cannot remove its only floor");let n=t.floors.findIndex(i=>i.id===e.floorId);if(n<0)throw new u("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});let[r]=t.floors.splice(n,1);if(t.floors.length===1){let[i]=t.floors;t.objects=i.objects,t.focalPoint=i.focalPoint,t.referenceImage=i.referenceImage,t.backgroundImage=i.backgroundImage,t.floors=void 0}else ge(t);return{changed:!0,floorId:r.id,removedObjects:r.objects.length,floorCount:G(t).length}}function $o(t,e){if((t.zones?.length??0)>=100)throw new u("invalid_operation","A chart supports at most 100 zones");let n={id:_(t,"zone",e.idFactory,new Set),label:at(t,e.label),color:L(e.color,"Zone color"),...e.focalPoint?{focalPoint:st(e.focalPoint,"Zone focal point")}:{}};return(t.zones??=[]).push(n),{changed:!0,zone:structuredClone(n)}}function zo(t,e){if(!e.updates.length)throw new u("invalid_operation","At least one zone update is required");let n=e.updates.map(c=>c.zoneId);if(new Set(n).size!==n.length)throw new u("invalid_operation","Zone ids must be unique");let r=new Map((t.zones??[]).map(c=>[c.id,c])),i=n.filter(c=>!r.has(c));if(i.length)throw new u("object_not_found",`Unknown zone id(s): ${i.join(", ")}. Call get_chart to list current zone ids.`,{zoneIds:i});let a=structuredClone(t),o=new Map((a.zones??[]).map(c=>[c.id,c]));for(let c of e.updates){if(!Object.keys(c.patch).length)throw new u("invalid_operation",`Zone ${c.zoneId} has no changes`);let d=o.get(c.zoneId);c.patch.label!==void 0&&(d.label=at(a,c.patch.label,d.id)),c.patch.color!==void 0&&(d.color=L(c.patch.color,"Zone color")),c.patch.focalPoint!==void 0&&(d.focalPoint=st(c.patch.focalPoint,"Zone focal point"))}let s=JSON.stringify(a.zones??[])!==JSON.stringify(t.zones??[]);return s&&(t.zones=a.zones),{changed:s,zoneIds:n,zones:n.map(c=>structuredClone(o.get(c)))}}function Bo(t,e){let n=(t.zones??[]).findIndex(a=>a.id===e.zoneId);if(n<0)throw new u("object_not_found",`Unknown chart zone: ${e.zoneId}`,{zoneId:e.zoneId});let r=G(t).flatMap(a=>a.objects).filter(a=>a.type==="section"&&a.zone===e.zoneId);if(r.length&&e.clearSectionAssignments!==!0)throw new u("invalid_operation",`Zone ${e.zoneId} is assigned to ${r.length} section(s)`,{zoneId:e.zoneId,sectionIds:r.map(a=>a.id),requiresClearSectionAssignments:!0});let i=r.map(a=>a.id);for(let a of r)delete a.zone;return t.zones.splice(n,1),t.zones.length||delete t.zones,ge(t),{changed:!0,zoneId:e.zoneId,clearedSectionIds:i,zoneCount:t.zones?.length??0}}var ke=[{key:"row-seats",label:"row seats",suffix:"rows",labelSuffix:"Rows",creationWord:"Seats",objectType:"row"},{key:"table-chairs",label:"table chairs",suffix:"tables",labelSuffix:"Tables",creationWord:"Tables",objectType:"table"},{key:"booth-units",label:"booth units",suffix:"booths",labelSuffix:"Booths",creationWord:"Booths",objectType:"booth"},{key:"ga-capacity",label:"GA capacity",suffix:"ga",labelSuffix:"GA",creationWord:"Standing",objectType:"gaArea"}];function Re(t){let e=new Map,n=Math.max(0,Math.floor(t.seatCount)),r=new Map((t.overrides??[]).filter(a=>Number.isInteger(a.index)&&a.index>=0&&a.index<t.seatCount).map(a=>[a.index,a])),i=(a,o=1)=>{a&&o>0&&e.set(a,(e.get(a)??0)+o)};i(t.categoryKey,n-r.size);for(let a of r.values())a.skip||i(a.categoryKey??t.categoryKey);return e}var Ht="__sl_ga__",ee=1e5,ce=1e5;function Uo(t,e){return`${Ht}${encodeURIComponent(t)}__${e+1}`}function lt(t){let e=t.inventorySegments;if(e===void 0)return!0;if(!Array.isArray(e)||e.length<1||e.length>256)return!1;let n=0,r=new Map;for(let i of e){if(!i||typeof i.sourceAreaId!="string"||!i.sourceAreaId.trim()||i.sourceAreaId.length>160||!Number.isInteger(i.startIndex)||i.startIndex<0||!Number.isInteger(i.count)||i.count<1||i.startIndex+i.count>ee||(n+=i.count,n>ee))return!1;let a=r.get(i.sourceAreaId)??[],o=i.startIndex+i.count;if(a.some(s=>i.startIndex<s.end&&o>s.start))return!1;a.push({start:i.startIndex,end:o}),r.set(i.sourceAreaId,a)}return n===t.capacity}function Fe(t){let e=Math.min(ee,Math.max(0,Math.floor(t.capacity)));return t.inventorySegments===void 0?e?[{sourceAreaId:t.id,startIndex:0,count:e}]:[]:lt(t)?t.inventorySegments.map(n=>({...n})):[]}function te(t){return Fe(t).flatMap(e=>Array.from({length:e.count},(n,r)=>Uo(e.sourceAreaId,e.startIndex+r)))}function dt(t,e){if(t.inventorySegments===void 0||e===t.capacity)return t.inventorySegments;if(e<t.capacity)return;let n=Fe(t);if(!n.length)return;let r=e-t.capacity;if(!r)return n;let a=n.filter(s=>s.sourceAreaId===t.id).reduce((s,c)=>Math.max(s,c.startIndex+c.count),0),o=n[n.length-1];if(o?.sourceAreaId===t.id&&o.startIndex+o.count===a)o.count+=r;else{if(n.length>=256)return;n.push({sourceAreaId:t.id,startIndex:a,count:r})}return n}function Vt(t){return t.startsWith(Ht)}var Ho="__ungrouped__";function Vo(t){return t.type==="row"?z(t).map(e=>e.label):t.type==="table"?Q(t).map(e=>e.label):t.type==="booth"?Gt(t).map(e=>e.label):t.type==="gaArea"?te(t):[]}function Jo(t){return t.type==="row"||t.type==="table"||t.type==="booth"||t.type==="gaArea"}function he(t){let e=H(t),n=e.filter(o=>o.type==="section"),r=new Map;for(let o of n){let s=o.logicalSectionId??o.id;r.get(s)||r.set(s,{id:s,label:o.displayLabel||o.label||"Section",zone:o.zone,seatCount:0,objectIds:[],seatLabels:[]})}let i={id:Ho,label:"Other seats",seatCount:0,objectIds:[],seatLabels:[]},a=new Map;for(let o of e){if(!Jo(o))continue;let s=Vo(o);if(s.length===0)continue;let c=Kt(e,o),l=c?r.get(c.logicalSectionId??c.id):i;l.seatCount+=s.length,l.objectIds.push(o.id),l.seatLabels.push(...s),a.set(o.id,l.id)}return{sections:[...r.values()],ungrouped:i.objectIds.length?i:null,objectToSection:a}}var ne={vip:{key:"vip",label:"VIP",color:"#e5484d",price:120},premium:{key:"premium",label:"Premium",color:"#a86b00",price:80},standard:{key:"standard",label:"Standard",color:"#6e7bff",price:45},balcony:{key:"balcony",label:"Balcony",color:"#22a06b",price:30}};function be(t,e,n,r,i,a,o=0){return{type:"row",id:t,label:e,origin:{x:-(r-1)*i/2,y:n},rotation:0,curve:o,seatCount:r,seatSpacing:i,categoryKey:a}}function qo(t,e,n,r,i,a){return{type:"table",id:t,label:e,center:n,shape:"round",seatCount:r,rotation:0,radius:i,categoryKey:a}}function Jt(t,e,n,r,i,a){let o=n/2,s=r/2;return{type:"gaArea",id:t,label:e,points:[{x:-o,y:-s},{x:o,y:-s},{x:o,y:s},{x:-o,y:s}],capacity:i,categoryKey:a}}function Xo(t,e,n,r,i){let a=n*2,o=[];for(let s=0;s<a;s++){let c=s%2===0,l=c?["wheelchair"]:["companion"];o.push(c?{index:s,accessibility:l,wheelchairSpaceType:"no-seat"}:{index:s,accessibility:l})}return{type:"row",id:t,label:e,origin:{x:-(a-1)*r/2,y:0},rotation:0,curve:0,seatCount:a,seatSpacing:r,categoryKey:i,overrides:o}}var qt=[{key:"balcony",label:"Balcony",icon:"\u2312",blurb:"Insert four curved rows inside a section.",categories:[ne.balcony],sectionLabel:"Balcony",build:()=>[be("blk-b0","A",-45,18,24,"balcony",18),be("blk-b1","B",-15,20,24,"balcony",18),be("blk-b2","C",15,22,24,"balcony",18),be("blk-b3","D",45,24,24,"balcony",18)]},{key:"rows",label:"Row block",icon:"\u2261",blurb:"Insert six straight rows inside a section.",categories:[ne.standard],sectionLabel:"Section",build:()=>Array.from({length:6},(t,e)=>be(`blk-r${e}`,"ABCDEF"[e],-80+e*32,12,26,"standard"))},{key:"ga-pen",label:"GA pen",icon:"\u25A8",blurb:"Insert a standing area for 250 people.",categories:[ne.standard],build:()=>[Jt("blk-ga","Standing",320,180,250,"standard")]},{key:"tables",label:"Tables",icon:"\u283F",blurb:"Insert six round tables with eight bookable seats each.",categories:[ne.premium],build:()=>Array.from({length:6},(t,e)=>qo(`blk-t${e}`,`T${e+1}`,{x:-150+e%3*150,y:e<3?-70:70},8,34,"premium"))},{key:"boxes",label:"Boxes",icon:"\u25A3",blurb:"Insert two private boxes with four bookable seats each.",categories:[ne.vip],build:()=>[{type:"table",id:"blk-x0",label:"Box 1",center:{x:-70,y:0},shape:"rect",seatCount:4,rotation:0,width:110,height:56,categoryKey:"vip"},{type:"table",id:"blk-x1",label:"Box 2",center:{x:70,y:0},shape:"rect",seatCount:4,rotation:0,width:110,height:56,categoryKey:"vip"}]},{key:"terrace",label:"Terrace",icon:"\u2263",blurb:"Insert a standing terrace for 500 people.",categories:[ne.standard],build:()=>[Jt("blk-terrace","Terrace",520,200,500,"standard")]},{key:"wheelchair-platform",label:"Wheelchair platform",icon:"\u267F",blurb:"Insert four wheelchair spaces, each with its companion seat.",categories:[ne.standard],build:()=>[Xo("blk-wc","A",4,40,"standard")]}];function B(t){let e="",n=t;do e=String.fromCharCode(65+n%26)+e,n=Math.floor(n/26)-1;while(n>=0);return e}function Xt(t){if(!/^[A-Z]+$/.test(t))return null;let e=0;for(let n of t)e=e*26+(n.charCodeAt(0)-64);return e-1}var Yt="M13 4.6a1.6 1.6 0 1 0-3.2 0 1.6 1.6 0 0 0 3.2 0 M11 6.5V13h5l2.4 6 M15 16.4A5 5 0 1 1 9 11.3",Qt=[{key:"restroom-men",label:"Men's restroom",group:"facilities",path:"M16 7a4 4 0 1 0-8 0 4 4 0 0 0 8 0 M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"},{key:"restroom-women",label:"Women's restroom",group:"facilities",path:"M15 5a3 3 0 1 0-6 0 3 3 0 0 0 6 0 M12 8l-4 10h8l-4-10 M10 18v4 M14 18v4"},{key:"restroom-accessible",label:"Accessible restroom",group:"facilities",path:Yt},{key:"first-aid",label:"First aid",group:"facilities",path:"M5 4h14a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1Z M12 8v8 M8 12h8"},{key:"coat-check",label:"Coat check",group:"facilities",path:"M12 6a2 2 0 0 1 0-4 2 2 0 0 1 1.6 3.2L21 13H3l8.4-7.8 M3 13h18"},{key:"atm",label:"ATM / cash",group:"facilities",path:"M2 6h20v12H2V6Z M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0 M6 9h.01 M18 15h.01"},{key:"info",label:"Info point",group:"facilities",path:"M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18 M12 11v5 M12 8h.01"},{key:"lost-found",label:"Lost & found",group:"facilities",path:"M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14 M16 16l5 5 M9 8.5a2 2 0 1 1 3 1.7c-.8.5-1 .8-1 1.8 M11 15h.01"},{key:"restrooms",label:"Restrooms",group:"facilities",path:"M6 3h12a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z M12 8a2 2 0 1 0 0 4 2 2 0 0 0 0-4 M9 18v-3.5a3 3 0 0 1 6 0V18"},{key:"charging",label:"Charging point",group:"facilities",path:"M3 8h13v8H3V8Z M16 10h3v4h-3 M9.6 9l-2 3.5h2.5l-1.5 3"},{key:"smoking",label:"Smoking area",group:"facilities",path:"M2 15h13v3H2v-3Z M18 16h2 M19 8c0 1 1 1.5 1 2.5S19 12 19 13"},{key:"no-smoking",label:"No smoking",group:"facilities",path:"M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18 M5.6 5.6l12.8 12.8 M7 13h6v2H7v-2Z"},{key:"food",label:"Food",group:"food-drink",path:"M7 3v6a2 2 0 0 0 4 0V3 M9 11v10 M17 3c-1.6 1-2.2 3-2.2 6 0 2 .9 3.2 2.2 3.6V21"},{key:"bar",label:"Bar",group:"food-drink",path:"M4 5h16l-8 8-8-8Z M12 13v6 M8 20h8"},{key:"coffee",label:"Caf\xE9 / coffee",group:"food-drink",path:"M4 8h13v4a5 5 0 0 1-5 5H9a5 5 0 0 1-5-5V8Z M17 9h2a2 2 0 0 1 0 4h-2 M8 2v2 M11 2v2 M4 21h14"},{key:"water",label:"Water / drinks",group:"food-drink",path:"M12 22a7 7 0 0 1-7-7c0-5 7-12 7-12s7 7 7 12a7 7 0 0 1-7 7Z"},{key:"merch",label:"Merch / shop",group:"food-drink",path:"M6 8h12l-1 12H7L6 8Z M9 8V6a3 3 0 0 1 6 0v2"},{key:"screen",label:"Screen",group:"facilities",path:"M3 4h18v12H3V4Z M9 20h6 M12 16v4 M10 8l4 2-4 2V8Z"},{key:"sound-booth",label:"Sound booth",group:"facilities",path:"M6 4v16 M6 14a2 2 0 1 0 0-4 2 2 0 0 0 0 4 M12 4v16 M12 8a2 2 0 1 0 0 4 2 2 0 0 0 0-4 M18 4v16 M18 12a2 2 0 1 0 0 4 2 2 0 0 0 0-4"},{key:"entrance",label:"Entrance",group:"navigation",path:"M14 3h5a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1h-5 M3 12h11 M10 8l4 4-4 4"},{key:"exit",label:"Exit",group:"navigation",path:"M10 3H5a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h5 M14 12h7 M17 8l4 4-4 4"},{key:"emergency-exit",label:"Emergency exit",group:"navigation",path:"M14 4.6a1.5 1.5 0 1 0-3 0 1.5 1.5 0 0 0 3 0 M12.5 8l-3.5 2 1.6 3.6-2 4.4 M12.5 10l3.5 1.5 M9 10.5l-3.5 1 M15 12h6 M18 9l3 3-3 3"},{key:"stairs",label:"Stairs",group:"navigation",path:"M3 20v-4h4v-4h4v-4h4V4h5"},{key:"elevator",label:"Elevator",group:"navigation",path:"M5 3h14a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z M8 11l1.5-2 1.5 2 M8 14l1.5 2 1.5-2 M15 8v8"},{key:"parking",label:"Parking",group:"navigation",path:"M5 3h14a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z M9 17V7h4a3 3 0 0 1 0 6H9"},{key:"wheelchair",label:"Wheelchair access",group:"accessibility",path:Yt},{key:"hearing",label:"Hearing assistance",group:"accessibility",path:"M8 20a4 4 0 0 1-2-3c0-1 .5-2 .5-3a4.5 4.5 0 1 1 9 0c0 1.4-1 2-2 2.4-1.2.5-1.5 1-1.5 2.2 M17 6a5 5 0 0 1 1 6 M19.5 4a8 8 0 0 1 1.2 9"}];var Yo=new Map(Qt.map(t=>[t.key,t]));function Zt(t){return typeof t=="string"&&Yo.has(t)}var Ha=Qt.map(t=>t.key);function ut(t){let e=(t%360+360)%360,n=e>=180?e-360:e;return Object.is(n,-0)||Math.abs(n)<1e-9?0:n}function Wt(t,e,n){let r=i=>({x:i.x+e,y:i.y+n});switch(t.type){case"row":t.origin=r(t.origin),t.path&&(t.path={start:r(t.path.start),control1:r(t.path.control1),control2:r(t.path.control2),end:r(t.path.end)});break;case"table":case"booth":t.center=r(t.center);break;case"text":t.position=r(t.position);break;case"gaArea":t.points=t.points.map(r),t.holes&&(t.holes=t.holes.map(i=>i.map(r)));break;case"section":t.outline=t.outline.map(r),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(r)),t.outlinePath&&(t.outlinePath=At(t.outlinePath,e,n)),t.holes&&(t.holes=t.holes.map(i=>i.map(r)));break;case"shape":t.points&&(t.points=t.points.map(r)),t.x!=null&&(t.x+=e),t.y!=null&&(t.y+=n);break;case"decorImage":t.x+=e,t.y+=n;break}}function Qo(t,e){return Math.abs(t.x-e.x)<=1e-7&&Math.abs(t.y-e.y)<=1e-7}function pe(t,e,n){return(e.x-t.x)*(n.y-t.y)-(e.y-t.y)*(n.x-t.x)}function Le(t,e,n){let r=pe(e,n,t);return Math.abs(r)>1e-7?!1:t.x>=Math.min(e.x,n.x)-1e-7&&t.x<=Math.max(e.x,n.x)+1e-7&&t.y>=Math.min(e.y,n.y)-1e-7&&t.y<=Math.max(e.y,n.y)+1e-7}function Zo(t,e,n,r){let i=pe(t,e,n),a=pe(t,e,r),o=pe(n,r,t),s=pe(n,r,e);return(i>1e-7&&a<-1e-7||i<-1e-7&&a>1e-7)&&(o>1e-7&&s<-1e-7||o<-1e-7&&s>1e-7)?!0:Math.abs(i)<=1e-7&&Le(n,t,e)||Math.abs(a)<=1e-7&&Le(r,t,e)||Math.abs(o)<=1e-7&&Le(t,n,r)||Math.abs(s)<=1e-7&&Le(e,n,r)}function Wo(t){return t.reduce((e,n,r)=>{let i=t[(r+1)%t.length];return e+n.x*i.y-i.x*n.y},0)}function er(t){for(let e=0;e<t.length;e+=1){let n=(e+1)%t.length;for(let r=e+1;r<t.length;r+=1){let i=(r+1)%t.length;if(!(e===r||n===r||i===e)&&Zo(t[e],t[n],t[r],t[i]))return!0}}return!1}function en(t){return t.length<3?{ok:!1,code:"too_few_vertices",message:"Add at least three vertices to create a polygon."}:t.length>256?{ok:!1,code:"too_many_vertices",message:"A polygon can contain at most 256 vertices."}:t.some(e=>!Number.isFinite(e.x)||!Number.isFinite(e.y)||Math.abs(e.x)>1e7||Math.abs(e.y)>1e7)?{ok:!1,code:"invalid_coordinate",message:"Every polygon vertex must use a finite coordinate inside the safe chart range."}:t.some((e,n)=>Qo(e,t[(n+1)%t.length]))?{ok:!1,code:"duplicate_vertex",message:"Move or remove duplicate neighbouring vertices."}:Math.abs(Wo(t))<2?{ok:!1,code:"degenerate_polygon",message:"The polygon needs a visible enclosed area."}:er(t)?{ok:!1,code:"self_intersection",message:"Polygon edges cannot cross or touch each other."}:{ok:!0}}function lr(t,e){let n=C(t,e.floorId),r=[...new Set(e.tableIds)];if(!r.length)throw new u("invalid_operation","At least one table id is required");let i=r.map(p=>n.objects.find(m=>m.type==="table"&&m.id===p)),a=r.filter((p,m)=>!i[m]);if(a.length)throw new u("object_not_found",`Unknown table id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current table ids.`,{tableIds:a});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new u("invalid_operation","At least one table change is required");if(o.label!==void 0){if(o.label=o.label.normalize("NFKC").trim(),r.length!==1)throw new u("invalid_operation","label can be changed only for one table at a time");if(!o.label||o.label.length>80)throw new u("invalid_operation","Table labels must contain 1 to 80 characters")}o.categoryKey!==void 0&&k(t,o.categoryKey);let s=o.seatCount!==void 0,c=o.seatCountsBySide!==void 0;if(c){if(o.sides!==void 0)throw new u("invalid_operation","Use seatCountsBySide for exact rectangular counts; do not also supply legacy sides");if(o.shape==="round")throw new u("invalid_operation","seatCountsBySide can be used only with rectangular tables");let p=["top","bottom","left","right"],m=Object.keys(o.seatCountsBySide);if(m.length!==p.length||m.some(S=>!p.includes(S)))throw new u("invalid_operation","seatCountsBySide must contain exactly top, bottom, left, and right");for(let S of p){let I=o.seatCountsBySide[S];if(!Number.isInteger(I)||I<0||I>40)throw new u("invalid_operation",`seatCountsBySide.${S} must be a whole number from 0 to 40`)}let w=p.reduce((S,I)=>S+o.seatCountsBySide[I],0);if(w<1||w>40)throw new u("invalid_operation","Rectangular table side counts must total from 1 to 40 chairs");if(s&&o.seatCount!==w)throw new u("invalid_operation",`seatCount must equal the ${w}-chair seatCountsBySide total`);o.seatCount=w,o.sides=p.filter(S=>o.seatCountsBySide[S]>0)}if(o.seatCount!==void 0&&(!Number.isInteger(o.seatCount)||o.seatCount<1||o.seatCount>40))throw new u("invalid_operation","seatCount must be an integer from 1 to 40");if(o.shape!==void 0&&o.shape!=="round"&&o.shape!=="rect")throw new u("invalid_operation","Table shape must be round or rect");if(o.bookAsWhole===!0&&o.variableOccupancy===!0)throw new u("invalid_operation","A table cannot use whole-table and variable-occupancy selling at the same time");if(o.variableOccupancy===!1&&(o.minOccupancy!==void 0||o.maxOccupancy!==void 0))throw new u("invalid_operation","Guest bounds can be supplied only with variable-occupancy selling");let l=(p,m,w,S)=>{if(m!==void 0&&(!Number.isFinite(m)||m<w||m>S))throw new u("invalid_operation",`${String(p)} must be from ${w} to ${S}`)};if(l("rotation",o.rotation,0,360),l("radius",o.radius,24,160),l("seatArc",o.seatArc,120,360),l("width",o.width,40,320),l("height",o.height,30,240),o.minOccupancy!==void 0&&(!Number.isInteger(o.minOccupancy)||o.minOccupancy<1||o.minOccupancy>40))throw new u("invalid_operation","minOccupancy must be a whole number from 1 to 40");if(o.maxOccupancy!==void 0&&(!Number.isInteger(o.maxOccupancy)||o.maxOccupancy<1||o.maxOccupancy>40))throw new u("invalid_operation","maxOccupancy must be a whole number from 1 to 40");if(o.sides!==void 0){let p=new Set(["top","bottom","left","right"]);if(!o.sides.length||o.sides.length>4||new Set(o.sides).size!==o.sides.length||o.sides.some(m=>!p.has(m)))throw new u("invalid_operation","Table sides must contain one to four unique perimeter sides")}let d=ae(o,"Table"),g=Me(o,"Table"),h=i.map(p=>{if(p.seatCountsBySide&&!c&&(s||e.patch.sides!==void 0))throw new u("invalid_operation",`Table "${p.label}" has exact per-side counts; update seatCountsBySide instead of aggregate seatCount or legacy sides`,{tableId:p.id});let m=structuredClone(p);if(Object.assign(m,o),m.shape==="round"&&delete m.seatCountsBySide,m.overrides&&o.seatCount!==void 0&&(m.overrides=m.overrides.filter(w=>w.index<m.seatCount),m.overrides.length||delete m.overrides),o.bookAsWhole===!1&&delete m.bookAsWhole,o.variableOccupancy===!1&&(delete m.variableOccupancy,delete m.minOccupancy,delete m.maxOccupancy),m.bookAsWhole||delete m.bookAsWhole,m.variableOccupancy||delete m.variableOccupancy,m.bookAsWhole&&m.variableOccupancy)throw new u("invalid_operation",`Table "${m.label}" cannot use whole-table and variable-occupancy selling at the same time`,{tableId:m.id});if((m.bookAsWhole||m.variableOccupancy)&&m.overrides?.length)throw new u("invalid_operation",`Table "${m.label}" has individual-chair overrides; reset them before choosing grouped table selling`,{tableId:m.id,overriddenChairIndices:m.overrides.map(w=>w.index)});if(m.bookAsWhole)delete m.minOccupancy,delete m.maxOccupancy;else if(m.variableOccupancy){if(!Number.isInteger(m.minOccupancy)||!Number.isInteger(m.maxOccupancy)||m.minOccupancy<1||m.maxOccupancy<m.minOccupancy||m.maxOccupancy>m.seatCount)throw new u("invalid_operation",`Table "${m.label}" needs whole-number minimum and maximum guests from 1 to its ${m.seatCount}-chair capacity`,{tableId:m.id,seatCount:m.seatCount})}else{if(o.minOccupancy!==void 0||o.maxOccupancy!==void 0)throw new u("invalid_operation","Guest bounds can be changed only on a variable-occupancy table",{tableId:m.id});delete m.minOccupancy,delete m.maxOccupancy}if(g&&delete m.displayType,d&&delete m.displayLabel,m.shape==="rect"){if(m.width??=80,m.height??=50,m.seatCountsBySide){let w=["top","bottom","left","right"],S=w.reduce((I,M)=>I+m.seatCountsBySide[M],0);if(S!==m.seatCount)throw new u("invalid_operation",`Table "${m.label}" side counts total ${S}, but seatCount is ${m.seatCount}`,{tableId:m.id,seatCount:m.seatCount,seatCountsBySide:m.seatCountsBySide});m.sides=w.filter(I=>m.seatCountsBySide[I]>0)}}else m.radius??=40;if((m.bookAsWhole||m.variableOccupancy)&&Vt(m.label))throw new u("invalid_operation",`Grouped table label "${m.label}" uses SeatLayer's reserved GA namespace`,{tableId:m.id});return m}),f=new Map(h.map(p=>[p.id,p])),b=new Set(r),y=new Map;for(let p of G(t))for(let m of p.objects){let w=m.type==="table"?f.get(m.id)??m:m,S=[];w.type==="row"?S=z(w).map(I=>I.label):w.type==="table"?S=w.bookAsWhole||w.variableOccupancy?[w.label]:Q(w).map(I=>I.label):w.type==="booth"?S=[w.label]:w.type==="gaArea"&&(S=te(w));for(let I of S){let M=y.get(I);if(M&&(b.has(M)||b.has(w.id)))throw new u("invalid_operation",`Inventory label "${I}" is already in use; grouped table labels must be unique`,{tableIds:r,inventoryLabel:I,conflictingObjectIds:[M,w.id]});y.set(I,M??w.id)}}let x=!1,v=["bookAsWhole","variableOccupancy","minOccupancy","maxOccupancy","displayLabel","displayType","seatCountsBySide","overrides"];for(let[p,m]of i.entries()){let w=h[p],S=JSON.stringify(m);for(let I of v)I in w||delete m[I];Object.assign(m,w),JSON.stringify(m)!==S&&(x=!0)}return{floorId:n.floorId,changed:x,tableIds:r}}function dr(t,e){let n=C(t,e.floorId),r=[...new Set(e.boothIds)];if(!r.length)throw new u("invalid_operation","At least one booth id is required");let i=r.map(f=>n.objects.find(b=>b.type==="booth"&&b.id===f)),a=r.filter((f,b)=>!i[b]);if(a.length)throw new u("object_not_found",`Unknown booth id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current booth ids.`,{boothIds:a});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new u("invalid_operation","At least one booth change is required");if(o.label!==void 0){if(o.label=o.label.normalize("NFKC").trim(),r.length!==1)throw new u("invalid_operation","label can be changed only for one booth at a time");if(!o.label||o.label.length>80)throw new u("invalid_operation","Booth labels must contain 1 to 80 characters")}o.categoryKey!==void 0&&k(t,o.categoryKey);let s=(f,b,y,x)=>{if(b!==void 0&&(!Number.isFinite(b)||b<y||b>x))throw new u("invalid_operation",`${f} must be from ${y} to ${x}`)};s("width",o.width,30,400),s("height",o.height,30,400),s("rotation",o.rotation,0,360);let c=o.points===null;if(o.points!=null){if(r.length!==1)throw new u("invalid_operation","points can be changed only for one booth at a time");let f=en(o.points);if(!f.ok)throw new u("invalid_operation",f.message??"The booth outline is not a valid simple polygon")}let l=o.points!=null?o.points.map(f=>({x:f.x,y:f.y})):void 0;delete o.points;let d=ae(o,"Booth"),g=Me(o,"Booth"),h=!1;for(let f of i){let b=JSON.stringify(f);Object.assign(f,o),d&&delete f.displayLabel,g&&delete f.displayType,c?delete f.points:l&&(f.points=l),JSON.stringify(f)!==b&&(h=!0)}return{floorId:n.floorId,changed:h,boothIds:r}}function ur(t,e){let n=C(t,e.floorId),r=[...new Set(e.gaAreaIds)];if(!r.length)throw new u("invalid_operation","At least one GA area id is required");let i=r.map(d=>n.objects.find(g=>g.type==="gaArea"&&g.id===d)),a=r.filter((d,g)=>!i[g]);if(a.length)throw new u("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:a});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new u("invalid_operation","At least one GA area change is required");if(o.label!==void 0){if(o.label=o.label.normalize("NFKC").trim(),r.length!==1)throw new u("invalid_operation","label can be changed only for one GA area at a time");if(!o.label||o.label.length>80)throw new u("invalid_operation","GA area labels must contain 1 to 80 characters")}if(o.categoryKey!==void 0&&k(t,o.categoryKey),o.capacity!==void 0&&(!Number.isInteger(o.capacity)||o.capacity<1||o.capacity>1e5))throw new u("invalid_operation","capacity must be an integer from 1 to 100000");if(o.cornerRadius!==void 0&&(!Number.isFinite(o.cornerRadius)||o.cornerRadius<0||o.cornerRadius>2e3))throw new u("invalid_operation","cornerRadius must be from 0 to 2000");let s=ae(o,"GA area"),c=Me(o,"GA area");if(o.capacity!==void 0)for(let d of i){if(d.inventorySegments!==void 0&&o.capacity<d.capacity)throw new u("invalid_operation",`Joined GA area "${d.label}" cannot be reduced below ${d.capacity}; shrinking would delete stable inventory identities. Create or split a new surface instead.`,{gaAreaId:d.id,currentCapacity:d.capacity,requestedCapacity:o.capacity});if(d.inventorySegments!==void 0&&o.capacity>d.capacity&&dt(d,o.capacity)===void 0)throw new u("invalid_operation",`Joined GA area "${d.label}" cannot append that capacity safely`,{gaAreaId:d.id})}let l=!1;for(let d of i){let g=JSON.stringify(d),h=o.capacity===void 0?d.inventorySegments:dt(d,o.capacity);Object.assign(d,o),h!==void 0&&(d.inventorySegments=h),s&&delete d.displayLabel,c&&delete d.displayType,JSON.stringify(d)!==g&&(l=!0)}return{floorId:n.floorId,changed:l,gaAreaIds:r}}function Te(t,e){if(e.length<3)return 0;let n=i=>N(i,e,void 0),r=0;for(let i of t)n(F(i))&&(i.type==="row"?r+=z(i).length:i.type==="table"?r+=Q(i).length:(i.type==="gaArea"||i.type==="booth")&&(r+=W(i)));return r}function fr(t,e){let n=C(t,e.floorId);if(!e.objectIds.length)throw new u("invalid_operation","At least one chart object id is required");if(new Set(e.objectIds).size!==e.objectIds.length)throw new u("invalid_operation","Chart object ids must be unique");let r=e.objectIds.map(s=>n.objects.find(c=>c.id===s)),i=e.objectIds.filter((s,c)=>!r[c]);if(i.length)throw new u("object_not_found","One or more chart object ids do not exist on the selected floor",{objectIds:i});let a=r,o=new Set(e.objectIds);for(let s=n.objects.length-1;s>=0;s--)o.has(n.objects[s].id)&&n.objects.splice(s,1);return{floorId:n.floorId,changed:!0,removedObjects:a.map(s=>({id:s.id,type:s.type})),removedInventory:a.reduce((s,c)=>s+W(c),0),remainingObjectCount:n.objects.length}}function gr(t,e){let n=C(t,e.floorId),r=[...new Set(e.textIds)];if(!r.length)throw new u("invalid_operation","At least one text id is required");let i=r.map(l=>n.objects.find(d=>d.type==="text"&&d.id===l)),a=r.filter((l,d)=>!i[d]);if(a.length)throw new u("object_not_found",`Unknown text id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current text ids.`,{textIds:a});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new u("invalid_operation","At least one text change is required");if(o.text!==void 0){if(o.text=o.text.normalize("NFKC").trim(),r.length!==1)throw new u("invalid_operation","content can be changed only for one text object at a time");if(!o.text||o.text.length>240)throw new u("invalid_operation","Text content must contain 1 to 240 characters")}if(o.fontSize!==void 0&&(!Number.isFinite(o.fontSize)||o.fontSize<8||o.fontSize>72))throw new u("invalid_operation","Text fontSize must be from 8 to 72");if(o.fontFamily!==void 0&&o.fontFamily!==null&&(o.fontFamily=o.fontFamily.normalize("NFKC").trim(),!o.fontFamily||o.fontFamily.length>120))throw new u("invalid_operation","Text fontFamily must contain 1 to 120 characters");if(o.rotation!==void 0&&(!Number.isFinite(o.rotation)||o.rotation<0||o.rotation>360))throw new u("invalid_operation","Text rotation must be from 0 to 360");if(o.color!==void 0&&o.color!==null&&(o.color=L(o.color,"Text color")),o.bold!==void 0&&typeof o.bold!="boolean")throw new u("invalid_operation","Text bold must be a boolean");if(o.italic!==void 0&&typeof o.italic!="boolean")throw new u("invalid_operation","Text italic must be a boolean");if(o.width!==void 0&&o.width!==null&&(!Number.isFinite(o.width)||o.width<40||o.width>1200))throw new u("invalid_operation",`Text width must be from ${40} to ${1200}`);if(o.align!==void 0&&!["left","center","right"].includes(o.align))throw new u("invalid_operation","Text align must be left, center, or right");if(o.lineHeight!==void 0&&(!Number.isFinite(o.lineHeight)||o.lineHeight<.8||o.lineHeight>3))throw new u("invalid_operation",`Text lineHeight must be from ${.8} to ${3}`);if(o.letterSpacing!==void 0&&(!Number.isFinite(o.letterSpacing)||o.letterSpacing<-2||o.letterSpacing>20))throw new u("invalid_operation",`Text letterSpacing must be from ${-2} to ${20}`);if(o.underline!==void 0&&typeof o.underline!="boolean")throw new u("invalid_operation","Text underline must be a boolean");if(o.opacity!==void 0&&(!Number.isFinite(o.opacity)||o.opacity<.1||o.opacity>1))throw new u("invalid_operation",`Text opacity must be from ${.1} to 1`);if(o.background!==void 0&&o.background!==null){o.background.color=L(o.background.color,"Text background color");let{padding:l=6,cornerRadius:d=4,opacity:g=.9}=o.background;if(!Number.isFinite(l)||l<0||l>40)throw new u("invalid_operation",`Text background padding must be from 0 to ${40}`);if(!Number.isFinite(d)||d<0||d>40)throw new u("invalid_operation",`Text background cornerRadius must be from 0 to ${40}`);if(!Number.isFinite(g)||g<.1||g>1)throw new u("invalid_operation",`Text background opacity must be from ${.1} to 1`)}if(["width","align","lineHeight","letterSpacing","underline","opacity","background"].some(l=>Object.prototype.hasOwnProperty.call(o,l))&&i.some(l=>l.semanticKind==="icon"))throw new u("invalid_operation","Text layout fields cannot be applied to venue icons");if(o.iconKey!==void 0){if(!Zt(o.iconKey))throw new u("invalid_operation","iconKey must be a known venue-icon registry key");if(i.some(l=>l.semanticKind!=="icon"))throw new u("invalid_operation",'iconKey can be set only on venue-icon objects (semanticKind "icon")')}let c=!1;for(let l of i){let d=JSON.stringify(l);o.iconKey!==void 0&&(l.iconKey=o.iconKey),o.text!==void 0&&(l.text=o.text),o.fontSize!==void 0&&(l.fontSize=o.fontSize),o.fontFamily===null?delete l.fontFamily:o.fontFamily!==void 0&&(l.fontFamily=o.fontFamily),o.rotation!==void 0&&(l.rotation=o.rotation),o.color===null?delete l.color:o.color!==void 0&&(l.color=o.color),o.bold!==void 0&&(o.bold?l.bold=!0:delete l.bold),o.italic!==void 0&&(o.italic?l.italic=!0:delete l.italic),o.width===null?delete l.width:o.width!==void 0&&(l.width=o.width),o.align!==void 0&&(o.align==="left"?delete l.align:l.align=o.align),o.lineHeight!==void 0&&(o.lineHeight===1.2?delete l.lineHeight:l.lineHeight=o.lineHeight),o.letterSpacing!==void 0&&(o.letterSpacing===0?delete l.letterSpacing:l.letterSpacing=o.letterSpacing),o.underline!==void 0&&(o.underline?l.underline=!0:delete l.underline),o.opacity!==void 0&&(o.opacity===1?delete l.opacity:l.opacity=o.opacity),o.background===null?delete l.background:o.background!==void 0&&(l.background=o.background),JSON.stringify(l)!==d&&(c=!0)}return{floorId:n.floorId,changed:c,textIds:r}}function hr(t,e){let n=C(t,e.floorId),r=[...new Set(e.rowIds)],i=r.map(l=>n.objects.find(d=>d.type==="row"&&d.id===l)),a=r.filter((l,d)=>!i[d]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let o=i.slice().sort((l,d)=>l.origin.y-d.origin.y||l.origin.x-d.origin.x),s=Ft(o.map(l=>({label:l.label})),e.options),c=!1;return o.forEach((l,d)=>{l.label!==s[d].label&&(c=!0),l.label=s[d].label}),{floorId:n.floorId,changed:c,rows:o.map(l=>({id:l.id,label:l.label}))}}function br(t,e){let n=qt.find(l=>l.key===e.blockKey);if(!n)throw new u("invalid_operation",`Unknown seating block: ${e.blockKey}`,{blockKey:e.blockKey});let r=C(t,e.floorId),i=new Set,a=n.build().map(l=>structuredClone(l));for(let l of a)l.id=_(t,l.type,e.idFactory,i),Wt(l,e.center.x,e.center.y);for(let l of n.categories)t.categories.some(d=>d.key===l.key)||t.categories.push({...l});let o=a.filter(l=>l.type==="row");if(o.length){let l=0;for(let d of r.objects){if(d.type!=="row")continue;let g=Xt(d.label);g!=null&&(l=Math.max(l,g+1))}for(let d of o)d.label=B(l++)}let s=new Set(r.objects.flatMap(l=>"label"in l&&l.label?[l.label]:[]));for(let l of a){if((l.type==="table"||l.type==="booth")&&s.has(l.label)){let d=/^(.*?)(\d+)$/.exec(l.label),g=d?d[1]:`${l.label} `,h=d?Number.parseInt(d[2],10):1;do h++;while(s.has(`${g}${h}`));l.label=`${g}${h}`}"label"in l&&l.label&&s.add(l.label)}r.objects.push(...a);let c=null;if(n.sectionLabel){let l=Z(a);if(l){let d={type:"section",id:_(t,"sec",e.idFactory,i),label:n.sectionLabel,outline:l};r.objects.push(d),c=d.id}}return{floorId:r.floorId,blockKey:n.key,createdIds:[...a.map(l=>l.id),...c?[c]:[]],sectionId:c}}function pr(t){let e=structuredClone(t);if([e.start,e.control1,e.control2,e.end].some(a=>!Number.isFinite(a.x)||!Number.isFinite(a.y)))throw new u("invalid_operation","Exact row path points must be finite");let r=Ie(e,97),i=r.slice(1).reduce((a,o,s)=>a+Math.hypot(o.x-r[s].x,o.y-r[s].y),0);if(!Number.isFinite(i)||i<1)throw new u("invalid_operation","Exact row path must have at least one chart unit of usable length");return{path:e,length:i}}function on(t,e){let n=C(t,e.floorId),r=n.objects.find(d=>d.type==="row"&&d.id===e.rowId);if(!r)throw new u("object_not_found",`Unknown row id: ${e.rowId}`,{rowId:e.rowId});let i=pr(e.path),a=z(r),o=structuredClone(r);o.path=i.path,o.origin={...i.path.start};let s=z(o),c=a.map((d,g)=>Math.hypot(d.x-s[g].x,d.y-s[g].y)),l=JSON.stringify(r.path)!==JSON.stringify(i.path)||r.origin.x!==i.path.start.x||r.origin.y!==i.path.start.y;return{floorId:n.floorId,rowId:r.id,seatCount:r.seatCount,pathLength:i.length,averageSeatMovement:c.length?c.reduce((d,g)=>d+g,0)/c.length:0,maxSeatMovement:c.length?Math.max(...c):0,convertingFromParametric:!r.path,changed:l,preservesStableId:!0,preservesSeatMetadata:!0,preservesInventoryUnits:r.seatCount}}function mr(t,e){let n=on(t,e);if(!n.changed)return n;let i=C(t,n.floorId).objects.find(a=>a.type==="row"&&a.id===n.rowId);return i.path=structuredClone(e.path),i.origin={...e.path.start},delete i.arcFanGeneration,delete i.rowBlockGeneration,n}function yr(t,e){let n=t.map((r,i)=>[...r,e[i]]);for(let r=0;r<3;r++){let i=r;for(let o=r+1;o<3;o++)Math.abs(n[o][r])>Math.abs(n[i][r])&&(i=o);if(Math.abs(n[i][r])<1e-9)return null;[n[r],n[i]]=[n[i],n[r]];let a=n[r][r];for(let o=r;o<4;o++)n[r][o]/=a;for(let o=0;o<3;o++){if(o===r)continue;let s=n[o][r];for(let c=r;c<4;c++)n[o][c]-=s*n[r][c]}}return[n[0][3],n[1][3],n[2][3]]}function wr(t){if(t.length<3)return null;let e=[[0,0,0],[0,0,0],[0,0,0]],n=[0,0,0];for(let i of t){if(!Number.isFinite(i.x)||!Number.isFinite(i.y))return null;let a=[2*i.x,2*i.y,1],o=i.x**2+i.y**2;for(let s=0;s<3;s++){n[s]+=a[s]*o;for(let c=0;c<3;c++)e[s][c]+=a[s]*a[c]}}let r=yr(e,n);return r?{x:r[0],y:r[1]}:null}function tn(t){let e=((t+180)%360+360)%360-180;return e===-180&&(e=180),e}function rn(t,e){let n=C(t,e.floorId),r=n.objects.find(f=>f.type==="section"&&f.id===e.sectionId);if(!r)throw new u("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});let i=e.strength??100;if(!Number.isFinite(i)||i<0||i>100)throw new u("invalid_operation","Section row-fit strength must be from 0 to 100");let a=G(t).find(f=>f.id===n.floorId),o=e.mode==="outline"?wr(r.outline):e.focalPoint??a.focalPoint??t.focalPoint;if(!o||!Number.isFinite(o.x)||!Number.isFinite(o.y))throw new u("invalid_operation",`Section ${e.mode} fit has no finite center`);let s=n.objects.filter(f=>f.type==="row"&&N(F(f),r.outline,r.holes)),c=s.filter(f=>!!f.path).map(f=>f.id),l=[],d=[],g=i/100;for(let f of s){if(f.path)continue;if(f.seatCount<2){l.push(f.id);continue}let b=Math.hypot(f.origin.x-o.x,f.origin.y-o.y);if(b<=f.seatSpacing/2+1e-6){l.push(f.id);continue}let y=2*Math.asin(f.seatSpacing/(2*b))/X,x=z(f),v=Math.atan2(f.origin.x-o.x,f.origin.y-o.y)/X,m=(f.curve!==0?Math.sign(f.curve):x.length>1&&Math.sign(tn(Math.atan2(x[1].x-o.x,x[1].y-o.y)/X-v))||1)*y*(f.seatCount-1);if(Math.abs(m)>320){l.push(f.id);continue}let w=-v,S=f.curve+(m-f.curve)*g,I=f.rotation+tn(w-f.rotation)*g,M={...f,curve:S,rotation:I},T=z(M).map((U,K)=>Math.hypot(U.x-x[K].x,U.y-x[K].y));d.push({rowId:f.id,fromCurve:f.curve,targetCurve:m,resultCurve:S,fromRotation:f.rotation,resultRotation:I,rmsMovement:Math.sqrt(T.reduce((U,K)=>U+K**2,0)/T.length),maxMovement:Math.max(...T)})}let h=d.map(f=>f.rmsMovement);return{floorId:n.floorId,sectionId:r.id,mode:e.mode,fitCenter:{...o},strength:i,rows:d,skippedPathRowIds:c,skippedInvalidRowIds:l,averageMovement:h.length?h.reduce((f,b)=>f+b,0)/h.length:0,maxMovement:d.length?Math.max(...d.map(f=>f.maxMovement)):0}}function xr(t,e){let n=rn(t,e),r=C(t,n.floorId),i=r.objects.find(o=>o.type==="section"&&o.id===n.sectionId),a=!1;for(let o of n.rows){let s=r.objects.find(c=>c.type==="row"&&c.id===o.rowId);(s.curve!==o.resultCurve||s.rotation!==o.resultRotation)&&(s.curve=o.resultCurve,s.rotation=o.resultRotation,delete s.arcFanGeneration,delete s.rowBlockGeneration,a=!0)}return(i.smoothing??0)!==n.strength&&(i.smoothing=n.strength,a=!0),{...n,changed:a}}function an(t,e,n,r){let i=J(t,e,n),a=J(t,e,r),o=J(n,r,t),s=J(n,r,e);return i*a<-1e-9&&o*s<-1e-9}function nn(t,e){return t.some((n,r)=>{let i=t[(r+1)%t.length];return e.some((a,o)=>an(n,i,a,e[(o+1)%e.length]))})}function Sr(t){if(t.length<3||t.length>256||Math.abs(de(t))<1||t.some(e=>!Number.isFinite(e.x)||!Number.isFinite(e.y)))return!1;for(let e=0;e<t.length;e++)for(let n=e+1;n<t.length;n++)if(!(n===e+1||e===0&&n===t.length-1)&&an(t[e],t[(e+1)%t.length],t[n],t[(n+1)%t.length]))return!1;return!0}function Ee(t,e,n){let r=C(t,e),i=r.objects.find(a=>(a.type==="section"||a.type==="gaArea")&&a.id===n);if(!i)throw new u("object_not_found",`Unknown polygon object id: ${n}`,{objectId:n});return{target:r,object:i,outer:i.type==="section"?i.outline:i.points}}function Ne(t,e){let{target:n,object:r,outer:i}=Ee(t,e.floorId,e.objectId),a=structuredClone(e.points);if(!Sr(a))throw new u("invalid_operation","Opening must be a finite, non-self-intersecting shape with 3\u2013256 corners");if(a.some(l=>!N(l,i,void 0)))throw new u("invalid_operation","Every opening corner must stay inside the outer boundary");if(nn(a,i))throw new u("invalid_operation","Opening edges cannot cross the outer boundary");let o=r.holes??[],s=e.holeIndex??o.length;if(!Number.isInteger(s)||s<0||s>o.length||e.holeIndex!=null&&s>=o.length)throw new u("invalid_operation","Opening not found");for(let l=0;l<o.length;l++){if(l===e.holeIndex)continue;let d=o[l];if(nn(a,d)||N(a[0],d,void 0)||N(d[0],a,void 0))throw new u("invalid_operation","Openings cannot overlap or contain one another")}let c=n.objects.filter(l=>l.id!==r.id&&l.type!=="section"&&N(F(l),a,void 0));return{floorId:n.floorId,objectId:r.id,objectType:r.type,holeIndex:s,vertexCount:a.length,excludedObjectIds:c.map(l=>l.id),excludedInventoryUnits:Te(n.objects.filter(l=>l.id!==r.id),a),preservesExactOuterPath:r.type==="section"&&!!r.outlinePath}}function Ir(t,e){let n=Ne(t,e),{object:r}=Ee(t,n.floorId,n.objectId);return r.holes??=[],e.holeIndex==null?r.holes.push(structuredClone(e.points)):r.holes[e.holeIndex]=structuredClone(e.points),{...n,changed:!0}}function sn(t,e){let{target:n,object:r}=Ee(t,e.floorId,e.objectId);if(!Number.isInteger(e.holeIndex)||e.holeIndex<0||e.holeIndex>=(r.holes?.length??0))throw new u("invalid_operation","Opening not found");let i=r.holes[e.holeIndex],a=n.objects.filter(o=>o.id!==r.id&&o.type!=="section"&&N(F(o),i,void 0));return{floorId:n.floorId,objectId:r.id,objectType:r.type,holeIndex:e.holeIndex,vertexCount:i.length,excludedObjectIds:a.map(o=>o.id),excludedInventoryUnits:Te(n.objects.filter(o=>o.id!==r.id),i),preservesExactOuterPath:r.type==="section"&&!!r.outlinePath}}function vr(t,e){let n=sn(t,e),{object:r}=Ee(t,n.floorId,n.objectId);return r.holes.splice(e.holeIndex,1),r.holes.length||delete r.holes,{...n,changed:!0}}function Cr(t){let e=t.trim();if(!e||e.length>2e6||!/^(https:\/\/|data:image\/)/.test(e))throw new u("invalid_operation","Section view photo must be an HTTPS or data:image URL no larger than 2 MB");return e}function cn(t,e){let n=[...new Set(e)];if(!n.length)throw new u("invalid_operation","At least one section id is required");let r=n.map(o=>t.find(s=>s.type==="section"&&s.id===o)),i=n.filter((o,s)=>!r[s]);if(i.length)throw new u("object_not_found",`Unknown section id(s): ${i.join(", ")} on the selected floor. Call get_chart to list current section ids.`,{sectionIds:i});let a=r;return{requested:n,sections:a,logicalSectionIds:[...new Set(a.map(o=>o.logicalSectionId??o.id))]}}function ln(t,e){let n=C(t,e.floorId),r=cn(n.objects,e.sectionIds),i=he(Oe(t,n.floorId)),a=new Map(i.sections.map(g=>[g.id,g])),o=new Map(n.objects.map(g=>[g.id,g])),s=r.logicalSectionIds.flatMap(g=>a.get(g)?.objectIds??[]),c=new Set;for(let g of s){let h=o.get(g);if(h)if(h.type==="row"||h.type==="table")for(let f of Re(h).keys())c.add(f);else(h.type==="booth"||h.type==="gaArea")&&c.add(h.categoryKey)}let l=r.logicalSectionIds.every(g=>(a.get(g)?.seatCount??0)>0),d=r.logicalSectionIds.every(g=>a.get(g)?.objectIds.some(h=>{let f=o.get(h);return f?.type==="row"||f?.type==="table"||f?.type==="booth"})===!0);return{floorId:n.floorId,sectionIds:r.requested,logicalSectionIds:r.logicalSectionIds,objectIds:s,categoryApplicable:l,...l&&c.size===1?{categoryKey:[...c][0]}:{},categoryMixed:l&&c.size!==1,viewApplicable:d}}function Pr(t,e){k(t,e.categoryKey);let n=ln(t,e);if(!n.categoryApplicable)throw new u("invalid_operation","Every selected logical section must contain buyer inventory before a section category can be assigned",{logicalSectionIds:n.logicalSectionIds});let r=C(t,n.floorId),i=new Set(n.objectIds),a=!1,o=0;for(let s of r.objects){if(!i.has(s.id)||s.type!=="row"&&s.type!=="table"&&s.type!=="booth"&&s.type!=="gaArea"||(s.categoryKey!==e.categoryKey&&(s.categoryKey=e.categoryKey,a=!0),s.type!=="row"&&s.type!=="table"||!s.overrides?.length))continue;let c=s.overrides.flatMap(l=>{if(l.categoryKey===void 0)return[l];let d={...l};return delete d.categoryKey,o++,a=!0,Object.keys(d).some(g=>g!=="index")?[d]:[]});c.length?s.overrides=c:delete s.overrides}return{...n,changed:a,categoryKey:e.categoryKey,categoryMixed:!1,clearedSeatOverrideCount:o}}function Or(t,e){let n=C(t,e.floorId),r=cn(n.objects,e.sectionIds),{requested:i}=r,a=structuredClone(e.patch),o=new Set(["label","displayLabel","entrance","viewFromSeatUrl","viewFromSeatMeta","labelPresentation","labelStyle","zone","elevation","height","rake","surfaceKind","color"]),s=Object.keys(a).filter(f=>!o.has(f));if(s.length)throw new u("invalid_operation",`Unsupported section metadata field(s): ${s.join(", ")}`);if(!Object.keys(a).length)throw new u("invalid_operation","At least one section metadata change is required");if(a.label!==void 0){if(a.label=a.label.normalize("NFKC").trim(),i.length!==1)throw new u("invalid_operation","label can be changed only for one section at a time");if(!a.label||a.label.length>80)throw new u("invalid_operation","Section labels must contain 1 to 80 characters")}if(a.displayLabel!==void 0&&a.displayLabel!==null){if(a.displayLabel=a.displayLabel.normalize("NFKC").trim(),i.length!==1)throw new u("invalid_operation","displayLabel can be changed only for one section at a time");if(!a.displayLabel||a.displayLabel.length>80)throw new u("invalid_operation","Section display labels must contain 1 to 80 characters")}if(a.entrance!==void 0&&a.entrance!==null&&(a.entrance=a.entrance.normalize("NFKC").trim(),a.entrance.length>40))throw new u("invalid_operation","Section entrance must be at most 40 characters");if(a.viewFromSeatUrl!==void 0&&a.viewFromSeatUrl!==null&&(a.viewFromSeatUrl=Cr(a.viewFromSeatUrl)),a.labelPresentation?.position&&(!Number.isFinite(a.labelPresentation.position.x)||!Number.isFinite(a.labelPresentation.position.y)))throw new u("invalid_operation","Section label position must be finite");if(a.labelPresentation?.rotation!=null&&!Number.isFinite(a.labelPresentation.rotation))throw new u("invalid_operation","Section label rotation must be finite");if(a.labelPresentation!==void 0&&Ae(a.labelPresentation,"Section"),a.labelStyle!==void 0&&se(a.labelStyle,"Section"),a.zone!==void 0&&a.zone!==null&&!(t.zones??[]).some(f=>f.id===a.zone))throw new u("object_not_found",`Unknown chart zone: ${a.zone}`,{zoneId:a.zone});if(a.elevation!==void 0&&(!Number.isInteger(a.elevation)||a.elevation<0||a.elevation>3))throw new u("invalid_operation","Section elevation must be an integer from 0 to 3");if(a.height!==void 0&&a.height!==null&&(!Number.isFinite(a.height)||a.height<0||a.height>120))throw new u("invalid_operation","Section height must be a number from 0 to 120 metres");if(a.rake!==void 0&&a.rake!==null&&(!Number.isFinite(a.rake)||a.rake<0||a.rake>45))throw new u("invalid_operation","Section rake must be a number from 0 to 45 degrees");if(a.surfaceKind!==void 0&&a.surfaceKind!==null&&a.surfaceKind!=="flat"&&a.surfaceKind!=="rakedRows")throw new u("invalid_operation","Section surfaceKind must be 'flat' or 'rakedRows'");a.color!==void 0&&a.color!==null&&(a.color=L(a.color,"Section color"));let c=a.displayLabel!==void 0||a.entrance!==void 0||a.viewFromSeatUrl!==void 0||a.viewFromSeatMeta!==void 0||a.labelStyle!==void 0||a.zone!==void 0,l=new Set(r.logicalSectionIds),d=c?n.objects.filter(f=>f.type==="section"&&l.has(f.logicalSectionId??f.id)):[],g=new Set,h=!1;for(let f of r.sections){let b=JSON.stringify(f);a.label!==void 0&&(f.label=a.label),a.labelPresentation===null?delete f.labelPresentation:a.labelPresentation!==void 0&&(f.labelPresentation=a.labelPresentation),a.elevation!==void 0&&(f.elevation=a.elevation);let y=x=>{f.physical3dProvenance&&(delete f.physical3dProvenance[x],Object.keys(f.physical3dProvenance).length===0&&delete f.physical3dProvenance)};a.height===null?(delete f.height,y("height")):a.height!==void 0&&(f.height=a.height,f.physical3dProvenance={...f.physical3dProvenance,height:{status:"confirmed",source:"user-review",note:"Section front-edge height reviewed through the shared Designer/Copilot operation."}}),a.rake===null?(delete f.rake,y("rake")):a.rake!==void 0&&(f.rake=a.rake,f.physical3dProvenance={...f.physical3dProvenance,rake:{status:"confirmed",source:"user-review",note:"Section rake reviewed through the shared Designer/Copilot operation."}}),a.surfaceKind===null?(delete f.surfaceKind,y("surfaceKind")):a.surfaceKind!==void 0&&(f.surfaceKind=a.surfaceKind,f.physical3dProvenance={...f.physical3dProvenance,surfaceKind:{status:"confirmed",source:"user-review",note:"Section surface behavior reviewed through the shared Designer/Copilot operation."}}),a.color===null?delete f.color:a.color!==void 0&&(f.color=a.color),JSON.stringify(f)!==b&&(h=!0,g.add(f.id))}for(let f of d){let b=JSON.stringify(f),y=f.viewFromSeatUrl;if(a.displayLabel===null?delete f.displayLabel:a.displayLabel!==void 0&&(f.displayLabel=a.displayLabel),a.entrance===null||a.entrance===""?delete f.entrance:a.entrance!==void 0&&(f.entrance=a.entrance),a.viewFromSeatUrl===null||a.viewFromSeatUrl===""?delete f.viewFromSeatUrl:a.viewFromSeatUrl!==void 0&&(f.viewFromSeatUrl=a.viewFromSeatUrl),!f.viewFromSeatUrl||a.viewFromSeatMeta===null?delete f.viewFromSeatMeta:a.viewFromSeatMeta!==void 0?f.viewFromSeatMeta=structuredClone(a.viewFromSeatMeta):a.viewFromSeatUrl!==void 0&&f.viewFromSeatUrl!==y&&delete f.viewFromSeatMeta,a.labelStyle!==void 0){let x=_e(f.labelPresentation,a.labelStyle);x?f.labelPresentation=x:delete f.labelPresentation}a.zone===null?delete f.zone:a.zone!==void 0&&(f.zone=a.zone),JSON.stringify(f)!==b&&(h=!0,g.add(f.id))}return{floorId:n.floorId,changed:h,sectionIds:i,affectedSectionIds:[...g]}}function dn(t,e){let n=C(t,e.floorId),r=n.objects.find(a=>a.type==="section"&&a.id===e.sectionId);if(!r)throw new u("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});if(r.outlinePath)throw new u("invalid_operation",`Section ${r.id} has an exact path; polygon conversion requires a separate loss review`,{sectionId:r.id,representation:"exact-path"});if(!r.geometry)throw new u("invalid_operation",`Section ${r.id} is already a manual polygon`,{sectionId:r.id,representation:"manual-polygon"});let i=n.objects.filter(a=>a.id!==r.id&&a.type!=="section"&&N(F(a),r.outline,r.holes));return{floorId:n.floorId,sectionId:r.id,sectionLabel:r.label,source:{representation:"generated-polygon",generator:structuredClone(r.geometry)},target:{representation:"manual-polygon"},geometryChanged:!1,preserved:{stableId:!0,outlineVertexCount:r.outline.length,holeCount:r.holes?.length??0,memberObjectIds:i.map(a=>a.id),inventoryUnits:i.reduce((a,o)=>a+W(o),0),durableReferenceSource:!!r.referenceSource,inventoryExclusionEvidence:!!r.referenceInventoryExclusion},removedFields:["geometry"]}}function Mr(t,e){let n=dn(t,e),i=C(t,n.floorId).objects.find(a=>a.type==="section"&&a.id===n.sectionId);return delete i.geometry,{...n,changed:!0}}function un(t,e){let n=(...s)=>s.every(Number.isFinite),r,i=1,a=!1,o=!0;if(e.kind==="translate"){if(!n(e.dx,e.dy))throw new u("invalid_operation","Section translation must be finite");o=e.dx!==0||e.dy!==0,r=s=>({x:s.x+e.dx,y:s.y+e.dy})}else if(e.kind==="scale"){if(!n(e.factor)||e.factor<=0||e.factor>100)throw new u("invalid_operation","Section scale factor must be finite and greater than 0");o=e.factor!==1,i=e.factor;let s=F(t);r=c=>({x:s.x+(c.x-s.x)*e.factor,y:s.y+(c.y-s.y)*e.factor})}else if(e.kind==="rotate"){if(!n(e.degrees))throw new u("invalid_operation","Section rotation must be finite");o=(e.degrees%360+360)%360!==0;let c=e.degrees*Math.PI/180,l=Math.cos(c),d=Math.sin(c),g=F(t);r=h=>{let f=h.x-g.x,b=h.y-g.y;return{x:g.x+f*l-b*d,y:g.y+f*d+b*l}}}else{if(!n(e.coordinate))throw new u("invalid_operation","Section reflection coordinate must be finite");a=!0,r=e.axis==="h"?s=>({x:2*e.coordinate-s.x,y:s.y}):s=>({x:s.x,y:2*e.coordinate-s.y})}return o&&(t.outline=t.outline.map(r),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(r)),t.outlinePath&&(t.outlinePath=Qe(t.outlinePath,r,i,a)),t.holes&&(t.holes=t.holes.map(s=>s.map(r)))),{changed:o,sectionId:t.id,representation:t.outlinePath?"exact-path":"polygon",outlineVertexCount:t.outline.length,holeCount:t.holes?.length??0,pathSegmentKinds:t.outlinePath?.segments.map(s=>s.kind)??[]}}function Ar(t,e){let n=C(t,e.floorId),r=n.objects.find(i=>i.type==="section"&&i.id===e.sectionId);if(!r)throw new u("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});return{floorId:n.floorId,...un(r,e.transform)}}function _r(t,e){let n=C(t,e.floorId),r=n.objects.find(s=>s.type==="section"&&s.id===e.sectionId);if(!r)throw new u("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});let i=structuredClone(e.path);if(!ve(i))throw new u("invalid_operation","Exact section path is not finite, continuous, closed, or radius-correct");let a=Ye(i),o=JSON.stringify(r.outlinePath)!==JSON.stringify(i)||JSON.stringify(r.outline)!==JSON.stringify(a)||r.sourceOutline!==void 0||r.cornerSmoothing!==void 0;return o&&(r.outlinePath=i,r.outline=a,delete r.geometry,delete r.sourceOutline,delete r.cornerSmoothing),{floorId:n.floorId,sectionId:r.id,changed:o,segmentKinds:i.segments.map(s=>s.kind),sampledVertexCount:a.length,holeCount:r.holes?.length??0}}function jr(t){return t.geometry?null:t.sourceOutline?.length?t.sourceOutline:t.outlinePath?null:t.outline?.length?t.outline:null}function kr(t,e){return fn(t,{floorId:e.floorId,sectionIds:e.sectionIds,cornerSmoothing:e.strength})}function fn(t,e){let n=C(t,e.floorId);if(e.cornerSmoothing!==void 0&&!Number.isFinite(e.cornerSmoothing))throw new u("invalid_operation","Corner smoothing must be a number from 0 to 100");if(e.edgeCurvature!=null&&e.edgeCurvature.some(s=>!Number.isFinite(s)))throw new u("invalid_operation","Edge curvature values must be numbers from -100 to 100");let r=[...new Set(e.sectionIds)],i=new Set,a=new Map,o=!1;try{for(let s of r){let c=n.objects.find(p=>p.type==="section"&&p.id===s);if(!c||!jr(c))continue;let d=structuredClone(c);a.set(c.id,{section:c,snapshot:d});let g=JSON.stringify(c),h=(c.sourceOutline??c.outline).map(p=>({...p})),f=Math.min(100,Math.max(0,e.cornerSmoothing??c.cornerSmoothing??0)),y=(e.edgeCurvature===void 0?c.edgeCurvature:e.edgeCurvature??void 0)?.map(p=>Math.min(100,Math.max(-100,p))),x=y?.some(p=>Math.abs(p)>.5)===!0,v=f>.5||x?_t(h,{cornerSmoothing:f,...x?{edgeCurvature:y}:{}}):null;v?(c.sourceOutline=h,c.outlinePath=v,c.outline=Ye(v),f>.5?c.cornerSmoothing=f:delete c.cornerSmoothing,x?c.edgeCurvature=[...y]:delete c.edgeCurvature):(c.outline=h,delete c.outlinePath,delete c.sourceOutline,delete c.cornerSmoothing,delete c.edgeCurvature);for(let p=0;p<(c.holes?.length??0);p+=1)Ne(t,{floorId:n.floorId,objectId:c.id,points:c.holes[p],holeIndex:p});JSON.stringify(c)!==g&&(o=!0,i.add(c.id))}}catch(s){for(let{section:c,snapshot:l}of a.values()){let d=c;for(let g of Object.keys(d))delete d[g];Object.assign(c,structuredClone(l))}throw s}return{floorId:n.floorId,changed:o,sectionIds:r,affectedSectionIds:[...i]}}var Rr=/^#?([\da-f]{3}|[\da-f]{6})$/i;function De(t){let e=Rr.exec((t??"").trim());if(!e)return null;let n=e[1].length===3?e[1].split("").map(i=>i+i).join(""):e[1],r=parseInt(n,16);return[r>>16&255,r>>8&255,r&255]}function gt(t){let e=t/255;return e<=.04045?e/12.92:((e+.055)/1.055)**2.4}function gn(t){return .2126*gt(t[0])+.7152*gt(t[1])+.0722*gt(t[2])}function Ge(t,e){let n=De(t),r=De(e);if(!n||!r)return null;let i=gn(n),a=gn(r);return(Math.max(i,a)+.05)/(Math.min(i,a)+.05)}var hn=["butt","round","square"],bn=["miter","round","bevel"],pn=["none","arrow"];function ht(t){return t==="line"||t==="polyline"}function mn(t){let e=De(t);if(!e)return null;let n=f=>{let b=f/255;return b<=.04045?b/12.92:((b+.055)/1.055)**2.4},r=n(e[0]),i=n(e[1]),a=n(e[2]),o=(.4124*r+.3576*i+.1805*a)/.95047,s=(.2126*r+.7152*i+.0722*a)/1,c=(.0193*r+.1192*i+.9505*a)/1.08883,l=f=>f>.008856?Math.cbrt(f):7.787*f+16/116,d=l(o),g=l(s),h=l(c);return[116*g-16,500*(d-g),200*(g-h)]}function yn(t,e){let n=mn(t),r=mn(e);return!n||!r?null:Math.hypot(n[0]-r[0],n[1]-r[1],n[2]-r[2])}var wn=[{key:"circle",label:"Circle",hint:"The standard seat dot.",path:null,bounds:null},{key:"theatre",label:"Theatre chair",hint:"Upright chair with a tall back \u2014 auditorium and theatre seating.",path:"M4.5 3.5 Q4.5 1.5 6.5 1.5 L17.5 1.5 Q19.5 1.5 19.5 3.5 L19.5 13 L4.5 13 Z M3.5 12 L20.5 12 Q22.5 12 22.5 14 L22.5 21 Q22.5 22.5 21 22.5 Q19.5 22.5 19.5 21 L19.5 17.5 L4.5 17.5 L4.5 21 Q4.5 22.5 3 22.5 Q1.5 22.5 1.5 21 L1.5 14 Q1.5 12 3.5 12 Z",bounds:{x:1.5,y:1.5,width:21,height:21}},{key:"armchair",label:"Armchair",hint:"Padded chair with wide arms \u2014 premium and box seating.",path:"M3.5 4 Q3.5 1.5 6 1.5 L18 1.5 Q20.5 1.5 20.5 4 L20.5 13 L3.5 13 Z M1.5 12.5 Q1.5 10 3.25 10 Q5 10 5 12.5 L5 13.5 L19 13.5 L19 12.5 Q19 10 20.75 10 Q22.5 10 22.5 12.5 L22.5 19.5 Q22.5 22 20 22 L4 22 Q1.5 22 1.5 19.5 Z",bounds:{x:1.5,y:1.5,width:21,height:20.5}},{key:"stool",label:"Stool",hint:"Backless perch \u2014 bar tops, high tables and standing rails.",path:"M6 2.5 L18 2.5 Q22 2.5 22 6.5 L22 12 Q22 16 18 16 L6 16 Q2 16 2 12 L2 6.5 Q2 2.5 6 2.5 Z M6 15.5 L9.5 15.5 L7.5 22.5 L3 22.5 Z M14.5 15.5 L18 15.5 L20.5 22.5 L16 22.5 Z",bounds:{x:2,y:2.5,width:20,height:20}},{key:"bench",label:"Bench slot",hint:"One place on a shared bench \u2014 pews, bleachers and terraces.",path:"M2.5 0.5 L21.5 0.5 Q23 0.5 23 2 L23 5 Q23 6.5 21.5 6.5 L2.5 6.5 Q1 6.5 1 5 L1 2 Q1 0.5 2.5 0.5 Z M2 7.5 L22 7.5 Q23.5 7.5 23.5 9 L23.5 15.5 Q23.5 17 22 17 L18 17 L18 21.5 Q18 22.5 16.75 22.5 Q15.5 22.5 15.5 21.5 L15.5 17 L8.5 17 L8.5 21.5 Q8.5 22.5 7.25 22.5 Q6 22.5 6 21.5 L6 17 L2 17 Q0.5 17 0.5 15.5 L0.5 9 Q0.5 7.5 2 7.5 Z",bounds:{x:.5,y:.5,width:23,height:22}}],vs=wn.map(t=>t.key),Fr=new Map(wn.map(t=>[t.key,t]));function me(t){return typeof t=="string"&&Fr.has(t)}var Lr=new Set(["companion","child","senior","student","membership","custom"]);function ye(t){if(!t.length)throw new u("invalid_operation","A chart must have at least one category");let e=new Set,n=new Map,r=structuredClone(t);for(let i of r){let a=i.key.trim(),o=i.label.normalize("NFKC").trim();if(!a||a.length>160||e.has(a))throw new u("invalid_operation",`Category keys must be non-empty and unique: ${a}`,{categoryKey:a});if(e.add(a),!o||o.length>80)throw new u("invalid_operation",`Category labels must contain 1 to 80 characters: ${a}`,{categoryKey:a});let s=o.toLocaleLowerCase("en"),c=n.get(s);if(c)throw new u("duplicate_category_label",`Categories ${c} and ${a} share the same label`,{categoryKeys:[c,a],label:o});if(n.set(s,a),!/^#[0-9a-fA-F]{6}$/.test(i.color))throw new u("invalid_operation",`Category ${a} must use a six-digit hex color`,{categoryKey:a});if(i.price!=null&&(!Number.isFinite(i.price)||i.price<0||i.price>1e6))throw new u("invalid_operation",`Category ${a} price must be from 0 to 1000000`,{categoryKey:a});if(i.seatGlyph!=null&&!me(i.seatGlyph))throw new u("invalid_operation",`Category ${a} has an unknown seat glyph`,{categoryKey:a,seatGlyph:i.seatGlyph});if((i.seatGlyph==null||i.seatGlyph==="circle")&&delete i.seatGlyph,i.tiers!=null)if(!i.tiers.length)delete i.tiers;else{if(i.tiers.length>20)throw new u("invalid_operation",`Category ${a} supports at most 20 ticket tiers`);let l=new Set,d=new Set;for(let g of i.tiers){let h=g.id.trim(),f=g.name.normalize("NFKC").trim(),b=f.toLocaleLowerCase("en");if(!h||h.length>160||l.has(h))throw new u("invalid_operation",`Ticket tier ids must be non-empty and unique in category ${a}`,{categoryKey:a,tierId:h});if(!f||f.length>80||d.has(b))throw new u("invalid_operation",`Ticket tier names must be non-empty and unique in category ${a}`,{categoryKey:a,tierName:f});if(!Number.isFinite(g.price)||g.price<0||g.price>1e6)throw new u("invalid_operation",`Ticket tier ${h} price must be from 0 to 1000000`,{categoryKey:a,tierId:h});if(g.restriction!=null&&!Lr.has(g.restriction))throw new u("invalid_operation",`Ticket tier ${h} has an unknown restriction`,{categoryKey:a,tierId:h});if(g.buyerMessage!=null){if(g.buyerMessage=g.buyerMessage.normalize("NFKC").trim(),!g.buyerMessage)delete g.buyerMessage;else if(g.buyerMessage.length>240)throw new u("invalid_operation",`Ticket tier ${h} buyer guidance must be at most 240 characters`,{categoryKey:a,tierId:h})}if(g.currency!=null&&(g.currency=g.currency.trim().toUpperCase(),!/^[A-Z]{3}$/.test(g.currency)))throw new u("invalid_operation",`Ticket tier ${h} must use a three-letter ISO currency`,{categoryKey:a,tierId:h});if(g.applicability!=null){let y=g.applicability.seatLabels?.map(v=>v.normalize("NFKC").trim()),x=g.applicability.accessibility;if(y&&(!y.length||y.length>1e4||y.some(v=>!v||v.length>160)||new Set(y).size!==y.length)||x&&(!x.length||x.some(v=>!fe.some(p=>p.key===v))||new Set(x).size!==x.length))throw new u("invalid_operation",`Ticket tier ${h} has invalid seat applicability`,{categoryKey:a,tierId:h});g.applicability={...y?{seatLabels:y}:{},...x?{accessibility:[...x]}:{}},!g.applicability.seatLabels&&!g.applicability.accessibility&&delete g.applicability}if(g.evidence!=null){if(!["public-host","public-event","user-confirmed"].includes(g.evidence.provenance)||typeof g.evidence.sourceDescription!="string")throw new u("invalid_operation",`Ticket tier ${h} has invalid evidence provenance`,{categoryKey:a,tierId:h});if(g.evidence.sourceDescription=g.evidence.sourceDescription.normalize("NFKC").trim(),!g.evidence.sourceDescription||g.evidence.sourceDescription.length>240||g.evidence.capturedAt!==void 0&&(g.evidence.capturedAt.length>40||!Number.isFinite(Date.parse(g.evidence.capturedAt))))throw new u("invalid_operation",`Ticket tier ${h} has invalid evidence provenance`,{categoryKey:a,tierId:h})}l.add(h),d.add(b)}}}return r}function In(t,e){let n=new Set,r=structuredClone(t.categories);for(let o of e.updates){if(n.has(o.categoryKey))throw new u("invalid_operation",`Category ${o.categoryKey} may be updated only once`);n.add(o.categoryKey);let s=r.find(g=>g.key===o.categoryKey);if(!s)throw new u("category_not_found",`Unknown chart category: ${o.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:o.categoryKey});let c=structuredClone(o.patch),{tiers:l,...d}=c;typeof d.label=="string"&&(d.label=d.label.normalize("NFKC").trim()),typeof d.color=="string"&&(d.color=d.color.toLowerCase()),Object.assign(s,d),s.notForSale===!1&&delete s.notForSale,Object.prototype.hasOwnProperty.call(c,"tiers")&&(l==null?delete s.tiers:s.tiers=l?.map(g=>{let h={...g,id:g.id.trim(),name:g.name.normalize("NFKC").trim()};return g.buyerMessage?.trim()?h.buyerMessage=g.buyerMessage.normalize("NFKC").trim():delete h.buyerMessage,h}))}let i=ye(r),a=JSON.stringify(i)!==JSON.stringify(t.categories);return a&&(t.categories=i),{changed:a,categoryKeys:[...n],categories:t.categories}}function Tr(t,e){let n=e.categoryKeys.map(c=>c.trim()),r=t.categories.map(c=>c.key);if(n.length!==r.length||new Set(n).size!==n.length)throw new u("invalid_operation","Category order must contain every stable category key exactly once",{categoryKeys:n,expectedCategoryKeys:r});let i=new Set(r),a=r.filter(c=>!n.includes(c)),o=n.filter(c=>!i.has(c));if(a.length||o.length)throw new u(o.length?"category_not_found":"invalid_operation","Category order must be an exact permutation of the current stable keys",{categoryKeys:n,missingCategoryKeys:a,unknownCategoryKeys:o});if(n.every((c,l)=>c===r[l]))return{changed:!1,categoryKeys:r,categories:t.categories};let s=new Map(t.categories.map(c=>[c.key,c]));return t.categories=ye(n.map(c=>structuredClone(s.get(c)))),{changed:!0,categoryKeys:n,categories:t.categories}}var bt=["#e69f00","#56b4e9","#009e73","#f0e442","#0072b2","#d55e00","#cc79a7"];function xn(t){let e=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i.exec(t.trim());if(!e)return null;let n=e[1];return n.length===3&&(n=n.split("").map(r=>r+r).join("")),[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)]}function Er(t,e){let n=xn(t),r=xn(e);return!n||!r?1/0:(n[0]-r[0])**2+(n[1]-r[1])**2+(n[2]-r[2])**2}var Nr=3600;function vn(t,e,n=bt){return n.find(i=>t.every(a=>Er(i,a)>=Nr))??n[e%n.length]}function Dr(t,e){let n=e?.palette??bt;if(!t.categories.length)return{changed:[],categories:t.categories};let r=new Map(t.categories.map(o=>[o.key,o.color.toLowerCase()])),i=t.categories.map((o,s)=>({categoryKey:o.key,patch:{color:n[s%n.length]}}));return In(t,{updates:i}),{changed:t.categories.map(o=>({key:o.key,from:r.get(o.key),to:o.color})).filter(o=>o.from!==o.to),categories:t.categories}}function Gr(t,e){let n=e.color.trim().toLowerCase(),r=e.sourceDescription.normalize("NFKC").trim();if(!/^#[0-9a-f]{6}$/.test(n))throw new u("invalid_operation","Sampled category color must be a six-digit hex color");if(!r||r.length>240)throw new u("invalid_operation","Color confirmation evidence must contain 1 to 240 characters");let i=structuredClone(t.categories),a=i.find(c=>c.key===e.categoryKey);if(!a)throw new u("category_not_found",`Unknown chart category: ${e.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:e.categoryKey});a.color=n,a.referenceCategorySource&&(a.referenceCategorySource.outputColorEvidence="user-confirmed",a.referenceCategorySource.outputColorSourceDescription=r);let o=ye(i),s=JSON.stringify(o)!==JSON.stringify(t.categories);return s&&(t.categories=o),{changed:s,category:t.categories.find(c=>c.key===e.categoryKey),categories:t.categories}}function Cn(t,e){let n=new Set(t.categories.map(o=>o.key)),r="";for(let o=0;o<100;o++){let c=e.idFactory("cat").trim();if(c&&!n.has(c)){r=c;break}}if(!r)throw new u("id_generation_failed","Unable to allocate a unique category id");let i={key:r,label:e.label.normalize("NFKC").trim(),color:e.color.toLowerCase(),price:e.price,tiers:e.tiers?.map(o=>({...o,id:o.id.trim(),name:o.name.normalize("NFKC").trim()}))},a=ye([...t.categories,i]);return t.categories=a,{changed:!0,category:a.find(o=>o.key===r),categories:a}}var Kr=["#e5484d","#a86b00","#8b5cf6","#d6336c","#4d7c0f","#dc2626","#c026d3"],$r={row:"#e5484d",table:"#a86b00",booth:"#8b5cf6",gaArea:"#4d7c0f"};function zr(t,e){let n=$r[t];return!n||!e.includes(n)?e:[n,...e.filter(r=>r!==n)]}var Br=26;function Ur(t,e,n){let r=(1-Math.abs(2*n-1))*e,i=(t%360+360)%360/60,a=r*(1-Math.abs(i%2-1)),[o,s,c]=i<1?[r,a,0]:i<2?[a,r,0]:i<3?[0,r,a]:i<4?[0,a,r]:i<5?[a,0,r]:[r,0,a],l=n-r/2,d=g=>Math.round((g+l)*255).toString(16).padStart(2,"0");return`#${d(o)}${d(s)}${d(c)}`}function Hr(t,e,n){let r=o=>t.every(s=>{let c=yn(o,s);return c==null||c>=Br}),i=o=>{let s=Ge(o,"#12151d"),c=Ge(o,"#ffffff");return(s??0)>=3||(c??0)>=3},a=e.find(o=>r(o)&&i(o));if(a)return a;for(let o=0;o<360;o+=12)for(let s of[.52,.44,.6]){let c=Ur(o,.62,s);if(r(c)&&i(c))return c}return n}function pt(t,e){let n=ke.find(i=>i.objectType===e).creationWord;return`${t.replace(/\s*[–-]\s*(Tables|Booths|Standing|Seats)$/i,"").trim()||t.trim()} \u2013 ${n}`}function Vr(t){let e=new Map;for(let n of G(t))for(let r of n.objects){let i=ke.find(o=>o.objectType===r.type);if(!i)continue;let a=new Set;if(r.type==="row"||r.type==="table")for(let o of Re(r).keys())a.add(o);else"categoryKey"in r&&r.categoryKey&&a.add(r.categoryKey);for(let o of a){let s=e.get(o)??new Set;s.add(i.objectType),e.set(o,s)}}return e}function Jr(t,e,n,r){let i=n,a=Vr(t),o=g=>{let h=a.get(g);return!h||h.size===0||h.size===1&&h.has(i)},s=t.categories.find(g=>g.key===e);if(s&&o(s.key))return s.key;if(!s){let g=t.categories.find(h=>{let f=a.get(h.key);return f?.size===1&&f.has(i)});if(g)return g.key}let c=s;if(!c)return Sn(t,n,void 0,r);let l=pt(c.label,n),d=t.categories.find(g=>g.label.toLowerCase()===l.toLowerCase()&&o(g.key));return d?d.key:Sn(t,n,c,r)}function Sn(t,e,n,r){let i=ke.find(b=>b.objectType===e),a=e==="gaArea"?"General Admission":i.creationWord,o=n?pt(n.label,e):a,s=r.palette??Kr,c=t.categories.map(b=>b.color),l=r.suggestColor?.(c.map(b=>b.toLowerCase()))??vn(c,t.categories.length),d=Hr(c,zr(e,s),l),g=new Set(t.categories.map(b=>b.label.toLowerCase())),h=o;for(let b=2;g.has(h.toLowerCase());b+=1)h=`${o} ${b}`;let f=Cn(t,{label:h,color:d,...n?.price!==void 0?{price:n.price}:{},...n?.tiers?.length?{tiers:n.tiers}:{},idFactory:r.idFactory});return t.categories=f.categories,f.category.key}function qr(t,e){let n=new Set;for(let r of G(t))for(let i of r.objects)"categoryKey"in i&&i.categoryKey===e&&n.add(i.id),(i.type==="row"||i.type==="table")&&i.overrides?.some(a=>a.categoryKey===e)&&n.add(i.id);return[...n]}function Xr(t,e){let n=t.categories.find(a=>a.key===e.categoryKey);if(!n)throw new u("category_not_found",`Unknown chart category: ${e.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:e.categoryKey});if(t.categories.length<=1)throw new u("invalid_operation","A chart must retain at least one category");let r=qr(t,e.categoryKey);if(r.length)throw new u("category_in_use",`Category ${e.categoryKey} is still assigned to chart inventory`,{categoryKey:e.categoryKey,objectIds:r});if(n.referenceCategorySource)throw new u("reference_category_protected",`Reference-backed category ${e.categoryKey} cannot be deleted through a generic catalog operation`,{categoryKey:e.categoryKey});let i=ye(t.categories.filter(a=>a.key!==e.categoryKey));return t.categories=i,{changed:!0,categoryKey:e.categoryKey,categories:i}}var Yr=["background","seatLabelColor","rowLabelColor","selectionColor","decorFill","textColor","accent","accentInk"],Pn=.7,On=1.6;function Qr(t,e){let n=e.patch;if(!Object.keys(n).length)throw new u("invalid_operation","At least one theme field is required");let r=JSON.stringify(t.theme??null),i={...t.theme??{}};for(let a of Yr){let o=n[a];o===null?delete i[a]:o!==void 0&&(i[a]=L(o,`Theme ${a}`))}if(n.fontFamily===null)delete i.fontFamily;else if(n.fontFamily!==void 0){let a=n.fontFamily.normalize("NFKC").trim();if(!a||a.length>120)throw new u("invalid_operation","Theme fontFamily must contain 1 to 120 characters");i.fontFamily=a}if(n.seatScale===null)delete i.seatScale;else if(n.seatScale!==void 0){if(!Number.isFinite(n.seatScale)||n.seatScale<Pn||n.seatScale>On)throw new u("invalid_operation",`Theme seatScale must be from ${Pn} to ${On}`);i.seatScale=n.seatScale}if(n.logoUrl===null)delete i.logoUrl;else if(n.logoUrl!==void 0){let a=n.logoUrl.trim();if(!/^(https:\/\/|data:image\/)/.test(a)||a.length>2e6)throw new u("invalid_operation","Theme logoUrl must be an https or data:image reference");i.logoUrl=a}if(n.brandName===null)delete i.brandName;else if(n.brandName!==void 0){let a=n.brandName.normalize("NFKC").trim();if(!a||a.length>80)throw new u("invalid_operation","Theme brandName must contain 1 to 80 characters");i.brandName=a}return n.hideBadge===null||n.hideBadge===!1?delete i.hideBadge:n.hideBadge===!0&&(i.hideBadge=!0),t.theme=Object.keys(i).length?i:void 0,{changed:JSON.stringify(t.theme??null)!==r,theme:t.theme??null}}function Zr(t,e){let n=e.url===null?null:e.url.trim();if(n!==null&&(!/^(https:\/\/|data:image\/)/.test(n)||n.length>2e6))throw new u("invalid_operation","View-from-seat photo must be an https or data:image reference");let r=n??void 0;if(e.floorId!==void 0){let s=t.floors?.find(g=>g.id===e.floorId);if(!s)throw new u("invalid_operation",`Unknown floor: ${e.floorId}`);let c=(s.viewFromSeatUrl??void 0)===r,l=r?e.metadata===null?void 0:e.metadata??(c?s.viewFromSeatMeta:void 0):void 0,d=!c||JSON.stringify(s.viewFromSeatMeta??null)!==JSON.stringify(l??null);return s.viewFromSeatUrl=r,s.viewFromSeatMeta=l,{changed:d,scope:"floor",floorId:e.floorId,url:s.viewFromSeatUrl??null}}let i=(t.viewFromSeatUrl??void 0)===r,a=r?e.metadata===null?void 0:e.metadata??(i?t.viewFromSeatMeta:void 0):void 0,o=!i||JSON.stringify(t.viewFromSeatMeta??null)!==JSON.stringify(a??null);return t.viewFromSeatUrl=r,t.viewFromSeatMeta=a,{changed:o,scope:"venue",url:t.viewFromSeatUrl??null}}function Wr(t,e){let n=Oe(t,e.floorId),r=$t(n),i=e.placement==="auto"||e.placement==null?"rear":e.placement,a=96;return i==="front"?{x:r.x+r.width/2,y:r.y-a-e.height/2}:i==="left"?{x:r.x-a-e.width/2,y:r.y+r.height/2}:i==="right"?{x:r.x+r.width+a+e.width/2,y:r.y+r.height/2}:{x:r.x+r.width/2,y:r.y+r.height+a+e.height/2}}function Ke(t,e){k(t,e.categoryKey);let n=(...d)=>d.every(Number.isFinite);if(!n(e.center.x,e.center.y,e.innerRadius,e.rowGap,e.startAngle,e.endAngle,e.seatPitch))throw new u("invalid_operation","Arc/Fan geometry values must be finite");if(!Number.isInteger(e.rowCount)||e.rowCount<1||e.rowCount>100)throw new u("invalid_operation","Arc/Fan rowCount must be an integer from 1 to 100");if(e.innerRadius<40||e.innerRadius>2e4||e.rowGap<12||e.rowGap>500)throw new u("invalid_operation","Arc/Fan radius must be 40\u201320000 and row gap 12\u2013500");let r=e.endAngle-e.startAngle;if(Math.abs(r)<5||Math.abs(r)>320)throw new u("invalid_operation","Arc/Fan sweep must be from 5\xB0 to 320\xB0");if(e.seatPitch<14||e.seatPitch>80)throw new u("invalid_operation","Arc/Fan seat pitch must be from 14 to 80 chart units");let i=e.fit??"seat-pitch";if(i==="fixed-count"&&(!Number.isInteger(e.seatsPerRow)||e.seatsPerRow<2||e.seatsPerRow>300))throw new u("invalid_operation","Fixed Arc/Fan rows require seatsPerRow from 2 to 300");let a=e.taperDegrees??0,o=e.skewDegrees??0;if(!n(a,o)||Math.abs(a)>120||Math.abs(o)>180)throw new u("invalid_operation","Arc/Fan taper must be within \xB1120\xB0 and skew within \xB1180\xB0");let s={left:e.aisleGaps?.left??0,center:e.aisleGaps?.center??0,right:e.aisleGaps?.right??0};if(!n(s.left,s.center,s.right)||Object.values(s).some(d=>d<0||d>200))throw new u("invalid_operation","Arc/Fan aisle widths must be from 0 to 200 chart units");let l=C(t,e.floorId).objects.filter(d=>d.type==="row").length;return{...e,fit:i,facing:e.facing??"inward",taperDegrees:a,skewDegrees:o,aisleGaps:s,rowLabelStart:e.rowLabelStart??l,seatLabelStart:e.seatLabelStart??1}}function ei(t,e,n){let r=n*X;return{x:t.x+e*Math.sin(r),y:t.y+e*Math.cos(r)}}function ti(t,e,n,r){let i=Math.abs(r-n)*X,a=[["left",.25],["center",.5],["right",.75]].flatMap(([l,d])=>{let g=t.aisleGaps[l];if(!g)return[];let h=g/e/i/2;return[[Math.max(0,d-h),Math.min(1,d+h)]]}).sort((l,d)=>l[0]-d[0]),o=[];for(let l of a){let d=o[o.length-1];d&&l[0]<=d[1]?d[1]=Math.max(d[1],l[1]):o.push([...l])}let s=[],c=0;for(let l of o)l[0]-c>1e-6&&s.push([c,l[0]]),c=Math.max(c,l[1]);return 1-c>1e-6&&s.push([c,1]),s.filter(([l,d])=>e*i*(d-l)>=t.seatPitch*.75)}function ni(t,e){let n=t.length*2;if(e<n)throw new u("invalid_operation",`Fixed seat count must be at least ${n} for ${t.length} aisle-separated row segments`);let r=e-n,i=t.reduce((c,l)=>c+l,0),a=t.map(c=>r*c/i),o=a.map(c=>2+Math.floor(c)),s=e-o.reduce((c,l)=>c+l,0);return a.map((c,l)=>({index:l,fraction:c-Math.floor(c)})).sort((c,l)=>l.fraction-c.fraction||c.index-l.index).forEach(({index:c})=>{s-- >0&&o[c]++}),o}function $e(t,e,n){let r=[];for(let i=0;i<t.rowCount;i++){let a=t.rowCount===1?0:i/(t.rowCount-1),o=t.innerRadius+i*t.rowGap,s=Math.sign(t.endAngle-t.startAngle)||1,c=t.startAngle+s*t.taperDegrees*a+t.skewDegrees*a,l=t.endAngle-s*t.taperDegrees*a+t.skewDegrees*a;if(Math.sign(l-c)!==Math.sign(t.endAngle-t.startAngle)||Math.abs(l-c)<5)throw new u("invalid_operation",`Arc/Fan taper collapses row ${i+1} below a 5\xB0 sweep`);let d=ti(t,o,c,l);if(!d.length)throw new u("invalid_operation",`Arc/Fan aisles leave no usable span in row ${i+1}`);t.facing==="outward"&&(d=d.slice().reverse());let g=d.map(([b,y])=>o*Math.abs(l-c)*X*(y-b)),h=t.fit==="fixed-count"?ni(g,t.seatsPerRow):g.map(b=>Math.max(2,Math.round(b/t.seatPitch)+1)),f=t.seatLabelStart;d.forEach(([b,y],x)=>{let v=c+(l-c)*b,p=c+(l-c)*y;t.facing==="outward"&&([v,p]=[p,v]);let m=h[x];if(m>300)throw new u("invalid_operation","An Arc/Fan row segment cannot exceed 300 seats");let w=Math.abs(p-v)*X/(m-1),S=2*o*Math.sin(w/2),I={type:"row",id:n(i,x),label:B(t.rowLabelStart+i),origin:ei(t.center,o,v),rotation:-v,curve:p-v,seatCount:m,seatSpacing:S,categoryKey:t.categoryKey,seatLabelStart:f,arcFanGeneration:{kind:"arc-fan-v1",groupId:e,center:{...t.center},innerRadius:t.innerRadius,rowCount:t.rowCount,rowGap:t.rowGap,startAngle:t.startAngle,endAngle:t.endAngle,seatPitch:t.seatPitch,fit:t.fit,...t.seatsPerRow!=null?{seatsPerRow:t.seatsPerRow}:{},facing:t.facing,taperDegrees:t.taperDegrees,skewDegrees:t.skewDegrees,aisleGaps:{...t.aisleGaps},rowLabelStart:t.rowLabelStart,seatLabelStart:t.seatLabelStart,rowIndex:i,segmentIndex:x}};r.push(I),f+=m})}return r}function mt(t,e){let n=Ke(t,e),r=C(t,e.floorId),i=$e(n,"preview-arc-fan",(c,l)=>`preview-fan-${c}-${l}`),a=i.map(c=>c.seatSpacing),o=Math.max(...a.map(c=>Math.abs(c-n.seatPitch))),s=[];return o>n.seatPitch*.12&&s.push(`Seat fitting deviates from the requested pitch by up to ${o.toFixed(1)} chart units`),i.length>n.rowCount*3&&s.push("Three aisles split each logical row into four separately editable segments"),{floorId:r.floorId,rows:i,logicalRowCount:n.rowCount,rowSegmentCount:i.length,totalSeats:i.reduce((c,l)=>c+l.seatCount,0),innerRadius:n.innerRadius,outerRadius:n.innerRadius+(n.rowCount-1)*n.rowGap,minSeatSpacing:Math.min(...a),maxSeatSpacing:Math.max(...a),maxPitchDeviation:o,aisleCount:Object.values(n.aisleGaps).filter(c=>c>0).length,warnings:s}}function oi(t,e){let n=Ke(t,e),r=C(t,e.floorId),i=new Set,a=_(t,"fan",e.idFactory,i),o=$e(n,a,()=>_(t,"r",e.idFactory,i)),s=mt(t,e),c=null,l=e.sectionLabel?.normalize("NFKC").trim(),d=null;if(l){if(l.length>80)throw new u("invalid_operation","Arc/Fan section label must contain at most 80 characters");let g=Z(o);g&&(c=_(t,"sec",e.idFactory,i),d={type:"section",id:c,label:l,outline:g,arcFanGroupId:a})}return r.objects.push(...o,...d?[d]:[]),{floorId:r.floorId,rowIds:o.map(g=>g.id),sectionId:c,groupId:a,logicalRowCount:s.logicalRowCount,rowSegmentCount:s.rowSegmentCount,totalSeats:s.totalSeats,innerRadius:s.innerRadius,outerRadius:s.outerRadius,minSeatSpacing:s.minSeatSpacing,maxSeatSpacing:s.maxSeatSpacing,maxPitchDeviation:s.maxPitchDeviation,aisleCount:s.aisleCount,warnings:s.warnings}}function Mn(t,e){let n=C(t,e.floorId),r=n.objects.filter(g=>g.type==="row"&&g.arcFanGeneration?.groupId===e.groupId);if(!r.length)throw new u("object_not_found",`Unknown Arc/Fan group: ${e.groupId}`,{groupId:e.groupId});let i=r[0].arcFanGeneration,a=g=>{let h=g.arcFanGeneration;return JSON.stringify({center:h.center,innerRadius:h.innerRadius,rowCount:h.rowCount,rowGap:h.rowGap,startAngle:h.startAngle,endAngle:h.endAngle,seatPitch:h.seatPitch,fit:h.fit,seatsPerRow:h.seatsPerRow,facing:h.facing,taperDegrees:h.taperDegrees,skewDegrees:h.skewDegrees,aisleGaps:h.aisleGaps,rowLabelStart:h.rowLabelStart,seatLabelStart:h.seatLabelStart})};if(r.some(g=>a(g)!==a(r[0])))throw new u("invalid_operation","Arc/Fan group provenance no longer agrees across all row segments",{groupId:e.groupId});let o=n.objects.find(g=>g.type==="section"&&g.arcFanGroupId===e.groupId),s={floorId:n.floorId,center:{...i.center},innerRadius:i.innerRadius,rowCount:i.rowCount,rowGap:i.rowGap,startAngle:i.startAngle,endAngle:i.endAngle,seatPitch:i.seatPitch,fit:i.fit,seatsPerRow:i.seatsPerRow,facing:i.facing,taperDegrees:i.taperDegrees,skewDegrees:i.skewDegrees,aisleGaps:{...i.aisleGaps},categoryKey:r[0].categoryKey,rowLabelStart:i.rowLabelStart,seatLabelStart:i.seatLabelStart,sectionLabel:o?.label},c=Ke(t,s),l=new Set($e(c,e.groupId,(g,h)=>`${g}:${h}`).map(g=>`${g.arcFanGeneration.rowIndex}:${g.arcFanGeneration.segmentIndex}`)),d=new Set(r.map(g=>`${g.arcFanGeneration.rowIndex}:${g.arcFanGeneration.segmentIndex}`));if(l.size!==d.size||[...l].some(g=>!d.has(g)))throw new u("invalid_operation","Arc/Fan group is incomplete and cannot be regenerated safely",{groupId:e.groupId});return s}function ri(t,e){Mn(t,{floorId:e.floorId,groupId:e.groupId});let n=Ke(t,e),r=C(t,e.floorId),i=r.objects.filter(y=>y.type==="row"&&y.arcFanGeneration?.groupId===e.groupId),a=r.objects.find(y=>y.type==="section"&&y.arcFanGroupId===e.groupId),o=new Map(i.map(y=>[`${y.arcFanGeneration.rowIndex}:${y.arcFanGeneration.segmentIndex}`,y.id])),s=new Set,c=$e(n,e.groupId,(y,x)=>o.get(`${y}:${x}`)??_(t,"r",e.idFactory,s)),l=mt(t,e),d=e.sectionLabel?.normalize("NFKC").trim(),g=null;if(d){if(d.length>80)throw new u("invalid_operation","Arc/Fan section label must contain at most 80 characters");let y=Z(c);y&&(g={type:"section",id:a?.id??_(t,"sec",e.idFactory,s),label:d,outline:y,arcFanGroupId:e.groupId})}let h=new Set([...i.map(y=>y.id),...a?[a.id]:[]]),f=Math.min(...r.objects.map((y,x)=>h.has(y.id)?x:1/0)),b=r.objects.filter(y=>!h.has(y.id));return b.splice(Number.isFinite(f)?f:b.length,0,...c,...g?[g]:[]),r.objects.splice(0,r.objects.length,...b),{floorId:r.floorId,rowIds:c.map(y=>y.id),sectionId:g?.id??null,groupId:e.groupId,logicalRowCount:l.logicalRowCount,rowSegmentCount:l.rowSegmentCount,totalSeats:l.totalSeats,innerRadius:l.innerRadius,outerRadius:l.outerRadius,minSeatSpacing:l.minSeatSpacing,maxSeatSpacing:l.maxSeatSpacing,maxPitchDeviation:l.maxPitchDeviation,aisleCount:l.aisleCount,warnings:l.warnings}}function ii(t){let e=new Set(H(t).filter(r=>r.type==="row"||r.type==="table"||r.type==="booth").map(r=>r.label).filter(r=>typeof r=="string")),n=0;return()=>{for(;e.has(B(n));)n+=1;let r=B(n);return e.add(r),n+=1,r}}function An(t){return JSON.stringify(["row-block-v1",t.style,t.origin.x,t.origin.y,t.rotation,t.rowCount,t.seatsPerRow,t.rowGap,t.seatSpacing,t.curve])}function ai(t,e){if(k(t,e.categoryKey),!Number.isInteger(e.rowCount)||e.rowCount<1||e.rowCount>100)throw new u("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(e.seatsPerRow)||e.seatsPerRow<1||e.seatsPerRow>300)throw new u("invalid_operation","seatsPerRow must be an integer from 1 to 300");let n=e.rowGap??28,r=e.seatSpacing??24;if(!Number.isFinite(n)||n<=0||!Number.isFinite(r)||r<=0)throw new u("invalid_operation","Row and seat spacing must be positive finite values");if(e.rotation!==void 0&&!Number.isFinite(e.rotation))throw new u("invalid_operation","rotation must be a finite number of degrees");let i=C(t,e.floorId),a=new Set,o=ii(t),s=ut(e.rotation??0),c=e.curve??0,l=e.style,d=l?_(t,"rowblock",e.idFactory,a):void 0,g=l?An({style:l,origin:e.origin,rotation:s,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,rowGap:n,seatSpacing:r,curve:c}):void 0,h={x:Math.cos(s*q),y:Math.sin(s*q)},f={x:-h.y,y:h.x},b=Array.from({length:e.rowCount},(v,p)=>{let m=l==="intertwined"&&p%2===1?r/2:0,w={type:"row",id:_(t,"r",e.idFactory,a),label:o(),origin:{x:e.origin.x+f.x*p*n+h.x*m,y:e.origin.y+f.y*p*n+h.y*m},rotation:s,curve:c,seatCount:e.seatsPerRow,seatSpacing:r,categoryKey:e.categoryKey};return l&&d&&g&&(w.rowBlockGeneration={kind:"row-block-v1",groupId:d,style:l,rowIndex:p,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,origin:{...e.origin},rotation:s,rowGap:n,seatSpacing:r,curve:c,signature:g}),w});i.objects.push(...b);let y=null,x=e.sectionLabel?.trim();if(x){let v=Z(b);if(v){let p={type:"section",id:_(t,"sec",e.idFactory,a),label:x,outline:v};i.objects.push(p),y=p.id}}return{floorId:i.floorId,rowIds:b.map(v=>v.id),sectionId:y,createdIds:[...b.map(v=>v.id),...y?[y]:[]]}}function _n(t,e){let n=new Set(H(t).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(i=>typeof i=="string")),r=1;return()=>{for(;n.has(`${e}${r}`);)r+=1;let i=`${e}${r}`;return n.add(i),r+=1,i}}function si(t,e){let n=new Set(H(t).filter(i=>i.type==="gaArea").map(i=>i.label));if(!n.has(e))return e;let r=2;for(;n.has(`${e} ${r}`);)r+=1;return`${e} ${r}`}var ci=456;function jn(t){let e=Math.sqrt(Math.max(1,t)*ci);return{width:Math.round(e*1.027),height:Math.round(e/1.027)}}function li(t,e){if(k(t,e.categoryKey),!Number.isInteger(e.capacity)||e.capacity<1)throw new u("invalid_operation","capacity must be a positive integer");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new u("invalid_operation","GA area center must be finite");let n=C(t,e.floorId),r=new Set,{width:i,height:a}=jn(e.capacity),o=si(t,(e.label??"General Admission").trim()||"General Admission"),s={type:"gaArea",id:_(t,"ga",e.idFactory,r),label:o,...e.displayLabel?.trim()?{displayLabel:e.displayLabel.trim()}:{},points:[{x:e.center.x-i/2,y:e.center.y-a/2},{x:e.center.x+i/2,y:e.center.y-a/2},{x:e.center.x+i/2,y:e.center.y+a/2},{x:e.center.x-i/2,y:e.center.y+a/2}],capacity:e.capacity,categoryKey:e.categoryKey};return n.objects.push(s),{floorId:n.floorId,gaAreaId:s.id,label:o,createdIds:[s.id]}}function di(t,e){if(k(t,e.categoryKey),!Number.isInteger(e.tableRows)||e.tableRows<1||e.tableRows>20||!Number.isInteger(e.tableColumns)||e.tableColumns<1||e.tableColumns>20)throw new u("invalid_operation","tableRows and tableColumns must be integers from 1 to 20");if(!Number.isInteger(e.seatsPerTable)||e.seatsPerTable<1||e.seatsPerTable>20)throw new u("invalid_operation","seatsPerTable must be an integer from 1 to 20");let n=e.gapX??155,r=e.gapY??150;if(!Number.isFinite(n)||n<80||!Number.isFinite(r)||r<80)throw new u("invalid_operation","Table spacing must be at least 80 chart units");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new u("invalid_operation","Table array center must be finite");let i=C(t,e.floorId),a=new Set,o=_n(t,"T"),s=[];for(let c=0;c<e.tableRows;c+=1)for(let l=0;l<e.tableColumns;l+=1)s.push({type:"table",id:_(t,"t",e.idFactory,a),label:o(),center:{x:e.center.x+(l-(e.tableColumns-1)/2)*n,y:e.center.y+(c-(e.tableRows-1)/2)*r},rotation:0,categoryKey:e.categoryKey,seatCount:e.seatsPerTable,...e.shape==="round"?{shape:"round",radius:46}:{shape:"rect",sides:["top","bottom"],width:120,height:58}});return i.objects.push(...s),{floorId:i.floorId,tableIds:s.map(c=>c.id),createdIds:s.map(c=>c.id)}}function ui(t,e){if(k(t,e.categoryKey),!Number.isInteger(e.boothRows)||e.boothRows<1||e.boothRows>30||!Number.isInteger(e.boothColumns)||e.boothColumns<1||e.boothColumns>30)throw new u("invalid_operation","boothRows and boothColumns must be integers from 1 to 30");let n=e.gapX??88,r=e.gapY??82;if(!Number.isFinite(n)||n<62||!Number.isFinite(r)||r<52)throw new u("invalid_operation","Booth spacing must clear the 62\xD752 booth footprint");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new u("invalid_operation","Booth array center must be finite");let i=C(t,e.floorId),a=new Set,o=_n(t,"B"),s=[];for(let c=0;c<e.boothRows;c+=1)for(let l=0;l<e.boothColumns;l+=1)s.push({type:"booth",id:_(t,"booth",e.idFactory,a),label:o(),center:{x:e.center.x+(l-(e.boothColumns-1)/2)*n,y:e.center.y+(c-(e.boothRows-1)/2)*r},width:62,height:52,rotation:0,categoryKey:e.categoryKey});return i.objects.push(...s),{floorId:i.floorId,boothIds:s.map(c=>c.id),createdIds:s.map(c=>c.id)}}function fi(t,e){let n=C(t,e.floorId),r=[...new Set(e.rowIds)];if(r.length<2||r.length>64)throw new u("invalid_operation","A segmented row requires 2 to 64 ordered component rows");if(e.boundaries.length!==r.length-1||e.boundaries.some(h=>h!=="continuous"&&h!=="break"))throw new u("invalid_operation","Declare one continuous or break boundary between every pair of row components");let i=r.map(h=>n.objects.find(f=>f.type==="row"&&f.id===h)),a=r.filter((h,f)=>!i[f]);if(a.length)throw new u("object_not_found","One or more segmented-row components do not exist on the selected floor",{rowIds:a});let o=i,s=o.filter(h=>h.segmentedRow);if(s.length)throw new u("invalid_operation","Ungroup existing segmented rows before combining their components again",{rowIds:s.map(h=>h.id)});let c=(e.displayLabel??o[0].displayLabel??o[0].label).normalize("NFKC").trim();if(!c||c.length>80)throw new u("invalid_operation","Segmented-row display label must contain 1 to 80 characters");let l=new Set(n.objects.flatMap(h=>h.type==="row"?[h.segmentedRow?.groupId,h.rowBlockGeneration?.groupId].filter(f=>!!f):[])),d="";for(let h=0;h<100;h+=1){let f=e.idFactory("rowgroup");if(f&&!l.has(f)){d=f;break}}if(!d)throw new u("id_generation_failed","Unable to allocate a segmented-row group id");let g=o[0];return o.forEach((h,f)=>{h.segmentedRow={kind:"segmented-row-v1",groupId:d,componentIndex:f,componentCount:o.length,boundaryBefore:f===0?"start":e.boundaries[f-1],displayLabel:c,...g.displayType?{displayType:g.displayType}:{},...g.labelPresentation?{labelPresentation:structuredClone(g.labelPresentation)}:{},...g.viewFromSeatUrl?{viewFromSeatUrl:g.viewFromSeatUrl}:{},...g.viewFromSeatMeta?{viewFromSeatMeta:structuredClone(g.viewFromSeatMeta)}:{},...g.confidenceEvidence?{confidenceEvidence:structuredClone(g.confidenceEvidence)}:{}}}),{floorId:n.floorId,groupId:d,rowIds:r,changed:!0}}function gi(t,e){let n=C(t,e.floorId),r=e.groupId?n.objects.find(s=>s.type==="row"&&s.segmentedRow?.groupId===e.groupId):n.objects.find(s=>s.type==="row"&&s.id===e.rowId),i=e.groupId??r?.segmentedRow?.groupId;if(!i)throw new u("object_not_found","The segmented row does not exist on the selected floor");let a=n.objects.filter(s=>s.type==="row"&&s.segmentedRow?.groupId===i);if(!a.length)throw new u("object_not_found","The segmented row does not exist on the selected floor");let o=a.sort((s,c)=>s.segmentedRow.componentIndex-c.segmentedRow.componentIndex).map(s=>s.id);for(let s of a)delete s.segmentedRow;return{floorId:n.floorId,groupId:i,rowIds:o,changed:!0}}function hi(t,e){let n=C(t,e.floorId),r=n.objects.filter(o=>o.type==="row"&&o.segmentedRow?.groupId===e.groupId).sort((o,s)=>o.segmentedRow.componentIndex-s.segmentedRow.componentIndex);if(r.length<2)throw new u("object_not_found","The segmented row is incomplete or missing on the selected floor");if(e.boundaries&&(e.boundaries.length!==r.length-1||e.boundaries.some(o=>o!=="continuous"&&o!=="break")))throw new u("invalid_operation","Declare one continuous or break boundary between every pair of row components");let i=e.displayLabel?.normalize("NFKC").trim();if(i!==void 0&&(!i||i.length>80))throw new u("invalid_operation","Segmented-row display label must contain 1 to 80 characters");let a=JSON.stringify(r.map(o=>o.segmentedRow));return r.forEach((o,s)=>{let c=o.segmentedRow,l=c.viewFromSeatUrl;i!==void 0&&(c.displayLabel=i),e.boundaries&&s>0&&(c.boundaryBefore=e.boundaries[s-1]),e.smoothing!==void 0&&(c.smoothing=e.smoothing||void 0),e.viewFromSeatUrl===null?delete c.viewFromSeatUrl:e.viewFromSeatUrl!==void 0&&(c.viewFromSeatUrl=e.viewFromSeatUrl),!c.viewFromSeatUrl||e.viewFromSeatMeta===null?delete c.viewFromSeatMeta:e.viewFromSeatMeta!==void 0?c.viewFromSeatMeta=structuredClone(e.viewFromSeatMeta):e.viewFromSeatUrl!==void 0&&c.viewFromSeatUrl!==l&&delete c.viewFromSeatMeta}),{floorId:n.floorId,groupId:e.groupId,rowIds:r.map(o=>o.id),changed:JSON.stringify(r.map(o=>o.segmentedRow))!==a}}function bi(t,e){let n=C(t,e.floorId),r=n.objects.filter(O=>O.type==="row"&&O.rowBlockGeneration?.groupId===e.groupId).sort((O,$)=>O.rowBlockGeneration.rowIndex-$.rowBlockGeneration.rowIndex),i=r[0]?.rowBlockGeneration;if(!i||r.length!==i.rowCount||r.some((O,$)=>{let j=O.rowBlockGeneration;return j.kind!=="row-block-v1"||j.rowIndex!==$||j.signature!==i.signature||JSON.stringify(j)!==JSON.stringify({...i,rowIndex:$})}))throw new u("invalid_operation","This row block was edited manually or is incomplete; repair or recreate it before regeneration",{groupId:e.groupId});let a=JSON.stringify(r),o=e.style??i.style,s=e.rowCount??i.rowCount,c=e.seatsPerRow??i.seatsPerRow,l=e.rowGap??i.rowGap,d=e.seatSpacing??i.seatSpacing,g=e.curve??i.curve,h=Number.isFinite(e.rotation??i.rotation)?ut(e.rotation??i.rotation):e.rotation??i.rotation,f=e.origin?{...e.origin}:{...i.origin};if(!Number.isInteger(s)||s<1||s>100)throw new u("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(c)||c<1||c>300)throw new u("invalid_operation","seatsPerRow must be an integer from 1 to 300");if(![l,d].every(O=>Number.isFinite(O)&&O>0)||!Number.isFinite(g)||!Number.isFinite(h)||!Number.isFinite(f.x)||!Number.isFinite(f.y))throw new u("invalid_operation","Row-block geometry must use positive spacing and finite origin, rotation, and curve values");let b=An({style:o,origin:f,rotation:h,rowCount:s,seatsPerRow:c,rowGap:l,seatSpacing:d,curve:g}),y={x:Math.cos(h*q),y:Math.sin(h*q)},x={x:-y.y,y:y.x},v=new Map(r.map(O=>[O.rowBlockGeneration.rowIndex,O])),p=new Set,m=new Set(n.objects.filter(O=>O.type==="row").filter(O=>!r.includes(O)).map(O=>O.label)),w=n.objects.filter(O=>O.type==="row").length,S=()=>{for(;m.has(B(w));)w+=1;let O=B(w);return m.add(O),w+=1,O},I=[],M=[];for(let O=0;O<s;O+=1){let $=o==="intertwined"&&O%2===1?d/2:0,j=v.get(O);j||(j={type:"row",id:_(t,"r",e.idFactory,p),label:S(),origin:{...f},rotation:h,curve:g,seatCount:c,seatSpacing:d,categoryKey:r[0].categoryKey},M.push(j.id)),j.origin={x:f.x+x.x*O*l+y.x*$,y:f.y+x.y*O*l+y.y*$},j.rotation=h,j.curve=g,j.seatCount=c,j.seatSpacing=d,delete j.path,delete j.arcFanGeneration,j.overrides&&(j.overrides=j.overrides.filter(Ve=>Ve.index<c),j.overrides.length||delete j.overrides),j.rowBlockGeneration={kind:"row-block-v1",groupId:e.groupId,style:o,rowIndex:O,rowCount:s,seatsPerRow:c,origin:{...f},rotation:h,rowGap:l,seatSpacing:d,curve:g,signature:b},I.push(j)}let D=r.slice(s).map(O=>O.id),T=Math.min(...r.map(O=>n.objects.indexOf(O))),U=new Set(r.map(O=>O.id)),K=n.objects.filter(O=>!U.has(O.id));return K.splice(T,0,...I),n.objects.splice(0,n.objects.length,...K),{floorId:n.floorId,groupId:e.groupId,rowIds:I.map(O=>O.id),createdRowIds:M,removedRowIds:D,changed:a!==JSON.stringify(I)||M.length>0||D.length>0}}var pi=300,mi=40;function yi(t){let e=new Set(H(t).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(i=>typeof i=="string")),n=0,r=()=>{for(;e.has(B(n));)n+=1;let i=B(n);return n+=1,i};return i=>{let a=i.normalize("NFKC").replace(/\s+/g," ").trim().slice(0,mi).trim(),o=0;return()=>{for(;a&&o<4096;o+=1){let c=`${a}-${B(o)}`;if(!e.has(c))return e.add(c),o+=1,c}let s=r();return e.add(s),s}}}function wi(t,e){return t.filter(n=>(n.type==="row"||n.type==="table"||n.type==="booth"||n.type==="gaArea")&&!(n.type==="row"&&n.referenceScan?.assetId===e))}function xi(t,e,n,r,i){let a=t.sectionId?e.find(c=>c.type==="section"&&c.id===t.sectionId):void 0;if(a){let c=wi(e,n).filter(l=>N(F(l),a.outline,a.holes));if(c.length)return{skip:{sectionId:a.id,name:t.name,reason:"section_not_empty",objectIds:c.map(l=>l.id)},rows:[],seats:0}}let o=[],s=0;for(let c of t.rows){let l=Math.min(pi,Math.max(1,Math.round(c.seatCount)));if(!Number.isFinite(l)||l<1)continue;let d=c.end.x-c.start.x,g=c.end.y-c.start.y,h=Math.hypot(d,g),f=l>1&&h>0?h/(l-1):r>0?r:24;if(!Number.isFinite(f)||f<=0)continue;let b=h>0?Math.atan2(g,d)*180/Math.PI:0;o.push({label:i(),origin:{x:c.start.x,y:c.start.y},rotation:b,seatCount:l,seatSpacing:f}),s+=l}return{skip:null,rows:o,seats:s}}function Si(t,e,n){k(t,n.categoryKey);let r=C(t,n.floorId),i=e.assetId,a=[],o=r.objects.filter(f=>f.type==="row"&&f.referenceScan?.assetId===i?(a.push(f.id),!1):!0);r.objects.splice(0,r.objects.length,...o);let s=[],c=[],l=[],d=new Set,g=0,h=yi(t);for(let f of e.sections){let b=xi(f,r.objects,i,e.seatPitch,h(f.name));if(b.skip){c.push(b.skip);continue}let y=b.rows.map(x=>({type:"row",id:_(t,"r",n.idFactory,d),referenceScan:{assetId:i},label:x.label,origin:x.origin,rotation:x.rotation,curve:0,seatCount:x.seatCount,seatSpacing:x.seatSpacing,categoryKey:n.categoryKey}));r.objects.push(...y);for(let x of y)l.push(x.id);s.push({sectionId:f.sectionId,name:f.name,seats:b.seats,rows:y.length}),g+=b.seats}return{floorId:r.floorId,assetId:i,createdRowIds:l,removedRowIds:a,totalSeats:g,perSection:s,skipped:c}}function kn(t,e){let n=C(t,e.floorId),r=[...new Set(e.objectIds)];if(!r.length)throw new u("invalid_operation","Select at least one table or booth to repeat");let i=r.map(f=>n.objects.find(b=>(b.type==="table"||b.type==="booth")&&b.id===f)),a=r.filter((f,b)=>!i[b]);if(a.length)throw new u("object_not_found","One or more grid sources do not exist on the selected floor",{objectIds:a});let o=i[0].type;if(i.some(f=>f.type!==o))throw new u("invalid_operation","A grid array must contain only tables or only booths");for(let[f,b,y]of[["rows",e.rows,30],["columns",e.columns,30]])if(!Number.isInteger(b)||b<1||b>y)throw new u("invalid_operation",`${f} must be a whole number from 1 to ${y}`);for(let[f,b]of[["stepX",e.stepX],["stepY",e.stepY]])if(!Number.isFinite(b)||b<30||b>2e3)throw new u("invalid_operation",`${f} must be from 30 to 2000 chart units`);let s=e.rows*e.columns;if(s<2)throw new u("invalid_operation","Choose at least two grid cells");let c=r.length*(s-1);if(c>5e3)throw new u("invalid_operation","A grid array can add at most 5000 objects");let l=i.reduce((f,b)=>f+(b.type==="table"?b.seatCount:1),0),g=(t.floors?.length?t.floors.flatMap(f=>f.objects):t.objects).reduce((f,b)=>f+(b.type==="row"||b.type==="table"?b.seatCount:b.type==="gaArea"?Math.max(0,Math.floor(b.capacity)):b.type==="booth"?1:0),0),h=l*(s-1);if(g+h>ce)throw new u("invalid_operation",`Grid inventory would exceed the ${ce} unit event limit`);return{target:n,sources:i,preview:{floorId:n.floorId,kind:o,sourceIds:r,sourceCount:r.length,cells:s,createdCount:c,addedInventory:h,resultingInventory:g+h,provenanceRemovedCount:i.filter(f=>!!f.referenceInventorySource).length*(s-1)}}}function Ii(t,e){return kn(t,e).preview}function vi(t,e){let{target:n,sources:r,preview:i}=kn(t,e),a=new Set,o=new Set((t.floors?.length?t.floors.flatMap(d=>d.objects):t.objects).flatMap(d=>"label"in d&&d.label?[d.label]:[])),s=[],c=(d,g)=>{let h=Math.max(2,g),f=y=>{let x=`-${y}`;return`${d.slice(0,Math.max(1,80-x.length))}${x}`},b=f(h);for(;o.has(b);)b=f(++h);return o.add(b),b},l=1;for(let d=0;d<e.rows;d++)for(let g=0;g<e.columns;g++)if(!(d===0&&g===0)){l+=1;for(let h of r){let f=structuredClone(h);f.id=_(t,f.type,e.idFactory,a),f.label=c(h.label,l),f.center={x:h.center.x+g*e.stepX,y:h.center.y+d*e.stepY},delete f.referenceInventorySource,s.push(f)}}return n.objects.push(...s),{...i,createdIds:s.map(d=>d.id)}}function Ci(t,e){let n=t?{...t}:{};return e.size===null?delete n.size:e.size!==void 0&&(n.size=e.size),e.color===null?delete n.color:e.color!==void 0&&(n.color=L(e.color,"Seat label color")),n.size===void 0&&n.color===void 0?void 0:n}var Pi=new Set(fe.map(t=>t.key));function we(t){return`${t.rowId}:${t.index}`}function Oi(t){let e=t.lastIndexOf(":"),n=e>0?t.slice(0,e):"",r=e>0?Number(t.slice(e+1)):Number.NaN;if(!n||!Number.isInteger(r)||r<0)throw new u("invalid_operation",`Invalid stable seat id: ${t}`,{seatId:t});return{rowId:n,index:r}}function Mi(t){if(t.label||delete t.label,t.displayLabel||delete t.displayLabel,t.dx||delete t.dx,t.dy||delete t.dy,t.skip||delete t.skip,t.categoryKey||delete t.categoryKey,me(t.glyph)||delete t.glyph,t.accessible&&!t.accessibility?.length&&(t.accessibility=["wheelchair"]),delete t.accessible,t.wheelchairSpaceType&&!t.accessibility?.includes("wheelchair")&&(t.accessibility=["wheelchair",...t.accessibility??[]]),t.accessibility?.length||delete t.accessibility,t.commercial){let e=t.commercial.note?.normalize("NFKC").trim(),n={};typeof t.commercial.restrictedView=="boolean"&&(n.restrictedView=t.commercial.restrictedView),typeof t.commercial.obstructedView=="boolean"&&(n.obstructedView=t.commercial.obstructedView),typeof t.commercial.premium=="boolean"&&(n.premium=t.commercial.premium),e&&(n.note=e),Object.keys(n).length?t.commercial=n:delete t.commercial}t.viewFromSeatUrl||(delete t.viewFromSeatUrl,delete t.viewFromSeatMeta),t.labelStyle&&t.labelStyle.size===void 0&&t.labelStyle.color===void 0&&delete t.labelStyle}function Ai(t){return Object.keys(t).every(e=>e==="index")}function Rn(t,e,n){if(!n.length)throw new u("invalid_operation","At least one seat is required");let r=C(t,e),i=[],a=new Set,o=new Map;for(let s of n){let c=we(s);if(a.has(c))continue;a.add(c);let l=r.objects.find(d=>(d.type==="row"||d.type==="table")&&d.id===s.rowId);if(!l)throw new u("object_not_found",`Unknown row or table for seat: ${c}`,{seatId:c,objectId:s.rowId});if(l.type==="table"&&(l.bookAsWhole||l.variableOccupancy))throw new u("invalid_operation",`Table "${l.label}" is sold as one grouped unit; switch it to individual-chair selling before editing chairs`,{seatId:c,tableId:l.id});if(!Number.isInteger(s.index)||s.index<0||s.index>=l.seatCount)throw new u("invalid_operation",l.type==="row"?`Seat index is outside row bounds: ${c}`:`Chair index is outside table bounds: ${c}`,{seatId:c,objectId:s.rowId,index:s.index,seatCount:l.seatCount});i.push({rowId:s.rowId,index:s.index}),o.set(l.id,l)}return{floorId:r.floorId,refs:i,owners:o}}function _i(t,e){let n=Rn(t,e.floorId,e.seats),r=Object.keys(e.patch);if(!r.length&&e.labelPrefix===void 0&&e.displayLabelPrefix===void 0)throw new u("invalid_operation","At least one seat override field is required");if(e.labelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(e.patch,"label"))throw new u("invalid_operation","Use either label or labelPrefix, not both");if(e.displayLabelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(e.patch,"displayLabel"))throw new u("invalid_operation","Use either displayLabel or displayLabelPrefix, not both");if(n.refs.length>1&&e.patch.label!=null)throw new u("invalid_operation","A literal label can only be assigned to one seat; use labelPrefix for a bulk sequence");if(n.refs.length>1&&e.patch.displayLabel!=null)throw new u("invalid_operation","A literal display label can only be assigned to one seat; use displayLabelPrefix for a bulk sequence");if(e.patch.categoryKey&&k(t,e.patch.categoryKey),e.patch.glyph!=null&&!me(e.patch.glyph))throw new u("invalid_operation","Unknown seat glyph",{glyph:e.patch.glyph});if(e.patch.accessibility){let a=e.patch.accessibility.filter(o=>!Pi.has(o));if(a.length)throw new u("invalid_operation","Unknown accessibility type",{accessibility:a})}if(e.patch.wheelchairSpaceType!==void 0&&e.patch.wheelchairSpaceType!==null&&e.patch.wheelchairSpaceType!=="seat-present"&&e.patch.wheelchairSpaceType!=="no-seat")throw new u("invalid_operation","wheelchairSpaceType must be seat-present, no-seat, or null");if(e.patch.wheelchairSpaceType&&e.patch.skip===!0)throw new u("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory");for(let a of n.refs){let o=n.owners.get(a.rowId)?.overrides?.find(l=>l.index===a.index),s=e.patch.wheelchairSpaceType===null?void 0:e.patch.wheelchairSpaceType??o?.wheelchairSpaceType,c=e.patch.skip===null?!1:e.patch.skip??o?.skip??!1;if(s&&c)throw new u("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory",{seatId:we(a)})}if(e.patch.commercial?.note&&e.patch.commercial.note.normalize("NFKC").trim().length>160)throw new u("invalid_operation","Commercial note supports at most 160 characters");for(let a of["dx","dy"]){let o=e.patch[a];if(o!=null&&!Number.isFinite(o))throw new u("invalid_operation",`${a} must be finite`,{[a]:o})}e.patch.labelStyle!=null&&se(e.patch.labelStyle,"Seat");let i=!1;return n.refs.forEach((a,o)=>{let s=n.owners.get(a.rowId),c=JSON.stringify(s.overrides??[]),l=s.overrides??(s.overrides=[]),d=l.find(h=>h.index===a.index);d||(d={index:a.index},l.push(d));let g=d.viewFromSeatUrl;for(let h of r){let f=e.patch[h];if(h==="wheelchairSpaceType"&&f==null)delete d.wheelchairSpaceType,d.accessibility&&(d.accessibility=d.accessibility.filter(b=>b!=="wheelchair"),d.accessibility.length||delete d.accessibility),delete d.accessible;else if(f==null)delete d[h];else if(h==="accessibility")d.accessibility=[...new Set(f)],delete d.accessible;else if(h==="commercial")d.commercial={...d.commercial,...f};else if(h==="labelStyle"){let b=Ci(d.labelStyle,f);b?d.labelStyle=b:delete d.labelStyle}else Object.assign(d,{[h]:f})}e.patch.viewFromSeatMeta===void 0&&e.patch.viewFromSeatUrl!==void 0&&d.viewFromSeatUrl!==g&&delete d.viewFromSeatMeta,e.labelPrefix!==void 0&&(d.label=`${e.labelPrefix}${o+1}`),e.displayLabelPrefix!==void 0&&(d.displayLabel=`${e.displayLabelPrefix}${o+1}`),Mi(d),Ai(d)&&(s.overrides=l.filter(h=>h!==d)),s.overrides?.length||delete s.overrides,JSON.stringify(s.overrides??[])!==c&&(i=!0)}),{floorId:n.floorId,changed:i,seatIds:n.refs.map(we)}}function ji(t,e){let n=Rn(t,e.floorId,e.seats),r=!1;for(let[i,a]of n.owners){if(!a.overrides?.length)continue;let o=new Set(n.refs.filter(c=>c.rowId===i).map(c=>c.index)),s=a.overrides.filter(c=>!o.has(c.index));s.length!==a.overrides.length&&(r=!0),a.overrides=s,a.overrides.length||delete a.overrides}return{floorId:n.floorId,changed:r,seatIds:n.refs.map(we)}}function ki(t,e){let n=C(t,e.floorId),r=[...new Set(e.rowIds)],i=r.map(p=>n.objects.find(m=>m.type==="row"&&m.id===p)),a=r.filter((p,m)=>!i[m]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});if(e.patch.categoryKey!==void 0&&k(t,e.patch.categoryKey),e.patch.seatCount!==void 0&&(!Number.isInteger(e.patch.seatCount)||e.patch.seatCount<1||e.patch.seatCount>300))throw new u("invalid_operation","seatCount must be an integer from 1 to 300");if(e.patch.seatNumbering!==void 0){let p=e.patch.seatNumbering,m=["decimal","odd","even","updown","updown-descending","roman","letters-upper","letters-lower"];if(p.scheme!==void 0&&!m.includes(p.scheme))throw new u("invalid_operation",`Unknown seat numbering scheme: ${p.scheme}. Expected one of ${m.join(", ")}.`);if(p.prefix!==void 0&&(typeof p.prefix!="string"||p.prefix.length>8))throw new u("invalid_operation","Seat label prefix must be a string of at most 8 characters");if(p.endAt!==void 0&&p.endAt!==null&&(!Number.isInteger(p.endAt)||p.endAt<0||p.endAt>9999))throw new u("invalid_operation","Seat numbering endAt must be an integer from 0 to 9999")}let{labelStyle:o,labelPosition:s,labelRotation:c,labelStyleShape:l,displayLabel:d,displayType:g,...h}=e.patch,f=d===void 0?{}:{displayLabel:d},b=ae(f,"Row"),y=g===void 0?void 0:it(g,"Row");if(o!==void 0&&se(o,"Row"),s!==void 0&&!["start","end","both","none"].includes(s))throw new u("invalid_operation","Row labelPosition must be one of start, end, both, none");if(c!=null&&(!Number.isFinite(c)||c<-180||c>180))throw new u("invalid_operation","Row labelRotation must be a number from -180 to 180");if(l!==void 0&&l!=="plain"&&l!=="pill")throw new u("invalid_operation","Row labelStyleShape must be plain or pill");h.labelPresentation!==void 0&&Ae(h.labelPresentation,"Row");let x=p=>JSON.stringify({origin:p.origin,rotation:p.rotation,curve:p.curve,seatCount:p.seatCount,seatSpacing:p.seatSpacing,path:p.path??null}),v=!1;for(let p of i){let m=JSON.stringify(p),w=x(p),S=e.preserveCenterOnSeatCountChange&&e.patch.seatCount!==void 0?F(p):null;if(Object.assign(p,structuredClone(h)),p.overrides&&e.patch.seatCount!==void 0&&(p.overrides=p.overrides.filter(I=>I.index<p.seatCount),p.overrides.length||(p.overrides=void 0)),S){let I=F(p);p.origin={x:p.origin.x+S.x-I.x,y:p.origin.y+S.y-I.y}}if(JSON.stringify(p)!==m&&(v=!0),x(p)!==w&&(delete p.arcFanGeneration,delete p.rowBlockGeneration),o!==void 0){let I=JSON.stringify(p.labelPresentation??null),M=_e(p.labelPresentation,o);M?p.labelPresentation=M:delete p.labelPresentation,JSON.stringify(p.labelPresentation??null)!==I&&(v=!0)}if(s!==void 0){let I=JSON.stringify(p.labelPresentation??null),M=p.labelPresentation?structuredClone(p.labelPresentation):{};M.positionPreset=s,M.visible=s!=="none",delete M.position,p.labelPresentation=M,JSON.stringify(p.labelPresentation??null)!==I&&(v=!0)}if(c!==void 0||l!==void 0){let I=JSON.stringify(p.labelPresentation??null),M=p.labelPresentation?structuredClone(p.labelPresentation):{};c===null?delete M.rotation:c!==void 0&&(M.rotation=c),l!==void 0&&(M.style=l),p.labelPresentation=M,JSON.stringify(p.labelPresentation??null)!==I&&(v=!0)}if(y!==void 0){let I=p.displayType;y?p.displayType=y:delete p.displayType,p.displayType!==I&&(v=!0)}if(d!==void 0){let I=p.displayLabel;b?delete p.displayLabel:p.displayLabel=f.displayLabel,p.displayLabel!==I&&(v=!0)}}return{floorId:n.floorId,changed:v,rowIds:r}}var Ri=3;function ze(t){return(t%360+360)%360}function Fi(t){let e=t.rotation*q;return{x:Math.cos(e),y:Math.sin(e)}}function Li(t,e){let n=Math.abs(ze(t-e));return n>180&&(n=360-n),n}function le(t,e,n){return(t.x-e.x)*n.x+(t.y-e.y)*n.y}function Fn(t){let e=0,n=0;for(let i of t){let a=2*i.rotation*q;e+=Math.cos(a),n+=Math.sin(a)}let r=(e===0&&n===0?0:Math.atan2(n,e))/2;return{x:Math.cos(r),y:Math.sin(r)}}function Ti(t,e,n){if(t.origin={x:t.origin.x+e,y:t.origin.y+n},t.path){let r=i=>({x:i.x+e,y:i.y+n});t.path={start:r(t.path.start),control1:r(t.path.control1),control2:r(t.path.control2),end:r(t.path.end)}}}function Ln(t,e){let n=Fn(t),r={x:-n.y,y:n.x},i=F(t[0]),a=t.map(c=>({row:c,coord:le(F(c),i,r)})).sort((c,l)=>c.coord-l.coord),o=a[0].coord,s=!1;return a.forEach((c,l)=>{let d=o+l*e-c.coord;Math.abs(d)>1e-6&&(Ti(c.row,r.x*d,r.y*d),delete c.row.arcFanGeneration,delete c.row.rowBlockGeneration,s=!0)}),s}function Ei(t,e){let n={x:-e.y,y:e.x},r=F(t[0]),i=t.map(o=>le(F(o),r,n)).sort((o,s)=>o-s);if(i.length<2)return 28;let a=(i[i.length-1]-i[0])/(i.length-1);return a>.5?a:28}function Ni(t){if(t.seatCount<2){t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration;return}let e=ue(t),n=e[0],r=e[e.length-1],i=r.x-n.x,a=r.y-n.y,o=Math.hypot(i,a);t.path&&(t.origin={...n},t.seatSpacing=Math.max(1,o/(t.seatCount-1))),o>1e-6&&(t.rotation=ze(Math.atan2(a,i)/q)),t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration}function Di(t,e){let n=new Set(t.filter(r=>r.type==="row").map(r=>r.label));for(let r=2;r<1e4;r++){let i=`${e}${r}`.slice(0,80);if(!n.has(i))return i}return`${e}-${Date.now().toString(36)}`}function Gi(t,e){let n=C(t,e.floorId),r=[...new Set(e.rowIds)];if(r.length<2)throw new u("invalid_operation","Select at least two rows to merge");let i=r.map(S=>n.objects.find(I=>I.type==="row"&&I.id===S)),a=r.filter((S,I)=>!i[I]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let o=i,s=o.filter(S=>S.path||S.curve!==0);if(s.length)throw new u("invalid_operation","Only straight rows can be merged \u2014 straighten the rows first, then merge.",{rowIds:s.map(S=>S.id)});let c=o[0],l=o.find(S=>Li(S.rotation,c.rotation)>Ri);if(l)throw new u("invalid_operation","Rows must be parallel to merge \u2014 they point in different directions.",{rowIds:[c.id,l.id]});let d=Fi(c),g={x:-d.y,y:d.x},h=Math.max(8,c.seatSpacing*.6),f=o.find(S=>Math.abs(le(S.origin,c.origin,g))>h);if(f){let S=Math.round(Math.abs(le(f.origin,c.origin,g)));throw new u("invalid_operation",`Rows must lie on the same line to merge \u2014 a selected row is offset ${S} units from the first.`,{rowIds:[c.id,f.id]})}let b=o.slice().sort((S,I)=>le(S.origin,c.origin,d)-le(I.origin,c.origin,d)),y=b.reduce((S,I)=>S+I.seatCount,0);if(y>300)throw new u("invalid_operation",`A merged row would have ${y} seats, over the 300-seat row limit. Merge fewer rows.`);let x=b[0],v=[],p=0;for(let S of b){if(S.overrides)for(let I of S.overrides)v.push({...structuredClone(I),index:I.index+p});p+=S.seatCount}x.seatCount=y,x.curve=0,delete x.path,v.length?x.overrides=v:delete x.overrides,delete x.arcFanGeneration,delete x.rowBlockGeneration;let m=b.slice(1).map(S=>S.id),w=new Set(m);for(let S=n.objects.length-1;S>=0;S--)w.has(n.objects[S].id)&&n.objects.splice(S,1);return{floorId:n.floorId,changed:!0,rowId:x.id,removedRowIds:m,seatCount:y}}function Ki(t,e){let n=C(t,e.floorId),r=n.objects.find(f=>f.type==="row"&&f.id===e.rowId);if(!r)throw new u("object_not_found","The row id does not exist on the selected floor",{rowIds:[e.rowId]});if(r.path)throw new u("invalid_operation","Cannot split a free-form curved row \u2014 straighten it first, then split.",{rowIds:[r.id]});let i=r.seatCount,a=e.index;if(!Number.isInteger(a)||a<1||a>i-1)throw new u("invalid_operation",`Split position must be a whole number from 1 to ${i-1} (the seat where the second row begins)`);let o=ue(r),s=i>1?r.curve/(i-1):0,c=i-a,l={type:"row",id:_(t,"r",e.idFactory,new Set),label:Di(n.objects,r.label),origin:{...o[a]},rotation:ze(r.rotation-s*a),curve:s*(c-1),seatCount:c,seatSpacing:r.seatSpacing,categoryKey:r.categoryKey};if(r.seatNumbering&&(l.seatNumbering=structuredClone(r.seatNumbering)),r.seatLabelStart!=null&&(l.seatLabelStart=r.seatLabelStart),r.commercial&&(l.commercial=structuredClone(r.commercial)),r.viewFromSeatUrl&&(l.viewFromSeatUrl=r.viewFromSeatUrl),r.viewFromSeatMeta&&(l.viewFromSeatMeta=structuredClone(r.viewFromSeatMeta)),r.confidenceEvidence&&(l.confidenceEvidence=structuredClone(r.confidenceEvidence)),r.labelPresentation){let f=structuredClone(r.labelPresentation);delete f.position,l.labelPresentation=f}let d=[],g=[];if(r.overrides)for(let f of r.overrides)f.index<a?d.push(structuredClone(f)):g.push({...structuredClone(f),index:f.index-a});r.seatCount=a,r.curve=s*(a-1),d.length?r.overrides=d:delete r.overrides,delete r.arcFanGeneration,delete r.rowBlockGeneration,g.length&&(l.overrides=g);let h=n.objects.indexOf(r);return n.objects.splice(h+1,0,l),{floorId:n.floorId,changed:!0,rowId:r.id,newRowId:l.id,firstSeatCount:a,secondSeatCount:c,newLabel:l.label}}function $i(t,e){let n=C(t,e.floorId),r=[...new Set(e.rowIds)];if(r.length<2)throw new u("invalid_operation","Select at least two rows to set row spacing");if(!Number.isFinite(e.gap)||e.gap<=0||e.gap>4e3)throw new u("invalid_operation","Row spacing must be a positive value up to 4000 chart units");let i=r.map(s=>n.objects.find(c=>c.type==="row"&&c.id===s)),a=r.filter((s,c)=>!i[c]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let o=Ln(i,e.gap);return{floorId:n.floorId,changed:o,rowIds:r,gap:e.gap}}function zi(t,e){let n=C(t,e.floorId),r=[...new Set(e.rowIds)];if(r.length<2)throw new u("invalid_operation","Select at least two rows to straighten and space evenly");let i=r.map(h=>n.objects.find(f=>f.type==="row"&&f.id===h)),a=r.filter((h,f)=>!i[f]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let o=i,s=()=>JSON.stringify(o.map(h=>[h.origin,h.rotation,h.curve,h.path??null,h.seatSpacing])),c=s();for(let h of o)Ni(h);let l=Fn(o),d=ze(Math.atan2(l.y,l.x)/q);for(let h of o)h.rotation=d;let g=Ei(o,l);return Ln(o,g),{floorId:n.floorId,changed:s()!==c,rowIds:r,gap:g}}var Ue=ro(require("polygon-clipping"),1),Tn=100,En=512,yt=8192,Un=64,Nn=1e7,R=1e-7;function Hn(t,e){return Math.abs(t.x-e.x)<=R&&Math.abs(t.y-e.y)<=R}function Vn(t){let e=t.map(n=>({x:n.x,y:n.y}));for(;e.length>1&&Hn(e[0],e[e.length-1]);)e.pop();return e}function xe(t,e,n){let r=J(e,n,t);return Math.abs(r)>R?!1:t.x>=Math.min(e.x,n.x)-R&&t.x<=Math.max(e.x,n.x)+R&&t.y>=Math.min(e.y,n.y)-R&&t.y<=Math.max(e.y,n.y)+R}function Jn(t,e,n,r){let i=J(t,e,n),a=J(t,e,r),o=J(n,r,t),s=J(n,r,e);return(i>R&&a<-R||i<-R&&a>R)&&(o>R&&s<-R||o<-R&&s>R)?!0:Math.abs(i)<=R&&xe(n,t,e)||Math.abs(a)<=R&&xe(r,t,e)||Math.abs(o)<=R&&xe(t,n,r)||Math.abs(s)<=R&&xe(e,n,r)}function Bi(t){for(let e=0;e<t.length;e+=1){let n=(e+1)%t.length;for(let r=e+1;r<t.length;r+=1){let i=(r+1)%t.length;if(!(e===r||n===r||i===e)&&Jn(t[e],t[n],t[r],t[i]))return!0}}return!1}function Dn(t,e){return t.some((n,r)=>e.some((i,a)=>Jn(n,t[(r+1)%t.length],i,e[(a+1)%e.length])))}function wt(t,e){return!e.some((n,r)=>xe(t,n,e[(r+1)%e.length]))&&N(t,e,void 0)}function He(t,e,n){let r=Vn(t);if(r.length<3||r.length>En||r.some((i,a)=>!Number.isFinite(i.x)||!Number.isFinite(i.y)||Math.abs(i.x)>Nn||Math.abs(i.y)>Nn||Hn(i,r[(a+1)%r.length]))||Math.abs(de(r))<=R||Bi(r))throw new u("invalid_operation",`GA area ${n} has an invalid or self-intersecting ${e}; Join Areas accepts 3\u2013${En} finite vertices per ring.`,{gaAreaId:n,ring:e});return r}function Ui(t){let e=He(t.points,"outline",t.id),n=t.holes??[];if(!Array.isArray(n)||n.length>Un)throw new u("invalid_operation",`GA area ${t.id} has too many cutouts to join`,{gaAreaId:t.id});let r=n.map(i=>He(i,"cutout",t.id));for(let i=0;i<r.length;i+=1){let a=r[i];if(!a.flatMap((s,c)=>{let l=a[(c+1)%a.length];return[s,{x:(s.x+l.x)/2,y:(s.y+l.y)/2}]}).every(s=>wt(s,e))||Dn(a,e))throw new u("invalid_operation",`GA area ${t.id} has a cutout outside its outline`,{gaAreaId:t.id,holeIndex:i});for(let s=i+1;s<r.length;s+=1)if(Dn(a,r[s])||wt(a[0],r[s])||wt(r[s][0],a))throw new u("invalid_operation",`GA area ${t.id} has overlapping cutouts`,{gaAreaId:t.id,holeIndex:i})}return{outer:e,holes:r}}function Be(t){return t.map(e=>[e.x,e.y])}function Gn(t){return Vn(t.map(([e,n])=>({x:e,y:n})))}function Kn(t){return Math.abs(t.reduce((e,n,r)=>{let i=t[(r+1)%t.length];return e+n[0]*i[1]-i[0]*n[1]},0))/2}function Hi(t){return t.reduce((e,n)=>e+(Kn(n[0]??[])-n.slice(1).reduce((r,i)=>r+Kn(i),0)),0)}function xt(t){if(t===void 0)return"undefined";if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(xt).join(",")}]`;let e=t;return`{${Object.keys(e).sort().map(n=>`${JSON.stringify(n)}:${xt(e[n])}`).join(",")}}`}function $n(t,e,n){let r=t[e];if(r===void 0)return null;let i=r.normalize("NFKC").trim();if(!i||i!==r||i.length>n)throw new u("invalid_operation",`GA area ${t.id} has an invalid ${e}; normalize it to 1\u2013${n} characters before joining.`,{gaAreaId:t.id,field:e});return i}function zn(t){return xt({categoryKey:t.categoryKey,displayLabel:$n(t,"displayLabel",80),displayType:$n(t,"displayType",24),referenceInventorySource:t.referenceInventorySource??null})}function Bn(t,e){let n=Math.min(...t.points.map(i=>i.y)),r=Math.min(...t.points.map(i=>i.x));return[n,r,e]}function Vi(t,e){return t[0]-e[0]||t[1]-e[1]||t[2]-e[2]}function qn(t,e){let n=C(t,e.floorId),r=[...new Set(e.gaAreaIds)];if(r.length<2)throw new u("invalid_operation","Select at least two GA areas to join");if(r.length>Tn)throw new u("invalid_operation",`Join Areas supports at most ${Tn} areas at once`);let i=r.map(P=>n.objects.find(A=>A.type==="gaArea"&&A.id===P)),a=r.filter((P,A)=>!i[A]);if(a.length)throw new u("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:a});let o=i;k(t,o[0].categoryKey);let s=zn(o[0]),c=o.find(P=>zn(P)!==s);if(c)throw new u("invalid_operation","GA areas must use the same category, displayed label, displayed type, and reference-inventory provenance before they can be joined.",{gaAreaIds:[o[0].id,c.id]});let l=he(t).objectToSection,d=l.get(o[0].id)??"__ungrouped__",g=o.find(P=>(l.get(P.id)??"__ungrouped__")!==d);if(g)throw new u("invalid_operation","GA areas must belong to the same buyer section before they can be joined.",{gaAreaIds:[o[0].id,g.id],sectionIds:[d,l.get(g.id)??"__ungrouped__"]});let h=o.reduce((P,A)=>{if(!Number.isInteger(A.capacity)||A.capacity<1||A.capacity>ee)throw new u("invalid_operation",`GA area ${A.id} has invalid capacity`,{gaAreaId:A.id});return P+A.capacity},0);if(h>ee)throw new u("invalid_operation",`Joined GA capacity would be ${h}, over the ${ee}-unit area limit`,{capacity:h});let f=H(t).reduce((P,A)=>P+W(A),0);if(f>ce)throw new u("invalid_operation",`Chart inventory exceeds the ${ce}-unit publication limit`,{inventory:f});let b=o.map(Ui),y=b.reduce((P,A)=>P+A.outer.length+A.holes.reduce((V,Y)=>V+Y.length,0),0);if(y>yt)throw new u("invalid_operation",`Join Areas supports at most ${yt} source vertices`,{vertexCount:y});let x;try{let P=b.map(Y=>[Be(Y.outer)]);if(x=Ue.default.union(P[0],...P.slice(1)),x.length!==1)throw new u("invalid_operation","Selected GA areas must overlap or share an edge. Disconnected or point-only contact cannot produce one sellable surface.",{surfaceCount:x.length});let A=b.flatMap(Y=>Y.holes.map(Je=>[Be(Je)]));A.length&&(x=Ue.default.difference(x,...A));let V=b.findIndex(Y=>{let Je=[Be(Y.outer),...Y.holes.map(Be)];return Hi(Ue.default.intersection(Je,x))<=R});if(V>=0)throw new u("invalid_operation",`GA area ${o[V].id} contributes no sellable surface after preserving every source cutout.`,{gaAreaId:o[V].id})}catch(P){throw P instanceof u?P:new u("invalid_operation","The selected GA boundaries could not be joined safely",{reason:P instanceof Error?P.message:"polygon_union_failed"})}if(x.length!==1||!x[0]?.length)throw new u("invalid_operation","Joining these boundaries would create disconnected sellable surfaces; adjust the outlines or cutouts first.",{surfaceCount:x.length});let v=Gn(x[0][0]),p=x[0].slice(1).map(Gn),m=v.length+p.reduce((P,A)=>P+A.length,0);if(p.length>Un||m>yt)throw new u("invalid_operation","The joined boundary is too complex to store safely",{holeCount:p.length,vertexCount:m});He(v,"outline",o[0].id),p.forEach(P=>He(P,"cutout",o[0].id));let w=new Map(n.objects.map((P,A)=>[P.id,A])),S=o.slice().sort((P,A)=>Vi(Bn(P,w.get(P.id)??Number.MAX_SAFE_INTEGER),Bn(A,w.get(A.id)??Number.MAX_SAFE_INTEGER))),I=S[0],M=structuredClone(t),D=C(M,n.floorId),T=D.objects.find(P=>P.type==="gaArea"&&P.id===I.id);T.points=structuredClone(v),p.length?T.holes=structuredClone(p):delete T.holes;let U=new Set(S.slice(1).map(P=>P.id));for(let P=D.objects.length-1;P>=0;P-=1)U.has(D.objects[P].id)&&D.objects.splice(P,1);let K=he(M).objectToSection.get(I.id)??"__ungrouped__";if(K!==d)throw new u("invalid_operation","The joined surface would change buyer-section ownership; adjust the GA or section boundaries first.",{gaAreaId:I.id,beforeSectionId:d,afterSectionId:K});let O=[],$=new Set;for(let P of S){if(!lt(P))throw new u("invalid_operation",`GA area ${P.id} has invalid inventory provenance and cannot be joined`,{gaAreaId:P.id});let A=te(P);if(A.length!==P.capacity||A.some(V=>$.has(V)))throw new u("invalid_operation","Selected GA areas contain duplicated or incomplete stable inventory identities",{gaAreaId:P.id});A.forEach(V=>$.add(V)),O.push(...Fe(P))}if(O.length>256)throw new u("invalid_operation","Joined inventory provenance would exceed 256 durable source ranges");let j=new Set(o.map(P=>P.id));for(let P of H(t).filter(A=>A.type==="gaArea"&&!j.has(A.id))){let A=te(P).find(V=>$.has(V));if(A)throw new u("invalid_operation","A stable GA inventory identity is already owned by another area",{label:A,gaAreaId:P.id})}let Ve=S.slice(1).map(P=>P.id);return{floorId:n.floorId,areaId:I.id,survivorLabel:I.label,removedAreaIds:Ve,sourceAreaCount:S.length,capacity:h,inventorySegmentCount:O.length,outerVertexCount:v.length,holeCount:p.length,sectionId:d,points:v,...p.length?{holes:p}:{},segments:O}}function Ji(t,e){let{segments:n,...r}=qn(t,e);return r}function qi(t,e){let n=qn(t,e),r=C(t,n.floorId),i=r.objects.find(c=>c.type==="gaArea"&&c.id===n.areaId);i.points=structuredClone(n.points),n.holes?.length?i.holes=structuredClone(n.holes):delete i.holes,i.capacity=n.capacity,i.inventorySegments=structuredClone(n.segments);let a=new Set(n.removedAreaIds);for(let c=r.objects.length-1;c>=0;c-=1)a.has(r.objects[c].id)&&r.objects.splice(c,1);let{segments:o,...s}=n;return{...s,changed:!0}}var Xn=[{key:"rect",label:"Flat stage",icon:"\u25AD",blurb:"Classic proscenium box."},{key:"rounded",label:"Rounded",icon:"\u25A2",blurb:"Softened corners."},{key:"arc",label:"Curved front",icon:"\u25D7",blurb:"Front edge bows toward the audience."},{key:"thrust",label:"Thrust (T)",icon:"\u22A4",blurb:"Central tongue projects into the crowd."},{key:"runway",label:"Runway",icon:"\u2337",blurb:"Long catwalk into the audience."},{key:"round",label:"In the round",icon:"\u25EF",blurb:"Central platform, audience all around."},{key:"pitch-football",label:"Football pitch",icon:"\u2B1B",blurb:"105 \xD7 68 m pitch with centre circle and penalty boxes."},{key:"rink-hockey",label:"Hockey rink",icon:"\u2B2D",blurb:"60 \xD7 30 m ice rink with blue lines and faceoff circles."},{key:"track-athletics",label:"Athletics track",icon:"\u2B2F",blurb:"400 m track: two straights, two semicircles, eight lanes."},{key:"oval-cricket",label:"Cricket oval",icon:"\u2B2E",blurb:"~150 \xD7 140 m oval with boundary rope and pitch strip."}];var Xi=Math.PI*2;function Yi(t,e,n,r,i,a){return{x:i+t*n-e*r,y:a+t*r+e*n}}function Yn(t){let{kind:e,cx:n,cy:r,width:i,height:a}=t,o=(t.rotation??0)*Math.PI/180,s=Math.cos(o),c=Math.sin(o),l=i/2,d=a/2,g=[],h=(f,b)=>{g.push({x:f,y:b})};switch(e){case"rect":{h(-l,-d),h(l,-d),h(l,d),h(-l,d);break}case"rounded":{let f=Math.min(i,a)*.18,b=5,y=(x,v,p)=>{for(let m=0;m<=b;m++){let w=p+m/b*(Math.PI/2);h(x+f*Math.cos(w),v+f*Math.sin(w))}};y(l-f,-d+f,-Math.PI/2),y(l-f,d-f,0),y(-l+f,d-f,Math.PI/2),y(-l+f,-d+f,Math.PI);break}case"arc":{let f=a*.45;h(-l,-d),h(l,-d);let b=24;for(let y=0;y<=b;y++){let x=y/b,v=l-x*i,p=d+f*(1-Math.pow(2*v/i,2));h(v,p)}break}case"thrust":{let f=i*.18,b=a*1.1;h(-l,-d),h(l,-d),h(l,d),h(f,d),h(f,d+b),h(-f,d+b),h(-f,d),h(-l,d);break}case"runway":{let f=i*.1,b=a*3;h(-l,-d),h(l,-d),h(l,d),h(f,d),h(f,d+b),h(-f,d+b),h(-f,d),h(-l,d);break}case"round":case"oval-cricket":{for(let b=0;b<40;b++){let y=b/40*Xi;h(l*Math.cos(y),d*Math.sin(y))}break}case"pitch-football":{h(-l,-d),h(l,-d),h(l,d),h(-l,d);break}case"rink-hockey":{for(let f of Qi(l,d,l*(8.5/60),d*(8.5/30)))h(f.x,f.y);break}case"track-athletics":{for(let f of Zi(l,d))h(f.x,f.y);break}}return g.map(f=>Yi(f.x,f.y,s,c,n,r))}function Qi(t,e,n,r){let i=[],o=(s,c,l)=>{for(let d=0;d<=8;d++){let g=l+d/8*(Math.PI/2);i.push({x:s+n*Math.cos(g),y:c+r*Math.sin(g)})}};return o(t-n,-e+r,-Math.PI/2),o(t-n,e-r,0),o(-t+n,e-r,Math.PI/2),o(-t+n,-e+r,Math.PI),i}function Zi(t,e){let n=Math.max(0,t-e),r=[],i=20;for(let a=0;a<=i;a++){let o=-Math.PI/2+a/i*Math.PI;r.push({x:n+e*Math.cos(o),y:e*Math.sin(o)})}for(let a=0;a<=i;a++){let o=Math.PI/2+a/i*Math.PI;r.push({x:-n+e*Math.cos(o),y:e*Math.sin(o)})}return r}function Wi(t,e){let n=C(t,e.floorId),r=[...new Set(e.shapeIds)];if(!r.length)throw new u("invalid_operation","At least one shape id is required");let i=r.map(l=>n.objects.find(d=>d.type==="shape"&&d.id===l)),a=r.filter((l,d)=>!i[d]);if(a.length)throw new u("object_not_found",`Unknown shape id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current shape ids.`,{shapeIds:a});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new u("invalid_operation","At least one shape change is required");if(o.label!==void 0){if(r.length!==1)throw new u("invalid_operation","label can be changed only for one shape at a time");if(o.label!==null){if(o.label=o.label.normalize("NFKC").trim(),!o.label)o.label=null;else if(o.label.length>80)throw new u("invalid_operation","Shape labels support at most 80 characters")}}if(o.fill!==void 0&&o.fill!==null&&(o.fill=L(o.fill,"Shape fill")),o.kind!==void 0&&!["rect","ellipse","polygon","line","polyline"].includes(o.kind))throw new u("invalid_operation","Shape kind must be rect, ellipse, polygon, line, or polyline");if(o.stroke!==void 0&&o.stroke!==null){if(!Number.isFinite(o.stroke.width)||o.stroke.width<.5||o.stroke.width>40)throw new u("invalid_operation","Shape stroke width must be from 0.5 to 40 chart units");o.stroke={color:L(o.stroke.color,"Shape stroke"),width:o.stroke.width}}if(o.cornerRadius!==void 0&&o.cornerRadius!==null&&(!Number.isFinite(o.cornerRadius)||o.cornerRadius<0||o.cornerRadius>5e3))throw new u("invalid_operation","Shape cornerRadius must be from 0 to 5000 chart units");if(o.opacity!==void 0&&o.opacity!==null&&(!Number.isFinite(o.opacity)||o.opacity<.1||o.opacity>1))throw new u("invalid_operation","Shape opacity must be from 0.1 to 1");if(o.heightM!==void 0&&o.heightM!==null&&(!Number.isFinite(o.heightM)||o.heightM<.05||o.heightM>50))throw new u("invalid_operation","Shape heightM must be from 0.05 to 50 metres");if(o.eventConfigurationIds!==void 0&&o.eventConfigurationIds!==null){let l=o.eventConfigurationIds.map(d=>d.normalize("NFKC").trim());if(!l.length||l.length>20||l.some(d=>!d||d.length>100)||new Set(l).size!==l.length)throw new u("invalid_operation","Shape event configurations must contain 1 to 20 unique ids");o.eventConfigurationIds=l}if(o.lineCap!==void 0&&o.lineCap!==null&&!hn.includes(o.lineCap))throw new u("invalid_operation","Shape lineCap must be butt, round, or square");if(o.lineJoin!==void 0&&o.lineJoin!==null&&!bn.includes(o.lineJoin))throw new u("invalid_operation","Shape lineJoin must be miter, round, or bevel");for(let[l,d]of[["startEnding",o.startEnding],["endEnding",o.endEnding]])if(d!=null&&!pn.includes(d))throw new u("invalid_operation",`Shape ${l} must be none or arrow`);if(o.lineCap!=null||o.lineJoin!=null||o.startEnding!=null||o.endEnding!=null){let l=i.filter(d=>!ht(o.kind??d.kind));if(l.length)throw new u("invalid_operation","Line caps, joins, and start/end decorations apply only to open line or polyline shapes",{shapeIds:l.map(d=>d.id)})}let c=!1;for(let l of i){let d=JSON.stringify(l);if(o.label===null?delete l.label:o.label!==void 0&&(l.label=o.label),o.fill===null?delete l.fill:o.fill!==void 0&&(l.fill=o.fill),o.kind!==void 0&&(l.kind=o.kind,ht(l.kind)||(delete l.lineCap,delete l.lineJoin,delete l.startEnding,delete l.endEnding)),o.stroke===null?delete l.stroke:o.stroke!==void 0&&(l.stroke={...o.stroke}),o.opacity===null?delete l.opacity:o.opacity!==void 0&&(l.opacity=o.opacity),o.heightM===null?delete l.heightM:o.heightM!==void 0&&(l.heightM=o.heightM),o.eventConfigurationIds===null?delete l.eventConfigurationIds:o.eventConfigurationIds!==void 0&&(l.eventConfigurationIds=[...o.eventConfigurationIds]),o.lineCap===null?delete l.lineCap:o.lineCap!==void 0&&(l.lineCap=o.lineCap),o.lineJoin===null?delete l.lineJoin:o.lineJoin!==void 0&&(l.lineJoin=o.lineJoin),o.startEnding===null?delete l.startEnding:o.startEnding!==void 0&&(l.startEnding=o.startEnding),o.endEnding===null?delete l.endEnding:o.endEnding!==void 0&&(l.endEnding=o.endEnding),o.cornerRadius===null)delete l.cornerRadius;else if(o.cornerRadius!==void 0){let g=Math.min(l.width??1/0,l.height??1/0),h=Number.isFinite(g)?g/2:o.cornerRadius;l.cornerRadius=l.kind==="rect"?Math.max(0,Math.min(o.cornerRadius,h)):o.cornerRadius}JSON.stringify(l)!==d&&(c=!0)}return{floorId:n.floorId,changed:c,shapeIds:r}}function Qn(t){if(t.x!=null&&t.y!=null&&t.width!=null&&t.height!=null){if(![t.x,t.y,t.width,t.height].every(Number.isFinite)||t.width<=0||t.height<=0)throw new u("invalid_operation",`Stage ${t.id} has an invalid stored base box`,{stageId:t.id});return{cx:t.x+t.width/2,cy:t.y+t.height/2,width:t.width,height:t.height}}let e=t.points??[];if(e.length<3||e.some(d=>!Number.isFinite(d.x)||!Number.isFinite(d.y)))throw new u("invalid_operation",`Stage ${t.id} has no valid geometry from which to derive its base box`,{stageId:t.id});let n=e.map(d=>d.x),r=e.map(d=>d.y),i=Math.min(...n),a=Math.max(...n),o=Math.min(...r),s=Math.max(...r),c=Math.max(1,a-i),l=Math.max(1,s-o);return{cx:i+c/2,cy:o+l/2,width:c,height:l}}function ea(t,e){let n=C(t,e.floorId);if(!e.updates.length)throw new u("invalid_operation","At least one shape resize is required");let r=e.updates.map(o=>o.shapeId);if(new Set(r).size!==r.length)throw new u("invalid_operation","Shape ids must be unique");let i=e.updates.map(o=>{if(![o.width,o.height].every(Number.isFinite)||o.width<8||o.height<8||o.width>1e4||o.height>1e4)throw new u("invalid_operation","Shape width and height must be between 8 and 10000 chart units",{shapeId:o.shapeId});let s=n.objects.find(l=>l.type==="shape"&&l.id===o.shapeId);if(!s)throw new u("object_not_found",`Unknown shape id: ${o.shapeId}`,{shapeId:o.shapeId});let c=s.role==="stage"?Qn(s):(s.kind==="rect"||s.kind==="ellipse")&&s.x!=null&&s.y!=null&&s.width!=null&&s.height!=null?{cx:s.x+s.width/2,cy:s.y+s.height/2,width:s.width,height:s.height}:(()=>{let l=s.points??[];if(l.length<3||l.some(x=>!Number.isFinite(x.x)||!Number.isFinite(x.y)))throw new u("invalid_operation",`Shape ${s.id} has no resizable geometry`,{shapeId:s.id});let d=l.map(x=>x.x),g=l.map(x=>x.y),h=Math.min(...d),f=Math.max(...d),b=Math.min(...g),y=Math.max(...g);return{cx:(h+f)/2,cy:(b+y)/2,width:Math.max(1,f-h),height:Math.max(1,y-b)}})();return{shape:s,update:o,box:c}}),a=!1;for(let{shape:o,update:s,box:c}of i)if(!(Math.abs(c.width-s.width)<1e-9&&Math.abs(c.height-s.height)<1e-9)){if(o.kind==="rect"||o.kind==="ellipse")o.x=c.cx-s.width/2,o.y=c.cy-s.height/2,o.width=s.width,o.height=s.height;else{let l=s.width/c.width,d=s.height/c.height;o.points=(o.points??[]).map(g=>({x:c.cx+(g.x-c.cx)*l,y:c.cy+(g.y-c.cy)*d})),(o.x!=null||o.y!=null||o.width!=null||o.height!=null||o.role==="stage")&&(o.x=c.cx-s.width/2,o.y=c.cy-s.height/2,o.width=s.width,o.height=s.height)}a=!0}return{floorId:n.floorId,changed:a,shapes:i.map(({shape:o,update:s})=>({id:o.id,width:s.width,height:s.height}))}}function ta(t,e){let n=C(t,e.floorId);if(!e.updates.length)throw new u("invalid_operation","At least one stage update is required");let r=e.updates.map(s=>s.stageId);if(new Set(r).size!==r.length)throw new u("invalid_operation","Stage ids must be unique");let i=new Set(Xn.map(s=>s.key)),a=e.updates.map(s=>{if(!i.has(s.stageKind))throw new u("invalid_operation",`Unknown stage kind: ${s.stageKind}`,{stageKind:s.stageKind});let c=n.objects.find(l=>l.type==="shape"&&l.id===s.stageId);if(!c)throw new u("object_not_found",`Unknown stage id: ${s.stageId}. Call get_chart to list current stage ids.`,{stageId:s.stageId});if(c.role!=="stage")throw new u("invalid_operation",`Shape ${s.stageId} is not tagged as a stage`,{stageId:s.stageId});return{shape:c,stageKind:s.stageKind,box:c.stageKind===s.stageKind?null:Qn(c)}}),o=!1;for(let s of a)s.box&&(s.shape.points=Yn({kind:s.stageKind,...s.box}),s.shape.kind="polygon",s.shape.stageKind=s.stageKind,o=!0);return{floorId:n.floorId,changed:o,stages:a.map(s=>({id:s.shape.id,stageKind:s.stageKind}))}}0&&(module.exports={COLORBLIND_SAFE_PALETTE,ChartOperationError,DEFAULT_FLOOR_HEIGHT_STEP_M,DEFAULT_SECTION_CORNER_SMOOTHING,MAX_FLOOR_BASE_HEIGHT_M,addArcFanRows,addBookableGridArray,addBoothArray,addChartCategory,addChartFloor,addChartZone,addGAArea,addRowBlock,addTableArray,applyPolygonHole,applyReferenceScanRows,applySectionCornerSmoothing,applySectionOutlineShaping,applySectionRowFit,arcFanInputForGroup,assignSectionInventoryCategory,automaticPlacementCenter,confirmReferenceCategoryOutputColor,convertGeneratedSectionToPolygon,countCoveredInventory,familyCategoryLabel,gaAreaFootprint,groupRowsAsSegmented,insertSeatingBlock,joinGAAreas,mergeRows,mirrorFirstFloor,parseSeatRefId,pickColorblindSafeCategoryColor,previewArcFanRows,previewBookableGridArray,previewGeneratedSectionPolygonConversion,previewJoinGAAreas,previewPolygonHole,previewRemovePolygonHole,previewRowCubicPath,previewSectionRowFit,reassignColorblindSafeCategoryColors,relabelChartRows,removeChartCategory,removeChartFloor,removeChartObjects,removeChartZone,removePolygonHole,renameChartFloor,reorderChartCategories,replaceArcFanRows,replaceRowBlock,resetSeatOverrides,resizeShapes,resolveCreationCategory,seatRefId,sectionInventorySelectionSummary,setRowBlockSpacing,splitRow,straightenAndSpaceRows,transformSectionBoundary,transformSectionBoundaryObject,ungroupSegmentedRow,updateBooths,updateCategoryDefinitions,updateChartFloorBaseHeight,updateChartTheme,updateChartZones,updateGAAreas,updateRowCubicPath,updateRows,updateSeatOverrides,updateSectionExactPath,updateSectionMetadata,updateSegmentedRow,updateShapes,updateStageKinds,updateTables,updateTextObjects,updateViewFromSeatFallback});
1
+ "use strict";var Zn=Object.create;var Se=Object.defineProperty;var Wn=Object.getOwnPropertyDescriptor;var eo=Object.getOwnPropertyNames;var to=Object.getPrototypeOf,no=Object.prototype.hasOwnProperty;var oo=(t,e)=>{for(var n in e)Se(t,n,{get:e[n],enumerable:!0})},St=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of eo(e))!no.call(t,i)&&i!==n&&Se(t,i,{get:()=>e[i],enumerable:!(r=Wn(e,i))||r.enumerable});return t};var ro=(t,e,n)=>(n=t!=null?Zn(to(t)):{},St(e||!t||!t.__esModule?Se(n,"default",{value:t,enumerable:!0}):n,t)),io=t=>St(Se({},"__esModule",{value:!0}),t);var na={};oo(na,{COLORBLIND_SAFE_PALETTE:()=>bt,ChartOperationError:()=>u,DEFAULT_FLOOR_HEIGHT_STEP_M:()=>ct,DEFAULT_SECTION_CORNER_SMOOTHING:()=>Ze,MAX_FLOOR_BASE_HEIGHT_M:()=>je,addArcFanRows:()=>oi,addBookableGridArray:()=>vi,addBoothArray:()=>ui,addChartCategory:()=>Cn,addChartFloor:()=>No,addChartZone:()=>$o,addGAArea:()=>li,addRowBlock:()=>ai,addTableArray:()=>di,applyPolygonHole:()=>Ir,applyReferenceScanRows:()=>Si,applySectionCornerSmoothing:()=>kr,applySectionOutlineShaping:()=>fn,applySectionRowFit:()=>xr,arcFanInputForGroup:()=>Mn,assignSectionInventoryCategory:()=>Pr,automaticPlacementCenter:()=>Wr,confirmReferenceCategoryOutputColor:()=>Gr,convertGeneratedSectionToPolygon:()=>Mr,countCoveredInventory:()=>Te,familyCategoryLabel:()=>pt,gaAreaFootprint:()=>jn,groupRowsAsSegmented:()=>fi,insertSeatingBlock:()=>br,joinGAAreas:()=>qi,mergeRows:()=>Gi,mirrorFirstFloor:()=>ge,parseSeatRefId:()=>Oi,pickColorblindSafeCategoryColor:()=>vn,previewArcFanRows:()=>mt,previewBookableGridArray:()=>Ii,previewGeneratedSectionPolygonConversion:()=>dn,previewJoinGAAreas:()=>Ji,previewPolygonHole:()=>Ne,previewRemovePolygonHole:()=>sn,previewRowCubicPath:()=>on,previewSectionRowFit:()=>rn,reassignColorblindSafeCategoryColors:()=>Dr,relabelChartRows:()=>hr,removeChartCategory:()=>Xr,removeChartFloor:()=>Ko,removeChartObjects:()=>fr,removeChartZone:()=>Bo,removePolygonHole:()=>vr,renameChartFloor:()=>Do,reorderChartCategories:()=>Tr,replaceArcFanRows:()=>ri,replaceRowBlock:()=>bi,resetSeatOverrides:()=>ji,resizeShapes:()=>ea,resolveCreationCategory:()=>Jr,seatRefId:()=>we,sectionInventorySelectionSummary:()=>ln,setRowBlockSpacing:()=>$i,splitRow:()=>Ki,straightenAndSpaceRows:()=>zi,transformSectionBoundary:()=>Ar,transformSectionBoundaryObject:()=>un,ungroupSegmentedRow:()=>gi,updateBooths:()=>dr,updateCategoryDefinitions:()=>In,updateChartFloorBaseHeight:()=>Go,updateChartTheme:()=>Yr,updateChartZones:()=>zo,updateGAAreas:()=>ur,updateRowCubicPath:()=>mr,updateRows:()=>ki,updateSeatOverrides:()=>_i,updateSectionExactPath:()=>_r,updateSectionMetadata:()=>Or,updateSegmentedRow:()=>hi,updateShapes:()=>Wi,updateStageKinds:()=>ta,updateTables:()=>lr,updateTextObjects:()=>gr,updateViewFromSeatFallback:()=>Zr});module.exports=io(na);var It=t=>Math.max(1,t.fontSize*.6+(t.letterSpacing??0));function ao(t,e){let n=t.text.split(/\r?\n/);if(!t.width)return Math.max(1,n.length);let r=Math.max(1,Math.floor(e/It(t))),i=0;for(let a of n){if(!a.length){i+=1;continue}let o=0;for(let s of a.split(/\s+/)){let c=s.length;o&&o+1+c<=r?o+=1+c:(i+=Math.max(1,Math.ceil(c/r)),o=c%r)}}return Math.max(1,i)}function vt(t){let e=t.background?.padding??0,n=t.text.split(/\r?\n/),r=Math.max(1,...n.map(s=>s.length))*It(t),i=t.width??r+e*2,a=Math.max(1,i-e*2),o=ao(t,a);return{width:i,height:o*t.fontSize*(t.lineHeight??1.2)+e*2,lineCount:o,padding:e}}var ia=Math.PI/180;function E(t,e){return Math.hypot(t.x-e.x,t.y-e.y)}function qe(t,e,n){return{x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n}}function Ct(t,e){let n=1-e,r=n*n*n,i=3*n*n*e,a=3*n*e*e,o=e*e*e;return{x:r*t.start.x+i*t.control1.x+a*t.control2.x+o*t.end.x,y:r*t.start.y+i*t.control1.y+a*t.control2.y+o*t.end.y}}function Ie(t,e,n=192){if(!Number.isInteger(e)||e<1)throw new Error("Path point count must be a positive integer");if(e===1)return[Ct(t,.5)];let r=Array.from({length:n+1},(c,l)=>Ct(t,l/n)),i=new Float64Array(r.length);for(let c=1;c<r.length;c+=1){let l=r[c].x-r[c-1].x,d=r[c].y-r[c-1].y;i[c]=i[c-1]+Math.hypot(l,d)}let a=i[i.length-1];if(a<=1e-9)return Array.from({length:e},()=>({...t.start}));let o=[],s=1;for(let c=0;c<e;c+=1){let l=a*c/(e-1);for(;s<i.length-1&&i[s]<l;)s+=1;let d=i[s-1],g=i[s],h=g===d?0:(l-d)/(g-d);o.push({x:r[s-1].x+(r[s].x-r[s-1].x)*h,y:r[s-1].y+(r[s].y-r[s-1].y)*h})}return o}function de(t){if(t.length<3)return 0;let e=0;for(let n=0,r=t.length-1;n<t.length;r=n++)e+=(t[r].x+t[n].x)*(t[r].y-t[n].y);return Math.abs(e)/2}function so(t,e,n){return Math.max(e,Math.min(n,t))}function co(t){return so(t,0,1)}function Pt(t){let e=co(t);return e*e*(3-2*e)}var oe=Math.PI*2;function re(t){return Number.isFinite(t.x)&&Number.isFinite(t.y)}function lo(t,e,n){let r=e-t;if(n){for(;r<0;)r+=oe;for(;r>=oe;)r-=oe}else{for(;r>0;)r-=oe;for(;r<=-oe;)r+=oe}return r}function ve(t){if(t.version!==1||t.closed!==!0||!re(t.start)||!Array.isArray(t.segments)||t.segments.length<2||t.segments.length>512)return!1;let e=t.start;for(let n of t.segments){if(!n||!re(n.end))return!1;if(n.kind==="line"){if(E(e,n.end)<=1e-9)return!1}else if(n.kind==="bezier"){if(!re(n.control1)||!re(n.control2)||E(e,n.end)<=1e-9)return!1}else if(n.kind==="arc"){if(!re(n.center)||!Number.isFinite(n.radius)||n.radius<=1e-6||Math.abs(E(e,n.center)-n.radius)>Math.max(1e-4,n.radius*1e-4)||Math.abs(E(n.end,n.center)-n.radius)>Math.max(1e-4,n.radius*1e-4)||E(e,n.end)<=1e-9)return!1}else return!1;e=n.end}return E(e,t.start)<=1e-4}function uo(t,e,n){let r=1-n;return{x:r**3*t.x+3*r**2*n*e.control1.x+3*r*n**2*e.control2.x+n**3*e.end.x,y:r**3*t.y+3*r**2*n*e.control1.y+3*r*n**2*e.control2.y+n**3*e.end.y}}function Qe(t,e=2){if(!ve(t))throw new Error("Section outline path is invalid");let n=Math.max(.25,e),r=[{...t.start}],i=t.start;for(let a of t.segments){if(a.kind==="line")r.push({...a.end});else if(a.kind==="arc"){let o=Math.atan2(i.y-a.center.y,i.x-a.center.x),s=Math.atan2(a.end.y-a.center.y,a.end.x-a.center.x),c=lo(o,s,a.clockwise),l=Math.max(2,Math.ceil(Math.abs(c)*a.radius/n));for(let d=1;d<=l;d+=1){let g=o+c*d/l;r.push({x:a.center.x+Math.cos(g)*a.radius,y:a.center.y+Math.sin(g)*a.radius})}}else{let o=E(i,a.control1)+E(a.control1,a.control2)+E(a.control2,a.end),s=Math.max(2,Math.ceil(o/n));for(let c=1;c<=s;c+=1)r.push(uo(i,a,c/s))}i=a.end}return E(r[r.length-1],r[0])<=1e-4&&r.pop(),r}function At(t,e,n){return Ye(t,i=>({x:i.x+e,y:i.y+n}))}function Ye(t,e,n=1,r=!1){return{...t,start:e(t.start),segments:t.segments.map(i=>i.kind==="line"?{...i,end:e(i.end)}:i.kind==="arc"?{...i,center:e(i.center),radius:i.radius*Math.abs(n),clockwise:r?!i.clockwise:i.clockwise,end:e(i.end)}:{...i,control1:e(i.control1),control2:e(i.control2),end:e(i.end)})}}var Ze=45,Xe=150,fo=60;function go(t){let e=Ze/100;if(t<=e)return Xe;let n=Math.min(1,(t-e)/(1-e));return Xe-n*(Xe-fo)}var Ot=.5523;function Mt(t,e){return Math.abs(t.x-e.x)<=1e-6&&Math.abs(t.y-e.y)<=1e-6}function ho(t){let e=[],n=[];for(t.forEach((r,i)=>{re(r)&&(e.length&&Mt(e[e.length-1],r)||(e.push({x:r.x,y:r.y}),n.push(i)))});e.length>1&&Mt(e[0],e[e.length-1]);)e.pop(),n.pop();return{points:e,sourceIndex:n}}var bo=.5,po=4/3;function mo(t,e,n){let r=e.x-t.x,i=e.y-t.y,a=Math.hypot(r,i);if(a<=1e-9)return{kind:"line",end:{...e}};let o=-i/a,s=r/a,c=n*po;return{kind:"bezier",control1:{x:t.x+r/3+o*c,y:t.y+i/3+s*c},control2:{x:t.x+r*2/3+o*c,y:t.y+i*2/3+s*c},end:{...e}}}function _t(t,e){let{points:n,sourceIndex:r}=ho(t),i=n.length;if(i<3)return null;let a=Math.min(100,Math.max(0,e.cornerSmoothing??0))/100,o=e.edgeCurvature,s=new Array(i).fill(0);if(o?.length)for(let w=0;w<i;w+=1){let S=o[r[w]];s[w]=Number.isFinite(S)?Math.min(100,Math.max(-100,S))/100:0}let c=s.some(w=>Math.abs(w)>1e-6);if(a<=0&&!c)return null;let l=e.wideAngleThresholdDeg??go(a),d=[];for(let w=0;w<i;w+=1)d[w]=E(n[w],n[(w+1)%i]);let g=new Array(i).fill(0);for(let w=0;w<i;w+=1){let S=n[(w-1+i)%i],I=n[w],M=n[(w+1)%i],D={x:S.x-I.x,y:S.y-I.y},T={x:M.x-I.x,y:M.y-I.y},U=Math.hypot(D.x,D.y),K=Math.hypot(T.x,T.y);if(U<=1e-9||K<=1e-9)continue;let O=Math.min(1,Math.max(-1,(D.x*T.x+D.y*T.y)/(U*K))),$=Math.acos(O)*180/Math.PI;if($<l)continue;let j=Pt(($-l)/(180-l));g[w]=a*j*.5*Math.min(U,K)}for(let w=0;w<i;w+=1){let S=(w+1)%i,I=g[w]+g[S];if(I>d[w]&&I>1e-9){let M=d[w]/I;g[w]*=M,g[S]*=M}}let h=new Array(i),f=new Array(i);for(let w=0;w<i;w+=1){let S=n[(w-1+i)%i],I=n[w],M=n[(w+1)%i];if(g[w]<=1e-6){h[w]={...I},f[w]={...I};continue}let D=E(I,S)||1,T=E(I,M)||1;h[w]={x:I.x+(S.x-I.x)/D*g[w],y:I.y+(S.y-I.y)/D*g[w]},f[w]={x:I.x+(M.x-I.x)/T*g[w],y:I.y+(M.y-I.y)/T*g[w]}}if(g.every(w=>w<=1e-6)&&!c)return null;let b=[],y={...f[0]},x=y,v=(w,S)=>{if(E(x,w)<=1e-9)return;let I=s[S];Math.abs(I)>1e-6?b.push(mo(x,w,I*bo*d[S])):b.push({kind:"line",end:{...w}}),x=w};for(let w=1;w<=i;w+=1){let S=w%i,I=n[S];v(h[S],(w-1)%i),g[S]>1e-6&&E(h[S],f[S])>1e-9&&(b.push({kind:"bezier",control1:qe(h[S],I,Ot),control2:qe(f[S],I,Ot),end:{...f[S]}}),x=f[S])}if(!b.length)return null;let p=b[b.length-1];E(p.end,y)>1e-9&&(p.kind==="line"?p.end={...y}:b.push({kind:"line",end:{...y}}));let m={version:1,closed:!0,start:y,segments:b};return ve(m)?m:null}var jt="ABCDEFGHIJKLMNOPQRSTUVWXYZ",yo="ABCDEFGHJKLMNPQRSTUVWXYZ",wo="abcdefghijklmnopqrstuvwxyz";function kt(t,e){let n=e.length,r=t+1,i="";for(;r>0;){r-=1;let a=r%n;i=e[a]+i,r=Math.floor(r/n)}return i}function xo(t,e){let n=e.startAt-1,r=t+n;if(e.scheme==="numbers")return String(r+1);let i=e.skipAmbiguous?yo:jt;return kt(r,i)}function We(t,e=!1){let n=e?wo:jt;return kt(Math.max(0,Math.floor(t)-1),n)}var So=[[1e3,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]];function Rt(t){if(!Number.isFinite(t)||t<=0)return String(t);let e=Math.floor(t),n="";for(let[r,i]of So)for(;e>=r;)n+=i,e-=r;return n}function Lt(t,e){let n=t.length;return t.map((r,i)=>{let a=e.reverse?n-1-i:i;return{...r,label:xo(a,e)}})}function Io(t){let e=new Array(t);return Array.from({length:t},(n,r)=>r).sort((n,r)=>Math.abs(2*n-(t-1))-Math.abs(2*r-(t-1))||n-r).forEach((n,r)=>e[n]=r),e}function et(t,e){let n=t.seatLabelStart??1,r=t.seatNumbering?.direction??"ltr",i=t.seatNumbering?.step??1,a=t.seatNumbering?.scheme??"decimal",o=t.seatNumbering?.prefix??"",s=t.seatNumbering?.endAt,c=t.seatCount;if(a==="updown"||a==="updown-descending"){let f=Math.ceil(c/2),b=a==="updown"?e<f?n+2*e:n-1+2*(c-e):e<f?n+2*(f-1-e):n+1+2*(e-f);return`${o}${b}`}let l=a==="odd"||a==="even"?2:i,d=s!=null&&Number.isFinite(s)?s-(c-1)*l:n,g=r==="center"?Io(c)[e]:r==="rtl"?c-1-e:e,h;switch(a){case"odd":{let f=d%2===1?d:d+1;h=String(f+g*2);break}case"even":{let f=d%2===0?d:d+1;h=String(f+g*2);break}case"roman":h=Rt(d+g*i);break;case"letters-upper":h=We(d+g*i,!1);break;case"letters-lower":h=We(d+g*i,!0);break;default:h=String(d+g*i);break}return`${o}${h}`}function vo(t){return{...t.canonical,seatCount:t.totalSeats,label:t.displayLabel,displayLabel:t.displayLabel}}function Ft(t,e,n){return n?.label??`${t.label}-${et(t,e)}`}function Tt(t,e,n,r){if(r?.displayLabel)return r.displayLabel;if(!n)return`${t.displayLabel??t.label}-${et(t,e)}`;let i=vo(n),a=n.displayOffset+e;return`${n.displayLabel}-${et(i,a)}`}function Dt(t){return t?t.accessibility&&t.accessibility.length?t.wheelchairSpaceType&&!t.accessibility.includes("wheelchair")?["wheelchair",...t.accessibility]:t.accessibility:t.wheelchairSpaceType?["wheelchair"]:t.accessible?["wheelchair"]:[]:[]}var Pe=Math.PI/180,Co=9,ie=16;function nt(t,e,n,r){let i=n*Pe,a=Math.cos(i),o=Math.sin(i);return{x:r.x+t*a-e*o,y:r.y+t*o+e*a}}function ue(t){let{seatCount:e,seatSpacing:n,curve:r,rotation:i,origin:a}=t,o=[];if(t.path)return Ie(t.path,e);if(e<=1)return e===1&&o.push({x:a.x,y:a.y}),o;if(r===0){for(let l=0;l<e;l++)o.push(nt(l*n,0,i,a));return o}let s=r/(e-1)*Pe,c=n/(2*Math.sin(Math.abs(s)/2));for(let l=0;l<e;l++){let d=l*s,g=c*Math.sin(d),h=-c+c*Math.cos(d);o.push(nt(g,h,i,a))}return o}function Po(t){let e=new Map;if(t.overrides)for(let n of t.overrides)e.set(n.index,n);return e}function Oo(t,e){let n=Po(t);return ue(t).map((r,i)=>{let a=n.get(i),o=Dt(a),s=Ft(t,i,a),c={...t.commercial,...a?.commercial};return{index:i,x:r.x+(a?.dx??0),y:r.y+(a?.dy??0),label:s,displayLabel:Tt(t,i,e,a),categoryKey:a?.categoryKey??t.categoryKey,skipped:!!a?.skip,accessible:o.length>0,accessibility:o,wheelchairSpaceType:a?.wheelchairSpaceType,commercial:Object.values(c).some(l=>l!==void 0&&l!==!1&&l!=="")?c:void 0,glyph:a?.glyph,viewUrl:a?.viewFromSeatUrl??t.viewFromSeatUrl,viewMeta:a?.viewFromSeatUrl?a.viewFromSeatMeta:t.viewFromSeatMeta,labelStyle:a?.labelStyle}})}function z(t){let e=[];for(let n of Oo(t))n.skipped||e.push({id:`${t.id}:${n.index}`,label:n.label,displayLabel:n.displayLabel===n.label?void 0:n.displayLabel,x:n.x,y:n.y,rowId:t.id,categoryKey:n.categoryKey,accessible:n.accessible||void 0,accessibility:n.accessibility.length?n.accessibility:void 0,wheelchairSpaceType:n.wheelchairSpaceType,commercial:n.commercial,glyph:n.glyph,viewUrl:n.viewUrl,viewMeta:n.viewMeta,labelStyle:n.labelStyle});return e}function Mo(t){if(t.seatCountsBySide)return{...t.seatCountsBySide};let e=t.sides&&t.sides.length?t.sides:["top","bottom"],n=["top","bottom","left","right"].filter(a=>e.includes(a)),r={top:0,bottom:0,left:0,right:0};if(!n.length)return r;let i=Math.max(0,Math.round(t.seatCount));for(let a=0;a<i;a++)r[n[a%n.length]]+=1;return r}function Ao(t){let e=[],n=Math.max(0,Math.round(t.seatCount));if(n===0)return e;let r=new Map((t.overrides??[]).map(d=>[d.index,d])),i=(d,g,h,f)=>{let b=r.get(d),y=Dt(b),x=b?.label??`${t.label}-${d+1}`,v=t.displayLabel??t.label;return{index:d,label:x,displayLabel:b?.displayLabel??`${v}-${d+1}`,x:g+(b?.dx??0),y:h+(b?.dy??0),categoryKey:b?.categoryKey??t.categoryKey,skipped:!!b?.skip,accessible:y.length>0,accessibility:y,wheelchairSpaceType:b?.wheelchairSpaceType,commercial:b?.commercial,glyph:b?.glyph,viewUrl:b?.viewFromSeatUrl,viewMeta:b?.viewFromSeatUrl?b.viewFromSeatMeta:void 0,labelStyle:b?.labelStyle,...f?{side:f}:{}}};if(t.shape==="round"){let d=(t.radius??40)+ie,g=t.rotation*Pe,h=Math.max(0,Math.min(360,t.seatArc??360));if(h>=360||n===1){for(let x=0;x<n;x++){let v=g+x/n*2*Math.PI;e.push(i(x,t.center.x+d*Math.cos(v),t.center.y+d*Math.sin(v)))}return e}let f=h*Pe,b=(2*Math.PI-f)/2,y=g+b;for(let x=0;x<n;x++){let v=y+x/(n-1)*f;e.push(i(x,t.center.x+d*Math.cos(v),t.center.y+d*Math.sin(v)))}return e}let a=t.width??80,o=t.height??50,s=Mo(t),c=["top","bottom","left","right"],l=0;for(let d of c){let g=s[d];for(let h=0;h<g;h++){let f,b;d==="top"?(f=-a/2+(h+.5)*a/g,b=-o/2-ie):d==="bottom"?(f=-a/2+(h+.5)*a/g,b=o/2+ie):d==="left"?(f=-a/2-ie,b=-o/2+(h+.5)*o/g):(f=a/2+ie,b=-o/2+(h+.5)*o/g);let y=nt(f,b,t.rotation,t.center);e.push(i(l++,y.x,y.y,d))}}return e}function Y(t){return Ao(t).filter(e=>!e.skipped).map(e=>({id:`${t.id}:${e.index}`,label:e.label,...e.displayLabel!==e.label?{displayLabel:e.displayLabel}:{},x:e.x,y:e.y,rowId:t.id,categoryKey:e.categoryKey,...e.accessible?{accessible:!0}:{},...e.accessibility.length?{accessibility:e.accessibility}:{},...e.wheelchairSpaceType?{wheelchairSpaceType:e.wheelchairSpaceType}:{},...e.commercial?{commercial:e.commercial}:{},...e.glyph?{glyph:e.glyph}:{},...e.viewUrl?{viewUrl:e.viewUrl}:{},...e.viewUrl&&e.viewMeta?{viewMeta:e.viewMeta}:{},...e.labelStyle?{labelStyle:e.labelStyle}:{}}))}function Gt(t){return[{id:`${t.id}:0`,label:t.label,...t.displayLabel&&t.displayLabel!==t.label?{displayLabel:t.displayLabel}:{},x:t.center.x,y:t.center.y,rowId:t.id,categoryKey:t.categoryKey,kind:"booth"}]}function Et(t,e){let n=!1;for(let r=0,i=e.length-1;r<e.length;i=r++){let a=e[r].x,o=e[r].y,s=e[i].x,c=e[i].y;o>t.y!=c>t.y&&t.x<(s-a)*(t.y-o)/(c-o)+a&&(n=!n)}return n}function _o(t,e){return e.some((n,r)=>{let i=e[(r+1)%e.length],a=(t.y-n.y)*(i.x-n.x)-(t.x-n.x)*(i.y-n.y);if(Math.abs(a)>1e-7)return!1;let o=(t.x-n.x)*(i.x-n.x)+(t.y-n.y)*(i.y-n.y),s=(i.x-n.x)**2+(i.y-n.y)**2;return o>=-1e-7&&o<=s+1e-7})}function N(t,e,n){return Et(t,e)&&!(n??[]).some(r=>Et(t,r)||_o(t,r))}function tt(t){if(!t.length)return{x:0,y:0};let e=0,n=0;for(let r of t)e+=r.x,n+=r.y;return{x:e/t.length,y:n/t.length}}function L(t){switch(t.type){case"row":{let e=z(t);if(!e.length)return{x:t.origin.x,y:t.origin.y};let n=0,r=0;for(let i of e)n+=i.x,r+=i.y;return{x:n/e.length,y:r/e.length}}case"table":case"booth":return{x:t.center.x,y:t.center.y};case"gaArea":return tt(t.points);case"section":return tt(t.outline);case"text":return{x:t.position.x,y:t.position.y};case"shape":return t.points&&t.points.length?tt(t.points):t.x!=null&&t.y!=null&&t.width!=null&&t.height!=null?{x:t.x+t.width/2,y:t.y+t.height/2}:{x:t.x??0,y:t.y??0};case"decorImage":return{x:t.x+t.width/2,y:t.y+t.height/2}}}function Nt(t,e){return t.length===e.length&&t.every((n,r)=>n.x===e[r].x&&n.y===e[r].y)}function jo(t,e){if(t.type!=="gaArea"||!Nt(t.points,e.outline))return!1;let n=t.holes??[],r=e.holes??[];return n.length===r.length&&n.every((i,a)=>Nt(i,r[a]))}function Kt(t,e){let n=t.filter(o=>o.type==="section"),r="referenceInventorySource"in e?e.referenceInventorySource?.logicalSectionId:void 0,i=L(e);return(r?n.find(o=>(o.logicalSectionId??o.id)===r&&(jo(e,o)||N(i,o.outline,o.holes))):void 0)??n.find(o=>N(i,o.outline,o.holes))}function G(t){return t.floors&&t.floors.length?t.floors:[{id:"floor-0",name:"Main",objects:t.objects,focalPoint:t.focalPoint,referenceImage:t.referenceImage,backgroundImage:t.backgroundImage}]}function H(t){return t.floors&&t.floors.length?t.floors.flatMap(e=>e.objects):t.objects}var Ce=40;function $t(t){let e=1/0,n=1/0,r=-1/0,i=-1/0,a=(o,s)=>{o<e&&(e=o),s<n&&(n=s),o>r&&(r=o),s>i&&(i=s)};for(let o of H(t))if(o.type==="row"){let s=new Map((o.overrides??[]).map(c=>[c.index,c]));ue(o).forEach((c,l)=>{let d=s.get(l);d?.skip||a(c.x+(d?.dx??0),c.y+(d?.dy??0))})}else if(o.type==="gaArea")for(let s of o.points)a(s.x,s.y);else if(o.type==="section")for(let s of o.outline)a(s.x,s.y);else if(o.type==="decorImage")a(o.x,o.y),a(o.x+o.width,o.y+o.height);else if(o.type==="shape")if(o.points&&o.points.length)for(let s of o.points)a(s.x,s.y);else o.x!=null&&o.y!=null&&o.width!=null&&o.height!=null&&(a(o.x,o.y),a(o.x+o.width,o.y+o.height));else if(o.type==="table"){let s=ie+Co,c=o.shape==="round"?(o.radius??40)+s:Math.max((o.width??80)/2,(o.height??50)/2)+s;a(o.center.x-c,o.center.y-c),a(o.center.x+c,o.center.y+c)}else if(o.type==="booth"){let s=Math.max(o.width,o.height)/2;a(o.center.x-s,o.center.y-s),a(o.center.x+s,o.center.y+s)}else if(o.type==="text"){let s=vt(o);a(o.position.x,o.position.y),a(o.position.x+s.width,o.position.y+s.height)}for(let o of[t.referenceImage,t.backgroundImage]){if(!o)continue;let{center:s,width:c}=o,l=c*3/4;a(s.x-c/2,s.y-l/2),a(s.x+c/2,s.y+l/2)}if(!isFinite(e)){let o=t.focalPoint??{x:0,y:0};return{x:o.x-200,y:o.y-200,width:400,height:400}}return{x:e-Ce,y:n-Ce,width:r-e+Ce*2,height:i-n+Ce*2}}var fe=[{key:"wheelchair",label:"Wheelchair space",short:"Wheelchair",icon:"\u267F"},{key:"companion",label:"Companion seat",short:"Companion",icon:"\u{1F9D1}\u200D\u{1F91D}\u200D\u{1F9D1}"},{key:"semi-ambulatory",label:"Semi-ambulatory (limited mobility)",short:"Limited mobility",icon:"\u{1F9AF}"},{key:"designated-aisle",label:"Designated aisle / transfer seat",short:"Aisle transfer",icon:"AS"},{key:"step-free",label:"Step-free accessible seat",short:"Step-free",icon:"SF"},{key:"hearing",label:"Assistive listening",short:"Hearing",icon:"\u{1F9BB}"},{key:"cart",label:"CART live-caption view",short:"CART captions",icon:"CC"},{key:"sign-language",label:"Sign-language view",short:"Sign language",icon:"\u{1F91F}"},{key:"low-vision",label:"Blind / low-vision viewing",short:"Low vision",icon:"LV"},{key:"sensory-friendly",label:"Quiet / sensory-friendly seating",short:"Sensory-friendly",icon:"QS"},{key:"plus-size",label:"Plus-size seat",short:"Plus-size",icon:"\u{1F4BA}"},{key:"lift-armrest",label:"Lift-up armrest",short:"Lift armrest",icon:"\u2195\uFE0F"}],xa=new Map(fe.map(t=>[t.key,t]));var ko=[{key:"obstructedView",label:"Obstructed view",short:"Obstructed",icon:"\u26D4"},{key:"restrictedView",label:"Restricted view",short:"Restricted",icon:"\u{1F441}"},{key:"premium",label:"Premium seat",short:"Premium",icon:"\u2605"}],Sa=new Map(ko.map(t=>[t.key,t]));var ot=8,rt=24,Ro=["reference-focal","bar","entrance","exit","restroom","screen","sound","concession","coat","wall","rail","suite","obstruction"],Ia=new Set(Ro);var u=class extends Error{constructor(n,r,i={}){super(r);this.code=n;this.details=i;this.name="ChartOperationError"}};function C(t,e){let n=G(t),r=e?n.find(i=>i.id===e):n[0];if(!r)throw new u("floor_not_found",`Unknown chart floor: ${e}`,{floorId:e});return{floorId:r.id,objects:r.objects}}function k(t,e){if(!t.categories.some(n=>n.key===e))throw new u("category_not_found",`Unknown chart category: ${e}. Call get_chart to list valid category keys.`,{categoryKey:e})}function _(t,e,n,r){let i=new Set([...r,...t.categories.map(a=>a.key),...t.zones?.map(a=>a.id)??[],...t.floors?.map(a=>a.id)??[],...t.floors?.length?t.floors.flatMap(a=>a.objects.map(o=>o.id)):t.objects.map(a=>a.id)]);for(let a=0;a<100;a++){let o=n(e);if(o&&!i.has(o))return r.add(o),o}throw new u("id_generation_failed",`Unable to allocate a unique ${e} id`)}function Lo(t){let e=t.slice().sort((a,o)=>a.x-o.x||a.y-o.y);if(e.length<3)return e;let n=(a,o,s)=>(o.x-a.x)*(s.y-a.y)-(o.y-a.y)*(s.x-a.x),r=[];for(let a of e){for(;r.length>=2&&n(r[r.length-2],r[r.length-1],a)<=0;)r.pop();r.push(a)}let i=[];for(let a=e.length-1;a>=0;a--){let o=e[a];for(;i.length>=2&&n(i[i.length-2],i[i.length-1],o)<=0;)i.pop();i.push(o)}return r.pop(),i.pop(),r.concat(i)}function Fo(t,e){if(!t.length)return t;let n={x:t.reduce((r,i)=>r+i.x,0)/t.length,y:t.reduce((r,i)=>r+i.y,0)/t.length};return t.map(r=>{let i=r.x-n.x,a=r.y-n.y,o=Math.hypot(i,a)||1;return{x:r.x+i/o*e,y:r.y+a/o*e}})}function Z(t){let e=[];for(let r of t)r.type==="row"?e.push(...z(r).map(i=>({x:i.x,y:i.y}))):r.type==="table"?e.push(...Y(r).map(i=>({x:i.x,y:i.y}))):r.type==="gaArea"?e.push(...r.points):r.type==="booth"&&e.push(r.center);if(e.length<3)return null;let n=Fo(Lo(e),22);return n.length>=3?n:null}function Oe(t,e){let n=C(t,e),r=G(t).find(i=>i.id===n.floorId);return{...t,objects:n.objects,floors:void 0,focalPoint:r.focalPoint,referenceImage:r.referenceImage,backgroundImage:r.backgroundImage}}var zt=24,Bt=80;function it(t,e){let n=t.normalize("NFKC").trim();if(n.length>zt)throw new u("invalid_operation",`${e} displayed type must be at most ${zt} characters`);return n}function Me(t,e){if(t.displayType===void 0)return!1;let n=it(t.displayType,e);return n?(t.displayType=n,!1):(delete t.displayType,!0)}function ae(t,e){if(t.displayLabel===void 0)return!1;let n=t.displayLabel.normalize("NFKC").trim();if(n.length>Bt)throw new u("invalid_operation",`${e} displayed label must be at most ${Bt} characters`);return n?(t.displayLabel=n,!1):(delete t.displayLabel,!0)}function F(t,e){let n=t.trim().toLowerCase();if(!/^#[0-9a-f]{6}$/.test(n))throw new u("invalid_operation",`${e} must use a six-digit hex color`);return n}function Ut(t,e){if(!Number.isFinite(t)||t<ot||t>rt)throw new u("invalid_operation",`${e} label size must be from ${ot} to ${rt}`)}function se(t,e){t.size!==void 0&&t.size!==null&&Ut(t.size,e),t.color!==void 0&&t.color!==null&&F(t.color,`${e} label color`)}function Ae(t,e){if(t?.positionPreset!==void 0&&!["start","end","both","none"].includes(t.positionPreset))throw new u("invalid_operation",`${e} label positionPreset must be one of start, end, both, none`);let n=t?.labelStyle;n&&(n.size!==void 0&&Ut(n.size,e),n.color!==void 0&&F(n.color,`${e} label color`))}function _e(t,e){let n=t?structuredClone(t):{},r=n.labelStyle?{...n.labelStyle}:{};return e.size===null?delete r.size:e.size!==void 0&&(r.size=e.size),e.color===null?delete r.color:e.color!==void 0&&(r.color=F(e.color,"Label color")),r.size===void 0&&r.color===void 0?delete n.labelStyle:n.labelStyle=r,e.visible!==void 0&&(n.visible=e.visible),Object.keys(n).length?n:void 0}function at(t,e,n){let r=e.normalize("NFKC").trim();if(!r||r.length>80)throw new u("invalid_operation","Zone labels must contain 1 to 80 characters");if((t.zones??[]).some(i=>i.id!==n&&i.label.normalize("NFKC").trim().toLocaleLowerCase("en")===r.toLocaleLowerCase("en")))throw new u("invalid_operation",`Zone label already exists: ${r}`);return r}function st(t,e){if(!Number.isFinite(t?.x)||!Number.isFinite(t?.y))throw new u("invalid_operation",`${e} must contain finite x and y values`);return{x:t.x,y:t.y}}function J(t,e,n){return(e.x-t.x)*(n.y-t.y)-(e.y-t.y)*(n.x-t.x)}var X=Math.PI/180,q=Math.PI/180;function W(t){return t.type==="row"||t.type==="table"?t.seatCount:t.type==="gaArea"?Math.max(0,Math.floor(t.capacity)):t.type==="booth"?1:0}function ge(t){if(t.floors?.length){let e=t.floors[0];t.objects=e.objects,t.focalPoint=e.focalPoint,t.referenceImage=e.referenceImage,t.backgroundImage=e.backgroundImage}return t}var To=0,je=120,ct=4;function Eo(t){if(!Number.isFinite(t)||t<To||t>je)throw new u("invalid_operation","Floor base height must be a number from 0 to 120 metres")}function No(t,e){let n=G(t);if(n.length>=5)throw new u("invalid_operation","A chart can contain at most five physical floors");let r=(e.name??String(n.length+1)).normalize("NFKC").trim();if(!r||r.length>80)throw new u("invalid_operation","Floor names must contain 1 to 80 characters");if(n.some(c=>c.name.toLocaleLowerCase("en")===r.toLocaleLowerCase("en")))throw new u("invalid_operation",`Floor name already exists: ${r}`);t.floors?.length||(t.floors=[{id:"floor-0",name:"1",objects:t.objects,baseHeightM:0,focalPoint:t.focalPoint,referenceImage:t.referenceImage,backgroundImage:t.backgroundImage}]);let a=t.floors[t.floors.length-1].baseHeightM??Math.min(je,(t.floors.length-1)*ct),o=Math.min(je,a+ct),s=_(t,"floor",e.idFactory,new Set);return t.floors.push({id:s,name:r,baseHeightM:o,objects:[],focalPoint:{...t.focalPoint}}),ge(t),{changed:!0,floorId:s,floorCount:t.floors.length,baseHeightM:o}}function Do(t,e){let n=G(t),r=n.find(o=>o.id===e.floorId);if(!r)throw new u("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});let i=e.name.normalize("NFKC").trim();if(!i||i.length>80)throw new u("invalid_operation","Floor names must contain 1 to 80 characters");if(n.some(o=>o.id!==r.id&&o.name.toLocaleLowerCase("en")===i.toLocaleLowerCase("en")))throw new u("invalid_operation",`Floor name already exists: ${i}`);let a=r.name!==i;return a&&(r.name=i),{changed:a,floorId:r.id,floorName:i}}function Go(t,e){if(!t.floors?.length)throw new u("invalid_operation","A single-floor chart has an implicit base height of 0 metres");let n=t.floors.find(i=>i.id===e.floorId);if(!n)throw new u("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});Eo(e.baseHeightM);let r=n.baseHeightM!==e.baseHeightM;return r&&(n.baseHeightM=e.baseHeightM,n.physical3dProvenance={...n.physical3dProvenance,baseHeightM:{status:"confirmed",source:"user-review",note:"Physical floor height reviewed through the shared Designer/Copilot operation."}}),{changed:r,floorId:n.id,baseHeightM:e.baseHeightM}}function Ko(t,e){if(!t.floors?.length)throw new u("invalid_operation","A single-floor chart cannot remove its only floor");let n=t.floors.findIndex(i=>i.id===e.floorId);if(n<0)throw new u("floor_not_found",`Unknown chart floor: ${e.floorId}`,{floorId:e.floorId});let[r]=t.floors.splice(n,1);if(t.floors.length===1){let[i]=t.floors;t.objects=i.objects,t.focalPoint=i.focalPoint,t.referenceImage=i.referenceImage,t.backgroundImage=i.backgroundImage,t.floors=void 0}else ge(t);return{changed:!0,floorId:r.id,removedObjects:r.objects.length,floorCount:G(t).length}}function $o(t,e){if((t.zones?.length??0)>=100)throw new u("invalid_operation","A chart supports at most 100 zones");let n={id:_(t,"zone",e.idFactory,new Set),label:at(t,e.label),color:F(e.color,"Zone color"),...e.focalPoint?{focalPoint:st(e.focalPoint,"Zone focal point")}:{}};return(t.zones??=[]).push(n),{changed:!0,zone:structuredClone(n)}}function zo(t,e){if(!e.updates.length)throw new u("invalid_operation","At least one zone update is required");let n=e.updates.map(c=>c.zoneId);if(new Set(n).size!==n.length)throw new u("invalid_operation","Zone ids must be unique");let r=new Map((t.zones??[]).map(c=>[c.id,c])),i=n.filter(c=>!r.has(c));if(i.length)throw new u("object_not_found",`Unknown zone id(s): ${i.join(", ")}. Call get_chart to list current zone ids.`,{zoneIds:i});let a=structuredClone(t),o=new Map((a.zones??[]).map(c=>[c.id,c]));for(let c of e.updates){if(!Object.keys(c.patch).length)throw new u("invalid_operation",`Zone ${c.zoneId} has no changes`);let d=o.get(c.zoneId);c.patch.label!==void 0&&(d.label=at(a,c.patch.label,d.id)),c.patch.color!==void 0&&(d.color=F(c.patch.color,"Zone color")),c.patch.focalPoint!==void 0&&(d.focalPoint=st(c.patch.focalPoint,"Zone focal point"))}let s=JSON.stringify(a.zones??[])!==JSON.stringify(t.zones??[]);return s&&(t.zones=a.zones),{changed:s,zoneIds:n,zones:n.map(c=>structuredClone(o.get(c)))}}function Bo(t,e){let n=(t.zones??[]).findIndex(a=>a.id===e.zoneId);if(n<0)throw new u("object_not_found",`Unknown chart zone: ${e.zoneId}`,{zoneId:e.zoneId});let r=G(t).flatMap(a=>a.objects).filter(a=>a.type==="section"&&a.zone===e.zoneId);if(r.length&&e.clearSectionAssignments!==!0)throw new u("invalid_operation",`Zone ${e.zoneId} is assigned to ${r.length} section(s)`,{zoneId:e.zoneId,sectionIds:r.map(a=>a.id),requiresClearSectionAssignments:!0});let i=r.map(a=>a.id);for(let a of r)delete a.zone;return t.zones.splice(n,1),t.zones.length||delete t.zones,ge(t),{changed:!0,zoneId:e.zoneId,clearedSectionIds:i,zoneCount:t.zones?.length??0}}var ke=[{key:"row-seats",label:"row seats",suffix:"rows",labelSuffix:"Rows",creationWord:"Seats",objectType:"row"},{key:"table-chairs",label:"table chairs",suffix:"tables",labelSuffix:"Tables",creationWord:"Tables",objectType:"table"},{key:"booth-units",label:"booth units",suffix:"booths",labelSuffix:"Booths",creationWord:"Booths",objectType:"booth"},{key:"ga-capacity",label:"GA capacity",suffix:"ga",labelSuffix:"GA",creationWord:"Standing",objectType:"gaArea"}];function Re(t){let e=new Map,n=Math.max(0,Math.floor(t.seatCount)),r=new Map((t.overrides??[]).filter(a=>Number.isInteger(a.index)&&a.index>=0&&a.index<t.seatCount).map(a=>[a.index,a])),i=(a,o=1)=>{a&&o>0&&e.set(a,(e.get(a)??0)+o)};i(t.categoryKey,n-r.size);for(let a of r.values())a.skip||i(a.categoryKey??t.categoryKey);return e}var Ht="__sl_ga__",ee=1e5,ce=1e5;function Uo(t,e){return`${Ht}${encodeURIComponent(t)}__${e+1}`}function lt(t){let e=t.inventorySegments;if(e===void 0)return!0;if(!Array.isArray(e)||e.length<1||e.length>256)return!1;let n=0,r=new Map;for(let i of e){if(!i||typeof i.sourceAreaId!="string"||!i.sourceAreaId.trim()||i.sourceAreaId.length>160||!Number.isInteger(i.startIndex)||i.startIndex<0||!Number.isInteger(i.count)||i.count<1||i.startIndex+i.count>ee||(n+=i.count,n>ee))return!1;let a=r.get(i.sourceAreaId)??[],o=i.startIndex+i.count;if(a.some(s=>i.startIndex<s.end&&o>s.start))return!1;a.push({start:i.startIndex,end:o}),r.set(i.sourceAreaId,a)}return n===t.capacity}function Le(t){let e=Math.min(ee,Math.max(0,Math.floor(t.capacity)));return t.inventorySegments===void 0?e?[{sourceAreaId:t.id,startIndex:0,count:e}]:[]:lt(t)?t.inventorySegments.map(n=>({...n})):[]}function te(t){return Le(t).flatMap(e=>Array.from({length:e.count},(n,r)=>Uo(e.sourceAreaId,e.startIndex+r)))}function dt(t,e){if(t.inventorySegments===void 0||e===t.capacity)return t.inventorySegments;if(e<t.capacity)return;let n=Le(t);if(!n.length)return;let r=e-t.capacity;if(!r)return n;let a=n.filter(s=>s.sourceAreaId===t.id).reduce((s,c)=>Math.max(s,c.startIndex+c.count),0),o=n[n.length-1];if(o?.sourceAreaId===t.id&&o.startIndex+o.count===a)o.count+=r;else{if(n.length>=256)return;n.push({sourceAreaId:t.id,startIndex:a,count:r})}return n}function Vt(t){return t.startsWith(Ht)}var Ho="__ungrouped__";function Vo(t){return t.type==="row"?z(t).map(e=>e.label):t.type==="table"?Y(t).map(e=>e.label):t.type==="booth"?Gt(t).map(e=>e.label):t.type==="gaArea"?te(t):[]}function Jo(t){return t.type==="row"||t.type==="table"||t.type==="booth"||t.type==="gaArea"}function he(t){let e=H(t),n=e.filter(o=>o.type==="section"),r=new Map;for(let o of n){let s=o.logicalSectionId??o.id;r.get(s)||r.set(s,{id:s,label:o.displayLabel||o.label||"Section",zone:o.zone,seatCount:0,objectIds:[],seatLabels:[]})}let i={id:Ho,label:"Other seats",seatCount:0,objectIds:[],seatLabels:[]},a=new Map;for(let o of e){if(!Jo(o))continue;let s=Vo(o);if(s.length===0)continue;let c=Kt(e,o),l=c?r.get(c.logicalSectionId??c.id):i;l.seatCount+=s.length,l.objectIds.push(o.id),l.seatLabels.push(...s),a.set(o.id,l.id)}return{sections:[...r.values()],ungrouped:i.objectIds.length?i:null,objectToSection:a}}var ne={vip:{key:"vip",label:"VIP",color:"#e5484d",price:120},premium:{key:"premium",label:"Premium",color:"#a86b00",price:80},standard:{key:"standard",label:"Standard",color:"#6e7bff",price:45},balcony:{key:"balcony",label:"Balcony",color:"#22a06b",price:30}};function be(t,e,n,r,i,a,o=0){return{type:"row",id:t,label:e,origin:{x:-(r-1)*i/2,y:n},rotation:0,curve:o,seatCount:r,seatSpacing:i,categoryKey:a}}function qo(t,e,n,r,i,a){return{type:"table",id:t,label:e,center:n,shape:"round",seatCount:r,rotation:0,radius:i,categoryKey:a}}function Jt(t,e,n,r,i,a){let o=n/2,s=r/2;return{type:"gaArea",id:t,label:e,points:[{x:-o,y:-s},{x:o,y:-s},{x:o,y:s},{x:-o,y:s}],capacity:i,categoryKey:a}}function Xo(t,e,n,r,i){let a=n*2,o=[];for(let s=0;s<a;s++){let c=s%2===0,l=c?["wheelchair"]:["companion"];o.push(c?{index:s,accessibility:l,wheelchairSpaceType:"no-seat"}:{index:s,accessibility:l})}return{type:"row",id:t,label:e,origin:{x:-(a-1)*r/2,y:0},rotation:0,curve:0,seatCount:a,seatSpacing:r,categoryKey:i,overrides:o}}var qt=[{key:"balcony",label:"Balcony",icon:"\u2312",blurb:"Insert four curved rows inside a section.",categories:[ne.balcony],sectionLabel:"Balcony",build:()=>[be("blk-b0","A",-45,18,24,"balcony",18),be("blk-b1","B",-15,20,24,"balcony",18),be("blk-b2","C",15,22,24,"balcony",18),be("blk-b3","D",45,24,24,"balcony",18)]},{key:"rows",label:"Row block",icon:"\u2261",blurb:"Insert six straight rows inside a section.",categories:[ne.standard],sectionLabel:"Section",build:()=>Array.from({length:6},(t,e)=>be(`blk-r${e}`,"ABCDEF"[e],-80+e*32,12,26,"standard"))},{key:"ga-pen",label:"GA pen",icon:"\u25A8",blurb:"Insert a standing area for 250 people.",categories:[ne.standard],build:()=>[Jt("blk-ga","Standing",320,180,250,"standard")]},{key:"tables",label:"Tables",icon:"\u283F",blurb:"Insert six round tables with eight bookable seats each.",categories:[ne.premium],build:()=>Array.from({length:6},(t,e)=>qo(`blk-t${e}`,`T${e+1}`,{x:-150+e%3*150,y:e<3?-70:70},8,34,"premium"))},{key:"boxes",label:"Boxes",icon:"\u25A3",blurb:"Insert two private boxes with four bookable seats each.",categories:[ne.vip],build:()=>[{type:"table",id:"blk-x0",label:"Box 1",center:{x:-70,y:0},shape:"rect",seatCount:4,rotation:0,width:110,height:56,categoryKey:"vip"},{type:"table",id:"blk-x1",label:"Box 2",center:{x:70,y:0},shape:"rect",seatCount:4,rotation:0,width:110,height:56,categoryKey:"vip"}]},{key:"terrace",label:"Terrace",icon:"\u2263",blurb:"Insert a standing terrace for 500 people.",categories:[ne.standard],build:()=>[Jt("blk-terrace","Terrace",520,200,500,"standard")]},{key:"wheelchair-platform",label:"Wheelchair platform",icon:"\u267F",blurb:"Insert four wheelchair spaces, each with its companion seat.",categories:[ne.standard],build:()=>[Xo("blk-wc","A",4,40,"standard")]}];function B(t){let e="",n=t;do e=String.fromCharCode(65+n%26)+e,n=Math.floor(n/26)-1;while(n>=0);return e}function Xt(t){if(!/^[A-Z]+$/.test(t))return null;let e=0;for(let n of t)e=e*26+(n.charCodeAt(0)-64);return e-1}var Qt="M13 4.6a1.6 1.6 0 1 0-3.2 0 1.6 1.6 0 0 0 3.2 0 M11 6.5V13h5l2.4 6 M15 16.4A5 5 0 1 1 9 11.3",Yt=[{key:"restroom-men",label:"Men's restroom",group:"facilities",path:"M16 7a4 4 0 1 0-8 0 4 4 0 0 0 8 0 M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"},{key:"restroom-women",label:"Women's restroom",group:"facilities",path:"M15 5a3 3 0 1 0-6 0 3 3 0 0 0 6 0 M12 8l-4 10h8l-4-10 M10 18v4 M14 18v4"},{key:"restroom-accessible",label:"Accessible restroom",group:"facilities",path:Qt},{key:"first-aid",label:"First aid",group:"facilities",path:"M5 4h14a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1Z M12 8v8 M8 12h8"},{key:"coat-check",label:"Coat check",group:"facilities",path:"M12 6a2 2 0 0 1 0-4 2 2 0 0 1 1.6 3.2L21 13H3l8.4-7.8 M3 13h18"},{key:"atm",label:"ATM / cash",group:"facilities",path:"M2 6h20v12H2V6Z M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0 M6 9h.01 M18 15h.01"},{key:"info",label:"Info point",group:"facilities",path:"M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18 M12 11v5 M12 8h.01"},{key:"lost-found",label:"Lost & found",group:"facilities",path:"M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14 M16 16l5 5 M9 8.5a2 2 0 1 1 3 1.7c-.8.5-1 .8-1 1.8 M11 15h.01"},{key:"restrooms",label:"Restrooms",group:"facilities",path:"M6 3h12a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z M12 8a2 2 0 1 0 0 4 2 2 0 0 0 0-4 M9 18v-3.5a3 3 0 0 1 6 0V18"},{key:"charging",label:"Charging point",group:"facilities",path:"M3 8h13v8H3V8Z M16 10h3v4h-3 M9.6 9l-2 3.5h2.5l-1.5 3"},{key:"smoking",label:"Smoking area",group:"facilities",path:"M2 15h13v3H2v-3Z M18 16h2 M19 8c0 1 1 1.5 1 2.5S19 12 19 13"},{key:"no-smoking",label:"No smoking",group:"facilities",path:"M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18 M5.6 5.6l12.8 12.8 M7 13h6v2H7v-2Z"},{key:"food",label:"Food",group:"food-drink",path:"M7 3v6a2 2 0 0 0 4 0V3 M9 11v10 M17 3c-1.6 1-2.2 3-2.2 6 0 2 .9 3.2 2.2 3.6V21"},{key:"bar",label:"Bar",group:"food-drink",path:"M4 5h16l-8 8-8-8Z M12 13v6 M8 20h8"},{key:"coffee",label:"Caf\xE9 / coffee",group:"food-drink",path:"M4 8h13v4a5 5 0 0 1-5 5H9a5 5 0 0 1-5-5V8Z M17 9h2a2 2 0 0 1 0 4h-2 M8 2v2 M11 2v2 M4 21h14"},{key:"water",label:"Water / drinks",group:"food-drink",path:"M12 22a7 7 0 0 1-7-7c0-5 7-12 7-12s7 7 7 12a7 7 0 0 1-7 7Z"},{key:"merch",label:"Merch / shop",group:"food-drink",path:"M6 8h12l-1 12H7L6 8Z M9 8V6a3 3 0 0 1 6 0v2"},{key:"screen",label:"Screen",group:"facilities",path:"M3 4h18v12H3V4Z M9 20h6 M12 16v4 M10 8l4 2-4 2V8Z"},{key:"sound-booth",label:"Sound booth",group:"facilities",path:"M6 4v16 M6 14a2 2 0 1 0 0-4 2 2 0 0 0 0 4 M12 4v16 M12 8a2 2 0 1 0 0 4 2 2 0 0 0 0-4 M18 4v16 M18 12a2 2 0 1 0 0 4 2 2 0 0 0 0-4"},{key:"entrance",label:"Entrance",group:"navigation",path:"M14 3h5a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1h-5 M3 12h11 M10 8l4 4-4 4"},{key:"exit",label:"Exit",group:"navigation",path:"M10 3H5a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h5 M14 12h7 M17 8l4 4-4 4"},{key:"emergency-exit",label:"Emergency exit",group:"navigation",path:"M14 4.6a1.5 1.5 0 1 0-3 0 1.5 1.5 0 0 0 3 0 M12.5 8l-3.5 2 1.6 3.6-2 4.4 M12.5 10l3.5 1.5 M9 10.5l-3.5 1 M15 12h6 M18 9l3 3-3 3"},{key:"stairs",label:"Stairs",group:"navigation",path:"M3 20v-4h4v-4h4v-4h4V4h5"},{key:"elevator",label:"Elevator",group:"navigation",path:"M5 3h14a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z M8 11l1.5-2 1.5 2 M8 14l1.5 2 1.5-2 M15 8v8"},{key:"parking",label:"Parking",group:"navigation",path:"M5 3h14a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z M9 17V7h4a3 3 0 0 1 0 6H9"},{key:"wheelchair",label:"Wheelchair access",group:"accessibility",path:Qt},{key:"hearing",label:"Hearing assistance",group:"accessibility",path:"M8 20a4 4 0 0 1-2-3c0-1 .5-2 .5-3a4.5 4.5 0 1 1 9 0c0 1.4-1 2-2 2.4-1.2.5-1.5 1-1.5 2.2 M17 6a5 5 0 0 1 1 6 M19.5 4a8 8 0 0 1 1.2 9"}];var Qo=new Map(Yt.map(t=>[t.key,t]));function Zt(t){return typeof t=="string"&&Qo.has(t)}var Ha=Yt.map(t=>t.key);function ut(t){let e=(t%360+360)%360,n=e>=180?e-360:e;return Object.is(n,-0)||Math.abs(n)<1e-9?0:n}function Wt(t,e,n){let r=i=>({x:i.x+e,y:i.y+n});switch(t.type){case"row":t.origin=r(t.origin),t.path&&(t.path={start:r(t.path.start),control1:r(t.path.control1),control2:r(t.path.control2),end:r(t.path.end)});break;case"table":case"booth":t.center=r(t.center);break;case"text":t.position=r(t.position);break;case"gaArea":t.points=t.points.map(r),t.holes&&(t.holes=t.holes.map(i=>i.map(r)));break;case"section":t.outline=t.outline.map(r),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(r)),t.outlinePath&&(t.outlinePath=At(t.outlinePath,e,n)),t.holes&&(t.holes=t.holes.map(i=>i.map(r)));break;case"shape":t.points&&(t.points=t.points.map(r)),t.x!=null&&(t.x+=e),t.y!=null&&(t.y+=n);break;case"decorImage":t.x+=e,t.y+=n;break}}function Yo(t,e){return Math.abs(t.x-e.x)<=1e-7&&Math.abs(t.y-e.y)<=1e-7}function pe(t,e,n){return(e.x-t.x)*(n.y-t.y)-(e.y-t.y)*(n.x-t.x)}function Fe(t,e,n){let r=pe(e,n,t);return Math.abs(r)>1e-7?!1:t.x>=Math.min(e.x,n.x)-1e-7&&t.x<=Math.max(e.x,n.x)+1e-7&&t.y>=Math.min(e.y,n.y)-1e-7&&t.y<=Math.max(e.y,n.y)+1e-7}function Zo(t,e,n,r){let i=pe(t,e,n),a=pe(t,e,r),o=pe(n,r,t),s=pe(n,r,e);return(i>1e-7&&a<-1e-7||i<-1e-7&&a>1e-7)&&(o>1e-7&&s<-1e-7||o<-1e-7&&s>1e-7)?!0:Math.abs(i)<=1e-7&&Fe(n,t,e)||Math.abs(a)<=1e-7&&Fe(r,t,e)||Math.abs(o)<=1e-7&&Fe(t,n,r)||Math.abs(s)<=1e-7&&Fe(e,n,r)}function Wo(t){return t.reduce((e,n,r)=>{let i=t[(r+1)%t.length];return e+n.x*i.y-i.x*n.y},0)}function er(t){for(let e=0;e<t.length;e+=1){let n=(e+1)%t.length;for(let r=e+1;r<t.length;r+=1){let i=(r+1)%t.length;if(!(e===r||n===r||i===e)&&Zo(t[e],t[n],t[r],t[i]))return!0}}return!1}function en(t){return t.length<3?{ok:!1,code:"too_few_vertices",message:"Add at least three vertices to create a polygon."}:t.length>256?{ok:!1,code:"too_many_vertices",message:"A polygon can contain at most 256 vertices."}:t.some(e=>!Number.isFinite(e.x)||!Number.isFinite(e.y)||Math.abs(e.x)>1e7||Math.abs(e.y)>1e7)?{ok:!1,code:"invalid_coordinate",message:"Every polygon vertex must use a finite coordinate inside the safe chart range."}:t.some((e,n)=>Yo(e,t[(n+1)%t.length]))?{ok:!1,code:"duplicate_vertex",message:"Move or remove duplicate neighbouring vertices."}:Math.abs(Wo(t))<2?{ok:!1,code:"degenerate_polygon",message:"The polygon needs a visible enclosed area."}:er(t)?{ok:!1,code:"self_intersection",message:"Polygon edges cannot cross or touch each other."}:{ok:!0}}function lr(t,e){let n=C(t,e.floorId),r=[...new Set(e.tableIds)];if(!r.length)throw new u("invalid_operation","At least one table id is required");let i=r.map(p=>n.objects.find(m=>m.type==="table"&&m.id===p)),a=r.filter((p,m)=>!i[m]);if(a.length)throw new u("object_not_found",`Unknown table id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current table ids.`,{tableIds:a});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new u("invalid_operation","At least one table change is required");if(o.label!==void 0){if(o.label=o.label.normalize("NFKC").trim(),r.length!==1)throw new u("invalid_operation","label can be changed only for one table at a time");if(!o.label||o.label.length>80)throw new u("invalid_operation","Table labels must contain 1 to 80 characters")}o.categoryKey!==void 0&&k(t,o.categoryKey);let s=o.seatCount!==void 0,c=o.seatCountsBySide!==void 0;if(c){if(o.sides!==void 0)throw new u("invalid_operation","Use seatCountsBySide for exact rectangular counts; do not also supply legacy sides");if(o.shape==="round")throw new u("invalid_operation","seatCountsBySide can be used only with rectangular tables");let p=["top","bottom","left","right"],m=Object.keys(o.seatCountsBySide);if(m.length!==p.length||m.some(S=>!p.includes(S)))throw new u("invalid_operation","seatCountsBySide must contain exactly top, bottom, left, and right");for(let S of p){let I=o.seatCountsBySide[S];if(!Number.isInteger(I)||I<0||I>40)throw new u("invalid_operation",`seatCountsBySide.${S} must be a whole number from 0 to 40`)}let w=p.reduce((S,I)=>S+o.seatCountsBySide[I],0);if(w<1||w>40)throw new u("invalid_operation","Rectangular table side counts must total from 1 to 40 chairs");if(s&&o.seatCount!==w)throw new u("invalid_operation",`seatCount must equal the ${w}-chair seatCountsBySide total`);o.seatCount=w,o.sides=p.filter(S=>o.seatCountsBySide[S]>0)}if(o.seatCount!==void 0&&(!Number.isInteger(o.seatCount)||o.seatCount<1||o.seatCount>40))throw new u("invalid_operation","seatCount must be an integer from 1 to 40");if(o.shape!==void 0&&o.shape!=="round"&&o.shape!=="rect")throw new u("invalid_operation","Table shape must be round or rect");if(o.bookAsWhole===!0&&o.variableOccupancy===!0)throw new u("invalid_operation","A table cannot use whole-table and variable-occupancy selling at the same time");if(o.variableOccupancy===!1&&(o.minOccupancy!==void 0||o.maxOccupancy!==void 0))throw new u("invalid_operation","Guest bounds can be supplied only with variable-occupancy selling");let l=(p,m,w,S)=>{if(m!==void 0&&(!Number.isFinite(m)||m<w||m>S))throw new u("invalid_operation",`${String(p)} must be from ${w} to ${S}`)};if(l("rotation",o.rotation,0,360),l("radius",o.radius,24,160),l("seatArc",o.seatArc,120,360),l("width",o.width,40,320),l("height",o.height,30,240),o.minOccupancy!==void 0&&(!Number.isInteger(o.minOccupancy)||o.minOccupancy<1||o.minOccupancy>40))throw new u("invalid_operation","minOccupancy must be a whole number from 1 to 40");if(o.maxOccupancy!==void 0&&(!Number.isInteger(o.maxOccupancy)||o.maxOccupancy<1||o.maxOccupancy>40))throw new u("invalid_operation","maxOccupancy must be a whole number from 1 to 40");if(o.sides!==void 0){let p=new Set(["top","bottom","left","right"]);if(!o.sides.length||o.sides.length>4||new Set(o.sides).size!==o.sides.length||o.sides.some(m=>!p.has(m)))throw new u("invalid_operation","Table sides must contain one to four unique perimeter sides")}let d=ae(o,"Table"),g=Me(o,"Table"),h=i.map(p=>{if(p.seatCountsBySide&&!c&&(s||e.patch.sides!==void 0))throw new u("invalid_operation",`Table "${p.label}" has exact per-side counts; update seatCountsBySide instead of aggregate seatCount or legacy sides`,{tableId:p.id});let m=structuredClone(p);if(Object.assign(m,o),m.shape==="round"&&delete m.seatCountsBySide,m.overrides&&o.seatCount!==void 0&&(m.overrides=m.overrides.filter(w=>w.index<m.seatCount),m.overrides.length||delete m.overrides),o.bookAsWhole===!1&&delete m.bookAsWhole,o.variableOccupancy===!1&&(delete m.variableOccupancy,delete m.minOccupancy,delete m.maxOccupancy),m.bookAsWhole||delete m.bookAsWhole,m.variableOccupancy||delete m.variableOccupancy,m.bookAsWhole&&m.variableOccupancy)throw new u("invalid_operation",`Table "${m.label}" cannot use whole-table and variable-occupancy selling at the same time`,{tableId:m.id});if((m.bookAsWhole||m.variableOccupancy)&&m.overrides?.length)throw new u("invalid_operation",`Table "${m.label}" has individual-chair overrides; reset them before choosing grouped table selling`,{tableId:m.id,overriddenChairIndices:m.overrides.map(w=>w.index)});if(m.bookAsWhole)delete m.minOccupancy,delete m.maxOccupancy;else if(m.variableOccupancy){if(!Number.isInteger(m.minOccupancy)||!Number.isInteger(m.maxOccupancy)||m.minOccupancy<1||m.maxOccupancy<m.minOccupancy||m.maxOccupancy>m.seatCount)throw new u("invalid_operation",`Table "${m.label}" needs whole-number minimum and maximum guests from 1 to its ${m.seatCount}-chair capacity`,{tableId:m.id,seatCount:m.seatCount})}else{if(o.minOccupancy!==void 0||o.maxOccupancy!==void 0)throw new u("invalid_operation","Guest bounds can be changed only on a variable-occupancy table",{tableId:m.id});delete m.minOccupancy,delete m.maxOccupancy}if(g&&delete m.displayType,d&&delete m.displayLabel,m.shape==="rect"){if(m.width??=80,m.height??=50,m.seatCountsBySide){let w=["top","bottom","left","right"],S=w.reduce((I,M)=>I+m.seatCountsBySide[M],0);if(S!==m.seatCount)throw new u("invalid_operation",`Table "${m.label}" side counts total ${S}, but seatCount is ${m.seatCount}`,{tableId:m.id,seatCount:m.seatCount,seatCountsBySide:m.seatCountsBySide});m.sides=w.filter(I=>m.seatCountsBySide[I]>0)}}else m.radius??=40;if((m.bookAsWhole||m.variableOccupancy)&&Vt(m.label))throw new u("invalid_operation",`Grouped table label "${m.label}" uses SeatLayer's reserved GA namespace`,{tableId:m.id});return m}),f=new Map(h.map(p=>[p.id,p])),b=new Set(r),y=new Map;for(let p of G(t))for(let m of p.objects){let w=m.type==="table"?f.get(m.id)??m:m,S=[];w.type==="row"?S=z(w).map(I=>I.label):w.type==="table"?S=w.bookAsWhole||w.variableOccupancy?[w.label]:Y(w).map(I=>I.label):w.type==="booth"?S=[w.label]:w.type==="gaArea"&&(S=te(w));for(let I of S){let M=y.get(I);if(M&&(b.has(M)||b.has(w.id)))throw new u("invalid_operation",`Inventory label "${I}" is already in use; grouped table labels must be unique`,{tableIds:r,inventoryLabel:I,conflictingObjectIds:[M,w.id]});y.set(I,M??w.id)}}let x=!1,v=["bookAsWhole","variableOccupancy","minOccupancy","maxOccupancy","displayLabel","displayType","seatCountsBySide","overrides"];for(let[p,m]of i.entries()){let w=h[p],S=JSON.stringify(m);for(let I of v)I in w||delete m[I];Object.assign(m,w),JSON.stringify(m)!==S&&(x=!0)}return{floorId:n.floorId,changed:x,tableIds:r}}function dr(t,e){let n=C(t,e.floorId),r=[...new Set(e.boothIds)];if(!r.length)throw new u("invalid_operation","At least one booth id is required");let i=r.map(f=>n.objects.find(b=>b.type==="booth"&&b.id===f)),a=r.filter((f,b)=>!i[b]);if(a.length)throw new u("object_not_found",`Unknown booth id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current booth ids.`,{boothIds:a});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new u("invalid_operation","At least one booth change is required");if(o.label!==void 0){if(o.label=o.label.normalize("NFKC").trim(),r.length!==1)throw new u("invalid_operation","label can be changed only for one booth at a time");if(!o.label||o.label.length>80)throw new u("invalid_operation","Booth labels must contain 1 to 80 characters")}o.categoryKey!==void 0&&k(t,o.categoryKey);let s=(f,b,y,x)=>{if(b!==void 0&&(!Number.isFinite(b)||b<y||b>x))throw new u("invalid_operation",`${f} must be from ${y} to ${x}`)};s("width",o.width,30,400),s("height",o.height,30,400),s("rotation",o.rotation,0,360);let c=o.points===null;if(o.points!=null){if(r.length!==1)throw new u("invalid_operation","points can be changed only for one booth at a time");let f=en(o.points);if(!f.ok)throw new u("invalid_operation",f.message??"The booth outline is not a valid simple polygon")}let l=o.points!=null?o.points.map(f=>({x:f.x,y:f.y})):void 0;delete o.points;let d=ae(o,"Booth"),g=Me(o,"Booth"),h=!1;for(let f of i){let b=JSON.stringify(f);Object.assign(f,o),d&&delete f.displayLabel,g&&delete f.displayType,c?delete f.points:l&&(f.points=l),JSON.stringify(f)!==b&&(h=!0)}return{floorId:n.floorId,changed:h,boothIds:r}}function ur(t,e){let n=C(t,e.floorId),r=[...new Set(e.gaAreaIds)];if(!r.length)throw new u("invalid_operation","At least one GA area id is required");let i=r.map(d=>n.objects.find(g=>g.type==="gaArea"&&g.id===d)),a=r.filter((d,g)=>!i[g]);if(a.length)throw new u("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:a});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new u("invalid_operation","At least one GA area change is required");if(o.label!==void 0){if(o.label=o.label.normalize("NFKC").trim(),r.length!==1)throw new u("invalid_operation","label can be changed only for one GA area at a time");if(!o.label||o.label.length>80)throw new u("invalid_operation","GA area labels must contain 1 to 80 characters")}if(o.categoryKey!==void 0&&k(t,o.categoryKey),o.capacity!==void 0&&(!Number.isInteger(o.capacity)||o.capacity<1||o.capacity>1e5))throw new u("invalid_operation","capacity must be an integer from 1 to 100000");if(o.cornerRadius!==void 0&&(!Number.isFinite(o.cornerRadius)||o.cornerRadius<0||o.cornerRadius>2e3))throw new u("invalid_operation","cornerRadius must be from 0 to 2000");let s=ae(o,"GA area"),c=Me(o,"GA area");if(o.capacity!==void 0)for(let d of i){if(d.inventorySegments!==void 0&&o.capacity<d.capacity)throw new u("invalid_operation",`Joined GA area "${d.label}" cannot be reduced below ${d.capacity}; shrinking would delete stable inventory identities. Create or split a new surface instead.`,{gaAreaId:d.id,currentCapacity:d.capacity,requestedCapacity:o.capacity});if(d.inventorySegments!==void 0&&o.capacity>d.capacity&&dt(d,o.capacity)===void 0)throw new u("invalid_operation",`Joined GA area "${d.label}" cannot append that capacity safely`,{gaAreaId:d.id})}let l=!1;for(let d of i){let g=JSON.stringify(d),h=o.capacity===void 0?d.inventorySegments:dt(d,o.capacity);Object.assign(d,o),h!==void 0&&(d.inventorySegments=h),s&&delete d.displayLabel,c&&delete d.displayType,JSON.stringify(d)!==g&&(l=!0)}return{floorId:n.floorId,changed:l,gaAreaIds:r}}function Te(t,e){if(e.length<3)return 0;let n=i=>N(i,e,void 0),r=0;for(let i of t)n(L(i))&&(i.type==="row"?r+=z(i).length:i.type==="table"?r+=Y(i).length:(i.type==="gaArea"||i.type==="booth")&&(r+=W(i)));return r}function fr(t,e){let n=C(t,e.floorId);if(!e.objectIds.length)throw new u("invalid_operation","At least one chart object id is required");if(new Set(e.objectIds).size!==e.objectIds.length)throw new u("invalid_operation","Chart object ids must be unique");let r=e.objectIds.map(s=>n.objects.find(c=>c.id===s)),i=e.objectIds.filter((s,c)=>!r[c]);if(i.length)throw new u("object_not_found","One or more chart object ids do not exist on the selected floor",{objectIds:i});let a=r,o=new Set(e.objectIds);for(let s=n.objects.length-1;s>=0;s--)o.has(n.objects[s].id)&&n.objects.splice(s,1);return{floorId:n.floorId,changed:!0,removedObjects:a.map(s=>({id:s.id,type:s.type})),removedInventory:a.reduce((s,c)=>s+W(c),0),remainingObjectCount:n.objects.length}}function gr(t,e){let n=C(t,e.floorId),r=[...new Set(e.textIds)];if(!r.length)throw new u("invalid_operation","At least one text id is required");let i=r.map(l=>n.objects.find(d=>d.type==="text"&&d.id===l)),a=r.filter((l,d)=>!i[d]);if(a.length)throw new u("object_not_found",`Unknown text id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current text ids.`,{textIds:a});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new u("invalid_operation","At least one text change is required");if(o.text!==void 0){if(o.text=o.text.normalize("NFKC").trim(),r.length!==1)throw new u("invalid_operation","content can be changed only for one text object at a time");if(!o.text||o.text.length>240)throw new u("invalid_operation","Text content must contain 1 to 240 characters")}if(o.fontSize!==void 0&&(!Number.isFinite(o.fontSize)||o.fontSize<8||o.fontSize>72))throw new u("invalid_operation","Text fontSize must be from 8 to 72");if(o.fontFamily!==void 0&&o.fontFamily!==null&&(o.fontFamily=o.fontFamily.normalize("NFKC").trim(),!o.fontFamily||o.fontFamily.length>120))throw new u("invalid_operation","Text fontFamily must contain 1 to 120 characters");if(o.rotation!==void 0&&(!Number.isFinite(o.rotation)||o.rotation<0||o.rotation>360))throw new u("invalid_operation","Text rotation must be from 0 to 360");if(o.color!==void 0&&o.color!==null&&(o.color=F(o.color,"Text color")),o.bold!==void 0&&typeof o.bold!="boolean")throw new u("invalid_operation","Text bold must be a boolean");if(o.italic!==void 0&&typeof o.italic!="boolean")throw new u("invalid_operation","Text italic must be a boolean");if(o.width!==void 0&&o.width!==null&&(!Number.isFinite(o.width)||o.width<40||o.width>1200))throw new u("invalid_operation",`Text width must be from ${40} to ${1200}`);if(o.align!==void 0&&!["left","center","right"].includes(o.align))throw new u("invalid_operation","Text align must be left, center, or right");if(o.lineHeight!==void 0&&(!Number.isFinite(o.lineHeight)||o.lineHeight<.8||o.lineHeight>3))throw new u("invalid_operation",`Text lineHeight must be from ${.8} to ${3}`);if(o.letterSpacing!==void 0&&(!Number.isFinite(o.letterSpacing)||o.letterSpacing<-2||o.letterSpacing>20))throw new u("invalid_operation",`Text letterSpacing must be from ${-2} to ${20}`);if(o.underline!==void 0&&typeof o.underline!="boolean")throw new u("invalid_operation","Text underline must be a boolean");if(o.opacity!==void 0&&(!Number.isFinite(o.opacity)||o.opacity<.1||o.opacity>1))throw new u("invalid_operation",`Text opacity must be from ${.1} to 1`);if(o.background!==void 0&&o.background!==null){o.background.color=F(o.background.color,"Text background color");let{padding:l=6,cornerRadius:d=4,opacity:g=.9}=o.background;if(!Number.isFinite(l)||l<0||l>40)throw new u("invalid_operation",`Text background padding must be from 0 to ${40}`);if(!Number.isFinite(d)||d<0||d>40)throw new u("invalid_operation",`Text background cornerRadius must be from 0 to ${40}`);if(!Number.isFinite(g)||g<.1||g>1)throw new u("invalid_operation",`Text background opacity must be from ${.1} to 1`)}if(["width","align","lineHeight","letterSpacing","underline","opacity","background"].some(l=>Object.prototype.hasOwnProperty.call(o,l))&&i.some(l=>l.semanticKind==="icon"))throw new u("invalid_operation","Text layout fields cannot be applied to venue icons");if(o.iconKey!==void 0){if(!Zt(o.iconKey))throw new u("invalid_operation","iconKey must be a known venue-icon registry key");if(i.some(l=>l.semanticKind!=="icon"))throw new u("invalid_operation",'iconKey can be set only on venue-icon objects (semanticKind "icon")')}let c=!1;for(let l of i){let d=JSON.stringify(l);o.iconKey!==void 0&&(l.iconKey=o.iconKey),o.text!==void 0&&(l.text=o.text),o.fontSize!==void 0&&(l.fontSize=o.fontSize),o.fontFamily===null?delete l.fontFamily:o.fontFamily!==void 0&&(l.fontFamily=o.fontFamily),o.rotation!==void 0&&(l.rotation=o.rotation),o.color===null?delete l.color:o.color!==void 0&&(l.color=o.color),o.bold!==void 0&&(o.bold?l.bold=!0:delete l.bold),o.italic!==void 0&&(o.italic?l.italic=!0:delete l.italic),o.width===null?delete l.width:o.width!==void 0&&(l.width=o.width),o.align!==void 0&&(o.align==="left"?delete l.align:l.align=o.align),o.lineHeight!==void 0&&(o.lineHeight===1.2?delete l.lineHeight:l.lineHeight=o.lineHeight),o.letterSpacing!==void 0&&(o.letterSpacing===0?delete l.letterSpacing:l.letterSpacing=o.letterSpacing),o.underline!==void 0&&(o.underline?l.underline=!0:delete l.underline),o.opacity!==void 0&&(o.opacity===1?delete l.opacity:l.opacity=o.opacity),o.background===null?delete l.background:o.background!==void 0&&(l.background=o.background),JSON.stringify(l)!==d&&(c=!0)}return{floorId:n.floorId,changed:c,textIds:r}}function hr(t,e){let n=C(t,e.floorId),r=[...new Set(e.rowIds)],i=r.map(l=>n.objects.find(d=>d.type==="row"&&d.id===l)),a=r.filter((l,d)=>!i[d]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let o=i.slice().sort((l,d)=>l.origin.y-d.origin.y||l.origin.x-d.origin.x),s=Lt(o.map(l=>({label:l.label})),e.options),c=!1;return o.forEach((l,d)=>{l.label!==s[d].label&&(c=!0),l.label=s[d].label}),{floorId:n.floorId,changed:c,rows:o.map(l=>({id:l.id,label:l.label}))}}function br(t,e){let n=qt.find(l=>l.key===e.blockKey);if(!n)throw new u("invalid_operation",`Unknown seating block: ${e.blockKey}`,{blockKey:e.blockKey});let r=C(t,e.floorId),i=new Set,a=n.build().map(l=>structuredClone(l));for(let l of a)l.id=_(t,l.type,e.idFactory,i),Wt(l,e.center.x,e.center.y);for(let l of n.categories)t.categories.some(d=>d.key===l.key)||t.categories.push({...l});let o=a.filter(l=>l.type==="row");if(o.length){let l=0;for(let d of r.objects){if(d.type!=="row")continue;let g=Xt(d.label);g!=null&&(l=Math.max(l,g+1))}for(let d of o)d.label=B(l++)}let s=new Set(r.objects.flatMap(l=>"label"in l&&l.label?[l.label]:[]));for(let l of a){if((l.type==="table"||l.type==="booth")&&s.has(l.label)){let d=/^(.*?)(\d+)$/.exec(l.label),g=d?d[1]:`${l.label} `,h=d?Number.parseInt(d[2],10):1;do h++;while(s.has(`${g}${h}`));l.label=`${g}${h}`}"label"in l&&l.label&&s.add(l.label)}r.objects.push(...a);let c=null;if(n.sectionLabel&&e.wrapInSection!==!1){let l=Z(a);if(l){let d={type:"section",id:_(t,"sec",e.idFactory,i),label:n.sectionLabel,outline:l};r.objects.push(d),c=d.id}}return{floorId:r.floorId,blockKey:n.key,createdIds:[...a.map(l=>l.id),...c?[c]:[]],sectionId:c}}function pr(t){let e=structuredClone(t);if([e.start,e.control1,e.control2,e.end].some(a=>!Number.isFinite(a.x)||!Number.isFinite(a.y)))throw new u("invalid_operation","Exact row path points must be finite");let r=Ie(e,97),i=r.slice(1).reduce((a,o,s)=>a+Math.hypot(o.x-r[s].x,o.y-r[s].y),0);if(!Number.isFinite(i)||i<1)throw new u("invalid_operation","Exact row path must have at least one chart unit of usable length");return{path:e,length:i}}function on(t,e){let n=C(t,e.floorId),r=n.objects.find(d=>d.type==="row"&&d.id===e.rowId);if(!r)throw new u("object_not_found",`Unknown row id: ${e.rowId}`,{rowId:e.rowId});let i=pr(e.path),a=z(r),o=structuredClone(r);o.path=i.path,o.origin={...i.path.start};let s=z(o),c=a.map((d,g)=>Math.hypot(d.x-s[g].x,d.y-s[g].y)),l=JSON.stringify(r.path)!==JSON.stringify(i.path)||r.origin.x!==i.path.start.x||r.origin.y!==i.path.start.y;return{floorId:n.floorId,rowId:r.id,seatCount:r.seatCount,pathLength:i.length,averageSeatMovement:c.length?c.reduce((d,g)=>d+g,0)/c.length:0,maxSeatMovement:c.length?Math.max(...c):0,convertingFromParametric:!r.path,changed:l,preservesStableId:!0,preservesSeatMetadata:!0,preservesInventoryUnits:r.seatCount}}function mr(t,e){let n=on(t,e);if(!n.changed)return n;let i=C(t,n.floorId).objects.find(a=>a.type==="row"&&a.id===n.rowId);return i.path=structuredClone(e.path),i.origin={...e.path.start},delete i.arcFanGeneration,delete i.rowBlockGeneration,n}function yr(t,e){let n=t.map((r,i)=>[...r,e[i]]);for(let r=0;r<3;r++){let i=r;for(let o=r+1;o<3;o++)Math.abs(n[o][r])>Math.abs(n[i][r])&&(i=o);if(Math.abs(n[i][r])<1e-9)return null;[n[r],n[i]]=[n[i],n[r]];let a=n[r][r];for(let o=r;o<4;o++)n[r][o]/=a;for(let o=0;o<3;o++){if(o===r)continue;let s=n[o][r];for(let c=r;c<4;c++)n[o][c]-=s*n[r][c]}}return[n[0][3],n[1][3],n[2][3]]}function wr(t){if(t.length<3)return null;let e=[[0,0,0],[0,0,0],[0,0,0]],n=[0,0,0];for(let i of t){if(!Number.isFinite(i.x)||!Number.isFinite(i.y))return null;let a=[2*i.x,2*i.y,1],o=i.x**2+i.y**2;for(let s=0;s<3;s++){n[s]+=a[s]*o;for(let c=0;c<3;c++)e[s][c]+=a[s]*a[c]}}let r=yr(e,n);return r?{x:r[0],y:r[1]}:null}function tn(t){let e=((t+180)%360+360)%360-180;return e===-180&&(e=180),e}function rn(t,e){let n=C(t,e.floorId),r=n.objects.find(f=>f.type==="section"&&f.id===e.sectionId);if(!r)throw new u("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});let i=e.strength??100;if(!Number.isFinite(i)||i<0||i>100)throw new u("invalid_operation","Section row-fit strength must be from 0 to 100");let a=G(t).find(f=>f.id===n.floorId),o=e.mode==="outline"?wr(r.outline):e.focalPoint??a.focalPoint??t.focalPoint;if(!o||!Number.isFinite(o.x)||!Number.isFinite(o.y))throw new u("invalid_operation",`Section ${e.mode} fit has no finite center`);let s=n.objects.filter(f=>f.type==="row"&&N(L(f),r.outline,r.holes)),c=s.filter(f=>!!f.path).map(f=>f.id),l=[],d=[],g=i/100;for(let f of s){if(f.path)continue;if(f.seatCount<2){l.push(f.id);continue}let b=Math.hypot(f.origin.x-o.x,f.origin.y-o.y);if(b<=f.seatSpacing/2+1e-6){l.push(f.id);continue}let y=2*Math.asin(f.seatSpacing/(2*b))/X,x=z(f),v=Math.atan2(f.origin.x-o.x,f.origin.y-o.y)/X,m=(f.curve!==0?Math.sign(f.curve):x.length>1&&Math.sign(tn(Math.atan2(x[1].x-o.x,x[1].y-o.y)/X-v))||1)*y*(f.seatCount-1);if(Math.abs(m)>320){l.push(f.id);continue}let w=-v,S=f.curve+(m-f.curve)*g,I=f.rotation+tn(w-f.rotation)*g,M={...f,curve:S,rotation:I},T=z(M).map((U,K)=>Math.hypot(U.x-x[K].x,U.y-x[K].y));d.push({rowId:f.id,fromCurve:f.curve,targetCurve:m,resultCurve:S,fromRotation:f.rotation,resultRotation:I,rmsMovement:Math.sqrt(T.reduce((U,K)=>U+K**2,0)/T.length),maxMovement:Math.max(...T)})}let h=d.map(f=>f.rmsMovement);return{floorId:n.floorId,sectionId:r.id,mode:e.mode,fitCenter:{...o},strength:i,rows:d,skippedPathRowIds:c,skippedInvalidRowIds:l,averageMovement:h.length?h.reduce((f,b)=>f+b,0)/h.length:0,maxMovement:d.length?Math.max(...d.map(f=>f.maxMovement)):0}}function xr(t,e){let n=rn(t,e),r=C(t,n.floorId),i=r.objects.find(o=>o.type==="section"&&o.id===n.sectionId),a=!1;for(let o of n.rows){let s=r.objects.find(c=>c.type==="row"&&c.id===o.rowId);(s.curve!==o.resultCurve||s.rotation!==o.resultRotation)&&(s.curve=o.resultCurve,s.rotation=o.resultRotation,delete s.arcFanGeneration,delete s.rowBlockGeneration,a=!0)}return(i.smoothing??0)!==n.strength&&(i.smoothing=n.strength,a=!0),{...n,changed:a}}function an(t,e,n,r){let i=J(t,e,n),a=J(t,e,r),o=J(n,r,t),s=J(n,r,e);return i*a<-1e-9&&o*s<-1e-9}function nn(t,e){return t.some((n,r)=>{let i=t[(r+1)%t.length];return e.some((a,o)=>an(n,i,a,e[(o+1)%e.length]))})}function Sr(t){if(t.length<3||t.length>256||Math.abs(de(t))<1||t.some(e=>!Number.isFinite(e.x)||!Number.isFinite(e.y)))return!1;for(let e=0;e<t.length;e++)for(let n=e+1;n<t.length;n++)if(!(n===e+1||e===0&&n===t.length-1)&&an(t[e],t[(e+1)%t.length],t[n],t[(n+1)%t.length]))return!1;return!0}function Ee(t,e,n){let r=C(t,e),i=r.objects.find(a=>(a.type==="section"||a.type==="gaArea")&&a.id===n);if(!i)throw new u("object_not_found",`Unknown polygon object id: ${n}`,{objectId:n});return{target:r,object:i,outer:i.type==="section"?i.outline:i.points}}function Ne(t,e){let{target:n,object:r,outer:i}=Ee(t,e.floorId,e.objectId),a=structuredClone(e.points);if(!Sr(a))throw new u("invalid_operation","Opening must be a finite, non-self-intersecting shape with 3\u2013256 corners");if(a.some(l=>!N(l,i,void 0)))throw new u("invalid_operation","Every opening corner must stay inside the outer boundary");if(nn(a,i))throw new u("invalid_operation","Opening edges cannot cross the outer boundary");let o=r.holes??[],s=e.holeIndex??o.length;if(!Number.isInteger(s)||s<0||s>o.length||e.holeIndex!=null&&s>=o.length)throw new u("invalid_operation","Opening not found");for(let l=0;l<o.length;l++){if(l===e.holeIndex)continue;let d=o[l];if(nn(a,d)||N(a[0],d,void 0)||N(d[0],a,void 0))throw new u("invalid_operation","Openings cannot overlap or contain one another")}let c=n.objects.filter(l=>l.id!==r.id&&l.type!=="section"&&N(L(l),a,void 0));return{floorId:n.floorId,objectId:r.id,objectType:r.type,holeIndex:s,vertexCount:a.length,excludedObjectIds:c.map(l=>l.id),excludedInventoryUnits:Te(n.objects.filter(l=>l.id!==r.id),a),preservesExactOuterPath:r.type==="section"&&!!r.outlinePath}}function Ir(t,e){let n=Ne(t,e),{object:r}=Ee(t,n.floorId,n.objectId);return r.holes??=[],e.holeIndex==null?r.holes.push(structuredClone(e.points)):r.holes[e.holeIndex]=structuredClone(e.points),{...n,changed:!0}}function sn(t,e){let{target:n,object:r}=Ee(t,e.floorId,e.objectId);if(!Number.isInteger(e.holeIndex)||e.holeIndex<0||e.holeIndex>=(r.holes?.length??0))throw new u("invalid_operation","Opening not found");let i=r.holes[e.holeIndex],a=n.objects.filter(o=>o.id!==r.id&&o.type!=="section"&&N(L(o),i,void 0));return{floorId:n.floorId,objectId:r.id,objectType:r.type,holeIndex:e.holeIndex,vertexCount:i.length,excludedObjectIds:a.map(o=>o.id),excludedInventoryUnits:Te(n.objects.filter(o=>o.id!==r.id),i),preservesExactOuterPath:r.type==="section"&&!!r.outlinePath}}function vr(t,e){let n=sn(t,e),{object:r}=Ee(t,n.floorId,n.objectId);return r.holes.splice(e.holeIndex,1),r.holes.length||delete r.holes,{...n,changed:!0}}function Cr(t){let e=t.trim();if(!e||e.length>2e6||!/^(https:\/\/|data:image\/)/.test(e))throw new u("invalid_operation","Section view photo must be an HTTPS or data:image URL no larger than 2 MB");return e}function cn(t,e){let n=[...new Set(e)];if(!n.length)throw new u("invalid_operation","At least one section id is required");let r=n.map(o=>t.find(s=>s.type==="section"&&s.id===o)),i=n.filter((o,s)=>!r[s]);if(i.length)throw new u("object_not_found",`Unknown section id(s): ${i.join(", ")} on the selected floor. Call get_chart to list current section ids.`,{sectionIds:i});let a=r;return{requested:n,sections:a,logicalSectionIds:[...new Set(a.map(o=>o.logicalSectionId??o.id))]}}function ln(t,e){let n=C(t,e.floorId),r=cn(n.objects,e.sectionIds),i=he(Oe(t,n.floorId)),a=new Map(i.sections.map(g=>[g.id,g])),o=new Map(n.objects.map(g=>[g.id,g])),s=r.logicalSectionIds.flatMap(g=>a.get(g)?.objectIds??[]),c=new Set;for(let g of s){let h=o.get(g);if(h)if(h.type==="row"||h.type==="table")for(let f of Re(h).keys())c.add(f);else(h.type==="booth"||h.type==="gaArea")&&c.add(h.categoryKey)}let l=r.logicalSectionIds.every(g=>(a.get(g)?.seatCount??0)>0),d=r.logicalSectionIds.every(g=>a.get(g)?.objectIds.some(h=>{let f=o.get(h);return f?.type==="row"||f?.type==="table"||f?.type==="booth"})===!0);return{floorId:n.floorId,sectionIds:r.requested,logicalSectionIds:r.logicalSectionIds,objectIds:s,categoryApplicable:l,...l&&c.size===1?{categoryKey:[...c][0]}:{},categoryMixed:l&&c.size!==1,viewApplicable:d}}function Pr(t,e){k(t,e.categoryKey);let n=ln(t,e);if(!n.categoryApplicable)throw new u("invalid_operation","Every selected logical section must contain buyer inventory before a section category can be assigned",{logicalSectionIds:n.logicalSectionIds});let r=C(t,n.floorId),i=new Set(n.objectIds),a=!1,o=0;for(let s of r.objects){if(!i.has(s.id)||s.type!=="row"&&s.type!=="table"&&s.type!=="booth"&&s.type!=="gaArea"||(s.categoryKey!==e.categoryKey&&(s.categoryKey=e.categoryKey,a=!0),s.type!=="row"&&s.type!=="table"||!s.overrides?.length))continue;let c=s.overrides.flatMap(l=>{if(l.categoryKey===void 0)return[l];let d={...l};return delete d.categoryKey,o++,a=!0,Object.keys(d).some(g=>g!=="index")?[d]:[]});c.length?s.overrides=c:delete s.overrides}return{...n,changed:a,categoryKey:e.categoryKey,categoryMixed:!1,clearedSeatOverrideCount:o}}function Or(t,e){let n=C(t,e.floorId),r=cn(n.objects,e.sectionIds),{requested:i}=r,a=structuredClone(e.patch),o=new Set(["label","displayLabel","entrance","viewFromSeatUrl","viewFromSeatMeta","labelPresentation","labelStyle","zone","elevation","height","rake","surfaceKind","color"]),s=Object.keys(a).filter(f=>!o.has(f));if(s.length)throw new u("invalid_operation",`Unsupported section metadata field(s): ${s.join(", ")}`);if(!Object.keys(a).length)throw new u("invalid_operation","At least one section metadata change is required");if(a.label!==void 0){if(a.label=a.label.normalize("NFKC").trim(),i.length!==1)throw new u("invalid_operation","label can be changed only for one section at a time");if(!a.label||a.label.length>80)throw new u("invalid_operation","Section labels must contain 1 to 80 characters")}if(a.displayLabel!==void 0&&a.displayLabel!==null){if(a.displayLabel=a.displayLabel.normalize("NFKC").trim(),i.length!==1)throw new u("invalid_operation","displayLabel can be changed only for one section at a time");if(!a.displayLabel||a.displayLabel.length>80)throw new u("invalid_operation","Section display labels must contain 1 to 80 characters")}if(a.entrance!==void 0&&a.entrance!==null&&(a.entrance=a.entrance.normalize("NFKC").trim(),a.entrance.length>40))throw new u("invalid_operation","Section entrance must be at most 40 characters");if(a.viewFromSeatUrl!==void 0&&a.viewFromSeatUrl!==null&&(a.viewFromSeatUrl=Cr(a.viewFromSeatUrl)),a.labelPresentation?.position&&(!Number.isFinite(a.labelPresentation.position.x)||!Number.isFinite(a.labelPresentation.position.y)))throw new u("invalid_operation","Section label position must be finite");if(a.labelPresentation?.rotation!=null&&!Number.isFinite(a.labelPresentation.rotation))throw new u("invalid_operation","Section label rotation must be finite");if(a.labelPresentation!==void 0&&Ae(a.labelPresentation,"Section"),a.labelStyle!==void 0&&se(a.labelStyle,"Section"),a.zone!==void 0&&a.zone!==null&&!(t.zones??[]).some(f=>f.id===a.zone))throw new u("object_not_found",`Unknown chart zone: ${a.zone}`,{zoneId:a.zone});if(a.elevation!==void 0&&(!Number.isInteger(a.elevation)||a.elevation<0||a.elevation>3))throw new u("invalid_operation","Section elevation must be an integer from 0 to 3");if(a.height!==void 0&&a.height!==null&&(!Number.isFinite(a.height)||a.height<0||a.height>120))throw new u("invalid_operation","Section height must be a number from 0 to 120 metres");if(a.rake!==void 0&&a.rake!==null&&(!Number.isFinite(a.rake)||a.rake<0||a.rake>45))throw new u("invalid_operation","Section rake must be a number from 0 to 45 degrees");if(a.surfaceKind!==void 0&&a.surfaceKind!==null&&a.surfaceKind!=="flat"&&a.surfaceKind!=="rakedRows")throw new u("invalid_operation","Section surfaceKind must be 'flat' or 'rakedRows'");a.color!==void 0&&a.color!==null&&(a.color=F(a.color,"Section color"));let c=a.displayLabel!==void 0||a.entrance!==void 0||a.viewFromSeatUrl!==void 0||a.viewFromSeatMeta!==void 0||a.labelStyle!==void 0||a.zone!==void 0,l=new Set(r.logicalSectionIds),d=c?n.objects.filter(f=>f.type==="section"&&l.has(f.logicalSectionId??f.id)):[],g=new Set,h=!1;for(let f of r.sections){let b=JSON.stringify(f);a.label!==void 0&&(f.label=a.label),a.labelPresentation===null?delete f.labelPresentation:a.labelPresentation!==void 0&&(f.labelPresentation=a.labelPresentation),a.elevation!==void 0&&(f.elevation=a.elevation);let y=x=>{f.physical3dProvenance&&(delete f.physical3dProvenance[x],Object.keys(f.physical3dProvenance).length===0&&delete f.physical3dProvenance)};a.height===null?(delete f.height,y("height")):a.height!==void 0&&(f.height=a.height,f.physical3dProvenance={...f.physical3dProvenance,height:{status:"confirmed",source:"user-review",note:"Section front-edge height reviewed through the shared Designer/Copilot operation."}}),a.rake===null?(delete f.rake,y("rake")):a.rake!==void 0&&(f.rake=a.rake,f.physical3dProvenance={...f.physical3dProvenance,rake:{status:"confirmed",source:"user-review",note:"Section rake reviewed through the shared Designer/Copilot operation."}}),a.surfaceKind===null?(delete f.surfaceKind,y("surfaceKind")):a.surfaceKind!==void 0&&(f.surfaceKind=a.surfaceKind,f.physical3dProvenance={...f.physical3dProvenance,surfaceKind:{status:"confirmed",source:"user-review",note:"Section surface behavior reviewed through the shared Designer/Copilot operation."}}),a.color===null?delete f.color:a.color!==void 0&&(f.color=a.color),JSON.stringify(f)!==b&&(h=!0,g.add(f.id))}for(let f of d){let b=JSON.stringify(f),y=f.viewFromSeatUrl;if(a.displayLabel===null?delete f.displayLabel:a.displayLabel!==void 0&&(f.displayLabel=a.displayLabel),a.entrance===null||a.entrance===""?delete f.entrance:a.entrance!==void 0&&(f.entrance=a.entrance),a.viewFromSeatUrl===null||a.viewFromSeatUrl===""?delete f.viewFromSeatUrl:a.viewFromSeatUrl!==void 0&&(f.viewFromSeatUrl=a.viewFromSeatUrl),!f.viewFromSeatUrl||a.viewFromSeatMeta===null?delete f.viewFromSeatMeta:a.viewFromSeatMeta!==void 0?f.viewFromSeatMeta=structuredClone(a.viewFromSeatMeta):a.viewFromSeatUrl!==void 0&&f.viewFromSeatUrl!==y&&delete f.viewFromSeatMeta,a.labelStyle!==void 0){let x=_e(f.labelPresentation,a.labelStyle);x?f.labelPresentation=x:delete f.labelPresentation}a.zone===null?delete f.zone:a.zone!==void 0&&(f.zone=a.zone),JSON.stringify(f)!==b&&(h=!0,g.add(f.id))}return{floorId:n.floorId,changed:h,sectionIds:i,affectedSectionIds:[...g]}}function dn(t,e){let n=C(t,e.floorId),r=n.objects.find(a=>a.type==="section"&&a.id===e.sectionId);if(!r)throw new u("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});if(r.outlinePath)throw new u("invalid_operation",`Section ${r.id} has an exact path; polygon conversion requires a separate loss review`,{sectionId:r.id,representation:"exact-path"});if(!r.geometry)throw new u("invalid_operation",`Section ${r.id} is already a manual polygon`,{sectionId:r.id,representation:"manual-polygon"});let i=n.objects.filter(a=>a.id!==r.id&&a.type!=="section"&&N(L(a),r.outline,r.holes));return{floorId:n.floorId,sectionId:r.id,sectionLabel:r.label,source:{representation:"generated-polygon",generator:structuredClone(r.geometry)},target:{representation:"manual-polygon"},geometryChanged:!1,preserved:{stableId:!0,outlineVertexCount:r.outline.length,holeCount:r.holes?.length??0,memberObjectIds:i.map(a=>a.id),inventoryUnits:i.reduce((a,o)=>a+W(o),0),durableReferenceSource:!!r.referenceSource,inventoryExclusionEvidence:!!r.referenceInventoryExclusion},removedFields:["geometry"]}}function Mr(t,e){let n=dn(t,e),i=C(t,n.floorId).objects.find(a=>a.type==="section"&&a.id===n.sectionId);return delete i.geometry,{...n,changed:!0}}function un(t,e){let n=(...s)=>s.every(Number.isFinite),r,i=1,a=!1,o=!0;if(e.kind==="translate"){if(!n(e.dx,e.dy))throw new u("invalid_operation","Section translation must be finite");o=e.dx!==0||e.dy!==0,r=s=>({x:s.x+e.dx,y:s.y+e.dy})}else if(e.kind==="scale"){if(!n(e.factor)||e.factor<=0||e.factor>100)throw new u("invalid_operation","Section scale factor must be finite and greater than 0");o=e.factor!==1,i=e.factor;let s=L(t);r=c=>({x:s.x+(c.x-s.x)*e.factor,y:s.y+(c.y-s.y)*e.factor})}else if(e.kind==="rotate"){if(!n(e.degrees))throw new u("invalid_operation","Section rotation must be finite");o=(e.degrees%360+360)%360!==0;let c=e.degrees*Math.PI/180,l=Math.cos(c),d=Math.sin(c),g=L(t);r=h=>{let f=h.x-g.x,b=h.y-g.y;return{x:g.x+f*l-b*d,y:g.y+f*d+b*l}}}else{if(!n(e.coordinate))throw new u("invalid_operation","Section reflection coordinate must be finite");a=!0,r=e.axis==="h"?s=>({x:2*e.coordinate-s.x,y:s.y}):s=>({x:s.x,y:2*e.coordinate-s.y})}return o&&(t.outline=t.outline.map(r),t.sourceOutline&&(t.sourceOutline=t.sourceOutline.map(r)),t.outlinePath&&(t.outlinePath=Ye(t.outlinePath,r,i,a)),t.holes&&(t.holes=t.holes.map(s=>s.map(r)))),{changed:o,sectionId:t.id,representation:t.outlinePath?"exact-path":"polygon",outlineVertexCount:t.outline.length,holeCount:t.holes?.length??0,pathSegmentKinds:t.outlinePath?.segments.map(s=>s.kind)??[]}}function Ar(t,e){let n=C(t,e.floorId),r=n.objects.find(i=>i.type==="section"&&i.id===e.sectionId);if(!r)throw new u("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});return{floorId:n.floorId,...un(r,e.transform)}}function _r(t,e){let n=C(t,e.floorId),r=n.objects.find(s=>s.type==="section"&&s.id===e.sectionId);if(!r)throw new u("object_not_found",`Unknown section id: ${e.sectionId}`,{sectionId:e.sectionId});let i=structuredClone(e.path);if(!ve(i))throw new u("invalid_operation","Exact section path is not finite, continuous, closed, or radius-correct");let a=Qe(i),o=JSON.stringify(r.outlinePath)!==JSON.stringify(i)||JSON.stringify(r.outline)!==JSON.stringify(a)||r.sourceOutline!==void 0||r.cornerSmoothing!==void 0;return o&&(r.outlinePath=i,r.outline=a,delete r.geometry,delete r.sourceOutline,delete r.cornerSmoothing),{floorId:n.floorId,sectionId:r.id,changed:o,segmentKinds:i.segments.map(s=>s.kind),sampledVertexCount:a.length,holeCount:r.holes?.length??0}}function jr(t){return t.geometry?null:t.sourceOutline?.length?t.sourceOutline:t.outlinePath?null:t.outline?.length?t.outline:null}function kr(t,e){return fn(t,{floorId:e.floorId,sectionIds:e.sectionIds,cornerSmoothing:e.strength})}function fn(t,e){let n=C(t,e.floorId);if(e.cornerSmoothing!==void 0&&!Number.isFinite(e.cornerSmoothing))throw new u("invalid_operation","Corner smoothing must be a number from 0 to 100");if(e.edgeCurvature!=null&&e.edgeCurvature.some(s=>!Number.isFinite(s)))throw new u("invalid_operation","Edge curvature values must be numbers from -100 to 100");let r=[...new Set(e.sectionIds)],i=new Set,a=new Map,o=!1;try{for(let s of r){let c=n.objects.find(p=>p.type==="section"&&p.id===s);if(!c||!jr(c))continue;let d=structuredClone(c);a.set(c.id,{section:c,snapshot:d});let g=JSON.stringify(c),h=(c.sourceOutline??c.outline).map(p=>({...p})),f=Math.min(100,Math.max(0,e.cornerSmoothing??c.cornerSmoothing??0)),y=(e.edgeCurvature===void 0?c.edgeCurvature:e.edgeCurvature??void 0)?.map(p=>Math.min(100,Math.max(-100,p))),x=y?.some(p=>Math.abs(p)>.5)===!0,v=f>.5||x?_t(h,{cornerSmoothing:f,...x?{edgeCurvature:y}:{}}):null;v?(c.sourceOutline=h,c.outlinePath=v,c.outline=Qe(v),f>.5?c.cornerSmoothing=f:delete c.cornerSmoothing,x?c.edgeCurvature=[...y]:delete c.edgeCurvature):(c.outline=h,delete c.outlinePath,delete c.sourceOutline,delete c.cornerSmoothing,delete c.edgeCurvature);for(let p=0;p<(c.holes?.length??0);p+=1)Ne(t,{floorId:n.floorId,objectId:c.id,points:c.holes[p],holeIndex:p});JSON.stringify(c)!==g&&(o=!0,i.add(c.id))}}catch(s){for(let{section:c,snapshot:l}of a.values()){let d=c;for(let g of Object.keys(d))delete d[g];Object.assign(c,structuredClone(l))}throw s}return{floorId:n.floorId,changed:o,sectionIds:r,affectedSectionIds:[...i]}}var Rr=/^#?([\da-f]{3}|[\da-f]{6})$/i;function De(t){let e=Rr.exec((t??"").trim());if(!e)return null;let n=e[1].length===3?e[1].split("").map(i=>i+i).join(""):e[1],r=parseInt(n,16);return[r>>16&255,r>>8&255,r&255]}function gt(t){let e=t/255;return e<=.04045?e/12.92:((e+.055)/1.055)**2.4}function gn(t){return .2126*gt(t[0])+.7152*gt(t[1])+.0722*gt(t[2])}function Ge(t,e){let n=De(t),r=De(e);if(!n||!r)return null;let i=gn(n),a=gn(r);return(Math.max(i,a)+.05)/(Math.min(i,a)+.05)}var hn=["butt","round","square"],bn=["miter","round","bevel"],pn=["none","arrow"];function ht(t){return t==="line"||t==="polyline"}function mn(t){let e=De(t);if(!e)return null;let n=f=>{let b=f/255;return b<=.04045?b/12.92:((b+.055)/1.055)**2.4},r=n(e[0]),i=n(e[1]),a=n(e[2]),o=(.4124*r+.3576*i+.1805*a)/.95047,s=(.2126*r+.7152*i+.0722*a)/1,c=(.0193*r+.1192*i+.9505*a)/1.08883,l=f=>f>.008856?Math.cbrt(f):7.787*f+16/116,d=l(o),g=l(s),h=l(c);return[116*g-16,500*(d-g),200*(g-h)]}function yn(t,e){let n=mn(t),r=mn(e);return!n||!r?null:Math.hypot(n[0]-r[0],n[1]-r[1],n[2]-r[2])}var wn=[{key:"circle",label:"Standard seat",shortLabel:"Standard",useCase:"General assigned seating",group:"general",path:null,bounds:null},{key:"theatre",label:"Theatre chair",shortLabel:"Theatre",useCase:"Auditoriums, arenas and stadium stands",group:"fixed",path:"M4.5 3.5 Q4.5 1.5 6.5 1.5 L17.5 1.5 Q19.5 1.5 19.5 3.5 L19.5 13 L4.5 13 Z M3.5 12 L20.5 12 Q22.5 12 22.5 14 L22.5 21 Q22.5 22.5 21 22.5 Q19.5 22.5 19.5 21 L19.5 17.5 L4.5 17.5 L4.5 21 Q4.5 22.5 3 22.5 Q1.5 22.5 1.5 21 L1.5 14 Q1.5 12 3.5 12 Z",bounds:{x:1.5,y:1.5,width:21,height:21}},{key:"dining",label:"Dining chair",shortLabel:"Dining",useCase:"Banquets, restaurants and table seating",group:"flexible",path:"M7 1 Q6 1 6 2.5 L6.75 10.5 L5 10.5 Q4 10.5 4 12 L4 14 Q4 15 5.25 15 L6 15 L4 23 L7 23 L9.5 15 L14.5 15 L17 23 L20 23 L18 15 L18.75 15 Q20 15 20 14 L20 12 Q20 10.5 19 10.5 L17.25 10.5 L18 2.5 Q18 1 17 1 Z",bounds:{x:4,y:1,width:16,height:22}},{key:"folding",label:"Folding chair",shortLabel:"Folding",useCase:"Concert floors, ceremonies and conferences",group:"flexible",path:"M6 2 Q5 2 5 3 L6 8 L18 8 L19 3 Q19 2 18 2 Z M5 9 L19 9 Q20 9 20 10.5 L19 13 L5 13 L4 10.5 Q4 9 5 9 Z M6 12 L9 12 L12 17 L15 12 L18 12 L14 19 L17 23 L14 23 L12 21 L10 23 L7 23 L10 19 Z",bounds:{x:4,y:2,width:16,height:21}},{key:"armchair",label:"Premium armchair",shortLabel:"Armchair",useCase:"Boxes, lounges and club seating",group:"premium",path:"M3.5 4 Q3.5 1.5 6 1.5 L18 1.5 Q20.5 1.5 20.5 4 L20.5 13 L3.5 13 Z M1.5 12.5 Q1.5 10 3.25 10 Q5 10 5 12.5 L5 13.5 L19 13.5 L19 12.5 Q19 10 20.75 10 Q22.5 10 22.5 12.5 L22.5 19.5 Q22.5 22 20 22 L4 22 Q1.5 22 1.5 19.5 Z",bounds:{x:1.5,y:1.5,width:21,height:20.5}},{key:"recliner",label:"Recliner",shortLabel:"Recliner",useCase:"Luxury cinemas and premium clubs",group:"premium",path:"M7 2 Q7 1 8.5 1 L15.5 1 Q17 1 17 2 L19 13 L5 13 Z M4 9 Q2 9 2 11.5 L2 16 Q2 18 4 18 L6 18 L6 15 L18 15 L18 18 L20 18 Q22 18 22 16 L22 11.5 Q22 9 20 9 Q18 9 18 11 L18 13 L6 13 L6 11 Q6 9 4 9 Z M7 17 L17 17 Q18 17 18.5 18.5 L19.5 22.5 L4.5 22.5 L5.5 18.5 Q6 17 7 17 Z",bounds:{x:2,y:1,width:20,height:21.5}},{key:"stool",label:"Stool",shortLabel:"Stool",useCase:"Bars, high-tops and seating rails",group:"flexible",path:"M6 2.5 L18 2.5 Q22 2.5 22 6.5 L22 12 Q22 16 18 16 L6 16 Q2 16 2 12 L2 6.5 Q2 2.5 6 2.5 Z M6 15.5 L9.5 15.5 L7.5 22.5 L3 22.5 Z M14.5 15.5 L18 15.5 L20.5 22.5 L16 22.5 Z",bounds:{x:2,y:2.5,width:20,height:20}},{key:"bench",label:"Bench place",shortLabel:"Bench",useCase:"Pews, bleachers and terraces",group:"fixed",path:"M2.5 0.5 L21.5 0.5 Q23 0.5 23 2 L23 5 Q23 6.5 21.5 6.5 L2.5 6.5 Q1 6.5 1 5 L1 2 Q1 0.5 2.5 0.5 Z M2 7.5 L22 7.5 Q23.5 7.5 23.5 9 L23.5 15.5 Q23.5 17 22 17 L18 17 L18 21.5 Q18 22.5 16.75 22.5 Q15.5 22.5 15.5 21.5 L15.5 17 L8.5 17 L8.5 21.5 Q8.5 22.5 7.25 22.5 Q6 22.5 6 21.5 L6 17 L2 17 Q0.5 17 0.5 15.5 L0.5 9 Q0.5 7.5 2 7.5 Z",bounds:{x:.5,y:.5,width:23,height:22}}],vs=wn.map(t=>t.key),Lr=new Map(wn.map(t=>[t.key,t]));function me(t){return typeof t=="string"&&Lr.has(t)}var Fr=new Set(["companion","child","senior","student","membership","custom"]);function ye(t){if(!t.length)throw new u("invalid_operation","A chart must have at least one category");let e=new Set,n=new Map,r=structuredClone(t);for(let i of r){let a=i.key.trim(),o=i.label.normalize("NFKC").trim();if(!a||a.length>160||e.has(a))throw new u("invalid_operation",`Category keys must be non-empty and unique: ${a}`,{categoryKey:a});if(e.add(a),!o||o.length>80)throw new u("invalid_operation",`Category labels must contain 1 to 80 characters: ${a}`,{categoryKey:a});let s=o.toLocaleLowerCase("en"),c=n.get(s);if(c)throw new u("duplicate_category_label",`Categories ${c} and ${a} share the same label`,{categoryKeys:[c,a],label:o});if(n.set(s,a),!/^#[0-9a-fA-F]{6}$/.test(i.color))throw new u("invalid_operation",`Category ${a} must use a six-digit hex color`,{categoryKey:a});if(i.price!=null&&(!Number.isFinite(i.price)||i.price<0||i.price>1e6))throw new u("invalid_operation",`Category ${a} price must be from 0 to 1000000`,{categoryKey:a});if(i.seatGlyph!=null&&!me(i.seatGlyph))throw new u("invalid_operation",`Category ${a} has an unknown seat glyph`,{categoryKey:a,seatGlyph:i.seatGlyph});if((i.seatGlyph==null||i.seatGlyph==="circle")&&delete i.seatGlyph,i.tiers!=null)if(!i.tiers.length)delete i.tiers;else{if(i.tiers.length>20)throw new u("invalid_operation",`Category ${a} supports at most 20 ticket tiers`);let l=new Set,d=new Set;for(let g of i.tiers){let h=g.id.trim(),f=g.name.normalize("NFKC").trim(),b=f.toLocaleLowerCase("en");if(!h||h.length>160||l.has(h))throw new u("invalid_operation",`Ticket tier ids must be non-empty and unique in category ${a}`,{categoryKey:a,tierId:h});if(!f||f.length>80||d.has(b))throw new u("invalid_operation",`Ticket tier names must be non-empty and unique in category ${a}`,{categoryKey:a,tierName:f});if(!Number.isFinite(g.price)||g.price<0||g.price>1e6)throw new u("invalid_operation",`Ticket tier ${h} price must be from 0 to 1000000`,{categoryKey:a,tierId:h});if(g.restriction!=null&&!Fr.has(g.restriction))throw new u("invalid_operation",`Ticket tier ${h} has an unknown restriction`,{categoryKey:a,tierId:h});if(g.buyerMessage!=null){if(g.buyerMessage=g.buyerMessage.normalize("NFKC").trim(),!g.buyerMessage)delete g.buyerMessage;else if(g.buyerMessage.length>240)throw new u("invalid_operation",`Ticket tier ${h} buyer guidance must be at most 240 characters`,{categoryKey:a,tierId:h})}if(g.currency!=null&&(g.currency=g.currency.trim().toUpperCase(),!/^[A-Z]{3}$/.test(g.currency)))throw new u("invalid_operation",`Ticket tier ${h} must use a three-letter ISO currency`,{categoryKey:a,tierId:h});if(g.applicability!=null){let y=g.applicability.seatLabels?.map(v=>v.normalize("NFKC").trim()),x=g.applicability.accessibility;if(y&&(!y.length||y.length>1e4||y.some(v=>!v||v.length>160)||new Set(y).size!==y.length)||x&&(!x.length||x.some(v=>!fe.some(p=>p.key===v))||new Set(x).size!==x.length))throw new u("invalid_operation",`Ticket tier ${h} has invalid seat applicability`,{categoryKey:a,tierId:h});g.applicability={...y?{seatLabels:y}:{},...x?{accessibility:[...x]}:{}},!g.applicability.seatLabels&&!g.applicability.accessibility&&delete g.applicability}if(g.evidence!=null){if(!["public-host","public-event","user-confirmed"].includes(g.evidence.provenance)||typeof g.evidence.sourceDescription!="string")throw new u("invalid_operation",`Ticket tier ${h} has invalid evidence provenance`,{categoryKey:a,tierId:h});if(g.evidence.sourceDescription=g.evidence.sourceDescription.normalize("NFKC").trim(),!g.evidence.sourceDescription||g.evidence.sourceDescription.length>240||g.evidence.capturedAt!==void 0&&(g.evidence.capturedAt.length>40||!Number.isFinite(Date.parse(g.evidence.capturedAt))))throw new u("invalid_operation",`Ticket tier ${h} has invalid evidence provenance`,{categoryKey:a,tierId:h})}l.add(h),d.add(b)}}}return r}function In(t,e){let n=new Set,r=structuredClone(t.categories);for(let o of e.updates){if(n.has(o.categoryKey))throw new u("invalid_operation",`Category ${o.categoryKey} may be updated only once`);n.add(o.categoryKey);let s=r.find(g=>g.key===o.categoryKey);if(!s)throw new u("category_not_found",`Unknown chart category: ${o.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:o.categoryKey});let c=structuredClone(o.patch),{tiers:l,...d}=c;typeof d.label=="string"&&(d.label=d.label.normalize("NFKC").trim()),typeof d.color=="string"&&(d.color=d.color.toLowerCase()),Object.assign(s,d),s.notForSale===!1&&delete s.notForSale,Object.prototype.hasOwnProperty.call(c,"tiers")&&(l==null?delete s.tiers:s.tiers=l?.map(g=>{let h={...g,id:g.id.trim(),name:g.name.normalize("NFKC").trim()};return g.buyerMessage?.trim()?h.buyerMessage=g.buyerMessage.normalize("NFKC").trim():delete h.buyerMessage,h}))}let i=ye(r),a=JSON.stringify(i)!==JSON.stringify(t.categories);return a&&(t.categories=i),{changed:a,categoryKeys:[...n],categories:t.categories}}function Tr(t,e){let n=e.categoryKeys.map(c=>c.trim()),r=t.categories.map(c=>c.key);if(n.length!==r.length||new Set(n).size!==n.length)throw new u("invalid_operation","Category order must contain every stable category key exactly once",{categoryKeys:n,expectedCategoryKeys:r});let i=new Set(r),a=r.filter(c=>!n.includes(c)),o=n.filter(c=>!i.has(c));if(a.length||o.length)throw new u(o.length?"category_not_found":"invalid_operation","Category order must be an exact permutation of the current stable keys",{categoryKeys:n,missingCategoryKeys:a,unknownCategoryKeys:o});if(n.every((c,l)=>c===r[l]))return{changed:!1,categoryKeys:r,categories:t.categories};let s=new Map(t.categories.map(c=>[c.key,c]));return t.categories=ye(n.map(c=>structuredClone(s.get(c)))),{changed:!0,categoryKeys:n,categories:t.categories}}var bt=["#e69f00","#56b4e9","#009e73","#f0e442","#0072b2","#d55e00","#cc79a7"];function xn(t){let e=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i.exec(t.trim());if(!e)return null;let n=e[1];return n.length===3&&(n=n.split("").map(r=>r+r).join("")),[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)]}function Er(t,e){let n=xn(t),r=xn(e);return!n||!r?1/0:(n[0]-r[0])**2+(n[1]-r[1])**2+(n[2]-r[2])**2}var Nr=3600;function vn(t,e,n=bt){return n.find(i=>t.every(a=>Er(i,a)>=Nr))??n[e%n.length]}function Dr(t,e){let n=e?.palette??bt;if(!t.categories.length)return{changed:[],categories:t.categories};let r=new Map(t.categories.map(o=>[o.key,o.color.toLowerCase()])),i=t.categories.map((o,s)=>({categoryKey:o.key,patch:{color:n[s%n.length]}}));return In(t,{updates:i}),{changed:t.categories.map(o=>({key:o.key,from:r.get(o.key),to:o.color})).filter(o=>o.from!==o.to),categories:t.categories}}function Gr(t,e){let n=e.color.trim().toLowerCase(),r=e.sourceDescription.normalize("NFKC").trim();if(!/^#[0-9a-f]{6}$/.test(n))throw new u("invalid_operation","Sampled category color must be a six-digit hex color");if(!r||r.length>240)throw new u("invalid_operation","Color confirmation evidence must contain 1 to 240 characters");let i=structuredClone(t.categories),a=i.find(c=>c.key===e.categoryKey);if(!a)throw new u("category_not_found",`Unknown chart category: ${e.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:e.categoryKey});a.color=n,a.referenceCategorySource&&(a.referenceCategorySource.outputColorEvidence="user-confirmed",a.referenceCategorySource.outputColorSourceDescription=r);let o=ye(i),s=JSON.stringify(o)!==JSON.stringify(t.categories);return s&&(t.categories=o),{changed:s,category:t.categories.find(c=>c.key===e.categoryKey),categories:t.categories}}function Cn(t,e){let n=new Set(t.categories.map(o=>o.key)),r="";for(let o=0;o<100;o++){let c=e.idFactory("cat").trim();if(c&&!n.has(c)){r=c;break}}if(!r)throw new u("id_generation_failed","Unable to allocate a unique category id");let i={key:r,label:e.label.normalize("NFKC").trim(),color:e.color.toLowerCase(),price:e.price,tiers:e.tiers?.map(o=>({...o,id:o.id.trim(),name:o.name.normalize("NFKC").trim()}))},a=ye([...t.categories,i]);return t.categories=a,{changed:!0,category:a.find(o=>o.key===r),categories:a}}var Kr=["#e5484d","#a86b00","#8b5cf6","#d6336c","#4d7c0f","#dc2626","#c026d3"],$r={row:"#e5484d",table:"#a86b00",booth:"#8b5cf6",gaArea:"#4d7c0f"};function zr(t,e){let n=$r[t];return!n||!e.includes(n)?e:[n,...e.filter(r=>r!==n)]}var Br=26;function Ur(t,e,n){let r=(1-Math.abs(2*n-1))*e,i=(t%360+360)%360/60,a=r*(1-Math.abs(i%2-1)),[o,s,c]=i<1?[r,a,0]:i<2?[a,r,0]:i<3?[0,r,a]:i<4?[0,a,r]:i<5?[a,0,r]:[r,0,a],l=n-r/2,d=g=>Math.round((g+l)*255).toString(16).padStart(2,"0");return`#${d(o)}${d(s)}${d(c)}`}function Hr(t,e,n){let r=o=>t.every(s=>{let c=yn(o,s);return c==null||c>=Br}),i=o=>{let s=Ge(o,"#12151d"),c=Ge(o,"#ffffff");return(s??0)>=3||(c??0)>=3},a=e.find(o=>r(o)&&i(o));if(a)return a;for(let o=0;o<360;o+=12)for(let s of[.52,.44,.6]){let c=Ur(o,.62,s);if(r(c)&&i(c))return c}return n}function pt(t,e){let n=ke.find(i=>i.objectType===e).creationWord;return`${t.replace(/\s*[–-]\s*(Tables|Booths|Standing|Seats)$/i,"").trim()||t.trim()} \u2013 ${n}`}function Vr(t){let e=new Map;for(let n of G(t))for(let r of n.objects){let i=ke.find(o=>o.objectType===r.type);if(!i)continue;let a=new Set;if(r.type==="row"||r.type==="table")for(let o of Re(r).keys())a.add(o);else"categoryKey"in r&&r.categoryKey&&a.add(r.categoryKey);for(let o of a){let s=e.get(o)??new Set;s.add(i.objectType),e.set(o,s)}}return e}function Jr(t,e,n,r){let i=n,a=Vr(t),o=g=>{let h=a.get(g);return!h||h.size===0||h.size===1&&h.has(i)},s=t.categories.find(g=>g.key===e);if(s&&o(s.key))return s.key;if(!s){let g=t.categories.find(h=>{let f=a.get(h.key);return f?.size===1&&f.has(i)});if(g)return g.key}let c=s;if(!c)return Sn(t,n,void 0,r);let l=pt(c.label,n),d=t.categories.find(g=>g.label.toLowerCase()===l.toLowerCase()&&o(g.key));return d?d.key:Sn(t,n,c,r)}function Sn(t,e,n,r){let i=ke.find(b=>b.objectType===e),a=e==="gaArea"?"General Admission":i.creationWord,o=n?pt(n.label,e):a,s=r.palette??Kr,c=t.categories.map(b=>b.color),l=r.suggestColor?.(c.map(b=>b.toLowerCase()))??vn(c,t.categories.length),d=Hr(c,zr(e,s),l),g=new Set(t.categories.map(b=>b.label.toLowerCase())),h=o;for(let b=2;g.has(h.toLowerCase());b+=1)h=`${o} ${b}`;let f=Cn(t,{label:h,color:d,...n?.price!==void 0?{price:n.price}:{},...n?.tiers?.length?{tiers:n.tiers}:{},idFactory:r.idFactory});return t.categories=f.categories,f.category.key}function qr(t,e){let n=new Set;for(let r of G(t))for(let i of r.objects)"categoryKey"in i&&i.categoryKey===e&&n.add(i.id),(i.type==="row"||i.type==="table")&&i.overrides?.some(a=>a.categoryKey===e)&&n.add(i.id);return[...n]}function Xr(t,e){let n=t.categories.find(a=>a.key===e.categoryKey);if(!n)throw new u("category_not_found",`Unknown chart category: ${e.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:e.categoryKey});if(t.categories.length<=1)throw new u("invalid_operation","A chart must retain at least one category");let r=qr(t,e.categoryKey);if(r.length)throw new u("category_in_use",`Category ${e.categoryKey} is still assigned to chart inventory`,{categoryKey:e.categoryKey,objectIds:r});if(n.referenceCategorySource)throw new u("reference_category_protected",`Reference-backed category ${e.categoryKey} cannot be deleted through a generic catalog operation`,{categoryKey:e.categoryKey});let i=ye(t.categories.filter(a=>a.key!==e.categoryKey));return t.categories=i,{changed:!0,categoryKey:e.categoryKey,categories:i}}var Qr=["background","seatLabelColor","rowLabelColor","selectionColor","decorFill","textColor","accent","accentInk"],Pn=.7,On=1.6;function Yr(t,e){let n=e.patch;if(!Object.keys(n).length)throw new u("invalid_operation","At least one theme field is required");let r=JSON.stringify(t.theme??null),i={...t.theme??{}};for(let a of Qr){let o=n[a];o===null?delete i[a]:o!==void 0&&(i[a]=F(o,`Theme ${a}`))}if(n.fontFamily===null)delete i.fontFamily;else if(n.fontFamily!==void 0){let a=n.fontFamily.normalize("NFKC").trim();if(!a||a.length>120)throw new u("invalid_operation","Theme fontFamily must contain 1 to 120 characters");i.fontFamily=a}if(n.seatScale===null)delete i.seatScale;else if(n.seatScale!==void 0){if(!Number.isFinite(n.seatScale)||n.seatScale<Pn||n.seatScale>On)throw new u("invalid_operation",`Theme seatScale must be from ${Pn} to ${On}`);i.seatScale=n.seatScale}if(n.logoUrl===null)delete i.logoUrl;else if(n.logoUrl!==void 0){let a=n.logoUrl.trim();if(!/^(https:\/\/|data:image\/)/.test(a)||a.length>2e6)throw new u("invalid_operation","Theme logoUrl must be an https or data:image reference");i.logoUrl=a}if(n.brandName===null)delete i.brandName;else if(n.brandName!==void 0){let a=n.brandName.normalize("NFKC").trim();if(!a||a.length>80)throw new u("invalid_operation","Theme brandName must contain 1 to 80 characters");i.brandName=a}return n.hideBadge===null||n.hideBadge===!1?delete i.hideBadge:n.hideBadge===!0&&(i.hideBadge=!0),t.theme=Object.keys(i).length?i:void 0,{changed:JSON.stringify(t.theme??null)!==r,theme:t.theme??null}}function Zr(t,e){let n=e.url===null?null:e.url.trim();if(n!==null&&(!/^(https:\/\/|data:image\/)/.test(n)||n.length>2e6))throw new u("invalid_operation","View-from-seat photo must be an https or data:image reference");let r=n??void 0;if(e.floorId!==void 0){let s=t.floors?.find(g=>g.id===e.floorId);if(!s)throw new u("invalid_operation",`Unknown floor: ${e.floorId}`);let c=(s.viewFromSeatUrl??void 0)===r,l=r?e.metadata===null?void 0:e.metadata??(c?s.viewFromSeatMeta:void 0):void 0,d=!c||JSON.stringify(s.viewFromSeatMeta??null)!==JSON.stringify(l??null);return s.viewFromSeatUrl=r,s.viewFromSeatMeta=l,{changed:d,scope:"floor",floorId:e.floorId,url:s.viewFromSeatUrl??null}}let i=(t.viewFromSeatUrl??void 0)===r,a=r?e.metadata===null?void 0:e.metadata??(i?t.viewFromSeatMeta:void 0):void 0,o=!i||JSON.stringify(t.viewFromSeatMeta??null)!==JSON.stringify(a??null);return t.viewFromSeatUrl=r,t.viewFromSeatMeta=a,{changed:o,scope:"venue",url:t.viewFromSeatUrl??null}}function Wr(t,e){let n=Oe(t,e.floorId),r=$t(n),i=e.placement==="auto"||e.placement==null?"rear":e.placement,a=96;return i==="front"?{x:r.x+r.width/2,y:r.y-a-e.height/2}:i==="left"?{x:r.x-a-e.width/2,y:r.y+r.height/2}:i==="right"?{x:r.x+r.width+a+e.width/2,y:r.y+r.height/2}:{x:r.x+r.width/2,y:r.y+r.height+a+e.height/2}}function Ke(t,e){k(t,e.categoryKey);let n=(...d)=>d.every(Number.isFinite);if(!n(e.center.x,e.center.y,e.innerRadius,e.rowGap,e.startAngle,e.endAngle,e.seatPitch))throw new u("invalid_operation","Arc/Fan geometry values must be finite");if(!Number.isInteger(e.rowCount)||e.rowCount<1||e.rowCount>100)throw new u("invalid_operation","Arc/Fan rowCount must be an integer from 1 to 100");if(e.innerRadius<40||e.innerRadius>2e4||e.rowGap<12||e.rowGap>500)throw new u("invalid_operation","Arc/Fan radius must be 40\u201320000 and row gap 12\u2013500");let r=e.endAngle-e.startAngle;if(Math.abs(r)<5||Math.abs(r)>320)throw new u("invalid_operation","Arc/Fan sweep must be from 5\xB0 to 320\xB0");if(e.seatPitch<14||e.seatPitch>80)throw new u("invalid_operation","Arc/Fan seat pitch must be from 14 to 80 chart units");let i=e.fit??"seat-pitch";if(i==="fixed-count"&&(!Number.isInteger(e.seatsPerRow)||e.seatsPerRow<2||e.seatsPerRow>300))throw new u("invalid_operation","Fixed Arc/Fan rows require seatsPerRow from 2 to 300");let a=e.taperDegrees??0,o=e.skewDegrees??0;if(!n(a,o)||Math.abs(a)>120||Math.abs(o)>180)throw new u("invalid_operation","Arc/Fan taper must be within \xB1120\xB0 and skew within \xB1180\xB0");let s={left:e.aisleGaps?.left??0,center:e.aisleGaps?.center??0,right:e.aisleGaps?.right??0};if(!n(s.left,s.center,s.right)||Object.values(s).some(d=>d<0||d>200))throw new u("invalid_operation","Arc/Fan aisle widths must be from 0 to 200 chart units");let l=C(t,e.floorId).objects.filter(d=>d.type==="row").length;return{...e,fit:i,facing:e.facing??"inward",taperDegrees:a,skewDegrees:o,aisleGaps:s,rowLabelStart:e.rowLabelStart??l,seatLabelStart:e.seatLabelStart??1}}function ei(t,e,n){let r=n*X;return{x:t.x+e*Math.sin(r),y:t.y+e*Math.cos(r)}}function ti(t,e,n,r){let i=Math.abs(r-n)*X,a=[["left",.25],["center",.5],["right",.75]].flatMap(([l,d])=>{let g=t.aisleGaps[l];if(!g)return[];let h=g/e/i/2;return[[Math.max(0,d-h),Math.min(1,d+h)]]}).sort((l,d)=>l[0]-d[0]),o=[];for(let l of a){let d=o[o.length-1];d&&l[0]<=d[1]?d[1]=Math.max(d[1],l[1]):o.push([...l])}let s=[],c=0;for(let l of o)l[0]-c>1e-6&&s.push([c,l[0]]),c=Math.max(c,l[1]);return 1-c>1e-6&&s.push([c,1]),s.filter(([l,d])=>e*i*(d-l)>=t.seatPitch*.75)}function ni(t,e){let n=t.length*2;if(e<n)throw new u("invalid_operation",`Fixed seat count must be at least ${n} for ${t.length} aisle-separated row segments`);let r=e-n,i=t.reduce((c,l)=>c+l,0),a=t.map(c=>r*c/i),o=a.map(c=>2+Math.floor(c)),s=e-o.reduce((c,l)=>c+l,0);return a.map((c,l)=>({index:l,fraction:c-Math.floor(c)})).sort((c,l)=>l.fraction-c.fraction||c.index-l.index).forEach(({index:c})=>{s-- >0&&o[c]++}),o}function $e(t,e,n){let r=[];for(let i=0;i<t.rowCount;i++){let a=t.rowCount===1?0:i/(t.rowCount-1),o=t.innerRadius+i*t.rowGap,s=Math.sign(t.endAngle-t.startAngle)||1,c=t.startAngle+s*t.taperDegrees*a+t.skewDegrees*a,l=t.endAngle-s*t.taperDegrees*a+t.skewDegrees*a;if(Math.sign(l-c)!==Math.sign(t.endAngle-t.startAngle)||Math.abs(l-c)<5)throw new u("invalid_operation",`Arc/Fan taper collapses row ${i+1} below a 5\xB0 sweep`);let d=ti(t,o,c,l);if(!d.length)throw new u("invalid_operation",`Arc/Fan aisles leave no usable span in row ${i+1}`);t.facing==="outward"&&(d=d.slice().reverse());let g=d.map(([b,y])=>o*Math.abs(l-c)*X*(y-b)),h=t.fit==="fixed-count"?ni(g,t.seatsPerRow):g.map(b=>Math.max(2,Math.round(b/t.seatPitch)+1)),f=t.seatLabelStart;d.forEach(([b,y],x)=>{let v=c+(l-c)*b,p=c+(l-c)*y;t.facing==="outward"&&([v,p]=[p,v]);let m=h[x];if(m>300)throw new u("invalid_operation","An Arc/Fan row segment cannot exceed 300 seats");let w=Math.abs(p-v)*X/(m-1),S=2*o*Math.sin(w/2),I={type:"row",id:n(i,x),label:B(t.rowLabelStart+i),origin:ei(t.center,o,v),rotation:-v,curve:p-v,seatCount:m,seatSpacing:S,categoryKey:t.categoryKey,seatLabelStart:f,arcFanGeneration:{kind:"arc-fan-v1",groupId:e,center:{...t.center},innerRadius:t.innerRadius,rowCount:t.rowCount,rowGap:t.rowGap,startAngle:t.startAngle,endAngle:t.endAngle,seatPitch:t.seatPitch,fit:t.fit,...t.seatsPerRow!=null?{seatsPerRow:t.seatsPerRow}:{},facing:t.facing,taperDegrees:t.taperDegrees,skewDegrees:t.skewDegrees,aisleGaps:{...t.aisleGaps},rowLabelStart:t.rowLabelStart,seatLabelStart:t.seatLabelStart,rowIndex:i,segmentIndex:x}};r.push(I),f+=m})}return r}function mt(t,e){let n=Ke(t,e),r=C(t,e.floorId),i=$e(n,"preview-arc-fan",(c,l)=>`preview-fan-${c}-${l}`),a=i.map(c=>c.seatSpacing),o=Math.max(...a.map(c=>Math.abs(c-n.seatPitch))),s=[];return o>n.seatPitch*.12&&s.push(`Seat fitting deviates from the requested pitch by up to ${o.toFixed(1)} chart units`),i.length>n.rowCount*3&&s.push("Three aisles split each logical row into four separately editable segments"),{floorId:r.floorId,rows:i,logicalRowCount:n.rowCount,rowSegmentCount:i.length,totalSeats:i.reduce((c,l)=>c+l.seatCount,0),innerRadius:n.innerRadius,outerRadius:n.innerRadius+(n.rowCount-1)*n.rowGap,minSeatSpacing:Math.min(...a),maxSeatSpacing:Math.max(...a),maxPitchDeviation:o,aisleCount:Object.values(n.aisleGaps).filter(c=>c>0).length,warnings:s}}function oi(t,e){let n=Ke(t,e),r=C(t,e.floorId),i=new Set,a=_(t,"fan",e.idFactory,i),o=$e(n,a,()=>_(t,"r",e.idFactory,i)),s=mt(t,e),c=null,l=e.sectionLabel?.normalize("NFKC").trim(),d=null;if(l){if(l.length>80)throw new u("invalid_operation","Arc/Fan section label must contain at most 80 characters");let g=Z(o);g&&(c=_(t,"sec",e.idFactory,i),d={type:"section",id:c,label:l,outline:g,arcFanGroupId:a})}return r.objects.push(...o,...d?[d]:[]),{floorId:r.floorId,rowIds:o.map(g=>g.id),sectionId:c,groupId:a,logicalRowCount:s.logicalRowCount,rowSegmentCount:s.rowSegmentCount,totalSeats:s.totalSeats,innerRadius:s.innerRadius,outerRadius:s.outerRadius,minSeatSpacing:s.minSeatSpacing,maxSeatSpacing:s.maxSeatSpacing,maxPitchDeviation:s.maxPitchDeviation,aisleCount:s.aisleCount,warnings:s.warnings}}function Mn(t,e){let n=C(t,e.floorId),r=n.objects.filter(g=>g.type==="row"&&g.arcFanGeneration?.groupId===e.groupId);if(!r.length)throw new u("object_not_found",`Unknown Arc/Fan group: ${e.groupId}`,{groupId:e.groupId});let i=r[0].arcFanGeneration,a=g=>{let h=g.arcFanGeneration;return JSON.stringify({center:h.center,innerRadius:h.innerRadius,rowCount:h.rowCount,rowGap:h.rowGap,startAngle:h.startAngle,endAngle:h.endAngle,seatPitch:h.seatPitch,fit:h.fit,seatsPerRow:h.seatsPerRow,facing:h.facing,taperDegrees:h.taperDegrees,skewDegrees:h.skewDegrees,aisleGaps:h.aisleGaps,rowLabelStart:h.rowLabelStart,seatLabelStart:h.seatLabelStart})};if(r.some(g=>a(g)!==a(r[0])))throw new u("invalid_operation","Arc/Fan group provenance no longer agrees across all row segments",{groupId:e.groupId});let o=n.objects.find(g=>g.type==="section"&&g.arcFanGroupId===e.groupId),s={floorId:n.floorId,center:{...i.center},innerRadius:i.innerRadius,rowCount:i.rowCount,rowGap:i.rowGap,startAngle:i.startAngle,endAngle:i.endAngle,seatPitch:i.seatPitch,fit:i.fit,seatsPerRow:i.seatsPerRow,facing:i.facing,taperDegrees:i.taperDegrees,skewDegrees:i.skewDegrees,aisleGaps:{...i.aisleGaps},categoryKey:r[0].categoryKey,rowLabelStart:i.rowLabelStart,seatLabelStart:i.seatLabelStart,sectionLabel:o?.label},c=Ke(t,s),l=new Set($e(c,e.groupId,(g,h)=>`${g}:${h}`).map(g=>`${g.arcFanGeneration.rowIndex}:${g.arcFanGeneration.segmentIndex}`)),d=new Set(r.map(g=>`${g.arcFanGeneration.rowIndex}:${g.arcFanGeneration.segmentIndex}`));if(l.size!==d.size||[...l].some(g=>!d.has(g)))throw new u("invalid_operation","Arc/Fan group is incomplete and cannot be regenerated safely",{groupId:e.groupId});return s}function ri(t,e){Mn(t,{floorId:e.floorId,groupId:e.groupId});let n=Ke(t,e),r=C(t,e.floorId),i=r.objects.filter(y=>y.type==="row"&&y.arcFanGeneration?.groupId===e.groupId),a=r.objects.find(y=>y.type==="section"&&y.arcFanGroupId===e.groupId),o=new Map(i.map(y=>[`${y.arcFanGeneration.rowIndex}:${y.arcFanGeneration.segmentIndex}`,y.id])),s=new Set,c=$e(n,e.groupId,(y,x)=>o.get(`${y}:${x}`)??_(t,"r",e.idFactory,s)),l=mt(t,e),d=e.sectionLabel?.normalize("NFKC").trim(),g=null;if(d){if(d.length>80)throw new u("invalid_operation","Arc/Fan section label must contain at most 80 characters");let y=Z(c);y&&(g={type:"section",id:a?.id??_(t,"sec",e.idFactory,s),label:d,outline:y,arcFanGroupId:e.groupId})}let h=new Set([...i.map(y=>y.id),...a?[a.id]:[]]),f=Math.min(...r.objects.map((y,x)=>h.has(y.id)?x:1/0)),b=r.objects.filter(y=>!h.has(y.id));return b.splice(Number.isFinite(f)?f:b.length,0,...c,...g?[g]:[]),r.objects.splice(0,r.objects.length,...b),{floorId:r.floorId,rowIds:c.map(y=>y.id),sectionId:g?.id??null,groupId:e.groupId,logicalRowCount:l.logicalRowCount,rowSegmentCount:l.rowSegmentCount,totalSeats:l.totalSeats,innerRadius:l.innerRadius,outerRadius:l.outerRadius,minSeatSpacing:l.minSeatSpacing,maxSeatSpacing:l.maxSeatSpacing,maxPitchDeviation:l.maxPitchDeviation,aisleCount:l.aisleCount,warnings:l.warnings}}function ii(t){let e=new Set(H(t).filter(r=>r.type==="row"||r.type==="table"||r.type==="booth").map(r=>r.label).filter(r=>typeof r=="string")),n=0;return()=>{for(;e.has(B(n));)n+=1;let r=B(n);return e.add(r),n+=1,r}}function An(t){return JSON.stringify(["row-block-v1",t.style,t.origin.x,t.origin.y,t.rotation,t.rowCount,t.seatsPerRow,t.rowGap,t.seatSpacing,t.curve])}function ai(t,e){if(k(t,e.categoryKey),!Number.isInteger(e.rowCount)||e.rowCount<1||e.rowCount>100)throw new u("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(e.seatsPerRow)||e.seatsPerRow<1||e.seatsPerRow>300)throw new u("invalid_operation","seatsPerRow must be an integer from 1 to 300");let n=e.rowGap??28,r=e.seatSpacing??24;if(!Number.isFinite(n)||n<=0||!Number.isFinite(r)||r<=0)throw new u("invalid_operation","Row and seat spacing must be positive finite values");if(e.rotation!==void 0&&!Number.isFinite(e.rotation))throw new u("invalid_operation","rotation must be a finite number of degrees");let i=C(t,e.floorId),a=new Set,o=ii(t),s=ut(e.rotation??0),c=e.curve??0,l=e.style,d=l?_(t,"rowblock",e.idFactory,a):void 0,g=l?An({style:l,origin:e.origin,rotation:s,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,rowGap:n,seatSpacing:r,curve:c}):void 0,h={x:Math.cos(s*q),y:Math.sin(s*q)},f={x:-h.y,y:h.x},b=Array.from({length:e.rowCount},(v,p)=>{let m=l==="intertwined"&&p%2===1?r/2:0,w={type:"row",id:_(t,"r",e.idFactory,a),label:o(),origin:{x:e.origin.x+f.x*p*n+h.x*m,y:e.origin.y+f.y*p*n+h.y*m},rotation:s,curve:c,seatCount:e.seatsPerRow,seatSpacing:r,categoryKey:e.categoryKey};return l&&d&&g&&(w.rowBlockGeneration={kind:"row-block-v1",groupId:d,style:l,rowIndex:p,rowCount:e.rowCount,seatsPerRow:e.seatsPerRow,origin:{...e.origin},rotation:s,rowGap:n,seatSpacing:r,curve:c,signature:g}),w});i.objects.push(...b);let y=null,x=e.sectionLabel?.trim();if(x){let v=Z(b);if(v){let p={type:"section",id:_(t,"sec",e.idFactory,a),label:x,outline:v};i.objects.push(p),y=p.id}}return{floorId:i.floorId,rowIds:b.map(v=>v.id),sectionId:y,createdIds:[...b.map(v=>v.id),...y?[y]:[]]}}function _n(t,e){let n=new Set(H(t).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(i=>typeof i=="string")),r=1;return()=>{for(;n.has(`${e}${r}`);)r+=1;let i=`${e}${r}`;return n.add(i),r+=1,i}}function si(t,e){let n=new Set(H(t).filter(i=>i.type==="gaArea").map(i=>i.label));if(!n.has(e))return e;let r=2;for(;n.has(`${e} ${r}`);)r+=1;return`${e} ${r}`}var ci=456;function jn(t){let e=Math.sqrt(Math.max(1,t)*ci);return{width:Math.round(e*1.027),height:Math.round(e/1.027)}}function li(t,e){if(k(t,e.categoryKey),!Number.isInteger(e.capacity)||e.capacity<1)throw new u("invalid_operation","capacity must be a positive integer");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new u("invalid_operation","GA area center must be finite");let n=C(t,e.floorId),r=new Set,{width:i,height:a}=jn(e.capacity),o=si(t,(e.label??"General Admission").trim()||"General Admission"),s={type:"gaArea",id:_(t,"ga",e.idFactory,r),label:o,...e.displayLabel?.trim()?{displayLabel:e.displayLabel.trim()}:{},points:[{x:e.center.x-i/2,y:e.center.y-a/2},{x:e.center.x+i/2,y:e.center.y-a/2},{x:e.center.x+i/2,y:e.center.y+a/2},{x:e.center.x-i/2,y:e.center.y+a/2}],capacity:e.capacity,categoryKey:e.categoryKey};return n.objects.push(s),{floorId:n.floorId,gaAreaId:s.id,label:o,createdIds:[s.id]}}function di(t,e){if(k(t,e.categoryKey),!Number.isInteger(e.tableRows)||e.tableRows<1||e.tableRows>20||!Number.isInteger(e.tableColumns)||e.tableColumns<1||e.tableColumns>20)throw new u("invalid_operation","tableRows and tableColumns must be integers from 1 to 20");if(!Number.isInteger(e.seatsPerTable)||e.seatsPerTable<1||e.seatsPerTable>20)throw new u("invalid_operation","seatsPerTable must be an integer from 1 to 20");let n=e.gapX??155,r=e.gapY??150;if(!Number.isFinite(n)||n<80||!Number.isFinite(r)||r<80)throw new u("invalid_operation","Table spacing must be at least 80 chart units");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new u("invalid_operation","Table array center must be finite");let i=C(t,e.floorId),a=new Set,o=_n(t,"T"),s=[];for(let c=0;c<e.tableRows;c+=1)for(let l=0;l<e.tableColumns;l+=1)s.push({type:"table",id:_(t,"t",e.idFactory,a),label:o(),center:{x:e.center.x+(l-(e.tableColumns-1)/2)*n,y:e.center.y+(c-(e.tableRows-1)/2)*r},rotation:0,categoryKey:e.categoryKey,seatCount:e.seatsPerTable,...e.shape==="round"?{shape:"round",radius:46}:{shape:"rect",sides:["top","bottom"],width:120,height:58}});return i.objects.push(...s),{floorId:i.floorId,tableIds:s.map(c=>c.id),createdIds:s.map(c=>c.id)}}function ui(t,e){if(k(t,e.categoryKey),!Number.isInteger(e.boothRows)||e.boothRows<1||e.boothRows>30||!Number.isInteger(e.boothColumns)||e.boothColumns<1||e.boothColumns>30)throw new u("invalid_operation","boothRows and boothColumns must be integers from 1 to 30");let n=e.gapX??88,r=e.gapY??82;if(!Number.isFinite(n)||n<62||!Number.isFinite(r)||r<52)throw new u("invalid_operation","Booth spacing must clear the 62\xD752 booth footprint");if(!Number.isFinite(e.center.x)||!Number.isFinite(e.center.y))throw new u("invalid_operation","Booth array center must be finite");let i=C(t,e.floorId),a=new Set,o=_n(t,"B"),s=[];for(let c=0;c<e.boothRows;c+=1)for(let l=0;l<e.boothColumns;l+=1)s.push({type:"booth",id:_(t,"booth",e.idFactory,a),label:o(),center:{x:e.center.x+(l-(e.boothColumns-1)/2)*n,y:e.center.y+(c-(e.boothRows-1)/2)*r},width:62,height:52,rotation:0,categoryKey:e.categoryKey});return i.objects.push(...s),{floorId:i.floorId,boothIds:s.map(c=>c.id),createdIds:s.map(c=>c.id)}}function fi(t,e){let n=C(t,e.floorId),r=[...new Set(e.rowIds)];if(r.length<2||r.length>64)throw new u("invalid_operation","A segmented row requires 2 to 64 ordered component rows");if(e.boundaries.length!==r.length-1||e.boundaries.some(h=>h!=="continuous"&&h!=="break"))throw new u("invalid_operation","Declare one continuous or break boundary between every pair of row components");let i=r.map(h=>n.objects.find(f=>f.type==="row"&&f.id===h)),a=r.filter((h,f)=>!i[f]);if(a.length)throw new u("object_not_found","One or more segmented-row components do not exist on the selected floor",{rowIds:a});let o=i,s=o.filter(h=>h.segmentedRow);if(s.length)throw new u("invalid_operation","Ungroup existing segmented rows before combining their components again",{rowIds:s.map(h=>h.id)});let c=(e.displayLabel??o[0].displayLabel??o[0].label).normalize("NFKC").trim();if(!c||c.length>80)throw new u("invalid_operation","Segmented-row display label must contain 1 to 80 characters");let l=new Set(n.objects.flatMap(h=>h.type==="row"?[h.segmentedRow?.groupId,h.rowBlockGeneration?.groupId].filter(f=>!!f):[])),d="";for(let h=0;h<100;h+=1){let f=e.idFactory("rowgroup");if(f&&!l.has(f)){d=f;break}}if(!d)throw new u("id_generation_failed","Unable to allocate a segmented-row group id");let g=o[0];return o.forEach((h,f)=>{h.segmentedRow={kind:"segmented-row-v1",groupId:d,componentIndex:f,componentCount:o.length,boundaryBefore:f===0?"start":e.boundaries[f-1],displayLabel:c,...g.displayType?{displayType:g.displayType}:{},...g.labelPresentation?{labelPresentation:structuredClone(g.labelPresentation)}:{},...g.viewFromSeatUrl?{viewFromSeatUrl:g.viewFromSeatUrl}:{},...g.viewFromSeatMeta?{viewFromSeatMeta:structuredClone(g.viewFromSeatMeta)}:{},...g.confidenceEvidence?{confidenceEvidence:structuredClone(g.confidenceEvidence)}:{}}}),{floorId:n.floorId,groupId:d,rowIds:r,changed:!0}}function gi(t,e){let n=C(t,e.floorId),r=e.groupId?n.objects.find(s=>s.type==="row"&&s.segmentedRow?.groupId===e.groupId):n.objects.find(s=>s.type==="row"&&s.id===e.rowId),i=e.groupId??r?.segmentedRow?.groupId;if(!i)throw new u("object_not_found","The segmented row does not exist on the selected floor");let a=n.objects.filter(s=>s.type==="row"&&s.segmentedRow?.groupId===i);if(!a.length)throw new u("object_not_found","The segmented row does not exist on the selected floor");let o=a.sort((s,c)=>s.segmentedRow.componentIndex-c.segmentedRow.componentIndex).map(s=>s.id);for(let s of a)delete s.segmentedRow;return{floorId:n.floorId,groupId:i,rowIds:o,changed:!0}}function hi(t,e){let n=C(t,e.floorId),r=n.objects.filter(o=>o.type==="row"&&o.segmentedRow?.groupId===e.groupId).sort((o,s)=>o.segmentedRow.componentIndex-s.segmentedRow.componentIndex);if(r.length<2)throw new u("object_not_found","The segmented row is incomplete or missing on the selected floor");if(e.boundaries&&(e.boundaries.length!==r.length-1||e.boundaries.some(o=>o!=="continuous"&&o!=="break")))throw new u("invalid_operation","Declare one continuous or break boundary between every pair of row components");let i=e.displayLabel?.normalize("NFKC").trim();if(i!==void 0&&(!i||i.length>80))throw new u("invalid_operation","Segmented-row display label must contain 1 to 80 characters");let a=JSON.stringify(r.map(o=>o.segmentedRow));return r.forEach((o,s)=>{let c=o.segmentedRow,l=c.viewFromSeatUrl;i!==void 0&&(c.displayLabel=i),e.boundaries&&s>0&&(c.boundaryBefore=e.boundaries[s-1]),e.smoothing!==void 0&&(c.smoothing=e.smoothing||void 0),e.viewFromSeatUrl===null?delete c.viewFromSeatUrl:e.viewFromSeatUrl!==void 0&&(c.viewFromSeatUrl=e.viewFromSeatUrl),!c.viewFromSeatUrl||e.viewFromSeatMeta===null?delete c.viewFromSeatMeta:e.viewFromSeatMeta!==void 0?c.viewFromSeatMeta=structuredClone(e.viewFromSeatMeta):e.viewFromSeatUrl!==void 0&&c.viewFromSeatUrl!==l&&delete c.viewFromSeatMeta}),{floorId:n.floorId,groupId:e.groupId,rowIds:r.map(o=>o.id),changed:JSON.stringify(r.map(o=>o.segmentedRow))!==a}}function bi(t,e){let n=C(t,e.floorId),r=n.objects.filter(O=>O.type==="row"&&O.rowBlockGeneration?.groupId===e.groupId).sort((O,$)=>O.rowBlockGeneration.rowIndex-$.rowBlockGeneration.rowIndex),i=r[0]?.rowBlockGeneration;if(!i||r.length!==i.rowCount||r.some((O,$)=>{let j=O.rowBlockGeneration;return j.kind!=="row-block-v1"||j.rowIndex!==$||j.signature!==i.signature||JSON.stringify(j)!==JSON.stringify({...i,rowIndex:$})}))throw new u("invalid_operation","This row block was edited manually or is incomplete; repair or recreate it before regeneration",{groupId:e.groupId});let a=JSON.stringify(r),o=e.style??i.style,s=e.rowCount??i.rowCount,c=e.seatsPerRow??i.seatsPerRow,l=e.rowGap??i.rowGap,d=e.seatSpacing??i.seatSpacing,g=e.curve??i.curve,h=Number.isFinite(e.rotation??i.rotation)?ut(e.rotation??i.rotation):e.rotation??i.rotation,f=e.origin?{...e.origin}:{...i.origin};if(!Number.isInteger(s)||s<1||s>100)throw new u("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(c)||c<1||c>300)throw new u("invalid_operation","seatsPerRow must be an integer from 1 to 300");if(![l,d].every(O=>Number.isFinite(O)&&O>0)||!Number.isFinite(g)||!Number.isFinite(h)||!Number.isFinite(f.x)||!Number.isFinite(f.y))throw new u("invalid_operation","Row-block geometry must use positive spacing and finite origin, rotation, and curve values");let b=An({style:o,origin:f,rotation:h,rowCount:s,seatsPerRow:c,rowGap:l,seatSpacing:d,curve:g}),y={x:Math.cos(h*q),y:Math.sin(h*q)},x={x:-y.y,y:y.x},v=new Map(r.map(O=>[O.rowBlockGeneration.rowIndex,O])),p=new Set,m=new Set(n.objects.filter(O=>O.type==="row").filter(O=>!r.includes(O)).map(O=>O.label)),w=n.objects.filter(O=>O.type==="row").length,S=()=>{for(;m.has(B(w));)w+=1;let O=B(w);return m.add(O),w+=1,O},I=[],M=[];for(let O=0;O<s;O+=1){let $=o==="intertwined"&&O%2===1?d/2:0,j=v.get(O);j||(j={type:"row",id:_(t,"r",e.idFactory,p),label:S(),origin:{...f},rotation:h,curve:g,seatCount:c,seatSpacing:d,categoryKey:r[0].categoryKey},M.push(j.id)),j.origin={x:f.x+x.x*O*l+y.x*$,y:f.y+x.y*O*l+y.y*$},j.rotation=h,j.curve=g,j.seatCount=c,j.seatSpacing=d,delete j.path,delete j.arcFanGeneration,j.overrides&&(j.overrides=j.overrides.filter(Ve=>Ve.index<c),j.overrides.length||delete j.overrides),j.rowBlockGeneration={kind:"row-block-v1",groupId:e.groupId,style:o,rowIndex:O,rowCount:s,seatsPerRow:c,origin:{...f},rotation:h,rowGap:l,seatSpacing:d,curve:g,signature:b},I.push(j)}let D=r.slice(s).map(O=>O.id),T=Math.min(...r.map(O=>n.objects.indexOf(O))),U=new Set(r.map(O=>O.id)),K=n.objects.filter(O=>!U.has(O.id));return K.splice(T,0,...I),n.objects.splice(0,n.objects.length,...K),{floorId:n.floorId,groupId:e.groupId,rowIds:I.map(O=>O.id),createdRowIds:M,removedRowIds:D,changed:a!==JSON.stringify(I)||M.length>0||D.length>0}}var pi=300,mi=40;function yi(t){let e=new Set(H(t).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(i=>typeof i=="string")),n=0,r=()=>{for(;e.has(B(n));)n+=1;let i=B(n);return n+=1,i};return i=>{let a=i.normalize("NFKC").replace(/\s+/g," ").trim().slice(0,mi).trim(),o=0;return()=>{for(;a&&o<4096;o+=1){let c=`${a}-${B(o)}`;if(!e.has(c))return e.add(c),o+=1,c}let s=r();return e.add(s),s}}}function wi(t,e){return t.filter(n=>(n.type==="row"||n.type==="table"||n.type==="booth"||n.type==="gaArea")&&!(n.type==="row"&&n.referenceScan?.assetId===e))}function xi(t,e,n,r,i){let a=t.sectionId?e.find(c=>c.type==="section"&&c.id===t.sectionId):void 0;if(a){let c=wi(e,n).filter(l=>N(L(l),a.outline,a.holes));if(c.length)return{skip:{sectionId:a.id,name:t.name,reason:"section_not_empty",objectIds:c.map(l=>l.id)},rows:[],seats:0}}let o=[],s=0;for(let c of t.rows){let l=Math.min(pi,Math.max(1,Math.round(c.seatCount)));if(!Number.isFinite(l)||l<1)continue;let d=c.end.x-c.start.x,g=c.end.y-c.start.y,h=Math.hypot(d,g),f=l>1&&h>0?h/(l-1):r>0?r:24;if(!Number.isFinite(f)||f<=0)continue;let b=h>0?Math.atan2(g,d)*180/Math.PI:0;o.push({label:i(),origin:{x:c.start.x,y:c.start.y},rotation:b,seatCount:l,seatSpacing:f}),s+=l}return{skip:null,rows:o,seats:s}}function Si(t,e,n){k(t,n.categoryKey);let r=C(t,n.floorId),i=e.assetId,a=[],o=r.objects.filter(f=>f.type==="row"&&f.referenceScan?.assetId===i?(a.push(f.id),!1):!0);r.objects.splice(0,r.objects.length,...o);let s=[],c=[],l=[],d=new Set,g=0,h=yi(t);for(let f of e.sections){let b=xi(f,r.objects,i,e.seatPitch,h(f.name));if(b.skip){c.push(b.skip);continue}let y=b.rows.map(x=>({type:"row",id:_(t,"r",n.idFactory,d),referenceScan:{assetId:i},label:x.label,origin:x.origin,rotation:x.rotation,curve:0,seatCount:x.seatCount,seatSpacing:x.seatSpacing,categoryKey:n.categoryKey}));r.objects.push(...y);for(let x of y)l.push(x.id);s.push({sectionId:f.sectionId,name:f.name,seats:b.seats,rows:y.length}),g+=b.seats}return{floorId:r.floorId,assetId:i,createdRowIds:l,removedRowIds:a,totalSeats:g,perSection:s,skipped:c}}function kn(t,e){let n=C(t,e.floorId),r=[...new Set(e.objectIds)];if(!r.length)throw new u("invalid_operation","Select at least one table or booth to repeat");let i=r.map(f=>n.objects.find(b=>(b.type==="table"||b.type==="booth")&&b.id===f)),a=r.filter((f,b)=>!i[b]);if(a.length)throw new u("object_not_found","One or more grid sources do not exist on the selected floor",{objectIds:a});let o=i[0].type;if(i.some(f=>f.type!==o))throw new u("invalid_operation","A grid array must contain only tables or only booths");for(let[f,b,y]of[["rows",e.rows,30],["columns",e.columns,30]])if(!Number.isInteger(b)||b<1||b>y)throw new u("invalid_operation",`${f} must be a whole number from 1 to ${y}`);for(let[f,b]of[["stepX",e.stepX],["stepY",e.stepY]])if(!Number.isFinite(b)||b<30||b>2e3)throw new u("invalid_operation",`${f} must be from 30 to 2000 chart units`);let s=e.rows*e.columns;if(s<2)throw new u("invalid_operation","Choose at least two grid cells");let c=r.length*(s-1);if(c>5e3)throw new u("invalid_operation","A grid array can add at most 5000 objects");let l=i.reduce((f,b)=>f+(b.type==="table"?b.seatCount:1),0),g=(t.floors?.length?t.floors.flatMap(f=>f.objects):t.objects).reduce((f,b)=>f+(b.type==="row"||b.type==="table"?b.seatCount:b.type==="gaArea"?Math.max(0,Math.floor(b.capacity)):b.type==="booth"?1:0),0),h=l*(s-1);if(g+h>ce)throw new u("invalid_operation",`Grid inventory would exceed the ${ce} unit event limit`);return{target:n,sources:i,preview:{floorId:n.floorId,kind:o,sourceIds:r,sourceCount:r.length,cells:s,createdCount:c,addedInventory:h,resultingInventory:g+h,provenanceRemovedCount:i.filter(f=>!!f.referenceInventorySource).length*(s-1)}}}function Ii(t,e){return kn(t,e).preview}function vi(t,e){let{target:n,sources:r,preview:i}=kn(t,e),a=new Set,o=new Set((t.floors?.length?t.floors.flatMap(d=>d.objects):t.objects).flatMap(d=>"label"in d&&d.label?[d.label]:[])),s=[],c=(d,g)=>{let h=Math.max(2,g),f=y=>{let x=`-${y}`;return`${d.slice(0,Math.max(1,80-x.length))}${x}`},b=f(h);for(;o.has(b);)b=f(++h);return o.add(b),b},l=1;for(let d=0;d<e.rows;d++)for(let g=0;g<e.columns;g++)if(!(d===0&&g===0)){l+=1;for(let h of r){let f=structuredClone(h);f.id=_(t,f.type,e.idFactory,a),f.label=c(h.label,l),f.center={x:h.center.x+g*e.stepX,y:h.center.y+d*e.stepY},delete f.referenceInventorySource,s.push(f)}}return n.objects.push(...s),{...i,createdIds:s.map(d=>d.id)}}function Ci(t,e){let n=t?{...t}:{};return e.size===null?delete n.size:e.size!==void 0&&(n.size=e.size),e.color===null?delete n.color:e.color!==void 0&&(n.color=F(e.color,"Seat label color")),n.size===void 0&&n.color===void 0?void 0:n}var Pi=new Set(fe.map(t=>t.key));function we(t){return`${t.rowId}:${t.index}`}function Oi(t){let e=t.lastIndexOf(":"),n=e>0?t.slice(0,e):"",r=e>0?Number(t.slice(e+1)):Number.NaN;if(!n||!Number.isInteger(r)||r<0)throw new u("invalid_operation",`Invalid stable seat id: ${t}`,{seatId:t});return{rowId:n,index:r}}function Mi(t){if(t.label||delete t.label,t.displayLabel||delete t.displayLabel,t.dx||delete t.dx,t.dy||delete t.dy,t.skip||delete t.skip,t.categoryKey||delete t.categoryKey,me(t.glyph)||delete t.glyph,t.accessible&&!t.accessibility?.length&&(t.accessibility=["wheelchair"]),delete t.accessible,t.wheelchairSpaceType&&!t.accessibility?.includes("wheelchair")&&(t.accessibility=["wheelchair",...t.accessibility??[]]),t.accessibility?.length||delete t.accessibility,t.commercial){let e=t.commercial.note?.normalize("NFKC").trim(),n={};typeof t.commercial.restrictedView=="boolean"&&(n.restrictedView=t.commercial.restrictedView),typeof t.commercial.obstructedView=="boolean"&&(n.obstructedView=t.commercial.obstructedView),typeof t.commercial.premium=="boolean"&&(n.premium=t.commercial.premium),e&&(n.note=e),Object.keys(n).length?t.commercial=n:delete t.commercial}t.viewFromSeatUrl||(delete t.viewFromSeatUrl,delete t.viewFromSeatMeta),t.labelStyle&&t.labelStyle.size===void 0&&t.labelStyle.color===void 0&&delete t.labelStyle}function Ai(t){return Object.keys(t).every(e=>e==="index")}function Rn(t,e,n){if(!n.length)throw new u("invalid_operation","At least one seat is required");let r=C(t,e),i=[],a=new Set,o=new Map;for(let s of n){let c=we(s);if(a.has(c))continue;a.add(c);let l=r.objects.find(d=>(d.type==="row"||d.type==="table")&&d.id===s.rowId);if(!l)throw new u("object_not_found",`Unknown row or table for seat: ${c}`,{seatId:c,objectId:s.rowId});if(l.type==="table"&&(l.bookAsWhole||l.variableOccupancy))throw new u("invalid_operation",`Table "${l.label}" is sold as one grouped unit; switch it to individual-chair selling before editing chairs`,{seatId:c,tableId:l.id});if(!Number.isInteger(s.index)||s.index<0||s.index>=l.seatCount)throw new u("invalid_operation",l.type==="row"?`Seat index is outside row bounds: ${c}`:`Chair index is outside table bounds: ${c}`,{seatId:c,objectId:s.rowId,index:s.index,seatCount:l.seatCount});i.push({rowId:s.rowId,index:s.index}),o.set(l.id,l)}return{floorId:r.floorId,refs:i,owners:o}}function _i(t,e){let n=Rn(t,e.floorId,e.seats),r=Object.keys(e.patch);if(!r.length&&e.labelPrefix===void 0&&e.displayLabelPrefix===void 0)throw new u("invalid_operation","At least one seat override field is required");if(e.labelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(e.patch,"label"))throw new u("invalid_operation","Use either label or labelPrefix, not both");if(e.displayLabelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(e.patch,"displayLabel"))throw new u("invalid_operation","Use either displayLabel or displayLabelPrefix, not both");if(n.refs.length>1&&e.patch.label!=null)throw new u("invalid_operation","A literal label can only be assigned to one seat; use labelPrefix for a bulk sequence");if(n.refs.length>1&&e.patch.displayLabel!=null)throw new u("invalid_operation","A literal display label can only be assigned to one seat; use displayLabelPrefix for a bulk sequence");if(e.patch.categoryKey&&k(t,e.patch.categoryKey),e.patch.glyph!=null&&!me(e.patch.glyph))throw new u("invalid_operation","Unknown seat glyph",{glyph:e.patch.glyph});if(e.patch.accessibility){let a=e.patch.accessibility.filter(o=>!Pi.has(o));if(a.length)throw new u("invalid_operation","Unknown accessibility type",{accessibility:a})}if(e.patch.wheelchairSpaceType!==void 0&&e.patch.wheelchairSpaceType!==null&&e.patch.wheelchairSpaceType!=="seat-present"&&e.patch.wheelchairSpaceType!=="no-seat")throw new u("invalid_operation","wheelchairSpaceType must be seat-present, no-seat, or null");if(e.patch.wheelchairSpaceType&&e.patch.skip===!0)throw new u("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory");for(let a of n.refs){let o=n.owners.get(a.rowId)?.overrides?.find(l=>l.index===a.index),s=e.patch.wheelchairSpaceType===null?void 0:e.patch.wheelchairSpaceType??o?.wheelchairSpaceType,c=e.patch.skip===null?!1:e.patch.skip??o?.skip??!1;if(s&&c)throw new u("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory",{seatId:we(a)})}if(e.patch.commercial?.note&&e.patch.commercial.note.normalize("NFKC").trim().length>160)throw new u("invalid_operation","Commercial note supports at most 160 characters");for(let a of["dx","dy"]){let o=e.patch[a];if(o!=null&&!Number.isFinite(o))throw new u("invalid_operation",`${a} must be finite`,{[a]:o})}e.patch.labelStyle!=null&&se(e.patch.labelStyle,"Seat");let i=!1;return n.refs.forEach((a,o)=>{let s=n.owners.get(a.rowId),c=JSON.stringify(s.overrides??[]),l=s.overrides??(s.overrides=[]),d=l.find(h=>h.index===a.index);d||(d={index:a.index},l.push(d));let g=d.viewFromSeatUrl;for(let h of r){let f=e.patch[h];if(h==="wheelchairSpaceType"&&f==null)delete d.wheelchairSpaceType,d.accessibility&&(d.accessibility=d.accessibility.filter(b=>b!=="wheelchair"),d.accessibility.length||delete d.accessibility),delete d.accessible;else if(f==null)delete d[h];else if(h==="accessibility")d.accessibility=[...new Set(f)],delete d.accessible;else if(h==="commercial")d.commercial={...d.commercial,...f};else if(h==="labelStyle"){let b=Ci(d.labelStyle,f);b?d.labelStyle=b:delete d.labelStyle}else Object.assign(d,{[h]:f})}e.patch.viewFromSeatMeta===void 0&&e.patch.viewFromSeatUrl!==void 0&&d.viewFromSeatUrl!==g&&delete d.viewFromSeatMeta,e.labelPrefix!==void 0&&(d.label=`${e.labelPrefix}${o+1}`),e.displayLabelPrefix!==void 0&&(d.displayLabel=`${e.displayLabelPrefix}${o+1}`),Mi(d),Ai(d)&&(s.overrides=l.filter(h=>h!==d)),s.overrides?.length||delete s.overrides,JSON.stringify(s.overrides??[])!==c&&(i=!0)}),{floorId:n.floorId,changed:i,seatIds:n.refs.map(we)}}function ji(t,e){let n=Rn(t,e.floorId,e.seats),r=!1;for(let[i,a]of n.owners){if(!a.overrides?.length)continue;let o=new Set(n.refs.filter(c=>c.rowId===i).map(c=>c.index)),s=a.overrides.filter(c=>!o.has(c.index));s.length!==a.overrides.length&&(r=!0),a.overrides=s,a.overrides.length||delete a.overrides}return{floorId:n.floorId,changed:r,seatIds:n.refs.map(we)}}function ki(t,e){let n=C(t,e.floorId),r=[...new Set(e.rowIds)],i=r.map(p=>n.objects.find(m=>m.type==="row"&&m.id===p)),a=r.filter((p,m)=>!i[m]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});if(e.patch.categoryKey!==void 0&&k(t,e.patch.categoryKey),e.patch.seatCount!==void 0&&(!Number.isInteger(e.patch.seatCount)||e.patch.seatCount<1||e.patch.seatCount>300))throw new u("invalid_operation","seatCount must be an integer from 1 to 300");if(e.patch.seatNumbering!==void 0){let p=e.patch.seatNumbering,m=["decimal","odd","even","updown","updown-descending","roman","letters-upper","letters-lower"];if(p.scheme!==void 0&&!m.includes(p.scheme))throw new u("invalid_operation",`Unknown seat numbering scheme: ${p.scheme}. Expected one of ${m.join(", ")}.`);if(p.prefix!==void 0&&(typeof p.prefix!="string"||p.prefix.length>8))throw new u("invalid_operation","Seat label prefix must be a string of at most 8 characters");if(p.endAt!==void 0&&p.endAt!==null&&(!Number.isInteger(p.endAt)||p.endAt<0||p.endAt>9999))throw new u("invalid_operation","Seat numbering endAt must be an integer from 0 to 9999")}let{labelStyle:o,labelPosition:s,labelRotation:c,labelStyleShape:l,displayLabel:d,displayType:g,...h}=e.patch,f=d===void 0?{}:{displayLabel:d},b=ae(f,"Row"),y=g===void 0?void 0:it(g,"Row");if(o!==void 0&&se(o,"Row"),s!==void 0&&!["start","end","both","none"].includes(s))throw new u("invalid_operation","Row labelPosition must be one of start, end, both, none");if(c!=null&&(!Number.isFinite(c)||c<-180||c>180))throw new u("invalid_operation","Row labelRotation must be a number from -180 to 180");if(l!==void 0&&l!=="plain"&&l!=="pill")throw new u("invalid_operation","Row labelStyleShape must be plain or pill");h.labelPresentation!==void 0&&Ae(h.labelPresentation,"Row");let x=p=>JSON.stringify({origin:p.origin,rotation:p.rotation,curve:p.curve,seatCount:p.seatCount,seatSpacing:p.seatSpacing,path:p.path??null}),v=!1;for(let p of i){let m=JSON.stringify(p),w=x(p),S=e.preserveCenterOnSeatCountChange&&e.patch.seatCount!==void 0?L(p):null;if(Object.assign(p,structuredClone(h)),p.overrides&&e.patch.seatCount!==void 0&&(p.overrides=p.overrides.filter(I=>I.index<p.seatCount),p.overrides.length||(p.overrides=void 0)),S){let I=L(p);p.origin={x:p.origin.x+S.x-I.x,y:p.origin.y+S.y-I.y}}if(JSON.stringify(p)!==m&&(v=!0),x(p)!==w&&(delete p.arcFanGeneration,delete p.rowBlockGeneration),o!==void 0){let I=JSON.stringify(p.labelPresentation??null),M=_e(p.labelPresentation,o);M?p.labelPresentation=M:delete p.labelPresentation,JSON.stringify(p.labelPresentation??null)!==I&&(v=!0)}if(s!==void 0){let I=JSON.stringify(p.labelPresentation??null),M=p.labelPresentation?structuredClone(p.labelPresentation):{};M.positionPreset=s,M.visible=s!=="none",delete M.position,p.labelPresentation=M,JSON.stringify(p.labelPresentation??null)!==I&&(v=!0)}if(c!==void 0||l!==void 0){let I=JSON.stringify(p.labelPresentation??null),M=p.labelPresentation?structuredClone(p.labelPresentation):{};c===null?delete M.rotation:c!==void 0&&(M.rotation=c),l!==void 0&&(M.style=l),p.labelPresentation=M,JSON.stringify(p.labelPresentation??null)!==I&&(v=!0)}if(y!==void 0){let I=p.displayType;y?p.displayType=y:delete p.displayType,p.displayType!==I&&(v=!0)}if(d!==void 0){let I=p.displayLabel;b?delete p.displayLabel:p.displayLabel=f.displayLabel,p.displayLabel!==I&&(v=!0)}}return{floorId:n.floorId,changed:v,rowIds:r}}var Ri=3;function ze(t){return(t%360+360)%360}function Li(t){let e=t.rotation*q;return{x:Math.cos(e),y:Math.sin(e)}}function Fi(t,e){let n=Math.abs(ze(t-e));return n>180&&(n=360-n),n}function le(t,e,n){return(t.x-e.x)*n.x+(t.y-e.y)*n.y}function Ln(t){let e=0,n=0;for(let i of t){let a=2*i.rotation*q;e+=Math.cos(a),n+=Math.sin(a)}let r=(e===0&&n===0?0:Math.atan2(n,e))/2;return{x:Math.cos(r),y:Math.sin(r)}}function Ti(t,e,n){if(t.origin={x:t.origin.x+e,y:t.origin.y+n},t.path){let r=i=>({x:i.x+e,y:i.y+n});t.path={start:r(t.path.start),control1:r(t.path.control1),control2:r(t.path.control2),end:r(t.path.end)}}}function Fn(t,e){let n=Ln(t),r={x:-n.y,y:n.x},i=L(t[0]),a=t.map(c=>({row:c,coord:le(L(c),i,r)})).sort((c,l)=>c.coord-l.coord),o=a[0].coord,s=!1;return a.forEach((c,l)=>{let d=o+l*e-c.coord;Math.abs(d)>1e-6&&(Ti(c.row,r.x*d,r.y*d),delete c.row.arcFanGeneration,delete c.row.rowBlockGeneration,s=!0)}),s}function Ei(t,e){let n={x:-e.y,y:e.x},r=L(t[0]),i=t.map(o=>le(L(o),r,n)).sort((o,s)=>o-s);if(i.length<2)return 28;let a=(i[i.length-1]-i[0])/(i.length-1);return a>.5?a:28}function Ni(t){if(t.seatCount<2){t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration;return}let e=ue(t),n=e[0],r=e[e.length-1],i=r.x-n.x,a=r.y-n.y,o=Math.hypot(i,a);t.path&&(t.origin={...n},t.seatSpacing=Math.max(1,o/(t.seatCount-1))),o>1e-6&&(t.rotation=ze(Math.atan2(a,i)/q)),t.curve=0,delete t.path,delete t.arcFanGeneration,delete t.rowBlockGeneration}function Di(t,e){let n=new Set(t.filter(r=>r.type==="row").map(r=>r.label));for(let r=2;r<1e4;r++){let i=`${e}${r}`.slice(0,80);if(!n.has(i))return i}return`${e}-${Date.now().toString(36)}`}function Gi(t,e){let n=C(t,e.floorId),r=[...new Set(e.rowIds)];if(r.length<2)throw new u("invalid_operation","Select at least two rows to merge");let i=r.map(S=>n.objects.find(I=>I.type==="row"&&I.id===S)),a=r.filter((S,I)=>!i[I]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let o=i,s=o.filter(S=>S.path||S.curve!==0);if(s.length)throw new u("invalid_operation","Only straight rows can be merged \u2014 straighten the rows first, then merge.",{rowIds:s.map(S=>S.id)});let c=o[0],l=o.find(S=>Fi(S.rotation,c.rotation)>Ri);if(l)throw new u("invalid_operation","Rows must be parallel to merge \u2014 they point in different directions.",{rowIds:[c.id,l.id]});let d=Li(c),g={x:-d.y,y:d.x},h=Math.max(8,c.seatSpacing*.6),f=o.find(S=>Math.abs(le(S.origin,c.origin,g))>h);if(f){let S=Math.round(Math.abs(le(f.origin,c.origin,g)));throw new u("invalid_operation",`Rows must lie on the same line to merge \u2014 a selected row is offset ${S} units from the first.`,{rowIds:[c.id,f.id]})}let b=o.slice().sort((S,I)=>le(S.origin,c.origin,d)-le(I.origin,c.origin,d)),y=b.reduce((S,I)=>S+I.seatCount,0);if(y>300)throw new u("invalid_operation",`A merged row would have ${y} seats, over the 300-seat row limit. Merge fewer rows.`);let x=b[0],v=[],p=0;for(let S of b){if(S.overrides)for(let I of S.overrides)v.push({...structuredClone(I),index:I.index+p});p+=S.seatCount}x.seatCount=y,x.curve=0,delete x.path,v.length?x.overrides=v:delete x.overrides,delete x.arcFanGeneration,delete x.rowBlockGeneration;let m=b.slice(1).map(S=>S.id),w=new Set(m);for(let S=n.objects.length-1;S>=0;S--)w.has(n.objects[S].id)&&n.objects.splice(S,1);return{floorId:n.floorId,changed:!0,rowId:x.id,removedRowIds:m,seatCount:y}}function Ki(t,e){let n=C(t,e.floorId),r=n.objects.find(f=>f.type==="row"&&f.id===e.rowId);if(!r)throw new u("object_not_found","The row id does not exist on the selected floor",{rowIds:[e.rowId]});if(r.path)throw new u("invalid_operation","Cannot split a free-form curved row \u2014 straighten it first, then split.",{rowIds:[r.id]});let i=r.seatCount,a=e.index;if(!Number.isInteger(a)||a<1||a>i-1)throw new u("invalid_operation",`Split position must be a whole number from 1 to ${i-1} (the seat where the second row begins)`);let o=ue(r),s=i>1?r.curve/(i-1):0,c=i-a,l={type:"row",id:_(t,"r",e.idFactory,new Set),label:Di(n.objects,r.label),origin:{...o[a]},rotation:ze(r.rotation-s*a),curve:s*(c-1),seatCount:c,seatSpacing:r.seatSpacing,categoryKey:r.categoryKey};if(r.seatNumbering&&(l.seatNumbering=structuredClone(r.seatNumbering)),r.seatLabelStart!=null&&(l.seatLabelStart=r.seatLabelStart),r.commercial&&(l.commercial=structuredClone(r.commercial)),r.viewFromSeatUrl&&(l.viewFromSeatUrl=r.viewFromSeatUrl),r.viewFromSeatMeta&&(l.viewFromSeatMeta=structuredClone(r.viewFromSeatMeta)),r.confidenceEvidence&&(l.confidenceEvidence=structuredClone(r.confidenceEvidence)),r.labelPresentation){let f=structuredClone(r.labelPresentation);delete f.position,l.labelPresentation=f}let d=[],g=[];if(r.overrides)for(let f of r.overrides)f.index<a?d.push(structuredClone(f)):g.push({...structuredClone(f),index:f.index-a});r.seatCount=a,r.curve=s*(a-1),d.length?r.overrides=d:delete r.overrides,delete r.arcFanGeneration,delete r.rowBlockGeneration,g.length&&(l.overrides=g);let h=n.objects.indexOf(r);return n.objects.splice(h+1,0,l),{floorId:n.floorId,changed:!0,rowId:r.id,newRowId:l.id,firstSeatCount:a,secondSeatCount:c,newLabel:l.label}}function $i(t,e){let n=C(t,e.floorId),r=[...new Set(e.rowIds)];if(r.length<2)throw new u("invalid_operation","Select at least two rows to set row spacing");if(!Number.isFinite(e.gap)||e.gap<=0||e.gap>4e3)throw new u("invalid_operation","Row spacing must be a positive value up to 4000 chart units");let i=r.map(s=>n.objects.find(c=>c.type==="row"&&c.id===s)),a=r.filter((s,c)=>!i[c]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let o=Fn(i,e.gap);return{floorId:n.floorId,changed:o,rowIds:r,gap:e.gap}}function zi(t,e){let n=C(t,e.floorId),r=[...new Set(e.rowIds)];if(r.length<2)throw new u("invalid_operation","Select at least two rows to straighten and space evenly");let i=r.map(h=>n.objects.find(f=>f.type==="row"&&f.id===h)),a=r.filter((h,f)=>!i[f]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let o=i,s=()=>JSON.stringify(o.map(h=>[h.origin,h.rotation,h.curve,h.path??null,h.seatSpacing])),c=s();for(let h of o)Ni(h);let l=Ln(o),d=ze(Math.atan2(l.y,l.x)/q);for(let h of o)h.rotation=d;let g=Ei(o,l);return Fn(o,g),{floorId:n.floorId,changed:s()!==c,rowIds:r,gap:g}}var Ue=ro(require("polygon-clipping"),1),Tn=100,En=512,yt=8192,Un=64,Nn=1e7,R=1e-7;function Hn(t,e){return Math.abs(t.x-e.x)<=R&&Math.abs(t.y-e.y)<=R}function Vn(t){let e=t.map(n=>({x:n.x,y:n.y}));for(;e.length>1&&Hn(e[0],e[e.length-1]);)e.pop();return e}function xe(t,e,n){let r=J(e,n,t);return Math.abs(r)>R?!1:t.x>=Math.min(e.x,n.x)-R&&t.x<=Math.max(e.x,n.x)+R&&t.y>=Math.min(e.y,n.y)-R&&t.y<=Math.max(e.y,n.y)+R}function Jn(t,e,n,r){let i=J(t,e,n),a=J(t,e,r),o=J(n,r,t),s=J(n,r,e);return(i>R&&a<-R||i<-R&&a>R)&&(o>R&&s<-R||o<-R&&s>R)?!0:Math.abs(i)<=R&&xe(n,t,e)||Math.abs(a)<=R&&xe(r,t,e)||Math.abs(o)<=R&&xe(t,n,r)||Math.abs(s)<=R&&xe(e,n,r)}function Bi(t){for(let e=0;e<t.length;e+=1){let n=(e+1)%t.length;for(let r=e+1;r<t.length;r+=1){let i=(r+1)%t.length;if(!(e===r||n===r||i===e)&&Jn(t[e],t[n],t[r],t[i]))return!0}}return!1}function Dn(t,e){return t.some((n,r)=>e.some((i,a)=>Jn(n,t[(r+1)%t.length],i,e[(a+1)%e.length])))}function wt(t,e){return!e.some((n,r)=>xe(t,n,e[(r+1)%e.length]))&&N(t,e,void 0)}function He(t,e,n){let r=Vn(t);if(r.length<3||r.length>En||r.some((i,a)=>!Number.isFinite(i.x)||!Number.isFinite(i.y)||Math.abs(i.x)>Nn||Math.abs(i.y)>Nn||Hn(i,r[(a+1)%r.length]))||Math.abs(de(r))<=R||Bi(r))throw new u("invalid_operation",`GA area ${n} has an invalid or self-intersecting ${e}; Join Areas accepts 3\u2013${En} finite vertices per ring.`,{gaAreaId:n,ring:e});return r}function Ui(t){let e=He(t.points,"outline",t.id),n=t.holes??[];if(!Array.isArray(n)||n.length>Un)throw new u("invalid_operation",`GA area ${t.id} has too many cutouts to join`,{gaAreaId:t.id});let r=n.map(i=>He(i,"cutout",t.id));for(let i=0;i<r.length;i+=1){let a=r[i];if(!a.flatMap((s,c)=>{let l=a[(c+1)%a.length];return[s,{x:(s.x+l.x)/2,y:(s.y+l.y)/2}]}).every(s=>wt(s,e))||Dn(a,e))throw new u("invalid_operation",`GA area ${t.id} has a cutout outside its outline`,{gaAreaId:t.id,holeIndex:i});for(let s=i+1;s<r.length;s+=1)if(Dn(a,r[s])||wt(a[0],r[s])||wt(r[s][0],a))throw new u("invalid_operation",`GA area ${t.id} has overlapping cutouts`,{gaAreaId:t.id,holeIndex:i})}return{outer:e,holes:r}}function Be(t){return t.map(e=>[e.x,e.y])}function Gn(t){return Vn(t.map(([e,n])=>({x:e,y:n})))}function Kn(t){return Math.abs(t.reduce((e,n,r)=>{let i=t[(r+1)%t.length];return e+n[0]*i[1]-i[0]*n[1]},0))/2}function Hi(t){return t.reduce((e,n)=>e+(Kn(n[0]??[])-n.slice(1).reduce((r,i)=>r+Kn(i),0)),0)}function xt(t){if(t===void 0)return"undefined";if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(xt).join(",")}]`;let e=t;return`{${Object.keys(e).sort().map(n=>`${JSON.stringify(n)}:${xt(e[n])}`).join(",")}}`}function $n(t,e,n){let r=t[e];if(r===void 0)return null;let i=r.normalize("NFKC").trim();if(!i||i!==r||i.length>n)throw new u("invalid_operation",`GA area ${t.id} has an invalid ${e}; normalize it to 1\u2013${n} characters before joining.`,{gaAreaId:t.id,field:e});return i}function zn(t){return xt({categoryKey:t.categoryKey,displayLabel:$n(t,"displayLabel",80),displayType:$n(t,"displayType",24),referenceInventorySource:t.referenceInventorySource??null})}function Bn(t,e){let n=Math.min(...t.points.map(i=>i.y)),r=Math.min(...t.points.map(i=>i.x));return[n,r,e]}function Vi(t,e){return t[0]-e[0]||t[1]-e[1]||t[2]-e[2]}function qn(t,e){let n=C(t,e.floorId),r=[...new Set(e.gaAreaIds)];if(r.length<2)throw new u("invalid_operation","Select at least two GA areas to join");if(r.length>Tn)throw new u("invalid_operation",`Join Areas supports at most ${Tn} areas at once`);let i=r.map(P=>n.objects.find(A=>A.type==="gaArea"&&A.id===P)),a=r.filter((P,A)=>!i[A]);if(a.length)throw new u("object_not_found","One or more GA area ids do not exist on the selected floor",{gaAreaIds:a});let o=i;k(t,o[0].categoryKey);let s=zn(o[0]),c=o.find(P=>zn(P)!==s);if(c)throw new u("invalid_operation","GA areas must use the same category, displayed label, displayed type, and reference-inventory provenance before they can be joined.",{gaAreaIds:[o[0].id,c.id]});let l=he(t).objectToSection,d=l.get(o[0].id)??"__ungrouped__",g=o.find(P=>(l.get(P.id)??"__ungrouped__")!==d);if(g)throw new u("invalid_operation","GA areas must belong to the same buyer section before they can be joined.",{gaAreaIds:[o[0].id,g.id],sectionIds:[d,l.get(g.id)??"__ungrouped__"]});let h=o.reduce((P,A)=>{if(!Number.isInteger(A.capacity)||A.capacity<1||A.capacity>ee)throw new u("invalid_operation",`GA area ${A.id} has invalid capacity`,{gaAreaId:A.id});return P+A.capacity},0);if(h>ee)throw new u("invalid_operation",`Joined GA capacity would be ${h}, over the ${ee}-unit area limit`,{capacity:h});let f=H(t).reduce((P,A)=>P+W(A),0);if(f>ce)throw new u("invalid_operation",`Chart inventory exceeds the ${ce}-unit publication limit`,{inventory:f});let b=o.map(Ui),y=b.reduce((P,A)=>P+A.outer.length+A.holes.reduce((V,Q)=>V+Q.length,0),0);if(y>yt)throw new u("invalid_operation",`Join Areas supports at most ${yt} source vertices`,{vertexCount:y});let x;try{let P=b.map(Q=>[Be(Q.outer)]);if(x=Ue.default.union(P[0],...P.slice(1)),x.length!==1)throw new u("invalid_operation","Selected GA areas must overlap or share an edge. Disconnected or point-only contact cannot produce one sellable surface.",{surfaceCount:x.length});let A=b.flatMap(Q=>Q.holes.map(Je=>[Be(Je)]));A.length&&(x=Ue.default.difference(x,...A));let V=b.findIndex(Q=>{let Je=[Be(Q.outer),...Q.holes.map(Be)];return Hi(Ue.default.intersection(Je,x))<=R});if(V>=0)throw new u("invalid_operation",`GA area ${o[V].id} contributes no sellable surface after preserving every source cutout.`,{gaAreaId:o[V].id})}catch(P){throw P instanceof u?P:new u("invalid_operation","The selected GA boundaries could not be joined safely",{reason:P instanceof Error?P.message:"polygon_union_failed"})}if(x.length!==1||!x[0]?.length)throw new u("invalid_operation","Joining these boundaries would create disconnected sellable surfaces; adjust the outlines or cutouts first.",{surfaceCount:x.length});let v=Gn(x[0][0]),p=x[0].slice(1).map(Gn),m=v.length+p.reduce((P,A)=>P+A.length,0);if(p.length>Un||m>yt)throw new u("invalid_operation","The joined boundary is too complex to store safely",{holeCount:p.length,vertexCount:m});He(v,"outline",o[0].id),p.forEach(P=>He(P,"cutout",o[0].id));let w=new Map(n.objects.map((P,A)=>[P.id,A])),S=o.slice().sort((P,A)=>Vi(Bn(P,w.get(P.id)??Number.MAX_SAFE_INTEGER),Bn(A,w.get(A.id)??Number.MAX_SAFE_INTEGER))),I=S[0],M=structuredClone(t),D=C(M,n.floorId),T=D.objects.find(P=>P.type==="gaArea"&&P.id===I.id);T.points=structuredClone(v),p.length?T.holes=structuredClone(p):delete T.holes;let U=new Set(S.slice(1).map(P=>P.id));for(let P=D.objects.length-1;P>=0;P-=1)U.has(D.objects[P].id)&&D.objects.splice(P,1);let K=he(M).objectToSection.get(I.id)??"__ungrouped__";if(K!==d)throw new u("invalid_operation","The joined surface would change buyer-section ownership; adjust the GA or section boundaries first.",{gaAreaId:I.id,beforeSectionId:d,afterSectionId:K});let O=[],$=new Set;for(let P of S){if(!lt(P))throw new u("invalid_operation",`GA area ${P.id} has invalid inventory provenance and cannot be joined`,{gaAreaId:P.id});let A=te(P);if(A.length!==P.capacity||A.some(V=>$.has(V)))throw new u("invalid_operation","Selected GA areas contain duplicated or incomplete stable inventory identities",{gaAreaId:P.id});A.forEach(V=>$.add(V)),O.push(...Le(P))}if(O.length>256)throw new u("invalid_operation","Joined inventory provenance would exceed 256 durable source ranges");let j=new Set(o.map(P=>P.id));for(let P of H(t).filter(A=>A.type==="gaArea"&&!j.has(A.id))){let A=te(P).find(V=>$.has(V));if(A)throw new u("invalid_operation","A stable GA inventory identity is already owned by another area",{label:A,gaAreaId:P.id})}let Ve=S.slice(1).map(P=>P.id);return{floorId:n.floorId,areaId:I.id,survivorLabel:I.label,removedAreaIds:Ve,sourceAreaCount:S.length,capacity:h,inventorySegmentCount:O.length,outerVertexCount:v.length,holeCount:p.length,sectionId:d,points:v,...p.length?{holes:p}:{},segments:O}}function Ji(t,e){let{segments:n,...r}=qn(t,e);return r}function qi(t,e){let n=qn(t,e),r=C(t,n.floorId),i=r.objects.find(c=>c.type==="gaArea"&&c.id===n.areaId);i.points=structuredClone(n.points),n.holes?.length?i.holes=structuredClone(n.holes):delete i.holes,i.capacity=n.capacity,i.inventorySegments=structuredClone(n.segments);let a=new Set(n.removedAreaIds);for(let c=r.objects.length-1;c>=0;c-=1)a.has(r.objects[c].id)&&r.objects.splice(c,1);let{segments:o,...s}=n;return{...s,changed:!0}}var Xn=[{key:"rect",label:"Flat stage",icon:"\u25AD",blurb:"Classic proscenium box."},{key:"rounded",label:"Rounded",icon:"\u25A2",blurb:"Softened corners."},{key:"arc",label:"Curved front",icon:"\u25D7",blurb:"Front edge bows toward the audience."},{key:"thrust",label:"Thrust (T)",icon:"\u22A4",blurb:"Central tongue projects into the crowd."},{key:"runway",label:"Runway",icon:"\u2337",blurb:"Long catwalk into the audience."},{key:"round",label:"In the round",icon:"\u25EF",blurb:"Central platform, audience all around."},{key:"pitch-football",label:"Football pitch",icon:"\u2B1B",blurb:"105 \xD7 68 m pitch with centre circle and penalty boxes."},{key:"rink-hockey",label:"Hockey rink",icon:"\u2B2D",blurb:"60 \xD7 30 m ice rink with blue lines and faceoff circles."},{key:"track-athletics",label:"Athletics track",icon:"\u2B2F",blurb:"400 m track: two straights, two semicircles, eight lanes."},{key:"oval-cricket",label:"Cricket oval",icon:"\u2B2E",blurb:"~150 \xD7 140 m oval with boundary rope and pitch strip."}];var Xi=Math.PI*2;function Qi(t,e,n,r,i,a){return{x:i+t*n-e*r,y:a+t*r+e*n}}function Qn(t){let{kind:e,cx:n,cy:r,width:i,height:a}=t,o=(t.rotation??0)*Math.PI/180,s=Math.cos(o),c=Math.sin(o),l=i/2,d=a/2,g=[],h=(f,b)=>{g.push({x:f,y:b})};switch(e){case"rect":{h(-l,-d),h(l,-d),h(l,d),h(-l,d);break}case"rounded":{let f=Math.min(i,a)*.18,b=5,y=(x,v,p)=>{for(let m=0;m<=b;m++){let w=p+m/b*(Math.PI/2);h(x+f*Math.cos(w),v+f*Math.sin(w))}};y(l-f,-d+f,-Math.PI/2),y(l-f,d-f,0),y(-l+f,d-f,Math.PI/2),y(-l+f,-d+f,Math.PI);break}case"arc":{let f=a*.45;h(-l,-d),h(l,-d);let b=24;for(let y=0;y<=b;y++){let x=y/b,v=l-x*i,p=d+f*(1-Math.pow(2*v/i,2));h(v,p)}break}case"thrust":{let f=i*.18,b=a*1.1;h(-l,-d),h(l,-d),h(l,d),h(f,d),h(f,d+b),h(-f,d+b),h(-f,d),h(-l,d);break}case"runway":{let f=i*.1,b=a*3;h(-l,-d),h(l,-d),h(l,d),h(f,d),h(f,d+b),h(-f,d+b),h(-f,d),h(-l,d);break}case"round":case"oval-cricket":{for(let b=0;b<40;b++){let y=b/40*Xi;h(l*Math.cos(y),d*Math.sin(y))}break}case"pitch-football":{h(-l,-d),h(l,-d),h(l,d),h(-l,d);break}case"rink-hockey":{for(let f of Yi(l,d,l*(8.5/60),d*(8.5/30)))h(f.x,f.y);break}case"track-athletics":{for(let f of Zi(l,d))h(f.x,f.y);break}}return g.map(f=>Qi(f.x,f.y,s,c,n,r))}function Yi(t,e,n,r){let i=[],o=(s,c,l)=>{for(let d=0;d<=8;d++){let g=l+d/8*(Math.PI/2);i.push({x:s+n*Math.cos(g),y:c+r*Math.sin(g)})}};return o(t-n,-e+r,-Math.PI/2),o(t-n,e-r,0),o(-t+n,e-r,Math.PI/2),o(-t+n,-e+r,Math.PI),i}function Zi(t,e){let n=Math.max(0,t-e),r=[],i=20;for(let a=0;a<=i;a++){let o=-Math.PI/2+a/i*Math.PI;r.push({x:n+e*Math.cos(o),y:e*Math.sin(o)})}for(let a=0;a<=i;a++){let o=Math.PI/2+a/i*Math.PI;r.push({x:-n+e*Math.cos(o),y:e*Math.sin(o)})}return r}function Wi(t,e){let n=C(t,e.floorId),r=[...new Set(e.shapeIds)];if(!r.length)throw new u("invalid_operation","At least one shape id is required");let i=r.map(l=>n.objects.find(d=>d.type==="shape"&&d.id===l)),a=r.filter((l,d)=>!i[d]);if(a.length)throw new u("object_not_found",`Unknown shape id(s): ${a.join(", ")} on the selected floor. Call get_chart to list current shape ids.`,{shapeIds:a});let o=structuredClone(e.patch);if(!Object.keys(o).length)throw new u("invalid_operation","At least one shape change is required");if(o.label!==void 0){if(r.length!==1)throw new u("invalid_operation","label can be changed only for one shape at a time");if(o.label!==null){if(o.label=o.label.normalize("NFKC").trim(),!o.label)o.label=null;else if(o.label.length>80)throw new u("invalid_operation","Shape labels support at most 80 characters")}}if(o.fill!==void 0&&o.fill!==null&&(o.fill=F(o.fill,"Shape fill")),o.kind!==void 0&&!["rect","ellipse","polygon","line","polyline"].includes(o.kind))throw new u("invalid_operation","Shape kind must be rect, ellipse, polygon, line, or polyline");if(o.stroke!==void 0&&o.stroke!==null){if(!Number.isFinite(o.stroke.width)||o.stroke.width<.5||o.stroke.width>40)throw new u("invalid_operation","Shape stroke width must be from 0.5 to 40 chart units");o.stroke={color:F(o.stroke.color,"Shape stroke"),width:o.stroke.width}}if(o.cornerRadius!==void 0&&o.cornerRadius!==null&&(!Number.isFinite(o.cornerRadius)||o.cornerRadius<0||o.cornerRadius>5e3))throw new u("invalid_operation","Shape cornerRadius must be from 0 to 5000 chart units");if(o.opacity!==void 0&&o.opacity!==null&&(!Number.isFinite(o.opacity)||o.opacity<.1||o.opacity>1))throw new u("invalid_operation","Shape opacity must be from 0.1 to 1");if(o.heightM!==void 0&&o.heightM!==null&&(!Number.isFinite(o.heightM)||o.heightM<.05||o.heightM>50))throw new u("invalid_operation","Shape heightM must be from 0.05 to 50 metres");if(o.eventConfigurationIds!==void 0&&o.eventConfigurationIds!==null){let l=o.eventConfigurationIds.map(d=>d.normalize("NFKC").trim());if(!l.length||l.length>20||l.some(d=>!d||d.length>100)||new Set(l).size!==l.length)throw new u("invalid_operation","Shape event configurations must contain 1 to 20 unique ids");o.eventConfigurationIds=l}if(o.lineCap!==void 0&&o.lineCap!==null&&!hn.includes(o.lineCap))throw new u("invalid_operation","Shape lineCap must be butt, round, or square");if(o.lineJoin!==void 0&&o.lineJoin!==null&&!bn.includes(o.lineJoin))throw new u("invalid_operation","Shape lineJoin must be miter, round, or bevel");for(let[l,d]of[["startEnding",o.startEnding],["endEnding",o.endEnding]])if(d!=null&&!pn.includes(d))throw new u("invalid_operation",`Shape ${l} must be none or arrow`);if(o.lineCap!=null||o.lineJoin!=null||o.startEnding!=null||o.endEnding!=null){let l=i.filter(d=>!ht(o.kind??d.kind));if(l.length)throw new u("invalid_operation","Line caps, joins, and start/end decorations apply only to open line or polyline shapes",{shapeIds:l.map(d=>d.id)})}let c=!1;for(let l of i){let d=JSON.stringify(l);if(o.label===null?delete l.label:o.label!==void 0&&(l.label=o.label),o.fill===null?delete l.fill:o.fill!==void 0&&(l.fill=o.fill),o.kind!==void 0&&(l.kind=o.kind,ht(l.kind)||(delete l.lineCap,delete l.lineJoin,delete l.startEnding,delete l.endEnding)),o.stroke===null?delete l.stroke:o.stroke!==void 0&&(l.stroke={...o.stroke}),o.opacity===null?delete l.opacity:o.opacity!==void 0&&(l.opacity=o.opacity),o.heightM===null?delete l.heightM:o.heightM!==void 0&&(l.heightM=o.heightM),o.eventConfigurationIds===null?delete l.eventConfigurationIds:o.eventConfigurationIds!==void 0&&(l.eventConfigurationIds=[...o.eventConfigurationIds]),o.lineCap===null?delete l.lineCap:o.lineCap!==void 0&&(l.lineCap=o.lineCap),o.lineJoin===null?delete l.lineJoin:o.lineJoin!==void 0&&(l.lineJoin=o.lineJoin),o.startEnding===null?delete l.startEnding:o.startEnding!==void 0&&(l.startEnding=o.startEnding),o.endEnding===null?delete l.endEnding:o.endEnding!==void 0&&(l.endEnding=o.endEnding),o.cornerRadius===null)delete l.cornerRadius;else if(o.cornerRadius!==void 0){let g=Math.min(l.width??1/0,l.height??1/0),h=Number.isFinite(g)?g/2:o.cornerRadius;l.cornerRadius=l.kind==="rect"?Math.max(0,Math.min(o.cornerRadius,h)):o.cornerRadius}JSON.stringify(l)!==d&&(c=!0)}return{floorId:n.floorId,changed:c,shapeIds:r}}function Yn(t){if(t.x!=null&&t.y!=null&&t.width!=null&&t.height!=null){if(![t.x,t.y,t.width,t.height].every(Number.isFinite)||t.width<=0||t.height<=0)throw new u("invalid_operation",`Stage ${t.id} has an invalid stored base box`,{stageId:t.id});return{cx:t.x+t.width/2,cy:t.y+t.height/2,width:t.width,height:t.height}}let e=t.points??[];if(e.length<3||e.some(d=>!Number.isFinite(d.x)||!Number.isFinite(d.y)))throw new u("invalid_operation",`Stage ${t.id} has no valid geometry from which to derive its base box`,{stageId:t.id});let n=e.map(d=>d.x),r=e.map(d=>d.y),i=Math.min(...n),a=Math.max(...n),o=Math.min(...r),s=Math.max(...r),c=Math.max(1,a-i),l=Math.max(1,s-o);return{cx:i+c/2,cy:o+l/2,width:c,height:l}}function ea(t,e){let n=C(t,e.floorId);if(!e.updates.length)throw new u("invalid_operation","At least one shape resize is required");let r=e.updates.map(o=>o.shapeId);if(new Set(r).size!==r.length)throw new u("invalid_operation","Shape ids must be unique");let i=e.updates.map(o=>{if(![o.width,o.height].every(Number.isFinite)||o.width<8||o.height<8||o.width>1e4||o.height>1e4)throw new u("invalid_operation","Shape width and height must be between 8 and 10000 chart units",{shapeId:o.shapeId});let s=n.objects.find(l=>l.type==="shape"&&l.id===o.shapeId);if(!s)throw new u("object_not_found",`Unknown shape id: ${o.shapeId}`,{shapeId:o.shapeId});let c=s.role==="stage"?Yn(s):(s.kind==="rect"||s.kind==="ellipse")&&s.x!=null&&s.y!=null&&s.width!=null&&s.height!=null?{cx:s.x+s.width/2,cy:s.y+s.height/2,width:s.width,height:s.height}:(()=>{let l=s.points??[];if(l.length<3||l.some(x=>!Number.isFinite(x.x)||!Number.isFinite(x.y)))throw new u("invalid_operation",`Shape ${s.id} has no resizable geometry`,{shapeId:s.id});let d=l.map(x=>x.x),g=l.map(x=>x.y),h=Math.min(...d),f=Math.max(...d),b=Math.min(...g),y=Math.max(...g);return{cx:(h+f)/2,cy:(b+y)/2,width:Math.max(1,f-h),height:Math.max(1,y-b)}})();return{shape:s,update:o,box:c}}),a=!1;for(let{shape:o,update:s,box:c}of i)if(!(Math.abs(c.width-s.width)<1e-9&&Math.abs(c.height-s.height)<1e-9)){if(o.kind==="rect"||o.kind==="ellipse")o.x=c.cx-s.width/2,o.y=c.cy-s.height/2,o.width=s.width,o.height=s.height;else{let l=s.width/c.width,d=s.height/c.height;o.points=(o.points??[]).map(g=>({x:c.cx+(g.x-c.cx)*l,y:c.cy+(g.y-c.cy)*d})),(o.x!=null||o.y!=null||o.width!=null||o.height!=null||o.role==="stage")&&(o.x=c.cx-s.width/2,o.y=c.cy-s.height/2,o.width=s.width,o.height=s.height)}a=!0}return{floorId:n.floorId,changed:a,shapes:i.map(({shape:o,update:s})=>({id:o.id,width:s.width,height:s.height}))}}function ta(t,e){let n=C(t,e.floorId);if(!e.updates.length)throw new u("invalid_operation","At least one stage update is required");let r=e.updates.map(s=>s.stageId);if(new Set(r).size!==r.length)throw new u("invalid_operation","Stage ids must be unique");let i=new Set(Xn.map(s=>s.key)),a=e.updates.map(s=>{if(!i.has(s.stageKind))throw new u("invalid_operation",`Unknown stage kind: ${s.stageKind}`,{stageKind:s.stageKind});let c=n.objects.find(l=>l.type==="shape"&&l.id===s.stageId);if(!c)throw new u("object_not_found",`Unknown stage id: ${s.stageId}. Call get_chart to list current stage ids.`,{stageId:s.stageId});if(c.role!=="stage")throw new u("invalid_operation",`Shape ${s.stageId} is not tagged as a stage`,{stageId:s.stageId});return{shape:c,stageKind:s.stageKind,box:c.stageKind===s.stageKind?null:Yn(c)}}),o=!1;for(let s of a)s.box&&(s.shape.points=Qn({kind:s.stageKind,...s.box}),s.shape.kind="polygon",s.shape.stageKind=s.stageKind,o=!0);return{floorId:n.floorId,changed:o,stages:a.map(s=>({id:s.shape.id,stageKind:s.stageKind}))}}0&&(module.exports={COLORBLIND_SAFE_PALETTE,ChartOperationError,DEFAULT_FLOOR_HEIGHT_STEP_M,DEFAULT_SECTION_CORNER_SMOOTHING,MAX_FLOOR_BASE_HEIGHT_M,addArcFanRows,addBookableGridArray,addBoothArray,addChartCategory,addChartFloor,addChartZone,addGAArea,addRowBlock,addTableArray,applyPolygonHole,applyReferenceScanRows,applySectionCornerSmoothing,applySectionOutlineShaping,applySectionRowFit,arcFanInputForGroup,assignSectionInventoryCategory,automaticPlacementCenter,confirmReferenceCategoryOutputColor,convertGeneratedSectionToPolygon,countCoveredInventory,familyCategoryLabel,gaAreaFootprint,groupRowsAsSegmented,insertSeatingBlock,joinGAAreas,mergeRows,mirrorFirstFloor,parseSeatRefId,pickColorblindSafeCategoryColor,previewArcFanRows,previewBookableGridArray,previewGeneratedSectionPolygonConversion,previewJoinGAAreas,previewPolygonHole,previewRemovePolygonHole,previewRowCubicPath,previewSectionRowFit,reassignColorblindSafeCategoryColors,relabelChartRows,removeChartCategory,removeChartFloor,removeChartObjects,removeChartZone,removePolygonHole,renameChartFloor,reorderChartCategories,replaceArcFanRows,replaceRowBlock,resetSeatOverrides,resizeShapes,resolveCreationCategory,seatRefId,sectionInventorySelectionSummary,setRowBlockSpacing,splitRow,straightenAndSpaceRows,transformSectionBoundary,transformSectionBoundaryObject,ungroupSegmentedRow,updateBooths,updateCategoryDefinitions,updateChartFloorBaseHeight,updateChartTheme,updateChartZones,updateGAAreas,updateRowCubicPath,updateRows,updateSeatOverrides,updateSectionExactPath,updateSectionMetadata,updateSegmentedRow,updateShapes,updateStageKinds,updateTables,updateTextObjects,updateViewFromSeatFallback});