@seatlayer/core 0.71.5 → 0.72.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 (74) hide show
  1. package/dist/{categoryInventory-r3OfIEQn.d.cts → categoryInventory-BU1j8Q70.d.cts} +1 -1
  2. package/dist/{categoryInventory-B8CDQtH4.d.ts → categoryInventory-Bt-0psga.d.ts} +1 -1
  3. package/dist/chunk-5U25QLSS.js +1 -0
  4. package/dist/{chunk-LR7WIR5Z.js → chunk-ALE2T36W.js} +1 -1
  5. package/dist/chunk-BLPBTW6I.js +1 -0
  6. package/dist/{chunk-GXMGOWKB.js → chunk-FMZ6HLDH.js} +1 -1
  7. package/dist/chunk-HXYWP6NX.js +1 -0
  8. package/dist/chunk-JBOTRSMY.js +1 -0
  9. package/dist/{chunk-MR2O5WC7.js → chunk-O5UWBFUT.js} +1 -1
  10. package/dist/chunk-XLGYWT5G.js +1 -0
  11. package/dist/chunk-YW2WGLRM.js +1 -0
  12. package/dist/core/chart-ops/index.cjs +1 -1
  13. package/dist/core/chart-ops/index.d.cts +38 -9
  14. package/dist/core/chart-ops/index.d.ts +38 -9
  15. package/dist/core/chart-ops/index.js +1 -1
  16. package/dist/core/color.cjs +1 -1
  17. package/dist/core/color.d.cts +4 -1
  18. package/dist/core/color.d.ts +4 -1
  19. package/dist/core/color.js +1 -1
  20. package/dist/core/inventory/index.cjs +1 -1
  21. package/dist/core/inventory/index.d.cts +15 -5
  22. package/dist/core/inventory/index.d.ts +15 -5
  23. package/dist/core/inventory/index.js +1 -1
  24. package/dist/core/layout/index.d.cts +6 -6
  25. package/dist/core/layout/index.d.ts +6 -6
  26. package/dist/core/quality/index.cjs +1 -1
  27. package/dist/core/quality/index.d.cts +3 -3
  28. package/dist/core/quality/index.d.ts +3 -3
  29. package/dist/core/quality/index.js +1 -1
  30. package/dist/core/render-assets/index.cjs +1 -1
  31. package/dist/core/render-assets/index.d.cts +1 -1
  32. package/dist/core/render-assets/index.d.ts +1 -1
  33. package/dist/core/render-assets/index.js +1 -1
  34. package/dist/core/seatConfidence.d.cts +1 -1
  35. package/dist/core/seatConfidence.d.ts +1 -1
  36. package/dist/core/sections/index.d.cts +7 -7
  37. package/dist/core/sections/index.d.ts +7 -7
  38. package/dist/{eventConfigurations-ByU_uPeS.d.cts → eventConfigurations-3uSorYVC.d.cts} +1 -1
  39. package/dist/{eventConfigurations-0OC43JJY.d.ts → eventConfigurations-DfVUGyCg.d.ts} +1 -1
  40. package/dist/index.cjs +1 -1
  41. package/dist/index.d.cts +12 -12
  42. package/dist/index.d.ts +12 -12
  43. package/dist/index.js +1 -1
  44. package/dist/{labeling-DAGq3u0z.d.cts → labeling-9RWWmJhZ.d.cts} +1 -1
  45. package/dist/{labeling-B05IJwd2.d.ts → labeling-BiWB-8aq.d.ts} +1 -1
  46. package/dist/{layout-e0Qe7jmM.d.cts → layout-B6iOoPOv.d.cts} +3 -3
  47. package/dist/{layout-DkDRcXvu.d.ts → layout-B7URbtDR.d.ts} +3 -3
  48. package/dist/{renderedQuality-BaejczsK.d.cts → renderedQuality-BZsq3wDe.d.cts} +1 -1
  49. package/dist/{renderedQuality-BwwrqYzX.d.ts → renderedQuality-C5dQiq97.d.ts} +1 -1
  50. package/dist/{renderer-BNicx5sw.d.ts → renderer-6sFRupj0.d.ts} +2 -2
  51. package/dist/{renderer-Duv1HhQg.d.cts → renderer-CBOo1OZk.d.cts} +2 -2
  52. package/dist/{sections-CrX4vq-m.d.ts → sections-Cn_sk1Sx.d.ts} +1 -1
  53. package/dist/{sections-BjGjR21N.d.cts → sections-DU6YDYoZ.d.cts} +1 -1
  54. package/dist/{segmentedRowModel-UO_YIQRB.d.cts → segmentedRowModel-CKmyHvKv.d.cts} +1 -1
  55. package/dist/{segmentedRowModel-BOO8w9Ng.d.ts → segmentedRowModel-DbP7pWUk.d.ts} +1 -1
  56. package/dist/{ticketRestrictions-dvlNTwem.d.ts → ticketRestrictions-CvS2oQ8v.d.ts} +2 -2
  57. package/dist/{ticketRestrictions-DUQrKTpS.d.cts → ticketRestrictions-DkenahW2.d.cts} +2 -2
  58. package/dist/{types-0yruRsAj.d.cts → types-D6-wLa-m.d.cts} +200 -20
  59. package/dist/{types-0yruRsAj.d.ts → types-D6-wLa-m.d.ts} +200 -20
  60. package/dist/view3d/crossfade/panorama.d.cts +1 -1
  61. package/dist/view3d/crossfade/panorama.d.ts +1 -1
  62. package/dist/view3d/index.cjs +27 -27
  63. package/dist/view3d/index.d.cts +3 -3
  64. package/dist/view3d/index.d.ts +3 -3
  65. package/dist/view3d/index.js +1 -1
  66. package/dist/view3d/scene/scene.worker.cjs +1 -1
  67. package/dist/view3d/scene/scene.worker.js +1 -1
  68. package/package.json +1 -1
  69. package/dist/chunk-7KS6TAYH.js +0 -1
  70. package/dist/chunk-CXF32VPG.js +0 -1
  71. package/dist/chunk-JBGLFOJO.js +0 -1
  72. package/dist/chunk-NXFDYBZY.js +0 -1
  73. package/dist/chunk-SKO3DCVB.js +0 -1
  74. package/dist/chunk-T2LWVOQ3.js +0 -1
@@ -1 +1 @@
1
- "use strict";var po=Object.create;var Oe=Object.defineProperty;var yo=Object.getOwnPropertyDescriptor;var mo=Object.getOwnPropertyNames;var wo=Object.getPrototypeOf,xo=Object.prototype.hasOwnProperty;var vo=(e,t)=>{for(var n in t)Oe(e,n,{get:t[n],enumerable:!0})},Rt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of mo(t))!xo.call(e,i)&&i!==n&&Oe(e,i,{get:()=>t[i],enumerable:!(o=yo(t,i))||o.enumerable});return e};var So=(e,t,n)=>(n=e!=null?po(wo(e)):{},Rt(t||!e||!e.__esModule?Oe(n,"default",{value:e,enumerable:!0}):n,e)),Io=e=>Rt(Oe({},"__esModule",{value:!0}),e);var Na={};vo(Na,{COLORBLIND_SAFE_PALETTE:()=>It,ChartOperationError:()=>u,DEFAULT_FLOOR_HEIGHT_STEP_M:()=>pt,DEFAULT_SECTION_CORNER_SMOOTHING:()=>at,MAX_BUYER_IMAGE_URL_LENGTH:()=>Zo,MAX_FLOOR_BASE_HEIGHT_M:()=>Te,addArcFanRows:()=>Oi,addBookableGridArray:()=>Vi,addBoothArray:()=>Ei,addChartCategory:()=>Tn,addChartFloor:()=>or,addChartZone:()=>sr,addGAArea:()=>Ri,addRowBlock:()=>Mi,addTableArray:()=>Li,applyPolygonHole:()=>zr,applyReferenceScanRows:()=>Ui,applySectionCornerSmoothing:()=>Yr,applySectionOutlineShaping:()=>Cn,applySectionRowFit:()=>Kr,approveConfidenceEvidence:()=>Ta,arcFanInputForGroup:()=>Kn,assignSectionInventoryCategory:()=>Hr,automaticPlacementCenter:()=>Si,clearConfidenceEvidence:()=>Ea,confidenceEvidenceChangeRequiresPublish:()=>_a,confidenceEvidenceChanges:()=>go,confirmReferenceCategoryOutputColor:()=>ii,convertGeneratedSectionToPolygon:()=>Jr,countCoveredInventory:()=>Ke,familyCategoryLabel:()=>Fn,gaAreaFootprint:()=>Bn,groupRowsAsSegmented:()=>Ti,insertSeatingBlock:()=>Tr,isSafeBuyerImageUrl:()=>nn,joinGAAreas:()=>pa,mergeRows:()=>sa,mirrorFirstFloor:()=>ye,normalizeBuyerImageUrl:()=>Y,normalizeDraftEvidence:()=>bo,parseSeatRefId:()=>Xi,pickColorblindSafeCategoryColor:()=>En,planCreationCategory:()=>Nn,previewArcFanRows:()=>Ct,previewBookableGridArray:()=>Hi,previewGeneratedSectionPolygonConversion:()=>Sn,previewJoinGAAreas:()=>ba,previewPolygonHole:()=>ze,previewRemovePolygonHole:()=>wn,previewRowCubicPath:()=>pn,previewSectionRowFit:()=>yn,reassignColorblindSafeCategoryColors:()=>ri,relabelChartRows:()=>Er,removeChartCategory:()=>yi,removeChartFloor:()=>ar,removeChartObjects:()=>Rr,removeChartZone:()=>lr,removePolygonHole:()=>Br,renameChartFloor:()=>rr,reorderChartCategories:()=>ti,replaceArcFanRows:()=>_i,replaceRowBlock:()=>Di,resetSeatOverrides:()=>Zi,resizeShapes:()=>Sa,resolveCreationCategory:()=>hi,retractConfidenceEvidence:()=>Fa,seatRefId:()=>Ie,sectionInventorySelectionSummary:()=>vn,setConfidenceEvidence:()=>La,setRowBlockSpacing:()=>la,splitRow:()=>ca,straightenAndSpaceRows:()=>da,transformSectionBoundary:()=>qr,transformSectionBoundaryObject:()=>In,ungroupSegmentedRow:()=>Fi,updateBooths:()=>jr,updateCategoryDefinitions:()=>Ln,updateChartFloorBaseHeight:()=>ir,updateChartTheme:()=>xi,updateChartZones:()=>cr,updateGAAreas:()=>kr,updateRowCubicPath:()=>Nr,updateRows:()=>Wi,updateSeatOverrides:()=>Pt,updateSectionExactPath:()=>Xr,updateSectionMetadata:()=>Vr,updateSegmentedRow:()=>Ni,updateShapes:()=>va,updateStageKinds:()=>Ia,updateTables:()=>Mr,updateTextObjects:()=>Lr,updateViewFromSeatFallback:()=>vi});module.exports=Io(Na);var Lt=e=>Math.max(1,e.fontSize*.6+(e.letterSpacing??0));function Co(e,t){let n=e.text.split(/\r?\n/);if(!e.width)return Math.max(1,n.length);let o=Math.max(1,Math.floor(t/Lt(e))),i=0;for(let a of n){if(!a.length){i+=1;continue}let r=0;for(let c of a.split(/\s+/)){let s=c.length;r&&r+1+s<=o?r+=1+s:(i+=Math.max(1,Math.ceil(s/o)),r=s%o)}}return Math.max(1,i)}function Et(e){let t=e.background?.padding??0,n=e.text.split(/\r?\n/),o=Math.max(1,...n.map(c=>c.length))*Lt(e),i=e.width??o+t*2,a=Math.max(1,i-t*2),r=Co(e,a);return{width:i,height:r*e.fontSize*(e.lineHeight??1.2)+t*2,lineCount:r,padding:t}}var Ka=Math.PI/180;function N(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function nt(e,t,n){return{x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n}}function Tt(e,t){let n=1-t,o=n*n*n,i=3*n*n*t,a=3*n*t*t,r=t*t*t;return{x:o*e.start.x+i*e.control1.x+a*e.control2.x+r*e.end.x,y:o*e.start.y+i*e.control1.y+a*e.control2.y+r*e.end.y}}function _e(e,t,n=192){if(!Number.isInteger(t)||t<1)throw new Error("Path point count must be a positive integer");if(t===1)return[Tt(e,.5)];let o=Array.from({length:n+1},(s,l)=>Tt(e,l/n)),i=new Float64Array(o.length);for(let s=1;s<o.length;s+=1){let l=o[s].x-o[s-1].x,d=o[s].y-o[s-1].y;i[s]=i[s-1]+Math.hypot(l,d)}let a=i[i.length-1];if(a<=1e-9)return Array.from({length:t},()=>({...e.start}));let r=[],c=1;for(let s=0;s<t;s+=1){let l=a*s/(t-1);for(;c<i.length-1&&i[c]<l;)c+=1;let d=i[c-1],g=i[c],h=g===d?0:(l-d)/(g-d);r.push({x:o[c-1].x+(o[c].x-o[c-1].x)*h,y:o[c-1].y+(o[c].y-o[c-1].y)*h})}return r}function he(e){if(e.length<3)return 0;let t=0;for(let n=0,o=e.length-1;n<e.length;o=n++)t+=(e[o].x+e[n].x)*(e[o].y-e[n].y);return Math.abs(t)/2}function Po(e,t,n){return Math.max(t,Math.min(n,e))}function Oo(e){return Po(e,0,1)}function Ft(e){let t=Oo(e);return t*t*(3-2*t)}var re=Math.PI*2;function ie(e){return Number.isFinite(e.x)&&Number.isFinite(e.y)}function _o(e,t,n){let o=t-e;if(n){for(;o<0;)o+=re;for(;o>=re;)o-=re}else{for(;o>0;)o-=re;for(;o<=-re;)o+=re}return o}function Ae(e){if(e.version!==1||e.closed!==!0||!ie(e.start)||!Array.isArray(e.segments)||e.segments.length<2||e.segments.length>512)return!1;let t=e.start;for(let n of e.segments){if(!n||!ie(n.end))return!1;if(n.kind==="line"){if(N(t,n.end)<=1e-9)return!1}else if(n.kind==="bezier"){if(!ie(n.control1)||!ie(n.control2)||N(t,n.end)<=1e-9)return!1}else if(n.kind==="arc"){if(!ie(n.center)||!Number.isFinite(n.radius)||n.radius<=1e-6||Math.abs(N(t,n.center)-n.radius)>Math.max(1e-4,n.radius*1e-4)||Math.abs(N(n.end,n.center)-n.radius)>Math.max(1e-4,n.radius*1e-4)||N(t,n.end)<=1e-9)return!1}else return!1;t=n.end}return N(t,e.start)<=1e-4}function Ao(e,t,n){let o=1-n;return{x:o**3*e.x+3*o**2*n*t.control1.x+3*o*n**2*t.control2.x+n**3*t.end.x,y:o**3*e.y+3*o**2*n*t.control1.y+3*o*n**2*t.control2.y+n**3*t.end.y}}function rt(e,t=2){if(!Ae(e))throw new Error("Section outline path is invalid");let n=Math.max(.25,t),o=[{...e.start}],i=e.start;for(let a of e.segments){if(a.kind==="line")o.push({...a.end});else if(a.kind==="arc"){let r=Math.atan2(i.y-a.center.y,i.x-a.center.x),c=Math.atan2(a.end.y-a.center.y,a.end.x-a.center.x),s=_o(r,c,a.clockwise),l=Math.max(2,Math.ceil(Math.abs(s)*a.radius/n));for(let d=1;d<=l;d+=1){let g=r+s*d/l;o.push({x:a.center.x+Math.cos(g)*a.radius,y:a.center.y+Math.sin(g)*a.radius})}}else{let r=N(i,a.control1)+N(a.control1,a.control2)+N(a.control2,a.end),c=Math.max(2,Math.ceil(r/n));for(let s=1;s<=c;s+=1)o.push(Ao(i,a,s/c))}i=a.end}return N(o[o.length-1],o[0])<=1e-4&&o.pop(),o}function Gt(e,t,n){return it(e,i=>({x:i.x+t,y:i.y+n}))}function it(e,t,n=1,o=!1){return{...e,start:t(e.start),segments:e.segments.map(i=>i.kind==="line"?{...i,end:t(i.end)}:i.kind==="arc"?{...i,center:t(i.center),radius:i.radius*Math.abs(n),clockwise:o?!i.clockwise:i.clockwise,end:t(i.end)}:{...i,control1:t(i.control1),control2:t(i.control2),end:t(i.end)})}}var at=45,ot=150,Mo=60;function jo(e){let t=at/100;if(e<=t)return ot;let n=Math.min(1,(e-t)/(1-t));return ot-n*(ot-Mo)}var Nt=.5523;function Dt(e,t){return Math.abs(e.x-t.x)<=1e-6&&Math.abs(e.y-t.y)<=1e-6}function ko(e){let t=[],n=[];for(e.forEach((o,i)=>{ie(o)&&(t.length&&Dt(t[t.length-1],o)||(t.push({x:o.x,y:o.y}),n.push(i)))});t.length>1&&Dt(t[0],t[t.length-1]);)t.pop(),n.pop();return{points:t,sourceIndex:n}}var Ro=.5,Lo=4/3;function Eo(e,t,n){let o=t.x-e.x,i=t.y-e.y,a=Math.hypot(o,i);if(a<=1e-9)return{kind:"line",end:{...t}};let r=-i/a,c=o/a,s=n*Lo;return{kind:"bezier",control1:{x:e.x+o/3+r*s,y:e.y+i/3+c*s},control2:{x:e.x+o*2/3+r*s,y:e.y+i*2/3+c*s},end:{...t}}}function Kt(e,t){let{points:n,sourceIndex:o}=ko(e),i=n.length;if(i<3)return null;let a=Math.min(100,Math.max(0,t.cornerSmoothing??0))/100,r=t.edgeCurvature,c=new Array(i).fill(0);if(r?.length)for(let w=0;w<i;w+=1){let v=r[o[w]];c[w]=Number.isFinite(v)?Math.min(100,Math.max(-100,v))/100:0}let s=c.some(w=>Math.abs(w)>1e-6);if(a<=0&&!s)return null;let l=t.wideAngleThresholdDeg??jo(a),d=[];for(let w=0;w<i;w+=1)d[w]=N(n[w],n[(w+1)%i]);let g=new Array(i).fill(0);for(let w=0;w<i;w+=1){let v=n[(w-1+i)%i],S=n[w],_=n[(w+1)%i],G={x:v.x-S.x,y:v.y-S.y},F={x:_.x-S.x,y:_.y-S.y},U=Math.hypot(G.x,G.y),K=Math.hypot(F.x,F.y);if(U<=1e-9||K<=1e-9)continue;let O=Math.min(1,Math.max(-1,(G.x*F.x+G.y*F.y)/(U*K))),$=Math.acos(O)*180/Math.PI;if($<l)continue;let j=Ft(($-l)/(180-l));g[w]=a*j*.5*Math.min(U,K)}for(let w=0;w<i;w+=1){let v=(w+1)%i,S=g[w]+g[v];if(S>d[w]&&S>1e-9){let _=d[w]/S;g[w]*=_,g[v]*=_}}let h=new Array(i),f=new Array(i);for(let w=0;w<i;w+=1){let v=n[(w-1+i)%i],S=n[w],_=n[(w+1)%i];if(g[w]<=1e-6){h[w]={...S},f[w]={...S};continue}let G=N(S,v)||1,F=N(S,_)||1;h[w]={x:S.x+(v.x-S.x)/G*g[w],y:S.y+(v.y-S.y)/G*g[w]},f[w]={x:S.x+(_.x-S.x)/F*g[w],y:S.y+(_.y-S.y)/F*g[w]}}if(g.every(w=>w<=1e-6)&&!s)return null;let b=[],m={...f[0]},x=m,I=(w,v)=>{if(N(x,w)<=1e-9)return;let S=c[v];Math.abs(S)>1e-6?b.push(Eo(x,w,S*Ro*d[v])):b.push({kind:"line",end:{...w}}),x=w};for(let w=1;w<=i;w+=1){let v=w%i,S=n[v];I(h[v],(w-1)%i),g[v]>1e-6&&N(h[v],f[v])>1e-9&&(b.push({kind:"bezier",control1:nt(h[v],S,Nt),control2:nt(f[v],S,Nt),end:{...f[v]}}),x=f[v])}if(!b.length)return null;let p=b[b.length-1];N(p.end,m)>1e-9&&(p.kind==="line"?p.end={...m}:b.push({kind:"line",end:{...m}}));let y={version:1,closed:!0,start:m,segments:b};return Ae(y)?y:null}var $t="ABCDEFGHIJKLMNOPQRSTUVWXYZ",To="ABCDEFGHJKLMNPQRSTUVWXYZ",Fo="abcdefghijklmnopqrstuvwxyz";function zt(e,t){let n=t.length,o=e+1,i="";for(;o>0;){o-=1;let a=o%n;i=t[a]+i,o=Math.floor(o/n)}return i}function No(e,t){let n=t.startAt-1,o=e+n;if(t.scheme==="numbers")return String(o+1);let i=t.skipAmbiguous?To:$t;return zt(o,i)}function st(e,t=!1){let n=t?Fo:$t;return zt(Math.max(0,Math.floor(e)-1),n)}var Do=[[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 Bt(e){if(!Number.isFinite(e)||e<=0)return String(e);let t=Math.floor(e),n="";for(let[o,i]of Do)for(;t>=o;)n+=i,t-=o;return n}function Ut(e,t){let n=e.length;return e.map((o,i)=>{let a=t.reverse?n-1-i:i;return{...o,label:No(a,t)}})}function Go(e){let t=new Array(e);return Array.from({length:e},(n,o)=>o).sort((n,o)=>Math.abs(2*n-(e-1))-Math.abs(2*o-(e-1))||n-o).forEach((n,o)=>t[n]=o),t}function ct(e,t){let n=e.seatLabelStart??1,o=e.seatNumbering?.direction??"ltr",i=e.seatNumbering?.step??1,a=e.seatNumbering?.scheme??"decimal",r=e.seatNumbering?.prefix??"",c=e.seatNumbering?.endAt,s=e.seatCount;if(a==="updown"||a==="updown-descending"){let f=Math.ceil(s/2),b=a==="updown"?t<f?n+2*t:n-1+2*(s-t):t<f?n+2*(f-1-t):n+1+2*(t-f);return`${r}${b}`}let l=a==="odd"||a==="even"?2:i,d=c!=null&&Number.isFinite(c)?c-(s-1)*l:n,g=o==="center"?Go(s)[t]:o==="rtl"?s-1-t:t,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=Bt(d+g*i);break;case"letters-upper":h=st(d+g*i,!1);break;case"letters-lower":h=st(d+g*i,!0);break;default:h=String(d+g*i);break}return`${r}${h}`}function Ko(e){return{...e.canonical,seatCount:e.totalSeats,label:e.displayLabel,displayLabel:e.displayLabel}}function Ht(e,t,n){return n?.label??`${e.label}-${ct(e,t)}`}function Vt(e,t,n,o){if(o?.displayLabel)return o.displayLabel;if(!n)return`${e.displayLabel??e.label}-${ct(e,t)}`;let i=Ko(n),a=n.displayOffset+t;return`${n.displayLabel}-${ct(i,a)}`}function Xt(e){return e?e.accessibility&&e.accessibility.length?e.wheelchairSpaceType&&!e.accessibility.includes("wheelchair")?["wheelchair",...e.accessibility]:e.accessibility:e.wheelchairSpaceType?["wheelchair"]:e.accessible?["wheelchair"]:[]:[]}var je=Math.PI/180,$o=9,ae=16;function dt(e,t,n,o){let i=n*je,a=Math.cos(i),r=Math.sin(i);return{x:o.x+e*a-t*r,y:o.y+e*r+t*a}}function be(e){let{seatCount:t,seatSpacing:n,curve:o,rotation:i,origin:a}=e,r=[];if(e.path)return _e(e.path,t);if(t<=1)return t===1&&r.push({x:a.x,y:a.y}),r;if(o===0){for(let l=0;l<t;l++)r.push(dt(l*n,0,i,a));return r}let c=o/(t-1)*je,s=n/(2*Math.sin(Math.abs(c)/2));for(let l=0;l<t;l++){let d=l*c,g=s*Math.sin(d),h=-s+s*Math.cos(d);r.push(dt(g,h,i,a))}return r}function zo(e){let t=new Map;if(e.overrides)for(let n of e.overrides)t.set(n.index,n);return t}function Bo(e,t){let n=zo(e);return be(e).map((o,i)=>{let a=n.get(i),r=Xt(a),c=Ht(e,i,a),s={...e.commercial,...a?.commercial};return{index:i,x:o.x+(a?.dx??0),y:o.y+(a?.dy??0),label:c,displayLabel:Vt(e,i,t,a),categoryKey:a?.categoryKey??e.categoryKey,skipped:!!a?.skip,accessible:r.length>0,accessibility:r,wheelchairSpaceType:a?.wheelchairSpaceType,commercial:Object.values(s).some(l=>l!==void 0&&l!==!1&&l!=="")?s:void 0,glyph:a?.glyph,viewUrl:a?.viewFromSeatUrl??e.viewFromSeatUrl,viewMeta:a?.viewFromSeatUrl?a.viewFromSeatMeta:e.viewFromSeatMeta,labelStyle:a?.labelStyle}})}function z(e){let t=[];for(let n of Bo(e))n.skipped||t.push({id:`${e.id}:${n.index}`,label:n.label,displayLabel:n.displayLabel===n.label?void 0:n.displayLabel,x:n.x,y:n.y,rowId:e.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 t}function Uo(e){if(e.seatCountsBySide)return{...e.seatCountsBySide};let t=e.sides&&e.sides.length?e.sides:["top","bottom"],n=["top","bottom","left","right"].filter(a=>t.includes(a)),o={top:0,bottom:0,left:0,right:0};if(!n.length)return o;let i=Math.max(0,Math.round(e.seatCount));for(let a=0;a<i;a++)o[n[a%n.length]]+=1;return o}function Ho(e){let t=[],n=Math.max(0,Math.round(e.seatCount));if(n===0)return t;let o=new Map((e.overrides??[]).map(d=>[d.index,d])),i=(d,g,h,f)=>{let b=o.get(d),m=Xt(b),x=b?.label??`${e.label}-${d+1}`,I=e.displayLabel??e.label;return{index:d,label:x,displayLabel:b?.displayLabel??`${I}-${d+1}`,x:g+(b?.dx??0),y:h+(b?.dy??0),categoryKey:b?.categoryKey??e.categoryKey,skipped:!!b?.skip,accessible:m.length>0,accessibility:m,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(e.shape==="round"){let d=(e.radius??40)+ae,g=e.rotation*je,h=Math.max(0,Math.min(360,e.seatArc??360));if(h>=360||n===1){for(let x=0;x<n;x++){let I=g+x/n*2*Math.PI;t.push(i(x,e.center.x+d*Math.cos(I),e.center.y+d*Math.sin(I)))}return t}let f=h*je,b=(2*Math.PI-f)/2,m=g+b;for(let x=0;x<n;x++){let I=m+x/(n-1)*f;t.push(i(x,e.center.x+d*Math.cos(I),e.center.y+d*Math.sin(I)))}return t}let a=e.width??80,r=e.height??50,c=Uo(e),s=["top","bottom","left","right"],l=0;for(let d of s){let g=c[d];for(let h=0;h<g;h++){let f,b;d==="top"?(f=-a/2+(h+.5)*a/g,b=-r/2-ae):d==="bottom"?(f=-a/2+(h+.5)*a/g,b=r/2+ae):d==="left"?(f=-a/2-ae,b=-r/2+(h+.5)*r/g):(f=a/2+ae,b=-r/2+(h+.5)*r/g);let m=dt(f,b,e.rotation,e.center);t.push(i(l++,m.x,m.y,d))}}return t}function Z(e){return Ho(e).filter(t=>!t.skipped).map(t=>({id:`${e.id}:${t.index}`,label:t.label,...t.displayLabel!==t.label?{displayLabel:t.displayLabel}:{},x:t.x,y:t.y,rowId:e.id,categoryKey:t.categoryKey,...t.accessible?{accessible:!0}:{},...t.accessibility.length?{accessibility:t.accessibility}:{},...t.wheelchairSpaceType?{wheelchairSpaceType:t.wheelchairSpaceType}:{},...t.commercial?{commercial:t.commercial}:{},...t.glyph?{glyph:t.glyph}:{},...t.viewUrl?{viewUrl:t.viewUrl}:{},...t.viewUrl&&t.viewMeta?{viewMeta:t.viewMeta}:{},...t.labelStyle?{labelStyle:t.labelStyle}:{}}))}function Qt(e){return[{id:`${e.id}:0`,label:e.label,...e.displayLabel&&e.displayLabel!==e.label?{displayLabel:e.displayLabel}:{},x:e.center.x,y:e.center.y,rowId:e.id,categoryKey:e.categoryKey,kind:"booth"}]}function Jt(e,t){let n=!1;for(let o=0,i=t.length-1;o<t.length;i=o++){let a=t[o].x,r=t[o].y,c=t[i].x,s=t[i].y;r>e.y!=s>e.y&&e.x<(c-a)*(e.y-r)/(s-r)+a&&(n=!n)}return n}function Vo(e,t){return t.some((n,o)=>{let i=t[(o+1)%t.length],a=(e.y-n.y)*(i.x-n.x)-(e.x-n.x)*(i.y-n.y);if(Math.abs(a)>1e-7)return!1;let r=(e.x-n.x)*(i.x-n.x)+(e.y-n.y)*(i.y-n.y),c=(i.x-n.x)**2+(i.y-n.y)**2;return r>=-1e-7&&r<=c+1e-7})}function D(e,t,n){return Jt(e,t)&&!(n??[]).some(o=>Jt(e,o)||Vo(e,o))}function lt(e){if(!e.length)return{x:0,y:0};let t=0,n=0;for(let o of e)t+=o.x,n+=o.y;return{x:t/e.length,y:n/e.length}}function L(e){switch(e.type){case"row":{let t=z(e);if(!t.length)return{x:e.origin.x,y:e.origin.y};let n=0,o=0;for(let i of t)n+=i.x,o+=i.y;return{x:n/t.length,y:o/t.length}}case"table":case"booth":return{x:e.center.x,y:e.center.y};case"gaArea":return lt(e.points);case"section":return lt(e.outline);case"text":return{x:e.position.x,y:e.position.y};case"shape":return e.points&&e.points.length?lt(e.points):e.x!=null&&e.y!=null&&e.width!=null&&e.height!=null?{x:e.x+e.width/2,y:e.y+e.height/2}:{x:e.x??0,y:e.y??0};case"decorImage":return{x:e.x+e.width/2,y:e.y+e.height/2}}}function qt(e,t){return e.length===t.length&&e.every((n,o)=>n.x===t[o].x&&n.y===t[o].y)}function Jo(e,t){if(e.type!=="gaArea"||!qt(e.points,t.outline))return!1;let n=e.holes??[],o=t.holes??[];return n.length===o.length&&n.every((i,a)=>qt(i,o[a]))}function Yt(e,t){let n=e.filter(r=>r.type==="section"),o="referenceInventorySource"in t?t.referenceInventorySource?.logicalSectionId:void 0,i=L(t);return(o?n.find(r=>(r.logicalSectionId??r.id)===o&&(Jo(t,r)||D(i,r.outline,r.holes))):void 0)??n.find(r=>D(i,r.outline,r.holes))}function E(e){return e.floors&&e.floors.length?e.floors:[{id:"floor-0",name:"Main",objects:e.objects,focalPoint:e.focalPoint,referenceImage:e.referenceImage,backgroundImage:e.backgroundImage}]}function H(e){return e.floors&&e.floors.length?e.floors.flatMap(t=>t.objects):e.objects}var Me=40;function Zt(e,t){let n=t?.freeText==="exclude",o=1/0,i=1/0,a=-1/0,r=-1/0,c=(s,l)=>{s<o&&(o=s),l<i&&(i=l),s>a&&(a=s),l>r&&(r=l)};for(let s of H(e))if(s.type==="row"){let l=new Map((s.overrides??[]).map(d=>[d.index,d]));be(s).forEach((d,g)=>{let h=l.get(g);h?.skip||c(d.x+(h?.dx??0),d.y+(h?.dy??0))})}else if(s.type==="gaArea")for(let l of s.points)c(l.x,l.y);else if(s.type==="section")for(let l of s.outline)c(l.x,l.y);else if(s.type==="decorImage")c(s.x,s.y),c(s.x+s.width,s.y+s.height);else if(s.type==="shape")if(s.points&&s.points.length)for(let l of s.points)c(l.x,l.y);else s.x!=null&&s.y!=null&&s.width!=null&&s.height!=null&&(c(s.x,s.y),c(s.x+s.width,s.y+s.height));else if(s.type==="table"){let l=ae+$o,d=s.shape==="round"?(s.radius??40)+l:Math.max((s.width??80)/2,(s.height??50)/2)+l;c(s.center.x-d,s.center.y-d),c(s.center.x+d,s.center.y+d)}else if(s.type==="booth"){let l=Math.max(s.width,s.height)/2;c(s.center.x-l,s.center.y-l),c(s.center.x+l,s.center.y+l)}else if(s.type==="text"){if(n)continue;let l=Et(s);c(s.position.x,s.position.y),c(s.position.x+l.width,s.position.y+l.height)}for(let s of[e.referenceImage,e.backgroundImage]){if(!s)continue;let{center:l,width:d}=s,g=d*3/4;c(l.x-d/2,l.y-g/2),c(l.x+d/2,l.y+g/2)}if(!isFinite(o)){let s=e.focalPoint??{x:0,y:0};return{x:s.x-200,y:s.y-200,width:400,height:400}}return{x:o-Me,y:i-Me,width:a-o+Me*2,height:r-i+Me*2}}var pe=[{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"}],ts=new Map(pe.map(e=>[e.key,e]));var qo=[{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"}],ns=new Map(qo.map(e=>[e.key,e]));var ut=8,ft=24,Xo=["reference-focal","bar","entrance","exit","restroom","screen","sound","concession","coat","wall","rail","suite","obstruction"],os=new Set(Xo);var u=class extends Error{constructor(n,o,i={}){super(o);this.code=n;this.details=i;this.name="ChartOperationError"}};function C(e,t){let n=E(e),o=t?n.find(i=>i.id===t):n[0];if(!o)throw new u("floor_not_found",`Unknown chart floor: ${t}`,{floorId:t});return{floorId:o.id,objects:o.objects}}function k(e,t){if(!e.categories.some(n=>n.key===t))throw new u("category_not_found",`Unknown chart category: ${t}. Call get_chart to list valid category keys.`,{categoryKey:t})}function M(e,t,n,o){let i=new Set([...o,...e.categories.map(a=>a.key),...e.zones?.map(a=>a.id)??[],...e.floors?.map(a=>a.id)??[],...e.floors?.length?e.floors.flatMap(a=>a.objects.map(r=>r.id)):e.objects.map(a=>a.id)]);for(let a=0;a<100;a++){let r=n(t);if(r&&!i.has(r))return o.add(r),r}throw new u("id_generation_failed",`Unable to allocate a unique ${t} id`)}function Qo(e){let t=e.slice().sort((a,r)=>a.x-r.x||a.y-r.y);if(t.length<3)return t;let n=(a,r,c)=>(r.x-a.x)*(c.y-a.y)-(r.y-a.y)*(c.x-a.x),o=[];for(let a of t){for(;o.length>=2&&n(o[o.length-2],o[o.length-1],a)<=0;)o.pop();o.push(a)}let i=[];for(let a=t.length-1;a>=0;a--){let r=t[a];for(;i.length>=2&&n(i[i.length-2],i[i.length-1],r)<=0;)i.pop();i.push(r)}return o.pop(),i.pop(),o.concat(i)}function Yo(e,t){if(!e.length)return e;let n={x:e.reduce((o,i)=>o+i.x,0)/e.length,y:e.reduce((o,i)=>o+i.y,0)/e.length};return e.map(o=>{let i=o.x-n.x,a=o.y-n.y,r=Math.hypot(i,a)||1;return{x:o.x+i/r*t,y:o.y+a/r*t}})}function W(e){let t=[];for(let o of e)o.type==="row"?t.push(...z(o).map(i=>({x:i.x,y:i.y}))):o.type==="table"?t.push(...Z(o).map(i=>({x:i.x,y:i.y}))):o.type==="gaArea"?t.push(...o.points):o.type==="booth"&&t.push(o.center);if(t.length<3)return null;let n=Yo(Qo(t),22);return n.length>=3?n:null}function ke(e,t){let n=C(e,t),o=E(e).find(i=>i.id===n.floorId);return{...e,objects:n.objects,floors:void 0,focalPoint:o.focalPoint,referenceImage:o.referenceImage,backgroundImage:o.backgroundImage}}var Wt=24,en=80;function gt(e,t){let n=e.normalize("NFKC").trim();if(n.length>Wt)throw new u("invalid_operation",`${t} displayed type must be at most ${Wt} characters`);return n}function Re(e,t){if(e.displayType===void 0)return!1;let n=gt(e.displayType,t);return n?(e.displayType=n,!1):(delete e.displayType,!0)}function se(e,t){if(e.displayLabel===void 0)return!1;let n=e.displayLabel.normalize("NFKC").trim();if(n.length>en)throw new u("invalid_operation",`${t} displayed label must be at most ${en} characters`);return n?(e.displayLabel=n,!1):(delete e.displayLabel,!0)}function T(e,t){let n=e.trim().toLowerCase();if(!/^#[0-9a-f]{6}$/.test(n))throw new u("invalid_operation",`${t} must use a six-digit hex color`);return n}function tn(e,t){if(!Number.isFinite(e)||e<ut||e>ft)throw new u("invalid_operation",`${t} label size must be from ${ut} to ${ft}`)}function ce(e,t){e.size!==void 0&&e.size!==null&&tn(e.size,t),e.color!==void 0&&e.color!==null&&T(e.color,`${t} label color`)}function Le(e,t){if(e?.positionPreset!==void 0&&!["start","end","both","none"].includes(e.positionPreset))throw new u("invalid_operation",`${t} label positionPreset must be one of start, end, both, none`);let n=e?.labelStyle;n&&(n.size!==void 0&&tn(n.size,t),n.color!==void 0&&T(n.color,`${t} label color`))}function Ee(e,t){let n=e?structuredClone(e):{},o=n.labelStyle?{...n.labelStyle}:{};return t.size===null?delete o.size:t.size!==void 0&&(o.size=t.size),t.color===null?delete o.color:t.color!==void 0&&(o.color=T(t.color,"Label color")),o.size===void 0&&o.color===void 0?delete n.labelStyle:n.labelStyle=o,t.visible!==void 0&&(n.visible=t.visible),Object.keys(n).length?n:void 0}function ht(e,t,n){let o=t.normalize("NFKC").trim();if(!o||o.length>80)throw new u("invalid_operation","Zone labels must contain 1 to 80 characters");if((e.zones??[]).some(i=>i.id!==n&&i.label.normalize("NFKC").trim().toLocaleLowerCase("en")===o.toLocaleLowerCase("en")))throw new u("invalid_operation",`Zone label already exists: ${o}`);return o}function bt(e,t){if(!Number.isFinite(e?.x)||!Number.isFinite(e?.y))throw new u("invalid_operation",`${t} must contain finite x and y values`);return{x:e.x,y:e.y}}function J(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)}var X=Math.PI/180,q=Math.PI/180;function ee(e){return e.type==="row"||e.type==="table"?e.seatCount:e.type==="gaArea"?Math.max(0,Math.floor(e.capacity)):e.type==="booth"?1:0}var Zo=2e6,Wo=/^data:image\/(?:png|jpe?g|webp|gif|avif);base64,[a-z0-9+/]+={0,2}$/i,er=/[\s"'<>`\\]/;function nn(e){if(typeof e!="string"||!e||e.length>2e6||e!==e.trim())return!1;if(e.startsWith("data:"))return Wo.test(e);if(er.test(e))return!1;try{let t=new URL(e);return t.protocol==="https:"&&!t.username&&!t.password}catch{return!1}}function Y(e){let t=e.trim();return nn(t)?t:null}function ye(e){if(e.floors?.length){let t=e.floors[0];e.objects=t.objects,e.focalPoint=t.focalPoint,e.referenceImage=t.referenceImage,e.backgroundImage=t.backgroundImage}return e}var tr=0,Te=120,pt=4;function nr(e){if(!Number.isFinite(e)||e<tr||e>Te)throw new u("invalid_operation","Floor base height must be a number from 0 to 120 metres")}function or(e,t){let n=E(e);if(n.length>=5)throw new u("invalid_operation","A chart can contain at most five physical floors");let o=(t.name??String(n.length+1)).normalize("NFKC").trim();if(!o||o.length>80)throw new u("invalid_operation","Floor names must contain 1 to 80 characters");if(n.some(s=>s.name.toLocaleLowerCase("en")===o.toLocaleLowerCase("en")))throw new u("invalid_operation",`Floor name already exists: ${o}`);e.floors?.length||(e.floors=[{id:"floor-0",name:"1",objects:e.objects,baseHeightM:0,focalPoint:e.focalPoint,referenceImage:e.referenceImage,backgroundImage:e.backgroundImage}]);let a=e.floors[e.floors.length-1].baseHeightM??Math.min(Te,(e.floors.length-1)*pt),r=Math.min(Te,a+pt),c=M(e,"floor",t.idFactory,new Set);return e.floors.push({id:c,name:o,baseHeightM:r,objects:[],focalPoint:{...e.focalPoint}}),ye(e),{changed:!0,floorId:c,floorCount:e.floors.length,baseHeightM:r}}function rr(e,t){let n=E(e),o=n.find(r=>r.id===t.floorId);if(!o)throw new u("floor_not_found",`Unknown chart floor: ${t.floorId}`,{floorId:t.floorId});let i=t.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(r=>r.id!==o.id&&r.name.toLocaleLowerCase("en")===i.toLocaleLowerCase("en")))throw new u("invalid_operation",`Floor name already exists: ${i}`);let a=o.name!==i;return a&&(o.name=i),{changed:a,floorId:o.id,floorName:i}}function ir(e,t){if(!e.floors?.length)throw new u("invalid_operation","A single-floor chart has an implicit base height of 0 metres");let n=e.floors.find(i=>i.id===t.floorId);if(!n)throw new u("floor_not_found",`Unknown chart floor: ${t.floorId}`,{floorId:t.floorId});nr(t.baseHeightM);let o=n.baseHeightM!==t.baseHeightM;return o&&(n.baseHeightM=t.baseHeightM,n.physical3dProvenance={...n.physical3dProvenance,baseHeightM:{status:"confirmed",source:"user-review",note:"Physical floor height reviewed through the shared Designer/Copilot operation."}}),{changed:o,floorId:n.id,baseHeightM:t.baseHeightM}}function ar(e,t){if(!e.floors?.length)throw new u("invalid_operation","A single-floor chart cannot remove its only floor");let n=e.floors.findIndex(i=>i.id===t.floorId);if(n<0)throw new u("floor_not_found",`Unknown chart floor: ${t.floorId}`,{floorId:t.floorId});let[o]=e.floors.splice(n,1);if(e.floors.length===1){let[i]=e.floors;e.objects=i.objects,e.focalPoint=i.focalPoint,e.referenceImage=i.referenceImage,e.backgroundImage=i.backgroundImage,e.floors=void 0}else ye(e);return{changed:!0,floorId:o.id,removedObjects:o.objects.length,floorCount:E(e).length}}function sr(e,t){if((e.zones?.length??0)>=100)throw new u("invalid_operation","A chart supports at most 100 zones");let n={id:M(e,"zone",t.idFactory,new Set),label:ht(e,t.label),color:T(t.color,"Zone color"),...t.focalPoint?{focalPoint:bt(t.focalPoint,"Zone focal point")}:{}};return(e.zones??=[]).push(n),{changed:!0,zone:structuredClone(n)}}function cr(e,t){if(!t.updates.length)throw new u("invalid_operation","At least one zone update is required");let n=t.updates.map(s=>s.zoneId);if(new Set(n).size!==n.length)throw new u("invalid_operation","Zone ids must be unique");let o=new Map((e.zones??[]).map(s=>[s.id,s])),i=n.filter(s=>!o.has(s));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(e),r=new Map((a.zones??[]).map(s=>[s.id,s]));for(let s of t.updates){if(!Object.keys(s.patch).length)throw new u("invalid_operation",`Zone ${s.zoneId} has no changes`);let d=r.get(s.zoneId);s.patch.label!==void 0&&(d.label=ht(a,s.patch.label,d.id)),s.patch.color!==void 0&&(d.color=T(s.patch.color,"Zone color")),s.patch.focalPoint!==void 0&&(d.focalPoint=bt(s.patch.focalPoint,"Zone focal point"))}let c=JSON.stringify(a.zones??[])!==JSON.stringify(e.zones??[]);return c&&(e.zones=a.zones),{changed:c,zoneIds:n,zones:n.map(s=>structuredClone(r.get(s)))}}function lr(e,t){let n=(e.zones??[]).findIndex(a=>a.id===t.zoneId);if(n<0)throw new u("object_not_found",`Unknown chart zone: ${t.zoneId}`,{zoneId:t.zoneId});let o=E(e).flatMap(a=>a.objects).filter(a=>a.type==="section"&&a.zone===t.zoneId);if(o.length&&t.clearSectionAssignments!==!0)throw new u("invalid_operation",`Zone ${t.zoneId} is assigned to ${o.length} section(s)`,{zoneId:t.zoneId,sectionIds:o.map(a=>a.id),requiresClearSectionAssignments:!0});let i=o.map(a=>a.id);for(let a of o)delete a.zone;return e.zones.splice(n,1),e.zones.length||delete e.zones,ye(e),{changed:!0,zoneId:t.zoneId,clearedSectionIds:i,zoneCount:e.zones?.length??0}}var Fe=[{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 Ne(e){let t=new Map,n=Math.max(0,Math.floor(e.seatCount)),o=new Map((e.overrides??[]).filter(a=>Number.isInteger(a.index)&&a.index>=0&&a.index<e.seatCount).map(a=>[a.index,a])),i=(a,r=1)=>{a&&r>0&&t.set(a,(t.get(a)??0)+r)};i(e.categoryKey,n-o.size);for(let a of o.values())a.skip||i(a.categoryKey??e.categoryKey);return t}var on="__sl_ga__",te=1e5,le=1e5;function dr(e,t){return`${on}${encodeURIComponent(e)}__${t+1}`}function yt(e){let t=e.inventorySegments;if(t===void 0)return!0;if(!Array.isArray(t)||t.length<1||t.length>256)return!1;let n=0,o=new Map;for(let i of t){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>te||(n+=i.count,n>te))return!1;let a=o.get(i.sourceAreaId)??[],r=i.startIndex+i.count;if(a.some(c=>i.startIndex<c.end&&r>c.start))return!1;a.push({start:i.startIndex,end:r}),o.set(i.sourceAreaId,a)}return n===e.capacity}function De(e){let t=Math.min(te,Math.max(0,Math.floor(e.capacity)));return e.inventorySegments===void 0?t?[{sourceAreaId:e.id,startIndex:0,count:t}]:[]:yt(e)?e.inventorySegments.map(n=>({...n})):[]}function ne(e){return De(e).flatMap(t=>Array.from({length:t.count},(n,o)=>dr(t.sourceAreaId,t.startIndex+o)))}function mt(e,t){if(e.inventorySegments===void 0||t===e.capacity)return e.inventorySegments;if(t<e.capacity)return;let n=De(e);if(!n.length)return;let o=t-e.capacity;if(!o)return n;let a=n.filter(c=>c.sourceAreaId===e.id).reduce((c,s)=>Math.max(c,s.startIndex+s.count),0),r=n[n.length-1];if(r?.sourceAreaId===e.id&&r.startIndex+r.count===a)r.count+=o;else{if(n.length>=256)return;n.push({sourceAreaId:e.id,startIndex:a,count:o})}return n}function rn(e){return e.startsWith(on)}var ur="__ungrouped__";function fr(e){return e.type==="row"?z(e).map(t=>t.label):e.type==="table"?Z(e).map(t=>t.label):e.type==="booth"?Qt(e).map(t=>t.label):e.type==="gaArea"?ne(e):[]}function gr(e){return e.type==="row"||e.type==="table"||e.type==="booth"||e.type==="gaArea"}function me(e){let t=H(e),n=t.filter(r=>r.type==="section"),o=new Map;for(let r of n){let c=r.logicalSectionId??r.id;o.get(c)||o.set(c,{id:c,label:r.displayLabel||r.label||"Section",zone:r.zone,seatCount:0,objectIds:[],seatLabels:[]})}let i={id:ur,label:"Other seats",seatCount:0,objectIds:[],seatLabels:[]},a=new Map;for(let r of t){if(!gr(r))continue;let c=fr(r);if(c.length===0)continue;let s=Yt(t,r),l=s?o.get(s.logicalSectionId??s.id):i;l.seatCount+=c.length,l.objectIds.push(r.id),l.seatLabels.push(...c),a.set(r.id,l.id)}return{sections:[...o.values()],ungrouped:i.objectIds.length?i:null,objectToSection:a}}var oe={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 we(e,t,n,o,i,a,r=0){return{type:"row",id:e,label:t,origin:{x:-(o-1)*i/2,y:n},rotation:0,curve:r,seatCount:o,seatSpacing:i,categoryKey:a}}function hr(e,t,n,o,i,a){return{type:"table",id:e,label:t,center:n,shape:"round",seatCount:o,rotation:0,radius:i,categoryKey:a}}function an(e,t,n,o,i,a){let r=n/2,c=o/2;return{type:"gaArea",id:e,label:t,points:[{x:-r,y:-c},{x:r,y:-c},{x:r,y:c},{x:-r,y:c}],capacity:i,categoryKey:a}}function br(e,t,n,o,i){let a=n*2,r=[];for(let c=0;c<a;c++){let s=c%2===0,l=s?["wheelchair"]:["companion"];r.push(s?{index:c,accessibility:l,wheelchairSpaceType:"no-seat"}:{index:c,accessibility:l})}return{type:"row",id:e,label:t,origin:{x:-(a-1)*o/2,y:0},rotation:0,curve:0,seatCount:a,seatSpacing:o,categoryKey:i,overrides:r}}var sn=[{key:"balcony",label:"Balcony",icon:"\u2312",blurb:"Insert four curved rows inside a section.",categories:[oe.balcony],sectionLabel:"Balcony",build:()=>[we("blk-b0","A",-45,18,24,"balcony",18),we("blk-b1","B",-15,20,24,"balcony",18),we("blk-b2","C",15,22,24,"balcony",18),we("blk-b3","D",45,24,24,"balcony",18)]},{key:"rows",label:"Row block",icon:"\u2261",blurb:"Insert six straight rows inside a section.",categories:[oe.standard],sectionLabel:"Section",build:()=>Array.from({length:6},(e,t)=>we(`blk-r${t}`,"ABCDEF"[t],-80+t*32,12,26,"standard"))},{key:"ga-pen",label:"GA pen",icon:"\u25A8",blurb:"Insert a standing area for 250 people.",categories:[oe.standard],build:()=>[an("blk-ga","Standing",320,180,250,"standard")]},{key:"tables",label:"Tables",icon:"\u283F",blurb:"Insert six round tables with eight bookable seats each.",categories:[oe.premium],build:()=>Array.from({length:6},(e,t)=>hr(`blk-t${t}`,`T${t+1}`,{x:-150+t%3*150,y:t<3?-70:70},8,34,"premium"))},{key:"boxes",label:"Boxes",icon:"\u25A3",blurb:"Insert two private boxes with four bookable seats each.",categories:[oe.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:[oe.standard],build:()=>[an("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:[oe.standard],build:()=>[br("blk-wc","A",4,40,"standard")]}];function B(e){let t="",n=e;do t=String.fromCharCode(65+n%26)+t,n=Math.floor(n/26)-1;while(n>=0);return t}function cn(e){if(!/^[A-Z]+$/.test(e))return null;let t=0;for(let n of e)t=t*26+(n.charCodeAt(0)-64);return t-1}var ln="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",dn=[{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:ln},{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:ln},{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 pr=new Map(dn.map(e=>[e.key,e]));function un(e){return typeof e=="string"&&pr.has(e)}var _s=dn.map(e=>e.key);function wt(e){let t=(e%360+360)%360,n=t>=180?t-360:t;return Object.is(n,-0)||Math.abs(n)<1e-9?0:n}function fn(e,t,n){let o=i=>({x:i.x+t,y:i.y+n});switch(e.type){case"row":e.origin=o(e.origin),e.path&&(e.path={start:o(e.path.start),control1:o(e.path.control1),control2:o(e.path.control2),end:o(e.path.end)});break;case"table":case"booth":e.center=o(e.center);break;case"text":e.position=o(e.position);break;case"gaArea":e.points=e.points.map(o),e.holes&&(e.holes=e.holes.map(i=>i.map(o)));break;case"section":e.outline=e.outline.map(o),e.sourceOutline&&(e.sourceOutline=e.sourceOutline.map(o)),e.outlinePath&&(e.outlinePath=Gt(e.outlinePath,t,n)),e.holes&&(e.holes=e.holes.map(i=>i.map(o)));break;case"shape":e.points&&(e.points=e.points.map(o)),e.x!=null&&(e.x+=t),e.y!=null&&(e.y+=n);break;case"decorImage":e.x+=t,e.y+=n;break}}function yr(e,t){return Math.abs(e.x-t.x)<=1e-7&&Math.abs(e.y-t.y)<=1e-7}function xe(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)}function Ge(e,t,n){let o=xe(t,n,e);return Math.abs(o)>1e-7?!1:e.x>=Math.min(t.x,n.x)-1e-7&&e.x<=Math.max(t.x,n.x)+1e-7&&e.y>=Math.min(t.y,n.y)-1e-7&&e.y<=Math.max(t.y,n.y)+1e-7}function mr(e,t,n,o){let i=xe(e,t,n),a=xe(e,t,o),r=xe(n,o,e),c=xe(n,o,t);return(i>1e-7&&a<-1e-7||i<-1e-7&&a>1e-7)&&(r>1e-7&&c<-1e-7||r<-1e-7&&c>1e-7)?!0:Math.abs(i)<=1e-7&&Ge(n,e,t)||Math.abs(a)<=1e-7&&Ge(o,e,t)||Math.abs(r)<=1e-7&&Ge(e,n,o)||Math.abs(c)<=1e-7&&Ge(t,n,o)}function wr(e){return e.reduce((t,n,o)=>{let i=e[(o+1)%e.length];return t+n.x*i.y-i.x*n.y},0)}function xr(e){for(let t=0;t<e.length;t+=1){let n=(t+1)%e.length;for(let o=t+1;o<e.length;o+=1){let i=(o+1)%e.length;if(!(t===o||n===o||i===t)&&mr(e[t],e[n],e[o],e[i]))return!0}}return!1}function gn(e){return e.length<3?{ok:!1,code:"too_few_vertices",message:"Add at least three vertices to create a polygon."}:e.length>256?{ok:!1,code:"too_many_vertices",message:"A polygon can contain at most 256 vertices."}:e.some(t=>!Number.isFinite(t.x)||!Number.isFinite(t.y)||Math.abs(t.x)>1e7||Math.abs(t.y)>1e7)?{ok:!1,code:"invalid_coordinate",message:"Every polygon vertex must use a finite coordinate inside the safe chart range."}:e.some((t,n)=>yr(t,e[(n+1)%e.length]))?{ok:!1,code:"duplicate_vertex",message:"Move or remove duplicate neighbouring vertices."}:Math.abs(wr(e))<2?{ok:!1,code:"degenerate_polygon",message:"The polygon needs a visible enclosed area."}:xr(e)?{ok:!1,code:"self_intersection",message:"Polygon edges cannot cross or touch each other."}:{ok:!0}}function Mr(e,t){let n=C(e,t.floorId),o=[...new Set(t.tableIds)];if(!o.length)throw new u("invalid_operation","At least one table id is required");let i=o.map(p=>n.objects.find(y=>y.type==="table"&&y.id===p)),a=o.filter((p,y)=>!i[y]);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 r=structuredClone(t.patch);if(!Object.keys(r).length)throw new u("invalid_operation","At least one table change is required");if(r.label!==void 0){if(r.label=r.label.normalize("NFKC").trim(),o.length!==1)throw new u("invalid_operation","label can be changed only for one table at a time");if(!r.label||r.label.length>80)throw new u("invalid_operation","Table labels must contain 1 to 80 characters")}r.categoryKey!==void 0&&k(e,r.categoryKey);let c=r.seatCount!==void 0,s=r.seatCountsBySide!==void 0;if(s){if(r.sides!==void 0)throw new u("invalid_operation","Use seatCountsBySide for exact rectangular counts; do not also supply legacy sides");if(r.shape==="round")throw new u("invalid_operation","seatCountsBySide can be used only with rectangular tables");let p=["top","bottom","left","right"],y=Object.keys(r.seatCountsBySide);if(y.length!==p.length||y.some(v=>!p.includes(v)))throw new u("invalid_operation","seatCountsBySide must contain exactly top, bottom, left, and right");for(let v of p){let S=r.seatCountsBySide[v];if(!Number.isInteger(S)||S<0||S>40)throw new u("invalid_operation",`seatCountsBySide.${v} must be a whole number from 0 to 40`)}let w=p.reduce((v,S)=>v+r.seatCountsBySide[S],0);if(w<1||w>40)throw new u("invalid_operation","Rectangular table side counts must total from 1 to 40 chairs");if(c&&r.seatCount!==w)throw new u("invalid_operation",`seatCount must equal the ${w}-chair seatCountsBySide total`);r.seatCount=w,r.sides=p.filter(v=>r.seatCountsBySide[v]>0)}if(r.seatCount!==void 0&&(!Number.isInteger(r.seatCount)||r.seatCount<1||r.seatCount>40))throw new u("invalid_operation","seatCount must be an integer from 1 to 40");if(r.shape!==void 0&&r.shape!=="round"&&r.shape!=="rect")throw new u("invalid_operation","Table shape must be round or rect");if(r.bookAsWhole===!0&&r.variableOccupancy===!0)throw new u("invalid_operation","A table cannot use whole-table and variable-occupancy selling at the same time");if(r.variableOccupancy===!1&&(r.minOccupancy!==void 0||r.maxOccupancy!==void 0))throw new u("invalid_operation","Guest bounds can be supplied only with variable-occupancy selling");let l=(p,y,w,v)=>{if(y!==void 0&&(!Number.isFinite(y)||y<w||y>v))throw new u("invalid_operation",`${String(p)} must be from ${w} to ${v}`)};if(l("rotation",r.rotation,0,360),l("radius",r.radius,24,160),l("seatArc",r.seatArc,120,360),l("width",r.width,40,320),l("height",r.height,30,240),r.minOccupancy!==void 0&&(!Number.isInteger(r.minOccupancy)||r.minOccupancy<1||r.minOccupancy>40))throw new u("invalid_operation","minOccupancy must be a whole number from 1 to 40");if(r.maxOccupancy!==void 0&&(!Number.isInteger(r.maxOccupancy)||r.maxOccupancy<1||r.maxOccupancy>40))throw new u("invalid_operation","maxOccupancy must be a whole number from 1 to 40");if(r.sides!==void 0){let p=new Set(["top","bottom","left","right"]);if(!r.sides.length||r.sides.length>4||new Set(r.sides).size!==r.sides.length||r.sides.some(y=>!p.has(y)))throw new u("invalid_operation","Table sides must contain one to four unique perimeter sides")}let d=se(r,"Table"),g=Re(r,"Table"),h=i.map(p=>{if(p.seatCountsBySide&&!s&&(c||t.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 y=structuredClone(p);if(Object.assign(y,r),y.shape==="round"&&delete y.seatCountsBySide,y.overrides&&r.seatCount!==void 0&&(y.overrides=y.overrides.filter(w=>w.index<y.seatCount),y.overrides.length||delete y.overrides),r.bookAsWhole===!1&&delete y.bookAsWhole,r.variableOccupancy===!1&&(delete y.variableOccupancy,delete y.minOccupancy,delete y.maxOccupancy),y.bookAsWhole||delete y.bookAsWhole,y.variableOccupancy||delete y.variableOccupancy,y.bookAsWhole&&y.variableOccupancy)throw new u("invalid_operation",`Table "${y.label}" cannot use whole-table and variable-occupancy selling at the same time`,{tableId:y.id});if((y.bookAsWhole||y.variableOccupancy)&&y.overrides?.length)throw new u("invalid_operation",`Table "${y.label}" has individual-chair overrides; reset them before choosing grouped table selling`,{tableId:y.id,overriddenChairIndices:y.overrides.map(w=>w.index)});if(y.bookAsWhole)delete y.minOccupancy,delete y.maxOccupancy;else if(y.variableOccupancy){if(!Number.isInteger(y.minOccupancy)||!Number.isInteger(y.maxOccupancy)||y.minOccupancy<1||y.maxOccupancy<y.minOccupancy||y.maxOccupancy>y.seatCount)throw new u("invalid_operation",`Table "${y.label}" needs whole-number minimum and maximum guests from 1 to its ${y.seatCount}-chair capacity`,{tableId:y.id,seatCount:y.seatCount})}else{if(r.minOccupancy!==void 0||r.maxOccupancy!==void 0)throw new u("invalid_operation","Guest bounds can be changed only on a variable-occupancy table",{tableId:y.id});delete y.minOccupancy,delete y.maxOccupancy}if(g&&delete y.displayType,d&&delete y.displayLabel,y.shape==="rect"){if(y.width??=80,y.height??=50,y.seatCountsBySide){let w=["top","bottom","left","right"],v=w.reduce((S,_)=>S+y.seatCountsBySide[_],0);if(v!==y.seatCount)throw new u("invalid_operation",`Table "${y.label}" side counts total ${v}, but seatCount is ${y.seatCount}`,{tableId:y.id,seatCount:y.seatCount,seatCountsBySide:y.seatCountsBySide});y.sides=w.filter(S=>y.seatCountsBySide[S]>0)}}else y.radius??=40;if((y.bookAsWhole||y.variableOccupancy)&&rn(y.label))throw new u("invalid_operation",`Grouped table label "${y.label}" uses SeatLayer's reserved GA namespace`,{tableId:y.id});return y}),f=new Map(h.map(p=>[p.id,p])),b=new Set(o),m=new Map;for(let p of E(e))for(let y of p.objects){let w=y.type==="table"?f.get(y.id)??y:y,v=[];w.type==="row"?v=z(w).map(S=>S.label):w.type==="table"?v=w.bookAsWhole||w.variableOccupancy?[w.label]:Z(w).map(S=>S.label):w.type==="booth"?v=[w.label]:w.type==="gaArea"&&(v=ne(w));for(let S of v){let _=m.get(S);if(_&&(b.has(_)||b.has(w.id)))throw new u("invalid_operation",`Inventory label "${S}" is already in use; grouped table labels must be unique`,{tableIds:o,inventoryLabel:S,conflictingObjectIds:[_,w.id]});m.set(S,_??w.id)}}let x=!1,I=["bookAsWhole","variableOccupancy","minOccupancy","maxOccupancy","displayLabel","displayType","seatCountsBySide","overrides"];for(let[p,y]of i.entries()){let w=h[p],v=JSON.stringify(y);for(let S of I)S in w||delete y[S];Object.assign(y,w),JSON.stringify(y)!==v&&(x=!0)}return{floorId:n.floorId,changed:x,tableIds:o}}function jr(e,t){let n=C(e,t.floorId),o=[...new Set(t.boothIds)];if(!o.length)throw new u("invalid_operation","At least one booth id is required");let i=o.map(f=>n.objects.find(b=>b.type==="booth"&&b.id===f)),a=o.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 r=structuredClone(t.patch);if(!Object.keys(r).length)throw new u("invalid_operation","At least one booth change is required");if(r.label!==void 0){if(r.label=r.label.normalize("NFKC").trim(),o.length!==1)throw new u("invalid_operation","label can be changed only for one booth at a time");if(!r.label||r.label.length>80)throw new u("invalid_operation","Booth labels must contain 1 to 80 characters")}r.categoryKey!==void 0&&k(e,r.categoryKey);let c=(f,b,m,x)=>{if(b!==void 0&&(!Number.isFinite(b)||b<m||b>x))throw new u("invalid_operation",`${f} must be from ${m} to ${x}`)};c("width",r.width,30,400),c("height",r.height,30,400),c("rotation",r.rotation,0,360);let s=r.points===null;if(r.points!=null){if(o.length!==1)throw new u("invalid_operation","points can be changed only for one booth at a time");let f=gn(r.points);if(!f.ok)throw new u("invalid_operation",f.message??"The booth outline is not a valid simple polygon")}let l=r.points!=null?r.points.map(f=>({x:f.x,y:f.y})):void 0;delete r.points;let d=se(r,"Booth"),g=Re(r,"Booth"),h=!1;for(let f of i){let b=JSON.stringify(f);Object.assign(f,r),d&&delete f.displayLabel,g&&delete f.displayType,s?delete f.points:l&&(f.points=l),JSON.stringify(f)!==b&&(h=!0)}return{floorId:n.floorId,changed:h,boothIds:o}}function kr(e,t){let n=C(e,t.floorId),o=[...new Set(t.gaAreaIds)];if(!o.length)throw new u("invalid_operation","At least one GA area id is required");let i=o.map(d=>n.objects.find(g=>g.type==="gaArea"&&g.id===d)),a=o.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 r=structuredClone(t.patch);if(!Object.keys(r).length)throw new u("invalid_operation","At least one GA area change is required");if(r.label!==void 0){if(r.label=r.label.normalize("NFKC").trim(),o.length!==1)throw new u("invalid_operation","label can be changed only for one GA area at a time");if(!r.label||r.label.length>80)throw new u("invalid_operation","GA area labels must contain 1 to 80 characters")}if(r.categoryKey!==void 0&&k(e,r.categoryKey),r.capacity!==void 0&&(!Number.isInteger(r.capacity)||r.capacity<1||r.capacity>1e5))throw new u("invalid_operation","capacity must be an integer from 1 to 100000");if(r.cornerRadius!==void 0&&(!Number.isFinite(r.cornerRadius)||r.cornerRadius<0||r.cornerRadius>2e3))throw new u("invalid_operation","cornerRadius must be from 0 to 2000");let c=se(r,"GA area"),s=Re(r,"GA area");if(r.capacity!==void 0)for(let d of i){if(d.inventorySegments!==void 0&&r.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:r.capacity});if(d.inventorySegments!==void 0&&r.capacity>d.capacity&&mt(d,r.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=r.capacity===void 0?d.inventorySegments:mt(d,r.capacity);Object.assign(d,r),h!==void 0&&(d.inventorySegments=h),c&&delete d.displayLabel,s&&delete d.displayType,JSON.stringify(d)!==g&&(l=!0)}return{floorId:n.floorId,changed:l,gaAreaIds:o}}function Ke(e,t){if(t.length<3)return 0;let n=i=>D(i,t,void 0),o=0;for(let i of e)n(L(i))&&(i.type==="row"?o+=z(i).length:i.type==="table"?o+=Z(i).length:(i.type==="gaArea"||i.type==="booth")&&(o+=ee(i)));return o}function Rr(e,t){let n=C(e,t.floorId);if(!t.objectIds.length)throw new u("invalid_operation","At least one chart object id is required");if(new Set(t.objectIds).size!==t.objectIds.length)throw new u("invalid_operation","Chart object ids must be unique");let o=t.objectIds.map(c=>n.objects.find(s=>s.id===c)),i=t.objectIds.filter((c,s)=>!o[s]);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=o,r=new Set(t.objectIds);for(let c=n.objects.length-1;c>=0;c--)r.has(n.objects[c].id)&&n.objects.splice(c,1);return{floorId:n.floorId,changed:!0,removedObjects:a.map(c=>({id:c.id,type:c.type})),removedInventory:a.reduce((c,s)=>c+ee(s),0),remainingObjectCount:n.objects.length}}function Lr(e,t){let n=C(e,t.floorId),o=[...new Set(t.textIds)];if(!o.length)throw new u("invalid_operation","At least one text id is required");let i=o.map(l=>n.objects.find(d=>d.type==="text"&&d.id===l)),a=o.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 r=structuredClone(t.patch);if(!Object.keys(r).length)throw new u("invalid_operation","At least one text change is required");if(r.text!==void 0){if(r.text=r.text.normalize("NFKC").trim(),o.length!==1)throw new u("invalid_operation","content can be changed only for one text object at a time");if(!r.text||r.text.length>240)throw new u("invalid_operation","Text content must contain 1 to 240 characters")}if(r.fontSize!==void 0&&(!Number.isFinite(r.fontSize)||r.fontSize<8||r.fontSize>72))throw new u("invalid_operation","Text fontSize must be from 8 to 72");if(r.fontFamily!==void 0&&r.fontFamily!==null&&(r.fontFamily=r.fontFamily.normalize("NFKC").trim(),!r.fontFamily||r.fontFamily.length>120))throw new u("invalid_operation","Text fontFamily must contain 1 to 120 characters");if(r.rotation!==void 0&&(!Number.isFinite(r.rotation)||r.rotation<0||r.rotation>360))throw new u("invalid_operation","Text rotation must be from 0 to 360");if(r.color!==void 0&&r.color!==null&&(r.color=T(r.color,"Text color")),r.bold!==void 0&&typeof r.bold!="boolean")throw new u("invalid_operation","Text bold must be a boolean");if(r.italic!==void 0&&typeof r.italic!="boolean")throw new u("invalid_operation","Text italic must be a boolean");if(r.width!==void 0&&r.width!==null&&(!Number.isFinite(r.width)||r.width<40||r.width>1200))throw new u("invalid_operation",`Text width must be from ${40} to ${1200}`);if(r.align!==void 0&&!["left","center","right"].includes(r.align))throw new u("invalid_operation","Text align must be left, center, or right");if(r.lineHeight!==void 0&&(!Number.isFinite(r.lineHeight)||r.lineHeight<.8||r.lineHeight>3))throw new u("invalid_operation",`Text lineHeight must be from ${.8} to ${3}`);if(r.letterSpacing!==void 0&&(!Number.isFinite(r.letterSpacing)||r.letterSpacing<-2||r.letterSpacing>20))throw new u("invalid_operation",`Text letterSpacing must be from ${-2} to ${20}`);if(r.underline!==void 0&&typeof r.underline!="boolean")throw new u("invalid_operation","Text underline must be a boolean");if(r.opacity!==void 0&&(!Number.isFinite(r.opacity)||r.opacity<.1||r.opacity>1))throw new u("invalid_operation",`Text opacity must be from ${.1} to 1`);if(r.background!==void 0&&r.background!==null){r.background.color=T(r.background.color,"Text background color");let{padding:l=6,cornerRadius:d=4,opacity:g=.9}=r.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(r,l))&&i.some(l=>l.semanticKind==="icon"))throw new u("invalid_operation","Text layout fields cannot be applied to venue icons");if(r.iconKey!==void 0){if(!un(r.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 s=!1;for(let l of i){let d=JSON.stringify(l);r.iconKey!==void 0&&(l.iconKey=r.iconKey),r.text!==void 0&&(l.text=r.text),r.fontSize!==void 0&&(l.fontSize=r.fontSize),r.fontFamily===null?delete l.fontFamily:r.fontFamily!==void 0&&(l.fontFamily=r.fontFamily),r.rotation!==void 0&&(l.rotation=r.rotation),r.color===null?delete l.color:r.color!==void 0&&(l.color=r.color),r.bold!==void 0&&(r.bold?l.bold=!0:delete l.bold),r.italic!==void 0&&(r.italic?l.italic=!0:delete l.italic),r.width===null?delete l.width:r.width!==void 0&&(l.width=r.width),r.align!==void 0&&(r.align==="left"?delete l.align:l.align=r.align),r.lineHeight!==void 0&&(r.lineHeight===1.2?delete l.lineHeight:l.lineHeight=r.lineHeight),r.letterSpacing!==void 0&&(r.letterSpacing===0?delete l.letterSpacing:l.letterSpacing=r.letterSpacing),r.underline!==void 0&&(r.underline?l.underline=!0:delete l.underline),r.opacity!==void 0&&(r.opacity===1?delete l.opacity:l.opacity=r.opacity),r.background===null?delete l.background:r.background!==void 0&&(l.background=r.background),JSON.stringify(l)!==d&&(s=!0)}return{floorId:n.floorId,changed:s,textIds:o}}function Er(e,t){let n=C(e,t.floorId),o=[...new Set(t.rowIds)],i=o.map(l=>n.objects.find(d=>d.type==="row"&&d.id===l)),a=o.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 r=i.slice().sort((l,d)=>l.origin.y-d.origin.y||l.origin.x-d.origin.x),c=Ut(r.map(l=>({label:l.label})),t.options),s=!1;return r.forEach((l,d)=>{l.label!==c[d].label&&(s=!0),l.label=c[d].label}),{floorId:n.floorId,changed:s,rows:r.map(l=>({id:l.id,label:l.label}))}}function Tr(e,t){let n=sn.find(l=>l.key===t.blockKey);if(!n)throw new u("invalid_operation",`Unknown seating block: ${t.blockKey}`,{blockKey:t.blockKey});let o=C(e,t.floorId),i=new Set,a=n.build().map(l=>structuredClone(l));for(let l of a)l.id=M(e,l.type,t.idFactory,i),fn(l,t.center.x,t.center.y);for(let l of n.categories)e.categories.some(d=>d.key===l.key)||e.categories.push({...l});let r=a.filter(l=>l.type==="row");if(r.length){let l=0;for(let d of o.objects){if(d.type!=="row")continue;let g=cn(d.label);g!=null&&(l=Math.max(l,g+1))}for(let d of r)d.label=B(l++)}let c=new Set(o.objects.flatMap(l=>"label"in l&&l.label?[l.label]:[]));for(let l of a){if((l.type==="table"||l.type==="booth")&&c.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(c.has(`${g}${h}`));l.label=`${g}${h}`}"label"in l&&l.label&&c.add(l.label)}o.objects.push(...a);let s=null;if(n.sectionLabel&&t.wrapInSection!==!1){let l=W(a);if(l){let d={type:"section",id:M(e,"sec",t.idFactory,i),label:n.sectionLabel,outline:l};o.objects.push(d),s=d.id}}return{floorId:o.floorId,blockKey:n.key,createdIds:[...a.map(l=>l.id),...s?[s]:[]],sectionId:s}}function Fr(e){let t=structuredClone(e);if([t.start,t.control1,t.control2,t.end].some(a=>!Number.isFinite(a.x)||!Number.isFinite(a.y)))throw new u("invalid_operation","Exact row path points must be finite");let o=_e(t,97),i=o.slice(1).reduce((a,r,c)=>a+Math.hypot(r.x-o[c].x,r.y-o[c].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:t,length:i}}function pn(e,t){let n=C(e,t.floorId),o=n.objects.find(d=>d.type==="row"&&d.id===t.rowId);if(!o)throw new u("object_not_found",`Unknown row id: ${t.rowId}`,{rowId:t.rowId});let i=Fr(t.path),a=z(o),r=structuredClone(o);r.path=i.path,r.origin={...i.path.start};let c=z(r),s=a.map((d,g)=>Math.hypot(d.x-c[g].x,d.y-c[g].y)),l=JSON.stringify(o.path)!==JSON.stringify(i.path)||o.origin.x!==i.path.start.x||o.origin.y!==i.path.start.y;return{floorId:n.floorId,rowId:o.id,seatCount:o.seatCount,pathLength:i.length,averageSeatMovement:s.length?s.reduce((d,g)=>d+g,0)/s.length:0,maxSeatMovement:s.length?Math.max(...s):0,convertingFromParametric:!o.path,changed:l,preservesStableId:!0,preservesSeatMetadata:!0,preservesInventoryUnits:o.seatCount}}function Nr(e,t){let n=pn(e,t);if(!n.changed)return n;let i=C(e,n.floorId).objects.find(a=>a.type==="row"&&a.id===n.rowId);return i.path=structuredClone(t.path),i.origin={...t.path.start},delete i.arcFanGeneration,delete i.rowBlockGeneration,n}function Dr(e,t){let n=e.map((o,i)=>[...o,t[i]]);for(let o=0;o<3;o++){let i=o;for(let r=o+1;r<3;r++)Math.abs(n[r][o])>Math.abs(n[i][o])&&(i=r);if(Math.abs(n[i][o])<1e-9)return null;[n[o],n[i]]=[n[i],n[o]];let a=n[o][o];for(let r=o;r<4;r++)n[o][r]/=a;for(let r=0;r<3;r++){if(r===o)continue;let c=n[r][o];for(let s=o;s<4;s++)n[r][s]-=c*n[o][s]}}return[n[0][3],n[1][3],n[2][3]]}function Gr(e){if(e.length<3)return null;let t=[[0,0,0],[0,0,0],[0,0,0]],n=[0,0,0];for(let i of e){if(!Number.isFinite(i.x)||!Number.isFinite(i.y))return null;let a=[2*i.x,2*i.y,1],r=i.x**2+i.y**2;for(let c=0;c<3;c++){n[c]+=a[c]*r;for(let s=0;s<3;s++)t[c][s]+=a[c]*a[s]}}let o=Dr(t,n);return o?{x:o[0],y:o[1]}:null}function hn(e){let t=((e+180)%360+360)%360-180;return t===-180&&(t=180),t}function yn(e,t){let n=C(e,t.floorId),o=n.objects.find(f=>f.type==="section"&&f.id===t.sectionId);if(!o)throw new u("object_not_found",`Unknown section id: ${t.sectionId}`,{sectionId:t.sectionId});let i=t.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=E(e).find(f=>f.id===n.floorId),r=t.mode==="outline"?Gr(o.outline):t.focalPoint??a.focalPoint??e.focalPoint;if(!r||!Number.isFinite(r.x)||!Number.isFinite(r.y))throw new u("invalid_operation",`Section ${t.mode} fit has no finite center`);let c=n.objects.filter(f=>f.type==="row"&&D(L(f),o.outline,o.holes)),s=c.filter(f=>!!f.path).map(f=>f.id),l=[],d=[],g=i/100;for(let f of c){if(f.path)continue;if(f.seatCount<2){l.push(f.id);continue}let b=Math.hypot(f.origin.x-r.x,f.origin.y-r.y);if(b<=f.seatSpacing/2+1e-6){l.push(f.id);continue}let m=2*Math.asin(f.seatSpacing/(2*b))/X,x=z(f),I=Math.atan2(f.origin.x-r.x,f.origin.y-r.y)/X,y=(f.curve!==0?Math.sign(f.curve):x.length>1&&Math.sign(hn(Math.atan2(x[1].x-r.x,x[1].y-r.y)/X-I))||1)*m*(f.seatCount-1);if(Math.abs(y)>320){l.push(f.id);continue}let w=-I,v=f.curve+(y-f.curve)*g,S=f.rotation+hn(w-f.rotation)*g,_={...f,curve:v,rotation:S},F=z(_).map((U,K)=>Math.hypot(U.x-x[K].x,U.y-x[K].y));d.push({rowId:f.id,fromCurve:f.curve,targetCurve:y,resultCurve:v,fromRotation:f.rotation,resultRotation:S,rmsMovement:Math.sqrt(F.reduce((U,K)=>U+K**2,0)/F.length),maxMovement:Math.max(...F)})}let h=d.map(f=>f.rmsMovement);return{floorId:n.floorId,sectionId:o.id,mode:t.mode,fitCenter:{...r},strength:i,rows:d,skippedPathRowIds:s,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 Kr(e,t){let n=yn(e,t),o=C(e,n.floorId),i=o.objects.find(r=>r.type==="section"&&r.id===n.sectionId),a=!1;for(let r of n.rows){let c=o.objects.find(s=>s.type==="row"&&s.id===r.rowId);(c.curve!==r.resultCurve||c.rotation!==r.resultRotation)&&(c.curve=r.resultCurve,c.rotation=r.resultRotation,delete c.arcFanGeneration,delete c.rowBlockGeneration,a=!0)}return(i.smoothing??0)!==n.strength&&(i.smoothing=n.strength,a=!0),{...n,changed:a}}function mn(e,t,n,o){let i=J(e,t,n),a=J(e,t,o),r=J(n,o,e),c=J(n,o,t);return i*a<-1e-9&&r*c<-1e-9}function bn(e,t){return e.some((n,o)=>{let i=e[(o+1)%e.length];return t.some((a,r)=>mn(n,i,a,t[(r+1)%t.length]))})}function $r(e){if(e.length<3||e.length>256||Math.abs(he(e))<1||e.some(t=>!Number.isFinite(t.x)||!Number.isFinite(t.y)))return!1;for(let t=0;t<e.length;t++)for(let n=t+1;n<e.length;n++)if(!(n===t+1||t===0&&n===e.length-1)&&mn(e[t],e[(t+1)%e.length],e[n],e[(n+1)%e.length]))return!1;return!0}function $e(e,t,n){let o=C(e,t),i=o.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:o,object:i,outer:i.type==="section"?i.outline:i.points}}function ze(e,t){let{target:n,object:o,outer:i}=$e(e,t.floorId,t.objectId),a=structuredClone(t.points);if(!$r(a))throw new u("invalid_operation","Opening must be a finite, non-self-intersecting shape with 3\u2013256 corners");if(a.some(l=>!D(l,i,void 0)))throw new u("invalid_operation","Every opening corner must stay inside the outer boundary");if(bn(a,i))throw new u("invalid_operation","Opening edges cannot cross the outer boundary");let r=o.holes??[],c=t.holeIndex??r.length;if(!Number.isInteger(c)||c<0||c>r.length||t.holeIndex!=null&&c>=r.length)throw new u("invalid_operation","Opening not found");for(let l=0;l<r.length;l++){if(l===t.holeIndex)continue;let d=r[l];if(bn(a,d)||D(a[0],d,void 0)||D(d[0],a,void 0))throw new u("invalid_operation","Openings cannot overlap or contain one another")}let s=n.objects.filter(l=>l.id!==o.id&&l.type!=="section"&&D(L(l),a,void 0));return{floorId:n.floorId,objectId:o.id,objectType:o.type,holeIndex:c,vertexCount:a.length,excludedObjectIds:s.map(l=>l.id),excludedInventoryUnits:Ke(n.objects.filter(l=>l.id!==o.id),a),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function zr(e,t){let n=ze(e,t),{object:o}=$e(e,n.floorId,n.objectId);return o.holes??=[],t.holeIndex==null?o.holes.push(structuredClone(t.points)):o.holes[t.holeIndex]=structuredClone(t.points),{...n,changed:!0}}function wn(e,t){let{target:n,object:o}=$e(e,t.floorId,t.objectId);if(!Number.isInteger(t.holeIndex)||t.holeIndex<0||t.holeIndex>=(o.holes?.length??0))throw new u("invalid_operation","Opening not found");let i=o.holes[t.holeIndex],a=n.objects.filter(r=>r.id!==o.id&&r.type!=="section"&&D(L(r),i,void 0));return{floorId:n.floorId,objectId:o.id,objectType:o.type,holeIndex:t.holeIndex,vertexCount:i.length,excludedObjectIds:a.map(r=>r.id),excludedInventoryUnits:Ke(n.objects.filter(r=>r.id!==o.id),i),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function Br(e,t){let n=wn(e,t),{object:o}=$e(e,n.floorId,n.objectId);return o.holes.splice(t.holeIndex,1),o.holes.length||delete o.holes,{...n,changed:!0}}function Ur(e){let t=Y(e);if(!t)throw new u("invalid_operation","Section view photo must be a safe HTTPS or base64 raster image reference");return t}function xn(e,t){let n=[...new Set(t)];if(!n.length)throw new u("invalid_operation","At least one section id is required");let o=n.map(r=>e.find(c=>c.type==="section"&&c.id===r)),i=n.filter((r,c)=>!o[c]);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=o;return{requested:n,sections:a,logicalSectionIds:[...new Set(a.map(r=>r.logicalSectionId??r.id))]}}function vn(e,t){let n=C(e,t.floorId),o=xn(n.objects,t.sectionIds),i=me(ke(e,n.floorId)),a=new Map(i.sections.map(g=>[g.id,g])),r=new Map(n.objects.map(g=>[g.id,g])),c=o.logicalSectionIds.flatMap(g=>a.get(g)?.objectIds??[]),s=new Set;for(let g of c){let h=r.get(g);if(h)if(h.type==="row"||h.type==="table")for(let f of Ne(h).keys())s.add(f);else(h.type==="booth"||h.type==="gaArea")&&s.add(h.categoryKey)}let l=o.logicalSectionIds.every(g=>(a.get(g)?.seatCount??0)>0),d=o.logicalSectionIds.every(g=>a.get(g)?.objectIds.some(h=>{let f=r.get(h);return f?.type==="row"||f?.type==="table"||f?.type==="booth"})===!0);return{floorId:n.floorId,sectionIds:o.requested,logicalSectionIds:o.logicalSectionIds,objectIds:c,categoryApplicable:l,...l&&s.size===1?{categoryKey:[...s][0]}:{},categoryMixed:l&&s.size!==1,viewApplicable:d}}function Hr(e,t){k(e,t.categoryKey);let n=vn(e,t);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 o=C(e,n.floorId),i=new Set(n.objectIds),a=!1,r=0;for(let c of o.objects){if(!i.has(c.id)||c.type!=="row"&&c.type!=="table"&&c.type!=="booth"&&c.type!=="gaArea"||(c.categoryKey!==t.categoryKey&&(c.categoryKey=t.categoryKey,a=!0),c.type!=="row"&&c.type!=="table"||!c.overrides?.length))continue;let s=c.overrides.flatMap(l=>{if(l.categoryKey===void 0)return[l];let d={...l};return delete d.categoryKey,r++,a=!0,Object.keys(d).some(g=>g!=="index")?[d]:[]});s.length?c.overrides=s:delete c.overrides}return{...n,changed:a,categoryKey:t.categoryKey,categoryMixed:!1,clearedSeatOverrideCount:r}}function Vr(e,t){let n=C(e,t.floorId),o=xn(n.objects,t.sectionIds),{requested:i}=o,a=structuredClone(t.patch),r=new Set(["label","displayLabel","entrance","viewFromSeatUrl","viewFromSeatMeta","labelPresentation","labelStyle","zone","elevation","height","rake","surfaceKind","color"]),c=Object.keys(a).filter(f=>!r.has(f));if(c.length)throw new u("invalid_operation",`Unsupported section metadata field(s): ${c.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=Ur(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&&Le(a.labelPresentation,"Section"),a.labelStyle!==void 0&&ce(a.labelStyle,"Section"),a.zone!==void 0&&a.zone!==null&&!(e.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=T(a.color,"Section color"));let s=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(o.logicalSectionIds),d=s?n.objects.filter(f=>f.type==="section"&&l.has(f.logicalSectionId??f.id)):[],g=new Set,h=!1;for(let f of o.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 m=x=>{f.physical3dProvenance&&(delete f.physical3dProvenance[x],Object.keys(f.physical3dProvenance).length===0&&delete f.physical3dProvenance)};a.height===null?(delete f.height,m("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,m("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,m("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),m=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!==m&&delete f.viewFromSeatMeta,a.labelStyle!==void 0){let x=Ee(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 Sn(e,t){let n=C(e,t.floorId),o=n.objects.find(a=>a.type==="section"&&a.id===t.sectionId);if(!o)throw new u("object_not_found",`Unknown section id: ${t.sectionId}`,{sectionId:t.sectionId});if(o.outlinePath)throw new u("invalid_operation",`Section ${o.id} has an exact path; polygon conversion requires a separate loss review`,{sectionId:o.id,representation:"exact-path"});if(!o.geometry)throw new u("invalid_operation",`Section ${o.id} is already a manual polygon`,{sectionId:o.id,representation:"manual-polygon"});let i=n.objects.filter(a=>a.id!==o.id&&a.type!=="section"&&D(L(a),o.outline,o.holes));return{floorId:n.floorId,sectionId:o.id,sectionLabel:o.label,source:{representation:"generated-polygon",generator:structuredClone(o.geometry)},target:{representation:"manual-polygon"},geometryChanged:!1,preserved:{stableId:!0,outlineVertexCount:o.outline.length,holeCount:o.holes?.length??0,memberObjectIds:i.map(a=>a.id),inventoryUnits:i.reduce((a,r)=>a+ee(r),0),durableReferenceSource:!!o.referenceSource,inventoryExclusionEvidence:!!o.referenceInventoryExclusion},removedFields:["geometry"]}}function Jr(e,t){let n=Sn(e,t),i=C(e,n.floorId).objects.find(a=>a.type==="section"&&a.id===n.sectionId);return delete i.geometry,{...n,changed:!0}}function In(e,t){let n=(...c)=>c.every(Number.isFinite),o,i=1,a=!1,r=!0;if(t.kind==="translate"){if(!n(t.dx,t.dy))throw new u("invalid_operation","Section translation must be finite");r=t.dx!==0||t.dy!==0,o=c=>({x:c.x+t.dx,y:c.y+t.dy})}else if(t.kind==="scale"){if(!n(t.factor)||t.factor<=0||t.factor>100)throw new u("invalid_operation","Section scale factor must be finite and greater than 0");r=t.factor!==1,i=t.factor;let c=L(e);o=s=>({x:c.x+(s.x-c.x)*t.factor,y:c.y+(s.y-c.y)*t.factor})}else if(t.kind==="rotate"){if(!n(t.degrees))throw new u("invalid_operation","Section rotation must be finite");r=(t.degrees%360+360)%360!==0;let s=t.degrees*Math.PI/180,l=Math.cos(s),d=Math.sin(s),g=L(e);o=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(t.coordinate))throw new u("invalid_operation","Section reflection coordinate must be finite");a=!0,o=t.axis==="h"?c=>({x:2*t.coordinate-c.x,y:c.y}):c=>({x:c.x,y:2*t.coordinate-c.y})}return r&&(e.outline=e.outline.map(o),e.sourceOutline&&(e.sourceOutline=e.sourceOutline.map(o)),e.outlinePath&&(e.outlinePath=it(e.outlinePath,o,i,a)),e.holes&&(e.holes=e.holes.map(c=>c.map(o)))),{changed:r,sectionId:e.id,representation:e.outlinePath?"exact-path":"polygon",outlineVertexCount:e.outline.length,holeCount:e.holes?.length??0,pathSegmentKinds:e.outlinePath?.segments.map(c=>c.kind)??[]}}function qr(e,t){let n=C(e,t.floorId),o=n.objects.find(i=>i.type==="section"&&i.id===t.sectionId);if(!o)throw new u("object_not_found",`Unknown section id: ${t.sectionId}`,{sectionId:t.sectionId});return{floorId:n.floorId,...In(o,t.transform)}}function Xr(e,t){let n=C(e,t.floorId),o=n.objects.find(c=>c.type==="section"&&c.id===t.sectionId);if(!o)throw new u("object_not_found",`Unknown section id: ${t.sectionId}`,{sectionId:t.sectionId});let i=structuredClone(t.path);if(!Ae(i))throw new u("invalid_operation","Exact section path is not finite, continuous, closed, or radius-correct");let a=rt(i),r=JSON.stringify(o.outlinePath)!==JSON.stringify(i)||JSON.stringify(o.outline)!==JSON.stringify(a)||o.sourceOutline!==void 0||o.cornerSmoothing!==void 0;return r&&(o.outlinePath=i,o.outline=a,delete o.geometry,delete o.sourceOutline,delete o.cornerSmoothing),{floorId:n.floorId,sectionId:o.id,changed:r,segmentKinds:i.segments.map(c=>c.kind),sampledVertexCount:a.length,holeCount:o.holes?.length??0}}function Qr(e){return e.geometry?null:e.sourceOutline?.length?e.sourceOutline:e.outlinePath?null:e.outline?.length?e.outline:null}function Yr(e,t){return Cn(e,{floorId:t.floorId,sectionIds:t.sectionIds,cornerSmoothing:t.strength})}function Cn(e,t){let n=C(e,t.floorId);if(t.cornerSmoothing!==void 0&&!Number.isFinite(t.cornerSmoothing))throw new u("invalid_operation","Corner smoothing must be a number from 0 to 100");if(t.edgeCurvature!=null&&t.edgeCurvature.some(c=>!Number.isFinite(c)))throw new u("invalid_operation","Edge curvature values must be numbers from -100 to 100");let o=[...new Set(t.sectionIds)],i=new Set,a=new Map,r=!1;try{for(let c of o){let s=n.objects.find(p=>p.type==="section"&&p.id===c);if(!s||!Qr(s))continue;let d=structuredClone(s);a.set(s.id,{section:s,snapshot:d});let g=JSON.stringify(s),h=(s.sourceOutline??s.outline).map(p=>({...p})),f=Math.min(100,Math.max(0,t.cornerSmoothing??s.cornerSmoothing??0)),m=(t.edgeCurvature===void 0?s.edgeCurvature:t.edgeCurvature??void 0)?.map(p=>Math.min(100,Math.max(-100,p))),x=m?.some(p=>Math.abs(p)>.5)===!0,I=f>.5||x?Kt(h,{cornerSmoothing:f,...x?{edgeCurvature:m}:{}}):null;I?(s.sourceOutline=h,s.outlinePath=I,s.outline=rt(I),f>.5?s.cornerSmoothing=f:delete s.cornerSmoothing,x?s.edgeCurvature=[...m]:delete s.edgeCurvature):(s.outline=h,delete s.outlinePath,delete s.sourceOutline,delete s.cornerSmoothing,delete s.edgeCurvature);for(let p=0;p<(s.holes?.length??0);p+=1)ze(e,{floorId:n.floorId,objectId:s.id,points:s.holes[p],holeIndex:p});JSON.stringify(s)!==g&&(r=!0,i.add(s.id))}}catch(c){for(let{section:s,snapshot:l}of a.values()){let d=s;for(let g of Object.keys(d))delete d[g];Object.assign(s,structuredClone(l))}throw c}return{floorId:n.floorId,changed:r,sectionIds:o,affectedSectionIds:[...i]}}var Zr=/^#?([\da-f]{3}|[\da-f]{6})$/i;function Be(e){let t=Zr.exec((e??"").trim());if(!t)return null;let n=t[1].length===3?t[1].split("").map(i=>i+i).join(""):t[1],o=parseInt(n,16);return[o>>16&255,o>>8&255,o&255]}function vt(e){let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}function Pn(e){return .2126*vt(e[0])+.7152*vt(e[1])+.0722*vt(e[2])}function Ue(e,t){let n=Be(e),o=Be(t);if(!n||!o)return null;let i=Pn(n),a=Pn(o);return(Math.max(i,a)+.05)/(Math.min(i,a)+.05)}var On=["butt","round","square"],_n=["miter","round","bevel"],An=["none","arrow"];function St(e){return e==="line"||e==="polyline"}function Mn(e){let t=Be(e);if(!t)return null;let n=f=>{let b=f/255;return b<=.04045?b/12.92:((b+.055)/1.055)**2.4},o=n(t[0]),i=n(t[1]),a=n(t[2]),r=(.4124*o+.3576*i+.1805*a)/.95047,c=(.2126*o+.7152*i+.0722*a)/1,s=(.0193*o+.1192*i+.9505*a)/1.08883,l=f=>f>.008856?Math.cbrt(f):7.787*f+16/116,d=l(r),g=l(c),h=l(s);return[116*g-16,500*(d-g),200*(g-h)]}function jn(e,t){let n=Mn(e),o=Mn(t);return!n||!o?null:Math.hypot(n[0]-o[0],n[1]-o[1],n[2]-o[2])}var kn=[{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}}],ac=kn.map(e=>e.key),Wr=new Map(kn.map(e=>[e.key,e]));function ve(e){return typeof e=="string"&&Wr.has(e)}var ei=new Set(["companion","child","senior","student","membership","custom"]);function Se(e){if(!e.length)throw new u("invalid_operation","A chart must have at least one category");let t=new Set,n=new Map,o=structuredClone(e);for(let i of o){let a=i.key.trim(),r=i.label.normalize("NFKC").trim();if(!a||a.length>160||t.has(a))throw new u("invalid_operation",`Category keys must be non-empty and unique: ${a}`,{categoryKey:a});if(t.add(a),!r||r.length>80)throw new u("invalid_operation",`Category labels must contain 1 to 80 characters: ${a}`,{categoryKey:a});let c=r.toLocaleLowerCase("en"),s=n.get(c);if(s)throw new u("duplicate_category_label",`Categories ${s} and ${a} share the same label`,{categoryKeys:[s,a],label:r});if(n.set(c,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&&!ve(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&&!ei.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 m=g.applicability.seatLabels?.map(I=>I.normalize("NFKC").trim()),x=g.applicability.accessibility;if(m&&(!m.length||m.length>1e4||m.some(I=>!I||I.length>160)||new Set(m).size!==m.length)||x&&(!x.length||x.some(I=>!pe.some(p=>p.key===I))||new Set(x).size!==x.length))throw new u("invalid_operation",`Ticket tier ${h} has invalid seat applicability`,{categoryKey:a,tierId:h});g.applicability={...m?{seatLabels:m}:{},...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 o}function Ln(e,t){let n=new Set,o=structuredClone(e.categories);for(let r of t.updates){if(n.has(r.categoryKey))throw new u("invalid_operation",`Category ${r.categoryKey} may be updated only once`);n.add(r.categoryKey);let c=o.find(g=>g.key===r.categoryKey);if(!c)throw new u("category_not_found",`Unknown chart category: ${r.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:r.categoryKey});let s=structuredClone(r.patch),{tiers:l,...d}=s;typeof d.label=="string"&&(d.label=d.label.normalize("NFKC").trim()),typeof d.color=="string"&&(d.color=d.color.toLowerCase()),Object.assign(c,d),c.notForSale===!1&&delete c.notForSale,Object.prototype.hasOwnProperty.call(s,"tiers")&&(l==null?delete c.tiers:c.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=Se(o),a=JSON.stringify(i)!==JSON.stringify(e.categories);return a&&(e.categories=i),{changed:a,categoryKeys:[...n],categories:e.categories}}function ti(e,t){let n=t.categoryKeys.map(s=>s.trim()),o=e.categories.map(s=>s.key);if(n.length!==o.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:o});let i=new Set(o),a=o.filter(s=>!n.includes(s)),r=n.filter(s=>!i.has(s));if(a.length||r.length)throw new u(r.length?"category_not_found":"invalid_operation","Category order must be an exact permutation of the current stable keys",{categoryKeys:n,missingCategoryKeys:a,unknownCategoryKeys:r});if(n.every((s,l)=>s===o[l]))return{changed:!1,categoryKeys:o,categories:e.categories};let c=new Map(e.categories.map(s=>[s.key,s]));return e.categories=Se(n.map(s=>structuredClone(c.get(s)))),{changed:!0,categoryKeys:n,categories:e.categories}}var It=["#e69f00","#56b4e9","#009e73","#f0e442","#0072b2","#d55e00","#cc79a7"];function Rn(e){let t=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i.exec(e.trim());if(!t)return null;let n=t[1];return n.length===3&&(n=n.split("").map(o=>o+o).join("")),[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)]}function ni(e,t){let n=Rn(e),o=Rn(t);return!n||!o?1/0:(n[0]-o[0])**2+(n[1]-o[1])**2+(n[2]-o[2])**2}var oi=3600;function En(e,t,n=It){return n.find(i=>e.every(a=>ni(i,a)>=oi))??n[t%n.length]}function ri(e,t){let n=t?.palette??It;if(!e.categories.length)return{changed:[],categories:e.categories};let o=new Map(e.categories.map(r=>[r.key,r.color.toLowerCase()])),i=e.categories.map((r,c)=>({categoryKey:r.key,patch:{color:n[c%n.length]}}));return Ln(e,{updates:i}),{changed:e.categories.map(r=>({key:r.key,from:o.get(r.key),to:r.color})).filter(r=>r.from!==r.to),categories:e.categories}}function ii(e,t){let n=t.color.trim().toLowerCase(),o=t.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(!o||o.length>240)throw new u("invalid_operation","Color confirmation evidence must contain 1 to 240 characters");let i=structuredClone(e.categories),a=i.find(s=>s.key===t.categoryKey);if(!a)throw new u("category_not_found",`Unknown chart category: ${t.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:t.categoryKey});a.color=n,a.referenceCategorySource&&(a.referenceCategorySource.outputColorEvidence="user-confirmed",a.referenceCategorySource.outputColorSourceDescription=o);let r=Se(i),c=JSON.stringify(r)!==JSON.stringify(e.categories);return c&&(e.categories=r),{changed:c,category:e.categories.find(s=>s.key===t.categoryKey),categories:e.categories}}function Tn(e,t){let n=new Set(e.categories.map(r=>r.key)),o="";for(let r=0;r<100;r++){let s=t.idFactory("cat").trim();if(s&&!n.has(s)){o=s;break}}if(!o)throw new u("id_generation_failed","Unable to allocate a unique category id");let i={key:o,label:t.label.normalize("NFKC").trim(),color:t.color.toLowerCase(),price:t.price,tiers:t.tiers?.map(r=>({...r,id:r.id.trim(),name:r.name.normalize("NFKC").trim()}))},a=Se([...e.categories,i]);return e.categories=a,{changed:!0,category:a.find(r=>r.key===o),categories:a}}var ai=["#e5484d","#a86b00","#8b5cf6","#d6336c","#4d7c0f","#dc2626","#c026d3"],si={row:"#e5484d",table:"#a86b00",booth:"#8b5cf6",gaArea:"#4d7c0f"};function ci(e,t){let n=si[e];return!n||!t.includes(n)?t:[n,...t.filter(o=>o!==n)]}var li=26;function di(e,t,n){let o=(1-Math.abs(2*n-1))*t,i=(e%360+360)%360/60,a=o*(1-Math.abs(i%2-1)),[r,c,s]=i<1?[o,a,0]:i<2?[a,o,0]:i<3?[0,o,a]:i<4?[0,a,o]:i<5?[a,0,o]:[o,0,a],l=n-o/2,d=g=>Math.round((g+l)*255).toString(16).padStart(2,"0");return`#${d(r)}${d(c)}${d(s)}`}function ui(e,t,n){let o=r=>e.every(c=>{let s=jn(r,c);return s==null||s>=li}),i=r=>{let c=Ue(r,"#12151d"),s=Ue(r,"#ffffff");return(c??0)>=3||(s??0)>=3},a=t.find(r=>o(r)&&i(r));if(a)return a;for(let r=0;r<360;r+=12)for(let c of[.52,.44,.6]){let s=di(r,.62,c);if(o(s)&&i(s))return s}return n}function Fn(e,t){let n=Fe.find(i=>i.objectType===t).creationWord;return`${e.replace(/\s*[–-]\s*(Tables|Booths|Standing|Seats)$/i,"").trim()||e.trim()} \u2013 ${n}`}function fi(e){let t=new Map;for(let n of E(e))for(let o of n.objects){let i=Fe.find(r=>r.objectType===o.type);if(!i)continue;let a=new Set;if(o.type==="row"||o.type==="table")for(let r of Ne(o).keys())a.add(r);else"categoryKey"in o&&o.categoryKey&&a.add(o.categoryKey);for(let r of a){let c=t.get(r)??new Set;c.add(i.objectType),t.set(r,c)}}return t}function gi(e,t){let n=new Set(e.categories.map(i=>i.label.toLowerCase())),o=t;for(let i=2;n.has(o.toLowerCase());i+=1)o=`${t} ${i}`;return o}function Nn(e,t,n){let o=fi(e),i=l=>{let d=o.get(l);return!d||d.size===0||d.size===1&&d.has(n)},a=e.categories.find(l=>l.key===t);if(a&&i(a.key))return{kind:"existing",categoryKey:a.key,label:a.label};if(!a){let l=e.categories.find(d=>{let g=o.get(d.key);return g?.size===1&&g.has(n)});if(l)return{kind:"existing",categoryKey:l.key,label:l.label}}let r=Fe.find(l=>l.objectType===n),c=a?Fn(a.label,n):n==="gaArea"?"General Admission":r.creationWord,s=e.categories.find(l=>l.label.toLowerCase()===c.toLowerCase()&&i(l.key));return s?{kind:"existing",categoryKey:s.key,label:s.label}:{kind:"mint",...a?{baseCategoryKey:a.key}:{},label:gi(e,c)}}function hi(e,t,n,o){let i=Nn(e,t,n);if(i.kind==="existing")return i.categoryKey;let a=i.baseCategoryKey?e.categories.find(r=>r.key===i.baseCategoryKey):void 0;return bi(e,n,a,i.label,o)}function bi(e,t,n,o,i){let a=i.palette??ai,r=e.categories.map(d=>d.color),c=i.suggestColor?.(r.map(d=>d.toLowerCase()))??En(r,e.categories.length),s=ui(r,ci(t,a),c),l=Tn(e,{label:o,color:s,...n?.price!==void 0?{price:n.price}:{},...n?.tiers?.length?{tiers:n.tiers}:{},idFactory:i.idFactory});return e.categories=l.categories,l.category.key}function pi(e,t){let n=new Set;for(let o of E(e))for(let i of o.objects)"categoryKey"in i&&i.categoryKey===t&&n.add(i.id),(i.type==="row"||i.type==="table")&&i.overrides?.some(a=>a.categoryKey===t)&&n.add(i.id);return[...n]}function yi(e,t){let n=e.categories.find(a=>a.key===t.categoryKey);if(!n)throw new u("category_not_found",`Unknown chart category: ${t.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:t.categoryKey});if(e.categories.length<=1)throw new u("invalid_operation","A chart must retain at least one category");let o=pi(e,t.categoryKey);if(o.length)throw new u("category_in_use",`Category ${t.categoryKey} is still assigned to chart inventory`,{categoryKey:t.categoryKey,objectIds:o});if(n.referenceCategorySource)throw new u("reference_category_protected",`Reference-backed category ${t.categoryKey} cannot be deleted through a generic catalog operation`,{categoryKey:t.categoryKey});let i=Se(e.categories.filter(a=>a.key!==t.categoryKey));return e.categories=i,{changed:!0,categoryKey:t.categoryKey,categories:i}}var mi=["background","seatLabelColor","rowLabelColor","selectionColor","decorFill","textColor","accent","accentInk"],Dn=.7,Gn=1.6,wi=["seat","deck","shell","fascia"];function xi(e,t){let n=t.patch;if(!Object.keys(n).length)throw new u("invalid_operation","At least one theme field is required");let o=JSON.stringify(e.theme??null),i={...e.theme??{}};for(let a of mi){let r=n[a];r===null?delete i[a]:r!==void 0&&(i[a]=T(r,`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<Dn||n.seatScale>Gn)throw new u("invalid_operation",`Theme seatScale must be from ${Dn} to ${Gn}`);i.seatScale=n.seatScale}if(n.logoUrl===null)delete i.logoUrl;else if(n.logoUrl!==void 0){let a=Y(n.logoUrl);if(!a)throw new u("invalid_operation","Theme logoUrl must be a safe HTTPS or base64 raster 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}if(n.hideBadge===null||n.hideBadge===!1?delete i.hideBadge:n.hideBadge===!0&&(i.hideBadge=!0),n.venue3d===null)delete i.venue3d;else if(n.venue3d!==void 0){let a={...i.venue3d??{}};for(let c of wi){let s=n.venue3d[c];s===null?delete a[c]:s!==void 0&&(a[c]=T(s,`3D venue ${c}`))}let r=n.venue3d.roughness;if(r===null)delete a.roughness;else if(r!==void 0){if(!Number.isFinite(r)||r<0||r>1)throw new u("invalid_operation","3D venue roughness must be from 0 to 1");a.roughness=r}i.venue3d=Object.keys(a).length?a:void 0,i.venue3d||delete i.venue3d}return e.theme=Object.keys(i).length?i:void 0,{changed:JSON.stringify(e.theme??null)!==o,theme:e.theme??null}}function vi(e,t){let n=t.url===null?null:Y(t.url);if(t.url!==null&&!n)throw new u("invalid_operation","View-from-seat photo must be a safe HTTPS or base64 raster image reference");let o=n??void 0;if(t.floorId!==void 0){let c=e.floors?.find(g=>g.id===t.floorId);if(!c)throw new u("invalid_operation",`Unknown floor: ${t.floorId}`);let s=(c.viewFromSeatUrl??void 0)===o,l=o?t.metadata===null?void 0:t.metadata??(s?c.viewFromSeatMeta:void 0):void 0,d=!s||JSON.stringify(c.viewFromSeatMeta??null)!==JSON.stringify(l??null);return c.viewFromSeatUrl=o,c.viewFromSeatMeta=l,{changed:d,scope:"floor",floorId:t.floorId,url:c.viewFromSeatUrl??null}}let i=(e.viewFromSeatUrl??void 0)===o,a=o?t.metadata===null?void 0:t.metadata??(i?e.viewFromSeatMeta:void 0):void 0,r=!i||JSON.stringify(e.viewFromSeatMeta??null)!==JSON.stringify(a??null);return e.viewFromSeatUrl=o,e.viewFromSeatMeta=a,{changed:r,scope:"venue",url:e.viewFromSeatUrl??null}}function Si(e,t){let n=ke(e,t.floorId),o=Zt(n),i=t.placement==="auto"||t.placement==null?"rear":t.placement,a=96;return i==="front"?{x:o.x+o.width/2,y:o.y-a-t.height/2}:i==="left"?{x:o.x-a-t.width/2,y:o.y+o.height/2}:i==="right"?{x:o.x+o.width+a+t.width/2,y:o.y+o.height/2}:{x:o.x+o.width/2,y:o.y+o.height+a+t.height/2}}function He(e,t){k(e,t.categoryKey);let n=(...d)=>d.every(Number.isFinite);if(!n(t.center.x,t.center.y,t.innerRadius,t.rowGap,t.startAngle,t.endAngle,t.seatPitch))throw new u("invalid_operation","Arc/Fan geometry values must be finite");if(!Number.isInteger(t.rowCount)||t.rowCount<1||t.rowCount>100)throw new u("invalid_operation","Arc/Fan rowCount must be an integer from 1 to 100");if(t.innerRadius<40||t.innerRadius>2e4||t.rowGap<12||t.rowGap>500)throw new u("invalid_operation","Arc/Fan radius must be 40\u201320000 and row gap 12\u2013500");let o=t.endAngle-t.startAngle;if(Math.abs(o)<5||Math.abs(o)>320)throw new u("invalid_operation","Arc/Fan sweep must be from 5\xB0 to 320\xB0");if(t.seatPitch<14||t.seatPitch>80)throw new u("invalid_operation","Arc/Fan seat pitch must be from 14 to 80 chart units");let i=t.fit??"seat-pitch";if(i==="fixed-count"&&(!Number.isInteger(t.seatsPerRow)||t.seatsPerRow<2||t.seatsPerRow>300))throw new u("invalid_operation","Fixed Arc/Fan rows require seatsPerRow from 2 to 300");let a=t.taperDegrees??0,r=t.skewDegrees??0;if(!n(a,r)||Math.abs(a)>120||Math.abs(r)>180)throw new u("invalid_operation","Arc/Fan taper must be within \xB1120\xB0 and skew within \xB1180\xB0");let c={left:t.aisleGaps?.left??0,center:t.aisleGaps?.center??0,right:t.aisleGaps?.right??0};if(!n(c.left,c.center,c.right)||Object.values(c).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(e,t.floorId).objects.filter(d=>d.type==="row").length;return{...t,fit:i,facing:t.facing??"inward",taperDegrees:a,skewDegrees:r,aisleGaps:c,rowLabelStart:t.rowLabelStart??l,seatLabelStart:t.seatLabelStart??1}}function Ii(e,t,n){let o=n*X;return{x:e.x+t*Math.sin(o),y:e.y+t*Math.cos(o)}}function Ci(e,t,n,o){let i=Math.abs(o-n)*X,a=[["left",.25],["center",.5],["right",.75]].flatMap(([l,d])=>{let g=e.aisleGaps[l];if(!g)return[];let h=g/t/i/2;return[[Math.max(0,d-h),Math.min(1,d+h)]]}).sort((l,d)=>l[0]-d[0]),r=[];for(let l of a){let d=r[r.length-1];d&&l[0]<=d[1]?d[1]=Math.max(d[1],l[1]):r.push([...l])}let c=[],s=0;for(let l of r)l[0]-s>1e-6&&c.push([s,l[0]]),s=Math.max(s,l[1]);return 1-s>1e-6&&c.push([s,1]),c.filter(([l,d])=>t*i*(d-l)>=e.seatPitch*.75)}function Pi(e,t){let n=e.length*2;if(t<n)throw new u("invalid_operation",`Fixed seat count must be at least ${n} for ${e.length} aisle-separated row segments`);let o=t-n,i=e.reduce((s,l)=>s+l,0),a=e.map(s=>o*s/i),r=a.map(s=>2+Math.floor(s)),c=t-r.reduce((s,l)=>s+l,0);return a.map((s,l)=>({index:l,fraction:s-Math.floor(s)})).sort((s,l)=>l.fraction-s.fraction||s.index-l.index).forEach(({index:s})=>{c-- >0&&r[s]++}),r}function Ve(e,t,n){let o=[];for(let i=0;i<e.rowCount;i++){let a=e.rowCount===1?0:i/(e.rowCount-1),r=e.innerRadius+i*e.rowGap,c=Math.sign(e.endAngle-e.startAngle)||1,s=e.startAngle+c*e.taperDegrees*a+e.skewDegrees*a,l=e.endAngle-c*e.taperDegrees*a+e.skewDegrees*a;if(Math.sign(l-s)!==Math.sign(e.endAngle-e.startAngle)||Math.abs(l-s)<5)throw new u("invalid_operation",`Arc/Fan taper collapses row ${i+1} below a 5\xB0 sweep`);let d=Ci(e,r,s,l);if(!d.length)throw new u("invalid_operation",`Arc/Fan aisles leave no usable span in row ${i+1}`);e.facing==="outward"&&(d=d.slice().reverse());let g=d.map(([b,m])=>r*Math.abs(l-s)*X*(m-b)),h=e.fit==="fixed-count"?Pi(g,e.seatsPerRow):g.map(b=>Math.max(2,Math.round(b/e.seatPitch)+1)),f=e.seatLabelStart;d.forEach(([b,m],x)=>{let I=s+(l-s)*b,p=s+(l-s)*m;e.facing==="outward"&&([I,p]=[p,I]);let y=h[x];if(y>300)throw new u("invalid_operation","An Arc/Fan row segment cannot exceed 300 seats");let w=Math.abs(p-I)*X/(y-1),v=2*r*Math.sin(w/2),S={type:"row",id:n(i,x),label:B(e.rowLabelStart+i),origin:Ii(e.center,r,I),rotation:-I,curve:p-I,seatCount:y,seatSpacing:v,categoryKey:e.categoryKey,seatLabelStart:f,arcFanGeneration:{kind:"arc-fan-v1",groupId:t,center:{...e.center},innerRadius:e.innerRadius,rowCount:e.rowCount,rowGap:e.rowGap,startAngle:e.startAngle,endAngle:e.endAngle,seatPitch:e.seatPitch,fit:e.fit,...e.seatsPerRow!=null?{seatsPerRow:e.seatsPerRow}:{},facing:e.facing,taperDegrees:e.taperDegrees,skewDegrees:e.skewDegrees,aisleGaps:{...e.aisleGaps},rowLabelStart:e.rowLabelStart,seatLabelStart:e.seatLabelStart,rowIndex:i,segmentIndex:x}};o.push(S),f+=y})}return o}function Ct(e,t){let n=He(e,t),o=C(e,t.floorId),i=Ve(n,"preview-arc-fan",(s,l)=>`preview-fan-${s}-${l}`),a=i.map(s=>s.seatSpacing),r=Math.max(...a.map(s=>Math.abs(s-n.seatPitch))),c=[];return r>n.seatPitch*.12&&c.push(`Seat fitting deviates from the requested pitch by up to ${r.toFixed(1)} chart units`),i.length>n.rowCount*3&&c.push("Three aisles split each logical row into four separately editable segments"),{floorId:o.floorId,rows:i,logicalRowCount:n.rowCount,rowSegmentCount:i.length,totalSeats:i.reduce((s,l)=>s+l.seatCount,0),innerRadius:n.innerRadius,outerRadius:n.innerRadius+(n.rowCount-1)*n.rowGap,minSeatSpacing:Math.min(...a),maxSeatSpacing:Math.max(...a),maxPitchDeviation:r,aisleCount:Object.values(n.aisleGaps).filter(s=>s>0).length,warnings:c}}function Oi(e,t){let n=He(e,t),o=C(e,t.floorId),i=new Set,a=M(e,"fan",t.idFactory,i),r=Ve(n,a,()=>M(e,"r",t.idFactory,i)),c=Ct(e,t),s=null,l=t.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=W(r);g&&(s=M(e,"sec",t.idFactory,i),d={type:"section",id:s,label:l,outline:g,arcFanGroupId:a})}return o.objects.push(...r,...d?[d]:[]),{floorId:o.floorId,rowIds:r.map(g=>g.id),sectionId:s,groupId:a,logicalRowCount:c.logicalRowCount,rowSegmentCount:c.rowSegmentCount,totalSeats:c.totalSeats,innerRadius:c.innerRadius,outerRadius:c.outerRadius,minSeatSpacing:c.minSeatSpacing,maxSeatSpacing:c.maxSeatSpacing,maxPitchDeviation:c.maxPitchDeviation,aisleCount:c.aisleCount,warnings:c.warnings}}function Kn(e,t){let n=C(e,t.floorId),o=n.objects.filter(g=>g.type==="row"&&g.arcFanGeneration?.groupId===t.groupId);if(!o.length)throw new u("object_not_found",`Unknown Arc/Fan group: ${t.groupId}`,{groupId:t.groupId});let i=o[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(o.some(g=>a(g)!==a(o[0])))throw new u("invalid_operation","Arc/Fan group provenance no longer agrees across all row segments",{groupId:t.groupId});let r=n.objects.find(g=>g.type==="section"&&g.arcFanGroupId===t.groupId),c={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:o[0].categoryKey,rowLabelStart:i.rowLabelStart,seatLabelStart:i.seatLabelStart,sectionLabel:r?.label},s=He(e,c),l=new Set(Ve(s,t.groupId,(g,h)=>`${g}:${h}`).map(g=>`${g.arcFanGeneration.rowIndex}:${g.arcFanGeneration.segmentIndex}`)),d=new Set(o.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:t.groupId});return c}function _i(e,t){Kn(e,{floorId:t.floorId,groupId:t.groupId});let n=He(e,t),o=C(e,t.floorId),i=o.objects.filter(m=>m.type==="row"&&m.arcFanGeneration?.groupId===t.groupId),a=o.objects.find(m=>m.type==="section"&&m.arcFanGroupId===t.groupId),r=new Map(i.map(m=>[`${m.arcFanGeneration.rowIndex}:${m.arcFanGeneration.segmentIndex}`,m.id])),c=new Set,s=Ve(n,t.groupId,(m,x)=>r.get(`${m}:${x}`)??M(e,"r",t.idFactory,c)),l=Ct(e,t),d=t.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 m=W(s);m&&(g={type:"section",id:a?.id??M(e,"sec",t.idFactory,c),label:d,outline:m,arcFanGroupId:t.groupId})}let h=new Set([...i.map(m=>m.id),...a?[a.id]:[]]),f=Math.min(...o.objects.map((m,x)=>h.has(m.id)?x:1/0)),b=o.objects.filter(m=>!h.has(m.id));return b.splice(Number.isFinite(f)?f:b.length,0,...s,...g?[g]:[]),o.objects.splice(0,o.objects.length,...b),{floorId:o.floorId,rowIds:s.map(m=>m.id),sectionId:g?.id??null,groupId:t.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 Ai(e){let t=new Set(H(e).filter(o=>o.type==="row"||o.type==="table"||o.type==="booth").map(o=>o.label).filter(o=>typeof o=="string")),n=0;return()=>{for(;t.has(B(n));)n+=1;let o=B(n);return t.add(o),n+=1,o}}function $n(e){return JSON.stringify(["row-block-v1",e.style,e.origin.x,e.origin.y,e.rotation,e.rowCount,e.seatsPerRow,e.rowGap,e.seatSpacing,e.curve])}function Mi(e,t){if(k(e,t.categoryKey),!Number.isInteger(t.rowCount)||t.rowCount<1||t.rowCount>100)throw new u("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(t.seatsPerRow)||t.seatsPerRow<1||t.seatsPerRow>300)throw new u("invalid_operation","seatsPerRow must be an integer from 1 to 300");let n=t.rowGap??28,o=t.seatSpacing??24;if(!Number.isFinite(n)||n<=0||!Number.isFinite(o)||o<=0)throw new u("invalid_operation","Row and seat spacing must be positive finite values");if(t.rotation!==void 0&&!Number.isFinite(t.rotation))throw new u("invalid_operation","rotation must be a finite number of degrees");let i=C(e,t.floorId),a=new Set,r=Ai(e),c=wt(t.rotation??0),s=t.curve??0,l=t.style,d=l?M(e,"rowblock",t.idFactory,a):void 0,g=l?$n({style:l,origin:t.origin,rotation:c,rowCount:t.rowCount,seatsPerRow:t.seatsPerRow,rowGap:n,seatSpacing:o,curve:s}):void 0,h={x:Math.cos(c*q),y:Math.sin(c*q)},f={x:-h.y,y:h.x},b=Array.from({length:t.rowCount},(I,p)=>{let y=l==="intertwined"&&p%2===1?o/2:0,w={type:"row",id:M(e,"r",t.idFactory,a),label:r(),origin:{x:t.origin.x+f.x*p*n+h.x*y,y:t.origin.y+f.y*p*n+h.y*y},rotation:c,curve:s,seatCount:t.seatsPerRow,seatSpacing:o,categoryKey:t.categoryKey};return l&&d&&g&&(w.rowBlockGeneration={kind:"row-block-v1",groupId:d,style:l,rowIndex:p,rowCount:t.rowCount,seatsPerRow:t.seatsPerRow,origin:{...t.origin},rotation:c,rowGap:n,seatSpacing:o,curve:s,signature:g}),w});i.objects.push(...b);let m=null,x=t.sectionLabel?.trim();if(x){let I=W(b);if(I){let p={type:"section",id:M(e,"sec",t.idFactory,a),label:x,outline:I};i.objects.push(p),m=p.id}}return{floorId:i.floorId,rowIds:b.map(I=>I.id),sectionId:m,createdIds:[...b.map(I=>I.id),...m?[m]:[]]}}function zn(e,t){let n=new Set(H(e).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(i=>typeof i=="string")),o=1;return()=>{for(;n.has(`${t}${o}`);)o+=1;let i=`${t}${o}`;return n.add(i),o+=1,i}}function ji(e,t){let n=new Set(H(e).filter(i=>i.type==="gaArea").map(i=>i.label));if(!n.has(t))return t;let o=2;for(;n.has(`${t} ${o}`);)o+=1;return`${t} ${o}`}var ki=456;function Bn(e){let t=Math.sqrt(Math.max(1,e)*ki);return{width:Math.round(t*1.027),height:Math.round(t/1.027)}}function Ri(e,t){if(k(e,t.categoryKey),!Number.isInteger(t.capacity)||t.capacity<1)throw new u("invalid_operation","capacity must be a positive integer");if(!Number.isFinite(t.center.x)||!Number.isFinite(t.center.y))throw new u("invalid_operation","GA area center must be finite");let n=C(e,t.floorId),o=new Set,{width:i,height:a}=Bn(t.capacity),r=ji(e,(t.label??"General Admission").trim()||"General Admission"),c={type:"gaArea",id:M(e,"ga",t.idFactory,o),label:r,...t.displayLabel?.trim()?{displayLabel:t.displayLabel.trim()}:{},points:[{x:t.center.x-i/2,y:t.center.y-a/2},{x:t.center.x+i/2,y:t.center.y-a/2},{x:t.center.x+i/2,y:t.center.y+a/2},{x:t.center.x-i/2,y:t.center.y+a/2}],capacity:t.capacity,categoryKey:t.categoryKey};return n.objects.push(c),{floorId:n.floorId,gaAreaId:c.id,label:r,createdIds:[c.id]}}function Li(e,t){if(k(e,t.categoryKey),!Number.isInteger(t.tableRows)||t.tableRows<1||t.tableRows>20||!Number.isInteger(t.tableColumns)||t.tableColumns<1||t.tableColumns>20)throw new u("invalid_operation","tableRows and tableColumns must be integers from 1 to 20");if(!Number.isInteger(t.seatsPerTable)||t.seatsPerTable<1||t.seatsPerTable>20)throw new u("invalid_operation","seatsPerTable must be an integer from 1 to 20");let n=t.gapX??155,o=t.gapY??150;if(!Number.isFinite(n)||n<80||!Number.isFinite(o)||o<80)throw new u("invalid_operation","Table spacing must be at least 80 chart units");if(!Number.isFinite(t.center.x)||!Number.isFinite(t.center.y))throw new u("invalid_operation","Table array center must be finite");let i=C(e,t.floorId),a=new Set,r=zn(e,"T"),c=[];for(let s=0;s<t.tableRows;s+=1)for(let l=0;l<t.tableColumns;l+=1)c.push({type:"table",id:M(e,"t",t.idFactory,a),label:r(),center:{x:t.center.x+(l-(t.tableColumns-1)/2)*n,y:t.center.y+(s-(t.tableRows-1)/2)*o},rotation:0,categoryKey:t.categoryKey,seatCount:t.seatsPerTable,...t.shape==="round"?{shape:"round",radius:46}:{shape:"rect",sides:["top","bottom"],width:120,height:58}});return i.objects.push(...c),{floorId:i.floorId,tableIds:c.map(s=>s.id),createdIds:c.map(s=>s.id)}}function Ei(e,t){if(k(e,t.categoryKey),!Number.isInteger(t.boothRows)||t.boothRows<1||t.boothRows>30||!Number.isInteger(t.boothColumns)||t.boothColumns<1||t.boothColumns>30)throw new u("invalid_operation","boothRows and boothColumns must be integers from 1 to 30");let n=t.gapX??88,o=t.gapY??82;if(!Number.isFinite(n)||n<62||!Number.isFinite(o)||o<52)throw new u("invalid_operation","Booth spacing must clear the 62\xD752 booth footprint");if(!Number.isFinite(t.center.x)||!Number.isFinite(t.center.y))throw new u("invalid_operation","Booth array center must be finite");let i=C(e,t.floorId),a=new Set,r=zn(e,"B"),c=[];for(let s=0;s<t.boothRows;s+=1)for(let l=0;l<t.boothColumns;l+=1)c.push({type:"booth",id:M(e,"booth",t.idFactory,a),label:r(),center:{x:t.center.x+(l-(t.boothColumns-1)/2)*n,y:t.center.y+(s-(t.boothRows-1)/2)*o},width:62,height:52,rotation:0,categoryKey:t.categoryKey});return i.objects.push(...c),{floorId:i.floorId,boothIds:c.map(s=>s.id),createdIds:c.map(s=>s.id)}}function Ti(e,t){let n=C(e,t.floorId),o=[...new Set(t.rowIds)];if(o.length<2||o.length>64)throw new u("invalid_operation","A segmented row requires 2 to 64 ordered component rows");if(t.boundaries.length!==o.length-1||t.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=o.map(h=>n.objects.find(f=>f.type==="row"&&f.id===h)),a=o.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 r=i,c=r.filter(h=>h.segmentedRow);if(c.length)throw new u("invalid_operation","Ungroup existing segmented rows before combining their components again",{rowIds:c.map(h=>h.id)});let s=(t.displayLabel??r[0].displayLabel??r[0].label).normalize("NFKC").trim();if(!s||s.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=t.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=r[0];return r.forEach((h,f)=>{h.segmentedRow={kind:"segmented-row-v1",groupId:d,componentIndex:f,componentCount:r.length,boundaryBefore:f===0?"start":t.boundaries[f-1],displayLabel:s,...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:o,changed:!0}}function Fi(e,t){let n=C(e,t.floorId),o=t.groupId?n.objects.find(c=>c.type==="row"&&c.segmentedRow?.groupId===t.groupId):n.objects.find(c=>c.type==="row"&&c.id===t.rowId),i=t.groupId??o?.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(c=>c.type==="row"&&c.segmentedRow?.groupId===i);if(!a.length)throw new u("object_not_found","The segmented row does not exist on the selected floor");let r=a.sort((c,s)=>c.segmentedRow.componentIndex-s.segmentedRow.componentIndex).map(c=>c.id);for(let c of a)delete c.segmentedRow;return{floorId:n.floorId,groupId:i,rowIds:r,changed:!0}}function Ni(e,t){let n=C(e,t.floorId),o=n.objects.filter(r=>r.type==="row"&&r.segmentedRow?.groupId===t.groupId).sort((r,c)=>r.segmentedRow.componentIndex-c.segmentedRow.componentIndex);if(o.length<2)throw new u("object_not_found","The segmented row is incomplete or missing on the selected floor");if(t.boundaries&&(t.boundaries.length!==o.length-1||t.boundaries.some(r=>r!=="continuous"&&r!=="break")))throw new u("invalid_operation","Declare one continuous or break boundary between every pair of row components");let i=t.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(o.map(r=>r.segmentedRow));return o.forEach((r,c)=>{let s=r.segmentedRow,l=s.viewFromSeatUrl;i!==void 0&&(s.displayLabel=i),t.boundaries&&c>0&&(s.boundaryBefore=t.boundaries[c-1]),t.smoothing!==void 0&&(s.smoothing=t.smoothing||void 0),t.viewFromSeatUrl===null?delete s.viewFromSeatUrl:t.viewFromSeatUrl!==void 0&&(s.viewFromSeatUrl=t.viewFromSeatUrl),!s.viewFromSeatUrl||t.viewFromSeatMeta===null?delete s.viewFromSeatMeta:t.viewFromSeatMeta!==void 0?s.viewFromSeatMeta=structuredClone(t.viewFromSeatMeta):t.viewFromSeatUrl!==void 0&&s.viewFromSeatUrl!==l&&delete s.viewFromSeatMeta}),{floorId:n.floorId,groupId:t.groupId,rowIds:o.map(r=>r.id),changed:JSON.stringify(o.map(r=>r.segmentedRow))!==a}}function Di(e,t){let n=C(e,t.floorId),o=n.objects.filter(O=>O.type==="row"&&O.rowBlockGeneration?.groupId===t.groupId).sort((O,$)=>O.rowBlockGeneration.rowIndex-$.rowBlockGeneration.rowIndex),i=o[0]?.rowBlockGeneration;if(!i||o.length!==i.rowCount||o.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:t.groupId});let a=JSON.stringify(o),r=t.style??i.style,c=t.rowCount??i.rowCount,s=t.seatsPerRow??i.seatsPerRow,l=t.rowGap??i.rowGap,d=t.seatSpacing??i.seatSpacing,g=t.curve??i.curve,h=Number.isFinite(t.rotation??i.rotation)?wt(t.rotation??i.rotation):t.rotation??i.rotation,f=t.origin?{...t.origin}:{...i.origin};if(!Number.isInteger(c)||c<1||c>100)throw new u("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(s)||s<1||s>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=$n({style:r,origin:f,rotation:h,rowCount:c,seatsPerRow:s,rowGap:l,seatSpacing:d,curve:g}),m={x:Math.cos(h*q),y:Math.sin(h*q)},x={x:-m.y,y:m.x},I=new Map(o.map(O=>[O.rowBlockGeneration.rowIndex,O])),p=new Set,y=new Set(n.objects.filter(O=>O.type==="row").filter(O=>!o.includes(O)).map(O=>O.label)),w=n.objects.filter(O=>O.type==="row").length,v=()=>{for(;y.has(B(w));)w+=1;let O=B(w);return y.add(O),w+=1,O},S=[],_=[];for(let O=0;O<c;O+=1){let $=r==="intertwined"&&O%2===1?d/2:0,j=I.get(O);j||(j={type:"row",id:M(e,"r",t.idFactory,p),label:v(),origin:{...f},rotation:h,curve:g,seatCount:s,seatSpacing:d,categoryKey:o[0].categoryKey},_.push(j.id)),j.origin={x:f.x+x.x*O*l+m.x*$,y:f.y+x.y*O*l+m.y*$},j.rotation=h,j.curve=g,j.seatCount=s,j.seatSpacing=d,delete j.path,delete j.arcFanGeneration,j.overrides&&(j.overrides=j.overrides.filter(et=>et.index<s),j.overrides.length||delete j.overrides),j.rowBlockGeneration={kind:"row-block-v1",groupId:t.groupId,style:r,rowIndex:O,rowCount:c,seatsPerRow:s,origin:{...f},rotation:h,rowGap:l,seatSpacing:d,curve:g,signature:b},S.push(j)}let G=o.slice(c).map(O=>O.id),F=Math.min(...o.map(O=>n.objects.indexOf(O))),U=new Set(o.map(O=>O.id)),K=n.objects.filter(O=>!U.has(O.id));return K.splice(F,0,...S),n.objects.splice(0,n.objects.length,...K),{floorId:n.floorId,groupId:t.groupId,rowIds:S.map(O=>O.id),createdRowIds:_,removedRowIds:G,changed:a!==JSON.stringify(S)||_.length>0||G.length>0}}var Gi=300,Ki=40;function $i(e){let t=new Set(H(e).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(i=>typeof i=="string")),n=0,o=()=>{for(;t.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,Ki).trim(),r=0;return()=>{for(;a&&r<4096;r+=1){let s=`${a}-${B(r)}`;if(!t.has(s))return t.add(s),r+=1,s}let c=o();return t.add(c),c}}}function zi(e,t){return e.filter(n=>(n.type==="row"||n.type==="table"||n.type==="booth"||n.type==="gaArea")&&!(n.type==="row"&&n.referenceScan?.assetId===t))}function Bi(e,t,n,o,i){let a=e.sectionId?t.find(s=>s.type==="section"&&s.id===e.sectionId):void 0;if(a){let s=zi(t,n).filter(l=>D(L(l),a.outline,a.holes));if(s.length)return{skip:{sectionId:a.id,name:e.name,reason:"section_not_empty",objectIds:s.map(l=>l.id)},rows:[],seats:0}}let r=[],c=0;for(let s of e.rows){let l=Math.min(Gi,Math.max(1,Math.round(s.seatCount)));if(!Number.isFinite(l)||l<1)continue;let d=s.end.x-s.start.x,g=s.end.y-s.start.y,h=Math.hypot(d,g),f=l>1&&h>0?h/(l-1):o>0?o:24;if(!Number.isFinite(f)||f<=0)continue;let b=h>0?Math.atan2(g,d)*180/Math.PI:0;r.push({label:i(),origin:{x:s.start.x,y:s.start.y},rotation:b,seatCount:l,seatSpacing:f}),c+=l}return{skip:null,rows:r,seats:c}}function Ui(e,t,n){k(e,n.categoryKey);let o=C(e,n.floorId),i=t.assetId,a=[],r=o.objects.filter(f=>f.type==="row"&&f.referenceScan?.assetId===i?(a.push(f.id),!1):!0);o.objects.splice(0,o.objects.length,...r);let c=[],s=[],l=[],d=new Set,g=0,h=$i(e);for(let f of t.sections){let b=Bi(f,o.objects,i,t.seatPitch,h(f.name));if(b.skip){s.push(b.skip);continue}let m=b.rows.map(x=>({type:"row",id:M(e,"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}));o.objects.push(...m);for(let x of m)l.push(x.id);c.push({sectionId:f.sectionId,name:f.name,seats:b.seats,rows:m.length}),g+=b.seats}return{floorId:o.floorId,assetId:i,createdRowIds:l,removedRowIds:a,totalSeats:g,perSection:c,skipped:s}}function Un(e,t){let n=C(e,t.floorId),o=[...new Set(t.objectIds)];if(!o.length)throw new u("invalid_operation","Select at least one table or booth to repeat");let i=o.map(f=>n.objects.find(b=>(b.type==="table"||b.type==="booth")&&b.id===f)),a=o.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 r=i[0].type;if(i.some(f=>f.type!==r))throw new u("invalid_operation","A grid array must contain only tables or only booths");for(let[f,b,m]of[["rows",t.rows,30],["columns",t.columns,30]])if(!Number.isInteger(b)||b<1||b>m)throw new u("invalid_operation",`${f} must be a whole number from 1 to ${m}`);for(let[f,b]of[["stepX",t.stepX],["stepY",t.stepY]])if(!Number.isFinite(b)||b<30||b>2e3)throw new u("invalid_operation",`${f} must be from 30 to 2000 chart units`);let c=t.rows*t.columns;if(c<2)throw new u("invalid_operation","Choose at least two grid cells");let s=o.length*(c-1);if(s>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=(e.floors?.length?e.floors.flatMap(f=>f.objects):e.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*(c-1);if(g+h>le)throw new u("invalid_operation",`Grid inventory would exceed the ${le} unit event limit`);return{target:n,sources:i,preview:{floorId:n.floorId,kind:r,sourceIds:o,sourceCount:o.length,cells:c,createdCount:s,addedInventory:h,resultingInventory:g+h,provenanceRemovedCount:i.filter(f=>!!f.referenceInventorySource).length*(c-1)}}}function Hi(e,t){return Un(e,t).preview}function Vi(e,t){let{target:n,sources:o,preview:i}=Un(e,t),a=new Set,r=new Set((e.floors?.length?e.floors.flatMap(d=>d.objects):e.objects).flatMap(d=>"label"in d&&d.label?[d.label]:[])),c=[],s=(d,g)=>{let h=Math.max(2,g),f=m=>{let x=`-${m}`;return`${d.slice(0,Math.max(1,80-x.length))}${x}`},b=f(h);for(;r.has(b);)b=f(++h);return r.add(b),b},l=1;for(let d=0;d<t.rows;d++)for(let g=0;g<t.columns;g++)if(!(d===0&&g===0)){l+=1;for(let h of o){let f=structuredClone(h);f.id=M(e,f.type,t.idFactory,a),f.label=s(h.label,l),f.center={x:h.center.x+g*t.stepX,y:h.center.y+d*t.stepY},delete f.referenceInventorySource,c.push(f)}}return n.objects.push(...c),{...i,createdIds:c.map(d=>d.id)}}function Ji(e,t){let n=e?{...e}:{};return t.size===null?delete n.size:t.size!==void 0&&(n.size=t.size),t.color===null?delete n.color:t.color!==void 0&&(n.color=T(t.color,"Seat label color")),n.size===void 0&&n.color===void 0?void 0:n}var qi=new Set(pe.map(e=>e.key));function Ie(e){return`${e.rowId}:${e.index}`}function Xi(e){let t=e.lastIndexOf(":"),n=t>0?e.slice(0,t):"",o=t>0?Number(e.slice(t+1)):Number.NaN;if(!n||!Number.isInteger(o)||o<0)throw new u("invalid_operation",`Invalid stable seat id: ${e}`,{seatId:e});return{rowId:n,index:o}}function Qi(e){if(e.label||delete e.label,e.displayLabel||delete e.displayLabel,e.dx||delete e.dx,e.dy||delete e.dy,e.skip||delete e.skip,e.categoryKey||delete e.categoryKey,ve(e.glyph)||delete e.glyph,e.accessible&&!e.accessibility?.length&&(e.accessibility=["wheelchair"]),delete e.accessible,e.wheelchairSpaceType&&!e.accessibility?.includes("wheelchair")&&(e.accessibility=["wheelchair",...e.accessibility??[]]),e.accessibility?.length||delete e.accessibility,e.commercial){let t=e.commercial.note?.normalize("NFKC").trim(),n={};typeof e.commercial.restrictedView=="boolean"&&(n.restrictedView=e.commercial.restrictedView),typeof e.commercial.obstructedView=="boolean"&&(n.obstructedView=e.commercial.obstructedView),typeof e.commercial.premium=="boolean"&&(n.premium=e.commercial.premium),t&&(n.note=t),Object.keys(n).length?e.commercial=n:delete e.commercial}e.viewFromSeatUrl||(delete e.viewFromSeatUrl,delete e.viewFromSeatMeta),e.labelStyle&&e.labelStyle.size===void 0&&e.labelStyle.color===void 0&&delete e.labelStyle}function Yi(e){return Object.keys(e).every(t=>t==="index")}function Hn(e,t,n){if(!n.length)throw new u("invalid_operation","At least one seat is required");let o=C(e,t),i=[],a=new Set,r=new Map;for(let c of n){let s=Ie(c);if(a.has(s))continue;a.add(s);let l=o.objects.find(d=>(d.type==="row"||d.type==="table")&&d.id===c.rowId);if(!l)throw new u("object_not_found",`Unknown row or table for seat: ${s}`,{seatId:s,objectId:c.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:s,tableId:l.id});if(!Number.isInteger(c.index)||c.index<0||c.index>=l.seatCount)throw new u("invalid_operation",l.type==="row"?`Seat index is outside row bounds: ${s}`:`Chair index is outside table bounds: ${s}`,{seatId:s,objectId:c.rowId,index:c.index,seatCount:l.seatCount});i.push({rowId:c.rowId,index:c.index}),r.set(l.id,l)}return{floorId:o.floorId,refs:i,owners:r}}function Pt(e,t){let n=Hn(e,t.floorId,t.seats),o=Object.keys(t.patch);if(!o.length&&t.labelPrefix===void 0&&t.displayLabelPrefix===void 0)throw new u("invalid_operation","At least one seat override field is required");if(t.labelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(t.patch,"label"))throw new u("invalid_operation","Use either label or labelPrefix, not both");if(t.displayLabelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(t.patch,"displayLabel"))throw new u("invalid_operation","Use either displayLabel or displayLabelPrefix, not both");if(n.refs.length>1&&t.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&&t.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(t.patch.categoryKey&&k(e,t.patch.categoryKey),t.patch.glyph!=null&&!ve(t.patch.glyph))throw new u("invalid_operation","Unknown seat glyph",{glyph:t.patch.glyph});if(t.patch.accessibility){let a=t.patch.accessibility.filter(r=>!qi.has(r));if(a.length)throw new u("invalid_operation","Unknown accessibility type",{accessibility:a})}if(t.patch.wheelchairSpaceType!==void 0&&t.patch.wheelchairSpaceType!==null&&t.patch.wheelchairSpaceType!=="seat-present"&&t.patch.wheelchairSpaceType!=="no-seat")throw new u("invalid_operation","wheelchairSpaceType must be seat-present, no-seat, or null");if(t.patch.wheelchairSpaceType&&t.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 r=n.owners.get(a.rowId)?.overrides?.find(l=>l.index===a.index),c=t.patch.wheelchairSpaceType===null?void 0:t.patch.wheelchairSpaceType??r?.wheelchairSpaceType,s=t.patch.skip===null?!1:t.patch.skip??r?.skip??!1;if(c&&s)throw new u("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory",{seatId:Ie(a)})}if(t.patch.commercial?.note&&t.patch.commercial.note.normalize("NFKC").trim().length>160)throw new u("invalid_operation","Commercial note supports at most 160 characters");if(t.patch.viewFromSeatUrl!=null){let a=Y(t.patch.viewFromSeatUrl);if(!a)throw new u("invalid_operation","Seat view photo must be a safe HTTPS or base64 raster image reference");t.patch.viewFromSeatUrl=a}for(let a of["dx","dy"]){let r=t.patch[a];if(r!=null&&!Number.isFinite(r))throw new u("invalid_operation",`${a} must be finite`,{[a]:r})}t.patch.labelStyle!=null&&ce(t.patch.labelStyle,"Seat");let i=!1;return n.refs.forEach((a,r)=>{let c=n.owners.get(a.rowId),s=JSON.stringify(c.overrides??[]),l=c.overrides??(c.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 o){let f=t.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=Ji(d.labelStyle,f);b?d.labelStyle=b:delete d.labelStyle}else Object.assign(d,{[h]:f})}t.patch.viewFromSeatMeta===void 0&&t.patch.viewFromSeatUrl!==void 0&&d.viewFromSeatUrl!==g&&delete d.viewFromSeatMeta,t.labelPrefix!==void 0&&(d.label=`${t.labelPrefix}${r+1}`),t.displayLabelPrefix!==void 0&&(d.displayLabel=`${t.displayLabelPrefix}${r+1}`),Qi(d),Yi(d)&&(c.overrides=l.filter(h=>h!==d)),c.overrides?.length||delete c.overrides,JSON.stringify(c.overrides??[])!==s&&(i=!0)}),{floorId:n.floorId,changed:i,seatIds:n.refs.map(Ie)}}function Zi(e,t){let n=Hn(e,t.floorId,t.seats),o=!1;for(let[i,a]of n.owners){if(!a.overrides?.length)continue;let r=new Set(n.refs.filter(s=>s.rowId===i).map(s=>s.index)),c=a.overrides.filter(s=>!r.has(s.index));c.length!==a.overrides.length&&(o=!0),a.overrides=c,a.overrides.length||delete a.overrides}return{floorId:n.floorId,changed:o,seatIds:n.refs.map(Ie)}}function Wi(e,t){let n=C(e,t.floorId),o=[...new Set(t.rowIds)],i=o.map(p=>n.objects.find(y=>y.type==="row"&&y.id===p)),a=o.filter((p,y)=>!i[y]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});if(t.patch.categoryKey!==void 0&&k(e,t.patch.categoryKey),t.patch.seatCount!==void 0&&(!Number.isInteger(t.patch.seatCount)||t.patch.seatCount<1||t.patch.seatCount>300))throw new u("invalid_operation","seatCount must be an integer from 1 to 300");if(t.patch.seatNumbering!==void 0){let p=t.patch.seatNumbering,y=["decimal","odd","even","updown","updown-descending","roman","letters-upper","letters-lower"];if(p.scheme!==void 0&&!y.includes(p.scheme))throw new u("invalid_operation",`Unknown seat numbering scheme: ${p.scheme}. Expected one of ${y.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:r,labelPosition:c,labelRotation:s,labelStyleShape:l,displayLabel:d,displayType:g,...h}=t.patch,f=d===void 0?{}:{displayLabel:d},b=se(f,"Row"),m=g===void 0?void 0:gt(g,"Row");if(r!==void 0&&ce(r,"Row"),c!==void 0&&!["start","end","both","none"].includes(c))throw new u("invalid_operation","Row labelPosition must be one of start, end, both, none");if(s!=null&&(!Number.isFinite(s)||s<-180||s>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&&Le(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}),I=!1;for(let p of i){let y=JSON.stringify(p),w=x(p),v=t.preserveCenterOnSeatCountChange&&t.patch.seatCount!==void 0?L(p):null;if(Object.assign(p,structuredClone(h)),p.overrides&&t.patch.seatCount!==void 0&&(p.overrides=p.overrides.filter(S=>S.index<p.seatCount),p.overrides.length||(p.overrides=void 0)),v){let S=L(p);p.origin={x:p.origin.x+v.x-S.x,y:p.origin.y+v.y-S.y}}if(JSON.stringify(p)!==y&&(I=!0),x(p)!==w&&(delete p.arcFanGeneration,delete p.rowBlockGeneration),r!==void 0){let S=JSON.stringify(p.labelPresentation??null),_=Ee(p.labelPresentation,r);_?p.labelPresentation=_:delete p.labelPresentation,JSON.stringify(p.labelPresentation??null)!==S&&(I=!0)}if(c!==void 0){let S=JSON.stringify(p.labelPresentation??null),_=p.labelPresentation?structuredClone(p.labelPresentation):{};_.positionPreset=c,_.visible=c!=="none",delete _.position,p.labelPresentation=_,JSON.stringify(p.labelPresentation??null)!==S&&(I=!0)}if(s!==void 0||l!==void 0){let S=JSON.stringify(p.labelPresentation??null),_=p.labelPresentation?structuredClone(p.labelPresentation):{};s===null?delete _.rotation:s!==void 0&&(_.rotation=s),l!==void 0&&(_.style=l),p.labelPresentation=_,JSON.stringify(p.labelPresentation??null)!==S&&(I=!0)}if(m!==void 0){let S=p.displayType;m?p.displayType=m:delete p.displayType,p.displayType!==S&&(I=!0)}if(d!==void 0){let S=p.displayLabel;b?delete p.displayLabel:p.displayLabel=f.displayLabel,p.displayLabel!==S&&(I=!0)}}return{floorId:n.floorId,changed:I,rowIds:o}}var ea=3;function Je(e){return(e%360+360)%360}function ta(e){let t=e.rotation*q;return{x:Math.cos(t),y:Math.sin(t)}}function na(e,t){let n=Math.abs(Je(e-t));return n>180&&(n=360-n),n}function de(e,t,n){return(e.x-t.x)*n.x+(e.y-t.y)*n.y}function Vn(e){let t=0,n=0;for(let i of e){let a=2*i.rotation*q;t+=Math.cos(a),n+=Math.sin(a)}let o=(t===0&&n===0?0:Math.atan2(n,t))/2;return{x:Math.cos(o),y:Math.sin(o)}}function oa(e,t,n){if(e.origin={x:e.origin.x+t,y:e.origin.y+n},e.path){let o=i=>({x:i.x+t,y:i.y+n});e.path={start:o(e.path.start),control1:o(e.path.control1),control2:o(e.path.control2),end:o(e.path.end)}}}function Jn(e,t){let n=Vn(e),o={x:-n.y,y:n.x},i=L(e[0]),a=e.map(s=>({row:s,coord:de(L(s),i,o)})).sort((s,l)=>s.coord-l.coord),r=a[0].coord,c=!1;return a.forEach((s,l)=>{let d=r+l*t-s.coord;Math.abs(d)>1e-6&&(oa(s.row,o.x*d,o.y*d),delete s.row.arcFanGeneration,delete s.row.rowBlockGeneration,c=!0)}),c}function ra(e,t){let n={x:-t.y,y:t.x},o=L(e[0]),i=e.map(r=>de(L(r),o,n)).sort((r,c)=>r-c);if(i.length<2)return 28;let a=(i[i.length-1]-i[0])/(i.length-1);return a>.5?a:28}function ia(e){if(e.seatCount<2){e.curve=0,delete e.path,delete e.arcFanGeneration,delete e.rowBlockGeneration;return}let t=be(e),n=t[0],o=t[t.length-1],i=o.x-n.x,a=o.y-n.y,r=Math.hypot(i,a);e.path&&(e.origin={...n},e.seatSpacing=Math.max(1,r/(e.seatCount-1))),r>1e-6&&(e.rotation=Je(Math.atan2(a,i)/q)),e.curve=0,delete e.path,delete e.arcFanGeneration,delete e.rowBlockGeneration}function aa(e,t){let n=new Set(e.filter(o=>o.type==="row").map(o=>o.label));for(let o=2;o<1e4;o++){let i=`${t}${o}`.slice(0,80);if(!n.has(i))return i}return`${t}-${Date.now().toString(36)}`}function sa(e,t){let n=C(e,t.floorId),o=[...new Set(t.rowIds)];if(o.length<2)throw new u("invalid_operation","Select at least two rows to merge");let i=o.map(v=>n.objects.find(S=>S.type==="row"&&S.id===v)),a=o.filter((v,S)=>!i[S]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let r=i,c=r.filter(v=>v.path||v.curve!==0);if(c.length)throw new u("invalid_operation","Only straight rows can be merged \u2014 straighten the rows first, then merge.",{rowIds:c.map(v=>v.id)});let s=r[0],l=r.find(v=>na(v.rotation,s.rotation)>ea);if(l)throw new u("invalid_operation","Rows must be parallel to merge \u2014 they point in different directions.",{rowIds:[s.id,l.id]});let d=ta(s),g={x:-d.y,y:d.x},h=Math.max(8,s.seatSpacing*.6),f=r.find(v=>Math.abs(de(v.origin,s.origin,g))>h);if(f){let v=Math.round(Math.abs(de(f.origin,s.origin,g)));throw new u("invalid_operation",`Rows must lie on the same line to merge \u2014 a selected row is offset ${v} units from the first.`,{rowIds:[s.id,f.id]})}let b=r.slice().sort((v,S)=>de(v.origin,s.origin,d)-de(S.origin,s.origin,d)),m=b.reduce((v,S)=>v+S.seatCount,0);if(m>300)throw new u("invalid_operation",`A merged row would have ${m} seats, over the 300-seat row limit. Merge fewer rows.`);let x=b[0],I=[],p=0;for(let v of b){if(v.overrides)for(let S of v.overrides)I.push({...structuredClone(S),index:S.index+p});p+=v.seatCount}x.seatCount=m,x.curve=0,delete x.path,I.length?x.overrides=I:delete x.overrides,delete x.arcFanGeneration,delete x.rowBlockGeneration;let y=b.slice(1).map(v=>v.id),w=new Set(y);for(let v=n.objects.length-1;v>=0;v--)w.has(n.objects[v].id)&&n.objects.splice(v,1);return{floorId:n.floorId,changed:!0,rowId:x.id,removedRowIds:y,seatCount:m}}function ca(e,t){let n=C(e,t.floorId),o=n.objects.find(f=>f.type==="row"&&f.id===t.rowId);if(!o)throw new u("object_not_found","The row id does not exist on the selected floor",{rowIds:[t.rowId]});if(o.path)throw new u("invalid_operation","Cannot split a free-form curved row \u2014 straighten it first, then split.",{rowIds:[o.id]});let i=o.seatCount,a=t.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 r=be(o),c=i>1?o.curve/(i-1):0,s=i-a,l={type:"row",id:M(e,"r",t.idFactory,new Set),label:aa(n.objects,o.label),origin:{...r[a]},rotation:Je(o.rotation-c*a),curve:c*(s-1),seatCount:s,seatSpacing:o.seatSpacing,categoryKey:o.categoryKey};if(o.seatNumbering&&(l.seatNumbering=structuredClone(o.seatNumbering)),o.seatLabelStart!=null&&(l.seatLabelStart=o.seatLabelStart),o.commercial&&(l.commercial=structuredClone(o.commercial)),o.viewFromSeatUrl&&(l.viewFromSeatUrl=o.viewFromSeatUrl),o.viewFromSeatMeta&&(l.viewFromSeatMeta=structuredClone(o.viewFromSeatMeta)),o.confidenceEvidence&&(l.confidenceEvidence=structuredClone(o.confidenceEvidence)),o.labelPresentation){let f=structuredClone(o.labelPresentation);delete f.position,l.labelPresentation=f}let d=[],g=[];if(o.overrides)for(let f of o.overrides)f.index<a?d.push(structuredClone(f)):g.push({...structuredClone(f),index:f.index-a});o.seatCount=a,o.curve=c*(a-1),d.length?o.overrides=d:delete o.overrides,delete o.arcFanGeneration,delete o.rowBlockGeneration,g.length&&(l.overrides=g);let h=n.objects.indexOf(o);return n.objects.splice(h+1,0,l),{floorId:n.floorId,changed:!0,rowId:o.id,newRowId:l.id,firstSeatCount:a,secondSeatCount:s,newLabel:l.label}}function la(e,t){let n=C(e,t.floorId),o=[...new Set(t.rowIds)];if(o.length<2)throw new u("invalid_operation","Select at least two rows to set row spacing");if(!Number.isFinite(t.gap)||t.gap<=0||t.gap>4e3)throw new u("invalid_operation","Row spacing must be a positive value up to 4000 chart units");let i=o.map(c=>n.objects.find(s=>s.type==="row"&&s.id===c)),a=o.filter((c,s)=>!i[s]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let r=Jn(i,t.gap);return{floorId:n.floorId,changed:r,rowIds:o,gap:t.gap}}function da(e,t){let n=C(e,t.floorId),o=[...new Set(t.rowIds)];if(o.length<2)throw new u("invalid_operation","Select at least two rows to straighten and space evenly");let i=o.map(h=>n.objects.find(f=>f.type==="row"&&f.id===h)),a=o.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 r=i,c=()=>JSON.stringify(r.map(h=>[h.origin,h.rotation,h.curve,h.path??null,h.seatSpacing])),s=c();for(let h of r)ia(h);let l=Vn(r),d=Je(Math.atan2(l.y,l.x)/q);for(let h of r)h.rotation=d;let g=ra(r,l);return Jn(r,g),{floorId:n.floorId,changed:c()!==s,rowIds:o,gap:g}}var Xe=So(require("polygon-clipping"),1),qn=100,Xn=512,Ot=8192,oo=64,Qn=1e7,R=1e-7;function ro(e,t){return Math.abs(e.x-t.x)<=R&&Math.abs(e.y-t.y)<=R}function io(e){let t=e.map(n=>({x:n.x,y:n.y}));for(;t.length>1&&ro(t[0],t[t.length-1]);)t.pop();return t}function Ce(e,t,n){let o=J(t,n,e);return Math.abs(o)>R?!1:e.x>=Math.min(t.x,n.x)-R&&e.x<=Math.max(t.x,n.x)+R&&e.y>=Math.min(t.y,n.y)-R&&e.y<=Math.max(t.y,n.y)+R}function ao(e,t,n,o){let i=J(e,t,n),a=J(e,t,o),r=J(n,o,e),c=J(n,o,t);return(i>R&&a<-R||i<-R&&a>R)&&(r>R&&c<-R||r<-R&&c>R)?!0:Math.abs(i)<=R&&Ce(n,e,t)||Math.abs(a)<=R&&Ce(o,e,t)||Math.abs(r)<=R&&Ce(e,n,o)||Math.abs(c)<=R&&Ce(t,n,o)}function ua(e){for(let t=0;t<e.length;t+=1){let n=(t+1)%e.length;for(let o=t+1;o<e.length;o+=1){let i=(o+1)%e.length;if(!(t===o||n===o||i===t)&&ao(e[t],e[n],e[o],e[i]))return!0}}return!1}function Yn(e,t){return e.some((n,o)=>t.some((i,a)=>ao(n,e[(o+1)%e.length],i,t[(a+1)%t.length])))}function _t(e,t){return!t.some((n,o)=>Ce(e,n,t[(o+1)%t.length]))&&D(e,t,void 0)}function Qe(e,t,n){let o=io(e);if(o.length<3||o.length>Xn||o.some((i,a)=>!Number.isFinite(i.x)||!Number.isFinite(i.y)||Math.abs(i.x)>Qn||Math.abs(i.y)>Qn||ro(i,o[(a+1)%o.length]))||Math.abs(he(o))<=R||ua(o))throw new u("invalid_operation",`GA area ${n} has an invalid or self-intersecting ${t}; Join Areas accepts 3\u2013${Xn} finite vertices per ring.`,{gaAreaId:n,ring:t});return o}function fa(e){let t=Qe(e.points,"outline",e.id),n=e.holes??[];if(!Array.isArray(n)||n.length>oo)throw new u("invalid_operation",`GA area ${e.id} has too many cutouts to join`,{gaAreaId:e.id});let o=n.map(i=>Qe(i,"cutout",e.id));for(let i=0;i<o.length;i+=1){let a=o[i];if(!a.flatMap((c,s)=>{let l=a[(s+1)%a.length];return[c,{x:(c.x+l.x)/2,y:(c.y+l.y)/2}]}).every(c=>_t(c,t))||Yn(a,t))throw new u("invalid_operation",`GA area ${e.id} has a cutout outside its outline`,{gaAreaId:e.id,holeIndex:i});for(let c=i+1;c<o.length;c+=1)if(Yn(a,o[c])||_t(a[0],o[c])||_t(o[c][0],a))throw new u("invalid_operation",`GA area ${e.id} has overlapping cutouts`,{gaAreaId:e.id,holeIndex:i})}return{outer:t,holes:o}}function qe(e){return e.map(t=>[t.x,t.y])}function Zn(e){return io(e.map(([t,n])=>({x:t,y:n})))}function Wn(e){return Math.abs(e.reduce((t,n,o)=>{let i=e[(o+1)%e.length];return t+n[0]*i[1]-i[0]*n[1]},0))/2}function ga(e){return e.reduce((t,n)=>t+(Wn(n[0]??[])-n.slice(1).reduce((o,i)=>o+Wn(i),0)),0)}function At(e){if(e===void 0)return"undefined";if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(At).join(",")}]`;let t=e;return`{${Object.keys(t).sort().map(n=>`${JSON.stringify(n)}:${At(t[n])}`).join(",")}}`}function eo(e,t,n){let o=e[t];if(o===void 0)return null;let i=o.normalize("NFKC").trim();if(!i||i!==o||i.length>n)throw new u("invalid_operation",`GA area ${e.id} has an invalid ${t}; normalize it to 1\u2013${n} characters before joining.`,{gaAreaId:e.id,field:t});return i}function to(e){return At({categoryKey:e.categoryKey,displayLabel:eo(e,"displayLabel",80),displayType:eo(e,"displayType",24),referenceInventorySource:e.referenceInventorySource??null})}function no(e,t){let n=Math.min(...e.points.map(i=>i.y)),o=Math.min(...e.points.map(i=>i.x));return[n,o,t]}function ha(e,t){return e[0]-t[0]||e[1]-t[1]||e[2]-t[2]}function so(e,t){let n=C(e,t.floorId),o=[...new Set(t.gaAreaIds)];if(o.length<2)throw new u("invalid_operation","Select at least two GA areas to join");if(o.length>qn)throw new u("invalid_operation",`Join Areas supports at most ${qn} areas at once`);let i=o.map(P=>n.objects.find(A=>A.type==="gaArea"&&A.id===P)),a=o.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 r=i;k(e,r[0].categoryKey);let c=to(r[0]),s=r.find(P=>to(P)!==c);if(s)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:[r[0].id,s.id]});let l=me(e).objectToSection,d=l.get(r[0].id)??"__ungrouped__",g=r.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:[r[0].id,g.id],sectionIds:[d,l.get(g.id)??"__ungrouped__"]});let h=r.reduce((P,A)=>{if(!Number.isInteger(A.capacity)||A.capacity<1||A.capacity>te)throw new u("invalid_operation",`GA area ${A.id} has invalid capacity`,{gaAreaId:A.id});return P+A.capacity},0);if(h>te)throw new u("invalid_operation",`Joined GA capacity would be ${h}, over the ${te}-unit area limit`,{capacity:h});let f=H(e).reduce((P,A)=>P+ee(A),0);if(f>le)throw new u("invalid_operation",`Chart inventory exceeds the ${le}-unit publication limit`,{inventory:f});let b=r.map(fa),m=b.reduce((P,A)=>P+A.outer.length+A.holes.reduce((V,Q)=>V+Q.length,0),0);if(m>Ot)throw new u("invalid_operation",`Join Areas supports at most ${Ot} source vertices`,{vertexCount:m});let x;try{let P=b.map(Q=>[qe(Q.outer)]);if(x=Xe.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(tt=>[qe(tt)]));A.length&&(x=Xe.default.difference(x,...A));let V=b.findIndex(Q=>{let tt=[qe(Q.outer),...Q.holes.map(qe)];return ga(Xe.default.intersection(tt,x))<=R});if(V>=0)throw new u("invalid_operation",`GA area ${r[V].id} contributes no sellable surface after preserving every source cutout.`,{gaAreaId:r[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 I=Zn(x[0][0]),p=x[0].slice(1).map(Zn),y=I.length+p.reduce((P,A)=>P+A.length,0);if(p.length>oo||y>Ot)throw new u("invalid_operation","The joined boundary is too complex to store safely",{holeCount:p.length,vertexCount:y});Qe(I,"outline",r[0].id),p.forEach(P=>Qe(P,"cutout",r[0].id));let w=new Map(n.objects.map((P,A)=>[P.id,A])),v=r.slice().sort((P,A)=>ha(no(P,w.get(P.id)??Number.MAX_SAFE_INTEGER),no(A,w.get(A.id)??Number.MAX_SAFE_INTEGER))),S=v[0],_=structuredClone(e),G=C(_,n.floorId),F=G.objects.find(P=>P.type==="gaArea"&&P.id===S.id);F.points=structuredClone(I),p.length?F.holes=structuredClone(p):delete F.holes;let U=new Set(v.slice(1).map(P=>P.id));for(let P=G.objects.length-1;P>=0;P-=1)U.has(G.objects[P].id)&&G.objects.splice(P,1);let K=me(_).objectToSection.get(S.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:S.id,beforeSectionId:d,afterSectionId:K});let O=[],$=new Set;for(let P of v){if(!yt(P))throw new u("invalid_operation",`GA area ${P.id} has invalid inventory provenance and cannot be joined`,{gaAreaId:P.id});let A=ne(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(...De(P))}if(O.length>256)throw new u("invalid_operation","Joined inventory provenance would exceed 256 durable source ranges");let j=new Set(r.map(P=>P.id));for(let P of H(e).filter(A=>A.type==="gaArea"&&!j.has(A.id))){let A=ne(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 et=v.slice(1).map(P=>P.id);return{floorId:n.floorId,areaId:S.id,survivorLabel:S.label,removedAreaIds:et,sourceAreaCount:v.length,capacity:h,inventorySegmentCount:O.length,outerVertexCount:I.length,holeCount:p.length,sectionId:d,points:I,...p.length?{holes:p}:{},segments:O}}function ba(e,t){let{segments:n,...o}=so(e,t);return o}function pa(e,t){let n=so(e,t),o=C(e,n.floorId),i=o.objects.find(s=>s.type==="gaArea"&&s.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 s=o.objects.length-1;s>=0;s-=1)a.has(o.objects[s].id)&&o.objects.splice(s,1);let{segments:r,...c}=n;return{...c,changed:!0}}var co=[{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 ya=Math.PI*2;function ma(e,t,n,o,i,a){return{x:i+e*n-t*o,y:a+e*o+t*n}}function lo(e){let{kind:t,cx:n,cy:o,width:i,height:a}=e,r=(e.rotation??0)*Math.PI/180,c=Math.cos(r),s=Math.sin(r),l=i/2,d=a/2,g=[],h=(f,b)=>{g.push({x:f,y:b})};switch(t){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,m=(x,I,p)=>{for(let y=0;y<=b;y++){let w=p+y/b*(Math.PI/2);h(x+f*Math.cos(w),I+f*Math.sin(w))}};m(l-f,-d+f,-Math.PI/2),m(l-f,d-f,0),m(-l+f,d-f,Math.PI/2),m(-l+f,-d+f,Math.PI);break}case"arc":{let f=a*.45;h(-l,-d),h(l,-d);let b=24;for(let m=0;m<=b;m++){let x=m/b,I=l-x*i,p=d+f*(1-Math.pow(2*I/i,2));h(I,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 m=b/40*ya;h(l*Math.cos(m),d*Math.sin(m))}break}case"pitch-football":{h(-l,-d),h(l,-d),h(l,d),h(-l,d);break}case"rink-hockey":{for(let f of wa(l,d,l*(8.5/60),d*(8.5/30)))h(f.x,f.y);break}case"track-athletics":{for(let f of xa(l,d))h(f.x,f.y);break}}return g.map(f=>ma(f.x,f.y,c,s,n,o))}function wa(e,t,n,o){let i=[],r=(c,s,l)=>{for(let d=0;d<=8;d++){let g=l+d/8*(Math.PI/2);i.push({x:c+n*Math.cos(g),y:s+o*Math.sin(g)})}};return r(e-n,-t+o,-Math.PI/2),r(e-n,t-o,0),r(-e+n,t-o,Math.PI/2),r(-e+n,-t+o,Math.PI),i}function xa(e,t){let n=Math.max(0,e-t),o=[],i=20;for(let a=0;a<=i;a++){let r=-Math.PI/2+a/i*Math.PI;o.push({x:n+t*Math.cos(r),y:t*Math.sin(r)})}for(let a=0;a<=i;a++){let r=Math.PI/2+a/i*Math.PI;o.push({x:-n+t*Math.cos(r),y:t*Math.sin(r)})}return o}function va(e,t){let n=C(e,t.floorId),o=[...new Set(t.shapeIds)];if(!o.length)throw new u("invalid_operation","At least one shape id is required");let i=o.map(l=>n.objects.find(d=>d.type==="shape"&&d.id===l)),a=o.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 r=structuredClone(t.patch);if(!Object.keys(r).length)throw new u("invalid_operation","At least one shape change is required");if(r.label!==void 0){if(o.length!==1)throw new u("invalid_operation","label can be changed only for one shape at a time");if(r.label!==null){if(r.label=r.label.normalize("NFKC").trim(),!r.label)r.label=null;else if(r.label.length>80)throw new u("invalid_operation","Shape labels support at most 80 characters")}}if(r.fill!==void 0&&r.fill!==null&&(r.fill=T(r.fill,"Shape fill")),r.kind!==void 0&&!["rect","ellipse","polygon","line","polyline"].includes(r.kind))throw new u("invalid_operation","Shape kind must be rect, ellipse, polygon, line, or polyline");if(r.stroke!==void 0&&r.stroke!==null){if(!Number.isFinite(r.stroke.width)||r.stroke.width<.5||r.stroke.width>40)throw new u("invalid_operation","Shape stroke width must be from 0.5 to 40 chart units");r.stroke={color:T(r.stroke.color,"Shape stroke"),width:r.stroke.width}}if(r.cornerRadius!==void 0&&r.cornerRadius!==null&&(!Number.isFinite(r.cornerRadius)||r.cornerRadius<0||r.cornerRadius>5e3))throw new u("invalid_operation","Shape cornerRadius must be from 0 to 5000 chart units");if(r.opacity!==void 0&&r.opacity!==null&&(!Number.isFinite(r.opacity)||r.opacity<.1||r.opacity>1))throw new u("invalid_operation","Shape opacity must be from 0.1 to 1");if(r.heightM!==void 0&&r.heightM!==null&&(!Number.isFinite(r.heightM)||r.heightM<.05||r.heightM>50))throw new u("invalid_operation","Shape heightM must be from 0.05 to 50 metres");if(r.eventConfigurationIds!==void 0&&r.eventConfigurationIds!==null){let l=r.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");r.eventConfigurationIds=l}if(r.lineCap!==void 0&&r.lineCap!==null&&!On.includes(r.lineCap))throw new u("invalid_operation","Shape lineCap must be butt, round, or square");if(r.lineJoin!==void 0&&r.lineJoin!==null&&!_n.includes(r.lineJoin))throw new u("invalid_operation","Shape lineJoin must be miter, round, or bevel");for(let[l,d]of[["startEnding",r.startEnding],["endEnding",r.endEnding]])if(d!=null&&!An.includes(d))throw new u("invalid_operation",`Shape ${l} must be none or arrow`);if(r.lineCap!=null||r.lineJoin!=null||r.startEnding!=null||r.endEnding!=null){let l=i.filter(d=>!St(r.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 s=!1;for(let l of i){let d=JSON.stringify(l);if(r.label===null?delete l.label:r.label!==void 0&&(l.label=r.label),r.fill===null?delete l.fill:r.fill!==void 0&&(l.fill=r.fill),r.kind!==void 0&&(l.kind=r.kind,St(l.kind)||(delete l.lineCap,delete l.lineJoin,delete l.startEnding,delete l.endEnding)),r.stroke===null?delete l.stroke:r.stroke!==void 0&&(l.stroke={...r.stroke}),r.opacity===null?delete l.opacity:r.opacity!==void 0&&(l.opacity=r.opacity),r.heightM===null?delete l.heightM:r.heightM!==void 0&&(l.heightM=r.heightM),r.eventConfigurationIds===null?delete l.eventConfigurationIds:r.eventConfigurationIds!==void 0&&(l.eventConfigurationIds=[...r.eventConfigurationIds]),r.lineCap===null?delete l.lineCap:r.lineCap!==void 0&&(l.lineCap=r.lineCap),r.lineJoin===null?delete l.lineJoin:r.lineJoin!==void 0&&(l.lineJoin=r.lineJoin),r.startEnding===null?delete l.startEnding:r.startEnding!==void 0&&(l.startEnding=r.startEnding),r.endEnding===null?delete l.endEnding:r.endEnding!==void 0&&(l.endEnding=r.endEnding),r.cornerRadius===null)delete l.cornerRadius;else if(r.cornerRadius!==void 0){let g=Math.min(l.width??1/0,l.height??1/0),h=Number.isFinite(g)?g/2:r.cornerRadius;l.cornerRadius=l.kind==="rect"?Math.max(0,Math.min(r.cornerRadius,h)):r.cornerRadius}JSON.stringify(l)!==d&&(s=!0)}return{floorId:n.floorId,changed:s,shapeIds:o}}function uo(e){if(e.x!=null&&e.y!=null&&e.width!=null&&e.height!=null){if(![e.x,e.y,e.width,e.height].every(Number.isFinite)||e.width<=0||e.height<=0)throw new u("invalid_operation",`Stage ${e.id} has an invalid stored base box`,{stageId:e.id});return{cx:e.x+e.width/2,cy:e.y+e.height/2,width:e.width,height:e.height}}let t=e.points??[];if(t.length<3||t.some(d=>!Number.isFinite(d.x)||!Number.isFinite(d.y)))throw new u("invalid_operation",`Stage ${e.id} has no valid geometry from which to derive its base box`,{stageId:e.id});let n=t.map(d=>d.x),o=t.map(d=>d.y),i=Math.min(...n),a=Math.max(...n),r=Math.min(...o),c=Math.max(...o),s=Math.max(1,a-i),l=Math.max(1,c-r);return{cx:i+s/2,cy:r+l/2,width:s,height:l}}function Sa(e,t){let n=C(e,t.floorId);if(!t.updates.length)throw new u("invalid_operation","At least one shape resize is required");let o=t.updates.map(r=>r.shapeId);if(new Set(o).size!==o.length)throw new u("invalid_operation","Shape ids must be unique");let i=t.updates.map(r=>{if(![r.width,r.height].every(Number.isFinite)||r.width<8||r.height<8||r.width>1e4||r.height>1e4)throw new u("invalid_operation","Shape width and height must be between 8 and 10000 chart units",{shapeId:r.shapeId});let c=n.objects.find(l=>l.type==="shape"&&l.id===r.shapeId);if(!c)throw new u("object_not_found",`Unknown shape id: ${r.shapeId}`,{shapeId:r.shapeId});let s=c.role==="stage"?uo(c):(c.kind==="rect"||c.kind==="ellipse")&&c.x!=null&&c.y!=null&&c.width!=null&&c.height!=null?{cx:c.x+c.width/2,cy:c.y+c.height/2,width:c.width,height:c.height}:(()=>{let l=c.points??[];if(l.length<3||l.some(x=>!Number.isFinite(x.x)||!Number.isFinite(x.y)))throw new u("invalid_operation",`Shape ${c.id} has no resizable geometry`,{shapeId:c.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),m=Math.max(...g);return{cx:(h+f)/2,cy:(b+m)/2,width:Math.max(1,f-h),height:Math.max(1,m-b)}})();return{shape:c,update:r,box:s}}),a=!1;for(let{shape:r,update:c,box:s}of i)if(!(Math.abs(s.width-c.width)<1e-9&&Math.abs(s.height-c.height)<1e-9)){if(r.kind==="rect"||r.kind==="ellipse")r.x=s.cx-c.width/2,r.y=s.cy-c.height/2,r.width=c.width,r.height=c.height;else{let l=c.width/s.width,d=c.height/s.height;r.points=(r.points??[]).map(g=>({x:s.cx+(g.x-s.cx)*l,y:s.cy+(g.y-s.cy)*d})),(r.x!=null||r.y!=null||r.width!=null||r.height!=null||r.role==="stage")&&(r.x=s.cx-c.width/2,r.y=s.cy-c.height/2,r.width=c.width,r.height=c.height)}a=!0}return{floorId:n.floorId,changed:a,shapes:i.map(({shape:r,update:c})=>({id:r.id,width:c.width,height:c.height}))}}function Ia(e,t){let n=C(e,t.floorId);if(!t.updates.length)throw new u("invalid_operation","At least one stage update is required");let o=t.updates.map(c=>c.stageId);if(new Set(o).size!==o.length)throw new u("invalid_operation","Stage ids must be unique");let i=new Set(co.map(c=>c.key)),a=t.updates.map(c=>{if(!i.has(c.stageKind))throw new u("invalid_operation",`Unknown stage kind: ${c.stageKind}`,{stageKind:c.stageKind});let s=n.objects.find(l=>l.type==="shape"&&l.id===c.stageId);if(!s)throw new u("object_not_found",`Unknown stage id: ${c.stageId}. Call get_chart to list current stage ids.`,{stageId:c.stageId});if(s.role!=="stage")throw new u("invalid_operation",`Shape ${c.stageId} is not tagged as a stage`,{stageId:c.stageId});return{shape:s,stageKind:c.stageKind,box:s.stageKind===c.stageKind?null:uo(s)}}),r=!1;for(let c of a)c.box&&(c.shape.points=lo({kind:c.stageKind,...c.box}),c.shape.kind="polygon",c.shape.stageKind=c.stageKind,r=!0);return{floorId:n.floorId,changed:r,stages:a.map(c=>({id:c.shape.id,stageKind:c.stageKind}))}}function fo(e){let t=new Map;e.confidenceEvidence&&t.set("venue",{target:{scope:"venue"},evidence:e.confidenceEvidence});for(let n of E(e)){n.confidenceEvidence&&t.set(`floor:${n.id}`,{target:{scope:"floor",floorId:n.id},evidence:n.confidenceEvidence});for(let o of n.objects){let i=`floor:${n.id}:object:${o.id}`;if((o.type==="row"||o.type==="section")&&o.confidenceEvidence&&t.set(i,{target:{scope:o.type,floorId:n.id,objectId:o.id},evidence:o.confidenceEvidence}),o.type==="row"&&o.segmentedRow?.confidenceEvidence&&t.set(`${i}:segmented`,{target:{scope:"row",floorId:n.id,objectId:o.id},evidence:o.segmentedRow.confidenceEvidence}),o.type==="row"||o.type==="table")for(let a of o.overrides??[])a.confidenceEvidence&&t.set(`${i}:seat:${a.index}`,{target:{scope:"seat",floorId:n.id,objectId:o.id,seatIndex:a.index},evidence:a.confidenceEvidence})}}return t}function Ye(e){return Array.isArray(e)?e.map(Ye):!e||typeof e!="object"?e:Object.fromEntries(Object.entries(e).sort(([t],[n])=>t.localeCompare(n)).map(([t,n])=>[t,Ye(n)]))}function Pa(e,t){return JSON.stringify(Ye(e))===JSON.stringify(Ye(t))}function Mt(e){return!!e&&e.status!=="draft"&&e.status!=="retracted"}function Oa(e){return e?e.status==="retracted"?"retract":Mt(e)?"approve":"set":"clear"}function go(e,t){let n=fo(e),o=fo(t),i=[...new Set([...n.keys(),...o.keys()])].sort(),a=[];for(let r of i){let c=n.get(r),s=o.get(r);if(c&&s&&Pa(c.evidence,s.evidence))continue;let l=s?.target??c?.target;l&&a.push({...l,operation:Oa(s?.evidence),...c?{before:c.evidence}:{},...s?{after:s.evidence}:{}})}return a}function _a(e,t){return go(e,t).some(n=>Mt(n.before)||Mt(n.after))}var Aa=new Set(["synthetic-model","organizer-approved","calibrated-provider"]),Ma=new Set(["generated","geometry-verified","configuration-verified"]),ja=new Set(["none","comparable-build-reference","actual-build-checked"]),ka=new Set(["clear","partial","obstructed"]);function jt(e){return e.toISOString().slice(0,10)}function kt(e,t){return typeof e=="string"&&e.normalize("NFKC").trim()===e&&e.length>0&&e.length<=t}function fe(e,t,n){if(!kt(e,t))throw new u("invalid_operation",`Confidence evidence ${n} is invalid`,{field:n});return e}function ue(e,t,n){if(e!==void 0)return fe(e,t,n)}function Ze(e,t,n){let o=n?[C(e,n)]:E(e).map(i=>({floorId:i.id,objects:i.objects}));for(let i of o){let a=i.objects.find(r=>r.id===t);if(a)return{floorId:i.floorId,object:a}}throw new u("object_not_found",`Unknown chart object: ${t}`,{objectId:t,floorId:n})}function ho(e,t){let n=E(e),o=t?n.find(i=>i.id===t):n[0];if(!o)throw new u("floor_not_found",`Unknown chart floor: ${t}`,{floorId:t});return o}function Pe(e,t){if(t.scope==="venue")return e.confidenceEvidence;if(t.scope==="floor")return ho(e,t.floorId).confidenceEvidence;if(t.scope==="seat"){if(!t.objectId||t.seatIndex===void 0)throw new u("invalid_operation","Seat evidence requires objectId and seatIndex");let o=Ze(e,t.objectId,t.floorId);if(o.object.type!=="row"&&o.object.type!=="table")throw new u("invalid_operation","Seat evidence can be stored only on a row or table",{objectId:t.objectId});return o.object.overrides?.find(i=>i.index===t.seatIndex)?.confidenceEvidence}if(!t.objectId)throw new u("invalid_operation",`${t.scope} evidence requires objectId`);let n=Ze(e,t.objectId,t.floorId);if(t.scope==="row"&&n.object.type!=="row")throw new u("invalid_operation","Row evidence requires a row id",{objectId:t.objectId});if(t.scope==="section"&&n.object.type!=="section")throw new u("invalid_operation","Section evidence requires a section id",{objectId:t.objectId});if(n.object.type==="row"||n.object.type==="section")return n.object.confidenceEvidence;throw new u("invalid_operation",`${t.scope} evidence is not supported on this object`,{objectId:t.objectId,type:n.object.type})}function We(e,t,n){if(t.scope==="venue")return n?e.confidenceEvidence=n:delete e.confidenceEvidence,{};if(t.scope==="floor"){let i=ho(e,t.floorId);return n?i.confidenceEvidence=n:delete i.confidenceEvidence,{floorId:i.id}}if(t.scope==="seat"){if(!t.objectId||t.seatIndex===void 0)throw new u("invalid_operation","Seat evidence requires objectId and seatIndex");let i=Ze(e,t.objectId,t.floorId);return Pt(e,{floorId:i.floorId,seats:[{rowId:t.objectId,index:t.seatIndex}],patch:{confidenceEvidence:n??null}}),{floorId:i.floorId,objectId:t.objectId}}if(!t.objectId)throw new u("invalid_operation",`${t.scope} evidence requires objectId`);let o=Ze(e,t.objectId,t.floorId);if(o.object.type!=="row"&&o.object.type!=="section")throw new u("invalid_operation",`${t.scope} evidence is not supported on this object`,{objectId:t.objectId,type:o.object.type});return n?o.object.confidenceEvidence=n:delete o.object.confidenceEvidence,{floorId:o.floorId,objectId:o.object.id}}function Ra(e){if(e===void 0)return;if(!e||typeof e!="object")throw new u("invalid_operation","Confidence evidence modeledTarget is invalid");if(!kt(e.label,80)||!kt(e.methodLabel,100))throw new u("invalid_operation","Confidence evidence modeledTarget labels are invalid");if(!Number.isInteger(e.totalRayCount)||e.totalRayCount<1||e.totalRayCount>1e3||!Number.isInteger(e.clearRayCount)||e.clearRayCount<0||e.clearRayCount>e.totalRayCount)throw new u("invalid_operation","Confidence evidence modeledTarget ray counts are invalid");if(!ka.has(e.classification))throw new u("invalid_operation","Confidence evidence modeledTarget classification is invalid");let t=e.occluderLabels?.map(n=>fe(n,80,"occluder label"));return{label:e.label,methodLabel:e.methodLabel,totalRayCount:e.totalRayCount,clearRayCount:e.clearRayCount,classification:e.classification,...t?.length?{occluderLabels:t}:{}}}function bo(e,t=new Date){if(e.schema!==void 0&&e.schema!=="seatlayer.seat-confidence/1")throw new u("invalid_operation","Confidence evidence schema must be seatlayer.seat-confidence/1");if(!Aa.has(e.evidenceKind))throw new u("invalid_operation","Confidence evidence kind is invalid");if(!Ma.has(e.modelLevel))throw new u("invalid_operation","Confidence evidence model level is invalid");let n=e.realityLevel??"none";if(!ja.has(n))throw new u("invalid_operation","Confidence evidence reality level is invalid");if(e.evidenceKind==="synthetic-model"&&(e.modelLevel!=="generated"||n!=="none"))throw new u("invalid_operation","Synthetic evidence cannot claim verification or reality checks");let o=ue(e.eventConfigurationId,100,"eventConfigurationId");if(e.eventConfigurationVersion!==void 0&&(!Number.isInteger(e.eventConfigurationVersion)||e.eventConfigurationVersion<1))throw new u("invalid_operation","Confidence evidence eventConfigurationVersion is invalid");if(e.modelLevel==="configuration-verified"&&!o)throw new u("invalid_operation","Configuration-verified evidence requires eventConfigurationId");let i=e.limitations?.map(d=>fe(d,160,"limitation"));if(i&&i.length>6)throw new u("invalid_operation","Confidence evidence accepts at most 6 limitations");let a=ue(e.assessedAt,40,"assessedAt")??jt(t),r=Date.parse(a);if(!Number.isFinite(r))throw new u("invalid_operation","Confidence evidence assessedAt is invalid");let c=ue(e.validUntil,40,"validUntil")??(e.modelLevel==="generated"?void 0:jt(new Date(r+365*24*60*60*1e3))),s=c?Date.parse(c):Number.NaN;if(c&&(!Number.isFinite(s)||s<r||s>r+366*24*60*60*1e3))throw new u("invalid_operation",`Confidence evidence validity must end within ${366} days of assessment`);let l=ue(e.approvedByRole,100,"approvedByRole");if(e.modelLevel!=="generated"&&!l)throw new u("invalid_operation","Verified model levels require approvedByRole");return{schema:"seatlayer.seat-confidence/1",evidenceId:fe(e.evidenceId,120,"evidenceId"),modelVersion:fe(e.modelVersion,120,"modelVersion"),evidenceKind:e.evidenceKind,modelLevel:e.modelLevel,realityLevel:n,status:"draft",assessedAt:a,...o?{eventConfigurationId:o}:{},...e.eventConfigurationVersion!==void 0?{eventConfigurationVersion:e.eventConfigurationVersion}:{},...c?{validUntil:c}:{},...l?{approvedByRole:l}:{},...ue(e.sourceLabel,120,"sourceLabel")?{sourceLabel:e.sourceLabel}:{},...i?.length?{limitations:i}:{},...e.modeledTarget?{modeledTarget:Ra(e.modeledTarget)}:{}}}function ge(e,t={}){return{changed:t.changed??!0,scope:e.scope,...e.objectId?{objectId:e.objectId}:{},...e.floorId?{floorId:e.floorId}:{},...e.seatIndex!==void 0?{seatIndex:e.seatIndex}:{},...t}}function La(e,t){let n=bo(t.evidence,t.now),o=JSON.stringify(Pe(e,t)??null),i=We(e,t,n),a=JSON.stringify(Pe(e,t)??null);return ge(t,{changed:o!==a,...i,evidenceId:n.evidenceId,status:"draft"})}function Ea(e,t){let n=Pe(e,t);if(!n)return ge(t,{changed:!1});let o=We(e,t,void 0);return ge(t,{changed:!0,...o,evidenceId:n.evidenceId})}function Ta(e,t){let n=Pe(e,t);if(!n)throw new u("invalid_operation","There is no confidence evidence at this scope to approve",{scope:t.scope,objectId:t.objectId});if(n.status==="retracted")throw new u("invalid_operation","Retracted evidence cannot be approved; author a new draft first");let o=fe(t.approvedByRole.normalize("NFKC").trim(),100,"approvedByRole"),i=ue(t.eventConfigurationId,100,"eventConfigurationId")??n.eventConfigurationId;if(n.modelLevel==="configuration-verified"&&!i)throw new u("invalid_operation","Configuration-verified evidence requires eventConfigurationId");let a=t.eventConfigurationVersion??n.eventConfigurationVersion;if(a!==void 0&&(!Number.isInteger(a)||a<1))throw new u("invalid_operation","Confidence evidence eventConfigurationVersion is invalid");let r={...n,status:"approved",approvedByRole:o,assessedAt:jt(t.now??new Date),...i?{eventConfigurationId:i}:{},...a!==void 0?{eventConfigurationVersion:a}:{}};delete r.basisSha256;let c=t.basisSha256??e.confidenceBasisSha256;c&&(r.basisSha256=c);let s=JSON.stringify(n),l=We(e,t,r);return ge(t,{changed:s!==JSON.stringify(r),...l,evidenceId:r.evidenceId,status:"approved"})}function Fa(e,t){let n=Pe(e,t);if(!n)throw new u("invalid_operation","There is no confidence evidence at this scope to retract",{scope:t.scope,objectId:t.objectId});if(n.status==="retracted")return ge(t,{changed:!1,evidenceId:n.evidenceId,status:"retracted"});let o={...n,status:"retracted"};delete o.basisSha256;let i=We(e,t,o);return ge(t,{changed:!0,...i,evidenceId:n.evidenceId,status:"retracted"})}0&&(module.exports={COLORBLIND_SAFE_PALETTE,ChartOperationError,DEFAULT_FLOOR_HEIGHT_STEP_M,DEFAULT_SECTION_CORNER_SMOOTHING,MAX_BUYER_IMAGE_URL_LENGTH,MAX_FLOOR_BASE_HEIGHT_M,addArcFanRows,addBookableGridArray,addBoothArray,addChartCategory,addChartFloor,addChartZone,addGAArea,addRowBlock,addTableArray,applyPolygonHole,applyReferenceScanRows,applySectionCornerSmoothing,applySectionOutlineShaping,applySectionRowFit,approveConfidenceEvidence,arcFanInputForGroup,assignSectionInventoryCategory,automaticPlacementCenter,clearConfidenceEvidence,confidenceEvidenceChangeRequiresPublish,confidenceEvidenceChanges,confirmReferenceCategoryOutputColor,convertGeneratedSectionToPolygon,countCoveredInventory,familyCategoryLabel,gaAreaFootprint,groupRowsAsSegmented,insertSeatingBlock,isSafeBuyerImageUrl,joinGAAreas,mergeRows,mirrorFirstFloor,normalizeBuyerImageUrl,normalizeDraftEvidence,parseSeatRefId,pickColorblindSafeCategoryColor,planCreationCategory,previewArcFanRows,previewBookableGridArray,previewGeneratedSectionPolygonConversion,previewJoinGAAreas,previewPolygonHole,previewRemovePolygonHole,previewRowCubicPath,previewSectionRowFit,reassignColorblindSafeCategoryColors,relabelChartRows,removeChartCategory,removeChartFloor,removeChartObjects,removeChartZone,removePolygonHole,renameChartFloor,reorderChartCategories,replaceArcFanRows,replaceRowBlock,resetSeatOverrides,resizeShapes,resolveCreationCategory,retractConfidenceEvidence,seatRefId,sectionInventorySelectionSummary,setConfidenceEvidence,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 ko=Object.create;var Me=Object.defineProperty;var Eo=Object.getOwnPropertyDescriptor;var To=Object.getOwnPropertyNames;var Fo=Object.getPrototypeOf,No=Object.prototype.hasOwnProperty;var Do=(e,t)=>{for(var n in t)Me(e,n,{get:t[n],enumerable:!0})},Ht=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of To(t))!No.call(e,i)&&i!==n&&Me(e,i,{get:()=>t[i],enumerable:!(o=Eo(t,i))||o.enumerable});return e};var Go=(e,t,n)=>(n=e!=null?ko(Fo(e)):{},Ht(t||!e||!e.__esModule?Me(n,"default",{value:e,enumerable:!0}):n,e)),Ko=e=>Ht(Me({},"__esModule",{value:!0}),e);var ds={};Do(ds,{COLORBLIND_SAFE_PALETTE:()=>jt,ChartOperationError:()=>u,DEFAULT_FLOOR_HEIGHT_STEP_M:()=>St,DEFAULT_SECTION_CORNER_SMOOTHING:()=>ut,MAX_BUYER_IMAGE_URL_LENGTH:()=>hr,MAX_FLOOR_BASE_HEIGHT_M:()=>Ge,addArcFanRows:()=>Ui,addBookableGridArray:()=>wa,addBoothArray:()=>Zi,addChartCategory:()=>Un,addChartFloor:()=>Sr,addChartZone:()=>Cr,addGAArea:()=>Yi,addRowBlock:()=>qi,addTableArray:()=>Qi,applyPolygonHole:()=>ii,applyReferenceScanRows:()=>ya,applySectionCornerSmoothing:()=>bi,applySectionOutlineShaping:()=>Tn,applySectionRowFit:()=>oi,approveConfidenceEvidence:()=>cs,arcFanInputForGroup:()=>qn,assignSectionInventoryCategory:()=>ci,automaticPlacementCenter:()=>Ki,clearConfidenceEvidence:()=>ss,confidenceEvidenceChangeRequiresPublish:()=>es,confidenceEvidenceChanges:()=>Mo,confirmReferenceCategoryOutputColor:()=>Ii,convertGeneratedSectionToPolygon:()=>di,countCoveredInventory:()=>Ve,familyCategoryLabel:()=>Hn,gaAreaFootprint:()=>Yn,groupRowsAsSegmented:()=>Wi,insertSeatingBlock:()=>Zr,isSafeBuyerImageUrl:()=>hn,joinGAAreas:()=>Ba,mergeRows:()=>Ea,mirrorFirstFloor:()=>ve,normalizeBuyerImageUrl:()=>Z,normalizeDraftEvidence:()=>Lo,parseSeatRefId:()=>va,pickColorblindSafeCategoryColor:()=>Bn,planCreationCategory:()=>Vn,previewArcFanRows:()=>Lt,previewBookableGridArray:()=>ma,previewGeneratedSectionPolygonConversion:()=>kn,previewJoinGAAreas:()=>za,previewPolygonHole:()=>Je,previewRemovePolygonHole:()=>Mn,previewRowCubicPath:()=>_n,previewSectionRowFit:()=>Rn,reassignColorblindSafeCategoryColors:()=>vi,relabelChartRows:()=>Qr,removeChartCategory:()=>Ti,removeChartFloor:()=>Ir,removeChartObjects:()=>Xr,removeChartZone:()=>Pr,removePolygonHole:()=>ai,renameChartFloor:()=>xr,renameDirectSeatImportCategory:()=>mi,reorderChartCategories:()=>wi,replaceArcFanRows:()=>Hi,replaceRowBlock:()=>na,resetSeatOverrides:()=>Oa,resizeShapes:()=>Xa,resolveCreationCategory:()=>Li,retractConfidenceEvidence:()=>ls,seatRefId:()=>_e,sectionInventorySelectionSummary:()=>Ln,setConfidenceEvidence:()=>as,setRowBlockSpacing:()=>Fa,splitRow:()=>Ta,straightenAndSpaceRows:()=>Na,transformSectionBoundary:()=>ui,transformSectionBoundaryObject:()=>En,ungroupSegmentedRow:()=>ea,updateBooths:()=>qr,updateCategoryDefinitions:()=>zn,updateChartFloorBaseHeight:()=>vr,updateChartTheme:()=>Di,updateChartZones:()=>Or,updateGAAreas:()=>Jr,updateRowCubicPath:()=>ei,updateRows:()=>Pa,updateSeatOverrides:()=>Dt,updateSectionExactPath:()=>fi,updateSectionMetadata:()=>li,updateSegmentedRow:()=>ta,updateShapes:()=>Ja,updateStageKinds:()=>Ya,updateTables:()=>Vr,updateTextObjects:()=>Yr,updateViewFromSeatFallback:()=>Gi});module.exports=Ko(ds);var Vt=e=>Math.max(1,e.fontSize*.6+(e.letterSpacing??0));function $o(e,t){let n=e.text.split(/\r?\n/);if(!e.width)return Math.max(1,n.length);let o=Math.max(1,Math.floor(t/Vt(e))),i=0;for(let a of n){if(!a.length){i+=1;continue}let r=0;for(let s of a.split(/\s+/)){let c=s.length;r&&r+1+c<=o?r+=1+c:(i+=Math.max(1,Math.ceil(c/o)),r=c%o)}}return Math.max(1,i)}function qt(e){let t=e.background?.padding??0,n=e.text.split(/\r?\n/),o=Math.max(1,...n.map(s=>s.length))*Vt(e),i=e.width??o+t*2,a=Math.max(1,i-t*2),r=$o(e,a);return{width:i,height:r*e.fontSize*(e.lineHeight??1.2)+t*2,lineCount:r,padding:t}}var gs=Math.PI/180;function D(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function st(e,t,n){return{x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n}}function Jt(e,t){let n=1-t,o=n*n*n,i=3*n*n*t,a=3*n*t*t,r=t*t*t;return{x:o*e.start.x+i*e.control1.x+a*e.control2.x+r*e.end.x,y:o*e.start.y+i*e.control1.y+a*e.control2.y+r*e.end.y}}function je(e,t,n=192){if(!Number.isInteger(t)||t<1)throw new Error("Path point count must be a positive integer");if(t===1)return[Jt(e,.5)];let o=Array.from({length:n+1},(c,l)=>Jt(e,l/n)),i=new Float64Array(o.length);for(let c=1;c<o.length;c+=1){let l=o[c].x-o[c-1].x,d=o[c].y-o[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:t},()=>({...e.start}));let r=[],s=1;for(let c=0;c<t;c+=1){let l=a*c/(t-1);for(;s<i.length-1&&i[s]<l;)s+=1;let d=i[s-1],f=i[s],b=f===d?0:(l-d)/(f-d);r.push({x:o[s-1].x+(o[s].x-o[s-1].x)*b,y:o[s-1].y+(o[s].y-o[s-1].y)*b})}return r}function me(e){if(e.length<3)return 0;let t=0;for(let n=0,o=e.length-1;n<e.length;o=n++)t+=(e[o].x+e[n].x)*(e[o].y-e[n].y);return Math.abs(t)/2}function zo(e,t,n){return Math.max(t,Math.min(n,e))}function Bo(e){return zo(e,0,1)}function Xt(e){let t=Bo(e);return t*t*(3-2*t)}var re=Math.PI*2;function ie(e){return Number.isFinite(e.x)&&Number.isFinite(e.y)}function Uo(e,t,n){let o=t-e;if(n){for(;o<0;)o+=re;for(;o>=re;)o-=re}else{for(;o>0;)o-=re;for(;o<=-re;)o+=re}return o}function Le(e){if(e.version!==1||e.closed!==!0||!ie(e.start)||!Array.isArray(e.segments)||e.segments.length<2||e.segments.length>512)return!1;let t=e.start;for(let n of e.segments){if(!n||!ie(n.end))return!1;if(n.kind==="line"){if(D(t,n.end)<=1e-9)return!1}else if(n.kind==="bezier"){if(!ie(n.control1)||!ie(n.control2)||D(t,n.end)<=1e-9)return!1}else if(n.kind==="arc"){if(!ie(n.center)||!Number.isFinite(n.radius)||n.radius<=1e-6||Math.abs(D(t,n.center)-n.radius)>Math.max(1e-4,n.radius*1e-4)||Math.abs(D(n.end,n.center)-n.radius)>Math.max(1e-4,n.radius*1e-4)||D(t,n.end)<=1e-9)return!1}else return!1;t=n.end}return D(t,e.start)<=1e-4}function Ho(e,t,n){let o=1-n;return{x:o**3*e.x+3*o**2*n*t.control1.x+3*o*n**2*t.control2.x+n**3*t.end.x,y:o**3*e.y+3*o**2*n*t.control1.y+3*o*n**2*t.control2.y+n**3*t.end.y}}function lt(e,t=2){if(!Le(e))throw new Error("Section outline path is invalid");let n=Math.max(.25,t),o=[{...e.start}],i=e.start;for(let a of e.segments){if(a.kind==="line")o.push({...a.end});else if(a.kind==="arc"){let r=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=Uo(r,s,a.clockwise),l=Math.max(2,Math.ceil(Math.abs(c)*a.radius/n));for(let d=1;d<=l;d+=1){let f=r+c*d/l;o.push({x:a.center.x+Math.cos(f)*a.radius,y:a.center.y+Math.sin(f)*a.radius})}}else{let r=D(i,a.control1)+D(a.control1,a.control2)+D(a.control2,a.end),s=Math.max(2,Math.ceil(r/n));for(let c=1;c<=s;c+=1)o.push(Ho(i,a,c/s))}i=a.end}return D(o[o.length-1],o[0])<=1e-4&&o.pop(),o}function Zt(e,t,n){return dt(e,i=>({x:i.x+t,y:i.y+n}))}function dt(e,t,n=1,o=!1){return{...e,start:t(e.start),segments:e.segments.map(i=>i.kind==="line"?{...i,end:t(i.end)}:i.kind==="arc"?{...i,center:t(i.center),radius:i.radius*Math.abs(n),clockwise:o?!i.clockwise:i.clockwise,end:t(i.end)}:{...i,control1:t(i.control1),control2:t(i.control2),end:t(i.end)})}}var ut=45,ct=150,Vo=60;function qo(e){let t=ut/100;if(e<=t)return ct;let n=Math.min(1,(e-t)/(1-t));return ct-n*(ct-Vo)}var Yt=.5523;function Qt(e,t){return Math.abs(e.x-t.x)<=1e-6&&Math.abs(e.y-t.y)<=1e-6}function Jo(e){let t=[],n=[];for(e.forEach((o,i)=>{ie(o)&&(t.length&&Qt(t[t.length-1],o)||(t.push({x:o.x,y:o.y}),n.push(i)))});t.length>1&&Qt(t[0],t[t.length-1]);)t.pop(),n.pop();return{points:t,sourceIndex:n}}var Xo=.5,Yo=4/3;function Qo(e,t,n){let o=t.x-e.x,i=t.y-e.y,a=Math.hypot(o,i);if(a<=1e-9)return{kind:"line",end:{...t}};let r=-i/a,s=o/a,c=n*Yo;return{kind:"bezier",control1:{x:e.x+o/3+r*c,y:e.y+i/3+s*c},control2:{x:e.x+o*2/3+r*c,y:e.y+i*2/3+s*c},end:{...t}}}function Wt(e,t){let{points:n,sourceIndex:o}=Jo(e),i=n.length;if(i<3)return null;let a=Math.min(100,Math.max(0,t.cornerSmoothing??0))/100,r=t.edgeCurvature,s=new Array(i).fill(0);if(r?.length)for(let w=0;w<i;w+=1){let S=r[o[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=t.wideAngleThresholdDeg??qo(a),d=[];for(let w=0;w<i;w+=1)d[w]=D(n[w],n[(w+1)%i]);let f=new Array(i).fill(0);for(let w=0;w<i;w+=1){let S=n[(w-1+i)%i],v=n[w],_=n[(w+1)%i],G={x:S.x-v.x,y:S.y-v.y},N={x:_.x-v.x,y:_.y-v.y},H=Math.hypot(G.x,G.y),K=Math.hypot(N.x,N.y);if(H<=1e-9||K<=1e-9)continue;let P=Math.min(1,Math.max(-1,(G.x*N.x+G.y*N.y)/(H*K))),$=Math.acos(P)*180/Math.PI;if($<l)continue;let M=Xt(($-l)/(180-l));f[w]=a*M*.5*Math.min(H,K)}for(let w=0;w<i;w+=1){let S=(w+1)%i,v=f[w]+f[S];if(v>d[w]&&v>1e-9){let _=d[w]/v;f[w]*=_,f[S]*=_}}let b=new Array(i),g=new Array(i);for(let w=0;w<i;w+=1){let S=n[(w-1+i)%i],v=n[w],_=n[(w+1)%i];if(f[w]<=1e-6){b[w]={...v},g[w]={...v};continue}let G=D(v,S)||1,N=D(v,_)||1;b[w]={x:v.x+(S.x-v.x)/G*f[w],y:v.y+(S.y-v.y)/G*f[w]},g[w]={x:v.x+(_.x-v.x)/N*f[w],y:v.y+(_.y-v.y)/N*f[w]}}if(f.every(w=>w<=1e-6)&&!c)return null;let p=[],m={...g[0]},x=m,I=(w,S)=>{if(D(x,w)<=1e-9)return;let v=s[S];Math.abs(v)>1e-6?p.push(Qo(x,w,v*Xo*d[S])):p.push({kind:"line",end:{...w}}),x=w};for(let w=1;w<=i;w+=1){let S=w%i,v=n[S];I(b[S],(w-1)%i),f[S]>1e-6&&D(b[S],g[S])>1e-9&&(p.push({kind:"bezier",control1:st(b[S],v,Yt),control2:st(g[S],v,Yt),end:{...g[S]}}),x=g[S])}if(!p.length)return null;let h=p[p.length-1];D(h.end,m)>1e-9&&(h.kind==="line"?h.end={...m}:p.push({kind:"line",end:{...m}}));let y={version:1,closed:!0,start:m,segments:p};return Le(y)?y:null}var en="ABCDEFGHIJKLMNOPQRSTUVWXYZ",Zo="ABCDEFGHJKLMNPQRSTUVWXYZ",Wo="abcdefghijklmnopqrstuvwxyz";function tn(e,t){let n=t.length,o=e+1,i="";for(;o>0;){o-=1;let a=o%n;i=t[a]+i,o=Math.floor(o/n)}return i}function er(e,t){let n=t.startAt-1,o=e+n;if(t.scheme==="numbers")return String(o+1);let i=t.skipAmbiguous?Zo:en;return tn(o,i)}function ft(e,t=!1){let n=t?Wo:en;return tn(Math.max(0,Math.floor(e)-1),n)}var tr=[[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 nn(e){if(!Number.isFinite(e)||e<=0)return String(e);let t=Math.floor(e),n="";for(let[o,i]of tr)for(;t>=o;)n+=i,t-=o;return n}function on(e,t){let n=e.length;return e.map((o,i)=>{let a=t.reverse?n-1-i:i;return{...o,label:er(a,t)}})}function nr(e){let t=new Array(e);return Array.from({length:e},(n,o)=>o).sort((n,o)=>Math.abs(2*n-(e-1))-Math.abs(2*o-(e-1))||n-o).forEach((n,o)=>t[n]=o),t}function gt(e,t){let n=e.seatLabelStart??1,o=e.seatNumbering?.direction??"ltr",i=e.seatNumbering?.step??1,a=e.seatNumbering?.scheme??"decimal",r=e.seatNumbering?.prefix??"",s=e.seatNumbering?.endAt,c=e.seatCount;if(a==="updown"||a==="updown-descending"){let g=Math.ceil(c/2),p=a==="updown"?t<g?n+2*t:n-1+2*(c-t):t<g?n+2*(g-1-t):n+1+2*(t-g);return`${r}${p}`}let l=a==="odd"||a==="even"?2:i,d=s!=null&&Number.isFinite(s)?s-(c-1)*l:n,f=o==="center"?nr(c)[t]:o==="rtl"?c-1-t:t,b;switch(a){case"odd":{let g=d%2===1?d:d+1;b=String(g+f*2);break}case"even":{let g=d%2===0?d:d+1;b=String(g+f*2);break}case"roman":b=nn(d+f*i);break;case"letters-upper":b=ft(d+f*i,!1);break;case"letters-lower":b=ft(d+f*i,!0);break;default:b=String(d+f*i);break}return`${r}${b}`}function or(e){return{...e.canonical,seatCount:e.totalSeats,label:e.displayLabel,displayLabel:e.displayLabel}}function we(e,t,n){return n?.label??`${e.label}-${gt(e,t)}`}function rn(e,t,n,o){if(o?.displayLabel)return o.displayLabel;if(!n)return`${e.displayLabel??e.label}-${gt(e,t)}`;let i=or(n),a=n.displayOffset+t;return`${n.displayLabel}-${gt(i,a)}`}function cn(e){return e?e.accessibility&&e.accessibility.length?e.wheelchairSpaceType&&!e.accessibility.includes("wheelchair")?["wheelchair",...e.accessibility]:e.accessibility:e.wheelchairSpaceType?["wheelchair"]:e.accessible?["wheelchair"]:[]:[]}var Ee=Math.PI/180,rr=9,ae=16;function ht(e,t,n,o){let i=n*Ee,a=Math.cos(i),r=Math.sin(i);return{x:o.x+e*a-t*r,y:o.y+e*r+t*a}}function Se(e){let{seatCount:t,seatSpacing:n,curve:o,rotation:i,origin:a}=e,r=[];if(e.path)return je(e.path,t);if(t<=1)return t===1&&r.push({x:a.x,y:a.y}),r;if(o===0){for(let l=0;l<t;l++)r.push(ht(l*n,0,i,a));return r}let s=o/(t-1)*Ee,c=n/(2*Math.sin(Math.abs(s)/2));for(let l=0;l<t;l++){let d=l*s,f=c*Math.sin(d),b=-c+c*Math.cos(d);r.push(ht(f,b,i,a))}return r}function ir(e){let t=new Map;if(e.overrides)for(let n of e.overrides)t.set(n.index,n);return t}function ar(e,t){let n=ir(e);return Se(e).map((o,i)=>{let a=n.get(i),r=cn(a),s=we(e,i,a),c={...e.commercial,...a?.commercial};return{index:i,x:o.x+(a?.dx??0),y:o.y+(a?.dy??0),label:s,displayLabel:rn(e,i,t,a),categoryKey:a?.categoryKey??e.categoryKey,skipped:!!a?.skip,accessible:r.length>0,accessibility:r,wheelchairSpaceType:a?.wheelchairSpaceType,commercial:Object.values(c).some(l=>l!==void 0&&l!==!1&&l!=="")?c:void 0,glyph:a?.glyph,viewUrl:a?.viewFromSeatUrl??e.viewFromSeatUrl,viewMeta:a?.viewFromSeatUrl?a.viewFromSeatMeta:e.viewFromSeatMeta,labelStyle:a?.labelStyle}})}function z(e){let t=[];for(let n of ar(e))n.skipped||t.push({id:`${e.id}:${n.index}`,label:n.label,displayLabel:n.displayLabel===n.label?void 0:n.displayLabel,x:n.x,y:n.y,rowId:e.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 t}function sr(e){if(e.seatCountsBySide)return{...e.seatCountsBySide};let t=e.sides&&e.sides.length?e.sides:["top","bottom"],n=["top","bottom","left","right"].filter(a=>t.includes(a)),o={top:0,bottom:0,left:0,right:0};if(!n.length)return o;let i=Math.max(0,Math.round(e.seatCount));for(let a=0;a<i;a++)o[n[a%n.length]]+=1;return o}function cr(e){let t=[],n=Math.max(0,Math.round(e.seatCount));if(n===0)return t;let o=new Map((e.overrides??[]).map(d=>[d.index,d])),i=(d,f,b,g)=>{let p=o.get(d),m=cn(p),x=p?.label??`${e.label}-${d+1}`,I=e.displayLabel??e.label;return{index:d,label:x,displayLabel:p?.displayLabel??`${I}-${d+1}`,x:f+(p?.dx??0),y:b+(p?.dy??0),categoryKey:p?.categoryKey??e.categoryKey,skipped:!!p?.skip,accessible:m.length>0,accessibility:m,wheelchairSpaceType:p?.wheelchairSpaceType,commercial:p?.commercial,glyph:p?.glyph,viewUrl:p?.viewFromSeatUrl,viewMeta:p?.viewFromSeatUrl?p.viewFromSeatMeta:void 0,labelStyle:p?.labelStyle,...g?{side:g}:{}}};if(e.shape==="round"){let d=(e.radius??40)+ae,f=e.rotation*Ee,b=Math.max(0,Math.min(360,e.seatArc??360));if(b>=360||n===1){for(let x=0;x<n;x++){let I=f+x/n*2*Math.PI;t.push(i(x,e.center.x+d*Math.cos(I),e.center.y+d*Math.sin(I)))}return t}let g=b*Ee,p=(2*Math.PI-g)/2,m=f+p;for(let x=0;x<n;x++){let I=m+x/(n-1)*g;t.push(i(x,e.center.x+d*Math.cos(I),e.center.y+d*Math.sin(I)))}return t}let a=e.width??80,r=e.height??50,s=sr(e),c=["top","bottom","left","right"],l=0;for(let d of c){let f=s[d];for(let b=0;b<f;b++){let g,p;d==="top"?(g=-a/2+(b+.5)*a/f,p=-r/2-ae):d==="bottom"?(g=-a/2+(b+.5)*a/f,p=r/2+ae):d==="left"?(g=-a/2-ae,p=-r/2+(b+.5)*r/f):(g=a/2+ae,p=-r/2+(b+.5)*r/f);let m=ht(g,p,e.rotation,e.center);t.push(i(l++,m.x,m.y,d))}}return t}function W(e){return cr(e).filter(t=>!t.skipped).map(t=>({id:`${e.id}:${t.index}`,label:t.label,...t.displayLabel!==t.label?{displayLabel:t.displayLabel}:{},x:t.x,y:t.y,rowId:e.id,categoryKey:t.categoryKey,...t.accessible?{accessible:!0}:{},...t.accessibility.length?{accessibility:t.accessibility}:{},...t.wheelchairSpaceType?{wheelchairSpaceType:t.wheelchairSpaceType}:{},...t.commercial?{commercial:t.commercial}:{},...t.glyph?{glyph:t.glyph}:{},...t.viewUrl?{viewUrl:t.viewUrl}:{},...t.viewUrl&&t.viewMeta?{viewMeta:t.viewMeta}:{},...t.labelStyle?{labelStyle:t.labelStyle}:{}}))}function ln(e){return[{id:`${e.id}:0`,label:e.label,...e.displayLabel&&e.displayLabel!==e.label?{displayLabel:e.displayLabel}:{},x:e.center.x,y:e.center.y,rowId:e.id,categoryKey:e.categoryKey,kind:"booth"}]}function an(e,t){let n=!1;for(let o=0,i=t.length-1;o<t.length;i=o++){let a=t[o].x,r=t[o].y,s=t[i].x,c=t[i].y;r>e.y!=c>e.y&&e.x<(s-a)*(e.y-r)/(c-r)+a&&(n=!n)}return n}function lr(e,t){return t.some((n,o)=>{let i=t[(o+1)%t.length],a=(e.y-n.y)*(i.x-n.x)-(e.x-n.x)*(i.y-n.y);if(Math.abs(a)>1e-7)return!1;let r=(e.x-n.x)*(i.x-n.x)+(e.y-n.y)*(i.y-n.y),s=(i.x-n.x)**2+(i.y-n.y)**2;return r>=-1e-7&&r<=s+1e-7})}function F(e,t,n){return an(e,t)&&!(n??[]).some(o=>an(e,o)||lr(e,o))}function bt(e){if(!e.length)return{x:0,y:0};let t=0,n=0;for(let o of e)t+=o.x,n+=o.y;return{x:t/e.length,y:n/e.length}}function L(e){switch(e.type){case"row":{let t=z(e);if(!t.length)return{x:e.origin.x,y:e.origin.y};let n=0,o=0;for(let i of t)n+=i.x,o+=i.y;return{x:n/t.length,y:o/t.length}}case"table":case"booth":return{x:e.center.x,y:e.center.y};case"gaArea":return bt(e.points);case"section":return bt(e.outline);case"text":return{x:e.position.x,y:e.position.y};case"shape":return e.points&&e.points.length?bt(e.points):e.x!=null&&e.y!=null&&e.width!=null&&e.height!=null?{x:e.x+e.width/2,y:e.y+e.height/2}:{x:e.x??0,y:e.y??0};case"decorImage":return{x:e.x+e.width/2,y:e.y+e.height/2}}}function sn(e,t){return e.length===t.length&&e.every((n,o)=>n.x===t[o].x&&n.y===t[o].y)}function dr(e,t){if(e.type!=="gaArea"||!sn(e.points,t.outline))return!1;let n=e.holes??[],o=t.holes??[];return n.length===o.length&&n.every((i,a)=>sn(i,o[a]))}function dn(e,t){let n=e.filter(r=>r.type==="section"),o="referenceInventorySource"in t?t.referenceInventorySource?.logicalSectionId:void 0,i=L(t);return(o?n.find(r=>(r.logicalSectionId??r.id)===o&&(dr(t,r)||F(i,r.outline,r.holes))):void 0)??n.find(r=>F(i,r.outline,r.holes))}function E(e){return e.floors&&e.floors.length?e.floors:[{id:"floor-0",name:"Main",objects:e.objects,focalPoint:e.focalPoint,referenceImage:e.referenceImage,backgroundImage:e.backgroundImage}]}function B(e){return e.floors&&e.floors.length?e.floors.flatMap(t=>t.objects):e.objects}var ke=40;function un(e,t){let n=t?.freeText==="exclude",o=1/0,i=1/0,a=-1/0,r=-1/0,s=(c,l)=>{c<o&&(o=c),l<i&&(i=l),c>a&&(a=c),l>r&&(r=l)};for(let c of B(e))if(c.type==="row"){let l=new Map((c.overrides??[]).map(d=>[d.index,d]));Se(c).forEach((d,f)=>{let b=l.get(f);b?.skip||s(d.x+(b?.dx??0),d.y+(b?.dy??0))})}else if(c.type==="gaArea")for(let l of c.points)s(l.x,l.y);else if(c.type==="section")for(let l of c.outline)s(l.x,l.y);else if(c.type==="decorImage")s(c.x,c.y),s(c.x+c.width,c.y+c.height);else if(c.type==="shape")if(c.points&&c.points.length)for(let l of c.points)s(l.x,l.y);else c.x!=null&&c.y!=null&&c.width!=null&&c.height!=null&&(s(c.x,c.y),s(c.x+c.width,c.y+c.height));else if(c.type==="table"){let l=ae+rr,d=c.shape==="round"?(c.radius??40)+l:Math.max((c.width??80)/2,(c.height??50)/2)+l;s(c.center.x-d,c.center.y-d),s(c.center.x+d,c.center.y+d)}else if(c.type==="booth"){let l=Math.max(c.width,c.height)/2;s(c.center.x-l,c.center.y-l),s(c.center.x+l,c.center.y+l)}else if(c.type==="text"){if(n)continue;let l=qt(c);s(c.position.x,c.position.y),s(c.position.x+l.width,c.position.y+l.height)}for(let c of[e.referenceImage,e.backgroundImage]){if(!c)continue;let{center:l,width:d}=c,f=d*3/4;s(l.x-d/2,l.y-f/2),s(l.x+d/2,l.y+f/2)}if(!isFinite(o)){let c=e.focalPoint??{x:0,y:0};return{x:c.x-200,y:c.y-200,width:400,height:400}}return{x:o-ke,y:i-ke,width:a-o+ke*2,height:r-i+ke*2}}var xe=[{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"}],Rs=new Map(xe.map(e=>[e.key,e]));var ur=[{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"}],As=new Map(ur.map(e=>[e.key,e]));var se=8,pt=24,fr=["reference-focal","bar","entrance","exit","restroom","screen","sound","concession","coat","wall","rail","suite","obstruction"],Ms=new Set(fr);var u=class extends Error{constructor(n,o,i={}){super(o);this.code=n;this.details=i;this.name="ChartOperationError"}};function C(e,t){let n=E(e),o=t?n.find(i=>i.id===t):n[0];if(!o)throw new u("floor_not_found",`Unknown chart floor: ${t}`,{floorId:t});return{floorId:o.id,objects:o.objects}}function j(e,t){if(!e.categories.some(n=>n.key===t))throw new u("category_not_found",`Unknown chart category: ${t}. Call get_chart to list valid category keys.`,{categoryKey:t})}function A(e,t,n,o){let i=new Set([...o,...e.categories.map(a=>a.key),...e.zones?.map(a=>a.id)??[],...e.floors?.map(a=>a.id)??[],...e.floors?.length?e.floors.flatMap(a=>a.objects.map(r=>r.id)):e.objects.map(a=>a.id)]);for(let a=0;a<100;a++){let r=n(t);if(r&&!i.has(r))return o.add(r),r}throw new u("id_generation_failed",`Unable to allocate a unique ${t} id`)}function gr(e){let t=e.slice().sort((a,r)=>a.x-r.x||a.y-r.y);if(t.length<3)return t;let n=(a,r,s)=>(r.x-a.x)*(s.y-a.y)-(r.y-a.y)*(s.x-a.x),o=[];for(let a of t){for(;o.length>=2&&n(o[o.length-2],o[o.length-1],a)<=0;)o.pop();o.push(a)}let i=[];for(let a=t.length-1;a>=0;a--){let r=t[a];for(;i.length>=2&&n(i[i.length-2],i[i.length-1],r)<=0;)i.pop();i.push(r)}return o.pop(),i.pop(),o.concat(i)}function br(e,t){if(!e.length)return e;let n={x:e.reduce((o,i)=>o+i.x,0)/e.length,y:e.reduce((o,i)=>o+i.y,0)/e.length};return e.map(o=>{let i=o.x-n.x,a=o.y-n.y,r=Math.hypot(i,a)||1;return{x:o.x+i/r*t,y:o.y+a/r*t}})}function ee(e){let t=[];for(let o of e)o.type==="row"?t.push(...z(o).map(i=>({x:i.x,y:i.y}))):o.type==="table"?t.push(...W(o).map(i=>({x:i.x,y:i.y}))):o.type==="gaArea"?t.push(...o.points):o.type==="booth"&&t.push(o.center);if(t.length<3)return null;let n=br(gr(t),22);return n.length>=3?n:null}function Te(e,t){let n=C(e,t),o=E(e).find(i=>i.id===n.floorId);return{...e,objects:n.objects,floors:void 0,focalPoint:o.focalPoint,referenceImage:o.referenceImage,backgroundImage:o.backgroundImage}}var fn=24,gn=80;function yt(e,t){let n=e.normalize("NFKC").trim();if(n.length>fn)throw new u("invalid_operation",`${t} displayed type must be at most ${fn} characters`);return n}function Fe(e,t){if(e.displayType===void 0)return!1;let n=yt(e.displayType,t);return n?(e.displayType=n,!1):(delete e.displayType,!0)}function ce(e,t){if(e.displayLabel===void 0)return!1;let n=e.displayLabel.normalize("NFKC").trim();if(n.length>gn)throw new u("invalid_operation",`${t} displayed label must be at most ${gn} characters`);return n?(e.displayLabel=n,!1):(delete e.displayLabel,!0)}function T(e,t){let n=e.trim().toLowerCase();if(!/^#[0-9a-f]{6}$/.test(n))throw new u("invalid_operation",`${t} must use a six-digit hex color`);return n}function bn(e,t){if(!Number.isFinite(e)||e<se||e>pt)throw new u("invalid_operation",`${t} label size must be from ${se} to ${pt}`)}function le(e,t){e.size!==void 0&&e.size!==null&&bn(e.size,t),e.color!==void 0&&e.color!==null&&T(e.color,`${t} label color`)}function Ne(e,t){if(e?.positionPreset!==void 0&&!["start","end","both","none"].includes(e.positionPreset))throw new u("invalid_operation",`${t} label positionPreset must be one of start, end, both, none`);let n=e?.labelStyle;n&&(n.size!==void 0&&bn(n.size,t),n.color!==void 0&&T(n.color,`${t} label color`))}function De(e,t){let n=e?structuredClone(e):{},o=n.labelStyle?{...n.labelStyle}:{};return t.size===null?delete o.size:t.size!==void 0&&(o.size=t.size),t.color===null?delete o.color:t.color!==void 0&&(o.color=T(t.color,"Label color")),o.size===void 0&&o.color===void 0?delete n.labelStyle:n.labelStyle=o,t.visible!==void 0&&(n.visible=t.visible),Object.keys(n).length?n:void 0}function mt(e,t,n){let o=t.normalize("NFKC").trim();if(!o||o.length>80)throw new u("invalid_operation","Zone labels must contain 1 to 80 characters");if((e.zones??[]).some(i=>i.id!==n&&i.label.normalize("NFKC").trim().toLocaleLowerCase("en")===o.toLocaleLowerCase("en")))throw new u("invalid_operation",`Zone label already exists: ${o}`);return o}function wt(e,t){if(!Number.isFinite(e?.x)||!Number.isFinite(e?.y))throw new u("invalid_operation",`${t} must contain finite x and y values`);return{x:e.x,y:e.y}}function q(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)}var X=Math.PI/180,J=Math.PI/180;function te(e){return e.type==="row"||e.type==="table"?e.seatCount:e.type==="gaArea"?Math.max(0,Math.floor(e.capacity)):e.type==="booth"?1:0}var hr=2e6,pr=/^data:image\/(?:png|jpe?g|webp|gif|avif);base64,[a-z0-9+/]+={0,2}$/i,yr=/[\s"'<>`\\]/;function hn(e){if(typeof e!="string"||!e||e.length>2e6||e!==e.trim())return!1;if(e.startsWith("data:"))return pr.test(e);if(yr.test(e))return!1;try{let t=new URL(e);return t.protocol==="https:"&&!t.username&&!t.password}catch{return!1}}function Z(e){let t=e.trim();return hn(t)?t:null}function ve(e){if(e.floors?.length){let t=e.floors[0];e.objects=t.objects,e.focalPoint=t.focalPoint,e.referenceImage=t.referenceImage,e.backgroundImage=t.backgroundImage}return e}var mr=0,Ge=120,St=4;function wr(e){if(!Number.isFinite(e)||e<mr||e>Ge)throw new u("invalid_operation","Floor base height must be a number from 0 to 120 metres")}function Sr(e,t){let n=E(e);if(n.length>=5)throw new u("invalid_operation","A chart can contain at most five physical floors");let o=(t.name??String(n.length+1)).normalize("NFKC").trim();if(!o||o.length>80)throw new u("invalid_operation","Floor names must contain 1 to 80 characters");if(n.some(c=>c.name.toLocaleLowerCase("en")===o.toLocaleLowerCase("en")))throw new u("invalid_operation",`Floor name already exists: ${o}`);e.floors?.length||(e.floors=[{id:"floor-0",name:"1",objects:e.objects,baseHeightM:0,focalPoint:e.focalPoint,referenceImage:e.referenceImage,backgroundImage:e.backgroundImage}]);let a=e.floors[e.floors.length-1].baseHeightM??Math.min(Ge,(e.floors.length-1)*St),r=Math.min(Ge,a+St),s=A(e,"floor",t.idFactory,new Set);return e.floors.push({id:s,name:o,baseHeightM:r,objects:[],focalPoint:{...e.focalPoint}}),ve(e),{changed:!0,floorId:s,floorCount:e.floors.length,baseHeightM:r}}function xr(e,t){let n=E(e),o=n.find(r=>r.id===t.floorId);if(!o)throw new u("floor_not_found",`Unknown chart floor: ${t.floorId}`,{floorId:t.floorId});let i=t.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(r=>r.id!==o.id&&r.name.toLocaleLowerCase("en")===i.toLocaleLowerCase("en")))throw new u("invalid_operation",`Floor name already exists: ${i}`);let a=o.name!==i;return a&&(o.name=i),{changed:a,floorId:o.id,floorName:i}}function vr(e,t){if(!e.floors?.length)throw new u("invalid_operation","A single-floor chart has an implicit base height of 0 metres");let n=e.floors.find(i=>i.id===t.floorId);if(!n)throw new u("floor_not_found",`Unknown chart floor: ${t.floorId}`,{floorId:t.floorId});wr(t.baseHeightM);let o=n.baseHeightM!==t.baseHeightM;return o&&(n.baseHeightM=t.baseHeightM,n.physical3dProvenance={...n.physical3dProvenance,baseHeightM:{status:"confirmed",source:"user-review",note:"Physical floor height reviewed through the shared Designer/Copilot operation."}}),{changed:o,floorId:n.id,baseHeightM:t.baseHeightM}}function Ir(e,t){if(!e.floors?.length)throw new u("invalid_operation","A single-floor chart cannot remove its only floor");let n=e.floors.findIndex(i=>i.id===t.floorId);if(n<0)throw new u("floor_not_found",`Unknown chart floor: ${t.floorId}`,{floorId:t.floorId});let[o]=e.floors.splice(n,1);if(e.floors.length===1){let[i]=e.floors;e.objects=i.objects,e.focalPoint=i.focalPoint,e.referenceImage=i.referenceImage,e.backgroundImage=i.backgroundImage,e.floors=void 0}else ve(e);return{changed:!0,floorId:o.id,removedObjects:o.objects.length,floorCount:E(e).length}}function Cr(e,t){if((e.zones?.length??0)>=100)throw new u("invalid_operation","A chart supports at most 100 zones");let n={id:A(e,"zone",t.idFactory,new Set),label:mt(e,t.label),color:T(t.color,"Zone color"),...t.focalPoint?{focalPoint:wt(t.focalPoint,"Zone focal point")}:{}};return(e.zones??=[]).push(n),{changed:!0,zone:structuredClone(n)}}function Or(e,t){if(!t.updates.length)throw new u("invalid_operation","At least one zone update is required");let n=t.updates.map(c=>c.zoneId);if(new Set(n).size!==n.length)throw new u("invalid_operation","Zone ids must be unique");let o=new Map((e.zones??[]).map(c=>[c.id,c])),i=n.filter(c=>!o.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(e),r=new Map((a.zones??[]).map(c=>[c.id,c]));for(let c of t.updates){if(!Object.keys(c.patch).length)throw new u("invalid_operation",`Zone ${c.zoneId} has no changes`);let d=r.get(c.zoneId);c.patch.label!==void 0&&(d.label=mt(a,c.patch.label,d.id)),c.patch.color!==void 0&&(d.color=T(c.patch.color,"Zone color")),c.patch.focalPoint!==void 0&&(d.focalPoint=wt(c.patch.focalPoint,"Zone focal point"))}let s=JSON.stringify(a.zones??[])!==JSON.stringify(e.zones??[]);return s&&(e.zones=a.zones),{changed:s,zoneIds:n,zones:n.map(c=>structuredClone(r.get(c)))}}function Pr(e,t){let n=(e.zones??[]).findIndex(a=>a.id===t.zoneId);if(n<0)throw new u("object_not_found",`Unknown chart zone: ${t.zoneId}`,{zoneId:t.zoneId});let o=E(e).flatMap(a=>a.objects).filter(a=>a.type==="section"&&a.zone===t.zoneId);if(o.length&&t.clearSectionAssignments!==!0)throw new u("invalid_operation",`Zone ${t.zoneId} is assigned to ${o.length} section(s)`,{zoneId:t.zoneId,sectionIds:o.map(a=>a.id),requiresClearSectionAssignments:!0});let i=o.map(a=>a.id);for(let a of o)delete a.zone;return e.zones.splice(n,1),e.zones.length||delete e.zones,ve(e),{changed:!0,zoneId:t.zoneId,clearedSectionIds:i,zoneCount:e.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 $e(e){let t=new Map,n=Math.max(0,Math.floor(e.seatCount)),o=new Map((e.overrides??[]).filter(a=>Number.isInteger(a.index)&&a.index>=0&&a.index<e.seatCount).map(a=>[a.index,a])),i=(a,r=1)=>{a&&r>0&&t.set(a,(t.get(a)??0)+r)};i(e.categoryKey,n-o.size);for(let a of o.values())a.skip||i(a.categoryKey??e.categoryKey);return t}var pn="__sl_ga__",ne=1e5,de=1e5;function _r(e,t){return`${pn}${encodeURIComponent(e)}__${t+1}`}function xt(e){let t=e.inventorySegments;if(t===void 0)return!0;if(!Array.isArray(t)||t.length<1||t.length>256)return!1;let n=0,o=new Map;for(let i of t){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>ne||(n+=i.count,n>ne))return!1;let a=o.get(i.sourceAreaId)??[],r=i.startIndex+i.count;if(a.some(s=>i.startIndex<s.end&&r>s.start))return!1;a.push({start:i.startIndex,end:r}),o.set(i.sourceAreaId,a)}return n===e.capacity}function ze(e){let t=Math.min(ne,Math.max(0,Math.floor(e.capacity)));return e.inventorySegments===void 0?t?[{sourceAreaId:e.id,startIndex:0,count:t}]:[]:xt(e)?e.inventorySegments.map(n=>({...n})):[]}function Y(e){return ze(e).flatMap(t=>Array.from({length:t.count},(n,o)=>_r(t.sourceAreaId,t.startIndex+o)))}function vt(e,t){if(e.inventorySegments===void 0||t===e.capacity)return e.inventorySegments;if(t<e.capacity)return;let n=ze(e);if(!n.length)return;let o=t-e.capacity;if(!o)return n;let a=n.filter(s=>s.sourceAreaId===e.id).reduce((s,c)=>Math.max(s,c.startIndex+c.count),0),r=n[n.length-1];if(r?.sourceAreaId===e.id&&r.startIndex+r.count===a)r.count+=o;else{if(n.length>=256)return;n.push({sourceAreaId:e.id,startIndex:a,count:o})}return n}function Be(e){return e.startsWith(pn)}var Rr="__ungrouped__";function Ar(e){return e.type==="row"?z(e).map(t=>t.label):e.type==="table"?W(e).map(t=>t.label):e.type==="booth"?ln(e).map(t=>t.label):e.type==="gaArea"?Y(e):[]}function Mr(e){return e.type==="row"||e.type==="table"||e.type==="booth"||e.type==="gaArea"}function Ie(e){let t=B(e),n=t.filter(r=>r.type==="section"),o=new Map;for(let r of n){let s=r.logicalSectionId??r.id;o.get(s)||o.set(s,{id:s,label:r.displayLabel||r.label||"Section",zone:r.zone,seatCount:0,objectIds:[],seatLabels:[]})}let i={id:Rr,label:"Other seats",seatCount:0,objectIds:[],seatLabels:[]},a=new Map;for(let r of t){if(!Mr(r))continue;let s=Ar(r);if(s.length===0)continue;let c=dn(t,r),l=c?o.get(c.logicalSectionId??c.id):i;l.seatCount+=s.length,l.objectIds.push(r.id),l.seatLabels.push(...s),a.set(r.id,l.id)}return{sections:[...o.values()],ungrouped:i.objectIds.length?i:null,objectToSection:a}}var oe={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 Ce(e,t,n,o,i,a,r=0){return{type:"row",id:e,label:t,origin:{x:-(o-1)*i/2,y:n},rotation:0,curve:r,seatCount:o,seatSpacing:i,categoryKey:a}}function jr(e,t,n,o,i,a){return{type:"table",id:e,label:t,center:n,shape:"round",seatCount:o,rotation:0,radius:i,categoryKey:a}}function yn(e,t,n,o,i,a){let r=n/2,s=o/2;return{type:"gaArea",id:e,label:t,points:[{x:-r,y:-s},{x:r,y:-s},{x:r,y:s},{x:-r,y:s}],capacity:i,categoryKey:a}}function Lr(e,t,n,o,i){let a=n*2,r=[];for(let s=0;s<a;s++){let c=s%2===0,l=c?["wheelchair"]:["companion"];r.push(c?{index:s,accessibility:l,wheelchairSpaceType:"no-seat"}:{index:s,accessibility:l})}return{type:"row",id:e,label:t,origin:{x:-(a-1)*o/2,y:0},rotation:0,curve:0,seatCount:a,seatSpacing:o,categoryKey:i,overrides:r}}var mn=[{key:"balcony",label:"Balcony",icon:"\u2312",blurb:"Insert four curved rows inside a section.",categories:[oe.balcony],sectionLabel:"Balcony",build:()=>[Ce("blk-b0","A",-45,18,24,"balcony",18),Ce("blk-b1","B",-15,20,24,"balcony",18),Ce("blk-b2","C",15,22,24,"balcony",18),Ce("blk-b3","D",45,24,24,"balcony",18)]},{key:"rows",label:"Row block",icon:"\u2261",blurb:"Insert six straight rows inside a section.",categories:[oe.standard],sectionLabel:"Section",build:()=>Array.from({length:6},(e,t)=>Ce(`blk-r${t}`,"ABCDEF"[t],-80+t*32,12,26,"standard"))},{key:"ga-pen",label:"GA pen",icon:"\u25A8",blurb:"Insert a standing area for 250 people.",categories:[oe.standard],build:()=>[yn("blk-ga","Standing",320,180,250,"standard")]},{key:"tables",label:"Tables",icon:"\u283F",blurb:"Insert six round tables with eight bookable seats each.",categories:[oe.premium],build:()=>Array.from({length:6},(e,t)=>jr(`blk-t${t}`,`T${t+1}`,{x:-150+t%3*150,y:t<3?-70:70},8,34,"premium"))},{key:"boxes",label:"Boxes",icon:"\u25A3",blurb:"Insert two private boxes with four bookable seats each.",categories:[oe.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:[oe.standard],build:()=>[yn("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:[oe.standard],build:()=>[Lr("blk-wc","A",4,40,"standard")]}];function U(e){let t="",n=e;do t=String.fromCharCode(65+n%26)+t,n=Math.floor(n/26)-1;while(n>=0);return t}function wn(e){if(!/^[A-Z]+$/.test(e))return null;let t=0;for(let n of e)t=t*26+(n.charCodeAt(0)-64);return t-1}var Sn="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",xn=[{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:Sn},{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:Sn},{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 kr=new Map(xn.map(e=>[e.key,e]));function vn(e){return typeof e=="string"&&kr.has(e)}var ec=xn.map(e=>e.key);function It(e){let t=(e%360+360)%360,n=t>=180?t-360:t;return Object.is(n,-0)||Math.abs(n)<1e-9?0:n}function In(e,t,n){let o=i=>({x:i.x+t,y:i.y+n});switch(e.type){case"row":e.origin=o(e.origin),e.path&&(e.path={start:o(e.path.start),control1:o(e.path.control1),control2:o(e.path.control2),end:o(e.path.end)});break;case"table":case"booth":e.center=o(e.center);break;case"text":e.position=o(e.position);break;case"gaArea":e.points=e.points.map(o),e.holes&&(e.holes=e.holes.map(i=>i.map(o)));break;case"section":e.outline=e.outline.map(o),e.sourceOutline&&(e.sourceOutline=e.sourceOutline.map(o)),e.outlinePath&&(e.outlinePath=Zt(e.outlinePath,t,n)),e.holes&&(e.holes=e.holes.map(i=>i.map(o)));break;case"shape":e.points&&(e.points=e.points.map(o)),e.x!=null&&(e.x+=t),e.y!=null&&(e.y+=n);break;case"decorImage":e.x+=t,e.y+=n;break}}function Er(e,t){return Math.abs(e.x-t.x)<=1e-7&&Math.abs(e.y-t.y)<=1e-7}function Oe(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)}function Ue(e,t,n){let o=Oe(t,n,e);return Math.abs(o)>1e-7?!1:e.x>=Math.min(t.x,n.x)-1e-7&&e.x<=Math.max(t.x,n.x)+1e-7&&e.y>=Math.min(t.y,n.y)-1e-7&&e.y<=Math.max(t.y,n.y)+1e-7}function Tr(e,t,n,o){let i=Oe(e,t,n),a=Oe(e,t,o),r=Oe(n,o,e),s=Oe(n,o,t);return(i>1e-7&&a<-1e-7||i<-1e-7&&a>1e-7)&&(r>1e-7&&s<-1e-7||r<-1e-7&&s>1e-7)?!0:Math.abs(i)<=1e-7&&Ue(n,e,t)||Math.abs(a)<=1e-7&&Ue(o,e,t)||Math.abs(r)<=1e-7&&Ue(e,n,o)||Math.abs(s)<=1e-7&&Ue(t,n,o)}function Fr(e){return e.reduce((t,n,o)=>{let i=e[(o+1)%e.length];return t+n.x*i.y-i.x*n.y},0)}function Nr(e){for(let t=0;t<e.length;t+=1){let n=(t+1)%e.length;for(let o=t+1;o<e.length;o+=1){let i=(o+1)%e.length;if(!(t===o||n===o||i===t)&&Tr(e[t],e[n],e[o],e[i]))return!0}}return!1}function Cn(e){return e.length<3?{ok:!1,code:"too_few_vertices",message:"Add at least three vertices to create a polygon."}:e.length>256?{ok:!1,code:"too_many_vertices",message:"A polygon can contain at most 256 vertices."}:e.some(t=>!Number.isFinite(t.x)||!Number.isFinite(t.y)||Math.abs(t.x)>1e7||Math.abs(t.y)>1e7)?{ok:!1,code:"invalid_coordinate",message:"Every polygon vertex must use a finite coordinate inside the safe chart range."}:e.some((t,n)=>Er(t,e[(n+1)%e.length]))?{ok:!1,code:"duplicate_vertex",message:"Move or remove duplicate neighbouring vertices."}:Math.abs(Fr(e))<2?{ok:!1,code:"degenerate_polygon",message:"The polygon needs a visible enclosed area."}:Nr(e)?{ok:!1,code:"self_intersection",message:"Polygon edges cannot cross or touch each other."}:{ok:!0}}function He(e){return(e.type==="shape"||e.type==="text")&&e.referenceAnnotationSource?.kind==="direct-landmark-v1"&&(e.referenceAnnotationSource.ownership="organizer"),e}function Vr(e,t){let n=C(e,t.floorId),o=[...new Set(t.tableIds)];if(!o.length)throw new u("invalid_operation","At least one table id is required");let i=o.map(h=>n.objects.find(y=>y.type==="table"&&y.id===h)),a=o.filter((h,y)=>!i[y]);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 r=structuredClone(t.patch);if(!Object.keys(r).length)throw new u("invalid_operation","At least one table change is required");if(r.label!==void 0){if(r.label=r.label.normalize("NFKC").trim(),o.length!==1)throw new u("invalid_operation","label can be changed only for one table at a time");if(!r.label||r.label.length>80)throw new u("invalid_operation","Table labels must contain 1 to 80 characters")}r.categoryKey!==void 0&&j(e,r.categoryKey);let s=r.seatCount!==void 0,c=r.seatCountsBySide!==void 0;if(c){if(r.sides!==void 0)throw new u("invalid_operation","Use seatCountsBySide for exact rectangular counts; do not also supply legacy sides");if(r.shape==="round")throw new u("invalid_operation","seatCountsBySide can be used only with rectangular tables");let h=["top","bottom","left","right"],y=Object.keys(r.seatCountsBySide);if(y.length!==h.length||y.some(S=>!h.includes(S)))throw new u("invalid_operation","seatCountsBySide must contain exactly top, bottom, left, and right");for(let S of h){let v=r.seatCountsBySide[S];if(!Number.isInteger(v)||v<0||v>40)throw new u("invalid_operation",`seatCountsBySide.${S} must be a whole number from 0 to 40`)}let w=h.reduce((S,v)=>S+r.seatCountsBySide[v],0);if(w<1||w>40)throw new u("invalid_operation","Rectangular table side counts must total from 1 to 40 chairs");if(s&&r.seatCount!==w)throw new u("invalid_operation",`seatCount must equal the ${w}-chair seatCountsBySide total`);r.seatCount=w,r.sides=h.filter(S=>r.seatCountsBySide[S]>0)}if(r.seatCount!==void 0&&(!Number.isInteger(r.seatCount)||r.seatCount<1||r.seatCount>40))throw new u("invalid_operation","seatCount must be an integer from 1 to 40");if(r.shape!==void 0&&r.shape!=="round"&&r.shape!=="rect")throw new u("invalid_operation","Table shape must be round or rect");if(r.bookAsWhole===!0&&r.variableOccupancy===!0)throw new u("invalid_operation","A table cannot use whole-table and variable-occupancy selling at the same time");if(r.variableOccupancy===!1&&(r.minOccupancy!==void 0||r.maxOccupancy!==void 0))throw new u("invalid_operation","Guest bounds can be supplied only with variable-occupancy selling");let l=(h,y,w,S)=>{if(y!==void 0&&(!Number.isFinite(y)||y<w||y>S))throw new u("invalid_operation",`${String(h)} must be from ${w} to ${S}`)};if(l("rotation",r.rotation,0,360),l("radius",r.radius,24,160),l("seatArc",r.seatArc,120,360),l("width",r.width,40,320),l("height",r.height,30,240),r.minOccupancy!==void 0&&(!Number.isInteger(r.minOccupancy)||r.minOccupancy<1||r.minOccupancy>40))throw new u("invalid_operation","minOccupancy must be a whole number from 1 to 40");if(r.maxOccupancy!==void 0&&(!Number.isInteger(r.maxOccupancy)||r.maxOccupancy<1||r.maxOccupancy>40))throw new u("invalid_operation","maxOccupancy must be a whole number from 1 to 40");if(r.sides!==void 0){let h=new Set(["top","bottom","left","right"]);if(!r.sides.length||r.sides.length>4||new Set(r.sides).size!==r.sides.length||r.sides.some(y=>!h.has(y)))throw new u("invalid_operation","Table sides must contain one to four unique perimeter sides")}let d=ce(r,"Table"),f=Fe(r,"Table"),b=i.map(h=>{if(h.seatCountsBySide&&!c&&(s||t.patch.sides!==void 0))throw new u("invalid_operation",`Table "${h.label}" has exact per-side counts; update seatCountsBySide instead of aggregate seatCount or legacy sides`,{tableId:h.id});let y=structuredClone(h);if(Object.assign(y,r),y.shape==="round"&&delete y.seatCountsBySide,y.overrides&&r.seatCount!==void 0&&(y.overrides=y.overrides.filter(w=>w.index<y.seatCount),y.overrides.length||delete y.overrides),r.bookAsWhole===!1&&delete y.bookAsWhole,r.variableOccupancy===!1&&(delete y.variableOccupancy,delete y.minOccupancy,delete y.maxOccupancy),y.bookAsWhole||delete y.bookAsWhole,y.variableOccupancy||delete y.variableOccupancy,y.bookAsWhole&&y.variableOccupancy)throw new u("invalid_operation",`Table "${y.label}" cannot use whole-table and variable-occupancy selling at the same time`,{tableId:y.id});if((y.bookAsWhole||y.variableOccupancy)&&y.overrides?.length)throw new u("invalid_operation",`Table "${y.label}" has individual-chair overrides; reset them before choosing grouped table selling`,{tableId:y.id,overriddenChairIndices:y.overrides.map(w=>w.index)});if(y.bookAsWhole)delete y.minOccupancy,delete y.maxOccupancy;else if(y.variableOccupancy){if(!Number.isInteger(y.minOccupancy)||!Number.isInteger(y.maxOccupancy)||y.minOccupancy<1||y.maxOccupancy<y.minOccupancy||y.maxOccupancy>y.seatCount)throw new u("invalid_operation",`Table "${y.label}" needs whole-number minimum and maximum guests from 1 to its ${y.seatCount}-chair capacity`,{tableId:y.id,seatCount:y.seatCount})}else{if(r.minOccupancy!==void 0||r.maxOccupancy!==void 0)throw new u("invalid_operation","Guest bounds can be changed only on a variable-occupancy table",{tableId:y.id});delete y.minOccupancy,delete y.maxOccupancy}if(f&&delete y.displayType,d&&delete y.displayLabel,y.shape==="rect"){if(y.width??=80,y.height??=50,y.seatCountsBySide){let w=["top","bottom","left","right"],S=w.reduce((v,_)=>v+y.seatCountsBySide[_],0);if(S!==y.seatCount)throw new u("invalid_operation",`Table "${y.label}" side counts total ${S}, but seatCount is ${y.seatCount}`,{tableId:y.id,seatCount:y.seatCount,seatCountsBySide:y.seatCountsBySide});y.sides=w.filter(v=>y.seatCountsBySide[v]>0)}}else y.radius??=40;if((y.bookAsWhole||y.variableOccupancy)&&Be(y.label))throw new u("invalid_operation",`Grouped table label "${y.label}" uses SeatLayer's reserved GA namespace`,{tableId:y.id});return y}),g=new Map(b.map(h=>[h.id,h])),p=new Set(o),m=new Map;for(let h of E(e))for(let y of h.objects){let w=y.type==="table"?g.get(y.id)??y:y,S=[];w.type==="row"?S=z(w).map(v=>v.label):w.type==="table"?S=w.bookAsWhole||w.variableOccupancy?[w.label]:W(w).map(v=>v.label):w.type==="booth"?S=[w.label]:w.type==="gaArea"&&(S=Y(w));for(let v of S){let _=m.get(v);if(_&&(p.has(_)||p.has(w.id)))throw new u("invalid_operation",`Inventory label "${v}" is already in use; grouped table labels must be unique`,{tableIds:o,inventoryLabel:v,conflictingObjectIds:[_,w.id]});m.set(v,_??w.id)}}let x=!1,I=["bookAsWhole","variableOccupancy","minOccupancy","maxOccupancy","displayLabel","displayType","seatCountsBySide","overrides"];for(let[h,y]of i.entries()){let w=b[h],S=JSON.stringify(y);for(let v of I)v in w||delete y[v];Object.assign(y,w),JSON.stringify(y)!==S&&(x=!0)}return{floorId:n.floorId,changed:x,tableIds:o}}function qr(e,t){let n=C(e,t.floorId),o=[...new Set(t.boothIds)];if(!o.length)throw new u("invalid_operation","At least one booth id is required");let i=o.map(g=>n.objects.find(p=>p.type==="booth"&&p.id===g)),a=o.filter((g,p)=>!i[p]);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 r=structuredClone(t.patch);if(!Object.keys(r).length)throw new u("invalid_operation","At least one booth change is required");if(r.label!==void 0){if(r.label=r.label.normalize("NFKC").trim(),o.length!==1)throw new u("invalid_operation","label can be changed only for one booth at a time");if(!r.label||r.label.length>80)throw new u("invalid_operation","Booth labels must contain 1 to 80 characters")}r.categoryKey!==void 0&&j(e,r.categoryKey);let s=(g,p,m,x)=>{if(p!==void 0&&(!Number.isFinite(p)||p<m||p>x))throw new u("invalid_operation",`${g} must be from ${m} to ${x}`)};s("width",r.width,30,400),s("height",r.height,30,400),s("rotation",r.rotation,0,360);let c=r.points===null;if(r.points!=null){if(o.length!==1)throw new u("invalid_operation","points can be changed only for one booth at a time");let g=Cn(r.points);if(!g.ok)throw new u("invalid_operation",g.message??"The booth outline is not a valid simple polygon")}let l=r.points!=null?r.points.map(g=>({x:g.x,y:g.y})):void 0;delete r.points;let d=ce(r,"Booth"),f=Fe(r,"Booth"),b=!1;for(let g of i){let p=JSON.stringify(g);Object.assign(g,r),d&&delete g.displayLabel,f&&delete g.displayType,c?delete g.points:l&&(g.points=l),JSON.stringify(g)!==p&&(b=!0)}return{floorId:n.floorId,changed:b,boothIds:o}}function Jr(e,t){let n=C(e,t.floorId),o=[...new Set(t.gaAreaIds)];if(!o.length)throw new u("invalid_operation","At least one GA area id is required");let i=o.map(d=>n.objects.find(f=>f.type==="gaArea"&&f.id===d)),a=o.filter((d,f)=>!i[f]);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 r=structuredClone(t.patch);if(!Object.keys(r).length)throw new u("invalid_operation","At least one GA area change is required");if(r.label!==void 0){if(r.label=r.label.normalize("NFKC").trim(),o.length!==1)throw new u("invalid_operation","label can be changed only for one GA area at a time");if(!r.label||r.label.length>80)throw new u("invalid_operation","GA area labels must contain 1 to 80 characters")}if(r.categoryKey!==void 0&&j(e,r.categoryKey),r.capacity!==void 0&&(!Number.isInteger(r.capacity)||r.capacity<1||r.capacity>1e5))throw new u("invalid_operation","capacity must be an integer from 1 to 100000");if(r.cornerRadius!==void 0&&(!Number.isFinite(r.cornerRadius)||r.cornerRadius<0||r.cornerRadius>2e3))throw new u("invalid_operation","cornerRadius must be from 0 to 2000");let s=ce(r,"GA area"),c=Fe(r,"GA area");if(r.capacity!==void 0)for(let d of i){if(d.inventorySegments!==void 0&&r.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:r.capacity});if(d.inventorySegments!==void 0&&r.capacity>d.capacity&&vt(d,r.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 f=JSON.stringify(d),b=r.capacity===void 0?d.inventorySegments:vt(d,r.capacity);Object.assign(d,r),b!==void 0&&(d.inventorySegments=b),s&&delete d.displayLabel,c&&delete d.displayType,JSON.stringify(d)!==f&&(l=!0)}return{floorId:n.floorId,changed:l,gaAreaIds:o}}function Ve(e,t){if(t.length<3)return 0;let n=i=>F(i,t,void 0),o=0;for(let i of e)n(L(i))&&(i.type==="row"?o+=z(i).length:i.type==="table"?o+=W(i).length:(i.type==="gaArea"||i.type==="booth")&&(o+=te(i)));return o}function Xr(e,t){let n=C(e,t.floorId);if(!t.objectIds.length)throw new u("invalid_operation","At least one chart object id is required");if(new Set(t.objectIds).size!==t.objectIds.length)throw new u("invalid_operation","Chart object ids must be unique");let o=t.objectIds.map(s=>n.objects.find(c=>c.id===s)),i=t.objectIds.filter((s,c)=>!o[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=o,r=new Set(t.objectIds);for(let s=n.objects.length-1;s>=0;s--)r.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+te(c),0),remainingObjectCount:n.objects.length}}function Yr(e,t){let n=C(e,t.floorId),o=[...new Set(t.textIds)];if(!o.length)throw new u("invalid_operation","At least one text id is required");let i=o.map(l=>n.objects.find(d=>d.type==="text"&&d.id===l)),a=o.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 r=structuredClone(t.patch);if(!Object.keys(r).length)throw new u("invalid_operation","At least one text change is required");if(r.text!==void 0){if(r.text=r.text.normalize("NFKC").trim(),o.length!==1)throw new u("invalid_operation","content can be changed only for one text object at a time");if(!r.text||r.text.length>240)throw new u("invalid_operation","Text content must contain 1 to 240 characters")}if(r.fontSize!==void 0&&(!Number.isFinite(r.fontSize)||r.fontSize<8||r.fontSize>72))throw new u("invalid_operation","Text fontSize must be from 8 to 72");if(r.fontFamily!==void 0&&r.fontFamily!==null&&(r.fontFamily=r.fontFamily.normalize("NFKC").trim(),!r.fontFamily||r.fontFamily.length>120))throw new u("invalid_operation","Text fontFamily must contain 1 to 120 characters");if(r.rotation!==void 0&&(!Number.isFinite(r.rotation)||r.rotation<0||r.rotation>360))throw new u("invalid_operation","Text rotation must be from 0 to 360");if(r.color!==void 0&&r.color!==null&&(r.color=T(r.color,"Text color")),r.bold!==void 0&&typeof r.bold!="boolean")throw new u("invalid_operation","Text bold must be a boolean");if(r.italic!==void 0&&typeof r.italic!="boolean")throw new u("invalid_operation","Text italic must be a boolean");if(r.width!==void 0&&r.width!==null&&(!Number.isFinite(r.width)||r.width<40||r.width>1200))throw new u("invalid_operation",`Text width must be from ${40} to ${1200}`);if(r.align!==void 0&&!["left","center","right"].includes(r.align))throw new u("invalid_operation","Text align must be left, center, or right");if(r.lineHeight!==void 0&&(!Number.isFinite(r.lineHeight)||r.lineHeight<.8||r.lineHeight>3))throw new u("invalid_operation",`Text lineHeight must be from ${.8} to ${3}`);if(r.letterSpacing!==void 0&&(!Number.isFinite(r.letterSpacing)||r.letterSpacing<-2||r.letterSpacing>20))throw new u("invalid_operation",`Text letterSpacing must be from ${-2} to ${20}`);if(r.underline!==void 0&&typeof r.underline!="boolean")throw new u("invalid_operation","Text underline must be a boolean");if(r.opacity!==void 0&&(!Number.isFinite(r.opacity)||r.opacity<.1||r.opacity>1))throw new u("invalid_operation",`Text opacity must be from ${.1} to 1`);if(r.background!==void 0&&r.background!==null){r.background.color=T(r.background.color,"Text background color");let{padding:l=6,cornerRadius:d=4,opacity:f=.9}=r.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(f)||f<.1||f>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(r,l))&&i.some(l=>l.semanticKind==="icon"))throw new u("invalid_operation","Text layout fields cannot be applied to venue icons");if(r.iconKey!==void 0){if(!vn(r.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);r.iconKey!==void 0&&(l.iconKey=r.iconKey),r.text!==void 0&&(l.text=r.text),r.fontSize!==void 0&&(l.fontSize=r.fontSize),r.fontFamily===null?delete l.fontFamily:r.fontFamily!==void 0&&(l.fontFamily=r.fontFamily),r.rotation!==void 0&&(l.rotation=r.rotation),r.color===null?delete l.color:r.color!==void 0&&(l.color=r.color),r.bold!==void 0&&(r.bold?l.bold=!0:delete l.bold),r.italic!==void 0&&(r.italic?l.italic=!0:delete l.italic),r.width===null?delete l.width:r.width!==void 0&&(l.width=r.width),r.align!==void 0&&(r.align==="left"?delete l.align:l.align=r.align),r.lineHeight!==void 0&&(r.lineHeight===1.2?delete l.lineHeight:l.lineHeight=r.lineHeight),r.letterSpacing!==void 0&&(r.letterSpacing===0?delete l.letterSpacing:l.letterSpacing=r.letterSpacing),r.underline!==void 0&&(r.underline?l.underline=!0:delete l.underline),r.opacity!==void 0&&(r.opacity===1?delete l.opacity:l.opacity=r.opacity),r.background===null?delete l.background:r.background!==void 0&&(l.background=r.background),JSON.stringify(l)!==d&&(He(l),c=!0)}return{floorId:n.floorId,changed:c,textIds:o}}function Qr(e,t){let n=C(e,t.floorId),o=[...new Set(t.rowIds)],i=o.map(d=>n.objects.find(f=>f.type==="row"&&f.id===d)),a=o.filter((d,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 r=i.slice().sort((d,f)=>d.origin.y-f.origin.y||d.origin.x-f.origin.x),s=d=>d.segmentedRow?.displayLabel??d.displayLabel??d.label,c=on(r.map(d=>({label:s(d)})),t.options),l=!1;return r.forEach((d,f)=>{let b=c[f].label.normalize("NFKC").replace(/\s+/g," ").trim();s(d)!==b&&(l=!0,d.segmentedRow?d.segmentedRow.displayLabel=b:d.displayLabel=b)}),{floorId:n.floorId,changed:l,rows:r.map(d=>({id:d.id,displayLabel:s(d)}))}}function Zr(e,t){let n=mn.find(l=>l.key===t.blockKey);if(!n)throw new u("invalid_operation",`Unknown seating block: ${t.blockKey}`,{blockKey:t.blockKey});let o=C(e,t.floorId),i=new Set,a=n.build().map(l=>structuredClone(l));for(let l of a)l.id=A(e,l.type,t.idFactory,i),In(l,t.center.x,t.center.y);for(let l of n.categories)e.categories.some(d=>d.key===l.key)||e.categories.push({...l});let r=a.filter(l=>l.type==="row");if(r.length){let l=0;for(let d of o.objects){if(d.type!=="row")continue;let f=wn(d.label);f!=null&&(l=Math.max(l,f+1))}for(let d of r)d.label=U(l++)}let s=new Set(o.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),f=d?d[1]:`${l.label} `,b=d?Number.parseInt(d[2],10):1;do b++;while(s.has(`${f}${b}`));l.label=`${f}${b}`}"label"in l&&l.label&&s.add(l.label)}o.objects.push(...a);let c=null;if(n.sectionLabel&&t.wrapInSection!==!1){let l=ee(a);if(l){let d={type:"section",id:A(e,"sec",t.idFactory,i),label:n.sectionLabel,outline:l};o.objects.push(d),c=d.id}}return{floorId:o.floorId,blockKey:n.key,createdIds:[...a.map(l=>l.id),...c?[c]:[]],sectionId:c}}function Wr(e){let t=structuredClone(e);if([t.start,t.control1,t.control2,t.end].some(a=>!Number.isFinite(a.x)||!Number.isFinite(a.y)))throw new u("invalid_operation","Exact row path points must be finite");let o=je(t,97),i=o.slice(1).reduce((a,r,s)=>a+Math.hypot(r.x-o[s].x,r.y-o[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:t,length:i}}function _n(e,t){let n=C(e,t.floorId),o=n.objects.find(d=>d.type==="row"&&d.id===t.rowId);if(!o)throw new u("object_not_found",`Unknown row id: ${t.rowId}`,{rowId:t.rowId});let i=Wr(t.path),a=z(o),r=structuredClone(o);r.path=i.path,r.origin={...i.path.start};let s=z(r),c=a.map((d,f)=>Math.hypot(d.x-s[f].x,d.y-s[f].y)),l=JSON.stringify(o.path)!==JSON.stringify(i.path)||o.origin.x!==i.path.start.x||o.origin.y!==i.path.start.y;return{floorId:n.floorId,rowId:o.id,seatCount:o.seatCount,pathLength:i.length,averageSeatMovement:c.length?c.reduce((d,f)=>d+f,0)/c.length:0,maxSeatMovement:c.length?Math.max(...c):0,convertingFromParametric:!o.path,changed:l,preservesStableId:!0,preservesSeatMetadata:!0,preservesInventoryUnits:o.seatCount}}function ei(e,t){let n=_n(e,t);if(!n.changed)return n;let i=C(e,n.floorId).objects.find(a=>a.type==="row"&&a.id===n.rowId);return i.path=structuredClone(t.path),i.origin={...t.path.start},delete i.arcFanGeneration,delete i.rowBlockGeneration,n}function ti(e,t){let n=e.map((o,i)=>[...o,t[i]]);for(let o=0;o<3;o++){let i=o;for(let r=o+1;r<3;r++)Math.abs(n[r][o])>Math.abs(n[i][o])&&(i=r);if(Math.abs(n[i][o])<1e-9)return null;[n[o],n[i]]=[n[i],n[o]];let a=n[o][o];for(let r=o;r<4;r++)n[o][r]/=a;for(let r=0;r<3;r++){if(r===o)continue;let s=n[r][o];for(let c=o;c<4;c++)n[r][c]-=s*n[o][c]}}return[n[0][3],n[1][3],n[2][3]]}function ni(e){if(e.length<3)return null;let t=[[0,0,0],[0,0,0],[0,0,0]],n=[0,0,0];for(let i of e){if(!Number.isFinite(i.x)||!Number.isFinite(i.y))return null;let a=[2*i.x,2*i.y,1],r=i.x**2+i.y**2;for(let s=0;s<3;s++){n[s]+=a[s]*r;for(let c=0;c<3;c++)t[s][c]+=a[s]*a[c]}}let o=ti(t,n);return o?{x:o[0],y:o[1]}:null}function On(e){let t=((e+180)%360+360)%360-180;return t===-180&&(t=180),t}function Rn(e,t){let n=C(e,t.floorId),o=n.objects.find(g=>g.type==="section"&&g.id===t.sectionId);if(!o)throw new u("object_not_found",`Unknown section id: ${t.sectionId}`,{sectionId:t.sectionId});let i=t.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=E(e).find(g=>g.id===n.floorId),r=t.mode==="outline"?ni(o.outline):t.focalPoint??a.focalPoint??e.focalPoint;if(!r||!Number.isFinite(r.x)||!Number.isFinite(r.y))throw new u("invalid_operation",`Section ${t.mode} fit has no finite center`);let s=n.objects.filter(g=>g.type==="row"&&F(L(g),o.outline,o.holes)),c=s.filter(g=>!!g.path).map(g=>g.id),l=[],d=[],f=i/100;for(let g of s){if(g.path)continue;if(g.seatCount<2){l.push(g.id);continue}let p=Math.hypot(g.origin.x-r.x,g.origin.y-r.y);if(p<=g.seatSpacing/2+1e-6){l.push(g.id);continue}let m=2*Math.asin(g.seatSpacing/(2*p))/X,x=z(g),I=Math.atan2(g.origin.x-r.x,g.origin.y-r.y)/X,y=(g.curve!==0?Math.sign(g.curve):x.length>1&&Math.sign(On(Math.atan2(x[1].x-r.x,x[1].y-r.y)/X-I))||1)*m*(g.seatCount-1);if(Math.abs(y)>320){l.push(g.id);continue}let w=-I,S=g.curve+(y-g.curve)*f,v=g.rotation+On(w-g.rotation)*f,_={...g,curve:S,rotation:v},N=z(_).map((H,K)=>Math.hypot(H.x-x[K].x,H.y-x[K].y));d.push({rowId:g.id,fromCurve:g.curve,targetCurve:y,resultCurve:S,fromRotation:g.rotation,resultRotation:v,rmsMovement:Math.sqrt(N.reduce((H,K)=>H+K**2,0)/N.length),maxMovement:Math.max(...N)})}let b=d.map(g=>g.rmsMovement);return{floorId:n.floorId,sectionId:o.id,mode:t.mode,fitCenter:{...r},strength:i,rows:d,skippedPathRowIds:c,skippedInvalidRowIds:l,averageMovement:b.length?b.reduce((g,p)=>g+p,0)/b.length:0,maxMovement:d.length?Math.max(...d.map(g=>g.maxMovement)):0}}function oi(e,t){let n=Rn(e,t),o=C(e,n.floorId),i=o.objects.find(r=>r.type==="section"&&r.id===n.sectionId),a=!1;for(let r of n.rows){let s=o.objects.find(c=>c.type==="row"&&c.id===r.rowId);(s.curve!==r.resultCurve||s.rotation!==r.resultRotation)&&(s.curve=r.resultCurve,s.rotation=r.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(e,t,n,o){let i=q(e,t,n),a=q(e,t,o),r=q(n,o,e),s=q(n,o,t);return i*a<-1e-9&&r*s<-1e-9}function Pn(e,t){return e.some((n,o)=>{let i=e[(o+1)%e.length];return t.some((a,r)=>An(n,i,a,t[(r+1)%t.length]))})}function ri(e){if(e.length<3||e.length>256||Math.abs(me(e))<1||e.some(t=>!Number.isFinite(t.x)||!Number.isFinite(t.y)))return!1;for(let t=0;t<e.length;t++)for(let n=t+1;n<e.length;n++)if(!(n===t+1||t===0&&n===e.length-1)&&An(e[t],e[(t+1)%e.length],e[n],e[(n+1)%e.length]))return!1;return!0}function qe(e,t,n){let o=C(e,t),i=o.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:o,object:i,outer:i.type==="section"?i.outline:i.points}}function Je(e,t){let{target:n,object:o,outer:i}=qe(e,t.floorId,t.objectId),a=structuredClone(t.points);if(!ri(a))throw new u("invalid_operation","Opening must be a finite, non-self-intersecting shape with 3\u2013256 corners");if(a.some(l=>!F(l,i,void 0)))throw new u("invalid_operation","Every opening corner must stay inside the outer boundary");if(Pn(a,i))throw new u("invalid_operation","Opening edges cannot cross the outer boundary");let r=o.holes??[],s=t.holeIndex??r.length;if(!Number.isInteger(s)||s<0||s>r.length||t.holeIndex!=null&&s>=r.length)throw new u("invalid_operation","Opening not found");for(let l=0;l<r.length;l++){if(l===t.holeIndex)continue;let d=r[l];if(Pn(a,d)||F(a[0],d,void 0)||F(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!==o.id&&l.type!=="section"&&F(L(l),a,void 0));return{floorId:n.floorId,objectId:o.id,objectType:o.type,holeIndex:s,vertexCount:a.length,excludedObjectIds:c.map(l=>l.id),excludedInventoryUnits:Ve(n.objects.filter(l=>l.id!==o.id),a),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function ii(e,t){let n=Je(e,t),{object:o}=qe(e,n.floorId,n.objectId);return o.holes??=[],t.holeIndex==null?o.holes.push(structuredClone(t.points)):o.holes[t.holeIndex]=structuredClone(t.points),{...n,changed:!0}}function Mn(e,t){let{target:n,object:o}=qe(e,t.floorId,t.objectId);if(!Number.isInteger(t.holeIndex)||t.holeIndex<0||t.holeIndex>=(o.holes?.length??0))throw new u("invalid_operation","Opening not found");let i=o.holes[t.holeIndex],a=n.objects.filter(r=>r.id!==o.id&&r.type!=="section"&&F(L(r),i,void 0));return{floorId:n.floorId,objectId:o.id,objectType:o.type,holeIndex:t.holeIndex,vertexCount:i.length,excludedObjectIds:a.map(r=>r.id),excludedInventoryUnits:Ve(n.objects.filter(r=>r.id!==o.id),i),preservesExactOuterPath:o.type==="section"&&!!o.outlinePath}}function ai(e,t){let n=Mn(e,t),{object:o}=qe(e,n.floorId,n.objectId);return o.holes.splice(t.holeIndex,1),o.holes.length||delete o.holes,{...n,changed:!0}}function si(e){let t=Z(e);if(!t)throw new u("invalid_operation","Section view photo must be a safe HTTPS or base64 raster image reference");return t}function jn(e,t){let n=[...new Set(t)];if(!n.length)throw new u("invalid_operation","At least one section id is required");let o=n.map(r=>e.find(s=>s.type==="section"&&s.id===r)),i=n.filter((r,s)=>!o[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=o;return{requested:n,sections:a,logicalSectionIds:[...new Set(a.map(r=>r.logicalSectionId??r.id))]}}function Ln(e,t){let n=C(e,t.floorId),o=jn(n.objects,t.sectionIds),i=Ie(Te(e,n.floorId)),a=new Map(i.sections.map(f=>[f.id,f])),r=new Map(n.objects.map(f=>[f.id,f])),s=o.logicalSectionIds.flatMap(f=>a.get(f)?.objectIds??[]),c=new Set;for(let f of s){let b=r.get(f);if(b)if(b.type==="row"||b.type==="table")for(let g of $e(b).keys())c.add(g);else(b.type==="booth"||b.type==="gaArea")&&c.add(b.categoryKey)}let l=o.logicalSectionIds.every(f=>(a.get(f)?.seatCount??0)>0),d=o.logicalSectionIds.every(f=>a.get(f)?.objectIds.some(b=>{let g=r.get(b);return g?.type==="row"||g?.type==="table"||g?.type==="booth"})===!0);return{floorId:n.floorId,sectionIds:o.requested,logicalSectionIds:o.logicalSectionIds,objectIds:s,categoryApplicable:l,...l&&c.size===1?{categoryKey:[...c][0]}:{},categoryMixed:l&&c.size!==1,viewApplicable:d}}function ci(e,t){j(e,t.categoryKey);let n=Ln(e,t);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 o=C(e,n.floorId),i=new Set(n.objectIds),a=!1,r=0;for(let s of o.objects){if(!i.has(s.id)||s.type!=="row"&&s.type!=="table"&&s.type!=="booth"&&s.type!=="gaArea"||(s.categoryKey!==t.categoryKey&&(s.categoryKey=t.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,r++,a=!0,Object.keys(d).some(f=>f!=="index")?[d]:[]});c.length?s.overrides=c:delete s.overrides}return{...n,changed:a,categoryKey:t.categoryKey,categoryMixed:!1,clearedSeatOverrideCount:r}}function li(e,t){let n=C(e,t.floorId),o=jn(n.objects,t.sectionIds),{requested:i}=o,a=structuredClone(t.patch),r=new Set(["label","displayLabel","entrance","viewFromSeatUrl","viewFromSeatMeta","labelPresentation","labelStyle","zone","elevation","height","rake","surfaceKind","color"]),s=Object.keys(a).filter(g=>!r.has(g));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=si(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&&Ne(a.labelPresentation,"Section"),a.labelStyle!==void 0&&le(a.labelStyle,"Section"),a.zone!==void 0&&a.zone!==null&&!(e.zones??[]).some(g=>g.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=T(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(o.logicalSectionIds),d=c?n.objects.filter(g=>g.type==="section"&&l.has(g.logicalSectionId??g.id)):[],f=new Set,b=!1;for(let g of o.sections){let p=JSON.stringify(g);a.label!==void 0&&(g.label=a.label),a.labelPresentation===null?delete g.labelPresentation:a.labelPresentation!==void 0&&(g.labelPresentation=a.labelPresentation),a.elevation!==void 0&&(g.elevation=a.elevation);let m=x=>{g.physical3dProvenance&&(delete g.physical3dProvenance[x],Object.keys(g.physical3dProvenance).length===0&&delete g.physical3dProvenance)};a.height===null?(delete g.height,m("height")):a.height!==void 0&&(g.height=a.height,g.physical3dProvenance={...g.physical3dProvenance,height:{status:"confirmed",source:"user-review",note:"Section front-edge height reviewed through the shared Designer/Copilot operation."}}),a.rake===null?(delete g.rake,m("rake")):a.rake!==void 0&&(g.rake=a.rake,g.physical3dProvenance={...g.physical3dProvenance,rake:{status:"confirmed",source:"user-review",note:"Section rake reviewed through the shared Designer/Copilot operation."}}),a.surfaceKind===null?(delete g.surfaceKind,m("surfaceKind")):a.surfaceKind!==void 0&&(g.surfaceKind=a.surfaceKind,g.physical3dProvenance={...g.physical3dProvenance,surfaceKind:{status:"confirmed",source:"user-review",note:"Section surface behavior reviewed through the shared Designer/Copilot operation."}}),a.color===null?delete g.color:a.color!==void 0&&(g.color=a.color),JSON.stringify(g)!==p&&(b=!0,f.add(g.id))}for(let g of d){let p=JSON.stringify(g),m=g.viewFromSeatUrl;if(a.displayLabel===null?delete g.displayLabel:a.displayLabel!==void 0&&(g.displayLabel=a.displayLabel),a.entrance===null||a.entrance===""?delete g.entrance:a.entrance!==void 0&&(g.entrance=a.entrance),a.viewFromSeatUrl===null||a.viewFromSeatUrl===""?delete g.viewFromSeatUrl:a.viewFromSeatUrl!==void 0&&(g.viewFromSeatUrl=a.viewFromSeatUrl),!g.viewFromSeatUrl||a.viewFromSeatMeta===null?delete g.viewFromSeatMeta:a.viewFromSeatMeta!==void 0?g.viewFromSeatMeta=structuredClone(a.viewFromSeatMeta):a.viewFromSeatUrl!==void 0&&g.viewFromSeatUrl!==m&&delete g.viewFromSeatMeta,a.labelStyle!==void 0){let x=De(g.labelPresentation,a.labelStyle);x?g.labelPresentation=x:delete g.labelPresentation}a.zone===null?delete g.zone:a.zone!==void 0&&(g.zone=a.zone),JSON.stringify(g)!==p&&(b=!0,f.add(g.id))}return{floorId:n.floorId,changed:b,sectionIds:i,affectedSectionIds:[...f]}}function kn(e,t){let n=C(e,t.floorId),o=n.objects.find(a=>a.type==="section"&&a.id===t.sectionId);if(!o)throw new u("object_not_found",`Unknown section id: ${t.sectionId}`,{sectionId:t.sectionId});if(o.outlinePath)throw new u("invalid_operation",`Section ${o.id} has an exact path; polygon conversion requires a separate loss review`,{sectionId:o.id,representation:"exact-path"});if(!o.geometry)throw new u("invalid_operation",`Section ${o.id} is already a manual polygon`,{sectionId:o.id,representation:"manual-polygon"});let i=n.objects.filter(a=>a.id!==o.id&&a.type!=="section"&&F(L(a),o.outline,o.holes));return{floorId:n.floorId,sectionId:o.id,sectionLabel:o.label,source:{representation:"generated-polygon",generator:structuredClone(o.geometry)},target:{representation:"manual-polygon"},geometryChanged:!1,preserved:{stableId:!0,outlineVertexCount:o.outline.length,holeCount:o.holes?.length??0,memberObjectIds:i.map(a=>a.id),inventoryUnits:i.reduce((a,r)=>a+te(r),0),durableReferenceSource:!!o.referenceSource,inventoryExclusionEvidence:!!o.referenceInventoryExclusion},removedFields:["geometry"]}}function di(e,t){let n=kn(e,t),i=C(e,n.floorId).objects.find(a=>a.type==="section"&&a.id===n.sectionId);return delete i.geometry,{...n,changed:!0}}function En(e,t){let n=(...s)=>s.every(Number.isFinite),o,i=1,a=!1,r=!0;if(t.kind==="translate"){if(!n(t.dx,t.dy))throw new u("invalid_operation","Section translation must be finite");r=t.dx!==0||t.dy!==0,o=s=>({x:s.x+t.dx,y:s.y+t.dy})}else if(t.kind==="scale"){if(!n(t.factor)||t.factor<=0||t.factor>100)throw new u("invalid_operation","Section scale factor must be finite and greater than 0");r=t.factor!==1,i=t.factor;let s=L(e);o=c=>({x:s.x+(c.x-s.x)*t.factor,y:s.y+(c.y-s.y)*t.factor})}else if(t.kind==="rotate"){if(!n(t.degrees))throw new u("invalid_operation","Section rotation must be finite");r=(t.degrees%360+360)%360!==0;let c=t.degrees*Math.PI/180,l=Math.cos(c),d=Math.sin(c),f=L(e);o=b=>{let g=b.x-f.x,p=b.y-f.y;return{x:f.x+g*l-p*d,y:f.y+g*d+p*l}}}else{if(!n(t.coordinate))throw new u("invalid_operation","Section reflection coordinate must be finite");a=!0,o=t.axis==="h"?s=>({x:2*t.coordinate-s.x,y:s.y}):s=>({x:s.x,y:2*t.coordinate-s.y})}return r&&(e.outline=e.outline.map(o),e.sourceOutline&&(e.sourceOutline=e.sourceOutline.map(o)),e.outlinePath&&(e.outlinePath=dt(e.outlinePath,o,i,a)),e.holes&&(e.holes=e.holes.map(s=>s.map(o)))),{changed:r,sectionId:e.id,representation:e.outlinePath?"exact-path":"polygon",outlineVertexCount:e.outline.length,holeCount:e.holes?.length??0,pathSegmentKinds:e.outlinePath?.segments.map(s=>s.kind)??[]}}function ui(e,t){let n=C(e,t.floorId),o=n.objects.find(i=>i.type==="section"&&i.id===t.sectionId);if(!o)throw new u("object_not_found",`Unknown section id: ${t.sectionId}`,{sectionId:t.sectionId});return{floorId:n.floorId,...En(o,t.transform)}}function fi(e,t){let n=C(e,t.floorId),o=n.objects.find(s=>s.type==="section"&&s.id===t.sectionId);if(!o)throw new u("object_not_found",`Unknown section id: ${t.sectionId}`,{sectionId:t.sectionId});let i=structuredClone(t.path);if(!Le(i))throw new u("invalid_operation","Exact section path is not finite, continuous, closed, or radius-correct");let a=lt(i),r=JSON.stringify(o.outlinePath)!==JSON.stringify(i)||JSON.stringify(o.outline)!==JSON.stringify(a)||o.sourceOutline!==void 0||o.cornerSmoothing!==void 0;return r&&(o.outlinePath=i,o.outline=a,delete o.geometry,delete o.sourceOutline,delete o.cornerSmoothing),{floorId:n.floorId,sectionId:o.id,changed:r,segmentKinds:i.segments.map(s=>s.kind),sampledVertexCount:a.length,holeCount:o.holes?.length??0}}function gi(e){return e.geometry?null:e.sourceOutline?.length?e.sourceOutline:e.outlinePath?null:e.outline?.length?e.outline:null}function bi(e,t){return Tn(e,{floorId:t.floorId,sectionIds:t.sectionIds,cornerSmoothing:t.strength})}function Tn(e,t){let n=C(e,t.floorId);if(t.cornerSmoothing!==void 0&&!Number.isFinite(t.cornerSmoothing))throw new u("invalid_operation","Corner smoothing must be a number from 0 to 100");if(t.edgeCurvature!=null&&t.edgeCurvature.some(s=>!Number.isFinite(s)))throw new u("invalid_operation","Edge curvature values must be numbers from -100 to 100");let o=[...new Set(t.sectionIds)],i=new Set,a=new Map,r=!1;try{for(let s of o){let c=n.objects.find(h=>h.type==="section"&&h.id===s);if(!c||!gi(c))continue;let d=structuredClone(c);a.set(c.id,{section:c,snapshot:d});let f=JSON.stringify(c),b=(c.sourceOutline??c.outline).map(h=>({...h})),g=Math.min(100,Math.max(0,t.cornerSmoothing??c.cornerSmoothing??0)),m=(t.edgeCurvature===void 0?c.edgeCurvature:t.edgeCurvature??void 0)?.map(h=>Math.min(100,Math.max(-100,h))),x=m?.some(h=>Math.abs(h)>.5)===!0,I=g>.5||x?Wt(b,{cornerSmoothing:g,...x?{edgeCurvature:m}:{}}):null;I?(c.sourceOutline=b,c.outlinePath=I,c.outline=lt(I),g>.5?c.cornerSmoothing=g:delete c.cornerSmoothing,x?c.edgeCurvature=[...m]:delete c.edgeCurvature):(c.outline=b,delete c.outlinePath,delete c.sourceOutline,delete c.cornerSmoothing,delete c.edgeCurvature);for(let h=0;h<(c.holes?.length??0);h+=1)Je(e,{floorId:n.floorId,objectId:c.id,points:c.holes[h],holeIndex:h});JSON.stringify(c)!==f&&(r=!0,i.add(c.id))}}catch(s){for(let{section:c,snapshot:l}of a.values()){let d=c;for(let f of Object.keys(d))delete d[f];Object.assign(c,structuredClone(l))}throw s}return{floorId:n.floorId,changed:r,sectionIds:o,affectedSectionIds:[...i]}}var Ot=.15,Pt=1.6;var hi=/^#?([\da-f]{3}|[\da-f]{6})$/i;function Rt(e){let t=hi.exec((e??"").trim());if(!t)return null;let n=t[1].length===3?t[1].split("").map(i=>i+i).join(""):t[1],o=parseInt(n,16);return[o>>16&255,o>>8&255,o&255]}function At(e,t){let n=a=>{let r=Rt(a);if(!r)return null;let s=h=>{let y=h/255;return y<=.04045?y/12.92:((y+.055)/1.055)**2.4},c=s(r[0]),l=s(r[1]),d=s(r[2]),f=(.4124*c+.3576*l+.1805*d)/.95047,b=.2126*c+.7152*l+.0722*d,g=(.0193*c+.1192*l+.9505*d)/1.08883,p=h=>h>.008856?Math.cbrt(h):7.787*h+16/116,m=p(f),x=p(b),I=p(g);return[116*x-16,500*(m-x),200*(x-I)]},o=n(e),i=n(t);return o&&i?Math.hypot(o[0]-i[0],o[1]-i[1],o[2]-i[2]):null}function _t(e){let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}function Fn(e){return .2126*_t(e[0])+.7152*_t(e[1])+.0722*_t(e[2])}function Xe(e,t){let n=Rt(e),o=Rt(t);if(!n||!o)return null;let i=Fn(n),a=Fn(o);return(Math.max(i,a)+.05)/(Math.min(i,a)+.05)}var Nn=["butt","round","square"],Dn=["miter","round","bevel"],Gn=["none","arrow"];function Mt(e){return e==="line"||e==="polyline"}var Kn=[{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}}],Fc=Kn.map(e=>e.key),pi=new Map(Kn.map(e=>[e.key,e]));function Pe(e){return typeof e=="string"&&pi.has(e)}var yi=new Set(["companion","child","senior","student","membership","custom"]);function ue(e){if(!e.length)throw new u("invalid_operation","A chart must have at least one category");let t=new Set,n=new Map,o=structuredClone(e);for(let i of o){let a=i.key.trim(),r=i.label.normalize("NFKC").trim();if(!a||a.length>160||t.has(a))throw new u("invalid_operation",`Category keys must be non-empty and unique: ${a}`,{categoryKey:a});if(t.add(a),!r||r.length>80)throw new u("invalid_operation",`Category labels must contain 1 to 80 characters: ${a}`,{categoryKey:a});let s=r.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:r});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.referenceDirectSeatImport!==void 0){let l=i.referenceDirectSeatImport;if(l.assetId!==l.assetId.trim()||l.assetId.length>160||!l.assetId||l.familyId!==l.familyId.trim()||!/^source-color:(?:#[0-9a-f]{6}(?:\+#[0-9a-f]{6})*|unclassified)$/i.test(l.familyId))throw new u("invalid_operation",`Category ${a} has invalid direct-seat import provenance`,{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&&!Pe(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 f of i.tiers){let b=f.id.trim(),g=f.name.normalize("NFKC").trim(),p=g.toLocaleLowerCase("en");if(!b||b.length>160||l.has(b))throw new u("invalid_operation",`Ticket tier ids must be non-empty and unique in category ${a}`,{categoryKey:a,tierId:b});if(!g||g.length>80||d.has(p))throw new u("invalid_operation",`Ticket tier names must be non-empty and unique in category ${a}`,{categoryKey:a,tierName:g});if(!Number.isFinite(f.price)||f.price<0||f.price>1e6)throw new u("invalid_operation",`Ticket tier ${b} price must be from 0 to 1000000`,{categoryKey:a,tierId:b});if(f.restriction!=null&&!yi.has(f.restriction))throw new u("invalid_operation",`Ticket tier ${b} has an unknown restriction`,{categoryKey:a,tierId:b});if(f.buyerMessage!=null){if(f.buyerMessage=f.buyerMessage.normalize("NFKC").trim(),!f.buyerMessage)delete f.buyerMessage;else if(f.buyerMessage.length>240)throw new u("invalid_operation",`Ticket tier ${b} buyer guidance must be at most 240 characters`,{categoryKey:a,tierId:b})}if(f.currency!=null&&(f.currency=f.currency.trim().toUpperCase(),!/^[A-Z]{3}$/.test(f.currency)))throw new u("invalid_operation",`Ticket tier ${b} must use a three-letter ISO currency`,{categoryKey:a,tierId:b});if(f.applicability!=null){let m=f.applicability.seatLabels?.map(I=>I.normalize("NFKC").trim()),x=f.applicability.accessibility;if(m&&(!m.length||m.length>1e4||m.some(I=>!I||I.length>160)||new Set(m).size!==m.length)||x&&(!x.length||x.some(I=>!xe.some(h=>h.key===I))||new Set(x).size!==x.length))throw new u("invalid_operation",`Ticket tier ${b} has invalid seat applicability`,{categoryKey:a,tierId:b});f.applicability={...m?{seatLabels:m}:{},...x?{accessibility:[...x]}:{}},!f.applicability.seatLabels&&!f.applicability.accessibility&&delete f.applicability}if(f.evidence!=null){if(!["public-host","public-event","user-confirmed"].includes(f.evidence.provenance)||typeof f.evidence.sourceDescription!="string")throw new u("invalid_operation",`Ticket tier ${b} has invalid evidence provenance`,{categoryKey:a,tierId:b});if(f.evidence.sourceDescription=f.evidence.sourceDescription.normalize("NFKC").trim(),!f.evidence.sourceDescription||f.evidence.sourceDescription.length>240||f.evidence.capturedAt!==void 0&&(f.evidence.capturedAt.length>40||!Number.isFinite(Date.parse(f.evidence.capturedAt))))throw new u("invalid_operation",`Ticket tier ${b} has invalid evidence provenance`,{categoryKey:a,tierId:b})}l.add(b),d.add(p)}}}return o}function zn(e,t){let n=new Set,o=structuredClone(e.categories);for(let r of t.updates){if(n.has(r.categoryKey))throw new u("invalid_operation",`Category ${r.categoryKey} may be updated only once`);n.add(r.categoryKey);let s=o.find(f=>f.key===r.categoryKey);if(!s)throw new u("category_not_found",`Unknown chart category: ${r.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:r.categoryKey});let c=structuredClone(r.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(f=>{let b={...f,id:f.id.trim(),name:f.name.normalize("NFKC").trim()};return f.buyerMessage?.trim()?b.buyerMessage=f.buyerMessage.normalize("NFKC").trim():delete b.buyerMessage,b})),delete s.referenceDirectSeatImport}let i=ue(o),a=JSON.stringify(i)!==JSON.stringify(e.categories);return a&&(e.categories=i),{changed:a,categoryKeys:[...n],categories:e.categories}}function mi(e,t){let n=structuredClone(e.categories),o=n.find(r=>r.key===t.categoryKey);if(!o||o.referenceDirectSeatImport?.assetId!==t.source.assetId||o.referenceDirectSeatImport.familyId!==t.source.familyId)throw new u("invalid_operation","The prior direct-seat import category is no longer available for this reference");o.label=t.label.normalize("NFKC").trim();let i=ue(n),a=JSON.stringify(i)!==JSON.stringify(e.categories);return a&&(e.categories=i),{changed:a,category:e.categories.find(r=>r.key===t.categoryKey),categories:e.categories}}function wi(e,t){let n=t.categoryKeys.map(c=>c.trim()),o=e.categories.map(c=>c.key);if(n.length!==o.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:o});let i=new Set(o),a=o.filter(c=>!n.includes(c)),r=n.filter(c=>!i.has(c));if(a.length||r.length)throw new u(r.length?"category_not_found":"invalid_operation","Category order must be an exact permutation of the current stable keys",{categoryKeys:n,missingCategoryKeys:a,unknownCategoryKeys:r});if(n.every((c,l)=>c===o[l]))return{changed:!1,categoryKeys:o,categories:e.categories};let s=new Map(e.categories.map(c=>[c.key,c]));return e.categories=ue(n.map((c,l)=>{let d=structuredClone(s.get(c));return c!==o[l]&&delete d.referenceDirectSeatImport,d})),{changed:!0,categoryKeys:n,categories:e.categories}}var jt=["#e69f00","#56b4e9","#009e73","#f0e442","#0072b2","#d55e00","#cc79a7"];function $n(e){let t=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i.exec(e.trim());if(!t)return null;let n=t[1];return n.length===3&&(n=n.split("").map(o=>o+o).join("")),[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)]}function Si(e,t){let n=$n(e),o=$n(t);return!n||!o?1/0:(n[0]-o[0])**2+(n[1]-o[1])**2+(n[2]-o[2])**2}var xi=3600;function Bn(e,t,n=jt){return n.find(i=>e.every(a=>Si(i,a)>=xi))??n[t%n.length]}function vi(e,t){let n=t?.palette??jt;if(!e.categories.length)return{changed:[],categories:e.categories};let o=new Map(e.categories.map(r=>[r.key,r.color.toLowerCase()])),i=e.categories.map((r,s)=>({categoryKey:r.key,patch:{color:n[s%n.length]}}));return zn(e,{updates:i}),{changed:e.categories.map(r=>({key:r.key,from:o.get(r.key),to:r.color})).filter(r=>r.from!==r.to),categories:e.categories}}function Ii(e,t){let n=t.color.trim().toLowerCase(),o=t.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(!o||o.length>240)throw new u("invalid_operation","Color confirmation evidence must contain 1 to 240 characters");let i=structuredClone(e.categories),a=i.find(c=>c.key===t.categoryKey);if(!a)throw new u("category_not_found",`Unknown chart category: ${t.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:t.categoryKey});a.color=n,delete a.referenceDirectSeatImport,a.referenceCategorySource&&(a.referenceCategorySource.outputColorEvidence="user-confirmed",a.referenceCategorySource.outputColorSourceDescription=o);let r=ue(i),s=JSON.stringify(r)!==JSON.stringify(e.categories);return s&&(e.categories=r),{changed:s,category:e.categories.find(c=>c.key===t.categoryKey),categories:e.categories}}function Un(e,t){let n=new Set(e.categories.map(r=>r.key)),o="";for(let r=0;r<100;r++){let c=t.idFactory("cat").trim();if(c&&!n.has(c)){o=c;break}}if(!o)throw new u("id_generation_failed","Unable to allocate a unique category id");let i={key:o,label:t.label.normalize("NFKC").trim(),color:t.color.toLowerCase(),price:t.price,tiers:t.tiers?.map(r=>({...r,id:r.id.trim(),name:r.name.normalize("NFKC").trim()})),...t.referenceDirectSeatImport?{referenceDirectSeatImport:structuredClone(t.referenceDirectSeatImport)}:{}},a=ue([...e.categories,i]);return e.categories=a,{changed:!0,category:a.find(r=>r.key===o),categories:a}}var Ci=["#e5484d","#a86b00","#8b5cf6","#d6336c","#4d7c0f","#dc2626","#c026d3"],Oi={row:"#e5484d",table:"#a86b00",booth:"#8b5cf6",gaArea:"#4d7c0f"};function Pi(e,t){let n=Oi[e];return!n||!t.includes(n)?t:[n,...t.filter(o=>o!==n)]}var _i=26;function Ri(e,t,n){let o=(1-Math.abs(2*n-1))*t,i=(e%360+360)%360/60,a=o*(1-Math.abs(i%2-1)),[r,s,c]=i<1?[o,a,0]:i<2?[a,o,0]:i<3?[0,o,a]:i<4?[0,a,o]:i<5?[a,0,o]:[o,0,a],l=n-o/2,d=f=>Math.round((f+l)*255).toString(16).padStart(2,"0");return`#${d(r)}${d(s)}${d(c)}`}function Ai(e,t,n){let o=r=>e.every(s=>{let c=At(r,s);return c==null||c>=_i}),i=r=>{let s=Xe(r,"#12151d"),c=Xe(r,"#ffffff");return(s??0)>=3||(c??0)>=3},a=t.find(r=>o(r)&&i(r));if(a)return a;for(let r=0;r<360;r+=12)for(let s of[.52,.44,.6]){let c=Ri(r,.62,s);if(o(c)&&i(c))return c}return n}function Hn(e,t){let n=Ke.find(i=>i.objectType===t).creationWord;return`${e.replace(/\s*[–-]\s*(Tables|Booths|Standing|Seats)$/i,"").trim()||e.trim()} \u2013 ${n}`}function Mi(e){let t=new Map;for(let n of E(e))for(let o of n.objects){let i=Ke.find(r=>r.objectType===o.type);if(!i)continue;let a=new Set;if(o.type==="row"||o.type==="table")for(let r of $e(o).keys())a.add(r);else"categoryKey"in o&&o.categoryKey&&a.add(o.categoryKey);for(let r of a){let s=t.get(r)??new Set;s.add(i.objectType),t.set(r,s)}}return t}function ji(e,t){let n=new Set(e.categories.map(i=>i.label.toLowerCase())),o=t;for(let i=2;n.has(o.toLowerCase());i+=1)o=`${t} ${i}`;return o}function Vn(e,t,n){let o=Mi(e),i=l=>{let d=o.get(l);return!d||d.size===0||d.size===1&&d.has(n)},a=e.categories.find(l=>l.key===t);if(a&&i(a.key))return{kind:"existing",categoryKey:a.key,label:a.label};if(!a){let l=e.categories.find(d=>{let f=o.get(d.key);return f?.size===1&&f.has(n)});if(l)return{kind:"existing",categoryKey:l.key,label:l.label}}let r=Ke.find(l=>l.objectType===n),s=a?Hn(a.label,n):n==="gaArea"?"General Admission":r.creationWord,c=e.categories.find(l=>l.label.toLowerCase()===s.toLowerCase()&&i(l.key));return c?{kind:"existing",categoryKey:c.key,label:c.label}:{kind:"mint",...a?{baseCategoryKey:a.key}:{},label:ji(e,s)}}function Li(e,t,n,o){let i=Vn(e,t,n);if(i.kind==="existing")return i.categoryKey;let a=i.baseCategoryKey?e.categories.find(r=>r.key===i.baseCategoryKey):void 0;return ki(e,n,a,i.label,o)}function ki(e,t,n,o,i){let a=i.palette??Ci,r=e.categories.map(d=>d.color),s=i.suggestColor?.(r.map(d=>d.toLowerCase()))??Bn(r,e.categories.length),c=Ai(r,Pi(t,a),s),l=Un(e,{label:o,color:c,...n?.price!==void 0?{price:n.price}:{},...n?.tiers?.length?{tiers:n.tiers}:{},idFactory:i.idFactory});return e.categories=l.categories,l.category.key}function Ei(e,t){let n=new Set;for(let o of E(e))for(let i of o.objects)"categoryKey"in i&&i.categoryKey===t&&n.add(i.id),(i.type==="row"||i.type==="table")&&i.overrides?.some(a=>a.categoryKey===t)&&n.add(i.id);return[...n]}function Ti(e,t){let n=e.categories.find(a=>a.key===t.categoryKey);if(!n)throw new u("category_not_found",`Unknown chart category: ${t.categoryKey}. Call get_chart to list valid category keys.`,{categoryKey:t.categoryKey});if(e.categories.length<=1)throw new u("invalid_operation","A chart must retain at least one category");let o=Ei(e,t.categoryKey);if(o.length)throw new u("category_in_use",`Category ${t.categoryKey} is still assigned to chart inventory`,{categoryKey:t.categoryKey,objectIds:o});if(n.referenceCategorySource)throw new u("reference_category_protected",`Reference-backed category ${t.categoryKey} cannot be deleted through a generic catalog operation`,{categoryKey:t.categoryKey});let i=ue(e.categories.filter(a=>a.key!==t.categoryKey));return e.categories=i,{changed:!0,categoryKey:t.categoryKey,categories:i}}var Fi=["background","seatLabelColor","rowLabelColor","selectionColor","decorFill","textColor","accent","accentInk"],Ni=["seat","deck","shell","fascia"];function Di(e,t){let n=t.patch;if(!Object.keys(n).length)throw new u("invalid_operation","At least one theme field is required");let o=JSON.stringify(e.theme??null),i={...e.theme??{}};for(let a of Fi){let r=n[a];r===null?delete i[a]:r!==void 0&&(i[a]=T(r,`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<Ot||n.seatScale>Pt)throw new u("invalid_operation",`Theme seatScale must be from ${Ot} to ${Pt}`);i.seatScale=n.seatScale}if(n.logoUrl===null)delete i.logoUrl;else if(n.logoUrl!==void 0){let a=Z(n.logoUrl);if(!a)throw new u("invalid_operation","Theme logoUrl must be a safe HTTPS or base64 raster 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}if(n.hideBadge===null||n.hideBadge===!1?delete i.hideBadge:n.hideBadge===!0&&(i.hideBadge=!0),n.venue3d===null)delete i.venue3d;else if(n.venue3d!==void 0){let a={...i.venue3d??{}};for(let s of Ni){let c=n.venue3d[s];c===null?delete a[s]:c!==void 0&&(a[s]=T(c,`3D venue ${s}`))}let r=n.venue3d.roughness;if(r===null)delete a.roughness;else if(r!==void 0){if(!Number.isFinite(r)||r<0||r>1)throw new u("invalid_operation","3D venue roughness must be from 0 to 1");a.roughness=r}i.venue3d=Object.keys(a).length?a:void 0,i.venue3d||delete i.venue3d}return e.theme=Object.keys(i).length?i:void 0,{changed:JSON.stringify(e.theme??null)!==o,theme:e.theme??null}}function Gi(e,t){let n=t.url===null?null:Z(t.url);if(t.url!==null&&!n)throw new u("invalid_operation","View-from-seat photo must be a safe HTTPS or base64 raster image reference");let o=n??void 0;if(t.floorId!==void 0){let s=e.floors?.find(f=>f.id===t.floorId);if(!s)throw new u("invalid_operation",`Unknown floor: ${t.floorId}`);let c=(s.viewFromSeatUrl??void 0)===o,l=o?t.metadata===null?void 0:t.metadata??(c?s.viewFromSeatMeta:void 0):void 0,d=!c||JSON.stringify(s.viewFromSeatMeta??null)!==JSON.stringify(l??null);return s.viewFromSeatUrl=o,s.viewFromSeatMeta=l,{changed:d,scope:"floor",floorId:t.floorId,url:s.viewFromSeatUrl??null}}let i=(e.viewFromSeatUrl??void 0)===o,a=o?t.metadata===null?void 0:t.metadata??(i?e.viewFromSeatMeta:void 0):void 0,r=!i||JSON.stringify(e.viewFromSeatMeta??null)!==JSON.stringify(a??null);return e.viewFromSeatUrl=o,e.viewFromSeatMeta=a,{changed:r,scope:"venue",url:e.viewFromSeatUrl??null}}function Ki(e,t){let n=Te(e,t.floorId),o=un(n),i=t.placement==="auto"||t.placement==null?"rear":t.placement,a=96;return i==="front"?{x:o.x+o.width/2,y:o.y-a-t.height/2}:i==="left"?{x:o.x-a-t.width/2,y:o.y+o.height/2}:i==="right"?{x:o.x+o.width+a+t.width/2,y:o.y+o.height/2}:{x:o.x+o.width/2,y:o.y+o.height+a+t.height/2}}function Ye(e,t){j(e,t.categoryKey);let n=(...d)=>d.every(Number.isFinite);if(!n(t.center.x,t.center.y,t.innerRadius,t.rowGap,t.startAngle,t.endAngle,t.seatPitch))throw new u("invalid_operation","Arc/Fan geometry values must be finite");if(!Number.isInteger(t.rowCount)||t.rowCount<1||t.rowCount>100)throw new u("invalid_operation","Arc/Fan rowCount must be an integer from 1 to 100");if(t.innerRadius<40||t.innerRadius>2e4||t.rowGap<12||t.rowGap>500)throw new u("invalid_operation","Arc/Fan radius must be 40\u201320000 and row gap 12\u2013500");let o=t.endAngle-t.startAngle;if(Math.abs(o)<5||Math.abs(o)>320)throw new u("invalid_operation","Arc/Fan sweep must be from 5\xB0 to 320\xB0");if(t.seatPitch<14||t.seatPitch>80)throw new u("invalid_operation","Arc/Fan seat pitch must be from 14 to 80 chart units");let i=t.fit??"seat-pitch";if(i==="fixed-count"&&(!Number.isInteger(t.seatsPerRow)||t.seatsPerRow<2||t.seatsPerRow>300))throw new u("invalid_operation","Fixed Arc/Fan rows require seatsPerRow from 2 to 300");let a=t.taperDegrees??0,r=t.skewDegrees??0;if(!n(a,r)||Math.abs(a)>120||Math.abs(r)>180)throw new u("invalid_operation","Arc/Fan taper must be within \xB1120\xB0 and skew within \xB1180\xB0");let s={left:t.aisleGaps?.left??0,center:t.aisleGaps?.center??0,right:t.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(e,t.floorId).objects.filter(d=>d.type==="row").length;return{...t,fit:i,facing:t.facing??"inward",taperDegrees:a,skewDegrees:r,aisleGaps:s,rowLabelStart:t.rowLabelStart??l,seatLabelStart:t.seatLabelStart??1}}function $i(e,t,n){let o=n*X;return{x:e.x+t*Math.sin(o),y:e.y+t*Math.cos(o)}}function zi(e,t,n,o){let i=Math.abs(o-n)*X,a=[["left",.25],["center",.5],["right",.75]].flatMap(([l,d])=>{let f=e.aisleGaps[l];if(!f)return[];let b=f/t/i/2;return[[Math.max(0,d-b),Math.min(1,d+b)]]}).sort((l,d)=>l[0]-d[0]),r=[];for(let l of a){let d=r[r.length-1];d&&l[0]<=d[1]?d[1]=Math.max(d[1],l[1]):r.push([...l])}let s=[],c=0;for(let l of r)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])=>t*i*(d-l)>=e.seatPitch*.75)}function Bi(e,t){let n=e.length*2;if(t<n)throw new u("invalid_operation",`Fixed seat count must be at least ${n} for ${e.length} aisle-separated row segments`);let o=t-n,i=e.reduce((c,l)=>c+l,0),a=e.map(c=>o*c/i),r=a.map(c=>2+Math.floor(c)),s=t-r.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&&r[c]++}),r}function Qe(e,t,n){let o=[];for(let i=0;i<e.rowCount;i++){let a=e.rowCount===1?0:i/(e.rowCount-1),r=e.innerRadius+i*e.rowGap,s=Math.sign(e.endAngle-e.startAngle)||1,c=e.startAngle+s*e.taperDegrees*a+e.skewDegrees*a,l=e.endAngle-s*e.taperDegrees*a+e.skewDegrees*a;if(Math.sign(l-c)!==Math.sign(e.endAngle-e.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=zi(e,r,c,l);if(!d.length)throw new u("invalid_operation",`Arc/Fan aisles leave no usable span in row ${i+1}`);e.facing==="outward"&&(d=d.slice().reverse());let f=d.map(([p,m])=>r*Math.abs(l-c)*X*(m-p)),b=e.fit==="fixed-count"?Bi(f,e.seatsPerRow):f.map(p=>Math.max(2,Math.round(p/e.seatPitch)+1)),g=e.seatLabelStart;d.forEach(([p,m],x)=>{let I=c+(l-c)*p,h=c+(l-c)*m;e.facing==="outward"&&([I,h]=[h,I]);let y=b[x];if(y>300)throw new u("invalid_operation","An Arc/Fan row segment cannot exceed 300 seats");let w=Math.abs(h-I)*X/(y-1),S=2*r*Math.sin(w/2),v={type:"row",id:n(i,x),label:U(e.rowLabelStart+i),origin:$i(e.center,r,I),rotation:-I,curve:h-I,seatCount:y,seatSpacing:S,categoryKey:e.categoryKey,seatLabelStart:g,arcFanGeneration:{kind:"arc-fan-v1",groupId:t,center:{...e.center},innerRadius:e.innerRadius,rowCount:e.rowCount,rowGap:e.rowGap,startAngle:e.startAngle,endAngle:e.endAngle,seatPitch:e.seatPitch,fit:e.fit,...e.seatsPerRow!=null?{seatsPerRow:e.seatsPerRow}:{},facing:e.facing,taperDegrees:e.taperDegrees,skewDegrees:e.skewDegrees,aisleGaps:{...e.aisleGaps},rowLabelStart:e.rowLabelStart,seatLabelStart:e.seatLabelStart,rowIndex:i,segmentIndex:x}};o.push(v),g+=y})}return o}function Lt(e,t){let n=Ye(e,t),o=C(e,t.floorId),i=Qe(n,"preview-arc-fan",(c,l)=>`preview-fan-${c}-${l}`),a=i.map(c=>c.seatSpacing),r=Math.max(...a.map(c=>Math.abs(c-n.seatPitch))),s=[];return r>n.seatPitch*.12&&s.push(`Seat fitting deviates from the requested pitch by up to ${r.toFixed(1)} chart units`),i.length>n.rowCount*3&&s.push("Three aisles split each logical row into four separately editable segments"),{floorId:o.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:r,aisleCount:Object.values(n.aisleGaps).filter(c=>c>0).length,warnings:s}}function Ui(e,t){let n=Ye(e,t),o=C(e,t.floorId),i=new Set,a=A(e,"fan",t.idFactory,i),r=Qe(n,a,()=>A(e,"r",t.idFactory,i)),s=Lt(e,t),c=null,l=t.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 f=ee(r);f&&(c=A(e,"sec",t.idFactory,i),d={type:"section",id:c,label:l,outline:f,arcFanGroupId:a})}return o.objects.push(...r,...d?[d]:[]),{floorId:o.floorId,rowIds:r.map(f=>f.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 qn(e,t){let n=C(e,t.floorId),o=n.objects.filter(f=>f.type==="row"&&f.arcFanGeneration?.groupId===t.groupId);if(!o.length)throw new u("object_not_found",`Unknown Arc/Fan group: ${t.groupId}`,{groupId:t.groupId});let i=o[0].arcFanGeneration,a=f=>{let b=f.arcFanGeneration;return JSON.stringify({center:b.center,innerRadius:b.innerRadius,rowCount:b.rowCount,rowGap:b.rowGap,startAngle:b.startAngle,endAngle:b.endAngle,seatPitch:b.seatPitch,fit:b.fit,seatsPerRow:b.seatsPerRow,facing:b.facing,taperDegrees:b.taperDegrees,skewDegrees:b.skewDegrees,aisleGaps:b.aisleGaps,rowLabelStart:b.rowLabelStart,seatLabelStart:b.seatLabelStart})};if(o.some(f=>a(f)!==a(o[0])))throw new u("invalid_operation","Arc/Fan group provenance no longer agrees across all row segments",{groupId:t.groupId});let r=n.objects.find(f=>f.type==="section"&&f.arcFanGroupId===t.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:o[0].categoryKey,rowLabelStart:i.rowLabelStart,seatLabelStart:i.seatLabelStart,sectionLabel:r?.label},c=Ye(e,s),l=new Set(Qe(c,t.groupId,(f,b)=>`${f}:${b}`).map(f=>`${f.arcFanGeneration.rowIndex}:${f.arcFanGeneration.segmentIndex}`)),d=new Set(o.map(f=>`${f.arcFanGeneration.rowIndex}:${f.arcFanGeneration.segmentIndex}`));if(l.size!==d.size||[...l].some(f=>!d.has(f)))throw new u("invalid_operation","Arc/Fan group is incomplete and cannot be regenerated safely",{groupId:t.groupId});return s}function Hi(e,t){qn(e,{floorId:t.floorId,groupId:t.groupId});let n=Ye(e,t),o=C(e,t.floorId),i=o.objects.filter(m=>m.type==="row"&&m.arcFanGeneration?.groupId===t.groupId),a=o.objects.find(m=>m.type==="section"&&m.arcFanGroupId===t.groupId),r=new Map(i.map(m=>[`${m.arcFanGeneration.rowIndex}:${m.arcFanGeneration.segmentIndex}`,m.id])),s=new Set,c=Qe(n,t.groupId,(m,x)=>r.get(`${m}:${x}`)??A(e,"r",t.idFactory,s)),l=Lt(e,t),d=t.sectionLabel?.normalize("NFKC").trim(),f=null;if(d){if(d.length>80)throw new u("invalid_operation","Arc/Fan section label must contain at most 80 characters");let m=ee(c);m&&(f={type:"section",id:a?.id??A(e,"sec",t.idFactory,s),label:d,outline:m,arcFanGroupId:t.groupId})}let b=new Set([...i.map(m=>m.id),...a?[a.id]:[]]),g=Math.min(...o.objects.map((m,x)=>b.has(m.id)?x:1/0)),p=o.objects.filter(m=>!b.has(m.id));return p.splice(Number.isFinite(g)?g:p.length,0,...c,...f?[f]:[]),o.objects.splice(0,o.objects.length,...p),{floorId:o.floorId,rowIds:c.map(m=>m.id),sectionId:f?.id??null,groupId:t.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 Vi(e){let t=new Set(B(e).filter(o=>o.type==="row"||o.type==="table"||o.type==="booth").map(o=>o.label).filter(o=>typeof o=="string")),n=0;return()=>{for(;t.has(U(n));)n+=1;let o=U(n);return t.add(o),n+=1,o}}function Jn(e){return JSON.stringify(["row-block-v1",e.style,e.origin.x,e.origin.y,e.rotation,e.rowCount,e.seatsPerRow,e.rowGap,e.seatSpacing,e.curve])}function qi(e,t){if(j(e,t.categoryKey),!Number.isInteger(t.rowCount)||t.rowCount<1||t.rowCount>100)throw new u("invalid_operation","rowCount must be an integer from 1 to 100");if(!Number.isInteger(t.seatsPerRow)||t.seatsPerRow<1||t.seatsPerRow>300)throw new u("invalid_operation","seatsPerRow must be an integer from 1 to 300");let n=t.rowGap??28,o=t.seatSpacing??24;if(!Number.isFinite(n)||n<=0||!Number.isFinite(o)||o<=0)throw new u("invalid_operation","Row and seat spacing must be positive finite values");if(t.rotation!==void 0&&!Number.isFinite(t.rotation))throw new u("invalid_operation","rotation must be a finite number of degrees");let i=C(e,t.floorId),a=new Set,r=Vi(e),s=It(t.rotation??0),c=t.curve??0,l=t.style,d=l?A(e,"rowblock",t.idFactory,a):void 0,f=l?Jn({style:l,origin:t.origin,rotation:s,rowCount:t.rowCount,seatsPerRow:t.seatsPerRow,rowGap:n,seatSpacing:o,curve:c}):void 0,b={x:Math.cos(s*J),y:Math.sin(s*J)},g={x:-b.y,y:b.x},p=Array.from({length:t.rowCount},(I,h)=>{let y=l==="intertwined"&&h%2===1?o/2:0,w={type:"row",id:A(e,"r",t.idFactory,a),label:r(),origin:{x:t.origin.x+g.x*h*n+b.x*y,y:t.origin.y+g.y*h*n+b.y*y},rotation:s,curve:c,seatCount:t.seatsPerRow,seatSpacing:o,categoryKey:t.categoryKey};return l&&d&&f&&(w.rowBlockGeneration={kind:"row-block-v1",groupId:d,style:l,rowIndex:h,rowCount:t.rowCount,seatsPerRow:t.seatsPerRow,origin:{...t.origin},rotation:s,rowGap:n,seatSpacing:o,curve:c,signature:f}),w});i.objects.push(...p);let m=null,x=t.sectionLabel?.trim();if(x){let I=ee(p);if(I){let h={type:"section",id:A(e,"sec",t.idFactory,a),label:x,outline:I};i.objects.push(h),m=h.id}}return{floorId:i.floorId,rowIds:p.map(I=>I.id),sectionId:m,createdIds:[...p.map(I=>I.id),...m?[m]:[]]}}function Xn(e,t){let n=new Set(B(e).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(i=>typeof i=="string")),o=1;return()=>{for(;n.has(`${t}${o}`);)o+=1;let i=`${t}${o}`;return n.add(i),o+=1,i}}function Ji(e,t){let n=new Set(B(e).filter(i=>i.type==="gaArea").map(i=>i.label));if(!n.has(t))return t;let o=2;for(;n.has(`${t} ${o}`);)o+=1;return`${t} ${o}`}var Xi=456;function Yn(e){let t=Math.sqrt(Math.max(1,e)*Xi);return{width:Math.round(t*1.027),height:Math.round(t/1.027)}}function Yi(e,t){if(j(e,t.categoryKey),!Number.isInteger(t.capacity)||t.capacity<1)throw new u("invalid_operation","capacity must be a positive integer");if(!Number.isFinite(t.center.x)||!Number.isFinite(t.center.y))throw new u("invalid_operation","GA area center must be finite");let n=C(e,t.floorId),o=new Set,{width:i,height:a}=Yn(t.capacity),r=Ji(e,(t.label??"General Admission").trim()||"General Admission"),s={type:"gaArea",id:A(e,"ga",t.idFactory,o),label:r,...t.displayLabel?.trim()?{displayLabel:t.displayLabel.trim()}:{},points:[{x:t.center.x-i/2,y:t.center.y-a/2},{x:t.center.x+i/2,y:t.center.y-a/2},{x:t.center.x+i/2,y:t.center.y+a/2},{x:t.center.x-i/2,y:t.center.y+a/2}],capacity:t.capacity,categoryKey:t.categoryKey};return n.objects.push(s),{floorId:n.floorId,gaAreaId:s.id,label:r,createdIds:[s.id]}}function Qi(e,t){if(j(e,t.categoryKey),!Number.isInteger(t.tableRows)||t.tableRows<1||t.tableRows>20||!Number.isInteger(t.tableColumns)||t.tableColumns<1||t.tableColumns>20)throw new u("invalid_operation","tableRows and tableColumns must be integers from 1 to 20");if(!Number.isInteger(t.seatsPerTable)||t.seatsPerTable<1||t.seatsPerTable>20)throw new u("invalid_operation","seatsPerTable must be an integer from 1 to 20");let n=t.gapX??155,o=t.gapY??150;if(!Number.isFinite(n)||n<80||!Number.isFinite(o)||o<80)throw new u("invalid_operation","Table spacing must be at least 80 chart units");if(!Number.isFinite(t.center.x)||!Number.isFinite(t.center.y))throw new u("invalid_operation","Table array center must be finite");let i=C(e,t.floorId),a=new Set,r=Xn(e,"T"),s=[];for(let c=0;c<t.tableRows;c+=1)for(let l=0;l<t.tableColumns;l+=1)s.push({type:"table",id:A(e,"t",t.idFactory,a),label:r(),center:{x:t.center.x+(l-(t.tableColumns-1)/2)*n,y:t.center.y+(c-(t.tableRows-1)/2)*o},rotation:0,categoryKey:t.categoryKey,seatCount:t.seatsPerTable,...t.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 Zi(e,t){if(j(e,t.categoryKey),!Number.isInteger(t.boothRows)||t.boothRows<1||t.boothRows>30||!Number.isInteger(t.boothColumns)||t.boothColumns<1||t.boothColumns>30)throw new u("invalid_operation","boothRows and boothColumns must be integers from 1 to 30");let n=t.gapX??88,o=t.gapY??82;if(!Number.isFinite(n)||n<62||!Number.isFinite(o)||o<52)throw new u("invalid_operation","Booth spacing must clear the 62\xD752 booth footprint");if(!Number.isFinite(t.center.x)||!Number.isFinite(t.center.y))throw new u("invalid_operation","Booth array center must be finite");let i=C(e,t.floorId),a=new Set,r=Xn(e,"B"),s=[];for(let c=0;c<t.boothRows;c+=1)for(let l=0;l<t.boothColumns;l+=1)s.push({type:"booth",id:A(e,"booth",t.idFactory,a),label:r(),center:{x:t.center.x+(l-(t.boothColumns-1)/2)*n,y:t.center.y+(c-(t.boothRows-1)/2)*o},width:62,height:52,rotation:0,categoryKey:t.categoryKey});return i.objects.push(...s),{floorId:i.floorId,boothIds:s.map(c=>c.id),createdIds:s.map(c=>c.id)}}function Wi(e,t){let n=C(e,t.floorId),o=[...new Set(t.rowIds)];if(o.length<2||o.length>64)throw new u("invalid_operation","A segmented row requires 2 to 64 ordered component rows");if(t.boundaries.length!==o.length-1||t.boundaries.some(b=>b!=="continuous"&&b!=="break"))throw new u("invalid_operation","Declare one continuous or break boundary between every pair of row components");let i=o.map(b=>n.objects.find(g=>g.type==="row"&&g.id===b)),a=o.filter((b,g)=>!i[g]);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 r=i,s=r.filter(b=>b.segmentedRow);if(s.length)throw new u("invalid_operation","Ungroup existing segmented rows before combining their components again",{rowIds:s.map(b=>b.id)});let c=(t.displayLabel??r[0].displayLabel??r[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(b=>b.type==="row"?[b.segmentedRow?.groupId,b.rowBlockGeneration?.groupId].filter(g=>!!g):[])),d="";for(let b=0;b<100;b+=1){let g=t.idFactory("rowgroup");if(g&&!l.has(g)){d=g;break}}if(!d)throw new u("id_generation_failed","Unable to allocate a segmented-row group id");let f=r[0];return r.forEach((b,g)=>{b.segmentedRow={kind:"segmented-row-v1",groupId:d,componentIndex:g,componentCount:r.length,boundaryBefore:g===0?"start":t.boundaries[g-1],displayLabel:c,...f.displayType?{displayType:f.displayType}:{},...f.labelPresentation?{labelPresentation:structuredClone(f.labelPresentation)}:{},...f.viewFromSeatUrl?{viewFromSeatUrl:f.viewFromSeatUrl}:{},...f.viewFromSeatMeta?{viewFromSeatMeta:structuredClone(f.viewFromSeatMeta)}:{},...f.confidenceEvidence?{confidenceEvidence:structuredClone(f.confidenceEvidence)}:{}}}),{floorId:n.floorId,groupId:d,rowIds:o,changed:!0}}function ea(e,t){let n=C(e,t.floorId),o=t.groupId?n.objects.find(s=>s.type==="row"&&s.segmentedRow?.groupId===t.groupId):n.objects.find(s=>s.type==="row"&&s.id===t.rowId),i=t.groupId??o?.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 r=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:r,changed:!0}}function ta(e,t){let n=C(e,t.floorId),o=n.objects.filter(r=>r.type==="row"&&r.segmentedRow?.groupId===t.groupId).sort((r,s)=>r.segmentedRow.componentIndex-s.segmentedRow.componentIndex);if(o.length<2)throw new u("object_not_found","The segmented row is incomplete or missing on the selected floor");if(t.boundaries&&(t.boundaries.length!==o.length-1||t.boundaries.some(r=>r!=="continuous"&&r!=="break")))throw new u("invalid_operation","Declare one continuous or break boundary between every pair of row components");let i=t.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(o.map(r=>r.segmentedRow));return o.forEach((r,s)=>{let c=r.segmentedRow,l=c.viewFromSeatUrl;i!==void 0&&(c.displayLabel=i),t.boundaries&&s>0&&(c.boundaryBefore=t.boundaries[s-1]),t.smoothing!==void 0&&(c.smoothing=t.smoothing||void 0),t.viewFromSeatUrl===null?delete c.viewFromSeatUrl:t.viewFromSeatUrl!==void 0&&(c.viewFromSeatUrl=t.viewFromSeatUrl),!c.viewFromSeatUrl||t.viewFromSeatMeta===null?delete c.viewFromSeatMeta:t.viewFromSeatMeta!==void 0?c.viewFromSeatMeta=structuredClone(t.viewFromSeatMeta):t.viewFromSeatUrl!==void 0&&c.viewFromSeatUrl!==l&&delete c.viewFromSeatMeta}),{floorId:n.floorId,groupId:t.groupId,rowIds:o.map(r=>r.id),changed:JSON.stringify(o.map(r=>r.segmentedRow))!==a}}function na(e,t){let n=C(e,t.floorId),o=n.objects.filter(P=>P.type==="row"&&P.rowBlockGeneration?.groupId===t.groupId).sort((P,$)=>P.rowBlockGeneration.rowIndex-$.rowBlockGeneration.rowIndex),i=o[0]?.rowBlockGeneration;if(!i||o.length!==i.rowCount||o.some((P,$)=>{let M=P.rowBlockGeneration;return M.kind!=="row-block-v1"||M.rowIndex!==$||M.signature!==i.signature||JSON.stringify(M)!==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:t.groupId});let a=JSON.stringify(o),r=t.style??i.style,s=t.rowCount??i.rowCount,c=t.seatsPerRow??i.seatsPerRow,l=t.rowGap??i.rowGap,d=t.seatSpacing??i.seatSpacing,f=t.curve??i.curve,b=Number.isFinite(t.rotation??i.rotation)?It(t.rotation??i.rotation):t.rotation??i.rotation,g=t.origin?{...t.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(P=>Number.isFinite(P)&&P>0)||!Number.isFinite(f)||!Number.isFinite(b)||!Number.isFinite(g.x)||!Number.isFinite(g.y))throw new u("invalid_operation","Row-block geometry must use positive spacing and finite origin, rotation, and curve values");let p=Jn({style:r,origin:g,rotation:b,rowCount:s,seatsPerRow:c,rowGap:l,seatSpacing:d,curve:f}),m={x:Math.cos(b*J),y:Math.sin(b*J)},x={x:-m.y,y:m.x},I=new Map(o.map(P=>[P.rowBlockGeneration.rowIndex,P])),h=new Set,y=new Set(n.objects.filter(P=>P.type==="row").filter(P=>!o.includes(P)).map(P=>P.label)),w=n.objects.filter(P=>P.type==="row").length,S=()=>{for(;y.has(U(w));)w+=1;let P=U(w);return y.add(P),w+=1,P},v=[],_=[];for(let P=0;P<s;P+=1){let $=r==="intertwined"&&P%2===1?d/2:0,M=I.get(P);M||(M={type:"row",id:A(e,"r",t.idFactory,h),label:S(),origin:{...g},rotation:b,curve:f,seatCount:c,seatSpacing:d,categoryKey:o[0].categoryKey},_.push(M.id)),M.origin={x:g.x+x.x*P*l+m.x*$,y:g.y+x.y*P*l+m.y*$},M.rotation=b,M.curve=f,M.seatCount=c,M.seatSpacing=d,delete M.path,delete M.arcFanGeneration,M.overrides&&(M.overrides=M.overrides.filter(it=>it.index<c),M.overrides.length||delete M.overrides),M.rowBlockGeneration={kind:"row-block-v1",groupId:t.groupId,style:r,rowIndex:P,rowCount:s,seatsPerRow:c,origin:{...g},rotation:b,rowGap:l,seatSpacing:d,curve:f,signature:p},v.push(M)}let G=o.slice(s).map(P=>P.id),N=Math.min(...o.map(P=>n.objects.indexOf(P))),H=new Set(o.map(P=>P.id)),K=n.objects.filter(P=>!H.has(P.id));return K.splice(N,0,...v),n.objects.splice(0,n.objects.length,...K),{floorId:n.floorId,groupId:t.groupId,rowIds:v.map(P=>P.id),createdRowIds:_,removedRowIds:G,changed:a!==JSON.stringify(v)||_.length>0||G.length>0}}function kt(e){return e.normalize("NFKC").replace(/\s+/g," ").trim()}function Et(e,t){let n="";for(let o of e){if(n.length+o.length>t)break;n+=o}return n.trim()}function Tt(e){return Et(kt(e),40)}function Qn(e,t=39){return Et(kt(e),Math.max(1,t))}function fe(e,t=80){return Et(kt(e),Math.max(1,t))}function Zn(e){return fe(e).toLocaleLowerCase("en")}function Ft(e){return Zn(e)}function Wn(e){return new Map((e??[]).map(t=>[t.index,t]))}function oa(e){let t=Wn(e.overrides),n=[];for(let o=0;o<e.seatCount;o+=1){let i=t.get(o);i?.skip||n.push(we(e,o,i))}return n}function ra(e){if(e.bookAsWhole||e.variableOccupancy)return[e.label];let t=Wn(e.overrides),n=[];for(let o=0;o<e.seatCount;o+=1){let i=t.get(o);i?.skip||n.push(i?.label??`${e.label}-${o+1}`)}return n}function ia(e){return e.type==="row"?[e.label,...oa(e)]:e.type==="table"?[e.label,...ra(e)]:e.type==="booth"?[e.label]:e.type==="gaArea"?[e.label,...Y(e)]:[]}function eo(e,t){let n=new Set;for(let o of e)if(!t?.has(o.id))for(let i of ia(o)){let a=Ft(i);a&&n.add(a)}return n}function aa(e,t){if(!Number.isInteger(t)||t<1)return[];let n={label:e,seatCount:t},o=[Ft(e)];for(let i=0;i<t;i+=1)o.push(Ft(we(n,i)));return o.filter(Boolean)}function to(e,t,n){let o=aa(t,n);if(!o.length||o.some(i=>e.has(i)||Be(i)))return!1;for(let i of o)e.add(i);return!0}var sa=1e-6,ca=160,la=.001,da=1e-5;function ge(e){if(typeof e!="string")return;let t=e.normalize("NFKC").replace(/\s+/g," ").trim();if(!t||t.length>ca)return;for(let a of t){let r=a.codePointAt(0)??0;if(r<32||r===127)return}let n=t.lastIndexOf(":"),o=t.slice(0,n),i=t.slice(n+1);if(!(!o||!/^(0|[1-9]\d*)$/.test(i)||!Number.isSafeInteger(Number(i))))return t}function no(e){return typeof e=="string"&&Qn(e)||void 0}function oo(e,t){if(e.seatCount!==t.seatCount||e.seatCount<1||!(Nt(e.origin)&&Nt(t.start)&&Nt(t.end)&&Number.isFinite(e.rotation)&&Number.isFinite(e.seatSpacing)&&e.seatSpacing>0)||e.curve!==0||e.path)return!1;let n=e.rotation*Math.PI/180,o={x:e.origin.x+Math.cos(n)*e.seatSpacing*(e.seatCount-1),y:e.origin.y+Math.sin(n)*e.seatSpacing*(e.seatCount-1)},i=Math.hypot(t.end.x-t.start.x,t.end.y-t.start.y),a=la+Math.max(1,i)*da;if(Math.hypot(e.origin.x-t.start.x,e.origin.y-t.start.y)>a||Math.hypot(o.x-t.end.x,o.y-t.end.y)>a)return!1;if(e.seatCount<2||i<=sa)return!0;let r=i/(e.seatCount-1);if(Math.abs(e.seatSpacing-r)>a)return!1;let s=Math.atan2(t.end.y-t.start.y,t.end.x-t.start.x)*180/Math.PI,c=Math.abs(((e.rotation-s)%360+540)%360-180),l=Math.max(.001,Math.atan2(a,Math.max(1,i))*180/Math.PI);return c<=l}function Nt(e){return Number.isFinite(e.x)&&Number.isFinite(e.y)}var ua=300;function fa(e){let t=new Set(B(e).filter(i=>i.type==="row"||i.type==="table"||i.type==="booth").map(i=>i.label).filter(Boolean)),n=0,o=()=>{for(;t.has(U(n));)n+=1;let i=U(n);return n+=1,t.add(i),i};return i=>{let a=Tt(i),r=0;return()=>{for(;a&&r<4096;r+=1){let s=`${a}-${U(r)}`;if(!t.has(s))return t.add(s),r+=1,s}return o()}}}function ga(e){let t=eo(B(e));return(n,o)=>{let i=fe(n);for(let a=1;a<4096;a+=1){let r=a===1?"":` ${a}`,s=r?`${fe(i,80-r.length)}${r}`:i;if(s&&to(t,s,o))return s}throw new Error("No collision-safe row identity is available for this reviewed direct seating row")}}function ba(e){return{ordinaryFor:fa(e),direct:ga(e)}}function ro(e,t,n){return e.type==="row"&&e.referenceScan?.assetId===t&&(!n||e.referenceScan.sectionId===n)}function ha(e,t,n){let o=new Map;for(let r of t.sections)if(!(n&&r.sectionId!==n)&&r.sourceGroupId)for(let[s,c]of r.rows.entries()){let l=ge(`${r.sourceGroupId}:${s}`),d=l&&ge(c.directSourceRowId)===l?l:void 0;d&&o.set(d,o.has(d)?null:c)}let i=new Map;for(let r of e){let s=ge(r.referenceScan?.directSourceRowId);if(!s){if(!r.overrides?.length)continue;throw new u("invalid_operation","This earlier imported row has seat overrides but no immutable source-row id. Keep it, remove its overrides, or restore the original import before rereading.",{rowId:r.id})}let c=i.get(s)??[];c.push(r),i.set(s,c)}let a=new Map;for(let[r,s]of i){let c=s.filter(b=>b.overrides?.length);if(!c.length)continue;let l=o.get(r),d=c[0],f=d.overrides;if(s.length!==1||c.length!==1||!f||!l||!oo(d,l))throw new u("invalid_operation","This reread would replace a row with seat overrides using different source geometry. Keep the existing row or remove its overrides before rereading.",{sourceRowId:r,rowIds:s.map(b=>b.id)});a.set(r,structuredClone(f))}return a}function io(e,t,n){return e.filter(o=>(o.type==="row"||o.type==="table"||o.type==="booth"||o.type==="gaArea")&&!(o.type==="row"&&o.referenceScan?.assetId===t&&(!n||o.referenceScan.sectionId===n)))}function pa(e,t,n,o,i,a,r){let s=e.sectionId?t.find(d=>d.type==="section"&&d.id===e.sectionId):void 0;if(s){let d=io(t,n,r).filter(f=>F(L(f),s.outline,s.holes));if(d.length)return{skip:{sectionId:s.id,name:e.name,reason:"section_not_empty",objectIds:d.map(f=>f.id)},rows:[],seats:0}}let c=[],l=0;for(let[d,f]of e.rows.entries()){let b=Math.min(ua,Math.max(1,Math.round(f.seatCount)));if(!Number.isFinite(b)||b<1)continue;let g=f.end.x-f.start.x,p=f.end.y-f.start.y,m=Math.hypot(g,p),x=b>1&&m>0?m/(b-1):o>0?o:24;if(!Number.isFinite(x)||x<=0)continue;let I=m>0?Math.atan2(p,g)*180/Math.PI:0,h=e.sourceGroupId?ge(`${e.sourceGroupId}:${d}`):void 0,y=h&&ge(f.directSourceRowId)===h?h:void 0,w=y?no(f.directReviewedSuffix):void 0,S=e.sourceGroupId&&f.rowLabel?fe(f.rowLabel):"",v=e.sourceGroupId&&f.rowDisplayLabel?fe(f.rowDisplayLabel):"";c.push({label:S?a(S,b):i(),displayLabel:v||String(d+1),origin:{x:f.start.x,y:f.start.y},rotation:I,seatCount:b,seatSpacing:x,...y?{directSourceRowId:y}:{},...w?{directReviewedSuffix:w}:{}}),l+=b}return{skip:null,rows:c,seats:l}}function ya(e,t,n){j(e,n.categoryKey);let o=C(e,n.floorId),i=t.assetId,a=n.sectionId?o.objects.find(h=>h.type==="section"&&h.id===n.sectionId):void 0;if(n.sectionId&&!a)throw new Error("The opened section no longer exists on this floor");let r=new Map;for(let h of t.sections){if(a&&h.sectionId!==a.id)continue;let y=n.categoryKeyForSection?.(h)??n.categoryKey;j(e,y),r.set(h,y)}if(a&&!t.sections.some(h=>h.sectionId===a.id&&h.seatCount>0))return{floorId:o.floorId,assetId:i,createdRowIds:[],removedRowIds:[],totalSeats:0,perSection:[],skipped:[]};let s=a?t.sections.find(h=>h.sectionId===a.id&&h.seatCount>0):void 0;if(a&&s){let h=io(o.objects,i,a.id).filter(y=>F(L(y),a.outline,a.holes));if(h.length)return{floorId:o.floorId,assetId:i,createdRowIds:[],removedRowIds:[],totalSeats:0,perSection:[],skipped:[{sectionId:a.id,name:s.name,reason:"section_not_empty",objectIds:h.map(y=>y.id)}]}}let c=o.objects.filter(h=>ro(h,i,a?.id)),l=ha(c,t,a?.id),d=[],f=o.objects.filter(h=>ro(h,i,a?.id)?(d.push(h.id),!1):!0);o.objects.splice(0,o.objects.length,...f);let b=[],g=[],p=[],m=new Set,x=0,I=ba(e);for(let h of t.sections){if(a&&h.sectionId!==a.id)continue;let y=pa(h,o.objects,i,t.seatPitch,I.ordinaryFor(h.name),I.direct,a?.id);if(y.skip){g.push(y.skip);continue}let w=y.rows.map(S=>({type:"row",id:A(e,"r",n.idFactory,m),referenceScan:{assetId:i,...h.sectionId?{sectionId:h.sectionId}:{},...S.directSourceRowId?{directSourceRowId:S.directSourceRowId}:{},...S.directReviewedSuffix?{directReviewedSuffix:S.directReviewedSuffix}:{}},label:S.label,...S.displayLabel?{displayLabel:S.displayLabel}:{},origin:S.origin,rotation:S.rotation,curve:0,seatCount:S.seatCount,seatSpacing:S.seatSpacing,categoryKey:r.get(h)??n.categoryKey,...S.directSourceRowId&&l.has(S.directSourceRowId)?{overrides:structuredClone(l.get(S.directSourceRowId))}:{}}));o.objects.push(...w);for(let S of w)p.push(S.id);b.push({sectionId:h.sectionId,name:h.name,seats:y.seats,rows:w.length}),x+=y.seats}return{floorId:o.floorId,assetId:i,createdRowIds:p,removedRowIds:d,totalSeats:x,perSection:b,skipped:g}}function ao(e,t){let n=C(e,t.floorId),o=[...new Set(t.objectIds)];if(!o.length)throw new u("invalid_operation","Select at least one table or booth to repeat");let i=o.map(g=>n.objects.find(p=>(p.type==="table"||p.type==="booth")&&p.id===g)),a=o.filter((g,p)=>!i[p]);if(a.length)throw new u("object_not_found","One or more grid sources do not exist on the selected floor",{objectIds:a});let r=i[0].type;if(i.some(g=>g.type!==r))throw new u("invalid_operation","A grid array must contain only tables or only booths");for(let[g,p,m]of[["rows",t.rows,30],["columns",t.columns,30]])if(!Number.isInteger(p)||p<1||p>m)throw new u("invalid_operation",`${g} must be a whole number from 1 to ${m}`);for(let[g,p]of[["stepX",t.stepX],["stepY",t.stepY]])if(!Number.isFinite(p)||p<30||p>2e3)throw new u("invalid_operation",`${g} must be from 30 to 2000 chart units`);let s=t.rows*t.columns;if(s<2)throw new u("invalid_operation","Choose at least two grid cells");let c=o.length*(s-1);if(c>5e3)throw new u("invalid_operation","A grid array can add at most 5000 objects");let l=i.reduce((g,p)=>g+(p.type==="table"?p.seatCount:1),0),f=(e.floors?.length?e.floors.flatMap(g=>g.objects):e.objects).reduce((g,p)=>g+(p.type==="row"||p.type==="table"?p.seatCount:p.type==="gaArea"?Math.max(0,Math.floor(p.capacity)):p.type==="booth"?1:0),0),b=l*(s-1);if(f+b>de)throw new u("invalid_operation",`Grid inventory would exceed the ${de} unit event limit`);return{target:n,sources:i,preview:{floorId:n.floorId,kind:r,sourceIds:o,sourceCount:o.length,cells:s,createdCount:c,addedInventory:b,resultingInventory:f+b,provenanceRemovedCount:i.filter(g=>!!g.referenceInventorySource).length*(s-1)}}}function ma(e,t){return ao(e,t).preview}function wa(e,t){let{target:n,sources:o,preview:i}=ao(e,t),a=new Set,r=new Set((e.floors?.length?e.floors.flatMap(d=>d.objects):e.objects).flatMap(d=>"label"in d&&d.label?[d.label]:[])),s=[],c=(d,f)=>{let b=Math.max(2,f),g=m=>{let x=`-${m}`;return`${d.slice(0,Math.max(1,80-x.length))}${x}`},p=g(b);for(;r.has(p);)p=g(++b);return r.add(p),p},l=1;for(let d=0;d<t.rows;d++)for(let f=0;f<t.columns;f++)if(!(d===0&&f===0)){l+=1;for(let b of o){let g=structuredClone(b);g.id=A(e,g.type,t.idFactory,a),g.label=c(b.label,l),g.center={x:b.center.x+f*t.stepX,y:b.center.y+d*t.stepY},delete g.referenceInventorySource,s.push(g)}}return n.objects.push(...s),{...i,createdIds:s.map(d=>d.id)}}function Sa(e,t){let n=e?{...e}:{};return t.size===null?delete n.size:t.size!==void 0&&(n.size=t.size),t.color===null?delete n.color:t.color!==void 0&&(n.color=T(t.color,"Seat label color")),n.size===void 0&&n.color===void 0?void 0:n}var xa=new Set(xe.map(e=>e.key));function _e(e){return`${e.rowId}:${e.index}`}function va(e){let t=e.lastIndexOf(":"),n=t>0?e.slice(0,t):"",o=t>0?Number(e.slice(t+1)):Number.NaN;if(!n||!Number.isInteger(o)||o<0)throw new u("invalid_operation",`Invalid stable seat id: ${e}`,{seatId:e});return{rowId:n,index:o}}function Ia(e){if(e.label||delete e.label,e.displayLabel||delete e.displayLabel,e.dx||delete e.dx,e.dy||delete e.dy,e.skip||delete e.skip,e.categoryKey||delete e.categoryKey,Pe(e.glyph)||delete e.glyph,e.accessible&&!e.accessibility?.length&&(e.accessibility=["wheelchair"]),delete e.accessible,e.wheelchairSpaceType&&!e.accessibility?.includes("wheelchair")&&(e.accessibility=["wheelchair",...e.accessibility??[]]),e.accessibility?.length||delete e.accessibility,e.commercial){let t=e.commercial.note?.normalize("NFKC").trim(),n={};typeof e.commercial.restrictedView=="boolean"&&(n.restrictedView=e.commercial.restrictedView),typeof e.commercial.obstructedView=="boolean"&&(n.obstructedView=e.commercial.obstructedView),typeof e.commercial.premium=="boolean"&&(n.premium=e.commercial.premium),t&&(n.note=t),Object.keys(n).length?e.commercial=n:delete e.commercial}e.viewFromSeatUrl||(delete e.viewFromSeatUrl,delete e.viewFromSeatMeta),e.labelStyle&&e.labelStyle.size===void 0&&e.labelStyle.color===void 0&&delete e.labelStyle}function Ca(e){return Object.keys(e).every(t=>t==="index")}function so(e,t,n){if(!n.length)throw new u("invalid_operation","At least one seat is required");let o=C(e,t),i=[],a=new Set,r=new Map;for(let s of n){let c=_e(s);if(a.has(c))continue;a.add(c);let l=o.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}),r.set(l.id,l)}return{floorId:o.floorId,refs:i,owners:r}}function Dt(e,t){let n=so(e,t.floorId,t.seats),o=Object.keys(t.patch);if(!o.length&&t.labelPrefix===void 0&&t.displayLabelPrefix===void 0)throw new u("invalid_operation","At least one seat override field is required");if(t.labelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(t.patch,"label"))throw new u("invalid_operation","Use either label or labelPrefix, not both");if(t.displayLabelPrefix!==void 0&&Object.prototype.hasOwnProperty.call(t.patch,"displayLabel"))throw new u("invalid_operation","Use either displayLabel or displayLabelPrefix, not both");if(n.refs.length>1&&t.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&&t.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(t.patch.categoryKey&&j(e,t.patch.categoryKey),t.patch.glyph!=null&&!Pe(t.patch.glyph))throw new u("invalid_operation","Unknown seat glyph",{glyph:t.patch.glyph});if(t.patch.accessibility){let a=t.patch.accessibility.filter(r=>!xa.has(r));if(a.length)throw new u("invalid_operation","Unknown accessibility type",{accessibility:a})}if(t.patch.wheelchairSpaceType!==void 0&&t.patch.wheelchairSpaceType!==null&&t.patch.wheelchairSpaceType!=="seat-present"&&t.patch.wheelchairSpaceType!=="no-seat")throw new u("invalid_operation","wheelchairSpaceType must be seat-present, no-seat, or null");if(t.patch.wheelchairSpaceType&&t.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 r=n.owners.get(a.rowId)?.overrides?.find(l=>l.index===a.index),s=t.patch.wheelchairSpaceType===null?void 0:t.patch.wheelchairSpaceType??r?.wheelchairSpaceType,c=t.patch.skip===null?!1:t.patch.skip??r?.skip??!1;if(s&&c)throw new u("invalid_operation","A wheelchair-space physical type cannot also be skipped inventory",{seatId:_e(a)})}if(t.patch.commercial?.note&&t.patch.commercial.note.normalize("NFKC").trim().length>160)throw new u("invalid_operation","Commercial note supports at most 160 characters");if(t.patch.viewFromSeatUrl!=null){let a=Z(t.patch.viewFromSeatUrl);if(!a)throw new u("invalid_operation","Seat view photo must be a safe HTTPS or base64 raster image reference");t.patch.viewFromSeatUrl=a}for(let a of["dx","dy"]){let r=t.patch[a];if(r!=null&&!Number.isFinite(r))throw new u("invalid_operation",`${a} must be finite`,{[a]:r})}t.patch.labelStyle!=null&&le(t.patch.labelStyle,"Seat");let i=!1;return n.refs.forEach((a,r)=>{let s=n.owners.get(a.rowId),c=JSON.stringify(s.overrides??[]),l=s.overrides??(s.overrides=[]),d=l.find(b=>b.index===a.index);d||(d={index:a.index},l.push(d));let f=d.viewFromSeatUrl;for(let b of o){let g=t.patch[b];if(b==="wheelchairSpaceType"&&g==null)delete d.wheelchairSpaceType,d.accessibility&&(d.accessibility=d.accessibility.filter(p=>p!=="wheelchair"),d.accessibility.length||delete d.accessibility),delete d.accessible;else if(g==null)delete d[b];else if(b==="accessibility")d.accessibility=[...new Set(g)],delete d.accessible;else if(b==="commercial")d.commercial={...d.commercial,...g};else if(b==="labelStyle"){let p=Sa(d.labelStyle,g);p?d.labelStyle=p:delete d.labelStyle}else Object.assign(d,{[b]:g})}t.patch.viewFromSeatMeta===void 0&&t.patch.viewFromSeatUrl!==void 0&&d.viewFromSeatUrl!==f&&delete d.viewFromSeatMeta,t.labelPrefix!==void 0&&(d.label=`${t.labelPrefix}${r+1}`),t.displayLabelPrefix!==void 0&&(d.displayLabel=`${t.displayLabelPrefix}${r+1}`),Ia(d),Ca(d)&&(s.overrides=l.filter(b=>b!==d)),s.overrides?.length||delete s.overrides,JSON.stringify(s.overrides??[])!==c&&(i=!0)}),{floorId:n.floorId,changed:i,seatIds:n.refs.map(_e)}}function Oa(e,t){let n=so(e,t.floorId,t.seats),o=!1;for(let[i,a]of n.owners){if(!a.overrides?.length)continue;let r=new Set(n.refs.filter(c=>c.rowId===i).map(c=>c.index)),s=a.overrides.filter(c=>!r.has(c.index));s.length!==a.overrides.length&&(o=!0),a.overrides=s,a.overrides.length||delete a.overrides}return{floorId:n.floorId,changed:o,seatIds:n.refs.map(_e)}}function Pa(e,t){let n=C(e,t.floorId),o=[...new Set(t.rowIds)],i=o.map(h=>n.objects.find(y=>y.type==="row"&&y.id===h)),a=o.filter((h,y)=>!i[y]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});if(t.patch.categoryKey!==void 0&&j(e,t.patch.categoryKey),t.patch.seatCount!==void 0&&(!Number.isInteger(t.patch.seatCount)||t.patch.seatCount<1||t.patch.seatCount>300))throw new u("invalid_operation","seatCount must be an integer from 1 to 300");if(t.patch.seatNumbering!==void 0){let h=t.patch.seatNumbering,y=["decimal","odd","even","updown","updown-descending","roman","letters-upper","letters-lower"];if(h.scheme!==void 0&&!y.includes(h.scheme))throw new u("invalid_operation",`Unknown seat numbering scheme: ${h.scheme}. Expected one of ${y.join(", ")}.`);if(h.prefix!==void 0&&(typeof h.prefix!="string"||h.prefix.length>8))throw new u("invalid_operation","Seat label prefix must be a string of at most 8 characters");if(h.endAt!==void 0&&h.endAt!==null&&(!Number.isInteger(h.endAt)||h.endAt<0||h.endAt>9999))throw new u("invalid_operation","Seat numbering endAt must be an integer from 0 to 9999")}let{labelStyle:r,labelPosition:s,labelRotation:c,labelStyleShape:l,displayLabel:d,displayType:f,...b}=t.patch,g=d===void 0?{}:{displayLabel:d},p=ce(g,"Row"),m=f===void 0?void 0:yt(f,"Row");if(r!==void 0&&le(r,"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");b.labelPresentation!==void 0&&Ne(b.labelPresentation,"Row");let x=h=>JSON.stringify({origin:h.origin,rotation:h.rotation,curve:h.curve,seatCount:h.seatCount,seatSpacing:h.seatSpacing,path:h.path??null}),I=!1;for(let h of i){let y=JSON.stringify(h),w=x(h),S=t.preserveCenterOnSeatCountChange&&t.patch.seatCount!==void 0?L(h):null;if(Object.assign(h,structuredClone(b)),h.overrides&&t.patch.seatCount!==void 0&&(h.overrides=h.overrides.filter(v=>v.index<h.seatCount),h.overrides.length||(h.overrides=void 0)),S){let v=L(h);h.origin={x:h.origin.x+S.x-v.x,y:h.origin.y+S.y-v.y}}if(JSON.stringify(h)!==y&&(I=!0),x(h)!==w&&(delete h.arcFanGeneration,delete h.rowBlockGeneration),r!==void 0){let v=JSON.stringify(h.labelPresentation??null),_=De(h.labelPresentation,r);_?h.labelPresentation=_:delete h.labelPresentation,JSON.stringify(h.labelPresentation??null)!==v&&(I=!0)}if(s!==void 0){let v=JSON.stringify(h.labelPresentation??null),_=h.labelPresentation?structuredClone(h.labelPresentation):{};_.positionPreset=s,_.visible=s!=="none",delete _.position,h.labelPresentation=_,JSON.stringify(h.labelPresentation??null)!==v&&(I=!0)}if(c!==void 0||l!==void 0){let v=JSON.stringify(h.labelPresentation??null),_=h.labelPresentation?structuredClone(h.labelPresentation):{};c===null?delete _.rotation:c!==void 0&&(_.rotation=c),l!==void 0&&(_.style=l),h.labelPresentation=_,JSON.stringify(h.labelPresentation??null)!==v&&(I=!0)}if(m!==void 0){let v=h.displayType;m?h.displayType=m:delete h.displayType,h.displayType!==v&&(I=!0)}if(d!==void 0){let v=h.displayLabel;p?delete h.displayLabel:h.displayLabel=g.displayLabel,h.displayLabel!==v&&(I=!0)}}return{floorId:n.floorId,changed:I,rowIds:o}}var _a=3;function Ze(e){return(e%360+360)%360}function Ra(e){let t=e.rotation*J;return{x:Math.cos(t),y:Math.sin(t)}}function Aa(e,t){let n=Math.abs(Ze(e-t));return n>180&&(n=360-n),n}function be(e,t,n){return(e.x-t.x)*n.x+(e.y-t.y)*n.y}function co(e){let t=0,n=0;for(let i of e){let a=2*i.rotation*J;t+=Math.cos(a),n+=Math.sin(a)}let o=(t===0&&n===0?0:Math.atan2(n,t))/2;return{x:Math.cos(o),y:Math.sin(o)}}function Ma(e,t,n){if(e.origin={x:e.origin.x+t,y:e.origin.y+n},e.path){let o=i=>({x:i.x+t,y:i.y+n});e.path={start:o(e.path.start),control1:o(e.path.control1),control2:o(e.path.control2),end:o(e.path.end)}}}function lo(e,t){let n=co(e),o={x:-n.y,y:n.x},i=L(e[0]),a=e.map(c=>({row:c,coord:be(L(c),i,o)})).sort((c,l)=>c.coord-l.coord),r=a[0].coord,s=!1;return a.forEach((c,l)=>{let d=r+l*t-c.coord;Math.abs(d)>1e-6&&(Ma(c.row,o.x*d,o.y*d),delete c.row.arcFanGeneration,delete c.row.rowBlockGeneration,s=!0)}),s}function ja(e,t){let n={x:-t.y,y:t.x},o=L(e[0]),i=e.map(r=>be(L(r),o,n)).sort((r,s)=>r-s);if(i.length<2)return 28;let a=(i[i.length-1]-i[0])/(i.length-1);return a>.5?a:28}function La(e){if(e.seatCount<2){e.curve=0,delete e.path,delete e.arcFanGeneration,delete e.rowBlockGeneration;return}let t=Se(e),n=t[0],o=t[t.length-1],i=o.x-n.x,a=o.y-n.y,r=Math.hypot(i,a);e.path&&(e.origin={...n},e.seatSpacing=Math.max(1,r/(e.seatCount-1))),r>1e-6&&(e.rotation=Ze(Math.atan2(a,i)/J)),e.curve=0,delete e.path,delete e.arcFanGeneration,delete e.rowBlockGeneration}function ka(e,t){let n=new Set(e.filter(o=>o.type==="row").map(o=>o.label));for(let o=2;o<1e4;o++){let i=`${t}${o}`.slice(0,80);if(!n.has(i))return i}return`${t}-${Date.now().toString(36)}`}function Ea(e,t){let n=C(e,t.floorId),o=[...new Set(t.rowIds)];if(o.length<2)throw new u("invalid_operation","Select at least two rows to merge");let i=o.map(S=>n.objects.find(v=>v.type==="row"&&v.id===S)),a=o.filter((S,v)=>!i[v]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let r=i,s=r.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=r[0],l=r.find(S=>Aa(S.rotation,c.rotation)>_a);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=Ra(c),f={x:-d.y,y:d.x},b=Math.max(8,c.seatSpacing*.6),g=r.find(S=>Math.abs(be(S.origin,c.origin,f))>b);if(g){let S=Math.round(Math.abs(be(g.origin,c.origin,f)));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,g.id]})}let p=r.slice().sort((S,v)=>be(S.origin,c.origin,d)-be(v.origin,c.origin,d)),m=p.reduce((S,v)=>S+v.seatCount,0);if(m>300)throw new u("invalid_operation",`A merged row would have ${m} seats, over the 300-seat row limit. Merge fewer rows.`);let x=p[0],I=[],h=0;for(let S of p){if(S.overrides)for(let v of S.overrides)I.push({...structuredClone(v),index:v.index+h});h+=S.seatCount}x.seatCount=m,x.curve=0,delete x.path,I.length?x.overrides=I:delete x.overrides,delete x.arcFanGeneration,delete x.rowBlockGeneration;let y=p.slice(1).map(S=>S.id),w=new Set(y);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:y,seatCount:m}}function Ta(e,t){let n=C(e,t.floorId),o=n.objects.find(g=>g.type==="row"&&g.id===t.rowId);if(!o)throw new u("object_not_found","The row id does not exist on the selected floor",{rowIds:[t.rowId]});if(o.path)throw new u("invalid_operation","Cannot split a free-form curved row \u2014 straighten it first, then split.",{rowIds:[o.id]});let i=o.seatCount,a=t.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 r=Se(o),s=i>1?o.curve/(i-1):0,c=i-a,l={type:"row",id:A(e,"r",t.idFactory,new Set),label:ka(n.objects,o.label),origin:{...r[a]},rotation:Ze(o.rotation-s*a),curve:s*(c-1),seatCount:c,seatSpacing:o.seatSpacing,categoryKey:o.categoryKey};if(o.seatNumbering&&(l.seatNumbering=structuredClone(o.seatNumbering)),o.seatLabelStart!=null&&(l.seatLabelStart=o.seatLabelStart),o.commercial&&(l.commercial=structuredClone(o.commercial)),o.viewFromSeatUrl&&(l.viewFromSeatUrl=o.viewFromSeatUrl),o.viewFromSeatMeta&&(l.viewFromSeatMeta=structuredClone(o.viewFromSeatMeta)),o.confidenceEvidence&&(l.confidenceEvidence=structuredClone(o.confidenceEvidence)),o.labelPresentation){let g=structuredClone(o.labelPresentation);delete g.position,l.labelPresentation=g}let d=[],f=[];if(o.overrides)for(let g of o.overrides)g.index<a?d.push(structuredClone(g)):f.push({...structuredClone(g),index:g.index-a});o.seatCount=a,o.curve=s*(a-1),d.length?o.overrides=d:delete o.overrides,delete o.arcFanGeneration,delete o.rowBlockGeneration,f.length&&(l.overrides=f);let b=n.objects.indexOf(o);return n.objects.splice(b+1,0,l),{floorId:n.floorId,changed:!0,rowId:o.id,newRowId:l.id,firstSeatCount:a,secondSeatCount:c,newLabel:l.label}}function Fa(e,t){let n=C(e,t.floorId),o=[...new Set(t.rowIds)];if(o.length<2)throw new u("invalid_operation","Select at least two rows to set row spacing");if(!Number.isFinite(t.gap)||t.gap<=0||t.gap>4e3)throw new u("invalid_operation","Row spacing must be a positive value up to 4000 chart units");let i=o.map(s=>n.objects.find(c=>c.type==="row"&&c.id===s)),a=o.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 r=lo(i,t.gap);return{floorId:n.floorId,changed:r,rowIds:o,gap:t.gap}}function Na(e,t){let n=C(e,t.floorId),o=[...new Set(t.rowIds)];if(o.length<2)throw new u("invalid_operation","Select at least two rows to straighten and space evenly");let i=o.map(b=>n.objects.find(g=>g.type==="row"&&g.id===b)),a=o.filter((b,g)=>!i[g]);if(a.length)throw new u("object_not_found","One or more row ids do not exist on the selected floor",{rowIds:a});let r=i,s=()=>JSON.stringify(r.map(b=>[b.origin,b.rotation,b.curve,b.path??null,b.seatSpacing])),c=s();for(let b of r)La(b);let l=co(r),d=Ze(Math.atan2(l.y,l.x)/J);for(let b of r)b.rotation=d;let f=ja(r,l);return lo(r,f),{floorId:n.floorId,changed:s()!==c,rowIds:o,gap:f}}var et=Go(require("polygon-clipping"),1),uo=100,fo=512,Gt=8192,So=64,go=1e7,k=1e-7;function xo(e,t){return Math.abs(e.x-t.x)<=k&&Math.abs(e.y-t.y)<=k}function vo(e){let t=e.map(n=>({x:n.x,y:n.y}));for(;t.length>1&&xo(t[0],t[t.length-1]);)t.pop();return t}function Re(e,t,n){let o=q(t,n,e);return Math.abs(o)>k?!1:e.x>=Math.min(t.x,n.x)-k&&e.x<=Math.max(t.x,n.x)+k&&e.y>=Math.min(t.y,n.y)-k&&e.y<=Math.max(t.y,n.y)+k}function Io(e,t,n,o){let i=q(e,t,n),a=q(e,t,o),r=q(n,o,e),s=q(n,o,t);return(i>k&&a<-k||i<-k&&a>k)&&(r>k&&s<-k||r<-k&&s>k)?!0:Math.abs(i)<=k&&Re(n,e,t)||Math.abs(a)<=k&&Re(o,e,t)||Math.abs(r)<=k&&Re(e,n,o)||Math.abs(s)<=k&&Re(t,n,o)}function Da(e){for(let t=0;t<e.length;t+=1){let n=(t+1)%e.length;for(let o=t+1;o<e.length;o+=1){let i=(o+1)%e.length;if(!(t===o||n===o||i===t)&&Io(e[t],e[n],e[o],e[i]))return!0}}return!1}function bo(e,t){return e.some((n,o)=>t.some((i,a)=>Io(n,e[(o+1)%e.length],i,t[(a+1)%t.length])))}function Kt(e,t){return!t.some((n,o)=>Re(e,n,t[(o+1)%t.length]))&&F(e,t,void 0)}function tt(e,t,n){let o=vo(e);if(o.length<3||o.length>fo||o.some((i,a)=>!Number.isFinite(i.x)||!Number.isFinite(i.y)||Math.abs(i.x)>go||Math.abs(i.y)>go||xo(i,o[(a+1)%o.length]))||Math.abs(me(o))<=k||Da(o))throw new u("invalid_operation",`GA area ${n} has an invalid or self-intersecting ${t}; Join Areas accepts 3\u2013${fo} finite vertices per ring.`,{gaAreaId:n,ring:t});return o}function Ga(e){let t=tt(e.points,"outline",e.id),n=e.holes??[];if(!Array.isArray(n)||n.length>So)throw new u("invalid_operation",`GA area ${e.id} has too many cutouts to join`,{gaAreaId:e.id});let o=n.map(i=>tt(i,"cutout",e.id));for(let i=0;i<o.length;i+=1){let a=o[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=>Kt(s,t))||bo(a,t))throw new u("invalid_operation",`GA area ${e.id} has a cutout outside its outline`,{gaAreaId:e.id,holeIndex:i});for(let s=i+1;s<o.length;s+=1)if(bo(a,o[s])||Kt(a[0],o[s])||Kt(o[s][0],a))throw new u("invalid_operation",`GA area ${e.id} has overlapping cutouts`,{gaAreaId:e.id,holeIndex:i})}return{outer:t,holes:o}}function We(e){return e.map(t=>[t.x,t.y])}function ho(e){return vo(e.map(([t,n])=>({x:t,y:n})))}function po(e){return Math.abs(e.reduce((t,n,o)=>{let i=e[(o+1)%e.length];return t+n[0]*i[1]-i[0]*n[1]},0))/2}function Ka(e){return e.reduce((t,n)=>t+(po(n[0]??[])-n.slice(1).reduce((o,i)=>o+po(i),0)),0)}function $t(e){if(e===void 0)return"undefined";if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map($t).join(",")}]`;let t=e;return`{${Object.keys(t).sort().map(n=>`${JSON.stringify(n)}:${$t(t[n])}`).join(",")}}`}function yo(e,t,n){let o=e[t];if(o===void 0)return null;let i=o.normalize("NFKC").trim();if(!i||i!==o||i.length>n)throw new u("invalid_operation",`GA area ${e.id} has an invalid ${t}; normalize it to 1\u2013${n} characters before joining.`,{gaAreaId:e.id,field:t});return i}function mo(e){return $t({categoryKey:e.categoryKey,displayLabel:yo(e,"displayLabel",80),displayType:yo(e,"displayType",24),referenceInventorySource:e.referenceInventorySource??null})}function wo(e,t){let n=Math.min(...e.points.map(i=>i.y)),o=Math.min(...e.points.map(i=>i.x));return[n,o,t]}function $a(e,t){return e[0]-t[0]||e[1]-t[1]||e[2]-t[2]}function Co(e,t){let n=C(e,t.floorId),o=[...new Set(t.gaAreaIds)];if(o.length<2)throw new u("invalid_operation","Select at least two GA areas to join");if(o.length>uo)throw new u("invalid_operation",`Join Areas supports at most ${uo} areas at once`);let i=o.map(O=>n.objects.find(R=>R.type==="gaArea"&&R.id===O)),a=o.filter((O,R)=>!i[R]);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 r=i;j(e,r[0].categoryKey);let s=mo(r[0]),c=r.find(O=>mo(O)!==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:[r[0].id,c.id]});let l=Ie(e).objectToSection,d=l.get(r[0].id)??"__ungrouped__",f=r.find(O=>(l.get(O.id)??"__ungrouped__")!==d);if(f)throw new u("invalid_operation","GA areas must belong to the same buyer section before they can be joined.",{gaAreaIds:[r[0].id,f.id],sectionIds:[d,l.get(f.id)??"__ungrouped__"]});let b=r.reduce((O,R)=>{if(!Number.isInteger(R.capacity)||R.capacity<1||R.capacity>ne)throw new u("invalid_operation",`GA area ${R.id} has invalid capacity`,{gaAreaId:R.id});return O+R.capacity},0);if(b>ne)throw new u("invalid_operation",`Joined GA capacity would be ${b}, over the ${ne}-unit area limit`,{capacity:b});let g=B(e).reduce((O,R)=>O+te(R),0);if(g>de)throw new u("invalid_operation",`Chart inventory exceeds the ${de}-unit publication limit`,{inventory:g});let p=r.map(Ga),m=p.reduce((O,R)=>O+R.outer.length+R.holes.reduce((V,Q)=>V+Q.length,0),0);if(m>Gt)throw new u("invalid_operation",`Join Areas supports at most ${Gt} source vertices`,{vertexCount:m});let x;try{let O=p.map(Q=>[We(Q.outer)]);if(x=et.default.union(O[0],...O.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 R=p.flatMap(Q=>Q.holes.map(at=>[We(at)]));R.length&&(x=et.default.difference(x,...R));let V=p.findIndex(Q=>{let at=[We(Q.outer),...Q.holes.map(We)];return Ka(et.default.intersection(at,x))<=k});if(V>=0)throw new u("invalid_operation",`GA area ${r[V].id} contributes no sellable surface after preserving every source cutout.`,{gaAreaId:r[V].id})}catch(O){throw O instanceof u?O:new u("invalid_operation","The selected GA boundaries could not be joined safely",{reason:O instanceof Error?O.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 I=ho(x[0][0]),h=x[0].slice(1).map(ho),y=I.length+h.reduce((O,R)=>O+R.length,0);if(h.length>So||y>Gt)throw new u("invalid_operation","The joined boundary is too complex to store safely",{holeCount:h.length,vertexCount:y});tt(I,"outline",r[0].id),h.forEach(O=>tt(O,"cutout",r[0].id));let w=new Map(n.objects.map((O,R)=>[O.id,R])),S=r.slice().sort((O,R)=>$a(wo(O,w.get(O.id)??Number.MAX_SAFE_INTEGER),wo(R,w.get(R.id)??Number.MAX_SAFE_INTEGER))),v=S[0],_=structuredClone(e),G=C(_,n.floorId),N=G.objects.find(O=>O.type==="gaArea"&&O.id===v.id);N.points=structuredClone(I),h.length?N.holes=structuredClone(h):delete N.holes;let H=new Set(S.slice(1).map(O=>O.id));for(let O=G.objects.length-1;O>=0;O-=1)H.has(G.objects[O].id)&&G.objects.splice(O,1);let K=Ie(_).objectToSection.get(v.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:v.id,beforeSectionId:d,afterSectionId:K});let P=[],$=new Set;for(let O of S){if(!xt(O))throw new u("invalid_operation",`GA area ${O.id} has invalid inventory provenance and cannot be joined`,{gaAreaId:O.id});let R=Y(O);if(R.length!==O.capacity||R.some(V=>$.has(V)))throw new u("invalid_operation","Selected GA areas contain duplicated or incomplete stable inventory identities",{gaAreaId:O.id});R.forEach(V=>$.add(V)),P.push(...ze(O))}if(P.length>256)throw new u("invalid_operation","Joined inventory provenance would exceed 256 durable source ranges");let M=new Set(r.map(O=>O.id));for(let O of B(e).filter(R=>R.type==="gaArea"&&!M.has(R.id))){let R=Y(O).find(V=>$.has(V));if(R)throw new u("invalid_operation","A stable GA inventory identity is already owned by another area",{label:R,gaAreaId:O.id})}let it=S.slice(1).map(O=>O.id);return{floorId:n.floorId,areaId:v.id,survivorLabel:v.label,removedAreaIds:it,sourceAreaCount:S.length,capacity:b,inventorySegmentCount:P.length,outerVertexCount:I.length,holeCount:h.length,sectionId:d,points:I,...h.length?{holes:h}:{},segments:P}}function za(e,t){let{segments:n,...o}=Co(e,t);return o}function Ba(e,t){let n=Co(e,t),o=C(e,n.floorId),i=o.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=o.objects.length-1;c>=0;c-=1)a.has(o.objects[c].id)&&o.objects.splice(c,1);let{segments:r,...s}=n;return{...s,changed:!0}}var Oo=[{key:"rect",label:"Flat stage",blurb:"Classic proscenium box."},{key:"rounded",label:"Rounded",blurb:"Softened corners."},{key:"arc",label:"Curved front",blurb:"Front edge bows toward the audience."},{key:"thrust",label:"Thrust (T)",blurb:"Central tongue projects into the crowd."},{key:"runway",label:"Runway",blurb:"Long catwalk into the audience."},{key:"round",label:"In the round",blurb:"Central platform, audience all around."},{key:"pitch-football",label:"Football pitch",blurb:"105 \xD7 68 m pitch with centre circle and penalty boxes."},{key:"rink-hockey",label:"Hockey rink",blurb:"60 \xD7 30 m ice rink with blue lines and faceoff circles."},{key:"track-athletics",label:"Athletics track",blurb:"400 m track: two straights, two semicircles, eight lanes."},{key:"oval-cricket",label:"Cricket oval",blurb:"~150 \xD7 140 m oval with boundary rope and pitch strip."}];var Ua=Math.PI*2;function Ha(e,t,n,o,i,a){return{x:i+e*n-t*o,y:a+e*o+t*n}}function Po(e){let{kind:t,cx:n,cy:o,width:i,height:a}=e,r=(e.rotation??0)*Math.PI/180,s=Math.cos(r),c=Math.sin(r),l=i/2,d=a/2,f=[],b=(g,p)=>{f.push({x:g,y:p})};switch(t){case"rect":{b(-l,-d),b(l,-d),b(l,d),b(-l,d);break}case"rounded":{let g=Math.min(i,a)*.18,p=5,m=(x,I,h)=>{for(let y=0;y<=p;y++){let w=h+y/p*(Math.PI/2);b(x+g*Math.cos(w),I+g*Math.sin(w))}};m(l-g,-d+g,-Math.PI/2),m(l-g,d-g,0),m(-l+g,d-g,Math.PI/2),m(-l+g,-d+g,Math.PI);break}case"arc":{let g=a*.45;b(-l,-d),b(l,-d);let p=24;for(let m=0;m<=p;m++){let x=m/p,I=l-x*i,h=d+g*(1-Math.pow(2*I/i,2));b(I,h)}break}case"thrust":{let g=i*.18,p=a*1.1;b(-l,-d),b(l,-d),b(l,d),b(g,d),b(g,d+p),b(-g,d+p),b(-g,d),b(-l,d);break}case"runway":{let g=i*.1,p=a*3;b(-l,-d),b(l,-d),b(l,d),b(g,d),b(g,d+p),b(-g,d+p),b(-g,d),b(-l,d);break}case"round":case"oval-cricket":{for(let p=0;p<40;p++){let m=p/40*Ua;b(l*Math.cos(m),d*Math.sin(m))}break}case"pitch-football":{b(-l,-d),b(l,-d),b(l,d),b(-l,d);break}case"rink-hockey":{for(let g of Va(l,d,l*(8.5/60),d*(8.5/30)))b(g.x,g.y);break}case"track-athletics":{for(let g of qa(l,d))b(g.x,g.y);break}}return f.map(g=>Ha(g.x,g.y,s,c,n,o))}function Va(e,t,n,o){let i=[],r=(s,c,l)=>{for(let d=0;d<=8;d++){let f=l+d/8*(Math.PI/2);i.push({x:s+n*Math.cos(f),y:c+o*Math.sin(f)})}};return r(e-n,-t+o,-Math.PI/2),r(e-n,t-o,0),r(-e+n,t-o,Math.PI/2),r(-e+n,-t+o,Math.PI),i}function qa(e,t){let n=Math.max(0,e-t),o=[],i=20;for(let a=0;a<=i;a++){let r=-Math.PI/2+a/i*Math.PI;o.push({x:n+t*Math.cos(r),y:t*Math.sin(r)})}for(let a=0;a<=i;a++){let r=Math.PI/2+a/i*Math.PI;o.push({x:-n+t*Math.cos(r),y:t*Math.sin(r)})}return o}function Ja(e,t){let n=C(e,t.floorId),o=[...new Set(t.shapeIds)];if(!o.length)throw new u("invalid_operation","At least one shape id is required");let i=o.map(l=>n.objects.find(d=>d.type==="shape"&&d.id===l)),a=o.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 r=structuredClone(t.patch);if(!Object.keys(r).length)throw new u("invalid_operation","At least one shape change is required");if(r.label!==void 0){if(o.length!==1)throw new u("invalid_operation","label can be changed only for one shape at a time");if(r.label!==null){if(r.label=r.label.normalize("NFKC").trim(),!r.label)r.label=null;else if(r.label.length>80)throw new u("invalid_operation","Shape labels support at most 80 characters")}}if(r.labelStyle!==void 0){let l=i.filter(d=>d.role!=="stage");if(l.length)throw new u("invalid_operation","Shape label styling applies only to stages",{shapeIds:l.map(d=>d.id)});if(r.labelStyle.size!==void 0&&r.labelStyle.size!==null&&(!Number.isFinite(r.labelStyle.size)||r.labelStyle.size<se||r.labelStyle.size>72))throw new u("invalid_operation",`Stage label size must be from ${se} to ${72}`);if(r.labelStyle.color!==void 0&&r.labelStyle.color!==null&&(r.labelStyle.color=T(r.labelStyle.color,"Shape label color")),r.labelStyle.fontFamily!==void 0&&r.labelStyle.fontFamily!==null&&(r.labelStyle.fontFamily=r.labelStyle.fontFamily.normalize("NFKC").trim(),!r.labelStyle.fontFamily||r.labelStyle.fontFamily.length>120))throw new u("invalid_operation","Stage label fontFamily must contain 1 to 120 characters");for(let d of["bold","italic","underline"]){let f=r.labelStyle[d];if(f!=null&&typeof f!="boolean")throw new u("invalid_operation",`Stage label ${d} must be a boolean`)}}if(r.fill!==void 0&&r.fill!==null&&(r.fill=T(r.fill,"Shape fill")),r.kind!==void 0&&!["rect","ellipse","polygon","line","polyline"].includes(r.kind))throw new u("invalid_operation","Shape kind must be rect, ellipse, polygon, line, or polyline");if(r.stroke!==void 0&&r.stroke!==null){if(!Number.isFinite(r.stroke.width)||r.stroke.width<.5||r.stroke.width>40)throw new u("invalid_operation","Shape stroke width must be from 0.5 to 40 chart units");r.stroke={color:T(r.stroke.color,"Shape stroke"),width:r.stroke.width}}if(r.cornerRadius!==void 0&&r.cornerRadius!==null&&(!Number.isFinite(r.cornerRadius)||r.cornerRadius<0||r.cornerRadius>5e3))throw new u("invalid_operation","Shape cornerRadius must be from 0 to 5000 chart units");if(r.opacity!==void 0&&r.opacity!==null&&(!Number.isFinite(r.opacity)||r.opacity<.1||r.opacity>1))throw new u("invalid_operation","Shape opacity must be from 0.1 to 1");if(r.heightM!==void 0&&r.heightM!==null&&(!Number.isFinite(r.heightM)||r.heightM<.05||r.heightM>50))throw new u("invalid_operation","Shape heightM must be from 0.05 to 50 metres");if(r.eventConfigurationIds!==void 0&&r.eventConfigurationIds!==null){let l=r.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");r.eventConfigurationIds=l}if(r.lineCap!==void 0&&r.lineCap!==null&&!Nn.includes(r.lineCap))throw new u("invalid_operation","Shape lineCap must be butt, round, or square");if(r.lineJoin!==void 0&&r.lineJoin!==null&&!Dn.includes(r.lineJoin))throw new u("invalid_operation","Shape lineJoin must be miter, round, or bevel");for(let[l,d]of[["startEnding",r.startEnding],["endEnding",r.endEnding]])if(d!=null&&!Gn.includes(d))throw new u("invalid_operation",`Shape ${l} must be none or arrow`);if(r.lineCap!=null||r.lineJoin!=null||r.startEnding!=null||r.endEnding!=null){let l=i.filter(d=>!Mt(r.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(r.label===null?delete l.label:r.label!==void 0&&(l.label=r.label),r.labelStyle!==void 0){let f={...l.labelStyle};r.labelStyle.size===null?delete f.size:r.labelStyle.size!==void 0&&(f.size=r.labelStyle.size),r.labelStyle.color===null?delete f.color:r.labelStyle.color!==void 0&&(f.color=r.labelStyle.color),r.labelStyle.fontFamily===null?delete f.fontFamily:r.labelStyle.fontFamily!==void 0&&(f.fontFamily=r.labelStyle.fontFamily),r.labelStyle.bold===null?delete f.bold:r.labelStyle.bold!==void 0&&(f.bold=r.labelStyle.bold),r.labelStyle.italic===null||r.labelStyle.italic===!1?delete f.italic:r.labelStyle.italic===!0&&(f.italic=!0),r.labelStyle.underline===null||r.labelStyle.underline===!1?delete f.underline:r.labelStyle.underline===!0&&(f.underline=!0),Object.keys(f).length?l.labelStyle=f:delete l.labelStyle}if(r.fill===null?delete l.fill:r.fill!==void 0&&(l.fill=r.fill),r.kind!==void 0&&(l.kind=r.kind,Mt(l.kind)||(delete l.lineCap,delete l.lineJoin,delete l.startEnding,delete l.endEnding)),r.stroke===null?delete l.stroke:r.stroke!==void 0&&(l.stroke={...r.stroke}),r.opacity===null?delete l.opacity:r.opacity!==void 0&&(l.opacity=r.opacity),r.heightM===null?delete l.heightM:r.heightM!==void 0&&(l.heightM=r.heightM),r.eventConfigurationIds===null?delete l.eventConfigurationIds:r.eventConfigurationIds!==void 0&&(l.eventConfigurationIds=[...r.eventConfigurationIds]),r.lineCap===null?delete l.lineCap:r.lineCap!==void 0&&(l.lineCap=r.lineCap),r.lineJoin===null?delete l.lineJoin:r.lineJoin!==void 0&&(l.lineJoin=r.lineJoin),r.startEnding===null?delete l.startEnding:r.startEnding!==void 0&&(l.startEnding=r.startEnding),r.endEnding===null?delete l.endEnding:r.endEnding!==void 0&&(l.endEnding=r.endEnding),r.cornerRadius===null)delete l.cornerRadius;else if(r.cornerRadius!==void 0){let f=Math.min(l.width??1/0,l.height??1/0),b=Number.isFinite(f)?f/2:r.cornerRadius;l.cornerRadius=l.kind==="rect"?Math.max(0,Math.min(r.cornerRadius,b)):r.cornerRadius}JSON.stringify(l)!==d&&(He(l),c=!0)}return{floorId:n.floorId,changed:c,shapeIds:o}}function Ro(e){if(e.x!=null&&e.y!=null&&e.width!=null&&e.height!=null){if(![e.x,e.y,e.width,e.height].every(Number.isFinite)||e.width<=0||e.height<=0)throw new u("invalid_operation",`Stage ${e.id} has an invalid stored base box`,{stageId:e.id});return{cx:e.x+e.width/2,cy:e.y+e.height/2,width:e.width,height:e.height}}let t=e.points??[];if(t.length<3||t.some(d=>!Number.isFinite(d.x)||!Number.isFinite(d.y)))throw new u("invalid_operation",`Stage ${e.id} has no valid geometry from which to derive its base box`,{stageId:e.id});let n=t.map(d=>d.x),o=t.map(d=>d.y),i=Math.min(...n),a=Math.max(...n),r=Math.min(...o),s=Math.max(...o),c=Math.max(1,a-i),l=Math.max(1,s-r);return{cx:i+c/2,cy:r+l/2,width:c,height:l}}function Xa(e,t){let n=C(e,t.floorId);if(!t.updates.length)throw new u("invalid_operation","At least one shape resize is required");let o=t.updates.map(r=>r.shapeId);if(new Set(o).size!==o.length)throw new u("invalid_operation","Shape ids must be unique");let i=t.updates.map(r=>{if(![r.width,r.height].every(Number.isFinite)||r.width<8||r.height<8||r.width>1e4||r.height>1e4)throw new u("invalid_operation","Shape width and height must be between 8 and 10000 chart units",{shapeId:r.shapeId});let s=n.objects.find(l=>l.type==="shape"&&l.id===r.shapeId);if(!s)throw new u("object_not_found",`Unknown shape id: ${r.shapeId}`,{shapeId:r.shapeId});let c=s.role==="stage"?Ro(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),f=l.map(x=>x.y),b=Math.min(...d),g=Math.max(...d),p=Math.min(...f),m=Math.max(...f);return{cx:(b+g)/2,cy:(p+m)/2,width:Math.max(1,g-b),height:Math.max(1,m-p)}})();return{shape:s,update:r,box:c}}),a=!1;for(let{shape:r,update:s,box:c}of i)if(!(Math.abs(c.width-s.width)<1e-9&&Math.abs(c.height-s.height)<1e-9)){if(r.kind==="rect"||r.kind==="ellipse")r.x=c.cx-s.width/2,r.y=c.cy-s.height/2,r.width=s.width,r.height=s.height;else{let l=s.width/c.width,d=s.height/c.height;r.points=(r.points??[]).map(f=>({x:c.cx+(f.x-c.cx)*l,y:c.cy+(f.y-c.cy)*d})),(r.x!=null||r.y!=null||r.width!=null||r.height!=null||r.role==="stage")&&(r.x=c.cx-s.width/2,r.y=c.cy-s.height/2,r.width=s.width,r.height=s.height)}a=!0}return{floorId:n.floorId,changed:a,shapes:i.map(({shape:r,update:s})=>({id:r.id,width:s.width,height:s.height}))}}function Ya(e,t){let n=C(e,t.floorId);if(!t.updates.length)throw new u("invalid_operation","At least one stage update is required");let o=t.updates.map(s=>s.stageId);if(new Set(o).size!==o.length)throw new u("invalid_operation","Stage ids must be unique");let i=new Set(Oo.map(s=>s.key)),a=t.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:Ro(c)}}),r=!1;for(let s of a)s.box&&(s.shape.points=Po({kind:s.stageKind,...s.box}),s.shape.kind="polygon",s.shape.stageKind=s.stageKind,r=!0);return{floorId:n.floorId,changed:r,stages:a.map(s=>({id:s.shape.id,stageKind:s.stageKind}))}}function Ao(e){let t=new Map;e.confidenceEvidence&&t.set("venue",{target:{scope:"venue"},evidence:e.confidenceEvidence});for(let n of E(e)){n.confidenceEvidence&&t.set(`floor:${n.id}`,{target:{scope:"floor",floorId:n.id},evidence:n.confidenceEvidence});for(let o of n.objects){let i=`floor:${n.id}:object:${o.id}`;if((o.type==="row"||o.type==="section")&&o.confidenceEvidence&&t.set(i,{target:{scope:o.type,floorId:n.id,objectId:o.id},evidence:o.confidenceEvidence}),o.type==="row"&&o.segmentedRow?.confidenceEvidence&&t.set(`${i}:segmented`,{target:{scope:"row",floorId:n.id,objectId:o.id},evidence:o.segmentedRow.confidenceEvidence}),o.type==="row"||o.type==="table")for(let a of o.overrides??[])a.confidenceEvidence&&t.set(`${i}:seat:${a.index}`,{target:{scope:"seat",floorId:n.id,objectId:o.id,seatIndex:a.index},evidence:a.confidenceEvidence})}}return t}function nt(e){return Array.isArray(e)?e.map(nt):!e||typeof e!="object"?e:Object.fromEntries(Object.entries(e).sort(([t],[n])=>t.localeCompare(n)).map(([t,n])=>[t,nt(n)]))}function Za(e,t){return JSON.stringify(nt(e))===JSON.stringify(nt(t))}function zt(e){return!!e&&e.status!=="draft"&&e.status!=="retracted"}function Wa(e){return e?e.status==="retracted"?"retract":zt(e)?"approve":"set":"clear"}function Mo(e,t){let n=Ao(e),o=Ao(t),i=[...new Set([...n.keys(),...o.keys()])].sort(),a=[];for(let r of i){let s=n.get(r),c=o.get(r);if(s&&c&&Za(s.evidence,c.evidence))continue;let l=c?.target??s?.target;l&&a.push({...l,operation:Wa(c?.evidence),...s?{before:s.evidence}:{},...c?{after:c.evidence}:{}})}return a}function es(e,t){return Mo(e,t).some(n=>zt(n.before)||zt(n.after))}var ts=new Set(["synthetic-model","organizer-approved","calibrated-provider"]),ns=new Set(["generated","geometry-verified","configuration-verified"]),os=new Set(["none","comparable-build-reference","actual-build-checked"]),rs=new Set(["clear","partial","obstructed"]);function Bt(e){return e.toISOString().slice(0,10)}function Ut(e,t){return typeof e=="string"&&e.normalize("NFKC").trim()===e&&e.length>0&&e.length<=t}function pe(e,t,n){if(!Ut(e,t))throw new u("invalid_operation",`Confidence evidence ${n} is invalid`,{field:n});return e}function he(e,t,n){if(e!==void 0)return pe(e,t,n)}function ot(e,t,n){let o=n?[C(e,n)]:E(e).map(i=>({floorId:i.id,objects:i.objects}));for(let i of o){let a=i.objects.find(r=>r.id===t);if(a)return{floorId:i.floorId,object:a}}throw new u("object_not_found",`Unknown chart object: ${t}`,{objectId:t,floorId:n})}function jo(e,t){let n=E(e),o=t?n.find(i=>i.id===t):n[0];if(!o)throw new u("floor_not_found",`Unknown chart floor: ${t}`,{floorId:t});return o}function Ae(e,t){if(t.scope==="venue")return e.confidenceEvidence;if(t.scope==="floor")return jo(e,t.floorId).confidenceEvidence;if(t.scope==="seat"){if(!t.objectId||t.seatIndex===void 0)throw new u("invalid_operation","Seat evidence requires objectId and seatIndex");let o=ot(e,t.objectId,t.floorId);if(o.object.type!=="row"&&o.object.type!=="table")throw new u("invalid_operation","Seat evidence can be stored only on a row or table",{objectId:t.objectId});return o.object.overrides?.find(i=>i.index===t.seatIndex)?.confidenceEvidence}if(!t.objectId)throw new u("invalid_operation",`${t.scope} evidence requires objectId`);let n=ot(e,t.objectId,t.floorId);if(t.scope==="row"&&n.object.type!=="row")throw new u("invalid_operation","Row evidence requires a row id",{objectId:t.objectId});if(t.scope==="section"&&n.object.type!=="section")throw new u("invalid_operation","Section evidence requires a section id",{objectId:t.objectId});if(n.object.type==="row"||n.object.type==="section")return n.object.confidenceEvidence;throw new u("invalid_operation",`${t.scope} evidence is not supported on this object`,{objectId:t.objectId,type:n.object.type})}function rt(e,t,n){if(t.scope==="venue")return n?e.confidenceEvidence=n:delete e.confidenceEvidence,{};if(t.scope==="floor"){let i=jo(e,t.floorId);return n?i.confidenceEvidence=n:delete i.confidenceEvidence,{floorId:i.id}}if(t.scope==="seat"){if(!t.objectId||t.seatIndex===void 0)throw new u("invalid_operation","Seat evidence requires objectId and seatIndex");let i=ot(e,t.objectId,t.floorId);return Dt(e,{floorId:i.floorId,seats:[{rowId:t.objectId,index:t.seatIndex}],patch:{confidenceEvidence:n??null}}),{floorId:i.floorId,objectId:t.objectId}}if(!t.objectId)throw new u("invalid_operation",`${t.scope} evidence requires objectId`);let o=ot(e,t.objectId,t.floorId);if(o.object.type!=="row"&&o.object.type!=="section")throw new u("invalid_operation",`${t.scope} evidence is not supported on this object`,{objectId:t.objectId,type:o.object.type});return n?o.object.confidenceEvidence=n:delete o.object.confidenceEvidence,{floorId:o.floorId,objectId:o.object.id}}function is(e){if(e===void 0)return;if(!e||typeof e!="object")throw new u("invalid_operation","Confidence evidence modeledTarget is invalid");if(!Ut(e.label,80)||!Ut(e.methodLabel,100))throw new u("invalid_operation","Confidence evidence modeledTarget labels are invalid");if(!Number.isInteger(e.totalRayCount)||e.totalRayCount<1||e.totalRayCount>1e3||!Number.isInteger(e.clearRayCount)||e.clearRayCount<0||e.clearRayCount>e.totalRayCount)throw new u("invalid_operation","Confidence evidence modeledTarget ray counts are invalid");if(!rs.has(e.classification))throw new u("invalid_operation","Confidence evidence modeledTarget classification is invalid");let t=e.occluderLabels?.map(n=>pe(n,80,"occluder label"));return{label:e.label,methodLabel:e.methodLabel,totalRayCount:e.totalRayCount,clearRayCount:e.clearRayCount,classification:e.classification,...t?.length?{occluderLabels:t}:{}}}function Lo(e,t=new Date){if(e.schema!==void 0&&e.schema!=="seatlayer.seat-confidence/1")throw new u("invalid_operation","Confidence evidence schema must be seatlayer.seat-confidence/1");if(!ts.has(e.evidenceKind))throw new u("invalid_operation","Confidence evidence kind is invalid");if(!ns.has(e.modelLevel))throw new u("invalid_operation","Confidence evidence model level is invalid");let n=e.realityLevel??"none";if(!os.has(n))throw new u("invalid_operation","Confidence evidence reality level is invalid");if(e.evidenceKind==="synthetic-model"&&(e.modelLevel!=="generated"||n!=="none"))throw new u("invalid_operation","Synthetic evidence cannot claim verification or reality checks");let o=he(e.eventConfigurationId,100,"eventConfigurationId");if(e.eventConfigurationVersion!==void 0&&(!Number.isInteger(e.eventConfigurationVersion)||e.eventConfigurationVersion<1))throw new u("invalid_operation","Confidence evidence eventConfigurationVersion is invalid");if(e.modelLevel==="configuration-verified"&&!o)throw new u("invalid_operation","Configuration-verified evidence requires eventConfigurationId");let i=e.limitations?.map(d=>pe(d,160,"limitation"));if(i&&i.length>6)throw new u("invalid_operation","Confidence evidence accepts at most 6 limitations");let a=he(e.assessedAt,40,"assessedAt")??Bt(t),r=Date.parse(a);if(!Number.isFinite(r))throw new u("invalid_operation","Confidence evidence assessedAt is invalid");let s=he(e.validUntil,40,"validUntil")??(e.modelLevel==="generated"?void 0:Bt(new Date(r+365*24*60*60*1e3))),c=s?Date.parse(s):Number.NaN;if(s&&(!Number.isFinite(c)||c<r||c>r+366*24*60*60*1e3))throw new u("invalid_operation",`Confidence evidence validity must end within ${366} days of assessment`);let l=he(e.approvedByRole,100,"approvedByRole");if(e.modelLevel!=="generated"&&!l)throw new u("invalid_operation","Verified model levels require approvedByRole");return{schema:"seatlayer.seat-confidence/1",evidenceId:pe(e.evidenceId,120,"evidenceId"),modelVersion:pe(e.modelVersion,120,"modelVersion"),evidenceKind:e.evidenceKind,modelLevel:e.modelLevel,realityLevel:n,status:"draft",assessedAt:a,...o?{eventConfigurationId:o}:{},...e.eventConfigurationVersion!==void 0?{eventConfigurationVersion:e.eventConfigurationVersion}:{},...s?{validUntil:s}:{},...l?{approvedByRole:l}:{},...he(e.sourceLabel,120,"sourceLabel")?{sourceLabel:e.sourceLabel}:{},...i?.length?{limitations:i}:{},...e.modeledTarget?{modeledTarget:is(e.modeledTarget)}:{}}}function ye(e,t={}){return{changed:t.changed??!0,scope:e.scope,...e.objectId?{objectId:e.objectId}:{},...e.floorId?{floorId:e.floorId}:{},...e.seatIndex!==void 0?{seatIndex:e.seatIndex}:{},...t}}function as(e,t){let n=Lo(t.evidence,t.now),o=JSON.stringify(Ae(e,t)??null),i=rt(e,t,n),a=JSON.stringify(Ae(e,t)??null);return ye(t,{changed:o!==a,...i,evidenceId:n.evidenceId,status:"draft"})}function ss(e,t){let n=Ae(e,t);if(!n)return ye(t,{changed:!1});let o=rt(e,t,void 0);return ye(t,{changed:!0,...o,evidenceId:n.evidenceId})}function cs(e,t){let n=Ae(e,t);if(!n)throw new u("invalid_operation","There is no confidence evidence at this scope to approve",{scope:t.scope,objectId:t.objectId});if(n.status==="retracted")throw new u("invalid_operation","Retracted evidence cannot be approved; author a new draft first");let o=pe(t.approvedByRole.normalize("NFKC").trim(),100,"approvedByRole"),i=he(t.eventConfigurationId,100,"eventConfigurationId")??n.eventConfigurationId;if(n.modelLevel==="configuration-verified"&&!i)throw new u("invalid_operation","Configuration-verified evidence requires eventConfigurationId");let a=t.eventConfigurationVersion??n.eventConfigurationVersion;if(a!==void 0&&(!Number.isInteger(a)||a<1))throw new u("invalid_operation","Confidence evidence eventConfigurationVersion is invalid");let r={...n,status:"approved",approvedByRole:o,assessedAt:Bt(t.now??new Date),...i?{eventConfigurationId:i}:{},...a!==void 0?{eventConfigurationVersion:a}:{}};delete r.basisSha256;let s=t.basisSha256??e.confidenceBasisSha256;s&&(r.basisSha256=s);let c=JSON.stringify(n),l=rt(e,t,r);return ye(t,{changed:c!==JSON.stringify(r),...l,evidenceId:r.evidenceId,status:"approved"})}function ls(e,t){let n=Ae(e,t);if(!n)throw new u("invalid_operation","There is no confidence evidence at this scope to retract",{scope:t.scope,objectId:t.objectId});if(n.status==="retracted")return ye(t,{changed:!1,evidenceId:n.evidenceId,status:"retracted"});let o={...n,status:"retracted"};delete o.basisSha256;let i=rt(e,t,o);return ye(t,{changed:!0,...i,evidenceId:n.evidenceId,status:"retracted"})}0&&(module.exports={COLORBLIND_SAFE_PALETTE,ChartOperationError,DEFAULT_FLOOR_HEIGHT_STEP_M,DEFAULT_SECTION_CORNER_SMOOTHING,MAX_BUYER_IMAGE_URL_LENGTH,MAX_FLOOR_BASE_HEIGHT_M,addArcFanRows,addBookableGridArray,addBoothArray,addChartCategory,addChartFloor,addChartZone,addGAArea,addRowBlock,addTableArray,applyPolygonHole,applyReferenceScanRows,applySectionCornerSmoothing,applySectionOutlineShaping,applySectionRowFit,approveConfidenceEvidence,arcFanInputForGroup,assignSectionInventoryCategory,automaticPlacementCenter,clearConfidenceEvidence,confidenceEvidenceChangeRequiresPublish,confidenceEvidenceChanges,confirmReferenceCategoryOutputColor,convertGeneratedSectionToPolygon,countCoveredInventory,familyCategoryLabel,gaAreaFootprint,groupRowsAsSegmented,insertSeatingBlock,isSafeBuyerImageUrl,joinGAAreas,mergeRows,mirrorFirstFloor,normalizeBuyerImageUrl,normalizeDraftEvidence,parseSeatRefId,pickColorblindSafeCategoryColor,planCreationCategory,previewArcFanRows,previewBookableGridArray,previewGeneratedSectionPolygonConversion,previewJoinGAAreas,previewPolygonHole,previewRemovePolygonHole,previewRowCubicPath,previewSectionRowFit,reassignColorblindSafeCategoryColors,relabelChartRows,removeChartCategory,removeChartFloor,removeChartObjects,removeChartZone,removePolygonHole,renameChartFloor,renameDirectSeatImportCategory,reorderChartCategories,replaceArcFanRows,replaceRowBlock,resetSeatOverrides,resizeShapes,resolveCreationCategory,retractConfidenceEvidence,seatRefId,sectionInventorySelectionSummary,setConfidenceEvidence,setRowBlockSpacing,splitRow,straightenAndSpaceRows,transformSectionBoundary,transformSectionBoundaryObject,ungroupSegmentedRow,updateBooths,updateCategoryDefinitions,updateChartFloorBaseHeight,updateChartTheme,updateChartZones,updateGAAreas,updateRowCubicPath,updateRows,updateSeatOverrides,updateSectionExactPath,updateSectionMetadata,updateSegmentedRow,updateShapes,updateStageKinds,updateTables,updateTextObjects,updateViewFromSeatFallback});